From 96672825d5ac604d95aca1cac2b0a5dca6c84523 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 9 Jul 2014 12:51:36 +0200 Subject: [PATCH] gnloperation: Totally clear operations when removing emptying current_bin 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 --- gnl/gnlcomposition.c | 4 ++++ gnl/gnlobject.c | 2 +- gnl/gnlobject.h | 4 ++++ gnl/gnloperation.c | 39 +++++++++++++++++++++++++++++++++++++++ gnl/gnloperation.h | 2 ++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/gnl/gnlcomposition.c b/gnl/gnlcomposition.c index 01af430..ef7dfa7 100644 --- a/gnl/gnlcomposition.c +++ b/gnl/gnlcomposition.c @@ -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; diff --git a/gnl/gnlobject.c b/gnl/gnlobject.c index a6e3b69..2f01d0c 100644 --- a/gnl/gnlobject.c +++ b/gnl/gnlobject.c @@ -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; diff --git a/gnl/gnlobject.h b/gnl/gnlobject.h index 450f5d9..b43e44c 100644 --- a/gnl/gnlobject.h +++ b/gnl/gnlobject.h @@ -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__ */ diff --git a/gnl/gnloperation.c b/gnl/gnloperation.c index 77c8f6c..480c70f 100644 --- a/gnl/gnloperation.c +++ b/gnl/gnloperation.c @@ -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, diff --git a/gnl/gnloperation.h b/gnl/gnloperation.h index 52ed82a..d26d315 100644 --- a/gnl/gnloperation.h +++ b/gnl/gnloperation.h @@ -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); -- 2.7.4