summaryrefslogtreecommitdiff
path: root/voctocore/lib/avpreviewoutput.py
blob: e444a87153b7e439ba973d36d024659428b36c8d (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. videorate !
  23. videoscale method=nearest-neighbour !
  24. {vcaps_out} !
  25. jpegenc !
  26. queue !
  27. mux.
  28. matroskamux
  29. name=mux
  30. streamable=true
  31. writing-app=Voctomix-AVPreviewOutput !
  32. multifdsink
  33. sync-method=next-keyframe
  34. name=fd
  35. """.format(
  36. channel=self.channel,
  37. acaps=Config.get('mix', 'audiocaps'),
  38. vcaps_in=Config.get('mix', 'videocaps'),
  39. vcaps_out=vcaps_out
  40. )
  41. self.log.debug('Launching Output-Pipeline:\n%s', pipeline)
  42. self.receiverPipeline = Gst.parse_launch(pipeline)
  43. self.receiverPipeline.set_state(Gst.State.PLAYING)
  44. def on_accepted(self, conn):
  45. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  46. fdsink = self.receiverPipeline.get_by_name('fd')
  47. fdsink.emit('add', conn.fileno())
  48. def on_disconnect(multifdsink, fileno):
  49. if fileno == conn.fileno():
  50. self.log.debug('fd %u removed from multifdsink', fileno)
  51. self.close_connection(conn)
  52. fdsink.connect('client-fd-removed', on_disconnect)