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