aboutsummaryrefslogtreecommitdiff
path: root/voctocore/experiments/intervideo.py
blob: a3f49bfc72b4abff1008c1dc2b273ec1290bc89a (plain)
  1. #!/usr/bin/python3
  2. import gi, time
  3. import socket
  4. # import GStreamer and GTK-Helper classes
  5. gi.require_version('Gst', '1.0')
  6. from gi.repository import GLib, Gst, GObject
  7. # init GObject before importing local classes
  8. GObject.threads_init()
  9. Gst.init(None)
  10. class Example:
  11. def __init__(self):
  12. self.mainloop = GObject.MainLoop()
  13. self.source_pipeline = None
  14. video = True
  15. if video:
  16. self.pipeline1 = Gst.parse_launch("""
  17. videotestsrc !
  18. video/x-raw,width=800,height=450,format=I420,framerate=1/1 !
  19. intervideosink channel=video
  20. """)
  21. self.pipeline2 = Gst.parse_launch("""
  22. intervideosrc channel=video !
  23. video/x-raw,width=800,height=450,format=I420,framerate=1/1 !
  24. xvimagesink
  25. """)
  26. else:
  27. self.pipeline1 = Gst.parse_launch("""
  28. audiotestsrc !
  29. audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000,channel-mask=(bitmask)0x3 !
  30. interaudiosink channel=audio
  31. """)
  32. self.pipeline2 = Gst.parse_launch("""
  33. interaudiosrc channel=audio !
  34. audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000,channel-mask=(bitmask)0x3 !
  35. alsasink
  36. """)
  37. self.pipeline1.bus.add_signal_watch()
  38. self.pipeline1.bus.connect("message::eos", self.on_eos)
  39. self.pipeline1.bus.connect("message::error", self.on_error)
  40. self.pipeline2.bus.add_signal_watch()
  41. self.pipeline2.bus.connect("message::eos", self.on_eos)
  42. self.pipeline2.bus.connect("message::error", self.on_error)
  43. GLib.timeout_add_seconds(3, self.on_timeout)
  44. def run(self):
  45. print("starting pipeline2")
  46. self.pipeline2.set_state(Gst.State.PLAYING)
  47. self.mainloop.run()
  48. def on_timeout(self):
  49. print("starting pipeline1")
  50. self.pipeline1.set_state(Gst.State.PLAYING)
  51. return False
  52. def on_eos(self, bus, message):
  53. self.log.debug('Received End-of-Stream-Signal on Pipeline')
  54. def on_error(self, bus, message):
  55. self.log.debug('Received Error-Signal on Pipeline')
  56. (error, debug) = message.parse_error()
  57. self.log.debug('Error-Details: #%u: %s', error.code, debug)
  58. example = Example()
  59. example.run()