vlc | branch: master | Filip Roséen <[email protected]> | Thu Jul 19 19:53:21 2018 +0200| [19b4ae52e7233f7aaa8d7f30efa564e1577896e1] | committer: Thomas Guillem
demux: mkv: use ES_OUT_VOUT_SET_MOUSE_EVENT > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=19b4ae52e7233f7aaa8d7f30efa564e1577896e1 --- modules/demux/mkv/events.cpp | 121 ++++++++++++++----------------------------- modules/demux/mkv/events.hpp | 27 +++++++--- 2 files changed, 59 insertions(+), 89 deletions(-) diff --git a/modules/demux/mkv/events.cpp b/modules/demux/mkv/events.cpp index 483d98fe56..ba9718522d 100644 --- a/modules/demux/mkv/events.cpp +++ b/modules/demux/mkv/events.cpp @@ -91,22 +91,20 @@ void event_thread_t::ResetPci() vlc_join( thread, NULL ); is_running = false; } -int event_thread_t::EventMouse( vlc_object_t *p_this, char const *psz_var, - vlc_value_t, vlc_value_t, void *p_data ) + +void event_thread_t::EventMouse( vlc_mouse_t const* new_state, void* userdata ) { - event_thread_t *p_ev = (event_thread_t *) p_data; - vlc_mutex_lock( &p_ev->lock ); - if( psz_var[6] == 'c' ) - { - p_ev->b_clicked = true; - msg_Dbg( p_this, "Event Mouse: clicked"); - } - else if( psz_var[6] == 'm' ) - p_ev->b_moved = true; - vlc_cond_signal( &p_ev->wait ); - vlc_mutex_unlock( &p_ev->lock ); + ESInfo* info = static_cast<ESInfo*>( userdata ); + vlc_mutex_locker lock_guard( &info->owner.lock ); - return VLC_SUCCESS; + if( !new_state ) + return vlc_mouse_Init( &info->mouse_state ); + + info->owner.pending_events.push_back( + EventInfo( info, info->mouse_state, *new_state ) ); + + vlc_cond_signal( &info->owner.wait ); + info->mouse_state = *new_state; } int event_thread_t::EventKey( vlc_object_t *p_this, char const *, @@ -122,43 +120,20 @@ int event_thread_t::EventKey( vlc_object_t *p_this, char const *, return VLC_SUCCESS; } -int event_thread_t::EventInput( vlc_object_t *p_this, char const *, - vlc_value_t, vlc_value_t newval, void *p_data ) -{ - VLC_UNUSED( p_this ); - event_thread_t *p_ev = (event_thread_t *) p_data; - vlc_mutex_lock( &p_ev->lock ); - if( newval.i_int == INPUT_EVENT_VOUT ) - { - p_ev->b_vout |= true; - vlc_cond_signal( &p_ev->wait ); - } - vlc_mutex_unlock( &p_ev->lock ); - - return VLC_SUCCESS; -} - void event_thread_t::EventThread() { - demux_sys_t *p_sys = (demux_sys_t *)p_demux->p_sys; - vlc_object_t *p_vout = NULL; int canc = vlc_savecancel (); - b_moved = false; - b_clicked = false; i_key_action = 0; - b_vout = true; /* catch all key event */ var_AddCallback( p_demux->obj.libvlc, "key-action", EventKey, this ); - /* catch input event */ - var_AddCallback( p_demux->p_input, "intf-event", EventInput, this ); /* main loop */ for( ;; ) { vlc_mutex_lock( &lock ); - while( !b_abort && !i_key_action && !b_moved && !b_clicked && !b_vout) + while( !b_abort && !i_key_action && pending_events.empty() ) vlc_cond_wait( &wait, &lock ); if( b_abort ) @@ -171,42 +146,24 @@ void event_thread_t::EventThread() if( i_key_action ) HandleKeyEvent(); - /* MOUSE part */ - if( p_vout && ( b_moved || b_clicked ) ) - HandleMouseEvent( p_vout ); - while( !pending_events.empty() ) { - /* TODO: handle events here */ - pending_events.pop_front(); - } - - - b_vout = false; - vlc_mutex_unlock( &lock ); + EventInfo const& ev = pending_events.front(); - /* Always check vout */ - if( p_vout == NULL ) - { - p_vout = (vlc_object_t*) input_GetVout(p_demux->p_input); - if( p_vout) + switch( ev.type ) { - var_AddCallback( p_vout, "mouse-moved", EventMouse, this ); - var_AddCallback( p_vout, "mouse-clicked", EventMouse, this ); + case EventInfo::ESMouseEvent: + HandleMouseEvent( ev ); + break; } + + pending_events.pop_front(); } - } - /* Release callback */ - if( p_vout ) - { - var_DelCallback( p_vout, "mouse-moved", EventMouse, this ); - var_DelCallback( p_vout, "mouse-clicked", EventMouse, this ); - vlc_object_release( p_vout ); + vlc_mutex_unlock( &lock ); } - var_DelCallback( p_demux->p_input, "intf-event", EventInput, this ); - var_DelCallback( p_demux->obj.libvlc, "key-action", EventKey, this ); + var_DelCallback( p_demux->obj.libvlc, "key-action", EventKey, this ); vlc_restorecancel (canc); } @@ -340,15 +297,16 @@ void event_thread_t::HandleKeyEvent() i_key_action = 0; } -void event_thread_t::HandleMouseEvent( vlc_object_t* p_vout ) +void event_thread_t::HandleMouseEvent( EventInfo const& event ) { demux_sys_t* p_sys = (demux_sys_t*)p_demux->p_sys; - int x, y; + int x = event.mouse.state_new.i_x; + int y = event.mouse.state_new.i_y; - var_GetCoords( p_vout, "mouse-moved", &x, &y ); pci_t *pci = &pci_packet; - if( b_clicked ) + if( vlc_mouse_HasPressed( &event.mouse.state_old, &event.mouse.state_new, + MOUSE_BUTTON_LEFT ) ) { int32_t button; int32_t best,dist,d; @@ -438,28 +396,29 @@ void event_thread_t::HandleMouseEvent( vlc_object_t* p_vout ) vlc_mutex_lock( &lock ); } } - else if( b_moved ) + else if( vlc_mouse_HasMoved( &event.mouse.state_old, &event.mouse.state_new ) ) { // dvdnav_mouse_select( NULL, pci, x, y ); } - - b_moved = false; - b_clicked = false; } void event_thread_t::AddES( es_out_id_t* es, int category ) { vlc_mutex_locker lock_guard( &lock ); - es_list.push_back( ESInfo( es, category, *this ) ); - es_list_t::reverse_iterator info = es_list.rbegin(); + es_list.push_front( ESInfo( es, category, *this ) ); + es_list_t::iterator info = es_list.begin(); - /* TODO: - * - subscribe to events if required, - * - use &*info as callback data if necessary - **/ - - VLC_UNUSED( info ); + if( category == VIDEO_ES ) + { + if( es_out_Control( p_demux->out, ES_OUT_VOUT_SET_MOUSE_EVENT, + es, EventMouse, static_cast<void*>( &*info ) ) ) + { + msg_Warn( p_demux, "Unable to subscribe to mouse events" ); + es_list.erase( info ); + return; + } + } } void event_thread_t::DelES( es_out_id_t* es ) diff --git a/modules/demux/mkv/events.hpp b/modules/demux/mkv/events.hpp index 1a94a13cc2..2800d0f09d 100644 --- a/modules/demux/mkv/events.hpp +++ b/modules/demux/mkv/events.hpp @@ -27,6 +27,7 @@ #include <vlc_common.h> #include <vlc_threads.h> +#include <vlc_mouse.h> #include "dvd_types.hpp" @@ -63,27 +64,40 @@ private: es_out_id_t* es; int category; event_thread_t& owner; + vlc_mouse_t mouse_state; }; struct EventInfo { enum { - /* XXX: event type */ + ESMouseEvent, + ActionEvent, } type; + EventInfo( ESInfo* info, vlc_mouse_t state_old, vlc_mouse_t state_new ) + : type( ESMouseEvent ) + { + mouse.es_info = info; + mouse.state_old = state_old; + mouse.state_new = state_new; + } + union { - /* XXX: event specific data */ + struct { + ESInfo* es_info; + vlc_mouse_t state_old; + vlc_mouse_t state_new; + } mouse; }; }; void EventThread(); static void *EventThread(void *); - static int EventMouse( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); + static void EventMouse( vlc_mouse_t const* state, void* userdata ); static int EventKey( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); - static int EventInput( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); void HandleKeyEvent(); - void HandleMouseEvent( vlc_object_t* p_vout ); + void HandleMouseEvent( EventInfo const& ); demux_t *p_demux; @@ -93,10 +107,7 @@ private: vlc_mutex_t lock; vlc_cond_t wait; bool b_abort; - bool b_moved; - bool b_clicked; int i_key_action; - bool b_vout; pci_t pci_packet; typedef std::list<ESInfo> es_list_t; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
