From 8d41d816a240b0a4739e99640a382d0beab670e0 Mon Sep 17 00:00:00 2001 From: Lyon Wang Date: Wed, 26 Oct 2016 16:28:10 +0800 Subject: [PATCH] player: Add configuration for enabling accurate seeks https://bugzilla.gnome.org/show_bug.cgi?id=773521 --- docs/libs/gst-plugins-bad-libs-sections.txt | 3 ++ gst-libs/gst/player/gstplayer.c | 60 +++++++++++++++++++++ gst-libs/gst/player/gstplayer.h | 3 ++ win32/common/libgstplayer.def | 2 + 4 files changed, 68 insertions(+) diff --git a/docs/libs/gst-plugins-bad-libs-sections.txt b/docs/libs/gst-plugins-bad-libs-sections.txt index a14bfc207b..2f2042d3be 100644 --- a/docs/libs/gst-plugins-bad-libs-sections.txt +++ b/docs/libs/gst-plugins-bad-libs-sections.txt @@ -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 + GST_IS_PLAYER GST_IS_PLAYER_CLASS diff --git a/gst-libs/gst/player/gstplayer.c b/gst-libs/gst/player/gstplayer.c index c1d937cf9c..f92f09e67d 100644 --- a/gst-libs/gst/player/gstplayer.c +++ b/gst-libs/gst/player/gstplayer.c @@ -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; +} diff --git a/gst-libs/gst/player/gstplayer.h b/gst-libs/gst/player/gstplayer.h index 0ac66beb13..8426be5d30 100644 --- a/gst-libs/gst/player/gstplayer.h +++ b/gst-libs/gst/player/gstplayer.h @@ -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__ */ diff --git a/win32/common/libgstplayer.def b/win32/common/libgstplayer.def index ccc32ed697..0c7909c083 100644 --- a/win32/common/libgstplayer.def +++ b/win32/common/libgstplayer.def @@ -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