[vlc-commits] decoder: fix out_pool race condtion

Thomas Guillem git at videolan.org
Mon Nov 30 09:41:10 CET 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Nov 27 16:11:35 2020 +0100| [29348f4a7861aafde6a97c604b8c28a970892e59] | committer: Thomas Guillem

decoder: fix out_pool race condtion

The ModuleThread is creating it, so it doesn't need a lock for reading,
but it does need a lock for writing it. Indeed, other threads (the
DecoderThread and the input one) are already reading this variable with
the lock held.

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

 src/input/decoder.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 19b774c49c..8d67f7ea63 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -449,16 +449,21 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
             dpb_size = 2;
             break;
         }
-
-        p_owner->out_pool = picture_pool_NewFromFormat( &p_dec->fmt_out.video,
+        picture_pool_t *pool = picture_pool_NewFromFormat( &p_dec->fmt_out.video,
                             dpb_size + p_dec->i_extra_picture_buffers + 1 );
-        if (p_owner->out_pool == NULL)
+
+        if( pool == NULL)
         {
             msg_Err(p_dec, "Failed to create a pool of %d %4.4s pictures",
                            dpb_size + p_dec->i_extra_picture_buffers + 1,
                            (char*)&p_dec->fmt_out.video.i_chroma);
             return -1;
         }
+
+        vlc_mutex_lock( &p_owner->lock );
+        p_owner->out_pool = pool;
+        vlc_mutex_unlock( &p_owner->lock );
+
     }
 
     vout_configuration_t cfg = {
@@ -544,13 +549,12 @@ static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner)
 
     DecoderUpdateFormatLocked( p_owner );
     p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
+    picture_pool_t *pool = p_owner->out_pool;
+    p_owner->out_pool = NULL;
     vlc_mutex_unlock( &p_owner->lock );
 
-     if ( p_owner->out_pool != NULL )
-     {
-         picture_pool_Release( p_owner->out_pool );
-         p_owner->out_pool = NULL;
-     }
+     if ( pool != NULL )
+         picture_pool_Release( pool );
 
     if( p_vout == NULL )
     {



More information about the vlc-commits mailing list