aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/pipeline.py
blob: 1a1349e3c890949d04f6e78166a5a9aec9eb6b22 (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. self.log.info('Creating Audiomixer')
  49. self.amix = AudioMix()
  50. port = 16000
  51. self.log.info('Creating Mixer-Background VSource at tcp-port %u', port)
  52. self.bgsrc = AVSource('background', port, has_audio=False)
  53. port = 11000
  54. self.log.info('Creating Mixer-Output at tcp-port %u', port)
  55. self.mixout = AVRawOutput('mix_out', port)
  56. if Config.getboolean('previews', 'enabled'):
  57. port = 12000
  58. self.log.info('Creating Preview-Output for AVSource %s '
  59. 'at tcp-port %u', name, port)
  60. self.mixpreview = AVPreviewOutput('mix_preview', port)
  61. if Config.getboolean('stream-blanker', 'enabled'):
  62. names = Config.getlist('stream-blanker', 'sources')
  63. if len(names) < 1:
  64. raise RuntimeError('At least one StreamBlanker-Source must '
  65. 'be configured or the '
  66. 'StreamBlanker disabled!')
  67. for idx, name in enumerate(names):
  68. port = 17000 + idx
  69. self.log.info('Creating StreamBlanker VSource %s '
  70. 'at tcp-port %u', name, port)
  71. source = AVSource('{}_streamblanker'.format(name), port,
  72. has_audio=False)
  73. self.sbsources.append(source)
  74. port = 18000
  75. self.log.info('Creating StreamBlanker ASource at tcp-port %u',
  76. port)
  77. source = AVSource('streamblanker', port, has_video=False)
  78. self.sbsources.append(source)
  79. self.log.info('Creating StreamBlanker')
  80. self.streamblanker = StreamBlanker()
  81. port = 15000
  82. self.log.info('Creating StreamBlanker-Output at tcp-port %u', port)
  83. self.streamout = AVRawOutput('streamblanker_out', port)