Skip to content

feat(audio): allow host-managed renderer session activation - #872

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
jonluca:feat/host-audio-session-activation
Oct 26, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
jonluca:feat/host-audio-session-activation

Conversation

@jonluca

@jonluca jonluca commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Let hosts coordinating audible focus across several players own renderer audio-session activation. Coalesce concurrent category setup through the existing process-wide transition queue and validate current settings on later loads, avoiding repeated configuration of an already matching session.

What changed

  • Add rendererAudioSessionActivationEnabled, defaulting to true. When disabled before load, renderer loads and interruption recovery skip activation and channel preference changes.
  • Validate category, mode, route-sharing policy and multichannel support off-main before load. Concurrent loads share the operation; later loads retry after failures or external session changes.
  • Keep configuration ordered with activation and deactivation through SharedOutputCoordinator.
  • Document the distinction between activation, category setup and the existing opt-in for final deactivation.

Test plan

  • Device / OS: Apple M4 Max, macOS 27.0.1, Xcode 27.1.
  • Source media: none; deterministic coordinator and activation-ownership tests.
  • 26 shared-output, audio-session transition order and teardown-policy Swift tests, plus 4 public API documentation tests, pass.
  • AetherEngine builds for arm64 iOS18 simulator with -warnings-as-errors.
  • Documentation link validation and git diff --check pass.
  • Physical iOS/tvOS audio routes and interruption recovery were not exercised.

Checklist

  • CHANGELOG.md updated
  • Conventional commit
  • Engine-owned behavior
  • Public API documented

Copilot AI balanced review requested due to automatic review settings October 25, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Route-change handling can still overwrite host-managed channel preferences when renderer activation is disabled.

1 open issue
What changed in this PR

This PR adds host control over renderer audio-session activation and moves category validation into the process-wide transition queue.

Changes:

  • Add a default-enabled activation flag for renderer loads and interruption recovery.
  • Coalesce concurrent category setup and revalidate settings on later loads.
  • Add ownership tests and document activation, configuration, and deactivation responsibilities.
File Description
Tests/​AetherEngineTests/​SharedOutputCoordinatorTests.swift Test configuration coalescing, revalidation, and activation ownership.
Sources/​AetherEngine/​SharedOutputCoordinator.swift Serialize and coalesce category configuration.
Sources/​AetherEngine/​AetherEngine+Loading.swift Gate renderer activation with the new ownership flag.
Sources/​AetherEngine/​AetherEngine.swift Expose the flag and validate category settings at load.
README.md Update category-configuration timing documentation.
docs/​formats.md Clarify load-time audio-session setup.
docs/​api.md Document host-managed activation and lifecycle responsibilities.
CHANGELOG.md Announce activation control and shared category setup.

Review effort: Balanced

/// iOS/tvOS 27 flag it as a hang risk on the main thread (AE#538): the same reasoning that moved `setCategory` off-main
/// in #114 and the teardown deactivation in #215. Only the track lookup, which reads published state, stays here.
func activateRendererAudioSession(audioSourceStreamIndex: Int32? = nil) async {
guard rendererAudioSessionActivationEnabled else { return }
@jonluca
jonluca force-pushed the feat/host-audio-session-activation branch from 1a3975d to 3057c8a Compare October 25, 2026 18:27
superuser404notfound pushed a commit that referenced this pull request Oct 26, 2026
…st activation own the channel preference (#872 follow-up)

#872 moved the category declaration from init to every load and rewrote it
whenever the session no longer matched. A host that switches the mode after the
first load (Sodalite's music playback sets .playback/.default and activates)
then had it flipped back to .moviePlayback on an active session at every track.
The declaration now runs once: concurrent loads share it, a success is never
repeated, a failure is retried, and a session the host already put on .playback
keeps its mode and policy.

rendererAudioSessionActivationEnabled = false now also covers route changes:
ownsChannelPreference no longer writes the channel preference for a host that
owns activation.

The init-time diagnostic line (category, maxChannels, output) moves to the
declaration so #24-style downmix reports still carry it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
@superuser404notfound
superuser404notfound merged commit 3e256c5 into superuser404notfound:main Oct 26, 2026
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged in 3e256c5, thanks @jonluca, the activation switch and the coalesced category setup are a good fit for hosts that juggle several players.

Follow-up in 24898a4, two changes on top:

  • The category is declared once per process instead of revalidated on every load. Revalidation rewrote the mode on an active session whenever a host had changed it after the first load. Sodalite's music playback does exactly that (.playback / .default, then activates), so every track flipped it back to .moviePlayback and the next track flipped it again. Concurrent loads still share the in-flight declaration, a failed one is retried by the next load, and a session the host already put on .playback keeps its mode and policy.
  • rendererAudioSessionActivationEnabled = false now also gates ownsChannelPreference, so a route change no longer writes the channel preference for a host that owns activation (the point Copilot raised). Covered in ChannelCountChangeTests.

The init-time category ... maxChannels= output= log line moved to the declaration, since downmix reports like #24 lean on it. Coordinator tests were updated for the once-per-process rule, plus one for retry after failure and one for ordering behind a pending release. This lands with the next release.

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.

3 participants