/**
* SECTION:gstbasetransform
+ * @title: GstBaseTransform
* @short_description: Base class for simple transform filters
* @see_also: #GstBaseSrc, #GstBaseSink
*
* for more concrete use cases.
*
* It provides for:
- * <itemizedlist>
- * <listitem><para>one sinkpad and one srcpad</para></listitem>
- * <listitem><para>
- * Possible formats on sink and source pad implemented
- * with custom transform_caps function. By default uses
- * same format on sink and source.
- * </para></listitem>
- * <listitem><para>Handles state changes</para></listitem>
- * <listitem><para>Does flushing</para></listitem>
- * <listitem><para>Push mode</para></listitem>
- * <listitem><para>
- * Pull mode if the sub-class transform can operate on arbitrary data
- * </para></listitem>
- * </itemizedlist>
- *
- * <refsect2>
- * <title>Use Cases</title>
- * <para>
- * <orderedlist>
- * <listitem>
- * <itemizedlist><title>Passthrough mode</title>
- * <listitem><para>
- * Element has no interest in modifying the buffer. It may want to inspect it,
+ *
+ * * one sinkpad and one srcpad
+ * * Possible formats on sink and source pad implemented
+ * with custom transform_caps function. By default uses
+ * same format on sink and source.
+ *
+ * * Handles state changes
+ * * Does flushing
+ * * Push mode
+ * * Pull mode if the sub-class transform can operate on arbitrary data
+ *
+ * # Use Cases
+ *
+ * ## Passthrough mode
+ *
+ * * Element has no interest in modifying the buffer. It may want to inspect it,
* in which case the element should have a transform_ip function. If there
* is no transform_ip function in passthrough mode, the buffer is pushed
* intact.
- * </para></listitem>
- * <listitem><para>
- * The #GstBaseTransformClass.passthrough_on_same_caps variable
+ *
+ * * The #GstBaseTransformClass.passthrough_on_same_caps variable
* will automatically set/unset passthrough based on whether the
* element negotiates the same caps on both pads.
- * </para></listitem>
- * <listitem><para>
- * #GstBaseTransformClass.passthrough_on_same_caps on an element that
+ *
+ * * #GstBaseTransformClass.passthrough_on_same_caps on an element that
* doesn't implement a transform_caps function is useful for elements that
* only inspect data (such as level)
- * </para></listitem>
- * </itemizedlist>
- * <itemizedlist>
- * <title>Example elements</title>
- * <listitem>Level</listitem>
- * <listitem>Videoscale, audioconvert, videoconvert, audioresample in
- * certain modes.</listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist>
- * <title>Modifications in-place - input buffer and output buffer are the
- * same thing.</title>
- * <listitem><para>
- * The element must implement a transform_ip function.
- * </para></listitem>
- * <listitem><para>
- * Output buffer size must <= input buffer size
- * </para></listitem>
- * <listitem><para>
- * If the always_in_place flag is set, non-writable buffers will be copied
- * and passed to the transform_ip function, otherwise a new buffer will be
- * created and the transform function called.
- * </para></listitem>
- * <listitem><para>
- * Incoming writable buffers will be passed to the transform_ip function
- * immediately. </para></listitem>
- * <listitem><para>
- * only implementing transform_ip and not transform implies always_in_place
- * = %TRUE
- * </para></listitem>
- * </itemizedlist>
- * <itemizedlist>
- * <title>Example elements</title>
- * <listitem>Volume</listitem>
- * <listitem>Audioconvert in certain modes (signed/unsigned
- * conversion)</listitem>
- * <listitem>videoconvert in certain modes (endianness
- * swapping)</listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist>
- * <title>Modifications only to the caps/metadata of a buffer</title>
- * <listitem><para>
- * The element does not require writable data, but non-writable buffers
- * should be subbuffered so that the meta-information can be replaced.
- * </para></listitem>
- * <listitem><para>
- * Elements wishing to operate in this mode should replace the
- * prepare_output_buffer method to create subbuffers of the input buffer
- * and set always_in_place to %TRUE
- * </para></listitem>
- * </itemizedlist>
- * <itemizedlist>
- * <title>Example elements</title>
- * <listitem>Capsfilter when setting caps on outgoing buffers that have
- * none.</listitem>
- * <listitem>identity when it is going to re-timestamp buffers by
- * datarate.</listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist><title>Normal mode</title>
- * <listitem><para>
- * always_in_place flag is not set, or there is no transform_ip function
- * </para></listitem>
- * <listitem><para>
- * Element will receive an input buffer and output buffer to operate on.
- * </para></listitem>
- * <listitem><para>
- * Output buffer is allocated by calling the prepare_output_buffer function.
- * </para></listitem>
- * </itemizedlist>
- * <itemizedlist>
- * <title>Example elements</title>
- * <listitem>Videoscale, videoconvert, audioconvert when doing
- * scaling/conversions</listitem>
- * </itemizedlist>
- * </listitem>
- * <listitem>
- * <itemizedlist><title>Special output buffer allocations</title>
- * <listitem><para>
- * Elements which need to do special allocation of their output buffers
+ *
+ * * Example elements
+ *
+ * * Level
+ * * Videoscale, audioconvert, videoconvert, audioresample in certain modes.
+ *
+ * ## Modifications in-place - input buffer and output buffer are the same thing.
+ *
+ * * The element must implement a transform_ip function.
+ * * Output buffer size must <= input buffer size
+ * * If the always_in_place flag is set, non-writable buffers will be copied
+ * and passed to the transform_ip function, otherwise a new buffer will be
+ * created and the transform function called.
+ *
+ * * Incoming writable buffers will be passed to the transform_ip function
+ * immediately.
+ * * only implementing transform_ip and not transform implies always_in_place = %TRUE
+ *
+ * * Example elements:
+ * * Volume
+ * * Audioconvert in certain modes (signed/unsigned conversion)
+ * * videoconvert in certain modes (endianness swapping)
+ *
+ * ## Modifications only to the caps/metadata of a buffer
+ *
+ * * The element does not require writable data, but non-writable buffers
+ * should be subbuffered so that the meta-information can be replaced.
+ *
+ * * Elements wishing to operate in this mode should replace the
+ * prepare_output_buffer method to create subbuffers of the input buffer
+ * and set always_in_place to %TRUE
+ *
+ * * Example elements
+ * * Capsfilter when setting caps on outgoing buffers that have
+ * none.
+ * * identity when it is going to re-timestamp buffers by
+ * datarate.
+ *
+ * ## Normal mode
+ * * always_in_place flag is not set, or there is no transform_ip function
+ * * Element will receive an input buffer and output buffer to operate on.
+ * * Output buffer is allocated by calling the prepare_output_buffer function.
+ * * Example elements:
+ * * Videoscale, videoconvert, audioconvert when doing
+ * scaling/conversions
+ *
+ * ## Special output buffer allocations
+ * * Elements which need to do special allocation of their output buffers
* beyond allocating output buffers via the negotiated allocator or
* buffer pool should implement the prepare_output_buffer method.
- * </para></listitem>
- * </itemizedlist>
- * <itemizedlist>
- * <title>Example elements</title>
- * <listitem>efence</listitem>
- * </itemizedlist>
- * </listitem>
- * </orderedlist>
- * </para>
- * </refsect2>
- * <refsect2>
- * <title>Sub-class settable flags on GstBaseTransform</title>
- * <para>
- * <itemizedlist>
- * <listitem><para>
- * <itemizedlist><title>passthrough</title>
- * <listitem><para>
- * Implies that in the current configuration, the sub-class is not
- * interested in modifying the buffers.
- * </para></listitem>
- * <listitem><para>
- * Elements which are always in passthrough mode whenever the same caps
- * has been negotiated on both pads can set the class variable
- * passthrough_on_same_caps to have this behaviour automatically.
- * </para></listitem>
- * </itemizedlist>
- * </para></listitem>
- * <listitem><para>
- * <itemizedlist><title>always_in_place</title>
- * <listitem><para>
- * Determines whether a non-writable buffer will be copied before passing
- * to the transform_ip function.
- * </para></listitem>
- * <listitem><para>
- * Implied %TRUE if no transform function is implemented.
- * </para></listitem>
- * <listitem><para>
- * Implied %FALSE if ONLY transform function is implemented.
- * </para></listitem>
- * </itemizedlist>
- * </para></listitem>
- * </itemizedlist>
- * </para>
- * </refsect2>
+ *
+ * * Example elements:
+ * * efence
+ *
+ * # Sub-class settable flags on GstBaseTransform
+ *
+ * * passthrough
+ *
+ * * Implies that in the current configuration, the sub-class is not interested in modifying the buffers.
+ * * Elements which are always in passthrough mode whenever the same caps has been negotiated on both pads can set the class variable passthrough_on_same_caps to have this behaviour automatically.
+ *
+ * * always_in_place
+ * * Determines whether a non-writable buffer will be copied before passing
+ * to the transform_ip function.
+ *
+ * * Implied %TRUE if no transform function is implemented.
+ * * Implied %FALSE if ONLY transform function is implemented.
*/
#ifdef HAVE_CONFIG_H
PROP_QOS
};
-#define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
-
struct _GstBaseTransformPrivate
{
/* Set by sub-class */
static GstElementClass *parent_class = NULL;
+static gint private_offset = 0;
static void gst_base_transform_class_init (GstBaseTransformClass * klass);
static void gst_base_transform_init (GstBaseTransform * trans,
_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
+
+ private_offset =
+ g_type_add_instance_private (_type, sizeof (GstBaseTransformPrivate));
+
g_once_init_leave (&base_transform_type, _type);
}
return base_transform_type;
}
+static inline GstBaseTransformPrivate *
+gst_base_transform_get_instance_private (GstBaseTransform * self)
+{
+ return (G_STRUCT_MEMBER_P (self, private_offset));
+}
+
static void gst_base_transform_finalize (GObject * object);
static void gst_base_transform_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
gobject_class = G_OBJECT_CLASS (klass);
+ if (private_offset != 0)
+ g_type_class_adjust_private_offset (klass, &private_offset);
+
GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
"basetransform element");
GST_DEBUG ("gst_base_transform_class_init");
- g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
-
parent_class = g_type_class_peek_parent (klass);
gobject_class->set_property = gst_base_transform_set_property;
GST_DEBUG ("gst_base_transform_init");
- priv = trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
+ priv = trans->priv = gst_base_transform_get_instance_private (trans);
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
/* 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
*
GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
gst_caps_unref (temp);
- if (!gst_caps_is_empty (peerfilter)) {
+ if (peerfilter && !gst_caps_is_empty (peerfilter)) {
/* and filter against the template of the other pad */
GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
/* We keep the caps sorted like the returned caps */
/* If change are not acceptable, fallback to generic pool */
if (!gst_buffer_pool_config_validate_params (config, outcaps, size, min,
max)) {
- GST_DEBUG_OBJECT (trans, "unsuported pool, making new pool");
+ GST_DEBUG_OBJECT (trans, "unsupported pool, making new pool");
gst_object_unref (pool);
pool = gst_buffer_pool_new ();
if (!result)
goto no_decide_allocation;
+ /* check again in case the sub-class have switch to passthrough/in-place
+ * after looking at the meta APIs */
+ if (priv->passthrough || priv->always_in_place) {
+ GST_DEBUG_OBJECT (trans, "no doing passthrough, delay bufferpool");
+ gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
+ gst_query_unref (query);
+ return TRUE;
+ }
+
/* we got configuration from our peer or the decide_allocation method,
* parse them */
if (gst_query_get_n_allocation_params (query) > 0) {
GstBaseTransformClass *bclass;
gboolean ret = FALSE;
- trans = GST_BASE_TRANSFORM (parent);
+ trans = GST_BASE_TRANSFORM_CAST (parent);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->query)
* function and when it returns %TRUE */
if (do_copy) {
GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
- GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
/* simply copy then */
- info->transform_func (outbuf, *meta, inbuf,
- _gst_meta_transform_copy, ©_data);
+ if (info->transform_func) {
+ GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
+ info->transform_func (outbuf, *meta, inbuf,
+ _gst_meta_transform_copy, ©_data);
+ } else {
+ GST_DEBUG_OBJECT (trans, "couldn't copy metadata %s",
+ g_type_name (info->api));
+ }
}
return TRUE;
}
}
}
-/* Given @caps calcultate the size of one unit.
+/* Given @caps calculate the size of one unit.
*
* For video caps, this is the size of one frame (and thus one buffer).
* For audio caps, this is the size of one sample.
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
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 %" GST_PTR_FORMAT " has unit size %" G_GSIZE_FORMAT ", res %s",
caps, *size, res ? "TRUE" : "FALSE");
if (res) {
GstBaseTransformClass *bclass;
gboolean ret = TRUE;
- trans = GST_BASE_TRANSFORM (parent);
+ trans = GST_BASE_TRANSFORM_CAST (parent);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->sink_event)
GstBaseTransformClass *bclass;
gboolean ret = TRUE;
- trans = GST_BASE_TRANSFORM (parent);
+ trans = GST_BASE_TRANSFORM_CAST (parent);
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->src_event)
guint length, GstBuffer ** buffer)
{
GstBaseTransformClass *klass = GST_BASE_TRANSFORM_GET_CLASS (parent);
- GstBaseTransform *trans = GST_BASE_TRANSFORM (parent);
+ GstBaseTransform *trans = GST_BASE_TRANSFORM_CAST (parent);
GstBaseTransformPrivate *priv = trans->priv;
GstFlowReturn ret;
GstBuffer *inbuf = NULL;
static GstFlowReturn
gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
- GstBaseTransform *trans = GST_BASE_TRANSFORM (parent);
+ GstBaseTransform *trans = GST_BASE_TRANSFORM_CAST (parent);
GstBaseTransformClass *klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
GstBaseTransformPrivate *priv = trans->priv;
GstFlowReturn ret;
{
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (object);
+ trans = GST_BASE_TRANSFORM_CAST (object);
switch (prop_id) {
case PROP_QOS:
{
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (object);
+ trans = GST_BASE_TRANSFORM_CAST (object);
switch (prop_id) {
case PROP_QOS:
GST_PAD_STREAM_UNLOCK (trans->sinkpad);
priv->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);
gboolean result = FALSE;
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (parent);
+ trans = GST_BASE_TRANSFORM_CAST (parent);
switch (mode) {
case GST_PAD_MODE_PUSH:
gboolean result = FALSE;
GstBaseTransform *trans;
- trans = GST_BASE_TRANSFORM (parent);
+ trans = GST_BASE_TRANSFORM_CAST (parent);
switch (mode) {
case GST_PAD_MODE_PULL:
*
* Determines whether a non-writable buffer will be copied before passing
* to the transform_ip function.
- * <itemizedlist>
- * <listitem>Always %TRUE if no transform function is implemented.</listitem>
- * <listitem>Always %FALSE if ONLY transform function is implemented.</listitem>
- * </itemizedlist>
+ *
+ * * Always %TRUE if no transform function is implemented.
+ * * Always %FALSE if ONLY transform function is implemented.
*
* MT safe.
*/
*
* Updates the srcpad caps and send the caps downstream. This function
* can be used by subclasses when they have already negotiated their caps
- * but found a change in them (or computed new informations). This way,
- * they can notify downstream about that change without loosing any
+ * but found a change in them (or computed new information). This way,
+ * they can notify downstream about that change without losing any
* buffer.
*
* Returns: %TRUE if the caps could be send downstream %FALSE otherwise