[vlc-devel] [PATCH v2 11/13] video_output: use an internal bool to detect when we must exit the vout thread

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 17 15:15:30 CEST 2020


Also exit after rendering, before we loop again an potentially wait for new
pictures.

Remove the related push functions and vout_control_Dead() since we don't push
any commands anymore.
---
 src/video_output/control.c      | 21 ---------------------
 src/video_output/control.h      |  8 --------
 src/video_output/video_output.c | 18 ++++++++++--------
 3 files changed, 10 insertions(+), 37 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 5081433242b..80c0def5c72 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -38,7 +38,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *cmd, int type)
 /* */
 void vout_control_Init(vout_control_t *ctrl)
 {
-    ctrl->is_dead = false;
     ctrl->can_sleep = true;
     ARRAY_INIT(ctrl->cmd);
 }
@@ -49,31 +48,11 @@ void vout_control_Clean(vout_control_t *ctrl)
     ARRAY_RESET(ctrl->cmd);
 }
 
-void vout_control_Dead(vout_control_t *ctrl)
-{
-    ctrl->is_dead = true;
-}
-
-void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
-{
-    if (!ctrl->is_dead) {
-        ARRAY_APPEND(ctrl->cmd, *cmd);
-    }
-}
-
 void vout_control_Wake(vout_control_t *ctrl)
 {
     ctrl->can_sleep = false;
 }
 
-void vout_control_PushVoid(vout_control_t *ctrl, int type)
-{
-    vout_control_cmd_t cmd;
-
-    vout_control_cmd_Init(&cmd, type);
-    vout_control_Push(ctrl, &cmd);
-}
-
 int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
                      vlc_tick_t deadline, vlc_cond_t *wait_request, vlc_mutex_t *lock)
 {
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 69b5ebc4a0c..6e904ba35b4 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -26,10 +26,6 @@
 #include <vlc_viewpoint.h>
 
 /* */
-enum {
-    VOUT_CONTROL_TERMINATE,
-};
-
 typedef struct {
     int type;
 } vout_control_cmd_t;
@@ -38,7 +34,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *, int type);
 
 typedef struct {
     /* */
-    bool is_dead;
     bool can_sleep;
     DECL_ARRAY(vout_control_cmd_t) cmd;
 } vout_control_t;
@@ -50,14 +45,11 @@ void vout_control_Clean(vout_control_t *);
 /* controls outside of the vout thread */
 void vout_control_WaitEmpty(vout_control_t *);
 
-void vout_control_Push(vout_control_t *, vout_control_cmd_t *);
-void vout_control_PushVoid(vout_control_t *, int type);
 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_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 28bee069927..8d1c3cab9fb 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -124,6 +124,7 @@ typedef struct vout_thread_sys_t
     vlc_cond_t      has_pictures;
     vout_control_t  control;
     vlc_thread_t    thread;
+    atomic_bool     terminate;
 
     struct {
         vlc_tick_t  date;
@@ -1903,16 +1904,19 @@ static void *Thread(void *object)
         vlc_mutex_lock(&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);
-                    return NULL; /* no need to clean &cmd */
+            if (atomic_load(&sys->terminate))
+            {
+                vlc_mutex_unlock(&sys->control_lock);
+                return NULL;
             }
         }
         vlc_mutex_unlock(&sys->control_lock);
 
         wait = ThreadDisplayPicture(vout, &deadline) != VLC_SUCCESS;
 
+        if (atomic_load(&sys->terminate))
+            return NULL;
+
         const bool picture_interlaced = sys->displayed.is_interlaced;
 
         vout_SetInterlacingState(&vout->obj, &sys->private, picture_interlaced);
@@ -1971,7 +1975,7 @@ void vout_StopDisplay(vout_thread_t *vout)
     vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
 
     vlc_mutex_lock(&sys->control_lock);
-    vout_control_PushVoid(&sys->control, VOUT_CONTROL_TERMINATE);
+    atomic_store(&sys->terminate, true);
     // stop waiting for pictures
     vlc_cond_signal(&sys->has_pictures);
     vlc_mutex_unlock(&sys->control_lock);
@@ -2013,9 +2017,6 @@ void vout_Close(vout_thread_t *vout)
 
     vout_IntfDeinit(VLC_OBJECT(vout));
     vout_snapshot_End(sys->snapshot);
-    vlc_mutex_lock(&sys->control_lock);
-    vout_control_Dead(&sys->control);
-    vlc_mutex_unlock(&sys->control_lock);
     vout_chrono_Clean(&sys->render);
 
     if (sys->spu)
@@ -2124,6 +2125,7 @@ vout_thread_t *vout_Create(vlc_object_t *object)
     vlc_mutex_init(&sys->control_lock);
     vlc_cond_init(&sys->has_pictures);
     vout_control_Init(&sys->control);
+    atomic_init(&sys->terminate, false);
 
     sys->title.show     = var_InheritBool(vout, "video-title-show");
     sys->title.timeout  = var_InheritInteger(vout, "video-title-timeout");
-- 
2.26.2



More information about the vlc-devel mailing list