summaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: c16358b73655c202958a45f28bce6eb9ccbb4235 (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. def decodeSourceName(self, src_name_or_id):
  11. if isinstance(src_name_or_id, str):
  12. try:
  13. return self.sources.index(src_name_or_id)
  14. except Exception as e:
  15. raise IndexError("source %s unknown" % src_name_or_id)
  16. if src_name_or_id < 0 or src_name_or_id >= len(self.sources):
  17. raise IndexError("source %s unknown" % src_name_or_id)
  18. def message(self, *args):
  19. return True
  20. def set_video_a(self, src_name_or_id):
  21. src_id = self.decodeSourceName(src_name_or_id)
  22. self.pipeline.vmix.setVideoSourceA(src_id)
  23. return True
  24. def set_video_b(self, src_name_or_id):
  25. src_id = self.decodeSourceName(src_name_or_id)
  26. self.pipeline.vmix.setVideoSourceB(src_id)
  27. return True
  28. def set_audio(self, src_name_or_id):
  29. src_id = self.decodeSourceName(src_name_or_id)
  30. self.pipeline.amix.setAudioSource(src_id)
  31. return True
  32. def set_composite_mode(self, composite_mode):
  33. try:
  34. mode = CompositeModes[composite_mode]
  35. except KeyError as e:
  36. raise KeyError("composite-mode %s unknown" % composite_mode)
  37. self.pipeline.vmix.setCompositeMode(mode)
  38. return True