|
| 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 | +} |
0 commit comments