From 35298bb0c60cdc6c55952de95ff7b92ff35130c7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 23 Mar 2018 14:01:58 +0100 Subject: [PATCH] Process the last video frame On H.264 stream EOF, the eof_reached flag is set, but av_read_frame() still provides a frame, so check the flag only afterwards. As a side-effect, it also fixes a memory leak (the very last packet was not unref). --- app/src/decoder.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index 68c1c500..94dc9401 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -92,10 +92,6 @@ static int run_decoder(void *data) { packet.size = 0; while (!av_read_frame(format_ctx, &packet)) { - if (avio_ctx->eof_reached) { - av_packet_unref(&packet); - goto run_quit; - } // the new decoding/encoding API has been introduced by: // #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0) @@ -129,6 +125,10 @@ static int run_decoder(void *data) { } #endif av_packet_unref(&packet); + + if (avio_ctx->eof_reached) { + break; + } } LOGD("End of frames");