[vlc-devel] [V4 PATCH 2/9] es_out: add ES_OUT_SET_VOUT_MOUSE_EVENT

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


This a new preferred method to get mouse events from demuxers (instead of
registering to "intf-event" from the p_input and registering to mouse events
from any vouts).
---
 include/vlc_es_out.h         |  4 ++++
 src/input/decoder.c          | 40 +++++++++++++++++++++++++++++++++++-
 src/input/decoder.h          |  3 +++
 src/input/es_out.c           | 10 +++++++++
 src/input/es_out_timeshift.c |  9 ++++++++
 5 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/include/vlc_es_out.h b/include/vlc_es_out.h
index c2a4212130..bdf5a0f046 100644
--- a/include/vlc_es_out.h
+++ b/include/vlc_es_out.h
@@ -98,6 +98,10 @@ enum es_out_query_e
 
     ES_OUT_POST_SUBNODE, /* arg1=input_item_node_t *, res=can fail */
 
+    ES_OUT_VOUT_SET_MOUSE_EVENT, /* arg1= es_out_id_t* (video es),
+                                    arg2=vlc_mouse_event, arg3=void *(user_data),
+                                    res=can fail */
+
     /* First value usable for private control */
     ES_OUT_PRIVATE_START = 0x10000,
 };
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 6af9ca8479..871333551f 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -141,6 +141,11 @@ struct decoder_owner
 
     /* Delay */
     vlc_tick_t i_ts_delay;
+
+    /* Mouse event */
+    vlc_mutex_t     mouse_lock;
+    vlc_mouse_event mouse_event;
+    void           *opaque;
 };
 
 /* Pictures which are DECODER_BOGUS_VIDEO_DELAY or more in advance probably have
@@ -279,6 +284,17 @@ static void DecoderUpdateFormatLocked( decoder_t *p_dec )
     p_owner->b_fmt_description = true;
 }
 
+static void MouseEvent( const vlc_mouse_t *newmouse, void *user_data )
+{
+    decoder_t *dec = user_data;
+    struct decoder_owner *owner = dec_get_owner( dec );
+
+    vlc_mutex_lock( &owner->mouse_lock );
+    if( owner->mouse_event )
+        owner->mouse_event( newmouse, owner->opaque);
+    vlc_mutex_unlock( &owner->mouse_lock );
+}
+
 /*****************************************************************************
  * Buffers allocation callbacks for the decoders
  *****************************************************************************/
@@ -521,7 +537,7 @@ static int vout_update_format( decoder_t *p_dec )
                                              p_vout, &fmt,
                                              dpb_size +
                                              p_dec->i_extra_picture_buffers + 1,
-                                             NULL, NULL, true );
+                                             MouseEvent, p_dec, true );
         vlc_mutex_lock( &p_owner->lock );
         p_owner->p_vout = p_vout;
 
@@ -1731,6 +1747,9 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     atomic_init( &p_owner->reload, RELOAD_NO_REQUEST );
     p_owner->b_idle = false;
 
+    p_owner->mouse_event = NULL;
+    p_owner->opaque = NULL;
+
     es_format_Init( &p_owner->fmt, fmt->i_cat, 0 );
 
     /* decoder fifo */
@@ -1742,6 +1761,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     }
 
     vlc_mutex_init( &p_owner->lock );
+    vlc_mutex_init( &p_owner->mouse_lock );
     vlc_cond_init( &p_owner->wait_request );
     vlc_cond_init( &p_owner->wait_acknowledge );
     vlc_cond_init( &p_owner->wait_fifo );
@@ -1908,6 +1928,7 @@ static void DeleteDecoder( decoder_t * p_dec )
     vlc_cond_destroy( &p_owner->wait_acknowledge );
     vlc_cond_destroy( &p_owner->wait_request );
     vlc_mutex_destroy( &p_owner->lock );
+    vlc_mutex_destroy( &p_owner->mouse_lock );
 
     vlc_object_release( p_dec );
 }
@@ -2446,3 +2467,20 @@ void input_DecoderGetObjects( decoder_t *p_dec,
             vlc_object_hold( p_owner->p_aout ) : NULL;
     vlc_mutex_unlock( &p_owner->lock );
 }
+
+int input_DecoderSetVoutMouseEvent( decoder_t *dec, vlc_mouse_event mouse_event,
+                                    void *user_data )
+{
+    struct decoder_owner *owner = dec_get_owner( dec );
+
+    if( dec->fmt_out.i_cat != VIDEO_ES )
+        return VLC_EGENERIC;
+
+    vlc_mutex_lock( &owner->mouse_lock );
+
+    owner->mouse_event = mouse_event;
+    owner->opaque = user_data;
+
+    vlc_mutex_unlock( &owner->mouse_lock );
+    return VLC_SUCCESS;
+}
diff --git a/src/input/decoder.h b/src/input/decoder.h
index 2cfda8cc54..e7db86842e 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -27,6 +27,7 @@
 
 #include <vlc_common.h>
 #include <vlc_codec.h>
+#include <vlc_mouse.h>
 
 decoder_t *input_DecoderNew( input_thread_t *, es_format_t *, input_clock_t *,
                              sout_instance_t * ) VLC_USED;
@@ -116,4 +117,6 @@ size_t input_DecoderGetFifoSize( decoder_t *p_dec );
  */
 void input_DecoderGetObjects( decoder_t *, vout_thread_t **, audio_output_t ** );
 
+int  input_DecoderSetVoutMouseEvent( decoder_t *, vlc_mouse_event, void * );
+
 #endif
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 676e1816ce..75c33a4400 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2876,6 +2876,16 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
         return VLC_SUCCESS;
     }
 
+    case ES_OUT_VOUT_SET_MOUSE_EVENT:
+    {
+        es_out_id_t *p_es = va_arg( args, es_out_id_t * );
+        vlc_mouse_event cb = va_arg( args, vlc_mouse_event );
+        void *user_data = va_arg( args, void * );
+        if( p_es && p_es->p_dec )
+            return input_DecoderSetVoutMouseEvent( p_es->p_dec, cb, user_data );
+        return VLC_EGENERIC;
+    }
+
     default:
         msg_Err( p_sys->p_input, "unknown query 0x%x in %s", i_query,
                  __func__  );
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index d17a8f8f2b..1ac501beff 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -40,6 +40,7 @@
 
 #include <vlc_common.h>
 #include <vlc_fs.h>
+#include <vlc_mouse.h>
 #ifdef _WIN32
 #  include <vlc_charset.h>
 #endif
@@ -652,6 +653,14 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
         }
         return es_out_Control( p_sys->p_out, ES_OUT_GET_ES_STATE, p_es->p_es, pb_enabled );
     }
+    case ES_OUT_VOUT_SET_MOUSE_EVENT:
+    {
+        es_out_id_t *p_es = va_arg( args, es_out_id_t * );
+        vlc_mouse_event cb = va_arg( args, vlc_mouse_event );
+        void *user_data = va_arg( args, void * );
+        return es_out_Control( p_sys->p_out, ES_OUT_VOUT_SET_MOUSE_EVENT,
+                               p_es->p_es, cb, user_data );
+    }
     /* Special internal input control */
     case ES_OUT_GET_EMPTY:
     {
-- 
2.18.0



More information about the vlc-devel mailing list