gst/base/gstbasetransform.c: use gboolean return values and pointers to size so we...
authorThomas Vander Stichele <thomas@apestaart.org>
Wed, 24 Aug 2005 13:33:21 +0000 (13:33 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Wed, 24 Aug 2005 13:33:21 +0000 (13:33 +0000)
Original commit message from CVS:
* gst/base/gstbasetransform.c: (gst_base_transform_transform_caps),
(gst_base_transform_transform_size), (gst_base_transform_getcaps),
(gst_base_transform_setcaps), (gst_base_transform_get_unit_size),
(gst_base_transform_buffer_alloc),
(gst_base_transform_handle_buffer):
use gboolean return values and pointers to size so we can use the
full GST_BUFFER_SIZE range (guint) for buffer sizes
use GstPadDirection for transform_caps
* gst/base/gstbasetransform.h:
rename get_size to get_unit_size since that's what it is
* gst/elements/gstcapsfilter.c: (gst_capsfilter_transform_caps):
use GstPadDirection for transform_caps
* gst/gstbuffer.c: (gst_buffer_new_and_alloc):
* gst/gstutils.h:
cleanup and debugging

ChangeLog
gst/base/gstbasetransform.c
gst/base/gstbasetransform.h
gst/elements/gstcapsfilter.c
libs/gst/base/gstbasetransform.c
libs/gst/base/gstbasetransform.h
plugins/elements/gstcapsfilter.c

index 5cc89b2..187d52f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2005-08-24  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+       * gst/base/gstbasetransform.c: (gst_base_transform_transform_caps),
+       (gst_base_transform_transform_size), (gst_base_transform_getcaps),
+       (gst_base_transform_setcaps), (gst_base_transform_get_unit_size),
+       (gst_base_transform_buffer_alloc),
+       (gst_base_transform_handle_buffer):
+         use gboolean return values and pointers to size so we can use the
+         full GST_BUFFER_SIZE range (guint) for buffer sizes
+         use GstPadDirection for transform_caps
+       * gst/base/gstbasetransform.h:
+         rename get_size to get_unit_size since that's what it is
+       * gst/elements/gstcapsfilter.c: (gst_capsfilter_transform_caps):
+         use GstPadDirection for transform_caps
+       * gst/gstbuffer.c: (gst_buffer_new_and_alloc):
+       * gst/gstutils.h:
+         cleanup and debugging
+
 2005-08-24  Stefan Kost  <ensonic@users.sf.net>
 
        * gst/gstelement.c: (gst_element_class_init),
index f23efb9..16822bb 100644 (file)
@@ -2,8 +2,8 @@
  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  *                    2000 Wim Taymans <wtay@chello.be>
  *                    2005 Wim Taymans <wim@fluendo.com>
- *
- * gstbasetransform.c:
+ *                    2005 Andy Wingo <wingo@fluendo.com>
+ *                    2005 Thomas Vander Stichele <thomas at apestaart dot org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -110,8 +110,8 @@ static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
     gboolean active);
 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
     gboolean active);
-static guint gst_base_transform_get_size (GstBaseTransform * trans,
-    GstCaps * caps);
+static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
+    GstCaps * caps, guint * size);
 
 static GstElementStateReturn gst_base_transform_change_state (GstElement *
     element);
@@ -209,8 +209,8 @@ gst_base_transform_init (GstBaseTransform * trans, gpointer g_class)
 }
 
 static GstCaps *
-gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
-    GstCaps * caps)
+gst_base_transform_transform_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps)
 {
   GstCaps *ret;
   GstBaseTransformClass *klass;
@@ -227,7 +227,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
     if (gst_caps_is_any (caps)) {
       /* for any caps we still have to call the transform function */
       GST_DEBUG_OBJECT (trans, "from ANY:");
-      temp = klass->transform_caps (trans, pad, caps);
+      temp = klass->transform_caps (trans, direction, caps);
       GST_DEBUG_OBJECT (trans, "  to: %" GST_PTR_FORMAT, temp);
 
       gst_caps_append (ret, temp);
@@ -239,7 +239,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
 
         nth = gst_caps_copy_nth (caps, i);
         GST_DEBUG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
-        temp = klass->transform_caps (trans, pad, nth);
+        temp = klass->transform_caps (trans, direction, nth);
         gst_caps_unref (nth);
         GST_DEBUG_OBJECT (trans, "  to[%d]: %" GST_PTR_FORMAT, i, temp);
 
@@ -258,10 +258,10 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
 }
 
 /* by default, this keeps the number of samples in the buffer the same */
-guint
+gboolean
 gst_base_transform_transform_size (GstBaseTransform * trans,
-    GstPadDirection direction, GstCaps * incaps,
-    guint insize, GstCaps * outcaps)
+    GstPadDirection direction, GstCaps * caps,
+    guint size, GstCaps * othercaps, guint * othersize)
 {
   guint inunitsize, outunitsize, units;
   GstBaseTransformClass *klass;
@@ -270,24 +270,29 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
   GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
-      GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %d",
-      insize, incaps, outcaps, direction);
+      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) {
-    ret = klass->transform_size (trans, direction, incaps, insize, outcaps);
+    ret = klass->transform_size (trans, direction, caps, size, othercaps,
+        othersize);
   } else {
-    inunitsize = gst_base_transform_get_size (trans, incaps);
-    g_return_val_if_fail (inunitsize != -1, -1);
-    g_return_val_if_fail (insize % inunitsize == 0, -1);
-
-    units = insize / inunitsize;
-    outunitsize = gst_base_transform_get_size (trans, outcaps);
-    ret = units * outunitsize;
+    g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps,
+            &inunitsize), FALSE);
+    g_return_val_if_fail (size % inunitsize == 0, -1);
+
+    units = size / inunitsize;
+    g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps,
+            &outunitsize), FALSE);
+    if (!othersize) {
+      ret = FALSE;
+    } else {
+      *othersize = units * outunitsize;
+      GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
+    }
   }
 
-  GST_DEBUG_OBJECT (trans, "transformed size %d", ret);
-
   return ret;
 }
 
@@ -317,7 +322,8 @@ gst_base_transform_getcaps (GstPad * pad)
     GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
     gst_caps_unref (caps);
     /* then see what we can tranform this to */
-    caps = gst_base_transform_transform_caps (trans, otherpad, temp);
+    caps = gst_base_transform_transform_caps (trans,
+        GST_PAD_DIRECTION (otherpad), temp);
     GST_DEBUG_OBJECT (pad, "transformed  %" GST_PTR_FORMAT, caps);
     gst_caps_unref (temp);
     if (caps == NULL)
@@ -376,6 +382,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
 
   trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+  g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
 
   otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
   otherpeer = gst_pad_get_peer (otherpad);
@@ -386,7 +393,8 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
     goto done;
 
   /* see how we can transform the input caps. */
-  othercaps = gst_base_transform_transform_caps (trans, pad, caps);
+  othercaps = gst_base_transform_transform_caps (trans,
+      GST_PAD_DIRECTION (pad), caps);
 
   /* check if transform is empty */
   if (!othercaps || gst_caps_is_empty (othercaps))
@@ -491,7 +499,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
   if (!gst_caps_is_fixed (othercaps))
     goto could_not_fixate;
 
-  /* and peer should accept, don't check again if we already checked the 
+  /* and peer should accept, don't check again if we already checked the
    * othercaps against the peer. */
   if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
     goto peer_no_accept;
@@ -572,17 +580,20 @@ failed_configure:
   }
 }
 
