[vlc-devel] [PATCH] Cycle video tracks keyboard shortcut

Antoine Huchet antoine+vlc at huchet.me
Fri Mar 22 12:27:14 CET 2019


This is an attempt to fix https://trac.videolan.org/vlc/ticket/5708

---
 include/vlc_actions.h     |  2 ++
 modules/control/hotkeys.c | 76 ++++++++++++++++++++++-----------------
 src/libvlc-module.c       |  6 ++++
 src/misc/actions.c        |  2 ++
 4 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/include/vlc_actions.h b/include/vlc_actions.h
index 428a34944d..d582bd78f3 100644
--- a/include/vlc_actions.h
+++ b/include/vlc_actions.h
@@ -109,6 +109,7 @@ libvlc_InternalActionsClean(libvlc_int_t *p_libvlc);
 #define KEY_ZOOM_OUT         0x00610000
 #define KEY_BRIGHTNESS_UP    0x00620000
 #define KEY_BRIGHTNESS_DOWN  0x00630000
+#define KEY_MEDIA_VIDEO      0x00640000
 
 #define KEY_MOUSEWHEELUP     0x00F00000
 #define KEY_MOUSEWHEELDOWN   0x00F10000
@@ -182,6 +183,7 @@ typedef enum vlc_action_id {
     ACTIONID_SUBPOS_UP,
     ACTIONID_SUBPOS_DOWN,
     ACTIONID_AUDIO_TRACK,
+    ACTIONID_VIDEO_TRACK,
     ACTIONID_SUBTITLE_REVERSE_TRACK,
     ACTIONID_SUBTITLE_TRACK,
     ACTIONID_SUBTITLE_TOGGLE,
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 8472c12771..5826ecfa31 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -378,6 +378,43 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }
 
+static void ChangeTrack( input_thread_t *p_input, vout_thread_t *p_vout,
+                            const char *media, const char *mediaC,
+                            const char *msg )
+{
+    vlc_value_t val;
+    vlc_value_t *list;
+    char **list2;
+    size_t count;
+
+    var_Get( p_input, media, &val );
+    var_Change( p_input, media, VLC_VAR_GETCHOICES,
+                &count, &list, &list2 );
+
+    if( count > 1 )
+    {
+        size_t i;
+
+        for( i = 0; i < count; i++ )
+            if( val.i_int == list[i].i_int )
+                break;
+        /* value of media was not in choices list */
+        if( i == count )
+        {
+            msg_Warn( p_input, msg );
+            i = 0;
+        }
+        else if( i == count - 1 )
+            i = 1;
+        else
+            i++;
+        var_Set( p_input, media, list[i] );
+        DisplayMessage( p_vout, _("%s track: %s"), mediaC,
+                        list2[i] );
+    }
+    var_FreeList( count, list, list2 );
+}
+
 static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
                       vout_thread_t *p_vout, int slider_chan, bool b_vrnav,
                       int i_action )
@@ -759,39 +796,14 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
 
         case ACTIONID_AUDIO_TRACK:
             if( p_input )
