+/* Perform a query iteration for the given bin. The query is stored in
+ * QueryFold and iter should be either a GstPad iterator or a
+ * GstElement iterator. */
+static gboolean
+bin_iterate_fold (GstBin * bin, GstIterator * iter, QueryInitFunction fold_init,
+ QueryDoneFunction fold_done, GstIteratorFoldFunction fold_func,
+ QueryFold fold_data)
+{
+ gboolean res = FALSE;
+ GValue ret = { 0 };
+ /* set the result of the query to FALSE initially */
+ g_value_init (&ret, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&ret, res);
+
+ while (TRUE) {
+ GstIteratorResult ires;
+
+ ires = gst_iterator_fold (iter, fold_func, &ret, &fold_data);
+
+ switch (ires) {
+ case GST_ITERATOR_RESYNC:
+ gst_iterator_resync (iter);
+ if (fold_init)
+ fold_init (bin, &fold_data);
+ g_value_set_boolean (&ret, res);
+ break;
+ case GST_ITERATOR_OK:
+ case GST_ITERATOR_DONE:
+ res = g_value_get_boolean (&ret);
+ if (fold_done != NULL && res)
+ fold_done (bin, &fold_data);
+ goto done;
+ default:
+ res = FALSE;
+ goto done;
+ }
+ }
+done:
+ return res;
+}
+