appsrc: Always take the object lock when accessing the caps
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 14 May 2010 15:24:14 +0000 (17:24 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 14 May 2010 15:24:14 +0000 (17:24 +0200)
Fixes bug #618625.

gst-libs/gst/app/gstappsrc.c

index 25cf39f..74e8bee 100644 (file)
@@ -939,8 +939,10 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
   GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
   GstAppSrcPrivate *priv = appsrc->priv;
   GstFlowReturn ret;
+  GstCaps *caps;
 
   GST_OBJECT_LOCK (appsrc);
+  caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
   if (G_UNLIKELY (priv->size != bsrc->segment.duration &&
           bsrc->segment.format == GST_FORMAT_BYTES)) {
     GST_DEBUG_OBJECT (appsrc,
@@ -994,7 +996,7 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
       if (priv->stream_type == GST_APP_STREAM_TYPE_RANDOM_ACCESS)
         priv->offset += buf_size;
       *buf = gst_buffer_make_metadata_writable (*buf);
-      gst_buffer_set_caps (*buf, priv->caps);
+      gst_buffer_set_caps (*buf, caps);
 
       /* signal that we removed an item */
       g_cond_broadcast (priv->cond);
@@ -1034,7 +1036,8 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
     g_cond_wait (priv->cond, priv->mutex);
   }
   g_mutex_unlock (priv->mutex);
-
+  if (caps)
+    gst_caps_unref (caps);
   return ret;
 
   /* ERRORS */
@@ -1042,17 +1045,23 @@ flushing:
   {
     GST_DEBUG_OBJECT (appsrc, "we are flushing");
     g_mutex_unlock (priv->mutex);
+    if (caps)
+      gst_caps_unref (caps);
     return GST_FLOW_WRONG_STATE;
   }
 eos:
   {
     GST_DEBUG_OBJECT (appsrc, "we are EOS");
     g_mutex_unlock (priv->mutex);
+    if (caps)
+      gst_caps_unref (caps);
     return GST_FLOW_UNEXPECTED;
   }
 seek_error:
   {
     g_mutex_unlock (priv->mutex);
+    if (caps)
+      gst_caps_unref (caps);
     GST_ELEMENT_ERROR (appsrc, RESOURCE, READ, ("failed to seek"),
         GST_ERROR_SYSTEM);
     return GST_FLOW_ERROR;