Skip to content

fix: clamp audio input channels to stereo to prevent WebRTC crash - #67

Open
stevenwritescode wants to merge 1 commit into
decentraland:mainfrom
stevenwritescode:fix/clamp-audio-channels-for-multichannel-devices
Open

fix: clamp audio input channels to stereo to prevent WebRTC crash#67
stevenwritescode wants to merge 1 commit into
decentraland:mainfrom
stevenwritescode:fix/clamp-audio-channels-for-multichannel-devices

Conversation

@stevenwritescode

Copy link
Copy Markdown

Summary

  • Clamps audio input channel count to 2 (stereo) in the Rust cpal capture layer (lib.rs)
  • Adds a defensive clamp in C# MicrophoneRtcAudioSource when creating the LiveKit audio source
  • Prevents fatal WebRTC AudioFrame assertion (num_channels <= kMaxConcurrentChannels) with multi-channel audio interfaces

Problem

Multi-channel audio interfaces (e.g. Focusrite Scarlett 18i20 with 20 output channels) cause a fatal process crash when used as the system audio device. The Rust audio capture code takes whatever channel count cpal reports from the device without any limit. This channel count flows through to WebRTC AudioFrame, which has a hard assertion that num_channels <= 8 (kMaxConcurrentChannels). The process aborts immediately:

Fatal error in: ../api/audio/audio_frame.cc, line 75
Check failed: num_channels <= kMaxConcurrentChannels (20 vs. 8)

Fix

Voice chat only needs mono or stereo audio. The fix clamps the channel count at two levels:

  1. Rust (RustAudio/rust-audio/src/lib.rs): config.channels = config.channels.min(2) -- prevents cpal from capturing unnecessary channels
  2. C# (MicrophoneRtcAudioSource.cs): Math.Min(channels, 2) -- safety net at LiveKit audio source creation

This avoids needing to update the bundled WebRTC fork.

Affected devices

Any audio interface reporting >8 channels: Focusrite Scarlett 18i20, Universal Audio Apollo, MOTU 828/1248, RME Fireface, or aggregate audio devices.

Fixes decentraland/unity-explorer#8766

Test plan

  • Verify voice chat works with a standard stereo audio device (no regression)
  • Verify voice chat works with a multi-channel audio interface (e.g. Scarlett 18i20) -- should no longer crash
  • Verify microphone input is correctly captured as mono/stereo even when the device supports more channels

Multi-channel audio interfaces (e.g. Focusrite Scarlett 18i20 with 20
channels) cause a fatal WebRTC assertion failure because the channel
count exceeds kMaxConcurrentChannels (8). Voice chat only needs
mono/stereo, so clamp at both the Rust capture layer (cpal config)
and the C# audio source creation as a safety net.

Fixes decentraland/unity-explorer#8766
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.

Fatal crash with multi-channel audio interfaces (e.g. Scarlett 18i20)

1 participant