forge
Explore
Log in

Don't you dare go Hollow

Expose HEVC prefix-SEI HDR peak and VUI colour tags on Frame/Decoder

Browse files at this commit

7669974cc0ae2f48f187ca2b6bd4befa7a97a8eeAhmet Kaan GümüşParent: e7509e8
  • feat
    • expose HEVC prefix-SEI HDR peak and VUI colour tags on Frame/Decoder
Show full message
feat(hw): expose HEVC prefix-SEI HDR peak and VUI colour tags on Frame/Decoder

edith's replica needs MaxCLL/MaxFALL for HDR films whose container never
carried them (they live only in HEVC content_light_level/mastering_display
SEI) — ec-hw's decode() dropped every SEI NAL on the floor. HevcDecoder now
merges ec_core::color::hevc_sei_light per access unit (sticky across frames
that carry none) and resolves VUI colour tags from the SPS; H264Decoder
resolves VUI tags only (no SEI parsing for that codec yet); VP9/AV1 report
None (not implemented). New Frame::colour()/Decoder::colour() surface it,
bundled as ec_hw::frame::Colour{description, light} over the existing
ec-core ColorDescription/ContentLight types.

Tests: hdr_film_light_level_sei_is_exposed pins MaxCLL/MaxFALL 1230/419 and
primaries/transfer/matrix 9/16/9 against the real ReelD rip;
sdr_h264_colour_never_panics proves the VUI-only path doesn't panic on an
SDR fixture (skips when no fixtures generated, same convention as the rest
of gpu.rs).
crates/ec-hw/src/dec/av1.rsmodified+2 -0
@@ -115,6 +115,7 @@ impl Av1Decoder {
115115 (header.render_width, header.render_height),
116116 session.coded_size,
117117 session.bit_depth,
118+ None,
118119 ));
119120 // 7.21: showing a KEY frame again refreshes every reference slot with
120121 // it, which the reference *surfaces* have to follow too.
@@ -183,6 +184,7 @@ impl Av1Decoder {
183184 (header.render_width, header.render_height),
184185 session.coded_size,
185186 session.bit_depth,
187+ None,
186188 ));
187189 }
188190 Ok(())
crates/ec-hw/src/dec/h264.rsmodified+40 -1
@@ -2,6 +2,7 @@
22
33 use std::sync::Arc;
44
5+use ec_core::color::{ColorDescription, ContentLight, Tags};
56 use ec_h264_syntax::{
67 AnnexBIter, DecRefPicMarking, NalHeader, NalUnitType, Pps, PredWeightTable, SliceHeader,
78 SliceType, Sps, unescape_rbsp,
@@ -12,7 +13,7 @@ use ec_va::{Buffer, Display, sys};
1213 use super::dpb264::{Dpb, Mark, PicInfo, Picture, Poc, RefList};
1314 use super::{ReadyFrames, Session, StreamInfo};
1415 use crate::error::{Error, Result};
15-use crate::frame::Frame;
16+use crate::frame::{Colour, Frame};
1617 use crate::params::h264::{
1718 IQMatrixBufferH264, PICTURE_LONG_TERM_REFERENCE, PICTURE_SHORT_TERM_REFERENCE,
1819 PictureParameterBufferH264, SliceParameterBufferH264, VAPictureH264,
@@ -52,6 +53,8 @@ pub struct H264Decoder {
5253 /// Reusable unescape buffer; NAL payloads are rewritten into it in turn.
5354 rbsp: Vec<u8>,
5455 gap_frames: u64,
56+ /// The most recent SPS's VUI colour tags, sticky across pictures.
57+ colour_tags: Tags,
5558 }
5659
5760 impl H264Decoder {
@@ -68,6 +71,7 @@ impl H264Decoder {
6871 current: None,
6972 rbsp: Vec::new(),
7073 gap_frames: 0,
74+ colour_tags: Tags::default(),
7175 }
7276 }
7377
@@ -86,6 +90,7 @@ impl H264Decoder {
8690 self.rbsp = rbsp;
8791 let sps = sps?;
8892 self.dpb.configure(&sps);
93+ self.colour_tags = vui_colour_tags(&sps);
8994 let id = usize::from(sps.id);
9095 self.sps_map[id] = Some(sps);
9196 }
@@ -395,11 +400,45 @@ impl H264Decoder {
395400 session.display_size,
396401 session.coded_size,
397402 session.bit_depth,
403+ self.colour(),
398404 );
399405 self.ready.push(frame);
400406 self.dpb.released(idx);
401407 }
402408 }
409+
410+ /// This stream's colour metadata, once its first SPS has been seen. No SEI
411+ /// here — H.264's mastering-display/content-light-level SEI is not parsed
412+ /// by this family today, so this is VUI-only.
413+ pub fn colour(&self) -> Option<Colour> {
414+ let session = self.session.as_ref()?;
415+ Some(Colour {
416+ description: ColorDescription::resolve(
417+ Tags::default(),
418+ self.colour_tags,
419+ session.display_size.1,
420+ ),
421+ light: ContentLight::default(),
422+ })
423+ }
424+}
425+
426+/// An SPS's VUI `colour_description` and range flag, as [`Tags`] for
427+/// [`ColorDescription::resolve`]. [`Tags::default()`] when the VUI has no
428+/// `video_signal_type` at all.
429+fn vui_colour_tags(sps: &Sps) -> Tags {
430+ let Some(vui) = &sps.vui else {
431+ return Tags::default();
432+ };
433+ if vui.video_format.is_none() {
434+ return Tags::default();
435+ }
436+ let (_primaries, transfer, matrix) = vui.colour_description.unwrap_or((0, 0, 0));
437+ Tags::from_codes(
438+ u64::from(matrix),
439+ u64::from(transfer),
440+ if vui.video_full_range { 2 } else { 1 },
441+ )
403442 }
404443
405444 /// The `pic_parameter_set_id` of a slice header, which is the second syntax
crates/ec-hw/src/dec/hevc.rsmodified+59 -3
@@ -9,6 +9,7 @@
99
1010 use std::sync::Arc;
1111
12+use ec_core::color::{ColorDescription, ContentLight, Tags};
1213 use ec_h265_syntax::{
1314 NalUnitType, ParsePositions, Pps, SliceHeader, SliceType, Sps, Vps, split_annex_b,
1415 unescape_rbsp,
@@ -18,7 +19,7 @@ use ec_va::{Buffer, Display, sys};
1819
1920 use super::{ReadyFrames, Session, StreamInfo};
2021 use crate::error::{Error, Result};
21-use crate::frame::Frame;
22+use crate::frame::{Colour, Frame};
2223 use crate::params::hevc::{
2324 IQMatrixBufferHEVC, PICTURE_INVALID, PICTURE_LONG_TERM_REFERENCE, PICTURE_RPS_LT_CURR,
2425 PICTURE_RPS_ST_CURR_AFTER, PICTURE_RPS_ST_CURR_BEFORE, PictureParameterBufferHEVC,
@@ -100,6 +101,11 @@ pub struct HevcDecoder {
100101 no_rasl_output: bool,
101102 max_reorder: usize,
102103 max_dec_pic_buffering: usize,
104+ /// The most recent SPS's VUI colour tags, sticky across pictures.
105+ colour_tags: Tags,
106+ /// The prefix SEI HDR peak seen so far, merged so a later access unit that
107+ /// says nothing does not erase what an earlier IRAP declared.
108+ colour_light: ContentLight,
103109 }
104110
105111 impl HevcDecoder {
@@ -119,6 +125,8 @@ impl HevcDecoder {
119125 no_rasl_output: false,
120126 max_reorder: 1,
121127 max_dec_pic_buffering: 6,
128+ colour_tags: Tags::default(),
129+ colour_light: ContentLight::default(),
122130 }
123131 }
124132
@@ -137,6 +145,7 @@ impl HevcDecoder {
137145 let sps = Sps::parse(&nal.rbsp())?;
138146 self.max_reorder = sps.max_num_reorder_pics as usize;
139147 self.max_dec_pic_buffering = sps.max_dec_pic_buffering_minus1 as usize + 1;
148+ self.colour_tags = vui_colour_tags(&sps);
140149 let id = sps.id as usize;
141150 if id < self.sps_map.len() {
142151 self.sps_map[id] = Some(sps);
@@ -155,10 +164,33 @@ impl HevcDecoder {
155164 _ => {}
156165 }
157166 }
167+ // The HDR SEI messages (mastering display, content light level) live
168+ // outside the slice loop above and are read on the whole access unit:
169+ // an encoder writes them once, ahead of the IRAP they describe, and
170+ // they otherwise say nothing (`ContentLight::default()`), so a later
171+ // access unit that carries neither never overwrites what an earlier
172+ // one declared.
173+ let light = ec_core::color::hevc_sei_light(data);
174+ if light != ContentLight::default() {
175+ self.colour_light = light.over(self.colour_light);
176+ }
158177 self.finish_picture()?;
159178 Ok(())
160179 }
161180
181+ /// This stream's colour metadata, once its first SPS has been seen.
182+ pub fn colour(&self) -> Option<Colour> {
183+ let session = self.session.as_ref()?;
184+ Some(Colour {
185+ description: ColorDescription::resolve(
186+ Tags::default(),
187+ self.colour_tags,
188+ session.display_size.1,
189+ ),
190+ light: self.colour_light,
191+ })
192+ }
193+
162194 /// The next frame in output order.
163195 pub fn next_frame(&mut self) -> Option<Frame> {
164196 self.ready.pop()
@@ -274,8 +306,7 @@ impl HevcDecoder {
274306 // 8.1.3: 1 for an IDR, a BLA, or the first picture of a coded
275307 // video sequence — which a mid-stream start's first IRAP always
276308 // is, `self.started` still being false at that point.
277- self.no_rasl_output =
278- nal_type.is_idr() || is_bla_picture(nal_type) || !self.started;
309+ self.no_rasl_output = nal_type.is_idr() || is_bla_picture(nal_type) || !self.started;
279310 }
280311
281312 let poc = self.picture_order_count(sps, sh, nal_type);
@@ -638,6 +669,7 @@ impl HevcDecoder {
638669 session.display_size,
639670 session.coded_size,
640671 session.bit_depth,
672+ self.colour(),
641673 ));
642674 self.dpb[idx].output = false;
643675 self.dpb.retain(|p| p.stored());
@@ -658,6 +690,30 @@ fn is_leading_picture(nal_type: NalUnitType) -> bool {
658690 (6..=9).contains(&nal_type.code())
659691 }
660692
693+/// An SPS's VUI `colour_description` and range flag, as [`Tags`] for
694+/// [`ColorDescription::resolve`]. [`Tags::default()`] when the VUI has no
695+/// `video_signal_type` at all.
696+fn vui_colour_tags(sps: &Sps) -> Tags {
697+ let Some(vst) = sps.vui.as_ref().and_then(|vui| vui.video_signal_type) else {
698+ return Tags::default();
699+ };
700+ let (_primaries, transfer, matrix) = vst
701+ .colour_description
702+ .map(|cd| {
703+ (
704+ cd.colour_primaries,
705+ cd.transfer_characteristics,
706+ cd.matrix_coeffs,
707+ )
708+ })
709+ .unwrap_or((0, 0, 0));
710+ Tags::from_codes(
711+ u64::from(matrix),
712+ u64::from(transfer),
713+ if vst.video_full_range_flag { 2 } else { 1 },
714+ )
715+}
716+
661717 /// RASL_N and RASL_R (8, 9): leading pictures dropped whole when their IRAP's
662718 /// `NoRaslOutputFlag` is 1 (8.1.3).
663719 fn is_rasl_picture(nal_type: NalUnitType) -> bool {
crates/ec-hw/src/dec/mod.rsmodified+11 -0
@@ -154,6 +154,17 @@ impl Decoder {
154154 Inner::Av1(d) => d.stream_info(),
155155 }
156156 }
157+
158+ /// This stream's colour metadata, once a session exists. [`None`] for VP9
159+ /// and AV1: neither's sequence header colour config is parsed by this
160+ /// family yet.
161+ pub fn colour(&self) -> Option<crate::frame::Colour> {
162+ match &self.inner {
163+ Inner::H264(d) => d.colour(),
164+ Inner::H265(d) => d.colour(),
165+ Inner::Vp9(_) | Inner::Av1(_) => None,
166+ }
167+ }
157168 }
158169
159170 /// Frames waiting to be collected, oldest first.
crates/ec-hw/src/dec/vp9.rsmodified+2 -0
@@ -98,6 +98,7 @@ impl Vp9Decoder {
9898 (header.width, header.height),
9999 session.coded_size,
100100 session.bit_depth,
101+ None,
101102 ));
102103 return Ok(());
103104 }
@@ -137,6 +138,7 @@ impl Vp9Decoder {
137138 (header.width, header.height),
138139 session.coded_size,
139140 session.bit_depth,
141+ None,
140142 ));
141143 }
142144 Ok(())
crates/ec-hw/src/enc/mod.rsmodified+7 -1
@@ -138,7 +138,13 @@ impl EncoderConfig {
138138 }
139139
140140 /// Set the VUI colour description; H.265 E.2.1 / H.264 E.1.1 code points.
141- pub fn colour(mut self, primaries: u8, transfer: u8, matrix: u8, full_range: bool) -> EncoderConfig {
141+ pub fn colour(
142+ mut self,
143+ primaries: u8,
144+ transfer: u8,
145+ matrix: u8,
146+ full_range: bool,
147+ ) -> EncoderConfig {
142148 self.colour = Some(Colour {
143149 primaries,
144150 transfer,
crates/ec-hw/src/frame.rsmodified+24 -0
@@ -3,12 +3,27 @@
33
44 use std::sync::{Arc, Mutex};
55
6+use ec_core::color::{ColorDescription, ContentLight};
67 use ec_va::sys::{VA_FOURCC_NV12, VA_FOURCC_P010};
78 use ec_va::{Image, MappedImage, PrimeSurface, Surface};
89
910 use crate::error::{Error, Result};
1011 use crate::pool::PooledSurface;
1112
13+/// A stream's colour metadata, resolved from its own headers: VUI tags for the
14+/// primaries/transfer/matrix triplet, and — for HEVC — the two HDR prefix SEI
15+/// messages for the peak the mastering grade and the content itself declared.
16+/// No container tier here: ec-hw only ever sees the elementary stream, so a
17+/// caller that also holds the container's tags resolves those over this.
18+#[derive(Debug, Clone, Copy, PartialEq)]
19+pub struct Colour {
20+ /// Matrix/transfer/range, resolved from the bitstream's own VUI.
21+ pub description: ColorDescription,
22+ /// HDR peak: MaxCLL/MaxFALL and the mastering display's luminance, when
23+ /// the stream carried them (HEVC prefix SEI only).
24+ pub light: ContentLight,
25+}
26+
1227 /// The readback image a decoder reuses across frames.
1328 ///
1429 /// One `vaCreateImage`/`vaDestroyImage` pair per frame costs ~20 ms at 1080p on
@@ -33,6 +48,8 @@ pub struct Frame {
3348 pub coded_size: (u32, u32),
3449 /// Luma bit depth: 8 for NV12 surfaces, 10 for P010.
3550 pub bit_depth: u8,
51+ /// This stream's colour metadata, when the codec's decoder resolves one.
52+ pub colour: Option<Colour>,
3653 }
3754
3855 /// 8-bit planar 4:2:0, the currency edith's software path speaks.
@@ -73,6 +90,7 @@ impl Frame {
7390 display_size: (u32, u32),
7491 coded_size: (u32, u32),
7592 bit_depth: u8,
93+ colour: Option<Colour>,
7694 ) -> Frame {
7795 Frame {
7896 surface,
@@ -81,6 +99,7 @@ impl Frame {
8199 display_size,
82100 coded_size,
83101 bit_depth,
102+ colour,
84103 }
85104 }
86105
@@ -89,6 +108,11 @@ impl Frame {
89108 &self.surface
90109 }
91110
111+ /// This frame's colour metadata, when the codec's decoder resolves one.
112+ pub fn colour(&self) -> Option<Colour> {
113+ self.colour
114+ }
115+
92116 /// Export the surface as DRM PRIME file descriptors.
93117 ///
94118 /// This is the path edith's `engine-hw` takes: the fds are imported into
crates/ec-hw/src/lib.rsmodified+1 -1
@@ -56,5 +56,5 @@ pub use enc::{
5656 CodedFrame, EncCodec, Encoder, EncoderConfig, FrameMetadata, RateControlMode, Tunings,
5757 };
5858 pub use error::{Error, Result};
59-pub use frame::{Frame, I420, I420_16, i420_to_nv12, nv12_to_i420};
59+pub use frame::{Colour, Frame, I420, I420_16, i420_to_nv12, nv12_to_i420};
6060 pub use pool::{PooledSurface, SurfacePool};
crates/ec-hw/tests/gpu.rsmodified+124 -12
@@ -72,7 +72,15 @@ impl Reference {
7272 // pictures on a film whose real cadence differs — which shows up
7373 // here as everything being one frame out from some point onward.
7474 .args([
75- "-map", "0:v:0", "-fps_mode", "passthrough", "-pix_fmt", pix, "-f", "rawvideo", "-",
75+ "-map",
76+ "0:v:0",
77+ "-fps_mode",
78+ "passthrough",
79+ "-pix_fmt",
80+ pix,
81+ "-f",
82+ "rawvideo",
83+ "-",
7684 ])
7785 .stdout(Stdio::piped())
7886 .stderr(Stdio::null())
@@ -708,7 +716,10 @@ fn encode_frame_zero_copy_matches_the_cpu_path() {
708716 count += 1;
709717 })
710718 .expect("decode");
711- assert_eq!(count as usize, frames, "{target:?}: decoded {count} of {frames}");
719+ assert_eq!(
720+ count as usize, frames,
721+ "{target:?}: decoded {count} of {frames}"
722+ );
712723
713724 let ext = match target {
714725 EncCodec::H264 => "264",
@@ -733,8 +744,16 @@ fn encode_frame_zero_copy_matches_the_cpu_path() {
733744 cpu_frames.push(Planes::from_8bit(&f.to_i420().expect("readback")))
734745 })
735746 .expect("decode CPU-path stream");
736- assert_eq!(zc_frames.len(), frames, "{target:?}: zero-copy stream frame count");
737- assert_eq!(cpu_frames.len(), frames, "{target:?}: CPU-path stream frame count");
747+ assert_eq!(
748+ zc_frames.len(),
749+ frames,
750+ "{target:?}: zero-copy stream frame count"
751+ );
752+ assert_eq!(
753+ cpu_frames.len(),
754+ frames,
755+ "{target:?}: CPU-path stream frame count"
756+ );
738757
739758 let worst = zc_frames
740759 .iter()
@@ -742,7 +761,10 @@ fn encode_frame_zero_copy_matches_the_cpu_path() {
742761 .map(|(a, b)| psnr(a, b))
743762 .fold(f64::INFINITY, f64::min);
744763 println!("{target:?} encode_frame vs CPU path: worst {worst:.1} dB");
745- assert!(worst >= 35.0, "{target:?}: worst {worst:.1} dB vs the CPU path");
764+ assert!(
765+ worst >= 35.0,
766+ "{target:?}: worst {worst:.1} dB vs the CPU path"
767+ );
746768 }
747769 }
748770
@@ -815,7 +837,10 @@ fn colour_description_reaches_the_vui() {
815837 // ffprobe's csv reorders these as color_space,color_transfer,color_primaries
816838 // regardless of the -show_entries order given above.
817839 let got = probe(&bt2020_path);
818- assert_eq!(got, "bt2020nc,smpte2084,bt2020", "ffprobe on the BT.2020 stream");
840+ assert_eq!(
841+ got, "bt2020nc,smpte2084,bt2020",
842+ "ffprobe on the BT.2020 stream"
843+ );
819844 }
820845
821846 /// AV1 encoding is opt-in, and this test does not turn it on.
@@ -1244,7 +1269,8 @@ fn ten_bit_4k_chroma_is_not_grey() {
12441269 let mut compared = 0usize;
12451270 decode_stream(&mut decoder, Codec::H265, &data, frames, |frame| {
12461271 let (w, h) = frame.display_size;
1247- let ref10 = ref10.get_or_insert_with(|| Reference::open(path, w, h, true).expect("ffmpeg runs"));
1272+ let ref10 =
1273+ ref10.get_or_insert_with(|| Reference::open(path, w, h, true).expect("ffmpeg runs"));
12481274 let want10 = ref10.next(w, h).expect("ffmpeg has a frame");
12491275 let got16 = Planes::from_16bit(&frame.to_i420_16().expect("readback"));
12501276 let y_db = plane_psnr(&got16.y, &want10.y, 1023.0);
@@ -1254,13 +1280,17 @@ fn ten_bit_4k_chroma_is_not_grey() {
12541280 1023.0,
12551281 );
12561282 println!("frame {compared} to_i420_16 vs yuv420p10le: Y {y_db:.1} dB, UV {uv_db:.1} dB");
1257- assert!(y_db >= 50.0, "frame {compared}: Y PSNR collapsed to {y_db:.1} dB");
1283+ assert!(
1284+ y_db >= 50.0,
1285+ "frame {compared}: Y PSNR collapsed to {y_db:.1} dB"
1286+ );
12581287 assert!(
12591288 uv_db >= 50.0,
12601289 "frame {compared}: chroma PSNR collapsed to {uv_db:.1} dB (grey frame)"
12611290 );
12621291
1263- let ref8 = ref8.get_or_insert_with(|| Reference::open(path, w, h, false).expect("ffmpeg runs"));
1292+ let ref8 =
1293+ ref8.get_or_insert_with(|| Reference::open(path, w, h, false).expect("ffmpeg runs"));
12641294 let want8 = ref8.next(w, h).expect("ffmpeg has a frame");
12651295 let got8 = Planes::from_8bit(&frame.to_i420().expect("readback"));
12661296 let y_db8 = plane_psnr(&got8.y, &want8.y, 255.0);
@@ -1273,7 +1303,10 @@ fn ten_bit_4k_chroma_is_not_grey() {
12731303 // ffmpeg dithers its 8-bit downconversion; this crate truncates. Both
12741304 // are legitimate 10-to-8 roundings, so the floor here is the
12751305 // dithering noise floor, not the lossless bound above.
1276- assert!(y_db8 >= 30.0, "frame {compared}: 8-bit Y PSNR {y_db8:.1} dB");
1306+ assert!(
1307+ y_db8 >= 30.0,
1308+ "frame {compared}: 8-bit Y PSNR {y_db8:.1} dB"
1309+ );
12771310 assert!(
12781311 uv_db8 >= 30.0,
12791312 "frame {compared}: 8-bit chroma PSNR collapsed to {uv_db8:.1} dB (grey frame)"
@@ -1284,6 +1317,80 @@ fn ten_bit_4k_chroma_is_not_grey() {
12841317 assert_eq!(compared, frames, "not all frames were compared");
12851318 }
12861319
1320+/// The HEVC HDR peak (`content_light_level_information` and
1321+/// `mastering_display_colour_volume` prefix SEI), on the one real file that
1322+/// only carries it there: the Matroska `Colour` element itself has no MaxCLL/
1323+/// MaxFALL for this rip (verified separately against `ffprobe`), so a decoder
1324+/// that does not read the SEI reports none at all. Numbers match what
1325+/// `ffprobe -show_frames -read_intervals %+#1 -show_entries
1326+/// frame_side_data_list` reports for this file.
1327+#[test]
1328+fn hdr_film_light_level_sei_is_exposed() {
1329+ let Some(display) = display() else { return };
1330+ let path = Path::new(
1331+ "/home/user/Downloads/reeld\
1332+ /reeld.mkv",
1333+ );
1334+ if !path.exists() {
1335+ eprintln!("skipped: film not present");
1336+ return;
1337+ }
1338+ let frames = 2usize;
1339+ let Some(data) = elementary(path, Codec::H265, frames) else {
1340+ eprintln!("skipped: no elementary stream");
1341+ return;
1342+ };
1343+ let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
1344+ let mut seen = 0usize;
1345+ decode_stream(&mut decoder, Codec::H265, &data, frames, |frame| {
1346+ seen += 1;
1347+ let colour = frame
1348+ .colour()
1349+ .expect("HEVC decoder resolves colour metadata");
1350+ assert_eq!(
1351+ colour.description.codes(),
1352+ (9, 16, 9),
1353+ "primaries/transfer/matrix (BT.2020 / PQ / BT.2020 NCL)"
1354+ );
1355+ assert_eq!(colour.light.max_cll, Some(1230.0), "MaxCLL");
1356+ assert_eq!(colour.light.max_fall, Some(419.0), "MaxFALL");
1357+ assert!(
1358+ colour.light.mastering_max.is_some(),
1359+ "mastering display peak missing"
1360+ );
1361+ })
1362+ .expect("decode");
1363+ assert_eq!(seen, frames, "not all frames were compared");
1364+}
1365+
1366+/// An SDR H.264 stream, which carries no HDR SEI at all: `Frame::colour`
1367+/// either resolves from the VUI or answers [`None`], but never panics.
1368+#[test]
1369+fn sdr_h264_colour_never_panics() {
1370+ let Some(display) = display() else { return };
1371+ let paths = fixtures(".264");
1372+ if paths.is_empty() {
1373+ eprintln!("skipped: no H.264 fixtures generated");
1374+ return;
1375+ }
1376+ let path = &paths[0];
1377+ let Some(data) = std::fs::read(path).ok() else {
1378+ eprintln!("skipped: fixture unreadable");
1379+ return;
1380+ };
1381+ let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
1382+ let mut seen = 0usize;
1383+ decode_stream(&mut decoder, Codec::H264, &data, 2, |frame| {
1384+ seen += 1;
1385+ // No SEI parsing on this codec: content light is always absent.
1386+ if let Some(colour) = frame.colour() {
1387+ assert_eq!(colour.light.max_cll, None);
1388+ }
1389+ })
1390+ .expect("decode");
1391+ assert!(seen > 0, "{}: nothing decoded", short(path));
1392+}
1393+
12871394 /// Per-frame cost of the 4K 10-bit read-back path, isolated from decode
12881395 /// submission itself.
12891396 ///
@@ -1309,7 +1416,10 @@ fn ten_bit_4k_frame_path_is_realtime() {
13091416 return;
13101417 };
13111418 let units = split_access_units(&data, Codec::H265);
1312- assert!(units.len() > limit, "film clip too short for {limit} frames");
1419+ assert!(
1420+ units.len() > limit,
1421+ "film clip too short for {limit} frames"
1422+ );
13131423
13141424 #[derive(Clone, Copy)]
13151425 enum Op {
@@ -1444,7 +1554,9 @@ fn hevc_seek_matches_linear_mkv() {
14441554 // caller to: decode the leading VPS/SPS/PPS (their IDR picture is thrown
14451555 // away) and reset picture state before feeding the seek target.
14461556 let mut seek_decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
1447- seek_decoder.decode(units[0], 0).expect("prime parameter sets");
1557+ seek_decoder
1558+ .decode(units[0], 0)
1559+ .expect("prime parameter sets");
14481560 seek_decoder.reset();
14491561 let mut seeked_frame = None;
14501562 for (i, unit) in units[cra_at..].iter().enumerate() {