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.
26 #include "gst_private.h"
27 #include "gstghostpad.h"
29 #include "gsturitype.h"
31 #include "gst-i18n-lib.h"
36 * @mem: a pointer to the memory to dump
37 * @size: the size of the memory block to dump
39 * Dumps the memory block into a hex representation. Useful for debugging.
42 gst_util_dump_mem (const guchar * mem, guint size)
45 GString *string = g_string_sized_new (50);
46 GString *chars = g_string_sized_new (18);
50 if (g_ascii_isprint (mem[i]))
51 g_string_append_printf (chars, "%c", mem[i]);
53 g_string_append_printf (chars, ".");
55 g_string_append_printf (string, "%02x ", mem[i]);
60 if (j == 16 || i == size) {
61 g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
62 string->str, chars->str);
63 g_string_set_size (string, 0);
64 g_string_set_size (chars, 0);
68 g_string_free (string, TRUE);
69 g_string_free (chars, TRUE);
74 * gst_util_set_value_from_string:
75 * @value: the value to set
76 * @value_str: the string to get the value from
78 * Converts the string to the type of the value and
79 * sets the value with it.
82 gst_util_set_value_from_string (GValue * value, const gchar * value_str)
85 g_return_if_fail (value != NULL);
86 g_return_if_fail (value_str != NULL);
88 GST_CAT_DEBUG (GST_CAT_PARAMS, "parsing '%s' to type %s", value_str,
89 g_type_name (G_VALUE_TYPE (value)));
91 switch (G_VALUE_TYPE (value)) {
93 g_value_set_string (value, g_strdup (value_str));
99 sscanf (value_str, "%d", &i);
100 g_value_set_int (value, i);
106 sscanf (value_str, "%u", &i);
107 g_value_set_uint (value, i);
113 sscanf (value_str, "%ld", &i);
114 g_value_set_long (value, i);
120 sscanf (value_str, "%lu", &i);
121 g_value_set_ulong (value, i);
124 case G_TYPE_BOOLEAN:{
127 if (!strncmp ("true", value_str, 4))
129 g_value_set_boolean (value, i);
135 sscanf (value_str, "%c", &i);
136 g_value_set_char (value, i);
142 sscanf (value_str, "%c", &i);
143 g_value_set_uchar (value, i);
149 sscanf (value_str, "%f", &i);
150 g_value_set_float (value, i);
156 sscanf (value_str, "%g", &i);
157 g_value_set_double (value, (gdouble) i);
166 * gst_util_set_object_arg:
167 * @object: the object to set the argument of
168 * @name: the name of the argument to set
169 * @value: the string value to set
171 * Convertes the string value to the type of the objects argument and
172 * sets the argument with it.
175 gst_util_set_object_arg (GObject * object, const gchar * name,
179 GParamSpec *paramspec;
182 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
188 GST_DEBUG ("paramspec->flags is %d, paramspec->value_type is %d",
189 paramspec->flags, (gint) paramspec->value_type);
191 if (paramspec->flags & G_PARAM_WRITABLE) {
192 switch (paramspec->value_type) {
194 g_object_set (G_OBJECT (object), name, value, NULL);
200 sscanf (value, "%d", &i);
201 g_object_set (G_OBJECT (object), name, i, NULL);
207 sscanf (value, "%u", &i);
208 g_object_set (G_OBJECT (object), name, i, NULL);
214 sscanf (value, "%ld", &i);
215 g_object_set (G_OBJECT (object), name, i, NULL);
221 sscanf (value, "%lu", &i);
222 g_object_set (G_OBJECT (object), name, i, NULL);
225 case G_TYPE_BOOLEAN:{
228 if (!g_ascii_strncasecmp ("true", value, 4))
230 g_object_set (G_OBJECT (object), name, i, NULL);
236 sscanf (value, "%c", &i);
237 g_object_set (G_OBJECT (object), name, i, NULL);
243 sscanf (value, "%c", &i);
244 g_object_set (G_OBJECT (object), name, i, NULL);
250 sscanf (value, "%f", &i);
251 g_object_set (G_OBJECT (object), name, i, NULL);
257 sscanf (value, "%g", &i);
258 g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
262 if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
265 sscanf (value, "%d", &i);
266 g_object_set (G_OBJECT (object), name, i, NULL);
267 } else if (paramspec->value_type == GST_TYPE_URI) {
268 g_object_set (G_OBJECT (object), name, value, NULL);
276 /* -----------------------------------------------------
278 * The following code will be moved out of the main
279 * gstreamer library someday.
285 string_append_indent (GString * str, gint count)
289 for (xx = 0; xx < count; xx++)
290 g_string_append_c (str, ' ');
294 * gst_print_pad_caps:
295 * @buf: the buffer to print the caps in
296 * @indent: initial indentation
297 * @pad: the pad to print the caps from
299 * Write the pad capabilities in a human readable format into
303 gst_print_pad_caps (GString * buf, gint indent, GstPad * pad)
310 string_append_indent (buf, indent);
311 g_string_printf (buf, "%s:%s has no capabilities",
312 GST_DEBUG_PAD_NAME (pad));
316 s = gst_caps_to_string (caps);
317 g_string_append (buf, s);
323 * gst_print_element_args:
324 * @buf: the buffer to print the args in
325 * @indent: initial indentation
326 * @element: the element to print the args of
328 * Print the element argument in a human readable format in the given
332 gst_print_element_args (GString * buf, gint indent, GstElement * element)
335 GValue value = { 0, }; /* the important thing is that value.type = 0 */
337 GParamSpec *spec, **specs, **walk;
339 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), NULL);
342 for (walk = specs; *walk; walk++) {
344 if (width < strlen (spec->name))
345 width = strlen (spec->name);
348 for (walk = specs; *walk; walk++) {
351 if (spec->flags & G_PARAM_READABLE) {
352 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
353 g_object_get_property (G_OBJECT (element), spec->name, &value);
354 str = g_strdup_value_contents (&value);
355 g_value_unset (&value);
357 str = g_strdup ("Parameter not readable.");
360 string_append_indent (buf, indent);
361 g_string_append (buf, spec->name);
362 string_append_indent (buf, 2 + width - strlen (spec->name));
363 g_string_append (buf, str);
364 g_string_append_c (buf, '\n');
373 * gst_element_create_all_pads:
374 * @element: a #GstElement to create pads for
376 * Creates a pad for each pad template that is always available.
377 * This function is only useful during object intialization of
378 * subclasses of #GstElement.
381 gst_element_create_all_pads (GstElement * element)
385 /* FIXME: lock element */
388 gst_element_class_get_pad_template_list (GST_ELEMENT_CLASS
389 (G_OBJECT_GET_CLASS (element)));
392 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
394 if (padtempl->presence == GST_PAD_ALWAYS) {
397 pad = gst_pad_new_from_template (padtempl, padtempl->name_template);
399 gst_element_add_pad (element, pad);
401 padlist = padlist->next;
406 * gst_element_get_compatible_pad_template:
407 * @element: a #GstElement to get a compatible pad template for.
408 * @compattempl: the #GstPadTemplate to find a compatible template for.
410 * Retrieves a pad template from @element that is compatible with @compattempl.
411 * Pads from compatible templates can be linked together.
413 * Returns: a compatible #GstPadTemplate, or NULL if none was found. No
414 * unreferencing is necessary.
417 gst_element_get_compatible_pad_template (GstElement * element,
418 GstPadTemplate * compattempl)
420 GstPadTemplate *newtempl = NULL;
422 GstElementClass *class;
424 g_return_val_if_fail (element != NULL, NULL);
425 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
426 g_return_val_if_fail (compattempl != NULL, NULL);
428 class = GST_ELEMENT_GET_CLASS (element);
430 padlist = gst_element_class_get_pad_template_list (class);
432 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
433 "Looking for a suitable pad template in %s out of %d templates...",
434 GST_ELEMENT_NAME (element), g_list_length (padlist));
437 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
438 GstCaps *intersection;
442 * Check direction (must be opposite)
445 GST_CAT_LOG (GST_CAT_CAPS,
446 "checking pad template %s", padtempl->name_template);
447 if (padtempl->direction != compattempl->direction) {
448 GST_CAT_DEBUG (GST_CAT_CAPS,
449 "compatible direction: found %s pad template \"%s\"",
450 padtempl->direction == GST_PAD_SRC ? "src" : "sink",
451 padtempl->name_template);
453 GST_CAT_DEBUG (GST_CAT_CAPS,
454 "intersecting %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (compattempl));
455 GST_CAT_DEBUG (GST_CAT_CAPS,
456 "..and %" GST_PTR_FORMAT, GST_PAD_TEMPLATE_CAPS (padtempl));
458 intersection = gst_caps_intersect (GST_PAD_TEMPLATE_CAPS (compattempl),
459 GST_PAD_TEMPLATE_CAPS (padtempl));
461 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible %" GST_PTR_FORMAT,
462 (intersection ? "" : "not "), intersection);
464 if (!gst_caps_is_empty (intersection))
466 gst_caps_unref (intersection);
471 padlist = g_list_next (padlist);
474 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
475 "Returning new pad template %p", newtempl);
477 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "No compatible pad template found");
483 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
486 GstPad *newpad = NULL;
487 GstElementClass *oclass;
489 oclass = GST_ELEMENT_GET_CLASS (element);
491 if (oclass->request_new_pad)
492 newpad = (oclass->request_new_pad) (element, templ, name);
495 gst_object_ref (newpad);
503 * gst_element_get_pad_from_template:
504 * @element: a #GstElement.
505 * @templ: a #GstPadTemplate belonging to @element.
507 * Gets a pad from @element described by @templ. If the presence of @templ is
508 * #GST_PAD_REQUEST, requests a new pad. Can return %NULL for #GST_PAD_SOMETIMES
511 * Returns: the #GstPad, or NULL if one could not be found or created.
514 gst_element_get_pad_from_template (GstElement * element, GstPadTemplate * templ)
517 GstPadPresence presence;
519 /* If this function is ever exported, we need check the validity of `element'
520 * and `templ', and to make sure the template actually belongs to the
523 presence = GST_PAD_TEMPLATE_PRESENCE (templ);
527 case GST_PAD_SOMETIMES:
528 ret = gst_element_get_static_pad (element, templ->name_template);
529 if (!ret && presence == GST_PAD_ALWAYS)
531 ("Element %s has an ALWAYS template %s, but no pad of the same name",
532 GST_OBJECT_NAME (element), templ->name_template);
535 case GST_PAD_REQUEST:
536 ret = gst_element_request_pad (element, templ, NULL);
544 * gst_element_request_compatible_pad:
545 * @element: a #GstElement.
546 * @templ: the #GstPadTemplate to which the new pad should be able to link.
548 * Requests a pad from @element. The returned pad should be unlinked and
549 * compatible with @templ. Might return an existing pad, or request a new one.
551 * Returns: a #GstPad, or %NULL if one could not be found or created.
554 gst_element_request_compatible_pad (GstElement * element,
555 GstPadTemplate * templ)
557 GstPadTemplate *templ_new;
560 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
561 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
563 /* FIXME: should really loop through the templates, testing each for
564 * compatibility and pad availability. */
565 templ_new = gst_element_get_compatible_pad_template (element, templ);
567 pad = gst_element_get_pad_from_template (element, templ_new);
569 /* This can happen for non-request pads. No need to unref. */
570 if (pad && GST_PAD_PEER (pad))
577 * gst_element_get_compatible_pad:
578 * @element: a #GstElement in which the pad should be found.
579 * @pad: the #GstPad to find a compatible one for.
580 * @caps: the #GstCaps to use as a filter.
582 * Looks for an unlinked pad to which the given pad can link. It is not
583 * guaranteed that linking the pads will work, though it should work in most
586 * Returns: the #GstPad to which a link can be made, or %NULL if one cannot be
590 gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
591 const GstCaps * caps)
594 GstPadTemplate *templ;
596 GstPad *foundpad = NULL;
599 /* FIXME check for caps compatibility */
601 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
602 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
604 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
605 "finding pad in %s compatible with %s:%s",
606 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
608 g_return_val_if_fail (GST_PAD_PEER (pad) == NULL, NULL);
611 /* try to get an existing unlinked pad */
612 pads = gst_element_iterate_pads (element);
616 switch (gst_iterator_next (pads, &padptr)) {
617 case GST_ITERATOR_OK:
622 current = GST_PAD (padptr);
624 GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
625 GST_DEBUG_PAD_NAME (current));
627 peer = gst_pad_get_peer (current);
629 if (peer == NULL && gst_pad_can_link (pad, current)) {
631 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
632 "found existing unlinked pad %s:%s",
633 GST_DEBUG_PAD_NAME (current));
635 gst_iterator_free (pads);
639 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
641 gst_object_unref (current);
643 gst_object_unref (peer);
647 case GST_ITERATOR_DONE:
650 case GST_ITERATOR_RESYNC:
651 gst_iterator_resync (pads);
653 case GST_ITERATOR_ERROR:
654 g_assert_not_reached ();
658 gst_iterator_free (pads);
660 /* try to create a new one */
661 /* requesting is a little crazy, we need a template. Let's create one */
662 templcaps = gst_pad_get_caps (pad);
664 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
665 GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
666 foundpad = gst_element_request_compatible_pad (element, templ);
667 gst_object_unref (templ);
670 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
671 "found existing request pad %s:%s", GST_DEBUG_PAD_NAME (foundpad));
675 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element,
676 "Could not find a compatible pad to link to %s:%s",
677 GST_DEBUG_PAD_NAME (pad));
682 * gst_element_state_get_name:
683 * @state: a #GstElementState to get the name of.
685 * Gets a string representing the given state.
687 * Returns: a string with the name of the state.
690 gst_element_state_get_name (GstElementState state)
693 #ifdef GST_DEBUG_COLOR
694 case GST_STATE_VOID_PENDING:
695 return "NONE_PENDING";
698 return "\033[01;34mNULL\033[00m";
700 case GST_STATE_READY:
701 return "\033[01;31mREADY\033[00m";
703 case GST_STATE_PLAYING:
704 return "\033[01;32mPLAYING\033[00m";
706 case GST_STATE_PAUSED:
707 return "\033[01;33mPAUSED\033[00m";
710 /* This is a memory leak */
711 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
713 case GST_STATE_VOID_PENDING:
714 return "NONE_PENDING";
719 case GST_STATE_READY:
722 case GST_STATE_PLAYING:
725 case GST_STATE_PAUSED:
729 return g_strdup_printf ("UNKNOWN!(%d)", state);
736 * gst_element_factory_can_src_caps :
737 * @factory: factory to query
738 * @caps: the caps to check
740 * Checks if the factory can source the given capability.
742 * Returns: true if it can src the capabilities
745 gst_element_factory_can_src_caps (GstElementFactory * factory,
746 const GstCaps * caps)
750 g_return_val_if_fail (factory != NULL, FALSE);
751 g_return_val_if_fail (caps != NULL, FALSE);
753 templates = factory->staticpadtemplates;
756 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
758 if (template->direction == GST_PAD_SRC) {
759 if (gst_caps_is_always_compatible (gst_static_caps_get (&template->
763 templates = g_list_next (templates);
770 * gst_element_factory_can_sink_caps :
771 * @factory: factory to query
772 * @caps: the caps to check
774 * Checks if the factory can sink the given capability.
776 * Returns: true if it can sink the capabilities
779 gst_element_factory_can_sink_caps (GstElementFactory * factory,
780 const GstCaps * caps)
784 g_return_val_if_fail (factory != NULL, FALSE);
785 g_return_val_if_fail (caps != NULL, FALSE);
787 templates = factory->staticpadtemplates;
790 GstStaticPadTemplate *template = (GstStaticPadTemplate *) templates->data;
792 if (template->direction == GST_PAD_SINK) {
793 if (gst_caps_is_always_compatible (caps,
794 gst_static_caps_get (&template->static_caps)))
797 templates = g_list_next (templates);
804 /* if return val is true, *direct_child is a caller-owned ref on the direct
805 * child of ancestor that is part of object's ancestry */
807 object_has_ancestor (GstObject * object, GstObject * ancestor,
808 GstObject ** direct_child)
810 GstObject *child, *parent;
813 *direct_child = NULL;
815 child = gst_object_ref (object);
816 parent = gst_object_get_parent (object);
819 if (ancestor == parent) {
821 *direct_child = child;
823 gst_object_unref (child);
824 gst_object_unref (parent);
828 gst_object_unref (child);
830 parent = gst_object_get_parent (parent);
833 gst_object_unref (child);
838 /* caller owns return */
840 find_common_root (GstObject * o1, GstObject * o2)
843 GstObject *kid1, *kid2;
844 GstObject *root = NULL;
846 while (GST_OBJECT_PARENT (top))
847 top = GST_OBJECT_PARENT (top);
849 /* the itsy-bitsy spider... */
851 if (!object_has_ancestor (o2, top, &kid2))
854 root = gst_object_ref (top);
856 if (!object_has_ancestor (o1, kid2, &kid1)) {
857 gst_object_unref (kid2);
861 if (!object_has_ancestor (o2, kid1, &kid2)) {
862 gst_object_unref (kid1);
869 /* caller does not own return */
871 ghost_up (GstElement * e, GstPad * pad)
873 static gint ghost_pad_index = 0;
876 GstObject *parent = GST_OBJECT_PARENT (e);
878 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
879 gpad = gst_ghost_pad_new (name, pad);
882 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
883 g_warning ("Pad named %s already exists in element %s\n",
884 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
885 gst_object_unref ((GstObject *) gpad);
893 remove_pad (gpointer ppad, gpointer unused)
897 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
898 g_warning ("Couldn't remove pad %s from element %s",
899 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
903 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
904 GSList ** pads_created)
908 GSList *pads_created_local = NULL;
910 g_assert (pads_created);
912 e1 = GST_OBJECT_PARENT (*src);
913 e2 = GST_OBJECT_PARENT (*sink);
915 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
916 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
917 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
921 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
922 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
924 /* we need to setup some ghost pads */
925 root = find_common_root (e1, e2);
928 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
929 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
933 while (GST_OBJECT_PARENT (e1) != root) {
934 *src = ghost_up ((GstElement *) e1, *src);
937 e1 = GST_OBJECT_PARENT (*src);
938 pads_created_local = g_slist_prepend (pads_created_local, *src);
940 while (GST_OBJECT_PARENT (e2) != root) {
941 *sink = ghost_up ((GstElement *) e2, *sink);
944 e2 = GST_OBJECT_PARENT (*sink);
945 pads_created_local = g_slist_prepend (pads_created_local, *sink);
948 gst_object_unref (root);
949 *pads_created = g_slist_concat (*pads_created, pads_created_local);
953 gst_object_unref (root);
954 g_slist_foreach (pads_created_local, remove_pad, NULL);
955 g_slist_free (pads_created_local);
960 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
962 GSList *pads_created = NULL;
965 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
968 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
972 g_slist_foreach (pads_created, remove_pad, NULL);
974 g_slist_free (pads_created);
980 * gst_element_link_pads:
981 * @src: a #GstElement containing the source pad.
982 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
983 * @dest: the #GstElement containing the destination pad.
984 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
986 * Links the two named pads of the source and destination elements.
987 * Side effect is that if one of the pads has no parent, it becomes a
988 * child of the parent of the other element. If they have different
989 * parents, the link fails.
991 * Returns: TRUE if the pads could be linked, FALSE otherwise.
994 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
995 GstElement * dest, const gchar * destpadname)
997 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
998 GstPad *srcpad, *destpad;
999 GstPadTemplate *srctempl, *desttempl;
1000 GstElementClass *srcclass, *destclass;
1003 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1004 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1006 srcclass = GST_ELEMENT_GET_CLASS (src);
1007 destclass = GST_ELEMENT_GET_CLASS (dest);
1009 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
1010 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
1011 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
1012 destpadname ? destpadname : "(any)");
1014 /* now get the pads we're trying to link and a list of all remaining pads */
1016 srcpad = gst_element_get_pad (src, srcpadname);
1018 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1019 GST_ELEMENT_NAME (src), srcpadname);
1022 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1023 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
1024 GST_DEBUG_PAD_NAME (srcpad));
1025 gst_object_unref (srcpad);
1028 if (GST_PAD_PEER (srcpad) != NULL) {
1029 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1030 GST_DEBUG_PAD_NAME (srcpad));
1031 gst_object_unref (srcpad);
1038 srcpads = GST_ELEMENT_PADS (src);
1039 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
1041 gst_object_ref (srcpad);
1045 destpad = gst_element_get_pad (dest, destpadname);
1047 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
1048 GST_ELEMENT_NAME (dest), destpadname);
1051 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1052 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
1053 GST_DEBUG_PAD_NAME (destpad));
1054 gst_object_unref (destpad);
1057 if (GST_PAD_PEER (destpad) != NULL) {
1058 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
1059 GST_DEBUG_PAD_NAME (destpad));
1060 gst_object_unref (destpad);
1067 destpads = GST_ELEMENT_PADS (dest);
1068 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1070 gst_object_ref (destpad);
1074 if (srcpadname && destpadname) {
1077 /* two explicitly specified pads */
1078 result = pad_link_maybe_ghosting (srcpad, destpad);
1080 gst_object_unref (srcpad);
1081 gst_object_unref (destpad);
1086 /* loop through the allowed pads in the source, trying to find a
1087 * compatible destination pad */
1088 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1089 "looping through allowed src and dest pads");
1091 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1092 GST_DEBUG_PAD_NAME (srcpad));
1093 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1094 (GST_PAD_PEER (srcpad) == NULL)) {
1099 gst_object_ref (temp);
1101 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1104 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1105 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1106 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1108 gst_object_unref (destpad);
1109 gst_object_unref (srcpad);
1110 gst_object_unref (temp);
1115 gst_object_unref (temp);
1118 /* find a better way for this mess */
1120 srcpads = g_list_next (srcpads);
1122 gst_object_unref (srcpad);
1123 srcpad = GST_PAD_CAST (srcpads->data);
1124 gst_object_ref (srcpad);
1130 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1131 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1132 gst_object_unref (srcpad);
1134 gst_object_unref (destpad);
1138 gst_object_unref (srcpad);
1142 /* loop through the existing pads in the destination */
1144 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1145 GST_DEBUG_PAD_NAME (destpad));
1146 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1147 (GST_PAD_PEER (destpad) == NULL)) {
1148 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1150 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1151 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1152 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1153 gst_object_unref (temp);
1154 gst_object_unref (destpad);
1156 gst_object_unref (srcpad);
1160 gst_object_unref (temp);
1164 destpads = g_list_next (destpads);
1166 gst_object_unref (destpad);
1167 destpad = GST_PAD_CAST (destpads->data);
1168 gst_object_ref (destpad);
1174 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1175 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1176 gst_object_unref (destpad);
1178 gst_object_unref (srcpad);
1181 gst_object_unref (destpad);
1183 gst_object_unref (srcpad);
1188 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1189 "we might have request pads on both sides, checking...");
1190 srctempls = gst_element_class_get_pad_template_list (srcclass);
1191 desttempls = gst_element_class_get_pad_template_list (destclass);
1193 if (srctempls && desttempls) {
1195 srctempl = (GstPadTemplate *) srctempls->data;
1196 if (srctempl->presence == GST_PAD_REQUEST) {
1197 for (l = desttempls; l; l = l->next) {
1198 desttempl = (GstPadTemplate *) l->data;
1199 if (desttempl->presence == GST_PAD_REQUEST &&
1200 desttempl->direction != srctempl->direction) {
1201 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1202 (srctempl), gst_pad_template_get_caps (desttempl))) {
1204 gst_element_get_request_pad (src, srctempl->name_template);
1206 gst_element_get_request_pad (dest, desttempl->name_template);
1207 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1208 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1209 "linked pad %s:%s to pad %s:%s",
1210 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1211 gst_object_unref (srcpad);
1212 gst_object_unref (destpad);
1215 /* it failed, so we release the request pads */
1216 gst_element_release_request_pad (src, srcpad);
1217 gst_element_release_request_pad (dest, destpad);
1222 srctempls = srctempls->next;
1226 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1227 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1233 * @src: a #GstElement containing the source pad.
1234 * @dest: the #GstElement containing the destination pad.
1236 * Links @src to @dest. The link must be from source to
1237 * destination; the other direction will not be tried. The function looks for
1238 * existing pads that aren't linked yet. It will request new pads if necessary.
1239 * If multiple links are possible, only one is established.
1241 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1244 gst_element_link (GstElement * src, GstElement * dest)
1246 return gst_element_link_pads (src, NULL, dest, NULL);
1250 * gst_element_link_many:
1251 * @element_1: the first #GstElement in the link chain.
1252 * @element_2: the second #GstElement in the link chain.
1253 * @...: the NULL-terminated list of elements to link in order.
1255 * Chain together a series of elements. Uses gst_element_link().
1257 * Returns: TRUE on success, FALSE otherwise.
1260 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1264 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1265 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1267 va_start (args, element_2);
1270 if (!gst_element_link (element_1, element_2))
1273 element_1 = element_2;
1274 element_2 = va_arg (args, GstElement *);
1283 * gst_element_unlink_pads:
1284 * @src: a #GstElement containing the source pad.
1285 * @srcpadname: the name of the #GstPad in source element.
1286 * @dest: a #GstElement containing the destination pad.
1287 * @destpadname: the name of the #GstPad in destination element.
1289 * Unlinks the two named pads of the source and destination elements.
1292 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1293 GstElement * dest, const gchar * destpadname)
1295 GstPad *srcpad, *destpad;
1297 g_return_if_fail (src != NULL);
1298 g_return_if_fail (GST_IS_ELEMENT (src));
1299 g_return_if_fail (srcpadname != NULL);
1300 g_return_if_fail (dest != NULL);
1301 g_return_if_fail (GST_IS_ELEMENT (dest));
1302 g_return_if_fail (destpadname != NULL);
1304 /* obtain the pads requested */
1305 srcpad = gst_element_get_pad (src, srcpadname);
1306 if (srcpad == NULL) {
1307 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1310 destpad = gst_element_get_pad (dest, destpadname);
1311 if (srcpad == NULL) {
1312 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1317 /* we're satisified they can be unlinked, let's do it */
1318 gst_pad_unlink (srcpad, destpad);
1322 * gst_element_unlink_many:
1323 * @element_1: the first #GstElement in the link chain.
1324 * @element_2: the second #GstElement in the link chain.
1325 * @...: the NULL-terminated list of elements to unlink in order.
1327 * Unlinks a series of elements. Uses gst_element_unlink().
1330 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1334 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1335 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1337 va_start (args, element_2);
1340 gst_element_unlink (element_1, element_2);
1342 element_1 = element_2;
1343 element_2 = va_arg (args, GstElement *);
1350 * gst_element_unlink:
1351 * @src: the source #GstElement to unlink.
1352 * @dest: the sink #GstElement to unlink.
1354 * Unlinks all source pads of the source element with all sink pads
1355 * of the sink element to which they are linked.
1358 gst_element_unlink (GstElement * src, GstElement * dest)
1361 gboolean done = FALSE;
1363 g_return_if_fail (GST_IS_ELEMENT (src));
1364 g_return_if_fail (GST_IS_ELEMENT (dest));
1366 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1367 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1369 pads = gst_element_iterate_pads (src);
1373 switch (gst_iterator_next (pads, &data)) {
1374 case GST_ITERATOR_OK:
1376 GstPad *pad = GST_PAD_CAST (data);
1378 if (GST_PAD_IS_SRC (pad)) {
1379 GstPad *peerpad = gst_pad_get_peer (pad);
1381 /* see if the pad is connected and is really a pad
1384 GstElement *peerelem = gst_pad_get_parent (peerpad);
1386 if (peerelem == dest) {
1387 gst_pad_unlink (pad, peerpad);
1390 gst_object_unref (peerelem);
1392 gst_object_unref (peerpad);
1395 gst_object_unref (pad);
1398 case GST_ITERATOR_RESYNC:
1399 gst_iterator_resync (pads);
1401 case GST_ITERATOR_DONE:
1405 g_assert_not_reached ();
1412 gst_element_query_position (GstElement * element, GstFormat * format,
1413 gint64 * cur, gint64 * end)
1418 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1419 g_return_val_if_fail (format != NULL, FALSE);
1421 query = gst_query_new_position (*format);
1422 ret = gst_element_query (element, query);
1425 gst_query_parse_position (query, format, cur, end);
1427 gst_query_unref (query);
1433 gst_element_query_convert (GstElement * element, GstFormat src_format,
1434 gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
1439 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1440 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1441 g_return_val_if_fail (dest_val != NULL, FALSE);
1443 if (*dest_fmt == src_format) {
1444 *dest_val = src_val;
1448 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1449 ret = gst_element_query (element, query);
1452 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1454 gst_query_unref (query);
1462 * @srcpad: the source #GstPad to link.
1463 * @sinkpad: the sink #GstPad to link.
1465 * Checks if the source pad and the sink pad can be linked.
1466 * Both @srcpad and @sinkpad must be unlinked.
1468 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1471 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1473 /* FIXME This function is gross. It's almost a direct copy of
1474 * gst_pad_link_filtered(). Any decent programmer would attempt
1475 * to merge the two functions, which I will do some day. --ds
1478 /* generic checks */
1479 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1480 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1482 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1483 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1485 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1486 if (GST_PAD_PEER (srcpad) != NULL) {
1487 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1488 GST_DEBUG_PAD_NAME (srcpad));
1491 if (GST_PAD_PEER (sinkpad) != NULL) {
1492 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1493 GST_DEBUG_PAD_NAME (sinkpad));
1496 if (!GST_PAD_IS_SRC (srcpad)) {
1497 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1498 GST_DEBUG_PAD_NAME (srcpad));
1501 if (!GST_PAD_IS_SINK (sinkpad)) {
1502 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1503 GST_DEBUG_PAD_NAME (sinkpad));
1506 if (GST_PAD_PARENT (srcpad) == NULL) {
1507 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1508 GST_DEBUG_PAD_NAME (srcpad));
1511 if (GST_PAD_PARENT (sinkpad) == NULL) {
1512 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1513 GST_DEBUG_PAD_NAME (srcpad));
1521 * gst_pad_use_fixed_caps:
1522 * @pad: the pad to use
1524 * A helper function you can use that sets the
1525 * @gst_pad_get_fixed_caps_func as the gstcaps function for the
1526 * pad. This way the function will always return the negotiated caps
1527 * or in case the pad is not negotiated, the padtemplate caps.
1530 gst_pad_use_fixed_caps (GstPad * pad)
1532 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1536 * gst_pad_get_fixed_caps_func:
1537 * @pad: the pad to use
1539 * A helper function you can use as a GetCaps function that
1540 * will return the currently negotiated caps or the padtemplate
1543 * Returns: The currently negotiated caps or the padtemplate.
1546 gst_pad_get_fixed_caps_func (GstPad * pad)
1550 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1552 if (GST_PAD_CAPS (pad)) {
1553 result = GST_PAD_CAPS (pad);
1555 GST_CAT_DEBUG (GST_CAT_CAPS,
1556 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1558 result = gst_caps_ref (result);
1561 if (GST_PAD_PAD_TEMPLATE (pad)) {
1562 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1564 result = GST_PAD_TEMPLATE_CAPS (templ);
1565 GST_CAT_DEBUG (GST_CAT_CAPS,
1566 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1569 result = gst_caps_ref (result);
1572 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1573 result = gst_caps_new_empty ();
1580 * gst_object_default_error:
1581 * @object: a #GObject that signalled the error.
1582 * @orig: the #GstObject that initiated the error.
1583 * @error: the GError.
1584 * @debug: an additional debug information string, or NULL.
1586 * A default error function.
1588 * The default handler will simply print the error string using g_print.
1591 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
1593 gchar *name = gst_object_get_path_string (source);
1595 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
1597 g_print (_("Additional debug info:\n%s\n"), debug);
1604 * @bin: the bin to add the elements to
1605 * @element_1: the first element to add to the bin
1606 * @...: additional elements to add to the bin
1608 * Adds a NULL-terminated list of elements to a bin. This function is
1609 * equivalent to calling #gst_bin_add() for each member of the list.
1612 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
1616 g_return_if_fail (GST_IS_BIN (bin));
1617 g_return_if_fail (GST_IS_ELEMENT (element_1));
1619 va_start (args, element_1);
1622 gst_bin_add (bin, element_1);
1624 element_1 = va_arg (args, GstElement *);
1631 * gst_bin_remove_many:
1632 * @bin: the bin to remove the elements from
1633 * @element_1: the first element to remove from the bin
1634 * @...: NULL-terminated list of elements to remove from the bin
1636 * Remove a list of elements from a bin. This function is equivalent
1637 * to calling #gst_bin_remove with each member of the list.
1640 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
1644 g_return_if_fail (GST_IS_BIN (bin));
1645 g_return_if_fail (GST_IS_ELEMENT (element_1));
1647 va_start (args, element_1);
1650 gst_bin_remove (bin, element_1);
1652 element_1 = va_arg (args, GstElement *);
1659 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
1660 guint arg_id, GParamFlags flags)
1662 GQuark prop_id = g_quark_from_string (prop_name);
1665 static GQuark fd_id = 0;
1666 static GQuark blocksize_id;
1667 static GQuark bytesperread_id;
1668 static GQuark dump_id;
1669 static GQuark filesize_id;
1670 static GQuark mmapsize_id;
1671 static GQuark location_id;
1672 static GQuark offset_id;
1673 static GQuark silent_id;
1674 static GQuark touch_id;
1677 fd_id = g_quark_from_static_string ("fd");
1678 blocksize_id = g_quark_from_static_string ("blocksize");
1679 bytesperread_id = g_quark_from_static_string ("bytesperread");
1680 dump_id = g_quark_from_static_string ("dump");
1681 filesize_id = g_quark_from_static_string ("filesize");
1682 mmapsize_id = g_quark_from_static_string ("mmapsize");
1683 location_id = g_quark_from_static_string ("location");
1684 offset_id = g_quark_from_static_string ("offset");
1685 silent_id = g_quark_from_static_string ("silent");
1686 touch_id = g_quark_from_static_string ("touch");
1689 if (prop_id == fd_id) {
1690 pspec = g_param_spec_int ("fd", "File-descriptor",
1691 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
1692 } else if (prop_id == blocksize_id) {
1693 pspec = g_param_spec_ulong ("blocksize", "Block Size",
1694 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
1696 } else if (prop_id == bytesperread_id) {
1697 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
1698 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
1700 } else if (prop_id == dump_id) {
1701 pspec = g_param_spec_boolean ("dump", "Dump",
1702 "Dump bytes to stdout", FALSE, flags);
1704 } else if (prop_id == filesize_id) {
1705 pspec = g_param_spec_int64 ("filesize", "File Size",
1706 "Size of the file being read", 0, G_MAXINT64, 0, flags);
1708 } else if (prop_id == mmapsize_id) {
1709 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
1710 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
1712 } else if (prop_id == location_id) {
1713 pspec = g_param_spec_string ("location", "File Location",
1714 "Location of the file to read", NULL, flags);
1716 } else if (prop_id == offset_id) {
1717 pspec = g_param_spec_int64 ("offset", "File Offset",
1718 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
1720 } else if (prop_id == silent_id) {
1721 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
1724 } else if (prop_id == touch_id) {
1725 pspec = g_param_spec_boolean ("touch", "Touch read data",
1726 "Touch data to force disk read before " "push ()", TRUE, flags);
1728 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
1729 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
1734 g_object_class_install_property (klass, arg_id, pspec);
1739 * gst_element_class_install_std_props:
1740 * @klass: the #GstElementClass to add the properties to.
1741 * @first_name: the name of the first property.
1742 * in a NULL terminated
1743 * @...: the id and flags of the first property, followed by
1744 * further 'name', 'id', 'flags' triplets and terminated by NULL.
1746 * Adds a list of standardized properties with types to the @klass.
1747 * the id is for the property switch in your get_prop method, and
1748 * the flags determine readability / writeability.
1751 gst_element_class_install_std_props (GstElementClass * klass,
1752 const gchar * first_name, ...)
1758 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1760 va_start (args, first_name);
1765 int arg_id = va_arg (args, int);
1766 int flags = va_arg (args, int);
1768 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
1771 name = va_arg (args, char *);
1780 * @buf1: a first source #GstBuffer to merge.
1781 * @buf2: the second source #GstBuffer to merge.
1783 * Create a new buffer that is the concatenation of the two source
1784 * buffers. The original source buffers will not be modified or
1785 * unref'd. Make sure you unref the source buffers if they are not used
1786 * anymore afterwards.
1788 * If the buffers point to contiguous areas of memory, the buffer
1789 * is created without copying the data.
1791 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
1794 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
1798 /* we're just a specific case of the more general gst_buffer_span() */
1799 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
1806 * @buf1: a first source #GstBuffer to merge.
1807 * @buf2: the second source #GstBuffer to merge.
1809 * Create a new buffer that is the concatenation of the two source
1810 * buffers, and takes ownership of the original source buffers.
1812 * If the buffers point to contiguous areas of memory, the buffer
1813 * is created without copying the data.
1815 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
1818 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
1822 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
1823 gst_buffer_unref (buf1);
1824 gst_buffer_unref (buf2);
1832 * @dest: buffer to stamp
1833 * @src: buffer to stamp from
1835 * Copies additional information (timestamps and offsets) from one buffer to
1839 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
1841 g_return_if_fail (dest != NULL);
1842 g_return_if_fail (src != NULL);
1844 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
1845 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
1846 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
1847 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
1851 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
1854 GstCaps *peercaps, *existing;
1856 existing = g_value_get_pointer (ret);
1857 peercaps = gst_pad_peer_get_caps (pad);
1858 if (peercaps == NULL)
1859 peercaps = gst_caps_new_any ();
1860 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
1861 gst_caps_unref (existing);
1862 gst_caps_unref (peercaps);
1868 * gst_pad_proxy_getcaps:
1869 * @pad: a #GstPad to proxy.
1871 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
1872 * same element as @pad, and returns the intersection of the results.
1874 * This function is useful as a default getcaps function for an element
1875 * that can handle any stream format, but requires all its pads to have
1876 * the same caps. Two such elements are tee and aggregator.
1878 * Returns: the intersection of the other pads' allowed caps.
1881 gst_pad_proxy_getcaps (GstPad * pad)
1883 GstElement *element;
1884 GstCaps *caps, *intersected;
1886 GstIteratorResult res;
1887 GValue ret = { 0, };
1889 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1891 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
1893 element = gst_pad_get_parent (pad);
1894 if (element == NULL)
1897 iter = gst_element_iterate_pads (element);
1899 g_value_init (&ret, G_TYPE_POINTER);
1900 g_value_set_pointer (&ret, gst_caps_new_any ());
1902 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
1904 gst_iterator_free (iter);
1906 if (res != GST_ITERATOR_DONE) {
1907 g_warning ("Pad list changed during capsnego for element %s",
1908 GST_ELEMENT_NAME (element));
1912 caps = g_value_get_pointer (&ret);
1913 g_value_unset (&ret);
1915 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
1916 gst_caps_unref (caps);
1928 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
1930 gboolean success = TRUE;
1932 if (pad != data->orig) {
1933 success = gst_pad_set_caps (pad, data->caps);
1934 g_value_set_boolean (ret, success);
1941 * gst_pad_proxy_setcaps
1942 * @pad: a #GstPad to proxy from
1943 * @caps: the #GstCaps to link with
1945 * Calls gst_pad_set_caps() for every other pad belonging to the
1946 * same element as @pad. If gst_pad_set_caps() fails on any pad,
1947 * the proxy setcaps fails. May be used only during negotiation.
1949 * Returns: TRUE if sucessful
1952 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
1954 GstElement *element;
1956 GstIteratorResult res;
1957 GValue ret = { 0, };
1960 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1961 g_return_val_if_fail (caps != NULL, FALSE);
1963 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
1965 element = gst_pad_get_parent (pad);
1967 iter = gst_element_iterate_pads (element);
1969 g_value_init (&ret, G_TYPE_BOOLEAN);
1970 g_value_set_boolean (&ret, TRUE);
1974 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
1976 gst_iterator_free (iter);
1978 if (res != GST_ITERATOR_DONE) {
1979 g_warning ("Pad list changed during proxy_pad_link for element %s",
1980 GST_ELEMENT_NAME (element));
1984 /* ok not to unset the gvalue */
1985 return g_value_get_boolean (&ret);
1989 * gst_pad_query_position:
1990 * @pad: a #GstPad to invoke the position query on.
1991 * @format: a pointer to the #GstFormat asked for.
1992 * On return contains the #GstFormat used.
1993 * @cur: A location in which to store the current position, or NULL.
1994 * @end: A location in which to store the end position (length), or NULL.
1996 * Queries a pad for the stream position and length.
1998 * Returns: TRUE if the query could be performed.
2001 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur,
2007 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2008 g_return_val_if_fail (format != NULL, FALSE);
2010 query = gst_query_new_position (*format);
2011 ret = gst_pad_query (pad, query);
2014 gst_query_parse_position (query, format, cur, end);
2016 gst_query_unref (query);
2022 * gst_pad_query_convert:
2023 * @pad: a #GstPad to invoke the convert query on.
2024 * @src_format: a #GstFormat to convert from.
2025 * @src_val: a value to convert.
2026 * @dest_format: a pointer to the #GstFormat to convert to.
2027 * @dest_val: a pointer to the result.
2029 * Queries a pad to convert @src_val in @src_format to @dest_format.
2031 * Returns: TRUE if the query could be performed.
2034 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
2035 GstFormat * dest_fmt, gint64 * dest_val)
2040 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2041 g_return_val_if_fail (dest_fmt != NULL, FALSE);
2042 g_return_val_if_fail (dest_val != NULL, FALSE);
2044 if (*dest_fmt == src_format) {
2045 *dest_val = src_val;
2049 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
2050 ret = gst_pad_query (pad, query);
2053 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
2055 gst_query_unref (query);
2061 * gst_atomic_int_set:
2062 * @atomic_int: pointer to an atomic integer
2063 * @value: value to set
2065 * Unconditionally sets the atomic integer to @value.
2068 gst_atomic_int_set (gint * atomic_int, gint value)
2072 *atomic_int = value;
2073 ignore = g_atomic_int_get (atomic_int);