diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c
index 7b7dd79..a3fdf7b 100644
--- a/libs/gst/base/gstbasetransform.c
+++ b/libs/gst/base/gstbasetransform.c
@@ -254,6 +254,8 @@ struct _GstBaseTransformPrivate
   gboolean suggest_pending;
 
   gboolean reconfigure;
+  
+  GstBuffer *last_pad_alloc_buffer;
 };
 
 static GstElementClass *parent_class = NULL;
@@ -1166,6 +1168,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
   GstFlowReturn ret = GST_FLOW_OK;
   guint outsize, newsize, expsize;
   gboolean discard;
+  gboolean same_output = FALSE;
   GstCaps *incaps, *oldcaps, *newcaps;
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
@@ -1183,6 +1186,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
     outsize = GST_BUFFER_SIZE (in_buf);
     /* we always alloc and discard here */
     discard = TRUE;
+    same_output = TRUE;
   } else {
     gboolean want_in_place = (bclass->transform_ip != NULL)
         && trans->always_in_place;
@@ -1195,6 +1199,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
        * the input buffer. */
       discard = gst_buffer_is_writable (in_buf);
       GST_DEBUG_OBJECT (trans, "discard: %d", discard);
+      same_output = TRUE;
     } else {
       GST_DEBUG_OBJECT (trans, "getting output size for copy transform");
       /* copy transform, figure out the output size */
@@ -1238,135 +1243,142 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
   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;
-  }
-
-  /* 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 (same_output && (priv->last_pad_alloc_buffer == in_buf)) {
+    GST_DEBUG_OBJECT (trans, "skipping pad_alloc as we did that already and work in passthrough or inplace");
+    *out_buf = in_buf;
+    discard = FALSE;
+    /*priv->last_pad_alloc_buffer = NULL;*/
+  } else {
+    if (*out_buf == NULL) {
+      GST_DEBUG_OBJECT (trans, "doing pad_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;
+    }
+  
+    /* 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 {
+          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);
+        }
         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 {
-        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);
-      }
-      if (in_buf != *out_buf)
-        gst_buffer_unref (*out_buf);
-      *out_buf = NULL;
     }
-  }
 
-  if (*out_buf == NULL) {
-    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 = in_buf;
+    if (*out_buf == NULL) {
+      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 {
-      GST_DEBUG_OBJECT (trans, "using allocated buffer");
-      gst_buffer_copy_metadata (*out_buf, in_buf,
-          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+      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 = 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);
+      }
     }
+    gst_buffer_set_caps (*out_buf, GST_PAD_CAPS (trans->srcpad));
   }
-  gst_buffer_set_caps (*out_buf, GST_PAD_CAPS (trans->srcpad));
 
   /* clear the GAP flag when the subclass does not understand it */
   if (!trans->priv->gap_aware)
@@ -1482,6 +1494,7 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
    * given input size and caps. */
   *buf = NULL;
   res = GST_FLOW_OK;
+  priv->last_pad_alloc_buffer = NULL;
 
   /* 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. */
@@ -1623,6 +1636,8 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
         sink_suggest);
     GST_BUFFER_CAPS (*buf) = sink_suggest;
   }
+  
+  priv->last_pad_alloc_buffer = *buf;
 
   gst_object_unref (trans);
 
