forge
Explore
Log in

Don't you dare go Hollow

M9: ec-hw, ec-bench, oracle use ec-testkit for ffmpeg, fixtures and bitstreams; fixture and tool skips now fail, HOME/Downloads media replaced by open/derived clips

Browse files at this commit

07ab700f2056c7df20703bb09d61561b7e7c0e7cAhmet Kaan GümüşParent: 155ce74

17 changed files +161 -1096

Cargo.lockmodified+5 -0
@@ -404,6 +404,7 @@ dependencies = [
404404 "ec-mp3",
405405 "ec-opus",
406406 "ec-probe",
407+ "ec-testkit",
407408 "ec-truehd",
408409 "ec-va",
409410 "ec-vorbis",
@@ -531,6 +532,7 @@ dependencies = [
531532 "ec-dsp",
532533 "ec-h264-syntax",
533534 "ec-h265-syntax",
535+ "ec-testkit",
534536 "ec-va",
535537 "ec-vk",
536538 "ec-vp9-syntax",
@@ -1229,6 +1231,9 @@ dependencies = [
12291231 [[package]]
12301232 name = "oracle"
12311233 version = "0.1.0"
1234+dependencies = [
1235+ "ec-testkit",
1236+]
12321237
12331238 [[package]]
12341239 name = "oxideav-ac3"
crates/ec-hw/Cargo.tomlmodified+3 -0
@@ -18,3 +18,6 @@ ec-vp9-syntax.workspace = true
1818
1919 [target.'cfg(target_os = "linux")'.dependencies]
2020 ec-va.workspace = true
21+
22+[dev-dependencies]
23+ec-testkit.workspace = true
crates/ec-hw/examples/hw_config.rsmodified+3 -4
@@ -1,6 +1,5 @@
11 use std::fs;
22 use std::path::{Path, PathBuf};
3-use std::process::Command;
43
54 use ec_hw::{
65 Backend, EncCodec, EncoderConfig, FrameMetadata, H264Profile, HwEncoder, I420, RateControlMode,
@@ -73,7 +72,7 @@ fn encode(dir: &Path, name: &str, profile: H264Profile, backend: Backend) -> Opt
7372 }
7473
7574 fn probe(path: &Path) -> Vec<(String, String)> {
76- let out = Command::new("ffprobe")
75+ let out = ec_testkit::ffprobe()
7776 .args(["-v", "error", "-select_streams", "v:0", "-show_entries"])
7877 .arg(format!("stream={}", FIELDS.join(",")))
7978 .args(["-of", "default=nw=1"])
@@ -88,7 +87,7 @@ fn probe(path: &Path) -> Vec<(String, String)> {
8887 }
8988
9089 fn keyframes(path: &Path) -> Vec<usize> {
91- let out = Command::new("ffprobe")
90+ let out = ec_testkit::ffprobe()
9291 .args([
9392 "-v",
9493 "error",
@@ -116,7 +115,7 @@ fn value(info: &[(String, String)], key: &str) -> String {
116115 }
117116
118117 fn main() {
119- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
118+ let dir = std::env::temp_dir();
120119 for (label, profile) in [("main", H264Profile::Main), ("cb", H264Profile::ConstrainedBaseline)] {
121120 compare(&dir, label, profile);
122121 }
crates/ec-hw/examples/hw_decode.rsmodified+5 -6
@@ -2,15 +2,14 @@
22 //! The 10-bit H.265 and AV1 streams run on Vulkan and are compared with the VA-API decode of the same stream.
33 //!
44 //! ```text
5-//! cargo run -p ec-hw --example hw_decode -- <scratch dir>
5+//! cargo run -p ec-hw --example hw_decode
66 //! ```
77
88 use std::collections::HashSet;
99 use std::fs;
1010 use std::os::fd::AsRawFd;
1111 use std::os::unix::fs::MetadataExt;
12-use std::path::{Path, PathBuf};
13-use std::process::Command;
12+use std::path::Path;
1413
1514 use ec_hw::{
1615 Backend, Codec, DmaBufPicture, EncCodec, EncoderConfig, FrameMetadata, HwDecoder, HwEncoder,
@@ -106,7 +105,7 @@ const CASES: &[Case] = &[
106105 ];
107106
108107 fn main() {
109- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
108+ let dir = std::env::temp_dir();
110109 for case in CASES {
111110 run(&dir, case);
112111 }
@@ -491,7 +490,7 @@ fn compare_i420(label: &str, codec: Codec, backend: Backend, ours: &[I420], thei
491490 }
492491
493492 fn ffmpeg(args: &[&str]) {
494- let status = Command::new("ffmpeg")
493+ let status = ec_testkit::ffmpeg()
495494 .args(["-y", "-loglevel", "error"])
496495 .args(args)
497496 .status()
@@ -588,7 +587,7 @@ fn own_av1(dir: &Path) {
588587 decoder.flush().expect("flush");
589588 drain(&mut decoder, &mut decoded);
590589
591- let status = Command::new("ffmpeg")
590+ let status = ec_testkit::ffmpeg()
592591 .args(["-y", "-loglevel", "error", "-i"])
593592 .arg(&stream)
594593 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
crates/ec-hw/examples/hw_decode_rgb.rsmodified+2 -4
@@ -3,11 +3,10 @@
33 //! Streams are assumed untagged, so the matrix is BT.709 from 720 lines up and BT.601 below.
44 //!
55 //! ```text
6-//! cargo run --release -p ec-hw --example hw_decode_rgb -- <scratch dir>
6+//! cargo run --release -p ec-hw --example hw_decode_rgb
77 //! ```
88
99 use std::fs;
10-use std::path::PathBuf;
1110 use std::time::{Duration, Instant};
1211
1312 use ec_dsp::rgb::{YuvToRgb, i420_to_packed};
@@ -23,9 +22,8 @@ const FILES: &[(&str, Codec)] = &[
2322 ];
2423
2524 fn main() {
26- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
2725 for &(name, codec) in FILES {
28- let data = fs::read(dir.join(name)).expect("read stream");
26+ let data = fs::read(ec_testkit::fixture(&format!("bitstreams/{name}"))).expect("read stream");
2927 let units = if matches!(codec, Codec::Av1 | Codec::Vp9) {
3028 ivf_units(&data)
3129 } else {
crates/ec-hw/examples/hw_oracle.rsmodified+2 -3
@@ -6,7 +6,6 @@
66
77 use std::fs;
88 use std::path::Path;
9-use std::process::Command;
109
1110 use ec_hw::{Backend, Codec, HwDecoder};
1211
@@ -99,13 +98,13 @@ fn ivf_units(ivf: &[u8]) -> Vec<&[u8]> {
9998 }
10099
101100 fn reference(path: &Path) -> Result<(bool, Vec<(usize, u32)>), String> {
102- let probe = Command::new("ffprobe")
101+ let probe = ec_testkit::ffprobe()
103102 .args(["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=pix_fmt", "-of", "csv=p=0"])
104103 .arg(path)
105104 .output()
106105 .map_err(|e| e.to_string())?;
107106 let wide = String::from_utf8_lossy(&probe.stdout).contains("10");
108- let out = Command::new("ffmpeg")
107+ let out = ec_testkit::ffmpeg()
109108 .args(["-v", "error", "-i"])
110109 .arg(path)
111110 .args(["-noautoscale", "-pix_fmt", if wide { "yuv420p10le" } else { "yuv420p" }, "-f", "framecrc", "-"])
crates/ec-hw/examples/hw_parity.rsmodified+4 -4
@@ -3,7 +3,7 @@
33 //! Every encode and decode runs in a child process of this binary, because the driver's state outlives a display: within one process the same encode lands at different sizes depending on what ran before it.
44 //!
55 //! ```text
6-//! cargo run --release -p ec-hw --example hw_parity -- <scratch dir>
6+//! cargo run --release -p ec-hw --example hw_parity
77 //! ```
88
99 use std::fmt::Display;
@@ -115,7 +115,7 @@ fn spec_from_key(key: &str) -> Spec {
115115 fn make_source(dir: &Path, source: &str, w: u32, h: u32) -> PathBuf {
116116 let path = dir.join(format!("{source}-{w}x{h}.yuv"));
117117 if !path.exists() {
118- let status = Command::new("ffmpeg")
118+ let status = ec_testkit::ffmpeg()
119119 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
120120 .arg(format!("{source}=size={w}x{h}:rate={FPS}"))
121121 .args(["-frames:v", &FRAMES.to_string(), "-pix_fmt", "yuv420p", "-f", "rawvideo"])
@@ -303,7 +303,7 @@ fn field(out: &str, key: &str) -> Option<f64> {
303303 fn psnr_y(stream: &Path, format: &str, source: &Path, (w, h): (u32, u32)) -> Option<f64> {
304304 let rate = FPS.to_string();
305305 let size = format!("{w}x{h}");
306- let out = Command::new("ffmpeg")
306+ let out = ec_testkit::ffmpeg()
307307 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
308308 .arg(stream)
309309 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-s", &size, "-r", &rate, "-i"])
@@ -393,7 +393,7 @@ fn main() {
393393 }
394394 return;
395395 }
396- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
396+ let dir = std::env::temp_dir();
397397 let me = std::env::current_exe().expect("own path");
398398 let mut decode_inputs: Vec<(&'static str, (u32, u32), Spec, Backend, PathBuf)> = Vec::new();
399399
crates/ec-hw/examples/hw_ten.rsmodified+1 -1
@@ -9,7 +9,7 @@ const FRAMES: u32 = 30;
99 const PEAK: f64 = 1023.0;
1010
1111 fn main() {
12- let dir = std::env::args().nth(1).unwrap_or_else(|| ".".into());
12+ let dir = std::env::temp_dir().display().to_string();
1313 let rates = [
1414 ("cqp", RateControlMode::ConstantQp { qp: 30 }),
1515 ("cbr", RateControlMode::ConstantBitrate),
crates/ec-hw/tests/film_grain.rsmodified+5 -22
@@ -7,8 +7,8 @@
77 //! that both apply grain: `ec-av1` (this family's software decoder) and ffmpeg
88 //! (libdav1d). Per-frame deviations are reported, not just asserted.
99
10-use std::path::{Path, PathBuf};
11-use std::process::{Command, Stdio};
10+use std::path::Path;
11+use std::process::Stdio;
1212 use std::rc::Rc;
1313
1414 use ec_hw::{Codec, Decoder, I420};
@@ -17,10 +17,6 @@ use ec_va::Display;
1717 /// Frames in the grain fixture (every one of them is shown).
1818 const FRAMES: usize = 90;
1919
20-fn fixture() -> PathBuf {
21- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/bitstreams/av1-grain.ivf")
22-}
23-
2420 fn display() -> Option<Rc<Display>> {
2521 match ec_va::open() {
2622 Ok(display) => Some(display),
@@ -145,7 +141,7 @@ fn software_frames(data: &[u8]) -> Vec<Planes> {
145141
146142 /// ffmpeg's decode (libdav1d, grain applied by default) as raw 4:2:0 planes.
147143 fn ffmpeg_frames(path: &Path, width: usize, height: usize) -> Option<Vec<Planes>> {
148- let output = Command::new("ffmpeg")
144+ let output = ec_testkit::ffmpeg()
149145 .args(["-nostdin", "-v", "error", "-i"])
150146 .arg(path)
151147 .args([
@@ -185,21 +181,8 @@ fn ffmpeg_frames(path: &Path, width: usize, height: usize) -> Option<Vec<Planes>
185181 /// the two software decoders frame by frame.
186182 #[test]
187183 fn hardware_grain_matches_software_decoders() {
188- let path = fixture();
189- let Ok(data) = std::fs::read(&path) else {
190- // `EC_REQUIRE_FIXTURES=1` turns an absent fixture into a failure, so a
191- // checkout that never generated it cannot report this test green.
192- assert!(
193- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
194- "EC_REQUIRE_FIXTURES=1 but fixture {} is absent",
195- path.display()
196- );
197- eprintln!(
198- "skipped: {} is absent (extract it from test_av1_grain.mkv)",
199- path.display()
200- );
201- return;
202- };
184+ let path = ec_testkit::fixture("bitstreams/av1-grain.ivf");
185+ let data = std::fs::read(&path).expect("read the grain fixture");
203186 let Some(display) = display() else {
204187 return;
205188 };
crates/ec-hw/tests/gpu.rsmodified+91 -908
@@ -2,8 +2,7 @@
22 //!
33 //! They are not `#[ignore]`d — a hardware crate whose tests do not touch the
44 //! hardware tests nothing — but they *skip* (print and return) when there is no
5-//! VA display or when the fixtures have not been generated. That keeps a
6-//! checkout without a GPU green while making this machine's run meaningful.
5+//! VA display. Missing fixtures and ffmpeg fail.
76 //!
87 //! The oracle is ffmpeg's software decoder: every fixture is decoded here and
98 //! by `ffmpeg -f rawvideo`, and the two are compared frame by frame.
@@ -12,7 +11,7 @@ use std::io::Read;
1211 use std::path::{Path, PathBuf};
1312 use std::process::{Command, Stdio};
1413 use std::rc::Rc;
15-use std::time::{Duration, Instant};
14+use std::time::Instant;
1615
1716 use ec_hw::{
1817 Codec, Decoder, EncCodec, Encoder, EncoderConfig, Frame, FrameMetadata, H264Profile, I420,
@@ -24,10 +23,6 @@ use ec_va::Display;
2423 /// reordering, few enough to keep the suite under a minute.
2524 const FRAMES: usize = 24;
2625
27-fn bitstreams() -> PathBuf {
28- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/bitstreams")
29-}
30-
3126 fn display() -> Option<Rc<Display>> {
3227 match ec_va::open() {
3328 Ok(display) => Some(display),
@@ -38,23 +33,6 @@ fn display() -> Option<Rc<Display>> {
3833 }
3934 }
4035
41-fn fixtures(pattern: &str) -> Vec<PathBuf> {
42- let Ok(dir) = std::fs::read_dir(bitstreams()) else {
43- return Vec::new();
44- };
45- let mut out: Vec<PathBuf> = dir
46- .flatten()
47- .map(|e| e.path())
48- .filter(|p| {
49- p.file_name()
50- .and_then(|n| n.to_str())
51- .is_some_and(|n| n.ends_with(pattern))
52- })
53- .collect();
54- out.sort();
55- out
56-}
57-
5836 /// The software reference: ffmpeg decoding the same file to raw planes.
5937 struct Reference {
6038 child: std::process::Child,
@@ -65,7 +43,7 @@ struct Reference {
6543 impl Reference {
6644 fn open(path: &Path, width: u32, height: u32, ten_bit: bool) -> Option<Reference> {
6745 let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
68- let child = Command::new("ffmpeg")
46+ let child = ec_testkit::ffmpeg()
6947 .args(["-nostdin", "-v", "error", "-i"])
7048 .arg(path)
7149 // `-fps_mode passthrough`: without it ffmpeg conforms its output to
@@ -301,10 +279,7 @@ fn split_ivf(data: &[u8]) -> Vec<&[u8]> {
301279 /// Decode every named fixture and compare with ffmpeg, frame by frame.
302280 fn compare_against_ffmpeg(files: &[PathBuf], codec: Codec, ten_bit: bool) {
303281 let Some(display) = display() else { return };
304- if files.is_empty() {
305- eprintln!("skipped: no fixtures — run scripts/gen-bitstream-fixtures.sh");
306- return;
307- }
282+ assert!(!files.is_empty(), "no fixtures: run scripts/fixtures.sh");
308283 let mut table = Vec::new();
309284 for path in files {
310285 let data = std::fs::read(path).expect("fixture is readable");
@@ -381,7 +356,7 @@ fn name_of(p: &Path) -> String {
381356 /// The 4:2:0 fixtures of one kind; the 4:4:4 and monochrome ones are the
382357 /// profiles this GPU does not decode, and have their own test.
383358 fn profile_420(pattern: &str, codec: &str) -> Vec<PathBuf> {
384- fixtures(pattern)
359+ ec_testkit::fixtures("bitstreams", pattern)
385360 .into_iter()
386361 .filter(|p| {
387362 let name = name_of(p);
@@ -407,14 +382,14 @@ fn ten_bit(pattern: &str, codec: &str) -> Vec<PathBuf> {
407382 /// The selection must not depend on where the repository is checked out.
408383 #[test]
409384 fn fixture_selection_ignores_the_checkout_path() {
410- for p in eight_bit(".ivf", "av1") {
385+ for p in eight_bit("ivf", "av1") {
411386 let name = name_of(&p);
412387 assert!(
413388 name.starts_with("av1") && !name.contains("10bit"),
414389 "{name} is not an 8-bit AV1 fixture"
415390 );
416391 }
417- for p in ten_bit(".ivf", "vp9") {
392+ for p in ten_bit("ivf", "vp9") {
418393 let name = name_of(&p);
419394 assert!(
420395 name.starts_with("vp9") && name.contains("10bit"),
@@ -425,12 +400,12 @@ fn fixture_selection_ignores_the_checkout_path() {
425400
426401 #[test]
427402 fn h264_matches_ffmpeg() {
428- compare_against_ffmpeg(&fixtures(".264"), Codec::H264, false);
403+ compare_against_ffmpeg(&ec_testkit::fixtures("bitstreams", "264"), Codec::H264, false);
429404 }
430405
431406 #[test]
432407 fn hevc_8bit_matches_ffmpeg() {
433- compare_against_ffmpeg(&eight_bit(".265", "hevc"), Codec::H265, false);
408+ compare_against_ffmpeg(&eight_bit("265", "hevc"), Codec::H265, false);
434409 }
435410
436411 /// The 10-bit path, which is the RT format defect this crate exists to not
@@ -438,11 +413,8 @@ fn hevc_8bit_matches_ffmpeg() {
438413 /// P010 surface, and the ten bits must survive to the caller.
439414 #[test]
440415 fn hevc_10bit_decodes_to_p010() {
441- let files = ten_bit(".265", "hevc");
442- if files.is_empty() {
443- eprintln!("skipped: no 10-bit HEVC fixtures");
444- return;
445- }
416+ let files = ten_bit("265", "hevc");
417+ assert!(!files.is_empty(), "no 10-bit HEVC fixtures");
446418 let Some(display) = display() else { return };
447419 let data = std::fs::read(&files[0]).expect("fixture is readable");
448420 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
@@ -461,22 +433,22 @@ fn hevc_10bit_decodes_to_p010() {
461433
462434 #[test]
463435 fn vp9_matches_ffmpeg() {
464- compare_against_ffmpeg(&eight_bit(".ivf", "vp9"), Codec::Vp9, false);
436+ compare_against_ffmpeg(&eight_bit("ivf", "vp9"), Codec::Vp9, false);
465437 }
466438
467439 #[test]
468440 fn vp9_10bit_matches_ffmpeg() {
469- compare_against_ffmpeg(&ten_bit(".ivf", "vp9"), Codec::Vp9, true);
441+ compare_against_ffmpeg(&ten_bit("ivf", "vp9"), Codec::Vp9, true);
470442 }
471443
472444 #[test]
473445 fn av1_matches_ffmpeg() {
474- compare_against_ffmpeg(&eight_bit(".ivf", "av1"), Codec::Av1, false);
446+ compare_against_ffmpeg(&eight_bit("ivf", "av1"), Codec::Av1, false);
475447 }
476448
477449 #[test]
478450 fn av1_10bit_matches_ffmpeg() {
479- compare_against_ffmpeg(&ten_bit(".ivf", "av1"), Codec::Av1, true);
451+ compare_against_ffmpeg(&ten_bit("ivf", "av1"), Codec::Av1, true);
480452 }
481453
482454 /// Every "not supported" this crate says has to be a fact about the driver, not
@@ -499,11 +471,7 @@ fn unsupported_profiles_are_refused_with_a_reason() {
499471 ec_va::caps::Profile::AV1Profile1,
500472 ),
501473 ] {
502- let path = bitstreams().join(file);
503- if !path.exists() {
504- eprintln!("skipped: no {file}");
505- continue;
506- }
474+ let path = ec_testkit::fixture(&format!("bitstreams/{file}"));
507475 assert!(
508476 !caps.supports(absent, ec_va::caps::Entrypoint::VLD),
509477 "{absent:?} is in fact supported — the refusal below would be a bug"
@@ -610,7 +578,7 @@ fn round_trip(codec: EncCodec, width: u32, height: u32, min_db: f64) {
610578
611579 // ffprobe first: the conformance window / frame cropping has to survive, so
612580 // a 1916-wide encode comes back 1916 wide and not 1920.
613- let probe = Command::new("ffprobe")
581+ let probe = ec_testkit::ffprobe()
614582 .args([
615583 "-v",
616584 "error",
@@ -691,7 +659,7 @@ fn h264_profile_round_trip(profile: H264Profile, ffprobe_name: &str) {
691659 let path = dir.join("out.264");
692660 std::fs::write(&path, &stream).expect("write bitstream");
693661
694- let probe = Command::new("ffprobe")
662+ let probe = ec_testkit::ffprobe()
695663 .args([
696664 "-v",
697665 "error",
@@ -712,7 +680,7 @@ fn h264_profile_round_trip(profile: H264Profile, ffprobe_name: &str) {
712680 );
713681
714682 // Strict decode: any warning or error on stderr fails the test.
715- let decode = Command::new("ffmpeg")
683+ let decode = ec_testkit::ffmpeg()
716684 .args(["-nostdin", "-v", "warning", "-i"])
717685 .arg(&path)
718686 .args(["-f", "null", "-"])
@@ -798,13 +766,7 @@ fn our_encoder_and_our_decoder_agree() {
798766 fn encode_frame_zero_copy_matches_the_cpu_path() {
799767 let Some(display) = display() else { return };
800768 let (width, height) = (1920u32, 1080u32);
801- let Some(path) = fixtures(".264")
802- .into_iter()
803- .find(|p| p.file_name().and_then(|n| n.to_str()) == Some("h264-1080p-23.976-8bit.264"))
804- else {
805- eprintln!("skipped: no h264-1080p fixture — run scripts/gen-bitstream-fixtures.sh");
806- return;
807- };
769+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
808770 let data = std::fs::read(&path).expect("fixture is readable");
809771 let frames = 10usize;
810772
@@ -921,7 +883,7 @@ fn colour_description_reaches_the_vui() {
921883 (path, coded.data)
922884 };
923885 let probe = |path: &Path| -> String {
924- let out = Command::new("ffprobe")
886+ let out = ec_testkit::ffprobe()
925887 .args([
926888 "-v",
927889 "error",
@@ -1045,38 +1007,7 @@ fn av1_encode_agrees_between_two_decoders() {
10451007 // encoder does not serve his files.
10461008 // ---------------------------------------------------------------------------
10471009
1048-/// Film B's native 10-bit crop from the real-library manifest: `(path, seek,
1049-/// width, height, x, y)`, the same 1920x1024 window and 00:40:00 seek the
1050-/// software gates use (`ec-av1`'s `native_gate_clips`).
1051-fn ten_bit_film_clip() -> Option<(PathBuf, String, u32, u32, u32, u32)> {
1052- let manifest =
1053- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
1054- let text = std::fs::read_to_string(manifest).ok()?;
1055- for line in text.lines().skip(1) {
1056- let f: Vec<&str> = line.split('\t').collect();
1057- if f.len() < 7 || f[2] != "av1" || f[5] != "yuv420p10le" || f[3] != "3840" {
1058- continue;
1059- }
1060- let path = PathBuf::from(f[0]);
1061- if !path.exists() {
1062- continue;
1063- }
1064- let (nw, nh): (u32, u32) = (f[3].parse().ok()?, f[4].parse().ok()?);
1065- let (cw, ch) = (nw.min(1920) / 128 * 128, nh.min(1024) / 128 * 128);
1066- return Some((
1067- path,
1068- "00:40:00".into(),
1069- cw,
1070- ch,
1071- ((nw - cw) / 2) & !1,
1072- ((nh - ch) / 2) & !1,
1073- ));
1074- }
1075- None
1076-}
1077-
1078-/// A 10-bit gradient with real dynamic range, used when the manifest has no
1079-/// 10-bit film: 64..940 across the frame with a moving highlight, so the
1010+/// A 10-bit gradient with real dynamic range: 64..940 across the frame with a moving highlight, so the
10801011 /// stream is neither flat nor 8-bit content dressed up as 10.
10811012 fn source_frame_16(width: u32, height: u32, t: u32) -> I420_16 {
10821013 let (w, h) = (width as usize, height as usize);
@@ -1109,6 +1040,16 @@ fn source_frame_16(width: u32, height: u32, t: u32) -> I420_16 {
11091040 f
11101041 }
11111042
1043+/// The 10-bit source the 10-bit gates encode, and the y4m every reference
1044+/// encoder and every PSNR reads.
1045+fn ten_bit_source(dir: &Path, frames: u32) -> (String, PathBuf, Vec<I420_16>) {
1046+ let y4m = dir.join("source-10bit.y4m");
1047+ let (w, h) = (1920u32, 1024u32);
1048+ let planes: Vec<I420_16> = (0..frames).map(|t| source_frame_16(w, h, t)).collect();
1049+ assert!(write_y4m_16(&y4m, &planes, (24, 1)), "write the 10-bit y4m");
1050+ ("synthetic 10-bit gradient".into(), y4m, planes)
1051+}
1052+
11121053 /// Write 10-bit planes as a y4m so ffmpeg sees the same source the encoder did.
11131054 fn write_y4m_16(path: &Path, frames: &[I420_16], fps: (u32, u32)) -> bool {
11141055 use std::io::Write;
@@ -1141,85 +1082,11 @@ fn write_y4m_16(path: &Path, frames: &[I420_16], fps: (u32, u32)) -> bool {
11411082 out.flush().is_ok()
11421083 }
11431084
1144-/// The 10-bit source the 10-bit gates encode, plus the y4m every reference
1145-/// encoder and every PSNR reads: his own film when the manifest has it,
1146-/// a synthetic 10-bit gradient otherwise. The label says which — a gate that
1147-/// does not say what it exercised proves nothing about his library.
1148-fn ten_bit_source(dir: &Path, frames: u32) -> Option<(String, PathBuf, Vec<I420_16>)> {
1149- let y4m = dir.join("source-10bit.y4m");
1150- let _ = std::fs::remove_file(&y4m);
1151- if let Some((path, seek, cw, ch, x, y)) = ten_bit_film_clip() {
1152- let ok = Command::new("ffmpeg")
1153- .args(["-nostdin", "-v", "error", "-y", "-ss", &seek, "-i"])
1154- .arg(&path)
1155- .args([
1156- "-frames:v",
1157- &frames.to_string(),
1158- "-vf",
1159- &format!("crop={cw}:{ch}:{x}:{y}"),
1160- "-pix_fmt",
1161- "yuv420p10le",
1162- // y4m's 10-bit chroma formats are outside its official set.
1163- "-strict",
1164- "-1",
1165- ])
1166- .arg(&y4m)
1167- .status()
1168- .is_ok_and(|s| s.success());
1169- if ok && let Some(planes) = raw_frames_16(&y4m, cw, ch, frames) {
1170- return Some(("film B 10-bit native crop".into(), y4m, planes));
1171- }
1172- eprintln!("film B 10-bit extraction failed; falling back to the synthetic gradient");
1173- }
1174- let (w, h) = (1920u32, 1024u32);
1175- let planes: Vec<I420_16> = (0..frames).map(|t| source_frame_16(w, h, t)).collect();
1176- write_y4m_16(&y4m, &planes, (24, 1)).then_some((
1177- "synthetic 10-bit gradient".into(),
1178- y4m,
1179- planes,
1180- ))
1181-}
1182-
1183-/// The same pictures as 10-bit planes, for the hardware encoder's own input.
1184-fn raw_frames_16(y4m: &Path, width: u32, height: u32, frames: u32) -> Option<Vec<I420_16>> {
1185- let out = Command::new("ffmpeg")
1186- .args(["-nostdin", "-v", "error", "-i"])
1187- .arg(y4m)
1188- .args(["-pix_fmt", "yuv420p10le", "-f", "rawvideo", "-"])
1189- .stderr(Stdio::null())
1190- .output()
1191- .ok()?;
1192- let (w, h) = (width as usize, height as usize);
1193- let (cw, ch) = (w.div_ceil(2), h.div_ceil(2));
1194- let frame_len = (w * h + 2 * cw * ch) * 2;
1195- let read = |s: &[u8]| -> Vec<u16> {
1196- s.as_chunks::<2>()
1197- .0
1198- .iter()
1199- .map(|p| u16::from_le_bytes(*p))
1200- .collect()
1201- };
1202- let mut pictures = Vec::new();
1203- for chunk in out.stdout.chunks_exact(frame_len).take(frames as usize) {
1204- let (y, rest) = chunk.split_at(w * h * 2);
1205- let (u, v) = rest.split_at(cw * ch * 2);
1206- pictures.push(I420_16 {
1207- y: read(y),
1208- u: read(u),
1209- v: read(v),
1210- width,
1211- height,
1212- bit_depth: 10,
1213- });
1214- }
1215- (!pictures.is_empty()).then_some(pictures)
1216-}
1217-
12181085 /// What ffprobe calls the stream's pixel format — for an AV1 stream that is
12191086 /// libdav1d reporting the sequence header's `high_bitdepth`, read by a decoder
12201087 /// that shares no code with the writer above.
12211088 fn ffprobe_pix_fmt(path: &Path, format: &str) -> Option<String> {
1222- let out = Command::new("ffprobe")
1089+ let out = ec_testkit::ffprobe()
12231090 .args([
12241091 "-v",
12251092 "error",
@@ -1274,10 +1141,7 @@ fn hevc_main10_encode_round_trips() {
12741141 let Some(display) = display() else { return };
12751142 let dir = std::env::temp_dir().join("ec-hw-hevc-10bit");
12761143 let _ = std::fs::create_dir_all(&dir);
1277- let Some((_, _, planes)) = ten_bit_source(&dir, 10) else {
1278- eprintln!("skipped: no 10-bit source could be built");
1279- return;
1280- };
1144+ let (_, _, planes) = ten_bit_source(&dir, 10);
12811145 let (width, height) = (planes[0].width, planes[0].height);
12821146 let data = match encode_stream_16(
12831147 &display,
@@ -1328,11 +1192,7 @@ fn av1_10bit_encode_agrees_between_two_decoders() {
13281192 let dir = std::env::temp_dir().join("ec-hw-av1-10bit");
13291193 let _ = std::fs::create_dir_all(&dir);
13301194 let frames = 10u32;
1331- let Some((label, y4m, planes)) = ten_bit_source(&dir, frames) else {
1332- eprintln!("skipped: no 10-bit source could be built");
1333- return;
1334- };
1335- let _ = y4m;
1195+ let (label, _, planes) = ten_bit_source(&dir, frames);
13361196 let (width, height) = (planes[0].width, planes[0].height);
13371197 let data = match encode_stream_16(
13381198 &display,
@@ -1432,23 +1292,16 @@ fn av1_10bit_encode_agrees_between_two_decoders() {
14321292 #[test]
14331293 fn av1_encode_rate_control_lands() {
14341294 let Some(display) = display() else { return };
1435- let clips = real_clips();
1436- let Some((label, source)) = clips.into_iter().next() else {
1437- eprintln!("skipped: no real-library manifest");
1438- return;
1439- };
1295+ let (label, source) = real_clips().remove(0);
14401296 let dir = std::env::temp_dir().join("ec-hw-av1-rc");
14411297 let _ = std::fs::create_dir_all(&dir);
14421298 let (width, height, frames, fps) = (1920u32, 1080u32, 60u32, 30u32);
14431299 let y4m = dir.join("rc-source.y4m");
1444- if !extract_y4m(&source, &y4m, width, height, frames) {
1445- eprintln!("skipped {label}: extraction failed");
1446- return;
1447- }
1448- let Some(planes) = raw_frames(&y4m, width, height, frames) else {
1449- eprintln!("skipped {label}: no frames extracted");
1450- return;
1451- };
1300+ assert!(
1301+ extract_y4m(&source, &y4m, width, height, frames),
1302+ "{label}: extraction failed"
1303+ );
1304+ let planes = raw_frames(&y4m, width, height, frames).expect("frames of the trailer");
14521305
14531306 println!(
14541307 "AV1 rate control on {label}, {width}x{height} yuv420p, {} frames at {fps} fps:",
@@ -1547,7 +1400,7 @@ fn av1_encode_rate_control_lands() {
15471400 /// [`ffmpeg_psnr`] with the rate pinned to `fps` on both inputs.
15481401 fn ffmpeg_psnr_at(coded: &Path, source: &Path, fps: u32) -> Option<f64> {
15491402 let rate = fps.to_string();
1550- let out = Command::new("ffmpeg")
1403+ let out = ec_testkit::ffmpeg()
15511404 .args(["-nostdin", "-v", "info", "-f", "obu", "-r", &rate])
15521405 .arg("-i")
15531406 .arg(coded)
@@ -1567,126 +1420,6 @@ fn ffmpeg_psnr_at(coded: &Path, source: &Path, fps: u32) -> Option<f64> {
15671420 .filter(|v| v.is_finite())
15681421 }
15691422
1570-/// What the GPU's 10-bit AV1 costs against 10-bit software, on his own film.
1571-///
1572-/// The same shape as the 8-bit row, at film B's native 1920x1024 crop and
1573-/// entirely in the 10-bit domain: no arm ever sees an 8-bit sample, so the
1574-/// comparison is encoder against encoder rather than depth against depth.
1575-/// Skips when the manifest has no 10-bit film -- a synthetic gradient would
1576-/// be a BD-rate number about a gradient.
1577-#[test]
1578-fn av1_10bit_bd_row_vs_software() {
1579- let Some(display) = display() else { return };
1580- let dir = std::env::temp_dir().join("ec-hw-av1-10bit-bd");
1581- let _ = std::fs::create_dir_all(&dir);
1582- let frames = 12u32;
1583- let Some((label, y4m, planes)) = ten_bit_source(&dir, frames) else {
1584- eprintln!("skipped: no 10-bit source could be built");
1585- return;
1586- };
1587- if !label.starts_with("film") {
1588- eprintln!("skipped: no 10-bit film in the real-library manifest ({label})");
1589- return;
1590- }
1591- let (width, height) = (planes[0].width, planes[0].height);
1592- let coded = planes.len() as u32;
1593-
1594- let mut ours = Vec::new();
1595- for qp in [180u32, 140, 100, 60] {
1596- let data = match encode_stream_16(
1597- &display,
1598- EncCodec::Av1,
1599- &planes,
1600- qp,
1601- RateControlMode::ConstantQp { qp },
1602- ) {
1603- Ok(data) => data,
1604- Err(e) => {
1605- eprintln!("skipped: 10-bit AV1 encode unavailable ({e})");
1606- return;
1607- }
1608- };
1609- let path = dir.join(format!("hw10-{qp}.obu"));
1610- std::fs::write(&path, &data).expect("write");
1611- if let Some(db) = ffmpeg_psnr(&path, &y4m, true) {
1612- ours.push((data.len() as f64 * 8.0 / f64::from(coded), db));
1613- }
1614- }
1615- let rav1e: Vec<(f64, f64)> = [180u32, 140, 100, 60]
1616- .iter()
1617- .filter_map(|q| {
1618- software_point(
1619- &dir,
1620- &y4m,
1621- "film-B-10bit",
1622- "librav1e",
1623- &[
1624- "-pix_fmt",
1625- "yuv420p10le",
1626- "-rav1e-params",
1627- &format!("speed=6:quantizer={q}"),
1628- "-g",
1629- "60",
1630- ],
1631- *q,
1632- coded,
1633- )
1634- })
1635- .collect();
1636- let libaom: Vec<(f64, f64)> = [56u32, 44, 32, 20]
1637- .iter()
1638- .filter_map(|crf| {
1639- software_point(
1640- &dir,
1641- &y4m,
1642- "film-B-10bit",
1643- "libaom-av1",
1644- &[
1645- "-pix_fmt",
1646- "yuv420p10le",
1647- "-cpu-used",
1648- "6",
1649- "-crf",
1650- &crf.to_string(),
1651- "-b:v",
1652- "0",
1653- "-g",
1654- "60",
1655- ],
1656- *crf,
1657- coded,
1658- )
1659- })
1660- .collect();
1661-
1662- println!("10-bit BD row: {label}, {width}x{height} yuv420p10le, {coded} frames");
1663- for (name, ladder) in [
1664- ("hw AV1 10-bit", &ours),
1665- ("librav1e 10-bit", &rav1e),
1666- ("libaom 10-bit", &libaom),
1667- ] {
1668- println!(" {name}: {ladder:?}");
1669- for pair in ladder.windows(2) {
1670- assert!(
1671- pair[1].0 > pair[0].0 && pair[1].1 > pair[0].1,
1672- "{name}: ladder is not monotone at {pair:?}"
1673- );
1674- }
1675- }
1676- if ours.len() >= 3 && rav1e.len() >= 3 {
1677- println!(
1678- " BD-rate: hw AV1 10-bit vs librav1e speed 6 10-bit: {:+.1}%",
1679- bd_rate(&rav1e, &ours) * 100.0
1680- );
1681- }
1682- if ours.len() >= 3 && libaom.len() >= 3 {
1683- println!(
1684- " BD-rate: hw AV1 10-bit vs libaom cpu-used 6 10-bit: {:+.1}%",
1685- bd_rate(&libaom, &ours) * 100.0
1686- );
1687- }
1688-}
1689-
16901423 /// What the GPU's AV1 costs against software, on his own content.
16911424 ///
16921425 /// Four quantisers per encoder on a 1920x1080 crop of a film and of a screen
@@ -1698,11 +1431,6 @@ fn av1_10bit_bd_row_vs_software() {
16981431 #[test]
16991432 fn av1_encode_bd_row_vs_software() {
17001433 let Some(display) = display() else { return };
1701- let clips = real_clips();
1702- if clips.is_empty() {
1703- eprintln!("skipped: no real-library manifest");
1704- return;
1705- }
17061434 // A ladder compared with itself saves nothing: the check on the metric.
17071435 let same = [(100.0, 30.0), (200.0, 35.0), (400.0, 40.0)];
17081436 assert!(
@@ -1712,20 +1440,14 @@ fn av1_encode_bd_row_vs_software() {
17121440
17131441 let dir = std::env::temp_dir().join("ec-hw-av1-bd");
17141442 let _ = std::fs::create_dir_all(&dir);
1715- for (label, source) in clips {
1443+ for (label, source) in real_clips() {
17161444 let y4m = dir.join(format!("{label}.y4m"));
17171445 let (width, height, frames) = (1920u32, 1080u32, 12u32);
1718- if !extract_y4m(&source, &y4m, width, height, frames) {
1719- eprintln!("skipped {label}: extraction failed");
1720- continue;
1721- }
1722- let planes = match raw_frames(&y4m, width, height, frames) {
1723- Some(planes) => planes,
1724- None => {
1725- eprintln!("skipped {label}: no frames extracted");
1726- continue;
1727- }
1728- };
1446+ assert!(
1447+ extract_y4m(&source, &y4m, width, height, frames),
1448+ "{label}: extraction failed"
1449+ );
1450+ let planes = raw_frames(&y4m, width, height, frames).expect("frames of the trailer");
17291451
17301452 let mut ours = Vec::new();
17311453 // Descending quantiser: every ladder here is ordered by rising rate.
@@ -1840,7 +1562,7 @@ fn software_point(
18401562 ) -> Option<(f64, f64)> {
18411563 let out = dir.join(format!("{label}-{encoder}-{point}.ivf"));
18421564 let _ = std::fs::remove_file(&out);
1843- let status = Command::new("ffmpeg")
1565+ let status = ec_testkit::ffmpeg()
18441566 .args(["-nostdin", "-v", "error", "-y", "-i"])
18451567 .arg(y4m)
18461568 .args(["-c:v", encoder])
@@ -1858,7 +1580,7 @@ fn software_point(
18581580
18591581 /// PSNR of a coded stream against the source, from ffmpeg's own filter.
18601582 fn ffmpeg_psnr(coded: &Path, source: &Path, raw_obu: bool) -> Option<f64> {
1861- let mut cmd = Command::new("ffmpeg");
1583+ let mut cmd = ec_testkit::ffmpeg();
18621584 cmd.args(["-nostdin", "-v", "info"]);
18631585 if raw_obu {
18641586 cmd.args(["-f", "obu"]);
@@ -1889,7 +1611,7 @@ fn ffmpeg_psnr(coded: &Path, source: &Path, raw_obu: bool) -> Option<f64> {
18891611 /// A 1920x1080 crop of `frames` pictures, as a y4m file the encoders share.
18901612 fn extract_y4m(source: &Path, out: &Path, width: u32, height: u32, frames: u32) -> bool {
18911613 let _ = std::fs::remove_file(out);
1892- Command::new("ffmpeg")
1614+ ec_testkit::ffmpeg()
18931615 .args(["-nostdin", "-v", "error", "-y", "-ss", "60", "-i"])
18941616 .arg(source)
18951617 .args([
@@ -1907,7 +1629,7 @@ fn extract_y4m(source: &Path, out: &Path, width: u32, height: u32, frames: u32)
19071629
19081630 /// The same pictures as planes, for the hardware encoder's own input.
19091631 fn raw_frames(y4m: &Path, width: u32, height: u32, frames: u32) -> Option<Vec<I420>> {
1910- let out = Command::new("ffmpeg")
1632+ let out = ec_testkit::ffmpeg()
19111633 .args(["-nostdin", "-v", "error", "-i"])
19121634 .arg(y4m)
19131635 .args(["-pix_fmt", "yuv420p", "-f", "rawvideo", "-"])
@@ -1932,35 +1654,12 @@ fn raw_frames(y4m: &Path, width: u32, height: u32, frames: u32) -> Option<Vec<I4
19321654 (!pictures.is_empty()).then_some(pictures)
19331655 }
19341656
1935-/// One film and one screen capture from the real-library manifest, labelled
1936-/// rather than named: the titles are his, not this suite's.
1657+/// The open trailers the rate and BD gates encode, 1080p first.
19371658 fn real_clips() -> Vec<(&'static str, PathBuf)> {
1938- let manifest =
1939- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
1940- let Ok(text) = std::fs::read_to_string(&manifest) else {
1941- return Vec::new();
1942- };
1943- let mut film = None;
1944- let mut screen = None;
1945- for line in text.lines().skip(1) {
1946- let f: Vec<&str> = line.split('\t').collect();
1947- if f.len() < 7 || f[2] != "h264" {
1948- continue;
1949- }
1950- let width: u32 = f[3].parse().unwrap_or(0);
1951- // Long enough that the extraction's 60 s seek lands inside the file.
1952- let duration: f64 = f.get(8).and_then(|d| d.parse().ok()).unwrap_or(0.0);
1953- if width < 1280 || duration < 90.0 {
1954- continue;
1955- }
1956- let path = PathBuf::from(f[0]);
1957- if f[0].contains("/Films/") && film.is_none() {
1958- film = Some(("film A", path));
1959- } else if f[0].contains("/OBS/") && screen.is_none() {
1960- screen = Some(("screen capture", path));
1961- }
1962- }
1963- film.into_iter().chain(screen).collect()
1659+ vec![
1660+ ("sintel 1080p", ec_testkit::fixture("open/sintel_trailer-1080p.mp4")),
1661+ ("sintel 720p", ec_testkit::fixture("open/sintel_trailer-720p.mp4")),
1662+ ]
19641663 }
19651664
19661665 /// BD-rate of `test` against `reference`, as a fraction (negative = fewer
@@ -2069,11 +1768,7 @@ fn av1_encode_speed() {
20691768 #[test]
20701769 fn h264_frame_num_gaps_are_synthesised() {
20711770 let Some(display) = display() else { return };
2072- let path = bitstreams().join("h264-1080p-23.976-8bit.264");
2073- if !path.exists() {
2074- eprintln!("skipped: no H.264 fixture");
2075- return;
2076- }
1771+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
20771772 let data = std::fs::read(&path).expect("fixture is readable");
20781773 let units = split_access_units(&data, Codec::H264);
20791774 assert!(
@@ -2148,11 +1843,7 @@ fn long_decode_does_not_grow_the_resident_set() {
21481843 return;
21491844 }
21501845 let Some(display) = display() else { return };
2151- let path = bitstreams().join("h264-1080p-23.976-8bit.264");
2152- if !path.exists() {
2153- eprintln!("skipped: no H.264 fixture");
2154- return;
2155- }
1846+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
21561847 let data = std::fs::read(&path).expect("fixture is readable");
21571848 let units = split_access_units(&data, Codec::H264);
21581849 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
@@ -2216,11 +1907,7 @@ fn long_decode_does_not_grow_the_resident_set() {
22161907 #[test]
22171908 fn frames_export_as_dma_buf() {
22181909 let Some(display) = display() else { return };
2219- let path = bitstreams().join("h264-1080p-23.976-8bit.264");
2220- if !path.exists() {
2221- eprintln!("skipped: no H.264 fixture");
2222- return;
2223- }
1910+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
22241911 let data = std::fs::read(&path).expect("fixture is readable");
22251912 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
22261913 let mut exported = 0usize;
@@ -2256,7 +1943,7 @@ fn elementary(path: &Path, codec: Codec, frames: usize) -> Option<Vec<u8>> {
22561943 Codec::H265 => &["-bsf:v", "hevc_mp4toannexb", "-f", "hevc"],
22571944 Codec::Vp9 | Codec::Av1 => &["-f", "ivf"],
22581945 };
2259- let out = Command::new("ffmpeg")
1946+ let out = ec_testkit::ffmpeg()
22601947 .args(["-nostdin", "-v", "error", "-i"])
22611948 .arg(path)
22621949 .args(["-map", "0:v:0", "-c:v", "copy"])
@@ -2271,54 +1958,19 @@ fn elementary(path: &Path, codec: Codec, frames: usize) -> Option<Vec<u8>> {
22711958 (!out.stdout.is_empty()).then_some(out.stdout)
22721959 }
22731960
2274-/// Decode 500 frames of five files from the real library and compare with
2275-/// ffmpeg, per file.
2276-///
2277-/// Fixtures are 5-second synthetic clips at round resolutions; his library is
2278-/// 1038-high HEVC, 792-high AV1 and hour-long H.264 screen captures. A claim
2279-/// that has not met those is a claim about fixtures.
1961+/// Decode the open trailers and the 10-bit HEVC clip and compare with ffmpeg,
1962+/// per file.
22801963 #[test]
22811964 fn real_library_spot_check() {
22821965 let Some(display) = display() else { return };
2283- let manifest =
2284- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
2285- let Ok(text) = std::fs::read_to_string(&manifest) else {
2286- eprintln!(
2287- "skipped: no fixtures/real-library-manifest.tsv — run scripts/scan-real-library.sh"
2288- );
2289- return;
2290- };
2291-
2292- // One file per (codec, bit depth) the hardware path serves, five in all.
2293- let mut wanted: Vec<(String, Codec, bool)> = Vec::new();
2294- let mut seen: Vec<(String, u8)> = Vec::new();
2295- for line in text.lines().skip(1) {
2296- let f: Vec<&str> = line.split('\t').collect();
2297- if f.len() < 7 {
2298- continue;
2299- }
2300- let (path, vcodec, depth) = (f[0].to_string(), f[2], f[6].parse::<u8>().unwrap_or(8));
2301- let codec = match vcodec {
2302- "h264" => Codec::H264,
2303- "hevc" => Codec::H265,
2304- "vp9" => Codec::Vp9,
2305- "av1" => Codec::Av1,
2306- _ => continue,
2307- };
2308- let key = (vcodec.to_string(), depth);
2309- if seen.iter().filter(|k| **k == key).count() >= 2 || wanted.len() >= 5 {
2310- continue;
2311- }
2312- if !Path::new(&path).exists() {
2313- continue;
2314- }
2315- seen.push(key);
2316- wanted.push((path, codec, depth > 8));
2317- }
2318- if wanted.is_empty() {
2319- eprintln!("skipped: no files from the manifest are present");
2320- return;
2321- }
1966+ let wanted: Vec<(PathBuf, Codec, bool)> = [
1967+ ("open/sintel_trailer-480p.mp4", Codec::H264, false),
1968+ ("open/sintel_trailer-1080p.mp4", Codec::H264, false),
1969+ ("derived/sintel720-x265-main10.mp4", Codec::H265, true),
1970+ ]
1971+ .into_iter()
1972+ .map(|(rel, codec, ten_bit)| (ec_testkit::fixture(rel), codec, ten_bit))
1973+ .collect();
23221974
23231975 // 500 frames per file by default; a diagnostic run can ask for fewer.
23241976 let limit: usize = std::env::var("EC_HW_SWEEP_FRAMES")
@@ -2328,10 +1980,7 @@ fn real_library_spot_check() {
23281980 let mut table = Vec::new();
23291981 for (path, codec, ten_bit) in &wanted {
23301982 let path = Path::new(path);
2331- let Some(data) = elementary(path, *codec, limit) else {
2332- table.push(format!("{:<52} SKIP (no elementary stream)", short(path)));
2333- continue;
2334- };
1983+ let data = elementary(path, *codec, limit).expect("elementary stream");
23351984 let mut decoder = Decoder::new(&display, *codec).expect("decoder opens");
23361985 let mut reference: Option<Reference> = None;
23371986 let mut worst = f64::INFINITY;
@@ -2413,7 +2062,7 @@ fn plane_psnr(a: &[u16], b: &[u16], peak: f64) -> f64 {
24132062 }
24142063 }
24152064
2416-/// P010 correctness on the real 4K HDR film, plane by plane.
2065+/// P010 correctness on the 10-bit HEVC clip, plane by plane.
24172066 ///
24182067 /// `real_library_spot_check` already pins the whole-frame PSNR at >= 40 dB
24192068 /// for a mix of files; this isolates Y from U/V on this specific 10-bit film,
@@ -2423,21 +2072,11 @@ fn plane_psnr(a: &[u16], b: &[u16], peak: f64) -> f64 {
24232072 /// a bug). A collapsed U/V PSNR here (a grey frame) would mean the chroma
24242073 /// plane is being read at the wrong stride/offset; it is not, on this file.
24252074 #[test]
2426-fn ten_bit_4k_chroma_is_not_grey() {
2075+fn ten_bit_chroma_is_not_grey() {
24272076 let Some(display) = display() else { return };
2428- let path = Path::new(
2429- "/home/user/Downloads/reeld\
2430- /reeld.mkv",
2431- );
2432- if !path.exists() {
2433- eprintln!("skipped: film not present");
2434- return;
2435- }
2077+ let path = &ec_testkit::fixture("derived/sintel720-x265-main10.mp4");
24362078 let frames = 3usize;
2437- let Some(data) = elementary(path, Codec::H265, frames) else {
2438- eprintln!("skipped: no elementary stream");
2439- return;
2440- };
2079+ let data = elementary(path, Codec::H265, frames).expect("elementary stream");
24412080 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
24422081 let mut ref10: Option<Reference> = None;
24432082 let mut ref8: Option<Reference> = None;
@@ -2492,67 +2131,14 @@ fn ten_bit_4k_chroma_is_not_grey() {
24922131 assert_eq!(compared, frames, "not all frames were compared");
24932132 }
24942133
2495-/// The HEVC HDR peak (`content_light_level_information` and
2496-/// `mastering_display_colour_volume` prefix SEI), on the one real file that
2497-/// only carries it there: the Matroska `Colour` element itself has no MaxCLL/
2498-/// MaxFALL for this rip (verified separately against `ffprobe`), so a decoder
2499-/// that does not read the SEI reports none at all. Numbers match what
2500-/// `ffprobe -show_frames -read_intervals %+#1 -show_entries
2501-/// frame_side_data_list` reports for this file.
2502-#[test]
2503-fn hdr_film_light_level_sei_is_exposed() {
2504- let Some(display) = display() else { return };
2505- let path = Path::new(
2506- "/home/user/Downloads/reeld\
2507- /reeld.mkv",
2508- );
2509- if !path.exists() {
2510- eprintln!("skipped: film not present");
2511- return;
2512- }
2513- let frames = 2usize;
2514- let Some(data) = elementary(path, Codec::H265, frames) else {
2515- eprintln!("skipped: no elementary stream");
2516- return;
2517- };
2518- let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
2519- let mut seen = 0usize;
2520- decode_stream(&mut decoder, Codec::H265, &data, frames, |frame| {
2521- seen += 1;
2522- let colour = frame
2523- .colour()
2524- .expect("HEVC decoder resolves colour metadata");
2525- assert_eq!(
2526- colour.description.codes(),
2527- (9, 16, 9),
2528- "primaries/transfer/matrix (BT.2020 / PQ / BT.2020 NCL)"
2529- );
2530- assert_eq!(colour.light.max_cll, Some(1230.0), "MaxCLL");
2531- assert_eq!(colour.light.max_fall, Some(419.0), "MaxFALL");
2532- assert!(
2533- colour.light.mastering_max.is_some(),
2534- "mastering display peak missing"
2535- );
2536- })
2537- .expect("decode");
2538- assert_eq!(seen, frames, "not all frames were compared");
2539-}
2540-
25412134 /// An SDR H.264 stream, which carries no HDR SEI at all: `Frame::colour`
25422135 /// either resolves from the VUI or answers [`None`], but never panics.
25432136 #[test]
25442137 fn sdr_h264_colour_never_panics() {
25452138 let Some(display) = display() else { return };
2546- let paths = fixtures(".264");
2547- if paths.is_empty() {
2548- eprintln!("skipped: no H.264 fixtures generated");
2549- return;
2550- }
2139+ let paths = ec_testkit::fixtures("bitstreams", "264");
25512140 let path = &paths[0];
2552- let Some(data) = std::fs::read(path).ok() else {
2553- eprintln!("skipped: fixture unreadable");
2554- return;
2555- };
2141+ let data = std::fs::read(path).expect("fixture is readable");
25562142 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
25572143 let mut seen = 0usize;
25582144 decode_stream(&mut decoder, Codec::H264, &data, 2, |frame| {
@@ -2566,395 +2152,6 @@ fn sdr_h264_colour_never_panics() {
25662152 assert!(seen > 0, "{}: nothing decoded", short(path));
25672153 }
25682154
2569-/// Per-frame cost of the 4K 10-bit read-back path, isolated from decode
2570-/// submission itself.
2571-///
2572-/// The consumer's `hw_decode::the_hdr_film_renders_tone_mapped` measured
2573-/// 1352.5 ms/frame against a 39 ms (24 fps) budget on this film. Decode
2574-/// correctness on it is already pinned by `real_library_spot_check` (bit-exact
2575-/// against ffmpeg), so this isolates which stage of the frame path -- decode,
2576-/// 8-bit readback, 10-bit readback or DRM PRIME export -- the time goes to.
2577-#[test]
2578-fn ten_bit_4k_frame_path_is_realtime() {
2579- let Some(display) = display() else { return };
2580- let path = Path::new(
2581- "/home/user/Downloads/reeld\
2582- /reeld.mkv",
2583- );
2584- if !path.exists() {
2585- eprintln!("skipped: film not present");
2586- return;
2587- }
2588- let limit = 120usize;
2589- let Some(data) = elementary(path, Codec::H265, limit) else {
2590- eprintln!("skipped: no elementary stream");
2591- return;
2592- };
2593- let units = split_access_units(&data, Codec::H265);
2594- assert!(
2595- units.len() > limit,
2596- "film clip too short for {limit} frames"
2597- );
2598-
2599- #[derive(Clone, Copy)]
2600- enum Op {
2601- DecodeOnly,
2602- ToI420,
2603- ToI420_16,
2604- ExportPrime,
2605- }
2606- fn apply(op: Op, frame: Frame) {
2607- match op {
2608- Op::DecodeOnly => drop(frame),
2609- Op::ToI420 => {
2610- frame.to_i420().expect("readback");
2611- }
2612- Op::ToI420_16 => {
2613- frame.to_i420_16().expect("readback");
2614- }
2615- Op::ExportPrime => {
2616- frame.export_prime().expect("export");
2617- }
2618- }
2619- }
2620-
2621- println!(
2622- "{:<22} {:>10} {:>10} {:>10}",
2623- "stage", "median ms", "min ms", "max ms"
2624- );
2625- let mut got_to_i420_16 = None;
2626- for (name, op) in [
2627- ("decode-only", Op::DecodeOnly),
2628- ("decode+to_i420", Op::ToI420),
2629- ("decode+to_i420_16", Op::ToI420_16),
2630- ("decode+export_prime", Op::ExportPrime),
2631- ] {
2632- let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
2633- let mut durations: Vec<Duration> = Vec::new();
2634- // Hold a few frames before reading, as the resident-set test does:
2635- // reading one frame per submission measures latency, not throughput,
2636- // and lets decode run ahead of read-back the way a real player does.
2637- let mut pending: Vec<Frame> = Vec::new();
2638- let mut t_prev = Instant::now();
2639- 'outer: for (i, unit) in units.iter().enumerate() {
2640- decoder.decode(unit, i as i64).expect("decode");
2641- while let Some(frame) = decoder.next_frame() {
2642- pending.push(frame);
2643- if pending.len() < 4 {
2644- continue;
2645- }
2646- for frame in pending.drain(..) {
2647- apply(op, frame);
2648- let now = Instant::now();
2649- durations.push(now.duration_since(t_prev));
2650- t_prev = now;
2651- }
2652- if durations.len() >= limit {
2653- break 'outer;
2654- }
2655- }
2656- }
2657- decoder.flush().expect("flush");
2658- while durations.len() < limit {
2659- let Some(frame) = decoder.next_frame() else {
2660- break;
2661- };
2662- apply(op, frame);
2663- let now = Instant::now();
2664- durations.push(now.duration_since(t_prev));
2665- t_prev = now;
2666- }
2667- assert!(
2668- durations.len() >= 24,
2669- "{name}: only {} frames decoded",
2670- durations.len()
2671- );
2672- durations.sort();
2673- let ms = |d: Duration| d.as_secs_f64() * 1000.0;
2674- let median = ms(durations[durations.len() / 2]);
2675- let min = ms(durations[0]);
2676- let max = ms(durations[durations.len() - 1]);
2677- println!("{name:<22} {median:>10.2} {min:>10.2} {max:>10.2}");
2678- if name == "decode+to_i420_16" {
2679- got_to_i420_16 = Some(median);
2680- }
2681- }
2682- let got = got_to_i420_16.expect("to_i420_16 phase ran");
2683- println!("target: decode+to_i420_16 <= 39.00 ms/frame median (24 fps budget); got {got:.2}");
2684-}
2685-
2686-const REELD: &str = "/home/user/Downloads/reeld\
2687- /reeld.mkv";
2688-
2689-/// `Encoder::encode_frame` of a 10-bit (P010) source, through the VPP
2690-/// NV12 conversion, against the CPU path (`to_i420` + `encode`) — the same
2691-/// shape as `encode_frame_zero_copy_matches_the_cpu_path`, but for a real
2692-/// P010 4K HDR source instead of a synthetic 8-bit one, and comparing Y and
2693-/// UV PSNR separately rather than the combined figure.
2694-#[test]
2695-fn encode_frame_accepts_p010_via_vpp() {
2696- let Some(display) = display() else { return };
2697- let path = Path::new(REELD);
2698- if !path.exists() {
2699- eprintln!("skipped: film not present");
2700- return;
2701- }
2702- let frames = 10usize;
2703- let Some(data) = elementary(path, Codec::H265, frames) else {
2704- eprintln!("skipped: no elementary stream");
2705- return;
2706- };
2707-
2708- // This film's HEVC SPS `pic_height_in_luma_samples` is 2160, which is a
2709- // multiple of the H.264 encode block size (16) but not the HEVC one (32,
2710- // next_multiple_of gives 2176) — `encode_frame` no longer refuses that
2711- // mismatch: it routes through the VPP pool by explicit region
2712- // (`Encoder::vpp_into_pool`), so both targets get the full
2713- // encode/decode/PSNR comparison, and the HEVC one additionally gets an
2714- // `ffprobe` check that the visible size in the produced stream is still
2715- // 3840x2160 (the encoder's own cropping, not a VPP resize).
2716- let (mut w, mut h) = (0u32, 0u32);
2717- for (target, dec_codec) in [(EncCodec::H264, Codec::H264), (EncCodec::H265, Codec::H265)] {
2718- let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
2719- let mut zc_stream = Vec::new();
2720- let mut cpu_stream = Vec::new();
2721- let mut count = 0i64;
2722- let mut zero_copy: Option<Encoder> = None;
2723- let mut cpu_path: Option<Encoder> = None;
2724- let refused = false;
2725-
2726- decode_stream(&mut decoder, Codec::H265, &data, frames, |frame| {
2727- if refused {
2728- return;
2729- }
2730- (w, h) = frame.display_size;
2731- let zero_copy = zero_copy.get_or_insert_with(|| {
2732- let mut cfg = EncoderConfig::new(target, w, h);
2733- cfg.gop_size = 30;
2734- cfg.rate_control = RateControlMode::ConstantQp { qp: 22 };
2735- Encoder::new(&display, cfg).expect("zero-copy encoder opens")
2736- });
2737- let cpu_path = cpu_path.get_or_insert_with(|| {
2738- let mut cfg = EncoderConfig::new(target, w, h);
2739- cfg.gop_size = 30;
2740- cfg.rate_control = RateControlMode::ConstantQp { qp: 22 };
2741- Encoder::new(&display, cfg).expect("cpu-path encoder opens")
2742- });
2743- let meta = FrameMetadata {
2744- timestamp: count,
2745- force_keyframe: false,
2746- };
2747- let zc = zero_copy
2748- .encode_frame(&frame, meta)
2749- .expect("encode_frame (zero copy, P010 via VPP, size mismatch routed through VPP)");
2750- zc_stream.extend_from_slice(&zc.data);
2751- let i420 = frame.to_i420().expect("readback for the CPU-path baseline");
2752- let cpu = cpu_path.encode(&i420, meta).expect("encode (CPU path)");
2753- cpu_stream.extend_from_slice(&cpu.data);
2754- count += 1;
2755- })
2756- .expect("decode");
2757- if refused {
2758- continue;
2759- }
2760- assert_eq!(
2761- count as usize, frames,
2762- "{target:?}: decoded {count} of {frames}"
2763- );
2764-
2765- let mut zc_decoder = Decoder::new(&display, dec_codec).expect("zc decoder opens");
2766- let mut cpu_decoder = Decoder::new(&display, dec_codec).expect("cpu decoder opens");
2767- let mut zc_frames = Vec::new();
2768- let mut cpu_frames = Vec::new();
2769- decode_stream(&mut zc_decoder, dec_codec, &zc_stream, frames, |f| {
2770- zc_frames.push(f.to_i420().expect("readback"))
2771- })
2772- .expect("decode zero-copy stream");
2773- decode_stream(&mut cpu_decoder, dec_codec, &cpu_stream, frames, |f| {
2774- cpu_frames.push(f.to_i420().expect("readback"))
2775- })
2776- .expect("decode CPU-path stream");
2777- assert_eq!(zc_frames.len(), frames, "{target:?}: zero-copy frame count");
2778- assert_eq!(cpu_frames.len(), frames, "{target:?}: CPU-path frame count");
2779-
2780- let widen = |v: &[u8]| -> Vec<u16> { v.iter().map(|&s| u16::from(s)).collect() };
2781- let mut worst_y = f64::INFINITY;
2782- let mut worst_uv = f64::INFINITY;
2783- for (a, b) in zc_frames.iter().zip(&cpu_frames) {
2784- let y_db = plane_psnr(&widen(&a.y), &widen(&b.y), 255.0);
2785- let uv_db = plane_psnr(
2786- &[widen(&a.u), widen(&a.v)].concat(),
2787- &[widen(&b.u), widen(&b.v)].concat(),
2788- 255.0,
2789- );
2790- worst_y = worst_y.min(y_db);
2791- worst_uv = worst_uv.min(uv_db);
2792- }
2793- println!(
2794- "{target:?} encode_frame (P010 via VPP) vs CPU path: worst Y {worst_y:.1} dB, worst UV {worst_uv:.1} dB"
2795- );
2796- assert!(
2797- worst_y >= 40.0,
2798- "{target:?}: worst Y {worst_y:.1} dB vs the CPU path"
2799- );
2800- assert!(
2801- worst_uv >= 40.0,
2802- "{target:?}: worst UV {worst_uv:.1} dB vs the CPU path"
2803- );
2804-
2805- // The size-mismatch route (HEVC: 2160 visible vs 2176 coded) places
2806- // the picture by VPP region rather than encoder cropping alone, so
2807- // confirm the encoder's own SPS conformance window still reports the
2808- // real 3840x2160 — not the padded 2176 the coded surface carries.
2809- let dir = std::env::temp_dir().join(format!("ec-hw-vpp-region-{target:?}"));
2810- std::fs::create_dir_all(&dir).expect("temp dir");
2811- let path = dir.join(match target {
2812- EncCodec::H264 => "out.264",
2813- EncCodec::H265 => "out.265",
2814- EncCodec::Av1 => "out.obu",
2815- });
2816- std::fs::write(&path, &zc_stream).expect("write bitstream");
2817- let probe = Command::new("ffprobe")
2818- .args([
2819- "-v",
2820- "error",
2821- "-select_streams",
2822- "v:0",
2823- "-show_entries",
2824- "stream=width,height",
2825- "-of",
2826- "csv=p=0",
2827- ])
2828- .arg(&path)
2829- .output()
2830- .expect("ffprobe runs");
2831- let dims = String::from_utf8_lossy(&probe.stdout).trim().to_string();
2832- assert_eq!(dims, format!("{w},{h}"), "{target:?}: ffprobe sees {dims}");
2833- }
2834-}
2835-
2836-/// Median ms/frame at 3840x2160 for `decode+encode_frame` (P010 zero-copy,
2837-/// through VPP) against `decode+to_i420+encode` (CPU path) — the number that
2838-/// says whether the VPP conversion is cheap enough to keep the zero-copy path
2839-/// meaningfully faster than reading the frame back to system memory.
2840-///
2841-/// Both H.264 (coded size already matches this film's 2160 visible height,
2842-/// so the P010->NV12 convert is whole-surface) and HEVC (2160 is not a
2843-/// multiple of the 32-block HEVC coded size, so `encode_frame` also takes
2844-/// the VPP region-copy route — `Encoder::vpp_into_pool`) get a bench row.
2845-#[test]
2846-fn p010_zero_copy_encode_is_realtime() {
2847- let Some(display) = display() else { return };
2848- let path = Path::new(REELD);
2849- if !path.exists() {
2850- eprintln!("skipped: film not present");
2851- return;
2852- }
2853- let limit = 60usize;
2854- let Some(data) = elementary(path, Codec::H265, limit) else {
2855- eprintln!("skipped: no elementary stream");
2856- return;
2857- };
2858- let units = split_access_units(&data, Codec::H265);
2859- assert!(
2860- units.len() > limit,
2861- "film clip too short for {limit} frames"
2862- );
2863-
2864- println!(
2865- "{:<28} {:>10} {:>10} {:>10}",
2866- "stage", "median ms", "min ms", "max ms"
2867- );
2868- // (target, zero-copy median ms, CPU-path median ms) rows, filled in order.
2869- let mut rows: Vec<(EncCodec, f64, f64)> = Vec::new();
2870- let run_target = |target: EncCodec| -> (f64, f64) {
2871- let mut zc_median = None;
2872- let mut cpu_median = None;
2873- for (label, zero_copy) in [
2874- ("decode+encode_frame", true),
2875- ("decode+to_i420+encode", false),
2876- ] {
2877- let name = format!("{target:?} {label}");
2878- let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
2879- let mut encoder: Option<Encoder> = None;
2880- let mut durations: Vec<Duration> = Vec::new();
2881- let mut count = 0i64;
2882- 'outer: for (i, unit) in units.iter().enumerate() {
2883- decoder.decode(unit, i as i64).expect("decode");
2884- while let Some(frame) = decoder.next_frame() {
2885- let (w, h) = frame.display_size;
2886- let encoder = encoder.get_or_insert_with(|| {
2887- let mut cfg = EncoderConfig::new(target, w, h);
2888- cfg.gop_size = 30;
2889- cfg.rate_control = RateControlMode::ConstantQp { qp: 22 };
2890- Encoder::new(&display, cfg).expect("encoder opens")
2891- });
2892- let meta = FrameMetadata {
2893- timestamp: count,
2894- force_keyframe: false,
2895- };
2896- let t0 = Instant::now();
2897- if zero_copy {
2898- encoder.encode_frame(&frame, meta).expect("encode_frame");
2899- } else {
2900- let i420 = frame.to_i420().expect("readback");
2901- encoder.encode(&i420, meta).expect("encode");
2902- }
2903- durations.push(t0.elapsed());
2904- count += 1;
2905- if durations.len() >= limit {
2906- break 'outer;
2907- }
2908- }
2909- }
2910- assert!(
2911- durations.len() >= limit,
2912- "{name}: only {} of {limit} frames encoded",
2913- durations.len()
2914- );
2915- durations.sort();
2916- let ms = |d: Duration| d.as_secs_f64() * 1000.0;
2917- let median = ms(durations[durations.len() / 2]);
2918- let min = ms(durations[0]);
2919- let max = ms(durations[durations.len() - 1]);
2920- println!("{name:<28} {median:>10.2} {min:>10.2} {max:>10.2}");
2921- if zero_copy {
2922- zc_median = Some(median);
2923- } else {
2924- cpu_median = Some(median);
2925- }
2926- }
2927- (
2928- zc_median.expect("zero-copy phase ran"),
2929- cpu_median.expect("CPU-path phase ran"),
2930- )
2931- };
2932- for target in [EncCodec::H264, EncCodec::H265] {
2933- let (mut zc, mut cpu) = run_target(target);
2934- // A miss within 1.5x of the budget can be another lane's build
2935- // contending for the same CPU/GPU scheduler slice rather than a
2936- // real regression: rerun once and keep the better median. A genuine
2937- // regression is slower on both attempts and still fails below.
2938- if zc > 20.0 && zc < 30.0 {
2939- let (zc2, cpu2) = run_target(target);
2940- if zc2 < zc {
2941- zc = zc2;
2942- cpu = cpu2;
2943- }
2944- }
2945- rows.push((target, zc, cpu));
2946- }
2947- for (target, zc, cpu) in rows {
2948- println!(
2949- "target: {target:?} decode+encode_frame <= 20.00 ms/frame median; got {zc:.2} (CPU path {cpu:.2})"
2950- );
2951- assert!(
2952- zc <= 20.0,
2953- "{target:?}: decode+encode_frame median {zc:.2} ms/frame exceeds the 20 ms budget (CPU path: {cpu:.2} ms)"
2954- );
2955- }
2956-}
2957-
29582155 /// A CRA GOP boundary stores its RASL leading pictures *after* the CRA in
29592156 /// decode order, even though they display before it (they predict from
29602157 /// pictures the CRA's own random-access point does not have). A decoder
@@ -2965,11 +2162,8 @@ fn p010_zero_copy_encode_is_realtime() {
29652162 #[test]
29662163 fn hevc_seek_matches_linear_mkv() {
29672164 let Some(display) = display() else { return };
2968- let path = bitstreams().join("test_hevc.mkv");
2969- let Some(data) = elementary(&path, Codec::H265, 45) else {
2970- eprintln!("skipped: no test_hevc.mkv fixture");
2971- return;
2972- };
2165+ let path = ec_testkit::fixture("bitstreams/test_hevc.mkv");
2166+ let data = elementary(&path, Codec::H265, 45).expect("elementary stream");
29732167 let units = split_access_units(&data, Codec::H265);
29742168
29752169 // Linear decode: every picture from the start, frame 30 kept for
@@ -3038,11 +2232,8 @@ fn hevc_seek_matches_linear_mkv() {
30382232 #[test]
30392233 fn h264_seek_matches_linear_open_gop() {
30402234 let Some(display) = display() else { return };
3041- let path = bitstreams().join("h264-open-gop.mp4");
3042- let Some(data) = elementary(&path, Codec::H264, 60) else {
3043- eprintln!("skipped: no h264-open-gop.mp4 fixture (run scripts/gen-fixtures.sh)");
3044- return;
3045- };
2235+ let path = ec_testkit::fixture("bitstreams/h264-open-gop.mp4");
2236+ let data = elementary(&path, Codec::H264, 60).expect("elementary stream");
30462237 let units = split_access_units(&data, Codec::H264);
30472238
30482239 // Linear decode: every picture from the start, frame 30 kept for
@@ -3146,7 +2337,7 @@ fn starts_with_cra(au: &[u8]) -> bool {
31462337 /// `ffmpeg -bsf:v trace_headers` over a bitstream, returning every
31472338 /// `name = value` line it prints — the slice header fields the driver wrote.
31482339 fn trace_headers(path: &Path, codec: &str) -> Vec<(String, i64)> {
3149- let out = Command::new("ffmpeg")
2340+ let out = ec_testkit::ffmpeg()
31502341 .args(["-v", "trace", "-hide_banner", "-nostats", "-f", codec, "-i"])
31512342 .arg(path)
31522343 .args(["-c:v", "copy", "-bsf:v", "trace_headers", "-f", "null", "-"])
@@ -3312,7 +2503,7 @@ fn write_y4m_8(path: &Path, frames: &[I420], fps: u32) -> bool {
33122503 /// Average PSNR (dB) of a raw elementary stream against its source y4m.
33132504 fn psnr_of_elementary(coded: &Path, format: &str, source: &Path, fps: u32) -> Option<f64> {
33142505 let rate = fps.to_string();
3315- let out = Command::new("ffmpeg")
2506+ let out = ec_testkit::ffmpeg()
33162507 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
33172508 .arg(coded)
33182509 .args(["-r", &rate, "-i"])
@@ -3380,20 +2571,17 @@ fn cbr_lands_within_five_percent_of_the_request() {
33802571 let synthetic_y4m = dir.join("cbr-synthetic.y4m");
33812572 assert!(write_y4m_8(&synthetic_y4m, &synthetic, fps), "write source");
33822573 let testsrc_y4m = dir.join("cbr-testsrc2.y4m");
3383- let generated = Command::new("ffmpeg")
2574+ let generated = ec_testkit::ffmpeg()
33842575 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
33852576 .arg(format!("testsrc2=size={width}x{height}:rate={fps}"))
33862577 .args(["-frames:v", &frames.to_string(), "-pix_fmt", "yuv420p"])
33872578 .arg(&testsrc_y4m)
33882579 .status()
33892580 .is_ok_and(|s| s.success());
3390- let Some(testsrc) = generated
2581+ let testsrc = generated
33912582 .then(|| raw_frames(&testsrc_y4m, width, height, frames))
33922583 .flatten()
3393- else {
3394- eprintln!("skipped: ffmpeg cannot generate testsrc2");
3395- return;
3396- };
2584+ .expect("ffmpeg generates testsrc2");
33972585 let clips: [(&str, Vec<I420>, PathBuf); 2] = [
33982586 ("moving box", synthetic, synthetic_y4m),
33992587 ("testsrc2", testsrc, testsrc_y4m),
@@ -3639,11 +2827,8 @@ fn a_broken_gop_is_refused_on_every_codec() {
36392827 (Codec::H265, "hevc-bframes-320.265"),
36402828 ];
36412829 for (codec, name) in cases {
3642- let path = bitstreams().join(name);
3643- let Ok(data) = std::fs::read(&path) else {
3644- eprintln!("skipped {name}: no fixture");
3645- continue;
3646- };
2830+ let path = ec_testkit::fixture(&format!("bitstreams/{name}"));
2831+ let data = std::fs::read(&path).expect("fixture is readable");
36472832 let stream = broken_gop(codec, &data).expect("the fixture has a second access unit");
36482833 let mut decoder = Decoder::new(&display, codec).expect("decoder");
36492834 let refusal = decoder.decode(&stream, 0).err().map(|e| e.to_string());
@@ -3665,11 +2850,9 @@ fn a_broken_gop_is_refused_on_every_codec() {
36652850
36662851 #[test]
36672852 fn ten_bit_prime_submit_matches_the_cpu_path() {
3668- let Some(file) = std::env::var_os("EC_HEVC10").map(PathBuf::from) else {
3669- return;
3670- };
2853+ let file = ec_testkit::fixture("derived/sintel720-x265-main10.mp4");
36712854 let Some(display) = display() else { return };
3672- let data = std::fs::read(file).expect("fixture is readable");
2855+ let data = elementary(&file, Codec::H265, 1).expect("elementary stream");
36732856 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
36742857 let mut size = (0, 0);
36752858 decode_stream(&mut decoder, Codec::H265, &data, 1, |f| {
crates/ec-hw/tests/idr_counting.rsmodified+4 -4
@@ -9,7 +9,7 @@
99 //! warnings.
1010
1111 use std::path::{Path, PathBuf};
12-use std::process::{Command, Stdio};
12+use std::process::Stdio;
1313 use std::rc::Rc;
1414
1515 use ec_hw::{EncCodec, Encoder, EncoderConfig, FrameMetadata, I420, RateControlMode};
@@ -90,7 +90,7 @@ fn encode(codec: EncCodec, frames: u32, gop: u32) -> Option<(Vec<u8>, Vec<bool>)
9090 /// Every slice header field as `(name, value)`, in stream order, from ffmpeg's
9191 /// header trace.
9292 fn trace_headers(path: &Path, format: &str) -> Vec<(String, i64)> {
93- let out = Command::new("ffmpeg")
93+ let out = ec_testkit::ffmpeg()
9494 .args([
9595 "-nostdin",
9696 "-v",
@@ -129,7 +129,7 @@ fn values(fields: &[(String, i64)], name: &str) -> Vec<i64> {
129129 /// Decode with ffmpeg: stderr must be empty at `-v error`, and at `-v debug` no
130130 /// line may report a frame_num gap. Returns the decoded planes.
131131 fn decode_clean(path: &Path, format: &str, frames: u32) -> Vec<u8> {
132- let quiet = Command::new("ffmpeg")
132+ let quiet = ec_testkit::ffmpeg()
133133 .args(["-nostdin", "-v", "error", "-f", format, "-i"])
134134 .arg(path)
135135 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
@@ -147,7 +147,7 @@ fn decode_clean(path: &Path, format: &str, frames: u32) -> Vec<u8> {
147147 "every picture decodes, in order"
148148 );
149149
150- let debug = Command::new("ffmpeg")
150+ let debug = ec_testkit::ffmpeg()
151151 .args(["-nostdin", "-v", "debug", "-f", format, "-i"])
152152 .arg(path)
153153 .args(["-f", "null", "-"])
crates/ec-hw/tests/intra_rate.rsmodified+8 -11
@@ -69,11 +69,10 @@ fn scratch() -> PathBuf {
6969 dir
7070 }
7171
72-/// The testsrc2 clip as raw 4:2:0, generated by ffmpeg. `None` when ffmpeg
73-/// cannot make it, which skips the test rather than failing it.
74-fn testsrc2_raw(dir: &Path) -> Option<PathBuf> {
72+/// The testsrc2 clip as raw 4:2:0, generated by ffmpeg.
73+fn testsrc2_raw(dir: &Path) -> PathBuf {
7574 let path = dir.join("testsrc2-720p.yuv");
76- let made = Command::new("ffmpeg")
75+ let status = ec_testkit::ffmpeg()
7776 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
7877 .arg(format!("testsrc2=size={WIDTH}x{HEIGHT}:rate={FPS}"))
7978 .args([
@@ -86,8 +85,9 @@ fn testsrc2_raw(dir: &Path) -> Option<PathBuf> {
8685 ])
8786 .arg(&path)
8887 .status()
89- .ok()?;
90- made.success().then_some(path)
88+ .expect("run ffmpeg");
89+ assert!(status.success(), "ffmpeg cannot generate testsrc2");
90+ path
9191 }
9292
9393 /// Picture `t` of the raw clip, read from the file at its offset.
@@ -241,7 +241,7 @@ fn encode_in_its_own_process(
241241 fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
242242 let rate = FPS.to_string();
243243 let size = format!("{WIDTH}x{HEIGHT}");
244- let out = Command::new("ffmpeg")
244+ let out = ec_testkit::ffmpeg()
245245 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
246246 .arg(coded)
247247 .args([
@@ -264,10 +264,7 @@ fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
264264 #[test]
265265 fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
266266 let dir = scratch();
267- let Some(source) = testsrc2_raw(&dir) else {
268- eprintln!("skipped: ffmpeg cannot generate testsrc2");
269- return;
270- };
267+ let source = testsrc2_raw(&dir);
271268
272269 let mut failures = Vec::new();
273270 println!(
tools/ec-bench/Cargo.tomlmodified+1 -0
@@ -32,3 +32,4 @@ ec-flac = { workspace = true }
3232 ec-alac = { workspace = true }
3333 ec-ac3 = { workspace = true }
3434 ec-truehd = { workspace = true }
35+ec-testkit.workspace = true
tools/ec-bench/src/main.rsmodified+16 -85
@@ -11,7 +11,6 @@
1111 #![forbid(unsafe_code)]
1212
1313 use std::path::{Path, PathBuf};
14-use std::process::Command;
1514 use std::time::Instant;
1615
1716 use ec_av1::encode::Picture as Av1Picture;
@@ -81,42 +80,18 @@ fn fixtures() -> PathBuf {
8180 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures")
8281 }
8382
84-fn home() -> PathBuf {
85- PathBuf::from(std::env::var("HOME").expect("HOME"))
86-}
87-
88-/// A handful of real-library candidates, largest-effort first, that ffprobe
89-/// confirms carry the wanted video codec. Read-only: never touches the file
90-/// beyond `ffprobe`/`ffmpeg -i ... -o <scratch>`.
83+/// The open clip the bench uses as the source for a codec.
9184 fn real_video(codec: &str) -> Option<PathBuf> {
92- let roots = [home().join("Videos"), home().join("Downloads")];
93- let mut found = Vec::new();
94- for root in roots {
95- let Ok(walker) = std::fs::read_dir(&root) else {
96- continue;
97- };
98- for entry in walker.flatten() {
99- let p = entry.path();
100- let Some(ext) = p.extension().and_then(|e| e.to_str()) else {
101- continue;
102- };
103- if !matches!(
104- ext.to_ascii_lowercase().as_str(),
105- "mp4" | "mkv" | "mov" | "avi"
106- ) {
107- continue;
108- }
109- found.push(p);
110- }
111- }
112- found.sort();
113- found
114- .into_iter()
115- .find(|p| ffprobe_field(p, "v:0", "codec_name").as_deref() == Some(codec))
85+ let name = match codec {
86+ "h264" => "open/sintel_trailer-1080p.mp4",
87+ "hevc" => "derived/sintel720-x265-main10.mp4",
88+ _ => return None,
89+ };
90+ Some(ec_testkit::fixture(name))
11691 }
11792
11893 fn ffprobe_field(path: &Path, stream: &str, key: &str) -> Option<String> {
119- let out = Command::new("ffprobe")
94+ let out = ec_testkit::ffprobe()
12095 .args(["-v", "error", "-select_streams", stream, "-show_entries"])
12196 .arg(format!("stream={key}"))
12297 .args(["-of", "default=nw=1:nk=1"])
@@ -148,7 +123,7 @@ fn bench_h264(rows: &mut Vec<Row>) {
148123 .unwrap_or(0);
149124
150125 // decode: 10s Annex-B extract, trimmed inside ffmpeg (never decode-then-trim).
151- let out = Command::new("ffmpeg")
126+ let out = ec_testkit::ffmpeg()
152127 .args(["-v", "error", "-t", "10", "-i"])
153128 .arg(&src)
154129 .args([
@@ -230,7 +205,7 @@ fn bench_h264(rows: &mut Vec<Row>) {
230205 /// `n` progressive frames of raw I420 at `w x h`, scaled and trimmed inside
231206 /// ffmpeg.
232207 fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u32) {
233- let out = Command::new("ffmpeg")
208+ let out = ec_testkit::ffmpeg()
234209 .args(["-v", "error", "-i"])
235210 .arg(src)
236211 .args([
@@ -475,7 +450,7 @@ fn bench_hw_av1_encode_10bit(rows: &mut Vec<Row>) {
475450 /// minute in: frame 0 of a film is its black leader, and a black leader codes
476451 /// to nothing and benchmarks nothing.
477452 fn extract_yuv420p10(src: &Path, w: u32, h: u32, n: u32) -> Vec<u8> {
478- let out = Command::new("ffmpeg")
453+ let out = ec_testkit::ffmpeg()
479454 .args(["-v", "error", "-ss", "60", "-i"])
480455 .arg(src)
481456 .args([
@@ -638,32 +613,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) {
638613 if let Ok(entries) = std::fs::read_dir(fixtures().join("audio")) {
639614 candidates.extend(entries.flatten().map(|e| e.path()));
640615 }
641- // Real-library samples: mp3 and wav are on disk; ac3 lives inside the
642- // ReelT mux (5.1 AC-3), extracted as its own elementary file.
643- for f in ["8a3b6d1d19.mp3", "test.wav"] {
644- let p = home().join("Downloads").join(f);
645- if p.exists() {
646- candidates.push(p);
647- }
648- }
649- if let Some(src) = real_video("h264")
650- && ffprobe_field(&src, "a:0", "codec_name").as_deref() == Some("ac3")
651- {
652- let out = Command::new("ffmpeg")
653- .args(["-v", "error", "-t", "10", "-i"])
654- .arg(&src)
655- .args(["-vn", "-c:a", "copy", "-f", "ac3"])
656- .arg(
657- Path::new(&std::env::var("HOME").unwrap())
658- .join(".cache/bench-media/sample.ac3"),
659- )
660- .output();
661- if let Ok(o) = out
662- && o.status.success()
663- {
664- candidates.push(home().join(".cache/bench-media/sample.ac3"));
665- }
666- }
616+ candidates.push(ec_testkit::fixture("open/fate/ac3/monsters_inc_5.1_448_small.ac3"));
667617 candidates.sort();
668618 candidates.dedup();
669619
@@ -717,7 +667,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) {
717667 /// `seconds` of real interleaved `f32` PCM, decoded through `ec-probe`'s own
718668 /// `Reader`/`AudioDecoder` route (the same one `bench_audio_decode` drives).
719669 fn real_pcm(seconds: f64) -> Option<(Vec<f32>, u32, usize)> {
720- let path = fixtures().join("audio/wav16-stereo-48000.wav");
670+ let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav");
721671 let mut reader = Reader::open(&path).ok()?;
722672 let stream = reader.default_stream(MediaType::Audio)?.index;
723673 let mut dec = reader.make_decoder(stream).ok()?;
@@ -1023,7 +973,7 @@ fn bench_truehd(rows: &mut Vec<Row>) {
1023973 /// Container-level duration (`format=duration`), for a mux whose per-stream
1024974 /// packets carry no duration field of their own (some Matroska tracks don't).
1025975 fn format_duration(path: &Path) -> Option<String> {
1026- let out = Command::new("ffprobe")
976+ let out = ec_testkit::ffprobe()
1027977 .args(["-v", "error", "-show_entries", "format=duration"])
1028978 .args(["-of", "default=nw=1:nk=1"])
1029979 .arg(path)
@@ -1038,7 +988,7 @@ fn format_duration(path: &Path) -> Option<String> {
1038988
1039989 fn bench_container_demux(rows: &mut Vec<Row>) {
1040990 for (component, ext) in [("ec-matroska", "mkv"), ("ec-mp4", "mp4")] {
1041- let Some(src) = [fixtures().join("video"), home().join("Videos")]
991+ let Some(src) = [ec_testkit::root().join("open"), ec_testkit::root().join("derived")]
1042992 .into_iter()
1043993 .filter_map(|d| std::fs::read_dir(d).ok())
1044994 .flatten()
@@ -1096,17 +1046,6 @@ fn bench_image_decode(rows: &mut Vec<Row>) {
10961046 .filter(|p| p.extension().is_some()),
10971047 );
10981048 }
1099- for f in [
1100- "IMG_20260804_170612.jpg",
1101- "drawing-1.png",
1102- "20260722-233942.png",
1103- "giphy.gif",
1104- ] {
1105- let p = home().join("Downloads").join(f);
1106- if p.exists() {
1107- candidates.push(p);
1108- }
1109- }
11101049 candidates.sort();
11111050
11121051 for path in candidates {
@@ -1138,15 +1077,7 @@ fn bench_image_decode(rows: &mut Vec<Row>) {
11381077 // ---------------------------------------------------------------------------
11391078
11401079 fn bench_inflate(rows: &mut Vec<Row>) {
1141- let Some(png) = [
1142- fixtures().join("stills/gray16.png"),
1143- home().join("Downloads/drawing-1.png"),
1144- ]
1145- .into_iter()
1146- .find(|p| p.exists()) else {
1147- rows.push(missing("ec-inflate", "inflate"));
1148- return;
1149- };
1080+ let png = fixtures().join("stills/gray16.png");
11501081 let Ok(bytes) = std::fs::read(&png) else {
11511082 rows.push(missing("ec-inflate", "inflate"));
11521083 return;
tools/oracle/Cargo.tomlmodified+1 -0
@@ -13,3 +13,4 @@ path = "src/main.rs"
1313 # No dependencies on purpose: the oracle drives ffmpeg/ffprobe through std process
1414 # pipes so that comparison tooling can never leak into any ec-* crate's dep graph.
1515 [dependencies]
16+ec-testkit.workspace = true
tools/oracle/src/main.rsmodified+3 -3
@@ -18,7 +18,7 @@
1818 #![forbid(unsafe_code)]
1919
2020 use std::collections::HashMap;
21-use std::process::{Command, Stdio};
21+use std::process::Stdio;
2222
2323 const USAGE: &str = "\
2424 oracle — comparison harness (ffmpeg is test tooling only)
@@ -98,7 +98,7 @@ impl Args {
9898 /// Decode `input` with ffmpeg and return the raw bytes it writes to stdout.
9999 /// stderr is inherited so a large error log can never deadlock the pipe.
100100 fn ffmpeg_raw(input: &str, extra: &[&str]) -> Result<Vec<u8>, String> {
101- let out = Command::new("ffmpeg")
101+ let out = ec_testkit::ffmpeg()
102102 .args(["-nostdin", "-v", "error", "-i", input])
103103 .args(extra)
104104 .arg("-")
@@ -117,7 +117,7 @@ fn ffmpeg_raw(input: &str, extra: &[&str]) -> Result<Vec<u8>, String> {
117117
118118 /// `ffprobe -show_entries stream=<entries>` as a key -> value map (first stream wins).
119119 fn ffprobe(input: &str, select: &str, entries: &str) -> Result<HashMap<String, String>, String> {
120- let out = Command::new("ffprobe")
120+ let out = ec_testkit::ffprobe()
121121 .args(["-v", "error", "-select_streams", select, "-show_entries"])
122122 .arg(format!("stream={entries}"))
123123 .args(["-of", "default=nw=1"])
tools/oracle/tests/cli.rsmodified+7 -41
@@ -2,19 +2,10 @@
22 //! crate's test will, using ffmpeg as both the "our decoder" stand-in and the
33 //! reference. Exercises the PASS and the FAIL path of every subcommand.
44 //!
5-//! Fixture-gated: fixtures/ is gitignored, so a checkout without
6-//! `scripts/gen-fixtures.sh` run skips loudly instead of failing.
75
86 use std::path::{Path, PathBuf};
97 use std::process::{Command, Stdio};
108
11-fn fixtures() -> PathBuf {
12- Path::new(env!("CARGO_MANIFEST_DIR"))
13- .join("../../fixtures")
14- .canonicalize()
15- .unwrap_or_else(|_| PathBuf::from("/nonexistent"))
16-}
17-
189 // Per-test directory: the test binary runs its cases as threads of one process,
1910 // so a pid-only name would let one case delete another's raw files.
2011 fn workdir(name: &str) -> PathBuf {
@@ -26,7 +17,7 @@ fn workdir(name: &str) -> PathBuf {
2617 /// Decode `input` to a raw file with ffmpeg — stands in for "our decoder's output".
2718 fn decode_raw(input: &Path, out: &Path, extra: &[&str]) {
2819 let f = std::fs::File::create(out).unwrap();
29- let st = Command::new("ffmpeg")
20+ let st = ec_testkit::ffmpeg()
3021 .args(["-nostdin", "-y", "-v", "error", "-i"])
3122 .arg(input)
3223 .args(extra)
@@ -46,29 +37,12 @@ fn oracle(args: &[&str]) -> i32 {
4637 .expect("oracle exited by signal")
4738 }
4839
49-fn require(paths: &[PathBuf]) -> bool {
50- for p in paths {
51- if !p.is_file() {
52- eprintln!(
53- "SKIP: missing fixture {} — run scripts/gen-fixtures.sh",
54- p.display()
55- );
56- return false;
57- }
58- }
59- true
60-}
61-
6240 const F32: &[&str] = &["-map", "0:a:0", "-f", "f32le", "-acodec", "pcm_f32le"];
6341
6442 #[test]
6543 fn bit_exact_passes_on_same_decode_and_fails_on_a_different_one() {
66- let fx = fixtures();
67- let a = fx.join("audio/flac-stereo-48000.flac");
68- let b = fx.join("audio/flac-mono-48000.flac");
69- if !require(&[a.clone(), b.clone()]) {
70- return;
71- }
44+ let a = ec_testkit::fixture("audio/flac-stereo-48000.flac");
45+ let b = ec_testkit::fixture("audio/flac-mono-48000.flac");
7246 let w = workdir("bitexact");
7347 let (r1, r2, r3) = (w.join("a1.raw"), w.join("a2.raw"), w.join("b.raw"));
7448 decode_raw(&a, &r1, F32);
@@ -90,12 +64,8 @@ fn bit_exact_passes_on_same_decode_and_fails_on_a_different_one() {
9064
9165 #[test]
9266 fn audio_compare_passes_against_its_own_source_and_fails_across_rates() {
93- let fx = fixtures();
94- let a = fx.join("audio/flac-stereo-48000.flac");
95- let b = fx.join("audio/flac-stereo-44100.flac");
96- if !require(&[a.clone(), b.clone()]) {
97- return;
98- }
67+ let a = ec_testkit::fixture("audio/flac-stereo-48000.flac");
68+ let b = ec_testkit::fixture("audio/flac-stereo-44100.flac");
9969 let w = workdir("audio");
10070 let (ra, rb) = (w.join("a.raw"), w.join("b.raw"));
10171 decode_raw(&a, &ra, F32);
@@ -117,12 +87,8 @@ fn audio_compare_passes_against_its_own_source_and_fails_across_rates() {
11787
11888 #[test]
11989 fn video_compare_passes_against_its_own_source_and_fails_on_frame_count() {
120- let fx = fixtures();
121- let a = fx.join("video/h264-1080p-23.976-8bit.mp4");
122- let b = fx.join("video/h264-1080p-60-8bit.mp4");
123- if !require(&[a.clone(), b.clone()]) {
124- return;
125- }
90+ let a = ec_testkit::fixture("video/h264-1080p-23.976-8bit.mp4");
91+ let b = ec_testkit::fixture("video/h264-1080p-60-8bit.mp4");
12692 let w = workdir("video");
12793 let raw = w.join("a.raw");
12894 decode_raw(