forge
Explore
Log in

Don't you dare go Hollow

Merge simplify/w0-m9 (ec-bench: committed stills path, no home media)

Browse files at this commit

de1790d81a67fe79bfc2268e37e7a8ce383b7e9cAhmet Kaan GümüşParent: 83b74a40da4989

17 changed files +148 -1096

Cargo.lockmodified+5 -0
@@ -411,6 +411,7 @@ dependencies = [
411411 "ec-mp3",
412412 "ec-opus",
413413 "ec-probe",
414+ "ec-testkit",
414415 "ec-truehd",
415416 "ec-va",
416417 "ec-vorbis",
@@ -548,6 +549,7 @@ dependencies = [
548549 "ec-dsp",
549550 "ec-h264-syntax",
550551 "ec-h265-syntax",
552+ "ec-testkit",
551553 "ec-va",
552554 "ec-vk",
553555 "ec-vp9-syntax",
@@ -1266,6 +1268,9 @@ dependencies = [
12661268 [[package]]
12671269 name = "oracle"
12681270 version = "0.1.0"
1271+dependencies = [
1272+ "ec-testkit",
1273+]
12691274
12701275 [[package]]
12711276 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+4 -6
@@ -2,15 +2,13 @@
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>
65 //! ```
76
87 use std::collections::HashSet;
98 use std::fs;
109 use std::os::fd::AsRawFd;
1110 use std::os::unix::fs::MetadataExt;
12-use std::path::{Path, PathBuf};
13-use std::process::Command;
11+use std::path::Path;
1412
1513 use ec_hw::{
1614 Backend, Codec, DmaBufPicture, EncCodec, EncoderConfig, FrameMetadata, HwDecoder, HwEncoder,
@@ -106,7 +104,7 @@ const CASES: &[Case] = &[
106104 ];
107105
108106 fn main() {
109- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
107+ let dir = std::env::temp_dir();
110108 for case in CASES {
111109 run(&dir, case);
112110 }
@@ -491,7 +489,7 @@ fn compare_i420(label: &str, codec: Codec, backend: Backend, ours: &[I420], thei
491489 }
492490
493491 fn ffmpeg(args: &[&str]) {
494- let status = Command::new("ffmpeg")
492+ let status = ec_testkit::ffmpeg()
495493 .args(["-y", "-loglevel", "error"])
496494 .args(args)
497495 .status()
@@ -588,7 +586,7 @@ fn own_av1(dir: &Path) {
588586 decoder.flush().expect("flush");
589587 drain(&mut decoder, &mut decoded);
590588
591- let status = Command::new("ffmpeg")
589+ let status = ec_testkit::ffmpeg()
592590 .args(["-y", "-loglevel", "error", "-i"])
593591 .arg(&stream)
594592 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
crates/ec-hw/examples/hw_decode_rgb.rsmodified+1 -4
@@ -3,11 +3,9 @@
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>
76 //! ```
87
98 use std::fs;
10-use std::path::PathBuf;
119 use std::time::{Duration, Instant};
1210
1311 use ec_dsp::rgb::{YuvToRgb, i420_to_packed};
@@ -23,9 +21,8 @@ const FILES: &[(&str, Codec)] = &[
2321 ];
2422
2523 fn main() {
26- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
2724 for &(name, codec) in FILES {
28- let data = fs::read(dir.join(name)).expect("read stream");
25+ let data = fs::read(ec_testkit::fixture(&format!("bitstreams/{name}"))).expect("read stream");
2926 let units = if matches!(codec, Codec::Av1 | Codec::Vp9) {
3027 ivf_units(&data)
3128 } 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+3 -4
@@ -3,7 +3,6 @@
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>
76 //! ```
87
98 use std::fmt::Display;
@@ -115,7 +114,7 @@ fn spec_from_key(key: &str) -> Spec {
115114 fn make_source(dir: &Path, source: &str, w: u32, h: u32) -> PathBuf {
116115 let path = dir.join(format!("{source}-{w}x{h}.yuv"));
117116 if !path.exists() {
118- let status = Command::new("ffmpeg")
117+ let status = ec_testkit::ffmpeg()
119118 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
120119 .arg(format!("{source}=size={w}x{h}:rate={FPS}"))
121120 .args(["-frames:v", &FRAMES.to_string(), "-pix_fmt", "yuv420p", "-f", "rawvideo"])
@@ -303,7 +302,7 @@ fn field(out: &str, key: &str) -> Option<f64> {
303302 fn psnr_y(stream: &Path, format: &str, source: &Path, (w, h): (u32, u32)) -> Option<f64> {
304303 let rate = FPS.to_string();
305304 let size = format!("{w}x{h}");
306- let out = Command::new("ffmpeg")
305+ let out = ec_testkit::ffmpeg()
307306 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
308307 .arg(stream)
309308 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-s", &size, "-r", &rate, "-i"])
@@ -393,7 +392,7 @@ fn main() {
393392 }
394393 return;
395394 }
396- let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
395+ let dir = std::env::temp_dir();
397396 let me = std::env::current_exe().expect("own path");
398397 let mut decode_inputs: Vec<(&'static str, (u32, u32), Spec, Backend, PathBuf)> = Vec::new();
399398
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+83 -908
@@ -2,8 +2,6 @@
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.
75 //!
86 //! The oracle is ffmpeg's software decoder: every fixture is decoded here and
97 //! by `ffmpeg -f rawvideo`, and the two are compared frame by frame.
@@ -12,7 +10,7 @@ use std::io::Read;
1210 use std::path::{Path, PathBuf};
1311 use std::process::{Command, Stdio};
1412 use std::rc::Rc;
15-use std::time::{Duration, Instant};
13+use std::time::Instant;
1614
1715 use ec_hw::{
1816 Codec, Decoder, EncCodec, Encoder, EncoderConfig, Frame, FrameMetadata, H264Profile, I420,
@@ -24,10 +22,6 @@ use ec_va::Display;
2422 /// reordering, few enough to keep the suite under a minute.
2523 const FRAMES: usize = 24;
2624
27-fn bitstreams() -> PathBuf {
28- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/bitstreams")
29-}
30-
3125 fn display() -> Option<Rc<Display>> {
3226 match ec_va::open() {
3327 Ok(display) => Some(display),
@@ -38,23 +32,6 @@ fn display() -> Option<Rc<Display>> {
3832 }
3933 }
4034
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-
5835 /// The software reference: ffmpeg decoding the same file to raw planes.
5936 struct Reference {
6037 child: std::process::Child,
@@ -65,7 +42,7 @@ struct Reference {
6542 impl Reference {
6643 fn open(path: &Path, width: u32, height: u32, ten_bit: bool) -> Option<Reference> {
6744 let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
68- let child = Command::new("ffmpeg")
45+ let child = ec_testkit::ffmpeg()
6946 .args(["-nostdin", "-v", "error", "-i"])
7047 .arg(path)
7148 // `-fps_mode passthrough`: without it ffmpeg conforms its output to
@@ -301,10 +278,7 @@ fn split_ivf(data: &[u8]) -> Vec<&[u8]> {
301278 /// Decode every named fixture and compare with ffmpeg, frame by frame.
302279 fn compare_against_ffmpeg(files: &[PathBuf], codec: Codec, ten_bit: bool) {
303280 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- }
281+ assert!(!files.is_empty(), "no fixtures: run scripts/fixtures.sh");
308282 let mut table = Vec::new();
309283 for path in files {
310284 let data = std::fs::read(path).expect("fixture is readable");
@@ -381,7 +355,7 @@ fn name_of(p: &Path) -> String {
381355 /// The 4:2:0 fixtures of one kind; the 4:4:4 and monochrome ones are the
382356 /// profiles this GPU does not decode, and have their own test.
383357 fn profile_420(pattern: &str, codec: &str) -> Vec<PathBuf> {
384- fixtures(pattern)
358+ ec_testkit::fixtures("bitstreams", pattern)
385359 .into_iter()
386360 .filter(|p| {
387361 let name = name_of(p);
@@ -407,14 +381,14 @@ fn ten_bit(pattern: &str, codec: &str) -> Vec<PathBuf> {
407381 /// The selection must not depend on where the repository is checked out.
408382 #[test]
409383 fn fixture_selection_ignores_the_checkout_path() {
410- for p in eight_bit(".ivf", "av1") {
384+ for p in eight_bit("ivf", "av1") {
411385 let name = name_of(&p);
412386 assert!(
413387 name.starts_with("av1") && !name.contains("10bit"),
414388 "{name} is not an 8-bit AV1 fixture"
415389 );
416390 }
417- for p in ten_bit(".ivf", "vp9") {
391+ for p in ten_bit("ivf", "vp9") {
418392 let name = name_of(&p);
419393 assert!(
420394 name.starts_with("vp9") && name.contains("10bit"),
@@ -425,12 +399,12 @@ fn fixture_selection_ignores_the_checkout_path() {
425399
426400 #[test]
427401 fn h264_matches_ffmpeg() {
428- compare_against_ffmpeg(&fixtures(".264"), Codec::H264, false);
402+ compare_against_ffmpeg(&ec_testkit::fixtures("bitstreams", "264"), Codec::H264, false);
429403 }
430404
431405 #[test]
432406 fn hevc_8bit_matches_ffmpeg() {
433- compare_against_ffmpeg(&eight_bit(".265", "hevc"), Codec::H265, false);
407+ compare_against_ffmpeg(&eight_bit("265", "hevc"), Codec::H265, false);
434408 }
435409
436410 /// The 10-bit path, which is the RT format defect this crate exists to not
@@ -438,11 +412,8 @@ fn hevc_8bit_matches_ffmpeg() {
438412 /// P010 surface, and the ten bits must survive to the caller.
439413 #[test]
440414 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- }
415+ let files = ten_bit("265", "hevc");
416+ assert!(!files.is_empty(), "no 10-bit HEVC fixtures");
446417 let Some(display) = display() else { return };
447418 let data = std::fs::read(&files[0]).expect("fixture is readable");
448419 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
@@ -461,22 +432,22 @@ fn hevc_10bit_decodes_to_p010() {
461432
462433 #[test]
463434 fn vp9_matches_ffmpeg() {
464- compare_against_ffmpeg(&eight_bit(".ivf", "vp9"), Codec::Vp9, false);
435+ compare_against_ffmpeg(&eight_bit("ivf", "vp9"), Codec::Vp9, false);
465436 }
466437
467438 #[test]
468439 fn vp9_10bit_matches_ffmpeg() {
469- compare_against_ffmpeg(&ten_bit(".ivf", "vp9"), Codec::Vp9, true);
440+ compare_against_ffmpeg(&ten_bit("ivf", "vp9"), Codec::Vp9, true);
470441 }
471442
472443 #[test]
473444 fn av1_matches_ffmpeg() {
474- compare_against_ffmpeg(&eight_bit(".ivf", "av1"), Codec::Av1, false);
445+ compare_against_ffmpeg(&eight_bit("ivf", "av1"), Codec::Av1, false);
475446 }
476447
477448 #[test]
478449 fn av1_10bit_matches_ffmpeg() {
479- compare_against_ffmpeg(&ten_bit(".ivf", "av1"), Codec::Av1, true);
450+ compare_against_ffmpeg(&ten_bit("ivf", "av1"), Codec::Av1, true);
480451 }
481452
482453 /// Every "not supported" this crate says has to be a fact about the driver, not
@@ -499,11 +470,7 @@ fn unsupported_profiles_are_refused_with_a_reason() {
499470 ec_va::caps::Profile::AV1Profile1,
500471 ),
501472 ] {
502- let path = bitstreams().join(file);
503- if !path.exists() {
504- eprintln!("skipped: no {file}");
505- continue;
506- }
473+ let path = ec_testkit::fixture(&format!("bitstreams/{file}"));
507474 assert!(
508475 !caps.supports(absent, ec_va::caps::Entrypoint::VLD),
509476 "{absent:?} is in fact supported — the refusal below would be a bug"
@@ -610,7 +577,7 @@ fn round_trip(codec: EncCodec, width: u32, height: u32, min_db: f64) {
610577
611578 // ffprobe first: the conformance window / frame cropping has to survive, so
612579 // a 1916-wide encode comes back 1916 wide and not 1920.
613- let probe = Command::new("ffprobe")
580+ let probe = ec_testkit::ffprobe()
614581 .args([
615582 "-v",
616583 "error",
@@ -691,7 +658,7 @@ fn h264_profile_round_trip(profile: H264Profile, ffprobe_name: &str) {
691658 let path = dir.join("out.264");
692659 std::fs::write(&path, &stream).expect("write bitstream");
693660
694- let probe = Command::new("ffprobe")
661+ let probe = ec_testkit::ffprobe()
695662 .args([
696663 "-v",
697664 "error",
@@ -712,7 +679,7 @@ fn h264_profile_round_trip(profile: H264Profile, ffprobe_name: &str) {
712679 );
713680
714681 // Strict decode: any warning or error on stderr fails the test.
715- let decode = Command::new("ffmpeg")
682+ let decode = ec_testkit::ffmpeg()
716683 .args(["-nostdin", "-v", "warning", "-i"])
717684 .arg(&path)
718685 .args(["-f", "null", "-"])
@@ -798,13 +765,7 @@ fn our_encoder_and_our_decoder_agree() {
798765 fn encode_frame_zero_copy_matches_the_cpu_path() {
799766 let Some(display) = display() else { return };
800767 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- };
768+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
808769 let data = std::fs::read(&path).expect("fixture is readable");
809770 let frames = 10usize;
810771
@@ -921,7 +882,7 @@ fn colour_description_reaches_the_vui() {
921882 (path, coded.data)
922883 };
923884 let probe = |path: &Path| -> String {
924- let out = Command::new("ffprobe")
885+ let out = ec_testkit::ffprobe()
925886 .args([
926887 "-v",
927888 "error",
@@ -1045,38 +1006,6 @@ fn av1_encode_agrees_between_two_decoders() {
10451006 // encoder does not serve his files.
10461007 // ---------------------------------------------------------------------------
10471008
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
10801009 /// stream is neither flat nor 8-bit content dressed up as 10.
10811010 fn source_frame_16(width: u32, height: u32, t: u32) -> I420_16 {
10821011 let (w, h) = (width as usize, height as usize);
@@ -1109,6 +1038,14 @@ fn source_frame_16(width: u32, height: u32, t: u32) -> I420_16 {
11091038 f
11101039 }
11111040
1041+fn ten_bit_source(dir: &Path, frames: u32) -> (String, PathBuf, Vec<I420_16>) {
1042+ let y4m = dir.join("source-10bit.y4m");
1043+ let (w, h) = (1920u32, 1024u32);
1044+ let planes: Vec<I420_16> = (0..frames).map(|t| source_frame_16(w, h, t)).collect();
1045+ assert!(write_y4m_16(&y4m, &planes, (24, 1)), "write the 10-bit y4m");
1046+ ("synthetic 10-bit gradient".into(), y4m, planes)
1047+}
1048+
11121049 /// Write 10-bit planes as a y4m so ffmpeg sees the same source the encoder did.
11131050 fn write_y4m_16(path: &Path, frames: &[I420_16], fps: (u32, u32)) -> bool {
11141051 use std::io::Write;
@@ -1141,85 +1078,11 @@ fn write_y4m_16(path: &Path, frames: &[I420_16], fps: (u32, u32)) -> bool {
11411078 out.flush().is_ok()
11421079 }
11431080
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-
12181081 /// What ffprobe calls the stream's pixel format — for an AV1 stream that is
12191082 /// libdav1d reporting the sequence header's `high_bitdepth`, read by a decoder
12201083 /// that shares no code with the writer above.
12211084 fn ffprobe_pix_fmt(path: &Path, format: &str) -> Option<String> {
1222- let out = Command::new("ffprobe")
1085+ let out = ec_testkit::ffprobe()
12231086 .args([
12241087 "-v",
12251088 "error",
@@ -1274,10 +1137,7 @@ fn hevc_main10_encode_round_trips() {
12741137 let Some(display) = display() else { return };
12751138 let dir = std::env::temp_dir().join("ec-hw-hevc-10bit");
12761139 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- };
1140+ let (_, _, planes) = ten_bit_source(&dir, 10);
12811141 let (width, height) = (planes[0].width, planes[0].height);
12821142 let data = match encode_stream_16(
12831143 &display,
@@ -1328,11 +1188,7 @@ fn av1_10bit_encode_agrees_between_two_decoders() {
13281188 let dir = std::env::temp_dir().join("ec-hw-av1-10bit");
13291189 let _ = std::fs::create_dir_all(&dir);
13301190 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;
1191+ let (label, _, planes) = ten_bit_source(&dir, frames);
13361192 let (width, height) = (planes[0].width, planes[0].height);
13371193 let data = match encode_stream_16(
13381194 &display,
@@ -1432,23 +1288,16 @@ fn av1_10bit_encode_agrees_between_two_decoders() {
14321288 #[test]
14331289 fn av1_encode_rate_control_lands() {
14341290 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- };
1291+ let (label, source) = real_clips().remove(0);
14401292 let dir = std::env::temp_dir().join("ec-hw-av1-rc");
14411293 let _ = std::fs::create_dir_all(&dir);
14421294 let (width, height, frames, fps) = (1920u32, 1080u32, 60u32, 30u32);
14431295 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- };
1296+ assert!(
1297+ extract_y4m(&source, &y4m, width, height, frames),
1298+ "{label}: extraction failed"
1299+ );
1300+ let planes = raw_frames(&y4m, width, height, frames).expect("frames of the trailer");
14521301
14531302 println!(
14541303 "AV1 rate control on {label}, {width}x{height} yuv420p, {} frames at {fps} fps:",
@@ -1547,7 +1396,7 @@ fn av1_encode_rate_control_lands() {
15471396 /// [`ffmpeg_psnr`] with the rate pinned to `fps` on both inputs.
15481397 fn ffmpeg_psnr_at(coded: &Path, source: &Path, fps: u32) -> Option<f64> {
15491398 let rate = fps.to_string();
1550- let out = Command::new("ffmpeg")
1399+ let out = ec_testkit::ffmpeg()
15511400 .args(["-nostdin", "-v", "info", "-f", "obu", "-r", &rate])
15521401 .arg("-i")
15531402 .arg(coded)
@@ -1567,126 +1416,6 @@ fn ffmpeg_psnr_at(coded: &Path, source: &Path, fps: u32) -> Option<f64> {
15671416 .filter(|v| v.is_finite())
15681417 }
15691418
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-
16901419 /// What the GPU's AV1 costs against software, on his own content.
16911420 ///
16921421 /// Four quantisers per encoder on a 1920x1080 crop of a film and of a screen
@@ -1698,11 +1427,6 @@ fn av1_10bit_bd_row_vs_software() {
16981427 #[test]
16991428 fn av1_encode_bd_row_vs_software() {
17001429 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- }
17061430 // A ladder compared with itself saves nothing: the check on the metric.
17071431 let same = [(100.0, 30.0), (200.0, 35.0), (400.0, 40.0)];
17081432 assert!(
@@ -1712,20 +1436,14 @@ fn av1_encode_bd_row_vs_software() {
17121436
17131437 let dir = std::env::temp_dir().join("ec-hw-av1-bd");
17141438 let _ = std::fs::create_dir_all(&dir);
1715- for (label, source) in clips {
1439+ for (label, source) in real_clips() {
17161440 let y4m = dir.join(format!("{label}.y4m"));
17171441 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- };
1442+ assert!(
1443+ extract_y4m(&source, &y4m, width, height, frames),
1444+ "{label}: extraction failed"
1445+ );
1446+ let planes = raw_frames(&y4m, width, height, frames).expect("frames of the trailer");
17291447
17301448 let mut ours = Vec::new();
17311449 // Descending quantiser: every ladder here is ordered by rising rate.
@@ -1840,7 +1558,7 @@ fn software_point(
18401558 ) -> Option<(f64, f64)> {
18411559 let out = dir.join(format!("{label}-{encoder}-{point}.ivf"));
18421560 let _ = std::fs::remove_file(&out);
1843- let status = Command::new("ffmpeg")
1561+ let status = ec_testkit::ffmpeg()
18441562 .args(["-nostdin", "-v", "error", "-y", "-i"])
18451563 .arg(y4m)
18461564 .args(["-c:v", encoder])
@@ -1858,7 +1576,7 @@ fn software_point(
18581576
18591577 /// PSNR of a coded stream against the source, from ffmpeg's own filter.
18601578 fn ffmpeg_psnr(coded: &Path, source: &Path, raw_obu: bool) -> Option<f64> {
1861- let mut cmd = Command::new("ffmpeg");
1579+ let mut cmd = ec_testkit::ffmpeg();
18621580 cmd.args(["-nostdin", "-v", "info"]);
18631581 if raw_obu {
18641582 cmd.args(["-f", "obu"]);
@@ -1889,7 +1607,7 @@ fn ffmpeg_psnr(coded: &Path, source: &Path, raw_obu: bool) -> Option<f64> {
18891607 /// A 1920x1080 crop of `frames` pictures, as a y4m file the encoders share.
18901608 fn extract_y4m(source: &Path, out: &Path, width: u32, height: u32, frames: u32) -> bool {
18911609 let _ = std::fs::remove_file(out);
1892- Command::new("ffmpeg")
1610+ ec_testkit::ffmpeg()
18931611 .args(["-nostdin", "-v", "error", "-y", "-ss", "60", "-i"])
18941612 .arg(source)
18951613 .args([
@@ -1907,7 +1625,7 @@ fn extract_y4m(source: &Path, out: &Path, width: u32, height: u32, frames: u32)
19071625
19081626 /// The same pictures as planes, for the hardware encoder's own input.
19091627 fn raw_frames(y4m: &Path, width: u32, height: u32, frames: u32) -> Option<Vec<I420>> {
1910- let out = Command::new("ffmpeg")
1628+ let out = ec_testkit::ffmpeg()
19111629 .args(["-nostdin", "-v", "error", "-i"])
19121630 .arg(y4m)
19131631 .args(["-pix_fmt", "yuv420p", "-f", "rawvideo", "-"])
@@ -1932,35 +1650,11 @@ fn raw_frames(y4m: &Path, width: u32, height: u32, frames: u32) -> Option<Vec<I4
19321650 (!pictures.is_empty()).then_some(pictures)
19331651 }
19341652
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.
19371653 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()
1654+ vec![
1655+ ("sintel 1080p", ec_testkit::fixture("open/sintel_trailer-1080p.mp4")),
1656+ ("sintel 720p", ec_testkit::fixture("open/sintel_trailer-720p.mp4")),
1657+ ]
19641658 }
19651659
19661660 /// BD-rate of `test` against `reference`, as a fraction (negative = fewer
@@ -2069,11 +1763,7 @@ fn av1_encode_speed() {
20691763 #[test]
20701764 fn h264_frame_num_gaps_are_synthesised() {
20711765 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- }
1766+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
20771767 let data = std::fs::read(&path).expect("fixture is readable");
20781768 let units = split_access_units(&data, Codec::H264);
20791769 assert!(
@@ -2148,11 +1838,7 @@ fn long_decode_does_not_grow_the_resident_set() {
21481838 return;
21491839 }
21501840 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- }
1841+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
21561842 let data = std::fs::read(&path).expect("fixture is readable");
21571843 let units = split_access_units(&data, Codec::H264);
21581844 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
@@ -2216,11 +1902,7 @@ fn long_decode_does_not_grow_the_resident_set() {
22161902 #[test]
22171903 fn frames_export_as_dma_buf() {
22181904 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- }
1905+ let path = ec_testkit::fixture("bitstreams/h264-1080p-23.976-8bit.264");
22241906 let data = std::fs::read(&path).expect("fixture is readable");
22251907 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
22261908 let mut exported = 0usize;
@@ -2256,7 +1938,7 @@ fn elementary(path: &Path, codec: Codec, frames: usize) -> Option<Vec<u8>> {
22561938 Codec::H265 => &["-bsf:v", "hevc_mp4toannexb", "-f", "hevc"],
22571939 Codec::Vp9 | Codec::Av1 => &["-f", "ivf"],
22581940 };
2259- let out = Command::new("ffmpeg")
1941+ let out = ec_testkit::ffmpeg()
22601942 .args(["-nostdin", "-v", "error", "-i"])
22611943 .arg(path)
22621944 .args(["-map", "0:v:0", "-c:v", "copy"])
@@ -2271,54 +1953,17 @@ fn elementary(path: &Path, codec: Codec, frames: usize) -> Option<Vec<u8>> {
22711953 (!out.stdout.is_empty()).then_some(out.stdout)
22721954 }
22731955
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.
22801956 #[test]
22811957 fn real_library_spot_check() {
22821958 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- }
1959+ let wanted: Vec<(PathBuf, Codec, bool)> = [
1960+ ("open/sintel_trailer-480p.mp4", Codec::H264, false),
1961+ ("open/sintel_trailer-1080p.mp4", Codec::H264, false),
1962+ ("derived/sintel720-x265-main10.mp4", Codec::H265, true),
1963+ ]
1964+ .into_iter()
1965+ .map(|(rel, codec, ten_bit)| (ec_testkit::fixture(rel), codec, ten_bit))
1966+ .collect();
23221967
23231968 // 500 frames per file by default; a diagnostic run can ask for fewer.
23241969 let limit: usize = std::env::var("EC_HW_SWEEP_FRAMES")
@@ -2328,10 +1973,7 @@ fn real_library_spot_check() {
23281973 let mut table = Vec::new();
23291974 for (path, codec, ten_bit) in &wanted {
23301975 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- };
1976+ let data = elementary(path, *codec, limit).expect("elementary stream");
23351977 let mut decoder = Decoder::new(&display, *codec).expect("decoder opens");
23361978 let mut reference: Option<Reference> = None;
23371979 let mut worst = f64::INFINITY;
@@ -2413,7 +2055,6 @@ fn plane_psnr(a: &[u16], b: &[u16], peak: f64) -> f64 {
24132055 }
24142056 }
24152057
2416-/// P010 correctness on the real 4K HDR film, plane by plane.
24172058 ///
24182059 /// `real_library_spot_check` already pins the whole-frame PSNR at >= 40 dB
24192060 /// for a mix of files; this isolates Y from U/V on this specific 10-bit film,
@@ -2423,21 +2064,11 @@ fn plane_psnr(a: &[u16], b: &[u16], peak: f64) -> f64 {
24232064 /// a bug). A collapsed U/V PSNR here (a grey frame) would mean the chroma
24242065 /// plane is being read at the wrong stride/offset; it is not, on this file.
24252066 #[test]
2426-fn ten_bit_4k_chroma_is_not_grey() {
2067+fn ten_bit_chroma_is_not_grey() {
24272068 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- }
2069+ let path = &ec_testkit::fixture("derived/sintel720-x265-main10.mp4");
24362070 let frames = 3usize;
2437- let Some(data) = elementary(path, Codec::H265, frames) else {
2438- eprintln!("skipped: no elementary stream");
2439- return;
2440- };
2071+ let data = elementary(path, Codec::H265, frames).expect("elementary stream");
24412072 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
24422073 let mut ref10: Option<Reference> = None;
24432074 let mut ref8: Option<Reference> = None;
@@ -2492,67 +2123,14 @@ fn ten_bit_4k_chroma_is_not_grey() {
24922123 assert_eq!(compared, frames, "not all frames were compared");
24932124 }
24942125
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-
25412126 /// An SDR H.264 stream, which carries no HDR SEI at all: `Frame::colour`
25422127 /// either resolves from the VUI or answers [`None`], but never panics.
25432128 #[test]
25442129 fn sdr_h264_colour_never_panics() {
25452130 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- }
2131+ let paths = ec_testkit::fixtures("bitstreams", "264");
25512132 let path = &paths[0];
2552- let Some(data) = std::fs::read(path).ok() else {
2553- eprintln!("skipped: fixture unreadable");
2554- return;
2555- };
2133+ let data = std::fs::read(path).expect("fixture is readable");
25562134 let mut decoder = Decoder::new(&display, Codec::H264).expect("decoder opens");
25572135 let mut seen = 0usize;
25582136 decode_stream(&mut decoder, Codec::H264, &data, 2, |frame| {
@@ -2566,395 +2144,6 @@ fn sdr_h264_colour_never_panics() {
25662144 assert!(seen > 0, "{}: nothing decoded", short(path));
25672145 }
25682146
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-
29582147 /// A CRA GOP boundary stores its RASL leading pictures *after* the CRA in
29592148 /// decode order, even though they display before it (they predict from
29602149 /// pictures the CRA's own random-access point does not have). A decoder
@@ -2965,11 +2154,8 @@ fn p010_zero_copy_encode_is_realtime() {
29652154 #[test]
29662155 fn hevc_seek_matches_linear_mkv() {
29672156 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- };
2157+ let path = ec_testkit::fixture("bitstreams/test_hevc.mkv");
2158+ let data = elementary(&path, Codec::H265, 45).expect("elementary stream");
29732159 let units = split_access_units(&data, Codec::H265);
29742160
29752161 // Linear decode: every picture from the start, frame 30 kept for
@@ -3038,11 +2224,8 @@ fn hevc_seek_matches_linear_mkv() {
30382224 #[test]
30392225 fn h264_seek_matches_linear_open_gop() {
30402226 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- };
2227+ let path = ec_testkit::fixture("bitstreams/h264-open-gop.mp4");
2228+ let data = elementary(&path, Codec::H264, 60).expect("elementary stream");
30462229 let units = split_access_units(&data, Codec::H264);
30472230
30482231 // Linear decode: every picture from the start, frame 30 kept for
@@ -3146,7 +2329,7 @@ fn starts_with_cra(au: &[u8]) -> bool {
31462329 /// `ffmpeg -bsf:v trace_headers` over a bitstream, returning every
31472330 /// `name = value` line it prints — the slice header fields the driver wrote.
31482331 fn trace_headers(path: &Path, codec: &str) -> Vec<(String, i64)> {
3149- let out = Command::new("ffmpeg")
2332+ let out = ec_testkit::ffmpeg()
31502333 .args(["-v", "trace", "-hide_banner", "-nostats", "-f", codec, "-i"])
31512334 .arg(path)
31522335 .args(["-c:v", "copy", "-bsf:v", "trace_headers", "-f", "null", "-"])
@@ -3312,7 +2495,7 @@ fn write_y4m_8(path: &Path, frames: &[I420], fps: u32) -> bool {
33122495 /// Average PSNR (dB) of a raw elementary stream against its source y4m.
33132496 fn psnr_of_elementary(coded: &Path, format: &str, source: &Path, fps: u32) -> Option<f64> {
33142497 let rate = fps.to_string();
3315- let out = Command::new("ffmpeg")
2498+ let out = ec_testkit::ffmpeg()
33162499 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
33172500 .arg(coded)
33182501 .args(["-r", &rate, "-i"])
@@ -3380,20 +2563,17 @@ fn cbr_lands_within_five_percent_of_the_request() {
33802563 let synthetic_y4m = dir.join("cbr-synthetic.y4m");
33812564 assert!(write_y4m_8(&synthetic_y4m, &synthetic, fps), "write source");
33822565 let testsrc_y4m = dir.join("cbr-testsrc2.y4m");
3383- let generated = Command::new("ffmpeg")
2566+ let generated = ec_testkit::ffmpeg()
33842567 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
33852568 .arg(format!("testsrc2=size={width}x{height}:rate={fps}"))
33862569 .args(["-frames:v", &frames.to_string(), "-pix_fmt", "yuv420p"])
33872570 .arg(&testsrc_y4m)
33882571 .status()
33892572 .is_ok_and(|s| s.success());
3390- let Some(testsrc) = generated
2573+ let testsrc = generated
33912574 .then(|| raw_frames(&testsrc_y4m, width, height, frames))
33922575 .flatten()
3393- else {
3394- eprintln!("skipped: ffmpeg cannot generate testsrc2");
3395- return;
3396- };
2576+ .expect("ffmpeg generates testsrc2");
33972577 let clips: [(&str, Vec<I420>, PathBuf); 2] = [
33982578 ("moving box", synthetic, synthetic_y4m),
33992579 ("testsrc2", testsrc, testsrc_y4m),
@@ -3639,11 +2819,8 @@ fn a_broken_gop_is_refused_on_every_codec() {
36392819 (Codec::H265, "hevc-bframes-320.265"),
36402820 ];
36412821 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- };
2822+ let path = ec_testkit::fixture(&format!("bitstreams/{name}"));
2823+ let data = std::fs::read(&path).expect("fixture is readable");
36472824 let stream = broken_gop(codec, &data).expect("the fixture has a second access unit");
36482825 let mut decoder = Decoder::new(&display, codec).expect("decoder");
36492826 let refusal = decoder.decode(&stream, 0).err().map(|e| e.to_string());
@@ -3665,11 +2842,9 @@ fn a_broken_gop_is_refused_on_every_codec() {
36652842
36662843 #[test]
36672844 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- };
2845+ let file = ec_testkit::fixture("derived/sintel720-x265-main10.mp4");
36712846 let Some(display) = display() else { return };
3672- let data = std::fs::read(file).expect("fixture is readable");
2847+ let data = elementary(&file, Codec::H265, 1).expect("elementary stream");
36732848 let mut decoder = Decoder::new(&display, Codec::H265).expect("decoder opens");
36742849 let mut size = (0, 0);
36752850 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+7 -11
@@ -69,11 +69,9 @@ 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+fn testsrc2_raw(dir: &Path) -> PathBuf {
7573 let path = dir.join("testsrc2-720p.yuv");
76- let made = Command::new("ffmpeg")
74+ let status = ec_testkit::ffmpeg()
7775 .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
7876 .arg(format!("testsrc2=size={WIDTH}x{HEIGHT}:rate={FPS}"))
7977 .args([
@@ -86,8 +84,9 @@ fn testsrc2_raw(dir: &Path) -> Option<PathBuf> {
8684 ])
8785 .arg(&path)
8886 .status()
89- .ok()?;
90- made.success().then_some(path)
87+ .expect("run ffmpeg");
88+ assert!(status.success(), "ffmpeg cannot generate testsrc2");
89+ path
9190 }
9291
9392 /// Picture `t` of the raw clip, read from the file at its offset.
@@ -241,7 +240,7 @@ fn encode_in_its_own_process(
241240 fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
242241 let rate = FPS.to_string();
243242 let size = format!("{WIDTH}x{HEIGHT}");
244- let out = Command::new("ffmpeg")
243+ let out = ec_testkit::ffmpeg()
245244 .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
246245 .arg(coded)
247246 .args([
@@ -264,10 +263,7 @@ fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
264263 #[test]
265264 fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
266265 let dir = scratch();
267- let Some(source) = testsrc2_raw(&dir) else {
268- eprintln!("skipped: ffmpeg cannot generate testsrc2");
269- return;
270- };
266+ let source = testsrc2_raw(&dir);
271267
272268 let mut failures = Vec::new();
273269 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+15 -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,17 @@ 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>`.
9183 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))
84+ let name = match codec {
85+ "h264" => "open/sintel_trailer-1080p.mp4",
86+ "hevc" => "derived/sintel720-x265-main10.mp4",
87+ _ => return None,
88+ };
89+ Some(ec_testkit::fixture(name))
11690 }
11791
11892 fn ffprobe_field(path: &Path, stream: &str, key: &str) -> Option<String> {
119- let out = Command::new("ffprobe")
93+ let out = ec_testkit::ffprobe()
12094 .args(["-v", "error", "-select_streams", stream, "-show_entries"])
12195 .arg(format!("stream={key}"))
12296 .args(["-of", "default=nw=1:nk=1"])
@@ -148,7 +122,7 @@ fn bench_h264(rows: &mut Vec<Row>) {
148122 .unwrap_or(0);
149123
150124 // decode: 10s Annex-B extract, trimmed inside ffmpeg (never decode-then-trim).
151- let out = Command::new("ffmpeg")
125+ let out = ec_testkit::ffmpeg()
152126 .args(["-v", "error", "-t", "10", "-i"])
153127 .arg(&src)
154128 .args([
@@ -230,7 +204,7 @@ fn bench_h264(rows: &mut Vec<Row>) {
230204 /// `n` progressive frames of raw I420 at `w x h`, scaled and trimmed inside
231205 /// ffmpeg.
232206 fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u32) {
233- let out = Command::new("ffmpeg")
207+ let out = ec_testkit::ffmpeg()
234208 .args(["-v", "error", "-i"])
235209 .arg(src)
236210 .args([
@@ -475,7 +449,7 @@ fn bench_hw_av1_encode_10bit(rows: &mut Vec<Row>) {
475449 /// minute in: frame 0 of a film is its black leader, and a black leader codes
476450 /// to nothing and benchmarks nothing.
477451 fn extract_yuv420p10(src: &Path, w: u32, h: u32, n: u32) -> Vec<u8> {
478- let out = Command::new("ffmpeg")
452+ let out = ec_testkit::ffmpeg()
479453 .args(["-v", "error", "-ss", "60", "-i"])
480454 .arg(src)
481455 .args([
@@ -638,32 +612,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) {
638612 if let Ok(entries) = std::fs::read_dir(fixtures().join("audio")) {
639613 candidates.extend(entries.flatten().map(|e| e.path()));
640614 }
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- }
615+ candidates.push(ec_testkit::fixture("open/fate/ac3/monsters_inc_5.1_448_small.ac3"));
667616 candidates.sort();
668617 candidates.dedup();
669618
@@ -717,7 +666,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) {
717666 /// `seconds` of real interleaved `f32` PCM, decoded through `ec-probe`'s own
718667 /// `Reader`/`AudioDecoder` route (the same one `bench_audio_decode` drives).
719668 fn real_pcm(seconds: f64) -> Option<(Vec<f32>, u32, usize)> {
720- let path = fixtures().join("audio/wav16-stereo-48000.wav");
669+ let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav");
721670 let mut reader = Reader::open(&path).ok()?;
722671 let stream = reader.default_stream(MediaType::Audio)?.index;
723672 let mut dec = reader.make_decoder(stream).ok()?;
@@ -1023,7 +972,7 @@ fn bench_truehd(rows: &mut Vec<Row>) {
1023972 /// Container-level duration (`format=duration`), for a mux whose per-stream
1024973 /// packets carry no duration field of their own (some Matroska tracks don't).
1025974 fn format_duration(path: &Path) -> Option<String> {
1026- let out = Command::new("ffprobe")
975+ let out = ec_testkit::ffprobe()
1027976 .args(["-v", "error", "-show_entries", "format=duration"])
1028977 .args(["-of", "default=nw=1:nk=1"])
1029978 .arg(path)
@@ -1038,7 +987,7 @@ fn format_duration(path: &Path) -> Option<String> {
1038987
1039988 fn bench_container_demux(rows: &mut Vec<Row>) {
1040989 for (component, ext) in [("ec-matroska", "mkv"), ("ec-mp4", "mp4")] {
1041- let Some(src) = [fixtures().join("video"), home().join("Videos")]
990+ let Some(src) = [ec_testkit::root().join("open"), ec_testkit::root().join("derived")]
1042991 .into_iter()
1043992 .filter_map(|d| std::fs::read_dir(d).ok())
1044993 .flatten()
@@ -1097,17 +1046,6 @@ fn bench_image_decode(rows: &mut Vec<Row>) {
10971046 .filter(|p| p.extension().is_some()),
10981047 );
10991048 }
1100- for f in [
1101- "IMG_20260804_170612.jpg",
1102- "drawing-1.png",
1103- "20260722-233942.png",
1104- "giphy.gif",
1105- ] {
1106- let p = home().join("Downloads").join(f);
1107- if p.exists() {
1108- candidates.push(p);
1109- }
1110- }
11111049 candidates.sort();
11121050
11131051 for path in candidates {
@@ -1139,15 +1077,7 @@ fn bench_image_decode(rows: &mut Vec<Row>) {
11391077 // ---------------------------------------------------------------------------
11401078
11411079 fn bench_inflate(rows: &mut Vec<Row>) {
1142- let Some(png) = [
1143- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../crates/ec-image/tests/data/stills/gray16.png"),
1144- home().join("Downloads/drawing-1.png"),
1145- ]
1146- .into_iter()
1147- .find(|p| p.exists()) else {
1148- rows.push(missing("ec-inflate", "inflate"));
1149- return;
1150- };
1080+ let png = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../crates/ec-image/tests/data/stills/gray16.png");
11511081 let Ok(bytes) = std::fs::read(&png) else {
11521082 rows.push(missing("ec-inflate", "inflate"));
11531083 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(