gst-play: pick up minus and plus also from navigation events
authorTim-Philipp Müller <tim@centricular.com>
Sun, 26 Sep 2021 17:05:31 +0000 (18:05 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 12 Oct 2021 11:19:22 +0000 (11:19 +0000)
Makes it easier to test playback rate changes with the video
window being in focus.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/928>

subprojects/gst-plugins-base/tools/gst-play.c

index 7a454cdc5e29ed0914de70190e0820848c4b0539..d02b42189f6ee3a9366ba8e9d05ce3f0ca868de5 100644 (file)
@@ -103,6 +103,9 @@ typedef struct
   GstPlayTrickMode trick_mode;
   gdouble rate;
   gdouble start_position;
+
+  /* keyboard state tracking */
+  gboolean shift_pressed;
 } GstPlay;
 
 static gboolean quiet = FALSE;
@@ -498,16 +501,38 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
                   key = GST_PLAY_KB_ARROW_UP;
                 else if (strcmp (key, "Down") == 0)
                   key = GST_PLAY_KB_ARROW_DOWN;
-                else if (strcmp (key, "space") == 0 ||
-                    strcmp (key, "Space") == 0)
+                else if (strncmp (key, "Shift", 5) == 0) {
+                  play->shift_pressed = TRUE;
+                  break;
+                } else if (strcmp (key, "space") == 0 ||
+                    strcmp (key, "Space") == 0) {
                   key = " ";
-                else if (strlen (key) > 1)
+                } else if (strcmp (key, "minus") == 0) {
+                  key = "-";
+                } else if (strcmp (key, "plus") == 0
+                    /* TODO: That's not universally correct at all, but still handy */
+                    || (strcmp (key, "equal") == 0 && play->shift_pressed)) {
+                  key = "+";
+                } else if (strlen (key) > 1) {
                   break;
+                }
 
                 keyboard_cb (key, user_data);
               }
               break;
             }
+            case GST_NAVIGATION_EVENT_KEY_RELEASE:
+            {
+              const gchar *key;
+
+              if (gst_navigation_event_parse_key_event (ev, &key)) {
+                GST_INFO ("Key release: %s", key);
+                if (strncmp (key, "Shift", 5) == 0) {
+                  play->shift_pressed = FALSE;
+                }
+              }
+              break;
+            }
             case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
             {
               gint button;
@@ -1325,6 +1350,7 @@ play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type)
 static void
 print_keyboard_help (void)
 {
+  /* *INDENT-OFF* */
   static struct
   {
     const gchar *key_desc;
@@ -1349,6 +1375,7 @@ print_keyboard_help (void)
     "s", N_("change subtitle track")}, {
     "0", N_("seek to beginning")}, {
   "k", N_("show keyboard shortcuts")},};
+  /* *INDENT-ON* */
   guint i, chars_to_pad, desc_len, max_desc_len = 0;
 
   gst_print ("\n\n%s\n\n", _("Interactive mode - keyboard controls:"));