-static guint
-gst_base_transform_get_size (GstBaseTransform * trans, GstCaps * caps)
+static gboolean
+gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
+    guint * size)
 {
-  guint res = -1;
+  gboolean res = FALSE;
   GstBaseTransformClass *bclass;
 
+  g_return_val_if_fail (size, FALSE);
+
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
-  if (bclass->get_size) {
-    res = bclass->get_size (trans, caps);
-    GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT ") returned %d", caps,
-        res);
+  if (bclass->get_unit_size) {
+    res = bclass->get_unit_size (trans, caps, size);
+    GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT
+        ") set size %d, returned %d", caps, *size, res);
   }
 
   return res;
@@ -606,7 +617,6 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
 
   GST_DEBUG_OBJECT (trans, "allocating a buffer of size %d at offset %"
       G_GUINT64_FORMAT, size, offset);
-
   /* before any buffers are pushed, in_place is TRUE; allocating can trigger
    * a renegotiation and change that to FALSE */
   if (trans->in_place) {
@@ -621,9 +631,8 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
       goto not_configured;
 
     GST_DEBUG_OBJECT (trans, "calling transform_size");
-    new_size = gst_base_transform_transform_size (trans,
-        GST_PAD_DIRECTION (pad), caps, size, srccaps);
-    if (new_size == -1) {
+    if (!gst_base_transform_transform_size (trans,
+            GST_PAD_DIRECTION (pad), caps, size, srccaps, &new_size)) {
       gst_caps_unref (srccaps);
       goto unknown_size;
     }
@@ -644,10 +653,9 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
     if (!sinkcaps)
       goto not_configured;
 
-    new_size = gst_base_transform_transform_size (trans,
-        GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf),
-        sinkcaps);
-    if (new_size == -1) {
+    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;
@@ -765,13 +773,13 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
       }
     }
   } else {
-    /* non inplace case, figure out the output size */
-    out_size = 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));
-    if (out_size == -1)
+    /* not inplace, figure out the output size */
+    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;
+    }
 
     /* we cannot reconfigure the element yet as we are still processing
      * the old buffer. We will therefore delay the reconfiguration of the
index ff2d45e..5c8f853 100644 (file)
@@ -2,8 +2,6 @@
  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  *                    2005 Wim Taymans <wim@fluendo.com>
  *
- * gstbasetransform.h:
- *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
@@ -20,7 +18,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-
 #ifndef __GST_BASE_TRANSFORM_H__
 #define __GST_BASE_TRANSFORM_H__
 
@@ -64,7 +61,7 @@ struct _GstBaseTransform {
 
 /**
  * GstBaseTransformClass::transform_caps:
- * @pad: the pad
+ * @direction: the pad direction
  * @caps: the caps
  *
  * This method should answer the question "given this pad, and given these
@@ -78,8 +75,8 @@ struct _GstBaseTransformClass {
 
   /* given the (non-)fixed simple caps on the pad in the given direction,
    * what can I do on the other pad ? */
-  /* FIXME: change to direction */
-  GstCaps*     (*transform_caps) (GstBaseTransform *trans, GstPad *pad,
+  GstCaps*     (*transform_caps) (GstBaseTransform *trans,
+                                   GstPadDirection direction,
                                    GstCaps *caps);
 
   /* given caps on one pad, how would you fixate caps on the other pad ? */
@@ -88,17 +85,18 @@ struct _GstBaseTransformClass {
                                    GstCaps *othercaps);
 
   /* given the size of a buffer in the given direction with the given caps,
-   * calculate the
-   * size of an outgoing buffer with the given outgoing caps; the default
+   * calculate the byte size of an buffer on the other side with the given
+   * other caps; the default
    * implementation uses get_size and keeps the number of units the same */
-  guint         (*transform_size) (GstBaseTransform *trans,
+  gboolean      (*transform_size) (GstBaseTransform *trans,
                                    GstPadDirection direction,
-                                   GstCaps *incaps, guint insize,
-                                   GstCaps *outcaps);
+                                   GstCaps *caps, guint size,
+                                   GstCaps *othercaps, guint *othersize);
 
-  /* get the byte size of one unit for a given caps, -1 on error.
+  /* get the byte size of one unit for a given caps.
    * Always needs to be implemented if the transform is not in-place. */
-  guint         (*get_size)     (GstBaseTransform *trans, GstCaps *caps);
+  gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
+                                   guint *size);
 
   /* notify the subclass of new caps */
   gboolean      (*set_caps)     (GstBaseTransform *trans, GstCaps *incaps,
index 648ad24..8e1bde2 100644 (file)
@@ -99,7 +99,7 @@ static void gst_capsfilter_get_property (GObject * object, guint prop_id,
     GValue * value, GParamSpec * pspec);
 static void gst_capsfilter_dispose (GObject * object);
 static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base,
-    GstPad * pad, GstCaps * caps);
+    GstPadDirection direction, GstCaps * caps);
 static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base,
     GstBuffer * buf);
 
