mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix: Stop using deprecated avcodec_decode_video2
This commit is contained in:
parent
91414b4fce
commit
f07daaf159
|
@ -395,27 +395,46 @@ void CameraSource::closeDevice()
|
||||||
void CameraSource::stream()
|
void CameraSource::stream()
|
||||||
{
|
{
|
||||||
auto streamLoop = [=]() {
|
auto streamLoop = [=]() {
|
||||||
AVFrame* frame = av_frame_alloc();
|
|
||||||
if (!frame)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
if (av_read_frame(device->context, &packet) < 0)
|
if (av_read_frame(device->context, &packet) != 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LIBAVCODEC_VERSION_INT < 3747941
|
||||||
|
AVFrame* frame = av_frame_alloc();
|
||||||
|
if (!frame) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Only keep packets from the right stream;
|
// Only keep packets from the right stream;
|
||||||
if (packet.stream_index == videoStreamIndex) {
|
if (packet.stream_index == videoStreamIndex) {
|
||||||
// Decode video frame
|
// Decode video frame
|
||||||
int frameFinished;
|
int frameFinished;
|
||||||
avcodec_decode_video2(cctx, frame, &frameFinished, &packet);
|
avcodec_decode_video2(cctx, frame, &frameFinished, &packet);
|
||||||
if (!frameFinished)
|
if (!frameFinished) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
VideoFrame* vframe = new VideoFrame(id, frame);
|
VideoFrame* vframe = new VideoFrame(id, frame);
|
||||||
emit frameAvailable(vframe->trackFrame());
|
emit frameAvailable(vframe->trackFrame());
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Forward packets to the decoder and grab the decoded frame
|
||||||
|
bool isVideo = packet.stream_index == videoStreamIndex;
|
||||||
|
bool readyToRecive = isVideo && !avcodec_send_packet(cctx, &packet);
|
||||||
|
|
||||||
|
if (readyToRecive) {
|
||||||
|
AVFrame* frame = av_frame_alloc();
|
||||||
|
if (frame && !avcodec_receive_frame(cctx, frame)) {
|
||||||
|
VideoFrame* vframe = new VideoFrame(id, frame);
|
||||||
|
emit frameAvailable(vframe->trackFrame());
|
||||||
|
} else {
|
||||||
|
av_frame_free(&frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Free the packet that was allocated by av_read_frame
|
|
||||||
av_packet_unref(&packet);
|
av_packet_unref(&packet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user