aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: f0b801101a21e9b8c8b00e2cadbc4e1536ffce91 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from lib.config import Config
  4. from lib.videomix import CompositeModes
  5. class ControlServerCommands():
  6. def __init__(self, pipeline):
  7. self.log = logging.getLogger('ControlServerCommands')
  8. self.pipeline = pipeline
  9. self.sources = Config.getlist('mix', 'sources')
  10. self.blankersources = Config.getlist('stream-blanker', 'sources')
  11. def decodeSourceName(self, src_name_or_id):
  12. if isinstance(src_name_or_id, str):
  13. try:
  14. return self.sources.index(src_name_or_id)
  15. except Exception as e:
  16. raise IndexError("source %s unknown" % src_name_or_id)
  17. if src_name_or_id < 0 or src_name_or_id >= len(self.sources):
  18. raise IndexError("source %s unknown" % src_name_or_id)
  19. def decodeBlankerSourceName(self, src_name_or_id):
  20. if isinstance(src_name_or_id, str):
  21. try:
  22. return self.blankersources.index(src_name_or_id)
  23. except Exception as e:
  24. raise IndexError("source %s unknown" % src_name_or_id)
  25. if src_name_or_id < 0 or src_name_or_id >= len(self.blankersources):
  26. raise IndexError("source %s unknown" % src_name_or_id)
  27. def message(self, *args):
  28. return True
  29. def set_video_a(self, src_name_or_id):
  30. src_id = self.decodeSourceName(src_name_or_id)
  31. self.pipeline.vmix.setVideoSourceA(src_id)
  32. return True
  33. def set_video_b(self, src_name_or_id):
  34. src_id = self.decodeSourceName(src_name_or_id)
  35. self.pipeline.vmix.setVideoSourceB(src_id)
  36. return True
  37. def set_audio(self, src_name_or_id):
  38. src_id = self.decodeSourceName(src_name_or_id)
  39. self.pipeline.amix.setAudioSource(src_id)
  40. return True
  41. def set_composite_mode(self, composite_mode):
  42. try:
  43. mode = CompositeModes[composite_mode]
  44. except KeyError as e:
  45. raise KeyError("composite-mode %s unknown" % composite_mode)
  46. self.pipeline.vmix.setCompositeMode(mode)
  47. return True
  48. def set_stream_blank(self, src_name_or_id):
  49. src_id = self.decodeBlankerSourceName(src_name_or_id)
  50. self.pipeline.streamblanker.setBlankSource(src_id)
  51. return True
  52. def set_stream_live(self):
  53. self.pipeline.streamblanker.setBlankSource(None)
  54. return True