diff mbox series

[FFmpeg-devel] mediacodecdec_common: enable refcounting of buffers unconditionally

Message ID PAXP251MB0726CE895BAE36DFC02B07F4EC4A9@PAXP251MB0726.EURP251.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel] mediacodecdec_common: enable refcounting of buffers unconditionally | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

sfan5 Sept. 18, 2022, 6 p.m. UTC
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.
---
  libavcodec/mediacodecdec_common.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)

mediacodec_wrap_hw_buffer(AVCodecContext *avctx,
       buffer->ctx = s;
      buffer->serial = atomic_load(&s->serial);
-    if (s->delay_flush)
-        ff_mediacodec_dec_ref(s);
+    ff_mediacodec_dec_ref(s);
       buffer->index = index;
      buffer->pts = info->presentationTimeUs;
@@ -872,7 +870,7 @@ int ff_mediacodec_dec_receive(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;
           /* No frames (holding a reference to the codec) are retained 
by the
diff mbox series

Patch

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index 9fa769656c..2a605e7f5b 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -265,8 +265,7 @@  static void mediacodec_buffer_release(void *opaque, 
uint8_t *data)
          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);
  }
  @@ -321,8 +320,7 @@ static int