2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstbin.c: GstBin container object and support code
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.
23 /* #define GST_DEBUG_ENABLED */
24 #include "gst_private.h"
29 #include "gstsystemclock.h"
31 #include "gstscheduler.h"
33 GstElementDetails gst_bin_details = {
36 "Simple container object",
38 "Erik Walthinsen <omega@cse.ogi.edu>",
42 GType _gst_bin_type = 0;
44 static void gst_bin_dispose (GObject * object);
46 static GstElementStateReturn gst_bin_change_state (GstElement *element);
47 static GstElementStateReturn gst_bin_change_state_norecurse (GstBin *bin);
48 static gboolean gst_bin_change_state_type (GstBin *bin,
49 GstElementState state,
52 static gboolean gst_bin_iterate_func (GstBin * bin);
54 #ifndef GST_DISABLE_LOADSAVE
55 static xmlNodePtr gst_bin_save_thyself (GstObject * object, xmlNodePtr parent);
56 static void gst_bin_restore_thyself (GstObject * object, xmlNodePtr self);
59 /* Bin signals and args */
72 static void gst_bin_class_init (GstBinClass * klass);
73 static void gst_bin_init (GstBin * bin);
75 static GstElementClass *parent_class = NULL;
76 static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
79 gst_bin_get_type (void)
82 static const GTypeInfo bin_info = {
86 (GClassInitFunc) gst_bin_class_init,
91 (GInstanceInitFunc) gst_bin_init,
95 _gst_bin_type = g_type_register_static (GST_TYPE_ELEMENT, "GstBin", &bin_info, 0);
101 gst_bin_class_init (GstBinClass * klass)
103 GObjectClass *gobject_class;
104 GstObjectClass *gstobject_class;
105 GstElementClass *gstelement_class;
107 gobject_class = (GObjectClass *) klass;
108 gstobject_class = (GstObjectClass *) klass;
109 gstelement_class = (GstElementClass *) klass;
111 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
113 gst_bin_signals[OBJECT_ADDED] =
114 g_signal_new ("object_added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
115 G_STRUCT_OFFSET (GstBinClass, object_added), NULL, NULL,
116 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
118 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_bin_dispose);
120 #ifndef GST_DISABLE_LOADSAVE
121 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_bin_save_thyself);
122 gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_bin_restore_thyself);
125 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_bin_change_state);
127 klass->change_state_type = GST_DEBUG_FUNCPTR (gst_bin_change_state_type);
128 klass->iterate = GST_DEBUG_FUNCPTR (gst_bin_iterate_func);
132 gst_bin_init (GstBin * bin)
134 /* in general, we prefer to use cothreads for most things */
135 GST_FLAG_SET (bin, GST_BIN_FLAG_PREFER_COTHREADS);
137 bin->numchildren = 0;
138 bin->children = NULL;
143 * @name: name of new bin
145 * Create a new bin with given name.
150 gst_bin_new (const gchar * name)
152 return gst_elementfactory_make ("bin", name);
156 gst_bin_reset_element_sched (GstElement * element, GstScheduler * sched)
158 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "resetting element's scheduler");
160 gst_element_set_sched (element, sched);
165 gst_bin_get_clock_elements (GstBin *bin, GList **needing, GList **providing)
167 GList *children = gst_bin_get_list (bin);
170 GstElement *child = GST_ELEMENT (children->data);
172 if (GST_IS_BIN (child)) {
173 gst_bin_get_clock_elements (GST_BIN (child), needing, providing);
175 if (child->getclockfunc) {
176 *providing = g_list_prepend (*providing, child);
178 if (child->setclockfunc) {
179 *needing = g_list_prepend (*needing, child);
182 children = g_list_next (children);
187 gst_bin_distribute_clock (GstBin *bin, GList *needing, GstClock *clock)
190 GST_DEBUG (GST_CAT_CLOCK, "setting clock on %s\n", GST_ELEMENT_NAME (needing->data));
191 gst_element_set_clock (GST_ELEMENT (needing->data), clock);
193 needing = g_list_next (needing);
198 gst_bin_distribute_clocks (GstBin *bin)
200 GList *needing = NULL, *providing = NULL;
203 gst_bin_get_clock_elements (bin, &needing, &providing);
205 if (GST_FLAG_IS_SET (bin, GST_BIN_FLAG_FIXED_CLOCK)) {
208 else if (providing) {
209 clock = gst_element_get_clock (GST_ELEMENT (providing->data));
212 GST_DEBUG (GST_CAT_CLOCK, "no clock provided, using default clock\n");
213 clock = gst_system_clock_obtain ();
216 GST_BIN_CLOCK (bin) = clock;
217 gst_bin_distribute_clock (bin, needing, clock);
221 gst_bin_get_clock (GstBin *bin)
223 g_return_val_if_fail (bin != NULL, NULL);
224 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
226 return GST_BIN_CLOCK (bin);
230 gst_bin_use_clock (GstBin *bin, GstClock *clock)
232 g_return_if_fail (bin != NULL);
233 g_return_if_fail (GST_IS_BIN (bin));
235 GST_FLAG_SET (bin, GST_BIN_FLAG_FIXED_CLOCK);
236 GST_BIN_CLOCK (bin) = clock;
240 gst_bin_auto_clock (GstBin *bin)
242 g_return_if_fail (bin != NULL);
243 g_return_if_fail (GST_IS_BIN (bin));
245 GST_FLAG_UNSET (bin, GST_BIN_FLAG_FIXED_CLOCK);
246 GST_BIN_CLOCK (bin) = NULL;
250 gst_bin_set_element_sched (GstElement * element, GstScheduler * sched)
255 g_return_if_fail (element != NULL);
256 g_return_if_fail (GST_IS_ELEMENT (element));
257 g_return_if_fail (sched != NULL);
258 g_return_if_fail (GST_IS_SCHEDULER (sched));
260 GST_INFO (GST_CAT_SCHEDULING, "setting element \"%s\" sched to %p", GST_ELEMENT_NAME (element),
263 /* if it's actually a Bin */
264 if (GST_IS_BIN (element)) {
265 if (GST_FLAG_IS_SET (element, GST_BIN_FLAG_MANAGER)) {
266 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "child is already a manager, not resetting");
270 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "setting children's schedule to parent's");
271 gst_scheduler_add_element (sched, element);
273 /* set the children's schedule */
274 children = GST_BIN (element)->children;
276 child = GST_ELEMENT (children->data);
277 children = g_list_next (children);
279 gst_bin_set_element_sched (child, sched);
283 /* otherwise, if it's just a regular old element */
285 gst_scheduler_add_element (sched, element);
291 gst_bin_unset_element_sched (GstElement * element)
296 g_return_if_fail (element != NULL);
297 g_return_if_fail (GST_IS_ELEMENT (element));
299 if (GST_ELEMENT_SCHED (element) == NULL) {
300 GST_INFO (GST_CAT_SCHEDULING, "element \"%s\" has no scheduler",
301 GST_ELEMENT_NAME (element));
305 GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from it sched %p",
306 GST_ELEMENT_NAME (element), GST_ELEMENT_SCHED (element));
308 /* if it's actually a Bin */
309 if (GST_IS_BIN (element)) {
311 if (GST_FLAG_IS_SET (element, GST_BIN_FLAG_MANAGER)) {
312 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element,
313 "child is already a manager, not unsetting sched");
317 gst_scheduler_remove_element (GST_ELEMENT_SCHED (element), element);
319 /* for each child, remove them from their schedule */
320 children = GST_BIN (element)->children;
322 child = GST_ELEMENT (children->data);
323 children = g_list_next (children);
325 gst_bin_unset_element_sched (child);
329 /* otherwise, if it's just a regular old element */
331 gst_scheduler_remove_element (GST_ELEMENT_SCHED (element), element);
337 * gst_element_connect_elements_many:
338 * @element_1: the first element to add to the bin
339 * @...: NULL-terminated list of elements to add to the bin
341 * Add a list of elements to a bin. Uses #gst_bin_add.
343 /* API FIXME: this should be called gst_element_connect_many, and connect_elements
344 * should just be connect */
346 gst_bin_add_many (GstBin *bin, GstElement *element_1, ...)
350 g_return_if_fail (bin != NULL);
351 g_return_if_fail (element_1 != NULL);
352 g_return_if_fail (GST_IS_BIN (bin));
353 g_return_if_fail (GST_IS_ELEMENT (element_1));
355 va_start (args, element_1);
358 gst_bin_add (bin, element_1);
360 element_1 = va_arg (args, GstElement*);
368 * @bin: #GstBin to add element to
369 * @element: #GstElement to add to bin
371 * Add the given element to the bin. Set the elements parent, and thus
375 gst_bin_add (GstBin * bin, GstElement * element)
378 GstElementState state;
380 g_return_if_fail (bin != NULL);
381 g_return_if_fail (GST_IS_BIN (bin));
382 g_return_if_fail (element != NULL);
383 g_return_if_fail (GST_IS_ELEMENT (element));
385 GST_DEBUG (GST_CAT_PARENTAGE, "adding element \"%s\" to bin \"%s\"\n",
386 GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (bin));
388 /* must be not be in PLAYING state in order to modify bin */
389 g_return_if_fail (GST_STATE (bin) != GST_STATE_PLAYING);
391 /* the element must not already have a parent */
392 g_return_if_fail (GST_ELEMENT_PARENT (element) == NULL);
394 /* then check to see if the element's name is already taken in the bin */
395 g_return_if_fail (gst_object_check_uniqueness (bin->children, GST_ELEMENT_NAME (element)) ==
398 /* set the element's parent and add the element to the bin's list of children */
399 gst_object_set_parent (GST_OBJECT (element), GST_OBJECT (bin));
401 bin->children = g_list_append (bin->children, element);
404 /* bump our internal state counter */
405 state = GST_STATE (element);
406 while (state >>= 1) state_idx++;
407 bin->child_states[state_idx]++;
409 /* now we have to deal with manager stuff
410 * we can only do this if there's a scheduler:
411 * if we're not a manager, and aren't attached to anything, we have no sched (yet) */
412 if (GST_IS_BIN (element) && GST_FLAG_IS_SET (element, GST_BIN_FLAG_MANAGER)) {
413 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "child is a manager");
415 else if (GST_ELEMENT_SCHED (bin) != NULL) {
416 gst_bin_set_element_sched (element, GST_ELEMENT_SCHED (bin));
419 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, bin, "added child \"%s\"", GST_ELEMENT_NAME (element));
421 g_signal_emit (G_OBJECT (bin), gst_bin_signals[OBJECT_ADDED], 0, element);
426 * @bin: #GstBin to remove element from
427 * @element: #GstElement to remove
429 * Remove the element from its associated bin, unparenting as well.
432 gst_bin_remove (GstBin * bin, GstElement * element)
435 GstElementState state;
437 GST_DEBUG_ELEMENT (GST_CAT_PARENTAGE, bin, "trying to remove child %s\n", GST_ELEMENT_NAME (element));
439 g_return_if_fail (bin != NULL);
440 g_return_if_fail (GST_IS_BIN (bin));
441 g_return_if_fail (element != NULL);
442 g_return_if_fail (GST_IS_ELEMENT (element));
443 g_return_if_fail (bin->children != NULL);
445 /* must not be in PLAYING state in order to modify bin */
446 g_return_if_fail (GST_STATE (bin) != GST_STATE_PLAYING);
448 /* the element must have its parent set to the current bin */
449 g_return_if_fail (GST_ELEMENT_PARENT (element) == (GstObject *) bin);
451 /* the element must be in the bin's list of children */
452 if (g_list_find (bin->children, element) == NULL) {
453 g_warning ("no element \"%s\" in bin \"%s\"\n", GST_ELEMENT_NAME (element),
454 GST_ELEMENT_NAME (bin));
458 /* remove this element from the list of managed elements */
459 gst_bin_unset_element_sched (element);
461 /* now remove the element from the list of elements */
462 bin->children = g_list_remove (bin->children, element);
465 /* bump our internal state counter */
466 state = GST_STATE (element);
467 while (state >>= 1) state_idx++;
468 bin->child_states[state_idx]--;
470 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, bin, "removed child %s", GST_ELEMENT_NAME (element));
472 gst_object_unparent (GST_OBJECT (element));
474 /* if we're down to zero children, force state to NULL */
475 if (bin->numchildren == 0 && GST_ELEMENT_SCHED (bin) != NULL) {
476 GST_STATE_PENDING (bin) = GST_STATE_NULL;
477 gst_bin_change_state_norecurse (bin);
482 * gst_bin_child_state_change:
483 * @bin: #GstBin with the child
484 * @oldstate: The old child state
485 * @newstate: The new child state
486 * @child: #GstElement that signaled an changed state
488 * An internal function to inform the parent bin about a state change
492 gst_bin_child_state_change (GstBin *bin, GstElementState oldstate, GstElementState newstate,
495 gint old_idx = 0, new_idx = 0, i;
497 GST_INFO (GST_CAT_STATES, "child %s changed state in bin %s from %s to %s",
498 GST_ELEMENT_NAME (child), GST_ELEMENT_NAME (bin),
499 gst_element_statename (oldstate), gst_element_statename (newstate));
501 while (oldstate >>= 1) old_idx++;
502 while (newstate >>= 1) new_idx++;
505 bin->child_states[old_idx]--;
506 bin->child_states[new_idx]++;
508 for (i = GST_NUM_STATES - 1; i >= 0; i--) {
509 if (bin->child_states[i] != 0) {
510 gint state = (1 << i);
511 if (GST_STATE (bin) != state) {
512 GST_INFO (GST_CAT_STATES, "bin %s need state change to %s",
513 GST_ELEMENT_NAME (bin), gst_element_statename (state));
514 GST_STATE_PENDING (bin) = state;
515 gst_bin_change_state_norecurse (bin);
523 static GstElementStateReturn
524 gst_bin_change_state (GstElement * element)
529 GstElementStateReturn ret;
530 GstElementState old_state, pending;
532 gboolean have_async = FALSE;
534 g_return_val_if_fail (GST_IS_BIN (element), GST_STATE_FAILURE);
536 bin = GST_BIN (element);
538 old_state = GST_STATE (element);
539 pending = GST_STATE_PENDING (element);
540 transition = GST_STATE_TRANSITION (element);
542 GST_INFO_ELEMENT (GST_CAT_STATES, element, "changing childrens' state from %s to %s",
543 gst_element_statename (old_state), gst_element_statename (pending));
545 children = bin->children;
547 child = GST_ELEMENT (children->data);
548 children = g_list_next (children);
550 switch (gst_element_set_state (child, pending)) {
551 case GST_STATE_FAILURE:
552 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
553 GST_DEBUG (GST_CAT_STATES, "child '%s' failed to go to state %d(%s)\n",
554 GST_ELEMENT_NAME (child), pending, gst_element_statename (pending));
556 gst_element_set_state (child, old_state);
557 if (GST_ELEMENT_SCHED (child) == GST_ELEMENT_SCHED (element)) {
558 /* reset to what is was */
559 GST_STATE_PENDING (element) = old_state;
560 gst_bin_change_state (element);
561 return GST_STATE_FAILURE;
564 case GST_STATE_ASYNC:
565 GST_DEBUG (GST_CAT_STATES, "child '%s' is changing state asynchronously\n",
566 GST_ELEMENT_NAME (child));
572 if (GST_ELEMENT_SCHED (bin) != NULL && GST_ELEMENT_PARENT (bin) == NULL) {
573 switch (transition) {
574 case GST_STATE_NULL_TO_READY:
575 gst_bin_distribute_clocks (bin);
577 case GST_STATE_READY_TO_PAUSED:
578 if (GST_BIN_CLOCK (bin))
579 gst_clock_reset (GST_BIN_CLOCK (bin));
581 case GST_STATE_PAUSED_TO_PLAYING:
582 gst_bin_distribute_clocks (bin);
583 if (GST_BIN_CLOCK (bin))
584 gst_clock_activate (GST_BIN_CLOCK (bin), TRUE);
586 case GST_STATE_PLAYING_TO_PAUSED:
587 if (GST_BIN_CLOCK (bin))
588 gst_clock_activate (GST_BIN_CLOCK (bin), FALSE);
594 GST_INFO_ELEMENT (GST_CAT_STATES, element, "done changing bin's state from %s to %s, now in %s",
595 gst_element_statename (old_state),
596 gst_element_statename (pending),
597 gst_element_statename (GST_STATE (element)));
600 ret = GST_STATE_ASYNC;
602 ret = GST_STATE_SUCCESS;
608 static GstElementStateReturn
609 gst_bin_change_state_norecurse (GstBin * bin)
611 GstElementStateReturn ret;
613 if (GST_ELEMENT_CLASS (parent_class)->change_state) {
614 GST_DEBUG_ELEMENT (GST_CAT_STATES, bin, "setting bin's own state\n");
615 ret = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (bin));
620 return GST_STATE_FAILURE;
624 gst_bin_change_state_type (GstBin * bin, GstElementState state, GType type)
629 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
630 g_return_val_if_fail (bin->numchildren != 0, FALSE);
632 children = bin->children;
634 child = GST_ELEMENT (children->data);
635 if (GST_IS_BIN (child)) {
636 if (!gst_bin_set_state_type (GST_BIN (child), state, type))
639 else if (G_TYPE_CHECK_INSTANCE_TYPE (child, type)) {
640 if (!gst_element_set_state (child, state))
643 children = g_list_next (children);
645 if (type == GST_TYPE_BIN)
646 gst_element_set_state (GST_ELEMENT (bin), state);
652 * gst_bin_set_state_type:
653 * @bin: #GstBin to set the state
654 * @state: the new state to set the elements to
655 * @type: the type of elements to change
657 * Sets the state of only those objects of the given type.
659 * Returns: indication if the state change was successfull
662 gst_bin_set_state_type (GstBin * bin, GstElementState state, GType type)
666 GST_DEBUG (GST_CAT_STATES, "gst_bin_set_state_type(\"%s\",%d,%s)\n",
667 GST_ELEMENT_NAME (bin), state, G_OBJECT_TYPE_NAME (type));
669 g_return_val_if_fail (bin != NULL, FALSE);
670 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
672 oclass = GST_BIN_CLASS (G_OBJECT_GET_CLASS (bin));
674 if (oclass->change_state_type)
675 (oclass->change_state_type) (bin, state, type);
680 gst_bin_dispose (GObject * object)
682 GstBin *bin = GST_BIN (object);
683 GList *children, *orig;
686 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose\n");
688 if (gst_element_get_state (GST_ELEMENT (object)) == GST_STATE_PLAYING)
689 gst_element_set_state (GST_ELEMENT (object), GST_STATE_PAUSED);
692 orig = children = g_list_copy (bin->children);
694 child = GST_ELEMENT (children->data);
695 gst_bin_remove (bin, child);
696 children = g_list_next (children);
698 g_list_free (bin->children);
701 bin->children = NULL;
702 bin->numchildren = 0;
704 G_OBJECT_CLASS (parent_class)->dispose (object);
708 * gst_bin_get_by_name:
709 * @bin: #Gstbin to search
710 * @name: the element name to search for
712 * Get the element with the given name from this bin.
714 * Returns: the element with the given name
717 gst_bin_get_by_name (GstBin * bin, const gchar * name)
722 g_return_val_if_fail (bin != NULL, NULL);
723 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
724 g_return_val_if_fail (name != NULL, NULL);
726 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, bin, "looking up child element %s", name);
728 children = bin->children;
730 child = GST_ELEMENT (children->data);
731 if (!strcmp (GST_OBJECT_NAME (child), name))
733 if (GST_IS_BIN (child)) {
734 GstElement *res = gst_bin_get_by_name (GST_BIN (child), name);
739 children = g_list_next (children);
746 * gst_bin_get_by_name_recurse_up:
747 * @bin: #Gstbin to search
748 * @name: the element name to search for
750 * Get the element with the given name from this bin. If the
751 * element is not found, a recursion is performed on the parent bin.
753 * Returns: the element with the given name
756 gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
758 GstElement *result = NULL;
761 g_return_val_if_fail (bin != NULL, NULL);
762 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
763 g_return_val_if_fail (name != NULL, NULL);
765 result = gst_bin_get_by_name (bin, name);
768 parent = gst_object_get_parent (GST_OBJECT (bin));
770 if (parent && GST_IS_BIN (parent)) {
771 result = gst_bin_get_by_name_recurse_up (GST_BIN (parent), name);
780 * @bin: #Gstbin to get the list from
782 * Get the list of elements in this bin.
784 * Returns: a GList of elements
787 gst_bin_get_list (GstBin * bin)
789 g_return_val_if_fail (bin != NULL, NULL);
790 g_return_val_if_fail (GST_IS_BIN (bin), NULL);
792 return bin->children;
795 #ifndef GST_DISABLE_LOADSAVE
797 gst_bin_save_thyself (GstObject * object, xmlNodePtr parent)
799 GstBin *bin = GST_BIN (object);
800 xmlNodePtr childlist, elementnode;
804 if (GST_OBJECT_CLASS (parent_class)->save_thyself)
805 GST_OBJECT_CLASS (parent_class)->save_thyself (GST_OBJECT (bin), parent);
807 childlist = xmlNewChild (parent, NULL, "children", NULL);
809 GST_INFO_ELEMENT (GST_CAT_XML, bin, "saving %d children", bin->numchildren);
811 children = bin->children;
813 child = GST_ELEMENT (children->data);
814 elementnode = xmlNewChild (childlist, NULL, "element", NULL);
815 gst_object_save_thyself (GST_OBJECT (child), elementnode);
816 children = g_list_next (children);
822 gst_bin_restore_thyself (GstObject * object, xmlNodePtr self)
824 GstBin *bin = GST_BIN (object);
825 xmlNodePtr field = self->xmlChildrenNode;
826 xmlNodePtr childlist;
829 if (!strcmp (field->name, "children")) {
830 GST_INFO_ELEMENT (GST_CAT_XML, GST_ELEMENT (object), "loading children");
831 childlist = field->xmlChildrenNode;
833 if (!strcmp (childlist->name, "element")) {
834 GstElement *element = gst_xml_make_element (childlist, GST_OBJECT (bin));
836 /* it had to be parented to find the pads, now we ref and unparent so
837 * we can add it to the bin */
838 gst_object_ref (GST_OBJECT (element));
839 gst_object_unparent (GST_OBJECT (element));
841 gst_bin_add (bin, element);
843 childlist = childlist->next;
850 #endif /* GST_DISABLE_LOADSAVE */
853 gst_bin_iterate_func (GstBin * bin)
855 /* only iterate if this is the manager bin */
856 if (GST_ELEMENT_SCHED (bin) &&
857 GST_ELEMENT_SCHED (bin)->parent == GST_ELEMENT (bin)) {
858 GstSchedulerState state;
860 state = gst_scheduler_iterate (GST_ELEMENT_SCHED (bin));
862 if (state == GST_SCHEDULER_STATE_RUNNING) {
865 else if (state == GST_SCHEDULER_STATE_ERROR) {
866 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
870 g_warning ("bin \"%s\" can't be iterated on!\n", GST_ELEMENT_NAME (bin));
878 * @bin: #Gstbin to iterate
880 * Iterates over the elements in this bin.
882 * Returns: TRUE if the bin did something usefull. This value
883 * can be used to determine it the bin is in EOS.
886 gst_bin_iterate (GstBin * bin)
889 gboolean running = TRUE;
891 GST_DEBUG_ENTER ("(\"%s\")", GST_ELEMENT_NAME (bin));
893 g_return_val_if_fail (bin != NULL, FALSE);
894 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
896 oclass = GST_BIN_CLASS (G_OBJECT_GET_CLASS (bin));
899 running = (oclass->iterate) (bin);
901 GST_DEBUG_LEAVE ("(\"%s\") %d", GST_ELEMENT_NAME (bin), running);
904 if (GST_STATE (bin) == GST_STATE_PLAYING && GST_STATE_PENDING (bin) == GST_STATE_VOID_PENDING) {
905 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, bin,
906 "waiting for child shutdown after useless iteration\n");
907 gst_element_wait_state_change (GST_ELEMENT (bin));
908 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, bin, "child shutdown\n");