[vlc-devel] [PATCH 5/7] video_output: lock the writing of the vout display object

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 17 11:27:08 CEST 2018


In case we want to be able to read it outside of the VOUT thread
---
 src/video_output/video_output.c  |  2 ++
 src/video_output/vout_internal.h |  2 ++
 src/video_output/vout_wrapper.c  | 20 ++++++++++++++++----
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index e91fa0d772..d80f825987 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -149,6 +149,7 @@ static vout_thread_t *VoutCreate(vlc_object_t *object,
 
     /* Initialize locks */
     vlc_mutex_init(&vout->p->filter.lock);
+    vlc_mutex_init(&vout->p->display.lock);
     vlc_mutex_init(&vout->p->spu_lock);
     vlc_mutex_init(&vout->p->window_lock);
 
@@ -304,6 +305,7 @@ static void VoutDestructor(vlc_object_t *object)
     /* Destroy the locks */
     vlc_mutex_destroy(&vout->p->window_lock);
     vlc_mutex_destroy(&vout->p->spu_lock);
+    vlc_mutex_destroy(&vout->p->display.lock);
     vlc_mutex_destroy(&vout->p->filter.lock);
     vout_control_Clean(&vout->p->control);
 
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index c1a1d6ac5a..ba583e7c8e 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -90,6 +90,8 @@ struct vout_thread_sys_t
     /* */
     struct {
         vout_display_t *vd;
+        /* locked when modified in the UI thread or read outside that thread */
+       vlc_mutex_t     lock;
         bool           use_dr;
     } display;
 
diff --git a/src/video_output/vout_wrapper.c b/src/video_output/vout_wrapper.c
index bacce55167..734af4bff4 100644
--- a/src/video_output/vout_wrapper.c
+++ b/src/video_output/vout_wrapper.c
@@ -43,20 +43,25 @@ int vout_OpenWrapper(vout_thread_t *vout,
                      const char *splitter_name, const vout_display_state_t *state)
 {
     vout_thread_sys_t *sys = vout->p;
+    vout_display_t *vd;
     msg_Dbg(vout, "Opening vout display wrapper");
 
     /* */
     char *modlist = var_InheritString(vout, "vout");
 
     if (splitter_name)
-        sys->display.vd = vout_NewSplitter(vout, &vout->p->original, state, modlist, splitter_name);
+        vd = vout_NewSplitter(vout, &vout->p->original, state, modlist, splitter_name);
     else
-        sys->display.vd = vout_NewDisplay(vout, &vout->p->original, state, modlist);
+        vd = vout_NewDisplay(vout, &vout->p->original, state, modlist);
     free(modlist);
 
-    if (!sys->display.vd)
+    if (vd==NULL)
         return VLC_EGENERIC;
 
+    vlc_mutex_lock(&sys->display.lock);
+    sys->display.vd = vd;
+    vlc_mutex_unlock(&sys->display.lock);
+
     /* */
     sys->decoder_pool = NULL;
 
@@ -69,10 +74,17 @@ int vout_OpenWrapper(vout_thread_t *vout,
 void vout_CloseWrapper(vout_thread_t *vout, vout_display_state_t *state)
 {
     vout_thread_sys_t *sys = vout->p;
+    vout_display_t *vd;
 
     sys->decoder_pool = NULL; /* FIXME remove */
 
-    vout_DeleteDisplay(sys->display.vd, state);
+
+    vlc_mutex_lock(&sys->display.lock);
+    vd = sys->display.vd;
+    sys->display.vd = NULL;
+    vlc_mutex_unlock(&sys->display.lock);
+
+    vout_DeleteDisplay(vd, state);
 }
 
 /*****************************************************************************
-- 
2.17.0



More information about the vlc-devel mailing list