aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/pipeline.py
blob: 6213ac6b9b26a331fb828e51199117744d427edb (plain)
  1. import logging
  2. from gi.repository import Gst
  3. # import library components
  4. from lib.config import Config
  5. from lib.avsource import AVSource
  6. from lib.avrawoutput import AVRawOutput
  7. from lib.avpreviewoutput import AVPreviewOutput
  8. from lib.videomix import VideoMix
  9. from lib.audiomix import AudioMix
  10. from lib.streamblanker import StreamBlanker
  11. class Pipeline(object):
  12. """mixing, streaming and encoding pipeline constuction and control"""
  13. def __init__(self):
  14. self.log = logging.getLogger('Pipeline')
  15. self.log.info('Video-Caps configured to: %s',
  16. Config.get('mix', 'videocaps'))
  17. self.log.info('Audio-Caps configured to: %s',
  18. Config.get('mix', 'audiocaps'))
  19. names = Config.getlist('mix', 'sources')
  20. if len(names) < 1:
  21. raise RuntimeError("At least one AVSource must be configured!")
  22. self.sources = []
  23. self.mirrors = []
  24. self.previews = []
  25. self.sbsources = []
  26. self.log.info('Creating %u Creating AVSources: %s', len(names), names)
  27. for idx, name in enumerate(names):
  28. port = 10000 + idx
  29. self.log.info('Creating AVSource %s at tcp-port %u', name, port)
  30. outputs = [name + '_mixer', name + '_mirror']
  31. if Config.getboolean('previews', 'enabled'):
  32. outputs.append(name + '_preview')
  33. source = AVSource(name, port, outputs=outputs)
  34. self.sources.append(source)
  35. port = 13000 + idx
  36. self.log.info('Creating Mirror-Output for AVSource %s '
  37. 'at tcp-port %u', name, port)
  38. mirror = AVRawOutput('%s_mirror' % name, port)
  39. self.mirrors.append(mirror)
  40. if Config.getboolean('previews', 'enabled'):
  41. port = 14000 + idx
  42. self.log.info('Creating Preview-Output for AVSource %s '
  43. 'at tcp-port %u', name, port)
  44. preview = AVPreviewOutput('%s_preview' % name, port)
  45. self.previews.append(preview)
  46. self.log.info('Creating Videmixer')
  47. self.vmix = VideoMix()
  48. # check if there is an audio source preconfigured
  49. try:
  50. audiosource = names.index(Config.get('mix', 'audiosource'))
  51. except:
  52. audiosource = 0
  53. self.log.info('Creating Audiomixer')
  54. self.amix = AudioMix(audiosource)
  55. port = 16000
  56. self.log.info('Creating Mixer-Background VSource at tcp-port %u', port)
  57. self.bgsrc = AVSource('background', port, has_audio=False)
  58. port = 11000
  59. self.log.info('Creating Mixer-Output at tcp-port %u', port)
  60. self.mixout = AVRawOutput('mix_out', port)
  61. if Config.getboolean('previews', 'enabled'):
  62. port = 12000
  63. self.log.info('Creating Preview-Output for AVSource %s '
  64. 'at tcp-port %u', name, port)
  65. self.mixpreview = AVPreviewOutput('mix_preview', port)
  66. if Config.getboolean('stream-blanker', 'enabled'):
  67. names = Config.getlist('stream-blanker', 'sources')
  68. if len(names) < 1:
  69. raise RuntimeError('At least one StreamBlanker-Source must '
  70. 'be configured or the '
  71. 'StreamBlanker disabled!')
  72. for idx, name in enumerate(names):
  73. port = 17000 + idx
  74. self.log.info('Creating StreamBlanker VSource %s '
  75. 'at tcp-port %u', name, port)
  76. source = AVSource('{}_streamblanker'.format(name), port,
  77. has_audio=False)
  78. self.sbsources.append(source)
  79. port = 18000
  80. self.log.info('Creating StreamBlanker ASource at tcp-port %u',
  81. port)
  82. source = AVSource('streamblanker', port, has_video=False)
  83. self.sbsources.append(source)
  84. self.log.info('Creating StreamBlanker')
  85. self.streamblanker = StreamBlanker()
  86. port = 15000
  87. self.log.info('Creating StreamBlanker-Output at tcp-port %u', port)
  88. self.streamout = AVRawOutput('streamblanker_out', port)