2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstutils.c: Utility functions: gtk_get_property stuff, etc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Various utility functions
27 * When defining own plugins, use the GST_BOILERPLATE ease gobject creation.
33 #include "gst_private.h"
34 #include "gstghostpad.h"
37 #include "gst-i18n-lib.h"
42 * @mem: a pointer to the memory to dump
43 * @size: the size of the memory block to dump
45 * Dumps the memory block into a hex representation. Useful for debugging.
48 gst_util_dump_mem (const guchar * mem, guint size)
51 GString *string = g_string_sized_new (50);
52 GString *chars = g_string_sized_new (18);
56 if (g_ascii_isprint (mem[i]))
57 g_string_append_printf (chars, "%c", mem[i]);
59 g_string_append_printf (chars, ".");
61 g_string_append_printf (string, "%02x ", mem[i]);
66 if (j == 16 || i == size) {
67 g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
68 string->str, chars->str);
69 g_string_set_size (string, 0);
70 g_string_set_size (chars, 0);
74 g_string_free (string, TRUE);
75 g_string_free (chars, TRUE);
80 * gst_util_set_value_from_string:
81 * @value: the value to set
82 * @value_str: the string to get the value from
84 * Converts the string to the type of the value and
85 * sets the value with it.
88 gst_util_set_value_from_string (GValue * value, const gchar * value_str)
92 g_return_if_fail (value != NULL);
93 g_return_if_fail (value_str != NULL);
95 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
96 g_type_name (G_VALUE_TYPE (value)));
98 switch (G_VALUE_TYPE (value)) {
100 g_value_set_string (value, g_strdup (value_str));
106 sscanf_ret = sscanf (value_str, "%d", &i);
107 g_return_if_fail (sscanf_ret == 1);
108 g_value_set_int (value, i);
114 sscanf_ret = sscanf (value_str, "%u", &i);
115 g_return_if_fail (sscanf_ret == 1);
116 g_value_set_uint (value, i);
122 sscanf_ret = sscanf (value_str, "%ld", &i);
123 g_return_if_fail (sscanf_ret == 1);
124 g_value_set_long (value, i);
130 sscanf_ret = sscanf (value_str, "%lu", &i);
131 g_return_if_fail (sscanf_ret == 1);
132 g_value_set_ulong (value, i);
135 case G_TYPE_BOOLEAN:{
138 if (!g_ascii_strncasecmp ("true", value_str, 4))
140 g_value_set_boolean (value, i);
146 sscanf_ret = sscanf (value_str, "%c", &i);
147 g_return_if_fail (sscanf_ret == 1);
148 g_value_set_char (value, i);
154 sscanf_ret = sscanf (value_str, "%c", &i);
155 g_return_if_fail (sscanf_ret == 1);
156 g_value_set_uchar (value, i);
162 sscanf_ret = sscanf (value_str, "%f", &i);
163 g_return_if_fail (sscanf_ret == 1);
164 g_value_set_float (value, i);
170 sscanf_ret = sscanf (value_str, "%g", &i);
171 g_return_if_fail (sscanf_ret == 1);
172 g_value_set_double (value, (gdouble) i);
181 * gst_util_set_object_arg:
182 * @object: the object to set the argument of
183 * @name: the name of the argument to set
184 * @value: the string value to set
186 * Convertes the string value to the type of the objects argument and
187 * sets the argument with it.
190 gst_util_set_object_arg (GObject * object, const gchar * name,
196 GParamSpec *paramspec;
199 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
205 GST_DEBUG ("paramspec->flags is %d, paramspec->value_type is %d",
206 paramspec->flags, (gint) paramspec->value_type);
208 if (paramspec->flags & G_PARAM_WRITABLE) {
209 switch (paramspec->value_type) {
211 g_object_set (G_OBJECT (object), name, value, NULL);
217 sscanf_ret = sscanf (value, "%d", &i);
218 g_return_if_fail (sscanf_ret == 1);
219 g_object_set (G_OBJECT (object), name, i, NULL);
225 sscanf_ret = sscanf (value, "%u", &i);
226 g_return_if_fail (sscanf_ret == 1);
227 g_object_set (G_OBJECT (object), name, i, NULL);
233 sscanf_ret = sscanf (value, "%ld", &i);
234 g_return_if_fail (sscanf_ret == 1);
235 g_object_set (G_OBJECT (object), name, i, NULL);
241 sscanf_ret = sscanf (value, "%lu", &i);
242 g_return_if_fail (sscanf_ret == 1);
243 g_object_set (G_OBJECT (object), name, i, NULL);
246 case G_TYPE_BOOLEAN:{
249 if (!g_ascii_strncasecmp ("true", value, 4))
251 g_object_set (G_OBJECT (object), name, i, NULL);
257 sscanf_ret = sscanf (value, "%c", &i);
258 g_return_if_fail (sscanf_ret == 1);
259 g_object_set (G_OBJECT (object), name, i, NULL);
265 sscanf_ret = sscanf (value, "%c", &i);
266 g_return_if_fail (sscanf_ret == 1);
267 g_object_set (G_OBJECT (object), name, i, NULL);
273 sscanf_ret = sscanf (value, "%f", &i);
274 g_return_if_fail (sscanf_ret == 1);
275 g_object_set (G_OBJECT (object), name, i, NULL);
281 sscanf_ret = sscanf (value, "%g", &i);
282 g_return_if_fail (sscanf_ret == 1);
283 g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
287 if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
290 sscanf_ret = sscanf (value, "%d", &i);
291 g_return_if_fail (sscanf_ret == 1);
292 g_object_set (G_OBJECT (object), name, i, NULL);
301 /* work around error C2520: conversion from unsigned __int64 to double
302 * not implemented, use signed __int64 */
304 * gst_guint64_to_gdouble:
305 * @value: the value to convert
307 * Convert @value to a gdouble. This is implemented as a function
308 * because on some platforms a 64bit int to double conversion is
309 * not defined/implemented.
311 * Returns: @value converted to a double.
314 gst_guint64_to_gdouble (guint64 value)
316 if (value & 0x8000000000000000)
317 return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
319 return (gdouble) ((gint64) value);
323 * gst_gdouble_to_guint64:
324 * @value: the value to convert
326 * Convert @value to a guint64. This is implemented as a function
327 * because on some platforms a double to guint64 conversion is not
328 * defined/implemented.
330 * Returns: @value converted to a double.
333 gst_gdouble_to_guint64 (gdouble value)
335 if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */
336 return ((guint64) ((gint64) value));
338 value -= (gdouble) 18446744073709551616.;
339 return ((guint64) ((gint64) value));
344 /* convenience struct for getting high an low uint32 parts of
351 #if G_BYTE_ORDER == G_BIG_ENDIAN
360 gst_util_uint64_scale_int64 (guint64 val, guint64 num, guint64 denom)
362 GstUInt64 a0, a1, b0, b1, c0, ct, c1, result;
370 /* do 128 bits multiply
378 * -------------------
381 a0.ll = (guint64) v.l.low * n.l.low;
382 a1.ll = (guint64) v.l.low * n.l.high;
383 b0.ll = (guint64) v.l.high * n.l.low;
384 b1.ll = (guint64) v.l.high * n.l.high;
386 /* and sum together with carry into 128 bits c1, c0 */
388 ct.ll = (guint64) a0.l.high + a1.l.low + b0.l.low;
389 c0.l.high = ct.l.low;
390 c1.ll = (guint64) a1.l.high + b0.l.high + ct.l.high + b1.ll;
392 /* if high bits bigger than denom, we overflow */
396 /* and 128/64 bits division, result fits 64 bits */
397 if (denom <= G_MAXUINT32) {
398 guint32 den = (guint32) denom;
400 /* easy case, (c1,c0)128/(den)32 division */
402 c1.l.high = c1.ll % den;
403 c1.l.low = c0.l.high;
404 c0.l.high = c1.ll % den;
405 result.l.high = c1.ll / den;
406 result.l.low = c0.ll / den;
411 /* full 128/64 case, very slow... */
412 /* quotient is c1, c0 */
413 a0.ll = 0; /* remainder a0 */
415 /* This can be done faster, inspiration in Hacker's Delight p152 */
416 for (i = 0; i < 128; i++) {
417 /* shift 192 bits remainder:quotient, we only need to
418 * check the top bit since denom is only 64 bits. */
419 /* sign extend top bit into mask */
420 mask = ((gint32) a0.l.high) >> 31;
421 mask |= (a0.ll = (a0.ll << 1) | (c1.l.high >> 31));
422 c1.ll = (c1.ll << 1) | (c0.l.high >> 31);
425 /* if remainder >= denom or top bit was set */
437 g_warning ("int64 scaling overflow");
443 * gst_util_uint64_scale:
444 * @val: the number to scale
445 * @num: the numerator of the scale ratio
446 * @denom: the denominator of the scale ratio
448 * Scale @val by @num / @denom, trying to avoid overflows.
450 * This function can potentially be very slow if denom > G_MAXUINT32.
452 * Returns: @val * @num / @denom, trying to avoid overflows.
455 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
457 g_return_val_if_fail (denom != 0, G_MAXUINT64);
459 /* if the denom is high, we need to do a 64 muldiv */
460 if (denom > G_MAXINT32)
463 /* if num and denom are low we can do a 32 bit muldiv */
464 if (num <= G_MAXINT32)
467 /* val and num are high, we need 64 muldiv */
468 if (val > G_MAXINT32)
471 /* val is low and num is high, we can swap them and do 32 muldiv */
472 return gst_util_uint64_scale_int (num, (gint) val, (gint) denom);
475 return gst_util_uint64_scale_int (val, (gint) num, (gint) denom);
478 /* to the more heavy implementations... */
479 return gst_util_uint64_scale_int64 (val, num, denom);
483 * gst_util_uint64_scale_int:
484 * @val: guint64 (such as a #GstClockTime) to scale.
485 * @num: numerator of the scale factor.
486 * @denom: denominator of the scale factor.
488 * Scale a guint64 by a factor expressed as a fraction (num/denom), avoiding
489 * overflows and loss of precision.
491 * @num and @denom must be positive integers. @denom cannot be 0.
493 * Returns: @val * @num / @denom, avoiding overflow and loss of precision
496 gst_util_uint64_scale_int (guint64 val, gint num, gint denom)
500 g_return_val_if_fail (denom > 0, G_MAXUINT64);
501 g_return_val_if_fail (num >= 0, G_MAXUINT64);
503 if (val <= G_MAXUINT32) {
505 result.ll = val * num / denom;
507 GstUInt64 gval, low, high, temp;
509 /* do 96 bits mult/div */
511 low.ll = ((guint64) gval.l.low) * num;
512 high.ll = ((guint64) gval.l.high) * num + (low.l.high);
513 result.ll = (high.ll / denom);
514 temp.l.high = (high.ll % denom);
515 temp.l.low = (low.l.low);
519 if (result.ll + temp.l.high > G_MAXUINT32)
522 result.l.high = result.l.low;
524 result.ll += temp.ll;
530 g_warning ("int scaling overflow");
535 /* -----------------------------------------------------
537 * The following code will be moved out of the main
538 * gstreamer library someday.
544 string_append_indent (GString * str, gint count)
548 for (xx = 0; xx < count; xx++)
549 g_string_append_c (str, ' ');
553 * gst_print_pad_caps:
554 * @buf: the buffer to print the caps in
555 * @indent: initial indentation
556 * @pad: the pad to print the caps from
558 * Write the pad capabilities in a human readable format into
562 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
569 string_append_indent (buf, indent);
570 g_string_printf (buf, "%s:%s has no capabilities",
571 GST_DEBUG_PAD_NAME (pad));
575 s = gst_caps_to_string (caps);
576 g_string_append (buf, s);
582 * gst_print_element_args:
583 * @buf: the buffer to print the args in
584 * @indent: initial indentation
585 * @element: the element to print the args of
587 * Print the element argument in a human readable format in the given
591 gst_print_element_args (GString * buf, gint indent, GstElement * element)
594 GValue value = { 0, }; /* the important thing is that value.type = 0 */
596 GParamSpec *spec, **specs, **walk;
598 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
601 for (walk = specs; *walk; walk++) {
603 if (width < strlen (spec->name))
604 width = strlen (spec->name);
607 for (walk = specs; *walk; walk++) {
610 if (spec->flags & G_PARAM_READABLE) {
611 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
612 g_object_get_property (G_OBJECT (element), spec->name, &value);
613 str = g_strdup_value_contents (&value);
614 g_value_unset (&value);
616 str = g_strdup ("Parameter not readable.");
619 string_append_indent (buf, indent);
620 g_string_append (buf, spec->name);
621 string_append_indent (buf, 2 + width - strlen (spec->name));
622 g_string_append (buf, str);
623 g_string_append_c (buf, '\n');
632 * gst_element_create_all_pads:
633 * @element: a #GstElement to create pads for
635 * Creates a pad for each pad template that is always available.
636 * This function is only useful during object intialization of
637 * subclasses of #GstElement.
640 gst_element_create_all_pads (GstElement * element)
644 /* FIXME: lock element */
647 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
648 (G_OBJECT_GET_CLASS (element)));
651 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
653 if (padtempl->presence == GST_PAD_ALWAYS) {
656 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
658 gst_element_add_pad (element, pad);
660 padlist = padlist->next;
665 * gst_element_get_compatible_pad_template:
666 * @element: a #GstElement to get a compatible pad template for.
667 * @compattempl: the #GstPadTemplate to find a compatible template for.
669 * Retrieves a pad template from @element that is compatible with @compattempl.
670 * Pads from compatible templates can be linked together.
672 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
673 * unreferencing is necessary.
676 gst_element_get_compatible_pad_template (GstElement * element,
677 GstPadTemplate * compattempl)
679 GstPadTemplate *newtempl = NULL;
681 GstElementClass *class;
683 g_return_val_if_fail (element != NULL, NULL);
684 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
685 g_return_val_if_fail (compattempl != NULL, NULL);
687 class = GST_ELEMENT_GET_CLASS (element);
689 padlist = gst_element_class_get_pad_template_list (class);
691 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
692 "Looking for a suitable pad template in %s out of %d templates...",
693 GST_ELEMENT_NAME (element), g_list_length (padlist));
696 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
697 GstCaps *intersection;
701 * Check direction (must be opposite)
704 GST_CAT_LOG (GST_CAT_CAPS,
705 "checking pad template %s", padtempl->name_template);
706 if (padtempl->direction != compattempl->direction) {
707 GST_CAT_DEBUG (GST_CAT_CAPS,
708 "compatible direction: found %s pad template \"%s\"",
709 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
710 padtempl->name_template);
712 GST_CAT_DEBUG (GST_CAT_CAPS,
713 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
714 GST_CAT_DEBUG (GST_CAT_CAPS,
715 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
717 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
718 GST_PAD_TEMPLATE_CAPS (padtempl));
720 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
721 (intersection ? "" : "not "), intersection);
723 if (!gst_caps_is_empty (intersection))
725 gst_caps_unref (intersection);
730 padlist = g_list_next (padlist);
733 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
734 "Returning new pad template %p", newtempl);
736 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
742 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
745 GstPad *newpad = NULL;
746 GstElementClass *oclass;
748 oclass = GST_ELEMENT_GET_CLASS (element);
750 if (oclass->request_new_pad)
751 newpad = (oclass->request_new_pad) (element, templ, name);
754 gst_object_ref (newpad);
762 * gst_element_get_pad_from_template:
763 * @element: a #GstElement.
764 * @templ: a #GstPadTemplate belonging to @element.
766 * Gets a pad from @element described by @templ. If the presence of @templ is
767 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
770 * Returns: the #GstPad, or NULL if one could not be found or created.
773 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
776 GstPadPresence presence;
778 /* If this function is ever exported, we need check the validity of `element'
779 * and `templ', and to make sure the template actually belongs to the
782 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
786 case GST_PAD_SOMETIMES:
787 ret = gst_element_get_static_pad (element, templ->name_template);
788 if (!ret && presence == GST_PAD_ALWAYS)
790 ("Element %s has an ALWAYS template %s, but no pad of the same name",
791 GST_OBJECT_NAME (element), templ->name_template);
794 case GST_PAD_REQUEST:
795 ret = gst_element_request_pad (element, templ, NULL);
803 * gst_element_request_compatible_pad:
804 * @element: a #GstElement.
805 * @templ: the #GstPadTemplate to which the new pad should be able to link.
807 * Requests a pad from @element. The returned pad should be unlinked and
808 * compatible with @templ. Might return an existing pad, or request a new one.
810 * Returns: a #GstPad, or %NULL if one could not be found or created.
813 gst_element_request_compatible_pad (GstElement * element,
814 GstPadTemplate * templ)
816 GstPadTemplate *templ_new;
819 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
820 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
822 /* FIXME: should really loop through the templates, testing each for
823 * compatibility and pad availability. */
824 templ_new = gst_element_get_compatible_pad_template (element, templ);
826 pad = gst_element_get_pad_from_template (element, templ_new);
828 /* This can happen for non-request pads. No need to unref. */
829 if (pad && GST_PAD_PEER (pad))
836 * gst_element_get_compatible_pad:
837 * @element: a #GstElement in which the pad should be found.
838 * @pad: the #GstPad to find a compatible one for.
839 * @caps: the #GstCaps to use as a filter.
841 * Looks for an unlinked pad to which the given pad can link. It is not
842 * guaranteed that linking the pads will work, though it should work in most
845 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
849 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
850 const GstCaps * caps)
853 GstPadTemplate *templ;
855 GstPad *foundpad = NULL;
858 /* FIXME check for caps compatibility */
860 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
861 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
863 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
864 "finding pad in %s compatible with %s:%s",
865 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
867 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
870 /* try to get an existing unlinked pad */
871 pads = gst_element_iterate_pads (element);
875 switch (gst_iterator_next (pads, &padptr)) {
876 case GST_ITERATOR_OK:
881 current = GST_PAD (padptr);
883 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
884 GST_DEBUG_PAD_NAME (current));
886 peer = gst_pad_get_peer (current);
888 if (peer == NULL && gst_pad_can_link (pad, current)) {
890 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
891 "found existing unlinked pad %s:%s",
892 GST_DEBUG_PAD_NAME (current));
894 gst_iterator_free (pads);
898 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
900 gst_object_unref (current);
902 gst_object_unref (peer);
906 case GST_ITERATOR_DONE:
909 case GST_ITERATOR_RESYNC:
910 gst_iterator_resync (pads);
912 case GST_ITERATOR_ERROR:
913 g_assert_not_reached ();
917 gst_iterator_free (pads);
919 /* try to create a new one */
920 /* requesting is a little crazy, we need a template. Let's create one */
921 templcaps = gst_pad_get_caps (pad);
923 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
924 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
925 foundpad = gst_element_request_compatible_pad (element, templ);
926 gst_object_unref (templ);
929 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
930 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
934 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
935 "Could not find a compatible pad to link to %s:%s",
936 GST_DEBUG_PAD_NAME (pad));
941 * gst_element_state_get_name:
942 * @state: a #GstState to get the name of.
944 * Gets a string representing the given state.
946 * Returns: a string with the name of the state.
949 gst_element_state_get_name (GstState state)
952 #ifdef GST_DEBUG_COLOR
953 case GST_STATE_VOID_PENDING:
954 return "VOID_PENDING";
957 return "\033[01;34mNULL\033[00m";
959 case GST_STATE_READY:
960 return "\033[01;31mREADY\033[00m";
962 case GST_STATE_PLAYING:
963 return "\033[01;32mPLAYING\033[00m";
965 case GST_STATE_PAUSED:
966 return "\033[01;33mPAUSED\033[00m";
969 /* This is a memory leak */
970 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
972 case GST_STATE_VOID_PENDING:
973 return "VOID_PENDING";
978 case GST_STATE_READY:
981 case GST_STATE_PLAYING:
984 case GST_STATE_PAUSED:
988 /* This is a memory leak */
989 return g_strdup_printf ("UNKNOWN!(%d)", state);
996 * gst_element_factory_can_src_caps :
997 * @factory: factory to query
998 * @caps: the caps to check
1000 * Checks if the factory can source the given capability.
1002 * Returns: true if it can src the capabilities
1005 gst_element_factory_can_src_caps (GstElementFactory * factory,
1006 const GstCaps * caps)
1010 g_return_val_if_fail (factory != NULL, FALSE);
1011 g_return_val_if_fail (caps != NULL, FALSE);
1013 templates = factory->staticpadtemplates;
1016 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1018 if (template->direction == GST_PAD_SRC) {
1019 if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
1020 static_caps), caps))
1023 templates = g_list_next (templates);
1030 * gst_element_factory_can_sink_caps :
1031 * @factory: factory to query
1032 * @caps: the caps to check
1034 * Checks if the factory can sink the given capability.
1036 * Returns: true if it can sink the capabilities
1039 gst_element_factory_can_sink_caps (GstElementFactory * factory,
1040 const GstCaps * caps)
1044 g_return_val_if_fail (factory != NULL, FALSE);
1045 g_return_val_if_fail (caps != NULL, FALSE);
1047 templates = factory->staticpadtemplates;
1050 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
1052 if (template->direction == GST_PAD_SINK) {
1053 if (gst_caps_is_always_compatible (caps,
1054 gst_static_caps_get (&template->static_caps)))
1057 templates = g_list_next (templates);
1064 /* if return val is true, *direct_child is a caller-owned ref on the direct
1065 * child of ancestor that is part of object's ancestry */
1067 object_has_ancestor (GstObject * object, GstObject * ancestor,
1068 GstObject ** direct_child)
1070 GstObject *child, *parent;
1073 *direct_child = NULL;
1075 child = gst_object_ref (object);
1076 parent = gst_object_get_parent (object);
1079 if (ancestor == parent) {
1081 *direct_child = child;
1083 gst_object_unref (child);
1084 gst_object_unref (parent);
1088 gst_object_unref (child);
1090 parent = gst_object_get_parent (parent);
1093 gst_object_unref (child);
1098 /* caller owns return */
1100 find_common_root (GstObject * o1, GstObject * o2)
1102 GstObject *top = o1;
1103 GstObject *kid1, *kid2;
1104 GstObject *root = NULL;
1106 while (GST_OBJECT_PARENT (top))
1107 top = GST_OBJECT_PARENT (top);
1109 /* the itsy-bitsy spider... */
1111 if (!object_has_ancestor (o2, top, &kid2))
1114 root = gst_object_ref (top);
1116 if (!object_has_ancestor (o1, kid2, &kid1)) {
1117 gst_object_unref (kid2);
1121 if (!object_has_ancestor (o2, kid1, &kid2)) {
1122 gst_object_unref (kid1);
1129 /* caller does not own return */
1131 ghost_up (GstElement * e, GstPad * pad)
1133 static gint ghost_pad_index = 0;
1136 GstObject *parent = GST_OBJECT_PARENT (e);
1138 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
1139 gpad = gst_ghost_pad_new (name, pad);
1142 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
1143 g_warning ("Pad named %s already exists in element %s\n",
1144 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
1145 gst_object_unref ((GstObject *) gpad);
1153 remove_pad (gpointer ppad, gpointer unused)
1157 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
1158 g_warning ("Couldn't remove pad %s from element %s",
1159 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
1163 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
1164 GSList ** pads_created)
1168 GSList *pads_created_local = NULL;
1170 g_assert (pads_created);
1172 e1 = GST_OBJECT_PARENT (*src);
1173 e2 = GST_OBJECT_PARENT (*sink);
1175 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
1176 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
1177 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1181 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
1182 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
1184 /* we need to setup some ghost pads */
1185 root = find_common_root (e1, e2);
1188 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
1189 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
1193 while (GST_OBJECT_PARENT (e1) != root) {
1194 *src = ghost_up ((GstElement *) e1, *src);
1197 e1 = GST_OBJECT_PARENT (*src);
1198 pads_created_local = g_slist_prepend (pads_created_local, *src);
1200 while (GST_OBJECT_PARENT (e2) != root) {
1201 *sink = ghost_up ((GstElement *) e2, *sink);
1204 e2 = GST_OBJECT_PARENT (*sink);
1205 pads_created_local = g_slist_prepend (pads_created_local, *sink);
1208 gst_object_unref (root);
1209 *pads_created = g_slist_concat (*pads_created, pads_created_local);
1213 gst_object_unref (root);
1214 g_slist_foreach (pads_created_local, remove_pad, NULL);
1215 g_slist_free (pads_created_local);
1220 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1222 GSList *pads_created = NULL;
1225 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1228 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1232 g_slist_foreach (pads_created, remove_pad, NULL);
1234 g_slist_free (pads_created);
1240 * gst_element_link_pads:
1241 * @src: a #GstElement containing the source pad.
1242 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1243 * @dest: the #GstElement containing the destination pad.
1244 * @destpadname: the name of the #GstPad in destination element,
1245 * or NULL for any pad.
1247 * Links the two named pads of the source and destination elements.
1248 * Side effect is that if one of the pads has no parent, it becomes a
1249 * child of the parent of the other element. If they have different
1250 * parents, the link fails.
1252 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1255 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1256 GstElement * dest, const gchar * destpadname)
1258 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1259 GstPad *srcpad, *destpad;
1260 GstPadTemplate *srctempl, *desttempl;
1261 GstElementClass *srcclass, *destclass;
1264 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1265 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1267 srcclass = GST_ELEMENT_GET_CLASS (src);
1268 destclass = GST_ELEMENT_GET_CLASS (dest);
1270 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1271 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1272 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1273 destpadname ? destpadname : "(any)");
1277 /* name specified, look it up */
1278 srcpad = gst_element_get_pad (src, srcpadname);
1280 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1281 GST_ELEMENT_NAME (src), srcpadname);
1284 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1285 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1286 GST_DEBUG_PAD_NAME (srcpad));
1287 gst_object_unref (srcpad);
1290 if (GST_PAD_PEER (srcpad) != NULL) {
1291 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1292 GST_DEBUG_PAD_NAME (srcpad));
1293 gst_object_unref (srcpad);
1299 /* no name given, get the first available pad */
1300 GST_OBJECT_LOCK (src);
1301 srcpads = GST_ELEMENT_PADS (src);
1302 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1304 gst_object_ref (srcpad);
1305 GST_OBJECT_UNLOCK (src);
1308 /* get a destination pad */
1310 /* name specified, look it up */
1311 destpad = gst_element_get_pad (dest, destpadname);
1313 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1314 GST_ELEMENT_NAME (dest), destpadname);
1317 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1318 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1319 GST_DEBUG_PAD_NAME (destpad));
1320 gst_object_unref (destpad);
1323 if (GST_PAD_PEER (destpad) != NULL) {
1324 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1325 GST_DEBUG_PAD_NAME (destpad));
1326 gst_object_unref (destpad);
1332 /* no name given, get the first available pad */
1333 GST_OBJECT_LOCK (dest);
1334 destpads = GST_ELEMENT_PADS (dest);
1335 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1337 gst_object_ref (destpad);
1338 GST_OBJECT_UNLOCK (dest);
1341 if (srcpadname && destpadname) {
1344 /* two explicitly specified pads */
1345 result = pad_link_maybe_ghosting (srcpad, destpad);
1347 gst_object_unref (srcpad);
1348 gst_object_unref (destpad);
1354 /* loop through the allowed pads in the source, trying to find a
1355 * compatible destination pad */
1356 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1357 "looping through allowed src and dest pads");
1359 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1360 GST_DEBUG_PAD_NAME (srcpad));
1361 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1362 (GST_PAD_PEER (srcpad) == NULL)) {
1367 gst_object_ref (temp);
1369 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1372 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1373 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1374 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1376 gst_object_unref (destpad);
1377 gst_object_unref (srcpad);
1378 gst_object_unref (temp);
1383 gst_object_unref (temp);
1386 /* find a better way for this mess */
1388 srcpads = g_list_next (srcpads);
1390 gst_object_unref (srcpad);
1391 srcpad = GST_PAD_CAST (srcpads->data);
1392 gst_object_ref (srcpad);
1398 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1399 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1401 gst_object_unref (srcpad);
1404 gst_object_unref (destpad);
1408 gst_object_unref (srcpad);
1413 /* loop through the existing pads in the destination */
1415 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1416 GST_DEBUG_PAD_NAME (destpad));
1417 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1418 (GST_PAD_PEER (destpad) == NULL)) {
1419 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1421 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1422 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1423 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1424 gst_object_unref (temp);
1425 gst_object_unref (destpad);
1427 gst_object_unref (srcpad);
1431 gst_object_unref (temp);
1435 destpads = g_list_next (destpads);
1437 gst_object_unref (destpad);
1438 destpad = GST_PAD_CAST (destpads->data);
1439 gst_object_ref (destpad);
1446 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1447 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1448 gst_object_unref (destpad);
1450 gst_object_unref (srcpad);
1454 gst_object_unref (srcpad);
1457 gst_object_unref (destpad);
1461 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1462 "we might have request pads on both sides, checking...");
1463 srctempls = gst_element_class_get_pad_template_list (srcclass);
1464 desttempls = gst_element_class_get_pad_template_list (destclass);
1466 if (srctempls && desttempls) {
1468 srctempl = (GstPadTemplate *) srctempls->data;
1469 if (srctempl->presence == GST_PAD_REQUEST) {
1470 for (l = desttempls; l; l = l->next) {
1471 desttempl = (GstPadTemplate *) l->data;
1472 if (desttempl->presence == GST_PAD_REQUEST &&
1473 desttempl->direction != srctempl->direction) {
1474 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1475 (srctempl), gst_pad_template_get_caps (desttempl))) {
1477 gst_element_get_request_pad (src, srctempl->name_template);
1479 gst_element_get_request_pad (dest, desttempl->name_template);
1480 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1481 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1482 "linked pad %s:%s to pad %s:%s",
1483 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1484 gst_object_unref (srcpad);
1485 gst_object_unref (destpad);
1488 /* it failed, so we release the request pads */
1489 gst_element_release_request_pad (src, srcpad);
1490 gst_element_release_request_pad (dest, destpad);
1495 srctempls = srctempls->next;
1499 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1500 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1505 * gst_element_link_pads_filtered:
1506 * @src: a #GstElement containing the source pad.
1507 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1508 * @dest: the #GstElement containing the destination pad.
1509 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1510 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1512 * Links the two named pads of the source and destination elements. Side effect
1513 * is that if one of the pads has no parent, it becomes a child of the parent of
1514 * the other element. If they have different parents, the link fails. If @caps
1515 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1517 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1520 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1521 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1524 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1525 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1526 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1529 GstElement *capsfilter;
1531 GstState state, pending;
1533 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1535 GST_ERROR ("Could not make a capsfilter");
1539 parent = gst_object_get_parent (GST_OBJECT (src));
1540 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1542 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, 0);
1544 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1545 GST_ERROR ("Could not add capsfilter");
1546 gst_object_unref (capsfilter);
1547 gst_object_unref (parent);
1551 if (pending != GST_STATE_VOID_PENDING)
1554 gst_element_set_state (capsfilter, state);
1556 gst_object_unref (parent);
1558 g_object_set (capsfilter, "caps", filter, NULL);
1560 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1561 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1564 GST_INFO ("Could not link elements");
1565 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1566 /* will unref and unlink as appropriate */
1570 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1576 * @src: a #GstElement containing the source pad.
1577 * @dest: the #GstElement containing the destination pad.
1579 * Links @src to @dest. The link must be from source to
1580 * destination; the other direction will not be tried. The function looks for
1581 * existing pads that aren't linked yet. It will request new pads if necessary.
1582 * If multiple links are possible, only one is established.
1584 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1587 gst_element_link (GstElement * src, GstElement * dest)
1589 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1593 * gst_element_link_many:
1594 * @element_1: the first #GstElement in the link chain.
1595 * @element_2: the second #GstElement in the link chain.
1596 * @...: the NULL-terminated list of elements to link in order.
1598 * Chain together a series of elements. Uses gst_element_link().
1600 * Returns: TRUE on success, FALSE otherwise.
1603 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1607 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1608 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1610 va_start (args, element_2);
1613 if (!gst_element_link (element_1, element_2))
1616 element_1 = element_2;
1617 element_2 = va_arg (args, GstElement *);
1626 * gst_element_link_filtered:
1627 * @src: a #GstElement containing the source pad.
1628 * @dest: the #GstElement containing the destination pad.
1629 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1631 * Links @src to @dest using the given caps as filtercaps.
1632 * The link must be from source to
1633 * destination; the other direction will not be tried. The function looks for
1634 * existing pads that aren't linked yet. It will request new pads if necessary.
1635 * If multiple links are possible, only one is established.
1637 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1640 gst_element_link_filtered (GstElement * src, GstElement * dest,
1643 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1647 * gst_element_unlink_pads:
1648 * @src: a #GstElement containing the source pad.
1649 * @srcpadname: the name of the #GstPad in source element.
1650 * @dest: a #GstElement containing the destination pad.
1651 * @destpadname: the name of the #GstPad in destination element.
1653 * Unlinks the two named pads of the source and destination elements.
1656 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1657 GstElement * dest, const gchar * destpadname)
1659 GstPad *srcpad, *destpad;
1661 g_return_if_fail (src != NULL);
1662 g_return_if_fail (GST_IS_ELEMENT (src));
1663 g_return_if_fail (srcpadname != NULL);
1664 g_return_if_fail (dest != NULL);
1665 g_return_if_fail (GST_IS_ELEMENT (dest));
1666 g_return_if_fail (destpadname != NULL);
1668 /* obtain the pads requested */
1669 srcpad = gst_element_get_pad (src, srcpadname);
1670 if (srcpad == NULL) {
1671 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1674 destpad = gst_element_get_pad (dest, destpadname);
1675 if (srcpad == NULL) {
1676 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1681 /* we're satisified they can be unlinked, let's do it */
1682 gst_pad_unlink (srcpad, destpad);
1686 * gst_element_unlink_many:
1687 * @element_1: the first #GstElement in the link chain.
1688 * @element_2: the second #GstElement in the link chain.
1689 * @...: the NULL-terminated list of elements to unlink in order.
1691 * Unlinks a series of elements. Uses gst_element_unlink().
1694 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1698 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1699 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1701 va_start (args, element_2);
1704 gst_element_unlink (element_1, element_2);
1706 element_1 = element_2;
1707 element_2 = va_arg (args, GstElement *);
1714 * gst_element_unlink:
1715 * @src: the source #GstElement to unlink.
1716 * @dest: the sink #GstElement to unlink.
1718 * Unlinks all source pads of the source element with all sink pads
1719 * of the sink element to which they are linked.
1722 gst_element_unlink (GstElement * src, GstElement * dest)
1725 gboolean done = FALSE;
1727 g_return_if_fail (GST_IS_ELEMENT (src));
1728 g_return_if_fail (GST_IS_ELEMENT (dest));
1730 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1731 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1733 pads = gst_element_iterate_pads (src);
1737 switch (gst_iterator_next (pads, &data)) {
1738 case GST_ITERATOR_OK:
1740 GstPad *pad = GST_PAD_CAST (data);
1742 if (GST_PAD_IS_SRC (pad)) {
1743 GstPad *peerpad = gst_pad_get_peer (pad);
1745 /* see if the pad is connected and is really a pad
1748 GstElement *peerelem;
1750 peerelem = gst_pad_get_parent_element (peerpad);
1752 if (peerelem == dest) {
1753 gst_pad_unlink (pad, peerpad);
1756 gst_object_unref (peerelem);
1758 gst_object_unref (peerpad);
1761 gst_object_unref (pad);
1764 case GST_ITERATOR_RESYNC:
1765 gst_iterator_resync (pads);
1767 case GST_ITERATOR_DONE:
1771 g_assert_not_reached ();
1778 * gst_element_query_position:
1779 * @element: a #GstElement to invoke the position query on.
1780 * @format: a pointer to the #GstFormat asked for.
1781 * On return contains the #GstFormat used.
1782 * @cur: A location in which to store the current position, or NULL.
1784 * Queries an element for the stream position.
1786 * Returns: TRUE if the query could be performed.
1789 gst_element_query_position (GstElement * element, GstFormat * format,
1795 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1796 g_return_val_if_fail (format != NULL, FALSE);
1798 query = gst_query_new_position (*format);
1799 ret = gst_element_query (element, query);
1802 gst_query_parse_position (query, format, cur);
1804 gst_query_unref (query);
1810 * gst_element_query_duration:
1811 * @element: a #GstElement to invoke the duration query on.
1812 * @format: a pointer to the #GstFormat asked for.
1813 * On return contains the #GstFormat used.
1814 * @duration: A location in which to store the total duration, or NULL.
1816 * Queries an element for the total stream duration.
1818 * Returns: TRUE if the query could be performed.
1821 gst_element_query_duration (GstElement * element, GstFormat * format,
1827 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1828 g_return_val_if_fail (format != NULL, FALSE);
1830 query = gst_query_new_duration (*format);
1831 ret = gst_element_query (element, query);
1834 gst_query_parse_duration (query, format, duration);
1836 gst_query_unref (query);
1842 * gst_element_query_convert:
1843 * @element: a #GstElement to invoke the convert query on.
1844 * @src_format: a #GstFormat to convert from.
1845 * @src_val: a value to convert.
1846 * @dest_format: a pointer to the #GstFormat to convert to.
1847 * @dest_val: a pointer to the result.
1849 * Queries an element to convert @src_val in @src_format to @dest_format.
1851 * Returns: TRUE if the query could be performed.
1854 gst_element_query_convert (GstElement * element, GstFormat src_format,
1855 gint64 src_val, GstFormat * dest_format, gint64 * dest_val)
1860 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1861 g_return_val_if_fail (dest_format != NULL, FALSE);
1862 g_return_val_if_fail (dest_val != NULL, FALSE);
1864 if (*dest_format == src_format) {
1865 *dest_val = src_val;
1869 query = gst_query_new_convert (src_format, src_val, *dest_format);
1870 ret = gst_element_query (element, query);
1873 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
1875 gst_query_unref (query);
1882 * @srcpad: the source #GstPad to link.
1883 * @sinkpad: the sink #GstPad to link.
1885 * Checks if the source pad and the sink pad can be linked.
1886 * Both @srcpad and @sinkpad must be unlinked.
1888 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1891 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1893 /* FIXME This function is gross. It's almost a direct copy of
1894 * gst_pad_link_filtered(). Any decent programmer would attempt
1895 * to merge the two functions, which I will do some day. --ds
1898 /* generic checks */
1899 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1900 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1902 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1903 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1905 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1906 if (GST_PAD_PEER (srcpad) != NULL) {
1907 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1908 GST_DEBUG_PAD_NAME (srcpad));
1911 if (GST_PAD_PEER (sinkpad) != NULL) {
1912 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1913 GST_DEBUG_PAD_NAME (sinkpad));
1916 if (!GST_PAD_IS_SRC (srcpad)) {
1917 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1918 GST_DEBUG_PAD_NAME (srcpad));
1921 if (!GST_PAD_IS_SINK (sinkpad)) {
1922 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1923 GST_DEBUG_PAD_NAME (sinkpad));
1926 if (GST_PAD_PARENT (srcpad) == NULL) {
1927 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1928 GST_DEBUG_PAD_NAME (srcpad));
1931 if (GST_PAD_PARENT (sinkpad) == NULL) {
1932 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1933 GST_DEBUG_PAD_NAME (srcpad));
1941 * gst_pad_use_fixed_caps:
1942 * @pad: the pad to use
1944 * A helper function you can use that sets the
1945 * @gst_pad_get_fixed_caps_func as the getcaps function for the
1946 * pad. This way the function will always return the negotiated caps
1947 * or in case the pad is not negotiated, the padtemplate caps.
1949 * Use this function on a pad that, once _set_caps() has been called
1950 * on it, cannot be renegotiated to something else.
1953 gst_pad_use_fixed_caps (GstPad * pad)
1955 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1959 * gst_pad_get_fixed_caps_func:
1960 * @pad: the pad to use
1962 * A helper function you can use as a GetCaps function that
1963 * will return the currently negotiated caps or the padtemplate
1966 * Returns: The currently negotiated caps or the padtemplate.
1969 gst_pad_get_fixed_caps_func (GstPad * pad)
1973 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1975 if (GST_PAD_CAPS (pad)) {
1976 result = GST_PAD_CAPS (pad);
1978 GST_CAT_DEBUG (GST_CAT_CAPS,
1979 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1981 result = gst_caps_ref (result);
1984 if (GST_PAD_PAD_TEMPLATE (pad)) {
1985 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1987 result = GST_PAD_TEMPLATE_CAPS (templ);
1988 GST_CAT_DEBUG (GST_CAT_CAPS,
1989 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1992 result = gst_caps_ref (result);
1995 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1996 result = gst_caps_new_empty ();
2003 * gst_pad_get_parent_element:
2006 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
2007 * its parent is not an element, return NULL.
2009 * Returns: The parent of the pad. The caller has a reference on the parent, so
2010 * unref when you're finished with it.
2015 gst_pad_get_parent_element (GstPad * pad)
2019 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2021 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
2023 if (p && !GST_IS_ELEMENT (p)) {
2024 gst_object_unref (p);
2027 return GST_ELEMENT_CAST (p);
2031 * gst_object_default_error:
2032 * @source: the #GstObject that initiated the error.
2033 * @error: the GError.
2034 * @debug: an additional debug information string, or NULL.
2036 * A default error function.
2038 * The default handler will simply print the error string using g_print.
2041 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
2043 gchar *name = gst_object_get_path_string (source);
2045 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
2047 g_print (_("Additional debug info:\n%s\n"), debug);
2055 * @element_1: the #GstElement element to add to the bin
2056 * @...: additional elements to add to the bin
2058 * Adds a NULL-terminated list of elements to a bin. This function is
2059 * equivalent to calling gst_bin_add() for each member of the list.
2062 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
2066 g_return_if_fail (GST_IS_BIN (bin));
2067 g_return_if_fail (GST_IS_ELEMENT (element_1));
2069 va_start (args, element_1);
2072 gst_bin_add (bin, element_1);
2074 element_1 = va_arg (args, GstElement *);
2081 * gst_bin_remove_many:
2083 * @element_1: the first #GstElement to remove from the bin
2084 * @...: NULL-terminated list of elements to remove from the bin
2086 * Remove a list of elements from a bin. This function is equivalent
2087 * to calling gst_bin_remove() with each member of the list.
2090 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
2094 g_return_if_fail (GST_IS_BIN (bin));
2095 g_return_if_fail (GST_IS_ELEMENT (element_1));
2097 va_start (args, element_1);
2100 gst_bin_remove (bin, element_1);
2102 element_1 = va_arg (args, GstElement *);
2109 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2110 guint arg_id, GParamFlags flags)
2112 GQuark prop_id = g_quark_from_string (prop_name);
2115 static GQuark fd_id = 0;
2116 static GQuark blocksize_id;
2117 static GQuark bytesperread_id;
2118 static GQuark dump_id;
2119 static GQuark filesize_id;
2120 static GQuark mmapsize_id;
2121 static GQuark location_id;
2122 static GQuark offset_id;
2123 static GQuark silent_id;
2124 static GQuark touch_id;
2127 fd_id = g_quark_from_static_string ("fd");
2128 blocksize_id = g_quark_from_static_string ("blocksize");
2129 bytesperread_id = g_quark_from_static_string ("bytesperread");
2130 dump_id = g_quark_from_static_string ("dump");
2131 filesize_id = g_quark_from_static_string ("filesize");
2132 mmapsize_id = g_quark_from_static_string ("mmapsize");
2133 location_id = g_quark_from_static_string ("location");
2134 offset_id = g_quark_from_static_string ("offset");
2135 silent_id = g_quark_from_static_string ("silent");
2136 touch_id = g_quark_from_static_string ("touch");
2139 if (prop_id == fd_id) {
2140 pspec = g_param_spec_int ("fd", "File-descriptor",
2141 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2142 } else if (prop_id == blocksize_id) {
2143 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2144 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2146 } else if (prop_id == bytesperread_id) {
2147 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2148 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2150 } else if (prop_id == dump_id) {
2151 pspec = g_param_spec_boolean ("dump", "Dump",
2152 "Dump bytes to stdout", FALSE, flags);
2154 } else if (prop_id == filesize_id) {
2155 pspec = g_param_spec_int64 ("filesize", "File Size",
2156 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2158 } else if (prop_id == mmapsize_id) {
2159 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2160 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2162 } else if (prop_id == location_id) {
2163 pspec = g_param_spec_string ("location", "File Location",
2164 "Location of the file to read", NULL, flags);
2166 } else if (prop_id == offset_id) {
2167 pspec = g_param_spec_int64 ("offset", "File Offset",
2168 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2170 } else if (prop_id == silent_id) {
2171 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2174 } else if (prop_id == touch_id) {
2175 pspec = g_param_spec_boolean ("touch", "Touch read data",
2176 "Touch data to force disk read before " "push ()", TRUE, flags);
2178 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2179 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2184 g_object_class_install_property (klass, arg_id, pspec);
2189 * gst_element_class_install_std_props:
2190 * @klass: the #GstElementClass to add the properties to.
2191 * @first_name: the name of the first property.
2192 * in a NULL terminated
2193 * @...: the id and flags of the first property, followed by
2194 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2196 * Adds a list of standardized properties with types to the @klass.
2197 * the id is for the property switch in your get_prop method, and
2198 * the flags determine readability / writeability.
2201 gst_element_class_install_std_props (GstElementClass * klass,
2202 const gchar * first_name, ...)
2208 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2210 va_start (args, first_name);
2215 int arg_id = va_arg (args, int);
2216 int flags = va_arg (args, int);
2218 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2221 name = va_arg (args, char *);
2230 * @buf1: the first source #GstBuffer to merge.
2231 * @buf2: the second source #GstBuffer to merge.
2233 * Create a new buffer that is the concatenation of the two source
2234 * buffers. The original source buffers will not be modified or
2235 * unref'd. Make sure you unref the source buffers if they are not used
2236 * anymore afterwards.
2238 * If the buffers point to contiguous areas of memory, the buffer
2239 * is created without copying the data.
2241 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2244 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2248 /* we're just a specific case of the more general gst_buffer_span() */
2249 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2256 * @buf1: the first source #GstBuffer.
2257 * @buf2: the second source #GstBuffer.
2259 * Create a new buffer that is the concatenation of the two source
2260 * buffers, and unrefs the original source buffers.
2262 * If the buffers point to contiguous areas of memory, the buffer
2263 * is created without copying the data.
2265 * Returns: the new #GstBuffer which is the concatenation of the source buffers.
2268 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2272 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2273 gst_buffer_unref (buf1);
2274 gst_buffer_unref (buf2);
2282 * @dest: buffer to stamp
2283 * @src: buffer to stamp from
2285 * Copies additional information (the timestamp, duration, and offset start
2286 * and end) from one buffer to the other.
2288 * This function does not copy any buffer flags or caps.
2291 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2293 g_return_if_fail (dest != NULL);
2294 g_return_if_fail (src != NULL);
2296 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
2297 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
2298 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
2299 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
2303 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2306 GstCaps *peercaps, *existing;
2308 existing = g_value_get_pointer (ret);
2309 peercaps = gst_pad_peer_get_caps (pad);
2310 if (peercaps == NULL)
2311 peercaps = gst_caps_new_any ();
2312 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2313 gst_caps_unref (existing);
2314 gst_caps_unref (peercaps);
2316 gst_object_unref (pad);
2321 * gst_pad_proxy_getcaps:
2322 * @pad: a #GstPad to proxy.
2324 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2325 * same element as @pad, and returns the intersection of the results.
2327 * This function is useful as a default getcaps function for an element
2328 * that can handle any stream format, but requires all its pads to have
2329 * the same caps. Two such elements are tee and aggregator.
2331 * Returns: the intersection of the other pads' allowed caps.
2334 gst_pad_proxy_getcaps (GstPad * pad)
2336 GstElement *element;
2337 GstCaps *caps, *intersected;
2339 GstIteratorResult res;
2340 GValue ret = { 0, };
2342 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2344 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2346 element = gst_pad_get_parent_element (pad);
2347 if (element == NULL)
2350 iter = gst_element_iterate_pads (element);
2352 g_value_init (&ret, G_TYPE_POINTER);
2353 g_value_set_pointer (&ret, gst_caps_new_any ());
2355 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2357 gst_iterator_free (iter);
2359 if (res != GST_ITERATOR_DONE)
2362 gst_object_unref (element);
2364 caps = g_value_get_pointer (&ret);
2365 g_value_unset (&ret);
2367 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2368 gst_caps_unref (caps);
2375 g_warning ("Pad list changed during capsnego for element %s",
2376 GST_ELEMENT_NAME (element));
2377 gst_object_unref (element);
2389 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2391 gboolean success = TRUE;
2393 if (pad != data->orig) {
2394 success = gst_pad_set_caps (pad, data->caps);
2395 g_value_set_boolean (ret, success);
2397 gst_object_unref (pad);
2403 * gst_pad_proxy_setcaps
2404 * @pad: a #GstPad to proxy from
2405 * @caps: the #GstCaps to link with
2407 * Calls gst_pad_set_caps() for every other pad belonging to the
2408 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2409 * the proxy setcaps fails. May be used only during negotiation.
2411 * Returns: TRUE if sucessful
2414 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2416 GstElement *element;
2418 GstIteratorResult res;
2419 GValue ret = { 0, };
2422 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2423 g_return_val_if_fail (caps != NULL, FALSE);
2425 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2427 element = gst_pad_get_parent_element (pad);
2428 if (element == NULL)
2431 iter = gst_element_iterate_pads (element);
2433 g_value_init (&ret, G_TYPE_BOOLEAN);
2434 g_value_set_boolean (&ret, TRUE);
2438 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2440 gst_iterator_free (iter);
2442 if (res != GST_ITERATOR_DONE)
2445 gst_object_unref (element);
2447 /* ok not to unset the gvalue */
2448 return g_value_get_boolean (&ret);
2453 g_warning ("Pad list changed during proxy_pad_link for element %s",
2454 GST_ELEMENT_NAME (element));
2455 gst_object_unref (element);
2461 * gst_pad_query_position:
2462 * @pad: a #GstPad to invoke the position query on.
2463 * @format: a pointer to the #GstFormat asked for.
2464 * On return contains the #GstFormat used.
2465 * @cur: A location in which to store the current position, or NULL.
2467 * Queries a pad for the stream position.
2469 * Returns: TRUE if the query could be performed.
2472 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur)
2477 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2478 g_return_val_if_fail (format != NULL, FALSE);
2480 query = gst_query_new_position (*format);
2481 ret = gst_pad_query (pad, query);
2484 gst_query_parse_position (query, format, cur);
2486 gst_query_unref (query);
2492 * gst_pad_query_duration:
2493 * @pad: a #GstPad to invoke the duration query on.
2494 * @format: a pointer to the #GstFormat asked for.
2495 * On return contains the #GstFormat used.
2496 * @duration: A location in which to store the total duration, or NULL.
2498 * Queries a pad for the total stream duration.
2500 * Returns: TRUE if the query could be performed.
2503 gst_pad_query_duration (GstPad * pad, GstFormat * format, gint64 * duration)
2508 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2509 g_return_val_if_fail (format != NULL, FALSE);
2511 query = gst_query_new_duration (*format);
2512 ret = gst_pad_query (pad, query);
2515 gst_query_parse_duration (query, format, duration);
2517 gst_query_unref (query);
2523 * gst_pad_query_convert:
2524 * @pad: a #GstPad to invoke the convert query on.
2525 * @src_format: a #GstFormat to convert from.
2526 * @src_val: a value to convert.
2527 * @dest_format: a pointer to the #GstFormat to convert to.
2528 * @dest_val: a pointer to the result.
2530 * Queries a pad to convert @src_val in @src_format to @dest_format.
2532 * Returns: TRUE if the query could be performed.
2535 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2536 GstFormat * dest_format, gint64 * dest_val)
2541 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2542 g_return_val_if_fail (src_val >= 0, FALSE);
2543 g_return_val_if_fail (dest_format != NULL, FALSE);
2544 g_return_val_if_fail (dest_val != NULL, FALSE);
2546 if (*dest_format == src_format) {
2547 *dest_val = src_val;
2551 query = gst_query_new_convert (src_format, src_val, *dest_format);
2552 ret = gst_pad_query (pad, query);
2555 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2557 gst_query_unref (query);
2563 * gst_atomic_int_set:
2564 * @atomic_int: pointer to an atomic integer
2565 * @value: value to set
2567 * Unconditionally sets the atomic integer to @value.
2570 gst_atomic_int_set (gint * atomic_int, gint value)
2574 *atomic_int = value;
2575 /* read acts as a memory barrier */
2576 ignore = g_atomic_int_get (atomic_int);
2580 * gst_pad_add_data_probe:
2581 * @pad: pad to add the data probe handler to
2582 * @handler: function to call when data is passed over pad
2583 * @data: data to pass along with the handler
2585 * Adds a "data probe" to a pad. This function will be called whenever data
2586 * passes through a pad. In this case data means both events and buffers. The
2587 * probe will be called with the data as an argument. Note that the data will
2588 * have a reference count greater than 1, so it will be immutable -- you must
2591 * For source pads, the probe will be called after the blocking function, if any
2592 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2593 * to. For sink pads, the probe function will be called before configuring the
2594 * sink with new caps, if any, and before calling the pad's chain function.
2596 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2597 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2600 * Although probes are implemented internally by connecting @handler to the
2601 * have-data signal on the pad, if you want to remove a probe it is insufficient
2602 * to only call g_signal_handler_disconnect on the returned handler id. To
2603 * remove a probe, use the appropriate function, such as
2604 * gst_pad_remove_data_probe().
2606 * Returns: The handler id.
2609 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2613 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2614 g_return_val_if_fail (handler != NULL, 0);
2616 GST_OBJECT_LOCK (pad);
2617 sigid = g_signal_connect (pad, "have-data", handler, data);
2618 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2619 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2620 GST_DEBUG ("adding data probe to pad %s:%s, now %d data, %d event probes",
2621 GST_DEBUG_PAD_NAME (pad),
2622 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2623 GST_OBJECT_UNLOCK (pad);
2629 * gst_pad_add_event_probe:
2630 * @pad: pad to add the event probe handler to
2631 * @handler: function to call when data is passed over pad
2632 * @data: data to pass along with the handler
2634 * Adds a probe that will be called for all events passing through a pad. See
2635 * gst_pad_add_data_probe() for more information.
2637 * Returns: The handler id
2640 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
2644 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2645 g_return_val_if_fail (handler != NULL, 0);
2647 GST_OBJECT_LOCK (pad);
2648 sigid = g_signal_connect (pad, "have-data::event", handler, data);
2649 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2650 GST_DEBUG ("adding event probe to pad %s:%s, now %d probes",
2651 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2652 GST_OBJECT_UNLOCK (pad);
2658 * gst_pad_add_buffer_probe:
2659 * @pad: pad to add the buffer probe handler to
2660 * @handler: function to call when data is passed over pad
2661 * @data: data to pass along with the handler
2663 * Adds a probe that will be called for all buffers passing through a pad. See
2664 * gst_pad_add_data_probe() for more information.
2666 * Returns: The handler id
2669 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2673 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2674 g_return_val_if_fail (handler != NULL, 0);
2676 GST_OBJECT_LOCK (pad);
2677 sigid = g_signal_connect (pad, "have-data::buffer", handler, data);
2678 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2679 GST_DEBUG ("adding buffer probe to pad %s:%s, now %d probes",
2680 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2681 GST_OBJECT_UNLOCK (pad);
2687 * gst_pad_remove_data_probe:
2688 * @pad: pad to remove the data probe handler from
2689 * @handler_id: handler id returned from gst_pad_add_data_probe
2691 * Removes a data probe from @pad.
2694 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
2696 g_return_if_fail (GST_IS_PAD (pad));
2697 g_return_if_fail (handler_id > 0);
2699 GST_OBJECT_LOCK (pad);
2700 g_signal_handler_disconnect (pad, handler_id);
2701 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2702 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2704 ("removed data probe from pad %s:%s, now %d event, %d buffer probes",
2705 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad),
2706 GST_PAD_DO_BUFFER_SIGNALS (pad));
2707 GST_OBJECT_UNLOCK (pad);
2711 * gst_pad_remove_event_probe:
2712 * @pad: pad to remove the event probe handler from
2713 * @handler_id: handler id returned from gst_pad_add_event_probe
2715 * Removes an event probe from @pad.
2718 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
2720 g_return_if_fail (GST_IS_PAD (pad));
2721 g_return_if_fail (handler_id > 0);
2723 GST_OBJECT_LOCK (pad);
2724 g_signal_handler_disconnect (pad, handler_id);
2725 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2726 GST_DEBUG ("removed event probe from pad %s:%s, now %d event probes",
2727 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2728 GST_OBJECT_UNLOCK (pad);
2732 * gst_pad_remove_buffer_probe:
2733 * @pad: pad to remove the buffer probe handler from
2734 * @handler_id: handler id returned from gst_pad_add_buffer_probe
2736 * Removes a buffer probe from @pad.
2739 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
2741 g_return_if_fail (GST_IS_PAD (pad));
2742 g_return_if_fail (handler_id > 0);
2744 GST_OBJECT_LOCK (pad);
2745 g_signal_handler_disconnect (pad, handler_id);
2746 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2747 GST_DEBUG ("removed buffer probe from pad %s:%s, now %d buffer probes",
2748 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2749 GST_OBJECT_UNLOCK (pad);
2753 * gst_element_found_tags_for_pad:
2754 * @element: element for which to post taglist to bus.
2755 * @pad: pad on which to push tag-event.
2756 * @list: the taglist to post on the bus and create event from.
2758 * Posts a message to the bus that new tags were found and pushes the
2759 * tags as event. Takes ownership of the taglist.
2762 gst_element_found_tags_for_pad (GstElement * element,
2763 GstPad * pad, GstTagList * list)
2765 g_return_if_fail (element != NULL);
2766 g_return_if_fail (pad != NULL);
2767 g_return_if_fail (list != NULL);
2769 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
2770 gst_element_post_message (element,
2771 gst_message_new_tag (GST_OBJECT (element), list));
2775 push_and_ref (GstPad * pad, GstEvent * event)
2777 gst_pad_push_event (pad, gst_event_ref (event));
2781 * gst_element_found_tags:
2782 * @element: element for which we found the tags.
2783 * @list: list of tags.
2785 * Posts a message to the bus that new tags were found, and pushes an event
2786 * to all sourcepads. Takes ownership of the taglist.
2789 gst_element_found_tags (GstElement * element, GstTagList * list)
2794 g_return_if_fail (element != NULL);
2795 g_return_if_fail (list != NULL);
2797 iter = gst_element_iterate_src_pads (element);
2798 event = gst_event_new_tag (gst_tag_list_copy (list));
2799 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
2800 gst_iterator_free (iter);
2801 gst_event_unref (event);
2803 gst_element_post_message (element,
2804 gst_message_new_tag (GST_OBJECT (element), list));