summaryrefslogtreecommitdiff
path: root/voctocore/lib/avrawoutput.py
blob: 3c7d73922f87e8df675b388cea4da8c32ec07172 (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. textoverlay halignment=left valignment=top ypad=75 text=AVRawOutput !
  19. timeoverlay halignment=left valignment=top ypad=75 xpad=400 !
  20. queue !
  21. mux.
  22. matroskamux
  23. name=mux
  24. streamable=true
  25. writing-app=Voctomix-AVRawOutput !
  26. multifdsink
  27. sync-method=next-keyframe
  28. name=fd
  29. """.format(
  30. channel=self.channel,
  31. acaps=Config.get('mix', 'audiocaps'),
  32. vcaps=Config.get('mix', 'videocaps')
  33. )
  34. self.log.debug('Launching Output-Pipeline:\n%s', pipeline)
  35. self.receiverPipeline = Gst.parse_launch(pipeline)
  36. self.receiverPipeline.set_state(Gst.State.PLAYING)
  37. def on_accepted(self, conn, addr):
  38. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  39. fdsink = self.receiverPipeline.get_by_name('fd')
  40. fdsink.emit('add', conn.fileno())
  41. def on_disconnect(multifdsink, fileno):
  42. if fileno == conn.fileno():
  43. self.log.debug('fd %u removed from multifdsink', fileno)
  44. self.close_connection(conn)
  45. fdsink.connect('client-fd-removed', on_disconnect)