[vlc-devel] [PATCH 3/4] demux: mkv: HandleKeyEvent: introduce common helper

Filip Roséen filip at atch.se
Sun Jul 22 08:16:34 CEST 2018


All of the handling in terms of ACTIONID_NAV_{LEFT,RIGHT,UP,DOWN} have
the same logic, besides what button they affect. A new helper,
ProcessNavAction, has been introduced to avoid code-duplication.
---
 modules/demux/mkv/events.cpp | 110 +++++++++--------------------------
 modules/demux/mkv/events.hpp |   2 +
 2 files changed, 28 insertions(+), 84 deletions(-)

diff --git a/modules/demux/mkv/events.cpp b/modules/demux/mkv/events.cpp
index 1834089bf1..57e9503c28 100644
--- a/modules/demux/mkv/events.cpp
+++ b/modules/demux/mkv/events.cpp
@@ -169,6 +169,28 @@ void *event_thread_t::EventThread(void *data)
     return NULL;
 }
 
+void event_thread_t::ProcessNavAction( uint16 button, pci_t* pci )
+{
+    demux_sys_t* p_sys = (demux_sys_t*)p_demux->p_sys;
+
+    if ( button > 0 && button <= pci->hli.hl_gi.btn_ns )
+    {
+        p_sys->dvd_interpretor.SetSPRM( 0x88, button );
+        btni_t button_ptr = pci->hli.btnit[button-1];
+        if ( button_ptr.auto_action_mode )
+        {
+            vlc_mutex_unlock( &lock );
+            vlc_mutex_lock( &p_sys->lock_demuxer );
+
+            // process the button action
+            p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
+
+            vlc_mutex_unlock( &p_sys->lock_demuxer );
+            vlc_mutex_lock( &lock );
+        }
+    }
+}
+
 void event_thread_t::HandleKeyEvent( EventInfo const& ev )
 {
     msg_Dbg( p_demux, "Handle Key Event");
@@ -185,90 +207,10 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
 
     switch( ev.action.id )
     {
-    case ACTIONID_NAV_LEFT:
-        {
-            if ( button_ptr.left > 0 && button_ptr.left <= pci->hli.hl_gi.btn_ns )
-            {
-                i_curr_button = button_ptr.left;
-                p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
-                btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
-                if ( button_ptr.auto_action_mode )
-                {
-                    vlc_mutex_unlock( &lock );
-                    vlc_mutex_lock( &p_sys->lock_demuxer );
-
-                    // process the button action
-                    p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
-
-                    vlc_mutex_unlock( &p_sys->lock_demuxer );
-                    vlc_mutex_lock( &lock );
-                }
-            }
-        }
-        break;
-    case ACTIONID_NAV_RIGHT:
-        {
-            if ( button_ptr.right > 0 && button_ptr.right <= pci->hli.hl_gi.btn_ns )
-            {
-                i_curr_button = button_ptr.right;
-                p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
-                btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
-                if ( button_ptr.auto_action_mode )
-                {
-                    vlc_mutex_unlock( &lock );
-                    vlc_mutex_lock( &p_sys->lock_demuxer );
-
-                    // process the button action
-                    p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
-
-                    vlc_mutex_unlock( &p_sys->lock_demuxer );
-                    vlc_mutex_lock( &lock );
-                }
-            }
-        }
-        break;
-    case ACTIONID_NAV_UP:
-        {
-            if ( button_ptr.up > 0 && button_ptr.up <= pci->hli.hl_gi.btn_ns )
-            {
-                i_curr_button = button_ptr.up;
-                p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
-                btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
-                if ( button_ptr.auto_action_mode )
-                {
-                    vlc_mutex_unlock( &lock );
-                    vlc_mutex_lock( &p_sys->lock_demuxer );
-
-                    // process the button action
-                    p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
-
-                    vlc_mutex_unlock( &p_sys->lock_demuxer );
-                    vlc_mutex_lock( &lock );
-                }
-            }
-        }
-        break;
-    case ACTIONID_NAV_DOWN:
-        {
-            if ( button_ptr.down > 0 && button_ptr.down <= pci->hli.hl_gi.btn_ns )
-            {
-                i_curr_button = button_ptr.down;
-                p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
-                btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
-                if ( button_ptr.auto_action_mode )
-                {
-                    vlc_mutex_unlock( &lock );
-                    vlc_mutex_lock( &p_sys->lock_demuxer );
-
-                    // process the button action
-                    p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
-
-                    vlc_mutex_unlock( &p_sys->lock_demuxer );
-                    vlc_mutex_lock( &lock );
-                }
-            }
-        }
-        break;
+    case ACTIONID_NAV_LEFT: return ProcessNavAction( button_ptr.left, pci );
+    case ACTIONID_NAV_RIGHT: return ProcessNavAction( button_ptr.right, pci );
+    case ACTIONID_NAV_UP: return ProcessNavAction( button_ptr.up, pci );
+    case ACTIONID_NAV_DOWN: return ProcessNavAction( button_ptr.down, pci );
     case ACTIONID_NAV_ACTIVATE:
         {
             vlc_mutex_unlock( &lock );
diff --git a/modules/demux/mkv/events.hpp b/modules/demux/mkv/events.hpp
index b30fae8cf7..1fdab3223d 100644
--- a/modules/demux/mkv/events.hpp
+++ b/modules/demux/mkv/events.hpp
@@ -110,6 +110,8 @@ private:
     void HandleKeyEvent( EventInfo const& );
     void HandleMouseEvent( EventInfo const& );
 
+    void ProcessNavAction( uint16 button, pci_t* pci );
+
     demux_t      *p_demux;
 
     bool         is_running;
-- 
2.18.0


More information about the vlc-devel mailing list