aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/avrawoutput.py
blob: bda6b77f1d400f122d7e69cc5f795c440a521b72 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from gi.repository import Gst
  4. from lib.config import Config
  5. from lib.tcpmulticonnection import TCPMultiConnection
  6. class AVRawOutput(TCPMultiConnection):
  7. def __init__(self, channel, port):
  8. self.log = logging.getLogger('AVRawOutput['+channel+']')
  9. super().__init__(port)
  10. self.channel = channel
  11. pipeline = """
  12. interaudiosrc channel=audio_{channel} !
  13. {acaps} !
  14. queue !
  15. mux.
  16. intervideosrc channel=video_{channel} !
  17. {vcaps} !
  18. queue !
  19. mux.
  20. matroskamux
  21. name=mux
  22. streamable=true
  23. writing-app=Voctomix-AVRawOutput !
  24. multifdsink
  25. sync-method=next-keyframe
  26. name=fd
  27. """.format(
  28. channel=self.channel,
  29. acaps=Config.get('mix', 'audiocaps'),
  30. vcaps=Config.get('mix', 'videocaps')
  31. )
  32. self.log.debug('Launching Output-Pipeline:\n%s', pipeline)
  33. self.receiverPipeline = Gst.parse_launch(pipeline)
  34. self.receiverPipeline.set_state(Gst.State.PLAYING)
  35. def on_accepted(self, conn, addr):
  36. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  37. fdsink = self.receiverPipeline.get_by_name('fd')
  38. fdsink.emit('add', conn.fileno())
  39. def on_disconnect(multifdsink, fileno):
  40. if fileno == conn.fileno():
  41. self.log.debug('fd %u removed from multifdsink', fileno)
  42. self.close_connection(conn, addr)
  43. fdsink.connect('client-fd-removed', on_disconnect)