import gobject
import pygst
pygst.require ("0.10")
import gst

def bus_quit_cb (bus, message, loop):
    print message
    loop.quit ()

def main ():
    loop = gobject.MainLoop ()
    pipeline = gst.Pipeline ()
    bus = gst.Bus ()
    bus.add_signal_watch ()
    bus.connect ("message::eos", bus_quit_cb, loop)
    bus.connect ("message::error", bus_quit_cb, loop)

    audiotestsrc = gst.element_factory_make ("audiotestsrc")
    tee = gst.element_factory_make ("tee")
    adder = gst.element_factory_make ("adder")
    fakesink = gst.element_factory_make ("fakesink")

    pipeline.add (audiotestsrc, tee, adder, fakesink)

    audiotestsrc.link (tee)
    adder.link (fakesink)
    # i wonder why gst-py returns PyBool_FromLong from _link
    assert not tee.get_pad ("src0").link (adder.get_pad ("sink0"))
    assert not tee.get_pad ("src1").link (adder.get_pad ("sink1"))
    
    # not reached
    assert False

    pipeline.set_state (gst.STATE_PLAYING)
    loop.run ()
    pipeline.set_state (gst.STATE_NULL)

if __name__ == '__main__':
    main ()
