Index: gst/gstpad.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpad.c,v
retrieving revision 1.552
diff -u -p -u -p -r1.552 gstpad.c
--- gst/gstpad.c	12 Apr 2007 10:32:38 -0000	1.552
+++ gst/gstpad.c	12 Apr 2007 19:38:14 -0000
@@ -2349,6 +2349,15 @@ gst_pad_set_caps (GstPad * pad, GstCaps 
   if (gst_caps_is_equal (caps, existing))
     goto setting_same_caps;
 
+  /* If the pad has a pad template check whether the caps that
+   * are tried to be set are compatible with the template */
+  if (GST_PAD_PAD_TEMPLATE (pad)) {
+    GST_OBJECT_UNLOCK (pad);
+    if (!gst_pad_accept_caps (pad, caps))
+      goto invalid_caps;
+    GST_OBJECT_LOCK (pad);
+  }
+
   setcaps = GST_PAD_SETCAPSFUNC (pad);
 
   /* call setcaps function to configure the pad only if the
@@ -2399,21 +2408,22 @@ could_not_set:
 
     return FALSE;
   }
+invalid_caps:
+  {
+    GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
+        "caps %" GST_PTR_FORMAT " not compatible with pad template", caps);
+    return FALSE;
+  }
 }
 
 static gboolean
 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
 {
-  GstPadSetCapsFunction setcaps;
   gboolean res;
 
-  setcaps = GST_PAD_SETCAPSFUNC (pad);
-
-  /* See if pad accepts the caps - only needed if 
-   * no setcaps function */
-  if (setcaps == NULL)
-    if (!gst_pad_accept_caps (pad, caps))
-      goto not_accepted;
+  /* See if pad accepts the caps */
+  if (!gst_pad_accept_caps (pad, caps))
+    goto not_accepted;
 
   /* set caps on pad if call succeeds */
   res = gst_pad_set_caps (pad, caps);
@@ -2434,16 +2444,11 @@ not_accepted:
 static gboolean
 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
 {
-  GstPadSetCapsFunction setcaps;
   gboolean res;
 
-  setcaps = GST_PAD_SETCAPSFUNC (pad);
-
-  /* See if pad accepts the caps - only needed if 
-   * no setcaps function */
-  if (setcaps == NULL)
-    if (!gst_pad_accept_caps (pad, caps))
-      goto not_accepted;
+  /* See if pad accepts the caps */
+  if (!gst_pad_accept_caps (pad, caps))
+    goto not_accepted;
 
   if (dosetcaps)
     res = gst_pad_set_caps (pad, caps);
@@ -2743,6 +2748,12 @@ gst_pad_alloc_buffer_full (GstPad * pad,
     if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, setcaps)))
       goto not_negotiated;
   }
+
+  /* If no caps were set and the buffer assume the pad caps and
+   * set them here to get renegotiation working in all cases */
+  if (!caps)
+    gst_buffer_set_caps (*buf, GST_PAD_CAPS (pad));
+
   return ret;
 
 flushed:
@@ -3615,6 +3626,11 @@ gst_pad_push (GstPad * pad, GstBuffer * 
 
   GST_OBJECT_UNLOCK (pad);
 
+  /* If no caps were set and the buffer assume the pad caps and
+   * set them here to get renegotiation working in all cases */
+  if (!caps)
+    gst_buffer_set_caps (buffer, GST_PAD_CAPS (pad));
+
   /* we got a new datatype from the pad, it had better handle it */
   if (G_UNLIKELY (caps_changed)) {
     GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
@@ -3805,6 +3821,11 @@ gst_pad_get_range (GstPad * pad, guint64
     caps_changed = caps && caps != GST_PAD_CAPS (pad);
     GST_OBJECT_UNLOCK (pad);
 
+    /* If no caps were set and the buffer assume the pad caps and
+     * set them here to get renegotiation working in all cases */
+    if (!caps)
+      gst_buffer_set_caps (*buffer, GST_PAD_CAPS (pad));
+
     /* we got a new datatype from the pad not supported in a running pull-mode
      * pipeline */
     if (G_UNLIKELY (caps_changed))
