2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2002 Thomas Vander Stichele <thomas@apestaart.org>
6 * gstutils.c: Utility functions
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.
26 * @short_description: Various utility functions
28 * When defining own plugins, use the GST_BOILERPLATE ease gobject creation.
31 #include "gst_private.h"
35 #include "gstghostpad.h"
41 #include "gst-i18n-lib.h"
45 * @mem: a pointer to the memory to dump
46 * @size: the size of the memory block to dump
48 * Dumps the memory block into a hex representation. Useful for debugging.
51 gst_util_dump_mem (const guchar * mem, guint size)
54 GString *string = g_string_sized_new (50);
55 GString *chars = g_string_sized_new (18);
59 if (g_ascii_isprint (mem[i]))
60 g_string_append_c (chars, mem[i]);
62 g_string_append_c (chars, '.');
64 g_string_append_printf (string, "%02x ", mem[i]);
69 if (j == 16 || i == size) {
70 g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
71 string->str, chars->str);
72 g_string_set_size (string, 0);
73 g_string_set_size (chars, 0);
77 g_string_free (string, TRUE);
78 g_string_free (chars, TRUE);
83 * gst_util_set_value_from_string:
84 * @value: the value to set
85 * @value_str: the string to get the value from
87 * Converts the string to the type of the value and
88 * sets the value with it.
90 * Note that this function is dangerous as it does not return any indication
91 * if the conversion worked or not.
94 gst_util_set_value_from_string (GValue * value, const gchar * value_str)
98 g_return_if_fail (value != NULL);
99 g_return_if_fail (value_str != NULL);
101 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
102 g_type_name (G_VALUE_TYPE (value)));
104 res = gst_value_deserialize (value, value_str);
105 if (!res && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
106 /* backwards compat, all booleans that fail to parse are false */
107 g_value_set_boolean (value, FALSE);
110 g_return_if_fail (res);
114 * gst_util_set_object_arg:
115 * @object: the object to set the argument of
116 * @name: the name of the argument to set
117 * @value: the string value to set
119 * Convertes the string value to the type of the objects argument and
120 * sets the argument with it.
122 * Note that this function silently returns if @object has no property named
123 * @name or when @value cannot be converted to the type of the property.
126 gst_util_set_object_arg (GObject * object, const gchar * name,
133 g_return_if_fail (G_IS_OBJECT (object));
134 g_return_if_fail (name != NULL);
135 g_return_if_fail (value != NULL);
137 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
141 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
143 GST_DEBUG ("pspec->flags is %d, pspec->value_type is %d",
144 pspec->flags, (gint) value_type);
146 if (!(pspec->flags & G_PARAM_WRITABLE))
149 g_value_init (&v, value_type);
150 if (!gst_value_deserialize (&v, value))
153 g_object_set_property (object, pspec->name, &v);
157 /* work around error C2520: conversion from unsigned __int64 to double
158 * not implemented, use signed __int64
160 * These are implemented as functions because on some platforms a 64bit int to
161 * double conversion is not defined/implemented.
165 gst_util_guint64_to_gdouble (guint64 value)
167 if (value & G_GINT64_CONSTANT (0x8000000000000000))
168 return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
170 return (gdouble) ((gint64) value);
174 gst_util_gdouble_to_guint64 (gdouble value)
176 if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */
177 return ((guint64) ((gint64) value));
179 value -= (gdouble) 18446744073709551616.;
180 return ((guint64) ((gint64) value));
183 /* convenience struct for getting high and low uint32 parts of
190 #if G_BYTE_ORDER == G_BIG_ENDIAN
198 /* based on Hacker's Delight p152 */
200 gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom)
202 GstUInt64 q1, q0, rhat;
203 GstUInt64 v, cmp1, cmp2;
208 /* count number of leading zeroes, we know they must be in the high
209 * part of denom since denom > G_MAXUINT32. */
210 s = v.l.high | (v.l.high >> 1);
214 s = ~(s | (s >> 16));
215 s = s - ((s >> 1) & 0x55555555);
216 s = (s & 0x33333333) + ((s >> 2) & 0x33333333);
217 s = (s + (s >> 4)) & 0x0f0f0f0f;
219 s = (s + (s >> 16)) & 0x3f;
222 /* normalize divisor and dividend */
224 c1.ll = (c1.ll << s) | (c0.l.high >> (32 - s));
228 q1.ll = c1.ll / v.l.high;
229 rhat.ll = c1.ll - q1.ll * v.l.high;
231 cmp1.l.high = rhat.l.low;
232 cmp1.l.low = c0.l.high;
233 cmp2.ll = q1.ll * v.l.low;
235 while (q1.l.high || cmp2.ll > cmp1.ll) {
240 cmp1.l.high = rhat.l.low;
243 c1.l.high = c1.l.low;
244 c1.l.low = c0.l.high;
245 c1.ll -= q1.ll * v.ll;
246 q0.ll = c1.ll / v.l.high;
247 rhat.ll = c1.ll - q0.ll * v.l.high;
249 cmp1.l.high = rhat.l.low;
250 cmp1.l.low = c0.l.low;
251 cmp2.ll = q0.ll * v.l.low;
253 while (q0.l.high || cmp2.ll > cmp1.ll) {
258 cmp1.l.high = rhat.l.low;
261 q0.l.high += q1.l.low;
267 gst_util_uint64_scale_int64 (guint64 val, guint64 num, guint64 denom)
269 GstUInt64 a0, a1, b0, b1, c0, ct, c1, result;
276 /* do 128 bits multiply
284 * -------------------
287 a0.ll = (guint64) v.l.low * n.l.low;
288 a1.ll = (guint64) v.l.low * n.l.high;
289 b0.ll = (guint64) v.l.high * n.l.low;
290 b1.ll = (guint64) v.l.high * n.l.high;
292 /* and sum together with carry into 128 bits c1, c0 */
294 ct.ll = (guint64) a0.l.high + a1.l.low + b0.l.low;
295 c0.l.high = ct.l.low;
296 c1.ll = (guint64) a1.l.high + b0.l.high + ct.l.high + b1.ll;
298 /* if high bits bigger than denom, we overflow */
302 /* shortcut for division by 1, c1.ll should be 0 because of the
303 * overflow check above. */
307 /* and 128/64 bits division, result fits 64 bits */
308 if (denom <= G_MAXUINT32) {
309 guint32 den = (guint32) denom;
311 /* easy case, (c1,c0)128/(den)32 division */
313 c1.l.high = c1.ll % den;
314 c1.l.low = c0.l.high;
315 c0.l.high = c1.ll % den;
316 result.l.high = c1.ll / den;
317 result.l.low = c0.ll / den;
319 result.ll = gst_util_div128_64 (c1, c0, denom);
330 * gst_util_uint64_scale:
331 * @val: the number to scale
332 * @num: the numerator of the scale ratio
333 * @denom: the denominator of the scale ratio
335 * Scale @val by @num / @denom, trying to avoid overflows.
337 * This function can potentially be very slow if denom > G_MAXUINT32.
339 * Returns: @val * @num / @denom, trying to avoid overflows.
340 * In the case of an overflow, this function returns G_MAXUINT64.
343 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
345 g_return_val_if_fail (denom != 0, G_MAXUINT64);
350 if (num == 1 && denom == 1)
353 /* if the denom is high, we need to do a 64 muldiv */
354 if (denom > G_MAXINT32)
357 /* if num and denom are low we can do a 32 bit muldiv */
358 if (num <= G_MAXINT32)
361 /* val and num are high, we need 64 muldiv */
362 if (val > G_MAXINT32)
365 /* val is low and num is high, we can swap them and do 32 muldiv */
366 return gst_util_uint64_scale_int (num, (gint) val, (gint) denom);
369 return gst_util_uint64_scale_int (val, (gint) num, (gint) denom);
372 /* to the more heavy implementations... */
373 return gst_util_uint64_scale_int64 (val, num, denom);
377 * gst_util_uint64_scale_int:
378 * @val: guint64 (such as a #GstClockTime) to scale.
379 * @num: numerator of the scale factor.
380 * @denom: denominator of the scale factor.
382 * Scale a guint64 by a factor expressed as a fraction (num/denom), avoiding
383 * overflows and loss of precision.
385 * @num and @denom must be positive integers. @denom cannot be 0.
387 * Returns: @val * @num / @denom, avoiding overflow and loss of precision.
388 * In the case of an overflow, this function returns G_MAXUINT64.
391 gst_util_uint64_scale_int (guint64 val, gint num, gint denom)
396 g_return_val_if_fail (denom > 0, G_MAXUINT64);
397 g_return_val_if_fail (num >= 0, G_MAXUINT64);
402 if (num == 1 && denom == 1)
405 if (val <= G_MAXUINT32)
407 return val * num / denom;
409 /* do 96 bits mult/div */
411 result.ll = ((guint64) low.l.low) * num;
412 high.ll = ((guint64) low.l.high) * num + (result.l.high);
414 low.ll = high.ll / denom;
415 result.l.high = high.ll % denom;
419 if (low.ll + result.l.high > G_MAXUINT32)
422 result.l.high += low.l.low;
433 * gst_util_seqnum_next:
435 * Return a constantly incrementing sequence number.
437 * This function is used internally to GStreamer to be able to determine which
438 * events and messages are "the same". For example, elements may set the seqnum
439 * on a segment-done message to be the same as that of the last seek event, to
440 * indicate that event and the message correspond to the same segment.
442 * Returns: A constantly incrementing 32-bit unsigned integer, which might
443 * overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
444 * you handle wraparound correctly.
449 gst_util_seqnum_next (void)
451 static gint counter = 0;
452 return g_atomic_int_exchange_and_add (&counter, 1);
456 * gst_util_seqnum_compare:
457 * @s1: A sequence number.
458 * @s2: Another sequence number.
460 * Compare two sequence numbers, handling wraparound.
462 * The current implementation just returns (gint32)(@s1 - @s2).
464 * Returns: A negative number if @s1 is before @s2, 0 if they are equal, or a
465 * positive number if @s1 is after @s2.
470 gst_util_seqnum_compare (guint32 s1, guint32 s2)
472 return (gint32) (s1 - s2);
475 /* -----------------------------------------------------
477 * The following code will be moved out of the main
478 * gstreamer library someday.
484 string_append_indent (GString * str, gint count)
488 for (xx = 0; xx < count; xx++)
489 g_string_append_c (str, ' ');
493 * gst_print_pad_caps:
494 * @buf: the buffer to print the caps in
495 * @indent: initial indentation
496 * @pad: the pad to print the caps from
498 * Write the pad capabilities in a human readable format into
502 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
509 string_append_indent (buf, indent);
510 g_string_printf (buf, "%s:%s has no capabilities",
511 GST_DEBUG_PAD_NAME (pad));
515 s = gst_caps_to_string (caps);
516 g_string_append (buf, s);
522 * gst_print_element_args:
523 * @buf: the buffer to print the args in
524 * @indent: initial indentation
525 * @element: the element to print the args of
527 * Print the element argument in a human readable format in the given
531 gst_print_element_args (GString * buf, gint indent, GstElement * element)
534 GValue value = { 0, }; /* the important thing is that value.type = 0 */
536 GParamSpec *spec, **specs, **walk;
538 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
541 for (walk = specs; *walk; walk++) {
543 if (width < strlen (spec->name))
544 width = strlen (spec->name);
547 for (walk = specs; *walk; walk++) {
550 if (spec->flags & G_PARAM_READABLE) {
551 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
552 g_object_get_property (G_OBJECT (element), spec->name, &value);
553 str = g_strdup_value_contents (&value);
554 g_value_unset (&value);
556 str = g_strdup ("Parameter not readable.");
559 string_append_indent (buf, indent);
560 g_string_append (buf, spec->name);
561 string_append_indent (buf, 2 + width - strlen (spec->name));
562 g_string_append (buf, str);
563 g_string_append_c (buf, '\n');
572 * gst_element_create_all_pads:
573 * @element: a #GstElement to create pads for
575 * Creates a pad for each pad template that is always available.
576 * This function is only useful during object intialization of
577 * subclasses of #GstElement.
580 gst_element_create_all_pads (GstElement * element)
584 /* FIXME: lock element */
587 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
588 (G_OBJECT_GET_CLASS (element)));
591 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
593 if (padtempl->presence == GST_PAD_ALWAYS) {
596 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
598 gst_element_add_pad (element, pad);
600 padlist = padlist->next;
605 * gst_element_get_compatible_pad_template:
606 * @element: a #GstElement to get a compatible pad template for.
607 * @compattempl: the #GstPadTemplate to find a compatible template for.
609 * Retrieves a pad template from @element that is compatible with @compattempl.
610 * Pads from compatible templates can be linked together.
612 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
613 * unreferencing is necessary.
616 gst_element_get_compatible_pad_template (GstElement * element,
617 GstPadTemplate * compattempl)
619 GstPadTemplate *newtempl = NULL;
621 GstElementClass *class;
623 g_return_val_if_fail (element != NULL, NULL);
624 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
625 g_return_val_if_fail (compattempl != NULL, NULL);
627 class = GST_ELEMENT_GET_CLASS (element);
629 padlist = gst_element_class_get_pad_template_list (class);
631 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
632 "Looking for a suitable pad template in %s out of %d templates...",
633 GST_ELEMENT_NAME (element), g_list_length (padlist));
636 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
637 GstCaps *intersection;
641 * Check direction (must be opposite)
644 GST_CAT_LOG (GST_CAT_CAPS,
645 "checking pad template %s", padtempl->name_template);
646 if (padtempl->direction != compattempl->direction) {
647 GST_CAT_DEBUG (GST_CAT_CAPS,
648 "compatible direction: found %s pad template \"%s\"",
649 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
650 padtempl->name_template);
652 GST_CAT_DEBUG (GST_CAT_CAPS,
653 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
654 GST_CAT_DEBUG (GST_CAT_CAPS,
655 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
657 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
658 GST_PAD_TEMPLATE_CAPS (padtempl));
660 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
661 (intersection ? "" : "not "), intersection);
663 if (!gst_caps_is_empty (intersection))
665 gst_caps_unref (intersection);
670 padlist = g_list_next (padlist);
673 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
674 "Returning new pad template %p", newtempl);
676 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
682 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
685 GstPad *newpad = NULL;
686 GstElementClass *oclass;
688 oclass = GST_ELEMENT_GET_CLASS (element);
690 if (oclass->request_new_pad)
691 newpad = (oclass->request_new_pad) (element, templ, name);
694 gst_object_ref (newpad);
702 * gst_element_get_pad_from_template:
703 * @element: a #GstElement.
704 * @templ: a #GstPadTemplate belonging to @element.
706 * Gets a pad from @element described by @templ. If the presence of @templ is
707 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
710 * Returns: the #GstPad, or NULL if one could not be found or created.
713 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
716 GstPadPresence presence;
718 /* If this function is ever exported, we need check the validity of `element'
719 * and `templ', and to make sure the template actually belongs to the
722 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
726 case GST_PAD_SOMETIMES:
727 ret = gst_element_get_static_pad (element, templ->name_template);
728 if (!ret && presence == GST_PAD_ALWAYS)
730 ("Element %s has an ALWAYS template %s, but no pad of the same name",
731 GST_OBJECT_NAME (element), templ->name_template);
734 case GST_PAD_REQUEST:
735 ret = gst_element_request_pad (element, templ, NULL);
743 * gst_element_request_compatible_pad:
744 * @element: a #GstElement.
745 * @templ: the #GstPadTemplate to which the new pad should be able to link.
747 * Requests a pad from @element. The returned pad should be unlinked and
748 * compatible with @templ. Might return an existing pad, or request a new one.
750 * Returns: a #GstPad, or %NULL if one could not be found or created.
753 gst_element_request_compatible_pad (GstElement * element,
754 GstPadTemplate * templ)
756 GstPadTemplate *templ_new;
759 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
760 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
762 /* FIXME: should really loop through the templates, testing each for
763 * compatibility and pad availability. */
764 templ_new = gst_element_get_compatible_pad_template (element, templ);
766 pad = gst_element_get_pad_from_template (element, templ_new);
768 /* This can happen for non-request pads. No need to unref. */
769 if (pad && GST_PAD_PEER (pad))
776 * Checks if the source pad and the sink pad can be linked.
777 * Both @srcpad and @sinkpad must be unlinked and have a parent.
780 gst_pad_check_link (GstPad * srcpad, GstPad * sinkpad)
782 /* FIXME This function is gross. It's almost a direct copy of
783 * gst_pad_link_filtered(). Any decent programmer would attempt
784 * to merge the two functions, which I will do some day. --ds
788 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
789 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
791 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
792 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
794 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
795 if (GST_PAD_PEER (srcpad) != NULL) {
796 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
797 GST_DEBUG_PAD_NAME (srcpad));
800 if (GST_PAD_PEER (sinkpad) != NULL) {
801 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
802 GST_DEBUG_PAD_NAME (sinkpad));
805 if (!GST_PAD_IS_SRC (srcpad)) {
806 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
807 GST_DEBUG_PAD_NAME (srcpad));
810 if (!GST_PAD_IS_SINK (sinkpad)) {
811 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
812 GST_DEBUG_PAD_NAME (sinkpad));
815 if (GST_PAD_PARENT (srcpad) == NULL) {
816 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
817 GST_DEBUG_PAD_NAME (srcpad));
820 if (GST_PAD_PARENT (sinkpad) == NULL) {
821 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
822 GST_DEBUG_PAD_NAME (srcpad));
830 * gst_element_get_compatible_pad:
831 * @element: a #GstElement in which the pad should be found.
832 * @pad: the #GstPad to find a compatible one for.
833 * @caps: the #GstCaps to use as a filter.
835 * Looks for an unlinked pad to which the given pad can link. It is not
836 * guaranteed that linking the pads will work, though it should work in most
839 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
840 * found. gst_object_unref() after usage.
843 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
844 const GstCaps * caps)
847 GstPadTemplate *templ;
849 GstPad *foundpad = NULL;
852 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
853 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
855 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
856 "finding pad in %s compatible with %s:%s",
857 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
859 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
862 /* try to get an existing unlinked pad */
863 pads = gst_element_iterate_pads (element);
867 switch (gst_iterator_next (pads, &padptr)) {
868 case GST_ITERATOR_OK:
873 current = GST_PAD (padptr);
875 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
876 GST_DEBUG_PAD_NAME (current));
878 peer = gst_pad_get_peer (current);
880 if (peer == NULL && gst_pad_check_link (pad, current)) {
881 GstCaps *temp, *temp2, *intersection;
883 /* Now check if the two pads' caps are compatible */
884 temp = gst_pad_get_caps (pad);
886 intersection = gst_caps_intersect (temp, caps);
887 gst_caps_unref (temp);
892 temp = gst_pad_get_caps (current);
893 temp2 = gst_caps_intersect (temp, intersection);
894 gst_caps_unref (temp);
895 gst_caps_unref (intersection);
897 intersection = temp2;
899 if (!gst_caps_is_empty (intersection)) {
900 gst_caps_unref (intersection);
902 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
903 "found existing unlinked compatible pad %s:%s",
904 GST_DEBUG_PAD_NAME (current));
905 gst_iterator_free (pads);
909 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "incompatible pads");
911 gst_caps_unref (intersection);
913 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
914 "already linked or cannot be linked (peer = %p)", peer);
916 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
918 gst_object_unref (current);
920 gst_object_unref (peer);
923 case GST_ITERATOR_DONE:
926 case GST_ITERATOR_RESYNC:
927 gst_iterator_resync (pads);
929 case GST_ITERATOR_ERROR:
930 g_assert_not_reached ();
934 gst_iterator_free (pads);
936 GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element,
937 "Could not find a compatible unlinked always pad to link to %s:%s, now checking request pads",
938 GST_DEBUG_PAD_NAME (pad));
940 /* try to create a new one */
941 /* requesting is a little crazy, we need a template. Let's create one */
942 /* FIXME: why not gst_pad_get_pad_template (pad); */
943 templcaps = gst_pad_get_caps (pad);
945 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
946 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
948 foundpad = gst_element_request_compatible_pad (element, templ);
949 gst_object_unref (templ);
952 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
953 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
957 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
958 "Could not find a compatible pad to link to %s:%s",
959 GST_DEBUG_PAD_NAME (pad));
964 * gst_element_state_get_name:
965 * @state: a #GstState to get the name of.
967 * Gets a string representing the given state.
969 * Returns: a string with the name of the state.
971 G_CONST_RETURN gchar *
972 gst_element_state_get_name (GstState state)
975 #ifdef GST_DEBUG_COLOR
976 case GST_STATE_VOID_PENDING:
977 return "VOID_PENDING";
979 return "\033[01;34mNULL\033[00m";
980 case GST_STATE_READY:
981 return "\033[01;31mREADY\033[00m";
982 case GST_STATE_PLAYING:
983 return "\033[01;32mPLAYING\033[00m";
984 case GST_STATE_PAUSED:
985 return "\033[01;33mPAUSED\033[00m";
987 /* This is a memory leak */
988 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
990 case GST_STATE_VOID_PENDING:
991 return "VOID_PENDING";
994 case GST_STATE_READY:
996 case GST_STATE_PLAYING:
998 case GST_STATE_PAUSED:
1001 /* This is a memory leak */
1002 return g_strdup_printf ("UNKNOWN!(%d)", state);
1008 * gst_element_state_change_return_get_name:
1009 * @state_ret: a #GstStateChangeReturn to get the name of.
1011 * Gets a string representing the given state change result.
1013 * Returns: a string with the name of the state change result.
1017 G_CONST_RETURN gchar *
1018 gst_element_state_change_return_get_name (GstStateChangeReturn state_ret)
1020 switch (state_ret) {
1021 #ifdef GST_DEBUG_COLOR
1022 case GST_STATE_CHANGE_FAILURE:
1023 return "\033[01;31mFAILURE\033[00m";
1024 case GST_STATE_CHANGE_SUCCESS:
1025 return "\033[01;32mSUCCESS\033[00m";
1026 case GST_STATE_CHANGE_ASYNC:
1027 return "\033[01;33mASYNC\033[00m";
1028 case GST_STATE_CHANGE_NO_PREROLL:
1029 return "\033[01;34mNO_PREROLL\033[00m";
1031 /* This is a memory leak */
1032 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state_ret);
1034 case GST_STATE_CHANGE_FAILURE:
1036 case GST_STATE_CHANGE_SUCCESS:
1038 case GST_STATE_CHANGE_ASYNC:
1040 case GST_STATE_CHANGE_NO_PREROLL:
1041 return "NO PREROLL";
1043 /* This is a memory leak */
1044 return g_strdup_printf ("UNKNOWN!(%d)", state_ret);
1051 * gst_element_factory_can_src_caps :
1052 * @factory: factory to query
1053 * @caps: the caps to check
1055 * Checks if the factory can source the given capability.
1057 * Returns: true if it can src the capabilities
1060 gst_element_factory_can_src_caps (GstElementFactory * factory,
1061 const GstCaps * caps)
1065 g_return_val_if_fail (factory != NULL, FALSE);
1066 g_return_val_if_fail (caps != NULL, FALSE);
1068 templates = factory->staticpadtemplates;
1071 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1073 if (template->direction == GST_PAD_SRC) {
1074 if (gst_caps_is_always_compatible (gst_static_caps_get
1075 (&template->static_caps), caps))
1078 templates = g_list_next (templates);
1085 * gst_element_factory_can_sink_caps :
1086 * @factory: factory to query
1087 * @caps: the caps to check
1089 * Checks if the factory can sink the given capability.
1091 * Returns: true if it can sink the capabilities
1094 gst_element_factory_can_sink_caps (GstElementFactory * factory,
1095 const GstCaps * caps)
1099 g_return_val_if_fail (factory != NULL, FALSE);
1100 g_return_val_if_fail (caps != NULL, FALSE);
1102 templates = factory->staticpadtemplates;
1105 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1107 if (template->direction == GST_PAD_SINK) {
1108 if (gst_caps_is_always_compatible (caps,
1109 gst_static_caps_get (&template->static_caps)))
1112 templates = g_list_next (templates);
1119 /* if return val is true, *direct_child is a caller-owned ref on the direct
1120 * child of ancestor that is part of object's ancestry */
1122 object_has_ancestor (GstObject * object, GstObject * ancestor,
1123 GstObject ** direct_child)
1125 GstObject *child, *parent;
1128 *direct_child = NULL;
1130 child = gst_object_ref (object);
1131 parent = gst_object_get_parent (object);
1134 if (ancestor == parent) {
1136 *direct_child = child;
1138 gst_object_unref (child);
1139 gst_object_unref (parent);
1143 gst_object_unref (child);
1145 parent = gst_object_get_parent (parent);
1148 gst_object_unref (child);
1153 /* caller owns return */
1155 find_common_root (GstObject * o1, GstObject * o2)
1157 GstObject *top = o1;
1158 GstObject *kid1, *kid2;
1159 GstObject *root = NULL;
1161 while (GST_OBJECT_PARENT (top))
1162 top = GST_OBJECT_PARENT (top);
1164 /* the itsy-bitsy spider... */
1166 if (!object_has_ancestor (o2, top, &kid2))
1169 root = gst_object_ref (top);
1171 if (!object_has_ancestor (o1, kid2, &kid1)) {
1172 gst_object_unref (kid2);
1176 if (!object_has_ancestor (o2, kid1, &kid2)) {
1177 gst_object_unref (kid1);
1184 /* caller does not own return */
1186 ghost_up (GstElement * e, GstPad * pad)
1188 static gint ghost_pad_index = 0;
1191 GstObject *parent = GST_OBJECT_PARENT (e);
1193 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
1194 gpad = gst_ghost_pad_new (name, pad);
1197 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
1198 g_warning ("Pad named %s already exists in element %s\n",
1199 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
1200 gst_object_unref ((GstObject *) gpad);
1208 remove_pad (gpointer ppad, gpointer unused)
1212 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
1213 g_warning ("Couldn't remove pad %s from element %s",
1214 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
1218 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
1219 GSList ** pads_created)
1223 GSList *pads_created_local = NULL;
1225 g_assert (pads_created);
1227 e1 = GST_OBJECT_PARENT (*src);
1228 e2 = GST_OBJECT_PARENT (*sink);
1230 if (G_UNLIKELY (e1 == NULL)) {
1231 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1232 GST_PTR_FORMAT, *src);
1235 if (G_UNLIKELY (e2 == NULL)) {
1236 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1237 GST_PTR_FORMAT, *sink);
1241 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
1242 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
1243 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1247 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
1248 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1250 /* we need to setup some ghost pads */
1251 root = find_common_root (e1, e2);
1253 g_warning ("Trying to connect elements that don't share a common "
1254 "ancestor: %s and %s", GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
1258 while (GST_OBJECT_PARENT (e1) != root) {
1259 *src = ghost_up ((GstElement *) e1, *src);
1262 e1 = GST_OBJECT_PARENT (*src);
1263 pads_created_local = g_slist_prepend (pads_created_local, *src);
1265 while (GST_OBJECT_PARENT (e2) != root) {
1266 *sink = ghost_up ((GstElement *) e2, *sink);
1269 e2 = GST_OBJECT_PARENT (*sink);
1270 pads_created_local = g_slist_prepend (pads_created_local, *sink);
1273 gst_object_unref (root);
1274 *pads_created = g_slist_concat (*pads_created, pads_created_local);
1278 gst_object_unref (root);
1279 g_slist_foreach (pads_created_local, remove_pad, NULL);
1280 g_slist_free (pads_created_local);
1285 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1287 GSList *pads_created = NULL;
1290 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1293 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1297 g_slist_foreach (pads_created, remove_pad, NULL);
1299 g_slist_free (pads_created);
1305 * gst_element_link_pads:
1306 * @src: a #GstElement containing the source pad.
1307 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1308 * @dest: the #GstElement containing the destination pad.
1309 * @destpadname: the name of the #GstPad in destination element,
1310 * or NULL for any pad.
1312 * Links the two named pads of the source and destination elements.
1313 * Side effect is that if one of the pads has no parent, it becomes a
1314 * child of the parent of the other element. If they have different
1315 * parents, the link fails.
1317 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1320 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1321 GstElement * dest, const gchar * destpadname)
1323 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1324 GstPad *srcpad, *destpad;
1325 GstPadTemplate *srctempl, *desttempl;
1326 GstElementClass *srcclass, *destclass;
1329 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1330 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1332 srcclass = GST_ELEMENT_GET_CLASS (src);
1333 destclass = GST_ELEMENT_GET_CLASS (dest);
1335 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1336 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1337 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1338 destpadname ? destpadname : "(any)");
1342 /* name specified, look it up */
1343 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1344 srcpad = gst_element_get_request_pad (src, srcpadname);
1346 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1347 GST_ELEMENT_NAME (src), srcpadname);
1350 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1351 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1352 GST_DEBUG_PAD_NAME (srcpad));
1353 gst_object_unref (srcpad);
1356 if (GST_PAD_PEER (srcpad) != NULL) {
1357 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1358 GST_DEBUG_PAD_NAME (srcpad));
1359 gst_object_unref (srcpad);
1365 /* no name given, get the first available pad */
1366 GST_OBJECT_LOCK (src);
1367 srcpads = GST_ELEMENT_PADS (src);
1368 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1370 gst_object_ref (srcpad);
1371 GST_OBJECT_UNLOCK (src);
1374 /* get a destination pad */
1376 /* name specified, look it up */
1377 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1378 destpad = gst_element_get_request_pad (dest, destpadname);
1380 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1381 GST_ELEMENT_NAME (dest), destpadname);
1384 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1385 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1386 GST_DEBUG_PAD_NAME (destpad));
1387 gst_object_unref (destpad);
1390 if (GST_PAD_PEER (destpad) != NULL) {
1391 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1392 GST_DEBUG_PAD_NAME (destpad));
1393 gst_object_unref (destpad);
1399 /* no name given, get the first available pad */
1400 GST_OBJECT_LOCK (dest);
1401 destpads = GST_ELEMENT_PADS (dest);
1402 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1404 gst_object_ref (destpad);
1405 GST_OBJECT_UNLOCK (dest);
1408 if (srcpadname && destpadname) {
1411 /* two explicitly specified pads */
1412 result = pad_link_maybe_ghosting (srcpad, destpad);
1414 gst_object_unref (srcpad);
1415 gst_object_unref (destpad);
1421 /* loop through the allowed pads in the source, trying to find a
1422 * compatible destination pad */
1423 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1424 "looping through allowed src and dest pads");
1426 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1427 GST_DEBUG_PAD_NAME (srcpad));
1428 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1429 (GST_PAD_PEER (srcpad) == NULL)) {
1434 gst_object_ref (temp);
1436 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1439 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1440 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1441 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1443 gst_object_unref (destpad);
1444 gst_object_unref (srcpad);
1445 gst_object_unref (temp);
1450 gst_object_unref (temp);
1453 /* find a better way for this mess */
1455 srcpads = g_list_next (srcpads);
1457 gst_object_unref (srcpad);
1458 srcpad = GST_PAD_CAST (srcpads->data);
1459 gst_object_ref (srcpad);
1465 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1466 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1468 gst_object_unref (destpad);
1472 gst_object_unref (srcpad);
1476 /* loop through the existing pads in the destination */
1478 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1479 GST_DEBUG_PAD_NAME (destpad));
1480 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1481 (GST_PAD_PEER (destpad) == NULL)) {
1482 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1484 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1485 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1486 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1487 gst_object_unref (temp);
1488 gst_object_unref (destpad);
1492 gst_object_unref (temp);
1496 destpads = g_list_next (destpads);
1498 gst_object_unref (destpad);
1499 destpad = GST_PAD_CAST (destpads->data);
1500 gst_object_ref (destpad);
1507 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1508 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1509 gst_object_unref (destpad);
1513 gst_object_unref (destpad);
1517 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1518 "we might have request pads on both sides, checking...");
1519 srctempls = gst_element_class_get_pad_template_list (srcclass);
1520 desttempls = gst_element_class_get_pad_template_list (destclass);
1522 if (srctempls && desttempls) {
1524 srctempl = (GstPadTemplate *) srctempls->data;
1525 if (srctempl->presence == GST_PAD_REQUEST) {
1526 for (l = desttempls; l; l = l->next) {
1527 desttempl = (GstPadTemplate *) l->data;
1528 if (desttempl->presence == GST_PAD_REQUEST &&
1529 desttempl->direction != srctempl->direction) {
1530 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1531 (srctempl), gst_pad_template_get_caps (desttempl))) {
1533 gst_element_get_request_pad (src, srctempl->name_template);
1535 gst_element_get_request_pad (dest, desttempl->name_template);
1536 if (srcpad && destpad
1537 && pad_link_maybe_ghosting (srcpad, destpad)) {
1538 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1539 "linked pad %s:%s to pad %s:%s",
1540 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1541 gst_object_unref (srcpad);
1542 gst_object_unref (destpad);
1545 /* it failed, so we release the request pads */
1547 gst_element_release_request_pad (src, srcpad);
1549 gst_element_release_request_pad (dest, destpad);
1554 srctempls = srctempls->next;
1558 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1559 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1564 * gst_element_link_pads_filtered:
1565 * @src: a #GstElement containing the source pad.
1566 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1567 * @dest: the #GstElement containing the destination pad.
1568 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1569 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1571 * Links the two named pads of the source and destination elements. Side effect
1572 * is that if one of the pads has no parent, it becomes a child of the parent of
1573 * the other element. If they have different parents, the link fails. If @caps
1574 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1576 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1579 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1580 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1583 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1584 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1585 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1588 GstElement *capsfilter;
1590 GstState state, pending;
1592 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1594 GST_ERROR ("Could not make a capsfilter");
1598 parent = gst_object_get_parent (GST_OBJECT (src));
1599 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1601 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, 0);
1603 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1604 GST_ERROR ("Could not add capsfilter");
1605 gst_object_unref (capsfilter);
1606 gst_object_unref (parent);
1610 if (pending != GST_STATE_VOID_PENDING)
1613 gst_element_set_state (capsfilter, state);
1615 gst_object_unref (parent);
1617 g_object_set (capsfilter, "caps", filter, NULL);
1619 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1620 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1623 GST_INFO ("Could not link elements");
1624 gst_element_set_state (capsfilter, GST_STATE_NULL);
1625 /* this will unlink and unref as appropriate */
1626 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1630 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1636 * @src: a #GstElement containing the source pad.
1637 * @dest: the #GstElement containing the destination pad.
1639 * Links @src to @dest. The link must be from source to
1640 * destination; the other direction will not be tried. The function looks for
1641 * existing pads that aren't linked yet. It will request new pads if necessary.
1642 * Such pads need to be released manualy when unlinking.
1643 * If multiple links are possible, only one is established.
1645 * Make sure you have added your elements to a bin or pipeline with
1646 * gst_bin_add() before trying to link them.
1648 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1651 gst_element_link (GstElement * src, GstElement * dest)
1653 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1657 * gst_element_link_many:
1658 * @element_1: the first #GstElement in the link chain.
1659 * @element_2: the second #GstElement in the link chain.
1660 * @...: the NULL-terminated list of elements to link in order.
1662 * Chain together a series of elements. Uses gst_element_link().
1663 * Make sure you have added your elements to a bin or pipeline with
1664 * gst_bin_add() before trying to link them.
1666 * Returns: TRUE on success, FALSE otherwise.
1669 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1671 gboolean res = TRUE;
1674 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1675 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1677 va_start (args, element_2);
1680 if (!gst_element_link (element_1, element_2)) {
1685 element_1 = element_2;
1686 element_2 = va_arg (args, GstElement *);
1695 * gst_element_link_filtered:
1696 * @src: a #GstElement containing the source pad.
1697 * @dest: the #GstElement containing the destination pad.
1698 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1700 * Links @src to @dest using the given caps as filtercaps.
1701 * The link must be from source to
1702 * destination; the other direction will not be tried. The function looks for
1703 * existing pads that aren't linked yet. It will request new pads if necessary.
1704 * If multiple links are possible, only one is established.
1706 * Make sure you have added your elements to a bin or pipeline with
1707 * gst_bin_add() before trying to link them.
1709 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1712 gst_element_link_filtered (GstElement * src, GstElement * dest,
1715 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1719 * gst_element_unlink_pads:
1720 * @src: a #GstElement containing the source pad.
1721 * @srcpadname: the name of the #GstPad in source element.
1722 * @dest: a #GstElement containing the destination pad.
1723 * @destpadname: the name of the #GstPad in destination element.
1725 * Unlinks the two named pads of the source and destination elements.
1728 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1729 GstElement * dest, const gchar * destpadname)
1731 GstPad *srcpad, *destpad;
1732 gboolean srcrequest, destrequest;
1734 srcrequest = destrequest = FALSE;
1736 g_return_if_fail (src != NULL);
1737 g_return_if_fail (GST_IS_ELEMENT (src));
1738 g_return_if_fail (srcpadname != NULL);
1739 g_return_if_fail (dest != NULL);
1740 g_return_if_fail (GST_IS_ELEMENT (dest));
1741 g_return_if_fail (destpadname != NULL);
1743 /* obtain the pads requested */
1744 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1745 if ((srcpad = gst_element_get_request_pad (src, srcpadname)))
1747 if (srcpad == NULL) {
1748 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1751 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1752 if ((destpad = gst_element_get_request_pad (dest, destpadname)))
1754 if (destpad == NULL) {
1755 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1760 /* we're satisified they can be unlinked, let's do it */
1761 gst_pad_unlink (srcpad, destpad);
1764 gst_element_release_request_pad (dest, destpad);
1765 gst_object_unref (destpad);
1769 gst_element_release_request_pad (src, srcpad);
1770 gst_object_unref (srcpad);
1774 * gst_element_unlink_many:
1775 * @element_1: the first #GstElement in the link chain.
1776 * @element_2: the second #GstElement in the link chain.
1777 * @...: the NULL-terminated list of elements to unlink in order.
1779 * Unlinks a series of elements. Uses gst_element_unlink().
1782 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1786 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1787 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1789 va_start (args, element_2);
1792 gst_element_unlink (element_1, element_2);
1794 element_1 = element_2;
1795 element_2 = va_arg (args, GstElement *);
1802 * gst_element_unlink:
1803 * @src: the source #GstElement to unlink.
1804 * @dest: the sink #GstElement to unlink.
1806 * Unlinks all source pads of the source element with all sink pads
1807 * of the sink element to which they are linked.
1809 * If the link has been made using gst_element_link(), it could have created an
1810 * requestpad, which has to be released using gst_element_release_request_pad().
1813 gst_element_unlink (GstElement * src, GstElement * dest)
1816 gboolean done = FALSE;
1818 g_return_if_fail (GST_IS_ELEMENT (src));
1819 g_return_if_fail (GST_IS_ELEMENT (dest));
1821 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1822 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1824 pads = gst_element_iterate_pads (src);
1828 switch (gst_iterator_next (pads, &data)) {
1829 case GST_ITERATOR_OK:
1831 GstPad *pad = GST_PAD_CAST (data);
1833 if (GST_PAD_IS_SRC (pad)) {
1834 GstPad *peerpad = gst_pad_get_peer (pad);
1836 /* see if the pad is linked and is really a pad of dest */
1838 GstElement *peerelem;
1840 peerelem = gst_pad_get_parent_element (peerpad);
1842 if (peerelem == dest) {
1843 gst_pad_unlink (pad, peerpad);
1846 gst_object_unref (peerelem);
1848 gst_object_unref (peerpad);
1851 gst_object_unref (pad);
1854 case GST_ITERATOR_RESYNC:
1855 gst_iterator_resync (pads);
1857 case GST_ITERATOR_DONE:
1861 g_assert_not_reached ();
1865 gst_iterator_free (pads);
1869 * gst_element_query_position:
1870 * @element: a #GstElement to invoke the position query on.
1871 * @format: a pointer to the #GstFormat asked for.
1872 * On return contains the #GstFormat used.
1873 * @cur: A location in which to store the current position, or NULL.
1875 * Queries an element for the stream position.
1877 * Returns: TRUE if the query could be performed.
1880 gst_element_query_position (GstElement * element, GstFormat * format,
1886 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1887 g_return_val_if_fail (format != NULL, FALSE);
1889 query = gst_query_new_position (*format);
1890 ret = gst_element_query (element, query);
1893 gst_query_parse_position (query, format, cur);
1895 gst_query_unref (query);
1901 * gst_element_query_duration:
1902 * @element: a #GstElement to invoke the duration query on.
1903 * @format: a pointer to the #GstFormat asked for.
1904 * On return contains the #GstFormat used.
1905 * @duration: A location in which to store the total duration, or NULL.
1907 * Queries an element for the total stream duration.
1909 * Returns: TRUE if the query could be performed.
1912 gst_element_query_duration (GstElement * element, GstFormat * format,
1918 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1919 g_return_val_if_fail (format != NULL, FALSE);
1921 query = gst_query_new_duration (*format);
1922 ret = gst_element_query (element, query);
1925 gst_query_parse_duration (query, format, duration);
1927 gst_query_unref (query);
1933 * gst_element_query_convert:
1934 * @element: a #GstElement to invoke the convert query on.
1935 * @src_format: a #GstFormat to convert from.
1936 * @src_val: a value to convert.
1937 * @dest_format: a pointer to the #GstFormat to convert to.
1938 * @dest_val: a pointer to the result.
1940 * Queries an element to convert @src_val in @src_format to @dest_format.
1942 * Returns: TRUE if the query could be performed.
1945 gst_element_query_convert (GstElement * element, GstFormat src_format,
1946 gint64 src_val, GstFormat * dest_format, gint64 * dest_val)
1951 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1952 g_return_val_if_fail (dest_format != NULL, FALSE);
1953 g_return_val_if_fail (dest_val != NULL, FALSE);
1955 if (*dest_format == src_format) {
1956 *dest_val = src_val;
1960 query = gst_query_new_convert (src_format, src_val, *dest_format);
1961 ret = gst_element_query (element, query);
1964 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
1966 gst_query_unref (query);
1972 * gst_element_seek_simple
1973 * @element: a #GstElement to seek on
1974 * @format: a #GstFormat to execute the seek in, such as #GST_FORMAT_TIME
1975 * @seek_flags: seek options; playback applications will usually want to use
1976 * GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here
1977 * @seek_pos: position to seek to (relative to the start); if you are doing
1978 * a seek in #GST_FORMAT_TIME this value is in nanoseconds -
1979 * multiply with #GST_SECOND to convert seconds to nanoseconds or
1980 * with #GST_MSECOND to convert milliseconds to nanoseconds.
1982 * Simple API to perform a seek on the given element, meaning it just seeks
1983 * to the given position relative to the start of the stream. For more complex
1984 * operations like segment seeks (e.g. for looping) or changing the playback
1985 * rate or seeking relative to the last configured playback segment you should
1986 * use gst_element_seek().
1988 * In a completely prerolled PAUSED or PLAYING pipeline, seeking is always
1989 * guaranteed to return %TRUE on a seekable media type or %FALSE when the media
1990 * type is certainly not seekable (such as a live stream).
1992 * Some elements allow for seeking in the READY state, in this
1993 * case they will store the seek event and execute it when they are put to
1994 * PAUSED. If the element supports seek in READY, it will always return %TRUE when
1995 * it receives the event in the READY state.
1997 * Returns: %TRUE if the seek operation succeeded (the seek might not always be
1998 * executed instantly though)
2003 gst_element_seek_simple (GstElement * element, GstFormat format,
2004 GstSeekFlags seek_flags, gint64 seek_pos)
2006 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2007 g_return_val_if_fail (seek_pos >= 0, FALSE);
2009 return gst_element_seek (element, 1.0, format, seek_flags,
2010 GST_SEEK_TYPE_SET, seek_pos, GST_SEEK_TYPE_NONE, 0);
2014 * gst_pad_use_fixed_caps:
2015 * @pad: the pad to use
2017 * A helper function you can use that sets the
2018 * @gst_pad_get_fixed_caps_func as the getcaps function for the
2019 * pad. This way the function will always return the negotiated caps
2020 * or in case the pad is not negotiated, the padtemplate caps.
2022 * Use this function on a pad that, once _set_caps() has been called
2023 * on it, cannot be renegotiated to something else.
2026 gst_pad_use_fixed_caps (GstPad * pad)
2028 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
2032 * gst_pad_get_fixed_caps_func:
2033 * @pad: the pad to use
2035 * A helper function you can use as a GetCaps function that
2036 * will return the currently negotiated caps or the padtemplate
2039 * Returns: The currently negotiated caps or the padtemplate.
2042 gst_pad_get_fixed_caps_func (GstPad * pad)
2046 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2048 GST_OBJECT_LOCK (pad);
2049 if (GST_PAD_CAPS (pad)) {
2050 result = GST_PAD_CAPS (pad);
2052 GST_CAT_DEBUG (GST_CAT_CAPS,
2053 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2055 result = gst_caps_ref (result);
2056 } else if (GST_PAD_PAD_TEMPLATE (pad)) {
2057 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
2059 result = GST_PAD_TEMPLATE_CAPS (templ);
2060 GST_CAT_DEBUG (GST_CAT_CAPS,
2061 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2064 result = gst_caps_ref (result);
2066 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2067 result = gst_caps_new_empty ();
2069 GST_OBJECT_UNLOCK (pad);
2075 * gst_pad_get_parent_element:
2078 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
2079 * its parent is not an element, return NULL.
2081 * Returns: The parent of the pad. The caller has a reference on the parent, so
2082 * unref when you're finished with it.
2087 gst_pad_get_parent_element (GstPad * pad)
2091 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2093 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
2095 if (p && !GST_IS_ELEMENT (p)) {
2096 gst_object_unref (p);
2099 return GST_ELEMENT_CAST (p);
2103 * gst_object_default_error:
2104 * @source: the #GstObject that initiated the error.
2105 * @error: the GError.
2106 * @debug: an additional debug information string, or NULL.
2108 * A default error function.
2110 * The default handler will simply print the error string using g_print.
2113 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
2115 gchar *name = gst_object_get_path_string (source);
2117 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
2119 g_print (_("Additional debug info:\n%s\n"), debug);
2127 * @element_1: the #GstElement element to add to the bin
2128 * @...: additional elements to add to the bin
2130 * Adds a NULL-terminated list of elements to a bin. This function is
2131 * equivalent to calling gst_bin_add() for each member of the list. The return
2132 * value of each gst_bin_add() is ignored.
2135 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
2139 g_return_if_fail (GST_IS_BIN (bin));
2140 g_return_if_fail (GST_IS_ELEMENT (element_1));
2142 va_start (args, element_1);
2145 gst_bin_add (bin, element_1);
2147 element_1 = va_arg (args, GstElement *);
2154 * gst_bin_remove_many:
2156 * @element_1: the first #GstElement to remove from the bin
2157 * @...: NULL-terminated list of elements to remove from the bin
2159 * Remove a list of elements from a bin. This function is equivalent
2160 * to calling gst_bin_remove() with each member of the list.
2163 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
2167 g_return_if_fail (GST_IS_BIN (bin));
2168 g_return_if_fail (GST_IS_ELEMENT (element_1));
2170 va_start (args, element_1);
2173 gst_bin_remove (bin, element_1);
2175 element_1 = va_arg (args, GstElement *);
2182 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2183 guint arg_id, GParamFlags flags)
2185 GQuark prop_id = g_quark_from_string (prop_name);
2188 static GQuark fd_id = 0;
2189 static GQuark blocksize_id;
2190 static GQuark bytesperread_id;
2191 static GQuark dump_id;
2192 static GQuark filesize_id;
2193 static GQuark mmapsize_id;
2194 static GQuark location_id;
2195 static GQuark offset_id;
2196 static GQuark silent_id;
2197 static GQuark touch_id;
2200 fd_id = g_quark_from_static_string ("fd");
2201 blocksize_id = g_quark_from_static_string ("blocksize");
2202 bytesperread_id = g_quark_from_static_string ("bytesperread");
2203 dump_id = g_quark_from_static_string ("dump");
2204 filesize_id = g_quark_from_static_string ("filesize");
2205 mmapsize_id = g_quark_from_static_string ("mmapsize");
2206 location_id = g_quark_from_static_string ("location");
2207 offset_id = g_quark_from_static_string ("offset");
2208 silent_id = g_quark_from_static_string ("silent");
2209 touch_id = g_quark_from_static_string ("touch");
2212 if (prop_id == fd_id) {
2213 pspec = g_param_spec_int ("fd", "File-descriptor",
2214 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2215 } else if (prop_id == blocksize_id) {
2216 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2217 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2219 } else if (prop_id == bytesperread_id) {
2220 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2221 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2223 } else if (prop_id == dump_id) {
2224 pspec = g_param_spec_boolean ("dump", "Dump",
2225 "Dump bytes to stdout", FALSE, flags);
2227 } else if (prop_id == filesize_id) {
2228 pspec = g_param_spec_int64 ("filesize", "File Size",
2229 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2231 } else if (prop_id == mmapsize_id) {
2232 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2233 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2235 } else if (prop_id == location_id) {
2236 pspec = g_param_spec_string ("location", "File Location",
2237 "Location of the file to read", NULL, flags);
2239 } else if (prop_id == offset_id) {
2240 pspec = g_param_spec_int64 ("offset", "File Offset",
2241 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2243 } else if (prop_id == silent_id) {
2244 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2247 } else if (prop_id == touch_id) {
2248 pspec = g_param_spec_boolean ("touch", "Touch read data",
2249 "Touch data to force disk read before " "push ()", TRUE, flags);
2251 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2252 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2257 g_object_class_install_property (klass, arg_id, pspec);
2262 * gst_element_class_install_std_props:
2263 * @klass: the #GstElementClass to add the properties to.
2264 * @first_name: the name of the first property.
2265 * in a NULL terminated
2266 * @...: the id and flags of the first property, followed by
2267 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2269 * Adds a list of standardized properties with types to the @klass.
2270 * the id is for the property switch in your get_prop method, and
2271 * the flags determine readability / writeability.
2274 gst_element_class_install_std_props (GstElementClass * klass,
2275 const gchar * first_name, ...)
2281 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2283 va_start (args, first_name);
2288 int arg_id = va_arg (args, int);
2289 int flags = va_arg (args, int);
2291 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2294 name = va_arg (args, char *);
2303 * @buf1: the first source #GstBuffer to merge.
2304 * @buf2: the second source #GstBuffer to merge.
2306 * Create a new buffer that is the concatenation of the two source
2307 * buffers. The original source buffers will not be modified or
2308 * unref'd. Make sure you unref the source buffers if they are not used
2309 * anymore afterwards.
2311 * If the buffers point to contiguous areas of memory, the buffer
2312 * is created without copying the data.
2314 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2317 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2321 /* we're just a specific case of the more general gst_buffer_span() */
2322 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2329 * @buf1: the first source #GstBuffer.
2330 * @buf2: the second source #GstBuffer.
2332 * Create a new buffer that is the concatenation of the two source
2333 * buffers, and unrefs the original source buffers.
2335 * If the buffers point to contiguous areas of memory, the buffer
2336 * is created without copying the data.
2338 * This is a convenience function for C programmers. See also
2339 * gst_buffer_merge(), which does the same thing without
2340 * unreffing the input parameters. Language bindings without
2341 * explicit reference counting should not wrap this function.
2343 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2346 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2350 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2351 gst_buffer_unref (buf1);
2352 gst_buffer_unref (buf2);
2360 * @dest: buffer to stamp
2361 * @src: buffer to stamp from
2363 * Copies additional information (the timestamp, duration, and offset start
2364 * and end) from one buffer to the other.
2366 * This function does not copy any buffer flags or caps and is equivalent to
2367 * gst_buffer_copy_metadata(@dest, @src, GST_BUFFER_COPY_TIMESTAMPS).
2369 * Deprecated: use gst_buffer_copy_metadata() instead, it provides more
2372 #ifndef GST_REMOVE_DEPRECATED
2374 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2376 gst_buffer_copy_metadata (dest, src, GST_BUFFER_COPY_TIMESTAMPS);
2378 #endif /* GST_REMOVE_DEPRECATED */
2381 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2383 /* skip the pad, the request came from */
2385 GstCaps *peercaps, *existing;
2387 existing = g_value_get_pointer (ret);
2388 peercaps = gst_pad_peer_get_caps (pad);
2389 if (peercaps == NULL)
2390 peercaps = gst_caps_new_any ();
2391 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2392 gst_caps_unref (existing);
2393 gst_caps_unref (peercaps);
2395 gst_object_unref (pad);
2400 * gst_pad_proxy_getcaps:
2401 * @pad: a #GstPad to proxy.
2403 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2404 * same element as @pad, and returns the intersection of the results.
2406 * This function is useful as a default getcaps function for an element
2407 * that can handle any stream format, but requires all its pads to have
2408 * the same caps. Two such elements are tee and aggregator.
2410 * Returns: the intersection of the other pads' allowed caps.
2413 gst_pad_proxy_getcaps (GstPad * pad)
2415 GstElement *element;
2416 GstCaps *caps, *intersected;
2418 GstIteratorResult res;
2419 GValue ret = { 0, };
2421 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2423 GST_CAT_DEBUG (GST_CAT_PADS, "proxying getcaps for %s:%s",
2424 GST_DEBUG_PAD_NAME (pad));
2426 element = gst_pad_get_parent_element (pad);
2427 if (element == NULL)
2430 /* value to hold the return, by default it holds ANY, the ref is taken by
2432 g_value_init (&ret, G_TYPE_POINTER);
2433 g_value_set_pointer (&ret, gst_caps_new_any ());
2435 iter = gst_element_iterate_pads (element);
2438 gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2441 case GST_ITERATOR_RESYNC:
2442 /* unref any value stored */
2443 if ((caps = g_value_get_pointer (&ret)))
2444 gst_caps_unref (caps);
2445 /* need to reset the result again to ANY */
2446 g_value_set_pointer (&ret, gst_caps_new_any ());
2447 gst_iterator_resync (iter);
2449 case GST_ITERATOR_DONE:
2450 /* all pads iterated, return collected value */
2453 /* iterator returned _ERROR or premature end with _OK,
2454 * mark an error and exit */
2455 if ((caps = g_value_get_pointer (&ret)))
2456 gst_caps_unref (caps);
2457 g_value_set_pointer (&ret, NULL);
2462 gst_iterator_free (iter);
2464 gst_object_unref (element);
2466 caps = g_value_get_pointer (&ret);
2467 g_value_unset (&ret);
2469 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2470 gst_caps_unref (caps);
2477 g_warning ("Pad list returned error on element %s",
2478 GST_ELEMENT_NAME (element));
2479 gst_iterator_free (iter);
2480 gst_object_unref (element);
2492 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2494 gboolean success = TRUE;
2496 if (pad != data->orig) {
2497 success = gst_pad_set_caps (pad, data->caps);
2498 g_value_set_boolean (ret, success);
2500 gst_object_unref (pad);
2506 * gst_pad_proxy_setcaps
2507 * @pad: a #GstPad to proxy from
2508 * @caps: the #GstCaps to link with
2510 * Calls gst_pad_set_caps() for every other pad belonging to the
2511 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2512 * the proxy setcaps fails. May be used only during negotiation.
2514 * Returns: TRUE if sucessful
2517 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2519 GstElement *element;
2521 GstIteratorResult res;
2522 GValue ret = { 0, };
2525 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2526 g_return_val_if_fail (caps != NULL, FALSE);
2528 GST_CAT_DEBUG (GST_CAT_PADS, "proxying pad link for %s:%s",
2529 GST_DEBUG_PAD_NAME (pad));
2531 element = gst_pad_get_parent_element (pad);
2532 if (element == NULL)
2535 iter = gst_element_iterate_pads (element);
2537 g_value_init (&ret, G_TYPE_BOOLEAN);
2538 g_value_set_boolean (&ret, TRUE);
2542 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2544 gst_iterator_free (iter);
2546 if (res != GST_ITERATOR_DONE)
2549 gst_object_unref (element);
2551 /* ok not to unset the gvalue */
2552 return g_value_get_boolean (&ret);
2557 g_warning ("Pad list changed during proxy_pad_link for element %s",
2558 GST_ELEMENT_NAME (element));
2559 gst_object_unref (element);
2565 * gst_pad_query_position:
2566 * @pad: a #GstPad to invoke the position query on.
2567 * @format: a pointer to the #GstFormat asked for.
2568 * On return contains the #GstFormat used.
2569 * @cur: A location in which to store the current position, or NULL.
2571 * Queries a pad for the stream position.
2573 * Returns: TRUE if the query could be performed.
2576 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur)
2581 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2582 g_return_val_if_fail (format != NULL, FALSE);
2584 query = gst_query_new_position (*format);
2585 ret = gst_pad_query (pad, query);
2588 gst_query_parse_position (query, format, cur);
2590 gst_query_unref (query);
2596 * gst_pad_query_peer_position:
2597 * @pad: a #GstPad on whose peer to invoke the position query on.
2598 * Must be a sink pad.
2599 * @format: a pointer to the #GstFormat asked for.
2600 * On return contains the #GstFormat used.
2601 * @cur: A location in which to store the current position, or NULL.
2603 * Queries the peer of a given sink pad for the stream position.
2605 * Returns: TRUE if the query could be performed.
2608 gst_pad_query_peer_position (GstPad * pad, GstFormat * format, gint64 * cur)
2610 gboolean ret = FALSE;
2613 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2614 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2615 g_return_val_if_fail (format != NULL, FALSE);
2617 peer = gst_pad_get_peer (pad);
2619 ret = gst_pad_query_position (peer, format, cur);
2620 gst_object_unref (peer);
2627 * gst_pad_query_duration:
2628 * @pad: a #GstPad to invoke the duration query on.
2629 * @format: a pointer to the #GstFormat asked for.
2630 * On return contains the #GstFormat used.
2631 * @duration: A location in which to store the total duration, or NULL.
2633 * Queries a pad for the total stream duration.
2635 * Returns: TRUE if the query could be performed.
2638 gst_pad_query_duration (GstPad * pad, GstFormat * format, gint64 * duration)
2643 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2644 g_return_val_if_fail (format != NULL, FALSE);
2646 query = gst_query_new_duration (*format);
2647 ret = gst_pad_query (pad, query);
2650 gst_query_parse_duration (query, format, duration);
2652 gst_query_unref (query);
2658 * gst_pad_query_peer_duration:
2659 * @pad: a #GstPad on whose peer pad to invoke the duration query on.
2660 * Must be a sink pad.
2661 * @format: a pointer to the #GstFormat asked for.
2662 * On return contains the #GstFormat used.
2663 * @duration: A location in which to store the total duration, or NULL.
2665 * Queries the peer pad of a given sink pad for the total stream duration.
2667 * Returns: TRUE if the query could be performed.
2670 gst_pad_query_peer_duration (GstPad * pad, GstFormat * format,
2673 gboolean ret = FALSE;
2676 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2677 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2678 g_return_val_if_fail (format != NULL, FALSE);
2680 peer = gst_pad_get_peer (pad);
2682 ret = gst_pad_query_duration (peer, format, duration);
2683 gst_object_unref (peer);
2690 * gst_pad_query_convert:
2691 * @pad: a #GstPad to invoke the convert query on.
2692 * @src_format: a #GstFormat to convert from.
2693 * @src_val: a value to convert.
2694 * @dest_format: a pointer to the #GstFormat to convert to.
2695 * @dest_val: a pointer to the result.
2697 * Queries a pad to convert @src_val in @src_format to @dest_format.
2699 * Returns: TRUE if the query could be performed.
2702 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2703 GstFormat * dest_format, gint64 * dest_val)
2708 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2709 g_return_val_if_fail (dest_format != NULL, FALSE);
2710 g_return_val_if_fail (dest_val != NULL, FALSE);
2712 if (*dest_format == src_format) {
2713 *dest_val = src_val;
2717 query = gst_query_new_convert (src_format, src_val, *dest_format);
2718 ret = gst_pad_query (pad, query);
2721 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2723 gst_query_unref (query);
2729 * gst_pad_query_peer_convert:
2730 * @pad: a #GstPad, on whose peer pad to invoke the convert query on.
2731 * Must be a sink pad.
2732 * @src_format: a #GstFormat to convert from.
2733 * @src_val: a value to convert.
2734 * @dest_format: a pointer to the #GstFormat to convert to.
2735 * @dest_val: a pointer to the result.
2737 * Queries the peer pad of a given sink pad to convert @src_val in @src_format
2740 * Returns: TRUE if the query could be performed.
2743 gst_pad_query_peer_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2744 GstFormat * dest_format, gint64 * dest_val)
2746 gboolean ret = FALSE;
2749 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2750 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2751 g_return_val_if_fail (src_val >= 0, FALSE);
2752 g_return_val_if_fail (dest_format != NULL, FALSE);
2753 g_return_val_if_fail (dest_val != NULL, FALSE);
2755 peer = gst_pad_get_peer (pad);
2757 ret = gst_pad_query_convert (peer, src_format, src_val, dest_format,
2759 gst_object_unref (peer);
2766 * gst_atomic_int_set:
2767 * @atomic_int: pointer to an atomic integer
2768 * @value: value to set
2770 * Unconditionally sets the atomic integer to @value.
2772 * Deprecated: Use g_atomic_int_set().
2775 #ifndef GST_REMOVE_DEPRECATED
2777 gst_atomic_int_set (gint * atomic_int, gint value)
2779 g_atomic_int_set (atomic_int, value);
2784 * gst_pad_add_data_probe:
2785 * @pad: pad to add the data probe handler to
2786 * @handler: function to call when data is passed over pad
2787 * @data: data to pass along with the handler
2789 * Adds a "data probe" to a pad. This function will be called whenever data
2790 * passes through a pad. In this case data means both events and buffers. The
2791 * probe will be called with the data as an argument, meaning @handler should
2792 * have the same callback signature as the #GstPad::have-data signal.
2793 * Note that the data will have a reference count greater than 1, so it will
2794 * be immutable -- you must not change it.
2796 * For source pads, the probe will be called after the blocking function, if any
2797 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2798 * to. For sink pads, the probe function will be called before configuring the
2799 * sink with new caps, if any, and before calling the pad's chain function.
2801 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2802 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2805 * Although probes are implemented internally by connecting @handler to the
2806 * have-data signal on the pad, if you want to remove a probe it is insufficient
2807 * to only call g_signal_handler_disconnect on the returned handler id. To
2808 * remove a probe, use the appropriate function, such as
2809 * gst_pad_remove_data_probe().
2811 * Returns: The handler id.
2814 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2816 return gst_pad_add_data_probe_full (pad, handler, data, NULL);
2820 * gst_pad_add_data_probe_full:
2821 * @pad: pad to add the data probe handler to
2822 * @handler: function to call when data is passed over pad
2823 * @data: data to pass along with the handler
2824 * @notify: function to call when the probe is disconnected, or NULL
2826 * Adds a "data probe" to a pad. This function will be called whenever data
2827 * passes through a pad. In this case data means both events and buffers. The
2828 * probe will be called with the data as an argument, meaning @handler should
2829 * have the same callback signature as the #GstPad::have-data signal.
2830 * Note that the data will have a reference count greater than 1, so it will
2831 * be immutable -- you must not change it.
2833 * For source pads, the probe will be called after the blocking function, if any
2834 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2835 * to. For sink pads, the probe function will be called before configuring the
2836 * sink with new caps, if any, and before calling the pad's chain function.
2838 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2839 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2842 * Although probes are implemented internally by connecting @handler to the
2843 * have-data signal on the pad, if you want to remove a probe it is insufficient
2844 * to only call g_signal_handler_disconnect on the returned handler id. To
2845 * remove a probe, use the appropriate function, such as
2846 * gst_pad_remove_data_probe().
2848 * The @notify function is called when the probe is disconnected and usually
2849 * used to free @data.
2851 * Returns: The handler id.
2856 gst_pad_add_data_probe_full (GstPad * pad, GCallback handler,
2857 gpointer data, GDestroyNotify notify)
2861 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2862 g_return_val_if_fail (handler != NULL, 0);
2864 GST_OBJECT_LOCK (pad);
2866 /* we only expose a GDestroyNotify in our API because that's less confusing */
2867 sigid = g_signal_connect_data (pad, "have-data", handler, data,
2868 (GClosureNotify) notify, 0);
2870 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2871 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2872 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2873 "adding data probe, now %d data, %d event probes",
2874 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2875 GST_OBJECT_UNLOCK (pad);
2881 * gst_pad_add_event_probe:
2882 * @pad: pad to add the event probe handler to
2883 * @handler: function to call when events are passed over pad
2884 * @data: data to pass along with the handler
2886 * Adds a probe that will be called for all events passing through a pad. See
2887 * gst_pad_add_data_probe() for more information.
2889 * Returns: The handler id
2892 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
2894 return gst_pad_add_event_probe_full (pad, handler, data, NULL);
2898 * gst_pad_add_event_probe_full:
2899 * @pad: pad to add the event probe handler to
2900 * @handler: function to call when events are passed over pad
2901 * @data: data to pass along with the handler, or NULL
2902 * @notify: function to call when probe is disconnected, or NULL
2904 * Adds a probe that will be called for all events passing through a pad. See
2905 * gst_pad_add_data_probe() for more information.
2907 * The @notify function is called when the probe is disconnected and usually
2908 * used to free @data.
2910 * Returns: The handler id
2915 gst_pad_add_event_probe_full (GstPad * pad, GCallback handler,
2916 gpointer data, GDestroyNotify notify)
2920 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2921 g_return_val_if_fail (handler != NULL, 0);
2923 GST_OBJECT_LOCK (pad);
2925 /* we only expose a GDestroyNotify in our API because that's less confusing */
2926 sigid = g_signal_connect_data (pad, "have-data::event", handler, data,
2927 (GClosureNotify) notify, 0);
2929 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2930 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding event probe, now %d probes",
2931 GST_PAD_DO_EVENT_SIGNALS (pad));
2932 GST_OBJECT_UNLOCK (pad);
2938 * gst_pad_add_buffer_probe:
2939 * @pad: pad to add the buffer probe handler to
2940 * @handler: function to call when buffers are passed over pad
2941 * @data: data to pass along with the handler
2943 * Adds a probe that will be called for all buffers passing through a pad. See
2944 * gst_pad_add_data_probe() for more information.
2946 * Returns: The handler id
2949 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2951 return gst_pad_add_buffer_probe_full (pad, handler, data, NULL);
2955 * gst_pad_add_buffer_probe_full:
2956 * @pad: pad to add the buffer probe handler to
2957 * @handler: function to call when buffer are passed over pad
2958 * @data: data to pass along with the handler
2959 * @notify: function to call when the probe is disconnected, or NULL
2961 * Adds a probe that will be called for all buffers passing through a pad. See
2962 * gst_pad_add_data_probe() for more information.
2964 * The @notify function is called when the probe is disconnected and usually
2965 * used to free @data.
2967 * Returns: The handler id
2972 gst_pad_add_buffer_probe_full (GstPad * pad, GCallback handler,
2973 gpointer data, GDestroyNotify notify)
2977 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2978 g_return_val_if_fail (handler != NULL, 0);
2980 GST_OBJECT_LOCK (pad);
2982 /* we only expose a GDestroyNotify in our API because that's less confusing */
2983 sigid = g_signal_connect_data (pad, "have-data::buffer", handler, data,
2984 (GClosureNotify) notify, 0);
2986 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2987 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding buffer probe, now %d probes",
2988 GST_PAD_DO_BUFFER_SIGNALS (pad));
2989 GST_OBJECT_UNLOCK (pad);
2995 * gst_pad_remove_data_probe:
2996 * @pad: pad to remove the data probe handler from
2997 * @handler_id: handler id returned from gst_pad_add_data_probe
2999 * Removes a data probe from @pad.
3002 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
3004 g_return_if_fail (GST_IS_PAD (pad));
3005 g_return_if_fail (handler_id > 0);
3007 GST_OBJECT_LOCK (pad);
3008 g_signal_handler_disconnect (pad, handler_id);
3009 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3010 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3011 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3012 "removed data probe, now %d event, %d buffer probes",
3013 GST_PAD_DO_EVENT_SIGNALS (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
3014 GST_OBJECT_UNLOCK (pad);
3019 * gst_pad_remove_event_probe:
3020 * @pad: pad to remove the event probe handler from
3021 * @handler_id: handler id returned from gst_pad_add_event_probe
3023 * Removes an event probe from @pad.
3026 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
3028 g_return_if_fail (GST_IS_PAD (pad));
3029 g_return_if_fail (handler_id > 0);
3031 GST_OBJECT_LOCK (pad);
3032 g_signal_handler_disconnect (pad, handler_id);
3033 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3034 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3035 "removed event probe, now %d event probes",
3036 GST_PAD_DO_EVENT_SIGNALS (pad));
3037 GST_OBJECT_UNLOCK (pad);
3041 * gst_pad_remove_buffer_probe:
3042 * @pad: pad to remove the buffer probe handler from
3043 * @handler_id: handler id returned from gst_pad_add_buffer_probe
3045 * Removes a buffer probe from @pad.
3048 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
3050 g_return_if_fail (GST_IS_PAD (pad));
3051 g_return_if_fail (handler_id > 0);
3053 GST_OBJECT_LOCK (pad);
3054 g_signal_handler_disconnect (pad, handler_id);
3055 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3056 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3057 "removed buffer probe, now %d buffer probes",
3058 GST_PAD_DO_BUFFER_SIGNALS (pad));
3059 GST_OBJECT_UNLOCK (pad);
3064 * gst_element_found_tags_for_pad:
3065 * @element: element for which to post taglist to bus.
3066 * @pad: pad on which to push tag-event.
3067 * @list: the taglist to post on the bus and create event from.
3069 * Posts a message to the bus that new tags were found and pushes the
3070 * tags as event. Takes ownership of the @list.
3072 * This is a utility method for elements. Applications should use the
3073 * #GstTagSetter interface.
3076 gst_element_found_tags_for_pad (GstElement * element,
3077 GstPad * pad, GstTagList * list)
3079 g_return_if_fail (element != NULL);
3080 g_return_if_fail (pad != NULL);
3081 g_return_if_fail (list != NULL);
3083 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
3084 /* FIXME 0.11: Set the pad as source to make it possible to detect for
3085 * which pad the tags are actually found.
3087 gst_element_post_message (element,
3088 gst_message_new_tag (GST_OBJECT (element), list));
3092 push_and_ref (GstPad * pad, GstEvent * event)
3094 gst_pad_push_event (pad, gst_event_ref (event));
3095 /* iterator refs pad, we unref when we are done with it */
3096 gst_object_unref (pad);
3100 * gst_element_found_tags:
3101 * @element: element for which we found the tags.
3102 * @list: list of tags.
3104 * Posts a message to the bus that new tags were found, and pushes an event
3105 * to all sourcepads. Takes ownership of the @list.
3107 * This is a utility method for elements. Applications should use the
3108 * #GstTagSetter interface.
3111 gst_element_found_tags (GstElement * element, GstTagList * list)
3116 g_return_if_fail (element != NULL);
3117 g_return_if_fail (list != NULL);
3119 iter = gst_element_iterate_src_pads (element);
3120 event = gst_event_new_tag (gst_tag_list_copy (list));
3121 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
3122 gst_iterator_free (iter);
3123 gst_event_unref (event);
3125 gst_element_post_message (element,
3126 gst_message_new_tag (GST_OBJECT (element), list));
3130 element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
3133 GstPad *unlinked_pad = NULL;
3136 switch (direction) {
3138 iter = gst_element_iterate_src_pads (element);
3141 iter = gst_element_iterate_sink_pads (element);
3144 g_return_val_if_reached (NULL);
3151 switch (gst_iterator_next (iter, &pad)) {
3152 case GST_ITERATOR_OK:{
3155 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
3156 GST_DEBUG_PAD_NAME (pad));
3158 peer = gst_pad_get_peer (GST_PAD (pad));
3162 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
3163 "found existing unlinked pad %s:%s",
3164 GST_DEBUG_PAD_NAME (unlinked_pad));
3166 gst_object_unref (pad);
3167 gst_object_unref (peer);
3171 case GST_ITERATOR_DONE:
3174 case GST_ITERATOR_RESYNC:
3175 gst_iterator_resync (iter);
3177 case GST_ITERATOR_ERROR:
3178 g_return_val_if_reached (NULL);
3183 gst_iterator_free (iter);
3185 return unlinked_pad;
3189 * gst_bin_find_unlinked_pad:
3190 * @bin: bin in which to look for elements with unlinked pads
3191 * @direction: whether to look for an unlinked source or sink pad
3193 * Recursively looks for elements with an unlinked pad of the given
3194 * direction within the specified bin and returns an unlinked pad
3195 * if one is found, or NULL otherwise. If a pad is found, the caller
3196 * owns a reference to it and should use gst_object_unref() on the
3197 * pad when it is not needed any longer.
3199 * Returns: unlinked pad of the given direction, or NULL.
3204 gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
3210 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
3211 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
3214 iter = gst_bin_iterate_recurse (bin);
3218 switch (gst_iterator_next (iter, &element)) {
3219 case GST_ITERATOR_OK:
3220 pad = element_find_unlinked_pad (GST_ELEMENT (element), direction);
3221 gst_object_unref (element);
3225 case GST_ITERATOR_DONE:
3228 case GST_ITERATOR_RESYNC:
3229 gst_iterator_resync (iter);
3231 case GST_ITERATOR_ERROR:
3232 g_return_val_if_reached (NULL);
3237 gst_iterator_free (iter);
3243 * gst_bin_find_unconnected_pad:
3244 * @bin: bin in which to look for elements with unlinked pads
3245 * @direction: whether to look for an unlinked source or sink pad
3247 * Recursively looks for elements with an unlinked pad of the given
3248 * direction within the specified bin and returns an unlinked pad
3249 * if one is found, or NULL otherwise. If a pad is found, the caller
3250 * owns a reference to it and should use gst_object_unref() on the
3251 * pad when it is not needed any longer.
3253 * Returns: unlinked pad of the given direction, or NULL.
3257 * Deprecated: use gst_bin_find_unlinked_pad() instead.
3259 #ifndef GST_REMOVE_DEPRECATED
3261 gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction)
3263 return gst_bin_find_unlinked_pad (bin, direction);
3268 * gst_parse_bin_from_description:
3269 * @bin_description: command line describing the bin
3270 * @ghost_unlinked_pads: whether to automatically create ghost pads
3271 * for unlinked source or sink pads within the bin
3272 * @err: where to store the error message in case of an error, or NULL
3274 * This is a convenience wrapper around gst_parse_launch() to create a
3275 * #GstBin from a gst-launch-style pipeline description. See
3276 * gst_parse_launch() and the gst-launch man page for details about the
3277 * syntax. Ghost pads on the bin for unlinked source or sink pads
3278 * within the bin can automatically be created (but only a maximum of
3279 * one ghost pad for each direction will be created; if you expect
3280 * multiple unlinked source pads or multiple unlinked sink pads
3281 * and want them all ghosted, you will have to create the ghost pads
3284 * Returns: a newly-created bin, or NULL if an error occurred.
3289 gst_parse_bin_from_description (const gchar * bin_description,
3290 gboolean ghost_unlinked_pads, GError ** err)
3292 return gst_parse_bin_from_description_full (bin_description,
3293 ghost_unlinked_pads, NULL, 0, err);
3297 * gst_parse_bin_from_description_full:
3298 * @bin_description: command line describing the bin
3299 * @ghost_unlinked_pads: whether to automatically create ghost pads
3300 * for unlinked source or sink pads within the bin
3301 * @context: a parse context allocated with gst_parse_context_new(), or %NULL
3302 * @flags: parsing options, or #GST_PARSE_FLAG_NONE
3303 * @err: where to store the error message in case of an error, or NULL
3305 * This is a convenience wrapper around gst_parse_launch() to create a
3306 * #GstBin from a gst-launch-style pipeline description. See
3307 * gst_parse_launch() and the gst-launch man page for details about the
3308 * syntax. Ghost pads on the bin for unlinked source or sink pads
3309 * within the bin can automatically be created (but only a maximum of
3310 * one ghost pad for each direction will be created; if you expect
3311 * multiple unlinked source pads or multiple unlinked sink pads
3312 * and want them all ghosted, you will have to create the ghost pads
3315 * Returns: a newly-created bin, or NULL if an error occurred.
3320 gst_parse_bin_from_description_full (const gchar * bin_description,
3321 gboolean ghost_unlinked_pads, GstParseContext * context,
3322 GstParseFlags flags, GError ** err)
3324 #ifndef GST_DISABLE_PARSE
3329 g_return_val_if_fail (bin_description != NULL, NULL);
3330 g_return_val_if_fail (err == NULL || *err == NULL, NULL);
3332 GST_DEBUG ("Making bin from description '%s'", bin_description);
3334 /* parse the pipeline to a bin */
3335 desc = g_strdup_printf ("bin.( %s )", bin_description);
3336 bin = (GstBin *) gst_parse_launch_full (desc, context, flags, err);
3339 if (bin == NULL || (err && *err != NULL)) {
3341 gst_object_unref (bin);
3345 /* find pads and ghost them if necessary */
3346 if (ghost_unlinked_pads) {
3347 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC))) {
3348 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("src", pad));
3349 gst_object_unref (pad);
3351 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SINK))) {
3352 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("sink", pad));
3353 gst_object_unref (pad);
3357 return GST_ELEMENT (bin);
3361 GST_WARNING ("Disabled API called");
3363 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED);
3364 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg);
3372 * gst_type_register_static_full:
3373 * @parent_type: The GType of the parent type the newly registered type will
3375 * @type_name: NULL-terminated string used as the name of the new type
3376 * @class_size: Size of the class structure.
3377 * @base_init: Location of the base initialization function (optional).
3378 * @base_finalize: Location of the base finalization function (optional).
3379 * @class_init: Location of the class initialization function for class types
3380 * Location of the default vtable inititalization function for interface
3382 * @class_finalize: Location of the class finalization function for class types.
3383 * Location of the default vtable finalization function for interface types.
3385 * @class_data: User-supplied data passed to the class init/finalize functions.
3386 * @instance_size: Size of the instance (object) structure (required for
3387 * instantiatable types only).
3388 * @n_preallocs: The number of pre-allocated (cached) instances to reserve
3389 * memory for (0 indicates no caching). Ignored on recent GLib's.
3390 * @instance_init: Location of the instance initialization function (optional,
3391 * for instantiatable types only).
3392 * @value_table: A GTypeValueTable function table for generic handling of
3393 * GValues of this type (usually only useful for fundamental types).
3394 * @flags: #GTypeFlags for this GType. E.g: G_TYPE_FLAG_ABSTRACT
3396 * Helper function which constructs a #GTypeInfo structure and registers a
3397 * GType, but which generates less linker overhead than a static const
3398 * #GTypeInfo structure. For further details of the parameters, please see
3399 * #GTypeInfo in the GLib documentation.
3401 * Registers type_name as the name of a new static type derived from
3402 * parent_type. The value of flags determines the nature (e.g. abstract or
3403 * not) of the type. It works by filling a GTypeInfo struct and calling
3404 * g_type_info_register_static().
3406 * Returns: A #GType for the newly-registered type.
3411 gst_type_register_static_full (GType parent_type,
3412 const gchar * type_name,
3414 GBaseInitFunc base_init,
3415 GBaseFinalizeFunc base_finalize,
3416 GClassInitFunc class_init,
3417 GClassFinalizeFunc class_finalize,
3418 gconstpointer class_data,
3419 guint instance_size,
3420 guint16 n_preallocs,
3421 GInstanceInitFunc instance_init,
3422 const GTypeValueTable * value_table, GTypeFlags flags)
3426 info.class_size = class_size;
3427 info.base_init = base_init;
3428 info.base_finalize = base_finalize;
3429 info.class_init = class_init;
3430 info.class_finalize = class_finalize;
3431 info.class_data = class_data;
3432 info.instance_size = instance_size;
3433 info.n_preallocs = n_preallocs;
3434 info.instance_init = instance_init;
3435 info.value_table = value_table;
3437 return g_type_register_static (parent_type, type_name, &info, flags);
3442 * gst_util_get_timestamp:
3444 * Get a timestamp as GstClockTime to be used for interval meassurements.
3445 * The timestamp should not be interpreted in any other way.
3447 * Returns: the timestamp
3452 gst_util_get_timestamp (void)
3454 #if defined (HAVE_POSIX_TIMERS) && defined(HAVE_MONOTONIC_CLOCK)
3455 struct timespec now;
3457 clock_gettime (CLOCK_MONOTONIC, &now);
3458 return GST_TIMESPEC_TO_TIME (now);
3462 g_get_current_time (&now);
3463 return GST_TIMEVAL_TO_TIME (now);
3468 * gst_util_array_binary_search:
3469 * @array: the sorted input array
3470 * @num_elements: number of elements in the array
3471 * @element_size: size of every element in bytes
3472 * @search_func: function to compare two elements, @search_data will always be passed as second argument
3473 * @mode: search mode that should be used
3474 * @search_data: element that should be found
3475 * @user_data: data to pass to @search_func
3477 * Searches inside @array for @search_data by using the comparison function
3478 * @search_func. @array must be sorted ascending.
3480 * As @search_data is always passed as second argument to @search_func it's
3481 * not required that @search_data has the same type as the array elements.
3483 * The complexity of this search function is O(log (num_elements)).
3485 * Returns: The address of the found element or %NULL if nothing was found
3490 gst_util_array_binary_search (gpointer array, guint num_elements,
3491 gsize element_size, GCompareDataFunc search_func, GstSearchMode mode,
3492 gconstpointer search_data, gpointer user_data)
3494 glong left = 0, right = num_elements - 1, m;
3496 guint8 *data = (guint8 *) array;
3498 g_return_val_if_fail (array != NULL, NULL);
3499 g_return_val_if_fail (element_size > 0, NULL);
3500 g_return_val_if_fail (search_func != NULL, NULL);
3502 /* 0. No elements => return NULL */
3503 if (num_elements == 0)
3506 /* 1. If search_data is before the 0th element return the 0th element */
3507 ret = search_func (data, search_data, user_data);
3508 if ((ret >= 0 && mode == GST_SEARCH_MODE_AFTER) || ret == 0)
3513 /* 2. If search_data is after the last element return the last element */
3515 search_func (data + (num_elements - 1) * element_size, search_data,
3517 if ((ret <= 0 && mode == GST_SEARCH_MODE_BEFORE) || ret == 0)
3518 return data + (num_elements - 1) * element_size;
3522 /* 3. else binary search */
3524 m = left + (right - left) / 2;
3526 ret = search_func (data + m * element_size, search_data, user_data);
3529 return data + m * element_size;
3530 } else if (ret < 0) {
3536 /* No exact match found */
3538 if (mode == GST_SEARCH_MODE_EXACT) {
3540 } else if (mode == GST_SEARCH_MODE_AFTER) {
3542 return (m < num_elements) ? data + (m + 1) * element_size : NULL;
3544 return data + m * element_size;
3547 return data + m * element_size;
3549 return (m > 0) ? data + (m - 1) * element_size : NULL;