2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
4 * 2005 Andy Wingo <wingo@fluendo.com>
5 * 2005 Thomas Vander Stichele <thomas at apestaart dot org>
6 * 2008 Wim Taymans <wim.taymans@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * SECTION:gstbasetransform
26 * @short_description: Base class for simple transform filters
27 * @see_also: #GstBaseSrc, #GstBaseSink
29 * This base class is for filter elements that process data.
33 * <listitem><para>one sinkpad and one srcpad</para></listitem>
35 * Possible formats on sink and source pad implemented
36 * with custom transform_caps function. By default uses
37 * same format on sink and source.
39 * <listitem><para>Handles state changes</para></listitem>
40 * <listitem><para>Does flushing</para></listitem>
41 * <listitem><para>Push mode</para></listitem>
43 * Pull mode if the sub-class transform can operate on arbitrary data
48 * <title>Use Cases</title>
52 * <itemizedlist><title>Passthrough mode</title>
54 * Element has no interest in modifying the buffer. It may want to inspect it,
55 * in which case the element should have a transform_ip function. If there
56 * is no transform_ip function in passthrough mode, the buffer is pushed
60 * On the GstBaseTransformClass is the passthrough_on_same_caps variable
61 * which will automatically set/unset passthrough based on whether the
62 * element negotiates the same caps on both pads.
65 * passthrough_on_same_caps on an element that doesn't implement a
66 * transform_caps function is useful for elements that only inspect data
71 * <title>Example elements</title>
72 * <listitem>Level</listitem>
73 * <listitem>Videoscale, audioconvert, ffmpegcolorspace, audioresample in
74 * certain modes.</listitem>
79 * <title>Modifications in-place - input buffer and output buffer are the
82 * The element must implement a transform_ip function.
85 * Output buffer size must <= input buffer size
88 * If the always_in_place flag is set, non-writable buffers will be copied
89 * and passed to the transform_ip function, otherwise a new buffer will be
90 * created and the transform function called.
93 * Incoming writable buffers will be passed to the transform_ip function
94 * immediately. </para></listitem>
96 * only implementing transform_ip and not transform implies always_in_place
101 * <title>Example elements</title>
102 * <listitem>Volume</listitem>
103 * <listitem>Audioconvert in certain modes (signed/unsigned
104 * conversion)</listitem>
105 * <listitem>ffmpegcolorspace in certain modes (endianness
106 * swapping)</listitem>
111 * <title>Modifications only to the caps/metadata of a buffer</title>
113 * The element does not require writable data, but non-writable buffers
114 * should be subbuffered so that the meta-information can be replaced.
117 * Elements wishing to operate in this mode should replace the
118 * prepare_output_buffer method to create subbuffers of the input buffer
119 * and set always_in_place to TRUE
123 * <title>Example elements</title>
124 * <listitem>Capsfilter when setting caps on outgoing buffers that have
126 * <listitem>identity when it is going to re-timestamp buffers by
127 * datarate.</listitem>
131 * <itemizedlist><title>Normal mode</title>
133 * always_in_place flag is not set, or there is no transform_ip function
136 * Element will receive an input buffer and output buffer to operate on.
139 * Output buffer is allocated by calling the prepare_output_buffer function.
143 * <title>Example elements</title>
144 * <listitem>Videoscale, ffmpegcolorspace, audioconvert when doing
145 * scaling/conversions</listitem>
149 * <itemizedlist><title>Special output buffer allocations</title>
151 * Elements which need to do special allocation of their output buffers
152 * other than what gst_buffer_pad_alloc allows should implement a
153 * prepare_output_buffer method, which calls the parent implementation and
154 * passes the newly allocated buffer.
158 * <title>Example elements</title>
159 * <listitem>efence</listitem>
166 * <title>Sub-class settable flags on GstBaseTransform</title>
170 * <itemizedlist><title>passthrough</title>
172 * Implies that in the current configuration, the sub-class is not
173 * interested in modifying the buffers.
176 * Elements which are always in passthrough mode whenever the same caps
177 * has been negotiated on both pads can set the class variable
178 * passthrough_on_same_caps to have this behaviour automatically.
183 * <itemizedlist><title>always_in_place</title>
185 * Determines whether a non-writable buffer will be copied before passing
186 * to the transform_ip function.
189 * Implied TRUE if no transform function is implemented.
192 * Implied FALSE if ONLY transform function is implemented.
208 #include "../../../gst/gst_private.h"
209 #include "../../../gst/gst-i18n-lib.h"
210 #include "gstbasetransform.h"
211 #include <gst/gstmarshal.h>
213 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
214 #define GST_CAT_DEFAULT gst_base_transform_debug
216 /* BaseTransform signals and args */
223 #define DEFAULT_PROP_QOS FALSE
231 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
232 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
234 struct _GstBaseTransformPrivate
236 /* QoS *//* with LOCK */
237 gboolean qos_enabled;
239 GstClockTime earliest_time;
240 /* previous buffer had a discont */
243 GstPadActivateMode pad_mode;
247 gboolean reconfigure;
253 GstClockTime position_out;
256 const GstAllocator *allocator;
262 static GstElementClass *parent_class = NULL;
264 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
265 static void gst_base_transform_init (GstBaseTransform * trans,
266 GstBaseTransformClass * klass);
268 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
269 * method to get to the padtemplates */
271 gst_base_transform_get_type (void)
273 static volatile gsize base_transform_type = 0;
275 if (g_once_init_enter (&base_transform_type)) {
277 static const GTypeInfo base_transform_info = {
278 sizeof (GstBaseTransformClass),
281 (GClassInitFunc) gst_base_transform_class_init,
284 sizeof (GstBaseTransform),
286 (GInstanceInitFunc) gst_base_transform_init,
289 _type = g_type_register_static (GST_TYPE_ELEMENT,
290 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
291 g_once_init_leave (&base_transform_type, _type);
293 return base_transform_type;
296 static void gst_base_transform_finalize (GObject * object);
297 static void gst_base_transform_set_property (GObject * object, guint prop_id,
298 const GValue * value, GParamSpec * pspec);
299 static void gst_base_transform_get_property (GObject * object, guint prop_id,
300 GValue * value, GParamSpec * pspec);
301 static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
303 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
305 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
307 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
308 GstCaps * caps, gsize * size);
310 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
311 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
313 static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
314 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
316 static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
317 guint length, GstBuffer ** buffer);
318 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
320 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
321 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
322 static void gst_base_transform_default_fixate (GstBaseTransform * trans,
323 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
324 static GstCaps *gst_base_transform_getcaps (GstPad * pad, GstCaps * filter);
325 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
326 GstPadDirection direction, GstCaps * caps);
327 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
328 GstPad * pad, GstCaps * caps);
329 static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
330 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
331 GstPadDirection direction, GstQuery * query);
332 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
333 trans, GstPadDirection direction, GstCaps * caps, gsize size,
334 GstCaps * othercaps, gsize * othersize);
336 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
337 GstBuffer * inbuf, GstBuffer ** outbuf);
338 static gboolean default_copy_metadata (GstBaseTransform * trans,
339 GstBuffer * inbuf, GstBuffer * outbuf);
341 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
345 gst_base_transform_finalize (GObject * object)
347 GstBaseTransform *trans;
349 trans = GST_BASE_TRANSFORM (object);
351 g_mutex_free (trans->transform_lock);
353 G_OBJECT_CLASS (parent_class)->finalize (object);
357 gst_base_transform_class_init (GstBaseTransformClass * klass)
359 GObjectClass *gobject_class;
361 gobject_class = G_OBJECT_CLASS (klass);
363 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
364 "basetransform element");
366 GST_DEBUG ("gst_base_transform_class_init");
368 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
370 parent_class = g_type_class_peek_parent (klass);
372 gobject_class->set_property = gst_base_transform_set_property;
373 gobject_class->get_property = gst_base_transform_get_property;
375 g_object_class_install_property (gobject_class, PROP_QOS,
376 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
377 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
379 gobject_class->finalize = gst_base_transform_finalize;
381 klass->passthrough_on_same_caps = FALSE;
383 klass->transform_caps =
384 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
385 klass->fixate_caps = GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate);
387 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
388 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
389 klass->transform_size =
390 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
392 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
393 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
394 klass->prepare_output_buffer =
395 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
396 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
400 gst_base_transform_init (GstBaseTransform * trans,
401 GstBaseTransformClass * bclass)
403 GstPadTemplate *pad_template;
405 GST_DEBUG ("gst_base_transform_init");
407 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
410 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
411 g_return_if_fail (pad_template != NULL);
412 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
413 gst_pad_set_getcaps_function (trans->sinkpad,
414 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
415 gst_pad_set_event_function (trans->sinkpad,
416 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
417 gst_pad_set_chain_function (trans->sinkpad,
418 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
419 gst_pad_set_activatepush_function (trans->sinkpad,
420 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
421 gst_pad_set_query_function (trans->sinkpad,
422 GST_DEBUG_FUNCPTR (gst_base_transform_query));
423 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
426 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
427 g_return_if_fail (pad_template != NULL);
428 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
429 gst_pad_set_getcaps_function (trans->srcpad,
430 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
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_activatepull_function (trans->srcpad,
436 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
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_ACTIVATE_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 (intersection);
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_getcaps (GstPad * pad, GstCaps * filter)
642 GstBaseTransform *trans;
644 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
647 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
649 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
651 /* we can do what the peer can */
654 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
656 /* filtered against our padtemplate on the other side */
657 templ = gst_pad_get_pad_template_caps (pad);
658 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
659 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
660 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
661 gst_caps_unref (templ);
663 /* then see what we can transform this to */
664 peerfilter = gst_base_transform_transform_caps (trans,
665 GST_PAD_DIRECTION (pad), temp, NULL);
666 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
667 gst_caps_unref (temp);
669 /* and filter against the template of this pad */
670 templ = gst_pad_get_pad_template_caps (otherpad);
671 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
672 /* We keep the caps sorted like the returned caps */
674 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
675 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
676 gst_caps_unref (peerfilter);
677 gst_caps_unref (templ);
681 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
684 gst_caps_unref (peerfilter);
687 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
689 /* filtered against our padtemplate on the other side */
690 templ = gst_pad_get_pad_template_caps (otherpad);
691 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
692 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
693 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
694 gst_caps_unref (templ);
696 temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
699 /* then see what we can transform this to */
700 caps = gst_base_transform_transform_caps (trans,
701 GST_PAD_DIRECTION (otherpad), temp, filter);
702 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
703 gst_caps_unref (temp);
708 /* and filter against the template of this pad */
709 templ = gst_pad_get_pad_template_caps (pad);
710 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
711 /* We keep the caps sorted like the returned caps */
712 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
713 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
714 gst_caps_unref (caps);
715 gst_caps_unref (templ);
718 /* Now try if we can put the untransformed downstream caps first */
719 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
720 if (!gst_caps_is_empty (temp)) {
721 gst_caps_merge (temp, caps);
724 gst_caps_unref (temp);
727 gst_caps_unref (caps);
728 /* no peer or the peer can do anything, our padtemplate is enough then */
729 caps = gst_pad_get_pad_template_caps (pad);
734 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
735 gst_caps_unref (caps);
741 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
744 gst_caps_unref (peercaps);
746 gst_object_unref (trans);
752 gst_base_transform_set_allocation (GstBaseTransform * trans,
753 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
756 GstBufferPool *oldpool;
757 GstBaseTransformPrivate *priv = trans->priv;
761 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
762 if (!gst_buffer_pool_set_active (pool, TRUE))
763 goto activate_failed;
766 GST_OBJECT_LOCK (trans);
767 oldpool = priv->pool;
769 priv->allocator = allocator;
770 priv->prefix = prefix;
771 priv->alignment = alignment;
772 GST_OBJECT_UNLOCK (trans);
775 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
776 gst_buffer_pool_set_active (oldpool, FALSE);
777 gst_object_unref (oldpool);
784 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
790 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
793 gboolean result = TRUE;
794 GstBufferPool *pool = NULL, *oldpool;
795 guint size, min, max, prefix, alignment;
796 GstBaseTransformClass *klass;
797 const GstAllocator *allocator = NULL;
799 /* there are these possibilities:
801 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
802 * will do that whenever some upstream does an allocation query.
803 * 2) we need to do a transform, we need to get a bufferpool from downstream
804 * and configure it. When upstream does the ALLOCATION query, the
805 * propose_allocation vmethod will be called and we will configure the
806 * upstream allocator with our porposed values then.
810 oldpool = trans->priv->pool;
812 GST_DEBUG_OBJECT (trans, "unreffing old pool");
813 gst_buffer_pool_set_active (oldpool, FALSE);
814 gst_object_unref (oldpool);
815 trans->priv->pool = oldpool = NULL;
818 if (trans->passthrough || trans->always_in_place) {
819 /* we are in passthrough, the input buffer is never copied and always passed
820 * along. We never allocate an output buffer on the srcpad. What we do is
821 * let the upstream element decide if it wants to use a bufferpool and
822 * then we will proxy the downstream pool */
823 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
827 /* not passthrough, we need to allocate */
828 /* find a pool for the negotiated caps now */
829 GST_DEBUG_OBJECT (trans, "doing allocation query");
830 query = gst_query_new_allocation (outcaps, TRUE);
831 if (!gst_pad_peer_query (trans->srcpad, query)) {
832 /* not a problem, just debug a little */
833 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
836 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
838 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
839 if (G_LIKELY (klass->decide_allocation))
840 result = klass->decide_allocation (trans, query);
842 /* we got configuration from our peer, parse them */
843 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
847 const gchar *mem = NULL;
849 /* no size, we have variable size buffers */
850 if (gst_query_get_n_allocation_memories (query) > 0) {
851 mem = gst_query_parse_nth_allocation_memory (query, 0);
853 allocator = gst_allocator_find (mem);
854 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
855 } else if (pool == NULL) {
856 GstStructure *config;
858 /* we did not get a pool, make one ourselves then */
859 pool = gst_buffer_pool_new ();
861 GST_DEBUG_OBJECT (trans, "no pool, making one");
862 config = gst_buffer_pool_get_config (pool);
863 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
865 gst_buffer_pool_set_config (pool, config);
868 gst_query_unref (query);
872 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
878 /* function triggered when the in and out caps are negotiated and need
879 * to be configured in the subclass. */
881 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
885 GstBaseTransformClass *klass;
887 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
889 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
890 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
892 /* clear the cache */
893 gst_caps_replace (&trans->cache_caps1, NULL);
894 gst_caps_replace (&trans->cache_caps2, NULL);
896 /* figure out same caps state */
897 trans->have_same_caps = gst_caps_is_equal (in, out);
898 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
900 /* If we've a transform_ip method and same input/output caps, set in_place
901 * by default. If for some reason the sub-class prefers using a transform
902 * function, it can clear the in place flag in the set_caps */
903 gst_base_transform_set_in_place (trans,
904 klass->transform_ip && trans->have_same_caps);
906 /* Set the passthrough if the class wants passthrough_on_same_caps
907 * and we have the same caps on each pad */
908 if (klass->passthrough_on_same_caps)
909 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
911 /* now configure the element with the caps */
912 if (klass->set_caps) {
913 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
914 ret = klass->set_caps (trans, in, out);
917 trans->negotiated = ret;
923 gst_base_transform_default_fixate (GstBaseTransform * trans,
924 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
926 GST_DEBUG_OBJECT (trans, "using default caps fixate function");
927 gst_caps_fixate (othercaps);
930 /* given a fixed @caps on @pad, create the best possible caps for the
932 * @caps must be fixed when calling this function.
934 * This function calls the transform caps vmethod of the basetransform to figure
935 * out the possible target formats. It then tries to select the best format from
938 * - attempt passthrough if the target caps is a superset of the input caps
939 * - fixating by using peer caps
940 * - fixating with transform fixate function
941 * - fixating with pad fixate functions.
943 * this function returns a caps that can be transformed into and is accepted by
947 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
950 GstBaseTransformClass *klass;
951 GstPad *otherpad, *otherpeer;
955 /* caps must be fixed here, this is a programming error if it's not */
956 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
958 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
960 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
961 otherpeer = gst_pad_get_peer (otherpad);
963 /* see how we can transform the input caps. We need to do this even for
964 * passthrough because it might be possible that this element cannot support
965 * passthrough at all. */
966 othercaps = gst_base_transform_transform_caps (trans,
967 GST_PAD_DIRECTION (pad), caps, NULL);
969 /* The caps we can actually output is the intersection of the transformed
970 * caps with the pad template for the pad */
972 GstCaps *intersect, *templ_caps;
974 templ_caps = gst_pad_get_pad_template_caps (otherpad);
975 GST_DEBUG_OBJECT (trans,
976 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
979 gst_caps_intersect_full (othercaps, templ_caps,
980 GST_CAPS_INTERSECT_FIRST);
982 gst_caps_unref (othercaps);
983 gst_caps_unref (templ_caps);
984 othercaps = intersect;
987 /* check if transform is empty */
988 if (!othercaps || gst_caps_is_empty (othercaps))
991 /* if the othercaps are not fixed, we need to fixate them, first attempt
992 * is by attempting passthrough if the othercaps are a superset of caps. */
993 /* FIXME. maybe the caps is not fixed because it has multiple structures of
995 is_fixed = gst_caps_is_fixed (othercaps);
997 GST_DEBUG_OBJECT (trans,
998 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1000 /* Now let's see what the peer suggests based on our transformed caps */
1002 GstCaps *peercaps, *intersection, *templ_caps;
1004 GST_DEBUG_OBJECT (trans,
1005 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1007 peercaps = gst_pad_get_caps (otherpeer, othercaps);
1008 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1010 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1012 GST_DEBUG_OBJECT (trans,
1013 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1016 gst_caps_intersect_full (peercaps, templ_caps,
1017 GST_CAPS_INTERSECT_FIRST);
1018 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1019 gst_caps_unref (peercaps);
1020 gst_caps_unref (templ_caps);
1021 peercaps = intersection;
1023 GST_DEBUG_OBJECT (trans,
1024 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1026 gst_caps_intersect_full (peercaps, othercaps,
1027 GST_CAPS_INTERSECT_FIRST);
1028 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
1029 gst_caps_unref (peercaps);
1030 gst_caps_unref (othercaps);
1031 othercaps = intersection;
1032 is_fixed = gst_caps_is_fixed (othercaps);
1034 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1035 gst_caps_unref (othercaps);
1036 othercaps = gst_caps_ref (caps);
1040 if (gst_caps_is_empty (othercaps))
1041 goto no_transform_possible;
1043 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1046 /* second attempt at fixation, call the fixate vmethod */
1047 /* caps could be 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, "calling faxate_caps for %" GST_PTR_FORMAT
1052 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1053 GST_DEBUG_PAD_NAME (otherpad));
1054 /* note that we pass the complete array of structures to the fixate
1055 * function, it needs to truncate itself */
1056 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1057 is_fixed = gst_caps_is_fixed (othercaps);
1058 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, 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 (otherpeer && !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);
1188 /* called when new caps arrive on the sink or source pad,
1189 * We try to find the best caps for the other side using our _find_transform()
1190 * function. If there are caps, we configure the transform for this new
1193 * FIXME, this function is currently commutative but this should not really be
1194 * because we never set caps starting from the srcpad.
1197 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1200 GstPad *otherpad, *otherpeer;
1201 GstCaps *othercaps = NULL;
1202 gboolean ret = TRUE;
1203 GstCaps *incaps, *outcaps;
1205 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1206 otherpeer = gst_pad_get_peer (otherpad);
1208 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1210 /* find best possible caps for the other pad */
1211 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1212 if (!othercaps || gst_caps_is_empty (othercaps))
1213 goto no_transform_possible;
1215 /* configure the element now */
1216 /* make sure in and out caps are correct */
1217 if (pad == trans->sinkpad) {
1219 outcaps = othercaps;
1225 /* if we have the same caps, we can optimize and reuse the input caps */
1226 if (gst_caps_is_equal (incaps, outcaps)) {
1227 GST_INFO_OBJECT (trans, "reuse caps");
1228 gst_caps_unref (othercaps);
1229 outcaps = othercaps = gst_caps_ref (incaps);
1232 /* call configure now */
1233 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1234 goto failed_configure;
1236 GST_OBJECT_LOCK (trans->sinkpad);
1237 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1238 trans->priv->reconfigure = FALSE;
1239 GST_OBJECT_UNLOCK (trans->sinkpad);
1241 /* we know this will work, we implement the setcaps */
1242 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1244 if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_ACTIVATE_PULL) {
1246 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1248 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1254 /* try to get a pool when needed */
1255 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1260 gst_object_unref (otherpeer);
1262 gst_caps_unref (othercaps);
1264 trans->negotiated = ret;
1269 no_transform_possible:
1271 GST_WARNING_OBJECT (trans,
1272 "transform could not transform %" GST_PTR_FORMAT
1273 " in anything we support", caps);
1279 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1280 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1287 gst_base_transform_default_query (GstBaseTransform * trans,
1288 GstPadDirection direction, GstQuery * query)
1290 gboolean ret = FALSE;
1292 GstBaseTransformClass *klass;
1294 otherpad = (direction == GST_PAD_SRC) ? trans->sinkpad : trans->srcpad;
1296 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1298 switch (GST_QUERY_TYPE (query)) {
1299 case GST_QUERY_ALLOCATION:
1301 gboolean passthrough;
1303 /* can only be done on the sinkpad */
1304 if (direction != GST_PAD_SINK)
1307 GST_BASE_TRANSFORM_LOCK (trans);
1308 passthrough = trans->passthrough || trans->always_in_place;
1309 GST_BASE_TRANSFORM_UNLOCK (trans);
1312 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1313 ret = gst_pad_peer_query (otherpad, query);
1315 GST_DEBUG_OBJECT (trans, "propose allocation values");
1316 /* pass the query to the propose_allocation vmethod if any */
1317 if (G_LIKELY (klass->propose_allocation))
1318 ret = klass->propose_allocation (trans, query);
1322 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1326 case GST_QUERY_POSITION:
1330 gst_query_parse_position (query, &format, NULL);
1331 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1335 if ((direction == GST_PAD_SINK)
1336 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1338 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1339 trans->segment.position);
1341 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1342 trans->priv->position_out);
1344 gst_query_set_position (query, format, pos);
1346 ret = gst_pad_peer_query (otherpad, query);
1350 case GST_QUERY_ACCEPT_CAPS:
1354 gst_query_parse_accept_caps (query, &caps);
1355 if (klass->accept_caps) {
1356 ret = klass->accept_caps (trans, direction, caps);
1357 gst_query_set_accept_caps_result (query, ret);
1358 /* return TRUE, we answered the query */
1364 ret = gst_pad_peer_query (otherpad, query);
1373 gst_base_transform_query (GstPad * pad, GstQuery * query)
1375 GstBaseTransform *trans;
1376 GstBaseTransformClass *bclass;
1377 gboolean ret = FALSE;
1379 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1380 if (G_UNLIKELY (trans == NULL))
1383 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1386 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1388 gst_object_unref (trans);
1393 /* this function either returns the input buffer without incrementing the
1394 * refcount or it allocates a new (writable) buffer */
1395 static GstFlowReturn
1396 default_prepare_output_buffer (GstBaseTransform * trans,
1397 GstBuffer * inbuf, GstBuffer ** outbuf)
1399 GstBaseTransformPrivate *priv;
1400 GstFlowReturn ret = GST_FLOW_OK;
1401 GstBaseTransformClass *bclass;
1404 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1406 /* figure out how to allocate an output buffer */
1407 if (trans->passthrough) {
1408 /* passthrough, we will not modify the incomming buffer so we can just
1410 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1413 /* we can't reuse the input buffer */
1415 GST_DEBUG_OBJECT (trans, "using pool alloc");
1416 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1418 gsize insize, outsize;
1421 /* no pool, we need to figure out the size of the output buffer first */
1422 insize = gst_buffer_get_size (inbuf);
1424 if (trans->passthrough) {
1425 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1426 /* passthrough, the output size is the same as the input size. */
1429 gboolean want_in_place = (bclass->transform_ip != NULL)
1430 && trans->always_in_place;
1432 if (want_in_place) {
1433 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1434 /* we alloc a buffer of the same size as the input */
1437 GstCaps *incaps, *outcaps;
1439 /* else use the transform function to get the size */
1440 incaps = gst_pad_get_current_caps (trans->sinkpad);
1441 outcaps = gst_pad_get_current_caps (trans->srcpad);
1443 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1444 /* copy transform, figure out the output size */
1445 res = gst_base_transform_transform_size (trans,
1446 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1448 gst_caps_unref (incaps);
1449 gst_caps_unref (outcaps);
1455 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1457 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1465 GST_ERROR_OBJECT (trans, "unknown output size");
1466 return GST_FLOW_ERROR;
1471 default_copy_metadata (GstBaseTransform * trans,
1472 GstBuffer * inbuf, GstBuffer * outbuf)
1474 GstBaseTransformPrivate *priv = trans->priv;
1476 /* now copy the metadata */
1477 GST_DEBUG_OBJECT (trans, "copying metadata");
1479 /* this should not happen, buffers allocated from a pool or with
1480 * new_allocate should always be writable. */
1481 if (!gst_buffer_is_writable (outbuf))
1484 /* when we get here, the metadata should be writable */
1485 gst_buffer_copy_into (outbuf, inbuf,
1486 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1488 /* clear the GAP flag when the subclass does not understand it */
1489 if (!priv->gap_aware)
1490 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1497 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1502 /* Given @caps calcultate the size of one unit.
1504 * For video caps, this is the size of one frame (and thus one buffer).
1505 * For audio caps, this is the size of one sample.
1507 * These values are cached since they do not change and the calculation
1508 * potentially involves parsing caps and other expensive stuff.
1510 * We have two cache locations to store the size, one for the source caps
1511 * and one for the sink caps.
1513 * this function returns FALSE if no size could be calculated.
1516 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1519 gboolean res = FALSE;
1520 GstBaseTransformClass *bclass;
1522 /* see if we have the result cached */
1523 if (trans->cache_caps1 == caps) {
1524 *size = trans->cache_caps1_size;
1525 GST_DEBUG_OBJECT (trans,
1526 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1529 if (trans->cache_caps2 == caps) {
1530 *size = trans->cache_caps2_size;
1531 GST_DEBUG_OBJECT (trans,
1532 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1536 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1537 res = bclass->get_unit_size (trans, caps, size);
1538 GST_DEBUG_OBJECT (trans,
1539 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1540 caps, *size, res ? "TRUE" : "FALSE");
1543 /* and cache the values */
1544 if (trans->cache_caps1 == NULL) {
1545 gst_caps_replace (&trans->cache_caps1, caps);
1546 trans->cache_caps1_size = *size;
1547 GST_DEBUG_OBJECT (trans,
1548 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1549 } else if (trans->cache_caps2 == NULL) {
1550 gst_caps_replace (&trans->cache_caps2, caps);
1551 trans->cache_caps2_size = *size;
1552 GST_DEBUG_OBJECT (trans,
1553 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1555 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1562 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1564 GstBaseTransform *trans;
1565 GstBaseTransformClass *bclass;
1566 gboolean ret = TRUE;
1568 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1569 if (G_UNLIKELY (trans == NULL)) {
1570 gst_event_unref (event);
1573 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1575 if (bclass->sink_event)
1576 ret = bclass->sink_event (trans, event);
1578 gst_event_unref (event);
1580 gst_object_unref (trans);
1586 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1588 gboolean ret = TRUE, forward = TRUE;
1590 switch (GST_EVENT_TYPE (event)) {
1591 case GST_EVENT_FLUSH_START:
1593 case GST_EVENT_FLUSH_STOP:
1594 GST_OBJECT_LOCK (trans);
1595 /* reset QoS parameters */
1596 trans->priv->proportion = 1.0;
1597 trans->priv->earliest_time = -1;
1598 trans->priv->discont = FALSE;
1599 trans->priv->processed = 0;
1600 trans->priv->dropped = 0;
1601 GST_OBJECT_UNLOCK (trans);
1602 /* we need new segment info after the flush. */
1603 trans->have_segment = FALSE;
1604 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1605 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1611 case GST_EVENT_CAPS:
1615 gst_event_parse_caps (event, &caps);
1616 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1621 case GST_EVENT_SEGMENT:
1623 gst_event_copy_segment (event, &trans->segment);
1624 trans->have_segment = TRUE;
1626 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1635 ret = gst_pad_push_event (trans->srcpad, event);
1637 gst_event_unref (event);
1643 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1645 GstBaseTransform *trans;
1646 GstBaseTransformClass *bclass;
1647 gboolean ret = TRUE;
1649 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1650 if (G_UNLIKELY (trans == NULL)) {
1651 gst_event_unref (event);
1655 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1657 if (bclass->src_event)
1658 ret = bclass->src_event (trans, event);
1660 gst_event_unref (event);
1662 gst_object_unref (trans);
1668 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1672 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1674 switch (GST_EVENT_TYPE (event)) {
1675 case GST_EVENT_SEEK:
1677 case GST_EVENT_NAVIGATION:
1682 GstClockTimeDiff diff;
1683 GstClockTime timestamp;
1685 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1686 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1693 ret = gst_pad_push_event (trans->sinkpad, event);
1698 /* perform a transform on @inbuf and put the result in @outbuf.
1700 * This function is common to the push and pull-based operations.
1702 * This function takes ownership of @inbuf */
1703 static GstFlowReturn
1704 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1705 GstBuffer ** outbuf)
1707 GstBaseTransformClass *bclass;
1708 GstFlowReturn ret = GST_FLOW_OK;
1709 gboolean want_in_place;
1710 GstClockTime running_time;
1711 GstClockTime timestamp;
1712 gboolean reconfigure;
1714 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1716 GST_OBJECT_LOCK (trans->sinkpad);
1717 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1718 || trans->priv->reconfigure;
1719 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1720 trans->priv->reconfigure = FALSE;
1721 GST_OBJECT_UNLOCK (trans->sinkpad);
1723 if (G_UNLIKELY (reconfigure)) {
1726 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1728 incaps = gst_pad_get_current_caps (trans->sinkpad);
1730 goto no_reconfigure;
1732 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1733 * will reconfigure the transform with the new output format. We can only
1734 * do this if the buffer actually has caps. */
1735 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1736 gst_caps_unref (incaps);
1737 goto not_negotiated;
1739 gst_caps_unref (incaps);
1743 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1744 GST_DEBUG_OBJECT (trans,
1745 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1746 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1747 GST_BUFFER_OFFSET (inbuf));
1749 GST_DEBUG_OBJECT (trans,
1750 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1751 gst_buffer_get_size (inbuf));
1753 /* Don't allow buffer handling before negotiation, except in passthrough mode
1754 * or if the class doesn't implement a set_caps function (in which case it doesn't
1757 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1758 goto not_negotiated;
1760 /* Set discont flag so we can mark the outgoing buffer */
1761 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1762 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1763 trans->priv->discont = TRUE;
1766 /* can only do QoS if the segment is in TIME */
1767 if (trans->segment.format != GST_FORMAT_TIME)
1770 /* QOS is done on the running time of the buffer, get it now */
1771 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1772 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1775 if (running_time != -1) {
1777 GstClockTime earliest_time;
1780 /* lock for getting the QoS parameters that are set (in a different thread)
1781 * with the QOS events */
1782 GST_OBJECT_LOCK (trans);
1783 earliest_time = trans->priv->earliest_time;
1784 proportion = trans->priv->proportion;
1785 /* check for QoS, don't perform conversion for buffers
1786 * that are known to be late. */
1787 need_skip = trans->priv->qos_enabled &&
1788 earliest_time != -1 && running_time <= earliest_time;
1789 GST_OBJECT_UNLOCK (trans);
1792 GstMessage *qos_msg;
1793 GstClockTime duration;
1794 guint64 stream_time;
1797 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1798 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1799 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1801 trans->priv->dropped++;
1803 duration = GST_BUFFER_DURATION (inbuf);
1805 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1807 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1810 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1811 stream_time, timestamp, duration);
1812 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1813 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1814 trans->priv->processed, trans->priv->dropped);
1815 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1817 /* mark discont for next buffer */
1818 trans->priv->discont = TRUE;
1825 /* first try to allocate an output buffer based on the currently negotiated
1826 * format. outbuf will contain a buffer suitable for doing the configured
1827 * transform after this function. */
1828 if (bclass->prepare_output_buffer == NULL)
1831 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1832 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1834 if (ret != GST_FLOW_OK || *outbuf == NULL)
1837 if (inbuf == *outbuf) {
1838 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1839 } else if (trans->passthrough) {
1840 /* we are asked to perform a passthrough transform but the input and
1841 * output buffers are different. We have to discard the output buffer and
1842 * reuse the input buffer. This is rather weird, it means that the prepare
1843 * output buffer does something wrong. */
1844 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1845 "prepare_output_buffer implementation");
1846 gst_buffer_unref (*outbuf);
1849 /* copy the metadata */
1850 if (bclass->copy_metadata)
1851 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1852 /* something failed, post a warning */
1853 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1854 ("could not copy metadata"), (NULL));
1857 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1860 /* now perform the needed transform */
1861 if (trans->passthrough) {
1862 /* In passthrough mode, give transform_ip a look at the
1863 * buffer, without making it writable, or just push the
1865 if (bclass->transform_ip) {
1866 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1867 ret = bclass->transform_ip (trans, *outbuf);
1869 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1872 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1874 if (want_in_place) {
1875 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1877 if (inbuf != *outbuf) {
1878 guint8 *indata, *outdata;
1879 gsize insize, outsize;
1881 /* Different buffer. The data can still be the same when we are dealing
1882 * with subbuffers of the same buffer. Note that because of the FIXME in
1883 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1884 * outbuf to keep them writable */
1885 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1886 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1888 if (indata != outdata)
1889 memcpy (outdata, indata, insize);
1891 gst_buffer_unmap (inbuf, indata, insize);
1892 gst_buffer_unmap (*outbuf, outdata, outsize);
1894 ret = bclass->transform_ip (trans, *outbuf);
1896 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1898 if (bclass->transform)
1899 ret = bclass->transform (trans, inbuf, *outbuf);
1901 ret = GST_FLOW_NOT_SUPPORTED;
1906 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1907 * the input buffer, no refcount is changed to keep the input buffer writable
1909 if (*outbuf != inbuf)
1910 gst_buffer_unref (inbuf);
1917 gst_buffer_unref (inbuf);
1919 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1920 ("not negotiated"), ("not negotiated"));
1921 return GST_FLOW_NOT_NEGOTIATED;
1925 gst_buffer_unref (inbuf);
1926 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1927 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1928 return GST_FLOW_NOT_SUPPORTED;
1932 gst_buffer_unref (inbuf);
1934 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1935 gst_flow_get_name (ret));
1940 /* FIXME, getrange is broken, need to pull range from the other
1941 * end based on the transform_size result.
1943 static GstFlowReturn
1944 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1945 guint length, GstBuffer ** buffer)
1947 GstBaseTransform *trans;
1948 GstBaseTransformClass *klass;
1952 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1954 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1955 if (G_UNLIKELY (ret != GST_FLOW_OK))
1958 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1959 if (klass->before_transform)
1960 klass->before_transform (trans, inbuf);
1962 GST_BASE_TRANSFORM_LOCK (trans);
1963 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1964 GST_BASE_TRANSFORM_UNLOCK (trans);
1967 gst_object_unref (trans);
1974 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1975 gst_flow_get_name (ret));
1980 static GstFlowReturn
1981 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
1983 GstBaseTransform *trans;
1984 GstBaseTransformClass *klass;
1986 GstClockTime position = GST_CLOCK_TIME_NONE;
1987 GstClockTime timestamp, duration;
1988 GstBuffer *outbuf = NULL;
1990 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
1992 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1993 duration = GST_BUFFER_DURATION (buffer);
1995 /* calculate end position of the incoming buffer */
1996 if (timestamp != GST_CLOCK_TIME_NONE) {
1997 if (duration != GST_CLOCK_TIME_NONE)
1998 position = timestamp + duration;
2000 position = timestamp;
2003 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2004 if (klass->before_transform)
2005 klass->before_transform (trans, buffer);
2007 /* protect transform method and concurrent buffer alloc */
2008 GST_BASE_TRANSFORM_LOCK (trans);
2009 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2010 GST_BASE_TRANSFORM_UNLOCK (trans);
2012 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2013 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2014 if (outbuf != NULL) {
2015 if (ret == GST_FLOW_OK) {
2016 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2018 /* Remember last stop position */
2019 if (position != GST_CLOCK_TIME_NONE &&
2020 trans->segment.format == GST_FORMAT_TIME)
2021 trans->segment.position = position;
2023 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2024 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2025 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2026 position_out += GST_BUFFER_DURATION (outbuf);
2027 } else if (position != GST_CLOCK_TIME_NONE) {
2028 position_out = position;
2030 if (position_out != GST_CLOCK_TIME_NONE
2031 && trans->segment.format == GST_FORMAT_TIME)
2032 trans->priv->position_out = position_out;
2034 /* apply DISCONT flag if the buffer is not yet marked as such */
2035 if (trans->priv->discont) {
2036 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2037 outbuf = gst_buffer_make_writable (outbuf);
2038 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2040 trans->priv->discont = FALSE;
2042 trans->priv->processed++;
2044 ret = gst_pad_push (trans->srcpad, outbuf);
2046 gst_buffer_unref (outbuf);
2050 /* convert internal flow to OK and mark discont for the next buffer. */
2051 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2052 trans->priv->discont = TRUE;
2060 gst_base_transform_set_property (GObject * object, guint prop_id,
2061 const GValue * value, GParamSpec * pspec)
2063 GstBaseTransform *trans;
2065 trans = GST_BASE_TRANSFORM (object);
2069 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2072 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2078 gst_base_transform_get_property (GObject * object, guint prop_id,
2079 GValue * value, GParamSpec * pspec)
2081 GstBaseTransform *trans;
2083 trans = GST_BASE_TRANSFORM (object);
2087 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2090 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2095 /* not a vmethod of anything, just an internal method */
2097 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2099 GstBaseTransformClass *bclass;
2100 gboolean result = TRUE;
2102 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2105 GstCaps *incaps, *outcaps;
2107 if (trans->priv->pad_mode == GST_PAD_ACTIVATE_NONE && bclass->start)
2108 result &= bclass->start (trans);
2110 incaps = gst_pad_get_current_caps (trans->sinkpad);
2111 outcaps = gst_pad_get_current_caps (trans->srcpad);
2113 GST_OBJECT_LOCK (trans);
2114 if (incaps && outcaps)
2115 trans->have_same_caps =
2116 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2118 trans->have_same_caps = trans->passthrough;
2119 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2120 trans->negotiated = FALSE;
2121 trans->have_segment = FALSE;
2122 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2123 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2124 trans->priv->proportion = 1.0;
2125 trans->priv->earliest_time = -1;
2126 trans->priv->discont = FALSE;
2127 trans->priv->processed = 0;
2128 trans->priv->dropped = 0;
2129 GST_OBJECT_UNLOCK (trans);
2132 gst_caps_unref (incaps);
2134 gst_caps_unref (outcaps);
2136 /* We must make sure streaming has finished before resetting things
2137 * and calling the ::stop vfunc */
2138 GST_PAD_STREAM_LOCK (trans->sinkpad);
2139 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2141 trans->have_same_caps = FALSE;
2142 /* We can only reset the passthrough mode if the instance told us to
2143 handle it in configure_caps */
2144 if (bclass->passthrough_on_same_caps) {
2145 gst_base_transform_set_passthrough (trans, FALSE);
2147 gst_caps_replace (&trans->cache_caps1, NULL);
2148 gst_caps_replace (&trans->cache_caps2, NULL);
2150 if (trans->priv->pad_mode != GST_PAD_ACTIVATE_NONE && bclass->stop)
2151 result &= bclass->stop (trans);
2153 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2160 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2162 gboolean result = TRUE;
2163 GstBaseTransform *trans;
2165 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2167 result = gst_base_transform_activate (trans, active);
2170 trans->priv->pad_mode =
2171 active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
2173 gst_object_unref (trans);
2179 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2181 gboolean result = FALSE;
2182 GstBaseTransform *trans;
2184 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2186 result = gst_pad_activate_pull (trans->sinkpad, active);
2189 result &= gst_base_transform_activate (trans, active);
2192 trans->priv->pad_mode =
2193 active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
2195 gst_object_unref (trans);
2201 * gst_base_transform_set_passthrough:
2202 * @trans: the #GstBaseTransform to set
2203 * @passthrough: boolean indicating passthrough mode.
2205 * Set passthrough mode for this filter by default. This is mostly
2206 * useful for filters that do not care about negotiation.
2208 * Always TRUE for filters which don't implement either a transform
2209 * or transform_ip method.
2214 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2215 gboolean passthrough)
2217 GstBaseTransformClass *bclass;
2219 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2221 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2223 GST_OBJECT_LOCK (trans);
2224 if (passthrough == FALSE) {
2225 if (bclass->transform_ip || bclass->transform)
2226 trans->passthrough = FALSE;
2228 trans->passthrough = TRUE;
2231 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2232 GST_OBJECT_UNLOCK (trans);
2236 * gst_base_transform_is_passthrough:
2237 * @trans: the #GstBaseTransform to query
2239 * See if @trans is configured as a passthrough transform.
2241 * Returns: TRUE is the transform is configured in passthrough mode.
2246 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2250 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2252 GST_OBJECT_LOCK (trans);
2253 result = trans->passthrough;
2254 GST_OBJECT_UNLOCK (trans);
2260 * gst_base_transform_set_in_place:
2261 * @trans: the #GstBaseTransform to modify
2262 * @in_place: Boolean value indicating that we would like to operate
2263 * on in_place buffers.
2265 * Determines whether a non-writable buffer will be copied before passing
2266 * to the transform_ip function.
2268 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2269 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2275 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2277 GstBaseTransformClass *bclass;
2279 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2281 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2283 GST_OBJECT_LOCK (trans);
2286 if (bclass->transform_ip) {
2287 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2288 trans->always_in_place = TRUE;
2291 if (bclass->transform) {
2292 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2293 trans->always_in_place = FALSE;
2297 GST_OBJECT_UNLOCK (trans);
2301 * gst_base_transform_is_in_place:
2302 * @trans: the #GstBaseTransform to query
2304 * See if @trans is configured as a in_place transform.
2306 * Returns: TRUE is the transform is configured in in_place mode.
2311 gst_base_transform_is_in_place (GstBaseTransform * trans)
2315 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2317 GST_OBJECT_LOCK (trans);
2318 result = trans->always_in_place;
2319 GST_OBJECT_UNLOCK (trans);
2325 * gst_base_transform_update_qos:
2326 * @trans: a #GstBaseTransform
2327 * @proportion: the proportion
2328 * @diff: the diff against the clock
2329 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2332 * Set the QoS parameters in the transform. This function is called internally
2333 * when a QOS event is received but subclasses can provide custom information
2341 gst_base_transform_update_qos (GstBaseTransform * trans,
2342 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2345 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2347 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2348 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2349 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2351 GST_OBJECT_LOCK (trans);
2352 trans->priv->proportion = proportion;
2353 trans->priv->earliest_time = timestamp + diff;
2354 GST_OBJECT_UNLOCK (trans);
2358 * gst_base_transform_set_qos_enabled:
2359 * @trans: a #GstBaseTransform
2360 * @enabled: new state
2362 * Enable or disable QoS handling in the transform.
2369 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2371 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2373 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2375 GST_OBJECT_LOCK (trans);
2376 trans->priv->qos_enabled = enabled;
2377 GST_OBJECT_UNLOCK (trans);
2381 * gst_base_transform_is_qos_enabled:
2382 * @trans: a #GstBaseTransform
2384 * Queries if the transform will handle QoS.
2386 * Returns: TRUE if QoS is enabled.
2393 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2397 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2399 GST_OBJECT_LOCK (trans);
2400 result = trans->priv->qos_enabled;
2401 GST_OBJECT_UNLOCK (trans);
2407 * gst_base_transform_set_gap_aware:
2408 * @trans: a #GstBaseTransform
2409 * @gap_aware: New state
2411 * If @gap_aware is %FALSE (the default), output buffers will have the
2412 * %GST_BUFFER_FLAG_GAP flag unset.
2414 * If set to %TRUE, the element must handle output buffers with this flag set
2415 * correctly, i.e. it can assume that the buffer contains neutral data but must
2416 * unset the flag if the output is no neutral data.
2423 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2425 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2427 GST_OBJECT_LOCK (trans);
2428 trans->priv->gap_aware = gap_aware;
2429 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2430 GST_OBJECT_UNLOCK (trans);
2434 * gst_base_transform_suggest:
2435 * @trans: a #GstBaseTransform
2436 * @caps: (transfer none): caps to suggest
2437 * @size: buffer size to suggest
2439 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2445 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2448 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2450 /* push the renegotiate event */
2451 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2452 gst_event_new_reconfigure ()))
2453 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2457 * gst_base_transform_reconfigure:
2458 * @trans: a #GstBaseTransform
2460 * Instructs @trans to renegotiate a new downstream transform on the next
2461 * buffer. This function is typically called after properties on the transform
2462 * were set that influence the output format.
2467 gst_base_transform_reconfigure (GstBaseTransform * trans)
2469 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2471 GST_OBJECT_LOCK (trans);
2472 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2473 trans->priv->reconfigure = TRUE;
2474 GST_OBJECT_UNLOCK (trans);