summaryrefslogtreecommitdiff
path: root/voctocore/lib/avrawoutput.py
blob: 69c90a22dd64dc2c657c7afa9b9380efec5dabc8 (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. log = logging.getLogger('AVRawOutput')
  8. name = None
  9. caps = None
  10. receiverPipeline = None
  11. def __init__(self, channel, port):
  12. self.log = logging.getLogger('AVRawOutput['+channel+']')
  13. super().__init__(port)
  14. self.channel = channel
  15. pipeline = """
  16. interaudiosrc channel=audio_{channel} !
  17. {acaps} !
  18. queue !
  19. mux.
  20. intervideosrc channel=video_{channel} !
  21. {vcaps} !
  22. textoverlay halignment=left valignment=top ypad=75 text=AVRawOutput !
  23. timeoverlay halignment=left valignment=top ypad=75 xpad=400 !
  24. queue !
  25. mux.
  26. matroskamux
  27. name=mux
  28. streamable=true
  29. writing-app=Voctomix-AVRawOutput !
  30. multifdsink
  31. sync-method=next-keyframe
  32. name=fd
  33. """.format(
  34. channel=self.channel,
  35. acaps=Config.get('mix', 'audiocaps'),
  36. vcaps=Config.get('mix', 'videocaps')
  37. )
  38. self.log.debug('Launching Output-Pipeline:\n%s', pipeline)
  39. self.receiverPipeline = Gst.parse_launch(pipeline)
  40. self.receiverPipeline.set_state(Gst.State.PLAYING)
  41. def on_accepted(self, conn, addr):
  42. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  43. fdsink = self.receiverPipeline.get_by_name('fd')
  44. fdsink.emit('add', conn.fileno())
  45. def on_disconnect(multifdsink, fileno):
  46. if fileno == conn.fileno():
  47. self.log.debug('fd %u removed from multifdsink', fileno)
  48. self.close_connection(conn)
  49. fdsink.connect('client-fd-removed', on_disconnect)