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_getcaps (GstPad * pad, GstCaps * filter);
321 static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
322 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
323 GstPadDirection direction, GstCaps * caps);
324 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
325 GstPad * pad, GstCaps * caps);
326 static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
327 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
328 GstPadDirection direction, GstQuery * query);
330 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
331 GstBuffer * inbuf, GstBuffer ** outbuf);
332 static gboolean default_copy_metadata (GstBaseTransform * trans,
333 GstBuffer * inbuf, GstBuffer * outbuf);
335 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
339 gst_base_transform_finalize (GObject * object)
341 GstBaseTransform *trans;
343 trans = GST_BASE_TRANSFORM (object);
345 g_mutex_free (trans->transform_lock);
347 G_OBJECT_CLASS (parent_class)->finalize (object);
351 gst_base_transform_class_init (GstBaseTransformClass * klass)
353 GObjectClass *gobject_class;
355 gobject_class = G_OBJECT_CLASS (klass);
357 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
358 "basetransform element");
360 GST_DEBUG ("gst_base_transform_class_init");
362 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
364 parent_class = g_type_class_peek_parent (klass);
366 gobject_class->set_property = gst_base_transform_set_property;
367 gobject_class->get_property = gst_base_transform_get_property;
369 g_object_class_install_property (gobject_class, PROP_QOS,
370 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
371 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
373 gobject_class->finalize = gst_base_transform_finalize;
375 klass->passthrough_on_same_caps = FALSE;
376 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
377 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
379 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
380 klass->prepare_output_buffer =
381 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
382 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
383 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
387 gst_base_transform_init (GstBaseTransform * trans,
388 GstBaseTransformClass * bclass)
390 GstPadTemplate *pad_template;
392 GST_DEBUG ("gst_base_transform_init");
394 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
397 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
398 g_return_if_fail (pad_template != NULL);
399 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
400 gst_pad_set_getcaps_function (trans->sinkpad,
401 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
402 gst_pad_set_acceptcaps_function (trans->sinkpad,
403 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
404 gst_pad_set_event_function (trans->sinkpad,
405 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
406 gst_pad_set_chain_function (trans->sinkpad,
407 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
408 gst_pad_set_activatepush_function (trans->sinkpad,
409 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
410 gst_pad_set_query_function (trans->sinkpad,
411 GST_DEBUG_FUNCPTR (gst_base_transform_query));
412 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
415 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
416 g_return_if_fail (pad_template != NULL);
417 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
418 gst_pad_set_getcaps_function (trans->srcpad,
419 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
420 gst_pad_set_acceptcaps_function (trans->srcpad,
421 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
422 gst_pad_set_event_function (trans->srcpad,
423 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
424 gst_pad_set_getrange_function (trans->srcpad,
425 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
426 gst_pad_set_activatepull_function (trans->srcpad,
427 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
428 gst_pad_set_query_function (trans->srcpad,
429 GST_DEBUG_FUNCPTR (gst_base_transform_query));
430 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
432 trans->transform_lock = g_mutex_new ();
433 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
434 trans->cache_caps1 = NULL;
435 trans->cache_caps2 = NULL;
436 trans->priv->pad_mode = GST_PAD_ACTIVATE_NONE;
437 trans->priv->gap_aware = FALSE;
439 trans->passthrough = FALSE;
440 if (bclass->transform == NULL) {
441 /* If no transform function, always_in_place is TRUE */
442 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
443 trans->always_in_place = TRUE;
445 if (bclass->transform_ip == NULL) {
446 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
447 trans->passthrough = TRUE;
451 trans->priv->processed = 0;
452 trans->priv->dropped = 0;
455 /* given @caps on the src or sink pad (given by @direction)
456 * calculate the possible caps on the other pad.
458 * Returns new caps, unref after usage.
461 gst_base_transform_transform_caps (GstBaseTransform * trans,
462 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
465 GstBaseTransformClass *klass;
470 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
472 /* if there is a custom transform function, use this */
473 if (klass->transform_caps) {
475 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
477 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
478 ret = klass->transform_caps (trans, direction, caps, filter);
479 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
481 #ifndef G_DISABLE_ASSERT
483 if (!gst_caps_is_subset (ret, filter)) {
484 GstCaps *intersection;
486 GST_ERROR_OBJECT (trans,
487 "transform_caps returned caps %" GST_PTR_FORMAT
488 " which are not a real subset of the filter caps %"
489 GST_PTR_FORMAT, ret, filter);
490 g_warning ("%s: transform_caps returned caps which are not a real "
491 "subset of the filter caps", GST_ELEMENT_NAME (trans));
494 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
495 gst_caps_unref (intersection);
501 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
502 /* no transform function, use the identity transform */
504 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
506 ret = gst_caps_ref (caps);
510 GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
516 /* transform a buffer of @size with @caps on the pad with @direction to
517 * the size of a buffer with @othercaps and store the result in @othersize
519 * We have two ways of doing this:
520 * 1) use a custom transform size function, this is for complicated custom
521 * cases with no fixed unit_size.
522 * 2) use the unit_size functions where there is a relationship between the
523 * caps and the size of a buffer.
526 gst_base_transform_transform_size (GstBaseTransform * trans,
527 GstPadDirection direction, GstCaps * caps,
528 gsize size, GstCaps * othercaps, gsize * othersize)
530 gsize inunitsize, outunitsize, units;
531 GstBaseTransformClass *klass;
534 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
536 GST_DEBUG_OBJECT (trans,
537 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
538 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
539 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
541 if (klass->transform_size) {
542 /* if there is a custom transform function, use this */
543 ret = klass->transform_size (trans, direction, caps, size, othercaps,
545 } else if (klass->get_unit_size == NULL) {
546 /* if there is no transform_size and no unit_size, it means the
547 * element does not modify the size of a buffer */
551 /* there is no transform_size function, we have to use the unit_size
552 * functions. This method assumes there is a fixed unit_size associated with
553 * each caps. We provide the same amount of units on both sides. */
554 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
557 GST_DEBUG_OBJECT (trans,
558 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
561 /* input size must be a multiple of the unit_size of the input caps */
562 if (inunitsize == 0 || (size % inunitsize != 0))
565 /* get the amount of units */
566 units = size / inunitsize;
568 /* now get the unit size of the output */
569 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
572 /* the output size is the unit_size times the amount of units on the
574 *othersize = units * outunitsize;
575 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
585 GST_DEBUG_OBJECT (trans, "could not get in_size");
586 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
591 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
592 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
593 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
594 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
599 GST_DEBUG_OBJECT (trans, "could not get out_size");
600 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
605 /* get the caps that can be handled by @pad. We perform:
607 * - take the caps of peer of otherpad,
608 * - filter against the padtemplate of otherpad,
609 * - calculate all transforms of remaining caps
610 * - filter against template of @pad
612 * If there is no peer, we simply return the caps of the padtemplate of pad.
615 gst_base_transform_getcaps (GstPad * pad, GstCaps * filter)
617 GstBaseTransform *trans;
619 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
622 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
624 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
626 /* we can do what the peer can */
629 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
631 /* filtered against our padtemplate on the other side */
632 templ = gst_pad_get_pad_template_caps (pad);
633 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
634 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
635 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
636 gst_caps_unref (templ);
638 /* then see what we can transform this to */
639 peerfilter = gst_base_transform_transform_caps (trans,
640 GST_PAD_DIRECTION (pad), temp, NULL);
641 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
642 gst_caps_unref (temp);
644 /* and filter against the template of this pad */
645 templ = gst_pad_get_pad_template_caps (otherpad);
646 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
647 /* We keep the caps sorted like the returned caps */
649 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
650 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
651 gst_caps_unref (peerfilter);
652 gst_caps_unref (templ);
656 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
659 gst_caps_unref (peerfilter);
662 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
664 /* filtered against our padtemplate on the other side */
665 templ = gst_pad_get_pad_template_caps (otherpad);
666 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
667 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
668 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
669 gst_caps_unref (templ);
671 temp = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
674 /* then see what we can transform this to */
675 caps = gst_base_transform_transform_caps (trans,
676 GST_PAD_DIRECTION (otherpad), temp, filter);
677 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
678 gst_caps_unref (temp);
683 /* and filter against the template of this pad */
684 templ = gst_pad_get_pad_template_caps (pad);
685 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
686 /* We keep the caps sorted like the returned caps */
687 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
688 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
689 gst_caps_unref (caps);
690 gst_caps_unref (templ);
693 /* Now try if we can put the untransformed downstream caps first */
694 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
695 if (!gst_caps_is_empty (temp)) {
696 gst_caps_merge (temp, caps);
699 gst_caps_unref (temp);
702 gst_caps_unref (caps);
703 /* no peer or the peer can do anything, our padtemplate is enough then */
704 caps = gst_pad_get_pad_template_caps (pad);
709 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
710 gst_caps_unref (caps);
716 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
719 gst_caps_unref (peercaps);
721 gst_object_unref (trans);
727 gst_base_transform_set_allocation (GstBaseTransform * trans,
728 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
731 GstBufferPool *oldpool;
732 GstBaseTransformPrivate *priv = trans->priv;
736 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
737 if (!gst_buffer_pool_set_active (pool, TRUE))
738 goto activate_failed;
741 GST_OBJECT_LOCK (trans);
742 oldpool = priv->pool;
744 priv->allocator = allocator;
745 priv->prefix = prefix;
746 priv->alignment = alignment;
747 GST_OBJECT_UNLOCK (trans);
750 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
751 gst_buffer_pool_set_active (oldpool, FALSE);
752 gst_object_unref (oldpool);
759 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
765 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
768 gboolean result = TRUE;
769 GstBufferPool *pool = NULL, *oldpool;
770 guint size, min, max, prefix, alignment;
771 GstBaseTransformClass *klass;
772 const GstAllocator *allocator = NULL;
774 /* there are these possibilities:
776 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
777 * will do that whenever some upstream does an allocation query.
778 * 2) we need to do a transform, we need to get a bufferpool from downstream
779 * and configure it. When upstream does the ALLOCATION query, the
780 * propose_allocation vmethod will be called and we will configure the
781 * upstream allocator with our porposed values then.
785 oldpool = trans->priv->pool;
787 GST_DEBUG_OBJECT (trans, "unreffing old pool");
788 gst_buffer_pool_set_active (oldpool, FALSE);
789 gst_object_unref (oldpool);
790 trans->priv->pool = oldpool = NULL;
793 if (trans->passthrough || trans->always_in_place) {
794 /* we are in passthrough, the input buffer is never copied and always passed
795 * along. We never allocate an output buffer on the srcpad. What we do is
796 * let the upstream element decide if it wants to use a bufferpool and
797 * then we will proxy the downstream pool */
798 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
802 /* not passthrough, we need to allocate */
803 /* find a pool for the negotiated caps now */
804 GST_DEBUG_OBJECT (trans, "doing allocation query");
805 query = gst_query_new_allocation (outcaps, TRUE);
806 if (!gst_pad_peer_query (trans->srcpad, query)) {
807 /* not a problem, just debug a little */
808 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
811 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
813 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
814 if (G_LIKELY (klass->decide_allocation))
815 result = klass->decide_allocation (trans, query);
817 /* we got configuration from our peer, parse them */
818 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
822 const gchar *mem = NULL;
824 /* no size, we have variable size buffers */
825 if (gst_query_get_n_allocation_memories (query) > 0) {
826 mem = gst_query_parse_nth_allocation_memory (query, 0);
828 allocator = gst_allocator_find (mem);
829 GST_DEBUG_OBJECT (trans, "no size, using allocator %s", GST_STR_NULL (mem));
830 } else if (pool == NULL) {
831 GstStructure *config;
833 /* we did not get a pool, make one ourselves then */
834 pool = gst_buffer_pool_new ();
836 GST_DEBUG_OBJECT (trans, "no pool, making one");
837 config = gst_buffer_pool_get_config (pool);
838 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
840 gst_buffer_pool_set_config (pool, config);
843 gst_query_unref (query);
847 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
853 /* function triggered when the in and out caps are negotiated and need
854 * to be configured in the subclass. */
856 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
860 GstBaseTransformClass *klass;
862 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
864 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
865 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
867 /* clear the cache */
868 gst_caps_replace (&trans->cache_caps1, NULL);
869 gst_caps_replace (&trans->cache_caps2, NULL);
871 /* figure out same caps state */
872 trans->have_same_caps = gst_caps_is_equal (in, out);
873 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
875 /* If we've a transform_ip method and same input/output caps, set in_place
876 * by default. If for some reason the sub-class prefers using a transform
877 * function, it can clear the in place flag in the set_caps */
878 gst_base_transform_set_in_place (trans,
879 klass->transform_ip && trans->have_same_caps);
881 /* Set the passthrough if the class wants passthrough_on_same_caps
882 * and we have the same caps on each pad */
883 if (klass->passthrough_on_same_caps)
884 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
886 /* now configure the element with the caps */
887 if (klass->set_caps) {
888 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
889 ret = klass->set_caps (trans, in, out);
892 trans->negotiated = ret;
897 /* given a fixed @caps on @pad, create the best possible caps for the
899 * @caps must be fixed when calling this function.
901 * This function calls the transform caps vmethod of the basetransform to figure
902 * out the possible target formats. It then tries to select the best format from
905 * - attempt passthrough if the target caps is a superset of the input caps
906 * - fixating by using peer caps
907 * - fixating with transform fixate function
908 * - fixating with pad fixate functions.
910 * this function returns a caps that can be transformed into and is accepted by
914 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
917 GstBaseTransformClass *klass;
918 GstPad *otherpad, *otherpeer;
922 /* caps must be fixed here, this is a programming error if it's not */
923 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
925 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
927 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
928 otherpeer = gst_pad_get_peer (otherpad);
930 /* see how we can transform the input caps. We need to do this even for
931 * passthrough because it might be possible that this element cannot support
932 * passthrough at all. */
933 othercaps = gst_base_transform_transform_caps (trans,
934 GST_PAD_DIRECTION (pad), caps, NULL);
936 /* The caps we can actually output is the intersection of the transformed
937 * caps with the pad template for the pad */
939 GstCaps *intersect, *templ_caps;
941 templ_caps = gst_pad_get_pad_template_caps (otherpad);
942 GST_DEBUG_OBJECT (trans,
943 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
946 gst_caps_intersect_full (othercaps, templ_caps,
947 GST_CAPS_INTERSECT_FIRST);
949 gst_caps_unref (othercaps);
950 gst_caps_unref (templ_caps);
951 othercaps = intersect;
954 /* check if transform is empty */
955 if (!othercaps || gst_caps_is_empty (othercaps))
958 /* if the othercaps are not fixed, we need to fixate them, first attempt
959 * is by attempting passthrough if the othercaps are a superset of caps. */
960 /* FIXME. maybe the caps is not fixed because it has multiple structures of
962 is_fixed = gst_caps_is_fixed (othercaps);
964 GST_DEBUG_OBJECT (trans,
965 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
967 /* Now let's see what the peer suggests based on our transformed caps */
969 GstCaps *peercaps, *intersection, *templ_caps;
971 GST_DEBUG_OBJECT (trans,
972 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
974 peercaps = gst_pad_get_caps (otherpeer, othercaps);
975 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
977 templ_caps = gst_pad_get_pad_template_caps (otherpad);
979 GST_DEBUG_OBJECT (trans,
980 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
983 gst_caps_intersect_full (peercaps, templ_caps,
984 GST_CAPS_INTERSECT_FIRST);
985 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
986 gst_caps_unref (peercaps);
987 gst_caps_unref (templ_caps);
988 peercaps = intersection;
990 GST_DEBUG_OBJECT (trans,
991 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
993 gst_caps_intersect_full (peercaps, othercaps,
994 GST_CAPS_INTERSECT_FIRST);
995 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
996 gst_caps_unref (peercaps);
997 gst_caps_unref (othercaps);
998 othercaps = intersection;
999 is_fixed = gst_caps_is_fixed (othercaps);
1001 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1002 gst_caps_unref (othercaps);
1003 othercaps = gst_caps_ref (caps);
1007 if (gst_caps_is_empty (othercaps))
1008 goto no_transform_possible;
1010 /* second attempt at fixation, call the fixate vmethod and
1011 * ultimately call the pad fixate function. */
1013 GST_DEBUG_OBJECT (trans,
1014 "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
1015 othercaps, GST_DEBUG_PAD_NAME (otherpad));
1017 /* since we have no other way to fixate left, we might as well just take
1018 * the first of the caps list and fixate that */
1020 /* FIXME: when fixating using the vmethod, it might make sense to fixate
1021 * each of the caps; but Wim doesn't see a use case for that yet */
1022 gst_caps_truncate (othercaps);
1024 if (klass->fixate_caps) {
1025 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1026 " using caps %" GST_PTR_FORMAT
1027 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1028 GST_DEBUG_PAD_NAME (otherpad));
1029 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1030 is_fixed = gst_caps_is_fixed (othercaps);
1032 /* if still not fixed, no other option but to let the default pad fixate
1033 * function do its job */
1035 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1036 " on pad %s:%s using gst_pad_fixate_caps", othercaps,
1037 GST_DEBUG_PAD_NAME (otherpad));
1038 gst_pad_fixate_caps (otherpad, othercaps);
1039 is_fixed = gst_caps_is_fixed (othercaps);
1041 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1043 GST_DEBUG ("caps are fixed");
1044 /* else caps are fixed but the subclass may want to add fields */
1045 if (klass->fixate_caps) {
1046 othercaps = gst_caps_make_writable (othercaps);
1048 GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
1049 " using caps %" GST_PTR_FORMAT
1050 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1051 GST_DEBUG_PAD_NAME (otherpad));
1053 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1054 is_fixed = gst_caps_is_fixed (othercaps);
1058 /* caps should be fixed now, if not we have to fail. */
1060 goto could_not_fixate;
1062 /* and peer should accept */
1063 if (otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
1064 goto peer_no_accept;
1066 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1067 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1070 gst_object_unref (otherpeer);
1077 GST_DEBUG_OBJECT (trans,
1078 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1081 no_transform_possible:
1083 GST_DEBUG_OBJECT (trans,
1084 "transform could not transform %" GST_PTR_FORMAT
1085 " in anything we support", caps);
1090 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1095 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1096 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1102 gst_object_unref (otherpeer);
1104 gst_caps_unref (othercaps);
1110 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1111 GstPadDirection direction, GstCaps * caps)
1115 GstCaps *othercaps = NULL;
1117 gboolean ret = TRUE;
1120 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1122 /* we need fixed caps for the check, fall back to the default implementation
1124 if (!gst_caps_is_fixed (caps))
1129 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1131 /* get all the formats we can handle on this pad */
1132 if (direction == GST_PAD_SRC)
1133 allowed = gst_pad_get_caps (trans->srcpad, NULL);
1135 allowed = gst_pad_get_caps (trans->sinkpad, NULL);
1138 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1139 goto no_transform_possible;
1142 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1144 /* intersect with the requested format */
1145 ret = gst_caps_is_subset (caps, allowed);
1146 gst_caps_unref (allowed);
1149 goto no_transform_possible;
1153 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1155 /* find best possible caps for the other pad as a way to see if we can
1156 * transform this caps. */
1157 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1158 if (!othercaps || gst_caps_is_empty (othercaps))
1159 goto no_transform_possible;
1161 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1167 /* We know it's always NULL since we never use it */
1169 gst_caps_unref (othercaps);
1175 no_transform_possible:
1177 GST_DEBUG_OBJECT (trans,
1178 "transform could not transform %" GST_PTR_FORMAT
1179 " in anything we support", caps);
1186 gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
1188 gboolean ret = TRUE;
1189 GstBaseTransform *trans;
1190 GstBaseTransformClass *bclass;
1192 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1193 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1195 if (bclass->accept_caps)
1196 ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
1198 gst_object_unref (trans);
1203 /* called when new caps arrive on the sink or source pad,
1204 * We try to find the best caps for the other side using our _find_transform()
1205 * function. If there are caps, we configure the transform for this new
1208 * FIXME, this function is currently commutative but this should not really be
1209 * because we never set caps starting from the srcpad.
1212 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1215 GstPad *otherpad, *otherpeer;
1216 GstCaps *othercaps = NULL;
1217 gboolean ret = TRUE;
1218 GstCaps *incaps, *outcaps;
1220 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1221 otherpeer = gst_pad_get_peer (otherpad);
1223 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1225 /* find best possible caps for the other pad */
1226 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1227 if (!othercaps || gst_caps_is_empty (othercaps))
1228 goto no_transform_possible;
1230 /* configure the element now */
1231 /* make sure in and out caps are correct */
1232 if (pad == trans->sinkpad) {
1234 outcaps = othercaps;
1240 /* if we have the same caps, we can optimize and reuse the input caps */
1241 if (gst_caps_is_equal (incaps, outcaps)) {
1242 GST_INFO_OBJECT (trans, "reuse caps");
1243 gst_caps_unref (othercaps);
1244 outcaps = othercaps = gst_caps_ref (incaps);
1247 /* call configure now */
1248 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1249 goto failed_configure;
1251 GST_OBJECT_LOCK (trans->sinkpad);
1252 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1253 trans->priv->reconfigure = FALSE;
1254 GST_OBJECT_UNLOCK (trans->sinkpad);
1256 /* we know this will work, we implement the setcaps */
1257 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1259 if (pad == trans->srcpad && trans->priv->pad_mode == GST_PAD_ACTIVATE_PULL) {
1261 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1263 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1269 /* try to get a pool when needed */
1270 ret = gst_base_transform_do_bufferpool (trans, othercaps);
1275 gst_object_unref (otherpeer);
1277 gst_caps_unref (othercaps);
1279 trans->negotiated = ret;
1284 no_transform_possible:
1286 GST_WARNING_OBJECT (trans,
1287 "transform could not transform %" GST_PTR_FORMAT
1288 " in anything we support", caps);
1294 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1295 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1302 gst_base_transform_default_query (GstBaseTransform * trans,
1303 GstPadDirection direction, GstQuery * query)
1305 gboolean ret = FALSE;
1308 otherpad = (direction == GST_PAD_SRC) ? trans->sinkpad : trans->srcpad;
1310 switch (GST_QUERY_TYPE (query)) {
1311 case GST_QUERY_ALLOCATION:
1313 gboolean passthrough;
1315 /* can only be done on the sinkpad */
1316 if (direction != GST_PAD_SINK)
1319 GST_BASE_TRANSFORM_LOCK (trans);
1320 passthrough = trans->passthrough || trans->always_in_place;
1321 GST_BASE_TRANSFORM_UNLOCK (trans);
1324 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1325 ret = gst_pad_peer_query (otherpad, query);
1327 GstBaseTransformClass *klass;
1329 GST_DEBUG_OBJECT (trans, "propose allocation values");
1331 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1332 /* pass the query to the propose_allocation vmethod if any */
1333 if (G_LIKELY (klass->propose_allocation))
1334 ret = klass->propose_allocation (trans, query);
1338 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1342 case GST_QUERY_POSITION:
1346 gst_query_parse_position (query, &format, NULL);
1347 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1351 if ((direction == GST_PAD_SINK)
1352 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1354 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1355 trans->segment.position);
1357 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1358 trans->priv->position_out);
1360 gst_query_set_position (query, format, pos);
1362 ret = gst_pad_peer_query (otherpad, query);
1367 ret = gst_pad_peer_query (otherpad, query);
1376 gst_base_transform_query (GstPad * pad, GstQuery * query)
1378 GstBaseTransform *trans;
1379 GstBaseTransformClass *bclass;
1382 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1383 if (G_UNLIKELY (trans == NULL))
1386 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1389 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1391 ret = gst_pad_query_default (pad, query);
1393 gst_object_unref (trans);
1398 /* this function either returns the input buffer without incrementing the
1399 * refcount or it allocates a new (writable) buffer */
1400 static GstFlowReturn
1401 default_prepare_output_buffer (GstBaseTransform * trans,
1402 GstBuffer * inbuf, GstBuffer ** outbuf)
1404 GstBaseTransformPrivate *priv;
1405 GstFlowReturn ret = GST_FLOW_OK;
1406 GstBaseTransformClass *bclass;
1409 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1411 /* figure out how to allocate an output buffer */
1412 if (trans->passthrough) {
1413 /* passthrough, we will not modify the incomming buffer so we can just
1415 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1418 /* we can't reuse the input buffer */
1420 GST_DEBUG_OBJECT (trans, "using pool alloc");
1421 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1423 gsize insize, outsize;
1426 /* no pool, we need to figure out the size of the output buffer first */
1427 insize = gst_buffer_get_size (inbuf);
1429 if (trans->passthrough) {
1430 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1431 /* passthrough, the output size is the same as the input size. */
1434 gboolean want_in_place = (bclass->transform_ip != NULL)
1435 && trans->always_in_place;
1437 if (want_in_place) {
1438 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1439 /* we alloc a buffer of the same size as the input */
1442 GstCaps *incaps, *outcaps;
1444 /* else use the transform function to get the size */
1445 incaps = gst_pad_get_current_caps (trans->sinkpad);
1446 outcaps = gst_pad_get_current_caps (trans->srcpad);
1448 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1449 /* copy transform, figure out the output size */
1450 res = gst_base_transform_transform_size (trans,
1451 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1453 gst_caps_unref (incaps);
1454 gst_caps_unref (outcaps);
1460 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1462 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1470 GST_ERROR_OBJECT (trans, "unknown output size");
1471 return GST_FLOW_ERROR;
1476 default_copy_metadata (GstBaseTransform * trans,
1477 GstBuffer * inbuf, GstBuffer * outbuf)
1479 GstBaseTransformPrivate *priv = trans->priv;
1481 /* now copy the metadata */
1482 GST_DEBUG_OBJECT (trans, "copying metadata");
1484 /* this should not happen, buffers allocated from a pool or with
1485 * new_allocate should always be writable. */
1486 if (!gst_buffer_is_writable (outbuf))
1489 /* when we get here, the metadata should be writable */
1490 gst_buffer_copy_into (outbuf, inbuf,
1491 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1493 /* clear the GAP flag when the subclass does not understand it */
1494 if (!priv->gap_aware)
1495 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1502 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1507 /* Given @caps calcultate the size of one unit.
1509 * For video caps, this is the size of one frame (and thus one buffer).
1510 * For audio caps, this is the size of one sample.
1512 * These values are cached since they do not change and the calculation
1513 * potentially involves parsing caps and other expensive stuff.
1515 * We have two cache locations to store the size, one for the source caps
1516 * and one for the sink caps.
1518 * this function returns FALSE if no size could be calculated.
1521 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1524 gboolean res = FALSE;
1525 GstBaseTransformClass *bclass;
1527 /* see if we have the result cached */
1528 if (trans->cache_caps1 == caps) {
1529 *size = trans->cache_caps1_size;
1530 GST_DEBUG_OBJECT (trans,
1531 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1534 if (trans->cache_caps2 == caps) {
1535 *size = trans->cache_caps2_size;
1536 GST_DEBUG_OBJECT (trans,
1537 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1541 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1542 if (bclass->get_unit_size) {
1543 res = bclass->get_unit_size (trans, caps, size);
1544 GST_DEBUG_OBJECT (trans,
1545 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1546 caps, *size, res ? "TRUE" : "FALSE");
1549 /* and cache the values */
1550 if (trans->cache_caps1 == NULL) {
1551 gst_caps_replace (&trans->cache_caps1, caps);
1552 trans->cache_caps1_size = *size;
1553 GST_DEBUG_OBJECT (trans,
1554 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1555 } else if (trans->cache_caps2 == NULL) {
1556 gst_caps_replace (&trans->cache_caps2, caps);
1557 trans->cache_caps2_size = *size;
1558 GST_DEBUG_OBJECT (trans,
1559 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1561 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1565 GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
1571 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1573 GstBaseTransform *trans;
1574 GstBaseTransformClass *bclass;
1575 gboolean ret = TRUE;
1577 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1578 if (G_UNLIKELY (trans == NULL)) {
1579 gst_event_unref (event);
1582 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1584 if (bclass->sink_event)
1585 ret = bclass->sink_event (trans, event);
1587 gst_event_unref (event);
1589 gst_object_unref (trans);
1595 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1597 gboolean ret = TRUE, forward = TRUE;
1599 switch (GST_EVENT_TYPE (event)) {
1600 case GST_EVENT_FLUSH_START:
1602 case GST_EVENT_FLUSH_STOP:
1603 GST_OBJECT_LOCK (trans);
1604 /* reset QoS parameters */
1605 trans->priv->proportion = 1.0;
1606 trans->priv->earliest_time = -1;
1607 trans->priv->discont = FALSE;
1608 trans->priv->processed = 0;
1609 trans->priv->dropped = 0;
1610 GST_OBJECT_UNLOCK (trans);
1611 /* we need new segment info after the flush. */
1612 trans->have_segment = FALSE;
1613 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1614 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1620 case GST_EVENT_CAPS:
1624 gst_event_parse_caps (event, &caps);
1625 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1630 case GST_EVENT_SEGMENT:
1632 gst_event_copy_segment (event, &trans->segment);
1633 trans->have_segment = TRUE;
1635 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1644 ret = gst_pad_push_event (trans->srcpad, event);
1646 gst_event_unref (event);
1652 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1654 GstBaseTransform *trans;
1655 GstBaseTransformClass *bclass;
1656 gboolean ret = TRUE;
1658 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1659 if (G_UNLIKELY (trans == NULL)) {
1660 gst_event_unref (event);
1664 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1666 if (bclass->src_event)
1667 ret = bclass->src_event (trans, event);
1669 gst_event_unref (event);
1671 gst_object_unref (trans);
1677 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1681 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1683 switch (GST_EVENT_TYPE (event)) {
1684 case GST_EVENT_SEEK:
1686 case GST_EVENT_NAVIGATION:
1691 GstClockTimeDiff diff;
1692 GstClockTime timestamp;
1694 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1695 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1702 ret = gst_pad_push_event (trans->sinkpad, event);
1707 /* perform a transform on @inbuf and put the result in @outbuf.
1709 * This function is common to the push and pull-based operations.
1711 * This function takes ownership of @inbuf */
1712 static GstFlowReturn
1713 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1714 GstBuffer ** outbuf)
1716 GstBaseTransformClass *bclass;
1717 GstFlowReturn ret = GST_FLOW_OK;
1718 gboolean want_in_place;
1719 GstClockTime running_time;
1720 GstClockTime timestamp;
1721 gboolean reconfigure;
1723 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1725 GST_OBJECT_LOCK (trans->sinkpad);
1726 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1727 || trans->priv->reconfigure;
1728 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1729 trans->priv->reconfigure = FALSE;
1730 GST_OBJECT_UNLOCK (trans->sinkpad);
1732 if (G_UNLIKELY (reconfigure)) {
1735 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1737 incaps = gst_pad_get_current_caps (trans->sinkpad);
1739 goto no_reconfigure;
1741 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1742 * will reconfigure the transform with the new output format. We can only
1743 * do this if the buffer actually has caps. */
1744 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1745 gst_caps_unref (incaps);
1746 goto not_negotiated;
1748 gst_caps_unref (incaps);
1752 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1753 GST_DEBUG_OBJECT (trans,
1754 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1755 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1756 GST_BUFFER_OFFSET (inbuf));
1758 GST_DEBUG_OBJECT (trans,
1759 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1760 gst_buffer_get_size (inbuf));
1762 /* Don't allow buffer handling before negotiation, except in passthrough mode
1763 * or if the class doesn't implement a set_caps function (in which case it doesn't
1766 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1767 goto not_negotiated;
1769 /* Set discont flag so we can mark the outgoing buffer */
1770 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1771 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1772 trans->priv->discont = TRUE;
1775 /* can only do QoS if the segment is in TIME */
1776 if (trans->segment.format != GST_FORMAT_TIME)
1779 /* QOS is done on the running time of the buffer, get it now */
1780 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1781 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1784 if (running_time != -1) {
1786 GstClockTime earliest_time;
1789 /* lock for getting the QoS parameters that are set (in a different thread)
1790 * with the QOS events */
1791 GST_OBJECT_LOCK (trans);
1792 earliest_time = trans->priv->earliest_time;
1793 proportion = trans->priv->proportion;
1794 /* check for QoS, don't perform conversion for buffers
1795 * that are known to be late. */
1796 need_skip = trans->priv->qos_enabled &&
1797 earliest_time != -1 && running_time <= earliest_time;
1798 GST_OBJECT_UNLOCK (trans);
1801 GstMessage *qos_msg;
1802 GstClockTime duration;
1803 guint64 stream_time;
1806 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1807 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1808 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1810 trans->priv->dropped++;
1812 duration = GST_BUFFER_DURATION (inbuf);
1814 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1816 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1819 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1820 stream_time, timestamp, duration);
1821 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1822 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1823 trans->priv->processed, trans->priv->dropped);
1824 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1826 /* mark discont for next buffer */
1827 trans->priv->discont = TRUE;
1834 /* first try to allocate an output buffer based on the currently negotiated
1835 * format. outbuf will contain a buffer suitable for doing the configured
1836 * transform after this function. */
1837 if (bclass->prepare_output_buffer == NULL)
1840 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1841 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1843 if (ret != GST_FLOW_OK || *outbuf == NULL)
1846 if (inbuf == *outbuf) {
1847 GST_DEBUG_OBJECT (trans, "reusing input buffer");
1848 } else if (trans->passthrough) {
1849 /* we are asked to perform a passthrough transform but the input and
1850 * output buffers are different. We have to discard the output buffer and
1851 * reuse the input buffer. This is rather weird, it means that the prepare
1852 * output buffer does something wrong. */
1853 GST_WARNING_OBJECT (trans, "passthrough but different buffers, check the "
1854 "prepare_output_buffer implementation");
1855 gst_buffer_unref (*outbuf);
1858 /* copy the metadata */
1859 if (bclass->copy_metadata)
1860 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1861 /* something failed, post a warning */
1862 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1863 ("could not copy metadata"), (NULL));
1866 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1869 /* now perform the needed transform */
1870 if (trans->passthrough) {
1871 /* In passthrough mode, give transform_ip a look at the
1872 * buffer, without making it writable, or just push the
1874 if (bclass->transform_ip) {
1875 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1876 ret = bclass->transform_ip (trans, *outbuf);
1878 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1881 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1883 if (want_in_place) {
1884 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1886 if (inbuf != *outbuf) {
1887 guint8 *indata, *outdata;
1888 gsize insize, outsize;
1890 /* Different buffer. The data can still be the same when we are dealing
1891 * with subbuffers of the same buffer. Note that because of the FIXME in
1892 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1893 * outbuf to keep them writable */
1894 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1895 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1897 if (indata != outdata)
1898 memcpy (outdata, indata, insize);
1900 gst_buffer_unmap (inbuf, indata, insize);
1901 gst_buffer_unmap (*outbuf, outdata, outsize);
1903 ret = bclass->transform_ip (trans, *outbuf);
1905 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1907 if (bclass->transform)
1908 ret = bclass->transform (trans, inbuf, *outbuf);
1910 ret = GST_FLOW_NOT_SUPPORTED;
1915 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1916 * the input buffer, no refcount is changed to keep the input buffer writable
1918 if (*outbuf != inbuf)
1919 gst_buffer_unref (inbuf);
1926 gst_buffer_unref (inbuf);
1928 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1929 ("not negotiated"), ("not negotiated"));
1930 return GST_FLOW_NOT_NEGOTIATED;
1934 gst_buffer_unref (inbuf);
1935 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1936 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1937 return GST_FLOW_NOT_SUPPORTED;
1941 gst_buffer_unref (inbuf);
1943 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1944 gst_flow_get_name (ret));
1949 /* FIXME, getrange is broken, need to pull range from the other
1950 * end based on the transform_size result.
1952 static GstFlowReturn
1953 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1954 guint length, GstBuffer ** buffer)
1956 GstBaseTransform *trans;
1957 GstBaseTransformClass *klass;
1961 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1963 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1964 if (G_UNLIKELY (ret != GST_FLOW_OK))
1967 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1968 if (klass->before_transform)
1969 klass->before_transform (trans, inbuf);
1971 GST_BASE_TRANSFORM_LOCK (trans);
1972 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1973 GST_BASE_TRANSFORM_UNLOCK (trans);
1976 gst_object_unref (trans);
1983 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1984 gst_flow_get_name (ret));
1989 static GstFlowReturn
1990 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
1992 GstBaseTransform *trans;
1993 GstBaseTransformClass *klass;
1995 GstClockTime position = GST_CLOCK_TIME_NONE;
1996 GstClockTime timestamp, duration;
1997 GstBuffer *outbuf = NULL;
1999 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
2001 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2002 duration = GST_BUFFER_DURATION (buffer);
2004 /* calculate end position of the incoming buffer */
2005 if (timestamp != GST_CLOCK_TIME_NONE) {
2006 if (duration != GST_CLOCK_TIME_NONE)
2007 position = timestamp + duration;
2009 position = timestamp;
2012 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2013 if (klass->before_transform)
2014 klass->before_transform (trans, buffer);
2016 /* protect transform method and concurrent buffer alloc */
2017 GST_BASE_TRANSFORM_LOCK (trans);
2018 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2019 GST_BASE_TRANSFORM_UNLOCK (trans);
2021 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2022 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2023 if (outbuf != NULL) {
2024 if (ret == GST_FLOW_OK) {
2025 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2027 /* Remember last stop position */
2028 if (position != GST_CLOCK_TIME_NONE &&
2029 trans->segment.format == GST_FORMAT_TIME)
2030 trans->segment.position = position;
2032 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2033 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2034 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2035 position_out += GST_BUFFER_DURATION (outbuf);
2036 } else if (position != GST_CLOCK_TIME_NONE) {
2037 position_out = position;
2039 if (position_out != GST_CLOCK_TIME_NONE
2040 && trans->segment.format == GST_FORMAT_TIME)
2041 trans->priv->position_out = position_out;
2043 /* apply DISCONT flag if the buffer is not yet marked as such */
2044 if (trans->priv->discont) {
2045 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2046 outbuf = gst_buffer_make_writable (outbuf);
2047 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2049 trans->priv->discont = FALSE;
2051 trans->priv->processed++;
2053 ret = gst_pad_push (trans->srcpad, outbuf);
2055 gst_buffer_unref (outbuf);
2059 /* convert internal flow to OK and mark discont for the next buffer. */
2060 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2061 trans->priv->discont = TRUE;
2069 gst_base_transform_set_property (GObject * object, guint prop_id,
2070 const GValue * value, GParamSpec * pspec)
2072 GstBaseTransform *trans;
2074 trans = GST_BASE_TRANSFORM (object);
2078 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2081 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2087 gst_base_transform_get_property (GObject * object, guint prop_id,
2088 GValue * value, GParamSpec * pspec)
2090 GstBaseTransform *trans;
2092 trans = GST_BASE_TRANSFORM (object);
2096 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2099 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2104 /* not a vmethod of anything, just an internal method */
2106 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2108 GstBaseTransformClass *bclass;
2109 gboolean result = TRUE;
2111 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2114 GstCaps *incaps, *outcaps;
2116 if (trans->priv->pad_mode == GST_PAD_ACTIVATE_NONE && bclass->start)
2117 result &= bclass->start (trans);
2119 incaps = gst_pad_get_current_caps (trans->sinkpad);
2120 outcaps = gst_pad_get_current_caps (trans->srcpad);
2122 GST_OBJECT_LOCK (trans);
2123 if (incaps && outcaps)
2124 trans->have_same_caps =
2125 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2127 trans->have_same_caps = trans->passthrough;
2128 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2129 trans->negotiated = FALSE;
2130 trans->have_segment = FALSE;
2131 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2132 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2133 trans->priv->proportion = 1.0;
2134 trans->priv->earliest_time = -1;
2135 trans->priv->discont = FALSE;
2136 trans->priv->processed = 0;
2137 trans->priv->dropped = 0;
2138 GST_OBJECT_UNLOCK (trans);
2141 gst_caps_unref (incaps);
2143 gst_caps_unref (outcaps);
2145 /* We must make sure streaming has finished before resetting things
2146 * and calling the ::stop vfunc */
2147 GST_PAD_STREAM_LOCK (trans->sinkpad);
2148 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2150 trans->have_same_caps = FALSE;
2151 /* We can only reset the passthrough mode if the instance told us to
2152 handle it in configure_caps */
2153 if (bclass->passthrough_on_same_caps) {
2154 gst_base_transform_set_passthrough (trans, FALSE);
2156 gst_caps_replace (&trans->cache_caps1, NULL);
2157 gst_caps_replace (&trans->cache_caps2, NULL);
2159 if (trans->priv->pad_mode != GST_PAD_ACTIVATE_NONE && bclass->stop)
2160 result &= bclass->stop (trans);
2162 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2169 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2171 gboolean result = TRUE;
2172 GstBaseTransform *trans;
2174 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2176 result = gst_base_transform_activate (trans, active);
2179 trans->priv->pad_mode =
2180 active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
2182 gst_object_unref (trans);
2188 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2190 gboolean result = FALSE;
2191 GstBaseTransform *trans;
2193 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2195 result = gst_pad_activate_pull (trans->sinkpad, active);
2198 result &= gst_base_transform_activate (trans, active);
2201 trans->priv->pad_mode =
2202 active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
2204 gst_object_unref (trans);
2210 * gst_base_transform_set_passthrough:
2211 * @trans: the #GstBaseTransform to set
2212 * @passthrough: boolean indicating passthrough mode.
2214 * Set passthrough mode for this filter by default. This is mostly
2215 * useful for filters that do not care about negotiation.
2217 * Always TRUE for filters which don't implement either a transform
2218 * or transform_ip method.
2223 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2224 gboolean passthrough)
2226 GstBaseTransformClass *bclass;
2228 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2230 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2232 GST_OBJECT_LOCK (trans);
2233 if (passthrough == FALSE) {
2234 if (bclass->transform_ip || bclass->transform)
2235 trans->passthrough = FALSE;
2237 trans->passthrough = TRUE;
2240 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2241 GST_OBJECT_UNLOCK (trans);
2245 * gst_base_transform_is_passthrough:
2246 * @trans: the #GstBaseTransform to query
2248 * See if @trans is configured as a passthrough transform.
2250 * Returns: TRUE is the transform is configured in passthrough mode.
2255 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2259 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2261 GST_OBJECT_LOCK (trans);
2262 result = trans->passthrough;
2263 GST_OBJECT_UNLOCK (trans);
2269 * gst_base_transform_set_in_place:
2270 * @trans: the #GstBaseTransform to modify
2271 * @in_place: Boolean value indicating that we would like to operate
2272 * on in_place buffers.
2274 * Determines whether a non-writable buffer will be copied before passing
2275 * to the transform_ip function.
2277 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2278 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2284 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2286 GstBaseTransformClass *bclass;
2288 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2290 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2292 GST_OBJECT_LOCK (trans);
2295 if (bclass->transform_ip) {
2296 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2297 trans->always_in_place = TRUE;
2300 if (bclass->transform) {
2301 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2302 trans->always_in_place = FALSE;
2306 GST_OBJECT_UNLOCK (trans);
2310 * gst_base_transform_is_in_place:
2311 * @trans: the #GstBaseTransform to query
2313 * See if @trans is configured as a in_place transform.
2315 * Returns: TRUE is the transform is configured in in_place mode.
2320 gst_base_transform_is_in_place (GstBaseTransform * trans)
2324 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2326 GST_OBJECT_LOCK (trans);
2327 result = trans->always_in_place;
2328 GST_OBJECT_UNLOCK (trans);
2334 * gst_base_transform_update_qos:
2335 * @trans: a #GstBaseTransform
2336 * @proportion: the proportion
2337 * @diff: the diff against the clock
2338 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2341 * Set the QoS parameters in the transform. This function is called internally
2342 * when a QOS event is received but subclasses can provide custom information
2350 gst_base_transform_update_qos (GstBaseTransform * trans,
2351 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2354 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2356 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2357 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2358 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2360 GST_OBJECT_LOCK (trans);
2361 trans->priv->proportion = proportion;
2362 trans->priv->earliest_time = timestamp + diff;
2363 GST_OBJECT_UNLOCK (trans);
2367 * gst_base_transform_set_qos_enabled:
2368 * @trans: a #GstBaseTransform
2369 * @enabled: new state
2371 * Enable or disable QoS handling in the transform.
2378 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2380 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2382 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2384 GST_OBJECT_LOCK (trans);
2385 trans->priv->qos_enabled = enabled;
2386 GST_OBJECT_UNLOCK (trans);
2390 * gst_base_transform_is_qos_enabled:
2391 * @trans: a #GstBaseTransform
2393 * Queries if the transform will handle QoS.
2395 * Returns: TRUE if QoS is enabled.
2402 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2406 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2408 GST_OBJECT_LOCK (trans);
2409 result = trans->priv->qos_enabled;
2410 GST_OBJECT_UNLOCK (trans);
2416 * gst_base_transform_set_gap_aware:
2417 * @trans: a #GstBaseTransform
2418 * @gap_aware: New state
2420 * If @gap_aware is %FALSE (the default), output buffers will have the
2421 * %GST_BUFFER_FLAG_GAP flag unset.
2423 * If set to %TRUE, the element must handle output buffers with this flag set
2424 * correctly, i.e. it can assume that the buffer contains neutral data but must
2425 * unset the flag if the output is no neutral data.
2432 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2434 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2436 GST_OBJECT_LOCK (trans);
2437 trans->priv->gap_aware = gap_aware;
2438 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2439 GST_OBJECT_UNLOCK (trans);
2443 * gst_base_transform_suggest:
2444 * @trans: a #GstBaseTransform
2445 * @caps: (transfer none): caps to suggest
2446 * @size: buffer size to suggest
2448 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2454 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2457 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2459 /* push the renegotiate event */
2460 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2461 gst_event_new_reconfigure ()))
2462 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2466 * gst_base_transform_reconfigure:
2467 * @trans: a #GstBaseTransform
2469 * Instructs @trans to renegotiate a new downstream transform on the next
2470 * buffer. This function is typically called after properties on the transform
2471 * were set that influence the output format.
2476 gst_base_transform_reconfigure (GstBaseTransform * trans)
2478 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2480 GST_OBJECT_LOCK (trans);
2481 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2482 trans->priv->reconfigure = TRUE;
2483 GST_OBJECT_UNLOCK (trans);