[vlc-commits] access: bluray: add lock in fake es_out

Francois Cartegnie git at videolan.org
Tue Oct 30 18:12:31 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 17 12:03:51 2018 +0200| [c6b6e1d60d9cf2076d12429b6f82459c0b97483b] | committer: Francois Cartegnie

access: bluray: add lock in fake es_out

fixes concurrent access due to chained Demux thread

(cherry picked from commit c631c7ec5407e0c299c8a05ddfeade5c1ee96bf6)

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

 modules/access/bluray.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index faf643ec19..cc8372c4c9 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -1070,6 +1070,7 @@ typedef struct
     vlc_object_t *p_obj;
     vlc_array_t es; /* es_pair_t */
     void *priv;
+    vlc_mutex_t lock;
     struct
     {
         int i_audio_pid; /* Selected audio stream. -1 if default */
@@ -1094,6 +1095,8 @@ static es_out_id_t *bluray_esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
 
     es_format_Copy(&fmt, p_fmt);
 
+    vlc_mutex_lock(&esout_sys->lock);
+
     switch (fmt.i_cat) {
     case VIDEO_ES:
         if (esout_sys->selected.i_video_pid != -1 && esout_sys->selected.i_video_pid != p_fmt->i_id)
@@ -1137,6 +1140,9 @@ static es_out_id_t *bluray_esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
         }
     }
     es_format_Clean(&fmt);
+
+    vlc_mutex_unlock(&esout_sys->lock);
+
     return p_es;
 }
 
@@ -1152,15 +1158,21 @@ static void bluray_esOutDel(es_out_t *p_out, es_out_id_t *p_es)
     bluray_esout_sys_t *esout_sys = (bluray_esout_sys_t *)p_out->p_sys;
 
     es_pair_t *p_pair = getEsPairByES(&esout_sys->es, p_es);
+    vlc_mutex_lock(&esout_sys->lock);
+
     if (p_pair)
         es_pair_Remove(&esout_sys->es, p_pair);
 
     es_out_Del(esout_sys->p_dst_out, p_es);
+
+    vlc_mutex_unlock(&esout_sys->lock);
 }
 
 static int bluray_esOutControl(es_out_t *p_out, int i_query, va_list args)
 {
     bluray_esout_sys_t *esout_sys = (bluray_esout_sys_t *)p_out->p_sys;
+    int i_ret;
+    vlc_mutex_lock(&esout_sys->lock);
     switch(i_query)
     {
         case BLURAY_ES_OUT_CONTROL_SET_ES_BY_PID:
@@ -1183,17 +1195,24 @@ static int bluray_esOutControl(es_out_t *p_out, int i_query, va_list args)
 
             es_pair_t *p_pair = getEsPairByPID(&esout_sys->es, i_pid);
             if(unlikely(!p_pair))
+            {
+                vlc_mutex_unlock(&esout_sys->lock);
                 return VLC_EGENERIC;
+            }
 
             if(b_select)
-                return es_out_Control(esout_sys->p_dst_out, ES_OUT_SET_ES, p_pair->p_es);
+                i_ret = es_out_Control(esout_sys->p_dst_out, ES_OUT_SET_ES, p_pair->p_es);
             else
-                return es_out_Control(esout_sys->p_dst_out, ES_OUT_SET_ES_STATE,
+                i_ret = es_out_Control(esout_sys->p_dst_out, ES_OUT_SET_ES_STATE,
                                       p_pair->p_es, false);
+            break;
         };
         default:
-            return es_out_vaControl(esout_sys->p_dst_out, i_query, args);
+            i_ret = es_out_vaControl(esout_sys->p_dst_out, i_query, args);
+            break;
     }
+    vlc_mutex_unlock(&esout_sys->lock);
+    return i_ret;
 }
 
 static void bluray_esOutDestroy(es_out_t *p_out)
@@ -1203,6 +1222,7 @@ static void bluray_esOutDestroy(es_out_t *p_out)
     for (size_t i = 0; i < vlc_array_count(&esout_sys->es); ++i)
         free(vlc_array_item_at_index(&esout_sys->es, i));
     vlc_array_clear(&esout_sys->es);
+    vlc_mutex_destroy(&esout_sys->lock);
     free(p_out->p_sys);
     free(p_out);
 }
@@ -1233,6 +1253,7 @@ static es_out_t *esOutNew(vlc_object_t *p_obj, es_out_t *p_dst_out, void *priv)
     esout_sys->selected.i_audio_pid = -1;
     esout_sys->selected.i_video_pid = -1;
     esout_sys->selected.i_spu_pid = -1;
+    vlc_mutex_init(&esout_sys->lock);
     return p_out;
 }
 



More information about the vlc-commits mailing list