From cf946b98da7f57659fac43e56e0dd639d28e0ec0 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 9 Jun 2025 01:04:45 +0200 Subject: [PATCH] add audio engine and tools in py script --- bin/streaming/telecaster.py | 74 +++++++++++++++++++++++++++++++------ bin/streaming/telecaster.sh | 8 ++-- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/bin/streaming/telecaster.py b/bin/streaming/telecaster.py index ae4ed3a..ba96b0f 100755 --- a/bin/streaming/telecaster.py +++ b/bin/streaming/telecaster.py @@ -13,18 +13,18 @@ from copy import deepcopy VIDEO_PIPELINE_BASE="""{video_source} {video_options} \ ! {format}, width={width}, height={height}, framerate={framerate}/1 \ ! {decoder} \ - ! videoflip method={flip} \ - ! videoconvert \ - ! vp8enc threads=4 deadline=2 target-bitrate={vp8_bitrate} \ + ! queue ! videoflip method={flip} \ + ! queue ! videoconvert \ + ! queue ! vp8enc threads=4 deadline=2 target-bitrate={vp8_bitrate} \ ! muxout. \ {audio_source} {audio_options} client-name="webm_streaming_{id}_audio" ! audio/x-raw, format=F32LE, channels={channels} \ - ! audiocheblimit mode=high-pass cutoff=120 poles=4 \ - ! volume volume={gain_pre} \ - ! audiodynamic characteristics=soft-knee mode=compressor threshold=0.125 ratio=0.125 \ - ! volume volume={gain_post} \ - ! audiodynamic characteristics=hard-knee mode=compressor threshold=0.95 ratio=0.001 \ - ! audioconvert \ - ! opusenc bitrate={opus_bitrate} \ + ! queue ! audiocheblimit mode=high-pass cutoff=120 poles=4 \ + ! queue ! volume volume={gain_pre} \ + ! queue ! audiodynamic characteristics=soft-knee mode=compressor threshold=0.125 ratio=0.125 \ + ! queue ! volume volume={gain_post} \ + ! queue ! audiodynamic characteristics=hard-knee mode=compressor threshold=0.95 ratio=0.001 \ + ! queue ! audioconvert \ + ! queue ! opusenc bitrate={opus_bitrate} \ ! muxout. \ webmmux streamable=true name=muxout \ ! queue ! shout2send ip={ip} port={port} password={password} mount=telecaster_live_{id}.webm > /dev/null @@ -42,17 +42,26 @@ AUDIO_PIPELINE_BASE="""{audio_source} {audio_options} \ ! queue ! shout2send ip={ip} port={port} password={password} mount=telecaster_live.mp3 > /dev/null """ -BOOT_TIME_DELAY = 0 +BOOT_TIME_DELAY = 1 DEFAULT_CONFIG_FILE = "/etc/telecaster/telecaster.yml" +JACK_CONFIG = {"engine": "jackd", + "options": "-R -P50 -dalsa -r48000 -p1024 -n3 -Chw:3 -Phw:3", + "tools": ["catia", "konsole"]} + +PIPEWIRE_CONFIG = {"engine": "pipewire", + "options": "", + "tools": ["qpwgraph", "konsole"]} + + class TeleCasterGStream(Thread): def __init__(self, pipeline): Thread.__init__(self) self.pipeline = pipeline - print(self.pipeline) + # print(self.pipeline) def run(self): os.system('gst-launch-1.0 ' + self.pipeline + ' & ') @@ -68,6 +77,25 @@ class TeleCasterDeeFuzzer(Thread): os.system('deefuzzer ' + self.conf_file + ' & ') +class TeleCasterThreadedCommand(Thread): + + def __init__(self, command): + Thread.__init__(self) + self.command = command + + def run(self): + os.system(self.command + ' & ') + + +class TeleCasterCommand: + + def __init__(self, command): + self.command = command + + def start(self): + os.system(self.command + ' & ') + + class TeleCaster(Thread): def __init__(self, conf_file_path): @@ -78,6 +106,11 @@ class TeleCaster(Thread): self.deefuzzer_video_conf_file = "/tmp/telecaster_deefuzzer_webm_monitor.yml" self.deefuzzer_audio_conf_file = "/tmp/telecaster_deefuzzer_mp3_monitor.yml" # print(self.conf) + audio_source = self.conf["audio"]["gstreamer"]["audio_source"] + if "pipewire" in audio_source: + audio_config = PIPEWIRE_CONFIG + elif "jack" in audio_source: + audio_config = JACK_CONFIG def write_conf(self, conf_dict, path): filename, ext = os.path.splitext(path) @@ -94,6 +127,21 @@ class TeleCaster(Thread): # print(args) subprocess.call(command, shell=True) + def audio_engine_start(self): + command = self.audio_config["engine"] + " " + self.audio_config["options"] + thread = TeleCasterCommand(command) + Thread.start() + + def audio_engine_start(self): + command = self.audio_config["engine"] + " " + self.audio_config["options"] + thread = TeleCasterCommand(command) + Thread.start() + + def audio_tools_start(self): + for tool in self.audio_config["tools"]: + command = TeleCasterCommand(tool) + command.start() + def deefuzzer_start(self, conf, conf_file): # print(self.conf) self.write_conf(conf, conf_file) @@ -165,6 +213,8 @@ class TeleCaster(Thread): self.deefuzzer_start(deefuzzer_global_conf, self.deefuzzer_audio_conf_file) def run(self): + self.audio_engine_start() + self.audio_tools_start() self.video_start() self.audio_start() diff --git a/bin/streaming/telecaster.sh b/bin/streaming/telecaster.sh index f9c4580..433a826 100755 --- a/bin/streaming/telecaster.sh +++ b/bin/streaming/telecaster.sh @@ -6,7 +6,7 @@ set -e #TELECASTER_PATH=/srv/telecaster/telecaster-server/ #XDG_RUNTIME_DIR="/run/user/1000" -konsole & +# konsole & # AUDIO @@ -19,9 +19,9 @@ konsole & # qpwgraph & # JACK -jackd $JACK_OPTIONS & -qjackctl & -catia & +# jackd $JACK_OPTIONS & +# qjackctl & +# catia & #sleep 2 -- 2.39.5