aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/backgroundsource.py
blob: 1f3da54a7bc8928379282554336ebfdac717125d (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from gi.repository import Gst
  4. from lib.config import Config
  5. from lib.tcpsingleconnection import TCPSingleConnection
  6. class BackgroundSource(TCPSingleConnection):
  7. def __init__(self, port):
  8. self.log = logging.getLogger('BackgroundSource')
  9. super().__init__(port)
  10. def on_accepted(self, conn, addr):
  11. pipeline = """
  12. fdsrc fd={fd} !
  13. matroskademux !
  14. {vcaps} !
  15. intervideosink channel=mixer_background
  16. """.format(
  17. fd=conn.fileno(),
  18. vcaps=Config.get('mix', 'videocaps')
  19. )
  20. self.log.debug('Launching Source-Pipeline:\n%s', pipeline)
  21. self.receiverPipeline = Gst.parse_launch(pipeline)
  22. self.log.debug('Binding End-of-Stream-Signal on Source-Pipeline')
  23. self.receiverPipeline.bus.add_signal_watch()
  24. self.receiverPipeline.bus.connect("message::eos", self.on_eos)
  25. self.receiverPipeline.bus.connect("message::error", self.on_error)
  26. self.receiverPipeline.set_state(Gst.State.PLAYING)
  27. def on_eos(self, bus, message):
  28. self.log.debug('Received End-of-Stream-Signal on Source-Pipeline')
  29. if self.currentConnection is not None:
  30. self.disconnect()
  31. def on_error(self, bus, message):
  32. self.log.debug('Received Error-Signal on Source-Pipeline')
  33. (error, debug) = message.parse_error()
  34. self.log.debug('Error-Details: #%u: %s', error.code, debug)
  35. if self.currentConnection is not None:
  36. self.disconnect()
  37. def disconnect(self):
  38. self.receiverPipeline.set_state(Gst.State.NULL)
  39. self.receiverPipeline = None
  40. self.close_connection()