decodebin2: remove leftover elements
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 27 May 2009 16:12:10 +0000 (18:12 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 27 May 2009 16:12:10 +0000 (18:12 +0200)
Remove all of the elements inside decodebin2 when goint to READY and NULL.
Makes decodebin2 reusable.
Fixes #583750

gst/playback/gstdecodebin2.c

index d63cb65..6ff9223 100644 (file)
@@ -663,6 +663,10 @@ static void
 gst_decode_bin_remove_groups (GstDecodeBin * dbin)
 {
   GList *tmp;
+  GstIterator *it;
+  gpointer point;
+  gboolean done;
+  GstIteratorResult res;
 
   GST_DEBUG_OBJECT (dbin, "cleaning up");
 
@@ -690,6 +694,44 @@ gst_decode_bin_remove_groups (GstDecodeBin * dbin)
   }
   g_list_free (dbin->oldgroups);
   dbin->oldgroups = NULL;
+
+  GST_DEBUG_OBJECT (dbin, "removing last elements");
+
+  /* remove all remaining elements */
+  it = gst_bin_iterate_elements (GST_BIN_CAST (dbin));
+restart:
+  done = FALSE;
+  while (!done) {
+    res = gst_iterator_next (it, &point);
+    switch (res) {
+      case GST_ITERATOR_DONE:
+        done = TRUE;
+        break;
+      case GST_ITERATOR_RESYNC:
+        gst_iterator_resync (it);
+        goto restart;
+      case GST_ITERATOR_ERROR:
+        GST_WARNING_OBJECT (dbin,
+            "Had an error while iterating bin %s", GST_ELEMENT_NAME (dbin));
+        done = TRUE;
+        break;
+      case GST_ITERATOR_OK:
+      {
+        GstElement *elem = GST_ELEMENT_CAST (point);
+
+        /* don't remove the typefind element */
+        if (elem != dbin->typefind) {
+          GST_DEBUG_OBJECT (dbin, "remove element %s", GST_ELEMENT_NAME (elem));
+          gst_bin_remove (GST_BIN_CAST (dbin), elem);
+          gst_element_set_state (elem, GST_STATE_NULL);
+        }
+        gst_object_unref (elem);
+        break;
+      }
+      default:
+        break;
+    }
+  }
 }
 
 static void