Index: libs/gst/base/gstbasetransform.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/libs/gst/base/gstbasetransform.c,v
retrieving revision 1.123
diff -u -p -r1.123 gstbasetransform.c
--- libs/gst/base/gstbasetransform.c	20 Aug 2008 10:52:08 -0000	1.123
+++ libs/gst/base/gstbasetransform.c	20 Aug 2008 23:49:17 -0000
@@ -1068,7 +1068,7 @@ gst_base_transform_prepare_output_buffer
   GstFlowReturn ret = GST_FLOW_OK;
   guint outsize, newsize, expsize;
   gboolean discard;
-  GstCaps *incaps, *oldcaps, *newcaps;
+  GstCaps *incaps = NULL, *oldcaps = NULL, *newcaps, *tmpcaps;
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
@@ -1095,20 +1095,42 @@ gst_base_transform_prepare_output_buffer
        * the input buffer. */
       discard = gst_buffer_is_writable (in_buf);
     } else {
+      GstCaps *srccaps, *sinkcaps;
+      gboolean res;
+      GST_OBJECT_LOCK (trans->sinkpad);
+      sinkcaps = GST_PAD_CAPS (trans->sinkpad);
+      if (sinkcaps)
+        gst_caps_ref (sinkcaps);
+      GST_OBJECT_UNLOCK (trans->sinkpad);
+      GST_OBJECT_LOCK (trans->srcpad);
+      srccaps = GST_PAD_CAPS (trans->srcpad);
+      if (srccaps)
+        gst_caps_ref (srccaps);
+      GST_OBJECT_UNLOCK (trans->srcpad);
+
       GST_DEBUG_OBJECT (trans, "getting output size for copy transform");
       /* copy transform, figure out the output size */
-      if (!gst_base_transform_transform_size (trans,
-              GST_PAD_SINK, GST_PAD_CAPS (trans->sinkpad),
-              GST_BUFFER_SIZE (in_buf), GST_PAD_CAPS (trans->srcpad),
-              &outsize)) {
+      res = gst_base_transform_transform_size (trans,
+          GST_PAD_SINK, sinkcaps,
+          GST_BUFFER_SIZE (in_buf), srccaps,
+          &outsize);
+      if (srccaps)
+        gst_caps_unref (srccaps);
+      if (sinkcaps)
+        gst_caps_unref (sinkcaps);
+      if (!res)
         goto unknown_size;
-      }
+
       /* never discard this buffer, we need it for storing the output */
       discard = FALSE;
     }
   }
 
+  GST_OBJECT_LOCK (trans->srcpad);
   oldcaps = GST_PAD_CAPS (trans->srcpad);
+  if (oldcaps)
+    gst_caps_ref (oldcaps);
+  GST_OBJECT_UNLOCK (trans->srcpad);
 
   if (bclass->prepare_output_buffer) {
     GST_DEBUG_OBJECT (trans,
@@ -1149,7 +1171,11 @@ gst_base_transform_prepare_output_buffer
 
     GST_DEBUG_OBJECT (trans, "received new caps %" GST_PTR_FORMAT, newcaps);
 
+    GST_OBJECT_LOCK (trans);
     incaps = GST_PAD_CAPS (trans->sinkpad);
+    if (incaps)
+      gst_caps_ref (incaps);
+    GST_OBJECT_UNLOCK (trans);
 
     /* it's possible that the buffer we got is of the wrong size, get the
      * expected size here, we will check the size if we are going to use the
@@ -1223,6 +1249,7 @@ gst_base_transform_prepare_output_buffer
         gst_buffer_unref (*out_buf);
       *out_buf = NULL;
     }
+    gst_caps_unref (incaps);
   }
 
   if (*out_buf == NULL) {
@@ -1255,7 +1282,15 @@ gst_base_transform_prepare_output_buffer
           GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
     }
   }
-  gst_buffer_set_caps (*out_buf, GST_PAD_CAPS (trans->srcpad));
+
+  GST_OBJECT_LOCK (trans->srcpad);
+  tmpcaps = GST_PAD_CAPS (trans->srcpad);
+  if (tmpcaps)
+    gst_caps_ref (tmpcaps);
+  GST_OBJECT_UNLOCK (trans->srcpad);
+  gst_buffer_set_caps (*out_buf, tmpcaps);
+  if (tmpcaps)
+    gst_caps_unref (tmpcaps);
 
   /* clear the GAP flag when the subclass does not understand it */
   if (!trans->priv->gap_aware)
@@ -1266,6 +1301,8 @@ gst_base_transform_prepare_output_buffer
   /* ERRORS */
 alloc_failed:
   {
+    if (oldcaps)
+      gst_caps_unref (oldcaps);
     GST_WARNING_OBJECT (trans, "pad-alloc failed: %s", gst_flow_get_name (ret));
     return ret;
   }
@@ -1276,6 +1313,10 @@ unknown_size:
   }
 failed_configure:
   {
+    if (incaps)
+      gst_caps_unref (incaps);
+    if (oldcaps)
+      gst_caps_unref (oldcaps);
     GST_WARNING_OBJECT (trans, "failed to configure caps");
     return GST_FLOW_NOT_NEGOTIATED;
   }
@@ -1953,12 +1994,14 @@ gst_base_transform_activate (GstBaseTran
 
     GST_OBJECT_LOCK (trans);
 
+    GST_OBJECT_LOCK (trans->sinkpad);
     if (GST_PAD_CAPS (trans->sinkpad) && GST_PAD_CAPS (trans->srcpad))
       trans->have_same_caps =
           gst_caps_is_equal (GST_PAD_CAPS (trans->sinkpad),
           GST_PAD_CAPS (trans->srcpad)) || trans->passthrough;
     else
       trans->have_same_caps = trans->passthrough;
+    GST_OBJECT_UNLOCK (trans->sinkpad);
     GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
     trans->negotiated = FALSE;
     trans->have_newsegment = FALSE;
