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 /* Set by sub-class */
237 gboolean passthrough;
238 gboolean always_in_place;
240 GstCaps *cache_caps1;
241 gsize cache_caps1_size;
242 GstCaps *cache_caps2;
243 gsize cache_caps2_size;
244 gboolean have_same_caps;
248 /* QoS *//* with LOCK */
249 gboolean qos_enabled;
251 GstClockTime earliest_time;
252 /* previous buffer had a discont */
259 gboolean reconfigure;
265 GstClockTime position_out;
268 gboolean pool_active;
269 GstAllocator *allocator;
270 GstAllocationParams params;
275 static GstElementClass *parent_class = NULL;
277 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
278 static void gst_base_transform_init (GstBaseTransform * trans,
279 GstBaseTransformClass * klass);
281 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
282 * method to get to the padtemplates */
284 gst_base_transform_get_type (void)
286 static volatile gsize base_transform_type = 0;
288 if (g_once_init_enter (&base_transform_type)) {
290 static const GTypeInfo base_transform_info = {
291 sizeof (GstBaseTransformClass),
294 (GClassInitFunc) gst_base_transform_class_init,
297 sizeof (GstBaseTransform),
299 (GInstanceInitFunc) gst_base_transform_init,
302 _type = g_type_register_static (GST_TYPE_ELEMENT,
303 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
304 g_once_init_leave (&base_transform_type, _type);
306 return base_transform_type;
309 static void gst_base_transform_finalize (GObject * object);
310 static void gst_base_transform_set_property (GObject * object, guint prop_id,
311 const GValue * value, GParamSpec * pspec);
312 static void gst_base_transform_get_property (GObject * object, guint prop_id,
313 GValue * value, GParamSpec * pspec);
314 static gboolean gst_base_transform_src_activate_mode (GstPad * pad,
315 GstObject * parent, GstPadMode mode, gboolean active);
316 static gboolean gst_base_transform_sink_activate_mode (GstPad * pad,
317 GstObject * parent, GstPadMode mode, gboolean active);
318 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
320 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
321 GstCaps * caps, gsize * size);
323 static gboolean gst_base_transform_src_event (GstPad * pad, GstObject * parent,
325 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
327 static gboolean gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
329 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
331 static GstFlowReturn gst_base_transform_getrange (GstPad * pad,
332 GstObject * parent, guint64 offset, guint length, GstBuffer ** buffer);
333 static GstFlowReturn gst_base_transform_chain (GstPad * pad, GstObject * parent,
335 static GstCaps *gst_base_transform_default_transform_caps (GstBaseTransform *
336 trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
337 static GstCaps *gst_base_transform_default_fixate_caps (GstBaseTransform *
338 trans, GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
339 static GstCaps *gst_base_transform_query_caps (GstBaseTransform * trans,
340 GstPad * pad, GstCaps * filter);
341 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
342 GstPadDirection direction, GstCaps * caps);
343 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
344 GstPad * pad, GstCaps * caps);
345 static gboolean gst_base_transform_default_decide_allocation (GstBaseTransform
346 * trans, GstQuery * query);
347 static gboolean gst_base_transform_default_propose_allocation (GstBaseTransform
348 * trans, GstQuery * decide_query, GstQuery * query);
349 static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent,
351 static gboolean gst_base_transform_default_query (GstBaseTransform * trans,
352 GstPadDirection direction, GstQuery * query);
353 static gboolean gst_base_transform_default_transform_size (GstBaseTransform *
354 trans, GstPadDirection direction, GstCaps * caps, gsize size,
355 GstCaps * othercaps, gsize * othersize);
357 static GstFlowReturn default_prepare_output_buffer (GstBaseTransform * trans,
358 GstBuffer * inbuf, GstBuffer ** outbuf);
359 static gboolean default_copy_metadata (GstBaseTransform * trans,
360 GstBuffer * inbuf, GstBuffer * outbuf);
362 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
366 gst_base_transform_finalize (GObject * object)
368 G_OBJECT_CLASS (parent_class)->finalize (object);
372 gst_base_transform_class_init (GstBaseTransformClass * klass)
374 GObjectClass *gobject_class;
376 gobject_class = G_OBJECT_CLASS (klass);
378 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
379 "basetransform element");
381 GST_DEBUG ("gst_base_transform_class_init");
383 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
385 parent_class = g_type_class_peek_parent (klass);
387 gobject_class->set_property = gst_base_transform_set_property;
388 gobject_class->get_property = gst_base_transform_get_property;
390 g_object_class_install_property (gobject_class, PROP_QOS,
391 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
392 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
394 gobject_class->finalize = gst_base_transform_finalize;
396 klass->passthrough_on_same_caps = FALSE;
397 klass->transform_ip_on_passthrough = TRUE;
399 klass->transform_caps =
400 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
402 GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate_caps);
404 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
405 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
406 klass->decide_allocation =
407 GST_DEBUG_FUNCPTR (gst_base_transform_default_decide_allocation);
408 klass->propose_allocation =
409 GST_DEBUG_FUNCPTR (gst_base_transform_default_propose_allocation);
410 klass->transform_size =
411 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
413 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
414 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
415 klass->prepare_output_buffer =
416 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
417 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
421 gst_base_transform_init (GstBaseTransform * trans,
422 GstBaseTransformClass * bclass)
424 GstPadTemplate *pad_template;
425 GstBaseTransformPrivate *priv;
427 GST_DEBUG ("gst_base_transform_init");
429 priv = trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
432 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
433 g_return_if_fail (pad_template != NULL);
434 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
435 gst_pad_set_event_function (trans->sinkpad,
436 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
437 gst_pad_set_chain_function (trans->sinkpad,
438 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
439 gst_pad_set_activatemode_function (trans->sinkpad,
440 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
441 gst_pad_set_query_function (trans->sinkpad,
442 GST_DEBUG_FUNCPTR (gst_base_transform_query));
443 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
446 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
447 g_return_if_fail (pad_template != NULL);
448 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
449 gst_pad_set_event_function (trans->srcpad,
450 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
451 gst_pad_set_getrange_function (trans->srcpad,
452 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
453 gst_pad_set_activatemode_function (trans->srcpad,
454 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
455 gst_pad_set_query_function (trans->srcpad,
456 GST_DEBUG_FUNCPTR (gst_base_transform_query));
457 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
459 priv->qos_enabled = DEFAULT_PROP_QOS;
460 priv->cache_caps1 = NULL;
461 priv->cache_caps2 = NULL;
462 priv->pad_mode = GST_PAD_MODE_NONE;
463 priv->gap_aware = FALSE;
465 priv->passthrough = FALSE;
466 if (bclass->transform == NULL) {
467 /* If no transform function, always_in_place is TRUE */
468 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
469 priv->always_in_place = TRUE;
471 if (bclass->transform_ip == NULL) {
472 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
473 priv->passthrough = TRUE;
482 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
483 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
487 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
488 /* no transform function, use the identity transform */
490 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
492 ret = gst_caps_ref (caps);
497 /* given @caps on the src or sink pad (given by @direction)
498 * calculate the possible caps on the other pad.
500 * Returns new caps, unref after usage.
503 gst_base_transform_transform_caps (GstBaseTransform * trans,
504 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
507 GstBaseTransformClass *klass;
512 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
514 /* if there is a custom transform function, use this */
515 if (klass->transform_caps) {
516 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
518 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
519 ret = klass->transform_caps (trans, direction, caps, filter);
520 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
522 #ifndef G_DISABLE_ASSERT
524 if (!gst_caps_is_subset (ret, filter)) {
525 GstCaps *intersection;
527 GST_ERROR_OBJECT (trans,
528 "transform_caps returned caps %" GST_PTR_FORMAT
529 " which are not a real subset of the filter caps %"
530 GST_PTR_FORMAT, ret, filter);
531 g_warning ("%s: transform_caps returned caps which are not a real "
532 "subset of the filter caps", GST_ELEMENT_NAME (trans));
535 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
536 gst_caps_unref (ret);
543 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
549 gst_base_transform_default_transform_size (GstBaseTransform * trans,
550 GstPadDirection direction, GstCaps * caps, gsize size,
551 GstCaps * othercaps, gsize * othersize)
553 gsize inunitsize, outunitsize, units;
554 GstBaseTransformClass *klass;
556 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
558 if (klass->get_unit_size == NULL) {
559 /* if there is no transform_size and no unit_size, it means the
560 * element does not modify the size of a buffer */
563 /* there is no transform_size function, we have to use the unit_size
564 * functions. This method assumes there is a fixed unit_size associated with
565 * each caps. We provide the same amount of units on both sides. */
566 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
569 GST_DEBUG_OBJECT (trans,
570 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
573 /* input size must be a multiple of the unit_size of the input caps */
574 if (inunitsize == 0 || (size % inunitsize != 0))
577 /* get the amount of units */
578 units = size / inunitsize;
580 /* now get the unit size of the output */
581 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
584 /* the output size is the unit_size times the amount of units on the
586 *othersize = units * outunitsize;
587 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
595 GST_DEBUG_OBJECT (trans, "could not get in_size");
596 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
601 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
602 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
603 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
604 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
609 GST_DEBUG_OBJECT (trans, "could not get out_size");
610 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
615 /* transform a buffer of @size with @caps on the pad with @direction to
616 * the size of a buffer with @othercaps and store the result in @othersize
618 * We have two ways of doing this:
619 * 1) use a custom transform size function, this is for complicated custom
620 * cases with no fixed unit_size.
621 * 2) use the unit_size functions where there is a relationship between the
622 * caps and the size of a buffer.
625 gst_base_transform_transform_size (GstBaseTransform * trans,
626 GstPadDirection direction, GstCaps * caps,
627 gsize size, GstCaps * othercaps, gsize * othersize)
629 GstBaseTransformClass *klass;
630 gboolean ret = FALSE;
632 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
634 GST_DEBUG_OBJECT (trans,
635 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
636 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
637 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
639 if (klass->transform_size) {
640 /* if there is a custom transform function, use this */
641 ret = klass->transform_size (trans, direction, caps, size, othercaps,
647 /* get the caps that can be handled by @pad. We perform:
649 * - take the caps of peer of otherpad,
650 * - filter against the padtemplate of otherpad,
651 * - calculate all transforms of remaining caps
652 * - filter against template of @pad
654 * If there is no peer, we simply return the caps of the padtemplate of pad.
657 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
661 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
662 GstCaps *templ, *otempl;
664 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
666 templ = gst_pad_get_pad_template_caps (pad);
667 otempl = gst_pad_get_pad_template_caps (otherpad);
669 /* we can do what the peer can */
671 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
673 /* filtered against our padtemplate on the other side */
674 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
675 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
676 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
678 /* then see what we can transform this to */
679 peerfilter = gst_base_transform_transform_caps (trans,
680 GST_PAD_DIRECTION (pad), temp, NULL);
681 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
682 gst_caps_unref (temp);
684 /* and filter against the template of this pad */
685 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
686 /* We keep the caps sorted like the returned caps */
688 gst_caps_intersect_full (peerfilter, otempl, GST_CAPS_INTERSECT_FIRST);
689 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
690 gst_caps_unref (peerfilter);
694 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
697 gst_caps_unref (peerfilter);
700 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
702 /* filtered against our padtemplate on the other side */
703 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
704 temp = gst_caps_intersect_full (peercaps, otempl, GST_CAPS_INTERSECT_FIRST);
705 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
707 temp = gst_caps_ref (otempl);
710 /* then see what we can transform this to */
711 caps = gst_base_transform_transform_caps (trans,
712 GST_PAD_DIRECTION (otherpad), temp, filter);
713 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
714 gst_caps_unref (temp);
719 /* and filter against the template of this pad */
720 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
721 /* We keep the caps sorted like the returned caps */
722 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
723 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
724 gst_caps_unref (caps);
727 /* Now try if we can put the untransformed downstream caps first */
728 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
729 if (!gst_caps_is_empty (temp)) {
730 caps = gst_caps_merge (temp, caps);
732 gst_caps_unref (temp);
735 gst_caps_unref (caps);
736 /* no peer or the peer can do anything, our padtemplate is enough then */
738 caps = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
740 caps = gst_caps_ref (templ);
745 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
748 gst_caps_unref (peercaps);
750 gst_caps_unref (templ);
751 gst_caps_unref (otempl);
756 /* takes ownership of the pool, allocator and query */
758 gst_base_transform_set_allocation (GstBaseTransform * trans,
759 GstBufferPool * pool, GstAllocator * allocator,
760 GstAllocationParams * params, GstQuery * query)
762 GstAllocator *oldalloc;
763 GstBufferPool *oldpool;
765 GstBaseTransformPrivate *priv = trans->priv;
767 GST_OBJECT_LOCK (trans);
768 oldpool = priv->pool;
770 priv->pool_active = FALSE;
772 oldalloc = priv->allocator;
773 priv->allocator = allocator;
775 oldquery = priv->query;
779 priv->params = *params;
781 gst_allocation_params_init (&priv->params);
782 GST_OBJECT_UNLOCK (trans);
785 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
786 gst_buffer_pool_set_active (oldpool, FALSE);
787 gst_object_unref (oldpool);
790 gst_allocator_unref (oldalloc);
793 gst_query_unref (oldquery);
800 gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
804 GstBaseTransformClass *klass;
806 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
808 n_metas = gst_query_get_n_allocation_metas (query);
809 for (i = 0; i < n_metas; i++) {
813 api = gst_query_parse_nth_allocation_meta (query, i);
815 /* by default we remove all metadata, subclasses should implement a
816 * filter_meta function */
817 if (gst_meta_api_type_has_tag (api, GST_META_TAG_MEMORY)) {
818 /* remove all memory dependent metadata because we are going to have to
819 * allocate different memory for input and output. */
820 GST_LOG_OBJECT (trans, "removing memory specific metadata %s",
823 } else if (G_LIKELY (klass->filter_meta)) {
824 /* remove if the subclass said so */
825 remove = !klass->filter_meta (trans, query, api);
826 GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s",
827 g_type_name (api), (remove ? "remove" : "keep"));
829 GST_LOG_OBJECT (trans, "removing metadata %s", g_type_name (api));
834 gst_query_remove_nth_allocation_meta (query, i);
843 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
846 gboolean result = TRUE;
848 guint size, min, max;
849 GstBaseTransformClass *klass;
850 GstBaseTransformPrivate *priv = trans->priv;
851 GstAllocator *allocator;
852 GstAllocationParams params;
854 /* there are these possibilities:
856 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
857 * will do that whenever some upstream does an allocation query.
858 * 2) we need to do a transform, we need to get a bufferpool from downstream
859 * and configure it. When upstream does the ALLOCATION query, the
860 * propose_allocation vmethod will be called and we will configure the
861 * upstream allocator with our proposed values then.
863 if (priv->passthrough || priv->always_in_place) {
864 /* we are in passthrough, the input buffer is never copied and always passed
865 * along. We never allocate an output buffer on the srcpad. What we do is
866 * let the upstream element decide if it wants to use a bufferpool and
867 * then we will proxy the downstream pool */
868 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
869 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
873 /* not passthrough, we need to allocate */
874 /* find a pool for the negotiated caps now */
875 GST_DEBUG_OBJECT (trans, "doing allocation query");
876 query = gst_query_new_allocation (outcaps, TRUE);
877 if (!gst_pad_peer_query (trans->srcpad, query)) {
878 /* not a problem, just debug a little */
879 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
882 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
884 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
885 if (G_LIKELY (klass->decide_allocation))
886 if ((result = klass->decide_allocation (trans, query)) == FALSE)
887 goto no_decide_allocation;
889 /* we got configuration from our peer or the decide_allocation method,
891 if (gst_query_get_n_allocation_params (query) > 0) {
892 /* try the allocator */
893 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
896 gst_allocation_params_init (¶ms);
899 if (gst_query_get_n_allocation_pools (query) > 0) {
900 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
903 /* no pool, just parameters, we can make our own */
904 GST_DEBUG_OBJECT (trans, "no pool, making new pool");
905 pool = gst_buffer_pool_new ();
909 size = min = max = 0;
914 GstStructure *config;
916 config = gst_buffer_pool_get_config (pool);
917 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
918 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
919 gst_buffer_pool_set_config (pool, config);
923 gst_base_transform_set_allocation (trans, pool, allocator, ¶ms,
929 no_decide_allocation:
931 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
932 gst_query_unref (query);
938 /* function triggered when the in and out caps are negotiated and need
939 * to be configured in the subclass. */
941 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
945 GstBaseTransformClass *klass;
946 GstBaseTransformPrivate *priv = trans->priv;
948 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
950 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
951 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
953 /* clear the cache */
954 gst_caps_replace (&priv->cache_caps1, NULL);
955 gst_caps_replace (&priv->cache_caps2, NULL);
957 /* figure out same caps state */
958 priv->have_same_caps = gst_caps_is_equal (in, out);
959 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", priv->have_same_caps);
961 /* Set the passthrough if the class wants passthrough_on_same_caps
962 * and we have the same caps on each pad */
963 if (klass->passthrough_on_same_caps)
964 gst_base_transform_set_passthrough (trans, priv->have_same_caps);
966 /* now configure the element with the caps */
967 if (klass->set_caps) {
968 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
969 ret = klass->set_caps (trans, in, out);
976 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
977 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
979 othercaps = gst_caps_fixate (othercaps);
980 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
985 /* given a fixed @caps on @pad, create the best possible caps for the
987 * @caps must be fixed when calling this function.
989 * This function calls the transform caps vmethod of the basetransform to figure
990 * out the possible target formats. It then tries to select the best format from
993 * - attempt passthrough if the target caps is a superset of the input caps
994 * - fixating by using peer caps
995 * - fixating with transform fixate function
996 * - fixating with pad fixate functions.
998 * this function returns a caps that can be transformed into and is accepted by
1002 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
1005 GstBaseTransformClass *klass;
1006 GstPad *otherpad, *otherpeer;
1010 /* caps must be fixed here, this is a programming error if it's not */
1011 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
1013 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1015 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1016 otherpeer = gst_pad_get_peer (otherpad);
1018 /* see how we can transform the input caps. We need to do this even for
1019 * passthrough because it might be possible that this element cannot support
1020 * passthrough at all. */
1021 othercaps = gst_base_transform_transform_caps (trans,
1022 GST_PAD_DIRECTION (pad), caps, NULL);
1024 /* The caps we can actually output is the intersection of the transformed
1025 * caps with the pad template for the pad */
1027 GstCaps *intersect, *templ_caps;
1029 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1030 GST_DEBUG_OBJECT (trans,
1031 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
1034 gst_caps_intersect_full (othercaps, templ_caps,
1035 GST_CAPS_INTERSECT_FIRST);
1037 gst_caps_unref (othercaps);
1038 gst_caps_unref (templ_caps);
1039 othercaps = intersect;
1042 /* check if transform is empty */
1043 if (!othercaps || gst_caps_is_empty (othercaps))
1046 /* if the othercaps are not fixed, we need to fixate them, first attempt
1047 * is by attempting passthrough if the othercaps are a superset of caps. */
1048 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1050 is_fixed = gst_caps_is_fixed (othercaps);
1052 GST_DEBUG_OBJECT (trans,
1053 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1055 /* Now let's see what the peer suggests based on our transformed caps */
1057 GstCaps *peercaps, *intersection, *templ_caps;
1059 GST_DEBUG_OBJECT (trans,
1060 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1062 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1063 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1064 if (!gst_caps_is_empty (peercaps)) {
1065 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1067 GST_DEBUG_OBJECT (trans,
1068 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1071 gst_caps_intersect_full (peercaps, templ_caps,
1072 GST_CAPS_INTERSECT_FIRST);
1073 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1075 gst_caps_unref (peercaps);
1076 gst_caps_unref (templ_caps);
1077 peercaps = intersection;
1079 GST_DEBUG_OBJECT (trans,
1080 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1082 gst_caps_intersect_full (peercaps, othercaps,
1083 GST_CAPS_INTERSECT_FIRST);
1084 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1086 gst_caps_unref (peercaps);
1087 gst_caps_unref (othercaps);
1088 othercaps = intersection;
1090 gst_caps_unref (othercaps);
1091 othercaps = peercaps;
1094 is_fixed = gst_caps_is_fixed (othercaps);
1096 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1097 gst_caps_unref (othercaps);
1098 othercaps = gst_caps_ref (caps);
1102 if (gst_caps_is_empty (othercaps))
1103 goto no_transform_possible;
1105 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1108 /* second attempt at fixation, call the fixate vmethod */
1109 /* caps could be fixed but the subclass may want to add fields */
1110 if (klass->fixate_caps) {
1111 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1112 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1113 GST_DEBUG_PAD_NAME (otherpad));
1114 /* note that we pass the complete array of structures to the fixate
1115 * function, it needs to truncate itself */
1117 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1118 is_fixed = gst_caps_is_fixed (othercaps);
1119 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1122 /* caps should be fixed now, if not we have to fail. */
1124 goto could_not_fixate;
1126 /* and peer should accept */
1127 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1128 goto peer_no_accept;
1130 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1131 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1134 gst_object_unref (otherpeer);
1141 GST_DEBUG_OBJECT (trans,
1142 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1145 no_transform_possible:
1147 GST_DEBUG_OBJECT (trans,
1148 "transform could not transform %" GST_PTR_FORMAT
1149 " in anything we support", caps);
1154 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1159 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1160 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1166 gst_object_unref (otherpeer);
1168 gst_caps_unref (othercaps);
1174 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1175 GstPadDirection direction, GstCaps * caps)
1179 GstCaps *othercaps = NULL;
1181 gboolean ret = TRUE;
1184 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1186 /* we need fixed caps for the check, fall back to the default implementation
1188 if (!gst_caps_is_fixed (caps))
1193 GST_DEBUG_OBJECT (trans, "accept caps %" GST_PTR_FORMAT, caps);
1195 /* get all the formats we can handle on this pad */
1196 if (direction == GST_PAD_SRC)
1197 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1199 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1202 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1203 goto no_transform_possible;
1206 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1208 /* intersect with the requested format */
1209 ret = gst_caps_is_subset (caps, allowed);
1210 gst_caps_unref (allowed);
1213 goto no_transform_possible;
1217 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1219 /* find best possible caps for the other pad as a way to see if we can
1220 * transform this caps. */
1221 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1222 if (!othercaps || gst_caps_is_empty (othercaps))
1223 goto no_transform_possible;
1225 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1231 /* We know it's always NULL since we never use it */
1233 gst_caps_unref (othercaps);
1239 no_transform_possible:
1241 GST_DEBUG_OBJECT (trans,
1242 "transform could not transform %" GST_PTR_FORMAT
1243 " in anything we support", caps);
1249 /* called when new caps arrive on the sink pad,
1250 * We try to find the best caps for the other side using our _find_transform()
1251 * function. If there are caps, we configure the transform for this new
1255 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1258 GstBaseTransformPrivate *priv = trans->priv;
1260 gboolean ret = TRUE;
1262 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1264 /* find best possible caps for the other pad */
1265 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1266 if (!outcaps || gst_caps_is_empty (outcaps))
1267 goto no_transform_possible;
1269 /* configure the element now */
1271 /* if we have the same caps, we can optimize and reuse the input caps */
1272 if (gst_caps_is_equal (incaps, outcaps)) {
1273 GST_INFO_OBJECT (trans, "reuse caps");
1274 gst_caps_unref (outcaps);
1275 outcaps = gst_caps_ref (incaps);
1278 /* call configure now */
1279 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1280 goto failed_configure;
1282 GST_OBJECT_LOCK (trans->sinkpad);
1283 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1284 trans->priv->reconfigure = FALSE;
1285 GST_OBJECT_UNLOCK (trans->sinkpad);
1287 /* let downstream know about our caps */
1288 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1291 /* try to get a pool when needed */
1292 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1297 gst_caps_unref (outcaps);
1299 GST_OBJECT_LOCK (trans);
1300 priv->negotiated = ret;
1301 GST_OBJECT_UNLOCK (trans);
1306 no_transform_possible:
1308 GST_WARNING_OBJECT (trans,
1309 "transform could not transform %" GST_PTR_FORMAT
1310 " in anything we support", incaps);
1316 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1317 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1324 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1325 GstQuery * decide_query, GstQuery * query)
1329 if (decide_query == NULL) {
1330 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1331 ret = gst_pad_peer_query (trans->srcpad, query);
1334 /* non-passthrough, copy all metadata, decide_query does not contain the
1335 * metadata anymore that depends on the buffer memory */
1336 n_metas = gst_query_get_n_allocation_metas (decide_query);
1337 for (i = 0; i < n_metas; i++) {
1340 api = gst_query_parse_nth_allocation_meta (decide_query, i);
1341 GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api));
1342 gst_query_add_allocation_meta (query, api);
1350 gst_base_transform_default_query (GstBaseTransform * trans,
1351 GstPadDirection direction, GstQuery * query)
1353 gboolean ret = FALSE;
1354 GstPad *pad, *otherpad;
1355 GstBaseTransformClass *klass;
1356 GstBaseTransformPrivate *priv = trans->priv;
1358 if (direction == GST_PAD_SRC) {
1359 pad = trans->srcpad;
1360 otherpad = trans->sinkpad;
1362 pad = trans->sinkpad;
1363 otherpad = trans->srcpad;
1366 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1368 switch (GST_QUERY_TYPE (query)) {
1369 case GST_QUERY_ALLOCATION:
1371 GstQuery *decide_query = NULL;
1372 gboolean negotiated;
1374 /* can only be done on the sinkpad */
1375 if (direction != GST_PAD_SINK)
1378 GST_OBJECT_LOCK (trans);
1379 if (G_UNLIKELY (!(negotiated = priv->negotiated))) {
1380 GST_DEBUG_OBJECT (trans,
1381 "not negotiated yet, can't answer ALLOCATION query");
1382 GST_OBJECT_UNLOCK (trans);
1385 if ((decide_query = trans->priv->query))
1386 gst_query_ref (decide_query);
1387 GST_OBJECT_UNLOCK (trans);
1389 GST_DEBUG_OBJECT (trans,
1390 "calling propose allocation with query %" GST_PTR_FORMAT,
1393 /* pass the query to the propose_allocation vmethod if any */
1394 if (G_LIKELY (klass->propose_allocation))
1395 ret = klass->propose_allocation (trans, decide_query, query);
1400 gst_query_unref (decide_query);
1402 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1406 case GST_QUERY_POSITION:
1410 gst_query_parse_position (query, &format, NULL);
1411 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1415 if ((direction == GST_PAD_SINK)
1416 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1418 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1419 trans->segment.position);
1421 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1422 trans->priv->position_out);
1424 gst_query_set_position (query, format, pos);
1426 ret = gst_pad_peer_query (otherpad, query);
1430 case GST_QUERY_ACCEPT_CAPS:
1434 gst_query_parse_accept_caps (query, &caps);
1435 if (klass->accept_caps) {
1436 ret = klass->accept_caps (trans, direction, caps);
1437 gst_query_set_accept_caps_result (query, ret);
1438 /* return TRUE, we answered the query */
1443 case GST_QUERY_CAPS:
1445 GstCaps *filter, *caps;
1447 gst_query_parse_caps (query, &filter);
1448 caps = gst_base_transform_query_caps (trans, pad, filter);
1449 gst_query_set_caps_result (query, caps);
1450 gst_caps_unref (caps);
1455 ret = gst_pad_peer_query (otherpad, query);
1464 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1466 GstBaseTransform *trans;
1467 GstBaseTransformClass *bclass;
1468 gboolean ret = FALSE;
1470 trans = GST_BASE_TRANSFORM (parent);
1471 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1474 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1479 /* this function either returns the input buffer without incrementing the
1480 * refcount or it allocates a new (writable) buffer */
1481 static GstFlowReturn
1482 default_prepare_output_buffer (GstBaseTransform * trans,
1483 GstBuffer * inbuf, GstBuffer ** outbuf)
1485 GstBaseTransformPrivate *priv;
1486 GstFlowReturn ret = GST_FLOW_OK;
1487 GstBaseTransformClass *bclass;
1488 GstCaps *incaps, *outcaps;
1489 gsize insize, outsize;
1493 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1495 /* figure out how to allocate an output buffer */
1496 if (priv->passthrough) {
1497 /* passthrough, we will not modify the incomming buffer so we can just
1499 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1504 /* we can't reuse the input buffer */
1506 if (!priv->pool_active) {
1507 GST_DEBUG_OBJECT (trans, "setting pool %p active", priv->pool);
1508 if (!gst_buffer_pool_set_active (priv->pool, TRUE))
1509 goto activate_failed;
1510 priv->pool_active = TRUE;
1512 GST_DEBUG_OBJECT (trans, "using pool alloc");
1513 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1517 /* no pool, we need to figure out the size of the output buffer first */
1518 if ((bclass->transform_ip != NULL) && priv->always_in_place) {
1519 /* we want to do an in-place alloc */
1520 if (gst_buffer_is_writable (inbuf)) {
1521 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1524 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1525 /* we make a copy of the input buffer */
1526 *outbuf = gst_buffer_copy (inbuf);
1531 /* else use the transform function to get the size */
1532 incaps = gst_pad_get_current_caps (trans->sinkpad);
1533 outcaps = gst_pad_get_current_caps (trans->srcpad);
1535 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1536 /* copy transform, figure out the output size */
1537 insize = gst_buffer_get_size (inbuf);
1538 res = gst_base_transform_transform_size (trans,
1539 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1541 gst_caps_unref (incaps);
1542 gst_caps_unref (outcaps);
1547 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1548 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, &priv->params);
1551 /* copy the metadata */
1552 if (bclass->copy_metadata)
1553 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1554 /* something failed, post a warning */
1555 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1556 ("could not copy metadata"), (NULL));
1566 GST_ELEMENT_ERROR (trans, RESOURCE, SETTINGS,
1567 ("failed to activate bufferpool"), ("failed to activate bufferpool"));
1568 return GST_FLOW_ERROR;
1572 GST_ERROR_OBJECT (trans, "unknown output size");
1573 return GST_FLOW_ERROR;
1579 GstBaseTransform *trans;
1584 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1586 CopyMetaData *data = user_data;
1587 GstBaseTransform *trans = data->trans;
1588 GstBaseTransformClass *klass;
1589 const GstMetaInfo *info = (*meta)->info;
1590 GstBuffer *outbuf = data->outbuf;
1593 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1595 if (GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
1596 /* never call the transform_meta with pool private metadata */
1597 GST_DEBUG_OBJECT (trans, "not copying pooled metadata %s",
1598 g_type_name (info->api));
1600 } else if (gst_meta_api_type_has_tag (info->api, GST_META_TAG_MEMORY)) {
1601 /* never call the transform_meta with memory specific metadata */
1602 GST_DEBUG_OBJECT (trans, "not copying memory specific metadata %s",
1603 g_type_name (info->api));
1605 } else if (klass->transform_meta) {
1606 do_copy = klass->transform_meta (trans, outbuf, *meta, inbuf);
1607 GST_DEBUG_OBJECT (trans, "transformed metadata %s: copy: %d",
1608 g_type_name (info->api), do_copy);
1611 GST_DEBUG_OBJECT (trans, "not copying metadata %s",
1612 g_type_name (info->api));
1615 /* we only copy metadata when the subclass implemented a transform_meta
1616 * function and when it returns TRUE */
1618 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1619 GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
1620 /* simply copy then */
1621 info->transform_func (outbuf, *meta, inbuf,
1622 _gst_meta_transform_copy, ©_data);
1628 default_copy_metadata (GstBaseTransform * trans,
1629 GstBuffer * inbuf, GstBuffer * outbuf)
1631 GstBaseTransformPrivate *priv = trans->priv;
1634 /* now copy the metadata */
1635 GST_DEBUG_OBJECT (trans, "copying metadata");
1637 /* this should not happen, buffers allocated from a pool or with
1638 * new_allocate should always be writable. */
1639 if (!gst_buffer_is_writable (outbuf))
1642 /* when we get here, the metadata should be writable */
1643 gst_buffer_copy_into (outbuf, inbuf,
1644 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1646 /* clear the GAP flag when the subclass does not understand it */
1647 if (!priv->gap_aware)
1648 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1652 data.outbuf = outbuf;
1654 gst_buffer_foreach_meta (inbuf, foreach_metadata, &data);
1661 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1666 /* Given @caps calcultate the size of one unit.
1668 * For video caps, this is the size of one frame (and thus one buffer).
1669 * For audio caps, this is the size of one sample.
1671 * These values are cached since they do not change and the calculation
1672 * potentially involves parsing caps and other expensive stuff.
1674 * We have two cache locations to store the size, one for the source caps
1675 * and one for the sink caps.
1677 * this function returns FALSE if no size could be calculated.
1680 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1683 gboolean res = FALSE;
1684 GstBaseTransformClass *bclass;
1685 GstBaseTransformPrivate *priv = trans->priv;
1687 /* see if we have the result cached */
1688 if (priv->cache_caps1 == caps) {
1689 *size = priv->cache_caps1_size;
1690 GST_DEBUG_OBJECT (trans,
1691 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1694 if (priv->cache_caps2 == caps) {
1695 *size = priv->cache_caps2_size;
1696 GST_DEBUG_OBJECT (trans,
1697 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1701 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1702 res = bclass->get_unit_size (trans, caps, size);
1703 GST_DEBUG_OBJECT (trans,
1704 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1705 caps, *size, res ? "TRUE" : "FALSE");
1708 /* and cache the values */
1709 if (priv->cache_caps1 == NULL) {
1710 gst_caps_replace (&priv->cache_caps1, caps);
1711 priv->cache_caps1_size = *size;
1712 GST_DEBUG_OBJECT (trans,
1713 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1714 } else if (priv->cache_caps2 == NULL) {
1715 gst_caps_replace (&priv->cache_caps2, caps);
1716 priv->cache_caps2_size = *size;
1717 GST_DEBUG_OBJECT (trans,
1718 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1720 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1727 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1730 GstBaseTransform *trans;
1731 GstBaseTransformClass *bclass;
1732 gboolean ret = TRUE;
1734 trans = GST_BASE_TRANSFORM (parent);
1735 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1737 if (bclass->sink_event)
1738 ret = bclass->sink_event (trans, event);
1740 gst_event_unref (event);
1746 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1748 gboolean ret = TRUE, forward = TRUE;
1749 GstBaseTransformPrivate *priv = trans->priv;
1751 switch (GST_EVENT_TYPE (event)) {
1752 case GST_EVENT_FLUSH_START:
1754 case GST_EVENT_FLUSH_STOP:
1755 GST_OBJECT_LOCK (trans);
1756 /* reset QoS parameters */
1757 priv->proportion = 1.0;
1758 priv->earliest_time = -1;
1759 priv->discont = FALSE;
1760 priv->processed = 0;
1762 GST_OBJECT_UNLOCK (trans);
1763 /* we need new segment info after the flush. */
1764 trans->have_segment = FALSE;
1765 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1766 priv->position_out = GST_CLOCK_TIME_NONE;
1772 case GST_EVENT_CAPS:
1776 gst_event_parse_caps (event, &caps);
1777 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1782 case GST_EVENT_SEGMENT:
1784 gst_event_copy_segment (event, &trans->segment);
1785 trans->have_segment = TRUE;
1787 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1796 ret = gst_pad_push_event (trans->srcpad, event);
1798 gst_event_unref (event);
1804 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1807 GstBaseTransform *trans;
1808 GstBaseTransformClass *bclass;
1809 gboolean ret = TRUE;
1811 trans = GST_BASE_TRANSFORM (parent);
1812 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1814 if (bclass->src_event)
1815 ret = bclass->src_event (trans, event);
1817 gst_event_unref (event);
1823 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1827 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1829 switch (GST_EVENT_TYPE (event)) {
1830 case GST_EVENT_SEEK:
1832 case GST_EVENT_NAVIGATION:
1837 GstClockTimeDiff diff;
1838 GstClockTime timestamp;
1840 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1841 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1848 ret = gst_pad_push_event (trans->sinkpad, event);
1853 /* perform a transform on @inbuf and put the result in @outbuf.
1855 * This function is common to the push and pull-based operations.
1857 * This function takes ownership of @inbuf */
1858 static GstFlowReturn
1859 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1860 GstBuffer ** outbuf)
1862 GstBaseTransformClass *bclass;
1863 GstBaseTransformPrivate *priv = trans->priv;
1864 GstFlowReturn ret = GST_FLOW_OK;
1865 gboolean want_in_place;
1866 GstClockTime running_time;
1867 GstClockTime timestamp;
1868 gboolean reconfigure;
1870 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1872 GST_OBJECT_LOCK (trans->sinkpad);
1873 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1874 || priv->reconfigure;
1875 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1876 priv->reconfigure = FALSE;
1877 GST_OBJECT_UNLOCK (trans->sinkpad);
1879 if (G_UNLIKELY (reconfigure)) {
1882 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1884 incaps = gst_pad_get_current_caps (trans->sinkpad);
1886 goto no_reconfigure;
1888 /* if we need to reconfigure we pretend new caps arrived. This
1889 * will reconfigure the transform with the new output format. */
1890 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1891 gst_caps_unref (incaps);
1892 goto not_negotiated;
1894 gst_caps_unref (incaps);
1898 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1899 GST_DEBUG_OBJECT (trans,
1900 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1901 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1902 GST_BUFFER_OFFSET (inbuf));
1904 GST_DEBUG_OBJECT (trans,
1905 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1906 gst_buffer_get_size (inbuf));
1908 /* Don't allow buffer handling before negotiation, except in passthrough mode
1909 * or if the class doesn't implement a set_caps function (in which case it doesn't
1912 if (!priv->negotiated && !priv->passthrough && (bclass->set_caps != NULL))
1913 goto not_negotiated;
1915 /* Set discont flag so we can mark the outgoing buffer */
1916 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1917 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1918 priv->discont = TRUE;
1921 /* can only do QoS if the segment is in TIME */
1922 if (trans->segment.format != GST_FORMAT_TIME)
1925 /* QOS is done on the running time of the buffer, get it now */
1926 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1927 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1930 if (running_time != -1) {
1932 GstClockTime earliest_time;
1935 /* lock for getting the QoS parameters that are set (in a different thread)
1936 * with the QOS events */
1937 GST_OBJECT_LOCK (trans);
1938 earliest_time = priv->earliest_time;
1939 proportion = priv->proportion;
1940 /* check for QoS, don't perform conversion for buffers
1941 * that are known to be late. */
1942 need_skip = priv->qos_enabled &&
1943 earliest_time != -1 && running_time <= earliest_time;
1944 GST_OBJECT_UNLOCK (trans);
1947 GstMessage *qos_msg;
1948 GstClockTime duration;
1949 guint64 stream_time;
1952 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1953 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1954 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1958 duration = GST_BUFFER_DURATION (inbuf);
1960 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1962 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1965 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1966 stream_time, timestamp, duration);
1967 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1968 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1969 priv->processed, priv->dropped);
1970 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1972 /* mark discont for next buffer */
1973 priv->discont = TRUE;
1980 /* first try to allocate an output buffer based on the currently negotiated
1981 * format. outbuf will contain a buffer suitable for doing the configured
1982 * transform after this function. */
1983 if (bclass->prepare_output_buffer == NULL)
1986 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1987 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1989 if (ret != GST_FLOW_OK || *outbuf == NULL)
1992 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1995 /* now perform the needed transform */
1996 if (priv->passthrough) {
1997 /* In passthrough mode, give transform_ip a look at the
1998 * buffer, without making it writable, or just push the
2000 if (bclass->transform_ip_on_passthrough && bclass->transform_ip) {
2001 GST_DEBUG_OBJECT (trans, "doing passthrough transform_ip");
2002 ret = bclass->transform_ip (trans, *outbuf);
2004 GST_DEBUG_OBJECT (trans, "element is in passthrough");
2007 want_in_place = (bclass->transform_ip != NULL) && priv->always_in_place;
2009 if (want_in_place) {
2010 GST_DEBUG_OBJECT (trans, "doing inplace transform");
2011 ret = bclass->transform_ip (trans, *outbuf);
2013 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
2015 if (bclass->transform)
2016 ret = bclass->transform (trans, inbuf, *outbuf);
2018 ret = GST_FLOW_NOT_SUPPORTED;
2023 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
2024 * the input buffer, no refcount is changed to keep the input buffer writable
2026 if (*outbuf != inbuf)
2027 gst_buffer_unref (inbuf);
2034 gst_buffer_unref (inbuf);
2036 GST_ELEMENT_ERROR (trans, STREAM, FORMAT,
2037 ("not negotiated"), ("not negotiated"));
2038 return GST_FLOW_NOT_NEGOTIATED;
2042 gst_buffer_unref (inbuf);
2043 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
2044 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
2045 return GST_FLOW_NOT_SUPPORTED;
2049 gst_buffer_unref (inbuf);
2051 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
2052 gst_flow_get_name (ret));
2057 /* FIXME, getrange is broken, need to pull range from the other
2058 * end based on the transform_size result.
2060 static GstFlowReturn
2061 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
2062 guint length, GstBuffer ** buffer)
2064 GstBaseTransform *trans;
2065 GstBaseTransformClass *klass;
2067 GstBuffer *inbuf = NULL;
2069 trans = GST_BASE_TRANSFORM (parent);
2071 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
2072 if (G_UNLIKELY (ret != GST_FLOW_OK))
2075 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2076 if (klass->before_transform)
2077 klass->before_transform (trans, inbuf);
2079 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
2087 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
2088 gst_flow_get_name (ret));
2093 static GstFlowReturn
2094 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2096 GstBaseTransform *trans;
2097 GstBaseTransformClass *klass;
2098 GstBaseTransformPrivate *priv;
2100 GstClockTime position = GST_CLOCK_TIME_NONE;
2101 GstClockTime timestamp, duration;
2102 GstBuffer *outbuf = NULL;
2104 trans = GST_BASE_TRANSFORM (parent);
2107 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2108 duration = GST_BUFFER_DURATION (buffer);
2110 /* calculate end position of the incoming buffer */
2111 if (timestamp != GST_CLOCK_TIME_NONE) {
2112 if (duration != GST_CLOCK_TIME_NONE)
2113 position = timestamp + duration;
2115 position = timestamp;
2118 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2119 if (klass->before_transform)
2120 klass->before_transform (trans, buffer);
2122 /* protect transform method and concurrent buffer alloc */
2123 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2125 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2126 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2127 if (outbuf != NULL) {
2128 if (ret == GST_FLOW_OK) {
2129 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2131 /* Remember last stop position */
2132 if (position != GST_CLOCK_TIME_NONE &&
2133 trans->segment.format == GST_FORMAT_TIME)
2134 trans->segment.position = position;
2136 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2137 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2138 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2139 position_out += GST_BUFFER_DURATION (outbuf);
2140 } else if (position != GST_CLOCK_TIME_NONE) {
2141 position_out = position;
2143 if (position_out != GST_CLOCK_TIME_NONE
2144 && trans->segment.format == GST_FORMAT_TIME)
2145 priv->position_out = position_out;
2147 /* apply DISCONT flag if the buffer is not yet marked as such */
2148 if (trans->priv->discont) {
2149 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2150 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2151 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2152 outbuf = gst_buffer_make_writable (outbuf);
2153 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2155 priv->discont = FALSE;
2159 ret = gst_pad_push (trans->srcpad, outbuf);
2161 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2162 gst_buffer_unref (outbuf);
2166 /* convert internal flow to OK and mark discont for the next buffer. */
2167 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2168 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2169 priv->discont = TRUE;
2177 gst_base_transform_set_property (GObject * object, guint prop_id,
2178 const GValue * value, GParamSpec * pspec)
2180 GstBaseTransform *trans;
2182 trans = GST_BASE_TRANSFORM (object);
2186 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2195 gst_base_transform_get_property (GObject * object, guint prop_id,
2196 GValue * value, GParamSpec * pspec)
2198 GstBaseTransform *trans;
2200 trans = GST_BASE_TRANSFORM (object);
2204 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2212 /* not a vmethod of anything, just an internal method */
2214 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2216 GstBaseTransformClass *bclass;
2217 GstBaseTransformPrivate *priv = trans->priv;
2218 gboolean result = TRUE;
2220 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2223 GstCaps *incaps, *outcaps;
2225 if (priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2226 result &= bclass->start (trans);
2228 incaps = gst_pad_get_current_caps (trans->sinkpad);
2229 outcaps = gst_pad_get_current_caps (trans->srcpad);
2231 GST_OBJECT_LOCK (trans);
2232 if (incaps && outcaps)
2233 priv->have_same_caps =
2234 gst_caps_is_equal (incaps, outcaps) || priv->passthrough;
2236 priv->have_same_caps = priv->passthrough;
2237 GST_DEBUG_OBJECT (trans, "have_same_caps %d", priv->have_same_caps);
2238 priv->negotiated = FALSE;
2239 trans->have_segment = FALSE;
2240 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2241 priv->position_out = GST_CLOCK_TIME_NONE;
2242 priv->proportion = 1.0;
2243 priv->earliest_time = -1;
2244 priv->discont = FALSE;
2245 priv->processed = 0;
2247 GST_OBJECT_UNLOCK (trans);
2250 gst_caps_unref (incaps);
2252 gst_caps_unref (outcaps);
2254 /* We must make sure streaming has finished before resetting things
2255 * and calling the ::stop vfunc */
2256 GST_PAD_STREAM_LOCK (trans->sinkpad);
2257 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2259 priv->have_same_caps = FALSE;
2260 /* We can only reset the passthrough mode if the instance told us to
2261 handle it in configure_caps */
2262 if (bclass->passthrough_on_same_caps) {
2263 gst_base_transform_set_passthrough (trans, FALSE);
2265 gst_caps_replace (&priv->cache_caps1, NULL);
2266 gst_caps_replace (&priv->cache_caps2, NULL);
2268 if (priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2269 result &= bclass->stop (trans);
2271 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
2278 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2279 GstPadMode mode, gboolean active)
2281 gboolean result = FALSE;
2282 GstBaseTransform *trans;
2284 trans = GST_BASE_TRANSFORM (parent);
2287 case GST_PAD_MODE_PUSH:
2289 result = gst_base_transform_activate (trans, active);
2292 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2304 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2305 GstPadMode mode, gboolean active)
2307 gboolean result = FALSE;
2308 GstBaseTransform *trans;
2310 trans = GST_BASE_TRANSFORM (parent);
2313 case GST_PAD_MODE_PULL:
2316 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2319 result &= gst_base_transform_activate (trans, active);
2322 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2334 * gst_base_transform_set_passthrough:
2335 * @trans: the #GstBaseTransform to set
2336 * @passthrough: boolean indicating passthrough mode.
2338 * Set passthrough mode for this filter by default. This is mostly
2339 * useful for filters that do not care about negotiation.
2341 * Always TRUE for filters which don't implement either a transform
2342 * or transform_ip method.
2347 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2348 gboolean passthrough)
2350 GstBaseTransformClass *bclass;
2352 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2354 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2356 GST_OBJECT_LOCK (trans);
2357 if (passthrough == FALSE) {
2358 if (bclass->transform_ip || bclass->transform)
2359 trans->priv->passthrough = FALSE;
2361 trans->priv->passthrough = TRUE;
2364 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->priv->passthrough);
2365 GST_OBJECT_UNLOCK (trans);
2369 * gst_base_transform_is_passthrough:
2370 * @trans: the #GstBaseTransform to query
2372 * See if @trans is configured as a passthrough transform.
2374 * Returns: TRUE is the transform is configured in passthrough mode.
2379 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2383 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2385 GST_OBJECT_LOCK (trans);
2386 result = trans->priv->passthrough;
2387 GST_OBJECT_UNLOCK (trans);
2393 * gst_base_transform_set_in_place:
2394 * @trans: the #GstBaseTransform to modify
2395 * @in_place: Boolean value indicating that we would like to operate
2396 * on in_place buffers.
2398 * Determines whether a non-writable buffer will be copied before passing
2399 * to the transform_ip function.
2401 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2402 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2408 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2410 GstBaseTransformClass *bclass;
2412 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2414 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2416 GST_OBJECT_LOCK (trans);
2419 if (bclass->transform_ip) {
2420 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2421 trans->priv->always_in_place = TRUE;
2424 if (bclass->transform) {
2425 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2426 trans->priv->always_in_place = FALSE;
2430 GST_OBJECT_UNLOCK (trans);
2434 * gst_base_transform_is_in_place:
2435 * @trans: the #GstBaseTransform to query
2437 * See if @trans is configured as a in_place transform.
2439 * Returns: TRUE is the transform is configured in in_place mode.
2444 gst_base_transform_is_in_place (GstBaseTransform * trans)
2448 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2450 GST_OBJECT_LOCK (trans);
2451 result = trans->priv->always_in_place;
2452 GST_OBJECT_UNLOCK (trans);
2458 * gst_base_transform_update_qos:
2459 * @trans: a #GstBaseTransform
2460 * @proportion: the proportion
2461 * @diff: the diff against the clock
2462 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2465 * Set the QoS parameters in the transform. This function is called internally
2466 * when a QOS event is received but subclasses can provide custom information
2474 gst_base_transform_update_qos (GstBaseTransform * trans,
2475 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2477 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2479 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2480 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2481 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2483 GST_OBJECT_LOCK (trans);
2484 trans->priv->proportion = proportion;
2485 trans->priv->earliest_time = timestamp + diff;
2486 GST_OBJECT_UNLOCK (trans);
2490 * gst_base_transform_set_qos_enabled:
2491 * @trans: a #GstBaseTransform
2492 * @enabled: new state
2494 * Enable or disable QoS handling in the transform.
2501 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2503 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2505 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2507 GST_OBJECT_LOCK (trans);
2508 trans->priv->qos_enabled = enabled;
2509 GST_OBJECT_UNLOCK (trans);
2513 * gst_base_transform_is_qos_enabled:
2514 * @trans: a #GstBaseTransform
2516 * Queries if the transform will handle QoS.
2518 * Returns: TRUE if QoS is enabled.
2525 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2529 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2531 GST_OBJECT_LOCK (trans);
2532 result = trans->priv->qos_enabled;
2533 GST_OBJECT_UNLOCK (trans);
2539 * gst_base_transform_set_gap_aware:
2540 * @trans: a #GstBaseTransform
2541 * @gap_aware: New state
2543 * If @gap_aware is %FALSE (the default), output buffers will have the
2544 * %GST_BUFFER_FLAG_GAP flag unset.
2546 * If set to %TRUE, the element must handle output buffers with this flag set
2547 * correctly, i.e. it can assume that the buffer contains neutral data but must
2548 * unset the flag if the output is no neutral data.
2555 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2557 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2559 GST_OBJECT_LOCK (trans);
2560 trans->priv->gap_aware = gap_aware;
2561 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2562 GST_OBJECT_UNLOCK (trans);
2566 * gst_base_transform_reconfigure_sink:
2567 * @trans: a #GstBaseTransform
2569 * Instructs @trans to request renegotiation upstream. This function is
2570 * typically called after properties on the transform were set that
2571 * influence the input format.
2574 gst_base_transform_reconfigure_sink (GstBaseTransform * trans)
2576 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2578 /* push the renegotiate event */
2579 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2580 gst_event_new_reconfigure ()))
2581 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2585 * gst_base_transform_reconfigure_src:
2586 * @trans: a #GstBaseTransform
2588 * Instructs @trans to renegotiate a new downstream transform on the next
2589 * buffer. This function is typically called after properties on the transform
2590 * were set that influence the output format.
2595 gst_base_transform_reconfigure_src (GstBaseTransform * trans)
2597 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2599 GST_OBJECT_LOCK (trans);
2600 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2601 trans->priv->reconfigure = TRUE;
2602 GST_OBJECT_UNLOCK (trans);