diff options
Diffstat (limited to 'voctocore/lib')
-rw-r--r-- | voctocore/lib/asource.py | 69 | ||||
-rw-r--r-- | voctocore/lib/avsource.py | 66 | ||||
-rw-r--r-- | voctocore/lib/pipeline.py | 14 | ||||
-rw-r--r-- | voctocore/lib/vsource.py | 69 |
4 files changed, 43 insertions, 175 deletions
diff --git a/voctocore/lib/asource.py b/voctocore/lib/asource.py deleted file mode 100644 index 6cf6029..0000000 --- a/voctocore/lib/asource.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python3 -import logging -from gi.repository import Gst - -from lib.config import Config -from lib.tcpsingleconnection import TCPSingleConnection - -class ASource(TCPSingleConnection): - def __init__(self, name, port): - self.log = logging.getLogger('ASource['+name+']') - super().__init__(port) - - self.name = name - - def on_accepted(self, conn, addr): - pipeline = """ - fdsrc fd={fd} ! - matroskademux ! - {acaps} ! - interaudiosink channel=audio_{name} - """.format( - fd=conn.fileno(), - name=self.name, - acaps=Config.get('mix', 'audiocaps') - ) - - self.log.debug('Launching Source-Pipeline:\n%s', pipeline) - self.receiverPipeline = Gst.parse_launch(pipeline) - - self.log.debug('Binding End-of-Stream-Signal on Source-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.all_audio_caps = Gst.Caps.from_string('audio/x-raw') - self.audio_caps = Gst.Caps.from_string(Config.get('mix', 'audiocaps')) - - demux = self.receiverPipeline.get_by_name('demux') - demux.connect('pad-added', self.on_pad_added) - - self.receiverPipeline.set_state(Gst.State.PLAYING) - - def on_pad_added(self, demux, src_pad): - caps = src_pad.query_caps(None) - self.log.debug('demuxer added pad w/ caps: %s', caps.to_string()) - if caps.can_intersect(self.all_audio_caps): - self.log.debug('new demuxer-pad is a audio-pad, testing against configured audio-caps') - if not caps.can_intersect(self.audio_caps): - self.log.warning('the incoming connection presented a video-stream that is not compatible to the configured caps') - self.log.warning(' incoming caps: %s', caps.to_string()) - self.log.warning(' configured caps: %s', self.audio_caps.to_string()) - - def on_eos(self, bus, message): - self.log.debug('Received End-of-Stream-Signal on Source-Pipeline') - if self.currentConnection is not None: - self.disconnect() - - def on_error(self, bus, message): - self.log.debug('Received Error-Signal on Source-Pipeline') - (error, debug) = message.parse_error() - self.log.debug('Error-Details: #%u: %s', error.code, debug) - - if self.currentConnection is not None: - self.disconnect() - - def disconnect(self): - self.receiverPipeline.set_state(Gst.State.NULL) - self.receiverPipeline = None - self.close_connection() diff --git a/voctocore/lib/avsource.py b/voctocore/lib/avsource.py index ecd5b0f..88d85f2 100644 --- a/voctocore/lib/avsource.py +++ b/voctocore/lib/avsource.py @@ -6,58 +6,62 @@ from lib.config import Config from lib.tcpsingleconnection import TCPSingleConnection class AVSource(TCPSingleConnection): - def __init__(self, name, port): + def __init__(self, name, port, outputs=None, has_audio=True, has_video=True): self.log = logging.getLogger('AVSource['+name+']') super().__init__(port) + if outputs is None: + outputs = [name] + + assert has_audio or has_video + self.name = name + self.has_audio = has_audio + self.has_video = has_video + self.outputs = outputs def on_accepted(self, conn, addr): pipeline = """ fdsrc fd={fd} ! matroskademux name=demux - - demux. ! - {acaps} ! - queue ! - tee name=atee - - atee. ! queue ! interaudiosink channel=audio_{name}_mixer - atee. ! queue ! interaudiosink channel=audio_{name}_mirror """.format( - fd=conn.fileno(), - name=self.name, - acaps=Config.get('mix', 'audiocaps') + fd=conn.fileno() ) - if Config.getboolean('previews', 'enabled'): + if self.has_audio: pipeline += """ - atee. ! queue ! interaudiosink channel=audio_{name}_preview + demux. ! + {acaps} ! + queue ! + tee name=atee """.format( - name=self.name + acaps=Config.get('mix', 'audiocaps') ) - pipeline += """ - demux. ! - {vcaps} ! - queue ! - tee name=vtee + for output in self.outputs: + pipeline += """ + atee. ! queue ! interaudiosink channel=audio_{output} + """.format( + output=output + ) - vtee. ! queue ! intervideosink channel=video_{name}_mixer - vtee. ! queue ! intervideosink channel=video_{name}_mirror - """.format( - fd=conn.fileno(), - name=self.name, - vcaps=Config.get('mix', 'videocaps') - ) - - if Config.getboolean('previews', 'enabled'): + if self.has_video: pipeline += """ - vtee. ! queue ! intervideosink channel=video_{name}_preview + demux. ! + {vcaps} ! + queue ! + tee name=vtee """.format( - name=self.name + vcaps=Config.get('mix', 'videocaps') ) + for output in self.outputs: + pipeline += """ + vtee. ! queue ! intervideosink channel=video_{output} + """.format( + output=output + ) + self.log.debug('Launching Source-Pipeline:\n%s', pipeline) self.receiverPipeline = Gst.parse_launch(pipeline) diff --git a/voctocore/lib/pipeline.py b/voctocore/lib/pipeline.py index f341491..365cadd 100644 --- a/voctocore/lib/pipeline.py +++ b/voctocore/lib/pipeline.py @@ -5,8 +5,6 @@ from gi.repository import Gst # import library components from lib.config import Config from lib.avsource import AVSource -from lib.asource import ASource -from lib.vsource import VSource from lib.avrawoutput import AVRawOutput from lib.avpreviewoutput import AVPreviewOutput from lib.videomix import VideoMix @@ -35,7 +33,11 @@ class Pipeline(object): port = 10000 + idx self.log.info('Creating AVSource %s at tcp-port %u', name, port) - source = AVSource(name, port) + outputs = [name+'_mixer', name+'_mirror'] + if Config.getboolean('previews', 'enabled'): + outputs.append(name+'_preview') + + source = AVSource(name, port, outputs=outputs) self.sources.append(source) @@ -62,7 +64,7 @@ class Pipeline(object): port = 16000 self.log.info('Creating Mixer-Background VSource at tcp-port %u', port) - self.bgsrc = VSource('background', port) + self.bgsrc = AVSource('background', port, has_audio=False) port = 11000 self.log.info('Creating Mixer-Output at tcp-port %u', port) @@ -83,13 +85,13 @@ class Pipeline(object): port = 17000 + idx self.log.info('Creating StreamBlanker VSource %s at tcp-port %u', name, port) - source = VSource('%s_streamblanker' % name, port) + source = AVSource('%s_streamblanker' % name, port, has_audio=False) self.sbsources.append(source) port = 18000 self.log.info('Creating StreamBlanker ASource at tcp-port %u', port) - source = ASource('streamblanker', port) + source = AVSource('streamblanker', port, has_video=False) self.sbsources.append(source) diff --git a/voctocore/lib/vsource.py b/voctocore/lib/vsource.py deleted file mode 100644 index 893c7c0..0000000 --- a/voctocore/lib/vsource.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python3 -import logging -from gi.repository import Gst - -from lib.config import Config -from lib.tcpsingleconnection import TCPSingleConnection - -class VSource(TCPSingleConnection): - def __init__(self, name, port): - self.log = logging.getLogger('VSource['+name+']') - super().__init__(port) - - self.name = name - - def on_accepted(self, conn, addr): - pipeline = """ - fdsrc fd={fd} ! - matroskademux ! - {vcaps} ! - intervideosink channel=video_{name} - """.format( - fd=conn.fileno(), - name=self.name, - vcaps=Config.get('mix', 'videocaps') - ) - - self.log.debug('Launching Source-Pipeline:\n%s', pipeline) - self.receiverPipeline = Gst.parse_launch(pipeline) - - self.log.debug('Binding End-of-Stream-Signal on Source-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.all_video_caps = Gst.Caps.from_string('video/x-raw') - self.video_caps = Gst.Caps.from_string(Config.get('mix', 'videocaps')) - - demux = self.receiverPipeline.get_by_name('demux') - demux.connect('pad-added', self.on_pad_added) - - self.receiverPipeline.set_state(Gst.State.PLAYING) - - def on_pad_added(self, demux, src_pad): - caps = src_pad.query_caps(None) - self.log.debug('demuxer added pad w/ caps: %s', caps.to_string()) - if caps.can_intersect(self.all_video_caps): - self.log.debug('new demuxer-pad is a video-pad, testing against configured video-caps') - if not caps.can_intersect(self.video_caps): - self.log.warning('the incoming connection presented a video-stream that is not compatible to the configured caps') - self.log.warning(' incoming caps: %s', caps.to_string()) - self.log.warning(' configured caps: %s', self.video_caps.to_string()) - - def on_eos(self, bus, message): - self.log.debug('Received End-of-Stream-Signal on Source-Pipeline') - if self.currentConnection is not None: - self.disconnect() - - def on_error(self, bus, message): - self.log.debug('Received Error-Signal on Source-Pipeline') - (error, debug) = message.parse_error() - self.log.debug('Error-Details: #%u: %s', error.code, debug) - - if self.currentConnection is not None: - self.disconnect() - - def disconnect(self): - self.receiverPipeline.set_state(Gst.State.NULL) - self.receiverPipeline = None - self.close_connection() |