gnloperation: Totally clear operations when removing emptying current_bin
authorThibault Saunier <tsaunier@gnome.org>
Wed, 9 Jul 2014 10:51:36 +0000 (12:51 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Fri, 31 Oct 2014 10:58:09 +0000 (11:58 +0100)
Removing linked childre leads to weird behaviour, we want to make sure
that all elements are totally clean when they are out the current bin.

Co-Authored by: Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>

gnl/gnlcomposition.c
gnl/gnlobject.c
gnl/gnlobject.h
gnl/gnloperation.c
gnl/gnloperation.h

index 01af430..ef7dfa7 100644 (file)
@@ -1073,6 +1073,10 @@ _remove_child (GValue * item, GValue * ret G_GNUC_UNUSED, GstBin * bin)
 {
   GstElement *child = g_value_get_object (item);
 
+  if (GNL_IS_OPERATION (child))
+    gnl_operation_hard_cleanup (GNL_OPERATION (child));
+
+
   gst_bin_remove (bin, child);
 
   return TRUE;
index a6e3b69..2f01d0c 100644 (file)
@@ -418,7 +418,7 @@ gnl_object_cleanup_func (GnlObject * object)
   return TRUE;
 }
 
-static GstStateChangeReturn
+GstStateChangeReturn
 gnl_object_cleanup (GnlObject * object)
 {
   GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
index 450f5d9..b43e44c 100644 (file)
@@ -166,5 +166,9 @@ gnl_object_commit (GnlObject *object, gboolean recurse);
 
 void
 gnl_object_reset (GnlObject *object);
+
+GstStateChangeReturn
+gnl_object_cleanup (GnlObject * object);
+
 G_END_DECLS
 #endif /* __GNL_OBJECT_H__ */
index 77c8f6c..480c70f 100644 (file)
@@ -728,6 +728,45 @@ gnl_operation_cleanup (GnlObject * object)
   return TRUE;
 }
 
+void
+gnl_operation_hard_cleanup (GnlOperation * operation)
+{
+  gboolean done = FALSE;
+
+  GValue item = { 0, };
+  GstIterator *pads;
+
+  GST_INFO_OBJECT (operation, "Hard reset of the operation");
+
+  pads = gst_element_iterate_sink_pads (GST_ELEMENT (operation));
+  while (!done) {
+    switch (gst_iterator_next (pads, &item)) {
+      case GST_ITERATOR_OK:
+      {
+        GstPad *sinkpad = g_value_get_object (&item);
+        GstPad *srcpad = gst_pad_get_peer (sinkpad);
+
+        if (srcpad) {
+          GST_ERROR ("Unlinking %" GST_PTR_FORMAT " and  %"
+              GST_PTR_FORMAT, srcpad, sinkpad);
+          gst_pad_unlink (srcpad, sinkpad);
+        }
+
+        g_value_reset (&item);
+        break;
+      }
+      case GST_ITERATOR_RESYNC:
+        gst_iterator_resync (pads);
+        break;
+      default:
+        /* ERROR and DONE */
+        done = TRUE;
+        break;
+    }
+  }
+  gnl_object_cleanup (GNL_OBJECT (operation));
+}
+
 
 static GstPad *
 gnl_operation_request_new_pad (GstElement * element, GstPadTemplate * templ,
index 52ed82a..d26d315 100644 (file)
@@ -80,6 +80,8 @@ gnl_operation_signal_input_priority_changed(GnlOperation * operation, GstPad *pa
 void gnl_operation_update_base_time (GnlOperation *operation,
                                      GstClockTime timestamp);
 
+void gnl_operation_hard_cleanup (GnlOperation *operation);
+
 
 /* normal GOperation stuff */
 GType gnl_operation_get_type (void);