From abef66c92c798594ffb725dbb0532133d24bfda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alicia=20Boya=20Garc=C3=ADa?= Date: Tue, 17 Dec 2019 16:43:00 +0100 Subject: [PATCH] decodebin3: Avoid duplicate streams Elements emitting stream collections do so by not only posting the GST_MESSAGE_STREAM_COLLECTION, but also then pushing a GST_EVENT_STREAM_COLLECTION through each srcpad. The latter is how decodebin3 detects stream collections itself, as the GST_MESSAGE_STREAM_COLLECTION may be posted before the source element is added to the pipeline and therefore missed. But it should be noted: when the source has two srcpads the stream collection event is received twice! When decodebin3 receives several stream collections it reacts by creating a new one combining all the streams... But the code doing so did not take into account the case mentioned before, where both collections are actually the same and have the same streams. This patch fixes that. --- gst/playback/gstdecodebin3.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gst/playback/gstdecodebin3.c b/gst/playback/gstdecodebin3.c index 1f18f4e12..9a076c645 100644 --- a/gst/playback/gstdecodebin3.c +++ b/gst/playback/gstdecodebin3.c @@ -1217,6 +1217,14 @@ sort_streams (GstStream * sa, GstStream * sb) return ret; } +static gint +compare_stream_by_id (const void *_stream, const void *_stream_id) +{ + const GstStream *stream = (const GstStream *) _stream; + const gchar *stream_id = (const gchar *) _stream_id; + return g_strcmp0 (stream->stream_id, stream_id); +} + /* Call with INPUT_LOCK taken */ static GstStreamCollection * get_merged_collection (GstDecodebin3 * dbin) @@ -1230,9 +1238,11 @@ get_merged_collection (GstDecodebin3 * dbin) /* First check if we need to do a merge or just return the only collection */ res = dbin->main_input->collection; + /* Look for an existing collection that is different than the one we are + * merging with. */ for (tmp = dbin->other_inputs; tmp; tmp = tmp->next) { DecodebinInput *input = (DecodebinInput *) tmp->data; - if (input->collection) { + if (input->collection && input->collection != res) { if (res) { needs_merge = TRUE; break; @@ -1269,7 +1279,9 @@ get_merged_collection (GstDecodebin3 * dbin) for (i = 0; i < nb_stream; i++) { GstStream *stream = gst_stream_collection_get_stream (input->collection, i); - unsorted_streams = g_list_append (unsorted_streams, stream); + if (!g_list_find_custom (unsorted_streams, stream->stream_id, + compare_stream_by_id)) + unsorted_streams = g_list_append (unsorted_streams, stream); } } } -- GitLab