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)
91 g_return_if_fail (value != NULL);
92 g_return_if_fail (value_str != NULL);
94 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
95 g_type_name (G_VALUE_TYPE (value)));
97 switch (G_VALUE_TYPE (value)) {
99 g_value_set_string (value, g_strdup (value_str));
105 g_return_if_fail (sscanf (value_str, "%d", &i) == 1);
106 g_value_set_int (value, i);
112 g_return_if_fail (sscanf (value_str, "%u", &i) == 1);
113 g_value_set_uint (value, i);
119 g_return_if_fail (sscanf (value_str, "%ld", &i) == 1);
120 g_value_set_long (value, i);
126 g_return_if_fail (sscanf (value_str, "%lu", &i) == 1);
127 g_value_set_ulong (value, i);
130 case G_TYPE_BOOLEAN:{
133 if (!strncmp ("true", value_str, 4))
135 g_value_set_boolean (value, i);
141 g_return_if_fail (sscanf (value_str, "%c", &i) == 1);
142 g_value_set_char (value, i);
148 g_return_if_fail (sscanf (value_str, "%c", &i) == 1);
149 g_value_set_uchar (value, i);
155 g_return_if_fail (sscanf (value_str, "%f", &i) == 1);
156 g_value_set_float (value, i);
162 g_return_if_fail (sscanf (value_str, "%g", &i) == 1);
163 g_value_set_double (value, (gdouble) i);
172 * gst_util_set_object_arg:
173 * @object: the object to set the argument of
174 * @name: the name of the argument to set
175 * @value: the string value to set
177 * Convertes the string value to the type of the objects argument and
178 * sets the argument with it.
181 gst_util_set_object_arg (GObject * object, const gchar * name,
185 GParamSpec *paramspec;
188 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
194 GST_DEBUG ("paramspec->flags is %d, paramspec->value_type is %d",
195 paramspec->flags, (gint) paramspec->value_type);
197 if (paramspec->flags & G_PARAM_WRITABLE) {
198 switch (paramspec->value_type) {
200 g_object_set (G_OBJECT (object), name, value, NULL);
206 g_return_if_fail (sscanf (value, "%d", &i) == 1);
207 g_object_set (G_OBJECT (object), name, i, NULL);
213 g_return_if_fail (sscanf (value, "%u", &i) == 1);
214 g_object_set (G_OBJECT (object), name, i, NULL);
220 g_return_if_fail (sscanf (value, "%ld", &i) == 1);
221 g_object_set (G_OBJECT (object), name, i, NULL);
227 g_return_if_fail (sscanf (value, "%lu", &i) == 1);
228 g_object_set (G_OBJECT (object), name, i, NULL);
231 case G_TYPE_BOOLEAN:{
234 if (!g_ascii_strncasecmp ("true", value, 4))
236 g_object_set (G_OBJECT (object), name, i, NULL);
242 g_return_if_fail (sscanf (value, "%c", &i) == 1);
243 g_object_set (G_OBJECT (object), name, i, NULL);
249 g_return_if_fail (sscanf (value, "%c", &i) == 1);
250 g_object_set (G_OBJECT (object), name, i, NULL);
256 g_return_if_fail (sscanf (value, "%f", &i) == 1);
257 g_object_set (G_OBJECT (object), name, i, NULL);
263 g_return_if_fail (sscanf (value, "%g", &i) == 1);
264 g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
268 if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
271 g_return_if_fail (sscanf (value, "%d", &i) == 1);
272 g_object_set (G_OBJECT (object), name, i, NULL);
273 } else if (paramspec->value_type == GST_TYPE_URI) {
274 g_object_set (G_OBJECT (object), name, value, NULL);
283 * gst_util_uint64_scale:
284 * @val: the number to scale
285 * @num: the numerator of the scale ratio
286 * @denom: the denominator of the scale ratio
288 * Scale @val by @num / @denom, trying to avoid overflows.
290 * Returns: @val * @num / @denom, trying to avoid overflows.
293 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
295 /* implement me with fixed point, if you care */
296 return val * (((double) num) / denom);
299 /* -----------------------------------------------------
301 * The following code will be moved out of the main
302 * gstreamer library someday.
308 string_append_indent (GString * str, gint count)
312 for (xx = 0; xx < count; xx++)
313 g_string_append_c (str, ' ');
317 * gst_print_pad_caps:
318 * @buf: the buffer to print the caps in
319 * @indent: initial indentation
320 * @pad: the pad to print the caps from
322 * Write the pad capabilities in a human readable format into
326 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
333 string_append_indent (buf, indent);
334 g_string_printf (buf, "%s:%s has no capabilities",
335 GST_DEBUG_PAD_NAME (pad));
339 s = gst_caps_to_string (caps);
340 g_string_append (buf, s);
346 * gst_print_element_args:
347 * @buf: the buffer to print the args in
348 * @indent: initial indentation
349 * @element: the element to print the args of
351 * Print the element argument in a human readable format in the given
355 gst_print_element_args (GString * buf, gint indent, GstElement * element)
358 GValue value = { 0, }; /* the important thing is that value.type = 0 */
360 GParamSpec *spec, **specs, **walk;
362 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
365 for (walk = specs; *walk; walk++) {
367 if (width < strlen (spec->name))
368 width = strlen (spec->name);
371 for (walk = specs; *walk; walk++) {
374 if (spec->flags & G_PARAM_READABLE) {
375 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
376 g_object_get_property (G_OBJECT (element), spec->name, &value);
377 str = g_strdup_value_contents (&value);
378 g_value_unset (&value);
380 str = g_strdup ("Parameter not readable.");
383 string_append_indent (buf, indent);
384 g_string_append (buf, spec->name);
385 string_append_indent (buf, 2 + width - strlen (spec->name));
386 g_string_append (buf, str);
387 g_string_append_c (buf, '\n');
396 * gst_element_create_all_pads:
397 * @element: a #GstElement to create pads for
399 * Creates a pad for each pad template that is always available.
400 * This function is only useful during object intialization of
401 * subclasses of #GstElement.
404 gst_element_create_all_pads (GstElement * element)
408 /* FIXME: lock element */
411 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
412 (G_OBJECT_GET_CLASS (element)));
415 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
417 if (padtempl->presence == GST_PAD_ALWAYS) {
420 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
422 gst_element_add_pad (element, pad);
424 padlist = padlist->next;
429 * gst_element_get_compatible_pad_template:
430 * @element: a #GstElement to get a compatible pad template for.
431 * @compattempl: the #GstPadTemplate to find a compatible template for.
433 * Retrieves a pad template from @element that is compatible with @compattempl.
434 * Pads from compatible templates can be linked together.
436 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
437 * unreferencing is necessary.
440 gst_element_get_compatible_pad_template (GstElement * element,
441 GstPadTemplate * compattempl)
443 GstPadTemplate *newtempl = NULL;
445 GstElementClass *class;
447 g_return_val_if_fail (element != NULL, NULL);
448 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
449 g_return_val_if_fail (compattempl != NULL, NULL);
451 class = GST_ELEMENT_GET_CLASS (element);
453 padlist = gst_element_class_get_pad_template_list (class);
455 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
456 "Looking for a suitable pad template in %s out of %d templates...",
457 GST_ELEMENT_NAME (element), g_list_length (padlist));
460 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
461 GstCaps *intersection;
465 * Check direction (must be opposite)
468 GST_CAT_LOG (GST_CAT_CAPS,
469 "checking pad template %s", padtempl->name_template);
470 if (padtempl->direction != compattempl->direction) {
471 GST_CAT_DEBUG (GST_CAT_CAPS,
472 "compatible direction: found %s pad template \"%s\"",
473 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
474 padtempl->name_template);
476 GST_CAT_DEBUG (GST_CAT_CAPS,
477 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
478 GST_CAT_DEBUG (GST_CAT_CAPS,
479 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
481 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
482 GST_PAD_TEMPLATE_CAPS (padtempl));
484 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
485 (intersection ? "" : "not "), intersection);
487 if (!gst_caps_is_empty (intersection))
489 gst_caps_unref (intersection);
494 padlist = g_list_next (padlist);
497 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
498 "Returning new pad template %p", newtempl);
500 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
506 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
509 GstPad *newpad = NULL;
510 GstElementClass *oclass;
512 oclass = GST_ELEMENT_GET_CLASS (element);
514 if (oclass->request_new_pad)
515 newpad = (oclass->request_new_pad) (element, templ, name);
518 gst_object_ref (newpad);
526 * gst_element_get_pad_from_template:
527 * @element: a #GstElement.
528 * @templ: a #GstPadTemplate belonging to @element.
530 * Gets a pad from @element described by @templ. If the presence of @templ is
531 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
534 * Returns: the #GstPad, or NULL if one could not be found or created.
537 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
540 GstPadPresence presence;
542 /* If this function is ever exported, we need check the validity of `element'
543 * and `templ', and to make sure the template actually belongs to the
546 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
550 case GST_PAD_SOMETIMES:
551 ret = gst_element_get_static_pad (element, templ->name_template);
552 if (!ret && presence == GST_PAD_ALWAYS)
554 ("Element %s has an ALWAYS template %s, but no pad of the same name",
555 GST_OBJECT_NAME (element), templ->name_template);
558 case GST_PAD_REQUEST:
559 ret = gst_element_request_pad (element, templ, NULL);
567 * gst_element_request_compatible_pad:
568 * @element: a #GstElement.
569 * @templ: the #GstPadTemplate to which the new pad should be able to link.
571 * Requests a pad from @element. The returned pad should be unlinked and
572 * compatible with @templ. Might return an existing pad, or request a new one.
574 * Returns: a #GstPad, or %NULL if one could not be found or created.
577 gst_element_request_compatible_pad (GstElement * element,
578 GstPadTemplate * templ)
580 GstPadTemplate *templ_new;
583 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
584 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
586 /* FIXME: should really loop through the templates, testing each for
587 * compatibility and pad availability. */
588 templ_new = gst_element_get_compatible_pad_template (element, templ);
590 pad = gst_element_get_pad_from_template (element, templ_new);
592 /* This can happen for non-request pads. No need to unref. */
593 if (pad && GST_PAD_PEER (pad))
600 * gst_element_get_compatible_pad:
601 * @element: a #GstElement in which the pad should be found.
602 * @pad: the #GstPad to find a compatible one for.
603 * @caps: the #GstCaps to use as a filter.
605 * Looks for an unlinked pad to which the given pad can link. It is not
606 * guaranteed that linking the pads will work, though it should work in most
609 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
613 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
614 const GstCaps * caps)
617 GstPadTemplate *templ;
619 GstPad *foundpad = NULL;
622 /* FIXME check for caps compatibility */
624 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
625 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
627 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
628 "finding pad in %s compatible with %s:%s",
629 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
631 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
634 /* try to get an existing unlinked pad */
635 pads = gst_element_iterate_pads (element);
639 switch (gst_iterator_next (pads, &padptr)) {
640 case GST_ITERATOR_OK:
645 current = GST_PAD (padptr);
647 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
648 GST_DEBUG_PAD_NAME (current));
650 peer = gst_pad_get_peer (current);
652 if (peer == NULL && gst_pad_can_link (pad, current)) {
654 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
655 "found existing unlinked pad %s:%s",
656 GST_DEBUG_PAD_NAME (current));
658 gst_iterator_free (pads);
662 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
664 gst_object_unref (current);
666 gst_object_unref (peer);
670 case GST_ITERATOR_DONE:
673 case GST_ITERATOR_RESYNC:
674 gst_iterator_resync (pads);
676 case GST_ITERATOR_ERROR:
677 g_assert_not_reached ();
681 gst_iterator_free (pads);
683 /* try to create a new one */
684 /* requesting is a little crazy, we need a template. Let's create one */
685 templcaps = gst_pad_get_caps (pad);
687 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
688 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
689 foundpad = gst_element_request_compatible_pad (element, templ);
690 gst_object_unref (templ);
693 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
694 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
698 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
699 "Could not find a compatible pad to link to %s:%s",
700 GST_DEBUG_PAD_NAME (pad));
705 * gst_element_state_get_name:
706 * @state: a #GstState to get the name of.
708 * Gets a string representing the given state.
710 * Returns: a string with the name of the state.
713 gst_element_state_get_name (GstState state)
716 #ifdef GST_DEBUG_COLOR
717 case GST_STATE_VOID_PENDING:
718 return "VOID_PENDING";
721 return "\033[01;34mNULL\033[00m";
723 case GST_STATE_READY:
724 return "\033[01;31mREADY\033[00m";
726 case GST_STATE_PLAYING:
727 return "\033[01;32mPLAYING\033[00m";
729 case GST_STATE_PAUSED:
730 return "\033[01;33mPAUSED\033[00m";
733 /* This is a memory leak */
734 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
736 case GST_STATE_VOID_PENDING:
737 return "VOID_PENDING";
742 case GST_STATE_READY:
745 case GST_STATE_PLAYING:
748 case GST_STATE_PAUSED:
752 return g_strdup_printf ("UNKNOWN!(%d)", state);
759 * gst_element_factory_can_src_caps :
760 * @factory: factory to query
761 * @caps: the caps to check
763 * Checks if the factory can source the given capability.
765 * Returns: true if it can src the capabilities
768 gst_element_factory_can_src_caps (GstElementFactory * factory,
769 const GstCaps * caps)
773 g_return_val_if_fail (factory != NULL, FALSE);
774 g_return_val_if_fail (caps != NULL, FALSE);
776 templates = factory->staticpadtemplates;
779 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
781 if (template->direction == GST_PAD_SRC) {
782 if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
786 templates = g_list_next (templates);
793 * gst_element_factory_can_sink_caps :
794 * @factory: factory to query
795 * @caps: the caps to check
797 * Checks if the factory can sink the given capability.
799 * Returns: true if it can sink the capabilities
802 gst_element_factory_can_sink_caps (GstElementFactory * factory,
803 const GstCaps * caps)
807 g_return_val_if_fail (factory != NULL, FALSE);
808 g_return_val_if_fail (caps != NULL, FALSE);
810 templates = factory->staticpadtemplates;
813 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
815 if (template->direction == GST_PAD_SINK) {
816 if (gst_caps_is_always_compatible (caps,
817 gst_static_caps_get (&template->static_caps)))
820 templates = g_list_next (templates);
827 /* if return val is true, *direct_child is a caller-owned ref on the direct
828 * child of ancestor that is part of object's ancestry */
830 object_has_ancestor (GstObject * object, GstObject * ancestor,
831 GstObject ** direct_child)
833 GstObject *child, *parent;
836 *direct_child = NULL;
838 child = gst_object_ref (object);
839 parent = gst_object_get_parent (object);
842 if (ancestor == parent) {
844 *direct_child = child;
846 gst_object_unref (child);
847 gst_object_unref (parent);
851 gst_object_unref (child);
853 parent = gst_object_get_parent (parent);
856 gst_object_unref (child);
861 /* caller owns return */
863 find_common_root (GstObject * o1, GstObject * o2)
866 GstObject *kid1, *kid2;
867 GstObject *root = NULL;
869 while (GST_OBJECT_PARENT (top))
870 top = GST_OBJECT_PARENT (top);
872 /* the itsy-bitsy spider... */
874 if (!object_has_ancestor (o2, top, &kid2))
877 root = gst_object_ref (top);
879 if (!object_has_ancestor (o1, kid2, &kid1)) {
880 gst_object_unref (kid2);
884 if (!object_has_ancestor (o2, kid1, &kid2)) {
885 gst_object_unref (kid1);
892 /* caller does not own return */
894 ghost_up (GstElement * e, GstPad * pad)
896 static gint ghost_pad_index = 0;
899 GstObject *parent = GST_OBJECT_PARENT (e);
901 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
902 gpad = gst_ghost_pad_new (name, pad);
905 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
906 g_warning ("Pad named %s already exists in element %s\n",
907 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
908 gst_object_unref ((GstObject *) gpad);
916 remove_pad (gpointer ppad, gpointer unused)
920 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
921 g_warning ("Couldn't remove pad %s from element %s",
922 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
926 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
927 GSList ** pads_created)
931 GSList *pads_created_local = NULL;
933 g_assert (pads_created);
935 e1 = GST_OBJECT_PARENT (*src);
936 e2 = GST_OBJECT_PARENT (*sink);
938 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
939 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
940 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
944 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
945 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
947 /* we need to setup some ghost pads */
948 root = find_common_root (e1, e2);
951 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
952 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
956 while (GST_OBJECT_PARENT (e1) != root) {
957 *src = ghost_up ((GstElement *) e1, *src);
960 e1 = GST_OBJECT_PARENT (*src);
961 pads_created_local = g_slist_prepend (pads_created_local, *src);
963 while (GST_OBJECT_PARENT (e2) != root) {
964 *sink = ghost_up ((GstElement *) e2, *sink);
967 e2 = GST_OBJECT_PARENT (*sink);
968 pads_created_local = g_slist_prepend (pads_created_local, *sink);
971 gst_object_unref (root);
972 *pads_created = g_slist_concat (*pads_created, pads_created_local);
976 gst_object_unref (root);
977 g_slist_foreach (pads_created_local, remove_pad, NULL);
978 g_slist_free (pads_created_local);
983 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
985 GSList *pads_created = NULL;
988 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
991 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
995 g_slist_foreach (pads_created, remove_pad, NULL);
997 g_slist_free (pads_created);
1003 * gst_element_link_pads:
1004 * @src: a #GstElement containing the source pad.
1005 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1006 * @dest: the #GstElement containing the destination pad.
1007 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1009 * Links the two named pads of the source and destination elements.
1010 * Side effect is that if one of the pads has no parent, it becomes a
1011 * child of the parent of the other element. If they have different
1012 * parents, the link fails.
1014 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1017 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
1018 GstElement * dest, const gchar * destpadname)
1020 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1021 GstPad *srcpad, *destpad;
1022 GstPadTemplate *srctempl, *desttempl;
1023 GstElementClass *srcclass, *destclass;
1026 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1027 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1029 srcclass = GST_ELEMENT_GET_CLASS (src);
1030 destclass = GST_ELEMENT_GET_CLASS (dest);
1032 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1033 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1034 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1035 destpadname ? destpadname : "(any)");
1037 /* now get the pads we're trying to link and a list of all remaining pads */
1039 srcpad = gst_element_get_pad (src, srcpadname);
1041 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1042 GST_ELEMENT_NAME (src), srcpadname);
1045 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1046 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1047 GST_DEBUG_PAD_NAME (srcpad));
1048 gst_object_unref (srcpad);
1051 if (GST_PAD_PEER (srcpad) != NULL) {
1052 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1053 GST_DEBUG_PAD_NAME (srcpad));
1054 gst_object_unref (srcpad);
1061 srcpads = GST_ELEMENT_PADS (src);
1062 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1064 gst_object_ref (srcpad);
1068 destpad = gst_element_get_pad (dest, destpadname);
1070 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1071 GST_ELEMENT_NAME (dest), destpadname);
1074 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1075 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1076 GST_DEBUG_PAD_NAME (destpad));
1077 gst_object_unref (destpad);
1080 if (GST_PAD_PEER (destpad) != NULL) {
1081 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1082 GST_DEBUG_PAD_NAME (destpad));
1083 gst_object_unref (destpad);
1090 destpads = GST_ELEMENT_PADS (dest);
1091 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1093 gst_object_ref (destpad);
1097 if (srcpadname && destpadname) {
1100 /* two explicitly specified pads */
1101 result = pad_link_maybe_ghosting (srcpad, destpad);
1103 gst_object_unref (srcpad);
1104 gst_object_unref (destpad);
1109 /* loop through the allowed pads in the source, trying to find a
1110 * compatible destination pad */
1111 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1112 "looping through allowed src and dest pads");
1114 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1115 GST_DEBUG_PAD_NAME (srcpad));
1116 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1117 (GST_PAD_PEER (srcpad) == NULL)) {
1122 gst_object_ref (temp);
1124 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1127 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1128 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1129 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1131 gst_object_unref (destpad);
1132 gst_object_unref (srcpad);
1133 gst_object_unref (temp);
1138 gst_object_unref (temp);
1141 /* find a better way for this mess */
1143 srcpads = g_list_next (srcpads);
1145 gst_object_unref (srcpad);
1146 srcpad = GST_PAD_CAST (srcpads->data);
1147 gst_object_ref (srcpad);
1153 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1154 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1155 gst_object_unref (srcpad);
1157 gst_object_unref (destpad);
1161 gst_object_unref (srcpad);
1165 /* loop through the existing pads in the destination */
1167 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1168 GST_DEBUG_PAD_NAME (destpad));
1169 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1170 (GST_PAD_PEER (destpad) == NULL)) {
1171 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1173 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1174 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1175 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1176 gst_object_unref (temp);
1177 gst_object_unref (destpad);
1179 gst_object_unref (srcpad);
1183 gst_object_unref (temp);
1187 destpads = g_list_next (destpads);
1189 gst_object_unref (destpad);
1190 destpad = GST_PAD_CAST (destpads->data);
1191 gst_object_ref (destpad);
1197 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1198 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1199 gst_object_unref (destpad);
1201 gst_object_unref (srcpad);
1204 gst_object_unref (destpad);
1206 gst_object_unref (srcpad);
1211 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1212 "we might have request pads on both sides, checking...");
1213 srctempls = gst_element_class_get_pad_template_list (srcclass);
1214 desttempls = gst_element_class_get_pad_template_list (destclass);
1216 if (srctempls && desttempls) {
1218 srctempl = (GstPadTemplate *) srctempls->data;
1219 if (srctempl->presence == GST_PAD_REQUEST) {
1220 for (l = desttempls; l; l = l->next) {
1221 desttempl = (GstPadTemplate *) l->data;
1222 if (desttempl->presence == GST_PAD_REQUEST &&
1223 desttempl->direction != srctempl->direction) {
1224 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1225 (srctempl), gst_pad_template_get_caps (desttempl))) {
1227 gst_element_get_request_pad (src, srctempl->name_template);
1229 gst_element_get_request_pad (dest, desttempl->name_template);
1230 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1231 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1232 "linked pad %s:%s to pad %s:%s",
1233 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1234 gst_object_unref (srcpad);
1235 gst_object_unref (destpad);
1238 /* it failed, so we release the request pads */
1239 gst_element_release_request_pad (src, srcpad);
1240 gst_element_release_request_pad (dest, destpad);
1245 srctempls = srctempls->next;
1249 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1250 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1255 * gst_element_link_pads_filtered:
1256 * @src: a #GstElement containing the source pad.
1257 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1258 * @dest: the #GstElement containing the destination pad.
1259 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1260 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1262 * Links the two named pads of the source and destination elements. Side effect
1263 * is that if one of the pads has no parent, it becomes a child of the parent of
1264 * the other element. If they have different parents, the link fails. If @caps
1265 * is not #NULL, makes sure that the caps of the link is a subset of @caps.
1267 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1270 gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1271 GstElement * dest, const gchar * destpadname, GstCaps * filter)
1274 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1275 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1276 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), FALSE);
1279 GstElement *capsfilter;
1281 GstState state, pending;
1284 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1286 GST_ERROR ("Could not make a capsfilter");
1290 parent = gst_object_get_parent (GST_OBJECT (src));
1291 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
1293 GST_TIME_TO_TIMEVAL (0, tv);
1294 gst_element_get_state (GST_ELEMENT_CAST (parent), &state, &pending, &tv);
1296 if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
1297 GST_ERROR ("Could not add capsfilter");
1298 gst_object_unref (capsfilter);
1299 gst_object_unref (parent);
1303 if (pending != GST_STATE_VOID_PENDING)
1306 gst_element_set_state (capsfilter, state);
1308 gst_object_unref (parent);
1310 g_object_set (capsfilter, "filter-caps", filter, NULL);
1312 if (gst_element_link_pads (src, srcpadname, capsfilter, "sink")
1313 && gst_element_link_pads (capsfilter, "src", dest, destpadname)) {
1316 GST_INFO ("Could not link elements");
1317 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (capsfilter)), capsfilter);
1318 /* will unref and unlink as appropriate */
1322 return gst_element_link_pads (src, srcpadname, dest, destpadname);
1328 * @src: a #GstElement containing the source pad.
1329 * @dest: the #GstElement containing the destination pad.
1331 * Links @src to @dest. The link must be from source to
1332 * destination; the other direction will not be tried. The function looks for
1333 * existing pads that aren't linked yet. It will request new pads if necessary.
1334 * If multiple links are possible, only one is established.
1336 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1339 gst_element_link (GstElement * src, GstElement * dest)
1341 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1345 * gst_element_link_many:
1346 * @element_1: the first #GstElement in the link chain.
1347 * @element_2: the second #GstElement in the link chain.
1348 * @...: the NULL-terminated list of elements to link in order.
1350 * Chain together a series of elements. Uses gst_element_link().
1352 * Returns: TRUE on success, FALSE otherwise.
1355 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1359 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1360 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1362 va_start (args, element_2);
1365 if (!gst_element_link (element_1, element_2))
1368 element_1 = element_2;
1369 element_2 = va_arg (args, GstElement *);
1378 * gst_element_link_filtered:
1379 * @src: a #GstElement containing the source pad.
1380 * @dest: the #GstElement containing the destination pad.
1381 * @filter: the #GstCaps to filter the link, or #NULL for no filter.
1383 * Links @src to @dest using the given caps as filtercaps.
1384 * The link must be from source to
1385 * destination; the other direction will not be tried. The function looks for
1386 * existing pads that aren't linked yet. It will request new pads if necessary.
1387 * If multiple links are possible, only one is established.
1389 * Returns: TRUE if the pads could be linked, FALSE otherwise.
1392 gst_element_link_filtered (GstElement * src, GstElement * dest,
1395 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filter);
1399 * gst_element_unlink_pads:
1400 * @src: a #GstElement containing the source pad.
1401 * @srcpadname: the name of the #GstPad in source element.
1402 * @dest: a #GstElement containing the destination pad.
1403 * @destpadname: the name of the #GstPad in destination element.
1405 * Unlinks the two named pads of the source and destination elements.
1408 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1409 GstElement * dest, const gchar * destpadname)
1411 GstPad *srcpad, *destpad;
1413 g_return_if_fail (src != NULL);
1414 g_return_if_fail (GST_IS_ELEMENT (src));
1415 g_return_if_fail (srcpadname != NULL);
1416 g_return_if_fail (dest != NULL);
1417 g_return_if_fail (GST_IS_ELEMENT (dest));
1418 g_return_if_fail (destpadname != NULL);
1420 /* obtain the pads requested */
1421 srcpad = gst_element_get_pad (src, srcpadname);
1422 if (srcpad == NULL) {
1423 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1426 destpad = gst_element_get_pad (dest, destpadname);
1427 if (srcpad == NULL) {
1428 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1433 /* we're satisified they can be unlinked, let's do it */
1434 gst_pad_unlink (srcpad, destpad);
1438 * gst_element_unlink_many:
1439 * @element_1: the first #GstElement in the link chain.
1440 * @element_2: the second #GstElement in the link chain.
1441 * @...: the NULL-terminated list of elements to unlink in order.
1443 * Unlinks a series of elements. Uses gst_element_unlink().
1446 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1450 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1451 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1453 va_start (args, element_2);
1456 gst_element_unlink (element_1, element_2);
1458 element_1 = element_2;
1459 element_2 = va_arg (args, GstElement *);
1466 * gst_element_unlink:
1467 * @src: the source #GstElement to unlink.
1468 * @dest: the sink #GstElement to unlink.
1470 * Unlinks all source pads of the source element with all sink pads
1471 * of the sink element to which they are linked.
1474 gst_element_unlink (GstElement * src, GstElement * dest)
1477 gboolean done = FALSE;
1479 g_return_if_fail (GST_IS_ELEMENT (src));
1480 g_return_if_fail (GST_IS_ELEMENT (dest));
1482 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1483 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1485 pads = gst_element_iterate_pads (src);
1489 switch (gst_iterator_next (pads, &data)) {
1490 case GST_ITERATOR_OK:
1492 GstPad *pad = GST_PAD_CAST (data);
1494 if (GST_PAD_IS_SRC (pad)) {
1495 GstPad *peerpad = gst_pad_get_peer (pad);
1497 /* see if the pad is connected and is really a pad
1500 GstElement *peerelem;
1502 peerelem = gst_pad_get_parent_element (peerpad);
1504 if (peerelem == dest) {
1505 gst_pad_unlink (pad, peerpad);
1508 gst_object_unref (peerelem);
1510 gst_object_unref (peerpad);
1513 gst_object_unref (pad);
1516 case GST_ITERATOR_RESYNC:
1517 gst_iterator_resync (pads);
1519 case GST_ITERATOR_DONE:
1523 g_assert_not_reached ();
1530 gst_element_query_position (GstElement * element, GstFormat * format,
1531 gint64 * cur, gint64 * end)
1536 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1537 g_return_val_if_fail (format != NULL, FALSE);
1539 query = gst_query_new_position (*format);
1540 ret = gst_element_query (element, query);
1543 gst_query_parse_position (query, format, cur, end);
1545 gst_query_unref (query);
1551 gst_element_query_convert (GstElement * element, GstFormat src_format,
1552 gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
1557 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1558 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1559 g_return_val_if_fail (dest_val != NULL, FALSE);
1561 if (*dest_fmt == src_format) {
1562 *dest_val = src_val;
1566 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1567 ret = gst_element_query (element, query);
1570 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1572 gst_query_unref (query);
1580 * @srcpad: the source #GstPad to link.
1581 * @sinkpad: the sink #GstPad to link.
1583 * Checks if the source pad and the sink pad can be linked.
1584 * Both @srcpad and @sinkpad must be unlinked.
1586 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1589 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1591 /* FIXME This function is gross. It's almost a direct copy of
1592 * gst_pad_link_filtered(). Any decent programmer would attempt
1593 * to merge the two functions, which I will do some day. --ds
1596 /* generic checks */
1597 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1598 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1600 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1601 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1603 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1604 if (GST_PAD_PEER (srcpad) != NULL) {
1605 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1606 GST_DEBUG_PAD_NAME (srcpad));
1609 if (GST_PAD_PEER (sinkpad) != NULL) {
1610 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1611 GST_DEBUG_PAD_NAME (sinkpad));
1614 if (!GST_PAD_IS_SRC (srcpad)) {
1615 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1616 GST_DEBUG_PAD_NAME (srcpad));
1619 if (!GST_PAD_IS_SINK (sinkpad)) {
1620 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1621 GST_DEBUG_PAD_NAME (sinkpad));
1624 if (GST_PAD_PARENT (srcpad) == NULL) {
1625 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1626 GST_DEBUG_PAD_NAME (srcpad));
1629 if (GST_PAD_PARENT (sinkpad) == NULL) {
1630 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1631 GST_DEBUG_PAD_NAME (srcpad));
1639 * gst_pad_use_fixed_caps:
1640 * @pad: the pad to use
1642 * A helper function you can use that sets the
1643 * @gst_pad_get_fixed_caps_func as the gstcaps function for the
1644 * pad. This way the function will always return the negotiated caps
1645 * or in case the pad is not negotiated, the padtemplate caps.
1647 * Use this function on a pad that, once _set_caps() has been called
1648 * on it, it cannot be renegotiated to something else.
1651 gst_pad_use_fixed_caps (GstPad * pad)
1653 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1657 * gst_pad_get_fixed_caps_func:
1658 * @pad: the pad to use
1660 * A helper function you can use as a GetCaps function that
1661 * will return the currently negotiated caps or the padtemplate
1664 * Returns: The currently negotiated caps or the padtemplate.
1667 gst_pad_get_fixed_caps_func (GstPad * pad)
1671 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1673 if (GST_PAD_CAPS (pad)) {
1674 result = GST_PAD_CAPS (pad);
1676 GST_CAT_DEBUG (GST_CAT_CAPS,
1677 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1679 result = gst_caps_ref (result);
1682 if (GST_PAD_PAD_TEMPLATE (pad)) {
1683 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1685 result = GST_PAD_TEMPLATE_CAPS (templ);
1686 GST_CAT_DEBUG (GST_CAT_CAPS,
1687 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1690 result = gst_caps_ref (result);
1693 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1694 result = gst_caps_new_empty ();
1701 * gst_pad_get_parent_element:
1704 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
1705 * its parent is not an element, return NULL.
1707 * Returns: The parent of the pad. The caller has a reference on the parent, so
1708 * unref when you're finished with it.
1713 gst_pad_get_parent_element (GstPad * pad)
1717 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1719 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
1721 if (p && !GST_IS_ELEMENT (p)) {
1722 gst_object_unref (p);
1725 return GST_ELEMENT_CAST (p);
1729 * gst_flow_get_name:
1730 * @ret: a #GstFlowReturn to get the name of.
1732 * Gets a string representing the given flow return.
1734 * Returns: a string with the name of the flow return.
1736 G_CONST_RETURN gchar *
1737 gst_flow_get_name (GstFlowReturn ret)
1740 case GST_FLOW_RESEND:
1741 return "need to resend buffer";
1744 /* expected failures */
1745 case GST_FLOW_NOT_LINKED:
1746 return "pad not linked";
1747 case GST_FLOW_WRONG_STATE:
1748 return "pad in wrong state";
1750 case GST_FLOW_UNEXPECTED:
1751 return "unexpected data on pad";
1752 case GST_FLOW_NOT_NEGOTIATED:
1753 return "pad not negotiated";
1754 case GST_FLOW_ERROR:
1755 return "fatal error occured";
1756 case GST_FLOW_NOT_SUPPORTED:
1757 return "unsupported function called";
1759 return "unknown error";
1764 * gst_object_default_error:
1765 * @source: the #GstObject that initiated the error.
1766 * @error: the GError.
1767 * @debug: an additional debug information string, or NULL.
1769 * A default error function.
1771 * The default handler will simply print the error string using g_print.
1774 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
1776 gchar *name = gst_object_get_path_string (source);
1778 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
1780 g_print (_("Additional debug info:\n%s\n"), debug);
1787 * @bin: the bin to add the elements to
1788 * @element_1: the first element to add to the bin
1789 * @...: additional elements to add to the bin
1791 * Adds a NULL-terminated list of elements to a bin. This function is
1792 * equivalent to calling gst_bin_add() for each member of the list.
1795 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
1799 g_return_if_fail (GST_IS_BIN (bin));
1800 g_return_if_fail (GST_IS_ELEMENT (element_1));
1802 va_start (args, element_1);
1805 gst_bin_add (bin, element_1);
1807 element_1 = va_arg (args, GstElement *);
1814 * gst_bin_remove_many:
1815 * @bin: the bin to remove the elements from
1816 * @element_1: the first element to remove from the bin
1817 * @...: NULL-terminated list of elements to remove from the bin
1819 * Remove a list of elements from a bin. This function is equivalent
1820 * to calling gst_bin_remove() with each member of the list.
1823 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
1827 g_return_if_fail (GST_IS_BIN (bin));
1828 g_return_if_fail (GST_IS_ELEMENT (element_1));
1830 va_start (args, element_1);
1833 gst_bin_remove (bin, element_1);
1835 element_1 = va_arg (args, GstElement *);
1842 get_state_func (GstElement * element, gpointer unused)
1844 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1846 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1847 "new thread waiting on state change");
1849 /* wait indefinitely */
1850 while (ret == GST_STATE_CHANGE_ASYNC)
1851 ret = gst_element_get_state (element, NULL, NULL, NULL);
1853 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1854 "thread done waiting on state change");
1856 gst_object_unref (element);
1860 * gst_bin_watch_for_state_change:
1861 * @bin: the bin to watch for state changes
1863 * Spawns a thread calling gst_element_get_state on @bin with infinite timeout.
1865 * In practice this is done because if a bin returns %GST_STATE_CHANGE_ASYNC
1866 * from a state change, it will not commit its state until someone calls
1867 * gst_element_get_state() on it. Thus having another thread checking the bin's
1868 * state will ensure that a state-changed message gets posted on the bus
1871 * This function is admittedly a bit of a hack. Bins should always post
1872 * messages. However this behavior was broken out into this function to avoid
1873 * spawning threads when scrubbing, when the bin's state is changing quickly and
1877 gst_bin_watch_for_state_change (GstBin * bin)
1879 static GThreadPool *pool = NULL;
1880 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
1882 g_static_mutex_lock (&mutex);
1884 pool = g_thread_pool_new ((GFunc) get_state_func, NULL, -1, FALSE, NULL);
1885 g_static_mutex_unlock (&mutex);
1887 g_thread_pool_push (pool, gst_object_ref (bin), NULL);
1891 set_state_async_thread_func (GstElement * element, gpointer statep)
1893 GstState state = GPOINTER_TO_INT (statep);
1894 GstState current, pending;
1895 GstStateChangeReturn ret = GST_STATE_CHANGE_ASYNC;
1897 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1898 "new thread ensuring state change to %s",
1899 gst_element_state_get_name (state));
1902 /* wait indefinitely */
1903 ret = gst_element_get_state (element, ¤t, &pending, NULL);
1904 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1905 "get_state returned %d, current %s, pending %s", ret,
1906 gst_element_state_get_name (current),
1907 gst_element_state_get_name (pending));
1909 /* can only be SUCCESS or FAILURE */
1910 if (ret == GST_STATE_CHANGE_FAILURE) {
1911 /* we can only break, hopefully an error message was posted as well */
1912 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1913 "FAILURE during state change");
1915 } else if (ret == GST_STATE_CHANGE_SUCCESS) {
1916 if (current == state) {
1917 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1918 "successfully reached final state");
1921 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1922 "setting target state %s again", gst_element_state_get_name (state));
1923 gst_element_set_state (element, state);
1925 g_assert_not_reached ();
1929 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1930 "thread done waiting on state change");
1932 gst_object_unref (element);
1936 * gst_element_set_state_async:
1937 * @element: a #GstElement to change state of
1938 * @state: the element's new #GstState
1940 * Sets the state of the element. This function will try to set the
1941 * requested state by going through all the intermediary states and calling
1942 * the class's state change function for each. If the state change returns
1943 * #GST_STATE_CHANGE_ASYNC at any time, a thread will be started to
1944 * monitor the state change and make sure the element is brought to the
1947 * Returns: Result of the state change using #GstStateChangeReturn.
1951 GstStateChangeReturn
1952 gst_element_set_state_async (GstElement * element, GstState state)
1954 GstStateChangeReturn ret;
1956 ret = gst_element_set_state (element, state);
1957 if (ret == GST_STATE_CHANGE_ASYNC) {
1958 static GThreadPool *pool = NULL;
1959 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
1961 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1962 "starting new thread to ensure state change to %s",
1963 gst_element_state_get_name (state));
1964 g_static_mutex_lock (&mutex);
1966 pool = g_thread_pool_new ((GFunc) set_state_async_thread_func,
1967 GINT_TO_POINTER (state), -1, FALSE, NULL);
1968 g_static_mutex_unlock (&mutex);
1970 g_thread_pool_push (pool, gst_object_ref (element), NULL);
1977 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
1978 guint arg_id, GParamFlags flags)
1980 GQuark prop_id = g_quark_from_string (prop_name);
1983 static GQuark fd_id = 0;
1984 static GQuark blocksize_id;
1985 static GQuark bytesperread_id;
1986 static GQuark dump_id;
1987 static GQuark filesize_id;
1988 static GQuark mmapsize_id;
1989 static GQuark location_id;
1990 static GQuark offset_id;
1991 static GQuark silent_id;
1992 static GQuark touch_id;
1995 fd_id = g_quark_from_static_string ("fd");
1996 blocksize_id = g_quark_from_static_string ("blocksize");
1997 bytesperread_id = g_quark_from_static_string ("bytesperread");
1998 dump_id = g_quark_from_static_string ("dump");
1999 filesize_id = g_quark_from_static_string ("filesize");
2000 mmapsize_id = g_quark_from_static_string ("mmapsize");
2001 location_id = g_quark_from_static_string ("location");
2002 offset_id = g_quark_from_static_string ("offset");
2003 silent_id = g_quark_from_static_string ("silent");
2004 touch_id = g_quark_from_static_string ("touch");
2007 if (prop_id == fd_id) {
2008 pspec = g_param_spec_int ("fd", "File-descriptor",
2009 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
2010 } else if (prop_id == blocksize_id) {
2011 pspec = g_param_spec_ulong ("blocksize", "Block Size",
2012 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
2014 } else if (prop_id == bytesperread_id) {
2015 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
2016 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
2018 } else if (prop_id == dump_id) {
2019 pspec = g_param_spec_boolean ("dump", "Dump",
2020 "Dump bytes to stdout", FALSE, flags);
2022 } else if (prop_id == filesize_id) {
2023 pspec = g_param_spec_int64 ("filesize", "File Size",
2024 "Size of the file being read", 0, G_MAXINT64, 0, flags);
2026 } else if (prop_id == mmapsize_id) {
2027 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
2028 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
2030 } else if (prop_id == location_id) {
2031 pspec = g_param_spec_string ("location", "File Location",
2032 "Location of the file to read", NULL, flags);
2034 } else if (prop_id == offset_id) {
2035 pspec = g_param_spec_int64 ("offset", "File Offset",
2036 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
2038 } else if (prop_id == silent_id) {
2039 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
2042 } else if (prop_id == touch_id) {
2043 pspec = g_param_spec_boolean ("touch", "Touch read data",
2044 "Touch data to force disk read before " "push ()", TRUE, flags);
2046 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
2047 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
2052 g_object_class_install_property (klass, arg_id, pspec);
2057 * gst_element_class_install_std_props:
2058 * @klass: the #GstElementClass to add the properties to.
2059 * @first_name: the name of the first property.
2060 * in a NULL terminated
2061 * @...: the id and flags of the first property, followed by
2062 * further 'name', 'id', 'flags' triplets and terminated by NULL.
2064 * Adds a list of standardized properties with types to the @klass.
2065 * the id is for the property switch in your get_prop method, and
2066 * the flags determine readability / writeability.
2069 gst_element_class_install_std_props (GstElementClass * klass,
2070 const gchar * first_name, ...)
2076 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
2078 va_start (args, first_name);
2083 int arg_id = va_arg (args, int);
2084 int flags = va_arg (args, int);
2086 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
2089 name = va_arg (args, char *);
2098 * @buf1: a first source #GstBuffer to merge.
2099 * @buf2: the second source #GstBuffer to merge.
2101 * Create a new buffer that is the concatenation of the two source
2102 * buffers. The original source buffers will not be modified or
2103 * unref'd. Make sure you unref the source buffers if they are not used
2104 * anymore afterwards.
2106 * If the buffers point to contiguous areas of memory, the buffer
2107 * is created without copying the data.
2109 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2112 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
2116 /* we're just a specific case of the more general gst_buffer_span() */
2117 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2124 * @buf1: a first source #GstBuffer to join.
2125 * @buf2: the second source #GstBuffer to join.
2127 * Create a new buffer that is the concatenation of the two source
2128 * buffers, and takes ownership of the original source buffers.
2130 * If the buffers point to contiguous areas of memory, the buffer
2131 * is created without copying the data.
2133 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
2136 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
2140 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
2141 gst_buffer_unref (buf1);
2142 gst_buffer_unref (buf2);
2150 * @dest: buffer to stamp
2151 * @src: buffer to stamp from
2153 * Copies additional information (timestamps and offsets) from one buffer to
2157 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
2159 g_return_if_fail (dest != NULL);
2160 g_return_if_fail (src != NULL);
2162 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
2163 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
2164 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
2165 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
2169 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
2172 GstCaps *peercaps, *existing;
2174 existing = g_value_get_pointer (ret);
2175 peercaps = gst_pad_peer_get_caps (pad);
2176 if (peercaps == NULL)
2177 peercaps = gst_caps_new_any ();
2178 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
2179 gst_caps_unref (existing);
2180 gst_caps_unref (peercaps);
2186 * gst_pad_proxy_getcaps:
2187 * @pad: a #GstPad to proxy.
2189 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2190 * same element as @pad, and returns the intersection of the results.
2192 * This function is useful as a default getcaps function for an element
2193 * that can handle any stream format, but requires all its pads to have
2194 * the same caps. Two such elements are tee and aggregator.
2196 * Returns: the intersection of the other pads' allowed caps.
2199 gst_pad_proxy_getcaps (GstPad * pad)
2201 GstElement *element;
2202 GstCaps *caps, *intersected;
2204 GstIteratorResult res;
2205 GValue ret = { 0, };
2207 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2209 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2211 element = gst_pad_get_parent_element (pad);
2212 if (element == NULL)
2215 iter = gst_element_iterate_pads (element);
2217 g_value_init (&ret, G_TYPE_POINTER);
2218 g_value_set_pointer (&ret, gst_caps_new_any ());
2220 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
2222 gst_iterator_free (iter);
2224 if (res != GST_ITERATOR_DONE) {
2225 g_warning ("Pad list changed during capsnego for element %s",
2226 GST_ELEMENT_NAME (element));
2230 caps = g_value_get_pointer (&ret);
2231 g_value_unset (&ret);
2233 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2234 gst_caps_unref (caps);
2246 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
2248 gboolean success = TRUE;
2250 if (pad != data->orig) {
2251 success = gst_pad_set_caps (pad, data->caps);
2252 g_value_set_boolean (ret, success);
2259 * gst_pad_proxy_setcaps
2260 * @pad: a #GstPad to proxy from
2261 * @caps: the #GstCaps to link with
2263 * Calls gst_pad_set_caps() for every other pad belonging to the
2264 * same element as @pad. If gst_pad_set_caps() fails on any pad,
2265 * the proxy setcaps fails. May be used only during negotiation.
2267 * Returns: TRUE if sucessful
2270 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
2272 GstElement *element;
2274 GstIteratorResult res;
2275 GValue ret = { 0, };
2278 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2279 g_return_val_if_fail (caps != NULL, FALSE);
2281 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2283 element = gst_pad_get_parent_element (pad);
2285 iter = gst_element_iterate_pads (element);
2287 g_value_init (&ret, G_TYPE_BOOLEAN);
2288 g_value_set_boolean (&ret, TRUE);
2292 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
2294 gst_iterator_free (iter);
2296 if (res != GST_ITERATOR_DONE) {
2297 g_warning ("Pad list changed during proxy_pad_link for element %s",
2298 GST_ELEMENT_NAME (element));
2302 /* ok not to unset the gvalue */
2303 return g_value_get_boolean (&ret);
2307 * gst_pad_query_position:
2308 * @pad: a #GstPad to invoke the position query on.
2309 * @format: a pointer to the #GstFormat asked for.
2310 * On return contains the #GstFormat used.
2311 * @cur: A location in which to store the current position, or NULL.
2312 * @end: A location in which to store the end position (length), or NULL.
2314 * Queries a pad for the stream position and length.
2316 * Returns: TRUE if the query could be performed.
2319 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur,
2325 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2326 g_return_val_if_fail (format != NULL, FALSE);
2328 query = gst_query_new_position (*format);
2329 ret = gst_pad_query (pad, query);
2332 gst_query_parse_position (query, format, cur, end);
2334 gst_query_unref (query);
2340 * gst_pad_query_convert:
2341 * @pad: a #GstPad to invoke the convert query on.
2342 * @src_format: a #GstFormat to convert from.
2343 * @src_val: a value to convert.
2344 * @dest_format: a pointer to the #GstFormat to convert to.
2345 * @dest_val: a pointer to the result.
2347 * Queries a pad to convert @src_val in @src_format to @dest_format.
2349 * Returns: TRUE if the query could be performed.
2352 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2353 GstFormat * dest_format, gint64 * dest_val)
2358 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2359 g_return_val_if_fail (dest_format != NULL, FALSE);
2360 g_return_val_if_fail (dest_val != NULL, FALSE);
2362 if (*dest_format == src_format) {
2363 *dest_val = src_val;
2367 query = gst_query_new_convert (src_format, src_val, *dest_format);
2368 ret = gst_pad_query (pad, query);
2371 gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
2373 gst_query_unref (query);
2379 * gst_atomic_int_set:
2380 * @atomic_int: pointer to an atomic integer
2381 * @value: value to set
2383 * Unconditionally sets the atomic integer to @value.
2386 gst_atomic_int_set (gint * atomic_int, gint value)
2390 *atomic_int = value;
2391 /* read acts as a memory barrier */
2392 ignore = g_atomic_int_get (atomic_int);
2396 * gst_pad_add_data_probe:
2397 * @pad: pad to add the data probe handler to
2398 * @handler: function to call when data is passed over pad
2399 * @data: data to pass along with the handler
2401 * Connects a signal handler to the pad's have-data signal, and increases
2402 * the do_{buffer,event}_signals number on the pads so that those
2403 * signals are actually fired.
2405 * Returns: The handler id
2409 gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
2413 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2414 g_return_val_if_fail (handler != NULL, 0);
2417 sigid = g_signal_connect (pad, "have-data", handler, data);
2418 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2419 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2420 GST_DEBUG ("adding data probe to pad %s:%s, now %d data, %d event probes",
2421 GST_DEBUG_PAD_NAME (pad),
2422 GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2429 * gst_pad_add_event_probe:
2430 * @pad: pad to add the event probe handler to
2431 * @handler: function to call when data is passed over pad
2432 * @data: data to pass along with the handler
2434 * Connects a signal handler to the pad's have-data signal, and increases
2435 * the do_event_signals number on the pads so that this signal
2436 * is actually fired.
2438 * Returns: The handler id
2442 gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
2446 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2447 g_return_val_if_fail (handler != NULL, 0);
2450 sigid = g_signal_connect (pad, "have-data", handler, data);
2451 GST_PAD_DO_EVENT_SIGNALS (pad)++;
2452 GST_DEBUG ("adding event probe to pad %s:%s, now %d probes",
2453 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2460 * gst_pad_add_buffer_probe:
2461 * @pad: pad to add the buffer probe handler to
2462 * @handler: function to call when data is passed over pad
2463 * @data: data to pass along with the handler
2465 * Connects a signal handler to the pad's have-data signal, and increases
2466 * the do_buffer_signals number on the pads so that this signal
2467 * is actually fired.
2469 * Returns: The handler id
2473 gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2477 g_return_val_if_fail (GST_IS_PAD (pad), 0);
2478 g_return_val_if_fail (handler != NULL, 0);
2481 sigid = g_signal_connect (pad, "have-data", handler, data);
2482 GST_PAD_DO_BUFFER_SIGNALS (pad)++;
2483 GST_DEBUG ("adding buffer probe to pad %s:%s, now %d probes",
2484 GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2491 * gst_pad_remove_data_probe:
2492 * @pad: pad to remove the data probe handler from
2493 * @handler: function that was assigned to the signal
2494 * @data: data that was assigned to the signal handler
2496 * Unconnects a signal handler to the pad's have-data signal, and decreases
2497 * the do_{buffer,event}_signals number on the pads so that those
2498 * signals are actually no more fired if no signals are connected.
2502 gst_pad_remove_data_probe (GstPad * pad, GCallback handler, gpointer data)
2506 g_return_if_fail (GST_IS_PAD (pad));
2507 g_return_if_fail (handler != NULL);
2510 count = g_signal_handlers_disconnect_by_func (pad, handler, data);
2511 GST_PAD_DO_BUFFER_SIGNALS (pad) -= count;
2512 GST_PAD_DO_EVENT_SIGNALS (pad) -= count;
2514 ("removing %d data probes from pad %s:%s, now %d event, %d buffer probes",
2515 count, GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad),
2516 GST_PAD_DO_BUFFER_SIGNALS (pad));
2521 * gst_pad_remove_event_probe:
2522 * @pad: pad to remove the event probe handler from
2523 * @handler: function that was assigned to the signal
2524 * @data: data that was assigned to the signal handler
2526 * Unconnects a signal handler to the pad's have-data signal, and decreases
2527 * the do_event_signals number on the pads so that this signal is
2528 * actually no more fired if no signals are connected.
2532 gst_pad_remove_event_probe (GstPad * pad, GCallback handler, gpointer data)
2536 g_return_if_fail (GST_IS_PAD (pad));
2537 g_return_if_fail (handler != NULL);
2540 count = g_signal_handlers_disconnect_by_func (pad, handler, data);
2541 GST_PAD_DO_EVENT_SIGNALS (pad) -= count;
2542 GST_DEBUG ("removing %d event probes from pad %s:%s, now %d event probes",
2543 count, GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
2548 * gst_pad_remove_buffer_probe:
2549 * @pad: pad to remove the buffer probe handler from
2550 * @handler: function that was assigned to the signal
2551 * @data: data that was assigned to the signal handler
2553 * Unconnects a signal handler to the pad's have-data signal, and decreases
2554 * the emit_buffer_signals number on the pads so that this signal is
2555 * actually no more fired if no signals are connected.
2559 gst_pad_remove_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
2563 g_return_if_fail (GST_IS_PAD (pad));
2564 g_return_if_fail (handler != NULL);
2567 count = g_signal_handlers_disconnect_by_func (pad, handler, data);
2568 GST_PAD_DO_BUFFER_SIGNALS (pad) -= count;
2569 GST_DEBUG ("removing %d buffer probes from pad %s:%s, now %d buffer probes",
2570 count, GST_DEBUG_PAD_NAME (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
2575 * gst_element_found_tags_for_pad:
2576 * @element: element for which to post taglist to bus.
2577 * @pad: pad on which to push tag-event.
2578 * @list: the taglist to post on the bus and create event from.
2580 * Posts a message to the bus that new tags were found and pushes the
2581 * tags as event. Takes ownership of the taglist.
2584 gst_element_found_tags_for_pad (GstElement * element,
2585 GstPad * pad, GstTagList * list)
2587 g_return_if_fail (element != NULL);
2588 g_return_if_fail (pad != NULL);
2589 g_return_if_fail (list != NULL);
2591 gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
2592 gst_element_post_message (element,
2593 gst_message_new_tag (GST_OBJECT (element), list));
2597 push_and_ref (GstPad * pad, GstEvent * event)
2599 gst_pad_push_event (pad, gst_event_ref (event));
2603 * gst_element_found_tags:
2604 * @element: element for which we found the tags.
2605 * @list: list of tags.
2607 * Posts a message to the bus that new tags were found, and pushes an event
2608 * to all sourcepads. Takes ownership of the taglist.
2611 gst_element_found_tags (GstElement * element, GstTagList * list)
2616 g_return_if_fail (element != NULL);
2617 g_return_if_fail (list != NULL);
2619 iter = gst_element_iterate_src_pads (element);
2620 event = gst_event_new_tag (gst_tag_list_copy (list));
2621 gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
2622 gst_iterator_free (iter);
2623 gst_event_unref (event);
2625 gst_element_post_message (element,
2626 gst_message_new_tag (GST_OBJECT (element), list));