-            {
-                vlc_value_t val;
-                vlc_value_t *list;
-                char **list2;
-                size_t count;
-
-                var_Get( p_input, "audio-es", &val );
-                var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
-                            &count, &list, &list2 );
-
-                if( count > 1 )
-                {
-                    size_t i;
+                ChangeTrack( p_input, p_vout, "audio-es", "Audio",
+                            "invalid current audio track, selecting 0" );
+            break;
 
-                    for( i = 0; i < count; i++ )
-                        if( val.i_int == list[i].i_int )
-                            break;
-                    /* value of audio-es was not in choices list */
-                    if( i == count )
-                    {
-                        msg_Warn( p_input,
-                                  "invalid current audio track, selecting 0" );
-                        i = 0;
-                    }
-                    else if( i == count - 1 )
-                        i = 1;
-                    else
-                        i++;
-                    var_Set( p_input, "audio-es", list[i] );
-                    DisplayMessage( p_vout, _("Audio track: %s"), list2[i] );
-                }
-                var_FreeList( count, list, list2 );
-            }
+        case ACTIONID_VIDEO_TRACK:
+            if( p_input )
+                ChangeTrack( p_input, p_vout, "video-es", "Video",
+                            "invalid current video track, selecting 0" );
             break;
 
         case ACTIONID_SUBTITLE_TRACK:
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 5d875f7d58..015835f070 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1430,6 +1430,8 @@ static const char *const mouse_wheel_texts[] = {
 
 #define AUDIO_TRACK_KEY_TEXT N_("Cycle audio track")
 #define AUDIO_TRACK_KEY_LONGTEXT N_("Cycle through the available audio tracks(languages).")
+#define VIDEO_TRACK_KEY_TEXT N_("Cycle video track")
+#define VIDEO_TRACK_KEY_LONGTEXT N_("Cycle through the available video tracks.")
 #define SUBTITLE_REVERSE_TRACK_KEY_TEXT N_("Cycle subtitle track in reverse order")
 #define SUBTITLE_REVERSE_TRACK_KEY_LONGTEXT N_("Cycle through the available subtitle tracks in reverse order.")
 #define SUBTITLE_TRACK_KEY_TEXT N_("Cycle subtitle track")
@@ -2321,6 +2323,7 @@ vlc_module_begin ()
 #   define KEY_AUDIODELAY_UP      "g"
 #   define KEY_AUDIODELAY_DOWN    "f"
 #   define KEY_AUDIO_TRACK        "l"
+#   define KEY_VIDEO_TRACK        "/"
 #   define KEY_SUBTITLE_TRACK     "s"
 #   define KEY_SUBTITLE_TOGGLE    "Shift+s"
 #   define KEY_SUBTITLE_REVTRACK  "Alt+s"
@@ -2464,6 +2467,7 @@ vlc_module_begin ()
 #   define KEY_LOOP               "l"
 
 #   define KEY_AUDIO_TRACK        "b"
+#   define KEY_VIDEO_TRACK        ";"
 #   define KEY_SUBTITLE_TRACK     "v"
 #   define KEY_SUBTITLE_TOGGLE    "Shift+v"
 #   define KEY_SUBTITLE_REVTRACK  "Alt+v"
@@ -2626,6 +2630,8 @@ vlc_module_begin ()
             AUDIODELAY_DOWN_KEY_TEXT, AUDIODELAY_DOWN_KEY_LONGTEXT)
     add_key("key-audio-track", KEY_AUDIO_TRACK, AUDIO_TRACK_KEY_TEXT,
             AUDIO_TRACK_KEY_LONGTEXT)
+    add_key( "key-video-track", KEY_VIDEO_TRACK, VIDEO_TRACK_KEY_TEXT,
+             VIDEO_TRACK_KEY_LONGTEXT)
     add_key("key-audiodevice-cycle", KEY_AUDIODEVICE_CYCLE,
             AUDIO_DEVICE_CYCLE_KEY_TEXT,
             AUDIO_DEVICE_CYCLE_KEY_LONGTEXT)
diff --git a/src/misc/actions.c b/src/misc/actions.c
index 9bf9a23aba..7e447e6513 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -81,6 +81,7 @@ static const struct key_descriptor
     { N_("Left"),              KEY_LEFT              },
     { N_("Media Angle"),       KEY_MEDIA_ANGLE       },
     { N_("Media Audio Track"), KEY_MEDIA_AUDIO       },
+    { N_("Media Video Track"), KEY_MEDIA_VIDEO       },
     { N_("Media Forward"),     KEY_MEDIA_FORWARD     },
     { N_("Media Menu"),        KEY_MEDIA_MENU        },
     { N_("Media Next Frame"),  KEY_MEDIA_FRAME_NEXT  },
@@ -362,6 +363,7 @@ static const struct name2action
     { "uncrop-right", ACTIONID_UNCROP_RIGHT, },
     { "uncrop-top", ACTIONID_UNCROP_TOP, },
     { "unzoom", ACTIONID_UNZOOM, },
+    { "video-track", ACTIONID_VIDEO_TRACK, },
     { "viewpoint-fov-in", ACTIONID_VIEWPOINT_FOV_IN, },
     { "viewpoint-fov-out", ACTIONID_VIEWPOINT_FOV_OUT, },
     { "viewpoint-roll-anticlock", ACTIONID_VIEWPOINT_ROLL_ANTICLOCK, },
-- 
2.19.1



More information about the vlc-devel mailing list