From a55dafe341ac7398e7c37c30d8b760228296da92 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Sun, 12 Sep 2021 10:07:49 +0100 Subject: [PATCH] discoverer: Prevent stream tags from leaking in global tags The PrivateStream should keep track of stream tags only. Likewise, the GstDiscovererInfo should keep track of global tags only. This patch fixes the issue where the discoverer would report duplicated tag titles, especially for Matroska media files. The Matroska demuxer emits correctly-scoped tags, but downstream was making no distinction of them. Fixes #598, #836, https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/827 Part-of: --- gst-libs/gst/pbutils/gstdiscoverer.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/pbutils/gstdiscoverer.c b/gst-libs/gst/pbutils/gstdiscoverer.c index 6d175316cb..685bb279ef 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer.c +++ b/gst-libs/gst/pbutils/gstdiscoverer.c @@ -539,9 +539,17 @@ _event_probe (GstPad * pad, GstPadProbeInfo * info, PrivateStream * ps) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_TAG:{ GstTagList *tl = NULL, *tmp; + GstTagScope scope; gst_event_parse_tag (event, &tl); + scope = gst_tag_list_get_scope (tl); GST_DEBUG_OBJECT (pad, "tags %" GST_PTR_FORMAT, tl); + + if (scope != GST_TAG_SCOPE_STREAM) { + GST_DEBUG_OBJECT (pad, "Ignoring non-stream tags"); + break; + } + DISCO_LOCK (ps->dc); /* If preroll is complete, drop these tags - the collected information is * possibly already being processed and adding more tags would be racy */ @@ -1703,10 +1711,19 @@ handle_message (GstDiscoverer * dc, GstMessage * msg) case GST_MESSAGE_TAG: { - GstTagList *tl, *tmp; + GstTagList *tl, *tmp = NULL; + GstTagScope scope; gst_message_parse_tag (msg, &tl); + scope = gst_tag_list_get_scope (tl); GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "Got tags %" GST_PTR_FORMAT, tl); + + if (scope != GST_TAG_SCOPE_GLOBAL) { + GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "Ignoring non-global tags"); + gst_tag_list_unref (tl); + break; + } + /* Merge with current tags */ tmp = gst_tag_list_merge (dc->priv->current_info->tags, tl,