@@ -202,8 +202,8 @@ gst_capsfilter_dispose (GObject * object)
 }
 
 static GstCaps *
-gst_capsfilter_transform_caps (GstBaseTransform * base, GstPad * pad,
-    GstCaps * caps)
+gst_capsfilter_transform_caps (GstBaseTransform * base,
+    GstPadDirection direction, GstCaps * caps)
 {
   GstCapsFilter *capsfilter = GST_CAPSFILTER (base);
   GstCaps *ret;
index f23efb9..16822bb 100644 (file)
@@ -2,8 +2,8 @@
  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  *                    2000 Wim Taymans <wtay@chello.be>
  *                    2005 Wim Taymans <wim@fluendo.com>
- *
- * gstbasetransform.c:
+ *                    2005 Andy Wingo <wingo@fluendo.com>
+ *                    2005 Thomas Vander Stichele <thomas at apestaart dot org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -110,8 +110,8 @@ static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
     gboolean active);
 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
     gboolean active);
-static guint gst_base_transform_get_size (GstBaseTransform * trans,
-    GstCaps * caps);
+static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
+    GstCaps * caps, guint * size);
 
 static GstElementStateReturn gst_base_transform_change_state (GstElement *
     element);
@@ -209,8 +209,8 @@ gst_base_transform_init (GstBaseTransform * trans, gpointer g_class)
 }
 
 static GstCaps *
-gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
-    GstCaps * caps)
+gst_base_transform_transform_caps (GstBaseTransform * trans,
+    GstPadDirection direction, GstCaps * caps)
 {
   GstCaps *ret;
   GstBaseTransformClass *klass;
@@ -227,7 +227,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
     if (gst_caps_is_any (caps)) {
       /* for any caps we still have to call the transform function */
       GST_DEBUG_OBJECT (trans, "from ANY:");
-      temp = klass->transform_caps (trans, pad, caps);
+      temp = klass->transform_caps (trans, direction, caps);
       GST_DEBUG_OBJECT (trans, "  to: %" GST_PTR_FORMAT, temp);
 
       gst_caps_append (ret, temp);
@@ -239,7 +239,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
 
         nth = gst_caps_copy_nth (caps, i);
         GST_DEBUG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
-        temp = klass->transform_caps (trans, pad, nth);
+        temp = klass->transform_caps (trans, direction, nth);
         gst_caps_unref (nth);
         GST_DEBUG_OBJECT (trans, "  to[%d]: %" GST_PTR_FORMAT, i, temp);
 
@@ -258,10 +258,10 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
 }
 
 /* by default, this keeps the number of samples in the buffer the same */
-guint
+gboolean
 gst_base_transform_transform_size (GstBaseTransform * trans,
-    GstPadDirection direction, GstCaps * incaps,
-    guint insize, GstCaps * outcaps)
+    GstPadDirection direction, GstCaps * caps,
+    guint size, GstCaps * othercaps, guint * othersize)
 {
   guint inunitsize, outunitsize, units;
   GstBaseTransformClass *klass;
@@ -270,24 +270,29 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
   GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
-      GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %d",
-      insize, incaps, outcaps, direction);
+      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) {
-    ret = klass->transform_size (trans, direction, incaps, insize, outcaps);
+    ret = klass->transform_size (trans, direction, caps, size, othercaps,
+        othersize);
   } else {
-    inunitsize = gst_base_transform_get_size (trans, incaps);
-    g_return_val_if_fail (inunitsize != -1, -1);
-    g_return_val_if_fail (insize % inunitsize == 0, -1);
-
-    units = insize / inunitsize;
-    outunitsize = gst_base_transform_get_size (trans, outcaps);
-    ret = units * outunitsize;
+    g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps,
+            &inunitsize), FALSE);
+    g_return_val_if_fail (size % inunitsize == 0, -1);
+
+    units = size / inunitsize;
+    g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps,
+            &outunitsize), FALSE);
+    if (!othersize) {
+      ret = FALSE;
+    } else {
+      *othersize = units * outunitsize;
+      GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
+    }
   }
 
