From 84ad6633a68d5ce340e53433c83bc696693e14a6 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 5 Mar 2018 21:04:39 +0100 Subject: [PATCH] Move the new avcodec implementation before the old The API to decode the video frames is different depending on the libavcodec version. Move the new API usage to the #if-block. --- app/src/decoder.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index f831107a..8c912715 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -94,7 +94,19 @@ static int run_decoder(void *data) { while (!av_read_frame(format_ctx, &packet) && !avio_ctx->eof_reached) { // the new decoding/encoding API has been introduced by: // -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 37, 0) +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0) + int ret; + if ((ret = avcodec_send_packet(codec_ctx, &packet)) < 0) { + LOGE("Could not send video packet: %d", ret); + goto run_quit; + } + if ((ret = avcodec_receive_frame(codec_ctx, decoder->frames->decoding_frame)) < 0) { + LOGE("Could not receive video frame: %d", ret); + goto run_quit; + } + + push_frame(decoder); +#else while (packet.size > 0) { int got_picture; int len = avcodec_decode_video2(codec_ctx, decoder->frames->decoding_frame, &got_picture, &packet); @@ -108,18 +120,6 @@ static int run_decoder(void *data) { packet.size -= len; packet.data += len; } -#else - int ret; - if ((ret = avcodec_send_packet(codec_ctx, &packet)) < 0) { - LOGE("Could not send video packet: %d", ret); - goto run_quit; - } - if ((ret = avcodec_receive_frame(codec_ctx, decoder->frames->decoding_frame)) < 0) { - LOGE("Could not receive video frame: %d", ret); - goto run_quit; - } - - push_frame(decoder); #endif }