Skip to content

fix(airplay): keep the SDR master so native subtitles reach the receiver (#227) - #228

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/ae227-airplay-native-subtitles
Jul 27, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/ae227-airplay-native-subtitles

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Refs #227 (reported by @thatcube).

Root cause

The reporter's reading of the code is correct. HLSVideoEngine.resolveUseMasterPlaylist already forces the master playlist for any routing-safe subtitled source (#15), so an SDR source with text tracks resolves to master.m3u8 with its EXT-X-MEDIA:TYPE=SUBTITLES renditions. The #86 AirPlay rewrite then discarded that: while external playback is active it rebuilt the playback URL on the device's LAN IP and forced /media.m3u8 for every source. A media playlist has no EXT-X-MEDIA tags, so the receiver was handed a manifest with no legible group, setNativeSubtitleSelected(track:) had nothing to select against, and the call succeeded while changing nothing. Mutually exclusive by construction, exactly as described.

The constraint that motivated the blanket downgrade is narrower than the rule built on it. DrHurt's caveat in #86 was specifically that "AVPlayer will reject a DV/HDR master playlist on an SDR receiver and will not automatically switch"; the safe-universal media routing was his suggestion on top of it. An SDR variant is routing-safe on any receiver.

Fix

  • SDR keeps the master on the AirPlay hop, so its subtitle renditions travel. The master's EXT-X-MEDIA URIs are relative, so they resolve against the LAN base with no extra work.
  • HDR/DV keeps the media downgrade. The reporter's first direction (a master with a single SDR variant) was tried and reverted in Unify handling of dynamic range checks #98 Stage 1.5: forcing VIDEO-RANGE=SDR does not fool the external-display compatibility gate, which reads the real colr/codec rather than the manifest string. So the second direction, master only when the source is SDR, is the one the manifests actually allow.
  • The constraint is now exposed rather than silent, which is the reporter's third direction: nativeSubtitleRenditionsServed reports the playlist actually served to the receiver instead of the one the local session resolved, so it goes false on an HDR/DV AirPlay hop and a host can tell the user their subtitles will not travel. No new API needed; the flag already promised exactly this and was simply lying on that path.
  • The master-rejection fallback is AirPlay-aware. It reloaded session.mediaPlaylistURL, the 127.0.0.1 loopback the receiver cannot reach. A receiver that rejects the kept SDR master (an older receiver with no 4K HEVC, say) now recovers onto the LAN media playlist instead of loading nothing. This was latent before the change: servingMasterPlaylist read true on the AirPlay path while media was actually served, so a rejection already routed into that dead fallback.

AirPlayPlaylistDecision holds the keep-master gate and the URL rewrite as pure functions, in the style of MasterFallbackDecision / StartupReadinessGate. HLSVideoEngine.servedSourceIsHDR publishes what the served variant signals so the gate does not re-derive it.

The #35 startup-readiness gate also loads loopback URLs, but it arms only on a real display-criteria panel switch, which is tvOS-only, so it cannot collide with the iOS AirPlay path.

Verification

  • AirPlayPlaylistDecisionTests, 6 new cases (keep/downgrade gate, host swap keeps the port, media path forcing, idempotent re-rewrite).
  • Full suite 1106 tests green; swift build -Xswiftc -strict-concurrency=complete clean; standalone iOS and tvOS builds clean, no warnings.
  • Not device-verified yet: the behaviour change is on the wireless AirPlay hop, which needs an iPad plus receiver.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB

…ver (#227)

A SUBTITLES rendition can only be declared in a master playlist, but the #86
AirPlay rewrite forced the media playlist for every source on its way to the
LAN IP, so the receiver got a manifest with no EXT-X-MEDIA tags:
setNativeSubtitleSelected(track:) had no legible group to select against,
succeeded, and rendered nothing.

The constraint behind the blanket downgrade is narrower than the rule built on
it: AVPlayer rejects an HDR/DV master on a receiver that is not in HDR or DV
mode. An SDR variant is routing-safe on any receiver, so it keeps its master
and the renditions travel (the master's rendition URIs are relative and resolve
against the LAN base). HDR/DV keeps the downgrade, since an SDR-signalled
master over HDR content does not fool the compatibility gate either (#98
Stage 1.5).

- AirPlayPlaylistDecision: pure keep-master gate plus the LAN-IP URL rewrite,
  in the style of MasterFallbackDecision.
- HLSVideoEngine.servedSourceIsHDR: what the served variant signals, so the
  gate does not have to re-derive it.
- nativeSubtitleRenditionsServed now reports the playlist actually served to
  the receiver, not the one the local session resolved, so a host can tell the
  user that subtitles will not travel on an HDR/DV AirPlay hop.
- The master-rejection fallback rewrites onto the LAN IP too; it previously
  reloaded the 127.0.0.1 media playlist, which a receiver cannot reach.

Reported by thatcube. Tests: AirPlayPlaylistDecisionTests (6), full suite
1106 green, iOS + tvOS builds clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
@superuser404notfound
superuser404notfound merged commit 0f90ca5 into main Jul 27, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/ae227-airplay-native-subtitles branch July 27, 2026 04:21
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