[vlc-commits] [Git][videolan/vlc][master] mkv: rework NAV handling

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Jan 13 16:30:02 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
66ca609d by Thomas Guillem at 2024-01-13T16:14:35+00:00
mkv: rework NAV handling

Use navigation from demux controls instead of hacking "key-action"
callbacks.

This allow to fallback to seek/volume handling if the mkv does not
handle navigation (=> PCI).

Before this commit, both seek/volume and mkv navigation were processed.

This also avoid to alloc, lock, append, wake up a thread when the user
press a key (not only, the nav ones).

- - - - -


3 changed files:

- modules/demux/mkv/events.cpp
- modules/demux/mkv/events.hpp
- modules/demux/mkv/mkv.cpp


Changes:

=====================================
modules/demux/mkv/events.cpp
=====================================
@@ -94,6 +94,20 @@ void event_thread_t::ResetPci()
     is_running = false;
 }
 
+int event_thread_t::SendEventNav( int nav_query )
+{
+    if( !is_running )
+        return VLC_EGENERIC;
+
+    vlc_mutex_locker lock_guard( &lock );
+
+    pending_events.push_back( EventInfo( nav_query ) );
+
+    vlc_cond_signal( &wait );
+
+    return VLC_SUCCESS;
+}
+
 void event_thread_t::EventMouse( vlc_mouse_t const* new_state, void* userdata )
 {
     ESInfo* info = static_cast<ESInfo*>( userdata );
@@ -109,31 +123,12 @@ void event_thread_t::EventMouse( vlc_mouse_t const* new_state, void* userdata )
     info->mouse_state = *new_state;
 }
 
-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* 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;
-}
-
 void event_thread_t::EventThread()
 {
     vlc_thread_set_name("vlc-mkv-events");
 
-    vlc_object_t *vlc = VLC_OBJECT(vlc_object_instance(p_demux));
     int canc = vlc_savecancel ();
 
-    /* catch all key event */
-    var_AddCallback( vlc, "key-action", EventKey, this );
-
     for( vlc_mutex_locker guard( &lock );; )
     {
         while( !b_abort && pending_events.empty() )
@@ -161,7 +156,6 @@ void event_thread_t::EventThread()
         }
     }
 
-    var_DelCallback( vlc, "key-action", EventKey, this );
     vlc_restorecancel (canc);
 }
 
@@ -207,13 +201,13 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
 
     btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
 
-    switch( ev.action.id )
+    switch( ev.nav.query )
     {
-    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:
+    case DEMUX_NAV_LEFT: return ProcessNavAction( button_ptr.left, pci );
+    case DEMUX_NAV_RIGHT: return ProcessNavAction( button_ptr.right, pci );
+    case DEMUX_NAV_UP: return ProcessNavAction( button_ptr.up, pci );
+    case DEMUX_NAV_DOWN: return ProcessNavAction( button_ptr.down, pci );
+    case DEMUX_NAV_ACTIVATE:
         {
             vlc_mutex_unlock( &lock );
             vlc_mutex_lock( &p_sys->lock_demuxer );


=====================================
modules/demux/mkv/events.hpp
=====================================
@@ -45,6 +45,7 @@ public:
 
     void SetPci(const pci_t *data);
     void ResetPci();
+    int SendEventNav( int );
 
     bool AddES( es_out_id_t* es, int category );
     void DelES( es_out_id_t* es );
@@ -83,10 +84,10 @@ private:
             mouse.state_new = state_new;
         }
 
-        EventInfo( vlc_action_id_t id )
+        EventInfo( int query )
             : type( ActionEvent )
         {
-            action.id = id;
+            nav.query = query;
         }
 
         union {
@@ -97,8 +98,8 @@ private:
             } mouse;
 
             struct {
-                vlc_action_id_t id;
-            } action;
+                int query;
+            } nav;
         };
     };
 
@@ -106,7 +107,6 @@ private:
     static void *EventThread(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 * );
 
     void HandleKeyEvent( EventInfo const& );
     void HandleMouseEvent( EventInfo const& );


=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -475,6 +475,15 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             msg_Dbg(p_demux,"SET_TIME to %" PRId64, i64 );
             return Seek( p_demux, i64, -1, NULL, b );
 
+        case DEMUX_NAV_ACTIVATE:
+        case DEMUX_NAV_UP:
+        case DEMUX_NAV_DOWN:
+        case DEMUX_NAV_LEFT:
+        case DEMUX_NAV_RIGHT:
+        case DEMUX_NAV_POPUP:
+        case DEMUX_NAV_MENU:
+            return p_sys->ev.SendEventNav( i_query );
+
         case DEMUX_CAN_PAUSE:
         case DEMUX_SET_PAUSE_STATE:
         case DEMUX_CAN_CONTROL_PACE:



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/66ca609d2bcede2f64fdcc518eba3eabcbdfe5ef

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/66ca609d2bcede2f64fdcc518eba3eabcbdfe5ef
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list