1
0
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:
tux3 2017-02-16 03:52:37 +01:00 committed by Diadlo
parent 91414b4fce
commit f07daaf159
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727

View File

@ -395,27 +395,46 @@ void CameraSource::closeDevice()
void CameraSource::stream()
{
auto streamLoop = [=]() {
AVFrame* frame = av_frame_alloc();
if (!frame)
return;
AVPacket packet;
if (av_read_frame(device->context, &packet) < 0)
if (av_read_frame(device->context, &packet) != 0) {
return;
}
#if LIBAVCODEC_VERSION_INT < 3747941
AVFrame* frame = av_frame_alloc();
if (!frame) {
return;
}
// Only keep packets from the right stream;
if (packet.stream_index == videoStreamIndex) {
// Decode video frame
int frameFinished;
avcodec_decode_video2(cctx, frame, &frameFinished, &packet);
if (!frameFinished)
if (!frameFinished) {
return;
}
VideoFrame* vframe = new VideoFrame(id, frame);
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);
};