gstreamer_core/libs/gst/base/gstbasetransform.c
branchRCL_3
changeset 29 567bb019e3e3
parent 0 0e761a78d257
child 30 7e817e7e631c
--- a/gstreamer_core/libs/gst/base/gstbasetransform.c	Wed Mar 31 22:03:18 2010 +0300
+++ b/gstreamer_core/libs/gst/base/gstbasetransform.c	Tue Aug 31 15:30:33 2010 +0300
@@ -1,9 +1,9 @@
 /* GStreamer
  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
- *                    2000 Wim Taymans <wtay@chello.be>
  *                    2005 Wim Taymans <wim@fluendo.com>
  *                    2005 Andy Wingo <wingo@fluendo.com>
  *                    2005 Thomas Vander Stichele <thomas at apestaart dot org>
+ *                    2008 Wim Taymans <wim.taymans@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -44,7 +44,9 @@
  *    </para></listitem>
  * </itemizedlist>
  *
- * Use Cases:
+ * <refsect2>
+ * <title>Use Cases</title>
+ * <para>
  * <orderedlist>
  * <listitem>
  *   <itemizedlist><title>Passthrough mode</title>
@@ -158,8 +160,12 @@
  *   </itemizedlist>
  * </listitem>
  * </orderedlist>
- *
- * <itemizedlist><title>Sub-class settable flags on GstBaseTransform</title>
+ * </para>
+ * </refsect2>
+ * <refsect2>
+ * <title>Sub-class settable flags on GstBaseTransform</title>
+ * <para>
+ * <itemizedlist>
  * <listitem><para>
  *   <itemizedlist><title>passthrough</title>
  *     <listitem><para>
@@ -188,8 +194,9 @@
  *   </itemizedlist>
  * </para></listitem>
  * </itemizedlist>
- *
-*/
+ * </para>
+ * </refsect2>
+ */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
@@ -245,6 +252,17 @@
   GstActivateMode pad_mode;
 
   gboolean gap_aware;
+
+  /* caps used for allocating buffers */
+  gboolean proxy_alloc;
+  GstCaps *sink_alloc;
+  GstCaps *src_alloc;
+  /* upstream caps and size suggestions */
+  GstCaps *sink_suggest;
+  guint size_suggest;
+  gboolean suggest_pending;
+
+  gboolean reconfigure;
 };
 
 static GstElementClass *parent_class = NULL;
@@ -253,7 +271,7 @@
 static void gst_base_transform_init (GstBaseTransform * trans,
     GstBaseTransformClass * klass);
 static GstFlowReturn gst_base_transform_prepare_output_buffer (GstBaseTransform
-    * trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
+    * trans, GstBuffer * input, GstBuffer ** buf);
 #ifdef __SYMBIAN32__
 EXPORT_C
 #endif
@@ -262,9 +280,10 @@
 GType
 gst_base_transform_get_type (void)
 {
-  static GType base_transform_type = 0;
+  static volatile gsize base_transform_type = 0;
 
-  if (!base_transform_type) {
+  if (g_once_init_enter (&base_transform_type)) {
+    GType _type;
     static const GTypeInfo base_transform_info = {
       sizeof (GstBaseTransformClass),
       NULL,
@@ -277,8 +296,9 @@
       (GInstanceInitFunc) gst_base_transform_init,
     };
 
-    base_transform_type = g_type_register_static (GST_TYPE_ELEMENT,
+    _type = g_type_register_static (GST_TYPE_ELEMENT,
         "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
+    g_once_init_leave (&base_transform_type, _type);
   }
   return base_transform_type;
 }
@@ -309,6 +329,7 @@
 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
     GstBuffer * buffer);
 static GstCaps *gst_base_transform_getcaps (GstPad * pad);
+static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
 static gboolean gst_base_transform_setcaps (GstPad * pad, GstCaps * caps);
 static GstFlowReturn gst_base_transform_buffer_alloc (GstPad * pad,
     guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
@@ -322,6 +343,7 @@
 
   trans = GST_BASE_TRANSFORM (object);
 
+  gst_caps_replace (&trans->priv->sink_suggest, NULL);
   g_mutex_free (trans->transform_lock);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -337,6 +359,8 @@
   GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
       "basetransform element");
 
+  GST_DEBUG ("gst_base_transform_class_init");
+
   g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
 
   parent_class = g_type_class_peek_parent (klass);
@@ -348,7 +372,7 @@
 
   g_object_class_install_property (gobject_class, PROP_QOS,
       g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
-          DEFAULT_PROP_QOS, G_PARAM_READWRITE));
+          DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_transform_finalize);
 
