From 10058b623dee99ed54421ff204b51adcc9a379d0 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 10 May 2015 23:52:31 +0200 Subject: implement side-by-side-equal composition --- voctocore/lib/commands.py | 4 +- voctocore/lib/controlserver.py | 29 ++++++------- voctocore/lib/video/mix.py | 94 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 103 insertions(+), 24 deletions(-) (limited to 'voctocore') diff --git a/voctocore/lib/commands.py b/voctocore/lib/commands.py index f3243f3..05db54c 100644 --- a/voctocore/lib/commands.py +++ b/voctocore/lib/commands.py @@ -2,6 +2,7 @@ import logging from lib.config import Config +from lib.video.mix import CompositeModes class ControlServerCommands(): log = logging.getLogger('ControlServerCommands') @@ -35,5 +36,6 @@ class ControlServerCommands(): return True def set_composite_mode(self, composite_mode): - self.pipeline.vmixer.set_composite_mode(src_name_or_id) + mode = CompositeModes[composite_mode] + self.pipeline.vmixer.setCompositeMode(mode) return True diff --git a/voctocore/lib/controlserver.py b/voctocore/lib/controlserver.py index e267ca7..2b96152 100644 --- a/voctocore/lib/controlserver.py +++ b/voctocore/lib/controlserver.py @@ -90,20 +90,15 @@ class ControlServer(): return False, 'unknown command %s' % command - try: - # fetch the function-pointer - f = getattr(self.commands, command) - - # call the function - ret = f(*args) - - # if it returned an iterable, probably (Success, Message), pass that on - if hasattr(ret, '__iter__'): - return ret - else: - # otherwise construct a tuple - return (ret, None) - - except Exception as e: - # In case of an Exception, return that - return False, str(e) + # fetch the function-pointer + f = getattr(self.commands, command) + + # call the function + ret = f(*args) + + # if it returned an iterable, probably (Success, Message), pass that on + if hasattr(ret, '__iter__'): + return ret + else: + # otherwise construct a tuple + return (ret, None) diff --git a/voctocore/lib/video/mix.py b/voctocore/lib/video/mix.py index a9e1513..bcac7d2 100644 --- a/voctocore/lib/video/mix.py +++ b/voctocore/lib/video/mix.py @@ -5,8 +5,9 @@ from enum import Enum from lib.config import Config -class ComposteModes(Enum): +class CompositeModes(Enum): fullscreen = 0 + side_by_side_equal = 1 class VideoMix(object): log = logging.getLogger('VideoMix') @@ -16,7 +17,7 @@ class VideoMix(object): caps = None names = [] - compositeMode = ComposteModes.fullscreen + compositeMode = CompositeModes.fullscreen sourceA = 0 sourceB = 1 @@ -58,15 +59,21 @@ class VideoMix(object): self.mixingPipeline.set_state(Gst.State.PLAYING) def updateMixerState(self): - if self.compositeMode == ComposteModes.fullscreen: + if self.compositeMode == CompositeModes.fullscreen: self.updateMixerStateFullscreen() + if self.compositeMode == CompositeModes.side_by_side_equal: + self.updateMixerStateSideBySideEqual() + def updateMixerStateFullscreen(self): self.log.info('Updating Mixer-State for Fullscreen-Composition') + + noScaleCaps = Gst.Caps.from_string('video/x-raw') + for idx, name in enumerate(self.names): alpha = int(idx == self.sourceA) - self.log.debug('Setting Mixerpad %u to x/y=0 and alpha=%u', idx, alpha) + self.log.debug('Setting Mixerpad %u to x/y=0 and alpha=%0.2f', idx, alpha) mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx) mixerpad.set_property('alpha', alpha ) mixerpad.set_property('xpos', 0) @@ -74,12 +81,87 @@ class VideoMix(object): self.log.debug('Resetting Scaler %u to non-scaling', idx) capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) - capsfilter.set_property('caps', Gst.Caps.from_string(self.caps)) + capsfilter.set_property('caps', noScaleCaps) + + def getInputVideoSize(self): + caps = Gst.Caps.from_string(self.caps) + struct = caps.get_structure(0) + _, width = struct.get_int('width') + _, height = struct.get_int('height') + + return width, height + + def updateMixerStateSideBySideEqual(self): + self.log.info('Updating Mixer-State for Side-by-side-Equal-Composition') + + width, height = self.getInputVideoSize() + gutter = int(width / 100) + + self.log.debug('Video-Size parsed as %u/%u, Gutter calculated to %upx', width, height, gutter) + + targetWidth = int((width - gutter) / 2) + targetHeight = int(targetWidth / width * height) + + ycenter = (height - targetHeight) / 2 + xa = 0 + xb = width - targetWidth + + scaleCaps = Gst.Caps.from_string('video/x-raw,width=%u,height=%u' % (targetWidth, targetHeight)) + noScaleCaps = Gst.Caps.from_string('video/x-raw') + + for idx, name in enumerate(self.names): + mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx) + + if idx == self.sourceA: + x = xa + y = ycenter + caps = scaleCaps + alpha = 1 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Setting Scaler %u to %u/%u', idx, targetWidth, targetHeight) + + elif idx == self.sourceB: + x = xb + y = ycenter + caps = scaleCaps + alpha = 1 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Setting Scaler %u to %u/%u', idx, targetWidth, targetHeight) + + else: + x = 0 + y = 0 + caps = noScaleCaps + alpha = 0 + + self.log.debug('Setting Mixerpad %u to x/y=%u/%u and alpha=%0.2f', idx, x, y, alpha) + self.log.debug('Resetting Scaler %u to non-scaling', idx) + + mixerpad.set_property('alpha', alpha) + mixerpad.set_property('xpos', x) + mixerpad.set_property('ypos', y) + + capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) + capsfilter.set_property('caps', caps) def setVideoA(self, source): + # swap if required + if self.sourceB == source: + self.sourceB = self.sourceA + self.sourceA = source self.updateMixerState() def setVideoB(self, source): - self.sourceN = source + # swap if required + if self.sourceA == source: + self.sourceA = self.sourceB + + self.sourceB = source + self.updateMixerState() + + def setCompositeMode(self, mode): + self.compositeMode = mode self.updateMixerState() -- cgit v1.2.3