aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/videodisplay.py
blob: 6537b78ab1647ae28d6f4ba447ad92eeb1d8ff81 (plain)
  1. import logging
  2. from gi.repository import Gst, Gtk
  3. class VideoDisplay:
  4. """ Displays a Voctomix-Video-Stream into a GtkWidget """
  5. def __init__(self, port, widget):
  6. self.log = logging.getLogger('VideoDisplay[%u]' % port)
  7. pipeline = """
  8. videotestsrc !
  9. timeoverlay !
  10. video/x-raw,width=1920,height=1080 !
  11. xvimagesink
  12. """.format(
  13. port=port
  14. )
  15. self.log.info('launching gstreamer-pipeline for widget %s "%s":\n%s', widget.get_name(), Gtk.Buildable.get_name(widget), pipeline)
  16. self.pipeline = Gst.parse_launch(pipeline)
  17. widget.realize()
  18. self.xid = widget.get_property('window').get_xid()
  19. bus = self.pipeline.get_bus()
  20. bus.add_signal_watch()
  21. bus.enable_sync_message_emission()
  22. bus.connect('message::error', self.on_error)
  23. bus.connect("sync-message::element", self.on_syncmsg)
  24. def run(self):
  25. self.pipeline.set_state(Gst.State.PLAYING)
  26. def on_syncmsg(self, bus, msg):
  27. if msg.get_structure().get_name() == "prepare-window-handle":
  28. self.log.info('setting xvimagesink window-handle to %s', self.xid)
  29. msg.src.set_window_handle(self.xid)
  30. def on_error(self, bus, msg):
  31. self.log.error('on_error():', msg.parse_error())