[vlc-devel] [V4 PATCH 1/9] vout: set a mouse event cb when creating a vout

Thomas Guillem thomas at gllm.fr
Tue Jul 17 17:00:16 CEST 2018


---
 include/vlc_mouse.h              |  8 ++++++++
 src/input/decoder.c              |  6 +++---
 src/input/resource.c             | 15 +++++++++++----
 src/input/resource.h             |  5 ++++-
 src/video_output/display.c       |  3 +++
 src/video_output/video_output.c  | 28 +++++++++++++++++++++-------
 src/video_output/vout_internal.h |  4 ++++
 7 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/include/vlc_mouse.h b/include/vlc_mouse.h
index 481c3598e9..dfdf99f680 100644
--- a/include/vlc_mouse.h
+++ b/include/vlc_mouse.h
@@ -53,6 +53,14 @@ typedef struct vlc_mouse_t
     bool b_double_click;
 } vlc_mouse_t;
 
+/**
+ * Mouse event callback
+ * @param mouse new mouse event to process, can be NULL for an invalidate state
+ * (a new vout is created or restarted).
+ * @param user_data
+ */
+typedef void (*vlc_mouse_event)(const vlc_mouse_t *mouse, void *user_data);
+
 static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
 {
     p_mouse->i_x = 0;
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 1cba292d14..6af9ca8479 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -291,7 +291,7 @@ static vout_thread_t *aout_request_vout( void *p_private,
     input_thread_t *p_input = p_owner->p_input;
 
     p_vout = input_resource_RequestVout( p_owner->p_resource, p_vout, p_fmt, 1,
-                                         b_recyle );
+                                         NULL, NULL, b_recyle );
     if( p_input != NULL )
         input_SendEventVout( p_input );
 
@@ -521,7 +521,7 @@ static int vout_update_format( decoder_t *p_dec )
                                              p_vout, &fmt,
                                              dpb_size +
                                              p_dec->i_extra_picture_buffers + 1,
-                                             true );
+                                             NULL, NULL, true );
         vlc_mutex_lock( &p_owner->lock );
         p_owner->p_vout = p_vout;
 
@@ -1869,7 +1869,7 @@ static void DeleteDecoder( decoder_t * p_dec )
                 vout_Cancel( p_owner->p_vout, false );
 
                 input_resource_RequestVout( p_owner->p_resource, p_owner->p_vout, NULL,
-                                            0, true );
+                                            0, NULL, NULL, true );
                 if( p_owner->p_input != NULL )
                     input_SendEventVout( p_owner->p_input );
             }
diff --git a/src/input/resource.c b/src/input/resource.c
index b1a8675dc3..44854952a0 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -196,7 +196,8 @@ static void DisplayVoutTitle( input_resource_t *p_resource,
 static vout_thread_t *RequestVout( input_resource_t *p_resource,
                                    vout_thread_t *p_vout,
                                    const video_format_t *p_fmt, unsigned dpb_size,
-                                   bool b_recycle )
+                                   vlc_mouse_event  mouse_event,
+                                   void *opaque, bool b_recycle )
 {
     vlc_assert_locked( &p_resource->lock );
 
@@ -237,6 +238,8 @@ static vout_thread_t *RequestVout( input_resource_t *p_resource,
             .change_fmt = true,
             .fmt        = p_fmt,
             .dpb_size   = dpb_size,
+            .mouse_event= mouse_event,
+            .opaque = opaque,
         };
         p_vout = vout_Request( p_resource->p_parent, &cfg );
         if( !p_vout )
@@ -282,6 +285,8 @@ static vout_thread_t *RequestVout( input_resource_t *p_resource,
                 .change_fmt = false,
                 .fmt        = NULL,
                 .dpb_size   = 0,
+                .mouse_event= NULL,
+                .opaque = NULL,
             };
             p_resource->p_vout_free = vout_Request( p_resource->p_parent, &cfg );
         }
