summaryrefslogtreecommitdiff
path: root/voctocore/lib/avpreviewoutput.py
blob: f757e1c1d21cb566b582d37c7171a02c76d9b78b (plain)
  1. import logging
  2. from gi.repository import Gst
  3. from lib.config import Config
  4. from lib.tcpmulticonnection import TCPMultiConnection
  5. class AVPreviewOutput(TCPMultiConnection):
  6. def __init__(self, channel, port):
  7. self.log = logging.getLogger('AVPreviewOutput['+channel+']')
  8. super().__init__(port)
  9. self.channel = channel
  10. if Config.has_option('previews', 'videocaps'):
  11. vcaps_out = Config.get('previews', 'videocaps')
  12. else:
  13. vcaps_out = Config.get('mix', 'videocaps')
  14. pipeline = """
  15. interaudiosrc channel=audio_{channel} !
  16. {acaps} !
  17. queue !
  18. mux.
  19. intervideosrc channel=video_{channel} !
  20. {vcaps_in} !
  21. videorate !
  22. videoscale method=nearest-neighbour !
  23. {vcaps_out} !
  24. jpegenc !
  25. queue !
  26. mux.
  27. matroskamux
  28. name=mux
  29. streamable=true
  30. writing-app=Voctomix-AVPreviewOutput !
  31. multifdsink
  32. buffers-max=500
  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('Creating Output-Pipeline:\n%s', pipeline)
  42. self.outputPipeline = Gst.parse_launch(pipeline)
  43. self.log.debug('Binding Error & End-of-Stream-Signal on Output-Pipeline')
  44. self.outputPipeline.bus.add_signal_watch()
  45. self.outputPipeline.bus.connect("message::eos", self.on_eos)
  46. self.outputPipeline.bus.connect("message::error", self.on_error)
  47. self.log.debug('Launching Output-Pipeline')
  48. self.outputPipeline.set_state(Gst.State.PLAYING)
  49. def on_accepted(self, conn, addr):
  50. self.log.debug('Adding fd %u to multifdsink', conn.fileno())
  51. fdsink = self.outputPipeline.get_by_name('fd')
  52. fdsink.emit('add', conn.fileno())
  53. def on_disconnect(multifdsink, fileno):
  54. if fileno == conn.fileno():
  55. self.log.debug('fd %u removed from multifdsink', fileno)
  56. self.close_connection(conn)
  57. fdsink.connect('client-fd-removed', on_disconnect)
  58. def on_eos(self, bus, message):
  59. self.log.debug('Received End-of-Stream-Signal on Output-Pipeline')
  60. def on_error(self, bus, message):
  61. self.log.debug('Received Error-Signal on Output-Pipeline')
  62. (error, debug) = message.parse_error()
  63. self.log.debug('Error-Details: #%u: %s', error.code, debug)