#include <stdlib.h>
#include <string.h>
-/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
- * with newer GLib versions (>= 2.31.0) */
-#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include "../../../gst/gst_private.h"
#include "../../../gst/gst-i18n-lib.h"
#include "../../../gst/glib-compat-private.h"
/* previous buffer had a discont */
gboolean discont;
- GstActivateMode pad_mode;
+ GstPadMode pad_mode;
gboolean gap_aware;
- /* caps used for allocating buffers */
- gboolean proxy_alloc;
- GstCaps *sink_alloc;
- GstCaps *src_alloc;
-
- /*
- * This flag controls if basetransform should explicitly
- * do a pad alloc when it receives a buffer even if it operates on
- * passthrough, this is needed to check for downstream caps suggestions
- * and this newly alloc'ed buffer is discarded.
- *
- * Without this flag basetransform would try a pad alloc whenever it
- * gets a new buffer and pipelines like:
- * "src ! basetrans1 ! basetrans2 ! basetrans3 ! sink"
- * Would have a 3 pad allocs for each buffer pushed downstream from the src.
- *
- * This flag is set to TRUE on start up, on setcaps and when a buffer is
- * pushed downstream. It is set to FALSE after a pad alloc has been requested
- * downstream.
- * The rationale is that when a pad alloc flows through the pipeline, all
- * basetransform elements on passthrough will avoid pad alloc'ing when they
- * get the buffer.
- */
- gboolean force_alloc;
-
- /* upstream caps and size suggestions */
- GstCaps *sink_suggest;
- guint size_suggest;
- gboolean suggest_pending;
-
gboolean reconfigure;
/* QoS stats */
guint64 processed;
guint64 dropped;
- GstClockTime last_stop_out;
- GList *delayed_events;
+ GstClockTime position_out;
- GstCaps *cached_peer_caps[2];
- GstCaps *cached_transformed_caps[2];
+ GstBufferPool *pool;
+ GstAllocator *allocator;
+ guint prefix;
+ guint alignment;
};
+
static GstElementClass *parent_class = NULL;
static void gst_base_transform_class_init (GstBaseTransformClass * klass);
static void gst_base_transform_init (GstBaseTransform * trans,
GstBaseTransformClass * klass);
-static GstFlowReturn gst_base_transform_prepare_output_buffer (GstBaseTransform
- * trans, GstBuffer * input, GstBuffer ** buf);
+/* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
+ * method to get to the padtemplates */
GType
gst_base_transform_get_type (void)
{
const GValue * value, GParamSpec * pspec);
static void gst_base_transform_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
-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 gboolean gst_base_transform_src_activate_mode (GstPad * pad,
+ GstObject * parent, GstPadMode mode, gboolean active);
+static gboolean gst_base_transform_sink_activate_mode (GstPad * pad,
+ GstObject * parent, GstPadMode mode, gboolean active);
static gboolean gst_base_transform_activate (GstBaseTransform * trans,
gboolean active);
static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
- GstCaps * caps, guint * size);
+ GstCaps * caps, gsize * size);
-static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
+static gboolean gst_base_transform_src_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
GstEvent * event);
-static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
+static gboolean gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
GstEvent * event);
-static gboolean gst_base_transform_check_get_range (GstPad * pad);
-static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
- guint length, GstBuffer ** buffer);
-static GstFlowReturn gst_base_transform_chain (GstPad * pad,
+static GstFlowReturn gst_base_transform_getrange (GstPad * pad,
+ GstObject * parent, guint64 offset, guint length, GstBuffer ** buffer);
+static GstFlowReturn gst_base_transform_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer);
-static GstCaps *gst_base_transform_getcaps (GstPad * pad);
-static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
+static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
+ trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
+static void gst_base_transform_default_fixate (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
+static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
+ GstPad * pad, GstCaps * filter);
static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
GstPadDirection direction, 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);
-static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
+static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
+ GstPad * pad, GstCaps * caps);
+static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
+ GstQuery * query);
static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
GstPadDirection direction, GstQuery * query);
-static const GstQueryType *gst_base_transform_query_type (GstPad * pad);
+static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
+ trans, GstPadDirection direction, GstCaps * caps, gsize size,
+ GstCaps * othercaps, gsize * othersize);
-/* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
-
-static void
-gst_base_transform_drop_delayed_events (GstBaseTransform * trans)
-{
- GST_OBJECT_LOCK (trans);
- if (trans->priv->delayed_events) {
- g_list_foreach (trans->priv->delayed_events, (GFunc) gst_event_unref, NULL);
- g_list_free (trans->priv->delayed_events);
- trans->priv->delayed_events = NULL;
- }
- GST_OBJECT_UNLOCK (trans);
-}
+static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer ** outbuf);
+static gboolean default_copy_metadata (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf);
-static void
-gst_base_transform_clear_transformed_caps_cache (GstBaseTransform * trans)
-{
- struct _GstBaseTransformPrivate *priv = trans->priv;
- int n;
+/* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
- for (n = 0; n < 2; ++n) {
- if (priv->cached_peer_caps[n]) {
- gst_caps_unref (priv->cached_peer_caps[n]);
- priv->cached_peer_caps[n] = NULL;
- }
- if (priv->cached_transformed_caps[n]) {
- gst_caps_unref (priv->cached_transformed_caps[n]);
- priv->cached_transformed_caps[n] = NULL;
- }
- }
-}
static void
gst_base_transform_finalize (GObject * object)
trans = GST_BASE_TRANSFORM (object);
- gst_base_transform_drop_delayed_events (trans);
- gst_caps_replace (&trans->priv->sink_suggest, NULL);
- g_mutex_free (trans->transform_lock);
-
- gst_base_transform_clear_transformed_caps_cache (trans);
+ g_mutex_clear (&trans->transform_lock);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
gobject_class->finalize = gst_base_transform_finalize;
klass->passthrough_on_same_caps = FALSE;
- klass->event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
- klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
+
+ klass->transform_caps =
+ GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
+ klass->fixate_caps = GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate);
klass->accept_caps =
GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
+ klass->transform_size =
+ GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
+
+ klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
+ klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
+ klass->prepare_output_buffer =
+ GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
+ klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
}
static void
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
g_return_if_fail (pad_template != NULL);
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,
GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
gst_pad_set_chain_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_chain));
- gst_pad_set_activatepush_function (trans->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
- gst_pad_set_bufferalloc_function (trans->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_transform_buffer_alloc));
+ gst_pad_set_activatemode_function (trans->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
gst_pad_set_query_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_query));
- gst_pad_set_query_type_function (trans->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
g_return_if_fail (pad_template != NULL);
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_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,
- GST_DEBUG_FUNCPTR (gst_base_transform_check_get_range));
gst_pad_set_getrange_function (trans->srcpad,
GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
- gst_pad_set_activatepull_function (trans->srcpad,
- GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
+ gst_pad_set_activatemode_function (trans->srcpad,
+ GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
gst_pad_set_query_function (trans->srcpad,
GST_DEBUG_FUNCPTR (gst_base_transform_query));
- gst_pad_set_query_type_function (trans->srcpad,
- GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
- trans->transform_lock = g_mutex_new ();
- trans->pending_configure = FALSE;
+ g_mutex_init (&trans->transform_lock);
trans->priv->qos_enabled = DEFAULT_PROP_QOS;
trans->cache_caps1 = NULL;
trans->cache_caps2 = NULL;
- trans->priv->pad_mode = GST_ACTIVATE_NONE;
+ trans->priv->pad_mode = GST_PAD_MODE_NONE;
trans->priv->gap_aware = FALSE;
- trans->priv->delayed_events = NULL;
trans->passthrough = FALSE;
if (bclass->transform == NULL) {
trans->priv->processed = 0;
trans->priv->dropped = 0;
- trans->priv->force_alloc = TRUE;
+}
+
+static GstCaps *
+gst_base_transform_default_transform_caps (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter)
+{
+ GstCaps *ret;
+
+ GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
+ /* no transform function, use the identity transform */
+ if (filter) {
+ ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+ } else {
+ ret = gst_caps_ref (caps);
+ }
+ return ret;
}
/* given @caps on the src or sink pad (given by @direction)
*/
static GstCaps *
gst_base_transform_transform_caps (GstBaseTransform * trans,
- GstPadDirection direction, GstCaps * caps)
+ GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
- GstCaps *ret;
+ GstCaps *ret = NULL;
GstBaseTransformClass *klass;
if (caps == NULL)
/* if there is a custom transform function, use this */
if (klass->transform_caps) {
- GstCaps *temp;
- gint i;
-
- /* start with empty caps */
- ret = gst_caps_new_empty ();
GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
- 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, direction, caps);
- GST_DEBUG_OBJECT (trans, " to: %" GST_PTR_FORMAT, temp);
-
- 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 < n; i++) {
- GstCaps *nth;
-
- nth = gst_caps_copy_nth (caps, i);
- GST_LOG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
- temp = klass->transform_caps (trans, direction, nth);
- gst_caps_unref (nth);
- GST_LOG_OBJECT (trans, " to[%d]: %" GST_PTR_FORMAT, i, temp);
-
- temp = gst_caps_make_writable (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_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
+ ret = klass->transform_caps (trans, direction, caps, filter);
+ GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
+
+#ifndef G_DISABLE_ASSERT
+ if (filter) {
+ if (!gst_caps_is_subset (ret, filter)) {
+ GstCaps *intersection;
+
+ GST_ERROR_OBJECT (trans,
+ "transform_caps returned caps %" GST_PTR_FORMAT
+ " which are not a real subset of the filter caps %"
+ GST_PTR_FORMAT, ret, filter);
+ g_warning ("%s: transform_caps returned caps which are not a real "
+ "subset of the filter caps", GST_ELEMENT_NAME (trans));
+
+ intersection =
+ gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (ret);
+ ret = intersection;
}
- 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 {
- GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
- /* no transform function, use the identity transform */
- ret = gst_caps_ref (caps);
+#endif
}
- GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
- ret);
+ GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
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,
- guint size, GstCaps * othercaps, guint * othersize)
+gst_base_transform_default_transform_size (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, gsize size,
+ GstCaps * othercaps, gsize * othersize)
{
- guint inunitsize, outunitsize, units;
+ gsize inunitsize, outunitsize, units;
GstBaseTransformClass *klass;
- gboolean ret;
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 %s",
- size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
-
- if (klass->transform_size) {
- /* if there is a custom transform function, use this */
- ret = klass->transform_size (trans, direction, caps, size, othercaps,
- othersize);
- } else if (klass->get_unit_size == NULL) {
+ if (klass->get_unit_size == NULL) {
/* if there is no transform_size and no unit_size, it means the
* element does not modify the size of a buffer */
*othersize = size;
- ret = TRUE;
} 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
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);
+ GST_DEBUG_OBJECT (trans,
+ "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
+ size, inunitsize);
/* input size must be a multiple of the unit_size of the input caps */
if (inunitsize == 0 || (size % inunitsize != 0))
/* 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);
-
- ret = TRUE;
+ GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
+ *othersize);
}
- return ret;
+ return TRUE;
/* ERRORS */
no_in_size:
}
no_multiple:
{
- GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size,
- inunitsize);
- g_warning ("%s: size %u is not a multiple of unit size %u",
- GST_ELEMENT_NAME (trans), size, inunitsize);
+ GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
+ "unit size %" G_GSIZE_FORMAT, size, inunitsize);
+ g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
+ G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
return FALSE;
}
no_out_size:
}
}
+/* 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,
+ gsize size, GstCaps * othercaps, gsize * othersize)
+{
+ GstBaseTransformClass *klass;
+ gboolean ret = FALSE;
+
+ klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+
+ GST_DEBUG_OBJECT (trans,
+ "asked to transform size %" G_GSIZE_FORMAT " for caps %"
+ GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
+ size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
+
+ if (klass->transform_size) {
+ /* if there is a custom transform function, use this */
+ ret = klass->transform_size (trans, direction, caps, size, othercaps,
+ othersize);
+ }
+ return ret;
+}
+
/* get the caps that can be handled by @pad. We perform:
*
* - take the caps of peer of otherpad,
- * - filter against the padtemplate 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)
+gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
+ GstCaps * filter)
{
- GstBaseTransform *trans;
GstPad *otherpad;
- const GstCaps *templ;
- GstCaps *peercaps, *caps, *temp;
- gboolean samecaps;
- int cache_index;
-
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+ GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
+ GstCaps *templ;
otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
- cache_index = (pad == trans->srcpad) ? 0 : 1;
/* we can do what the peer can */
- peercaps = gst_pad_peer_get_caps_reffed (otherpad);
- GST_OBJECT_LOCK (trans);
- samecaps = (peercaps && trans->priv->cached_peer_caps[cache_index]
- && gst_caps_is_strictly_equal (peercaps,
- trans->priv->cached_peer_caps[cache_index]));
- if (!samecaps) {
- if (trans->priv->cached_peer_caps[cache_index]) {
- gst_caps_unref (trans->priv->cached_peer_caps[cache_index]);
- trans->priv->cached_peer_caps[cache_index] = NULL;
- }
- if (trans->priv->cached_transformed_caps[cache_index]) {
- gst_caps_unref (trans->priv->cached_transformed_caps[cache_index]);
- trans->priv->cached_transformed_caps[cache_index] = NULL;
- }
- } else {
- GST_DEBUG_OBJECT (trans,
- "Returning cached transformed caps (index = %d)", cache_index);
- caps = gst_caps_ref (trans->priv->cached_transformed_caps[cache_index]);
- goto done;
+ if (filter) {
+
+ GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
+
+ /* filtered against our padtemplate on the other side */
+ templ = gst_pad_get_pad_template_caps (pad);
+ GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
+ temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
+ GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
+ gst_caps_unref (templ);
+
+ /* then see what we can transform this to */
+ peerfilter = gst_base_transform_transform_caps (trans,
+ GST_PAD_DIRECTION (pad), temp, NULL);
+ GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
+ gst_caps_unref (temp);
+
+ /* and filter against the template of this pad */
+ templ = gst_pad_get_pad_template_caps (otherpad);
+ GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
+ /* We keep the caps sorted like the returned caps */
+ temp =
+ gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
+ GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
+ gst_caps_unref (peerfilter);
+ gst_caps_unref (templ);
+ peerfilter = temp;
}
- GST_OBJECT_UNLOCK (trans);
+
+ peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
+
+ if (peerfilter)
+ gst_caps_unref (peerfilter);
if (peercaps) {
GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
+ gst_caps_unref (templ);
} else {
- temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
- GST_DEBUG_OBJECT (pad, "no peer, using our template caps %" GST_PTR_FORMAT,
- temp);
+ temp = gst_pad_get_pad_template_caps (otherpad);
}
/* then see what we can transform this to */
caps = gst_base_transform_transform_caps (trans,
- GST_PAD_DIRECTION (otherpad), temp);
+ GST_PAD_DIRECTION (otherpad), temp, filter);
GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
gst_caps_unref (temp);
if (caps == NULL)
- goto done_update_cache;
-
- /* and filter against the template of this pad */
- templ = gst_pad_get_pad_template_caps (pad);
- GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
- /* We keep the caps sorted like the returned caps */
- temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
- GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
- gst_caps_unref (caps);
- caps = temp;
+ goto done;
if (peercaps) {
+ /* and filter against the template of this pad */
+ templ = gst_pad_get_pad_template_caps (pad);
+ GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
+ /* We keep the caps sorted like the returned caps */
+ temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
+ GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
+ gst_caps_unref (caps);
+ gst_caps_unref (templ);
+ caps = temp;
+
/* Now try if we can put the untransformed downstream caps first */
temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
if (!gst_caps_is_empty (temp)) {
} else {
gst_caps_unref (temp);
}
+ } else {
+ gst_caps_unref (caps);
+ /* no peer or the peer can do anything, our padtemplate is enough then */
+ caps = gst_pad_get_pad_template_caps (pad);
+
+ if (filter) {
+ GstCaps *temp;
+
+ temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (caps);
+ caps = temp;
+ }
}
-done_update_cache:
+done:
GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
+ if (peercaps)
+ gst_caps_unref (peercaps);
+
+ return caps;
+}
+
+static gboolean
+gst_base_transform_set_allocation (GstBaseTransform * trans,
+ GstBufferPool * pool, GstAllocator * allocator, guint prefix,
+ guint alignment)
+{
+ GstAllocator *oldalloc;
+ GstBufferPool *oldpool;
+ GstBaseTransformPrivate *priv = trans->priv;
+
+ /* activate */
+ if (pool) {
+ GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
+ if (!gst_buffer_pool_set_active (pool, TRUE))
+ goto activate_failed;
+ }
+
GST_OBJECT_LOCK (trans);
- if (peercaps) {
- trans->priv->cached_peer_caps[cache_index] = gst_caps_ref (peercaps);
+ oldpool = priv->pool;
+ priv->pool = pool;
+ oldalloc = priv->allocator;
+ priv->allocator = allocator;
+ priv->prefix = prefix;
+ priv->alignment = alignment;
+ GST_OBJECT_UNLOCK (trans);
+
+ if (oldpool) {
+ GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
+ gst_buffer_pool_set_active (oldpool, FALSE);
+ gst_object_unref (oldpool);
}
- if (caps) {
- trans->priv->cached_transformed_caps[cache_index] = gst_caps_ref (caps);
+ if (oldalloc) {
+ gst_allocator_unref (oldalloc);
}
+ return TRUE;
-done:
- GST_OBJECT_UNLOCK (trans);
+ /* ERRORS */
+activate_failed:
+ {
+ GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
+ return FALSE;
+ }
+}
- if (peercaps)
- gst_caps_unref (peercaps);
+static gboolean
+gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
+{
+ GstQuery *query;
+ gboolean result = TRUE;
+ GstBufferPool *pool = NULL, *oldpool;
+ guint size, min, max, prefix, alignment;
+ GstBaseTransformClass *klass;
+ GstAllocator *allocator = NULL;
- gst_object_unref (trans);
+ /* there are these possibilities:
+ *
+ * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
+ * will do that whenever some upstream does an allocation query.
+ * 2) we need to do a transform, we need to get a bufferpool from downstream
+ * and configure it. When upstream does the ALLOCATION query, the
+ * propose_allocation vmethod will be called and we will configure the
+ * upstream allocator with our porposed values then.
+ */
- return caps;
+ /* clear old pool */
+ oldpool = trans->priv->pool;
+ if (oldpool) {
+ GST_DEBUG_OBJECT (trans, "unreffing old pool");
+ gst_buffer_pool_set_active (oldpool, FALSE);
+ gst_object_unref (oldpool);
+ trans->priv->pool = oldpool = NULL;
+ }
+
+ if (trans->passthrough || trans->always_in_place) {
+ /* we are in passthrough, the input buffer is never copied and always passed
+ * along. We never allocate an output buffer on the srcpad. What we do is
+ * let the upstream element decide if it wants to use a bufferpool and
+ * then we will proxy the downstream pool */
+ GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
+ return TRUE;
+ }
+
+ /* not passthrough, we need to allocate */
+ /* find a pool for the negotiated caps now */
+ GST_DEBUG_OBJECT (trans, "doing allocation query");
+ query = gst_query_new_allocation (outcaps, TRUE);
+ if (!gst_pad_peer_query (trans->srcpad, query)) {
+ /* not a problem, just debug a little */
+ GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
+ }
+
+ klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+
+ GST_DEBUG_OBJECT (trans, "calling decide_allocation");
+ if (G_LIKELY (klass->decide_allocation))
+ result = klass->decide_allocation (trans, query);
+
+ /* we got configuration from our peer, parse them */
+ gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
+ &alignment, &pool);
+
+ if (size == 0) {
+ const gchar *mem = NULL;
+
+ /* no size, we have variable size buffers */
+ if (gst_query_get_n_allocation_memories (query) > 0) {
+ mem = gst_query_parse_nth_allocation_memory (query, 0);
+ }
+ allocator = gst_allocator_find (mem);
+ GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
+ } else if (pool == NULL) {
+ GstStructure *config;
+
+ /* we did not get a pool, make one ourselves then */
+ pool = gst_buffer_pool_new ();
+
+ GST_DEBUG_OBJECT (trans, "no pool, making one");
+ config = gst_buffer_pool_get_config (pool);
+ gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
+ alignment);
+ gst_buffer_pool_set_config (pool, config);
+ }
+
+ gst_query_unref (query);
+
+ /* and store */
+ result =
+ gst_base_transform_set_allocation (trans, pool, allocator, prefix,
+ alignment);
+
+ return result;
}
/* function triggered when the in and out caps are negotiated and need
ret = klass->set_caps (trans, in, out);
}
- GST_OBJECT_LOCK (trans);
- /* make sure we reevaluate how the buffer_alloc works wrt to proxy allocating
- * the buffer. FIXME, this triggers some quite heavy codepaths that don't need
- * to be taken.. */
- trans->priv->suggest_pending = TRUE;
- GST_OBJECT_UNLOCK (trans);
trans->negotiated = ret;
return ret;
}
-/* 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_can_transform (GstBaseTransform * trans, GstPad * pad,
- GstCaps * in, GstCaps * out)
+static void
+gst_base_transform_default_fixate (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
{
- 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_can_intersect (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;
- }
+ GST_DEBUG_OBJECT (trans, "using default caps fixate function");
+ gst_caps_fixate (othercaps);
}
/* given a fixed @caps on @pad, create the best possible caps for the
GstBaseTransformClass *klass;
GstPad *otherpad, *otherpeer;
GstCaps *othercaps;
- gboolean peer_checked = FALSE;
gboolean is_fixed;
/* caps must be fixed here, this is a programming error if it's not */
* 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);
+ GST_PAD_DIRECTION (pad), caps, NULL);
/* The caps we can actually output is the intersection of the transformed
* caps with the pad template for the pad */
if (othercaps) {
- GstCaps *intersect;
- const GstCaps *templ_caps;
+ GstCaps *intersect, *templ_caps;
templ_caps = gst_pad_get_pad_template_caps (otherpad);
GST_DEBUG_OBJECT (trans,
GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (othercaps);
+ gst_caps_unref (templ_caps);
othercaps = intersect;
}
GST_DEBUG_OBJECT (trans,
"transform returned non fixed %" GST_PTR_FORMAT, othercaps);
- /* see if the target caps are a superset of the source caps, in this
- * case we can try to perform passthrough */
- if (gst_caps_can_intersect (othercaps, caps)) {
- GST_DEBUG_OBJECT (trans, "try passthrough with %" GST_PTR_FORMAT, 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);
- is_fixed = TRUE;
- /* 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);
- is_fixed = TRUE;
- }
- }
- }
+ /* Now let's see what the peer suggests based on our transformed caps */
+ if (otherpeer) {
+ GstCaps *peercaps, *intersection, *templ_caps;
- /* second attempt at fixation is done by intersecting with
- * the peer caps */
- if (!is_fixed && otherpeer) {
- /* intersect against what the peer can do */
- GstCaps *peercaps;
- GstCaps *intersect;
+ GST_DEBUG_OBJECT (trans,
+ "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
- GST_DEBUG_OBJECT (trans, "othercaps now %" GST_PTR_FORMAT, othercaps);
+ peercaps = gst_pad_query_caps (otherpeer, othercaps);
+ GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
+ if (!gst_caps_is_empty (peercaps)) {
+ templ_caps = gst_pad_get_pad_template_caps (otherpad);
- peercaps = gst_pad_get_caps_reffed (otherpeer);
- intersect = gst_caps_intersect (peercaps, othercaps);
- gst_caps_unref (peercaps);
- gst_caps_unref (othercaps);
- othercaps = intersect;
- peer_checked = FALSE;
+ GST_DEBUG_OBJECT (trans,
+ "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
- is_fixed = gst_caps_is_fixed (othercaps);
+ intersection =
+ gst_caps_intersect_full (peercaps, templ_caps,
+ GST_CAPS_INTERSECT_FIRST);
+ GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
+ intersection);
+ gst_caps_unref (peercaps);
+ gst_caps_unref (templ_caps);
+ peercaps = intersection;
- GST_DEBUG_OBJECT (trans,
- "filtering against peer yields %" GST_PTR_FORMAT, othercaps);
- }
+ GST_DEBUG_OBJECT (trans,
+ "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
+ intersection =
+ gst_caps_intersect_full (peercaps, othercaps,
+ GST_CAPS_INTERSECT_FIRST);
+ GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
+ intersection);
+ gst_caps_unref (peercaps);
+ gst_caps_unref (othercaps);
+ othercaps = intersection;
+ } else {
+ othercaps = peercaps;
+ }
+ is_fixed = gst_caps_is_fixed (othercaps);
+ } else {
+ GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
+ gst_caps_unref (othercaps);
+ othercaps = gst_caps_ref (caps);
+ is_fixed = TRUE;
+ }
+ }
if (gst_caps_is_empty (othercaps))
goto no_transform_possible;
- /* third attempt at fixation, call the fixate vmethod and
- * ultimately call the pad fixate function. */
- if (!is_fixed) {
- GST_DEBUG_OBJECT (trans,
- "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
- othercaps, GST_DEBUG_PAD_NAME (otherpad));
-
- /* since we have no other way to fixate left, we might as well just take
- * the first of the caps list and fixate that */
-
- /* FIXME: when fixating using the vmethod, it might make sense to fixate
- * each of the caps; but Wim doesn't see a use case for that yet */
- gst_caps_truncate (othercaps);
- peer_checked = FALSE;
-
- if (klass->fixate_caps) {
- GST_DEBUG_OBJECT (trans, "trying to 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);
- is_fixed = gst_caps_is_fixed (othercaps);
- }
- /* if still not fixed, no other option but to let the default pad fixate
- * function do its job */
- if (!is_fixed) {
- GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
- " on pad %s:%s using gst_pad_fixate_caps", othercaps,
- GST_DEBUG_PAD_NAME (otherpad));
- gst_pad_fixate_caps (otherpad, othercaps);
- is_fixed = gst_caps_is_fixed (othercaps);
- }
- GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
- } else {
- GST_DEBUG ("caps are fixed");
- /* else caps are fixed but the subclass may want to add fields */
- if (klass->fixate_caps) {
- othercaps = gst_caps_make_writable (othercaps);
+ GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
+ 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));
+ /* second attempt at fixation, call the fixate vmethod */
+ /* caps could be fixed but the subclass may want to add fields */
+ if (klass->fixate_caps) {
+ othercaps = gst_caps_make_writable (othercaps);
- klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
- is_fixed = gst_caps_is_fixed (othercaps);
- }
+ GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
+ " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
+ GST_DEBUG_PAD_NAME (otherpad));
+ /* note that we pass the complete array of structures to the fixate
+ * function, it needs to truncate itself */
+ klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
+ is_fixed = gst_caps_is_fixed (othercaps);
+ GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
}
/* caps should be fixed now, if not we have to fail. */
if (!is_fixed)
goto could_not_fixate;
- /* 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))
+ /* and peer should accept */
+ if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
goto peer_no_accept;
GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
/* get all the formats we can handle on this pad */
if (direction == GST_PAD_SRC)
- allowed = gst_pad_get_caps_reffed (trans->srcpad);
+ allowed = gst_pad_query_caps (trans->srcpad, NULL);
else
- allowed = gst_pad_get_caps_reffed (trans->sinkpad);
+ allowed = gst_pad_query_caps (trans->sinkpad, NULL);
if (!allowed) {
- GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
+ GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
goto no_transform_possible;
}
GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
/* intersect with the requested format */
- ret = gst_caps_can_intersect (allowed, caps);
+ ret = gst_caps_is_subset (caps, allowed);
gst_caps_unref (allowed);
if (!ret)
/* 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);
+ othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
if (!othercaps || gst_caps_is_empty (othercaps))
goto no_transform_possible;
}
}
-static gboolean
-gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
-{
- gboolean ret = TRUE;
- GstBaseTransform *trans;
- GstBaseTransformClass *bclass;
-
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
- bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
-
- if (bclass->accept_caps)
- ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
-
- gst_object_unref (trans);
-
- return ret;
-}
-
/* 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
* because we never set caps starting from the srcpad.
*/
static gboolean
-gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
+gst_base_transform_setcaps (GstBaseTransform * trans, 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 %p %" GST_PTR_FORMAT, caps, caps);
/* find best possible caps for the other pad */
if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
goto failed_configure;
+ GST_OBJECT_LOCK (trans->sinkpad);
+ GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
+ trans->priv->reconfigure = FALSE;
+ GST_OBJECT_UNLOCK (trans->sinkpad);
+
/* we know this will work, we implement the setcaps */
- gst_pad_set_caps (otherpad, othercaps);
+ gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
- if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
+ if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_MODE_PULL) {
/* FIXME hm? */
- ret &= gst_pad_set_caps (otherpeer, othercaps);
+ ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
if (!ret) {
GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
othercaps);
}
}
+ if (ret) {
+ /* try to get a pool when needed */
+ ret = gst_base_transform_do_bufferpool (trans, othercaps);
+ }
+
done:
- /* new caps, force alloc on next buffer on the chain */
- trans->priv->force_alloc = TRUE;
if (otherpeer)
gst_object_unref (otherpeer);
if (othercaps)
trans->negotiated = ret;
- gst_object_unref (trans);
-
return ret;
/* ERRORS */
GstPadDirection direction, GstQuery * query)
{
gboolean ret = FALSE;
- GstPad *otherpad;
+ GstPad *pad, *otherpad;
+ GstBaseTransformClass *klass;
- otherpad = (direction == GST_PAD_SRC) ? trans->sinkpad : trans->srcpad;
+ if (direction == GST_PAD_SRC) {
+ pad = trans->srcpad;
+ otherpad = trans->sinkpad;
+ } else {
+ pad = trans->sinkpad;
+ otherpad = trans->srcpad;
+ }
+
+ klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
switch (GST_QUERY_TYPE (query)) {
- case GST_QUERY_POSITION:{
+ case GST_QUERY_ALLOCATION:
+ {
+ gboolean passthrough;
+
+ /* can only be done on the sinkpad */
+ if (direction != GST_PAD_SINK)
+ goto done;
+
+ GST_BASE_TRANSFORM_LOCK (trans);
+ passthrough = trans->passthrough;
+ GST_BASE_TRANSFORM_UNLOCK (trans);
+
+ GST_DEBUG_OBJECT (trans, "propose allocation values");
+ /* pass the query to the propose_allocation vmethod if any */
+ if (G_LIKELY (klass->propose_allocation)) {
+ ret = klass->propose_allocation (trans, query);
+ } else if (passthrough) {
+ GST_DEBUG_OBJECT (trans, "doing passthrough query");
+ ret = gst_pad_peer_query (otherpad, query);
+ } else {
+ ret = FALSE;
+ }
+ GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
+ query);
+ break;
+ }
+ case GST_QUERY_POSITION:
+ {
GstFormat format;
gst_query_parse_position (query, &format, NULL);
ret = TRUE;
if ((direction == GST_PAD_SINK)
- || (trans->priv->last_stop_out == GST_CLOCK_TIME_NONE)) {
+ || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
pos =
gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
- trans->segment.last_stop);
+ trans->segment.position);
} else {
pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
- trans->priv->last_stop_out);
+ trans->priv->position_out);
}
gst_query_set_position (query, format, pos);
} else {
}
break;
}
+ case GST_QUERY_ACCEPT_CAPS:
+ {
+ GstCaps *caps;
+
+ gst_query_parse_accept_caps (query, &caps);
+ if (klass->accept_caps) {
+ ret = klass->accept_caps (trans, direction, caps);
+ gst_query_set_accept_caps_result (query, ret);
+ /* return TRUE, we answered the query */
+ ret = TRUE;
+ }
+ break;
+ }
+ case GST_QUERY_CAPS:
+ {
+ GstCaps *filter, *caps;
+
+ gst_query_parse_caps (query, &filter);
+ caps = gst_base_transform_query_caps (trans, pad, filter);
+ gst_query_set_caps_result (query, caps);
+ gst_caps_unref (caps);
+ ret = TRUE;
+ break;
+ }
default:
ret = gst_pad_peer_query (otherpad, query);
break;
}
+done:
return ret;
}
static gboolean
-gst_base_transform_query (GstPad * pad, GstQuery * query)
+gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
GstBaseTransform *trans;
- GstBaseTransformClass *bclass;
- gboolean ret;
-
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
- if (G_UNLIKELY (trans == NULL))
- return FALSE;
-
- bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
-
- if (bclass->query)
- ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
- else
- ret = gst_pad_query_default (pad, query);
-
- gst_object_unref (trans);
-
- return ret;
-}
-
-static const GstQueryType *
-gst_base_transform_query_type (GstPad * pad)
-{
- static const GstQueryType types[] = {
- GST_QUERY_POSITION,
- GST_QUERY_NONE
- };
-
- return types;
-}
-
-static void
-compute_upstream_suggestion (GstBaseTransform * trans, guint expsize,
- GstCaps * caps)
-{
- GstCaps *othercaps;
- GstBaseTransformPrivate *priv = trans->priv;
-
- GST_DEBUG_OBJECT (trans, "trying to find upstream suggestion");
-
- /* 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, caps);
-
- 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;
+ GstBaseTransformClass *bclass;
+ gboolean ret = FALSE;
- GST_DEBUG_OBJECT (trans, "getting size of suggestion");
+ trans = GST_BASE_TRANSFORM (parent);
+ bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
- /* 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, caps, expsize, othercaps, &size_suggest)) {
+ if (bclass->query)
+ ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
- /* 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);
- }
+ return ret;
}
-/* Allocate a buffer using gst_pad_alloc_buffer
- *
- * 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
- * appropriate refcounting.
- */
+/* this function either returns the input buffer without incrementing the
+ * refcount or it allocates a new (writable) buffer */
static GstFlowReturn
-gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
- GstBuffer * in_buf, GstBuffer ** out_buf)
+default_prepare_output_buffer (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer ** outbuf)
{
- GstBaseTransformClass *bclass;
GstBaseTransformPrivate *priv;
GstFlowReturn ret = GST_FLOW_OK;
- guint outsize, newsize, expsize;
- gboolean discard, setcaps, copymeta;
- GstCaps *incaps, *oldcaps, *newcaps, *outcaps;
-
- bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
+ GstBaseTransformClass *bclass;
priv = trans->priv;
+ bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
- *out_buf = NULL;
-
- /* figure out how to allocate a buffer based on the current configuration */
+ /* figure out how to allocate an output buffer */
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;
+ /* passthrough, we will not modify the incomming buffer so we can just
+ * reuse it */
+ GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
+ *outbuf = inbuf;
} else {
- gboolean want_in_place = (bclass->transform_ip != NULL)
- && trans->always_in_place;
-
- 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;
- }
- }
-
- oldcaps = GST_PAD_CAPS (trans->srcpad);
-
- if (bclass->prepare_output_buffer) {
- GST_DEBUG_OBJECT (trans,
- "calling prepare buffer with caps %p %" GST_PTR_FORMAT, oldcaps,
- oldcaps);
- ret =
- bclass->prepare_output_buffer (trans, in_buf, outsize, oldcaps,
- out_buf);
-
- /* 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) {
- if (trans->passthrough && !trans->priv->force_alloc) {
- GST_DEBUG_OBJECT (trans, "Avoiding pad alloc");
- *out_buf = gst_buffer_ref (in_buf);
+ /* we can't reuse the input buffer */
+ if (priv->pool) {
+ GST_DEBUG_OBJECT (trans, "using pool alloc");
+ ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
} else {
- 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 (newcaps && !gst_caps_is_equal (newcaps, oldcaps)) {
- GstCaps *othercaps;
- gboolean can_convert;
-
- GST_DEBUG_OBJECT (trans, "received new caps %" GST_PTR_FORMAT, newcaps);
+ gsize insize, outsize;
+ gboolean res;
- incaps = GST_PAD_CAPS (trans->sinkpad);
+ /* no pool, we need to figure out the size of the output buffer first */
+ insize = gst_buffer_get_size (inbuf);
- /* 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, "cannot perform transform on current buffer");
-
- gst_base_transform_transform_size (trans,
- GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize);
-
- compute_upstream_suggestion (trans, expsize, newcaps);
+ if (trans->passthrough) {
+ GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
+ /* passthrough, the output size is the same as the input size. */
+ outsize = insize;
+ } else {
+ gboolean want_in_place = (bclass->transform_ip != NULL)
+ && trans->always_in_place;
- /* we got a suggested caps but we can't transform to it. See if there is
- * another downstream format that we can transform to */
- othercaps =
- gst_base_transform_find_transform (trans, trans->sinkpad, incaps);
+ if (want_in_place) {
+ GST_DEBUG_OBJECT (trans, "doing inplace alloc");
+ /* we alloc a buffer of the same size as the input */
+ outsize = insize;
+ } else {
+ GstCaps *incaps, *outcaps;
- if (othercaps && !gst_caps_is_empty (othercaps)) {
- GST_DEBUG_OBJECT (trans, "we found target caps %" GST_PTR_FORMAT,
- othercaps);
- *out_buf = gst_buffer_make_metadata_writable (*out_buf);
- gst_buffer_set_caps (*out_buf, othercaps);
- gst_caps_unref (othercaps);
- newcaps = GST_BUFFER_CAPS (*out_buf);
- can_convert = TRUE;
- } else if (othercaps)
- gst_caps_unref (othercaps);
- }
+ /* else use the transform function to get the size */
+ incaps = gst_pad_get_current_caps (trans->sinkpad);
+ outcaps = gst_pad_get_current_caps (trans->srcpad);
- /* 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);
-
- if (can_convert) {
- GST_DEBUG_OBJECT (trans, "reconfigure transform for current buffer");
-
- /* subclass might want to add fields to the caps */
- if (bclass->fixate_caps != NULL) {
- newcaps = gst_caps_copy (newcaps);
-
- GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
- " using caps %" GST_PTR_FORMAT
- " on pad %s:%s using fixate_caps vmethod", newcaps, incaps,
- GST_DEBUG_PAD_NAME (trans->srcpad));
- bclass->fixate_caps (trans, GST_PAD_SINK, incaps, newcaps);
-
- *out_buf = gst_buffer_make_metadata_writable (*out_buf);
- gst_buffer_set_caps (*out_buf, newcaps);
- gst_caps_unref (newcaps);
- newcaps = GST_BUFFER_CAPS (*out_buf);
- }
+ GST_DEBUG_OBJECT (trans, "getting output size for alloc");
+ /* copy transform, figure out the output size */
+ res = gst_base_transform_transform_size (trans,
+ GST_PAD_SINK, incaps, insize, outcaps, &outsize);
- /* 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;
- /* clear previous cached sink-pad caps, so buffer_alloc knows that
- * it needs to revisit the decision about whether to proxy or not: */
- gst_caps_replace (&priv->sink_alloc, NULL);
- /* if we got a buffer of the wrong size, discard it now and make sure we
- * allocate a properly sized buffer later. */
- if (newsize != expsize) {
- if (in_buf != *out_buf)
- gst_buffer_unref (*out_buf);
- *out_buf = NULL;
- }
- outsize = expsize;
- } else {
- compute_upstream_suggestion (trans, expsize, newcaps);
+ gst_caps_unref (incaps);
+ gst_caps_unref (outcaps);
- if (in_buf != *out_buf)
- gst_buffer_unref (*out_buf);
- *out_buf = NULL;
- }
- } else if (outsize != newsize) {
- GST_WARNING_OBJECT (trans, "Caps did not change but allocated size does "
- "not match expected size (%d != %d)", newsize, outsize);
- if (in_buf != *out_buf)
- gst_buffer_unref (*out_buf);
- *out_buf = NULL;
- }
-
- /* these are the final output caps */
- outcaps = GST_PAD_CAPS (trans->srcpad);
-
- copymeta = FALSE;
- if (*out_buf == NULL) {
- if (!discard) {
- GST_DEBUG_OBJECT (trans, "make default output buffer of size %d",
- outsize);
- /* no valid buffer yet, make one, metadata is writable */
- *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;
- } else {
- GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", in_buf,
- *out_buf);
- /* if we have different buffers, check if the metadata is ok */
- if (*out_buf != in_buf) {
- guint mask;
-
- mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
- GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
- GST_BUFFER_FLAG_GAP | GST_BUFFER_FLAG_MEDIA1 |
- GST_BUFFER_FLAG_MEDIA2 | GST_BUFFER_FLAG_MEDIA3;
- /* see if the flags and timestamps match */
- copymeta =
- (GST_MINI_OBJECT_FLAGS (*out_buf) & mask) ==
- (GST_MINI_OBJECT_FLAGS (in_buf) & mask);
- copymeta |=
- GST_BUFFER_TIMESTAMP (*out_buf) != GST_BUFFER_TIMESTAMP (in_buf) ||
- GST_BUFFER_DURATION (*out_buf) != GST_BUFFER_DURATION (in_buf) ||
- GST_BUFFER_OFFSET (*out_buf) != GST_BUFFER_OFFSET (in_buf) ||
- GST_BUFFER_OFFSET_END (*out_buf) != GST_BUFFER_OFFSET_END (in_buf);
+ if (!res)
+ goto unknown_size;
+ }
}
+ GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
+ *outbuf =
+ gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
}
}
-
- /* check if we need to make things writable. We need this when we need to
- * update the caps or the metadata on the output buffer. */
- newcaps = GST_BUFFER_CAPS (*out_buf);
- /* we check the pointers as a quick check and then go to the more involved
- * check. This is needed when we receive different pointers on the sinkpad
- * that mean the same caps. What we then want to do is prefer those caps over
- * the ones on the srcpad and set the srcpad caps to the buffer caps */
- setcaps = !newcaps || ((newcaps != outcaps)
- && (!gst_caps_is_equal (newcaps, outcaps)));
- /* we need to modify the metadata when the element is not gap aware,
- * passthrough is not used and the gap flag is set */
- copymeta |= !trans->priv->gap_aware && !trans->passthrough
- && (GST_MINI_OBJECT_FLAGS (*out_buf) & GST_BUFFER_FLAG_GAP);
-
- if (setcaps || copymeta) {
- GST_DEBUG_OBJECT (trans, "setcaps %d, copymeta %d", setcaps, copymeta);
- if (!gst_buffer_is_metadata_writable (*out_buf)) {
- GST_DEBUG_OBJECT (trans, "buffer metadata %p not writable", *out_buf);
- if (in_buf == *out_buf)
- *out_buf = gst_buffer_create_sub (in_buf, 0, GST_BUFFER_SIZE (in_buf));
- else
- *out_buf = gst_buffer_make_metadata_writable (*out_buf);
- }
- /* when we get here, the metadata should be writable */
- if (setcaps)
- gst_buffer_set_caps (*out_buf, outcaps);
- if (copymeta)
- gst_buffer_copy_metadata (*out_buf, in_buf,
- GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
- /* 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:
+}
+
+static gboolean
+default_copy_metadata (GstBaseTransform * trans,
+ GstBuffer * inbuf, GstBuffer * outbuf)
+{
+ GstBaseTransformPrivate *priv = trans->priv;
+
+ /* now copy the metadata */
+ GST_DEBUG_OBJECT (trans, "copying metadata");
+
+ /* this should not happen, buffers allocated from a pool or with
+ * new_allocate should always be writable. */
+ if (!gst_buffer_is_writable (outbuf))
+ goto not_writable;
+
+ /* when we get here, the metadata should be writable */
+ gst_buffer_copy_into (outbuf, inbuf,
+ GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
+
+ /* clear the GAP flag when the subclass does not understand it */
+ if (!priv->gap_aware)
+ GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
+
+ return TRUE;
+
+ /* ERRORS */
+not_writable:
{
- GST_WARNING_OBJECT (trans, "failed to configure caps");
- return GST_FLOW_NOT_NEGOTIATED;
+ GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
+ return FALSE;
}
}
*/
static gboolean
gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
- guint * size)
+ gsize * size)
{
gboolean res = FALSE;
GstBaseTransformClass *bclass;
/* see if we have the result cached */
if (trans->cache_caps1 == caps) {
*size = trans->cache_caps1_size;
- GST_DEBUG_OBJECT (trans, "returned %d from first cache", *size);
+ GST_DEBUG_OBJECT (trans,
+ "returned %" G_GSIZE_FORMAT " from first cache", *size);
return TRUE;
}
if (trans->cache_caps2 == caps) {
*size = trans->cache_caps2_size;
- GST_DEBUG_OBJECT (trans, "returned %d from second cached", *size);
+ GST_DEBUG_OBJECT (trans,
+ "returned %" G_GSIZE_FORMAT " from second cached", *size);
return TRUE;
}
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) {
- /* and cache the values */
- if (trans->cache_caps1 == NULL) {
- gst_caps_replace (&trans->cache_caps1, caps);
- trans->cache_caps1_size = *size;
- GST_DEBUG_OBJECT (trans, "caching %d in first cache", *size);
- } else if (trans->cache_caps2 == NULL) {
- gst_caps_replace (&trans->cache_caps2, caps);
- trans->cache_caps2_size = *size;
- GST_DEBUG_OBJECT (trans, "caching %d in second cache", *size);
- } else {
- GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
- }
- }
- } else {
- GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
- }
- return res;
-}
-
-/* your upstream peer wants to send you a buffer
- * that buffer has the given offset, size and caps
- * you're requested to allocate a buffer
- */
-static GstFlowReturn
-gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
- GstCaps * caps, GstBuffer ** buf)
-{
- GstBaseTransform *trans;
- GstBaseTransformClass *klass;
- GstBaseTransformPrivate *priv;
- GstFlowReturn res;
- gboolean alloced = FALSE;
- gboolean proxy, suggest, same_caps;
- GstCaps *sink_suggest = NULL;
- guint size_suggest;
-
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
- if (G_UNLIKELY (trans == NULL))
- return GST_FLOW_WRONG_STATE;
- klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
- priv = trans->priv;
-
- GST_DEBUG_OBJECT (pad, "alloc with caps %p %" GST_PTR_FORMAT ", size %u",
- caps, 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 %p, size %u", caps, size);
- gst_caps_replace (&sink_suggest, caps);
- size_suggest = size;
- suggest = FALSE;
- } else {
- GST_DEBUG_OBJECT (trans, "new format %p %" GST_PTR_FORMAT, caps, caps);
-
- /* 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 %p %" GST_PTR_FORMAT " size %u",
- sink_suggest, sink_suggest, priv->size_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 %p %" GST_PTR_FORMAT " size %u",
- caps, caps, size);
- gst_caps_replace (&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) {
- const GstCaps *templ;
- GstCaps *peercaps;
-
- /* Always intersect with the peer caps to get correct
- * and complete caps. The suggested caps could be incomplete,
- * for example video/x-raw-yuv without any fields at all.
- */
- peercaps =
- gst_pad_peer_get_caps_reffed (GST_BASE_TRANSFORM_SINK_PAD (trans));
-
- if (peercaps) {
- GstCaps *intersect;
-
- intersect =
- gst_caps_intersect_full (sink_suggest, peercaps,
- GST_CAPS_INTERSECT_FIRST);
- gst_caps_unref (peercaps);
-
- /* If intersected caps is empty then just keep them empty. The
- * code below will try to come up with possible caps if there
- * are any */
- gst_caps_unref (sink_suggest);
- sink_suggest = intersect;
- }
-
- /* If the suggested caps are not empty and not fixed, try to fixate them */
- if (!gst_caps_is_fixed (sink_suggest)
- && !gst_caps_is_empty (sink_suggest)) {
- GST_DEBUG_OBJECT (trans,
- "Suggested caps is not fixed: %" GST_PTR_FORMAT, sink_suggest);
-
- /* try the alloc caps if it is still not fixed */
- if (!gst_caps_is_fixed (sink_suggest)) {
- GstCaps *intersect;
-
- GST_DEBUG_OBJECT (trans, "Checking if the input caps is compatible "
- "with the non-fixed caps suggestion");
- intersect =
- gst_caps_intersect_full (sink_suggest, caps,
- GST_CAPS_INTERSECT_FIRST);
- if (!gst_caps_is_empty (intersect)) {
- GST_DEBUG_OBJECT (trans, "It is, using it");
- gst_caps_replace (&sink_suggest, caps);
- }
- gst_caps_unref (intersect);
- }
-
- /* be safe and call default fixate */
- sink_suggest = gst_caps_make_writable (sink_suggest);
- gst_pad_fixate_caps (GST_BASE_TRANSFORM_SINK_PAD (trans), sink_suggest);
-
- if (!gst_caps_is_fixed (sink_suggest)) {
- gst_caps_unref (sink_suggest);
- sink_suggest = NULL;
- }
-
- GST_DEBUG_OBJECT (trans, "Caps fixed to: %" GST_PTR_FORMAT,
- sink_suggest);
- }
-
- /* Check if the suggested caps are compatible with our
- * sinkpad template caps and if they're not (or were
- * empty after intersecting with the peer caps above)
- * we try to come up with any supported caps
- */
- if (sink_suggest) {
- templ = gst_pad_get_pad_template_caps (pad);
-
- if (!gst_caps_can_intersect (sink_suggest, templ)) {
- GstCaps *allowed;
- GstCaps *peercaps;
-
- GST_DEBUG_OBJECT (trans,
- "Requested pad alloc caps are not supported: %" GST_PTR_FORMAT,
- sink_suggest);
- /* the requested pad alloc caps are not supported, so let's try
- * picking something allowed between the pads (they are linked,
- * there must be something) */
- allowed = gst_pad_get_allowed_caps (pad);
- if (allowed && !gst_caps_is_empty (allowed)) {
- GST_DEBUG_OBJECT (trans,
- "pads could agree on one of the following caps: " "%"
- GST_PTR_FORMAT, allowed);
- allowed = gst_caps_make_writable (allowed);
-
- if (klass->fixate_caps) {
- peercaps =
- gst_pad_get_allowed_caps (GST_BASE_TRANSFORM_SRC_PAD (trans));
- klass->fixate_caps (trans, GST_PAD_SRC, peercaps, allowed);
- gst_caps_unref (peercaps);
- }
-
- /* Fixate them to be safe if the subclass didn't do it */
- gst_caps_truncate (allowed);
- gst_pad_fixate_caps (pad, allowed);
- gst_caps_replace (&sink_suggest, allowed);
- gst_caps_unref (allowed);
-
- suggest = TRUE;
-
- GST_DEBUG_OBJECT (trans, "Fixated suggestion caps to %"
- GST_PTR_FORMAT, sink_suggest);
- } else {
- if (allowed)
- gst_caps_unref (allowed);
- goto not_supported;
- }
- }
- }
- }
-
- /* 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 (sink_suggest, 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);
-
- proxy = priv->proxy_alloc;
- GST_DEBUG_OBJECT (trans, "doing default alloc, proxy %d, suggest %d", proxy,
- suggest);
-
- /* 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 %p %" GST_PTR_FORMAT
- ", size %u", caps, 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;
- alloced = TRUE;
-
- /* check if the caps changed */
- newcaps = GST_BUFFER_CAPS (*buf);
-
- GST_DEBUG_OBJECT (trans, "got caps %" GST_PTR_FORMAT, newcaps);
-
- 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, disable proxy_alloc, free the
- * buffer we received and create a buffer of the requested format
- * by the default handler. */
- GST_DEBUG_OBJECT (trans, "disabling proxy");
- priv->proxy_alloc = FALSE;
- gst_buffer_unref (*buf);
- *buf = NULL;
- }
+ res = bclass->get_unit_size (trans, caps, size);
+ GST_DEBUG_OBJECT (trans,
+ "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
+ caps, *size, res ? "TRUE" : "FALSE");
+
+ if (res) {
+ /* and cache the values */
+ if (trans->cache_caps1 == NULL) {
+ gst_caps_replace (&trans->cache_caps1, caps);
+ trans->cache_caps1_size = *size;
+ GST_DEBUG_OBJECT (trans,
+ "caching %" G_GSIZE_FORMAT " in first cache", *size);
+ } else if (trans->cache_caps2 == NULL) {
+ gst_caps_replace (&trans->cache_caps2, caps);
+ trans->cache_caps2_size = *size;
+ GST_DEBUG_OBJECT (trans,
+ "caching %" G_GSIZE_FORMAT " in second cache", *size);
} else {
- GST_DEBUG_OBJECT (trans, "received required caps from peer");
+ GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
}
}
-
- 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 %p %" GST_PTR_FORMAT, size_suggest,
- sink_suggest, sink_suggest);
- GST_BUFFER_CAPS (*buf) = sink_suggest;
- sink_suggest = NULL;
- }
-
- if (sink_suggest)
- gst_caps_unref (sink_suggest);
-
- if (res == GST_FLOW_OK && alloced) {
- /* just alloc'ed a buffer, so we only want to do this again if we
- * received a buffer */
- GST_DEBUG_OBJECT (trans, "Cleaning force alloc");
- trans->priv->force_alloc = FALSE;
- }
-
- gst_object_unref (trans);
return res;
-
- /* ERRORS */
-alloc_failed:
- {
- GST_DEBUG_OBJECT (trans, "pad alloc failed: %s", gst_flow_get_name (res));
- if (sink_suggest)
- gst_caps_unref (sink_suggest);
- gst_object_unref (trans);
- return res;
- }
-not_supported:
- {
- GST_DEBUG_OBJECT (trans, "pad alloc with unsupported caps");
- if (sink_suggest)
- gst_caps_unref (sink_suggest);
- gst_object_unref (trans);
- return GST_FLOW_NOT_NEGOTIATED;
- }
-}
-
-static void
-gst_base_transform_send_delayed_events (GstBaseTransform * trans)
-{
- GList *list, *tmp;
-
- GST_OBJECT_LOCK (trans);
- list = trans->priv->delayed_events;
- trans->priv->delayed_events = NULL;
- GST_OBJECT_UNLOCK (trans);
- if (!list)
- return;
-
- for (tmp = list; tmp; tmp = tmp->next) {
- GstEvent *ev = tmp->data;
-
- GST_DEBUG_OBJECT (trans->srcpad, "Sending delayed event %s",
- GST_EVENT_TYPE_NAME (ev));
- gst_pad_push_event (trans->srcpad, ev);
- }
- g_list_free (list);
}
static gboolean
-gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
+gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
+ GstEvent * event)
{
GstBaseTransform *trans;
GstBaseTransformClass *bclass;
gboolean ret = TRUE;
- gboolean forward = TRUE;
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
- if (G_UNLIKELY (trans == NULL)) {
- gst_event_unref (event);
- return FALSE;
- }
+ trans = GST_BASE_TRANSFORM (parent);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
- if (bclass->event)
- forward = bclass->event (trans, event);
-
- /* FIXME, do this in the default event handler so the subclass can do
- * something different. */
- if (forward) {
- gboolean delay, caps_set = (GST_PAD_CAPS (trans->srcpad) != NULL);
-
- /* src caps may not yet be set, so we delay any serialized events
- that we receive before (in particular newsegment events), except
- EOS and flush stops, since those'll obsolete previous events */
- if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP) {
- gst_base_transform_drop_delayed_events (trans);
- delay = FALSE;
- } else {
- delay = GST_EVENT_IS_SERIALIZED (event) && !caps_set
- && GST_EVENT_TYPE (event) != GST_EVENT_EOS;
- }
-
- if (delay) {
- GST_OBJECT_LOCK (trans);
- trans->priv->delayed_events =
- g_list_append (trans->priv->delayed_events, event);
- GST_OBJECT_UNLOCK (trans);
- } else {
- if (caps_set && GST_EVENT_IS_SERIALIZED (event))
- gst_base_transform_send_delayed_events (trans);
- ret = gst_pad_push_event (trans->srcpad, event);
- }
- } else
+ if (bclass->sink_event)
+ ret = bclass->sink_event (trans, event);
+ else
gst_event_unref (event);
- gst_object_unref (trans);
-
return ret;
}
static gboolean
gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
{
+ gboolean ret = TRUE, forward = TRUE;
+
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
break;
trans->priv->dropped = 0;
GST_OBJECT_UNLOCK (trans);
/* we need new segment info after the flush. */
- trans->have_newsegment = FALSE;
+ trans->have_segment = FALSE;
gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
- trans->priv->last_stop_out = GST_CLOCK_TIME_NONE;
+ trans->priv->position_out = GST_CLOCK_TIME_NONE;
break;
case GST_EVENT_EOS:
break;
case GST_EVENT_TAG:
break;
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_CAPS:
{
- GstFormat format;
- gdouble rate, arate;
- gint64 start, stop, time;
- gboolean update;
-
- gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
- &start, &stop, &time);
-
- trans->have_newsegment = TRUE;
-
- gst_segment_set_newsegment_full (&trans->segment, update, rate, arate,
- format, start, stop, time);
-
- if (format == GST_FORMAT_TIME) {
- GST_DEBUG_OBJECT (trans, "received TIME NEW_SEGMENT %" GST_TIME_FORMAT
- " -- %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT
- ", accum %" GST_TIME_FORMAT,
- GST_TIME_ARGS (trans->segment.start),
- GST_TIME_ARGS (trans->segment.stop),
- GST_TIME_ARGS (trans->segment.time),
- GST_TIME_ARGS (trans->segment.accum));
- } else {
- GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" G_GINT64_FORMAT
- " -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT
- ", accum %" G_GINT64_FORMAT,
- trans->segment.start, trans->segment.stop,
- trans->segment.time, trans->segment.accum);
- }
+ GstCaps *caps;
+
+ gst_event_parse_caps (event, &caps);
+ ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
+
+ forward = FALSE;
+ break;
+ }
+ case GST_EVENT_SEGMENT:
+ {
+ gst_event_copy_segment (event, &trans->segment);
+ trans->have_segment = TRUE;
+
+ GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
+ &trans->segment);
break;
}
default:
break;
}
- return TRUE;
+ if (ret && forward)
+ ret = gst_pad_push_event (trans->srcpad, event);
+ else
+ gst_event_unref (event);
+
+ return ret;
}
static gboolean
-gst_base_transform_src_event (GstPad * pad, GstEvent * event)
+gst_base_transform_src_event (GstPad * pad, GstObject * parent,
+ GstEvent * event)
{
GstBaseTransform *trans;
GstBaseTransformClass *bclass;
gboolean ret = TRUE;
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
- if (G_UNLIKELY (trans == NULL)) {
- gst_event_unref (event);
- return FALSE;
- }
-
+ trans = GST_BASE_TRANSFORM (parent);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->src_event)
else
gst_event_unref (event);
- gst_object_unref (trans);
-
return ret;
}
GstClockTimeDiff diff;
GstClockTime timestamp;
- gst_event_parse_qos (event, &proportion, &diff, ×tamp);
+ gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
gst_base_transform_update_qos (trans, proportion, diff, timestamp);
break;
}
{
GstBaseTransformClass *bclass;
GstFlowReturn ret = GST_FLOW_OK;
- gboolean want_in_place, reconfigure;
+ gboolean want_in_place;
GstClockTime running_time;
GstClockTime timestamp;
- GstCaps *incaps;
+ gboolean reconfigure;
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);
+ GST_OBJECT_LOCK (trans->sinkpad);
+ reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
+ || trans->priv->reconfigure;
+ GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
+ trans->priv->reconfigure = FALSE;
+ GST_OBJECT_UNLOCK (trans->sinkpad);
+
+ if (G_UNLIKELY (reconfigure)) {
+ GstCaps *incaps;
+
+ GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
- 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;
+ incaps = gst_pad_get_current_caps (trans->sinkpad);
+ if (incaps == NULL)
+ goto no_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, trans->sinkpad, incaps)) {
+ gst_caps_unref (incaps);
+ goto not_negotiated;
}
+ gst_caps_unref (incaps);
}
+no_reconfigure:
if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
- GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset %"
- G_GUINT64_FORMAT, inbuf, GST_BUFFER_SIZE (inbuf),
+ GST_DEBUG_OBJECT (trans,
+ "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
+ G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
GST_BUFFER_OFFSET (inbuf));
else
- GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset NONE",
- inbuf, GST_BUFFER_SIZE (inbuf));
+ GST_DEBUG_OBJECT (trans,
+ "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
+ gst_buffer_get_size (inbuf));
/* Don't allow buffer handling before negotiation, except in passthrough mode
* or if the class doesn't implement a set_caps function (in which case it doesn't
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
+ * format. 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))
+ if (bclass->prepare_output_buffer == NULL)
+ goto no_prepare;
+
+ GST_DEBUG_OBJECT (trans, "calling prepare buffer");
+ ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
+
+ if (ret != GST_FLOW_OK || *outbuf == NULL)
goto no_buffer;
+ if (inbuf == *outbuf) {
+ GST_DEBUG_OBJECT (trans, "reusing input buffer");
+ } else if (trans->passthrough) {
+ /* 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. This is rather weird, it means that the prepare
+ * output buffer does something wrong. */
+ GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
+ "prepare_output_buffer implementation");
+ gst_buffer_unref (*outbuf);
+ *outbuf = inbuf;
+ } else {
+ /* copy the metadata */
+ if (bclass->copy_metadata)
+ if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
+ /* something failed, post a warning */
+ GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
+ ("could not copy metadata"), (NULL));
+ }
+ }
+ GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
+ *outbuf);
+
/* now perform the needed transform */
if (trans->passthrough) {
/* In passthrough mode, give transform_ip a look at the
GST_DEBUG_OBJECT (trans, "doing inplace transform");
if (inbuf != *outbuf) {
- guint8 *indata, *outdata;
+ GstMapInfo ininfo, outinfo;
/* Different buffer. The data can still be the same when we are dealing
* with subbuffers of the same buffer. Note that because of the FIXME in
* prepare_output_buffer() we have decreased the refcounts of inbuf and
* outbuf to keep them writable */
- indata = GST_BUFFER_DATA (inbuf);
- outdata = GST_BUFFER_DATA (*outbuf);
+ g_assert (gst_buffer_map (inbuf, &ininfo, GST_MAP_READ));
+ g_assert (gst_buffer_map (*outbuf, &outinfo, GST_MAP_WRITE));
- if (indata != outdata)
- memcpy (outdata, indata, GST_BUFFER_SIZE (inbuf));
+ if (ininfo.data != outinfo.data)
+ memcpy (outinfo.data, ininfo.data, ininfo.size);
+
+ gst_buffer_unmap (inbuf, &ininfo);
+ gst_buffer_unmap (*outbuf, &outinfo);
}
ret = bclass->transform_ip (trans, *outbuf);
} else {
}
skip:
- /* only unref input buffer if we allocated a new outbuf buffer */
+ /* only unref input buffer if we allocated a new outbuf buffer. If we reused
+ * the input buffer, no refcount is changed to keep the input buffer writable
+ * when needed. */
if (*outbuf != inbuf)
gst_buffer_unref (inbuf);
- /* pushed a buffer, we can now try an alloc */
- GST_DEBUG_OBJECT (trans, "Pushed a buffer, setting force alloc to true");
- trans->priv->force_alloc = TRUE;
return ret;
/* ERRORS */
not_negotiated:
{
gst_buffer_unref (inbuf);
+ *outbuf = NULL;
GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
("not negotiated"), ("not negotiated"));
return GST_FLOW_NOT_NEGOTIATED;
}
+no_prepare:
+ {
+ gst_buffer_unref (inbuf);
+ GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
+ ("Sub-class has no prepare_output_buffer implementation"), (NULL));
+ return GST_FLOW_NOT_SUPPORTED;
+ }
no_buffer:
{
gst_buffer_unref (inbuf);
+ *outbuf = NULL;
GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
gst_flow_get_name (ret));
return ret;
}
}
-static gboolean
-gst_base_transform_check_get_range (GstPad * pad)
-{
- GstBaseTransform *trans;
- gboolean ret;
-
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
-
- ret = gst_pad_check_pull_range (trans->sinkpad);
-
- gst_object_unref (trans);
-
- return ret;
-}
-
/* FIXME, getrange is broken, need to pull range from the other
* end based on the transform_size result.
*/
static GstFlowReturn
-gst_base_transform_getrange (GstPad * pad, guint64 offset,
+gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
guint length, GstBuffer ** buffer)
{
GstBaseTransform *trans;
GstFlowReturn ret;
GstBuffer *inbuf;
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+ trans = GST_BASE_TRANSFORM (parent);
ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
if (G_UNLIKELY (ret != GST_FLOW_OK))
GST_BASE_TRANSFORM_UNLOCK (trans);
done:
- gst_object_unref (trans);
-
return ret;
/* ERRORS */
}
static GstFlowReturn
-gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
+gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
GstBaseTransform *trans;
GstBaseTransformClass *klass;
GstFlowReturn ret;
- GstClockTime last_stop = GST_CLOCK_TIME_NONE;
+ GstClockTime position = GST_CLOCK_TIME_NONE;
GstClockTime timestamp, duration;
GstBuffer *outbuf = NULL;
- trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
+ trans = GST_BASE_TRANSFORM (parent);
timestamp = GST_BUFFER_TIMESTAMP (buffer);
duration = GST_BUFFER_DURATION (buffer);
/* calculate end position of the incoming buffer */
if (timestamp != GST_CLOCK_TIME_NONE) {
if (duration != GST_CLOCK_TIME_NONE)
- last_stop = timestamp + duration;
+ position = timestamp + duration;
else
- last_stop = timestamp;
+ position = timestamp;
}
klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (klass->before_transform)
klass->before_transform (trans, buffer);
- gst_base_transform_send_delayed_events (trans);
-
/* protect transform method and concurrent buffer alloc */
GST_BASE_TRANSFORM_LOCK (trans);
ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
/* 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. */
if (outbuf != NULL) {
- if ((ret == GST_FLOW_OK)) {
- GstClockTime last_stop_out = GST_CLOCK_TIME_NONE;
+ if (ret == GST_FLOW_OK) {
+ GstClockTime position_out = GST_CLOCK_TIME_NONE;
/* Remember last stop position */
- if (last_stop != GST_CLOCK_TIME_NONE &&
+ if (position != GST_CLOCK_TIME_NONE &&
trans->segment.format == GST_FORMAT_TIME)
- gst_segment_set_last_stop (&trans->segment, GST_FORMAT_TIME, last_stop);
+ trans->segment.position = position;
if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
- last_stop_out = GST_BUFFER_TIMESTAMP (outbuf);
+ position_out = GST_BUFFER_TIMESTAMP (outbuf);
if (GST_BUFFER_DURATION_IS_VALID (outbuf))
- last_stop_out += GST_BUFFER_DURATION (outbuf);
- } else if (last_stop != GST_CLOCK_TIME_NONE) {
- last_stop_out = last_stop;
+ position_out += GST_BUFFER_DURATION (outbuf);
+ } else if (position != GST_CLOCK_TIME_NONE) {
+ position_out = position;
}
- if (last_stop_out != GST_CLOCK_TIME_NONE
+ if (position_out != GST_CLOCK_TIME_NONE
&& trans->segment.format == GST_FORMAT_TIME)
- trans->priv->last_stop_out = last_stop_out;
+ trans->priv->position_out = position_out;
/* apply DISCONT flag if the buffer is not yet marked as such */
if (trans->priv->discont) {
+ GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
if (!GST_BUFFER_IS_DISCONT (outbuf)) {
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
+ outbuf = gst_buffer_make_writable (outbuf);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
}
trans->priv->discont = FALSE;
ret = gst_pad_push (trans->srcpad, outbuf);
} else {
+ GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
gst_buffer_unref (outbuf);
}
}
/* convert internal flow to OK and mark discont for the next buffer. */
if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
+ GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
trans->priv->discont = TRUE;
ret = GST_FLOW_OK;
}
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
- GST_OBJECT_LOCK (trans);
- gst_base_transform_clear_transformed_caps_cache (trans);
- GST_OBJECT_UNLOCK (trans);
-
if (active) {
- if (trans->priv->pad_mode == GST_ACTIVATE_NONE && bclass->start)
+ GstCaps *incaps, *outcaps;
+
+ if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
result &= bclass->start (trans);
- GST_OBJECT_LOCK (trans);
+ incaps = gst_pad_get_current_caps (trans->sinkpad);
+ outcaps = gst_pad_get_current_caps (trans->srcpad);
- if (GST_PAD_CAPS (trans->sinkpad) && GST_PAD_CAPS (trans->srcpad))
+ GST_OBJECT_LOCK (trans);
+ if (incaps && outcaps)
trans->have_same_caps =
- gst_caps_is_equal (GST_PAD_CAPS (trans->sinkpad),
- GST_PAD_CAPS (trans->srcpad)) || trans->passthrough;
+ gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
else
trans->have_same_caps = trans->passthrough;
GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
trans->negotiated = FALSE;
- trans->have_newsegment = FALSE;
+ trans->have_segment = FALSE;
gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
- trans->priv->last_stop_out = GST_CLOCK_TIME_NONE;
+ trans->priv->position_out = GST_CLOCK_TIME_NONE;
trans->priv->proportion = 1.0;
trans->priv->earliest_time = -1;
trans->priv->discont = FALSE;
- gst_caps_replace (&trans->priv->sink_suggest, NULL);
trans->priv->processed = 0;
trans->priv->dropped = 0;
- trans->priv->force_alloc = TRUE;
-
GST_OBJECT_UNLOCK (trans);
+
+ if (incaps)
+ gst_caps_unref (incaps);
+ if (outcaps)
+ gst_caps_unref (outcaps);
} else {
/* We must make sure streaming has finished before resetting things
* and calling the ::stop vfunc */
GST_PAD_STREAM_LOCK (trans->sinkpad);
GST_PAD_STREAM_UNLOCK (trans->sinkpad);
- gst_base_transform_drop_delayed_events (trans);
-
trans->have_same_caps = FALSE;
- /* We can only reset the passthrough mode if the instance told us to
+ /* We can only reset the passthrough mode if the instance told us to
handle it in configure_caps */
if (bclass->passthrough_on_same_caps) {
gst_base_transform_set_passthrough (trans, FALSE);
}
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)
+ if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
result &= bclass->stop (trans);
+
+ gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
}
return result;
}
static gboolean
-gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
+gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
+ GstPadMode mode, gboolean active)
{
- gboolean result = TRUE;
+ gboolean result = FALSE;
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
+ trans = GST_BASE_TRANSFORM (parent);
- result = gst_base_transform_activate (trans, active);
-
- if (result)
- trans->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
+ switch (mode) {
+ case GST_PAD_MODE_PUSH:
+ {
+ result = gst_base_transform_activate (trans, active);
- gst_object_unref (trans);
+ if (result)
+ trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
+ break;
+ }
+ default:
+ result = TRUE;
+ break;
+ }
return result;
}
static gboolean
-gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
+gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
+ GstPadMode mode, gboolean active)
{
gboolean result = FALSE;
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
-
- result = gst_pad_activate_pull (trans->sinkpad, active);
+ trans = GST_BASE_TRANSFORM (parent);
- if (result)
- result &= gst_base_transform_activate (trans, active);
+ switch (mode) {
+ case GST_PAD_MODE_PULL:
+ {
+ result =
+ gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
- if (result)
- trans->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
+ if (result)
+ result &= gst_base_transform_activate (trans, active);
- gst_object_unref (trans);
+ if (result)
+ trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
+ break;
+ }
+ default:
+ result = TRUE;
+ break;
+ }
return result;
}
*/
void
gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
- guint size)
+ gsize 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_base_transform_clear_transformed_caps_cache (trans);
- GST_DEBUG_OBJECT (trans, "new suggest %" GST_PTR_FORMAT, caps);
- GST_OBJECT_UNLOCK (trans->sinkpad);
+ /* push the renegotiate event */
+ if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
+ gst_event_new_reconfigure ()))
+ GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
}
/**
GST_OBJECT_LOCK (trans);
GST_DEBUG_OBJECT (trans, "marking reconfigure");
trans->priv->reconfigure = TRUE;
- gst_base_transform_clear_transformed_caps_cache (trans);
- gst_caps_replace (&trans->priv->sink_alloc, NULL);
GST_OBJECT_UNLOCK (trans);
}