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"
45 * @mem: a pointer to the memory to dump
46 * @size: the size of the memory block to dump
48 * Dumps the memory block into a hex representation. Useful for debugging.
51 gst_util_dump_mem (const guchar * mem, guint size)
54 GString *string = g_string_sized_new (50);
55 GString *chars = g_string_sized_new (18);
59 if (g_ascii_isprint (mem[i]))
60 g_string_append_c (chars, mem[i]);
62 g_string_append_c (chars, '.');
64 g_string_append_printf (string, "%02x ", mem[i]);
69 if (j == 16 || i == size) {
70 g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
71 string->str, chars->str);
72 g_string_set_size (string, 0);
73 g_string_set_size (chars, 0);
77 g_string_free (string, TRUE);
78 g_string_free (chars, TRUE);
83 * gst_util_set_value_from_string:
84 * @value: the value to set
85 * @value_str: the string to get the value from
87 * Converts the string to the type of the value and
88 * sets the value with it.
91 gst_util_set_value_from_string (GValue * value, const gchar * value_str)
95 g_return_if_fail (value != NULL);
96 g_return_if_fail (value_str != NULL);
98 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
99 g_type_name (G_VALUE_TYPE (value)));
101 switch (G_VALUE_TYPE (value)) {
103 g_value_set_string (value, value_str);
109 sscanf_ret = sscanf (value_str, "%d", &i);
110 g_return_if_fail (sscanf_ret == 1);
111 g_value_set_int (value, i);
117 sscanf_ret = sscanf (value_str, "%u", &i);
118 g_return_if_fail (sscanf_ret == 1);
119 g_value_set_uint (value, i);
125 sscanf_ret = sscanf (value_str, "%ld", &i);
126 g_return_if_fail (sscanf_ret == 1);
127 g_value_set_long (value, i);
133 sscanf_ret = sscanf (value_str, "%lu", &i);
134 g_return_if_fail (sscanf_ret == 1);
135 g_value_set_ulong (value, i);
138 case G_TYPE_BOOLEAN:{
141 if (!g_ascii_strncasecmp ("true", value_str, 4))
143 g_value_set_boolean (value, i);
149 sscanf_ret = sscanf (value_str, "%c", &i);
150 g_return_if_fail (sscanf_ret == 1);
151 g_value_set_char (value, i);
157 sscanf_ret = sscanf (value_str, "%c", &i);
158 g_return_if_fail (sscanf_ret == 1);
159 g_value_set_uchar (value, i);
165 sscanf_ret = sscanf (value_str, "%f", &i);
166 g_return_if_fail (sscanf_ret == 1);
167 g_value_set_float (value, i);
173 sscanf_ret = sscanf (value_str, "%g", &i);
174 g_return_if_fail (sscanf_ret == 1);
175 g_value_set_double (value, (gdouble) i);
184 * gst_util_set_object_arg:
185 * @object: the object to set the argument of
186 * @name: the name of the argument to set
187 * @value: the string value to set
189 * Convertes the string value to the type of the objects argument and
190 * sets the argument with it.
193 gst_util_set_object_arg (GObject * object, const gchar * name,
199 GParamSpec *paramspec;
202 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
208 GST_DEBUG ("paramspec->flags is %d, paramspec->value_type is %d",
209 paramspec->flags, (gint) paramspec->value_type);
211 if (paramspec->flags & G_PARAM_WRITABLE) {
212 switch (paramspec->value_type) {
214 g_object_set (G_OBJECT (object), name, value, NULL);
220 sscanf_ret = sscanf (value, "%d", &i);
221 g_return_if_fail (sscanf_ret == 1);
222 g_object_set (G_OBJECT (object), name, i, NULL);
228 sscanf_ret = sscanf (value, "%u", &i);
229 g_return_if_fail (sscanf_ret == 1);
230 g_object_set (G_OBJECT (object), name, i, NULL);
236 sscanf_ret = sscanf (value, "%ld", &i);
237 g_return_if_fail (sscanf_ret == 1);
238 g_object_set (G_OBJECT (object), name, i, NULL);
244 sscanf_ret = sscanf (value, "%lu", &i);
245 g_return_if_fail (sscanf_ret == 1);
246 g_object_set (G_OBJECT (object), name, i, NULL);
249 case G_TYPE_BOOLEAN:{
252 if (!g_ascii_strncasecmp ("true", value, 4))
254 g_object_set (G_OBJECT (object), name, i, NULL);
260 sscanf_ret = sscanf (value, "%c", &i);
261 g_return_if_fail (sscanf_ret == 1);
262 g_object_set (G_OBJECT (object), name, i, NULL);
268 sscanf_ret = sscanf (value, "%c", &i);
269 g_return_if_fail (sscanf_ret == 1);
270 g_object_set (G_OBJECT (object), name, i, NULL);
276 sscanf_ret = sscanf (value, "%f", &i);
277 g_return_if_fail (sscanf_ret == 1);
278 g_object_set (G_OBJECT (object), name, i, NULL);
284 sscanf_ret = sscanf (value, "%g", &i);
285 g_return_if_fail (sscanf_ret == 1);
286 g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
290 if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
293 sscanf_ret = sscanf (value, "%d", &i);
294 g_return_if_fail (sscanf_ret == 1);
295 g_object_set (G_OBJECT (object), name, i, NULL);
303 /* work around error C2520: conversion from unsigned __int64 to double
304 * not implemented, use signed __int64
306 * These are implemented as functions because on some platforms a 64bit int to
307 * double conversion is not defined/implemented.
311 gst_util_guint64_to_gdouble (guint64 value)
313 if (value & G_GINT64_CONSTANT (0x8000000000000000))
314 return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
316 return (gdouble) ((gint64) value);
320 gst_util_gdouble_to_guint64 (gdouble value)
322 if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */
323 return ((guint64) ((gint64) value));
325 value -= (gdouble) 18446744073709551616.;
326 return ((guint64) ((gint64) value));
329 /* convenience struct for getting high and low uint32 parts of
336 #if G_BYTE_ORDER == G_BIG_ENDIAN
344 /* based on Hacker's Delight p152 */
346 gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom)
348 GstUInt64 q1, q0, rhat;
349 GstUInt64 v, cmp1, cmp2;
354 /* count number of leading zeroes, we know they must be in the high
355 * part of denom since denom > G_MAXUINT32. */
356 s = v.l.high | (v.l.high >> 1);
360 s = ~(s | (s >> 16));
361 s = s - ((s >> 1) & 0x55555555);
362 s = (s & 0x33333333) + ((s >> 2) & 0x33333333);
363 s = (s + (s >> 4)) & 0x0f0f0f0f;
365 s = (s + (s >> 16)) & 0x3f;
368 /* normalize divisor and dividend */
370 c1.ll = (c1.ll << s) | (c0.l.high >> (32 - s));
374 q1.ll = c1.ll / v.l.high;
375 rhat.ll = c1.ll - q1.ll * v.l.high;
377 cmp1.l.high = rhat.l.low;
378 cmp1.l.low = c0.l.high;
379 cmp2.ll = q1.ll * v.l.low;
381 while (q1.l.high || cmp2.ll > cmp1.ll) {
386 cmp1.l.high = rhat.l.low;
389 c1.l.high = c1.l.low;
390 c1.l.low = c0.l.high;
391 c1.ll -= q1.ll * v.ll;
392 q0.ll = c1.ll / v.l.high;
393 rhat.ll = c1.ll - q0.ll * v.l.high;
395 cmp1.l.high = rhat.l.low;
396 cmp1.l.low = c0.l.low;
397 cmp2.ll = q0.ll * v.l.low;
399 while (q0.l.high || cmp2.ll > cmp1.ll) {
404 cmp1.l.high = rhat.l.low;
407 q0.l.high += q1.l.low;
413 gst_util_uint64_scale_int64 (guint64 val, guint64 num, guint64 denom)
415 GstUInt64 a0, a1, b0, b1, c0, ct, c1, result;
422 /* do 128 bits multiply
430 * -------------------
433 a0.ll = (guint64) v.l.low * n.l.low;
434 a1.ll = (guint64) v.l.low * n.l.high;
435 b0.ll = (guint64) v.l.high * n.l.low;
436 b1.ll = (guint64) v.l.high * n.l.high;
438 /* and sum together with carry into 128 bits c1, c0 */
440 ct.ll = (guint64) a0.l.high + a1.l.low + b0.l.low;
441 c0.l.high = ct.l.low;
442 c1.ll = (guint64) a1.l.high + b0.l.high + ct.l.high + b1.ll;
444 /* if high bits bigger than denom, we overflow */
448 /* shortcut for division by 1, c1.ll should be 0 because of the
449 * overflow check above. */
453 /* and 128/64 bits division, result fits 64 bits */
454 if (denom <= G_MAXUINT32) {
455 guint32 den = (guint32) denom;
457 /* easy case, (c1,c0)128/(den)32 division */
459 c1.l.high = c1.ll % den;
460 c1.l.low = c0.l.high;
461 c0.l.high = c1.ll % den;
462 result.l.high = c1.ll / den;
463 result.l.low = c0.ll / den;
465 result.ll = gst_util_div128_64 (c1, c0, denom);
476 * gst_util_uint64_scale:
477 * @val: the number to scale
478 * @num: the numerator of the scale ratio
479 * @denom: the denominator of the scale ratio
481 * Scale @val by @num / @denom, trying to avoid overflows.
483 * This function can potentially be very slow if denom > G_MAXUINT32.
485 * Returns: @val * @num / @denom, trying to avoid overflows.
486 * In the case of an overflow, this function returns G_MAXUINT64.
489 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
491 g_return_val_if_fail (denom != 0, G_MAXUINT64);
496 if (num == 1 && denom == 1)
499 /* if the denom is high, we need to do a 64 muldiv */
500 if (denom > G_MAXINT32)
503 /* if num and denom are low we can do a 32 bit muldiv */
504 if (num <= G_MAXINT32)
507 /* val and num are high, we need 64 muldiv */
508 if (val > G_MAXINT32)
511 /* val is low and num is high, we can swap them and do 32 muldiv */
512 return gst_util_uint64_scale_int (num, (gint) val, (gint) denom);
515 return gst_util_uint64_scale_int (val, (gint) num, (gint) denom);
518 /* to the more heavy implementations... */
519 return gst_util_uint64_scale_int64 (val, num, denom);
523 * gst_util_uint64_scale_int:
524 * @val: guint64 (such as a #GstClockTime) to scale.
525 * @num: numerator of the scale factor.
526 * @denom: denominator of the scale factor.
528 * Scale a guint64 by a factor expressed as a fraction (num/denom), avoiding
529 * overflows and loss of precision.
531 * @num and @denom must be positive integers. @denom cannot be 0.
533 * Returns: @val * @num / @denom, avoiding overflow and loss of precision.
534 * In the case of an overflow, this function returns G_MAXUINT64.
537 gst_util_uint64_scale_int (guint64 val, gint num, gint denom)
542 g_return_val_if_fail (denom > 0, G_MAXUINT64);
543 g_return_val_if_fail (num >= 0, G_MAXUINT64);
548 if (num == 1 && denom == 1)
551 if (val <= G_MAXUINT32)
553 return val * num / denom;
555 /* do 96 bits mult/div */
557 result.ll = ((guint64) low.l.low) * num;
558 high.ll = ((guint64) low.l.high) * num + (result.l.high);
560 low.ll = high.ll / denom;
561 result.l.high = high.ll % denom;
565 if (low.ll + result.l.high > G_MAXUINT32)
568 result.l.high += low.l.low;
579 * gst_util_seqnum_next:
581 * Return a constantly incrementing sequence number.
583 * This function is used internally to GStreamer to be able to determine which
584 * events and messages are "the same". For example, elements may set the seqnum
585 * on a segment-done message to be the same as that of the last seek event, to
586 * indicate that event and the message correspond to the same segment.
588 * Returns: A constantly incrementing 32-bit unsigned integer, which might
589 * overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
590 * you handle wraparound correctly.
595 gst_util_seqnum_next (void)
597 static gint counter = 0;
598 return g_atomic_int_exchange_and_add (&counter, 1);
602 * gst_util_seqnum_compare:
603 * @s1: A sequence number.
604 * @s2: Another sequence number.
606 * Compare two sequence numbers, handling wraparound.
608 * The current implementation just returns (gint32)(@s1 - @s2).
610 * Returns: A negative number if @s1 is before @s2, 0 if they are equal, or a
611 * positive number if @s1 is after @s2.
616 gst_util_seqnum_compare (guint32 s1, guint32 s2)
618 return (gint32) (s1 - s2);
621 /* -----------------------------------------------------
623 * The following code will be moved out of the main
624 * gstreamer library someday.
630 string_append_indent (GString * str, gint count)
634 for (xx = 0; xx < count; xx++)
635 g_string_append_c (str, ' ');
639 * gst_print_pad_caps:
640 * @buf: the buffer to print the caps in
641 * @indent: initial indentation
642 * @pad: the pad to print the caps from
644 * Write the pad capabilities in a human readable format into
648 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
655 string_append_indent (buf, indent);
656 g_string_printf (buf, "%s:%s has no capabilities",
657 GST_DEBUG_PAD_NAME (pad));
661 s = gst_caps_to_string (caps);
662 g_string_append (buf, s);
668 * gst_print_element_args:
669 * @buf: the buffer to print the args in
670 * @indent: initial indentation
671 * @element: the element to print the args of
673 * Print the element argument in a human readable format in the given
677 gst_print_element_args (GString * buf, gint indent, GstElement * element)
680 GValue value = { 0, }; /* the important thing is that value.type = 0 */
682 GParamSpec *spec, **specs, **walk;
684 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
687 for (walk = specs; *walk; walk++) {
689 if (width < strlen (spec->name))
690 width = strlen (spec->name);
693 for (walk = specs; *walk; walk++) {
696 if (spec->flags & G_PARAM_READABLE) {
697 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
698 g_object_get_property (G_OBJECT (element), spec->name, &value);
699 str = g_strdup_value_contents (&value);
700 g_value_unset (&value);
702 str = g_strdup ("Parameter not readable.");
705 string_append_indent (buf, indent);
706 g_string_append (buf, spec->name);
707 string_append_indent (buf, 2 + width - strlen (spec->name));
708 g_string_append (buf, str);
709 g_string_append_c (buf, '\n');
718 * gst_element_create_all_pads:
719 * @element: a #GstElement to create pads for
721 * Creates a pad for each pad template that is always available.
722 * This function is only useful during object intialization of
723 * subclasses of #GstElement.
726 gst_element_create_all_pads (GstElement * element)
730 /* FIXME: lock element */
733 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
734 (G_OBJECT_GET_CLASS (element)));
737 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
739 if (padtempl->presence == GST_PAD_ALWAYS) {
742 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
744 gst_element_add_pad (element, pad);
746 padlist = padlist->next;
751 * gst_element_get_compatible_pad_template:
752 * @element: a #GstElement to get a compatible pad template for.
753 * @compattempl: the #GstPadTemplate to find a compatible template for.
755 * Retrieves a pad template from @element that is compatible with @compattempl.
756 * Pads from compatible templates can be linked together.
758 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
759 * unreferencing is necessary.
762 gst_element_get_compatible_pad_template (GstElement * element,
763 GstPadTemplate * compattempl)
765 GstPadTemplate *newtempl = NULL;
767 GstElementClass *class;
769 g_return_val_if_fail (element != NULL, NULL);
770 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
771 g_return_val_if_fail (compattempl != NULL, NULL);
773 class = GST_ELEMENT_GET_CLASS (element);
775 padlist = gst_element_class_get_pad_template_list (class);
777 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
778 "Looking for a suitable pad template in %s out of %d templates...",
779 GST_ELEMENT_NAME (element), g_list_length (padlist));
782 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
783 GstCaps *intersection;
787 * Check direction (must be opposite)
790 GST_CAT_LOG (GST_CAT_CAPS,
791 "checking pad template %s", padtempl->name_template);
792 if (padtempl->direction != compattempl->direction) {
793 GST_CAT_DEBUG (GST_CAT_CAPS,
794 "compatible direction: found %s pad template \"%s\"",
795 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
796 padtempl->name_template);
798 GST_CAT_DEBUG (GST_CAT_CAPS,
799 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
800 GST_CAT_DEBUG (GST_CAT_CAPS,
801 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
803 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
804 GST_PAD_TEMPLATE_CAPS (padtempl));
806 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
807 (intersection ? "" : "not "), intersection);
809 if (!gst_caps_is_empty (intersection))
811 gst_caps_unref (intersection);
816 padlist = g_list_next (padlist);
819 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
820 "Returning new pad template %p", newtempl);
822 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
828 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
831 GstPad *newpad = NULL;
832 GstElementClass *oclass;
834 oclass = GST_ELEMENT_GET_CLASS (element);
836 if (oclass->request_new_pad)
837 newpad = (oclass->request_new_pad) (element, templ, name);
840 gst_object_ref (newpad);
848 * gst_element_get_pad_from_template:
849 * @element: a #GstElement.
850 * @templ: a #GstPadTemplate belonging to @element.
852 * Gets a pad from @element described by @templ. If the presence of @templ is
853 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
856 * Returns: the #GstPad, or NULL if one could not be found or created.
859 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
862 GstPadPresence presence;
864 /* If this function is ever exported, we need check the validity of `element'
865 * and `templ', and to make sure the template actually belongs to the
868 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
872 case GST_PAD_SOMETIMES:
873 ret = gst_element_get_static_pad (element, templ->name_template);
874 if (!ret && presence == GST_PAD_ALWAYS)
876 ("Element %s has an ALWAYS template %s, but no pad of the same name",
877 GST_OBJECT_NAME (element), templ->name_template);
880 case GST_PAD_REQUEST:
881 ret = gst_element_request_pad (element, templ, NULL);
889 * gst_element_request_compatible_pad:
890 * @element: a #GstElement.
891 * @templ: the #GstPadTemplate to which the new pad should be able to link.
893 * Requests a pad from @element. The returned pad should be unlinked and
894 * compatible with @templ. Might return an existing pad, or request a new one.
896 * Returns: a #GstPad, or %NULL if one could not be found or created.
899 gst_element_request_compatible_pad (GstElement * element,
900 GstPadTemplate * templ)
902 GstPadTemplate *templ_new;
905 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
906 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
908 /* FIXME: should really loop through the templates, testing each for
909 * compatibility and pad availability. */
910 templ_new = gst_element_get_compatible_pad_template (element, templ);
912 pad = gst_element_get_pad_from_template (element, templ_new);
914 /* This can happen for non-request pads. No need to unref. */
915 if (pad && GST_PAD_PEER (pad))
922 * gst_element_get_compatible_pad:
923 * @element: a #GstElement in which the pad should be found.
924 * @pad: the #GstPad to find a compatible one for.
925 * @caps: the #GstCaps to use as a filter.
927 * Looks for an unlinked pad to which the given pad can link. It is not
928 * guaranteed that linking the pads will work, though it should work in most
931 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
932 * found. gst_object_unref() after usage.
935 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
936 const GstCaps * caps)
939 GstPadTemplate *templ;
941 GstPad *foundpad = NULL;
944 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
945 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
947 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
948 "finding pad in %s compatible with %s:%s",
949 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
951 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
954 /* try to get an existing unlinked pad */
955 pads = gst_element_iterate_pads (element);
959 switch (gst_iterator_next (pads, &padptr)) {
960 case GST_ITERATOR_OK:
965 current = GST_PAD (padptr);
967 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
968 GST_DEBUG_PAD_NAME (current));
970 peer = gst_pad_get_peer (current);
972 if (peer == NULL && gst_pad_can_link (pad, current)) {
973 GstCaps *temp, *temp2, *intersection;
975 /* Now check if the two pads' caps are compatible */
976 temp = gst_pad_get_caps (pad);
978 intersection = gst_caps_intersect (temp, caps);
979 gst_caps_unref (temp);
984 temp = gst_pad_get_caps (current);
985 temp2 = gst_caps_intersect (temp, intersection);
986 gst_caps_unref (temp);
987 gst_caps_unref (intersection);
989 intersection = temp2;
991 if (!gst_caps_is_empty (intersection)) {
992 gst_caps_unref (intersection);
994 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
995 "found existing unlinked compatible pad %s:%s",
996 GST_DEBUG_PAD_NAME (current));
997 gst_iterator_free (pads);
1002 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "incompatible pads");
1004 gst_caps_unref (intersection);
1007 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1008 "already linked or cannot be linked (peer = %p)", peer);
1010 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
1012 gst_object_unref (current);
1014 gst_object_unref (peer);
1017 case GST_ITERATOR_DONE:
1020 case GST_ITERATOR_RESYNC:
1021 gst_iterator_resync (pads);
1023 case GST_ITERATOR_ERROR:
1024 g_assert_not_reached ();
1028 gst_iterator_free (pads);
1030 GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element,
1031 "Could not find a compatible unlinked always pad to link to %s:%s, now checking request pads",
1032 GST_DEBUG_PAD_NAME (pad));
1034 /* try to create a new one */
1035 /* requesting is a little crazy, we need a template. Let's create one */
1036 /* FIXME: why not gst_pad_get_pad_template (pad); */
1037 templcaps = gst_pad_get_caps (pad);
1039 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
1040 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
1042 /* FIXME : Because of a bug in gst_pad_template_new() by which is does not
1043 * properly steal the refcount of the given caps, we have to unref these caps
1044 * REVERT THIS WHEN FIXED !*/
1045 gst_caps_unref (templcaps);
1047 foundpad = gst_element_request_compatible_pad (element, templ);
1048 gst_object_unref (templ);
1051 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1052 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
1056 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
1057 "Could not find a compatible pad to link to %s:%s",
1058 GST_DEBUG_PAD_NAME (pad));
1063 * gst_element_state_get_name:
1064 * @state: a #GstState to get the name of.
1066 * Gets a string representing the given state.
1068 * Returns: a string with the name of the state.
1070 G_CONST_RETURN gchar *
1071 gst_element_state_get_name (GstState state)
1074 #ifdef GST_DEBUG_COLOR
1075 case GST_STATE_VOID_PENDING:
1076 return "VOID_PENDING";
1077 case GST_STATE_NULL:
1078 return "\033[01;34mNULL\033[00m";
1079 case GST_STATE_READY:
1080 return "\033[01;31mREADY\033[00m";
1081 case GST_STATE_PLAYING:
1082 return "\033[01;32mPLAYING\033[00m";
1083 case GST_STATE_PAUSED:
1084 return "\033[01;33mPAUSED\033[00m";
1086 /* This is a memory leak */
1087 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
1089 case GST_STATE_VOID_PENDING:
1090 return "VOID_PENDING";
1091 case GST_STATE_NULL:
1093 case GST_STATE_READY:
1095 case GST_STATE_PLAYING:
1097 case GST_STATE_PAUSED:
1100 /* This is a memory leak */
1101 return g_strdup_printf ("UNKNOWN!(%d)", state);
1107 * gst_element_state_change_return_get_name:
1108 * @state_ret: a #GstStateChangeReturn to get the name of.
1110 * Gets a string representing the given state change result.
1112 * Returns: a string with the name of the state change result.
1116 G_CONST_RETURN gchar *
1117 gst_element_state_change_return_get_name (GstStateChangeReturn state_ret)
1119 switch (state_ret) {
1120 #ifdef GST_DEBUG_COLOR
1121 case GST_STATE_CHANGE_FAILURE:
1122 return "\033[01;31mFAILURE\033[00m";
1123 case GST_STATE_CHANGE_SUCCESS:
1124 return "\033[01;32mSUCCESS\033[00m";
1125 case GST_STATE_CHANGE_ASYNC:
1126 return "\033[01;33mASYNC\033[00m";
1127 case GST_STATE_CHANGE_NO_PREROLL:
1128 return "\033[01;34mNO_PREROLL\033[00m";
1130 /* This is a memory leak */
1131 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state_ret);
1133 case GST_STATE_CHANGE_FAILURE:
1135 case GST_STATE_CHANGE_SUCCESS:
1137 case GST_STATE_CHANGE_ASYNC:
1139 case GST_STATE_CHANGE_NO_PREROLL:
1140 return "NO PREROLL";
1142 /* This is a memory leak */
1143 return g_strdup_printf ("UNKNOWN!(%d)", state_ret);
1150 * gst_element_factory_can_src_caps :
1151 * @factory: factory to query
1152 * @caps: the caps to check
1154 * Checks if the factory can source the given capability.
1156 * Returns: true if it can src the capabilities
1159 gst_element_factory_can_src_caps (GstElementFactory * factory,
1160 const GstCaps * caps)
1164 g_return_val_if_fail (factory != NULL, FALSE);
1165 g_return_val_if_fail (caps != NULL, FALSE);
1167 templates = factory->staticpadtemplates;
1170 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1172 if (template->direction == GST_PAD_SRC) {
1173 if (gst_caps_is_always_compatible (gst_static_caps_get
1174 (&template->static_caps), caps))
1177 templates = g_list_next (templates);
1184 * gst_element_factory_can_sink_caps :
1185 * @factory: factory to query
1186 * @caps: the caps to check
1188 * Checks if the factory can sink the given capability.
1190 * Returns: true if it can sink the capabilities
1193 gst_element_factory_can_sink_caps (GstElementFactory * factory,
1194 const GstCaps * caps)
1198 g_return_val_if_fail (factory != NULL, FALSE);
1199 g_return_val_if_fail (caps != NULL, FALSE);
1201 templates = factory->staticpadtemplates;
1204 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1206 if (template->direction == GST_PAD_SINK) {
1207 if (gst_caps_is_always_compatible (caps,
1208 gst_static_caps_get (&template->static_caps)))
1211 templates = g_list_next (templates);
1218 /* if return val is true, *direct_child is a caller-owned ref on the direct
1219 * child of ancestor that is part of object's ancestry */
1221 object_has_ancestor (GstObject * object, GstObject * ancestor,
1222 GstObject ** direct_child)
1224 GstObject *child, *parent;
1227 *direct_child = NULL;
1229 child = gst_object_ref (object);
1230 parent = gst_object_get_parent (object);
1233 if (ancestor == parent) {
1235 *direct_child = child;
1237 gst_object_unref (child);
1238 gst_object_unref (parent);
1242 gst_object_unref (child);
1244 parent = gst_object_get_parent (parent);
1247 gst_object_unref (child);
1252 /* caller owns return */
1254 find_common_root (GstObject * o1, GstObject * o2)
1256 GstObject *top = o1;
1257 GstObject *kid1, *kid2;
1258 GstObject *root = NULL;
1260 while (GST_OBJECT_PARENT (top))
1261 top = GST_OBJECT_PARENT (top);
1263 /* the itsy-bitsy spider... */
1265 if (!object_has_ancestor (o2, top, &kid2))
1268 root = gst_object_ref (top);
1270 if (!object_has_ancestor (o1, kid2, &kid1)) {
1271 gst_object_unref (kid2);
1275 if (!object_has_ancestor (o2, kid1, &kid2)) {
1276 gst_object_unref (kid1);
1283 /* caller does not own return */
1285 ghost_up (GstElement * e, GstPad * pad)
1287 static gint ghost_pad_index = 0;
1290 GstObject *parent = GST_OBJECT_PARENT (e);
1292 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
1293 gpad = gst_ghost_pad_new (name, pad);
1296 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
1297 g_warning ("Pad named %s already exists in element %s\n",
1298 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
1299 gst_object_unref ((GstObject *) gpad);
1307 remove_pad (gpointer ppad, gpointer unused)
1311 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
1312 g_warning ("Couldn't remove pad %s from element %s",
1313 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
1317 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
1318 GSList ** pads_created)
1322 GSList *pads_created_local = NULL;
1324 g_assert (pads_created);
1326 e1 = GST_OBJECT_PARENT (*src);
1327 e2 = GST_OBJECT_PARENT (*sink);
1329 if (G_UNLIKELY (e1 == NULL)) {
1330 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1331 GST_PTR_FORMAT, *src);
1334 if (G_UNLIKELY (e2 == NULL)) {
1335 GST_WARNING ("Trying to ghost a pad that doesn't have a parent: %"
1336 GST_PTR_FORMAT, *sink);
1340 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
1341 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
1342 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1346 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
1347 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1349 /* we need to setup some ghost pads */
1350 root = find_common_root (e1, e2);
1352 g_warning ("Trying to connect elements that don't share a common "
1353 "ancestor: %s and %s", GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
1357 while (GST_OBJECT_PARENT (e1) != root) {
1358 *src = ghost_up ((GstElement *) e1, *src);
1361 e1 = GST_OBJECT_PARENT (*src);
1362 pads_created_local = g_slist_prepend (pads_created_local, *src);
1364 while (GST_OBJECT_PARENT (e2) != root) {
1365 *sink = ghost_up ((GstElement *) e2, *sink);
1368 e2 = GST_OBJECT_PARENT (*sink);
1369 pads_created_local = g_slist_prepend (pads_created_local, *sink);
1372 gst_object_unref (root);
1373 *pads_created = g_slist_concat (*pads_created, pads_created_local);
1377 gst_object_unref (root);
1378 g_slist_foreach (pads_created_local, remove_pad, NULL);
1379 g_slist_free (pads_created_local);
1384 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1386 GSList *pads_created = NULL;
1389 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1392 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1396 g_slist_foreach (pads_created, remove_pad, NULL);
1398 g_slist_free (pads_created);
1404 * gst_element_link_pads:
1405 * @src: a #GstElement containing the source pad.
1406 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1407 * @dest: the #GstElement containing the destination pad.
1408 * @destpadname: the name of the #GstPad in destination element,
1409 * or NULL for any pad.
1411 * Links the two named pads of the source and destination elements.
1412 * Side effect is that if one of the pads has no parent, it becomes a
1413 * child of the parent of the other element. If they have different
1414 * parents, the link fails.
1416 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1419 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1420 GstElement * dest, const gchar * destpadname)
1422 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1423 GstPad *srcpad, *destpad;
1424 GstPadTemplate *srctempl, *desttempl;
1425 GstElementClass *srcclass, *destclass;
1428 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1429 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1431 srcclass = GST_ELEMENT_GET_CLASS (src);
1432 destclass = GST_ELEMENT_GET_CLASS (dest);
1434 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1435 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1436 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1437 destpadname ? destpadname : "(any)");
1441 /* name specified, look it up */
1442 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1443 srcpad = gst_element_get_request_pad (src, srcpadname);
1445 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1446 GST_ELEMENT_NAME (src), srcpadname);
1449 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1450 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1451 GST_DEBUG_PAD_NAME (srcpad));
1452 gst_object_unref (srcpad);
1455 if (GST_PAD_PEER (srcpad) != NULL) {
1456 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1457 GST_DEBUG_PAD_NAME (srcpad));
1458 gst_object_unref (srcpad);
1464 /* no name given, get the first available pad */
1465 GST_OBJECT_LOCK (src);
1466 srcpads = GST_ELEMENT_PADS (src);
1467 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1469 gst_object_ref (srcpad);
1470 GST_OBJECT_UNLOCK (src);
1473 /* get a destination pad */
1475 /* name specified, look it up */
1476 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1477 destpad = gst_element_get_request_pad (dest, destpadname);
1479 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1480 GST_ELEMENT_NAME (dest), destpadname);
1483 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1484 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1485 GST_DEBUG_PAD_NAME (destpad));
1486 gst_object_unref (destpad);
1489 if (GST_PAD_PEER (destpad) != NULL) {
1490 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1491 GST_DEBUG_PAD_NAME (destpad));
1492 gst_object_unref (destpad);
1498 /* no name given, get the first available pad */
1499 GST_OBJECT_LOCK (dest);
1500 destpads = GST_ELEMENT_PADS (dest);
1501 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1503 gst_object_ref (destpad);
1504 GST_OBJECT_UNLOCK (dest);
1507 if (srcpadname && destpadname) {
1510 /* two explicitly specified pads */
1511 result = pad_link_maybe_ghosting (srcpad, destpad);
1513 gst_object_unref (srcpad);
1514 gst_object_unref (destpad);
1520 /* loop through the allowed pads in the source, trying to find a
1521 * compatible destination pad */
1522 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1523 "looping through allowed src and dest pads");
1525 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1526 GST_DEBUG_PAD_NAME (srcpad));
1527 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1528 (GST_PAD_PEER (srcpad) == NULL)) {
1533 gst_object_ref (temp);
1535 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1538 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1539 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1540 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1542 gst_object_unref (destpad);
1543 gst_object_unref (srcpad);
1544 gst_object_unref (temp);
1549 gst_object_unref (temp);
1552 /* find a better way for this mess */
1554 srcpads = g_list_next (srcpads);
1556 gst_object_unref (srcpad);
1557 srcpad = GST_PAD_CAST (srcpads->data);
1558 gst_object_ref (srcpad);
1564 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1565 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1567 gst_object_unref (destpad);
1571 gst_object_unref (srcpad);
1575 /* loop through the existing pads in the destination */
1577 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1578 GST_DEBUG_PAD_NAME (destpad));
1579 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1580 (GST_PAD_PEER (destpad) == NULL)) {
1581 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1583 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1584 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1585 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1586 gst_object_unref (temp);
1587 gst_object_unref (destpad);
1591 gst_object_unref (temp);
1595 destpads = g_list_next (destpads);
1597 gst_object_unref (destpad);
1598 destpad = GST_PAD_CAST (destpads->data);
1599 gst_object_ref (destpad);
1606 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1607 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1608 gst_object_unref (destpad);
1612 gst_object_unref (destpad);
1616 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1617 "we might have request pads on both sides, checking...");
1618 srctempls = gst_element_class_get_pad_template_list (srcclass);
1619 desttempls = gst_element_class_get_pad_template_list (destclass);
1621 if (srctempls && desttempls) {
1623 srctempl = (GstPadTemplate *) srctempls->data;
1624 if (srctempl->presence == GST_PAD_REQUEST) {
1625 for (l = desttempls; l; l = l->next) {
1626 desttempl = (GstPadTemplate *) l->data;
1627 if (desttempl->presence == GST_PAD_REQUEST &&
1628 desttempl->direction != srctempl->direction) {
1629 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1630 (srctempl), gst_pad_template_get_caps (desttempl))) {
1632 gst_element_get_request_pad (src, srctempl->name_template);
1634 gst_element_get_request_pad (dest, desttempl->name_template);
1635 if (srcpad && destpad
1636 && pad_link_maybe_ghosting (srcpad, destpad)) {
1637 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1638 "linked pad %s:%s to pad %s:%s",
1639 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1640 gst_object_unref (srcpad);
1641 gst_object_unref (destpad);
1644 /* it failed, so we release the request pads */
1646 gst_element_release_request_pad (src, srcpad);
1648 gst_element_release_request_pad (dest, destpad);
1653 srctempls = srctempls->next;
1657 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1658 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1663 * gst_element_link_pads_filtered:
1664 * @src: a #GstElement containing the source pad.
1665 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1666 * @dest: the #GstElement containing the destination pad.
1667 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1668 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1670 * Links the two named pads of the source and destination elements. Side effect
1671 * is that if one of the pads has no parent, it becomes a child of the parent of
1672 * the other element. If they have different parents, the link fails. If @caps
1673 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1675 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1678 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1679 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1682 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1683 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1684 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1687 GstElement *capsfilter;
1689 GstState state, pending;
1691 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1693 GST_ERROR ("Could not make a capsfilter");
1697 parent = gst_object_get_parent (GST_OBJECT (src));
1698 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1700 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, 0);
1702 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1703 GST_ERROR ("Could not add capsfilter");
1704 gst_object_unref (capsfilter);
1705 gst_object_unref (parent);
1709 if (pending != GST_STATE_VOID_PENDING)
1712 gst_element_set_state (capsfilter, state);
1714 gst_object_unref (parent);
1716 g_object_set (capsfilter, "caps", filter, NULL);
1718 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1719 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1722 GST_INFO ("Could not link elements");
1723 gst_element_set_state (capsfilter, GST_STATE_NULL);
1724 /* this will unlink and unref as appropriate */
1725 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1729 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1735 * @src: a #GstElement containing the source pad.
1736 * @dest: the #GstElement containing the destination pad.
1738 * Links @src to @dest. The link must be from source to
1739 * destination; the other direction will not be tried. The function looks for
1740 * existing pads that aren't linked yet. It will request new pads if necessary.
1741 * Such pads need to be released manualy when unlinking.
1742 * If multiple links are possible, only one is established.
1744 * Make sure you have added your elements to a bin or pipeline with
1745 * gst_bin_add() before trying to link them.
1747 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1750 gst_element_link (GstElement * src, GstElement * dest)
1752 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1756 * gst_element_link_many:
1757 * @element_1: the first #GstElement in the link chain.
1758 * @element_2: the second #GstElement in the link chain.
1759 * @...: the NULL-terminated list of elements to link in order.
1761 * Chain together a series of elements. Uses gst_element_link().
1762 * Make sure you have added your elements to a bin or pipeline with
1763 * gst_bin_add() before trying to link them.
1765 * Returns: TRUE on success, FALSE otherwise.
1768 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1772 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1773 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1775 va_start (args, element_2);
1778 if (!gst_element_link (element_1, element_2))
1781 element_1 = element_2;
1782 element_2 = va_arg (args, GstElement *);
1791 * gst_element_link_filtered:
1792 * @src: a #GstElement containing the source pad.
1793 * @dest: the #GstElement containing the destination pad.
1794 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1796 * Links @src to @dest using the given caps as filtercaps.
1797 * The link must be from source to
1798 * destination; the other direction will not be tried. The function looks for
1799 * existing pads that aren't linked yet. It will request new pads if necessary.
1800 * If multiple links are possible, only one is established.
1802 * Make sure you have added your elements to a bin or pipeline with
1803 * gst_bin_add() before trying to link them.
1805 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1808 gst_element_link_filtered (GstElement * src, GstElement * dest,
1811 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1815 * gst_element_unlink_pads:
1816 * @src: a #GstElement containing the source pad.
1817 * @srcpadname: the name of the #GstPad in source element.
1818 * @dest: a #GstElement containing the destination pad.
1819 * @destpadname: the name of the #GstPad in destination element.
1821 * Unlinks the two named pads of the source and destination elements.
1824 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1825 GstElement * dest, const gchar * destpadname)
1827 GstPad *srcpad, *destpad;
1828 gboolean srcrequest, destrequest;
1830 srcrequest = destrequest = FALSE;
1832 g_return_if_fail (src != NULL);
1833 g_return_if_fail (GST_IS_ELEMENT (src));
1834 g_return_if_fail (srcpadname != NULL);
1835 g_return_if_fail (dest != NULL);
1836 g_return_if_fail (GST_IS_ELEMENT (dest));
1837 g_return_if_fail (destpadname != NULL);
1839 /* obtain the pads requested */
1840 if (!(srcpad = gst_element_get_static_pad (src, srcpadname)))
1841 if ((srcpad = gst_element_get_request_pad (src, srcpadname)))
1843 if (srcpad == NULL) {
1844 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1847 if (!(destpad = gst_element_get_static_pad (dest, destpadname)))
1848 if ((destpad = gst_element_get_request_pad (dest, destpadname)))
1850 if (destpad == NULL) {
1851 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1856 /* we're satisified they can be unlinked, let's do it */
1857 gst_pad_unlink (srcpad, destpad);
1860 gst_element_release_request_pad (dest, destpad);
1861 gst_object_unref (destpad);
1865 gst_element_release_request_pad (src, srcpad);
1866 gst_object_unref (srcpad);
1870 * gst_element_unlink_many:
1871 * @element_1: the first #GstElement in the link chain.
1872 * @element_2: the second #GstElement in the link chain.
1873 * @...: the NULL-terminated list of elements to unlink in order.
1875 * Unlinks a series of elements. Uses gst_element_unlink().
1878 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1882 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1883 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1885 va_start (args, element_2);
1888 gst_element_unlink (element_1, element_2);
1890 element_1 = element_2;
1891 element_2 = va_arg (args, GstElement *);
1898 * gst_element_unlink:
1899 * @src: the source #GstElement to unlink.
1900 * @dest: the sink #GstElement to unlink.
1902 * Unlinks all source pads of the source element with all sink pads
1903 * of the sink element to which they are linked.
1905 * If the link has been made using gst_element_link(), it could have created an
1906 * requestpad, which has to be released using gst_element_release_request_pad().
1909 gst_element_unlink (GstElement * src, GstElement * dest)
1912 gboolean done = FALSE;
1914 g_return_if_fail (GST_IS_ELEMENT (src));
1915 g_return_if_fail (GST_IS_ELEMENT (dest));
1917 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1918 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1920 pads = gst_element_iterate_pads (src);
1924 switch (gst_iterator_next (pads, &data)) {
1925 case GST_ITERATOR_OK:
1927 GstPad *pad = GST_PAD_CAST (data);
1929 if (GST_PAD_IS_SRC (pad)) {
1930 GstPad *peerpad = gst_pad_get_peer (pad);
1932 /* see if the pad is linked and is really a pad of dest */
1934 GstElement *peerelem;
1936 peerelem = gst_pad_get_parent_element (peerpad);
1938 if (peerelem == dest) {
1939 gst_pad_unlink (pad, peerpad);
1942 gst_object_unref (peerelem);
1944 gst_object_unref (peerpad);
1947 gst_object_unref (pad);
1950 case GST_ITERATOR_RESYNC:
1951 gst_iterator_resync (pads);
1953 case GST_ITERATOR_DONE:
1957 g_assert_not_reached ();
1961 gst_iterator_free (pads);
1965 * gst_element_query_position:
1966 * @element: a #GstElement to invoke the position query on.
1967 * @format: a pointer to the #GstFormat asked for.
1968 * On return contains the #GstFormat used.
1969 * @cur: A location in which to store the current position, or NULL.
1971 * Queries an element for the stream position.
1973 * Returns: TRUE if the query could be performed.
1976 gst_element_query_position (GstElement * element, GstFormat * format,
1982 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1983 g_return_val_if_fail (format != NULL, FALSE);
1985 query = gst_query_new_position (*format);
1986 ret = gst_element_query (element, query);
1989 gst_query_parse_position (query, format, cur);
1991 gst_query_unref (query);
1997 * gst_element_query_duration:
1998 * @element: a #GstElement to invoke the duration query on.
1999 * @format: a pointer to the #GstFormat asked for.
2000 * On return contains the #GstFormat used.
2001 * @duration: A location in which to store the total duration, or NULL.
2003 * Queries an element for the total stream duration.
2005 * Returns: TRUE if the query could be performed.
2008 gst_element_query_duration (GstElement * element, GstFormat * format,
2014 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2015 g_return_val_if_fail (format != NULL, FALSE);
2017 query = gst_query_new_duration (*format);
2018 ret = gst_element_query (element, query);
2021 gst_query_parse_duration (query, format, duration);
2023 gst_query_unref (query);
2029 * gst_element_query_convert:
2030 * @element: a #GstElement to invoke the convert query on.
2031 * @src_format: a #GstFormat to convert from.
2032 * @src_val: a value to convert.
2033 * @dest_format: a pointer to the #GstFormat to convert to.
2034 * @dest_val: a pointer to the result.
2036 * Queries an element to convert @src_val in @src_format to @dest_format.
2038 * Returns: TRUE if the query could be performed.
2041 gst_element_query_convert (GstElement * element, GstFormat src_format,
2042 gint64 src_val, GstFormat * dest_format, gint64 * dest_val)
2047 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2048 g_return_val_if_fail (dest_format != NULL, FALSE);
2049 g_return_val_if_fail (dest_val != NULL, FALSE);
2051 if (*dest_format == src_format) {
2052 *dest_val = src_val;
2056 query = gst_query_new_convert (src_format, src_val, *dest_format);
2057 ret = gst_element_query (element, query);
2060 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2062 gst_query_unref (query);
2068 * gst_element_seek_simple
2069 * @element: a #GstElement to seek on
2070 * @format: a #GstFormat to execute the seek in, such as #GST_FORMAT_TIME
2071 * @seek_flags: seek options; playback applications will usually want to use
2072 * GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here
2073 * @seek_pos: position to seek to (relative to the start); if you are doing
2074 * a seek in #GST_FORMAT_TIME this value is in nanoseconds -
2075 * multiply with #GST_SECOND to convert seconds to nanoseconds or
2076 * with #GST_MSECOND to convert milliseconds to nanoseconds.
2078 * Simple API to perform a seek on the given element, meaning it just seeks
2079 * to the given position relative to the start of the stream. For more complex
2080 * operations like segment seeks (e.g. for looping) or changing the playback
2081 * rate or seeking relative to the last configured playback segment you should
2082 * use gst_element_seek().
2084 * In a completely prerolled PAUSED or PLAYING pipeline, seeking is always
2085 * guaranteed to return %TRUE on a seekable media type or %FALSE when the media
2086 * type is certainly not seekable (such as a live stream).
2088 * Some elements allow for seeking in the READY state, in this
2089 * case they will store the seek event and execute it when they are put to
2090 * PAUSED. If the element supports seek in READY, it will always return %TRUE when
2091 * it receives the event in the READY state.
2093 * Returns: %TRUE if the seek operation succeeded (the seek might not always be
2094 * executed instantly though)
2099 gst_element_seek_simple (GstElement * element, GstFormat format,
2100 GstSeekFlags seek_flags, gint64 seek_pos)
2102 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2103 g_return_val_if_fail (seek_pos >= 0, FALSE);
2105 return gst_element_seek (element, 1.0, format, seek_flags,
2106 GST_SEEK_TYPE_SET, seek_pos, GST_SEEK_TYPE_NONE, 0);
2111 * @srcpad: the source #GstPad to link.
2112 * @sinkpad: the sink #GstPad to link.
2114 * Checks if the source pad and the sink pad can be linked.
2115 * Both @srcpad and @sinkpad must be unlinked.
2117 * Returns: TRUE if the pads can be linked, FALSE otherwise.
2120 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2122 /* FIXME This function is gross. It's almost a direct copy of
2123 * gst_pad_link_filtered(). Any decent programmer would attempt
2124 * to merge the two functions, which I will do some day. --ds
2127 /* generic checks */
2128 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2129 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2131 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2132 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2134 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
2135 if (GST_PAD_PEER (srcpad) != NULL) {
2136 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
2137 GST_DEBUG_PAD_NAME (srcpad));
2140 if (GST_PAD_PEER (sinkpad) != NULL) {
2141 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
2142 GST_DEBUG_PAD_NAME (sinkpad));
2145 if (!GST_PAD_IS_SRC (srcpad)) {
2146 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
2147 GST_DEBUG_PAD_NAME (srcpad));
2150 if (!GST_PAD_IS_SINK (sinkpad)) {
2151 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
2152 GST_DEBUG_PAD_NAME (sinkpad));
2155 if (GST_PAD_PARENT (srcpad) == NULL) {
2156 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
2157 GST_DEBUG_PAD_NAME (srcpad));
2160 if (GST_PAD_PARENT (sinkpad) == NULL) {
2161 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
2162 GST_DEBUG_PAD_NAME (srcpad));
2170 * gst_pad_use_fixed_caps:
2171 * @pad: the pad to use
2173 * A helper function you can use that sets the
2174 * @gst_pad_get_fixed_caps_func as the getcaps function for the
2175 * pad. This way the function will always return the negotiated caps
2176 * or in case the pad is not negotiated, the padtemplate caps.
2178 * Use this function on a pad that, once _set_caps() has been called
2179 * on it, cannot be renegotiated to something else.
2182 gst_pad_use_fixed_caps (GstPad * pad)
2184 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
2188 * gst_pad_get_fixed_caps_func:
2189 * @pad: the pad to use
2191 * A helper function you can use as a GetCaps function that
2192 * will return the currently negotiated caps or the padtemplate
2195 * Returns: The currently negotiated caps or the padtemplate.
2198 gst_pad_get_fixed_caps_func (GstPad * pad)
2202 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2204 GST_OBJECT_LOCK (pad);
2205 if (GST_PAD_CAPS (pad)) {
2206 result = GST_PAD_CAPS (pad);
2208 GST_CAT_DEBUG (GST_CAT_CAPS,
2209 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2211 result = gst_caps_ref (result);
2214 if (GST_PAD_PAD_TEMPLATE (pad)) {
2215 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
2217 result = GST_PAD_TEMPLATE_CAPS (templ);
2218 GST_CAT_DEBUG (GST_CAT_CAPS,
2219 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2222 result = gst_caps_ref (result);
2225 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2226 result = gst_caps_new_empty ();
2229 GST_OBJECT_UNLOCK (pad);
2235 * gst_pad_get_parent_element:
2238 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
2239 * its parent is not an element, return NULL.
2241 * Returns: The parent of the pad. The caller has a reference on the parent, so
2242 * unref when you're finished with it.
2247 gst_pad_get_parent_element (GstPad * pad)
2251 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2253 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
2255 if (p && !GST_IS_ELEMENT (p)) {
2256 gst_object_unref (p);
2259 return GST_ELEMENT_CAST (p);
2263 * gst_object_default_error:
2264 * @source: the #GstObject that initiated the error.
2265 * @error: the GError.
2266 * @debug: an additional debug information string, or NULL.
2268 * A default error function.
2270 * The default handler will simply print the error string using g_print.
2273 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
2275 gchar *name = gst_object_get_path_string (source);
2277 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
2279 g_print (_("Additional debug info:\n%s\n"), debug);
2287 * @element_1: the #GstElement element to add to the bin
2288 * @...: additional elements to add to the bin
2290 * Adds a NULL-terminated list of elements to a bin. This function is
2291 * equivalent to calling gst_bin_add() for each member of the list. The return
2292 * value of each gst_bin_add() is ignored.
2295 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
2299 g_return_if_fail (GST_IS_BIN (bin));
2300 g_return_if_fail (GST_IS_ELEMENT (element_1));
2302 va_start (args, element_1);
2305 gst_bin_add (bin, element_1);
2307 element_1 = va_arg (args, GstElement *);
2314 * gst_bin_remove_many:
2316 * @element_1: the first #GstElement to remove from the bin
2317 * @...: NULL-terminated list of elements to remove from the bin
2319 * Remove a list of elements from a bin. This function is equivalent
2320 * to calling gst_bin_remove() with each member of the list.
2323 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
2327 g_return_if_fail (GST_IS_BIN (bin));
2328 g_return_if_fail (GST_IS_ELEMENT (element_1));
2330 va_start (args, element_1);
2333 gst_bin_remove (bin, element_1);
2335 element_1 = va_arg (args, GstElement *);
2342 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2343 guint arg_id, GParamFlags flags)
2345 GQuark prop_id = g_quark_from_string (prop_name);
2348 static GQuark fd_id = 0;
2349 static GQuark blocksize_id;
2350 static GQuark bytesperread_id;
2351 static GQuark dump_id;
2352 static GQuark filesize_id;
2353 static GQuark mmapsize_id;
2354 static GQuark location_id;
2355 static GQuark offset_id;
2356 static GQuark silent_id;
2357 static GQuark touch_id;
2360 fd_id = g_quark_from_static_string ("fd");
2361 blocksize_id = g_quark_from_static_string ("blocksize");
2362 bytesperread_id = g_quark_from_static_string ("bytesperread");
2363 dump_id = g_quark_from_static_string ("dump");
2364 filesize_id = g_quark_from_static_string ("filesize");
2365 mmapsize_id = g_quark_from_static_string ("mmapsize");
2366 location_id = g_quark_from_static_string ("location");
2367 offset_id = g_quark_from_static_string ("offset");
2368 silent_id = g_quark_from_static_string ("silent");
2369 touch_id = g_quark_from_static_string ("touch");
2372 if (prop_id == fd_id) {
2373 pspec = g_param_spec_int ("fd", "File-descriptor",
2374 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2375 } else if (prop_id == blocksize_id) {
2376 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2377 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2379 } else if (prop_id == bytesperread_id) {
2380 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2381 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2383 } else if (prop_id == dump_id) {
2384 pspec = g_param_spec_boolean ("dump", "Dump",
2385 "Dump bytes to stdout", FALSE, flags);
2387 } else if (prop_id == filesize_id) {
2388 pspec = g_param_spec_int64 ("filesize", "File Size",
2389 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2391 } else if (prop_id == mmapsize_id) {
2392 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2393 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2395 } else if (prop_id == location_id) {
2396 pspec = g_param_spec_string ("location", "File Location",
2397 "Location of the file to read", NULL, flags);
2399 } else if (prop_id == offset_id) {
2400 pspec = g_param_spec_int64 ("offset", "File Offset",
2401 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2403 } else if (prop_id == silent_id) {
2404 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2407 } else if (prop_id == touch_id) {
2408 pspec = g_param_spec_boolean ("touch", "Touch read data",
2409 "Touch data to force disk read before " "push ()", TRUE, flags);
2411 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2412 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2417 g_object_class_install_property (klass, arg_id, pspec);
2422 * gst_element_class_install_std_props:
2423 * @klass: the #GstElementClass to add the properties to.
2424 * @first_name: the name of the first property.
2425 * in a NULL terminated
2426 * @...: the id and flags of the first property, followed by
2427 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2429 * Adds a list of standardized properties with types to the @klass.
2430 * the id is for the property switch in your get_prop method, and
2431 * the flags determine readability / writeability.
2434 gst_element_class_install_std_props (GstElementClass * klass,
2435 const gchar * first_name, ...)
2441 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2443 va_start (args, first_name);
2448 int arg_id = va_arg (args, int);
2449 int flags = va_arg (args, int);
2451 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2454 name = va_arg (args, char *);
2463 * @buf1: the first source #GstBuffer to merge.
2464 * @buf2: the second source #GstBuffer to merge.
2466 * Create a new buffer that is the concatenation of the two source
2467 * buffers. The original source buffers will not be modified or
2468 * unref'd. Make sure you unref the source buffers if they are not used
2469 * anymore afterwards.
2471 * If the buffers point to contiguous areas of memory, the buffer
2472 * is created without copying the data.
2474 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2477 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2481 /* we're just a specific case of the more general gst_buffer_span() */
2482 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2489 * @buf1: the first source #GstBuffer.
2490 * @buf2: the second source #GstBuffer.
2492 * Create a new buffer that is the concatenation of the two source
2493 * buffers, and unrefs the original source buffers.
2495 * If the buffers point to contiguous areas of memory, the buffer
2496 * is created without copying the data.
2498 * This is a convenience function for C programmers. See also
2499 * gst_buffer_merge(), which does the same thing without
2500 * unreffing the input parameters. Language bindings without
2501 * explicit reference counting should not wrap this function.
2503 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2506 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2510 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2511 gst_buffer_unref (buf1);
2512 gst_buffer_unref (buf2);
2520 * @dest: buffer to stamp
2521 * @src: buffer to stamp from
2523 * Copies additional information (the timestamp, duration, and offset start
2524 * and end) from one buffer to the other.
2526 * This function does not copy any buffer flags or caps and is equivalent to
2527 * gst_buffer_copy_metadata(@dest, @src, GST_BUFFER_COPY_TIMESTAMPS).
2529 * Deprecated: use gst_buffer_copy_metadata() instead, it provides more
2532 #ifndef GST_REMOVE_DEPRECATED
2534 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2536 gst_buffer_copy_metadata (dest, src, GST_BUFFER_COPY_TIMESTAMPS);
2538 #endif /* GST_REMOVE_DEPRECATED */
2541 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2543 /* skip the pad, the request came from */
2545 GstCaps *peercaps, *existing;
2547 existing = g_value_get_pointer (ret);
2548 peercaps = gst_pad_peer_get_caps (pad);
2549 if (peercaps == NULL)
2550 peercaps = gst_caps_new_any ();
2551 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2552 gst_caps_unref (existing);
2553 gst_caps_unref (peercaps);
2555 gst_object_unref (pad);
2560 * gst_pad_proxy_getcaps:
2561 * @pad: a #GstPad to proxy.
2563 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2564 * same element as @pad, and returns the intersection of the results.
2566 * This function is useful as a default getcaps function for an element
2567 * that can handle any stream format, but requires all its pads to have
2568 * the same caps. Two such elements are tee and aggregator.
2570 * Returns: the intersection of the other pads' allowed caps.
2573 gst_pad_proxy_getcaps (GstPad * pad)
2575 GstElement *element;
2576 GstCaps *caps, *intersected;
2578 GstIteratorResult res;
2579 GValue ret = { 0, };
2581 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2583 GST_CAT_DEBUG (GST_CAT_PADS, "proxying getcaps for %s:%s",
2584 GST_DEBUG_PAD_NAME (pad));
2586 element = gst_pad_get_parent_element (pad);
2587 if (element == NULL)
2590 /* value to hold the return, by default it holds ANY, the ref is taken by
2592 g_value_init (&ret, G_TYPE_POINTER);
2593 g_value_set_pointer (&ret, gst_caps_new_any ());
2595 iter = gst_element_iterate_pads (element);
2598 gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2601 case GST_ITERATOR_RESYNC:
2602 /* unref any value stored */
2603 if ((caps = g_value_get_pointer (&ret)))
2604 gst_caps_unref (caps);
2605 /* need to reset the result again to ANY */
2606 g_value_set_pointer (&ret, gst_caps_new_any ());
2607 gst_iterator_resync (iter);
2609 case GST_ITERATOR_DONE:
2610 /* all pads iterated, return collected value */
2613 /* iterator returned _ERROR or premature end with _OK,
2614 * mark an error and exit */
2615 if ((caps = g_value_get_pointer (&ret)))
2616 gst_caps_unref (caps);
2617 g_value_set_pointer (&ret, NULL);
2622 gst_iterator_free (iter);
2624 gst_object_unref (element);
2626 caps = g_value_get_pointer (&ret);
2627 g_value_unset (&ret);
2629 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2630 gst_caps_unref (caps);
2637 g_warning ("Pad list returned error on element %s",
2638 GST_ELEMENT_NAME (element));
2639 gst_iterator_free (iter);
2640 gst_object_unref (element);
2652 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2654 gboolean success = TRUE;
2656 if (pad != data->orig) {
2657 success = gst_pad_set_caps (pad, data->caps);
2658 g_value_set_boolean (ret, success);
2660 gst_object_unref (pad);
2666 * gst_pad_proxy_setcaps
2667 * @pad: a #GstPad to proxy from
2668 * @caps: the #GstCaps to link with
2670 * Calls gst_pad_set_caps() for every other pad belonging to the
2671 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2672 * the proxy setcaps fails. May be used only during negotiation.
2674 * Returns: TRUE if sucessful
2677 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2679 GstElement *element;
2681 GstIteratorResult res;
2682 GValue ret = { 0, };
2685 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2686 g_return_val_if_fail (caps != NULL, FALSE);
2688 GST_CAT_DEBUG (GST_CAT_PADS, "proxying pad link for %s:%s",
2689 GST_DEBUG_PAD_NAME (pad));
2691 element = gst_pad_get_parent_element (pad);
2692 if (element == NULL)
2695 iter = gst_element_iterate_pads (element);
2697 g_value_init (&ret, G_TYPE_BOOLEAN);
2698 g_value_set_boolean (&ret, TRUE);
2702 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2704 gst_iterator_free (iter);
2706 if (res != GST_ITERATOR_DONE)
2709 gst_object_unref (element);
2711 /* ok not to unset the gvalue */
2712 return g_value_get_boolean (&ret);
2717 g_warning ("Pad list changed during proxy_pad_link for element %s",
2718 GST_ELEMENT_NAME (element));
2719 gst_object_unref (element);
2725 * gst_pad_query_position:
2726 * @pad: a #GstPad to invoke the position query on.
2727 * @format: a pointer to the #GstFormat asked for.
2728 * On return contains the #GstFormat used.
2729 * @cur: A location in which to store the current position, or NULL.
2731 * Queries a pad for the stream position.
2733 * Returns: TRUE if the query could be performed.
2736 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur)
2741 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2742 g_return_val_if_fail (format != NULL, FALSE);
2744 query = gst_query_new_position (*format);
2745 ret = gst_pad_query (pad, query);
2748 gst_query_parse_position (query, format, cur);
2750 gst_query_unref (query);
2756 * gst_pad_query_peer_position:
2757 * @pad: a #GstPad on whose peer to invoke the position query on.
2758 * Must be a sink pad.
2759 * @format: a pointer to the #GstFormat asked for.
2760 * On return contains the #GstFormat used.
2761 * @cur: A location in which to store the current position, or NULL.
2763 * Queries the peer of a given sink pad for the stream position.
2765 * Returns: TRUE if the query could be performed.
2768 gst_pad_query_peer_position (GstPad * pad, GstFormat * format, gint64 * cur)
2770 gboolean ret = FALSE;
2773 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2774 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2775 g_return_val_if_fail (format != NULL, FALSE);
2777 peer = gst_pad_get_peer (pad);
2779 ret = gst_pad_query_position (peer, format, cur);
2780 gst_object_unref (peer);
2787 * gst_pad_query_duration:
2788 * @pad: a #GstPad to invoke the duration query on.
2789 * @format: a pointer to the #GstFormat asked for.
2790 * On return contains the #GstFormat used.
2791 * @duration: A location in which to store the total duration, or NULL.
2793 * Queries a pad for the total stream duration.
2795 * Returns: TRUE if the query could be performed.
2798 gst_pad_query_duration (GstPad * pad, GstFormat * format, gint64 * duration)
2803 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2804 g_return_val_if_fail (format != NULL, FALSE);
2806 query = gst_query_new_duration (*format);
2807 ret = gst_pad_query (pad, query);
2810 gst_query_parse_duration (query, format, duration);
2812 gst_query_unref (query);
2818 * gst_pad_query_peer_duration:
2819 * @pad: a #GstPad on whose peer pad to invoke the duration query on.
2820 * Must be a sink pad.
2821 * @format: a pointer to the #GstFormat asked for.
2822 * On return contains the #GstFormat used.
2823 * @duration: A location in which to store the total duration, or NULL.
2825 * Queries the peer pad of a given sink pad for the total stream duration.
2827 * Returns: TRUE if the query could be performed.
2830 gst_pad_query_peer_duration (GstPad * pad, GstFormat * format,
2833 gboolean ret = FALSE;
2836 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2837 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2838 g_return_val_if_fail (format != NULL, FALSE);
2840 peer = gst_pad_get_peer (pad);
2842 ret = gst_pad_query_duration (peer, format, duration);
2843 gst_object_unref (peer);
2850 * gst_pad_query_convert:
2851 * @pad: a #GstPad to invoke the convert query on.
2852 * @src_format: a #GstFormat to convert from.
2853 * @src_val: a value to convert.
2854 * @dest_format: a pointer to the #GstFormat to convert to.
2855 * @dest_val: a pointer to the result.
2857 * Queries a pad to convert @src_val in @src_format to @dest_format.
2859 * Returns: TRUE if the query could be performed.
2862 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2863 GstFormat * dest_format, gint64 * dest_val)
2868 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2869 g_return_val_if_fail (dest_format != NULL, FALSE);
2870 g_return_val_if_fail (dest_val != NULL, FALSE);
2872 if (*dest_format == src_format) {
2873 *dest_val = src_val;
2877 query = gst_query_new_convert (src_format, src_val, *dest_format);
2878 ret = gst_pad_query (pad, query);
2881 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2883 gst_query_unref (query);
2889 * gst_pad_query_peer_convert:
2890 * @pad: a #GstPad, on whose peer pad to invoke the convert query on.
2891 * Must be a sink pad.
2892 * @src_format: a #GstFormat to convert from.
2893 * @src_val: a value to convert.
2894 * @dest_format: a pointer to the #GstFormat to convert to.
2895 * @dest_val: a pointer to the result.
2897 * Queries the peer pad of a given sink pad to convert @src_val in @src_format
2900 * Returns: TRUE if the query could be performed.
2903 gst_pad_query_peer_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2904 GstFormat * dest_format, gint64 * dest_val)
2906 gboolean ret = FALSE;
2909 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2910 g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
2911 g_return_val_if_fail (src_val >= 0, FALSE);
2912 g_return_val_if_fail (dest_format != NULL, FALSE);
2913 g_return_val_if_fail (dest_val != NULL, FALSE);
2915 peer = gst_pad_get_peer (pad);
2917 ret = gst_pad_query_convert (peer, src_format, src_val, dest_format,
2919 gst_object_unref (peer);
2926 * gst_atomic_int_set:
2927 * @atomic_int: pointer to an atomic integer
2928 * @value: value to set
2930 * Unconditionally sets the atomic integer to @value.
2932 * Deprecated: Use g_atomic_int_set().
2935 #ifndef GST_REMOVE_DEPRECATED
2937 gst_atomic_int_set (gint * atomic_int, gint value)
2939 g_atomic_int_set (atomic_int, value);
2944 * gst_pad_add_data_probe:
2945 * @pad: pad to add the data probe handler to
2946 * @handler: function to call when data is passed over pad
2947 * @data: data to pass along with the handler
2949 * Adds a "data probe" to a pad. This function will be called whenever data
2950 * passes through a pad. In this case data means both events and buffers. The
2951 * probe will be called with the data as an argument, meaning @handler should
2952 * have the same callback signature as the #GstPad::have-data signal.
2953 * Note that the data will have a reference count greater than 1, so it will
2954 * be immutable -- you must not change it.
2956 * For source pads, the probe will be called after the blocking function, if any
2957 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2958 * to. For sink pads, the probe function will be called before configuring the
2959 * sink with new caps, if any, and before calling the pad's chain function.
2961 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2962 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2965 * Although probes are implemented internally by connecting @handler to the
2966 * have-data signal on the pad, if you want to remove a probe it is insufficient
2967 * to only call g_signal_handler_disconnect on the returned handler id. To
2968 * remove a probe, use the appropriate function, such as
2969 * gst_pad_remove_data_probe().
2971 * Returns: The handler id.
2974 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2976 return gst_pad_add_data_probe_full (pad, handler, data, NULL);
2980 * gst_pad_add_data_probe_full:
2981 * @pad: pad to add the data probe handler to
2982 * @handler: function to call when data is passed over pad
2983 * @data: data to pass along with the handler
2984 * @notify: function to call when the probe is disconnected, or NULL
2986 * Adds a "data probe" to a pad. This function will be called whenever data
2987 * passes through a pad. In this case data means both events and buffers. The
2988 * probe will be called with the data as an argument, meaning @handler should
2989 * have the same callback signature as the #GstPad::have-data signal.
2990 * Note that the data will have a reference count greater than 1, so it will
2991 * be immutable -- you must not change it.
2993 * For source pads, the probe will be called after the blocking function, if any
2994 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2995 * to. For sink pads, the probe function will be called before configuring the
2996 * sink with new caps, if any, and before calling the pad's chain function.
2998 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2999 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
3002 * Although probes are implemented internally by connecting @handler to the
3003 * have-data signal on the pad, if you want to remove a probe it is insufficient
3004 * to only call g_signal_handler_disconnect on the returned handler id. To
3005 * remove a probe, use the appropriate function, such as
3006 * gst_pad_remove_data_probe().
3008 * The @notify function is called when the probe is disconnected and usually
3009 * used to free @data.
3011 * Returns: The handler id.
3016 gst_pad_add_data_probe_full (GstPad * pad, GCallback handler,
3017 gpointer data, GDestroyNotify notify)
3021 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3022 g_return_val_if_fail (handler != NULL, 0);
3024 GST_OBJECT_LOCK (pad);
3026 /* we only expose a GDestroyNotify in our API because that's less confusing */
3027 sigid = g_signal_connect_data (pad, "have-data", handler, data,
3028 (GClosureNotify) notify, 0);
3030 GST_PAD_DO_EVENT_SIGNALS (pad)++;
3031 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
3032 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3033 "adding data probe, now %d data, %d event probes",
3034 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
3035 GST_OBJECT_UNLOCK (pad);
3041 * gst_pad_add_event_probe:
3042 * @pad: pad to add the event probe handler to
3043 * @handler: function to call when events are passed over pad
3044 * @data: data to pass along with the handler
3046 * Adds a probe that will be called for all events passing through a pad. See
3047 * gst_pad_add_data_probe() for more information.
3049 * Returns: The handler id
3052 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
3054 return gst_pad_add_event_probe_full (pad, handler, data, NULL);
3058 * gst_pad_add_event_probe_full:
3059 * @pad: pad to add the event probe handler to
3060 * @handler: function to call when events are passed over pad
3061 * @data: data to pass along with the handler, or NULL
3062 * @notify: function to call when probe is disconnected, or NULL
3064 * Adds a probe that will be called for all events passing through a pad. See
3065 * gst_pad_add_data_probe() for more information.
3067 * The @notify function is called when the probe is disconnected and usually
3068 * used to free @data.
3070 * Returns: The handler id
3075 gst_pad_add_event_probe_full (GstPad * pad, GCallback handler,
3076 gpointer data, GDestroyNotify notify)
3080 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3081 g_return_val_if_fail (handler != NULL, 0);
3083 GST_OBJECT_LOCK (pad);
3085 /* we only expose a GDestroyNotify in our API because that's less confusing */
3086 sigid = g_signal_connect_data (pad, "have-data::event", handler, data,
3087 (GClosureNotify) notify, 0);
3089 GST_PAD_DO_EVENT_SIGNALS (pad)++;
3090 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding event probe, now %d probes",
3091 GST_PAD_DO_EVENT_SIGNALS (pad));
3092 GST_OBJECT_UNLOCK (pad);
3098 * gst_pad_add_buffer_probe:
3099 * @pad: pad to add the buffer probe handler to
3100 * @handler: function to call when buffers are passed over pad
3101 * @data: data to pass along with the handler
3103 * Adds a probe that will be called for all buffers passing through a pad. See
3104 * gst_pad_add_data_probe() for more information.
3106 * Returns: The handler id
3109 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
3111 return gst_pad_add_buffer_probe_full (pad, handler, data, NULL);
3115 * gst_pad_add_buffer_probe_full:
3116 * @pad: pad to add the buffer probe handler to
3117 * @handler: function to call when buffer are passed over pad
3118 * @data: data to pass along with the handler
3119 * @notify: function to call when the probe is disconnected, or NULL
3121 * Adds a probe that will be called for all buffers passing through a pad. See
3122 * gst_pad_add_data_probe() for more information.
3124 * The @notify function is called when the probe is disconnected and usually
3125 * used to free @data.
3127 * Returns: The handler id
3132 gst_pad_add_buffer_probe_full (GstPad * pad, GCallback handler,
3133 gpointer data, GDestroyNotify notify)
3137 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3138 g_return_val_if_fail (handler != NULL, 0);
3140 GST_OBJECT_LOCK (pad);
3142 /* we only expose a GDestroyNotify in our API because that's less confusing */
3143 sigid = g_signal_connect_data (pad, "have-data::buffer", handler, data,
3144 (GClosureNotify) notify, 0);
3146 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
3147 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding buffer probe, now %d probes",
3148 GST_PAD_DO_BUFFER_SIGNALS (pad));
3149 GST_OBJECT_UNLOCK (pad);
3155 * gst_pad_remove_data_probe:
3156 * @pad: pad to remove the data probe handler from
3157 * @handler_id: handler id returned from gst_pad_add_data_probe
3159 * Removes a data probe from @pad.
3162 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
3164 g_return_if_fail (GST_IS_PAD (pad));
3165 g_return_if_fail (handler_id > 0);
3167 GST_OBJECT_LOCK (pad);
3168 g_signal_handler_disconnect (pad, handler_id);
3169 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3170 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3171 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3172 "removed data probe, now %d event, %d buffer probes",
3173 GST_PAD_DO_EVENT_SIGNALS (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
3174 GST_OBJECT_UNLOCK (pad);
3179 * gst_pad_remove_event_probe:
3180 * @pad: pad to remove the event probe handler from
3181 * @handler_id: handler id returned from gst_pad_add_event_probe
3183 * Removes an event probe from @pad.
3186 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
3188 g_return_if_fail (GST_IS_PAD (pad));
3189 g_return_if_fail (handler_id > 0);
3191 GST_OBJECT_LOCK (pad);
3192 g_signal_handler_disconnect (pad, handler_id);
3193 GST_PAD_DO_EVENT_SIGNALS (pad)--;
3194 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3195 "removed event probe, now %d event probes",
3196 GST_PAD_DO_EVENT_SIGNALS (pad));
3197 GST_OBJECT_UNLOCK (pad);
3201 * gst_pad_remove_buffer_probe:
3202 * @pad: pad to remove the buffer probe handler from
3203 * @handler_id: handler id returned from gst_pad_add_buffer_probe
3205 * Removes a buffer probe from @pad.
3208 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
3210 g_return_if_fail (GST_IS_PAD (pad));
3211 g_return_if_fail (handler_id > 0);
3213 GST_OBJECT_LOCK (pad);
3214 g_signal_handler_disconnect (pad, handler_id);
3215 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
3216 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3217 "removed buffer probe, now %d buffer probes",
3218 GST_PAD_DO_BUFFER_SIGNALS (pad));
3219 GST_OBJECT_UNLOCK (pad);
3224 * gst_element_found_tags_for_pad:
3225 * @element: element for which to post taglist to bus.
3226 * @pad: pad on which to push tag-event.
3227 * @list: the taglist to post on the bus and create event from.
3229 * Posts a message to the bus that new tags were found and pushes the
3230 * tags as event. Takes ownership of the @list.
3232 * This is a utility method for elements. Applications should use the
3233 * #GstTagSetter interface.
3236 gst_element_found_tags_for_pad (GstElement * element,
3237 GstPad * pad, GstTagList * list)
3239 g_return_if_fail (element != NULL);
3240 g_return_if_fail (pad != NULL);
3241 g_return_if_fail (list != NULL);
3243 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
3244 /* FIXME 0.11: Set the pad as source to make it possible to detect for
3245 * which pad the tags are actually found.
3247 gst_element_post_message (element,
3248 gst_message_new_tag (GST_OBJECT (element), list));
3252 push_and_ref (GstPad * pad, GstEvent * event)
3254 gst_pad_push_event (pad, gst_event_ref (event));
3255 /* iterator refs pad, we unref when we are done with it */
3256 gst_object_unref (pad);
3260 * gst_element_found_tags:
3261 * @element: element for which we found the tags.
3262 * @list: list of tags.
3264 * Posts a message to the bus that new tags were found, and pushes an event
3265 * to all sourcepads. Takes ownership of the @list.
3267 * This is a utility method for elements. Applications should use the
3268 * #GstTagSetter interface.
3271 gst_element_found_tags (GstElement * element, GstTagList * list)
3276 g_return_if_fail (element != NULL);
3277 g_return_if_fail (list != NULL);
3279 iter = gst_element_iterate_src_pads (element);
3280 event = gst_event_new_tag (gst_tag_list_copy (list));
3281 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
3282 gst_iterator_free (iter);
3283 gst_event_unref (event);
3285 gst_element_post_message (element,
3286 gst_message_new_tag (GST_OBJECT (element), list));
3290 element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
3293 GstPad *unlinked_pad = NULL;
3296 switch (direction) {
3298 iter = gst_element_iterate_src_pads (element);
3301 iter = gst_element_iterate_sink_pads (element);
3304 g_return_val_if_reached (NULL);
3311 switch (gst_iterator_next (iter, &pad)) {
3312 case GST_ITERATOR_OK:{
3315 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
3316 GST_DEBUG_PAD_NAME (pad));
3318 peer = gst_pad_get_peer (GST_PAD (pad));
3322 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
3323 "found existing unlinked pad %s:%s",
3324 GST_DEBUG_PAD_NAME (unlinked_pad));
3326 gst_object_unref (pad);
3327 gst_object_unref (peer);
3331 case GST_ITERATOR_DONE:
3334 case GST_ITERATOR_RESYNC:
3335 gst_iterator_resync (iter);
3337 case GST_ITERATOR_ERROR:
3338 g_return_val_if_reached (NULL);
3343 gst_iterator_free (iter);
3345 return unlinked_pad;
3349 * gst_bin_find_unlinked_pad:
3350 * @bin: bin in which to look for elements with unlinked pads
3351 * @direction: whether to look for an unlinked source or sink pad
3353 * Recursively looks for elements with an unlinked pad of the given
3354 * direction within the specified bin and returns an unlinked pad
3355 * if one is found, or NULL otherwise. If a pad is found, the caller
3356 * owns a reference to it and should use gst_object_unref() on the
3357 * pad when it is not needed any longer.
3359 * Returns: unlinked pad of the given direction, or NULL.
3364 gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
3370 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
3371 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
3374 iter = gst_bin_iterate_recurse (bin);
3378 switch (gst_iterator_next (iter, &element)) {
3379 case GST_ITERATOR_OK:
3380 pad = element_find_unlinked_pad (GST_ELEMENT (element), direction);
3381 gst_object_unref (element);
3385 case GST_ITERATOR_DONE:
3388 case GST_ITERATOR_RESYNC:
3389 gst_iterator_resync (iter);
3391 case GST_ITERATOR_ERROR:
3392 g_return_val_if_reached (NULL);
3397 gst_iterator_free (iter);
3403 * gst_bin_find_unconnected_pad:
3404 * @bin: bin in which to look for elements with unlinked pads
3405 * @direction: whether to look for an unlinked source or sink pad
3407 * Recursively looks for elements with an unlinked pad of the given
3408 * direction within the specified bin and returns an unlinked pad
3409 * if one is found, or NULL otherwise. If a pad is found, the caller
3410 * owns a reference to it and should use gst_object_unref() on the
3411 * pad when it is not needed any longer.
3413 * Returns: unlinked pad of the given direction, or NULL.
3417 * Deprecated: use gst_bin_find_unlinked_pad() instead.
3419 #ifndef GST_REMOVE_DEPRECATED
3421 gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction)
3423 return gst_bin_find_unlinked_pad (bin, direction);
3428 * gst_parse_bin_from_description:
3429 * @bin_description: command line describing the bin
3430 * @ghost_unlinked_pads: whether to automatically create ghost pads
3431 * for unlinked source or sink pads within the bin
3432 * @err: where to store the error message in case of an error, or NULL
3434 * This is a convenience wrapper around gst_parse_launch() to create a
3435 * #GstBin from a gst-launch-style pipeline description. See
3436 * gst_parse_launch() and the gst-launch man page for details about the
3437 * syntax. Ghost pads on the bin for unlinked source or sink pads
3438 * within the bin can automatically be created (but only a maximum of
3439 * one ghost pad for each direction will be created; if you expect
3440 * multiple unlinked source pads or multiple unlinked sink pads
3441 * and want them all ghosted, you will have to create the ghost pads
3444 * Returns: a newly-created bin, or NULL if an error occurred.
3449 gst_parse_bin_from_description (const gchar * bin_description,
3450 gboolean ghost_unlinked_pads, GError ** err)
3452 return gst_parse_bin_from_description_full (bin_description,
3453 ghost_unlinked_pads, NULL, 0, err);
3457 * gst_parse_bin_from_description_full:
3458 * @bin_description: command line describing the bin
3459 * @ghost_unlinked_pads: whether to automatically create ghost pads
3460 * for unlinked source or sink pads within the bin
3461 * @context: a parse context allocated with gst_parse_context_new(), or %NULL
3462 * @flags: parsing options, or #GST_PARSE_FLAG_NONE
3463 * @err: where to store the error message in case of an error, or NULL
3465 * This is a convenience wrapper around gst_parse_launch() to create a
3466 * #GstBin from a gst-launch-style pipeline description. See
3467 * gst_parse_launch() and the gst-launch man page for details about the
3468 * syntax. Ghost pads on the bin for unlinked source or sink pads
3469 * within the bin can automatically be created (but only a maximum of
3470 * one ghost pad for each direction will be created; if you expect
3471 * multiple unlinked source pads or multiple unlinked sink pads
3472 * and want them all ghosted, you will have to create the ghost pads
3475 * Returns: a newly-created bin, or NULL if an error occurred.
3480 gst_parse_bin_from_description_full (const gchar * bin_description,
3481 gboolean ghost_unlinked_pads, GstParseContext * context,
3482 GstParseFlags flags, GError ** err)
3484 #ifndef GST_DISABLE_PARSE
3489 g_return_val_if_fail (bin_description != NULL, NULL);
3490 g_return_val_if_fail (err == NULL || *err == NULL, NULL);
3492 GST_DEBUG ("Making bin from description '%s'", bin_description);
3494 /* parse the pipeline to a bin */
3495 desc = g_strdup_printf ("bin.( %s )", bin_description);
3496 bin = (GstBin *) gst_parse_launch_full (desc, context, flags, err);
3499 if (bin == NULL || (err && *err != NULL)) {
3501 gst_object_unref (bin);
3505 /* find pads and ghost them if necessary */
3506 if (ghost_unlinked_pads) {
3507 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC))) {
3508 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("src", pad));
3509 gst_object_unref (pad);
3511 if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SINK))) {
3512 gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("sink", pad));
3513 gst_object_unref (pad);
3517 return GST_ELEMENT (bin);
3521 GST_WARNING ("Disabled API called");
3523 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED);
3524 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg);
3532 * gst_type_register_static_full:
3533 * @parent_type: The GType of the parent type the newly registered type will
3535 * @type_name: NULL-terminated string used as the name of the new type
3536 * @class_size: Size of the class structure.
3537 * @base_init: Location of the base initialization function (optional).
3538 * @base_finalize: Location of the base finalization function (optional).
3539 * @class_init: Location of the class initialization function for class types
3540 * Location of the default vtable inititalization function for interface
3542 * @class_finalize: Location of the class finalization function for class types.
3543 * Location of the default vtable finalization function for interface types.
3545 * @class_data: User-supplied data passed to the class init/finalize functions.
3546 * @instance_size: Size of the instance (object) structure (required for
3547 * instantiatable types only).
3548 * @n_preallocs: The number of pre-allocated (cached) instances to reserve
3549 * memory for (0 indicates no caching). Ignored on recent GLib's.
3550 * @instance_init: Location of the instance initialization function (optional,
3551 * for instantiatable types only).
3552 * @value_table: A GTypeValueTable function table for generic handling of
3553 * GValues of this type (usually only useful for fundamental types).
3554 * @flags: #GTypeFlags for this GType. E.g: G_TYPE_FLAG_ABSTRACT
3556 * Helper function which constructs a #GTypeInfo structure and registers a
3557 * GType, but which generates less linker overhead than a static const
3558 * #GTypeInfo structure. For further details of the parameters, please see
3559 * #GTypeInfo in the GLib documentation.
3561 * Registers type_name as the name of a new static type derived from
3562 * parent_type. The value of flags determines the nature (e.g. abstract or
3563 * not) of the type. It works by filling a GTypeInfo struct and calling
3564 * g_type_info_register_static().
3566 * Returns: A #GType for the newly-registered type.
3571 gst_type_register_static_full (GType parent_type,
3572 const gchar * type_name,
3574 GBaseInitFunc base_init,
3575 GBaseFinalizeFunc base_finalize,
3576 GClassInitFunc class_init,
3577 GClassFinalizeFunc class_finalize,
3578 gconstpointer class_data,
3579 guint instance_size,
3580 guint16 n_preallocs,
3581 GInstanceInitFunc instance_init,
3582 const GTypeValueTable * value_table, GTypeFlags flags)
3586 info.class_size = class_size;
3587 info.base_init = base_init;
3588 info.base_finalize = base_finalize;
3589 info.class_init = class_init;
3590 info.class_finalize = class_finalize;
3591 info.class_data = class_data;
3592 info.instance_size = instance_size;
3593 info.n_preallocs = n_preallocs;
3594 info.instance_init = instance_init;
3595 info.value_table = value_table;
3597 return g_type_register_static (parent_type, type_name, &info, flags);
3602 * gst_util_get_timestamp:
3604 * Get a timestamp as GstClockTime to be used for interval meassurements.
3605 * The timestamp should not be interpreted in any other way.
3607 * Returns: the timestamp
3612 gst_util_get_timestamp (void)
3614 #if defined (HAVE_POSIX_TIMERS) && defined(HAVE_MONOTONIC_CLOCK)
3615 struct timespec now;
3617 clock_gettime (CLOCK_MONOTONIC, &now);
3618 return GST_TIMESPEC_TO_TIME (now);
3622 g_get_current_time (&now);
3623 return GST_TIMEVAL_TO_TIME (now);