From 0b222cd7f66375356f3826a5c0f77f15a3793f0d Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 14 May 2015 15:44:34 +0200 Subject: Implement an Audio-Mixer --- voctocore/lib/audiomix.py | 35 +++++++++++++++++++++++++++++++++-- voctocore/lib/commands.py | 9 +++++++-- voctocore/lib/videomix.py | 4 ++-- 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'voctocore') diff --git a/voctocore/lib/audiomix.py b/voctocore/lib/audiomix.py index 24c34a9..e307527 100644 --- a/voctocore/lib/audiomix.py +++ b/voctocore/lib/audiomix.py @@ -18,15 +18,46 @@ class AudioMix(object): def __init__(self): self.caps = Config.get('mix', 'audiocaps') + self.names = Config.getlist('mix', 'sources') + self.log.info('Configuring Mixer for %u Sources', len(self.names)) + pipeline = """ - interaudiosrc channel=audio_cam1_mixer ! + audiomixer name=mix ! {caps} ! - queue ! interaudiosink channel=audio_mix """.format( caps=self.caps ) + for idx, name in enumerate(self.names): + pipeline += """ + interaudiosrc channel=audio_{name}_mixer ! + {caps} ! + mix. + """.format( + name=name, + caps=self.caps + ) + self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline) self.mixingPipeline = Gst.parse_launch(pipeline) + + self.log.debug('Initializing Mixer-State') + self.updateMixerState() + + self.log.debug('Launching Mixing-Pipeline') self.mixingPipeline.set_state(Gst.State.PLAYING) + + def updateMixerState(self): + self.log.info('Updating Mixer-State') + + for idx, name in enumerate(self.names): + volume = int(idx == self.selectedSource) + + self.log.debug('Setting Mixerpad %u to volume=%0.2f', idx, volume) + mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx) + mixerpad.set_property('volume', volume) + + def setAudioSource(self, source): + self.selectedSource = source + self.updateMixerState() diff --git a/voctocore/lib/commands.py b/voctocore/lib/commands.py index c898baf..5975e98 100644 --- a/voctocore/lib/commands.py +++ b/voctocore/lib/commands.py @@ -27,12 +27,17 @@ class ControlServerCommands(): def set_video_a(self, src_name_or_id): src_id = self.decodeSourceName(src_name_or_id) - self.pipeline.vmix.setVideoA(src_id) + self.pipeline.vmix.setVideoSourceA(src_id) return True def set_video_b(self, src_name_or_id): src_id = self.decodeSourceName(src_name_or_id) - self.pipeline.vmix.setVideoB(src_id) + self.pipeline.vmix.setVideoSourceB(src_id) + return True + + def set_audio(self, src_name_or_id): + src_id = self.decodeSourceName(src_name_or_id) + self.pipeline.amix.setAudioSource(src_id) return True def set_composite_mode(self, composite_mode): diff --git a/voctocore/lib/videomix.py b/voctocore/lib/videomix.py index dbebede..77bea42 100644 --- a/voctocore/lib/videomix.py +++ b/voctocore/lib/videomix.py @@ -147,7 +147,7 @@ class VideoMix(object): capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) capsfilter.set_property('caps', caps) - def setVideoA(self, source): + def setVideoSourceA(self, source): # swap if required if self.sourceB == source: self.sourceB = self.sourceA @@ -155,7 +155,7 @@ class VideoMix(object): self.sourceA = source self.updateMixerState() - def setVideoB(self, source): + def setVideoSourceB(self, source): # swap if required if self.sourceA == source: self.sourceA = self.sourceB -- cgit v1.2.3