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 * gst_util_uint64_scale:
304 * @val: the number to scale
305 * @num: the numerator of the scale ratio
306 * @denom: the denominator of the scale ratio
308 * Scale @val by @num / @denom, trying to avoid overflows.
310 * Returns: @val * @num / @denom, trying to avoid overflows.
313 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
315 /* implement me with fixed point, if you care */
316 return val * (((double) num) / denom);
319 /* -----------------------------------------------------
321 * The following code will be moved out of the main
322 * gstreamer library someday.
328 string_append_indent (GString * str, gint count)
332 for (xx = 0; xx < count; xx++)
333 g_string_append_c (str, ' ');
337 * gst_print_pad_caps:
338 * @buf: the buffer to print the caps in
339 * @indent: initial indentation
340 * @pad: the pad to print the caps from
342 * Write the pad capabilities in a human readable format into
346 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
353 string_append_indent (buf, indent);
354 g_string_printf (buf, "%s:%s has no capabilities",
355 GST_DEBUG_PAD_NAME (pad));
359 s = gst_caps_to_string (caps);
360 g_string_append (buf, s);
366 * gst_print_element_args:
367 * @buf: the buffer to print the args in
368 * @indent: initial indentation
369 * @element: the element to print the args of
371 * Print the element argument in a human readable format in the given
375 gst_print_element_args (GString * buf, gint indent, GstElement * element)
378 GValue value = { 0, }; /* the important thing is that value.type = 0 */
380 GParamSpec *spec, **specs, **walk;
382 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
385 for (walk = specs; *walk; walk++) {
387 if (width < strlen (spec->name))
388 width = strlen (spec->name);
391 for (walk = specs; *walk; walk++) {
394 if (spec->flags & G_PARAM_READABLE) {
395 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
396 g_object_get_property (G_OBJECT (element), spec->name, &value);
397 str = g_strdup_value_contents (&value);
398 g_value_unset (&value);
400 str = g_strdup ("Parameter not readable.");
403 string_append_indent (buf, indent);
404 g_string_append (buf, spec->name);
405 string_append_indent (buf, 2 + width - strlen (spec->name));
406 g_string_append (buf, str);
407 g_string_append_c (buf, '\n');
416 * gst_element_create_all_pads:
417 * @element: a #GstElement to create pads for
419 * Creates a pad for each pad template that is always available.
420 * This function is only useful during object intialization of
421 * subclasses of #GstElement.
424 gst_element_create_all_pads (GstElement * element)
428 /* FIXME: lock element */
431 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
432 (G_OBJECT_GET_CLASS (element)));
435 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
437 if (padtempl->presence == GST_PAD_ALWAYS) {
440 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
442 gst_element_add_pad (element, pad);
444 padlist = padlist->next;
449 * gst_element_get_compatible_pad_template:
450 * @element: a #GstElement to get a compatible pad template for.
451 * @compattempl: the #GstPadTemplate to find a compatible template for.
453 * Retrieves a pad template from @element that is compatible with @compattempl.
454 * Pads from compatible templates can be linked together.
456 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
457 * unreferencing is necessary.
460 gst_element_get_compatible_pad_template (GstElement * element,
461 GstPadTemplate * compattempl)
463 GstPadTemplate *newtempl = NULL;
465 GstElementClass *class;
467 g_return_val_if_fail (element != NULL, NULL);
468 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
469 g_return_val_if_fail (compattempl != NULL, NULL);
471 class = GST_ELEMENT_GET_CLASS (element);
473 padlist = gst_element_class_get_pad_template_list (class);
475 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
476 "Looking for a suitable pad template in %s out of %d templates...",
477 GST_ELEMENT_NAME (element), g_list_length (padlist));
480 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
481 GstCaps *intersection;
485 * Check direction (must be opposite)
488 GST_CAT_LOG (GST_CAT_CAPS,
489 "checking pad template %s", padtempl->name_template);
490 if (padtempl->direction != compattempl->direction) {
491 GST_CAT_DEBUG (GST_CAT_CAPS,
492 "compatible direction: found %s pad template \"%s\"",
493 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
494 padtempl->name_template);
496 GST_CAT_DEBUG (GST_CAT_CAPS,
497 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
498 GST_CAT_DEBUG (GST_CAT_CAPS,
499 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
501 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
502 GST_PAD_TEMPLATE_CAPS (padtempl));
504 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
505 (intersection ? "" : "not "), intersection);
507 if (!gst_caps_is_empty (intersection))
509 gst_caps_unref (intersection);
514 padlist = g_list_next (padlist);
517 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
518 "Returning new pad template %p", newtempl);
520 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
526 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
529 GstPad *newpad = NULL;
530 GstElementClass *oclass;
532 oclass = GST_ELEMENT_GET_CLASS (element);
534 if (oclass->request_new_pad)
535 newpad = (oclass->request_new_pad) (element, templ, name);
538 gst_object_ref (newpad);
546 * gst_element_get_pad_from_template:
547 * @element: a #GstElement.
548 * @templ: a #GstPadTemplate belonging to @element.
550 * Gets a pad from @element described by @templ. If the presence of @templ is
551 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
554 * Returns: the #GstPad, or NULL if one could not be found or created.
557 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
560 GstPadPresence presence;
562 /* If this function is ever exported, we need check the validity of `element'
563 * and `templ', and to make sure the template actually belongs to the
566 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
570 case GST_PAD_SOMETIMES:
571 ret = gst_element_get_static_pad (element, templ->name_template);
572 if (!ret && presence == GST_PAD_ALWAYS)
574 ("Element %s has an ALWAYS template %s, but no pad of the same name",
575 GST_OBJECT_NAME (element), templ->name_template);
578 case GST_PAD_REQUEST:
579 ret = gst_element_request_pad (element, templ, NULL);
587 * gst_element_request_compatible_pad:
588 * @element: a #GstElement.
589 * @templ: the #GstPadTemplate to which the new pad should be able to link.
591 * Requests a pad from @element. The returned pad should be unlinked and
592 * compatible with @templ. Might return an existing pad, or request a new one.
594 * Returns: a #GstPad, or %NULL if one could not be found or created.
597 gst_element_request_compatible_pad (GstElement * element,
598 GstPadTemplate * templ)
600 GstPadTemplate *templ_new;
603 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
604 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
606 /* FIXME: should really loop through the templates, testing each for
607 * compatibility and pad availability. */
608 templ_new = gst_element_get_compatible_pad_template (element, templ);
610 pad = gst_element_get_pad_from_template (element, templ_new);
612 /* This can happen for non-request pads. No need to unref. */
613 if (pad && GST_PAD_PEER (pad))
620 * gst_element_get_compatible_pad:
621 * @element: a #GstElement in which the pad should be found.
622 * @pad: the #GstPad to find a compatible one for.
623 * @caps: the #GstCaps to use as a filter.
625 * Looks for an unlinked pad to which the given pad can link. It is not
626 * guaranteed that linking the pads will work, though it should work in most
629 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
633 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
634 const GstCaps * caps)
637 GstPadTemplate *templ;
639 GstPad *foundpad = NULL;
642 /* FIXME check for caps compatibility */
644 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
645 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
647 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
648 "finding pad in %s compatible with %s:%s",
649 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
651 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
654 /* try to get an existing unlinked pad */
655 pads = gst_element_iterate_pads (element);
659 switch (gst_iterator_next (pads, &padptr)) {
660 case GST_ITERATOR_OK:
665 current = GST_PAD (padptr);
667 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
668 GST_DEBUG_PAD_NAME (current));
670 peer = gst_pad_get_peer (current);
672 if (peer == NULL && gst_pad_can_link (pad, current)) {
674 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
675 "found existing unlinked pad %s:%s",
676 GST_DEBUG_PAD_NAME (current));
678 gst_iterator_free (pads);
682 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
684 gst_object_unref (current);
686 gst_object_unref (peer);
690 case GST_ITERATOR_DONE:
693 case GST_ITERATOR_RESYNC:
694 gst_iterator_resync (pads);
696 case GST_ITERATOR_ERROR:
697 g_assert_not_reached ();
701 gst_iterator_free (pads);
703 /* try to create a new one */
704 /* requesting is a little crazy, we need a template. Let's create one */
705 templcaps = gst_pad_get_caps (pad);
707 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
708 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
709 foundpad = gst_element_request_compatible_pad (element, templ);
710 gst_object_unref (templ);
713 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
714 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
718 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
719 "Could not find a compatible pad to link to %s:%s",
720 GST_DEBUG_PAD_NAME (pad));
725 * gst_element_state_get_name:
726 * @state: a #GstState to get the name of.
728 * Gets a string representing the given state.
730 * Returns: a string with the name of the state.
733 gst_element_state_get_name (GstState state)
736 #ifdef GST_DEBUG_COLOR
737 case GST_STATE_VOID_PENDING:
738 return "VOID_PENDING";
741 return "\033[01;34mNULL\033[00m";
743 case GST_STATE_READY:
744 return "\033[01;31mREADY\033[00m";
746 case GST_STATE_PLAYING:
747 return "\033[01;32mPLAYING\033[00m";
749 case GST_STATE_PAUSED:
750 return "\033[01;33mPAUSED\033[00m";
753 /* This is a memory leak */
754 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
756 case GST_STATE_VOID_PENDING:
757 return "VOID_PENDING";
762 case GST_STATE_READY:
765 case GST_STATE_PLAYING:
768 case GST_STATE_PAUSED:
772 /* This is a memory leak */
773 return g_strdup_printf ("UNKNOWN!(%d)", state);
780 * gst_element_factory_can_src_caps :
781 * @factory: factory to query
782 * @caps: the caps to check
784 * Checks if the factory can source the given capability.
786 * Returns: true if it can src the capabilities
789 gst_element_factory_can_src_caps (GstElementFactory * factory,
790 const GstCaps * caps)
794 g_return_val_if_fail (factory != NULL, FALSE);
795 g_return_val_if_fail (caps != NULL, FALSE);
797 templates = factory->staticpadtemplates;
800 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
802 if (template->direction == GST_PAD_SRC) {
803 if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
807 templates = g_list_next (templates);
814 * gst_element_factory_can_sink_caps :
815 * @factory: factory to query
816 * @caps: the caps to check
818 * Checks if the factory can sink the given capability.
820 * Returns: true if it can sink the capabilities
823 gst_element_factory_can_sink_caps (GstElementFactory * factory,
824 const GstCaps * caps)
828 g_return_val_if_fail (factory != NULL, FALSE);
829 g_return_val_if_fail (caps != NULL, FALSE);
831 templates = factory->staticpadtemplates;
834 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
836 if (template->direction == GST_PAD_SINK) {
837 if (gst_caps_is_always_compatible (caps,
838 gst_static_caps_get (&template->static_caps)))
841 templates = g_list_next (templates);
848 /* if return val is true, *direct_child is a caller-owned ref on the direct
849 * child of ancestor that is part of object's ancestry */
851 object_has_ancestor (GstObject * object, GstObject * ancestor,
852 GstObject ** direct_child)
854 GstObject *child, *parent;
857 *direct_child = NULL;
859 child = gst_object_ref (object);
860 parent = gst_object_get_parent (object);
863 if (ancestor == parent) {
865 *direct_child = child;
867 gst_object_unref (child);
868 gst_object_unref (parent);
872 gst_object_unref (child);
874 parent = gst_object_get_parent (parent);
877 gst_object_unref (child);
882 /* caller owns return */
884 find_common_root (GstObject * o1, GstObject * o2)
887 GstObject *kid1, *kid2;
888 GstObject *root = NULL;
890 while (GST_OBJECT_PARENT (top))
891 top = GST_OBJECT_PARENT (top);
893 /* the itsy-bitsy spider... */
895 if (!object_has_ancestor (o2, top, &kid2))
898 root = gst_object_ref (top);
900 if (!object_has_ancestor (o1, kid2, &kid1)) {
901 gst_object_unref (kid2);
905 if (!object_has_ancestor (o2, kid1, &kid2)) {
906 gst_object_unref (kid1);
913 /* caller does not own return */
915 ghost_up (GstElement * e, GstPad * pad)
917 static gint ghost_pad_index = 0;
920 GstObject *parent = GST_OBJECT_PARENT (e);
922 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
923 gpad = gst_ghost_pad_new (name, pad);
926 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
927 g_warning ("Pad named %s already exists in element %s\n",
928 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
929 gst_object_unref ((GstObject *) gpad);
937 remove_pad (gpointer ppad, gpointer unused)
941 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
942 g_warning ("Couldn't remove pad %s from element %s",
943 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
947 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
948 GSList ** pads_created)
952 GSList *pads_created_local = NULL;
954 g_assert (pads_created);
956 e1 = GST_OBJECT_PARENT (*src);
957 e2 = GST_OBJECT_PARENT (*sink);
959 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
960 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
961 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
965 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
966 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
968 /* we need to setup some ghost pads */
969 root = find_common_root (e1, e2);
972 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
973 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
977 while (GST_OBJECT_PARENT (e1) != root) {
978 *src = ghost_up ((GstElement *) e1, *src);
981 e1 = GST_OBJECT_PARENT (*src);
982 pads_created_local = g_slist_prepend (pads_created_local, *src);
984 while (GST_OBJECT_PARENT (e2) != root) {
985 *sink = ghost_up ((GstElement *) e2, *sink);
988 e2 = GST_OBJECT_PARENT (*sink);
989 pads_created_local = g_slist_prepend (pads_created_local, *sink);
992 gst_object_unref (root);
993 *pads_created = g_slist_concat (*pads_created, pads_created_local);
997 gst_object_unref (root);
998 g_slist_foreach (pads_created_local, remove_pad, NULL);
999 g_slist_free (pads_created_local);
1004 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
1006 GSList *pads_created = NULL;
1009 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
1012 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
1016 g_slist_foreach (pads_created, remove_pad, NULL);
1018 g_slist_free (pads_created);
1024 * gst_element_link_pads:
1025 * @src: a #GstElement containing the source pad.
1026 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1027 * @dest: the #GstElement containing the destination pad.
1028 * @destpadname: the name of the #GstPad in destination element,
1029 * or NULL for any pad.
1031 * Links the two named pads of the source and destination elements.
1032 * Side effect is that if one of the pads has no parent, it becomes a
1033 * child of the parent of the other element. If they have different
1034 * parents, the link fails.
1036 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1039 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1040 GstElement * dest, const gchar * destpadname)
1042 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1043 GstPad *srcpad, *destpad;
1044 GstPadTemplate *srctempl, *desttempl;
1045 GstElementClass *srcclass, *destclass;
1048 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1049 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1051 srcclass = GST_ELEMENT_GET_CLASS (src);
1052 destclass = GST_ELEMENT_GET_CLASS (dest);
1054 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1055 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1056 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1057 destpadname ? destpadname : "(any)");
1061 /* name specified, look it up */
1062 srcpad = gst_element_get_pad (src, srcpadname);
1064 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1065 GST_ELEMENT_NAME (src), srcpadname);
1068 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1069 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1070 GST_DEBUG_PAD_NAME (srcpad));
1071 gst_object_unref (srcpad);
1074 if (GST_PAD_PEER (srcpad) != NULL) {
1075 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1076 GST_DEBUG_PAD_NAME (srcpad));
1077 gst_object_unref (srcpad);
1083 /* no name given, get the first available pad */
1085 srcpads = GST_ELEMENT_PADS (src);
1086 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1088 gst_object_ref (srcpad);
1092 /* get a destination pad */
1094 /* name specified, look it up */
1095 destpad = gst_element_get_pad (dest, destpadname);
1097 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1098 GST_ELEMENT_NAME (dest), destpadname);
1101 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1102 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1103 GST_DEBUG_PAD_NAME (destpad));
1104 gst_object_unref (destpad);
1107 if (GST_PAD_PEER (destpad) != NULL) {
1108 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1109 GST_DEBUG_PAD_NAME (destpad));
1110 gst_object_unref (destpad);
1116 /* no name given, get the first available pad */
1118 destpads = GST_ELEMENT_PADS (dest);
1119 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1121 gst_object_ref (destpad);
1125 if (srcpadname && destpadname) {
1128 /* two explicitly specified pads */
1129 result = pad_link_maybe_ghosting (srcpad, destpad);
1131 gst_object_unref (srcpad);
1132 gst_object_unref (destpad);
1138 /* loop through the allowed pads in the source, trying to find a
1139 * compatible destination pad */
1140 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1141 "looping through allowed src and dest pads");
1143 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1144 GST_DEBUG_PAD_NAME (srcpad));
1145 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1146 (GST_PAD_PEER (srcpad) == NULL)) {
1151 gst_object_ref (temp);
1153 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1156 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1157 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1158 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1160 gst_object_unref (destpad);
1161 gst_object_unref (srcpad);
1162 gst_object_unref (temp);
1167 gst_object_unref (temp);
1170 /* find a better way for this mess */
1172 srcpads = g_list_next (srcpads);
1174 gst_object_unref (srcpad);
1175 srcpad = GST_PAD_CAST (srcpads->data);
1176 gst_object_ref (srcpad);
1182 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1183 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1185 gst_object_unref (srcpad);
1188 gst_object_unref (destpad);
1192 gst_object_unref (srcpad);
1197 /* loop through the existing pads in the destination */
1199 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1200 GST_DEBUG_PAD_NAME (destpad));
1201 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1202 (GST_PAD_PEER (destpad) == NULL)) {
1203 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1205 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1206 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1207 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1208 gst_object_unref (temp);
1209 gst_object_unref (destpad);
1211 gst_object_unref (srcpad);
1215 gst_object_unref (temp);
1219 destpads = g_list_next (destpads);
1221 gst_object_unref (destpad);
1222 destpad = GST_PAD_CAST (destpads->data);
1223 gst_object_ref (destpad);
1230 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1231 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1232 gst_object_unref (destpad);
1234 gst_object_unref (srcpad);
1238 gst_object_unref (srcpad);
1241 gst_object_unref (destpad);
1245 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1246 "we might have request pads on both sides, checking...");
1247 srctempls = gst_element_class_get_pad_template_list (srcclass);
1248 desttempls = gst_element_class_get_pad_template_list (destclass);
1250 if (srctempls && desttempls) {
1252 srctempl = (GstPadTemplate *) srctempls->data;
1253 if (srctempl->presence == GST_PAD_REQUEST) {
1254 for (l = desttempls; l; l = l->next) {
1255 desttempl = (GstPadTemplate *) l->data;
1256 if (desttempl->presence == GST_PAD_REQUEST &&
1257 desttempl->direction != srctempl->direction) {
1258 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1259 (srctempl), gst_pad_template_get_caps (desttempl))) {
1261 gst_element_get_request_pad (src, srctempl->name_template);
1263 gst_element_get_request_pad (dest, desttempl->name_template);
1264 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1265 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1266 "linked pad %s:%s to pad %s:%s",
1267 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1268 gst_object_unref (srcpad);
1269 gst_object_unref (destpad);
1272 /* it failed, so we release the request pads */
1273 gst_element_release_request_pad (src, srcpad);
1274 gst_element_release_request_pad (dest, destpad);
1279 srctempls = srctempls->next;
1283 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1284 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1289 * gst_element_link_pads_filtered:
1290 * @src: a #GstElement containing the source pad.
1291 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1292 * @dest: the #GstElement containing the destination pad.
1293 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1294 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1296 * Links the two named pads of the source and destination elements. Side effect
1297 * is that if one of the pads has no parent, it becomes a child of the parent of
1298 * the other element. If they have different parents, the link fails. If @caps
1299 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1301 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1304 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1305 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1308 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1309 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1310 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1313 GstElement *capsfilter;
1315 GstState state, pending;
1318 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1320 GST_ERROR ("Could not make a capsfilter");
1324 parent = gst_object_get_parent (GST_OBJECT (src));
1325 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1327 GST_TIME_TO_TIMEVAL (0, tv);
1328 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, &tv);
1330 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1331 GST_ERROR ("Could not add capsfilter");
1332 gst_object_unref (capsfilter);
1333 gst_object_unref (parent);
1337 if (pending != GST_STATE_VOID_PENDING)
1340 gst_element_set_state (capsfilter, state);
1342 gst_object_unref (parent);
1344 g_object_set (capsfilter, "caps", filter, NULL);
1346 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1347 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1350 GST_INFO ("Could not link elements");
1351 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1352 /* will unref and unlink as appropriate */
1356 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1362 * @src: a #GstElement containing the source pad.
1363 * @dest: the #GstElement containing the destination pad.
1365 * Links @src to @dest. The link must be from source to
1366 * destination; the other direction will not be tried. The function looks for
1367 * existing pads that aren't linked yet. It will request new pads if necessary.
1368 * If multiple links are possible, only one is established.
1370 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1373 gst_element_link (GstElement * src, GstElement * dest)
1375 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1379 * gst_element_link_many:
1380 * @element_1: the first #GstElement in the link chain.
1381 * @element_2: the second #GstElement in the link chain.
1382 * @...: the NULL-terminated list of elements to link in order.
1384 * Chain together a series of elements. Uses gst_element_link().
1386 * Returns: TRUE on success, FALSE otherwise.
1389 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1393 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1394 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1396 va_start (args, element_2);
1399 if (!gst_element_link (element_1, element_2))
1402 element_1 = element_2;
1403 element_2 = va_arg (args, GstElement *);
1412 * gst_element_link_filtered:
1413 * @src: a #GstElement containing the source pad.
1414 * @dest: the #GstElement containing the destination pad.
1415 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1417 * Links @src to @dest using the given caps as filtercaps.
1418 * The link must be from source to
1419 * destination; the other direction will not be tried. The function looks for
1420 * existing pads that aren't linked yet. It will request new pads if necessary.
1421 * If multiple links are possible, only one is established.
1423 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1426 gst_element_link_filtered (GstElement * src, GstElement * dest,
1429 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1433 * gst_element_unlink_pads:
1434 * @src: a #GstElement containing the source pad.
1435 * @srcpadname: the name of the #GstPad in source element.
1436 * @dest: a #GstElement containing the destination pad.
1437 * @destpadname: the name of the #GstPad in destination element.
1439 * Unlinks the two named pads of the source and destination elements.
1442 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1443 GstElement * dest, const gchar * destpadname)
1445 GstPad *srcpad, *destpad;
1447 g_return_if_fail (src != NULL);
1448 g_return_if_fail (GST_IS_ELEMENT (src));
1449 g_return_if_fail (srcpadname != NULL);
1450 g_return_if_fail (dest != NULL);
1451 g_return_if_fail (GST_IS_ELEMENT (dest));
1452 g_return_if_fail (destpadname != NULL);
1454 /* obtain the pads requested */
1455 srcpad = gst_element_get_pad (src, srcpadname);
1456 if (srcpad == NULL) {
1457 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1460 destpad = gst_element_get_pad (dest, destpadname);
1461 if (srcpad == NULL) {
1462 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1467 /* we're satisified they can be unlinked, let's do it */
1468 gst_pad_unlink (srcpad, destpad);
1472 * gst_element_unlink_many:
1473 * @element_1: the first #GstElement in the link chain.
1474 * @element_2: the second #GstElement in the link chain.
1475 * @...: the NULL-terminated list of elements to unlink in order.
1477 * Unlinks a series of elements. Uses gst_element_unlink().
1480 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1484 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1485 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1487 va_start (args, element_2);
1490 gst_element_unlink (element_1, element_2);
1492 element_1 = element_2;
1493 element_2 = va_arg (args, GstElement *);
1500 * gst_element_unlink:
1501 * @src: the source #GstElement to unlink.
1502 * @dest: the sink #GstElement to unlink.
1504 * Unlinks all source pads of the source element with all sink pads
1505 * of the sink element to which they are linked.
1508 gst_element_unlink (GstElement * src, GstElement * dest)
1511 gboolean done = FALSE;
1513 g_return_if_fail (GST_IS_ELEMENT (src));
1514 g_return_if_fail (GST_IS_ELEMENT (dest));
1516 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1517 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1519 pads = gst_element_iterate_pads (src);
1523 switch (gst_iterator_next (pads, &data)) {
1524 case GST_ITERATOR_OK:
1526 GstPad *pad = GST_PAD_CAST (data);
1528 if (GST_PAD_IS_SRC (pad)) {
1529 GstPad *peerpad = gst_pad_get_peer (pad);
1531 /* see if the pad is connected and is really a pad
1534 GstElement *peerelem;
1536 peerelem = gst_pad_get_parent_element (peerpad);
1538 if (peerelem == dest) {
1539 gst_pad_unlink (pad, peerpad);
1542 gst_object_unref (peerelem);
1544 gst_object_unref (peerpad);
1547 gst_object_unref (pad);
1550 case GST_ITERATOR_RESYNC:
1551 gst_iterator_resync (pads);
1553 case GST_ITERATOR_DONE:
1557 g_assert_not_reached ();
1564 gst_element_query_position (GstElement * element, GstFormat * format,
1565 gint64 * cur, gint64 * end)
1570 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1571 g_return_val_if_fail (format != NULL, FALSE);
1573 query = gst_query_new_position (*format);
1574 ret = gst_element_query (element, query);
1577 gst_query_parse_position (query, format, cur, end);
1579 gst_query_unref (query);
1585 gst_element_query_convert (GstElement * element, GstFormat src_format,
1586 gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
1591 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1592 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1593 g_return_val_if_fail (dest_val != NULL, FALSE);
1595 if (*dest_fmt == src_format) {
1596 *dest_val = src_val;
1600 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1601 ret = gst_element_query (element, query);
1604 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1606 gst_query_unref (query);
1614 * @srcpad: the source #GstPad to link.
1615 * @sinkpad: the sink #GstPad to link.
1617 * Checks if the source pad and the sink pad can be linked.
1618 * Both @srcpad and @sinkpad must be unlinked.
1620 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1623 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1625 /* FIXME This function is gross. It's almost a direct copy of
1626 * gst_pad_link_filtered(). Any decent programmer would attempt
1627 * to merge the two functions, which I will do some day. --ds
1630 /* generic checks */
1631 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1632 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1634 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1635 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1637 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1638 if (GST_PAD_PEER (srcpad) != NULL) {
1639 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1640 GST_DEBUG_PAD_NAME (srcpad));
1643 if (GST_PAD_PEER (sinkpad) != NULL) {
1644 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1645 GST_DEBUG_PAD_NAME (sinkpad));
1648 if (!GST_PAD_IS_SRC (srcpad)) {
1649 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1650 GST_DEBUG_PAD_NAME (srcpad));
1653 if (!GST_PAD_IS_SINK (sinkpad)) {
1654 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1655 GST_DEBUG_PAD_NAME (sinkpad));
1658 if (GST_PAD_PARENT (srcpad) == NULL) {
1659 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1660 GST_DEBUG_PAD_NAME (srcpad));
1663 if (GST_PAD_PARENT (sinkpad) == NULL) {
1664 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1665 GST_DEBUG_PAD_NAME (srcpad));
1673 * gst_pad_use_fixed_caps:
1674 * @pad: the pad to use
1676 * A helper function you can use that sets the
1677 * @gst_pad_get_fixed_caps_func as the gstcaps function for the
1678 * pad. This way the function will always return the negotiated caps
1679 * or in case the pad is not negotiated, the padtemplate caps.
1681 * Use this function on a pad that, once _set_caps() has been called
1682 * on it, it cannot be renegotiated to something else.
1685 gst_pad_use_fixed_caps (GstPad * pad)
1687 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1691 * gst_pad_get_fixed_caps_func:
1692 * @pad: the pad to use
1694 * A helper function you can use as a GetCaps function that
1695 * will return the currently negotiated caps or the padtemplate
1698 * Returns: The currently negotiated caps or the padtemplate.
1701 gst_pad_get_fixed_caps_func (GstPad * pad)
1705 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1707 if (GST_PAD_CAPS (pad)) {
1708 result = GST_PAD_CAPS (pad);
1710 GST_CAT_DEBUG (GST_CAT_CAPS,
1711 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1713 result = gst_caps_ref (result);
1716 if (GST_PAD_PAD_TEMPLATE (pad)) {
1717 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1719 result = GST_PAD_TEMPLATE_CAPS (templ);
1720 GST_CAT_DEBUG (GST_CAT_CAPS,
1721 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1724 result = gst_caps_ref (result);
1727 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1728 result = gst_caps_new_empty ();
1735 * gst_pad_get_parent_element:
1738 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
1739 * its parent is not an element, return NULL.
1741 * Returns: The parent of the pad. The caller has a reference on the parent, so
1742 * unref when you're finished with it.
1747 gst_pad_get_parent_element (GstPad * pad)
1751 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1753 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
1755 if (p && !GST_IS_ELEMENT (p)) {
1756 gst_object_unref (p);
1759 return GST_ELEMENT_CAST (p);
1763 * gst_flow_get_name:
1764 * @ret: a #GstFlowReturn to get the name of.
1766 * Gets a string representing the given flow return.
1768 * Returns: a string with the name of the flow return.
1770 G_CONST_RETURN gchar *
1771 gst_flow_get_name (GstFlowReturn ret)
1774 case GST_FLOW_RESEND:
1775 return "RESEND_BUFFER";
1778 /* expected failures */
1779 case GST_FLOW_NOT_LINKED:
1780 return "NOT_LINKED";
1781 case GST_FLOW_WRONG_STATE:
1782 return "WRONG_STATE";
1784 case GST_FLOW_UNEXPECTED:
1785 return "UNEXPECTED";
1786 case GST_FLOW_NOT_NEGOTIATED:
1787 return "NOT_NEGOTIATED";
1788 case GST_FLOW_ERROR:
1790 case GST_FLOW_NOT_SUPPORTED:
1791 return "NOT_SUPPORTED";
1793 return "UNKNOWN error";
1798 * gst_object_default_error:
1799 * @source: the #GstObject that initiated the error.
1800 * @error: the GError.
1801 * @debug: an additional debug information string, or NULL.
1803 * A default error function.
1805 * The default handler will simply print the error string using g_print.
1808 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
1810 gchar *name = gst_object_get_path_string (source);
1812 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
1814 g_print (_("Additional debug info:\n%s\n"), debug);
1819 #ifdef GST_COMPILE_STATIC_REC_COND_WAIT
1821 #if GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P
1822 # define g_system_thread_equal_simple(thread1, thread2) \
1823 ((thread1).dummy_pointer == (thread2).dummy_pointer)
1824 # define g_system_thread_assign(dest, src) \
1825 ((dest).dummy_pointer = (src).dummy_pointer)
1826 #else /* GLIB_SIZEOF_SYSTEM_THREAD != SIZEOF_VOID_P */
1827 # define g_system_thread_equal_simple(thread1, thread2) \
1828 (memcmp (&(thread1), &(thread2), GLIB_SIZEOF_SYSTEM_THREAD) == 0)
1829 # define g_system_thread_assign(dest, src) \
1830 (memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
1831 #endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */
1833 #define g_system_thread_equal(thread1, thread2) \
1834 (g_thread_functions_for_glib_use.thread_equal ? \
1835 g_thread_functions_for_glib_use.thread_equal (&(thread1), &(thread2)) :\
1836 g_system_thread_equal_simple((thread1), (thread2)))
1838 static GSystemThread zero_thread;
1841 g_static_rec_cond_timed_wait (GCond * cond,
1842 GStaticRecMutex * mutex, GTimeVal * end_time)
1849 if (!g_thread_supported ())
1852 G_THREAD_UF (thread_self, (&self));
1854 g_return_val_if_fail (g_system_thread_equal (self, mutex->owner), FALSE);
1856 depth = mutex->depth;
1858 g_system_thread_assign (mutex->owner, zero_thread);
1860 smutex = g_static_mutex_get_mutex (&mutex->mutex);
1862 res = g_cond_timed_wait (cond, smutex, end_time);
1864 g_system_thread_assign (mutex->owner, self);
1865 mutex->depth = depth;
1871 g_static_rec_cond_wait (GCond * cond, GStaticRecMutex * mutex)
1873 g_static_rec_cond_timed_wait (cond, mutex, NULL);
1876 #endif /* GST_COMPILE_STATIC_REC_COND_WAIT */
1880 * @bin: the bin to add the elements to
1881 * @element_1: the first element to add to the bin
1882 * @...: additional elements to add to the bin
1884 * Adds a NULL-terminated list of elements to a bin. This function is
1885 * equivalent to calling gst_bin_add() for each member of the list.
1888 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
1892 g_return_if_fail (GST_IS_BIN (bin));
1893 g_return_if_fail (GST_IS_ELEMENT (element_1));
1895 va_start (args, element_1);
1898 gst_bin_add (bin, element_1);
1900 element_1 = va_arg (args, GstElement *);
1907 * gst_bin_remove_many:
1908 * @bin: the bin to remove the elements from
1909 * @element_1: the first element to remove from the bin
1910 * @...: NULL-terminated list of elements to remove from the bin
1912 * Remove a list of elements from a bin. This function is equivalent
1913 * to calling gst_bin_remove() with each member of the list.
1916 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
1920 g_return_if_fail (GST_IS_BIN (bin));
1921 g_return_if_fail (GST_IS_ELEMENT (element_1));
1923 va_start (args, element_1);
1926 gst_bin_remove (bin, element_1);
1928 element_1 = va_arg (args, GstElement *);
1935 get_state_func (GstElement * element, gpointer unused)
1937 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1939 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1940 "new thread waiting on state change");
1942 /* wait indefinitely */
1943 while (ret == GST_STATE_CHANGE_ASYNC)
1944 ret = gst_element_get_state (element, NULL, NULL, NULL);
1946 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1947 "thread done waiting on state change");
1949 gst_object_unref (element);
1953 * gst_bin_watch_for_state_change:
1954 * @bin: the bin to watch for state changes
1956 * Spawns a thread calling gst_element_get_state on @bin with infinite timeout.
1958 * In practice this is done because if a bin returns %GST_STATE_CHANGE_ASYNC
1959 * from a state change, it will not commit its state until someone calls
1960 * gst_element_get_state() on it. Thus having another thread checking the bin's
1961 * state will ensure that a state-changed message gets posted on the bus
1964 * This function is admittedly a bit of a hack. Bins should always post
1965 * messages. However this behavior was broken out into this function to avoid
1966 * spawning threads when scrubbing, when the bin's state is changing quickly and
1970 gst_bin_watch_for_state_change (GstBin * bin)
1972 static GThreadPool *pool = NULL;
1973 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
1975 g_static_mutex_lock (&mutex);
1977 pool = g_thread_pool_new ((GFunc) get_state_func, NULL, -1, FALSE, NULL);
1978 g_static_mutex_unlock (&mutex);
1980 g_thread_pool_push (pool, gst_object_ref (bin), NULL);
1983 struct _GstAsyncThreadData
1985 GstElement *element;
1990 set_state_async_thread_func (struct _GstAsyncThreadData *data, gpointer unused)
1992 GstState current, pending;
1993 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1995 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
1996 "new thread ensuring state change to %s",
1997 gst_element_state_get_name (data->state));
2000 /* wait indefinitely */
2001 ret = gst_element_get_state (data->element, ¤t, &pending, NULL);
2002 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2003 "get_state returned %d, current %s, pending %s", ret,
2004 gst_element_state_get_name (current),
2005 gst_element_state_get_name (pending));
2007 /* can only be SUCCESS or FAILURE */
2008 if (ret == GST_STATE_CHANGE_FAILURE) {
2009 /* we can only break, hopefully an error message was posted as well */
2010 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2011 "FAILURE during state change");
2013 } else if (ret == GST_STATE_CHANGE_SUCCESS) {
2014 if (current == data->state) {
2015 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2016 "successfully reached final state");
2019 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2020 "setting target state %s again",
2021 gst_element_state_get_name (data->state));
2022 gst_element_set_state (data->element, data->state);
2024 g_assert_not_reached ();
2028 GST_CAT_INFO_OBJECT (GST_CAT_STATES, data->element,
2029 "thread done waiting on state change");
2031 gst_object_unref (data->element);
2036 * gst_element_set_state_async:
2037 * @element: a #GstElement to change state of
2038 * @state: the element's new #GstState
2040 * Sets the state of the element. This function will try to set the
2041 * requested state by going through all the intermediary states and calling
2042 * the class's state change function for each. If the state change returns
2043 * #GST_STATE_CHANGE_ASYNC at any time, a thread will be started to
2044 * monitor the state change and make sure the element is brought to the
2047 * Returns: Result of the state change using #GstStateChangeReturn.
2051 GstStateChangeReturn
2052 gst_element_set_state_async (GstElement * element, GstState state)
2054 GstStateChangeReturn ret;
2055 struct _GstAsyncThreadData *data;
2057 ret = gst_element_set_state (element, state);
2058 if (ret == GST_STATE_CHANGE_ASYNC) {
2059 static GThreadPool *pool = NULL;
2060 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
2062 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2063 "starting new thread to ensure state change to %s",
2064 gst_element_state_get_name (state));
2065 g_static_mutex_lock (&mutex);
2067 pool = g_thread_pool_new ((GFunc) set_state_async_thread_func,
2068 NULL, -1, FALSE, NULL);
2069 g_static_mutex_unlock (&mutex);
2071 data = g_new0 (struct _GstAsyncThreadData, 1);
2073 gst_object_ref (element);
2074 data->element = element;
2075 data->state = state;
2076 g_thread_pool_push (pool, data, NULL);
2083 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
2084 guint arg_id, GParamFlags flags)
2086 GQuark prop_id = g_quark_from_string (prop_name);
2089 static GQuark fd_id = 0;
2090 static GQuark blocksize_id;
2091 static GQuark bytesperread_id;
2092 static GQuark dump_id;
2093 static GQuark filesize_id;
2094 static GQuark mmapsize_id;
2095 static GQuark location_id;
2096 static GQuark offset_id;
2097 static GQuark silent_id;
2098 static GQuark touch_id;
2101 fd_id = g_quark_from_static_string ("fd");
2102 blocksize_id = g_quark_from_static_string ("blocksize");
2103 bytesperread_id = g_quark_from_static_string ("bytesperread");
2104 dump_id = g_quark_from_static_string ("dump");
2105 filesize_id = g_quark_from_static_string ("filesize");
2106 mmapsize_id = g_quark_from_static_string ("mmapsize");
2107 location_id = g_quark_from_static_string ("location");
2108 offset_id = g_quark_from_static_string ("offset");
2109 silent_id = g_quark_from_static_string ("silent");
2110 touch_id = g_quark_from_static_string ("touch");
2113 if (prop_id == fd_id) {
2114 pspec = g_param_spec_int ("fd", "File-descriptor",
2115 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2116 } else if (prop_id == blocksize_id) {
2117 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2118 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2120 } else if (prop_id == bytesperread_id) {
2121 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2122 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2124 } else if (prop_id == dump_id) {
2125 pspec = g_param_spec_boolean ("dump", "Dump",
2126 "Dump bytes to stdout", FALSE, flags);
2128 } else if (prop_id == filesize_id) {
2129 pspec = g_param_spec_int64 ("filesize", "File Size",
2130 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2132 } else if (prop_id == mmapsize_id) {
2133 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2134 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2136 } else if (prop_id == location_id) {
2137 pspec = g_param_spec_string ("location", "File Location",
2138 "Location of the file to read", NULL, flags);
2140 } else if (prop_id == offset_id) {
2141 pspec = g_param_spec_int64 ("offset", "File Offset",
2142 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2144 } else if (prop_id == silent_id) {
2145 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2148 } else if (prop_id == touch_id) {
2149 pspec = g_param_spec_boolean ("touch", "Touch read data",
2150 "Touch data to force disk read before " "push ()", TRUE, flags);
2152 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2153 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2158 g_object_class_install_property (klass, arg_id, pspec);
2163 * gst_element_class_install_std_props:
2164 * @klass: the #GstElementClass to add the properties to.
2165 * @first_name: the name of the first property.
2166 * in a NULL terminated
2167 * @...: the id and flags of the first property, followed by
2168 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2170 * Adds a list of standardized properties with types to the @klass.
2171 * the id is for the property switch in your get_prop method, and
2172 * the flags determine readability / writeability.
2175 gst_element_class_install_std_props (GstElementClass * klass,
2176 const gchar * first_name, ...)
2182 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2184 va_start (args, first_name);
2189 int arg_id = va_arg (args, int);
2190 int flags = va_arg (args, int);
2192 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2195 name = va_arg (args, char *);
2204 * @buf1: a first source #GstBuffer to merge.
2205 * @buf2: the second source #GstBuffer to merge.
2207 * Create a new buffer that is the concatenation of the two source
2208 * buffers. The original source buffers will not be modified or
2209 * unref'd. Make sure you unref the source buffers if they are not used
2210 * anymore afterwards.
2212 * If the buffers point to contiguous areas of memory, the buffer
2213 * is created without copying the data.
2215 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2218 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2222 /* we're just a specific case of the more general gst_buffer_span() */
2223 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2230 * @buf1: a first source #GstBuffer to join.
2231 * @buf2: the second source #GstBuffer to join.
2233 * Create a new buffer that is the concatenation of the two source
2234 * buffers, and takes ownership of the original source buffers.
2236 * If the buffers point to contiguous areas of memory, the buffer
2237 * is created without copying the data.
2239 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2242 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2246 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2247 gst_buffer_unref (buf1);
2248 gst_buffer_unref (buf2);
2256 * @dest: buffer to stamp
2257 * @src: buffer to stamp from
2259 * Copies additional information (timestamps and offsets) from one buffer to
2263 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2265 g_return_if_fail (dest != NULL);
2266 g_return_if_fail (src != NULL);
2268 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
2269 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
2270 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
2271 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
2275 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2278 GstCaps *peercaps, *existing;
2280 existing = g_value_get_pointer (ret);
2281 peercaps = gst_pad_peer_get_caps (pad);
2282 if (peercaps == NULL)
2283 peercaps = gst_caps_new_any ();
2284 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2285 gst_caps_unref (existing);
2286 gst_caps_unref (peercaps);
2288 gst_object_unref (pad);
2293 * gst_pad_proxy_getcaps:
2294 * @pad: a #GstPad to proxy.
2296 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2297 * same element as @pad, and returns the intersection of the results.
2299 * This function is useful as a default getcaps function for an element
2300 * that can handle any stream format, but requires all its pads to have
2301 * the same caps. Two such elements are tee and aggregator.
2303 * Returns: the intersection of the other pads' allowed caps.
2306 gst_pad_proxy_getcaps (GstPad * pad)
2308 GstElement *element;
2309 GstCaps *caps, *intersected;
2311 GstIteratorResult res;
2312 GValue ret = { 0, };
2314 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2316 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2318 element = gst_pad_get_parent_element (pad);
2319 if (element == NULL)
2322 iter = gst_element_iterate_pads (element);
2324 g_value_init (&ret, G_TYPE_POINTER);
2325 g_value_set_pointer (&ret, gst_caps_new_any ());
2327 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2329 gst_iterator_free (iter);
2331 if (res != GST_ITERATOR_DONE)
2334 gst_object_unref (element);
2336 caps = g_value_get_pointer (&ret);
2337 g_value_unset (&ret);
2339 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2340 gst_caps_unref (caps);
2347 g_warning ("Pad list changed during capsnego for element %s",
2348 GST_ELEMENT_NAME (element));
2349 gst_object_unref (element);
2361 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2363 gboolean success = TRUE;
2365 if (pad != data->orig) {
2366 success = gst_pad_set_caps (pad, data->caps);
2367 g_value_set_boolean (ret, success);
2369 gst_object_unref (pad);
2375 * gst_pad_proxy_setcaps
2376 * @pad: a #GstPad to proxy from
2377 * @caps: the #GstCaps to link with
2379 * Calls gst_pad_set_caps() for every other pad belonging to the
2380 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2381 * the proxy setcaps fails. May be used only during negotiation.
2383 * Returns: TRUE if sucessful
2386 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2388 GstElement *element;
2390 GstIteratorResult res;
2391 GValue ret = { 0, };
2394 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2395 g_return_val_if_fail (caps != NULL, FALSE);
2397 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2399 element = gst_pad_get_parent_element (pad);
2400 if (element == NULL)
2403 iter = gst_element_iterate_pads (element);
2405 g_value_init (&ret, G_TYPE_BOOLEAN);
2406 g_value_set_boolean (&ret, TRUE);
2410 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2412 gst_iterator_free (iter);
2414 if (res != GST_ITERATOR_DONE)
2417 gst_object_unref (element);
2419 /* ok not to unset the gvalue */
2420 return g_value_get_boolean (&ret);
2425 g_warning ("Pad list changed during proxy_pad_link for element %s",
2426 GST_ELEMENT_NAME (element));
2427 gst_object_unref (element);
2433 * gst_pad_query_position:
2434 * @pad: a #GstPad to invoke the position query on.
2435 * @format: a pointer to the #GstFormat asked for.
2436 * On return contains the #GstFormat used.
2437 * @cur: A location in which to store the current position, or NULL.
2438 * @end: A location in which to store the end position (length), or NULL.
2440 * Queries a pad for the stream position and length.
2442 * Returns: TRUE if the query could be performed.
2445 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur,
2451 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2452 g_return_val_if_fail (format != NULL, FALSE);
2454 query = gst_query_new_position (*format);
2455 ret = gst_pad_query (pad, query);
2458 gst_query_parse_position (query, format, cur, end);
2460 gst_query_unref (query);
2466 * gst_pad_query_convert:
2467 * @pad: a #GstPad to invoke the convert query on.
2468 * @src_format: a #GstFormat to convert from.
2469 * @src_val: a value to convert.
2470 * @dest_format: a pointer to the #GstFormat to convert to.
2471 * @dest_val: a pointer to the result.
2473 * Queries a pad to convert @src_val in @src_format to @dest_format.
2475 * Returns: TRUE if the query could be performed.
2478 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2479 GstFormat * dest_format, gint64 * dest_val)
2484 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2485 g_return_val_if_fail (src_val >= 0, FALSE);
2486 g_return_val_if_fail (dest_format != NULL, FALSE);
2487 g_return_val_if_fail (dest_val != NULL, FALSE);
2489 if (*dest_format == src_format) {
2490 *dest_val = src_val;
2494 query = gst_query_new_convert (src_format, src_val, *dest_format);
2495 ret = gst_pad_query (pad, query);
2498 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2500 gst_query_unref (query);
2506 * gst_atomic_int_set:
2507 * @atomic_int: pointer to an atomic integer
2508 * @value: value to set
2510 * Unconditionally sets the atomic integer to @value.
2513 gst_atomic_int_set (gint * atomic_int, gint value)
2517 *atomic_int = value;
2518 /* read acts as a memory barrier */
2519 ignore = g_atomic_int_get (atomic_int);
2523 * gst_pad_add_data_probe:
2524 * @pad: pad to add the data probe handler to
2525 * @handler: function to call when data is passed over pad
2526 * @data: data to pass along with the handler
2528 * Adds a "data probe" to a pad. This function will be called whenever data
2529 * passes through a pad. In this case data means both events and buffers. The
2530 * probe will be called with the data as an argument. Note that the data will
2531 * have a reference count greater than 1, so it will be immutable -- you must
2534 * For source pads, the probe will be called after the blocking function, if any
2535 * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
2536 * to. For sink pads, the probe function will be called before configuring the
2537 * sink with new caps, if any, and before calling the pad's chain function.
2539 * Your data probe should return TRUE to let the data continue to flow, or FALSE
2540 * to drop it. Dropping data is rarely useful, but occasionally comes in handy
2543 * Although probes are implemented internally by connecting @handler to the
2544 * have-data signal on the pad, if you want to remove a probe it is insufficient
2545 * to only call g_signal_handler_disconnect on the returned handler id. To
2546 * remove a probe, use the appropriate function, such as
2547 * gst_pad_remove_data_probe().
2549 * Returns: The handler id.
2552 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2556 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2557 g_return_val_if_fail (handler != NULL, 0);
2560 sigid = g_signal_connect (pad, "have-data", handler, data);
2561 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2562 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2563 GST_DEBUG ("adding data probe to pad %s:%s, now %d data, %d event probes",
2564 GST_DEBUG_PAD_NAME (pad),
2565 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2572 * gst_pad_add_event_probe:
2573 * @pad: pad to add the event probe handler to
2574 * @handler: function to call when data is passed over pad
2575 * @data: data to pass along with the handler
2577 * Adds a probe that will be called for all events passing through a pad. See
2578 * gst_pad_add_data_probe() for more information.
2580 * Returns: The handler id
2583 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
2587 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2588 g_return_val_if_fail (handler != NULL, 0);
2591 sigid = g_signal_connect (pad, "have-data::event", handler, data);
2592 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2593 GST_DEBUG ("adding event probe to pad %s:%s, now %d probes",
2594 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2601 * gst_pad_add_buffer_probe:
2602 * @pad: pad to add the buffer probe handler to
2603 * @handler: function to call when data is passed over pad
2604 * @data: data to pass along with the handler
2606 * Adds a probe that will be called for all buffers passing through a pad. See
2607 * gst_pad_add_data_probe() for more information.
2609 * Returns: The handler id
2612 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2616 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2617 g_return_val_if_fail (handler != NULL, 0);
2620 sigid = g_signal_connect (pad, "have-data::buffer", handler, data);
2621 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2622 GST_DEBUG ("adding buffer probe to pad %s:%s, now %d probes",
2623 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2630 * gst_pad_remove_data_probe:
2631 * @pad: pad to remove the data probe handler from
2632 * @handler_id: handler id returned from gst_pad_add_data_probe
2634 * Removes a data probe from @pad.
2637 gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
2639 g_return_if_fail (GST_IS_PAD (pad));
2640 g_return_if_fail (handler_id > 0);
2643 g_signal_handler_disconnect (pad, handler_id);
2644 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2645 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2647 ("removed data probe from pad %s:%s, now %d event, %d buffer probes",
2648 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad),
2649 GST_PAD_DO_BUFFER_SIGNALS (pad));
2654 * gst_pad_remove_event_probe:
2655 * @pad: pad to remove the event probe handler from
2656 * @handler_id: handler id returned from gst_pad_add_event_probe
2658 * Removes an event probe from @pad.
2661 gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
2663 g_return_if_fail (GST_IS_PAD (pad));
2664 g_return_if_fail (handler_id > 0);
2667 g_signal_handler_disconnect (pad, handler_id);
2668 GST_PAD_DO_EVENT_SIGNALS (pad)--;
2669 GST_DEBUG ("removed event probe from pad %s:%s, now %d event probes",
2670 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2675 * gst_pad_remove_buffer_probe:
2676 * @pad: pad to remove the buffer probe handler from
2677 * @handler_id: handler id returned from gst_pad_add_buffer_probe
2679 * Removes a buffer probe from @pad.
2682 gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
2684 g_return_if_fail (GST_IS_PAD (pad));
2685 g_return_if_fail (handler_id > 0);
2688 g_signal_handler_disconnect (pad, handler_id);
2689 GST_PAD_DO_BUFFER_SIGNALS (pad)--;
2690 GST_DEBUG ("removed buffer probe from pad %s:%s, now %d buffer probes",
2691 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2696 * gst_element_found_tags_for_pad:
2697 * @element: element for which to post taglist to bus.
2698 * @pad: pad on which to push tag-event.
2699 * @list: the taglist to post on the bus and create event from.
2701 * Posts a message to the bus that new tags were found and pushes the
2702 * tags as event. Takes ownership of the taglist.
2705 gst_element_found_tags_for_pad (GstElement * element,
2706 GstPad * pad, GstTagList * list)
2708 g_return_if_fail (element != NULL);
2709 g_return_if_fail (pad != NULL);
2710 g_return_if_fail (list != NULL);
2712 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
2713 gst_element_post_message (element,
2714 gst_message_new_tag (GST_OBJECT (element), list));
2718 push_and_ref (GstPad * pad, GstEvent * event)
2720 gst_pad_push_event (pad, gst_event_ref (event));
2724 * gst_element_found_tags:
2725 * @element: element for which we found the tags.
2726 * @list: list of tags.
2728 * Posts a message to the bus that new tags were found, and pushes an event
2729 * to all sourcepads. Takes ownership of the taglist.
2732 gst_element_found_tags (GstElement * element, GstTagList * list)
2737 g_return_if_fail (element != NULL);
2738 g_return_if_fail (list != NULL);
2740 iter = gst_element_iterate_src_pads (element);
2741 event = gst_event_new_tag (gst_tag_list_copy (list));
2742 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
2743 gst_iterator_free (iter);
2744 gst_event_unref (event);
2746 gst_element_post_message (element,
2747 gst_message_new_tag (GST_OBJECT (element), list));