From 943ab31a0f32b7bb50fa1ff90c9ce8d72b232cfd Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 13 May 2015 19:35:20 +0200 Subject: experiment with transporting uncompressed a/v together in a matroska stream --- voctocore/lib/video/mix.py | 167 --------------------------------------- voctocore/lib/video/rawoutput.py | 84 -------------------- voctocore/lib/video/src.py | 88 --------------------- 3 files changed, 339 deletions(-) delete mode 100644 voctocore/lib/video/mix.py delete mode 100644 voctocore/lib/video/rawoutput.py delete mode 100644 voctocore/lib/video/src.py (limited to 'voctocore/lib/video') diff --git a/voctocore/lib/video/mix.py b/voctocore/lib/video/mix.py deleted file mode 100644 index bcac7d2..0000000 --- a/voctocore/lib/video/mix.py +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/python3 -import logging -from gi.repository import Gst -from enum import Enum - -from lib.config import Config - -class CompositeModes(Enum): - fullscreen = 0 - side_by_side_equal = 1 - -class VideoMix(object): - log = logging.getLogger('VideoMix') - - mixingPipeline = None - - caps = None - names = [] - - compositeMode = CompositeModes.fullscreen - sourceA = 0 - sourceB = 1 - - def __init__(self): - self.caps = Config.get('mix', 'videocaps') - - self.names = Config.getlist('sources', 'video') - self.log.info('Configuring Mixer for %u Sources', len(self.names)) - - pipeline = """ - videomixer name=mix ! - {caps} ! - textoverlay text=mixer halignment=left valignment=top ypad=175 ! - intervideosink channel=video_mix - """.format( - caps=self.caps - ) - - for idx, name in enumerate(self.names): - pipeline += """ - intervideosrc channel=video_{name}_mixer ! - {caps} ! - videoscale ! - capsfilter name=caps_{idx} ! - mix. - """.format( - name=name, - caps=self.caps, - idx=idx - ) - - 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:\n%s', pipeline) - self.mixingPipeline.set_state(Gst.State.PLAYING) - - def updateMixerState(self): - 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=%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) - mixerpad.set_property('ypos', 0) - - self.log.debug('Resetting Scaler %u to non-scaling', idx) - capsfilter = self.mixingPipeline.get_by_name('caps_%u' % idx) - 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): - # 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() diff --git a/voctocore/lib/video/rawoutput.py b/voctocore/lib/video/rawoutput.py deleted file mode 100644 index bb9efc4..0000000 --- a/voctocore/lib/video/rawoutput.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/python3 -import logging, socket -from gi.repository import GObject, Gst - -from lib.config import Config - -class VideoRawOutput(object): - log = logging.getLogger('VideoRawOutput') - - name = None - port = None - caps = None - - boundSocket = None - - receiverPipelines = [] - currentConnections = [] - - def __init__(self, channel, port, caps): - self.log = logging.getLogger('VideoRawOutput['+channel+']') - - self.channel = channel - self.port = port - self.caps = caps - - self.log.debug('Binding to Mirror-Socket on [::]:%u', port) - self.boundSocket = socket.socket(socket.AF_INET6) - self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False) - self.boundSocket.bind(('::', port)) - self.boundSocket.listen(1) - - self.log.debug('Setting GObject io-watch on Socket') - GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect) - - def on_connect(self, sock, *args): - conn, addr = sock.accept() - self.log.info("Incomming Connection from %s", addr) - - pipeline = """ - intervideosrc channel={channel} ! - {caps} ! - textoverlay text={channel} halignment=left valignment=top ypad=225 ! - gdppay ! - fdsink fd={fd} - """.format( - fd=conn.fileno(), - channel=self.channel, - caps=self.caps - ) - self.log.debug('Launching Pipeline:\n%s', pipeline) - receiverPipeline = Gst.parse_launch(pipeline) - - def on_eos(bus, message): - self.log.info('Received End-of-Stream-Signal on Source-Receiver-Pipeline') - self.disconnect(receiverPipeline, conn) - - def on_error(bus, message): - self.log.info('Received Error-Signal on Source-Receiver-Pipeline') - - (error, debug) = message.parse_error() - self.log.debug('Error-Message %s\n%s', error.message, debug) - - self.disconnect(receiverPipeline, conn) - - self.log.debug('Binding End-of-Stream-Signal on Pipeline') - receiverPipeline.bus.add_signal_watch() - receiverPipeline.bus.connect("message::eos", on_eos) - receiverPipeline.bus.connect("message::error", on_error) - - receiverPipeline.set_state(Gst.State.PLAYING) - - self.receiverPipelines.append(receiverPipeline) - self.currentConnections.append(conn) - - self.log.info('Now %u Receiver connected', len(self.currentConnections)) - - return True - - def disconnect(self, receiverPipeline, currentConnection): - receiverPipeline.set_state(Gst.State.NULL) - self.receiverPipelines.remove(receiverPipeline) - self.currentConnections.remove(currentConnection) - self.log.info('Disconnected Receiver, now %u Receiver connected', len(self.currentConnections)) diff --git a/voctocore/lib/video/src.py b/voctocore/lib/video/src.py deleted file mode 100644 index cd36d8c..0000000 --- a/voctocore/lib/video/src.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/python3 -import logging, socket -from gi.repository import GObject, Gst - -from lib.config import Config - -class VideoSrc(object): - log = logging.getLogger('VideoSrc') - - name = None - port = None - caps = None - - receiverPipeline = None - - boundSocket = None - currentConnection = None - - def __init__(self, name, port, caps): - self.log = logging.getLogger('VideoSrc['+name+']') - - self.name = name - self.port = port - self.caps = caps - - self.log.debug('Binding to Source-Socket on [::]:%u', port) - self.boundSocket = socket.socket(socket.AF_INET6) - self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False) - self.boundSocket.bind(('::', port)) - self.boundSocket.listen(1) - - self.log.debug('Setting GObject io-watch on Socket') - GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect) - - def on_connect(self, sock, *args): - conn, addr = sock.accept() - self.log.info("Incomming Connection from %s", addr) - - if self.currentConnection is not None: - self.log.warn("Another Source is already connected") - return True - - pipeline = """ - fdsrc fd={fd} ! - gdpdepay ! - {caps} ! - textoverlay text=video_{name}_fd halignment=left valignment=top ypad=125 ! - queue ! - tee name=tee - - tee. ! queue ! intervideosink channel=video_{name}_mixer - tee. ! queue ! intervideosink channel=video_{name}_mirror - """.format( - fd=conn.fileno(), - name=self.name, - caps=self.caps - ) - self.log.debug('Launching Source-Receiver-Pipeline:\n%s', pipeline) - self.receiverPipeline = Gst.parse_launch(pipeline) - - self.log.debug('Binding End-of-Stream-Signal on Source-Receiver-Pipeline') - self.receiverPipeline.bus.add_signal_watch() - self.receiverPipeline.bus.connect("message::eos", self.on_eos) - self.receiverPipeline.bus.connect("message::error", self.on_error) - - self.receiverPipeline.set_state(Gst.State.PLAYING) - - self.currentConnection = conn - return True - - def on_eos(self, bus, message): - self.log.info('Received End-of-Stream-Signal on Source-Receiver-Pipeline') - if self.currentConnection is not None: - self.disconnect() - - def on_error(self, bus, message): - self.log.info('Received Error-Signal on Source-Receiver-Pipeline') - (code, debug) = message.parse_error() - self.log.debug('Error-Details: #%u: %s', code, debug) - - if self.currentConnection is not None: - self.disconnect() - - def disconnect(self): - self.receiverPipeline.set_state(Gst.State.NULL) - self.receiverPipeline = None - self.currentConnection = None -- cgit v1.2.3