From 2ec79418df0dd2de8d4f4d8e35459464497ef146 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 28 Apr 2022 10:46:34 +0200 Subject: [PATCH] mssdemux2: Ensure stream/track uniqueness If there is more than one track of the same type (say audio), we would end up creating several stream/types with the same name. Instead use the MSS stream name property to make them unique Part-of: --- .../ext/adaptivedemux2/mss/gstmssdemux.c | 26 ++++++++++++++----- .../ext/adaptivedemux2/mss/gstmssmanifest.c | 12 +++++++++ .../ext/adaptivedemux2/mss/gstmssmanifest.h | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.c index 843f0c67f7..3175effe5b 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.c @@ -369,14 +369,28 @@ gst_mss_demux_setup_streams (GstAdaptiveDemux * demux) GstStreamType stream_type = gst_stream_type_from_mss_type (gst_mss_stream_get_type (manifeststream)); - const gchar *lang, *stream_id = gst_stream_type_get_name (stream_type); - gchar *name; + const gchar *lang = gst_mss_stream_get_lang (manifeststream); + const gchar *name = gst_mss_stream_get_name (manifeststream); + gchar *stream_id; GstCaps *caps; GstTagList *tags = NULL; - name = g_strdup_printf ("mss-stream-%s", stream_id); - mss_stream = g_object_new (GST_TYPE_MSS_DEMUX_STREAM, "name", name, NULL); - g_free (name); + if (name) + stream_id = + g_strdup_printf ("mss-stream-%s-%s", + gst_stream_type_get_name (stream_type), + gst_mss_stream_get_name (manifeststream)); + else if (lang) + stream_id = + g_strdup_printf ("mss-stream-%s-%s", + gst_stream_type_get_name (stream_type), lang); + else + stream_id = + g_strdup_printf ("mss-stream-%s", + gst_stream_type_get_name (stream_type)); + + mss_stream = + g_object_new (GST_TYPE_MSS_DEMUX_STREAM, "name", stream_id, NULL); stream = GST_ADAPTIVE_DEMUX2_STREAM_CAST (mss_stream); stream->stream_type = stream_type; @@ -391,7 +405,6 @@ gst_mss_demux_setup_streams (GstAdaptiveDemux * demux) caps = gst_mss_stream_get_caps (mss_stream->manifest_stream); gst_adaptive_demux2_stream_set_caps (stream, create_mss_caps (mss_stream, caps)); - lang = gst_mss_stream_get_lang (mss_stream->manifest_stream); if (lang != NULL) tags = gst_tag_list_new (GST_TAG_LANGUAGE_CODE, lang, NULL); @@ -399,6 +412,7 @@ gst_mss_demux_setup_streams (GstAdaptiveDemux * demux) GST_STREAM_FLAG_NONE, (gchar *) stream_id, create_mss_caps (mss_stream, caps), tags); + g_free (stream_id); gst_adaptive_demux2_add_stream (demux, stream); gst_adaptive_demux2_stream_add_track (stream, track); gst_adaptive_demux_track_unref (track); diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.c index 514033a480..110aa681c9 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.c @@ -44,6 +44,7 @@ GST_DEBUG_CATEGORY_EXTERN (mssdemux2_debug); #define MSS_PROP_DURATION "d" #define MSS_PROP_DVR_WINDOW_LENGTH "DVRWindowLength" #define MSS_PROP_LANGUAGE "Language" +#define MSS_PROP_NAME "Name" #define MSS_PROP_NUMBER "n" #define MSS_PROP_REPETITIONS "r" #define MSS_PROP_STREAM_DURATION "Duration" @@ -84,6 +85,7 @@ struct _GstMssStream gchar *url; gchar *lang; + gchar *name; GstMssFragmentParser fragment_parser; @@ -254,6 +256,7 @@ _gst_mss_stream_init (GstMssManifest * manifest, GstMssStream * stream, stream->xmlnode = node; /* get the base url path generator */ + stream->name = (gchar *) xmlGetProp (node, (xmlChar *) MSS_PROP_NAME); stream->url = (gchar *) xmlGetProp (node, (xmlChar *) MSS_PROP_URL); stream->lang = (gchar *) xmlGetProp (node, (xmlChar *) MSS_PROP_LANGUAGE); @@ -263,12 +266,14 @@ _gst_mss_stream_init (GstMssManifest * manifest, GstMssStream * stream, * of the manifest. */ + GST_DEBUG ("lang '%s' url %s", stream->lang, stream->url); GST_DEBUG ("Live stream: %s, look-ahead fragments: %" G_GUINT64_FORMAT, manifest->is_live ? "yes" : "no", manifest->look_ahead_fragment_count); stream->has_live_fragments = manifest->is_live && manifest->look_ahead_fragment_count; for (iter = node->children; iter; iter = iter->next) { + GST_LOG ("Handling child '%s'", iter->name); if (node_has_type (iter, MSS_NODE_STREAM_FRAGMENT)) { gst_mss_fragment_list_builder_add (&builder, iter); } else if (node_has_type (iter, MSS_NODE_STREAM_QUALITY)) { @@ -439,6 +444,7 @@ gst_mss_stream_free (GstMssStream * stream) g_list_free_full (stream->qualities, (GDestroyNotify) gst_mss_stream_quality_free); xmlFree (stream->url); + xmlFree (stream->name); xmlFree (stream->lang); g_regex_unref (stream->regex_position); g_regex_unref (stream->regex_bitrate); @@ -1499,6 +1505,12 @@ gst_mss_stream_get_lang (GstMssStream * stream) return stream->lang; } +const gchar * +gst_mss_stream_get_name (GstMssStream * stream) +{ + return stream->name; +} + static GstClockTime gst_mss_manifest_get_dvr_window_length_clock_time (GstMssManifest * manifest) { diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.h index a88f5d72d6..86da662e80 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssmanifest.h @@ -71,6 +71,7 @@ GstFlowReturn gst_mss_stream_advance_fragment (GstMssStream * stream); GstFlowReturn gst_mss_stream_regress_fragment (GstMssStream * stream); void gst_mss_stream_seek (GstMssStream * stream, gboolean forward, GstSeekFlags flags, gint64 time, gint64 * final_time); const gchar * gst_mss_stream_get_lang (GstMssStream * stream); +const gchar * gst_mss_stream_get_name (GstMssStream * stream); const gchar * gst_mss_stream_type_name (GstMssStreamType streamtype); -- 2.34.1