From 6ac2e5d3846b2038113ed2dda7c298e296faa938 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 18 Jan 2011 01:09:53 +0530 Subject: [PATCH] discoverer: Drop new stream tags once preroll is done This makes sure we do not touch the stream taglist once the pipeline has been prerolled. Adding of stream tags happens in the pad event probe which runs in a different thread from discoverer stream processing, so modifying the tag list while discoverer might be processing it can sometimes cause a crash. https://bugzilla.gnome.org/show_bug.cgi?id=639778 --- gst-libs/gst/pbutils/gstdiscoverer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/pbutils/gstdiscoverer.c b/gst-libs/gst/pbutils/gstdiscoverer.c index 46e2cfbb6b..8422d8f10b 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer.c +++ b/gst-libs/gst/pbutils/gstdiscoverer.c @@ -393,10 +393,15 @@ _event_probe (GstPad * pad, GstEvent * event, PrivateStream * ps) gst_event_parse_tag (event, &tl); GST_DEBUG_OBJECT (pad, "tags %" GST_PTR_FORMAT, tl); DISCO_LOCK (ps->dc); - tmp = gst_tag_list_merge (ps->tags, tl, GST_TAG_MERGE_APPEND); - if (ps->tags) - gst_tag_list_free (ps->tags); - ps->tags = tmp; + /* If preroll is complete, drop these tags - the collected information is + * possibly already being processed and adding more tags would be racy */ + if (G_LIKELY (ps->dc->priv->processing)) { + tmp = gst_tag_list_merge (ps->tags, tl, GST_TAG_MERGE_APPEND); + if (ps->tags) + gst_tag_list_free (ps->tags); + ps->tags = tmp; + } else + GST_DEBUG_OBJECT (ps->dc, "Dropping tags since preroll is done"); DISCO_UNLOCK (ps->dc); } @@ -1143,7 +1148,10 @@ discoverer_bus_cb (GstBus * bus, GstMessage * msg, GstDiscoverer * dc) if (dc->priv->processing) { if (handle_message (dc, msg)) { GST_DEBUG ("Stopping asynchronously"); + /* Serialise with _event_probe() */ + DISCO_LOCK (dc); dc->priv->processing = FALSE; + DISCO_UNLOCK (dc); discoverer_collect (dc); discoverer_cleanup (dc); }