|
1 | 1 | import Foundation |
2 | 2 | import Testing |
| 3 | +import AetherLibavcodec |
3 | 4 | import AetherLibavutil |
4 | 5 | @testable import AetherEngine |
5 | 6 |
|
@@ -144,4 +145,94 @@ struct Issue493HostDisplayAssertionTests { |
144 | 145 | #expect(SessionOptionCorrection.refusedFields( |
145 | 146 | from: LoadOptions(), to: LoadOptions(panelPresentsDolbyVision: true)).isEmpty) |
146 | 147 | } |
| 148 | + |
| 149 | + // MARK: - What the assertion no longer changes about the served bytes |
| 150 | + |
| 151 | + /// An HEVC / AV1 `AVCodecParameters` carrying a DOVI configuration record, freed with the test. |
| 152 | + private final class DVCodecpar { |
| 153 | + let ptr: UnsafeMutablePointer<AVCodecParameters> |
| 154 | + |
| 155 | + init(codecID: AVCodecID, profile: UInt8, compat: UInt8, trc: AVColorTransferCharacteristic) { |
| 156 | + ptr = avcodec_parameters_alloc() |
| 157 | + ptr.pointee.codec_type = AVMEDIA_TYPE_VIDEO |
| 158 | + ptr.pointee.codec_id = codecID |
| 159 | + ptr.pointee.width = 3840 |
| 160 | + ptr.pointee.height = 2160 |
| 161 | + ptr.pointee.level = 153 |
| 162 | + ptr.pointee.color_primaries = AVCOL_PRI_BT2020 |
| 163 | + ptr.pointee.color_trc = trc |
| 164 | + ptr.pointee.color_space = AVCOL_SPC_BT2020_NCL |
| 165 | + let size = MemoryLayout<AVDOVIDecoderConfigurationRecord>.size |
| 166 | + guard let sd = av_packet_side_data_new( |
| 167 | + &ptr.pointee.coded_side_data, &ptr.pointee.nb_coded_side_data, |
| 168 | + AV_PKT_DATA_DOVI_CONF, size, 0 |
| 169 | + ) else { fatalError("could not attach a DOVI configuration record") } |
| 170 | + memset(sd.pointee.data, 0, size) |
| 171 | + sd.pointee.data.withMemoryRebound(to: AVDOVIDecoderConfigurationRecord.self, capacity: 1) { rec in |
| 172 | + rec.pointee.dv_version_major = 1 |
| 173 | + rec.pointee.dv_profile = profile |
| 174 | + rec.pointee.dv_level = 6 |
| 175 | + rec.pointee.rpu_present_flag = 1 |
| 176 | + rec.pointee.el_present_flag = profile == 7 ? 1 : 0 |
| 177 | + rec.pointee.bl_present_flag = 1 |
| 178 | + rec.pointee.dv_bl_signal_compatibility_id = compat |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + deinit { |
| 183 | + var p: UnsafeMutablePointer<AVCodecParameters>? = ptr |
| 184 | + avcodec_parameters_free(&p) |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + private static func route( |
| 189 | + codecID: AVCodecID = AV_CODEC_ID_HEVC, |
| 190 | + profile: UInt8, |
| 191 | + compat: UInt8, |
| 192 | + trc: AVColorTransferCharacteristic = AVCOL_TRC_SMPTE2084, |
| 193 | + dvDisplay: Bool |
| 194 | + ) throws -> HLSVideoEngine.CodecRoute { |
| 195 | + let par = DVCodecpar(codecID: codecID, profile: profile, compat: compat, trc: trc) |
| 196 | + let engine = HLSVideoEngine(url: URL(fileURLWithPath: "/dev/null"), dvModeAvailable: dvDisplay) |
| 197 | + return try engine.resolveCodecRoute(codecpar: UnsafePointer(par.ptr)) |
| 198 | + } |
| 199 | + |
| 200 | + /// Everything the muxer and the manifest read out of a route, as one comparable line. |
| 201 | + private static func packaging(_ r: HLSVideoEngine.CodecRoute) -> String { |
| 202 | + "tag=\(r.codecTagOverride ?? "nil") range=\(r.videoRange) codecs=\(r.primaryCodecs) " |
| 203 | + + "supplemental=\(r.supplementalCodecs ?? "nil") dovi=\(r.doviConfig) " |
| 204 | + + "p7convert=\(r.convertP7ToProfile81) variant=\(r.dvVariant)" |
| 205 | + } |
| 206 | + |
| 207 | + /// 6.72.0 gave the non-DV branch its `dvcC` back and 6.73.0 its `SUPPLEMENTAL-CODECS`, which left the |
| 208 | + /// three grades a Dolby Vision display used to be served differently identical on both branches. So |
| 209 | + /// the assertion no longer decides a byte of the served stream for them, only the published |
| 210 | + /// `videoFormat`, the tvOS criteria request, and the HDR readiness that rides along. Measured the |
| 211 | + /// same day against the matched Dolby P5 / P8.1 / P8.4 grades on macOS: master, media playlist, |
| 212 | + /// init.mp4 and seg0.mp4 came back md5-identical with and without the claim. |
| 213 | + @Test("AE#493: the assertion does not move the packaging of P5, P8.1 or P8.4", |
| 214 | + arguments: [(UInt8(5), UInt8(0)), (UInt8(8), UInt8(1)), (UInt8(8), UInt8(4))]) |
| 215 | + func assertionLeavesTheHEVCPackagingAlone(grade: (profile: UInt8, compat: UInt8)) throws { |
| 216 | + let trc: AVColorTransferCharacteristic = grade.compat == 4 ? AVCOL_TRC_ARIB_STD_B67 : AVCOL_TRC_SMPTE2084 |
| 217 | + let asserted = try Self.route(profile: grade.profile, compat: grade.compat, trc: trc, dvDisplay: true) |
| 218 | + let control = try Self.route(profile: grade.profile, compat: grade.compat, trc: trc, dvDisplay: false) |
| 219 | + #expect(Self.packaging(asserted) == Self.packaging(control)) |
| 220 | + } |
| 221 | + |
| 222 | + /// The two grades where it still does, so "the claim changes nothing" cannot quietly become the rule: |
| 223 | + /// P7 needs the per-packet RPU conversion to 8.1 and its supplemental, and the AV1 DV record is read |
| 224 | + /// only on a display that takes it, so a non-DV display gets plain `av01` rather than `dav1`. |
| 225 | + @Test("AE#493: P7 and AV1 Dolby Vision are still packaged by the claim") |
| 226 | + func assertionStillMovesTheGatedGrades() throws { |
| 227 | + let p7Asserted = try Self.route(profile: 7, compat: 0, dvDisplay: true) |
| 228 | + let p7Control = try Self.route(profile: 7, compat: 0, dvDisplay: false) |
| 229 | + #expect(Self.packaging(p7Asserted) != Self.packaging(p7Control)) |
| 230 | + #expect(p7Asserted.convertP7ToProfile81) |
| 231 | + #expect(p7Control.convertP7ToProfile81 == false) |
| 232 | + |
| 233 | + let av1Asserted = try Self.route(codecID: AV_CODEC_ID_AV1, profile: 10, compat: 1, dvDisplay: true) |
| 234 | + let av1Control = try Self.route(codecID: AV_CODEC_ID_AV1, profile: 10, compat: 1, dvDisplay: false) |
| 235 | + #expect(av1Asserted.codecTagOverride == "dav1") |
| 236 | + #expect(av1Control.codecTagOverride == "av01") |
| 237 | + } |
147 | 238 | } |
0 commit comments