gst/gstbin.c: Use an iterator to set the clock and the index so that we can release...
authorWim Taymans <wim.taymans@gmail.com>
Mon, 5 Jan 2009 10:14:28 +0000 (10:14 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 5 Jan 2009 10:14:28 +0000 (10:14 +0000)
Original commit message from CVS:
* gst/gstbin.c: (gst_bin_set_index_func), (gst_bin_set_clock_func),
(gst_bin_change_state_func):
Use an iterator to set the clock and the index so that we can release
the object lock appropriately. Fixes #566393.

ChangeLog
gst/gstbin.c

index dc800b6..9509ad7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-01-05  Wim Taymans  <wim.taymans@collabora.co.uk>
+
+       * gst/gstbin.c: (gst_bin_set_index_func), (gst_bin_set_clock_func),
+       (gst_bin_change_state_func):
+       Use an iterator to set the clock and the index so that we can release
+       the object lock appropriately. Fixes #566393.
+
 2009-01-03  Edward Hervey  <edward.hervey@collabora.co.uk>
 
        * libs/gst/base/gstcollectpads.c: (gst_collect_pads_available):
index 94d5f9c..16b4c57 100644 (file)
@@ -624,17 +624,40 @@ static void
 gst_bin_set_index_func (GstElement * element, GstIndex * index)
 {
   GstBin *bin;
-  GList *children;
+  gboolean done;
+  GstIterator *it;
 
   bin = GST_BIN (element);
 
-  GST_OBJECT_LOCK (bin);
-  for (children = bin->children; children; children = g_list_next (children)) {
-    GstElement *child = GST_ELEMENT (children->data);
+  it = gst_bin_iterate_elements (bin);
+
+  done = FALSE;
+  while (!done) {
+    gpointer data;
+
+    switch (gst_iterator_next (it, &data)) {
+      case GST_ITERATOR_OK:
+      {
+        GstElement *child = GST_ELEMENT_CAST (data);
+
+        GST_DEBUG_OBJECT (bin, "setting index on %s", GST_ELEMENT_NAME (child));
+        gst_element_set_index (child, index);
 
-    gst_element_set_index (child, index);
+        gst_object_unref (child);
+        break;
+      }
+      case GST_ITERATOR_RESYNC:
+        GST_DEBUG_OBJECT (bin, "iterator doing resync");
+        gst_iterator_resync (it);
+        break;
+      default:
+      case GST_ITERATOR_DONE:
+        GST_DEBUG_OBJECT (bin, "iterator done");
+        done = TRUE;
+        break;
+    }
   }
-  GST_OBJECT_UNLOCK (bin);
+  gst_iterator_free (it);
 }
 
 /* set the clock on all elements in this bin
@@ -644,21 +667,42 @@ gst_bin_set_index_func (GstElement * element, GstIndex * index)
 static gboolean
 gst_bin_set_clock_func (GstElement * element, GstClock * clock)
 {
-  GList *children;
   GstBin *bin;
+  gboolean done;
+  GstIterator *it;
   gboolean res = TRUE;
 
   bin = GST_BIN (element);
 
-  GST_OBJECT_LOCK (bin);
-  if (element->clock != clock) {
-    for (children = bin->children; children; children = g_list_next (children)) {
-      GstElement *child = GST_ELEMENT (children->data);
+  it = gst_bin_iterate_elements (bin);
+
+  done = FALSE;
+  while (!done) {
+    gpointer data;
+
+    switch (gst_iterator_next (it, &data)) {
+      case GST_ITERATOR_OK:
+      {
+        GstElement *child = GST_ELEMENT_CAST (data);
+
+        res &= gst_element_set_clock (child, clock);
 
-      res &= gst_element_set_clock (child, clock);
+        gst_object_unref (child);
+        break;
+      }
+      case GST_ITERATOR_RESYNC:
+        GST_DEBUG_OBJECT (bin, "iterator doing resync");
+        gst_iterator_resync (it);
+        res = TRUE;
+        break;
+      default:
+      case GST_ITERATOR_DONE:
+        GST_DEBUG_OBJECT (bin, "iterator done");
+        done = TRUE;
+        break;
     }
   }
-  GST_OBJECT_UNLOCK (bin);
+  gst_iterator_free (it);
 
   return res;
 }