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 +194 -1180

Cargo.lockmodified+3 -0
@@ -499,6 +499,7 @@ dependencies = [
499499 "ec-h264-syntax",
500500 "ec-matroska",
501501 "ec-mp4",
502+ "ec-testkit",
502503 "tracking-allocator",
503504 "wide",
504505 ]
@@ -518,6 +519,7 @@ dependencies = [
518519 "bytemuck",
519520 "ec-core",
520521 "ec-h265-syntax",
522+ "ec-testkit",
521523 "multiversion",
522524 "wide",
523525 ]
@@ -527,6 +529,7 @@ name = "ec-h265-syntax"
527529 version = "0.1.0"
528530 dependencies = [
529531 "ec-core",
532+ "ec-testkit",
530533 ]
531534
532535 [[package]]
crates/ec-h264/Cargo.tomlmodified+1 -0
@@ -18,6 +18,7 @@ ec-h264-syntax = { workspace = true }
1818 wide = { workspace = true }
1919
2020 [dev-dependencies]
21+ec-testkit.workspace = true
2122 # The conformance harness walks Annex B itself to drive push_nal.
2223 ec-h264-syntax = { workspace = true }
2324 # ... 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 @@
44 set -euo pipefail
55
66 here=$(cd -- "$(dirname -- "$0")" && pwd)
7-src="$here/../../../fixtures/vectors/h264-jvt"
7+src="${EC_FIXTURES:-$here/../../../fixtures}/vectors/h264-jvt"
88 dst="$here/corpus/decode_annexb"
99
1010 seeds=(
@@ -19,7 +19,7 @@ mkdir -p "$dst"
1919 for rel in "${seeds[@]}"; do
2020 f="$src/$rel"
2121 if [ ! -f "$f" ]; then
22- echo "seed.sh: missing fixture $f (run scripts/link-fixtures.sh)" >&2
22+ echo "seed.sh: missing fixture $f (run scripts/fixtures.sh)" >&2
2323 exit 1
2424 fi
2525 cp -f "$f" "$dst/$(basename "$rel")"
crates/ec-h264/tests/conformance.rsmodified+9 -489
@@ -1,7 +1,5 @@
11 //! JVT conformance: first IDR picture, bit-exact.
22 //!
3-//! Fixture-gated like tools/oracle: fixtures/ is gitignored, so a checkout
4-//! without `scripts/fetch-vectors.sh` skips loudly instead of failing.
53 //!
64 //! Oracles, in order of authority:
75 //! 1. The reference decoder YUV that ships with each JVT vector (first
@@ -18,7 +16,6 @@ use std::sync::Once;
1816 use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator};
1917 use std::cell::Cell;
2018 use std::path::{Path, PathBuf};
21-use std::process::Command;
2219 use std::sync::atomic::{AtomicU64, Ordering};
2320
2421 use ec_core::registry::{CodecId, CodecParameters, Decoder as _};
@@ -76,38 +73,9 @@ fn install_counter() {
7673 // ---------------------------------------------------------------------------
7774
7875 fn vectors_dir() -> PathBuf {
79- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")
76+ ec_testkit::fixture("vectors/h264-jvt")
8077 }
8178
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
11179 /// order.
11280 ///
11381 /// 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> {
153121 }
154122
155123 fn ffmpeg_first_frame(stream: &Path) -> Option<Vec<u8>> {
156- let out = Command::new("ffmpeg")
124+ let out = ec_testkit::ffmpeg()
157125 .args(["-v", "error", "-i"])
158126 .arg(stream)
159127 .args([
@@ -235,7 +203,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, Error> {
235203
236204 /// Every frame ffmpeg decodes from `stream`, as raw I420.
237205 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()
239207 .args(["-v", "error", "-i"])
240208 .arg(stream)
241209 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
@@ -291,7 +259,7 @@ fn x264_encode_gop(
291259 stream.to_string_lossy().into_owned(),
292260 ]);
293261 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)
295263 }
296264
297265 /// Decode `stream` both ways and report the first frame that differs.
@@ -328,23 +296,13 @@ fn compare_sequence(stream: &Path) -> Result<usize, String> {
328296 #[test]
329297 fn jvt_cavlc_first_idr_bit_exact() {
330298 let base = vectors_dir();
331- if !require_fixtures(
332- &base,
333- "the JVT conformance vectors",
334- "scripts/fetch-vectors.sh",
335- ) {
336- return;
337- }
338299 let mut passed = Vec::new();
339300 let mut failed = Vec::new();
340301 let mut refused = Vec::new();
341302 for name in all_vectors(&base) {
342303 let name = name.as_str();
343304 let dir = base.join(name);
344- let Some(stream) = find_stream(&dir) else {
345- eprintln!("SKIP {name}: no bitstream file");
346- continue;
347- };
305+ let stream = find_stream(&dir).unwrap_or_else(|| panic!("{name}: no bitstream file"));
348306 let bytes = std::fs::read(&stream).unwrap();
349307 match decode_first(&bytes) {
350308 Ok((ours, w, h)) => {
@@ -436,13 +394,6 @@ fn jvt_cavlc_first_idr_bit_exact() {
436394 fn steady_state_decode_loop_zero_alloc() {
437395 install_counter();
438396 let base = vectors_dir();
439- if !require_fixtures(
440- &base,
441- "the JVT conformance vectors",
442- "scripts/fetch-vectors.sh",
443- ) {
444- return;
445- }
446397 // One stream per entropy coder, and one with B slices and multiple
447398 // reference frames so the decoded picture buffer really recycles pictures.
448399 for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] {
@@ -523,13 +474,6 @@ fn steady_state_decode_loop_zero_alloc() {
523474 #[test]
524475 fn ns_per_macroblock_measurement() {
525476 let base = vectors_dir();
526- if !require_fixtures(
527- &base,
528- "the JVT conformance vectors",
529- "scripts/fetch-vectors.sh",
530- ) {
531- return;
532- }
533477 for name in [
534478 "BA1_Sony_D",
535479 "CI_MW_D",
@@ -610,13 +554,6 @@ fn perf_whole_sequence() {
610554 #[test]
611555 fn corrupt_streams_never_panic() {
612556 let base = vectors_dir();
613- if !require_fixtures(
614- &base,
615- "the JVT conformance vectors",
616- "scripts/fetch-vectors.sh",
617- ) {
618- return;
619- }
620557 // One stream per entropy coder, plus one with B slices and multiple
621558 // references: CABAC's arithmetic decoder indexes context and coefficient
622559 // arrays from stream-derived values, and inter prediction indexes the
@@ -682,9 +619,8 @@ fn corrupt_sweep(bytes: &[u8]) {
682619 // ffmpeg's own decoder as the oracle.
683620 // ---------------------------------------------------------------------------
684621
685-/// Run a command, false when it fails or is not installed.
686-fn run(command: &str, args: &[&str]) -> bool {
687- Command::new(command)
622+fn run(args: &[&str]) -> bool {
623+ ec_testkit::ffmpeg()
688624 .args(args)
689625 .stdout(std::process::Stdio::null())
690626 .stderr(std::process::Stdio::null())
@@ -693,13 +629,6 @@ fn run(command: &str, args: &[&str]) -> bool {
693629 .unwrap_or(false)
694630 }
695631
696-fn have_ffmpeg() -> bool {
697- run(
698- "ffmpeg",
699- &["-hide_banner", "-loglevel", "error", "-version"],
700- )
701-}
702-
703632 /// A private scratch directory for one test.
704633 fn scratch(tag: &str) -> PathBuf {
705634 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
742671 stream.to_string_lossy().into_owned(),
743672 ]);
744673 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)
746675 }
747676
748677 /// Encode, decode both ways, return the number of differing bytes.
@@ -787,10 +716,6 @@ const ENTROPY_MODES: [(&str, &[&str]); 2] = [
787716 /// produces, none of which the QCIF single-slice vectors cover.
788717 #[test]
789718 fn geometry_and_slice_structure_match_ffmpeg() {
790- if !have_ffmpeg() {
791- eprintln!("SKIP: ffmpeg not on PATH");
792- return;
793- }
794719 let dir = scratch("geometry");
795720 let cases: &[(&str, &str, &[&str])] = &[
796721 // 1080 lines are coded as 68 macroblock rows and cropped back to 1080.
@@ -851,10 +776,6 @@ fn geometry_and_slice_structure_match_ffmpeg() {
851776 /// nothing else in the suite would notice it regressing into a refusal.
852777 #[test]
853778 fn jvt_scaling_matrices_decode_bit_exact() {
854- if !have_ffmpeg() {
855- eprintln!("SKIP: ffmpeg not on PATH");
856- return;
857- }
858779 let dir = scratch("scaling");
859780 let extra = [
860781 "-profile:v",
@@ -877,10 +798,6 @@ fn jvt_scaling_matrices_decode_bit_exact() {
877798 /// prefixed — how an MP4 or Matroska demuxer hands H.264 over.
878799 #[test]
879800 fn avcc_extradata_and_length_prefixed_packets() {
880- if !have_ffmpeg() {
881- eprintln!("SKIP: ffmpeg not on PATH");
882- return;
883- }
884801 let dir = scratch("avcc");
885802 let Some(annex_b) = x264_encode(
886803 &dir,
@@ -960,10 +877,6 @@ fn avcc_extradata_and_length_prefixed_packets() {
960877 /// once, so it is the first test to look at when any of them regress.
961878 #[test]
962879 fn p_only_gop_matches_ffmpeg_every_frame() {
963- if !have_ffmpeg() {
964- eprintln!("SKIP: ffmpeg not on PATH");
965- return;
966- }
967880 let dir = scratch("p-gop");
968881 let mut failures = Vec::new();
969882 for (mode, profile) in ENTROPY_MODES {
@@ -992,13 +905,6 @@ fn p_only_gop_matches_ffmpeg_every_frame() {
992905 #[test]
993906 fn jvt_full_sequence_bit_exact() {
994907 let base = vectors_dir();
995- if !require_fixtures(
996- &base,
997- "the JVT conformance vectors",
998- "scripts/fetch-vectors.sh",
999- ) {
1000- return;
1001- }
1002908 let mut table = String::new();
1003909 let mut passed = 0usize;
1004910 let mut refused = Vec::new();
@@ -1144,10 +1050,6 @@ fn slice_type_counts(bytes: &[u8]) -> [usize; 3] {
11441050 /// they arrived.
11451051 #[test]
11461052 fn b_pictures_match_ffmpeg_every_frame() {
1147- if !have_ffmpeg() {
1148- eprintln!("SKIP: ffmpeg not on PATH");
1149- return;
1150- }
11511053 let dir = scratch("b-gop");
11521054 let cases: &[(&str, &[&str])] = &[
11531055 (
@@ -1227,10 +1129,6 @@ fn b_pictures_match_ffmpeg_every_frame() {
12271129 /// test would pass on a decoder that never reorders anything.
12281130 #[test]
12291131 fn output_is_display_order_and_the_reorder_is_real() {
1230- if !have_ffmpeg() {
1231- eprintln!("SKIP: ffmpeg not on PATH");
1232- return;
1233- }
12341132 let dir = scratch("order");
12351133 let extra = [
12361134 "-profile:v",
@@ -1296,10 +1194,6 @@ fn output_is_display_order_and_the_reorder_is_real() {
12961194 /// preview after a seek.
12971195 #[test]
12981196 fn a_frame_num_gap_keeps_decoding() {
1299- if !have_ffmpeg() {
1300- eprintln!("SKIP: ffmpeg not on PATH");
1301- return;
1302- }
13031197 let dir = scratch("gap");
13041198 let extra = [
13051199 "-profile:v",
@@ -1359,10 +1253,6 @@ fn a_frame_num_gap_keeps_decoding() {
13591253 /// inter prediction and reordering active.
13601254 #[test]
13611255 fn geometry_with_motion_matches_ffmpeg() {
1362- if !have_ffmpeg() {
1363- eprintln!("SKIP: ffmpeg not on PATH");
1364- return;
1365- }
13661256 let dir = scratch("geometry-motion");
13671257 let cases: &[(&str, &str, &[&str])] = &[
13681258 ("hd", "1920x1080", &["bframes=2:b-adapt=0"]),
@@ -1511,96 +1401,10 @@ fn switching_slices_are_refused_by_name() {
15111401 }
15121402 }
15131403
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-}
15991404
16001405 /// Extract the video elementary stream of a real file as Annex B.
16011406 fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
16021407 run(
1603- "ffmpeg",
16041408 &[
16051409 "-v",
16061410 "error",
@@ -1622,273 +1426,8 @@ fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
16221426 )
16231427 }
16241428
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.
18861429 #[test]
18871430 fn packet_entry_surface_reorders_and_carries_timestamps() {
1888- if !have_ffmpeg() {
1889- eprintln!("SKIP: ffmpeg not on PATH");
1890- return;
1891- }
18921431 let dir = scratch("entry");
18931432 let extra = [
18941433 "-profile:v",
@@ -2004,10 +1543,6 @@ fn packet_entry_surface_reorders_and_carries_timestamps() {
20041543 /// are what makes the two readings differ at all, so this needs `-refs`.
20051544 #[test]
20061545 fn spatial_direct_over_a_b_reference_matches_ffmpeg() {
2007- if !have_ffmpeg() {
2008- eprintln!("SKIP: ffmpeg not on PATH");
2009- return;
2010- }
20111546 let dir = scratch("direct-bref");
20121547 let mut failures = Vec::new();
20131548 for (tag, coder) in [("cabac", "ac"), ("cavlc", "0")] {
@@ -2073,10 +1608,6 @@ fn pps_enables_8x8(stream: &Path) -> bool {
20731608 /// 8x8 macroblock alone (8.7).
20741609 #[test]
20751610 fn high_profile_8x8_inter_sequences_match_ffmpeg() {
2076- if !have_ffmpeg() {
2077- eprintln!("SKIP: ffmpeg not on PATH");
2078- return;
2079- }
20801611 let dir = scratch("high8x8-seq");
20811612 let mut failures = Vec::new();
20821613 let cases: &[(&str, &[&str])] = &[
@@ -2160,18 +1691,7 @@ fn high_profile_8x8_inter_sequences_match_ffmpeg() {
21601691 /// picture itself, per D.2.8 absent a recovery_point SEI.
21611692 #[test]
21621693 fn h264_seek_matches_linear_open_gop() {
2163- if !have_ffmpeg() {
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- }
1694+ let src = ec_testkit::fixture("video/h264-open-gop.mp4");
21751695 let dir = scratch("open-gop");
21761696 std::fs::create_dir_all(&dir).unwrap();
21771697 let annexb = dir.join("open-gop.264");
crates/ec-h264/tests/it/common.rsmodified+2 -3
@@ -2,7 +2,6 @@
22 //! ffmpeg pipes and stream utilities that were identical in each file.
33
44 use std::path::{Path, PathBuf};
5-use std::process::Command;
65
76 use ec_core::frame::{PixelFormat, VideoFrame};
87
@@ -25,7 +24,7 @@ pub(super) fn frame_bytes(frame: &VideoFrame) -> Vec<u8> {
2524 }
2625
2726 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()
2928 .args(["-v", "error", "-i"])
3029 .arg(stream)
3130 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -78,7 +77,7 @@ pub(super) fn layout(f: PixelFormat) -> (usize, usize, usize) {
7877 }
7978
8079 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()
8281 .args(["-v", "error", "-f", "h264", "-i"])
8382 .arg(stream)
8483 .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() {
427427 // absent, exactly like the conformance suite's ffmpeg cross-check.
428428 // ---------------------------------------------------------------------------
429429
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-
463430 /// Write `bytes` to `path` and PROVE the file on disk is exactly that long.
464431 ///
465432 /// 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
635602 SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
636603 ));
637604 pin_or_bail("ffmpeg_decode", &path, stream)?;
638- let mut cmd = std::process::Command::new("ffmpeg");
605+ let mut cmd = ec_testkit::ffmpeg();
639606 cmd.args(["-v", "error"]);
640607 cmd.args(extra);
641608 cmd.arg("-i").arg(&path);
@@ -777,10 +744,6 @@ fn eight_by_eight_gains_on_flat_and_text() {
777744 /// across a QP sweep and at a size that is not a multiple of a macroblock.
778745 #[test]
779746 fn ffmpeg_decodes_bit_exactly() {
780- if !have_ffmpeg() {
781- eprintln!("SKIP ffmpeg_decodes_bit_exactly: no ffmpeg on PATH");
782- return;
783- }
784747 let mut t8x8_mbs = (0, 0);
785748 for (w, h) in [(176, 144), (322, 242)] {
786749 for qp in [10, 20, 28, 37, 47] {
@@ -813,10 +776,6 @@ fn ffmpeg_decodes_bit_exactly() {
813776 /// The same stream under constant bitrate, which is the mode edith exports in.
814777 #[test]
815778 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- }
820779 let (w, h) = (352, 288);
821780 let (stream, recons, _) = encode_clip(w, h, 12, |cfg| {
822781 cfg.bitrate = 2_000_000;
@@ -839,8 +798,8 @@ fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {
839798 /// software decoder says about it.
840799 #[test]
841800 fn vaapi_decodes_our_stream() {
842- if !have_ffmpeg() || !std::path::Path::new("/dev/dri/renderD128").exists() {
843- eprintln!("SKIP vaapi_decodes_our_stream: no ffmpeg or no render node");
801+ if !std::path::Path::new("/dev/dri/renderD128").exists() {
802+ eprintln!("SKIP vaapi_decodes_our_stream: no render node");
844803 return;
845804 }
846805 let (w, h) = (352, 288);
@@ -882,50 +841,10 @@ fn vaapi_decodes_our_stream() {
882841 fn real_library_frames_encode_and_decode_exactly() {
883842 use ec_core::registry::Decoder as _;
884843
885- if !have_ffmpeg() {
886- eprintln!("SKIP real_library_frames: no ffmpeg on PATH");
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- };
844+ let path = ec_testkit::fixture("open/sintel_trailer-720p.mp4");
845+ let (w, h) = (1280, 720);
926846
927- // Decode a handful of real pictures.
928- let (params, mut demux, index) = open_h264_source(std::ffi::OsStr::new(&path));
847+ let (params, mut demux, index) = open_h264_source(path.as_os_str());
929848 let mut dec = ec_h264::H264Decoder::new(params).expect("decoder");
930849 let mut sources: Vec<Planes> = Vec::new();
931850 while sources.len() < 12 {
@@ -1124,12 +1043,10 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
11241043 /// EC_H264_CLIP=<file> cargo test --release -p ec-h264 --test encode \
11251044 /// real_clip_t8x8_bd_psnr -- --ignored --nocapture
11261045 #[test]
1127-#[ignore = "set EC_H264_CLIP to a media file of yours"]
1046+#[ignore = "slow measurement on the open 480p trailer"]
11281047 fn real_clip_t8x8_bd_psnr() {
1129- let Some(path) = std::env::var_os("EC_H264_CLIP") else {
1130- panic!("EC_H264_CLIP must name a media file");
1131- };
1132- let (w, h, sources) = clip_sources(&path, 30);
1048+ let path = ec_testkit::fixture("open/sintel_trailer-480p.mp4");
1049+ let (w, h, sources) = clip_sources(path.as_os_str(), 30);
11331050
11341051 let run = |t8x8: bool, qp: i32| {
11351052 let mut cfg = EncoderConfig::new(w as u32, h as u32);
@@ -1200,7 +1117,7 @@ fn real_clip_t8x8_bd_psnr() {
12001117 const BD_PSNR_VS_X264_FLOOR: f64 = -4.15;
12011118
12021119 fn have_x264() -> bool {
1203- std::process::Command::new("ffmpeg")
1120+ ec_testkit::ffmpeg()
12041121 .args(["-v", "error", "-hide_banner", "-encoders"])
12051122 .output()
12061123 .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) ->
12281145 buf.extend_from_slice(v);
12291146 }
12301147 pin_or_bail("x264_encode_qp", &raw, &buf)?;
1231- let status = std::process::Command::new("ffmpeg")
1148+ let status = ec_testkit::ffmpeg()
12321149 .args(["-v", "error", "-y"])
12331150 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
12341151 .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) ->
13101227 /// bd_psnr_vs_x264 -- --nocapture
13111228 #[test]
13121229 fn bd_psnr_vs_x264() {
1313- if !have_ffmpeg() || !have_x264() {
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- }
1230+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
13211231 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
13221232 Some(path) => clip_sources(&path, 24),
13231233 None => {
@@ -1485,10 +1395,7 @@ fn bd_psnr_vs_x264() {
14851395 /// bit_account_vs_x264 -- --nocapture
14861396 #[test]
14871397 fn bit_account_vs_x264() {
1488- if !have_ffmpeg() || !have_x264() {
1489- eprintln!("SKIP bit_account_vs_x264: no ffmpeg with libx264 on PATH");
1490- return;
1491- }
1398+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
14921399 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
14931400 Some(path) => clip_sources(&path, 12),
14941401 None => {
@@ -1578,10 +1485,6 @@ fn bit_account_vs_x264() {
15781485 /// never a `sub_mb_type` -- in front of another decoder. This does.
15791486 #[test]
15801487 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- }
15851488 let (w, h) = (176, 144);
15861489 let mut shapes = ec_h264::MbShapes::default();
15871490 for qp in [16, 26, 36] {
crates/ec-h264/tests/it/high10.rsmodified+4 -16
@@ -5,12 +5,8 @@
55 //! 1. Committed fixtures in `tests/data/high10/`: tiny libx264 streams with the
66 //! MD5 of ffmpeg's decode beside them, checked on every run with no ffmpeg.
77 //! 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.
118
129 use std::path::{Path, PathBuf};
13-use std::process::Command;
1410
1511 use ec_core::frame::{PixelFormat, VideoFrame};
1612 use ec_h264::{Decoder, NalOutcome};
@@ -54,7 +50,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, ec_h264::Error> {
5450 }
5551
5652 fn ffmpeg_frames(stream: &Path, frame_len: usize) -> Option<Vec<u8>> {
57- let out = Command::new("ffmpeg")
53+ let out = ec_testkit::ffmpeg()
5854 .args(["-v", "error", "-i"])
5955 .arg(stream)
6056 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-"])
@@ -202,22 +198,14 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
202198 "h264".into(),
203199 stream.to_string_lossy().into_owned(),
204200 ]);
205- let st = Command::new("ffmpeg").args(&args).status().ok()?;
201+ let st = ec_testkit::ffmpeg().args(&args).status().ok()?;
206202 st.success().then_some(stream)
207203 }
208204
209205 fn check(c: &Case) -> Result<usize, String> {
210206 let dir = scratch();
211- let Some(stream) = encode(&dir, c) else {
212- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
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- };
207+ let stream =
208+ encode(&dir, c).unwrap_or_else(|| panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag));
221209 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
222210 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
223211 let first = ours.first().ok_or("no frames decoded")?;
crates/ec-h264/tests/it/high422.rsmodified+4 -22
@@ -3,14 +3,8 @@
33 //! with B-frames, CABAC and CAVLC, the 8x8 transform, weighted prediction,
44 //! scaling matrices, chroma QP offsets, several slices, progressive and
55 //! 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).
116
127 use std::path::{Path, PathBuf};
13-use std::process::Command;
148
159 use ec_h264::{Decoder, NalOutcome};
1610
@@ -72,7 +66,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
7266 } else {
7367 c.params.to_string()
7468 };
75- let st = Command::new("ffmpeg")
69+ let st = ec_testkit::ffmpeg()
7670 .args([
7771 "-hide_banner",
7872 "-loglevel",
@@ -99,16 +93,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
9993
10094 fn check(c: &Case) -> Result<usize, String> {
10195 let dir = scratch();
102- let Some(stream) = encode(&dir, c) else {
103- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
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- };
96+ let stream = encode(&dir, c)
97+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
11298 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
11399 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
114100 let first = ours
@@ -377,13 +363,9 @@ fn x264_hi422_mbaff() {
377363 sweep(&cases);
378364 }
379365
380-/// 1920x1080 intra and long-GOP, progressive and MBAFF (opt-in, slow).
366+/// 1920x1080 intra and long-GOP, progressive and MBAFF (slow).
381367 #[test]
382368 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- }
387369 sweep(&[
388370 case("hd-i-cabac", "testsrc2", "1920x1080", 2, "keyint=1"),
389371 case(
crates/ec-h264/tests/it/high422_jvt.rsmodified+15 -48
@@ -5,13 +5,9 @@
55 //! Where the archive carries a reference YUV (Hi422FR10..15) each frame is
66 //! compared to it; the other streams ship only a trace, so every stream is
77 //! 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
118 //! streams are slow in a debug build and are skipped there.
129
1310 use std::path::{Path, PathBuf};
14-use std::process::Command;
1511
1612 use ec_core::frame::PixelFormat;
1713 use ec_h264::{Decoder, NalOutcome};
@@ -19,7 +15,7 @@ use ec_h264::{Decoder, NalOutcome};
1915 use super::common::{ffmpeg_pix_frames, frame_bytes};
2016
2117 fn root() -> PathBuf {
22- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi422")
18+ ec_testkit::fixture("vectors/h264-jvt-hi422")
2319 }
2420
2521 /// Every elementary stream (`.264`, `.jsv`) below `dir`, sorted.
@@ -90,38 +86,19 @@ fn compare(name: &str, ours: &[Vec<u8>], theirs: &[u8], who: &str) -> Result<(),
9086 Ok(())
9187 }
9288
93-fn have_set() -> Option<Vec<PathBuf>> {
89+fn have_set() -> Vec<PathBuf> {
9490 let list = streams(&root());
95- if list.is_empty() {
96- assert!(
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)
91+ assert!(list.len() >= 18, "only {} Hi422 streams found", list.len());
92+ list
10693 }
10794
10895 #[test]
10996 fn jvt_hi422_vectors_bit_exact() {
110- let Some(list) = have_set() else { return };
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();
97+ let list = have_set();
11598 let mut failed = Vec::new();
11699 let mut exact = Vec::new();
117100 for path in &list {
118101 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- }
125102 let bytes = std::fs::read(path).unwrap();
126103 let (ours, format) = match decode_all(&bytes) {
127104 Ok(v) => v,
@@ -148,26 +125,16 @@ fn jvt_hi422_vectors_bit_exact() {
148125 ok = false;
149126 }
150127 }
151- if have_ffmpeg {
152- let pix = if format == PixelFormat::I210 {
153- "yuv422p10le"
154- } else {
155- "yuv422p"
156- };
157- match ffmpeg_pix_frames(path, pix) {
158- Some(t) => {
159- if let Err(e) = compare(&name, &ours, &t, "ffmpeg") {
160- failed.push(e);
161- ok = false;
162- }
163- }
164- None => {
165- assert!(
166- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
167- "{name}: ffmpeg cannot decode"
168- );
169- }
170- }
128+ let pix = if format == PixelFormat::I210 {
129+ "yuv422p10le"
130+ } else {
131+ "yuv422p"
132+ };
133+ let theirs =
134+ ffmpeg_pix_frames(path, pix).unwrap_or_else(|| panic!("{name}: ffmpeg cannot decode"));
135+ if let Err(e) = compare(&name, &ours, &theirs, "ffmpeg") {
136+ failed.push(e);
137+ ok = false;
171138 }
172139 if ok {
173140 exact.push(format!("{name} ({} frames, {format:?})", ours.len()));
crates/ec-h264/tests/it/high444.rsmodified+4 -22
@@ -9,14 +9,8 @@
99 //! on the luma plane against ffmpeg's `gray` / `gray10le`; chroma must be 128,
1010 //! or 512 at 10 bits). Separate colour planes cannot be written by x264; the
1111 //! 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`.
1712
1813 use std::path::{Path, PathBuf};
19-use std::process::Command;
2014
2115 use ec_core::frame::{PixelFormat, VideoFrame};
2216 use ec_h264::{Decoder, NalOutcome};
@@ -93,7 +87,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
9387 } else {
9488 c.params.to_string()
9589 };
96- let st = Command::new("ffmpeg")
90+ let st = ec_testkit::ffmpeg()
9791 .args([
9892 "-hide_banner",
9993 "-loglevel",
@@ -121,16 +115,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
121115
122116 fn check(c: &Case) -> Result<usize, String> {
123117 let dir = scratch();
124- let Some(stream) = encode(&dir, c) else {
125- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
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- };
118+ let stream = encode(&dir, c)
119+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
134120 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
135121 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
136122 let (first, format) = ours
@@ -616,13 +602,9 @@ fn x264_monochrome_mbaff_and_lossless() {
616602 sweep("gray MBAFF / lossless", &cases);
617603 }
618604
619-/// 1280x720 (opt-in, slow).
605+/// 1280x720 (slow).
620606 #[test]
621607 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- }
626608 let base = [
627609 case("hd-i-cabac", "testsrc2", "1280x720", 2, "keyint=1"),
628610 case(
crates/ec-h264/tests/it/high444_jvt.rsmodified+39 -55
@@ -8,13 +8,11 @@
88 //! the archive ships a reference YUV, that YUV is used instead of / as well as
99 //! ffmpeg; a stream with neither is reported `unchecked` (and counted as a
1010 //! 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
1311 //! debug builds.
1412
1513 use std::io::Read;
1614 use std::path::{Path, PathBuf};
17-use std::process::{Command, Stdio};
15+use std::process::Stdio;
1816
1917 use ec_core::frame::{PixelFormat, VideoFrame};
2018 use ec_h264::{Decoder, NalOutcome};
@@ -22,7 +20,7 @@ use ec_h264::{Decoder, NalOutcome};
2220 use super::common::layout;
2321
2422 fn root() -> PathBuf {
25- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi444")
23+ ec_testkit::fixture("vectors/h264-jvt-hi444")
2624 }
2725
2826 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> {
127125 }
128126
129127 fn probe_pix_fmt(stream: &Path) -> Option<String> {
130- let out = Command::new("ffprobe")
128+ let out = ec_testkit::ffprobe()
131129 .args(["-v", "error", "-f", "h264", "-select_streams", "v:0"])
132130 .args(["-show_entries", "stream=pix_fmt", "-of", "csv=p=0"])
133131 .arg(stream)
@@ -140,7 +138,7 @@ fn probe_pix_fmt(stream: &Path) -> Option<String> {
140138 /// ffmpeg's raw decode as a pipe, so a long 14-bit 4:4:4 stream is compared a
141139 /// frame at a time instead of held in memory.
142140 fn ffmpeg_pipe(stream: &Path, pix_fmt: &str) -> Option<std::process::Child> {
143- Command::new("ffmpeg")
141+ ec_testkit::ffmpeg()
144142 .args(["-v", "error", "-f", "h264", "-i"])
145143 .arg(stream)
146144 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -205,25 +203,15 @@ fn reference_yuv(stream: &Path) -> Option<PathBuf> {
205203 #[test]
206204 fn jvt_hi444_vectors_bit_exact() {
207205 let list = streams(&root());
208- if list.is_empty() {
209- assert!(
210- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
211- "h264-jvt-hi444 missing at {} - this gate would prove nothing; run \
212- scripts/fetch-vectors.sh h264-jvt-hi444",
213- root().display()
214- );
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();
206+ assert!(
207+ !list.is_empty(),
208+ "no h264-jvt-hi444 streams in {}",
209+ root().display()
210+ );
219211 let mut failed = Vec::new();
220212 let mut summary = Vec::new();
221213 for path in &list {
222214 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- }
227215 let bytes = std::fs::read(path).unwrap();
228216 let (ours, format) = match decode_all(&bytes) {
229217 Ok((f, fmt)) if !f.is_empty() => (f, fmt),
@@ -235,7 +223,6 @@ fn jvt_hi444_vectors_bit_exact() {
235223 Err(e) if e.to_string().contains("FMO") => {
236224 // The Sejong Univ. streams use slice groups, which this
237225 // decoder refuses by name (not part of this lane).
238- eprintln!("SKIP {name}: {e}");
239226 summary.push(format!("{name} fmo-refused"));
240227 continue;
241228 }
@@ -262,41 +249,38 @@ fn jvt_hi444_vectors_bit_exact() {
262249 Err(e) => errors.push(e),
263250 }
264251 }
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() {
268- Some("gray") => "gray".to_string(),
269- Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),
270- Some(p) if p.contains("p9") => p.replace("p9", "p10"),
271- Some(p) => p.to_string(),
272- None => match format {
273- PixelFormat::I410 => "yuv444p10le".into(),
274- PixelFormat::I444 => "yuv444p".into(),
275- _ => String::new(),
276- },
277- };
278- let luma_only = pix.starts_with("gray");
279- match (!pix.is_empty() && pix != "unknown")
280- .then(|| ffmpeg_pipe(path, &pix))
281- .flatten()
282- {
283- Some(mut child) => {
284- let res = compare(
285- &name,
286- &ours,
287- child.stdout.as_mut().unwrap(),
288- luma_only,
289- "ffmpeg",
290- );
291- let _ = child.kill();
292- let _ = child.wait();
293- match res {
294- Ok(()) => checked.push("ffmpeg"),
295- Err(e) => errors.push(e),
296- }
252+ let pix = match probe_pix_fmt(path).as_deref() {
253+ Some("gray") => "gray".to_string(),
254+ Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),
255+ Some(p) if p.contains("p9") => p.replace("p9", "p10"),
256+ Some(p) => p.to_string(),
257+ None => match format {
258+ PixelFormat::I410 => "yuv444p10le".into(),
259+ PixelFormat::I444 => "yuv444p".into(),
260+ _ => String::new(),
261+ },
262+ };
263+ let luma_only = pix.starts_with("gray");
264+ match (!pix.is_empty() && pix != "unknown")
265+ .then(|| ffmpeg_pipe(path, &pix))
266+ .flatten()
267+ {
268+ Some(mut child) => {
269+ let res = compare(
270+ &name,
271+ &ours,
272+ child.stdout.as_mut().unwrap(),
273+ luma_only,
274+ "ffmpeg",
275+ );
276+ let _ = child.kill();
277+ let _ = child.wait();
278+ match res {
279+ Ok(()) => checked.push("ffmpeg"),
280+ Err(e) => errors.push(e),
297281 }
298- None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),
299282 }
283+ None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),
300284 }
301285 if !errors.is_empty() {
302286 eprintln!("FAIL {name}: {}", errors.join("; "));
crates/ec-h264/tests/it/interlaced.rsmodified+4 -25
@@ -2,42 +2,24 @@
22 //! macroblock-adaptive frame/field coding (MBAFF), woven into frames.
33 //!
44 //! 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.
85
96 use std::path::{Path, PathBuf};
107
118 use ec_core::frame::{Interlace, VideoFrame};
129 use ec_h264::{Decoder, NalOutcome};
1310
14-/// Where a vector lives: the interlaced set (`scripts/fetch-vectors.sh`), or
1511 /// the general JVT set for the few interlaced streams that were fetched first.
1612 fn vector_dir(name: &str) -> PathBuf {
17- let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors");
18- let own = root.join("h264-jvt-interlaced").join(name);
13+ let own = ec_testkit::root()
14+ .join("vectors/h264-jvt-interlaced")
15+ .join(name);
1916 if own.exists() {
2017 own
2118 } else {
22- root.join("h264-jvt").join(name)
19+ ec_testkit::fixture(&format!("vectors/h264-jvt/{name}"))
2320 }
2421 }
2522
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-
4123 fn find_with_ext(dir: &Path, exts: &[&str]) -> Option<PathBuf> {
4224 let mut found: Vec<PathBuf> = std::fs::read_dir(dir)
4325 .ok()?
@@ -92,9 +74,6 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<(Vec<u8>, Interlace)>, ec_h264::Error>
9274 /// Decode one JVT vector and compare it with its reference YUV.
9375 fn check_vector(name: &str) -> Result<usize, String> {
9476 let dir = vector_dir(name);
95- if !have_fixture(&dir, &format!("JVT vector {name}")) {
96- return Ok(0);
97- }
9877 let stream = find_with_ext(&dir, &["jsv", "264", "avc", "26l", "h264", "jvt"])
9978 .ok_or(format!("{name}: no bitstream"))?;
10079 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 @@
33 //! sources: CABAC and CAVLC, top and bottom field first, B-frames with
44 //! spatial and temporal direct, weighted prediction, the 8x8 transform,
55 //! 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).
116
127 use std::path::{Path, PathBuf};
13-use std::process::Command;
148
159 use ec_core::frame::{PixelFormat, VideoFrame};
1610 use ec_h264::{Decoder, NalOutcome};
@@ -89,7 +83,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
8983 ("yuv420p", "high")
9084 };
9185 let params = format!("interlaced=1:{}", c.params);
92- let st = Command::new("ffmpeg")
86+ let st = ec_testkit::ffmpeg()
9387 .args([
9488 "-hide_banner",
9589 "-loglevel",
@@ -112,16 +106,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
112106
113107 fn check(c: &Case) -> Result<usize, String> {
114108 let dir = scratch();
115- let Some(stream) = encode(&dir, c) else {
116- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
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- };
109+ let stream = encode(&dir, c)
110+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
125111 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
126112 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
127113 let first = ours
@@ -369,13 +355,9 @@ fn x264_mbaff_sd() {
369355 ]);
370356 }
371357
372-/// 1920x1080: opt-in (`EC_H264_MBAFF_HD=1`).
358+/// 1920x1080.
373359 #[test]
374360 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- }
379361 sweep(&[
380362 case(
381363 "hd-cabac-tff",
crates/ec-h264/tests/it/no_panic.rsmodified+1 -12
@@ -5,8 +5,6 @@
55 //! fixed-seed positions. Every mutant is decoded end to end. An `Err` is fine;
66 //! a panic fails the test.
77 //!
8-//! Fixture-gated like the other conformance tests: without `fixtures/` the test
9-//! skips loudly, or fails when `EC_REQUIRE_FIXTURES` is set.
108
119 use std::path::{Path, PathBuf};
1210
@@ -20,7 +18,7 @@ const CORRUPTIONS: usize = 30;
2018 const SEED: u32 = 0x9E37_79B9;
2119
2220 fn vectors_dir() -> PathBuf {
23- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")
21+ ec_testkit::fixture("vectors/h264-jvt")
2422 }
2523
2624 /// Every vector directory, in name order (the order `conformance.rs` walks).
@@ -53,15 +51,6 @@ fn decode_everything(bytes: &[u8]) {
5351 #[test]
5452 fn truncated_and_corrupted_conformance_streams_never_panic() {
5553 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- }
6554 let mut streams = 0usize;
6655 for name in vector_names(&base).into_iter().take(STREAMS) {
6756 let Some(stream) = find_stream(&base.join(&name)) else {
crates/ec-h264/tests/it/refusals.rsmodified+1 -13
@@ -10,8 +10,6 @@
1010 //! maps every refused JVT conformance vector to the feature it really uses,
1111 //! and is fixture-gated like `conformance.rs`.
1212
13-use std::path::Path;
14-
1513 use ec_core::BitWriter;
1614 use ec_h264::{Decoder, Error, NalOutcome};
1715
@@ -294,21 +292,11 @@ fn different_luma_and_chroma_bit_depth_is_refused_by_name() {
294292 }
295293 }
296294
297-/// Every refused vector in `fetch-vectors.sh`'s h264-jvt set, against the
298295 /// feature it really uses. A vector that starts refusing for another reason,
299296 /// or stops being refused, changes this table and fails the test.
300297 #[test]
301298 fn jvt_refused_vectors_refuse_for_their_feature() {
302- let base = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/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- }
299+ let base = ec_testkit::fixture("vectors/h264-jvt");
312300 let expected: &[(&str, &str)] = &[];
313301 let mut failures = Vec::new();
314302 for &(name, feature) in expected {
crates/ec-h265-syntax/Cargo.tomlmodified+3 -0
@@ -8,3 +8,6 @@ authors.workspace = true
88
99 [dependencies]
1010 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 @@
11 //! The SEI reader over the JCT-VC conformance streams.
22 //!
33 //! 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.
74
85 use std::path::{Path, PathBuf};
96
107 use ec_h265_syntax::nal::split_annex_b;
118 use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp};
129
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.
1510 fn streams() -> Vec<PathBuf> {
16- let root = match std::env::var("EC_H265_JCTVC_DIR") {
17- Ok(dir) => PathBuf::from(dir),
18- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
19- };
11+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
2012 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
2113 let Ok(entries) = std::fs::read_dir(dir) else {
2214 return;
@@ -39,14 +31,7 @@ fn streams() -> Vec<PathBuf> {
3931 #[test]
4032 fn every_sei_in_the_conformance_streams_parses() {
4133 let streams = streams();
42- if streams.is_empty() {
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- }
34+ assert!(!streams.is_empty(), "no streams under vectors/hevc-jctvc");
5035 let mut with_hash = 0usize;
5136 let mut hash_streams = Vec::new();
5237 let mut sei_nals = 0usize;
crates/ec-h265/Cargo.tomlmodified+1 -0
@@ -15,4 +15,5 @@ archmage = "=0.9.31-beta.1"
1515 multiversion = "0.9"
1616
1717 [dev-dependencies]
18+ec-testkit.workspace = true
1819 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};
88 use ec_core::frame::VideoFrame;
99 use ec_h265::encoder::{EncodedPicture, Encoder, EncoderConfig, RateControl, TransformSkip};
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 fn scratch_dir() -> PathBuf {
1413 let dir = std::env::temp_dir().join("ec-h265-tests");
@@ -16,18 +15,10 @@ fn scratch_dir() -> PathBuf {
1615 dir
1716 }
1817
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-
2718 /// Decode an Annex-B file with ffmpeg into planar 8-bit 4:2:0.
2819 fn ffmpeg_decode(path: &Path) -> Result<Vec<u8>, String> {
2920 let out = path.with_extension("yuv");
30- let status = Command::new("ffmpeg")
21+ let status = ec_testkit::ffmpeg()
3122 .args(["-v", "error", "-y", "-i"])
3223 .arg(path)
3324 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -147,10 +138,6 @@ fn encode_natural(
147138 /// the search actually fired — and still decode bit-exactly.
148139 #[test]
149140 fn chroma_mode_search_decodes_bit_exactly() {
150- if !have_ffmpeg() {
151- eprintln!("skipping: ffmpeg not installed");
152- return;
153- }
154141 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
155142 let (source, coded) = encode_with(w, h, 27, None, true, false);
156143 let (_, derived) = encode_with(w, h, 27, None, false, false);
@@ -224,10 +211,6 @@ fn chroma_mode_search_decodes_bit_exactly() {
224211 /// partition are all where the decoder looks for them.
225212 #[test]
226213 fn intra_nxn_decodes_bit_exactly() {
227- if !have_ffmpeg() {
228- eprintln!("skipping: ffmpeg not installed");
229- return;
230- }
231214 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
232215 let (source, coded) = encode_natural(w, h, 22, true);
233216 let (_, square) = encode_natural(w, h, 22, false);
@@ -305,10 +288,6 @@ fn intra_nxn_decodes_bit_exactly() {
305288 /// `EC_H265_SDH` arm of the clip gate measures.
306289 #[test]
307290 fn sign_hiding_decodes_bit_exactly() {
308- if !have_ffmpeg() {
309- eprintln!("skipping: ffmpeg not installed");
310- return;
311- }
312291 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
313292 let (source, coded) = encode_sdh(w, h, 22, true);
314293 let (_, plain) = encode_sdh(w, h, 22, false);
@@ -414,10 +393,6 @@ fn encode_tskip(
414393 /// sample for sample.
415394 #[test]
416395 fn transform_skip_decodes_bit_exactly() {
417- if !have_ffmpeg() {
418- eprintln!("skipping: ffmpeg not installed");
419- return;
420- }
421396 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
422397 let (source, coded) = encode_tskip(w, h, 22, TransformSkip::AlwaysFor4x4);
423398 let (_, plain) = encode_tskip(w, h, 22, TransformSkip::Off);
@@ -484,10 +459,6 @@ fn transform_skip_decodes_bit_exactly() {
484459 }
485460 #[test]
486461 fn ffmpeg_decodes_bit_exactly_at_every_shape() {
487- if !have_ffmpeg() {
488- eprintln!("skipping: ffmpeg not installed");
489- return;
490- }
491462 // 1920x1080 needs the conformance window on the bottom (1088 coded rows are
492463 // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916
493464 // 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() {
577548 /// pass without a single 64x64 coding unit ever being kept.
578549 #[test]
579550 fn cu64_decodes_bit_exactly() {
580- if !have_ffmpeg() {
581- eprintln!("skipping: ffmpeg not installed");
582- return;
583- }
584551 // 130x66 is here for the partial coding tree blocks, not for the decision:
585552 // at that size only two tree blocks are whole and the search keeps neither,
586553 // so its stream is allowed to come out identical.
@@ -684,13 +651,9 @@ fn ffmpeg_verifies_the_decoded_picture_hash() {
684651 // decoder checks that claim against what it decoded when asked to. This is
685652 // the one oracle that does not depend on this crate being right about
686653 // anything except the hash itself.
687- if !have_ffmpeg() {
688- eprintln!("skipping: ffmpeg not installed");
689- return;
690- }
691654 let (_, coded) = encode(352, 288, 30, None);
692655 let path = write_au("hash-352x288", &coded);
693- let output = Command::new("ffmpeg")
656+ let output = ec_testkit::ffmpeg()
694657 .args(["-v", "debug", "-err_detect", "crccheck", "-y", "-i"])
695658 .arg(&path)
696659 .args(["-f", "null", "-"])
@@ -712,13 +675,13 @@ fn vaapi_hardware_decodes_the_stream() {
712675 // The other half of "it decodes": a GPU decoder is a different
713676 // implementation with different tolerances, and it is what edith's HEVC
714677 // path actually uses. Skipped where there is no render node.
715- if !have_ffmpeg() || !Path::new("/dev/dri/renderD128").exists() {
716- eprintln!("skipping: no ffmpeg or no VA-API render node");
678+ if !Path::new("/dev/dri/renderD128").exists() {
679+ eprintln!("skipping: no VA-API render node");
717680 return;
718681 }
719682 let (_, coded) = encode(1920, 1080, 27, None);
720683 let path = write_au("vaapi-1080p", &coded);
721- let output = Command::new("ffmpeg")
684+ let output = ec_testkit::ffmpeg()
722685 .args([
723686 "-v",
724687 "error",
@@ -838,10 +801,6 @@ fn the_batch_helper_codes_every_picture_as_its_own_access_unit() {
838801 /// has to read them back to the same samples the encoder reconstructed.
839802 #[test]
840803 fn rdoq_decodes_bit_exactly() {
841- if !have_ffmpeg() {
842- eprintln!("skipping: ffmpeg not installed");
843- return;
844- }
845804 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
846805 let (source, coded) = encode_rdoq(w, h, 27, true);
847806 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
925884 /// samples the encoder reconstructed.
926885 #[test]
927886 fn rqt_decodes_bit_exactly() {
928- if !have_ffmpeg() {
929- eprintln!("skipping: ffmpeg not installed");
930- return;
931- }
932887 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
933888 let (source, coded) = encode_rqt(w, h, 27, true);
934889 let (_, plain) = encode_rqt(w, h, 27, false);
crates/ec-h265/tests/it/conformance_intra.rsmodified+10 -37
@@ -24,12 +24,8 @@ struct Row {
2424 decode_secs: f64,
2525 }
2626
27-/// The conformance directory: `EC_H265_JCTVC_DIR`, or the fixtures link.
2827 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_JCTVC_DIR") {
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
32- }
28+ ec_testkit::fixture("vectors/hevc-jctvc")
3329 }
3430
3531 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -51,9 +47,7 @@ fn streams() -> Vec<PathBuf> {
5147 }
5248 }
5349 }
54- let Ok(dirs) = std::fs::read_dir(&root) else {
55- return Vec::new();
56- };
50+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
5751 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
5852 dirs.sort();
5953 dirs.into_iter()
@@ -67,7 +61,7 @@ fn streams() -> Vec<PathBuf> {
6761 }
6862
6963 /// 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 {
7165 let mut row = Row {
7266 name: name.to_string(),
7367 accepted: "no",
@@ -84,7 +78,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
8478 return row;
8579 }
8680 };
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();
8882 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
8983 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
9084 // 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 {
120114 // No hash SEI: the frame is checked against the reference YUV, when there is one.
121115 if let Some(reference) = reference.as_deref() {
122116 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- }
134117 let start = index * want.len();
135118 row.checked += 1;
136119 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 {
197180 fn conformance_pictures_match_the_sei_hash() {
198181 let root = jctvc_root();
199182 let streams = streams();
200- if streams.is_empty() {
201- eprintln!(
202- "conformance check skipped: no streams under {}",
203- root.display()
204- );
205- assert!(
206- !root.is_dir(),
207- "fixture directory {} exists but holds no bitstreams",
208- root.display()
209- );
210- return;
211- }
212- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
183+ assert!(
184+ !streams.is_empty(),
185+ "no conformance streams under {}",
186+ root.display()
187+ );
213188
214189 let mut rows = Vec::new();
215190 for path in &streams {
@@ -217,9 +192,7 @@ fn conformance_pictures_match_the_sei_hash() {
217192 .file_stem()
218193 .map(|s| s.to_string_lossy().into_owned())
219194 .unwrap_or_default();
220- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {
221- check_stream(path, &name, ref_dir.as_deref())
222- }));
195+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
223196 let mut row = match outcome {
224197 Ok(row) => row,
225198 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext.rsmodified+10 -38
@@ -1,5 +1,4 @@
11 //! 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
32 //! (D.3.19), or against the whole-output MD5 of the package when the stream has no hash.
43 //!
54 //! A stream the decoder refuses must be refused by name: the error text has to be one of
@@ -24,12 +23,8 @@ struct Row {
2423 decode_secs: f64,
2524 }
2625
27-/// The conformance directory: `EC_H265_REXT_DIR`, or the fixtures link.
2826 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_REXT_DIR") {
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
32- }
27+ ec_testkit::fixture("vectors/hevc-rext")
3328 }
3429
3530 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -51,9 +46,7 @@ fn streams() -> Vec<PathBuf> {
5146 }
5247 }
5348 }
54- let Ok(dirs) = std::fs::read_dir(&root) else {
55- return Vec::new();
56- };
49+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
5750 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
5851 dirs.sort();
5952 dirs.into_iter()
@@ -106,7 +99,7 @@ fn nal_chunks(data: &[u8]) -> Vec<&[u8]> {
10699 }
107100
108101 /// 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 {
110103 let mut row = Row {
111104 name: name.to_string(),
112105 accepted: "no",
@@ -123,7 +116,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
123116 return row;
124117 }
125118 };
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();
127120 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
128121 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
129122 // 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 {
149142 // No hash SEI: the frame is checked against the reference YUV, when there is one.
150143 if let Some(reference) = reference.as_deref() {
151144 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- }
163145 let start = index * want.len();
164146 row.checked += 1;
165147 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 {
244226 fn rext_conformance_pictures_match_the_sei_hash() {
245227 let root = jctvc_root();
246228 let streams = streams();
247- if streams.is_empty() {
248- eprintln!(
249- "conformance check skipped: no streams under {}",
250- root.display()
251- );
252- assert!(
253- std::env::var_os("EC_REQUIRE_FIXTURES").is_none() && !root.is_dir(),
254- "fixture directory {} holds no bitstreams",
255- root.display()
256- );
257- return;
258- }
259- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
229+ assert!(
230+ !streams.is_empty(),
231+ "no conformance streams under {}",
232+ root.display()
233+ );
260234
261235 let mut rows = Vec::new();
262236 for path in &streams {
@@ -265,9 +239,7 @@ fn rext_conformance_pictures_match_the_sei_hash() {
265239 .map(|s| s.to_string_lossy().into_owned())
266240 .unwrap_or_default();
267241 eprintln!("stream {name}");
268- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {
269- check_stream(path, &name, ref_dir.as_deref())
270- }));
242+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
271243 let mut row = match outcome {
272244 Ok(row) => row,
273245 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext422.rsmodified+7 -20
@@ -2,12 +2,8 @@
22 //!
33 //! The committed 64x64 stream is decoded by ffmpeg at run time and compared sample for
44 //! 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.
85
96 use std::path::{Path, PathBuf};
10-use std::process::Command;
117
128 use ec_h265::Decoder;
139
@@ -59,16 +55,12 @@ fn first_diff(a: &[u8], b: &[u8]) -> Option<usize> {
5955
6056 #[test]
6157 fn committed_422_stream_matches_ffmpeg() {
62- if Command::new("ffmpeg").arg("-version").output().is_err() {
63- eprintln!("skip: no ffmpeg");
64- return;
65- }
6658 let dir = std::env::temp_dir().join("ec-h265-rext422");
6759 std::fs::create_dir_all(&dir).unwrap();
6860 let src = dir.join("yuv422_10.265");
6961 let reference = dir.join("yuv422_10.yuv");
7062 std::fs::write(&src, YUV422_10).unwrap();
71- let st = Command::new("ffmpeg")
63+ let st = ec_testkit::ffmpeg()
7264 .args(["-v", "error", "-y", "-i"])
7365 .arg(&src)
7466 .args(["-f", "rawvideo", "-pix_fmt", "yuv422p10le"])
@@ -86,10 +78,7 @@ fn committed_422_stream_matches_ffmpeg() {
8678 }
8779
8880 fn rext_root() -> PathBuf {
89- match std::env::var("EC_H265_REXT_DIR") {
90- Ok(d) => PathBuf::from(d),
91- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
92- }
81+ ec_testkit::fixture("vectors/hevc-rext")
9382 }
9483
9584 fn find_stream(dir: &Path) -> Option<PathBuf> {
@@ -116,9 +105,8 @@ fn rext_422_vectors_are_byte_exact() {
116105 ("Main_422_10_A_RExt_Sony_2", 1920, 1080),
117106 ("Main_422_10_B_RExt_Sony_2", 2560, 1600),
118107 ] {
119- if let Some(s) = find_stream(&root.join(name)) {
120- cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));
121- }
108+ let s = find_stream(&root.join(name)).unwrap_or_else(|| panic!("{name}: no stream"));
109+ cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));
122110 }
123111 for name in [
124112 "i422_8",
@@ -137,10 +125,9 @@ fn rext_422_vectors_are_byte_exact() {
137125 }
138126 let mut checked = 0;
139127 for (stream, reference, w, h) in cases {
140- let (Ok(data), Ok(want)) = (std::fs::read(&stream), std::fs::read(&reference)) else {
141- eprintln!("skip (fixture missing): {}", stream.display());
142- continue;
143- };
128+ let data = std::fs::read(&stream).unwrap_or_else(|e| panic!("{}: {e}", stream.display()));
129+ let want =
130+ std::fs::read(&reference).unwrap_or_else(|e| panic!("{}: {e}", reference.display()));
144131 let got = raw(&decode(&data), w, h);
145132 assert_eq!(
146133 first_diff(&got, &want),
crates/ec-h265/tests/it/cu_syntax.rsmodified+3 -12
@@ -7,12 +7,8 @@ use ec_h265::dec::Decoder;
77 use std::path::{Path, PathBuf};
88
99 /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory
10-/// under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted.
1110 fn streams() -> Vec<PathBuf> {
12- let root = match std::env::var("EC_H265_JCTVC_DIR") {
13- Ok(dir) => PathBuf::from(dir),
14- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
15- };
11+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
1612 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
1713 let Ok(entries) = std::fs::read_dir(dir) else {
1814 return;
@@ -27,9 +23,7 @@ fn streams() -> Vec<PathBuf> {
2723 }
2824 }
2925 }
30- let Ok(dirs) = std::fs::read_dir(&root) else {
31- return Vec::new();
32- };
26+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
3327 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
3428 dirs.sort();
3529 dirs.into_iter()
@@ -84,10 +78,7 @@ fn inter_placeholder_runs_over_pb_slices() {
8478 use ec_h265_syntax::nal::{NalUnitType, unescape_rbsp};
8579 use ec_h265_syntax::slice::{SliceHeader, SliceType};
8680 let streams = streams();
87- if streams.is_empty() {
88- eprintln!("inter placeholder: no conformance streams found, skipping");
89- return;
90- }
81+ assert!(!streams.is_empty(), "no conformance streams");
9182 let (mut pb_slices, mut decoded, mut refused) = (0usize, 0usize, 0usize);
9283 for path in &streams {
9384 let data = std::fs::read(path).expect("read bitstream");
crates/ec-h265/tests/it/dec_meta.rsmodified+7 -27
@@ -3,7 +3,6 @@
33 //! NAL units (62, 63) and malformed SEI change nothing.
44 //!
55 //! 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.
76
87 use std::path::{Path, PathBuf};
98
@@ -12,10 +11,7 @@ use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
1211 use ec_h265_syntax::sei::{ContentLightLevel, MasteringDisplay, PictureHash};
1312
1413 fn stream_files() -> Vec<PathBuf> {
15- let root = match std::env::var("EC_H265_JCTVC_DIR") {
16- Ok(dir) => PathBuf::from(dir),
17- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
18- };
14+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
1915 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
2016 let Ok(entries) = std::fs::read_dir(dir) else {
2117 return;
@@ -81,16 +77,8 @@ fn clean_stream() -> Option<(String, Vec<Vec<u8>>)> {
8177 None
8278 }
8379
84-fn require_stream() -> Option<(String, Vec<Vec<u8>>)> {
85- let found = clean_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
80+fn require_stream() -> (String, Vec<Vec<u8>>) {
81+ clean_stream().expect("no clean conformance stream")
9482 }
9583
9684 /// What a frame looks like to a caller, for comparing two decodes.
@@ -140,9 +128,7 @@ fn hdr10_prefix_rbsp() -> Vec<u8> {
140128
141129 #[test]
142130 fn dolby_vision_nal_units_change_nothing() {
143- let Some((name, nals)) = require_stream() else {
144- return;
145- };
131+ let (name, nals) = require_stream();
146132 let base = decode(&nals).unwrap();
147133 let mut injected = Vec::new();
148134 for nal in &nals {
@@ -164,9 +150,7 @@ fn dolby_vision_nal_units_change_nothing() {
164150
165151 #[test]
166152 fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
167- let Some((name, nals)) = require_stream() else {
168- return;
169- };
153+ let (name, nals) = require_stream();
170154 let base = decode(&nals).unwrap();
171155 let mut injected = Vec::new();
172156 for nal in &nals {
@@ -193,9 +177,7 @@ fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
193177
194178 #[test]
195179 fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
196- let Some((name, nals)) = require_stream() else {
197- return;
198- };
180+ let (name, nals) = require_stream();
199181 let mut injected = Vec::new();
200182 let mut placed = false;
201183 for nal in &nals {
@@ -225,9 +207,7 @@ fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
225207
226208 #[test]
227209 fn picture_hash_attaches_to_the_picture_it_follows() {
228- let Some((name, nals)) = require_stream() else {
229- return;
230- };
210+ let (name, nals) = require_stream();
231211 // One MD5 plane: payloadType 132, payloadSize 17, hash_type 0, the digest.
232212 let digest = [0x5au8; 16];
233213 let mut hash_rbsp = vec![132, 17, 0];
crates/ec-h265/tests/it/dec_shell.rsmodified+5 -27
@@ -4,11 +4,9 @@
44 //! The sweep parses every slice of every stream through the picture-management
55 //! path (pixel decode off) and checks the output order against ffprobe. Streams
66 //! 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.
87
98 use std::collections::VecDeque;
109 use std::path::{Path, PathBuf};
11-use std::process::Command;
1210
1311 use ec_h265::dec::dpb::{Dpb, DpbLimits, Marking, PendingFrame};
1412 use ec_h265::dec::poc::derive_poc;
@@ -274,16 +272,8 @@ fn decoder_refuses_out_of_scope_parameter_sets_and_skips_layers() {
274272 assert!(dec.next_frame().is_none());
275273 }
276274
277-fn have_tool(tool: &str) -> bool {
278- Command::new(tool)
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)
275+fn run(args: &[&str], file: &Path) -> Result<Vec<u8>, String> {
276+ let out = ec_testkit::ffprobe()
287277 .args(["-v", "error"])
288278 .args(args)
289279 .arg(file)
@@ -303,14 +293,9 @@ fn numbers(text: &[u8]) -> Vec<u64> {
303293 }
304294
305295 /// 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
307296 /// by name. Some zips extract one directory deeper, so two levels are searched.
308297 fn streams() -> Vec<PathBuf> {
309- // EC_H265_JCTVC_DIR overrides the default, for hosts whose fixtures link is dangling.
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- };
298+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
314299 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
315300 let Ok(entries) = std::fs::read_dir(dir) else {
316301 return;
@@ -325,9 +310,7 @@ fn streams() -> Vec<PathBuf> {
325310 }
326311 }
327312 }
328- let Ok(dirs) = std::fs::read_dir(&root) else {
329- return Vec::new();
330- };
313+ let dirs = std::fs::read_dir(&root).expect("fixture directory");
331314 let mut dirs: Vec<PathBuf> = dirs.filter_map(|e| e.ok().map(|e| e.path())).collect();
332315 dirs.sort();
333316 dirs.into_iter()
@@ -357,7 +340,6 @@ fn our_order(data: &[u8]) -> Result<Vec<(i32, u32)>, String> {
357340 /// decode order) of each frame, in display order.
358341 fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
359342 let packets = numbers(&run(
360- "ffprobe",
361343 &[
362344 "-select_streams",
363345 "v:0",
@@ -369,7 +351,6 @@ fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
369351 path,
370352 )?);
371353 let frames = numbers(&run(
372- "ffprobe",
373354 &[
374355 "-select_streams",
375356 "v:0",
@@ -407,10 +388,7 @@ fn spec_expectation(name: &str) -> Option<(usize, &'static str)> {
407388 #[test]
408389 fn conformance_output_order_matches_ffprobe() {
409390 let streams = streams();
410- if streams.is_empty() || !have_tool("ffprobe") {
411- eprintln!("conformance sweep skipped: vectors or ffprobe absent");
412- return;
413- }
391+ assert!(!streams.is_empty(), "no conformance streams");
414392 let mut table = String::from("stream\tpictures_out\tffprobe_out\tresult\tdetail\n");
415393 let mut pass = 0usize;
416394 let mut spec_ok = 0usize;
crates/ec-h265/tests/it/dolby_vision_p8.rsmodified+2 -20
@@ -6,32 +6,22 @@
66 //! inserted in front of every VCL NAL unit. ec-h265 must decode the injected stream
77 //! to exactly the pictures it decodes from the clean one, and ffmpeg must decode the
88 //! injected stream to the same bytes.
9-//!
10-//! The test skips when ffmpeg is absent, unless `EC_REQUIRE_FIXTURES` is set.
119
1210 use ec_h265::Decoder;
1311 use ec_h265::dec::Frame;
1412 use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
1513 use std::path::Path;
16-use std::process::Command;
1714
1815 const WIDTH: usize = 352;
1916 const HEIGHT: usize = 288;
2017 const FRAMES: usize = 12;
2118
22-fn have_ffmpeg() -> bool {
23- Command::new("ffmpeg")
24- .arg("-version")
25- .output()
26- .is_ok_and(|o| o.status.success())
27-}
28-
2919 /// The base layer: libx265, an IDR every 4 pictures, P pictures in between, no B.
3020 fn encode_base_layer(dir: &Path) -> Result<Vec<u8>, String> {
3121 let out = dir.join("base.hevc");
3222 let frames = FRAMES.to_string();
3323 let source = format!("testsrc2=size={WIDTH}x{HEIGHT}:rate=30");
34- let status = Command::new("ffmpeg")
24+ let status = ec_testkit::ffmpeg()
3525 .args(["-v", "error", "-y", "-f", "lavfi", "-i"])
3626 .arg(&source)
3727 .arg("-frames:v")
@@ -137,7 +127,7 @@ fn decode_ec(annex_b: &[u8]) -> Result<(Vec<u8>, usize), String> {
137127
138128 /// Every picture ffmpeg outputs, as yuv420p.
139129 fn decode_ffmpeg(path: &Path, out: &Path) -> Result<Vec<u8>, String> {
140- let status = Command::new("ffmpeg")
130+ let status = ec_testkit::ffmpeg()
141131 .args(["-v", "error", "-y", "-i"])
142132 .arg(path)
143133 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -159,14 +149,6 @@ fn first_difference(a: &[u8], b: &[u8]) -> Option<usize> {
159149
160150 #[test]
161151 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- }
170152 let dir = std::env::temp_dir().join(format!("ec-h265-dvp8-{}", std::process::id()));
171153 std::fs::create_dir_all(&dir).expect("temp dir");
172154
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,
266266 (bd, cand_extrap, anc_extrap)
267267 }
268268
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-
278269 fn have_x265() -> bool {
279- std::process::Command::new("ffmpeg")
270+ ec_testkit::ffmpeg()
280271 .args(["-v", "error", "-hide_banner", "-encoders"])
281272 .output()
282273 .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>> {
367358 std::fs::create_dir_all(&dir).ok()?;
368359 let path = dir.join(format!("s{}.265", stream.len()));
369360 pin_or_bail("ffmpeg_decode", &path, stream)?;
370- let out = std::process::Command::new("ffmpeg")
361+ let out = ec_testkit::ffmpeg()
371362 .args(["-v", "error"])
372363 .arg("-i")
373364 .arg(&path)
@@ -445,7 +436,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option<Vec
445436 _ => String::new(),
446437 }
447438 );
448- let status = std::process::Command::new("ffmpeg")
439+ let status = ec_testkit::ffmpeg()
449440 .args(["-v", "error", "-y"])
450441 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
451442 .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
486477 /// bd_psnr_vs_x265 -- --nocapture
487478 #[test]
488479 fn bd_psnr_vs_x265() {
489- if !have_ffmpeg() || !have_x265() {
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- }
480+ assert!(have_x265(), "the pinned ffmpeg has no libx265");
497481 let (w, h, sources) = match std::env::var_os("EC_H265_CLIP") {
498482 Some(path) => clip_sources(&path, 24),
499483 None => {
@@ -844,7 +828,7 @@ fn bd_psnr_vs_x265() {
844828 /// `EC_H265_CLIP_SKIP` passes over that many pictures before sampling (film
845829 /// heads are titles and fades).
846830 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()
848832 .args([
849833 "-v",
850834 "error",
@@ -887,7 +871,7 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
887871 // killer. `select` drops the skipped pictures inside ffmpeg and
888872 // `-frames:v` stops the decode once `want` have come out, so what reaches
889873 // this process is exactly `want` frames.
890- let raw = std::process::Command::new("ffmpeg")
874+ let raw = ec_testkit::ffmpeg()
891875 .args(["-v", "error", "-i"])
892876 .arg(path)
893877 .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-//!
61 //! Every file either decodes bit-exactly, is refused by name (a pixel format or
72 //! a bit depth outside 4:2:0 8/10-bit, or a decoder refusal that says
83 //! "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
134
145 use std::io::Read;
156 use std::path::{Path, PathBuf};
16-use std::process::{Command, Stdio};
7+use std::process::Stdio;
178
189 use ec_h265::dec::Decoder;
1910 use ec_h265::decode::DecodedPicture;
@@ -25,15 +16,6 @@ const FRAMES: usize = 300;
2516 /// Pixel formats inside the decoder's scope: 4:2:0 at 8 or 10 bits.
2617 const IN_SCOPE_PIX_FMTS: [&str; 2] = ["yuv420p", "yuv420p10le"];
2718
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-
3719 fn scratch(tag: &str) -> PathBuf {
3820 let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from);
3921 let dir = base.join(format!("ec-h265-{tag}-{}", std::process::id()));
@@ -50,31 +32,25 @@ struct Entry {
5032 pix_fmt: String,
5133 }
5234
53-fn manifest_hevc_entries() -> Vec<Entry> {
54- let manifest =
55- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
56- let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| {
57- panic!(
58- "{}: {e}. This test sweeps the personal library; generate the manifest with \
59- scripts/scan-real-library.sh on the machine that holds the media.",
60- manifest.display()
61- )
62- });
63- let mut out = Vec::new();
64- for line in text.lines().skip(1) {
65- let f: Vec<&str> = line.split('\t').collect();
66- if f.len() < 6 || f[2] != "hevc" || !Path::new(f[0]).is_file() {
67- continue;
68- }
69- out.push(Entry {
70- path: PathBuf::from(f[0]),
71- container: f[1].to_string(),
72- width: f[3].to_string(),
73- height: f[4].to_string(),
74- pix_fmt: f[5].to_string(),
75- });
76- }
77- out
35+fn hevc_entries() -> Vec<Entry> {
36+ [
37+ (
38+ "derived/sintel720-x265-main10.mp4",
39+ "yuv420p10le",
40+ "1280",
41+ "720",
42+ ),
43+ ("open/sintel_trailer-1080p.mp4", "yuv420p", "1920", "1080"),
44+ ]
45+ .into_iter()
46+ .map(|(rel, pix_fmt, width, height)| Entry {
47+ path: ec_testkit::fixture(rel),
48+ container: "mp4".to_string(),
49+ width: width.to_string(),
50+ height: height.to_string(),
51+ pix_fmt: pix_fmt.to_string(),
52+ })
53+ .collect()
7854 }
7955
8056 /// 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 {
232208 /// with the text the table prints.
233209 fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, String> {
234210 let bps = if bit_depth > 8 { 2 } else { 1 };
235- let mut child = Command::new("ffmpeg")
211+ let mut child = ec_testkit::ffmpeg()
236212 .args(["-v", "error", "-c:v", "hevc", "-i"])
237213 .arg(es)
238214 .args([
@@ -286,7 +262,7 @@ fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, Strin
286262
287263 /// Extracts the first `FRAMES` pictures of the video as Annex B.
288264 fn extract(src: &Path, dst: &Path) -> bool {
289- Command::new("ffmpeg")
265+ ec_testkit::ffmpeg()
290266 .args(["-v", "error", "-y", "-i"])
291267 .arg(src)
292268 .args([
@@ -307,11 +283,9 @@ fn extract(src: &Path, dst: &Path) -> bool {
307283 }
308284
309285 #[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."]
311287 fn real_library_hevc_streams_match_ffmpeg() {
312- assert!(have_ffmpeg(), "ffmpeg is required to sweep the library");
313- let entries = manifest_hevc_entries();
314- assert!(!entries.is_empty(), "the manifest lists no hevc rows");
288+ let entries = hevc_entries();
315289 let dir = scratch("real-library-hevc");
316290 let mut table = String::new();
317291 let mut decoded = 0usize;
crates/ec-h265/tests/it/scaling_lists.rsmodified+3 -21
@@ -8,7 +8,6 @@
88 use ec_h265::Decoder;
99 use ec_h265::dec::Frame;
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 /// The four scaling-list streams the picture-management sweep covers; `str` is
1413 /// the SLIST_D stream.
@@ -20,10 +19,7 @@ const STREAMS: [&str; 4] = [
2019 ];
2120
2221 fn vectors_dir() -> PathBuf {
23- match std::env::var("EC_H265_JCTVC_DIR") {
24- Ok(dir) => PathBuf::from(dir),
25- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
26- }
22+ ec_testkit::fixture("vectors/hevc-jctvc")
2723 }
2824
2925 /// 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> {
5955 /// The first frame of `path` as ffmpeg decodes it, in yuv420p.
6056 fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {
6157 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()
6359 .args(["-v", "error", "-y", "-i"])
6460 .arg(path)
6561 .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> {
7268 std::fs::read(&out).map_err(|e| e.to_string())
7369 }
7470
75-fn have_ffmpeg() -> bool {
76- Command::new("ffmpeg")
77- .arg("-version")
78- .output()
79- .is_ok_and(|o| o.status.success())
80-}
81-
8271 // Ignored until the intra path decodes the syntax these streams use: the decode
8372 // desyncs at the last CTB of the IDR, and the intra CTU loop has no SAO or
8473 // cu_qp_delta parsing. Run with `--ignored` to see the failure.
8574 #[ignore = "intra path lacks the syntax these streams use (desync at the IDR's last CTB)"]
8675 #[test]
8776 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- }
9277 let dir = vectors_dir();
9378 let mut checked = 0usize;
9479 for rel in STREAMS {
9580 let path = dir.join(rel);
96- let Ok(data) = std::fs::read(&path) else {
97- eprintln!("scaling-list check: {rel} absent, skipped");
98- continue;
99- };
81+ let data = std::fs::read(&path).unwrap_or_else(|e| panic!("{rel}: {e}"));
10082 let mut decoder = Decoder::new();
10183 decoder
10284 .decode_annex_b(&data)