fix(tvos): make EAC3 playback conform to Dolby's guidance

Groundwork for #1300. Establishes the session, buffering and route
handling Dolby's application guide prescribes, and adds the diagnostic
arm needed to find out whether Apple's sample-buffer renderer can carry
Atmos objects at all.

Audio session, per the guide's sequence:

- Adopt the long-form playback profile in one atomic call at app launch
  and activate the session there. The SDK only accepts that policy with
  category Playback, a Default/MoviePlayback/SpokenAudio mode and no
  options, so it cannot be assembled from separate calls.
- Report the resolved rendering mode in the player, hidden unless the
  system resolves it. Apple only resolves it for CarPlay and AirPlay, so
  an unresolved value means unknown, never "not Dolby".

Diagnostics (Apple TV only, Settings > Video Playback > Atmos Output Test):

- Add a sample-buffer arm. It reads the asset with AVAssetReader at
  outputSettings nil and hands the untouched compressed buffers and the
  untouched format description straight to the renderer, with a variant
  that rebuilds the description the way playback builds it. Every
  existing mode went through AVPlayer, so nothing exercised the path
  playback actually uses; this is what tells us whether the renderer or
  our construction is at fault.
- Add an AirPlay route picker. AirPlay is the only route where the system
  resolves the rendering mode and the supported channel layouts, so it is
  what makes those observations reachable at all, and the AVPlayer arms
  now allow external playback so every arm can be compared on the same
  destination.
- Add a session-mode toggle for the one profile difference between the
  guide and previous playback behaviour.
- Report the session profile, supported layouts, both format
  descriptions, the magic cookie and the renderer status, and release the
  session on stop so a failed run cannot contaminate the next one.

Also bumps MPVKit to 1.0.14, which carries the matching audio output
work: the channel layout AVFoundation itself uses for Dolby content, a
renderer-failure observer so the fallback to PCM can actually run, the
prescribed feed ordering and preroll, flush recovery that re-supplies the
discarded audio instead of shifting later audio into its place, and
capability-driven fallback on route and capability changes.

This does not yet fix #1300. Whether the sample-buffer renderer can carry
JOC is still unknown; it removes every difference from the documented
setup that could explain the failure, and gives us the arm to answer it
on real hardware.
This commit is contained in:
edde746
2026-07-26 20:42:58 +02:00
parent a56b9a3dfb
commit 6c14049e95
62 changed files with 1743 additions and 148 deletions
@@ -180,6 +180,67 @@ class _SettingsToggleItemState extends State<_SettingsToggleItem> {
}
}
/// Reflects the system's resolved audio rendering mode, as the Dolby
/// application guide requires. Renders nothing until the system reports a
/// conclusive value: Apple only resolves `renderingMode` for CarPlay and
/// AirPlay routes, and showing "Stereo" for an inconclusive HDMI route would
/// be worse than showing nothing.
class _AudioRenderingModeItem extends StatefulWidget {
const _AudioRenderingModeItem({required this.player});
final Player player;
@override
State<_AudioRenderingModeItem> createState() => _AudioRenderingModeItemState();
}
class _AudioRenderingModeItemState extends State<_AudioRenderingModeItem> {
AudioRenderingMode? _mode;
Timer? _poll;
@override
void initState() {
super.initState();
unawaited(_refresh());
_poll = Timer.periodic(const Duration(seconds: 2), (_) => unawaited(_refresh()));
}
@override
void dispose() {
_poll?.cancel();
super.dispose();
}
Future<void> _refresh() async {
final mode = await widget.player.getAudioRenderingMode();
if (!mounted) return;
setState(() => _mode = mode);
}
@override
Widget build(BuildContext context) {
final mode = _mode;
if (mode == null || !mode.isConclusive) return const SizedBox.shrink();
final label = switch (mode.rawValue) {
AudioRenderingMode.dolbyAtmos => t.videoSettings.audioOutputDolbyAtmos,
AudioRenderingMode.dolbyAudio => t.videoSettings.audioOutputDolbyAudio,
AudioRenderingMode.surround => t.videoSettings.audioOutputSurround,
AudioRenderingMode.spatialAudio => t.videoSettings.audioOutputSpatial,
_ => t.videoSettings.audioOutputStereo,
};
final highlighted = mode.isDolbyAtmos || mode.isDolbyAudio;
return FocusableListTile(
leading: AppIcon(
Symbols.spatial_audio_rounded,
fill: 1,
color: highlighted ? Colors.amber : tokens(context).textMuted,
),
title: Text(t.videoSettings.audioOutput),
trailing: Text(label, style: TextStyle(color: tokens(context).textMuted)),
);
}
}
/// Unified settings sheet for playback adjustments with in-sheet navigation
class VideoSettingsSheet extends StatefulWidget {
final Player player;
@@ -580,6 +641,12 @@ class _VideoSettingsSheetState extends State<VideoSettingsSheet> {
onAfterWrite: widget.player.setAudioPassthrough,
),
// Dolby playback badge. The Dolby application guide requires the app
// to reflect AVAudioSession.renderingMode; Apple only resolves that
// for CarPlay/AirPlay routes, so it is hidden rather than shown as
// "not Dolby" when the system reports notApplicable.
if (PlatformDetector.isAppleTV()) _AudioRenderingModeItem(player: widget.player),
// Audio Normalization
_SettingsToggleItem(
pref: SettingsService.audioNormalization,