From 5e301fd1a88acf698f1918ddf8ea5981d12ac811 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 27 Jan 2016 12:11:28 +0100 Subject: force all pipelines to the same clock and expose it to the network, #46 --- voctocore/README.md | 1 + voctocore/lib/audiomix.py | 2 ++ voctocore/lib/avpreviewoutput.py | 2 ++ voctocore/lib/avrawoutput.py | 2 ++ voctocore/lib/avsource.py | 2 ++ voctocore/lib/clock.py | 15 +++++++++++++++ voctocore/lib/streamblanker.py | 2 ++ voctocore/lib/videomix.py | 2 ++ voctocore/voctocore.py | 2 +- 9 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 voctocore/lib/clock.py 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) -- cgit v1.2.3 From aa2e12b92df3400e6f9cb89afc16eb968b0c2491 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 27 Jan 2016 12:25:53 +0100 Subject: use the server-net-clock in the gui --- voctogui/lib/clock.py | 19 +++++++++++++++++++ voctogui/lib/connection.py | 6 +++++- voctogui/lib/videodisplay.py | 2 ++ voctogui/voctogui.py | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 voctogui/lib/clock.py diff --git a/voctogui/lib/clock.py b/voctogui/lib/clock.py new file mode 100644 index 0000000..8fdbe3d --- /dev/null +++ b/voctogui/lib/clock.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +import logging +from gi.repository import Gst, GstNet + +__all__ = ['Clock'] +port = 9998 + +log = logging.getLogger('Clock') +Clock = None + +log.debug("Obtaining System-Clock") +SystemClock = Gst.SystemClock.obtain() + +def obtainClock(host): + global log, Clock + + log.debug('obtaining NetClientClock from host %s', host) + Clock = GstNet.NetClientClock.new('voctocore', host, port, 0) + log.info('obtained NetClientClock from host %s: %s', host, Clock) 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..18ea3bb 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 """ @@ -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() -- cgit v1.2.3 From 4f561f1d5ba5cd3430ffb987eee65105133e793e Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 27 Jan 2016 12:35:07 +0100 Subject: base gui-time on gui-system-clock --- voctogui/lib/clock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/voctogui/lib/clock.py b/voctogui/lib/clock.py index 8fdbe3d..862c2d5 100644 --- a/voctogui/lib/clock.py +++ b/voctogui/lib/clock.py @@ -12,8 +12,8 @@ log.debug("Obtaining System-Clock") SystemClock = Gst.SystemClock.obtain() def obtainClock(host): - global log, Clock + global log, Clock, SystemClock log.debug('obtaining NetClientClock from host %s', host) - Clock = GstNet.NetClientClock.new('voctocore', host, port, 0) + Clock = GstNet.NetClientClock.new('voctocore', host, port, SystemClock.get_time()) log.info('obtained NetClientClock from host %s: %s', host, Clock) -- cgit v1.2.3 From 757572f64d10172341b60191dcbfe7ba280bd286 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 27 Jan 2016 12:36:12 +0100 Subject: add source-example with network-time client --- ...source-videotestsrc-as-cam1-with-networktime.py | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py diff --git a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py new file mode 100755 index 0000000..cf3870c --- /dev/null +++ b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +import sys, gi, signal + +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): + # 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=192,height=108,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=127.0.0.1 port=10000 + """ + + clock = Gst.SystemClock.obtain() + self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 9998, clock.get_time()) + print('obtained NetClientClock from host', self.clock) + + 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) + + src = Source() + + mainloop = GObject.MainLoop() + try: + mainloop.run() + except KeyboardInterrupt: + print('Terminated via Ctrl-C') + + +if __name__ == '__main__': + main() -- cgit v1.2.3 From 6bc0e4f5733c2abb6aaf85bb3e0ec2cab4322a7c Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 11:19:43 +0100 Subject: remove unnecessary slashes --- .../source-videotestsrc-as-cam1-with-networktime.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py index cf3870c..63ee180 100755 --- a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py +++ b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py @@ -12,16 +12,16 @@ class Source(object): def __init__(self): # it works much better with a local file pipeline = """ - videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 !\ + videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 ! timeoverlay ! - video/x-raw,format=I420,width=192,height=108,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 !\ + video/x-raw,format=I420,width=192,height=108,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=127.0.0.1 port=10000 """ -- cgit v1.2.3 From 60e205cb92e7127742b42ff0e5c0bbc06df1d0e5 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 11:21:52 +0100 Subject: fix example resolution --- .../gstreamer/source-videotestsrc-as-cam1-with-networktime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py index 63ee180..b07bf55 100755 --- a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py +++ b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py @@ -14,7 +14,7 @@ class Source(object): pipeline = """ videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 ! timeoverlay ! - video/x-raw,format=I420,width=192,height=108,framerate=25/1,pixel-aspect-ratio=1/1 ! + video/x-raw,format=I420,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 ! mux. audiotestsrc freq=330 ! -- cgit v1.2.3 From c64ce93a9f2a85bcaafe8fddf1b591f1ba618d32 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 11:22:26 +0100 Subject: wait until clock-sync --- .../gstreamer/source-videotestsrc-as-cam1-with-networktime.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py index b07bf55..441a129 100755 --- a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py +++ b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py @@ -25,10 +25,13 @@ class Source(object): tcpclientsink host=127.0.0.1 port=10000 """ - clock = Gst.SystemClock.obtain() - self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 9998, clock.get_time()) + self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 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') -- cgit v1.2.3 From 049b95862fe7d751b40c5e448471226c8063f3d8 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 12:19:13 +0100 Subject: sync gui-clock --- voctogui/lib/clock.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/voctogui/lib/clock.py b/voctogui/lib/clock.py index 862c2d5..9075bdc 100644 --- a/voctogui/lib/clock.py +++ b/voctogui/lib/clock.py @@ -8,12 +8,13 @@ port = 9998 log = logging.getLogger('Clock') Clock = None -log.debug("Obtaining System-Clock") -SystemClock = Gst.SystemClock.obtain() - def obtainClock(host): global log, Clock, SystemClock log.debug('obtaining NetClientClock from host %s', host) - Clock = GstNet.NetClientClock.new('voctocore', host, port, SystemClock.get_time()) - log.info('obtained NetClientClock from host %s: %s', host, Clock) + 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') -- cgit v1.2.3 From 23fdb289436d792557227ec4d445636b2808de2d Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 12:27:27 +0100 Subject: rename source and make hostname a parameter --- .../source-remote-videotestsrc-as-cam1.py | 85 ++++++++++++++++++++++ ...source-videotestsrc-as-cam1-with-networktime.py | 71 ------------------ 2 files changed, 85 insertions(+), 71 deletions(-) create mode 100755 example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py delete mode 100755 example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py 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/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py b/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py deleted file mode 100755 index 441a129..0000000 --- a/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python3 -import sys, gi, signal - -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): - # 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=1920,height=1080,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=127.0.0.1 port=10000 - """ - - self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 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) - - src = Source() - - mainloop = GObject.MainLoop() - try: - mainloop.run() - except KeyboardInterrupt: - print('Terminated via Ctrl-C') - - -if __name__ == '__main__': - main() -- cgit v1.2.3 From 95f72ae9ff3f616484000e30e8d6a0f1b273ff6d Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 28 Jan 2016 13:06:20 +0100 Subject: add an example streaming live-video-content from a remote-location --- .../gstreamer/source-remote-desktop-as-cam1.py | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 example-scripts/gstreamer/source-remote-desktop-as-cam1.py 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() -- cgit v1.2.3 From 54775670b049a338d97b57218d36da00d778b432 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Thu, 4 Feb 2016 17:46:02 +0100 Subject: default to sync audio out --- voctogui/lib/videodisplay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voctogui/lib/videodisplay.py b/voctogui/lib/videodisplay.py index 18ea3bb..9a02658 100644 --- a/voctogui/lib/videodisplay.py +++ b/voctogui/lib/videodisplay.py @@ -93,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 -- cgit v1.2.3