-  GST_DEBUG_OBJECT (trans, "transformed size %d", ret);
-
   return ret;
 }
 
@@ -317,7 +322,8 @@ gst_base_transform_getcaps (GstPad * pad)
     GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
     gst_caps_unref (caps);
     /* then see what we can tranform this to */
-    caps = gst_base_transform_transform_caps (trans, otherpad, temp);
+    caps = gst_base_transform_transform_caps (trans,
+        GST_PAD_DIRECTION (otherpad), temp);
     GST_DEBUG_OBJECT (pad, "transformed  %" GST_PTR_FORMAT, caps);
     gst_caps_unref (temp);
     if (caps == NULL)
@@ -376,6 +382,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
 
   trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+  g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
 
   otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
   otherpeer = gst_pad_get_peer (otherpad);
@@ -386,7 +393,8 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
     goto done;
 
   /* see how we can transform the input caps. */
-  othercaps = gst_base_transform_transform_caps (trans, pad, caps);
+  othercaps = gst_base_transform_transform_caps (trans,
+      GST_PAD_DIRECTION (pad), caps);
 
   /* check if transform is empty */
   if (!othercaps || gst_caps_is_empty (othercaps))
@@ -491,7 +499,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
   if (!gst_caps_is_fixed (othercaps))
     goto could_not_fixate;
 
-  /* and peer should accept, don't check again if we already checked the 
+  /* and peer should accept, don't check again if we already checked the
    * othercaps against the peer. */
   if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
     goto peer_no_accept;
@@ -572,17 +580,20 @@ failed_configure:
   }
 }
 
-static guint
-gst_base_transform_get_size (GstBaseTransform * trans, GstCaps * caps)
+static gboolean
+gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
+    guint * size)
 {
-  guint res = -1;
+  gboolean res = FALSE;
   GstBaseTransformClass *bclass;
 
+  g_return_val_if_fail (size, FALSE);
+
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
-  if (bclass->get_size) {
-    res = bclass->get_size (trans, caps);
-    GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT ") returned %d", caps,
-        res);
+  if (bclass->get_unit_size) {
+    res = bclass->get_unit_size (trans, caps, size);
+    GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT
+        ") set size %d, returned %d", caps, *size, res);
   }
 
   return res;
@@ -606,7 +617,6 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
 
   GST_DEBUG_OBJECT (trans, "allocating a buffer of size %d at offset %"
       G_GUINT64_FORMAT, size, offset);