@@ -373,6 +397,8 @@
   trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
   gst_pad_set_getcaps_function (trans->sinkpad,
       GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
+  gst_pad_set_acceptcaps_function (trans->sinkpad,
+      GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
   gst_pad_set_setcaps_function (trans->sinkpad,
       GST_DEBUG_FUNCPTR (gst_base_transform_setcaps));
   gst_pad_set_event_function (trans->sinkpad,
@@ -391,8 +417,8 @@
   trans->srcpad = gst_pad_new_from_template (pad_template, "src");
   gst_pad_set_getcaps_function (trans->srcpad,
       GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
-  gst_pad_set_setcaps_function (trans->srcpad,
-      GST_DEBUG_FUNCPTR (gst_base_transform_setcaps));
+  gst_pad_set_acceptcaps_function (trans->srcpad,
+      GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
   gst_pad_set_event_function (trans->srcpad,
       GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
   gst_pad_set_checkgetrange_function (trans->srcpad,
@@ -404,7 +430,6 @@
   gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
 
   trans->transform_lock = g_mutex_new ();
-  trans->delay_configure = FALSE;
   trans->pending_configure = FALSE;
   trans->priv->qos_enabled = DEFAULT_PROP_QOS;
   trans->cache_caps1 = NULL;
@@ -418,8 +443,10 @@
     GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
     trans->always_in_place = TRUE;
 
-    if (bclass->transform_ip == NULL)
+    if (bclass->transform_ip == NULL) {
+      GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
       trans->passthrough = TRUE;
+    }
   }
 }
 
@@ -435,6 +462,9 @@
   GstCaps *ret;
   GstBaseTransformClass *klass;
 
+  if (caps == NULL)
+    return NULL;
+
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
   /* if there is a custom transform function, use this */
@@ -455,32 +485,36 @@
       temp = gst_caps_make_writable (temp);
       gst_caps_append (ret, temp);
     } else {
+      gint n = gst_caps_get_size (caps);
       /* we send caps with just one structure to the transform
        * function as this is easier for the element */
-      for (i = 0; i < gst_caps_get_size (caps); i++) {
+      for (i = 0; i < n; i++) {
         GstCaps *nth;
 
         nth = gst_caps_copy_nth (caps, i);
-        GST_DEBUG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
+        GST_LOG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
         temp = klass->transform_caps (trans, direction, nth);
         gst_caps_unref (nth);
-        GST_DEBUG_OBJECT (trans, "  to[%d]: %" GST_PTR_FORMAT, i, temp);
+        GST_LOG_OBJECT (trans, "  to[%d]: %" GST_PTR_FORMAT, i, temp);
 
         temp = gst_caps_make_writable (temp);
-        /* FIXME: here we need to only append those structures, that are not yet
-         * in there
-         * gst_caps_append (ret, temp);
-         */
+
+        /* here we need to only append those structures, that are not yet
+         * in there, we use the merge function for this */
         gst_caps_merge (ret, temp);
+
+        GST_LOG_OBJECT (trans, "  merged[%d]: %" GST_PTR_FORMAT, i, ret);
       }
-      GST_DEBUG_OBJECT (trans, "merged: (%d)", gst_caps_get_size (ret));
-      /* now simplify caps
-         gst_caps_do_simplify (ret);
-         GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
+      GST_LOG_OBJECT (trans, "merged: (%d)", gst_caps_get_size (ret));
+      /* FIXME: we can't do much simplification here because we don't really want to
+       * change the caps order
+       gst_caps_do_simplify (ret);
+       GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
        */
     }
   } else {
-    /* else use the identity transform */
+    GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
+    /* no transform function, use the identity transform */
     ret = gst_caps_ref (caps);
   }
 
@@ -490,6 +524,15 @@
   return ret;
 }
 
+/* transform a buffer of @size with @caps on the pad with @direction to
+ * the size of a buffer with @othercaps and store the result in @othersize
+ *
+ * We have two ways of doing this:
+ *  1) use a custom transform size function, this is for complicated custom
+ *     cases with no fixed unit_size.
+ *  2) use the unit_size functions where there is a relationship between the
+ *     caps and the size of a buffer.
+ */
 static gboolean
 gst_base_transform_transform_size (GstBaseTransform * trans,
     GstPadDirection direction, GstCaps * caps,
@@ -505,24 +548,33 @@
       GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
       size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
 
-  /* if there is a custom transform function, use this */
   if (klass->transform_size) {
+    /* if there is a custom transform function, use this */
     ret = klass->transform_size (trans, direction, caps, size, othercaps,
         othersize);
   } else {
+    /* there is no transform_size function, we have to use the unit_size
+     * functions. This method assumes there is a fixed unit_size associated with
+     * each caps. We provide the same amount of units on both sides. */
     if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
       goto no_in_size;
 
     GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
         inunitsize);
 
+    /* input size must be a multiple of the unit_size of the input caps */
     if (inunitsize == 0 || (size % inunitsize != 0))
       goto no_multiple;
 
+    /* get the amount of units */
     units = size / inunitsize;
+
+    /* now get the unit size of the output */
     if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
       goto no_out_size;
 
+    /* the output size is the unit_size times the amount of units on the
+     * input */
     *othersize = units * outunitsize;
     GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
 
@@ -553,6 +605,15 @@
   }
 }
 
+/* get the caps that can be handled by @pad. We perform:
+ *
+ *  - take the caps of peer of otherpad,
+ *  - filter against the padtemplate of otherpad, 
+ *  - calculate all transforms of remaining caps
+ *  - filter against template of @pad
+ *
+ * If there is no peer, we simply return the caps of the padtemplate of pad.
+ */
 static GstCaps *
 gst_base_transform_getcaps (GstPad * pad)
 {
@@ -578,6 +639,7 @@
     temp = gst_caps_intersect (caps, templ);
     GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
     gst_caps_unref (caps);
+
     /* then see what we can transform this to */
     caps = gst_base_transform_transform_caps (trans,
         GST_PAD_DIRECTION (otherpad), temp);
@@ -595,7 +657,7 @@
     /* this is what we can do */
     caps = temp;
   } else {
-    /* no peer, our padtemplate is enough then */
+    /* no peer or the peer can do anything, our padtemplate is enough then */
     caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
   }
 
@@ -618,10 +680,17 @@
 
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
+  GST_DEBUG_OBJECT (trans, "in caps:  %" GST_PTR_FORMAT, in);
+  GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
+
   /* clear the cache */
   gst_caps_replace (&trans->cache_caps1, NULL);
   gst_caps_replace (&trans->cache_caps2, NULL);
 
+  /* figure out same caps state */
+  trans->have_same_caps = gst_caps_is_equal (in, out);
+  GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
+
   /* If we've a transform_ip method and same input/output caps, set in_place
    * by default. If for some reason the sub-class prefers using a transform
    * function, it can clear the in place flag in the set_caps */
@@ -644,33 +713,90 @@
   return ret;
 }
 
-/* called when new caps arrive on the sink or source pad */
+/* check if caps @in on @pad can be transformed to @out on the other pad.
+ * We don't have a vmethod to test this yet so we have to do a somewhat less
+ * efficient check for this.
+ */
 static gboolean
-gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
+gst_base_transform_can_transform (GstBaseTransform * trans, GstPad * pad,
+    GstCaps * in, GstCaps * out)
 {
-  GstBaseTransform *trans;
+  GstCaps *othercaps;
+
+  /* convert the in caps to all possible out caps */
+  othercaps =
+      gst_base_transform_transform_caps (trans, GST_PAD_DIRECTION (pad), in);
+
+  /* check if transform is empty */
+  if (!othercaps || gst_caps_is_empty (othercaps))
+    goto no_transform;
+
+  /* check if the out caps is a subset of the othercaps */
+  if (!gst_caps_is_subset (out, othercaps))
+    goto no_subset;
+
+  if (othercaps)
+    gst_caps_unref (othercaps);
+
+  GST_DEBUG_OBJECT (trans, "from %" GST_PTR_FORMAT, in);
+  GST_DEBUG_OBJECT (trans, "to   %" GST_PTR_FORMAT, out);
+
+  return TRUE;
+
+  /* ERRORS */
+no_transform:
+  {
+    GST_DEBUG_OBJECT (trans,
+        "transform returned useless %" GST_PTR_FORMAT, othercaps);
+    if (othercaps)
+      gst_caps_unref (othercaps);
+    return FALSE;
+  }
+no_subset:
+  {
+    GST_DEBUG_OBJECT (trans, "no subset");
+    if (othercaps)
+      gst_caps_unref (othercaps);
+    return FALSE;
+  }
+}
+
+/* given a fixed @caps on @pad, create the best possible caps for the
+ * other pad.
+ * @caps must be fixed when calling this function.
+ *
+ * This function calls the transform caps vmethod of the basetransform to figure
+ * out the possible target formats. It then tries to select the best format from
+ * this list by:
+ *
+ * - attempt passthrough if the target caps is a superset of the input caps
+ * - fixating by using peer caps
+ * - fixating with transform fixate function
+ * - fixating with pad fixate functions.
+ *
+ * this function returns a caps that can be transformed into and is accepted by
+ * the peer element.
+ */
+static GstCaps *
+gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
+    GstCaps * caps)
+{
   GstBaseTransformClass *klass;
   GstPad *otherpad, *otherpeer;
-  GstCaps *othercaps = NULL;
-  gboolean ret = TRUE;
+  GstCaps *othercaps;
   gboolean peer_checked = FALSE;
 
-  trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+  /* caps must be fixed here, this is a programming error if it's not */
+  g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
+
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
   otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
   otherpeer = gst_pad_get_peer (otherpad);
 
-  /* if we get called recursively, we bail out now to avoid an
-   * infinite loop. */
-  if (GST_PAD_IS_IN_SETCAPS (otherpad))
-    goto done;
-
-  /* caps must be fixed here */
-  if (!gst_caps_is_fixed (caps))
-    goto unfixed_caps;
-
-  /* see how we can transform the input caps. */
+  /* see how we can transform the input caps. We need to do this even for
+   * passthrough because it might be possible that this element cannot support
+   * passthrough at all. */
   othercaps = gst_base_transform_transform_caps (trans,
       GST_PAD_DIRECTION (pad), caps);
 
@@ -681,6 +807,9 @@
     const GstCaps *templ_caps;
 
     templ_caps = gst_pad_get_pad_template_caps (otherpad);
+    GST_DEBUG_OBJECT (trans,
+        "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
+
     intersect = gst_caps_intersect (othercaps, templ_caps);
 
     gst_caps_unref (othercaps);
@@ -693,6 +822,8 @@
 
   /* if the othercaps are not fixed, we need to fixate them, first attempt
    * is by attempting passthrough if the othercaps are a superset of caps. */
+  /* FIXME. maybe the caps is not fixed because it has multiple structures of
+   * fixed caps */
   if (!gst_caps_is_fixed (othercaps)) {
     GstCaps *temp;
 
@@ -704,22 +835,28 @@
     temp = gst_caps_intersect (othercaps, caps);
     GST_DEBUG_OBJECT (trans, "intersect returned %" GST_PTR_FORMAT, temp);
     if (temp) {
-      if (!gst_caps_is_empty (temp) && otherpeer) {
+      if (!gst_caps_is_empty (temp)) {
         GST_DEBUG_OBJECT (trans, "try passthrough with %" GST_PTR_FORMAT, caps);
-        /* try passthrough. we know it's fixed, because caps is fixed */
-        if (gst_pad_accept_caps (otherpeer, caps)) {
-          GST_DEBUG_OBJECT (trans, "peer accepted %" GST_PTR_FORMAT, caps);
-          /* peer accepted unmodified caps, we free the original non-fixed
-           * caps and work with the passthrough caps */
+        if (otherpeer) {
+          /* try passthrough. we know it's fixed, because caps is fixed */
+          if (gst_pad_accept_caps (otherpeer, caps)) {
+            GST_DEBUG_OBJECT (trans, "peer accepted %" GST_PTR_FORMAT, caps);
+            /* peer accepted unmodified caps, we free the original non-fixed
+             * caps and work with the passthrough caps */
+            gst_caps_unref (othercaps);
+            othercaps = gst_caps_ref (caps);
+            /* mark that we checked othercaps with the peer, this
+             * makes sure we don't call accept_caps again with these same
+             * caps */
+            peer_checked = TRUE;
+          } else {
+            GST_DEBUG_OBJECT (trans,
+                "peer did not accept %" GST_PTR_FORMAT, caps);
+          }
+        } else {
+          GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
           gst_caps_unref (othercaps);
           othercaps = gst_caps_ref (caps);
-          /* mark that we checked othercaps with the peer, this
-           * makes sure we don't call accept_caps again with these same
-           * caps */
-          peer_checked = TRUE;
-        } else {
-          GST_DEBUG_OBJECT (trans,
-              "peer did not accept %" GST_PTR_FORMAT, caps);
         }
       }
       gst_caps_unref (temp);
@@ -784,6 +921,18 @@
       gst_pad_fixate_caps (otherpad, othercaps);
     }
     GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
+  } else {
+    /* else caps are fixed but the subclass may want to add fields */
+    if (klass->fixate_caps) {
+      othercaps = gst_caps_make_writable (othercaps);
+
+      GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
+          " using caps %" GST_PTR_FORMAT
+          " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
+          GST_DEBUG_PAD_NAME (otherpad));
+
+      klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
+    }
   }
 
   /* caps should be fixed now, if not we have to fail. */
@@ -798,34 +947,185 @@
   GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
       ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
 
-  trans->have_same_caps = gst_caps_is_equal (caps, othercaps);
-  GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
+  if (otherpeer)
+    gst_object_unref (otherpeer);
+
+  return othercaps;
+
+  /* ERRORS */
+no_transform:
+  {
+    GST_DEBUG_OBJECT (trans,
+        "transform returned useless  %" GST_PTR_FORMAT, othercaps);
+    goto error_cleanup;
+  }
+no_transform_possible:
+  {
+    GST_DEBUG_OBJECT (trans,
+        "transform could not transform %" GST_PTR_FORMAT
+        " in anything we support", caps);
+    goto error_cleanup;
+  }
+could_not_fixate:
+  {
+    GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
+    goto error_cleanup;
+  }
+peer_no_accept:
+  {
+    GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
+        " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
+    goto error_cleanup;
+  }
+error_cleanup:
+  {
+    if (otherpeer)
+      gst_object_unref (otherpeer);
+    if (othercaps)
+      gst_caps_unref (othercaps);
+    return NULL;
+  }
+}
 
-  /* see if we have to configure the element now */
-  if (!trans->delay_configure) {
-    GstCaps *incaps, *outcaps;
+static gboolean
+gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
+{
+  GstBaseTransform *trans;
+#if 0
+  GstPad *otherpad;
+  GstCaps *othercaps = NULL;
+#endif
+  gboolean ret = TRUE;
+
+  trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+
+#if 0
+  otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
+
+  /* we need fixed caps for the check, fall back to the default implementation
+   * if we don't */
+  if (!gst_caps_is_fixed (caps))
+#endif
+  {
+    GstCaps *allowed, *intersect;
+
+    GST_DEBUG_OBJECT (pad, "non fixed accept caps %" GST_PTR_FORMAT, caps);
+
+    /* get all the formats we can handle on this pad */
+    allowed = gst_pad_get_caps (pad);
+    if (!allowed)
+      goto no_transform_possible;
+
+    /* intersect with the requested format */
+    intersect = gst_caps_intersect (allowed, caps);
+
+    GST_DEBUG_OBJECT (pad, "intersection %" GST_PTR_FORMAT, intersect);
+
+    /* we can accept if the intersection is not empty  */
+    ret = !gst_caps_is_empty (intersect);
+    gst_caps_unref (intersect);
+    gst_caps_unref (allowed);
+
+    if (!ret)
+      goto no_transform_possible;
+  }
+#if 0
+  else {
+    GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
 
-    /* make sure in and out caps are correct */
-    if (pad == trans->sinkpad) {
-      incaps = caps;
-      outcaps = othercaps;
-    } else {
-      incaps = othercaps;
-      outcaps = caps;
-    }
-    /* call configure now */
-    if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
-      goto failed_configure;
+    /* find best possible caps for the other pad as a way to see if we can
+     * transform this caps. */
+    othercaps = gst_base_transform_find_transform (trans, pad, caps);
+    if (!othercaps || gst_caps_is_empty (othercaps))
+      goto no_transform_possible;
+
+    GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
+  }
+#endif
+
+done:
+#if 0
+  /* We know it's always NULL since we never use it */
+  if (othercaps)
+    gst_caps_unref (othercaps);
+#endif
+  gst_object_unref (trans);
+
+  return ret;
+
+  /* ERRORS */
+no_transform_possible:
+  {
+    GST_WARNING_OBJECT (trans,
+        "transform could not transform %" GST_PTR_FORMAT
+        " in anything we support", caps);
+    ret = FALSE;
+    goto done;
+  }
+}
+
+/* called when new caps arrive on the sink or source pad,
+ * We try to find the best caps for the other side using our _find_transform()
+ * function. If there are caps, we configure the transform for this new
+ * transformation.
+ *
+ * FIXME, this function is currently commutative but this should not really be
+ * because we never set caps starting from the srcpad.
+ */
+static gboolean
+gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
+{
+  GstBaseTransform *trans;
+  GstPad *otherpad, *otherpeer;
+  GstCaps *othercaps = NULL;
+  gboolean ret = TRUE;
+  GstCaps *incaps, *outcaps;
+
+  trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+
+  otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
+  otherpeer = gst_pad_get_peer (otherpad);
+
+  /* if we get called recursively, we bail out now to avoid an
+   * infinite loop. */
+  if (GST_PAD_IS_IN_SETCAPS (otherpad))
+    goto done;
+
+  GST_DEBUG_OBJECT (pad, "have new caps %" GST_PTR_FORMAT, caps);
+
+  /* find best possible caps for the other pad */
+  othercaps = gst_base_transform_find_transform (trans, pad, caps);
+  if (!othercaps || gst_caps_is_empty (othercaps))
+    goto no_transform_possible;
+
+  /* configure the element now */
+  /* make sure in and out caps are correct */
+  if (pad == trans->sinkpad) {
+    incaps = caps;
+    outcaps = othercaps;
   } else {
-    /* set pending configure, the configure will happen later with the
-     * caps we set on the pads above. */
-    trans->pending_configure = TRUE;
+    incaps = othercaps;
+    outcaps = caps;
   }
 
+#if 0
+  /* if we have the same caps, we can optimize and reuse the input caps */
+  if (gst_caps_is_equal (incaps, outcaps)) {
+    GST_INFO_OBJECT (trans, "reuse caps");
+    gst_caps_unref (outcaps);
+    outcaps = gst_caps_ref (incaps);
+  }
+#endif
+
+  /* call configure now */
+  if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
+    goto failed_configure;
+
   /* we know this will work, we implement the setcaps */
   gst_pad_set_caps (otherpad, othercaps);
 
   if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
+    /* FIXME hm? */
     ret &= gst_pad_set_caps (otherpeer, othercaps);
     if (!ret) {
       GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
@@ -846,43 +1146,17 @@
   return ret;
 
   /* ERRORS */
-unfixed_caps:
-  {
-    GST_DEBUG_OBJECT (trans, "caps are not fixed  %" GST_PTR_FORMAT, caps);
-    ret = FALSE;
-    goto done;
-  }
-no_transform:
-  {
-    GST_DEBUG_OBJECT (trans,
-        "transform returned useless  %" GST_PTR_FORMAT, othercaps);
-    ret = FALSE;
-    goto done;
-  }
 no_transform_possible:
   {
-    GST_DEBUG_OBJECT (trans,
+    GST_WARNING_OBJECT (trans,
         "transform could not transform %" GST_PTR_FORMAT
         " in anything we support", caps);
     ret = FALSE;
     goto done;
   }
-could_not_fixate:
-  {
-    GST_ERROR_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
-    ret = FALSE;
-    goto done;
-  }
-peer_no_accept:
-  {
-    GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
-        " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
-    ret = FALSE;
-    goto done;
-  }
 failed_configure:
   {
-    GST_DEBUG_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
+    GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
         " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
     ret = FALSE;
     goto done;
@@ -891,7 +1165,7 @@
 
 /* Allocate a buffer using gst_pad_alloc_buffer
  *
- * This function does not do renegotiation on the source pad
+ * This function can do renegotiation on the source pad
  *
  * The output buffer is always writable. outbuf can be equal to
  * inbuf, the caller should be prepared for this and perform 
@@ -899,108 +1173,243 @@
  */
 static GstFlowReturn
 gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
-    GstBuffer * in_buf, gint out_size, GstCaps * out_caps, GstBuffer ** out_buf)
+    GstBuffer * in_buf, GstBuffer ** out_buf)
 {
   GstBaseTransformClass *bclass;
+  GstBaseTransformPrivate *priv;
   GstFlowReturn ret = GST_FLOW_OK;
-  gboolean copy_inbuf = FALSE;
+  guint outsize, newsize, expsize;
+  gboolean discard;
+  GstCaps *incaps, *oldcaps, *newcaps;
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
-  /* we cannot reconfigure the element yet as we are still processing
-   * the old buffer. We will therefore delay the reconfiguration of the
-   * element until we have processed this last buffer. */
-  trans->delay_configure = TRUE;
+  priv = trans->priv;
+
+  *out_buf = NULL;
+
+  /* figure out how to allocate a buffer based on the current configuration */
+  if (trans->passthrough) {
+    GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
+    /* passthrough, we don't really need to call pad alloc but we still need to
+     * in order to get upstream negotiation. The output size is the same as the
+     * input size. */
+    outsize = GST_BUFFER_SIZE (in_buf);
+    /* we always alloc and discard here */
+    discard = TRUE;
+  } else {
+    gboolean want_in_place = (bclass->transform_ip != NULL)
+        && trans->always_in_place;
 
-  /* out_caps is the caps of the src pad gathered through the GST_PAD_CAPS 
-     macro. If a set_caps occurs during this function this caps will become
-     invalid. We want to keep them during preparation of the output buffer. */
-  if (out_caps)
-    gst_caps_ref (out_caps);
+    if (want_in_place) {
+      GST_DEBUG_OBJECT (trans, "doing inplace alloc");
+      /* we alloc a buffer of the same size as the input */
+      outsize = GST_BUFFER_SIZE (in_buf);
+      /* only discard it when the input was not writable, otherwise, we reuse
+       * the input buffer. */
+      discard = gst_buffer_is_writable (in_buf);
+      GST_DEBUG_OBJECT (trans, "discard: %d", discard);
+    } else {
+      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)) {
+        goto unknown_size;
+      }
+      /* never discard this buffer, we need it for storing the output */
+      discard = FALSE;
+    }
+  }
 
-  /* see if the subclass wants to alloc a buffer */
+  oldcaps = GST_PAD_CAPS (trans->srcpad);
+
   if (bclass->prepare_output_buffer) {
+    GST_DEBUG_OBJECT (trans,
+        "calling prepare buffer with caps %" GST_PTR_FORMAT, oldcaps);
     ret =
-        bclass->prepare_output_buffer (trans, in_buf, out_size, out_caps,
+        bclass->prepare_output_buffer (trans, in_buf, outsize, oldcaps,
         out_buf);
-    if (ret != GST_FLOW_OK)
-      goto done;
 
-    /* decrease refcount again if vmethod returned refcounted in_buf. This
+    /* get a new ref to the srcpad caps, the prepare_output_buffer function can
+     * update the pad caps if it wants */
+    oldcaps = GST_PAD_CAPS (trans->srcpad);
+
+    /* FIXME 0.11:
+     * decrease refcount again if vmethod returned refcounted in_buf. This
      * is because we need to make sure that the buffer is writable for the
      * in_place transform. The docs of the vmethod say that you should return
      * a reffed inbuf, which is exactly what we don't want :), oh well.. */
     if (in_buf == *out_buf)
       gst_buffer_unref (in_buf);
+
+    /* never discard the buffer from the prepare_buffer method */
+    if (*out_buf != NULL)
+      discard = FALSE;
+  }
+
+  if (ret != GST_FLOW_OK)
+    goto alloc_failed;
+
+  if (*out_buf == NULL) {
+    GST_DEBUG_OBJECT (trans, "doing alloc with caps %" GST_PTR_FORMAT, oldcaps);
+
+    ret = gst_pad_alloc_buffer (trans->srcpad,
+        GST_BUFFER_OFFSET (in_buf), outsize, oldcaps, out_buf);
+    if (ret != GST_FLOW_OK)
+      goto alloc_failed;
   }
 
-  /* See if we want to prepare the buffer for in place output */
-  if (*out_buf == NULL && GST_BUFFER_SIZE (in_buf) == out_size
-      && bclass->transform_ip) {
-    if (gst_buffer_is_writable (in_buf)) {
-      if (trans->have_same_caps) {
-        /* Input buffer is already writable and caps are the same, return input as
-         * output buffer. We don't take an additional ref since that would make the
-         * output buffer not writable anymore. Caller should be prepared to deal
-         * with proper refcounting of input/output buffers. */
-        *out_buf = in_buf;
-        GST_LOG_OBJECT (trans, "reuse input buffer");
+  /* must always have a buffer by now */
+  if (*out_buf == NULL)
+    goto no_buffer;
+
+  /* check if we got different caps on this new output buffer */
+  newcaps = GST_BUFFER_CAPS (*out_buf);
+  newsize = GST_BUFFER_SIZE (*out_buf);
+  if (!gst_caps_is_equal (newcaps, oldcaps)) {
+    GstCaps *othercaps;
+    gboolean can_convert;
+
+    GST_DEBUG_OBJECT (trans, "received new caps %" GST_PTR_FORMAT, newcaps);
+
+    incaps = GST_PAD_CAPS (trans->sinkpad);
+
+    /* 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
+     * buffer later on. */
+    gst_base_transform_transform_size (trans,
+        GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize);
+
+    /* check if we can convert the current incaps to the new target caps */
+    can_convert =
+        gst_base_transform_can_transform (trans, trans->sinkpad, incaps,
+        newcaps);
+
+    if (can_convert) {
+      GST_DEBUG_OBJECT (trans, "reconfigure transform for current buffer");
+      /* caps not empty, try to renegotiate to the new format */
+      if (!gst_base_transform_configure_caps (trans, incaps, newcaps)) {
+        /* not sure we need to fail hard here, we can simply continue our
+         * conversion with what we negotiated before */
+        goto failed_configure;
+      }
+      /* new format configure, and use the new output buffer */
+      gst_pad_set_caps (trans->srcpad, newcaps);
+      discard = FALSE;
+      /* if we got a buffer of the wrong size, discard it now and make sure we
+       * allocate a propertly sized buffer later. */
+      if (newsize != expsize) {
+        if (in_buf != *out_buf)
+          gst_buffer_unref (*out_buf);
+        *out_buf = NULL;
+      }
+      outsize = expsize;
+    } else {
+      GST_DEBUG_OBJECT (trans, "cannot perform transform on current buffer");
+
+      /* we cannot convert the current buffer but we might be able to suggest a
+       * new format upstream, try to find what the best format is. */
+      othercaps =
+          gst_base_transform_find_transform (trans, trans->srcpad, newcaps);
+
+      if (!othercaps) {
+        GST_DEBUG_OBJECT (trans, "incompatible caps, ignoring");
+        /* we received caps that we cannot transform. Upstream is behaving badly
+         * because it should have checked if we could handle these caps. We can
+         * simply ignore these caps and produce a buffer with our original caps. */
       } else {
-        /* Writable buffer, but need to change caps => subbuffer */
-        *out_buf = gst_buffer_create_sub (in_buf, 0, GST_BUFFER_SIZE (in_buf));
-        gst_caps_replace (&GST_BUFFER_CAPS (*out_buf), out_caps);
-        GST_LOG_OBJECT (trans, "created sub-buffer of input buffer");
+        guint size_suggest;
+
+        GST_DEBUG_OBJECT (trans, "getting size of suggestion");
+
+        /* not a subset, we have a new upstream suggestion, remember it and
+         * allocate a default buffer. First we try to convert the size */
+        if (gst_base_transform_transform_size (trans,
+                GST_PAD_SRC, newcaps, expsize, othercaps, &size_suggest)) {
+
+          /* ok, remember the suggestions now */
+          GST_DEBUG_OBJECT (trans,
+              "storing new caps and size suggestion of %u and %" GST_PTR_FORMAT,
+              size_suggest, othercaps);
+
+          GST_OBJECT_LOCK (trans->sinkpad);
+          if (priv->sink_suggest)
+            gst_caps_unref (priv->sink_suggest);
+          priv->sink_suggest = gst_caps_ref (othercaps);
+          priv->size_suggest = size_suggest;
+          trans->priv->suggest_pending = TRUE;
+          GST_OBJECT_UNLOCK (trans->sinkpad);
+        }
+        gst_caps_unref (othercaps);
       }
-      /* we are done now */
-      goto done;
-    } else {
-      /* Make a writable buffer below and copy the data */
-      copy_inbuf = TRUE;
-      GST_LOG_OBJECT (trans, "need to copy input buffer to new output buffer");
+      if (in_buf != *out_buf)
+        gst_buffer_unref (*out_buf);
+      *out_buf = NULL;
     }
   }
 
   if (*out_buf == NULL) {
-    /* Sub-class didn't already provide a buffer for us. Make one */
-    ret = gst_pad_alloc_buffer (trans->srcpad,
-        GST_BUFFER_OFFSET (in_buf), out_size, out_caps, out_buf);
-    if (ret != GST_FLOW_OK || *out_buf == NULL)
-      goto done;
-
-    /* allocated buffer could be of different caps than what we requested */
-    if (G_UNLIKELY (!gst_caps_is_equal (out_caps, GST_BUFFER_CAPS (*out_buf)))) {
-      /* FIXME, it is possible we can reconfigure the transform with new caps at this
-       * point but for now we just create a buffer ourselves */
+    if (!discard) {
+      GST_DEBUG_OBJECT (trans, "make default output buffer of size %d",
+          outsize);
+      /* no valid buffer yet, make one */
+      *out_buf = gst_buffer_new_and_alloc (outsize);
+      gst_buffer_copy_metadata (*out_buf, in_buf,
+          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+    } else {
+      GST_DEBUG_OBJECT (trans, "reuse input buffer");
+      *out_buf = in_buf;
+    }
+  } else {
+    if (trans->passthrough && in_buf != *out_buf) {
+      /* we are asked to perform a passthrough transform but the input and
+       * output buffers are different. We have to discard the output buffer and
+       * reuse the input buffer. */
+      GST_DEBUG_OBJECT (trans, "passthrough but different buffers");
+      discard = TRUE;
+    }
+    if (discard) {
+      GST_DEBUG_OBJECT (trans, "discard buffer, reuse input buffer");
       gst_buffer_unref (*out_buf);
-      *out_buf = gst_buffer_new_and_alloc (out_size);
-      gst_buffer_set_caps (*out_buf, out_caps);
+      *out_buf = in_buf;
+    } else {
+      GST_DEBUG_OBJECT (trans, "using allocated buffer");
+      gst_buffer_copy_metadata (*out_buf, in_buf,
+          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
     }
   }
-
-  /* If the output buffer metadata is modifiable, copy timestamps and
-   * buffer flags */
-  if (*out_buf != in_buf && gst_buffer_is_metadata_writable (*out_buf)) {
-
-    if (copy_inbuf && gst_buffer_is_writable (*out_buf))
-      memcpy (GST_BUFFER_DATA (*out_buf), GST_BUFFER_DATA (in_buf), out_size);
-
-    gst_buffer_copy_metadata (*out_buf, in_buf,
-        GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+  gst_buffer_set_caps (*out_buf, GST_PAD_CAPS (trans->srcpad));
 
-    /* Unset the GAP flag if the element is _not_ GAP aware. Otherwise
-     * it might create an output buffer that does not contain neutral data
-     * but still has the GAP flag on it! */
-    if (!trans->priv->gap_aware)
-      GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
-  }
-
-done:
-  if (out_caps)
-    gst_caps_unref (out_caps);
-
-  trans->delay_configure = FALSE;
+  /* clear the GAP flag when the subclass does not understand it */
+  if (!trans->priv->gap_aware)
+    GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
 
   return ret;
+
+  /* ERRORS */
+alloc_failed:
+  {
+    GST_WARNING_OBJECT (trans, "pad-alloc failed: %s", gst_flow_get_name (ret));
+    return ret;
+  }
+no_buffer:
+  {
+    GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
+        ("Sub-class failed to provide an output buffer"), (NULL));
+    return GST_FLOW_ERROR;
+  }
+unknown_size:
+  {
+    GST_ERROR_OBJECT (trans, "unknown output size");
+    return GST_FLOW_ERROR;
+  }
+failed_configure:
+  {
+    GST_WARNING_OBJECT (trans, "failed to configure caps");
+    return GST_FLOW_NOT_NEGOTIATED;
+  }
 }
 
 /* Given @caps calcultate the size of one unit.
@@ -1038,9 +1447,15 @@
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
   if (bclass->get_unit_size) {
     res = bclass->get_unit_size (trans, caps, size);
-//    GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
-//        ") has unit size %d, result %s", caps, *size, res ? "TRUE" : "FALSE");
-
+    if(res)
+        {
+        GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
+                ") has unit size %d, result TRUE", caps, *size);
+        }else{ 
+  
+        GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
+                ") has unit size %d, result FALSE", caps, *size);
+        }
     if (res) {
       /* and cache the values */
       if (trans->cache_caps1 == NULL) {
@@ -1070,167 +1485,185 @@
     GstCaps * caps, GstBuffer ** buf)
 {
   GstBaseTransform *trans;
+  GstBaseTransformPrivate *priv;
   GstFlowReturn res;
-  guint new_size;
-  gboolean issinkcaps = TRUE;
+  gboolean proxy, suggest, same_caps;
+  GstCaps *sink_suggest;
+  guint size_suggest;
 
   trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+  priv = trans->priv;
 
-  /* we cannot run this when we are transforming data and as such doing 
-   * another negotiation in the transform method. */
-  g_mutex_lock (trans->transform_lock);
+  GST_DEBUG_OBJECT (pad, "alloc with caps %" GST_PTR_FORMAT ", size %u", caps,
+      size);
+
+  /* if the code below does not come up with a better buffer, we will return _OK
+   * and an empty buffer. This will trigger the core to allocate a buffer with
+   * given input size and caps. */
+  *buf = NULL;
+  res = GST_FLOW_OK;
+
+  /* we remember our previous alloc request to quickly see if we can proxy or
+   * not. We skip this check if we have a pending suggestion. */
+  GST_OBJECT_LOCK (pad);
+  same_caps = !priv->suggest_pending && caps &&
+      gst_caps_is_equal (priv->sink_alloc, caps);
+  GST_OBJECT_UNLOCK (pad);
+
+  if (same_caps) {
+    /* we have seen this before, see below if we need to proxy */
+    GST_DEBUG_OBJECT (trans, "have old caps");
+    sink_suggest = caps;
+    size_suggest = size;
+    suggest = FALSE;
+  } else {
+    GstCaps *temp;
+    const GstCaps *templ;
+    gboolean empty;
+
+    GST_DEBUG_OBJECT (trans, "new format %" GST_PTR_FORMAT, caps);
 
-  *buf = NULL;
+    /* if we have a suggestion, pretend we got these as input */
+    GST_OBJECT_LOCK (pad);
+    if ((priv->sink_suggest && !gst_caps_is_equal (caps, priv->sink_suggest))) {
+      sink_suggest = gst_caps_ref (priv->sink_suggest);
+      size_suggest = priv->size_suggest;
+      GST_DEBUG_OBJECT (trans, "have suggestion %" GST_PTR_FORMAT,
+          sink_suggest);
+      /* suggest is TRUE when we have a custom suggestion pending that we need
+       * to unref later. */
+      suggest = TRUE;
+    } else {
+      GST_DEBUG_OBJECT (trans, "using caps %" GST_PTR_FORMAT, caps);
+      sink_suggest = caps;
+      size_suggest = size;
+      suggest = FALSE;
+    }
+    priv->suggest_pending = FALSE;
+    GST_OBJECT_UNLOCK (pad);
+
+    /* check if we actually handle this format on the sinkpad */
+    if (sink_suggest) {
+      templ = gst_pad_get_pad_template_caps (pad);
+      temp = gst_caps_intersect (sink_suggest, templ);
+
+      empty = gst_caps_is_empty (temp);
+      gst_caps_unref (temp);
+
+      if (empty)
+        goto not_supported;
+    }
 
-  GST_DEBUG_OBJECT (trans, "allocating a buffer of size %d ...", size);
-  if (offset == GST_BUFFER_OFFSET_NONE)
-    GST_DEBUG_OBJECT (trans, "... and offset NONE");
-  else
-    GST_DEBUG_OBJECT (trans, "... and offset %" G_GUINT64_FORMAT, offset);
+    /* find the best format for the other side here we decide if we will proxy
+     * the caps or not. */
+    if (sink_suggest == NULL) {
+      /* always proxy when the caps are NULL. When this is a new format, see if
+       * we can proxy it downstream */
+      GST_DEBUG_OBJECT (trans, "null caps, marking for proxy");
+      priv->proxy_alloc = TRUE;
+    } else {
+      GstCaps *othercaps;
+
+      /* we have a new format, see what we need to proxy to */
+      othercaps = gst_base_transform_find_transform (trans, pad, sink_suggest);
+      if (!othercaps || gst_caps_is_empty (othercaps)) {
+        /* no transform possible, we certainly can't proxy */
+        GST_DEBUG_OBJECT (trans, "can't find transform, disable proxy");
+        priv->proxy_alloc = FALSE;
+      } else {
+        /* we transformed into something */
+        if (gst_caps_is_equal (caps, othercaps)) {
+          GST_DEBUG_OBJECT (trans,
+              "best caps same as input, marking for proxy");
+          priv->proxy_alloc = TRUE;
+        } else {
+          GST_DEBUG_OBJECT (trans,
+              "best caps different from input, disable proxy");
+          priv->proxy_alloc = FALSE;
+        }
+      }
+      if (othercaps)
+        gst_caps_unref (othercaps);
+    }
+  }
+  /* remember the new caps */
+  GST_OBJECT_LOCK (pad);
+  gst_caps_replace (&priv->sink_alloc, sink_suggest);
+  GST_OBJECT_UNLOCK (pad);
 
-  /* if have_same_caps was previously set to TRUE we need to double check if it
-   * hasn't changed */
-  if (trans->have_same_caps) {
-    GstCaps *sinkcaps;
+  proxy = priv->proxy_alloc;
+  GST_DEBUG_OBJECT (trans, "doing default alloc, proxy %d", proxy);
+
+  /* we only want to proxy if we have no suggestion pending, FIXME */
+  if (proxy && !suggest) {
+    GstCaps *newcaps;
+
+    GST_DEBUG_OBJECT (trans, "proxy buffer-alloc with caps %" GST_PTR_FORMAT
+        ", size %u", caps, size);
+
+    /* we always proxy the input caps, never the suggestion. The reason is that
+     * We don't yet handle the caps of renegotiation in here. FIXME */
+    res = gst_pad_alloc_buffer (trans->srcpad, offset, size, caps, buf);
+    if (res != GST_FLOW_OK)
+      goto alloc_failed;
+
+    /* check if the caps changed */
+    newcaps = GST_BUFFER_CAPS (*buf);
+
+    GST_DEBUG_OBJECT (trans, "got caps %" GST_PTR_FORMAT, newcaps);
 
-    GST_OBJECT_LOCK (trans->sinkpad);
-    sinkcaps = GST_PAD_CAPS (trans->sinkpad);
-    issinkcaps = sinkcaps && (gst_caps_is_equal (sinkcaps, caps));
-    GST_OBJECT_UNLOCK (trans->sinkpad);
+    if (!gst_caps_is_equal (newcaps, caps)) {
+      GST_DEBUG_OBJECT (trans, "caps are new");
+      /* we have new caps, see if we can proxy downstream */
+      if (gst_pad_peer_accept_caps (pad, newcaps)) {
+        /* peer accepts the caps, return a buffer in this format */
+        GST_DEBUG_OBJECT (trans, "peer accepted new caps");
+        /* remember the format */
+        GST_OBJECT_LOCK (pad);
+        gst_caps_replace (&priv->sink_alloc, newcaps);
+        GST_OBJECT_UNLOCK (pad);
+      } else {
+        GST_DEBUG_OBJECT (trans, "peer did not accept new caps");
+        /* peer does not accept the caps, free the buffer we received and
+         * create a buffer of the requested format by the default handler. */
+        gst_buffer_unref (*buf);
+        *buf = NULL;
+      }
+    } else {
+      GST_DEBUG_OBJECT (trans, "received required caps from peer");
+    }
   }
 
-  /* before any buffers are pushed, have_same_caps is TRUE; allocating can trigger
-   * a renegotiation and change that to FALSE */
-
-  /* bilboed: This seems wrong, from all debug logs, have_same_caps is
-   * initialized to FALSE */
-
-  /* checking against trans->have_same_caps is not enough !! It should also
-   *  check to see if the requested caps are equal to the sink caps */
-  if (trans->have_same_caps && issinkcaps) {
-    /* request a buffer with the same caps */
-    GST_DEBUG_OBJECT (trans, "requesting buffer with same caps, size %d", size);
-
-    res =
-        gst_pad_alloc_buffer_and_set_caps (trans->srcpad, offset, size, caps,
-        buf);
-  } else {
-    /* if we are configured, request a buffer with the src caps */
-    GstCaps *srccaps;
-    GstCaps *sinkcaps;
-    gboolean configured;
-
-    /* take lock, peek if the caps are ok */
-    GST_OBJECT_LOCK (trans->sinkpad);
-    sinkcaps = GST_PAD_CAPS (trans->sinkpad);
-    configured = (sinkcaps == NULL || gst_caps_is_equal (sinkcaps, caps));
-    GST_OBJECT_UNLOCK (trans->sinkpad);
-    if (!configured)
-      goto not_configured;
-
-    /* take lock on srcpad to grab the caps, caps can change when pushing a
-     * buffer. */
-    GST_OBJECT_LOCK (trans->srcpad);
-    if ((srccaps = GST_PAD_CAPS (trans->srcpad)))
-      gst_caps_ref (srccaps);
-    GST_OBJECT_UNLOCK (trans->srcpad);
-    if (!srccaps)
-      goto not_configured;
-
-    GST_DEBUG_OBJECT (trans, "calling transform_size");
-    if (!gst_base_transform_transform_size (trans,
-            GST_PAD_DIRECTION (pad), caps, size, srccaps, &new_size)) {
-      gst_caps_unref (srccaps);
-      goto unknown_size;
-    }
-
-    res =
-        gst_pad_alloc_buffer_and_set_caps (trans->srcpad, offset, new_size,
-        srccaps, buf);
-
-    gst_caps_unref (srccaps);
+  if (suggest) {
+    /* there was a custom suggestion, create a buffer of this format and return
+     * it. Note that this format  */
+    *buf = gst_buffer_new_and_alloc (size_suggest);
+    GST_DEBUG_OBJECT (trans,
+        "doing suggestion of size %u, caps %" GST_PTR_FORMAT, size_suggest,
+        sink_suggest);
+    GST_BUFFER_CAPS (*buf) = sink_suggest;
   }
 
-  if (res == GST_FLOW_OK && !trans->have_same_caps) {
-    /* note that we might have had same caps before, but calling the
-       alloc_buffer caused setcaps to switch us out of in_place -- in any case
-       the alloc_buffer served to transmit caps information but we can't use the
-       buffer. fall through and allocate a buffer corresponding to our sink
-       caps, if any */
-    GstCaps *sinkcaps;
-    GstCaps *srccaps;
-
-    GST_OBJECT_LOCK (trans->sinkpad);
-    if ((sinkcaps = GST_PAD_CAPS (trans->sinkpad)))
-      gst_caps_ref (sinkcaps);
-    GST_OBJECT_UNLOCK (trans->sinkpad);
-    if (!sinkcaps)
-      goto not_configured;
-
-    GST_OBJECT_LOCK (trans->srcpad);
-    if ((srccaps = GST_PAD_CAPS (trans->srcpad)))
-      gst_caps_ref (srccaps);
-    GST_OBJECT_UNLOCK (trans->srcpad);
-    if (!srccaps) {
-      gst_caps_unref (sinkcaps);
-      goto not_configured;
-    }
-
-    if (!gst_base_transform_transform_size (trans,
-            GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf),
-            sinkcaps, &new_size)) {
-      gst_caps_unref (srccaps);
-      gst_caps_unref (sinkcaps);
-      goto unknown_size;
-    }
-    /* don't need the caps anymore now */
-    gst_caps_unref (srccaps);
-
-    gst_buffer_unref (*buf);
-
-    *buf = gst_buffer_new_and_alloc (new_size);
-    GST_BUFFER_OFFSET (*buf) = offset;
-    /* set caps, gives away the ref */
-    GST_BUFFER_CAPS (*buf) = sinkcaps;
-
-    res = GST_FLOW_OK;
-  }
-
-done:
-  g_mutex_unlock (trans->transform_lock);
   gst_object_unref (trans);
 
   return res;
 
-not_configured:
+  /* ERRORS */
+alloc_failed:
   {
-    /* let the default allocator handle it... */
-    GST_DEBUG_OBJECT (trans, "not configured");
-    gst_buffer_replace (buf, NULL);
-    if (trans->passthrough) {
-      /* ...by calling alloc_buffer without setting caps on the src pad, which
-       * will force negotiation in the chain function. */
-      res = gst_pad_alloc_buffer (trans->srcpad, offset, size, caps, buf);
-    } else {
-      /* ...by letting the default handler create a buffer */
-      res = GST_FLOW_OK;
-    }
-    goto done;
+    GST_DEBUG_OBJECT (trans, "pad alloc failed: %s", gst_flow_get_name (res));
+    if (suggest)
+      gst_caps_unref (sink_suggest);
+    gst_object_unref (trans);
+    return res;
   }
-unknown_size:
+not_supported:
   {
-    /* let the default allocator handle it... */
-    GST_DEBUG_OBJECT (trans, "unknown size");
-    gst_buffer_replace (buf, NULL);
-    if (trans->passthrough) {
-      /* ...by calling alloc_buffer without setting caps on the src pad, which
-       * will force negotiation in the chain function. */
-      res = gst_pad_alloc_buffer (trans->srcpad, offset, size, caps, buf);
-    } else {
-      /* ...by letting the default handler create a buffer */
-      res = GST_FLOW_OK;
-    }
-    goto done;
+    GST_DEBUG_OBJECT (trans, "pad alloc with unsupported caps");
+    if (suggest)
+      gst_caps_unref (sink_suggest);
+    gst_object_unref (trans);
+    return GST_FLOW_NOT_NEGOTIATED;
   }
 }
 
@@ -1252,6 +1685,8 @@
    * something different. */
   if (forward)
     ret = gst_pad_push_event (trans->srcpad, event);
+  else
+    gst_event_unref (event);
 
   gst_object_unref (trans);
 
@@ -1365,24 +1800,45 @@
   return ret;
 }
 
+/* perform a transform on @inbuf and put the result in @outbuf.
+ *
+ * This function is common to the push and pull-based operations.
+ *
+ * This function takes ownership of @inbuf */
 static GstFlowReturn
 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
     GstBuffer ** outbuf)
 {
   GstBaseTransformClass *bclass;
   GstFlowReturn ret = GST_FLOW_OK;
-  guint out_size;
-  gboolean want_in_place;
+  gboolean want_in_place, reconfigure;
   GstClockTime qostime;
+  GstCaps *incaps;
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
+  if (G_LIKELY ((incaps = GST_BUFFER_CAPS (inbuf)))) {
+    GST_OBJECT_LOCK (trans);
+    reconfigure = trans->priv->reconfigure;
+    trans->priv->reconfigure = FALSE;
+    GST_OBJECT_UNLOCK (trans);
+
+    if (G_UNLIKELY (reconfigure)) {
+      GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
+      /* if we need to reconfigure we pretend a buffer with new caps arrived. This
+       * will reconfigure the transform with the new output format. We can only
+       * do this if the buffer actually has caps. */
+      if (!gst_base_transform_setcaps (trans->sinkpad, incaps))
+        goto not_negotiated;
+    }
+  }
+
   if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
-    GST_LOG_OBJECT (trans, "handling buffer %p of size %d and offset %"
+    GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset %"
         G_GUINT64_FORMAT, inbuf, GST_BUFFER_SIZE (inbuf),
         GST_BUFFER_OFFSET (inbuf));
   else
-    GST_LOG_OBJECT (trans, "handling buffer %p of size %d and offset NONE",
+    GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset NONE",
         inbuf, GST_BUFFER_SIZE (inbuf));
 
   /* Don't allow buffer handling before negotiation, except in passthrough mode
@@ -1394,7 +1850,7 @@
 
   /* Set discont flag so we can mark the outgoing buffer */
   if (GST_BUFFER_IS_DISCONT (inbuf)) {
-    GST_LOG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
+    GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
     trans->priv->discont = TRUE;
   }
 
@@ -1402,6 +1858,7 @@
   if (trans->segment.format != GST_FORMAT_TIME)
     goto no_qos;
 
+  /* QOS is done on the running time of the buffer, get it now */
   qostime = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
       GST_BUFFER_TIMESTAMP (inbuf));
 
@@ -1409,6 +1866,8 @@
     gboolean need_skip;
     GstClockTime earliest_time;
 
+    /* lock for getting the QoS parameters that are set (in a different thread)
+     * with the QOS events */
     GST_OBJECT_LOCK (trans);
     earliest_time = trans->priv->earliest_time;
     /* check for QoS, don't perform conversion for buffers
@@ -1428,76 +1887,48 @@
   }
 
 no_qos:
+
+  /* first try to allocate an output buffer based on the currently negotiated
+   * format. While we call pad-alloc we could renegotiate the srcpad format or
+   * have a new suggestion for upstream buffer-alloc. 
+   * In any case, outbuf will contain a buffer suitable for doing the configured
+   * transform after this function. */
+  ret = gst_base_transform_prepare_output_buffer (trans, inbuf, outbuf);
+  if (G_UNLIKELY (ret != GST_FLOW_OK))
+    goto no_buffer;
+
+  /* now perform the needed transform */
   if (trans->passthrough) {
     /* In passthrough mode, give transform_ip a look at the
      * buffer, without making it writable, or just push the
      * data through */
-    GST_LOG_OBJECT (trans, "element is in passthrough mode");
-
-    if (bclass->transform_ip)
-      ret = bclass->transform_ip (trans, inbuf);
-
-    *outbuf = inbuf;
-
-    goto done;
-  }
-
-  want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
-  *outbuf = NULL;
-
-  if (want_in_place) {
-    /* If want_in_place is TRUE, we may need to prepare a new output buffer
-     * Sub-classes can implement a prepare_output_buffer function as they
-     * wish. */
-    GST_LOG_OBJECT (trans, "doing inplace transform");
-
-    ret = gst_base_transform_prepare_output_buffer (trans, inbuf,
-        GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad), outbuf);
-    if (G_UNLIKELY (ret != GST_FLOW_OK))
-      goto no_buffer;
-
-    ret = bclass->transform_ip (trans, *outbuf);
-
-  } else {
-    GST_LOG_OBJECT (trans, "doing non-inplace transform");
-
-    /* not transforming inplace, figure out the output size */
-    if (trans->always_in_place) {
-      out_size = GST_BUFFER_SIZE (inbuf);
+    if (bclass->transform_ip) {
+      GST_DEBUG_OBJECT (trans, "doing passthrough transform");
+      ret = bclass->transform_ip (trans, *outbuf);
     } else {
-      if (!gst_base_transform_transform_size (trans,
-              GST_PAD_DIRECTION (trans->sinkpad), GST_PAD_CAPS (trans->sinkpad),
-              GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad),
-              &out_size)) {
-        /* we have an error */
-        goto no_size;
-      }
+      GST_DEBUG_OBJECT (trans, "element is in passthrough");
     }
+  } else {
+    want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
 
-    /* no in place transform, get buffer, this might renegotiate. */
-    ret = gst_base_transform_prepare_output_buffer (trans, inbuf, out_size,
-        GST_PAD_CAPS (trans->srcpad), outbuf);
-    if (ret != GST_FLOW_OK)
-      goto no_buffer;
+    if (want_in_place) {
+      GST_DEBUG_OBJECT (trans, "doing inplace transform");
 
-    if (bclass->transform)
-      ret = bclass->transform (trans, inbuf, *outbuf);
-    else
-      ret = GST_FLOW_NOT_SUPPORTED;
-  }
+      if (inbuf != *outbuf) {
+        /* different buffers, copy the input to the output first, we then do an
+         * in-place transform on the output buffer. */
+        memcpy (GST_BUFFER_DATA (*outbuf), GST_BUFFER_DATA (inbuf),
+            GST_BUFFER_SIZE (inbuf));
+      }
+      ret = bclass->transform_ip (trans, *outbuf);
+    } else {
+      GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
 
-  /* if we got renegotiated we can configure now */
-  if (trans->pending_configure) {
-    gboolean success;
-
-    success =
-        gst_base_transform_configure_caps (trans,
-        GST_PAD_CAPS (trans->sinkpad), GST_PAD_CAPS (trans->srcpad));
-
-    trans->pending_configure = FALSE;
-
-    if (!success)
-      goto configure_failed;
+      if (bclass->transform)
+        ret = bclass->transform (trans, inbuf, *outbuf);
+      else
+        ret = GST_FLOW_NOT_SUPPORTED;
+    }
   }
 
 skip:
@@ -1505,7 +1936,6 @@
   if (*outbuf != inbuf)
     gst_buffer_unref (inbuf);
 
-done:
   return ret;
 
   /* ERRORS */
@@ -1516,28 +1946,13 @@
         ("not negotiated"), ("not negotiated"));
     return GST_FLOW_NOT_NEGOTIATED;
   }
-no_size:
-  {
-    gst_buffer_unref (inbuf);
-    GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
-        ("subclass did not specify output size"),
-        ("subclass did not specify output size"));
-    return GST_FLOW_ERROR;
-  }
 no_buffer:
   {
     gst_buffer_unref (inbuf);
-    GST_DEBUG_OBJECT (trans, "could not get buffer from pool: %s",
+    GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
         gst_flow_get_name (ret));
     return ret;
   }
-configure_failed:
-  {
-    if (*outbuf != inbuf)
-      gst_buffer_unref (inbuf);
-    GST_DEBUG_OBJECT (trans, "could not negotiate");
-    return GST_FLOW_NOT_NEGOTIATED;
-  }
 }
 
 static gboolean
@@ -1563,27 +1978,43 @@
     guint length, GstBuffer ** buffer)
 {
   GstBaseTransform *trans;
+  GstBaseTransformClass *klass;
   GstFlowReturn ret;
   GstBuffer *inbuf;
 
   trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
 
   ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
-  if (ret == GST_FLOW_OK) {
-    g_mutex_lock (trans->transform_lock);
-    ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
-    g_mutex_unlock (trans->transform_lock);
-  }
+  if (G_UNLIKELY (ret != GST_FLOW_OK))
+    goto pull_error;
 
+  klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+  if (klass->before_transform)
+    klass->before_transform (trans, inbuf);
+
+  GST_BASE_TRANSFORM_LOCK (trans);
+  ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
+  GST_BASE_TRANSFORM_UNLOCK (trans);
+
+done:
   gst_object_unref (trans);
 
   return ret;
+
+  /* ERRORS */
+pull_error:
+  {
+    GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
+        gst_flow_get_name (ret));
+    goto done;
+  }
 }
 
 static GstFlowReturn
 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
 {
   GstBaseTransform *trans;
+  GstBaseTransformClass *klass;
   GstFlowReturn ret;
   GstClockTime last_stop = GST_CLOCK_TIME_NONE;
   GstBuffer *outbuf = NULL;
@@ -1598,10 +2029,14 @@
       last_stop = GST_BUFFER_TIMESTAMP (buffer);
   }
 
+  klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+  if (klass->before_transform)
+    klass->before_transform (trans, buffer);
+
   /* protect transform method and concurrent buffer alloc */
-  g_mutex_lock (trans->transform_lock);
+  GST_BASE_TRANSFORM_LOCK (trans);
   ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
-  g_mutex_unlock (trans->transform_lock);
+  GST_BASE_TRANSFORM_UNLOCK (trans);
 
   /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
    * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
@@ -1698,6 +2133,7 @@
     trans->priv->proportion = 1.0;
     trans->priv->earliest_time = -1;
     trans->priv->discont = FALSE;
+    gst_caps_replace (&trans->priv->sink_suggest, NULL);
 
     GST_OBJECT_UNLOCK (trans);
   } else {
@@ -1714,6 +2150,8 @@
     }
     gst_caps_replace (&trans->cache_caps1, NULL);
     gst_caps_replace (&trans->cache_caps2, NULL);
+    gst_caps_replace (&trans->priv->sink_alloc, NULL);
+    gst_caps_replace (&trans->priv->sink_suggest, NULL);
 
     if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
       result &= bclass->stop (trans);
@@ -1784,7 +2222,7 @@
 {
   GstBaseTransformClass *bclass;
 
-  g_return_if_fail (trans != NULL);
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
@@ -1819,7 +2257,7 @@
 {
   gboolean result;
 
-  g_return_val_if_fail (trans != NULL, FALSE);
+  g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
 
   GST_OBJECT_LOCK (trans);
   result = trans->passthrough;
@@ -1838,7 +2276,7 @@
  * to the transform_ip function.
  * <itemizedlist>
  *   <listitem>Always TRUE if no transform function is implemented.</listitem>
- *   <listitem>Always FALSE if ONLY transform_ip function is implemented.</listitem>
+ *   <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
  * </itemizedlist>
  *
  * MT safe.
@@ -1852,7 +2290,7 @@
 {
   GstBaseTransformClass *bclass;
 
-  g_return_if_fail (trans != NULL);
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
@@ -1892,7 +2330,7 @@
 {
   gboolean result;
 
-  g_return_val_if_fail (trans != NULL, FALSE);
+  g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
 
   GST_OBJECT_LOCK (trans);
   result = trans->always_in_place;
@@ -1906,13 +2344,16 @@
  * @trans: a #GstBaseTransform
  * @proportion: the proportion
  * @diff: the diff against the clock
- * @timestamp: the timestamp of the buffer generating the QoS
+ * @timestamp: the timestamp of the buffer generating the QoS expressed in
+ * running_time.
  *
- * Set the QoS parameters in the transform.
+ * Set the QoS parameters in the transform. This function is called internally
+ * when a QOS event is received but subclasses can provide custom information
+ * when needed.
+ *
+ * MT safe.
  *
  * Since: 0.10.5
- *
- * MT safe.
  */
 #ifdef __SYMBIAN32__
 EXPORT_C
@@ -1923,7 +2364,7 @@
     gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
 {
 
-  g_return_if_fail (trans != NULL);
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
       "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
@@ -1942,9 +2383,9 @@
  *
  * Enable or disable QoS handling in the transform.
  *
- * Since: 0.10.5
+ * MT safe.
  *
- * MT safe.
+ * Since: 0.10.5
  */
 #ifdef __SYMBIAN32__
 EXPORT_C
@@ -1953,7 +2394,7 @@
 void
 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
 {
-  g_return_if_fail (trans != NULL);
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
 
@@ -1970,9 +2411,9 @@
  *
  * Returns: TRUE if QoS is enabled.
  *
- * Since: 0.10.5
+ * MT safe.
  *
- * MT safe.
+ * Since: 0.10.5
  */
 #ifdef __SYMBIAN32__
 EXPORT_C
@@ -1983,7 +2424,7 @@
 {
   gboolean result;
 
-  g_return_val_if_fail (trans != NULL, FALSE);
+  g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
 
   GST_OBJECT_LOCK (trans);
   result = trans->priv->qos_enabled;
@@ -1997,15 +2438,16 @@
  * @trans: a #GstBaseTransform
  * @gap_aware: New state
  *
- * If @gap_aware is %FALSE (as it is by default) subclasses will never get
- * output buffers with the %GST_BUFFER_FLAG_GAP flag set.
+ * If @gap_aware is %FALSE (the default), output buffers will have the
+ * %GST_BUFFER_FLAG_GAP flag unset.
  *
- * If set to %TRUE elements must handle output buffers with this flag set
- * correctly, i.e. they can assume that the buffer contains neutral data
- * but must unset the flag if the output is no neutral data.
- * Since: 0.10.16
+ * If set to %TRUE, the element must handle output buffers with this flag set
+ * correctly, i.e. it can assume that the buffer contains neutral data but must
+ * unset the flag if the output is no neutral data.
  *
  * MT safe.
+ *
+ * Since: 0.10.16
  */
 #ifdef __SYMBIAN32__
 EXPORT_C
@@ -2014,10 +2456,69 @@
 void
 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
 {
-  g_return_if_fail (trans != NULL);
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
 
   GST_OBJECT_LOCK (trans);
   trans->priv->gap_aware = gap_aware;
   GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
   GST_OBJECT_UNLOCK (trans);
 }
+
+/**
+ * gst_base_transform_suggest:
+ * @trans: a #GstBaseTransform
+ * @caps: caps to suggest
+ * @size: buffer size to suggest
+ *
+ * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
+ * taken.
+ *
+ * Since: 0.10.21
+ */
+#ifdef __SYMBIAN32__
+EXPORT_C
+#endif
+
+void
+gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
+    guint size)
+{
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
+
+  GST_OBJECT_LOCK (trans->sinkpad);
+  if (trans->priv->sink_suggest)
+    gst_caps_unref (trans->priv->sink_suggest);
+  if (caps)
+    caps = gst_caps_copy (caps);
+  trans->priv->sink_suggest = caps;
+  trans->priv->size_suggest = size;
+  trans->priv->suggest_pending = TRUE;
+  GST_DEBUG_OBJECT (trans, "new suggest %" GST_PTR_FORMAT, caps);
+  GST_OBJECT_UNLOCK (trans->sinkpad);
+}
+
+/**
+ * gst_base_transform_reconfigure:
+ * @trans: a #GstBaseTransform
+ *
+ * Instructs @trans to renegotiate a new downstream transform on the next
+ * buffer. This function is typically called after properties on the transform
+ * were set that influence the output format.
+ *
+ * Since: 0.10.21
+ */
+#ifdef __SYMBIAN32__
+EXPORT_C
+#endif
+
+void
+gst_base_transform_reconfigure (GstBaseTransform * trans)
+{
+  g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
+
+  GST_OBJECT_LOCK (trans);
+  GST_DEBUG_OBJECT (trans, "marking reconfigure");
+  trans->priv->reconfigure = TRUE;
+  gst_caps_replace (&trans->priv->sink_alloc, NULL);
+  GST_OBJECT_UNLOCK (trans);
+}