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 "gstbasetransform.h"
211 #include <gst/gstmarshal.h>
213 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
214 #define GST_CAT_DEFAULT gst_base_transform_debug
216 /* BaseTransform signals and args */
223 #define DEFAULT_PROP_QOS FALSE
231 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
232 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
234 struct _GstBaseTransformPrivate
236 /* QoS *//* with LOCK */
237 gboolean qos_enabled;
239 GstClockTime earliest_time;
240 /* previous buffer had a discont */
243 GstPadActivateMode pad_mode;
247 gboolean reconfigure;
253 GstClockTime position_out;
256 const GstAllocator *allocator;
262 static GstElementClass *parent_class = NULL;
264 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
265 static void gst_base_transform_init (GstBaseTransform * trans,
266 GstBaseTransformClass * klass);
268 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
269 * method to get to the padtemplates */
271 gst_base_transform_get_type (void)
273 static volatile gsize base_transform_type = 0;
275 if (g_once_init_enter (&base_transform_type)) {
277 static const GTypeInfo base_transform_info = {
278 sizeof (GstBaseTransformClass),
281 (GClassInitFunc) gst_base_transform_class_init,
284 sizeof (GstBaseTransform),
286 (GInstanceInitFunc) gst_base_transform_init,
289 _type = g_type_register_static (GST_TYPE_ELEMENT,
290 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
291 g_once_init_leave (&base_transform_type, _type);
293 return base_transform_type;
296 static void gst_base_transform_finalize (GObject * object);
297 static void gst_base_transform_set_property (GObject * object, guint prop_id,
298 const GValue * value, GParamSpec * pspec);
299 static void gst_base_transform_get_property (GObject * object, guint prop_id,
300 GValue * value, GParamSpec * pspec);
301 static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
303 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
305 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
307 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
308 GstCaps * caps, gsize * size);
310 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
311 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
313 static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
314 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
316 static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
317 guint length, GstBuffer ** buffer);
318 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
320 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
321 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
322 static void gst_base_transform_default_fixate (GstBaseTransform * trans,
323 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
324 static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
325 GstPad * pad, GstCaps * filter);
326 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
327 GstPadDirection direction, GstCaps * caps);
328 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
329 GstPad * pad, GstCaps * caps);
330 static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
331 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
332 GstPadDirection direction, GstQuery * query);
333 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
334 trans, GstPadDirection direction, GstCaps * caps, gsize size,
335 GstCaps * othercaps, gsize * othersize);
337 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
338 GstBuffer * inbuf, GstBuffer ** outbuf);
339 static gboolean default_copy_metadata (GstBaseTransform * trans,
340 GstBuffer * inbuf, GstBuffer * outbuf);
342 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
346 gst_base_transform_finalize (GObject * object)
348 GstBaseTransform *trans;
350 trans = GST_BASE_TRANSFORM (object);
352 g_mutex_free (trans->transform_lock);
354 G_OBJECT_CLASS (parent_class)->finalize (object);
358 gst_base_transform_class_init (GstBaseTransformClass * klass)
360 GObjectClass *gobject_class;
362 gobject_class = G_OBJECT_CLASS (klass);
364 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
365 "basetransform element");
367 GST_DEBUG ("gst_base_transform_class_init");
369 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
371 parent_class = g_type_class_peek_parent (klass);
373 gobject_class->set_property = gst_base_transform_set_property;
374 gobject_class->get_property = gst_base_transform_get_property;
376 g_object_class_install_property (gobject_class, PROP_QOS,
377 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
378 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
380 gobject_class->finalize = gst_base_transform_finalize;
382 klass->passthrough_on_same_caps = FALSE;
384 klass->transform_caps =
385 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
386 klass->fixate_caps = GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate);
388 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
389 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
390 klass->transform_size =
391 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
393 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
394 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
395 klass->prepare_output_buffer =
396 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
397 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
401 gst_base_transform_init (GstBaseTransform * trans,
402 GstBaseTransformClass * bclass)
404 GstPadTemplate *pad_template;
406 GST_DEBUG ("gst_base_transform_init");
408 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
411 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
412 g_return_if_fail (pad_template != NULL);
413 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
414 gst_pad_set_event_function (trans->sinkpad,
415 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
416 gst_pad_set_chain_function (trans->sinkpad,
417 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
418 gst_pad_set_activatepush_function (trans->sinkpad,
419 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
420 gst_pad_set_query_function (trans->sinkpad,
421 GST_DEBUG_FUNCPTR (gst_base_transform_query));
422 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
425 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
426 g_return_if_fail (pad_template != NULL);
427 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
428 gst_pad_set_event_function (trans->srcpad,
429 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
430 gst_pad_set_getrange_function (trans->srcpad,
431 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
432 gst_pad_set_activatepull_function (trans->srcpad,
433 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
434 gst_pad_set_query_function (trans->srcpad,
435 GST_DEBUG_FUNCPTR (gst_base_transform_query));
436 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
438 trans->transform_lock = g_mutex_new ();
439 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
440 trans->cache_caps1 = NULL;
441 trans->cache_caps2 = NULL;
442 trans->priv->pad_mode = GST_PAD_ACTIVATE_NONE;
443 trans->priv->gap_aware = FALSE;
445 trans->passthrough = FALSE;
446 if (bclass->transform == NULL) {
447 /* If no transform function, always_in_place is TRUE */
448 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
449 trans->always_in_place = TRUE;
451 if (bclass->transform_ip == NULL) {
452 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
453 trans->passthrough = TRUE;
457 trans->priv->processed = 0;
458 trans->priv->dropped = 0;
462 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
463 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
467 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
468 /* no transform function, use the identity transform */
470 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
472 ret = gst_caps_ref (caps);
477 /* given @caps on the src or sink pad (given by @direction)
478 * calculate the possible caps on the other pad.
480 * Returns new caps, unref after usage.
483 gst_base_transform_transform_caps (GstBaseTransform * trans,
484 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
487 GstBaseTransformClass *klass;
492 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
494 /* if there is a custom transform function, use this */
495 if (klass->transform_caps) {
496 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
498 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
499 ret = klass->transform_caps (trans, direction, caps, filter);
500 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
502 #ifndef G_DISABLE_ASSERT
504 if (!gst_caps_is_subset (ret, filter)) {
505 GstCaps *intersection;
507 GST_ERROR_OBJECT (trans,
508 "transform_caps returned caps %" GST_PTR_FORMAT
509 " which are not a real subset of the filter caps %"
510 GST_PTR_FORMAT, ret, filter);
511 g_warning ("%s: transform_caps returned caps which are not a real "
512 "subset of the filter caps", GST_ELEMENT_NAME (trans));
515 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
516 gst_caps_unref (ret);
523 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
529 gst_base_transform_default_transform_size (GstBaseTransform * trans,
530 GstPadDirection direction, GstCaps * caps, gsize size,
531 GstCaps * othercaps, gsize * othersize)
533 gsize inunitsize, outunitsize, units;
534 GstBaseTransformClass *klass;
536 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
538 if (klass->get_unit_size == NULL) {
539 /* if there is no transform_size and no unit_size, it means the
540 * element does not modify the size of a buffer */
543 /* there is no transform_size function, we have to use the unit_size
544 * functions. This method assumes there is a fixed unit_size associated with
545 * each caps. We provide the same amount of units on both sides. */
546 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
549 GST_DEBUG_OBJECT (trans,
550 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
553 /* input size must be a multiple of the unit_size of the input caps */
554 if (inunitsize == 0 || (size % inunitsize != 0))
557 /* get the amount of units */
558 units = size / inunitsize;
560 /* now get the unit size of the output */
561 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
564 /* the output size is the unit_size times the amount of units on the
566 *othersize = units * outunitsize;
567 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
575 GST_DEBUG_OBJECT (trans, "could not get in_size");
576 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
581 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
582 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
583 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
584 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
589 GST_DEBUG_OBJECT (trans, "could not get out_size");
590 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
595 /* transform a buffer of @size with @caps on the pad with @direction to
596 * the size of a buffer with @othercaps and store the result in @othersize
598 * We have two ways of doing this:
599 * 1) use a custom transform size function, this is for complicated custom
600 * cases with no fixed unit_size.
601 * 2) use the unit_size functions where there is a relationship between the
602 * caps and the size of a buffer.
605 gst_base_transform_transform_size (GstBaseTransform * trans,
606 GstPadDirection direction, GstCaps * caps,
607 gsize size, GstCaps * othercaps, gsize * othersize)
609 GstBaseTransformClass *klass;
610 gboolean ret = FALSE;
612 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
614 GST_DEBUG_OBJECT (trans,
615 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
616 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
617 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
619 if (klass->transform_size) {
620 /* if there is a custom transform function, use this */
621 ret = klass->transform_size (trans, direction, caps, size, othercaps,
627 /* get the caps that can be handled by @pad. We perform:
629 * - take the caps of peer of otherpad,
630 * - filter against the padtemplate of otherpad,
631 * - calculate all transforms of remaining caps
632 * - filter against template of @pad
634 * If there is no peer, we simply return the caps of the padtemplate of pad.
637 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
641 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
644 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
646 /* we can do what the peer can */
649 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
651 /* filtered against our padtemplate on the other side */
652 templ = gst_pad_get_pad_template_caps (pad);
653 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
654 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
655 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
656 gst_caps_unref (templ);
658 /* then see what we can transform this to */
659 peerfilter = gst_base_transform_transform_caps (trans,
660 GST_PAD_DIRECTION (pad), temp, NULL);
661 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
662 gst_caps_unref (temp);
664 /* and filter against the template of this pad */
665 templ = gst_pad_get_pad_template_caps (otherpad);
666 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
667 /* We keep the caps sorted like the returned caps */
669 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
670 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
671 gst_caps_unref (peerfilter);
672 gst_caps_unref (templ);
676 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
679 gst_caps_unref (peerfilter);
682 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
684 /* filtered against our padtemplate on the other side */
685 templ = gst_pad_get_pad_template_caps (otherpad);
686 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
687 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
688 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
689 gst_caps_unref (templ);
691 temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
694 /* then see what we can transform this to */
695 caps = gst_base_transform_transform_caps (trans,
696 GST_PAD_DIRECTION (otherpad), temp, filter);
697 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
698 gst_caps_unref (temp);
703 /* and filter against the template of this pad */
704 templ = gst_pad_get_pad_template_caps (pad);
705 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
706 /* We keep the caps sorted like the returned caps */
707 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
708 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
709 gst_caps_unref (caps);
710 gst_caps_unref (templ);
713 /* Now try if we can put the untransformed downstream caps first */
714 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
715 if (!gst_caps_is_empty (temp)) {
716 gst_caps_merge (temp, caps);
719 gst_caps_unref (temp);
722 gst_caps_unref (caps);
723 /* no peer or the peer can do anything, our padtemplate is enough then */
724 caps = gst_pad_get_pad_template_caps (pad);
729 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
730 gst_caps_unref (caps);
736 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
739 gst_caps_unref (peercaps);
745 gst_base_transform_set_allocation (GstBaseTransform * trans,
746 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
749 GstBufferPool *oldpool;
750 GstBaseTransformPrivate *priv = trans->priv;
754 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
755 if (!gst_buffer_pool_set_active (pool, TRUE))
756 goto activate_failed;
759 GST_OBJECT_LOCK (trans);
760 oldpool = priv->pool;
762 priv->allocator = allocator;
763 priv->prefix = prefix;
764 priv->alignment = alignment;
765 GST_OBJECT_UNLOCK (trans);
768 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
769 gst_buffer_pool_set_active (oldpool, FALSE);
770 gst_object_unref (oldpool);
777 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
783 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
786 gboolean result = TRUE;
787 GstBufferPool *pool = NULL, *oldpool;
788 guint size, min, max, prefix, alignment;
789 GstBaseTransformClass *klass;
790 const GstAllocator *allocator = NULL;
792 /* there are these possibilities:
794 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
795 * will do that whenever some upstream does an allocation query.
796 * 2) we need to do a transform, we need to get a bufferpool from downstream
797 * and configure it. When upstream does the ALLOCATION query, the
798 * propose_allocation vmethod will be called and we will configure the
799 * upstream allocator with our porposed values then.
803 oldpool = trans->priv->pool;
805 GST_DEBUG_OBJECT (trans, "unreffing old pool");
806 gst_buffer_pool_set_active (oldpool, FALSE);
807 gst_object_unref (oldpool);
808 trans->priv->pool = oldpool = NULL;
811 if (trans->passthrough || trans->always_in_place) {
812 /* we are in passthrough, the input buffer is never copied and always passed
813 * along. We never allocate an output buffer on the srcpad. What we do is
814 * let the upstream element decide if it wants to use a bufferpool and
815 * then we will proxy the downstream pool */
816 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
820 /* not passthrough, we need to allocate */
821 /* find a pool for the negotiated caps now */
822 GST_DEBUG_OBJECT (trans, "doing allocation query");
823 query = gst_query_new_allocation (outcaps, TRUE);
824 if (!gst_pad_peer_query (trans->srcpad, query)) {
825 /* not a problem, just debug a little */
826 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
829 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
831 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
832 if (G_LIKELY (klass->decide_allocation))
833 result = klass->decide_allocation (trans, query);
835 /* we got configuration from our peer, parse them */
836 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
840 const gchar *mem = NULL;
842 /* no size, we have variable size buffers */
843 if (gst_query_get_n_allocation_memories (query) > 0) {
844 mem = gst_query_parse_nth_allocation_memory (query, 0);
846 allocator = gst_allocator_find (mem);
847 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
848 } else if (pool == NULL) {
849 GstStructure *config;
851 /* we did not get a pool, make one ourselves then */
852 pool = gst_buffer_pool_new ();
854 GST_DEBUG_OBJECT (trans, "no pool, making one");
855 config = gst_buffer_pool_get_config (pool);
856 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
858 gst_buffer_pool_set_config (pool, config);
861 gst_query_unref (query);
865 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
871 /* function triggered when the in and out caps are negotiated and need
872 * to be configured in the subclass. */
874 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
878 GstBaseTransformClass *klass;
880 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
882 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
883 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
885 /* clear the cache */
886 gst_caps_replace (&trans->cache_caps1, NULL);
887 gst_caps_replace (&trans->cache_caps2, NULL);
889 /* figure out same caps state */
890 trans->have_same_caps = gst_caps_is_equal (in, out);
891 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
893 /* If we've a transform_ip method and same input/output caps, set in_place
894 * by default. If for some reason the sub-class prefers using a transform
895 * function, it can clear the in place flag in the set_caps */
896 gst_base_transform_set_in_place (trans,
897 klass->transform_ip && trans->have_same_caps);
899 /* Set the passthrough if the class wants passthrough_on_same_caps
900 * and we have the same caps on each pad */
901 if (klass->passthrough_on_same_caps)
902 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
904 /* now configure the element with the caps */
905 if (klass->set_caps) {
906 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
907 ret = klass->set_caps (trans, in, out);
910 trans->negotiated = ret;
916 gst_base_transform_default_fixate (GstBaseTransform * trans,
917 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
919 GST_DEBUG_OBJECT (trans, "using default caps fixate function");
920 gst_caps_fixate (othercaps);
923 /* given a fixed @caps on @pad, create the best possible caps for the
925 * @caps must be fixed when calling this function.
927 * This function calls the transform caps vmethod of the basetransform to figure
928 * out the possible target formats. It then tries to select the best format from
931 * - attempt passthrough if the target caps is a superset of the input caps
932 * - fixating by using peer caps
933 * - fixating with transform fixate function
934 * - fixating with pad fixate functions.
936 * this function returns a caps that can be transformed into and is accepted by
940 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
943 GstBaseTransformClass *klass;
944 GstPad *otherpad, *otherpeer;
948 /* caps must be fixed here, this is a programming error if it's not */
949 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
951 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
953 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
954 otherpeer = gst_pad_get_peer (otherpad);
956 /* see how we can transform the input caps. We need to do this even for
957 * passthrough because it might be possible that this element cannot support
958 * passthrough at all. */
959 othercaps = gst_base_transform_transform_caps (trans,
960 GST_PAD_DIRECTION (pad), caps, NULL);
962 /* The caps we can actually output is the intersection of the transformed
963 * caps with the pad template for the pad */
965 GstCaps *intersect, *templ_caps;
967 templ_caps = gst_pad_get_pad_template_caps (otherpad);
968 GST_DEBUG_OBJECT (trans,
969 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
972 gst_caps_intersect_full (othercaps, templ_caps,
973 GST_CAPS_INTERSECT_FIRST);
975 gst_caps_unref (othercaps);
976 gst_caps_unref (templ_caps);
977 othercaps = intersect;
980 /* check if transform is empty */
981 if (!othercaps || gst_caps_is_empty (othercaps))
984 /* if the othercaps are not fixed, we need to fixate them, first attempt
985 * is by attempting passthrough if the othercaps are a superset of caps. */
986 /* FIXME. maybe the caps is not fixed because it has multiple structures of
988 is_fixed = gst_caps_is_fixed (othercaps);
990 GST_DEBUG_OBJECT (trans,
991 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
993 /* Now let's see what the peer suggests based on our transformed caps */
995 GstCaps *peercaps, *intersection, *templ_caps;
997 GST_DEBUG_OBJECT (trans,
998 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1000 peercaps = gst_pad_get_caps (otherpeer, othercaps);
1001 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1003 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1005 GST_DEBUG_OBJECT (trans,
1006 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1009 gst_caps_intersect_full (peercaps, templ_caps,
1010 GST_CAPS_INTERSECT_FIRST);
1011 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1012 gst_caps_unref (peercaps);
1013 gst_caps_unref (templ_caps);
1014 peercaps = intersection;
1016 GST_DEBUG_OBJECT (trans,
1017 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1019 gst_caps_intersect_full (peercaps, othercaps,
1020 GST_CAPS_INTERSECT_FIRST);
1021 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1022 gst_caps_unref (peercaps);
1023 gst_caps_unref (othercaps);
1024 othercaps = intersection;
1025 is_fixed = gst_caps_is_fixed (othercaps);
1027 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1028 gst_caps_unref (othercaps);
1029 othercaps = gst_caps_ref (caps);
1033 if (gst_caps_is_empty (othercaps))
1034 goto no_transform_possible;
1036 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1039 /* second attempt at fixation, call the fixate vmethod */
1040 /* caps could be fixed but the subclass may want to add fields */
1041 if (klass->fixate_caps) {
1042 othercaps = gst_caps_make_writable (othercaps);
1044 GST_DEBUG_OBJECT (trans, "calling faxate_caps for %" GST_PTR_FORMAT
1045 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1046 GST_DEBUG_PAD_NAME (otherpad));
1047 /* note that we pass the complete array of structures to the fixate
1048 * function, it needs to truncate itself */
1049 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1050 is_fixed = gst_caps_is_fixed (othercaps);
1051 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1054 /* caps should be fixed now, if not we have to fail. */
1056 goto could_not_fixate;
1058 /* and peer should accept */
1059 if (otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
1060 goto peer_no_accept;
1062 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1063 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1066 gst_object_unref (otherpeer);
1073 GST_DEBUG_OBJECT (trans,
1074 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1077 no_transform_possible:
1079 GST_DEBUG_OBJECT (trans,
1080 "transform could not transform %" GST_PTR_FORMAT
1081 " in anything we support", caps);
1086 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1091 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1092 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1098 gst_object_unref (otherpeer);
1100 gst_caps_unref (othercaps);
1106 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1107 GstPadDirection direction, GstCaps * caps)
1111 GstCaps *othercaps = NULL;
1113 gboolean ret = TRUE;
1116 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1118 /* we need fixed caps for the check, fall back to the default implementation
1120 if (!gst_caps_is_fixed (caps))
1125 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1127 /* get all the formats we can handle on this pad */
1128 if (direction == GST_PAD_SRC)
1129 allowed = gst_pad_get_caps (trans->srcpad, NULL);
1131 allowed = gst_pad_get_caps (trans->sinkpad, NULL);
1134 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1135 goto no_transform_possible;
1138 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1140 /* intersect with the requested format */
1141 ret = gst_caps_is_subset (caps, allowed);
1142 gst_caps_unref (allowed);
1145 goto no_transform_possible;
1149 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1151 /* find best possible caps for the other pad as a way to see if we can
1152 * transform this caps. */
1153 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1154 if (!othercaps || gst_caps_is_empty (othercaps))
1155 goto no_transform_possible;
1157 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1163 /* We know it's always NULL since we never use it */
1165 gst_caps_unref (othercaps);
1171 no_transform_possible:
1173 GST_DEBUG_OBJECT (trans,
1174 "transform could not transform %" GST_PTR_FORMAT
1175 " in anything we support", caps);
1181 /* called when new caps arrive on the sink or source pad,
1182 * We try to find the best caps for the other side using our _find_transform()
1183 * function. If there are caps, we configure the transform for this new
1186 * FIXME, this function is currently commutative but this should not really be
1187 * because we never set caps starting from the srcpad.
1190 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1193 GstPad *otherpad, *otherpeer;
1194 GstCaps *othercaps = NULL;
1195 gboolean ret = TRUE;
1196 GstCaps *incaps, *outcaps;
1198 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1199 otherpeer = gst_pad_get_peer (otherpad);
1201 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1203 /* find best possible caps for the other pad */
1204 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1205 if (!othercaps || gst_caps_is_empty (othercaps))
1206 goto no_transform_possible;
1208 /* configure the element now */
1209 /* make sure in and out caps are correct */
1210 if (pad == trans->sinkpad) {
1212 outcaps = othercaps;
1218 /* if we have the same caps, we can optimize and reuse the input caps */
1219 if (gst_caps_is_equal (incaps, outcaps)) {
1220 GST_INFO_OBJECT (trans, "reuse caps");
1221 gst_caps_unref (othercaps);
1222 outcaps = othercaps = gst_caps_ref (incaps);
1225 /* call configure now */
1226 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1227 goto failed_configure;
1229 GST_OBJECT_LOCK (trans->sinkpad);
1230 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1231 trans->priv->reconfigure = FALSE;
1232 GST_OBJECT_UNLOCK (trans->sinkpad);
1234 /* we know this will work, we implement the setcaps */
1235 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1237 if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_ACTIVATE_PULL) {
1239 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1241 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1247 /* try to get a pool when needed */
1248 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1253 gst_object_unref (otherpeer);
1255 gst_caps_unref (othercaps);
1257 trans->negotiated = ret;
1262 no_transform_possible:
1264 GST_WARNING_OBJECT (trans,
1265 "transform could not transform %" GST_PTR_FORMAT
1266 " in anything we support", caps);
1272 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1273 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1280 gst_base_transform_default_query (GstBaseTransform * trans,
1281 GstPadDirection direction, GstQuery * query)
1283 gboolean ret = FALSE;
1284 GstPad *pad, *otherpad;
1285 GstBaseTransformClass *klass;
1287 if (direction == GST_PAD_SRC) {
1288 pad = trans->srcpad;
1289 otherpad = trans->sinkpad;
1291 pad = trans->sinkpad;
1292 otherpad = trans->srcpad;
1295 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1297 switch (GST_QUERY_TYPE (query)) {
1298 case GST_QUERY_ALLOCATION:
1300 gboolean passthrough;
1302 /* can only be done on the sinkpad */
1303 if (direction != GST_PAD_SINK)
1306 GST_BASE_TRANSFORM_LOCK (trans);
1307 passthrough = trans->passthrough || trans->always_in_place;
1308 GST_BASE_TRANSFORM_UNLOCK (trans);
1311 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1312 ret = gst_pad_peer_query (otherpad, query);
1314 GST_DEBUG_OBJECT (trans, "propose allocation values");
1315 /* pass the query to the propose_allocation vmethod if any */
1316 if (G_LIKELY (klass->propose_allocation))
1317 ret = klass->propose_allocation (trans, query);
1321 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1325 case GST_QUERY_POSITION:
1329 gst_query_parse_position (query, &format, NULL);
1330 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1334 if ((direction == GST_PAD_SINK)
1335 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1337 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1338 trans->segment.position);
1340 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1341 trans->priv->position_out);
1343 gst_query_set_position (query, format, pos);
1345 ret = gst_pad_peer_query (otherpad, query);
1349 case GST_QUERY_ACCEPT_CAPS:
1353 gst_query_parse_accept_caps (query, &caps);
1354 if (klass->accept_caps) {
1355 ret = klass->accept_caps (trans, direction, caps);
1356 gst_query_set_accept_caps_result (query, ret);
1357 /* return TRUE, we answered the query */
1362 case GST_QUERY_CAPS:
1364 GstCaps *filter, *caps;
1366 gst_query_parse_caps (query, &filter);
1367 caps = gst_base_transform_query_caps (trans, pad, filter);
1368 gst_query_set_caps_result (query, caps);
1369 gst_caps_unref (caps);
1374 ret = gst_pad_peer_query (otherpad, query);
1383 gst_base_transform_query (GstPad * pad, GstQuery * query)
1385 GstBaseTransform *trans;
1386 GstBaseTransformClass *bclass;
1387 gboolean ret = FALSE;
1389 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1390 if (G_UNLIKELY (trans == NULL))
1393 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1396 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1398 gst_object_unref (trans);
1403 /* this function either returns the input buffer without incrementing the
1404 * refcount or it allocates a new (writable) buffer */
1405 static GstFlowReturn
1406 default_prepare_output_buffer (GstBaseTransform * trans,
1407 GstBuffer * inbuf, GstBuffer ** outbuf)
1409 GstBaseTransformPrivate *priv;
1410 GstFlowReturn ret = GST_FLOW_OK;
1411 GstBaseTransformClass *bclass;
1414 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1416 /* figure out how to allocate an output buffer */
1417 if (trans->passthrough) {
1418 /* passthrough, we will not modify the incomming buffer so we can just
1420 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1423 /* we can't reuse the input buffer */
1425 GST_DEBUG_OBJECT (trans, "using pool alloc");
1426 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1428 gsize insize, outsize;
1431 /* no pool, we need to figure out the size of the output buffer first */
1432 insize = gst_buffer_get_size (inbuf);
1434 if (trans->passthrough) {
1435 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1436 /* passthrough, the output size is the same as the input size. */
1439 gboolean want_in_place = (bclass->transform_ip != NULL)
1440 && trans->always_in_place;
1442 if (want_in_place) {
1443 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1444 /* we alloc a buffer of the same size as the input */
1447 GstCaps *incaps, *outcaps;
1449 /* else use the transform function to get the size */
1450 incaps = gst_pad_get_current_caps (trans->sinkpad);
1451 outcaps = gst_pad_get_current_caps (trans->srcpad);
1453 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1454 /* copy transform, figure out the output size */
1455 res = gst_base_transform_transform_size (trans,
1456 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1458 gst_caps_unref (incaps);
1459 gst_caps_unref (outcaps);
1465 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1467 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1475 GST_ERROR_OBJECT (trans, "unknown output size");
1476 return GST_FLOW_ERROR;
1481 default_copy_metadata (GstBaseTransform * trans,
1482 GstBuffer * inbuf, GstBuffer * outbuf)
1484 GstBaseTransformPrivate *priv = trans->priv;
1486 /* now copy the metadata */
1487 GST_DEBUG_OBJECT (trans, "copying metadata");
1489 /* this should not happen, buffers allocated from a pool or with
1490 * new_allocate should always be writable. */
1491 if (!gst_buffer_is_writable (outbuf))
1494 /* when we get here, the metadata should be writable */
1495 gst_buffer_copy_into (outbuf, inbuf,
1496 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1498 /* clear the GAP flag when the subclass does not understand it */
1499 if (!priv->gap_aware)
1500 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1507 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1512 /* Given @caps calcultate the size of one unit.
1514 * For video caps, this is the size of one frame (and thus one buffer).
1515 * For audio caps, this is the size of one sample.
1517 * These values are cached since they do not change and the calculation
1518 * potentially involves parsing caps and other expensive stuff.
1520 * We have two cache locations to store the size, one for the source caps
1521 * and one for the sink caps.
1523 * this function returns FALSE if no size could be calculated.
1526 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1529 gboolean res = FALSE;
1530 GstBaseTransformClass *bclass;
1532 /* see if we have the result cached */
1533 if (trans->cache_caps1 == caps) {
1534 *size = trans->cache_caps1_size;
1535 GST_DEBUG_OBJECT (trans,
1536 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1539 if (trans->cache_caps2 == caps) {
1540 *size = trans->cache_caps2_size;
1541 GST_DEBUG_OBJECT (trans,
1542 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1546 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1547 res = bclass->get_unit_size (trans, caps, size);
1548 GST_DEBUG_OBJECT (trans,
1549 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1550 caps, *size, res ? "TRUE" : "FALSE");
1553 /* and cache the values */
1554 if (trans->cache_caps1 == NULL) {
1555 gst_caps_replace (&trans->cache_caps1, caps);
1556 trans->cache_caps1_size = *size;
1557 GST_DEBUG_OBJECT (trans,
1558 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1559 } else if (trans->cache_caps2 == NULL) {
1560 gst_caps_replace (&trans->cache_caps2, caps);
1561 trans->cache_caps2_size = *size;
1562 GST_DEBUG_OBJECT (trans,
1563 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1565 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1572 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1574 GstBaseTransform *trans;
1575 GstBaseTransformClass *bclass;
1576 gboolean ret = TRUE;
1578 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1579 if (G_UNLIKELY (trans == NULL)) {
1580 gst_event_unref (event);
1583 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1585 if (bclass->sink_event)
1586 ret = bclass->sink_event (trans, event);
1588 gst_event_unref (event);
1590 gst_object_unref (trans);
1596 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1598 gboolean ret = TRUE, forward = TRUE;
1600 switch (GST_EVENT_TYPE (event)) {
1601 case GST_EVENT_FLUSH_START:
1603 case GST_EVENT_FLUSH_STOP:
1604 GST_OBJECT_LOCK (trans);
1605 /* reset QoS parameters */
1606 trans->priv->proportion = 1.0;
1607 trans->priv->earliest_time = -1;
1608 trans->priv->discont = FALSE;
1609 trans->priv->processed = 0;
1610 trans->priv->dropped = 0;
1611 GST_OBJECT_UNLOCK (trans);
1612 /* we need new segment info after the flush. */
1613 trans->have_segment = FALSE;
1614 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1615 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1621 case GST_EVENT_CAPS:
1625 gst_event_parse_caps (event, &caps);
1626 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1631 case GST_EVENT_SEGMENT:
1633 gst_event_copy_segment (event, &trans->segment);
1634 trans->have_segment = TRUE;
1636 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1645 ret = gst_pad_push_event (trans->srcpad, event);
1647 gst_event_unref (event);
1653 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1655 GstBaseTransform *trans;
1656 GstBaseTransformClass *bclass;
1657 gboolean ret = TRUE;
1659 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1660 if (G_UNLIKELY (trans == NULL)) {
1661 gst_event_unref (event);
1665 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1667 if (bclass->src_event)
1668 ret = bclass->src_event (trans, event);
1670 gst_event_unref (event);
1672 gst_object_unref (trans);
1678 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1682 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1684 switch (GST_EVENT_TYPE (event)) {
1685 case GST_EVENT_SEEK:
1687 case GST_EVENT_NAVIGATION:
1692 GstClockTimeDiff diff;
1693 GstClockTime timestamp;
1695 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1696 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1703 ret = gst_pad_push_event (trans->sinkpad, event);
1708 /* perform a transform on @inbuf and put the result in @outbuf.
1710 * This function is common to the push and pull-based operations.
1712 * This function takes ownership of @inbuf */
1713 static GstFlowReturn
1714 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1715 GstBuffer ** outbuf)
1717 GstBaseTransformClass *bclass;
1718 GstFlowReturn ret = GST_FLOW_OK;
1719 gboolean want_in_place;
1720 GstClockTime running_time;
1721 GstClockTime timestamp;
1722 gboolean reconfigure;
1724 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1726 GST_OBJECT_LOCK (trans->sinkpad);
1727 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1728 || trans->priv->reconfigure;
1729 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1730 trans->priv->reconfigure = FALSE;
1731 GST_OBJECT_UNLOCK (trans->sinkpad);
1733 if (G_UNLIKELY (reconfigure)) {
1736 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1738 incaps = gst_pad_get_current_caps (trans->sinkpad);
1740 goto no_reconfigure;
1742 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1743 * will reconfigure the transform with the new output format. We can only
1744 * do this if the buffer actually has caps. */
1745 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1746 gst_caps_unref (incaps);
1747 goto not_negotiated;
1749 gst_caps_unref (incaps);
1753 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1754 GST_DEBUG_OBJECT (trans,
1755 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1756 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1757 GST_BUFFER_OFFSET (inbuf));
1759 GST_DEBUG_OBJECT (trans,
1760 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1761 gst_buffer_get_size (inbuf));
1763 /* Don't allow buffer handling before negotiation, except in passthrough mode
1764 * or if the class doesn't implement a set_caps function (in which case it doesn't
1767 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1768 goto not_negotiated;
1770 /* Set discont flag so we can mark the outgoing buffer */
1771 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1772 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1773 trans->priv->discont = TRUE;
1776 /* can only do QoS if the segment is in TIME */
1777 if (trans->segment.format != GST_FORMAT_TIME)
1780 /* QOS is done on the running time of the buffer, get it now */
1781 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1782 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1785 if (running_time != -1) {
1787 GstClockTime earliest_time;
1790 /* lock for getting the QoS parameters that are set (in a different thread)
1791 * with the QOS events */
1792 GST_OBJECT_LOCK (trans);
1793 earliest_time = trans->priv->earliest_time;
1794 proportion = trans->priv->proportion;
1795 /* check for QoS, don't perform conversion for buffers
1796 * that are known to be late. */
1797 need_skip = trans->priv->qos_enabled &&
1798 earliest_time != -1 && running_time <= earliest_time;
1799 GST_OBJECT_UNLOCK (trans);
1802 GstMessage *qos_msg;
1803 GstClockTime duration;
1804 guint64 stream_time;
1807 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1808 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1809 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1811 trans->priv->dropped++;
1813 duration = GST_BUFFER_DURATION (inbuf);
1815 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1817 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1820 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1821 stream_time, timestamp, duration);
1822 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1823 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1824 trans->priv->processed, trans->priv->dropped);
1825 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1827 /* mark discont for next buffer */
1828 trans->priv->discont = TRUE;
1835 /* first try to allocate an output buffer based on the currently negotiated
1836 * format. outbuf will contain a buffer suitable for doing the configured
1837 * transform after this function. */
1838 if (bclass->prepare_output_buffer == NULL)
1841 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1842 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1844 if (ret != GST_FLOW_OK || *outbuf == NULL)
1847 if (inbuf == *outbuf) {
1848 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1849 } else if (trans->passthrough) {
1850 /* we are asked to perform a passthrough transform but the input and
1851 * output buffers are different. We have to discard the output buffer and
1852 * reuse the input buffer. This is rather weird, it means that the prepare
1853 * output buffer does something wrong. */
1854 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1855 "prepare_output_buffer implementation");
1856 gst_buffer_unref (*outbuf);
1859 /* copy the metadata */
1860 if (bclass->copy_metadata)
1861 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1862 /* something failed, post a warning */
1863 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1864 ("could not copy metadata"), (NULL));
1867 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1870 /* now perform the needed transform */
1871 if (trans->passthrough) {
1872 /* In passthrough mode, give transform_ip a look at the
1873 * buffer, without making it writable, or just push the
1875 if (bclass->transform_ip) {
1876 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1877 ret = bclass->transform_ip (trans, *outbuf);
1879 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1882 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1884 if (want_in_place) {
1885 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1887 if (inbuf != *outbuf) {
1888 guint8 *indata, *outdata;
1889 gsize insize, outsize;
1891 /* Different buffer. The data can still be the same when we are dealing
1892 * with subbuffers of the same buffer. Note that because of the FIXME in
1893 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1894 * outbuf to keep them writable */
1895 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1896 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1898 if (indata != outdata)
1899 memcpy (outdata, indata, insize);
1901 gst_buffer_unmap (inbuf, indata, insize);
1902 gst_buffer_unmap (*outbuf, outdata, outsize);
1904 ret = bclass->transform_ip (trans, *outbuf);
1906 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1908 if (bclass->transform)
1909 ret = bclass->transform (trans, inbuf, *outbuf);
1911 ret = GST_FLOW_NOT_SUPPORTED;
1916 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1917 * the input buffer, no refcount is changed to keep the input buffer writable
1919 if (*outbuf != inbuf)
1920 gst_buffer_unref (inbuf);
1927 gst_buffer_unref (inbuf);
1929 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1930 ("not negotiated"), ("not negotiated"));
1931 return GST_FLOW_NOT_NEGOTIATED;
1935 gst_buffer_unref (inbuf);
1936 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1937 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1938 return GST_FLOW_NOT_SUPPORTED;
1942 gst_buffer_unref (inbuf);
1944 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1945 gst_flow_get_name (ret));
1950 /* FIXME, getrange is broken, need to pull range from the other
1951 * end based on the transform_size result.
1953 static GstFlowReturn
1954 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1955 guint length, GstBuffer ** buffer)
1957 GstBaseTransform *trans;
1958 GstBaseTransformClass *klass;
1962 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1964 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1965 if (G_UNLIKELY (ret != GST_FLOW_OK))
1968 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1969 if (klass->before_transform)
1970 klass->before_transform (trans, inbuf);
1972 GST_BASE_TRANSFORM_LOCK (trans);
1973 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1974 GST_BASE_TRANSFORM_UNLOCK (trans);
1977 gst_object_unref (trans);
1984 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1985 gst_flow_get_name (ret));
1990 static GstFlowReturn
1991 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
1993 GstBaseTransform *trans;
1994 GstBaseTransformClass *klass;
1996 GstClockTime position = GST_CLOCK_TIME_NONE;
1997 GstClockTime timestamp, duration;
1998 GstBuffer *outbuf = NULL;
2000 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
2002 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2003 duration = GST_BUFFER_DURATION (buffer);
2005 /* calculate end position of the incoming buffer */
2006 if (timestamp != GST_CLOCK_TIME_NONE) {
2007 if (duration != GST_CLOCK_TIME_NONE)
2008 position = timestamp + duration;
2010 position = timestamp;
2013 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2014 if (klass->before_transform)
2015 klass->before_transform (trans, buffer);
2017 /* protect transform method and concurrent buffer alloc */
2018 GST_BASE_TRANSFORM_LOCK (trans);
2019 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2020 GST_BASE_TRANSFORM_UNLOCK (trans);
2022 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2023 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2024 if (outbuf != NULL) {
2025 if (ret == GST_FLOW_OK) {
2026 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2028 /* Remember last stop position */
2029 if (position != GST_CLOCK_TIME_NONE &&
2030 trans->segment.format == GST_FORMAT_TIME)
2031 trans->segment.position = position;
2033 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2034 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2035 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2036 position_out += GST_BUFFER_DURATION (outbuf);
2037 } else if (position != GST_CLOCK_TIME_NONE) {
2038 position_out = position;
2040 if (position_out != GST_CLOCK_TIME_NONE
2041 && trans->segment.format == GST_FORMAT_TIME)
2042 trans->priv->position_out = position_out;
2044 /* apply DISCONT flag if the buffer is not yet marked as such */
2045 if (trans->priv->discont) {
2046 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2047 outbuf = gst_buffer_make_writable (outbuf);
2048 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2050 trans->priv->discont = FALSE;
2052 trans->priv->processed++;
2054 ret = gst_pad_push (trans->srcpad, outbuf);
2056 gst_buffer_unref (outbuf);
2060 /* convert internal flow to OK and mark discont for the next buffer. */
2061 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2062 trans->priv->discont = TRUE;
2070 gst_base_transform_set_property (GObject * object, guint prop_id,
2071 const GValue * value, GParamSpec * pspec)
2073 GstBaseTransform *trans;
2075 trans = GST_BASE_TRANSFORM (object);
2079 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2082 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2088 gst_base_transform_get_property (GObject * object, guint prop_id,
2089 GValue * value, GParamSpec * pspec)
2091 GstBaseTransform *trans;
2093 trans = GST_BASE_TRANSFORM (object);
2097 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2105 /* not a vmethod of anything, just an internal method */
2107 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2109 GstBaseTransformClass *bclass;
2110 gboolean result = TRUE;
2112 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2115 GstCaps *incaps, *outcaps;
2117 if (trans->priv->pad_mode == GST_PAD_ACTIVATE_NONE && bclass->start)
2118 result &= bclass->start (trans);
2120 incaps = gst_pad_get_current_caps (trans->sinkpad);
2121 outcaps = gst_pad_get_current_caps (trans->srcpad);
2123 GST_OBJECT_LOCK (trans);
2124 if (incaps && outcaps)
2125 trans->have_same_caps =
2126 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2128 trans->have_same_caps = trans->passthrough;
2129 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2130 trans->negotiated = FALSE;
2131 trans->have_segment = FALSE;
2132 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2133 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2134 trans->priv->proportion = 1.0;
2135 trans->priv->earliest_time = -1;
2136 trans->priv->discont = FALSE;
2137 trans->priv->processed = 0;
2138 trans->priv->dropped = 0;
2139 GST_OBJECT_UNLOCK (trans);
2142 gst_caps_unref (incaps);
2144 gst_caps_unref (outcaps);
2146 /* We must make sure streaming has finished before resetting things
2147 * and calling the ::stop vfunc */
2148 GST_PAD_STREAM_LOCK (trans->sinkpad);
2149 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2151 trans->have_same_caps = FALSE;
2152 /* We can only reset the passthrough mode if the instance told us to
2153 handle it in configure_caps */
2154 if (bclass->passthrough_on_same_caps) {
2155 gst_base_transform_set_passthrough (trans, FALSE);
2157 gst_caps_replace (&trans->cache_caps1, NULL);
2158 gst_caps_replace (&trans->cache_caps2, NULL);
2160 if (trans->priv->pad_mode != GST_PAD_ACTIVATE_NONE && bclass->stop)
2161 result &= bclass->stop (trans);
2163 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2170 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2172 gboolean result = TRUE;
2173 GstBaseTransform *trans;
2175 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2177 result = gst_base_transform_activate (trans, active);
2180 trans->priv->pad_mode =
2181 active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
2183 gst_object_unref (trans);
2189 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2191 gboolean result = FALSE;
2192 GstBaseTransform *trans;
2194 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2196 result = gst_pad_activate_pull (trans->sinkpad, active);
2199 result &= gst_base_transform_activate (trans, active);
2202 trans->priv->pad_mode =
2203 active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
2205 gst_object_unref (trans);
2211 * gst_base_transform_set_passthrough:
2212 * @trans: the #GstBaseTransform to set
2213 * @passthrough: boolean indicating passthrough mode.
2215 * Set passthrough mode for this filter by default. This is mostly
2216 * useful for filters that do not care about negotiation.
2218 * Always TRUE for filters which don't implement either a transform
2219 * or transform_ip method.
2224 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2225 gboolean passthrough)
2227 GstBaseTransformClass *bclass;
2229 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2231 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2233 GST_OBJECT_LOCK (trans);
2234 if (passthrough == FALSE) {
2235 if (bclass->transform_ip || bclass->transform)
2236 trans->passthrough = FALSE;
2238 trans->passthrough = TRUE;
2241 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2242 GST_OBJECT_UNLOCK (trans);
2246 * gst_base_transform_is_passthrough:
2247 * @trans: the #GstBaseTransform to query
2249 * See if @trans is configured as a passthrough transform.
2251 * Returns: TRUE is the transform is configured in passthrough mode.
2256 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2260 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2262 GST_OBJECT_LOCK (trans);
2263 result = trans->passthrough;
2264 GST_OBJECT_UNLOCK (trans);
2270 * gst_base_transform_set_in_place:
2271 * @trans: the #GstBaseTransform to modify
2272 * @in_place: Boolean value indicating that we would like to operate
2273 * on in_place buffers.
2275 * Determines whether a non-writable buffer will be copied before passing
2276 * to the transform_ip function.
2278 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2279 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2285 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2287 GstBaseTransformClass *bclass;
2289 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2291 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2293 GST_OBJECT_LOCK (trans);
2296 if (bclass->transform_ip) {
2297 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2298 trans->always_in_place = TRUE;
2301 if (bclass->transform) {
2302 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2303 trans->always_in_place = FALSE;
2307 GST_OBJECT_UNLOCK (trans);
2311 * gst_base_transform_is_in_place:
2312 * @trans: the #GstBaseTransform to query
2314 * See if @trans is configured as a in_place transform.
2316 * Returns: TRUE is the transform is configured in in_place mode.
2321 gst_base_transform_is_in_place (GstBaseTransform * trans)
2325 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2327 GST_OBJECT_LOCK (trans);
2328 result = trans->always_in_place;
2329 GST_OBJECT_UNLOCK (trans);
2335 * gst_base_transform_update_qos:
2336 * @trans: a #GstBaseTransform
2337 * @proportion: the proportion
2338 * @diff: the diff against the clock
2339 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2342 * Set the QoS parameters in the transform. This function is called internally
2343 * when a QOS event is received but subclasses can provide custom information
2351 gst_base_transform_update_qos (GstBaseTransform * trans,
2352 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2355 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2357 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2358 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2359 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2361 GST_OBJECT_LOCK (trans);
2362 trans->priv->proportion = proportion;
2363 trans->priv->earliest_time = timestamp + diff;
2364 GST_OBJECT_UNLOCK (trans);
2368 * gst_base_transform_set_qos_enabled:
2369 * @trans: a #GstBaseTransform
2370 * @enabled: new state
2372 * Enable or disable QoS handling in the transform.
2379 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2381 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2383 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2385 GST_OBJECT_LOCK (trans);
2386 trans->priv->qos_enabled = enabled;
2387 GST_OBJECT_UNLOCK (trans);
2391 * gst_base_transform_is_qos_enabled:
2392 * @trans: a #GstBaseTransform
2394 * Queries if the transform will handle QoS.
2396 * Returns: TRUE if QoS is enabled.
2403 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2407 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2409 GST_OBJECT_LOCK (trans);
2410 result = trans->priv->qos_enabled;
2411 GST_OBJECT_UNLOCK (trans);
2417 * gst_base_transform_set_gap_aware:
2418 * @trans: a #GstBaseTransform
2419 * @gap_aware: New state
2421 * If @gap_aware is %FALSE (the default), output buffers will have the
2422 * %GST_BUFFER_FLAG_GAP flag unset.
2424 * If set to %TRUE, the element must handle output buffers with this flag set
2425 * correctly, i.e. it can assume that the buffer contains neutral data but must
2426 * unset the flag if the output is no neutral data.
2433 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2435 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2437 GST_OBJECT_LOCK (trans);
2438 trans->priv->gap_aware = gap_aware;
2439 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2440 GST_OBJECT_UNLOCK (trans);
2444 * gst_base_transform_suggest:
2445 * @trans: a #GstBaseTransform
2446 * @caps: (transfer none): caps to suggest
2447 * @size: buffer size to suggest
2449 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2455 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2458 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2460 /* push the renegotiate event */
2461 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2462 gst_event_new_reconfigure ()))
2463 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2467 * gst_base_transform_reconfigure:
2468 * @trans: a #GstBaseTransform
2470 * Instructs @trans to renegotiate a new downstream transform on the next
2471 * buffer. This function is typically called after properties on the transform
2472 * were set that influence the output format.
2477 gst_base_transform_reconfigure (GstBaseTransform * trans)
2479 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2481 GST_OBJECT_LOCK (trans);
2482 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2483 trans->priv->reconfigure = TRUE;
2484 GST_OBJECT_UNLOCK (trans);