diff options
-rwxr-xr-x | example-scripts/control-server/generate-cut-list.py | 1 | ||||
-rwxr-xr-x | example-scripts/ffmpeg/source-nostream-music.sh | 2 | ||||
-rwxr-xr-x | example-scripts/gstreamer/source-background-loop.py | 18 | ||||
-rwxr-xr-x | example-scripts/gstreamer/source-remote-desktop-as-cam1.py | 96 | ||||
-rwxr-xr-x | example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py | 91 | ||||
-rw-r--r-- | voctocore/README.md | 1 | ||||
-rw-r--r-- | voctocore/lib/audiomix.py | 2 | ||||
-rw-r--r-- | voctocore/lib/avpreviewoutput.py | 13 | ||||
-rw-r--r-- | voctocore/lib/avrawoutput.py | 11 | ||||
-rw-r--r-- | voctocore/lib/avsource.py | 4 | ||||
-rw-r--r-- | voctocore/lib/clock.py | 15 | ||||
-rw-r--r-- | voctocore/lib/streamblanker.py | 2 | ||||
-rw-r--r-- | voctocore/lib/videomix.py | 2 | ||||
-rwxr-xr-x | voctocore/voctocore.py | 2 | ||||
-rw-r--r-- | voctogui/README.md | 7 | ||||
-rw-r--r-- | voctogui/lib/clock.py | 20 | ||||
-rw-r--r-- | voctogui/lib/connection.py | 6 | ||||
-rw-r--r-- | voctogui/lib/toolbar/misc.py | 8 | ||||
-rw-r--r-- | voctogui/lib/videodisplay.py | 9 | ||||
-rwxr-xr-x | voctogui/voctogui.py | 4 |
20 files changed, 291 insertions, 23 deletions
diff --git a/example-scripts/control-server/generate-cut-list.py b/example-scripts/control-server/generate-cut-list.py index 23a0b33..959ab58 100755 --- a/example-scripts/control-server/generate-cut-list.py +++ b/example-scripts/control-server/generate-cut-list.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import socket import datetime import sys diff --git a/example-scripts/ffmpeg/source-nostream-music.sh b/example-scripts/ffmpeg/source-nostream-music.sh index 5f10caf..23db81d 100755 --- a/example-scripts/ffmpeg/source-nostream-music.sh +++ b/example-scripts/ffmpeg/source-nostream-music.sh @@ -9,4 +9,6 @@ while true; do -c:a pcm_s16le \ -f matroska \ tcp://localhost:18000 + + sleep 1; done diff --git a/example-scripts/gstreamer/source-background-loop.py b/example-scripts/gstreamer/source-background-loop.py index 8b65088..2f13edf 100755 --- a/example-scripts/gstreamer/source-background-loop.py +++ b/example-scripts/gstreamer/source-background-loop.py @@ -1,4 +1,5 @@ -import sys, gi, signal +#!/usr/bin/env python3 +import os, sys, gi, signal gi.require_version('Gst', '1.0') from gi.repository import Gst, GObject @@ -8,17 +9,18 @@ GObject.threads_init() Gst.init([]) class LoopSource(object): - def __init__(self): + def __init__(self, settings): # it works much better with a local file pipeline = """ uridecodebin name=src uri=http://c3voc.mazdermind.de/testfiles/bg.ts ! videoscale ! videoconvert ! - video/x-raw,format=I420,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 ! + video/x-raw,format=I420,width={WIDTH},height={HEIGHT},framerate={FRAMERATE}/1,pixel-aspect-ratio=1/1 ! matroskamux ! tcpclientsink host=localhost port=16000 - """ + """.format_map(settings) + print('starting pipeline '+pipeline) self.senderPipeline = Gst.parse_launch(pipeline) self.src = self.senderPipeline.get_by_name('src') @@ -52,7 +54,13 @@ class LoopSource(object): def main(): signal.signal(signal.SIGINT, signal.SIG_DFL) - src = LoopSource() + config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.sh') + with open(config, 'r') as config: + lines = [ line.strip() for line in config if line[0] != '#' ] + pairs = [ line.split('=', 1) for line in lines ] + settings = { pair[0]: pair[1] for pair in pairs } + + src = LoopSource(settings) mainloop = GObject.MainLoop() try: 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..7d1c7f2 --- /dev/null +++ b/example-scripts/gstreamer/source-remote-desktop-as-cam1.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 +import os, 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, settings): + pipeline = """ + ximagesrc use-damage=0 startx=0 starty=0 endx=1919 endy=1079 ! + queue ! + videoscale ! + videorate ! + timeoverlay ! + videoconvert ! + video/x-raw,format=I420,width={WIDTH},height={HEIGHT},framerate={FRAMERATE}/1,pixel-aspect-ratio=1/1 ! + queue ! + mux. + + pulsesrc ! + audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate={AUDIORATE} ! + queue ! + mux. + + matroskamux name=mux ! + tcpclientsink host={IP} port=10000 + """.format_map(settings) + + self.clock = GstNet.NetClientClock.new('voctocore', settings['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 '+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]) + + config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.sh') + with open(config) as config: + lines = [ line.strip() for line in config if line[0] != '#' ] + pairs = [ line.split('=', 1) for line in lines ] + settings = { pair[0]: pair[1] for pair in pairs } + + settings['IP'] = addrs[0] + + src = Source(settings) + 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..5404add --- /dev/null +++ b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +import os, 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, settings): + # 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_map(settings) + + self.clock = GstNet.NetClientClock.new('voctocore', settings['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 '+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]) + + config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.sh') + with open(config) as config: + lines = [ line.strip() for line in config if line[0] != '#' ] + pairs = [ line.split('=', 1) for line in lines ] + settings = { pair[0]: pair[1] for pair in pairs } + + settings['IP'] = addrs[0] + + src = Source(settings) + 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..ac5fd0a 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): @@ -17,11 +18,6 @@ class AVPreviewOutput(TCPMultiConnection): vcaps_out = Config.get('mix', 'videocaps') pipeline = """ - interaudiosrc channel=audio_{channel} ! - {acaps} ! - queue ! - mux. - intervideosrc channel=video_{channel} ! {vcaps_in} ! videorate ! @@ -31,12 +27,18 @@ class AVPreviewOutput(TCPMultiConnection): queue ! mux. + interaudiosrc channel=audio_{channel} ! + {acaps} ! + queue ! + mux. + matroskamux name=mux streamable=true writing-app=Voctomix-AVPreviewOutput ! multifdsink + blocksize=1048576 buffers-max=500 sync-method=next-keyframe name=fd @@ -49,6 +51,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..4603c30 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): @@ -12,13 +13,13 @@ class AVRawOutput(TCPMultiConnection): self.channel = channel pipeline = """ - interaudiosrc channel=audio_{channel} ! - {acaps} ! + intervideosrc channel=video_{channel} ! + {vcaps} ! queue ! mux. - intervideosrc channel=video_{channel} ! - {vcaps} ! + interaudiosrc channel=audio_{channel} ! + {acaps} ! queue ! mux. @@ -28,6 +29,7 @@ class AVRawOutput(TCPMultiConnection): writing-app=Voctomix-AVRawOutput ! multifdsink + blocksize=1048576 buffers-max=500 sync-method=next-keyframe name=fd @@ -38,6 +40,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..aa604b2 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): @@ -21,7 +22,7 @@ class AVSource(TCPSingleConnection): def on_accepted(self, conn, addr): pipeline = """ - fdsrc fd={fd} ! + fdsrc fd={fd} blocksize=1048576 ! queue ! matroskademux name=demux """.format( @@ -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/README.md b/voctogui/README.md index 7283da0..156a086 100644 --- a/voctogui/README.md +++ b/voctogui/README.md @@ -6,8 +6,8 @@ ### Composition Modes - `F1` Fullscreen - `F2` Picture in Picture -- `F1` Side-by-Side Equal -- `F1` Side-by-Side Preview +- `F3` Side-by-Side Equal +- `F4` Side-by-Side Preview ### Select A-Source - `1` Source Nr. 1 @@ -19,5 +19,8 @@ - `Ctrl+2` Source Nr. 2 - … +### Other options +- `t` Cut + ### Select an Audio-Source Click twice on the Selection Combobox, the select your Source within 5 Seconds (It will auto-lock again after 5 Seconds) 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/toolbar/misc.py b/voctogui/lib/toolbar/misc.py index 32dd96c..9528b67 100644 --- a/voctogui/lib/toolbar/misc.py +++ b/voctogui/lib/toolbar/misc.py @@ -4,12 +4,17 @@ from gi.repository import Gtk from lib.config import Config import lib.connection as Connection + class MiscToolbarController(object): """ Manages Accelerators and Clicks Misc buttons """ def __init__(self, drawing_area, win, uibuilder): self.log = logging.getLogger('MiscToolbarController') + # Accelerators + accelerators = Gtk.AccelGroup() + win.add_accel_group(accelerators) + closebtn = uibuilder.find_widget_recursive(drawing_area, 'close') closebtn.set_visible( Config.getboolean('misc', 'close') ) closebtn.connect('clicked', self.on_closebtn_clicked) @@ -18,6 +23,9 @@ class MiscToolbarController(object): cutbtn.set_visible( Config.getboolean('misc', 'cut') ) cutbtn.connect('clicked', self.on_cutbtn_clicked) + key, mod = Gtk.accelerator_parse('t') + cutbtn.add_accelerator('clicked', accelerators, key, mod, Gtk.AccelFlags.VISIBLE) + def on_closebtn_clicked(self, btn): self.log.info('close-button clicked') Gtk.main_quit() diff --git a/voctogui/lib/videodisplay.py b/voctogui/lib/videodisplay.py index 8ce1413..78dafba 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 """ @@ -24,7 +25,7 @@ class VideoDisplay(object): # Setup Server-Connection, Demuxing and Decoding pipeline = """ - tcpclientsrc host={host} port={port} ! + tcpclientsrc host={host} port={port} blocksize=1048576 ! queue ! matroskademux name=demux """ @@ -88,11 +89,10 @@ class VideoDisplay(object): level name=lvl interval=50000000 ! """ - # If Playback is requested, push fo alsa + # If Playback is requested, push fo pulseaudio if play_audio: - # ts-offset=1000000000 (1s) - should keep audio & video in sync but delay by 1s pipeline += """ - alsasink sync=False + pulsesink """ # Otherwise just trash the Audio @@ -111,6 +111,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() |