Audio: support app-audio publishing without claiming a device#985
Open
sgu-bithuman wants to merge 1 commit intolivekit:mainfrom
Open
Audio: support app-audio publishing without claiming a device#985sgu-bithuman wants to merge 1 commit intolivekit:mainfrom
sgu-bithuman wants to merge 1 commit intolivekit:mainfrom
Conversation
Add `MixerEngineObserver.wireAppAudioPath()` so callers can connect the `appNode → appMixerNode → mainMixerNode` graph in manual rendering mode, where `engineWillConnectInput` is never invoked by the WebRTC ADM (no real device) and `mixer.capture(appAudio:)` would otherwise drop every buffer. `capture(appAudio:)` also lazy-wires the path on its first call, so existing call sites (server-side avatars, `MacOSScreenCapturer`, `BroadcastScreenCapturer`, custom audio sources) get the fix automatically. This unblocks several no-device scenarios that work in `AudioManager`'s manual rendering mode but had no path to actually publish: - Server-side avatars that only republish app-supplied audio (no mic). Multi-process deployments on a single Mac can't share the audio device, so the existing `startLocalRecording()` path tops out at one audio publisher per machine. - Screen-share with system audio but no microphone. - Custom audio sources (e.g. file playback) without a real input. `engineWillRelease` now also clears `isInputConnected` and `mainMixerNode` so a recreated engine re-runs the wiring. Verified end-to-end with eight server-side processes publishing audio concurrently on the same Mac. The lazy auto-wire matches the existing `engineWillConnectInput` behavior — Float32 player-node format derived from the engine's mainMixer output format. Idempotent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
Contributor
|
@sgu-bithuman could you add some description of the scenarios that are not covered by the current implementation? client-sdk-swift/Tests/LiveKitAudioTests/AudioEngineTests.swift Lines 251 to 301 in 397b800 Based on an initial review, it should work "as is". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AudioManager.shared.mixer.capture(appAudio:)is the documented entry-point for feeding app-supplied PCM into the publish path (used byMacOSScreenCapturer,BroadcastScreenCapturer, and any custom audio source). In manual rendering mode it drops every buffer because the input chain (appNode → appMixerNode → mainMixerNode) is never wired up — the WebRTC ADM only invokesengineWillConnectInputwhen connecting a real device, which manual rendering by definition has none of.This blocks several scenarios that
AudioManager.setManualRenderingMode(_:)otherwise enables:startLocalRecording()path tops out at one audio publisher per machine. SeetestManualRenderingModePublishAudioinLiveKitAudioTests— that test demonstrates the publish flow but only one process can hold the device.Changes
MixerEngineObserver.wireAppAudioPath()— public, idempotent. WiresappNode → appMixerNode → mainMixerNodeagainstengine.mainMixerNodeusing the same Float32 player-node format derivation as thesrc=nilbranch inengineWillConnectInput.capture(appAudio:)lazy-wires the path on the first call when it sees a manual-rendering engine. Existing call sites get the fix automatically; no API churn for callers.engineWillReleaseclearsisInputConnectedandmainMixerNodeso a recreated engine re-runs the wiring.Purely additive — no public API removed, no signature changes. Engine-running and
isInputConnectedguards incapture(appAudio:)are preserved.Test plan
swift build --target LiveKitmixer.capture(appAudio:)→ published track. Each process: ~0.019 avg / ~0.25 peak RMS, ~36% non-zero samples vs ~2% noise floor on the previous code path.LocalAudioTrackmic flow unchanged (the new code only fires whenengine.isInManualRenderingMode).LiveKitAudioTestspass (would benefit from a new test mirroringtestManualRenderingModePublishAudiobut withmixer.capture(appAudio:)as the source, replacing the file player). Happy to add this if useful.🤖 Generated with Claude Code