Skip to content

feat: re-acquire mic track when effects require specific audio constraints - #99

Open
antsukanova wants to merge 30 commits into
mainfrom
antsukan/agc-fix
Open

feat: re-acquire mic track when effects require specific audio constraints#99
antsukanova wants to merge 30 commits into
mainfrom
antsukan/agc-fix

Conversation

@antsukanova

@antsukanova antsukanova commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds constraint handling to LocalAudioStream so audio effects can request specific MediaTrackConstraints on the microphone track. Since Chrome silently ignores applyConstraints() for audio processing properties (chromium#40555809), the handler re-acquires the track via getUserMedia(). Original track settings are saved and restored when the effect releases its constraints on disable/dispose.

Keeping the old track alive while calling getUserMedia() causes Chrome to reuse the existing hardware capture session and silently ignore hardware-level constraints such as echoCancellation. The old track is stopped before getUserMedia() to force a fresh session and ensure all constraints are honored.

What's changed

  • addConstraintHandlers — new private method on LocalAudioStream wired up from addEffect(); listens for ConstraintsRequired / ConstraintsReleased events from the effect and calls reacquireInputTrack
  • reacquireInputTrack — stops the current track before calling getUserMedia() with the merged baseline + effect constraints; restores mute state and wires the new track into the effect chain
  • AppliableAudioConstraints — extended with sampleRate, sampleSize, and channelCount
  • filterToSupportedConstraints — new helper that strips keys not recognized by the browser via getSupportedConstraints() before passing baseline settings to getUserMedia()
  • effects / loadingEffects / changeOutputTrack — visibility changed from private to protected in LocalStream to allow access from LocalAudioStream
  • Failure handling — if getUserMedia() or effect wiring fails, all effects are disposed and Ended is emitted; if the effect is disposed while getUserMedia() is in-flight, the new track is discarded and Ended is emitted to prevent a silent dead stream

Testing

  • Enable OFMV → verify autoGainControl: false, noiseSuppression: false, echoCancellation: true
  • Disable OFMV → verify original values restored
  • BNR enable/disable → no constraint re-acquisition triggered
  • Dispose during pending getUserMedia() → new track discarded, Ended emitted

See code change in web-media-effects
You can use the sdk linked branch with these changes to test: agc-fix-branch-test

Loading
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.

6 participants