aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/vsource.py
blob: 2296eac1d2a5ce3de85a7963b0499c90a7a52cb3 (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 VSource(TCPSingleConnection):
  7. def __init__(self, name, port):
  8. self.log = logging.getLogger('VSource['+name+']')
  9. super().__init__(port)
  10. self.name = name
  11. def on_accepted(self, conn, addr):
  12. pipeline = """
  13. fdsrc fd={fd} !
  14. matroskademux !
  15. {vcaps} !
  16. intervideosink channel=video_{name}
  17. """.format(
  18. fd=conn.fileno(),
  19. name=self.name,
  20. vcaps=Config.get('mix', 'videocaps')
  21. )
  22. self.log.debug('Launching Source-Pipeline:\n%s', pipeline)
  23. self.receiverPipeline = Gst.parse_launch(pipeline)
  24. self.log.debug('Binding End-of-Stream-Signal on Source-Pipeline')
  25. self.receiverPipeline.bus.add_signal_watch()
  26. self.receiverPipeline.bus.connect("message::eos", self.on_eos)
  27. self.receiverPipeline.bus.connect("message::error", self.on_error)
  28. self.receiverPipeline.set_state(Gst.State.PLAYING)
  29. def on_eos(self, bus, message):
  30. self.log.debug('Received End-of-Stream-Signal on Source-Pipeline')
  31. if self.currentConnection is not None:
  32. self.disconnect()
  33. def on_error(self, bus, message):
  34. self.log.debug('Received Error-Signal on Source-Pipeline')
  35. (error, debug) = message.parse_error()
  36. self.log.debug('Error-Details: #%u: %s', error.code, debug)
  37. if self.currentConnection is not None:
  38. self.disconnect()
  39. def disconnect(self):
  40. self.receiverPipeline.set_state(Gst.State.NULL)
  41. self.receiverPipeline = None
  42. self.close_connection()