decodebin: Fix locking
authorSebastian Dröge <sebastian@centricular.com>
Tue, 21 Oct 2014 11:30:27 +0000 (13:30 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 21 Oct 2014 11:32:19 +0000 (13:32 +0200)
The chain mutex needs to be locked when looking at chain->elements. Move code
around a bit to require only one lock() and unlock().

gst/playback/gstdecodebin2.c

index bcc4db8..362c78a 100644 (file)
@@ -2122,12 +2122,16 @@ connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
         if (pelem && gst_element_get_factory (pelem->element) == factory)
           skip = TRUE;
       }
-      CHAIN_MUTEX_UNLOCK (chain);
 
-      if (!skip && chain->elements) {
+      if (skip) {
+        GST_DEBUG_OBJECT (dbin,
+            "Skipping factory '%s' because it was already used in this chain",
+            gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (factory)));
+        CHAIN_MUTEX_UNLOCK (chain);
+        continue;
+      } else if (chain->elements) {
         GstElementFactory *chainelemfact;
 
-        CHAIN_MUTEX_LOCK (chain);
         delem = (GstDecodeElement *) chain->elements->data;
         chainelemfact = gst_element_get_factory (delem->element);
 
@@ -2142,15 +2146,9 @@ connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
           CHAIN_MUTEX_UNLOCK (chain);
           continue;
         }
-        CHAIN_MUTEX_UNLOCK (chain);
-      }
-      if (skip) {
-        GST_DEBUG_OBJECT (dbin,
-            "Skipping factory '%s' because it was already used in this chain",
-            gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (factory)));
-        continue;
       }
 
+      CHAIN_MUTEX_UNLOCK (chain);
     }
 
     /* emit autoplug-select to see what we should do with it. */