From 61db5758613f26dd5295b023fb1e3fad67a48b60 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 9 Nov 2018 19:28:28 +0100 Subject: [PATCH] Decode and push frame before recording Handle display before recording, to reduce latency. --- app/src/decoder.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index 681a5609..ad7fede8 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -142,24 +142,6 @@ static int run_decoder(void *data) { packet.size = 0; while (!av_read_frame(format_ctx, &packet)) { - if (decoder->recorder) { - // do not record configuration packets - // (they contain no media data and have no PTS/DTS) - // FIXME do not use MediaCodec specific flags - if (!(decoder->buffer_info_flags & MEDIA_CODEC_FLAG_CONFIG)) { - packet.pts = decoder->pts; - packet.dts = decoder->pts; - - // no need to rescale with av_packet_rescale_ts(), the timestamps - // are in microseconds both in input and output - if (!recorder_write(decoder->recorder, &packet)) { - LOGE("Could not write frame to output file"); - 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) @@ -194,6 +176,24 @@ static int run_decoder(void *data) { } #endif + if (decoder->recorder) { + // do not record configuration packets + // (they contain no media data and have no PTS/DTS) + // FIXME do not use MediaCodec specific flags + if (!(decoder->buffer_info_flags & MEDIA_CODEC_FLAG_CONFIG)) { + packet.pts = decoder->pts; + packet.dts = decoder->pts; + + // no need to rescale with av_packet_rescale_ts(), the timestamps + // are in microseconds both in input and output + if (!recorder_write(decoder->recorder, &packet)) { + LOGE("Could not write frame to output file"); + av_packet_unref(&packet); + goto run_quit; + } + } + } + av_packet_unref(&packet); if (avio_ctx->eof_reached) {