playbin3: Remove duration caching
This is now handled directly via sinks and queries through pads
This commit is contained in:
parent
fc93302087
commit
9f1063e4a3
@ -472,13 +472,6 @@ struct _GstPlayBin3
|
|||||||
GSequence *aelements; /* a list of GstAVElements for audio stream */
|
GSequence *aelements; /* a list of GstAVElements for audio stream */
|
||||||
GSequence *velements; /* a list of GstAVElements for video stream */
|
GSequence *velements; /* a list of GstAVElements for video stream */
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
gboolean valid;
|
|
||||||
GstFormat format;
|
|
||||||
gint64 duration;
|
|
||||||
} duration[5]; /* cached durations */
|
|
||||||
|
|
||||||
guint64 ring_buffer_max_size; /* 0 means disabled */
|
guint64 ring_buffer_max_size; /* 0 means disabled */
|
||||||
|
|
||||||
/* Active stream collection */
|
/* Active stream collection */
|
||||||
@ -581,7 +574,6 @@ static GstStateChangeReturn gst_play_bin3_change_state (GstElement * element,
|
|||||||
static void gst_play_bin3_handle_message (GstBin * bin, GstMessage * message);
|
static void gst_play_bin3_handle_message (GstBin * bin, GstMessage * message);
|
||||||
static void gst_play_bin3_deep_element_added (GstBin * playbin,
|
static void gst_play_bin3_deep_element_added (GstBin * playbin,
|
||||||
GstBin * sub_bin, GstElement * child);
|
GstBin * sub_bin, GstElement * child);
|
||||||
static gboolean gst_play_bin3_query (GstElement * element, GstQuery * query);
|
|
||||||
static gboolean gst_play_bin3_send_event (GstElement * element,
|
static gboolean gst_play_bin3_send_event (GstElement * element,
|
||||||
GstEvent * event);
|
GstEvent * event);
|
||||||
|
|
||||||
@ -1023,7 +1015,6 @@ gst_play_bin3_class_init (GstPlayBin3Class * klass)
|
|||||||
|
|
||||||
gstelement_klass->change_state =
|
gstelement_klass->change_state =
|
||||||
GST_DEBUG_FUNCPTR (gst_play_bin3_change_state);
|
GST_DEBUG_FUNCPTR (gst_play_bin3_change_state);
|
||||||
gstelement_klass->query = GST_DEBUG_FUNCPTR (gst_play_bin3_query);
|
|
||||||
gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin3_send_event);
|
gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin3_send_event);
|
||||||
|
|
||||||
gstbin_klass->handle_message =
|
gstbin_klass->handle_message =
|
||||||
@ -2116,108 +2107,6 @@ gst_play_bin3_get_property (GObject * object, guint prop_id, GValue * value,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gst_play_bin3_update_cached_duration_from_query (GstPlayBin3 * playbin,
|
|
||||||
gboolean valid, GstQuery * query)
|
|
||||||
{
|
|
||||||
GstFormat fmt;
|
|
||||||
gint64 duration;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (playbin, "Updating cached duration from query");
|
|
||||||
gst_query_parse_duration (query, &fmt, &duration);
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (playbin->duration); i++) {
|
|
||||||
if (playbin->duration[i].format == 0 || fmt == playbin->duration[i].format) {
|
|
||||||
playbin->duration[i].valid = valid;
|
|
||||||
playbin->duration[i].format = fmt;
|
|
||||||
playbin->duration[i].duration = valid ? duration : -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_play_bin3_update_cached_duration (GstPlayBin3 * playbin)
|
|
||||||
{
|
|
||||||
const GstFormat formats[] =
|
|
||||||
{ GST_FORMAT_TIME, GST_FORMAT_BYTES, GST_FORMAT_DEFAULT };
|
|
||||||
gboolean ret;
|
|
||||||
GstQuery *query;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (playbin, "Updating cached durations before group switch");
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
|
|
||||||
query = gst_query_new_duration (formats[i]);
|
|
||||||
ret =
|
|
||||||
GST_ELEMENT_CLASS (parent_class)->query (GST_ELEMENT_CAST (playbin),
|
|
||||||
query);
|
|
||||||
gst_play_bin3_update_cached_duration_from_query (playbin, ret, query);
|
|
||||||
gst_query_unref (query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_play_bin3_query (GstElement * element, GstQuery * query)
|
|
||||||
{
|
|
||||||
GstPlayBin3 *playbin = GST_PLAY_BIN3 (element);
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
/* During a group switch we shouldn't allow duration queries
|
|
||||||
* because it's not clear if the old or new group's duration
|
|
||||||
* is returned and if the sinks are already playing new data
|
|
||||||
* or old data. See bug #585969
|
|
||||||
*
|
|
||||||
* While we're at it, also don't do any other queries during
|
|
||||||
* a group switch or any other event that causes topology changes
|
|
||||||
* by taking the playbin lock in any case.
|
|
||||||
*/
|
|
||||||
GST_PLAY_BIN3_LOCK (playbin);
|
|
||||||
|
|
||||||
if (GST_QUERY_TYPE (query) == GST_QUERY_DURATION) {
|
|
||||||
GstSourceGroup *group = playbin->curr_group;
|
|
||||||
gboolean pending;
|
|
||||||
|
|
||||||
GST_SOURCE_GROUP_LOCK (group);
|
|
||||||
|
|
||||||
pending = group->pending || group->stream_changed_pending;
|
|
||||||
|
|
||||||
if (pending) {
|
|
||||||
GstFormat fmt;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
ret = FALSE;
|
|
||||||
gst_query_parse_duration (query, &fmt, NULL);
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (playbin->duration); i++) {
|
|
||||||
if (fmt == playbin->duration[i].format) {
|
|
||||||
ret = playbin->duration[i].valid;
|
|
||||||
gst_query_set_duration (query, fmt,
|
|
||||||
(ret ? playbin->duration[i].duration : -1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* if nothing cached yet, we might as well request duration,
|
|
||||||
* such as during initial startup */
|
|
||||||
if (ret) {
|
|
||||||
GST_DEBUG_OBJECT (playbin,
|
|
||||||
"Taking cached duration because of pending group switch: %d", ret);
|
|
||||||
GST_SOURCE_GROUP_UNLOCK (group);
|
|
||||||
GST_PLAY_BIN3_UNLOCK (playbin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GST_SOURCE_GROUP_UNLOCK (group);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = GST_ELEMENT_CLASS (parent_class)->query (element, query);
|
|
||||||
|
|
||||||
if (GST_QUERY_TYPE (query) == GST_QUERY_DURATION)
|
|
||||||
gst_play_bin3_update_cached_duration_from_query (playbin, ret, query);
|
|
||||||
GST_PLAY_BIN3_UNLOCK (playbin);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
get_combiner_stream_id (GstPlayBin3 * playbin, GstSourceCombine * combine,
|
get_combiner_stream_id (GstPlayBin3 * playbin, GstSourceCombine * combine,
|
||||||
GList * full_list)
|
GList * full_list)
|
||||||
@ -4902,7 +4791,6 @@ setup_next_source (GstPlayBin3 * playbin, GstState target)
|
|||||||
if (old_group && old_group->valid && old_group->active) {
|
if (old_group && old_group->valid && old_group->active) {
|
||||||
new_group->stream_changed_pending = TRUE;
|
new_group->stream_changed_pending = TRUE;
|
||||||
|
|
||||||
gst_play_bin3_update_cached_duration (playbin);
|
|
||||||
/* unlink our pads with the sink */
|
/* unlink our pads with the sink */
|
||||||
deactivate_group (playbin, old_group);
|
deactivate_group (playbin, old_group);
|
||||||
old_group->valid = FALSE;
|
old_group->valid = FALSE;
|
||||||
@ -5001,12 +4889,8 @@ gst_play_bin3_change_state (GstElement * element, GstStateChange transition)
|
|||||||
playbin = GST_PLAY_BIN3 (element);
|
playbin = GST_PLAY_BIN3 (element);
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
||||||
memset (&playbin->duration, 0, sizeof (playbin->duration));
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
GST_LOG_OBJECT (playbin, "clearing shutdown flag");
|
GST_LOG_OBJECT (playbin, "clearing shutdown flag");
|
||||||
memset (&playbin->duration, 0, sizeof (playbin->duration));
|
|
||||||
g_atomic_int_set (&playbin->shutdown, 0);
|
g_atomic_int_set (&playbin->shutdown, 0);
|
||||||
do_async_start (playbin);
|
do_async_start (playbin);
|
||||||
break;
|
break;
|
||||||
@ -5015,7 +4899,6 @@ gst_play_bin3_change_state (GstElement * element, GstStateChange transition)
|
|||||||
/* FIXME unlock our waiting groups */
|
/* FIXME unlock our waiting groups */
|
||||||
GST_LOG_OBJECT (playbin, "setting shutdown flag");
|
GST_LOG_OBJECT (playbin, "setting shutdown flag");
|
||||||
g_atomic_int_set (&playbin->shutdown, 1);
|
g_atomic_int_set (&playbin->shutdown, 1);
|
||||||
memset (&playbin->duration, 0, sizeof (playbin->duration));
|
|
||||||
|
|
||||||
/* wait for all callbacks to end by taking the lock.
|
/* wait for all callbacks to end by taking the lock.
|
||||||
* No dynamic (critical) new callbacks will
|
* No dynamic (critical) new callbacks will
|
||||||
@ -5033,7 +4916,6 @@ gst_play_bin3_change_state (GstElement * element, GstStateChange transition)
|
|||||||
do_save = TRUE;
|
do_save = TRUE;
|
||||||
goto async_down;
|
goto async_down;
|
||||||
}
|
}
|
||||||
memset (&playbin->duration, 0, sizeof (playbin->duration));
|
|
||||||
|
|
||||||
/* unlock so that all groups go to NULL */
|
/* unlock so that all groups go to NULL */
|
||||||
groups_set_locked_state (playbin, FALSE);
|
groups_set_locked_state (playbin, FALSE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user