forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

hw_decode.rs586 lines, 23.0 KiBHistoryRawDownload
1//! Hardware path checks. These need a built `libengine_hw.so` plus a working
2//! VA-API driver, so they are `#[ignore]`d by default. Run them with:
3//!
4//! ```text
5//! cargo build --workspace --release
6//! LD_LIBRARY_PATH=target/release \
7//! cargo test -p engine --release --test hw_decode -- --ignored --nocapture --test-threads=1
8//! ```
9//!
10//! The comparison test pins [`DecodeSession`] to the software decoder itself
11//! (it sets `VE_SW=1` in-process, hence the required `--test-threads=1`); the
12//! hardware side goes through [`HwSession`] directly and can never silently be
13//! a fallback.
14
15#[path = "support/hwchild.rs"]
16mod hwchild;
17
18use std::path::{Path, PathBuf};
19use std::time::Instant;
20
21use engine::DecodeSession;
22use engine::colorspace::{ColorDescription, Matrix};
23use engine::convert::i420_to_bgra;
24use engine::demux::{Codec, Demuxer};
25use engine::mux::{self, Mp4Muxer, VideoParams};
26use engine::scratch::Scratch;
27use engine::hw::HwSession;
28use engine::tonemap::{ToneMapper, Transfer};
29
30fn asset(name: &str) -> PathBuf {
31 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
32 .join("../../assets")
33 .join(name)
34}
35
36/// What the decode funnel converts this file's planes in, so a conversion done
37/// by hand here is the one `DecodeSession` would have done.
38fn color_of(path: &Path) -> ColorDescription {
39 Demuxer::open(path).expect("open for colour").0.color
40}
41
42fn open_hw(path: &Path) -> HwSession {
43 HwSession::open(path).expect("no hardware decode plugin/driver available")
44}
45
46/// Decodes the whole file through the plugin, returning (frame count, frame 30 as BGRA).
47fn decode_all_hw(name: &str) -> (usize, Vec<u8>) {
48 let path = asset(name);
49 let color = color_of(&path);
50 let mut hw = open_hw(&path);
51 let meta = hw.meta().expect("meta");
52 assert_eq!(
53 (meta.width, meta.height),
54 (1280, 720),
55 "{name} container dims"
56 );
57
58 let mut count = 0usize;
59 let mut frame_30 = Vec::new();
60 let start = Instant::now();
61 while let Some((y, u, v, w, h)) = hw.next_frame().expect("hardware decode") {
62 assert_eq!((w, h), (1280, 720), "{name} frame {count} dims");
63 if count == 30 {
64 frame_30 = i420_to_bgra(&color, y, u, v, w as usize, h as usize);
65 }
66 count += 1;
67 }
68 eprintln!(
69 "{name}: {count} hardware frames in {:?} ({:?}/frame)",
70 start.elapsed(),
71 start.elapsed() / count.max(1) as u32
72 );
73 (count, frame_30)
74}
75
76/// The plugin must refuse junk by returning null, never by unwinding into us.
77#[test]
78#[ignore = "needs libengine_hw.so and a VA-API driver"]
79fn rejects_unopenable_files() {
80 hwchild::require();
81 assert!(HwSession::open(Path::new("/definitely/not/here.mp4")).is_none());
82 assert!(
83 HwSession::open(Path::new("/etc/hostname")).is_none(),
84 "not an mp4"
85 );
86}
87
88/// 24 frames cut from a 2160p HDR remux that used to give a black picture and
89/// an instant `eof`: at 3840x2160 with CTB 64 the picture is 34 CTB rows, so
90/// wavefront slices carry `num_entry_point_offsets == 33` (§7.4.7.1 allows up
91/// to PicHeightInCtbsY - 1) and the vendored parser indexed a `[u32; 32]` with
92/// 32. Conformant stream, panicking parser -- caught at the plugin edge, which
93/// is exactly why it reached the user as a silent eof.
94#[test]
95#[ignore = "needs libengine_hw.so and a VA-API driver"]
96fn hardware_decodes_4k_wavefront_slices() {
97 hwchild::require();
98 let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/test_hevc_4k_wpp.mkv");
99 let mut hw = open_hw(&path);
100 let mut count = 0usize;
101 while let Some((_, _, _, w, h)) = hw.next_frame().expect("hardware decode") {
102 assert_eq!((w, h), (3840, 2160), "frame {count} dims");
103 count += 1;
104 }
105 assert!(count > 0, "4K wavefront stream decoded no pictures");
106}
107
108/// ...and the same file with its slice bytes scrambled -- a stream the plugin
109/// opens and then cannot decode a picture out of -- is refused at the door, in
110/// words that do not send the user installing a plugin they already have. The
111/// case this whole bug arrived as: never a black picture and a silent `eof`.
112#[test]
113#[ignore = "needs libengine_hw.so and a VA-API driver"]
114fn an_undecodable_hevc_stream_is_refused_by_name() {
115 hwchild::require();
116 let good = std::fs::read(
117 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/test_hevc_4k_wpp.mkv"),
118 )
119 .expect("read the 4K fixture");
120 // Every SPS in it (`nal_unit_type` 33, so the two header bytes are 42 01)
121 // gets `sps_max_sub_layers_minus1 = 7`, which §7.4.3.2.1 does not allow and
122 // the parser now refuses instead of indexing a 7-long array with 7.
123 let mut broken = good.clone();
124 let mut patched = 0;
125 for i in 0..broken.len() - 2 {
126 if broken[i] == 0x42 && broken[i + 1] == 0x01 {
127 broken[i + 2] |= 0x0e;
128 patched += 1;
129 }
130 }
131 assert!(patched > 0, "no SPS found in the fixture");
132 let path = Scratch::file("undecodable_hevc", "mkv");
133 std::fs::write(&path, &broken).expect("write the broken copy");
134
135 let refused = DecodeSession::open(&path)
136 .expect_err("a stream with no decodable picture must not open")
137 .to_string();
138 assert_eq!(refused, Codec::Hevc.undecodable());
139}
140
141#[test]
142#[ignore = "needs libengine_hw.so and a VA-API driver"]
143fn hardware_decodes_baseline() {
144 hwchild::require();
145 let (count, _) = decode_all_hw("test_baseline.mp4");
146 assert_eq!(count, 150);
147}
148
149#[test]
150#[ignore = "needs libengine_hw.so and a VA-API driver"]
151fn hardware_decodes_high_profile() {
152 hwchild::require();
153 // B-frames: the plugin emits display order (DPB bumping happens inside
154 // cros-codecs), so a clean run to EOF is the check we can make headlessly.
155 let (count, _) = decode_all_hw("test_high.mp4");
156 assert_eq!(count, 150);
157}
158
159/// Seeking may only change *when* a picture arrives, never the picture: both
160/// backends must land on bytes identical to a linear decode of the same index.
161#[test]
162#[ignore = "needs libengine_hw.so and a VA-API driver"]
163fn seek_matches_linear() {
164 hwchild::require();
165 const TARGET: u32 = 60;
166 let path = asset("test_baseline.mp4");
167
168 engine::envcfg::set("VE_SW", "1");
169 let (_, rx) = DecodeSession::open(&path).expect("software open");
170 let linear = rx
171 .into_iter()
172 .find(|f| f.index == TARGET)
173 .expect("software frame 60")
174 .bgra;
175
176 let start = Instant::now();
177 let (_, rx, _cancel) = DecodeSession::open_at(&path, TARGET).expect("software open_at");
178 let seeked = rx.into_iter().next().expect("no frame after software seek");
179 eprintln!("software seek to {TARGET} took {:?}", start.elapsed());
180 assert_eq!(seeked.index, TARGET, "first frame after seek is the target");
181 assert_eq!(seeked.bgra, linear, "software seek != software linear");
182
183 let start = Instant::now();
184 let mut hw = HwSession::open_at(&path, TARGET).expect("no plugin/driver available");
185 let (y, u, v, w, h) = hw
186 .next_frame()
187 .expect("hardware decode")
188 .expect("no frame after hardware seek");
189 eprintln!("hardware seek to {TARGET} took {:?}", start.elapsed());
190 assert_eq!(
191 i420_to_bgra(&color_of(&path), y, u, v, w as usize, h as usize),
192 linear,
193 "hardware seek != software linear"
194 );
195}
196
197/// The same promise as [`seek_matches_linear`], made of every container and
198/// codec pair there is a fixture for and at targets on, either side of and away
199/// from a keyframe -- because which of them holds is a property of the *stream's
200/// structure*, not of the seek code alone.
201///
202/// An open-GOP HEVC stream (x265's default, so `test_hevc.mkv` and its 10-bit
203/// twin, and every film off a disc or a web rip) stores the CRA that opens a GOP
204/// *ahead of* the RASL leading pictures that are shown *before* it: keyframe 30
205/// on screen is the 28th block in the file. A seek that counts stored positions
206/// rather than displayed pictures therefore hands back a picture two frames
207/// later than the index it labels, and by a different amount in a GOP with
208/// another number of leading pictures. `test_baseline.mp4` alone never showed
209/// it: it has exactly one keyframe, at frame 0, where the two orders agree.
210#[test]
211#[ignore = "needs libengine_hw.so and a VA-API driver"]
212fn seek_matches_linear_every_container() {
213 hwchild::require();
214 engine::envcfg::unset("VE_SW");
215 for name in [
216 "test_baseline.mp4",
217 "test_high.mp4",
218 "test_hevc.mp4",
219 "test_hevc.mkv",
220 "test_hevc10.mkv",
221 "test_h264.mkv",
222 "test_av1.mkv",
223 ] {
224 let path = asset(name);
225 let (meta, rx) = DecodeSession::open(&path).unwrap_or_else(|e| panic!("{name}: open: {e}"));
226 // On a keyframe, either side of one, well inside a GOP, the first
227 // picture and the last -- deduplicated for a fixture short enough that
228 // some of those coincide.
229 let mut targets = vec![0, 1, 29, 30, 31, 45, meta.frame_count - 1];
230 targets.retain(|&t| t < meta.frame_count);
231 targets.sort_unstable();
232 targets.dedup();
233 let linear: Vec<(u32, Vec<u8>)> = rx
234 .into_iter()
235 .filter(|f| targets.contains(&f.index))
236 .map(|f| (f.index, f.bgra))
237 .collect();
238 assert_eq!(
239 linear.iter().map(|(i, _)| *i).collect::<Vec<_>>(),
240 targets,
241 "{name}: linear decode never delivered every target"
242 );
243 for (target, want) in linear {
244 let (_, rx, _cancel) = DecodeSession::open_at(&path, target)
245 .unwrap_or_else(|e| panic!("{name}: open_at({target}): {e}"));
246 let seeked = rx
247 .into_iter()
248 .next()
249 .unwrap_or_else(|| panic!("{name}: no frame after seek to {target}"));
250 assert_eq!(
251 seeked.index, target,
252 "{name}: first frame after seek is not the target"
253 );
254 assert!(
255 seeked.bgra == want,
256 "{name}: seek to {target} handed back a different picture than a linear decode of {target}"
257 );
258 }
259 }
260}
261
262/// Drains a bounded session, returning the indices it delivered. The loop ends
263/// only on `RecvError`, i.e. the worker closed the channel by itself.
264fn range_indices(path: &Path, start: u32, end: u32) -> Vec<u32> {
265 let (_, rx, _cancel) = DecodeSession::open_range(path, start, end).expect("open_range");
266 let mut got = Vec::new();
267 while let Ok(frame) = rx.recv() {
268 got.push(frame.index);
269 }
270 got
271}
272
273/// A bounded range must stop on its own — both backends — with `Frame::index`
274/// still the absolute source index, and then disconnect rather than hang.
275#[test]
276#[ignore = "needs libengine_hw.so and a VA-API driver"]
277fn range_stops_at_end() {
278 hwchild::require();
279 const START: u32 = 30;
280 const END: u32 = 60;
281 let path = asset("test_baseline.mp4");
282 let want: Vec<u32> = (START..END).collect();
283
284 engine::envcfg::unset("VE_SW");
285 assert_eq!(range_indices(&path, START, END), want, "hardware range");
286
287 engine::envcfg::set("VE_SW", "1");
288 assert_eq!(range_indices(&path, START, END), want, "software range");
289
290 // Degenerate ranges close cleanly instead of decoding to EOF.
291 assert!(range_indices(&path, 30, 30).is_empty(), "empty range");
292 assert!(range_indices(&path, 60, 30).is_empty(), "inverted range");
293 // Past the end is clamped to the frame count.
294 assert_eq!(range_indices(&path, 148, 999).len(), 2, "clamped range");
295}
296
297/// The real thing: a 4K HDR10 film through the funnel, against the picture the
298/// same planes gave before the tone map was in it (BT.2020 matrix, HDR codes
299/// shown as if they were SDR -- flat and grey-washed, which is the complaint
300/// this whole path answers). Colour has to come *up*, not down, and the picture
301/// has to land somewhere a display can show rather than at either rail.
302///
303/// Gated on the film being here: it is a 20 GB download, not a fixture. HEVC
304/// Main 10, so this is a hardware-only test in every sense.
305#[test]
306#[ignore = "needs libengine_hw.so, a VA-API driver and the film"]
307fn the_hdr_film_renders_tone_mapped() {
308 hwchild::require();
309 // Two minutes in: past the studio logos, inside lit footage.
310 const TARGET: u32 = 3000;
311 let Some(path) = engine::real_library::film("hevc_4k_hdr") else {
312 return;
313 };
314 let path = path.as_path();
315 engine::envcfg::unset("VE_SW");
316
317 // The old picture, by hand off the plugin's own planes: the funnel did
318 // exactly this before the tone map, and it is what the comparison needs.
319 let mut hw = HwSession::open_at(path, TARGET).expect("no plugin/driver available");
320 let (y, u, v, w, h) = hw
321 .next_frame()
322 .expect("hardware decode")
323 .expect("no frame at the seek");
324 let (w, h) = (w as usize, h as usize);
325 let (y, u, v) = (y.to_vec(), u.to_vec(), v.to_vec());
326 let untouched = i420_to_bgra(&color_of(path), &y, &u, &v, w, h);
327
328 // ...and the picture the engine shows now, through the funnel itself.
329 let (_, rx, _cancel) = DecodeSession::open_at(path, TARGET).expect("open the film");
330 let shown = rx.recv().expect("a frame off the funnel").bgra;
331 assert_eq!(shown.len(), untouched.len(), "frame size");
332
333 // Saturation, as the mean distance from grey per pixel...
334 let spread = |bgra: &[u8]| -> f64 {
335 let total: u64 = bgra
336 .as_chunks::<4>().0.iter()
337 .map(|px| u64::from(px[..3].iter().max().unwrap() - px[..3].iter().min().unwrap()))
338 .sum();
339 total as f64 / (bgra.len() / 4) as f64
340 };
341 // ...and mean luma, in the limited-range code the tone map's anchors are in.
342 let luma = |bgra: &[u8]| -> f64 {
343 let total: f64 = bgra
344 .as_chunks::<4>().0.iter()
345 .map(|px| {
346 0.2126 * f64::from(px[2]) + 0.7152 * f64::from(px[1]) + 0.0722 * f64::from(px[0])
347 })
348 .sum();
349 16.0 + 219.0 * (total / (bgra.len() / 4) as f64) / 255.0
350 };
351 let (was, now) = (spread(&untouched), spread(&shown));
352 eprintln!(
353 "frame {TARGET}: saturation {was:.1} -> {now:.1}, mean luma {:.1} -> {:.1}",
354 luma(&untouched),
355 luma(&shown)
356 );
357 assert!(
358 now > was,
359 "the tone-mapped frame is no more colourful: {now}"
360 );
361 let mean = luma(&shown);
362 assert!(
363 (24.0..=200.0).contains(&mean),
364 "the tone-mapped frame sits at one end of the scale: mean luma {mean}"
365 );
366
367 // The funnel's own budget at this size: the map plus the conversion, which
368 // is what an HDR frame costs on top of the decode. Fastest of five, for the
369 // reason `tonemap::perf_4k_and_1080p` documents.
370 let mapper = ToneMapper::new(Transfer::Pq, engine::tonemap::Preset::default(), None);
371 let sdr = ColorDescription {
372 matrix: Matrix::Bt709,
373 transfer: engine::colorspace::Transfer::Sdr,
374 full_range: false,
375 };
376 let mut best = f64::MAX;
377 for _ in 0..5 {
378 let (mut my, mut mu, mut mv) = (y.clone(), u.clone(), v.clone());
379 let t = Instant::now();
380 mapper.map(&mut my, &mut mu, &mut mv, w, h);
381 let _ = i420_to_bgra(&sdr, &my, &mu, &mv, w, h);
382 best = best.min(t.elapsed().as_secs_f64() * 1000.0);
383 }
384 eprintln!("{w}x{h} tone map + convert: {best:.1} ms/frame");
385 assert!(best <= 39.0, "{best:.1} ms/frame over the 39 ms budget");
386}
387
388/// H.264 8-bit decode is bit-exact by conformance, so the two backends must
389/// agree. A mismatch means a driver deviation and is reported, not swallowed.
390#[test]
391#[ignore = "needs libengine_hw.so and a VA-API driver"]
392fn hardware_matches_software_on_frame_30() {
393 hwchild::require();
394 let (_, hw) = decode_all_hw("test_baseline.mp4");
395
396 engine::envcfg::set("VE_SW", "1");
397
398 let start = Instant::now();
399 let (_, rx) = DecodeSession::open(asset("test_baseline.mp4")).expect("software open");
400 let sw = rx
401 .into_iter()
402 .find(|f| f.index == 30)
403 .expect("software frame 30")
404 .bgra;
405 eprintln!("software reached frame 30 in {:?}", start.elapsed());
406
407 assert_eq!(hw.len(), sw.len(), "frame size");
408 let diff = hw.iter().zip(&sw).filter(|(a, b)| a != b).count();
409 eprintln!("frame 30 differing bytes: {diff} / {}", hw.len());
410 assert_eq!(diff, 0, "hardware and software decode disagree");
411}
412
413/// The AV1 twin of [`hardware_matches_software_on_frame_30`]: the plugin's
414/// VA-API decoder against the project's own `ec-av1`, whole file, byte for
415/// byte -- 8-bit AV1 decode is bit-exact by the same conformance argument the
416/// H.264 twin makes, and a mismatch means a deviation in one of the two
417/// decoders, reported rather than swallowed.
418#[test]
419#[ignore = "needs libengine_hw.so and a VA-API driver with AV1 decode"]
420fn av1_hardware_matches_software_on_every_frame() {
421 hwchild::require();
422 const NAME: &str = "test_av1.mkv";
423 let (hw_count, hw_frame_30) = decode_all_hw(NAME);
424
425 engine::envcfg::set("VE_SW", "1");
426 let path = asset(NAME);
427 let start = Instant::now();
428 let (meta, rx) = DecodeSession::open(&path).expect("software open");
429 let mut sw_count = 0usize;
430 let mut sw_frame_30 = Vec::new();
431 for frame in rx {
432 if frame.index == 30 {
433 sw_frame_30 = frame.bgra;
434 }
435 sw_count += 1;
436 }
437 let sw_elapsed = start.elapsed();
438 engine::envcfg::unset("VE_SW");
439 eprintln!("{NAME}: hardware {hw_count} frames, software {sw_count} frames in {sw_elapsed:?}");
440 assert_eq!(sw_count, hw_count, "frame count");
441 assert_eq!(sw_count, usize::try_from(meta.frame_count).expect("count"));
442 assert_eq!(hw_frame_30.len(), sw_frame_30.len(), "frame size");
443 let diff = hw_frame_30.iter().zip(&sw_frame_30).filter(|(a, b)| a != b).count();
444 eprintln!("frame 30 differing bytes: {diff} / {}", sw_frame_30.len());
445 assert_eq!(diff, 0, "hardware and software AV1 decode disagree");
446}
447
448/// The 10-bit twin: the plugin reads a P010 surface back as the high byte of
449/// each pair; `ec-av1` hands `u16` planes the seat downshifts by two. Same
450/// truncation, same picture -- or one of the two seats is wrong.
451#[test]
452#[ignore = "needs libengine_hw.so and a VA-API driver with 10-bit AV1 decode"]
453fn av1_ten_bit_hardware_matches_software_on_every_frame() {
454 hwchild::require();
455 const NAME: &str = "test_av1_10.mkv";
456 let (hw_count, hw_frame_30) = decode_all_hw(NAME);
457 engine::envcfg::set("VE_SW", "1");
458 let path = asset(NAME);
459 let start = Instant::now();
460 let (_, rx) = DecodeSession::open(&path).expect("software open");
461 let mut sw_count = 0usize;
462 let mut sw_frame_30 = Vec::new();
463 for frame in rx {
464 if frame.index == 30 {
465 sw_frame_30 = frame.bgra;
466 }
467 sw_count += 1;
468 }
469 let sw_elapsed = start.elapsed();
470 engine::envcfg::unset("VE_SW");
471 eprintln!("{NAME}: hardware {hw_count} frames, software {sw_count} frames in {sw_elapsed:?}");
472 assert_eq!(sw_count, hw_count, "frame count");
473 assert_eq!(hw_frame_30.len(), sw_frame_30.len(), "frame size");
474 let diff = hw_frame_30.iter().zip(&sw_frame_30).filter(|(a, b)| a != b).count();
475 eprintln!("frame 30 differing bytes: {diff} / {}", sw_frame_30.len());
476 assert_eq!(diff, 0, "hardware and software 10-bit AV1 decode disagree");
477}
478
479/// Annex-B NAL payloads (start codes stripped, trailing zeros trimmed).
480fn nals(annex_b: &[u8]) -> Vec<&[u8]> {
481 let mut out = Vec::new();
482 let mut start = None;
483 let mut i = 0;
484 while i + 2 < annex_b.len() {
485 if annex_b[i] == 0 && annex_b[i + 1] == 0 && annex_b[i + 2] == 1 {
486 if let Some(s) = start {
487 out.push(&annex_b[s..i]);
488 }
489 i += 3;
490 start = Some(i);
491 } else {
492 i += 1;
493 }
494 }
495 if let Some(s) = start {
496 out.push(&annex_b[s..]);
497 }
498 out
499}
500
501/// One access unit as a length-prefixed AVCC sample with `cabac_zero_word` --
502/// `zeros` zero bytes -- inside the *last* coded NAL's declared length. That is
503/// byte-for-byte what a phone-camera encoder writes, and what a decoder that
504/// stops consuming at the last NAL leaves behind as "not a NAL".
505fn sample_with_trailing_zeros(annex_b: &[u8], zeros: usize) -> (Vec<u8>, bool) {
506 let mut coded: Vec<&[u8]> = Vec::new();
507 let mut key = false;
508 for nal in nals(annex_b) {
509 let end = nal.iter().rposition(|&b| b != 0).map_or(0, |p| p + 1);
510 let nal = &nal[..end];
511 if nal.is_empty() {
512 continue;
513 }
514 match nal[0] & 0x1f {
515 6..=9 => continue, // parameter sets/SEI live in avcC or are dropped
516 5 => key = true,
517 _ => {}
518 }
519 coded.push(nal);
520 }
521 let mut sample = Vec::new();
522 let last = coded.len().saturating_sub(1);
523 for (i, nal) in coded.iter().enumerate() {
524 let len = nal.len() + if i == last { zeros } else { 0 };
525 sample.extend_from_slice(&(len as u32).to_be_bytes());
526 sample.extend_from_slice(nal);
527 if i == last {
528 sample.extend(std::iter::repeat_n(0u8, zeros));
529 }
530 }
531 (sample, key)
532}
533
534/// An mp4 cut from `test_baseline.mp4` whose every H.264 sample ends in four
535/// zero bytes.
536fn write_trailing_zero_fixture(src: &Path, out: &Path, frames: usize) {
537 let (meta, mut demuxer) = Demuxer::open(src).expect("open fixture source");
538 let first = demuxer.next_access_unit().expect("read").expect("au");
539 let (sps, pps) = mux::parameter_sets(&first).expect("parameter sets in the first au");
540 let mut muxer = Mp4Muxer::create(
541 out,
542 &VideoParams {
543 width: meta.width,
544 height: meta.height,
545 frame_rate: meta.frame_rate,
546 sps,
547 pps,
548 },
549 None,
550 )
551 .expect("create fixture");
552 let (sample, key) = sample_with_trailing_zeros(&first, 4);
553 muxer.write_coded_sample(&sample, key).expect("first sample");
554 for _ in 1..frames {
555 let Some(au) = demuxer.next_access_unit().expect("read") else {
556 break;
557 };
558 let (sample, key) = sample_with_trailing_zeros(&au, 4);
559 muxer.write_coded_sample(&sample, key).expect("sample");
560 }
561 muxer.finish().expect("finish fixture");
562}
563
564/// A phone-camera mp4 ends its every coded sample in `cabac_zero_word`. The
565/// plugin consumed each access unit only up to the last NAL cros-codecs
566/// reported and fed the leftover zero bytes back as if they were the next unit;
567/// `Nalu::next` refuses a buffer with no start code ("No NAL found"), so the
568/// whole session failed with code -2 before the first picture -- the export's
569/// `hardware decode failed (code -2)` on a file VA-API otherwise decodes.
570#[test]
571#[ignore = "needs libengine_hw.so and a VA-API driver"]
572fn hardware_decodes_samples_with_trailing_zero_words() {
573 hwchild::require();
574 let out = Scratch::file("ve_hw_trailing_zeros", "mp4");
575 write_trailing_zero_fixture(&asset("test_baseline.mp4"), &out, 30);
576 let mut hw = open_hw(&out);
577 let mut count = 0usize;
578 while let Some((_, _, _, w, h)) = hw
579 .next_frame()
580 .expect("hardware decode of trailing-zero samples")
581 {
582 assert_eq!((w, h), (1280, 720), "frame {count} dims");
583 count += 1;
584 }
585 assert_eq!(count, 30, "every picture decoded");
586}