[vlc-devel] [PATCH v3 15/18] video_output: move the mouse events handling outside of the control pop

Steve Lhomme robux4 at ycbcr.xyz
Tue Aug 18 16:58:42 CEST 2020


We manage a local array of vlc_mouse_t.

We exited the loop if no command was found or we were asked to terminate.
---
 src/video_output/video_output.c | 40 ++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index e0f5914df86..60363fe2d90 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -123,6 +123,7 @@ typedef struct vout_thread_sys_t
     vlc_mutex_t     control_lock;
     vlc_cond_t      has_pictures;
     bool            terminate;
+    DECL_ARRAY(vlc_mouse_t) mouse_events;
     vout_control_t  control;
     vlc_thread_t    thread;
 
@@ -392,12 +393,9 @@ void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
     vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
     assert(!sys->dummy);
     assert(mouse);
-    vout_control_cmd_t cmd;
-    vout_control_cmd_Init(&cmd, VOUT_CONTROL_MOUSE_STATE);
-    cmd.mouse = *mouse;
 
     vlc_mutex_lock(&sys->control_lock);
-    vout_control_Push(&sys->control, &cmd);
+    ARRAY_APPEND(sys->mouse_events, *mouse);
     vlc_cond_signal(&sys->has_pictures);
     vlc_mutex_unlock(&sys->control_lock);
 }
@@ -1845,8 +1843,6 @@ static void *Thread(void *object)
     bool wait = false;
 
     for (;;) {
-        vout_control_cmd_t cmd;
-
         if (wait)
         {
             if (deadline != INVALID_DEADLINE)
@@ -1858,19 +1854,37 @@ 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)) {
+        for (;;)
+        {
             if (sys->terminate)
             {
                 vlc_mutex_unlock(&sys->control_lock);
                 return NULL;
             }
 
-            switch(cmd.type) {
-                case VOUT_CONTROL_MOUSE_STATE:
-                    ThreadProcessMouseState(vout, &cmd.mouse);
+            if (sys->mouse_events.i_size <= 0)
+            {
+                if (deadline == INVALID_DEADLINE)
                     break;
+                vlc_cond_timedwait(&sys->has_pictures, &sys->control_lock, deadline);
+
+                if (sys->mouse_events.i_size <= 0)
+                    break;
+            }
+
+            if (sys->terminate)
+            {
+                vlc_mutex_unlock(&sys->control_lock);
+                return NULL;
             }
+
+            vlc_mouse_t event = ARRAY_VAL(sys->mouse_events, 0);
+            ARRAY_REMOVE(sys->mouse_events, 0);
+            vlc_mutex_unlock(&sys->control_lock);
+
+            ThreadProcessMouseState(vout, &event);
+
+            vlc_mutex_lock(&sys->control_lock);
         }
         vlc_mutex_unlock(&sys->control_lock);
 
@@ -2003,7 +2017,7 @@ void vout_Release(vout_thread_t *vout)
     assert(!sys->window_enabled);
     vout_display_window_Delete(sys->display_cfg.window);
 
-    vout_control_Clean(&sys->control);
+    ARRAY_RESET(sys->mouse_events);
 
     /* */
     vout_statistic_Clean(&sys->statistic);
@@ -2081,7 +2095,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);
+    ARRAY_INIT(sys->mouse_events);
     sys->terminate = false;
 
     sys->title.show     = var_InheritBool(vout, "video-title-show");
-- 
2.26.2



More information about the vlc-devel mailing list