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 "../../../gst/glib-compat-private.h"
211 #include "gstbasetransform.h"
212 #include <gst/gstmarshal.h>
214 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
215 #define GST_CAT_DEFAULT gst_base_transform_debug
217 /* BaseTransform signals and args */
224 #define DEFAULT_PROP_QOS FALSE
232 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
233 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
235 struct _GstBaseTransformPrivate
237 /* QoS *//* with LOCK */
238 gboolean qos_enabled;
240 GstClockTime earliest_time;
241 /* previous buffer had a discont */
248 gboolean reconfigure;
254 GstClockTime position_out;
257 GstAllocator *allocator;
263 static GstElementClass *parent_class = NULL;
265 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
266 static void gst_base_transform_init (GstBaseTransform * trans,
267 GstBaseTransformClass * klass);
269 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
270 * method to get to the padtemplates */
272 gst_base_transform_get_type (void)
274 static volatile gsize base_transform_type = 0;
276 if (g_once_init_enter (&base_transform_type)) {
278 static const GTypeInfo base_transform_info = {
279 sizeof (GstBaseTransformClass),
282 (GClassInitFunc) gst_base_transform_class_init,
285 sizeof (GstBaseTransform),
287 (GInstanceInitFunc) gst_base_transform_init,
290 _type = g_type_register_static (GST_TYPE_ELEMENT,
291 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
292 g_once_init_leave (&base_transform_type, _type);
294 return base_transform_type;
297 static void gst_base_transform_finalize (GObject * object);
298 static void gst_base_transform_set_property (GObject * object, guint prop_id,
299 const GValue * value, GParamSpec * pspec);
300 static void gst_base_transform_get_property (GObject * object, guint prop_id,
301 GValue * value, GParamSpec * pspec);
302 static gboolean gst_base_transform_src_activate_mode (GstPad * pad,
303 GstObject * parent, GstPadMode mode, gboolean active);
304 static gboolean gst_base_transform_sink_activate_mode (GstPad * pad,
305 GstObject * parent, GstPadMode mode, gboolean active);
306 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
308 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
309 GstCaps * caps, gsize * size);
311 static gboolean gst_base_transform_src_event (GstPad * pad, GstObject * parent,
313 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
315 static gboolean gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
317 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
319 static GstFlowReturn gst_base_transform_getrange (GstPad * pad,
320 GstObject * parent, guint64 offset, guint length, GstBuffer ** buffer);
321 static GstFlowReturn gst_base_transform_chain (GstPad * pad, GstObject * parent,
323 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
324 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
325 static GstCaps *gst_base_transform_default_fixate_caps (GstBaseTransform *
326 trans, GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
327 static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
328 GstPad * pad, GstCaps * filter);
329 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
330 GstPadDirection direction, GstCaps * caps);
331 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
332 GstPad * pad, GstCaps * caps);
333 static gboolean gst_base_transform_default_propose_allocation (GstBaseTransform
334 * trans, gboolean passthrough, GstQuery * query);
335 static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
337 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
338 GstPadDirection direction, GstQuery * query);
339 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
340 trans, GstPadDirection direction, GstCaps * caps, gsize size,
341 GstCaps * othercaps, gsize * othersize);
343 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
344 GstBuffer * inbuf, GstBuffer ** outbuf);
345 static gboolean default_copy_metadata (GstBaseTransform * trans,
346 GstBuffer * inbuf, GstBuffer * outbuf);
348 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
352 gst_base_transform_finalize (GObject * object)
354 GstBaseTransform *trans;
356 trans = GST_BASE_TRANSFORM (object);
358 g_mutex_clear (&trans->transform_lock);
360 G_OBJECT_CLASS (parent_class)->finalize (object);
364 gst_base_transform_class_init (GstBaseTransformClass * klass)
366 GObjectClass *gobject_class;
368 gobject_class = G_OBJECT_CLASS (klass);
370 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
371 "basetransform element");
373 GST_DEBUG ("gst_base_transform_class_init");
375 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
377 parent_class = g_type_class_peek_parent (klass);
379 gobject_class->set_property = gst_base_transform_set_property;
380 gobject_class->get_property = gst_base_transform_get_property;
382 g_object_class_install_property (gobject_class, PROP_QOS,
383 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
384 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
386 gobject_class->finalize = gst_base_transform_finalize;
388 klass->passthrough_on_same_caps = FALSE;
390 klass->transform_caps =
391 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
393 GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate_caps);
395 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
396 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
397 klass->propose_allocation =
398 GST_DEBUG_FUNCPTR (gst_base_transform_default_propose_allocation);
399 klass->transform_size =
400 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
402 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
403 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
404 klass->prepare_output_buffer =
405 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
406 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
410 gst_base_transform_init (GstBaseTransform * trans,
411 GstBaseTransformClass * bclass)
413 GstPadTemplate *pad_template;
415 GST_DEBUG ("gst_base_transform_init");
417 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
420 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
421 g_return_if_fail (pad_template != NULL);
422 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
423 gst_pad_set_event_function (trans->sinkpad,
424 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
425 gst_pad_set_chain_function (trans->sinkpad,
426 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
427 gst_pad_set_activatemode_function (trans->sinkpad,
428 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
429 gst_pad_set_query_function (trans->sinkpad,
430 GST_DEBUG_FUNCPTR (gst_base_transform_query));
431 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
434 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
435 g_return_if_fail (pad_template != NULL);
436 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
437 gst_pad_set_event_function (trans->srcpad,
438 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
439 gst_pad_set_getrange_function (trans->srcpad,
440 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
441 gst_pad_set_activatemode_function (trans->srcpad,
442 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
443 gst_pad_set_query_function (trans->srcpad,
444 GST_DEBUG_FUNCPTR (gst_base_transform_query));
445 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
447 g_mutex_init (&trans->transform_lock);
448 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
449 trans->cache_caps1 = NULL;
450 trans->cache_caps2 = NULL;
451 trans->priv->pad_mode = GST_PAD_MODE_NONE;
452 trans->priv->gap_aware = FALSE;
454 trans->passthrough = FALSE;
455 if (bclass->transform == NULL) {
456 /* If no transform function, always_in_place is TRUE */
457 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
458 trans->always_in_place = TRUE;
460 if (bclass->transform_ip == NULL) {
461 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
462 trans->passthrough = TRUE;
466 trans->priv->processed = 0;
467 trans->priv->dropped = 0;
471 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
472 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
476 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
477 /* no transform function, use the identity transform */
479 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
481 ret = gst_caps_ref (caps);
486 /* given @caps on the src or sink pad (given by @direction)
487 * calculate the possible caps on the other pad.
489 * Returns new caps, unref after usage.
492 gst_base_transform_transform_caps (GstBaseTransform * trans,
493 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
496 GstBaseTransformClass *klass;
501 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
503 /* if there is a custom transform function, use this */
504 if (klass->transform_caps) {
505 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
507 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
508 ret = klass->transform_caps (trans, direction, caps, filter);
509 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
511 #ifndef G_DISABLE_ASSERT
513 if (!gst_caps_is_subset (ret, filter)) {
514 GstCaps *intersection;
516 GST_ERROR_OBJECT (trans,
517 "transform_caps returned caps %" GST_PTR_FORMAT
518 " which are not a real subset of the filter caps %"
519 GST_PTR_FORMAT, ret, filter);
520 g_warning ("%s: transform_caps returned caps which are not a real "
521 "subset of the filter caps", GST_ELEMENT_NAME (trans));
524 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
525 gst_caps_unref (ret);
532 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
538 gst_base_transform_default_transform_size (GstBaseTransform * trans,
539 GstPadDirection direction, GstCaps * caps, gsize size,
540 GstCaps * othercaps, gsize * othersize)
542 gsize inunitsize, outunitsize, units;
543 GstBaseTransformClass *klass;
545 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
547 if (klass->get_unit_size == NULL) {
548 /* if there is no transform_size and no unit_size, it means the
549 * element does not modify the size of a buffer */
552 /* there is no transform_size function, we have to use the unit_size
553 * functions. This method assumes there is a fixed unit_size associated with
554 * each caps. We provide the same amount of units on both sides. */
555 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
558 GST_DEBUG_OBJECT (trans,
559 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
562 /* input size must be a multiple of the unit_size of the input caps */
563 if (inunitsize == 0 || (size % inunitsize != 0))
566 /* get the amount of units */
567 units = size / inunitsize;
569 /* now get the unit size of the output */
570 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
573 /* the output size is the unit_size times the amount of units on the
575 *othersize = units * outunitsize;
576 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
584 GST_DEBUG_OBJECT (trans, "could not get in_size");
585 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
590 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
591 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
592 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
593 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
598 GST_DEBUG_OBJECT (trans, "could not get out_size");
599 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
604 /* transform a buffer of @size with @caps on the pad with @direction to
605 * the size of a buffer with @othercaps and store the result in @othersize
607 * We have two ways of doing this:
608 * 1) use a custom transform size function, this is for complicated custom
609 * cases with no fixed unit_size.
610 * 2) use the unit_size functions where there is a relationship between the
611 * caps and the size of a buffer.
614 gst_base_transform_transform_size (GstBaseTransform * trans,
615 GstPadDirection direction, GstCaps * caps,
616 gsize size, GstCaps * othercaps, gsize * othersize)
618 GstBaseTransformClass *klass;
619 gboolean ret = FALSE;
621 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
623 GST_DEBUG_OBJECT (trans,
624 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
625 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
626 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
628 if (klass->transform_size) {
629 /* if there is a custom transform function, use this */
630 ret = klass->transform_size (trans, direction, caps, size, othercaps,
636 /* get the caps that can be handled by @pad. We perform:
638 * - take the caps of peer of otherpad,
639 * - filter against the padtemplate of otherpad,
640 * - calculate all transforms of remaining caps
641 * - filter against template of @pad
643 * If there is no peer, we simply return the caps of the padtemplate of pad.
646 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
650 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
653 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
655 /* we can do what the peer can */
658 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
660 /* filtered against our padtemplate on the other side */
661 templ = gst_pad_get_pad_template_caps (pad);
662 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
663 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
664 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
665 gst_caps_unref (templ);
667 /* then see what we can transform this to */
668 peerfilter = gst_base_transform_transform_caps (trans,
669 GST_PAD_DIRECTION (pad), temp, NULL);
670 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
671 gst_caps_unref (temp);
673 /* and filter against the template of this pad */
674 templ = gst_pad_get_pad_template_caps (otherpad);
675 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
676 /* We keep the caps sorted like the returned caps */
678 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
679 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
680 gst_caps_unref (peerfilter);
681 gst_caps_unref (templ);
685 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
688 gst_caps_unref (peerfilter);
691 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
693 /* filtered against our padtemplate on the other side */
694 templ = gst_pad_get_pad_template_caps (otherpad);
695 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
696 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
697 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
698 gst_caps_unref (templ);
700 temp = gst_pad_get_pad_template_caps (otherpad);
703 /* then see what we can transform this to */
704 caps = gst_base_transform_transform_caps (trans,
705 GST_PAD_DIRECTION (otherpad), temp, filter);
706 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
707 gst_caps_unref (temp);
712 /* and filter against the template of this pad */
713 templ = gst_pad_get_pad_template_caps (pad);
714 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
715 /* We keep the caps sorted like the returned caps */
716 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
717 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
718 gst_caps_unref (caps);
719 gst_caps_unref (templ);
722 /* Now try if we can put the untransformed downstream caps first */
723 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
724 if (!gst_caps_is_empty (temp)) {
725 gst_caps_merge (temp, caps);
728 gst_caps_unref (temp);
731 gst_caps_unref (caps);
732 /* no peer or the peer can do anything, our padtemplate is enough then */
733 caps = gst_pad_get_pad_template_caps (pad);
738 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
739 gst_caps_unref (caps);
745 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
748 gst_caps_unref (peercaps);
753 /* takes ownership of the pool and allocator */
755 gst_base_transform_set_allocation (GstBaseTransform * trans,
756 GstBufferPool * pool, GstAllocator * allocator, guint prefix,
759 GstAllocator *oldalloc;
760 GstBufferPool *oldpool;
761 GstBaseTransformPrivate *priv = trans->priv;
765 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
766 if (!gst_buffer_pool_set_active (pool, TRUE))
767 goto activate_failed;
770 GST_OBJECT_LOCK (trans);
771 oldpool = priv->pool;
773 oldalloc = priv->allocator;
774 priv->allocator = allocator;
775 priv->prefix = prefix;
776 priv->alignment = alignment;
777 GST_OBJECT_UNLOCK (trans);
780 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
781 gst_buffer_pool_set_active (oldpool, FALSE);
782 gst_object_unref (oldpool);
785 gst_allocator_unref (oldalloc);
792 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
798 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
801 gboolean result = TRUE;
802 GstBufferPool *pool = NULL, *oldpool;
803 guint size, min, max, prefix, alignment;
804 GstBaseTransformClass *klass;
805 GstAllocator *allocator = NULL;
807 /* there are these possibilities:
809 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
810 * will do that whenever some upstream does an allocation query.
811 * 2) we need to do a transform, we need to get a bufferpool from downstream
812 * and configure it. When upstream does the ALLOCATION query, the
813 * propose_allocation vmethod will be called and we will configure the
814 * upstream allocator with our proposed values then.
818 oldpool = trans->priv->pool;
820 GST_DEBUG_OBJECT (trans, "unreffing old pool");
821 gst_buffer_pool_set_active (oldpool, FALSE);
822 gst_object_unref (oldpool);
823 trans->priv->pool = oldpool = NULL;
826 if (trans->passthrough || trans->always_in_place) {
827 /* we are in passthrough, the input buffer is never copied and always passed
828 * along. We never allocate an output buffer on the srcpad. What we do is
829 * let the upstream element decide if it wants to use a bufferpool and
830 * then we will proxy the downstream pool */
831 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
835 /* not passthrough, we need to allocate */
836 /* find a pool for the negotiated caps now */
837 GST_DEBUG_OBJECT (trans, "doing allocation query");
838 query = gst_query_new_allocation (outcaps, TRUE);
839 if (!gst_pad_peer_query (trans->srcpad, query)) {
840 /* not a problem, just debug a little */
841 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
844 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
846 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
847 if (G_LIKELY (klass->decide_allocation))
848 if ((result = klass->decide_allocation (trans, query)) == FALSE)
849 goto no_decide_allocation;
851 /* we got configuration from our peer, parse them */
852 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
856 /* no size, we have variable size buffers */
857 if (gst_query_get_n_allocation_memories (query) > 0) {
858 if ((allocator = gst_query_parse_nth_allocation_memory (query, 0)))
859 gst_allocator_ref (allocator);
861 GST_DEBUG_OBJECT (trans, "no size, using allocator %p", allocator);
862 } else if (pool == NULL) {
863 GstStructure *config;
865 /* we did not get a pool, make one ourselves then */
866 pool = gst_buffer_pool_new ();
868 GST_DEBUG_OBJECT (trans, "no pool, making one");
869 config = gst_buffer_pool_get_config (pool);
870 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
872 gst_buffer_pool_set_config (pool, config);
875 gst_query_unref (query);
879 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
885 no_decide_allocation:
887 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
888 gst_query_unref (query);
894 /* function triggered when the in and out caps are negotiated and need
895 * to be configured in the subclass. */
897 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
901 GstBaseTransformClass *klass;
903 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
905 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
906 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
908 /* clear the cache */
909 gst_caps_replace (&trans->cache_caps1, NULL);
910 gst_caps_replace (&trans->cache_caps2, NULL);
912 /* figure out same caps state */
913 trans->have_same_caps = gst_caps_is_equal (in, out);
914 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
916 /* If we've a transform_ip method and same input/output caps, set in_place
917 * by default. If for some reason the sub-class prefers using a transform
918 * function, it can clear the in place flag in the set_caps */
919 gst_base_transform_set_in_place (trans,
920 klass->transform_ip && trans->have_same_caps);
922 /* Set the passthrough if the class wants passthrough_on_same_caps
923 * and we have the same caps on each pad */
924 if (klass->passthrough_on_same_caps)
925 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
927 /* now configure the element with the caps */
928 if (klass->set_caps) {
929 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
930 ret = klass->set_caps (trans, in, out);
933 trans->negotiated = ret;
939 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
940 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
942 othercaps = gst_caps_make_writable (othercaps);
943 gst_caps_fixate (othercaps);
944 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
949 /* given a fixed @caps on @pad, create the best possible caps for the
951 * @caps must be fixed when calling this function.
953 * This function calls the transform caps vmethod of the basetransform to figure
954 * out the possible target formats. It then tries to select the best format from
957 * - attempt passthrough if the target caps is a superset of the input caps
958 * - fixating by using peer caps
959 * - fixating with transform fixate function
960 * - fixating with pad fixate functions.
962 * this function returns a caps that can be transformed into and is accepted by
966 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
969 GstBaseTransformClass *klass;
970 GstPad *otherpad, *otherpeer;
974 /* caps must be fixed here, this is a programming error if it's not */
975 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
977 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
979 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
980 otherpeer = gst_pad_get_peer (otherpad);
982 /* see how we can transform the input caps. We need to do this even for
983 * passthrough because it might be possible that this element cannot support
984 * passthrough at all. */
985 othercaps = gst_base_transform_transform_caps (trans,
986 GST_PAD_DIRECTION (pad), caps, NULL);
988 /* The caps we can actually output is the intersection of the transformed
989 * caps with the pad template for the pad */
991 GstCaps *intersect, *templ_caps;
993 templ_caps = gst_pad_get_pad_template_caps (otherpad);
994 GST_DEBUG_OBJECT (trans,
995 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
998 gst_caps_intersect_full (othercaps, templ_caps,
999 GST_CAPS_INTERSECT_FIRST);
1001 gst_caps_unref (othercaps);
1002 gst_caps_unref (templ_caps);
1003 othercaps = intersect;
1006 /* check if transform is empty */
1007 if (!othercaps || gst_caps_is_empty (othercaps))
1010 /* if the othercaps are not fixed, we need to fixate them, first attempt
1011 * is by attempting passthrough if the othercaps are a superset of caps. */
1012 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1014 is_fixed = gst_caps_is_fixed (othercaps);
1016 GST_DEBUG_OBJECT (trans,
1017 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1019 /* Now let's see what the peer suggests based on our transformed caps */
1021 GstCaps *peercaps, *intersection, *templ_caps;
1023 GST_DEBUG_OBJECT (trans,
1024 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1026 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1027 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1028 if (!gst_caps_is_empty (peercaps)) {
1029 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1031 GST_DEBUG_OBJECT (trans,
1032 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1035 gst_caps_intersect_full (peercaps, templ_caps,
1036 GST_CAPS_INTERSECT_FIRST);
1037 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1039 gst_caps_unref (peercaps);
1040 gst_caps_unref (templ_caps);
1041 peercaps = intersection;
1043 GST_DEBUG_OBJECT (trans,
1044 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1046 gst_caps_intersect_full (peercaps, othercaps,
1047 GST_CAPS_INTERSECT_FIRST);
1048 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1050 gst_caps_unref (peercaps);
1051 gst_caps_unref (othercaps);
1052 othercaps = intersection;
1054 othercaps = peercaps;
1057 is_fixed = gst_caps_is_fixed (othercaps);
1059 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1060 gst_caps_unref (othercaps);
1061 othercaps = gst_caps_ref (caps);
1065 if (gst_caps_is_empty (othercaps))
1066 goto no_transform_possible;
1068 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1071 /* second attempt at fixation, call the fixate vmethod */
1072 /* caps could be fixed but the subclass may want to add fields */
1073 if (klass->fixate_caps) {
1074 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1075 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1076 GST_DEBUG_PAD_NAME (otherpad));
1077 /* note that we pass the complete array of structures to the fixate
1078 * function, it needs to truncate itself */
1080 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1081 is_fixed = gst_caps_is_fixed (othercaps);
1082 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1085 /* caps should be fixed now, if not we have to fail. */
1087 goto could_not_fixate;
1089 /* and peer should accept */
1090 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1091 goto peer_no_accept;
1093 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1094 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1097 gst_object_unref (otherpeer);
1104 GST_DEBUG_OBJECT (trans,
1105 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1108 no_transform_possible:
1110 GST_DEBUG_OBJECT (trans,
1111 "transform could not transform %" GST_PTR_FORMAT
1112 " in anything we support", caps);
1117 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1122 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1123 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1129 gst_object_unref (otherpeer);
1131 gst_caps_unref (othercaps);
1137 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1138 GstPadDirection direction, GstCaps * caps)
1142 GstCaps *othercaps = NULL;
1144 gboolean ret = TRUE;
1147 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1149 /* we need fixed caps for the check, fall back to the default implementation
1151 if (!gst_caps_is_fixed (caps))
1156 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1158 /* get all the formats we can handle on this pad */
1159 if (direction == GST_PAD_SRC)
1160 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1162 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1165 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1166 goto no_transform_possible;
1169 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1171 /* intersect with the requested format */
1172 ret = gst_caps_is_subset (caps, allowed);
1173 gst_caps_unref (allowed);
1176 goto no_transform_possible;
1180 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1182 /* find best possible caps for the other pad as a way to see if we can
1183 * transform this caps. */
1184 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1185 if (!othercaps || gst_caps_is_empty (othercaps))
1186 goto no_transform_possible;
1188 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1194 /* We know it's always NULL since we never use it */
1196 gst_caps_unref (othercaps);
1202 no_transform_possible:
1204 GST_DEBUG_OBJECT (trans,
1205 "transform could not transform %" GST_PTR_FORMAT
1206 " in anything we support", caps);
1212 /* called when new caps arrive on the sink pad,
1213 * We try to find the best caps for the other side using our _find_transform()
1214 * function. If there are caps, we configure the transform for this new
1218 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1222 gboolean ret = TRUE;
1224 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1226 /* find best possible caps for the other pad */
1227 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1228 if (!outcaps || gst_caps_is_empty (outcaps))
1229 goto no_transform_possible;
1231 /* configure the element now */
1233 /* if we have the same caps, we can optimize and reuse the input caps */
1234 if (gst_caps_is_equal (incaps, outcaps)) {
1235 GST_INFO_OBJECT (trans, "reuse caps");
1236 gst_caps_unref (outcaps);
1237 outcaps = gst_caps_ref (incaps);
1240 /* call configure now */
1241 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1242 goto failed_configure;
1244 GST_OBJECT_LOCK (trans->sinkpad);
1245 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1246 trans->priv->reconfigure = FALSE;
1247 GST_OBJECT_UNLOCK (trans->sinkpad);
1249 /* we know this will work, we implement the setcaps */
1250 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1253 /* try to get a pool when needed */
1254 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1259 gst_caps_unref (outcaps);
1261 trans->negotiated = ret;
1266 no_transform_possible:
1268 GST_WARNING_OBJECT (trans,
1269 "transform could not transform %" GST_PTR_FORMAT
1270 " in anything we support", incaps);
1276 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1277 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1284 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1285 gboolean passthrough, GstQuery * query)
1290 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1291 ret = gst_pad_peer_query (trans->srcpad, query);
1299 gst_base_transform_default_query (GstBaseTransform * trans,
1300 GstPadDirection direction, GstQuery * query)
1302 gboolean ret = FALSE;
1303 GstPad *pad, *otherpad;
1304 GstBaseTransformClass *klass;
1306 if (direction == GST_PAD_SRC) {
1307 pad = trans->srcpad;
1308 otherpad = trans->sinkpad;
1310 pad = trans->sinkpad;
1311 otherpad = trans->srcpad;
1314 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1316 switch (GST_QUERY_TYPE (query)) {
1317 case GST_QUERY_ALLOCATION:
1319 gboolean passthrough;
1321 /* can only be done on the sinkpad */
1322 if (direction != GST_PAD_SINK)
1325 passthrough = gst_base_transform_is_passthrough (trans);
1327 GST_DEBUG_OBJECT (trans, "propose %spassthrough allocation values",
1328 (passthrough ? "" : "non-"));
1330 /* pass the query to the propose_allocation vmethod if any */
1331 if (G_LIKELY (klass->propose_allocation))
1332 ret = klass->propose_allocation (trans, passthrough, query);
1336 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1340 case GST_QUERY_POSITION:
1344 gst_query_parse_position (query, &format, NULL);
1345 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1349 if ((direction == GST_PAD_SINK)
1350 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1352 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1353 trans->segment.position);
1355 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1356 trans->priv->position_out);
1358 gst_query_set_position (query, format, pos);
1360 ret = gst_pad_peer_query (otherpad, query);
1364 case GST_QUERY_ACCEPT_CAPS:
1368 gst_query_parse_accept_caps (query, &caps);
1369 if (klass->accept_caps) {
1370 ret = klass->accept_caps (trans, direction, caps);
1371 gst_query_set_accept_caps_result (query, ret);
1372 /* return TRUE, we answered the query */
1377 case GST_QUERY_CAPS:
1379 GstCaps *filter, *caps;
1381 gst_query_parse_caps (query, &filter);
1382 caps = gst_base_transform_query_caps (trans, pad, filter);
1383 gst_query_set_caps_result (query, caps);
1384 gst_caps_unref (caps);
1389 ret = gst_pad_peer_query (otherpad, query);
1398 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1400 GstBaseTransform *trans;
1401 GstBaseTransformClass *bclass;
1402 gboolean ret = FALSE;
1404 trans = GST_BASE_TRANSFORM (parent);
1405 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1408 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1413 /* this function either returns the input buffer without incrementing the
1414 * refcount or it allocates a new (writable) buffer */
1415 static GstFlowReturn
1416 default_prepare_output_buffer (GstBaseTransform * trans,
1417 GstBuffer * inbuf, GstBuffer ** outbuf)
1419 GstBaseTransformPrivate *priv;
1420 GstFlowReturn ret = GST_FLOW_OK;
1421 GstBaseTransformClass *bclass;
1422 GstCaps *incaps, *outcaps;
1423 gsize insize, outsize;
1427 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1429 /* figure out how to allocate an output buffer */
1430 if (trans->passthrough) {
1431 /* passthrough, we will not modify the incomming buffer so we can just
1433 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1438 /* we can't reuse the input buffer */
1440 GST_DEBUG_OBJECT (trans, "using pool alloc");
1441 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1445 /* no pool, we need to figure out the size of the output buffer first */
1446 if ((bclass->transform_ip != NULL) && trans->always_in_place) {
1447 /* we want to do an in-place alloc */
1448 if (gst_buffer_is_writable (inbuf)) {
1449 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1452 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1453 /* we make a copy of the input buffer */
1454 *outbuf = gst_buffer_copy (inbuf);
1459 /* else use the transform function to get the size */
1460 incaps = gst_pad_get_current_caps (trans->sinkpad);
1461 outcaps = gst_pad_get_current_caps (trans->srcpad);
1463 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1464 /* copy transform, figure out the output size */
1465 insize = gst_buffer_get_size (inbuf);
1466 res = gst_base_transform_transform_size (trans,
1467 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1469 gst_caps_unref (incaps);
1470 gst_caps_unref (outcaps);
1475 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1476 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1479 /* copy the metadata */
1480 if (bclass->copy_metadata)
1481 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1482 /* something failed, post a warning */
1483 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1484 ("could not copy metadata"), (NULL));
1493 GST_ERROR_OBJECT (trans, "unknown output size");
1494 return GST_FLOW_ERROR;
1499 default_copy_metadata (GstBaseTransform * trans,
1500 GstBuffer * inbuf, GstBuffer * outbuf)
1502 GstBaseTransformPrivate *priv = trans->priv;
1504 /* now copy the metadata */
1505 GST_DEBUG_OBJECT (trans, "copying metadata");
1507 /* this should not happen, buffers allocated from a pool or with
1508 * new_allocate should always be writable. */
1509 if (!gst_buffer_is_writable (outbuf))
1512 /* when we get here, the metadata should be writable */
1513 gst_buffer_copy_into (outbuf, inbuf,
1514 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1516 /* clear the GAP flag when the subclass does not understand it */
1517 if (!priv->gap_aware)
1518 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1525 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1530 /* Given @caps calcultate the size of one unit.
1532 * For video caps, this is the size of one frame (and thus one buffer).
1533 * For audio caps, this is the size of one sample.
1535 * These values are cached since they do not change and the calculation
1536 * potentially involves parsing caps and other expensive stuff.
1538 * We have two cache locations to store the size, one for the source caps
1539 * and one for the sink caps.
1541 * this function returns FALSE if no size could be calculated.
1544 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1547 gboolean res = FALSE;
1548 GstBaseTransformClass *bclass;
1550 /* see if we have the result cached */
1551 if (trans->cache_caps1 == caps) {
1552 *size = trans->cache_caps1_size;
1553 GST_DEBUG_OBJECT (trans,
1554 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1557 if (trans->cache_caps2 == caps) {
1558 *size = trans->cache_caps2_size;
1559 GST_DEBUG_OBJECT (trans,
1560 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1564 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1565 res = bclass->get_unit_size (trans, caps, size);
1566 GST_DEBUG_OBJECT (trans,
1567 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1568 caps, *size, res ? "TRUE" : "FALSE");
1571 /* and cache the values */
1572 if (trans->cache_caps1 == NULL) {
1573 gst_caps_replace (&trans->cache_caps1, caps);
1574 trans->cache_caps1_size = *size;
1575 GST_DEBUG_OBJECT (trans,
1576 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1577 } else if (trans->cache_caps2 == NULL) {
1578 gst_caps_replace (&trans->cache_caps2, caps);
1579 trans->cache_caps2_size = *size;
1580 GST_DEBUG_OBJECT (trans,
1581 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1583 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1590 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1593 GstBaseTransform *trans;
1594 GstBaseTransformClass *bclass;
1595 gboolean ret = TRUE;
1597 trans = GST_BASE_TRANSFORM (parent);
1598 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1600 if (bclass->sink_event)
1601 ret = bclass->sink_event (trans, event);
1603 gst_event_unref (event);
1609 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1611 gboolean ret = TRUE, forward = TRUE;
1613 switch (GST_EVENT_TYPE (event)) {
1614 case GST_EVENT_FLUSH_START:
1616 case GST_EVENT_FLUSH_STOP:
1617 GST_OBJECT_LOCK (trans);
1618 /* reset QoS parameters */
1619 trans->priv->proportion = 1.0;
1620 trans->priv->earliest_time = -1;
1621 trans->priv->discont = FALSE;
1622 trans->priv->processed = 0;
1623 trans->priv->dropped = 0;
1624 GST_OBJECT_UNLOCK (trans);
1625 /* we need new segment info after the flush. */
1626 trans->have_segment = FALSE;
1627 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1628 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1634 case GST_EVENT_CAPS:
1638 gst_event_parse_caps (event, &caps);
1639 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1644 case GST_EVENT_SEGMENT:
1646 gst_event_copy_segment (event, &trans->segment);
1647 trans->have_segment = TRUE;
1649 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1658 ret = gst_pad_push_event (trans->srcpad, event);
1660 gst_event_unref (event);
1666 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1669 GstBaseTransform *trans;
1670 GstBaseTransformClass *bclass;
1671 gboolean ret = TRUE;
1673 trans = GST_BASE_TRANSFORM (parent);
1674 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1676 if (bclass->src_event)
1677 ret = bclass->src_event (trans, event);
1679 gst_event_unref (event);
1685 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1689 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1691 switch (GST_EVENT_TYPE (event)) {
1692 case GST_EVENT_SEEK:
1694 case GST_EVENT_NAVIGATION:
1699 GstClockTimeDiff diff;
1700 GstClockTime timestamp;
1702 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1703 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1710 ret = gst_pad_push_event (trans->sinkpad, event);
1715 /* perform a transform on @inbuf and put the result in @outbuf.
1717 * This function is common to the push and pull-based operations.
1719 * This function takes ownership of @inbuf */
1720 static GstFlowReturn
1721 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1722 GstBuffer ** outbuf)
1724 GstBaseTransformClass *bclass;
1725 GstFlowReturn ret = GST_FLOW_OK;
1726 gboolean want_in_place;
1727 GstClockTime running_time;
1728 GstClockTime timestamp;
1729 gboolean reconfigure;
1731 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1733 GST_OBJECT_LOCK (trans->sinkpad);
1734 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1735 || trans->priv->reconfigure;
1736 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1737 trans->priv->reconfigure = FALSE;
1738 GST_OBJECT_UNLOCK (trans->sinkpad);
1740 if (G_UNLIKELY (reconfigure)) {
1743 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1745 incaps = gst_pad_get_current_caps (trans->sinkpad);
1747 goto no_reconfigure;
1749 /* if we need to reconfigure we pretend new caps arrived. This
1750 * will reconfigure the transform with the new output format. */
1751 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1752 gst_caps_unref (incaps);
1753 goto not_negotiated;
1755 gst_caps_unref (incaps);
1759 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1760 GST_DEBUG_OBJECT (trans,
1761 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1762 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1763 GST_BUFFER_OFFSET (inbuf));
1765 GST_DEBUG_OBJECT (trans,
1766 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1767 gst_buffer_get_size (inbuf));
1769 /* Don't allow buffer handling before negotiation, except in passthrough mode
1770 * or if the class doesn't implement a set_caps function (in which case it doesn't
1773 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1774 goto not_negotiated;
1776 /* Set discont flag so we can mark the outgoing buffer */
1777 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1778 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1779 trans->priv->discont = TRUE;
1782 /* can only do QoS if the segment is in TIME */
1783 if (trans->segment.format != GST_FORMAT_TIME)
1786 /* QOS is done on the running time of the buffer, get it now */
1787 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1788 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1791 if (running_time != -1) {
1793 GstClockTime earliest_time;
1796 /* lock for getting the QoS parameters that are set (in a different thread)
1797 * with the QOS events */
1798 GST_OBJECT_LOCK (trans);
1799 earliest_time = trans->priv->earliest_time;
1800 proportion = trans->priv->proportion;
1801 /* check for QoS, don't perform conversion for buffers
1802 * that are known to be late. */
1803 need_skip = trans->priv->qos_enabled &&
1804 earliest_time != -1 && running_time <= earliest_time;
1805 GST_OBJECT_UNLOCK (trans);
1808 GstMessage *qos_msg;
1809 GstClockTime duration;
1810 guint64 stream_time;
1813 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1814 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1815 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1817 trans->priv->dropped++;
1819 duration = GST_BUFFER_DURATION (inbuf);
1821 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1823 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1826 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1827 stream_time, timestamp, duration);
1828 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1829 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1830 trans->priv->processed, trans->priv->dropped);
1831 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1833 /* mark discont for next buffer */
1834 trans->priv->discont = TRUE;
1841 /* first try to allocate an output buffer based on the currently negotiated
1842 * format. outbuf will contain a buffer suitable for doing the configured
1843 * transform after this function. */
1844 if (bclass->prepare_output_buffer == NULL)
1847 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1848 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1850 if (ret != GST_FLOW_OK || *outbuf == NULL)
1853 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1856 /* now perform the needed transform */
1857 if (trans->passthrough) {
1858 /* In passthrough mode, give transform_ip a look at the
1859 * buffer, without making it writable, or just push the
1861 if (bclass->transform_ip) {
1862 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1863 ret = bclass->transform_ip (trans, *outbuf);
1865 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1868 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1870 if (want_in_place) {
1871 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1872 ret = bclass->transform_ip (trans, *outbuf);
1874 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1876 if (bclass->transform)
1877 ret = bclass->transform (trans, inbuf, *outbuf);
1879 ret = GST_FLOW_NOT_SUPPORTED;
1884 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1885 * the input buffer, no refcount is changed to keep the input buffer writable
1887 if (*outbuf != inbuf)
1888 gst_buffer_unref (inbuf);
1895 gst_buffer_unref (inbuf);
1897 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1898 ("not negotiated"), ("not negotiated"));
1899 return GST_FLOW_NOT_NEGOTIATED;
1903 gst_buffer_unref (inbuf);
1904 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1905 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1906 return GST_FLOW_NOT_SUPPORTED;
1910 gst_buffer_unref (inbuf);
1912 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1913 gst_flow_get_name (ret));
1918 /* FIXME, getrange is broken, need to pull range from the other
1919 * end based on the transform_size result.
1921 static GstFlowReturn
1922 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
1923 guint length, GstBuffer ** buffer)
1925 GstBaseTransform *trans;
1926 GstBaseTransformClass *klass;
1930 trans = GST_BASE_TRANSFORM (parent);
1932 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1933 if (G_UNLIKELY (ret != GST_FLOW_OK))
1936 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1937 if (klass->before_transform)
1938 klass->before_transform (trans, inbuf);
1940 GST_BASE_TRANSFORM_LOCK (trans);
1941 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1942 GST_BASE_TRANSFORM_UNLOCK (trans);
1950 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1951 gst_flow_get_name (ret));
1956 static GstFlowReturn
1957 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
1959 GstBaseTransform *trans;
1960 GstBaseTransformClass *klass;
1962 GstClockTime position = GST_CLOCK_TIME_NONE;
1963 GstClockTime timestamp, duration;
1964 GstBuffer *outbuf = NULL;
1966 trans = GST_BASE_TRANSFORM (parent);
1968 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1969 duration = GST_BUFFER_DURATION (buffer);
1971 /* calculate end position of the incoming buffer */
1972 if (timestamp != GST_CLOCK_TIME_NONE) {
1973 if (duration != GST_CLOCK_TIME_NONE)
1974 position = timestamp + duration;
1976 position = timestamp;
1979 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1980 if (klass->before_transform)
1981 klass->before_transform (trans, buffer);
1983 /* protect transform method and concurrent buffer alloc */
1984 GST_BASE_TRANSFORM_LOCK (trans);
1985 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
1986 GST_BASE_TRANSFORM_UNLOCK (trans);
1988 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
1989 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
1990 if (outbuf != NULL) {
1991 if (ret == GST_FLOW_OK) {
1992 GstClockTime position_out = GST_CLOCK_TIME_NONE;
1994 /* Remember last stop position */
1995 if (position != GST_CLOCK_TIME_NONE &&
1996 trans->segment.format == GST_FORMAT_TIME)
1997 trans->segment.position = position;
1999 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2000 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2001 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2002 position_out += GST_BUFFER_DURATION (outbuf);
2003 } else if (position != GST_CLOCK_TIME_NONE) {
2004 position_out = position;
2006 if (position_out != GST_CLOCK_TIME_NONE
2007 && trans->segment.format == GST_FORMAT_TIME)
2008 trans->priv->position_out = position_out;
2010 /* apply DISCONT flag if the buffer is not yet marked as such */
2011 if (trans->priv->discont) {
2012 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2013 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2014 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2015 outbuf = gst_buffer_make_writable (outbuf);
2016 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2018 trans->priv->discont = FALSE;
2020 trans->priv->processed++;
2022 ret = gst_pad_push (trans->srcpad, outbuf);
2024 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2025 gst_buffer_unref (outbuf);
2029 /* convert internal flow to OK and mark discont for the next buffer. */
2030 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2031 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2032 trans->priv->discont = TRUE;
2040 gst_base_transform_set_property (GObject * object, guint prop_id,
2041 const GValue * value, GParamSpec * pspec)
2043 GstBaseTransform *trans;
2045 trans = GST_BASE_TRANSFORM (object);
2049 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2052 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2058 gst_base_transform_get_property (GObject * object, guint prop_id,
2059 GValue * value, GParamSpec * pspec)
2061 GstBaseTransform *trans;
2063 trans = GST_BASE_TRANSFORM (object);
2067 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2070 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2075 /* not a vmethod of anything, just an internal method */
2077 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2079 GstBaseTransformClass *bclass;
2080 gboolean result = TRUE;
2082 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2085 GstCaps *incaps, *outcaps;
2087 if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2088 result &= bclass->start (trans);
2090 incaps = gst_pad_get_current_caps (trans->sinkpad);
2091 outcaps = gst_pad_get_current_caps (trans->srcpad);
2093 GST_OBJECT_LOCK (trans);
2094 if (incaps && outcaps)
2095 trans->have_same_caps =
2096 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2098 trans->have_same_caps = trans->passthrough;
2099 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2100 trans->negotiated = FALSE;
2101 trans->have_segment = FALSE;
2102 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2103 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2104 trans->priv->proportion = 1.0;
2105 trans->priv->earliest_time = -1;
2106 trans->priv->discont = FALSE;
2107 trans->priv->processed = 0;
2108 trans->priv->dropped = 0;
2109 GST_OBJECT_UNLOCK (trans);
2112 gst_caps_unref (incaps);
2114 gst_caps_unref (outcaps);
2116 /* We must make sure streaming has finished before resetting things
2117 * and calling the ::stop vfunc */
2118 GST_PAD_STREAM_LOCK (trans->sinkpad);
2119 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2121 trans->have_same_caps = FALSE;
2122 /* We can only reset the passthrough mode if the instance told us to
2123 handle it in configure_caps */
2124 if (bclass->passthrough_on_same_caps) {
2125 gst_base_transform_set_passthrough (trans, FALSE);
2127 gst_caps_replace (&trans->cache_caps1, NULL);
2128 gst_caps_replace (&trans->cache_caps2, NULL);
2130 if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2131 result &= bclass->stop (trans);
2133 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2140 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2141 GstPadMode mode, gboolean active)
2143 gboolean result = FALSE;
2144 GstBaseTransform *trans;
2146 trans = GST_BASE_TRANSFORM (parent);
2149 case GST_PAD_MODE_PUSH:
2151 result = gst_base_transform_activate (trans, active);
2154 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2166 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2167 GstPadMode mode, gboolean active)
2169 gboolean result = FALSE;
2170 GstBaseTransform *trans;
2172 trans = GST_BASE_TRANSFORM (parent);
2175 case GST_PAD_MODE_PULL:
2178 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2181 result &= gst_base_transform_activate (trans, active);
2184 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2196 * gst_base_transform_set_passthrough:
2197 * @trans: the #GstBaseTransform to set
2198 * @passthrough: boolean indicating passthrough mode.
2200 * Set passthrough mode for this filter by default. This is mostly
2201 * useful for filters that do not care about negotiation.
2203 * Always TRUE for filters which don't implement either a transform
2204 * or transform_ip method.
2209 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2210 gboolean passthrough)
2212 GstBaseTransformClass *bclass;
2214 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2216 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2218 GST_OBJECT_LOCK (trans);
2219 if (passthrough == FALSE) {
2220 if (bclass->transform_ip || bclass->transform)
2221 trans->passthrough = FALSE;
2223 trans->passthrough = TRUE;
2226 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2227 GST_OBJECT_UNLOCK (trans);
2231 * gst_base_transform_is_passthrough:
2232 * @trans: the #GstBaseTransform to query
2234 * See if @trans is configured as a passthrough transform.
2236 * Returns: TRUE is the transform is configured in passthrough mode.
2241 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2245 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2247 GST_OBJECT_LOCK (trans);
2248 result = trans->passthrough;
2249 GST_OBJECT_UNLOCK (trans);
2255 * gst_base_transform_set_in_place:
2256 * @trans: the #GstBaseTransform to modify
2257 * @in_place: Boolean value indicating that we would like to operate
2258 * on in_place buffers.
2260 * Determines whether a non-writable buffer will be copied before passing
2261 * to the transform_ip function.
2263 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2264 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2270 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2272 GstBaseTransformClass *bclass;
2274 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2276 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2278 GST_OBJECT_LOCK (trans);
2281 if (bclass->transform_ip) {
2282 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2283 trans->always_in_place = TRUE;
2286 if (bclass->transform) {
2287 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2288 trans->always_in_place = FALSE;
2292 GST_OBJECT_UNLOCK (trans);
2296 * gst_base_transform_is_in_place:
2297 * @trans: the #GstBaseTransform to query
2299 * See if @trans is configured as a in_place transform.
2301 * Returns: TRUE is the transform is configured in in_place mode.
2306 gst_base_transform_is_in_place (GstBaseTransform * trans)
2310 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2312 GST_OBJECT_LOCK (trans);
2313 result = trans->always_in_place;
2314 GST_OBJECT_UNLOCK (trans);
2320 * gst_base_transform_update_qos:
2321 * @trans: a #GstBaseTransform
2322 * @proportion: the proportion
2323 * @diff: the diff against the clock
2324 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2327 * Set the QoS parameters in the transform. This function is called internally
2328 * when a QOS event is received but subclasses can provide custom information
2336 gst_base_transform_update_qos (GstBaseTransform * trans,
2337 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2340 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2342 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2343 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2344 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2346 GST_OBJECT_LOCK (trans);
2347 trans->priv->proportion = proportion;
2348 trans->priv->earliest_time = timestamp + diff;
2349 GST_OBJECT_UNLOCK (trans);
2353 * gst_base_transform_set_qos_enabled:
2354 * @trans: a #GstBaseTransform
2355 * @enabled: new state
2357 * Enable or disable QoS handling in the transform.
2364 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2366 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2368 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2370 GST_OBJECT_LOCK (trans);
2371 trans->priv->qos_enabled = enabled;
2372 GST_OBJECT_UNLOCK (trans);
2376 * gst_base_transform_is_qos_enabled:
2377 * @trans: a #GstBaseTransform
2379 * Queries if the transform will handle QoS.
2381 * Returns: TRUE if QoS is enabled.
2388 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2392 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2394 GST_OBJECT_LOCK (trans);
2395 result = trans->priv->qos_enabled;
2396 GST_OBJECT_UNLOCK (trans);
2402 * gst_base_transform_set_gap_aware:
2403 * @trans: a #GstBaseTransform
2404 * @gap_aware: New state
2406 * If @gap_aware is %FALSE (the default), output buffers will have the
2407 * %GST_BUFFER_FLAG_GAP flag unset.
2409 * If set to %TRUE, the element must handle output buffers with this flag set
2410 * correctly, i.e. it can assume that the buffer contains neutral data but must
2411 * unset the flag if the output is no neutral data.
2418 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2420 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2422 GST_OBJECT_LOCK (trans);
2423 trans->priv->gap_aware = gap_aware;
2424 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2425 GST_OBJECT_UNLOCK (trans);
2429 * gst_base_transform_suggest:
2430 * @trans: a #GstBaseTransform
2431 * @caps: (transfer none): caps to suggest
2432 * @size: buffer size to suggest
2434 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2440 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2443 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2445 /* push the renegotiate event */
2446 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2447 gst_event_new_reconfigure ()))
2448 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2452 * gst_base_transform_reconfigure:
2453 * @trans: a #GstBaseTransform
2455 * Instructs @trans to renegotiate a new downstream transform on the next
2456 * buffer. This function is typically called after properties on the transform
2457 * were set that influence the output format.
2462 gst_base_transform_reconfigure (GstBaseTransform * trans)
2464 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2466 GST_OBJECT_LOCK (trans);
2467 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2468 trans->priv->reconfigure = TRUE;
2469 GST_OBJECT_UNLOCK (trans);