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