[vlc-commits] [Git][videolan/vlc][master] mediacodec: fix AImageReader flush deadlock

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jun 6 10:21:47 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
f829ba5f by Martin Finkel at 2026-06-06T12:10:27+02:00
mediacodec: fix AImageReader flush deadlock

A flush can arrive while OutThread waits for a pending AImageReader callback, leaving the flush and output paths waiting on each other.

Wake all AImageReader waiters, discard callback images during flush, and drain pending callbacks before AMediaCodec_flush() invalidates output buffer indices. If a flush interrupts Video_ProcessOutput, release the buffer without rendering so OutThread can acknowledge the flush.

- - - - -


1 changed file:

- modules/codec/omxil/mediacodec.c


Changes:

=====================================
modules/codec/omxil/mediacodec.c
=====================================
@@ -932,8 +932,11 @@ AImageReader_OnImageAvailable(void *context, AImageReader *reader)
     vlc_mutex_lock(&p_sys->lock);
     assert(p_sys->video.air_waiting_count > 0);
     p_sys->video.air_waiting_count--;
-    vlc_cond_signal(&p_sys->video.air_cond);
-    QueueAImagePicture(p_dec, avctx, image, fence_fd);
+    vlc_cond_broadcast(&p_sys->video.air_cond);
+    if (p_sys->b_flush_out)
+        avctx->air_api->AImage.deleteAsync(image, fence_fd);
+    else
+        QueueAImagePicture(p_dec, avctx, image, fence_fd);
     vlc_mutex_unlock(&p_sys->lock);
 }
 
@@ -1544,8 +1547,17 @@ static int Video_ProcessOutput(decoder_t *p_dec, mc_api_out *p_out,
             {
                 /* We need to wait for AImageReader. Otherwise, we might
                  * overwrite a picture (even when using acquireNextImageAsync) */
-                while (p_sys->video.air_waiting_count != 0 && !p_sys->b_aborted)
+                while (p_sys->video.air_waiting_count != 0
+                       && !p_sys->b_aborted && !p_sys->b_flush_out)
                     vlc_cond_wait(&p_sys->video.air_cond, &p_sys->lock);
+
+                if (p_sys->b_flush_out)
+                {
+                    /* Drop this buffer so OutThread can acknowledge the flush. */
+                    p_sys->api.release_out(&p_sys->api, p_out->buf.i_index, false);
+                    return 0;
+                }
+
                 p_sys->video.air_waiting_count++;
 
                 p_sys->api.release_out(&p_sys->api, p_out->buf.i_index,
@@ -2313,6 +2325,14 @@ static void Video_OnFlush(decoder_sys_t *p_sys)
      * since flushing make all previous indices returned by
      * MediaCodec invalid. */
     ReleaseAllPictureContexts(p_sys);
+
+    if (p_sys->video.use_air)
+    {
+        /* Drain AImageReader callbacks before AMediaCodec_flush() invalidates
+         * output buffer indices, or air_waiting_count may stay stuck. */
+        while (p_sys->video.air_waiting_count != 0 && !p_sys->b_aborted)
+            vlc_cond_wait(&p_sys->video.air_cond, &p_sys->lock);
+    }
 }
 
 static int Audio_OnNewBlock(decoder_t *p_dec, block_t **pp_block)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f829ba5f283a89aa32c40229d762b91e8a3a6528

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f829ba5f283a89aa32c40229d762b91e8a3a6528
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list