[vlc-devel] [PATCH v5 2/9] video_output: make a function per push command

Steve Lhomme robux4 at ycbcr.xyz
Fri Dec 18 10:21:25 UTC 2020


We pass the mouse data directly to vout_control_PushMouse(). No need to know
about vout_control_cmd_Init in video_output.c. It doesn't create commands
anymore.
---
 src/video_output/control.c      | 25 ++++++++++++++-----------
 src/video_output/control.h      | 11 +++--------
 src/video_output/video_output.c | 11 +++++------
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 3b7fabb07e9..fa5210bba9f 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -29,13 +29,6 @@
 #include "vout_internal.h"
 #include "control.h"
 
-/* */
-void vout_control_cmd_Init(vout_control_cmd_t *cmd, int type)
-{
-    memset(cmd, 0, sizeof(*cmd));
-    cmd->type = type;
-}
-
 /* */
 void vout_control_Init(vout_control_t *ctrl)
 {
@@ -63,7 +56,7 @@ void vout_control_Dead(vout_control_t *ctrl)
     vlc_mutex_unlock(&ctrl->lock);
 }
 
-void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
+static void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
 {
     vlc_mutex_lock(&ctrl->lock);
     if (!ctrl->is_dead) {
@@ -73,6 +66,15 @@ void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
     vlc_mutex_unlock(&ctrl->lock);
 }
 
+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,
+    };
+
+    vout_control_Push(ctrl, &cmd);
+}
+
 void vout_control_Wake(vout_control_t *ctrl)
 {
     vlc_mutex_lock(&ctrl->lock);
@@ -81,11 +83,12 @@ void vout_control_Wake(vout_control_t *ctrl)
     vlc_mutex_unlock(&ctrl->lock);
 }
 
-void vout_control_PushVoid(vout_control_t *ctrl, int type)
+void vout_control_PushTerminate(vout_control_t *ctrl)
 {
-    vout_control_cmd_t cmd;
+    vout_control_cmd_t cmd = {
+        VOUT_CONTROL_TERMINATE, {0},
+    };
 
-    vout_control_cmd_Init(&cmd, type);
     vout_control_Push(ctrl, &cmd);
 }
 
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 6fb299e139c..5976a0f6750 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -34,14 +34,9 @@ enum {
 
 typedef struct {
     int type;
-
-    union {
-        vlc_mouse_t mouse;
-    };
+    vlc_mouse_t mouse;
 } vout_control_cmd_t;
 
-void vout_control_cmd_Init(vout_control_cmd_t *, int type);
-
 typedef struct {
     vlc_mutex_t lock;
     vlc_cond_t  wait_request;
@@ -60,8 +55,8 @@ void vout_control_Init(vout_control_t *);
 void vout_control_Clean(vout_control_t *);
 
 /* controls outside of the vout thread */
-void vout_control_Push(vout_control_t *, vout_control_cmd_t *);
-void vout_control_PushVoid(vout_control_t *, int type);
+void vout_control_PushMouse(vout_control_t *, const vlc_mouse_t *);
+void vout_control_PushTerminate(vout_control_t *);
 void vout_control_Wake(vout_control_t *);
 void vout_control_Hold(vout_control_t *);
 void vout_control_Release(vout_control_t *);
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 57ee54e6e8b..29b8b140e09 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -382,18 +382,17 @@ 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);
 
     /* Translate window coordinates to video coordinates */
     vlc_mutex_lock(&sys->display_lock);
+    vlc_mouse_t video_mouse;
     if (sys->display)
-        vout_display_TranslateMouseState(sys->display, &cmd.mouse, mouse);
+        vout_display_TranslateMouseState(sys->display, &video_mouse, mouse);
     else
-        cmd.mouse = *mouse;
+        video_mouse = *mouse;
     vlc_mutex_unlock(&sys->display_lock);
 
-    vout_control_Push(&sys->control, &cmd);
+    vout_control_PushMouse(&sys->control, &video_mouse);
 }
 
 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
@@ -1972,7 +1971,7 @@ void vout_StopDisplay(vout_thread_t *vout)
 {
     vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
 
-    vout_control_PushVoid(&sys->control, VOUT_CONTROL_TERMINATE);
+    vout_control_PushTerminate(&sys->control);
     vlc_join(sys->thread, NULL);
 
     vout_ReleaseDisplay(sys);
-- 
2.29.2



More information about the vlc-devel mailing list