from gi.repository import Gst
import sys, time

Gst.init(sys.argv)

p = Gst.parse_launch("videotestsrc ! tee name=t ! fakesink")

print p.set_state(Gst.State.PLAYING)
time.sleep(1)

t = p.get_by_name("t")
queue = Gst.ElementFactory.make("queue", None)
p.add(queue)
queue.set_state(Gst.State.PLAYING)
t.link(queue)

while True:
    message = p.get_bus().timed_pop(1000*1000*1000)
    if message is None:
        break
    print message.type
    if message.get_structure():
        print message.get_structure().to_string()

print p.set_state(Gst.State.NULL)
