aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexample-scripts/gstreamer/source-remote-desktop-as-cam1.py91
-rwxr-xr-xexample-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py85
-rw-r--r--voctocore/README.md1
-rw-r--r--voctocore/lib/audiomix.py2
-rw-r--r--voctocore/lib/avpreviewoutput.py2
-rw-r--r--voctocore/lib/avrawoutput.py2
-rw-r--r--voctocore/lib/avsource.py2
-rw-r--r--voctocore/lib/clock.py15
-rw-r--r--voctocore/lib/streamblanker.py2
-rw-r--r--voctocore/lib/videomix.py2
-rwxr-xr-xvoctocore/voctocore.py2
-rw-r--r--voctogui/lib/clock.py20
-rw-r--r--voctogui/lib/connection.py6
-rw-r--r--voctogui/lib/videodisplay.py4
-rwxr-xr-xvoctogui/voctogui.py4
15 files changed, 237 insertions, 3 deletions
diff --git a/example-scripts/gstreamer/source-remote-desktop-as-cam1.py b/example-scripts/gstreamer/source-remote-desktop-as-cam1.py
new file mode 100755
index 0000000..686cc73
--- /dev/null
+++ b/example-scripts/gstreamer/source-remote-desktop-as-cam1.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python3
+import sys, gi, signal
+import argparse, socket
+
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst, GstNet, GObject
+
+# init GObject & Co. before importing local classes
+GObject.threads_init()
+Gst.init([])
+
+class Source(object):
+ def __init__(self, ip):
+ # it works much better with a local file
+ pipeline = """
+ ximagesrc use-damage=0 startx=0 starty=0 endx=1919 endy=1079 !
+ queue !
+ videoscale !
+ videorate !
+ timeoverlay !
+ videoconvert !
+ video/x-raw,format=I420,width=1280,height=720,framerate=25/1,pixel-aspect-ratio=1/1 !
+ queue !
+ mux.
+
+ pulsesrc !
+ audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000 !
+ queue !
+ mux.
+
+ matroskamux name=mux !
+ tcpclientsink host={ip} port=10000
+ """.format(
+ ip=ip
+ )
+
+ self.clock = GstNet.NetClientClock.new('voctocore', ip, 9998, 0)
+ print('obtained NetClientClock from host', self.clock)
+
+ print('waiting for NetClientClock to sync…')
+ self.clock.wait_for_sync(Gst.CLOCK_TIME_NONE)
+
+ print('starting pipeline')
+ self.senderPipeline = Gst.parse_launch(pipeline)
+ self.senderPipeline.use_clock(self.clock)
+ self.src = self.senderPipeline.get_by_name('src')
+
+ # Binding End-of-Stream-Signal on Source-Pipeline
+ self.senderPipeline.bus.add_signal_watch()
+ self.senderPipeline.bus.connect("message::eos", self.on_eos)
+ self.senderPipeline.bus.connect("message::error", self.on_error)
+
+ print("playing")
+ self.senderPipeline.set_state(Gst.State.PLAYING)
+
+
+ def on_eos(self, bus, message):
+ print('Received EOS-Signal')
+ sys.exit(1)
+
+ def on_error(self, bus, message):
+ print('Received Error-Signal')
+ (error, debug) = message.parse_error()
+ print('Error-Details: #%u: %s' % (error.code, debug))
+ sys.exit(1)
+
+def main():
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+ parser = argparse.ArgumentParser(description='Voctocore Remote-Source')
+ parser.add_argument('host')
+
+ args = parser.parse_args()
+ print('Resolving hostname '+args.host)
+ addrs = [ str(i[4][0]) for i in socket.getaddrinfo(args.host, None) ]
+ if len(addrs) == 0:
+ print('Found no IPs')
+ sys.exit(1)
+
+ print('Using IP '+addrs[0])
+
+ src = Source(addrs[0])
+ mainloop = GObject.MainLoop()
+ try:
+ mainloop.run()
+ except KeyboardInterrupt:
+ print('Terminated via Ctrl-C')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
new file mode 100755
index 0000000..70e838f
--- /dev/null
+++ b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python3
+import sys, gi, signal
+import argparse, socket
+
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst, GstNet, GObject
+
+# init GObject & Co. before importing local classes
+GObject.threads_init()
+Gst.init([])
+
+class Source(object):
+ def __init__(self, ip):
+ # it works much better with a local file
+ pipeline = """
+ videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 !
+ timeoverlay !
+ video/x-raw,format=I420,width=1280,height=720,framerate=25/1,pixel-aspect-ratio=1/1 !
+ mux.
+
+ audiotestsrc freq=330 !
+ audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000 !
+ mux.
+
+ matroskamux name=mux !
+ tcpclientsink host={ip} port=10000
+ """.format(
+ ip=ip
+ )
+
+ self.clock = GstNet.NetClientClock.new('voctocore', ip, 9998, 0)
+ print('obtained NetClientClock from host', self.clock)
+
+ print('waiting for NetClientClock to sync…')
+ self.clock.wait_for_sync(Gst.CLOCK_TIME_NONE)
+
+ print('starting pipeline')
+ self.senderPipeline = Gst.parse_launch(pipeline)
+ self.senderPipeline.use_clock(self.clock)
+ self.src = self.senderPipeline.get_by_name('src')
+
+ # Binding End-of-Stream-Signal on Source-Pipeline
+ self.senderPipeline.bus.add_signal_watch()
+ self.senderPipeline.bus.connect("message::eos", self.on_eos)
+ self.senderPipeline.bus.connect("message::error", self.on_error)
+
+ print("playing")
+ self.senderPipeline.set_state(Gst.State.PLAYING)
+
+
+ def on_eos(self, bus, message):
+ print('Received EOS-Signal')
+ sys.exit(1)
+
+ def on_error(self, bus, message):
+ print('Received Error-Signal')
+ (error, debug) = message.parse_error()
+ print('Error-Details: #%u: %s' % (error.code, debug))
+ sys.exit(1)
+
+def main():
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+ parser = argparse.ArgumentParser(description='Voctocore Remote-Source')
+ parser.add_argument('host')
+
+ args = parser.parse_args()
+ print('Resolving hostname '+args.host)
+ addrs = [ str(i[4][0]) for i in socket.getaddrinfo(args.host, None) ]
+ if len(addrs) == 0:
+ print('Found no IPs')
+ sys.exit(1)
+
+ print('Using IP '+addrs[0])
+
+ src = Source(addrs[0])
+ mainloop = GObject.MainLoop()
+ try:
+ mainloop.run()
+ except KeyboardInterrupt:
+ print('Terminated via Ctrl-C')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/voctocore/README.md b/voctocore/README.md
index ac98694..f5ed2c3 100644
--- a/voctocore/README.md
+++ b/voctocore/README.md
@@ -36,6 +36,7 @@ Also, if enabled in Config, another Building-Block is chained after the Main-Mix
\-> Encoder* -> PreviewPort* 14000…
9999 Control-Server
+9998 GstNetTimeProvider Network-Clock
*) only when [previews] enabled=true is configured
**) only when [stream-blanker] enabled=true is configured
diff --git a/voctocore/lib/audiomix.py b/voctocore/lib/audiomix.py
index 1c72ede..6c1768a 100644
--- a/voctocore/lib/audiomix.py
+++ b/voctocore/lib/audiomix.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from enum import Enum
from lib.config import Config
+from lib.clock import Clock
class AudioMix(object):
def __init__(self):
@@ -47,6 +48,7 @@ class AudioMix(object):
self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
self.mixingPipeline = Gst.parse_launch(pipeline)
+ self.mixingPipeline.use_clock(Clock)
self.log.debug('Binding Error & End-of-Stream-Signal on Mixing-Pipeline')
self.mixingPipeline.bus.add_signal_watch()
diff --git a/voctocore/lib/avpreviewoutput.py b/voctocore/lib/avpreviewoutput.py
index f757e1c..04ff637 100644
--- a/voctocore/lib/avpreviewoutput.py
+++ b/voctocore/lib/avpreviewoutput.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from lib.config import Config
from lib.tcpmulticonnection import TCPMultiConnection
+from lib.clock import Clock
class AVPreviewOutput(TCPMultiConnection):
def __init__(self, channel, port):
@@ -49,6 +50,7 @@ class AVPreviewOutput(TCPMultiConnection):
self.log.debug('Creating Output-Pipeline:\n%s', pipeline)
self.outputPipeline = Gst.parse_launch(pipeline)
+ self.outputPipeline.use_clock(Clock)
self.log.debug('Binding Error & End-of-Stream-Signal on Output-Pipeline')
self.outputPipeline.bus.add_signal_watch()
diff --git a/voctocore/lib/avrawoutput.py b/voctocore/lib/avrawoutput.py
index 62a03d2..60d2b37 100644
--- a/voctocore/lib/avrawoutput.py
+++ b/voctocore/lib/avrawoutput.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from lib.config import Config
from lib.tcpmulticonnection import TCPMultiConnection
+from lib.clock import Clock
class AVRawOutput(TCPMultiConnection):
def __init__(self, channel, port):
@@ -38,6 +39,7 @@ class AVRawOutput(TCPMultiConnection):
)
self.log.debug('Creating Output-Pipeline:\n%s', pipeline)
self.outputPipeline = Gst.parse_launch(pipeline)
+ self.outputPipeline.use_clock(Clock)
self.log.debug('Binding Error & End-of-Stream-Signal on Output-Pipeline')
self.outputPipeline.bus.add_signal_watch()
diff --git a/voctocore/lib/avsource.py b/voctocore/lib/avsource.py
index c9f4dea..f814c45 100644
--- a/voctocore/lib/avsource.py
+++ b/voctocore/lib/avsource.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from lib.config import Config
from lib.tcpsingleconnection import TCPSingleConnection
+from lib.clock import Clock
class AVSource(TCPSingleConnection):
def __init__(self, name, port, outputs=None, has_audio=True, has_video=True):
@@ -64,6 +65,7 @@ class AVSource(TCPSingleConnection):
self.log.debug('Launching Source-Pipeline:\n%s', pipeline)
self.receiverPipeline = Gst.parse_launch(pipeline)
+ self.receiverPipeline.use_clock(Clock)
self.log.debug('Binding End-of-Stream-Signal on Source-Pipeline')
self.receiverPipeline.bus.add_signal_watch()
diff --git a/voctocore/lib/clock.py b/voctocore/lib/clock.py
new file mode 100644
index 0000000..ed8152e
--- /dev/null
+++ b/voctocore/lib/clock.py
@@ -0,0 +1,15 @@
+#!/usr/bin/python3
+import logging
+from gi.repository import Gst, GstNet
+
+__all__ = ['Clock', 'NetTimeProvider']
+port = 9998
+
+log = logging.getLogger('Clock')
+
+log.debug("Obtaining System-Clock")
+Clock = Gst.SystemClock.obtain()
+log.info("Using System-Clock for all Pipelines: %s", Clock)
+
+log.info("Starting NetTimeProvider on Port %u", port)
+NetTimeProvider = GstNet.NetTimeProvider.new(Clock, None, port)
diff --git a/voctocore/lib/streamblanker.py b/voctocore/lib/streamblanker.py
index b3f460c..fea3d6a 100644
--- a/voctocore/lib/streamblanker.py
+++ b/voctocore/lib/streamblanker.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from enum import Enum
from lib.config import Config
+from lib.clock import Clock
class StreamBlanker(object):
log = logging.getLogger('StreamBlanker')
@@ -53,6 +54,7 @@ class StreamBlanker(object):
self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
self.mixingPipeline = Gst.parse_launch(pipeline)
+ self.mixingPipeline.use_clock(Clock)
self.log.debug('Binding Error & End-of-Stream-Signal on Mixing-Pipeline')
self.mixingPipeline.bus.add_signal_watch()
diff --git a/voctocore/lib/videomix.py b/voctocore/lib/videomix.py
index 98614db..7ff98c2 100644
--- a/voctocore/lib/videomix.py
+++ b/voctocore/lib/videomix.py
@@ -3,6 +3,7 @@ from gi.repository import Gst
from enum import Enum, unique
from lib.config import Config
+from lib.clock import Clock
@unique
class CompositeModes(Enum):
@@ -71,6 +72,7 @@ class VideoMix(object):
self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
self.mixingPipeline = Gst.parse_launch(pipeline)
+ self.mixingPipeline.use_clock(Clock)
self.log.debug('Binding Error & End-of-Stream-Signal on Mixing-Pipeline')
self.mixingPipeline.bus.add_signal_watch()
diff --git a/voctocore/voctocore.py b/voctocore/voctocore.py
index 39def6a..b1955e0 100755
--- a/voctocore/voctocore.py
+++ b/voctocore/voctocore.py
@@ -3,7 +3,7 @@ import gi, signal, logging, sys
# import GStreamer and GLib-Helper classes
gi.require_version('Gst', '1.0')
-from gi.repository import Gst, GObject
+from gi.repository import Gst, GstNet, GObject
# check min-version
minGst = (1, 5)
diff --git a/voctogui/lib/clock.py b/voctogui/lib/clock.py
new file mode 100644
index 0000000..9075bdc
--- /dev/null
+++ b/voctogui/lib/clock.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python3
+import logging
+from gi.repository import Gst, GstNet
+
+__all__ = ['Clock']
+port = 9998
+
+log = logging.getLogger('Clock')
+Clock = None
+
+def obtainClock(host):
+ global log, Clock, SystemClock
+
+ log.debug('obtaining NetClientClock from host %s', host)
+ Clock = GstNet.NetClientClock.new('voctocore', host, port, 0)
+ log.debug('obtained NetClientClock from host %s: %s', host, Clock)
+
+ log.debug('waiting for NetClientClock to sync to host')
+ Clock.wait_for_sync(Gst.CLOCK_TIME_NONE)
+ log.info('successfully synced NetClientClock to host')
diff --git a/voctogui/lib/connection.py b/voctogui/lib/connection.py
index 6a9c025..6f8245f 100644
--- a/voctogui/lib/connection.py
+++ b/voctogui/lib/connection.py
@@ -7,17 +7,21 @@ from gi.repository import Gtk, GObject
log = logging.getLogger('Connection')
conn = None
+ip = None
port = 9999
command_queue = Queue()
signal_handlers = {}
def establish(host):
- global conn, port, log
+ global conn, port, log, ip
log.info('establishing Connection to %s', host)
conn = socket.create_connection( (host, port) )
log.debug('Connection successful \o/')
+ ip = conn.getpeername()[0]
+ log.debug('Remote-IP is %s', ip)
+
def fetchServerConfig():
global conn, log
diff --git a/voctogui/lib/videodisplay.py b/voctogui/lib/videodisplay.py
index 8ce1413..9a02658 100644
--- a/voctogui/lib/videodisplay.py
+++ b/voctogui/lib/videodisplay.py
@@ -2,6 +2,7 @@ import logging
from gi.repository import Gst
from lib.config import Config
+from lib.clock import Clock
class VideoDisplay(object):
""" Displays a Voctomix-Video-Stream into a GtkWidget """
@@ -92,7 +93,7 @@ class VideoDisplay(object):
if play_audio:
# ts-offset=1000000000 (1s) - should keep audio & video in sync but delay by 1s
pipeline += """
- alsasink sync=False
+ alsasink
"""
# Otherwise just trash the Audio
@@ -111,6 +112,7 @@ class VideoDisplay(object):
self.log.debug('Creating Display-Pipeline:\n%s', pipeline)
self.pipeline = Gst.parse_launch(pipeline)
+ self.pipeline.use_clock(Clock)
self.drawing_area.realize()
self.xid = self.drawing_area.get_property('window').get_xid()
diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py
index 0853898..d6bf5b6 100755
--- a/voctogui/voctogui.py
+++ b/voctogui/voctogui.py
@@ -32,6 +32,7 @@ from lib.ui import Ui
from lib.loghandler import LogHandler
import lib.connection as Connection
+import lib.clock as ClockManager
# main class
class Voctogui(object):
@@ -125,6 +126,9 @@ def main():
Config.get('server', 'host')
)
+ # obtain network-clock
+ ClockManager.obtainClock(Connection.ip)
+
# switch connection to nonblocking, event-driven mode
Connection.enterNonblockingMode()