Skip to content

fix: stop camera streams from ducking system audio#140

Merged
nickustinov merged 2 commits into
nickustinov:mainfrom
mvanhorn:fix/138-camera-audio-ducking
Jul 2, 2026
Merged

fix: stop camera streams from ducking system audio#140
nickustinov merged 2 commits into
nickustinov:mainfrom
mvanhorn:fix/138-camera-audio-ducking

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Camera streams no longer duck (lower the volume of) other system audio. The stream players now configure their audio session so opening a camera view stops interrupting music, calls, or other playback, and the session is deactivated cleanly when the stream closes.

Why this matters

Issue #138 reports that viewing a camera ducks system audio: starting an HLS or WebRTC camera stream activated an audio session with default options, so iOS lowered other audio even though these streams are typically muted video. Users watching a camera had their music or podcast volume dropped for no reason.

The stream clients now use a non-ducking audio-session configuration and balance activation with deactivation on teardown. Because LKRTCAudioSession (WebRTC) and the AVAudioSession are reference-counted, activation and deactivation are guarded by a per-client didActivateAudioSession flag so each client activates at most once and deactivates exactly once. deinit routes through the idempotent teardown, so normal disconnect(); client = nil flows and stream reopen do not drive the reference count negative or leave the session active.

Testing

Verified the activation/deactivation is balanced and idempotent by tracing the disconnect and deinit paths and the mute path (which clears the flag after deactivating). On-device build/run was not exercised in this environment (no iOS simulator available); the change is scoped to audio-session setup and teardown in the two stream clients.

Fixes #138

@nickustinov nickustinov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matt! Reviewed and verified – activation/deactivation is balanced on every path (connect/disconnect, play/stop, mute toggle, fallback chain, deinit), and the build passes on Mac Catalyst. Nice clean fix for #138.

One note for the future: since AVAudioSession.setActive(false) isn't reference-counted, the unconditional deactivation in both clients would need revisiting if we ever add a multi-camera live grid. Fine as-is with the single-stream architecture.

@nickustinov
nickustinov merged commit 1d91d13 into nickustinov:main Jul 2, 2026
1 check passed
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.

Overall Sound when cam is pinned

2 participants