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;
398 klass->transform_caps =
399 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_caps);
401 GST_DEBUG_FUNCPTR (gst_base_transform_default_fixate_caps);
403 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
404 klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query);
405 klass->decide_allocation =
406 GST_DEBUG_FUNCPTR (gst_base_transform_default_decide_allocation);
407 klass->propose_allocation =
408 GST_DEBUG_FUNCPTR (gst_base_transform_default_propose_allocation);
409 klass->transform_size =
410 GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size);
412 klass->sink_event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
413 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
414 klass->prepare_output_buffer =
415 GST_DEBUG_FUNCPTR (default_prepare_output_buffer);
416 klass->copy_metadata = GST_DEBUG_FUNCPTR (default_copy_metadata);
420 gst_base_transform_init (GstBaseTransform * trans,
421 GstBaseTransformClass * bclass)
423 GstPadTemplate *pad_template;
424 GstBaseTransformPrivate *priv;
426 GST_DEBUG ("gst_base_transform_init");
428 priv = trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
431 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
432 g_return_if_fail (pad_template != NULL);
433 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
434 gst_pad_set_event_function (trans->sinkpad,
435 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
436 gst_pad_set_chain_function (trans->sinkpad,
437 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
438 gst_pad_set_activatemode_function (trans->sinkpad,
439 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_mode));
440 gst_pad_set_query_function (trans->sinkpad,
441 GST_DEBUG_FUNCPTR (gst_base_transform_query));
442 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
445 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
446 g_return_if_fail (pad_template != NULL);
447 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
448 gst_pad_set_event_function (trans->srcpad,
449 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
450 gst_pad_set_getrange_function (trans->srcpad,
451 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
452 gst_pad_set_activatemode_function (trans->srcpad,
453 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_mode));
454 gst_pad_set_query_function (trans->srcpad,
455 GST_DEBUG_FUNCPTR (gst_base_transform_query));
456 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
458 priv->qos_enabled = DEFAULT_PROP_QOS;
459 priv->cache_caps1 = NULL;
460 priv->cache_caps2 = NULL;
461 priv->pad_mode = GST_PAD_MODE_NONE;
462 priv->gap_aware = FALSE;
464 priv->passthrough = FALSE;
465 if (bclass->transform == NULL) {
466 /* If no transform function, always_in_place is TRUE */
467 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
468 priv->always_in_place = TRUE;
470 if (bclass->transform_ip == NULL) {
471 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
472 priv->passthrough = TRUE;
481 gst_base_transform_default_transform_caps (GstBaseTransform * trans,
482 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
486 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
487 /* no transform function, use the identity transform */
489 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
491 ret = gst_caps_ref (caps);
496 /* given @caps on the src or sink pad (given by @direction)
497 * calculate the possible caps on the other pad.
499 * Returns new caps, unref after usage.
502 gst_base_transform_transform_caps (GstBaseTransform * trans,
503 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
506 GstBaseTransformClass *klass;
511 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
513 /* if there is a custom transform function, use this */
514 if (klass->transform_caps) {
515 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
517 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
518 ret = klass->transform_caps (trans, direction, caps, filter);
519 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
521 #ifndef G_DISABLE_ASSERT
523 if (!gst_caps_is_subset (ret, filter)) {
524 GstCaps *intersection;
526 GST_ERROR_OBJECT (trans,
527 "transform_caps returned caps %" GST_PTR_FORMAT
528 " which are not a real subset of the filter caps %"
529 GST_PTR_FORMAT, ret, filter);
530 g_warning ("%s: transform_caps returned caps which are not a real "
531 "subset of the filter caps", GST_ELEMENT_NAME (trans));
534 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
535 gst_caps_unref (ret);
542 GST_DEBUG_OBJECT (trans, "to: %" GST_PTR_FORMAT, ret);
548 gst_base_transform_default_transform_size (GstBaseTransform * trans,
549 GstPadDirection direction, GstCaps * caps, gsize size,
550 GstCaps * othercaps, gsize * othersize)
552 gsize inunitsize, outunitsize, units;
553 GstBaseTransformClass *klass;
555 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
557 if (klass->get_unit_size == NULL) {
558 /* if there is no transform_size and no unit_size, it means the
559 * element does not modify the size of a buffer */
562 /* there is no transform_size function, we have to use the unit_size
563 * functions. This method assumes there is a fixed unit_size associated with
564 * each caps. We provide the same amount of units on both sides. */
565 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
568 GST_DEBUG_OBJECT (trans,
569 "input size %" G_GSIZE_FORMAT ", input unit size %" G_GSIZE_FORMAT,
572 /* input size must be a multiple of the unit_size of the input caps */
573 if (inunitsize == 0 || (size % inunitsize != 0))
576 /* get the amount of units */
577 units = size / inunitsize;
579 /* now get the unit size of the output */
580 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
583 /* the output size is the unit_size times the amount of units on the
585 *othersize = units * outunitsize;
586 GST_DEBUG_OBJECT (trans, "transformed size to %" G_GSIZE_FORMAT,
594 GST_DEBUG_OBJECT (trans, "could not get in_size");
595 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
600 GST_DEBUG_OBJECT (trans, "Size %" G_GSIZE_FORMAT " is not a multiple of"
601 "unit size %" G_GSIZE_FORMAT, size, inunitsize);
602 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
603 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
608 GST_DEBUG_OBJECT (trans, "could not get out_size");
609 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
614 /* transform a buffer of @size with @caps on the pad with @direction to
615 * the size of a buffer with @othercaps and store the result in @othersize
617 * We have two ways of doing this:
618 * 1) use a custom transform size function, this is for complicated custom
619 * cases with no fixed unit_size.
620 * 2) use the unit_size functions where there is a relationship between the
621 * caps and the size of a buffer.
624 gst_base_transform_transform_size (GstBaseTransform * trans,
625 GstPadDirection direction, GstCaps * caps,
626 gsize size, GstCaps * othercaps, gsize * othersize)
628 GstBaseTransformClass *klass;
629 gboolean ret = FALSE;
631 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
633 GST_DEBUG_OBJECT (trans,
634 "asked to transform size %" G_GSIZE_FORMAT " for caps %"
635 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
636 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
638 if (klass->transform_size) {
639 /* if there is a custom transform function, use this */
640 ret = klass->transform_size (trans, direction, caps, size, othercaps,
646 /* get the caps that can be handled by @pad. We perform:
648 * - take the caps of peer of otherpad,
649 * - filter against the padtemplate of otherpad,
650 * - calculate all transforms of remaining caps
651 * - filter against template of @pad
653 * If there is no peer, we simply return the caps of the padtemplate of pad.
656 gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
660 GstCaps *peercaps, *caps, *temp, *peerfilter = NULL;
661 GstCaps *templ, *otempl;
663 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
665 templ = gst_pad_get_pad_template_caps (pad);
666 otempl = gst_pad_get_pad_template_caps (otherpad);
668 /* we can do what the peer can */
670 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
672 /* filtered against our padtemplate on the other side */
673 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
674 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
675 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
677 /* then see what we can transform this to */
678 peerfilter = gst_base_transform_transform_caps (trans,
679 GST_PAD_DIRECTION (pad), temp, NULL);
680 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
681 gst_caps_unref (temp);
683 /* and filter against the template of this pad */
684 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
685 /* We keep the caps sorted like the returned caps */
687 gst_caps_intersect_full (peerfilter, otempl, GST_CAPS_INTERSECT_FIRST);
688 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
689 gst_caps_unref (peerfilter);
693 peercaps = gst_pad_peer_query_caps (otherpad, peerfilter);
696 gst_caps_unref (peerfilter);
699 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
701 /* filtered against our padtemplate on the other side */
702 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, otempl);
703 temp = gst_caps_intersect_full (peercaps, otempl, GST_CAPS_INTERSECT_FIRST);
704 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
706 temp = gst_caps_ref (otempl);
709 /* then see what we can transform this to */
710 caps = gst_base_transform_transform_caps (trans,
711 GST_PAD_DIRECTION (otherpad), temp, filter);
712 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
713 gst_caps_unref (temp);
718 /* and filter against the template of this pad */
719 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
720 /* We keep the caps sorted like the returned caps */
721 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
722 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
723 gst_caps_unref (caps);
726 /* Now try if we can put the untransformed downstream caps first */
727 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
728 if (!gst_caps_is_empty (temp)) {
729 caps = gst_caps_merge (temp, caps);
731 gst_caps_unref (temp);
734 gst_caps_unref (caps);
735 /* no peer or the peer can do anything, our padtemplate is enough then */
737 caps = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
739 caps = gst_caps_ref (templ);
744 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
747 gst_caps_unref (peercaps);
749 gst_caps_unref (templ);
750 gst_caps_unref (otempl);
755 /* takes ownership of the pool, allocator and query */
757 gst_base_transform_set_allocation (GstBaseTransform * trans,
758 GstBufferPool * pool, GstAllocator * allocator,
759 GstAllocationParams * params, GstQuery * query)
761 GstAllocator *oldalloc;
762 GstBufferPool *oldpool;
764 GstBaseTransformPrivate *priv = trans->priv;
766 GST_OBJECT_LOCK (trans);
767 oldpool = priv->pool;
769 priv->pool_active = FALSE;
771 oldalloc = priv->allocator;
772 priv->allocator = allocator;
774 oldquery = priv->query;
778 priv->params = *params;
780 gst_allocation_params_init (&priv->params);
781 GST_OBJECT_UNLOCK (trans);
784 GST_DEBUG_OBJECT (trans, "deactivating old pool %p", oldpool);
785 gst_buffer_pool_set_active (oldpool, FALSE);
786 gst_object_unref (oldpool);
789 gst_allocator_unref (oldalloc);
792 gst_query_unref (oldquery);
799 gst_base_transform_default_decide_allocation (GstBaseTransform * trans,
803 GstBaseTransformClass *klass;
805 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
807 n_metas = gst_query_get_n_allocation_metas (query);
808 for (i = 0; i < n_metas; i++) {
812 api = gst_query_parse_nth_allocation_meta (query, i);
814 /* by default we remove all metadata, subclasses should implement a
815 * filter_meta function */
816 if (gst_meta_api_type_has_tag (api, GST_META_TAG_MEMORY)) {
817 /* remove all memory dependent metadata because we are going to have to
818 * allocate different memory for input and output. */
819 GST_LOG_OBJECT (trans, "removing memory specific metadata %s",
822 } else if (G_LIKELY (klass->filter_meta)) {
823 /* remove if the subclass said so */
824 remove = !klass->filter_meta (trans, query, api);
825 GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s",
826 g_type_name (api), (remove ? "remove" : "keep"));
828 GST_LOG_OBJECT (trans, "removing metadata %s", g_type_name (api));
833 gst_query_remove_nth_allocation_meta (query, i);
842 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
845 gboolean result = TRUE;
847 guint size, min, max;
848 GstBaseTransformClass *klass;
849 GstBaseTransformPrivate *priv = trans->priv;
850 GstAllocator *allocator;
851 GstAllocationParams params;
853 /* there are these possibilities:
855 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
856 * will do that whenever some upstream does an allocation query.
857 * 2) we need to do a transform, we need to get a bufferpool from downstream
858 * and configure it. When upstream does the ALLOCATION query, the
859 * propose_allocation vmethod will be called and we will configure the
860 * upstream allocator with our proposed values then.
862 if (priv->passthrough || priv->always_in_place) {
863 /* we are in passthrough, the input buffer is never copied and always passed
864 * along. We never allocate an output buffer on the srcpad. What we do is
865 * let the upstream element decide if it wants to use a bufferpool and
866 * then we will proxy the downstream pool */
867 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
868 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
872 /* not passthrough, we need to allocate */
873 /* find a pool for the negotiated caps now */
874 GST_DEBUG_OBJECT (trans, "doing allocation query");
875 query = gst_query_new_allocation (outcaps, TRUE);
876 if (!gst_pad_peer_query (trans->srcpad, query)) {
877 /* not a problem, just debug a little */
878 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
881 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
883 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
884 if (G_LIKELY (klass->decide_allocation))
885 if ((result = klass->decide_allocation (trans, query)) == FALSE)
886 goto no_decide_allocation;
888 /* we got configuration from our peer or the decide_allocation method,
890 if (gst_query_get_n_allocation_params (query) > 0) {
891 /* try the allocator */
892 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
895 gst_allocation_params_init (¶ms);
898 if (gst_query_get_n_allocation_pools (query) > 0) {
899 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
902 /* no pool, just parameters, we can make our own */
903 GST_DEBUG_OBJECT (trans, "no pool, making new pool");
904 pool = gst_buffer_pool_new ();
908 size = min = max = 0;
913 GstStructure *config;
915 config = gst_buffer_pool_get_config (pool);
916 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
917 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
918 gst_buffer_pool_set_config (pool, config);
922 gst_base_transform_set_allocation (trans, pool, allocator, ¶ms,
928 no_decide_allocation:
930 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
931 gst_query_unref (query);
937 /* function triggered when the in and out caps are negotiated and need
938 * to be configured in the subclass. */
940 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
944 GstBaseTransformClass *klass;
945 GstBaseTransformPrivate *priv = trans->priv;
947 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
949 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
950 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
952 /* clear the cache */
953 gst_caps_replace (&priv->cache_caps1, NULL);
954 gst_caps_replace (&priv->cache_caps2, NULL);
956 /* figure out same caps state */
957 priv->have_same_caps = gst_caps_is_equal (in, out);
958 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", priv->have_same_caps);
960 /* If we've a transform_ip method and same input/output caps, set in_place
961 * by default. If for some reason the sub-class prefers using a transform
962 * function, it can clear the in place flag in the set_caps */
963 gst_base_transform_set_in_place (trans,
964 klass->transform_ip && priv->have_same_caps);
966 /* Set the passthrough if the class wants passthrough_on_same_caps
967 * and we have the same caps on each pad */
968 if (klass->passthrough_on_same_caps)
969 gst_base_transform_set_passthrough (trans, priv->have_same_caps);
971 /* now configure the element with the caps */
972 if (klass->set_caps) {
973 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
974 ret = klass->set_caps (trans, in, out);
981 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
982 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
984 othercaps = gst_caps_fixate (othercaps);
985 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
990 /* given a fixed @caps on @pad, create the best possible caps for the
992 * @caps must be fixed when calling this function.
994 * This function calls the transform caps vmethod of the basetransform to figure
995 * out the possible target formats. It then tries to select the best format from
998 * - attempt passthrough if the target caps is a superset of the input caps
999 * - fixating by using peer caps
1000 * - fixating with transform fixate function
1001 * - fixating with pad fixate functions.
1003 * this function returns a caps that can be transformed into and is accepted by
1007 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
1010 GstBaseTransformClass *klass;
1011 GstPad *otherpad, *otherpeer;
1015 /* caps must be fixed here, this is a programming error if it's not */
1016 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
1018 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1020 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1021 otherpeer = gst_pad_get_peer (otherpad);
1023 /* see how we can transform the input caps. We need to do this even for
1024 * passthrough because it might be possible that this element cannot support
1025 * passthrough at all. */
1026 othercaps = gst_base_transform_transform_caps (trans,
1027 GST_PAD_DIRECTION (pad), caps, NULL);
1029 /* The caps we can actually output is the intersection of the transformed
1030 * caps with the pad template for the pad */
1032 GstCaps *intersect, *templ_caps;
1034 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1035 GST_DEBUG_OBJECT (trans,
1036 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
1039 gst_caps_intersect_full (othercaps, templ_caps,
1040 GST_CAPS_INTERSECT_FIRST);
1042 gst_caps_unref (othercaps);
1043 gst_caps_unref (templ_caps);
1044 othercaps = intersect;
1047 /* check if transform is empty */
1048 if (!othercaps || gst_caps_is_empty (othercaps))
1051 /* if the othercaps are not fixed, we need to fixate them, first attempt
1052 * is by attempting passthrough if the othercaps are a superset of caps. */
1053 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1055 is_fixed = gst_caps_is_fixed (othercaps);
1057 GST_DEBUG_OBJECT (trans,
1058 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1060 /* Now let's see what the peer suggests based on our transformed caps */
1062 GstCaps *peercaps, *intersection, *templ_caps;
1064 GST_DEBUG_OBJECT (trans,
1065 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1067 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1068 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1069 if (!gst_caps_is_empty (peercaps)) {
1070 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1072 GST_DEBUG_OBJECT (trans,
1073 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1076 gst_caps_intersect_full (peercaps, templ_caps,
1077 GST_CAPS_INTERSECT_FIRST);
1078 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1080 gst_caps_unref (peercaps);
1081 gst_caps_unref (templ_caps);
1082 peercaps = intersection;
1084 GST_DEBUG_OBJECT (trans,
1085 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1087 gst_caps_intersect_full (peercaps, othercaps,
1088 GST_CAPS_INTERSECT_FIRST);
1089 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1091 gst_caps_unref (peercaps);
1092 gst_caps_unref (othercaps);
1093 othercaps = intersection;
1095 othercaps = peercaps;
1098 is_fixed = gst_caps_is_fixed (othercaps);
1100 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1101 gst_caps_unref (othercaps);
1102 othercaps = gst_caps_ref (caps);
1106 if (gst_caps_is_empty (othercaps))
1107 goto no_transform_possible;
1109 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1112 /* second attempt at fixation, call the fixate vmethod */
1113 /* caps could be fixed but the subclass may want to add fields */
1114 if (klass->fixate_caps) {
1115 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1116 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1117 GST_DEBUG_PAD_NAME (otherpad));
1118 /* note that we pass the complete array of structures to the fixate
1119 * function, it needs to truncate itself */
1121 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1122 is_fixed = gst_caps_is_fixed (othercaps);
1123 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1126 /* caps should be fixed now, if not we have to fail. */
1128 goto could_not_fixate;
1130 /* and peer should accept */
1131 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1132 goto peer_no_accept;
1134 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1135 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1138 gst_object_unref (otherpeer);
1145 GST_DEBUG_OBJECT (trans,
1146 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1149 no_transform_possible:
1151 GST_DEBUG_OBJECT (trans,
1152 "transform could not transform %" GST_PTR_FORMAT
1153 " in anything we support", caps);
1158 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1163 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1164 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1170 gst_object_unref (otherpeer);
1172 gst_caps_unref (othercaps);
1178 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1179 GstPadDirection direction, GstCaps * caps)
1183 GstCaps *othercaps = NULL;
1185 gboolean ret = TRUE;
1188 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1190 /* we need fixed caps for the check, fall back to the default implementation
1192 if (!gst_caps_is_fixed (caps))
1197 GST_DEBUG_OBJECT (trans, "accept caps %" GST_PTR_FORMAT, caps);
1199 /* get all the formats we can handle on this pad */
1200 if (direction == GST_PAD_SRC)
1201 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1203 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1206 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1207 goto no_transform_possible;
1210 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1212 /* intersect with the requested format */
1213 ret = gst_caps_is_subset (caps, allowed);
1214 gst_caps_unref (allowed);
1217 goto no_transform_possible;
1221 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1223 /* find best possible caps for the other pad as a way to see if we can
1224 * transform this caps. */
1225 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1226 if (!othercaps || gst_caps_is_empty (othercaps))
1227 goto no_transform_possible;
1229 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1235 /* We know it's always NULL since we never use it */
1237 gst_caps_unref (othercaps);
1243 no_transform_possible:
1245 GST_DEBUG_OBJECT (trans,
1246 "transform could not transform %" GST_PTR_FORMAT
1247 " in anything we support", caps);
1253 /* called when new caps arrive on the sink pad,
1254 * We try to find the best caps for the other side using our _find_transform()
1255 * function. If there are caps, we configure the transform for this new
1259 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1262 GstBaseTransformPrivate *priv = trans->priv;
1264 gboolean ret = TRUE;
1266 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1268 /* find best possible caps for the other pad */
1269 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1270 if (!outcaps || gst_caps_is_empty (outcaps))
1271 goto no_transform_possible;
1273 /* configure the element now */
1275 /* if we have the same caps, we can optimize and reuse the input caps */
1276 if (gst_caps_is_equal (incaps, outcaps)) {
1277 GST_INFO_OBJECT (trans, "reuse caps");
1278 gst_caps_unref (outcaps);
1279 outcaps = gst_caps_ref (incaps);
1282 /* call configure now */
1283 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1284 goto failed_configure;
1286 GST_OBJECT_LOCK (trans->sinkpad);
1287 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1288 trans->priv->reconfigure = FALSE;
1289 GST_OBJECT_UNLOCK (trans->sinkpad);
1291 /* let downstream know about our caps */
1292 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1295 /* try to get a pool when needed */
1296 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1301 gst_caps_unref (outcaps);
1303 GST_OBJECT_LOCK (trans);
1304 priv->negotiated = ret;
1305 GST_OBJECT_UNLOCK (trans);
1310 no_transform_possible:
1312 GST_WARNING_OBJECT (trans,
1313 "transform could not transform %" GST_PTR_FORMAT
1314 " in anything we support", incaps);
1320 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1321 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1328 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1329 GstQuery * decide_query, GstQuery * query)
1333 if (decide_query == NULL) {
1334 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1335 ret = gst_pad_peer_query (trans->srcpad, query);
1338 /* non-passthrough, copy all metadata, decide_query does not contain the
1339 * metadata anymore that depends on the buffer memory */
1340 n_metas = gst_query_get_n_allocation_metas (decide_query);
1341 for (i = 0; i < n_metas; i++) {
1344 api = gst_query_parse_nth_allocation_meta (decide_query, i);
1345 GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api));
1346 gst_query_add_allocation_meta (query, api);
1354 gst_base_transform_default_query (GstBaseTransform * trans,
1355 GstPadDirection direction, GstQuery * query)
1357 gboolean ret = FALSE;
1358 GstPad *pad, *otherpad;
1359 GstBaseTransformClass *klass;
1360 GstBaseTransformPrivate *priv = trans->priv;
1362 if (direction == GST_PAD_SRC) {
1363 pad = trans->srcpad;
1364 otherpad = trans->sinkpad;
1366 pad = trans->sinkpad;
1367 otherpad = trans->srcpad;
1370 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1372 switch (GST_QUERY_TYPE (query)) {
1373 case GST_QUERY_ALLOCATION:
1375 GstQuery *decide_query = NULL;
1376 gboolean negotiated;
1378 /* can only be done on the sinkpad */
1379 if (direction != GST_PAD_SINK)
1382 GST_OBJECT_LOCK (trans);
1383 if (G_UNLIKELY (!(negotiated = priv->negotiated))) {
1384 GST_DEBUG_OBJECT (trans,
1385 "not negotiated yet, can't answer ALLOCATION query");
1386 GST_OBJECT_UNLOCK (trans);
1389 if ((decide_query = trans->priv->query))
1390 gst_query_ref (decide_query);
1391 GST_OBJECT_UNLOCK (trans);
1393 GST_DEBUG_OBJECT (trans,
1394 "calling propose allocation with query %" GST_PTR_FORMAT,
1397 /* pass the query to the propose_allocation vmethod if any */
1398 if (G_LIKELY (klass->propose_allocation))
1399 ret = klass->propose_allocation (trans, decide_query, query);
1404 gst_query_unref (decide_query);
1406 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1410 case GST_QUERY_POSITION:
1414 gst_query_parse_position (query, &format, NULL);
1415 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1419 if ((direction == GST_PAD_SINK)
1420 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1422 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1423 trans->segment.position);
1425 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1426 trans->priv->position_out);
1428 gst_query_set_position (query, format, pos);
1430 ret = gst_pad_peer_query (otherpad, query);
1434 case GST_QUERY_ACCEPT_CAPS:
1438 gst_query_parse_accept_caps (query, &caps);
1439 if (klass->accept_caps) {
1440 ret = klass->accept_caps (trans, direction, caps);
1441 gst_query_set_accept_caps_result (query, ret);
1442 /* return TRUE, we answered the query */
1447 case GST_QUERY_CAPS:
1449 GstCaps *filter, *caps;
1451 gst_query_parse_caps (query, &filter);
1452 caps = gst_base_transform_query_caps (trans, pad, filter);
1453 gst_query_set_caps_result (query, caps);
1454 gst_caps_unref (caps);
1459 ret = gst_pad_peer_query (otherpad, query);
1468 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1470 GstBaseTransform *trans;
1471 GstBaseTransformClass *bclass;
1472 gboolean ret = FALSE;
1474 trans = GST_BASE_TRANSFORM (parent);
1475 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1478 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1483 /* this function either returns the input buffer without incrementing the
1484 * refcount or it allocates a new (writable) buffer */
1485 static GstFlowReturn
1486 default_prepare_output_buffer (GstBaseTransform * trans,
1487 GstBuffer * inbuf, GstBuffer ** outbuf)
1489 GstBaseTransformPrivate *priv;
1490 GstFlowReturn ret = GST_FLOW_OK;
1491 GstBaseTransformClass *bclass;
1492 GstCaps *incaps, *outcaps;
1493 gsize insize, outsize;
1497 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1499 /* figure out how to allocate an output buffer */
1500 if (priv->passthrough) {
1501 /* passthrough, we will not modify the incomming buffer so we can just
1503 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1508 /* we can't reuse the input buffer */
1510 if (!priv->pool_active) {
1511 GST_DEBUG_OBJECT (trans, "setting pool %p active", priv->pool);
1512 if (!gst_buffer_pool_set_active (priv->pool, TRUE))
1513 goto activate_failed;
1514 priv->pool_active = TRUE;
1516 GST_DEBUG_OBJECT (trans, "using pool alloc");
1517 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1521 /* no pool, we need to figure out the size of the output buffer first */
1522 if ((bclass->transform_ip != NULL) && priv->always_in_place) {
1523 /* we want to do an in-place alloc */
1524 if (gst_buffer_is_writable (inbuf)) {
1525 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1528 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1529 /* we make a copy of the input buffer */
1530 *outbuf = gst_buffer_copy (inbuf);
1535 /* else use the transform function to get the size */
1536 incaps = gst_pad_get_current_caps (trans->sinkpad);
1537 outcaps = gst_pad_get_current_caps (trans->srcpad);
1539 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1540 /* copy transform, figure out the output size */
1541 insize = gst_buffer_get_size (inbuf);
1542 res = gst_base_transform_transform_size (trans,
1543 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1545 gst_caps_unref (incaps);
1546 gst_caps_unref (outcaps);
1551 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1552 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, &priv->params);
1555 /* copy the metadata */
1556 if (bclass->copy_metadata)
1557 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1558 /* something failed, post a warning */
1559 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1560 ("could not copy metadata"), (NULL));
1570 GST_ELEMENT_ERROR (trans, RESOURCE, SETTINGS,
1571 ("failed to activate bufferpool"), ("failed to activate bufferpool"));
1572 return GST_FLOW_ERROR;
1576 GST_ERROR_OBJECT (trans, "unknown output size");
1577 return GST_FLOW_ERROR;
1583 GstBaseTransform *trans;
1588 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1590 CopyMetaData *data = user_data;
1591 GstBaseTransform *trans = data->trans;
1592 GstBaseTransformClass *klass;
1593 const GstMetaInfo *info = (*meta)->info;
1594 GstBuffer *outbuf = data->outbuf;
1597 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1599 if (GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
1600 /* never call the transform_meta with pool private metadata */
1601 GST_DEBUG_OBJECT (trans, "not copying pooled metadata %s",
1602 g_type_name (info->api));
1604 } else if (gst_meta_api_type_has_tag (info->api, GST_META_TAG_MEMORY)) {
1605 /* never call the transform_meta with memory specific metadata */
1606 GST_DEBUG_OBJECT (trans, "not copying memory specific metadata %s",
1607 g_type_name (info->api));
1609 } else if (klass->transform_meta) {
1610 do_copy = klass->transform_meta (trans, outbuf, *meta, inbuf);
1611 GST_DEBUG_OBJECT (trans, "transformed metadata %s: copy: %d",
1612 g_type_name (info->api), do_copy);
1615 GST_DEBUG_OBJECT (trans, "not copying metadata %s",
1616 g_type_name (info->api));
1619 /* we only copy metadata when the subclass implemented a transform_meta
1620 * function and when it returns TRUE */
1622 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1623 GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
1624 /* simply copy then */
1625 info->transform_func (outbuf, *meta, inbuf,
1626 _gst_meta_transform_copy, ©_data);
1632 default_copy_metadata (GstBaseTransform * trans,
1633 GstBuffer * inbuf, GstBuffer * outbuf)
1635 GstBaseTransformPrivate *priv = trans->priv;
1638 /* now copy the metadata */
1639 GST_DEBUG_OBJECT (trans, "copying metadata");
1641 /* this should not happen, buffers allocated from a pool or with
1642 * new_allocate should always be writable. */
1643 if (!gst_buffer_is_writable (outbuf))
1646 /* when we get here, the metadata should be writable */
1647 gst_buffer_copy_into (outbuf, inbuf,
1648 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1650 /* clear the GAP flag when the subclass does not understand it */
1651 if (!priv->gap_aware)
1652 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1656 data.outbuf = outbuf;
1658 gst_buffer_foreach_meta (inbuf, foreach_metadata, &data);
1665 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1670 /* Given @caps calcultate the size of one unit.
1672 * For video caps, this is the size of one frame (and thus one buffer).
1673 * For audio caps, this is the size of one sample.
1675 * These values are cached since they do not change and the calculation
1676 * potentially involves parsing caps and other expensive stuff.
1678 * We have two cache locations to store the size, one for the source caps
1679 * and one for the sink caps.
1681 * this function returns FALSE if no size could be calculated.
1684 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1687 gboolean res = FALSE;
1688 GstBaseTransformClass *bclass;
1689 GstBaseTransformPrivate *priv = trans->priv;
1691 /* see if we have the result cached */
1692 if (priv->cache_caps1 == caps) {
1693 *size = priv->cache_caps1_size;
1694 GST_DEBUG_OBJECT (trans,
1695 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1698 if (priv->cache_caps2 == caps) {
1699 *size = priv->cache_caps2_size;
1700 GST_DEBUG_OBJECT (trans,
1701 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1705 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1706 res = bclass->get_unit_size (trans, caps, size);
1707 GST_DEBUG_OBJECT (trans,
1708 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1709 caps, *size, res ? "TRUE" : "FALSE");
1712 /* and cache the values */
1713 if (priv->cache_caps1 == NULL) {
1714 gst_caps_replace (&priv->cache_caps1, caps);
1715 priv->cache_caps1_size = *size;
1716 GST_DEBUG_OBJECT (trans,
1717 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1718 } else if (priv->cache_caps2 == NULL) {
1719 gst_caps_replace (&priv->cache_caps2, caps);
1720 priv->cache_caps2_size = *size;
1721 GST_DEBUG_OBJECT (trans,
1722 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1724 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1731 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1734 GstBaseTransform *trans;
1735 GstBaseTransformClass *bclass;
1736 gboolean ret = TRUE;
1738 trans = GST_BASE_TRANSFORM (parent);
1739 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1741 if (bclass->sink_event)
1742 ret = bclass->sink_event (trans, event);
1744 gst_event_unref (event);
1750 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1752 gboolean ret = TRUE, forward = TRUE;
1753 GstBaseTransformPrivate *priv = trans->priv;
1755 switch (GST_EVENT_TYPE (event)) {
1756 case GST_EVENT_FLUSH_START:
1758 case GST_EVENT_FLUSH_STOP:
1759 GST_OBJECT_LOCK (trans);
1760 /* reset QoS parameters */
1761 priv->proportion = 1.0;
1762 priv->earliest_time = -1;
1763 priv->discont = FALSE;
1764 priv->processed = 0;
1766 GST_OBJECT_UNLOCK (trans);
1767 /* we need new segment info after the flush. */
1768 trans->have_segment = FALSE;
1769 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1770 priv->position_out = GST_CLOCK_TIME_NONE;
1776 case GST_EVENT_CAPS:
1780 gst_event_parse_caps (event, &caps);
1781 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1786 case GST_EVENT_SEGMENT:
1788 gst_event_copy_segment (event, &trans->segment);
1789 trans->have_segment = TRUE;
1791 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1800 ret = gst_pad_push_event (trans->srcpad, event);
1802 gst_event_unref (event);
1808 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1811 GstBaseTransform *trans;
1812 GstBaseTransformClass *bclass;
1813 gboolean ret = TRUE;
1815 trans = GST_BASE_TRANSFORM (parent);
1816 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1818 if (bclass->src_event)
1819 ret = bclass->src_event (trans, event);
1821 gst_event_unref (event);
1827 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1831 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1833 switch (GST_EVENT_TYPE (event)) {
1834 case GST_EVENT_SEEK:
1836 case GST_EVENT_NAVIGATION:
1841 GstClockTimeDiff diff;
1842 GstClockTime timestamp;
1844 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1845 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1852 ret = gst_pad_push_event (trans->sinkpad, event);
1857 /* perform a transform on @inbuf and put the result in @outbuf.
1859 * This function is common to the push and pull-based operations.
1861 * This function takes ownership of @inbuf */
1862 static GstFlowReturn
1863 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1864 GstBuffer ** outbuf)
1866 GstBaseTransformClass *bclass;
1867 GstBaseTransformPrivate *priv = trans->priv;
1868 GstFlowReturn ret = GST_FLOW_OK;
1869 gboolean want_in_place;
1870 GstClockTime running_time;
1871 GstClockTime timestamp;
1872 gboolean reconfigure;
1874 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1876 GST_OBJECT_LOCK (trans->sinkpad);
1877 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1878 || priv->reconfigure;
1879 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1880 priv->reconfigure = FALSE;
1881 GST_OBJECT_UNLOCK (trans->sinkpad);
1883 if (G_UNLIKELY (reconfigure)) {
1886 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1888 incaps = gst_pad_get_current_caps (trans->sinkpad);
1890 goto no_reconfigure;
1892 /* if we need to reconfigure we pretend new caps arrived. This
1893 * will reconfigure the transform with the new output format. */
1894 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1895 gst_caps_unref (incaps);
1896 goto not_negotiated;
1898 gst_caps_unref (incaps);
1902 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1903 GST_DEBUG_OBJECT (trans,
1904 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1905 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1906 GST_BUFFER_OFFSET (inbuf));
1908 GST_DEBUG_OBJECT (trans,
1909 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1910 gst_buffer_get_size (inbuf));
1912 /* Don't allow buffer handling before negotiation, except in passthrough mode
1913 * or if the class doesn't implement a set_caps function (in which case it doesn't
1916 if (!priv->negotiated && !priv->passthrough && (bclass->set_caps != NULL))
1917 goto not_negotiated;
1919 /* Set discont flag so we can mark the outgoing buffer */
1920 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1921 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1922 priv->discont = TRUE;
1925 /* can only do QoS if the segment is in TIME */
1926 if (trans->segment.format != GST_FORMAT_TIME)
1929 /* QOS is done on the running time of the buffer, get it now */
1930 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1931 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1934 if (running_time != -1) {
1936 GstClockTime earliest_time;
1939 /* lock for getting the QoS parameters that are set (in a different thread)
1940 * with the QOS events */
1941 GST_OBJECT_LOCK (trans);
1942 earliest_time = priv->earliest_time;
1943 proportion = priv->proportion;
1944 /* check for QoS, don't perform conversion for buffers
1945 * that are known to be late. */
1946 need_skip = priv->qos_enabled &&
1947 earliest_time != -1 && running_time <= earliest_time;
1948 GST_OBJECT_UNLOCK (trans);
1951 GstMessage *qos_msg;
1952 GstClockTime duration;
1953 guint64 stream_time;
1956 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1957 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1958 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1962 duration = GST_BUFFER_DURATION (inbuf);
1964 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1966 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1969 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1970 stream_time, timestamp, duration);
1971 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1972 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1973 priv->processed, priv->dropped);
1974 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1976 /* mark discont for next buffer */
1977 priv->discont = TRUE;
1984 /* first try to allocate an output buffer based on the currently negotiated
1985 * format. outbuf will contain a buffer suitable for doing the configured
1986 * transform after this function. */
1987 if (bclass->prepare_output_buffer == NULL)
1990 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
1991 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
1993 if (ret != GST_FLOW_OK || *outbuf == NULL)
1996 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
1999 /* now perform the needed transform */
2000 if (priv->passthrough) {
2001 /* In passthrough mode, give transform_ip a look at the
2002 * buffer, without making it writable, or just push the
2004 if (bclass->transform_ip) {
2005 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
2006 ret = bclass->transform_ip (trans, *outbuf);
2008 GST_DEBUG_OBJECT (trans, "element is in passthrough");
2011 want_in_place = (bclass->transform_ip != NULL) && priv->always_in_place;
2013 if (want_in_place) {
2014 GST_DEBUG_OBJECT (trans, "doing inplace transform");
2015 ret = bclass->transform_ip (trans, *outbuf);
2017 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
2019 if (bclass->transform)
2020 ret = bclass->transform (trans, inbuf, *outbuf);
2022 ret = GST_FLOW_NOT_SUPPORTED;
2027 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
2028 * the input buffer, no refcount is changed to keep the input buffer writable
2030 if (*outbuf != inbuf)
2031 gst_buffer_unref (inbuf);
2038 gst_buffer_unref (inbuf);
2040 GST_ELEMENT_ERROR (trans, STREAM, FORMAT,
2041 ("not negotiated"), ("not negotiated"));
2042 return GST_FLOW_NOT_NEGOTIATED;
2046 gst_buffer_unref (inbuf);
2047 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
2048 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
2049 return GST_FLOW_NOT_SUPPORTED;
2053 gst_buffer_unref (inbuf);
2055 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
2056 gst_flow_get_name (ret));
2061 /* FIXME, getrange is broken, need to pull range from the other
2062 * end based on the transform_size result.
2064 static GstFlowReturn
2065 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
2066 guint length, GstBuffer ** buffer)
2068 GstBaseTransform *trans;
2069 GstBaseTransformClass *klass;
2071 GstBuffer *inbuf = NULL;
2073 trans = GST_BASE_TRANSFORM (parent);
2075 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
2076 if (G_UNLIKELY (ret != GST_FLOW_OK))
2079 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2080 if (klass->before_transform)
2081 klass->before_transform (trans, inbuf);
2083 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
2091 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
2092 gst_flow_get_name (ret));
2097 static GstFlowReturn
2098 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2100 GstBaseTransform *trans;
2101 GstBaseTransformClass *klass;
2102 GstBaseTransformPrivate *priv;
2104 GstClockTime position = GST_CLOCK_TIME_NONE;
2105 GstClockTime timestamp, duration;
2106 GstBuffer *outbuf = NULL;
2108 trans = GST_BASE_TRANSFORM (parent);
2111 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2112 duration = GST_BUFFER_DURATION (buffer);
2114 /* calculate end position of the incoming buffer */
2115 if (timestamp != GST_CLOCK_TIME_NONE) {
2116 if (duration != GST_CLOCK_TIME_NONE)
2117 position = timestamp + duration;
2119 position = timestamp;
2122 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2123 if (klass->before_transform)
2124 klass->before_transform (trans, buffer);
2126 /* protect transform method and concurrent buffer alloc */
2127 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2129 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2130 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2131 if (outbuf != NULL) {
2132 if (ret == GST_FLOW_OK) {
2133 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2135 /* Remember last stop position */
2136 if (position != GST_CLOCK_TIME_NONE &&
2137 trans->segment.format == GST_FORMAT_TIME)
2138 trans->segment.position = position;
2140 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2141 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2142 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2143 position_out += GST_BUFFER_DURATION (outbuf);
2144 } else if (position != GST_CLOCK_TIME_NONE) {
2145 position_out = position;
2147 if (position_out != GST_CLOCK_TIME_NONE
2148 && trans->segment.format == GST_FORMAT_TIME)
2149 priv->position_out = position_out;
2151 /* apply DISCONT flag if the buffer is not yet marked as such */
2152 if (trans->priv->discont) {
2153 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2154 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2155 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2156 outbuf = gst_buffer_make_writable (outbuf);
2157 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2159 priv->discont = FALSE;
2163 ret = gst_pad_push (trans->srcpad, outbuf);
2165 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2166 gst_buffer_unref (outbuf);
2170 /* convert internal flow to OK and mark discont for the next buffer. */
2171 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2172 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2173 priv->discont = TRUE;
2181 gst_base_transform_set_property (GObject * object, guint prop_id,
2182 const GValue * value, GParamSpec * pspec)
2184 GstBaseTransform *trans;
2186 trans = GST_BASE_TRANSFORM (object);
2190 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2199 gst_base_transform_get_property (GObject * object, guint prop_id,
2200 GValue * value, GParamSpec * pspec)
2202 GstBaseTransform *trans;
2204 trans = GST_BASE_TRANSFORM (object);
2208 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2216 /* not a vmethod of anything, just an internal method */
2218 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2220 GstBaseTransformClass *bclass;
2221 GstBaseTransformPrivate *priv = trans->priv;
2222 gboolean result = TRUE;
2224 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2227 GstCaps *incaps, *outcaps;
2229 if (priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2230 result &= bclass->start (trans);
2232 incaps = gst_pad_get_current_caps (trans->sinkpad);
2233 outcaps = gst_pad_get_current_caps (trans->srcpad);
2235 GST_OBJECT_LOCK (trans);
2236 if (incaps && outcaps)
2237 priv->have_same_caps =
2238 gst_caps_is_equal (incaps, outcaps) || priv->passthrough;
2240 priv->have_same_caps = priv->passthrough;
2241 GST_DEBUG_OBJECT (trans, "have_same_caps %d", priv->have_same_caps);
2242 priv->negotiated = FALSE;
2243 trans->have_segment = FALSE;
2244 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2245 priv->position_out = GST_CLOCK_TIME_NONE;
2246 priv->proportion = 1.0;
2247 priv->earliest_time = -1;
2248 priv->discont = FALSE;
2249 priv->processed = 0;
2251 GST_OBJECT_UNLOCK (trans);
2254 gst_caps_unref (incaps);
2256 gst_caps_unref (outcaps);
2258 /* We must make sure streaming has finished before resetting things
2259 * and calling the ::stop vfunc */
2260 GST_PAD_STREAM_LOCK (trans->sinkpad);
2261 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2263 priv->have_same_caps = FALSE;
2264 /* We can only reset the passthrough mode if the instance told us to
2265 handle it in configure_caps */
2266 if (bclass->passthrough_on_same_caps) {
2267 gst_base_transform_set_passthrough (trans, FALSE);
2269 gst_caps_replace (&priv->cache_caps1, NULL);
2270 gst_caps_replace (&priv->cache_caps2, NULL);
2272 if (priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2273 result &= bclass->stop (trans);
2275 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
2282 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2283 GstPadMode mode, gboolean active)
2285 gboolean result = FALSE;
2286 GstBaseTransform *trans;
2288 trans = GST_BASE_TRANSFORM (parent);
2291 case GST_PAD_MODE_PUSH:
2293 result = gst_base_transform_activate (trans, active);
2296 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2308 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2309 GstPadMode mode, gboolean active)
2311 gboolean result = FALSE;
2312 GstBaseTransform *trans;
2314 trans = GST_BASE_TRANSFORM (parent);
2317 case GST_PAD_MODE_PULL:
2320 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2323 result &= gst_base_transform_activate (trans, active);
2326 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2338 * gst_base_transform_set_passthrough:
2339 * @trans: the #GstBaseTransform to set
2340 * @passthrough: boolean indicating passthrough mode.
2342 * Set passthrough mode for this filter by default. This is mostly
2343 * useful for filters that do not care about negotiation.
2345 * Always TRUE for filters which don't implement either a transform
2346 * or transform_ip method.
2351 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2352 gboolean passthrough)
2354 GstBaseTransformClass *bclass;
2356 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2358 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2360 GST_OBJECT_LOCK (trans);
2361 if (passthrough == FALSE) {
2362 if (bclass->transform_ip || bclass->transform)
2363 trans->priv->passthrough = FALSE;
2365 trans->priv->passthrough = TRUE;
2368 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->priv->passthrough);
2369 GST_OBJECT_UNLOCK (trans);
2373 * gst_base_transform_is_passthrough:
2374 * @trans: the #GstBaseTransform to query
2376 * See if @trans is configured as a passthrough transform.
2378 * Returns: TRUE is the transform is configured in passthrough mode.
2383 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2387 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2389 GST_OBJECT_LOCK (trans);
2390 result = trans->priv->passthrough;
2391 GST_OBJECT_UNLOCK (trans);
2397 * gst_base_transform_set_in_place:
2398 * @trans: the #GstBaseTransform to modify
2399 * @in_place: Boolean value indicating that we would like to operate
2400 * on in_place buffers.
2402 * Determines whether a non-writable buffer will be copied before passing
2403 * to the transform_ip function.
2405 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2406 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2412 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2414 GstBaseTransformClass *bclass;
2416 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2418 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2420 GST_OBJECT_LOCK (trans);
2423 if (bclass->transform_ip) {
2424 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2425 trans->priv->always_in_place = TRUE;
2428 if (bclass->transform) {
2429 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2430 trans->priv->always_in_place = FALSE;
2434 GST_OBJECT_UNLOCK (trans);
2438 * gst_base_transform_is_in_place:
2439 * @trans: the #GstBaseTransform to query
2441 * See if @trans is configured as a in_place transform.
2443 * Returns: TRUE is the transform is configured in in_place mode.
2448 gst_base_transform_is_in_place (GstBaseTransform * trans)
2452 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2454 GST_OBJECT_LOCK (trans);
2455 result = trans->priv->always_in_place;
2456 GST_OBJECT_UNLOCK (trans);
2462 * gst_base_transform_update_qos:
2463 * @trans: a #GstBaseTransform
2464 * @proportion: the proportion
2465 * @diff: the diff against the clock
2466 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2469 * Set the QoS parameters in the transform. This function is called internally
2470 * when a QOS event is received but subclasses can provide custom information
2478 gst_base_transform_update_qos (GstBaseTransform * trans,
2479 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2481 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2483 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2484 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2485 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2487 GST_OBJECT_LOCK (trans);
2488 trans->priv->proportion = proportion;
2489 trans->priv->earliest_time = timestamp + diff;
2490 GST_OBJECT_UNLOCK (trans);
2494 * gst_base_transform_set_qos_enabled:
2495 * @trans: a #GstBaseTransform
2496 * @enabled: new state
2498 * Enable or disable QoS handling in the transform.
2505 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2507 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2509 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2511 GST_OBJECT_LOCK (trans);
2512 trans->priv->qos_enabled = enabled;
2513 GST_OBJECT_UNLOCK (trans);
2517 * gst_base_transform_is_qos_enabled:
2518 * @trans: a #GstBaseTransform
2520 * Queries if the transform will handle QoS.
2522 * Returns: TRUE if QoS is enabled.
2529 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2533 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2535 GST_OBJECT_LOCK (trans);
2536 result = trans->priv->qos_enabled;
2537 GST_OBJECT_UNLOCK (trans);
2543 * gst_base_transform_set_gap_aware:
2544 * @trans: a #GstBaseTransform
2545 * @gap_aware: New state
2547 * If @gap_aware is %FALSE (the default), output buffers will have the
2548 * %GST_BUFFER_FLAG_GAP flag unset.
2550 * If set to %TRUE, the element must handle output buffers with this flag set
2551 * correctly, i.e. it can assume that the buffer contains neutral data but must
2552 * unset the flag if the output is no neutral data.
2559 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2561 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2563 GST_OBJECT_LOCK (trans);
2564 trans->priv->gap_aware = gap_aware;
2565 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2566 GST_OBJECT_UNLOCK (trans);
2570 * gst_base_transform_reconfigure_sink:
2571 * @trans: a #GstBaseTransform
2573 * Instructs @trans to request renegotiation upstream. This function is
2574 * typically called after properties on the transform were set that
2575 * influence the input format.
2578 gst_base_transform_reconfigure_sink (GstBaseTransform * trans)
2580 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2582 /* push the renegotiate event */
2583 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2584 gst_event_new_reconfigure ()))
2585 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2589 * gst_base_transform_reconfigure_src:
2590 * @trans: a #GstBaseTransform
2592 * Instructs @trans to renegotiate a new downstream transform on the next
2593 * buffer. This function is typically called after properties on the transform
2594 * were set that influence the output format.
2599 gst_base_transform_reconfigure_src (GstBaseTransform * trans)
2601 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2603 GST_OBJECT_LOCK (trans);
2604 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2605 trans->priv->reconfigure = TRUE;
2606 GST_OBJECT_UNLOCK (trans);