[vlc-devel] [PATCH v5 19/24] vout/control: move the condition on pictures/control outside of the control API

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 24 09:42:00 CEST 2020


For now we need to signal manually anytime we push a control command.
---
 src/video_output/control.c      | 8 ++------
 src/video_output/control.h      | 4 +---
 src/video_output/video_output.c | 9 ++++++++-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 0d2912dee6d..4950da5aae6 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -39,8 +39,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *cmd, int type)
 /* */
 void vout_control_Init(vout_control_t *ctrl)
 {
-    vlc_cond_init(&ctrl->wait_request);
-
     ctrl->is_dead = false;
     ctrl->can_sleep = true;
     ARRAY_INIT(ctrl->cmd);
@@ -61,14 +59,12 @@ void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
 {
     if (!ctrl->is_dead) {
         ARRAY_APPEND(ctrl->cmd, *cmd);
-        vlc_cond_signal(&ctrl->wait_request);
     }
 }
 
 void vout_control_Wake(vout_control_t *ctrl)
 {
     ctrl->can_sleep = false;
-    vlc_cond_signal(&ctrl->wait_request);
 }
 
 void vout_control_PushVoid(vout_control_t *ctrl, int type)
@@ -80,12 +76,12 @@ void vout_control_PushVoid(vout_control_t *ctrl, int type)
 }
 
 int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
-                     vlc_tick_t deadline, vlc_mutex_t *lock)
+                     vlc_tick_t deadline, vlc_cond_t *wait_request, vlc_mutex_t *lock)
 {
     if (ctrl->cmd.i_size <= 0) {
         /* Spurious wakeups are perfectly fine */
         if (deadline != INVALID_DEADLINE && ctrl->can_sleep) {
-            vlc_cond_timedwait(&ctrl->wait_request, lock, deadline);
+            vlc_cond_timedwait(wait_request, lock, deadline);
         }
     }
 
diff --git a/src/video_output/control.h b/src/video_output/control.h
index e06f4739c3b..55906f84723 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -43,8 +43,6 @@ typedef struct {
 void vout_control_cmd_Init(vout_control_cmd_t *, int type);
 
 typedef struct {
-    vlc_cond_t  wait_request;
-
     /* */
     bool is_dead;
     bool can_sleep;
@@ -65,7 +63,7 @@ void vout_control_Wake(vout_control_t *);
 /* control inside of the vout thread */
 #define INVALID_DEADLINE   ((vlc_tick_t) INT64_MAX)
 
-int vout_control_Pop(vout_control_t *, vout_control_cmd_t *, vlc_tick_t deadline, vlc_mutex_t *lock);
+int vout_control_Pop(vout_control_t *, vout_control_cmd_t *, vlc_tick_t deadline, vlc_cond_t *, vlc_mutex_t *);
 void vout_control_Dead(vout_control_t *);
 
 #endif
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 44f425c5bad..3fa04d4bb68 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -121,6 +121,7 @@ typedef struct vout_thread_sys_t
 
     /* Thread & synchronization */
     vlc_mutex_t     control_lock;
+    vlc_cond_t      has_pictures;
     vout_control_t  control;
     vlc_thread_t    thread;
 
@@ -408,6 +409,7 @@ void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
 
     vlc_mutex_lock(&sys->control_lock);
     vout_control_Push(&sys->control, &cmd);
+    vlc_cond_signal(&sys->has_pictures);
     vlc_mutex_unlock(&sys->control_lock);
 
     if (moved)
@@ -495,6 +497,7 @@ void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
     picture->p_next = NULL;
     vlc_mutex_lock(&sys->control_lock);
     picture_fifo_Push(sys->decoder_fifo, picture);
+    vlc_cond_signal(&sys->has_pictures);
     vout_control_Wake(&sys->control);
     vlc_mutex_unlock(&sys->control_lock);
 }
@@ -1848,7 +1851,8 @@ static void *Thread(void *object)
         }
 
         vlc_mutex_lock(&sys->control_lock);
-        while (!vout_control_Pop(&sys->control, &cmd, deadline, &sys->control_lock)) {
+        while (!vout_control_Pop(&sys->control, &cmd, deadline,
+                                 &sys->has_pictures, &sys->control_lock)) {
             switch(cmd.type) {
                 case VOUT_CONTROL_TERMINATE:
                     vlc_mutex_unlock(&sys->control_lock);
@@ -1921,6 +1925,8 @@ void vout_StopDisplay(vout_thread_t *vout)
 
     vlc_mutex_lock(&sys->control_lock);
     vout_control_PushVoid(&sys->control, VOUT_CONTROL_TERMINATE);
+    // stop waiting for pictures
+    vlc_cond_signal(&sys->has_pictures);
     vlc_mutex_unlock(&sys->control_lock);
     vlc_join(sys->thread, NULL);
 
@@ -2069,6 +2075,7 @@ vout_thread_t *vout_Create(vlc_object_t *object)
                spu_Create(vout, vout) : NULL;
 
     vlc_mutex_init(&sys->control_lock);
+    vlc_cond_init(&sys->has_pictures);
     vout_control_Init(&sys->control);
 
     sys->title.show     = var_InheritBool(vout, "video-title-show");
-- 
2.26.2



More information about the vlc-devel mailing list