6 gi.require_version('Gst', '1.0')
7 from gi.repository import Gst
10 from gi.repository import GLib
13 # The following pipeline works
15 videotestsrc pattern=0 ! selector.
16 videotestsrc pattern=18 background-color=4294901760 ! selector.
17 input-selector name=selector ! autovideosink
23 self.loop = GLib.MainLoop()
24 self.pipeline = Gst.parse_launch(PIPELINE)
25 self.selector = self.pipeline.get_by_name('selector')
27 pad = self.selector.get_static_pad("sink_0")
28 self.selector.set_property("active-pad", pad)
29 print("n-pads: %d" % self.selector.get_property("n-pads"))
31 bus = self.pipeline.get_bus()
32 bus.add_signal_watch()
33 bus.connect('message::eos', self.on_eos)
34 bus.connect('message::error', self.on_error)
35 bus.connect('message::state-changed', self.on_state_changed)
38 self.pipeline.set_state(Gst.State.PLAYING)
42 self.pipeline.set_state(Gst.State.NULL)
46 active_pad = self.selector.get_property("active-pad")
47 if active_pad.get_name() == "sink_0":
48 new_pad = self.selector.get_static_pad("sink_1")
50 new_pad = self.selector.get_static_pad("sink_0")
52 print("switching from %s to %s" % (active_pad.get_name(),
55 self.selector.set_property("active-pad", new_pad)
57 def on_eos(self, bus, msg):
60 def on_error(self, bus, msg):
61 (err, debug) = msg.parse_error()
62 print("Error: %s" % err)
65 def on_state_changed(self, bus, msg):
66 if msg.src != self.pipeline:
69 old_state, new_state, pending = msg.parse_state_changed()
70 print("%s from %s to %s" % (msg.src.get_name(), old_state, new_state))
76 def stdin_cb(source, condition):
81 GLib.io_add_watch(sys.stdin, GLib.IO_IN, stdin_cb)
83 print("\nPress Enter to switch the source\n")
87 if __name__ == '__main__':