playbin: add current-*uri properties
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 25 May 2012 13:12:53 +0000 (15:12 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 25 May 2012 13:18:46 +0000 (15:18 +0200)
Make the uri property getter return the next uri, like it was configured in the
setter.
Make a new current-uri and current-suburi property that reflects the currently
playing uri and suburi.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=676665

gst/playback/gstplaybin2.c
tests/check/elements/playbin.c

index b09f75f..8ccaeb1 100644 (file)
@@ -482,7 +482,9 @@ enum
 {
   PROP_0,
   PROP_URI,
+  PROP_CURRENT_URI,
   PROP_SUBURI,
+  PROP_CURRENT_SUBURI,
   PROP_SOURCE,
   PROP_FLAGS,
   PROP_N_VIDEO,
@@ -663,6 +665,16 @@ gst_play_bin_class_init (GstPlayBinClass * klass)
       g_param_spec_string ("uri", "URI", "URI of the media to play",
           NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+   /**
+   * GstPlayBin:current-uri
+   *
+   * The currently playing uri.
+   */
+  g_object_class_install_property (gobject_klass, PROP_CURRENT_URI,
+      g_param_spec_string ("current-uri", "Current URI",
+          "The currently playing URI", NULL,
+          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   /**
    * GstPlayBin:suburi
    *
@@ -673,6 +685,16 @@ gst_play_bin_class_init (GstPlayBinClass * klass)
       g_param_spec_string ("suburi", ".sub-URI", "Optional URI of a subtitle",
           NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * GstPlayBin:current-suburi
+   *
+   * The currently playing subtitle uri.
+   */
+  g_object_class_install_property (gobject_klass, PROP_CURRENT_SUBURI,
+      g_param_spec_string ("current-suburi", "Current .sub-URI",
+          "The currently playing URI of a subtitle",
+          NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_property (gobject_klass, PROP_SOURCE,
       g_param_spec_object ("source", "Source", "Source element",
           GST_TYPE_ELEMENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
@@ -2068,6 +2090,17 @@ gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
       GstSourceGroup *group;
 
       GST_PLAY_BIN_LOCK (playbin);
+      group = playbin->next_group;
+      g_value_set_string (value, group->uri);
+      GST_PLAY_BIN_UNLOCK (playbin);
+      break;
+      break;
+    }
+    case PROP_CURRENT_URI:
+    {
+      GstSourceGroup *group;
+
+      GST_PLAY_BIN_LOCK (playbin);
       group = get_group (playbin);
       g_value_set_string (value, group->uri);
       GST_PLAY_BIN_UNLOCK (playbin);
@@ -2078,6 +2111,16 @@ gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
       GstSourceGroup *group;
 
       GST_PLAY_BIN_LOCK (playbin);
+      group = playbin->next_group;
+      g_value_set_string (value, group->suburi);
+      GST_PLAY_BIN_UNLOCK (playbin);
+      break;
+    }
+    case PROP_CURRENT_SUBURI:
+    {
+      GstSourceGroup *group;
+
+      GST_PLAY_BIN_LOCK (playbin);
       group = get_group (playbin);
       g_value_set_string (value, group->suburi);
       GST_PLAY_BIN_UNLOCK (playbin);
index 924dd5a..26cf665 100644 (file)
 static GType gst_red_video_src_get_type (void);
 static GType gst_codec_src_get_type (void);
 
+GST_START_TEST (test_uri)
+{
+  GstElement *playbin, *fakesink;
+  gchar *uri;
+
+  fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY,
+          gst_red_video_src_get_type ()));
+
+  playbin = gst_element_factory_make ("playbin", "playbin");
+  fail_unless (playbin != NULL, "Failed to create playbin element");
+
+  fakesink = gst_element_factory_make ("fakesink", "fakesink");
+  fail_unless (fakesink != NULL, "Failed to create fakesink element");
+
+  g_object_set (playbin, "video-sink", fakesink, NULL);
+
+  g_object_set (playbin, "uri", "redvideo://", NULL);
+  g_object_get (playbin, "uri", &uri, NULL);
+
+  fail_unless_equals_string (uri, "redvideo://");
+
+  g_object_get (playbin, "current-uri", &uri, NULL);
+  fail_unless_equals_string (uri, NULL);
+
+  fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED),
+      GST_STATE_CHANGE_ASYNC);
+  fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1),
+      GST_STATE_CHANGE_SUCCESS);
+
+  g_object_get (playbin, "uri", &uri, NULL);
+  fail_unless_equals_string (uri, NULL);
+  g_object_get (playbin, "current-uri", &uri, NULL);
+  fail_unless_equals_string (uri, "redvideo://");
+
+  gst_element_set_state (playbin, GST_STATE_NULL);
+  gst_object_unref (playbin);
+}
+
+GST_END_TEST;
+
 /* make sure the audio sink is not touched for video-only streams */
 GST_START_TEST (test_sink_usage_video_only_stream)
 {
@@ -736,6 +776,7 @@ playbin_suite (void)
   suite_add_tcase (s, tc_chain);
 
 #ifndef GST_DISABLE_REGISTRY
+  tcase_add_test (tc_chain, test_uri);
   tcase_add_test (tc_chain, test_sink_usage_video_only_stream);
   tcase_add_test (tc_chain, test_suburi_error_wrongproto);
   tcase_add_test (tc_chain, test_suburi_error_invalidfile);