summaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: 5975e98133a5bdff18fab126d8f7635ab8ed9f40 (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.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