summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivia Nikolaidou <vivia@ahiru.eu>2015-02-23 20:27:32 +0200
committerSebastian Dröge <sebastian@centricular.com>2015-03-13 12:50:48 +0000
commit6ec3c4bc66cbbefa6e5811874d9787d675c807ee (patch)
tree0b9a7911cc21e9841b5a8423ffbfcb9fb99e108a
parent3da3e8df3e50d4cef1d0198aa620a9e78367d7f8 (diff)
utils: Add gst_bin_sync_children_states()
gst_bin_sync_children_states() will iterate over all the elements of a bin and sync their states with the state of the bin. This is useful when adding many elements to a bin and would otherwise have to call gst_element_sync_state_with_parent() on each and every one of them. https://bugzilla.gnome.org/show_bug.cgi?id=745042
-rw-r--r--docs/gst/gstreamer-sections.txt1
-rw-r--r--gst/gstutils.c52
-rw-r--r--gst/gstutils.h2
-rw-r--r--win32/common/libgstreamer.def1
4 files changed, 56 insertions, 0 deletions
diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt
index f1a5f9e4f..9ebcb8c7d 100644
--- a/docs/gst/gstreamer-sections.txt
+++ b/docs/gst/gstreamer-sections.txt
@@ -87,6 +87,7 @@ gst_bin_recalculate_latency
gst_bin_add_many
gst_bin_remove_many
gst_bin_find_unlinked_pad
+gst_bin_sync_children_states
<SUBSECTION>
GstBinFlags
diff --git a/gst/gstutils.c b/gst/gstutils.c
index 2d7d23cce..e00f8e8e0 100644
--- a/gst/gstutils.c
+++ b/gst/gstutils.c
@@ -3068,6 +3068,58 @@ gst_bin_find_unlinked_pad (GstBin * bin, GstPadDirection direction)
return pad;
}
+static void
+gst_bin_sync_children_states_foreach (const GValue * value, gpointer user_data)
+{
+ gboolean *success = user_data;
+ GstElement *element = g_value_get_object (value);
+
+ if (gst_element_is_locked_state (element)) {
+ *success = TRUE;
+ } else {
+ *success = *success && gst_element_sync_state_with_parent (element);
+
+ if (GST_IS_BIN (element))
+ *success = *success
+ && gst_bin_sync_children_states (GST_BIN_CAST (element));
+ }
+}
+
+/**
+ * gst_bin_sync_children_states:
+ * @bin: a #GstBin
+ *
+ * Synchronizes the state of every child of @bin with the state
+ * of @bin. See also gst_element_sync_state_with_parent().
+ *
+ * Returns: %TRUE if syncing the state was successful for all children,
+ * otherwise %FALSE.
+ *
+ * Since: 1.6
+ */
+gboolean
+gst_bin_sync_children_states (GstBin * bin)
+{
+ GstIterator *it;
+ GstIteratorResult res = GST_ITERATOR_OK;
+ gboolean success = TRUE;
+
+ it = gst_bin_iterate_sorted (bin);
+
+ do {
+ if (res == GST_ITERATOR_RESYNC) {
+ success = TRUE;
+ gst_iterator_resync (it);
+ }
+ res =
+ gst_iterator_foreach (it, gst_bin_sync_children_states_foreach,
+ &success);
+ } while (res == GST_ITERATOR_RESYNC);
+ gst_iterator_free (it);
+
+ return success;
+}
+
/**
* gst_parse_bin_from_description:
* @bin_description: command line describing the bin
diff --git a/gst/gstutils.h b/gst/gstutils.h
index a93588386..186f43917 100644
--- a/gst/gstutils.h
+++ b/gst/gstutils.h
@@ -983,6 +983,8 @@ void gst_bin_add_many (GstBin *bin, GstElement
void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
+gboolean gst_bin_sync_children_states (GstBin *bin);
+
/* parse utility functions */
GstElement * gst_parse_bin_from_description (const gchar * bin_description,
gboolean ghost_unlinked_pads,
diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def
index d3e94c301..675661dfb 100644
--- a/win32/common/libgstreamer.def
+++ b/win32/common/libgstreamer.def
@@ -109,6 +109,7 @@ EXPORTS
gst_bin_recalculate_latency
gst_bin_remove
gst_bin_remove_many
+ gst_bin_sync_children_states
gst_bitmask_get_type
gst_buffer_add_meta
gst_buffer_append