[gst-devel] GstIterator python bindings

Johan Dahlin johan at gnome.org
Sun Oct 2 21:52:37 CEST 2005


Hi there

I've been thinking a little bit about wrapping GstIterators in python.
Currently there is no way to get a list of elements of a bin or a
list of pads for an element.

So my plan is the following:

Everything that returns a GstIterator will return a iterator wrapper.
The wrapper will implement the python iterator protocol, eg __iter__
and StopIteration when done, which allows us to use short cuts like:

  for item in iterator:

However, as Andy kindly pointed out on irc, the GstIterator
has a couple of useful methods which are not possible to use
in the common/simple case. The resync() method comes to mind, however
push may also be useful.

We have the following use cases:

GstElement:

  for pad in element.pads()
  for srcpad in element.src_pads():
  for sinkpad in element.sink_pads():
  
  Common case, shortcut
  for pad in elem

GstBin:

  for element in bin.elements():
  for element in bin.sorted():
  for element in bin.recurse():
  for element in bin.sinks():
  for element in bin.interfaces(iface):
 
  Common case, shortcut
  for element in bin

Note, GstFormat/GstQuery iterators are excluded.

I removed the iterator_ prefix, which seemed like a pretty sane thing to do.
       
To be able to properly convert the contents of the iterator to a python
object we need to provide a GType in each iterator which will describe
of which type the elements contained in the iterator will have.  I've
attached a patch which does this and updates the core to use the new API.
In the future we might want to look into makeing GstFormatDefinition and
GstQueryTypeDefinition as GBoxed, it didn't seem to be very urgent though.

Andy asked me to hold of this until after the next release which is
scheduled to be released tomorrow.

Comments, suggestions?

Johan




More information about the gstreamer-devel mailing list