summaryrefslogtreecommitdiff
path: root/voctocore/lib/commands.py
blob: 58dd23459fc250087754e9f448477ee9ec442a64 (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 set_video_a(self, src_name_or_id):
  19. src_id = self.decodeSourceName(src_name_or_id)
  20. self.pipeline.vmix.setVideoSourceA(src_id)
  21. return True
  22. def set_video_b(self, src_name_or_id):
  23. src_id = self.decodeSourceName(src_name_or_id)
  24. self.pipeline.vmix.setVideoSourceB(src_id)
  25. return True
  26. def set_audio(self, src_name_or_id):
  27. src_id = self.decodeSourceName(src_name_or_id)
  28. self.pipeline.amix.setAudioSource(src_id)
  29. return True
  30. def set_composite_mode(self, composite_mode):
  31. try:
  32. mode = CompositeModes[composite_mode]
  33. except KeyError as e:
  34. raise KeyError("composite-mode %s unknown" % composite_mode)
  35. self.pipeline.vmix.setCompositeMode(mode)
  36. return True