summaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: 9b35bf29826a65b26b7de714d3251d1ea08c5028 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from lib.config import Config
  4. from lib.video.mix 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.vnames = Config.getlist('sources', 'video')
  12. def decodeVideoSrcName(self, src_name_or_id):
  13. if isinstance(src_name_or_id, str):
  14. try:
  15. return self.vnames.index(src_name_or_id)
  16. except Exception as e:
  17. raise IndexError("video-source %s unknown" % src_name_or_id)
  18. if src_name_or_id < 0 or src_name_or_id >= len(self.vnames):
  19. raise IndexError("video-source %s unknown" % src_name_or_id)
  20. def set_video_a(self, src_name_or_id):
  21. src_id = self.decodeVideoSrcName(src_name_or_id)
  22. self.pipeline.vmixer.setVideoA(src_id)
  23. return True
  24. def set_video_b(self, src_name_or_id):
  25. src_id = self.decodeVideoSrcName(src_name_or_id)
  26. self.pipeline.vmixer.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.vmixer.setCompositeMode(mode)
  34. return True