diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 40a2ee6778..887865a281 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -443,6 +443,8 @@ static int mediacodec_dec_flush_codec(AVCodecContext *avctx, MediaCodecDecContex FFAMediaCodec *codec = s->codec; int status; + s->output_buffer_count = 0; + s->draining = 0; s->flushing = 0; s->eos = 0; @@ -670,7 +672,10 @@ int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, /* If the codec is flushing or need to be flushed, block for a fair * amount of time to ensure we got a frame */ output_dequeue_timeout_us = OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US; - } else if (!wait) { + } else if (s->output_buffer_count == 0 || !wait) { + /* If the codec hasn't produced any frames, do not block so we + * can push data to it as fast as possible, and get the first + * frame */ output_dequeue_timeout_us = 0; } @@ -704,6 +709,7 @@ int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, } } + s->output_buffer_count++; return 0; } else { status = ff_AMediaCodec_releaseOutputBuffer(codec, index, 0); diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h index d280236b8e..0b21129fee 100644 --- a/libavcodec/mediacodecdec_common.h +++ b/libavcodec/mediacodecdec_common.h @@ -64,6 +64,7 @@ typedef struct MediaCodecDecContext { int display_width; int display_height; + uint64_t output_buffer_count; ssize_t current_input_buffer; bool delay_flush;