summaryrefslogtreecommitdiff
path: root/voctocore/lib/avpreviewoutput.py
blob: a637976eb86c52dc5a8d4bbf3e010eef08d73920 (plain)
  1. import logging
  2. from gi.repository import Gst
  3. from lib.config import Config
  4. from lib.tcpmulticonnection import TCPMultiConnection
  5. from lib.clock import Clock
  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. intervideosrc channel=video_{channel} !
  17. {vcaps_in} !
  18. capssetter caps="video/x-raw,interlace-mode=interlaced" !
  19. deinterlace !
  20. video/x-raw,interlace-mode=progressive !
  21. videorate !
  22. videoscale method=nearest-neighbour !
  23. {vcaps_out} !
  24. jpegenc !
  25. queue !
  26. mux.
  27. interaudiosrc channel=audio_{channel} !
  28. {acaps} !
  29. queue !
  30. mux.
  31. matroskamux
  32. name=mux
  33. streamable=true
  34. writing-app=Voctomix-AVPreviewOutput !
  35. multifdsink
  36. blocksize=1048576
  37. buffers-max=500
  38. sync-method=next-keyframe
  39. name=fd
  40. """.format(
  41. channel=self.channel,
  42. acaps=Config.get('mix', 'audiocaps'),
  43. vcaps_in=Config.get('mix', 'videocaps'),
  44. vcaps_out=vcaps_out
  45. )
  46. self.log.debug('Creating Output-Pipeline:\n%s', pipeline)
  47. self.outputPipeline = Gst.parse_launch(pipeline)
  48. self.outputPipeline.use_clock(Clock)
  49. self.log.debug('Binding Error & End-of-Stream-Signal on Output-Pipeline')
  50. self.outputPipeline.bus.add_signal_watch()
  51. self.outputPipeline.bus.connect("message::eos", self.on_eos)
  52. self.outputPipeline.bus.connect("message::error", self.on_error)
  53. self.log.debug('Launching Output-Pipeline')
  54. self.outputPipeline.set_state(Gst.State.PLAYING)
  55. def on_accepted(self, conn, addr):
  56. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  57. fdsink = self.outputPipeline.get_by_name('fd')
  58. fdsink.emit('add', conn.fileno())
  59. def on_disconnect(multifdsink, fileno):
  60. if fileno == conn.fileno():
  61. self.log.debug('fd %u removed from multifdsink', fileno)
  62. self.close_connection(conn)
  63. fdsink.connect('client-fd-removed', on_disconnect)
  64. def on_eos(self, bus, message):
  65. self.log.debug('Received End-of-Stream-Signal on Output-Pipeline')
  66. def on_error(self, bus, message):
  67. self.log.debug('Received Error-Signal on Output-Pipeline')
  68. (error, debug) = message.parse_error()
  69. self.log.debug('Error-Details: #%u: %s', error.code, debug)