gst/base/gstbasetransform.c: use gboolean return values and pointers to size so we can use the full GST_BUFFER_SIZE r...

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
This commit is contained in:
Thomas Vander Stichele 2005-08-24 13:33:21 +00:00
parent a7d4464ac1
commit 6519d7bfba
7 changed files with 152 additions and 122 deletions

View file

@ -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> 2005-08-24 Stefan Kost <ensonic@users.sf.net>
* gst/gstelement.c: (gst_element_class_init), * gst/gstelement.c: (gst_element_class_init),

View file

@ -2,8 +2,8 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be> * 2000 Wim Taymans <wtay@chello.be>
* 2005 Wim Taymans <wim@fluendo.com> * 2005 Wim Taymans <wim@fluendo.com>
* * 2005 Andy Wingo <wingo@fluendo.com>
* gstbasetransform.c: * 2005 Thomas Vander Stichele <thomas at apestaart dot org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * 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); gboolean active);
static gboolean gst_base_transform_sink_activate_push (GstPad * pad, static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
gboolean active); gboolean active);
static guint gst_base_transform_get_size (GstBaseTransform * trans, static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
GstCaps * caps); GstCaps * caps, guint * size);
static GstElementStateReturn gst_base_transform_change_state (GstElement * static GstElementStateReturn gst_base_transform_change_state (GstElement *
element); element);
@ -209,8 +209,8 @@ gst_base_transform_init (GstBaseTransform * trans, gpointer g_class)
} }
static GstCaps * static GstCaps *
gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad, gst_base_transform_transform_caps (GstBaseTransform * trans,
GstCaps * caps) GstPadDirection direction, GstCaps * caps)
{ {
GstCaps *ret; GstCaps *ret;
GstBaseTransformClass *klass; GstBaseTransformClass *klass;
@ -227,7 +227,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
if (gst_caps_is_any (caps)) { if (gst_caps_is_any (caps)) {
/* for any caps we still have to call the transform function */ /* for any caps we still have to call the transform function */
GST_DEBUG_OBJECT (trans, "from ANY:"); 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_DEBUG_OBJECT (trans, " to: %" GST_PTR_FORMAT, temp);
gst_caps_append (ret, 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); nth = gst_caps_copy_nth (caps, i);
GST_DEBUG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth); 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_caps_unref (nth);
GST_DEBUG_OBJECT (trans, " to[%d]: %" GST_PTR_FORMAT, i, temp); 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 */ /* by default, this keeps the number of samples in the buffer the same */
guint gboolean
gst_base_transform_transform_size (GstBaseTransform * trans, gst_base_transform_transform_size (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * incaps, GstPadDirection direction, GstCaps * caps,
guint insize, GstCaps * outcaps) guint size, GstCaps * othercaps, guint * othersize)
{ {
guint inunitsize, outunitsize, units; guint inunitsize, outunitsize, units;
GstBaseTransformClass *klass; GstBaseTransformClass *klass;
@ -270,24 +270,29 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
klass = GST_BASE_TRANSFORM_GET_CLASS (trans); klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %" GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %d", GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
insize, incaps, outcaps, direction); size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
/* if there is a custom transform function, use this */ /* if there is a custom transform function, use this */
if (klass->transform_size) { if (klass->transform_size) {
ret = klass->transform_size (trans, direction, incaps, insize, outcaps); ret = klass->transform_size (trans, direction, caps, size, othercaps,
othersize);
} else { } else {
inunitsize = gst_base_transform_get_size (trans, incaps); g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps,
g_return_val_if_fail (inunitsize != -1, -1); &inunitsize), FALSE);
g_return_val_if_fail (insize % inunitsize == 0, -1); g_return_val_if_fail (size % inunitsize == 0, -1);
units = insize / inunitsize; units = size / inunitsize;
outunitsize = gst_base_transform_get_size (trans, outcaps); g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps,
ret = units * outunitsize; &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; return ret;
} }
@ -317,7 +322,8 @@ gst_base_transform_getcaps (GstPad * pad)
GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp); GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
gst_caps_unref (caps); gst_caps_unref (caps);
/* then see what we can tranform this to */ /* 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_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
gst_caps_unref (temp); gst_caps_unref (temp);
if (caps == NULL) if (caps == NULL)
@ -376,6 +382,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad)); trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
klass = GST_BASE_TRANSFORM_GET_CLASS (trans); 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; otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
otherpeer = gst_pad_get_peer (otherpad); otherpeer = gst_pad_get_peer (otherpad);
@ -386,7 +393,8 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
goto done; goto done;
/* see how we can transform the input caps. */ /* 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 */ /* check if transform is empty */
if (!othercaps || gst_caps_is_empty (othercaps)) 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)) if (!gst_caps_is_fixed (othercaps))
goto could_not_fixate; 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. */ * othercaps against the peer. */
if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps)) if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
goto peer_no_accept; goto peer_no_accept;
@ -572,17 +580,20 @@ failed_configure:
} }
} }
static guint static gboolean
gst_base_transform_get_size (GstBaseTransform * trans, GstCaps * caps) gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{ {
guint res = -1; gboolean res = FALSE;
GstBaseTransformClass *bclass; GstBaseTransformClass *bclass;
g_return_val_if_fail (size, FALSE);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans); bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->get_size) { if (bclass->get_unit_size) {
res = bclass->get_size (trans, caps); res = bclass->get_unit_size (trans, caps, size);
GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT ") returned %d", caps, GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT
res); ") set size %d, returned %d", caps, *size, res);
} }
return 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 %" GST_DEBUG_OBJECT (trans, "allocating a buffer of size %d at offset %"
G_GUINT64_FORMAT, size, offset); G_GUINT64_FORMAT, size, offset);
/* before any buffers are pushed, in_place is TRUE; allocating can trigger /* before any buffers are pushed, in_place is TRUE; allocating can trigger
* a renegotiation and change that to FALSE */ * a renegotiation and change that to FALSE */
if (trans->in_place) { if (trans->in_place) {
@ -621,9 +631,8 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
goto not_configured; goto not_configured;
GST_DEBUG_OBJECT (trans, "calling transform_size"); GST_DEBUG_OBJECT (trans, "calling transform_size");
new_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (pad), caps, size, srccaps); GST_PAD_DIRECTION (pad), caps, size, srccaps, &new_size)) {
if (new_size == -1) {
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
goto unknown_size; goto unknown_size;
} }
@ -644,10 +653,9 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
if (!sinkcaps) if (!sinkcaps)
goto not_configured; goto not_configured;
new_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf), GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf),
sinkcaps); sinkcaps, &new_size)) {
if (new_size == -1) {
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
gst_caps_unref (sinkcaps); gst_caps_unref (sinkcaps);
goto unknown_size; goto unknown_size;
@ -765,13 +773,13 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
} }
} }
} else { } else {
/* non inplace case, figure out the output size */ /* not inplace, figure out the output size */
out_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (trans->sinkpad), GST_PAD_CAPS (trans->sinkpad), GST_PAD_DIRECTION (trans->sinkpad), GST_PAD_CAPS (trans->sinkpad),
GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad)); GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad), &out_size)) {
if (out_size == -1)
/* we have an error */ /* we have an error */
goto no_size; goto no_size;
}
/* we cannot reconfigure the element yet as we are still processing /* we cannot reconfigure the element yet as we are still processing
* the old buffer. We will therefore delay the reconfiguration of the * the old buffer. We will therefore delay the reconfiguration of the

View file

@ -2,8 +2,6 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2005 Wim Taymans <wim@fluendo.com> * 2005 Wim Taymans <wim@fluendo.com>
* *
* gstbasetransform.h:
*
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -20,7 +18,6 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#ifndef __GST_BASE_TRANSFORM_H__ #ifndef __GST_BASE_TRANSFORM_H__
#define __GST_BASE_TRANSFORM_H__ #define __GST_BASE_TRANSFORM_H__
@ -64,7 +61,7 @@ struct _GstBaseTransform {
/** /**
* GstBaseTransformClass::transform_caps: * GstBaseTransformClass::transform_caps:
* @pad: the pad * @direction: the pad direction
* @caps: the caps * @caps: the caps
* *
* This method should answer the question "given this pad, and given these * 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, /* given the (non-)fixed simple caps on the pad in the given direction,
* what can I do on the other pad ? */ * what can I do on the other pad ? */
/* FIXME: change to direction */ GstCaps* (*transform_caps) (GstBaseTransform *trans,
GstCaps* (*transform_caps) (GstBaseTransform *trans, GstPad *pad, GstPadDirection direction,
GstCaps *caps); GstCaps *caps);
/* given caps on one pad, how would you fixate caps on the other pad ? */ /* given caps on one pad, how would you fixate caps on the other pad ? */
@ -88,17 +85,18 @@ struct _GstBaseTransformClass {
GstCaps *othercaps); GstCaps *othercaps);
/* given the size of a buffer in the given direction with the given caps, /* given the size of a buffer in the given direction with the given caps,
* calculate the * calculate the byte size of an buffer on the other side with the given
* size of an outgoing buffer with the given outgoing caps; the default * other caps; the default
* implementation uses get_size and keeps the number of units the same */ * implementation uses get_size and keeps the number of units the same */
guint (*transform_size) (GstBaseTransform *trans, gboolean (*transform_size) (GstBaseTransform *trans,
GstPadDirection direction, GstPadDirection direction,
GstCaps *incaps, guint insize, GstCaps *caps, guint size,
GstCaps *outcaps); 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. */ * 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 */ /* notify the subclass of new caps */
gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps, gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,

View file

@ -99,7 +99,7 @@ static void gst_capsfilter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static void gst_capsfilter_dispose (GObject * object); static void gst_capsfilter_dispose (GObject * object);
static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base, static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base,
GstPad * pad, GstCaps * caps); GstPadDirection direction, GstCaps * caps);
static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base, static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base,
GstBuffer * buf); GstBuffer * buf);
@ -202,8 +202,8 @@ gst_capsfilter_dispose (GObject * object)
} }
static GstCaps * static GstCaps *
gst_capsfilter_transform_caps (GstBaseTransform * base, GstPad * pad, gst_capsfilter_transform_caps (GstBaseTransform * base,
GstCaps * caps) GstPadDirection direction, GstCaps * caps)
{ {
GstCapsFilter *capsfilter = GST_CAPSFILTER (base); GstCapsFilter *capsfilter = GST_CAPSFILTER (base);
GstCaps *ret; GstCaps *ret;

View file

@ -2,8 +2,8 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be> * 2000 Wim Taymans <wtay@chello.be>
* 2005 Wim Taymans <wim@fluendo.com> * 2005 Wim Taymans <wim@fluendo.com>
* * 2005 Andy Wingo <wingo@fluendo.com>
* gstbasetransform.c: * 2005 Thomas Vander Stichele <thomas at apestaart dot org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * 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); gboolean active);
static gboolean gst_base_transform_sink_activate_push (GstPad * pad, static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
gboolean active); gboolean active);
static guint gst_base_transform_get_size (GstBaseTransform * trans, static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
GstCaps * caps); GstCaps * caps, guint * size);
static GstElementStateReturn gst_base_transform_change_state (GstElement * static GstElementStateReturn gst_base_transform_change_state (GstElement *
element); element);
@ -209,8 +209,8 @@ gst_base_transform_init (GstBaseTransform * trans, gpointer g_class)
} }
static GstCaps * static GstCaps *
gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad, gst_base_transform_transform_caps (GstBaseTransform * trans,
GstCaps * caps) GstPadDirection direction, GstCaps * caps)
{ {
GstCaps *ret; GstCaps *ret;
GstBaseTransformClass *klass; GstBaseTransformClass *klass;
@ -227,7 +227,7 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, GstPad * pad,
if (gst_caps_is_any (caps)) { if (gst_caps_is_any (caps)) {
/* for any caps we still have to call the transform function */ /* for any caps we still have to call the transform function */
GST_DEBUG_OBJECT (trans, "from ANY:"); 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_DEBUG_OBJECT (trans, " to: %" GST_PTR_FORMAT, temp);
gst_caps_append (ret, 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); nth = gst_caps_copy_nth (caps, i);
GST_DEBUG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth); 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_caps_unref (nth);
GST_DEBUG_OBJECT (trans, " to[%d]: %" GST_PTR_FORMAT, i, temp); 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 */ /* by default, this keeps the number of samples in the buffer the same */
guint gboolean
gst_base_transform_transform_size (GstBaseTransform * trans, gst_base_transform_transform_size (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * incaps, GstPadDirection direction, GstCaps * caps,
guint insize, GstCaps * outcaps) guint size, GstCaps * othercaps, guint * othersize)
{ {
guint inunitsize, outunitsize, units; guint inunitsize, outunitsize, units;
GstBaseTransformClass *klass; GstBaseTransformClass *klass;
@ -270,24 +270,29 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
klass = GST_BASE_TRANSFORM_GET_CLASS (trans); klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %" GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %d", GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
insize, incaps, outcaps, direction); size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
/* if there is a custom transform function, use this */ /* if there is a custom transform function, use this */
if (klass->transform_size) { if (klass->transform_size) {
ret = klass->transform_size (trans, direction, incaps, insize, outcaps); ret = klass->transform_size (trans, direction, caps, size, othercaps,
othersize);
} else { } else {
inunitsize = gst_base_transform_get_size (trans, incaps); g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps,
g_return_val_if_fail (inunitsize != -1, -1); &inunitsize), FALSE);
g_return_val_if_fail (insize % inunitsize == 0, -1); g_return_val_if_fail (size % inunitsize == 0, -1);
units = insize / inunitsize; units = size / inunitsize;
outunitsize = gst_base_transform_get_size (trans, outcaps); g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps,
ret = units * outunitsize; &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; return ret;
} }
@ -317,7 +322,8 @@ gst_base_transform_getcaps (GstPad * pad)
GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp); GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
gst_caps_unref (caps); gst_caps_unref (caps);
/* then see what we can tranform this to */ /* 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_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
gst_caps_unref (temp); gst_caps_unref (temp);
if (caps == NULL) if (caps == NULL)
@ -376,6 +382,7 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad)); trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
klass = GST_BASE_TRANSFORM_GET_CLASS (trans); 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; otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
otherpeer = gst_pad_get_peer (otherpad); otherpeer = gst_pad_get_peer (otherpad);
@ -386,7 +393,8 @@ gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
goto done; goto done;
/* see how we can transform the input caps. */ /* 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 */ /* check if transform is empty */
if (!othercaps || gst_caps_is_empty (othercaps)) 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)) if (!gst_caps_is_fixed (othercaps))
goto could_not_fixate; 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. */ * othercaps against the peer. */
if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps)) if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
goto peer_no_accept; goto peer_no_accept;
@ -572,17 +580,20 @@ failed_configure:
} }
} }
static guint static gboolean
gst_base_transform_get_size (GstBaseTransform * trans, GstCaps * caps) gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{ {
guint res = -1; gboolean res = FALSE;
GstBaseTransformClass *bclass; GstBaseTransformClass *bclass;
g_return_val_if_fail (size, FALSE);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans); bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->get_size) { if (bclass->get_unit_size) {
res = bclass->get_size (trans, caps); res = bclass->get_unit_size (trans, caps, size);
GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT ") returned %d", caps, GST_DEBUG_OBJECT (trans, "get size(%" GST_PTR_FORMAT
res); ") set size %d, returned %d", caps, *size, res);
} }
return 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 %" GST_DEBUG_OBJECT (trans, "allocating a buffer of size %d at offset %"
G_GUINT64_FORMAT, size, offset); G_GUINT64_FORMAT, size, offset);
/* before any buffers are pushed, in_place is TRUE; allocating can trigger /* before any buffers are pushed, in_place is TRUE; allocating can trigger
* a renegotiation and change that to FALSE */ * a renegotiation and change that to FALSE */
if (trans->in_place) { if (trans->in_place) {
@ -621,9 +631,8 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
goto not_configured; goto not_configured;
GST_DEBUG_OBJECT (trans, "calling transform_size"); GST_DEBUG_OBJECT (trans, "calling transform_size");
new_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (pad), caps, size, srccaps); GST_PAD_DIRECTION (pad), caps, size, srccaps, &new_size)) {
if (new_size == -1) {
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
goto unknown_size; goto unknown_size;
} }
@ -644,10 +653,9 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
if (!sinkcaps) if (!sinkcaps)
goto not_configured; goto not_configured;
new_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf), GST_PAD_DIRECTION (trans->srcpad), srccaps, GST_BUFFER_SIZE (*buf),
sinkcaps); sinkcaps, &new_size)) {
if (new_size == -1) {
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
gst_caps_unref (sinkcaps); gst_caps_unref (sinkcaps);
goto unknown_size; goto unknown_size;
@ -765,13 +773,13 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
} }
} }
} else { } else {
/* non inplace case, figure out the output size */ /* not inplace, figure out the output size */
out_size = gst_base_transform_transform_size (trans, if (!gst_base_transform_transform_size (trans,
GST_PAD_DIRECTION (trans->sinkpad), GST_PAD_CAPS (trans->sinkpad), GST_PAD_DIRECTION (trans->sinkpad), GST_PAD_CAPS (trans->sinkpad),
GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad)); GST_BUFFER_SIZE (inbuf), GST_PAD_CAPS (trans->srcpad), &out_size)) {
if (out_size == -1)
/* we have an error */ /* we have an error */
goto no_size; goto no_size;
}
/* we cannot reconfigure the element yet as we are still processing /* we cannot reconfigure the element yet as we are still processing
* the old buffer. We will therefore delay the reconfiguration of the * the old buffer. We will therefore delay the reconfiguration of the

View file

@ -2,8 +2,6 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2005 Wim Taymans <wim@fluendo.com> * 2005 Wim Taymans <wim@fluendo.com>
* *
* gstbasetransform.h:
*
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -20,7 +18,6 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#ifndef __GST_BASE_TRANSFORM_H__ #ifndef __GST_BASE_TRANSFORM_H__
#define __GST_BASE_TRANSFORM_H__ #define __GST_BASE_TRANSFORM_H__
@ -64,7 +61,7 @@ struct _GstBaseTransform {
/** /**
* GstBaseTransformClass::transform_caps: * GstBaseTransformClass::transform_caps:
* @pad: the pad * @direction: the pad direction
* @caps: the caps * @caps: the caps
* *
* This method should answer the question "given this pad, and given these * 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, /* given the (non-)fixed simple caps on the pad in the given direction,
* what can I do on the other pad ? */ * what can I do on the other pad ? */
/* FIXME: change to direction */ GstCaps* (*transform_caps) (GstBaseTransform *trans,
GstCaps* (*transform_caps) (GstBaseTransform *trans, GstPad *pad, GstPadDirection direction,
GstCaps *caps); GstCaps *caps);
/* given caps on one pad, how would you fixate caps on the other pad ? */ /* given caps on one pad, how would you fixate caps on the other pad ? */
@ -88,17 +85,18 @@ struct _GstBaseTransformClass {
GstCaps *othercaps); GstCaps *othercaps);
/* given the size of a buffer in the given direction with the given caps, /* given the size of a buffer in the given direction with the given caps,
* calculate the * calculate the byte size of an buffer on the other side with the given
* size of an outgoing buffer with the given outgoing caps; the default * other caps; the default
* implementation uses get_size and keeps the number of units the same */ * implementation uses get_size and keeps the number of units the same */
guint (*transform_size) (GstBaseTransform *trans, gboolean (*transform_size) (GstBaseTransform *trans,
GstPadDirection direction, GstPadDirection direction,
GstCaps *incaps, guint insize, GstCaps *caps, guint size,
GstCaps *outcaps); 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. */ * 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 */ /* notify the subclass of new caps */
gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps, gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,

View file

@ -99,7 +99,7 @@ static void gst_capsfilter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static void gst_capsfilter_dispose (GObject * object); static void gst_capsfilter_dispose (GObject * object);
static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base, static GstCaps *gst_capsfilter_transform_caps (GstBaseTransform * base,
GstPad * pad, GstCaps * caps); GstPadDirection direction, GstCaps * caps);
static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base, static GstFlowReturn gst_capsfilter_transform_ip (GstBaseTransform * base,
GstBuffer * buf); GstBuffer * buf);
@ -202,8 +202,8 @@ gst_capsfilter_dispose (GObject * object)
} }
static GstCaps * static GstCaps *
gst_capsfilter_transform_caps (GstBaseTransform * base, GstPad * pad, gst_capsfilter_transform_caps (GstBaseTransform * base,
GstCaps * caps) GstPadDirection direction, GstCaps * caps)
{ {
GstCapsFilter *capsfilter = GST_CAPSFILTER (base); GstCapsFilter *capsfilter = GST_CAPSFILTER (base);
GstCaps *ret; GstCaps *ret;