opusdec: refactor getcaps repeated code into a function
[platform/upstream/gstreamer.git] / tools / gst-play.c
index 40361c0..4204d55 100644 (file)
@@ -84,6 +84,8 @@ typedef struct
 
   GstState desired_state;       /* as per user interaction, PAUSED or PLAYING */
 
+  gulong deep_notify_id;
+
   /* configuration */
   gboolean gapless;
 
@@ -136,7 +138,8 @@ gst_play_printf (const gchar * format, ...)
 
 static GstPlay *
 play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
-    gboolean gapless, gdouble initial_volume)
+    gboolean gapless, gdouble initial_volume, gboolean verbose,
+    const gchar * flags_string)
 {
   GstElement *sink, *playbin;
   GstPlay *play;
@@ -176,6 +179,25 @@ play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
       g_warning ("Couldn't create specified video sink '%s'", video_sink);
   }
 
+  if (flags_string != NULL) {
+    GParamSpec *pspec;
+    GValue val = { 0, };
+
+    pspec =
+        g_object_class_find_property (G_OBJECT_GET_CLASS (playbin), "flags");
+    g_value_init (&val, pspec->value_type);
+    if (gst_value_deserialize (&val, flags_string))
+      g_object_set_property (G_OBJECT (play->playbin), "flags", &val);
+    else
+      g_printerr ("Couldn't convert '%s' to playbin flags!\n", flags_string);
+    g_value_unset (&val);
+  }
+
+  if (verbose) {
+    play->deep_notify_id = g_signal_connect (play->playbin, "deep-notify",
+        G_CALLBACK (gst_object_default_deep_notify), NULL);
+  }
+
   play->loop = g_main_loop_new (NULL, FALSE);
 
   play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin),
@@ -208,6 +230,10 @@ play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
 static void
 play_free (GstPlay * play)
 {
+  /* No need to see all those pad caps going to NULL etc., it's just noise */
+  if (play->deep_notify_id != 0)
+    g_signal_handler_disconnect (play->playbin, play->deep_notify_id);
+
   play_reset (play);
 
   gst_element_set_state (play->playbin, GST_STATE_NULL);
@@ -960,8 +986,8 @@ print_keyboard_help (void)
     {
     N_("space"), N_("pause/unpause")}, {
     N_("q or ESC"), N_("quit")}, {
-    ">", N_("play next")}, {
-    "<", N_("play previous")}, {
+    N_("> or n"), N_("play next")}, {
+    N_("< or b"), N_("play previous")}, {
     "\342\206\222", N_("seek forward")}, {
     "\342\206\220", N_("seek backward")}, {
     "\342\206\221", N_("volume up")}, {
@@ -973,6 +999,7 @@ print_keyboard_help (void)
     "a", N_("change audio track")}, {
     "v", N_("change video track")}, {
     "s", N_("change subtitle track")}, {
+    "0", N_("seek to beginning")}, {
   "k", N_("show keyboard shortcuts")},};
   guint i, chars_to_pad, desc_len, max_desc_len = 0;
 
@@ -1014,12 +1041,14 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
     case 'Q':
       g_main_loop_quit (play->loop);
       break;
+    case 'n':
     case '>':
       if (!play_next (play)) {
         g_print ("\n%s\n", _("Reached end of play list."));
         g_main_loop_quit (play->loop);
       }
       break;
+    case 'b':
     case '<':
       play_prev (play);
       break;
@@ -1063,7 +1092,9 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
     case 's':
       play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE);
       break;
-      /* fall through */
+    case '0':
+      play_do_seek (play, 0, play->rate, play->trick_mode);
+      break;
     default:
       if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
         relative_seek (play, +0.08);
@@ -1087,6 +1118,7 @@ main (int argc, char **argv)
 {
   GstPlay *play;
   GPtrArray *playlist;
+  gboolean verbose = FALSE;
   gboolean print_version = FALSE;
   gboolean interactive = TRUE;
   gboolean gapless = FALSE;
@@ -1096,11 +1128,17 @@ main (int argc, char **argv)
   gchar *audio_sink = NULL;
   gchar *video_sink = NULL;
   gchar **uris;
+  gchar *flags = NULL;
   guint num, i;
   GError *err = NULL;
   GOptionContext *ctx;
   gchar *playlist_file = NULL;
   GOptionEntry options[] = {
+    {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+        N_("Output status information and property notifications"), NULL},
+    {"flags", 0, 0, G_OPTION_ARG_STRING, &flags,
+          N_("Control playback behaviour setting playbin 'flags' property"),
+        NULL},
     {"version", 0, 0, G_OPTION_ARG_NONE, &print_version,
         N_("Print version information and exit"), NULL},
     {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink,
@@ -1223,7 +1261,8 @@ main (int argc, char **argv)
     shuffle_uris (uris, num);
 
   /* prepare */
-  play = play_new (uris, audio_sink, video_sink, gapless, volume);
+  play =
+      play_new (uris, audio_sink, video_sink, gapless, volume, verbose, flags);
 
   if (play == NULL) {
     g_printerr
@@ -1250,5 +1289,6 @@ main (int argc, char **argv)
   g_free (video_sink);
 
   g_print ("\n");
+  gst_deinit ();
   return 0;
 }