diff options
author | Aman Gupta <aman@tmm1.net> | 2018-04-24 12:40:38 -0700 |
---|---|---|
committer | Aman Gupta <aman@tmm1.net> | 2018-05-04 11:53:33 -0700 |
commit | f6681feda641c026d84f6d207f661bf9b87d9d70 (patch) | |
tree | 2050df51d09bd71392045a1d75a310b787f3a4af /libavcodec/mediacodecdec_common.c | |
parent | fe0a6bcbda0f51d0613dbbd42a7635c22530ce95 (diff) | |
download | ffmpeg-f6681feda641c026d84f6d207f661bf9b87d9d70.tar.gz |
avcodec/mediacodecdec: restructure mediacodec_receive_frame
The new logic follows a recommendation by @rcombs to use
dequeueInputBuffer with a timeout of 0 as a way to detect
whether the codec wants more data. The dequeued buffer index is
kept in MediaCodecDecContext until it can be used next.
A similar technique is also used by the Google's official media
player Exoplayer: see MediaCodecRenderer.feedInputBuffer().
Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
Diffstat (limited to 'libavcodec/mediacodecdec_common.c')
-rw-r--r-- | libavcodec/mediacodecdec_common.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index c0f0a6b983..887865a281 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -450,6 +450,7 @@ static int mediacodec_dec_flush_codec(AVCodecContext *avctx, MediaCodecDecContex s->eos = 0; atomic_fetch_add(&s->serial, 1); atomic_init(&s->hw_buffer_count, 0); + s->current_input_buffer = -1; status = ff_AMediaCodec_flush(codec); if (status < 0) { @@ -477,6 +478,7 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, atomic_init(&s->refcount, 1); atomic_init(&s->hw_buffer_count, 0); atomic_init(&s->serial, 1); + s->current_input_buffer = -1; pix_fmt = ff_get_format(avctx, pix_fmts); if (pix_fmt == AV_PIX_FMT_MEDIACODEC) { @@ -561,16 +563,16 @@ fail: } int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, - AVPacket *pkt) + AVPacket *pkt, bool wait) { int offset = 0; int need_draining = 0; uint8_t *data; - ssize_t index; + ssize_t index = s->current_input_buffer; size_t size; FFAMediaCodec *codec = s->codec; int status; - int64_t input_dequeue_timeout_us = INPUT_DEQUEUE_TIMEOUT_US; + int64_t input_dequeue_timeout_us = wait ? INPUT_DEQUEUE_TIMEOUT_US : 0; int64_t pts; if (s->flushing) { @@ -588,17 +590,19 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, } while (offset < pkt->size || (need_draining && !s->draining)) { - - index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us); - if (ff_AMediaCodec_infoTryAgainLater(codec, index)) { - av_log(avctx, AV_LOG_TRACE, "No input buffer available, try again later\n"); - break; - } - if (index < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to dequeue input buffer (status=%zd)\n", index); - return AVERROR_EXTERNAL; + index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us); + if (ff_AMediaCodec_infoTryAgainLater(codec, index)) { + av_log(avctx, AV_LOG_TRACE, "No input buffer available, try again later\n"); + break; + } + + if (index < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to dequeue input buffer (status=%zd)\n", index); + return AVERROR_EXTERNAL; + } } + s->current_input_buffer = -1; data = ff_AMediaCodec_getInputBuffer(codec, index, &size); if (!data) { |