[vlc-devel] [PATCH v3 6/8] video_output: pop mouse events and terminated state from the control FIFO

Steve Lhomme robux4 at ycbcr.xyz
Fri Dec 18 06:42:12 UTC 2020


The terminate state is always reported. So we don't wait anymore until all
mouse events are processed before the TERMINATE command is handled.

The command array is now a mouse state array.
---
 src/video_output/control.c      | 17 ++++++-----------
 src/video_output/control.h      | 15 ++-------------
 src/video_output/video_output.c | 19 +++++++++----------
 3 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 15b3e5d2adc..56f105f4bbd 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -51,12 +51,8 @@ void vout_control_Clean(vout_control_t *ctrl)
 
 void vout_control_PushMouse(vout_control_t *ctrl, const vlc_mouse_t *video_mouse)
 {
-    vout_control_cmd_t cmd = {
-        VOUT_CONTROL_MOUSE_STATE, *video_mouse,
-    };
-
     vlc_mutex_lock(&ctrl->lock);
-    ARRAY_APPEND(ctrl->cmd, cmd);
+    ARRAY_APPEND(ctrl->cmd, *video_mouse);
     vlc_cond_signal(&ctrl->wait_request);
     vlc_mutex_unlock(&ctrl->lock);
 }
@@ -95,8 +91,8 @@ void vout_control_Release(vout_control_t *ctrl)
     vlc_mutex_unlock(&ctrl->lock);
 }
 
-int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
-                     vlc_tick_t deadline)
+int vout_control_Pop(vout_control_t *ctrl, vlc_mouse_t *mouse,
+                     bool *is_terminated, vlc_tick_t deadline)
 {
     bool has_cmd = false;
     vlc_mutex_lock(&ctrl->lock);
@@ -114,19 +110,18 @@ int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
     while (ctrl->is_held)
         vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
 
-    if (ctrl->is_terminated) {
-        *cmd = (vout_control_cmd_t) { VOUT_CONTROL_TERMINATE, {0} };
+    if (ctrl->is_terminated)
         goto done;
-    }
 
     if (ctrl->cmd.i_size > 0) {
         has_cmd = true;
-        *cmd = ARRAY_VAL(ctrl->cmd, 0);
+        *mouse = ARRAY_VAL(ctrl->cmd, 0);
         ARRAY_REMOVE(ctrl->cmd, 0);
     } else {
         ctrl->can_sleep = true;
     }
 done:
+    *is_terminated = ctrl->is_terminated;
     vlc_mutex_unlock(&ctrl->lock);
 
     return has_cmd ? VLC_SUCCESS : VLC_EGENERIC;
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 684ad909b59..ce2c480879c 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -26,17 +26,6 @@
 #include <vlc_viewpoint.h>
 
 /* */
-enum {
-    VOUT_CONTROL_TERMINATE,
-
-    VOUT_CONTROL_MOUSE_STATE,           /* vlc_mouse_t */
-};
-
-typedef struct {
-    int type;
-    vlc_mouse_t mouse;
-} vout_control_cmd_t;
-
 typedef struct {
     vlc_mutex_t lock;
     vlc_cond_t  wait_request;
@@ -47,7 +36,7 @@ typedef struct {
     bool is_waiting;
     bool is_held;
     bool is_terminated;
-    DECL_ARRAY(vout_control_cmd_t) cmd;
+    DECL_ARRAY(vlc_mouse_t) cmd;
 } vout_control_t;
 
 /* */
@@ -62,6 +51,6 @@ void vout_control_Hold(vout_control_t *);
 void vout_control_Release(vout_control_t *);
 
 /* control inside of the vout thread */
-int vout_control_Pop(vout_control_t *, vout_control_cmd_t *, vlc_tick_t deadline);
+int vout_control_Pop(vout_control_t *, vlc_mouse_t *, bool *, vlc_tick_t deadline);
 
 #endif
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index e3e9b112679..3cbc3d69d39 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1892,8 +1892,6 @@ static void *Thread(void *object)
     bool wait = false;
 
     for (;;) {
-        vout_control_cmd_t cmd;
-
         if (wait)
         {
             const vlc_tick_t max_deadline = vlc_tick_now() + VLC_TICK_FROM_MS(100);
@@ -1902,22 +1900,23 @@ static void *Thread(void *object)
             deadline = VLC_TICK_INVALID;
         }
 
-        while (!vout_control_Pop(&sys->control, &cmd, deadline)) {
-            switch(cmd.type) {
-                case VOUT_CONTROL_TERMINATE:
-                    return NULL; /* no need to clean &cmd */
-                case VOUT_CONTROL_MOUSE_STATE:
-                    ThreadProcessMouseState(vout, &cmd.mouse);
-                    break;
-            }
+        bool terminated = false;
+        vlc_mouse_t video_mouse;
+        while (vout_control_Pop(&sys->control, &video_mouse, &terminated,
+                                deadline) == VLC_SUCCESS && !terminated) {
+            ThreadProcessMouseState(vout, &video_mouse);
         }
 
+        if (terminated)
+            break;
+
         wait = ThreadDisplayPicture(vout, &deadline) != VLC_SUCCESS;
 
         const bool picture_interlaced = sys->displayed.is_interlaced;
 
         vout_SetInterlacingState(&vout->obj, &sys->private, picture_interlaced);
     }
+    return NULL;
 }
 
 static void vout_ReleaseDisplay(vout_thread_sys_t *vout)
-- 
2.29.2



More information about the vlc-devel mailing list