aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib
diff options
context:
space:
mode:
authorMaZderMind <github@mazdermind.de>2015-06-16 15:24:24 +0200
committerMaZderMind <github@mazdermind.de>2015-06-16 15:24:24 +0200
commit59e394e00d6c29bf71c38996d09be1cc5647bfb7 (patch)
treeac3bbbd9543de7653805bb41ac6609d6ea81bacd /voctocore/lib
parentb2c5c5cc6eb904db8e6c05d2281541b16d4a2ce8 (diff)
Implement ASource and VSource as generic sources
they are needed for the StreamBlanker-Feature as well
Diffstat (limited to 'voctocore/lib')
-rw-r--r--voctocore/lib/asource.py54
-rw-r--r--voctocore/lib/pipeline.py5
-rw-r--r--voctocore/lib/videomix.py2
-rw-r--r--voctocore/lib/vsource.py (renamed from voctocore/lib/backgroundsource.py)11
4 files changed, 65 insertions, 7 deletions
diff --git a/voctocore/lib/asource.py b/voctocore/lib/asource.py
new file mode 100644
index 0000000..2383a32
--- /dev/null
+++ b/voctocore/lib/asource.py
@@ -0,0 +1,54 @@
+#!/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.receiverPipeline.set_state(Gst.State.PLAYING)
+
+
+ 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/pipeline.py b/voctocore/lib/pipeline.py
index a45ea53..18b54dd 100644
--- a/voctocore/lib/pipeline.py
+++ b/voctocore/lib/pipeline.py
@@ -5,9 +5,10 @@ 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.backgroundsource import BackgroundSource
from lib.videomix import VideoMix
from lib.audiomix import AudioMix
@@ -58,7 +59,7 @@ class Pipeline(object):
self.amix = AudioMix()
port = 16000
- self.bgsrc = BackgroundSource(port)
+ self.bgsrc = VSource('background', port)
port = 11000
self.log.info('Creating Mixer-Output at tcp-port %u', port)
diff --git a/voctocore/lib/videomix.py b/voctocore/lib/videomix.py
index 379c788..ebd60e6 100644
--- a/voctocore/lib/videomix.py
+++ b/voctocore/lib/videomix.py
@@ -40,7 +40,7 @@ class VideoMix(object):
queue !
tee name=tee
- intervideosrc channel=mixer_background !
+ intervideosrc channel=video_background !
{caps} !
mix.
diff --git a/voctocore/lib/backgroundsource.py b/voctocore/lib/vsource.py
index 1f3da54..2296eac 100644
--- a/voctocore/lib/backgroundsource.py
+++ b/voctocore/lib/vsource.py
@@ -5,19 +5,22 @@ from gi.repository import Gst
from lib.config import Config
from lib.tcpsingleconnection import TCPSingleConnection
-class BackgroundSource(TCPSingleConnection):
- def __init__(self, port):
- self.log = logging.getLogger('BackgroundSource')
+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=mixer_background
+ intervideosink channel=video_{name}
""".format(
fd=conn.fileno(),
+ name=self.name,
vcaps=Config.get('mix', 'videocaps')
)