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 */
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_mode (GstPad * pad,
302 GstObject * parent, GstPadMode mode, gboolean active);
303 static gboolean gst_base_transform_sink_activate_mode (GstPad * pad,
304 GstObject * parent, GstPadMode mode, gboolean active);
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, GstObject * parent,
312 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
314 static gboolean gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
316 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
318 static GstFlowReturn gst_base_transform_getrange (GstPad * pad,
319 GstObject * parent, guint64 offset, guint length, GstBuffer ** buffer);
320 static GstFlowReturn gst_base_transform_chain (GstPad * pad, GstObject * parent,
322 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
323 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
324 static void gst_base_transform_default_fixate (GstBaseTransform * trans,
325 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
326 static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
327 GstPad * pad, GstCaps * filter);
328 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
329 GstPadDirection direction, GstCaps * caps);
330 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
331 GstPad * pad, GstCaps * caps);
332 static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
334 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
335 GstPadDirection direction, GstQuery * query);
336 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
337 trans, GstPadDirection direction, GstCaps * caps, gsize size,
338 GstCaps * othercaps, gsize * othersize);
340 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
341 GstBuffer * inbuf, GstBuffer ** outbuf);
342 static gboolean default_copy_metadata (GstBaseTransform * trans,
343 GstBuffer * inbuf, GstBuffer * outbuf);
345 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
349 gst_base_transform_finalize (GObject * object)
351 GstBaseTransform *trans;
353 trans = GST_BASE_TRANSFORM (object);
355 g_mutex_free (trans->transform_lock);
357 G_OBJECT_CLASS (parent_class)->finalize (object);
361 gst_base_transform_class_init (GstBaseTransformClass * klass)
363 GObjectClass *gobject_class;
365 gobject_class = G_OBJECT_CLASS (klass);
367 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
368 "basetransform element");
370 GST_DEBUG ("gst_base_transform_class_init");
372 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
374 parent_class = g_type_class_peek_parent (klass);
376 gobject_class->set_property = gst_base_transform_set_property;
377 gobject_class->get_property = gst_base_transform_get_property;
379 g_object_class_install_property (gobject_class, PROP_QOS,
380 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
381 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
383 gobject_class->finalize = gst_base_transform_finalize;
385 klass->passthrough_on_same_caps = FALSE;
387 klass->transform_caps =
388 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
389 klass->fixate_caps = GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate);
391 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
392 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
393 klass->transform_size =
394 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
396 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
397 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
398 klass->prepare_output_buffer =
399 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
400 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
404 gst_base_transform_init (GstBaseTransform * trans,
405 GstBaseTransformClass * bclass)
407 GstPadTemplate *pad_template;
409 GST_DEBUG ("gst_base_transform_init");
411 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
414 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
415 g_return_if_fail (pad_template != NULL);
416 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
417 gst_pad_set_event_function (trans->sinkpad,
418 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
419 gst_pad_set_chain_function (trans->sinkpad,
420 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
421 gst_pad_set_activatemode_function (trans->sinkpad,
422 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
423 gst_pad_set_query_function (trans->sinkpad,
424 GST_DEBUG_FUNCPTR (gst_base_transform_query));
425 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
428 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
429 g_return_if_fail (pad_template != NULL);
430 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
431 gst_pad_set_event_function (trans->srcpad,
432 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
433 gst_pad_set_getrange_function (trans->srcpad,
434 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
435 gst_pad_set_activatemode_function (trans->srcpad,
436 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
437 gst_pad_set_query_function (trans->srcpad,
438 GST_DEBUG_FUNCPTR (gst_base_transform_query));
439 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
441 trans->transform_lock = g_mutex_new ();
442 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
443 trans->cache_caps1 = NULL;
444 trans->cache_caps2 = NULL;
445 trans->priv->pad_mode = GST_PAD_MODE_NONE;
446 trans->priv->gap_aware = FALSE;
448 trans->passthrough = FALSE;
449 if (bclass->transform == NULL) {
450 /* If no transform function, always_in_place is TRUE */
451 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
452 trans->always_in_place = TRUE;
454 if (bclass->transform_ip == NULL) {
455 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
456 trans->passthrough = TRUE;
460 trans->priv->processed = 0;
461 trans->priv->dropped = 0;
465 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
466 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
470 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
471 /* no transform function, use the identity transform */
473 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
475 ret = gst_caps_ref (caps);
480 /* given @caps on the src or sink pad (given by @direction)
481 * calculate the possible caps on the other pad.
483 * Returns new caps, unref after usage.
486 gst_base_transform_transform_caps (GstBaseTransform * trans,
487 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
490 GstBaseTransformClass *klass;
495 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
497 /* if there is a custom transform function, use this */
498 if (klass->transform_caps) {
499 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
501 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
502 ret = klass->transform_caps (trans, direction, caps, filter);
503 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
505 #ifndef G_DISABLE_ASSERT
507 if (!gst_caps_is_subset (ret, filter)) {
508 GstCaps *intersection;
510 GST_ERROR_OBJECT (trans,
511 "transform_caps returned caps %" GST_PTR_FORMAT
512 " which are not a real subset of the filter caps %"
513 GST_PTR_FORMAT, ret, filter);
514 g_warning ("%s: transform_caps returned caps which are not a real "
515 "subset of the filter caps", GST_ELEMENT_NAME (trans));
518 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
519 gst_caps_unref (ret);
526 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
532 gst_base_transform_default_transform_size (GstBaseTransform * trans,
533 GstPadDirection direction, GstCaps * caps, gsize size,
534 GstCaps * othercaps, gsize * othersize)
536 gsize inunitsize, outunitsize, units;
537 GstBaseTransformClass *klass;
539 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
541 if (klass->get_unit_size == NULL) {
542 /* if there is no transform_size and no unit_size, it means the
543 * element does not modify the size of a buffer */
546 /* there is no transform_size function, we have to use the unit_size
547 * functions. This method assumes there is a fixed unit_size associated with
548 * each caps. We provide the same amount of units on both sides. */
549 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
552 GST_DEBUG_OBJECT (trans,
553 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
556 /* input size must be a multiple of the unit_size of the input caps */
557 if (inunitsize == 0 || (size % inunitsize != 0))
560 /* get the amount of units */
561 units = size / inunitsize;
563 /* now get the unit size of the output */
564 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
567 /* the output size is the unit_size times the amount of units on the
569 *othersize = units * outunitsize;
570 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
578 GST_DEBUG_OBJECT (trans, "could not get in_size");
579 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
584 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
585 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
586 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
587 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
592 GST_DEBUG_OBJECT (trans, "could not get out_size");
593 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
598 /* transform a buffer of @size with @caps on the pad with @direction to
599 * the size of a buffer with @othercaps and store the result in @othersize
601 * We have two ways of doing this:
602 * 1) use a custom transform size function, this is for complicated custom
603 * cases with no fixed unit_size.
604 * 2) use the unit_size functions where there is a relationship between the
605 * caps and the size of a buffer.
608 gst_base_transform_transform_size (GstBaseTransform * trans,
609 GstPadDirection direction, GstCaps * caps,
610 gsize size, GstCaps * othercaps, gsize * othersize)
612 GstBaseTransformClass *klass;
613 gboolean ret = FALSE;
615 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
617 GST_DEBUG_OBJECT (trans,
618 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
619 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
620 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
622 if (klass->transform_size) {
623 /* if there is a custom transform function, use this */
624 ret = klass->transform_size (trans, direction, caps, size, othercaps,
630 /* get the caps that can be handled by @pad. We perform:
632 * - take the caps of peer of otherpad,
633 * - filter against the padtemplate of otherpad,
634 * - calculate all transforms of remaining caps
635 * - filter against template of @pad
637 * If there is no peer, we simply return the caps of the padtemplate of pad.
640 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
644 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
647 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
649 /* we can do what the peer can */
652 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
654 /* filtered against our padtemplate on the other side */
655 templ = gst_pad_get_pad_template_caps (pad);
656 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
657 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
658 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
659 gst_caps_unref (templ);
661 /* then see what we can transform this to */
662 peerfilter = gst_base_transform_transform_caps (trans,
663 GST_PAD_DIRECTION (pad), temp, NULL);
664 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
665 gst_caps_unref (temp);
667 /* and filter against the template of this pad */
668 templ = gst_pad_get_pad_template_caps (otherpad);
669 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
670 /* We keep the caps sorted like the returned caps */
672 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
673 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
674 gst_caps_unref (peerfilter);
675 gst_caps_unref (templ);
679 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
682 gst_caps_unref (peerfilter);
685 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
687 /* filtered against our padtemplate on the other side */
688 templ = gst_pad_get_pad_template_caps (otherpad);
689 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
690 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
691 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
692 gst_caps_unref (templ);
694 temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
697 /* then see what we can transform this to */
698 caps = gst_base_transform_transform_caps (trans,
699 GST_PAD_DIRECTION (otherpad), temp, filter);
700 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
701 gst_caps_unref (temp);
706 /* and filter against the template of this pad */
707 templ = gst_pad_get_pad_template_caps (pad);
708 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
709 /* We keep the caps sorted like the returned caps */
710 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
711 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
712 gst_caps_unref (caps);
713 gst_caps_unref (templ);
716 /* Now try if we can put the untransformed downstream caps first */
717 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
718 if (!gst_caps_is_empty (temp)) {
719 gst_caps_merge (temp, caps);
722 gst_caps_unref (temp);
725 gst_caps_unref (caps);
726 /* no peer or the peer can do anything, our padtemplate is enough then */
727 caps = gst_pad_get_pad_template_caps (pad);
732 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
733 gst_caps_unref (caps);
739 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
742 gst_caps_unref (peercaps);
748 gst_base_transform_set_allocation (GstBaseTransform * trans,
749 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
752 GstBufferPool *oldpool;
753 GstBaseTransformPrivate *priv = trans->priv;
757 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
758 if (!gst_buffer_pool_set_active (pool, TRUE))
759 goto activate_failed;
762 GST_OBJECT_LOCK (trans);
763 oldpool = priv->pool;
765 priv->allocator = allocator;
766 priv->prefix = prefix;
767 priv->alignment = alignment;
768 GST_OBJECT_UNLOCK (trans);
771 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
772 gst_buffer_pool_set_active (oldpool, FALSE);
773 gst_object_unref (oldpool);
780 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
786 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
789 gboolean result = TRUE;
790 GstBufferPool *pool = NULL, *oldpool;
791 guint size, min, max, prefix, alignment;
792 GstBaseTransformClass *klass;
793 const GstAllocator *allocator = NULL;
795 /* there are these possibilities:
797 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
798 * will do that whenever some upstream does an allocation query.
799 * 2) we need to do a transform, we need to get a bufferpool from downstream
800 * and configure it. When upstream does the ALLOCATION query, the
801 * propose_allocation vmethod will be called and we will configure the
802 * upstream allocator with our porposed values then.
806 oldpool = trans->priv->pool;
808 GST_DEBUG_OBJECT (trans, "unreffing old pool");
809 gst_buffer_pool_set_active (oldpool, FALSE);
810 gst_object_unref (oldpool);
811 trans->priv->pool = oldpool = NULL;
814 if (trans->passthrough || trans->always_in_place) {
815 /* we are in passthrough, the input buffer is never copied and always passed
816 * along. We never allocate an output buffer on the srcpad. What we do is
817 * let the upstream element decide if it wants to use a bufferpool and
818 * then we will proxy the downstream pool */
819 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
823 /* not passthrough, we need to allocate */
824 /* find a pool for the negotiated caps now */
825 GST_DEBUG_OBJECT (trans, "doing allocation query");
826 query = gst_query_new_allocation (outcaps, TRUE);
827 if (!gst_pad_peer_query (trans->srcpad, query)) {
828 /* not a problem, just debug a little */
829 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
832 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
834 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
835 if (G_LIKELY (klass->decide_allocation))
836 result = klass->decide_allocation (trans, query);
838 /* we got configuration from our peer, parse them */
839 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
843 const gchar *mem = NULL;
845 /* no size, we have variable size buffers */
846 if (gst_query_get_n_allocation_memories (query) > 0) {
847 mem = gst_query_parse_nth_allocation_memory (query, 0);
849 allocator = gst_allocator_find (mem);
850 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
851 } else if (pool == NULL) {
852 GstStructure *config;
854 /* we did not get a pool, make one ourselves then */
855 pool = gst_buffer_pool_new ();
857 GST_DEBUG_OBJECT (trans, "no pool, making one");
858 config = gst_buffer_pool_get_config (pool);
859 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
861 gst_buffer_pool_set_config (pool, config);
864 gst_query_unref (query);
868 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
874 /* function triggered when the in and out caps are negotiated and need
875 * to be configured in the subclass. */
877 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
881 GstBaseTransformClass *klass;
883 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
885 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
886 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
888 /* clear the cache */
889 gst_caps_replace (&trans->cache_caps1, NULL);
890 gst_caps_replace (&trans->cache_caps2, NULL);
892 /* figure out same caps state */
893 trans->have_same_caps = gst_caps_is_equal (in, out);
894 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
896 /* If we've a transform_ip method and same input/output caps, set in_place
897 * by default. If for some reason the sub-class prefers using a transform
898 * function, it can clear the in place flag in the set_caps */
899 gst_base_transform_set_in_place (trans,
900 klass->transform_ip && trans->have_same_caps);
902 /* Set the passthrough if the class wants passthrough_on_same_caps
903 * and we have the same caps on each pad */
904 if (klass->passthrough_on_same_caps)
905 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
907 /* now configure the element with the caps */
908 if (klass->set_caps) {
909 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
910 ret = klass->set_caps (trans, in, out);
913 trans->negotiated = ret;
919 gst_base_transform_default_fixate (GstBaseTransform * trans,
920 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
922 GST_DEBUG_OBJECT (trans, "using default caps fixate function");
923 gst_caps_fixate (othercaps);
926 /* given a fixed @caps on @pad, create the best possible caps for the
928 * @caps must be fixed when calling this function.
930 * This function calls the transform caps vmethod of the basetransform to figure
931 * out the possible target formats. It then tries to select the best format from
934 * - attempt passthrough if the target caps is a superset of the input caps
935 * - fixating by using peer caps
936 * - fixating with transform fixate function
937 * - fixating with pad fixate functions.
939 * this function returns a caps that can be transformed into and is accepted by
943 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
946 GstBaseTransformClass *klass;
947 GstPad *otherpad, *otherpeer;
951 /* caps must be fixed here, this is a programming error if it's not */
952 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
954 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
956 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
957 otherpeer = gst_pad_get_peer (otherpad);
959 /* see how we can transform the input caps. We need to do this even for
960 * passthrough because it might be possible that this element cannot support
961 * passthrough at all. */
962 othercaps = gst_base_transform_transform_caps (trans,
963 GST_PAD_DIRECTION (pad), caps, NULL);
965 /* The caps we can actually output is the intersection of the transformed
966 * caps with the pad template for the pad */
968 GstCaps *intersect, *templ_caps;
970 templ_caps = gst_pad_get_pad_template_caps (otherpad);
971 GST_DEBUG_OBJECT (trans,
972 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
975 gst_caps_intersect_full (othercaps, templ_caps,
976 GST_CAPS_INTERSECT_FIRST);
978 gst_caps_unref (othercaps);
979 gst_caps_unref (templ_caps);
980 othercaps = intersect;
983 /* check if transform is empty */
984 if (!othercaps || gst_caps_is_empty (othercaps))
987 /* if the othercaps are not fixed, we need to fixate them, first attempt
988 * is by attempting passthrough if the othercaps are a superset of caps. */
989 /* FIXME. maybe the caps is not fixed because it has multiple structures of
991 is_fixed = gst_caps_is_fixed (othercaps);
993 GST_DEBUG_OBJECT (trans,
994 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
996 /* Now let's see what the peer suggests based on our transformed caps */
998 GstCaps *peercaps, *intersection, *templ_caps;
1000 GST_DEBUG_OBJECT (trans,
1001 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1003 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1004 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1006 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1008 GST_DEBUG_OBJECT (trans,
1009 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1012 gst_caps_intersect_full (peercaps, templ_caps,
1013 GST_CAPS_INTERSECT_FIRST);
1014 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1015 gst_caps_unref (peercaps);
1016 gst_caps_unref (templ_caps);
1017 peercaps = intersection;
1019 GST_DEBUG_OBJECT (trans,
1020 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1022 gst_caps_intersect_full (peercaps, othercaps,
1023 GST_CAPS_INTERSECT_FIRST);
1024 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1025 gst_caps_unref (peercaps);
1026 gst_caps_unref (othercaps);
1027 othercaps = intersection;
1028 is_fixed = gst_caps_is_fixed (othercaps);
1030 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1031 gst_caps_unref (othercaps);
1032 othercaps = gst_caps_ref (caps);
1036 if (gst_caps_is_empty (othercaps))
1037 goto no_transform_possible;
1039 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1042 /* second attempt at fixation, call the fixate vmethod */
1043 /* caps could be fixed but the subclass may want to add fields */
1044 if (klass->fixate_caps) {
1045 othercaps = gst_caps_make_writable (othercaps);
1047 GST_DEBUG_OBJECT (trans, "calling faxate_caps for %" GST_PTR_FORMAT
1048 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1049 GST_DEBUG_PAD_NAME (otherpad));
1050 /* note that we pass the complete array of structures to the fixate
1051 * function, it needs to truncate itself */
1052 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1053 is_fixed = gst_caps_is_fixed (othercaps);
1054 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1057 /* caps should be fixed now, if not we have to fail. */
1059 goto could_not_fixate;
1061 /* and peer should accept */
1062 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1063 goto peer_no_accept;
1065 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1066 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1069 gst_object_unref (otherpeer);
1076 GST_DEBUG_OBJECT (trans,
1077 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1080 no_transform_possible:
1082 GST_DEBUG_OBJECT (trans,
1083 "transform could not transform %" GST_PTR_FORMAT
1084 " in anything we support", caps);
1089 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1094 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1095 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1101 gst_object_unref (otherpeer);
1103 gst_caps_unref (othercaps);
1109 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1110 GstPadDirection direction, GstCaps * caps)
1114 GstCaps *othercaps = NULL;
1116 gboolean ret = TRUE;
1119 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1121 /* we need fixed caps for the check, fall back to the default implementation
1123 if (!gst_caps_is_fixed (caps))
1128 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1130 /* get all the formats we can handle on this pad */
1131 if (direction == GST_PAD_SRC)
1132 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1134 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1137 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1138 goto no_transform_possible;
1141 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1143 /* intersect with the requested format */
1144 ret = gst_caps_is_subset (caps, allowed);
1145 gst_caps_unref (allowed);
1148 goto no_transform_possible;
1152 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1154 /* find best possible caps for the other pad as a way to see if we can
1155 * transform this caps. */
1156 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1157 if (!othercaps || gst_caps_is_empty (othercaps))
1158 goto no_transform_possible;
1160 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1166 /* We know it's always NULL since we never use it */
1168 gst_caps_unref (othercaps);
1174 no_transform_possible:
1176 GST_DEBUG_OBJECT (trans,
1177 "transform could not transform %" GST_PTR_FORMAT
1178 " in anything we support", caps);
1184 /* called when new caps arrive on the sink or source pad,
1185 * We try to find the best caps for the other side using our _find_transform()
1186 * function. If there are caps, we configure the transform for this new
1189 * FIXME, this function is currently commutative but this should not really be
1190 * because we never set caps starting from the srcpad.
1193 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1196 GstPad *otherpad, *otherpeer;
1197 GstCaps *othercaps = NULL;
1198 gboolean ret = TRUE;
1199 GstCaps *incaps, *outcaps;
1201 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1202 otherpeer = gst_pad_get_peer (otherpad);
1204 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1206 /* find best possible caps for the other pad */
1207 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1208 if (!othercaps || gst_caps_is_empty (othercaps))
1209 goto no_transform_possible;
1211 /* configure the element now */
1212 /* make sure in and out caps are correct */
1213 if (pad == trans->sinkpad) {
1215 outcaps = othercaps;
1221 /* if we have the same caps, we can optimize and reuse the input caps */
1222 if (gst_caps_is_equal (incaps, outcaps)) {
1223 GST_INFO_OBJECT (trans, "reuse caps");
1224 gst_caps_unref (othercaps);
1225 outcaps = othercaps = gst_caps_ref (incaps);
1228 /* call configure now */
1229 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1230 goto failed_configure;
1232 GST_OBJECT_LOCK (trans->sinkpad);
1233 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1234 trans->priv->reconfigure = FALSE;
1235 GST_OBJECT_UNLOCK (trans->sinkpad);
1237 /* we know this will work, we implement the setcaps */
1238 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1240 if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_MODE_PULL) {
1242 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1244 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1250 /* try to get a pool when needed */
1251 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1256 gst_object_unref (otherpeer);
1258 gst_caps_unref (othercaps);
1260 trans->negotiated = ret;
1265 no_transform_possible:
1267 GST_WARNING_OBJECT (trans,
1268 "transform could not transform %" GST_PTR_FORMAT
1269 " in anything we support", caps);
1275 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1276 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1283 gst_base_transform_default_query (GstBaseTransform * trans,
1284 GstPadDirection direction, GstQuery * query)
1286 gboolean ret = FALSE;
1287 GstPad *pad, *otherpad;
1288 GstBaseTransformClass *klass;
1290 if (direction == GST_PAD_SRC) {
1291 pad = trans->srcpad;
1292 otherpad = trans->sinkpad;
1294 pad = trans->sinkpad;
1295 otherpad = trans->srcpad;
1298 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1300 switch (GST_QUERY_TYPE (query)) {
1301 case GST_QUERY_ALLOCATION:
1303 gboolean passthrough;
1305 /* can only be done on the sinkpad */
1306 if (direction != GST_PAD_SINK)
1309 GST_BASE_TRANSFORM_LOCK (trans);
1310 passthrough = trans->passthrough || trans->always_in_place;
1311 GST_BASE_TRANSFORM_UNLOCK (trans);
1314 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1315 ret = gst_pad_peer_query (otherpad, query);
1317 GST_DEBUG_OBJECT (trans, "propose allocation values");
1318 /* pass the query to the propose_allocation vmethod if any */
1319 if (G_LIKELY (klass->propose_allocation))
1320 ret = klass->propose_allocation (trans, query);
1324 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1328 case GST_QUERY_POSITION:
1332 gst_query_parse_position (query, &format, NULL);
1333 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1337 if ((direction == GST_PAD_SINK)
1338 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1340 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1341 trans->segment.position);
1343 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1344 trans->priv->position_out);
1346 gst_query_set_position (query, format, pos);
1348 ret = gst_pad_peer_query (otherpad, query);
1352 case GST_QUERY_ACCEPT_CAPS:
1356 gst_query_parse_accept_caps (query, &caps);
1357 if (klass->accept_caps) {
1358 ret = klass->accept_caps (trans, direction, caps);
1359 gst_query_set_accept_caps_result (query, ret);
1360 /* return TRUE, we answered the query */
1365 case GST_QUERY_CAPS:
1367 GstCaps *filter, *caps;
1369 gst_query_parse_caps (query, &filter);
1370 caps = gst_base_transform_query_caps (trans, pad, filter);
1371 gst_query_set_caps_result (query, caps);
1372 gst_caps_unref (caps);
1377 ret = gst_pad_peer_query (otherpad, query);
1386 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1388 GstBaseTransform *trans;
1389 GstBaseTransformClass *bclass;
1390 gboolean ret = FALSE;
1392 trans = GST_BASE_TRANSFORM (parent);
1393 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1396 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1401 /* this function either returns the input buffer without incrementing the
1402 * refcount or it allocates a new (writable) buffer */
1403 static GstFlowReturn
1404 default_prepare_output_buffer (GstBaseTransform * trans,
1405 GstBuffer * inbuf, GstBuffer ** outbuf)
1407 GstBaseTransformPrivate *priv;
1408 GstFlowReturn ret = GST_FLOW_OK;
1409 GstBaseTransformClass *bclass;
1412 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1414 /* figure out how to allocate an output buffer */
1415 if (trans->passthrough) {
1416 /* passthrough, we will not modify the incomming buffer so we can just
1418 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1421 /* we can't reuse the input buffer */
1423 GST_DEBUG_OBJECT (trans, "using pool alloc");
1424 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1426 gsize insize, outsize;
1429 /* no pool, we need to figure out the size of the output buffer first */
1430 insize = gst_buffer_get_size (inbuf);
1432 if (trans->passthrough) {
1433 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1434 /* passthrough, the output size is the same as the input size. */
1437 gboolean want_in_place = (bclass->transform_ip != NULL)
1438 && trans->always_in_place;
1440 if (want_in_place) {
1441 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1442 /* we alloc a buffer of the same size as the input */
1445 GstCaps *incaps, *outcaps;
1447 /* else use the transform function to get the size */
1448 incaps = gst_pad_get_current_caps (trans->sinkpad);
1449 outcaps = gst_pad_get_current_caps (trans->srcpad);
1451 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1452 /* copy transform, figure out the output size */
1453 res = gst_base_transform_transform_size (trans,
1454 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1456 gst_caps_unref (incaps);
1457 gst_caps_unref (outcaps);
1463 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1465 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1473 GST_ERROR_OBJECT (trans, "unknown output size");
1474 return GST_FLOW_ERROR;
1479 default_copy_metadata (GstBaseTransform * trans,
1480 GstBuffer * inbuf, GstBuffer * outbuf)
1482 GstBaseTransformPrivate *priv = trans->priv;
1484 /* now copy the metadata */
1485 GST_DEBUG_OBJECT (trans, "copying metadata");
1487 /* this should not happen, buffers allocated from a pool or with
1488 * new_allocate should always be writable. */
1489 if (!gst_buffer_is_writable (outbuf))
1492 /* when we get here, the metadata should be writable */
1493 gst_buffer_copy_into (outbuf, inbuf,
1494 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1496 /* clear the GAP flag when the subclass does not understand it */
1497 if (!priv->gap_aware)
1498 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1505 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1510 /* Given @caps calcultate the size of one unit.
1512 * For video caps, this is the size of one frame (and thus one buffer).
1513 * For audio caps, this is the size of one sample.
1515 * These values are cached since they do not change and the calculation
1516 * potentially involves parsing caps and other expensive stuff.
1518 * We have two cache locations to store the size, one for the source caps
1519 * and one for the sink caps.
1521 * this function returns FALSE if no size could be calculated.
1524 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1527 gboolean res = FALSE;
1528 GstBaseTransformClass *bclass;
1530 /* see if we have the result cached */
1531 if (trans->cache_caps1 == caps) {
1532 *size = trans->cache_caps1_size;
1533 GST_DEBUG_OBJECT (trans,
1534 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1537 if (trans->cache_caps2 == caps) {
1538 *size = trans->cache_caps2_size;
1539 GST_DEBUG_OBJECT (trans,
1540 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1544 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1545 res = bclass->get_unit_size (trans, caps, size);
1546 GST_DEBUG_OBJECT (trans,
1547 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1548 caps, *size, res ? "TRUE" : "FALSE");
1551 /* and cache the values */
1552 if (trans->cache_caps1 == NULL) {
1553 gst_caps_replace (&trans->cache_caps1, caps);
1554 trans->cache_caps1_size = *size;
1555 GST_DEBUG_OBJECT (trans,
1556 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1557 } else if (trans->cache_caps2 == NULL) {
1558 gst_caps_replace (&trans->cache_caps2, caps);
1559 trans->cache_caps2_size = *size;
1560 GST_DEBUG_OBJECT (trans,
1561 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1563 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1570 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1573 GstBaseTransform *trans;
1574 GstBaseTransformClass *bclass;
1575 gboolean ret = TRUE;
1577 trans = GST_BASE_TRANSFORM (parent);
1578 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1580 if (bclass->sink_event)
1581 ret = bclass->sink_event (trans, event);
1583 gst_event_unref (event);
1589 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1591 gboolean ret = TRUE, forward = TRUE;
1593 switch (GST_EVENT_TYPE (event)) {
1594 case GST_EVENT_FLUSH_START:
1596 case GST_EVENT_FLUSH_STOP:
1597 GST_OBJECT_LOCK (trans);
1598 /* reset QoS parameters */
1599 trans->priv->proportion = 1.0;
1600 trans->priv->earliest_time = -1;
1601 trans->priv->discont = FALSE;
1602 trans->priv->processed = 0;
1603 trans->priv->dropped = 0;
1604 GST_OBJECT_UNLOCK (trans);
1605 /* we need new segment info after the flush. */
1606 trans->have_segment = FALSE;
1607 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1608 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1614 case GST_EVENT_CAPS:
1618 gst_event_parse_caps (event, &caps);
1619 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1624 case GST_EVENT_SEGMENT:
1626 gst_event_copy_segment (event, &trans->segment);
1627 trans->have_segment = TRUE;
1629 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1638 ret = gst_pad_push_event (trans->srcpad, event);
1640 gst_event_unref (event);
1646 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1649 GstBaseTransform *trans;
1650 GstBaseTransformClass *bclass;
1651 gboolean ret = TRUE;
1653 trans = GST_BASE_TRANSFORM (parent);
1654 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1656 if (bclass->src_event)
1657 ret = bclass->src_event (trans, event);
1659 gst_event_unref (event);
1665 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1669 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1671 switch (GST_EVENT_TYPE (event)) {
1672 case GST_EVENT_SEEK:
1674 case GST_EVENT_NAVIGATION:
1679 GstClockTimeDiff diff;
1680 GstClockTime timestamp;
1682 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1683 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1690 ret = gst_pad_push_event (trans->sinkpad, event);
1695 /* perform a transform on @inbuf and put the result in @outbuf.
1697 * This function is common to the push and pull-based operations.
1699 * This function takes ownership of @inbuf */
1700 static GstFlowReturn
1701 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1702 GstBuffer ** outbuf)
1704 GstBaseTransformClass *bclass;
1705 GstFlowReturn ret = GST_FLOW_OK;
1706 gboolean want_in_place;
1707 GstClockTime running_time;
1708 GstClockTime timestamp;
1709 gboolean reconfigure;
1711 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1713 GST_OBJECT_LOCK (trans->sinkpad);
1714 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1715 || trans->priv->reconfigure;
1716 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1717 trans->priv->reconfigure = FALSE;
1718 GST_OBJECT_UNLOCK (trans->sinkpad);
1720 if (G_UNLIKELY (reconfigure)) {
1723 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1725 incaps = gst_pad_get_current_caps (trans->sinkpad);
1727 goto no_reconfigure;
1729 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1730 * will reconfigure the transform with the new output format. We can only
1731 * do this if the buffer actually has caps. */
1732 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1733 gst_caps_unref (incaps);
1734 goto not_negotiated;
1736 gst_caps_unref (incaps);
1740 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1741 GST_DEBUG_OBJECT (trans,
1742 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1743 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1744 GST_BUFFER_OFFSET (inbuf));
1746 GST_DEBUG_OBJECT (trans,
1747 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1748 gst_buffer_get_size (inbuf));
1750 /* Don't allow buffer handling before negotiation, except in passthrough mode
1751 * or if the class doesn't implement a set_caps function (in which case it doesn't
1754 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1755 goto not_negotiated;
1757 /* Set discont flag so we can mark the outgoing buffer */
1758 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1759 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1760 trans->priv->discont = TRUE;
1763 /* can only do QoS if the segment is in TIME */
1764 if (trans->segment.format != GST_FORMAT_TIME)
1767 /* QOS is done on the running time of the buffer, get it now */
1768 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1769 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1772 if (running_time != -1) {
1774 GstClockTime earliest_time;
1777 /* lock for getting the QoS parameters that are set (in a different thread)
1778 * with the QOS events */
1779 GST_OBJECT_LOCK (trans);
1780 earliest_time = trans->priv->earliest_time;
1781 proportion = trans->priv->proportion;
1782 /* check for QoS, don't perform conversion for buffers
1783 * that are known to be late. */
1784 need_skip = trans->priv->qos_enabled &&
1785 earliest_time != -1 && running_time <= earliest_time;
1786 GST_OBJECT_UNLOCK (trans);
1789 GstMessage *qos_msg;
1790 GstClockTime duration;
1791 guint64 stream_time;
1794 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1795 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1796 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1798 trans->priv->dropped++;
1800 duration = GST_BUFFER_DURATION (inbuf);
1802 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1804 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1807 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1808 stream_time, timestamp, duration);
1809 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1810 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1811 trans->priv->processed, trans->priv->dropped);
1812 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1814 /* mark discont for next buffer */
1815 trans->priv->discont = TRUE;
1822 /* first try to allocate an output buffer based on the currently negotiated
1823 * format. outbuf will contain a buffer suitable for doing the configured
1824 * transform after this function. */
1825 if (bclass->prepare_output_buffer == NULL)
1828 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1829 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1831 if (ret != GST_FLOW_OK || *outbuf == NULL)
1834 if (inbuf == *outbuf) {
1835 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1836 } else if (trans->passthrough) {
1837 /* we are asked to perform a passthrough transform but the input and
1838 * output buffers are different. We have to discard the output buffer and
1839 * reuse the input buffer. This is rather weird, it means that the prepare
1840 * output buffer does something wrong. */
1841 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1842 "prepare_output_buffer implementation");
1843 gst_buffer_unref (*outbuf);
1846 /* copy the metadata */
1847 if (bclass->copy_metadata)
1848 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1849 /* something failed, post a warning */
1850 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1851 ("could not copy metadata"), (NULL));
1854 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1857 /* now perform the needed transform */
1858 if (trans->passthrough) {
1859 /* In passthrough mode, give transform_ip a look at the
1860 * buffer, without making it writable, or just push the
1862 if (bclass->transform_ip) {
1863 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1864 ret = bclass->transform_ip (trans, *outbuf);
1866 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1869 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1871 if (want_in_place) {
1872 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1874 if (inbuf != *outbuf) {
1875 guint8 *indata, *outdata;
1876 gsize insize, outsize;
1878 /* Different buffer. The data can still be the same when we are dealing
1879 * with subbuffers of the same buffer. Note that because of the FIXME in
1880 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1881 * outbuf to keep them writable */
1882 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1883 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1885 if (indata != outdata)
1886 memcpy (outdata, indata, insize);
1888 gst_buffer_unmap (inbuf, indata, insize);
1889 gst_buffer_unmap (*outbuf, outdata, outsize);
1891 ret = bclass->transform_ip (trans, *outbuf);
1893 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1895 if (bclass->transform)
1896 ret = bclass->transform (trans, inbuf, *outbuf);
1898 ret = GST_FLOW_NOT_SUPPORTED;
1903 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1904 * the input buffer, no refcount is changed to keep the input buffer writable
1906 if (*outbuf != inbuf)
1907 gst_buffer_unref (inbuf);
1914 gst_buffer_unref (inbuf);
1916 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1917 ("not negotiated"), ("not negotiated"));
1918 return GST_FLOW_NOT_NEGOTIATED;
1922 gst_buffer_unref (inbuf);
1923 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1924 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1925 return GST_FLOW_NOT_SUPPORTED;
1929 gst_buffer_unref (inbuf);
1931 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1932 gst_flow_get_name (ret));
1937 /* FIXME, getrange is broken, need to pull range from the other
1938 * end based on the transform_size result.
1940 static GstFlowReturn
1941 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
1942 guint length, GstBuffer ** buffer)
1944 GstBaseTransform *trans;
1945 GstBaseTransformClass *klass;
1949 trans = GST_BASE_TRANSFORM (parent);
1951 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1952 if (G_UNLIKELY (ret != GST_FLOW_OK))
1955 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1956 if (klass->before_transform)
1957 klass->before_transform (trans, inbuf);
1959 GST_BASE_TRANSFORM_LOCK (trans);
1960 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1961 GST_BASE_TRANSFORM_UNLOCK (trans);
1969 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1970 gst_flow_get_name (ret));
1975 static GstFlowReturn
1976 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
1978 GstBaseTransform *trans;
1979 GstBaseTransformClass *klass;
1981 GstClockTime position = GST_CLOCK_TIME_NONE;
1982 GstClockTime timestamp, duration;
1983 GstBuffer *outbuf = NULL;
1985 trans = GST_BASE_TRANSFORM (parent);
1987 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1988 duration = GST_BUFFER_DURATION (buffer);
1990 /* calculate end position of the incoming buffer */
1991 if (timestamp != GST_CLOCK_TIME_NONE) {
1992 if (duration != GST_CLOCK_TIME_NONE)
1993 position = timestamp + duration;
1995 position = timestamp;
1998 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1999 if (klass->before_transform)
2000 klass->before_transform (trans, buffer);
2002 /* protect transform method and concurrent buffer alloc */
2003 GST_BASE_TRANSFORM_LOCK (trans);
2004 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2005 GST_BASE_TRANSFORM_UNLOCK (trans);
2007 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2008 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2009 if (outbuf != NULL) {
2010 if (ret == GST_FLOW_OK) {
2011 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2013 /* Remember last stop position */
2014 if (position != GST_CLOCK_TIME_NONE &&
2015 trans->segment.format == GST_FORMAT_TIME)
2016 trans->segment.position = position;
2018 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2019 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2020 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2021 position_out += GST_BUFFER_DURATION (outbuf);
2022 } else if (position != GST_CLOCK_TIME_NONE) {
2023 position_out = position;
2025 if (position_out != GST_CLOCK_TIME_NONE
2026 && trans->segment.format == GST_FORMAT_TIME)
2027 trans->priv->position_out = position_out;
2029 /* apply DISCONT flag if the buffer is not yet marked as such */
2030 if (trans->priv->discont) {
2031 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2032 outbuf = gst_buffer_make_writable (outbuf);
2033 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2035 trans->priv->discont = FALSE;
2037 trans->priv->processed++;
2039 ret = gst_pad_push (trans->srcpad, outbuf);
2041 gst_buffer_unref (outbuf);
2045 /* convert internal flow to OK and mark discont for the next buffer. */
2046 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2047 trans->priv->discont = TRUE;
2055 gst_base_transform_set_property (GObject * object, guint prop_id,
2056 const GValue * value, GParamSpec * pspec)
2058 GstBaseTransform *trans;
2060 trans = GST_BASE_TRANSFORM (object);
2064 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2067 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2073 gst_base_transform_get_property (GObject * object, guint prop_id,
2074 GValue * value, GParamSpec * pspec)
2076 GstBaseTransform *trans;
2078 trans = GST_BASE_TRANSFORM (object);
2082 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2085 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2090 /* not a vmethod of anything, just an internal method */
2092 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2094 GstBaseTransformClass *bclass;
2095 gboolean result = TRUE;
2097 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2100 GstCaps *incaps, *outcaps;
2102 if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2103 result &= bclass->start (trans);
2105 incaps = gst_pad_get_current_caps (trans->sinkpad);
2106 outcaps = gst_pad_get_current_caps (trans->srcpad);
2108 GST_OBJECT_LOCK (trans);
2109 if (incaps && outcaps)
2110 trans->have_same_caps =
2111 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2113 trans->have_same_caps = trans->passthrough;
2114 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2115 trans->negotiated = FALSE;
2116 trans->have_segment = FALSE;
2117 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2118 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2119 trans->priv->proportion = 1.0;
2120 trans->priv->earliest_time = -1;
2121 trans->priv->discont = FALSE;
2122 trans->priv->processed = 0;
2123 trans->priv->dropped = 0;
2124 GST_OBJECT_UNLOCK (trans);
2127 gst_caps_unref (incaps);
2129 gst_caps_unref (outcaps);
2131 /* We must make sure streaming has finished before resetting things
2132 * and calling the ::stop vfunc */
2133 GST_PAD_STREAM_LOCK (trans->sinkpad);
2134 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2136 trans->have_same_caps = FALSE;
2137 /* We can only reset the passthrough mode if the instance told us to
2138 handle it in configure_caps */
2139 if (bclass->passthrough_on_same_caps) {
2140 gst_base_transform_set_passthrough (trans, FALSE);
2142 gst_caps_replace (&trans->cache_caps1, NULL);
2143 gst_caps_replace (&trans->cache_caps2, NULL);
2145 if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2146 result &= bclass->stop (trans);
2148 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2155 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2156 GstPadMode mode, gboolean active)
2158 gboolean result = FALSE;
2159 GstBaseTransform *trans;
2161 trans = GST_BASE_TRANSFORM (parent);
2164 case GST_PAD_MODE_PUSH:
2166 result = gst_base_transform_activate (trans, active);
2169 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2181 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2182 GstPadMode mode, gboolean active)
2184 gboolean result = FALSE;
2185 GstBaseTransform *trans;
2187 trans = GST_BASE_TRANSFORM (parent);
2190 case GST_PAD_MODE_PULL:
2193 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2196 result &= gst_base_transform_activate (trans, active);
2199 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
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);