Skip to content

Conference audio: a native client's audio is off the frame loop - #1408

Merged
transfix merged 1 commit into
masterfrom
fix/conference-audio-off-frame-loop
Nov 21, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/conference-audio-off-frame-loop

Conversation

@transfix

@transfix transfix commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

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:

  • a peer's mic chunks reached on_media on the transport's reader thread, but were only queued, then decoded and pushed to the jitter buffer in drain_inbox;
  • our own mic chunks went out in 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)

  • Receive on arrival. 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 (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.
  • The frame takes the bookkeeping. Once a frame, take_voice copies each peer's talk highlight (talk_until) and A/V clock (last_audio_pts, last_audio_wall) into peers_.
  • Mixer first, output later. 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.
  • A mic sender. Our mic goes out on its own thread as the producer delivers each chunk (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.
  • Single-threaded stays. CVC_ARIGL_AUDIO_THREADS=0 puts 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.
  • Docs: §5j of the conference roadmap, and the publisher and receiver rows of CONFERENCE_SHARING.md.

End to end (native)

The setup is #1398's, rebuilt:

  • a local 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;
  • two arigl run clients on cyprty's main.ari, on Xvfb with llvmpipe (cvcpkg xvfb and mesa), with CVC_ARIADNE_SYNTHETIC_CAM=1;
  • SDL's disk driver, recording what each client plays.

Every peer sends a steady 440 Hz tone, so any gap or discontinuity in a recording is a glitch. There are two mics:

  • disk: an SDL recording device, fed a 440 Hz file through SDL_AUDIO_DISK_INPUT_FILE. Like a real mic, it is a FIFO that the producer drains.
  • tone: the document's generator. On a loaded box its producer loses audio whenever it falls behind (producer_thread resets its schedule), whatever the build.

Frame stalls are induced with an LD_PRELOAD shim around SDL_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:

  • gaps: silent runs of 2 ms or more;
  • discontinuities: places where the sine fails to continue by more than 8% of its amplitude (a hard edge or a jump; the jitter buffer's 2.5 ms fades do not count);
  • ran dry and target at end: from the client's own arigl: voice lines, 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:

mic frame stalls #1398 this PR this PR, CVC_ARIGL_AUDIO_THREADS=0
disk none gaps 2–12 4–5 3–7
silent 0.7–7.5% 0.7–1.6% 0.7–3.5%
discontinuities 0–48 0–1 0–3
target at end 180–400 ms 140–180 ms 180–280 ms
disk 150 ms, about every 1 s gaps 7–11 4–6 9–13
silent 2.5–5.3% 0.7–1.4% 3.1–5.1%
discontinuities 20–22 0–1 20–22
target at end 320–380 ms 160–220 ms 360–400 ms
disk 400 ms, about every 2.5 s gaps 15–17 3–4 14–17
silent 11.5–13.7% 0.4–1.0% 12.6–16.1%
discontinuities 6–17 0–1 8–19
target at end 400 ms 120–180 ms 400 ms
tone none gaps 4–6 2–5 2–10
silent 0.8–1.6% 0.3–0.7% 0.3–8.5%
discontinuities 1–2 0 1–57
target at end 180–200 ms 140–160 ms 200–320 ms
tone 150 ms, about every 1 s gaps 7–25 4–5 10–16
silent 2.8–33.1% 0.8–1.0% 3.8–9.9%
discontinuities 20–85 0–1 20–42
target at end 300–400 ms 140 ms 360–400 ms
tone 400 ms, about every 2.5 s gaps 13–14 2–4 12–17
silent 9.3–11.1% 0.4–1.0% 8.5–18.3%
discontinuities 9–13 0–1 8–56
target at end 400 ms 140–160 ms 400 ms
Every run
mic frame stalls build trial load gaps silent discontinuities ran dry target at end
disk none #1398 1 37.91-57.16 6 / 12 3.3% / 7.46% 10 / 48 11 / 16 260 ms / 400 ms
disk none this PR 1 53.86-55.18 4 / 5 0.68% / 1.61% 0 / 0 5 / 6 160 ms / 160 ms
disk none this PR, threads off 1 47.60-59.77 7 / 3 3.18% / 0.66% 0 / 0 10 / 7 260 ms / 180 ms
disk none #1398 2 37.77-40.89 2 / 4 0.74% / 1.32% 0 / 1 7 / 7 180 ms / 200 ms
disk none this PR 2 37.70-44.85 4 / 4 0.86% / 0.68% 1 / 1 5 / 6 140 ms / 180 ms
disk none this PR, threads off 2 38.56-58.52 7 / 5 3.46% / 1.85% 0 / 3 11 / 9 280 ms / 240 ms
disk 150 ms every ~1 s #1398 1 55.38-52.08 11 / 11 5.27% / 3.57% 20 / 20 15 / 15 380 ms / 380 ms
disk 150 ms every ~1 s this PR 1 48.31-48.59 6 / 4 1.37% / 0.74% 1 / 0 7 / 6 200 ms / 180 ms
disk 150 ms every ~1 s this PR, threads off 1 45.10-44.58 11 / 9 3.86% / 3.06% 21 / 20 16 / 14 400 ms / 360 ms
disk 150 ms every ~1 s #1398 2 54.98-48.17 8 / 7 3.84% / 2.54% 22 / 21 13 / 12 340 ms / 320 ms
disk 150 ms every ~1 s this PR 2 44.64-48.79 4 / 4 1.04% / 0.65% 0 / 1 8 / 7 220 ms / 160 ms
disk 150 ms every ~1 s this PR, threads off 2 44.97-54.81 11 / 13 5.09% / 3.58% 22 / 20 16 / 15 400 ms / 380 ms
disk 400 ms every ~2.5 s #1398 1 38.02-46.56 17 / 15 13.68% / 13.2% 17 / 8 23 / 19 400 ms / 400 ms
disk 400 ms every ~2.5 s this PR 1 45.56-48.69 3 / 4 0.44% / 1.02% 0 / 1 5 / 6 140 ms / 160 ms
disk 400 ms every ~2.5 s this PR, threads off 1 45.12-46.36 17 / 14 16.1% / 13.45% 11 / 19 22 / 21 400 ms / 400 ms
disk 400 ms every ~2.5 s #1398 2 47.08-46.04 15 / 17 13.57% / 11.5% 9 / 6 21 / 23 400 ms / 400 ms
disk 400 ms every ~2.5 s this PR 2 42.60-43.20 3 / 4 0.39% / 1.04% 0 / 0 5 / 6 120 ms / 180 ms
disk 400 ms every ~2.5 s this PR, threads off 2 39.98-41.85 14 / 15 12.8% / 12.63% 10 / 8 20 / 21 400 ms / 400 ms
tone none #1398 1 39.54-50.57 6 / 5 1.33% / 0.84% 1 / 2 7 / 7 180 ms / 200 ms
tone none this PR 1 46.76-75.25 4 / 3 0.57% / 0.52% 0 / 0 6 / 5 160 ms / 160 ms
tone none this PR, threads off 1 75.07-82.67 10 / 9 5.9% / 8.47% 46 / 57 14 / 14 320 ms / 320 ms
tone none #1398 2 35.95-51.08 4 / 5 1.63% / 1.31% 1 / 1 7 / 8 180 ms / 200 ms
tone none this PR 2 47.47-48.13 2 / 5 0.31% / 0.73% 0 / 0 5 / 6 140 ms / 160 ms
tone none this PR, threads off 2 47.31-55.20 6 / 2 0.94% / 0.3% 1 / 1 8 / 8 220 ms / 200 ms
tone 150 ms every ~1 s #1398 1 76.53-89.39 23 / 25 33.15% / 26.75% 85 / 79 26 / 29 400 ms / 400 ms
tone 150 ms every ~1 s this PR 1 83.92-73.28 5 / 5 1.04% / 0.79% 0 / 0 5 / 5 140 ms / 140 ms
tone 150 ms every ~1 s this PR, threads off 1 67.65-72.79 15 / 16 9.95% / 8.93% 26 / 42 21 / 20 400 ms / 400 ms
tone 150 ms every ~1 s #1398 2 50.94-61.02 10 / 7 4.23% / 2.78% 21 / 20 12 / 12 300 ms / 300 ms
tone 150 ms every ~1 s this PR 2 56.27-56.65 4 / 4 0.95% / 0.88% 0 / 1 5 / 5 140 ms / 140 ms
tone 150 ms every ~1 s this PR, threads off 2 52.28-62.06 10 / 11 4.5% / 3.77% 25 / 20 14 / 15 360 ms / 380 ms
tone 400 ms every ~2.5 s #1398 1 68.00-58.04 14 / 13 9.3% / 9.61% 9 / 13 21 / 19 400 ms / 400 ms
tone 400 ms every ~2.5 s this PR 1 53.87-49.39 4 / 4 0.85% / 0.71% 1 / 0 5 / 5 140 ms / 160 ms
tone 400 ms every ~2.5 s this PR, threads off 1 42.10-40.97 12 / 16 8.53% / 11.03% 8 / 10 20 / 20 400 ms / 400 ms
tone 400 ms every ~2.5 s #1398 2 59.81-53.87 13 / 13 11.05% / 11.06% 13 / 9 19 / 19 400 ms / 400 ms
tone 400 ms every ~2.5 s this PR 2 50.95-58.78 4 / 2 0.96% / 0.41% 1 / 0 5 / 5 140 ms / 140 ms
tone 400 ms every ~2.5 s this PR, threads off 2 54.04-62.92 17 / 16 18.32% / 14.33% 56 / 45 24 / 23 400 ms / 400 ms
  • With frame stalls, the frame-loop builds lose 3 to 16% of the peer's audio. That is Conference audio: a jitter buffer per peer, pulled by the device; the mic drains its backlog #1398, and this PR with threads off: 7 to 17 gaps per client in 30 s (25 at load 89). Their jitter buffers climb to the 400 ms ceiling. About 20 discontinuities appear per client, because the mic's ring overflows at the sender during long frames. This PR stays at 0.4 to 1.4% (2 to 6 gaps), with 0 or 1 discontinuities, and its buffers settle at 120 to 220 ms.
  • Without stalls, the builds are within each other's noise at this load: 2 to 12 gaps per client. What remains falls at the same moment in both clients (for example 16.5 s into one run), so it comes from what they share: the relay, the proxy, a box at load 40 to 60. It does not come from either client's frame loop.
  • Threads off matches Conference audio: a jitter buffer per peer, pulled by the device; the mic drains its backlog #1398 in every stalled row. So the improvement is the threads, not the rest of the change.
  • Two rows ran while the box was at load 75 to 89, and they stand out: Conference audio: a jitter buffer per peer, pulled by the device; the mic drains its backlog #1398's first tone run with 150 ms stalls (27 to 33% silent), and threads off's first tone run with no stalls (46 to 57 discontinuities).
  • Over gRPC (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.
  • Teardown is clean. A client exits within 1.4 s of SIGINT, alone or with a peer, whether or not the peer has left. A snapshot-mode client, which tears down through the destructor, exits 0.
  • The harness (proxy, stall shim, analyzer, scripts) is kept with the session notes this time, outside the repo.

Not verified

  • The browser build is not run; it keeps the frame-loop path. main.cpp passes em++ -fsyntax-only for single-threaded wasm with the WebSocket transport.
  • The lane (CVC_ENABLE_RTC) is off in this build, so decoding on the lane's thread is not exercised.

@transfix
transfix changed the base branch from fix/conference-audio to master November 20, 2026 21:04
@transfix
transfix force-pushed the fix/conference-audio-off-frame-loop branch from 68c31bf to 9c25e37 Compare November 20, 2026 21:04
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
transfix force-pushed the fix/conference-audio-off-frame-loop branch from 9c25e37 to 4d04070 Compare November 20, 2026 22:47
@transfix
transfix merged commit 136e014 into master Nov 21, 2026
29 checks passed
@transfix
transfix deleted the fix/conference-audio-off-frame-loop branch November 21, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant