forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/w0-m4' into simplify/w0

Browse files at this commit

7eb6d3444aefa0dfd66f545444f239c0baaaa7ccAhmet Kaan GümüşParent: 803be3c1eb7f8c

29 changed files +147 -1133

Cargo.lockmodified+3 -0
@@ -499,6 +499,7 @@ dependencies = [
499 "ec-h264-syntax",499 "ec-h264-syntax",
500 "ec-matroska",500 "ec-matroska",
501 "ec-mp4",501 "ec-mp4",
502+ "ec-testkit",
502 "tracking-allocator",503 "tracking-allocator",
503 "wide",504 "wide",
504 ]505 ]
@@ -518,6 +519,7 @@ dependencies = [
518 "bytemuck",519 "bytemuck",
519 "ec-core",520 "ec-core",
520 "ec-h265-syntax",521 "ec-h265-syntax",
522+ "ec-testkit",
521 "multiversion",523 "multiversion",
522 "wide",524 "wide",
523 ]525 ]
@@ -527,6 +529,7 @@ name = "ec-h265-syntax"
527 version = "0.1.0"529 version = "0.1.0"
528 dependencies = [530 dependencies = [
529 "ec-core",531 "ec-core",
532+ "ec-testkit",
530 ]533 ]
531 534
532 [[package]]535 [[package]]
crates/ec-h264/Cargo.tomlmodified+1 -0
@@ -18,6 +18,7 @@ ec-h264-syntax = { workspace = true }
18 wide = { workspace = true }18 wide = { workspace = true }
19 19
20 [dev-dependencies]20 [dev-dependencies]
21+ec-testkit.workspace = true
21 # The conformance harness walks Annex B itself to drive push_nal.22 # The conformance harness walks Annex B itself to drive push_nal.
22 ec-h264-syntax = { workspace = true }23 ec-h264-syntax = { workspace = true }
23 # ... and demuxes an MP4 directly where ffmpeg's own Annex B extraction of it24 # ... and demuxes an MP4 directly where ffmpeg's own Annex B extraction of it
crates/ec-h264/fuzz/seed.shmodified+2 -2
@@ -4,7 +4,7 @@
4 set -euo pipefail4 set -euo pipefail
5 5
6 here=$(cd -- "$(dirname -- "$0")" && pwd)6 here=$(cd -- "$(dirname -- "$0")" && pwd)
7-src="$here/../../../fixtures/vectors/h264-jvt"7+src="${EC_FIXTURES:-$here/../../../fixtures}/vectors/h264-jvt"
8 dst="$here/corpus/decode_annexb"8 dst="$here/corpus/decode_annexb"
9 9
10 seeds=(10 seeds=(
@@ -19,7 +19,7 @@ mkdir -p "$dst"
19 for rel in "${seeds[@]}"; do19 for rel in "${seeds[@]}"; do
20 f="$src/$rel"20 f="$src/$rel"
21 if [ ! -f "$f" ]; then21 if [ ! -f "$f" ]; then
22- echo "seed.sh: missing fixture $f (run scripts/link-fixtures.sh)" >&222+ echo "seed.sh: missing fixture $f (run scripts/fixtures.sh)" >&2
23 exit 123 exit 1
24 fi24 fi
25 cp -f "$f" "$dst/$(basename "$rel")"25 cp -f "$f" "$dst/$(basename "$rel")"
crates/ec-h264/tests/conformance.rsmodified+9 -489
@@ -1,7 +1,5 @@
1 //! JVT conformance: first IDR picture, bit-exact.1 //! JVT conformance: first IDR picture, bit-exact.
2 //!2 //!
3-//! Fixture-gated like tools/oracle: fixtures/ is gitignored, so a checkout
4-//! without `scripts/fetch-vectors.sh` skips loudly instead of failing.
5 //!3 //!
6 //! Oracles, in order of authority:4 //! Oracles, in order of authority:
7 //! 1. The reference decoder YUV that ships with each JVT vector (first5 //! 1. The reference decoder YUV that ships with each JVT vector (first
@@ -18,7 +16,6 @@ use std::sync::Once;
18 use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator};16 use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator};
19 use std::cell::Cell;17 use std::cell::Cell;
20 use std::path::{Path, PathBuf};18 use std::path::{Path, PathBuf};
21-use std::process::Command;
22 use std::sync::atomic::{AtomicU64, Ordering};19 use std::sync::atomic::{AtomicU64, Ordering};
23 20
24 use ec_core::registry::{CodecId, CodecParameters, Decoder as _};21 use ec_core::registry::{CodecId, CodecParameters, Decoder as _};
@@ -76,38 +73,9 @@ fn install_counter() {
76 // ---------------------------------------------------------------------------73 // ---------------------------------------------------------------------------
77 74
78 fn vectors_dir() -> PathBuf {75 fn vectors_dir() -> PathBuf {
79- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")76+ ec_testkit::fixture("vectors/h264-jvt")
80 }77 }
81 78
82-/// A gate that skips when its fixtures are absent reports GREEN having checked
83-/// nothing — the "gate skips on its own failure" class. The root `fixtures/`
84-/// directory is gitignored, so `git worktree add` hands every lane worktree a
85-/// tree without it and the whole conformance suite silently stops testing.
86-///
87-/// `EC_REQUIRE_FIXTURES=1` turns the skip into a hard failure naming the exact
88-/// missing path and the command that produces it; unset (the default), the skip
89-/// is kept and now says what it skipped. Set it in every batch run.
90-fn require_fixtures(path: &Path, what: &str, generator: &str) -> bool {
91- if path.exists() {
92- return true;
93- }
94- assert!(
95- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
96- "{what} missing at {} — this gate would prove nothing. A worktree has no \
97- gitignored root `fixtures/`: run scripts/link-fixtures.sh, or generate \
98- them with {generator}.",
99- path.display()
100- );
101- eprintln!(
102- "SKIP {what} missing at {} — this gate proved nothing; run \
103- scripts/link-fixtures.sh, or generate them with {generator} \
104- (or set EC_REQUIRE_FIXTURES=1 to make this a failure).",
105- path.display()
106- );
107- false
108-}
109-
110-/// Every vector directory `scripts/fetch-vectors.sh` has populated, in name
111 /// order.79 /// order.
112 ///80 ///
113 /// A hand-written list would only ever record what passed on the day it was81 /// A hand-written list would only ever record what passed on the day it was
@@ -153,7 +121,7 @@ fn find_ref_yuv(dir: &Path) -> Option<PathBuf> {
153 }121 }
154 122
155 fn ffmpeg_first_frame(stream: &Path) -> Option<Vec<u8>> {123 fn ffmpeg_first_frame(stream: &Path) -> Option<Vec<u8>> {
156- let out = Command::new("ffmpeg")124+ let out = ec_testkit::ffmpeg()
157 .args(["-v", "error", "-i"])125 .args(["-v", "error", "-i"])
158 .arg(stream)126 .arg(stream)
159 .args([127 .args([
@@ -235,7 +203,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, Error> {
235 203
236 /// Every frame ffmpeg decodes from `stream`, as raw I420.204 /// Every frame ffmpeg decodes from `stream`, as raw I420.
237 fn ffmpeg_all_frames(stream: &Path, frame_len: usize) -> Option<Vec<Vec<u8>>> {205 fn ffmpeg_all_frames(stream: &Path, frame_len: usize) -> Option<Vec<Vec<u8>>> {
238- let out = Command::new("ffmpeg")206+ let out = ec_testkit::ffmpeg()
239 .args(["-v", "error", "-i"])207 .args(["-v", "error", "-i"])
240 .arg(stream)208 .arg(stream)
241 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])209 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
@@ -291,7 +259,7 @@ fn x264_encode_gop(
291 stream.to_string_lossy().into_owned(),259 stream.to_string_lossy().into_owned(),
292 ]);260 ]);
293 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();261 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
294- run("ffmpeg", &refs).then_some(stream)262+ run(&refs).then_some(stream)
295 }263 }
296 264
297 /// Decode `stream` both ways and report the first frame that differs.265 /// Decode `stream` both ways and report the first frame that differs.
@@ -328,23 +296,13 @@ fn compare_sequence(stream: &Path) -> Result<usize, String> {
328 #[test]296 #[test]
329 fn jvt_cavlc_first_idr_bit_exact() {297 fn jvt_cavlc_first_idr_bit_exact() {
330 let base = vectors_dir();298 let base = vectors_dir();
331- if !require_fixtures(
332- &base,
333- "the JVT conformance vectors",
334- "scripts/fetch-vectors.sh",
335- ) {
336- return;
337- }
338 let mut passed = Vec::new();299 let mut passed = Vec::new();
339 let mut failed = Vec::new();300 let mut failed = Vec::new();
340 let mut refused = Vec::new();301 let mut refused = Vec::new();
341 for name in all_vectors(&base) {302 for name in all_vectors(&base) {
342 let name = name.as_str();303 let name = name.as_str();
343 let dir = base.join(name);304 let dir = base.join(name);
344- let Some(stream) = find_stream(&dir) else {305+ let stream = find_stream(&dir).unwrap_or_else(|| panic!("{name}: no bitstream file"));
345- eprintln!("SKIP {name}: no bitstream file");
346- continue;
347- };
348 let bytes = std::fs::read(&stream).unwrap();306 let bytes = std::fs::read(&stream).unwrap();
349 match decode_first(&bytes) {307 match decode_first(&bytes) {
350 Ok((ours, w, h)) => {308 Ok((ours, w, h)) => {
@@ -436,13 +394,6 @@ fn jvt_cavlc_first_idr_bit_exact() {
436 fn steady_state_decode_loop_zero_alloc() {394 fn steady_state_decode_loop_zero_alloc() {
437 install_counter();395 install_counter();
438 let base = vectors_dir();396 let base = vectors_dir();
439- if !require_fixtures(
440- &base,
441- "the JVT conformance vectors",
442- "scripts/fetch-vectors.sh",
443- ) {
444- return;
445- }
446 // One stream per entropy coder, and one with B slices and multiple397 // One stream per entropy coder, and one with B slices and multiple
447 // reference frames so the decoded picture buffer really recycles pictures.398 // reference frames so the decoded picture buffer really recycles pictures.
448 for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] {399 for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] {
@@ -523,13 +474,6 @@ fn steady_state_decode_loop_zero_alloc() {
523 #[test]474 #[test]
524 fn ns_per_macroblock_measurement() {475 fn ns_per_macroblock_measurement() {
525 let base = vectors_dir();476 let base = vectors_dir();
526- if !require_fixtures(
527- &base,
528- "the JVT conformance vectors",
529- "scripts/fetch-vectors.sh",
530- ) {
531- return;
532- }
533 for name in [477 for name in [
534 "BA1_Sony_D",478 "BA1_Sony_D",
535 "CI_MW_D",479 "CI_MW_D",
@@ -610,13 +554,6 @@ fn perf_whole_sequence() {
610 #[test]554 #[test]
611 fn corrupt_streams_never_panic() {555 fn corrupt_streams_never_panic() {
612 let base = vectors_dir();556 let base = vectors_dir();
613- if !require_fixtures(
614- &base,
615- "the JVT conformance vectors",
616- "scripts/fetch-vectors.sh",
617- ) {
618- return;
619- }
620 // One stream per entropy coder, plus one with B slices and multiple557 // One stream per entropy coder, plus one with B slices and multiple
621 // references: CABAC's arithmetic decoder indexes context and coefficient558 // references: CABAC's arithmetic decoder indexes context and coefficient
622 // arrays from stream-derived values, and inter prediction indexes the559 // arrays from stream-derived values, and inter prediction indexes the
@@ -682,9 +619,8 @@ fn corrupt_sweep(bytes: &[u8]) {
682 // ffmpeg's own decoder as the oracle.619 // ffmpeg's own decoder as the oracle.
683 // ---------------------------------------------------------------------------620 // ---------------------------------------------------------------------------
684 621
685-/// Run a command, false when it fails or is not installed.622+fn run(args: &[&str]) -> bool {
686-fn run(command: &str, args: &[&str]) -> bool {623+ ec_testkit::ffmpeg()
687- Command::new(command)
688 .args(args)624 .args(args)
689 .stdout(std::process::Stdio::null())625 .stdout(std::process::Stdio::null())
690 .stderr(std::process::Stdio::null())626 .stderr(std::process::Stdio::null())
@@ -693,13 +629,6 @@ fn run(command: &str, args: &[&str]) -> bool {
693 .unwrap_or(false)629 .unwrap_or(false)
694 }630 }
695 631
696-fn have_ffmpeg() -> bool {
697- run(
698- "ffmpeg",
699- &["-hide_banner", "-loglevel", "error", "-version"],
700- )
701-}
702-
703 /// A private scratch directory for one test.632 /// A private scratch directory for one test.
704 fn scratch(tag: &str) -> PathBuf {633 fn scratch(tag: &str) -> PathBuf {
705 let dir = std::env::temp_dir().join(format!("ec-h264-{tag}-{}", std::process::id()));634 let dir = std::env::temp_dir().join(format!("ec-h264-{tag}-{}", std::process::id()));
@@ -742,7 +671,7 @@ fn x264_encode(dir: &Path, tag: &str, size: &str, extra: &[&str]) -> Option<Path
742 stream.to_string_lossy().into_owned(),671 stream.to_string_lossy().into_owned(),
743 ]);672 ]);
744 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();673 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
745- run("ffmpeg", &refs).then_some(stream)674+ run(&refs).then_some(stream)
746 }675 }
747 676
748 /// Encode, decode both ways, return the number of differing bytes.677 /// Encode, decode both ways, return the number of differing bytes.
@@ -787,10 +716,6 @@ const ENTROPY_MODES: [(&str, &[&str]); 2] = [
787 /// produces, none of which the QCIF single-slice vectors cover.716 /// produces, none of which the QCIF single-slice vectors cover.
788 #[test]717 #[test]
789 fn geometry_and_slice_structure_match_ffmpeg() {718 fn geometry_and_slice_structure_match_ffmpeg() {
790- if !have_ffmpeg() {
791- eprintln!("SKIP: ffmpeg not on PATH");
792- return;
793- }
794 let dir = scratch("geometry");719 let dir = scratch("geometry");
795 let cases: &[(&str, &str, &[&str])] = &[720 let cases: &[(&str, &str, &[&str])] = &[
796 // 1080 lines are coded as 68 macroblock rows and cropped back to 1080.721 // 1080 lines are coded as 68 macroblock rows and cropped back to 1080.
@@ -851,10 +776,6 @@ fn geometry_and_slice_structure_match_ffmpeg() {
851 /// nothing else in the suite would notice it regressing into a refusal.776 /// nothing else in the suite would notice it regressing into a refusal.
852 #[test]777 #[test]
853 fn jvt_scaling_matrices_decode_bit_exact() {778 fn jvt_scaling_matrices_decode_bit_exact() {
854- if !have_ffmpeg() {
855- eprintln!("SKIP: ffmpeg not on PATH");
856- return;
857- }
858 let dir = scratch("scaling");779 let dir = scratch("scaling");
859 let extra = [780 let extra = [
860 "-profile:v",781 "-profile:v",
@@ -877,10 +798,6 @@ fn jvt_scaling_matrices_decode_bit_exact() {
877 /// prefixed — how an MP4 or Matroska demuxer hands H.264 over.798 /// prefixed — how an MP4 or Matroska demuxer hands H.264 over.
878 #[test]799 #[test]
879 fn avcc_extradata_and_length_prefixed_packets() {800 fn avcc_extradata_and_length_prefixed_packets() {
880- if !have_ffmpeg() {
881- eprintln!("SKIP: ffmpeg not on PATH");
882- return;
883- }
884 let dir = scratch("avcc");801 let dir = scratch("avcc");
885 let Some(annex_b) = x264_encode(802 let Some(annex_b) = x264_encode(
886 &dir,803 &dir,
@@ -960,10 +877,6 @@ fn avcc_extradata_and_length_prefixed_packets() {
960 /// once, so it is the first test to look at when any of them regress.877 /// once, so it is the first test to look at when any of them regress.
961 #[test]878 #[test]
962 fn p_only_gop_matches_ffmpeg_every_frame() {879 fn p_only_gop_matches_ffmpeg_every_frame() {
963- if !have_ffmpeg() {
964- eprintln!("SKIP: ffmpeg not on PATH");
965- return;
966- }
967 let dir = scratch("p-gop");880 let dir = scratch("p-gop");
968 let mut failures = Vec::new();881 let mut failures = Vec::new();
969 for (mode, profile) in ENTROPY_MODES {882 for (mode, profile) in ENTROPY_MODES {
@@ -992,13 +905,6 @@ fn p_only_gop_matches_ffmpeg_every_frame() {
992 #[test]905 #[test]
993 fn jvt_full_sequence_bit_exact() {906 fn jvt_full_sequence_bit_exact() {
994 let base = vectors_dir();907 let base = vectors_dir();
995- if !require_fixtures(
996- &base,
997- "the JVT conformance vectors",
998- "scripts/fetch-vectors.sh",
999- ) {
1000- return;
1001- }
1002 let mut table = String::new();908 let mut table = String::new();
1003 let mut passed = 0usize;909 let mut passed = 0usize;
1004 let mut refused = Vec::new();910 let mut refused = Vec::new();
@@ -1144,10 +1050,6 @@ fn slice_type_counts(bytes: &[u8]) -> [usize; 3] {
1144 /// they arrived.1050 /// they arrived.
1145 #[test]1051 #[test]
1146 fn b_pictures_match_ffmpeg_every_frame() {1052 fn b_pictures_match_ffmpeg_every_frame() {
1147- if !have_ffmpeg() {
1148- eprintln!("SKIP: ffmpeg not on PATH");
1149- return;
1150- }
1151 let dir = scratch("b-gop");1053 let dir = scratch("b-gop");
1152 let cases: &[(&str, &[&str])] = &[1054 let cases: &[(&str, &[&str])] = &[
1153 (1055 (
@@ -1227,10 +1129,6 @@ fn b_pictures_match_ffmpeg_every_frame() {
1227 /// test would pass on a decoder that never reorders anything.1129 /// test would pass on a decoder that never reorders anything.
1228 #[test]1130 #[test]
1229 fn output_is_display_order_and_the_reorder_is_real() {1131 fn output_is_display_order_and_the_reorder_is_real() {
1230- if !have_ffmpeg() {
1231- eprintln!("SKIP: ffmpeg not on PATH");
1232- return;
1233- }
1234 let dir = scratch("order");1132 let dir = scratch("order");
1235 let extra = [1133 let extra = [
1236 "-profile:v",1134 "-profile:v",
@@ -1296,10 +1194,6 @@ fn output_is_display_order_and_the_reorder_is_real() {
1296 /// preview after a seek.1194 /// preview after a seek.
1297 #[test]1195 #[test]
1298 fn a_frame_num_gap_keeps_decoding() {1196 fn a_frame_num_gap_keeps_decoding() {
1299- if !have_ffmpeg() {
1300- eprintln!("SKIP: ffmpeg not on PATH");
1301- return;
1302- }
1303 let dir = scratch("gap");1197 let dir = scratch("gap");
1304 let extra = [1198 let extra = [
1305 "-profile:v",1199 "-profile:v",
@@ -1359,10 +1253,6 @@ fn a_frame_num_gap_keeps_decoding() {
1359 /// inter prediction and reordering active.1253 /// inter prediction and reordering active.
1360 #[test]1254 #[test]
1361 fn geometry_with_motion_matches_ffmpeg() {1255 fn geometry_with_motion_matches_ffmpeg() {
1362- if !have_ffmpeg() {
1363- eprintln!("SKIP: ffmpeg not on PATH");
1364- return;
1365- }
1366 let dir = scratch("geometry-motion");1256 let dir = scratch("geometry-motion");
1367 let cases: &[(&str, &str, &[&str])] = &[1257 let cases: &[(&str, &str, &[&str])] = &[
1368 ("hd", "1920x1080", &["bframes=2:b-adapt=0"]),1258 ("hd", "1920x1080", &["bframes=2:b-adapt=0"]),
@@ -1511,96 +1401,10 @@ fn switching_slices_are_refused_by_name() {
1511 }1401 }
1512 }1402 }
1513 1403
1514-// ---------------------------------------------------------------------------
1515-// Real library: the files actually on this machine, not fixtures.
1516-// ---------------------------------------------------------------------------
1517-
1518-/// Compare a long stream against ffmpeg without holding it in memory: ffmpeg's
1519-/// raw output is consumed from a pipe one frame at a time, in step with our
1520-/// own decoding, so a 500-frame 1080p sweep costs two frames of memory rather
1521-/// than three gigabytes.
1522-fn compare_sequence_streamed(
1523- stream: &Path,
1524- frames_wanted: usize,
1525-) -> Result<StreamedResult, String> {
1526- use std::io::Read;
1527-
1528- let bytes = std::fs::read(stream).map_err(|e| e.to_string())?;
1529- let mut child = Command::new("ffmpeg")
1530- .args(["-v", "error", "-i"])
1531- .arg(stream)
1532- .args([
1533- "-frames:v",
1534- &frames_wanted.to_string(),
1535- "-f",
1536- "rawvideo",
1537- "-pix_fmt",
1538- "yuv420p",
1539- "-",
1540- ])
1541- .stdout(std::process::Stdio::piped())
1542- .stderr(std::process::Stdio::null())
1543- .spawn()
1544- .map_err(|e| e.to_string())?;
1545- let mut out = child.stdout.take().expect("piped stdout");
1546-
1547- let mut dec = Decoder::new();
1548- let mut reference = Vec::new();
1549- let mut result = StreamedResult::default();
1550- let mut oracle_open = true;
1551- let mut take = |frame: Vec<u8>, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1552- result.produced += 1;
1553- if !oracle_open || result.compared >= frames_wanted {
1554- return;
1555- }
1556- reference.resize(frame.len(), 0);
1557- if out.read_exact(reference).is_err() {
1558- oracle_open = false;
1559- return;
1560- }
1561- if let Some(pos) = first_diff(&frame, reference) {
1562- result.diffs.push((result.compared, pos));
1563- }
1564- result.compared += 1;
1565- };
1566-
1567- for nal in ec_h264_syntax::AnnexBIter::new(&bytes) {
1568- match dec.push_nal(nal) {
1569- Ok(NalOutcome::PictureBoundary) => {
1570- dec.end_picture().map_err(|e| format!("{e}"))?;
1571- dec.push_nal(nal).map_err(|e| format!("{e}"))?;
1572- }
1573- Ok(_) => {}
1574- Err(e) => return Err(format!("{e}")),
1575- }
1576- while let Some(f) = dec.next_frame() {
1577- take(frame_bytes(&f), &mut result, &mut reference);
1578- }
1579- }
1580- dec.flush().map_err(|e| format!("{e}"))?;
1581- while let Some(f) = dec.next_frame() {
1582- take(frame_bytes(&f), &mut result, &mut reference);
1583- }
1584- let _ = child.kill();
1585- let _ = child.wait();
1586- Ok(result)
1587-}
1588-
1589-/// Outcome of a streamed comparison.
1590-#[derive(Default)]
1591-struct StreamedResult {
1592- /// Frames this decoder produced.
1593- produced: usize,
1594- /// Frames the oracle also produced, and which were therefore compared.
1595- compared: usize,
1596- /// `(frame index, byte offset)` of each mismatch.
1597- diffs: Vec<(usize, usize)>,
1598-}
1599 1404
1600 /// Extract the video elementary stream of a real file as Annex B.1405 /// Extract the video elementary stream of a real file as Annex B.
1601 fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {1406 fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
1602 run(1407 run(
1603- "ffmpeg",
1604 &[1408 &[
1605 "-v",1409 "-v",
1606 "error",1410 "error",
@@ -1622,273 +1426,8 @@ fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
1622 )1426 )
1623 }1427 }
1624 1428
1625-/// The same comparison, but demuxed from the container by [`ec_mp4`] instead
1626-/// of extracted to Annex B by ffmpeg's bitstream filter.
1627-///
1628-/// Some real MP4s produce an elementary stream that ffmpeg itself then decodes
1629-/// only three frames of, silently. That is a property of the extraction, not of
1630-/// the file: reading the sample table directly and handing the `avcC` and the
1631-/// length-prefixed samples to the packet entry surface leaves the oracle able to
1632-/// decode the original file, so the comparison is real again.
1633-fn compare_container_streamed(
1634- source: &Path,
1635- frames_wanted: usize,
1636-) -> Result<StreamedResult, String> {
1637- use ec_core::registry::{Decoder as _, Demuxer as _};
1638- use std::io::Read;
1639-
1640- let file = std::fs::File::open(source).map_err(|e| e.to_string())?;
1641- let mut demux = ec_mp4::Mp4Demuxer::new(std::io::BufReader::new(file))
1642- .map_err(|e| format!("ec-mp4 open: {e}"))?;
1643- let (stream_index, params) = demux
1644- .streams()
1645- .iter()
1646- .find(|s| s.params.codec == ec_core::registry::CodecId::H264)
1647- .map(|s| (s.index, s.params.clone()))
1648- .ok_or("no H.264 track")?;
1649- let mut dec = ec_h264::H264Decoder::new(params).map_err(|e| format!("{e}"))?;
1650-
1651- let mut child = Command::new("ffmpeg")
1652- .args(["-v", "error", "-i"])
1653- .arg(source)
1654- .args([
1655- "-map",
1656- "0:v:0",
1657- "-frames:v",
1658- &frames_wanted.to_string(),
1659- "-f",
1660- "rawvideo",
1661- "-pix_fmt",
1662- "yuv420p",
1663- "-",
1664- ])
1665- .stdout(std::process::Stdio::piped())
1666- .stderr(std::process::Stdio::null())
1667- .spawn()
1668- .map_err(|e| e.to_string())?;
1669- let mut out = child.stdout.take().expect("piped stdout");
1670-
1671- let mut reference = Vec::new();
1672- let mut result = StreamedResult::default();
1673- let mut oracle_open = true;
1674- let mut take = |frame: Vec<u8>, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1675- result.produced += 1;
1676- if !oracle_open || result.compared >= frames_wanted {
1677- return;
1678- }
1679- reference.resize(frame.len(), 0);
1680- if out.read_exact(reference).is_err() {
1681- oracle_open = false;
1682- return;
1683- }
1684- if let Some(pos) = first_diff(&frame, reference) {
1685- result.diffs.push((result.compared, pos));
1686- }
1687- result.compared += 1;
1688- };
1689- let mut drain =
1690- |dec: &mut ec_h264::H264Decoder, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1691- while let Ok(ec_core::frame::Frame::Video(f)) = dec.receive_frame() {
1692- take(frame_bytes(&f), result, reference);
1693- }
1694- };
1695- while result.produced < frames_wanted {
1696- let packet = match demux.next_packet() {
1697- Ok(p) => p,
1698- Err(_) => break,
1699- };
1700- if packet.stream != stream_index {
1701- continue;
1702- }
1703- dec.send_packet(&packet).map_err(|e| format!("{e}"))?;
1704- drain(&mut dec, &mut result, &mut reference);
1705- }
1706- dec.flush().map_err(|e| format!("{e}"))?;
1707- drain(&mut dec, &mut result, &mut reference);
1708- let _ = child.kill();
1709- let _ = child.wait();
1710- Ok(result)
1711-}
1712-
1713-/// Decode real H.264 files from this machine's library, several hundred frames
1714-/// each, frame for frame against ffmpeg.
1715-///
1716-/// Synthetic clips and conformance vectors are both written by people trying to
1717-/// exercise a decoder. Real files are written by encoders tuned for size, at
1718-/// resolutions and GOP structures the fixtures never use, and they are the ones
1719-/// a user actually opens. Every file either decodes bit-exactly or is refused
1720-/// by name; a file that decodes to different pixels is a failure.
1721-// lane-h264reallib: LOCAL-ONLY, and the reason lives in the attribute so it
1722-// shows in `cargo test -- --list` instead of hiding in a skip print.
1723-//
1724-// The precondition is a PERSONAL MEDIA LIBRARY: the manifest is generated by
1725-// `scripts/scan-real-library.sh`, which scans `~/Videos ~/Downloads ~/Music`
1726-// by default and is gitignored precisely because it is machine-local. A
1727-// runner host has none of those directories, so both of this test's possible
1728-// behaviours there are wrong:
1729-//
1730-// - manifest absent -> the `SKIP: ... missing` early return, which prints
1731-// green. That is the silent-skip class this batch is removing: a green
1732-// that means "nothing was checked".
1733-// - manifest present but its absolute paths unresolvable (a host that ran
1734-// the scan script against an empty library) -> zero files swept and
1735-// `decoded >= 3` fails. That is the red every fleet run currently eats,
1736-// and it is red for a reason that has nothing to do with the decoder.
1737-//
1738-// Hence `#[ignore]` rather than an env gate: an env gate whose variable is
1739-// absent on the runner prints the same green the missing manifest already
1740-// prints, which is the defect rather than the fix. An ignore is visible in
1741-// `--list`, cannot go green silently, and leaves the assertion itself intact
1742-// -- "the sweep is the point" still holds on the machine that can run it.
1743-//
1744-// Run it on the workstation, where the library is:
1745-// cargo test -p ec-h264 --test conformance real_library_streams_match_ffmpeg -- --ignored
1746-#[ignore = "sweeps the PERSONAL media library (~/Videos, ~/Downloads, ~/Music) through the gitignored fixtures/real-library-manifest.tsv; MINUTES of wall time (measured past 840 s on the workstation), so workstation only -- budget an hour, it is not wedged. A runner host has no such library, so the test is either a silent green or a red for the wrong reason. Run it on the workstation with --ignored."]
1747-#[test]
1748-fn real_library_streams_match_ffmpeg() {
1749- if !have_ffmpeg() {
1750- eprintln!("SKIP: ffmpeg not on PATH");
1751- return;
1752- }
1753- let manifest =
1754- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
1755- let Ok(text) = std::fs::read_to_string(&manifest) else {
1756- eprintln!("SKIP: {} missing", manifest.display());
1757- return;
1758- };
1759- let dir = scratch("real-library");
1760- const FRAMES: usize = 500;
1761- /// A file counts as swept only when the oracle stayed with us this long.
1762- const MIN_FRAMES: usize = 100;
1763- let mut table = String::new();
1764- let mut decoded = 0usize;
1765- let mut refused = 0usize;
1766- let mut failures = Vec::new();
1767- let mut seen_containers = std::collections::BTreeSet::new();
1768-
1769- for line in text.lines().skip(1) {
1770- let mut f = line.split('\t');
1771- let (Some(path), Some(container), Some(vcodec)) = (f.next(), f.next(), f.next()) else {
1772- continue;
1773- };
1774- if vcodec != "h264" || !Path::new(path).is_file() {
1775- continue;
1776- }
1777- // One file per container family per resolution class keeps the sweep
1778- // to a few minutes while still covering both demuxers.
1779- let width = f.next().unwrap_or("0");
1780- let key = (container.to_string(), width.to_string());
1781- if !seen_containers.insert(key) {
1782- continue;
1783- }
1784- let name: String = Path::new(path)
1785- .file_name()
1786- .map(|n| n.to_string_lossy().chars().take(38).collect())
1787- .unwrap_or_default();
1788- let annexb = dir.join("stream.264");
1789- if !extract_annexb(Path::new(path), &annexb, FRAMES) {
1790- table.push_str(&format!("{name:<40} {container:<12} not extractable\n"));
1791- continue;
1792- }
1793- match compare_sequence_streamed(&annexb, FRAMES) {
1794- Ok(r) if !r.diffs.is_empty() => {
1795- failures.push(format!(
1796- "{name}: {} of {} frames differ",
1797- r.diffs.len(),
1798- r.compared
1799- ));
1800- table.push_str(&format!(
1801- "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {}\n",
1802- r.diffs.len(),
1803- r.compared
1804- ));
1805- }
1806- // The oracle stopped before we did: ffmpeg gave up on the elementary
1807- // stream its own bitstream filter produced. That is a property of
1808- // the extraction, so the file is re-run straight out of the
1809- // container, where the oracle can read the original samples.
1810- Ok(r) if r.compared < r.produced.min(MIN_FRAMES) => {
1811- match compare_container_streamed(Path::new(path), FRAMES) {
1812- Ok(c) if !c.diffs.is_empty() => {
1813- failures.push(format!(
1814- "{name} (container demux): {} of {} frames differ",
1815- c.diffs.len(),
1816- c.compared
1817- ));
1818- table.push_str(&format!(
1819- "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {} \
1820- (container demux)\n",
1821- c.diffs.len(),
1822- c.compared
1823- ));
1824- }
1825- Ok(c) if c.compared >= MIN_FRAMES => {
1826- decoded += 1;
1827- table.push_str(&format!(
1828- "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact \
1829- (container demux)\n",
1830- c.compared
1831- ));
1832- }
1833- Ok(c) => {
1834- table.push_str(&format!(
1835- "{name:<40} {container:<12} {width:>5}px oracle short both ways: \
1836- ffmpeg gave {} frames, we decoded {}\n",
1837- c.compared, c.produced
1838- ));
1839- }
1840- Err(e) => {
1841- table.push_str(&format!(
1842- "{name:<40} {container:<12} {width:>5}px oracle short, container \
1843- demux failed: {e}\n"
1844- ));
1845- }
1846- }
1847- }
1848- Ok(r) => {
1849- decoded += 1;
1850- table.push_str(&format!(
1851- "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact\n",
1852- r.compared
1853- ));
1854- }
1855- Err(e) if e.contains("unsupported") => {
1856- refused += 1;
1857- table.push_str(&format!(
1858- "{name:<40} {container:<12} {width:>5}px refused: {e}\n"
1859- ));
1860- }
1861- Err(e) => {
1862- failures.push(format!("{name}: {e}"));
1863- table.push_str(&format!(
1864- "{name:<40} {container:<12} {width:>5}px ERROR {e}\n"
1865- ));
1866- }
1867- }
1868- }
1869- let _ = std::fs::remove_dir_all(&dir);
1870- eprintln!("{table}");
1871- eprintln!("real library: {decoded} decoded bit-exact, {refused} refused by name");
1872- assert!(failures.is_empty(), "{failures:#?}");
1873- assert!(
1874- decoded >= 3,
1875- "only {decoded} real files swept end to end; the sweep is the point"
1876- );
1877-}
1878-
1879-/// The registry entry surface, driven the way a demuxer drives it: one access
1880-/// unit per packet, frames pulled with `receive_frame`.
1881-///
1882-/// This is where display order has to actually arrive. Everything above tests
1883-/// the NAL-level API; a player never touches that one, so a reordering decoder
1884-/// whose packet API still hands back decode order would look correct in every
1885-/// other test here and wrong on screen.
1886 #[test]1429 #[test]
1887 fn packet_entry_surface_reorders_and_carries_timestamps() {1430 fn packet_entry_surface_reorders_and_carries_timestamps() {
1888- if !have_ffmpeg() {
1889- eprintln!("SKIP: ffmpeg not on PATH");
1890- return;
1891- }
1892 let dir = scratch("entry");1431 let dir = scratch("entry");
1893 let extra = [1432 let extra = [
1894 "-profile:v",1433 "-profile:v",
@@ -2004,10 +1543,6 @@ fn packet_entry_surface_reorders_and_carries_timestamps() {
2004 /// are what makes the two readings differ at all, so this needs `-refs`.1543 /// are what makes the two readings differ at all, so this needs `-refs`.
2005 #[test]1544 #[test]
2006 fn spatial_direct_over_a_b_reference_matches_ffmpeg() {1545 fn spatial_direct_over_a_b_reference_matches_ffmpeg() {
2007- if !have_ffmpeg() {
2008- eprintln!("SKIP: ffmpeg not on PATH");
2009- return;
2010- }
2011 let dir = scratch("direct-bref");1546 let dir = scratch("direct-bref");
2012 let mut failures = Vec::new();1547 let mut failures = Vec::new();
2013 for (tag, coder) in [("cabac", "ac"), ("cavlc", "0")] {1548 for (tag, coder) in [("cabac", "ac"), ("cavlc", "0")] {
@@ -2073,10 +1608,6 @@ fn pps_enables_8x8(stream: &Path) -> bool {
2073 /// 8x8 macroblock alone (8.7).1608 /// 8x8 macroblock alone (8.7).
2074 #[test]1609 #[test]
2075 fn high_profile_8x8_inter_sequences_match_ffmpeg() {1610 fn high_profile_8x8_inter_sequences_match_ffmpeg() {
2076- if !have_ffmpeg() {
2077- eprintln!("SKIP: ffmpeg not on PATH");
2078- return;
2079- }
2080 let dir = scratch("high8x8-seq");1611 let dir = scratch("high8x8-seq");
2081 let mut failures = Vec::new();1612 let mut failures = Vec::new();
2082 let cases: &[(&str, &[&str])] = &[1613 let cases: &[(&str, &[&str])] = &[
@@ -2160,18 +1691,7 @@ fn high_profile_8x8_inter_sequences_match_ffmpeg() {
2160 /// picture itself, per D.2.8 absent a recovery_point SEI.1691 /// picture itself, per D.2.8 absent a recovery_point SEI.
2161 #[test]1692 #[test]
2162 fn h264_seek_matches_linear_open_gop() {1693 fn h264_seek_matches_linear_open_gop() {
2163- if !have_ffmpeg() {1694+ let src = ec_testkit::fixture("video/h264-open-gop.mp4");
2164- eprintln!("SKIP: ffmpeg not on PATH");
2165- return;
2166- }
2167- let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/video/h264-open-gop.mp4");
2168- if !require_fixtures(
2169- &src,
2170- "the open-GOP fixture",
2171- "scripts/gen-fixtures.sh (fixtures/video/h264-open-gop.mp4)",
2172- ) {
2173- return;
2174- }
2175 let dir = scratch("open-gop");1695 let dir = scratch("open-gop");
2176 std::fs::create_dir_all(&dir).unwrap();1696 std::fs::create_dir_all(&dir).unwrap();
2177 let annexb = dir.join("open-gop.264");1697 let annexb = dir.join("open-gop.264");
crates/ec-h264/tests/it/common.rsmodified+2 -3
@@ -2,7 +2,6 @@
2 //! ffmpeg pipes and stream utilities that were identical in each file.2 //! ffmpeg pipes and stream utilities that were identical in each file.
3 3
4 use std::path::{Path, PathBuf};4 use std::path::{Path, PathBuf};
5-use std::process::Command;
6 5
7 use ec_core::frame::{PixelFormat, VideoFrame};6 use ec_core::frame::{PixelFormat, VideoFrame};
8 7
@@ -25,7 +24,7 @@ pub(super) fn frame_bytes(frame: &VideoFrame) -> Vec<u8> {
25 }24 }
26 25
27 pub(super) fn ffmpeg_frames(stream: &Path, pix_fmt: &str, frame_len: usize) -> Option<Vec<u8>> {26 pub(super) fn ffmpeg_frames(stream: &Path, pix_fmt: &str, frame_len: usize) -> Option<Vec<u8>> {
28- let out = Command::new("ffmpeg")27+ let out = ec_testkit::ffmpeg()
29 .args(["-v", "error", "-i"])28 .args(["-v", "error", "-i"])
30 .arg(stream)29 .arg(stream)
31 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])30 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -78,7 +77,7 @@ pub(super) fn layout(f: PixelFormat) -> (usize, usize, usize) {
78 }77 }
79 78
80 pub(super) fn ffmpeg_pix_frames(stream: &Path, pix_fmt: &str) -> Option<Vec<u8>> {79 pub(super) fn ffmpeg_pix_frames(stream: &Path, pix_fmt: &str) -> Option<Vec<u8>> {
81- let out = Command::new("ffmpeg")80+ let out = ec_testkit::ffmpeg()
82 .args(["-v", "error", "-f", "h264", "-i"])81 .args(["-v", "error", "-f", "h264", "-i"])
83 .arg(stream)82 .arg(stream)
84 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])83 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
crates/ec-h264/tests/it/encode.rsmodified+13 -110
@@ -427,39 +427,6 @@ fn all_intra_when_the_gop_is_one() {
427 // absent, exactly like the conformance suite's ffmpeg cross-check.427 // absent, exactly like the conformance suite's ffmpeg cross-check.
428 // ---------------------------------------------------------------------------428 // ---------------------------------------------------------------------------
429 429
430-fn have_ffmpeg() -> bool {
431- std::process::Command::new("ffmpeg")
432- .arg("-version")
433- .stdout(std::process::Stdio::null())
434- .stderr(std::process::Stdio::null())
435- .status()
436- .is_ok_and(|s| s.success())
437-}
438-
439-/// Fixture-presence probe for `<what this test needs>`.
440-/// Returns whether the fixture is present, but never silently: under
441-/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path
442-/// and the script that regenerates it, so a host whose fixture library drifted
443-/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure;
444-/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently
445-/// short-circuited because the probe ran first in a compound `if`).
446-///
447-/// Order is load-bearing: probe, assert, return. Never merge the probe into
448-/// the same `if` as the escape.
449-fn require_fixture(path: &std::path::Path, generator: &str) -> bool {
450- let present = path.exists();
451- assert!(
452- present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
453- "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}",
454- path.display(),
455- generator
456- );
457- if !present {
458- eprintln!("SKIP: fixture {} absent", path.display());
459- }
460- present
461-}
462-
463 /// Write `bytes` to `path` and PROVE the file on disk is exactly that long.430 /// Write `bytes` to `path` and PROVE the file on disk is exactly that long.
464 ///431 ///
465 /// lane-h26xpinloud: every write below used `std::fs::write(..).ok()?` and then432 /// lane-h26xpinloud: every write below used `std::fs::write(..).ok()?` and then
@@ -635,7 +602,7 @@ fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option<Ve
635 SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)602 SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
636 ));603 ));
637 pin_or_bail("ffmpeg_decode", &path, stream)?;604 pin_or_bail("ffmpeg_decode", &path, stream)?;
638- let mut cmd = std::process::Command::new("ffmpeg");605+ let mut cmd = ec_testkit::ffmpeg();
639 cmd.args(["-v", "error"]);606 cmd.args(["-v", "error"]);
640 cmd.args(extra);607 cmd.args(extra);
641 cmd.arg("-i").arg(&path);608 cmd.arg("-i").arg(&path);
@@ -777,10 +744,6 @@ fn eight_by_eight_gains_on_flat_and_text() {
777 /// across a QP sweep and at a size that is not a multiple of a macroblock.744 /// across a QP sweep and at a size that is not a multiple of a macroblock.
778 #[test]745 #[test]
779 fn ffmpeg_decodes_bit_exactly() {746 fn ffmpeg_decodes_bit_exactly() {
780- if !have_ffmpeg() {
781- eprintln!("SKIP ffmpeg_decodes_bit_exactly: no ffmpeg on PATH");
782- return;
783- }
784 let mut t8x8_mbs = (0, 0);747 let mut t8x8_mbs = (0, 0);
785 for (w, h) in [(176, 144), (322, 242)] {748 for (w, h) in [(176, 144), (322, 242)] {
786 for qp in [10, 20, 28, 37, 47] {749 for qp in [10, 20, 28, 37, 47] {
@@ -813,10 +776,6 @@ fn ffmpeg_decodes_bit_exactly() {
813 /// The same stream under constant bitrate, which is the mode edith exports in.776 /// The same stream under constant bitrate, which is the mode edith exports in.
814 #[test]777 #[test]
815 fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {778 fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {
816- if !have_ffmpeg() {
817- eprintln!("SKIP ffmpeg_decodes_a_cbr_stream_bit_exactly: no ffmpeg on PATH");
818- return;
819- }
820 let (w, h) = (352, 288);779 let (w, h) = (352, 288);
821 let (stream, recons, _) = encode_clip(w, h, 12, |cfg| {780 let (stream, recons, _) = encode_clip(w, h, 12, |cfg| {
822 cfg.bitrate = 2_000_000;781 cfg.bitrate = 2_000_000;
@@ -839,8 +798,8 @@ fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {
839 /// software decoder says about it.798 /// software decoder says about it.
840 #[test]799 #[test]
841 fn vaapi_decodes_our_stream() {800 fn vaapi_decodes_our_stream() {
842- if !have_ffmpeg() || !std::path::Path::new("/dev/dri/renderD128").exists() {801+ if !std::path::Path::new("/dev/dri/renderD128").exists() {
843- eprintln!("SKIP vaapi_decodes_our_stream: no ffmpeg or no render node");802+ eprintln!("SKIP vaapi_decodes_our_stream: no render node");
844 return;803 return;
845 }804 }
846 let (w, h) = (352, 288);805 let (w, h) = (352, 288);
@@ -882,50 +841,10 @@ fn vaapi_decodes_our_stream() {
882 fn real_library_frames_encode_and_decode_exactly() {841 fn real_library_frames_encode_and_decode_exactly() {
883 use ec_core::registry::Decoder as _;842 use ec_core::registry::Decoder as _;
884 843
885- if !have_ffmpeg() {844+ let path = ec_testkit::fixture("open/sintel_trailer-720p.mp4");
886- eprintln!("SKIP real_library_frames: no ffmpeg on PATH");845+ let (w, h) = (1280, 720);
887- return;
888- }
889- let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
890- .join("../../fixtures/real-library-manifest.tsv");
891- if !require_fixture(&manifest, "scripts/scan-real-library.sh") {
892- return;
893- }
894- let text = std::fs::read_to_string(&manifest).expect("manifest reads");
895- // The first 8-bit 4:2:0 H.264 mp4 of at least 720p in the manifest.
896- let mut source = None;
897- for line in text.lines().skip(1) {
898- let f: Vec<&str> = line.split('\t').collect();
899- if f.len() < 7 || f[2] != "h264" || f[5] != "yuv420p" {
900- continue;
901- }
902- let (Ok(w), Ok(h)) = (f[3].parse::<usize>(), f[4].parse::<usize>()) else {
903- continue;
904- };
905- if w < 1280 || h < 720 || !w.is_multiple_of(2) || !h.is_multiple_of(2) {
906- continue;
907- }
908- if !f[1].contains("mp4") || !std::path::Path::new(f[0]).exists() {
909- continue;
910- }
911- source = Some((f[0].to_string(), w, h));
912- break;
913- }
914- let Some((path, w, h)) = source else {
915- // A manifest with no qualifying row is a corpus that drifted, not a
916- // reason to report PASS for a sweep that never ran.
917- assert!(
918- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
919- "EC_REQUIRE_FIXTURES=1 but {} lists no H.264 4:2:0 mp4 of at least \
920- 720p -- regenerate with: scripts/scan-real-library.sh",
921- manifest.display()
922- );
923- eprintln!("SKIP real_library_frames: no H.264 4:2:0 mp4 in the manifest");
924- return;
925- };
926 846
927- // Decode a handful of real pictures.847+ let (params, mut demux, index) = open_h264_source(path.as_os_str());
928- let (params, mut demux, index) = open_h264_source(std::ffi::OsStr::new(&path));
929 let mut dec = ec_h264::H264Decoder::new(params).expect("decoder");848 let mut dec = ec_h264::H264Decoder::new(params).expect("decoder");
930 let mut sources: Vec<Planes> = Vec::new();849 let mut sources: Vec<Planes> = Vec::new();
931 while sources.len() < 12 {850 while sources.len() < 12 {
@@ -1124,12 +1043,10 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
1124 /// EC_H264_CLIP=<file> cargo test --release -p ec-h264 --test encode \1043 /// EC_H264_CLIP=<file> cargo test --release -p ec-h264 --test encode \
1125 /// real_clip_t8x8_bd_psnr -- --ignored --nocapture1044 /// real_clip_t8x8_bd_psnr -- --ignored --nocapture
1126 #[test]1045 #[test]
1127-#[ignore = "set EC_H264_CLIP to a media file of yours"]1046+#[ignore = "slow measurement on the open 480p trailer"]
1128 fn real_clip_t8x8_bd_psnr() {1047 fn real_clip_t8x8_bd_psnr() {
1129- let Some(path) = std::env::var_os("EC_H264_CLIP") else {1048+ let path = ec_testkit::fixture("open/sintel_trailer-480p.mp4");
1130- panic!("EC_H264_CLIP must name a media file");1049+ let (w, h, sources) = clip_sources(path.as_os_str(), 30);
1131- };
1132- let (w, h, sources) = clip_sources(&path, 30);
1133 1050
1134 let run = |t8x8: bool, qp: i32| {1051 let run = |t8x8: bool, qp: i32| {
1135 let mut cfg = EncoderConfig::new(w as u32, h as u32);1052 let mut cfg = EncoderConfig::new(w as u32, h as u32);
@@ -1200,7 +1117,7 @@ fn real_clip_t8x8_bd_psnr() {
1200 const BD_PSNR_VS_X264_FLOOR: f64 = -4.15;1117 const BD_PSNR_VS_X264_FLOOR: f64 = -4.15;
1201 1118
1202 fn have_x264() -> bool {1119 fn have_x264() -> bool {
1203- std::process::Command::new("ffmpeg")1120+ ec_testkit::ffmpeg()
1204 .args(["-v", "error", "-hide_banner", "-encoders"])1121 .args(["-v", "error", "-hide_banner", "-encoders"])
1205 .output()1122 .output()
1206 .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx264"))1123 .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx264"))
@@ -1228,7 +1145,7 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) ->
1228 buf.extend_from_slice(v);1145 buf.extend_from_slice(v);
1229 }1146 }
1230 pin_or_bail("x264_encode_qp", &raw, &buf)?;1147 pin_or_bail("x264_encode_qp", &raw, &buf)?;
1231- let status = std::process::Command::new("ffmpeg")1148+ let status = ec_testkit::ffmpeg()
1232 .args(["-v", "error", "-y"])1149 .args(["-v", "error", "-y"])
1233 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])1150 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
1234 .args(["-s", &format!("{w}x{h}"), "-r", "1"])1151 .args(["-s", &format!("{w}x{h}"), "-r", "1"])
@@ -1310,14 +1227,7 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) ->
1310 /// bd_psnr_vs_x264 -- --nocapture1227 /// bd_psnr_vs_x264 -- --nocapture
1311 #[test]1228 #[test]
1312 fn bd_psnr_vs_x264() {1229 fn bd_psnr_vs_x264() {
1313- if !have_ffmpeg() || !have_x264() {1230+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
1314- eprintln!(
1315- "SKIP bd_psnr_vs_x264: no ffmpeg with libx264 on PATH. \
1316- Install one, then: cargo test --release -p ec-h264 --test encode \
1317- bd_psnr_vs_x264 -- --nocapture"
1318- );
1319- return;
1320- }
1321 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {1231 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
1322 Some(path) => clip_sources(&path, 24),1232 Some(path) => clip_sources(&path, 24),
1323 None => {1233 None => {
@@ -1485,10 +1395,7 @@ fn bd_psnr_vs_x264() {
1485 /// bit_account_vs_x264 -- --nocapture1395 /// bit_account_vs_x264 -- --nocapture
1486 #[test]1396 #[test]
1487 fn bit_account_vs_x264() {1397 fn bit_account_vs_x264() {
1488- if !have_ffmpeg() || !have_x264() {1398+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
1489- eprintln!("SKIP bit_account_vs_x264: no ffmpeg with libx264 on PATH");
1490- return;
1491- }
1492 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {1399 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
1493 Some(path) => clip_sources(&path, 12),1400 Some(path) => clip_sources(&path, 12),
1494 None => {1401 None => {
@@ -1578,10 +1485,6 @@ fn bit_account_vs_x264() {
1578 /// never a `sub_mb_type` -- in front of another decoder. This does.1485 /// never a `sub_mb_type` -- in front of another decoder. This does.
1579 #[test]1486 #[test]
1580 fn balanced_partitions_decode_bit_exactly() {1487 fn balanced_partitions_decode_bit_exactly() {
1581- if !have_ffmpeg() {
1582- eprintln!("SKIP balanced_partitions_decode_bit_exactly: no ffmpeg on PATH");
1583- return;
1584- }
1585 let (w, h) = (176, 144);1488 let (w, h) = (176, 144);
1586 let mut shapes = ec_h264::MbShapes::default();1489 let mut shapes = ec_h264::MbShapes::default();
1587 for qp in [16, 26, 36] {1490 for qp in [16, 26, 36] {
crates/ec-h264/tests/it/high10.rsmodified+4 -16
@@ -5,12 +5,8 @@
5 //! 1. Committed fixtures in `tests/data/high10/`: tiny libx264 streams with the5 //! 1. Committed fixtures in `tests/data/high10/`: tiny libx264 streams with the
6 //! MD5 of ffmpeg's decode beside them, checked on every run with no ffmpeg.6 //! MD5 of ffmpeg's decode beside them, checked on every run with no ffmpeg.
7 //! 2. A sweep that encodes synthetic sources with libx264 (`-profile:v high10`)7 //! 2. A sweep that encodes synthetic sources with libx264 (`-profile:v high10`)
8-//! and compares every frame with ffmpeg's decode. It skips, saying so, when
9-//! ffmpeg or a 10-bit libx264 is absent, and fails instead when
10-//! `EC_REQUIRE_FIXTURES` is set.
11 8
12 use std::path::{Path, PathBuf};9 use std::path::{Path, PathBuf};
13-use std::process::Command;
14 10
15 use ec_core::frame::{PixelFormat, VideoFrame};11 use ec_core::frame::{PixelFormat, VideoFrame};
16 use ec_h264::{Decoder, NalOutcome};12 use ec_h264::{Decoder, NalOutcome};
@@ -54,7 +50,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, ec_h264::Error> {
54 }50 }
55 51
56 fn ffmpeg_frames(stream: &Path, frame_len: usize) -> Option<Vec<u8>> {52 fn ffmpeg_frames(stream: &Path, frame_len: usize) -> Option<Vec<u8>> {
57- let out = Command::new("ffmpeg")53+ let out = ec_testkit::ffmpeg()
58 .args(["-v", "error", "-i"])54 .args(["-v", "error", "-i"])
59 .arg(stream)55 .arg(stream)
60 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-"])56 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-"])
@@ -202,22 +198,14 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
202 "h264".into(),198 "h264".into(),
203 stream.to_string_lossy().into_owned(),199 stream.to_string_lossy().into_owned(),
204 ]);200 ]);
205- let st = Command::new("ffmpeg").args(&args).status().ok()?;201+ let st = ec_testkit::ffmpeg().args(&args).status().ok()?;
206 st.success().then_some(stream)202 st.success().then_some(stream)
207 }203 }
208 204
209 fn check(c: &Case) -> Result<usize, String> {205 fn check(c: &Case) -> Result<usize, String> {
210 let dir = scratch();206 let dir = scratch();
211- let Some(stream) = encode(&dir, c) else {207+ let stream =
212- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {208+ encode(&dir, c).unwrap_or_else(|| panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag));
213- panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag);
214- }
215- eprintln!(
216- "SKIP {}: ffmpeg with 10-bit libx264 is not available",
217- c.tag
218- );
219- return Ok(0);
220- };
221 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;209 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
222 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;210 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
223 let first = ours.first().ok_or("no frames decoded")?;211 let first = ours.first().ok_or("no frames decoded")?;
crates/ec-h264/tests/it/high422.rsmodified+4 -22
@@ -3,14 +3,8 @@
3 //! with B-frames, CABAC and CAVLC, the 8x8 transform, weighted prediction,3 //! with B-frames, CABAC and CAVLC, the 8x8 transform, weighted prediction,
4 //! scaling matrices, chroma QP offsets, several slices, progressive and4 //! scaling matrices, chroma QP offsets, several slices, progressive and
5 //! MBAFF, at 8 and 10 bits.5 //! MBAFF, at 8 and 10 bits.
6-//!
7-//! Every case is generated in the test (no committed binaries). A case skips,
8-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
9-//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be
10-//! opt-in: set `EC_H264_HI422_HD=1` (the lane gate does).
11 6
12 use std::path::{Path, PathBuf};7 use std::path::{Path, PathBuf};
13-use std::process::Command;
14 8
15 use ec_h264::{Decoder, NalOutcome};9 use ec_h264::{Decoder, NalOutcome};
16 10
@@ -72,7 +66,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
72 } else {66 } else {
73 c.params.to_string()67 c.params.to_string()
74 };68 };
75- let st = Command::new("ffmpeg")69+ let st = ec_testkit::ffmpeg()
76 .args([70 .args([
77 "-hide_banner",71 "-hide_banner",
78 "-loglevel",72 "-loglevel",
@@ -99,16 +93,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
99 93
100 fn check(c: &Case) -> Result<usize, String> {94 fn check(c: &Case) -> Result<usize, String> {
101 let dir = scratch();95 let dir = scratch();
102- let Some(stream) = encode(&dir, c) else {96+ let stream = encode(&dir, c)
103- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {97+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
104- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
105- }
106- eprintln!(
107- "SKIP {}: ffmpeg with the needed libx264 is not available",
108- c.tag
109- );
110- return Ok(0);
111- };
112 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;98 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
113 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;99 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
114 let first = ours100 let first = ours
@@ -377,13 +363,9 @@ fn x264_hi422_mbaff() {
377 sweep(&cases);363 sweep(&cases);
378 }364 }
379 365
380-/// 1920x1080 intra and long-GOP, progressive and MBAFF (opt-in, slow).366+/// 1920x1080 intra and long-GOP, progressive and MBAFF (slow).
381 #[test]367 #[test]
382 fn x264_hi422_hd() {368 fn x264_hi422_hd() {
383- if std::env::var_os("EC_H264_HI422_HD").is_none() {
384- eprintln!("SKIP x264_hi422_hd: set EC_H264_HI422_HD=1");
385- return;
386- }
387 sweep(&[369 sweep(&[
388 case("hd-i-cabac", "testsrc2", "1920x1080", 2, "keyint=1"),370 case("hd-i-cabac", "testsrc2", "1920x1080", 2, "keyint=1"),
389 case(371 case(
crates/ec-h264/tests/it/high422_jvt.rsmodified+8 -41
@@ -5,13 +5,9 @@
5 //! Where the archive carries a reference YUV (Hi422FR10..15) each frame is5 //! Where the archive carries a reference YUV (Hi422FR10..15) each frame is
6 //! compared to it; the other streams ship only a trace, so every stream is6 //! compared to it; the other streams ship only a trace, so every stream is
7 //! also compared frame by frame with ffmpeg's decode (`yuv422p` or7 //! also compared frame by frame with ffmpeg's decode (`yuv422p` or
8-//! `yuv422p10le`). Fixtures live in the gitignored root `fixtures/`
9-//! (`scripts/fetch-vectors.sh h264-jvt`); a missing set skips with a message,
10-//! or fails when `EC_REQUIRE_FIXTURES` is set. The two 1920x1088 field
11 //! streams are slow in a debug build and are skipped there.8 //! streams are slow in a debug build and are skipped there.
12 9
13 use std::path::{Path, PathBuf};10 use std::path::{Path, PathBuf};
14-use std::process::Command;
15 11
16 use ec_core::frame::PixelFormat;12 use ec_core::frame::PixelFormat;
17 use ec_h264::{Decoder, NalOutcome};13 use ec_h264::{Decoder, NalOutcome};
@@ -19,7 +15,7 @@ use ec_h264::{Decoder, NalOutcome};
19 use super::common::{ffmpeg_pix_frames, frame_bytes};15 use super::common::{ffmpeg_pix_frames, frame_bytes};
20 16
21 fn root() -> PathBuf {17 fn root() -> PathBuf {
22- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi422")18+ ec_testkit::fixture("vectors/h264-jvt-hi422")
23 }19 }
24 20
25 /// Every elementary stream (`.264`, `.jsv`) below `dir`, sorted.21 /// Every elementary stream (`.264`, `.jsv`) below `dir`, sorted.
@@ -90,38 +86,19 @@ fn compare(name: &str, ours: &[Vec<u8>], theirs: &[u8], who: &str) -> Result<(),
90 Ok(())86 Ok(())
91 }87 }
92 88
93-fn have_set() -> Option<Vec<PathBuf>> {89+fn have_set() -> Vec<PathBuf> {
94 let list = streams(&root());90 let list = streams(&root());
95- if list.is_empty() {91+ assert!(list.len() >= 18, "only {} Hi422 streams found", list.len());
96- assert!(92+ list
97- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
98- "h264-jvt-hi422 missing at {} - this gate would prove nothing; run \
99- scripts/fetch-vectors.sh h264-jvt",
100- root().display()
101- );
102- eprintln!("SKIP h264-jvt-hi422 missing at {}", root().display());
103- return None;
104- }
105- Some(list)
106 }93 }
107 94
108 #[test]95 #[test]
109 fn jvt_hi422_vectors_bit_exact() {96 fn jvt_hi422_vectors_bit_exact() {
110- let Some(list) = have_set() else { return };97+ let list = have_set();
111- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
112- assert!(list.len() >= 18, "only {} Hi422 streams found", list.len());
113- }
114- let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok();
115 let mut failed = Vec::new();98 let mut failed = Vec::new();
116 let mut exact = Vec::new();99 let mut exact = Vec::new();
117 for path in &list {100 for path in &list {
118 let name = path.file_stem().unwrap().to_string_lossy().to_string();101 let name = path.file_stem().unwrap().to_string_lossy().to_string();
119- if cfg!(debug_assertions)
120- && matches!(name.as_str(), "Hi422FREXT16_SONY_A" | "Hi422FREXT17_SONY_A")
121- {
122- eprintln!("SKIP {name}: 1920x1088 field stream, release builds only");
123- continue;
124- }
125 let bytes = std::fs::read(path).unwrap();102 let bytes = std::fs::read(path).unwrap();
126 let (ours, format) = match decode_all(&bytes) {103 let (ours, format) = match decode_all(&bytes) {
127 Ok(v) => v,104 Ok(v) => v,
@@ -148,27 +125,17 @@ fn jvt_hi422_vectors_bit_exact() {
148 ok = false;125 ok = false;
149 }126 }
150 }127 }
151- if have_ffmpeg {
152 let pix = if format == PixelFormat::I210 {128 let pix = if format == PixelFormat::I210 {
153 "yuv422p10le"129 "yuv422p10le"
154 } else {130 } else {
155 "yuv422p"131 "yuv422p"
156 };132 };
157- match ffmpeg_pix_frames(path, pix) {133+ let theirs =
158- Some(t) => {134+ ffmpeg_pix_frames(path, pix).unwrap_or_else(|| panic!("{name}: ffmpeg cannot decode"));
159- if let Err(e) = compare(&name, &ours, &t, "ffmpeg") {135+ if let Err(e) = compare(&name, &ours, &theirs, "ffmpeg") {
160 failed.push(e);136 failed.push(e);
161 ok = false;137 ok = false;
162 }138 }
163- }
164- None => {
165- assert!(
166- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
167- "{name}: ffmpeg cannot decode"
168- );
169- }
170- }
171- }
172 if ok {139 if ok {
173 exact.push(format!("{name} ({} frames, {format:?})", ours.len()));140 exact.push(format!("{name} ({} frames, {format:?})", ours.len()));
174 }141 }
crates/ec-h264/tests/it/high444.rsmodified+4 -22
@@ -9,14 +9,8 @@
9 //! on the luma plane against ffmpeg's `gray` / `gray10le`; chroma must be 128,9 //! on the luma plane against ffmpeg's `gray` / `gray10le`; chroma must be 128,
10 //! or 512 at 10 bits). Separate colour planes cannot be written by x264; the10 //! or 512 at 10 bits). Separate colour planes cannot be written by x264; the
11 //! JVT vectors (`high444_jvt.rs`) cover them.11 //! JVT vectors (`high444_jvt.rs`) cover them.
12-//!
13-//! Every case is generated in the test (no committed binaries). A case skips,
14-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
15-//! when `EC_REQUIRE_FIXTURES` is set. The 1280x720 cases are opt-in:
16-//! set `EC_H264_HI444_HD=1`.
17 12
18 use std::path::{Path, PathBuf};13 use std::path::{Path, PathBuf};
19-use std::process::Command;
20 14
21 use ec_core::frame::{PixelFormat, VideoFrame};15 use ec_core::frame::{PixelFormat, VideoFrame};
22 use ec_h264::{Decoder, NalOutcome};16 use ec_h264::{Decoder, NalOutcome};
@@ -93,7 +87,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
93 } else {87 } else {
94 c.params.to_string()88 c.params.to_string()
95 };89 };
96- let st = Command::new("ffmpeg")90+ let st = ec_testkit::ffmpeg()
97 .args([91 .args([
98 "-hide_banner",92 "-hide_banner",
99 "-loglevel",93 "-loglevel",
@@ -121,16 +115,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
121 115
122 fn check(c: &Case) -> Result<usize, String> {116 fn check(c: &Case) -> Result<usize, String> {
123 let dir = scratch();117 let dir = scratch();
124- let Some(stream) = encode(&dir, c) else {118+ let stream = encode(&dir, c)
125- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {119+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
126- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
127- }
128- eprintln!(
129- "SKIP {}: ffmpeg with the needed libx264 is not available",
130- c.tag
131- );
132- return Ok(0);
133- };
134 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;120 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
135 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;121 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
136 let (first, format) = ours122 let (first, format) = ours
@@ -616,13 +602,9 @@ fn x264_monochrome_mbaff_and_lossless() {
616 sweep("gray MBAFF / lossless", &cases);602 sweep("gray MBAFF / lossless", &cases);
617 }603 }
618 604
619-/// 1280x720 (opt-in, slow).605+/// 1280x720 (slow).
620 #[test]606 #[test]
621 fn x264_hi444_hd() {607 fn x264_hi444_hd() {
622- if std::env::var_os("EC_H264_HI444_HD").is_none() {
623- eprintln!("SKIP x264_hi444_hd: set EC_H264_HI444_HD=1");
624- return;
625- }
626 let base = [608 let base = [
627 case("hd-i-cabac", "testsrc2", "1280x720", 2, "keyint=1"),609 case("hd-i-cabac", "testsrc2", "1280x720", 2, "keyint=1"),
628 case(610 case(
crates/ec-h264/tests/it/high444_jvt.rsmodified+6 -22
@@ -8,13 +8,11 @@
8 //! the archive ships a reference YUV, that YUV is used instead of / as well as8 //! the archive ships a reference YUV, that YUV is used instead of / as well as
9 //! ffmpeg; a stream with neither is reported `unchecked` (and counted as a9 //! ffmpeg; a stream with neither is reported `unchecked` (and counted as a
10 //! failure only if it also fails to decode). Fixtures live in the gitignored10 //! failure only if it also fails to decode). Fixtures live in the gitignored
11-//! root `fixtures/vectors/h264-jvt-hi444`; a missing set skips with a message,
12-//! or fails when `EC_REQUIRE_FIXTURES` is set. Heavy streams are skipped in
13 //! debug builds.11 //! debug builds.
14 12
15 use std::io::Read;13 use std::io::Read;
16 use std::path::{Path, PathBuf};14 use std::path::{Path, PathBuf};
17-use std::process::{Command, Stdio};15+use std::process::Stdio;
18 16
19 use ec_core::frame::{PixelFormat, VideoFrame};17 use ec_core::frame::{PixelFormat, VideoFrame};
20 use ec_h264::{Decoder, NalOutcome};18 use ec_h264::{Decoder, NalOutcome};
@@ -22,7 +20,7 @@ use ec_h264::{Decoder, NalOutcome};
22 use super::common::layout;20 use super::common::layout;
23 21
24 fn root() -> PathBuf {22 fn root() -> PathBuf {
25- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi444")23+ ec_testkit::fixture("vectors/h264-jvt-hi444")
26 }24 }
27 25
28 const STREAM_EXT: &[&str] = &["264", "jsv", "avc", "26l", "h264", "bit", "bits", "jvt"];26 const STREAM_EXT: &[&str] = &["264", "jsv", "avc", "26l", "h264", "bit", "bits", "jvt"];
@@ -127,7 +125,7 @@ fn decode_all(bytes: &[u8]) -> Result<Decoded, ec_h264::Error> {
127 }125 }
128 126
129 fn probe_pix_fmt(stream: &Path) -> Option<String> {127 fn probe_pix_fmt(stream: &Path) -> Option<String> {
130- let out = Command::new("ffprobe")128+ let out = ec_testkit::ffprobe()
131 .args(["-v", "error", "-f", "h264", "-select_streams", "v:0"])129 .args(["-v", "error", "-f", "h264", "-select_streams", "v:0"])
132 .args(["-show_entries", "stream=pix_fmt", "-of", "csv=p=0"])130 .args(["-show_entries", "stream=pix_fmt", "-of", "csv=p=0"])
133 .arg(stream)131 .arg(stream)
@@ -140,7 +138,7 @@ fn probe_pix_fmt(stream: &Path) -> Option<String> {
140 /// ffmpeg's raw decode as a pipe, so a long 14-bit 4:4:4 stream is compared a138 /// ffmpeg's raw decode as a pipe, so a long 14-bit 4:4:4 stream is compared a
141 /// frame at a time instead of held in memory.139 /// frame at a time instead of held in memory.
142 fn ffmpeg_pipe(stream: &Path, pix_fmt: &str) -> Option<std::process::Child> {140 fn ffmpeg_pipe(stream: &Path, pix_fmt: &str) -> Option<std::process::Child> {
143- Command::new("ffmpeg")141+ ec_testkit::ffmpeg()
144 .args(["-v", "error", "-f", "h264", "-i"])142 .args(["-v", "error", "-f", "h264", "-i"])
145 .arg(stream)143 .arg(stream)
146 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])144 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -205,25 +203,15 @@ fn reference_yuv(stream: &Path) -> Option<PathBuf> {
205 #[test]203 #[test]
206 fn jvt_hi444_vectors_bit_exact() {204 fn jvt_hi444_vectors_bit_exact() {
207 let list = streams(&root());205 let list = streams(&root());
208- if list.is_empty() {
209 assert!(206 assert!(
210- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),207+ !list.is_empty(),
211- "h264-jvt-hi444 missing at {} - this gate would prove nothing; run \208+ "no h264-jvt-hi444 streams in {}",
212- scripts/fetch-vectors.sh h264-jvt-hi444",
213 root().display()209 root().display()
214 );210 );
215- eprintln!("SKIP h264-jvt-hi444 missing at {}", root().display());
216- return;
217- }
218- let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok();
219 let mut failed = Vec::new();211 let mut failed = Vec::new();
220 let mut summary = Vec::new();212 let mut summary = Vec::new();
221 for path in &list {213 for path in &list {
222 let name = path.file_stem().unwrap().to_string_lossy().to_string();214 let name = path.file_stem().unwrap().to_string_lossy().to_string();
223- if cfg!(debug_assertions) && std::fs::metadata(path).map_or(0, |m| m.len()) > 2_000_000 {
224- eprintln!("SKIP {name}: large stream, release builds only");
225- continue;
226- }
227 let bytes = std::fs::read(path).unwrap();215 let bytes = std::fs::read(path).unwrap();
228 let (ours, format) = match decode_all(&bytes) {216 let (ours, format) = match decode_all(&bytes) {
229 Ok((f, fmt)) if !f.is_empty() => (f, fmt),217 Ok((f, fmt)) if !f.is_empty() => (f, fmt),
@@ -235,7 +223,6 @@ fn jvt_hi444_vectors_bit_exact() {
235 Err(e) if e.to_string().contains("FMO") => {223 Err(e) if e.to_string().contains("FMO") => {
236 // The Sejong Univ. streams use slice groups, which this224 // The Sejong Univ. streams use slice groups, which this
237 // decoder refuses by name (not part of this lane).225 // decoder refuses by name (not part of this lane).
238- eprintln!("SKIP {name}: {e}");
239 summary.push(format!("{name} fmo-refused"));226 summary.push(format!("{name} fmo-refused"));
240 continue;227 continue;
241 }228 }
@@ -262,8 +249,6 @@ fn jvt_hi444_vectors_bit_exact() {
262 Err(e) => errors.push(e),249 Err(e) => errors.push(e),
263 }250 }
264 }251 }
265- if have_ffmpeg {
266- // 9-bit streams are left-aligned to 10 bits by us.
267 let pix = match probe_pix_fmt(path).as_deref() {252 let pix = match probe_pix_fmt(path).as_deref() {
268 Some("gray") => "gray".to_string(),253 Some("gray") => "gray".to_string(),
269 Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),254 Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),
@@ -297,7 +282,6 @@ fn jvt_hi444_vectors_bit_exact() {
297 }282 }
298 None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),283 None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),
299 }284 }
300- }
301 if !errors.is_empty() {285 if !errors.is_empty() {
302 eprintln!("FAIL {name}: {}", errors.join("; "));286 eprintln!("FAIL {name}: {}", errors.join("; "));
303 failed.extend(errors);287 failed.extend(errors);
crates/ec-h264/tests/it/interlaced.rsmodified+4 -25
@@ -2,42 +2,24 @@
2 //! macroblock-adaptive frame/field coding (MBAFF), woven into frames.2 //! macroblock-adaptive frame/field coding (MBAFF), woven into frames.
3 //!3 //!
4 //! The authority is the JVT conformance suite: each vector's reference YUV is4 //! The authority is the JVT conformance suite: each vector's reference YUV is
5-//! compared frame by frame. Fixtures live in the gitignored root `fixtures/`
6-//! (`scripts/fetch-vectors.sh`); a missing one skips with a message, or fails
7-//! when `EC_REQUIRE_FIXTURES` is set, like the other conformance tests.
8 5
9 use std::path::{Path, PathBuf};6 use std::path::{Path, PathBuf};
10 7
11 use ec_core::frame::{Interlace, VideoFrame};8 use ec_core::frame::{Interlace, VideoFrame};
12 use ec_h264::{Decoder, NalOutcome};9 use ec_h264::{Decoder, NalOutcome};
13 10
14-/// Where a vector lives: the interlaced set (`scripts/fetch-vectors.sh`), or
15 /// the general JVT set for the few interlaced streams that were fetched first.11 /// the general JVT set for the few interlaced streams that were fetched first.
16 fn vector_dir(name: &str) -> PathBuf {12 fn vector_dir(name: &str) -> PathBuf {
17- let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors");13+ let own = ec_testkit::root()
18- let own = root.join("h264-jvt-interlaced").join(name);14+ .join("vectors/h264-jvt-interlaced")
15+ .join(name);
19 if own.exists() {16 if own.exists() {
20 own17 own
21 } else {18 } else {
22- root.join("h264-jvt").join(name)19+ ec_testkit::fixture(&format!("vectors/h264-jvt/{name}"))
23 }20 }
24 }21 }
25 22
26-/// True when `path` exists; otherwise skip (or fail under `EC_REQUIRE_FIXTURES`).
27-fn have_fixture(path: &Path, what: &str) -> bool {
28- if path.exists() {
29- return true;
30- }
31- assert!(
32- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
33- "{what} missing at {} - this gate would prove nothing; run \
34- scripts/link-fixtures.sh or scripts/fetch-vectors.sh",
35- path.display()
36- );
37- eprintln!("SKIP {what} missing at {}", path.display());
38- false
39-}
40-
41 fn find_with_ext(dir: &Path, exts: &[&str]) -> Option<PathBuf> {23 fn find_with_ext(dir: &Path, exts: &[&str]) -> Option<PathBuf> {
42 let mut found: Vec<PathBuf> = std::fs::read_dir(dir)24 let mut found: Vec<PathBuf> = std::fs::read_dir(dir)
43 .ok()?25 .ok()?
@@ -92,9 +74,6 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<(Vec<u8>, Interlace)>, ec_h264::Error>
92 /// Decode one JVT vector and compare it with its reference YUV.74 /// Decode one JVT vector and compare it with its reference YUV.
93 fn check_vector(name: &str) -> Result<usize, String> {75 fn check_vector(name: &str) -> Result<usize, String> {
94 let dir = vector_dir(name);76 let dir = vector_dir(name);
95- if !have_fixture(&dir, &format!("JVT vector {name}")) {
96- return Ok(0);
97- }
98 let stream = find_with_ext(&dir, &["jsv", "264", "avc", "26l", "h264", "jvt"])77 let stream = find_with_ext(&dir, &["jsv", "264", "avc", "26l", "h264", "jvt"])
99 .ok_or(format!("{name}: no bitstream"))?;78 .ok_or(format!("{name}: no bitstream"))?;
100 let yuv = find_with_ext(&dir, &["yuv"]).ok_or(format!("{name}: no reference YUV"))?;79 let yuv = find_with_ext(&dir, &["yuv"]).ok_or(format!("{name}: no reference YUV"))?;
crates/ec-h264/tests/it/mbaff_x264.rsmodified+4 -22
@@ -3,14 +3,8 @@
3 //! sources: CABAC and CAVLC, top and bottom field first, B-frames with3 //! sources: CABAC and CAVLC, top and bottom field first, B-frames with
4 //! spatial and temporal direct, weighted prediction, the 8x8 transform,4 //! spatial and temporal direct, weighted prediction, the 8x8 transform,
5 //! several slices, and High 10.5 //! several slices, and High 10.
6-//!
7-//! Every case is generated in the test (no committed binaries). A case skips,
8-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
9-//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be
10-//! opt-in: set `EC_H264_MBAFF_HD=1` (the lane gate does).
11 6
12 use std::path::{Path, PathBuf};7 use std::path::{Path, PathBuf};
13-use std::process::Command;
14 8
15 use ec_core::frame::{PixelFormat, VideoFrame};9 use ec_core::frame::{PixelFormat, VideoFrame};
16 use ec_h264::{Decoder, NalOutcome};10 use ec_h264::{Decoder, NalOutcome};
@@ -89,7 +83,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
89 ("yuv420p", "high")83 ("yuv420p", "high")
90 };84 };
91 let params = format!("interlaced=1:{}", c.params);85 let params = format!("interlaced=1:{}", c.params);
92- let st = Command::new("ffmpeg")86+ let st = ec_testkit::ffmpeg()
93 .args([87 .args([
94 "-hide_banner",88 "-hide_banner",
95 "-loglevel",89 "-loglevel",
@@ -112,16 +106,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
112 106
113 fn check(c: &Case) -> Result<usize, String> {107 fn check(c: &Case) -> Result<usize, String> {
114 let dir = scratch();108 let dir = scratch();
115- let Some(stream) = encode(&dir, c) else {109+ let stream = encode(&dir, c)
116- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {110+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
117- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
118- }
119- eprintln!(
120- "SKIP {}: ffmpeg with the needed libx264 is not available",
121- c.tag
122- );
123- return Ok(0);
124- };
125 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;111 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
126 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;112 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
127 let first = ours113 let first = ours
@@ -369,13 +355,9 @@ fn x264_mbaff_sd() {
369 ]);355 ]);
370 }356 }
371 357
372-/// 1920x1080: opt-in (`EC_H264_MBAFF_HD=1`).358+/// 1920x1080.
373 #[test]359 #[test]
374 fn x264_mbaff_hd() {360 fn x264_mbaff_hd() {
375- if std::env::var_os("EC_H264_MBAFF_HD").is_none() {
376- eprintln!("SKIP 1080p MBAFF sweep: set EC_H264_MBAFF_HD=1");
377- return;
378- }
379 sweep(&[361 sweep(&[
380 case(362 case(
381 "hd-cabac-tff",363 "hd-cabac-tff",
crates/ec-h264/tests/it/no_panic.rsmodified+1 -12
@@ -5,8 +5,6 @@
5 //! fixed-seed positions. Every mutant is decoded end to end. An `Err` is fine;5 //! fixed-seed positions. Every mutant is decoded end to end. An `Err` is fine;
6 //! a panic fails the test.6 //! a panic fails the test.
7 //!7 //!
8-//! Fixture-gated like the other conformance tests: without `fixtures/` the test
9-//! skips loudly, or fails when `EC_REQUIRE_FIXTURES` is set.
10 8
11 use std::path::{Path, PathBuf};9 use std::path::{Path, PathBuf};
12 10
@@ -20,7 +18,7 @@ const CORRUPTIONS: usize = 30;
20 const SEED: u32 = 0x9E37_79B9;18 const SEED: u32 = 0x9E37_79B9;
21 19
22 fn vectors_dir() -> PathBuf {20 fn vectors_dir() -> PathBuf {
23- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")21+ ec_testkit::fixture("vectors/h264-jvt")
24 }22 }
25 23
26 /// Every vector directory, in name order (the order `conformance.rs` walks).24 /// Every vector directory, in name order (the order `conformance.rs` walks).
@@ -53,15 +51,6 @@ fn decode_everything(bytes: &[u8]) {
53 #[test]51 #[test]
54 fn truncated_and_corrupted_conformance_streams_never_panic() {52 fn truncated_and_corrupted_conformance_streams_never_panic() {
55 let base = vectors_dir();53 let base = vectors_dir();
56- if !base.exists() {
57- assert!(
58- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
59- "JVT vectors missing at {} — run scripts/link-fixtures.sh or scripts/fetch-vectors.sh",
60- base.display()
61- );
62- eprintln!("SKIP JVT vectors missing at {}", base.display());
63- return;
64- }
65 let mut streams = 0usize;54 let mut streams = 0usize;
66 for name in vector_names(&base).into_iter().take(STREAMS) {55 for name in vector_names(&base).into_iter().take(STREAMS) {
67 let Some(stream) = find_stream(&base.join(&name)) else {56 let Some(stream) = find_stream(&base.join(&name)) else {
crates/ec-h264/tests/it/refusals.rsmodified+1 -13
@@ -10,8 +10,6 @@
10 //! maps every refused JVT conformance vector to the feature it really uses,10 //! maps every refused JVT conformance vector to the feature it really uses,
11 //! and is fixture-gated like `conformance.rs`.11 //! and is fixture-gated like `conformance.rs`.
12 12
13-use std::path::Path;
14-
15 use ec_core::BitWriter;13 use ec_core::BitWriter;
16 use ec_h264::{Decoder, Error, NalOutcome};14 use ec_h264::{Decoder, Error, NalOutcome};
17 15
@@ -294,21 +292,11 @@ fn different_luma_and_chroma_bit_depth_is_refused_by_name() {
294 }292 }
295 }293 }
296 294
297-/// Every refused vector in `fetch-vectors.sh`'s h264-jvt set, against the
298 /// feature it really uses. A vector that starts refusing for another reason,295 /// feature it really uses. A vector that starts refusing for another reason,
299 /// or stops being refused, changes this table and fails the test.296 /// or stops being refused, changes this table and fails the test.
300 #[test]297 #[test]
301 fn jvt_refused_vectors_refuse_for_their_feature() {298 fn jvt_refused_vectors_refuse_for_their_feature() {
302- let base = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt");299+ let base = ec_testkit::fixture("vectors/h264-jvt");
303- if !base.exists() {
304- assert!(
305- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
306- "JVT vectors missing at {} (run scripts/fetch-vectors.sh)",
307- base.display()
308- );
309- eprintln!("SKIP JVT vectors missing at {}", base.display());
310- return;
311- }
312 let expected: &[(&str, &str)] = &[];300 let expected: &[(&str, &str)] = &[];
313 let mut failures = Vec::new();301 let mut failures = Vec::new();
314 for &(name, feature) in expected {302 for &(name, feature) in expected {
crates/ec-h265-syntax/Cargo.tomlmodified+3 -0
@@ -8,3 +8,6 @@ authors.workspace = true
8 8
9 [dependencies]9 [dependencies]
10 ec-core.workspace = true10 ec-core.workspace = true
11+
12+[dev-dependencies]
13+ec-testkit.workspace = true
crates/ec-h265-syntax/tests/sei_sweep.rsmodified+2 -17
@@ -1,22 +1,14 @@
1 //! The SEI reader over the JCT-VC conformance streams.1 //! The SEI reader over the JCT-VC conformance streams.
2 //!2 //!
3 //! Every prefix and suffix SEI NAL unit of every stream must parse without error,3 //! Every prefix and suffix SEI NAL unit of every stream must parse without error,
4-//! and the streams that carry a `decoded_picture_hash` are counted. The sweep is
5-//! skipped when the vectors are absent, unless `EC_REQUIRE_FIXTURES` is set, in
6-//! which case an absent fixture fails the test.
7 4
8 use std::path::{Path, PathBuf};5 use std::path::{Path, PathBuf};
9 6
10 use ec_h265_syntax::nal::split_annex_b;7 use ec_h265_syntax::nal::split_annex_b;
11 use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp};8 use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp};
12 9
13-/// Every `.bin` or `.bit` stream under `fixtures/vectors/hevc-jctvc`, two directory
14-/// levels deep, sorted by path. `EC_H265_JCTVC_DIR` overrides the root.
15 fn streams() -> Vec<PathBuf> {10 fn streams() -> Vec<PathBuf> {
16- let root = match std::env::var("EC_H265_JCTVC_DIR") {11+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
17- Ok(dir) => PathBuf::from(dir),
18- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
19- };
20 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {12 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
21 let Ok(entries) = std::fs::read_dir(dir) else {13 let Ok(entries) = std::fs::read_dir(dir) else {
22 return;14 return;
@@ -39,14 +31,7 @@ fn streams() -> Vec<PathBuf> {
39 #[test]31 #[test]
40 fn every_sei_in_the_conformance_streams_parses() {32 fn every_sei_in_the_conformance_streams_parses() {
41 let streams = streams();33 let streams = streams();
42- if streams.is_empty() {34+ assert!(!streams.is_empty(), "no streams under vectors/hevc-jctvc");
43- assert!(
44- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
45- "EC_REQUIRE_FIXTURES=1 but fixtures/vectors/hevc-jctvc has no streams"
46- );
47- eprintln!("SEI sweep skipped: vectors absent");
48- return;
49- }
50 let mut with_hash = 0usize;35 let mut with_hash = 0usize;
51 let mut hash_streams = Vec::new();36 let mut hash_streams = Vec::new();
52 let mut sei_nals = 0usize;37 let mut sei_nals = 0usize;
crates/ec-h265/Cargo.tomlmodified+1 -0
@@ -15,4 +15,5 @@ archmage = "=0.9.31-beta.1"
15 multiversion = "0.9"15 multiversion = "0.9"
16 16
17 [dev-dependencies]17 [dev-dependencies]
18+ec-testkit.workspace = true
18 ec-h265-syntax.workspace = true19 ec-h265-syntax.workspace = true
crates/ec-h265/tests/it/conformance.rsmodified+5 -50
@@ -8,7 +8,6 @@ use crate::common::{natural_frame, pin_or_panic, test_frame};
8 use ec_core::frame::VideoFrame;8 use ec_core::frame::VideoFrame;
9 use ec_h265::encoder::{EncodedPicture, Encoder, EncoderConfig, RateControl, TransformSkip};9 use ec_h265::encoder::{EncodedPicture, Encoder, EncoderConfig, RateControl, TransformSkip};
10 use std::path::{Path, PathBuf};10 use std::path::{Path, PathBuf};
11-use std::process::Command;
12 11
13 fn scratch_dir() -> PathBuf {12 fn scratch_dir() -> PathBuf {
14 let dir = std::env::temp_dir().join("ec-h265-tests");13 let dir = std::env::temp_dir().join("ec-h265-tests");
@@ -16,18 +15,10 @@ fn scratch_dir() -> PathBuf {
16 dir15 dir
17 }16 }
18 17
19-fn have_ffmpeg() -> bool {
20- Command::new("ffmpeg")
21- .arg("-version")
22- .output()
23- .map(|o| o.status.success())
24- .unwrap_or(false)
25-}
26-
27 /// Decode an Annex-B file with ffmpeg into planar 8-bit 4:2:0.18 /// Decode an Annex-B file with ffmpeg into planar 8-bit 4:2:0.
28 fn ffmpeg_decode(path: &Path) -> Result<Vec<u8>, String> {19 fn ffmpeg_decode(path: &Path) -> Result<Vec<u8>, String> {
29 let out = path.with_extension("yuv");20 let out = path.with_extension("yuv");
30- let status = Command::new("ffmpeg")21+ let status = ec_testkit::ffmpeg()
31 .args(["-v", "error", "-y", "-i"])22 .args(["-v", "error", "-y", "-i"])
32 .arg(path)23 .arg(path)
33 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])24 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -147,10 +138,6 @@ fn encode_natural(
147 /// the search actually fired — and still decode bit-exactly.138 /// the search actually fired — and still decode bit-exactly.
148 #[test]139 #[test]
149 fn chroma_mode_search_decodes_bit_exactly() {140 fn chroma_mode_search_decodes_bit_exactly() {
150- if !have_ffmpeg() {
151- eprintln!("skipping: ffmpeg not installed");
152- return;
153- }
154 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {141 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
155 let (source, coded) = encode_with(w, h, 27, None, true, false);142 let (source, coded) = encode_with(w, h, 27, None, true, false);
156 let (_, derived) = encode_with(w, h, 27, None, false, false);143 let (_, derived) = encode_with(w, h, 27, None, false, false);
@@ -224,10 +211,6 @@ fn chroma_mode_search_decodes_bit_exactly() {
224 /// partition are all where the decoder looks for them.211 /// partition are all where the decoder looks for them.
225 #[test]212 #[test]
226 fn intra_nxn_decodes_bit_exactly() {213 fn intra_nxn_decodes_bit_exactly() {
227- if !have_ffmpeg() {
228- eprintln!("skipping: ffmpeg not installed");
229- return;
230- }
231 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {214 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
232 let (source, coded) = encode_natural(w, h, 22, true);215 let (source, coded) = encode_natural(w, h, 22, true);
233 let (_, square) = encode_natural(w, h, 22, false);216 let (_, square) = encode_natural(w, h, 22, false);
@@ -305,10 +288,6 @@ fn intra_nxn_decodes_bit_exactly() {
305 /// `EC_H265_SDH` arm of the clip gate measures.288 /// `EC_H265_SDH` arm of the clip gate measures.
306 #[test]289 #[test]
307 fn sign_hiding_decodes_bit_exactly() {290 fn sign_hiding_decodes_bit_exactly() {
308- if !have_ffmpeg() {
309- eprintln!("skipping: ffmpeg not installed");
310- return;
311- }
312 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {291 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
313 let (source, coded) = encode_sdh(w, h, 22, true);292 let (source, coded) = encode_sdh(w, h, 22, true);
314 let (_, plain) = encode_sdh(w, h, 22, false);293 let (_, plain) = encode_sdh(w, h, 22, false);
@@ -414,10 +393,6 @@ fn encode_tskip(
414 /// sample for sample.393 /// sample for sample.
415 #[test]394 #[test]
416 fn transform_skip_decodes_bit_exactly() {395 fn transform_skip_decodes_bit_exactly() {
417- if !have_ffmpeg() {
418- eprintln!("skipping: ffmpeg not installed");
419- return;
420- }
421 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {396 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
422 let (source, coded) = encode_tskip(w, h, 22, TransformSkip::AlwaysFor4x4);397 let (source, coded) = encode_tskip(w, h, 22, TransformSkip::AlwaysFor4x4);
423 let (_, plain) = encode_tskip(w, h, 22, TransformSkip::Off);398 let (_, plain) = encode_tskip(w, h, 22, TransformSkip::Off);
@@ -484,10 +459,6 @@ fn transform_skip_decodes_bit_exactly() {
484 }459 }
485 #[test]460 #[test]
486 fn ffmpeg_decodes_bit_exactly_at_every_shape() {461 fn ffmpeg_decodes_bit_exactly_at_every_shape() {
487- if !have_ffmpeg() {
488- eprintln!("skipping: ffmpeg not installed");
489- return;
490- }
491 // 1920x1080 needs the conformance window on the bottom (1088 coded rows are462 // 1920x1080 needs the conformance window on the bottom (1088 coded rows are
492 // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916463 // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916
493 // needs it on the right, 130x66 exercises a partial CTB in both directions.464 // needs it on the right, 130x66 exercises a partial CTB in both directions.
@@ -577,10 +548,6 @@ fn ffmpeg_decodes_bit_exactly_at_every_shape() {
577 /// pass without a single 64x64 coding unit ever being kept.548 /// pass without a single 64x64 coding unit ever being kept.
578 #[test]549 #[test]
579 fn cu64_decodes_bit_exactly() {550 fn cu64_decodes_bit_exactly() {
580- if !have_ffmpeg() {
581- eprintln!("skipping: ffmpeg not installed");
582- return;
583- }
584 // 130x66 is here for the partial coding tree blocks, not for the decision:551 // 130x66 is here for the partial coding tree blocks, not for the decision:
585 // at that size only two tree blocks are whole and the search keeps neither,552 // at that size only two tree blocks are whole and the search keeps neither,
586 // so its stream is allowed to come out identical.553 // so its stream is allowed to come out identical.
@@ -684,13 +651,9 @@ fn ffmpeg_verifies_the_decoded_picture_hash() {
684 // decoder checks that claim against what it decoded when asked to. This is651 // decoder checks that claim against what it decoded when asked to. This is
685 // the one oracle that does not depend on this crate being right about652 // the one oracle that does not depend on this crate being right about
686 // anything except the hash itself.653 // anything except the hash itself.
687- if !have_ffmpeg() {
688- eprintln!("skipping: ffmpeg not installed");
689- return;
690- }
691 let (_, coded) = encode(352, 288, 30, None);654 let (_, coded) = encode(352, 288, 30, None);
692 let path = write_au("hash-352x288", &coded);655 let path = write_au("hash-352x288", &coded);
693- let output = Command::new("ffmpeg")656+ let output = ec_testkit::ffmpeg()
694 .args(["-v", "debug", "-err_detect", "crccheck", "-y", "-i"])657 .args(["-v", "debug", "-err_detect", "crccheck", "-y", "-i"])
695 .arg(&path)658 .arg(&path)
696 .args(["-f", "null", "-"])659 .args(["-f", "null", "-"])
@@ -712,13 +675,13 @@ fn vaapi_hardware_decodes_the_stream() {
712 // The other half of "it decodes": a GPU decoder is a different675 // The other half of "it decodes": a GPU decoder is a different
713 // implementation with different tolerances, and it is what edith's HEVC676 // implementation with different tolerances, and it is what edith's HEVC
714 // path actually uses. Skipped where there is no render node.677 // path actually uses. Skipped where there is no render node.
715- if !have_ffmpeg() || !Path::new("/dev/dri/renderD128").exists() {678+ if !Path::new("/dev/dri/renderD128").exists() {
716- eprintln!("skipping: no ffmpeg or no VA-API render node");679+ eprintln!("skipping: no VA-API render node");
717 return;680 return;
718 }681 }
719 let (_, coded) = encode(1920, 1080, 27, None);682 let (_, coded) = encode(1920, 1080, 27, None);
720 let path = write_au("vaapi-1080p", &coded);683 let path = write_au("vaapi-1080p", &coded);
721- let output = Command::new("ffmpeg")684+ let output = ec_testkit::ffmpeg()
722 .args([685 .args([
723 "-v",686 "-v",
724 "error",687 "error",
@@ -838,10 +801,6 @@ fn the_batch_helper_codes_every_picture_as_its_own_access_unit() {
838 /// has to read them back to the same samples the encoder reconstructed.801 /// has to read them back to the same samples the encoder reconstructed.
839 #[test]802 #[test]
840 fn rdoq_decodes_bit_exactly() {803 fn rdoq_decodes_bit_exactly() {
841- if !have_ffmpeg() {
842- eprintln!("skipping: ffmpeg not installed");
843- return;
844- }
845 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {804 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
846 let (source, coded) = encode_rdoq(w, h, 27, true);805 let (source, coded) = encode_rdoq(w, h, 27, true);
847 let (_, plain) = encode_rdoq(w, h, 27, false);806 let (_, plain) = encode_rdoq(w, h, 27, false);
@@ -925,10 +884,6 @@ fn encode_rdoq(width: u32, height: u32, qp: i32, rdoq: bool) -> (VideoFrame, Enc
925 /// samples the encoder reconstructed.884 /// samples the encoder reconstructed.
926 #[test]885 #[test]
927 fn rqt_decodes_bit_exactly() {886 fn rqt_decodes_bit_exactly() {
928- if !have_ffmpeg() {
929- eprintln!("skipping: ffmpeg not installed");
930- return;
931- }
932 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {887 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
933 let (source, coded) = encode_rqt(w, h, 27, true);888 let (source, coded) = encode_rqt(w, h, 27, true);
934 let (_, plain) = encode_rqt(w, h, 27, false);889 let (_, plain) = encode_rqt(w, h, 27, false);
crates/ec-h265/tests/it/conformance_intra.rsmodified+7 -34
@@ -24,12 +24,8 @@ struct Row {
24 decode_secs: f64,24 decode_secs: f64,
25 }25 }
26 26
27-/// The conformance directory: `EC_H265_JCTVC_DIR`, or the fixtures link.
28 fn jctvc_root() -> PathBuf {27 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_JCTVC_DIR") {28+ ec_testkit::fixture("vectors/hevc-jctvc")
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
32- }
33 }29 }
34 30
35 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's31 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -51,9 +47,7 @@ fn streams() -> Vec<PathBuf> {
51 }47 }
52 }48 }
53 }49 }
54- let Ok(dirs) = std::fs::read_dir(&root) else {50+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
55- return Vec::new();
56- };
57 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();51 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
58 dirs.sort();52 dirs.sort();
59 dirs.into_iter()53 dirs.into_iter()
@@ -67,7 +61,7 @@ fn streams() -> Vec<PathBuf> {
67 }61 }
68 62
69 /// Decodes one stream and checks every output picture against its MD5 SEI.63 /// Decodes one stream and checks every output picture against its MD5 SEI.
70-fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {64+fn check_stream(path: &Path, name: &str) -> Row {
71 let mut row = Row {65 let mut row = Row {
72 name: name.to_string(),66 name: name.to_string(),
73 accepted: "no",67 accepted: "no",
@@ -84,7 +78,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
84 return row;78 return row;
85 }79 }
86 };80 };
87- let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok());81+ let reference = std::fs::read(path.with_extension("yuv")).ok();
88 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It82 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
89 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a83 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
90 // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames).84 // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames).
@@ -120,17 +114,6 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
120 // No hash SEI: the frame is checked against the reference YUV, when there is one.114 // No hash SEI: the frame is checked against the reference YUV, when there is one.
121 if let Some(reference) = reference.as_deref() {115 if let Some(reference) = reference.as_deref() {
122 let want = cropped_bytes(&frame.picture, &frame.window);116 let want = cropped_bytes(&frame.picture, &frame.window);
123- if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") {
124- // Diagnostic: append this frame to the stream's dump file.
125- use std::io::Write;
126- if let Ok(mut f) = std::fs::OpenOptions::new()
127- .create(true)
128- .append(true)
129- .open(Path::new(&dir).join(format!("{name}.ours.yuv")))
130- {
131- let _ = f.write_all(&want);
132- }
133- }
134 let start = index * want.len();117 let start = index * want.len();
135 row.checked += 1;118 row.checked += 1;
136 if reference.get(start..start + want.len()) == Some(&want[..]) {119 if reference.get(start..start + want.len()) == Some(&want[..]) {
@@ -197,19 +180,11 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
197 fn conformance_pictures_match_the_sei_hash() {180 fn conformance_pictures_match_the_sei_hash() {
198 let root = jctvc_root();181 let root = jctvc_root();
199 let streams = streams();182 let streams = streams();
200- if streams.is_empty() {
201- eprintln!(
202- "conformance check skipped: no streams under {}",
203- root.display()
204- );
205 assert!(183 assert!(
206- !root.is_dir(),184+ !streams.is_empty(),
207- "fixture directory {} exists but holds no bitstreams",185+ "no conformance streams under {}",
208 root.display()186 root.display()
209 );187 );
210- return;
211- }
212- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
213 188
214 let mut rows = Vec::new();189 let mut rows = Vec::new();
215 for path in &streams {190 for path in &streams {
@@ -217,9 +192,7 @@ fn conformance_pictures_match_the_sei_hash() {
217 .file_stem()192 .file_stem()
218 .map(|s| s.to_string_lossy().into_owned())193 .map(|s| s.to_string_lossy().into_owned())
219 .unwrap_or_default();194 .unwrap_or_default();
220- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {195+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
221- check_stream(path, &name, ref_dir.as_deref())
222- }));
223 let mut row = match outcome {196 let mut row = match outcome {
224 Ok(row) => row,197 Ok(row) => row,
225 Err(payload) => {198 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext.rsmodified+7 -35
@@ -1,5 +1,4 @@
1 //! Checks every output picture of each JCT-VC range extension conformance stream1 //! Checks every output picture of each JCT-VC range extension conformance stream
2-//! (`scripts/fetch-vectors.sh hevc-rext`) against the hash in its decoded picture hash SEI
3 //! (D.3.19), or against the whole-output MD5 of the package when the stream has no hash.2 //! (D.3.19), or against the whole-output MD5 of the package when the stream has no hash.
4 //!3 //!
5 //! A stream the decoder refuses must be refused by name: the error text has to be one of4 //! A stream the decoder refuses must be refused by name: the error text has to be one of
@@ -24,12 +23,8 @@ struct Row {
24 decode_secs: f64,23 decode_secs: f64,
25 }24 }
26 25
27-/// The conformance directory: `EC_H265_REXT_DIR`, or the fixtures link.
28 fn jctvc_root() -> PathBuf {26 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_REXT_DIR") {27+ ec_testkit::fixture("vectors/hevc-rext")
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
32- }
33 }28 }
34 29
35 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's30 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -51,9 +46,7 @@ fn streams() -> Vec<PathBuf> {
51 }46 }
52 }47 }
53 }48 }
54- let Ok(dirs) = std::fs::read_dir(&root) else {49+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
55- return Vec::new();
56- };
57 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();50 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
58 dirs.sort();51 dirs.sort();
59 dirs.into_iter()52 dirs.into_iter()
@@ -106,7 +99,7 @@ fn nal_chunks(data: &[u8]) -> Vec<&[u8]> {
106 }99 }
107 100
108 /// Decodes one stream and checks every output picture against its MD5 SEI.101 /// Decodes one stream and checks every output picture against its MD5 SEI.
109-fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {102+fn check_stream(path: &Path, name: &str) -> Row {
110 let mut row = Row {103 let mut row = Row {
111 name: name.to_string(),104 name: name.to_string(),
112 accepted: "no",105 accepted: "no",
@@ -123,7 +116,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
123 return row;116 return row;
124 }117 }
125 };118 };
126- let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok());119+ let reference = std::fs::read(path.with_extension("yuv")).ok();
127 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It120 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
128 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a121 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
129 // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames).122 // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames).
@@ -149,17 +142,6 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
149 // No hash SEI: the frame is checked against the reference YUV, when there is one.142 // No hash SEI: the frame is checked against the reference YUV, when there is one.
150 if let Some(reference) = reference.as_deref() {143 if let Some(reference) = reference.as_deref() {
151 let want = cropped_bytes(&frame.picture, &frame.window);144 let want = cropped_bytes(&frame.picture, &frame.window);
152- if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") {
153- // Diagnostic: append this frame to the stream's dump file.
154- use std::io::Write;
155- if let Ok(mut f) = std::fs::OpenOptions::new()
156- .create(true)
157- .append(true)
158- .open(Path::new(&dir).join(format!("{name}.ours.yuv")))
159- {
160- let _ = f.write_all(&want);
161- }
162- }
163 let start = index * want.len();145 let start = index * want.len();
164 row.checked += 1;146 row.checked += 1;
165 if reference.get(start..start + want.len()) == Some(&want[..]) {147 if reference.get(start..start + want.len()) == Some(&want[..]) {
@@ -244,19 +226,11 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
244 fn rext_conformance_pictures_match_the_sei_hash() {226 fn rext_conformance_pictures_match_the_sei_hash() {
245 let root = jctvc_root();227 let root = jctvc_root();
246 let streams = streams();228 let streams = streams();
247- if streams.is_empty() {
248- eprintln!(
249- "conformance check skipped: no streams under {}",
250- root.display()
251- );
252 assert!(229 assert!(
253- std::env::var_os("EC_REQUIRE_FIXTURES").is_none() && !root.is_dir(),230+ !streams.is_empty(),
254- "fixture directory {} holds no bitstreams",231+ "no conformance streams under {}",
255 root.display()232 root.display()
256 );233 );
257- return;
258- }
259- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
260 234
261 let mut rows = Vec::new();235 let mut rows = Vec::new();
262 for path in &streams {236 for path in &streams {
@@ -265,9 +239,7 @@ fn rext_conformance_pictures_match_the_sei_hash() {
265 .map(|s| s.to_string_lossy().into_owned())239 .map(|s| s.to_string_lossy().into_owned())
266 .unwrap_or_default();240 .unwrap_or_default();
267 eprintln!("stream {name}");241 eprintln!("stream {name}");
268- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {242+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
269- check_stream(path, &name, ref_dir.as_deref())
270- }));
271 let mut row = match outcome {243 let mut row = match outcome {
272 Ok(row) => row,244 Ok(row) => row,
273 Err(payload) => {245 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext422.rsmodified+6 -19
@@ -2,12 +2,8 @@
2 //!2 //!
3 //! The committed 64x64 stream is decoded by ffmpeg at run time and compared sample for3 //! The committed 64x64 stream is decoded by ffmpeg at run time and compared sample for
4 //! sample. The Sony RExt conformance streams and the generated GOP/intra clips live in the4 //! sample. The Sony RExt conformance streams and the generated GOP/intra clips live in the
5-//! gitignored fixtures (`EC_H265_REXT_DIR`, default `fixtures/vectors/hevc-rext`, with the
6-//! ffmpeg output of each stream under `ref/` or next to it); a missing fixture is skipped
7-//! and reported, a present one must decode byte-exactly.
8 5
9 use std::path::{Path, PathBuf};6 use std::path::{Path, PathBuf};
10-use std::process::Command;
11 7
12 use ec_h265::Decoder;8 use ec_h265::Decoder;
13 9
@@ -59,16 +55,12 @@ fn first_diff(a: &[u8], b: &[u8]) -> Option<usize> {
59 55
60 #[test]56 #[test]
61 fn committed_422_stream_matches_ffmpeg() {57 fn committed_422_stream_matches_ffmpeg() {
62- if Command::new("ffmpeg").arg("-version").output().is_err() {
63- eprintln!("skip: no ffmpeg");
64- return;
65- }
66 let dir = std::env::temp_dir().join("ec-h265-rext422");58 let dir = std::env::temp_dir().join("ec-h265-rext422");
67 std::fs::create_dir_all(&dir).unwrap();59 std::fs::create_dir_all(&dir).unwrap();
68 let src = dir.join("yuv422_10.265");60 let src = dir.join("yuv422_10.265");
69 let reference = dir.join("yuv422_10.yuv");61 let reference = dir.join("yuv422_10.yuv");
70 std::fs::write(&src, YUV422_10).unwrap();62 std::fs::write(&src, YUV422_10).unwrap();
71- let st = Command::new("ffmpeg")63+ let st = ec_testkit::ffmpeg()
72 .args(["-v", "error", "-y", "-i"])64 .args(["-v", "error", "-y", "-i"])
73 .arg(&src)65 .arg(&src)
74 .args(["-f", "rawvideo", "-pix_fmt", "yuv422p10le"])66 .args(["-f", "rawvideo", "-pix_fmt", "yuv422p10le"])
@@ -86,10 +78,7 @@ fn committed_422_stream_matches_ffmpeg() {
86 }78 }
87 79
88 fn rext_root() -> PathBuf {80 fn rext_root() -> PathBuf {
89- match std::env::var("EC_H265_REXT_DIR") {81+ ec_testkit::fixture("vectors/hevc-rext")
90- Ok(d) => PathBuf::from(d),
91- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
92- }
93 }82 }
94 83
95 fn find_stream(dir: &Path) -> Option<PathBuf> {84 fn find_stream(dir: &Path) -> Option<PathBuf> {
@@ -116,10 +105,9 @@ fn rext_422_vectors_are_byte_exact() {
116 ("Main_422_10_A_RExt_Sony_2", 1920, 1080),105 ("Main_422_10_A_RExt_Sony_2", 1920, 1080),
117 ("Main_422_10_B_RExt_Sony_2", 2560, 1600),106 ("Main_422_10_B_RExt_Sony_2", 2560, 1600),
118 ] {107 ] {
119- if let Some(s) = find_stream(&root.join(name)) {108+ let s = find_stream(&root.join(name)).unwrap_or_else(|| panic!("{name}: no stream"));
120 cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));109 cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));
121 }110 }
122- }
123 for name in [111 for name in [
124 "i422_8",112 "i422_8",
125 "g422_8",113 "g422_8",
@@ -137,10 +125,9 @@ fn rext_422_vectors_are_byte_exact() {
137 }125 }
138 let mut checked = 0;126 let mut checked = 0;
139 for (stream, reference, w, h) in cases {127 for (stream, reference, w, h) in cases {
140- let (Ok(data), Ok(want)) = (std::fs::read(&stream), std::fs::read(&reference)) else {128+ let data = std::fs::read(&stream).unwrap_or_else(|e| panic!("{}: {e}", stream.display()));
141- eprintln!("skip (fixture missing): {}", stream.display());129+ let want =
142- continue;130+ std::fs::read(&reference).unwrap_or_else(|e| panic!("{}: {e}", reference.display()));
143- };
144 let got = raw(&decode(&data), w, h);131 let got = raw(&decode(&data), w, h);
145 assert_eq!(132 assert_eq!(
146 first_diff(&got, &want),133 first_diff(&got, &want),
crates/ec-h265/tests/it/cu_syntax.rsmodified+3 -12
@@ -7,12 +7,8 @@ use ec_h265::dec::Decoder;
7 use std::path::{Path, PathBuf};7 use std::path::{Path, PathBuf};
8 8
9 /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory9 /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory
10-/// under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted.
11 fn streams() -> Vec<PathBuf> {10 fn streams() -> Vec<PathBuf> {
12- let root = match std::env::var("EC_H265_JCTVC_DIR") {11+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
13- Ok(dir) => PathBuf::from(dir),
14- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
15- };
16 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {12 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
17 let Ok(entries) = std::fs::read_dir(dir) else {13 let Ok(entries) = std::fs::read_dir(dir) else {
18 return;14 return;
@@ -27,9 +23,7 @@ fn streams() -> Vec<PathBuf> {
27 }23 }
28 }24 }
29 }25 }
30- let Ok(dirs) = std::fs::read_dir(&root) else {26+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
31- return Vec::new();
32- };
33 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();27 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
34 dirs.sort();28 dirs.sort();
35 dirs.into_iter()29 dirs.into_iter()
@@ -84,10 +78,7 @@ fn inter_placeholder_runs_over_pb_slices() {
84 use ec_h265_syntax::nal::{NalUnitType, unescape_rbsp};78 use ec_h265_syntax::nal::{NalUnitType, unescape_rbsp};
85 use ec_h265_syntax::slice::{SliceHeader, SliceType};79 use ec_h265_syntax::slice::{SliceHeader, SliceType};
86 let streams = streams();80 let streams = streams();
87- if streams.is_empty() {81+ assert!(!streams.is_empty(), "no conformance streams");
88- eprintln!("inter placeholder: no conformance streams found, skipping");
89- return;
90- }
91 let (mut pb_slices, mut decoded, mut refused) = (0usize, 0usize, 0usize);82 let (mut pb_slices, mut decoded, mut refused) = (0usize, 0usize, 0usize);
92 for path in &streams {83 for path in &streams {
93 let data = std::fs::read(path).expect("read bitstream");84 let data = std::fs::read(path).expect("read bitstream");
crates/ec-h265/tests/it/dec_meta.rsmodified+7 -27
@@ -3,7 +3,6 @@
3 //! NAL units (62, 63) and malformed SEI change nothing.3 //! NAL units (62, 63) and malformed SEI change nothing.
4 //!4 //!
5 //! The streams come from `fixtures/vectors/hevc-jctvc`. Without them the tests5 //! The streams come from `fixtures/vectors/hevc-jctvc`. Without them the tests
6-//! skip, unless `EC_REQUIRE_FIXTURES` is set, in which case they fail.
7 6
8 use std::path::{Path, PathBuf};7 use std::path::{Path, PathBuf};
9 8
@@ -12,10 +11,7 @@ use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
12 use ec_h265_syntax::sei::{ContentLightLevel, MasteringDisplay, PictureHash};11 use ec_h265_syntax::sei::{ContentLightLevel, MasteringDisplay, PictureHash};
13 12
14 fn stream_files() -> Vec<PathBuf> {13 fn stream_files() -> Vec<PathBuf> {
15- let root = match std::env::var("EC_H265_JCTVC_DIR") {14+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
16- Ok(dir) => PathBuf::from(dir),
17- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
18- };
19 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {15 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
20 let Ok(entries) = std::fs::read_dir(dir) else {16 let Ok(entries) = std::fs::read_dir(dir) else {
21 return;17 return;
@@ -81,16 +77,8 @@ fn clean_stream() -> Option<(String, Vec<Vec<u8>>)> {
81 None77 None
82 }78 }
83 79
84-fn require_stream() -> Option<(String, Vec<Vec<u8>>)> {80+fn require_stream() -> (String, Vec<Vec<u8>>) {
85- let found = clean_stream();81+ clean_stream().expect("no clean conformance stream")
86- if found.is_none() {
87- assert!(
88- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
89- "EC_REQUIRE_FIXTURES=1 but no clean conformance stream is available"
90- );
91- eprintln!("decoder metadata tests skipped: vectors absent");
92- }
93- found
94 }82 }
95 83
96 /// What a frame looks like to a caller, for comparing two decodes.84 /// What a frame looks like to a caller, for comparing two decodes.
@@ -140,9 +128,7 @@ fn hdr10_prefix_rbsp() -> Vec<u8> {
140 128
141 #[test]129 #[test]
142 fn dolby_vision_nal_units_change_nothing() {130 fn dolby_vision_nal_units_change_nothing() {
143- let Some((name, nals)) = require_stream() else {131+ let (name, nals) = require_stream();
144- return;
145- };
146 let base = decode(&nals).unwrap();132 let base = decode(&nals).unwrap();
147 let mut injected = Vec::new();133 let mut injected = Vec::new();
148 for nal in &nals {134 for nal in &nals {
@@ -164,9 +150,7 @@ fn dolby_vision_nal_units_change_nothing() {
164 150
165 #[test]151 #[test]
166 fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {152 fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
167- let Some((name, nals)) = require_stream() else {153+ let (name, nals) = require_stream();
168- return;
169- };
170 let base = decode(&nals).unwrap();154 let base = decode(&nals).unwrap();
171 let mut injected = Vec::new();155 let mut injected = Vec::new();
172 for nal in &nals {156 for nal in &nals {
@@ -193,9 +177,7 @@ fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
193 177
194 #[test]178 #[test]
195 fn hdr_sei_applies_to_every_frame_from_the_irap_on() {179 fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
196- let Some((name, nals)) = require_stream() else {180+ let (name, nals) = require_stream();
197- return;
198- };
199 let mut injected = Vec::new();181 let mut injected = Vec::new();
200 let mut placed = false;182 let mut placed = false;
201 for nal in &nals {183 for nal in &nals {
@@ -225,9 +207,7 @@ fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
225 207
226 #[test]208 #[test]
227 fn picture_hash_attaches_to_the_picture_it_follows() {209 fn picture_hash_attaches_to_the_picture_it_follows() {
228- let Some((name, nals)) = require_stream() else {210+ let (name, nals) = require_stream();
229- return;
230- };
231 // One MD5 plane: payloadType 132, payloadSize 17, hash_type 0, the digest.211 // One MD5 plane: payloadType 132, payloadSize 17, hash_type 0, the digest.
232 let digest = [0x5au8; 16];212 let digest = [0x5au8; 16];
233 let mut hash_rbsp = vec![132, 17, 0];213 let mut hash_rbsp = vec![132, 17, 0];
crates/ec-h265/tests/it/dec_shell.rsmodified+5 -27
@@ -4,11 +4,9 @@
4 //! The sweep parses every slice of every stream through the picture-management4 //! The sweep parses every slice of every stream through the picture-management
5 //! path (pixel decode off) and checks the output order against ffprobe. Streams5 //! path (pixel decode off) and checks the output order against ffprobe. Streams
6 //! whose slices are all intra are also pixel-decoded and compared with ffmpeg's6 //! whose slices are all intra are also pixel-decoded and compared with ffmpeg's
7-//! output. The sweep is skipped when the vectors are absent.
8 7
9 use std::collections::VecDeque;8 use std::collections::VecDeque;
10 use std::path::{Path, PathBuf};9 use std::path::{Path, PathBuf};
11-use std::process::Command;
12 10
13 use ec_h265::dec::dpb::{Dpb, DpbLimits, Marking, PendingFrame};11 use ec_h265::dec::dpb::{Dpb, DpbLimits, Marking, PendingFrame};
14 use ec_h265::dec::poc::derive_poc;12 use ec_h265::dec::poc::derive_poc;
@@ -274,16 +272,8 @@ fn decoder_refuses_out_of_scope_parameter_sets_and_skips_layers() {
274 assert!(dec.next_frame().is_none());272 assert!(dec.next_frame().is_none());
275 }273 }
276 274
277-fn have_tool(tool: &str) -> bool {275+fn run(args: &[&str], file: &Path) -> Result<Vec<u8>, String> {
278- Command::new(tool)276+ let out = ec_testkit::ffprobe()
279- .arg("-version")
280- .output()
281- .map(|o| o.status.success())
282- .unwrap_or(false)
283-}
284-
285-fn run(tool: &str, args: &[&str], file: &Path) -> Result<Vec<u8>, String> {
286- let out = Command::new(tool)
287 .args(["-v", "error"])277 .args(["-v", "error"])
288 .args(args)278 .args(args)
289 .arg(file)279 .arg(file)
@@ -303,14 +293,9 @@ fn numbers(text: &[u8]) -> Vec<u64> {
303 }293 }
304 294
305 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's295 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
306-/// directory under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted
307 /// by name. Some zips extract one directory deeper, so two levels are searched.296 /// by name. Some zips extract one directory deeper, so two levels are searched.
308 fn streams() -> Vec<PathBuf> {297 fn streams() -> Vec<PathBuf> {
309- // EC_H265_JCTVC_DIR overrides the default, for hosts whose fixtures link is dangling.298+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
310- let root = match std::env::var("EC_H265_JCTVC_DIR") {
311- Ok(dir) => PathBuf::from(dir),
312- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
313- };
314 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {299 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
315 let Ok(entries) = std::fs::read_dir(dir) else {300 let Ok(entries) = std::fs::read_dir(dir) else {
316 return;301 return;
@@ -325,9 +310,7 @@ fn streams() -> Vec<PathBuf> {
325 }310 }
326 }311 }
327 }312 }
328- let Ok(dirs) = std::fs::read_dir(&root) else {313+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
329- return Vec::new();
330- };
331 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();314 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
332 dirs.sort();315 dirs.sort();
333 dirs.into_iter()316 dirs.into_iter()
@@ -357,7 +340,6 @@ fn our_order(data: &[u8]) -> Result<Vec<(i32, u32)>, String> {
357 /// decode order) of each frame, in display order.340 /// decode order) of each frame, in display order.
358 fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {341 fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
359 let packets = numbers(&run(342 let packets = numbers(&run(
360- "ffprobe",
361 &[343 &[
362 "-select_streams",344 "-select_streams",
363 "v:0",345 "v:0",
@@ -369,7 +351,6 @@ fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
369 path,351 path,
370 )?);352 )?);
371 let frames = numbers(&run(353 let frames = numbers(&run(
372- "ffprobe",
373 &[354 &[
374 "-select_streams",355 "-select_streams",
375 "v:0",356 "v:0",
@@ -407,10 +388,7 @@ fn spec_expectation(name: &str) -> Option<(usize, &'static str)> {
407 #[test]388 #[test]
408 fn conformance_output_order_matches_ffprobe() {389 fn conformance_output_order_matches_ffprobe() {
409 let streams = streams();390 let streams = streams();
410- if streams.is_empty() || !have_tool("ffprobe") {391+ assert!(!streams.is_empty(), "no conformance streams");
411- eprintln!("conformance sweep skipped: vectors or ffprobe absent");
412- return;
413- }
414 let mut table = String::from("stream\tpictures_out\tffprobe_out\tresult\tdetail\n");392 let mut table = String::from("stream\tpictures_out\tffprobe_out\tresult\tdetail\n");
415 let mut pass = 0usize;393 let mut pass = 0usize;
416 let mut spec_ok = 0usize;394 let mut spec_ok = 0usize;
crates/ec-h265/tests/it/dolby_vision_p8.rsmodified+2 -20
@@ -6,32 +6,22 @@
6 //! inserted in front of every VCL NAL unit. ec-h265 must decode the injected stream6 //! inserted in front of every VCL NAL unit. ec-h265 must decode the injected stream
7 //! to exactly the pictures it decodes from the clean one, and ffmpeg must decode the7 //! to exactly the pictures it decodes from the clean one, and ffmpeg must decode the
8 //! injected stream to the same bytes.8 //! injected stream to the same bytes.
9-//!
10-//! The test skips when ffmpeg is absent, unless `EC_REQUIRE_FIXTURES` is set.
11 9
12 use ec_h265::Decoder;10 use ec_h265::Decoder;
13 use ec_h265::dec::Frame;11 use ec_h265::dec::Frame;
14 use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};12 use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
15 use std::path::Path;13 use std::path::Path;
16-use std::process::Command;
17 14
18 const WIDTH: usize = 352;15 const WIDTH: usize = 352;
19 const HEIGHT: usize = 288;16 const HEIGHT: usize = 288;
20 const FRAMES: usize = 12;17 const FRAMES: usize = 12;
21 18
22-fn have_ffmpeg() -> bool {
23- Command::new("ffmpeg")
24- .arg("-version")
25- .output()
26- .is_ok_and(|o| o.status.success())
27-}
28-
29 /// The base layer: libx265, an IDR every 4 pictures, P pictures in between, no B.19 /// The base layer: libx265, an IDR every 4 pictures, P pictures in between, no B.
30 fn encode_base_layer(dir: &Path) -> Result<Vec<u8>, String> {20 fn encode_base_layer(dir: &Path) -> Result<Vec<u8>, String> {
31 let out = dir.join("base.hevc");21 let out = dir.join("base.hevc");
32 let frames = FRAMES.to_string();22 let frames = FRAMES.to_string();
33 let source = format!("testsrc2=size={WIDTH}x{HEIGHT}:rate=30");23 let source = format!("testsrc2=size={WIDTH}x{HEIGHT}:rate=30");
34- let status = Command::new("ffmpeg")24+ let status = ec_testkit::ffmpeg()
35 .args(["-v", "error", "-y", "-f", "lavfi", "-i"])25 .args(["-v", "error", "-y", "-f", "lavfi", "-i"])
36 .arg(&source)26 .arg(&source)
37 .arg("-frames:v")27 .arg("-frames:v")
@@ -137,7 +127,7 @@ fn decode_ec(annex_b: &[u8]) -> Result<(Vec<u8>, usize), String> {
137 127
138 /// Every picture ffmpeg outputs, as yuv420p.128 /// Every picture ffmpeg outputs, as yuv420p.
139 fn decode_ffmpeg(path: &Path, out: &Path) -> Result<Vec<u8>, String> {129 fn decode_ffmpeg(path: &Path, out: &Path) -> Result<Vec<u8>, String> {
140- let status = Command::new("ffmpeg")130+ let status = ec_testkit::ffmpeg()
141 .args(["-v", "error", "-y", "-i"])131 .args(["-v", "error", "-y", "-i"])
142 .arg(path)132 .arg(path)
143 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])133 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -159,14 +149,6 @@ fn first_difference(a: &[u8], b: &[u8]) -> Option<usize> {
159 149
160 #[test]150 #[test]
161 fn dolby_vision_p8_base_layer_decodes_and_rpu_is_ignored() {151 fn dolby_vision_p8_base_layer_decodes_and_rpu_is_ignored() {
162- if !have_ffmpeg() {
163- assert!(
164- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
165- "EC_REQUIRE_FIXTURES=1 but ffmpeg is absent"
166- );
167- eprintln!("dolby vision profile 8 check skipped: ffmpeg absent");
168- return;
169- }
170 let dir = std::env::temp_dir().join(format!("ec-h265-dvp8-{}", std::process::id()));152 let dir = std::env::temp_dir().join(format!("ec-h265-dvp8-{}", std::process::id()));
171 std::fs::create_dir_all(&dir).expect("temp dir");153 std::fs::create_dir_all(&dir).expect("temp dir");
172 154
crates/ec-h265/tests/it/encode.rsmodified+6 -22
@@ -266,17 +266,8 @@ fn bd_psnr_delta(candidate: &[(f64, f64)], anchor: &[(f64, f64)]) -> (f64, f64,
266 (bd, cand_extrap, anc_extrap)266 (bd, cand_extrap, anc_extrap)
267 }267 }
268 268
269-fn have_ffmpeg() -> bool {
270- std::process::Command::new("ffmpeg")
271- .arg("-version")
272- .stdout(std::process::Stdio::null())
273- .stderr(std::process::Stdio::null())
274- .status()
275- .is_ok_and(|s| s.success())
276-}
277-
278 fn have_x265() -> bool {269 fn have_x265() -> bool {
279- std::process::Command::new("ffmpeg")270+ ec_testkit::ffmpeg()
280 .args(["-v", "error", "-hide_banner", "-encoders"])271 .args(["-v", "error", "-hide_banner", "-encoders"])
281 .output()272 .output()
282 .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx265"))273 .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx265"))
@@ -367,7 +358,7 @@ fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Option<Vec<Planes>> {
367 std::fs::create_dir_all(&dir).ok()?;358 std::fs::create_dir_all(&dir).ok()?;
368 let path = dir.join(format!("s{}.265", stream.len()));359 let path = dir.join(format!("s{}.265", stream.len()));
369 pin_or_bail("ffmpeg_decode", &path, stream)?;360 pin_or_bail("ffmpeg_decode", &path, stream)?;
370- let out = std::process::Command::new("ffmpeg")361+ let out = ec_testkit::ffmpeg()
371 .args(["-v", "error"])362 .args(["-v", "error"])
372 .arg("-i")363 .arg("-i")
373 .arg(&path)364 .arg(&path)
@@ -445,7 +436,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option<Vec
445 _ => String::new(),436 _ => String::new(),
446 }437 }
447 );438 );
448- let status = std::process::Command::new("ffmpeg")439+ let status = ec_testkit::ffmpeg()
449 .args(["-v", "error", "-y"])440 .args(["-v", "error", "-y"])
450 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])441 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
451 .args(["-s", &format!("{w}x{h}"), "-r", "1"])442 .args(["-s", &format!("{w}x{h}"), "-r", "1"])
@@ -486,14 +477,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option<Vec
486 /// bd_psnr_vs_x265 -- --nocapture477 /// bd_psnr_vs_x265 -- --nocapture
487 #[test]478 #[test]
488 fn bd_psnr_vs_x265() {479 fn bd_psnr_vs_x265() {
489- if !have_ffmpeg() || !have_x265() {480+ assert!(have_x265(), "the pinned ffmpeg has no libx265");
490- eprintln!(
491- "SKIP bd_psnr_vs_x265: no ffmpeg with libx265 on PATH. \
492- Install one, then: cargo test --release -p ec-h265 --test encode \
493- bd_psnr_vs_x265 -- --nocapture"
494- );
495- return;
496- }
497 let (w, h, sources) = match std::env::var_os("EC_H265_CLIP") {481 let (w, h, sources) = match std::env::var_os("EC_H265_CLIP") {
498 Some(path) => clip_sources(&path, 24),482 Some(path) => clip_sources(&path, 24),
499 None => {483 None => {
@@ -844,7 +828,7 @@ fn bd_psnr_vs_x265() {
844 /// `EC_H265_CLIP_SKIP` passes over that many pictures before sampling (film828 /// `EC_H265_CLIP_SKIP` passes over that many pictures before sampling (film
845 /// heads are titles and fades).829 /// heads are titles and fades).
846 fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Planes>) {830 fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Planes>) {
847- let dims = std::process::Command::new("ffprobe")831+ let dims = ec_testkit::ffprobe()
848 .args([832 .args([
849 "-v",833 "-v",
850 "error",834 "error",
@@ -887,7 +871,7 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
887 // killer. `select` drops the skipped pictures inside ffmpeg and871 // killer. `select` drops the skipped pictures inside ffmpeg and
888 // `-frames:v` stops the decode once `want` have come out, so what reaches872 // `-frames:v` stops the decode once `want` have come out, so what reaches
889 // this process is exactly `want` frames.873 // this process is exactly `want` frames.
890- let raw = std::process::Command::new("ffmpeg")874+ let raw = ec_testkit::ffmpeg()
891 .args(["-v", "error", "-i"])875 .args(["-v", "error", "-i"])
892 .arg(path)876 .arg(path)
893 .args([877 .args([
crates/ec-h265/tests/it/real_library.rsmodified+24 -50
@@ -1,19 +1,10 @@
1-//! The personal media library, HEVC half: every `hevc` row of
2-//! `fixtures/real-library-manifest.tsv` is extracted to Annex B, its first
3-//! `FRAMES` pictures are decoded, and each output frame is compared sample for
4-//! sample with ffmpeg's own `hevc` decoder at the same pixel format.
5-//!
6 //! Every file either decodes bit-exactly, is refused by name (a pixel format or1 //! Every file either decodes bit-exactly, is refused by name (a pixel format or
7 //! a bit depth outside 4:2:0 8/10-bit, or a decoder refusal that says2 //! a bit depth outside 4:2:0 8/10-bit, or a decoder refusal that says
8 //! "unsupported"), or fails. A refusal is reported, not counted as a failure.3 //! "unsupported"), or fails. A refusal is reported, not counted as a failure.
9-//!
10-//! LOCAL ONLY and ignored: the manifest is generated from the user's own media
11-//! by `scripts/scan-real-library.sh` and is gitignored, so no other host has it.
12-//! cargo test -p ec-h265 --test real_library -- --ignored --nocapture
13 4
14 use std::io::Read;5 use std::io::Read;
15 use std::path::{Path, PathBuf};6 use std::path::{Path, PathBuf};
16-use std::process::{Command, Stdio};7+use std::process::Stdio;
17 8
18 use ec_h265::dec::Decoder;9 use ec_h265::dec::Decoder;
19 use ec_h265::decode::DecodedPicture;10 use ec_h265::decode::DecodedPicture;
@@ -25,15 +16,6 @@ const FRAMES: usize = 300;
25 /// Pixel formats inside the decoder's scope: 4:2:0 at 8 or 10 bits.16 /// Pixel formats inside the decoder's scope: 4:2:0 at 8 or 10 bits.
26 const IN_SCOPE_PIX_FMTS: [&str; 2] = ["yuv420p", "yuv420p10le"];17 const IN_SCOPE_PIX_FMTS: [&str; 2] = ["yuv420p", "yuv420p10le"];
27 18
28-fn have_ffmpeg() -> bool {
29- Command::new("ffmpeg")
30- .arg("-version")
31- .stdout(Stdio::null())
32- .stderr(Stdio::null())
33- .status()
34- .is_ok_and(|s| s.success())
35-}
36-
37 fn scratch(tag: &str) -> PathBuf {19 fn scratch(tag: &str) -> PathBuf {
38 let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from);20 let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from);
39 let dir = base.join(format!("ec-h265-{tag}-{}", std::process::id()));21 let dir = base.join(format!("ec-h265-{tag}-{}", std::process::id()));
@@ -50,31 +32,25 @@ struct Entry {
50 pix_fmt: String,32 pix_fmt: String,
51 }33 }
52 34
53-fn manifest_hevc_entries() -> Vec<Entry> {35+fn hevc_entries() -> Vec<Entry> {
54- let manifest =36+ [
55- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");37+ (
56- let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| {38+ "derived/sintel720-x265-main10.mp4",
57- panic!(39+ "yuv420p10le",
58- "{}: {e}. This test sweeps the personal library; generate the manifest with \40+ "1280",
59- scripts/scan-real-library.sh on the machine that holds the media.",41+ "720",
60- manifest.display()42+ ),
61- )43+ ("open/sintel_trailer-1080p.mp4", "yuv420p", "1920", "1080"),
62- });44+ ]
63- let mut out = Vec::new();45+ .into_iter()
64- for line in text.lines().skip(1) {46+ .map(|(rel, pix_fmt, width, height)| Entry {
65- let f: Vec<&str> = line.split('\t').collect();47+ path: ec_testkit::fixture(rel),
66- if f.len() < 6 || f[2] != "hevc" || !Path::new(f[0]).is_file() {48+ container: "mp4".to_string(),
67- continue;49+ width: width.to_string(),
68- }50+ height: height.to_string(),
69- out.push(Entry {51+ pix_fmt: pix_fmt.to_string(),
70- path: PathBuf::from(f[0]),52+ })
71- container: f[1].to_string(),53+ .collect()
72- width: f[3].to_string(),
73- height: f[4].to_string(),
74- pix_fmt: f[5].to_string(),
75- });
76- }
77- out
78 }54 }
79 55
80 /// The samples of a picture cropped to its conformance window, as the bytes of a56 /// The samples of a picture cropped to its conformance window, as the bytes of a
@@ -232,7 +208,7 @@ fn short_name(path: &Path) -> String {
232 /// with the text the table prints.208 /// with the text the table prints.
233 fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, String> {209 fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, String> {
234 let bps = if bit_depth > 8 { 2 } else { 1 };210 let bps = if bit_depth > 8 { 2 } else { 1 };
235- let mut child = Command::new("ffmpeg")211+ let mut child = ec_testkit::ffmpeg()
236 .args(["-v", "error", "-c:v", "hevc", "-i"])212 .args(["-v", "error", "-c:v", "hevc", "-i"])
237 .arg(es)213 .arg(es)
238 .args([214 .args([
@@ -286,7 +262,7 @@ fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, Strin
286 262
287 /// Extracts the first `FRAMES` pictures of the video as Annex B.263 /// Extracts the first `FRAMES` pictures of the video as Annex B.
288 fn extract(src: &Path, dst: &Path) -> bool {264 fn extract(src: &Path, dst: &Path) -> bool {
289- Command::new("ffmpeg")265+ ec_testkit::ffmpeg()
290 .args(["-v", "error", "-y", "-i"])266 .args(["-v", "error", "-y", "-i"])
291 .arg(src)267 .arg(src)
292 .args([268 .args([
@@ -307,11 +283,9 @@ fn extract(src: &Path, dst: &Path) -> bool {
307 }283 }
308 284
309 #[test]285 #[test]
310-#[ignore = "sweeps the PERSONAL media library (fixtures/real-library-manifest.tsv, hevc rows) through ffmpeg; minutes of wall time. Local only: run with --ignored."]286+#[ignore = "slow: decodes and compares two open clips with ffmpeg; run with --ignored."]
311 fn real_library_hevc_streams_match_ffmpeg() {287 fn real_library_hevc_streams_match_ffmpeg() {
312- assert!(have_ffmpeg(), "ffmpeg is required to sweep the library");288+ let entries = hevc_entries();
313- let entries = manifest_hevc_entries();
314- assert!(!entries.is_empty(), "the manifest lists no hevc rows");
315 let dir = scratch("real-library-hevc");289 let dir = scratch("real-library-hevc");
316 let mut table = String::new();290 let mut table = String::new();
317 let mut decoded = 0usize;291 let mut decoded = 0usize;
crates/ec-h265/tests/it/scaling_lists.rsmodified+3 -21
@@ -8,7 +8,6 @@
8 use ec_h265::Decoder;8 use ec_h265::Decoder;
9 use ec_h265::dec::Frame;9 use ec_h265::dec::Frame;
10 use std::path::{Path, PathBuf};10 use std::path::{Path, PathBuf};
11-use std::process::Command;
12 11
13 /// The four scaling-list streams the picture-management sweep covers; `str` is12 /// The four scaling-list streams the picture-management sweep covers; `str` is
14 /// the SLIST_D stream.13 /// the SLIST_D stream.
@@ -20,10 +19,7 @@ const STREAMS: [&str; 4] = [
20 ];19 ];
21 20
22 fn vectors_dir() -> PathBuf {21 fn vectors_dir() -> PathBuf {
23- match std::env::var("EC_H265_JCTVC_DIR") {22+ ec_testkit::fixture("vectors/hevc-jctvc")
24- Ok(dir) => PathBuf::from(dir),
25- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
26- }
27 }23 }
28 24
29 /// The first output picture as 4:2:0 bytes cropped to the conformance window.25 /// The first output picture as 4:2:0 bytes cropped to the conformance window.
@@ -59,7 +55,7 @@ fn cropped_yuv(frame: &Frame) -> Vec<u8> {
59 /// The first frame of `path` as ffmpeg decodes it, in yuv420p.55 /// The first frame of `path` as ffmpeg decodes it, in yuv420p.
60 fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {56 fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {
61 let out = std::env::temp_dir().join(format!("ec-h265-scaling-{tag}.yuv"));57 let out = std::env::temp_dir().join(format!("ec-h265-scaling-{tag}.yuv"));
62- let status = Command::new("ffmpeg")58+ let status = ec_testkit::ffmpeg()
63 .args(["-v", "error", "-y", "-i"])59 .args(["-v", "error", "-y", "-i"])
64 .arg(path)60 .arg(path)
65 .args(["-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "yuv420p"])61 .args(["-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -72,31 +68,17 @@ fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {
72 std::fs::read(&out).map_err(|e| e.to_string())68 std::fs::read(&out).map_err(|e| e.to_string())
73 }69 }
74 70
75-fn have_ffmpeg() -> bool {
76- Command::new("ffmpeg")
77- .arg("-version")
78- .output()
79- .is_ok_and(|o| o.status.success())
80-}
81-
82 // Ignored until the intra path decodes the syntax these streams use: the decode71 // Ignored until the intra path decodes the syntax these streams use: the decode
83 // desyncs at the last CTB of the IDR, and the intra CTU loop has no SAO or72 // desyncs at the last CTB of the IDR, and the intra CTU loop has no SAO or
84 // cu_qp_delta parsing. Run with `--ignored` to see the failure.73 // cu_qp_delta parsing. Run with `--ignored` to see the failure.
85 #[ignore = "intra path lacks the syntax these streams use (desync at the IDR's last CTB)"]74 #[ignore = "intra path lacks the syntax these streams use (desync at the IDR's last CTB)"]
86 #[test]75 #[test]
87 fn first_picture_of_each_scaling_list_stream_matches_ffmpeg() {76 fn first_picture_of_each_scaling_list_stream_matches_ffmpeg() {
88- if !have_ffmpeg() {
89- eprintln!("scaling-list check skipped: ffmpeg absent");
90- return;
91- }
92 let dir = vectors_dir();77 let dir = vectors_dir();
93 let mut checked = 0usize;78 let mut checked = 0usize;
94 for rel in STREAMS {79 for rel in STREAMS {
95 let path = dir.join(rel);80 let path = dir.join(rel);
96- let Ok(data) = std::fs::read(&path) else {81+ let data = std::fs::read(&path).unwrap_or_else(|e| panic!("{rel}: {e}"));
97- eprintln!("scaling-list check: {rel} absent, skipped");
98- continue;
99- };
100 let mut decoder = Decoder::new();82 let mut decoder = Decoder::new();
101 decoder83 decoder
102 .decode_annex_b(&data)84 .decode_annex_b(&data)