Repository navigation
Conference audio: a jitter buffer per peer, pulled by the device; the mic drains its backlog - #1398
Merged
Merged
Conversation
… mic drains its backlog Peers' voices broke up while video and avatars stayed smooth. Two causes: - The receiver played a peer's audio the moment it landed, into a 100 ms output it filled once a frame. Over a WebSocket, audio lands in bursts (the sender captures in blocks and sends once a frame, and it shares the connection with video), so a late burst left the speaker with nothing. - The mic producer read one 21 ms chunk per tick. A browser delivers its mic in 43 ms blocks and its timers skip the beats a busy frame misses, so every skipped tick left a chunk behind for good, and at 80 ms of backlog the capture dropped it (about 64 ms of audio each time). cvc::voice_mixer (voice_mixer.h) holds a jitter buffer per peer and mixes them. The playback device pulls the mix at its own pace through open_audio_output_pull (SDL's get-callback), not at the frame loop's. A peer starts once its target is buffered: 80 ms, at least the device's block plus 20 ms. The target grows 20 ms each time the peer runs dry and its audio comes back within 300 ms, and shrinks after 10 s without that. A burst past twice the target is cut back to it with a cross-fade. The client logs each peer's buffer every 10 s. frame_source::more lets a FIFO source say it has another chunk ready, and the producer reads up to 16 chunks a tick. The SDL mic says so while its backlog holds a chunk, and keeps up to 250 ms before it drops. A decoder also drops an Opus packet at or behind the last one, and starts over when the sender has.
This was referenced Nov 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Peers' voices broke up in a conference while the scene, the avatars and the video stayed smooth. This fixes the two causes on the clients. The relay is not involved: its log for the Nov 18 session shows no media dropped, no backlog and no stalls. But it also shows the round trip on the same connection swinging between 40 and 90 ms, and per-viewer video queues of 460 to 750 ms.
Causes
mix_audioplayed a peer's audio as soon as it landed, into a 100 ms output it filled once a frame. Over a WebSocket, audio lands in bursts: the sender captures in blocks, sends once a frame, and shares one TCP connection with video. A late burst left the speaker with nothing to play.Changes
cvc::voice_mixer(inc/cvc/media/voice_mixer.h) holds one jitter buffer per peer and mixes them. The playback device pulls the mix at its own pace through the newopen_audio_output_pull(SDL's get-callback), not at the frame loop's. It is thread-safe: pushes come from the app thread, pulls from SDL's audio thread or the page's audio callback.audio_output::device_period_s). In a browser that is 63 ms and 85 ms to start.frame_source::more. A FIFO source can say it has another chunk ready, and the producer reads up to 16 chunks a tick. The SDL mic says so while its backlog holds a whole chunk.muted_sourceandgain_sourceforward it. The drop-at-source ceiling goes from 80 ms to 250 ms: a tick now drains everything, so only a real stall reaches it.Tests
voice_mixer_test(12). The headline case simulates a browser link: 43 ms blocks, 30 ms + U(0, 40 ms) delay, 10% of blocks 60 ms later still, delivered in order and seen at 60 Hz frames, with 3 s talk spurts. Over 20 seeds, playing as it lands runs dry 61 to 105 times in 30 s. The jitter buffer runs dry once, settles at 105 ms, and drops nothing. Also tested: start at target, late vs. end-of-spurt underruns, short spurts, trimming and the cross-fade, overflow, gains and clamping, stereo, relaxing, the delay floor.stream_test:DrainsAFifoSourcesBacklogEachTickandMutedSourceForwardsMore. All 41 pass.cvcmedia_audio_output: pull mode on SDL's dummy driver (the device pulls by itself, in whole frames), anddevice_period_s.media_rungs_test,room_intrinsics_test,cvcgl_audio_*(live, on the dummy driver),cvcgl_media_*,cvcmedia_audio_output.End to end (native)
The setup:
arisrv;ariglclients running cyprty'smain.ari(synthetic cameras), on Xvfb with llvmpipe;Each peer sends a steady 440 Hz tone, so any gap or discontinuity in the recording is a glitch. The box was at load average 40 to 49 the whole time. Old and new builds ran alternately under the same conditions. Figures are per client, over about 31 s:
What remains comes from this box's frame stalls under that load. Targets settled at 240 to 260 ms there; on an idle machine they should sit near the floor.
Not verified
arigl/main.cppincluded, compile for single-threaded wasm with the WebSocket transport and Opus. The page has not been linked or run in a browser with this change.