[vlc-commits] demux: mkv: use new event handling for actions

Filip Roséen git at videolan.org
Fri Jul 20 09:37:42 CEST 2018


vlc | branch: master | Filip Roséen <filip at atch.se> | Thu Jul 19 19:30:45 2018 +0200| [8c9b0069967a3e36372b940d0e5a6da397ab350c] | committer: Thomas Guillem

demux: mkv: use new event handling for actions

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c9b0069967a3e36372b940d0e5a6da397ab350c
---

 modules/demux/mkv/events.cpp | 29 ++++++++++++++---------------
 modules/demux/mkv/events.hpp | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/modules/demux/mkv/events.cpp b/modules/demux/mkv/events.cpp
index 015cdf0115..776c42f817 100644
--- a/modules/demux/mkv/events.cpp
+++ b/modules/demux/mkv/events.cpp
@@ -110,11 +110,13 @@ void event_thread_t::EventMouse( vlc_mouse_t const* new_state, void* userdata )
 int event_thread_t::EventKey( vlc_object_t *p_this, char const *,
                               vlc_value_t, vlc_value_t newval, void *p_data )
 {
-    event_thread_t *p_ev = (event_thread_t *) p_data;
-    vlc_mutex_lock( &p_ev->lock );
-    p_ev->i_key_action = newval.i_int;
-    vlc_cond_signal( &p_ev->wait );
-    vlc_mutex_unlock( &p_ev->lock );
+    event_thread_t* owner = static_cast<event_thread_t*>( p_data );
+    vlc_mutex_locker lock_guard( &owner->lock );
+
+    owner->pending_events.push_back(
+        EventInfo( static_cast<vlc_action_id_t>( newval.i_int ) ) );
+
+    vlc_cond_signal( &owner->wait );
     msg_Dbg( p_this, "Event Key");
 
     return VLC_SUCCESS;
@@ -124,8 +126,6 @@ void event_thread_t::EventThread()
 {
     int canc = vlc_savecancel ();
 
-    i_key_action = 0;
-
     /* catch all key event */
     var_AddCallback( p_demux->obj.libvlc, "key-action", EventKey, this );
 
@@ -133,7 +133,7 @@ void event_thread_t::EventThread()
     for( ;; )
     {
         vlc_mutex_lock( &lock );
-        while( !b_abort && !i_key_action && pending_events.empty() )
+        while( !b_abort && pending_events.empty() )
             vlc_cond_wait( &wait, &lock );
 
         if( b_abort )
@@ -142,10 +142,6 @@ void event_thread_t::EventThread()
             break;
         }
 
-        /* KEY part */
-        if( i_key_action )
-            HandleKeyEvent();
-
         while( !pending_events.empty() )
         {
             EventInfo const& ev = pending_events.front();
@@ -155,6 +151,10 @@ void event_thread_t::EventThread()
                 case EventInfo::ESMouseEvent:
                     HandleMouseEvent( ev );
                     break;
+
+                case EventInfo::ActionEvent:
+                    HandleKeyEvent( ev );
+                    break;
             }
 
             pending_events.pop_front();
@@ -173,7 +173,7 @@ void *event_thread_t::EventThread(void *data)
     return NULL;
 }
 
-void event_thread_t::HandleKeyEvent()
+void event_thread_t::HandleKeyEvent( EventInfo const& ev )
 {
     msg_Dbg( p_demux, "Handle Key Event");
 
@@ -182,7 +182,7 @@ void event_thread_t::HandleKeyEvent()
 
     uint16 i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
 
-    switch( i_key_action )
+    switch( ev.action.id )
     {
     case ACTIONID_NAV_LEFT:
         if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
@@ -294,7 +294,6 @@ void event_thread_t::HandleKeyEvent()
     default:
         break;
     }
-    i_key_action = 0;
 }
 
 void event_thread_t::HandleMouseEvent( EventInfo const& event )
diff --git a/modules/demux/mkv/events.hpp b/modules/demux/mkv/events.hpp
index 2800d0f09d..b30fae8cf7 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_actions.h>
 #include <vlc_mouse.h>
 
 #include "dvd_types.hpp"
@@ -81,12 +82,22 @@ private:
             mouse.state_new = state_new;
         }
 
+        EventInfo( vlc_action_id_t id )
+            : type( ActionEvent )
+        {
+            action.id = id;
+        }
+
         union {
             struct {
                 ESInfo* es_info;
                 vlc_mouse_t state_old;
                 vlc_mouse_t state_new;
             } mouse;
+
+            struct {
+                vlc_action_id_t id;
+            } action;
         };
     };
 
@@ -96,7 +107,7 @@ private:
     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 * );
 
-    void HandleKeyEvent();
+    void HandleKeyEvent( EventInfo const& );
     void HandleMouseEvent( EventInfo const& );
 
     demux_t      *p_demux;
@@ -107,7 +118,6 @@ private:
     vlc_mutex_t  lock;
     vlc_cond_t   wait;
     bool         b_abort;
-    int          i_key_action;
     pci_t        pci_packet;
 
     typedef std::list<ESInfo> es_list_t;



More information about the vlc-commits mailing list