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 * and one for sending messages up the hierarchy */
278 bus = g_object_new (gst_bus_get_type (), NULL);
279 bin->child_bus = bus;
280 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin);
282 bus = g_object_new (gst_bus_get_type (), NULL);
283 gst_element_set_bus (GST_ELEMENT (bin), bus);
284 /* set_bus refs the bus via gst_object_replace, we drop our ref */
285 gst_object_unref (bus);
290 * @name: name of new bin
292 * Create a new bin with given name.
297 gst_bin_new (const gchar * name)
299 return gst_element_factory_make ("bin", name);
302 /* set the index on all elements in this bin
306 #ifndef GST_DISABLE_INDEX
308 gst_bin_set_index_func (GstElement * element, GstIndex * index)
313 bin = GST_BIN (element);
316 for (children = bin->children; children; children = g_list_next (children)) {
317 GstElement *child = GST_ELEMENT (children->data);
319 gst_element_set_index (child, index);
325 /* set the clock on all elements in this bin
330 gst_bin_set_clock_func (GstElement * element, GstClock * clock)
335 bin = GST_BIN (element);
338 for (children = bin->children; children; children = g_list_next (children)) {
339 GstElement *child = GST_ELEMENT (children->data);
341 gst_element_set_clock (child, clock);
346 /* get the clock for this bin by asking all of the children in this bin
348 * The ref of the returned clock in increased so unref after usage.
352 * FIXME, clock selection is not correct here.
355 gst_bin_provide_clock_func (GstElement * element)
357 GstClock *result = NULL;
361 bin = GST_BIN (element);
364 for (children = bin->children; children; children = g_list_next (children)) {
365 GstElement *child = GST_ELEMENT (children->data);
367 result = gst_element_provide_clock (child);
377 is_eos (GstBin * bin)
380 gboolean result = TRUE;
381 gboolean done = FALSE;
383 sinks = gst_bin_iterate_sinks (bin);
387 switch (gst_iterator_next (sinks, &data)) {
388 case GST_ITERATOR_OK:
390 GstElement *element = GST_ELEMENT (data);
394 name = gst_element_get_name (element);
395 eosed = g_list_find (bin->eosed, element);
397 GST_DEBUG ("element %s did not post EOS yet", name);
401 GST_DEBUG ("element %s posted EOS", name);
404 gst_object_unref (element);
407 case GST_ITERATOR_RESYNC:
409 gst_iterator_resync (sinks);
411 case GST_ITERATOR_DONE:
415 g_assert_not_reached ();
419 gst_iterator_free (sinks);
424 unlink_pads (GstPad * pad)
428 if ((peer = gst_pad_get_peer (pad))) {
429 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
430 gst_pad_unlink (pad, peer);
432 gst_pad_unlink (peer, pad);
433 gst_object_unref (peer);
435 gst_object_unref (pad);
438 /* add an element to this bin
443 gst_bin_add_func (GstBin * bin, GstElement * element)
448 /* we obviously can't add ourself to ourself */
449 if (G_UNLIKELY (GST_ELEMENT_CAST (element) == GST_ELEMENT_CAST (bin)))
452 /* get the element name to make sure it is unique in this bin. */
454 elem_name = g_strdup (GST_ELEMENT_NAME (element));
455 GST_UNLOCK (element);
459 /* then check to see if the element's name is already taken in the bin,
460 * we can safely take the lock here. This check is probably bogus because
461 * you can safely change the element name after this check and before setting
462 * the object parent. The window is very small though... */
463 if (G_UNLIKELY (!gst_object_check_uniqueness (bin->children, elem_name)))
466 /* set the element's parent and add the element to the bin's list of children */
467 if (G_UNLIKELY (!gst_object_set_parent (GST_OBJECT_CAST (element),
468 GST_OBJECT_CAST (bin))))
471 /* if we add a sink we become a sink */
472 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
473 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "element \"%s\" was sink",
475 GST_FLAG_SET (bin, GST_ELEMENT_IS_SINK);
478 bin->children = g_list_prepend (bin->children, element);
480 bin->children_cookie++;
482 /* distribute the bus */
483 gst_element_set_bus (element, bin->child_bus);
485 /* propagate the current base time and clock */
486 gst_element_set_base_time (element, GST_ELEMENT (bin)->base_time);
487 gst_element_set_clock (element, GST_ELEMENT_CLOCK (bin));
491 /* unlink all linked pads */
492 it = gst_element_iterate_pads (element);
493 gst_iterator_foreach (it, (GFunc) unlink_pads, element);
494 gst_iterator_free (it);
496 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
500 g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_ADDED], 0, element);
504 /* ERROR handling here */
508 g_warning ("Cannot add bin %s to itself", GST_ELEMENT_NAME (bin));
514 g_warning ("Name %s is not unique in bin %s, not adding",
515 elem_name, GST_ELEMENT_NAME (bin));
522 g_warning ("Element %s already has parent", elem_name);
532 * @bin: #GstBin to add element to
533 * @element: #GstElement to add to bin
535 * Adds the given element to the bin. Sets the element's parent, and thus
536 * takes ownership of the element. An element can only be added to one bin.
538 * If the element's pads are linked to other pads, the pads will be unlinked
539 * before the element is added to the bin.
543 * Returns: TRUE if the element could be added, FALSE on wrong parameters or
544 * the bin does not want to accept the element.
547 gst_bin_add (GstBin * bin, GstElement * element)
552 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
553 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
555 bclass = GST_BIN_GET_CLASS (bin);
557 if (G_UNLIKELY (bclass->add_element == NULL))
560 GST_CAT_DEBUG (GST_CAT_PARENTAGE, "adding element %s to bin %s",
561 GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (bin));
563 result = bclass->add_element (bin, element);
570 g_warning ("adding elements to bin %s is not supported",
571 GST_ELEMENT_NAME (bin));
576 /* remove an element from the bin
581 gst_bin_remove_func (GstBin * bin, GstElement * element)
587 /* Check if the element is already being removed and immediately
589 if (G_UNLIKELY (GST_FLAG_IS_SET (element, GST_ELEMENT_UNPARENTING)))
590 goto already_removing;
592 GST_FLAG_SET (element, GST_ELEMENT_UNPARENTING);
593 /* grab element name so we can print it */
594 elem_name = g_strdup (GST_ELEMENT_NAME (element));
595 GST_UNLOCK (element);
597 /* unlink all linked pads */
598 it = gst_element_iterate_pads (element);
599 gst_iterator_foreach (it, (GFunc) unlink_pads, element);
600 gst_iterator_free (it);
603 /* the element must be in the bin's list of children */
604 if (G_UNLIKELY (g_list_find (bin->children, element) == NULL))
607 /* now remove the element from the list of elements */
608 bin->children = g_list_remove (bin->children, element);
610 bin->children_cookie++;
612 /* check if we removed a sink */
613 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
616 /* check if we removed the last sink */
617 other_sink = g_list_find_custom (bin->children,
618 bin, (GCompareFunc) bin_element_is_sink);
620 /* yups, we're not a sink anymore */
621 GST_FLAG_UNSET (bin, GST_ELEMENT_IS_SINK);
626 GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin, "removed child \"%s\"",
630 gst_element_set_bus (element, NULL);
632 /* unlock any waiters for the state change. It is possible that
633 * we are waiting for an ASYNC state change on this element. The
634 * element cannot be added to another bin yet as it is not yet
636 GST_STATE_LOCK (element);
637 GST_STATE_BROADCAST (element);
638 GST_STATE_UNLOCK (element);
640 /* we ref here because after the _unparent() the element can be disposed
641 * and we still need it to reset the UNPARENTING flag and fire a signal. */
642 gst_object_ref (element);
643 gst_object_unparent (GST_OBJECT_CAST (element));
646 GST_FLAG_UNSET (element, GST_ELEMENT_UNPARENTING);
647 GST_UNLOCK (element);
649 g_signal_emit (G_OBJECT (bin), gst_bin_signals[ELEMENT_REMOVED], 0, element);
651 /* element is really out of our control now */
652 gst_object_unref (element);
659 g_warning ("Element %s is not in bin %s", elem_name,
660 GST_ELEMENT_NAME (bin));
667 GST_UNLOCK (element);
674 * @bin: #GstBin to remove element from
675 * @element: #GstElement to remove
677 * Remove the element from its associated bin, unparenting it as well.
678 * Unparenting the element means that the element will be dereferenced,
679 * so if the bin holds the only reference to the element, the element
680 * will be freed in the process of removing it from the bin. If you
681 * want the element to still exist after removing, you need to call
682 * gst_object_ref() before removing it from the bin.
684 * If the element's pads are linked to other pads, the pads will be unlinked
685 * before the element is removed from the bin.
689 * Returns: TRUE if the element could be removed, FALSE on wrong parameters or
690 * the bin does not want to remove the element.
693 gst_bin_remove (GstBin * bin, GstElement * element)
698 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
699 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
701 bclass = GST_BIN_GET_CLASS (bin);
703 if (G_UNLIKELY (bclass->remove_element == NULL))
706 GST_CAT_DEBUG (GST_CAT_PARENTAGE, "removing element %s from bin %s",
707 GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (bin));
709 result = bclass->remove_element (bin, element);
716 g_warning ("removing elements from bin %s is not supported",
717 GST_ELEMENT_NAME (bin));
722 static GstIteratorItem
723 iterate_child (GstIterator * it, GstElement * child)
725 gst_object_ref (child);
726 return GST_ITERATOR_ITEM_PASS;
730 * gst_bin_iterate_elements:
731 * @bin: #Gstbin to iterate the elements of
733 * Get an iterator for the elements in this bin.
734 * Each element will have its refcount increased, so unref
739 * Returns: a #GstIterator of #GstElements. gst_iterator_free after
740 * use. returns NULL when passing bad parameters.
743 gst_bin_iterate_elements (GstBin * bin)
747 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
750 /* add ref because the iterator refs the bin. When the iterator
751 * is freed it will unref the bin again using the provided dispose
753 gst_object_ref (bin);
754 result = gst_iterator_new_list (GST_GET_LOCK (bin),
755 &bin->children_cookie,
758 (GstIteratorItemFunction) iterate_child,
759 (GstIteratorDisposeFunction) gst_object_unref);
765 static GstIteratorItem
766 iterate_child_recurse (GstIterator * it, GstElement * child)
768 gst_object_ref (child);
769 if (GST_IS_BIN (child)) {
770 GstIterator *other = gst_bin_iterate_recurse (GST_BIN (child));
772 gst_iterator_push (it, other);
774 return GST_ITERATOR_ITEM_PASS;
778 * gst_bin_iterate_recurse:
779 * @bin: #Gstbin to iterate the elements of
781 * Get an iterator for the elements in this bin.
782 * Each element will have its refcount increased, so unref
783 * after use. This iterator recurses into GstBin children.
787 * Returns: a #GstIterator of #GstElements. gst_iterator_free after
788 * use. returns NULL when passing bad parameters.
791 gst_bin_iterate_recurse (GstBin * bin)
795 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
798 /* add ref because the iterator refs the bin. When the iterator
799 * is freed it will unref the bin again using the provided dispose
801 gst_object_ref (bin);
802 result = gst_iterator_new_list (GST_GET_LOCK (bin),
803 &bin->children_cookie,
806 (GstIteratorItemFunction) iterate_child_recurse,
807 (GstIteratorDisposeFunction) gst_object_unref);
813 /* returns 0 when TRUE because this is a GCompareFunc */
816 bin_element_is_sink (GstElement * child, GstBin * bin)
820 /* we lock the child here for the remainder of the function to
821 * get its name safely. */
823 is_sink = GST_FLAG_IS_SET (child, GST_ELEMENT_IS_SINK);
825 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, bin,
826 "child %s %s sink", GST_OBJECT_NAME (child), is_sink ? "is" : "is not");
829 return is_sink ? 0 : 1;
833 sink_iterator_filter (GstElement * child, GstBin * bin)
835 if (bin_element_is_sink (child, bin) == 0) {
836 /* returns 0 because this is a GCompareFunc */
839 /* child carries a ref from gst_bin_iterate_elements -- drop if not passing
841 gst_object_unref ((GstObject *) child);
847 * gst_bin_iterate_sinks:
848 * @bin: #Gstbin to iterate on
850 * Get an iterator for the sink elements in this bin.
851 * Each element will have its refcount increased, so unref
854 * The sink elements are those without any linked srcpads.
858 * Returns: a #GstIterator of #GstElements. gst_iterator_free after use.
861 gst_bin_iterate_sinks (GstBin * bin)
863 GstIterator *children;
866 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
868 children = gst_bin_iterate_elements (bin);
869 result = gst_iterator_filter (children,
870 (GCompareFunc) sink_iterator_filter, bin);
876 * 1) check state of all children with 0 timeout to find ERROR and
877 * NO_PREROLL elements. return if found.
878 * 2) perform full blocking wait with requested timeout.
880 * 2) cannot be performed when 1) returns results as the sinks might
881 * not be able to complete the state change making 2) block forever.
885 static GstStateChangeReturn
886 gst_bin_get_state (GstElement * element, GstState * state,
887 GstState * pending, GTimeVal * timeout)
889 GstBin *bin = GST_BIN (element);
890 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
892 guint32 children_cookie;
893 gboolean have_no_preroll;
895 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "getting state");
897 /* lock bin, no element can be added or removed between going into
898 * the quick scan and the blocking wait. */
902 have_no_preroll = FALSE;
904 /* first we need to poll with a non zero timeout to make sure we don't block
905 * on the sinks when we have NO_PREROLL elements. This is why we do
906 * a quick check if there are still NO_PREROLL elements. We also
907 * catch the error elements this way. */
910 gboolean have_async = FALSE;
912 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "checking for NO_PREROLL");
913 /* use 0 timeout so we don't block on the sinks */
914 GST_TIME_TO_TIMEVAL (0, tv);
915 children = bin->children;
916 children_cookie = bin->children_cookie;
918 GstElement *child = GST_ELEMENT_CAST (children->data);
920 gst_object_ref (child);
921 /* now we release the lock to enter a non blocking wait. We
922 * release the lock anyway since we can. */
925 ret = gst_element_get_state (child, NULL, NULL, &tv);
927 gst_object_unref (child);
929 /* now grab the lock to iterate to the next child */
931 if (G_UNLIKELY (children_cookie != bin->children_cookie)) {
932 /* child added/removed during state change, restart. We need
933 * to restart with the quick check as a no-preroll element could
934 * have been added here and we don't want to block on sinks then.*/
939 /* report FAILURE immediatly */
940 case GST_STATE_CHANGE_FAILURE:
942 case GST_STATE_CHANGE_NO_PREROLL:
943 /* we have to continue scanning as there might be
945 have_no_preroll = TRUE;
947 case GST_STATE_CHANGE_ASYNC:
953 children = g_list_next (children);
955 /* if we get here, we have no FAILURES, check for any NO_PREROLL
957 if (have_no_preroll) {
958 ret = GST_STATE_CHANGE_NO_PREROLL;
962 /* if we get here, no NO_PREROLL elements are in the pipeline */
963 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "no NO_PREROLL elements");
965 /* if no ASYNC elements exist we don't even have to poll with a
968 ret = GST_STATE_CHANGE_SUCCESS;
973 /* next we poll all children for their state to see if one of them
974 * is still busy with its state change. We did not release the bin lock
975 * yet so the elements are the same as the ones from the quick scan. */
976 children = bin->children;
977 children_cookie = bin->children_cookie;
979 GstElement *child = GST_ELEMENT_CAST (children->data);
981 gst_object_ref (child);
982 /* now we release the lock to enter the potentialy blocking wait */
985 /* ret is ASYNC if some child is still performing the state change
986 * ater the timeout. */
987 ret = gst_element_get_state (child, NULL, NULL, timeout);
989 gst_object_unref (child);
991 /* now grab the lock to iterate to the next child */
993 if (G_UNLIKELY (children_cookie != bin->children_cookie)) {
994 /* child added/removed during state change, restart. We need
995 * to restart with the quick check as a no-preroll element could
996 * have been added here and we don't want to block on sinks then.*/
1001 case GST_STATE_CHANGE_SUCCESS:
1003 case GST_STATE_CHANGE_FAILURE:
1004 case GST_STATE_CHANGE_NO_PREROLL:
1005 /* report FAILURE and NO_PREROLL immediatly */
1007 case GST_STATE_CHANGE_ASYNC:
1010 g_assert_not_reached ();
1012 children = g_list_next (children);
1014 /* if we got here, all elements can do preroll */
1015 have_no_preroll = FALSE;
1020 /* now we can take the state lock, it is possible that new elements
1021 * are added now and we still report the old state. No problem though as
1022 * the return is still consistent, the effect is as if the element was
1023 * added after this function completed. */
1024 GST_STATE_LOCK (bin);
1026 case GST_STATE_CHANGE_SUCCESS:
1027 /* we can commit the state */
1028 gst_element_commit_state (element);
1030 case GST_STATE_CHANGE_FAILURE:
1031 /* some element failed, abort the state change */
1032 gst_element_abort_state (element);
1035 /* other cases are just passed along */
1039 /* and report the state if needed */
1041 *state = GST_STATE (element);
1043 *pending = GST_STATE_PENDING (element);
1045 GST_STATE_NO_PREROLL (element) = have_no_preroll;
1047 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1048 "state current: %s, pending: %s, error: %d, no_preroll: %d, result: %d",
1049 gst_element_state_get_name (GST_STATE (element)),
1050 gst_element_state_get_name (GST_STATE_PENDING (element)),
1051 GST_STATE_ERROR (element), GST_STATE_NO_PREROLL (element), ret);
1053 GST_STATE_UNLOCK (bin);
1058 /***********************************************
1059 * Topologically sorted iterator
1060 * see http://en.wikipedia.org/wiki/Topological_sorting
1062 * For each element in the graph, an entry is kept in a HashTable
1063 * with its number of srcpad connections (degree).
1064 * We then change state of all elements without dependencies
1065 * (degree 0) and decrement the degree of all elements connected
1066 * on the sinkpads. When an element reaches degree 0, its state is
1068 * When all elements are handled the algorithm stops.
1070 typedef struct _GstBinSortIterator
1073 GQueue *queue; /* elements queued for state change */
1074 GstBin *bin; /* bin we iterate */
1075 gint mode; /* adding or removing dependency */
1076 GstElement *best; /* next element with least dependencies */
1077 gint best_deg; /* best degree */
1078 GHashTable *hash; /* has table with element dependencies */
1079 } GstBinSortIterator;
1081 /* we add and subtract 1 to make sure we don't confuse NULL and 0 */
1082 #define HASH_SET_DEGREE(bit, elem, deg) \
1083 g_hash_table_replace (bit->hash, elem, GINT_TO_POINTER(deg+1))
1084 #define HASH_GET_DEGREE(bit, elem) \
1085 (GPOINTER_TO_INT(g_hash_table_lookup (bit->hash, elem))-1)
1087 /* add element to queue of next elements in the iterator.
1088 * We push at the tail to give higher priority elements a
1091 add_to_queue (GstBinSortIterator * bit, GstElement * element)
1093 GST_DEBUG ("%s add to queue", GST_ELEMENT_NAME (element));
1094 gst_object_ref (element);
1095 g_queue_push_tail (bit->queue, element);
1096 HASH_SET_DEGREE (bit, element, -1);
1099 /* clear the queue, unref all objects as we took a ref when
1100 * we added them to the queue */
1102 clear_queue (GQueue * queue)
1106 while ((p = g_queue_pop_head (queue)))
1107 gst_object_unref (p);
1110 /* set all degrees to 0. Elements marked as a sink are
1111 * added to the queue immediatly. */
1113 reset_degree (GstElement * element, GstBinSortIterator * bit)
1115 /* sinks are added right away */
1116 if (GST_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK)) {
1117 add_to_queue (bit, element);
1119 /* others are marked with 0 and handled when sinks are done */
1120 HASH_SET_DEGREE (bit, element, 0);
1124 /* adjust the degree of all elements connected to the given
1125 * element. If an degree of an element drops to 0, it is
1126 * added to the queue of elements to schedule next.
1128 * We have to make sure not to cross the bin boundary this element
1132 update_degree (GstElement * element, GstBinSortIterator * bit)
1134 gboolean linked = FALSE;
1137 /* don't touch degree is element has no sourcepads */
1138 if (element->numsinkpads != 0) {
1139 /* loop over all sinkpads, decrement degree for all connected
1140 * elements in this bin */
1143 for (pads = element->sinkpads; pads; pads = g_list_next (pads)) {
1146 if ((peer = gst_pad_get_peer (GST_PAD_CAST (pads->data)))) {
1147 GstElement *peer_element;
1149 if ((peer_element = gst_pad_get_parent_element (peer))) {
1150 GST_LOCK (peer_element);
1151 if (GST_OBJECT_CAST (peer_element)->parent ==
1152 GST_OBJECT_CAST (bit->bin)) {
1153 gint old_deg, new_deg;
1155 old_deg = HASH_GET_DEGREE (bit, peer_element);
1156 new_deg = old_deg + bit->mode;
1158 GST_DEBUG ("change element %s, degree %d->%d, linked to %s",
1159 GST_ELEMENT_NAME (peer_element),
1160 old_deg, new_deg, GST_ELEMENT_NAME (element));
1164 /* degree hit 0, add to queue */
1165 add_to_queue (bit, peer_element);
1167 HASH_SET_DEGREE (bit, peer_element, new_deg);
1171 GST_UNLOCK (peer_element);
1172 gst_object_unref (peer_element);
1174 gst_object_unref (peer);
1179 GST_DEBUG ("element %s not linked to anything", GST_ELEMENT_NAME (element));
1181 GST_UNLOCK (element);
1184 /* find the next best element not handled yet. This is the one
1185 * with the lowest non-negative degree */
1187 find_element (GstElement * element, GstBinSortIterator * bit)
1191 /* element is already handled */
1192 if ((degree = HASH_GET_DEGREE (bit, element)) < 0)
1195 /* first element or element with smaller degree */
1196 if (bit->best == NULL || bit->best_deg > degree) {
1197 bit->best = element;
1198 bit->best_deg = degree;
1202 /* get next element in iterator. the returned element has the
1203 * refcount increased */
1204 static GstIteratorResult
1205 gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
1207 /* empty queue, we have to find a next best element */
1208 if (g_queue_is_empty (bit->queue)) {
1210 bit->best_deg = G_MAXINT;
1211 g_list_foreach (bit->bin->children, (GFunc) find_element, bit);
1213 if (bit->best_deg != 0) {
1214 /* we don't fail on this one yet */
1215 g_warning ("loop detected in the graph !!");
1217 /* best unhandled element, schedule as next element */
1218 GST_DEBUG ("queue empty, next best: %s", GST_ELEMENT_NAME (bit->best));
1219 gst_object_ref (bit->best);
1220 HASH_SET_DEGREE (bit, bit->best, -1);
1221 *result = bit->best;
1223 GST_DEBUG ("queue empty, elements exhausted");
1224 /* no more unhandled elements, we are done */
1225 return GST_ITERATOR_DONE;
1228 /* everything added to the queue got reffed */
1229 *result = g_queue_pop_head (bit->queue);
1232 GST_DEBUG ("queue head gives %s", GST_ELEMENT_NAME (*result));
1233 /* update degrees of linked elements */
1234 update_degree (GST_ELEMENT_CAST (*result), bit);
1236 return GST_ITERATOR_OK;
1239 /* clear queues, recalculate the degrees and restart. */
1241 gst_bin_sort_iterator_resync (GstBinSortIterator * bit)
1243 clear_queue (bit->queue);
1245 g_list_foreach (bit->bin->children, (GFunc) reset_degree, bit);
1246 /* calc degrees, incrementing */
1248 g_list_foreach (bit->bin->children, (GFunc) update_degree, bit);
1249 /* for the rest of the function we decrement the degrees */
1253 /* clear queues, unref bin and free iterator. */
1255 gst_bin_sort_iterator_free (GstBinSortIterator * bit)
1257 clear_queue (bit->queue);
1258 g_queue_free (bit->queue);
1259 g_hash_table_destroy (bit->hash);
1260 gst_object_unref (bit->bin);
1265 * gst_bin_iterate_sorted:
1266 * @bin: #Gstbin to iterate on
1268 * Get an iterator for the elements in this bin in topologically
1269 * sorted order. This means that the elements are returned from
1270 * the most downstream elements (sinks) to the sources.
1272 * This function is used internally to perform the state changes
1273 * of the bin elements.
1275 * Each element will have its refcount increased, so unref
1280 * Returns: a #GstIterator of #GstElements. gst_iterator_free after use.
1283 gst_bin_iterate_sorted (GstBin * bin)
1285 GstBinSortIterator *result;
1287 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1290 gst_object_ref (bin);
1291 /* we don't need a NextFunction because we ref the items in the _next
1293 result = (GstBinSortIterator *)
1294 gst_iterator_new (sizeof (GstBinSortIterator),
1296 &bin->children_cookie,
1297 (GstIteratorNextFunction) gst_bin_sort_iterator_next,
1298 (GstIteratorItemFunction) NULL,
1299 (GstIteratorResyncFunction) gst_bin_sort_iterator_resync,
1300 (GstIteratorFreeFunction) gst_bin_sort_iterator_free);
1301 result->queue = g_queue_new ();
1302 result->hash = g_hash_table_new (NULL, NULL);
1304 gst_bin_sort_iterator_resync (result);
1307 return (GstIterator *) result;
1310 static GstStateChangeReturn
1311 gst_bin_element_set_state (GstBin * bin, GstElement * element, GstState pending)
1313 GstStateChangeReturn ret;
1316 /* peel off the locked flag */
1318 locked = GST_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1319 GST_UNLOCK (element);
1321 /* skip locked elements */
1322 if (G_UNLIKELY (locked)) {
1323 ret = GST_STATE_CHANGE_SUCCESS;
1328 ret = gst_element_set_state (element, pending);
1334 static GstStateChangeReturn
1335 gst_bin_change_state (GstElement * element, GstStateChange transition)
1338 GstStateChangeReturn ret;
1339 GstState old_state, pending;
1340 gboolean have_async;
1341 gboolean have_no_preroll;
1342 GstClockTime base_time;
1346 /* we don't need to take the STATE_LOCK, it is already taken */
1347 old_state = GST_STATE (element);
1348 pending = GST_STATE_PENDING (element);
1350 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1351 "changing state of children from %s to %s",
1352 gst_element_state_get_name (old_state),
1353 gst_element_state_get_name (pending));
1355 if (pending == GST_STATE_VOID_PENDING)
1356 return GST_STATE_CHANGE_SUCCESS;
1358 bin = GST_BIN_CAST (element);
1360 /* Clear eosed element list on READY-> PAUSED */
1361 if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) {
1362 g_list_free (bin->eosed);
1366 /* iterate in state change order */
1367 it = gst_bin_iterate_sorted (bin);
1370 /* take base time */
1371 base_time = element->base_time;
1374 have_no_preroll = FALSE;
1380 switch (gst_iterator_next (it, &data)) {
1381 case GST_ITERATOR_OK:
1383 GstElement *element;
1385 element = GST_ELEMENT_CAST (data);
1387 /* set base time on element */
1388 gst_element_set_base_time (element, base_time);
1391 ret = gst_bin_element_set_state (bin, element, pending);
1394 case GST_STATE_CHANGE_SUCCESS:
1395 GST_CAT_DEBUG (GST_CAT_STATES,
1396 "child '%s' changed state to %d(%s) successfully",
1397 GST_ELEMENT_NAME (element), pending,
1398 gst_element_state_get_name (pending));
1400 case GST_STATE_CHANGE_ASYNC:
1401 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1402 "child '%s' is changing state asynchronously",
1403 GST_ELEMENT_NAME (element));
1406 case GST_STATE_CHANGE_FAILURE:
1407 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1408 "child '%s' failed to go to state %d(%s)",
1409 GST_ELEMENT_NAME (element),
1410 pending, gst_element_state_get_name (pending));
1411 gst_object_unref (element);
1413 case GST_STATE_CHANGE_NO_PREROLL:
1414 GST_CAT_DEBUG (GST_CAT_STATES,
1415 "child '%s' changed state to %d(%s) successfully without preroll",
1416 GST_ELEMENT_NAME (element), pending,
1417 gst_element_state_get_name (pending));
1418 have_no_preroll = TRUE;
1421 g_assert_not_reached ();
1424 gst_object_unref (element);
1427 case GST_ITERATOR_RESYNC:
1428 gst_iterator_resync (it);
1432 case GST_ITERATOR_DONE:
1438 if (have_no_preroll) {
1439 ret = GST_STATE_CHANGE_NO_PREROLL;
1440 } else if (have_async) {
1441 ret = GST_STATE_CHANGE_ASYNC;
1443 ret = parent_class->change_state (element, transition);
1447 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1448 "done changing bin's state from %s to %s, now in %s, ret %d",
1449 gst_element_state_get_name (old_state),
1450 gst_element_state_get_name (pending),
1451 gst_element_state_get_name (GST_STATE (element)), ret);
1453 gst_iterator_free (it);
1459 gst_bin_dispose (GObject * object)
1461 GstBin *bin = GST_BIN (object);
1463 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object, "dispose");
1465 g_list_free (bin->eosed);
1467 gst_object_unref (bin->child_bus);
1468 bin->child_bus = NULL;
1469 gst_element_set_bus (GST_ELEMENT (bin), NULL);
1471 while (bin->children) {
1472 gst_bin_remove (bin, GST_ELEMENT (bin->children->data));
1474 if (G_UNLIKELY (bin->children != NULL)) {
1475 g_critical ("could not remove elements from bin %s",
1476 GST_STR_NULL (GST_OBJECT_NAME (object)));
1479 G_OBJECT_CLASS (parent_class)->dispose (object);
1483 * This function is a utility event handler for seek events.
1484 * It will send the event to all sinks.
1485 * Applications are free to override this behaviour and
1486 * implement their own seek handler, but this will work for
1487 * pretty much all cases in practice.
1490 gst_bin_send_event (GstElement * element, GstEvent * event)
1492 GstBin *bin = GST_BIN (element);
1494 gboolean res = TRUE;
1495 gboolean done = FALSE;
1497 iter = gst_bin_iterate_sinks (bin);
1498 GST_DEBUG_OBJECT (bin, "Sending event to sink children");
1503 switch (gst_iterator_next (iter, &data)) {
1504 case GST_ITERATOR_OK:
1508 gst_event_ref (event);
1509 sink = GST_ELEMENT_CAST (data);
1510 res &= gst_element_send_event (sink, event);
1511 gst_object_unref (sink);
1514 case GST_ITERATOR_RESYNC:
1515 gst_iterator_resync (iter);
1519 case GST_ITERATOR_DONE:
1524 gst_iterator_free (iter);
1525 gst_event_unref (event);
1530 static GstBusSyncReply
1531 bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin)
1533 GST_DEBUG_OBJECT (bin, "[msg %p] handling child message of type %d",
1534 message, GST_MESSAGE_TYPE (message));
1536 switch (GST_MESSAGE_TYPE (message)) {
1537 case GST_MESSAGE_EOS:{
1538 GstObject *src = GST_MESSAGE_SRC (message);
1543 name = gst_object_get_name (src);
1544 GST_DEBUG_OBJECT (bin, "got EOS message from %s", name);
1547 /* collect all eos messages from the children */
1548 GST_LOCK (bin->child_bus);
1549 bin->eosed = g_list_prepend (bin->eosed, src);
1550 GST_UNLOCK (bin->child_bus);
1552 /* if we are completely EOS, we forward an EOS message */
1554 GST_DEBUG_OBJECT (bin, "all sinks posted EOS");
1555 gst_element_post_message (GST_ELEMENT (bin),
1556 gst_message_new_eos (GST_OBJECT (bin)));
1559 GST_DEBUG_OBJECT (bin, "got EOS message from (NULL), not processing");
1562 /* we drop all EOS messages */
1563 gst_message_unref (message);
1567 /* Send all other messages upward */
1568 GST_DEBUG_OBJECT (bin, "posting message upward");
1569 gst_element_post_message (GST_ELEMENT (bin), message);
1573 return GST_BUS_DROP;
1577 gst_bin_query (GstElement * element, GstQuery * query)
1579 GstBin *bin = GST_BIN (element);
1581 gboolean res = FALSE, done = FALSE;
1583 iter = gst_bin_iterate_sinks (bin);
1584 GST_DEBUG_OBJECT (bin, "Sending event to sink children");
1586 while (!(res || done)) {
1589 switch (gst_iterator_next (iter, &data)) {
1590 case GST_ITERATOR_OK:
1594 sink = GST_ELEMENT_CAST (data);
1595 res = gst_element_query (sink, query);
1596 gst_object_unref (sink);
1599 case GST_ITERATOR_RESYNC:
1600 gst_iterator_resync (iter);
1603 case GST_ITERATOR_DONE:
1608 gst_iterator_free (iter);
1614 compare_name (GstElement * element, const gchar * name)
1619 eq = strcmp (GST_ELEMENT_NAME (element), name);
1620 GST_UNLOCK (element);
1623 gst_object_unref (element);
1629 * gst_bin_get_by_name:
1630 * @bin: #Gstbin to search
1631 * @name: the element name to search for
1633 * Get the element with the given name from this bin. This
1634 * function recurses into subbins.
1638 * Returns: the element with the given name. Returns NULL if the
1639 * element is not found or when bad parameters were given. Unref after
1643 gst_bin_get_by_name (GstBin * bin, const gchar * name)
1645 GstIterator *children;
1646 GstIterator *result;
1648 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1650 GST_CAT_INFO (GST_CAT_PARENTAGE, "[%s]: looking up child element %s",
1651 GST_ELEMENT_NAME (bin), name);
1653 children = gst_bin_iterate_recurse (bin);
1654 result = gst_iterator_find_custom (children,
1655 (GCompareFunc) compare_name, (gpointer) name);
1656 gst_iterator_free (children);
1658 return GST_ELEMENT_CAST (result);
1662 * gst_bin_get_by_name_recurse_up:
1663 * @bin: #Gstbin to search
1664 * @name: the element name to search for
1668 * Get the element with the given name from this bin. If the
1669 * element is not found, a recursion is performed on the parent bin.
1671 * Returns: the element with the given name or NULL when the element
1672 * was not found or bad parameters were given. Unref after use.
1675 gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
1679 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1680 g_return_val_if_fail (name != NULL, NULL);
1682 result = gst_bin_get_by_name (bin, name);
1687 parent = gst_object_get_parent (GST_OBJECT_CAST (bin));
1689 if (GST_IS_BIN (parent)) {
1690 result = gst_bin_get_by_name_recurse_up (GST_BIN_CAST (parent), name);
1692 gst_object_unref (parent);
1700 compare_interface (GstElement * element, gpointer interface)
1704 if (G_TYPE_CHECK_INSTANCE_TYPE (element, GPOINTER_TO_INT (interface))) {
1707 /* we did not find the element, need to release the ref
1708 * added by the iterator */
1709 gst_object_unref (element);
1716 * gst_bin_get_by_interface:
1717 * @bin: bin to find element in
1718 * @interface: interface to be implemented by interface
1720 * Looks for the first element inside the bin that implements the given
1721 * interface. If such an element is found, it returns the element. You can
1722 * cast this element to the given interface afterwards.
1723 * If you want all elements that implement the interface, use
1724 * gst_bin_iterate_all_by_interface(). The function recurses inside bins.
1728 * Returns: An #GstElement inside the bin implementing the interface.
1732 gst_bin_get_by_interface (GstBin * bin, GType interface)
1734 GstIterator *children;
1735 GstIterator *result;
1737 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1739 children = gst_bin_iterate_recurse (bin);
1740 result = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
1741 GINT_TO_POINTER (interface));
1742 gst_iterator_free (children);
1744 return GST_ELEMENT_CAST (result);
1748 * gst_bin_iterate_all_by_interface:
1749 * @bin: bin to find elements in
1750 * @interface: interface to be implemented by interface
1752 * Looks for all elements inside the bin that implements the given
1753 * interface. You can safely cast all returned elements to the given interface.
1754 * The function recurses bins inside bins. The iterator will return a series
1755 * of #GstElement that should be unreffed after use.
1759 * Returns: A #GstIterator for the elements inside the bin implementing the
1763 gst_bin_iterate_all_by_interface (GstBin * bin, GType interface)
1765 GstIterator *children;
1766 GstIterator *result;
1768 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
1770 children = gst_bin_iterate_recurse (bin);
1771 result = gst_iterator_filter (children, (GCompareFunc) compare_interface,
1772 GINT_TO_POINTER (interface));
1777 #ifndef GST_DISABLE_LOADSAVE
1779 gst_bin_save_thyself (GstObject * object, xmlNodePtr parent)
1781 GstBin *bin = GST_BIN (object);
1782 xmlNodePtr childlist, elementnode;
1786 if (GST_OBJECT_CLASS (parent_class)->save_thyself)
1787 GST_OBJECT_CLASS (parent_class)->save_thyself (GST_OBJECT (bin), parent);
1789 childlist = xmlNewChild (parent, NULL, (xmlChar *) "children", NULL);
1791 GST_CAT_INFO (GST_CAT_XML, "[%s]: saving %d children",
1792 GST_ELEMENT_NAME (bin), bin->numchildren);
1794 children = bin->children;
1796 child = GST_ELEMENT (children->data);
1797 elementnode = xmlNewChild (childlist, NULL, (xmlChar *) "element", NULL);
1798 gst_object_save_thyself (GST_OBJECT (child), elementnode);
1799 children = g_list_next (children);
1805 gst_bin_restore_thyself (GstObject * object, xmlNodePtr self)
1807 GstBin *bin = GST_BIN (object);
1808 xmlNodePtr field = self->xmlChildrenNode;
1809 xmlNodePtr childlist;
1812 if (!strcmp ((char *) field->name, "children")) {
1813 GST_CAT_INFO (GST_CAT_XML, "[%s]: loading children",
1814 GST_ELEMENT_NAME (object));
1815 childlist = field->xmlChildrenNode;
1817 if (!strcmp ((char *) childlist->name, "element")) {
1818 GstElement *element =
1819 gst_xml_make_element (childlist, GST_OBJECT (bin));
1821 /* it had to be parented to find the pads, now we ref and unparent so
1822 * we can add it to the bin */
1823 gst_object_ref (element);
1824 gst_object_unparent (GST_OBJECT (element));
1826 gst_bin_add (bin, element);
1828 childlist = childlist->next;
1832 field = field->next;
1834 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
1835 (GST_OBJECT_CLASS (parent_class)->restore_thyself) (object, self);
1837 #endif /* GST_DISABLE_LOADSAVE */