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 gboolean pool_active;
257 GstAllocator *allocator;
258 GstAllocationParams params;
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;
648 GstCaps *templ, *otempl;
650 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
652 templ = gst_pad_get_pad_template_caps (pad);
653 otempl = gst_pad_get_pad_template_caps (otherpad);
655 /* we can do what the peer can */
657 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
659 /* filtered against our padtemplate on the other side */
660 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
661 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
662 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
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 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
672 /* We keep the caps sorted like the returned caps */
674 gst_caps_intersect_full (peerfilter, otempl, GST_CAPS_INTERSECT_FIRST);
675 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
676 gst_caps_unref (peerfilter);
680 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
683 gst_caps_unref (peerfilter);
686 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
688 /* filtered against our padtemplate on the other side */
689 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
690 temp = gst_caps_intersect_full (peercaps, otempl, GST_CAPS_INTERSECT_FIRST);
691 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
693 temp = gst_caps_ref (otempl);
696 /* then see what we can transform this to */
697 caps = gst_base_transform_transform_caps (trans,
698 GST_PAD_DIRECTION (otherpad), temp, filter);
699 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
700 gst_caps_unref (temp);
705 /* and filter against the template of this pad */
706 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
707 /* We keep the caps sorted like the returned caps */
708 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
709 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
710 gst_caps_unref (caps);
713 /* Now try if we can put the untransformed downstream caps first */
714 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
715 if (!gst_caps_is_empty (temp)) {
716 caps = gst_caps_merge (temp, caps);
718 gst_caps_unref (temp);
721 gst_caps_unref (caps);
722 /* no peer or the peer can do anything, our padtemplate is enough then */
724 caps = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
726 caps = gst_caps_ref (templ);
731 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
734 gst_caps_unref (peercaps);
736 gst_caps_unref (templ);
737 gst_caps_unref (otempl);
742 /* takes ownership of the pool, allocator and query */
744 gst_base_transform_set_allocation (GstBaseTransform * trans,
745 GstBufferPool * pool, GstAllocator * allocator,
746 GstAllocationParams * params, GstQuery * query)
748 GstAllocator *oldalloc;
749 GstBufferPool *oldpool;
751 GstBaseTransformPrivate *priv = trans->priv;
753 GST_OBJECT_LOCK (trans);
754 oldpool = priv->pool;
756 priv->pool_active = FALSE;
758 oldalloc = priv->allocator;
759 priv->allocator = allocator;
761 oldquery = priv->query;
765 priv->params = *params;
767 gst_allocation_params_init (&priv->params);
768 GST_OBJECT_UNLOCK (trans);
771 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
772 gst_buffer_pool_set_active (oldpool, FALSE);
773 gst_object_unref (oldpool);
776 gst_allocator_unref (oldalloc);
779 gst_query_unref (oldquery);
786 gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
790 GstBaseTransformClass *klass;
792 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
794 n_metas = gst_query_get_n_allocation_metas (query);
795 for (i = 0; i < n_metas; i++) {
799 api = gst_query_parse_nth_allocation_meta (query, i);
801 /* by default we remove all metadata, subclasses should implement a
802 * filter_meta function */
803 if (gst_meta_api_type_has_tag (api, GST_META_TAG_MEMORY)) {
804 /* remove all memory dependent metadata because we are going to have to
805 * allocate different memory for input and output. */
806 GST_LOG_OBJECT (trans, "removing memory specific metadata %s",
809 } else if (G_LIKELY (klass->filter_meta)) {
810 /* remove if the subclass said so */
811 remove = !klass->filter_meta (trans, query, api);
812 GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s",
813 g_type_name (api), (remove ? "remove" : "keep"));
815 GST_LOG_OBJECT (trans, "removing metadata %s", g_type_name (api));
820 gst_query_remove_nth_allocation_meta (query, i);
829 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
832 gboolean result = TRUE;
834 guint size, min, max;
835 GstBaseTransformClass *klass;
836 GstAllocator *allocator;
837 GstAllocationParams params;
839 /* there are these possibilities:
841 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
842 * will do that whenever some upstream does an allocation query.
843 * 2) we need to do a transform, we need to get a bufferpool from downstream
844 * and configure it. When upstream does the ALLOCATION query, the
845 * propose_allocation vmethod will be called and we will configure the
846 * upstream allocator with our proposed values then.
848 if (trans->passthrough || trans->always_in_place) {
849 /* we are in passthrough, the input buffer is never copied and always passed
850 * along. We never allocate an output buffer on the srcpad. What we do is
851 * let the upstream element decide if it wants to use a bufferpool and
852 * then we will proxy the downstream pool */
853 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
854 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
858 /* not passthrough, we need to allocate */
859 /* find a pool for the negotiated caps now */
860 GST_DEBUG_OBJECT (trans, "doing allocation query");
861 query = gst_query_new_allocation (outcaps, TRUE);
862 if (!gst_pad_peer_query (trans->srcpad, query)) {
863 /* not a problem, just debug a little */
864 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
867 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
869 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
870 if (G_LIKELY (klass->decide_allocation))
871 if ((result = klass->decide_allocation (trans, query)) == FALSE)
872 goto no_decide_allocation;
874 /* we got configuration from our peer or the decide_allocation method,
876 if (gst_query_get_n_allocation_params (query) > 0) {
877 /* try the allocator */
878 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
881 gst_allocation_params_init (¶ms);
884 if (gst_query_get_n_allocation_pools (query) > 0) {
885 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
888 /* no pool, just parameters, we can make our own */
889 GST_DEBUG_OBJECT (trans, "no pool, making new pool");
890 pool = gst_buffer_pool_new ();
894 size = min = max = 0;
899 GstStructure *config;
901 config = gst_buffer_pool_get_config (pool);
902 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
903 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
904 gst_buffer_pool_set_config (pool, config);
908 gst_base_transform_set_allocation (trans, pool, allocator, ¶ms,
914 no_decide_allocation:
916 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
917 gst_query_unref (query);
923 /* function triggered when the in and out caps are negotiated and need
924 * to be configured in the subclass. */
926 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
930 GstBaseTransformClass *klass;
932 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
934 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
935 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
937 /* clear the cache */
938 gst_caps_replace (&trans->cache_caps1, NULL);
939 gst_caps_replace (&trans->cache_caps2, NULL);
941 /* figure out same caps state */
942 trans->have_same_caps = gst_caps_is_equal (in, out);
943 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
945 /* If we've a transform_ip method and same input/output caps, set in_place
946 * by default. If for some reason the sub-class prefers using a transform
947 * function, it can clear the in place flag in the set_caps */
948 gst_base_transform_set_in_place (trans,
949 klass->transform_ip && trans->have_same_caps);
951 /* Set the passthrough if the class wants passthrough_on_same_caps
952 * and we have the same caps on each pad */
953 if (klass->passthrough_on_same_caps)
954 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
956 /* now configure the element with the caps */
957 if (klass->set_caps) {
958 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
959 ret = klass->set_caps (trans, in, out);
962 trans->negotiated = ret;
968 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
969 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
971 othercaps = gst_caps_fixate (othercaps);
972 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
977 /* given a fixed @caps on @pad, create the best possible caps for the
979 * @caps must be fixed when calling this function.
981 * This function calls the transform caps vmethod of the basetransform to figure
982 * out the possible target formats. It then tries to select the best format from
985 * - attempt passthrough if the target caps is a superset of the input caps
986 * - fixating by using peer caps
987 * - fixating with transform fixate function
988 * - fixating with pad fixate functions.
990 * this function returns a caps that can be transformed into and is accepted by
994 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
997 GstBaseTransformClass *klass;
998 GstPad *otherpad, *otherpeer;
1002 /* caps must be fixed here, this is a programming error if it's not */
1003 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
1005 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1007 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1008 otherpeer = gst_pad_get_peer (otherpad);
1010 /* see how we can transform the input caps. We need to do this even for
1011 * passthrough because it might be possible that this element cannot support
1012 * passthrough at all. */
1013 othercaps = gst_base_transform_transform_caps (trans,
1014 GST_PAD_DIRECTION (pad), caps, NULL);
1016 /* The caps we can actually output is the intersection of the transformed
1017 * caps with the pad template for the pad */
1019 GstCaps *intersect, *templ_caps;
1021 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1022 GST_DEBUG_OBJECT (trans,
1023 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
1026 gst_caps_intersect_full (othercaps, templ_caps,
1027 GST_CAPS_INTERSECT_FIRST);
1029 gst_caps_unref (othercaps);
1030 gst_caps_unref (templ_caps);
1031 othercaps = intersect;
1034 /* check if transform is empty */
1035 if (!othercaps || gst_caps_is_empty (othercaps))
1038 /* if the othercaps are not fixed, we need to fixate them, first attempt
1039 * is by attempting passthrough if the othercaps are a superset of caps. */
1040 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1042 is_fixed = gst_caps_is_fixed (othercaps);
1044 GST_DEBUG_OBJECT (trans,
1045 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1047 /* Now let's see what the peer suggests based on our transformed caps */
1049 GstCaps *peercaps, *intersection, *templ_caps;
1051 GST_DEBUG_OBJECT (trans,
1052 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1054 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1055 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1056 if (!gst_caps_is_empty (peercaps)) {
1057 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1059 GST_DEBUG_OBJECT (trans,
1060 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1063 gst_caps_intersect_full (peercaps, templ_caps,
1064 GST_CAPS_INTERSECT_FIRST);
1065 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1067 gst_caps_unref (peercaps);
1068 gst_caps_unref (templ_caps);
1069 peercaps = intersection;
1071 GST_DEBUG_OBJECT (trans,
1072 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1074 gst_caps_intersect_full (peercaps, othercaps,
1075 GST_CAPS_INTERSECT_FIRST);
1076 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1078 gst_caps_unref (peercaps);
1079 gst_caps_unref (othercaps);
1080 othercaps = intersection;
1082 othercaps = peercaps;
1085 is_fixed = gst_caps_is_fixed (othercaps);
1087 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1088 gst_caps_unref (othercaps);
1089 othercaps = gst_caps_ref (caps);
1093 if (gst_caps_is_empty (othercaps))
1094 goto no_transform_possible;
1096 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1099 /* second attempt at fixation, call the fixate vmethod */
1100 /* caps could be fixed but the subclass may want to add fields */
1101 if (klass->fixate_caps) {
1102 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1103 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1104 GST_DEBUG_PAD_NAME (otherpad));
1105 /* note that we pass the complete array of structures to the fixate
1106 * function, it needs to truncate itself */
1108 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1109 is_fixed = gst_caps_is_fixed (othercaps);
1110 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1113 /* caps should be fixed now, if not we have to fail. */
1115 goto could_not_fixate;
1117 /* and peer should accept */
1118 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1119 goto peer_no_accept;
1121 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1122 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1125 gst_object_unref (otherpeer);
1132 GST_DEBUG_OBJECT (trans,
1133 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1136 no_transform_possible:
1138 GST_DEBUG_OBJECT (trans,
1139 "transform could not transform %" GST_PTR_FORMAT
1140 " in anything we support", caps);
1145 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1150 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1151 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1157 gst_object_unref (otherpeer);
1159 gst_caps_unref (othercaps);
1165 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1166 GstPadDirection direction, GstCaps * caps)
1170 GstCaps *othercaps = NULL;
1172 gboolean ret = TRUE;
1175 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1177 /* we need fixed caps for the check, fall back to the default implementation
1179 if (!gst_caps_is_fixed (caps))
1184 GST_DEBUG_OBJECT (trans, "accept caps %" GST_PTR_FORMAT, caps);
1186 /* get all the formats we can handle on this pad */
1187 if (direction == GST_PAD_SRC)
1188 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1190 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1193 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1194 goto no_transform_possible;
1197 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1199 /* intersect with the requested format */
1200 ret = gst_caps_is_subset (caps, allowed);
1201 gst_caps_unref (allowed);
1204 goto no_transform_possible;
1208 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1210 /* find best possible caps for the other pad as a way to see if we can
1211 * transform this caps. */
1212 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1213 if (!othercaps || gst_caps_is_empty (othercaps))
1214 goto no_transform_possible;
1216 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1222 /* We know it's always NULL since we never use it */
1224 gst_caps_unref (othercaps);
1230 no_transform_possible:
1232 GST_DEBUG_OBJECT (trans,
1233 "transform could not transform %" GST_PTR_FORMAT
1234 " in anything we support", caps);
1240 /* called when new caps arrive on the sink pad,
1241 * We try to find the best caps for the other side using our _find_transform()
1242 * function. If there are caps, we configure the transform for this new
1246 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1250 gboolean ret = TRUE;
1252 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1254 /* find best possible caps for the other pad */
1255 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1256 if (!outcaps || gst_caps_is_empty (outcaps))
1257 goto no_transform_possible;
1259 /* configure the element now */
1261 /* if we have the same caps, we can optimize and reuse the input caps */
1262 if (gst_caps_is_equal (incaps, outcaps)) {
1263 GST_INFO_OBJECT (trans, "reuse caps");
1264 gst_caps_unref (outcaps);
1265 outcaps = gst_caps_ref (incaps);
1268 /* call configure now */
1269 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1270 goto failed_configure;
1272 GST_OBJECT_LOCK (trans->sinkpad);
1273 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1274 trans->priv->reconfigure = FALSE;
1275 GST_OBJECT_UNLOCK (trans->sinkpad);
1277 /* we know this will work, we implement the setcaps */
1278 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1281 /* try to get a pool when needed */
1282 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1287 gst_caps_unref (outcaps);
1289 trans->negotiated = ret;
1294 no_transform_possible:
1296 GST_WARNING_OBJECT (trans,
1297 "transform could not transform %" GST_PTR_FORMAT
1298 " in anything we support", incaps);
1304 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1305 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1312 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1313 GstQuery * decide_query, GstQuery * query)
1317 if (decide_query == NULL) {
1318 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1319 ret = gst_pad_peer_query (trans->srcpad, query);
1322 /* non-passthrough, copy all metadata, decide_query does not contain the
1323 * metadata anymore that depends on the buffer memory */
1324 n_metas = gst_query_get_n_allocation_metas (decide_query);
1325 for (i = 0; i < n_metas; i++) {
1328 api = gst_query_parse_nth_allocation_meta (decide_query, i);
1329 GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api));
1330 gst_query_add_allocation_meta (query, api);
1338 gst_base_transform_default_query (GstBaseTransform * trans,
1339 GstPadDirection direction, GstQuery * query)
1341 gboolean ret = FALSE;
1342 GstPad *pad, *otherpad;
1343 GstBaseTransformClass *klass;
1345 if (direction == GST_PAD_SRC) {
1346 pad = trans->srcpad;
1347 otherpad = trans->sinkpad;
1349 pad = trans->sinkpad;
1350 otherpad = trans->srcpad;
1353 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1355 switch (GST_QUERY_TYPE (query)) {
1356 case GST_QUERY_ALLOCATION:
1358 GstQuery *decide_query = NULL;
1359 gboolean negotiated;
1361 /* can only be done on the sinkpad */
1362 if (direction != GST_PAD_SINK)
1365 GST_OBJECT_LOCK (trans);
1366 if (G_UNLIKELY (!(negotiated = trans->negotiated))) {
1367 GST_DEBUG_OBJECT (trans,
1368 "not negotiated yet, can't answer ALLOCATION query");
1369 GST_OBJECT_UNLOCK (trans);
1372 if ((decide_query = trans->priv->query))
1373 gst_query_ref (decide_query);
1374 GST_OBJECT_UNLOCK (trans);
1376 GST_DEBUG_OBJECT (trans,
1377 "calling propose allocation with query %" GST_PTR_FORMAT,
1380 /* pass the query to the propose_allocation vmethod if any */
1381 if (G_LIKELY (klass->propose_allocation))
1382 ret = klass->propose_allocation (trans, decide_query, query);
1387 gst_query_unref (decide_query);
1389 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1393 case GST_QUERY_POSITION:
1397 gst_query_parse_position (query, &format, NULL);
1398 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1402 if ((direction == GST_PAD_SINK)
1403 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1405 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1406 trans->segment.position);
1408 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1409 trans->priv->position_out);
1411 gst_query_set_position (query, format, pos);
1413 ret = gst_pad_peer_query (otherpad, query);
1417 case GST_QUERY_ACCEPT_CAPS:
1421 gst_query_parse_accept_caps (query, &caps);
1422 if (klass->accept_caps) {
1423 ret = klass->accept_caps (trans, direction, caps);
1424 gst_query_set_accept_caps_result (query, ret);
1425 /* return TRUE, we answered the query */
1430 case GST_QUERY_CAPS:
1432 GstCaps *filter, *caps;
1434 gst_query_parse_caps (query, &filter);
1435 caps = gst_base_transform_query_caps (trans, pad, filter);
1436 gst_query_set_caps_result (query, caps);
1437 gst_caps_unref (caps);
1442 ret = gst_pad_peer_query (otherpad, query);
1451 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1453 GstBaseTransform *trans;
1454 GstBaseTransformClass *bclass;
1455 gboolean ret = FALSE;
1457 trans = GST_BASE_TRANSFORM (parent);
1458 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1461 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1466 /* this function either returns the input buffer without incrementing the
1467 * refcount or it allocates a new (writable) buffer */
1468 static GstFlowReturn
1469 default_prepare_output_buffer (GstBaseTransform * trans,
1470 GstBuffer * inbuf, GstBuffer ** outbuf)
1472 GstBaseTransformPrivate *priv;
1473 GstFlowReturn ret = GST_FLOW_OK;
1474 GstBaseTransformClass *bclass;
1475 GstCaps *incaps, *outcaps;
1476 gsize insize, outsize;
1480 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1482 /* figure out how to allocate an output buffer */
1483 if (trans->passthrough) {
1484 /* passthrough, we will not modify the incomming buffer so we can just
1486 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1491 /* we can't reuse the input buffer */
1493 if (!priv->pool_active) {
1494 GST_DEBUG_OBJECT (trans, "setting pool %p active", priv->pool);
1495 if (!gst_buffer_pool_set_active (priv->pool, TRUE))
1496 goto activate_failed;
1497 priv->pool_active = TRUE;
1499 GST_DEBUG_OBJECT (trans, "using pool alloc");
1500 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1504 /* no pool, we need to figure out the size of the output buffer first */
1505 if ((bclass->transform_ip != NULL) && trans->always_in_place) {
1506 /* we want to do an in-place alloc */
1507 if (gst_buffer_is_writable (inbuf)) {
1508 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1511 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1512 /* we make a copy of the input buffer */
1513 *outbuf = gst_buffer_copy (inbuf);
1518 /* else use the transform function to get the size */
1519 incaps = gst_pad_get_current_caps (trans->sinkpad);
1520 outcaps = gst_pad_get_current_caps (trans->srcpad);
1522 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1523 /* copy transform, figure out the output size */
1524 insize = gst_buffer_get_size (inbuf);
1525 res = gst_base_transform_transform_size (trans,
1526 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1528 gst_caps_unref (incaps);
1529 gst_caps_unref (outcaps);
1534 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1535 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, &priv->params);
1538 /* copy the metadata */
1539 if (bclass->copy_metadata)
1540 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1541 /* something failed, post a warning */
1542 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1543 ("could not copy metadata"), (NULL));
1553 GST_ELEMENT_ERROR (trans, RESOURCE, SETTINGS,
1554 ("failed to activate bufferpool"), ("failed to activate bufferpool"));
1555 return GST_FLOW_ERROR;
1559 GST_ERROR_OBJECT (trans, "unknown output size");
1560 return GST_FLOW_ERROR;
1566 GstBaseTransform *trans;
1571 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1573 CopyMetaData *data = user_data;
1574 GstBaseTransform *trans = data->trans;
1575 GstBaseTransformClass *klass;
1576 const GstMetaInfo *info = (*meta)->info;
1577 GstBuffer *outbuf = data->outbuf;
1580 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1582 if (GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
1583 /* never call the transform_meta with pool private metadata */
1584 GST_DEBUG_OBJECT (trans, "not copying pooled metadata %s",
1585 g_type_name (info->api));
1587 } else if (gst_meta_api_type_has_tag (info->api, GST_META_TAG_MEMORY)) {
1588 /* never call the transform_meta with memory specific metadata */
1589 GST_DEBUG_OBJECT (trans, "not copying memory specific metadata %s",
1590 g_type_name (info->api));
1592 } else if (klass->transform_meta) {
1593 do_copy = klass->transform_meta (trans, outbuf, *meta, inbuf);
1594 GST_DEBUG_OBJECT (trans, "transformed metadata %s: copy: %d",
1595 g_type_name (info->api), do_copy);
1598 GST_DEBUG_OBJECT (trans, "not copying metadata %s",
1599 g_type_name (info->api));
1602 /* we only copy metadata when the subclass implemented a transform_meta
1603 * function and when it returns TRUE */
1605 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1606 GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
1607 /* simply copy then */
1608 info->transform_func (outbuf, *meta, inbuf,
1609 _gst_meta_transform_copy, ©_data);
1615 default_copy_metadata (GstBaseTransform * trans,
1616 GstBuffer * inbuf, GstBuffer * outbuf)
1618 GstBaseTransformPrivate *priv = trans->priv;
1621 /* now copy the metadata */
1622 GST_DEBUG_OBJECT (trans, "copying metadata");
1624 /* this should not happen, buffers allocated from a pool or with
1625 * new_allocate should always be writable. */
1626 if (!gst_buffer_is_writable (outbuf))
1629 /* when we get here, the metadata should be writable */
1630 gst_buffer_copy_into (outbuf, inbuf,
1631 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1633 /* clear the GAP flag when the subclass does not understand it */
1634 if (!priv->gap_aware)
1635 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1639 data.outbuf = outbuf;
1641 gst_buffer_foreach_meta (inbuf, foreach_metadata, &data);
1648 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1653 /* Given @caps calcultate the size of one unit.
1655 * For video caps, this is the size of one frame (and thus one buffer).
1656 * For audio caps, this is the size of one sample.
1658 * These values are cached since they do not change and the calculation
1659 * potentially involves parsing caps and other expensive stuff.
1661 * We have two cache locations to store the size, one for the source caps
1662 * and one for the sink caps.
1664 * this function returns FALSE if no size could be calculated.
1667 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1670 gboolean res = FALSE;
1671 GstBaseTransformClass *bclass;
1673 /* see if we have the result cached */
1674 if (trans->cache_caps1 == caps) {
1675 *size = trans->cache_caps1_size;
1676 GST_DEBUG_OBJECT (trans,
1677 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1680 if (trans->cache_caps2 == caps) {
1681 *size = trans->cache_caps2_size;
1682 GST_DEBUG_OBJECT (trans,
1683 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1687 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1688 res = bclass->get_unit_size (trans, caps, size);
1689 GST_DEBUG_OBJECT (trans,
1690 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1691 caps, *size, res ? "TRUE" : "FALSE");
1694 /* and cache the values */
1695 if (trans->cache_caps1 == NULL) {
1696 gst_caps_replace (&trans->cache_caps1, caps);
1697 trans->cache_caps1_size = *size;
1698 GST_DEBUG_OBJECT (trans,
1699 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1700 } else if (trans->cache_caps2 == NULL) {
1701 gst_caps_replace (&trans->cache_caps2, caps);
1702 trans->cache_caps2_size = *size;
1703 GST_DEBUG_OBJECT (trans,
1704 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1706 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1713 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1716 GstBaseTransform *trans;
1717 GstBaseTransformClass *bclass;
1718 gboolean ret = TRUE;
1720 trans = GST_BASE_TRANSFORM (parent);
1721 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1723 if (bclass->sink_event)
1724 ret = bclass->sink_event (trans, event);
1726 gst_event_unref (event);
1732 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1734 gboolean ret = TRUE, forward = TRUE;
1736 switch (GST_EVENT_TYPE (event)) {
1737 case GST_EVENT_FLUSH_START:
1739 case GST_EVENT_FLUSH_STOP:
1740 GST_OBJECT_LOCK (trans);
1741 /* reset QoS parameters */
1742 trans->priv->proportion = 1.0;
1743 trans->priv->earliest_time = -1;
1744 trans->priv->discont = FALSE;
1745 trans->priv->processed = 0;
1746 trans->priv->dropped = 0;
1747 GST_OBJECT_UNLOCK (trans);
1748 /* we need new segment info after the flush. */
1749 trans->have_segment = FALSE;
1750 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1751 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1757 case GST_EVENT_CAPS:
1761 gst_event_parse_caps (event, &caps);
1762 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1767 case GST_EVENT_SEGMENT:
1769 gst_event_copy_segment (event, &trans->segment);
1770 trans->have_segment = TRUE;
1772 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1781 ret = gst_pad_push_event (trans->srcpad, event);
1783 gst_event_unref (event);
1789 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1792 GstBaseTransform *trans;
1793 GstBaseTransformClass *bclass;
1794 gboolean ret = TRUE;
1796 trans = GST_BASE_TRANSFORM (parent);
1797 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1799 if (bclass->src_event)
1800 ret = bclass->src_event (trans, event);
1802 gst_event_unref (event);
1808 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1812 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1814 switch (GST_EVENT_TYPE (event)) {
1815 case GST_EVENT_SEEK:
1817 case GST_EVENT_NAVIGATION:
1822 GstClockTimeDiff diff;
1823 GstClockTime timestamp;
1825 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1826 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1833 ret = gst_pad_push_event (trans->sinkpad, event);
1838 /* perform a transform on @inbuf and put the result in @outbuf.
1840 * This function is common to the push and pull-based operations.
1842 * This function takes ownership of @inbuf */
1843 static GstFlowReturn
1844 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1845 GstBuffer ** outbuf)
1847 GstBaseTransformClass *bclass;
1848 GstFlowReturn ret = GST_FLOW_OK;
1849 gboolean want_in_place;
1850 GstClockTime running_time;
1851 GstClockTime timestamp;
1852 gboolean reconfigure;
1854 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1856 GST_OBJECT_LOCK (trans->sinkpad);
1857 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1858 || trans->priv->reconfigure;
1859 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1860 trans->priv->reconfigure = FALSE;
1861 GST_OBJECT_UNLOCK (trans->sinkpad);
1863 if (G_UNLIKELY (reconfigure)) {
1866 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1868 incaps = gst_pad_get_current_caps (trans->sinkpad);
1870 goto no_reconfigure;
1872 /* if we need to reconfigure we pretend new caps arrived. This
1873 * will reconfigure the transform with the new output format. */
1874 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1875 gst_caps_unref (incaps);
1876 goto not_negotiated;
1878 gst_caps_unref (incaps);
1882 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1883 GST_DEBUG_OBJECT (trans,
1884 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1885 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1886 GST_BUFFER_OFFSET (inbuf));
1888 GST_DEBUG_OBJECT (trans,
1889 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1890 gst_buffer_get_size (inbuf));
1892 /* Don't allow buffer handling before negotiation, except in passthrough mode
1893 * or if the class doesn't implement a set_caps function (in which case it doesn't
1896 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1897 goto not_negotiated;
1899 /* Set discont flag so we can mark the outgoing buffer */
1900 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1901 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1902 trans->priv->discont = TRUE;
1905 /* can only do QoS if the segment is in TIME */
1906 if (trans->segment.format != GST_FORMAT_TIME)
1909 /* QOS is done on the running time of the buffer, get it now */
1910 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1911 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1914 if (running_time != -1) {
1916 GstClockTime earliest_time;
1919 /* lock for getting the QoS parameters that are set (in a different thread)
1920 * with the QOS events */
1921 GST_OBJECT_LOCK (trans);
1922 earliest_time = trans->priv->earliest_time;
1923 proportion = trans->priv->proportion;
1924 /* check for QoS, don't perform conversion for buffers
1925 * that are known to be late. */
1926 need_skip = trans->priv->qos_enabled &&
1927 earliest_time != -1 && running_time <= earliest_time;
1928 GST_OBJECT_UNLOCK (trans);
1931 GstMessage *qos_msg;
1932 GstClockTime duration;
1933 guint64 stream_time;
1936 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1937 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1938 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1940 trans->priv->dropped++;
1942 duration = GST_BUFFER_DURATION (inbuf);
1944 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1946 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1949 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1950 stream_time, timestamp, duration);
1951 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1952 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1953 trans->priv->processed, trans->priv->dropped);
1954 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1956 /* mark discont for next buffer */
1957 trans->priv->discont = TRUE;
1964 /* first try to allocate an output buffer based on the currently negotiated
1965 * format. outbuf will contain a buffer suitable for doing the configured
1966 * transform after this function. */
1967 if (bclass->prepare_output_buffer == NULL)
1970 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1971 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1973 if (ret != GST_FLOW_OK || *outbuf == NULL)
1976 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1979 /* now perform the needed transform */
1980 if (trans->passthrough) {
1981 /* In passthrough mode, give transform_ip a look at the
1982 * buffer, without making it writable, or just push the
1984 if (bclass->transform_ip) {
1985 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1986 ret = bclass->transform_ip (trans, *outbuf);
1988 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1991 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1993 if (want_in_place) {
1994 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1995 ret = bclass->transform_ip (trans, *outbuf);
1997 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1999 if (bclass->transform)
2000 ret = bclass->transform (trans, inbuf, *outbuf);
2002 ret = GST_FLOW_NOT_SUPPORTED;
2007 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
2008 * the input buffer, no refcount is changed to keep the input buffer writable
2010 if (*outbuf != inbuf)
2011 gst_buffer_unref (inbuf);
2018 gst_buffer_unref (inbuf);
2020 GST_ELEMENT_ERROR (trans, STREAM, FORMAT,
2021 ("not negotiated"), ("not negotiated"));
2022 return GST_FLOW_NOT_NEGOTIATED;
2026 gst_buffer_unref (inbuf);
2027 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
2028 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
2029 return GST_FLOW_NOT_SUPPORTED;
2033 gst_buffer_unref (inbuf);
2035 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
2036 gst_flow_get_name (ret));
2041 /* FIXME, getrange is broken, need to pull range from the other
2042 * end based on the transform_size result.
2044 static GstFlowReturn
2045 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
2046 guint length, GstBuffer ** buffer)
2048 GstBaseTransform *trans;
2049 GstBaseTransformClass *klass;
2053 trans = GST_BASE_TRANSFORM (parent);
2055 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
2056 if (G_UNLIKELY (ret != GST_FLOW_OK))
2059 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2060 if (klass->before_transform)
2061 klass->before_transform (trans, inbuf);
2063 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
2071 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
2072 gst_flow_get_name (ret));
2077 static GstFlowReturn
2078 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2080 GstBaseTransform *trans;
2081 GstBaseTransformClass *klass;
2083 GstClockTime position = GST_CLOCK_TIME_NONE;
2084 GstClockTime timestamp, duration;
2085 GstBuffer *outbuf = NULL;
2087 trans = GST_BASE_TRANSFORM (parent);
2089 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2090 duration = GST_BUFFER_DURATION (buffer);
2092 /* calculate end position of the incoming buffer */
2093 if (timestamp != GST_CLOCK_TIME_NONE) {
2094 if (duration != GST_CLOCK_TIME_NONE)
2095 position = timestamp + duration;
2097 position = timestamp;
2100 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2101 if (klass->before_transform)
2102 klass->before_transform (trans, buffer);
2104 /* protect transform method and concurrent buffer alloc */
2105 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2107 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2108 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2109 if (outbuf != NULL) {
2110 if (ret == GST_FLOW_OK) {
2111 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2113 /* Remember last stop position */
2114 if (position != GST_CLOCK_TIME_NONE &&
2115 trans->segment.format == GST_FORMAT_TIME)
2116 trans->segment.position = position;
2118 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2119 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2120 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2121 position_out += GST_BUFFER_DURATION (outbuf);
2122 } else if (position != GST_CLOCK_TIME_NONE) {
2123 position_out = position;
2125 if (position_out != GST_CLOCK_TIME_NONE
2126 && trans->segment.format == GST_FORMAT_TIME)
2127 trans->priv->position_out = position_out;
2129 /* apply DISCONT flag if the buffer is not yet marked as such */
2130 if (trans->priv->discont) {
2131 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2132 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2133 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2134 outbuf = gst_buffer_make_writable (outbuf);
2135 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2137 trans->priv->discont = FALSE;
2139 trans->priv->processed++;
2141 ret = gst_pad_push (trans->srcpad, outbuf);
2143 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2144 gst_buffer_unref (outbuf);
2148 /* convert internal flow to OK and mark discont for the next buffer. */
2149 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2150 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2151 trans->priv->discont = TRUE;
2159 gst_base_transform_set_property (GObject * object, guint prop_id,
2160 const GValue * value, GParamSpec * pspec)
2162 GstBaseTransform *trans;
2164 trans = GST_BASE_TRANSFORM (object);
2168 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2177 gst_base_transform_get_property (GObject * object, guint prop_id,
2178 GValue * value, GParamSpec * pspec)
2180 GstBaseTransform *trans;
2182 trans = GST_BASE_TRANSFORM (object);
2186 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2194 /* not a vmethod of anything, just an internal method */
2196 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2198 GstBaseTransformClass *bclass;
2199 gboolean result = TRUE;
2201 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2204 GstCaps *incaps, *outcaps;
2206 if (trans->priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2207 result &= bclass->start (trans);
2209 incaps = gst_pad_get_current_caps (trans->sinkpad);
2210 outcaps = gst_pad_get_current_caps (trans->srcpad);
2212 GST_OBJECT_LOCK (trans);
2213 if (incaps && outcaps)
2214 trans->have_same_caps =
2215 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2217 trans->have_same_caps = trans->passthrough;
2218 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2219 trans->negotiated = FALSE;
2220 trans->have_segment = FALSE;
2221 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2222 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2223 trans->priv->proportion = 1.0;
2224 trans->priv->earliest_time = -1;
2225 trans->priv->discont = FALSE;
2226 trans->priv->processed = 0;
2227 trans->priv->dropped = 0;
2228 GST_OBJECT_UNLOCK (trans);
2231 gst_caps_unref (incaps);
2233 gst_caps_unref (outcaps);
2235 /* We must make sure streaming has finished before resetting things
2236 * and calling the ::stop vfunc */
2237 GST_PAD_STREAM_LOCK (trans->sinkpad);
2238 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2240 trans->have_same_caps = FALSE;
2241 /* We can only reset the passthrough mode if the instance told us to
2242 handle it in configure_caps */
2243 if (bclass->passthrough_on_same_caps) {
2244 gst_base_transform_set_passthrough (trans, FALSE);
2246 gst_caps_replace (&trans->cache_caps1, NULL);
2247 gst_caps_replace (&trans->cache_caps2, NULL);
2249 if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2250 result &= bclass->stop (trans);
2252 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
2259 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2260 GstPadMode mode, gboolean active)
2262 gboolean result = FALSE;
2263 GstBaseTransform *trans;
2265 trans = GST_BASE_TRANSFORM (parent);
2268 case GST_PAD_MODE_PUSH:
2270 result = gst_base_transform_activate (trans, active);
2273 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2285 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2286 GstPadMode mode, gboolean active)
2288 gboolean result = FALSE;
2289 GstBaseTransform *trans;
2291 trans = GST_BASE_TRANSFORM (parent);
2294 case GST_PAD_MODE_PULL:
2297 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2300 result &= gst_base_transform_activate (trans, active);
2303 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2315 * gst_base_transform_set_passthrough:
2316 * @trans: the #GstBaseTransform to set
2317 * @passthrough: boolean indicating passthrough mode.
2319 * Set passthrough mode for this filter by default. This is mostly
2320 * useful for filters that do not care about negotiation.
2322 * Always TRUE for filters which don't implement either a transform
2323 * or transform_ip method.
2328 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2329 gboolean passthrough)
2331 GstBaseTransformClass *bclass;
2333 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2335 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2337 GST_OBJECT_LOCK (trans);
2338 if (passthrough == FALSE) {
2339 if (bclass->transform_ip || bclass->transform)
2340 trans->passthrough = FALSE;
2342 trans->passthrough = TRUE;
2345 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2346 GST_OBJECT_UNLOCK (trans);
2350 * gst_base_transform_is_passthrough:
2351 * @trans: the #GstBaseTransform to query
2353 * See if @trans is configured as a passthrough transform.
2355 * Returns: TRUE is the transform is configured in passthrough mode.
2360 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2364 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2366 GST_OBJECT_LOCK (trans);
2367 result = trans->passthrough;
2368 GST_OBJECT_UNLOCK (trans);
2374 * gst_base_transform_set_in_place:
2375 * @trans: the #GstBaseTransform to modify
2376 * @in_place: Boolean value indicating that we would like to operate
2377 * on in_place buffers.
2379 * Determines whether a non-writable buffer will be copied before passing
2380 * to the transform_ip function.
2382 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2383 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2389 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2391 GstBaseTransformClass *bclass;
2393 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2395 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2397 GST_OBJECT_LOCK (trans);
2400 if (bclass->transform_ip) {
2401 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2402 trans->always_in_place = TRUE;
2405 if (bclass->transform) {
2406 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2407 trans->always_in_place = FALSE;
2411 GST_OBJECT_UNLOCK (trans);
2415 * gst_base_transform_is_in_place:
2416 * @trans: the #GstBaseTransform to query
2418 * See if @trans is configured as a in_place transform.
2420 * Returns: TRUE is the transform is configured in in_place mode.
2425 gst_base_transform_is_in_place (GstBaseTransform * trans)
2429 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2431 GST_OBJECT_LOCK (trans);
2432 result = trans->always_in_place;
2433 GST_OBJECT_UNLOCK (trans);
2439 * gst_base_transform_update_qos:
2440 * @trans: a #GstBaseTransform
2441 * @proportion: the proportion
2442 * @diff: the diff against the clock
2443 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2446 * Set the QoS parameters in the transform. This function is called internally
2447 * when a QOS event is received but subclasses can provide custom information
2455 gst_base_transform_update_qos (GstBaseTransform * trans,
2456 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2459 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2461 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2462 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2463 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2465 GST_OBJECT_LOCK (trans);
2466 trans->priv->proportion = proportion;
2467 trans->priv->earliest_time = timestamp + diff;
2468 GST_OBJECT_UNLOCK (trans);
2472 * gst_base_transform_set_qos_enabled:
2473 * @trans: a #GstBaseTransform
2474 * @enabled: new state
2476 * Enable or disable QoS handling in the transform.
2483 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2485 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2487 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2489 GST_OBJECT_LOCK (trans);
2490 trans->priv->qos_enabled = enabled;
2491 GST_OBJECT_UNLOCK (trans);
2495 * gst_base_transform_is_qos_enabled:
2496 * @trans: a #GstBaseTransform
2498 * Queries if the transform will handle QoS.
2500 * Returns: TRUE if QoS is enabled.
2507 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2511 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2513 GST_OBJECT_LOCK (trans);
2514 result = trans->priv->qos_enabled;
2515 GST_OBJECT_UNLOCK (trans);
2521 * gst_base_transform_set_gap_aware:
2522 * @trans: a #GstBaseTransform
2523 * @gap_aware: New state
2525 * If @gap_aware is %FALSE (the default), output buffers will have the
2526 * %GST_BUFFER_FLAG_GAP flag unset.
2528 * If set to %TRUE, the element must handle output buffers with this flag set
2529 * correctly, i.e. it can assume that the buffer contains neutral data but must
2530 * unset the flag if the output is no neutral data.
2537 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2539 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2541 GST_OBJECT_LOCK (trans);
2542 trans->priv->gap_aware = gap_aware;
2543 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2544 GST_OBJECT_UNLOCK (trans);
2548 * gst_base_transform_reconfigure_sink:
2549 * @trans: a #GstBaseTransform
2551 * Instructs @trans to request renegotiation upstream. This function is
2552 * typically called after properties on the transform were set that
2553 * influence the input format.
2556 gst_base_transform_reconfigure_sink (GstBaseTransform * trans)
2558 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2560 /* push the renegotiate event */
2561 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2562 gst_event_new_reconfigure ()))
2563 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2567 * gst_base_transform_reconfigure_src:
2568 * @trans: a #GstBaseTransform
2570 * Instructs @trans to renegotiate a new downstream transform on the next
2571 * buffer. This function is typically called after properties on the transform
2572 * were set that influence the output format.
2577 gst_base_transform_reconfigure_src (GstBaseTransform * trans)
2579 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2581 GST_OBJECT_LOCK (trans);
2582 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2583 trans->priv->reconfigure = TRUE;
2584 GST_OBJECT_UNLOCK (trans);