[vlc-commits] mediacodec: defer mediacodec flush to release

Alexandre Janniaux git at videolan.org
Thu Mar 4 17:12:02 UTC 2021


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Tue Feb 16 14:46:40 2021 +0100| [57323ddadbe6579697cc9ecdef0de2fbc6831dac] | committer: Alexandre Janniaux

mediacodec: defer mediacodec flush to release

Avoid flushing 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 too pessimistic currently, the best alternative being doing the
flush when every picture have been rendered.

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

 modules/codec/omxil/mediacodec.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 2bcc27c704..18e761d53a 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -577,11 +577,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);
 }
 
@@ -1064,8 +1074,21 @@ static void CloseDecoder(vlc_object_t *p_this)
     decoder_sys_t *p_sys = p_dec->p_sys;
 
     vlc_mutex_lock(&p_sys->lock);
-    p_sys->b_closed = true;
+    p_sys->b_decoder_dead = true;
+    vlc_mutex_unlock(&p_sys->lock);
+
+    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);
+        CleanInputVideo(p_dec);
+        return;
+    }
 
+    vlc_mutex_lock(&p_sys->lock);
     /* Unblock output thread waiting in dequeue_out */
     DecodeFlushLocked(p_sys);
     /* Cancel the output thread */
@@ -1075,11 +1098,7 @@ static void CloseDecoder(vlc_object_t *p_this)
     vlc_join(p_sys->out_thread, NULL);
 
     CleanInputVideo(p_dec);
-
-    if (p_sys->video.ctx)
-        vlc_video_context_Release(p_sys->video.ctx);
-    else
-        CleanDecoder(p_sys);
+    CleanDecoder(p_sys);
 }
 
 static int Video_ProcessOutput(decoder_t *p_dec, mc_api_out *p_out,



More information about the vlc-commits mailing list