Reparented everything to GstElement, removing GstSrc, GstSink, GstFilter, and GstConn...
[platform/upstream/gstreamer.git] / gst / gstbin.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstbin.c: GstBin container object and support code
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 //#define GST_DEBUG_ENABLED
24 #include "gst_private.h"
25
26 #include "gstbin.h"
27
28 #include "gstscheduler.h"
29
30
31 GstElementDetails gst_bin_details = { 
32   "Generic bin",
33   "Bin",
34   "Simple container object",
35   VERSION,
36   "Erik Walthinsen <omega@cse.ogi.edu>",
37   "(C) 1999",
38 };
39
40
41 static void                     gst_bin_real_destroy            (GtkObject *object);
42
43 static GstElementStateReturn    gst_bin_change_state            (GstElement *element);
44 static GstElementStateReturn    gst_bin_change_state_norecurse  (GstBin *bin);
45 static gboolean                 gst_bin_change_state_type       (GstBin *bin,
46                                                                  GstElementState state,
47                                                                  GtkType type);
48
49 static void                     gst_bin_create_plan_func        (GstBin *bin);
50 static void                     gst_bin_iterate_func            (GstBin *bin);
51
52 static xmlNodePtr               gst_bin_save_thyself            (GstElement *element, xmlNodePtr parent);
53 static void                     gst_bin_restore_thyself         (GstElement *element, xmlNodePtr parent, 
54                                                                  GHashTable *elements);
55
56 /* Bin signals and args */
57 enum {
58   OBJECT_ADDED,
59   LAST_SIGNAL
60 };
61
62 enum {
63   ARG_0,
64   /* FILL ME */
65 };
66
67
68 static void gst_bin_class_init  (GstBinClass *klass);
69 static void gst_bin_init        (GstBin *bin);
70
71
72 static GstElementClass *parent_class = NULL;
73 static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
74
75 GtkType
76 gst_bin_get_type (void) 
77 {
78   static GtkType bin_type = 0;
79
80   if (!bin_type) {
81     static const GtkTypeInfo bin_info = {
82       "GstBin",
83       sizeof(GstBin),
84       sizeof(GstBinClass),
85       (GtkClassInitFunc)gst_bin_class_init,
86       (GtkObjectInitFunc)gst_bin_init,
87       (GtkArgSetFunc)NULL,
88       (GtkArgGetFunc)NULL,
89       (GtkClassInitFunc)NULL,
90     };
91     bin_type = gtk_type_unique (GST_TYPE_ELEMENT, &bin_info);
92   }
93   return bin_type;
94 }
95
96 static void
97 gst_bin_class_init (GstBinClass *klass) 
98 {
99   GtkObjectClass *gtkobject_class;
100   GstElementClass *gstelement_class;
101
102   gtkobject_class = (GtkObjectClass*)klass;
103   gstelement_class = (GstElementClass*)klass;
104
105   parent_class = gtk_type_class (GST_TYPE_ELEMENT);
106
107   gst_bin_signals[OBJECT_ADDED] =
108     gtk_signal_new ("object_added", GTK_RUN_FIRST, gtkobject_class->type,
109                     GTK_SIGNAL_OFFSET (GstBinClass, object_added),
110                     gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1,
111                     GST_TYPE_ELEMENT);
112   gtk_object_class_add_signals (gtkobject_class, gst_bin_signals, LAST_SIGNAL);
113
114   klass->change_state_type =            gst_bin_change_state_type;
115   klass->create_plan =                  gst_bin_create_plan_func;
116   klass->schedule =                     gst_bin_schedule_func;
117   klass->iterate =                      gst_bin_iterate_func;
118
119   gstelement_class->change_state =      gst_bin_change_state;
120   gstelement_class->save_thyself =      gst_bin_save_thyself;
121   gstelement_class->restore_thyself =   gst_bin_restore_thyself;
122
123   gtkobject_class->destroy =            gst_bin_real_destroy;
124 }
125
126 static void 
127 gst_bin_init (GstBin *bin) 
128 {
129   // in general, we prefer to use cothreads for most things
130   GST_FLAG_SET (bin, GST_BIN_FLAG_PREFER_COTHREADS);
131
132   bin->numchildren = 0;
133   bin->children = NULL;
134   bin->chains = NULL;
135 // FIXME temporary testing measure
136 //  bin->use_cothreads = TRUE;
137 }
138
139 /**
140  * gst_bin_new:
141  * @name: name of new bin
142  *
143  * Create a new bin with given name.
144  *
145  * Returns: new bin
146  */
147 GstElement*
148 gst_bin_new (gchar *name) 
149 {
150   return gst_elementfactory_make ("bin", name);
151 }
152
153 /**
154  * gst_bin_add:
155  * @bin: #GstBin to add element to
156  * @element: #GstElement to add to bin
157  *
158  * Add the given element to the bin.  Set the elements parent, and thus
159  * add a reference.
160  */
161 void 
162 gst_bin_add (GstBin *bin, 
163              GstElement *element) 
164 {
165   g_return_if_fail (bin != NULL);
166   g_return_if_fail (GST_IS_BIN (bin));
167   g_return_if_fail (element != NULL);
168   g_return_if_fail (GST_IS_ELEMENT (element));
169
170   // must be NULL or PAUSED state in order to modify bin
171   g_return_if_fail ((GST_STATE (bin) == GST_STATE_NULL) ||
172                     (GST_STATE (bin) == GST_STATE_PAUSED));
173
174   bin->children = g_list_append (bin->children, element);
175   bin->numchildren++;
176   gst_object_set_parent (GST_OBJECT (element), GST_OBJECT (bin));
177
178   /* we know we have at least one child, we just added one... */
179 //  if (GST_STATE(element) < GST_STATE_READY)
180 //    gst_bin_change_state_norecurse(bin,GST_STATE_READY);
181
182   gtk_signal_emit (GTK_OBJECT (bin), gst_bin_signals[OBJECT_ADDED], element);
183 }
184
185 /**
186  * gst_bin_remove:
187  * @bin: #GstBin to remove element from
188  * @element: #GstElement to remove
189  *
190  * Remove the element from its associated bin, unparenting as well.
191  */
192 void 
193 gst_bin_remove (GstBin *bin,
194                 GstElement *element) 
195 {
196   g_return_if_fail (bin != NULL);
197   g_return_if_fail (GST_IS_BIN (bin));
198   g_return_if_fail (element != NULL);
199   g_return_if_fail (GST_IS_ELEMENT (element));
200   g_return_if_fail (bin->children != NULL);
201
202   // must be NULL or PAUSED state in order to modify bin
203   g_return_if_fail ((GST_STATE (bin) == GST_STATE_NULL) ||
204                     (GST_STATE (bin) == GST_STATE_PAUSED));
205
206   gst_object_unparent (GST_OBJECT (element));
207   bin->children = g_list_remove (bin->children, element);
208   bin->numchildren--;
209
210   /* if we're down to zero children, force state to NULL */
211   if (bin->numchildren == 0)
212     gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
213 }
214
215
216 static GstElementStateReturn 
217 gst_bin_change_state (GstElement *element) 
218 {
219   GstBin *bin;
220   GList *children;
221   GstElement *child;
222
223   DEBUG_ENTER("(\"%s\")",gst_element_get_name (element));
224
225   g_return_val_if_fail (GST_IS_BIN (element), GST_STATE_FAILURE);
226
227   bin = GST_BIN (element);
228
229   DEBUG("currently %d(%s), %d(%s) pending\n", GST_STATE (element),
230           _gst_print_statename (GST_STATE (element)), GST_STATE_PENDING (element),
231           _gst_print_statename (GST_STATE_PENDING (element)));
232
233 //  g_return_val_if_fail(bin->numchildren != 0, GST_STATE_FAILURE);
234
235 //  g_print("-->\n");
236   children = bin->children;
237   while (children) {
238     child = GST_ELEMENT (children->data);
239     DEBUG("setting state on '%s'\n",gst_element_get_name (child));
240     switch (gst_element_set_state (child, GST_STATE_PENDING (element))) {
241       case GST_STATE_FAILURE:
242         GST_STATE_PENDING (element) = GST_STATE_NONE_PENDING;
243         DEBUG("child '%s' failed to go to state %d(%s)\n", gst_element_get_name (child),
244               GST_STATE_PENDING (element), _gst_print_statename (GST_STATE_PENDING (element)));
245         return GST_STATE_FAILURE;
246         break;
247       case GST_STATE_ASYNC:
248         DEBUG("child '%s' is changing state asynchronously\n", gst_element_get_name (child));
249         break;
250     }
251 //    g_print("\n");
252     children = g_list_next (children);
253   }
254 //  g_print("<-- \"%s\"\n",gst_object_get_name(GST_OBJECT(bin)));
255
256   switch (GST_STATE_TRANSITION (element)) {
257     case GST_STATE_NULL_TO_READY:         
258     {
259       GstObject *parent;
260
261       parent = gst_object_get_parent (GST_OBJECT (element));
262
263       if (!parent || !GST_IS_BIN (parent))
264         gst_bin_create_plan (bin);
265
266       break;
267     }
268     default:
269       break;
270   }
271
272   return gst_bin_change_state_norecurse (bin);
273 }
274
275
276 static GstElementStateReturn 
277 gst_bin_change_state_norecurse (GstBin *bin) 
278 {
279
280   if (GST_ELEMENT_CLASS (parent_class)->change_state)
281     return GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (bin));
282   else
283     return GST_STATE_FAILURE;
284 }
285
286 static gboolean 
287 gst_bin_change_state_type(GstBin *bin,
288                           GstElementState state,
289                           GtkType type) 
290 {
291   GList *children;
292   GstElement *child;
293
294 //  g_print("gst_bin_change_state_type(\"%s\",%d,%d);\n",
295 //          gst_object_get_name(GST_OBJECT(bin)),state,type);
296
297   g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
298   g_return_val_if_fail (bin->numchildren != 0, FALSE);
299
300 //  g_print("-->\n");
301   children = bin->children;
302   while (children) {
303     child = GST_ELEMENT (children->data);
304     if (GST_IS_BIN (child)) {
305       if (!gst_bin_set_state_type (GST_BIN (child), state,type))
306         return FALSE;
307     } else if (GTK_CHECK_TYPE (child,type)) {
308       if (!gst_element_set_state (child,state))
309         return FALSE;
310     }
311 //    g_print("\n");
312     children = g_list_next (children);
313   }
314   if (type == GST_TYPE_BIN)
315     gst_element_set_state (GST_ELEMENT (bin),state);
316
317   return TRUE;
318 }
319
320 /**
321  * gst_bin_set_state_type:
322  * @bin: #GstBin to set the state
323  * @state: the new state to set the elements to
324  * @type: the type of elements to change
325  *
326  * Sets the state of only those objects of the given type.
327  *
328  * Returns: indication if the state change was successfull
329  */
330 gboolean 
331 gst_bin_set_state_type (GstBin *bin,
332                         GstElementState state,
333                         GtkType type) 
334 {
335   GstBinClass *oclass;
336
337   DEBUG("gst_bin_set_state_type(\"%s\",%d,%d)\n",
338           gst_element_get_name (GST_ELEMENT (bin)), state,type);
339
340   g_return_val_if_fail (bin != NULL, FALSE);
341   g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
342
343   oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
344
345   if (oclass->change_state_type)
346     (oclass->change_state_type) (bin,state,type);
347   return TRUE;
348 }
349
350 static void 
351 gst_bin_real_destroy (GtkObject *object) 
352 {
353   GstBin *bin = GST_BIN (object);
354   GList *children;
355   GstElement *child;
356
357   DEBUG("in gst_bin_real_destroy()\n");
358
359   children = bin->children;
360   while (children) {
361     child = GST_ELEMENT (children->data);
362     gst_element_destroy (child);
363     children = g_list_next (children);
364   }
365
366   g_list_free (bin->children);
367 }
368
369 /**
370  * gst_bin_get_by_name:
371  * @bin: #Gstbin to search
372  * @name: the element name to search for
373  *
374  * get the element with the given name from this bin
375  *
376  * Returns: the element with the given name
377  */
378 GstElement*
379 gst_bin_get_by_name (GstBin *bin,
380                      gchar *name) 
381 {
382   GList *children;
383   GstElement *child;
384
385   g_return_val_if_fail (bin != NULL, NULL);
386   g_return_val_if_fail (GST_IS_BIN (bin), NULL);
387   g_return_val_if_fail (name != NULL, NULL);
388
389   g_print("gstbin: lookup element \"%s\" in \"%s\"\n", name, 
390                   gst_element_get_name (GST_ELEMENT (bin)));
391   
392   children = bin->children;
393   while (children) {
394     child = GST_ELEMENT (children->data);
395     if (!strcmp (child->name,name))
396       return child;
397     if (GST_IS_BIN (child)) {
398       GstElement *res = gst_bin_get_by_name (GST_BIN (child), name);
399       if (res) 
400         return res;
401     }
402     children = g_list_next (children);
403   }
404
405   return NULL;
406 }
407
408 /**
409  * gst_bin_get_list:
410  * @bin: #Gstbin to get the list from
411  *
412  * get the list of elements in this bin
413  *
414  * Returns: a GList of elements
415  */
416 GList*
417 gst_bin_get_list (GstBin *bin) 
418 {
419   g_return_val_if_fail (bin != NULL, NULL);
420   g_return_val_if_fail (GST_IS_BIN (bin), NULL);
421
422   return bin->children;
423 }
424
425 static xmlNodePtr 
426 gst_bin_save_thyself (GstElement *element, 
427                       xmlNodePtr parent) 
428 {
429   GstBin *bin = GST_BIN (element);
430   xmlNodePtr childlist;
431   GList *children;
432   GstElement *child;
433
434   if (GST_ELEMENT_CLASS (parent_class)->save_thyself)
435     GST_ELEMENT_CLASS (parent_class)->save_thyself (GST_ELEMENT (bin), parent);
436
437   childlist = xmlNewChild (parent,NULL,"children",NULL);
438
439   children = bin->children;
440   while (children) {
441     child = GST_ELEMENT (children->data);
442     gst_element_save_thyself (child, childlist);
443     children = g_list_next (children);
444   }
445   return childlist;
446 }
447
448 static void 
449 gst_bin_restore_thyself (GstElement *element, 
450                          xmlNodePtr parent, 
451                          GHashTable *elements) 
452 {
453   GstBin *bin = GST_BIN (element);
454   xmlNodePtr field = parent->childs;
455   xmlNodePtr childlist;
456
457   g_print("gstbin: restore \"%s\"\n", gst_element_get_name (element));
458
459   while (field) {
460     if (!strcmp (field->name, "children")) {
461       childlist = field->childs;
462       while (childlist) {
463         if (!strcmp (childlist->name, "element")) {
464           GstElement *element = gst_element_load_thyself (childlist, elements);
465
466           gst_bin_add (bin, element);
467         }
468         childlist = childlist->next;
469       }
470     }
471
472     field = field->next;
473   }
474   
475 }
476
477 void 
478 gst_bin_use_cothreads (GstBin *bin, 
479                        gboolean enabled) 
480 {
481   g_return_if_fail (GST_IS_BIN (bin));
482
483   bin->use_cothreads = enabled;
484 }
485
486 /**
487  * gst_bin_iterate:
488  * @bin: #Gstbin to iterate
489  *
490  * iterates over the elements in this bin
491  */
492 void 
493 gst_bin_iterate (GstBin *bin) 
494 {
495   GstBinClass *oclass;
496
497   DEBUG_ENTER("(\"%s\")",gst_element_get_name(GST_ELEMENT(bin)));
498
499   oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
500   
501   if (oclass->iterate)
502     (oclass->iterate) (bin);
503
504   DEBUG_LEAVE("(\"%s\")",gst_element_get_name(GST_ELEMENT(bin)));
505 }
506
507 /**
508  * gst_bin_create_plan:
509  * @bin: #GstBin to create the plan for
510  *
511  * let the bin figure out how to handle the plugins in it.
512  */
513 void 
514 gst_bin_create_plan (GstBin *bin) 
515 {
516   GstBinClass *oclass;
517
518   oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
519
520   if (oclass->create_plan)
521     (oclass->create_plan) (bin);
522 }
523
524 /**
525  * gst_bin_schedule:
526  * @bin: #GstBin to schedule
527  *
528  * let the bin figure out how to handle the plugins in it.
529  */
530 void 
531 gst_bin_schedule (GstBin *bin) 
532 {
533   GstBinClass *oclass;
534
535   oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
536
537   if (oclass->schedule)
538     (oclass->schedule) (bin);
539 }
540
541 typedef struct {
542   gulong offset;
543   gulong size;
544 } region_struct; 
545
546
547 static void
548 gst_bin_create_plan_func (GstBin *bin) 
549 {
550   GstElement *manager;
551   GList *elements;
552   GstElement *element;
553   const gchar *elementname;
554   GSList *pending = NULL;
555   GstBin *pending_bin;
556
557   DEBUG_SET_STRING("(\"%s\")",gst_element_get_name (GST_ELEMENT (bin)));
558   DEBUG_ENTER_STRING;
559
560   // first figure out which element is the manager of this and all child elements
561   // if we're a managing bin ourselves, that'd be us
562   if (GST_FLAG_IS_SET (bin, GST_BIN_FLAG_MANAGER)) {
563     manager = GST_ELEMENT (bin);
564     DEBUG("setting manager to self\n");
565   // otherwise, it's what our parent says it is
566   } else {
567     manager = gst_element_get_manager (GST_ELEMENT (bin));
568     if (!manager) {
569       DEBUG("manager not set for element \"%s\" assuming manager is self\n", gst_element_get_name (GST_ELEMENT (bin)));
570       manager = GST_ELEMENT (bin);
571       GST_FLAG_SET (bin, GST_BIN_FLAG_MANAGER);
572     }
573     DEBUG("setting manager to \"%s\"\n", gst_element_get_name (manager));
574   }
575
576   // perform the first recursive pass of plan generation
577   // we set the manager of every element but those who manage themselves
578   // the need for cothreads is also determined recursively
579   DEBUG("performing first-phase recursion\n");
580   bin->need_cothreads = bin->use_cothreads;
581   if (bin->need_cothreads)
582     DEBUG("requiring cothreads because we're forced to\n");
583
584   elements = bin->children;
585   while (elements) {
586     element = GST_ELEMENT (elements->data);
587     elements = g_list_next (elements);
588 #ifdef GST_DEBUG_ENABLED
589     elementname = gst_element_get_name (element);
590 #endif
591     DEBUG("have element \"%s\"\n",elementname);
592
593     // first set their manager
594     DEBUG("setting manager of \"%s\" to \"%s\"\n",elementname,gst_element_get_name(manager));
595     gst_element_set_manager (element, manager);
596
597     // we do recursion and such for Bins
598     if (GST_IS_BIN (element)) {
599       // recurse into the child Bin
600       DEBUG("recursing into child Bin \"%s\"\n",elementname);
601       gst_bin_create_plan (GST_BIN (element));
602       // check to see if it needs cothreads and isn't self-managing
603       if (((GST_BIN (element))->need_cothreads) && !GST_FLAG_IS_SET(element,GST_BIN_FLAG_MANAGER)) {
604         DEBUG("requiring cothreads because child bin \"%s\" does\n",elementname);
605         bin->need_cothreads = TRUE;
606       }
607     } else {
608       // then we need to determine whether they need cothreads
609       // if it's a loop-based element, use cothreads
610       if (element->loopfunc != NULL) {
611         DEBUG("requiring cothreads because \"%s\" is a loop-based element\n",elementname);
612         GST_FLAG_SET (element, GST_ELEMENT_USE_COTHREAD);
613       // if it's a 'complex' element, use cothreads
614       } else if (GST_FLAG_IS_SET (element, GST_ELEMENT_COMPLEX)) {
615         DEBUG("requiring cothreads because \"%s\" is complex\n",elementname);
616         GST_FLAG_SET (element, GST_ELEMENT_USE_COTHREAD);
617       // if the element has more than one sink pad, use cothreads
618       } else if (element->numsinkpads > 1) {
619         DEBUG("requiring cothreads because \"%s\" has more than one sink pad\n",elementname);
620         GST_FLAG_SET (element, GST_ELEMENT_USE_COTHREAD);
621       }
622       if (GST_FLAG_IS_SET (element, GST_ELEMENT_USE_COTHREAD))
623         bin->need_cothreads = TRUE;
624     }
625   }
626
627
628   // if we're not a manager thread, we're done.
629   if (!GST_FLAG_IS_SET (bin, GST_BIN_FLAG_MANAGER)) {
630     DEBUG_LEAVE("(\"%s\")",gst_element_get_name(GST_ELEMENT(bin)));
631     return;
632   }
633
634   // clear previous plan state
635   g_list_free (bin->managed_elements);
636   bin->managed_elements = NULL;
637   bin->num_managed_elements = 0;
638
639   // find all the managed children
640   // here we pull off the trick of walking an entire arbitrary tree without recursion
641   DEBUG("attempting to find all the elements to manage\n");
642   pending = g_slist_prepend (pending, bin);
643   do {
644     // retrieve the top of the stack and pop it
645     pending_bin = GST_BIN (pending->data);
646     pending = g_slist_remove (pending, pending_bin);
647
648     // walk the list of elements, find bins, and do stuff
649     DEBUG("checking Bin \"%s\" for managed elements\n",
650           gst_element_get_name (GST_ELEMENT (pending_bin)));
651     elements = pending_bin->children;
652     while (elements) {
653       element = GST_ELEMENT (elements->data);
654       elements = g_list_next (elements);
655 #ifdef GST_DEBUG_ENABLED
656       elementname = gst_element_get_name (element);
657 #endif
658
659       // if it's ours, add it to the list
660       if (element->manager == GST_ELEMENT(bin)) {
661         // if it's a Bin, add it to the list of Bins to check
662         if (GST_IS_BIN (element)) {
663           DEBUG("flattened recurse into \"%s\"\n",elementname);
664           pending = g_slist_prepend (pending, element);
665         // otherwise add it to the list of elements
666         } else {
667           DEBUG("found element \"%s\" that I manage\n",elementname);
668           bin->managed_elements = g_list_prepend (bin->managed_elements, element);
669           bin->num_managed_elements++;
670         }
671       }
672     }
673   } while (pending);
674
675   DEBUG("have %d elements to manage, implementing plan\n",bin->num_managed_elements);
676
677   gst_bin_schedule(bin);
678
679   DEBUG_LEAVE("(\"%s\")",gst_element_get_name(GST_ELEMENT(bin)));
680 }
681
682 static void 
683 gst_bin_iterate_func (GstBin *bin) 
684 {
685   GList *chains;
686   _GstBinChain *chain;
687   GList *entries;
688   GstElement *entry;
689   GList *pads;
690   GstPad *pad;
691   GstBuffer *buf;
692
693   DEBUG_SET_STRING("(\"%s\")", gst_element_get_name (GST_ELEMENT (bin)));
694   DEBUG_ENTER_STRING;
695
696   g_return_if_fail (bin != NULL);
697   g_return_if_fail (GST_IS_BIN (bin));
698   g_return_if_fail (GST_STATE (bin) == GST_STATE_PLAYING);
699
700   // step through all the chains
701   chains = bin->chains;
702   while (chains) {
703     chain = (_GstBinChain *)(chains->data);
704     chains = g_list_next (chains);
705
706     if (chain->need_cothreads) {
707       // all we really have to do is switch to the first child
708       // FIXME this should be lots more intelligent about where to start
709       DEBUG("starting iteration via cothreads\n");
710
711       entry = GST_ELEMENT (chain->elements->data);
712       GST_FLAG_SET (entry, GST_ELEMENT_COTHREAD_STOPPING);
713       DEBUG("set COTHREAD_STOPPING flag on \"%s\"(@%p)\n",
714             gst_element_get_name(entry),entry);
715       cothread_switch (entry->threadstate);
716
717     } else {
718       DEBUG("starting iteration via chain-functions\n");
719
720       entries = chain->entries;
721
722       g_assert (entries != NULL);
723
724       while (entries) {
725         entry = GST_ELEMENT (entries->data);
726         entries = g_list_next (entries);
727
728         DEBUG("have entry \"%s\"\n",gst_element_get_name(entry));
729
730         if (GST_IS_BIN (entry)) {
731           gst_bin_iterate (GST_BIN (entry));
732         } else {
733           pads = entry->pads;
734           while (pads) {
735             pad = GST_PAD (pads->data);
736             if (pad->direction == GST_PAD_SRC) {
737               DEBUG("calling getfunc of %s:%s\n",GST_DEBUG_PAD_NAME(pad));
738               if (pad->getfunc == NULL) 
739                 fprintf(stderr, "error, no getfunc in \"%s\"\n", gst_element_get_name (entry));
740               else
741                 buf = (pad->getfunc)(pad);
742               gst_pad_push(pad,buf);
743             }
744             pads = g_list_next (pads);
745           }
746         }
747       }
748     }
749   }
750
751   DEBUG_LEAVE("(%s)", gst_element_get_name (GST_ELEMENT (bin)));
752 }