2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
4 * 2005 Andy Wingo <wingo@fluendo.com>
5 * 2005 Thomas Vander Stichele <thomas at apestaart dot org>
6 * 2008 Wim Taymans <wim.taymans@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * SECTION:gstbasetransform
26 * @short_description: Base class for simple transform filters
27 * @see_also: #GstBaseSrc, #GstBaseSink
29 * This base class is for filter elements that process data.
33 * <listitem><para>one sinkpad and one srcpad</para></listitem>
35 * Possible formats on sink and source pad implemented
36 * with custom transform_caps function. By default uses
37 * same format on sink and source.
39 * <listitem><para>Handles state changes</para></listitem>
40 * <listitem><para>Does flushing</para></listitem>
41 * <listitem><para>Push mode</para></listitem>
43 * Pull mode if the sub-class transform can operate on arbitrary data
48 * <title>Use Cases</title>
52 * <itemizedlist><title>Passthrough mode</title>
54 * Element has no interest in modifying the buffer. It may want to inspect it,
55 * in which case the element should have a transform_ip function. If there
56 * is no transform_ip function in passthrough mode, the buffer is pushed
60 * On the GstBaseTransformClass is the passthrough_on_same_caps variable
61 * which will automatically set/unset passthrough based on whether the
62 * element negotiates the same caps on both pads.
65 * passthrough_on_same_caps on an element that doesn't implement a
66 * transform_caps function is useful for elements that only inspect data
71 * <title>Example elements</title>
72 * <listitem>Level</listitem>
73 * <listitem>Videoscale, audioconvert, ffmpegcolorspace, audioresample in
74 * certain modes.</listitem>
79 * <title>Modifications in-place - input buffer and output buffer are the
82 * The element must implement a transform_ip function.
85 * Output buffer size must <= input buffer size
88 * If the always_in_place flag is set, non-writable buffers will be copied
89 * and passed to the transform_ip function, otherwise a new buffer will be
90 * created and the transform function called.
93 * Incoming writable buffers will be passed to the transform_ip function
94 * immediately. </para></listitem>
96 * only implementing transform_ip and not transform implies always_in_place
101 * <title>Example elements</title>
102 * <listitem>Volume</listitem>
103 * <listitem>Audioconvert in certain modes (signed/unsigned
104 * conversion)</listitem>
105 * <listitem>ffmpegcolorspace in certain modes (endianness
106 * swapping)</listitem>
111 * <title>Modifications only to the caps/metadata of a buffer</title>
113 * The element does not require writable data, but non-writable buffers
114 * should be subbuffered so that the meta-information can be replaced.
117 * Elements wishing to operate in this mode should replace the
118 * prepare_output_buffer method to create subbuffers of the input buffer
119 * and set always_in_place to TRUE
123 * <title>Example elements</title>
124 * <listitem>Capsfilter when setting caps on outgoing buffers that have
126 * <listitem>identity when it is going to re-timestamp buffers by
127 * datarate.</listitem>
131 * <itemizedlist><title>Normal mode</title>
133 * always_in_place flag is not set, or there is no transform_ip function
136 * Element will receive an input buffer and output buffer to operate on.
139 * Output buffer is allocated by calling the prepare_output_buffer function.
143 * <title>Example elements</title>
144 * <listitem>Videoscale, ffmpegcolorspace, audioconvert when doing
145 * scaling/conversions</listitem>
149 * <itemizedlist><title>Special output buffer allocations</title>
151 * Elements which need to do special allocation of their output buffers
152 * other than what gst_buffer_pad_alloc allows should implement a
153 * prepare_output_buffer method, which calls the parent implementation and
154 * passes the newly allocated buffer.
158 * <title>Example elements</title>
159 * <listitem>efence</listitem>
166 * <title>Sub-class settable flags on GstBaseTransform</title>
170 * <itemizedlist><title>passthrough</title>
172 * Implies that in the current configuration, the sub-class is not
173 * interested in modifying the buffers.
176 * Elements which are always in passthrough mode whenever the same caps
177 * has been negotiated on both pads can set the class variable
178 * passthrough_on_same_caps to have this behaviour automatically.
183 * <itemizedlist><title>always_in_place</title>
185 * Determines whether a non-writable buffer will be copied before passing
186 * to the transform_ip function.
189 * Implied TRUE if no transform function is implemented.
192 * Implied FALSE if ONLY transform function is implemented.
208 #include "../../../gst/gst_private.h"
209 #include "../../../gst/gst-i18n-lib.h"
210 #include "gstbasetransform.h"
211 #include <gst/gstmarshal.h>
213 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
214 #define GST_CAT_DEFAULT gst_base_transform_debug
216 /* BaseTransform signals and args */
223 #define DEFAULT_PROP_QOS FALSE
231 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
232 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
234 struct _GstBaseTransformPrivate
236 /* QoS *//* with LOCK */
237 gboolean qos_enabled;
239 GstClockTime earliest_time;
240 /* previous buffer had a discont */
243 GstActivateMode pad_mode;
247 /* caps used for allocating buffers */
248 gboolean proxy_alloc;
252 /* upstream caps and size suggestions */
253 GstCaps *sink_suggest;
255 gboolean suggest_pending;
257 gboolean reconfigure;
263 GstClockTime last_stop_out;
266 static GstElementClass *parent_class = NULL;
268 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
269 static void gst_base_transform_init (GstBaseTransform * trans,
270 GstBaseTransformClass * klass);
271 static GstFlowReturn gst_base_transform_prepare_output_buffer (GstBaseTransform
272 * trans, GstBuffer * input, GstBuffer ** buf);
275 gst_base_transform_get_type (void)
277 static volatile gsize base_transform_type = 0;
279 if (g_once_init_enter (&base_transform_type)) {
281 static const GTypeInfo base_transform_info = {
282 sizeof (GstBaseTransformClass),
285 (GClassInitFunc) gst_base_transform_class_init,
288 sizeof (GstBaseTransform),
290 (GInstanceInitFunc) gst_base_transform_init,
293 _type = g_type_register_static (GST_TYPE_ELEMENT,
294 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
295 g_once_init_leave (&base_transform_type, _type);
297 return base_transform_type;
300 static void gst_base_transform_finalize (GObject * object);
301 static void gst_base_transform_set_property (GObject * object, guint prop_id,
302 const GValue * value, GParamSpec * pspec);
303 static void gst_base_transform_get_property (GObject * object, guint prop_id,
304 GValue * value, GParamSpec * pspec);
305 static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
307 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
309 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
311 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
312 GstCaps * caps, gsize * size);
314 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
315 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
317 static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
318 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
320 static gboolean gst_base_transform_check_get_range (GstPad * pad);
321 static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
322 guint length, GstBuffer ** buffer);
323 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
325 static GstCaps *gst_base_transform_getcaps (GstPad * pad);
326 static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
327 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
328 GstPadDirection direction, GstCaps * caps);
329 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
330 GstPad * pad, GstCaps * caps, gboolean reconfigure);
331 static gboolean gst_base_transform_query (GstPad * pad, GstQuery ** query);
332 static const GstQueryType *gst_base_transform_query_type (GstPad * pad);
334 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
337 gst_base_transform_finalize (GObject * object)
339 GstBaseTransform *trans;
341 trans = GST_BASE_TRANSFORM (object);
343 gst_caps_replace (&trans->priv->sink_suggest, NULL);
344 g_mutex_free (trans->transform_lock);
346 G_OBJECT_CLASS (parent_class)->finalize (object);
350 gst_base_transform_class_init (GstBaseTransformClass * klass)
352 GObjectClass *gobject_class;
354 gobject_class = G_OBJECT_CLASS (klass);
356 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
357 "basetransform element");
359 GST_DEBUG ("gst_base_transform_class_init");
361 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
363 parent_class = g_type_class_peek_parent (klass);
365 gobject_class->set_property = gst_base_transform_set_property;
366 gobject_class->get_property = gst_base_transform_get_property;
368 g_object_class_install_property (gobject_class, PROP_QOS,
369 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
370 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
372 gobject_class->finalize = gst_base_transform_finalize;
374 klass->passthrough_on_same_caps = FALSE;
375 klass->event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
376 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
378 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
382 gst_base_transform_init (GstBaseTransform * trans,
383 GstBaseTransformClass * bclass)
385 GstPadTemplate *pad_template;
387 GST_DEBUG ("gst_base_transform_init");
389 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
392 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
393 g_return_if_fail (pad_template != NULL);
394 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
395 gst_pad_set_getcaps_function (trans->sinkpad,
396 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
397 gst_pad_set_acceptcaps_function (trans->sinkpad,
398 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
399 gst_pad_set_event_function (trans->sinkpad,
400 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
401 gst_pad_set_chain_function (trans->sinkpad,
402 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
403 gst_pad_set_activatepush_function (trans->sinkpad,
404 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
405 gst_pad_set_query_function (trans->sinkpad,
406 GST_DEBUG_FUNCPTR (gst_base_transform_query));
407 gst_pad_set_query_type_function (trans->sinkpad,
408 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
409 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
412 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
413 g_return_if_fail (pad_template != NULL);
414 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
415 gst_pad_set_getcaps_function (trans->srcpad,
416 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
417 gst_pad_set_acceptcaps_function (trans->srcpad,
418 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
419 gst_pad_set_event_function (trans->srcpad,
420 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
421 gst_pad_set_checkgetrange_function (trans->srcpad,
422 GST_DEBUG_FUNCPTR (gst_base_transform_check_get_range));
423 gst_pad_set_getrange_function (trans->srcpad,
424 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
425 gst_pad_set_activatepull_function (trans->srcpad,
426 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
427 gst_pad_set_query_function (trans->srcpad,
428 GST_DEBUG_FUNCPTR (gst_base_transform_query));
429 gst_pad_set_query_type_function (trans->srcpad,
430 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
431 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
433 trans->transform_lock = g_mutex_new ();
434 trans->pending_configure = FALSE;
435 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
436 trans->cache_caps1 = NULL;
437 trans->cache_caps2 = NULL;
438 trans->priv->pad_mode = GST_ACTIVATE_NONE;
439 trans->priv->gap_aware = FALSE;
441 trans->passthrough = FALSE;
442 if (bclass->transform == NULL) {
443 /* If no transform function, always_in_place is TRUE */
444 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
445 trans->always_in_place = TRUE;
447 if (bclass->transform_ip == NULL) {
448 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
449 trans->passthrough = TRUE;
453 trans->priv->processed = 0;
454 trans->priv->dropped = 0;
457 /* given @caps on the src or sink pad (given by @direction)
458 * calculate the possible caps on the other pad.
460 * Returns new caps, unref after usage.
463 gst_base_transform_transform_caps (GstBaseTransform * trans,
464 GstPadDirection direction, GstCaps * caps)
467 GstBaseTransformClass *klass;
472 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
474 /* if there is a custom transform function, use this */
475 if (klass->transform_caps) {
479 /* start with empty caps */
480 ret = gst_caps_new_empty ();
481 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
483 if (gst_caps_is_any (caps)) {
484 /* for any caps we still have to call the transform function */
485 GST_DEBUG_OBJECT (trans, "from: ANY");
486 temp = klass->transform_caps (trans, direction, caps);
487 GST_DEBUG_OBJECT (trans, " to: %" GST_PTR_FORMAT, temp);
489 temp = gst_caps_make_writable (temp);
490 gst_caps_append (ret, temp);
492 gint n = gst_caps_get_size (caps);
493 /* we send caps with just one structure to the transform
494 * function as this is easier for the element */
495 for (i = 0; i < n; i++) {
498 nth = gst_caps_copy_nth (caps, i);
499 GST_LOG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
500 temp = klass->transform_caps (trans, direction, nth);
501 gst_caps_unref (nth);
502 GST_LOG_OBJECT (trans, " to[%d]: %" GST_PTR_FORMAT, i, temp);
504 temp = gst_caps_make_writable (temp);
506 /* here we need to only append those structures, that are not yet
507 * in there, we use the merge function for this */
508 gst_caps_merge (ret, temp);
510 GST_LOG_OBJECT (trans, " merged[%d]: %" GST_PTR_FORMAT, i, ret);
512 GST_LOG_OBJECT (trans, "merged: (%d)", gst_caps_get_size (ret));
513 /* FIXME: we can't do much simplification here because we don't really want to
514 * change the caps order
515 gst_caps_do_simplify (ret);
516 GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
520 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
521 /* no transform function, use the identity transform */
522 ret = gst_caps_ref (caps);
525 GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
531 /* transform a buffer of @size with @caps on the pad with @direction to
532 * the size of a buffer with @othercaps and store the result in @othersize
534 * We have two ways of doing this:
535 * 1) use a custom transform size function, this is for complicated custom
536 * cases with no fixed unit_size.
537 * 2) use the unit_size functions where there is a relationship between the
538 * caps and the size of a buffer.
541 gst_base_transform_transform_size (GstBaseTransform * trans,
542 GstPadDirection direction, GstCaps * caps,
543 gsize size, GstCaps * othercaps, gsize * othersize)
545 gsize inunitsize, outunitsize, units;
546 GstBaseTransformClass *klass;
549 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
551 GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
552 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
553 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
555 if (klass->transform_size) {
556 /* if there is a custom transform function, use this */
557 ret = klass->transform_size (trans, direction, caps, size, othercaps,
559 } else if (klass->get_unit_size == NULL) {
560 /* if there is no transform_size and no unit_size, it means the
561 * element does not modify the size of a buffer */
565 /* there is no transform_size function, we have to use the unit_size
566 * functions. This method assumes there is a fixed unit_size associated with
567 * each caps. We provide the same amount of units on both sides. */
568 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
571 GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
574 /* input size must be a multiple of the unit_size of the input caps */
575 if (inunitsize == 0 || (size % inunitsize != 0))
578 /* get the amount of units */
579 units = size / inunitsize;
581 /* now get the unit size of the output */
582 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
585 /* the output size is the unit_size times the amount of units on the
587 *othersize = units * outunitsize;
588 GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
597 GST_DEBUG_OBJECT (trans, "could not get in_size");
598 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
603 GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size,
605 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
606 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
611 GST_DEBUG_OBJECT (trans, "could not get out_size");
612 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
617 /* get the caps that can be handled by @pad. We perform:
619 * - take the caps of peer of otherpad,
620 * - filter against the padtemplate of otherpad,
621 * - calculate all transforms of remaining caps
622 * - filter against template of @pad
624 * If there is no peer, we simply return the caps of the padtemplate of pad.
627 gst_base_transform_getcaps (GstPad * pad)
629 GstBaseTransform *trans;
631 GstCaps *peercaps, *caps;
633 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
635 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
637 /* we can do what the peer can */
638 peercaps = gst_pad_peer_get_caps (otherpad);
641 const GstCaps *templ;
643 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
645 /* filtered against our padtemplate on the other side */
646 templ = gst_pad_get_pad_template_caps (otherpad);
647 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
648 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
649 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
651 /* then see what we can transform this to */
652 caps = gst_base_transform_transform_caps (trans,
653 GST_PAD_DIRECTION (otherpad), temp);
654 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
655 gst_caps_unref (temp);
659 /* and filter against the template of this pad */
660 templ = gst_pad_get_pad_template_caps (pad);
661 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
662 /* We keep the caps sorted like the returned caps */
663 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
664 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
665 gst_caps_unref (caps);
668 /* Now try if we can put the untransformed downstream caps first */
669 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
670 if (!gst_caps_is_empty (temp)) {
671 gst_caps_merge (temp, caps);
674 gst_caps_unref (temp);
677 /* no peer or the peer can do anything, our padtemplate is enough then */
678 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
682 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
685 gst_caps_unref (peercaps);
687 gst_object_unref (trans);
692 /* function triggered when the in and out caps are negotiated and need
693 * to be configured in the subclass. */
695 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
699 GstBaseTransformClass *klass;
701 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
703 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
704 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
706 /* clear the cache */
707 gst_caps_replace (&trans->cache_caps1, NULL);
708 gst_caps_replace (&trans->cache_caps2, NULL);
710 /* figure out same caps state */
711 trans->have_same_caps = gst_caps_is_equal (in, out);
712 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
714 /* If we've a transform_ip method and same input/output caps, set in_place
715 * by default. If for some reason the sub-class prefers using a transform
716 * function, it can clear the in place flag in the set_caps */
717 gst_base_transform_set_in_place (trans,
718 klass->transform_ip && trans->have_same_caps);
720 /* Set the passthrough if the class wants passthrough_on_same_caps
721 * and we have the same caps on each pad */
722 if (klass->passthrough_on_same_caps)
723 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
725 /* now configure the element with the caps */
726 if (klass->set_caps) {
727 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
728 ret = klass->set_caps (trans, in, out);
731 GST_OBJECT_LOCK (trans);
732 /* make sure we reevaluate how the buffer_alloc works wrt to proxy allocating
733 * the buffer. FIXME, this triggers some quite heavy codepaths that don't need
735 trans->priv->suggest_pending = TRUE;
736 GST_OBJECT_UNLOCK (trans);
737 trans->negotiated = ret;
743 /* check if caps @in on @pad can be transformed to @out on the other pad.
744 * We don't have a vmethod to test this yet so we have to do a somewhat less
745 * efficient check for this.
748 gst_base_transform_can_transform (GstBaseTransform * trans, GstPad * pad,
749 GstCaps * in, GstCaps * out)
753 /* convert the in caps to all possible out caps */
755 gst_base_transform_transform_caps (trans, GST_PAD_DIRECTION (pad), in);
757 /* check if transform is empty */
758 if (!othercaps || gst_caps_is_empty (othercaps))
761 /* check if the out caps is a subset of the othercaps */
762 if (!gst_caps_can_intersect (out, othercaps))
766 gst_caps_unref (othercaps);
768 GST_DEBUG_OBJECT (trans, "from %" GST_PTR_FORMAT, in);
769 GST_DEBUG_OBJECT (trans, "to %" GST_PTR_FORMAT, out);
776 GST_DEBUG_OBJECT (trans,
777 "transform returned useless %" GST_PTR_FORMAT, othercaps);
779 gst_caps_unref (othercaps);
784 GST_DEBUG_OBJECT (trans, "no subset");
786 gst_caps_unref (othercaps);
792 /* given a fixed @caps on @pad, create the best possible caps for the
794 * @caps must be fixed when calling this function.
796 * This function calls the transform caps vmethod of the basetransform to figure
797 * out the possible target formats. It then tries to select the best format from
800 * - attempt passthrough if the target caps is a superset of the input caps
801 * - fixating by using peer caps
802 * - fixating with transform fixate function
803 * - fixating with pad fixate functions.
805 * this function returns a caps that can be transformed into and is accepted by
809 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
810 GstCaps * caps, gboolean reconfigure)
812 GstBaseTransformClass *klass;
813 GstPad *otherpad, *otherpeer;
815 gboolean peer_checked = FALSE;
818 /* caps must be fixed here, this is a programming error if it's not */
819 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
821 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
823 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
824 otherpeer = gst_pad_get_peer (otherpad);
826 /* see how we can transform the input caps. We need to do this even for
827 * passthrough because it might be possible that this element cannot support
828 * passthrough at all. */
829 othercaps = gst_base_transform_transform_caps (trans,
830 GST_PAD_DIRECTION (pad), caps);
832 /* The caps we can actually output is the intersection of the transformed
833 * caps with the pad template for the pad */
836 const GstCaps *templ_caps;
838 templ_caps = gst_pad_get_pad_template_caps (otherpad);
839 GST_DEBUG_OBJECT (trans,
840 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
843 gst_caps_intersect_full (othercaps, templ_caps,
844 GST_CAPS_INTERSECT_FIRST);
846 gst_caps_unref (othercaps);
847 othercaps = intersect;
850 /* check if transform is empty */
851 if (!othercaps || gst_caps_is_empty (othercaps))
854 /* if the othercaps are not fixed, we need to fixate them, first attempt
855 * is by attempting passthrough if the othercaps are a superset of caps. */
856 /* FIXME. maybe the caps is not fixed because it has multiple structures of
858 is_fixed = gst_caps_is_fixed (othercaps);
859 if (!is_fixed && !reconfigure) {
860 GST_DEBUG_OBJECT (trans,
861 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
863 /* see if the target caps are a superset of the source caps, in this
864 * case we can try to perform passthrough */
865 if (gst_caps_can_intersect (othercaps, caps)) {
866 GST_DEBUG_OBJECT (trans, "try passthrough with %" GST_PTR_FORMAT, caps);
868 /* try passthrough. we know it's fixed, because caps is fixed */
869 if (gst_pad_accept_caps (otherpeer, caps)) {
870 GST_DEBUG_OBJECT (trans, "peer accepted %" GST_PTR_FORMAT, caps);
871 /* peer accepted unmodified caps, we free the original non-fixed
872 * caps and work with the passthrough caps */
873 gst_caps_unref (othercaps);
874 othercaps = gst_caps_ref (caps);
876 /* mark that we checked othercaps with the peer, this
877 * makes sure we don't call accept_caps again with these same
881 GST_DEBUG_OBJECT (trans,
882 "peer did not accept %" GST_PTR_FORMAT, caps);
885 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
886 gst_caps_unref (othercaps);
887 othercaps = gst_caps_ref (caps);
893 /* second attempt at fixation is done by intersecting with
895 if (!is_fixed && otherpeer) {
896 /* intersect against what the peer can do */
900 GST_DEBUG_OBJECT (trans, "othercaps now %" GST_PTR_FORMAT, othercaps);
902 peercaps = gst_pad_get_caps (otherpeer);
904 intersect = gst_caps_intersect (peercaps, othercaps);
907 gst_caps_intersect_full (peercaps, othercaps,
908 GST_CAPS_INTERSECT_FIRST);
909 gst_caps_unref (peercaps);
910 gst_caps_unref (othercaps);
911 othercaps = intersect;
912 peer_checked = FALSE;
914 is_fixed = gst_caps_is_fixed (othercaps);
916 GST_DEBUG_OBJECT (trans,
917 "filtering against peer yields %" GST_PTR_FORMAT, othercaps);
920 if (gst_caps_is_empty (othercaps))
921 goto no_transform_possible;
923 /* third attempt at fixation, call the fixate vmethod and
924 * ultimately call the pad fixate function. */
926 GST_DEBUG_OBJECT (trans,
927 "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
928 othercaps, GST_DEBUG_PAD_NAME (otherpad));
930 /* since we have no other way to fixate left, we might as well just take
931 * the first of the caps list and fixate that */
933 /* FIXME: when fixating using the vmethod, it might make sense to fixate
934 * each of the caps; but Wim doesn't see a use case for that yet */
935 gst_caps_truncate (othercaps);
936 peer_checked = FALSE;
938 if (klass->fixate_caps) {
939 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
940 " using caps %" GST_PTR_FORMAT
941 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
942 GST_DEBUG_PAD_NAME (otherpad));
943 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
944 is_fixed = gst_caps_is_fixed (othercaps);
946 /* if still not fixed, no other option but to let the default pad fixate
947 * function do its job */
949 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
950 " on pad %s:%s using gst_pad_fixate_caps", othercaps,
951 GST_DEBUG_PAD_NAME (otherpad));
952 gst_pad_fixate_caps (otherpad, othercaps);
953 is_fixed = gst_caps_is_fixed (othercaps);
955 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
957 GST_DEBUG ("caps are fixed");
958 /* else caps are fixed but the subclass may want to add fields */
959 if (klass->fixate_caps) {
960 othercaps = gst_caps_make_writable (othercaps);
962 GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
963 " using caps %" GST_PTR_FORMAT
964 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
965 GST_DEBUG_PAD_NAME (otherpad));
967 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
968 is_fixed = gst_caps_is_fixed (othercaps);
972 /* caps should be fixed now, if not we have to fail. */
974 goto could_not_fixate;
976 /* and peer should accept, don't check again if we already checked the
977 * othercaps against the peer. */
978 if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
981 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
982 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
985 gst_object_unref (otherpeer);
992 GST_DEBUG_OBJECT (trans,
993 "transform returned useless %" GST_PTR_FORMAT, othercaps);
996 no_transform_possible:
998 GST_DEBUG_OBJECT (trans,
999 "transform could not transform %" GST_PTR_FORMAT
1000 " in anything we support", caps);
1005 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1010 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1011 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1017 gst_object_unref (otherpeer);
1019 gst_caps_unref (othercaps);
1025 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1026 GstPadDirection direction, GstCaps * caps)
1030 GstCaps *othercaps = NULL;
1032 gboolean ret = TRUE;
1035 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1037 /* we need fixed caps for the check, fall back to the default implementation
1039 if (!gst_caps_is_fixed (caps))
1044 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1046 /* get all the formats we can handle on this pad */
1047 if (direction == GST_PAD_SRC)
1048 allowed = gst_pad_get_caps (trans->srcpad);
1050 allowed = gst_pad_get_caps (trans->sinkpad);
1053 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1054 goto no_transform_possible;
1057 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1059 /* intersect with the requested format */
1060 ret = gst_caps_can_intersect (allowed, caps);
1061 gst_caps_unref (allowed);
1064 goto no_transform_possible;
1068 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1070 /* find best possible caps for the other pad as a way to see if we can
1071 * transform this caps. */
1072 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1073 if (!othercaps || gst_caps_is_empty (othercaps))
1074 goto no_transform_possible;
1076 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1082 /* We know it's always NULL since we never use it */
1084 gst_caps_unref (othercaps);
1090 no_transform_possible:
1092 GST_DEBUG_OBJECT (trans,
1093 "transform could not transform %" GST_PTR_FORMAT
1094 " in anything we support", caps);
1101 gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
1103 gboolean ret = TRUE;
1104 GstBaseTransform *trans;
1105 GstBaseTransformClass *bclass;
1107 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1108 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1110 if (bclass->accept_caps)
1111 ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
1113 gst_object_unref (trans);
1118 /* called when new caps arrive on the sink or source pad,
1119 * We try to find the best caps for the other side using our _find_transform()
1120 * function. If there are caps, we configure the transform for this new
1123 * FIXME, this function is currently commutative but this should not really be
1124 * because we never set caps starting from the srcpad.
1127 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1128 GstCaps * caps, gboolean reconfigure)
1130 GstPad *otherpad, *otherpeer;
1131 GstCaps *othercaps = NULL;
1132 gboolean ret = TRUE;
1133 GstCaps *incaps, *outcaps;
1135 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1136 otherpeer = gst_pad_get_peer (otherpad);
1138 /* if we get called recursively, we bail out now to avoid an
1140 if (GST_PAD_IS_IN_SETCAPS (otherpad))
1143 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1145 /* find best possible caps for the other pad */
1146 othercaps = gst_base_transform_find_transform (trans, pad, caps, reconfigure);
1147 if (!othercaps || gst_caps_is_empty (othercaps))
1148 goto no_transform_possible;
1150 /* configure the element now */
1151 /* make sure in and out caps are correct */
1152 if (pad == trans->sinkpad) {
1154 outcaps = othercaps;
1160 /* if we have the same caps, we can optimize and reuse the input caps */
1161 if (gst_caps_is_equal (incaps, outcaps)) {
1162 GST_INFO_OBJECT (trans, "reuse caps");
1163 gst_caps_unref (othercaps);
1164 outcaps = othercaps = gst_caps_ref (incaps);
1167 /* call configure now */
1168 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1169 goto failed_configure;
1171 /* we know this will work, we implement the setcaps */
1172 gst_pad_set_caps (otherpad, othercaps);
1174 if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
1176 ret &= gst_pad_set_caps (otherpeer, othercaps);
1178 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1185 gst_object_unref (otherpeer);
1187 gst_caps_unref (othercaps);
1189 trans->negotiated = ret;
1194 no_transform_possible:
1196 GST_WARNING_OBJECT (trans,
1197 "transform could not transform %" GST_PTR_FORMAT
1198 " in anything we support", caps);
1204 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1205 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1212 gst_base_transform_query (GstPad * pad, GstQuery ** query)
1214 gboolean ret = FALSE;
1215 GstBaseTransform *trans;
1218 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1219 if (G_UNLIKELY (trans == NULL))
1221 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1223 switch (GST_QUERY_TYPE (*query)) {
1224 case GST_QUERY_POSITION:{
1227 gst_query_parse_position (*query, &format, NULL);
1228 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1232 if ((pad == trans->sinkpad)
1233 || (trans->priv->last_stop_out == GST_CLOCK_TIME_NONE)) {
1235 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1236 trans->segment.last_stop);
1238 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1239 trans->priv->last_stop_out);
1241 gst_query_set_position (*query, format, pos);
1243 ret = gst_pad_peer_query (otherpad, query);
1248 ret = gst_pad_peer_query (otherpad, query);
1252 gst_object_unref (trans);
1256 static const GstQueryType *
1257 gst_base_transform_query_type (GstPad * pad)
1259 static const GstQueryType types[] = {
1269 compute_upstream_suggestion (GstBaseTransform * trans, gsize expsize,
1273 GstBaseTransformPrivate *priv = trans->priv;
1275 GST_DEBUG_OBJECT (trans, "trying to find upstream suggestion");
1277 /* we cannot convert the current buffer but we might be able to suggest a
1278 * new format upstream, try to find what the best format is. */
1280 gst_base_transform_find_transform (trans, trans->srcpad, caps, TRUE);
1283 GST_DEBUG_OBJECT (trans, "incompatible caps, ignoring");
1284 /* we received caps that we cannot transform. Upstream is behaving badly
1285 * because it should have checked if we could handle these caps. We can
1286 * simply ignore these caps and produce a buffer with our original caps. */
1290 GST_DEBUG_OBJECT (trans, "getting size of suggestion");
1292 /* not a subset, we have a new upstream suggestion, remember it and
1293 * allocate a default buffer. First we try to convert the size */
1294 if (gst_base_transform_transform_size (trans,
1295 GST_PAD_SRC, caps, expsize, othercaps, &size_suggest)) {
1297 /* ok, remember the suggestions now */
1298 GST_DEBUG_OBJECT (trans,
1299 "storing new caps and size suggestion of %u and %" GST_PTR_FORMAT,
1300 size_suggest, othercaps);
1302 GST_OBJECT_LOCK (trans->sinkpad);
1303 if (priv->sink_suggest)
1304 gst_caps_unref (priv->sink_suggest);
1305 priv->sink_suggest = gst_caps_ref (othercaps);
1306 priv->size_suggest = size_suggest;
1307 trans->priv->suggest_pending = TRUE;
1308 GST_OBJECT_UNLOCK (trans->sinkpad);
1310 gst_caps_unref (othercaps);
1315 /* Allocate a buffer using gst_pad_alloc_buffer
1317 * This function can do renegotiation on the source pad
1319 * The output buffer is always writable. outbuf can be equal to
1320 * inbuf, the caller should be prepared for this and perform
1321 * appropriate refcounting.
1323 static GstFlowReturn
1324 gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
1325 GstBuffer * in_buf, GstBuffer ** out_buf)
1327 GstBaseTransformClass *bclass;
1328 GstBaseTransformPrivate *priv;
1329 GstFlowReturn ret = GST_FLOW_OK;
1330 gboolean discard, copymeta;
1331 gsize insize, outsize;
1332 GstCaps *incaps = NULL, *outcaps = NULL;
1334 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1340 insize = gst_buffer_get_size (in_buf);
1342 /* figure out how to allocate a buffer based on the current configuration */
1343 if (trans->passthrough) {
1344 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1345 /* passthrough, we don't really need to call pad alloc but we still need to
1346 * in order to get upstream negotiation. The output size is the same as the
1349 /* we always alloc and discard here */
1352 gboolean want_in_place = (bclass->transform_ip != NULL)
1353 && trans->always_in_place;
1355 if (want_in_place) {
1356 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1357 /* we alloc a buffer of the same size as the input */
1359 /* only discard it when the input was not writable, otherwise, we reuse
1360 * the input buffer. */
1361 discard = gst_buffer_is_writable (in_buf);
1362 GST_DEBUG_OBJECT (trans, "discard: %d", discard);
1364 incaps = gst_pad_get_current_caps (trans->sinkpad);
1365 outcaps = gst_pad_get_current_caps (trans->srcpad);
1367 GST_DEBUG_OBJECT (trans, "getting output size for copy transform");
1368 /* copy transform, figure out the output size */
1369 if (!gst_base_transform_transform_size (trans,
1370 GST_PAD_SINK, incaps, insize, outcaps, &outsize)) {
1373 /* never discard this buffer, we need it for storing the output */
1378 if (bclass->prepare_output_buffer) {
1379 if (outcaps == NULL)
1380 outcaps = gst_pad_get_current_caps (trans->srcpad);
1382 GST_DEBUG_OBJECT (trans,
1383 "calling prepare buffer with caps %p %" GST_PTR_FORMAT, outcaps,
1386 bclass->prepare_output_buffer (trans, in_buf, outsize, outcaps,
1389 /* get a new ref to the srcpad caps, the prepare_output_buffer function can
1390 * update the pad caps if it wants */
1392 gst_caps_unref (outcaps);
1393 outcaps = gst_pad_get_current_caps (trans->srcpad);
1396 * decrease refcount again if vmethod returned refcounted in_buf. This
1397 * is because we need to make sure that the buffer is writable for the
1398 * in_place transform. The docs of the vmethod say that you should return
1399 * a reffed inbuf, which is exactly what we don't want :), oh well.. */
1400 if (in_buf == *out_buf)
1401 gst_buffer_unref (in_buf);
1403 /* never discard the buffer from the prepare_buffer method */
1404 if (*out_buf != NULL)
1408 if (ret != GST_FLOW_OK)
1411 if (*out_buf == NULL) {
1412 if (trans->passthrough) {
1413 GST_DEBUG_OBJECT (trans, "Avoiding pad alloc");
1414 *out_buf = gst_buffer_ref (in_buf);
1416 GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
1418 *out_buf = gst_buffer_new_and_alloc (outsize);
1422 /* must always have a buffer by now */
1423 if (*out_buf == NULL)
1427 if (*out_buf == NULL) {
1429 GST_DEBUG_OBJECT (trans, "make default output buffer of size %d",
1431 /* no valid buffer yet, make one, metadata is writable */
1432 *out_buf = gst_buffer_new_and_alloc (outsize);
1433 gst_buffer_copy_into (*out_buf, in_buf,
1434 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1436 GST_DEBUG_OBJECT (trans, "reuse input buffer");
1440 if (trans->passthrough && in_buf != *out_buf) {
1441 /* we are asked to perform a passthrough transform but the input and
1442 * output buffers are different. We have to discard the output buffer and
1443 * reuse the input buffer. */
1444 GST_DEBUG_OBJECT (trans, "passthrough but different buffers");
1448 GST_DEBUG_OBJECT (trans, "discard buffer, reuse input buffer");
1449 gst_buffer_unref (*out_buf);
1452 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", in_buf,
1454 /* if we have different buffers, check if the metadata is ok */
1455 if (*out_buf != in_buf) {
1458 mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
1459 GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
1460 GST_BUFFER_FLAG_GAP | GST_BUFFER_FLAG_MEDIA1 |
1461 GST_BUFFER_FLAG_MEDIA2 | GST_BUFFER_FLAG_MEDIA3;
1462 /* see if the flags and timestamps match */
1464 (GST_MINI_OBJECT_FLAGS (*out_buf) & mask) ==
1465 (GST_MINI_OBJECT_FLAGS (in_buf) & mask);
1467 GST_BUFFER_TIMESTAMP (*out_buf) != GST_BUFFER_TIMESTAMP (in_buf) ||
1468 GST_BUFFER_DURATION (*out_buf) != GST_BUFFER_DURATION (in_buf) ||
1469 GST_BUFFER_OFFSET (*out_buf) != GST_BUFFER_OFFSET (in_buf) ||
1470 GST_BUFFER_OFFSET_END (*out_buf) != GST_BUFFER_OFFSET_END (in_buf);
1475 /* we need to modify the metadata when the element is not gap aware,
1476 * passthrough is not used and the gap flag is set */
1477 copymeta |= !trans->priv->gap_aware && !trans->passthrough
1478 && (GST_MINI_OBJECT_FLAGS (*out_buf) & GST_BUFFER_FLAG_GAP);
1481 GST_DEBUG_OBJECT (trans, "copymeta %d", copymeta);
1482 if (!gst_buffer_is_writable (*out_buf)) {
1483 GST_DEBUG_OBJECT (trans, "buffer %p not writable", *out_buf);
1484 if (in_buf == *out_buf)
1485 *out_buf = gst_buffer_copy (in_buf);
1487 *out_buf = gst_buffer_make_writable (*out_buf);
1489 /* when we get here, the metadata should be writable */
1491 gst_buffer_copy_into (*out_buf, in_buf,
1492 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1493 /* clear the GAP flag when the subclass does not understand it */
1494 if (!trans->priv->gap_aware)
1495 GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
1500 gst_caps_unref (incaps);
1502 gst_caps_unref (outcaps);
1509 GST_WARNING_OBJECT (trans, "pad-alloc failed: %s", gst_flow_get_name (ret));
1514 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1515 ("Sub-class failed to provide an output buffer"), (NULL));
1516 ret = GST_FLOW_ERROR;
1521 GST_ERROR_OBJECT (trans, "unknown output size");
1522 ret = GST_FLOW_ERROR;
1527 /* Given @caps calcultate the size of one unit.
1529 * For video caps, this is the size of one frame (and thus one buffer).
1530 * For audio caps, this is the size of one sample.
1532 * These values are cached since they do not change and the calculation
1533 * potentially involves parsing caps and other expensive stuff.
1535 * We have two cache locations to store the size, one for the source caps
1536 * and one for the sink caps.
1538 * this function returns FALSE if no size could be calculated.
1541 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1544 gboolean res = FALSE;
1545 GstBaseTransformClass *bclass;
1547 /* see if we have the result cached */
1548 if (trans->cache_caps1 == caps) {
1549 *size = trans->cache_caps1_size;
1550 GST_DEBUG_OBJECT (trans, "returned %d from first cache", *size);
1553 if (trans->cache_caps2 == caps) {
1554 *size = trans->cache_caps2_size;
1555 GST_DEBUG_OBJECT (trans, "returned %d from second cached", *size);
1559 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1560 if (bclass->get_unit_size) {
1561 res = bclass->get_unit_size (trans, caps, size);
1562 GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
1563 ") has unit size %d, result %s", caps, *size, res ? "TRUE" : "FALSE");
1566 /* and cache the values */
1567 if (trans->cache_caps1 == NULL) {
1568 gst_caps_replace (&trans->cache_caps1, caps);
1569 trans->cache_caps1_size = *size;
1570 GST_DEBUG_OBJECT (trans, "caching %d in first cache", *size);
1571 } else if (trans->cache_caps2 == NULL) {
1572 gst_caps_replace (&trans->cache_caps2, caps);
1573 trans->cache_caps2_size = *size;
1574 GST_DEBUG_OBJECT (trans, "caching %d in second cache", *size);
1576 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1580 GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
1586 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1588 GstBaseTransform *trans;
1589 GstBaseTransformClass *bclass;
1590 gboolean ret = TRUE;
1591 gboolean forward = TRUE;
1593 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1594 if (G_UNLIKELY (trans == NULL)) {
1595 gst_event_unref (event);
1598 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1601 forward = bclass->event (trans, event);
1603 /* FIXME, do this in the default event handler so the subclass can do
1604 * something different. */
1606 ret = gst_pad_push_event (trans->srcpad, event);
1608 gst_event_unref (event);
1610 gst_object_unref (trans);
1616 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1618 gboolean forward = TRUE;
1620 switch (GST_EVENT_TYPE (event)) {
1621 case GST_EVENT_FLUSH_START:
1623 case GST_EVENT_FLUSH_STOP:
1624 GST_OBJECT_LOCK (trans);
1625 /* reset QoS parameters */
1626 trans->priv->proportion = 1.0;
1627 trans->priv->earliest_time = -1;
1628 trans->priv->discont = FALSE;
1629 trans->priv->processed = 0;
1630 trans->priv->dropped = 0;
1631 GST_OBJECT_UNLOCK (trans);
1632 /* we need new segment info after the flush. */
1633 trans->have_newsegment = FALSE;
1634 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1635 trans->priv->last_stop_out = GST_CLOCK_TIME_NONE;
1641 case GST_EVENT_CAPS:
1645 gst_event_parse_caps (event, &caps);
1646 gst_base_transform_setcaps (trans, trans->sinkpad, caps, FALSE);
1651 case GST_EVENT_NEWSEGMENT:
1654 gdouble rate, arate;
1655 gint64 start, stop, time;
1658 gst_event_parse_new_segment (event, &update, &rate, &arate, &format,
1659 &start, &stop, &time);
1661 trans->have_newsegment = TRUE;
1663 gst_segment_set_newsegment (&trans->segment, update, rate, arate,
1664 format, start, stop, time);
1666 if (format == GST_FORMAT_TIME) {
1667 GST_DEBUG_OBJECT (trans, "received TIME NEW_SEGMENT %" GST_TIME_FORMAT
1668 " -- %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT
1669 ", accum %" GST_TIME_FORMAT,
1670 GST_TIME_ARGS (trans->segment.start),
1671 GST_TIME_ARGS (trans->segment.stop),
1672 GST_TIME_ARGS (trans->segment.time),
1673 GST_TIME_ARGS (trans->segment.accum));
1675 GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" G_GINT64_FORMAT
1676 " -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT
1677 ", accum %" G_GINT64_FORMAT,
1678 trans->segment.start, trans->segment.stop,
1679 trans->segment.time, trans->segment.accum);
1691 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1693 GstBaseTransform *trans;
1694 GstBaseTransformClass *bclass;
1695 gboolean ret = TRUE;
1697 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1698 if (G_UNLIKELY (trans == NULL)) {
1699 gst_event_unref (event);
1703 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1705 if (bclass->src_event)
1706 ret = bclass->src_event (trans, event);
1708 gst_event_unref (event);
1710 gst_object_unref (trans);
1716 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1720 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1722 switch (GST_EVENT_TYPE (event)) {
1723 case GST_EVENT_SEEK:
1725 case GST_EVENT_NAVIGATION:
1730 GstClockTimeDiff diff;
1731 GstClockTime timestamp;
1733 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1734 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1741 ret = gst_pad_push_event (trans->sinkpad, event);
1746 /* perform a transform on @inbuf and put the result in @outbuf.
1748 * This function is common to the push and pull-based operations.
1750 * This function takes ownership of @inbuf */
1751 static GstFlowReturn
1752 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1753 GstBuffer ** outbuf)
1755 GstBaseTransformClass *bclass;
1756 GstFlowReturn ret = GST_FLOW_OK;
1757 gboolean want_in_place;
1758 GstClockTime running_time;
1759 GstClockTime timestamp;
1765 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1768 if (G_LIKELY ((incaps = GST_BUFFER_CAPS (inbuf)))) {
1769 gboolean reconfigure;
1771 GST_OBJECT_LOCK (trans->sinkpad);
1772 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->sinkpad)
1773 || trans->priv->reconfigure;
1774 GST_OBJECT_FLAG_UNSET (trans->sinkpad, GST_PAD_NEED_RECONFIGURE);
1775 trans->priv->reconfigure = FALSE;
1776 GST_OBJECT_UNLOCK (trans->sinkpad);
1778 if (G_UNLIKELY (reconfigure)) {
1779 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1781 GST_OBJECT_LOCK (trans);
1782 gst_caps_replace (&trans->priv->sink_alloc, NULL);
1783 GST_OBJECT_UNLOCK (trans);
1785 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1786 * will reconfigure the transform with the new output format. We can only
1787 * do this if the buffer actually has caps. */
1788 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps, TRUE))
1789 goto not_negotiated;
1794 insize = gst_buffer_get_size (inbuf);
1796 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1797 GST_DEBUG_OBJECT (trans,
1798 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1799 G_GUINT64_FORMAT, inbuf, insize, GST_BUFFER_OFFSET (inbuf));
1801 GST_DEBUG_OBJECT (trans,
1802 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1805 /* Don't allow buffer handling before negotiation, except in passthrough mode
1806 * or if the class doesn't implement a set_caps function (in which case it doesn't
1809 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1810 goto not_negotiated;
1812 /* Set discont flag so we can mark the outgoing buffer */
1813 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1814 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1815 trans->priv->discont = TRUE;
1818 /* can only do QoS if the segment is in TIME */
1819 if (trans->segment.format != GST_FORMAT_TIME)
1822 /* QOS is done on the running time of the buffer, get it now */
1823 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1824 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1827 if (running_time != -1) {
1829 GstClockTime earliest_time;
1832 /* lock for getting the QoS parameters that are set (in a different thread)
1833 * with the QOS events */
1834 GST_OBJECT_LOCK (trans);
1835 earliest_time = trans->priv->earliest_time;
1836 proportion = trans->priv->proportion;
1837 /* check for QoS, don't perform conversion for buffers
1838 * that are known to be late. */
1839 need_skip = trans->priv->qos_enabled &&
1840 earliest_time != -1 && running_time <= earliest_time;
1841 GST_OBJECT_UNLOCK (trans);
1844 GstMessage *qos_msg;
1845 GstClockTime duration;
1846 guint64 stream_time;
1849 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1850 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1851 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1853 trans->priv->dropped++;
1855 duration = GST_BUFFER_DURATION (inbuf);
1857 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1859 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1862 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1863 stream_time, timestamp, duration);
1864 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1865 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1866 trans->priv->processed, trans->priv->dropped);
1867 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1869 /* mark discont for next buffer */
1870 trans->priv->discont = TRUE;
1877 /* first try to allocate an output buffer based on the currently negotiated
1878 * format. While we call pad-alloc we could renegotiate the srcpad format or
1879 * have a new suggestion for upstream buffer-alloc.
1880 * In any case, outbuf will contain a buffer suitable for doing the configured
1881 * transform after this function. */
1882 ret = gst_base_transform_prepare_output_buffer (trans, inbuf, outbuf);
1883 if (G_UNLIKELY (ret != GST_FLOW_OK))
1886 /* now perform the needed transform */
1887 if (trans->passthrough) {
1888 /* In passthrough mode, give transform_ip a look at the
1889 * buffer, without making it writable, or just push the
1891 if (bclass->transform_ip) {
1892 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1893 ret = bclass->transform_ip (trans, *outbuf);
1895 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1898 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1900 if (want_in_place) {
1901 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1903 if (inbuf != *outbuf) {
1904 guint8 *indata, *outdata;
1905 gsize insize, outsize;
1907 /* Different buffer. The data can still be the same when we are dealing
1908 * with subbuffers of the same buffer. Note that because of the FIXME in
1909 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1910 * outbuf to keep them writable */
1911 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1912 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1914 if (indata != outdata)
1915 memcpy (outdata, indata, insize);
1917 gst_buffer_unmap (inbuf, indata, insize);
1918 gst_buffer_unmap (*outbuf, outdata, outsize);
1920 ret = bclass->transform_ip (trans, *outbuf);
1922 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1924 if (bclass->transform)
1925 ret = bclass->transform (trans, inbuf, *outbuf);
1927 ret = GST_FLOW_NOT_SUPPORTED;
1932 /* only unref input buffer if we allocated a new outbuf buffer */
1933 if (*outbuf != inbuf)
1934 gst_buffer_unref (inbuf);
1941 gst_buffer_unref (inbuf);
1942 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1943 ("not negotiated"), ("not negotiated"));
1944 return GST_FLOW_NOT_NEGOTIATED;
1948 gst_buffer_unref (inbuf);
1949 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1950 gst_flow_get_name (ret));
1956 gst_base_transform_check_get_range (GstPad * pad)
1958 GstBaseTransform *trans;
1961 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1963 ret = gst_pad_check_pull_range (trans->sinkpad);
1965 gst_object_unref (trans);
1970 /* FIXME, getrange is broken, need to pull range from the other
1971 * end based on the transform_size result.
1973 static GstFlowReturn
1974 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1975 guint length, GstBuffer ** buffer)
1977 GstBaseTransform *trans;
1978 GstBaseTransformClass *klass;
1982 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1984 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1985 if (G_UNLIKELY (ret != GST_FLOW_OK))
1988 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1989 if (klass->before_transform)
1990 klass->before_transform (trans, inbuf);
1992 GST_BASE_TRANSFORM_LOCK (trans);
1993 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1994 GST_BASE_TRANSFORM_UNLOCK (trans);
1997 gst_object_unref (trans);
2004 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
2005 gst_flow_get_name (ret));
2010 static GstFlowReturn
2011 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
2013 GstBaseTransform *trans;
2014 GstBaseTransformClass *klass;
2016 GstClockTime last_stop = GST_CLOCK_TIME_NONE;
2017 GstClockTime timestamp, duration;
2018 GstBuffer *outbuf = NULL;
2020 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
2022 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2023 duration = GST_BUFFER_DURATION (buffer);
2025 /* calculate end position of the incoming buffer */
2026 if (timestamp != GST_CLOCK_TIME_NONE) {
2027 if (duration != GST_CLOCK_TIME_NONE)
2028 last_stop = timestamp + duration;
2030 last_stop = timestamp;
2033 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2034 if (klass->before_transform)
2035 klass->before_transform (trans, buffer);
2037 /* protect transform method and concurrent buffer alloc */
2038 GST_BASE_TRANSFORM_LOCK (trans);
2039 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2040 GST_BASE_TRANSFORM_UNLOCK (trans);
2042 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2043 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2044 if (outbuf != NULL) {
2045 if ((ret == GST_FLOW_OK)) {
2046 GstClockTime last_stop_out = GST_CLOCK_TIME_NONE;
2048 /* Remember last stop position */
2049 if (last_stop != GST_CLOCK_TIME_NONE &&
2050 trans->segment.format == GST_FORMAT_TIME)
2051 gst_segment_set_last_stop (&trans->segment, GST_FORMAT_TIME, last_stop);
2053 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2054 last_stop_out = GST_BUFFER_TIMESTAMP (outbuf);
2055 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2056 last_stop_out += GST_BUFFER_DURATION (outbuf);
2057 } else if (last_stop != GST_CLOCK_TIME_NONE) {
2058 last_stop_out = last_stop;
2060 if (last_stop_out != GST_CLOCK_TIME_NONE
2061 && trans->segment.format == GST_FORMAT_TIME)
2062 trans->priv->last_stop_out = last_stop_out;
2064 /* apply DISCONT flag if the buffer is not yet marked as such */
2065 if (trans->priv->discont) {
2066 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2067 outbuf = gst_buffer_make_writable (outbuf);
2068 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2070 trans->priv->discont = FALSE;
2072 trans->priv->processed++;
2073 ret = gst_pad_push (trans->srcpad, outbuf);
2075 gst_buffer_unref (outbuf);
2079 /* convert internal flow to OK and mark discont for the next buffer. */
2080 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2081 trans->priv->discont = TRUE;
2089 gst_base_transform_set_property (GObject * object, guint prop_id,
2090 const GValue * value, GParamSpec * pspec)
2092 GstBaseTransform *trans;
2094 trans = GST_BASE_TRANSFORM (object);
2098 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2107 gst_base_transform_get_property (GObject * object, guint prop_id,
2108 GValue * value, GParamSpec * pspec)
2110 GstBaseTransform *trans;
2112 trans = GST_BASE_TRANSFORM (object);
2116 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2124 /* not a vmethod of anything, just an internal method */
2126 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2128 GstBaseTransformClass *bclass;
2129 gboolean result = TRUE;
2131 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2134 GstCaps *incaps, *outcaps;
2136 if (trans->priv->pad_mode == GST_ACTIVATE_NONE && bclass->start)
2137 result &= bclass->start (trans);
2139 incaps = gst_pad_get_current_caps (trans->sinkpad);
2140 outcaps = gst_pad_get_current_caps (trans->srcpad);
2142 GST_OBJECT_LOCK (trans);
2143 if (incaps && outcaps)
2144 trans->have_same_caps =
2145 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2147 trans->have_same_caps = trans->passthrough;
2148 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2149 trans->negotiated = FALSE;
2150 trans->have_newsegment = FALSE;
2151 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2152 trans->priv->last_stop_out = GST_CLOCK_TIME_NONE;
2153 trans->priv->proportion = 1.0;
2154 trans->priv->earliest_time = -1;
2155 trans->priv->discont = FALSE;
2156 gst_caps_replace (&trans->priv->sink_suggest, NULL);
2157 trans->priv->processed = 0;
2158 trans->priv->dropped = 0;
2159 GST_OBJECT_UNLOCK (trans);
2162 gst_caps_unref (incaps);
2164 gst_caps_unref (outcaps);
2166 /* We must make sure streaming has finished before resetting things
2167 * and calling the ::stop vfunc */
2168 GST_PAD_STREAM_LOCK (trans->sinkpad);
2169 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2171 trans->have_same_caps = FALSE;
2172 /* We can only reset the passthrough mode if the instance told us to
2173 handle it in configure_caps */
2174 if (bclass->passthrough_on_same_caps) {
2175 gst_base_transform_set_passthrough (trans, FALSE);
2177 gst_caps_replace (&trans->cache_caps1, NULL);
2178 gst_caps_replace (&trans->cache_caps2, NULL);
2179 gst_caps_replace (&trans->priv->sink_alloc, NULL);
2180 gst_caps_replace (&trans->priv->sink_suggest, NULL);
2182 if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
2183 result &= bclass->stop (trans);
2190 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2192 gboolean result = TRUE;
2193 GstBaseTransform *trans;
2195 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2197 result = gst_base_transform_activate (trans, active);
2200 trans->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
2202 gst_object_unref (trans);
2208 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2210 gboolean result = FALSE;
2211 GstBaseTransform *trans;
2213 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2215 result = gst_pad_activate_pull (trans->sinkpad, active);
2218 result &= gst_base_transform_activate (trans, active);
2221 trans->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
2223 gst_object_unref (trans);
2229 * gst_base_transform_set_passthrough:
2230 * @trans: the #GstBaseTransform to set
2231 * @passthrough: boolean indicating passthrough mode.
2233 * Set passthrough mode for this filter by default. This is mostly
2234 * useful for filters that do not care about negotiation.
2236 * Always TRUE for filters which don't implement either a transform
2237 * or transform_ip method.
2242 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2243 gboolean passthrough)
2245 GstBaseTransformClass *bclass;
2247 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2249 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2251 GST_OBJECT_LOCK (trans);
2252 if (passthrough == FALSE) {
2253 if (bclass->transform_ip || bclass->transform)
2254 trans->passthrough = FALSE;
2256 trans->passthrough = TRUE;
2259 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2260 GST_OBJECT_UNLOCK (trans);
2264 * gst_base_transform_is_passthrough:
2265 * @trans: the #GstBaseTransform to query
2267 * See if @trans is configured as a passthrough transform.
2269 * Returns: TRUE is the transform is configured in passthrough mode.
2274 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2278 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2280 GST_OBJECT_LOCK (trans);
2281 result = trans->passthrough;
2282 GST_OBJECT_UNLOCK (trans);
2288 * gst_base_transform_set_in_place:
2289 * @trans: the #GstBaseTransform to modify
2290 * @in_place: Boolean value indicating that we would like to operate
2291 * on in_place buffers.
2293 * Determines whether a non-writable buffer will be copied before passing
2294 * to the transform_ip function.
2296 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2297 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2303 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2305 GstBaseTransformClass *bclass;
2307 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2309 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2311 GST_OBJECT_LOCK (trans);
2314 if (bclass->transform_ip) {
2315 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2316 trans->always_in_place = TRUE;
2319 if (bclass->transform) {
2320 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2321 trans->always_in_place = FALSE;
2325 GST_OBJECT_UNLOCK (trans);
2329 * gst_base_transform_is_in_place:
2330 * @trans: the #GstBaseTransform to query
2332 * See if @trans is configured as a in_place transform.
2334 * Returns: TRUE is the transform is configured in in_place mode.
2339 gst_base_transform_is_in_place (GstBaseTransform * trans)
2343 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2345 GST_OBJECT_LOCK (trans);
2346 result = trans->always_in_place;
2347 GST_OBJECT_UNLOCK (trans);
2353 * gst_base_transform_update_qos:
2354 * @trans: a #GstBaseTransform
2355 * @proportion: the proportion
2356 * @diff: the diff against the clock
2357 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2360 * Set the QoS parameters in the transform. This function is called internally
2361 * when a QOS event is received but subclasses can provide custom information
2369 gst_base_transform_update_qos (GstBaseTransform * trans,
2370 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2373 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2375 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2376 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2377 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2379 GST_OBJECT_LOCK (trans);
2380 trans->priv->proportion = proportion;
2381 trans->priv->earliest_time = timestamp + diff;
2382 GST_OBJECT_UNLOCK (trans);
2386 * gst_base_transform_set_qos_enabled:
2387 * @trans: a #GstBaseTransform
2388 * @enabled: new state
2390 * Enable or disable QoS handling in the transform.
2397 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2399 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2401 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2403 GST_OBJECT_LOCK (trans);
2404 trans->priv->qos_enabled = enabled;
2405 GST_OBJECT_UNLOCK (trans);
2409 * gst_base_transform_is_qos_enabled:
2410 * @trans: a #GstBaseTransform
2412 * Queries if the transform will handle QoS.
2414 * Returns: TRUE if QoS is enabled.
2421 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2425 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2427 GST_OBJECT_LOCK (trans);
2428 result = trans->priv->qos_enabled;
2429 GST_OBJECT_UNLOCK (trans);
2435 * gst_base_transform_set_gap_aware:
2436 * @trans: a #GstBaseTransform
2437 * @gap_aware: New state
2439 * If @gap_aware is %FALSE (the default), output buffers will have the
2440 * %GST_BUFFER_FLAG_GAP flag unset.
2442 * If set to %TRUE, the element must handle output buffers with this flag set
2443 * correctly, i.e. it can assume that the buffer contains neutral data but must
2444 * unset the flag if the output is no neutral data.
2451 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2453 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2455 GST_OBJECT_LOCK (trans);
2456 trans->priv->gap_aware = gap_aware;
2457 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2458 GST_OBJECT_UNLOCK (trans);
2462 * gst_base_transform_suggest:
2463 * @trans: a #GstBaseTransform
2464 * @caps: (transfer none): caps to suggest
2465 * @size: buffer size to suggest
2467 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2473 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2476 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2478 GST_OBJECT_LOCK (trans->sinkpad);
2479 if (trans->priv->sink_suggest)
2480 gst_caps_unref (trans->priv->sink_suggest);
2482 caps = gst_caps_copy (caps);
2483 trans->priv->sink_suggest = caps;
2484 trans->priv->size_suggest = size;
2485 trans->priv->suggest_pending = TRUE;
2486 GST_DEBUG_OBJECT (trans, "new suggest %" GST_PTR_FORMAT, caps);
2487 GST_OBJECT_UNLOCK (trans->sinkpad);
2489 /* push the renegotiate event */
2490 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2491 gst_event_new_reconfigure ()))
2492 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2496 * gst_base_transform_reconfigure:
2497 * @trans: a #GstBaseTransform
2499 * Instructs @trans to renegotiate a new downstream transform on the next
2500 * buffer. This function is typically called after properties on the transform
2501 * were set that influence the output format.
2506 gst_base_transform_reconfigure (GstBaseTransform * trans)
2508 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2510 GST_OBJECT_LOCK (trans);
2511 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2512 trans->priv->reconfigure = TRUE;
2513 gst_caps_replace (&trans->priv->sink_alloc, NULL);
2514 GST_OBJECT_UNLOCK (trans);