2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
4 * 2005 Andy Wingo <wingo@fluendo.com>
5 * 2005 Thomas Vander Stichele <thomas at apestaart dot org>
6 * 2008 Wim Taymans <wim.taymans@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * SECTION:gstbasetransform
26 * @short_description: Base class for simple transform filters
27 * @see_also: #GstBaseSrc, #GstBaseSink
29 * This base class is for filter elements that process data.
33 * <listitem><para>one sinkpad and one srcpad</para></listitem>
35 * Possible formats on sink and source pad implemented
36 * with custom transform_caps function. By default uses
37 * same format on sink and source.
39 * <listitem><para>Handles state changes</para></listitem>
40 * <listitem><para>Does flushing</para></listitem>
41 * <listitem><para>Push mode</para></listitem>
43 * Pull mode if the sub-class transform can operate on arbitrary data
48 * <title>Use Cases</title>
52 * <itemizedlist><title>Passthrough mode</title>
54 * Element has no interest in modifying the buffer. It may want to inspect it,
55 * in which case the element should have a transform_ip function. If there
56 * is no transform_ip function in passthrough mode, the buffer is pushed
60 * On the GstBaseTransformClass is the passthrough_on_same_caps variable
61 * which will automatically set/unset passthrough based on whether the
62 * element negotiates the same caps on both pads.
65 * passthrough_on_same_caps on an element that doesn't implement a
66 * transform_caps function is useful for elements that only inspect data
71 * <title>Example elements</title>
72 * <listitem>Level</listitem>
73 * <listitem>Videoscale, audioconvert, ffmpegcolorspace, audioresample in
74 * certain modes.</listitem>
79 * <title>Modifications in-place - input buffer and output buffer are the
82 * The element must implement a transform_ip function.
85 * Output buffer size must <= input buffer size
88 * If the always_in_place flag is set, non-writable buffers will be copied
89 * and passed to the transform_ip function, otherwise a new buffer will be
90 * created and the transform function called.
93 * Incoming writable buffers will be passed to the transform_ip function
94 * immediately. </para></listitem>
96 * only implementing transform_ip and not transform implies always_in_place
101 * <title>Example elements</title>
102 * <listitem>Volume</listitem>
103 * <listitem>Audioconvert in certain modes (signed/unsigned
104 * conversion)</listitem>
105 * <listitem>ffmpegcolorspace in certain modes (endianness
106 * swapping)</listitem>
111 * <title>Modifications only to the caps/metadata of a buffer</title>
113 * The element does not require writable data, but non-writable buffers
114 * should be subbuffered so that the meta-information can be replaced.
117 * Elements wishing to operate in this mode should replace the
118 * prepare_output_buffer method to create subbuffers of the input buffer
119 * and set always_in_place to TRUE
123 * <title>Example elements</title>
124 * <listitem>Capsfilter when setting caps on outgoing buffers that have
126 * <listitem>identity when it is going to re-timestamp buffers by
127 * datarate.</listitem>
131 * <itemizedlist><title>Normal mode</title>
133 * always_in_place flag is not set, or there is no transform_ip function
136 * Element will receive an input buffer and output buffer to operate on.
139 * Output buffer is allocated by calling the prepare_output_buffer function.
143 * <title>Example elements</title>
144 * <listitem>Videoscale, ffmpegcolorspace, audioconvert when doing
145 * scaling/conversions</listitem>
149 * <itemizedlist><title>Special output buffer allocations</title>
151 * Elements which need to do special allocation of their output buffers
152 * other than what gst_buffer_pad_alloc allows should implement a
153 * prepare_output_buffer method, which calls the parent implementation and
154 * passes the newly allocated buffer.
158 * <title>Example elements</title>
159 * <listitem>efence</listitem>
166 * <title>Sub-class settable flags on GstBaseTransform</title>
170 * <itemizedlist><title>passthrough</title>
172 * Implies that in the current configuration, the sub-class is not
173 * interested in modifying the buffers.
176 * Elements which are always in passthrough mode whenever the same caps
177 * has been negotiated on both pads can set the class variable
178 * passthrough_on_same_caps to have this behaviour automatically.
183 * <itemizedlist><title>always_in_place</title>
185 * Determines whether a non-writable buffer will be copied before passing
186 * to the transform_ip function.
189 * Implied TRUE if no transform function is implemented.
192 * Implied FALSE if ONLY transform function is implemented.
208 #include "../../../gst/gst_private.h"
209 #include "../../../gst/gst-i18n-lib.h"
210 #include "../../../gst/glib-compat-private.h"
211 #include "gstbasetransform.h"
212 #include <gst/gstmarshal.h>
214 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
215 #define GST_CAT_DEFAULT gst_base_transform_debug
217 /* BaseTransform signals and args */
224 #define DEFAULT_PROP_QOS FALSE
232 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
233 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
235 struct _GstBaseTransformPrivate
237 /* QoS *//* with LOCK */
238 gboolean qos_enabled;
240 GstClockTime earliest_time;
241 /* previous buffer had a discont */
248 gboolean reconfigure;
254 GstClockTime position_out;
257 const GstAllocator *allocator;
263 static GstElementClass *parent_class = NULL;
265 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
266 static void gst_base_transform_init (GstBaseTransform * trans,
267 GstBaseTransformClass * klass);
269 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
270 * method to get to the padtemplates */
272 gst_base_transform_get_type (void)
274 static volatile gsize base_transform_type = 0;
276 if (g_once_init_enter (&base_transform_type)) {
278 static const GTypeInfo base_transform_info = {
279 sizeof (GstBaseTransformClass),
282 (GClassInitFunc) gst_base_transform_class_init,
285 sizeof (GstBaseTransform),
287 (GInstanceInitFunc) gst_base_transform_init,
290 _type = g_type_register_static (GST_TYPE_ELEMENT,
291 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
292 g_once_init_leave (&base_transform_type, _type);
294 return base_transform_type;
297 static void gst_base_transform_finalize (GObject * object);
298 static void gst_base_transform_set_property (GObject * object, guint prop_id,
299 const GValue * value, GParamSpec * pspec);
300 static void gst_base_transform_get_property (GObject * object, guint prop_id,
301 GValue * value, GParamSpec * pspec);
302 static gboolean gst_base_transform_src_activate_mode (GstPad * pad,
303 GstObject * parent, GstPadMode mode, gboolean active);
304 static gboolean gst_base_transform_sink_activate_mode (GstPad * pad,
305 GstObject * parent, GstPadMode mode, gboolean active);
306 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
308 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
309 GstCaps * caps, gsize * size);
311 static gboolean gst_base_transform_src_event (GstPad * pad, GstObject * parent,
313 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
315 static gboolean gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
317 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
319 static GstFlowReturn gst_base_transform_getrange (GstPad * pad,
320 GstObject * parent, guint64 offset, guint length, GstBuffer ** buffer);
321 static GstFlowReturn gst_base_transform_chain (GstPad * pad, GstObject * parent,
323 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
324 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
325 static void gst_base_transform_default_fixate (GstBaseTransform * trans,
326 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
327 static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
328 GstPad * pad, GstCaps * filter);
329 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
330 GstPadDirection direction, GstCaps * caps);
331 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
332 GstPad * pad, GstCaps * caps);
333 static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
335 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
336 GstPadDirection direction, GstQuery * query);
337 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
338 trans, GstPadDirection direction, GstCaps * caps, gsize size,
339 GstCaps * othercaps, gsize * othersize);
341 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
342 GstBuffer * inbuf, GstBuffer ** outbuf);
343 static gboolean default_copy_metadata (GstBaseTransform * trans,
344 GstBuffer * inbuf, GstBuffer * outbuf);
346 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
350 gst_base_transform_finalize (GObject * object)
352 GstBaseTransform *trans;
354 trans = GST_BASE_TRANSFORM (object);
356 g_mutex_clear (&trans->transform_lock);
358 G_OBJECT_CLASS (parent_class)->finalize (object);
362 gst_base_transform_class_init (GstBaseTransformClass * klass)
364 GObjectClass *gobject_class;
366 gobject_class = G_OBJECT_CLASS (klass);
368 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
369 "basetransform element");
371 GST_DEBUG ("gst_base_transform_class_init");
373 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
375 parent_class = g_type_class_peek_parent (klass);
377 gobject_class->set_property = gst_base_transform_set_property;
378 gobject_class->get_property = gst_base_transform_get_property;
380 g_object_class_install_property (gobject_class, PROP_QOS,
381 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
382 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
384 gobject_class->finalize = gst_base_transform_finalize;
386 klass->passthrough_on_same_caps = FALSE;
388 klass->transform_caps =
389 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
390 klass->fixate_caps = GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate);
392 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
393 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
394 klass->transform_size =
395 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
397 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
398 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
399 klass->prepare_output_buffer =
400 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
401 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
405 gst_base_transform_init (GstBaseTransform * trans,
406 GstBaseTransformClass * bclass)
408 GstPadTemplate *pad_template;
410 GST_DEBUG ("gst_base_transform_init");
412 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
415 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
416 g_return_if_fail (pad_template != NULL);
417 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
418 gst_pad_set_event_function (trans->sinkpad,
419 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
420 gst_pad_set_chain_function (trans->sinkpad,
421 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
422 gst_pad_set_activatemode_function (trans->sinkpad,
423 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
424 gst_pad_set_query_function (trans->sinkpad,
425 GST_DEBUG_FUNCPTR (gst_base_transform_query));
426 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
429 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
430 g_return_if_fail (pad_template != NULL);
431 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
432 gst_pad_set_event_function (trans->srcpad,
433 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
434 gst_pad_set_getrange_function (trans->srcpad,
435 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
436 gst_pad_set_activatemode_function (trans->srcpad,
437 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
438 gst_pad_set_query_function (trans->srcpad,
439 GST_DEBUG_FUNCPTR (gst_base_transform_query));
440 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
442 g_mutex_init (&trans->transform_lock);
443 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
444 trans->cache_caps1 = NULL;
445 trans->cache_caps2 = NULL;
446 trans->priv->pad_mode = GST_PAD_MODE_NONE;
447 trans->priv->gap_aware = FALSE;
449 trans->passthrough = FALSE;
450 if (bclass->transform == NULL) {
451 /* If no transform function, always_in_place is TRUE */
452 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
453 trans->always_in_place = TRUE;
455 if (bclass->transform_ip == NULL) {
456 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
457 trans->passthrough = TRUE;
461 trans->priv->processed = 0;
462 trans->priv->dropped = 0;
466 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
467 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
471 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
472 /* no transform function, use the identity transform */
474 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
476 ret = gst_caps_ref (caps);
481 /* given @caps on the src or sink pad (given by @direction)
482 * calculate the possible caps on the other pad.
484 * Returns new caps, unref after usage.
487 gst_base_transform_transform_caps (GstBaseTransform * trans,
488 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
491 GstBaseTransformClass *klass;
496 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
498 /* if there is a custom transform function, use this */
499 if (klass->transform_caps) {
500 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
502 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
503 ret = klass->transform_caps (trans, direction, caps, filter);
504 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
506 #ifndef G_DISABLE_ASSERT
508 if (!gst_caps_is_subset (ret, filter)) {
509 GstCaps *intersection;
511 GST_ERROR_OBJECT (trans,
512 "transform_caps returned caps %" GST_PTR_FORMAT
513 " which are not a real subset of the filter caps %"
514 GST_PTR_FORMAT, ret, filter);
515 g_warning ("%s: transform_caps returned caps which are not a real "
516 "subset of the filter caps", GST_ELEMENT_NAME (trans));
519 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
520 gst_caps_unref (ret);
527 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
533 gst_base_transform_default_transform_size (GstBaseTransform * trans,
534 GstPadDirection direction, GstCaps * caps, gsize size,
535 GstCaps * othercaps, gsize * othersize)
537 gsize inunitsize, outunitsize, units;
538 GstBaseTransformClass *klass;
540 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
542 if (klass->get_unit_size == NULL) {
543 /* if there is no transform_size and no unit_size, it means the
544 * element does not modify the size of a buffer */
547 /* there is no transform_size function, we have to use the unit_size
548 * functions. This method assumes there is a fixed unit_size associated with
549 * each caps. We provide the same amount of units on both sides. */
550 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
553 GST_DEBUG_OBJECT (trans,
554 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
557 /* input size must be a multiple of the unit_size of the input caps */
558 if (inunitsize == 0 || (size % inunitsize != 0))
561 /* get the amount of units */
562 units = size / inunitsize;
564 /* now get the unit size of the output */
565 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
568 /* the output size is the unit_size times the amount of units on the
570 *othersize = units * outunitsize;
571 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
579 GST_DEBUG_OBJECT (trans, "could not get in_size");
580 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
585 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
586 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
587 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
588 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
593 GST_DEBUG_OBJECT (trans, "could not get out_size");
594 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
599 /* transform a buffer of @size with @caps on the pad with @direction to
600 * the size of a buffer with @othercaps and store the result in @othersize
602 * We have two ways of doing this:
603 * 1) use a custom transform size function, this is for complicated custom
604 * cases with no fixed unit_size.
605 * 2) use the unit_size functions where there is a relationship between the
606 * caps and the size of a buffer.
609 gst_base_transform_transform_size (GstBaseTransform * trans,
610 GstPadDirection direction, GstCaps * caps,
611 gsize size, GstCaps * othercaps, gsize * othersize)
613 GstBaseTransformClass *klass;
614 gboolean ret = FALSE;
616 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
618 GST_DEBUG_OBJECT (trans,
619 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
620 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
621 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
623 if (klass->transform_size) {
624 /* if there is a custom transform function, use this */
625 ret = klass->transform_size (trans, direction, caps, size, othercaps,
631 /* get the caps that can be handled by @pad. We perform:
633 * - take the caps of peer of otherpad,
634 * - filter against the padtemplate of otherpad,
635 * - calculate all transforms of remaining caps
636 * - filter against template of @pad
638 * If there is no peer, we simply return the caps of the padtemplate of pad.
641 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
645 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
648 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
650 /* we can do what the peer can */
653 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
655 /* filtered against our padtemplate on the other side */
656 templ = gst_pad_get_pad_template_caps (pad);
657 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
658 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
659 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
660 gst_caps_unref (templ);
662 /* then see what we can transform this to */
663 peerfilter = gst_base_transform_transform_caps (trans,
664 GST_PAD_DIRECTION (pad), temp, NULL);
665 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
666 gst_caps_unref (temp);
668 /* and filter against the template of this pad */
669 templ = gst_pad_get_pad_template_caps (otherpad);
670 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
671 /* We keep the caps sorted like the returned caps */
673 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
674 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
675 gst_caps_unref (peerfilter);
676 gst_caps_unref (templ);
680 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
683 gst_caps_unref (peerfilter);
686 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
688 /* filtered against our padtemplate on the other side */
689 templ = gst_pad_get_pad_template_caps (otherpad);
690 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
691 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
692 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
693 gst_caps_unref (templ);
695 temp = gst_pad_get_pad_template_caps (otherpad);
698 /* then see what we can transform this to */
699 caps = gst_base_transform_transform_caps (trans,
700 GST_PAD_DIRECTION (otherpad), temp, filter);
701 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
702 gst_caps_unref (temp);
707 /* and filter against the template of this pad */
708 templ = gst_pad_get_pad_template_caps (pad);
709 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
710 /* We keep the caps sorted like the returned caps */
711 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
712 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
713 gst_caps_unref (caps);
714 gst_caps_unref (templ);
717 /* Now try if we can put the untransformed downstream caps first */
718 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
719 if (!gst_caps_is_empty (temp)) {
720 gst_caps_merge (temp, caps);
723 gst_caps_unref (temp);
726 gst_caps_unref (caps);
727 /* no peer or the peer can do anything, our padtemplate is enough then */
728 caps = gst_pad_get_pad_template_caps (pad);
733 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
734 gst_caps_unref (caps);
740 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
743 gst_caps_unref (peercaps);
749 gst_base_transform_set_allocation (GstBaseTransform * trans,
750 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
753 GstBufferPool *oldpool;
754 GstBaseTransformPrivate *priv = trans->priv;
758 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
759 if (!gst_buffer_pool_set_active (pool, TRUE))
760 goto activate_failed;
763 GST_OBJECT_LOCK (trans);
764 oldpool = priv->pool;
766 priv->allocator = allocator;
767 priv->prefix = prefix;
768 priv->alignment = alignment;
769 GST_OBJECT_UNLOCK (trans);
772 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
773 gst_buffer_pool_set_active (oldpool, FALSE);
774 gst_object_unref (oldpool);
781 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
787 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
790 gboolean result = TRUE;
791 GstBufferPool *pool = NULL, *oldpool;
792 guint size, min, max, prefix, alignment;
793 GstBaseTransformClass *klass;
794 const GstAllocator *allocator = NULL;
796 /* there are these possibilities:
798 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
799 * will do that whenever some upstream does an allocation query.
800 * 2) we need to do a transform, we need to get a bufferpool from downstream
801 * and configure it. When upstream does the ALLOCATION query, the
802 * propose_allocation vmethod will be called and we will configure the
803 * upstream allocator with our porposed values then.
807 oldpool = trans->priv->pool;
809 GST_DEBUG_OBJECT (trans, "unreffing old pool");
810 gst_buffer_pool_set_active (oldpool, FALSE);
811 gst_object_unref (oldpool);
812 trans->priv->pool = oldpool = NULL;
815 if (trans->passthrough || trans->always_in_place) {
816 /* we are in passthrough, the input buffer is never copied and always passed
817 * along. We never allocate an output buffer on the srcpad. What we do is
818 * let the upstream element decide if it wants to use a bufferpool and
819 * then we will proxy the downstream pool */
820 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
824 /* not passthrough, we need to allocate */
825 /* find a pool for the negotiated caps now */
826 GST_DEBUG_OBJECT (trans, "doing allocation query");
827 query = gst_query_new_allocation (outcaps, TRUE);
828 if (!gst_pad_peer_query (trans->srcpad, query)) {
829 /* not a problem, just debug a little */
830 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
833 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
835 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
836 if (G_LIKELY (klass->decide_allocation))
837 result = klass->decide_allocation (trans, query);
839 /* we got configuration from our peer, parse them */
840 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
844 const gchar *mem = NULL;
846 /* no size, we have variable size buffers */
847 if (gst_query_get_n_allocation_memories (query) > 0) {
848 mem = gst_query_parse_nth_allocation_memory (query, 0);
850 allocator = gst_allocator_find (mem);
851 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
852 } else if (pool == NULL) {
853 GstStructure *config;
855 /* we did not get a pool, make one ourselves then */
856 pool = gst_buffer_pool_new ();
858 GST_DEBUG_OBJECT (trans, "no pool, making one");
859 config = gst_buffer_pool_get_config (pool);
860 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
862 gst_buffer_pool_set_config (pool, config);
865 gst_query_unref (query);
869 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
875 /* function triggered when the in and out caps are negotiated and need
876 * to be configured in the subclass. */
878 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
882 GstBaseTransformClass *klass;
884 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
886 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
887 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
889 /* clear the cache */
890 gst_caps_replace (&trans->cache_caps1, NULL);
891 gst_caps_replace (&trans->cache_caps2, NULL);
893 /* figure out same caps state */
894 trans->have_same_caps = gst_caps_is_equal (in, out);
895 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
897 /* If we've a transform_ip method and same input/output caps, set in_place
898 * by default. If for some reason the sub-class prefers using a transform
899 * function, it can clear the in place flag in the set_caps */
900 gst_base_transform_set_in_place (trans,
901 klass->transform_ip && trans->have_same_caps);
903 /* Set the passthrough if the class wants passthrough_on_same_caps
904 * and we have the same caps on each pad */
905 if (klass->passthrough_on_same_caps)
906 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
908 /* now configure the element with the caps */
909 if (klass->set_caps) {
910 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
911 ret = klass->set_caps (trans, in, out);
914 trans->negotiated = ret;
920 gst_base_transform_default_fixate (GstBaseTransform * trans,
921 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
923 GST_DEBUG_OBJECT (trans, "using default caps fixate function");
924 gst_caps_fixate (othercaps);
927 /* given a fixed @caps on @pad, create the best possible caps for the
929 * @caps must be fixed when calling this function.
931 * This function calls the transform caps vmethod of the basetransform to figure
932 * out the possible target formats. It then tries to select the best format from
935 * - attempt passthrough if the target caps is a superset of the input caps
936 * - fixating by using peer caps
937 * - fixating with transform fixate function
938 * - fixating with pad fixate functions.
940 * this function returns a caps that can be transformed into and is accepted by
944 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
947 GstBaseTransformClass *klass;
948 GstPad *otherpad, *otherpeer;
952 /* caps must be fixed here, this is a programming error if it's not */
953 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
955 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
957 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
958 otherpeer = gst_pad_get_peer (otherpad);
960 /* see how we can transform the input caps. We need to do this even for
961 * passthrough because it might be possible that this element cannot support
962 * passthrough at all. */
963 othercaps = gst_base_transform_transform_caps (trans,
964 GST_PAD_DIRECTION (pad), caps, NULL);
966 /* The caps we can actually output is the intersection of the transformed
967 * caps with the pad template for the pad */
969 GstCaps *intersect, *templ_caps;
971 templ_caps = gst_pad_get_pad_template_caps (otherpad);
972 GST_DEBUG_OBJECT (trans,
973 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
976 gst_caps_intersect_full (othercaps, templ_caps,
977 GST_CAPS_INTERSECT_FIRST);
979 gst_caps_unref (othercaps);
980 gst_caps_unref (templ_caps);
981 othercaps = intersect;
984 /* check if transform is empty */
985 if (!othercaps || gst_caps_is_empty (othercaps))
988 /* if the othercaps are not fixed, we need to fixate them, first attempt
989 * is by attempting passthrough if the othercaps are a superset of caps. */
990 /* FIXME. maybe the caps is not fixed because it has multiple structures of
992 is_fixed = gst_caps_is_fixed (othercaps);
994 GST_DEBUG_OBJECT (trans,
995 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
997 /* Now let's see what the peer suggests based on our transformed caps */
999 GstCaps *peercaps, *intersection, *templ_caps;
1001 GST_DEBUG_OBJECT (trans,
1002 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1004 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1005 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1006 if (!gst_caps_is_empty (peercaps)) {
1007 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1009 GST_DEBUG_OBJECT (trans,
1010 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1013 gst_caps_intersect_full (peercaps, templ_caps,
1014 GST_CAPS_INTERSECT_FIRST);
1015 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1017 gst_caps_unref (peercaps);
1018 gst_caps_unref (templ_caps);
1019 peercaps = intersection;
1021 GST_DEBUG_OBJECT (trans,
1022 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1024 gst_caps_intersect_full (peercaps, othercaps,
1025 GST_CAPS_INTERSECT_FIRST);
1026 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1028 gst_caps_unref (peercaps);
1029 gst_caps_unref (othercaps);
1030 othercaps = intersection;
1032 othercaps = peercaps;
1035 is_fixed = gst_caps_is_fixed (othercaps);
1037 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1038 gst_caps_unref (othercaps);
1039 othercaps = gst_caps_ref (caps);
1043 if (gst_caps_is_empty (othercaps))
1044 goto no_transform_possible;
1046 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1049 /* second attempt at fixation, call the fixate vmethod */
1050 /* caps could be fixed but the subclass may want to add fields */
1051 if (klass->fixate_caps) {
1052 othercaps = gst_caps_make_writable (othercaps);
1054 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1055 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1056 GST_DEBUG_PAD_NAME (otherpad));
1057 /* note that we pass the complete array of structures to the fixate
1058 * function, it needs to truncate itself */
1059 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1060 is_fixed = gst_caps_is_fixed (othercaps);
1061 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1064 /* caps should be fixed now, if not we have to fail. */
1066 goto could_not_fixate;
1068 /* and peer should accept */
1069 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1070 goto peer_no_accept;
1072 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1073 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1076 gst_object_unref (otherpeer);
1083 GST_DEBUG_OBJECT (trans,
1084 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1087 no_transform_possible:
1089 GST_DEBUG_OBJECT (trans,
1090 "transform could not transform %" GST_PTR_FORMAT
1091 " in anything we support", caps);
1096 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1101 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1102 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1108 gst_object_unref (otherpeer);
1110 gst_caps_unref (othercaps);
1116 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1117 GstPadDirection direction, GstCaps * caps)
1121 GstCaps *othercaps = NULL;
1123 gboolean ret = TRUE;
1126 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1128 /* we need fixed caps for the check, fall back to the default implementation
1130 if (!gst_caps_is_fixed (caps))
1135 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1137 /* get all the formats we can handle on this pad */
1138 if (direction == GST_PAD_SRC)
1139 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1141 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1144 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1145 goto no_transform_possible;
1148 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1150 /* intersect with the requested format */
1151 ret = gst_caps_is_subset (caps, allowed);
1152 gst_caps_unref (allowed);
1155 goto no_transform_possible;
1159 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1161 /* find best possible caps for the other pad as a way to see if we can
1162 * transform this caps. */
1163 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1164 if (!othercaps || gst_caps_is_empty (othercaps))
1165 goto no_transform_possible;
1167 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1173 /* We know it's always NULL since we never use it */
1175 gst_caps_unref (othercaps);
1181 no_transform_possible:
1183 GST_DEBUG_OBJECT (trans,
1184 "transform could not transform %" GST_PTR_FORMAT
1185 " in anything we support", caps);
1191 /* called when new caps arrive on the sink or source pad,
1192 * We try to find the best caps for the other side using our _find_transform()
1193 * function. If there are caps, we configure the transform for this new
1196 * FIXME, this function is currently commutative but this should not really be
1197 * because we never set caps starting from the srcpad.
1200 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1203 GstPad *otherpad, *otherpeer;
1204 GstCaps *othercaps = NULL;
1205 gboolean ret = TRUE;
1206 GstCaps *incaps, *outcaps;
1208 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1209 otherpeer = gst_pad_get_peer (otherpad);
1211 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1213 /* find best possible caps for the other pad */
1214 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1215 if (!othercaps || gst_caps_is_empty (othercaps))
1216 goto no_transform_possible;
1218 /* configure the element now */
1219 /* make sure in and out caps are correct */
1220 if (pad == trans->sinkpad) {
1222 outcaps = othercaps;
1228 /* if we have the same caps, we can optimize and reuse the input caps */
1229 if (gst_caps_is_equal (incaps, outcaps)) {
1230 GST_INFO_OBJECT (trans, "reuse caps");
1231 gst_caps_unref (othercaps);
1232 outcaps = othercaps = gst_caps_ref (incaps);
1235 /* call configure now */
1236 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1237 goto failed_configure;
1239 GST_OBJECT_LOCK (trans->sinkpad);
1240 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1241 trans->priv->reconfigure = FALSE;
1242 GST_OBJECT_UNLOCK (trans->sinkpad);
1244 /* we know this will work, we implement the setcaps */
1245 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1247 if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_MODE_PULL) {
1249 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1251 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1257 /* try to get a pool when needed */
1258 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1263 gst_object_unref (otherpeer);
1265 gst_caps_unref (othercaps);
1267 trans->negotiated = ret;
1272 no_transform_possible:
1274 GST_WARNING_OBJECT (trans,
1275 "transform could not transform %" GST_PTR_FORMAT
1276 " in anything we support", caps);
1282 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1283 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1290 gst_base_transform_default_query (GstBaseTransform * trans,
1291 GstPadDirection direction, GstQuery * query)
1293 gboolean ret = FALSE;
1294 GstPad *pad, *otherpad;
1295 GstBaseTransformClass *klass;
1297 if (direction == GST_PAD_SRC) {
1298 pad = trans->srcpad;
1299 otherpad = trans->sinkpad;
1301 pad = trans->sinkpad;
1302 otherpad = trans->srcpad;
1305 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1307 switch (GST_QUERY_TYPE (query)) {
1308 case GST_QUERY_ALLOCATION:
1310 gboolean passthrough;
1312 /* can only be done on the sinkpad */
1313 if (direction != GST_PAD_SINK)
1316 GST_BASE_TRANSFORM_LOCK (trans);
1317 passthrough = trans->passthrough;
1318 GST_BASE_TRANSFORM_UNLOCK (trans);
1320 GST_DEBUG_OBJECT (trans, "propose allocation values");
1321 /* pass the query to the propose_allocation vmethod if any */
1322 if (G_LIKELY (klass->propose_allocation)) {
1323 ret = klass->propose_allocation (trans, query);
1324 } else if (passthrough) {
1325 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1326 ret = gst_pad_peer_query (otherpad, query);
1330 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1334 case GST_QUERY_POSITION:
1338 gst_query_parse_position (query, &format, NULL);
1339 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1343 if ((direction == GST_PAD_SINK)
1344 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1346 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1347 trans->segment.position);
1349 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1350 trans->priv->position_out);
1352 gst_query_set_position (query, format, pos);
1354 ret = gst_pad_peer_query (otherpad, query);
1358 case GST_QUERY_ACCEPT_CAPS:
1362 gst_query_parse_accept_caps (query, &caps);
1363 if (klass->accept_caps) {
1364 ret = klass->accept_caps (trans, direction, caps);
1365 gst_query_set_accept_caps_result (query, ret);
1366 /* return TRUE, we answered the query */
1371 case GST_QUERY_CAPS:
1373 GstCaps *filter, *caps;
1375 gst_query_parse_caps (query, &filter);
1376 caps = gst_base_transform_query_caps (trans, pad, filter);
1377 gst_query_set_caps_result (query, caps);
1378 gst_caps_unref (caps);
1383 ret = gst_pad_peer_query (otherpad, query);
1392 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1394 GstBaseTransform *trans;
1395 GstBaseTransformClass *bclass;
1396 gboolean ret = FALSE;
1398 trans = GST_BASE_TRANSFORM (parent);
1399 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1402 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1407 /* this function either returns the input buffer without incrementing the
1408 * refcount or it allocates a new (writable) buffer */
1409 static GstFlowReturn
1410 default_prepare_output_buffer (GstBaseTransform * trans,
1411 GstBuffer * inbuf, GstBuffer ** outbuf)
1413 GstBaseTransformPrivate *priv;
1414 GstFlowReturn ret = GST_FLOW_OK;
1415 GstBaseTransformClass *bclass;
1418 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1420 /* figure out how to allocate an output buffer */
1421 if (trans->passthrough) {
1422 /* passthrough, we will not modify the incomming buffer so we can just
1424 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1427 /* we can't reuse the input buffer */
1429 GST_DEBUG_OBJECT (trans, "using pool alloc");
1430 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1432 gsize insize, outsize;
1435 /* no pool, we need to figure out the size of the output buffer first */
1436 insize = gst_buffer_get_size (inbuf);
1438 if (trans->passthrough) {
1439 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1440 /* passthrough, the output size is the same as the input size. */
1443 gboolean want_in_place = (bclass->transform_ip != NULL)
1444 && trans->always_in_place;
1446 if (want_in_place) {
1447 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1448 /* we alloc a buffer of the same size as the input */
1451 GstCaps *incaps, *outcaps;
1453 /* else use the transform function to get the size */
1454 incaps = gst_pad_get_current_caps (trans->sinkpad);
1455 outcaps = gst_pad_get_current_caps (trans->srcpad);
1457 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1458 /* copy transform, figure out the output size */
1459 res = gst_base_transform_transform_size (trans,
1460 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1462 gst_caps_unref (incaps);
1463 gst_caps_unref (outcaps);
1469 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1471 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1479 GST_ERROR_OBJECT (trans, "unknown output size");
1480 return GST_FLOW_ERROR;
1485 default_copy_metadata (GstBaseTransform * trans,
1486 GstBuffer * inbuf, GstBuffer * outbuf)
1488 GstBaseTransformPrivate *priv = trans->priv;
1490 /* now copy the metadata */
1491 GST_DEBUG_OBJECT (trans, "copying metadata");
1493 /* this should not happen, buffers allocated from a pool or with
1494 * new_allocate should always be writable. */
1495 if (!gst_buffer_is_writable (outbuf))
1498 /* when we get here, the metadata should be writable */
1499 gst_buffer_copy_into (outbuf, inbuf,
1500 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1502 /* clear the GAP flag when the subclass does not understand it */
1503 if (!priv->gap_aware)
1504 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1511 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1516 /* Given @caps calcultate the size of one unit.
1518 * For video caps, this is the size of one frame (and thus one buffer).
1519 * For audio caps, this is the size of one sample.
1521 * These values are cached since they do not change and the calculation
1522 * potentially involves parsing caps and other expensive stuff.
1524 * We have two cache locations to store the size, one for the source caps
1525 * and one for the sink caps.
1527 * this function returns FALSE if no size could be calculated.
1530 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1533 gboolean res = FALSE;
1534 GstBaseTransformClass *bclass;
1536 /* see if we have the result cached */
1537 if (trans->cache_caps1 == caps) {
1538 *size = trans->cache_caps1_size;
1539 GST_DEBUG_OBJECT (trans,
1540 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1543 if (trans->cache_caps2 == caps) {
1544 *size = trans->cache_caps2_size;
1545 GST_DEBUG_OBJECT (trans,
1546 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1550 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1551 res = bclass->get_unit_size (trans, caps, size);
1552 GST_DEBUG_OBJECT (trans,
1553 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1554 caps, *size, res ? "TRUE" : "FALSE");
1557 /* and cache the values */
1558 if (trans->cache_caps1 == NULL) {
1559 gst_caps_replace (&trans->cache_caps1, caps);
1560 trans->cache_caps1_size = *size;
1561 GST_DEBUG_OBJECT (trans,
1562 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1563 } else if (trans->cache_caps2 == NULL) {
1564 gst_caps_replace (&trans->cache_caps2, caps);
1565 trans->cache_caps2_size = *size;
1566 GST_DEBUG_OBJECT (trans,
1567 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1569 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1576 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1579 GstBaseTransform *trans;
1580 GstBaseTransformClass *bclass;
1581 gboolean ret = TRUE;
1583 trans = GST_BASE_TRANSFORM (parent);
1584 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1586 if (bclass->sink_event)
1587 ret = bclass->sink_event (trans, event);
1589 gst_event_unref (event);
1595 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1597 gboolean ret = TRUE, forward = TRUE;
1599 switch (GST_EVENT_TYPE (event)) {
1600 case GST_EVENT_FLUSH_START:
1602 case GST_EVENT_FLUSH_STOP:
1603 GST_OBJECT_LOCK (trans);
1604 /* reset QoS parameters */
1605 trans->priv->proportion = 1.0;
1606 trans->priv->earliest_time = -1;
1607 trans->priv->discont = FALSE;
1608 trans->priv->processed = 0;
1609 trans->priv->dropped = 0;
1610 GST_OBJECT_UNLOCK (trans);
1611 /* we need new segment info after the flush. */
1612 trans->have_segment = FALSE;
1613 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1614 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1620 case GST_EVENT_CAPS:
1624 gst_event_parse_caps (event, &caps);
1625 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1630 case GST_EVENT_SEGMENT:
1632 gst_event_copy_segment (event, &trans->segment);
1633 trans->have_segment = TRUE;
1635 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1644 ret = gst_pad_push_event (trans->srcpad, event);
1646 gst_event_unref (event);
1652 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1655 GstBaseTransform *trans;
1656 GstBaseTransformClass *bclass;
1657 gboolean ret = TRUE;
1659 trans = GST_BASE_TRANSFORM (parent);
1660 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1662 if (bclass->src_event)
1663 ret = bclass->src_event (trans, event);
1665 gst_event_unref (event);
1671 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1675 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1677 switch (GST_EVENT_TYPE (event)) {
1678 case GST_EVENT_SEEK:
1680 case GST_EVENT_NAVIGATION:
1685 GstClockTimeDiff diff;
1686 GstClockTime timestamp;
1688 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1689 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1696 ret = gst_pad_push_event (trans->sinkpad, event);
1701 /* perform a transform on @inbuf and put the result in @outbuf.
1703 * This function is common to the push and pull-based operations.
1705 * This function takes ownership of @inbuf */
1706 static GstFlowReturn
1707 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1708 GstBuffer ** outbuf)
1710 GstBaseTransformClass *bclass;
1711 GstFlowReturn ret = GST_FLOW_OK;
1712 gboolean want_in_place;
1713 GstClockTime running_time;
1714 GstClockTime timestamp;
1715 gboolean reconfigure;
1717 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1719 GST_OBJECT_LOCK (trans->sinkpad);
1720 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1721 || trans->priv->reconfigure;
1722 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1723 trans->priv->reconfigure = FALSE;
1724 GST_OBJECT_UNLOCK (trans->sinkpad);
1726 if (G_UNLIKELY (reconfigure)) {
1729 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1731 incaps = gst_pad_get_current_caps (trans->sinkpad);
1733 goto no_reconfigure;
1735 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1736 * will reconfigure the transform with the new output format. We can only
1737 * do this if the buffer actually has caps. */
1738 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1739 gst_caps_unref (incaps);
1740 goto not_negotiated;
1742 gst_caps_unref (incaps);
1746 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1747 GST_DEBUG_OBJECT (trans,
1748 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1749 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1750 GST_BUFFER_OFFSET (inbuf));
1752 GST_DEBUG_OBJECT (trans,
1753 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1754 gst_buffer_get_size (inbuf));
1756 /* Don't allow buffer handling before negotiation, except in passthrough mode
1757 * or if the class doesn't implement a set_caps function (in which case it doesn't
1760 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1761 goto not_negotiated;
1763 /* Set discont flag so we can mark the outgoing buffer */
1764 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1765 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1766 trans->priv->discont = TRUE;
1769 /* can only do QoS if the segment is in TIME */
1770 if (trans->segment.format != GST_FORMAT_TIME)
1773 /* QOS is done on the running time of the buffer, get it now */
1774 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1775 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1778 if (running_time != -1) {
1780 GstClockTime earliest_time;
1783 /* lock for getting the QoS parameters that are set (in a different thread)
1784 * with the QOS events */
1785 GST_OBJECT_LOCK (trans);
1786 earliest_time = trans->priv->earliest_time;
1787 proportion = trans->priv->proportion;
1788 /* check for QoS, don't perform conversion for buffers
1789 * that are known to be late. */
1790 need_skip = trans->priv->qos_enabled &&
1791 earliest_time != -1 && running_time <= earliest_time;
1792 GST_OBJECT_UNLOCK (trans);
1795 GstMessage *qos_msg;
1796 GstClockTime duration;
1797 guint64 stream_time;
1800 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1801 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1802 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1804 trans->priv->dropped++;
1806 duration = GST_BUFFER_DURATION (inbuf);
1808 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1810 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1813 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1814 stream_time, timestamp, duration);
1815 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1816 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1817 trans->priv->processed, trans->priv->dropped);
1818 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1820 /* mark discont for next buffer */
1821 trans->priv->discont = TRUE;
1828 /* first try to allocate an output buffer based on the currently negotiated
1829 * format. outbuf will contain a buffer suitable for doing the configured
1830 * transform after this function. */
1831 if (bclass->prepare_output_buffer == NULL)
1834 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1835 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1837 if (ret != GST_FLOW_OK || *outbuf == NULL)
1840 if (inbuf == *outbuf) {
1841 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1842 } else if (trans->passthrough) {
1843 /* we are asked to perform a passthrough transform but the input and
1844 * output buffers are different. We have to discard the output buffer and
1845 * reuse the input buffer. This is rather weird, it means that the prepare
1846 * output buffer does something wrong. */
1847 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1848 "prepare_output_buffer implementation");
1849 gst_buffer_unref (*outbuf);
1852 /* copy the metadata */
1853 if (bclass->copy_metadata)
1854 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1855 /* something failed, post a warning */
1856 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1857 ("could not copy metadata"), (NULL));
1860 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1863 /* now perform the needed transform */
1864 if (trans->passthrough) {
1865 /* In passthrough mode, give transform_ip a look at the
1866 * buffer, without making it writable, or just push the
1868 if (bclass->transform_ip) {
1869 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1870 ret = bclass->transform_ip (trans, *outbuf);
1872 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1875 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1877 if (want_in_place) {
1878 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1880 if (inbuf != *outbuf) {
1881 GstMapInfo ininfo, outinfo;
1883 /* Different buffer. The data can still be the same when we are dealing
1884 * with subbuffers of the same buffer. Note that because of the FIXME in
1885 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1886 * outbuf to keep them writable */
1887 g_assert (gst_buffer_map (inbuf, &ininfo, GST_MAP_READ));
1888 g_assert (gst_buffer_map (*outbuf, &outinfo, GST_MAP_WRITE));
1890 if (ininfo.data != outinfo.data)
1891 memcpy (outinfo.data, ininfo.data, ininfo.size);
1893 gst_buffer_unmap (inbuf, &ininfo);
1894 gst_buffer_unmap (*outbuf, &outinfo);
1896 ret = bclass->transform_ip (trans, *outbuf);
1898 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1900 if (bclass->transform)
1901 ret = bclass->transform (trans, inbuf, *outbuf);
1903 ret = GST_FLOW_NOT_SUPPORTED;
1908 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1909 * the input buffer, no refcount is changed to keep the input buffer writable
1911 if (*outbuf != inbuf)
1912 gst_buffer_unref (inbuf);
1919 gst_buffer_unref (inbuf);
1921 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1922 ("not negotiated"), ("not negotiated"));
1923 return GST_FLOW_NOT_NEGOTIATED;
1927 gst_buffer_unref (inbuf);
1928 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1929 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1930 return GST_FLOW_NOT_SUPPORTED;
1934 gst_buffer_unref (inbuf);
1936 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1937 gst_flow_get_name (ret));
1942 /* FIXME, getrange is broken, need to pull range from the other
1943 * end based on the transform_size result.
1945 static GstFlowReturn
1946 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
1947 guint length, GstBuffer ** buffer)
1949 GstBaseTransform *trans;
1950 GstBaseTransformClass *klass;
1954 trans = GST_BASE_TRANSFORM (parent);
1956 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1957 if (G_UNLIKELY (ret != GST_FLOW_OK))
1960 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1961 if (klass->before_transform)
1962 klass->before_transform (trans, inbuf);
1964 GST_BASE_TRANSFORM_LOCK (trans);
1965 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1966 GST_BASE_TRANSFORM_UNLOCK (trans);
1974 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1975 gst_flow_get_name (ret));
1980 static GstFlowReturn
1981 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
1983 GstBaseTransform *trans;
1984 GstBaseTransformClass *klass;
1986 GstClockTime position = GST_CLOCK_TIME_NONE;
1987 GstClockTime timestamp, duration;
1988 GstBuffer *outbuf = NULL;
1990 trans = GST_BASE_TRANSFORM (parent);
1992 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1993 duration = GST_BUFFER_DURATION (buffer);
1995 /* calculate end position of the incoming buffer */
1996 if (timestamp != GST_CLOCK_TIME_NONE) {
1997 if (duration != GST_CLOCK_TIME_NONE)
1998 position = timestamp + duration;
2000 position = timestamp;
2003 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2004 if (klass->before_transform)
2005 klass->before_transform (trans, buffer);
2007 /* protect transform method and concurrent buffer alloc */
2008 GST_BASE_TRANSFORM_LOCK (trans);
2009 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2010 GST_BASE_TRANSFORM_UNLOCK (trans);
2012 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2013 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2014 if (outbuf != NULL) {
2015 if (ret == GST_FLOW_OK) {
2016 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2018 /* Remember last stop position */
2019 if (position != GST_CLOCK_TIME_NONE &&
2020 trans->segment.format == GST_FORMAT_TIME)
2021 trans->segment.position = position;
2023 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2024 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2025 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2026 position_out += GST_BUFFER_DURATION (outbuf);
2027 } else if (position != GST_CLOCK_TIME_NONE) {
2028 position_out = position;
2030 if (position_out != GST_CLOCK_TIME_NONE
2031 && trans->segment.format == GST_FORMAT_TIME)
2032 trans->priv->position_out = position_out;
2034 /* apply DISCONT flag if the buffer is not yet marked as such */
2035 if (trans->priv->discont) {
2036 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2037 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2038 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2039 outbuf = gst_buffer_make_writable (outbuf);
2040 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2042 trans->priv->discont = FALSE;
2044 trans->priv->processed++;
2046 ret = gst_pad_push (trans->srcpad, outbuf);
2048 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2049 gst_buffer_unref (outbuf);
2053 /* convert internal flow to OK and mark discont for the next buffer. */
2054 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2055 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2056 trans->priv->discont = TRUE;
2064 gst_base_transform_set_property (GObject * object, guint prop_id,
2065 const GValue * value, GParamSpec * pspec)
2067 GstBaseTransform *trans;
2069 trans = GST_BASE_TRANSFORM (object);
2073 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2076 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2082 gst_base_transform_get_property (GObject * object, guint prop_id,
2083 GValue * value, GParamSpec * pspec)
2085 GstBaseTransform *trans;
2087 trans = GST_BASE_TRANSFORM (object);
2091 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2094 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2099 /* not a vmethod of anything, just an internal method */
2101 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2103 GstBaseTransformClass *bclass;
2104 gboolean result = TRUE;
2106 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2109 GstCaps *incaps, *outcaps;
2111 if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2112 result &= bclass->start (trans);
2114 incaps = gst_pad_get_current_caps (trans->sinkpad);
2115 outcaps = gst_pad_get_current_caps (trans->srcpad);
2117 GST_OBJECT_LOCK (trans);
2118 if (incaps && outcaps)
2119 trans->have_same_caps =
2120 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2122 trans->have_same_caps = trans->passthrough;
2123 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2124 trans->negotiated = FALSE;
2125 trans->have_segment = FALSE;
2126 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2127 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2128 trans->priv->proportion = 1.0;
2129 trans->priv->earliest_time = -1;
2130 trans->priv->discont = FALSE;
2131 trans->priv->processed = 0;
2132 trans->priv->dropped = 0;
2133 GST_OBJECT_UNLOCK (trans);
2136 gst_caps_unref (incaps);
2138 gst_caps_unref (outcaps);
2140 /* We must make sure streaming has finished before resetting things
2141 * and calling the ::stop vfunc */
2142 GST_PAD_STREAM_LOCK (trans->sinkpad);
2143 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2145 trans->have_same_caps = FALSE;
2146 /* We can only reset the passthrough mode if the instance told us to
2147 handle it in configure_caps */
2148 if (bclass->passthrough_on_same_caps) {
2149 gst_base_transform_set_passthrough (trans, FALSE);
2151 gst_caps_replace (&trans->cache_caps1, NULL);
2152 gst_caps_replace (&trans->cache_caps2, NULL);
2154 if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2155 result &= bclass->stop (trans);
2157 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2164 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2165 GstPadMode mode, gboolean active)
2167 gboolean result = FALSE;
2168 GstBaseTransform *trans;
2170 trans = GST_BASE_TRANSFORM (parent);
2173 case GST_PAD_MODE_PUSH:
2175 result = gst_base_transform_activate (trans, active);
2178 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2190 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2191 GstPadMode mode, gboolean active)
2193 gboolean result = FALSE;
2194 GstBaseTransform *trans;
2196 trans = GST_BASE_TRANSFORM (parent);
2199 case GST_PAD_MODE_PULL:
2202 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2205 result &= gst_base_transform_activate (trans, active);
2208 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2220 * gst_base_transform_set_passthrough:
2221 * @trans: the #GstBaseTransform to set
2222 * @passthrough: boolean indicating passthrough mode.
2224 * Set passthrough mode for this filter by default. This is mostly
2225 * useful for filters that do not care about negotiation.
2227 * Always TRUE for filters which don't implement either a transform
2228 * or transform_ip method.
2233 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2234 gboolean passthrough)
2236 GstBaseTransformClass *bclass;
2238 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2240 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2242 GST_OBJECT_LOCK (trans);
2243 if (passthrough == FALSE) {
2244 if (bclass->transform_ip || bclass->transform)
2245 trans->passthrough = FALSE;
2247 trans->passthrough = TRUE;
2250 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2251 GST_OBJECT_UNLOCK (trans);
2255 * gst_base_transform_is_passthrough:
2256 * @trans: the #GstBaseTransform to query
2258 * See if @trans is configured as a passthrough transform.
2260 * Returns: TRUE is the transform is configured in passthrough mode.
2265 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2269 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2271 GST_OBJECT_LOCK (trans);
2272 result = trans->passthrough;
2273 GST_OBJECT_UNLOCK (trans);
2279 * gst_base_transform_set_in_place:
2280 * @trans: the #GstBaseTransform to modify
2281 * @in_place: Boolean value indicating that we would like to operate
2282 * on in_place buffers.
2284 * Determines whether a non-writable buffer will be copied before passing
2285 * to the transform_ip function.
2287 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2288 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2294 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2296 GstBaseTransformClass *bclass;
2298 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2300 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2302 GST_OBJECT_LOCK (trans);
2305 if (bclass->transform_ip) {
2306 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2307 trans->always_in_place = TRUE;
2310 if (bclass->transform) {
2311 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2312 trans->always_in_place = FALSE;
2316 GST_OBJECT_UNLOCK (trans);
2320 * gst_base_transform_is_in_place:
2321 * @trans: the #GstBaseTransform to query
2323 * See if @trans is configured as a in_place transform.
2325 * Returns: TRUE is the transform is configured in in_place mode.
2330 gst_base_transform_is_in_place (GstBaseTransform * trans)
2334 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2336 GST_OBJECT_LOCK (trans);
2337 result = trans->always_in_place;
2338 GST_OBJECT_UNLOCK (trans);
2344 * gst_base_transform_update_qos:
2345 * @trans: a #GstBaseTransform
2346 * @proportion: the proportion
2347 * @diff: the diff against the clock
2348 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2351 * Set the QoS parameters in the transform. This function is called internally
2352 * when a QOS event is received but subclasses can provide custom information
2360 gst_base_transform_update_qos (GstBaseTransform * trans,
2361 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2364 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2366 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2367 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2368 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2370 GST_OBJECT_LOCK (trans);
2371 trans->priv->proportion = proportion;
2372 trans->priv->earliest_time = timestamp + diff;
2373 GST_OBJECT_UNLOCK (trans);
2377 * gst_base_transform_set_qos_enabled:
2378 * @trans: a #GstBaseTransform
2379 * @enabled: new state
2381 * Enable or disable QoS handling in the transform.
2388 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2390 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2392 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2394 GST_OBJECT_LOCK (trans);
2395 trans->priv->qos_enabled = enabled;
2396 GST_OBJECT_UNLOCK (trans);
2400 * gst_base_transform_is_qos_enabled:
2401 * @trans: a #GstBaseTransform
2403 * Queries if the transform will handle QoS.
2405 * Returns: TRUE if QoS is enabled.
2412 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2416 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2418 GST_OBJECT_LOCK (trans);
2419 result = trans->priv->qos_enabled;
2420 GST_OBJECT_UNLOCK (trans);
2426 * gst_base_transform_set_gap_aware:
2427 * @trans: a #GstBaseTransform
2428 * @gap_aware: New state
2430 * If @gap_aware is %FALSE (the default), output buffers will have the
2431 * %GST_BUFFER_FLAG_GAP flag unset.
2433 * If set to %TRUE, the element must handle output buffers with this flag set
2434 * correctly, i.e. it can assume that the buffer contains neutral data but must
2435 * unset the flag if the output is no neutral data.
2442 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2444 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2446 GST_OBJECT_LOCK (trans);
2447 trans->priv->gap_aware = gap_aware;
2448 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2449 GST_OBJECT_UNLOCK (trans);
2453 * gst_base_transform_suggest:
2454 * @trans: a #GstBaseTransform
2455 * @caps: (transfer none): caps to suggest
2456 * @size: buffer size to suggest
2458 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2464 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2467 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2469 /* push the renegotiate event */
2470 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2471 gst_event_new_reconfigure ()))
2472 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2476 * gst_base_transform_reconfigure:
2477 * @trans: a #GstBaseTransform
2479 * Instructs @trans to renegotiate a new downstream transform on the next
2480 * buffer. This function is typically called after properties on the transform
2481 * were set that influence the output format.
2486 gst_base_transform_reconfigure (GstBaseTransform * trans)
2488 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2490 GST_OBJECT_LOCK (trans);
2491 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2492 trans->priv->reconfigure = TRUE;
2493 GST_OBJECT_UNLOCK (trans);