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"
213 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
214 #define GST_CAT_DEFAULT gst_base_transform_debug
216 /* BaseTransform signals and args */
223 #define DEFAULT_PROP_QOS FALSE
231 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
232 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
234 struct _GstBaseTransformPrivate
236 /* QoS *//* with LOCK */
237 gboolean qos_enabled;
239 GstClockTime earliest_time;
240 /* previous buffer had a discont */
247 gboolean reconfigure;
253 GstClockTime position_out;
256 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_decide_allocation (GstBaseTransform
334 * trans, GstQuery * query);
335 static gboolean gst_base_transform_default_propose_allocation (GstBaseTransform
336 * trans, GstQuery * decide_query, GstQuery * query);
337 static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
339 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
340 GstPadDirection direction, GstQuery * query);
341 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
342 trans, GstPadDirection direction, GstCaps * caps, gsize size,
343 GstCaps * othercaps, gsize * othersize);
345 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
346 GstBuffer * inbuf, GstBuffer ** outbuf);
347 static gboolean default_copy_metadata (GstBaseTransform * trans,
348 GstBuffer * inbuf, GstBuffer * outbuf);
350 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
354 gst_base_transform_finalize (GObject * object)
356 G_OBJECT_CLASS (parent_class)->finalize (object);
360 gst_base_transform_class_init (GstBaseTransformClass * klass)
362 GObjectClass *gobject_class;
364 gobject_class = G_OBJECT_CLASS (klass);
366 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
367 "basetransform element");
369 GST_DEBUG ("gst_base_transform_class_init");
371 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
373 parent_class = g_type_class_peek_parent (klass);
375 gobject_class->set_property = gst_base_transform_set_property;
376 gobject_class->get_property = gst_base_transform_get_property;
378 g_object_class_install_property (gobject_class, PROP_QOS,
379 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
380 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 gobject_class->finalize = gst_base_transform_finalize;
384 klass->passthrough_on_same_caps = FALSE;
386 klass->transform_caps =
387 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
389 GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate_caps);
391 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
392 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
393 klass->decide_allocation =
394 GST_DEBUG_FUNCPTR (gst_base_transform_default_decide_allocation);
395 klass->propose_allocation =
396 GST_DEBUG_FUNCPTR (gst_base_transform_default_propose_allocation);
397 klass->transform_size =
398 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
400 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
401 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
402 klass->prepare_output_buffer =
403 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
404 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
408 gst_base_transform_init (GstBaseTransform * trans,
409 GstBaseTransformClass * bclass)
411 GstPadTemplate *pad_template;
413 GST_DEBUG ("gst_base_transform_init");
415 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
418 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
419 g_return_if_fail (pad_template != NULL);
420 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
421 gst_pad_set_event_function (trans->sinkpad,
422 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
423 gst_pad_set_chain_function (trans->sinkpad,
424 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
425 gst_pad_set_activatemode_function (trans->sinkpad,
426 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
427 gst_pad_set_query_function (trans->sinkpad,
428 GST_DEBUG_FUNCPTR (gst_base_transform_query));
429 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
432 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
433 g_return_if_fail (pad_template != NULL);
434 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
435 gst_pad_set_event_function (trans->srcpad,
436 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
437 gst_pad_set_getrange_function (trans->srcpad,
438 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
439 gst_pad_set_activatemode_function (trans->srcpad,
440 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
441 gst_pad_set_query_function (trans->srcpad,
442 GST_DEBUG_FUNCPTR (gst_base_transform_query));
443 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
445 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
446 trans->cache_caps1 = NULL;
447 trans->cache_caps2 = NULL;
448 trans->priv->pad_mode = GST_PAD_MODE_NONE;
449 trans->priv->gap_aware = FALSE;
451 trans->passthrough = FALSE;
452 if (bclass->transform == NULL) {
453 /* If no transform function, always_in_place is TRUE */
454 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
455 trans->always_in_place = TRUE;
457 if (bclass->transform_ip == NULL) {
458 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
459 trans->passthrough = TRUE;
463 trans->priv->processed = 0;
464 trans->priv->dropped = 0;
468 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
469 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
473 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
474 /* no transform function, use the identity transform */
476 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
478 ret = gst_caps_ref (caps);
483 /* given @caps on the src or sink pad (given by @direction)
484 * calculate the possible caps on the other pad.
486 * Returns new caps, unref after usage.
489 gst_base_transform_transform_caps (GstBaseTransform * trans,
490 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
493 GstBaseTransformClass *klass;
498 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
500 /* if there is a custom transform function, use this */
501 if (klass->transform_caps) {
502 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
504 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
505 ret = klass->transform_caps (trans, direction, caps, filter);
506 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
508 #ifndef G_DISABLE_ASSERT
510 if (!gst_caps_is_subset (ret, filter)) {
511 GstCaps *intersection;
513 GST_ERROR_OBJECT (trans,
514 "transform_caps returned caps %" GST_PTR_FORMAT
515 " which are not a real subset of the filter caps %"
516 GST_PTR_FORMAT, ret, filter);
517 g_warning ("%s: transform_caps returned caps which are not a real "
518 "subset of the filter caps", GST_ELEMENT_NAME (trans));
521 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
522 gst_caps_unref (ret);
529 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
535 gst_base_transform_default_transform_size (GstBaseTransform * trans,
536 GstPadDirection direction, GstCaps * caps, gsize size,
537 GstCaps * othercaps, gsize * othersize)
539 gsize inunitsize, outunitsize, units;
540 GstBaseTransformClass *klass;
542 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
544 if (klass->get_unit_size == NULL) {
545 /* if there is no transform_size and no unit_size, it means the
546 * element does not modify the size of a buffer */
549 /* there is no transform_size function, we have to use the unit_size
550 * functions. This method assumes there is a fixed unit_size associated with
551 * each caps. We provide the same amount of units on both sides. */
552 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
555 GST_DEBUG_OBJECT (trans,
556 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
559 /* input size must be a multiple of the unit_size of the input caps */
560 if (inunitsize == 0 || (size % inunitsize != 0))
563 /* get the amount of units */
564 units = size / inunitsize;
566 /* now get the unit size of the output */
567 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
570 /* the output size is the unit_size times the amount of units on the
572 *othersize = units * outunitsize;
573 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
581 GST_DEBUG_OBJECT (trans, "could not get in_size");
582 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
587 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
588 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
589 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
590 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
595 GST_DEBUG_OBJECT (trans, "could not get out_size");
596 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
601 /* transform a buffer of @size with @caps on the pad with @direction to
602 * the size of a buffer with @othercaps and store the result in @othersize
604 * We have two ways of doing this:
605 * 1) use a custom transform size function, this is for complicated custom
606 * cases with no fixed unit_size.
607 * 2) use the unit_size functions where there is a relationship between the
608 * caps and the size of a buffer.
611 gst_base_transform_transform_size (GstBaseTransform * trans,
612 GstPadDirection direction, GstCaps * caps,
613 gsize size, GstCaps * othercaps, gsize * othersize)
615 GstBaseTransformClass *klass;
616 gboolean ret = FALSE;
618 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
620 GST_DEBUG_OBJECT (trans,
621 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
622 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
623 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
625 if (klass->transform_size) {
626 /* if there is a custom transform function, use this */
627 ret = klass->transform_size (trans, direction, caps, size, othercaps,
633 /* get the caps that can be handled by @pad. We perform:
635 * - take the caps of peer of otherpad,
636 * - filter against the padtemplate of otherpad,
637 * - calculate all transforms of remaining caps
638 * - filter against template of @pad
640 * If there is no peer, we simply return the caps of the padtemplate of pad.
643 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
647 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
650 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
652 /* we can do what the peer can */
655 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
657 /* filtered against our padtemplate on the other side */
658 templ = gst_pad_get_pad_template_caps (pad);
659 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
660 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
661 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
662 gst_caps_unref (templ);
664 /* then see what we can transform this to */
665 peerfilter = gst_base_transform_transform_caps (trans,
666 GST_PAD_DIRECTION (pad), temp, NULL);
667 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
668 gst_caps_unref (temp);
670 /* and filter against the template of this pad */
671 templ = gst_pad_get_pad_template_caps (otherpad);
672 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
673 /* We keep the caps sorted like the returned caps */
675 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
676 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
677 gst_caps_unref (peerfilter);
678 gst_caps_unref (templ);
682 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
685 gst_caps_unref (peerfilter);
688 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
690 /* filtered against our padtemplate on the other side */
691 templ = gst_pad_get_pad_template_caps (otherpad);
692 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
693 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
694 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
695 gst_caps_unref (templ);
697 temp = gst_pad_get_pad_template_caps (otherpad);
700 /* then see what we can transform this to */
701 caps = gst_base_transform_transform_caps (trans,
702 GST_PAD_DIRECTION (otherpad), temp, filter);
703 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
704 gst_caps_unref (temp);
709 /* and filter against the template of this pad */
710 templ = gst_pad_get_pad_template_caps (pad);
711 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
712 /* We keep the caps sorted like the returned caps */
713 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
714 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
715 gst_caps_unref (caps);
716 gst_caps_unref (templ);
719 /* Now try if we can put the untransformed downstream caps first */
720 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
721 if (!gst_caps_is_empty (temp)) {
722 gst_caps_merge (temp, caps);
725 gst_caps_unref (temp);
728 gst_caps_unref (caps);
729 /* no peer or the peer can do anything, our padtemplate is enough then */
730 caps = gst_pad_get_pad_template_caps (pad);
735 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
736 gst_caps_unref (caps);
742 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
745 gst_caps_unref (peercaps);
750 /* takes ownership of the pool, allocator and query */
752 gst_base_transform_set_allocation (GstBaseTransform * trans,
753 GstBufferPool * pool, GstAllocator * allocator, guint prefix,
754 guint alignment, GstQuery * query)
756 GstAllocator *oldalloc;
757 GstBufferPool *oldpool;
759 GstBaseTransformPrivate *priv = trans->priv;
763 GST_DEBUG_OBJECT (trans, "setting pool %p active", pool);
764 if (!gst_buffer_pool_set_active (pool, TRUE))
765 goto activate_failed;
768 GST_OBJECT_LOCK (trans);
769 oldpool = priv->pool;
771 oldalloc = priv->allocator;
772 priv->allocator = allocator;
773 oldquery = priv->query;
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);
788 gst_query_unref (oldquery);
795 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
801 gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
806 n_metas = gst_query_get_n_allocation_metas (query);
807 for (i = 0; i < n_metas; i++) {
810 api = gst_query_parse_nth_allocation_meta (query, i);
811 /* remove all memory dependent metadata because we are going to have to
812 * allocate different memory for input and output. */
813 if (gst_meta_api_type_has_tag (api, GST_META_TAG_MEMORY)) {
814 GST_LOG_OBJECT (trans, "removing memory metadata %s", g_type_name (api));
815 gst_query_remove_nth_allocation_meta (query, i);
825 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
828 gboolean result = TRUE;
829 GstBufferPool *pool = NULL;
830 guint size, min, max, prefix, alignment;
831 GstBaseTransformClass *klass;
832 GstAllocator *allocator = NULL;
834 /* there are these possibilities:
836 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
837 * will do that whenever some upstream does an allocation query.
838 * 2) we need to do a transform, we need to get a bufferpool from downstream
839 * and configure it. When upstream does the ALLOCATION query, the
840 * propose_allocation vmethod will be called and we will configure the
841 * upstream allocator with our proposed values then.
843 if (trans->passthrough || trans->always_in_place) {
844 /* we are in passthrough, the input buffer is never copied and always passed
845 * along. We never allocate an output buffer on the srcpad. What we do is
846 * let the upstream element decide if it wants to use a bufferpool and
847 * then we will proxy the downstream pool */
848 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
849 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, NULL);
853 /* not passthrough, we need to allocate */
854 /* find a pool for the negotiated caps now */
855 GST_DEBUG_OBJECT (trans, "doing allocation query");
856 query = gst_query_new_allocation (outcaps, TRUE);
857 if (!gst_pad_peer_query (trans->srcpad, query)) {
858 /* not a problem, just debug a little */
859 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
862 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
864 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
865 if (G_LIKELY (klass->decide_allocation))
866 if ((result = klass->decide_allocation (trans, query)) == FALSE)
867 goto no_decide_allocation;
869 /* we got configuration from our peer, parse them */
870 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
874 /* no size, we have variable size buffers */
875 if (gst_query_get_n_allocation_memories (query) > 0) {
876 if ((allocator = gst_query_parse_nth_allocation_memory (query, 0)))
877 gst_allocator_ref (allocator);
879 GST_DEBUG_OBJECT (trans, "no size, using allocator %p", allocator);
880 } else if (pool == NULL) {
881 GstStructure *config;
883 /* we did not get a pool, make one ourselves then */
884 pool = gst_buffer_pool_new ();
886 GST_DEBUG_OBJECT (trans, "no pool, making one");
887 config = gst_buffer_pool_get_config (pool);
888 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
890 gst_buffer_pool_set_config (pool, config);
895 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
901 no_decide_allocation:
903 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
904 gst_query_unref (query);
910 /* function triggered when the in and out caps are negotiated and need
911 * to be configured in the subclass. */
913 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
917 GstBaseTransformClass *klass;
919 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
921 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
922 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
924 /* clear the cache */
925 gst_caps_replace (&trans->cache_caps1, NULL);
926 gst_caps_replace (&trans->cache_caps2, NULL);
928 /* figure out same caps state */
929 trans->have_same_caps = gst_caps_is_equal (in, out);
930 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
932 /* If we've a transform_ip method and same input/output caps, set in_place
933 * by default. If for some reason the sub-class prefers using a transform
934 * function, it can clear the in place flag in the set_caps */
935 gst_base_transform_set_in_place (trans,
936 klass->transform_ip && trans->have_same_caps);
938 /* Set the passthrough if the class wants passthrough_on_same_caps
939 * and we have the same caps on each pad */
940 if (klass->passthrough_on_same_caps)
941 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
943 /* now configure the element with the caps */
944 if (klass->set_caps) {
945 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
946 ret = klass->set_caps (trans, in, out);
949 trans->negotiated = ret;
955 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
956 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
958 othercaps = gst_caps_make_writable (othercaps);
959 gst_caps_fixate (othercaps);
960 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
965 /* given a fixed @caps on @pad, create the best possible caps for the
967 * @caps must be fixed when calling this function.
969 * This function calls the transform caps vmethod of the basetransform to figure
970 * out the possible target formats. It then tries to select the best format from
973 * - attempt passthrough if the target caps is a superset of the input caps
974 * - fixating by using peer caps
975 * - fixating with transform fixate function
976 * - fixating with pad fixate functions.
978 * this function returns a caps that can be transformed into and is accepted by
982 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
985 GstBaseTransformClass *klass;
986 GstPad *otherpad, *otherpeer;
990 /* caps must be fixed here, this is a programming error if it's not */
991 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
993 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
995 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
996 otherpeer = gst_pad_get_peer (otherpad);
998 /* see how we can transform the input caps. We need to do this even for
999 * passthrough because it might be possible that this element cannot support
1000 * passthrough at all. */
1001 othercaps = gst_base_transform_transform_caps (trans,
1002 GST_PAD_DIRECTION (pad), caps, NULL);
1004 /* The caps we can actually output is the intersection of the transformed
1005 * caps with the pad template for the pad */
1007 GstCaps *intersect, *templ_caps;
1009 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1010 GST_DEBUG_OBJECT (trans,
1011 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
1014 gst_caps_intersect_full (othercaps, templ_caps,
1015 GST_CAPS_INTERSECT_FIRST);
1017 gst_caps_unref (othercaps);
1018 gst_caps_unref (templ_caps);
1019 othercaps = intersect;
1022 /* check if transform is empty */
1023 if (!othercaps || gst_caps_is_empty (othercaps))
1026 /* if the othercaps are not fixed, we need to fixate them, first attempt
1027 * is by attempting passthrough if the othercaps are a superset of caps. */
1028 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1030 is_fixed = gst_caps_is_fixed (othercaps);
1032 GST_DEBUG_OBJECT (trans,
1033 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1035 /* Now let's see what the peer suggests based on our transformed caps */
1037 GstCaps *peercaps, *intersection, *templ_caps;
1039 GST_DEBUG_OBJECT (trans,
1040 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1042 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1043 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1044 if (!gst_caps_is_empty (peercaps)) {
1045 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1047 GST_DEBUG_OBJECT (trans,
1048 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1051 gst_caps_intersect_full (peercaps, templ_caps,
1052 GST_CAPS_INTERSECT_FIRST);
1053 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1055 gst_caps_unref (peercaps);
1056 gst_caps_unref (templ_caps);
1057 peercaps = intersection;
1059 GST_DEBUG_OBJECT (trans,
1060 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1062 gst_caps_intersect_full (peercaps, othercaps,
1063 GST_CAPS_INTERSECT_FIRST);
1064 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1066 gst_caps_unref (peercaps);
1067 gst_caps_unref (othercaps);
1068 othercaps = intersection;
1070 othercaps = peercaps;
1073 is_fixed = gst_caps_is_fixed (othercaps);
1075 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1076 gst_caps_unref (othercaps);
1077 othercaps = gst_caps_ref (caps);
1081 if (gst_caps_is_empty (othercaps))
1082 goto no_transform_possible;
1084 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1087 /* second attempt at fixation, call the fixate vmethod */
1088 /* caps could be fixed but the subclass may want to add fields */
1089 if (klass->fixate_caps) {
1090 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1091 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1092 GST_DEBUG_PAD_NAME (otherpad));
1093 /* note that we pass the complete array of structures to the fixate
1094 * function, it needs to truncate itself */
1096 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1097 is_fixed = gst_caps_is_fixed (othercaps);
1098 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1101 /* caps should be fixed now, if not we have to fail. */
1103 goto could_not_fixate;
1105 /* and peer should accept */
1106 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1107 goto peer_no_accept;
1109 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1110 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1113 gst_object_unref (otherpeer);
1120 GST_DEBUG_OBJECT (trans,
1121 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1124 no_transform_possible:
1126 GST_DEBUG_OBJECT (trans,
1127 "transform could not transform %" GST_PTR_FORMAT
1128 " in anything we support", caps);
1133 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1138 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1139 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1145 gst_object_unref (otherpeer);
1147 gst_caps_unref (othercaps);
1153 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1154 GstPadDirection direction, GstCaps * caps)
1158 GstCaps *othercaps = NULL;
1160 gboolean ret = TRUE;
1163 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1165 /* we need fixed caps for the check, fall back to the default implementation
1167 if (!gst_caps_is_fixed (caps))
1172 GST_DEBUG_OBJECT (trans, "accept caps %" GST_PTR_FORMAT, caps);
1174 /* get all the formats we can handle on this pad */
1175 if (direction == GST_PAD_SRC)
1176 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1178 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1181 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1182 goto no_transform_possible;
1185 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1187 /* intersect with the requested format */
1188 ret = gst_caps_is_subset (caps, allowed);
1189 gst_caps_unref (allowed);
1192 goto no_transform_possible;
1196 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1198 /* find best possible caps for the other pad as a way to see if we can
1199 * transform this caps. */
1200 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1201 if (!othercaps || gst_caps_is_empty (othercaps))
1202 goto no_transform_possible;
1204 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1210 /* We know it's always NULL since we never use it */
1212 gst_caps_unref (othercaps);
1218 no_transform_possible:
1220 GST_DEBUG_OBJECT (trans,
1221 "transform could not transform %" GST_PTR_FORMAT
1222 " in anything we support", caps);
1228 /* called when new caps arrive on the sink pad,
1229 * We try to find the best caps for the other side using our _find_transform()
1230 * function. If there are caps, we configure the transform for this new
1234 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1238 gboolean ret = TRUE;
1240 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1242 /* find best possible caps for the other pad */
1243 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1244 if (!outcaps || gst_caps_is_empty (outcaps))
1245 goto no_transform_possible;
1247 /* configure the element now */
1249 /* if we have the same caps, we can optimize and reuse the input caps */
1250 if (gst_caps_is_equal (incaps, outcaps)) {
1251 GST_INFO_OBJECT (trans, "reuse caps");
1252 gst_caps_unref (outcaps);
1253 outcaps = gst_caps_ref (incaps);
1256 /* call configure now */
1257 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1258 goto failed_configure;
1260 GST_OBJECT_LOCK (trans->sinkpad);
1261 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1262 trans->priv->reconfigure = FALSE;
1263 GST_OBJECT_UNLOCK (trans->sinkpad);
1265 /* we know this will work, we implement the setcaps */
1266 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1269 /* try to get a pool when needed */
1270 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1275 gst_caps_unref (outcaps);
1277 trans->negotiated = ret;
1282 no_transform_possible:
1284 GST_WARNING_OBJECT (trans,
1285 "transform could not transform %" GST_PTR_FORMAT
1286 " in anything we support", incaps);
1292 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1293 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1300 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1301 GstQuery * decide_query, GstQuery * query)
1305 if (decide_query == NULL) {
1306 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1307 ret = gst_pad_peer_query (trans->srcpad, query);
1315 gst_base_transform_default_query (GstBaseTransform * trans,
1316 GstPadDirection direction, GstQuery * query)
1318 gboolean ret = FALSE;
1319 GstPad *pad, *otherpad;
1320 GstBaseTransformClass *klass;
1322 if (direction == GST_PAD_SRC) {
1323 pad = trans->srcpad;
1324 otherpad = trans->sinkpad;
1326 pad = trans->sinkpad;
1327 otherpad = trans->srcpad;
1330 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1332 switch (GST_QUERY_TYPE (query)) {
1333 case GST_QUERY_ALLOCATION:
1335 GstQuery *decide_query;
1337 /* can only be done on the sinkpad */
1338 if (direction != GST_PAD_SINK)
1341 GST_OBJECT_LOCK (trans);
1342 if ((decide_query = trans->priv->query))
1343 gst_query_ref (decide_query);
1344 GST_OBJECT_UNLOCK (trans);
1346 GST_DEBUG_OBJECT (trans,
1347 "calling propose allocation with query %" GST_PTR_FORMAT,
1350 /* pass the query to the propose_allocation vmethod if any */
1351 if (G_LIKELY (klass->propose_allocation))
1352 ret = klass->propose_allocation (trans, decide_query, query);
1357 gst_query_unref (decide_query);
1359 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1363 case GST_QUERY_POSITION:
1367 gst_query_parse_position (query, &format, NULL);
1368 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1372 if ((direction == GST_PAD_SINK)
1373 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1375 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1376 trans->segment.position);
1378 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1379 trans->priv->position_out);
1381 gst_query_set_position (query, format, pos);
1383 ret = gst_pad_peer_query (otherpad, query);
1387 case GST_QUERY_ACCEPT_CAPS:
1391 gst_query_parse_accept_caps (query, &caps);
1392 if (klass->accept_caps) {
1393 ret = klass->accept_caps (trans, direction, caps);
1394 gst_query_set_accept_caps_result (query, ret);
1395 /* return TRUE, we answered the query */
1400 case GST_QUERY_CAPS:
1402 GstCaps *filter, *caps;
1404 gst_query_parse_caps (query, &filter);
1405 caps = gst_base_transform_query_caps (trans, pad, filter);
1406 gst_query_set_caps_result (query, caps);
1407 gst_caps_unref (caps);
1412 ret = gst_pad_peer_query (otherpad, query);
1421 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1423 GstBaseTransform *trans;
1424 GstBaseTransformClass *bclass;
1425 gboolean ret = FALSE;
1427 trans = GST_BASE_TRANSFORM (parent);
1428 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1431 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1436 /* this function either returns the input buffer without incrementing the
1437 * refcount or it allocates a new (writable) buffer */
1438 static GstFlowReturn
1439 default_prepare_output_buffer (GstBaseTransform * trans,
1440 GstBuffer * inbuf, GstBuffer ** outbuf)
1442 GstBaseTransformPrivate *priv;
1443 GstFlowReturn ret = GST_FLOW_OK;
1444 GstBaseTransformClass *bclass;
1445 GstCaps *incaps, *outcaps;
1446 gsize insize, outsize;
1450 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1452 /* figure out how to allocate an output buffer */
1453 if (trans->passthrough) {
1454 /* passthrough, we will not modify the incomming buffer so we can just
1456 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1461 /* we can't reuse the input buffer */
1463 GST_DEBUG_OBJECT (trans, "using pool alloc");
1464 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1468 /* no pool, we need to figure out the size of the output buffer first */
1469 if ((bclass->transform_ip != NULL) && trans->always_in_place) {
1470 /* we want to do an in-place alloc */
1471 if (gst_buffer_is_writable (inbuf)) {
1472 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1475 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1476 /* we make a copy of the input buffer */
1477 *outbuf = gst_buffer_copy (inbuf);
1482 /* else use the transform function to get the size */
1483 incaps = gst_pad_get_current_caps (trans->sinkpad);
1484 outcaps = gst_pad_get_current_caps (trans->srcpad);
1486 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1487 /* copy transform, figure out the output size */
1488 insize = gst_buffer_get_size (inbuf);
1489 res = gst_base_transform_transform_size (trans,
1490 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1492 gst_caps_unref (incaps);
1493 gst_caps_unref (outcaps);
1498 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1499 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1502 /* copy the metadata */
1503 if (bclass->copy_metadata)
1504 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1505 /* something failed, post a warning */
1506 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1507 ("could not copy metadata"), (NULL));
1516 GST_ERROR_OBJECT (trans, "unknown output size");
1517 return GST_FLOW_ERROR;
1522 default_copy_metadata (GstBaseTransform * trans,
1523 GstBuffer * inbuf, GstBuffer * outbuf)
1525 GstBaseTransformPrivate *priv = trans->priv;
1527 /* now copy the metadata */
1528 GST_DEBUG_OBJECT (trans, "copying metadata");
1530 /* this should not happen, buffers allocated from a pool or with
1531 * new_allocate should always be writable. */
1532 if (!gst_buffer_is_writable (outbuf))
1535 /* when we get here, the metadata should be writable */
1536 gst_buffer_copy_into (outbuf, inbuf,
1537 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1539 /* clear the GAP flag when the subclass does not understand it */
1540 if (!priv->gap_aware)
1541 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1548 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1553 /* Given @caps calcultate the size of one unit.
1555 * For video caps, this is the size of one frame (and thus one buffer).
1556 * For audio caps, this is the size of one sample.
1558 * These values are cached since they do not change and the calculation
1559 * potentially involves parsing caps and other expensive stuff.
1561 * We have two cache locations to store the size, one for the source caps
1562 * and one for the sink caps.
1564 * this function returns FALSE if no size could be calculated.
1567 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1570 gboolean res = FALSE;
1571 GstBaseTransformClass *bclass;
1573 /* see if we have the result cached */
1574 if (trans->cache_caps1 == caps) {
1575 *size = trans->cache_caps1_size;
1576 GST_DEBUG_OBJECT (trans,
1577 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1580 if (trans->cache_caps2 == caps) {
1581 *size = trans->cache_caps2_size;
1582 GST_DEBUG_OBJECT (trans,
1583 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1587 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1588 res = bclass->get_unit_size (trans, caps, size);
1589 GST_DEBUG_OBJECT (trans,
1590 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1591 caps, *size, res ? "TRUE" : "FALSE");
1594 /* and cache the values */
1595 if (trans->cache_caps1 == NULL) {
1596 gst_caps_replace (&trans->cache_caps1, caps);
1597 trans->cache_caps1_size = *size;
1598 GST_DEBUG_OBJECT (trans,
1599 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1600 } else if (trans->cache_caps2 == NULL) {
1601 gst_caps_replace (&trans->cache_caps2, caps);
1602 trans->cache_caps2_size = *size;
1603 GST_DEBUG_OBJECT (trans,
1604 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1606 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1613 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1616 GstBaseTransform *trans;
1617 GstBaseTransformClass *bclass;
1618 gboolean ret = TRUE;
1620 trans = GST_BASE_TRANSFORM (parent);
1621 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1623 if (bclass->sink_event)
1624 ret = bclass->sink_event (trans, event);
1626 gst_event_unref (event);
1632 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1634 gboolean ret = TRUE, forward = TRUE;
1636 switch (GST_EVENT_TYPE (event)) {
1637 case GST_EVENT_FLUSH_START:
1639 case GST_EVENT_FLUSH_STOP:
1640 GST_OBJECT_LOCK (trans);
1641 /* reset QoS parameters */
1642 trans->priv->proportion = 1.0;
1643 trans->priv->earliest_time = -1;
1644 trans->priv->discont = FALSE;
1645 trans->priv->processed = 0;
1646 trans->priv->dropped = 0;
1647 GST_OBJECT_UNLOCK (trans);
1648 /* we need new segment info after the flush. */
1649 trans->have_segment = FALSE;
1650 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1651 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1657 case GST_EVENT_CAPS:
1661 gst_event_parse_caps (event, &caps);
1662 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1667 case GST_EVENT_SEGMENT:
1669 gst_event_copy_segment (event, &trans->segment);
1670 trans->have_segment = TRUE;
1672 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1681 ret = gst_pad_push_event (trans->srcpad, event);
1683 gst_event_unref (event);
1689 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1692 GstBaseTransform *trans;
1693 GstBaseTransformClass *bclass;
1694 gboolean ret = TRUE;
1696 trans = GST_BASE_TRANSFORM (parent);
1697 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1699 if (bclass->src_event)
1700 ret = bclass->src_event (trans, event);
1702 gst_event_unref (event);
1708 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1712 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1714 switch (GST_EVENT_TYPE (event)) {
1715 case GST_EVENT_SEEK:
1717 case GST_EVENT_NAVIGATION:
1722 GstClockTimeDiff diff;
1723 GstClockTime timestamp;
1725 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1726 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1733 ret = gst_pad_push_event (trans->sinkpad, event);
1738 /* perform a transform on @inbuf and put the result in @outbuf.
1740 * This function is common to the push and pull-based operations.
1742 * This function takes ownership of @inbuf */
1743 static GstFlowReturn
1744 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1745 GstBuffer ** outbuf)
1747 GstBaseTransformClass *bclass;
1748 GstFlowReturn ret = GST_FLOW_OK;
1749 gboolean want_in_place;
1750 GstClockTime running_time;
1751 GstClockTime timestamp;
1752 gboolean reconfigure;
1754 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1756 GST_OBJECT_LOCK (trans->sinkpad);
1757 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1758 || trans->priv->reconfigure;
1759 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1760 trans->priv->reconfigure = FALSE;
1761 GST_OBJECT_UNLOCK (trans->sinkpad);
1763 if (G_UNLIKELY (reconfigure)) {
1766 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1768 incaps = gst_pad_get_current_caps (trans->sinkpad);
1770 goto no_reconfigure;
1772 /* if we need to reconfigure we pretend new caps arrived. This
1773 * will reconfigure the transform with the new output format. */
1774 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1775 gst_caps_unref (incaps);
1776 goto not_negotiated;
1778 gst_caps_unref (incaps);
1782 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1783 GST_DEBUG_OBJECT (trans,
1784 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1785 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1786 GST_BUFFER_OFFSET (inbuf));
1788 GST_DEBUG_OBJECT (trans,
1789 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1790 gst_buffer_get_size (inbuf));
1792 /* Don't allow buffer handling before negotiation, except in passthrough mode
1793 * or if the class doesn't implement a set_caps function (in which case it doesn't
1796 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1797 goto not_negotiated;
1799 /* Set discont flag so we can mark the outgoing buffer */
1800 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1801 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1802 trans->priv->discont = TRUE;
1805 /* can only do QoS if the segment is in TIME */
1806 if (trans->segment.format != GST_FORMAT_TIME)
1809 /* QOS is done on the running time of the buffer, get it now */
1810 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1811 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1814 if (running_time != -1) {
1816 GstClockTime earliest_time;
1819 /* lock for getting the QoS parameters that are set (in a different thread)
1820 * with the QOS events */
1821 GST_OBJECT_LOCK (trans);
1822 earliest_time = trans->priv->earliest_time;
1823 proportion = trans->priv->proportion;
1824 /* check for QoS, don't perform conversion for buffers
1825 * that are known to be late. */
1826 need_skip = trans->priv->qos_enabled &&
1827 earliest_time != -1 && running_time <= earliest_time;
1828 GST_OBJECT_UNLOCK (trans);
1831 GstMessage *qos_msg;
1832 GstClockTime duration;
1833 guint64 stream_time;
1836 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1837 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1838 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1840 trans->priv->dropped++;
1842 duration = GST_BUFFER_DURATION (inbuf);
1844 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1846 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1849 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1850 stream_time, timestamp, duration);
1851 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1852 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1853 trans->priv->processed, trans->priv->dropped);
1854 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1856 /* mark discont for next buffer */
1857 trans->priv->discont = TRUE;
1864 /* first try to allocate an output buffer based on the currently negotiated
1865 * format. outbuf will contain a buffer suitable for doing the configured
1866 * transform after this function. */
1867 if (bclass->prepare_output_buffer == NULL)
1870 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1871 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1873 if (ret != GST_FLOW_OK || *outbuf == NULL)
1876 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1879 /* now perform the needed transform */
1880 if (trans->passthrough) {
1881 /* In passthrough mode, give transform_ip a look at the
1882 * buffer, without making it writable, or just push the
1884 if (bclass->transform_ip) {
1885 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1886 ret = bclass->transform_ip (trans, *outbuf);
1888 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1891 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1893 if (want_in_place) {
1894 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1895 ret = bclass->transform_ip (trans, *outbuf);
1897 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1899 if (bclass->transform)
1900 ret = bclass->transform (trans, inbuf, *outbuf);
1902 ret = GST_FLOW_NOT_SUPPORTED;
1907 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
1908 * the input buffer, no refcount is changed to keep the input buffer writable
1910 if (*outbuf != inbuf)
1911 gst_buffer_unref (inbuf);
1918 gst_buffer_unref (inbuf);
1920 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1921 ("not negotiated"), ("not negotiated"));
1922 return GST_FLOW_NOT_NEGOTIATED;
1926 gst_buffer_unref (inbuf);
1927 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1928 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
1929 return GST_FLOW_NOT_SUPPORTED;
1933 gst_buffer_unref (inbuf);
1935 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1936 gst_flow_get_name (ret));
1941 /* FIXME, getrange is broken, need to pull range from the other
1942 * end based on the transform_size result.
1944 static GstFlowReturn
1945 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
1946 guint length, GstBuffer ** buffer)
1948 GstBaseTransform *trans;
1949 GstBaseTransformClass *klass;
1953 trans = GST_BASE_TRANSFORM (parent);
1955 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1956 if (G_UNLIKELY (ret != GST_FLOW_OK))
1959 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1960 if (klass->before_transform)
1961 klass->before_transform (trans, inbuf);
1963 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1971 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1972 gst_flow_get_name (ret));
1977 static GstFlowReturn
1978 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
1980 GstBaseTransform *trans;
1981 GstBaseTransformClass *klass;
1983 GstClockTime position = GST_CLOCK_TIME_NONE;
1984 GstClockTime timestamp, duration;
1985 GstBuffer *outbuf = NULL;
1987 trans = GST_BASE_TRANSFORM (parent);
1989 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1990 duration = GST_BUFFER_DURATION (buffer);
1992 /* calculate end position of the incoming buffer */
1993 if (timestamp != GST_CLOCK_TIME_NONE) {
1994 if (duration != GST_CLOCK_TIME_NONE)
1995 position = timestamp + duration;
1997 position = timestamp;
2000 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2001 if (klass->before_transform)
2002 klass->before_transform (trans, buffer);
2004 /* protect transform method and concurrent buffer alloc */
2005 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2007 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2008 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2009 if (outbuf != NULL) {
2010 if (ret == GST_FLOW_OK) {
2011 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2013 /* Remember last stop position */
2014 if (position != GST_CLOCK_TIME_NONE &&
2015 trans->segment.format == GST_FORMAT_TIME)
2016 trans->segment.position = position;
2018 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2019 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2020 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2021 position_out += GST_BUFFER_DURATION (outbuf);
2022 } else if (position != GST_CLOCK_TIME_NONE) {
2023 position_out = position;
2025 if (position_out != GST_CLOCK_TIME_NONE
2026 && trans->segment.format == GST_FORMAT_TIME)
2027 trans->priv->position_out = position_out;
2029 /* apply DISCONT flag if the buffer is not yet marked as such */
2030 if (trans->priv->discont) {
2031 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2032 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2033 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2034 outbuf = gst_buffer_make_writable (outbuf);
2035 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2037 trans->priv->discont = FALSE;
2039 trans->priv->processed++;
2041 ret = gst_pad_push (trans->srcpad, outbuf);
2043 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2044 gst_buffer_unref (outbuf);
2048 /* convert internal flow to OK and mark discont for the next buffer. */
2049 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2050 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2051 trans->priv->discont = TRUE;
2059 gst_base_transform_set_property (GObject * object, guint prop_id,
2060 const GValue * value, GParamSpec * pspec)
2062 GstBaseTransform *trans;
2064 trans = GST_BASE_TRANSFORM (object);
2068 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2071 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2077 gst_base_transform_get_property (GObject * object, guint prop_id,
2078 GValue * value, GParamSpec * pspec)
2080 GstBaseTransform *trans;
2082 trans = GST_BASE_TRANSFORM (object);
2086 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2089 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2094 /* not a vmethod of anything, just an internal method */
2096 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2098 GstBaseTransformClass *bclass;
2099 gboolean result = TRUE;
2101 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2104 GstCaps *incaps, *outcaps;
2106 if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2107 result &= bclass->start (trans);
2109 incaps = gst_pad_get_current_caps (trans->sinkpad);
2110 outcaps = gst_pad_get_current_caps (trans->srcpad);
2112 GST_OBJECT_LOCK (trans);
2113 if (incaps && outcaps)
2114 trans->have_same_caps =
2115 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2117 trans->have_same_caps = trans->passthrough;
2118 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2119 trans->negotiated = FALSE;
2120 trans->have_segment = FALSE;
2121 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2122 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2123 trans->priv->proportion = 1.0;
2124 trans->priv->earliest_time = -1;
2125 trans->priv->discont = FALSE;
2126 trans->priv->processed = 0;
2127 trans->priv->dropped = 0;
2128 GST_OBJECT_UNLOCK (trans);
2131 gst_caps_unref (incaps);
2133 gst_caps_unref (outcaps);
2135 /* We must make sure streaming has finished before resetting things
2136 * and calling the ::stop vfunc */
2137 GST_PAD_STREAM_LOCK (trans->sinkpad);
2138 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2140 trans->have_same_caps = FALSE;
2141 /* We can only reset the passthrough mode if the instance told us to
2142 handle it in configure_caps */
2143 if (bclass->passthrough_on_same_caps) {
2144 gst_base_transform_set_passthrough (trans, FALSE);
2146 gst_caps_replace (&trans->cache_caps1, NULL);
2147 gst_caps_replace (&trans->cache_caps2, NULL);
2149 if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2150 result &= bclass->stop (trans);
2152 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, NULL);
2159 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2160 GstPadMode mode, gboolean active)
2162 gboolean result = FALSE;
2163 GstBaseTransform *trans;
2165 trans = GST_BASE_TRANSFORM (parent);
2168 case GST_PAD_MODE_PUSH:
2170 result = gst_base_transform_activate (trans, active);
2173 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2185 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2186 GstPadMode mode, gboolean active)
2188 gboolean result = FALSE;
2189 GstBaseTransform *trans;
2191 trans = GST_BASE_TRANSFORM (parent);
2194 case GST_PAD_MODE_PULL:
2197 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2200 result &= gst_base_transform_activate (trans, active);
2203 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2215 * gst_base_transform_set_passthrough:
2216 * @trans: the #GstBaseTransform to set
2217 * @passthrough: boolean indicating passthrough mode.
2219 * Set passthrough mode for this filter by default. This is mostly
2220 * useful for filters that do not care about negotiation.
2222 * Always TRUE for filters which don't implement either a transform
2223 * or transform_ip method.
2228 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2229 gboolean passthrough)
2231 GstBaseTransformClass *bclass;
2233 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2235 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2237 GST_OBJECT_LOCK (trans);
2238 if (passthrough == FALSE) {
2239 if (bclass->transform_ip || bclass->transform)
2240 trans->passthrough = FALSE;
2242 trans->passthrough = TRUE;
2245 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2246 GST_OBJECT_UNLOCK (trans);
2250 * gst_base_transform_is_passthrough:
2251 * @trans: the #GstBaseTransform to query
2253 * See if @trans is configured as a passthrough transform.
2255 * Returns: TRUE is the transform is configured in passthrough mode.
2260 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2264 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2266 GST_OBJECT_LOCK (trans);
2267 result = trans->passthrough;
2268 GST_OBJECT_UNLOCK (trans);
2274 * gst_base_transform_set_in_place:
2275 * @trans: the #GstBaseTransform to modify
2276 * @in_place: Boolean value indicating that we would like to operate
2277 * on in_place buffers.
2279 * Determines whether a non-writable buffer will be copied before passing
2280 * to the transform_ip function.
2282 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2283 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2289 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2291 GstBaseTransformClass *bclass;
2293 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2295 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2297 GST_OBJECT_LOCK (trans);
2300 if (bclass->transform_ip) {
2301 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2302 trans->always_in_place = TRUE;
2305 if (bclass->transform) {
2306 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2307 trans->always_in_place = FALSE;
2311 GST_OBJECT_UNLOCK (trans);
2315 * gst_base_transform_is_in_place:
2316 * @trans: the #GstBaseTransform to query
2318 * See if @trans is configured as a in_place transform.
2320 * Returns: TRUE is the transform is configured in in_place mode.
2325 gst_base_transform_is_in_place (GstBaseTransform * trans)
2329 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2331 GST_OBJECT_LOCK (trans);
2332 result = trans->always_in_place;
2333 GST_OBJECT_UNLOCK (trans);
2339 * gst_base_transform_update_qos:
2340 * @trans: a #GstBaseTransform
2341 * @proportion: the proportion
2342 * @diff: the diff against the clock
2343 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2346 * Set the QoS parameters in the transform. This function is called internally
2347 * when a QOS event is received but subclasses can provide custom information
2355 gst_base_transform_update_qos (GstBaseTransform * trans,
2356 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2359 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2361 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2362 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2363 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2365 GST_OBJECT_LOCK (trans);
2366 trans->priv->proportion = proportion;
2367 trans->priv->earliest_time = timestamp + diff;
2368 GST_OBJECT_UNLOCK (trans);
2372 * gst_base_transform_set_qos_enabled:
2373 * @trans: a #GstBaseTransform
2374 * @enabled: new state
2376 * Enable or disable QoS handling in the transform.
2383 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2385 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2387 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2389 GST_OBJECT_LOCK (trans);
2390 trans->priv->qos_enabled = enabled;
2391 GST_OBJECT_UNLOCK (trans);
2395 * gst_base_transform_is_qos_enabled:
2396 * @trans: a #GstBaseTransform
2398 * Queries if the transform will handle QoS.
2400 * Returns: TRUE if QoS is enabled.
2407 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2411 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2413 GST_OBJECT_LOCK (trans);
2414 result = trans->priv->qos_enabled;
2415 GST_OBJECT_UNLOCK (trans);
2421 * gst_base_transform_set_gap_aware:
2422 * @trans: a #GstBaseTransform
2423 * @gap_aware: New state
2425 * If @gap_aware is %FALSE (the default), output buffers will have the
2426 * %GST_BUFFER_FLAG_GAP flag unset.
2428 * If set to %TRUE, the element must handle output buffers with this flag set
2429 * correctly, i.e. it can assume that the buffer contains neutral data but must
2430 * unset the flag if the output is no neutral data.
2437 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2439 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2441 GST_OBJECT_LOCK (trans);
2442 trans->priv->gap_aware = gap_aware;
2443 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2444 GST_OBJECT_UNLOCK (trans);
2448 * gst_base_transform_reconfigure_sink:
2449 * @trans: a #GstBaseTransform
2451 * Instructs @trans to request renegotiation upstream. This function is
2452 * typically called after properties on the transform were set that
2453 * influence the input format.
2456 gst_base_transform_reconfigure_sink (GstBaseTransform * trans)
2458 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2460 /* push the renegotiate event */
2461 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2462 gst_event_new_reconfigure ()))
2463 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2467 * gst_base_transform_reconfigure_src:
2468 * @trans: a #GstBaseTransform
2470 * Instructs @trans to renegotiate a new downstream transform on the next
2471 * buffer. This function is typically called after properties on the transform
2472 * were set that influence the output format.
2477 gst_base_transform_reconfigure_src (GstBaseTransform * trans)
2479 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2481 GST_OBJECT_LOCK (trans);
2482 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2483 trans->priv->reconfigure = TRUE;
2484 GST_OBJECT_UNLOCK (trans);