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 static GstElementClass *parent_class = NULL;
258 static void gst_base_transform_class_init (GstBaseTransformClass * klass);
259 static void gst_base_transform_init (GstBaseTransform * trans,
260 GstBaseTransformClass * klass);
261 static GstFlowReturn gst_base_transform_prepare_output_buffer (GstBaseTransform
262 * trans, GstBuffer * input, GstBuffer ** buf);
265 gst_base_transform_get_type (void)
267 static volatile gsize base_transform_type = 0;
269 if (g_once_init_enter (&base_transform_type)) {
271 static const GTypeInfo base_transform_info = {
272 sizeof (GstBaseTransformClass),
275 (GClassInitFunc) gst_base_transform_class_init,
278 sizeof (GstBaseTransform),
280 (GInstanceInitFunc) gst_base_transform_init,
283 _type = g_type_register_static (GST_TYPE_ELEMENT,
284 "GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
285 g_once_init_leave (&base_transform_type, _type);
287 return base_transform_type;
290 static void gst_base_transform_finalize (GObject * object);
291 static void gst_base_transform_set_property (GObject * object, guint prop_id,
292 const GValue * value, GParamSpec * pspec);
293 static void gst_base_transform_get_property (GObject * object, guint prop_id,
294 GValue * value, GParamSpec * pspec);
295 static gboolean gst_base_transform_src_activate_pull (GstPad * pad,
297 static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
299 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
301 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
302 GstCaps * caps, gsize * size);
304 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
305 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
307 static gboolean gst_base_transform_sink_event (GstPad * pad, GstEvent * event);
308 static gboolean gst_base_transform_sink_eventfunc (GstBaseTransform * trans,
310 static gboolean gst_base_transform_check_get_range (GstPad * pad);
311 static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
312 guint length, GstBuffer ** buffer);
313 static GstFlowReturn gst_base_transform_chain (GstPad * pad,
315 static GstCaps *gst_base_transform_getcaps (GstPad * pad, GstCaps * filter);
316 static gboolean gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps);
317 static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
318 GstPadDirection direction, GstCaps * caps);
319 static gboolean gst_base_transform_setcaps (GstBaseTransform * trans,
320 GstPad * pad, GstCaps * caps);
321 static gboolean gst_base_transform_query (GstPad * pad, GstQuery ** query);
322 static const GstQueryType *gst_base_transform_query_type (GstPad * pad);
324 /* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
327 gst_base_transform_finalize (GObject * object)
329 GstBaseTransform *trans;
331 trans = GST_BASE_TRANSFORM (object);
333 g_mutex_free (trans->transform_lock);
335 G_OBJECT_CLASS (parent_class)->finalize (object);
339 gst_base_transform_class_init (GstBaseTransformClass * klass)
341 GObjectClass *gobject_class;
343 gobject_class = G_OBJECT_CLASS (klass);
345 GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
346 "basetransform element");
348 GST_DEBUG ("gst_base_transform_class_init");
350 g_type_class_add_private (klass, sizeof (GstBaseTransformPrivate));
352 parent_class = g_type_class_peek_parent (klass);
354 gobject_class->set_property = gst_base_transform_set_property;
355 gobject_class->get_property = gst_base_transform_get_property;
357 g_object_class_install_property (gobject_class, PROP_QOS,
358 g_param_spec_boolean ("qos", "QoS", "Handle Quality-of-Service events",
359 DEFAULT_PROP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
361 gobject_class->finalize = gst_base_transform_finalize;
363 klass->passthrough_on_same_caps = FALSE;
364 klass->event = GST_DEBUG_FUNCPTR (gst_base_transform_sink_eventfunc);
365 klass->src_event = GST_DEBUG_FUNCPTR (gst_base_transform_src_eventfunc);
367 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default);
371 gst_base_transform_init (GstBaseTransform * trans,
372 GstBaseTransformClass * bclass)
374 GstPadTemplate *pad_template;
376 GST_DEBUG ("gst_base_transform_init");
378 trans->priv = GST_BASE_TRANSFORM_GET_PRIVATE (trans);
381 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
382 g_return_if_fail (pad_template != NULL);
383 trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
384 gst_pad_set_getcaps_function (trans->sinkpad,
385 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
386 gst_pad_set_acceptcaps_function (trans->sinkpad,
387 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
388 gst_pad_set_event_function (trans->sinkpad,
389 GST_DEBUG_FUNCPTR (gst_base_transform_sink_event));
390 gst_pad_set_chain_function (trans->sinkpad,
391 GST_DEBUG_FUNCPTR (gst_base_transform_chain));
392 gst_pad_set_activatepush_function (trans->sinkpad,
393 GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate_push));
394 gst_pad_set_query_function (trans->sinkpad,
395 GST_DEBUG_FUNCPTR (gst_base_transform_query));
396 gst_pad_set_query_type_function (trans->sinkpad,
397 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
398 gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
401 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
402 g_return_if_fail (pad_template != NULL);
403 trans->srcpad = gst_pad_new_from_template (pad_template, "src");
404 gst_pad_set_getcaps_function (trans->srcpad,
405 GST_DEBUG_FUNCPTR (gst_base_transform_getcaps));
406 gst_pad_set_acceptcaps_function (trans->srcpad,
407 GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps));
408 gst_pad_set_event_function (trans->srcpad,
409 GST_DEBUG_FUNCPTR (gst_base_transform_src_event));
410 gst_pad_set_checkgetrange_function (trans->srcpad,
411 GST_DEBUG_FUNCPTR (gst_base_transform_check_get_range));
412 gst_pad_set_getrange_function (trans->srcpad,
413 GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
414 gst_pad_set_activatepull_function (trans->srcpad,
415 GST_DEBUG_FUNCPTR (gst_base_transform_src_activate_pull));
416 gst_pad_set_query_function (trans->srcpad,
417 GST_DEBUG_FUNCPTR (gst_base_transform_query));
418 gst_pad_set_query_type_function (trans->srcpad,
419 GST_DEBUG_FUNCPTR (gst_base_transform_query_type));
420 gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
422 trans->transform_lock = g_mutex_new ();
423 trans->pending_configure = FALSE;
424 trans->priv->qos_enabled = DEFAULT_PROP_QOS;
425 trans->cache_caps1 = NULL;
426 trans->cache_caps2 = NULL;
427 trans->priv->pad_mode = GST_ACTIVATE_NONE;
428 trans->priv->gap_aware = FALSE;
430 trans->passthrough = FALSE;
431 if (bclass->transform == NULL) {
432 /* If no transform function, always_in_place is TRUE */
433 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
434 trans->always_in_place = TRUE;
436 if (bclass->transform_ip == NULL) {
437 GST_DEBUG_OBJECT (trans, "setting passthrough TRUE");
438 trans->passthrough = TRUE;
442 trans->priv->processed = 0;
443 trans->priv->dropped = 0;
446 /* given @caps on the src or sink pad (given by @direction)
447 * calculate the possible caps on the other pad.
449 * Returns new caps, unref after usage.
452 gst_base_transform_transform_caps (GstBaseTransform * trans,
453 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
456 GstBaseTransformClass *klass;
461 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
463 /* if there is a custom transform function, use this */
464 if (klass->transform_caps) {
468 /* start with empty caps */
469 ret = gst_caps_new_empty ();
470 GST_DEBUG_OBJECT (trans, "transform caps (direction = %d)", direction);
472 if (gst_caps_is_any (caps)) {
473 /* for any caps we still have to call the transform function */
474 GST_DEBUG_OBJECT (trans, "from: ANY");
475 temp = klass->transform_caps (trans, direction, caps, filter);
476 GST_DEBUG_OBJECT (trans, " to: %" GST_PTR_FORMAT, temp);
477 temp = gst_caps_make_writable (temp);
478 gst_caps_append (ret, temp);
480 gint n = gst_caps_get_size (caps);
481 /* we send caps with just one structure to the transform
482 * function as this is easier for the element */
483 for (i = 0; i < n; i++) {
486 nth = gst_caps_copy_nth (caps, i);
487 GST_LOG_OBJECT (trans, "from[%d]: %" GST_PTR_FORMAT, i, nth);
488 temp = klass->transform_caps (trans, direction, nth, filter);
489 gst_caps_unref (nth);
491 GST_LOG_OBJECT (trans, " to[%d]: %" GST_PTR_FORMAT, i, temp);
493 temp = gst_caps_make_writable (temp);
495 /* here we need to only append those structures, that are not yet
496 * in there, we use the merge function for this */
497 gst_caps_merge (ret, temp);
499 GST_LOG_OBJECT (trans, " merged[%d]: %" GST_PTR_FORMAT, i, ret);
501 GST_LOG_OBJECT (trans, "merged: (%d)", gst_caps_get_size (ret));
502 /* FIXME: we can't do much simplification here because we don't really want to
503 * change the caps order
504 gst_caps_do_simplify (ret);
505 GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
509 #ifndef G_DISABLE_ASSERT
511 if (!gst_caps_is_subset (ret, filter)) {
512 GST_ERROR_OBJECT (trans,
513 "transform_caps returned caps %" GST_PTR_FORMAT
514 " which are not a real subset of the filter caps %"
515 GST_PTR_FORMAT, ret, filter);
516 g_warning ("%s: transform_caps returned caps which are not a real "
517 "subset of the filter caps", GST_ELEMENT_NAME (trans));
519 temp = gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
520 gst_caps_unref (ret);
526 GST_DEBUG_OBJECT (trans, "identity from: %" GST_PTR_FORMAT, caps);
527 /* no transform function, use the identity transform */
529 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
531 ret = gst_caps_ref (caps);
535 GST_DEBUG_OBJECT (trans, "to: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (ret),
541 /* transform a buffer of @size with @caps on the pad with @direction to
542 * the size of a buffer with @othercaps and store the result in @othersize
544 * We have two ways of doing this:
545 * 1) use a custom transform size function, this is for complicated custom
546 * cases with no fixed unit_size.
547 * 2) use the unit_size functions where there is a relationship between the
548 * caps and the size of a buffer.
551 gst_base_transform_transform_size (GstBaseTransform * trans,
552 GstPadDirection direction, GstCaps * caps,
553 gsize size, GstCaps * othercaps, gsize * othersize)
555 gsize inunitsize, outunitsize, units;
556 GstBaseTransformClass *klass;
559 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
561 GST_DEBUG_OBJECT (trans, "asked to transform size %d for caps %"
562 GST_PTR_FORMAT " to size for caps %" GST_PTR_FORMAT " in direction %s",
563 size, caps, othercaps, direction == GST_PAD_SRC ? "SRC" : "SINK");
565 if (klass->transform_size) {
566 /* if there is a custom transform function, use this */
567 ret = klass->transform_size (trans, direction, caps, size, othercaps,
569 } else if (klass->get_unit_size == NULL) {
570 /* if there is no transform_size and no unit_size, it means the
571 * element does not modify the size of a buffer */
575 /* there is no transform_size function, we have to use the unit_size
576 * functions. This method assumes there is a fixed unit_size associated with
577 * each caps. We provide the same amount of units on both sides. */
578 if (!gst_base_transform_get_unit_size (trans, caps, &inunitsize))
581 GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
584 /* input size must be a multiple of the unit_size of the input caps */
585 if (inunitsize == 0 || (size % inunitsize != 0))
588 /* get the amount of units */
589 units = size / inunitsize;
591 /* now get the unit size of the output */
592 if (!gst_base_transform_get_unit_size (trans, othercaps, &outunitsize))
595 /* the output size is the unit_size times the amount of units on the
597 *othersize = units * outunitsize;
598 GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);
607 GST_DEBUG_OBJECT (trans, "could not get in_size");
608 g_warning ("%s: could not get in_size", GST_ELEMENT_NAME (trans));
613 GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size,
615 g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
616 G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
621 GST_DEBUG_OBJECT (trans, "could not get out_size");
622 g_warning ("%s: could not get out_size", GST_ELEMENT_NAME (trans));
627 /* get the caps that can be handled by @pad. We perform:
629 * - take the caps of peer of otherpad,
630 * - filter against the padtemplate of otherpad,
631 * - calculate all transforms of remaining caps
632 * - filter against template of @pad
634 * If there is no peer, we simply return the caps of the padtemplate of pad.
637 gst_base_transform_getcaps (GstPad * pad, GstCaps * filter)
639 GstBaseTransform *trans;
641 GstCaps *peercaps, *caps, *peerfilter = NULL;
643 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
645 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
647 /* we can do what the peer can */
650 const GstCaps *templ;
652 GST_DEBUG_OBJECT (pad, "filter caps %" GST_PTR_FORMAT, filter);
654 /* filtered against our padtemplate on the other side */
655 templ = gst_pad_get_pad_template_caps (pad);
656 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
657 temp = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST);
658 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
660 /* then see what we can transform this to */
661 peerfilter = gst_base_transform_transform_caps (trans,
662 GST_PAD_DIRECTION (pad), temp, NULL);
663 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, peerfilter);
664 gst_caps_unref (temp);
666 /* and filter against the template of this pad */
667 templ = gst_pad_get_pad_template_caps (otherpad);
668 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
669 /* We keep the caps sorted like the returned caps */
671 gst_caps_intersect_full (peerfilter, templ, GST_CAPS_INTERSECT_FIRST);
672 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
673 gst_caps_unref (peerfilter);
677 peercaps = gst_pad_peer_get_caps (otherpad, peerfilter);
680 gst_caps_unref (peerfilter);
682 if (peercaps && !gst_caps_is_any (peercaps)) {
684 const GstCaps *templ;
686 GST_DEBUG_OBJECT (pad, "peer caps %" GST_PTR_FORMAT, peercaps);
688 /* filtered against our padtemplate on the other side */
689 templ = gst_pad_get_pad_template_caps (otherpad);
690 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
691 temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
692 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
694 /* then see what we can transform this to */
695 caps = gst_base_transform_transform_caps (trans,
696 GST_PAD_DIRECTION (otherpad), temp, filter);
697 GST_DEBUG_OBJECT (pad, "transformed %" GST_PTR_FORMAT, caps);
698 gst_caps_unref (temp);
702 /* and filter against the template of this pad */
703 templ = gst_pad_get_pad_template_caps (pad);
704 GST_DEBUG_OBJECT (pad, "our template %" GST_PTR_FORMAT, templ);
705 /* We keep the caps sorted like the returned caps */
706 temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
707 GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, temp);
708 gst_caps_unref (caps);
711 /* Now try if we can put the untransformed downstream caps first */
712 temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
713 if (!gst_caps_is_empty (temp)) {
714 gst_caps_merge (temp, caps);
717 gst_caps_unref (temp);
720 /* no peer or the peer can do anything, our padtemplate is enough then */
721 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
726 temp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
727 gst_caps_unref (caps);
733 GST_DEBUG_OBJECT (trans, "returning %" GST_PTR_FORMAT, caps);
736 gst_caps_unref (peercaps);
738 gst_object_unref (trans);
743 /* function triggered when the in and out caps are negotiated and need
744 * to be configured in the subclass. */
746 gst_base_transform_configure_caps (GstBaseTransform * trans, GstCaps * in,
750 GstBaseTransformClass *klass;
752 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
754 GST_DEBUG_OBJECT (trans, "in caps: %" GST_PTR_FORMAT, in);
755 GST_DEBUG_OBJECT (trans, "out caps: %" GST_PTR_FORMAT, out);
757 /* clear the cache */
758 gst_caps_replace (&trans->cache_caps1, NULL);
759 gst_caps_replace (&trans->cache_caps2, NULL);
761 /* figure out same caps state */
762 trans->have_same_caps = gst_caps_is_equal (in, out);
763 GST_DEBUG_OBJECT (trans, "have_same_caps: %d", trans->have_same_caps);
765 /* If we've a transform_ip method and same input/output caps, set in_place
766 * by default. If for some reason the sub-class prefers using a transform
767 * function, it can clear the in place flag in the set_caps */
768 gst_base_transform_set_in_place (trans,
769 klass->transform_ip && trans->have_same_caps);
771 /* Set the passthrough if the class wants passthrough_on_same_caps
772 * and we have the same caps on each pad */
773 if (klass->passthrough_on_same_caps)
774 gst_base_transform_set_passthrough (trans, trans->have_same_caps);
776 /* now configure the element with the caps */
777 if (klass->set_caps) {
778 GST_DEBUG_OBJECT (trans, "Calling set_caps method to setup caps");
779 ret = klass->set_caps (trans, in, out);
782 trans->negotiated = ret;
787 /* given a fixed @caps on @pad, create the best possible caps for the
789 * @caps must be fixed when calling this function.
791 * This function calls the transform caps vmethod of the basetransform to figure
792 * out the possible target formats. It then tries to select the best format from
795 * - attempt passthrough if the target caps is a superset of the input caps
796 * - fixating by using peer caps
797 * - fixating with transform fixate function
798 * - fixating with pad fixate functions.
800 * this function returns a caps that can be transformed into and is accepted by
804 gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
807 GstBaseTransformClass *klass;
808 GstPad *otherpad, *otherpeer;
810 gboolean peer_checked = FALSE;
813 /* caps must be fixed here, this is a programming error if it's not */
814 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
816 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
818 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
819 otherpeer = gst_pad_get_peer (otherpad);
821 /* see how we can transform the input caps. We need to do this even for
822 * passthrough because it might be possible that this element cannot support
823 * passthrough at all. */
824 othercaps = gst_base_transform_transform_caps (trans,
825 GST_PAD_DIRECTION (pad), caps, NULL);
827 /* The caps we can actually output is the intersection of the transformed
828 * caps with the pad template for the pad */
831 const GstCaps *templ_caps;
833 templ_caps = gst_pad_get_pad_template_caps (otherpad);
834 GST_DEBUG_OBJECT (trans,
835 "intersecting against padtemplate %" GST_PTR_FORMAT, templ_caps);
838 gst_caps_intersect_full (othercaps, templ_caps,
839 GST_CAPS_INTERSECT_FIRST);
841 gst_caps_unref (othercaps);
842 othercaps = intersect;
845 /* check if transform is empty */
846 if (!othercaps || gst_caps_is_empty (othercaps))
849 /* if the othercaps are not fixed, we need to fixate them, first attempt
850 * is by attempting passthrough if the othercaps are a superset of caps. */
851 /* FIXME. maybe the caps is not fixed because it has multiple structures of
853 is_fixed = gst_caps_is_fixed (othercaps);
855 GST_DEBUG_OBJECT (trans,
856 "transform returned non fixed %" GST_PTR_FORMAT, othercaps);
858 /* Now let's see what the peer suggests based on our transformed caps */
860 GstCaps *peercaps, *intersection;
861 const GstCaps *templ_caps;
863 GST_DEBUG_OBJECT (trans,
864 "Checking peer caps with filter %" GST_PTR_FORMAT, othercaps);
866 peercaps = gst_pad_get_caps (otherpeer, othercaps);
867 GST_DEBUG_OBJECT (trans, "Resulted in %" GST_PTR_FORMAT, peercaps);
869 templ_caps = gst_pad_get_pad_template_caps (otherpad);
871 GST_DEBUG_OBJECT (trans,
872 "Intersecting with template caps %" GST_PTR_FORMAT, templ_caps);
875 gst_caps_intersect_full (peercaps, templ_caps,
876 GST_CAPS_INTERSECT_FIRST);
877 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
878 gst_caps_unref (peercaps);
879 peercaps = intersection;
881 GST_DEBUG_OBJECT (trans,
882 "Intersecting with transformed caps %" GST_PTR_FORMAT, othercaps);
884 gst_caps_intersect_full (peercaps, othercaps,
885 GST_CAPS_INTERSECT_FIRST);
886 GST_DEBUG_OBJECT (trans, "Intersection: %" GST_PTR_FORMAT, intersection);
887 gst_caps_unref (peercaps);
888 gst_caps_unref (othercaps);
889 othercaps = intersection;
890 is_fixed = gst_caps_is_fixed (othercaps);
893 GST_DEBUG_OBJECT (trans, "no peer, doing passthrough");
894 gst_caps_unref (othercaps);
895 othercaps = gst_caps_ref (caps);
899 if (gst_caps_is_empty (othercaps))
900 goto no_transform_possible;
902 /* second attempt at fixation, call the fixate vmethod and
903 * ultimately call the pad fixate function. */
905 GST_DEBUG_OBJECT (trans,
906 "trying to fixate %" GST_PTR_FORMAT " on pad %s:%s",
907 othercaps, GST_DEBUG_PAD_NAME (otherpad));
909 /* since we have no other way to fixate left, we might as well just take
910 * the first of the caps list and fixate that */
912 /* FIXME: when fixating using the vmethod, it might make sense to fixate
913 * each of the caps; but Wim doesn't see a use case for that yet */
914 gst_caps_truncate (othercaps);
915 peer_checked = FALSE;
917 if (klass->fixate_caps) {
918 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
919 " using caps %" GST_PTR_FORMAT
920 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
921 GST_DEBUG_PAD_NAME (otherpad));
922 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
923 is_fixed = gst_caps_is_fixed (othercaps);
925 /* if still not fixed, no other option but to let the default pad fixate
926 * function do its job */
928 GST_DEBUG_OBJECT (trans, "trying to fixate %" GST_PTR_FORMAT
929 " on pad %s:%s using gst_pad_fixate_caps", othercaps,
930 GST_DEBUG_PAD_NAME (otherpad));
931 gst_pad_fixate_caps (otherpad, othercaps);
932 is_fixed = gst_caps_is_fixed (othercaps);
934 GST_DEBUG_OBJECT (trans, "after fixating %" GST_PTR_FORMAT, othercaps);
936 GST_DEBUG ("caps are fixed");
937 /* else caps are fixed but the subclass may want to add fields */
938 if (klass->fixate_caps) {
939 othercaps = gst_caps_make_writable (othercaps);
941 GST_DEBUG_OBJECT (trans, "doing fixate %" GST_PTR_FORMAT
942 " using caps %" GST_PTR_FORMAT
943 " on pad %s:%s using fixate_caps vmethod", othercaps, caps,
944 GST_DEBUG_PAD_NAME (otherpad));
946 klass->fixate_caps (trans, GST_PAD_DIRECTION (pad), caps, othercaps);
947 is_fixed = gst_caps_is_fixed (othercaps);
951 /* caps should be fixed now, if not we have to fail. */
953 goto could_not_fixate;
955 /* and peer should accept, don't check again if we already checked the
956 * othercaps against the peer. */
957 if (!peer_checked && otherpeer && !gst_pad_accept_caps (otherpeer, othercaps))
960 GST_DEBUG_OBJECT (trans, "Input caps were %" GST_PTR_FORMAT
961 ", and got final caps %" GST_PTR_FORMAT, caps, othercaps);
964 gst_object_unref (otherpeer);
971 GST_DEBUG_OBJECT (trans,
972 "transform returned useless %" GST_PTR_FORMAT, othercaps);
975 no_transform_possible:
977 GST_DEBUG_OBJECT (trans,
978 "transform could not transform %" GST_PTR_FORMAT
979 " in anything we support", caps);
984 GST_DEBUG_OBJECT (trans, "FAILED to fixate %" GST_PTR_FORMAT, othercaps);
989 GST_DEBUG_OBJECT (trans, "FAILED to get peer of %" GST_PTR_FORMAT
990 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
996 gst_object_unref (otherpeer);
998 gst_caps_unref (othercaps);
1004 gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
1005 GstPadDirection direction, GstCaps * caps)
1009 GstCaps *othercaps = NULL;
1011 gboolean ret = TRUE;
1014 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1016 /* we need fixed caps for the check, fall back to the default implementation
1018 if (!gst_caps_is_fixed (caps))
1023 GST_DEBUG_OBJECT (trans, "non fixed accept caps %" GST_PTR_FORMAT, caps);
1025 /* get all the formats we can handle on this pad */
1026 if (direction == GST_PAD_SRC)
1027 allowed = gst_pad_get_caps (trans->srcpad, NULL);
1029 allowed = gst_pad_get_caps (trans->sinkpad, NULL);
1032 GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
1033 goto no_transform_possible;
1036 GST_DEBUG_OBJECT (trans, "allowed caps %" GST_PTR_FORMAT, allowed);
1038 /* intersect with the requested format */
1039 ret = gst_caps_can_intersect (allowed, caps);
1040 gst_caps_unref (allowed);
1043 goto no_transform_possible;
1047 GST_DEBUG_OBJECT (pad, "accept caps %" GST_PTR_FORMAT, caps);
1049 /* find best possible caps for the other pad as a way to see if we can
1050 * transform this caps. */
1051 othercaps = gst_base_transform_find_transform (trans, pad, caps, FALSE);
1052 if (!othercaps || gst_caps_is_empty (othercaps))
1053 goto no_transform_possible;
1055 GST_DEBUG_OBJECT (pad, "we can transform to %" GST_PTR_FORMAT, othercaps);
1061 /* We know it's always NULL since we never use it */
1063 gst_caps_unref (othercaps);
1069 no_transform_possible:
1071 GST_DEBUG_OBJECT (trans,
1072 "transform could not transform %" GST_PTR_FORMAT
1073 " in anything we support", caps);
1080 gst_base_transform_acceptcaps (GstPad * pad, GstCaps * caps)
1082 gboolean ret = TRUE;
1083 GstBaseTransform *trans;
1084 GstBaseTransformClass *bclass;
1086 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1087 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1089 if (bclass->accept_caps)
1090 ret = bclass->accept_caps (trans, GST_PAD_DIRECTION (pad), caps);
1092 gst_object_unref (trans);
1097 /* called when new caps arrive on the sink or source pad,
1098 * We try to find the best caps for the other side using our _find_transform()
1099 * function. If there are caps, we configure the transform for this new
1102 * FIXME, this function is currently commutative but this should not really be
1103 * because we never set caps starting from the srcpad.
1106 gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad,
1109 GstPad *otherpad, *otherpeer;
1110 GstCaps *othercaps = NULL;
1111 gboolean ret = TRUE;
1112 GstCaps *incaps, *outcaps;
1114 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1115 otherpeer = gst_pad_get_peer (otherpad);
1117 /* if we get called recursively, we bail out now to avoid an
1119 if (GST_PAD_IS_IN_SETCAPS (otherpad))
1122 GST_DEBUG_OBJECT (pad, "have new caps %p %" GST_PTR_FORMAT, caps, caps);
1124 /* find best possible caps for the other pad */
1125 othercaps = gst_base_transform_find_transform (trans, pad, caps);
1126 if (!othercaps || gst_caps_is_empty (othercaps))
1127 goto no_transform_possible;
1129 /* configure the element now */
1130 /* make sure in and out caps are correct */
1131 if (pad == trans->sinkpad) {
1133 outcaps = othercaps;
1139 /* if we have the same caps, we can optimize and reuse the input caps */
1140 if (gst_caps_is_equal (incaps, outcaps)) {
1141 GST_INFO_OBJECT (trans, "reuse caps");
1142 gst_caps_unref (othercaps);
1143 outcaps = othercaps = gst_caps_ref (incaps);
1146 /* call configure now */
1147 if (!(ret = gst_base_transform_configure_caps (trans, incaps, outcaps)))
1148 goto failed_configure;
1150 /* we know this will work, we implement the setcaps */
1151 gst_pad_set_caps (otherpad, othercaps);
1153 if (pad == trans->srcpad && trans->priv->pad_mode == GST_ACTIVATE_PULL) {
1155 ret &= gst_pad_set_caps (otherpeer, othercaps);
1157 GST_INFO_OBJECT (trans, "otherpeer setcaps(%" GST_PTR_FORMAT ") failed",
1164 gst_object_unref (otherpeer);
1166 gst_caps_unref (othercaps);
1168 trans->negotiated = ret;
1173 no_transform_possible:
1175 GST_WARNING_OBJECT (trans,
1176 "transform could not transform %" GST_PTR_FORMAT
1177 " in anything we support", caps);
1183 GST_WARNING_OBJECT (trans, "FAILED to configure caps %" GST_PTR_FORMAT
1184 " to accept %" GST_PTR_FORMAT, otherpad, othercaps);
1191 gst_base_transform_query (GstPad * pad, GstQuery ** query)
1193 gboolean ret = FALSE;
1194 GstBaseTransform *trans;
1197 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1198 if (G_UNLIKELY (trans == NULL))
1200 otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
1202 switch (GST_QUERY_TYPE (*query)) {
1203 case GST_QUERY_POSITION:{
1206 gst_query_parse_position (*query, &format, NULL);
1207 if (format == GST_FORMAT_TIME && trans->segment.format == GST_FORMAT_TIME) {
1211 if ((pad == trans->sinkpad)
1212 || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) {
1214 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1215 trans->segment.position);
1217 pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1218 trans->priv->position_out);
1220 gst_query_set_position (*query, format, pos);
1222 ret = gst_pad_peer_query (otherpad, query);
1227 ret = gst_pad_peer_query (otherpad, query);
1231 gst_object_unref (trans);
1235 static const GstQueryType *
1236 gst_base_transform_query_type (GstPad * pad)
1238 static const GstQueryType types[] = {
1246 /* Allocate a buffer using gst_pad_alloc_buffer
1248 * This function can do renegotiation on the source pad
1250 * The output buffer is always writable. outbuf can be equal to
1251 * inbuf, the caller should be prepared for this and perform
1252 * appropriate refcounting.
1254 static GstFlowReturn
1255 gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
1256 GstBuffer * in_buf, GstBuffer ** out_buf)
1258 GstBaseTransformClass *bclass;
1259 GstBaseTransformPrivate *priv;
1260 GstFlowReturn ret = GST_FLOW_OK;
1261 gboolean discard, copymeta;
1262 gsize insize, outsize;
1263 GstCaps *incaps = NULL, *outcaps = NULL;
1265 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1271 insize = gst_buffer_get_size (in_buf);
1273 /* figure out how to allocate a buffer based on the current configuration */
1274 if (trans->passthrough) {
1275 GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
1276 /* passthrough, we don't really need to call pad alloc but we still need to
1277 * in order to get upstream negotiation. The output size is the same as the
1280 /* we always alloc and discard here */
1283 gboolean want_in_place = (bclass->transform_ip != NULL)
1284 && trans->always_in_place;
1286 if (want_in_place) {
1287 GST_DEBUG_OBJECT (trans, "doing inplace alloc");
1288 /* we alloc a buffer of the same size as the input */
1290 /* only discard it when the input was not writable, otherwise, we reuse
1291 * the input buffer. */
1292 discard = gst_buffer_is_writable (in_buf);
1293 GST_DEBUG_OBJECT (trans, "discard: %d", discard);
1295 incaps = gst_pad_get_current_caps (trans->sinkpad);
1296 outcaps = gst_pad_get_current_caps (trans->srcpad);
1298 GST_DEBUG_OBJECT (trans, "getting output size for copy transform");
1299 /* copy transform, figure out the output size */
1300 if (!gst_base_transform_transform_size (trans,
1301 GST_PAD_SINK, incaps, insize, outcaps, &outsize)) {
1304 /* never discard this buffer, we need it for storing the output */
1309 if (bclass->prepare_output_buffer) {
1310 if (outcaps == NULL)
1311 outcaps = gst_pad_get_current_caps (trans->srcpad);
1313 GST_DEBUG_OBJECT (trans,
1314 "calling prepare buffer with caps %p %" GST_PTR_FORMAT, outcaps,
1317 bclass->prepare_output_buffer (trans, in_buf, outsize, outcaps,
1320 /* get a new ref to the srcpad caps, the prepare_output_buffer function can
1321 * update the pad caps if it wants */
1323 gst_caps_unref (outcaps);
1324 outcaps = gst_pad_get_current_caps (trans->srcpad);
1327 * decrease refcount again if vmethod returned refcounted in_buf. This
1328 * is because we need to make sure that the buffer is writable for the
1329 * in_place transform. The docs of the vmethod say that you should return
1330 * a reffed inbuf, which is exactly what we don't want :), oh well.. */
1331 if (in_buf == *out_buf)
1332 gst_buffer_unref (in_buf);
1334 /* never discard the buffer from the prepare_buffer method */
1335 if (*out_buf != NULL)
1339 if (ret != GST_FLOW_OK)
1342 if (*out_buf == NULL) {
1343 if (trans->passthrough) {
1344 GST_DEBUG_OBJECT (trans, "Avoiding pad alloc");
1345 *out_buf = gst_buffer_ref (in_buf);
1347 GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
1349 *out_buf = gst_buffer_new_and_alloc (outsize);
1353 /* must always have a buffer by now */
1354 if (*out_buf == NULL)
1358 if (*out_buf == NULL) {
1360 GST_DEBUG_OBJECT (trans, "make default output buffer of size %d",
1362 /* no valid buffer yet, make one, metadata is writable */
1363 *out_buf = gst_buffer_new_and_alloc (outsize);
1364 gst_buffer_copy_into (*out_buf, in_buf,
1365 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1367 GST_DEBUG_OBJECT (trans, "reuse input buffer");
1371 if (trans->passthrough && in_buf != *out_buf) {
1372 /* we are asked to perform a passthrough transform but the input and
1373 * output buffers are different. We have to discard the output buffer and
1374 * reuse the input buffer. */
1375 GST_DEBUG_OBJECT (trans, "passthrough but different buffers");
1379 GST_DEBUG_OBJECT (trans, "discard buffer, reuse input buffer");
1380 gst_buffer_unref (*out_buf);
1383 GST_DEBUG_OBJECT (trans, "using allocated buffer in %p, out %p", in_buf,
1385 /* if we have different buffers, check if the metadata is ok */
1386 if (*out_buf != in_buf) {
1389 mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
1390 GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
1391 GST_BUFFER_FLAG_GAP | GST_BUFFER_FLAG_MEDIA1 |
1392 GST_BUFFER_FLAG_MEDIA2 | GST_BUFFER_FLAG_MEDIA3;
1393 /* see if the flags and timestamps match */
1395 (GST_MINI_OBJECT_FLAGS (*out_buf) & mask) ==
1396 (GST_MINI_OBJECT_FLAGS (in_buf) & mask);
1398 GST_BUFFER_TIMESTAMP (*out_buf) != GST_BUFFER_TIMESTAMP (in_buf) ||
1399 GST_BUFFER_DURATION (*out_buf) != GST_BUFFER_DURATION (in_buf) ||
1400 GST_BUFFER_OFFSET (*out_buf) != GST_BUFFER_OFFSET (in_buf) ||
1401 GST_BUFFER_OFFSET_END (*out_buf) != GST_BUFFER_OFFSET_END (in_buf);
1406 /* we need to modify the metadata when the element is not gap aware,
1407 * passthrough is not used and the gap flag is set */
1408 copymeta |= !trans->priv->gap_aware && !trans->passthrough
1409 && (GST_MINI_OBJECT_FLAGS (*out_buf) & GST_BUFFER_FLAG_GAP);
1412 GST_DEBUG_OBJECT (trans, "copymeta %d", copymeta);
1413 if (!gst_buffer_is_writable (*out_buf)) {
1414 GST_DEBUG_OBJECT (trans, "buffer %p not writable", *out_buf);
1415 if (in_buf == *out_buf)
1416 *out_buf = gst_buffer_copy (in_buf);
1418 *out_buf = gst_buffer_make_writable (*out_buf);
1420 /* when we get here, the metadata should be writable */
1422 gst_buffer_copy_into (*out_buf, in_buf,
1423 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
1424 /* clear the GAP flag when the subclass does not understand it */
1425 if (!trans->priv->gap_aware)
1426 GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
1431 gst_caps_unref (incaps);
1433 gst_caps_unref (outcaps);
1440 GST_WARNING_OBJECT (trans, "pad-alloc failed: %s", gst_flow_get_name (ret));
1445 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1446 ("Sub-class failed to provide an output buffer"), (NULL));
1447 ret = GST_FLOW_ERROR;
1452 GST_ERROR_OBJECT (trans, "unknown output size");
1453 ret = GST_FLOW_ERROR;
1458 /* Given @caps calcultate the size of one unit.
1460 * For video caps, this is the size of one frame (and thus one buffer).
1461 * For audio caps, this is the size of one sample.
1463 * These values are cached since they do not change and the calculation
1464 * potentially involves parsing caps and other expensive stuff.
1466 * We have two cache locations to store the size, one for the source caps
1467 * and one for the sink caps.
1469 * this function returns FALSE if no size could be calculated.
1472 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
1475 gboolean res = FALSE;
1476 GstBaseTransformClass *bclass;
1478 /* see if we have the result cached */
1479 if (trans->cache_caps1 == caps) {
1480 *size = trans->cache_caps1_size;
1481 GST_DEBUG_OBJECT (trans, "returned %d from first cache", *size);
1484 if (trans->cache_caps2 == caps) {
1485 *size = trans->cache_caps2_size;
1486 GST_DEBUG_OBJECT (trans, "returned %d from second cached", *size);
1490 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1491 if (bclass->get_unit_size) {
1492 res = bclass->get_unit_size (trans, caps, size);
1493 GST_DEBUG_OBJECT (trans, "caps %" GST_PTR_FORMAT
1494 ") has unit size %d, result %s", caps, *size, res ? "TRUE" : "FALSE");
1497 /* and cache the values */
1498 if (trans->cache_caps1 == NULL) {
1499 gst_caps_replace (&trans->cache_caps1, caps);
1500 trans->cache_caps1_size = *size;
1501 GST_DEBUG_OBJECT (trans, "caching %d in first cache", *size);
1502 } else if (trans->cache_caps2 == NULL) {
1503 gst_caps_replace (&trans->cache_caps2, caps);
1504 trans->cache_caps2_size = *size;
1505 GST_DEBUG_OBJECT (trans, "caching %d in second cache", *size);
1507 GST_DEBUG_OBJECT (trans, "no free spot to cache unit_size");
1511 GST_DEBUG_OBJECT (trans, "Sub-class does not implement get_unit_size");
1517 gst_base_transform_sink_event (GstPad * pad, GstEvent * event)
1519 GstBaseTransform *trans;
1520 GstBaseTransformClass *bclass;
1521 gboolean ret = TRUE;
1522 gboolean forward = TRUE;
1524 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1525 if (G_UNLIKELY (trans == NULL)) {
1526 gst_event_unref (event);
1529 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1532 forward = bclass->event (trans, event);
1534 /* FIXME, do this in the default event handler so the subclass can do
1535 * something different. */
1537 ret = gst_pad_push_event (trans->srcpad, event);
1539 gst_event_unref (event);
1541 gst_object_unref (trans);
1547 gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event)
1549 gboolean forward = TRUE;
1551 switch (GST_EVENT_TYPE (event)) {
1552 case GST_EVENT_FLUSH_START:
1554 case GST_EVENT_FLUSH_STOP:
1555 GST_OBJECT_LOCK (trans);
1556 /* reset QoS parameters */
1557 trans->priv->proportion = 1.0;
1558 trans->priv->earliest_time = -1;
1559 trans->priv->discont = FALSE;
1560 trans->priv->processed = 0;
1561 trans->priv->dropped = 0;
1562 GST_OBJECT_UNLOCK (trans);
1563 /* we need new segment info after the flush. */
1564 trans->have_segment = FALSE;
1565 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
1566 trans->priv->position_out = GST_CLOCK_TIME_NONE;
1572 case GST_EVENT_CAPS:
1576 gst_event_parse_caps (event, &caps);
1577 gst_base_transform_setcaps (trans, trans->sinkpad, caps);
1582 case GST_EVENT_SEGMENT:
1584 gst_event_parse_segment (event, &trans->segment);
1585 trans->have_segment = TRUE;
1587 GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT,
1599 gst_base_transform_src_event (GstPad * pad, GstEvent * event)
1601 GstBaseTransform *trans;
1602 GstBaseTransformClass *bclass;
1603 gboolean ret = TRUE;
1605 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1606 if (G_UNLIKELY (trans == NULL)) {
1607 gst_event_unref (event);
1611 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1613 if (bclass->src_event)
1614 ret = bclass->src_event (trans, event);
1616 gst_event_unref (event);
1618 gst_object_unref (trans);
1624 gst_base_transform_src_eventfunc (GstBaseTransform * trans, GstEvent * event)
1628 GST_DEBUG_OBJECT (trans, "handling event %p %" GST_PTR_FORMAT, event, event);
1630 switch (GST_EVENT_TYPE (event)) {
1631 case GST_EVENT_SEEK:
1633 case GST_EVENT_NAVIGATION:
1638 GstClockTimeDiff diff;
1639 GstClockTime timestamp;
1641 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
1642 gst_base_transform_update_qos (trans, proportion, diff, timestamp);
1649 ret = gst_pad_push_event (trans->sinkpad, event);
1654 /* perform a transform on @inbuf and put the result in @outbuf.
1656 * This function is common to the push and pull-based operations.
1658 * This function takes ownership of @inbuf */
1659 static GstFlowReturn
1660 gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
1661 GstBuffer ** outbuf)
1663 GstBaseTransformClass *bclass;
1664 GstFlowReturn ret = GST_FLOW_OK;
1665 gboolean want_in_place;
1666 GstClockTime running_time;
1667 GstClockTime timestamp;
1669 gboolean reconfigure;
1671 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1673 GST_OBJECT_LOCK (trans->sinkpad);
1674 reconfigure = GST_PAD_NEEDS_RECONFIGURE (trans->srcpad)
1675 || trans->priv->reconfigure;
1676 GST_OBJECT_FLAG_UNSET (trans->srcpad, GST_PAD_NEED_RECONFIGURE);
1677 trans->priv->reconfigure = FALSE;
1678 GST_OBJECT_UNLOCK (trans->sinkpad);
1680 if (G_UNLIKELY (reconfigure)) {
1683 GST_DEBUG_OBJECT (trans, "we had a pending reconfigure");
1685 incaps = gst_pad_get_current_caps (trans->sinkpad);
1687 goto no_reconfigure;
1689 /* if we need to reconfigure we pretend a buffer with new caps arrived. This
1690 * will reconfigure the transform with the new output format. We can only
1691 * do this if the buffer actually has caps. */
1692 if (!gst_base_transform_setcaps (trans, trans->sinkpad, incaps)) {
1693 gst_caps_unref (incaps);
1694 goto not_negotiated;
1696 gst_caps_unref (incaps);
1700 insize = gst_buffer_get_size (inbuf);
1702 if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
1703 GST_DEBUG_OBJECT (trans,
1704 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
1705 G_GUINT64_FORMAT, inbuf, insize, GST_BUFFER_OFFSET (inbuf));
1707 GST_DEBUG_OBJECT (trans,
1708 "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
1711 /* Don't allow buffer handling before negotiation, except in passthrough mode
1712 * or if the class doesn't implement a set_caps function (in which case it doesn't
1715 if (!trans->negotiated && !trans->passthrough && (bclass->set_caps != NULL))
1716 goto not_negotiated;
1718 /* Set discont flag so we can mark the outgoing buffer */
1719 if (GST_BUFFER_IS_DISCONT (inbuf)) {
1720 GST_DEBUG_OBJECT (trans, "got DISCONT buffer %p", inbuf);
1721 trans->priv->discont = TRUE;
1724 /* can only do QoS if the segment is in TIME */
1725 if (trans->segment.format != GST_FORMAT_TIME)
1728 /* QOS is done on the running time of the buffer, get it now */
1729 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
1730 running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
1733 if (running_time != -1) {
1735 GstClockTime earliest_time;
1738 /* lock for getting the QoS parameters that are set (in a different thread)
1739 * with the QOS events */
1740 GST_OBJECT_LOCK (trans);
1741 earliest_time = trans->priv->earliest_time;
1742 proportion = trans->priv->proportion;
1743 /* check for QoS, don't perform conversion for buffers
1744 * that are known to be late. */
1745 need_skip = trans->priv->qos_enabled &&
1746 earliest_time != -1 && running_time <= earliest_time;
1747 GST_OBJECT_UNLOCK (trans);
1750 GstMessage *qos_msg;
1751 GstClockTime duration;
1752 guint64 stream_time;
1755 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "skipping transform: qostime %"
1756 GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
1757 GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
1759 trans->priv->dropped++;
1761 duration = GST_BUFFER_DURATION (inbuf);
1763 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
1765 jitter = GST_CLOCK_DIFF (running_time, earliest_time);
1768 gst_message_new_qos (GST_OBJECT_CAST (trans), FALSE, running_time,
1769 stream_time, timestamp, duration);
1770 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1771 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1772 trans->priv->processed, trans->priv->dropped);
1773 gst_element_post_message (GST_ELEMENT_CAST (trans), qos_msg);
1775 /* mark discont for next buffer */
1776 trans->priv->discont = TRUE;
1783 /* first try to allocate an output buffer based on the currently negotiated
1784 * format. While we call pad-alloc we could renegotiate the srcpad format or
1785 * have a new suggestion for upstream buffer-alloc.
1786 * In any case, outbuf will contain a buffer suitable for doing the configured
1787 * transform after this function. */
1788 ret = gst_base_transform_prepare_output_buffer (trans, inbuf, outbuf);
1789 if (G_UNLIKELY (ret != GST_FLOW_OK))
1792 /* now perform the needed transform */
1793 if (trans->passthrough) {
1794 /* In passthrough mode, give transform_ip a look at the
1795 * buffer, without making it writable, or just push the
1797 if (bclass->transform_ip) {
1798 GST_DEBUG_OBJECT (trans, "doing passthrough transform");
1799 ret = bclass->transform_ip (trans, *outbuf);
1801 GST_DEBUG_OBJECT (trans, "element is in passthrough");
1804 want_in_place = (bclass->transform_ip != NULL) && trans->always_in_place;
1806 if (want_in_place) {
1807 GST_DEBUG_OBJECT (trans, "doing inplace transform");
1809 if (inbuf != *outbuf) {
1810 guint8 *indata, *outdata;
1811 gsize insize, outsize;
1813 /* Different buffer. The data can still be the same when we are dealing
1814 * with subbuffers of the same buffer. Note that because of the FIXME in
1815 * prepare_output_buffer() we have decreased the refcounts of inbuf and
1816 * outbuf to keep them writable */
1817 indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1818 outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
1820 if (indata != outdata)
1821 memcpy (outdata, indata, insize);
1823 gst_buffer_unmap (inbuf, indata, insize);
1824 gst_buffer_unmap (*outbuf, outdata, outsize);
1826 ret = bclass->transform_ip (trans, *outbuf);
1828 GST_DEBUG_OBJECT (trans, "doing non-inplace transform");
1830 if (bclass->transform)
1831 ret = bclass->transform (trans, inbuf, *outbuf);
1833 ret = GST_FLOW_NOT_SUPPORTED;
1838 /* only unref input buffer if we allocated a new outbuf buffer */
1839 if (*outbuf != inbuf)
1840 gst_buffer_unref (inbuf);
1847 gst_buffer_unref (inbuf);
1848 GST_ELEMENT_ERROR (trans, STREAM, NOT_IMPLEMENTED,
1849 ("not negotiated"), ("not negotiated"));
1850 return GST_FLOW_NOT_NEGOTIATED;
1854 gst_buffer_unref (inbuf);
1855 GST_WARNING_OBJECT (trans, "could not get buffer from pool: %s",
1856 gst_flow_get_name (ret));
1862 gst_base_transform_check_get_range (GstPad * pad)
1864 GstBaseTransform *trans;
1867 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1869 ret = gst_pad_check_pull_range (trans->sinkpad);
1871 gst_object_unref (trans);
1876 /* FIXME, getrange is broken, need to pull range from the other
1877 * end based on the transform_size result.
1879 static GstFlowReturn
1880 gst_base_transform_getrange (GstPad * pad, guint64 offset,
1881 guint length, GstBuffer ** buffer)
1883 GstBaseTransform *trans;
1884 GstBaseTransformClass *klass;
1888 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
1890 ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
1891 if (G_UNLIKELY (ret != GST_FLOW_OK))
1894 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1895 if (klass->before_transform)
1896 klass->before_transform (trans, inbuf);
1898 GST_BASE_TRANSFORM_LOCK (trans);
1899 ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
1900 GST_BASE_TRANSFORM_UNLOCK (trans);
1903 gst_object_unref (trans);
1910 GST_DEBUG_OBJECT (trans, "failed to pull a buffer: %s",
1911 gst_flow_get_name (ret));
1916 static GstFlowReturn
1917 gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
1919 GstBaseTransform *trans;
1920 GstBaseTransformClass *klass;
1922 GstClockTime position = GST_CLOCK_TIME_NONE;
1923 GstClockTime timestamp, duration;
1924 GstBuffer *outbuf = NULL;
1926 trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
1928 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1929 duration = GST_BUFFER_DURATION (buffer);
1931 /* calculate end position of the incoming buffer */
1932 if (timestamp != GST_CLOCK_TIME_NONE) {
1933 if (duration != GST_CLOCK_TIME_NONE)
1934 position = timestamp + duration;
1936 position = timestamp;
1939 klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
1940 if (klass->before_transform)
1941 klass->before_transform (trans, buffer);
1943 /* protect transform method and concurrent buffer alloc */
1944 GST_BASE_TRANSFORM_LOCK (trans);
1945 ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
1946 GST_BASE_TRANSFORM_UNLOCK (trans);
1948 /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but
1949 * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */
1950 if (outbuf != NULL) {
1951 if ((ret == GST_FLOW_OK)) {
1952 GstClockTime position_out = GST_CLOCK_TIME_NONE;
1954 /* Remember last stop position */
1955 if (position != GST_CLOCK_TIME_NONE &&
1956 trans->segment.format == GST_FORMAT_TIME)
1957 trans->segment.position = position;
1959 if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) {
1960 position_out = GST_BUFFER_TIMESTAMP (outbuf);
1961 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
1962 position_out += GST_BUFFER_DURATION (outbuf);
1963 } else if (position != GST_CLOCK_TIME_NONE) {
1964 position_out = position;
1966 if (position_out != GST_CLOCK_TIME_NONE
1967 && trans->segment.format == GST_FORMAT_TIME)
1968 trans->priv->position_out = position_out;
1970 /* apply DISCONT flag if the buffer is not yet marked as such */
1971 if (trans->priv->discont) {
1972 if (!GST_BUFFER_IS_DISCONT (outbuf)) {
1973 outbuf = gst_buffer_make_writable (outbuf);
1974 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
1976 trans->priv->discont = FALSE;
1978 trans->priv->processed++;
1979 ret = gst_pad_push (trans->srcpad, outbuf);
1981 gst_buffer_unref (outbuf);
1985 /* convert internal flow to OK and mark discont for the next buffer. */
1986 if (ret == GST_BASE_TRANSFORM_FLOW_DROPPED) {
1987 trans->priv->discont = TRUE;
1995 gst_base_transform_set_property (GObject * object, guint prop_id,
1996 const GValue * value, GParamSpec * pspec)
1998 GstBaseTransform *trans;
2000 trans = GST_BASE_TRANSFORM (object);
2004 gst_base_transform_set_qos_enabled (trans, g_value_get_boolean (value));
2007 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2013 gst_base_transform_get_property (GObject * object, guint prop_id,
2014 GValue * value, GParamSpec * pspec)
2016 GstBaseTransform *trans;
2018 trans = GST_BASE_TRANSFORM (object);
2022 g_value_set_boolean (value, gst_base_transform_is_qos_enabled (trans));
2025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2030 /* not a vmethod of anything, just an internal method */
2032 gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
2034 GstBaseTransformClass *bclass;
2035 gboolean result = TRUE;
2037 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2040 GstCaps *incaps, *outcaps;
2042 if (trans->priv->pad_mode == GST_ACTIVATE_NONE && bclass->start)
2043 result &= bclass->start (trans);
2045 incaps = gst_pad_get_current_caps (trans->sinkpad);
2046 outcaps = gst_pad_get_current_caps (trans->srcpad);
2048 GST_OBJECT_LOCK (trans);
2049 if (incaps && outcaps)
2050 trans->have_same_caps =
2051 gst_caps_is_equal (incaps, outcaps) || trans->passthrough;
2053 trans->have_same_caps = trans->passthrough;
2054 GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps);
2055 trans->negotiated = FALSE;
2056 trans->have_segment = FALSE;
2057 gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED);
2058 trans->priv->position_out = GST_CLOCK_TIME_NONE;
2059 trans->priv->proportion = 1.0;
2060 trans->priv->earliest_time = -1;
2061 trans->priv->discont = FALSE;
2062 trans->priv->processed = 0;
2063 trans->priv->dropped = 0;
2064 GST_OBJECT_UNLOCK (trans);
2067 gst_caps_unref (incaps);
2069 gst_caps_unref (outcaps);
2071 /* We must make sure streaming has finished before resetting things
2072 * and calling the ::stop vfunc */
2073 GST_PAD_STREAM_LOCK (trans->sinkpad);
2074 GST_PAD_STREAM_UNLOCK (trans->sinkpad);
2076 trans->have_same_caps = FALSE;
2077 /* We can only reset the passthrough mode if the instance told us to
2078 handle it in configure_caps */
2079 if (bclass->passthrough_on_same_caps) {
2080 gst_base_transform_set_passthrough (trans, FALSE);
2082 gst_caps_replace (&trans->cache_caps1, NULL);
2083 gst_caps_replace (&trans->cache_caps2, NULL);
2085 if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
2086 result &= bclass->stop (trans);
2093 gst_base_transform_sink_activate_push (GstPad * pad, gboolean active)
2095 gboolean result = TRUE;
2096 GstBaseTransform *trans;
2098 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2100 result = gst_base_transform_activate (trans, active);
2103 trans->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
2105 gst_object_unref (trans);
2111 gst_base_transform_src_activate_pull (GstPad * pad, gboolean active)
2113 gboolean result = FALSE;
2114 GstBaseTransform *trans;
2116 trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
2118 result = gst_pad_activate_pull (trans->sinkpad, active);
2121 result &= gst_base_transform_activate (trans, active);
2124 trans->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
2126 gst_object_unref (trans);
2132 * gst_base_transform_set_passthrough:
2133 * @trans: the #GstBaseTransform to set
2134 * @passthrough: boolean indicating passthrough mode.
2136 * Set passthrough mode for this filter by default. This is mostly
2137 * useful for filters that do not care about negotiation.
2139 * Always TRUE for filters which don't implement either a transform
2140 * or transform_ip method.
2145 gst_base_transform_set_passthrough (GstBaseTransform * trans,
2146 gboolean passthrough)
2148 GstBaseTransformClass *bclass;
2150 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2152 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2154 GST_OBJECT_LOCK (trans);
2155 if (passthrough == FALSE) {
2156 if (bclass->transform_ip || bclass->transform)
2157 trans->passthrough = FALSE;
2159 trans->passthrough = TRUE;
2162 GST_DEBUG_OBJECT (trans, "set passthrough %d", trans->passthrough);
2163 GST_OBJECT_UNLOCK (trans);
2167 * gst_base_transform_is_passthrough:
2168 * @trans: the #GstBaseTransform to query
2170 * See if @trans is configured as a passthrough transform.
2172 * Returns: TRUE is the transform is configured in passthrough mode.
2177 gst_base_transform_is_passthrough (GstBaseTransform * trans)
2181 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2183 GST_OBJECT_LOCK (trans);
2184 result = trans->passthrough;
2185 GST_OBJECT_UNLOCK (trans);
2191 * gst_base_transform_set_in_place:
2192 * @trans: the #GstBaseTransform to modify
2193 * @in_place: Boolean value indicating that we would like to operate
2194 * on in_place buffers.
2196 * Determines whether a non-writable buffer will be copied before passing
2197 * to the transform_ip function.
2199 * <listitem>Always TRUE if no transform function is implemented.</listitem>
2200 * <listitem>Always FALSE if ONLY transform function is implemented.</listitem>
2206 gst_base_transform_set_in_place (GstBaseTransform * trans, gboolean in_place)
2208 GstBaseTransformClass *bclass;
2210 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2212 bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
2214 GST_OBJECT_LOCK (trans);
2217 if (bclass->transform_ip) {
2218 GST_DEBUG_OBJECT (trans, "setting in_place TRUE");
2219 trans->always_in_place = TRUE;
2222 if (bclass->transform) {
2223 GST_DEBUG_OBJECT (trans, "setting in_place FALSE");
2224 trans->always_in_place = FALSE;
2228 GST_OBJECT_UNLOCK (trans);
2232 * gst_base_transform_is_in_place:
2233 * @trans: the #GstBaseTransform to query
2235 * See if @trans is configured as a in_place transform.
2237 * Returns: TRUE is the transform is configured in in_place mode.
2242 gst_base_transform_is_in_place (GstBaseTransform * trans)
2246 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2248 GST_OBJECT_LOCK (trans);
2249 result = trans->always_in_place;
2250 GST_OBJECT_UNLOCK (trans);
2256 * gst_base_transform_update_qos:
2257 * @trans: a #GstBaseTransform
2258 * @proportion: the proportion
2259 * @diff: the diff against the clock
2260 * @timestamp: the timestamp of the buffer generating the QoS expressed in
2263 * Set the QoS parameters in the transform. This function is called internally
2264 * when a QOS event is received but subclasses can provide custom information
2272 gst_base_transform_update_qos (GstBaseTransform * trans,
2273 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2276 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2278 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans,
2279 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2280 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2282 GST_OBJECT_LOCK (trans);
2283 trans->priv->proportion = proportion;
2284 trans->priv->earliest_time = timestamp + diff;
2285 GST_OBJECT_UNLOCK (trans);
2289 * gst_base_transform_set_qos_enabled:
2290 * @trans: a #GstBaseTransform
2291 * @enabled: new state
2293 * Enable or disable QoS handling in the transform.
2300 gst_base_transform_set_qos_enabled (GstBaseTransform * trans, gboolean enabled)
2302 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2304 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, trans, "enabled: %d", enabled);
2306 GST_OBJECT_LOCK (trans);
2307 trans->priv->qos_enabled = enabled;
2308 GST_OBJECT_UNLOCK (trans);
2312 * gst_base_transform_is_qos_enabled:
2313 * @trans: a #GstBaseTransform
2315 * Queries if the transform will handle QoS.
2317 * Returns: TRUE if QoS is enabled.
2324 gst_base_transform_is_qos_enabled (GstBaseTransform * trans)
2328 g_return_val_if_fail (GST_IS_BASE_TRANSFORM (trans), FALSE);
2330 GST_OBJECT_LOCK (trans);
2331 result = trans->priv->qos_enabled;
2332 GST_OBJECT_UNLOCK (trans);
2338 * gst_base_transform_set_gap_aware:
2339 * @trans: a #GstBaseTransform
2340 * @gap_aware: New state
2342 * If @gap_aware is %FALSE (the default), output buffers will have the
2343 * %GST_BUFFER_FLAG_GAP flag unset.
2345 * If set to %TRUE, the element must handle output buffers with this flag set
2346 * correctly, i.e. it can assume that the buffer contains neutral data but must
2347 * unset the flag if the output is no neutral data.
2354 gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
2356 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2358 GST_OBJECT_LOCK (trans);
2359 trans->priv->gap_aware = gap_aware;
2360 GST_DEBUG_OBJECT (trans, "set gap aware %d", trans->priv->gap_aware);
2361 GST_OBJECT_UNLOCK (trans);
2365 * gst_base_transform_suggest:
2366 * @trans: a #GstBaseTransform
2367 * @caps: (transfer none): caps to suggest
2368 * @size: buffer size to suggest
2370 * Instructs @trans to suggest new @caps upstream. A copy of @caps will be
2376 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
2379 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2381 /* push the renegotiate event */
2382 if (!gst_pad_push_event (GST_BASE_TRANSFORM_SINK_PAD (trans),
2383 gst_event_new_reconfigure ()))
2384 GST_DEBUG_OBJECT (trans, "Renegotiate event wasn't handled");
2388 * gst_base_transform_reconfigure:
2389 * @trans: a #GstBaseTransform
2391 * Instructs @trans to renegotiate a new downstream transform on the next
2392 * buffer. This function is typically called after properties on the transform
2393 * were set that influence the output format.
2398 gst_base_transform_reconfigure (GstBaseTransform * trans)
2400 g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
2402 GST_OBJECT_LOCK (trans);
2403 GST_DEBUG_OBJECT (trans, "marking reconfigure");
2404 trans->priv->reconfigure = TRUE;
2405 GST_OBJECT_UNLOCK (trans);