[vlc-devel] [V2 PATCH 1/2] es_out: add ES_OUT_SET_VOUT_MOUSE_CALLBACKS

Steve Lhomme robux4 at ycbcr.xyz
Tue Jul 17 08:38:04 CEST 2018


On 2018-07-13 17:17, Thomas Guillem wrote:
> Allow demuxers to register mouse events for the current VIDEO ES. Demuxers
> won't have to register to the "intf-event" variable from the input and then
> register to mouse events from multiples vouts. Furthermore, there was a small
> (tiny) chance that the demuxers were registering to a wrong vout.

I like this a lot.

> ---
>   include/vlc_es_out.h             |  4 +++
>   include/vlc_mouse.h              |  3 ++
>   src/input/decoder.c              | 49 ++++++++++++++++++++++++++++++++
>   src/input/decoder.h              |  3 ++
>   src/input/es_out.c               | 10 +++++++
>   src/input/es_out_timeshift.c     |  9 ++++++
>   src/video_output/display.c       | 12 +++++---
>   src/video_output/video_output.c  |  3 +-
>   src/video_output/vout_internal.h |  2 +-
>   src/video_output/vout_intf.c     |  1 +
>   10 files changed, 90 insertions(+), 6 deletions(-)
>
> diff --git a/include/vlc_es_out.h b/include/vlc_es_out.h
> index c2a4212130..6364b1db45 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_SET_VOUT_MOUSE_CALLBACKS, /* arg1= es_out_id_t*
> +                                        arg2=vlc_mouse_event_cb,
> +                                        arg3=user_data, res=can fail */
> +
>       /* First value usable for private control */
>       ES_OUT_PRIVATE_START = 0x10000,
>   };
> diff --git a/include/vlc_mouse.h b/include/vlc_mouse.h
> index 481c3598e9..459e2d1d95 100644
> --- a/include/vlc_mouse.h
> +++ b/include/vlc_mouse.h
> @@ -53,6 +53,9 @@ typedef struct vlc_mouse_t
>       bool b_double_click;
>   } vlc_mouse_t;
>   
> +typedef void (*vlc_mouse_cb)(vlc_mouse_t *oldmouse, vlc_mouse_t *newmouse,
> +                             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..1f33bab2ad 100644
> --- a/src/input/decoder.c
> +++ b/src/input/decoder.c
> @@ -141,6 +141,10 @@ struct decoder_owner
>   
>       /* Delay */
>       vlc_tick_t i_ts_delay;
> +
> +    /* Mouse event */
> +    vlc_mouse_cb mouse_cb;
> +    void              *mouse_data;
>   };
>   
>   /* Pictures which are DECODER_BOGUS_VIDEO_DELAY or more in advance probably have
> @@ -279,6 +283,20 @@ static void DecoderUpdateFormatLocked( decoder_t *p_dec )
>       p_owner->b_fmt_description = true;
>   }
>   
> +static int MouseEvent( vlc_object_t *vout, char const *var,
> +                       vlc_value_t oldval, vlc_value_t val, void *data )
> +{
> +    decoder_t *dec = data;
> +    struct decoder_owner *owner = dec_get_owner( dec );
> +    vlc_mouse_t *mouses = val.p_address;
> +
> +    assert(owner->mouse_cb);
> +    owner->mouse_cb(&mouses[0], &mouses[1], owner->mouse_data);
> +
> +    return VLC_SUCCESS;
> +    (void) oldval; (void) var; (void) vout;
> +}
> +
>   /*****************************************************************************
>    * Buffers allocation callbacks for the decoders
>    *****************************************************************************/
> @@ -497,6 +515,8 @@ static int vout_update_format( decoder_t *p_dec )
>   
>           p_vout = p_owner->p_vout;
>           p_owner->p_vout = NULL;
> +        if( p_owner->mouse_cb && p_vout )
> +            var_DelCallback( p_vout, "mouse-event", MouseEvent, p_dec );
>           vlc_mutex_unlock( &p_owner->lock );
>   
>           unsigned dpb_size;
> @@ -527,6 +547,8 @@ static int vout_update_format( decoder_t *p_dec )
>   
>           DecoderUpdateFormatLocked( p_dec );
>           p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
> +        if( p_owner->mouse_cb )
> +            var_AddCallback( p_owner->p_vout, "mouse-event", MouseEvent, p_dec );
>           vlc_mutex_unlock( &p_owner->lock );
>   
>           if( p_owner->p_input != NULL )
> @@ -1731,6 +1753,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_cb = NULL;
> +    p_owner->mouse_data = NULL;
> +
>       es_format_Init( &p_owner->fmt, fmt->i_cat, 0 );
>   
>       /* decoder fifo */
> @@ -1864,6 +1889,9 @@ static void DeleteDecoder( decoder_t * p_dec )
>           case VIDEO_ES:
>               if( p_owner->p_vout )
>               {
> +                if( p_owner->mouse_cb )
> +                    var_DelCallback( p_owner->p_vout, "mouse-event",
> +                                     MouseEvent, p_dec );
>                   /* Reset the cancel state that was set before joining the decoder
>                    * thread */
>                   vout_Cancel( p_owner->p_vout, false );
> @@ -2446,3 +2474,24 @@ void input_DecoderGetObjects( decoder_t *p_dec,
>               vlc_object_hold( p_owner->p_aout ) : NULL;
>       vlc_mutex_unlock( &p_owner->lock );
>   }
> +
> +int input_DecoderSetVoutMouseCb( decoder_t *dec, vlc_mouse_cb cb,
> +                                 void *user_data )
> +{
> +    struct decoder_owner *owner = dec_get_owner( dec );
> +
> +    vlc_mutex_lock( &owner->lock );
> +    owner->mouse_cb = cb;
> +    owner->mouse_data = user_data;
> +    if( owner->p_vout )
> +    {
> +        if( owner->mouse_cb )
> +            var_AddCallback( owner->p_vout, "mouse-event", MouseEvent, dec );
> +        else
> +            var_DelCallback( owner->p_vout, "mouse-event", MouseEvent, dec );
> +        vlc_mutex_unlock( &owner->lock );
> +        return VLC_SUCCESS;
> +    }
> +    vlc_mutex_unlock( &owner->lock );
> +    return VLC_EGENERIC;
> +}
> diff --git a/src/input/decoder.h b/src/input/decoder.h
> index 2cfda8cc54..b3f1d894d9 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_DecoderSetVoutMouseCb( decoder_t *, vlc_mouse_cb, void * );
> +
>   #endif
> diff --git a/src/input/es_out.c b/src/input/es_out.c
> index 676e1816ce..f6c6b90817 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_SET_VOUT_MOUSE_CALLBACKS:
> +    {
> +        es_out_id_t *p_es = va_arg( args, es_out_id_t * );
> +        vlc_mouse_cb cb = va_arg( args, vlc_mouse_cb );
> +        void *user_data = va_arg( args, void * );
> +        if( p_es && p_es->p_dec )
> +            return input_DecoderSetVoutMouseCb( 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..21d584185d 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_SET_VOUT_MOUSE_CALLBACKS:
> +    {
> +        es_out_id_t *p_es = va_arg( args, es_out_id_t * );
> +        vlc_mouse_cb cb = va_arg( args, vlc_mouse_cb );
> +        void *user_data = va_arg( args, void * );
> +        return es_out_Control( p_sys->p_out, ES_OUT_SET_VOUT_MOUSE_CALLBACKS,
> +                               p_es->p_es, cb, user_data );
> +    }
>       /* Special internal input control */
>       case ES_OUT_GET_EMPTY:
>       {
> diff --git a/src/video_output/display.c b/src/video_output/display.c
> index 7f0b16c937..6505ce3f0c 100644
> --- a/src/video_output/display.c
> +++ b/src/video_output/display.c
> @@ -1314,13 +1314,17 @@ void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
>       }
>       vlc_mutex_unlock( &vout->p->filter.lock );
>   
> -    if (vlc_mouse_HasMoved(&vout->p->mouse, m))
> +    vout->p->mouses[0] = vout->p->mouses[1];
> +    vout->p->mouses[1] = *m;
> +
> +    if (vlc_mouse_HasMoved(&vout->p->mouses[0], &vout->p->mouses[1]))
>           var_SetCoords(vout, "mouse-moved", m->i_x, m->i_y);
>   
> -    if (vlc_mouse_HasButton(&vout->p->mouse, m)) {
> +    if (vlc_mouse_HasButton(&vout->p->mouses[0], &vout->p->mouses[1])) {
>           var_SetInteger(vout, "mouse-button-down", m->i_pressed);
>   
> -        if (vlc_mouse_HasPressed(&vout->p->mouse, m, MOUSE_BUTTON_LEFT)) {
> +        if (vlc_mouse_HasPressed(&vout->p->mouses[0], &vout->p->mouses[1],
> +                                 MOUSE_BUTTON_LEFT)) {
>               /* FIXME? */
>               int x, y;
>   
> @@ -1331,5 +1335,5 @@ 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;
> +    var_SetAddress(vout, "mouse-event", &vout->p->mouses);
>   }
> diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
> index 5db7acf509..6db01904d3 100644
> --- a/src/video_output/video_output.c
> +++ b/src/video_output/video_output.c
> @@ -1464,7 +1464,8 @@ static void ThreadExecuteViewpoint(vout_thread_t *vout,
>   
>   static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
>   {
> -    vlc_mouse_Init(&vout->p->mouse);
> +    vlc_mouse_Init(&vout->p->mouses[0]);
> +    vlc_mouse_Init(&vout->p->mouses[1]);
>       vout->p->decoder_fifo = picture_fifo_New();
>       vout->p->decoder_pool = NULL;
>       vout->p->display_pool = NULL;
> diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
> index b6940ba070..1ce0c4dca6 100644
> --- a/src/video_output/vout_internal.h
> +++ b/src/video_output/vout_internal.h
> @@ -137,7 +137,7 @@ struct vout_thread_sys_t
>       } filter;
>   
>       /* */
> -    vlc_mouse_t     mouse;
> +    vlc_mouse_t     mouses[2]; /* old, then new */
>   
>       /* */
>       picture_pool_t  *private_pool;
> diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
> index 8c7b4571d6..a81d50bd39 100644
> --- a/src/video_output/vout_intf.c
> +++ b/src/video_output/vout_intf.c
> @@ -287,6 +287,7 @@ void vout_IntfInit( vout_thread_t *p_vout )
>       var_AddCallback( p_vout, "sub-margin", SubMarginCallback, NULL );
>   
>       /* Mouse coordinates */
> +    var_Create( p_vout, "mouse-event", VLC_VAR_ADDRESS );
>       var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
>       var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
>       var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
> -- 
> 2.18.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list