Repository navigation
Conference audio: a native client's audio is off the frame loop - #1408
Merged
Merged
Conversation
transfix
force-pushed
the
fix/conference-audio-off-frame-loop
branch
from
November 20, 2026 21:04
68c31bf to
9c25e37
Compare
A long frame held a native client's audio up both ways. A peer's mic chunks were decoded and pushed to its jitter buffer once a frame, so a stall let the device drain the buffer. Our own mic went out once a frame from a ring of 8 chunks (170 ms), so a stall delayed it, and one past 170 ms dropped it. - A peer's mic is decoded and pushed to voice_mixer on the thread it arrives on (the transport's reader, or the lane's), with a decoder per peer under its own mutex. The frame takes each peer's talk highlight and A/V clock from there (take_voice). - voice_ is made when the client joins, at 48 kHz mono; the output still opens on the frame's thread, once there is audio to play. A/V sync follows the jitter buffer only while the output is open. - Our mic goes out on a sender thread as the producer delivers each chunk, stamped with the last frame's world-clock time moved on by the steady clock since. The frame still binds the stream and hands the subscription over. - CVC_ARIGL_AUDIO_THREADS=0 puts both back on the frame. A browser build always has them there.
transfix
force-pushed
the
fix/conference-audio-off-frame-loop
branch
from
November 20, 2026 22:47
9c25e37 to
4d04070
Compare
This was referenced Nov 21, 2026
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.
Follows #1398 (merged as 825a7ba), rebased onto master.
After #1398, what is left of the choppy audio on a loaded machine comes from long frames. A native client handled its audio once a frame:
on_mediaon the transport's reader thread, but were only queued, then decoded and pushed to the jitter buffer indrain_inbox;forward_streams, from a ring of 8 chunks (170 ms).So a long frame let the device drain a peer's buffer, and the burst after it was trimmed. A frame longer than 170 ms dropped audio at the sender. The encoder never saw the dropped chunks, so the receiver heard a jump in the waveform, not a lost packet.
Changes (
src/arigl/main.cpp)voice_mixeron the thread it arrives on: the transport's reader, or the lane's (receive_voice). The decoders, one per peer, are under their own mutex (voice_rx_mu_), since the connection and the lane can both deliver one peer's packets, and its decodes and pushes must stay in order.take_voicecopies each peer's talk highlight (talk_until) and A/V clock (last_audio_pts,last_audio_wall) intopeers_.voice_is made when the client joins, at 48 kHz mono, so the reader can feed it from the first chunk. The output still opens on the frame's thread, once there is audio to play. A/V sync follows the jitter buffer only while the output is open, since with no output nothing drains it.mic_send_loop). The frame still binds the stream and hands the subscription over (hand_mic); a rebind or a stop closes the old subscription, which wakes the sender. Each chunk is stamped with the last frame's world-clock time moved on by the steady clock since, never stepping back. The WebSocket and gRPC transports already write media from several threads (the relay fans from its readers), and the lane is thread-safe.CVC_ARIGL_AUDIO_THREADS=0puts receiving and sending back on the frame, as before. A browser build always has them there: its transport, its audio callbacks and its frames share the page's one thread. The client logs which it is using.End to end (native)
The setup is #1398's, rebuilt:
arisrv, with a TCP proxy in front of its WebSocket port that delays each chunk 20 ms + U(0, 40 ms), plus 60 ms on 10% of chunks, in order, both ways;arigl runclients on cyprty'smain.ari, on Xvfb with llvmpipe (cvcpkgxvfbandmesa), withCVC_ARIADNE_SYNTHETIC_CAM=1;Every peer sends a steady 440 Hz tone, so any gap or discontinuity in a recording is a glitch. There are two mics:
SDL_AUDIO_DISK_INPUT_FILE. Like a real mic, it is a FIFO that the producer drains.producer_threadresets its schedule), whatever the build.Frame stalls are induced with an
LD_PRELOADshim aroundSDL_PollEvent, which the frame calls on the main thread. It sleeps for the stall length at random intervals around the stated period, starting 8 s in. Nothing else in the process stops.Each run is about 42 s. Figures are per client, over 30 s starting 2 s after the first sound:
arigl: voicelines, over the whole run.The three builds ran alternately under the same conditions, two trials each. The box was shared with other builds: mostly at load 38 to 60, and up to 89 for a few runs. In the full table, each row is one run, the figures are alice / bob, and the load is at the run's start and end.
Ranges over both clients and both trials:
CVC_ARIGL_AUDIO_THREADS=0Every run
grpc://straight to the relay, no proxy), with 400 ms stalls and the disk mic, this PR has 2 / 1 gaps, 0.5 / 0.2% silent and no discontinuities.Not verified
main.cpppassesem++ -fsyntax-onlyfor single-threaded wasm with the WebSocket transport.CVC_ENABLE_RTC) is off in this build, so decoding on the lane's thread is not exercised.