6 gi.require_version('Gst', '1.0')
7 from gi.repository import Gst
10 from gi.repository import GObject
11 GObject.threads_init()
14 # The following pipeline works
16 videotestsrc pattern=0 ! selector.
17 videotestsrc pattern=18 background-color=4294901760 ! selector.
18 input-selector name=selector ! autovideosink
24 self.loop = GObject.MainLoop()
25 self.pipeline = Gst.parse_launch(PIPELINE)
26 self.selector = self.pipeline.get_by_name('selector')
28 pad = self.selector.get_static_pad("sink_0")
29 self.selector.set_property("active-pad", pad)
30 print("n-pads: %d" % self.selector.get_property("n-pads"))
32 bus = self.pipeline.get_bus()
33 bus.add_signal_watch()
34 bus.connect('message::eos', self.on_eos)
35 bus.connect('message::error', self.on_error)
36 bus.connect('message::state-changed', self.on_state_changed)
39 self.pipeline.set_state(Gst.State.PLAYING)
43 self.pipeline.set_state(Gst.State.NULL)
47 active_pad = self.selector.get_property("active-pad")
48 if active_pad.get_name() == "sink_0":
49 new_pad = self.selector.get_static_pad("sink_1")
51 new_pad = self.selector.get_static_pad("sink_0")
53 print("switching from %s to %s" % (active_pad.get_name(),
56 self.selector.set_property("active-pad", new_pad)
58 def on_eos(self, bus, msg):
61 def on_error(self, bus, msg):
62 (err, debug) = msg.parse_error()
63 print("Error: %s" % err)
66 def on_state_changed(self, bus, msg):
67 if msg.src != self.pipeline:
70 old_state, new_state, pending = msg.parse_state_changed()
71 print("%s from %s to %s" % (msg.src.get_name(), old_state, new_state))
77 def stdin_cb(source, condition):
82 GObject.io_add_watch(sys.stdin, GObject.IO_IN, stdin_cb)
84 print("\nPress Enter to switch the source\n")
88 if __name__ == '__main__':