player: move 'position-update-interval' setting to the config struct
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 25 Jul 2016 08:30:26 +0000 (10:30 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 25 Jul 2016 10:03:20 +0000 (13:03 +0300)
https://bugzilla.gnome.org/show_bug.cgi?id=769144

docs/libs/gst-plugins-bad-libs-sections.txt
gst-libs/gst/player/gstplayer.c
gst-libs/gst/player/gstplayer.h
tests/check/libs/player.c
win32/common/libgstplayer.def

index 8e51936..a14bfc2 100644 (file)
@@ -1708,9 +1708,6 @@ gst_player_get_pipeline
 gst_player_set_config
 gst_player_get_config
 
-gst_player_set_position_update_interval
-gst_player_get_position_update_interval
-
 GstPlayerState
 gst_player_state_get_name
 
@@ -1767,6 +1764,9 @@ GstPlayerVideoRenderer
 GstPlayerVideoRendererInterface
 
 <SUBSECTION config>
+gst_player_config_set_position_update_interval
+gst_player_config_get_position_update_interval
+
 gst_player_config_set_user_agent
 gst_player_config_get_user_agent
 
index 01f00e3..a23d26b 100644 (file)
@@ -84,12 +84,14 @@ static GQuark QUARK_CONFIG;
 typedef enum
 {
   CONFIG_QUARK_USER_AGENT = 0,
+  CONFIG_QUARK_POSITION_INTERVAL_UPDATE,
 
   CONFIG_QUARK_MAX
 } ConfigQuarkId;
 
 static const gchar *_config_quark_strings[] = {
   "user-agent",
+  "position-interval-update",
 };
 
 GQuark _config_quark_table[CONFIG_QUARK_MAX];
@@ -113,7 +115,6 @@ enum
   PROP_MUTE,
   PROP_RATE,
   PROP_PIPELINE,
-  PROP_POSITION_UPDATE_INTERVAL,
   PROP_VIDEO_MULTIVIEW_MODE,
   PROP_VIDEO_MULTIVIEW_FLAGS,
   PROP_AUDIO_VIDEO_OFFSET,
@@ -169,7 +170,6 @@ struct _GstPlayer
   GSource *tick_source, *ready_timeout_source;
 
   gdouble rate;
-  guint position_update_interval_ms;
 
   GstPlayerState app_state;
   gint buffering;
@@ -218,8 +218,6 @@ static gboolean gst_player_stop_internal (gpointer user_data);
 static gboolean gst_player_pause_internal (gpointer user_data);
 static gboolean gst_player_play_internal (gpointer user_data);
 static gboolean gst_player_set_rate_internal (gpointer user_data);
-static gboolean gst_player_set_position_update_interval_internal (gpointer
-    user_data);
 static void change_state (GstPlayer * self, GstPlayerState state);
 
 static GstPlayerMediaInfo *gst_player_media_info_create (GstPlayer * self);
@@ -263,9 +261,12 @@ gst_player_init (GstPlayer * self)
   self->context = g_main_context_new ();
   self->loop = g_main_loop_new (self->context, FALSE);
 
-  self->config = gst_structure_new_id_empty (QUARK_CONFIG);
+  /* *INDENT-OFF* */
+  self->config = gst_structure_new_id (QUARK_CONFIG,
+      CONFIG_QUARK (POSITION_INTERVAL_UPDATE), G_TYPE_UINT, DEFAULT_POSITION_UPDATE_INTERVAL_MS,
+      NULL);
+  /* *INDENT-ON* */
 
-  self->position_update_interval_ms = DEFAULT_POSITION_UPDATE_INTERVAL_MS;
   self->seek_pending = FALSE;
   self->seek_position = GST_CLOCK_TIME_NONE;
   self->last_seek_time = GST_CLOCK_TIME_NONE;
@@ -367,13 +368,6 @@ gst_player_class_init (GstPlayerClass * klass)
       g_param_spec_double ("rate", "rate", "Playback rate",
       -64.0, 64.0, DEFAULT_RATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-  param_specs[PROP_POSITION_UPDATE_INTERVAL] =
-      g_param_spec_uint ("position-update-interval", "Position update interval",
-      "Interval in milliseconds between two position-updated signals."
-      "Pass 0 to stop updating the position.",
-      0, 10000, DEFAULT_POSITION_UPDATE_INTERVAL_MS,
-      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
   param_specs[PROP_VIDEO_MULTIVIEW_MODE] =
       g_param_spec_enum ("video-multiview-mode",
       "Multiview Mode Override",
@@ -672,15 +666,6 @@ gst_player_set_property (GObject * object, guint prop_id,
       GST_DEBUG_OBJECT (self, "Set mute=%d", g_value_get_boolean (value));
       g_object_set_property (G_OBJECT (self->playbin), "mute", value);
       break;
-    case PROP_POSITION_UPDATE_INTERVAL:
-      g_mutex_lock (&self->lock);
-      self->position_update_interval_ms = g_value_get_uint (value);
-      GST_DEBUG_OBJECT (self, "Set position update interval=%u ms",
-          g_value_get_uint (value));
-      g_mutex_unlock (&self->lock);
-
-      gst_player_set_position_update_interval_internal (self);
-      break;
     case PROP_VIDEO_MULTIVIEW_MODE:
       GST_DEBUG_OBJECT (self, "Set multiview mode=%u",
           g_value_get_enum (value));
@@ -783,11 +768,6 @@ gst_player_get_property (GObject * object, guint prop_id,
     case PROP_PIPELINE:
       g_value_set_object (value, self->playbin);
       break;
-    case PROP_POSITION_UPDATE_INTERVAL:
-      g_mutex_lock (&self->lock);
-      g_value_set_uint (value, gst_player_get_position_update_interval (self));
-      g_mutex_unlock (&self->lock);
-      break;
     case PROP_VIDEO_MULTIVIEW_MODE:{
       g_object_get_property (G_OBJECT (self->playbin), "video-multiview-mode",
           value);
@@ -932,13 +912,17 @@ tick_cb (gpointer user_data)
 static void
 add_tick_source (GstPlayer * self)
 {
+  guint position_update_interval_ms;
+
   if (self->tick_source)
     return;
 
-  if (!self->position_update_interval_ms)
+  position_update_interval_ms =
+      gst_player_config_get_position_update_interval (self->config);
+  if (!position_update_interval_ms)
     return;
 
-  self->tick_source = g_timeout_source_new (self->position_update_interval_ms);
+  self->tick_source = g_timeout_source_new (position_update_interval_ms);
   g_source_set_callback (self->tick_source, (GSourceFunc) tick_cb, self, NULL);
   g_source_attach (self->tick_source, self->context);
 }
@@ -3092,59 +3076,6 @@ gst_player_get_rate (GstPlayer * self)
   return self->rate;
 }
 
-static gboolean
-gst_player_set_position_update_interval_internal (gpointer user_data)
-{
-  GstPlayer *self = user_data;
-
-  g_mutex_lock (&self->lock);
-
-  if (self->tick_source) {
-    remove_tick_source (self);
-    add_tick_source (self);
-  }
-
-  g_mutex_unlock (&self->lock);
-
-  return G_SOURCE_REMOVE;
-}
-
-/**
- * gst_player_set_position_update_interval:
- * @player: #GstPlayer instance
- * @interval: interval in ms
- *
- * Set interval in milliseconds between two position-updated signals.
- * Pass 0 to stop updating the position.
- */
-void
-gst_player_set_position_update_interval (GstPlayer * self, guint interval)
-{
-  g_return_if_fail (GST_IS_PLAYER (self));
-  g_return_if_fail (interval <= 10000);
-
-  g_mutex_lock (&self->lock);
-  self->position_update_interval_ms = interval;
-  g_mutex_unlock (&self->lock);
-
-  gst_player_set_position_update_interval_internal (self);
-}
-
-/**
- * gst_player_get_position_update_interval:
- * @player: #GstPlayer instance
- *
- * Returns: current position update interval in milliseconds
- */
-guint
-gst_player_get_position_update_interval (GstPlayer * self)
-{
-  g_return_val_if_fail (GST_IS_PLAYER (self),
-      DEFAULT_POSITION_UPDATE_INTERVAL_MS);
-
-  return self->position_update_interval_ms;
-}
-
 /**
  * gst_player_seek:
  * @player: #GstPlayer instance
@@ -4227,3 +4158,43 @@ gst_player_config_get_user_agent (GstStructure * config)
 
   return agent;
 }
+
+/**
+ * gst_player_config_set_position_update_interval:
+ * @config: a #GstPlayer configuration
+ * @interval: interval in ms
+ *
+ * set interval in milliseconds between two position-updated signals.
+ * pass 0 to stop updating the position.
+ * Since 1.10
+ */
+void
+gst_player_config_set_position_update_interval (GstStructure * config,
+    guint interval)
+{
+  g_return_if_fail (config != NULL);
+  g_return_if_fail (interval <= 10000);
+
+  gst_structure_id_set (config,
+      CONFIG_QUARK (POSITION_INTERVAL_UPDATE), G_TYPE_UINT, interval, NULL);
+}
+
+/**
+ * gst_player_config_get_position_update_interval:
+ * @player: #GstPlayer instance
+ *
+ * Returns: current position update interval in milliseconds
+ * Since 1.10
+ */
+guint
+gst_player_config_get_position_update_interval (GstStructure * config)
+{
+  guint interval = DEFAULT_POSITION_UPDATE_INTERVAL_MS;
+
+  g_return_val_if_fail (config != NULL, DEFAULT_POSITION_UPDATE_INTERVAL_MS);
+
+  gst_structure_id_get (config,
+      CONFIG_QUARK (POSITION_INTERVAL_UPDATE), G_TYPE_UINT, &interval, NULL);
+
+  return interval;
+}
index 93b6d72..641af21 100644 (file)
@@ -202,6 +202,10 @@ void           gst_player_config_set_user_agent       (GstStructure * config,
                                                        const gchar * agent);
 gchar *        gst_player_config_get_user_agent       (GstStructure * config);
 
+void           gst_player_config_set_position_update_interval  (GstStructure * config,
+                                                                guint          interval);
+guint          gst_player_config_get_position_update_interval  (GstStructure * config);
+
 G_END_DECLS
 
 #endif /* __GST_PLAYER_H__ */
index e0fcf92..e4c83fc 100644 (file)
@@ -100,20 +100,17 @@ START_TEST (test_set_and_get_position_update_interval)
 {
   GstPlayer *player;
   guint interval = 0;
+  GstStructure *config;
 
   player = gst_player_new (NULL, NULL);
 
   fail_unless (player != NULL);
 
-  gst_player_set_position_update_interval (player, 500);
-  interval = gst_player_get_position_update_interval (player);
-
+  config = gst_player_get_config (player);
+  gst_player_config_set_position_update_interval (config, 500);
+  interval = gst_player_config_get_position_update_interval (config);
   fail_unless (interval == 500);
-
-  g_object_set (player, "position-update-interval", 1000, NULL);
-  g_object_get (player, "position-update-interval", &interval, NULL);
-
-  fail_unless_equals_int (interval, 1000);
+  gst_player_set_config (player, config);
 
   g_object_unref (player);
 }
@@ -1476,7 +1473,6 @@ test_play_position_update_interval_cb (GstPlayer * player,
 
     if (do_quit && position >= 2000 * GST_MSECOND) {
       do_quit = FALSE;
-      gst_player_set_position_update_interval (player, 0);
       g_main_loop_quit (new_state->loop);
     }
   } else if (change == STATE_CHANGE_END_OF_STREAM ||
@@ -1499,6 +1495,7 @@ START_TEST (test_play_position_update_interval)
   GstPlayer *player;
   TestPlayerState state;
   gchar *uri;
+  GstStructure *config;
 
   memset (&state, 0, sizeof (state));
   state.loop = g_main_loop_new (NULL, FALSE);
@@ -1506,7 +1503,10 @@ START_TEST (test_play_position_update_interval)
   state.test_data = GINT_TO_POINTER (0);
 
   player = test_player_new (&state);
-  gst_player_set_position_update_interval (player, 600);
+
+  config = gst_player_get_config (player);
+  gst_player_config_set_position_update_interval (config, 600);
+  gst_player_set_config (player, config);
 
   fail_unless (player != NULL);
 
@@ -1520,6 +1520,13 @@ START_TEST (test_play_position_update_interval)
 
   fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 5);
 
+  /* Disable position updates */
+  gst_player_stop (player);
+
+  config = gst_player_get_config (player);
+  gst_player_config_set_position_update_interval (config, 0);
+  gst_player_set_config (player, config);
+
   g_timeout_add (2000, quit_loop_cb, state.loop);
   g_main_loop_run (state.loop);
 
index 09b74fb..ccc32ed 100644 (file)
@@ -7,7 +7,9 @@ EXPORTS
        gst_player_audio_info_get_type
        gst_player_color_balance_type_get_name
        gst_player_color_balance_type_get_type
+       gst_player_config_get_position_update_interval
        gst_player_config_get_user_agent
+       gst_player_config_set_position_update_interval
        gst_player_config_set_user_agent
        gst_player_error_get_name
        gst_player_error_get_type
@@ -29,7 +31,6 @@ EXPORTS
        gst_player_get_mute
        gst_player_get_pipeline
        gst_player_get_position
-       gst_player_get_position_update_interval
        gst_player_get_rate
        gst_player_get_subtitle_streams
        gst_player_get_subtitle_uri
@@ -60,7 +61,6 @@ EXPORTS
        gst_player_set_multiview_flags
        gst_player_set_multiview_mode
        gst_player_set_mute
-       gst_player_set_position_update_interval
        gst_player_set_rate
        gst_player_set_subtitle_track
        gst_player_set_subtitle_track_enabled