Skip to content

Web calls: an audio codec error no longer ends the call - #2476

Merged
unbekannt3 merged 1 commit into
mainfrom
fix/2460-web-audio-codec-recovery
Nov 27, 2026
Merged

unbekannt3 merged 1 commit into
mainfrom
fix/2460-web-audio-codec-recovery

Conversation

@unbekannt3

Copy link
Copy Markdown
Collaborator

Fixes #2460

WebCodecs closes an AudioEncoder or AudioDecoder after its error callback. In web calls the next encode, decode or configure on the closed codec threw InvalidStateError, which went up with ? and ended the whole call. Video already recovered (decoder replaced plus a keyframe request, encoder replaced); audio now does too.

What changes

  • Encoder (OpusEncoder: the voice, its thin copy and the screen's sound): when WebCodecs has closed it, the next frame builds a new one with the configuration it had (bitrate, packet length, planned loss). A reconfiguration that arrives while it is closed (uplink loss, voice step) only updates the fields, and the rebuild uses them.
  • Decoder (RemoteAudio, WebCodecs path): when WebCodecs has closed a remote stream's decoder, its next decode_due replaces it. The output count still on its way is reset, so the stream's audio continues after a short gap. The voice worker path already fell back by itself.
  • Pacing: each codec is rebuilt at most once per second (AUDIO_CODEC_REBUILD_EVERY). A codec that fails every time it starts costs one rebuild a second, not one every 20 ms frame. Meanwhile the samples are a gap, and the jitter buffer (bounded) holds the remote packets.
  • Crash reports: each rebuild sends CallEngineEvent::AudioCodecRebuilt(Encoder|Decoder) to the call telemetry. It reports a new CallProblem::AudioCodecRebuilt (CallAudioCodecRebuilt, warning, fingerprint call / audio_codec_rebuilt / encoder|decoder) once per call and puts a trail line in. The report carries no content and no IDs: the side only (AudioCodecRole, with an Unknown catch-all). Documented in docs/crash-reports.md.

Decision: the rebuild happens lazily, where the codec is next used (state == "closed"), rather than by routing the error callback to the right codec instance. This covers every encoder and decoder instance the same way, and it can't race the callback: WebCodecs sets closed in the same task that runs the error callback.

Tests

  • In a browser, with an injected codec error (call_web::tests::browser_audio_codecs, wasm-bindgen-test; it runs with WASM_BINDGEN_USE_BROWSER=1). The test configures the codec with a configuration no browser runs, so WebCodecs closes it through its error callback, the same path a codec failing mid-call takes. Checked in Chromium, both pass:
    • the encoder reports the error and stays closed; a reconfiguration while closed is fine; the next frames rebuild it (AudioCodecRebuilt(Encoder)) and real Opus packets come out again; a second failure right away is not rebuilt within the second;
    • a remote stream's decoder is closed by the injected error; the next decode_due rebuilds it (AudioCodecRebuilt(Decoder)) and decoded samples of that stream arrive.
    • Not run in Firefox here: there is no geckodriver on this machine.
  • Native: RebuildGate pacing; telemetry reports once per call with a trail line; CallProblem::AudioCodecRebuilt fingerprint, message, type, level, and JSON round trip, plus an unknown side.
  • Wasm clippy (teamcraft-media --features web,call-view --all-targets), native clippy (media, client-api, web-calls), scripts/check-feature-combos.sh teamcraft-media.

Robustness checklist

  • Network loss and change: not affected. The codec state is independent of the transport.
  • Offline/queued actions: not applicable.
  • Lifecycle: a codec the browser closes, for example after a GPU or audio process reset, is rebuilt instead of ending the call.
  • Hostile networks: a malformed remote packet that makes the decoder error now costs that stream a short gap, not the call.
  • Multi-device: not applicable.
  • Server side: not applicable.
  • Large data / resources: rebuilds are paced to one per second per codec. While a codec waits, nothing is decoded; the jitter buffer is bounded (max_depth_packets).
  • Time: the pacing uses the monotonic clock.
  • User-visible status: the call keeps running, and the gap is short. No new UI: the failure is reported to crash reports.

🤖 Generated with Claude Code

WebCodecs closes an AudioEncoder or AudioDecoder after its error
callback; the next encode, decode or configure threw InvalidStateError,
which went up with `?` and ended the call loop. Video already recovered.

A closed Opus encoder (voice, thin copy, screen sound) is now built anew
with its current bitrate, packet length and planned loss on its next
frame; a closed decoder of a remote stream is replaced on its next
decode, so the stream goes on after a short gap. Rebuilds of one codec
run at most once a second, so a codec that keeps failing costs a rebuild
a second, not one per 20 ms frame. Each rebuild reaches the call's
telemetry, which reports CallAudioCodecRebuilt (encoder or decoder) once
per call, without content.

Tested in Chromium with an injected codec error (an unsupported
configuration, which closes the codec through its error callback).

Fixes #2460

Signed-off-by: unbekannt3 <me@unbekannt3.eu>
@unbekannt3 unbekannt3 added bug Something isn't working ci Run CI, Android, iOS and web-size workflows on this pull request labels Nov 27, 2026
@unbekannt3
unbekannt3 enabled auto-merge (squash) November 27, 2026 01:51
@unbekannt3
unbekannt3 merged commit 60fe351 into main Nov 27, 2026
22 checks passed
@unbekannt3
unbekannt3 deleted the fix/2460-web-audio-codec-recovery branch November 27, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci Run CI, Android, iOS and web-size workflows on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web calls: an audio codec error ends the call (no recovery as for video)

1 participant