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;
807 guint size, min, max;
808 GstAllocator *allocator;
809 GstAllocationParams params;
810 GstStructure *config;
811 gboolean update_allocator;
813 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
815 n_metas = gst_query_get_n_allocation_metas (query);
816 for (i = 0; i < n_metas; i++) {
820 api = gst_query_parse_nth_allocation_meta (query, i);
822 /* by default we remove all metadata, subclasses should implement a
823 * filter_meta function */
824 if (gst_meta_api_type_has_tag (api, GST_META_TAG_MEMORY)) {
825 /* remove all memory dependent metadata because we are going to have to
826 * allocate different memory for input and output. */
827 GST_LOG_OBJECT (trans, "removing memory specific metadata %s",
830 } else if (G_LIKELY (klass->filter_meta)) {
831 /* remove if the subclass said so */
832 remove = !klass->filter_meta (trans, query, api);
833 GST_LOG_OBJECT (trans, "filter_meta for api %s returned: %s",
834 g_type_name (api), (remove ? "remove" : "keep"));
836 GST_LOG_OBJECT (trans, "removing metadata %s", g_type_name (api));
841 gst_query_remove_nth_allocation_meta (query, i);
847 gst_query_parse_allocation (query, &outcaps, NULL);
849 /* we got configuration from our peer or the decide_allocation method,
851 if (gst_query_get_n_allocation_params (query) > 0) {
852 /* try the allocator */
853 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
854 update_allocator = TRUE;
857 gst_allocation_params_init (¶ms);
858 update_allocator = FALSE;
861 if (gst_query_get_n_allocation_pools (query) > 0) {
862 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
865 /* no pool, we can make our own */
866 GST_DEBUG_OBJECT (trans, "no pool, making new pool");
867 pool = gst_buffer_pool_new ();
871 size = min = max = 0;
876 config = gst_buffer_pool_get_config (pool);
877 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
878 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
879 gst_buffer_pool_set_config (pool, config);
882 if (update_allocator)
883 gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
885 gst_query_add_allocation_param (query, allocator, ¶ms);
887 gst_allocator_unref (allocator);
890 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
891 gst_object_unref (pool);
898 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
901 gboolean result = TRUE;
902 GstBufferPool *pool = NULL;
903 GstBaseTransformClass *klass;
904 GstBaseTransformPrivate *priv = trans->priv;
905 GstAllocator *allocator;
906 GstAllocationParams params;
908 /* there are these possibilities:
910 * 1) we negotiated passthrough, we can proxy the bufferpool directly and we
911 * will do that whenever some upstream does an allocation query.
912 * 2) we need to do a transform, we need to get a bufferpool from downstream
913 * and configure it. When upstream does the ALLOCATION query, the
914 * propose_allocation vmethod will be called and we will configure the
915 * upstream allocator with our proposed values then.
917 if (priv->passthrough || priv->always_in_place) {
918 /* we are in passthrough, the input buffer is never copied and always passed
919 * along. We never allocate an output buffer on the srcpad. What we do is
920 * let the upstream element decide if it wants to use a bufferpool and
921 * then we will proxy the downstream pool */
922 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
923 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
927 /* not passthrough, we need to allocate */
928 /* find a pool for the negotiated caps now */
929 GST_DEBUG_OBJECT (trans, "doing allocation query");
930 query = gst_query_new_allocation (outcaps, TRUE);
931 if (!gst_pad_peer_query (trans->srcpad, query)) {
932 /* not a problem, just debug a little */
933 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
936 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
938 GST_DEBUG_OBJECT (trans, "calling decide_allocation");
939 g_assert (klass->decide_allocation != NULL);
940 result = klass->decide_allocation (trans, query);
942 GST_DEBUG_OBJECT (trans, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
946 goto no_decide_allocation;
948 /* we got configuration from our peer or the decide_allocation method,
950 if (gst_query_get_n_allocation_params (query) > 0) {
951 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
954 gst_allocation_params_init (¶ms);
957 if (gst_query_get_n_allocation_pools (query) > 0)
958 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
962 gst_base_transform_set_allocation (trans, pool, allocator, ¶ms,
968 no_decide_allocation:
970 GST_WARNING_OBJECT (trans, "Subclass failed to decide allocation");
971 gst_query_unref (query);
977 /* function triggered when the in and out caps are negotiated and need
978 * to be configured in the subclass. */
980 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
984 GstBaseTransformClass *klass;
985 GstBaseTransformPrivate *priv = trans->priv;
987 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
989 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
990 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
992 /* clear the cache */
993 gst_caps_replace (&priv->cache_caps1, NULL);
994 gst_caps_replace (&priv->cache_caps2, NULL);
996 /* figure out same caps state */
997 priv->have_same_caps = gst_caps_is_equal (in, out);
998 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", priv->have_same_caps);
1000 /* Set the passthrough if the class wants passthrough_on_same_caps
1001 * and we have the same caps on each pad */
1002 if (klass->passthrough_on_same_caps)
1003 gst_base_transform_set_passthrough (trans, priv->have_same_caps);
1005 /* now configure the element with the caps */
1006 if (klass->set_caps) {
1007 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
1008 ret = klass->set_caps (trans, in, out);
1015 gst_base_transform_default_fixate_caps (GstBaseTransform * trans,
1016 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1018 othercaps = gst_caps_fixate (othercaps);
1019 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, othercaps);
1024 /* given a fixed @caps on @pad, create the best possible caps for the
1026 * @caps must be fixed when calling this function.
1028 * This function calls the transform caps vmethod of the basetransform to figure
1029 * out the possible target formats. It then tries to select the best format from
1032 * - attempt passthrough if the target caps is a superset of the input caps
1033 * - fixating by using peer caps
1034 * - fixating with transform fixate function
1035 * - fixating with pad fixate functions.
1037 * this function returns a caps that can be transformed into and is accepted by
1041 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
1044 GstBaseTransformClass *klass;
1045 GstPad *otherpad, *otherpeer;
1049 /* caps must be fixed here, this is a programming error if it's not */
1050 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
1052 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1054 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1055 otherpeer = gst_pad_get_peer (otherpad);
1057 /* see how we can transform the input caps. We need to do this even for
1058 * passthrough because it might be possible that this element cannot support
1059 * passthrough at all. */
1060 othercaps = gst_base_transform_transform_caps (trans,
1061 GST_PAD_DIRECTION (pad), caps, NULL);
1063 /* The caps we can actually output is the intersection of the transformed
1064 * caps with the pad template for the pad */
1066 GstCaps *intersect, *templ_caps;
1068 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1069 GST_DEBUG_OBJECT (trans,
1070 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
1073 gst_caps_intersect_full (othercaps, templ_caps,
1074 GST_CAPS_INTERSECT_FIRST);
1076 gst_caps_unref (othercaps);
1077 gst_caps_unref (templ_caps);
1078 othercaps = intersect;
1081 /* check if transform is empty */
1082 if (!othercaps || gst_caps_is_empty (othercaps))
1085 /* if the othercaps are not fixed, we need to fixate them, first attempt
1086 * is by attempting passthrough if the othercaps are a superset of caps. */
1087 /* FIXME. maybe the caps is not fixed because it has multiple structures of
1089 is_fixed = gst_caps_is_fixed (othercaps);
1091 GST_DEBUG_OBJECT (trans,
1092 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
1094 /* Now let's see what the peer suggests based on our transformed caps */
1096 GstCaps *peercaps, *intersection, *templ_caps;
1098 GST_DEBUG_OBJECT (trans,
1099 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
1101 peercaps = gst_pad_query_caps (otherpeer, othercaps);
1102 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
1103 if (!gst_caps_is_empty (peercaps)) {
1104 templ_caps = gst_pad_get_pad_template_caps (otherpad);
1106 GST_DEBUG_OBJECT (trans,
1107 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
1110 gst_caps_intersect_full (peercaps, templ_caps,
1111 GST_CAPS_INTERSECT_FIRST);
1112 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1114 gst_caps_unref (peercaps);
1115 gst_caps_unref (templ_caps);
1116 peercaps = intersection;
1118 GST_DEBUG_OBJECT (trans,
1119 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
1121 gst_caps_intersect_full (peercaps, othercaps,
1122 GST_CAPS_INTERSECT_FIRST);
1123 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT,
1125 gst_caps_unref (peercaps);
1126 gst_caps_unref (othercaps);
1127 othercaps = intersection;
1129 gst_caps_unref (othercaps);
1130 othercaps = peercaps;
1133 is_fixed = gst_caps_is_fixed (othercaps);
1135 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
1136 gst_caps_unref (othercaps);
1137 othercaps = gst_caps_ref (caps);
1141 if (gst_caps_is_empty (othercaps))
1142 goto no_transform_possible;
1144 GST_DEBUG ("have %sfixed caps %" GST_PTR_FORMAT, (is_fixed ? "" : "non-"),
1147 /* second attempt at fixation, call the fixate vmethod */
1148 /* caps could be fixed but the subclass may want to add fields */
1149 if (klass->fixate_caps) {
1150 GST_DEBUG_OBJECT (trans, "calling fixate_caps for %" GST_PTR_FORMAT
1151 " using caps %" GST_PTR_FORMAT " on pad %s:%s", othercaps, caps,
1152 GST_DEBUG_PAD_NAME (otherpad));
1153 /* note that we pass the complete array of structures to the fixate
1154 * function, it needs to truncate itself */
1156 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1157 is_fixed = gst_caps_is_fixed (othercaps);
1158 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1161 /* caps should be fixed now, if not we have to fail. */
1163 goto could_not_fixate;
1165 /* and peer should accept */
1166 if (otherpeer && !gst_pad_query_accept_caps (otherpeer, othercaps))
1167 goto peer_no_accept;
1169 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1170 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1173 gst_object_unref (otherpeer);
1180 GST_DEBUG_OBJECT (trans,
1181 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1184 no_transform_possible:
1186 GST_DEBUG_OBJECT (trans,
1187 "transform could not transform %" GST_PTR_FORMAT
1188 " in anything we support", caps);
1193 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1198 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1199 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1205 gst_object_unref (otherpeer);
1207 gst_caps_unref (othercaps);
1213 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1214 GstPadDirection direction, GstCaps * caps)
1218 GstCaps *othercaps = NULL;
1220 gboolean ret = TRUE;
1223 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1225 /* we need fixed caps for the check, fall back to the default implementation
1227 if (!gst_caps_is_fixed (caps))
1232 GST_DEBUG_OBJECT (trans, "accept caps %" GST_PTR_FORMAT, caps);
1234 /* get all the formats we can handle on this pad */
1235 if (direction == GST_PAD_SRC)
1236 allowed = gst_pad_query_caps (trans->srcpad, NULL);
1238 allowed = gst_pad_query_caps (trans->sinkpad, NULL);
1241 GST_DEBUG_OBJECT (trans, "gst_pad_query_caps() failed");
1242 goto no_transform_possible;
1245 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1247 /* intersect with the requested format */
1248 ret = gst_caps_is_subset (caps, allowed);
1249 gst_caps_unref (allowed);
1252 goto no_transform_possible;
1256 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1258 /* find best possible caps for the other pad as a way to see if we can
1259 * transform this caps. */
1260 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1261 if (!othercaps || gst_caps_is_empty (othercaps))
1262 goto no_transform_possible;
1264 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1270 /* We know it's always NULL since we never use it */
1272 gst_caps_unref (othercaps);
1278 no_transform_possible:
1280 GST_DEBUG_OBJECT (trans,
1281 "transform could not transform %" GST_PTR_FORMAT
1282 " in anything we support", caps);
1288 /* called when new caps arrive on the sink pad,
1289 * We try to find the best caps for the other side using our _find_transform()
1290 * function. If there are caps, we configure the transform for this new
1294 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1297 GstBaseTransformPrivate *priv = trans->priv;
1299 gboolean ret = TRUE;
1301 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, incaps, incaps);
1303 /* find best possible caps for the other pad */
1304 outcaps = gst_base_transform_find_transform (trans, pad, incaps);
1305 if (!outcaps || gst_caps_is_empty (outcaps))
1306 goto no_transform_possible;
1308 /* configure the element now */
1310 /* if we have the same caps, we can optimize and reuse the input caps */
1311 if (gst_caps_is_equal (incaps, outcaps)) {
1312 GST_INFO_OBJECT (trans, "reuse caps");
1313 gst_caps_unref (outcaps);
1314 outcaps = gst_caps_ref (incaps);
1317 /* call configure now */
1318 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1319 goto failed_configure;
1321 GST_OBJECT_LOCK (trans->sinkpad);
1322 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1323 trans->priv->reconfigure = FALSE;
1324 GST_OBJECT_UNLOCK (trans->sinkpad);
1326 /* let downstream know about our caps */
1327 gst_pad_push_event (trans->srcpad, gst_event_new_caps (outcaps));
1330 /* try to get a pool when needed */
1331 ret = gst_base_transform_do_bufferpool (trans, outcaps);
1336 gst_caps_unref (outcaps);
1338 GST_OBJECT_LOCK (trans);
1339 priv->negotiated = ret;
1340 GST_OBJECT_UNLOCK (trans);
1345 no_transform_possible:
1347 GST_WARNING_OBJECT (trans,
1348 "transform could not transform %" GST_PTR_FORMAT
1349 " in anything we support", incaps);
1355 GST_WARNING_OBJECT (trans, "FAILED to configure incaps %" GST_PTR_FORMAT
1356 " and outcaps %" GST_PTR_FORMAT, incaps, outcaps);
1363 gst_base_transform_default_propose_allocation (GstBaseTransform * trans,
1364 GstQuery * decide_query, GstQuery * query)
1368 if (decide_query == NULL) {
1369 GST_DEBUG_OBJECT (trans, "doing passthrough query");
1370 ret = gst_pad_peer_query (trans->srcpad, query);
1373 /* non-passthrough, copy all metadata, decide_query does not contain the
1374 * metadata anymore that depends on the buffer memory */
1375 n_metas = gst_query_get_n_allocation_metas (decide_query);
1376 for (i = 0; i < n_metas; i++) {
1379 api = gst_query_parse_nth_allocation_meta (decide_query, i);
1380 GST_DEBUG_OBJECT (trans, "proposing metadata %s", g_type_name (api));
1381 gst_query_add_allocation_meta (query, api);
1389 gst_base_transform_default_query (GstBaseTransform * trans,
1390 GstPadDirection direction, GstQuery * query)
1392 gboolean ret = FALSE;
1393 GstPad *pad, *otherpad;
1394 GstBaseTransformClass *klass;
1395 GstBaseTransformPrivate *priv = trans->priv;
1397 if (direction == GST_PAD_SRC) {
1398 pad = trans->srcpad;
1399 otherpad = trans->sinkpad;
1401 pad = trans->sinkpad;
1402 otherpad = trans->srcpad;
1405 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1407 switch (GST_QUERY_TYPE (query)) {
1408 case GST_QUERY_ALLOCATION:
1410 GstQuery *decide_query = NULL;
1411 gboolean negotiated;
1413 /* can only be done on the sinkpad */
1414 if (direction != GST_PAD_SINK)
1417 GST_OBJECT_LOCK (trans);
1418 if (G_UNLIKELY (!(negotiated = priv->negotiated))) {
1419 GST_DEBUG_OBJECT (trans,
1420 "not negotiated yet, can't answer ALLOCATION query");
1421 GST_OBJECT_UNLOCK (trans);
1424 if ((decide_query = trans->priv->query))
1425 gst_query_ref (decide_query);
1426 GST_OBJECT_UNLOCK (trans);
1428 GST_DEBUG_OBJECT (trans,
1429 "calling propose allocation with query %" GST_PTR_FORMAT,
1432 /* pass the query to the propose_allocation vmethod if any */
1433 if (G_LIKELY (klass->propose_allocation))
1434 ret = klass->propose_allocation (trans, decide_query, query);
1439 gst_query_unref (decide_query);
1441 GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret,
1445 case GST_QUERY_POSITION:
1449 gst_query_parse_position (query, &format, NULL);
1450 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1454 if ((direction == GST_PAD_SINK)
1455 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1457 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1458 trans->segment.position);
1460 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1461 trans->priv->position_out);
1463 gst_query_set_position (query, format, pos);
1465 ret = gst_pad_peer_query (otherpad, query);
1469 case GST_QUERY_ACCEPT_CAPS:
1473 gst_query_parse_accept_caps (query, &caps);
1474 if (klass->accept_caps) {
1475 ret = klass->accept_caps (trans, direction, caps);
1476 gst_query_set_accept_caps_result (query, ret);
1477 /* return TRUE, we answered the query */
1482 case GST_QUERY_CAPS:
1484 GstCaps *filter, *caps;
1486 gst_query_parse_caps (query, &filter);
1487 caps = gst_base_transform_query_caps (trans, pad, filter);
1488 gst_query_set_caps_result (query, caps);
1489 gst_caps_unref (caps);
1494 ret = gst_pad_peer_query (otherpad, query);
1503 gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query)
1505 GstBaseTransform *trans;
1506 GstBaseTransformClass *bclass;
1507 gboolean ret = FALSE;
1509 trans = GST_BASE_TRANSFORM (parent);
1510 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1513 ret = bclass->query (trans, GST_PAD_DIRECTION (pad), query);
1518 /* this function either returns the input buffer without incrementing the
1519 * refcount or it allocates a new (writable) buffer */
1520 static GstFlowReturn
1521 default_prepare_output_buffer (GstBaseTransform * trans,
1522 GstBuffer * inbuf, GstBuffer ** outbuf)
1524 GstBaseTransformPrivate *priv;
1525 GstFlowReturn ret = GST_FLOW_OK;
1526 GstBaseTransformClass *bclass;
1527 GstCaps *incaps, *outcaps;
1528 gsize insize, outsize;
1532 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1534 /* figure out how to allocate an output buffer */
1535 if (priv->passthrough) {
1536 /* passthrough, we will not modify the incomming buffer so we can just
1538 GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
1543 /* we can't reuse the input buffer */
1545 if (!priv->pool_active) {
1546 GST_DEBUG_OBJECT (trans, "setting pool %p active", priv->pool);
1547 if (!gst_buffer_pool_set_active (priv->pool, TRUE))
1548 goto activate_failed;
1549 priv->pool_active = TRUE;
1551 GST_DEBUG_OBJECT (trans, "using pool alloc");
1552 ret = gst_buffer_pool_acquire_buffer (priv->pool, outbuf, NULL);
1556 /* no pool, we need to figure out the size of the output buffer first */
1557 if ((bclass->transform_ip != NULL) && priv->always_in_place) {
1558 /* we want to do an in-place alloc */
1559 if (gst_buffer_is_writable (inbuf)) {
1560 GST_DEBUG_OBJECT (trans, "inplace reuse writable input buffer");
1563 GST_DEBUG_OBJECT (trans, "making writable buffer copy");
1564 /* we make a copy of the input buffer */
1565 *outbuf = gst_buffer_copy (inbuf);
1570 /* else use the transform function to get the size */
1571 incaps = gst_pad_get_current_caps (trans->sinkpad);
1572 outcaps = gst_pad_get_current_caps (trans->srcpad);
1574 GST_DEBUG_OBJECT (trans, "getting output size for alloc");
1575 /* copy transform, figure out the output size */
1576 insize = gst_buffer_get_size (inbuf);
1577 res = gst_base_transform_transform_size (trans,
1578 GST_PAD_SINK, incaps, insize, outcaps, &outsize);
1580 gst_caps_unref (incaps);
1581 gst_caps_unref (outcaps);
1586 GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
1587 *outbuf = gst_buffer_new_allocate (priv->allocator, outsize, &priv->params);
1590 /* copy the metadata */
1591 if (bclass->copy_metadata)
1592 if (!bclass->copy_metadata (trans, inbuf, *outbuf)) {
1593 /* something failed, post a warning */
1594 GST_ELEMENT_WARNING (trans, STREAM, NOT_IMPLEMENTED,
1595 ("could not copy metadata"), (NULL));
1605 GST_ELEMENT_ERROR (trans, RESOURCE, SETTINGS,
1606 ("failed to activate bufferpool"), ("failed to activate bufferpool"));
1607 return GST_FLOW_ERROR;
1611 GST_ERROR_OBJECT (trans, "unknown output size");
1612 return GST_FLOW_ERROR;
1618 GstBaseTransform *trans;
1623 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
1625 CopyMetaData *data = user_data;
1626 GstBaseTransform *trans = data->trans;
1627 GstBaseTransformClass *klass;
1628 const GstMetaInfo *info = (*meta)->info;
1629 GstBuffer *outbuf = data->outbuf;
1632 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1634 if (GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
1635 /* never call the transform_meta with pool private metadata */
1636 GST_DEBUG_OBJECT (trans, "not copying pooled metadata %s",
1637 g_type_name (info->api));
1639 } else if (gst_meta_api_type_has_tag (info->api, GST_META_TAG_MEMORY)) {
1640 /* never call the transform_meta with memory specific metadata */
1641 GST_DEBUG_OBJECT (trans, "not copying memory specific metadata %s",
1642 g_type_name (info->api));
1644 } else if (klass->transform_meta) {
1645 do_copy = klass->transform_meta (trans, outbuf, *meta, inbuf);
1646 GST_DEBUG_OBJECT (trans, "transformed metadata %s: copy: %d",
1647 g_type_name (info->api), do_copy);
1650 GST_DEBUG_OBJECT (trans, "not copying metadata %s",
1651 g_type_name (info->api));
1654 /* we only copy metadata when the subclass implemented a transform_meta
1655 * function and when it returns TRUE */
1657 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
1658 GST_DEBUG_OBJECT (trans, "copy metadata %s", g_type_name (info->api));
1659 /* simply copy then */
1660 info->transform_func (outbuf, *meta, inbuf,
1661 _gst_meta_transform_copy, ©_data);
1667 default_copy_metadata (GstBaseTransform * trans,
1668 GstBuffer * inbuf, GstBuffer * outbuf)
1670 GstBaseTransformPrivate *priv = trans->priv;
1673 /* now copy the metadata */
1674 GST_DEBUG_OBJECT (trans, "copying metadata");
1676 /* this should not happen, buffers allocated from a pool or with
1677 * new_allocate should always be writable. */
1678 if (!gst_buffer_is_writable (outbuf))
1681 /* when we get here, the metadata should be writable */
1682 gst_buffer_copy_into (outbuf, inbuf,
1683 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1685 /* clear the GAP flag when the subclass does not understand it */
1686 if (!priv->gap_aware)
1687 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
1691 data.outbuf = outbuf;
1693 gst_buffer_foreach_meta (inbuf, foreach_metadata, &data);
1700 GST_WARNING_OBJECT (trans, "buffer %p not writable", outbuf);
1705 /* Given @caps calcultate the size of one unit.
1707 * For video caps, this is the size of one frame (and thus one buffer).
1708 * For audio caps, this is the size of one sample.
1710 * These values are cached since they do not change and the calculation
1711 * potentially involves parsing caps and other expensive stuff.
1713 * We have two cache locations to store the size, one for the source caps
1714 * and one for the sink caps.
1716 * this function returns FALSE if no size could be calculated.
1719 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1722 gboolean res = FALSE;
1723 GstBaseTransformClass *bclass;
1724 GstBaseTransformPrivate *priv = trans->priv;
1726 /* see if we have the result cached */
1727 if (priv->cache_caps1 == caps) {
1728 *size = priv->cache_caps1_size;
1729 GST_DEBUG_OBJECT (trans,
1730 "returned %" G_GSIZE_FORMAT " from first cache", *size);
1733 if (priv->cache_caps2 == caps) {
1734 *size = priv->cache_caps2_size;
1735 GST_DEBUG_OBJECT (trans,
1736 "returned %" G_GSIZE_FORMAT " from second cached", *size);
1740 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1741 res = bclass->get_unit_size (trans, caps, size);
1742 GST_DEBUG_OBJECT (trans,
1743 "caps %" GST_PTR_FORMAT ") has unit size %" G_GSIZE_FORMAT ", res %s",
1744 caps, *size, res ? "TRUE" : "FALSE");
1747 /* and cache the values */
1748 if (priv->cache_caps1 == NULL) {
1749 gst_caps_replace (&priv->cache_caps1, caps);
1750 priv->cache_caps1_size = *size;
1751 GST_DEBUG_OBJECT (trans,
1752 "caching %" G_GSIZE_FORMAT " in first cache", *size);
1753 } else if (priv->cache_caps2 == NULL) {
1754 gst_caps_replace (&priv->cache_caps2, caps);
1755 priv->cache_caps2_size = *size;
1756 GST_DEBUG_OBJECT (trans,
1757 "caching %" G_GSIZE_FORMAT " in second cache", *size);
1759 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1766 gst_base_transform_sink_event (GstPad * pad, GstObject * parent,
1769 GstBaseTransform *trans;
1770 GstBaseTransformClass *bclass;
1771 gboolean ret = TRUE;
1773 trans = GST_BASE_TRANSFORM (parent);
1774 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1776 if (bclass->sink_event)
1777 ret = bclass->sink_event (trans, event);
1779 gst_event_unref (event);
1785 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1787 gboolean ret = TRUE, forward = TRUE;
1788 GstBaseTransformPrivate *priv = trans->priv;
1790 switch (GST_EVENT_TYPE (event)) {
1791 case GST_EVENT_FLUSH_START:
1793 case GST_EVENT_FLUSH_STOP:
1794 GST_OBJECT_LOCK (trans);
1795 /* reset QoS parameters */
1796 priv->proportion = 1.0;
1797 priv->earliest_time = -1;
1798 priv->discont = FALSE;
1799 priv->processed = 0;
1801 GST_OBJECT_UNLOCK (trans);
1802 /* we need new segment info after the flush. */
1803 trans->have_segment = FALSE;
1804 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1805 priv->position_out = GST_CLOCK_TIME_NONE;
1811 case GST_EVENT_CAPS:
1815 gst_event_parse_caps (event, &caps);
1816 ret = gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1821 case GST_EVENT_SEGMENT:
1823 gst_event_copy_segment (event, &trans->segment);
1824 trans->have_segment = TRUE;
1826 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1835 ret = gst_pad_push_event (trans->srcpad, event);
1837 gst_event_unref (event);
1843 gst_base_transform_src_event (GstPad * pad, GstObject * parent,
1846 GstBaseTransform *trans;
1847 GstBaseTransformClass *bclass;
1848 gboolean ret = TRUE;
1850 trans = GST_BASE_TRANSFORM (parent);
1851 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1853 if (bclass->src_event)
1854 ret = bclass->src_event (trans, event);
1856 gst_event_unref (event);
1862 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1866 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1868 switch (GST_EVENT_TYPE (event)) {
1869 case GST_EVENT_SEEK:
1871 case GST_EVENT_NAVIGATION:
1876 GstClockTimeDiff diff;
1877 GstClockTime timestamp;
1879 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1880 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1887 ret = gst_pad_push_event (trans->sinkpad, event);
1892 /* perform a transform on @inbuf and put the result in @outbuf.
1894 * This function is common to the push and pull-based operations.
1896 * This function takes ownership of @inbuf */
1897 static GstFlowReturn
1898 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1899 GstBuffer ** outbuf)
1901 GstBaseTransformClass *bclass;
1902 GstBaseTransformPrivate *priv = trans->priv;
1903 GstFlowReturn ret = GST_FLOW_OK;
1904 gboolean want_in_place;
1905 GstClockTime running_time;
1906 GstClockTime timestamp;
1907 gboolean reconfigure;
1909 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1911 GST_OBJECT_LOCK (trans->sinkpad);
1912 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1913 || priv->reconfigure;
1914 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_FLAG_NEED_RECONFIGURE);
1915 priv->reconfigure = FALSE;
1916 GST_OBJECT_UNLOCK (trans->sinkpad);
1918 if (G_UNLIKELY (reconfigure)) {
1921 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1923 incaps = gst_pad_get_current_caps (trans->sinkpad);
1925 goto no_reconfigure;
1927 /* if we need to reconfigure we pretend new caps arrived. This
1928 * will reconfigure the transform with the new output format. */
1929 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1930 gst_caps_unref (incaps);
1931 goto not_negotiated;
1933 gst_caps_unref (incaps);
1937 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1938 GST_DEBUG_OBJECT (trans,
1939 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1940 G_GUINT64_FORMAT, inbuf, gst_buffer_get_size (inbuf),
1941 GST_BUFFER_OFFSET (inbuf));
1943 GST_DEBUG_OBJECT (trans,
1944 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1945 gst_buffer_get_size (inbuf));
1947 /* Don't allow buffer handling before negotiation, except in passthrough mode
1948 * or if the class doesn't implement a set_caps function (in which case it doesn't
1951 if (!priv->negotiated && !priv->passthrough && (bclass->set_caps != NULL))
1952 goto not_negotiated;
1954 /* Set discont flag so we can mark the outgoing buffer */
1955 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1956 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1957 priv->discont = TRUE;
1960 /* can only do QoS if the segment is in TIME */
1961 if (trans->segment.format != GST_FORMAT_TIME)
1964 /* QOS is done on the running time of the buffer, get it now */
1965 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1966 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1969 if (running_time != -1) {
1971 GstClockTime earliest_time;
1974 /* lock for getting the QoS parameters that are set (in a different thread)
1975 * with the QOS events */
1976 GST_OBJECT_LOCK (trans);
1977 earliest_time = priv->earliest_time;
1978 proportion = priv->proportion;
1979 /* check for QoS, don't perform conversion for buffers
1980 * that are known to be late. */
1981 need_skip = priv->qos_enabled &&
1982 earliest_time != -1 && running_time <= earliest_time;
1983 GST_OBJECT_UNLOCK (trans);
1986 GstMessage *qos_msg;
1987 GstClockTime duration;
1988 guint64 stream_time;
1991 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1992 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1993 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1997 duration = GST_BUFFER_DURATION (inbuf);
1999 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
2001 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
2004 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
2005 stream_time, timestamp, duration);
2006 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
2007 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
2008 priv->processed, priv->dropped);
2009 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
2011 /* mark discont for next buffer */
2012 priv->discont = TRUE;
2019 /* first try to allocate an output buffer based on the currently negotiated
2020 * format. outbuf will contain a buffer suitable for doing the configured
2021 * transform after this function. */
2022 if (bclass->prepare_output_buffer == NULL)
2025 GST_DEBUG_OBJECT (trans, "calling prepare buffer");
2026 ret = bclass->prepare_output_buffer (trans, inbuf, outbuf);
2028 if (ret != GST_FLOW_OK || *outbuf == NULL)
2031 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", inbuf,
2034 /* now perform the needed transform */
2035 if (priv->passthrough) {
2036 /* In passthrough mode, give transform_ip a look at the
2037 * buffer, without making it writable, or just push the
2039 if (bclass->transform_ip_on_passthrough && bclass->transform_ip) {
2040 GST_DEBUG_OBJECT (trans, "doing passthrough transform_ip");
2041 ret = bclass->transform_ip (trans, *outbuf);
2043 GST_DEBUG_OBJECT (trans, "element is in passthrough");
2046 want_in_place = (bclass->transform_ip != NULL) && priv->always_in_place;
2048 if (want_in_place) {
2049 GST_DEBUG_OBJECT (trans, "doing inplace transform");
2050 ret = bclass->transform_ip (trans, *outbuf);
2052 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
2054 if (bclass->transform)
2055 ret = bclass->transform (trans, inbuf, *outbuf);
2057 ret = GST_FLOW_NOT_SUPPORTED;
2062 /* only unref input buffer if we allocated a new outbuf buffer. If we reused
2063 * the input buffer, no refcount is changed to keep the input buffer writable
2065 if (*outbuf != inbuf)
2066 gst_buffer_unref (inbuf);
2073 gst_buffer_unref (inbuf);
2075 GST_ELEMENT_ERROR (trans, STREAM, FORMAT,
2076 ("not negotiated"), ("not negotiated"));
2077 return GST_FLOW_NOT_NEGOTIATED;
2081 gst_buffer_unref (inbuf);
2082 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
2083 ("Sub-class has no prepare_output_buffer implementation"), (NULL));
2084 return GST_FLOW_NOT_SUPPORTED;
2088 gst_buffer_unref (inbuf);
2090 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
2091 gst_flow_get_name (ret));
2096 /* FIXME, getrange is broken, need to pull range from the other
2097 * end based on the transform_size result.
2099 static GstFlowReturn
2100 gst_base_transform_getrange (GstPad * pad, GstObject * parent, guint64 offset,
2101 guint length, GstBuffer ** buffer)
2103 GstBaseTransform *trans;
2104 GstBaseTransformClass *klass;
2106 GstBuffer *inbuf = NULL;
2108 trans = GST_BASE_TRANSFORM (parent);
2110 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
2111 if (G_UNLIKELY (ret != GST_FLOW_OK))
2114 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2115 if (klass->before_transform)
2116 klass->before_transform (trans, inbuf);
2118 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
2126 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
2127 gst_flow_get_name (ret));
2132 static GstFlowReturn
2133 gst_base_transform_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2135 GstBaseTransform *trans;
2136 GstBaseTransformClass *klass;
2137 GstBaseTransformPrivate *priv;
2139 GstClockTime position = GST_CLOCK_TIME_NONE;
2140 GstClockTime timestamp, duration;
2141 GstBuffer *outbuf = NULL;
2143 trans = GST_BASE_TRANSFORM (parent);
2146 timestamp = GST_BUFFER_TIMESTAMP (buffer);
2147 duration = GST_BUFFER_DURATION (buffer);
2149 /* calculate end position of the incoming buffer */
2150 if (timestamp != GST_CLOCK_TIME_NONE) {
2151 if (duration != GST_CLOCK_TIME_NONE)
2152 position = timestamp + duration;
2154 position = timestamp;
2157 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2158 if (klass->before_transform)
2159 klass->before_transform (trans, buffer);
2161 /* protect transform method and concurrent buffer alloc */
2162 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2164 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2165 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2166 if (outbuf != NULL) {
2167 if (ret == GST_FLOW_OK) {
2168 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2170 /* Remember last stop position */
2171 if (position != GST_CLOCK_TIME_NONE &&
2172 trans->segment.format == GST_FORMAT_TIME)
2173 trans->segment.position = position;
2175 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2176 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2177 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2178 position_out += GST_BUFFER_DURATION (outbuf);
2179 } else if (position != GST_CLOCK_TIME_NONE) {
2180 position_out = position;
2182 if (position_out != GST_CLOCK_TIME_NONE
2183 && trans->segment.format == GST_FORMAT_TIME)
2184 priv->position_out = position_out;
2186 /* apply DISCONT flag if the buffer is not yet marked as such */
2187 if (trans->priv->discont) {
2188 GST_DEBUG_OBJECT (trans, "we have a pending DISCONT");
2189 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2190 GST_DEBUG_OBJECT (trans, "marking DISCONT on output buffer");
2191 outbuf = gst_buffer_make_writable (outbuf);
2192 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2194 priv->discont = FALSE;
2198 ret = gst_pad_push (trans->srcpad, outbuf);
2200 GST_DEBUG_OBJECT (trans, "we got return %s", gst_flow_get_name (ret));
2201 gst_buffer_unref (outbuf);
2205 /* convert internal flow to OK and mark discont for the next buffer. */
2206 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2207 GST_DEBUG_OBJECT (trans, "dropped a buffer, marking DISCONT");
2208 priv->discont = TRUE;
2216 gst_base_transform_set_property (GObject * object, guint prop_id,
2217 const GValue * value, GParamSpec * pspec)
2219 GstBaseTransform *trans;
2221 trans = GST_BASE_TRANSFORM (object);
2225 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2234 gst_base_transform_get_property (GObject * object, guint prop_id,
2235 GValue * value, GParamSpec * pspec)
2237 GstBaseTransform *trans;
2239 trans = GST_BASE_TRANSFORM (object);
2243 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2246 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2251 /* not a vmethod of anything, just an internal method */
2253 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2255 GstBaseTransformClass *bclass;
2256 GstBaseTransformPrivate *priv = trans->priv;
2257 gboolean result = TRUE;
2259 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2262 GstCaps *incaps, *outcaps;
2264 if (priv->pad_mode == GST_PAD_MODE_NONE && bclass->start)
2265 result &= bclass->start (trans);
2267 incaps = gst_pad_get_current_caps (trans->sinkpad);
2268 outcaps = gst_pad_get_current_caps (trans->srcpad);
2270 GST_OBJECT_LOCK (trans);
2271 if (incaps && outcaps)
2272 priv->have_same_caps =
2273 gst_caps_is_equal (incaps, outcaps) || priv->passthrough;
2275 priv->have_same_caps = priv->passthrough;
2276 GST_DEBUG_OBJECT (trans, "have_same_caps %d", priv->have_same_caps);
2277 priv->negotiated = FALSE;
2278 trans->have_segment = FALSE;
2279 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2280 priv->position_out = GST_CLOCK_TIME_NONE;
2281 priv->proportion = 1.0;
2282 priv->earliest_time = -1;
2283 priv->discont = FALSE;
2284 priv->processed = 0;
2286 GST_OBJECT_UNLOCK (trans);
2289 gst_caps_unref (incaps);
2291 gst_caps_unref (outcaps);
2293 /* We must make sure streaming has finished before resetting things
2294 * and calling the ::stop vfunc */
2295 GST_PAD_STREAM_LOCK (trans->sinkpad);
2296 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2298 priv->have_same_caps = FALSE;
2299 /* We can only reset the passthrough mode if the instance told us to
2300 handle it in configure_caps */
2301 if (bclass->passthrough_on_same_caps) {
2302 gst_base_transform_set_passthrough (trans, FALSE);
2304 gst_caps_replace (&priv->cache_caps1, NULL);
2305 gst_caps_replace (&priv->cache_caps2, NULL);
2307 if (priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
2308 result &= bclass->stop (trans);
2310 gst_base_transform_set_allocation (trans, NULL, NULL, NULL, NULL);
2317 gst_base_transform_sink_activate_mode (GstPad * pad, GstObject * parent,
2318 GstPadMode mode, gboolean active)
2320 gboolean result = FALSE;
2321 GstBaseTransform *trans;
2323 trans = GST_BASE_TRANSFORM (parent);
2326 case GST_PAD_MODE_PUSH:
2328 result = gst_base_transform_activate (trans, active);
2331 trans->priv->pad_mode = active ? GST_PAD_MODE_PUSH : GST_PAD_MODE_NONE;
2343 gst_base_transform_src_activate_mode (GstPad * pad, GstObject * parent,
2344 GstPadMode mode, gboolean active)
2346 gboolean result = FALSE;
2347 GstBaseTransform *trans;
2349 trans = GST_BASE_TRANSFORM (parent);
2352 case GST_PAD_MODE_PULL:
2355 gst_pad_activate_mode (trans->sinkpad, GST_PAD_MODE_PULL, active);
2358 result &= gst_base_transform_activate (trans, active);
2361 trans->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
2373 * gst_base_transform_set_passthrough:
2374 * @trans: the #GstBaseTransform to set
2375 * @passthrough: boolean indicating passthrough mode.
2377 * Set passthrough mode for this filter by default. This is mostly
2378 * useful for filters that do not care about negotiation.
2380 * Always TRUE for filters which don't implement either a transform
2381 * or transform_ip method.
2386 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2387 gboolean passthrough)
2389 GstBaseTransformClass *bclass;
2391 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2393 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2395 GST_OBJECT_LOCK (trans);
2396 if (passthrough == FALSE) {
2397 if (bclass->transform_ip || bclass->transform)
2398 trans->priv->passthrough = FALSE;
2400 trans->priv->passthrough = TRUE;
2403 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->priv->passthrough);
2404 GST_OBJECT_UNLOCK (trans);
2408 * gst_base_transform_is_passthrough:
2409 * @trans: the #GstBaseTransform to query
2411 * See if @trans is configured as a passthrough transform.
2413 * Returns: TRUE is the transform is configured in passthrough mode.
2418 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2422 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2424 GST_OBJECT_LOCK (trans);
2425 result = trans->priv->passthrough;
2426 GST_OBJECT_UNLOCK (trans);
2432 * gst_base_transform_set_in_place:
2433 * @trans: the #GstBaseTransform to modify
2434 * @in_place: Boolean value indicating that we would like to operate
2435 * on in_place buffers.
2437 * Determines whether a non-writable buffer will be copied before passing
2438 * to the transform_ip function.
2440 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2441 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2447 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2449 GstBaseTransformClass *bclass;
2451 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2453 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2455 GST_OBJECT_LOCK (trans);
2458 if (bclass->transform_ip) {
2459 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2460 trans->priv->always_in_place = TRUE;
2463 if (bclass->transform) {
2464 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2465 trans->priv->always_in_place = FALSE;
2469 GST_OBJECT_UNLOCK (trans);
2473 * gst_base_transform_is_in_place:
2474 * @trans: the #GstBaseTransform to query
2476 * See if @trans is configured as a in_place transform.
2478 * Returns: TRUE is the transform is configured in in_place mode.
2483 gst_base_transform_is_in_place (GstBaseTransform * trans)
2487 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2489 GST_OBJECT_LOCK (trans);
2490 result = trans->priv->always_in_place;
2491 GST_OBJECT_UNLOCK (trans);
2497 * gst_base_transform_update_qos:
2498 * @trans: a #GstBaseTransform
2499 * @proportion: the proportion
2500 * @diff: the diff against the clock
2501 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2504 * Set the QoS parameters in the transform. This function is called internally
2505 * when a QOS event is received but subclasses can provide custom information
2513 gst_base_transform_update_qos (GstBaseTransform * trans,
2514 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2516 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2518 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2519 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2520 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2522 GST_OBJECT_LOCK (trans);
2523 trans->priv->proportion = proportion;
2524 trans->priv->earliest_time = timestamp + diff;
2525 GST_OBJECT_UNLOCK (trans);
2529 * gst_base_transform_set_qos_enabled:
2530 * @trans: a #GstBaseTransform
2531 * @enabled: new state
2533 * Enable or disable QoS handling in the transform.
2540 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2542 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2544 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2546 GST_OBJECT_LOCK (trans);
2547 trans->priv->qos_enabled = enabled;
2548 GST_OBJECT_UNLOCK (trans);
2552 * gst_base_transform_is_qos_enabled:
2553 * @trans: a #GstBaseTransform
2555 * Queries if the transform will handle QoS.
2557 * Returns: TRUE if QoS is enabled.
2564 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2568 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2570 GST_OBJECT_LOCK (trans);
2571 result = trans->priv->qos_enabled;
2572 GST_OBJECT_UNLOCK (trans);
2578 * gst_base_transform_set_gap_aware:
2579 * @trans: a #GstBaseTransform
2580 * @gap_aware: New state
2582 * If @gap_aware is %FALSE (the default), output buffers will have the
2583 * %GST_BUFFER_FLAG_GAP flag unset.
2585 * If set to %TRUE, the element must handle output buffers with this flag set
2586 * correctly, i.e. it can assume that the buffer contains neutral data but must
2587 * unset the flag if the output is no neutral data.
2594 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2596 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2598 GST_OBJECT_LOCK (trans);
2599 trans->priv->gap_aware = gap_aware;
2600 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2601 GST_OBJECT_UNLOCK (trans);
2605 * gst_base_transform_reconfigure_sink:
2606 * @trans: a #GstBaseTransform
2608 * Instructs @trans to request renegotiation upstream. This function is
2609 * typically called after properties on the transform were set that
2610 * influence the input format.
2613 gst_base_transform_reconfigure_sink (GstBaseTransform * trans)
2615 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2617 /* push the renegotiate event */
2618 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2619 gst_event_new_reconfigure ()))
2620 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2624 * gst_base_transform_reconfigure_src:
2625 * @trans: a #GstBaseTransform
2627 * Instructs @trans to renegotiate a new downstream transform on the next
2628 * buffer. This function is typically called after properties on the transform
2629 * were set that influence the output format.
2634 gst_base_transform_reconfigure_src (GstBaseTransform * trans)
2636 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2638 GST_OBJECT_LOCK (trans);
2639 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2640 trans->priv->reconfigure = TRUE;
2641 GST_OBJECT_UNLOCK (trans);