Skip to content

Report runtime audio processing changes in the audio track features - #1239

Draft
hiroshihorie wants to merge 1 commit into
mainfrom
hiroshi/clt-3223-runtime-audio-features
Draft

hiroshihorie wants to merge 1 commit into
mainfrom
hiroshi/clt-3223-runtime-audio-features

Conversation

@hiroshihorie

Copy link
Copy Markdown
Member

Problem

After a successful LocalAudioTrack.setAudioProcessingOptions(_:), the audio features the server holds for the track are stale. LocalAudioTrack.features(publishOptions:) was built from the immutable captureOptions, and LocalTrackPublication.sendAudioTrackFeatures() only ran on set(track:) and on Krisp delegate changes. So after turning echo cancellation, noise suppression or auto gain control off at runtime, the server kept advertising the publish-time TF_ECHO_CANCELLATION / TF_NOISE_SUPPRESSION / TF_AUTO_GAIN_CONTROL, and the other way round.

Change

Internal only, no public API change.

  • LocalAudioTrack keeps the options last accepted by setAudioProcessingOptions(_:) in a StateSync. They are recorded inside the existing mediaTrack.blocking closure, right after WebRTC returns applied or stored. That runs on the serial RTC executor, so concurrent calls are recorded in the same order WebRTC applied them. A rejected call throws before anything is recorded, so the reported features stay as they were.
  • features(publishOptions:) now derives the processing features from those runtime options, falling back to captureOptions until the first successful runtime change. toFeatures() moved from AudioCaptureOptions to AudioProcessingOptions (the capture options already project onto it via audioProcessing).
  • After a successful call the track notifies its delegates through a new internal LocalAudioTrackDelegateInternal protocol, next to TrackDelegateInternal. LocalTrackPublication conforms and calls the existing sendAudioTrackFeatures(), which already diffs against the last features sent and skips the send when nothing changed. No new locks, queues or Combine subscriptions.
  • A runtime change made before the track is published is picked up by the AddTrackRequest and by the feature update that follows set(track:), since both go through features(publishOptions:).

Worth checking

  • Both applied and stored count as accepted. stored means WebRTC kept the options for the sender to reapply, which matches what the track will run with once it is published.
  • startCapture() still passes captureOptions.audioProcessing to AudioManager.startLocalRecording. I left that alone because it changes processing behaviour and not just reporting, but it does mean that a capture restart after a runtime change starts recording with the capture options while the reported features follow the runtime options. Should it use the runtime options as well?
  • The publication ignores a notification from a track it no longer holds, because MulticastDelegate.notify delivers asynchronously.

Tests

  • New LocalAudioTrackFeaturesTests (unit tests, no server and no audio hardware): the options-to-features mapping; features follow captureOptions until runtime options are recorded, and publish-option features (TF_NO_DTX) are still merged in; a real setAudioProcessingOptions(.noProcessing) on an unpublished track returns applied or stored, updates the features and notifies the track delegate.
  • New e2e test PublishTrackTests.runtimeAudioProcessingChangeUpdatesFeatures: it publishes a track, waits until the subscriber sees the three processing features in the TrackInfo, calls setAudioProcessingOptions(.noProcessing), and checks that both the local publication and the subscriber's TrackInfo drop them. With the notification call temporarily removed, this test fails on both expectations.

What was run:

  • xcodebuild build-for-testing -scheme LiveKit for platform=macOS and for an iPhone 18 Pro simulator (Xcode 27.2): both succeeded, with no new warnings in the touched files.
  • macOS, against a local livekit-server --dev: LocalAudioTrackFeaturesTests, AudioProcessingOptionsTests and all of PublishTrackTests passed (18 tests).
  • iOS simulator: LocalAudioTrackFeaturesTests and AudioProcessingOptionsTests passed. The e2e PublishTrackTests suite did not complete on the simulator in my environment. Its existing tests, which this PR does not change, stalled and were restarted the same way as the new one, so the e2e test was verified on macOS only.
  • swiftformat --lint . and swiftlint lint --strict are clean.

Not verified

Not run on a physical device. I did not check that the reported features match what the device's audio processing actually does on real hardware; the tests only cover what the SDK records and sends.

🤖 Generated with Claude Code

LocalAudioTrack.setAudioProcessingOptions(_:) changes echo cancellation,
noise suppression and auto gain control at runtime, but the features sent
to the server were still derived from the immutable captureOptions, and
LocalTrackPublication only re-sent them on set(track:) and on Krisp
delegate changes. The server kept advertising the publish-time features.

The track now records the options once WebRTC accepts them (applied or
stored), on the RTC executor so concurrent calls are recorded in the order
they were applied, and derives its features from them. A rejected call
throws before anything is recorded, so it leaves the features unchanged.
The publication is notified through a new internal track delegate
protocol and re-sends the features when they differ from the last ones
sent. A runtime change made before publishing is picked up by the
AddTrackRequest and the first feature update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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