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