From af109381c129e8e04abbdd3d65b33590817ffab6 Mon Sep 17 00:00:00 2001 From: ComputerTech Date: Tue, 10 Mar 2026 19:32:24 +0000 Subject: [PATCH] Reduce buffering: 250ms DJ chunks, 1024-chunk preroll, X-Accel-Buffering header --- script.js | 6 ++++-- server.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 528a0cc..ecd269c 100644 --- a/script.js +++ b/script.js @@ -2211,10 +2211,12 @@ function startBroadcast() { } }; - // 1000ms chunks: Dramatically reduces CPU interrupts on low-RAM machines + // 250ms chunks: More frequent smaller chunks reduces stall gaps on weak connections. + // A 1-second chunk creates a 1-second starvation gap if the network hiccups; + // 250ms chunks keep the server fed 4x more often. // Validate state before starting if (mediaRecorder.state === 'inactive') { - mediaRecorder.start(1000); + mediaRecorder.start(250); streamProcessor = mediaRecorder; console.log('[OK] MediaRecorder started in state:', mediaRecorder.state); } else { diff --git a/server.py b/server.py index ecd03df..cd58571 100644 --- a/server.py +++ b/server.py @@ -67,7 +67,7 @@ _mp3_lock = threading.Lock() _transcoder_bytes_out = 0 _transcoder_last_error = None _last_audio_chunk_ts = 0.0 -_mp3_preroll = collections.deque(maxlen=512) +_mp3_preroll = collections.deque(maxlen=1024) # ~83s at 96kbps for fast reconnect buffer fill def _start_transcoder_if_needed(is_mp3_input=False): @@ -486,6 +486,7 @@ def setup_shared_routes(app, index_file='index.html'): 'X-Content-Type-Options': 'nosniff', 'Access-Control-Allow-Origin': '*', 'Icy-Name': 'TechDJ Live', + 'X-Accel-Buffering': 'no', # Tell nginx/Cloudflare not to buffer this stream }) @app.route('/stream_debug')