player: Add configuration for enabling accurate seeks
authorLyon Wang <lyon.wang@nxp.com>
Wed, 26 Oct 2016 08:28:10 +0000 (16:28 +0800)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 1 Nov 2016 17:49:52 +0000 (19:49 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=773521

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

index a14bfc207b0cf4f6ff38b3e3cab21eb6d2ca1860..2f2042d3be270741bbae457d8eefd5b456685d8c 100644 (file)
@@ -1770,6 +1770,9 @@ gst_player_config_get_position_update_interval
 gst_player_config_set_user_agent
 gst_player_config_get_user_agent
 
+gst_player_config_set_seek_accurate
+gst_player_config_get_seek_accurate
+
 <SUBSECTION Standard>
 GST_IS_PLAYER
 GST_IS_PLAYER_CLASS
index c1d937cf9c468c6a841ec24139f1e4ca6689cade..f92f09e67df1f2547857be2e7b7670898edc1dfe 100644 (file)
@@ -85,6 +85,7 @@ typedef enum
 {
   CONFIG_QUARK_USER_AGENT = 0,
   CONFIG_QUARK_POSITION_INTERVAL_UPDATE,
+  CONFIG_QUARK_ACCURATE_SEEK,
 
   CONFIG_QUARK_MAX
 } ConfigQuarkId;
@@ -92,6 +93,7 @@ typedef enum
 static const gchar *_config_quark_strings[] = {
   "user-agent",
   "position-interval-update",
+  "accurate-seek",
 };
 
 GQuark _config_quark_table[CONFIG_QUARK_MAX];
@@ -267,6 +269,7 @@ gst_player_init (GstPlayer * self)
   /* *INDENT-OFF* */
   self->config = gst_structure_new_id (QUARK_CONFIG,
       CONFIG_QUARK (POSITION_INTERVAL_UPDATE), G_TYPE_UINT, DEFAULT_POSITION_UPDATE_INTERVAL_MS,
+      CONFIG_QUARK (ACCURATE_SEEK), G_TYPE_BOOLEAN, FALSE,
       NULL);
   /* *INDENT-ON* */
 
@@ -2970,6 +2973,7 @@ gst_player_seek_internal_locked (GstPlayer * self)
   GstStateChangeReturn state_ret;
   GstEvent *s_event;
   GstSeekFlags flags = 0;
+  gboolean accurate = FALSE;
 
   if (self->seek_source) {
     g_source_destroy (self->seek_source);
@@ -3005,6 +3009,14 @@ gst_player_seek_internal_locked (GstPlayer * self)
 
   flags |= GST_SEEK_FLAG_FLUSH;
 
+  accurate = gst_player_config_get_seek_accurate (self->config);
+
+  if (accurate) {
+    flags |= GST_SEEK_FLAG_ACCURATE;
+  } else {
+    flags &= ~GST_SEEK_FLAG_ACCURATE;
+  }
+
   if (rate != 1.0) {
     flags |= GST_SEEK_FLAG_TRICKMODE;
   }
@@ -4202,3 +4214,51 @@ gst_player_config_get_position_update_interval (const GstStructure * config)
 
   return interval;
 }
+
+/**
+ * gst_player_config_set_seek_accurate:
+ * @player: #GstPlayer instance
+ * @accurate: accurate seek or not
+ *
+ * Enable or disable accurate seeking. When enabled, elements will try harder
+ * to seek as accurately as possible to the requested seek position. Generally
+ * it will be slower especially for formats that don't have any indexes or
+ * timestamp markers in the stream.
+ *
+ * If accurate seeking is disabled, elements will seek as close as the request
+ * position without slowing down seeking too much.
+ *
+ * Accurate seeking is disabled by default.
+ *
+ * Since: 1.12
+ */
+void
+gst_player_config_set_seek_accurate (GstPlayer * self, gboolean accurate)
+{
+  GstStructure *config = self->config;
+  g_return_if_fail (config != NULL);
+
+  gst_structure_id_set (config,
+      CONFIG_QUARK (ACCURATE_SEEK), G_TYPE_BOOLEAN, accurate, NULL);
+}
+
+/**
+ * gst_player_config_get_seek_accurate:
+ * @config: a #GstPlayer configuration
+ *
+ * Returns: %TRUE if accurate seeking is enabled
+ *
+ * Since 1.12
+ */
+gboolean
+gst_player_config_get_seek_accurate (const GstStructure * config)
+{
+  gboolean accurate = FALSE;
+
+  g_return_val_if_fail (config != NULL, FALSE);
+
+  gst_structure_id_get (config,
+      CONFIG_QUARK (ACCURATE_SEEK), G_TYPE_BOOLEAN, &accurate, NULL);
+
+  return accurate;
+}
index 0ac66beb131083bbe053c2811af70af46f671359..8426be5d3079f5f2b64d7afe9c719f1139d091bd 100644 (file)
@@ -202,6 +202,9 @@ void           gst_player_config_set_position_update_interval  (GstStructure * c
                                                                 guint          interval);
 guint          gst_player_config_get_position_update_interval  (const GstStructure * config);
 
+void           gst_player_config_set_seek_accurate (GstPlayer * player, gboolean accurate);
+gboolean       gst_player_config_get_seek_accurate (const GstStructure * config);
+
 G_END_DECLS
 
 #endif /* __GST_PLAYER_H__ */
index ccc32ed6979a1f401df39eb52ba00647a7e92344..0c7909c0833e6ec150b90ac1ee3622ce520de667 100644 (file)
@@ -7,8 +7,10 @@ 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_seek_accurate
        gst_player_config_get_position_update_interval
        gst_player_config_get_user_agent
+       gst_player_config_set_seek_accurate
        gst_player_config_set_position_update_interval
        gst_player_config_set_user_agent
        gst_player_error_get_name