[vlc-commits] mediacodec: fix ref counting

Thomas Guillem git at videolan.org
Mon Jan 20 18:05:15 CET 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Jan 20 17:42:49 2020 +0100| [039735dff4bba90b2eaa18236c6913d0bbde1089] | committer: Thomas Guillem

mediacodec: fix ref counting

Regression from c515dc468dfffe8ed56042c2a3cc28fcb8e9d071

I originally planned to have 2 users of the android_picture_ctx, hence the 2. I
forgot to go back to 1 ref when I abandoned this idea.

This caused MediaCodec buffers to not be released when the VLC pictures were
released without being rendered.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=039735dff4bba90b2eaa18236c6913d0bbde1089
---

 modules/codec/omxil/mediacodec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index f0cf159cc4..c802f8c71e 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -592,9 +592,9 @@ GetPictureContext(decoder_t *p_dec, unsigned index)
         for (size_t i = 0; i < ARRAY_SIZE(p_sys->video.apic_ctxs); ++i)
         {
             struct android_picture_ctx *apctx = &p_sys->video.apic_ctxs[i];
-            /* Find an available picture context (ie. refs == 1) */
-            unsigned expected_refs = 1;
-            if (atomic_compare_exchange_strong(&apctx->refs, &expected_refs, 2))
+            /* Find an available picture context (ie. refs == 0) */
+            unsigned expected_refs = 0;
+            if (atomic_compare_exchange_strong(&apctx->refs, &expected_refs, 1))
             {
                 int expected_index = -1;
                 /* Store the new index */
@@ -606,7 +606,7 @@ GetPictureContext(decoder_t *p_dec, unsigned index)
                  * this picture context is being released. Cf.
                  * PictureContextDestroy(), this function first decrement the
                  * ref count before releasing the index.  */
-                atomic_store(&apctx->refs, 1);
+                atomic_store(&apctx->refs, 0);
             }
         }
 
@@ -695,7 +695,7 @@ CreateVideoContext(decoder_t *p_dec)
             p_sys->video.ctx,
         };
         atomic_init(&apctx->index, -1);
-        atomic_init(&apctx->refs, 1);
+        atomic_init(&apctx->refs, 0);
     }
 
     return VLC_SUCCESS;



More information about the vlc-commits mailing list