aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/audiomix.py
blob: 326e7a5bd6614cad58b3d5a9a6b036b840513009 (plain)
  1. #!/usr/bin/python3
  2. import time, logging
  3. from gi.repository import GLib, Gst
  4. from lib.config import Config
  5. class AudioMix(Gst.Bin):
  6. log = logging.getLogger('AudioMix')
  7. mixerpads = []
  8. def __init__(self):
  9. super().__init__()
  10. self.switch = Gst.ElementFactory.make('input-selector', 'switch')
  11. self.add(self.switch)
  12. self.switch.set_property('sync-streams', True)
  13. self.switch.set_property('sync-mode', 1) #GST_INPUT_SELECTOR_SYNC_MODE_CLOCK
  14. self.switch.set_property('cache-buffers', True)
  15. self.add_pad(
  16. Gst.GhostPad.new('src', self.switch.get_static_pad('src'))
  17. )
  18. def request_mixer_pad(self):
  19. mixerpad = self.switch.get_request_pad('sink_%u')
  20. self.mixerpads.append(mixerpad)
  21. self.log.info('requested mixerpad %u (named %s)', len(self.mixerpads) - 1, mixerpad.get_name())
  22. ghostpad = Gst.GhostPad.new(mixerpad.get_name(), mixerpad)
  23. self.add_pad(ghostpad)
  24. return ghostpad
  25. def set_active(self, target):
  26. self.log.info('switching to audiosource %u', target)
  27. self.switch.set_property('active-pad', self.mixerpads[target])