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 "gstbasetransform.h"
211 #include <gst/gstmarshal.h>
213 GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
214 #define GST_CAT_DEFAULT gst_base_transform_debug
216 /* BaseTransform signals and args */
223 #define DEFAULT_PROP_QOS FALSE
231 #define GST_BASE_TRANSFORM_GET_PRIVATE(obj) \
232 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_TRANSFORM, GstBaseTransformPrivate))
234 struct _GstBaseTransformPrivate
236 /* QoS *//* with LOCK */
237 gboolean qos_enabled;
239 GstClockTime earliest_time;
240 /* previous buffer had a discont */
243 GstActivateMode pad_mode;
247 gboolean reconfigure;
253 GstClockTime position_out;
256 const GstAllocator *allocator;
261 static GstElementClass *parent_class = NULL;
263 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
264 static void gst_base_transform_init (GstBaseTransform * trans,
265 GstBaseTransformClass * klass);
266 static GstFlowReturn gst_base_transform_prepare_output_buffer (GstBaseTransform
267 * trans, GstBuffer * input, GstBuffer ** buf);
270 gst_base_transform_get_type (void)
272 static volatile gsize base_transform_type = 0;
274 if (g_once_init_enter (&base_transform_type)) {
276 static const GTypeInfo base_transform_info = {
277 sizeof (GstBaseTransformClass),
280 (GClassInitFunc) gst_base_transform_class_init,
283 sizeof (GstBaseTransform),
285 (GInstanceInitFunc) gst_base_transform_init,
288 _type = g_type_register_static (GST_TYPE_ELEMENT,
289 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
290 g_once_init_leave (&base_transform_type, _type);
292 return base_transform_type;
295 static void gst_base_transform_finalize (GObject * object);
296 static void gst_base_transform_set_property (GObject * object, guint prop_id,
297 const GValue * value, GParamSpec * pspec);
298 static void gst_base_transform_get_property (GObject * object, guint prop_id,
299 GValue * value, GParamSpec * pspec);
300 static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
302 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
304 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
306 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
307 GstCaps * caps, gsize * size);
309 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
310 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
312 static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
313 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
315 static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
316 guint length, GstBuffer ** buffer);
317 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
319 static GstCaps *gst_base_transform_getcaps (GstPad * pad, GstCaps * filter);
320 static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
321 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
322 GstPadDirection direction, GstCaps * caps);
323 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
324 GstPad * pad, GstCaps * caps);
325 static gboolean gst_base_transform_query (GstPad * pad, GstQuery * query);
326 static const GstQueryType *gst_base_transform_query_type (GstPad * pad);
328 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
331 gst_base_transform_finalize (GObject * object)
333 GstBaseTransform *trans;
335 trans = GST_BASE_TRANSFORM (object);
337 g_mutex_free (trans->transform_lock);
339 G_OBJECT_CLASS (parent_class)->finalize (object);
343 gst_base_transform_class_init (GstBaseTransformClass * klass)
345 GObjectClass *gobject_class;
347 gobject_class = G_OBJECT_CLASS (klass);
349 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
350 "basetransform element");
352 GST_DEBUG ("gst_base_transform_class_init");
354 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
356 parent_class = g_type_class_peek_parent (klass);
358 gobject_class->set_property = gst_base_transform_set_property;
359 gobject_class->get_property = gst_base_transform_get_property;
361 g_object_class_install_property (gobject_class, PROP_QOS,
362 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
363 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
365 gobject_class->finalize = gst_base_transform_finalize;
367 klass->passthrough_on_same_caps = FALSE;
368 klass->event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
369 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
371 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
375 gst_base_transform_init (GstBaseTransform * trans,
376 GstBaseTransformClass * bclass)
378 GstPadTemplate *pad_template;
380 GST_DEBUG ("gst_base_transform_init");
382 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
385 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
386 g_return_if_fail (pad_template != NULL);
387 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
388 gst_pad_set_getcaps_function (trans->sinkpad,
389 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
390 gst_pad_set_acceptcaps_function (trans->sinkpad,
391 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
392 gst_pad_set_event_function (trans->sinkpad,
393 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
394 gst_pad_set_chain_function (trans->sinkpad,
395 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
396 gst_pad_set_activatepush_function (trans->sinkpad,
397 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
398 gst_pad_set_query_function (trans->sinkpad,
399 GST_DEBUG_FUNCPTR (gst_base_transform_query));
400 gst_pad_set_query_type_function (trans->sinkpad,
401 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
402 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
405 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
406 g_return_if_fail (pad_template != NULL);
407 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
408 gst_pad_set_getcaps_function (trans->srcpad,
409 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
410 gst_pad_set_acceptcaps_function (trans->srcpad,
411 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
412 gst_pad_set_event_function (trans->srcpad,
413 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
414 gst_pad_set_getrange_function (trans->srcpad,
415 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
416 gst_pad_set_activatepull_function (trans->srcpad,
417 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
418 gst_pad_set_query_function (trans->srcpad,
419 GST_DEBUG_FUNCPTR (gst_base_transform_query));
420 gst_pad_set_query_type_function (trans->srcpad,
421 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
422 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
424 trans->transform_lock = g_mutex_new ();
425 trans->pending_configure = FALSE;
426 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
427 trans->cache_caps1 = NULL;
428 trans->cache_caps2 = NULL;
429 trans->priv->pad_mode = GST_ACTIVATE_NONE;
430 trans->priv->gap_aware = FALSE;
432 trans->passthrough = FALSE;
433 if (bclass->transform == NULL) {
434 /* If no transform function, always_in_place is TRUE */
435 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
436 trans->always_in_place = TRUE;
438 if (bclass->transform_ip == NULL) {
439 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
440 trans->passthrough = TRUE;
444 trans->priv->processed = 0;
445 trans->priv->dropped = 0;
448 /* given @caps on the src or sink pad (given by @direction)
449 * calculate the possible caps on the other pad.
451 * Returns new caps, unref after usage.
454 gst_base_transform_transform_caps (GstBaseTransform * trans,
455 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
458 GstBaseTransformClass *klass;
463 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
465 /* if there is a custom transform function, use this */
466 if (klass->transform_caps) {
468 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
470 GST_LOG_OBJECT (trans, "from: %" GST_PTR_FORMAT, caps);
471 ret = klass->transform_caps (trans, direction, caps, filter);
472 GST_LOG_OBJECT (trans, " to: %" GST_PTR_FORMAT, ret);
474 #ifndef G_DISABLE_ASSERT
476 if (!gst_caps_is_subset (ret, filter)) {
477 GstCaps *intersection;
479 GST_ERROR_OBJECT (trans,
480 "transform_caps returned caps %" GST_PTR_FORMAT
481 " which are not a real subset of the filter caps %"
482 GST_PTR_FORMAT, ret, filter);
483 g_warning ("%s: transform_caps returned caps which are not a real "
484 "subset of the filter caps", GST_ELEMENT_NAME (trans));
487 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
488 gst_caps_unref (intersection);
494 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
495 /* no transform function, use the identity transform */
497 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
499 ret = gst_caps_ref (caps);
503 GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
509 /* transform a buffer of @size with @caps on the pad with @direction to
510 * the size of a buffer with @othercaps and store the result in @othersize
512 * We have two ways of doing this:
513 * 1) use a custom transform size function, this is for complicated custom
514 * cases with no fixed unit_size.
515 * 2) use the unit_size functions where there is a relationship between the
516 * caps and the size of a buffer.
519 gst_base_transform_transform_size (GstBaseTransform * trans,
520 GstPadDirection direction, GstCaps * caps,
521 gsize size, GstCaps * othercaps, gsize * othersize)
523 gsize inunitsize, outunitsize, units;
524 GstBaseTransformClass *klass;
527 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
529 GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
530 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
531 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
533 if (klass->transform_size) {
534 /* if there is a custom transform function, use this */
535 ret = klass->transform_size (trans, direction, caps, size, othercaps,
537 } else if (klass->get_unit_size == NULL) {
538 /* if there is no transform_size and no unit_size, it means the
539 * element does not modify the size of a buffer */
543 /* there is no transform_size function, we have to use the unit_size
544 * functions. This method assumes there is a fixed unit_size associated with
545 * each caps. We provide the same amount of units on both sides. */
546 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
549 GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
552 /* input size must be a multiple of the unit_size of the input caps */
553 if (inunitsize == 0 || (size % inunitsize != 0))
556 /* get the amount of units */
557 units = size / inunitsize;
559 /* now get the unit size of the output */
560 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
563 /* the output size is the unit_size times the amount of units on the
565 *othersize = units * outunitsize;
566 GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
575 GST_DEBUG_OBJECT (trans, "could not get in_size");
576 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
581 GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size,
583 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
584 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
589 GST_DEBUG_OBJECT (trans, "could not get out_size");
590 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
595 /* get the caps that can be handled by @pad. We perform:
597 * - take the caps of peer of otherpad,
598 * - filter against the padtemplate of otherpad,
599 * - calculate all transforms of remaining caps
600 * - filter against template of @pad
602 * If there is no peer, we simply return the caps of the padtemplate of pad.
605 gst_base_transform_getcaps (GstPad * pad, GstCaps * filter)
607 GstBaseTransform *trans;
609 GstCaps *peercaps, *caps, *peerfilter = NULL;
611 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
613 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
615 /* we can do what the peer can */
617 GstCaps *temp, *templ;
619 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
621 /* filtered against our padtemplate on the other side */
622 templ = gst_pad_get_pad_template_caps (pad);
623 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
624 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
625 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
626 gst_caps_unref (templ);
628 /* then see what we can transform this to */
629 peerfilter = gst_base_transform_transform_caps (trans,
630 GST_PAD_DIRECTION (pad), temp, NULL);
631 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
632 gst_caps_unref (temp);
634 /* and filter against the template of this pad */
635 templ = gst_pad_get_pad_template_caps (otherpad);
636 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
637 /* We keep the caps sorted like the returned caps */
639 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
640 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
641 gst_caps_unref (peerfilter);
642 gst_caps_unref (templ);
646 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
649 gst_caps_unref (peerfilter);
652 GstCaps *temp, *templ;
654 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
656 /* filtered against our padtemplate on the other side */
657 templ = gst_pad_get_pad_template_caps (otherpad);
658 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
659 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
660 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
661 gst_caps_unref (templ);
663 /* then see what we can transform this to */
664 caps = gst_base_transform_transform_caps (trans,
665 GST_PAD_DIRECTION (otherpad), temp, filter);
666 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
667 gst_caps_unref (temp);
671 /* and filter against the template of this pad */
672 templ = gst_pad_get_pad_template_caps (pad);
673 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
674 /* We keep the caps sorted like the returned caps */
675 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
676 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
677 gst_caps_unref (caps);
678 gst_caps_unref (templ);
681 /* Now try if we can put the untransformed downstream caps first */
682 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
683 if (!gst_caps_is_empty (temp)) {
684 gst_caps_merge (temp, caps);
687 gst_caps_unref (temp);
690 /* no peer or the peer can do anything, our padtemplate is enough then */
691 caps = gst_pad_get_pad_template_caps (pad);
696 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
697 gst_caps_unref (caps);
703 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
706 gst_caps_unref (peercaps);
708 gst_object_unref (trans);
714 gst_base_transform_set_allocation (GstBaseTransform * trans,
715 GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
718 GstBufferPool *oldpool;
719 GstBaseTransformPrivate *priv = trans->priv;
723 if (!gst_buffer_pool_set_active (pool, TRUE))
724 goto activate_failed;
727 GST_OBJECT_LOCK (trans);
728 oldpool = priv->pool;
730 priv->allocator = allocator;
731 priv->prefix = prefix;
732 priv->alignment = alignment;
733 GST_OBJECT_UNLOCK (trans);
736 gst_buffer_pool_set_active (oldpool, FALSE);
737 gst_object_unref (oldpool);
744 GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
750 gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
753 gboolean result = TRUE;
754 GstBufferPool *pool = NULL, *oldpool;
755 guint size, min, max, prefix, alignment;
756 GstBaseTransformClass *klass;
757 const GstAllocator *allocator = NULL;
759 /* there are these possibilities:
761 * 1) we negotiated passthrough, we can proxy the bufferpool directly.
766 oldpool = trans->priv->pool;
768 gst_buffer_pool_set_active (oldpool, FALSE);
769 gst_object_unref (oldpool);
770 trans->priv->pool = oldpool = NULL;
773 if (trans->passthrough) {
774 /* we are in passthrough, the input buffer is never copied and always passed
775 * along. We never allocate an output buffer on the srcpad. What we do is
776 * let the upstream element decide if it wants to use a bufferpool and
777 * then we will proxy the downstream pool */
778 GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
782 /* not passthrough, we need to allocate */
783 /* find a pool for the negotiated caps now */
784 query = gst_query_new_allocation (outcaps, TRUE);
785 if (!gst_pad_peer_query (trans->srcpad, query)) {
786 /* not a problem, just debug a little */
787 GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
790 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
792 if (G_LIKELY (klass->setup_allocation))
793 result = klass->setup_allocation (trans, query);
795 /* we got configuration from our peer, parse them */
796 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
798 gst_query_unref (query);
801 const gchar *mem = NULL;
803 /* no size, we have variable size buffers */
804 if (gst_query_get_n_allocation_memories (query) > 0) {
805 mem = gst_query_parse_nth_allocation_memory (query, 0);
807 allocator = gst_allocator_find (mem);
808 } else if (pool == NULL) {
809 GstStructure *config;
811 /* we did not get a pool, make one ourselves then */
812 pool = gst_buffer_pool_new ();
814 config = gst_buffer_pool_get_config (pool);
815 gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
817 gst_buffer_pool_set_config (pool, config);
822 gst_base_transform_set_allocation (trans, pool, allocator, prefix,
828 /* function triggered when the in and out caps are negotiated and need
829 * to be configured in the subclass. */
831 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
835 GstBaseTransformClass *klass;
837 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
839 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
840 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
842 /* clear the cache */
843 gst_caps_replace (&trans->cache_caps1, NULL);
844 gst_caps_replace (&trans->cache_caps2, NULL);
846 /* figure out same caps state */
847 trans->have_same_caps = gst_caps_is_equal (in, out);
848 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
850 /* If we've a transform_ip method and same input/output caps, set in_place
851 * by default. If for some reason the sub-class prefers using a transform
852 * function, it can clear the in place flag in the set_caps */
853 gst_base_transform_set_in_place (trans,
854 klass->transform_ip && trans->have_same_caps);
856 /* Set the passthrough if the class wants passthrough_on_same_caps
857 * and we have the same caps on each pad */
858 if (klass->passthrough_on_same_caps)
859 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
861 /* now configure the element with the caps */
862 if (klass->set_caps) {
863 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
864 ret = klass->set_caps (trans, in, out);
867 trans->negotiated = ret;
872 /* given a fixed @caps on @pad, create the best possible caps for the
874 * @caps must be fixed when calling this function.
876 * This function calls the transform caps vmethod of the basetransform to figure
877 * out the possible target formats. It then tries to select the best format from
880 * - attempt passthrough if the target caps is a superset of the input caps
881 * - fixating by using peer caps
882 * - fixating with transform fixate function
883 * - fixating with pad fixate functions.
885 * this function returns a caps that can be transformed into and is accepted by
889 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
892 GstBaseTransformClass *klass;
893 GstPad *otherpad, *otherpeer;
895 gboolean peer_checked = FALSE;
898 /* caps must be fixed here, this is a programming error if it's not */
899 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
901 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
903 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
904 otherpeer = gst_pad_get_peer (otherpad);
906 /* see how we can transform the input caps. We need to do this even for
907 * passthrough because it might be possible that this element cannot support
908 * passthrough at all. */
909 othercaps = gst_base_transform_transform_caps (trans,
910 GST_PAD_DIRECTION (pad), caps, NULL);
912 /* The caps we can actually output is the intersection of the transformed
913 * caps with the pad template for the pad */
915 GstCaps *intersect, *templ_caps;
917 templ_caps = gst_pad_get_pad_template_caps (otherpad);
918 GST_DEBUG_OBJECT (trans,
919 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
922 gst_caps_intersect_full (othercaps, templ_caps,
923 GST_CAPS_INTERSECT_FIRST);
925 gst_caps_unref (othercaps);
926 gst_caps_unref (templ_caps);
927 othercaps = intersect;
930 /* check if transform is empty */
931 if (!othercaps || gst_caps_is_empty (othercaps))
934 /* if the othercaps are not fixed, we need to fixate them, first attempt
935 * is by attempting passthrough if the othercaps are a superset of caps. */
936 /* FIXME. maybe the caps is not fixed because it has multiple structures of
938 is_fixed = gst_caps_is_fixed (othercaps);
940 GST_DEBUG_OBJECT (trans,
941 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
943 /* Now let's see what the peer suggests based on our transformed caps */
945 GstCaps *peercaps, *intersection, *templ_caps;
947 GST_DEBUG_OBJECT (trans,
948 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
950 peercaps = gst_pad_get_caps (otherpeer, othercaps);
951 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
953 templ_caps = gst_pad_get_pad_template_caps (otherpad);
955 GST_DEBUG_OBJECT (trans,
956 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
959 gst_caps_intersect_full (peercaps, templ_caps,
960 GST_CAPS_INTERSECT_FIRST);
961 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
962 gst_caps_unref (peercaps);
963 gst_caps_unref (templ_caps);
964 peercaps = intersection;
966 GST_DEBUG_OBJECT (trans,
967 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
969 gst_caps_intersect_full (peercaps, othercaps,
970 GST_CAPS_INTERSECT_FIRST);
971 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
972 gst_caps_unref (peercaps);
973 gst_caps_unref (othercaps);
974 othercaps = intersection;
975 is_fixed = gst_caps_is_fixed (othercaps);
978 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
979 gst_caps_unref (othercaps);
980 othercaps = gst_caps_ref (caps);
984 if (gst_caps_is_empty (othercaps))
985 goto no_transform_possible;
987 /* second attempt at fixation, call the fixate vmethod and
988 * ultimately call the pad fixate function. */
990 GST_DEBUG_OBJECT (trans,
991 "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
992 othercaps, GST_DEBUG_PAD_NAME (otherpad));
994 /* since we have no other way to fixate left, we might as well just take
995 * the first of the caps list and fixate that */
997 /* FIXME: when fixating using the vmethod, it might make sense to fixate
998 * each of the caps; but Wim doesn't see a use case for that yet */
999 gst_caps_truncate (othercaps);
1000 peer_checked = FALSE;
1002 if (klass->fixate_caps) {
1003 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1004 " using caps %" GST_PTR_FORMAT
1005 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1006 GST_DEBUG_PAD_NAME (otherpad));
1007 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1008 is_fixed = gst_caps_is_fixed (othercaps);
1010 /* if still not fixed, no other option but to let the default pad fixate
1011 * function do its job */
1013 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
1014 " on pad %s:%s using gst_pad_fixate_caps", othercaps,
1015 GST_DEBUG_PAD_NAME (otherpad));
1016 gst_pad_fixate_caps (otherpad, othercaps);
1017 is_fixed = gst_caps_is_fixed (othercaps);
1019 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
1021 GST_DEBUG ("caps are fixed");
1022 /* else caps are fixed but the subclass may want to add fields */
1023 if (klass->fixate_caps) {
1024 othercaps = gst_caps_make_writable (othercaps);
1026 GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
1027 " using caps %" GST_PTR_FORMAT
1028 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
1029 GST_DEBUG_PAD_NAME (otherpad));
1031 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
1032 is_fixed = gst_caps_is_fixed (othercaps);
1036 /* caps should be fixed now, if not we have to fail. */
1038 goto could_not_fixate;
1040 /* and peer should accept, don't check again if we already checked the
1041 * othercaps against the peer. */
1042 if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
1043 goto peer_no_accept;
1045 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
1046 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
1049 gst_object_unref (otherpeer);
1056 GST_DEBUG_OBJECT (trans,
1057 "transform returned useless %" GST_PTR_FORMAT, othercaps);
1060 no_transform_possible:
1062 GST_DEBUG_OBJECT (trans,
1063 "transform could not transform %" GST_PTR_FORMAT
1064 " in anything we support", caps);
1069 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
1074 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
1075 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1081 gst_object_unref (otherpeer);
1083 gst_caps_unref (othercaps);
1089 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1090 GstPadDirection direction, GstCaps * caps)
1094 GstCaps *othercaps = NULL;
1096 gboolean ret = TRUE;
1099 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1101 /* we need fixed caps for the check, fall back to the default implementation
1103 if (!gst_caps_is_fixed (caps))
1108 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1110 /* get all the formats we can handle on this pad */
1111 if (direction == GST_PAD_SRC)
1112 allowed = gst_pad_get_caps (trans->srcpad, NULL);
1114 allowed = gst_pad_get_caps (trans->sinkpad, NULL);
1117 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1118 goto no_transform_possible;
1121 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1123 /* intersect with the requested format */
1124 ret = gst_caps_can_intersect (allowed, caps);
1125 gst_caps_unref (allowed);
1128 goto no_transform_possible;
1132 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1134 /* find best possible caps for the other pad as a way to see if we can
1135 * transform this caps. */
1136 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1137 if (!othercaps || gst_caps_is_empty (othercaps))
1138 goto no_transform_possible;
1140 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1146 /* We know it's always NULL since we never use it */
1148 gst_caps_unref (othercaps);
1154 no_transform_possible:
1156 GST_DEBUG_OBJECT (trans,
1157 "transform could not transform %" GST_PTR_FORMAT
1158 " in anything we support", caps);
1165 gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
1167 gboolean ret = TRUE;
1168 GstBaseTransform *trans;
1169 GstBaseTransformClass *bclass;
1171 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1172 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1174 if (bclass->accept_caps)
1175 ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
1177 gst_object_unref (trans);
1182 /* called when new caps arrive on the sink or source pad,
1183 * We try to find the best caps for the other side using our _find_transform()
1184 * function. If there are caps, we configure the transform for this new
1187 * FIXME, this function is currently commutative but this should not really be
1188 * because we never set caps starting from the srcpad.
1191 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1194 GstPad *otherpad, *otherpeer;
1195 GstCaps *othercaps = NULL;
1196 gboolean ret = TRUE;
1197 GstCaps *incaps, *outcaps;
1199 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1200 otherpeer = gst_pad_get_peer (otherpad);
1202 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1204 /* find best possible caps for the other pad */
1205 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1206 if (!othercaps || gst_caps_is_empty (othercaps))
1207 goto no_transform_possible;
1209 /* configure the element now */
1210 /* make sure in and out caps are correct */
1211 if (pad == trans->sinkpad) {
1213 outcaps = othercaps;
1219 /* if we have the same caps, we can optimize and reuse the input caps */
1220 if (gst_caps_is_equal (incaps, outcaps)) {
1221 GST_INFO_OBJECT (trans, "reuse caps");
1222 gst_caps_unref (othercaps);
1223 outcaps = othercaps = gst_caps_ref (incaps);
1226 /* call configure now */
1227 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1228 goto failed_configure;
1230 GST_OBJECT_LOCK (trans->sinkpad);
1231 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1232 trans->priv->reconfigure = FALSE;
1233 GST_OBJECT_UNLOCK (trans->sinkpad);
1235 /* we know this will work, we implement the setcaps */
1236 gst_pad_push_event (otherpad, gst_event_new_caps (othercaps));
1238 if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
1240 ret &= gst_pad_push_event (otherpeer, gst_event_new_caps (othercaps));
1242 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1248 /* try to get a pool when needed */
1249 gst_base_transform_do_bufferpool (trans, othercaps);
1254 gst_object_unref (otherpeer);
1256 gst_caps_unref (othercaps);
1258 trans->negotiated = ret;
1263 no_transform_possible:
1265 GST_WARNING_OBJECT (trans,
1266 "transform could not transform %" GST_PTR_FORMAT
1267 " in anything we support", caps);
1273 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1274 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1281 gst_base_transform_query (GstPad * pad, GstQuery * query)
1283 gboolean ret = FALSE;
1284 GstBaseTransform *trans;
1287 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1288 if (G_UNLIKELY (trans == NULL))
1290 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1292 switch (GST_QUERY_TYPE (query)) {
1293 case GST_QUERY_ALLOCATION:
1295 gboolean passthrough;
1297 /* can only be done on the sinkpad */
1298 if (!GST_PAD_IS_SINK (pad))
1301 GST_BASE_TRANSFORM_LOCK (trans);
1302 passthrough = trans->passthrough || trans->always_in_place;
1303 GST_BASE_TRANSFORM_UNLOCK (trans);
1305 GST_DEBUG_OBJECT (trans, "passthrough %d", passthrough);
1308 ret = gst_pad_peer_query (otherpad, query);
1313 case GST_QUERY_POSITION:
1317 gst_query_parse_position (query, &format, NULL);
1318 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1322 if ((pad == trans->sinkpad)
1323 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1325 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1326 trans->segment.position);
1328 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1329 trans->priv->position_out);
1331 gst_query_set_position (query, format, pos);
1333 ret = gst_pad_peer_query (otherpad, query);
1338 ret = gst_pad_peer_query (otherpad, query);
1343 gst_object_unref (trans);
1347 static const GstQueryType *
1348 gst_base_transform_query_type (GstPad * pad)
1350 static const GstQueryType types[] = {
1358 /* Allocate a buffer using gst_pad_alloc_buffer
1360 * This function can do renegotiation on the source pad
1362 * The output buffer is always writable. outbuf can be equal to
1363 * inbuf, the caller should be prepared for this and perform
1364 * appropriate refcounting.
1366 static GstFlowReturn
1367 gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
1368 GstBuffer * in_buf, GstBuffer ** out_buf)
1370 GstBaseTransformClass *bclass;
1371 GstBaseTransformPrivate *priv;
1372 GstFlowReturn ret = GST_FLOW_OK;
1374 gsize insize, outsize;
1375 GstCaps *incaps = NULL, *outcaps = NULL;
1377 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1383 insize = gst_buffer_get_size (in_buf);
1385 /* figure out how to allocate a buffer based on the current configuration */
1386 if (trans->passthrough) {
1387 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1388 /* passthrough, the output size is the same as the input size. */
1391 gboolean want_in_place = (bclass->transform_ip != NULL)
1392 && trans->always_in_place;
1394 if (want_in_place) {
1395 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1396 /* we alloc a buffer of the same size as the input */
1399 incaps = gst_pad_get_current_caps (trans->sinkpad);
1400 outcaps = gst_pad_get_current_caps (trans->srcpad);
1402 GST_DEBUG_OBJECT (trans, "getting output size for copy transform");
1403 /* copy transform, figure out the output size */
1404 if (!gst_base_transform_transform_size (trans,
1405 GST_PAD_SINK, incaps, insize, outcaps, &outsize)) {
1411 if (bclass->prepare_output_buffer) {
1412 if (outcaps == NULL)
1413 outcaps = gst_pad_get_current_caps (trans->srcpad);
1415 GST_DEBUG_OBJECT (trans,
1416 "calling prepare buffer with caps %p %" GST_PTR_FORMAT, outcaps,
1419 bclass->prepare_output_buffer (trans, in_buf, outsize, outcaps,
1422 /* get a new ref to the srcpad caps, the prepare_output_buffer function can
1423 * update the pad caps if it wants */
1425 gst_caps_unref (outcaps);
1426 outcaps = gst_pad_get_current_caps (trans->srcpad);
1429 * decrease refcount again if vmethod returned refcounted in_buf. This
1430 * is because we need to make sure that the buffer is writable for the
1431 * in_place transform. The docs of the vmethod say that you should return
1432 * a reffed inbuf, which is exactly what we don't want :), oh well.. */
1433 if (in_buf == *out_buf)
1434 gst_buffer_unref (in_buf);
1437 if (ret != GST_FLOW_OK)
1440 if (*out_buf == NULL) {
1441 if (trans->passthrough) {
1442 GST_DEBUG_OBJECT (trans, "Reusing input buffer");
1444 } else if (priv->pool) {
1445 GST_DEBUG_OBJECT (trans, "using pool alloc");
1446 ret = gst_buffer_pool_acquire_buffer (priv->pool, out_buf, NULL);
1448 GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
1450 gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
1454 if (ret != GST_FLOW_OK)
1457 /* must always have a buffer by now */
1458 if (*out_buf == NULL)
1461 if (trans->passthrough && in_buf != *out_buf) {
1462 /* we are asked to perform a passthrough transform but the input and
1463 * output buffers are different. We have to discard the output buffer and
1464 * reuse the input buffer. */
1465 GST_DEBUG_OBJECT (trans, "passthrough but different buffers");
1466 gst_buffer_unref (*out_buf);
1469 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", in_buf,
1472 /* if we have different buffers, check if the metadata is ok */
1474 if (*out_buf != in_buf) {
1477 mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
1478 GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
1479 GST_BUFFER_FLAG_GAP | GST_BUFFER_FLAG_MEDIA1 |
1480 GST_BUFFER_FLAG_MEDIA2 | GST_BUFFER_FLAG_MEDIA3;
1481 /* see if the flags and timestamps match */
1483 (GST_MINI_OBJECT_FLAGS (*out_buf) & mask) ==
1484 (GST_MINI_OBJECT_FLAGS (in_buf) & mask);
1486 GST_BUFFER_TIMESTAMP (*out_buf) != GST_BUFFER_TIMESTAMP (in_buf) ||
1487 GST_BUFFER_DURATION (*out_buf) != GST_BUFFER_DURATION (in_buf) ||
1488 GST_BUFFER_OFFSET (*out_buf) != GST_BUFFER_OFFSET (in_buf) ||
1489 GST_BUFFER_OFFSET_END (*out_buf) != GST_BUFFER_OFFSET_END (in_buf);
1492 /* we need to modify the metadata when the element is not gap aware,
1493 * passthrough is not used and the gap flag is set */
1494 copymeta |= !priv->gap_aware && !trans->passthrough
1495 && (GST_MINI_OBJECT_FLAGS (*out_buf) & GST_BUFFER_FLAG_GAP);
1498 GST_DEBUG_OBJECT (trans, "copymeta %d", copymeta);
1499 if (!gst_buffer_is_writable (*out_buf)) {
1500 GST_DEBUG_OBJECT (trans, "buffer %p not writable", *out_buf);
1501 if (in_buf == *out_buf)
1502 *out_buf = gst_buffer_copy (in_buf);
1504 *out_buf = gst_buffer_make_writable (*out_buf);
1506 /* when we get here, the metadata should be writable */
1508 gst_buffer_copy_into (*out_buf, in_buf,
1509 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1510 /* clear the GAP flag when the subclass does not understand it */
1511 if (!priv->gap_aware)
1512 GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
1517 gst_caps_unref (incaps);
1519 gst_caps_unref (outcaps);
1526 GST_WARNING_OBJECT (trans, "pad-alloc failed: %s", gst_flow_get_name (ret));
1531 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1532 ("Sub-class failed to provide an output buffer"), (NULL));
1533 ret = GST_FLOW_ERROR;
1538 GST_ERROR_OBJECT (trans, "unknown output size");
1539 ret = GST_FLOW_ERROR;
1544 /* Given @caps calcultate the size of one unit.
1546 * For video caps, this is the size of one frame (and thus one buffer).
1547 * For audio caps, this is the size of one sample.
1549 * These values are cached since they do not change and the calculation
1550 * potentially involves parsing caps and other expensive stuff.
1552 * We have two cache locations to store the size, one for the source caps
1553 * and one for the sink caps.
1555 * this function returns FALSE if no size could be calculated.
1558 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1561 gboolean res = FALSE;
1562 GstBaseTransformClass *bclass;
1564 /* see if we have the result cached */
1565 if (trans->cache_caps1 == caps) {
1566 *size = trans->cache_caps1_size;
1567 GST_DEBUG_OBJECT (trans, "returned %d from first cache", *size);
1570 if (trans->cache_caps2 == caps) {
1571 *size = trans->cache_caps2_size;
1572 GST_DEBUG_OBJECT (trans, "returned %d from second cached", *size);
1576 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1577 if (bclass->get_unit_size) {
1578 res = bclass->get_unit_size (trans, caps, size);
1579 GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
1580 ") has unit size %d, result %s", caps, *size, res ? "TRUE" : "FALSE");
1583 /* and cache the values */
1584 if (trans->cache_caps1 == NULL) {
1585 gst_caps_replace (&trans->cache_caps1, caps);
1586 trans->cache_caps1_size = *size;
1587 GST_DEBUG_OBJECT (trans, "caching %d in first cache", *size);
1588 } else if (trans->cache_caps2 == NULL) {
1589 gst_caps_replace (&trans->cache_caps2, caps);
1590 trans->cache_caps2_size = *size;
1591 GST_DEBUG_OBJECT (trans, "caching %d in second cache", *size);
1593 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1597 GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
1603 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1605 GstBaseTransform *trans;
1606 GstBaseTransformClass *bclass;
1607 gboolean ret = TRUE;
1608 gboolean forward = TRUE;
1610 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1611 if (G_UNLIKELY (trans == NULL)) {
1612 gst_event_unref (event);
1615 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1618 forward = bclass->event (trans, event);
1620 /* FIXME, do this in the default event handler so the subclass can do
1621 * something different. */
1623 ret = gst_pad_push_event (trans->srcpad, event);
1625 gst_event_unref (event);
1627 gst_object_unref (trans);
1633 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1635 gboolean forward = TRUE;
1637 switch (GST_EVENT_TYPE (event)) {
1638 case GST_EVENT_FLUSH_START:
1640 case GST_EVENT_FLUSH_STOP:
1641 GST_OBJECT_LOCK (trans);
1642 /* reset QoS parameters */
1643 trans->priv->proportion = 1.0;
1644 trans->priv->earliest_time = -1;
1645 trans->priv->discont = FALSE;
1646 trans->priv->processed = 0;
1647 trans->priv->dropped = 0;
1648 GST_OBJECT_UNLOCK (trans);
1649 /* we need new segment info after the flush. */
1650 trans->have_segment = FALSE;
1651 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1652 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1658 case GST_EVENT_CAPS:
1662 gst_event_parse_caps (event, &caps);
1663 gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1668 case GST_EVENT_SEGMENT:
1670 gst_event_copy_segment (event, &trans->segment);
1671 trans->have_segment = TRUE;
1673 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1685 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1687 GstBaseTransform *trans;
1688 GstBaseTransformClass *bclass;
1689 gboolean ret = TRUE;
1691 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1692 if (G_UNLIKELY (trans == NULL)) {
1693 gst_event_unref (event);
1697 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1699 if (bclass->src_event)
1700 ret = bclass->src_event (trans, event);
1702 gst_event_unref (event);
1704 gst_object_unref (trans);
1710 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1714 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1716 switch (GST_EVENT_TYPE (event)) {
1717 case GST_EVENT_SEEK:
1719 case GST_EVENT_NAVIGATION:
1724 GstClockTimeDiff diff;
1725 GstClockTime timestamp;
1727 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1728 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1735 ret = gst_pad_push_event (trans->sinkpad, event);
1740 /* perform a transform on @inbuf and put the result in @outbuf.
1742 * This function is common to the push and pull-based operations.
1744 * This function takes ownership of @inbuf */
1745 static GstFlowReturn
1746 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1747 GstBuffer ** outbuf)
1749 GstBaseTransformClass *bclass;
1750 GstFlowReturn ret = GST_FLOW_OK;
1751 gboolean want_in_place;
1752 GstClockTime running_time;
1753 GstClockTime timestamp;
1755 gboolean reconfigure;
1757 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1759 GST_OBJECT_LOCK (trans->sinkpad);
1760 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1761 || trans->priv->reconfigure;
1762 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1763 trans->priv->reconfigure = FALSE;
1764 GST_OBJECT_UNLOCK (trans->sinkpad);
1766 if (G_UNLIKELY (reconfigure)) {
1769 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1771 incaps = gst_pad_get_current_caps (trans->sinkpad);
1773 goto no_reconfigure;
1775 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1776 * will reconfigure the transform with the new output format. We can only
1777 * do this if the buffer actually has caps. */
1778 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1779 gst_caps_unref (incaps);
1780 goto not_negotiated;
1782 gst_caps_unref (incaps);
1786 insize = gst_buffer_get_size (inbuf);
1788 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1789 GST_DEBUG_OBJECT (trans,
1790 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1791 G_GUINT64_FORMAT, inbuf, insize, GST_BUFFER_OFFSET (inbuf));
1793 GST_DEBUG_OBJECT (trans,
1794 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1797 /* Don't allow buffer handling before negotiation, except in passthrough mode
1798 * or if the class doesn't implement a set_caps function (in which case it doesn't
1801 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1802 goto not_negotiated;
1804 /* Set discont flag so we can mark the outgoing buffer */
1805 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1806 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1807 trans->priv->discont = TRUE;
1810 /* can only do QoS if the segment is in TIME */
1811 if (trans->segment.format != GST_FORMAT_TIME)
1814 /* QOS is done on the running time of the buffer, get it now */
1815 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1816 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1819 if (running_time != -1) {
1821 GstClockTime earliest_time;
1824 /* lock for getting the QoS parameters that are set (in a different thread)
1825 * with the QOS events */
1826 GST_OBJECT_LOCK (trans);
1827 earliest_time = trans->priv->earliest_time;
1828 proportion = trans->priv->proportion;
1829 /* check for QoS, don't perform conversion for buffers
1830 * that are known to be late. */
1831 need_skip = trans->priv->qos_enabled &&
1832 earliest_time != -1 && running_time <= earliest_time;
1833 GST_OBJECT_UNLOCK (trans);
1836 GstMessage *qos_msg;
1837 GstClockTime duration;
1838 guint64 stream_time;
1841 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1842 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1843 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1845 trans->priv->dropped++;
1847 duration = GST_BUFFER_DURATION (inbuf);
1849 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1851 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1854 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1855 stream_time, timestamp, duration);
1856 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1857 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1858 trans->priv->processed, trans->priv->dropped);
1859 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1861 /* mark discont for next buffer */
1862 trans->priv->discont = TRUE;
1869 /* first try to allocate an output buffer based on the currently negotiated
1870 * format. outbuf will contain a buffer suitable for doing the configured
1871 * transform after this function. */
1872 ret = gst_base_transform_prepare_output_buffer (trans, inbuf, outbuf);
1873 if (G_UNLIKELY (ret != GST_FLOW_OK))
1876 /* now perform the needed transform */
1877 if (trans->passthrough) {
1878 /* In passthrough mode, give transform_ip a look at the
1879 * buffer, without making it writable, or just push the
1881 if (bclass->transform_ip) {
1882 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1883 ret = bclass->transform_ip (trans, *outbuf);
1885 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1888 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1890 if (want_in_place) {
1891 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1893 if (inbuf != *outbuf) {
1894 guint8 *indata, *outdata;
1895 gsize insize, outsize;
1897 /* Different buffer. The data can still be the same when we are dealing
1898 * with subbuffers of the same buffer. Note that because of the FIXME in
1899 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1900 * outbuf to keep them writable */
1901 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1902 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1904 if (indata != outdata)
1905 memcpy (outdata, indata, insize);
1907 gst_buffer_unmap (inbuf, indata, insize);
1908 gst_buffer_unmap (*outbuf, outdata, outsize);
1910 ret = bclass->transform_ip (trans, *outbuf);
1912 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1914 if (bclass->transform)
1915 ret = bclass->transform (trans, inbuf, *outbuf);
1917 ret = GST_FLOW_NOT_SUPPORTED;
1922 /* only unref input buffer if we allocated a new outbuf buffer */
1923 if (*outbuf != inbuf)
1924 gst_buffer_unref (inbuf);
1931 gst_buffer_unref (inbuf);
1932 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1933 ("not negotiated"), ("not negotiated"));
1934 return GST_FLOW_NOT_NEGOTIATED;
1938 gst_buffer_unref (inbuf);
1940 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1941 gst_flow_get_name (ret));
1946 /* FIXME, getrange is broken, need to pull range from the other
1947 * end based on the transform_size result.
1949 static GstFlowReturn
1950 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1951 guint length, GstBuffer ** buffer)
1953 GstBaseTransform *trans;
1954 GstBaseTransformClass *klass;
1958 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1960 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1961 if (G_UNLIKELY (ret != GST_FLOW_OK))
1964 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1965 if (klass->before_transform)
1966 klass->before_transform (trans, inbuf);
1968 GST_BASE_TRANSFORM_LOCK (trans);
1969 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1970 GST_BASE_TRANSFORM_UNLOCK (trans);
1973 gst_object_unref (trans);
1980 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1981 gst_flow_get_name (ret));
1986 static GstFlowReturn
1987 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
1989 GstBaseTransform *trans;
1990 GstBaseTransformClass *klass;
1992 GstClockTime position = GST_CLOCK_TIME_NONE;
1993 GstClockTime timestamp, duration;
1994 GstBuffer *outbuf = NULL;
1996 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
1998 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1999 duration = GST_BUFFER_DURATION (buffer);
2001 /* calculate end position of the incoming buffer */
2002 if (timestamp != GST_CLOCK_TIME_NONE) {
2003 if (duration != GST_CLOCK_TIME_NONE)
2004 position = timestamp + duration;
2006 position = timestamp;
2009 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2010 if (klass->before_transform)
2011 klass->before_transform (trans, buffer);
2013 /* protect transform method and concurrent buffer alloc */
2014 GST_BASE_TRANSFORM_LOCK (trans);
2015 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
2016 GST_BASE_TRANSFORM_UNLOCK (trans);
2018 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
2019 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
2020 if (outbuf != NULL) {
2021 if (ret == GST_FLOW_OK) {
2022 GstClockTime position_out = GST_CLOCK_TIME_NONE;
2024 /* Remember last stop position */
2025 if (position != GST_CLOCK_TIME_NONE &&
2026 trans->segment.format == GST_FORMAT_TIME)
2027 trans->segment.position = position;
2029 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
2030 position_out = GST_BUFFER_TIMESTAMP (outbuf);
2031 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
2032 position_out += GST_BUFFER_DURATION (outbuf);
2033 } else if (position != GST_CLOCK_TIME_NONE) {
2034 position_out = position;
2036 if (position_out != GST_CLOCK_TIME_NONE
2037 && trans->segment.format == GST_FORMAT_TIME)
2038 trans->priv->position_out = position_out;
2040 /* apply DISCONT flag if the buffer is not yet marked as such */
2041 if (trans->priv->discont) {
2042 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
2043 outbuf = gst_buffer_make_writable (outbuf);
2044 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
2046 trans->priv->discont = FALSE;
2048 trans->priv->processed++;
2049 ret = gst_pad_push (trans->srcpad, outbuf);
2051 gst_buffer_unref (outbuf);
2055 /* convert internal flow to OK and mark discont for the next buffer. */
2056 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
2057 trans->priv->discont = TRUE;
2065 gst_base_transform_set_property (GObject * object, guint prop_id,
2066 const GValue * value, GParamSpec * pspec)
2068 GstBaseTransform *trans;
2070 trans = GST_BASE_TRANSFORM (object);
2074 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2077 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2083 gst_base_transform_get_property (GObject * object, guint prop_id,
2084 GValue * value, GParamSpec * pspec)
2086 GstBaseTransform *trans;
2088 trans = GST_BASE_TRANSFORM (object);
2092 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2095 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2100 /* not a vmethod of anything, just an internal method */
2102 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2104 GstBaseTransformClass *bclass;
2105 gboolean result = TRUE;
2107 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2110 GstCaps *incaps, *outcaps;
2112 if (trans->priv->pad_mode == GST_ACTIVATE_NONE && bclass->start)
2113 result &= bclass->start (trans);
2115 incaps = gst_pad_get_current_caps (trans->sinkpad);
2116 outcaps = gst_pad_get_current_caps (trans->srcpad);
2118 GST_OBJECT_LOCK (trans);
2119 if (incaps && outcaps)
2120 trans->have_same_caps =
2121 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2123 trans->have_same_caps = trans->passthrough;
2124 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2125 trans->negotiated = FALSE;
2126 trans->have_segment = FALSE;
2127 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2128 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2129 trans->priv->proportion = 1.0;
2130 trans->priv->earliest_time = -1;
2131 trans->priv->discont = FALSE;
2132 trans->priv->processed = 0;
2133 trans->priv->dropped = 0;
2134 GST_OBJECT_UNLOCK (trans);
2137 gst_caps_unref (incaps);
2139 gst_caps_unref (outcaps);
2141 /* We must make sure streaming has finished before resetting things
2142 * and calling the ::stop vfunc */
2143 GST_PAD_STREAM_LOCK (trans->sinkpad);
2144 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2146 trans->have_same_caps = FALSE;
2147 /* We can only reset the passthrough mode if the instance told us to
2148 handle it in configure_caps */
2149 if (bclass->passthrough_on_same_caps) {
2150 gst_base_transform_set_passthrough (trans, FALSE);
2152 gst_caps_replace (&trans->cache_caps1, NULL);
2153 gst_caps_replace (&trans->cache_caps2, NULL);
2155 if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
2156 result &= bclass->stop (trans);
2158 gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
2165 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2167 gboolean result = TRUE;
2168 GstBaseTransform *trans;
2170 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2172 result = gst_base_transform_activate (trans, active);
2175 trans->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
2177 gst_object_unref (trans);
2183 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2185 gboolean result = FALSE;
2186 GstBaseTransform *trans;
2188 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2190 result = gst_pad_activate_pull (trans->sinkpad, active);
2193 result &= gst_base_transform_activate (trans, active);
2196 trans->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
2198 gst_object_unref (trans);
2204 * gst_base_transform_set_passthrough:
2205 * @trans: the #GstBaseTransform to set
2206 * @passthrough: boolean indicating passthrough mode.
2208 * Set passthrough mode for this filter by default. This is mostly
2209 * useful for filters that do not care about negotiation.
2211 * Always TRUE for filters which don't implement either a transform
2212 * or transform_ip method.
2217 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2218 gboolean passthrough)
2220 GstBaseTransformClass *bclass;
2222 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2224 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2226 GST_OBJECT_LOCK (trans);
2227 if (passthrough == FALSE) {
2228 if (bclass->transform_ip || bclass->transform)
2229 trans->passthrough = FALSE;
2231 trans->passthrough = TRUE;
2234 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2235 GST_OBJECT_UNLOCK (trans);
2239 * gst_base_transform_is_passthrough:
2240 * @trans: the #GstBaseTransform to query
2242 * See if @trans is configured as a passthrough transform.
2244 * Returns: TRUE is the transform is configured in passthrough mode.
2249 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2253 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2255 GST_OBJECT_LOCK (trans);
2256 result = trans->passthrough;
2257 GST_OBJECT_UNLOCK (trans);
2263 * gst_base_transform_set_in_place:
2264 * @trans: the #GstBaseTransform to modify
2265 * @in_place: Boolean value indicating that we would like to operate
2266 * on in_place buffers.
2268 * Determines whether a non-writable buffer will be copied before passing
2269 * to the transform_ip function.
2271 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2272 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2278 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2280 GstBaseTransformClass *bclass;
2282 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2284 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2286 GST_OBJECT_LOCK (trans);
2289 if (bclass->transform_ip) {
2290 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2291 trans->always_in_place = TRUE;
2294 if (bclass->transform) {
2295 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2296 trans->always_in_place = FALSE;
2300 GST_OBJECT_UNLOCK (trans);
2304 * gst_base_transform_is_in_place:
2305 * @trans: the #GstBaseTransform to query
2307 * See if @trans is configured as a in_place transform.
2309 * Returns: TRUE is the transform is configured in in_place mode.
2314 gst_base_transform_is_in_place (GstBaseTransform * trans)
2318 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2320 GST_OBJECT_LOCK (trans);
2321 result = trans->always_in_place;
2322 GST_OBJECT_UNLOCK (trans);
2328 * gst_base_transform_update_qos:
2329 * @trans: a #GstBaseTransform
2330 * @proportion: the proportion
2331 * @diff: the diff against the clock
2332 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2335 * Set the QoS parameters in the transform. This function is called internally
2336 * when a QOS event is received but subclasses can provide custom information
2344 gst_base_transform_update_qos (GstBaseTransform * trans,
2345 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2348 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2350 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2351 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2352 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2354 GST_OBJECT_LOCK (trans);
2355 trans->priv->proportion = proportion;
2356 trans->priv->earliest_time = timestamp + diff;
2357 GST_OBJECT_UNLOCK (trans);
2361 * gst_base_transform_set_qos_enabled:
2362 * @trans: a #GstBaseTransform
2363 * @enabled: new state
2365 * Enable or disable QoS handling in the transform.
2372 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2374 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2376 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2378 GST_OBJECT_LOCK (trans);
2379 trans->priv->qos_enabled = enabled;
2380 GST_OBJECT_UNLOCK (trans);
2384 * gst_base_transform_is_qos_enabled:
2385 * @trans: a #GstBaseTransform
2387 * Queries if the transform will handle QoS.
2389 * Returns: TRUE if QoS is enabled.
2396 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2400 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2402 GST_OBJECT_LOCK (trans);
2403 result = trans->priv->qos_enabled;
2404 GST_OBJECT_UNLOCK (trans);
2410 * gst_base_transform_set_gap_aware:
2411 * @trans: a #GstBaseTransform
2412 * @gap_aware: New state
2414 * If @gap_aware is %FALSE (the default), output buffers will have the
2415 * %GST_BUFFER_FLAG_GAP flag unset.
2417 * If set to %TRUE, the element must handle output buffers with this flag set
2418 * correctly, i.e. it can assume that the buffer contains neutral data but must
2419 * unset the flag if the output is no neutral data.
2426 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2428 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2430 GST_OBJECT_LOCK (trans);
2431 trans->priv->gap_aware = gap_aware;
2432 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2433 GST_OBJECT_UNLOCK (trans);
2437 * gst_base_transform_suggest:
2438 * @trans: a #GstBaseTransform
2439 * @caps: (transfer none): caps to suggest
2440 * @size: buffer size to suggest
2442 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2448 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2451 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2453 /* push the renegotiate event */
2454 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2455 gst_event_new_reconfigure ()))
2456 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2460 * gst_base_transform_reconfigure:
2461 * @trans: a #GstBaseTransform
2463 * Instructs @trans to renegotiate a new downstream transform on the next
2464 * buffer. This function is typically called after properties on the transform
2465 * were set that influence the output format.
2470 gst_base_transform_reconfigure (GstBaseTransform * trans)
2472 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2474 GST_OBJECT_LOCK (trans);
2475 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2476 trans->priv->reconfigure = TRUE;
2477 GST_OBJECT_UNLOCK (trans);