[vlc-devel] [PATCH 13/13] vout: fix race to update window size

RĂ©mi Denis-Courmont remi at remlab.net
Wed Jun 12 19:48:37 CEST 2019


Locking the window does not guarantee that the original format will not
change. Lock the display and check if there is a display: the original
format cannot change while a display exists.
---
 src/video_output/video_output.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 4a721e4c64..e535979eec 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -201,17 +201,20 @@ static void vout_SizeWindow(vout_thread_t *vout, unsigned *restrict width,
 
 static void vout_UpdateWindowSizeLocked(vout_thread_t *vout)
 {
+    vout_thread_sys_t *sys = vout->p;
     unsigned width, height;
 
-    vlc_mutex_assert(&vout->p->window_lock);
+    vlc_mutex_assert(&sys->window_lock);
 
-#warning Data race! /* Window lock does not protect original format */
-    if (vout->p->original.i_chroma == 0)
-        return;
+    vlc_mutex_lock(&sys->display_lock);
+    if (sys->display != NULL) {
+        vout_SizeWindow(vout, &width, &height);
+        vlc_mutex_unlock(&sys->display_lock);
 
-    vout_SizeWindow(vout, &width, &height);
-    msg_Dbg(vout, "requested window size: %ux%u", width, height);
-    vout_window_SetSize(vout->p->display_cfg.window, width, height);
+        msg_Dbg(vout, "requested window size: %ux%u", width, height);
+        vout_window_SetSize(vout->p->display_cfg.window, width, height);
+    } else
+        vlc_mutex_unlock(&sys->display_lock);
 }
 
 /* */
-- 
2.20.1



More information about the vlc-devel mailing list