Skip to content

Commit 895ccd0

Browse files
Vincent Herbstclaude
andcommitted
fix(hdr): the loopback route takes its Dolby Vision label back from the item (#515)
On macOS `AVPlayer.availableHDRModes` is API_UNAVAILABLE, so `supportsDolbyVision` is false on every Mac unless the host asserts it, and `effectiveVideoFormat` sends a Profile 5 PQ base to `.hdr10`. The session goes on playing the `dvh1` sample entry the engine served, so a host reading `videoFormat` badged a Dolby Vision session HDR10. Measured in #493 with the assertion off on a 16" XDR: Profile 5 and Profile 8.1 both strobe against Dolby's reference content, so the RPU reaches the pixels with no claim set anywhere and the clamp was moving nothing but the label. `NativeAVPlayerHost` already parses the item's sample entry for the remote-HLS bypass; the loopback route now reads the same publisher, as an upgrade only. Mirroring the `loadRemoteHLS` sink was the wrong shape and the case that rules it out is tvOS: a Profile 5 master carries `dvh1` on every panel, so an unconditional copy would relabel a session on a panel parked in SDR, whose label is deliberately `.sdr`, as Dolby Vision, and would overwrite a `sourceVideoFormat` the probe had already answered better. `dolbyVisionLabelUpgrade` therefore fires only where the platform has no per-mode capability table, only from `.hdr10`, only for a source the probe called Dolby Vision, and only on a `dvh1` / `dvhe` item. Profile 8.1 keeps `.hdr10`: it reports `hvc1`, it composes anyway, and nothing in the stack says so. Also renames the host's format line from `remote-HLS videoFormat=` to `item videoFormat=`. It runs on every native session, and naming the wrong route cost a reporter time on a log where the route was the question. Reported and diagnosed by @Rasmusmart57, down to the two line numbers. 7 tests, full suite green on both runners (XCTest 607 with 1 skipped, swift-testing 2781 in 379 suites, real EXIT=0). Re #515, measured in #493. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014tQ8MerNbZQdWBpDStitoD
1 parent 9931c1a commit 895ccd0

7 files changed

Lines changed: 178 additions & 2 deletions

File tree

‎Sources/AetherEngine/AetherEngine+Loading.swift‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,17 @@ extension AetherEngine {
12641264
}
12651265
.store(in: &nativeCancellables)
12661266
startLiveWindowTimer(host: host)
1267+
// AE#515: the same parse `loadRemoteHLS` mirrors, read here as an upgrade only. This route has a
1268+
// probe, so `sourceVideoFormat` is already answered and `videoFormat` is the clamped label; what
1269+
// the item adds is the one thing the clamp cannot know on a platform without a capability table,
1270+
// namely that AVFoundation is playing a Dolby Vision sample entry. Mirroring the sink instead
1271+
// would overwrite a tvOS label the panel answered for.
1272+
host.$detectedVideoFormat
1273+
.compactMap { $0 }
1274+
.sink { [weak self] fmt in
1275+
self?.applyDolbyVisionLabelUpgrade(itemFormat: fmt)
1276+
}
1277+
.store(in: &nativeCancellables)
12671278
wireCommonHostSinks(
12681279
duration: host.$duration,
12691280
isReady: host.$isReady,
@@ -2343,4 +2354,24 @@ extension AetherEngine {
23432354
EngineLog.emit("[AetherEngine] HDR10+ T.35 detected, upgrading videoFormat .hdr10 → .hdr10Plus", category: .engine)
23442355
videoFormat = .hdr10Plus
23452356
}
2357+
2358+
/// AE#515: republish a clamped Dolby Vision label once the item AVFoundation is playing says so.
2359+
/// Called from the loopback route's item-format sink; `dolbyVisionLabelUpgrade` carries the rule and
2360+
/// the reason for every term. `sourceVideoFormat` is untouched: the probe answered that one already,
2361+
/// and better than a sample entry can.
2362+
@MainActor
2363+
private func applyDolbyVisionLabelUpgrade(itemFormat: VideoFormat) {
2364+
guard let upgraded = Self.dolbyVisionLabelUpgrade(
2365+
publishedFormat: videoFormat,
2366+
sourceFormat: sourceVideoFormat,
2367+
itemFormat: itemFormat,
2368+
perModeCapabilitiesObservable: Self.perModeDisplayCapabilitiesObservable
2369+
) else { return }
2370+
EngineLog.emit(
2371+
"[AetherEngine] item carries a Dolby Vision sample entry, upgrading videoFormat "
2372+
+ "\(videoFormat) → \(upgraded); this display reports no per-mode capabilities and the "
2373+
+ "clamp had nothing to read (#515)",
2374+
category: .engine)
2375+
videoFormat = upgraded
2376+
}
23462377
}

‎Sources/AetherEngine/AetherEngine+Probe.swift‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,44 @@ extension AetherEngine {
638638
return effectiveFormat
639639
}
640640

641+
/// AE#515 (from #493): the label a loopback session takes back from the item AVFoundation is playing,
642+
/// where the platform has no capability table to clamp it against.
643+
///
644+
/// `AVPlayer.availableHDRModes` is `API_UNAVAILABLE(macos)`, so `supportsDolbyVision` is false on
645+
/// every Mac unless the host asserts it, and `effectiveVideoFormat` sends a Profile 5 PQ base to
646+
/// `.hdr10`. Measured with the assertion off on a 16" XDR: Profile 5 and Profile 8.1 both strobe
647+
/// against Dolby's reference content, so the RPU reaches the pixels with no claim set anywhere and
648+
/// the clamp was moving nothing but the label. `NativeAVPlayerHost` already parses the served item's
649+
/// sample entry, and a `dvh1` / `dvhe` entry is that session's own evidence.
650+
///
651+
/// An upgrade rather than the unconditional mirror `loadRemoteHLS` wires, and each term earns its
652+
/// place by a case it keeps out:
653+
///
654+
/// - `perModeCapabilitiesObservable` keeps tvOS and iOS out, where the table answers and the label
655+
/// follows it. A Profile 5 master carries `dvh1` on every panel, so the mirror would relabel a
656+
/// tvOS session parked in SDR, or one on an HDR10-only panel, as Dolby Vision.
657+
/// - `.hdr10` is the only clamped value taken back. `.sdr` is the clamp being right about a display
658+
/// that presents no HDR at all, and `.dolbyVision` is a session that already says so.
659+
/// - the item term is what the evidence actually is. Profile 8.1 reports `hvc1` and composes anyway,
660+
/// which nothing in the stack reports, so it keeps `.hdr10`.
661+
/// - the source term is the engine's own probe agreeing. A probe that did not call the source Dolby
662+
/// Vision leaves no RPU to compose, and the disagreement is a packaging fault worth seeing rather
663+
/// than a label to publish.
664+
///
665+
/// `nil` means leave the published label alone.
666+
nonisolated static func dolbyVisionLabelUpgrade(
667+
publishedFormat: VideoFormat,
668+
sourceFormat: VideoFormat,
669+
itemFormat: VideoFormat,
670+
perModeCapabilitiesObservable: Bool
671+
) -> VideoFormat? {
672+
guard !perModeCapabilitiesObservable,
673+
publishedFormat == .hdr10,
674+
sourceFormat == .dolbyVision,
675+
itemFormat == .dolbyVision else { return nil }
676+
return .dolbyVision
677+
}
678+
641679
/// AE#459: what this session takes the panel to be presenting, from the host's assertion and the
642680
/// engine's own criteria readout.
643681
///

‎Sources/AetherEngine/AetherEngine.swift‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,21 @@ public final class AetherEngine: ObservableObject {
13101310
#endif
13111311
}
13121312

1313+
/// AE#515: whether this platform can be asked what the display presents, mode by mode.
1314+
///
1315+
/// True exactly where `displayCapabilities` reads `AVPlayer.availableHDRModes`. Everywhere else the
1316+
/// per-mode terms are not an observation: HDR10 and HLG are answered from eligibility, and Dolby
1317+
/// Vision is left to a host assertion because nothing can observe it. `dolbyVisionLabelUpgrade` is
1318+
/// the one rule that turns on the difference, so it is named rather than re-derived from `#if`s at
1319+
/// the call site.
1320+
nonisolated static let perModeDisplayCapabilitiesObservable: Bool = {
1321+
#if os(tvOS) || os(iOS)
1322+
return true
1323+
#else
1324+
return false
1325+
#endif
1326+
}()
1327+
13131328
// MARK: - View binding
13141329

13151330
/// Weak: dropping the view reference must not leak the surface through the engine singleton.

‎Sources/AetherEngine/Native/NativeAVPlayerHost.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,10 @@ final class NativeAVPlayerHost {
22302230
/// format instead of the `.sdr` default. Called at readyToPlay and again at first `.playing` (an HLS
22312231
/// video track can be absent from `item.tracks` at the readyToPlay instant). No-op for the item once it
22322232
/// has been replaced; leaves `detectedVideoFormat` nil while no video track resolves (audio-only black).
2233+
///
2234+
/// AE#515: this runs on every native session, the loopback route included, where the engine reads it
2235+
/// as a Dolby Vision label upgrade rather than as the format itself. The line used to name itself
2236+
/// `remote-HLS` on both, which cost a reporter time on a log where the route was the question.
22332237
@MainActor
22342238
private func publishDetectedVideoFormat(from item: AVPlayerItem) async {
22352239
let sid = sessionID
@@ -2249,7 +2253,7 @@ final class NativeAVPlayerHost {
22492253
if detectedVideoFormat != fmt {
22502254
detectedVideoFormat = fmt
22512255
EngineLog.emit(
2252-
"[NativeAVPlayerHost] #\(sessionID) remote-HLS videoFormat=\(fmt) "
2256+
"[NativeAVPlayerHost] #\(sessionID) item videoFormat=\(fmt) "
22532257
+ "subType='\(fourccString(subType))' transfer=\(transfer ?? "nil") "
22542258
+ "rate=\(rate.map { String(format: "%.3f", $0) } ?? "nil")",
22552259
category: .engine
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import Foundation
2+
import Testing
3+
@testable import AetherEngine
4+
5+
/// AE#515 (split out of #493): the label a loopback session takes back from AVFoundation's own parse.
6+
///
7+
/// On macOS `AVPlayer.availableHDRModes` is `API_UNAVAILABLE`, so `supportsDolbyVision` is false on
8+
/// every Mac unless the host asserts it, and `effectiveVideoFormat` clamps a Profile 5 PQ base to
9+
/// `.hdr10`. Measured in #493 with the assertion off, on a 16" XDR: Profile 5 and Profile 8.1 both
10+
/// strobe against Dolby's reference content, so the RPU reaches the pixels with no claim set anywhere
11+
/// and the clamp was moving nothing but the label. The item's own sample entry is the evidence that
12+
/// takes it back, and it is an upgrade rather than a mirror, because the same parse is right about the
13+
/// item and wrong about the panel everywhere the platform can answer for itself.
14+
struct Issue515LoopbackDolbyVisionLabelTests {
15+
16+
private func upgrade(
17+
published: VideoFormat,
18+
source: VideoFormat = .dolbyVision,
19+
item: VideoFormat = .dolbyVision,
20+
perModeCapabilities: Bool = false
21+
) -> VideoFormat? {
22+
AetherEngine.dolbyVisionLabelUpgrade(
23+
publishedFormat: published,
24+
sourceFormat: source,
25+
itemFormat: item,
26+
perModeCapabilitiesObservable: perModeCapabilities)
27+
}
28+
29+
// MARK: - What it takes back
30+
31+
@Test("AE#515: a clamped Dolby Vision label is upgraded from the item's dvh1 sample entry")
32+
func clampedDolbyVisionLabelIsUpgraded() {
33+
#expect(upgrade(published: .hdr10) == .dolbyVision)
34+
}
35+
36+
@Test("AE#515: the upgrade lands once, so a label already reading Dolby Vision is not republished")
37+
func assertedSessionIsLeftAlone() {
38+
#expect(upgrade(published: .dolbyVision) == nil)
39+
}
40+
41+
// MARK: - What the guard keeps out
42+
43+
/// The clamp is right whenever the display cannot present HDR at all: macOS on an SDR monitor
44+
/// resolves the same source to `.sdr` through `supportsHDR10 == false`, and on tvOS a panel parked
45+
/// in SDR gets `.sdr` from `presentedVideoFormat`. Neither is a session whose label lost a Dolby
46+
/// Vision it was presenting.
47+
@Test("AE#515: an SDR label is the clamp being right, and stays")
48+
func sdrLabelStays() {
49+
#expect(upgrade(published: .sdr) == nil)
50+
}
51+
52+
/// The case that rules out mirroring the `loadRemoteHLS` sink into `loadNative`. A Profile 5 master
53+
/// carries a `dvh1` sample entry on every panel, so an unguarded copy would relabel a tvOS session
54+
/// on a panel parked in SDR, or on an HDR10-only panel, as Dolby Vision. There the platform has a
55+
/// per-mode table and the label follows it.
56+
@Test("AE#515: a platform that can observe its display keeps its own answer")
57+
func perModeCapabilityPlatformKeepsItsAnswer() {
58+
#expect(upgrade(published: .hdr10, perModeCapabilities: true) == nil)
59+
}
60+
61+
/// Profile 8.1 reports `hvc1` with the Dolby Vision configuration alongside it, and it composes on
62+
/// that display all the same. Nothing in the stack reports that, so `.hdr10` is the honest label and
63+
/// this rule does not guess past its evidence.
64+
@Test("AE#515: an hvc1 item leaves the label where the clamp put it")
65+
func hvc1ItemDoesNotUpgrade() {
66+
#expect(upgrade(published: .hdr10, item: .hdr10) == nil)
67+
}
68+
69+
/// The engine's probe and AVFoundation's parse disagreeing is a packaging fault worth seeing in the
70+
/// log, not a label to publish: a source the probe did not call Dolby Vision has no RPU to compose.
71+
@Test("AE#515: a source the probe did not call Dolby Vision is not relabelled by the item alone")
72+
func itemParseAloneDoesNotRelabel() {
73+
#expect(upgrade(published: .hdr10, source: .hdr10) == nil)
74+
}
75+
76+
/// Boundary, deliberately drawn where the measurement stops. A Profile 8.4 HLG base clamps to
77+
/// `.hlg`, and an HDR10+ payload can upgrade a Profile 8 base to `.hdr10Plus` before the item parse
78+
/// arrives. Neither was measured on a macOS display, and in practice the order settles it: this
79+
/// upgrade runs at `readyToPlay`, the T.35 one on the SEI tap during playback, and each blocks the
80+
/// other by its own guard.
81+
@Test("AE#515: only the PQ clamp is taken back, the HLG and HDR10+ labels are not")
82+
func onlyThePQClampIsTakenBack() {
83+
#expect(upgrade(published: .hlg) == nil)
84+
#expect(upgrade(published: .hdr10Plus) == nil)
85+
}
86+
}

‎docs/api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ Time lives on `player.clock`, a separate `ObservableObject`, so ~10 Hz ticks nev
421421
| `$startupProgress` | `StartupProgress?` for a determinate loading bar. |
422422
| `$videoRoute` | `VideoRoute`: which pipeline is actually serving, one of `.none`, `.remoteBypass`, `.loopback`, `.software`, `.audio`. `LoadOptions.nativeRemoteHLS` is only the request; the carriage watchdog, the remembered verdict and the HLS reroutes move a session between routes, mid-session too. Branch on this, above all for who draws subtitles. |
423423
| `$audioDelivery` | `AudioDelivery`: how the audio reaches the renderer, one of `.none`, `.noAudioInSource`, `.streamCopy`, `.bridged`, `.decoded`, `.droppedNoPipeline`, `.playerManaged`. `.droppedNoPipeline` is a source that HAS audio playing video-only because no pipeline could be built for it: the value a fallback ladder demotes on. See [Reading whether the audio was delivered](#reading-whether-the-audio-was-delivered). |
424-
| `$videoFormat` | The format being presented: `.sdr`, `.hdr10`, `.hdr10Plus`, `.dolbyVision`, `.hlg`. |
424+
| `$videoFormat` | The format being presented: `.sdr`, `.hdr10`, `.hdr10Plus`, `.dolbyVision`, `.hlg`. On a platform with no per-mode capability table (macOS), a Dolby Vision session the clamp sent to `.hdr10` is upgraded back to `.dolbyVision` once the item AVFoundation is playing turns out to carry a `dvh1` / `dvhe` sample entry (AE#515). |
425425
| `$sourceVideoFormat` | The format the **source** carries, before any panel-driven mapping. The pair is what an honest badge needs: HDR content on an SDR panel differs between the two. |
426426
| `$sourceDVProfile`, `$sourceVideoFrameRate`, `$sourceVideoBitrate` | Source detail for an info panel. |
427427
| `$sourceVideoCodecName` | The source video codec in the libavcodec spelling ("hevc", "h264", "av1"), nil when the source carries no video. The probe-free remote-HLS bypass maps it back from the item's video sample type, so the field answers on every route rather than going quiet on one of them. Not the same question as `$activeVideoDecoder`: a codec has several decoders, and which one runs depends on the hardware. |

‎docs/formats.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ ST 2094-40 metadata stays attached to the HEVC bitstream as user-data-registered
169169

170170
The published `videoFormat` starts at `.hdr10` for any BT.2020 / PQ source and flips to `.hdr10Plus` the first time a packet's T.35 SEI signature is seen in the producer's scan. Debounced across producer restarts so a scrub doesn't re-fire. Hosts can drive an HDR10+ badge or analytics hook off the `$videoFormat` transition.
171171

172+
The label can also be taken back from the item itself, where the platform has no capability table to clamp it against (AE#515). A Dolby Vision source on macOS resolves to `.hdr10`, because `supportsDolbyVision` is unclaimable there without a host assertion, while AVFoundation goes on playing the `dvh1` sample entry the engine served. Measured with the assertion off on a 16" XDR, a Profile 5 and a Profile 8.1 grade of Dolby's reference content both strobe, so the RPU reaches the pixels with no claim set anywhere and the clamp was moving nothing but the label. When the item's sample entry reads `dvh1` / `dvhe` and the probe agrees the source is Dolby Vision, the label is upgraded from `.hdr10` to `.dolbyVision` at `readyToPlay`. It is an upgrade and not a mirror of what AVFoundation parsed, for two reasons that both matter: an `.sdr` label is the clamp being right about a display presenting no HDR at all, and on tvOS and iOS the per-mode table answers the capability question, so the label follows it rather than a sample entry that a Profile 5 master carries on every panel. Profile 8.1 keeps `.hdr10` on macOS: it reports `hvc1` with the DV configuration alongside it, it composes on that display all the same, and nothing in the stack reports that.
173+
172174
## Audio
173175

174176
| | |

0 commit comments

Comments
 (0)