Skip to content

Add public audio output routing API surface - #370

Draft
MaxHeimbrock wants to merge 1 commit into
mainfrom
max/par-019-routing-api-surface
Draft

Add public audio output routing API surface#370
MaxHeimbrock wants to merge 1 commit into
mainfrom
max/par-019-routing-api-surface

Conversation

@MaxHeimbrock

Copy link
Copy Markdown
Contributor

Background

First card of the platform-audio routing redesign's phase A (PAR-019): apps need a supported, cross-platform way to influence audio output routing (speaker vs. earpiece, ranked device-kind preferences, explicit device overrides, device-change notifications) instead of reaching into platform APIs themselves. This PR defines that public API surface on PlatformAudio, purely in C#, shaped identically to what the later FFI-backed implementation will expose — so nothing written against it is throwaway when the plumbing is swapped underneath.

Changes

  • Added AudioOutputKind enum (Unknown, Earpiece, Speaker, WiredHeadset, Bluetooth, Usb, HearingAid); numeric values mirror the planned FFI protocol enum one-to-one.
  • AudioDevice gains Kind and IsSelected (documented as not yet populated — no backend reports them).
  • New public API on PlatformAudio:
    • OutputPreference — ranked automatic output policy; default Bluetooth > WiredHeadset > Speaker > Earpiece.
    • IsSpeakerOutputPreferred — documented precedence rule: the bool is sugar that only rewrites the relative order of Speaker/Earpiece inside OutputPreference; the list is the single source of truth.
    • SelectOutput(AudioDevice) / ClearOutputOverride() — sticky override of the automatic policy; bogus devices throw ArgumentException.
    • DevicesChanged event (playout, recording), raised on the Unity main thread; safe to (un)subscribe across Dispose.
  • Internal IRouteController backend seam with per-platform registration: DesktopRouteController wraps the existing FFI enumeration/GUID selection; UnsupportedRouteController covers Android/iOS until their phase-A backends land (documented throws/no-ops — no silent fake success anywhere).
  • PlayMode tests: preference set/get roundtrip and validation, precedence rule in both directions (incl. missing-kind insertion), bogus SelectOutput throws, DevicesChanged subscribe/unsubscribe safe across dispose.

Define the phase-A routing API on PlatformAudio, purely in C# and shaped
identically to the planned FFI-backed implementation so app code written
against it survives the plumbing swap:

- AudioOutputKind enum (values mirror the planned FFI proto enum 1:1)
- AudioDevice.Kind / AudioDevice.IsSelected
- OutputPreference ranked policy (default BT > wired > speaker > earpiece)
- IsSpeakerOutputPreferred as documented sugar over the list order
- SelectOutput / ClearOutputOverride sticky override
- DevicesChanged event (playout, recording) on the Unity main thread
- internal IRouteController seam with desktop (FFI enumeration/GUID
  selection) and unsupported-mobile implementations; Android/iOS
  backends plug into the seam in follow-up work

Co-Authored-By: Claude Fable 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