discoverer: Drop new stream tags once preroll is done
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 17 Jan 2011 19:39:53 +0000 (01:09 +0530)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 17 Jan 2011 23:50:45 +0000 (23:50 +0000)
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

index 46e2cfb..8422d8f 100644 (file)
@@ -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);
     }