[vlc-devel] [PATCH 3/3] mediacodec: defer mediacodec flush to release

Alexandre Janniaux ajanni at videolabs.io
Tue Feb 16 13:46:40 UTC 2021


Avoid flushing at the mediacodec when the decoder has been drained at
the VLC decoder_t level, because the picture output by the decoder are
inflight pictures that will not stay valid when the decoder will be
flushed. Instead, only flush it when every pictures have been released.

This is not yet perfect though, the best alternative being doing the
flush when every picture have been rendered.
---
 modules/codec/omxil/mediacodec.c | 40 +++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index df0afad13e..1f40a83631 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -573,11 +573,21 @@ static struct picture_context_t *PictureContextCopy(struct picture_context_t *ct
     return ctx;
 }
 
+static void AbortDecoderLocked(decoder_sys_t *p_dec);
 static void CleanFromVideoContext(void *priv)
 {
     android_video_context_t *avctx = priv;
     decoder_sys_t *p_sys = avctx->dec_opaque;
 
+    vlc_mutex_lock(&p_sys->lock);
+    /* Unblock output thread waiting in dequeue_out */
+    DecodeFlushLocked(p_sys);
+    /* Cancel the output thread */
+    AbortDecoderLocked(p_sys);
+    vlc_mutex_unlock(&p_sys->lock);
+
+    vlc_join(p_sys->out_thread, NULL);
+
     CleanDecoder(p_sys);
 }
 
@@ -1061,21 +1071,29 @@ static void CloseDecoder(vlc_object_t *p_this)
 
     vlc_mutex_lock(&p_sys->lock);
     p_sys->b_closed = true;
-
-    /* Unblock output thread waiting in dequeue_out */
-    DecodeFlushLocked(p_sys);
-    /* Cancel the output thread */
-    AbortDecoderLocked(p_sys);
     vlc_mutex_unlock(&p_sys->lock);
 
-    vlc_join(p_sys->out_thread, NULL);
-
-    CleanInputVideo(p_dec);
-
     if (p_sys->video.ctx)
+    {
+        /* If we have a video context, we're using Surface with inflight
+         * pictures, which might already have been queued, and flushing
+         * them would make them invalid, breaking mechanism like waiting
+         * on OnFrameAvailableListener.*/
         vlc_video_context_Release(p_sys->video.ctx);
-    else
-        CleanDecoder(p_sys);
+        return;
+    }
+
+    vlc_mutex_lock(&p_sys->lock);
+    /* Unblock output thread waiting in dequeue_out */
+    DecodeFlushLocked(p_sys);
+    /* Cancel the output thread */
+    AbortDecoderLocked(p_sys);
+    vlc_mutex_unlock(&p_sys->lock);
+
+    vlc_join(p_sys->out_thread, NULL);
+
+    CleanInputVideo(p_dec);
+    CleanDecoder(p_sys);
 }
 
 static int Video_ProcessOutput(decoder_t *p_dec, mc_api_out *p_out,
-- 
2.30.1



More information about the vlc-devel mailing list