summaryrefslogtreecommitdiff
path: root/voctocore/lib/asource.py
blob: 2383a32322c7acaa2f7cb0d78ed7e22d656cfbe7 (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 ASource(TCPSingleConnection):
  7. def __init__(self, name, port):
  8. self.log = logging.getLogger('ASource['+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. {acaps} !
  16. interaudiosink channel=audio_{name}
  17. """.format(
  18. fd=conn.fileno(),
  19. name=self.name,
  20. acaps=Config.get('mix', 'audiocaps')
  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()