After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 742152 - iterator: Add a way to iterate pads and elements only once for each
iterator: Add a way to iterate pads and elements only once for each
Status: RESOLVED DUPLICATE of bug 785679
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-12-31 14:10 UTC by Thibault Saunier
Modified: 2017-10-17 08:56 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Thibault Saunier 2014-12-31 14:10:29 UTC
Currently in GstAggregator we have:

gboolean gst_aggregator_iterate_sinkpads(GstAggregator*  self,
      GstAggregatorPadForeachFunc func, gpointer user_data);

which does basically that but we should offer an API in the iterator for that.

in #739010 Tim proposed:

gst_iterator_once_foreach_pad / gst_iterator_once_foreach_element
Comment 1 Tim-Philipp Müller 2014-12-31 14:24:49 UTC
Maybe my suggestion is not ideal, since you would still have to do:

  iterator = gst_element_iterate_sink_pads()
  gst_iterator_once_foreach_pad (iterator, callback_func, data);
  gst_iterator_free (iterator);

It's kind of a middle way. The alternative is to add callback-based variants of all the various _iterate*() functions.

OR, and at least from a C language point of view this might be a bit nicer/tighter (since we have no lambda funcs there):

  iterator = gst_element_iterate_sink_pads()
  while ((pad = gst_iterator_iterate_once_get_next_pad (iterator))) {
    do_xyz...
  }
  gst_iterator_free (iterator);

as it seems to me that almost all callback functions are basically 1-3 lines of code anyway.
Comment 2 Thibault Saunier 2014-12-31 15:22:05 UTC
> It's kind of a middle way. The alternative is to add callback-based variants of
> all the various _iterate*() functions.

Right, I think it is a good option, something like:

Why not just do:

gst_element_iterate_*pads_once (GstElement *element,
    GstPadForeachFunction func, gpointer udata);

gst_bin_iterate_*_once (GstBin *bin,
    GstElementForeachFunction func, gpointer udata);
 
> OR, and at least from a C language point of view this might be a bit
> nicer/tighter (since we have no lambda funcs there):
> 
>   iterator = gst_element_iterate_sink_pads()
>   while ((pad = gst_iterator_iterate_once_get_next_pad (iterator))) {
>     do_xyz...
>   }
>   gst_iterator_free (iterator);
> 
> as it seems to me that almost all callback functions are basically 1-3 lines of
> code anyway.

Could be too.
Comment 3 Olivier Crête 2015-01-05 20:35:41 UTC
Another option would be to have a function like that to create a wrapper around the original iterator, then we can use all of the existing functions, a bit like gst_iterator_filter() works:
GstIterator *gst_iterator_once (GstIterator *iter);

I'm not a big fan of having special functions to iterate pads or elements, maybe a generic one for GObjects? Then just have something like gst_iterator_foreach_object()?
Comment 4 Sebastian Dröge (slomo) 2015-01-08 13:37:44 UTC
I like that idea most! Could be done with gst_value_compare(), which works not only on objects but also integers and other stuff. Not that anybody ever iterates over anything that is not a GObject*, but the GstIterator API allows that.
Comment 5 Olivier Crête 2017-10-16 23:25:20 UTC
Tim mostly convinced me that iterators were a terrible API and that having simple foreach function like the one in gst_aggregator, but inside GstElement was the right way to go. I think he has a patch on some bug.
Comment 6 Olivier Crête 2017-10-17 00:02:54 UTC
See bug #785679 for Tim's patches
Comment 7 Sebastian Dröge (slomo) 2017-10-17 08:56:05 UTC
We should simplify GstIterator for 2.0 and get rid of the GValue stuff. Nobody is using it for anything but GObjects, and this is what makes it very hard to use IMHO. It's also not very bindings friendly as-is.

*** This bug has been marked as a duplicate of bug 785679 ***