[vlc-devel] [PATCH v2 10/13] vout/control: move the condition on pictures/control outside of the control API

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 17 15:15:29 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 | 8 +++++++-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index cf974f4e29c..5081433242b 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -38,8 +38,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);
@@ -60,14 +58,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)
@@ -79,12 +75,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 5e73d2fc3ab..69b5ebc4a0c 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -37,8 +37,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;
@@ -59,7 +57,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 3cdc849e507..28bee069927 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;
 
@@ -500,6 +501,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);
 }
@@ -1899,7 +1901,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);
@@ -1969,6 +1972,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);
 
@@ -2117,6 +2122,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