lavc/mediacodecdec_common: enable refcounting of buffers unconditionally

This allows av_mediacodec_release_buffer to be called safely after
the decoder is closed, this was already the case with delay_flush=1.
Note that this causes holding onto frames to keep the decoding context
alive which is generally considered to be the intended behavior.

Signed-off-by: sfan5 <sfan5@live.de>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
This commit is contained in:
sfan5 2022-09-18 18:26:43 +02:00 committed by Anton Khirnov
parent 8bafe8a418
commit 954784b120
1 changed files with 3 additions and 5 deletions

View File

@ -265,7 +265,6 @@ static void mediacodec_buffer_release(void *opaque, uint8_t *data)
ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, 0); ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, 0);
} }
if (ctx->delay_flush)
ff_mediacodec_dec_unref(ctx); ff_mediacodec_dec_unref(ctx);
av_freep(&buffer); av_freep(&buffer);
} }
@ -321,7 +320,6 @@ static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx,
buffer->ctx = s; buffer->ctx = s;
buffer->serial = atomic_load(&s->serial); buffer->serial = atomic_load(&s->serial);
if (s->delay_flush)
ff_mediacodec_dec_ref(s); ff_mediacodec_dec_ref(s);
buffer->index = index; buffer->index = index;
@ -872,7 +870,7 @@ int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s,
*/ */
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
{ {
if (!s->surface || atomic_load(&s->refcount) == 1) { if (!s->surface || !s->delay_flush || atomic_load(&s->refcount) == 1) {
int ret; int ret;
/* No frames (holding a reference to the codec) are retained by the /* No frames (holding a reference to the codec) are retained by the