Skip to content

fix(airplay): make the wireless hop work again, and carry subtitles as far as the receiver allows (#227) - #229

Merged
superuser404notfound merged 14 commits into
mainfrom
feat/ae227-airplay-hdr-master
Jul 27, 2026
Merged

superuser404notfound merged 14 commits into
mainfrom
feat/ae227-airplay-hdr-master

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Refs #227. Follow-up to 5.23.8, entirely device-driven: iPhone 17 Pro against two Apple TV 4K receivers, 2026-07-27.

What was broken

The hop cycled and the LAN rewrite never applied. The reload started by the external-playback observer tears down the AVPlayer item that same observer watches, so a transient isExternalPlaybackActive = false arrived mid-reload and cleared airPlayActive before loadNative read it. The rebuilt session served 127.0.0.1 again, the receiver re-engaged, and that edge started the next reload. One full session rebuild per turn, forever (ports 51291, 51296, 51299, ... in the log), and [AirPlay] loadNative serving via <lan> never appeared once. Pre-existing since #86; 5.23.8 did not cause it and could not work through it.

5.23.8 was a no-op on DV-capable devices. servedSourceIsHDR was videoRange != .sdr || effectiveDvMode, and effectiveDvMode is a device capability, so SDR content on any DV-capable iPhone or iPad read as HDR and lost its renditions anyway. resolveUseMasterPlaylist carries the same warning after the same mistake in #15. Device log: sourceIsHDR=true videoRange=sdr dvVariant=none.

Recovery paths pointed at the loopback. The reactive master-rejection fallback and the startup-readiness gate's three reloads all served 127.0.0.1, which a receiver cannot reach.

What the receiver actually does

The receiver fetches for itself: its own address shows up in the server log next to the sender's, which settles the model #86 was built on. What it accepts:

Master handed over Result
SDR 1080p H.264, BANDWIDTH 7.5 Mbps plays, subtitles travel
SDR 720p HEVC, BANDWIDTH 5.0 Mbps plays
4K PQ + DV SUPPLEMENTAL-CODECS, 33.8 Mbps refused
4K PQ, DV dropped, 33.8 Mbps refused
4K PQ, DV dropped, BANDWIDTH clamped to 8 Mbps refused
4K PQ, DV dropped, RESOLUTION omitted refused
4K PQ, DV dropped, HDCP-LEVEL=TYPE-1 refused

So the trigger is VIDEO-RANGE=PQ, not the DV tag, not the declared peak, not 4K (with RESOLUTION omitted the receiver cannot know the dimensions before the first segment), not the missing HDCP level. Declaring the range as SDR is not available either, disproven on hardware in #98 Stage 1.5. Since a SUBTITLES rendition can only live in a master, HDR and DV cannot carry native subtitles to a wireless receiver at all; the media playlist is the only routable manifest for them, and the picture is unaffected because the HDR metadata rides in the segments rather than the manifest.

The refusal is silent, which matters for the code: no -11868, no failed item, the rate flickers to playing for one tick so hasEverPlayed latches, and the readiness gate waves it through. Only progress reveals it.

Changes

  • Hold an external-playback edge that lands during a session-preserving reload; reconcile against the live audio route once the rebuilt item exists, since the route survives the teardown and the player flag does not.
  • servedSourceIsHDR reads the real VIDEO-RANGE.
  • The reactive fallback and the readiness gate rewrite onto the LAN address; the gate also arms on any master handed to a receiver, with a longer first settle window because that first fetch crosses the LAN.
  • Progress watchdog: eight seconds without the clock advancing on a master handed to a receiver reloads the LAN media playlist. Verified firing on device, twice.
  • The loopback server names each distinct client once, which is how the fetch question got settled and what any future report of this shape will need.

Verification

1107 tests, swift build -Xswiftc -strict-concurrency=complete clean, standalone iOS and tvOS builds without warnings. On device: SDR source over AirPlay plays with subtitles (subs_2_77.vtt onward fetched in sequence), DV source plays without them, and a refused master recovers into playback in eight seconds instead of parking.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB

Vincent Herbst and others added 11 commits July 27, 2026 06:47
…ss (#227)

Device experiment on top of 5.23.8. DrHurt's AirPlay caveat is conditional on
the receiver's mode ("TV MUST be in HDR or DV mode to accept any non-SDR
content"), and an Apple TV defaults to HDR, so the common case would accept an
HDR/DV master and its subtitle renditions. The sender cannot read that mode, so
5.23.8 downgrades HDR/DV up front and those sources reach the receiver without
subtitles.

Offer the master instead and let the #35 startup-readiness gate decide, which is
the recovery this hop needs anyway: it covers both failure shapes (the
-11868/-11848 rejection and the silent zero-track park), escalates master ->
HDR-preserving reduced master -> media, and is bounded at every stage.

- AirPlayPlaylistDecision.attemptHDRMaster, one constant to flip back to the
  5.23.8 behaviour.
- The gate arms on any master handed to a receiver, not only on a panel switch,
  and its three reloads are rewritten onto the LAN IP (they served 127.0.0.1,
  which a receiver cannot reach).
- A 6 s first settle window on that hop: the receiver fetches across the LAN and
  runs its own handshake, which the local 3 s window can judge too early.

Not device-verified: that is what this branch is for. Tests 1107 green, iOS and
tvOS builds clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…arts (#227)

Device log 2026-07-27, DV P8.1 over wireless AirPlay: the session rebuilt itself
forever, one full teardown per turn (loopback ports 51291, 51296, 51299, ...),
and the LAN swap never applied once, so the receiver kept being handed
127.0.0.1 and no subtitles.

The observer's own reload is what breaks it. The reload tears down the item the
KVO watches, AVPlayer reports a transient isExternalPlaybackActive=false in the
middle of it, and that edge clears airPlayActive before loadNative reads it. The
rebuilt session therefore serves the loopback again, the receiver re-engages
external playback, and that true edge starts the next reload.

Hold any edge that lands while a session-preserving reload is in flight, and
reconcile once it finishes. The reconcile reads the audio route as well as the
player flag: the rebuilt item may not have re-engaged the receiver yet, and
reading the flag alone at that instant restarts the same loop.

Pre-existing since #86; it is not the HDR-master experiment on this branch,
which never got to run because the swap it depends on was skipped every time.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…s DV support (#227)

`servedSourceIsHDR` was `videoRange != .sdr || effectiveDvMode`, and
`effectiveDvMode` is a DEVICE capability. On any DV-capable iPhone or iPad it
therefore read true for SDR content (device log 2026-07-27:
`sourceIsHDR=true videoRange=sdr dvVariant=none`), so 5.23.8 kept downgrading
those sources to the media playlist and its subtitle fix was a no-op on exactly
the hardware it was written for. `resolveUseMasterPlaylist` carries the same
warning after the same mistake in #15.

Also settles the HDR-master experiment: it does not work. iPhone 17 Pro to an
Apple TV 4K in HDR mode, DV P8.1, the receiver takes the manifest and even
fetches the subtitle rendition, then AVPlayer never hands the stream over. The
picture stays at the start position and AVKit shows its "not playable on this
display" sign, with no -11868/-11848 and no failed item, so the readiness gate
cannot see it either (the rate flickers to playing for one tick and
hasEverPlayed latches). DrHurt's "TV MUST be in HDR or DV mode" is a necessary
condition, not a sufficient one. An SDR master over the same route plays with
subtitles, verified in the same session.

The HDR attempt is gone; what it taught is in the decision's doc comment. The
readiness gate stays armed on a master handed to a receiver, now for the
SDR-master case (a receiver without 4K HEVC would still reject it).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…es (#227)

The AirPlay design assumes the receiver fetches the playlist from the sender's
LAN address. The device log so far only ever shows the sender's own
AppleCoreMedia user agent, but the server dumps headers once per session, so
that proves nothing either way. Log each distinct peer address once instead: an
AirPlay session must then show the receiver's address, and if it never does the
sender is pulling the media and the LAN-IP rewrite addresses a problem that does
not exist.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…227)

Device round 2026-07-27 narrowed the DV failure: the receiver fetches for
itself (its own address now shows in the server log), takes an SDR master
including HEVC, and refuses the DV master. Untested so far is whether the DV
SUPPLEMENTAL-CODECS alone is what it refuses. The #98 reduced HDR master
answers that: source range kept, DV dropped, subtitle renditions kept. If the
receiver takes it, HDR content gets subtitles over AirPlay and only the DV
upgrade is lost on that hop.

Backed by a progress watchdog, because the refusal is silent: no -11868, no
failed item, the rate just flickers to playing for a tick and the clock never
moves, which is exactly what let the readiness gate wave the broken DV session
through earlier. Eight seconds without the clock advancing on a master handed
to a receiver now reloads the LAN media playlist.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…227)

Third suspect, and the first one the measurements point at directly. The
receiver plays 4K HEVC PQ segments off the media playlist without complaint,
so the media is within its reach; what it refuses is the master describing
those same segments. The two masters it accepted declared 5.0 and 7.5 Mbps,
this one declares 33.8. If the declared peak is what its variant filter drops,
clamping is the entire fix, and dropping DV (already the case for the reduced
master) is not needed at all.

Serves the reduced HDR master at /master_hdr_ap.m3u8 with BANDWIDTH clamped to
8 Mbps for the AirPlay hop only; the #35 gate's /master_hdr.m3u8 is untouched.
Diagnostic: if this plays, the honest question of what to declare comes next.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
HDR and 4K are perfectly confounded in the measurements so far: every master
the receiver accepted was 1080p or below, every one it refused was 4K, and
neither a 4K SDR nor a 1080p HDR source was on hand to separate them. The
literature does not settle it either, consumer sources call AirPlay video a
1080p pipe while Apple's own AirPlay 2 material and the HLS authoring rules
ask for 4K and HDR variants "appropriate for a TV".

RESOLUTION is optional in HLS, so leaving it out takes 4K out of what the
receiver can filter on without misdeclaring anything, and it cannot learn the
real dimensions before the first segment. A refusal that survives this belongs
to VIDEO-RANGE=PQ; acceptance means HDR was never the problem and HDR content
can carry its subtitle renditions after all.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…#227)

Last manifest attribute never tried. Apple's authoring spec asks for TYPE-1
above HD and our master declares no level at all, so a receiver that cannot
tell whether it may render protected 4K HDR has a reason to filter the variant
out. Scoped to the receiver-facing master only: emitting TYPE-1 generally broke
wired HDMI with -11868 / tracks count=0 when the link's HDCP 2.2 state did not
match (Vincent, 2026-05-26), which is why hdcpLevel is nil upstream, and local
playback has nothing to gain since its master already carries the renditions.

Everything else matches the run this is compared against (DV dropped, real
bandwidth, RESOLUTION present), so a difference in outcome is this attribute.
A wrong guess costs the eight seconds the watchdog needs, not the session.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…r refuses (#227)

Declaring HDCP-LEVEL=TYPE-1 changed nothing: the receiver fetched that master,
then media.m3u8 and the subtitle rendition, and never asked for a segment. The
experiment is removed and its result recorded.

That closes the manifest side. The DV supplemental, the declared peak, the
resolution attribute and the HDCP level are each ruled out, and what remains is
VIDEO-RANGE=PQ, which cannot be declared away either (#98 Stage 1.5). An HDR or
DV source therefore cannot carry subtitle renditions to a wireless AirPlay
receiver, and the media downgrade is the only routable manifest rather than a
workaround. Docs and changelog say so, with the measurements behind it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
…ses it (#227)

The receiver in every refused run was parked in SDR: output format 4K SDR with
Match Dynamic Range on, which switches only when tvOS decides the content
warrants it and evidently never does for AirPlay content. That is the same rule
the engine already applies locally, where an HDR source on a panel that is not
in HDR mode is served the media playlist, so the refusal is consistent rather
than an AirPlay prohibition, and it says nothing yet about a receiver whose
format is fixed to HDR or Dolby Vision. DrHurt's #86 advice was exactly that.

So the master is offered for HDR again, and the cost of a parked receiver is
bounded instead of permanent:

- the progress watchdog drops to 5 s, since a receiver that does take the master
  fetches its init segment within about a second of the playlist,
- and a receiver that fails to start on an HDR master is remembered by route UID
  for the rest of the process, so it goes straight to media from then on. Per
  process on purpose: switching the receiver to HDR earns the offer again on the
  next launch, and no public API reports a receiver's dynamic range.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
… yes (#227)

Device round with the Apple TV's video format fixed to 4K Dolby Vision: it
fetches the DV master, plays it, and pulls the subtitle rendition continuously
(seg264 and subs_0_328 by the time the log was cut). The same receiver on 4K
SDR with Match Dynamic Range on refuses every HDR master, which is what the
earlier rounds measured and what made the first conclusion too broad.

So Match Dynamic Range does not count as HDR readiness for AirPlay content, and
DrHurt's #86 advice was literal. Docs and changelog now say that, with the
measurement table behind it, instead of claiming HDR can never carry subtitle
renditions to a receiver.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
@superuser404notfound superuser404notfound changed the title fix(airplay): make the wireless hop work again, and only promise subtitles it can keep (#227) fix(airplay): make the wireless hop work again, and carry subtitles as far as the receiver allows (#227) Jul 27, 2026
Vincent Herbst and others added 3 commits July 27, 2026 09:57
…DR (#227)

The watchdog never fired in the field case it exists for. It was gated on
`state == .playing`, and a refused session parks at paused, so the guard was
shut exactly when it was needed; the #65 wedge recovery then nudged AVPlayer six
times and gave up while the picture stayed on AVKit's "not playable" sign
(device log 2026-07-27). The gate is gone. What replaces it is the server's own
account: a receiver that refuses the manifest fetches playlists and never a
single segment, while a merely paused session fetched its init segment long ago.
`HLSVideoEngine.hasServedMediaSegment` surfaces that.

And the fallback turns out to be the way in. A receiver on Match Dynamic Range
sits in SDR and refuses the HDR master, but it does switch its output once it is
actually rendering HDR, which the media playlist gives it: the TV changes mode
during that fallback playback (Vincent, on device). So the deadlock (no HDR mode
because no HDR playback, no HDR playback because no HDR mode) breaks from the
media side. Twelve seconds after the fallback the master is offered once more,
to a receiver that is now in HDR. Once per receiver per process and only for an
HDR source, so a receiver that stays in SDR costs a single interruption.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
Vincent's correction, and the measurement behind it beats my ordering: the
receiver switches its output to HDR during the FIRST, refused master attempt,
and it drops back to SDR while it plays the media playlist. So the window in
which the receiver is HDR-ready opens right after the refusal and closes again
once the fallback runs, which is precisely the wrong place to wait for it.

The HDR master now gets a second attempt five seconds after the first, and only
a second refusal falls back to media and remembers the receiver. Same shape as
the #35 cold-DV gate, where the failed attempt warms the link and the retry is
the one that starts. Removes the post-fallback upgrade, which aimed at a window
that had already closed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
The second attempt is out. Its premise held (the receiver does switch its output
to HDR during the refused attempt) but on device it bought nothing and only
doubled the wait before the picture appeared. For a receiver on Match Dynamic
Range the honest answer is the media playlist plus a host that can tell the user
to fix the format to HDR or Dolby Vision, which is what
nativeSubtitleRenditionsServed is for.

What stays is what the device runs proved: an SDR source keeps its master and
its subtitles, an HDR source keeps them on a receiver whose format is fixed to
HDR or DV, a refusal lands on media within five seconds, and that receiver is
then left alone for the rest of the process.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
@superuser404notfound
superuser404notfound merged commit 47e6a53 into main Jul 27, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the feat/ae227-airplay-hdr-master branch July 27, 2026 09:47
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