zebra-report: deploy always-SFU receive audio + 0.7s worklet cushion
Pulls in zebra-report 1984bb1: SFU is the only receive-audio path for every role, mesh inbound audio ignored. SPEAKER_PLAYOUT_DELAY_SEC 0.5s → 0.7s.
This commit is contained in:
parent
faa52b4871
commit
9818f0860f
1 changed files with 14 additions and 135 deletions
|
|
@ -3036,7 +3036,7 @@ const DD_JITTER_THRESH_SEC = 0.030; /* > 30ms = unstable */
|
||||||
const DD_UNSTABLE_SAMPLES_NEEDED = 2;
|
const DD_UNSTABLE_SAMPLES_NEEDED = 2;
|
||||||
const DD_CLEAN_SAMPLES_NEEDED = 6; /* 6 × 5s = 30s clean → recover */
|
const DD_CLEAN_SAMPLES_NEEDED = 6; /* 6 × 5s = 30s clean → recover */
|
||||||
const DD_TELEMETRY_TICK_SEC = 5;
|
const DD_TELEMETRY_TICK_SEC = 5;
|
||||||
const DD_BASE_TARGET_SEC = 0.5; /* speaker minimum on stable feed */
|
const DD_BASE_TARGET_SEC = 0.7; /* speaker minimum on stable feed */
|
||||||
const DD_BASE_LISTENER_TARGET_SEC = 1.3; /* listener minimum on stable high-quality feed — fox 2026-06-05 */
|
const DD_BASE_LISTENER_TARGET_SEC = 1.3; /* listener minimum on stable high-quality feed — fox 2026-06-05 */
|
||||||
const DD_MAX_TARGET_SEC = 4.0; /* maximum cushion under instability — same ceiling for everyone */
|
const DD_MAX_TARGET_SEC = 4.0; /* maximum cushion under instability — same ceiling for everyone */
|
||||||
/* Self-calibrating floor: after a wiggle, the floor for THAT publisher
|
/* Self-calibrating floor: after a wiggle, the floor for THAT publisher
|
||||||
|
|
@ -3675,14 +3675,14 @@ const VIDEO_REMOVE_MUTE_WINDOW_SCREEN_MS = 120000;
|
||||||
* out wiggle-stalls without a glitch. Big enough to survive any
|
* out wiggle-stalls without a glitch. Big enough to survive any
|
||||||
* realistic publisher-side hiccup. */
|
* realistic publisher-side hiccup. */
|
||||||
const RECV_PLAYOUT_DELAY_SEC = 4.0;
|
const RECV_PLAYOUT_DELAY_SEC = 4.0;
|
||||||
/* Speaker/cohost/host INITIAL cushion — 0.5s for conversational
|
/* Speaker/cohost/host INITIAL cushion — 0.7s. Enough to absorb a
|
||||||
* latency, then the Double Dragon adaptive controller grows it to
|
* 200ms host wiggle through SFU's worklet unaided. Double Dragon
|
||||||
* DD_MAX_TARGET_SEC (4s) when the publisher's network or encoder
|
* adaptive controller grows it to DD_MAX_TARGET_SEC (4s) under
|
||||||
* shows instability and shrinks it back to DD_BASE_TARGET_SEC (0.5s)
|
* publisher instability and shrinks it back to DD_BASE_TARGET_SEC
|
||||||
* during sustained clean periods. The worklet's ±6% rate-limited
|
* during sustained clean periods. The worklet's ±6% rate-limited
|
||||||
* resampling makes the transition smooth: brief ≤1 semitone pitch
|
* resampling makes the transition smooth: brief ≤1 semitone pitch
|
||||||
* shift during the ramp, silence-free, click-free. */
|
* shift during the ramp, silence-free, click-free. */
|
||||||
const SPEAKER_PLAYOUT_DELAY_SEC = 0.5;
|
const SPEAKER_PLAYOUT_DELAY_SEC = 0.7;
|
||||||
/* HTTP /stream estimated end-to-end delay used for lip-sync when the
|
/* HTTP /stream estimated end-to-end delay used for lip-sync when the
|
||||||
* per-speaker stream toggle is ON for a publisher. The actual delay
|
* per-speaker stream toggle is ON for a publisher. The actual delay
|
||||||
* varies (~1-3s depending on browser buffer + network), so this is a
|
* varies (~1-3s depending on browser buffer + network), so this is a
|
||||||
|
|
@ -4893,24 +4893,8 @@ function handleRemoteSfuTrack(ev){
|
||||||
registerLipSyncAudio(pubHex, uuid, ev.receiver);
|
registerLipSyncAudio(pubHex, uuid, ev.receiver);
|
||||||
sfuAudioReceivers.set(pubHex, ev.receiver);
|
sfuAudioReceivers.set(pubHex, ev.receiver);
|
||||||
}
|
}
|
||||||
/* speakers get their peers' audio via mesh (lower latency)
|
/* SFU is the only receive-audio path for every role,
|
||||||
* AT THE TIMES THE MESH PC IS CONNECTED. A stale or failing
|
* including speakers. Mesh PCs carry our outbound mic only. */
|
||||||
* mesh PC must NOT block the SFU fallback — that's how the
|
|
||||||
* 'phone re-promoted but nobody hears them' regression
|
|
||||||
* appeared: the peers map still had an entry whose state
|
|
||||||
* was 'failed', so we skipped SFU and the receiver got no
|
|
||||||
* audio at all. */
|
|
||||||
if (canSpeak(myRole)){
|
|
||||||
const meshPC = peers.get(uuid);
|
|
||||||
const meshState = meshPC ? meshPC.connectionState : 'none';
|
|
||||||
if (meshPC && meshState === 'connected'){
|
|
||||||
logLine('', 'sfu mic skipped for '+uuid+' — mesh peer connected');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (meshPC){
|
|
||||||
logLine('', 'sfu mic taking over for '+uuid+' — mesh state='+meshState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attachSfuTrack(uuid, s);
|
attachSfuTrack(uuid, s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -6769,93 +6753,10 @@ async function connectToPeer(uuid, weOffer){
|
||||||
for (const tr of micStream.getTracks()){ tagTrack(tr); pc.addTrack(tr, micStream); }
|
for (const tr of micStream.getTracks()){ tagTrack(tr); pc.addTrack(tr, micStream); }
|
||||||
setSenderBitrate(pc.getSenders().find(s=>s.track && s.track.kind==='audio'));
|
setSenderBitrate(pc.getSenders().find(s=>s.track && s.track.kind==='audio'));
|
||||||
pc.ontrack = (ev) => {
|
pc.ontrack = (ev) => {
|
||||||
/* SFU and mesh both feed the SAME worklet now. The SFU stream
|
/* Mesh inbound audio is ignored — the SFU-fed worklet is the
|
||||||
* was already routed there by attachSfuTrack; we swap in the
|
* single receive-audio path. The mesh PC carries our outbound
|
||||||
* mesh stream so the worklet's buffer absorbs wiggle-glitches
|
* mic only. */
|
||||||
* for mesh too. Without this, mesh's native ~50ms buffer was no
|
logLine('', 'mesh ontrack for '+uuid.slice(0,4)+' — SFU is the receive path');
|
||||||
* cushion at all — a 200ms host stall caused mesh listeners to
|
|
||||||
* glitch while SFU listeners didn't. Now both share the worklet
|
|
||||||
* cushion (0.5s for speakers). Source swap is seamless because
|
|
||||||
* the worklet's queue holds 0.5s of decoded samples and both
|
|
||||||
* sources contain identical content at slightly different
|
|
||||||
* network delays.
|
|
||||||
*
|
|
||||||
* Gate the swap on track-not-muted. ev.track.muted=true means
|
|
||||||
* "no RTP yet"; it transitions to false on the first decoded
|
|
||||||
* packet ('unmute' event). Swapping the worklet to a muted mesh
|
|
||||||
* track orphans the SFU receiver (no decoder consumes it →
|
|
||||||
* jbuf=? + level=0 on telemetry) while the worklet plays silence
|
|
||||||
* from mesh — the silent-room state seen on fedora chrome
|
|
||||||
* (ticket 0001, fox 2026-06-07). If the mesh track is already
|
|
||||||
* unmuted at ontrack-time, swap immediately. Otherwise wait for
|
|
||||||
* 'unmute' before touching the worklet. */
|
|
||||||
const stream = ev.streams[0] || new MediaStream([ev.track]);
|
|
||||||
const swapToMesh = () => {
|
|
||||||
if (!setWorkletStream(uuid, stream)){
|
|
||||||
/* fallback: no existing worklet (AudioContext failed at SFU
|
|
||||||
* attach time). Create one fresh with mesh as the source.
|
|
||||||
* Small initial silence while the buffer fills. */
|
|
||||||
attachAudioStreamViaWorklet(uuid, stream, SPEAKER_PLAYOUT_DELAY_SEC);
|
|
||||||
}
|
|
||||||
/* mesh path is peer-to-peer between two speakers (you'd never be
|
|
||||||
* in mesh as a pure listener). Always conversational latency
|
|
||||||
* here — fixed at SPEAKER_PLAYOUT_DELAY_SEC, no role check
|
|
||||||
* needed. */
|
|
||||||
try { ev.receiver.playoutDelayHint = SPEAKER_PLAYOUT_DELAY_SEC; } catch(_){}
|
|
||||||
try { ev.receiver.jitterBufferTarget = SPEAKER_PLAYOUT_DELAY_SEC * 1000; } catch(_){}
|
|
||||||
/* lip-sync: rebind the audio receiver for this publisher to the
|
|
||||||
* MESH receiver since mesh is now what's feeding the worklet.
|
|
||||||
* Its jbuf (~50ms native) + worklet (0.5s) ≈ ~0.55s total audio
|
|
||||||
* delay. Video receivers will re-target to match on the next
|
|
||||||
* worklet 'buffered' message. Fox 2026-06-04: "video would need
|
|
||||||
* to be slid depending on the mode to keep it in sync." */
|
|
||||||
try {
|
|
||||||
const mm = members.get(uuid);
|
|
||||||
const pubHex = mm && mm.pubkey ? hex(unb64(mm.pubkey)) : null;
|
|
||||||
if (pubHex && ev.receiver) registerLipSyncAudio(pubHex, uuid, ev.receiver);
|
|
||||||
} catch(_){}
|
|
||||||
stopMeter(uuid); startMeter(uuid, stream);
|
|
||||||
logLine('', 'mesh stream swapped into worklet for '+uuid.slice(0,4)+' — buffer cushion now applies to mesh too');
|
|
||||||
};
|
|
||||||
/* Mesh-stale fallback: once swapped in, if the mesh track returns
|
|
||||||
* to muted (RTP stopped flowing) for >MESH_MUTE_WINDOW_MS, swap
|
|
||||||
* the worklet back to the cached SFU stream so the listener keeps
|
|
||||||
* hearing the publisher even if mesh stalls without dropping the
|
|
||||||
* PC's connectionState. Same idea as the connectionState='failed'
|
|
||||||
* restore path (below), but driven by track-level mute instead of
|
|
||||||
* PC-level failure. */
|
|
||||||
const MESH_MUTE_WINDOW_MS = 5000;
|
|
||||||
let muteTimer = null;
|
|
||||||
ev.track.addEventListener('mute', () => {
|
|
||||||
if (muteTimer) return;
|
|
||||||
muteTimer = setTimeout(() => {
|
|
||||||
muteTimer = null;
|
|
||||||
if (!ev.track.muted) return;
|
|
||||||
try {
|
|
||||||
const mm = members.get(uuid);
|
|
||||||
const pubHex = mm && mm.pubkey ? hex(unb64(mm.pubkey)) : null;
|
|
||||||
const sfuStream = pubHex ? sfuStreamsByPubHex.get(pubHex) : null;
|
|
||||||
if (sfuStream && setWorkletStream(uuid, sfuStream)){
|
|
||||||
const sfuRx = pubHex ? sfuAudioReceivers.get(pubHex) : null;
|
|
||||||
if (sfuRx) registerLipSyncAudio(pubHex, uuid, sfuRx);
|
|
||||||
logLine('', 'mesh muted >'+(MESH_MUTE_WINDOW_MS/1000)+'s for '+uuid.slice(0,4)+' — worklet swapped back to SFU');
|
|
||||||
}
|
|
||||||
} catch(_){}
|
|
||||||
}, MESH_MUTE_WINDOW_MS);
|
|
||||||
});
|
|
||||||
ev.track.addEventListener('unmute', () => {
|
|
||||||
if (muteTimer){ clearTimeout(muteTimer); muteTimer = null; }
|
|
||||||
/* if we were on SFU because mesh went muted, swap forward to
|
|
||||||
* mesh again now that RTP is flowing. swapToMesh is idempotent
|
|
||||||
* (setWorkletStream is a no-op if the same source is already
|
|
||||||
* connected). */
|
|
||||||
swapToMesh();
|
|
||||||
});
|
|
||||||
if (!ev.track.muted){
|
|
||||||
swapToMesh();
|
|
||||||
} else {
|
|
||||||
logLine('', 'mesh track for '+uuid.slice(0,4)+' arrived muted — staying on SFU until unmute');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
pc.onicecandidate = (ev) => { /* using waitForIceGathering pattern, candidates ignored */ };
|
pc.onicecandidate = (ev) => { /* using waitForIceGathering pattern, candidates ignored */ };
|
||||||
pc.onconnectionstatechange = () => {
|
pc.onconnectionstatechange = () => {
|
||||||
|
|
@ -6870,28 +6771,6 @@ async function connectToPeer(uuid, weOffer){
|
||||||
const attempts = (peerMeshRetries.get(uuid) || 0) + 1;
|
const attempts = (peerMeshRetries.get(uuid) || 0) + 1;
|
||||||
peerMeshRetries.set(uuid, attempts);
|
peerMeshRetries.set(uuid, attempts);
|
||||||
tearPeer(uuid);
|
tearPeer(uuid);
|
||||||
/* Mesh PC died. Swap the worklet's source back to the cached
|
|
||||||
* SFU stream so the user keeps hearing the publisher without a
|
|
||||||
* hiccup. The worklet's existing queue covers the swap latency
|
|
||||||
* — by the time the queue drains 0.5s of (now-stale) mesh
|
|
||||||
* samples, SFU samples are flowing in. attachCachedSfuStreamFor
|
|
||||||
* is kept as a fallback for the no-worklet case (AudioContext
|
|
||||||
* failed earlier). */
|
|
||||||
try {
|
|
||||||
const mm = members.get(uuid);
|
|
||||||
const pubHex = mm && mm.pubkey ? hex(unb64(mm.pubkey)) : null;
|
|
||||||
const sfuStream = pubHex ? sfuStreamsByPubHex.get(pubHex) : null;
|
|
||||||
if (sfuStream && setWorkletStream(uuid, sfuStream)){
|
|
||||||
/* lip-sync: rebind back to the SFU audio receiver. Worklet
|
|
||||||
* source is SFU again → video should target SFU's native
|
|
||||||
* jbuf + worklet (~0.5s + 0.5s ≈ 1s) instead of mesh's. */
|
|
||||||
const sfuRx = pubHex ? sfuAudioReceivers.get(pubHex) : null;
|
|
||||||
if (sfuRx) registerLipSyncAudio(pubHex, uuid, sfuRx);
|
|
||||||
logLine('', 'mesh failed → worklet swapped back to SFU stream for '+uuid.slice(0,4));
|
|
||||||
} else {
|
|
||||||
attachCachedSfuStreamFor(uuid);
|
|
||||||
}
|
|
||||||
} catch(_){ try { attachCachedSfuStreamFor(uuid); } catch(_){} }
|
|
||||||
|
|
||||||
if (attempts >= PEER_MESH_MAX_RETRIES){
|
if (attempts >= PEER_MESH_MAX_RETRIES){
|
||||||
peerMeshGiveUp.add(uuid);
|
peerMeshGiveUp.add(uuid);
|
||||||
|
|
@ -8213,8 +8092,8 @@ logLine('', 'ready — pick a handle, type a rendezvous code, enter the space');
|
||||||
|
|
||||||
<footer style="margin:2.2rem auto 0;font-size:0.65rem;color:#999;line-height:1.7;word-break:break-all;font-family:monospace">
|
<footer style="margin:2.2rem auto 0;font-size:0.65rem;color:#999;line-height:1.7;word-break:break-all;font-family:monospace">
|
||||||
<span id="pi-seal" style="color:#777;cursor:default;user-select:none" title="">page integrity</span> · built <span class="stamp-date">2026-06-07</span><br>
|
<span id="pi-seal" style="color:#777;cursor:default;user-select:none" title="">page integrity</span> · built <span class="stamp-date">2026-06-07</span><br>
|
||||||
md5 <span class="stamp-md5">1e77ac2d270d5b6b8697257a6d7f43cc</span><br>
|
md5 <span class="stamp-md5">9e0930862e9720838a0d0928578590f7</span><br>
|
||||||
sha256 <span class="stamp-sha">6b76bd2486a0b366599cc8e22c1e11d51072e3bf09df3afed6f0208e5af8b0a9</span><br>
|
sha256 <span class="stamp-sha">680c406db618bcc53fc029f073347c4b921af2dde9a97563ea308c23ea8451d3</span><br>
|
||||||
<span style="color:#bbb">hashes are of this page with these two fields zeroed — to verify, blank them and re-hash</span><br>
|
<span style="color:#bbb">hashes are of this page with these two fields zeroed — to verify, blank them and re-hash</span><br>
|
||||||
<span style="color:#bbb">one self-contained file — <strong>save a copy</strong> and verify against these hashes; point at your own servers with ?signal= and ?turncred=, or <a href="host-your-own.html" style="color:#999">host your own community</a></span>
|
<span style="color:#bbb">one self-contained file — <strong>save a copy</strong> and verify against these hashes; point at your own servers with ?signal= and ?turncred=, or <a href="host-your-own.html" style="color:#999">host your own community</a></span>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue