aboutsummaryrefslogtreecommitdiff
path: root/voctocore/experiments/failovertest.py
blob: deb665b1f25ee8a5ef287a97d4832289b488601d (plain)
  1. #!/usr/bin/python3
  2. import gi, time
  3. # import GStreamer and GTK-Helper classes
  4. gi.require_version('Gst', '1.0')
  5. from gi.repository import GLib, Gst, GObject
  6. # init GObject before importing local classes
  7. GObject.threads_init()
  8. Gst.init(None)
  9. from videodisplay import VideomixerWithDisplay
  10. from shmsrc import ShmSrc
  11. class Example:
  12. def __init__(self):
  13. self.mainloop = GObject.MainLoop()
  14. self.pipeline = Gst.Pipeline()
  15. self.bus = self.pipeline.get_bus()
  16. self.bus.add_signal_watch()
  17. self.bus.connect('message::eos', self.on_eos)
  18. self.bus.connect('message::error', self.on_error)
  19. self.addTest('/tmp/v-cam2')
  20. self.addTest('/tmp/v-cam1')
  21. def addTest(self, socket):
  22. self.mixdisplay = VideomixerWithDisplay()
  23. self.videoconvert = Gst.ElementFactory.make('videoconvert', None)
  24. self.grabbersrc = ShmSrc(socket, Gst.Caps.from_string('video/x-raw,width=1280,height=720,framerate=25/1,format=RGBx'))
  25. # Add elements to pipeline
  26. self.pipeline.add(self.grabbersrc)
  27. self.pipeline.add(self.videoconvert)
  28. self.pipeline.add(self.mixdisplay)
  29. self.grabbersrc.link(self.videoconvert)
  30. self.videoconvert.link(self.mixdisplay)
  31. def run(self):
  32. self.pipeline.set_state(Gst.State.PAUSED)
  33. time.sleep(0.5)
  34. self.pipeline.set_state(Gst.State.PLAYING)
  35. self.mainloop.run()
  36. def kill(self):
  37. self.pipeline.set_state(Gst.State.NULL)
  38. self.mainloop.quit()
  39. def on_eos(self, bus, msg):
  40. print('on_eos()')
  41. #self.kill()
  42. def on_error(self, bus, msg):
  43. print('on_error():', msg.parse_error())
  44. #self.kill()
  45. example = Example()
  46. example.run()