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.
24 * @short_description: Various utility functions
26 * When defining own plugins, use the GST_BOILERPLATE ease gobject creation.
32 #include "gst_private.h"
33 #include "gstghostpad.h"
35 #include "gsturitype.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);
293 } else if (paramspec->value_type == GST_TYPE_URI) {
294 g_object_set (G_OBJECT (object), name, value, NULL);
303 /* work around error C2520: conversion from unsigned __int64 to double
304 * not implemented, use signed __int64 */
306 gst_guint64_to_gdouble (guint64 value)
308 if (value & 0x8000000000000000)
309 return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
311 return (gdouble) ((gint64) value);
315 gst_gdouble_to_guint64 (gdouble value)
317 if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */
318 return ((guint64) ((gint64) value));
320 value -= (gdouble) 18446744073709551616.;
321 return ((guint64) ((gint64) value));
326 * gst_util_uint64_scale:
327 * @val: the number to scale
328 * @num: the numerator of the scale ratio
329 * @denom: the denominator of the scale ratio
331 * Scale @val by @num / @denom, trying to avoid overflows.
333 * Returns: @val * @num / @denom, trying to avoid overflows.
336 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
338 /* implement me with fixed point, if you care */
339 return gst_gdouble_to_guint64 (gst_guint64_to_gdouble (val) *
340 ((gst_guint64_to_gdouble (num)) / gst_guint64_to_gdouble (denom)));
343 /* -----------------------------------------------------
345 * The following code will be moved out of the main
346 * gstreamer library someday.
352 string_append_indent (GString * str, gint count)
356 for (xx = 0; xx < count; xx++)
357 g_string_append_c (str, ' ');
361 * gst_print_pad_caps:
362 * @buf: the buffer to print the caps in
363 * @indent: initial indentation
364 * @pad: the pad to print the caps from
366 * Write the pad capabilities in a human readable format into
370 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
377 string_append_indent (buf, indent);
378 g_string_printf (buf, "%s:%s has no capabilities",
379 GST_DEBUG_PAD_NAME (pad));
383 s = gst_caps_to_string (caps);
384 g_string_append (buf, s);
390 * gst_print_element_args:
391 * @buf: the buffer to print the args in
392 * @indent: initial indentation
393 * @element: the element to print the args of
395 * Print the element argument in a human readable format in the given
399 gst_print_element_args (GString * buf, gint indent, GstElement * element)
402 GValue value = { 0, }; /* the important thing is that value.type = 0 */
404 GParamSpec *spec, **specs, **walk;
406 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
409 for (walk = specs; *walk; walk++) {
411 if (width < strlen (spec->name))
412 width = strlen (spec->name);
415 for (walk = specs; *walk; walk++) {
418 if (spec->flags & G_PARAM_READABLE) {
419 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
420 g_object_get_property (G_OBJECT (element), spec->name, &value);
421 str = g_strdup_value_contents (&value);
422 g_value_unset (&value);
424 str = g_strdup ("Parameter not readable.");
427 string_append_indent (buf, indent);
428 g_string_append (buf, spec->name);
429 string_append_indent (buf, 2 + width - strlen (spec->name));
430 g_string_append (buf, str);
431 g_string_append_c (buf, '\n');
440 * gst_element_create_all_pads:
441 * @element: a #GstElement to create pads for
443 * Creates a pad for each pad template that is always available.
444 * This function is only useful during object intialization of
445 * subclasses of #GstElement.
448 gst_element_create_all_pads (GstElement * element)
452 /* FIXME: lock element */
455 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
456 (G_OBJECT_GET_CLASS (element)));
459 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
461 if (padtempl->presence == GST_PAD_ALWAYS) {
464 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
466 gst_element_add_pad (element, pad);
468 padlist = padlist->next;
473 * gst_element_get_compatible_pad_template:
474 * @element: a #GstElement to get a compatible pad template for.
475 * @compattempl: the #GstPadTemplate to find a compatible template for.
477 * Retrieves a pad template from @element that is compatible with @compattempl.
478 * Pads from compatible templates can be linked together.
480 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
481 * unreferencing is necessary.
484 gst_element_get_compatible_pad_template (GstElement * element,
485 GstPadTemplate * compattempl)
487 GstPadTemplate *newtempl = NULL;
489 GstElementClass *class;
491 g_return_val_if_fail (element != NULL, NULL);
492 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
493 g_return_val_if_fail (compattempl != NULL, NULL);
495 class = GST_ELEMENT_GET_CLASS (element);
497 padlist = gst_element_class_get_pad_template_list (class);
499 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
500 "Looking for a suitable pad template in %s out of %d templates...",
501 GST_ELEMENT_NAME (element), g_list_length (padlist));
504 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
505 GstCaps *intersection;
509 * Check direction (must be opposite)
512 GST_CAT_LOG (GST_CAT_CAPS,
513 "checking pad template %s", padtempl->name_template);
514 if (padtempl->direction != compattempl->direction) {
515 GST_CAT_DEBUG (GST_CAT_CAPS,
516 "compatible direction: found %s pad template \"%s\"",
517 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
518 padtempl->name_template);
520 GST_CAT_DEBUG (GST_CAT_CAPS,
521 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
522 GST_CAT_DEBUG (GST_CAT_CAPS,
523 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
525 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
526 GST_PAD_TEMPLATE_CAPS (padtempl));
528 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
529 (intersection ? "" : "not "), intersection);
531 if (!gst_caps_is_empty (intersection))
533 gst_caps_unref (intersection);
538 padlist = g_list_next (padlist);
541 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
542 "Returning new pad template %p", newtempl);
544 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
550 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
553 GstPad *newpad = NULL;
554 GstElementClass *oclass;
556 oclass = GST_ELEMENT_GET_CLASS (element);
558 if (oclass->request_new_pad)
559 newpad = (oclass->request_new_pad) (element, templ, name);
562 gst_object_ref (newpad);
570 * gst_element_get_pad_from_template:
571 * @element: a #GstElement.
572 * @templ: a #GstPadTemplate belonging to @element.
574 * Gets a pad from @element described by @templ. If the presence of @templ is
575 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
578 * Returns: the #GstPad, or NULL if one could not be found or created.
581 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
584 GstPadPresence presence;
586 /* If this function is ever exported, we need check the validity of `element'
587 * and `templ', and to make sure the template actually belongs to the
590 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
594 case GST_PAD_SOMETIMES:
595 ret = gst_element_get_static_pad (element, templ->name_template);
596 if (!ret && presence == GST_PAD_ALWAYS)
598 ("Element %s has an ALWAYS template %s, but no pad of the same name",
599 GST_OBJECT_NAME (element), templ->name_template);
602 case GST_PAD_REQUEST:
603 ret = gst_element_request_pad (element, templ, NULL);
611 * gst_element_request_compatible_pad:
612 * @element: a #GstElement.
613 * @templ: the #GstPadTemplate to which the new pad should be able to link.
615 * Requests a pad from @element. The returned pad should be unlinked and
616 * compatible with @templ. Might return an existing pad, or request a new one.
618 * Returns: a #GstPad, or %NULL if one could not be found or created.
621 gst_element_request_compatible_pad (GstElement * element,
622 GstPadTemplate * templ)
624 GstPadTemplate *templ_new;
627 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
628 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
630 /* FIXME: should really loop through the templates, testing each for
631 * compatibility and pad availability. */
632 templ_new = gst_element_get_compatible_pad_template (element, templ);
634 pad = gst_element_get_pad_from_template (element, templ_new);
636 /* This can happen for non-request pads. No need to unref. */
637 if (pad && GST_PAD_PEER (pad))
644 * gst_element_get_compatible_pad:
645 * @element: a #GstElement in which the pad should be found.
646 * @pad: the #GstPad to find a compatible one for.
647 * @caps: the #GstCaps to use as a filter.
649 * Looks for an unlinked pad to which the given pad can link. It is not
650 * guaranteed that linking the pads will work, though it should work in most
653 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
657 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
658 const GstCaps * caps)
661 GstPadTemplate *templ;
663 GstPad *foundpad = NULL;
666 /* FIXME check for caps compatibility */
668 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
669 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
671 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
672 "finding pad in %s compatible with %s:%s",
673 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
675 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
678 /* try to get an existing unlinked pad */
679 pads = gst_element_iterate_pads (element);
683 switch (gst_iterator_next (pads, &padptr)) {
684 case GST_ITERATOR_OK:
689 current = GST_PAD (padptr);
691 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
692 GST_DEBUG_PAD_NAME (current));
694 peer = gst_pad_get_peer (current);
696 if (peer == NULL && gst_pad_can_link (pad, current)) {
698 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
699 "found existing unlinked pad %s:%s",
700 GST_DEBUG_PAD_NAME (current));
702 gst_iterator_free (pads);
706 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
708 gst_object_unref (current);
710 gst_object_unref (peer);
714 case GST_ITERATOR_DONE:
717 case GST_ITERATOR_RESYNC:
718 gst_iterator_resync (pads);
720 case GST_ITERATOR_ERROR:
721 g_assert_not_reached ();
725 gst_iterator_free (pads);
727 /* try to create a new one */
728 /* requesting is a little crazy, we need a template. Let's create one */
729 templcaps = gst_pad_get_caps (pad);
731 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
732 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
733 foundpad = gst_element_request_compatible_pad (element, templ);
734 gst_object_unref (templ);
737 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
738 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
742 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
743 "Could not find a compatible pad to link to %s:%s",
744 GST_DEBUG_PAD_NAME (pad));
749 * gst_element_state_get_name:
750 * @state: a #GstState to get the name of.
752 * Gets a string representing the given state.
754 * Returns: a string with the name of the state.
757 gst_element_state_get_name (GstState state)
760 #ifdef GST_DEBUG_COLOR
761 case GST_STATE_VOID_PENDING:
762 return "VOID_PENDING";
765 return "\033[01;34mNULL\033[00m";
767 case GST_STATE_READY:
768 return "\033[01;31mREADY\033[00m";
770 case GST_STATE_PLAYING:
771 return "\033[01;32mPLAYING\033[00m";
773 case GST_STATE_PAUSED:
774 return "\033[01;33mPAUSED\033[00m";
777 /* This is a memory leak */
778 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
780 case GST_STATE_VOID_PENDING:
781 return "VOID_PENDING";
786 case GST_STATE_READY:
789 case GST_STATE_PLAYING:
792 case GST_STATE_PAUSED:
796 /* This is a memory leak */
797 return g_strdup_printf ("UNKNOWN!(%d)", state);
804 * gst_element_factory_can_src_caps :
805 * @factory: factory to query
806 * @caps: the caps to check
808 * Checks if the factory can source the given capability.
810 * Returns: true if it can src the capabilities
813 gst_element_factory_can_src_caps (GstElementFactory * factory,
814 const GstCaps * caps)
818 g_return_val_if_fail (factory != NULL, FALSE);
819 g_return_val_if_fail (caps != NULL, FALSE);
821 templates = factory->staticpadtemplates;
824 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
826 if (template->direction == GST_PAD_SRC) {
827 if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
831 templates = g_list_next (templates);
838 * gst_element_factory_can_sink_caps :
839 * @factory: factory to query
840 * @caps: the caps to check
842 * Checks if the factory can sink the given capability.
844 * Returns: true if it can sink the capabilities
847 gst_element_factory_can_sink_caps (GstElementFactory * factory,
848 const GstCaps * caps)
852 g_return_val_if_fail (factory != NULL, FALSE);
853 g_return_val_if_fail (caps != NULL, FALSE);
855 templates = factory->staticpadtemplates;
858 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
860 if (template->direction == GST_PAD_SINK) {
861 if (gst_caps_is_always_compatible (caps,
862 gst_static_caps_get (&template->static_caps)))
865 templates = g_list_next (templates);
872 /* if return val is true, *direct_child is a caller-owned ref on the direct
873 * child of ancestor that is part of object's ancestry */
875 object_has_ancestor (GstObject * object, GstObject * ancestor,
876 GstObject ** direct_child)
878 GstObject *child, *parent;
881 *direct_child = NULL;
883 child = gst_object_ref (object);
884 parent = gst_object_get_parent (object);
887 if (ancestor == parent) {
889 *direct_child = child;
891 gst_object_unref (child);
892 gst_object_unref (parent);
896 gst_object_unref (child);
898 parent = gst_object_get_parent (parent);
901 gst_object_unref (child);
906 /* caller owns return */
908 find_common_root (GstObject * o1, GstObject * o2)
911 GstObject *kid1, *kid2;
912 GstObject *root = NULL;
914 while (GST_OBJECT_PARENT (top))
915 top = GST_OBJECT_PARENT (top);
917 /* the itsy-bitsy spider... */
919 if (!object_has_ancestor (o2, top, &kid2))
922 root = gst_object_ref (top);
924 if (!object_has_ancestor (o1, kid2, &kid1)) {
925 gst_object_unref (kid2);
929 if (!object_has_ancestor (o2, kid1, &kid2)) {
930 gst_object_unref (kid1);
937 /* caller does not own return */
939 ghost_up (GstElement * e, GstPad * pad)
941 static gint ghost_pad_index = 0;
944 GstObject *parent = GST_OBJECT_PARENT (e);
946 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
947 gpad = gst_ghost_pad_new (name, pad);
950 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
951 g_warning ("Pad named %s already exists in element %s\n",
952 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
953 gst_object_unref ((GstObject *) gpad);
961 remove_pad (gpointer ppad, gpointer unused)
965 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
966 g_warning ("Couldn't remove pad %s from element %s",
967 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
971 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
972 GSList ** pads_created)
976 GSList *pads_created_local = NULL;
978 g_assert (pads_created);
980 e1 = GST_OBJECT_PARENT (*src);
981 e2 = GST_OBJECT_PARENT (*sink);
983 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
984 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
985 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
989 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
990 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
992 /* we need to setup some ghost pads */
993 root = find_common_root (e1, e2);
996 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
997 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
1001 while (GST_OBJECT_PARENT (e1) != root) {
1002 *src = ghost_up ((GstElement *) e1, *src);
1005 e1 = GST_OBJECT_PARENT (*src);
1006 pads_created_local = g_slist_prepend (pads_created_local, *src);
1008 while (GST_OBJECT_PARENT (e2) != root) {
1009 *sink = ghost_up ((GstElement *) e2, *sink);
1012 e2 = GST_OBJECT_PARENT (*sink);
1013 pads_created_local = g_slist_prepend (pads_created_local, *sink);
1016 gst_object_unref (root);
1017 *pads_created = g_slist_concat (*pads_created, pads_created_local);
1021 gst_object_unref (root);
1022 g_slist_foreach (pads_created_local, remove_pad, NULL);
1023 g_slist_free (pads_created_local);
1028 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1030 GSList *pads_created = NULL;
1033 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1036 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1040 g_slist_foreach (pads_created, remove_pad, NULL);
1042 g_slist_free (pads_created);
1048 * gst_element_link_pads:
1049 * @src: a #GstElement containing the source pad.
1050 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1051 * @dest: the #GstElement containing the destination pad.
1052 * @destpadname: the name of the #GstPad in destination element,
1053 * or NULL for any pad.
1055 * Links the two named pads of the source and destination elements.
1056 * Side effect is that if one of the pads has no parent, it becomes a
1057 * child of the parent of the other element. If they have different
1058 * parents, the link fails.
1060 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1063 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1064 GstElement * dest, const gchar * destpadname)
1066 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1067 GstPad *srcpad, *destpad;
1068 GstPadTemplate *srctempl, *desttempl;
1069 GstElementClass *srcclass, *destclass;
1072 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1073 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1075 srcclass = GST_ELEMENT_GET_CLASS (src);
1076 destclass = GST_ELEMENT_GET_CLASS (dest);
1078 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1079 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1080 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1081 destpadname ? destpadname : "(any)");
1085 /* name specified, look it up */
1086 srcpad = gst_element_get_pad (src, srcpadname);
1088 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1089 GST_ELEMENT_NAME (src), srcpadname);
1092 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1093 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1094 GST_DEBUG_PAD_NAME (srcpad));
1095 gst_object_unref (srcpad);
1098 if (GST_PAD_PEER (srcpad) != NULL) {
1099 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1100 GST_DEBUG_PAD_NAME (srcpad));
1101 gst_object_unref (srcpad);
1107 /* no name given, get the first available pad */
1109 srcpads = GST_ELEMENT_PADS (src);
1110 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1112 gst_object_ref (srcpad);
1116 /* get a destination pad */
1118 /* name specified, look it up */
1119 destpad = gst_element_get_pad (dest, destpadname);
1121 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1122 GST_ELEMENT_NAME (dest), destpadname);
1125 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1126 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1127 GST_DEBUG_PAD_NAME (destpad));
1128 gst_object_unref (destpad);
1131 if (GST_PAD_PEER (destpad) != NULL) {
1132 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1133 GST_DEBUG_PAD_NAME (destpad));
1134 gst_object_unref (destpad);
1140 /* no name given, get the first available pad */
1142 destpads = GST_ELEMENT_PADS (dest);
1143 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1145 gst_object_ref (destpad);
1149 if (srcpadname && destpadname) {
1152 /* two explicitly specified pads */
1153 result = pad_link_maybe_ghosting (srcpad, destpad);
1155 gst_object_unref (srcpad);
1156 gst_object_unref (destpad);
1162 /* loop through the allowed pads in the source, trying to find a
1163 * compatible destination pad */
1164 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1165 "looping through allowed src and dest pads");
1167 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1168 GST_DEBUG_PAD_NAME (srcpad));
1169 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1170 (GST_PAD_PEER (srcpad) == NULL)) {
1175 gst_object_ref (temp);
1177 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1180 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1181 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1182 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1184 gst_object_unref (destpad);
1185 gst_object_unref (srcpad);
1186 gst_object_unref (temp);
1191 gst_object_unref (temp);
1194 /* find a better way for this mess */
1196 srcpads = g_list_next (srcpads);
1198 gst_object_unref (srcpad);
1199 srcpad = GST_PAD_CAST (srcpads->data);
1200 gst_object_ref (srcpad);
1206 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1207 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1209 gst_object_unref (srcpad);
1212 gst_object_unref (destpad);
1216 gst_object_unref (srcpad);
1221 /* loop through the existing pads in the destination */
1223 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1224 GST_DEBUG_PAD_NAME (destpad));
1225 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1226 (GST_PAD_PEER (destpad) == NULL)) {
1227 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1229 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1230 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1231 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1232 gst_object_unref (temp);
1233 gst_object_unref (destpad);
1235 gst_object_unref (srcpad);
1239 gst_object_unref (temp);
1243 destpads = g_list_next (destpads);
1245 gst_object_unref (destpad);
1246 destpad = GST_PAD_CAST (destpads->data);
1247 gst_object_ref (destpad);
1254 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1255 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1256 gst_object_unref (destpad);
1258 gst_object_unref (srcpad);
1262 gst_object_unref (srcpad);
1265 gst_object_unref (destpad);
1269 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1270 "we might have request pads on both sides, checking...");
1271 srctempls = gst_element_class_get_pad_template_list (srcclass);
1272 desttempls = gst_element_class_get_pad_template_list (destclass);
1274 if (srctempls && desttempls) {
1276 srctempl = (GstPadTemplate *) srctempls->data;
1277 if (srctempl->presence == GST_PAD_REQUEST) {
1278 for (l = desttempls; l; l = l->next) {
1279 desttempl = (GstPadTemplate *) l->data;
1280 if (desttempl->presence == GST_PAD_REQUEST &&
1281 desttempl->direction != srctempl->direction) {
1282 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1283 (srctempl), gst_pad_template_get_caps (desttempl))) {
1285 gst_element_get_request_pad (src, srctempl->name_template);
1287 gst_element_get_request_pad (dest, desttempl->name_template);
1288 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1289 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1290 "linked pad %s:%s to pad %s:%s",
1291 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1292 gst_object_unref (srcpad);
1293 gst_object_unref (destpad);
1296 /* it failed, so we release the request pads */
1297 gst_element_release_request_pad (src, srcpad);
1298 gst_element_release_request_pad (dest, destpad);
1303 srctempls = srctempls->next;
1307 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1308 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1313 * gst_element_link_pads_filtered:
1314 * @src: a #GstElement containing the source pad.
1315 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1316 * @dest: the #GstElement containing the destination pad.
1317 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1318 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1320 * Links the two named pads of the source and destination elements. Side effect
1321 * is that if one of the pads has no parent, it becomes a child of the parent of
1322 * the other element. If they have different parents, the link fails. If @caps
1323 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1325 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1328 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1329 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1332 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1333 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1334 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1337 GstElement *capsfilter;
1339 GstState state, pending;
1342 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1344 GST_ERROR ("Could not make a capsfilter");
1348 parent = gst_object_get_parent (GST_OBJECT (src));
1349 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1351 GST_TIME_TO_TIMEVAL (0, tv);
1352 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, &tv);
1354 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1355 GST_ERROR ("Could not add capsfilter");
1356 gst_object_unref (capsfilter);
1357 gst_object_unref (parent);
1361 if (pending != GST_STATE_VOID_PENDING)
1364 gst_element_set_state (capsfilter, state);
1366 gst_object_unref (parent);
1368 g_object_set (capsfilter, "caps", filter, NULL);
1370 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1371 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1374 GST_INFO ("Could not link elements");
1375 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1376 /* will unref and unlink as appropriate */
1380 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1386 * @src: a #GstElement containing the source pad.
1387 * @dest: the #GstElement containing the destination pad.
1389 * Links @src to @dest. The link must be from source to
1390 * destination; the other direction will not be tried. The function looks for
1391 * existing pads that aren't linked yet. It will request new pads if necessary.
1392 * If multiple links are possible, only one is established.
1394 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1397 gst_element_link (GstElement * src, GstElement * dest)
1399 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1403 * gst_element_link_many:
1404 * @element_1: the first #GstElement in the link chain.
1405 * @element_2: the second #GstElement in the link chain.
1406 * @...: the NULL-terminated list of elements to link in order.
1408 * Chain together a series of elements. Uses gst_element_link().
1410 * Returns: TRUE on success, FALSE otherwise.
1413 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1417 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1418 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1420 va_start (args, element_2);
1423 if (!gst_element_link (element_1, element_2))
1426 element_1 = element_2;
1427 element_2 = va_arg (args, GstElement *);
1436 * gst_element_link_filtered:
1437 * @src: a #GstElement containing the source pad.
1438 * @dest: the #GstElement containing the destination pad.
1439 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1441 * Links @src to @dest using the given caps as filtercaps.
1442 * The link must be from source to
1443 * destination; the other direction will not be tried. The function looks for
1444 * existing pads that aren't linked yet. It will request new pads if necessary.
1445 * If multiple links are possible, only one is established.
1447 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1450 gst_element_link_filtered (GstElement * src, GstElement * dest,
1453 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1457 * gst_element_unlink_pads:
1458 * @src: a #GstElement containing the source pad.
1459 * @srcpadname: the name of the #GstPad in source element.
1460 * @dest: a #GstElement containing the destination pad.
1461 * @destpadname: the name of the #GstPad in destination element.
1463 * Unlinks the two named pads of the source and destination elements.
1466 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1467 GstElement * dest, const gchar * destpadname)
1469 GstPad *srcpad, *destpad;
1471 g_return_if_fail (src != NULL);
1472 g_return_if_fail (GST_IS_ELEMENT (src));
1473 g_return_if_fail (srcpadname != NULL);
1474 g_return_if_fail (dest != NULL);
1475 g_return_if_fail (GST_IS_ELEMENT (dest));
1476 g_return_if_fail (destpadname != NULL);
1478 /* obtain the pads requested */
1479 srcpad = gst_element_get_pad (src, srcpadname);
1480 if (srcpad == NULL) {
1481 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1484 destpad = gst_element_get_pad (dest, destpadname);
1485 if (srcpad == NULL) {
1486 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1491 /* we're satisified they can be unlinked, let's do it */
1492 gst_pad_unlink (srcpad, destpad);
1496 * gst_element_unlink_many:
1497 * @element_1: the first #GstElement in the link chain.
1498 * @element_2: the second #GstElement in the link chain.
1499 * @...: the NULL-terminated list of elements to unlink in order.
1501 * Unlinks a series of elements. Uses gst_element_unlink().
1504 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1508 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1509 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1511 va_start (args, element_2);
1514 gst_element_unlink (element_1, element_2);
1516 element_1 = element_2;
1517 element_2 = va_arg (args, GstElement *);
1524 * gst_element_unlink:
1525 * @src: the source #GstElement to unlink.
1526 * @dest: the sink #GstElement to unlink.
1528 * Unlinks all source pads of the source element with all sink pads
1529 * of the sink element to which they are linked.
1532 gst_element_unlink (GstElement * src, GstElement * dest)
1535 gboolean done = FALSE;
1537 g_return_if_fail (GST_IS_ELEMENT (src));
1538 g_return_if_fail (GST_IS_ELEMENT (dest));
1540 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1541 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1543 pads = gst_element_iterate_pads (src);
1547 switch (gst_iterator_next (pads, &data)) {
1548 case GST_ITERATOR_OK:
1550 GstPad *pad = GST_PAD_CAST (data);
1552 if (GST_PAD_IS_SRC (pad)) {
1553 GstPad *peerpad = gst_pad_get_peer (pad);
1555 /* see if the pad is connected and is really a pad
1558 GstElement *peerelem;
1560 peerelem = gst_pad_get_parent_element (peerpad);
1562 if (peerelem == dest) {
1563 gst_pad_unlink (pad, peerpad);
1566 gst_object_unref (peerelem);
1568 gst_object_unref (peerpad);
1571 gst_object_unref (pad);
1574 case GST_ITERATOR_RESYNC:
1575 gst_iterator_resync (pads);
1577 case GST_ITERATOR_DONE:
1581 g_assert_not_reached ();
1588 gst_element_query_position (GstElement * element, GstFormat * format,
1589 gint64 * cur, gint64 * end)
1594 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1595 g_return_val_if_fail (format != NULL, FALSE);
1597 query = gst_query_new_position (*format);
1598 ret = gst_element_query (element, query);
1601 gst_query_parse_position (query, format, cur, end);
1603 gst_query_unref (query);
1609 gst_element_query_convert (GstElement * element, GstFormat src_format,
1610 gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
1615 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1616 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1617 g_return_val_if_fail (dest_val != NULL, FALSE);
1619 if (*dest_fmt == src_format) {
1620 *dest_val = src_val;
1624 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1625 ret = gst_element_query (element, query);
1628 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1630 gst_query_unref (query);
1638 * @srcpad: the source #GstPad to link.
1639 * @sinkpad: the sink #GstPad to link.
1641 * Checks if the source pad and the sink pad can be linked.
1642 * Both @srcpad and @sinkpad must be unlinked.
1644 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1647 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1649 /* FIXME This function is gross. It's almost a direct copy of
1650 * gst_pad_link_filtered(). Any decent programmer would attempt
1651 * to merge the two functions, which I will do some day. --ds
1654 /* generic checks */
1655 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1656 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1658 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1659 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1661 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1662 if (GST_PAD_PEER (srcpad) != NULL) {
1663 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1664 GST_DEBUG_PAD_NAME (srcpad));
1667 if (GST_PAD_PEER (sinkpad) != NULL) {
1668 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1669 GST_DEBUG_PAD_NAME (sinkpad));
1672 if (!GST_PAD_IS_SRC (srcpad)) {
1673 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1674 GST_DEBUG_PAD_NAME (srcpad));
1677 if (!GST_PAD_IS_SINK (sinkpad)) {
1678 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1679 GST_DEBUG_PAD_NAME (sinkpad));
1682 if (GST_PAD_PARENT (srcpad) == NULL) {
1683 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1684 GST_DEBUG_PAD_NAME (srcpad));
1687 if (GST_PAD_PARENT (sinkpad) == NULL) {
1688 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1689 GST_DEBUG_PAD_NAME (srcpad));
1697 * gst_pad_use_fixed_caps:
1698 * @pad: the pad to use
1700 * A helper function you can use that sets the
1701 * @gst_pad_get_fixed_caps_func as the gstcaps function for the
1702 * pad. This way the function will always return the negotiated caps
1703 * or in case the pad is not negotiated, the padtemplate caps.
1705 * Use this function on a pad that, once _set_caps() has been called
1706 * on it, it cannot be renegotiated to something else.
1709 gst_pad_use_fixed_caps (GstPad * pad)
1711 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1715 * gst_pad_get_fixed_caps_func:
1716 * @pad: the pad to use
1718 * A helper function you can use as a GetCaps function that
1719 * will return the currently negotiated caps or the padtemplate
1722 * Returns: The currently negotiated caps or the padtemplate.
1725 gst_pad_get_fixed_caps_func (GstPad * pad)
1729 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1731 if (GST_PAD_CAPS (pad)) {
1732 result = GST_PAD_CAPS (pad);
1734 GST_CAT_DEBUG (GST_CAT_CAPS,
1735 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1737 result = gst_caps_ref (result);
1740 if (GST_PAD_PAD_TEMPLATE (pad)) {
1741 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1743 result = GST_PAD_TEMPLATE_CAPS (templ);
1744 GST_CAT_DEBUG (GST_CAT_CAPS,
1745 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1748 result = gst_caps_ref (result);
1751 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1752 result = gst_caps_new_empty ();
1759 * gst_pad_get_parent_element:
1762 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
1763 * its parent is not an element, return NULL.
1765 * Returns: The parent of the pad. The caller has a reference on the parent, so
1766 * unref when you're finished with it.
1771 gst_pad_get_parent_element (GstPad * pad)
1775 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1777 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
1779 if (p && !GST_IS_ELEMENT (p)) {
1780 gst_object_unref (p);
1783 return GST_ELEMENT_CAST (p);
1787 * gst_object_default_error:
1788 * @source: the #GstObject that initiated the error.
1789 * @error: the GError.
1790 * @debug: an additional debug information string, or NULL.
1792 * A default error function.
1794 * The default handler will simply print the error string using g_print.
1797 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
1799 gchar *name = gst_object_get_path_string (source);
1801 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
1803 g_print (_("Additional debug info:\n%s\n"), debug);
1808 #ifdef GST_COMPILE_STATIC_REC_COND_WAIT
1810 #if GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P
1811 # define g_system_thread_equal_simple(thread1, thread2) \
1812 ((thread1).dummy_pointer == (thread2).dummy_pointer)
1813 # define g_system_thread_assign(dest, src) \
1814 ((dest).dummy_pointer = (src).dummy_pointer)
1815 #else /* GLIB_SIZEOF_SYSTEM_THREAD != SIZEOF_VOID_P */
1816 # define g_system_thread_equal_simple(thread1, thread2) \
1817 (memcmp (&(thread1), &(thread2), GLIB_SIZEOF_SYSTEM_THREAD) == 0)
1818 # define g_system_thread_assign(dest, src) \
1819 (memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
1820 #endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */
1822 #define g_system_thread_equal(thread1, thread2) \
1823 (g_thread_functions_for_glib_use.thread_equal ? \
1824 g_thread_functions_for_glib_use.thread_equal (&(thread1), &(thread2)) :\
1825 g_system_thread_equal_simple((thread1), (thread2)))
1827 static GSystemThread zero_thread;
1830 g_static_rec_cond_timed_wait (GCond * cond,
1831 GStaticRecMutex * mutex, GTimeVal * end_time)
1838 if (!g_thread_supported ())
1841 G_THREAD_UF (thread_self, (&self));
1843 g_return_val_if_fail (g_system_thread_equal (self, mutex->owner), FALSE);
1845 depth = mutex->depth;
1847 g_system_thread_assign (mutex->owner, zero_thread);
1849 smutex = g_static_mutex_get_mutex (&mutex->mutex);
1851 res = g_cond_timed_wait (cond, smutex, end_time);
1853 g_system_thread_assign (mutex->owner, self);
1854 mutex->depth = depth;
1860 g_static_rec_cond_wait (GCond * cond, GStaticRecMutex * mutex)
1862 g_static_rec_cond_timed_wait (cond, mutex, NULL);
1865 #endif /* GST_COMPILE_STATIC_REC_COND_WAIT */
1869 * @bin: the bin to add the elements to
1870 * @element_1: the first element to add to the bin
1871 * @...: additional elements to add to the bin
1873 * Adds a NULL-terminated list of elements to a bin. This function is
1874 * equivalent to calling gst_bin_add() for each member of the list.
1877 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
1881 g_return_if_fail (GST_IS_BIN (bin));
1882 g_return_if_fail (GST_IS_ELEMENT (element_1));
1884 va_start (args, element_1);
1887 gst_bin_add (bin, element_1);
1889 element_1 = va_arg (args, GstElement *);
1896 * gst_bin_remove_many:
1897 * @bin: the bin to remove the elements from
1898 * @element_1: the first element to remove from the bin
1899 * @...: NULL-terminated list of elements to remove from the bin
1901 * Remove a list of elements from a bin. This function is equivalent
1902 * to calling gst_bin_remove() with each member of the list.
1905 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
1909 g_return_if_fail (GST_IS_BIN (bin));
1910 g_return_if_fail (GST_IS_ELEMENT (element_1));
1912 va_start (args, element_1);
1915 gst_bin_remove (bin, element_1);
1917 element_1 = va_arg (args, GstElement *);
1924 get_state_func (GstElement * element, gpointer unused)
1926 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1928 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1929 "new thread waiting on state change");
1931 /* wait indefinitely */
1932 while (ret == GST_STATE_CHANGE_ASYNC)
1933 ret = gst_element_get_state (element, NULL, NULL, NULL);
1935 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1936 "thread done waiting on state change");
1938 gst_object_unref (element);
1942 * gst_bin_watch_for_state_change:
1943 * @bin: the bin to watch for state changes
1945 * Spawns a thread calling gst_element_get_state on @bin with infinite timeout.
1947 * In practice this is done because if a bin returns %GST_STATE_CHANGE_ASYNC
1948 * from a state change, it will not commit its state until someone calls
1949 * gst_element_get_state() on it. Thus having another thread checking the bin's
1950 * state will ensure that a state-changed message gets posted on the bus
1953 * This function is admittedly a bit of a hack. Bins should always post
1954 * messages. However this behavior was broken out into this function to avoid
1955 * spawning threads when scrubbing, when the bin's state is changing quickly and
1959 gst_bin_watch_for_state_change (GstBin * bin)
1961 static GThreadPool *pool = NULL;
1962 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
1964 g_static_mutex_lock (&mutex);
1966 pool = g_thread_pool_new ((GFunc) get_state_func, NULL, -1, FALSE, NULL);
1967 g_static_mutex_unlock (&mutex);
1969 g_thread_pool_push (pool, gst_object_ref (bin), NULL);
1972 struct _GstAsyncThreadData
1974 GstElement *element;
1979 set_state_async_thread_func (struct _GstAsyncThreadData *data, gpointer unused)
1981 GstState current, pending;
1982 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1984 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
1985 "new thread ensuring state change to %s",
1986 gst_element_state_get_name (data->state));
1989 /* wait indefinitely */
1990 ret = gst_element_get_state (data->element, ¤t, &pending, NULL);
1991 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
1992 "get_state returned %d, current %s, pending %s", ret,
1993 gst_element_state_get_name (current),
1994 gst_element_state_get_name (pending));
1996 /* can only be SUCCESS or FAILURE */
1997 if (ret == GST_STATE_CHANGE_FAILURE) {
1998 /* we can only break, hopefully an error message was posted as well */
1999 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2000 "FAILURE during state change");
2002 } else if (ret == GST_STATE_CHANGE_SUCCESS) {
2003 if (current == data->state) {
2004 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2005 "successfully reached final state");
2008 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2009 "setting target state %s again",
2010 gst_element_state_get_name (data->state));
2011 gst_element_set_state (data->element, data->state);
2013 g_assert_not_reached ();
2017 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2018 "thread done waiting on state change");
2020 gst_object_unref (data->element);
2025 * gst_element_set_state_async:
2026 * @element: a #GstElement to change state of
2027 * @state: the element's new #GstState
2029 * Sets the state of the element. This function will try to set the
2030 * requested state by going through all the intermediary states and calling
2031 * the class's state change function for each. If the state change returns
2032 * #GST_STATE_CHANGE_ASYNC at any time, a thread will be started to
2033 * monitor the state change and make sure the element is brought to the
2036 * Returns: Result of the state change using #GstStateChangeReturn.
2040 GstStateChangeReturn
2041 gst_element_set_state_async (GstElement * element, GstState state)
2043 GstStateChangeReturn ret;
2044 struct _GstAsyncThreadData *data;
2046 ret = gst_element_set_state (element, state);
2047 if (ret == GST_STATE_CHANGE_ASYNC) {
2048 static GThreadPool *pool = NULL;
2049 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
2051 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2052 "starting new thread to ensure state change to %s",
2053 gst_element_state_get_name (state));
2054 g_static_mutex_lock (&mutex);
2056 pool = g_thread_pool_new ((GFunc) set_state_async_thread_func,
2057 NULL, -1, FALSE, NULL);
2058 g_static_mutex_unlock (&mutex);
2060 data = g_new0 (struct _GstAsyncThreadData, 1);
2062 gst_object_ref (element);
2063 data->element = element;
2064 data->state = state;
2065 g_thread_pool_push (pool, data, NULL);
2072 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2073 guint arg_id, GParamFlags flags)
2075 GQuark prop_id = g_quark_from_string (prop_name);
2078 static GQuark fd_id = 0;
2079 static GQuark blocksize_id;
2080 static GQuark bytesperread_id;
2081 static GQuark dump_id;
2082 static GQuark filesize_id;
2083 static GQuark mmapsize_id;
2084 static GQuark location_id;
2085 static GQuark offset_id;
2086 static GQuark silent_id;
2087 static GQuark touch_id;
2090 fd_id = g_quark_from_static_string ("fd");
2091 blocksize_id = g_quark_from_static_string ("blocksize");
2092 bytesperread_id = g_quark_from_static_string ("bytesperread");
2093 dump_id = g_quark_from_static_string ("dump");
2094 filesize_id = g_quark_from_static_string ("filesize");
2095 mmapsize_id = g_quark_from_static_string ("mmapsize");
2096 location_id = g_quark_from_static_string ("location");
2097 offset_id = g_quark_from_static_string ("offset");
2098 silent_id = g_quark_from_static_string ("silent");
2099 touch_id = g_quark_from_static_string ("touch");
2102 if (prop_id == fd_id) {
2103 pspec = g_param_spec_int ("fd", "File-descriptor",
2104 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2105 } else if (prop_id == blocksize_id) {
2106 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2107 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2109 } else if (prop_id == bytesperread_id) {
2110 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2111 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2113 } else if (prop_id == dump_id) {
2114 pspec = g_param_spec_boolean ("dump", "Dump",
2115 "Dump bytes to stdout", FALSE, flags);
2117 } else if (prop_id == filesize_id) {
2118 pspec = g_param_spec_int64 ("filesize", "File Size",
2119 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2121 } else if (prop_id == mmapsize_id) {
2122 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2123 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2125 } else if (prop_id == location_id) {
2126 pspec = g_param_spec_string ("location", "File Location",
2127 "Location of the file to read", NULL, flags);
2129 } else if (prop_id == offset_id) {
2130 pspec = g_param_spec_int64 ("offset", "File Offset",
2131 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2133 } else if (prop_id == silent_id) {
2134 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2137 } else if (prop_id == touch_id) {
2138 pspec = g_param_spec_boolean ("touch", "Touch read data",
2139 "Touch data to force disk read before " "push ()", TRUE, flags);
2141 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2142 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2147 g_object_class_install_property (klass, arg_id, pspec);
2152 * gst_element_class_install_std_props:
2153 * @klass: the #GstElementClass to add the properties to.
2154 * @first_name: the name of the first property.
2155 * in a NULL terminated
2156 * @...: the id and flags of the first property, followed by
2157 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2159 * Adds a list of standardized properties with types to the @klass.
2160 * the id is for the property switch in your get_prop method, and
2161 * the flags determine readability / writeability.
2164 gst_element_class_install_std_props (GstElementClass * klass,
2165 const gchar * first_name, ...)
2171 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2173 va_start (args, first_name);
2178 int arg_id = va_arg (args, int);
2179 int flags = va_arg (args, int);
2181 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2184 name = va_arg (args, char *);
2193 * @buf1: a first source #GstBuffer to merge.
2194 * @buf2: the second source #GstBuffer to merge.
2196 * Create a new buffer that is the concatenation of the two source
2197 * buffers. The original source buffers will not be modified or
2198 * unref'd. Make sure you unref the source buffers if they are not used
2199 * anymore afterwards.
2201 * If the buffers point to contiguous areas of memory, the buffer
2202 * is created without copying the data.
2204 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2207 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2211 /* we're just a specific case of the more general gst_buffer_span() */
2212 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2219 * @buf1: a first source #GstBuffer to join.
2220 * @buf2: the second source #GstBuffer to join.
2222 * Create a new buffer that is the concatenation of the two source
2223 * buffers, and takes ownership of the original source buffers.
2225 * If the buffers point to contiguous areas of memory, the buffer
2226 * is created without copying the data.
2228 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2231 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2235 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2236 gst_buffer_unref (buf1);
2237 gst_buffer_unref (buf2);
2245 * @dest: buffer to stamp
2246 * @src: buffer to stamp from
2248 * Copies additional information (timestamps and offsets) from one buffer to
2252 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2254 g_return_if_fail (dest != NULL);
2255 g_return_if_fail (src != NULL);
2257 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
2258 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
2259 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
2260 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
2264 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2267 GstCaps *peercaps, *existing;
2269 existing = g_value_get_pointer (ret);
2270 peercaps = gst_pad_peer_get_caps (pad);
2271 if (peercaps == NULL)
2272 peercaps = gst_caps_new_any ();
2273 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2274 gst_caps_unref (existing);
2275 gst_caps_unref (peercaps);
2277 gst_object_unref (pad);
2282 * gst_pad_proxy_getcaps:
2283 * @pad: a #GstPad to proxy.
2285 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2286 * same element as @pad, and returns the intersection of the results.
2288 * This function is useful as a default getcaps function for an element
2289 * that can handle any stream format, but requires all its pads to have
2290 * the same caps. Two such elements are tee and aggregator.
2292 * Returns: the intersection of the other pads' allowed caps.
2295 gst_pad_proxy_getcaps (GstPad * pad)
2297 GstElement *element;
2298 GstCaps *caps, *intersected;
2300 GstIteratorResult res;
2301 GValue ret = { 0, };
2303 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2305 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2307 element = gst_pad_get_parent_element (pad);
2308 if (element == NULL)
2311 iter = gst_element_iterate_pads (element);
2313 g_value_init (&ret, G_TYPE_POINTER);
2314 g_value_set_pointer (&ret, gst_caps_new_any ());
2316 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2318 gst_iterator_free (iter);
2320 if (res != GST_ITERATOR_DONE)
2323 gst_object_unref (element);
2325 caps = g_value_get_pointer (&ret);
2326 g_value_unset (&ret);
2328 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2329 gst_caps_unref (caps);
2336 g_warning ("Pad list changed during capsnego for element %s",
2337 GST_ELEMENT_NAME (element));
2338 gst_object_unref (element);
2350 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2352 gboolean success = TRUE;
2354 if (pad != data->orig) {
2355 success = gst_pad_set_caps (pad, data->caps);
2356 g_value_set_boolean (ret, success);
2358 gst_object_unref (pad);
2364 * gst_pad_proxy_setcaps
2365 * @pad: a #GstPad to proxy from
2366 * @caps: the #GstCaps to link with
2368 * Calls gst_pad_set_caps() for every other pad belonging to the
2369 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2370 * the proxy setcaps fails. May be used only during negotiation.
2372 * Returns: TRUE if sucessful
2375 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2377 GstElement *element;
2379 GstIteratorResult res;
2380 GValue ret = { 0, };
2383 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2384 g_return_val_if_fail (caps != NULL, FALSE);
2386 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2388 element = gst_pad_get_parent_element (pad);
2389 if (element == NULL)
2392 iter = gst_element_iterate_pads (element);
2394 g_value_init (&ret, G_TYPE_BOOLEAN);
2395 g_value_set_boolean (&ret, TRUE);
2399 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2401 gst_iterator_free (iter);
2403 if (res != GST_ITERATOR_DONE)
2406 gst_object_unref (element);
2408 /* ok not to unset the gvalue */
2409 return g_value_get_boolean (&ret);
2414 g_warning ("Pad list changed during proxy_pad_link for element %s",
2415 GST_ELEMENT_NAME (element));
2416 gst_object_unref (element);
2422 * gst_pad_query_position:
2423 * @pad: a #GstPad to invoke the position query on.
2424 * @format: a pointer to the #GstFormat asked for.
2425 * On return contains the #GstFormat used.
2426 * @cur: A location in which to store the current position, or NULL.
2427 * @end: A location in which to store the end position (length), or NULL.
2429 * Queries a pad for the stream position and length.
2431 * Returns: TRUE if the query could be performed.
2434 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur,
2440 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2441 g_return_val_if_fail (format != NULL, FALSE);
2443 query = gst_query_new_position (*format);
2444 ret = gst_pad_query (pad, query);
2447 gst_query_parse_position (query, format, cur, end);
2449 gst_query_unref (query);
2455 * gst_pad_query_convert:
2456 * @pad: a #GstPad to invoke the convert query on.
2457 * @src_format: a #GstFormat to convert from.
2458 * @src_val: a value to convert.
2459 * @dest_format: a pointer to the #GstFormat to convert to.
2460 * @dest_val: a pointer to the result.
2462 * Queries a pad to convert @src_val in @src_format to @dest_format.
2464 * Returns: TRUE if the query could be performed.
2467 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2468 GstFormat * dest_format, gint64 * dest_val)
2473 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2474 g_return_val_if_fail (src_val >= 0, FALSE);
2475 g_return_val_if_fail (dest_format != NULL, FALSE);
2476 g_return_val_if_fail (dest_val != NULL, FALSE);
2478 if (*dest_format == src_format) {
2479 *dest_val = src_val;
2483 query = gst_query_new_convert (src_format, src_val, *dest_format);
2484 ret = gst_pad_query (pad, query);
2487 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2489 gst_query_unref (query);
2495 * gst_atomic_int_set:
2496 * @atomic_int: pointer to an atomic integer
2497 * @value: value to set
2499 * Unconditionally sets the atomic integer to @value.
2502 gst_atomic_int_set (gint * atomic_int, gint value)
2506 *atomic_int = value;
2507 /* read acts as a memory barrier */
2508 ignore = g_atomic_int_get (atomic_int);
2512 * gst_pad_add_data_probe:
2513 * @pad: pad to add the data probe handler to
2514 * @handler: function to call when data is passed over pad
2515 * @data: data to pass along with the handler
2517 * Adds a "data probe" to a pad. This function will be called whenever data
2518 * passes through a pad. In this case data means both events and buffers. The
2519 * probe will be called with the data as an argument. Note that the data will
2520 * have a reference count greater than 1, so it will be immutable -- you must
2523 * For source pads, the probe will be called after the blocking function, if any
2524 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2525 * to. For sink pads, the probe function will be called before configuring the
2526 * sink with new caps, if any, and before calling the pad's chain function.
2528 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2529 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2532 * Although probes are implemented internally by connecting @handler to the
2533 * have-data signal on the pad, if you want to remove a probe it is insufficient
2534 * to only call g_signal_handler_disconnect on the returned handler id. To
2535 * remove a probe, use the appropriate function, such as
2536 * gst_pad_remove_data_probe().
2538 * Returns: The handler id.
2541 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2545 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2546 g_return_val_if_fail (handler != NULL, 0);
2549 sigid = g_signal_connect (pad, "have-data", handler, data);
2550 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2551 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2552 GST_DEBUG ("adding data probe to pad %s:%s, now %d data, %d event probes",
2553 GST_DEBUG_PAD_NAME (pad),
2554 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2561 * gst_pad_add_event_probe:
2562 * @pad: pad to add the event probe handler to
2563 * @handler: function to call when data is passed over pad
2564 * @data: data to pass along with the handler
2566 * Adds a probe that will be called for all events passing through a pad. See
2567 * gst_pad_add_data_probe() for more information.
2569 * Returns: The handler id
2572 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
2576 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2577 g_return_val_if_fail (handler != NULL, 0);
2580 sigid = g_signal_connect (pad, "have-data::event", handler, data);
2581 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2582 GST_DEBUG ("adding event probe to pad %s:%s, now %d probes",
2583 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2590 * gst_pad_add_buffer_probe:
2591 * @pad: pad to add the buffer probe handler to
2592 * @handler: function to call when data is passed over pad
2593 * @data: data to pass along with the handler
2595 * Adds a probe that will be called for all buffers passing through a pad. See
2596 * gst_pad_add_data_probe() for more information.
2598 * Returns: The handler id
2601 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2605 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2606 g_return_val_if_fail (handler != NULL, 0);
2609 sigid = g_signal_connect (pad, "have-data::buffer", handler, data);
2610 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2611 GST_DEBUG ("adding buffer probe to pad %s:%s, now %d probes",
2612 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2619 * gst_pad_remove_data_probe:
2620 * @pad: pad to remove the data probe handler from
2621 * @handler_id: handler id returned from gst_pad_add_data_probe
2623 * Removes a data probe from @pad.
2626 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
2628 g_return_if_fail (GST_IS_PAD (pad));
2629 g_return_if_fail (handler_id > 0);
2632 g_signal_handler_disconnect (pad, handler_id);
2633 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2634 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2636 ("removed data probe from pad %s:%s, now %d event, %d buffer probes",
2637 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad),
2638 GST_PAD_DO_BUFFER_SIGNALS (pad));
2643 * gst_pad_remove_event_probe:
2644 * @pad: pad to remove the event probe handler from
2645 * @handler_id: handler id returned from gst_pad_add_event_probe
2647 * Removes an event probe from @pad.
2650 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
2652 g_return_if_fail (GST_IS_PAD (pad));
2653 g_return_if_fail (handler_id > 0);
2656 g_signal_handler_disconnect (pad, handler_id);
2657 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2658 GST_DEBUG ("removed event probe from pad %s:%s, now %d event probes",
2659 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2664 * gst_pad_remove_buffer_probe:
2665 * @pad: pad to remove the buffer probe handler from
2666 * @handler_id: handler id returned from gst_pad_add_buffer_probe
2668 * Removes a buffer probe from @pad.
2671 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
2673 g_return_if_fail (GST_IS_PAD (pad));
2674 g_return_if_fail (handler_id > 0);
2677 g_signal_handler_disconnect (pad, handler_id);
2678 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2679 GST_DEBUG ("removed buffer probe from pad %s:%s, now %d buffer probes",
2680 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2685 * gst_element_found_tags_for_pad:
2686 * @element: element for which to post taglist to bus.
2687 * @pad: pad on which to push tag-event.
2688 * @list: the taglist to post on the bus and create event from.
2690 * Posts a message to the bus that new tags were found and pushes the
2691 * tags as event. Takes ownership of the taglist.
2694 gst_element_found_tags_for_pad (GstElement * element,
2695 GstPad * pad, GstTagList * list)
2697 g_return_if_fail (element != NULL);
2698 g_return_if_fail (pad != NULL);
2699 g_return_if_fail (list != NULL);
2701 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
2702 gst_element_post_message (element,
2703 gst_message_new_tag (GST_OBJECT (element), list));
2707 push_and_ref (GstPad * pad, GstEvent * event)
2709 gst_pad_push_event (pad, gst_event_ref (event));
2713 * gst_element_found_tags:
2714 * @element: element for which we found the tags.
2715 * @list: list of tags.
2717 * Posts a message to the bus that new tags were found, and pushes an event
2718 * to all sourcepads. Takes ownership of the taglist.
2721 gst_element_found_tags (GstElement * element, GstTagList * list)
2726 g_return_if_fail (element != NULL);
2727 g_return_if_fail (list != NULL);
2729 iter = gst_element_iterate_src_pads (element);
2730 event = gst_event_new_tag (gst_tag_list_copy (list));
2731 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
2732 gst_iterator_free (iter);
2733 gst_event_unref (event);
2735 gst_element_post_message (element,
2736 gst_message_new_tag (GST_OBJECT (element), list));