3 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
4 * 2004 Wim Taymans <wim@fluendo.com>
6 * gstbin.c: GstBin container object and support code
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 * @short_description: Base class for elements that contain other elements
29 * GstBin is the simplest of the container elements, allowing elements to
30 * become children of itself. Pads from the child elements can be ghosted to
31 * the bin, making the bin itself look transparently like any other element,
32 * allowing for deep nesting of predefined sub-pipelines.
34 * A new GstBin is created with gst_bin_new(). Use a #GstPipeline instead if you
35 * want to create a toplevel bin because a normal bin doesn't have a bus or
36 * handle clock distribution of its own.
38 * After the bin has been created you will typically add elements to it with
39 * gst_bin_add(). You can remove elements with gst_bin_remove().
41 * An element can be retrieved from a bin with gst_bin_get_by_name(), using the
42 * elements name. gst_bin_get_by_name_recurse_up() is mainly used for internal
43 * purposes and will query the parent bins when the element is not found in the
46 * An iterator of elements in a bin can be retrieved with
47 * gst_bin_iterate_elements(). Various other iterators exist to retrieve the
50 * The "element_added" signal is fired whenever a new element is added to the
51 * bin. Likewise the "element_removed" signal is fired whenever an element is
52 * removed from the bin.
54 * gst_bin_unref() is used to destroy the bin.
57 #include "gst_private.h"
61 #include "gstmarshal.h"
67 #include "gstindexfactory.h"
69 #include "gstchildproxy.h"
71 GST_DEBUG_CATEGORY_STATIC (bin_debug);
72 #define GST_CAT_DEFAULT bin_debug
73 #define GST_LOG_BIN_CONTENTS(bin, text) GST_LOG_OBJECT ((bin), \
74 text ": %d elements: %u PLAYING, %u PAUSED, %u READY, %u NULL, own state: %s", \
75 (bin)->numchildren, (guint) (bin)->child_states[3], \
76 (guint) (bin)->child_states[2], (bin)->child_states[1], \
77 (bin)->child_states[0], gst_element_state_get_name (GST_STATE (bin)))
80 static GstElementDetails gst_bin_details = GST_ELEMENT_DETAILS ("Generic bin",
82 "Simple container object",
83 "Erik Walthinsen <omega@cse.ogi.edu>," "Wim Taymans <wim@fluendo.com>");
85 GType _gst_bin_type = 0;
87 static void gst_bin_dispose (GObject * object);
89 static GstStateChangeReturn gst_bin_change_state (GstElement * element,
90 GstStateChange transition);
91 static GstStateChangeReturn gst_bin_get_state (GstElement * element,
92 GstState * state, GstState * pending, GTimeVal * timeout);
94 static gboolean gst_bin_add_func (GstBin * bin, GstElement * element);
95 static gboolean gst_bin_remove_func (GstBin * bin, GstElement * element);
97 #ifndef GST_DISABLE_INDEX
98 static void gst_bin_set_index_func (GstElement * element, GstIndex * index);
100 static GstClock *gst_bin_provide_clock_func (GstElement * element);
101 static void gst_bin_set_clock_func (GstElement * element, GstClock * clock);
103 static gboolean gst_bin_send_event (GstElement * element, GstEvent * event);
104 static GstBusSyncReply bin_bus_handler (GstBus * bus,
105 GstMessage * message, GstBin * bin);
106 static gboolean gst_bin_query (GstElement * element, GstQuery * query);
108 #ifndef GST_DISABLE_LOADSAVE
109 static xmlNodePtr gst_bin_save_thyself (GstObject * object, xmlNodePtr parent);
110 static void gst_bin_restore_thyself (GstObject * object, xmlNodePtr self);
113 static gint bin_element_is_sink (GstElement * child, GstBin * bin);
115 /* Bin signals and args */
129 static void gst_bin_base_init (gpointer g_class);
130 static void gst_bin_class_init (GstBinClass * klass);
131 static void gst_bin_init (GstBin * bin);
132 static void gst_bin_child_proxy_init (gpointer g_iface, gpointer iface_data);
134 static GstElementClass *parent_class = NULL;
135 static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
140 * Returns: the type of #GstBin
143 gst_bin_get_type (void)
145 if (!_gst_bin_type) {
146 static const GTypeInfo bin_info = {
147 sizeof (GstBinClass),
150 (GClassInitFunc) gst_bin_class_init,
155 (GInstanceInitFunc) gst_bin_init,
158 static const GInterfaceInfo child_proxy_info = {
159 gst_bin_child_proxy_init,
165 g_type_register_static (GST_TYPE_ELEMENT, "GstBin", &bin_info, 0);
167 g_type_add_interface_static (_gst_bin_type, GST_TYPE_CHILD_PROXY,
170 GST_DEBUG_CATEGORY_INIT (bin_debug, "bin", GST_DEBUG_BOLD,
171 "debugging info for the 'bin' container element");
173 return _gst_bin_type;
177 gst_bin_base_init (gpointer g_class)
179 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
181 gst_element_class_set_details (gstelement_class, &gst_bin_details);
185 gst_bin_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
188 return g_list_nth_data (GST_BIN (child_proxy)->children, index);
192 gst_bin_child_proxy_get_children_count (GstChildProxy * child_proxy)
194 return GST_BIN (child_proxy)->numchildren;
198 gst_bin_child_proxy_init (gpointer g_iface, gpointer iface_data)
200 GstChildProxyInterface *iface = g_iface;
202 iface->get_children_count = gst_bin_child_proxy_get_children_count;
203 iface->get_child_by_index = gst_bin_child_proxy_get_child_by_index;
207 gst_bin_class_init (GstBinClass * klass)
209 GObjectClass *gobject_class;
210 GstObjectClass *gstobject_class;
211 GstElementClass *gstelement_class;
213 gobject_class = (GObjectClass *) klass;
214 gstobject_class = (GstObjectClass *) klass;
215 gstelement_class = (GstElementClass *) klass;
217 parent_class = g_type_class_peek_parent (klass);
220 * GstBin::element-added:
221 * @bin: the object which emitted the signal.
222 * @element: the element that was added to the bin
224 * Will be emitted if a new element was removed/added to this bin.
226 gst_bin_signals[ELEMENT_ADDED] =
227 g_signal_new ("element-added", G_TYPE_FROM_CLASS (klass),
228 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstBinClass, element_added), NULL,
229 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
231 * GstBin::element-removed:
232 * @bin: the object which emitted the signal.
233 * @element: the element that was removed from the bin
235 * Will be emitted if an element was removed from this bin.
237 gst_bin_signals[ELEMENT_REMOVED] =
238 g_signal_new ("element-removed", G_TYPE_FROM_CLASS (klass),
239 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstBinClass, element_removed), NULL,
240 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
242 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_bin_dispose);
244 #ifndef GST_DISABLE_LOADSAVE
245 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_bin_save_thyself);
246 gstobject_class->restore_thyself =
247 GST_DEBUG_FUNCPTR (gst_bin_restore_thyself);
250 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_bin_change_state);
251 gstelement_class->get_state = GST_DEBUG_FUNCPTR (gst_bin_get_state);
252 #ifndef GST_DISABLE_INDEX
253 gstelement_class->set_index = GST_DEBUG_FUNCPTR (gst_bin_set_index_func);
255 gstelement_class->provide_clock =
256 GST_DEBUG_FUNCPTR (gst_bin_provide_clock_func);
257 gstelement_class->set_clock = GST_DEBUG_FUNCPTR (gst_bin_set_clock_func);
259 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_bin_send_event);
260 gstelement_class->query = GST_DEBUG_FUNCPTR (gst_bin_query);
262 klass->add_element = GST_DEBUG_FUNCPTR (gst_bin_add_func);
263 klass->remove_element = GST_DEBUG_FUNCPTR (gst_bin_remove_func);
267 gst_bin_init (GstBin * bin)
271 bin->numchildren = 0;
272 bin->children = NULL;
273 bin->children_cookie = 0;
276 /* Set up a bus for listening to child elements */
277 bus = g_object_new (gst_bus_get_type (), NULL);
278 bin->child_bus = bus;
279 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin);
284 * @name: name of new bin
286 * Create a new bin with given name.
291 gst_bin_new (const gchar * name)
293 return gst_element_factory_make ("bin", name);
296 /* set the index on all elements in this bin
300 #ifndef GST_DISABLE_INDEX
302 gst_bin_set_index_func (GstElement * element, GstIndex * index)
307 bin = GST_BIN (element);
310 for (children = bin->children; children; children = g_list_next (children)) {
311 GstElement *child = GST_ELEMENT (children->data);
313 gst_element_set_index (child, index);
319 /* set the clock on all elements in this bin
324 gst_bin_set_clock_func (GstElement * element, GstClock * clock)
329 bin = GST_BIN (element);
332 for (children = bin->children; children; children = g_list_next (children)) {
333 GstElement *child = GST_ELEMENT (children->data);
335 gst_element_set_clock (child, clock);
340 /* get the clock for this bin by asking all of the children in this bin
342 * The ref of the returned clock in increased so unref after usage.
346 * FIXME, clock selection is not correct here.
349 gst_bin_provide_clock_func (GstElement * element)
351 GstClock *result = NULL;
355 bin = GST_BIN (element);
358 for (children = bin->children; children; children = g_list_next (children)) {
359 GstElement *child = GST_ELEMENT (children->data);
361 result = gst_element_provide_clock (child);
371 is_eos (GstBin * bin)
374 gboolean result = TRUE;
375 gboolean done = FALSE;
377 sinks = gst_bin_iterate_sinks (bin);
381 switch (gst_iterator_next (sinks, &data)) {
382 case GST_ITERATOR_OK:
384 GstElement *element = GST_ELEMENT (data);
388 name = gst_element_get_name (element);
389 eosed = g_list_find (bin->eosed, element);
391 GST_DEBUG ("element %s did not post EOS yet", name);
395 GST_DEBUG ("element %s posted EOS", name);
398 gst_object_unref (element);
401 case GST_ITERATOR_RESYNC:
403 gst_iterator_resync (sinks);
405 case GST_ITERATOR_DONE:
409 g_assert_not_reached ();
413 gst_iterator_free (sinks);
418 unlink_pads (GstPad * pad)
422 if ((peer = gst_pad_get_peer (pad))) {
423 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
424 gst_pad_unlink (pad, peer);
426 gst_pad_unlink (peer, pad);
427 gst_object_unref (peer);
429 gst_object_unref (pad);
432 /* add an element to this bin
437 gst_bin_add_func (GstBin * bin, GstElement * element)
442 /* we obviously can't add ourself to ourself */
443 if (G_UNLIKELY (GST_ELEMENT_CAST (element) == GST_ELEMENT_CAST (bin)))
446 /* get the element name to make sure it is unique in this bin. */
448 elem_name = g_strdup (GST_ELEMENT_NAME (element));
449 GST_UNLOCK (element);
453 /* then check to see if the element's name is already taken in the bin,
454 * we can safely take the lock here. This check is probably bogus because
455 * you can safely change the element name after this check and before setting
456 * the object parent. The window is very small though... */
457 if (G_UNLIKELY (!gst_object_check_uniqueness (bin->children, elem_name)))
460 /* set the element's parent and add the element to the bin's list of children */
461 if (G_UNLIKELY (!gst_object_set_parent (GST_OBJECT_CAST (element),
462 GST_OBJECT_CAST (bin))))
465 /* if we add a sink we become a sink */
466 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
467 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "element \"%s\" was sink",
469 GST_FLAG_SET (bin, GST_ELEMENT_IS_SINK);
472 bin->children = g_list_prepend (bin->children, element);
474 bin->children_cookie++;
476 /* distribute the bus */
477 gst_element_set_bus (element, bin->child_bus);
479 /* propagate the current base time and clock */
480 gst_element_set_base_time (element, GST_ELEMENT (bin)->base_time);
481 gst_element_set_clock (element, GST_ELEMENT_CLOCK (bin));
485 /* unlink all linked pads */
486 it = gst_element_iterate_pads (element);
487 gst_iterator_foreach (it, (GFunc) unlink_pads, element);
488 gst_iterator_free (it);
490 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
494 g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_ADDED], 0, element);
498 /* ERROR handling here */
502 g_warning ("Cannot add bin %s to itself", GST_ELEMENT_NAME (bin));
508 g_warning ("Name %s is not unique in bin %s, not adding",
509 elem_name, GST_ELEMENT_NAME (bin));
516 g_warning ("Element %s already has parent", elem_name);
526 * @bin: #GstBin to add element to
527 * @element: #GstElement to add to bin
529 * Adds the given element to the bin. Sets the element's parent, and thus
530 * takes ownership of the element. An element can only be added to one bin.
532 * If the element's pads are linked to other pads, the pads will be unlinked
533 * before the element is added to the bin.
537 * Returns: TRUE if the element could be added, FALSE on wrong parameters or
538 * the bin does not want to accept the element.
541 gst_bin_add (GstBin * bin, GstElement * element)
546 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
547 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
549 bclass = GST_BIN_GET_CLASS (bin);
551 if (G_UNLIKELY (bclass->add_element == NULL))
554 GST_CAT_DEBUG (GST_CAT_PARENTAGE, "adding element %s to bin %s",
555 GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (bin));
557 result = bclass->add_element (bin, element);
564 g_warning ("adding elements to bin %s is not supported",
565 GST_ELEMENT_NAME (bin));
570 /* remove an element from the bin
575 gst_bin_remove_func (GstBin * bin, GstElement * element)
581 /* Check if the element is already being removed and immediately
583 if (G_UNLIKELY (GST_FLAG_IS_SET (element, GST_ELEMENT_UNPARENTING)))
584 goto already_removing;
586 GST_FLAG_SET (element, GST_ELEMENT_UNPARENTING);
587 /* grab element name so we can print it */
588 elem_name = g_strdup (GST_ELEMENT_NAME (element));
589 GST_UNLOCK (element);
591 /* unlink all linked pads */
592 it = gst_element_iterate_pads (element);
593 gst_iterator_foreach (it, (GFunc) unlink_pads, element);
594 gst_iterator_free (it);
597 /* the element must be in the bin's list of children */
598 if (G_UNLIKELY (g_list_find (bin->children, element) == NULL))
601 /* now remove the element from the list of elements */
602 bin->children = g_list_remove (bin->children, element);
604 bin->children_cookie++;
606 /* check if we removed a sink */
607 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
610 /* check if we removed the last sink */
611 other_sink = g_list_find_custom (bin->children,
612 bin, (GCompareFunc) bin_element_is_sink);
614 /* yups, we're not a sink anymore */
615 GST_FLAG_UNSET (bin, GST_ELEMENT_IS_SINK);
620 GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin, "removed child \"%s\"",
624 gst_element_set_bus (element, NULL);
626 /* unlock any waiters for the state change. It is possible that
627 * we are waiting for an ASYNC state change on this element. The
628 * element cannot be added to another bin yet as it is not yet
630 GST_STATE_LOCK (element);
631 GST_STATE_BROADCAST (element);
632 GST_STATE_UNLOCK (element);
634 /* we ref here because after the _unparent() the element can be disposed
635 * and we still need it to reset the UNPARENTING flag and fire a signal. */
636 gst_object_ref (element);
637 gst_object_unparent (GST_OBJECT_CAST (element));
640 GST_FLAG_UNSET (element, GST_ELEMENT_UNPARENTING);
641 GST_UNLOCK (element);
643 g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_REMOVED], 0, element);
645 /* element is really out of our control now */
646 gst_object_unref (element);
653 g_warning ("Element %s is not in bin %s", elem_name,
654 GST_ELEMENT_NAME (bin));
661 GST_UNLOCK (element);
668 * @bin: #GstBin to remove element from
669 * @element: #GstElement to remove
671 * Remove the element from its associated bin, unparenting it as well.
672 * Unparenting the element means that the element will be dereferenced,
673 * so if the bin holds the only reference to the element, the element
674 * will be freed in the process of removing it from the bin. If you
675 * want the element to still exist after removing, you need to call
676 * gst_object_ref() before removing it from the bin.
678 * If the element's pads are linked to other pads, the pads will be unlinked
679 * before the element is removed from the bin.
683 * Returns: TRUE if the element could be removed, FALSE on wrong parameters or
684 * the bin does not want to remove the element.
687 gst_bin_remove (GstBin * bin, GstElement * element)
692 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
693 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
695 bclass = GST_BIN_GET_CLASS (bin);
697 if (G_UNLIKELY (bclass->remove_element == NULL))
700 GST_CAT_DEBUG (GST_CAT_PARENTAGE, "removing element %s from bin %s",
701 GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (bin));
703 result = bclass->remove_element (bin, element);
710 g_warning ("removing elements from bin %s is not supported",
711 GST_ELEMENT_NAME (bin));
716 static GstIteratorItem
717 iterate_child (GstIterator * it, GstElement * child)
719 gst_object_ref (child);
720 return GST_ITERATOR_ITEM_PASS;
724 * gst_bin_iterate_elements:
725 * @bin: #Gstbin to iterate the elements of
727 * Get an iterator for the elements in this bin.
728 * Each element will have its refcount increased, so unref
733 * Returns: a #GstIterator of #GstElements. gst_iterator_free after
734 * use. returns NULL when passing bad parameters.
737 gst_bin_iterate_elements (GstBin * bin)
741 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
744 /* add ref because the iterator refs the bin. When the iterator
745 * is freed it will unref the bin again using the provided dispose
747 gst_object_ref (bin);
748 result = gst_iterator_new_list (GST_GET_LOCK (bin),
749 &bin->children_cookie,
752 (GstIteratorItemFunction) iterate_child,
753 (GstIteratorDisposeFunction) gst_object_unref);
759 static GstIteratorItem
760 iterate_child_recurse (GstIterator * it, GstElement * child)
762 gst_object_ref (child);
763 if (GST_IS_BIN (child)) {
764 GstIterator *other = gst_bin_iterate_recurse (GST_BIN (child));
766 gst_iterator_push (it, other);
768 return GST_ITERATOR_ITEM_PASS;
772 * gst_bin_iterate_recurse:
773 * @bin: #Gstbin to iterate the elements of
775 * Get an iterator for the elements in this bin.
776 * Each element will have its refcount increased, so unref
777 * after use. This iterator recurses into GstBin children.
781 * Returns: a #GstIterator of #GstElements. gst_iterator_free after
782 * use. returns NULL when passing bad parameters.
785 gst_bin_iterate_recurse (GstBin * bin)
789 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
792 /* add ref because the iterator refs the bin. When the iterator
793 * is freed it will unref the bin again using the provided dispose
795 gst_object_ref (bin);
796 result = gst_iterator_new_list (GST_GET_LOCK (bin),
797 &bin->children_cookie,
800 (GstIteratorItemFunction) iterate_child_recurse,
801 (GstIteratorDisposeFunction) gst_object_unref);
807 /* returns 0 when TRUE because this is a GCompareFunc */
810 bin_element_is_sink (GstElement * child, GstBin * bin)
814 /* we lock the child here for the remainder of the function to
815 * get its name safely. */
817 is_sink = GST_FLAG_IS_SET (child, GST_ELEMENT_IS_SINK);
819 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, bin,
820 "child %s %s sink", GST_OBJECT_NAME (child), is_sink ? "is" : "is not");
823 return is_sink ? 0 : 1;
827 sink_iterator_filter (GstElement * child, GstBin * bin)
829 if (bin_element_is_sink (child, bin) == 0) {
830 /* returns 0 because this is a GCompareFunc */
833 /* child carries a ref from gst_bin_iterate_elements -- drop if not passing
835 gst_object_unref ((GstObject *) child);
841 * gst_bin_iterate_sinks:
842 * @bin: #Gstbin to iterate on
844 * Get an iterator for the sink elements in this bin.
845 * Each element will have its refcount increased, so unref
848 * The sink elements are those without any linked srcpads.
852 * Returns: a #GstIterator of #GstElements. gst_iterator_free after use.
855 gst_bin_iterate_sinks (GstBin * bin)
857 GstIterator *children;
860 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
862 children = gst_bin_iterate_elements (bin);
863 result = gst_iterator_filter (children,
864 (GCompareFunc) sink_iterator_filter, bin);
870 * 1) check state of all children with 0 timeout to find ERROR and
871 * NO_PREROLL elements. return if found.
872 * 2) perform full blocking wait with requested timeout.
874 * 2) cannot be performed when 1) returns results as the sinks might
875 * not be able to complete the state change making 2) block forever.
879 static GstStateChangeReturn
880 gst_bin_get_state (GstElement * element, GstState * state,
881 GstState * pending, GTimeVal * timeout)
883 GstBin *bin = GST_BIN (element);
884 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
886 guint32 children_cookie;
887 gboolean have_no_preroll;
889 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "getting state");
891 /* lock bin, no element can be added or removed between going into
892 * the quick scan and the blocking wait. */
896 have_no_preroll = FALSE;
898 /* first we need to poll with a non zero timeout to make sure we don't block
899 * on the sinks when we have NO_PREROLL elements. This is why we do
900 * a quick check if there are still NO_PREROLL elements. We also
901 * catch the error elements this way. */
904 gboolean have_async = FALSE;
906 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "checking for NO_PREROLL");
907 /* use 0 timeout so we don't block on the sinks */
908 GST_TIME_TO_TIMEVAL (0, tv);
909 children = bin->children;
910 children_cookie = bin->children_cookie;
912 GstElement *child = GST_ELEMENT_CAST (children->data);
914 gst_object_ref (child);
915 /* now we release the lock to enter a non blocking wait. We
916 * release the lock anyway since we can. */
919 ret = gst_element_get_state (child, NULL, NULL, &tv);
921 gst_object_unref (child);
923 /* now grab the lock to iterate to the next child */
925 if (G_UNLIKELY (children_cookie != bin->children_cookie)) {
926 /* child added/removed during state change, restart. We need
927 * to restart with the quick check as a no-preroll element could
928 * have been added here and we don't want to block on sinks then.*/
933 /* report FAILURE immediatly */
934 case GST_STATE_CHANGE_FAILURE:
936 case GST_STATE_CHANGE_NO_PREROLL:
937 /* we have to continue scanning as there might be
939 have_no_preroll = TRUE;
941 case GST_STATE_CHANGE_ASYNC:
947 children = g_list_next (children);
949 /* if we get here, we have no FAILURES, check for any NO_PREROLL
951 if (have_no_preroll) {
952 ret = GST_STATE_CHANGE_NO_PREROLL;
956 /* if we get here, no NO_PREROLL elements are in the pipeline */
957 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "no NO_PREROLL elements");
959 /* if no ASYNC elements exist we don't even have to poll with a
962 ret = GST_STATE_CHANGE_SUCCESS;
967 /* next we poll all children for their state to see if one of them
968 * is still busy with its state change. We did not release the bin lock
969 * yet so the elements are the same as the ones from the quick scan. */
970 children = bin->children;
971 children_cookie = bin->children_cookie;
973 GstElement *child = GST_ELEMENT_CAST (children->data);
975 gst_object_ref (child);
976 /* now we release the lock to enter the potentialy blocking wait */
979 /* ret is ASYNC if some child is still performing the state change
980 * ater the timeout. */
981 ret = gst_element_get_state (child, NULL, NULL, timeout);
983 gst_object_unref (child);
985 /* now grab the lock to iterate to the next child */
987 if (G_UNLIKELY (children_cookie != bin->children_cookie)) {
988 /* child added/removed during state change, restart. We need
989 * to restart with the quick check as a no-preroll element could
990 * have been added here and we don't want to block on sinks then.*/
995 case GST_STATE_CHANGE_SUCCESS:
997 case GST_STATE_CHANGE_FAILURE:
998 case GST_STATE_CHANGE_NO_PREROLL:
999 /* report FAILURE and NO_PREROLL immediatly */
1001 case GST_STATE_CHANGE_ASYNC:
1004 g_assert_not_reached ();
1006 children = g_list_next (children);
1008 /* if we got here, all elements can do preroll */
1009 have_no_preroll = FALSE;
1014 /* now we can take the state lock, it is possible that new elements
1015 * are added now and we still report the old state. No problem though as
1016 * the return is still consistent, the effect is as if the element was
1017 * added after this function completed. */
1018 GST_STATE_LOCK (bin);
1020 case GST_STATE_CHANGE_SUCCESS:
1021 /* we can commit the state */
1022 gst_element_commit_state (element);
1024 case GST_STATE_CHANGE_FAILURE:
1025 /* some element failed, abort the state change */
1026 gst_element_abort_state (element);
1029 /* other cases are just passed along */
1033 /* and report the state if needed */
1035 *state = GST_STATE (element);
1037 *pending = GST_STATE_PENDING (element);
1039 GST_STATE_NO_PREROLL (element) = have_no_preroll;
1041 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1042 "state current: %s, pending: %s, error: %d, no_preroll: %d, result: %d",
1043 gst_element_state_get_name (GST_STATE (element)),
1044 gst_element_state_get_name (GST_STATE_PENDING (element)),
1045 GST_STATE_ERROR (element), GST_STATE_NO_PREROLL (element), ret);
1047 GST_STATE_UNLOCK (bin);
1052 /***********************************************
1053 * Topologically sorted iterator
1054 * see http://en.wikipedia.org/wiki/Topological_sorting
1056 * For each element in the graph, an entry is kept in a HashTable
1057 * with its number of srcpad connections (degree).
1058 * We then change state of all elements without dependencies
1059 * (degree 0) and decrement the degree of all elements connected
1060 * on the sinkpads. When an element reaches degree 0, its state is
1062 * When all elements are handled the algorithm stops.
1064 typedef struct _GstBinSortIterator
1067 GQueue *queue; /* elements queued for state change */
1068 GstBin *bin; /* bin we iterate */
1069 gint mode; /* adding or removing dependency */
1070 GstElement *best; /* next element with least dependencies */
1071 gint best_deg; /* best degree */
1072 GHashTable *hash; /* has table with element dependencies */
1073 } GstBinSortIterator;
1075 /* we add and subtract 1 to make sure we don't confuse NULL and 0 */
1076 #define HASH_SET_DEGREE(bit, elem, deg) \
1077 g_hash_table_replace (bit->hash, elem, GINT_TO_POINTER(deg+1))
1078 #define HASH_GET_DEGREE(bit, elem) \
1079 (GPOINTER_TO_INT(g_hash_table_lookup (bit->hash, elem))-1)
1081 /* add element to queue of next elements in the iterator.
1082 * We push at the tail to give higher priority elements a
1085 add_to_queue (GstBinSortIterator * bit, GstElement * element)
1087 GST_DEBUG ("%s add to queue", GST_ELEMENT_NAME (element));
1088 gst_object_ref (element);
1089 g_queue_push_tail (bit->queue, element);
1090 HASH_SET_DEGREE (bit, element, -1);
1093 /* clear the queue, unref all objects as we took a ref when
1094 * we added them to the queue */
1096 clear_queue (GQueue * queue)
1100 while ((p = g_queue_pop_head (queue)))
1101 gst_object_unref (p);
1104 /* set all degrees to 0. Elements marked as a sink are
1105 * added to the queue immediatly. */
1107 reset_degree (GstElement * element, GstBinSortIterator * bit)
1109 /* sinks are added right away */
1110 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
1111 add_to_queue (bit, element);
1113 /* others are marked with 0 and handled when sinks are done */
1114 HASH_SET_DEGREE (bit, element, 0);
1118 /* adjust the degree of all elements connected to the given
1119 * element. If an degree of an element drops to 0, it is
1120 * added to the queue of elements to schedule next.
1122 * We have to make sure not to cross the bin boundary this element
1126 update_degree (GstElement * element, GstBinSortIterator * bit)
1128 gboolean linked = FALSE;
1131 /* don't touch degree is element has no sourcepads */
1132 if (element->numsinkpads != 0) {
1133 /* loop over all sinkpads, decrement degree for all connected
1134 * elements in this bin */
1137 for (pads = element->sinkpads; pads; pads = g_list_next (pads)) {
1140 if ((peer = gst_pad_get_peer (GST_PAD_CAST (pads->data)))) {
1141 GstElement *peer_element;
1143 if ((peer_element = gst_pad_get_parent_element (peer))) {
1144 GST_LOCK (peer_element);
1145 if (GST_OBJECT_CAST (peer_element)->parent ==
1146 GST_OBJECT_CAST (bit->bin)) {
1147 gint old_deg, new_deg;
1149 old_deg = HASH_GET_DEGREE (bit, peer_element);
1150 new_deg = old_deg + bit->mode;
1152 GST_DEBUG ("change element %s, degree %d->%d, linked to %s",
1153 GST_ELEMENT_NAME (peer_element),
1154 old_deg, new_deg, GST_ELEMENT_NAME (element));
1158 /* degree hit 0, add to queue */
1159 add_to_queue (bit, peer_element);
1161 HASH_SET_DEGREE (bit, peer_element, new_deg);
1165 GST_UNLOCK (peer_element);
1166 gst_object_unref (peer_element);
1168 gst_object_unref (peer);
1173 GST_DEBUG ("element %s not linked to anything", GST_ELEMENT_NAME (element));
1175 GST_UNLOCK (element);
1178 /* find the next best element not handled yet. This is the one
1179 * with the lowest non-negative degree */
1181 find_element (GstElement * element, GstBinSortIterator * bit)
1185 /* element is already handled */
1186 if ((degree = HASH_GET_DEGREE (bit, element)) < 0)
1189 /* first element or element with smaller degree */
1190 if (bit->best == NULL || bit->best_deg > degree) {
1191 bit->best = element;
1192 bit->best_deg = degree;
1196 /* get next element in iterator. the returned element has the
1197 * refcount increased */
1198 static GstIteratorResult
1199 gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
1201 /* empty queue, we have to find a next best element */
1202 if (g_queue_is_empty (bit->queue)) {
1204 bit->best_deg = G_MAXINT;
1205 g_list_foreach (bit->bin->children, (GFunc) find_element, bit);
1207 if (bit->best_deg != 0) {
1208 /* we don't fail on this one yet */
1209 g_warning ("loop detected in the graph !!");
1211 /* best unhandled element, schedule as next element */
1212 GST_DEBUG ("queue empty, next best: %s", GST_ELEMENT_NAME (bit->best));
1213 gst_object_ref (bit->best);
1214 HASH_SET_DEGREE (bit, bit->best, -1);
1215 *result = bit->best;
1217 GST_DEBUG ("queue empty, elements exhausted");
1218 /* no more unhandled elements, we are done */
1219 return GST_ITERATOR_DONE;
1222 /* everything added to the queue got reffed */
1223 *result = g_queue_pop_head (bit->queue);
1226 GST_DEBUG ("queue head gives %s", GST_ELEMENT_NAME (*result));
1227 /* update degrees of linked elements */
1228 update_degree (GST_ELEMENT_CAST (*result), bit);
1230 return GST_ITERATOR_OK;
1233 /* clear queues, recalculate the degrees and restart. */
1235 gst_bin_sort_iterator_resync (GstBinSortIterator * bit)
1237 clear_queue (bit->queue);
1239 g_list_foreach (bit->bin->children, (GFunc) reset_degree, bit);
1240 /* calc degrees, incrementing */
1242 g_list_foreach (bit->bin->children, (GFunc) update_degree, bit);
1243 /* for the rest of the function we decrement the degrees */
1247 /* clear queues, unref bin and free iterator. */
1249 gst_bin_sort_iterator_free (GstBinSortIterator * bit)
1251 clear_queue (bit->queue);
1252 g_queue_free (bit->queue);
1253 g_hash_table_destroy (bit->hash);
1254 gst_object_unref (bit->bin);
1259 * gst_bin_iterate_sorted:
1260 * @bin: #Gstbin to iterate on
1262 * Get an iterator for the elements in this bin in topologically
1263 * sorted order. This means that the elements are returned from
1264 * the most downstream elements (sinks) to the sources.
1266 * This function is used internally to perform the state changes
1267 * of the bin elements.
1269 * Each element will have its refcount increased, so unref
1274 * Returns: a #GstIterator of #GstElements. gst_iterator_free after use.
1277 gst_bin_iterate_sorted (GstBin * bin)
1279 GstBinSortIterator *result;
1281 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1284 gst_object_ref (bin);
1285 /* we don't need a NextFunction because we ref the items in the _next
1287 result = (GstBinSortIterator *)
1288 gst_iterator_new (sizeof (GstBinSortIterator),
1290 &bin->children_cookie,
1291 (GstIteratorNextFunction) gst_bin_sort_iterator_next,
1292 (GstIteratorItemFunction) NULL,
1293 (GstIteratorResyncFunction) gst_bin_sort_iterator_resync,
1294 (GstIteratorFreeFunction) gst_bin_sort_iterator_free);
1295 result->queue = g_queue_new ();
1296 result->hash = g_hash_table_new (NULL, NULL);
1298 gst_bin_sort_iterator_resync (result);
1301 return (GstIterator *) result;
1304 static GstStateChangeReturn
1305 gst_bin_element_set_state (GstBin * bin, GstElement * element, GstState pending)
1307 GstStateChangeReturn ret;
1310 /* peel off the locked flag */
1312 locked = GST_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1313 GST_UNLOCK (element);
1315 /* skip locked elements */
1316 if (G_UNLIKELY (locked)) {
1317 ret = GST_STATE_CHANGE_SUCCESS;
1322 ret = gst_element_set_state (element, pending);
1328 static GstStateChangeReturn
1329 gst_bin_change_state (GstElement * element, GstStateChange transition)
1332 GstStateChangeReturn ret;
1333 GstState old_state, pending;
1334 gboolean have_async;
1335 gboolean have_no_preroll;
1336 GstClockTime base_time;
1340 /* we don't need to take the STATE_LOCK, it is already taken */
1341 old_state = GST_STATE (element);
1342 pending = GST_STATE_PENDING (element);
1344 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1345 "changing state of children from %s to %s",
1346 gst_element_state_get_name (old_state),
1347 gst_element_state_get_name (pending));
1349 if (pending == GST_STATE_VOID_PENDING)
1350 return GST_STATE_CHANGE_SUCCESS;
1352 bin = GST_BIN_CAST (element);
1354 /* Clear eosed element list on READY-> PAUSED */
1355 if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) {
1356 g_list_free (bin->eosed);
1360 /* iterate in state change order */
1361 it = gst_bin_iterate_sorted (bin);
1364 /* take base time */
1365 base_time = element->base_time;
1368 have_no_preroll = FALSE;
1374 switch (gst_iterator_next (it, &data)) {
1375 case GST_ITERATOR_OK:
1377 GstElement *element;
1379 element = GST_ELEMENT_CAST (data);
1381 /* set base time on element */
1382 gst_element_set_base_time (element, base_time);
1385 ret = gst_bin_element_set_state (bin, element, pending);
1388 case GST_STATE_CHANGE_SUCCESS:
1389 GST_CAT_DEBUG (GST_CAT_STATES,
1390 "child '%s' changed state to %d(%s) successfully",
1391 GST_ELEMENT_NAME (element), pending,
1392 gst_element_state_get_name (pending));
1394 case GST_STATE_CHANGE_ASYNC:
1395 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1396 "child '%s' is changing state asynchronously",
1397 GST_ELEMENT_NAME (element));
1400 case GST_STATE_CHANGE_FAILURE:
1401 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1402 "child '%s' failed to go to state %d(%s)",
1403 GST_ELEMENT_NAME (element),
1404 pending, gst_element_state_get_name (pending));
1405 gst_object_unref (element);
1407 case GST_STATE_CHANGE_NO_PREROLL:
1408 GST_CAT_DEBUG (GST_CAT_STATES,
1409 "child '%s' changed state to %d(%s) successfully without preroll",
1410 GST_ELEMENT_NAME (element), pending,
1411 gst_element_state_get_name (pending));
1412 have_no_preroll = TRUE;
1415 g_assert_not_reached ();
1418 gst_object_unref (element);
1421 case GST_ITERATOR_RESYNC:
1422 GST_CAT_DEBUG (GST_CAT_STATES, "iterator doing resync");
1423 gst_iterator_resync (it);
1427 case GST_ITERATOR_DONE:
1428 GST_CAT_DEBUG (GST_CAT_STATES, "iterator done");
1434 if (have_no_preroll) {
1435 ret = GST_STATE_CHANGE_NO_PREROLL;
1436 } else if (have_async) {
1437 ret = GST_STATE_CHANGE_ASYNC;
1439 ret = parent_class->change_state (element, transition);
1443 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1444 "done changing bin's state from %s to %s, now in %s, ret %d",
1445 gst_element_state_get_name (old_state),
1446 gst_element_state_get_name (pending),
1447 gst_element_state_get_name (GST_STATE (element)), ret);
1449 gst_iterator_free (it);
1455 gst_bin_dispose (GObject * object)
1457 GstBin *bin = GST_BIN (object);
1459 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object, "dispose");
1461 g_list_free (bin->eosed);
1463 gst_object_unref (bin->child_bus);
1464 bin->child_bus = NULL;
1466 while (bin->children) {
1467 gst_bin_remove (bin, GST_ELEMENT (bin->children->data));
1469 if (G_UNLIKELY (bin->children != NULL)) {
1470 g_critical ("could not remove elements from bin %s",
1471 GST_STR_NULL (GST_OBJECT_NAME (object)));
1474 G_OBJECT_CLASS (parent_class)->dispose (object);
1478 * This function is a utility event handler for seek events.
1479 * It will send the event to all sinks.
1480 * Applications are free to override this behaviour and
1481 * implement their own seek handler, but this will work for
1482 * pretty much all cases in practice.
1485 gst_bin_send_event (GstElement * element, GstEvent * event)
1487 GstBin *bin = GST_BIN (element);
1489 gboolean res = TRUE;
1490 gboolean done = FALSE;
1492 iter = gst_bin_iterate_sinks (bin);
1493 GST_DEBUG_OBJECT (bin, "Sending event to sink children");
1498 switch (gst_iterator_next (iter, &data)) {
1499 case GST_ITERATOR_OK:
1503 gst_event_ref (event);
1504 sink = GST_ELEMENT_CAST (data);
1505 res &= gst_element_send_event (sink, event);
1506 gst_object_unref (sink);
1509 case GST_ITERATOR_RESYNC:
1510 gst_iterator_resync (iter);
1514 case GST_ITERATOR_DONE:
1519 gst_iterator_free (iter);
1520 gst_event_unref (event);
1525 static GstBusSyncReply
1526 bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin)
1528 GST_DEBUG_OBJECT (bin, "[msg %p] handling child message of type %s",
1529 message, gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1531 switch (GST_MESSAGE_TYPE (message)) {
1532 case GST_MESSAGE_EOS:{
1533 GstObject *src = GST_MESSAGE_SRC (message);
1538 name = gst_object_get_name (src);
1539 GST_DEBUG_OBJECT (bin, "got EOS message from %s", name);
1542 /* collect all eos messages from the children */
1543 GST_LOCK (bin->child_bus);
1544 bin->eosed = g_list_prepend (bin->eosed, src);
1545 GST_UNLOCK (bin->child_bus);
1547 /* if we are completely EOS, we forward an EOS message */
1549 GST_DEBUG_OBJECT (bin, "all sinks posted EOS");
1550 gst_element_post_message (GST_ELEMENT (bin),
1551 gst_message_new_eos (GST_OBJECT (bin)));
1554 GST_DEBUG_OBJECT (bin, "got EOS message from (NULL), not processing");
1557 /* we drop all EOS messages */
1558 gst_message_unref (message);
1562 /* Send all other messages upward */
1563 GST_DEBUG_OBJECT (bin, "posting message upward");
1564 gst_element_post_message (GST_ELEMENT (bin), message);
1568 return GST_BUS_DROP;
1572 gst_bin_query (GstElement * element, GstQuery * query)
1574 GstBin *bin = GST_BIN (element);
1576 gboolean res = FALSE, done = FALSE;
1578 iter = gst_bin_iterate_sinks (bin);
1579 GST_DEBUG_OBJECT (bin, "Sending event to sink children");
1581 while (!(res || done)) {
1584 switch (gst_iterator_next (iter, &data)) {
1585 case GST_ITERATOR_OK:
1589 sink = GST_ELEMENT_CAST (data);
1590 res = gst_element_query (sink, query);
1591 gst_object_unref (sink);
1594 case GST_ITERATOR_RESYNC:
1595 gst_iterator_resync (iter);
1598 case GST_ITERATOR_DONE:
1603 gst_iterator_free (iter);
1609 compare_name (GstElement * element, const gchar * name)
1614 eq = strcmp (GST_ELEMENT_NAME (element), name);
1615 GST_UNLOCK (element);
1618 gst_object_unref (element);
1624 * gst_bin_get_by_name:
1625 * @bin: #Gstbin to search
1626 * @name: the element name to search for
1628 * Get the element with the given name from this bin. This
1629 * function recurses into subbins.
1633 * Returns: the element with the given name. Returns NULL if the
1634 * element is not found or when bad parameters were given. Unref after
1638 gst_bin_get_by_name (GstBin * bin, const gchar * name)
1640 GstIterator *children;
1641 GstIterator *result;
1643 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1645 GST_CAT_INFO (GST_CAT_PARENTAGE, "[%s]: looking up child element %s",
1646 GST_ELEMENT_NAME (bin), name);
1648 children = gst_bin_iterate_recurse (bin);
1649 result = gst_iterator_find_custom (children,
1650 (GCompareFunc) compare_name, (gpointer) name);
1651 gst_iterator_free (children);
1653 return GST_ELEMENT_CAST (result);
1657 * gst_bin_get_by_name_recurse_up:
1658 * @bin: #Gstbin to search
1659 * @name: the element name to search for
1663 * Get the element with the given name from this bin. If the
1664 * element is not found, a recursion is performed on the parent bin.
1666 * Returns: the element with the given name or NULL when the element
1667 * was not found or bad parameters were given. Unref after use.
1670 gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
1674 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1675 g_return_val_if_fail (name != NULL, NULL);
1677 result = gst_bin_get_by_name (bin, name);
1682 parent = gst_object_get_parent (GST_OBJECT_CAST (bin));
1684 if (GST_IS_BIN (parent)) {
1685 result = gst_bin_get_by_name_recurse_up (GST_BIN_CAST (parent), name);
1687 gst_object_unref (parent);
1695 compare_interface (GstElement * element, gpointer interface)
1699 if (G_TYPE_CHECK_INSTANCE_TYPE (element, GPOINTER_TO_INT (interface))) {
1702 /* we did not find the element, need to release the ref
1703 * added by the iterator */
1704 gst_object_unref (element);
1711 * gst_bin_get_by_interface:
1712 * @bin: bin to find element in
1713 * @interface: interface to be implemented by interface
1715 * Looks for the first element inside the bin that implements the given
1716 * interface. If such an element is found, it returns the element. You can
1717 * cast this element to the given interface afterwards.
1718 * If you want all elements that implement the interface, use
1719 * gst_bin_iterate_all_by_interface(). The function recurses inside bins.
1723 * Returns: An #GstElement inside the bin implementing the interface.
1727 gst_bin_get_by_interface (GstBin * bin, GType interface)
1729 GstIterator *children;
1730 GstIterator *result;
1732 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1734 children = gst_bin_iterate_recurse (bin);
1735 result = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
1736 GINT_TO_POINTER (interface));
1737 gst_iterator_free (children);
1739 return GST_ELEMENT_CAST (result);
1743 * gst_bin_iterate_all_by_interface:
1744 * @bin: bin to find elements in
1745 * @interface: interface to be implemented by interface
1747 * Looks for all elements inside the bin that implements the given
1748 * interface. You can safely cast all returned elements to the given interface.
1749 * The function recurses bins inside bins. The iterator will return a series
1750 * of #GstElement that should be unreffed after use.
1754 * Returns: A #GstIterator for the elements inside the bin implementing the
1758 gst_bin_iterate_all_by_interface (GstBin * bin, GType interface)
1760 GstIterator *children;
1761 GstIterator *result;
1763 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1765 children = gst_bin_iterate_recurse (bin);
1766 result = gst_iterator_filter (children, (GCompareFunc) compare_interface,
1767 GINT_TO_POINTER (interface));
1772 #ifndef GST_DISABLE_LOADSAVE
1774 gst_bin_save_thyself (GstObject * object, xmlNodePtr parent)
1776 GstBin *bin = GST_BIN (object);
1777 xmlNodePtr childlist, elementnode;
1781 if (GST_OBJECT_CLASS (parent_class)->save_thyself)
1782 GST_OBJECT_CLASS (parent_class)->save_thyself (GST_OBJECT (bin), parent);
1784 childlist = xmlNewChild (parent, NULL, (xmlChar *) "children", NULL);
1786 GST_CAT_INFO (GST_CAT_XML, "[%s]: saving %d children",
1787 GST_ELEMENT_NAME (bin), bin->numchildren);
1789 children = bin->children;
1791 child = GST_ELEMENT (children->data);
1792 elementnode = xmlNewChild (childlist, NULL, (xmlChar *) "element", NULL);
1793 gst_object_save_thyself (GST_OBJECT (child), elementnode);
1794 children = g_list_next (children);
1800 gst_bin_restore_thyself (GstObject * object, xmlNodePtr self)
1802 GstBin *bin = GST_BIN (object);
1803 xmlNodePtr field = self->xmlChildrenNode;
1804 xmlNodePtr childlist;
1807 if (!strcmp ((char *) field->name, "children")) {
1808 GST_CAT_INFO (GST_CAT_XML, "[%s]: loading children",
1809 GST_ELEMENT_NAME (object));
1810 childlist = field->xmlChildrenNode;
1812 if (!strcmp ((char *) childlist->name, "element")) {
1813 GstElement *element =
1814 gst_xml_make_element (childlist, GST_OBJECT (bin));
1816 /* it had to be parented to find the pads, now we ref and unparent so
1817 * we can add it to the bin */
1818 gst_object_ref (element);
1819 gst_object_unparent (GST_OBJECT (element));
1821 gst_bin_add (bin, element);
1823 childlist = childlist->next;
1827 field = field->next;
1829 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
1830 (GST_OBJECT_CLASS (parent_class)->restore_thyself) (object, self);
1832 #endif /* GST_DISABLE_LOADSAVE */