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 GstActivateMode 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_getcaps (GstPad * pad, GstCaps * filter);
321 static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
322 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
323 GstPadDirection direction, GstCaps * caps);
324 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
325 GstPad * pad, GstCaps * caps);
326 static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
327 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
328 GstPadDirection direction, GstQuery * query);
329 static const GstQueryType *gst_base_transform_query_type (GstPad * pad);
331 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
332 GstBuffer * inbuf, GstBuffer ** outbuf);
333 static gboolean default_copy_metadata (GstBaseTransform * trans,
334 GstBuffer * inbuf, GstBuffer * outbuf);
336 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
340 gst_base_transform_finalize (GObject * object)
342 GstBaseTransform *trans;
344 trans = GST_BASE_TRANSFORM (object);
346 g_mutex_free (trans->transform_lock);
348 G_OBJECT_CLASS (parent_class)->finalize (object);
352 gst_base_transform_class_init (GstBaseTransformClass * klass)
354 GObjectClass *gobject_class;
356 gobject_class = G_OBJECT_CLASS (klass);
358 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
359 "basetransform element");
361 GST_DEBUG ("gst_base_transform_class_init");
363 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
365 parent_class = g_type_class_peek_parent (klass);
367 gobject_class->set_property = gst_base_transform_set_property;
368 gobject_class->get_property = gst_base_transform_get_property;
370 g_object_class_install_property (gobject_class, PROP_QOS,
371 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
372 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
374 gobject_class->finalize = gst_base_transform_finalize;
376 klass->passthrough_on_same_caps = FALSE;
377 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
378 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
380 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
381 klass->prepare_output_buffer =
382 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
383 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
384 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
388 gst_base_transform_init (GstBaseTransform * trans,
389 GstBaseTransformClass * bclass)
391 GstPadTemplate *pad_template;
393 GST_DEBUG ("gst_base_transform_init");
395 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
398 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
399 g_return_if_fail (pad_template != NULL);
400 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
401 gst_pad_set_getcaps_function (trans->sinkpad,
402 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
403 gst_pad_set_acceptcaps_function (trans->sinkpad,
404 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
405 gst_pad_set_event_function (trans->sinkpad,
406 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
407 gst_pad_set_chain_function (trans->sinkpad,
408 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
409 gst_pad_set_activatepush_function (trans->sinkpad,
410 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
411 gst_pad_set_query_function (trans->sinkpad,
412 GST_DEBUG_FUNCPTR (gst_base_transform_query));
413 gst_pad_set_query_type_function (trans->sinkpad,
414 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
415 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
418 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
419 g_return_if_fail (pad_template != NULL);
420 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
421 gst_pad_set_getcaps_function (trans->srcpad,
422 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
423 gst_pad_set_acceptcaps_function (trans->srcpad,
424 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
425 gst_pad_set_event_function (trans->srcpad,
426 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
427 gst_pad_set_getrange_function (trans->srcpad,
428 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
429 gst_pad_set_activatepull_function (trans->srcpad,
430 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
431 gst_pad_set_query_function (trans->srcpad,
432 GST_DEBUG_FUNCPTR (gst_base_transform_query));
433 gst_pad_set_query_type_function (trans->srcpad,
434 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
435 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
437 trans->transform_lock = g_mutex_new ();
438 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
439 trans->cache_caps1 = NULL;
440 trans->cache_caps2 = NULL;
441 trans->priv->pad_mode = GST_ACTIVATE_NONE;
442 trans->priv->gap_aware = FALSE;
444 trans->passthrough = FALSE;
445 if (bclass->transform == NULL) {
446 /* If no transform function, always_in_place is TRUE */
447 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
448 trans->always_in_place = TRUE;
450 if (bclass->transform_ip == NULL) {
451 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
452 trans->passthrough = TRUE;
456 trans->priv->processed = 0;
457 trans->priv->dropped = 0;
460 /* given @caps on the src or sink pad (given by @direction)
461 * calculate the possible caps on the other pad.
463 * Returns new caps, unref after usage.
466 gst_base_transform_transform_caps (GstBaseTransform * trans,
467 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
470 GstBaseTransformClass *klass;
475 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
477 /* if there is a custom transform function, use this */
478 if (klass->transform_caps) {
480 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
482 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
483 ret = klass->transform_caps (trans, direction, caps, filter);
484 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
486 #ifndef G_DISABLE_ASSERT
488 if (!gst_caps_is_subset (ret, filter)) {
489 GstCaps *intersection;
491 GST_ERROR_OBJECT (trans,
492 "transform_caps returned caps %" GST_PTR_FORMAT
493 " which are not a real subset of the filter caps %"
494 GST_PTR_FORMAT, ret, filter);
495 g_warning ("%s: transform_caps returned caps which are not a real "
496 "subset of the filter caps", GST_ELEMENT_NAME (trans));
499 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
500 gst_caps_unref (intersection);
506 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
507 /* no transform function, use the identity transform */
509 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
511 ret = gst_caps_ref (caps);
515 GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
521 /* transform a buffer of @size with @caps on the pad with @direction to
522 * the size of a buffer with @othercaps and store the result in @othersize
524 * We have two ways of doing this:
525 * 1) use a custom transform size function, this is for complicated custom
526 * cases with no fixed unit_size.
527 * 2) use the unit_size functions where there is a relationship between the
528 * caps and the size of a buffer.
531 gst_base_transform_transform_size (GstBaseTransform * trans,
532 GstPadDirection direction, GstCaps * caps,
533 gsize size, GstCaps * othercaps, gsize * othersize)
535 gsize inunitsize, outunitsize, units;
536 GstBaseTransformClass *klass;
539 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
541 GST_DEBUG_OBJECT (trans,
542 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
543 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
544 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
546 if (klass->transform_size) {
547 /* if there is a custom transform function, use this */
548 ret = klass->transform_size (trans, direction, caps, size, othercaps,
550 } else if (klass->get_unit_size == NULL) {
551 /* if there is no transform_size and no unit_size, it means the
552 * element does not modify the size of a buffer */
556 /* there is no transform_size function, we have to use the unit_size
557 * functions. This method assumes there is a fixed unit_size associated with
558 * each caps. We provide the same amount of units on both sides. */
559 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
562 GST_DEBUG_OBJECT (trans,
563 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
566 /* input size must be a multiple of the unit_size of the input caps */
567 if (inunitsize == 0 || (size % inunitsize != 0))
570 /* get the amount of units */
571 units = size / inunitsize;
573 /* now get the unit size of the output */
574 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
577 /* the output size is the unit_size times the amount of units on the
579 *othersize = units * outunitsize;
580 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
590 GST_DEBUG_OBJECT (trans, "could not get in_size");
591 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
596 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
597 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
598 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
599 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
604 GST_DEBUG_OBJECT (trans, "could not get out_size");
605 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
610 /* get the caps that can be handled by @pad. We perform:
612 * - take the caps of peer of otherpad,
613 * - filter against the padtemplate of otherpad,
614 * - calculate all transforms of remaining caps
615 * - filter against template of @pad
617 * If there is no peer, we simply return the caps of the padtemplate of pad.
620 gst_base_transform_getcaps (GstPad * pad, GstCaps * filter)
622 GstBaseTransform *trans;
624 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
627 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
629 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
631 /* we can do what the peer can */
634 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
636 /* filtered against our padtemplate on the other side */
637 templ = gst_pad_get_pad_template_caps (pad);
638 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
639 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
640 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
641 gst_caps_unref (templ);
643 /* then see what we can transform this to */
644 peerfilter = gst_base_transform_transform_caps (trans,
645 GST_PAD_DIRECTION (pad), temp, NULL);
646 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
647 gst_caps_unref (temp);
649 /* and filter against the template of this pad */
650 templ = gst_pad_get_pad_template_caps (otherpad);
651 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
652 /* We keep the caps sorted like the returned caps */
654 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
655 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
656 gst_caps_unref (peerfilter);
657 gst_caps_unref (templ);
661 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
664 gst_caps_unref (peerfilter);
667 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
669 /* filtered against our padtemplate on the other side */
670 templ = gst_pad_get_pad_template_caps (otherpad);
671 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
672 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
673 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
674 gst_caps_unref (templ);
676 temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
679 /* then see what we can transform this to */
680 caps = gst_base_transform_transform_caps (trans,
681 GST_PAD_DIRECTION (otherpad), temp, filter);
682 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
683 gst_caps_unref (temp);
687 /* and filter against the template of this pad */
688 templ = gst_pad_get_pad_template_caps (pad);
689 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
690 /* We keep the caps sorted like the returned caps */
691 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
692 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
693 gst_caps_unref (caps);
694 gst_caps_unref (templ);
698 /* Now try if we can put the untransformed downstream caps first */
699 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
700 if (!gst_caps_is_empty (temp)) {
701 gst_caps_merge (temp, caps);
704 gst_caps_unref (temp);
707 /* no peer or the peer can do anything, our padtemplate is enough then */
708 caps = gst_pad_get_pad_template_caps (pad);
713 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
714 gst_caps_unref (caps);
720 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
723 gst_caps_unref (peercaps);
725 gst_object_unref (trans);
731 gst_base_transform_set_allocation (GstBaseTransform * trans,
732 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
735 GstBufferPool *oldpool;
736 GstBaseTransformPrivate *priv = trans->priv;
740 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
741 if (!gst_buffer_pool_set_active (pool, TRUE))
742 goto activate_failed;
745 GST_OBJECT_LOCK (trans);
746 oldpool = priv->pool;
748 priv->allocator = allocator;
749 priv->prefix = prefix;
750 priv->alignment = alignment;
751 GST_OBJECT_UNLOCK (trans);
754 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
755 gst_buffer_pool_set_active (oldpool, FALSE);
756 gst_object_unref (oldpool);
763 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
769 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
772 gboolean result = TRUE;
773 GstBufferPool *pool = NULL, *oldpool;
774 guint size, min, max, prefix, alignment;
775 GstBaseTransformClass *klass;
776 const GstAllocator *allocator = NULL;
778 /* there are these possibilities:
780 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
781 * will do that whenever some upstream does an allocation query.
782 * 2) we need to do a transform, we need to get a bufferpool from downstream
783 * and configure it. When upstream does the ALLOCATION query, the
784 * propose_allocation vmethod will be called and we will configure the
785 * upstream allocator with our porposed values then.
789 oldpool = trans->priv->pool;
791 GST_DEBUG_OBJECT (trans, "unreffing old pool");
792 gst_buffer_pool_set_active (oldpool, FALSE);
793 gst_object_unref (oldpool);
794 trans->priv->pool = oldpool = NULL;
797 if (trans->passthrough || trans->always_in_place) {
798 /* we are in passthrough, the input buffer is never copied and always passed
799 * along. We never allocate an output buffer on the srcpad. What we do is
800 * let the upstream element decide if it wants to use a bufferpool and
801 * then we will proxy the downstream pool */
802 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
806 /* not passthrough, we need to allocate */
807 /* find a pool for the negotiated caps now */
808 GST_DEBUG_OBJECT (trans, "doing allocation query");
809 query = gst_query_new_allocation (outcaps, TRUE);
810 if (!gst_pad_peer_query (trans->srcpad, query)) {
811 /* not a problem, just debug a little */
812 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
815 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
817 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
818 if (G_LIKELY (klass->decide_allocation))
819 result = klass->decide_allocation (trans, query);
821 /* we got configuration from our peer, parse them */
822 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
824 gst_query_unref (query);
827 const gchar *mem = NULL;
829 /* no size, we have variable size buffers */
830 if (gst_query_get_n_allocation_memories (query) > 0) {
831 mem = gst_query_parse_nth_allocation_memory (query, 0);
833 allocator = gst_allocator_find (mem);
834 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
835 } else if (pool == NULL) {
836 GstStructure *config;
838 /* we did not get a pool, make one ourselves then */
839 pool = gst_buffer_pool_new ();
841 GST_DEBUG_OBJECT (trans, "no pool, making one");
842 config = gst_buffer_pool_get_config (pool);
843 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
845 gst_buffer_pool_set_config (pool, config);
850 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
856 /* function triggered when the in and out caps are negotiated and need
857 * to be configured in the subclass. */
859 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
863 GstBaseTransformClass *klass;
865 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
867 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
868 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
870 /* clear the cache */
871 gst_caps_replace (&trans->cache_caps1, NULL);
872 gst_caps_replace (&trans->cache_caps2, NULL);
874 /* figure out same caps state */
875 trans->have_same_caps = gst_caps_is_equal (in, out);
876 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
878 /* If we've a transform_ip method and same input/output caps, set in_place
879 * by default. If for some reason the sub-class prefers using a transform
880 * function, it can clear the in place flag in the set_caps */
881 gst_base_transform_set_in_place (trans,
882 klass->transform_ip && trans->have_same_caps);
884 /* Set the passthrough if the class wants passthrough_on_same_caps
885 * and we have the same caps on each pad */
886 if (klass->passthrough_on_same_caps)
887 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
889 /* now configure the element with the caps */
890 if (klass->set_caps) {
891 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
892 ret = klass->set_caps (trans, in, out);
895 trans->negotiated = ret;
900 /* given a fixed @caps on @pad, create the best possible caps for the
902 * @caps must be fixed when calling this function.
904 * This function calls the transform caps vmethod of the basetransform to figure
905 * out the possible target formats. It then tries to select the best format from
908 * - attempt passthrough if the target caps is a superset of the input caps
909 * - fixating by using peer caps
910 * - fixating with transform fixate function
911 * - fixating with pad fixate functions.
913 * this function returns a caps that can be transformed into and is accepted by
917 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
920 GstBaseTransformClass *klass;
921 GstPad *otherpad, *otherpeer;
925 /* caps must be fixed here, this is a programming error if it's not */
926 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
928 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
930 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
931 otherpeer = gst_pad_get_peer (otherpad);
933 /* see how we can transform the input caps. We need to do this even for
934 * passthrough because it might be possible that this element cannot support
935 * passthrough at all. */
936 othercaps = gst_base_transform_transform_caps (trans,
937 GST_PAD_DIRECTION (pad), caps, NULL);
939 /* The caps we can actually output is the intersection of the transformed
940 * caps with the pad template for the pad */
942 GstCaps *intersect, *templ_caps;
944 templ_caps = gst_pad_get_pad_template_caps (otherpad);
945 GST_DEBUG_OBJECT (trans,
946 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
949 gst_caps_intersect_full (othercaps, templ_caps,
950 GST_CAPS_INTERSECT_FIRST);
952 gst_caps_unref (othercaps);
953 gst_caps_unref (templ_caps);
954 othercaps = intersect;
957 /* check if transform is empty */
958 if (!othercaps || gst_caps_is_empty (othercaps))
961 /* if the othercaps are not fixed, we need to fixate them, first attempt
962 * is by attempting passthrough if the othercaps are a superset of caps. */
963 /* FIXME. maybe the caps is not fixed because it has multiple structures of
965 is_fixed = gst_caps_is_fixed (othercaps);
967 GST_DEBUG_OBJECT (trans,
968 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
970 /* Now let's see what the peer suggests based on our transformed caps */
972 GstCaps *peercaps, *intersection, *templ_caps;
974 GST_DEBUG_OBJECT (trans,
975 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
977 peercaps = gst_pad_get_caps (otherpeer, othercaps);
978 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
980 templ_caps = gst_pad_get_pad_template_caps (otherpad);
982 GST_DEBUG_OBJECT (trans,
983 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
986 gst_caps_intersect_full (peercaps, templ_caps,
987 GST_CAPS_INTERSECT_FIRST);
988 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
989 gst_caps_unref (peercaps);
990 gst_caps_unref (templ_caps);
991 peercaps = intersection;
993 GST_DEBUG_OBJECT (trans,
994 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
996 gst_caps_intersect_full (peercaps, othercaps,
997 GST_CAPS_INTERSECT_FIRST);
998 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
999 gst_caps_unref (peercaps);
1000 gst_caps_unref (othercaps);
1001 othercaps = intersection;
1002 is_fixed = gst_caps_is_fixed (othercaps);
1004 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1005 gst_caps_unref (othercaps);
1006 othercaps = gst_caps_ref (caps);
1010 if (gst_caps_is_empty (othercaps))
1011 goto no_transform_possible;
1013 /* second attempt at fixation, call the fixate vmethod and
1014 * ultimately call the pad fixate function. */
1016 GST_DEBUG_OBJECT (trans,
1017 "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
1018 othercaps, GST_DEBUG_PAD_NAME (otherpad));
1020 /* since we have no other way to fixate left, we might as well just take
1021 * the first of the caps list and fixate that */
1023 /* FIXME: when fixating using the vmethod, it might make sense to fixate
1024 * each of the caps; but Wim doesn't see a use case for that yet */
1025 gst_caps_truncate (othercaps);
1027 if (klass->fixate_caps) {
1028 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1029 " using caps %" GST_PTR_FORMAT
1030 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1031 GST_DEBUG_PAD_NAME (otherpad));
1032 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1033 is_fixed = gst_caps_is_fixed (othercaps);
1035 /* if still not fixed, no other option but to let the default pad fixate
1036 * function do its job */
1038 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1039 " on pad %s:%s using gst_pad_fixate_caps", othercaps,
1040 GST_DEBUG_PAD_NAME (otherpad));
1041 gst_pad_fixate_caps (otherpad, othercaps);
1042 is_fixed = gst_caps_is_fixed (othercaps);
1044 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1046 GST_DEBUG ("caps are fixed");
1047 /* else caps are fixed but the subclass may want to add fields */
1048 if (klass->fixate_caps) {
1049 othercaps = gst_caps_make_writable (othercaps);
1051 GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
1052 " using caps %" GST_PTR_FORMAT
1053 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1054 GST_DEBUG_PAD_NAME (otherpad));
1056 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1057 is_fixed = gst_caps_is_fixed (othercaps);
1061 /* caps should be fixed now, if not we have to fail. */
1063 goto could_not_fixate;
1065 /* and peer should accept */
1066 if (!gst_pad_accept_caps (otherpeer, othercaps))
1067 goto peer_no_accept;
1069 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1070 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1073 gst_object_unref (otherpeer);
1080 GST_DEBUG_OBJECT (trans,
1081 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1084 no_transform_possible:
1086 GST_DEBUG_OBJECT (trans,
1087 "transform could not transform %" GST_PTR_FORMAT
1088 " in anything we support", caps);
1093 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1098 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1099 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1105 gst_object_unref (otherpeer);
1107 gst_caps_unref (othercaps);
1113 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1114 GstPadDirection direction, GstCaps * caps)
1118 GstCaps *othercaps = NULL;
1120 gboolean ret = TRUE;
1123 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1125 /* we need fixed caps for the check, fall back to the default implementation
1127 if (!gst_caps_is_fixed (caps))
1132 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1134 /* get all the formats we can handle on this pad */
1135 if (direction == GST_PAD_SRC)
1136 allowed = gst_pad_get_caps (trans->srcpad, NULL);
1138 allowed = gst_pad_get_caps (trans->sinkpad, NULL);
1141 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1142 goto no_transform_possible;
1145 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1147 /* intersect with the requested format */
1148 ret = gst_caps_is_subset (caps, allowed);
1149 gst_caps_unref (allowed);
1152 goto no_transform_possible;
1156 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1158 /* find best possible caps for the other pad as a way to see if we can
1159 * transform this caps. */
1160 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1161 if (!othercaps || gst_caps_is_empty (othercaps))
1162 goto no_transform_possible;
1164 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1170 /* We know it's always NULL since we never use it */
1172 gst_caps_unref (othercaps);
1178 no_transform_possible:
1180 GST_DEBUG_OBJECT (trans,
1181 "transform could not transform %" GST_PTR_FORMAT
1182 " in anything we support", caps);
1189 gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
1191 gboolean ret = TRUE;
1192 GstBaseTransform *trans;
1193 GstBaseTransformClass *bclass;
1195 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1196 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1198 if (bclass->accept_caps)
1199 ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
1201 gst_object_unref (trans);
1206 /* called when new caps arrive on the sink or source pad,
1207 * We try to find the best caps for the other side using our _find_transform()
1208 * function. If there are caps, we configure the transform for this new
1211 * FIXME, this function is currently commutative but this should not really be
1212 * because we never set caps starting from the srcpad.
1215 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1218 GstPad *otherpad, *otherpeer;
1219 GstCaps *othercaps = NULL;
1220 gboolean ret = TRUE;
1221 GstCaps *incaps, *outcaps;
1223 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1224 otherpeer = gst_pad_get_peer (otherpad);
1226 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1228 /* find best possible caps for the other pad */
1229 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1230 if (!othercaps || gst_caps_is_empty (othercaps))
1231 goto no_transform_possible;
1233 /* configure the element now */
1234 /* make sure in and out caps are correct */
1235 if (pad == trans->sinkpad) {
1237 outcaps = othercaps;
1243 /* if we have the same caps, we can optimize and reuse the input caps */
1244 if (gst_caps_is_equal (incaps, outcaps)) {
1245 GST_INFO_OBJECT (trans, "reuse caps");
1246 gst_caps_unref (othercaps);
1247 outcaps = othercaps = gst_caps_ref (incaps);
1250 /* call configure now */
1251 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1252 goto failed_configure;
1254 GST_OBJECT_LOCK (trans->sinkpad);
1255 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1256 trans->priv->reconfigure = FALSE;
1257 GST_OBJECT_UNLOCK (trans->sinkpad);
1259 /* we know this will work, we implement the setcaps */
1260 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1262 if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
1264 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1266 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1272 /* try to get a pool when needed */
1273 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1278 gst_object_unref (otherpeer);
1280 gst_caps_unref (othercaps);
1282 trans->negotiated = ret;
1287 no_transform_possible:
1289 GST_WARNING_OBJECT (trans,
1290 "transform could not transform %" GST_PTR_FORMAT
1291 " in anything we support", caps);
1297 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1298 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1305 gst_base_transform_default_query (GstBaseTransform * trans,
1306 GstPadDirection direction, GstQuery * query)
1308 gboolean ret = FALSE;
1311 otherpad = (direction == GST_PAD_SRC) ? trans->sinkpad : trans->srcpad;
1313 switch (GST_QUERY_TYPE (query)) {
1314 case GST_QUERY_ALLOCATION:
1316 gboolean passthrough;
1318 /* can only be done on the sinkpad */
1319 if (direction != GST_PAD_SINK)
1322 GST_BASE_TRANSFORM_LOCK (trans);
1323 passthrough = trans->passthrough || trans->always_in_place;
1324 GST_BASE_TRANSFORM_UNLOCK (trans);
1327 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1328 ret = gst_pad_peer_query (otherpad, query);
1330 GstBaseTransformClass *klass;
1332 GST_DEBUG_OBJECT (trans, "propose allocation values");
1334 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1335 /* pass the query to the propose_allocation vmethod if any */
1336 if (G_LIKELY (klass->propose_allocation))
1337 ret = klass->propose_allocation (trans, query);
1341 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1345 case GST_QUERY_POSITION:
1349 gst_query_parse_position (query, &format, NULL);
1350 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1354 if ((direction == GST_PAD_SINK)
1355 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1357 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1358 trans->segment.position);
1360 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1361 trans->priv->position_out);
1363 gst_query_set_position (query, format, pos);
1365 ret = gst_pad_peer_query (otherpad, query);
1370 ret = gst_pad_peer_query (otherpad, query);
1379 gst_base_transform_query (GstPad * pad, GstQuery * query)
1381 GstBaseTransform *trans;
1382 GstBaseTransformClass *bclass;
1385 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1386 if (G_UNLIKELY (trans == NULL))
1389 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1392 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1394 ret = gst_pad_query_default (pad, query);
1396 gst_object_unref (trans);
1401 static const GstQueryType *
1402 gst_base_transform_query_type (GstPad * pad)
1404 static const GstQueryType types[] = {
1412 /* this function either returns the input buffer without incrementing the
1413 * refcount or it allocates a new (writable) buffer */
1414 static GstFlowReturn
1415 default_prepare_output_buffer (GstBaseTransform * trans,
1416 GstBuffer * inbuf, GstBuffer ** outbuf)
1418 GstBaseTransformPrivate *priv;
1419 GstFlowReturn ret = GST_FLOW_OK;
1420 GstBaseTransformClass *bclass;
1423 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1425 /* figure out how to allocate an output buffer */
1426 if (trans->passthrough) {
1427 /* passthrough, we will not modify the incomming buffer so we can just
1429 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1432 /* we can't reuse the input buffer */
1434 GST_DEBUG_OBJECT (trans, "using pool alloc");
1435 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1437 gsize insize, outsize;
1440 /* no pool, we need to figure out the size of the output buffer first */
1441 insize = gst_buffer_get_size (inbuf);
1443 if (trans->passthrough) {
1444 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1445 /* passthrough, the output size is the same as the input size. */
1448 gboolean want_in_place = (bclass->transform_ip != NULL)
1449 && trans->always_in_place;
1451 if (want_in_place) {
1452 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1453 /* we alloc a buffer of the same size as the input */
1456 GstCaps *incaps, *outcaps;
1458 /* else use the transform function to get the size */
1459 incaps = gst_pad_get_current_caps (trans->sinkpad);
1460 outcaps = gst_pad_get_current_caps (trans->srcpad);
1462 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1463 /* copy transform, figure out the output size */
1464 res = gst_base_transform_transform_size (trans,
1465 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1467 gst_caps_unref (incaps);
1468 gst_caps_unref (outcaps);
1474 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1476 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1484 GST_ERROR_OBJECT (trans, "unknown output size");
1485 return GST_FLOW_ERROR;
1490 default_copy_metadata (GstBaseTransform * trans,
1491 GstBuffer * inbuf, GstBuffer * outbuf)
1493 GstBaseTransformPrivate *priv = trans->priv;
1495 /* now copy the metadata */
1496 GST_DEBUG_OBJECT (trans, "copying metadata");
1498 /* this should not happen, buffers allocated from a pool or with
1499 * new_allocate should always be writable. */
1500 if (!gst_buffer_is_writable (outbuf))
1503 /* when we get here, the metadata should be writable */
1504 gst_buffer_copy_into (outbuf, inbuf,
1505 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1507 /* clear the GAP flag when the subclass does not understand it */
1508 if (!priv->gap_aware)
1509 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1516 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1521 /* Given @caps calcultate the size of one unit.
1523 * For video caps, this is the size of one frame (and thus one buffer).
1524 * For audio caps, this is the size of one sample.
1526 * These values are cached since they do not change and the calculation
1527 * potentially involves parsing caps and other expensive stuff.
1529 * We have two cache locations to store the size, one for the source caps
1530 * and one for the sink caps.
1532 * this function returns FALSE if no size could be calculated.
1535 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1538 gboolean res = FALSE;
1539 GstBaseTransformClass *bclass;
1541 /* see if we have the result cached */
1542 if (trans->cache_caps1 == caps) {
1543 *size = trans->cache_caps1_size;
1544 GST_DEBUG_OBJECT (trans,
1545 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1548 if (trans->cache_caps2 == caps) {
1549 *size = trans->cache_caps2_size;
1550 GST_DEBUG_OBJECT (trans,
1551 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1555 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1556 if (bclass->get_unit_size) {
1557 res = bclass->get_unit_size (trans, caps, size);
1558 GST_DEBUG_OBJECT (trans,
1559 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1560 caps, *size, res ? "TRUE" : "FALSE");
1563 /* and cache the values */
1564 if (trans->cache_caps1 == NULL) {
1565 gst_caps_replace (&trans->cache_caps1, caps);
1566 trans->cache_caps1_size = *size;
1567 GST_DEBUG_OBJECT (trans,
1568 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1569 } else if (trans->cache_caps2 == NULL) {
1570 gst_caps_replace (&trans->cache_caps2, caps);
1571 trans->cache_caps2_size = *size;
1572 GST_DEBUG_OBJECT (trans,
1573 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1575 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1579 GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
1585 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1587 GstBaseTransform *trans;
1588 GstBaseTransformClass *bclass;
1589 gboolean ret = TRUE;
1591 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1592 if (G_UNLIKELY (trans == NULL)) {
1593 gst_event_unref (event);
1596 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1598 if (bclass->sink_event)
1599 ret = bclass->sink_event (trans, event);
1601 gst_event_unref (event);
1603 gst_object_unref (trans);
1609 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1611 gboolean ret = TRUE, forward = TRUE;
1613 switch (GST_EVENT_TYPE (event)) {
1614 case GST_EVENT_FLUSH_START:
1616 case GST_EVENT_FLUSH_STOP:
1617 GST_OBJECT_LOCK (trans);
1618 /* reset QoS parameters */
1619 trans->priv->proportion = 1.0;
1620 trans->priv->earliest_time = -1;
1621 trans->priv->discont = FALSE;
1622 trans->priv->processed = 0;
1623 trans->priv->dropped = 0;
1624 GST_OBJECT_UNLOCK (trans);
1625 /* we need new segment info after the flush. */
1626 trans->have_segment = FALSE;
1627 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1628 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1634 case GST_EVENT_CAPS:
1638 gst_event_parse_caps (event, &caps);
1639 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1644 case GST_EVENT_SEGMENT:
1646 gst_event_copy_segment (event, &trans->segment);
1647 trans->have_segment = TRUE;
1649 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1658 ret = gst_pad_push_event (trans->srcpad, event);
1660 gst_event_unref (event);
1666 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1668 GstBaseTransform *trans;
1669 GstBaseTransformClass *bclass;
1670 gboolean ret = TRUE;
1672 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1673 if (G_UNLIKELY (trans == NULL)) {
1674 gst_event_unref (event);
1678 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1680 if (bclass->src_event)
1681 ret = bclass->src_event (trans, event);
1683 gst_event_unref (event);
1685 gst_object_unref (trans);
1691 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1695 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1697 switch (GST_EVENT_TYPE (event)) {
1698 case GST_EVENT_SEEK:
1700 case GST_EVENT_NAVIGATION:
1705 GstClockTimeDiff diff;
1706 GstClockTime timestamp;
1708 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1709 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1716 ret = gst_pad_push_event (trans->sinkpad, event);
1721 /* perform a transform on @inbuf and put the result in @outbuf.
1723 * This function is common to the push and pull-based operations.
1725 * This function takes ownership of @inbuf */
1726 static GstFlowReturn
1727 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1728 GstBuffer ** outbuf)
1730 GstBaseTransformClass *bclass;
1731 GstFlowReturn ret = GST_FLOW_OK;
1732 gboolean want_in_place;
1733 GstClockTime running_time;
1734 GstClockTime timestamp;
1735 gboolean reconfigure;
1737 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1739 GST_OBJECT_LOCK (trans->sinkpad);
1740 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1741 || trans->priv->reconfigure;
1742 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1743 trans->priv->reconfigure = FALSE;
1744 GST_OBJECT_UNLOCK (trans->sinkpad);
1746 if (G_UNLIKELY (reconfigure)) {
1749 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1751 incaps = gst_pad_get_current_caps (trans->sinkpad);
1753 goto no_reconfigure;
1755 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1756 * will reconfigure the transform with the new output format. We can only
1757 * do this if the buffer actually has caps. */
1758 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1759 gst_caps_unref (incaps);
1760 goto not_negotiated;
1762 gst_caps_unref (incaps);
1766 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1767 GST_DEBUG_OBJECT (trans,
1768 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1769 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1770 GST_BUFFER_OFFSET (inbuf));
1772 GST_DEBUG_OBJECT (trans,
1773 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1774 gst_buffer_get_size (inbuf));
1776 /* Don't allow buffer handling before negotiation, except in passthrough mode
1777 * or if the class doesn't implement a set_caps function (in which case it doesn't
1780 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1781 goto not_negotiated;
1783 /* Set discont flag so we can mark the outgoing buffer */
1784 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1785 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1786 trans->priv->discont = TRUE;
1789 /* can only do QoS if the segment is in TIME */
1790 if (trans->segment.format != GST_FORMAT_TIME)
1793 /* QOS is done on the running time of the buffer, get it now */
1794 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1795 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1798 if (running_time != -1) {
1800 GstClockTime earliest_time;
1803 /* lock for getting the QoS parameters that are set (in a different thread)
1804 * with the QOS events */
1805 GST_OBJECT_LOCK (trans);
1806 earliest_time = trans->priv->earliest_time;
1807 proportion = trans->priv->proportion;
1808 /* check for QoS, don't perform conversion for buffers
1809 * that are known to be late. */
1810 need_skip = trans->priv->qos_enabled &&
1811 earliest_time != -1 && running_time <= earliest_time;
1812 GST_OBJECT_UNLOCK (trans);
1815 GstMessage *qos_msg;
1816 GstClockTime duration;
1817 guint64 stream_time;
1820 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1821 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1822 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1824 trans->priv->dropped++;
1826 duration = GST_BUFFER_DURATION (inbuf);
1828 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1830 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1833 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1834 stream_time, timestamp, duration);
1835 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1836 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1837 trans->priv->processed, trans->priv->dropped);
1838 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1840 /* mark discont for next buffer */
1841 trans->priv->discont = TRUE;
1848 /* first try to allocate an output buffer based on the currently negotiated
1849 * format. outbuf will contain a buffer suitable for doing the configured
1850 * transform after this function. */
1851 if (bclass->prepare_output_buffer == NULL)
1854 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1855 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1857 if (ret != GST_FLOW_OK || *outbuf == NULL)
1860 if (inbuf == *outbuf) {
1861 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1862 } else if (trans->passthrough) {
1863 /* we are asked to perform a passthrough transform but the input and
1864 * output buffers are different. We have to discard the output buffer and
1865 * reuse the input buffer. This is rather weird, it means that the prepare
1866 * output buffer does something wrong. */
1867 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1868 "prepare_output_buffer implementation");
1869 gst_buffer_unref (*outbuf);
1872 /* copy the metadata */
1873 if (bclass->copy_metadata)
1874 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1875 /* something failed, post a warning */
1876 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1877 ("could not copy metadata"), (NULL));
1880 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1883 /* now perform the needed transform */
1884 if (trans->passthrough) {
1885 /* In passthrough mode, give transform_ip a look at the
1886 * buffer, without making it writable, or just push the
1888 if (bclass->transform_ip) {
1889 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1890 ret = bclass->transform_ip (trans, *outbuf);
1892 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1895 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1897 if (want_in_place) {
1898 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1900 if (inbuf != *outbuf) {
1901 guint8 *indata, *outdata;
1902 gsize insize, outsize;
1904 /* Different buffer. The data can still be the same when we are dealing
1905 * with subbuffers of the same buffer. Note that because of the FIXME in
1906 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1907 * outbuf to keep them writable */
1908 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1909 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1911 if (indata != outdata)
1912 memcpy (outdata, indata, insize);
1914 gst_buffer_unmap (inbuf, indata, insize);
1915 gst_buffer_unmap (*outbuf, outdata, outsize);
1917 ret = bclass->transform_ip (trans, *outbuf);
1919 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1921 if (bclass->transform)
1922 ret = bclass->transform (trans, inbuf, *outbuf);
1924 ret = GST_FLOW_NOT_SUPPORTED;
1929 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1930 * the input buffer, no refcount is changed to keep the input buffer writable
1932 if (*outbuf != inbuf)
1933 gst_buffer_unref (inbuf);
1940 gst_buffer_unref (inbuf);
1942 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1943 ("not negotiated"), ("not negotiated"));
1944 return GST_FLOW_NOT_NEGOTIATED;
1948 gst_buffer_unref (inbuf);
1949 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1950 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1951 return GST_FLOW_NOT_SUPPORTED;
1955 gst_buffer_unref (inbuf);
1957 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1958 gst_flow_get_name (ret));
1963 /* FIXME, getrange is broken, need to pull range from the other
1964 * end based on the transform_size result.
1966 static GstFlowReturn
1967 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1968 guint length, GstBuffer ** buffer)
1970 GstBaseTransform *trans;
1971 GstBaseTransformClass *klass;
1975 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1977 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1978 if (G_UNLIKELY (ret != GST_FLOW_OK))
1981 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1982 if (klass->before_transform)
1983 klass->before_transform (trans, inbuf);
1985 GST_BASE_TRANSFORM_LOCK (trans);
1986 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1987 GST_BASE_TRANSFORM_UNLOCK (trans);
1990 gst_object_unref (trans);
1997 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1998 gst_flow_get_name (ret));
2003 static GstFlowReturn
2004 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
2006 GstBaseTransform *trans;
2007 GstBaseTransformClass *klass;
2009 GstClockTime position = GST_CLOCK_TIME_NONE;
2010 GstClockTime timestamp, duration;
2011 GstBuffer *outbuf = NULL;
2013 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
2015 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2016 duration = GST_BUFFER_DURATION (buffer);
2018 /* calculate end position of the incoming buffer */
2019 if (timestamp != GST_CLOCK_TIME_NONE) {
2020 if (duration != GST_CLOCK_TIME_NONE)
2021 position = timestamp + duration;
2023 position = timestamp;
2026 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2027 if (klass->before_transform)
2028 klass->before_transform (trans, buffer);
2030 /* protect transform method and concurrent buffer alloc */
2031 GST_BASE_TRANSFORM_LOCK (trans);
2032 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2033 GST_BASE_TRANSFORM_UNLOCK (trans);
2035 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2036 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2037 if (outbuf != NULL) {
2038 if (ret == GST_FLOW_OK) {
2039 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2041 /* Remember last stop position */
2042 if (position != GST_CLOCK_TIME_NONE &&
2043 trans->segment.format == GST_FORMAT_TIME)
2044 trans->segment.position = position;
2046 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2047 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2048 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2049 position_out += GST_BUFFER_DURATION (outbuf);
2050 } else if (position != GST_CLOCK_TIME_NONE) {
2051 position_out = position;
2053 if (position_out != GST_CLOCK_TIME_NONE
2054 && trans->segment.format == GST_FORMAT_TIME)
2055 trans->priv->position_out = position_out;
2057 /* apply DISCONT flag if the buffer is not yet marked as such */
2058 if (trans->priv->discont) {
2059 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2060 outbuf = gst_buffer_make_writable (outbuf);
2061 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2063 trans->priv->discont = FALSE;
2065 trans->priv->processed++;
2067 ret = gst_pad_push (trans->srcpad, outbuf);
2069 gst_buffer_unref (outbuf);
2073 /* convert internal flow to OK and mark discont for the next buffer. */
2074 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2075 trans->priv->discont = TRUE;
2083 gst_base_transform_set_property (GObject * object, guint prop_id,
2084 const GValue * value, GParamSpec * pspec)
2086 GstBaseTransform *trans;
2088 trans = GST_BASE_TRANSFORM (object);
2092 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2095 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2101 gst_base_transform_get_property (GObject * object, guint prop_id,
2102 GValue * value, GParamSpec * pspec)
2104 GstBaseTransform *trans;
2106 trans = GST_BASE_TRANSFORM (object);
2110 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2113 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2118 /* not a vmethod of anything, just an internal method */
2120 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2122 GstBaseTransformClass *bclass;
2123 gboolean result = TRUE;
2125 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2128 GstCaps *incaps, *outcaps;
2130 if (trans->priv->pad_mode == GST_ACTIVATE_NONE && bclass->start)
2131 result &= bclass->start (trans);
2133 incaps = gst_pad_get_current_caps (trans->sinkpad);
2134 outcaps = gst_pad_get_current_caps (trans->srcpad);
2136 GST_OBJECT_LOCK (trans);
2137 if (incaps && outcaps)
2138 trans->have_same_caps =
2139 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2141 trans->have_same_caps = trans->passthrough;
2142 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2143 trans->negotiated = FALSE;
2144 trans->have_segment = FALSE;
2145 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2146 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2147 trans->priv->proportion = 1.0;
2148 trans->priv->earliest_time = -1;
2149 trans->priv->discont = FALSE;
2150 trans->priv->processed = 0;
2151 trans->priv->dropped = 0;
2152 GST_OBJECT_UNLOCK (trans);
2155 gst_caps_unref (incaps);
2157 gst_caps_unref (outcaps);
2159 /* We must make sure streaming has finished before resetting things
2160 * and calling the ::stop vfunc */
2161 GST_PAD_STREAM_LOCK (trans->sinkpad);
2162 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2164 trans->have_same_caps = FALSE;
2165 /* We can only reset the passthrough mode if the instance told us to
2166 handle it in configure_caps */
2167 if (bclass->passthrough_on_same_caps) {
2168 gst_base_transform_set_passthrough (trans, FALSE);
2170 gst_caps_replace (&trans->cache_caps1, NULL);
2171 gst_caps_replace (&trans->cache_caps2, NULL);
2173 if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
2174 result &= bclass->stop (trans);
2176 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2183 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2185 gboolean result = TRUE;
2186 GstBaseTransform *trans;
2188 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2190 result = gst_base_transform_activate (trans, active);
2193 trans->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
2195 gst_object_unref (trans);
2201 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2203 gboolean result = FALSE;
2204 GstBaseTransform *trans;
2206 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2208 result = gst_pad_activate_pull (trans->sinkpad, active);
2211 result &= gst_base_transform_activate (trans, active);
2214 trans->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
2216 gst_object_unref (trans);
2222 * gst_base_transform_set_passthrough:
2223 * @trans: the #GstBaseTransform to set
2224 * @passthrough: boolean indicating passthrough mode.
2226 * Set passthrough mode for this filter by default. This is mostly
2227 * useful for filters that do not care about negotiation.
2229 * Always TRUE for filters which don't implement either a transform
2230 * or transform_ip method.
2235 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2236 gboolean passthrough)
2238 GstBaseTransformClass *bclass;
2240 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2242 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2244 GST_OBJECT_LOCK (trans);
2245 if (passthrough == FALSE) {
2246 if (bclass->transform_ip || bclass->transform)
2247 trans->passthrough = FALSE;
2249 trans->passthrough = TRUE;
2252 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2253 GST_OBJECT_UNLOCK (trans);
2257 * gst_base_transform_is_passthrough:
2258 * @trans: the #GstBaseTransform to query
2260 * See if @trans is configured as a passthrough transform.
2262 * Returns: TRUE is the transform is configured in passthrough mode.
2267 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2271 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2273 GST_OBJECT_LOCK (trans);
2274 result = trans->passthrough;
2275 GST_OBJECT_UNLOCK (trans);
2281 * gst_base_transform_set_in_place:
2282 * @trans: the #GstBaseTransform to modify
2283 * @in_place: Boolean value indicating that we would like to operate
2284 * on in_place buffers.
2286 * Determines whether a non-writable buffer will be copied before passing
2287 * to the transform_ip function.
2289 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2290 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2296 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2298 GstBaseTransformClass *bclass;
2300 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2302 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2304 GST_OBJECT_LOCK (trans);
2307 if (bclass->transform_ip) {
2308 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2309 trans->always_in_place = TRUE;
2312 if (bclass->transform) {
2313 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2314 trans->always_in_place = FALSE;
2318 GST_OBJECT_UNLOCK (trans);
2322 * gst_base_transform_is_in_place:
2323 * @trans: the #GstBaseTransform to query
2325 * See if @trans is configured as a in_place transform.
2327 * Returns: TRUE is the transform is configured in in_place mode.
2332 gst_base_transform_is_in_place (GstBaseTransform * trans)
2336 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2338 GST_OBJECT_LOCK (trans);
2339 result = trans->always_in_place;
2340 GST_OBJECT_UNLOCK (trans);
2346 * gst_base_transform_update_qos:
2347 * @trans: a #GstBaseTransform
2348 * @proportion: the proportion
2349 * @diff: the diff against the clock
2350 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2353 * Set the QoS parameters in the transform. This function is called internally
2354 * when a QOS event is received but subclasses can provide custom information
2362 gst_base_transform_update_qos (GstBaseTransform * trans,
2363 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2366 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2368 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2369 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2370 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2372 GST_OBJECT_LOCK (trans);
2373 trans->priv->proportion = proportion;
2374 trans->priv->earliest_time = timestamp + diff;
2375 GST_OBJECT_UNLOCK (trans);
2379 * gst_base_transform_set_qos_enabled:
2380 * @trans: a #GstBaseTransform
2381 * @enabled: new state
2383 * Enable or disable QoS handling in the transform.
2390 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2392 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2394 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2396 GST_OBJECT_LOCK (trans);
2397 trans->priv->qos_enabled = enabled;
2398 GST_OBJECT_UNLOCK (trans);
2402 * gst_base_transform_is_qos_enabled:
2403 * @trans: a #GstBaseTransform
2405 * Queries if the transform will handle QoS.
2407 * Returns: TRUE if QoS is enabled.
2414 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2418 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2420 GST_OBJECT_LOCK (trans);
2421 result = trans->priv->qos_enabled;
2422 GST_OBJECT_UNLOCK (trans);
2428 * gst_base_transform_set_gap_aware:
2429 * @trans: a #GstBaseTransform
2430 * @gap_aware: New state
2432 * If @gap_aware is %FALSE (the default), output buffers will have the
2433 * %GST_BUFFER_FLAG_GAP flag unset.
2435 * If set to %TRUE, the element must handle output buffers with this flag set
2436 * correctly, i.e. it can assume that the buffer contains neutral data but must
2437 * unset the flag if the output is no neutral data.
2444 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2446 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2448 GST_OBJECT_LOCK (trans);
2449 trans->priv->gap_aware = gap_aware;
2450 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2451 GST_OBJECT_UNLOCK (trans);
2455 * gst_base_transform_suggest:
2456 * @trans: a #GstBaseTransform
2457 * @caps: (transfer none): caps to suggest
2458 * @size: buffer size to suggest
2460 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2466 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2469 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2471 /* push the renegotiate event */
2472 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2473 gst_event_new_reconfigure ()))
2474 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2478 * gst_base_transform_reconfigure:
2479 * @trans: a #GstBaseTransform
2481 * Instructs @trans to renegotiate a new downstream transform on the next
2482 * buffer. This function is typically called after properties on the transform
2483 * were set that influence the output format.
2488 gst_base_transform_reconfigure (GstBaseTransform * trans)
2490 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2492 GST_OBJECT_LOCK (trans);
2493 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2494 trans->priv->reconfigure = TRUE;
2495 GST_OBJECT_UNLOCK (trans);