@@ -466,10 +471,12 @@ void input_resource_SetInput( input_resource_t *p_resource, input_thread_t *p_in
 vout_thread_t *input_resource_RequestVout( input_resource_t *p_resource,
                                             vout_thread_t *p_vout,
                                             const video_format_t *p_fmt, unsigned dpb_size,
-                                            bool b_recycle )
+                                            vlc_mouse_event mouse_event,
+                                            void *opaque, bool b_recycle )
 {
     vlc_mutex_lock( &p_resource->lock );
-    vout_thread_t *p_ret = RequestVout( p_resource, p_vout, p_fmt, dpb_size, b_recycle );
+    vout_thread_t *p_ret = RequestVout( p_resource, p_vout, p_fmt, dpb_size,
+                                        mouse_event, opaque, b_recycle );
     vlc_mutex_unlock( &p_resource->lock );
 
     return p_ret;
@@ -487,7 +494,7 @@ void input_resource_HoldVouts( input_resource_t *p_resource, vout_thread_t ***pp
 
 void input_resource_TerminateVout( input_resource_t *p_resource )
 {
-    input_resource_RequestVout( p_resource, NULL, NULL, 0, false );
+    input_resource_RequestVout( p_resource, NULL, NULL, 0, NULL, NULL, false );
 }
 bool input_resource_HasVout( input_resource_t *p_resource )
 {
diff --git a/src/input/resource.h b/src/input/resource.h
index 8f83eb3183..8011a59edb 100644
--- a/src/input/resource.h
+++ b/src/input/resource.h
@@ -25,6 +25,7 @@
 #define LIBVLC_INPUT_RESOURCE_H 1
 
 #include <vlc_common.h>
+#include <vlc_mouse.h>
 
 /**
  * This function set the associated input.
@@ -40,7 +41,9 @@ sout_instance_t *input_resource_RequestSout( input_resource_t *, sout_instance_t
  * This function handles vout request.
  */
 vout_thread_t *input_resource_RequestVout( input_resource_t *, vout_thread_t *,
-                                           const video_format_t *, unsigned dpb_size, bool b_recycle );
+                                           const video_format_t *, unsigned dpb_size,
+                                           vlc_mouse_event  mouse_event,
+                                           void *mouse_event_data, bool b_recycle );
 
 /**
  * This function returns one of the current vout if any.
diff --git a/src/video_output/display.c b/src/video_output/display.c
index 7f0b16c937..e9d03d7563 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -1332,4 +1332,7 @@ void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
     if (m->b_double_click)
         var_ToggleBool(vout, "fullscreen");
     vout->p->mouse = *m;
+
+    if (vout->p->mouse_event)
+        vout->p->mouse_event(m, vout->p->opaque);
 }
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 5db7acf509..43e55b163b 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -134,6 +134,8 @@ static vout_thread_t *VoutCreate(vlc_object_t *object,
 
     vout->p->original = original;
     vout->p->dpb_size = cfg->dpb_size;
+    vout->p->mouse_event = cfg->mouse_event;
+    vout->p->opaque = cfg->opaque;
 
     vout_control_Init(&vout->p->control);
     vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_INIT);
@@ -242,15 +244,14 @@ vout_thread_t *vout_Request(vlc_object_t *object,
                 spu_Attach(vout->p->spu, vout->p->input, true);
         }
 
-        if (cfg->change_fmt) {
-            vout_control_cmd_t cmd;
-            vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
-            cmd.cfg = cfg;
+        vout_control_cmd_t cmd;
+        vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
+        cmd.cfg = cfg;
+        vout_control_Push(&vout->p->control, &cmd);
+        vout_control_WaitEmpty(&vout->p->control);
 
-            vout_control_Push(&vout->p->control, &cmd);
-            vout_control_WaitEmpty(&vout->p->control);
+        if (cfg->change_fmt)
             vout_IntfReinit(vout);
-        }
 
         if (!vout->p->dead) {
             msg_Dbg(object, "reusing provided vout");
@@ -1570,6 +1571,9 @@ static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
     if (vout->p->decoder_fifo)
         picture_fifo_Delete(vout->p->decoder_fifo);
     assert(!vout->p->decoder_pool);
+
+    if (vout->p->mouse_event)
+        vout->p->mouse_event(NULL, vout->p->opaque);
 }
 
 static void ThreadInit(vout_thread_t *vout)
@@ -1594,6 +1598,16 @@ static int ThreadReinit(vout_thread_t *vout,
 {
     video_format_t original;
 
+    if (!cfg->change_fmt)
+    {
+        vout->p->mouse_event = NULL;
+        vout->p->opaque = NULL;
+        return VLC_SUCCESS;
+    }
+
+    vout->p->mouse_event = cfg->mouse_event;
+    vout->p->opaque = cfg->opaque;
+
     vout->p->pause.is_on = false;
     vout->p->pause.date  = VLC_TICK_INVALID;
 
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index b6940ba070..155efdf189 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -50,6 +50,8 @@ typedef struct {
     bool                 change_fmt;
     const video_format_t *fmt;
     unsigned             dpb_size;
+    vlc_mouse_event      mouse_event;
+    void                 *opaque;
 } vout_configuration_t;
 #include "control.h"
 
@@ -138,6 +140,8 @@ struct vout_thread_sys_t
 
     /* */
     vlc_mouse_t     mouse;
+    vlc_mouse_event mouse_event;
+    void            *opaque;
 
     /* */
     picture_pool_t  *private_pool;
-- 
2.18.0



More information about the vlc-devel mailing list