summaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: c898baf90eecf38a157992f0d5eb805ba8655417 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from lib.config import Config
  4. from lib.videomix import CompositeModes
  5. class ControlServerCommands():
  6. log = logging.getLogger('ControlServerCommands')
  7. pipeline = None
  8. vnames = []
  9. def __init__(self, pipeline):
  10. self.pipeline = pipeline
  11. self.sources = Config.getlist('mix', 'sources')
  12. def decodeSourceName(self, src_name_or_id):
  13. if isinstance(src_name_or_id, str):
  14. try:
  15. return self.sources.index(src_name_or_id)
  16. except Exception as e:
  17. raise IndexError("source %s unknown" % src_name_or_id)
  18. if src_name_or_id < 0 or src_name_or_id >= len(self.sources):
  19. raise IndexError("source %s unknown" % src_name_or_id)
  20. def set_video_a(self, src_name_or_id):
  21. src_id = self.decodeSourceName(src_name_or_id)
  22. self.pipeline.vmix.setVideoA(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.setVideoB(src_id)
  27. return True
  28. def set_composite_mode(self, composite_mode):
  29. try:
  30. mode = CompositeModes[composite_mode]
  31. except KeyError as e:
  32. raise KeyError("composite-mode %s unknown" % composite_mode)
  33. self.pipeline.vmix.setCompositeMode(mode)
  34. return True