summaryrefslogtreecommitdiff
path: root/voctocore/lib/videomix.py
blob: 92077230129b5d9be76c3c1613936bc966af43fe (plain)
  1. #!/usr/bin/python3
  2. import time, logging
  3. from gi.repository import GLib, Gst
  4. from lib.config import Config
  5. class VideoMix(object):
  6. log = logging.getLogger('VideoMix')
  7. mixerpads = []
  8. def __init__(self):
  9. super().__init__()
  10. self.mixer = Gst.ElementFactory.make('videomixer', 'mixer')
  11. self.scale = Gst.ElementFactory.make('videoscale', 'scale')
  12. self.conv = Gst.ElementFactory.make('videoconvert', 'conv')
  13. self.add(self.mixer)
  14. self.add(self.scale)
  15. self.add(self.conv)
  16. caps = Gst.Caps.from_string(Config.get('mix', 'outputcaps'))
  17. self.mixer.link_filtered(self.scale, caps)
  18. self.scale.link(self.conv)
  19. self.add_pad(
  20. Gst.GhostPad.new('src', self.conv.get_static_pad('src'))
  21. )
  22. def request_mixer_pad(self):
  23. mixerpad = self.mixer.get_request_pad('sink_%u')
  24. self.mixerpads.append(mixerpad)
  25. mixerpad.set_property('alpha', 1)
  26. self.log.info('requested mixerpad %u (named %s)', len(self.mixerpads) - 1, mixerpad.get_name())
  27. ghostpad = Gst.GhostPad.new(mixerpad.get_name(), mixerpad)
  28. self.add_pad(ghostpad)
  29. return ghostpad
  30. def set_active(self, target):
  31. self.log.info('setting videosource %u active, disabling other', target)
  32. for idx, mixerpad in enumerate(self.mixerpads):
  33. mixerpad.set_property('alpha', int(target == idx))