Index: gst/gstpad.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpad.c,v
retrieving revision 1.485
diff -u -B -b -p -r1.485 gstpad.c
--- gst/gstpad.c	28 Nov 2005 10:04:45 -0000	1.485
+++ gst/gstpad.c	5 Dec 2005 09:41:04 -0000
@@ -2215,7 +2215,7 @@ not_accepted:
 
 /* returns TRUE if the src pad could be configured to accept the given caps */
 static gboolean
-gst_pad_configure_src (GstPad * pad, GstCaps * caps)
+gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
 {
   GstPadAcceptCapsFunction acceptcaps;
   GstPadSetCapsFunction setcaps;
@@ -2230,10 +2230,10 @@ gst_pad_configure_src (GstPad * pad, Gst
     if (!acceptcaps (pad, caps))
       goto not_accepted;
   }
-  /* set caps on pad if call succeeds */
+  if (dosetcaps)
   res = gst_pad_set_caps (pad, caps);
-  /* no need to unref the caps here, set_caps takes a ref and
-   * our ref goes away when we leave this function. */
+  else
+    res = TRUE;
 
   return res;
 
@@ -2405,33 +2405,9 @@ no_peer:
   }
 }
 
-/**
- * gst_pad_alloc_buffer:
- * @pad: a source #GstPad
- * @offset: the offset of the new buffer in the stream
- * @size: the size of the new buffer
- * @caps: the caps of the new buffer
- * @buf: a newly allocated buffer
- *
- * Allocates a new, empty buffer optimized to push to pad @pad.  This
- * function only works if @pad is a source pad and has a peer.
- *
- * You need to check the caps of the buffer after performing this
- * function and renegotiate to the format if needed.
- *
- * A new, empty #GstBuffer will be put in the @buf argument.
- *
- * Returns: a result code indicating success of the operation. Any
- * result code other than GST_FLOW_OK is an error and @buf should
- * not be used.
- * An error can occur if the pad is not connected or when the downstream
- * peer elements cannot provide an acceptable buffer.
- *
- * MT safe.
- */
-GstFlowReturn
-gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
-    GstBuffer ** buf)
+static GstFlowReturn
+gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
+    GstBuffer ** buf, gboolean setcaps)
 {
   GstPad *peer;
   GstFlowReturn ret;
@@ -2499,7 +2475,7 @@ do_caps:
   /* we got a new datatype on the pad, see if it can handle it */
   if (G_UNLIKELY (caps_changed)) {
     GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
-    if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
+    if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, setcaps)))
       goto not_negotiated;
   }
   return ret;
@@ -2559,6 +2535,64 @@ peer_error:
 }
 
 /**
+ * gst_pad_alloc_buffer:
+ * @pad: a source #GstPad
+ * @offset: the offset of the new buffer in the stream
+ * @size: the size of the new buffer
+ * @caps: the caps of the new buffer
+ * @buf: a newly allocated buffer
+ *
+ * Allocates a new, empty buffer optimized to push to pad @pad.  This
+ * function only works if @pad is a source pad and has a peer.
+ *
+ * You need to check the caps of the buffer after performing this
+ * function and renegotiate to the format if needed.
+ *
+ * A new, empty #GstBuffer will be put in the @buf argument.
+ *
+ * Returns: a result code indicating success of the operation. Any
+ * result code other than GST_FLOW_OK is an error and @buf should
+ * not be used.
+ * An error can occur if the pad is not connected or when the downstream
+ * peer elements cannot provide an acceptable buffer.
+ *
+ * MT safe.
+ */
+GstFlowReturn
+gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
+    GstBuffer ** buf)
+{
+  return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
+}
+
+/**
+ * gst_pad_alloc_buffer_and_set_caps:
+ * @pad: a source #GstPad
+ * @offset: the offset of the new buffer in the stream
+ * @size: the size of the new buffer
+ * @caps: the caps of the new buffer
+ * @buf: a newly allocated buffer
+ *
+ * In addition to the function gst_pad_alloc_buffer(), this function
+ * automatically calls gst_pad_set_caps() when the caps of the
+ * newly allocated buffer are different from the @pad caps.
+ *
+ * Returns: a result code indicating success of the operation. Any
+ * result code other than GST_FLOW_OK is an error and @buf should
+ * not be used.
+ * An error can occur if the pad is not connected or when the downstream
+ * peer elements cannot provide an acceptable buffer.
+ *
+ * MT safe.
+ */
+GstFlowReturn
+gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size, 
+    GstCaps * caps, GstBuffer ** buf)
+{
+  return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
+}
+
+/**
  * gst_pad_get_internal_links_default:
  * @pad: the #GstPad to get the internal links of.
  *
Index: gst/gstpad.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpad.h,v
retrieving revision 1.204
diff -u -B -b -p -r1.204 gstpad.h
--- gst/gstpad.h	24 Nov 2005 09:44:06 -0000	1.204
+++ gst/gstpad.h	5 Dec 2005 09:41:04 -0000
@@ -712,6 +712,8 @@ GstPadTemplate*		gst_pad_get_pad_templat
 void			gst_pad_set_bufferalloc_function	(GstPad *pad, GstPadBufferAllocFunction bufalloc);
 GstFlowReturn		gst_pad_alloc_buffer			(GstPad *pad, guint64 offset, gint size,
 								 GstCaps *caps, GstBuffer **buf);
+GstFlowReturn		gst_pad_alloc_buffer_and_set_caps	(GstPad *pad, guint64 offset, gint size,
+								 GstCaps *caps, GstBuffer **buf);
 
 /* data passing setup functions */
 void			gst_pad_set_activate_function		(GstPad *pad, GstPadActivateFunction activate);
