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 (GST_OBJECT (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 * @filtercaps: 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 (GST_OBJECT (current));
643 gst_object_unref (GST_OBJECT (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 (GST_OBJECT (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);
735 /* if return val is true, *direct_child is a caller-owned ref on the direct
736 * child of ancestor that is part of object's ancestry */
738 object_has_ancestor (GstObject * object, GstObject * ancestor,
739 GstObject ** direct_child)
741 GstObject *child, *parent;
744 *direct_child = NULL;
746 child = gst_object_ref (object);
747 parent = gst_object_get_parent (object);
750 if (ancestor == parent) {
752 *direct_child = child;
754 gst_object_unref (child);
755 gst_object_unref (parent);
759 gst_object_unref (child);
761 parent = gst_object_get_parent (parent);
764 gst_object_unref (child);
769 /* caller owns return */
771 find_common_root (GstObject * o1, GstObject * o2)
774 GstObject *kid1, *kid2;
775 GstObject *root = NULL;
777 while (GST_OBJECT_PARENT (top))
778 top = GST_OBJECT_PARENT (top);
780 /* the itsy-bitsy spider... */
782 if (!object_has_ancestor (o2, top, &kid2))
785 root = gst_object_ref (top);
787 if (!object_has_ancestor (o1, kid2, &kid1)) {
788 gst_object_unref (kid2);
792 if (!object_has_ancestor (o2, kid1, &kid2)) {
793 gst_object_unref (kid1);
800 /* caller does not own return */
802 ghost_up (GstElement * e, GstPad * pad)
804 static gint ghost_pad_index = 0;
807 GstObject *parent = GST_OBJECT_PARENT (e);
809 name = g_strdup_printf ("ghost%d", ghost_pad_index++);
810 gpad = gst_ghost_pad_new (name, pad);
813 if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
814 g_warning ("Pad named %s already exists in element %s\n",
815 GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
816 gst_object_unref ((GstObject *) gpad);
824 remove_pad (gpointer ppad, gpointer unused)
828 if (!gst_element_remove_pad ((GstElement *) GST_OBJECT_PARENT (pad), pad))
829 g_warning ("Couldn't remove pad %s from element %s",
830 GST_OBJECT_NAME (pad), GST_OBJECT_NAME (GST_OBJECT_PARENT (pad)));
834 prepare_link_maybe_ghosting (GstPad ** src, GstPad ** sink,
835 GSList ** pads_created)
839 GSList *pads_created_local = NULL;
841 g_assert (pads_created);
843 e1 = GST_OBJECT_PARENT (*src);
844 e2 = GST_OBJECT_PARENT (*sink);
846 if (GST_OBJECT_PARENT (e1) == GST_OBJECT_PARENT (e2)) {
847 GST_CAT_INFO (GST_CAT_PADS, "%s and %s in same bin, no need for ghost pads",
848 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
852 GST_CAT_INFO (GST_CAT_PADS, "%s and %s not in same bin, making ghost pads",
853 GST_OBJECT_NAME (e1), GST_OBJECT_NAME (e2));
855 /* we need to setup some ghost pads */
856 root = find_common_root (e1, e2);
859 ("Trying to connect elements that don't share a common ancestor: %s and %s\n",
860 GST_ELEMENT_NAME (e1), GST_ELEMENT_NAME (e2));
864 while (GST_OBJECT_PARENT (e1) != root) {
865 *src = ghost_up ((GstElement *) e1, *src);
868 e1 = GST_OBJECT_PARENT (*src);
869 pads_created_local = g_slist_prepend (pads_created_local, *src);
871 while (GST_OBJECT_PARENT (e2) != root) {
872 *sink = ghost_up ((GstElement *) e2, *sink);
875 e2 = GST_OBJECT_PARENT (*sink);
876 pads_created_local = g_slist_prepend (pads_created_local, *sink);
879 gst_object_unref (root);
880 *pads_created = g_slist_concat (*pads_created, pads_created_local);
884 gst_object_unref (root);
885 g_slist_foreach (pads_created_local, remove_pad, NULL);
886 g_slist_free (pads_created_local);
891 pad_link_maybe_ghosting (GstPad * src, GstPad * sink)
893 GSList *pads_created = NULL;
896 if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
899 ret = (gst_pad_link (src, sink) == GST_PAD_LINK_OK);
903 g_slist_foreach (pads_created, remove_pad, NULL);
905 g_slist_free (pads_created);
911 * gst_element_link_pads:
912 * @src: a #GstElement containing the source pad.
913 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
914 * @dest: the #GstElement containing the destination pad.
915 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
917 * Links the two named pads of the source and destination elements.
918 * Side effect is that if one of the pads has no parent, it becomes a
919 * child of the parent of the other element. If they have different
920 * parents, the link fails.
922 * Returns: TRUE if the pads could be linked, FALSE otherwise.
925 gst_element_link_pads (GstElement * src, const gchar * srcpadname,
926 GstElement * dest, const gchar * destpadname)
928 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
929 GstPad *srcpad, *destpad;
930 GstPadTemplate *srctempl, *desttempl;
931 GstElementClass *srcclass, *destclass;
934 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
935 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
937 srcclass = GST_ELEMENT_GET_CLASS (src);
938 destclass = GST_ELEMENT_GET_CLASS (dest);
940 GST_CAT_INFO (GST_CAT_ELEMENT_PADS,
941 "trying to link element %s:%s to element %s:%s", GST_ELEMENT_NAME (src),
942 srcpadname ? srcpadname : "(any)", GST_ELEMENT_NAME (dest),
943 destpadname ? destpadname : "(any)");
945 /* now get the pads we're trying to link and a list of all remaining pads */
947 srcpad = gst_element_get_pad (src, srcpadname);
949 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
950 GST_ELEMENT_NAME (src), srcpadname);
953 if (!(GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
954 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad",
955 GST_DEBUG_PAD_NAME (srcpad));
956 gst_object_unref (GST_OBJECT (srcpad));
959 if (GST_PAD_PEER (srcpad) != NULL) {
960 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
961 GST_DEBUG_PAD_NAME (srcpad));
962 gst_object_unref (GST_OBJECT (srcpad));
969 srcpads = GST_ELEMENT_PADS (src);
970 srcpad = srcpads ? GST_PAD_CAST (srcpads->data) : NULL;
972 gst_object_ref (GST_OBJECT (srcpad));
976 destpad = gst_element_get_pad (dest, destpadname);
978 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s",
979 GST_ELEMENT_NAME (dest), destpadname);
982 if (!(GST_PAD_DIRECTION (destpad) == GST_PAD_SINK)) {
983 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad",
984 GST_DEBUG_PAD_NAME (destpad));
985 gst_object_unref (GST_OBJECT (destpad));
988 if (GST_PAD_PEER (destpad) != NULL) {
989 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked",
990 GST_DEBUG_PAD_NAME (destpad));
991 gst_object_unref (GST_OBJECT (destpad));
998 destpads = GST_ELEMENT_PADS (dest);
999 destpad = destpads ? GST_PAD_CAST (destpads->data) : NULL;
1001 gst_object_ref (GST_OBJECT (destpad));
1005 if (srcpadname && destpadname) {
1008 /* two explicitly specified pads */
1009 result = pad_link_maybe_ghosting (srcpad, destpad);
1011 gst_object_unref (GST_OBJECT (srcpad));
1012 gst_object_unref (GST_OBJECT (destpad));
1017 /* loop through the allowed pads in the source, trying to find a
1018 * compatible destination pad */
1019 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1020 "looping through allowed src and dest pads");
1022 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1023 GST_DEBUG_PAD_NAME (srcpad));
1024 if ((GST_PAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1025 (GST_PAD_PEER (srcpad) == NULL)) {
1030 gst_object_ref (GST_OBJECT (temp));
1032 temp = gst_element_get_compatible_pad (dest, srcpad, NULL);
1035 if (temp && pad_link_maybe_ghosting (srcpad, temp)) {
1036 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1037 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1039 gst_object_unref (GST_OBJECT (destpad));
1040 gst_object_unref (GST_OBJECT (srcpad));
1041 gst_object_unref (GST_OBJECT (temp));
1046 gst_object_unref (GST_OBJECT (temp));
1049 /* find a better way for this mess */
1051 srcpads = g_list_next (srcpads);
1053 gst_object_unref (GST_OBJECT (srcpad));
1054 srcpad = GST_PAD_CAST (srcpads->data);
1055 gst_object_ref (GST_OBJECT (srcpad));
1061 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1062 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1063 gst_object_unref (GST_OBJECT (srcpad));
1065 gst_object_unref (GST_OBJECT (destpad));
1069 gst_object_unref (GST_OBJECT (srcpad));
1073 /* loop through the existing pads in the destination */
1075 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1076 GST_DEBUG_PAD_NAME (destpad));
1077 if ((GST_PAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1078 (GST_PAD_PEER (destpad) == NULL)) {
1079 GstPad *temp = gst_element_get_compatible_pad (src, destpad, NULL);
1081 if (temp && pad_link_maybe_ghosting (temp, destpad)) {
1082 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1083 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1084 gst_object_unref (GST_OBJECT (temp));
1085 gst_object_unref (GST_OBJECT (destpad));
1087 gst_object_unref (GST_OBJECT (srcpad));
1091 gst_object_unref (GST_OBJECT (temp));
1095 destpads = g_list_next (destpads);
1097 gst_object_unref (GST_OBJECT (destpad));
1098 destpad = GST_PAD_CAST (destpads->data);
1099 gst_object_ref (GST_OBJECT (destpad));
1105 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1106 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1107 gst_object_unref (GST_OBJECT (destpad));
1109 gst_object_unref (GST_OBJECT (srcpad));
1112 gst_object_unref (GST_OBJECT (destpad));
1114 gst_object_unref (GST_OBJECT (srcpad));
1119 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1120 "we might have request pads on both sides, checking...");
1121 srctempls = gst_element_class_get_pad_template_list (srcclass);
1122 desttempls = gst_element_class_get_pad_template_list (destclass);
1124 if (srctempls && desttempls) {
1126 srctempl = (GstPadTemplate *) srctempls->data;
1127 if (srctempl->presence == GST_PAD_REQUEST) {
1128 for (l = desttempls; l; l = l->next) {
1129 desttempl = (GstPadTemplate *) l->data;
1130 if (desttempl->presence == GST_PAD_REQUEST &&
1131 desttempl->direction != srctempl->direction) {
1132 if (gst_caps_is_always_compatible (gst_pad_template_get_caps
1133 (srctempl), gst_pad_template_get_caps (desttempl))) {
1135 gst_element_get_request_pad (src, srctempl->name_template);
1137 gst_element_get_request_pad (dest, desttempl->name_template);
1138 if (pad_link_maybe_ghosting (srcpad, destpad)) {
1139 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1140 "linked pad %s:%s to pad %s:%s",
1141 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
1142 gst_object_unref (GST_OBJECT (srcpad));
1143 gst_object_unref (GST_OBJECT (destpad));
1146 /* it failed, so we release the request pads */
1147 gst_element_release_request_pad (src, srcpad);
1148 gst_element_release_request_pad (dest, destpad);
1153 srctempls = srctempls->next;
1157 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1158 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1164 * @src: a #GstElement containing the source pad.
1165 * @dest: the #GstElement containing the destination pad.
1167 * Links @src to @dest. The link must be from source to
1168 * destination; the other direction will not be tried. The function looks for
1169 * existing pads that aren't linked yet. It will request new pads if necessary.
1170 * If multiple links are possible, only one is established.
1172 * Returns: TRUE if the elements could be linked, FALSE otherwise.
1175 gst_element_link (GstElement * src, GstElement * dest)
1177 return gst_element_link_pads (src, NULL, dest, NULL);
1181 * gst_element_link_many:
1182 * @element_1: the first #GstElement in the link chain.
1183 * @element_2: the second #GstElement in the link chain.
1184 * @...: the NULL-terminated list of elements to link in order.
1186 * Chain together a series of elements. Uses gst_element_link().
1188 * Returns: TRUE on success, FALSE otherwise.
1191 gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
1195 g_return_val_if_fail (GST_IS_ELEMENT (element_1), FALSE);
1196 g_return_val_if_fail (GST_IS_ELEMENT (element_2), FALSE);
1198 va_start (args, element_2);
1201 if (!gst_element_link (element_1, element_2))
1204 element_1 = element_2;
1205 element_2 = va_arg (args, GstElement *);
1214 * gst_element_unlink_pads:
1215 * @src: a #GstElement containing the source pad.
1216 * @srcpadname: the name of the #GstPad in source element.
1217 * @dest: a #GstElement containing the destination pad.
1218 * @destpadname: the name of the #GstPad in destination element.
1220 * Unlinks the two named pads of the source and destination elements.
1223 gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
1224 GstElement * dest, const gchar * destpadname)
1226 GstPad *srcpad, *destpad;
1228 g_return_if_fail (src != NULL);
1229 g_return_if_fail (GST_IS_ELEMENT (src));
1230 g_return_if_fail (srcpadname != NULL);
1231 g_return_if_fail (dest != NULL);
1232 g_return_if_fail (GST_IS_ELEMENT (dest));
1233 g_return_if_fail (destpadname != NULL);
1235 /* obtain the pads requested */
1236 srcpad = gst_element_get_pad (src, srcpadname);
1237 if (srcpad == NULL) {
1238 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1241 destpad = gst_element_get_pad (dest, destpadname);
1242 if (srcpad == NULL) {
1243 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
1248 /* we're satisified they can be unlinked, let's do it */
1249 gst_pad_unlink (srcpad, destpad);
1253 * gst_element_unlink_many:
1254 * @element_1: the first #GstElement in the link chain.
1255 * @element_2: the second #GstElement in the link chain.
1256 * @...: the NULL-terminated list of elements to unlink in order.
1258 * Unlinks a series of elements. Uses gst_element_unlink().
1261 gst_element_unlink_many (GstElement * element_1, GstElement * element_2, ...)
1265 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1266 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1268 va_start (args, element_2);
1271 gst_element_unlink (element_1, element_2);
1273 element_1 = element_2;
1274 element_2 = va_arg (args, GstElement *);
1281 * gst_element_unlink:
1282 * @src: the source #GstElement to unlink.
1283 * @dest: the sink #GstElement to unlink.
1285 * Unlinks all source pads of the source element with all sink pads
1286 * of the sink element to which they are linked.
1289 gst_element_unlink (GstElement * src, GstElement * dest)
1292 gboolean done = FALSE;
1294 g_return_if_fail (GST_IS_ELEMENT (src));
1295 g_return_if_fail (GST_IS_ELEMENT (dest));
1297 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1298 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1300 pads = gst_element_iterate_pads (src);
1304 switch (gst_iterator_next (pads, &data)) {
1305 case GST_ITERATOR_OK:
1307 GstPad *pad = GST_PAD_CAST (data);
1309 if (GST_PAD_IS_SRC (pad)) {
1310 GstPad *peerpad = gst_pad_get_peer (pad);
1312 /* see if the pad is connected and is really a pad
1315 GstElement *peerelem = gst_pad_get_parent (peerpad);
1317 if (peerelem == dest) {
1318 gst_pad_unlink (pad, peerpad);
1321 gst_object_unref (GST_OBJECT (peerelem));
1323 gst_object_unref (GST_OBJECT (peerpad));
1326 gst_object_unref (GST_OBJECT (pad));
1329 case GST_ITERATOR_RESYNC:
1330 gst_iterator_resync (pads);
1332 case GST_ITERATOR_DONE:
1336 g_assert_not_reached ();
1343 gst_element_query_position (GstElement * element, GstFormat * format,
1344 gint64 * cur, gint64 * end)
1349 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1350 g_return_val_if_fail (format != NULL, FALSE);
1352 query = gst_query_new_position (*format);
1353 ret = gst_element_query (element, query);
1356 gst_query_parse_position (query, format, cur, end);
1358 gst_query_unref (query);
1364 gst_element_query_convert (GstElement * element, GstFormat src_format,
1365 gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
1370 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1371 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1372 g_return_val_if_fail (dest_val != NULL, FALSE);
1374 if (*dest_fmt == src_format) {
1375 *dest_val = src_val;
1379 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1380 ret = gst_element_query (element, query);
1383 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1385 gst_query_unref (query);
1393 * @srcpad: the source #GstPad to link.
1394 * @sinkpad: the sink #GstPad to link.
1396 * Checks if the source pad and the sink pad can be linked.
1397 * Both @srcpad and @sinkpad must be unlinked.
1399 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1402 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1404 /* FIXME This function is gross. It's almost a direct copy of
1405 * gst_pad_link_filtered(). Any decent programmer would attempt
1406 * to merge the two functions, which I will do some day. --ds
1409 /* generic checks */
1410 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1411 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1413 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1414 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1416 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1417 if (GST_PAD_PEER (srcpad) != NULL) {
1418 GST_CAT_INFO (GST_CAT_PADS, "Source pad %s:%s has a peer, failed",
1419 GST_DEBUG_PAD_NAME (srcpad));
1422 if (GST_PAD_PEER (sinkpad) != NULL) {
1423 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has a peer, failed",
1424 GST_DEBUG_PAD_NAME (sinkpad));
1427 if (!GST_PAD_IS_SRC (srcpad)) {
1428 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s is not source pad, failed",
1429 GST_DEBUG_PAD_NAME (srcpad));
1432 if (!GST_PAD_IS_SINK (sinkpad)) {
1433 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s is not sink pad, failed",
1434 GST_DEBUG_PAD_NAME (sinkpad));
1437 if (GST_PAD_PARENT (srcpad) == NULL) {
1438 GST_CAT_INFO (GST_CAT_PADS, "Src pad %s:%s has no parent, failed",
1439 GST_DEBUG_PAD_NAME (srcpad));
1442 if (GST_PAD_PARENT (sinkpad) == NULL) {
1443 GST_CAT_INFO (GST_CAT_PADS, "Sink pad %s:%s has no parent, failed",
1444 GST_DEBUG_PAD_NAME (srcpad));
1452 * gst_pad_use_fixed_caps:
1453 * @pad: the pad to use
1455 * A helper function you can use that sets the
1456 * @gst_pad_get_fixed_caps_func as the gstcaps function for the
1457 * pad. This way the function will always return the negotiated caps
1458 * or in case the pad is not negotiated, the padtemplate caps.
1461 gst_pad_use_fixed_caps (GstPad * pad)
1463 gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
1467 * gst_pad_get_fixed_caps_func:
1468 * @pad: the pad to use
1470 * A helper function you can use as a GetCaps function that
1471 * will return the currently negotiated caps or the padtemplate
1474 * Returns: The currently negotiated caps or the padtemplate.
1477 gst_pad_get_fixed_caps_func (GstPad * pad)
1481 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1483 if (GST_PAD_CAPS (pad)) {
1484 result = GST_PAD_CAPS (pad);
1486 GST_CAT_DEBUG (GST_CAT_CAPS,
1487 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1489 result = gst_caps_ref (result);
1492 if (GST_PAD_PAD_TEMPLATE (pad)) {
1493 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1495 result = GST_PAD_TEMPLATE_CAPS (templ);
1496 GST_CAT_DEBUG (GST_CAT_CAPS,
1497 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1500 result = gst_caps_ref (result);
1503 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1504 result = gst_caps_new_empty ();
1511 * gst_object_default_error:
1512 * @object: a #GObject that signalled the error.
1513 * @orig: the #GstObject that initiated the error.
1514 * @error: the GError.
1515 * @debug: an additional debug information string, or NULL.
1517 * A default error function.
1519 * The default handler will simply print the error string using g_print.
1522 gst_object_default_error (GstObject * source, GError * error, gchar * debug)
1524 gchar *name = gst_object_get_path_string (source);
1526 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
1528 g_print (_("Additional debug info:\n%s\n"), debug);
1535 * @bin: the bin to add the elements to
1536 * @element_1: the first element to add to the bin
1537 * @...: additional elements to add to the bin
1539 * Adds a NULL-terminated list of elements to a bin. This function is
1540 * equivalent to calling #gst_bin_add() for each member of the list.
1543 gst_bin_add_many (GstBin * bin, GstElement * element_1, ...)
1547 g_return_if_fail (GST_IS_BIN (bin));
1548 g_return_if_fail (GST_IS_ELEMENT (element_1));
1550 va_start (args, element_1);
1553 gst_bin_add (bin, element_1);
1555 element_1 = va_arg (args, GstElement *);
1562 * gst_bin_remove_many:
1563 * @bin: the bin to remove the elements from
1564 * @element_1: the first element to remove from the bin
1565 * @...: NULL-terminated list of elements to remove from the bin
1567 * Remove a list of elements from a bin. This function is equivalent
1568 * to calling #gst_bin_remove with each member of the list.
1571 gst_bin_remove_many (GstBin * bin, GstElement * element_1, ...)
1575 g_return_if_fail (GST_IS_BIN (bin));
1576 g_return_if_fail (GST_IS_ELEMENT (element_1));
1578 va_start (args, element_1);
1581 gst_bin_remove (bin, element_1);
1583 element_1 = va_arg (args, GstElement *);
1590 gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
1591 guint arg_id, GParamFlags flags)
1593 GQuark prop_id = g_quark_from_string (prop_name);
1596 static GQuark fd_id = 0;
1597 static GQuark blocksize_id;
1598 static GQuark bytesperread_id;
1599 static GQuark dump_id;
1600 static GQuark filesize_id;
1601 static GQuark mmapsize_id;
1602 static GQuark location_id;
1603 static GQuark offset_id;
1604 static GQuark silent_id;
1605 static GQuark touch_id;
1608 fd_id = g_quark_from_static_string ("fd");
1609 blocksize_id = g_quark_from_static_string ("blocksize");
1610 bytesperread_id = g_quark_from_static_string ("bytesperread");
1611 dump_id = g_quark_from_static_string ("dump");
1612 filesize_id = g_quark_from_static_string ("filesize");
1613 mmapsize_id = g_quark_from_static_string ("mmapsize");
1614 location_id = g_quark_from_static_string ("location");
1615 offset_id = g_quark_from_static_string ("offset");
1616 silent_id = g_quark_from_static_string ("silent");
1617 touch_id = g_quark_from_static_string ("touch");
1620 if (prop_id == fd_id) {
1621 pspec = g_param_spec_int ("fd", "File-descriptor",
1622 "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
1623 } else if (prop_id == blocksize_id) {
1624 pspec = g_param_spec_ulong ("blocksize", "Block Size",
1625 "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
1627 } else if (prop_id == bytesperread_id) {
1628 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
1629 "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
1631 } else if (prop_id == dump_id) {
1632 pspec = g_param_spec_boolean ("dump", "Dump",
1633 "Dump bytes to stdout", FALSE, flags);
1635 } else if (prop_id == filesize_id) {
1636 pspec = g_param_spec_int64 ("filesize", "File Size",
1637 "Size of the file being read", 0, G_MAXINT64, 0, flags);
1639 } else if (prop_id == mmapsize_id) {
1640 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
1641 "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
1643 } else if (prop_id == location_id) {
1644 pspec = g_param_spec_string ("location", "File Location",
1645 "Location of the file to read", NULL, flags);
1647 } else if (prop_id == offset_id) {
1648 pspec = g_param_spec_int64 ("offset", "File Offset",
1649 "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
1651 } else if (prop_id == silent_id) {
1652 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
1655 } else if (prop_id == touch_id) {
1656 pspec = g_param_spec_boolean ("touch", "Touch read data",
1657 "Touch data to force disk read before " "push ()", TRUE, flags);
1659 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
1660 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
1665 g_object_class_install_property (klass, arg_id, pspec);
1670 * gst_element_class_install_std_props:
1671 * @klass: the #GstElementClass to add the properties to.
1672 * @first_name: the name of the first property.
1673 * in a NULL terminated
1674 * @...: the id and flags of the first property, followed by
1675 * further 'name', 'id', 'flags' triplets and terminated by NULL.
1677 * Adds a list of standardized properties with types to the @klass.
1678 * the id is for the property switch in your get_prop method, and
1679 * the flags determine readability / writeability.
1682 gst_element_class_install_std_props (GstElementClass * klass,
1683 const gchar * first_name, ...)
1689 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1691 va_start (args, first_name);
1696 int arg_id = va_arg (args, int);
1697 int flags = va_arg (args, int);
1699 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
1702 name = va_arg (args, char *);
1711 * @buf1: a first source #GstBuffer to merge.
1712 * @buf2: the second source #GstBuffer to merge.
1714 * Create a new buffer that is the concatenation of the two source
1715 * buffers. The original source buffers will not be modified or
1716 * unref'd. Make sure you unref the source buffers if they are not used
1717 * anymore afterwards.
1719 * If the buffers point to contiguous areas of memory, the buffer
1720 * is created without copying the data.
1722 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
1725 gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
1729 /* we're just a specific case of the more general gst_buffer_span() */
1730 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
1737 * @buf1: a first source #GstBuffer to merge.
1738 * @buf2: the second source #GstBuffer to merge.
1740 * Create a new buffer that is the concatenation of the two source
1741 * buffers, and takes ownership of the original source buffers.
1743 * If the buffers point to contiguous areas of memory, the buffer
1744 * is created without copying the data.
1746 * Returns: the new #GstBuffer that's the concatenation of the source buffers.
1749 gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
1753 result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
1754 gst_buffer_unref (buf1);
1755 gst_buffer_unref (buf2);
1763 * @dest: buffer to stamp
1764 * @src: buffer to stamp from
1766 * Copies additional information (timestamps and offsets) from one buffer to
1770 gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
1772 g_return_if_fail (dest != NULL);
1773 g_return_if_fail (src != NULL);
1775 GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
1776 GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
1777 GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
1778 GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
1782 intersect_caps_func (GstPad * pad, GValue * ret, GstPad * orig)
1785 GstCaps *peercaps, *existing;
1787 existing = g_value_get_pointer (ret);
1788 peercaps = gst_pad_peer_get_caps (pad);
1789 if (peercaps == NULL)
1790 peercaps = gst_caps_new_any ();
1791 g_value_set_pointer (ret, gst_caps_intersect (existing, peercaps));
1792 gst_caps_unref (existing);
1793 gst_caps_unref (peercaps);
1799 * gst_pad_proxy_getcaps:
1800 * @pad: a #GstPad to proxy.
1802 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
1803 * same element as @pad, and returns the intersection of the results.
1805 * This function is useful as a default getcaps function for an element
1806 * that can handle any stream format, but requires all its pads to have
1807 * the same caps. Two such elements are tee and aggregator.
1809 * Returns: the intersection of the other pads' allowed caps.
1812 gst_pad_proxy_getcaps (GstPad * pad)
1814 GstElement *element;
1815 GstCaps *caps, *intersected;
1817 GstIteratorResult res;
1818 GValue ret = { 0, };
1820 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1822 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
1824 element = gst_pad_get_parent (pad);
1825 if (element == NULL)
1828 iter = gst_element_iterate_pads (element);
1830 g_value_init (&ret, G_TYPE_POINTER);
1831 g_value_set_pointer (&ret, gst_caps_new_any ());
1833 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) intersect_caps_func,
1835 gst_iterator_free (iter);
1837 if (res != GST_ITERATOR_DONE) {
1838 g_warning ("Pad list changed during capsnego for element %s",
1839 GST_ELEMENT_NAME (element));
1843 caps = g_value_get_pointer (&ret);
1844 g_value_unset (&ret);
1846 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
1847 gst_caps_unref (caps);
1859 link_fold_func (GstPad * pad, GValue * ret, LinkData * data)
1861 gboolean success = TRUE;
1863 if (pad != data->orig) {
1864 success = gst_pad_set_caps (pad, data->caps);
1865 g_value_set_boolean (ret, success);
1872 * gst_pad_proxy_setcaps
1873 * @pad: a #GstPad to proxy from
1874 * @caps: the #GstCaps to link with
1876 * Calls gst_pad_set_caps() for every other pad belonging to the
1877 * same element as @pad. If gst_pad_set_caps() fails on any pad,
1878 * the proxy setcaps fails. May be used only during negotiation.
1880 * Returns: TRUE if sucessful
1883 gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
1885 GstElement *element;
1887 GstIteratorResult res;
1888 GValue ret = { 0, };
1891 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1892 g_return_val_if_fail (caps != NULL, FALSE);
1894 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
1896 element = gst_pad_get_parent (pad);
1898 iter = gst_element_iterate_pads (element);
1900 g_value_init (&ret, G_TYPE_BOOLEAN);
1901 g_value_set_boolean (&ret, TRUE);
1905 res = gst_iterator_fold (iter, (GstIteratorFoldFunction) link_fold_func,
1907 gst_iterator_free (iter);
1909 if (res != GST_ITERATOR_DONE) {
1910 g_warning ("Pad list changed during proxy_pad_link for element %s",
1911 GST_ELEMENT_NAME (element));
1915 /* ok not to unset the gvalue */
1916 return g_value_get_boolean (&ret);
1920 * gst_pad_query_position:
1921 * @pad: a #GstPad to invoke the position query on.
1922 * @format: a pointer to the #GstFormat asked for.
1923 * On return contains the #GstFormat used.
1924 * @cur: A location in which to store the current position, or NULL.
1925 * @end: A location in which to store the end position (length), or NULL.
1927 * Queries a pad for the stream position and length.
1929 * Returns: TRUE if the query could be performed.
1932 gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur,
1938 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1939 g_return_val_if_fail (format != NULL, FALSE);
1941 query = gst_query_new_position (*format);
1942 ret = gst_pad_query (pad, query);
1945 gst_query_parse_position (query, format, cur, end);
1947 gst_query_unref (query);
1953 * gst_pad_query_convert:
1954 * @pad: a #GstPad to invoke the convert query on.
1955 * @src_format: a #GstFormat to convert from.
1956 * @src_val: a value to convert.
1957 * @dest_format: a pointer to the #GstFormat to convert to.
1958 * @dest_val: a pointer to the result.
1960 * Queries a pad to convert @src_val in @src_format to @dest_format.
1962 * Returns: TRUE if the query could be performed.
1965 gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
1966 GstFormat * dest_fmt, gint64 * dest_val)
1971 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1972 g_return_val_if_fail (dest_fmt != NULL, FALSE);
1973 g_return_val_if_fail (dest_val != NULL, FALSE);
1975 if (*dest_fmt == src_format) {
1976 *dest_val = src_val;
1980 query = gst_query_new_convert (src_format, src_val, *dest_fmt);
1981 ret = gst_pad_query (pad, query);
1984 gst_query_parse_convert (query, NULL, NULL, dest_fmt, dest_val);
1986 gst_query_unref (query);
1992 * gst_atomic_int_set:
1993 * @atomic_int: pointer to an atomic integer
1994 * @value: value to set
1996 * Unconditionally sets the atomic integer to @value.
1999 gst_atomic_int_set (gint * atomic_int, gint value)
2003 *atomic_int = value;
2004 ignore = g_atomic_int_get (atomic_int);