I’ve been using pygst on a project and it’s been working fine. I’m trying to migrate it to the new introspection system (GI), but I’ve been getting a different behavior.
In the old pygst I have something like this:
... # other imports
import pygst
pygst.require('0.10')
import gst
... # other imports
gobjects.threads_init()
...
def my_handler(bus, message):
# handle the message
...
player = gst.element_factory_make('playbin2', 'my_player')
bus = player.get_bus()
bus.connect('message', my_handler)
bus.add_signal_watch()
...
player.set_state(gst.STATE_PLAYING)
# start the main Glib loop
The message parameter has an attribute .type which can be used for selective processing (I’m only interested in the end of stream (EOS) and error). Using the new system I have:
... # other imports
from gi.repository import Gst
import glib
import gobject
.... # other imports
gobject.threads_init()
loop = glib.MainLoop(None, False)
def bus_handler(bus, message):
print message
# handle the message
...
Gst.init_check(None)
player = Gst.ElementFactory.make('playbin2', 'my_player')
player.set_property('uri', 'file:///home/kenji/button.ogg')
bus = player.get_bus()
bus.connect('message', bus_handler)
bus.add_signal_watch()
player.set_state(Gst.State.PLAYING)
# start the main loop
However, the handler always receives the parameter message as None. I’ve tried filtering these out, but I still get nothing (i.e. all messages are None).
I’ve read a lot of the GStreamer documentation (especially on GstBus, add_signal_watch() and playbin2) but I didn’t find anything related to this behavior. I’ve checked the Gst gir file and I’ve seen that add_watch() cannot be introspected, so that’s a dead end. The glib main loop in this above example is just to make things shorter without a full GTK example, but the real thing uses Gtk.main() (giving exactly the same behavior).
I’m using GStreamer 0.10.35.0 (as informed by Gst.version()) on Arch Linux 64, but I’ve tested the same behavior on GStreamer 0.10.32.0 on Ubuntu 11.04 32-bit.
Is there any alternative to bus.connect()? Am I using it in the wrong way? I’ve spent quite a few hours hunting down this bug, I would really appreciate any insight on this. Thanks! =)
I ended up using
add_signal_watch_full(), which is unfortunately more verbose. It works fine though, and I can receive messages on my handler.