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