-
   /* before any buffers are pushed, in_place is TRUE; allocating can trigger
    * a renegotiation and change that to FALSE */
   if (trans->in_place) {
@@ -621,9 +631,8 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
       goto not_configured;
 
     GST_DEBUG_OBJECT (trans, "calling transform_size");
-    new_size = gst_base_transform_transform_size (trans,
-        GST_PAD_DIRECTION (pad), caps, size, srccaps);
-    if (new_size == -1) {
+    if (!gst_base_transform_transform_size (trans,
+            GST_PAD_DIRECTION (pad), caps, size, srccaps, &new_size)) {
       gst_caps_unref (srccaps);
       goto unknown_size;
     }
@@ -644,10 +653,9 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
     if (!sinkcaps)
       goto not_configured;
 
-    new_size = gst_base_transform_transform_size (trans,
-        GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf),
-        sinkcaps);
-    if (new_size == -1) {
+    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;
@@ -765,13 +773,13 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
       }
     }
   } else {
-    /* non inplace case, figure out the output size */
-    out_size = 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));
-    if (out_size == -1)
+    /* not inplace, figure out the output size */
+    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;
+    }
 
     /* we cannot reconfigure the element yet as we are still processing
      * the old buffer. We will therefore delay the reconfiguration of the
index ff2d45e..5c8f853 100644 (file)
@@ -2,8 +2,6 @@
  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  *                    2005 Wim Taymans <wim@fluendo.com>
  *
- * gstbasetransform.h:
- *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
@@ -20,7 +18,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-
 #ifndef __GST_BASE_TRANSFORM_H__
 #define __GST_BASE_TRANSFORM_H__
 
@@ -64,7 +61,7 @@ struct _GstBaseTransform {
 
 /**
  * GstBaseTransformClass::transform_caps:
- * @pad: the pad
+ * @direction: the pad direction
  * @caps: the caps
  *
  * This method should answer the question "given this pad, and given these
@@ -78,8 +75,8 @@ struct _GstBaseTransformClass {
 
   /* given the (non-)fixed simple caps on the pad in the given direction,
    * what can I do on the other pad ? */
-  /* FIXME: change to direction */
-  GstCaps*     (*transform_caps) (GstBaseTransform *trans, GstPad *pad,
+  GstCaps*     (*transform_caps) (GstBaseTransform *trans,
+                                   GstPadDirection direction,
                                    GstCaps *caps);
 
   /* given caps on one pad, how would you fixate caps on the other pad ? */
@@ -88,17 +85,18 @@ struct _GstBaseTransformClass {
                                    GstCaps *othercaps);
 
   /* given the size of a buffer in the given direction with the given caps,
-   * calculate the
-   * size of an outgoing buffer with the given outgoing caps; the default
+   * calculate the byte size of an buffer on the other side with the given
+   * other caps; the default
    * implementation uses get_size and keeps the number of units the same */
-  guint         (*transform_size) (GstBaseTransform *trans,
+  gboolean      (*transform_size) (GstBaseTransform *trans,
                                    GstPadDirection direction,
-                                   GstCaps *incaps, guint insize,
-                                   GstCaps *outcaps);
+                                   GstCaps *caps, guint size,
+                                   GstCaps *othercaps, guint *othersize);
 
-  /* get the byte size of one unit for a given caps, -1 on error.
+  /* get the byte size of one unit for a given caps.
    * Always needs to be implemented if the transform is not in-place. */
-  guint         (*get_size)     (GstBaseTransform *trans, GstCaps *caps);
+  gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
+                                   guint *size);
 
   /* notify the subclass of new caps */
   gboolean      (*set_caps)     (GstBaseTransform *trans, GstCaps *incaps,
index 648ad24..8e1bde2 100644 (file)
@@ -99,7 +99,7 @@ static void gst_capsfilter_get_property (GObject * object, guint prop_id,
     GValue * value, GParamSpec * pspec);
 static void gst_capsfilter_dispose (GObject * object);
 static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base,
-    GstPad * pad, GstCaps * caps);
+    GstPadDirection direction, GstCaps * caps);
 static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base,
     GstBuffer * buf);
 
@@ -202,8 +202,8 @@ gst_capsfilter_dispose (GObject * object)
 }
 
 static GstCaps *
-gst_capsfilter_transform_caps (GstBaseTransform * base, GstPad * pad,
-    GstCaps * caps)
+gst_capsfilter_transform_caps (GstBaseTransform * base,
+    GstPadDirection direction, GstCaps * caps)
 {
   GstCapsFilter *capsfilter = GST_CAPSFILTER (base);
   GstCaps *ret;