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"
40 #include "gst-i18n-lib.h"
44 * @mem: a pointer to the memory to dump
45 * @size: the size of the memory block to dump
47 * Dumps the memory block into a hex representation. Useful for debugging.
50 gst_util_dump_mem (const guchar * mem, guint size)
53 GString *string = g_string_sized_new (50);
54 GString *chars = g_string_sized_new (18);
58 if (g_ascii_isprint (mem[i]))
59 g_string_append_c (chars, mem[i]);
61 g_string_append_c (chars, '.');
63 g_string_append_printf (string, "%02x ", mem[i]);
68 if (j == 16 || i == size) {
69 g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
70 string->str, chars->str);
71 g_string_set_size (string, 0);
72 g_string_set_size (chars, 0);
76 g_string_free (string, TRUE);
77 g_string_free (chars, TRUE);
82 * gst_util_set_value_from_string:
83 * @value: the value to set
84 * @value_str: the string to get the value from
86 * Converts the string to the type of the value and
87 * sets the value with it.
90 gst_util_set_value_from_string (GValue * value, const gchar * value_str)
94 g_return_if_fail (value != NULL);
95 g_return_if_fail (value_str != NULL);
97 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
98 g_type_name (G_VALUE_TYPE (value)));
100 switch (G_VALUE_TYPE (value)) {
102 g_value_set_string (value, value_str);
108 sscanf_ret = sscanf (value_str, "%d", &i);
109 g_return_if_fail (sscanf_ret == 1);
110 g_value_set_int (value, i);
116 sscanf_ret = sscanf (value_str, "%u", &i);
117 g_return_if_fail (sscanf_ret == 1);
118 g_value_set_uint (value, i);
124 sscanf_ret = sscanf (value_str, "%ld", &i);
125 g_return_if_fail (sscanf_ret == 1);
126 g_value_set_long (value, i);
132 sscanf_ret = sscanf (value_str, "%lu", &i);
133 g_return_if_fail (sscanf_ret == 1);
134 g_value_set_ulong (value, i);
137 case G_TYPE_BOOLEAN:{
140 if (!g_ascii_strncasecmp ("true", value_str, 4))
142 g_value_set_boolean (value, i);
148 sscanf_ret = sscanf (value_str, "%c", &i);
149 g_return_if_fail (sscanf_ret == 1);
150 g_value_set_char (value, i);
156 sscanf_ret = sscanf (value_str, "%c", &i);
157 g_return_if_fail (sscanf_ret == 1);
158 g_value_set_uchar (value, i);
164 sscanf_ret = sscanf (value_str, "%f", &i);
165 g_return_if_fail (sscanf_ret == 1);
166 g_value_set_float (value, i);
172 sscanf_ret = sscanf (value_str, "%g", &i);
173 g_return_if_fail (sscanf_ret == 1);
174 g_value_set_double (value, (gdouble) i);
183 * gst_util_set_object_arg:
184 * @object: the object to set the argument of
185 * @name: the name of the argument to set
186 * @value: the string value to set
188 * Convertes the string value to the type of the objects argument and
189 * sets the argument with it.
192 gst_util_set_object_arg (GObject * object, const gchar * name,
198 GParamSpec *paramspec;
201 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
207 GST_DEBUG ("paramspec->flags is %d, paramspec->value_type is %d",
208 paramspec->flags, (gint) paramspec->value_type);
210 if (paramspec->flags & G_PARAM_WRITABLE) {
211 switch (paramspec->value_type) {
213 g_object_set (G_OBJECT (object), name, value, NULL);
219 sscanf_ret = sscanf (value, "%d", &i);
220 g_return_if_fail (sscanf_ret == 1);
221 g_object_set (G_OBJECT (object), name, i, NULL);
227 sscanf_ret = sscanf (value, "%u", &i);
228 g_return_if_fail (sscanf_ret == 1);
229 g_object_set (G_OBJECT (object), name, i, NULL);
235 sscanf_ret = sscanf (value, "%ld", &i);
236 g_return_if_fail (sscanf_ret == 1);
237 g_object_set (G_OBJECT (object), name, i, NULL);
243 sscanf_ret = sscanf (value, "%lu", &i);
244 g_return_if_fail (sscanf_ret == 1);
245 g_object_set (G_OBJECT (object), name, i, NULL);
248 case G_TYPE_BOOLEAN:{
251 if (!g_ascii_strncasecmp ("true", value, 4))
253 g_object_set (G_OBJECT (object), name, i, NULL);
259 sscanf_ret = sscanf (value, "%c", &i);
260 g_return_if_fail (sscanf_ret == 1);
261 g_object_set (G_OBJECT (object), name, i, NULL);
267 sscanf_ret = sscanf (value, "%c", &i);
268 g_return_if_fail (sscanf_ret == 1);
269 g_object_set (G_OBJECT (object), name, i, NULL);
275 sscanf_ret = sscanf (value, "%f", &i);
276 g_return_if_fail (sscanf_ret == 1);
277 g_object_set (G_OBJECT (object), name, i, NULL);
283 sscanf_ret = sscanf (value, "%g", &i);
284 g_return_if_fail (sscanf_ret == 1);
285 g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
289 if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
292 sscanf_ret = sscanf (value, "%d", &i);
293 g_return_if_fail (sscanf_ret == 1);
294 g_object_set (G_OBJECT (object), name, i, NULL);
302 /* work around error C2520: conversion from unsigned __int64 to double
303 * not implemented, use signed __int64
305 * These are implemented as functions because on some platforms a 64bit int to
306 * double conversion is not defined/implemented.
310 gst_util_guint64_to_gdouble (guint64 value)
312 if (value & G_GINT64_CONSTANT (0x8000000000000000))
313 return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
315 return (gdouble) ((gint64) value);
319 gst_util_gdouble_to_guint64 (gdouble value)
321 if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */
322 return ((guint64) ((gint64) value));
324 value -= (gdouble) 18446744073709551616.;
325 return ((guint64) ((gint64) value));
328 /* convenience struct for getting high and low uint32 parts of
335 #if G_BYTE_ORDER == G_BIG_ENDIAN
343 /* based on Hacker's Delight p152 */
345 gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom)
347 GstUInt64 q1, q0, rhat;
348 GstUInt64 v, cmp1, cmp2;
353 /* count number of leading zeroes, we know they must be in the high
354 * part of denom since denom > G_MAXUINT32. */
355 s = v.l.high | (v.l.high >> 1);
359 s = ~(s | (s >> 16));
360 s = s - ((s >> 1) & 0x55555555);
361 s = (s & 0x33333333) + ((s >> 2) & 0x33333333);
362 s = (s + (s >> 4)) & 0x0f0f0f0f;
364 s = (s + (s >> 16)) & 0x3f;
367 /* normalize divisor and dividend */
369 c1.ll = (c1.ll << s) | (c0.l.high >> (32 - s));
373 q1.ll = c1.ll / v.l.high;
374 rhat.ll = c1.ll - q1.ll * v.l.high;
376 cmp1.l.high = rhat.l.low;
377 cmp1.l.low = c0.l.high;
378 cmp2.ll = q1.ll * v.l.low;
380 while (q1.l.high || cmp2.ll > cmp1.ll) {
385 cmp1.l.high = rhat.l.low;
388 c1.l.high = c1.l.low;
389 c1.l.low = c0.l.high;
390 c1.ll -= q1.ll * v.ll;
391 q0.ll = c1.ll / v.l.high;
392 rhat.ll = c1.ll - q0.ll * v.l.high;
394 cmp1.l.high = rhat.l.low;
395 cmp1.l.low = c0.l.low;
396 cmp2.ll = q0.ll * v.l.low;
398 while (q0.l.high || cmp2.ll > cmp1.ll) {
403 cmp1.l.high = rhat.l.low;
406 q0.l.high += q1.l.low;
412 gst_util_uint64_scale_int64 (guint64 val, guint64 num, guint64 denom)
414 GstUInt64 a0, a1, b0, b1, c0, ct, c1, result;
421 /* do 128 bits multiply
429 * -------------------
432 a0.ll = (guint64) v.l.low * n.l.low;
433 a1.ll = (guint64) v.l.low * n.l.high;
434 b0.ll = (guint64) v.l.high * n.l.low;
435 b1.ll = (guint64) v.l.high * n.l.high;
437 /* and sum together with carry into 128 bits c1, c0 */
439 ct.ll = (guint64) a0.l.high + a1.l.low + b0.l.low;
440 c0.l.high = ct.l.low;
441 c1.ll = (guint64) a1.l.high + b0.l.high + ct.l.high + b1.ll;
443 /* if high bits bigger than denom, we overflow */
447 /* shortcut for division by 1, c1.ll should be 0 because of the
448 * overflow check above. */
452 /* and 128/64 bits division, result fits 64 bits */
453 if (denom <= G_MAXUINT32) {
454 guint32 den = (guint32) denom;
456 /* easy case, (c1,c0)128/(den)32 division */
458 c1.l.high = c1.ll % den;
459 c1.l.low = c0.l.high;
460 c0.l.high = c1.ll % den;
461 result.l.high = c1.ll / den;
462 result.l.low = c0.ll / den;
464 result.ll = gst_util_div128_64 (c1, c0, denom);
475 * gst_util_uint64_scale:
476 * @val: the number to scale
477 * @num: the numerator of the scale ratio
478 * @denom: the denominator of the scale ratio
480 * Scale @val by @num / @denom, trying to avoid overflows.
482 * This function can potentially be very slow if denom > G_MAXUINT32.
484 * Returns: @val * @num / @denom, trying to avoid overflows.
485 * In the case of an overflow, this function returns G_MAXUINT64.
488 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
490 g_return_val_if_fail (denom != 0, G_MAXUINT64);
495 if (num == 1 && denom == 1)
498 /* if the denom is high, we need to do a 64 muldiv */
499 if (denom > G_MAXINT32)
502 /* if num and denom are low we can do a 32 bit muldiv */
503 if (num <= G_MAXINT32)
506 /* val and num are high, we need 64 muldiv */
507 if (val > G_MAXINT32)
510 /* val is low and num is high, we can swap them and do 32 muldiv */
511 return gst_util_uint64_scale_int (num, (gint) val, (gint) denom);
514 return gst_util_uint64_scale_int (val, (gint) num, (gint) denom);
517 /* to the more heavy implementations... */
518 return gst_util_uint64_scale_int64 (val, num, denom);
522 * gst_util_uint64_scale_int:
523 * @val: guint64 (such as a #GstClockTime) to scale.
524 * @num: numerator of the scale factor.
525 * @denom: denominator of the scale factor.
527 * Scale a guint64 by a factor expressed as a fraction (num/denom), avoiding
528 * overflows and loss of precision.
530 * @num and @denom must be positive integers. @denom cannot be 0.
532 * Returns: @val * @num / @denom, avoiding overflow and loss of precision.
533 * In the case of an overflow, this function returns G_MAXUINT64.
536 gst_util_uint64_scale_int (guint64 val, gint num, gint denom)
541 g_return_val_if_fail (denom > 0, G_MAXUINT64);
542 g_return_val_if_fail (num >= 0, G_MAXUINT64);
547 if (num == 1 && denom == 1)
550 if (val <= G_MAXUINT32)
552 return val * num / denom;
554 /* do 96 bits mult/div */
556 result.ll = ((guint64) low.l.low) * num;
557 high.ll = ((guint64) low.l.high) * num + (result.l.high);
559 low.ll = high.ll / denom;
560 result.l.high = high.ll % denom;
564 if (low.ll + result.l.high > G_MAXUINT32)
567 result.l.high += low.l.low;
578 * gst_util_seqnum_next:
580 * Return a constantly incrementing sequence number.
582 * This function is used internally to GStreamer to be able to determine which
583 * events and messages are "the same". For example, elements may set the seqnum
584 * on a segment-done message to be the same as that of the last seek event, to
585 * indicate that event and the message correspond to the same segment.
587 * Returns: A constantly incrementing 32-bit unsigned integer, which might
588 * overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
589 * you handle wraparound correctly.
594 gst_util_seqnum_next (void)
596 static gint counter = 0;
597 return g_atomic_int_exchange_and_add (&counter, 1);
601 * gst_util_seqnum_compare:
602 * @s1: A sequence number.
603 * @s2: Another sequence number.
605 * Compare two sequence numbers, handling wraparound.
607 * The current implementation just returns (gint32)(@s1 - @s2).
609 * Returns: A negative number if @s1 is before @s2, 0 if they are equal, or a
610 * positive number if @s1 is after @s2.
615 gst_util_seqnum_compare (guint32 s1, guint32 s2)
617 return (gint32) (s1 - s2);
620 /* -----------------------------------------------------
622 * The following code will be moved out of the main
623 * gstreamer library someday.
629 string_append_indent (GString * str, gint count)
633 for (xx = 0; xx < count; xx++)
634 g_string_append_c (str, ' ');
638 * gst_print_pad_caps:
639 * @buf: the buffer to print the caps in
640 * @indent: initial indentation
641 * @pad: the pad to print the caps from
643 * Write the pad capabilities in a human readable format into
647 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
654 string_append_indent (buf, indent);
655 g_string_printf (buf, "%s:%s has no capabilities",
656 GST_DEBUG_PAD_NAME (pad));
660 s = gst_caps_to_string (caps);
661 g_string_append (buf, s);
667 * gst_print_element_args:
668 * @buf: the buffer to print the args in
669 * @indent: initial indentation
670 * @element: the element to print the args of
672 * Print the element argument in a human readable format in the given
676 gst_print_element_args (GString * buf, gint indent, GstElement * element)
679 GValue value = { 0, }; /* the important thing is that value.type = 0 */
681 GParamSpec *spec, **specs, **walk;
683 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
686 for (walk = specs; *walk; walk++) {
688 if (width < strlen (spec->name))
689 width = strlen (spec->name);
692 for (walk = specs; *walk; walk++) {
695 if (spec->flags & G_PARAM_READABLE) {
696 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
697 g_object_get_property (G_OBJECT (element), spec->name, &value);
698 str = g_strdup_value_contents (&value);
699 g_value_unset (&value);
701 str = g_strdup ("Parameter not readable.");
704 string_append_indent (buf, indent);
705 g_string_append (buf, spec->name);
706 string_append_indent (buf, 2 + width - strlen (spec->name));
707 g_string_append (buf, str);
708 g_string_append_c (buf, '\n');
717 * gst_element_create_all_pads:
718 * @element: a #GstElement to create pads for
720 * Creates a pad for each pad template that is always available.
721 * This function is only useful during object intialization of
722 * subclasses of #GstElement.
725 gst_element_create_all_pads (GstElement * element)
729 /* FIXME: lock element */
732 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
733 (G_OBJECT_GET_CLASS (element)));
736 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
738 if (padtempl->presence == GST_PAD_ALWAYS) {
741 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
743 gst_element_add_pad (element, pad);
745 padlist = padlist->next;
750 * gst_element_get_compatible_pad_template:
751 * @element: a #GstElement to get a compatible pad template for.
752 * @compattempl: the #GstPadTemplate to find a compatible template for.
754 * Retrieves a pad template from @element that is compatible with @compattempl.
755 * Pads from compatible templates can be linked together.
757 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
758 * unreferencing is necessary.
761 gst_element_get_compatible_pad_template (GstElement * element,
762 GstPadTemplate * compattempl)
764 GstPadTemplate *newtempl = NULL;
766 GstElementClass *class;
768 g_return_val_if_fail (element != NULL, NULL);
769 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
770 g_return_val_if_fail (compattempl != NULL, NULL);
772 class = GST_ELEMENT_GET_CLASS (element);
774 padlist = gst_element_class_get_pad_template_list (class);
776 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
777 "Looking for a suitable pad template in %s out of %d templates...",
778 GST_ELEMENT_NAME (element), g_list_length (padlist));
781 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
782 GstCaps *intersection;
786 * Check direction (must be opposite)
789 GST_CAT_LOG (GST_CAT_CAPS,
790 "checking pad template %s", padtempl->name_template);
791 if (padtempl->direction != compattempl->direction) {
792 GST_CAT_DEBUG (GST_CAT_CAPS,
793 "compatible direction: found %s pad template \"%s\"",
794 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
795 padtempl->name_template);
797 GST_CAT_DEBUG (GST_CAT_CAPS,
798 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
799 GST_CAT_DEBUG (GST_CAT_CAPS,
800 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
802 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
803 GST_PAD_TEMPLATE_CAPS (padtempl));
805 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
806 (intersection ? "" : "not "), intersection);
808 if (!gst_caps_is_empty (intersection))
810 gst_caps_unref (intersection);
815 padlist = g_list_next (padlist);
818 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
819 "Returning new pad template %p", newtempl);
821 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
827 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
830 GstPad *newpad = NULL;
831 GstElementClass *oclass;
833 oclass = GST_ELEMENT_GET_CLASS (element);
835 if (oclass->request_new_pad)
836 newpad = (oclass->request_new_pad) (element, templ, name);
839 gst_object_ref (newpad);
847 * gst_element_get_pad_from_template:
848 * @element: a #GstElement.
849 * @templ: a #GstPadTemplate belonging to @element.
851 * Gets a pad from @element described by @templ. If the presence of @templ is
852 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
855 * Returns: the #GstPad, or NULL if one could not be found or created.
858 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
861 GstPadPresence presence;
863 /* If this function is ever exported, we need check the validity of `element'
864 * and `templ', and to make sure the template actually belongs to the
867 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
871 case GST_PAD_SOMETIMES:
872 ret = gst_element_get_static_pad (element, templ->name_template);
873 if (!ret && presence == GST_PAD_ALWAYS)
875 ("Element %s has an ALWAYS template %s, but no pad of the same name",
876 GST_OBJECT_NAME (element), templ->name_template);
879 case GST_PAD_REQUEST:
880 ret = gst_element_request_pad (element, templ, NULL);
888 * gst_element_request_compatible_pad:
889 * @element: a #GstElement.
890 * @templ: the #GstPadTemplate to which the new pad should be able to link.
892 * Requests a pad from @element. The returned pad should be unlinked and
893 * compatible with @templ. Might return an existing pad, or request a new one.
895 * Returns: a #GstPad, or %NULL if one could not be found or created.
898 gst_element_request_compatible_pad (GstElement * element,
899 GstPadTemplate * templ)
901 GstPadTemplate *templ_new;
904 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
905 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
907 /* FIXME: should really loop through the templates, testing each for
908 * compatibility and pad availability. */
909 templ_new = gst_element_get_compatible_pad_template (element, templ);
911 pad = gst_element_get_pad_from_template (element, templ_new);
913 /* This can happen for non-request pads. No need to unref. */
914 if (pad && GST_PAD_PEER (pad))
921 * Checks if the source pad and the sink pad can be linked.
922 * Both @srcpad and @sinkpad must be unlinked and have a parent.
925 gst_pad_check_link (GstPad * srcpad, GstPad * sinkpad)
927 /* FIXME This function is gross. It's almost a direct copy of
928 * gst_pad_link_filtered(). Any decent programmer would attempt
929 * to merge the two functions, which I will do some day. --ds
933 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
934 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
936 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
937 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
939 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
940 if (GST_PAD_PEER (srcpad) != NULL) {
941 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
942 GST_DEBUG_PAD_NAME (srcpad));
945 if (GST_PAD_PEER (sinkpad) != NULL) {
946 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
947 GST_DEBUG_PAD_NAME (sinkpad));
950 if (!GST_PAD_IS_SRC (srcpad)) {
951 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
952 GST_DEBUG_PAD_NAME (srcpad));
955 if (!GST_PAD_IS_SINK (sinkpad)) {
956 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
957 GST_DEBUG_PAD_NAME (sinkpad));
960 if (GST_PAD_PARENT (srcpad) == NULL) {
961 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
962 GST_DEBUG_PAD_NAME (srcpad));
965 if (GST_PAD_PARENT (sinkpad) == NULL) {
966 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
967 GST_DEBUG_PAD_NAME (srcpad));
975 * gst_element_get_compatible_pad:
976 * @element: a #GstElement in which the pad should be found.
977 * @pad: the #GstPad to find a compatible one for.
978 * @caps: the #GstCaps to use as a filter.
980 * Looks for an unlinked pad to which the given pad can link. It is not
981 * guaranteed that linking the pads will work, though it should work in most
984 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
985 * found. gst_object_unref() after usage.
988 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
989 const GstCaps * caps)
992 GstPadTemplate *templ;
994 GstPad *foundpad = NULL;
997 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
998 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1000 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1001 "finding pad in %s compatible with %s:%s",
1002 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
1004 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
1007 /* try to get an existing unlinked pad */
1008 pads = gst_element_iterate_pads (element);
1012 switch (gst_iterator_next (pads, &padptr)) {
1013 case GST_ITERATOR_OK:
1018 current = GST_PAD (padptr);
1020 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
1021 GST_DEBUG_PAD_NAME (current));
1023 peer = gst_pad_get_peer (current);
1025 if (peer == NULL && gst_pad_check_link (pad, current)) {
1026 GstCaps *temp, *temp2, *intersection;
1028 /* Now check if the two pads' caps are compatible */
1029 temp = gst_pad_get_caps (pad);
1031 intersection = gst_caps_intersect (temp, caps);
1032 gst_caps_unref (temp);
1034 intersection = temp;
1037 temp = gst_pad_get_caps (current);
1038 temp2 = gst_caps_intersect (temp, intersection);
1039 gst_caps_unref (temp);
1040 gst_caps_unref (intersection);
1042 intersection = temp2;
1044 if (!gst_caps_is_empty (intersection)) {
1045 gst_caps_unref (intersection);
1047 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1048 "found existing unlinked compatible pad %s:%s",
1049 GST_DEBUG_PAD_NAME (current));
1050 gst_iterator_free (pads);
1054 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "incompatible pads");
1056 gst_caps_unref (intersection);
1058 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1059 "already linked or cannot be linked (peer = %p)", peer);
1061 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
1063 gst_object_unref (current);
1065 gst_object_unref (peer);
1068 case GST_ITERATOR_DONE:
1071 case GST_ITERATOR_RESYNC:
1072 gst_iterator_resync (pads);
1074 case GST_ITERATOR_ERROR:
1075 g_assert_not_reached ();
1079 gst_iterator_free (pads);
1081 GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element,
1082 "Could not find a compatible unlinked always pad to link to %s:%s, now checking request pads",
1083 GST_DEBUG_PAD_NAME (pad));
1085 /* try to create a new one */
1086 /* requesting is a little crazy, we need a template. Let's create one */
1087 /* FIXME: why not gst_pad_get_pad_template (pad); */
1088 templcaps = gst_pad_get_caps (pad);
1090 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
1091 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
1093 /* FIXME : Because of a bug in gst_pad_template_new() by which is does not
1094 * properly steal the refcount of the given caps, we have to unref these caps
1095 * REVERT THIS WHEN FIXED !*/
1096 gst_caps_unref (templcaps);
1098 foundpad = gst_element_request_compatible_pad (element, templ);
1099 gst_object_unref (templ);
1102 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1103 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
1107 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
1108 "Could not find a compatible pad to link to %s:%s",
1109 GST_DEBUG_PAD_NAME (pad));
1114 * gst_element_state_get_name:
1115 * @state: a #GstState to get the name of.
1117 * Gets a string representing the given state.
1119 * Returns: a string with the name of the state.
1121 G_CONST_RETURN gchar *
1122 gst_element_state_get_name (GstState state)
1125 #ifdef GST_DEBUG_COLOR
1126 case GST_STATE_VOID_PENDING:
1127 return "VOID_PENDING";
1128 case GST_STATE_NULL:
1129 return "\033[01;34mNULL\033[00m";
1130 case GST_STATE_READY:
1131 return "\033[01;31mREADY\033[00m";
1132 case GST_STATE_PLAYING:
1133 return "\033[01;32mPLAYING\033[00m";
1134 case GST_STATE_PAUSED:
1135 return "\033[01;33mPAUSED\033[00m";
1137 /* This is a memory leak */
1138 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
1140 case GST_STATE_VOID_PENDING:
1141 return "VOID_PENDING";
1142 case GST_STATE_NULL:
1144 case GST_STATE_READY:
1146 case GST_STATE_PLAYING:
1148 case GST_STATE_PAUSED:
1151 /* This is a memory leak */
1152 return g_strdup_printf ("UNKNOWN!(%d)", state);
1158 * gst_element_state_change_return_get_name:
1159 * @state_ret: a #GstStateChangeReturn to get the name of.
1161 * Gets a string representing the given state change result.
1163 * Returns: a string with the name of the state change result.
1167 G_CONST_RETURN gchar *
1168 gst_element_state_change_return_get_name (GstStateChangeReturn state_ret)
1170 switch (state_ret) {
1171 #ifdef GST_DEBUG_COLOR
1172 case GST_STATE_CHANGE_FAILURE:
1173 return "\033[01;31mFAILURE\033[00m";
1174 case GST_STATE_CHANGE_SUCCESS:
1175 return "\033[01;32mSUCCESS\033[00m";
1176 case GST_STATE_CHANGE_ASYNC:
1177 return "\033[01;33mASYNC\033[00m";
1178 case GST_STATE_CHANGE_NO_PREROLL:
1179 return "\033[01;34mNO_PREROLL\033[00m";
1181 /* This is a memory leak */
1182 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state_ret);
1184 case GST_STATE_CHANGE_FAILURE:
1186 case GST_STATE_CHANGE_SUCCESS:
1188 case GST_STATE_CHANGE_ASYNC:
1190 case GST_STATE_CHANGE_NO_PREROLL:
1191 return "NO PREROLL";
1193 /* This is a memory leak */
1194 return g_strdup_printf ("UNKNOWN!(%d)", state_ret);
1201 * gst_element_factory_can_src_caps :
1202 * @factory: factory to query
1203 * @caps: the caps to check
1205 * Checks if the factory can source the given capability.
1207 * Returns: true if it can src the capabilities
1210 gst_element_factory_can_src_caps (GstElementFactory * factory,
1211 const GstCaps * caps)
1215 g_return_val_if_fail (factory != NULL, FALSE);
1216 g_return_val_if_fail (caps != NULL, FALSE);
1218 templates = factory->staticpadtemplates;
1221 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1223 if (template->direction == GST_PAD_SRC) {
1224 if (gst_caps_is_always_compatible (gst_static_caps_get
1225 (&template->static_caps), caps))
1228 templates = g_list_next (templates);
1235 * gst_element_factory_can_sink_caps :
1236 * @factory: factory to query
1237 * @caps: the caps to check
1239 * Checks if the factory can sink the given capability.
1241 * Returns: true if it can sink the capabilities
1244 gst_element_factory_can_sink_caps (GstElementFactory * factory,
1245 const GstCaps * caps)
1249 g_return_val_if_fail (factory != NULL, FALSE);
1250 g_return_val_if_fail (caps != NULL, FALSE);
1252 templates = factory->staticpadtemplates;
1255 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1257 if (template->direction == GST_PAD_SINK) {
1258 if (gst_caps_is_always_compatible (caps,
1259 gst_static_caps_get (&template->static_caps)))
1262 templates = g_list_next (templates);
1269 /* if return val is true, *direct_child is a caller-owned ref on the direct
1270 * child of ancestor that is part of object's ancestry */
1272 object_has_ancestor (GstObject * object, GstObject * ancestor,
1273 GstObject ** direct_child)
1275 GstObject *child, *parent;
1278 *direct_child = NULL;
1280 child = gst_object_ref (object);
1281 parent = gst_object_get_parent (object);
1284 if (ancestor == parent) {
1286 *direct_child = child;
1288 gst_object_unref (child);
1289 gst_object_unref (parent);
1293 gst_object_unref (child);
1295 parent = gst_object_get_parent (parent);
1298 gst_object_unref (child);
1303 /* caller owns return */
1305 find_common_root (GstObject * o1, GstObject * o2)
1307 GstObject *top = o1;
1308 GstObject *kid1, *kid2;
1309 GstObject *root = NULL;
1311 while (GST_OBJECT_PARENT (top))
1312 top = GST_OBJECT_PARENT (top);
1314 /* the itsy-bitsy spider... */
1316 if (!object_has_ancestor (o2, top, &kid2))
1319 root = gst_object_ref (top);
1321 if (!object_has_ancestor (o1, kid2, &kid1)) {
1322 gst_object_unref (kid2);
1326 if (!object_has_ancestor (o2, kid1, &kid2)) {
1327 gst_object_unref (kid1);
1334 /* caller does not own return */
1336 ghost_up (GstElement * e, GstPad * pad)
1338 static gint ghost_pad_index = 0;
1341 GstObject *parent = GST_OBJECT_PARENT (e);
1343 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
1344 gpad = gst_ghost_pad_new (name, pad);
1347 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
1348 g_warning ("Pad named %s already exists in element %s\n",
1349 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
1350 gst_object_unref ((GstObject *) gpad);
1358 remove_pad (gpointer ppad, gpointer unused)
1362 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
1363 g_warning ("Couldn't remove pad %s from element %s",
1364 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
1368 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
1369 GSList ** pads_created)
1373 GSList *pads_created_local = NULL;
1375 g_assert (pads_created);
1377 e1 = GST_OBJECT_PARENT (*src);
1378 e2 = GST_OBJECT_PARENT (*sink);
1380 if (G_UNLIKELY (e1 == NULL)) {
1381 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1382 GST_PTR_FORMAT, *src);
1385 if (G_UNLIKELY (e2 == NULL)) {
1386 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1387 GST_PTR_FORMAT, *sink);
1391 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
1392 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
1393 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1397 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
1398 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1400 /* we need to setup some ghost pads */
1401 root = find_common_root (e1, e2);
1403 g_warning ("Trying to connect elements that don't share a common "
1404 "ancestor: %s and %s", GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
1408 while (GST_OBJECT_PARENT (e1) != root) {
1409 *src = ghost_up ((GstElement *) e1, *src);
1412 e1 = GST_OBJECT_PARENT (*src);
1413 pads_created_local = g_slist_prepend (pads_created_local, *src);
1415 while (GST_OBJECT_PARENT (e2) != root) {
1416 *sink = ghost_up ((GstElement *) e2, *sink);
1419 e2 = GST_OBJECT_PARENT (*sink);
1420 pads_created_local = g_slist_prepend (pads_created_local, *sink);
1423 gst_object_unref (root);
1424 *pads_created = g_slist_concat (*pads_created, pads_created_local);
1428 gst_object_unref (root);
1429 g_slist_foreach (pads_created_local, remove_pad, NULL);
1430 g_slist_free (pads_created_local);
1435 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1437 GSList *pads_created = NULL;
1440 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1443 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1447 g_slist_foreach (pads_created, remove_pad, NULL);
1449 g_slist_free (pads_created);
1455 * gst_element_link_pads:
1456 * @src: a #GstElement containing the source pad.
1457 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1458 * @dest: the #GstElement containing the destination pad.
1459 * @destpadname: the name of the #GstPad in destination element,
1460 * or NULL for any pad.
1462 * Links the two named pads of the source and destination elements.
1463 * Side effect is that if one of the pads has no parent, it becomes a
1464 * child of the parent of the other element. If they have different
1465 * parents, the link fails.
1467 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1470 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1471 GstElement * dest, const gchar * destpadname)
1473 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1474 GstPad *srcpad, *destpad;
1475 GstPadTemplate *srctempl, *desttempl;
1476 GstElementClass *srcclass, *destclass;
1479 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1480 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1482 srcclass = GST_ELEMENT_GET_CLASS (src);
1483 destclass = GST_ELEMENT_GET_CLASS (dest);
1485 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1486 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1487 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1488 destpadname ? destpadname : "(any)");
1492 /* name specified, look it up */
1493 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1494 srcpad = gst_element_get_request_pad (src, srcpadname);
1496 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1497 GST_ELEMENT_NAME (src), srcpadname);
1500 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1501 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1502 GST_DEBUG_PAD_NAME (srcpad));
1503 gst_object_unref (srcpad);
1506 if (GST_PAD_PEER (srcpad) != NULL) {
1507 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1508 GST_DEBUG_PAD_NAME (srcpad));
1509 gst_object_unref (srcpad);
1515 /* no name given, get the first available pad */
1516 GST_OBJECT_LOCK (src);
1517 srcpads = GST_ELEMENT_PADS (src);
1518 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1520 gst_object_ref (srcpad);
1521 GST_OBJECT_UNLOCK (src);
1524 /* get a destination pad */
1526 /* name specified, look it up */
1527 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1528 destpad = gst_element_get_request_pad (dest, destpadname);
1530 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1531 GST_ELEMENT_NAME (dest), destpadname);
1534 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1535 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1536 GST_DEBUG_PAD_NAME (destpad));
1537 gst_object_unref (destpad);
1540 if (GST_PAD_PEER (destpad) != NULL) {
1541 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1542 GST_DEBUG_PAD_NAME (destpad));
1543 gst_object_unref (destpad);
1549 /* no name given, get the first available pad */
1550 GST_OBJECT_LOCK (dest);
1551 destpads = GST_ELEMENT_PADS (dest);
1552 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1554 gst_object_ref (destpad);
1555 GST_OBJECT_UNLOCK (dest);
1558 if (srcpadname && destpadname) {
1561 /* two explicitly specified pads */
1562 result = pad_link_maybe_ghosting (srcpad, destpad);
1564 gst_object_unref (srcpad);
1565 gst_object_unref (destpad);
1571 /* loop through the allowed pads in the source, trying to find a
1572 * compatible destination pad */
1573 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1574 "looping through allowed src and dest pads");
1576 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1577 GST_DEBUG_PAD_NAME (srcpad));
1578 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1579 (GST_PAD_PEER (srcpad) == NULL)) {
1584 gst_object_ref (temp);
1586 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1589 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1590 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1591 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1593 gst_object_unref (destpad);
1594 gst_object_unref (srcpad);
1595 gst_object_unref (temp);
1600 gst_object_unref (temp);
1603 /* find a better way for this mess */
1605 srcpads = g_list_next (srcpads);
1607 gst_object_unref (srcpad);
1608 srcpad = GST_PAD_CAST (srcpads->data);
1609 gst_object_ref (srcpad);
1615 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1616 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1618 gst_object_unref (destpad);
1622 gst_object_unref (srcpad);
1626 /* loop through the existing pads in the destination */
1628 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1629 GST_DEBUG_PAD_NAME (destpad));
1630 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1631 (GST_PAD_PEER (destpad) == NULL)) {
1632 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1634 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1635 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1636 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1637 gst_object_unref (temp);
1638 gst_object_unref (destpad);
1642 gst_object_unref (temp);
1646 destpads = g_list_next (destpads);
1648 gst_object_unref (destpad);
1649 destpad = GST_PAD_CAST (destpads->data);
1650 gst_object_ref (destpad);
1657 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1658 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1659 gst_object_unref (destpad);
1663 gst_object_unref (destpad);
1667 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1668 "we might have request pads on both sides, checking...");
1669 srctempls = gst_element_class_get_pad_template_list (srcclass);
1670 desttempls = gst_element_class_get_pad_template_list (destclass);
1672 if (srctempls && desttempls) {
1674 srctempl = (GstPadTemplate *) srctempls->data;
1675 if (srctempl->presence == GST_PAD_REQUEST) {
1676 for (l = desttempls; l; l = l->next) {
1677 desttempl = (GstPadTemplate *) l->data;
1678 if (desttempl->presence == GST_PAD_REQUEST &&
1679 desttempl->direction != srctempl->direction) {
1680 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1681 (srctempl), gst_pad_template_get_caps (desttempl))) {
1683 gst_element_get_request_pad (src, srctempl->name_template);
1685 gst_element_get_request_pad (dest, desttempl->name_template);
1686 if (srcpad && destpad
1687 && pad_link_maybe_ghosting (srcpad, destpad)) {
1688 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1689 "linked pad %s:%s to pad %s:%s",
1690 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1691 gst_object_unref (srcpad);
1692 gst_object_unref (destpad);
1695 /* it failed, so we release the request pads */
1697 gst_element_release_request_pad (src, srcpad);
1699 gst_element_release_request_pad (dest, destpad);
1704 srctempls = srctempls->next;
1708 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1709 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1714 * gst_element_link_pads_filtered:
1715 * @src: a #GstElement containing the source pad.
1716 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1717 * @dest: the #GstElement containing the destination pad.
1718 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1719 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1721 * Links the two named pads of the source and destination elements. Side effect
1722 * is that if one of the pads has no parent, it becomes a child of the parent of
1723 * the other element. If they have different parents, the link fails. If @caps
1724 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1726 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1729 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1730 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1733 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1734 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1735 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1738 GstElement *capsfilter;
1740 GstState state, pending;
1742 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1744 GST_ERROR ("Could not make a capsfilter");
1748 parent = gst_object_get_parent (GST_OBJECT (src));
1749 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1751 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, 0);
1753 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1754 GST_ERROR ("Could not add capsfilter");
1755 gst_object_unref (capsfilter);
1756 gst_object_unref (parent);
1760 if (pending != GST_STATE_VOID_PENDING)
1763 gst_element_set_state (capsfilter, state);
1765 gst_object_unref (parent);
1767 g_object_set (capsfilter, "caps", filter, NULL);
1769 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1770 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1773 GST_INFO ("Could not link elements");
1774 gst_element_set_state (capsfilter, GST_STATE_NULL);
1775 /* this will unlink and unref as appropriate */
1776 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1780 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1786 * @src: a #GstElement containing the source pad.
1787 * @dest: the #GstElement containing the destination pad.
1789 * Links @src to @dest. The link must be from source to
1790 * destination; the other direction will not be tried. The function looks for
1791 * existing pads that aren't linked yet. It will request new pads if necessary.
1792 * Such pads need to be released manualy when unlinking.
1793 * If multiple links are possible, only one is established.
1795 * Make sure you have added your elements to a bin or pipeline with
1796 * gst_bin_add() before trying to link them.
1798 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1801 gst_element_link (GstElement * src, GstElement * dest)
1803 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1807 * gst_element_link_many:
1808 * @element_1: the first #GstElement in the link chain.
1809 * @element_2: the second #GstElement in the link chain.
1810 * @...: the NULL-terminated list of elements to link in order.
1812 * Chain together a series of elements. Uses gst_element_link().
1813 * Make sure you have added your elements to a bin or pipeline with
1814 * gst_bin_add() before trying to link them.
1816 * Returns: TRUE on success, FALSE otherwise.
1819 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1821 gboolean res = TRUE;
1824 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1825 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1827 va_start (args, element_2);
1830 if (!gst_element_link (element_1, element_2)) {
1835 element_1 = element_2;
1836 element_2 = va_arg (args, GstElement *);
1845 * gst_element_link_filtered:
1846 * @src: a #GstElement containing the source pad.
1847 * @dest: the #GstElement containing the destination pad.
1848 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1850 * Links @src to @dest using the given caps as filtercaps.
1851 * The link must be from source to
1852 * destination; the other direction will not be tried. The function looks for
1853 * existing pads that aren't linked yet. It will request new pads if necessary.
1854 * If multiple links are possible, only one is established.
1856 * Make sure you have added your elements to a bin or pipeline with
1857 * gst_bin_add() before trying to link them.
1859 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1862 gst_element_link_filtered (GstElement * src, GstElement * dest,
1865 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1869 * gst_element_unlink_pads:
1870 * @src: a #GstElement containing the source pad.
1871 * @srcpadname: the name of the #GstPad in source element.
1872 * @dest: a #GstElement containing the destination pad.
1873 * @destpadname: the name of the #GstPad in destination element.
1875 * Unlinks the two named pads of the source and destination elements.
1878 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1879 GstElement * dest, const gchar * destpadname)
1881 GstPad *srcpad, *destpad;
1882 gboolean srcrequest, destrequest;
1884 srcrequest = destrequest = FALSE;
1886 g_return_if_fail (src != NULL);
1887 g_return_if_fail (GST_IS_ELEMENT (src));
1888 g_return_if_fail (srcpadname != NULL);
1889 g_return_if_fail (dest != NULL);
1890 g_return_if_fail (GST_IS_ELEMENT (dest));
1891 g_return_if_fail (destpadname != NULL);
1893 /* obtain the pads requested */
1894 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1895 if ((srcpad = gst_element_get_request_pad (src, srcpadname)))
1897 if (srcpad == NULL) {
1898 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1901 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1902 if ((destpad = gst_element_get_request_pad (dest, destpadname)))
1904 if (destpad == NULL) {
1905 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1910 /* we're satisified they can be unlinked, let's do it */
1911 gst_pad_unlink (srcpad, destpad);
1914 gst_element_release_request_pad (dest, destpad);
1915 gst_object_unref (destpad);
1919 gst_element_release_request_pad (src, srcpad);
1920 gst_object_unref (srcpad);
1924 * gst_element_unlink_many:
1925 * @element_1: the first #GstElement in the link chain.
1926 * @element_2: the second #GstElement in the link chain.
1927 * @...: the NULL-terminated list of elements to unlink in order.
1929 * Unlinks a series of elements. Uses gst_element_unlink().
1932 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1936 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1937 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1939 va_start (args, element_2);
1942 gst_element_unlink (element_1, element_2);
1944 element_1 = element_2;
1945 element_2 = va_arg (args, GstElement *);
1952 * gst_element_unlink:
1953 * @src: the source #GstElement to unlink.
1954 * @dest: the sink #GstElement to unlink.
1956 * Unlinks all source pads of the source element with all sink pads
1957 * of the sink element to which they are linked.
1959 * If the link has been made using gst_element_link(), it could have created an
1960 * requestpad, which has to be released using gst_element_release_request_pad().
1963 gst_element_unlink (GstElement * src, GstElement * dest)
1966 gboolean done = FALSE;
1968 g_return_if_fail (GST_IS_ELEMENT (src));
1969 g_return_if_fail (GST_IS_ELEMENT (dest));
1971 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1972 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1974 pads = gst_element_iterate_pads (src);
1978 switch (gst_iterator_next (pads, &data)) {
1979 case GST_ITERATOR_OK:
1981 GstPad *pad = GST_PAD_CAST (data);
1983 if (GST_PAD_IS_SRC (pad)) {
1984 GstPad *peerpad = gst_pad_get_peer (pad);
1986 /* see if the pad is linked and is really a pad of dest */
1988 GstElement *peerelem;
1990 peerelem = gst_pad_get_parent_element (peerpad);
1992 if (peerelem == dest) {
1993 gst_pad_unlink (pad, peerpad);
1996 gst_object_unref (peerelem);
1998 gst_object_unref (peerpad);
2001 gst_object_unref (pad);
2004 case GST_ITERATOR_RESYNC:
2005 gst_iterator_resync (pads);
2007 case GST_ITERATOR_DONE:
2011 g_assert_not_reached ();
2015 gst_iterator_free (pads);
2019 * gst_element_query_position:
2020 * @element: a #GstElement to invoke the position query on.
2021 * @format: a pointer to the #GstFormat asked for.
2022 * On return contains the #GstFormat used.
2023 * @cur: A location in which to store the current position, or NULL.
2025 * Queries an element for the stream position.
2027 * Returns: TRUE if the query could be performed.
2030 gst_element_query_position (GstElement * element, GstFormat * format,
2036 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2037 g_return_val_if_fail (format != NULL, FALSE);
2039 query = gst_query_new_position (*format);
2040 ret = gst_element_query (element, query);
2043 gst_query_parse_position (query, format, cur);
2045 gst_query_unref (query);
2051 * gst_element_query_duration:
2052 * @element: a #GstElement to invoke the duration query on.
2053 * @format: a pointer to the #GstFormat asked for.
2054 * On return contains the #GstFormat used.
2055 * @duration: A location in which to store the total duration, or NULL.
2057 * Queries an element for the total stream duration.
2059 * Returns: TRUE if the query could be performed.
2062 gst_element_query_duration (GstElement * element, GstFormat * format,
2068 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2069 g_return_val_if_fail (format != NULL, FALSE);
2071 query = gst_query_new_duration (*format);
2072 ret = gst_element_query (element, query);
2075 gst_query_parse_duration (query, format, duration);
2077 gst_query_unref (query);
2083 * gst_element_query_convert:
2084 * @element: a #GstElement to invoke the convert query on.
2085 * @src_format: a #GstFormat to convert from.
2086 * @src_val: a value to convert.
2087 * @dest_format: a pointer to the #GstFormat to convert to.
2088 * @dest_val: a pointer to the result.
2090 * Queries an element to convert @src_val in @src_format to @dest_format.
2092 * Returns: TRUE if the query could be performed.
2095 gst_element_query_convert (GstElement * element, GstFormat src_format,
2096 gint64 src_val, GstFormat * dest_format, gint64 * dest_val)
2101 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2102 g_return_val_if_fail (dest_format != NULL, FALSE);
2103 g_return_val_if_fail (dest_val != NULL, FALSE);
2105 if (*dest_format == src_format) {
2106 *dest_val = src_val;
2110 query = gst_query_new_convert (src_format, src_val, *dest_format);
2111 ret = gst_element_query (element, query);
2114 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2116 gst_query_unref (query);
2122 * gst_element_seek_simple
2123 * @element: a #GstElement to seek on
2124 * @format: a #GstFormat to execute the seek in, such as #GST_FORMAT_TIME
2125 * @seek_flags: seek options; playback applications will usually want to use
2126 * GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here
2127 * @seek_pos: position to seek to (relative to the start); if you are doing
2128 * a seek in #GST_FORMAT_TIME this value is in nanoseconds -
2129 * multiply with #GST_SECOND to convert seconds to nanoseconds or
2130 * with #GST_MSECOND to convert milliseconds to nanoseconds.
2132 * Simple API to perform a seek on the given element, meaning it just seeks
2133 * to the given position relative to the start of the stream. For more complex
2134 * operations like segment seeks (e.g. for looping) or changing the playback
2135 * rate or seeking relative to the last configured playback segment you should
2136 * use gst_element_seek().
2138 * In a completely prerolled PAUSED or PLAYING pipeline, seeking is always
2139 * guaranteed to return %TRUE on a seekable media type or %FALSE when the media
2140 * type is certainly not seekable (such as a live stream).
2142 * Some elements allow for seeking in the READY state, in this
2143 * case they will store the seek event and execute it when they are put to
2144 * PAUSED. If the element supports seek in READY, it will always return %TRUE when
2145 * it receives the event in the READY state.
2147 * Returns: %TRUE if the seek operation succeeded (the seek might not always be
2148 * executed instantly though)
2153 gst_element_seek_simple (GstElement * element, GstFormat format,
2154 GstSeekFlags seek_flags, gint64 seek_pos)
2156 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2157 g_return_val_if_fail (seek_pos >= 0, FALSE);
2159 return gst_element_seek (element, 1.0, format, seek_flags,
2160 GST_SEEK_TYPE_SET, seek_pos, GST_SEEK_TYPE_NONE, 0);
2164 * gst_pad_use_fixed_caps:
2165 * @pad: the pad to use
2167 * A helper function you can use that sets the
2168 * @gst_pad_get_fixed_caps_func as the getcaps function for the
2169 * pad. This way the function will always return the negotiated caps
2170 * or in case the pad is not negotiated, the padtemplate caps.
2172 * Use this function on a pad that, once _set_caps() has been called
2173 * on it, cannot be renegotiated to something else.
2176 gst_pad_use_fixed_caps (GstPad * pad)
2178 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
2182 * gst_pad_get_fixed_caps_func:
2183 * @pad: the pad to use
2185 * A helper function you can use as a GetCaps function that
2186 * will return the currently negotiated caps or the padtemplate
2189 * Returns: The currently negotiated caps or the padtemplate.
2192 gst_pad_get_fixed_caps_func (GstPad * pad)
2196 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2198 GST_OBJECT_LOCK (pad);
2199 if (GST_PAD_CAPS (pad)) {
2200 result = GST_PAD_CAPS (pad);
2202 GST_CAT_DEBUG (GST_CAT_CAPS,
2203 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2205 result = gst_caps_ref (result);
2206 } else if (GST_PAD_PAD_TEMPLATE (pad)) {
2207 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
2209 result = GST_PAD_TEMPLATE_CAPS (templ);
2210 GST_CAT_DEBUG (GST_CAT_CAPS,
2211 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2214 result = gst_caps_ref (result);
2216 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2217 result = gst_caps_new_empty ();
2219 GST_OBJECT_UNLOCK (pad);
2225 * gst_pad_get_parent_element:
2228 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
2229 * its parent is not an element, return NULL.
2231 * Returns: The parent of the pad. The caller has a reference on the parent, so
2232 * unref when you're finished with it.
2237 gst_pad_get_parent_element (GstPad * pad)
2241 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2243 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
2245 if (p && !GST_IS_ELEMENT (p)) {
2246 gst_object_unref (p);
2249 return GST_ELEMENT_CAST (p);
2253 * gst_object_default_error:
2254 * @source: the #GstObject that initiated the error.
2255 * @error: the GError.
2256 * @debug: an additional debug information string, or NULL.
2258 * A default error function.
2260 * The default handler will simply print the error string using g_print.
2263 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
2265 gchar *name = gst_object_get_path_string (source);
2267 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
2269 g_print (_("Additional debug info:\n%s\n"), debug);
2277 * @element_1: the #GstElement element to add to the bin
2278 * @...: additional elements to add to the bin
2280 * Adds a NULL-terminated list of elements to a bin. This function is
2281 * equivalent to calling gst_bin_add() for each member of the list. The return
2282 * value of each gst_bin_add() is ignored.
2285 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
2289 g_return_if_fail (GST_IS_BIN (bin));
2290 g_return_if_fail (GST_IS_ELEMENT (element_1));
2292 va_start (args, element_1);
2295 gst_bin_add (bin, element_1);
2297 element_1 = va_arg (args, GstElement *);
2304 * gst_bin_remove_many:
2306 * @element_1: the first #GstElement to remove from the bin
2307 * @...: NULL-terminated list of elements to remove from the bin
2309 * Remove a list of elements from a bin. This function is equivalent
2310 * to calling gst_bin_remove() with each member of the list.
2313 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
2317 g_return_if_fail (GST_IS_BIN (bin));
2318 g_return_if_fail (GST_IS_ELEMENT (element_1));
2320 va_start (args, element_1);
2323 gst_bin_remove (bin, element_1);
2325 element_1 = va_arg (args, GstElement *);
2332 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2333 guint arg_id, GParamFlags flags)
2335 GQuark prop_id = g_quark_from_string (prop_name);
2338 static GQuark fd_id = 0;
2339 static GQuark blocksize_id;
2340 static GQuark bytesperread_id;
2341 static GQuark dump_id;
2342 static GQuark filesize_id;
2343 static GQuark mmapsize_id;
2344 static GQuark location_id;
2345 static GQuark offset_id;
2346 static GQuark silent_id;
2347 static GQuark touch_id;
2350 fd_id = g_quark_from_static_string ("fd");
2351 blocksize_id = g_quark_from_static_string ("blocksize");
2352 bytesperread_id = g_quark_from_static_string ("bytesperread");
2353 dump_id = g_quark_from_static_string ("dump");
2354 filesize_id = g_quark_from_static_string ("filesize");
2355 mmapsize_id = g_quark_from_static_string ("mmapsize");
2356 location_id = g_quark_from_static_string ("location");
2357 offset_id = g_quark_from_static_string ("offset");
2358 silent_id = g_quark_from_static_string ("silent");
2359 touch_id = g_quark_from_static_string ("touch");
2362 if (prop_id == fd_id) {
2363 pspec = g_param_spec_int ("fd", "File-descriptor",
2364 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2365 } else if (prop_id == blocksize_id) {
2366 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2367 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2369 } else if (prop_id == bytesperread_id) {
2370 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2371 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2373 } else if (prop_id == dump_id) {
2374 pspec = g_param_spec_boolean ("dump", "Dump",
2375 "Dump bytes to stdout", FALSE, flags);
2377 } else if (prop_id == filesize_id) {
2378 pspec = g_param_spec_int64 ("filesize", "File Size",
2379 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2381 } else if (prop_id == mmapsize_id) {
2382 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2383 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2385 } else if (prop_id == location_id) {
2386 pspec = g_param_spec_string ("location", "File Location",
2387 "Location of the file to read", NULL, flags);
2389 } else if (prop_id == offset_id) {
2390 pspec = g_param_spec_int64 ("offset", "File Offset",
2391 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2393 } else if (prop_id == silent_id) {
2394 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2397 } else if (prop_id == touch_id) {
2398 pspec = g_param_spec_boolean ("touch", "Touch read data",
2399 "Touch data to force disk read before " "push ()", TRUE, flags);
2401 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2402 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2407 g_object_class_install_property (klass, arg_id, pspec);
2412 * gst_element_class_install_std_props:
2413 * @klass: the #GstElementClass to add the properties to.
2414 * @first_name: the name of the first property.
2415 * in a NULL terminated
2416 * @...: the id and flags of the first property, followed by
2417 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2419 * Adds a list of standardized properties with types to the @klass.
2420 * the id is for the property switch in your get_prop method, and
2421 * the flags determine readability / writeability.
2424 gst_element_class_install_std_props (GstElementClass * klass,
2425 const gchar * first_name, ...)
2431 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2433 va_start (args, first_name);
2438 int arg_id = va_arg (args, int);
2439 int flags = va_arg (args, int);
2441 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2444 name = va_arg (args, char *);
2453 * @buf1: the first source #GstBuffer to merge.
2454 * @buf2: the second source #GstBuffer to merge.
2456 * Create a new buffer that is the concatenation of the two source
2457 * buffers. The original source buffers will not be modified or
2458 * unref'd. Make sure you unref the source buffers if they are not used
2459 * anymore afterwards.
2461 * If the buffers point to contiguous areas of memory, the buffer
2462 * is created without copying the data.
2464 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2467 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2471 /* we're just a specific case of the more general gst_buffer_span() */
2472 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2479 * @buf1: the first source #GstBuffer.
2480 * @buf2: the second source #GstBuffer.
2482 * Create a new buffer that is the concatenation of the two source
2483 * buffers, and unrefs the original source buffers.
2485 * If the buffers point to contiguous areas of memory, the buffer
2486 * is created without copying the data.
2488 * This is a convenience function for C programmers. See also
2489 * gst_buffer_merge(), which does the same thing without
2490 * unreffing the input parameters. Language bindings without
2491 * explicit reference counting should not wrap this function.
2493 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2496 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2500 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2501 gst_buffer_unref (buf1);
2502 gst_buffer_unref (buf2);
2510 * @dest: buffer to stamp
2511 * @src: buffer to stamp from
2513 * Copies additional information (the timestamp, duration, and offset start
2514 * and end) from one buffer to the other.
2516 * This function does not copy any buffer flags or caps and is equivalent to
2517 * gst_buffer_copy_metadata(@dest, @src, GST_BUFFER_COPY_TIMESTAMPS).
2519 * Deprecated: use gst_buffer_copy_metadata() instead, it provides more
2522 #ifndef GST_REMOVE_DEPRECATED
2524 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2526 gst_buffer_copy_metadata (dest, src, GST_BUFFER_COPY_TIMESTAMPS);
2528 #endif /* GST_REMOVE_DEPRECATED */
2531 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2533 /* skip the pad, the request came from */
2535 GstCaps *peercaps, *existing;
2537 existing = g_value_get_pointer (ret);
2538 peercaps = gst_pad_peer_get_caps (pad);
2539 if (peercaps == NULL)
2540 peercaps = gst_caps_new_any ();
2541 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2542 gst_caps_unref (existing);
2543 gst_caps_unref (peercaps);
2545 gst_object_unref (pad);
2550 * gst_pad_proxy_getcaps:
2551 * @pad: a #GstPad to proxy.
2553 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2554 * same element as @pad, and returns the intersection of the results.
2556 * This function is useful as a default getcaps function for an element
2557 * that can handle any stream format, but requires all its pads to have
2558 * the same caps. Two such elements are tee and aggregator.
2560 * Returns: the intersection of the other pads' allowed caps.
2563 gst_pad_proxy_getcaps (GstPad * pad)
2565 GstElement *element;
2566 GstCaps *caps, *intersected;
2568 GstIteratorResult res;
2569 GValue ret = { 0, };
2571 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2573 GST_CAT_DEBUG (GST_CAT_PADS, "proxying getcaps for %s:%s",
2574 GST_DEBUG_PAD_NAME (pad));
2576 element = gst_pad_get_parent_element (pad);
2577 if (element == NULL)
2580 /* value to hold the return, by default it holds ANY, the ref is taken by
2582 g_value_init (&ret, G_TYPE_POINTER);
2583 g_value_set_pointer (&ret, gst_caps_new_any ());
2585 iter = gst_element_iterate_pads (element);
2588 gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2591 case GST_ITERATOR_RESYNC:
2592 /* unref any value stored */
2593 if ((caps = g_value_get_pointer (&ret)))
2594 gst_caps_unref (caps);
2595 /* need to reset the result again to ANY */
2596 g_value_set_pointer (&ret, gst_caps_new_any ());
2597 gst_iterator_resync (iter);
2599 case GST_ITERATOR_DONE:
2600 /* all pads iterated, return collected value */
2603 /* iterator returned _ERROR or premature end with _OK,
2604 * mark an error and exit */
2605 if ((caps = g_value_get_pointer (&ret)))
2606 gst_caps_unref (caps);
2607 g_value_set_pointer (&ret, NULL);
2612 gst_iterator_free (iter);
2614 gst_object_unref (element);
2616 caps = g_value_get_pointer (&ret);
2617 g_value_unset (&ret);
2619 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2620 gst_caps_unref (caps);
2627 g_warning ("Pad list returned error on element %s",
2628 GST_ELEMENT_NAME (element));
2629 gst_iterator_free (iter);
2630 gst_object_unref (element);
2642 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2644 gboolean success = TRUE;
2646 if (pad != data->orig) {
2647 success = gst_pad_set_caps (pad, data->caps);
2648 g_value_set_boolean (ret, success);
2650 gst_object_unref (pad);
2656 * gst_pad_proxy_setcaps
2657 * @pad: a #GstPad to proxy from
2658 * @caps: the #GstCaps to link with
2660 * Calls gst_pad_set_caps() for every other pad belonging to the
2661 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2662 * the proxy setcaps fails. May be used only during negotiation.
2664 * Returns: TRUE if sucessful
2667 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2669 GstElement *element;
2671 GstIteratorResult res;
2672 GValue ret = { 0, };
2675 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2676 g_return_val_if_fail (caps != NULL, FALSE);
2678 GST_CAT_DEBUG (GST_CAT_PADS, "proxying pad link for %s:%s",
2679 GST_DEBUG_PAD_NAME (pad));
2681 element = gst_pad_get_parent_element (pad);
2682 if (element == NULL)
2685 iter = gst_element_iterate_pads (element);
2687 g_value_init (&ret, G_TYPE_BOOLEAN);
2688 g_value_set_boolean (&ret, TRUE);
2692 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2694 gst_iterator_free (iter);
2696 if (res != GST_ITERATOR_DONE)
2699 gst_object_unref (element);
2701 /* ok not to unset the gvalue */
2702 return g_value_get_boolean (&ret);
2707 g_warning ("Pad list changed during proxy_pad_link for element %s",
2708 GST_ELEMENT_NAME (element));
2709 gst_object_unref (element);
2715 * gst_pad_query_position:
2716 * @pad: a #GstPad to invoke the position query on.
2717 * @format: a pointer to the #GstFormat asked for.
2718 * On return contains the #GstFormat used.
2719 * @cur: A location in which to store the current position, or NULL.
2721 * Queries a pad for the stream position.
2723 * Returns: TRUE if the query could be performed.
2726 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur)
2731 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2732 g_return_val_if_fail (format != NULL, FALSE);
2734 query = gst_query_new_position (*format);
2735 ret = gst_pad_query (pad, query);
2738 gst_query_parse_position (query, format, cur);
2740 gst_query_unref (query);
2746 * gst_pad_query_peer_position:
2747 * @pad: a #GstPad on whose peer to invoke the position query on.
2748 * Must be a sink pad.
2749 * @format: a pointer to the #GstFormat asked for.
2750 * On return contains the #GstFormat used.
2751 * @cur: A location in which to store the current position, or NULL.
2753 * Queries the peer of a given sink pad for the stream position.
2755 * Returns: TRUE if the query could be performed.
2758 gst_pad_query_peer_position (GstPad * pad, GstFormat * format, gint64 * cur)
2760 gboolean ret = FALSE;
2763 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2764 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2765 g_return_val_if_fail (format != NULL, FALSE);
2767 peer = gst_pad_get_peer (pad);
2769 ret = gst_pad_query_position (peer, format, cur);
2770 gst_object_unref (peer);
2777 * gst_pad_query_duration:
2778 * @pad: a #GstPad to invoke the duration query on.
2779 * @format: a pointer to the #GstFormat asked for.
2780 * On return contains the #GstFormat used.
2781 * @duration: A location in which to store the total duration, or NULL.
2783 * Queries a pad for the total stream duration.
2785 * Returns: TRUE if the query could be performed.
2788 gst_pad_query_duration (GstPad * pad, GstFormat * format, gint64 * duration)
2793 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2794 g_return_val_if_fail (format != NULL, FALSE);
2796 query = gst_query_new_duration (*format);
2797 ret = gst_pad_query (pad, query);
2800 gst_query_parse_duration (query, format, duration);
2802 gst_query_unref (query);
2808 * gst_pad_query_peer_duration:
2809 * @pad: a #GstPad on whose peer pad to invoke the duration query on.
2810 * Must be a sink pad.
2811 * @format: a pointer to the #GstFormat asked for.
2812 * On return contains the #GstFormat used.
2813 * @duration: A location in which to store the total duration, or NULL.
2815 * Queries the peer pad of a given sink pad for the total stream duration.
2817 * Returns: TRUE if the query could be performed.
2820 gst_pad_query_peer_duration (GstPad * pad, GstFormat * format,
2823 gboolean ret = FALSE;
2826 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2827 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2828 g_return_val_if_fail (format != NULL, FALSE);
2830 peer = gst_pad_get_peer (pad);
2832 ret = gst_pad_query_duration (peer, format, duration);
2833 gst_object_unref (peer);
2840 * gst_pad_query_convert:
2841 * @pad: a #GstPad to invoke the convert query on.
2842 * @src_format: a #GstFormat to convert from.
2843 * @src_val: a value to convert.
2844 * @dest_format: a pointer to the #GstFormat to convert to.
2845 * @dest_val: a pointer to the result.
2847 * Queries a pad to convert @src_val in @src_format to @dest_format.
2849 * Returns: TRUE if the query could be performed.
2852 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2853 GstFormat * dest_format, gint64 * dest_val)
2858 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2859 g_return_val_if_fail (dest_format != NULL, FALSE);
2860 g_return_val_if_fail (dest_val != NULL, FALSE);
2862 if (*dest_format == src_format) {
2863 *dest_val = src_val;
2867 query = gst_query_new_convert (src_format, src_val, *dest_format);
2868 ret = gst_pad_query (pad, query);
2871 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2873 gst_query_unref (query);
2879 * gst_pad_query_peer_convert:
2880 * @pad: a #GstPad, on whose peer pad to invoke the convert query on.
2881 * Must be a sink pad.
2882 * @src_format: a #GstFormat to convert from.
2883 * @src_val: a value to convert.
2884 * @dest_format: a pointer to the #GstFormat to convert to.
2885 * @dest_val: a pointer to the result.
2887 * Queries the peer pad of a given sink pad to convert @src_val in @src_format
2890 * Returns: TRUE if the query could be performed.
2893 gst_pad_query_peer_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2894 GstFormat * dest_format, gint64 * dest_val)
2896 gboolean ret = FALSE;
2899 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2900 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2901 g_return_val_if_fail (src_val >= 0, FALSE);
2902 g_return_val_if_fail (dest_format != NULL, FALSE);
2903 g_return_val_if_fail (dest_val != NULL, FALSE);
2905 peer = gst_pad_get_peer (pad);
2907 ret = gst_pad_query_convert (peer, src_format, src_val, dest_format,
2909 gst_object_unref (peer);
2916 * gst_atomic_int_set:
2917 * @atomic_int: pointer to an atomic integer
2918 * @value: value to set
2920 * Unconditionally sets the atomic integer to @value.
2922 * Deprecated: Use g_atomic_int_set().
2925 #ifndef GST_REMOVE_DEPRECATED
2927 gst_atomic_int_set (gint * atomic_int, gint value)
2929 g_atomic_int_set (atomic_int, value);
2934 * gst_pad_add_data_probe:
2935 * @pad: pad to add the data probe handler to
2936 * @handler: function to call when data is passed over pad
2937 * @data: data to pass along with the handler
2939 * Adds a "data probe" to a pad. This function will be called whenever data
2940 * passes through a pad. In this case data means both events and buffers. The
2941 * probe will be called with the data as an argument, meaning @handler should
2942 * have the same callback signature as the #GstPad::have-data signal.
2943 * Note that the data will have a reference count greater than 1, so it will
2944 * be immutable -- you must not change it.
2946 * For source pads, the probe will be called after the blocking function, if any
2947 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2948 * to. For sink pads, the probe function will be called before configuring the
2949 * sink with new caps, if any, and before calling the pad's chain function.
2951 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2952 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2955 * Although probes are implemented internally by connecting @handler to the
2956 * have-data signal on the pad, if you want to remove a probe it is insufficient
2957 * to only call g_signal_handler_disconnect on the returned handler id. To
2958 * remove a probe, use the appropriate function, such as
2959 * gst_pad_remove_data_probe().
2961 * Returns: The handler id.
2964 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2966 return gst_pad_add_data_probe_full (pad, handler, data, NULL);
2970 * gst_pad_add_data_probe_full:
2971 * @pad: pad to add the data probe handler to
2972 * @handler: function to call when data is passed over pad
2973 * @data: data to pass along with the handler
2974 * @notify: function to call when the probe is disconnected, or NULL
2976 * Adds a "data probe" to a pad. This function will be called whenever data
2977 * passes through a pad. In this case data means both events and buffers. The
2978 * probe will be called with the data as an argument, meaning @handler should
2979 * have the same callback signature as the #GstPad::have-data signal.
2980 * Note that the data will have a reference count greater than 1, so it will
2981 * be immutable -- you must not change it.
2983 * For source pads, the probe will be called after the blocking function, if any
2984 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2985 * to. For sink pads, the probe function will be called before configuring the
2986 * sink with new caps, if any, and before calling the pad's chain function.
2988 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2989 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2992 * Although probes are implemented internally by connecting @handler to the
2993 * have-data signal on the pad, if you want to remove a probe it is insufficient
2994 * to only call g_signal_handler_disconnect on the returned handler id. To
2995 * remove a probe, use the appropriate function, such as
2996 * gst_pad_remove_data_probe().
2998 * The @notify function is called when the probe is disconnected and usually
2999 * used to free @data.
3001 * Returns: The handler id.
3006 gst_pad_add_data_probe_full (GstPad * pad, GCallback handler,
3007 gpointer data, GDestroyNotify notify)
3011 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3012 g_return_val_if_fail (handler != NULL, 0);
3014 GST_OBJECT_LOCK (pad);
3016 /* we only expose a GDestroyNotify in our API because that's less confusing */
3017 sigid = g_signal_connect_data (pad, "have-data", handler, data,
3018 (GClosureNotify) notify, 0);
3020 GST_PAD_DO_EVENT_SIGNALS (pad)++;
3021 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
3022 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3023 "adding data probe, now %d data, %d event probes",
3024 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
3025 GST_OBJECT_UNLOCK (pad);
3031 * gst_pad_add_event_probe:
3032 * @pad: pad to add the event probe handler to
3033 * @handler: function to call when events are passed over pad
3034 * @data: data to pass along with the handler
3036 * Adds a probe that will be called for all events passing through a pad. See
3037 * gst_pad_add_data_probe() for more information.
3039 * Returns: The handler id
3042 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
3044 return gst_pad_add_event_probe_full (pad, handler, data, NULL);
3048 * gst_pad_add_event_probe_full:
3049 * @pad: pad to add the event probe handler to
3050 * @handler: function to call when events are passed over pad
3051 * @data: data to pass along with the handler, or NULL
3052 * @notify: function to call when probe is disconnected, or NULL
3054 * Adds a probe that will be called for all events passing through a pad. See
3055 * gst_pad_add_data_probe() for more information.
3057 * The @notify function is called when the probe is disconnected and usually
3058 * used to free @data.
3060 * Returns: The handler id
3065 gst_pad_add_event_probe_full (GstPad * pad, GCallback handler,
3066 gpointer data, GDestroyNotify notify)
3070 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3071 g_return_val_if_fail (handler != NULL, 0);
3073 GST_OBJECT_LOCK (pad);
3075 /* we only expose a GDestroyNotify in our API because that's less confusing */
3076 sigid = g_signal_connect_data (pad, "have-data::event", handler, data,
3077 (GClosureNotify) notify, 0);
3079 GST_PAD_DO_EVENT_SIGNALS (pad)++;
3080 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding event probe, now %d probes",
3081 GST_PAD_DO_EVENT_SIGNALS (pad));
3082 GST_OBJECT_UNLOCK (pad);
3088 * gst_pad_add_buffer_probe:
3089 * @pad: pad to add the buffer probe handler to
3090 * @handler: function to call when buffers are passed over pad
3091 * @data: data to pass along with the handler
3093 * Adds a probe that will be called for all buffers passing through a pad. See
3094 * gst_pad_add_data_probe() for more information.
3096 * Returns: The handler id
3099 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
3101 return gst_pad_add_buffer_probe_full (pad, handler, data, NULL);
3105 * gst_pad_add_buffer_probe_full:
3106 * @pad: pad to add the buffer probe handler to
3107 * @handler: function to call when buffer are passed over pad
3108 * @data: data to pass along with the handler
3109 * @notify: function to call when the probe is disconnected, or NULL
3111 * Adds a probe that will be called for all buffers passing through a pad. See
3112 * gst_pad_add_data_probe() for more information.
3114 * The @notify function is called when the probe is disconnected and usually
3115 * used to free @data.
3117 * Returns: The handler id
3122 gst_pad_add_buffer_probe_full (GstPad * pad, GCallback handler,
3123 gpointer data, GDestroyNotify notify)
3127 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3128 g_return_val_if_fail (handler != NULL, 0);
3130 GST_OBJECT_LOCK (pad);
3132 /* we only expose a GDestroyNotify in our API because that's less confusing */
3133 sigid = g_signal_connect_data (pad, "have-data::buffer", handler, data,
3134 (GClosureNotify) notify, 0);
3136 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
3137 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding buffer probe, now %d probes",
3138 GST_PAD_DO_BUFFER_SIGNALS (pad));
3139 GST_OBJECT_UNLOCK (pad);
3145 * gst_pad_remove_data_probe:
3146 * @pad: pad to remove the data probe handler from
3147 * @handler_id: handler id returned from gst_pad_add_data_probe
3149 * Removes a data probe from @pad.
3152 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
3154 g_return_if_fail (GST_IS_PAD (pad));
3155 g_return_if_fail (handler_id > 0);
3157 GST_OBJECT_LOCK (pad);
3158 g_signal_handler_disconnect (pad, handler_id);
3159 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3160 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3161 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3162 "removed data probe, now %d event, %d buffer probes",
3163 GST_PAD_DO_EVENT_SIGNALS (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
3164 GST_OBJECT_UNLOCK (pad);
3169 * gst_pad_remove_event_probe:
3170 * @pad: pad to remove the event probe handler from
3171 * @handler_id: handler id returned from gst_pad_add_event_probe
3173 * Removes an event probe from @pad.
3176 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
3178 g_return_if_fail (GST_IS_PAD (pad));
3179 g_return_if_fail (handler_id > 0);
3181 GST_OBJECT_LOCK (pad);
3182 g_signal_handler_disconnect (pad, handler_id);
3183 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3184 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3185 "removed event probe, now %d event probes",
3186 GST_PAD_DO_EVENT_SIGNALS (pad));
3187 GST_OBJECT_UNLOCK (pad);
3191 * gst_pad_remove_buffer_probe:
3192 * @pad: pad to remove the buffer probe handler from
3193 * @handler_id: handler id returned from gst_pad_add_buffer_probe
3195 * Removes a buffer probe from @pad.
3198 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
3200 g_return_if_fail (GST_IS_PAD (pad));
3201 g_return_if_fail (handler_id > 0);
3203 GST_OBJECT_LOCK (pad);
3204 g_signal_handler_disconnect (pad, handler_id);
3205 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3206 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3207 "removed buffer probe, now %d buffer probes",
3208 GST_PAD_DO_BUFFER_SIGNALS (pad));
3209 GST_OBJECT_UNLOCK (pad);
3214 * gst_element_found_tags_for_pad:
3215 * @element: element for which to post taglist to bus.
3216 * @pad: pad on which to push tag-event.
3217 * @list: the taglist to post on the bus and create event from.
3219 * Posts a message to the bus that new tags were found and pushes the
3220 * tags as event. Takes ownership of the @list.
3222 * This is a utility method for elements. Applications should use the
3223 * #GstTagSetter interface.
3226 gst_element_found_tags_for_pad (GstElement * element,
3227 GstPad * pad, GstTagList * list)
3229 g_return_if_fail (element != NULL);
3230 g_return_if_fail (pad != NULL);
3231 g_return_if_fail (list != NULL);
3233 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
3234 /* FIXME 0.11: Set the pad as source to make it possible to detect for
3235 * which pad the tags are actually found.
3237 gst_element_post_message (element,
3238 gst_message_new_tag (GST_OBJECT (element), list));
3242 push_and_ref (GstPad * pad, GstEvent * event)
3244 gst_pad_push_event (pad, gst_event_ref (event));
3245 /* iterator refs pad, we unref when we are done with it */
3246 gst_object_unref (pad);
3250 * gst_element_found_tags:
3251 * @element: element for which we found the tags.
3252 * @list: list of tags.
3254 * Posts a message to the bus that new tags were found, and pushes an event
3255 * to all sourcepads. Takes ownership of the @list.
3257 * This is a utility method for elements. Applications should use the
3258 * #GstTagSetter interface.
3261 gst_element_found_tags (GstElement * element, GstTagList * list)
3266 g_return_if_fail (element != NULL);
3267 g_return_if_fail (list != NULL);
3269 iter = gst_element_iterate_src_pads (element);
3270 event = gst_event_new_tag (gst_tag_list_copy (list));
3271 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
3272 gst_iterator_free (iter);
3273 gst_event_unref (event);
3275 gst_element_post_message (element,
3276 gst_message_new_tag (GST_OBJECT (element), list));
3280 element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
3283 GstPad *unlinked_pad = NULL;
3286 switch (direction) {
3288 iter = gst_element_iterate_src_pads (element);
3291 iter = gst_element_iterate_sink_pads (element);
3294 g_return_val_if_reached (NULL);
3301 switch (gst_iterator_next (iter, &pad)) {
3302 case GST_ITERATOR_OK:{
3305 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
3306 GST_DEBUG_PAD_NAME (pad));
3308 peer = gst_pad_get_peer (GST_PAD (pad));
3312 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
3313 "found existing unlinked pad %s:%s",
3314 GST_DEBUG_PAD_NAME (unlinked_pad));
3316 gst_object_unref (pad);
3317 gst_object_unref (peer);
3321 case GST_ITERATOR_DONE:
3324 case GST_ITERATOR_RESYNC:
3325 gst_iterator_resync (iter);
3327 case GST_ITERATOR_ERROR:
3328 g_return_val_if_reached (NULL);
3333 gst_iterator_free (iter);
3335 return unlinked_pad;
3339 * gst_bin_find_unlinked_pad:
3340 * @bin: bin in which to look for elements with unlinked pads
3341 * @direction: whether to look for an unlinked source or sink pad
3343 * Recursively looks for elements with an unlinked pad of the given
3344 * direction within the specified bin and returns an unlinked pad
3345 * if one is found, or NULL otherwise. If a pad is found, the caller
3346 * owns a reference to it and should use gst_object_unref() on the
3347 * pad when it is not needed any longer.
3349 * Returns: unlinked pad of the given direction, or NULL.
3354 gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
3360 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
3361 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
3364 iter = gst_bin_iterate_recurse (bin);
3368 switch (gst_iterator_next (iter, &element)) {
3369 case GST_ITERATOR_OK:
3370 pad = element_find_unlinked_pad (GST_ELEMENT (element), direction);
3371 gst_object_unref (element);
3375 case GST_ITERATOR_DONE:
3378 case GST_ITERATOR_RESYNC:
3379 gst_iterator_resync (iter);
3381 case GST_ITERATOR_ERROR:
3382 g_return_val_if_reached (NULL);
3387 gst_iterator_free (iter);
3393 * gst_bin_find_unconnected_pad:
3394 * @bin: bin in which to look for elements with unlinked pads
3395 * @direction: whether to look for an unlinked source or sink pad
3397 * Recursively looks for elements with an unlinked pad of the given
3398 * direction within the specified bin and returns an unlinked pad
3399 * if one is found, or NULL otherwise. If a pad is found, the caller
3400 * owns a reference to it and should use gst_object_unref() on the
3401 * pad when it is not needed any longer.
3403 * Returns: unlinked pad of the given direction, or NULL.
3407 * Deprecated: use gst_bin_find_unlinked_pad() instead.
3409 #ifndef GST_REMOVE_DEPRECATED
3411 gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction)
3413 return gst_bin_find_unlinked_pad (bin, direction);
3418 * gst_parse_bin_from_description:
3419 * @bin_description: command line describing the bin
3420 * @ghost_unlinked_pads: whether to automatically create ghost pads
3421 * for unlinked source or sink pads within the bin
3422 * @err: where to store the error message in case of an error, or NULL
3424 * This is a convenience wrapper around gst_parse_launch() to create a
3425 * #GstBin from a gst-launch-style pipeline description. See
3426 * gst_parse_launch() and the gst-launch man page for details about the
3427 * syntax. Ghost pads on the bin for unlinked source or sink pads
3428 * within the bin can automatically be created (but only a maximum of
3429 * one ghost pad for each direction will be created; if you expect
3430 * multiple unlinked source pads or multiple unlinked sink pads
3431 * and want them all ghosted, you will have to create the ghost pads
3434 * Returns: a newly-created bin, or NULL if an error occurred.
3439 gst_parse_bin_from_description (const gchar * bin_description,
3440 gboolean ghost_unlinked_pads, GError ** err)
3442 return gst_parse_bin_from_description_full (bin_description,
3443 ghost_unlinked_pads, NULL, 0, err);
3447 * gst_parse_bin_from_description_full:
3448 * @bin_description: command line describing the bin
3449 * @ghost_unlinked_pads: whether to automatically create ghost pads
3450 * for unlinked source or sink pads within the bin
3451 * @context: a parse context allocated with gst_parse_context_new(), or %NULL
3452 * @flags: parsing options, or #GST_PARSE_FLAG_NONE
3453 * @err: where to store the error message in case of an error, or NULL
3455 * This is a convenience wrapper around gst_parse_launch() to create a
3456 * #GstBin from a gst-launch-style pipeline description. See
3457 * gst_parse_launch() and the gst-launch man page for details about the
3458 * syntax. Ghost pads on the bin for unlinked source or sink pads
3459 * within the bin can automatically be created (but only a maximum of
3460 * one ghost pad for each direction will be created; if you expect
3461 * multiple unlinked source pads or multiple unlinked sink pads
3462 * and want them all ghosted, you will have to create the ghost pads
3465 * Returns: a newly-created bin, or NULL if an error occurred.
3470 gst_parse_bin_from_description_full (const gchar * bin_description,
3471 gboolean ghost_unlinked_pads, GstParseContext * context,
3472 GstParseFlags flags, GError ** err)
3474 #ifndef GST_DISABLE_PARSE
3479 g_return_val_if_fail (bin_description != NULL, NULL);
3480 g_return_val_if_fail (err == NULL || *err == NULL, NULL);
3482 GST_DEBUG ("Making bin from description '%s'", bin_description);
3484 /* parse the pipeline to a bin */
3485 desc = g_strdup_printf ("bin.( %s )", bin_description);
3486 bin = (GstBin *) gst_parse_launch_full (desc, context, flags, err);
3489 if (bin == NULL || (err && *err != NULL)) {
3491 gst_object_unref (bin);
3495 /* find pads and ghost them if necessary */
3496 if (ghost_unlinked_pads) {
3497 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC))) {
3498 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("src", pad));
3499 gst_object_unref (pad);
3501 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SINK))) {
3502 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("sink", pad));
3503 gst_object_unref (pad);
3507 return GST_ELEMENT (bin);
3511 GST_WARNING ("Disabled API called");
3513 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED);
3514 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg);
3522 * gst_type_register_static_full:
3523 * @parent_type: The GType of the parent type the newly registered type will
3525 * @type_name: NULL-terminated string used as the name of the new type
3526 * @class_size: Size of the class structure.
3527 * @base_init: Location of the base initialization function (optional).
3528 * @base_finalize: Location of the base finalization function (optional).
3529 * @class_init: Location of the class initialization function for class types
3530 * Location of the default vtable inititalization function for interface
3532 * @class_finalize: Location of the class finalization function for class types.
3533 * Location of the default vtable finalization function for interface types.
3535 * @class_data: User-supplied data passed to the class init/finalize functions.
3536 * @instance_size: Size of the instance (object) structure (required for
3537 * instantiatable types only).
3538 * @n_preallocs: The number of pre-allocated (cached) instances to reserve
3539 * memory for (0 indicates no caching). Ignored on recent GLib's.
3540 * @instance_init: Location of the instance initialization function (optional,
3541 * for instantiatable types only).
3542 * @value_table: A GTypeValueTable function table for generic handling of
3543 * GValues of this type (usually only useful for fundamental types).
3544 * @flags: #GTypeFlags for this GType. E.g: G_TYPE_FLAG_ABSTRACT
3546 * Helper function which constructs a #GTypeInfo structure and registers a
3547 * GType, but which generates less linker overhead than a static const
3548 * #GTypeInfo structure. For further details of the parameters, please see
3549 * #GTypeInfo in the GLib documentation.
3551 * Registers type_name as the name of a new static type derived from
3552 * parent_type. The value of flags determines the nature (e.g. abstract or
3553 * not) of the type. It works by filling a GTypeInfo struct and calling
3554 * g_type_info_register_static().
3556 * Returns: A #GType for the newly-registered type.
3561 gst_type_register_static_full (GType parent_type,
3562 const gchar * type_name,
3564 GBaseInitFunc base_init,
3565 GBaseFinalizeFunc base_finalize,
3566 GClassInitFunc class_init,
3567 GClassFinalizeFunc class_finalize,
3568 gconstpointer class_data,
3569 guint instance_size,
3570 guint16 n_preallocs,
3571 GInstanceInitFunc instance_init,
3572 const GTypeValueTable * value_table, GTypeFlags flags)
3576 info.class_size = class_size;
3577 info.base_init = base_init;
3578 info.base_finalize = base_finalize;
3579 info.class_init = class_init;
3580 info.class_finalize = class_finalize;
3581 info.class_data = class_data;
3582 info.instance_size = instance_size;
3583 info.n_preallocs = n_preallocs;
3584 info.instance_init = instance_init;
3585 info.value_table = value_table;
3587 return g_type_register_static (parent_type, type_name, &info, flags);
3592 * gst_util_get_timestamp:
3594 * Get a timestamp as GstClockTime to be used for interval meassurements.
3595 * The timestamp should not be interpreted in any other way.
3597 * Returns: the timestamp
3602 gst_util_get_timestamp (void)
3604 #if defined (HAVE_POSIX_TIMERS) && defined(HAVE_MONOTONIC_CLOCK)
3605 struct timespec now;
3607 clock_gettime (CLOCK_MONOTONIC, &now);
3608 return GST_TIMESPEC_TO_TIME (now);
3612 g_get_current_time (&now);
3613 return GST_TIMEVAL_TO_TIME (now);
3618 * gst_util_array_binary_search:
3619 * @array: the sorted input array
3620 * @num_elements: number of elements in the array
3621 * @element_size: size of every element in bytes
3622 * @search_func: function to compare two elements, @search_data will always be passed as second argument
3623 * @mode: search mode that should be used
3624 * @search_data: element that should be found
3625 * @user_data: data to pass to @search_func
3627 * Searches inside @array for @search_data by using the comparison function
3628 * @search_func. @array must be sorted ascending.
3630 * As @search_data is always passed as second argument to @search_func it's
3631 * not required that @search_data has the same type as the array elements.
3633 * The complexity of this search function is O(log (num_elements)).
3635 * Returns: The address of the found element or %NULL if nothing was found
3640 gst_util_array_binary_search (gpointer array, guint num_elements,
3641 gsize element_size, GCompareDataFunc search_func, GstSearchMode mode,
3642 gconstpointer search_data, gpointer user_data)
3644 glong left = 0, right = num_elements - 1, m;
3646 guint8 *data = (guint8 *) array;
3648 g_return_val_if_fail (array != NULL, NULL);
3649 g_return_val_if_fail (element_size > 0, NULL);
3650 g_return_val_if_fail (search_func != NULL, NULL);
3652 /* 0. No elements => return NULL */
3653 if (num_elements == 0)
3656 /* 1. If search_data is before the 0th element return the 0th element */
3657 ret = search_func (data, search_data, user_data);
3658 if ((ret >= 0 && mode == GST_SEARCH_MODE_AFTER) || ret == 0)
3663 /* 2. If search_data is after the last element return the last element */
3665 search_func (data + (num_elements - 1) * element_size, search_data,
3667 if ((ret <= 0 && mode == GST_SEARCH_MODE_BEFORE) || ret == 0)
3668 return data + (num_elements - 1) * element_size;
3672 /* 3. else binary search */
3674 m = left + (right - left) / 2;
3676 ret = search_func (data + m * element_size, search_data, user_data);
3679 return data + m * element_size;
3680 } else if (ret < 0) {
3686 /* No exact match found */
3688 if (mode == GST_SEARCH_MODE_EXACT) {
3690 } else if (mode == GST_SEARCH_MODE_AFTER) {
3692 return (m < num_elements) ? data + (m + 1) * element_size : NULL;
3694 return data + m * element_size;
3697 return data + m * element_size;
3699 return (m > 0) ? data + (m - 1) * element_size : NULL;