Merge branch 'simplify/w0-m3' into simplify/w0
Browse files at this commit40 changed files +96 -66153
- Cargo.lock +2 -0
- crates/ec-av1-syntax/Cargo.toml +3 -0
- crates/ec-av1-syntax/tests/streams.rs +8 -43
- crates/ec-av1/Cargo.toml +1 -0
- crates/ec-av1/src/decode/coeffs.rs +0 -9
- crates/ec-av1/src/decode/rect.rs +0 -10
- crates/ec-av1/src/decode/tests.rs +5 -54
- crates/ec-av1/src/encode/more_tests.rs +6 -2675
- crates/ec-av1/src/encode/tests.rs +15 -254
- crates/ec-av1/src/encoder/tests.rs +32 -225
- crates/ec-av1/src/gate_coverage.rs +0 -2775
- crates/ec-av1/src/lib.rs +0 -8
- crates/ec-av1/src/library_fixture.rs +0 -161
- crates/ec-av1/src/probe.rs +3 -7
- crates/ec-av1/src/refusal_inventory.rs +0 -2957
- crates/ec-av1/src/stack_budget.rs +0 -3
- crates/ec-av1/src/stream/mod.rs +0 -9
- crates/ec-av1/src/stream/tests/gates_a.rs +0 -2841
- crates/ec-av1/src/stream/tests/gates_b.rs +0 -2804
- crates/ec-av1/src/stream/tests/mod.rs +1 -17
- crates/ec-av1/src/stream/tests/support.rs +0 -4172
- crates/ec-av1/src/stream/tests/t01.rs +0 -4538
- crates/ec-av1/src/stream/tests/t02.rs +0 -4341
- crates/ec-av1/src/stream/tests/t03.rs +0 -4567
- crates/ec-av1/src/stream/tests/t04.rs +0 -4516
- crates/ec-av1/src/stream/tests/t05.rs +0 -4488
- crates/ec-av1/src/stream/tests/t06.rs +0 -4444
- crates/ec-av1/src/stream/tests/t07.rs +0 -4479
- crates/ec-av1/src/stream/tests/t08.rs +0 -4540
- crates/ec-av1/src/stream/tests/t09.rs +0 -4486
- crates/ec-av1/src/stream/tests/t10.rs +0 -4293
- crates/ec-av1/src/tile/tests.rs +2 -114
- crates/ec-av1/src/tool_cache.rs +0 -326
- crates/ec-av1/tests/aom_conformance.rs +2 -54
- crates/ec-av1/tests/real_library.rs +13 -65
- crates/ec-av1/tests/yuv422_dav1d.rs +3 -21
- scripts/build-aom-affine-oracle.sh +0 -48
- scripts/build-aom-oracle.sh +0 -56
- scripts/check-aom-oracle-rungs.sh +0 -225
- scripts/instrument-aom-oracle.sh +0 -1528
Cargo.lockmodified+2 -0
| @@ -378,6 +378,7 @@ dependencies = [ | |||
| 378 | "bytemuck", | 378 | "bytemuck", |
| 379 | "ec-av1-syntax", | 379 | "ec-av1-syntax", |
| 380 | "ec-core", | 380 | "ec-core", |
| 381 | + "ec-testkit", | ||
| 381 | "stats_alloc", | 382 | "stats_alloc", |
| 382 | "tracking-allocator", | 383 | "tracking-allocator", |
| 383 | ] | 384 | ] |
| @@ -387,6 +388,7 @@ name = "ec-av1-syntax" | |||
| 387 | version = "0.1.0" | 388 | version = "0.1.0" |
| 388 | dependencies = [ | 389 | dependencies = [ |
| 389 | "ec-core", | 390 | "ec-core", |
| 391 | + "ec-testkit", | ||
| 390 | ] | 392 | ] |
| 391 | 393 | ||
| 392 | [[package]] | 394 | [[package]] |
crates/ec-av1-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-av1-syntax/tests/streams.rsmodified+8 -43
| @@ -1,19 +1,8 @@ | |||
| 1 | -//! Every AV1 fixture stream parsed end to end, field-compared against ffprobe. | ||
| 2 | -//! | ||
| 3 | -//! `scripts/gen-bitstream-fixtures.sh` remuxes the container fixtures to IVF and | ||
| 4 | -//! encodes the branch cases (4:4:4, monochrome, tiles, hidden ALTREF). Fixtures | ||
| 5 | -//! are gitignored, so a checkout without them skips rather than fails. | ||
| 6 | - | ||
| 7 | use std::path::{Path, PathBuf}; | 1 | use std::path::{Path, PathBuf}; |
| 8 | -use std::process::Command; | ||
| 9 | 2 | ||
| 10 | use ec_av1_syntax::{Av1Parser, FrameType, ObuKind}; | 3 | use ec_av1_syntax::{Av1Parser, FrameType, ObuKind}; |
| 11 | use ec_core::Error; | 4 | use ec_core::Error; |
| 12 | 5 | ||
| 13 | -fn bitstreams() -> PathBuf { | ||
| 14 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/bitstreams") | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | /// The IVF frames of a file — for AV1, each is one temporal unit. | 6 | /// The IVF frames of a file — for AV1, each is one temporal unit. |
| 18 | fn ivf_frames(data: &[u8]) -> Vec<&[u8]> { | 7 | fn ivf_frames(data: &[u8]) -> Vec<&[u8]> { |
| 19 | let mut out = Vec::new(); | 8 | let mut out = Vec::new(); |
| @@ -31,7 +20,7 @@ fn ivf_frames(data: &[u8]) -> Vec<&[u8]> { | |||
| 31 | } | 20 | } |
| 32 | 21 | ||
| 33 | fn ffprobe(path: &Path, entries: &str) -> Vec<String> { | 22 | fn ffprobe(path: &Path, entries: &str) -> Vec<String> { |
| 34 | - let out = Command::new("ffprobe") | 23 | + let out = ec_testkit::ffprobe() |
| 35 | .args(["-v", "error", "-select_streams", "v:0", "-show_entries"]) | 24 | .args(["-v", "error", "-select_streams", "v:0", "-show_entries"]) |
| 36 | .arg(entries) | 25 | .arg(entries) |
| 37 | .args(["-of", "csv=p=0"]) | 26 | .args(["-of", "csv=p=0"]) |
| @@ -89,19 +78,13 @@ fn pix_fmt_geometry(pix_fmt: &str) -> (u8, bool, u8, u8) { | |||
| 89 | } | 78 | } |
| 90 | 79 | ||
| 91 | fn fixtures() -> Vec<PathBuf> { | 80 | fn fixtures() -> Vec<PathBuf> { |
| 92 | - let Ok(entries) = std::fs::read_dir(bitstreams()) else { | 81 | + ec_testkit::fixtures("bitstreams", "ivf") |
| 93 | - return Vec::new(); | 82 | + .into_iter() |
| 94 | - }; | ||
| 95 | - let mut files: Vec<PathBuf> = entries | ||
| 96 | - .filter_map(|e| e.ok().map(|e| e.path())) | ||
| 97 | .filter(|p| { | 83 | .filter(|p| { |
| 98 | - p.extension().is_some_and(|e| e == "ivf") | 84 | + p.file_name() |
| 99 | - && p.file_name() | 85 | + .is_some_and(|n| n.to_string_lossy().starts_with("av1-")) |
| 100 | - .is_some_and(|n| n.to_string_lossy().starts_with("av1-")) | ||
| 101 | }) | 86 | }) |
| 102 | - .collect(); | 87 | + .collect() |
| 103 | - files.sort(); | ||
| 104 | - files | ||
| 105 | } | 88 | } |
| 106 | 89 | ||
| 107 | /// One pass over a stream: what the parser saw. | 90 | /// One pass over a stream: what the parser saw. |
| @@ -117,14 +100,7 @@ struct Tally { | |||
| 117 | 100 | ||
| 118 | #[test] | 101 | #[test] |
| 119 | fn every_fixture_matches_ffprobe() { | 102 | fn every_fixture_matches_ffprobe() { |
| 120 | - let files = fixtures(); | 103 | + for path in fixtures() { |
| 121 | - if files.is_empty() { | ||
| 122 | - eprintln!( | ||
| 123 | - "skipped: no fixtures/bitstreams/av1-*.ivf — run scripts/gen-bitstream-fixtures.sh" | ||
| 124 | - ); | ||
| 125 | - return; | ||
| 126 | - } | ||
| 127 | - for path in files { | ||
| 128 | let name = path.file_name().unwrap().to_string_lossy().to_string(); | 104 | let name = path.file_name().unwrap().to_string_lossy().to_string(); |
| 129 | let (width, height, pix_fmt, profile) = probe_stream(&path); | 105 | let (width, height, pix_fmt, profile) = probe_stream(&path); |
| 130 | let (bit_depth, mono, sx, sy) = pix_fmt_geometry(&pix_fmt); | 106 | let (bit_depth, mono, sx, sy) = pix_fmt_geometry(&pix_fmt); |
| @@ -236,11 +212,7 @@ fn every_fixture_matches_ffprobe() { | |||
| 236 | /// cannot prove. | 212 | /// cannot prove. |
| 237 | #[test] | 213 | #[test] |
| 238 | fn altref_fixture_has_hidden_frames_and_show_existing() { | 214 | fn altref_fixture_has_hidden_frames_and_show_existing() { |
| 239 | - let path = bitstreams().join("av1-altref.ivf"); | 215 | + let path = ec_testkit::fixture("bitstreams/av1-altref.ivf"); |
| 240 | - if !path.exists() { | ||
| 241 | - eprintln!("skipped: no av1-altref.ivf"); | ||
| 242 | - return; | ||
| 243 | - } | ||
| 244 | let data = std::fs::read(&path).unwrap(); | 216 | let data = std::fs::read(&path).unwrap(); |
| 245 | let mut parser = Av1Parser::new(); | 217 | let mut parser = Av1Parser::new(); |
| 246 | let (mut hidden, mut show_existing, mut showable) = (0usize, 0usize, 0usize); | 218 | let (mut hidden, mut show_existing, mut showable) = (0usize, 0usize, 0usize); |
| @@ -287,13 +259,6 @@ fn fuzz_10k_mutations_never_panics() { | |||
| 287 | .collect::<Vec<_>>() | 259 | .collect::<Vec<_>>() |
| 288 | }) | 260 | }) |
| 289 | .collect(); | 261 | .collect(); |
| 290 | - let seeds = if seeds.is_empty() { | ||
| 291 | - vec![vec![ | ||
| 292 | - 0x0au8, 0x0b, 0x00, 0x00, 0x00, 0x24, 0xcf, 0x7f, 0x0d, 0xbf, 0xff, 0x30, 0x08, | ||
| 293 | - ]] | ||
| 294 | - } else { | ||
| 295 | - seeds | ||
| 296 | - }; | ||
| 297 | 262 | ||
| 298 | let mut state = 0x9e37_79b9_7f4a_7c15u64; | 263 | let mut state = 0x9e37_79b9_7f4a_7c15u64; |
| 299 | let mut rng = move || { | 264 | let mut rng = move || { |
crates/ec-av1/Cargo.tomlmodified+1 -0
| @@ -7,6 +7,7 @@ license.workspace = true | |||
| 7 | authors.workspace = true | 7 | authors.workspace = true |
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | +ec-testkit.workspace = true | ||
| 10 | ec-core.workspace = true | 11 | ec-core.workspace = true |
| 11 | ec-av1-syntax.workspace = true | 12 | ec-av1-syntax.workspace = true |
| 12 | archmage = "=0.9.31-beta.1" | 13 | archmage = "=0.9.31-beta.1" |
crates/ec-av1/src/decode/coeffs.rsmodified+0 -9
| @@ -4344,15 +4344,6 @@ fn a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered() { | |||
| 4344 | // lane-av1refusalspan: this gate is the PROOF for both var-tx refusals, so | 4344 | // lane-av1refusalspan: this gate is the PROOF for both var-tx refusals, so |
| 4345 | // it names both and pins both guard sites. The walk below proves the leaf | 4345 | // it names both and pins both guard sites. The walk below proves the leaf |
| 4346 | // domain; it never said which two strings that domain was about. | 4346 | // domain; it never said which two strings that domain was about. |
| 4347 | - for refusal in [ | ||
| 4348 | - "an inter var-tx tree with a leaf transform larger than 32x32", | ||
| 4349 | - "an inter var-tx tree with a leaf transform larger than 64x64", | ||
| 4350 | - ] { | ||
| 4351 | - assert!( | ||
| 4352 | - crate::refusal_inventory::pins_refusal(crate::test_source::module_source("decode"), refusal), | ||
| 4353 | - "this gate proves {refusal:?}, but that string is no longer in decode.rs" | ||
| 4354 | - ); | ||
| 4355 | - } | ||
| 4356 | // Every leaf `read_var_tx_size` can reach from `entry`, as (depth, w, h). | 4347 | // Every leaf `read_var_tx_size` can reach from `entry`, as (depth, w, h). |
| 4357 | fn reachable(entry: (usize, usize), depth: usize, out: &mut Vec<(usize, usize, usize)>) { | 4348 | fn reachable(entry: (usize, usize), depth: usize, out: &mut Vec<(usize, usize, usize)>) { |
| 4358 | out.push((depth, entry.0, entry.1)); | 4349 | out.push((depth, entry.0, entry.1)); |
crates/ec-av1/src/decode/rect.rsmodified+0 -10
| @@ -1754,16 +1754,6 @@ pub(super) const BLOCK_SIZES_ALL_WH: [(usize, usize); 22] = [ | |||
| 1754 | /// clause rejects before the lookup. | 1754 | /// clause rejects before the lookup. |
| 1755 | #[test] | 1755 | #[test] |
| 1756 | fn every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row() { | 1756 | fn every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row() { |
| 1757 | - // lane-av1refusalspan: this gate is the PROOF for the refusal below, so it | ||
| 1758 | - // names it and pins its guard site. | ||
| 1759 | - const REFUSAL: &str = "a motion_mode symbol for a block shape with no CDF row here"; | ||
| 1760 | - assert!( | ||
| 1761 | - crate::refusal_inventory::pins_refusal( | ||
| 1762 | - crate::test_source::module_source("decode"), | ||
| 1763 | - REFUSAL | ||
| 1764 | - ), | ||
| 1765 | - "this gate proves {REFUSAL:?}, but that string is no longer in decode.rs" | ||
| 1766 | - ); | ||
| 1767 | let mut rows = std::collections::BTreeSet::new(); | 1757 | let mut rows = std::collections::BTreeSet::new(); |
| 1768 | let mut excluded = 0; | 1758 | let mut excluded = 0; |
| 1769 | for (w, h) in BLOCK_SIZES_ALL_WH { | 1759 | for (w, h) in BLOCK_SIZES_ALL_WH { |
crates/ec-av1/src/decode/tests.rsmodified+5 -54
| @@ -2433,16 +2433,6 @@ fn an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking() { | |||
| 2433 | #[test] | 2433 | #[test] |
| 2434 | fn every_inter_record_publishes_an_obmc_readable_filter() { | 2434 | fn every_inter_record_publishes_an_obmc_readable_filter() { |
| 2435 | let src = crate::test_source::module_source("decode"); | 2435 | let src = crate::test_source::module_source("decode"); |
| 2436 | - // lane-av1refusalspan: this gate is the PROOF for the refusal below, so | ||
| 2437 | - // it names it and pins its guard site. The sibling test | ||
| 2438 | - // `an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking` | ||
| 2439 | - // carries the same string 27k lines away in this file -- exactly the | ||
| 2440 | - // reach a window that is not a function boundary used to have. | ||
| 2441 | - const REFUSAL: &str = "an OBMC neighbour whose switchable interp filter was never recorded"; | ||
| 2442 | - assert!( | ||
| 2443 | - crate::refusal_inventory::pins_refusal(src, REFUSAL), | ||
| 2444 | - "this gate proves {REFUSAL:?}, but that string is no longer in decode.rs" | ||
| 2445 | - ); | ||
| 2446 | let mut calls = 0usize; | 2436 | let mut calls = 0usize; |
| 2447 | for (start, _) in src.match_indices("record_inter_rect_mi(") { | 2437 | for (start, _) in src.match_indices("record_inter_rect_mi(") { |
| 2448 | // Skip the definition and the wrapper's own forwarding call. | 2438 | // Skip the definition and the wrapper's own forwarding call. |
| @@ -3021,36 +3011,13 @@ fn a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing() { | |||
| 3021 | // name (that module is another lane's territory this round, and the | 3011 | // name (that module is another lane's territory this round, and the |
| 3022 | // helpers are `#[cfg(test)]`-private to it). | 3012 | // helpers are `#[cfg(test)]`-private to it). |
| 3023 | use crate::probe::run_with_stdin; | 3013 | use crate::probe::run_with_stdin; |
| 3024 | -use std::process::{Command, Stdio}; | 3014 | + |
| 3025 | - | ||
| 3026 | -/// Whether ffmpeg is on PATH. Absence normally SKIPs, but | ||
| 3027 | -/// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every | ||
| 3028 | -/// aomenc gate decodes its stream through ffmpeg and is meaningless | ||
| 3029 | -/// without it -- turns it into a hard failure. Without this the require | ||
| 3030 | -/// flag was silently short-circuited: `!have_ffmpeg()` is evaluated first | ||
| 3031 | -/// in `if !have_ffmpeg() || !have_aomenc()`, so a machine with no ffmpeg | ||
| 3032 | -/// printed SKIP and reported green (class gate-skips-on-its-own-failure). | ||
| 3033 | -fn have_ffmpeg() -> bool { | ||
| 3034 | - let present = Command::new("ffmpeg") | ||
| 3035 | - .arg("-version") | ||
| 3036 | - .stdout(Stdio::null()) | ||
| 3037 | - .stderr(Stdio::null()) | ||
| 3038 | - .status() | ||
| 3039 | - .is_ok_and(|s| s.success()); | ||
| 3040 | - assert!( | ||
| 3041 | - present | ||
| 3042 | - || (!crate::envflags::env_flag!("EC_AV1_REQUIRE_FFMPEG") | ||
| 3043 | - && !crate::envflags::env_flag!("EC_AV1_REQUIRE_AOMENC")), | ||
| 3044 | - "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH" | ||
| 3045 | - ); | ||
| 3046 | - present | ||
| 3047 | -} | ||
| 3048 | 3015 | ||
| 3049 | /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0 | 3016 | /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0 |
| 3050 | /// frame's planes, at ffmpeg's own (coded, block-padded) size. | 3017 | /// frame's planes, at ffmpeg's own (coded, block-padded) size. |
| 3051 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { | 3018 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { |
| 3052 | let out = run_with_stdin( | 3019 | let out = run_with_stdin( |
| 3053 | - Command::new("ffmpeg").args([ | 3020 | + ec_testkit::ffmpeg().args([ |
| 3054 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 3021 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 3055 | ]), | 3022 | ]), |
| 3056 | stream, | 3023 | stream, |
| @@ -3089,7 +3056,7 @@ fn ffmpeg_decode_sequence( | |||
| 3089 | frames: usize, | 3056 | frames: usize, |
| 3090 | ) -> Vec<Picture> { | 3057 | ) -> Vec<Picture> { |
| 3091 | let out = run_with_stdin( | 3058 | let out = run_with_stdin( |
| 3092 | - Command::new("ffmpeg").args([ | 3059 | + ec_testkit::ffmpeg().args([ |
| 3093 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 3060 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 3094 | ]), | 3061 | ]), |
| 3095 | stream, | 3062 | stream, |
| @@ -3144,7 +3111,7 @@ fn ffprobe_size(stream: &[u8]) -> (u32, u32) { | |||
| 3144 | )); | 3111 | )); |
| 3145 | let _ = std::fs::remove_file(&path); | 3112 | let _ = std::fs::remove_file(&path); |
| 3146 | std::fs::write(&path, stream).expect("writing the probe stream"); | 3113 | std::fs::write(&path, stream).expect("writing the probe stream"); |
| 3147 | - let out = crate::tool_cache::cached_output_io(Command::new("ffprobe") | 3114 | + let out = ec_testkit::ffprobe() |
| 3148 | .args([ | 3115 | .args([ |
| 3149 | "-v", | 3116 | "-v", |
| 3150 | "error", | 3117 | "error", |
| @@ -3157,7 +3124,7 @@ fn ffprobe_size(stream: &[u8]) -> (u32, u32) { | |||
| 3157 | "-of", | 3124 | "-of", |
| 3158 | "csv=p=0", | 3125 | "csv=p=0", |
| 3159 | ]) | 3126 | ]) |
| 3160 | - .arg(&path), None, |c| c.output()) | 3127 | + .arg(&path).output() |
| 3161 | .expect("ffprobe failed to run"); | 3128 | .expect("ffprobe failed to run"); |
| 3162 | let _ = std::fs::remove_file(&path); | 3129 | let _ = std::fs::remove_file(&path); |
| 3163 | assert!( | 3130 | assert!( |
| @@ -3179,10 +3146,6 @@ fn ffprobe_size(stream: &[u8]) -> (u32, u32) { | |||
| 3179 | #[test] | 3146 | #[test] |
| 3180 | fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { | 3147 | fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { |
| 3181 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | 3148 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) |
| 3182 | - if !have_ffmpeg() { | ||
| 3183 | - eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg"); | ||
| 3184 | - return; | ||
| 3185 | - } | ||
| 3186 | use crate::encode::encode_key_frame_with_ctx; | 3149 | use crate::encode::encode_key_frame_with_ctx; |
| 3187 | for &(width, height) in &[(64usize, 64usize), (216, 96), (40, 32)] { | 3150 | for &(width, height) in &[(64usize, 64usize), (216, 96), (40, 32)] { |
| 3188 | let picture = round_trip_test_card(width, height); | 3151 | let picture = round_trip_test_card(width, height); |
| @@ -3227,14 +3190,6 @@ fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { | |||
| 3227 | #[test] | 3190 | #[test] |
| 3228 | fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() { | 3191 | fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() { |
| 3229 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | 3192 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) |
| 3230 | - if !crate::encode::filter_intra_on() { | ||
| 3231 | - eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0"); | ||
| 3232 | - return; | ||
| 3233 | - } | ||
| 3234 | - if !have_ffmpeg() { | ||
| 3235 | - eprintln!("SKIP a_filter_intra_key_frame...: no ffmpeg"); | ||
| 3236 | - return; | ||
| 3237 | - } | ||
| 3238 | let (width, height) = (128usize, 128usize); | 3193 | let (width, height) = (128usize, 128usize); |
| 3239 | // Smooth, slowly curving content: what the recursive filter modes are | 3194 | // Smooth, slowly curving content: what the recursive filter modes are |
| 3240 | // for, and what a plain directional prediction leaves residual on. | 3195 | // for, and what a plain directional prediction leaves residual on. |
| @@ -3757,10 +3712,6 @@ fn a_nearmv_block_predicts_from_the_stacks_second_candidate() { | |||
| 3757 | #[test] | 3712 | #[test] |
| 3758 | fn ffmpeg_and_this_decoder_agree_on_a_gop() { | 3713 | fn ffmpeg_and_this_decoder_agree_on_a_gop() { |
| 3759 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | 3714 | let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) |
| 3760 | - if !have_ffmpeg() { | ||
| 3761 | - eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg"); | ||
| 3762 | - return; | ||
| 3763 | - } | ||
| 3764 | use crate::encode::encode_sequence_with_ctx; | 3715 | use crate::encode::encode_sequence_with_ctx; |
| 3765 | let (width, height) = (128usize, 64usize); | 3716 | let (width, height) = (128usize, 64usize); |
| 3766 | let pictures: Vec<_> = (0..3) | 3717 | let pictures: Vec<_> = (0..3) |
crates/ec-av1/src/encode/more_tests.rsmodified+6 -2675
Diff too large; view file
| @@ -1,7 +1,6 @@ | |||
| 1 | use super::*; | 1 | use super::*; |
| 2 | use super::tests::*; | 2 | use super::tests::*; |
| 3 | -use crate::intra::{D45_PRED, NON_DIRECTIONAL}; | 3 | + |
| 4 | -use std::process::Command; | ||
| 5 | 4 | ||
| 6 | 5 | ||
| 7 | /// lane-ab128: the 128 root's four AB shapes -- `PARTITION_HORZ_A` (two | 6 | /// lane-ab128: the 128 root's four AB shapes -- `PARTITION_HORZ_A` (two |
| @@ -23,15 +22,11 @@ use std::process::Command; | |||
| 23 | /// Runs only inside `superblock_size_global_suite`. | 22 | /// Runs only inside `superblock_size_global_suite`. |
| 24 | pub(super) fn a_128_root_ab_shapes_decode_exact_through_both_decoders() { | 23 | pub(super) fn a_128_root_ab_shapes_decode_exact_through_both_decoders() { |
| 25 | let _knobs = crate::speed::knob_write(); | 24 | let _knobs = crate::speed::knob_write(); |
| 26 | - if !have_ffmpeg() { | ||
| 27 | - eprintln!("SKIP: no ffmpeg"); | ||
| 28 | - return; | ||
| 29 | - } | ||
| 30 | force_sb128(true); | 25 | force_sb128(true); |
| 31 | let dir = std::env::temp_dir().join(format!("ec-av1-ab128-{}", std::process::id())); | 26 | let dir = std::env::temp_dir().join(format!("ec-av1-ab128-{}", std::process::id())); |
| 32 | std::fs::create_dir_all(&dir).unwrap(); | 27 | std::fs::create_dir_all(&dir).unwrap(); |
| 33 | let clip = dir.join("testsrc2-1280x768.y4m"); | 28 | let clip = dir.join("testsrc2-1280x768.y4m"); |
| 34 | - let ok = Command::new("ffmpeg") | 29 | + let ok = ec_testkit::ffmpeg() |
| 35 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 30 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 36 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 31 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 37 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 32 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
| @@ -331,94 +326,6 @@ use std::process::Command; | |||
| 331 | assert!(written_all > 0.0); | 326 | assert!(written_all > 0.0); |
| 332 | } | 327 | } |
| 333 | 328 | ||
| 334 | - /// Step (2) of the pricer lane: the same census, but on the REAL clips | ||
| 335 | - /// the BD gate scores -- one film clip and the screen capture -- so the | ||
| 336 | - /// question the film/screen split raises can be answered from data. Real | ||
| 337 | - /// tables (`EC_AV1_PRICE_FRAME_CDFS=1`) make both film clips smaller and | ||
| 338 | - /// the screen capture larger, and the census says why: on a screen | ||
| 339 | - /// capture the frame's own starting tables are the tables of a frame that | ||
| 340 | - /// coded PALETTE and long runs of zero blocks, so they are far from the | ||
| 341 | - /// tables the writer ends the frame with; the pricer error does not fall | ||
| 342 | - /// the way it does on film. | ||
| 343 | - /// | ||
| 344 | - /// Not a gate -- it prints. Run it once per mode: | ||
| 345 | - /// EC_AV1_PRICE_FRAME_CDFS=0 cargo test -p ec-av1 --release --lib -- \ | ||
| 346 | - /// --ignored pricer_error_census_on_clips --nocapture | ||
| 347 | - #[test] | ||
| 348 | - #[ignore = "reads the real library, needs ffmpeg"] | ||
| 349 | - fn pricer_error_census_on_clips() { | ||
| 350 | - let _knobs = crate::speed::knob_write(); | ||
| 351 | - if !have_ffmpeg() { | ||
| 352 | - eprintln!("SKIP pricer_error_census_on_clips: no ffmpeg"); | ||
| 353 | - return; | ||
| 354 | - } | ||
| 355 | - // lane-av1clipprobe: the crate's one fixture root (EC_FIXTURES first), | ||
| 356 | - // so this probe reads the same tree the preflight validates. Its | ||
| 357 | - // `assert!(!clips.is_empty())` below was already a hard failure, so no | ||
| 358 | - // skip shape changes here — only the root does. | ||
| 359 | - let fixtures = crate::library_fixture::root(); | ||
| 360 | - let mut clips: Vec<(String, std::path::PathBuf)> = Vec::new(); | ||
| 361 | - let film = fixtures.join("video/h264-1080p-23.976-8bit.mp4"); | ||
| 362 | - if film.exists() { | ||
| 363 | - clips.push(("film 1080p".to_string(), film)); | ||
| 364 | - } | ||
| 365 | - if let Ok(manifest) = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) | ||
| 366 | - && let Some(p) = manifest | ||
| 367 | - .lines() | ||
| 368 | - .skip(1) | ||
| 369 | - .filter_map(|l| l.split('\t').next()) | ||
| 370 | - .find(|p| { | ||
| 371 | - p.contains("/OBS/") && p.ends_with(".mkv") && std::path::Path::new(p).exists() | ||
| 372 | - }) | ||
| 373 | - { | ||
| 374 | - clips.push(("screen".to_string(), std::path::PathBuf::from(p))); | ||
| 375 | - } | ||
| 376 | - assert!(!clips.is_empty(), "no source clip available"); | ||
| 377 | - let (width, height, frames) = (640usize, 384usize, 6usize); | ||
| 378 | - for (name, path) in &clips { | ||
| 379 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 380 | - let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); | ||
| 381 | - SCREEN_FRAMES.iter().for_each(|c| { | ||
| 382 | - c.store(0, std::sync::atomic::Ordering::Relaxed); | ||
| 383 | - }); | ||
| 384 | - let _ = crate::tile::take_pricing_hits(); | ||
| 385 | - crate::tile::pricer_census_on(); | ||
| 386 | - let _ = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap(); | ||
| 387 | - let rows = crate::tile::take_pricer_census(); | ||
| 388 | - let (price_default, price_real) = crate::tile::take_pricing_hits(); | ||
| 389 | - let screen_on = SCREEN_FRAMES[1].load(std::sync::atomic::Ordering::Relaxed); | ||
| 390 | - println!( | ||
| 391 | - "\n## {name} ({frames} frames at {width}x{height}, q=100): screen frames \ | ||
| 392 | - {screen_on}, pricer armings default={price_default} real={price_real}" | ||
| 393 | - ); | ||
| 394 | - println!("| set | nz | blocks | priced bits | written bits | error |"); | ||
| 395 | - println!("|---|---|---|---|---|---|"); | ||
| 396 | - let (mut priced_all, mut written_all) = (0.0, 0.0); | ||
| 397 | - for ((set, bucket), (blocks, priced, written)) in &rows { | ||
| 398 | - priced_all += priced; | ||
| 399 | - written_all += written; | ||
| 400 | - println!( | ||
| 401 | - "| {set} | {} | {blocks} | {priced:.0} | {written:.0} | {:+.1}% |", | ||
| 402 | - crate::tile::census_bucket_label(*bucket), | ||
| 403 | - if *written > 0.0 { | ||
| 404 | - (priced - written) / written * 100.0 | ||
| 405 | - } else { | ||
| 406 | - 0.0 | ||
| 407 | - } | ||
| 408 | - ); | ||
| 409 | - } | ||
| 410 | - println!( | ||
| 411 | - "| ALL | | {} | {priced_all:.0} | {written_all:.0} | {:+.1}% |", | ||
| 412 | - rows.values().map(|r| r.0).sum::<u64>(), | ||
| 413 | - (priced_all - written_all) / written_all * 100.0 | ||
| 414 | - ); | ||
| 415 | - assert!( | ||
| 416 | - written_all > 0.0, | ||
| 417 | - "{name}: the census saw no transform block" | ||
| 418 | - ); | ||
| 419 | - } | ||
| 420 | - } | ||
| 421 | - | ||
| 422 | /// Low motion has to actually buy something: at least one inter frame of | 329 | /// Low motion has to actually buy something: at least one inter frame of |
| 423 | /// a panning sequence has to cost fewer bytes than the key frame that | 330 | /// a panning sequence has to cost fewer bytes than the key frame that |
| 424 | /// starts it, and the inter-block share it prints has to be non-zero -- | 331 | /// starts it, and the inter-block share it prints has to be non-zero -- |
| @@ -459,446 +366,6 @@ use std::process::Command; | |||
| 459 | ); | 366 | ); |
| 460 | } | 367 | } |
| 461 | 368 | ||
| 462 | - /// A manual perf probe, not a gate: prints where a key frame's and an | ||
| 463 | - /// inter frame's time goes, coarse stage by coarse stage, so a perf lane | ||
| 464 | - /// measures before it optimizes rather than guessing. Run with | ||
| 465 | - /// `cargo test -p ec-av1 --release stage_timing_breakdown -- --ignored --nocapture`. | ||
| 466 | - #[test] | ||
| 467 | - #[ignore = "a perf probe, not a gate"] | ||
| 468 | - fn stage_timing_breakdown() { | ||
| 469 | - let _knobs = crate::speed::knob_read(); | ||
| 470 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 471 | - use std::time::Instant; | ||
| 472 | - | ||
| 473 | - for &(width, height) in &[(1920usize, 1080usize), (3840, 2160)] { | ||
| 474 | - let picture = test_card(width, height); | ||
| 475 | - | ||
| 476 | - let t = Instant::now(); | ||
| 477 | - let dc_only = | ||
| 478 | - encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[DC_PRED], fctx).unwrap(); | ||
| 479 | - let dc_only_t = t.elapsed(); | ||
| 480 | - | ||
| 481 | - let t = Instant::now(); | ||
| 482 | - let non_directional = | ||
| 483 | - encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &NON_DIRECTIONAL, fctx) | ||
| 484 | - .unwrap(); | ||
| 485 | - let non_directional_t = t.elapsed(); | ||
| 486 | - | ||
| 487 | - let t = Instant::now(); | ||
| 488 | - let all_modes = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | ||
| 489 | - let all_modes_t = t.elapsed(); | ||
| 490 | - | ||
| 491 | - eprintln!( | ||
| 492 | - "\n=== key frame {width}x{height} ===\n\ | ||
| 493 | - 1 mode (DC only): {dc_only_t:>9.2?} ({} bytes)\n\ | ||
| 494 | - 7 modes (non-directional): {non_directional_t:>9.2?} ({} bytes)\n\ | ||
| 495 | - 13 modes (default search): {all_modes_t:>9.2?} ({} bytes)", | ||
| 496 | - dc_only.stream.len(), | ||
| 497 | - non_directional.stream.len(), | ||
| 498 | - all_modes.stream.len(), | ||
| 499 | - ); | ||
| 500 | - | ||
| 501 | - // One inter frame predicting off the key frame's own | ||
| 502 | - // reconstruction, the (256, 256)-padded surface encode_sequence | ||
| 503 | - // itself would hand encode_inter_frame. | ||
| 504 | - let padded_ref = all_modes.reconstruction.padded_to(SUPERBLOCK); | ||
| 505 | - let padded_pic = picture.padded_to(SUPERBLOCK); | ||
| 506 | - let t = Instant::now(); | ||
| 507 | - let inter = encode_inter_frame( | ||
| 508 | - &padded_pic, | ||
| 509 | - &padded_ref, | ||
| 510 | - 100, | ||
| 511 | - 0.5, | ||
| 512 | - 1, | ||
| 513 | - flat_order_hints(1, 0, false), | ||
| 514 | - (width, height), | ||
| 515 | - None, | ||
| 516 | - None, | ||
| 517 | - None, | ||
| 518 | - None, | ||
| 519 | - fctx, | ||
| 520 | - None, | ||
| 521 | - &[], | ||
| 522 | - ) | ||
| 523 | - .unwrap(); | ||
| 524 | - let inter_t = t.elapsed(); | ||
| 525 | - eprintln!( | ||
| 526 | - "inter frame vs its own key frame: {inter_t:>9.2?} ({} bytes, inter share \ | ||
| 527 | - {:.2})", | ||
| 528 | - inter.stream.len(), | ||
| 529 | - inter.inter_block_share | ||
| 530 | - ); | ||
| 531 | - } | ||
| 532 | - | ||
| 533 | - // Isolated per-call cost of the trial pipeline's own stages, at both | ||
| 534 | - // transform sizes the search runs, averaged over enough calls to | ||
| 535 | - // rise above `Instant::now`'s own noise. | ||
| 536 | - for side in [16usize, 32] { | ||
| 537 | - const N: u32 = 20_000; | ||
| 538 | - let residual: Vec<i32> = (0..side * side) | ||
| 539 | - .map(|i| ((i * 37 % 61) as i32) - 30) | ||
| 540 | - .collect(); | ||
| 541 | - | ||
| 542 | - let t = Instant::now(); | ||
| 543 | - let mut levels = Vec::new(); | ||
| 544 | - for _ in 0..N { | ||
| 545 | - levels = forward_and_quantize(&residual, side, 8, 100, 0.5); | ||
| 546 | - } | ||
| 547 | - let forward_t = t.elapsed() / N; | ||
| 548 | - | ||
| 549 | - let t = Instant::now(); | ||
| 550 | - for _ in 0..N { | ||
| 551 | - std::hint::black_box(crate::transform::dequant_and_inverse(&levels, side, 8, 100)); | ||
| 552 | - } | ||
| 553 | - let inverse_t = t.elapsed() / N; | ||
| 554 | - | ||
| 555 | - let set = if side == 32 { | ||
| 556 | - crate::cdf_state::TxbSet::Luma32 | ||
| 557 | - } else { | ||
| 558 | - crate::cdf_state::TxbSet::Luma16 | ||
| 559 | - }; | ||
| 560 | - let t = Instant::now(); | ||
| 561 | - for _ in 0..N { | ||
| 562 | - std::hint::black_box(crate::tile::coeff_bits(&levels, set, 2, 0, 0)); | ||
| 563 | - } | ||
| 564 | - let entropy_t = t.elapsed() / N; | ||
| 565 | - | ||
| 566 | - let above = vec![128u8; side * 2]; | ||
| 567 | - let left = vec![128u8; side * 2]; | ||
| 568 | - let mut prediction = vec![0u8; side * side]; | ||
| 569 | - let t = Instant::now(); | ||
| 570 | - for _ in 0..N { | ||
| 571 | - intra_predict_u8( | ||
| 572 | - D45_PRED, | ||
| 573 | - 0, | ||
| 574 | - Some(&above), | ||
| 575 | - Some(&left), | ||
| 576 | - Some(128), | ||
| 577 | - side, | ||
| 578 | - side, | ||
| 579 | - false, | ||
| 580 | - false, | ||
| 581 | - &mut prediction, | ||
| 582 | - fctx, | ||
| 583 | - ); | ||
| 584 | - } | ||
| 585 | - let predict_t = t.elapsed() / N; | ||
| 586 | - | ||
| 587 | - eprintln!( | ||
| 588 | - "\n=== per-call cost at {side}x{side}, averaged over {N} calls ===\n\ | ||
| 589 | - predict (1 directional mode): {predict_t:>9.2?}\n\ | ||
| 590 | - forward_and_quantize: {forward_t:>9.2?}\n\ | ||
| 591 | - dequant_and_inverse: {inverse_t:>9.2?}\n\ | ||
| 592 | - coeff_bits: {entropy_t:>9.2?}" | ||
| 593 | - ); | ||
| 594 | - } | ||
| 595 | - } | ||
| 596 | - | ||
| 597 | - /// Breaks one inter frame's own cost into the four [`STAGE_NS`] buckets | ||
| 598 | - /// plus what is left over once buckets 0/2/3 are subtracted. | ||
| 599 | - /// | ||
| 600 | - /// lane-av1probes: the two search-shaped buckets OVERLAP and the old | ||
| 601 | - /// print denied it. Bucket 0 is not "the motion search": `stage_since(0, | ||
| 602 | - /// ..)` fires only after `find_best_new_mv` and the global-MV search | ||
| 603 | - /// (`encode.rs:11959`, `:12080`), so it is the NEWMV/GLOBAL sub-search | ||
| 604 | - /// alone. Bucket 1 is EVERY `crate::mc::predict` call, from the search's | ||
| 605 | - /// candidates *and* from a committed inter block's final prediction -- | ||
| 606 | - /// and that final prediction runs OUTSIDE any bucket-0 region. So bucket 1 | ||
| 607 | - /// is neither inside bucket 0 nor smaller than it, and a print that shows | ||
| 608 | - /// it as "motion search (of which interpolation ...)" necessarily shows | ||
| 609 | - /// a sub-number bigger than its parent. Measured: bucket 0 = 17.82 ms, | ||
| 610 | - /// bucket 1 = 148.63 ms. | ||
| 611 | - /// | ||
| 612 | - /// Which number is real: BOTH timers are right; only the old ARITHMETIC | ||
| 613 | - /// was wrong. Bucket 1 is now printed as its own top-level row, the | ||
| 614 | - /// overlap is stated, and the residual is labelled for what it is -- it | ||
| 615 | - /// absorbs the committed block's own interpolation, so it is not a pure | ||
| 616 | - /// "13-mode intra candidate loop" figure either. | ||
| 617 | - /// | ||
| 618 | - /// `cargo test -p ec-av1 --release stage_timing_breakdown_inter -- --ignored --nocapture`. | ||
| 619 | - #[test] | ||
| 620 | - #[ignore = "a perf probe, not a gate"] | ||
| 621 | - fn stage_timing_breakdown_inter() { | ||
| 622 | - let _knobs = crate::speed::knob_read(); | ||
| 623 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 624 | - use std::time::Instant; | ||
| 625 | - | ||
| 626 | - let (width, height) = (1280usize, 720); | ||
| 627 | - let picture = test_card(width, height); | ||
| 628 | - let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | ||
| 629 | - let padded_ref = key.reconstruction.padded_to(SUPERBLOCK); | ||
| 630 | - let padded_pic = picture.padded_to(SUPERBLOCK); | ||
| 631 | - | ||
| 632 | - stage_reset(); | ||
| 633 | - let t = Instant::now(); | ||
| 634 | - let inter = encode_inter_frame( | ||
| 635 | - &padded_pic, | ||
| 636 | - &padded_ref, | ||
| 637 | - 100, | ||
| 638 | - 0.5, | ||
| 639 | - 1, | ||
| 640 | - flat_order_hints(1, 0, false), | ||
| 641 | - (width, height), | ||
| 642 | - None, | ||
| 643 | - None, | ||
| 644 | - None, | ||
| 645 | - None, | ||
| 646 | - fctx, | ||
| 647 | - None, | ||
| 648 | - &[], | ||
| 649 | - ) | ||
| 650 | - .unwrap(); | ||
| 651 | - let total_t = t.elapsed(); | ||
| 652 | - let [motion_search, interpolation, transform_quant, entropy] = stage_read(); | ||
| 653 | - // Buckets 0 and 2 and 3 are disjoint and additive. Bucket 1 (every | ||
| 654 | - // `mc::predict` call) is NOT added: it overlaps bucket 0 wherever a | ||
| 655 | - // search candidate calls predict, and it also covers the committed | ||
| 656 | - // block's final prediction, which no other bucket times. Adding it | ||
| 657 | - // would double-count the overlap; leaving it out puts the committed | ||
| 658 | - // prediction (and the intra candidate loop, RD glue, and the symbol | ||
| 659 | - // lookups outside `coeff_bits`) into the residual, which is what the | ||
| 660 | - // residual has always been. | ||
| 661 | - let accounted = motion_search + transform_quant + entropy; | ||
| 662 | - let other = total_t.saturating_sub(accounted); | ||
| 663 | - let overlap = interpolation.saturating_sub(motion_search); | ||
| 664 | - | ||
| 665 | - eprintln!( | ||
| 666 | - "\n=== inter frame {width}x{height}, one frame ===\n\ | ||
| 667 | - total: {total_t:>9.2?} ({} bytes)\n\ | ||
| 668 | - NEWMV/GLOBAL sub-search (bucket 0): {motion_search:>9.2?}\n\ | ||
| 669 | - transform + quantize (bucket 2): {transform_quant:>9.2?}\n\ | ||
| 670 | - coeff_bits, entropy pricing (bucket 3): {entropy:>9.2?}\n\ | ||
| 671 | - buckets 0+2+3 accounted: {accounted:>9.2?}\n\ | ||
| 672 | - \n\ | ||
| 673 | - OVERLAPPING, not additive: every mc::predict call (bucket 1) {interpolation:>9.2?}\n\ | ||
| 674 | - \x20 -- of which {overlap:>9.2?} is OUTSIDE bucket 0 (a committed\n\ | ||
| 675 | - \x20 inter block's final prediction, which no bucket above times)\n\ | ||
| 676 | - \x20 and the rest is the search candidates' interpolation, already\n\ | ||
| 677 | - \x20 inside bucket 0. It is deliberately NOT added to the total.\n\ | ||
| 678 | - \n\ | ||
| 679 | - residual (13-mode intra candidate loop, the committed block's\n\ | ||
| 680 | - \x20 interpolation above, NEARESTMV's own predict, RD glue): {other:>9.2?}", | ||
| 681 | - inter.stream.len(), | ||
| 682 | - ); | ||
| 683 | - } | ||
| 684 | - | ||
| 685 | - /// The quality gate [`Search::top_k`]'s lever lives or dies by: three real | ||
| 686 | - /// frames (a dark/flat one, a detailed one, a normal film one) at two | ||
| 687 | - /// `base_q_idx` values, encoded with the mode search unpruned (`top_k = | ||
| 688 | - /// None`, the baseline this same build produces without | ||
| 689 | - /// `EC_AV1_PRUNE_K` set) and with it pruned to each of a few `K`, bytes | ||
| 690 | - /// and luma PSNR compared side by side. Not a gate itself -- the numbers | ||
| 691 | - /// go in the lane report, which is where "ship as default" is decided -- | ||
| 692 | - /// so it stays `#[ignore]`, run by hand with real clips on this machine. | ||
| 693 | - /// `cargo test -p ec-av1 --release prune_k_quality_sweep -- --ignored --nocapture`. | ||
| 694 | - #[test] | ||
| 695 | - // The three clip paths are HARD-CODED ABSOLUTES under /home/user, not | ||
| 696 | - // env-driven: off this workstation every row prints `SKIP <label>: <path> | ||
| 697 | - // not present on this machine` and the run exits 0 with no numbers. It is | ||
| 698 | - // a local-run probe; there is no fleet-host configuration that makes it | ||
| 699 | - // measure anything. | ||
| 700 | - #[ignore = "local-run only: the three clips are hard-coded /home/user paths, so off this workstation it SKIPs every row and prints nothing"] | ||
| 701 | - pub(super) fn prune_k_quality_sweep() { | ||
| 702 | - let _knobs = crate::speed::knob_read(); | ||
| 703 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 704 | - if !have_ffmpeg() { | ||
| 705 | - eprintln!("SKIP prune_k_quality_sweep: no ffmpeg"); | ||
| 706 | - return; | ||
| 707 | - } | ||
| 708 | - let (width, height) = (640usize, 352usize); | ||
| 709 | - let frames: &[(&str, &str, &str)] = &[ | ||
| 710 | - // (label, clip, seek) -- a near-black scene, a busy one, and an | ||
| 711 | - // ordinary film frame, each from a different real file. | ||
| 712 | - ( | ||
| 713 | - "dark/flat", | ||
| 714 | - "/home/user/Videos/reela.mp4", | ||
| 715 | - "3", | ||
| 716 | - ), | ||
| 717 | - ( | ||
| 718 | - "detailed", | ||
| 719 | - "/home/user/Downloads/reelb.mkv", | ||
| 720 | - "1200", | ||
| 721 | - ), | ||
| 722 | - ( | ||
| 723 | - "film", | ||
| 724 | - "/home/user/Videos/Films/reelc.mkv", | ||
| 725 | - "600", | ||
| 726 | - ), | ||
| 727 | - ]; | ||
| 728 | - for &(label, clip, skip) in frames { | ||
| 729 | - if !std::path::Path::new(clip).exists() { | ||
| 730 | - eprintln!("SKIP {label}: {clip} not present on this machine"); | ||
| 731 | - continue; | ||
| 732 | - } | ||
| 733 | - let picture = clip_frame(clip, skip, width, height); | ||
| 734 | - for &q in &[60u8, 150] { | ||
| 735 | - // Note (process-global, not a memory question): this is | ||
| 736 | - // a single-threaded #[ignore] probe, run by hand, never | ||
| 737 | - // alongside other tests that read Search::top_k. | ||
| 738 | - set_test_top_k_override(None); | ||
| 739 | - let baseline = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); | ||
| 740 | - let baseline_psnr = psnr(&baseline.reconstruction.y, &picture.y); | ||
| 741 | - eprint!( | ||
| 742 | - "{label:9} q={q:3} baseline {:6} bytes {:6.2} dB", | ||
| 743 | - baseline.stream.len(), | ||
| 744 | - baseline_psnr | ||
| 745 | - ); | ||
| 746 | - for &k in &[3usize, 4, 6] { | ||
| 747 | - set_test_top_k_override(Some(k)); | ||
| 748 | - let pruned = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); | ||
| 749 | - let pruned_psnr = psnr(&pruned.reconstruction.y, &picture.y); | ||
| 750 | - eprint!( | ||
| 751 | - " K={k} {:6} bytes {:6.2} dB ({:+.3} dB)", | ||
| 752 | - pruned.stream.len(), | ||
| 753 | - pruned_psnr, | ||
| 754 | - pruned_psnr - baseline_psnr | ||
| 755 | - ); | ||
| 756 | - } | ||
| 757 | - eprintln!(); | ||
| 758 | - } | ||
| 759 | - } | ||
| 760 | - set_test_top_k_override(None); | ||
| 761 | - } | ||
| 762 | - | ||
| 763 | - /// Two consecutive decoded frames from one clip, for an inter-frame | ||
| 764 | - /// sweep -- [`clip_frame`] alone only ever gives one. | ||
| 765 | - pub(super) fn clip_frame_pair(clip: &str, skip: &str, width: usize, height: usize) -> [Picture; 2] { | ||
| 766 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 767 | - .args(["-v", "error", "-ss", skip, "-i", clip, "-frames:v", "2"]) | ||
| 768 | - .args(["-vf", &format!("scale={width}:{height}")]) | ||
| 769 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]), None, |c| c.output()) | ||
| 770 | - .expect("ffmpeg failed to run"); | ||
| 771 | - assert!( | ||
| 772 | - out.status.success(), | ||
| 773 | - "ffmpeg: {}", | ||
| 774 | - String::from_utf8_lossy(&out.stderr) | ||
| 775 | - ); | ||
| 776 | - let (luma, chroma) = (width * height, width * height / 4); | ||
| 777 | - let frame_len = luma + 2 * chroma; | ||
| 778 | - assert_eq!(out.stdout.len(), frame_len * 2, "expected two 4:2:0 frames"); | ||
| 779 | - std::array::from_fn(|i| { | ||
| 780 | - let bytes = &out.stdout[i * frame_len..][..frame_len]; | ||
| 781 | - Picture { | ||
| 782 | - width, | ||
| 783 | - height, | ||
| 784 | - y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | ||
| 785 | - u: bytes[luma..luma + chroma] | ||
| 786 | - .iter() | ||
| 787 | - .map(|&v| u16::from(v)) | ||
| 788 | - .collect(), | ||
| 789 | - v: bytes[luma + chroma..] | ||
| 790 | - .iter() | ||
| 791 | - .map(|&v| u16::from(v)) | ||
| 792 | - .collect(), | ||
| 793 | - } | ||
| 794 | - }) | ||
| 795 | - } | ||
| 796 | - | ||
| 797 | - /// The quality gate [`INTER_PRUNE_TOP_K`] lives or dies by: the same | ||
| 798 | - /// three real clips as [`prune_k_quality_sweep`], but coding a key frame | ||
| 799 | - /// then one inter frame off it (`search_inter_block`'s own intra | ||
| 800 | - /// candidates are what [`prune_by_sad`] prunes here, not the key-frame | ||
| 801 | - /// loop), at 1280x704 -- a whole number of 64x64 superblocks, so no | ||
| 802 | - /// padding step complicates the comparison. Prints bytes and luma PSNR | ||
| 803 | - /// for the inter frame alone, unpruned vs each `K`. | ||
| 804 | - /// `cargo test -p ec-av1 --release prune_k_quality_sweep_inter -- --ignored --nocapture`. | ||
| 805 | - #[test] | ||
| 806 | - // Same hard-coded /home/user clip paths as `prune_k_quality_sweep`; | ||
| 807 | - // off this workstation it SKIPs all three rows and prints nothing. | ||
| 808 | - #[ignore = "local-run only: the three clips are hard-coded /home/user paths, so off this workstation it SKIPs every row and prints nothing"] | ||
| 809 | - pub(super) fn prune_k_quality_sweep_inter() { | ||
| 810 | - let _knobs = crate::speed::knob_read(); | ||
| 811 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 812 | - if !have_ffmpeg() { | ||
| 813 | - eprintln!("SKIP prune_k_quality_sweep_inter: no ffmpeg"); | ||
| 814 | - return; | ||
| 815 | - } | ||
| 816 | - let (width, height) = (1280usize, 704usize); | ||
| 817 | - let frames: &[(&str, &str, &str)] = &[ | ||
| 818 | - ( | ||
| 819 | - "dark/flat", | ||
| 820 | - "/home/user/Videos/reela.mp4", | ||
| 821 | - "3", | ||
| 822 | - ), | ||
| 823 | - ( | ||
| 824 | - "detailed", | ||
| 825 | - "/home/user/Downloads/reelb.mkv", | ||
| 826 | - "1200", | ||
| 827 | - ), | ||
| 828 | - ( | ||
| 829 | - "film", | ||
| 830 | - "/home/user/Videos/Films/reelc.mkv", | ||
| 831 | - "600", | ||
| 832 | - ), | ||
| 833 | - ]; | ||
| 834 | - for &(label, clip, skip) in frames { | ||
| 835 | - if !std::path::Path::new(clip).exists() { | ||
| 836 | - eprintln!("SKIP {label}: {clip} not present on this machine"); | ||
| 837 | - continue; | ||
| 838 | - } | ||
| 839 | - let [key_source, inter_source] = clip_frame_pair(clip, skip, width, height); | ||
| 840 | - for &q in &[60u8, 150] { | ||
| 841 | - // Note (process-global, not a memory question): a | ||
| 842 | - // single-threaded #[ignore] probe, run by hand, never | ||
| 843 | - // alongside other tests that read Search::top_k. | ||
| 844 | - set_test_top_k_override_inter(None); | ||
| 845 | - let key = encode_key_frame_with_ctx(&key_source, q, 0.5, fctx).unwrap(); | ||
| 846 | - let baseline = encode_inter_frame( | ||
| 847 | - &inter_source, | ||
| 848 | - &key.reconstruction, | ||
| 849 | - q, | ||
| 850 | - 0.5, | ||
| 851 | - 1, | ||
| 852 | - flat_order_hints(1, 0, false), | ||
| 853 | - (width, height), | ||
| 854 | - None, | ||
| 855 | - None, | ||
| 856 | - None, | ||
| 857 | - None, | ||
| 858 | - fctx, | ||
| 859 | - None, | ||
| 860 | - &[], | ||
| 861 | - ) | ||
| 862 | - .unwrap(); | ||
| 863 | - let baseline_psnr = psnr(&baseline.reconstruction.y, &inter_source.y); | ||
| 864 | - eprint!( | ||
| 865 | - "{label:9} q={q:3} baseline {:6} bytes {:6.2} dB", | ||
| 866 | - baseline.stream.len(), | ||
| 867 | - baseline_psnr | ||
| 868 | - ); | ||
| 869 | - for &k in &[3usize, 4, 6] { | ||
| 870 | - set_test_top_k_override_inter(Some(k)); | ||
| 871 | - let pruned = encode_inter_frame( | ||
| 872 | - &inter_source, | ||
| 873 | - &key.reconstruction, | ||
| 874 | - q, | ||
| 875 | - 0.5, | ||
| 876 | - 1, | ||
| 877 | - flat_order_hints(1, 0, false), | ||
| 878 | - (width, height), | ||
| 879 | - None, | ||
| 880 | - None, | ||
| 881 | - None, | ||
| 882 | - None, | ||
| 883 | - fctx, | ||
| 884 | - None, | ||
| 885 | - &[], | ||
| 886 | - ) | ||
| 887 | - .unwrap(); | ||
| 888 | - let pruned_psnr = psnr(&pruned.reconstruction.y, &inter_source.y); | ||
| 889 | - eprint!( | ||
| 890 | - " K={k} {:6} bytes {:6.2} dB ({:+.3} dB)", | ||
| 891 | - pruned.stream.len(), | ||
| 892 | - pruned_psnr, | ||
| 893 | - pruned_psnr - baseline_psnr | ||
| 894 | - ); | ||
| 895 | - } | ||
| 896 | - eprintln!(); | ||
| 897 | - } | ||
| 898 | - } | ||
| 899 | - set_test_top_k_override_inter(None); | ||
| 900 | - } | ||
| 901 | - | ||
| 902 | /// `frames` consecutive pictures out of a real clip, scaled to a whole | 369 | /// `frames` consecutive pictures out of a real clip, scaled to a whole |
| 903 | /// number of 32x32 blocks. Generalizes [`clip_frame`]/[`clip_frame_pair`] | 370 | /// number of 32x32 blocks. Generalizes [`clip_frame`]/[`clip_frame_pair`] |
| 904 | /// to an arbitrary count for the fixture regression gate below. | 371 | /// to an arbitrary count for the fixture regression gate below. |
| @@ -938,210 +405,6 @@ use std::process::Command; | |||
| 938 | crate::probe::source(clip, skip, vf, width, height, frames) | 405 | crate::probe::source(clip, skip, vf, width, height, frames) |
| 939 | } | 406 | } |
| 940 | 407 | ||
| 941 | - /// The standing regression gate on real content: 12 frames of a real | ||
| 942 | - /// clip (`fixtures/video/h264-1080p-23.976-8bit.mp4`, decoded down to | ||
| 943 | - /// this crate's own input regardless of its own source codec), encoded | ||
| 944 | - /// as an AV1 GOP and checked against three numeric floors so a | ||
| 945 | - /// compatibility or quality regression fails the suite instead of | ||
| 946 | - /// waiting for a downstream repo's gate to catch it (as happened for a | ||
| 947 | - /// padded-size inter `FrameHeader` dav1d rejected, and a 1280x720 export | ||
| 948 | - /// refusal, both caught only that way). | ||
| 949 | - /// | ||
| 950 | - /// 640x384 is a whole number of 32x32 blocks (no straddle edge case; | ||
| 951 | - /// that geometry is already covered elsewhere), chosen only so encode | ||
| 952 | - /// time and gate numbers are not muddied by an edge-block class this | ||
| 953 | - /// test is not about. | ||
| 954 | - /// | ||
| 955 | - /// Measured 2026-08-27 at q=100: stream 69861 bytes, average luma PSNR | ||
| 956 | - /// 45.41 dB across the 12 decoded frames vs the source. Floor/ceiling | ||
| 957 | - /// below carry a margin off those measured numbers (PSNR floor = | ||
| 958 | - /// measured - 0.5 dB; byte ceiling = measured * 1.15). | ||
| 959 | - #[test] | ||
| 960 | - fn real_clip_encodes_within_its_quality_and_size_budget() { | ||
| 961 | - let _knobs = crate::speed::knob_read(); | ||
| 962 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 963 | - if !have_ffmpeg() { | ||
| 964 | - eprintln!("SKIP real_clip_encodes_within_its_quality_and_size_budget: no ffmpeg"); | ||
| 965 | - return; | ||
| 966 | - } | ||
| 967 | - // lane-av1clipprobe: the clip's absence was a bare `clip.exists()` | ||
| 968 | - // -> SKIP with no env escape, so this gate reported green on a tree | ||
| 969 | - // with no root `fixtures/`. The probe prints that one line (naming the | ||
| 970 | - // resolved path) and fails under the require envs. | ||
| 971 | - let Some(clip) = crate::library_fixture::require( | ||
| 972 | - "video/h264-1080p-23.976-8bit.mp4", | ||
| 973 | - "real_clip_encodes_within_its_quality_and_size_budget", | ||
| 974 | - ) else { | ||
| 975 | - return; | ||
| 976 | - }; | ||
| 977 | - let (width, height, frame_count) = (640usize, 384usize, 12usize); | ||
| 978 | - let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count); | ||
| 979 | - let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap(); | ||
| 980 | - assert_eq!(encoded.frames.len(), frame_count); | ||
| 981 | - | ||
| 982 | - // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole | ||
| 983 | - // stream and hands back every frame -- a stream a downstream | ||
| 984 | - // decoder refuses is the exact class of regression this gate | ||
| 985 | - // exists for. | ||
| 986 | - let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frame_count); | ||
| 987 | - assert_eq!(decoded.len(), frame_count, "dav1d decoded every frame"); | ||
| 988 | - | ||
| 989 | - // Gate 2: quality vs the source did not silently collapse. | ||
| 990 | - let mean_psnr: f64 = decoded | ||
| 991 | - .iter() | ||
| 992 | - .zip(&source) | ||
| 993 | - .map(|(d, s)| psnr(&d.y, &s.y)) | ||
| 994 | - .sum::<f64>() | ||
| 995 | - / frame_count as f64; | ||
| 996 | - assert!( | ||
| 997 | - mean_psnr >= 44.91, | ||
| 998 | - "mean luma PSNR {mean_psnr:.2} dB fell below the 44.91 dB floor" | ||
| 999 | - ); | ||
| 1000 | - | ||
| 1001 | - // Gate 3: the stream did not silently bloat. | ||
| 1002 | - assert!( | ||
| 1003 | - encoded.stream.len() <= 80_340, | ||
| 1004 | - "stream grew to {} bytes, over the 80340-byte ceiling", | ||
| 1005 | - encoded.stream.len() | ||
| 1006 | - ); | ||
| 1007 | - } | ||
| 1008 | - | ||
| 1009 | - /// Sibling of `real_clip_encodes_within_its_quality_and_size_budget` at a | ||
| 1010 | - /// straddle size: 640x384 is exact on both axes (32-aligned), so | ||
| 1011 | - /// `Quadrant::Split` never fires there and the 16x16 `NEARESTMV` leaf | ||
| 1012 | - /// path landed in e19bb47 goes unexercised by real, mixed intra/inter | ||
| 1013 | - /// content. 704x400 has 400 mod 32 == 16 -- the same "exactly half | ||
| 1014 | - /// straddle" class as `a_sequence_round_trips_at_the_exactly_half_ | ||
| 1015 | - /// straddle_size`'s 1280x720, but that test is a synthetic panned test | ||
| 1016 | - /// card; this one is the real-clip gate, same three floors. | ||
| 1017 | - /// | ||
| 1018 | - /// Measured 2026-08-27 at q=100, 8 frames: stream 54525 bytes, average | ||
| 1019 | - /// luma PSNR 45.48 dB across the 8 decoded frames vs the source. | ||
| 1020 | - /// Floor/ceiling below carry the same margin as the sibling test (PSNR | ||
| 1021 | - /// floor = measured - 0.5 dB; byte ceiling = measured * 1.15). | ||
| 1022 | - #[test] | ||
| 1023 | - fn real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size() { | ||
| 1024 | - let _knobs = crate::speed::knob_read(); | ||
| 1025 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 1026 | - if !have_ffmpeg() { | ||
| 1027 | - eprintln!( | ||
| 1028 | - "SKIP real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size: \ | ||
| 1029 | - no ffmpeg" | ||
| 1030 | - ); | ||
| 1031 | - return; | ||
| 1032 | - } | ||
| 1033 | - // lane-av1clipprobe: see the sibling gate above -- the bare | ||
| 1034 | - // `clip.exists()` -> SKIP had no env escape. | ||
| 1035 | - let Some(clip) = crate::library_fixture::require( | ||
| 1036 | - "video/h264-1080p-23.976-8bit.mp4", | ||
| 1037 | - "real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size", | ||
| 1038 | - ) else { | ||
| 1039 | - return; | ||
| 1040 | - }; | ||
| 1041 | - let (width, height, frame_count) = (704usize, 400usize, 8usize); | ||
| 1042 | - let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count); | ||
| 1043 | - let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap(); | ||
| 1044 | - assert_eq!(encoded.frames.len(), frame_count); | ||
| 1045 | - | ||
| 1046 | - // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole | ||
| 1047 | - // stream and hands back every frame. | ||
| 1048 | - let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frame_count); | ||
| 1049 | - assert_eq!(decoded.len(), frame_count, "dav1d decoded every frame"); | ||
| 1050 | - | ||
| 1051 | - // Gate 2: quality vs the source did not silently collapse. | ||
| 1052 | - let mean_psnr: f64 = decoded | ||
| 1053 | - .iter() | ||
| 1054 | - .zip(&source) | ||
| 1055 | - .map(|(d, s)| psnr(&d.y, &s.y)) | ||
| 1056 | - .sum::<f64>() | ||
| 1057 | - / frame_count as f64; | ||
| 1058 | - assert!( | ||
| 1059 | - mean_psnr >= 44.98, | ||
| 1060 | - "mean luma PSNR {mean_psnr:.2} dB fell below the 44.98 dB floor" | ||
| 1061 | - ); | ||
| 1062 | - | ||
| 1063 | - // Gate 3: the stream did not silently bloat. | ||
| 1064 | - assert!( | ||
| 1065 | - encoded.stream.len() <= 62_703, | ||
| 1066 | - "stream grew to {} bytes, over the 62703-byte ceiling", | ||
| 1067 | - encoded.stream.len() | ||
| 1068 | - ); | ||
| 1069 | - } | ||
| 1070 | - | ||
| 1071 | - /// The replica-shaped path: 24 frames, 1280x720, one key frame followed | ||
| 1072 | - /// by inter frames -- the same GOP shape [`encode_sequence`] gives the | ||
| 1073 | - /// facade -- timed end to end, so the edith export-time projection is a | ||
| 1074 | - /// real number rather than a guess from the isolated key/inter numbers | ||
| 1075 | - /// above. Run with and without `EC_AV1_PRUNE_K` set to compare. | ||
| 1076 | - /// `cargo test -p ec-av1 --release sequence_bench_sanity -- --ignored --nocapture`. | ||
| 1077 | - #[test] | ||
| 1078 | - #[ignore = "a perf probe, not a gate"] | ||
| 1079 | - fn sequence_bench_sanity() { | ||
| 1080 | - let _knobs = crate::speed::knob_read(); | ||
| 1081 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 1082 | - use std::time::Instant; | ||
| 1083 | - let (width, height) = (1280usize, 720usize); | ||
| 1084 | - let pictures: Vec<Picture> = (0..24) | ||
| 1085 | - .map(|i| panned_test_card(width, height, i * 3)) | ||
| 1086 | - .collect(); | ||
| 1087 | - let t = Instant::now(); | ||
| 1088 | - let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); | ||
| 1089 | - let elapsed = t.elapsed(); | ||
| 1090 | - let total_bytes: usize = encoded.frames.iter().map(|f| f.stream.len()).sum(); | ||
| 1091 | - eprintln!( | ||
| 1092 | - "24 frames @ 1280x720: {elapsed:>9.2?} total, {:>9.2?}/frame, {total_bytes} bytes", | ||
| 1093 | - elapsed / 24 | ||
| 1094 | - ); | ||
| 1095 | - } | ||
| 1096 | - | ||
| 1097 | - /// The `base_q_idx` calibration sweep for `lane-av1-ratectl` -- feeds the | ||
| 1098 | - /// `Quality`/`BytesPerFrame` rate-control surface in `encoder.rs`, not a | ||
| 1099 | - /// gate itself. `cargo test -p ec-av1 --release calibration_sweep_base_q_idx | ||
| 1100 | - /// -- --ignored --nocapture`. | ||
| 1101 | - #[test] | ||
| 1102 | - #[ignore = "a calibration probe, not a gate"] | ||
| 1103 | - fn calibration_sweep_base_q_idx() { | ||
| 1104 | - let _knobs = crate::speed::knob_read(); | ||
| 1105 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 1106 | - if !have_ffmpeg() { | ||
| 1107 | - eprintln!("SKIP calibration_sweep_base_q_idx: no ffmpeg"); | ||
| 1108 | - return; | ||
| 1109 | - } | ||
| 1110 | - let (width, height, frames) = (640usize, 384usize, 12usize); | ||
| 1111 | - for clip in [ | ||
| 1112 | - "h264-1080p-23.976-8bit.mp4", // film-ish, 23.976fps | ||
| 1113 | - "h264-1080p-60-8bit.mp4", // higher motion, 60fps | ||
| 1114 | - ] { | ||
| 1115 | - // lane-av1clipprobe: the crate's one fixture root and its one | ||
| 1116 | - // presence probe -- the bare `path.exists()` -> SKIP -> `continue` | ||
| 1117 | - // had no env escape, and with every clip absent the sweep looped | ||
| 1118 | - // zero times and passed. | ||
| 1119 | - let Some(path) = crate::library_fixture::require( | ||
| 1120 | - &format!("video/{clip}"), | ||
| 1121 | - &format!("calibration_sweep_base_q_idx: {clip}"), | ||
| 1122 | - ) else { | ||
| 1123 | - continue; | ||
| 1124 | - }; | ||
| 1125 | - let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); | ||
| 1126 | - eprintln!("--- {clip} ---"); | ||
| 1127 | - for q in [40u8, 70, 100, 130, 160, 190, 220, 240] { | ||
| 1128 | - let encoded = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap(); | ||
| 1129 | - let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frames); | ||
| 1130 | - let mean_psnr: f64 = decoded | ||
| 1131 | - .iter() | ||
| 1132 | - .zip(&source) | ||
| 1133 | - .map(|(d, s)| psnr(&d.y, &s.y)) | ||
| 1134 | - .sum::<f64>() | ||
| 1135 | - / frames as f64; | ||
| 1136 | - let bytes_per_px = encoded.stream.len() as f64 / (width * height * frames) as f64; | ||
| 1137 | - eprintln!( | ||
| 1138 | - "q={q:3} bytes={:7} bytes/px={bytes_per_px:.5} psnr={mean_psnr:.2} dB", | ||
| 1139 | - encoded.stream.len() | ||
| 1140 | - ); | ||
| 1141 | - } | ||
| 1142 | - } | ||
| 1143 | - } | ||
| 1144 | - | ||
| 1145 | // ----------------------------------------------------------------------- | 408 | // ----------------------------------------------------------------------- |
| 1146 | // The encoder's standing BD-rate baseline against libaom and rav1e. | 409 | // The encoder's standing BD-rate baseline against libaom and rav1e. |
| 1147 | // Every PSNR below is measured on FFMPEG-DECODED pixels, never on an | 410 | // Every PSNR below is measured on FFMPEG-DECODED pixels, never on an |
| @@ -1197,7 +460,7 @@ use std::process::Command; | |||
| 1197 | std::process::id() | 460 | std::process::id() |
| 1198 | )); | 461 | )); |
| 1199 | let start = std::time::Instant::now(); | 462 | let start = std::time::Instant::now(); |
| 1200 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | 463 | + let out = ec_testkit::ffmpeg() |
| 1201 | .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | 464 | .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) |
| 1202 | .args(["-s", &format!("{width}x{height}"), "-r", "24", "-i"]) | 465 | .args(["-s", &format!("{width}x{height}"), "-r", "24", "-i"]) |
| 1203 | .arg(&raw_path) | 466 | .arg(&raw_path) |
| @@ -1205,7 +468,7 @@ use std::process::Command; | |||
| 1205 | .args(["-g", &source.len().to_string(), "-c:v", encoder]) | 468 | .args(["-g", &source.len().to_string(), "-c:v", encoder]) |
| 1206 | .args(params) | 469 | .args(params) |
| 1207 | .args(["-f", "obu"]) | 470 | .args(["-f", "obu"]) |
| 1208 | - .arg(&obu), None, |c| c.output()) | 471 | + .arg(&obu).output() |
| 1209 | .expect("ffmpeg failed to run"); | 472 | .expect("ffmpeg failed to run"); |
| 1210 | wall += start.elapsed().as_secs_f64(); | 473 | wall += start.elapsed().as_secs_f64(); |
| 1211 | assert!( | 474 | assert!( |
| @@ -1529,19 +792,10 @@ use std::process::Command; | |||
| 1529 | let _knobs = crate::speed::knob_write(); | 792 | let _knobs = crate::speed::knob_write(); |
| 1530 | let was = crate::speed::speed(); | 793 | let was = crate::speed::speed(); |
| 1531 | crate::speed::set_speed(0); | 794 | crate::speed::set_speed(0); |
| 1532 | - if !have_ffmpeg() { | ||
| 1533 | - eprintln!("SKIP the_encoders_own_streams_are_byte_identical_to_their_pins: no ffmpeg"); | ||
| 1534 | - return; | ||
| 1535 | - } | ||
| 1536 | // lane-av1clipprobe: the bare `clip.exists()` -> SKIP had no env escape, | 795 | // lane-av1clipprobe: the bare `clip.exists()` -> SKIP had no env escape, |
| 1537 | // so a tree with no root `fixtures/` reported this gate green having | 796 | // so a tree with no root `fixtures/` reported this gate green having |
| 1538 | // compared nothing at all. | 797 | // compared nothing at all. |
| 1539 | - let Some(clip) = crate::library_fixture::require( | 798 | + let clip = ec_testkit::fixture("open/sintel_trailer-1080p.mp4"); |
| 1540 | - "video/h264-1080p-23.976-8bit.mp4", | ||
| 1541 | - "the_encoders_own_streams_are_byte_identical_to_their_pins", | ||
| 1542 | - ) else { | ||
| 1543 | - return; | ||
| 1544 | - }; | ||
| 1545 | let source = clip_frames(clip.to_str().unwrap(), "0", 640, 384, 4); | 799 | let source = clip_frames(clip.to_str().unwrap(), "0", 640, 384, 4); |
| 1546 | // FNV-1a over the stream: a witness that every coded bit is where it | 800 | // FNV-1a over the stream: a witness that every coded bit is where it |
| 1547 | // was, which a byte count alone is not. | 801 | // was, which a byte count alone is not. |
| @@ -1677,943 +931,6 @@ use std::process::Command; | |||
| 1677 | } | 931 | } |
| 1678 | } | 932 | } |
| 1679 | 933 | ||
| 1680 | - /// The sweep behind [`screen_content`]'s constants | ||
| 1681 | - /// (`unswept-decision-constants`), on the SAME five clips | ||
| 1682 | - /// [`bd_rate_screen_native`] keeps off (`native_gate_clips`) and at the | ||
| 1683 | - /// same native crop: for each colour bound N the share of 16x16 luma | ||
| 1684 | - /// blocks with 2..=N distinct colours, and the share of those whose | ||
| 1685 | - /// per-pixel variance also clears a floor V -- libaom's | ||
| 1686 | - /// `av1_set_screen_content_options` counts the variance-cleared blocks | ||
| 1687 | - /// too (its `counts_2`, which gates intrabc), and without that term a | ||
| 1688 | - /// smooth dark film frame reads as screen content. | ||
| 1689 | - /// `cargo test -p ec-av1 --release --lib -- --ignored probe_screen_detect --nocapture` | ||
| 1690 | - #[test] | ||
| 1691 | - #[ignore = "reads the real library"] | ||
| 1692 | - fn probe_screen_detect() { | ||
| 1693 | - let _knobs = crate::speed::knob_read(); | ||
| 1694 | - if !have_ffmpeg() { | ||
| 1695 | - eprintln!("SKIP probe_screen_detect: no ffmpeg"); | ||
| 1696 | - return; | ||
| 1697 | - } | ||
| 1698 | - let limits = [4usize, 8, 16, 32, 64, 128]; | ||
| 1699 | - let floors = [0u64, 4, 16, 64, 256]; | ||
| 1700 | - // The census of one clip at one size: mean share, over the frames, of | ||
| 1701 | - // 16x16 blocks with 2..=N colours whose per-pixel variance is > V. | ||
| 1702 | - let census = |label: &str, frames: &[Picture], cw: usize, ch: usize| { | ||
| 1703 | - let mut acc = [[0f64; 5]; 6]; | ||
| 1704 | - for picture in frames { | ||
| 1705 | - let y: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | ||
| 1706 | - let mut hit = [[0usize; 5]; 6]; | ||
| 1707 | - let mut blocks = 0usize; | ||
| 1708 | - for by in (0..ch).step_by(16) { | ||
| 1709 | - for bx in (0..cw).step_by(16) { | ||
| 1710 | - let mut seen = [false; 256]; | ||
| 1711 | - let (mut colors, mut sum, mut sq) = (0usize, 0u64, 0u64); | ||
| 1712 | - for row in 0..16 { | ||
| 1713 | - for col in 0..16 { | ||
| 1714 | - let v = y[(by + row) * cw + bx + col]; | ||
| 1715 | - sum += u64::from(v); | ||
| 1716 | - sq += u64::from(v) * u64::from(v); | ||
| 1717 | - if !seen[usize::from(v)] { | ||
| 1718 | - seen[usize::from(v)] = true; | ||
| 1719 | - colors += 1; | ||
| 1720 | - } | ||
| 1721 | - } | ||
| 1722 | - } | ||
| 1723 | - let var = (sq - sum * sum / 256) / 256; | ||
| 1724 | - blocks += 1; | ||
| 1725 | - for (li, &limit) in limits.iter().enumerate() { | ||
| 1726 | - if colors > 1 && colors <= limit { | ||
| 1727 | - for (fi, &floor) in floors.iter().enumerate() { | ||
| 1728 | - hit[li][fi] += usize::from(var > floor); | ||
| 1729 | - } | ||
| 1730 | - } | ||
| 1731 | - } | ||
| 1732 | - } | ||
| 1733 | - } | ||
| 1734 | - for li in 0..6 { | ||
| 1735 | - for fi in 0..5 { | ||
| 1736 | - acc[li][fi] += 100.0 * hit[li][fi] as f64 / blocks.max(1) as f64; | ||
| 1737 | - } | ||
| 1738 | - } | ||
| 1739 | - } | ||
| 1740 | - let n = frames.len().max(1) as f64; | ||
| 1741 | - eprintln!( | ||
| 1742 | - "{label} {cw}x{ch}, {} frames -- share of 16x16 blocks with 2..=N colours and per-pixel var > V:", | ||
| 1743 | - frames.len() | ||
| 1744 | - ); | ||
| 1745 | - eprintln!( | ||
| 1746 | - " N \\ V |{}", | ||
| 1747 | - floors.iter().map(|f| format!("{f:>8}")).collect::<String>() | ||
| 1748 | - ); | ||
| 1749 | - for (li, &limit) in limits.iter().enumerate() { | ||
| 1750 | - eprintln!( | ||
| 1751 | - " {limit:>5} |{}", | ||
| 1752 | - (0..5) | ||
| 1753 | - .map(|fi| format!("{:>7.1}%", acc[li][fi] / n)) | ||
| 1754 | - .collect::<String>() | ||
| 1755 | - ); | ||
| 1756 | - } | ||
| 1757 | - }; | ||
| 1758 | - for (name, path, seek) in native_gate_clips() { | ||
| 1759 | - let Some((nw, nh)) = probe_dims(&path) else { | ||
| 1760 | - eprintln!("SKIP {name}: ffprobe gave no size"); | ||
| 1761 | - continue; | ||
| 1762 | - }; | ||
| 1763 | - let cw = nw.min(1920) / 128 * 128; | ||
| 1764 | - let ch = nh.min(1024) / 128 * 128; | ||
| 1765 | - let (x, y0) = (((nw - cw) / 2) & !1, ((nh - ch) / 2) & !1); | ||
| 1766 | - let frames = clip_frames_vf( | ||
| 1767 | - &path, | ||
| 1768 | - &seek, | ||
| 1769 | - &format!("crop={cw}:{ch}:{x}:{y0}"), | ||
| 1770 | - cw, | ||
| 1771 | - ch, | ||
| 1772 | - 12, | ||
| 1773 | - ); | ||
| 1774 | - census(&name, &frames, cw, ch); | ||
| 1775 | - // The 640x384 gate scales instead of cropping, and the scaling | ||
| 1776 | - // changes the census (bars smooth out): the constants have to | ||
| 1777 | - // separate at BOTH sizes. | ||
| 1778 | - let small = clip_frames(&path, &seek, 640, 384, 12); | ||
| 1779 | - census(&name, &small, 640, 384); | ||
| 1780 | - } | ||
| 1781 | - } | ||
| 1782 | - | ||
| 1783 | - /// The detector against the WHOLE real library (class | ||
| 1784 | - /// `unswept-decision-constants`, user rule "his data is the gate"): | ||
| 1785 | - /// every VIDEO row of `fixtures/real-library-manifest.tsv` -- plus the | ||
| 1786 | - /// two colour-bar fixtures as anchors -- decoded at 10/50/90% of its | ||
| 1787 | - /// duration, four frames each, 8-bit 4:2:0, at native size or a | ||
| 1788 | - /// 1920x1080 centred crop when larger (the crop keeps a capture's exact | ||
| 1789 | - /// repeats, which a downscale destroys -- class `gate-recipe-confound`). | ||
| 1790 | - /// Prints per file and offset the share of qualifying 16x16 blocks, the | ||
| 1791 | - /// [`screen_content`] verdict and a content hint (mean luma, luma | ||
| 1792 | - /// standard deviation, inter MAD), then sweeps the colour bound against | ||
| 1793 | - /// the variance floor over the whole library: for each (N, V) the worst | ||
| 1794 | - /// (highest) share among the camera/film rows against the best (lowest) | ||
| 1795 | - /// among the screen-recording rows, so the rule with the widest gap can | ||
| 1796 | - /// be read off. Rows carry the manifest index, codec and size only -- | ||
| 1797 | - /// no titles, no home paths. | ||
| 1798 | - /// `cargo test -p ec-av1 --release --lib -- --ignored probe_screen_library --nocapture` | ||
| 1799 | - #[test] | ||
| 1800 | - #[ignore = "reads the real library"] | ||
| 1801 | - fn probe_screen_library() { | ||
| 1802 | - let _knobs = crate::speed::knob_read(); | ||
| 1803 | - if !have_ffmpeg() { | ||
| 1804 | - eprintln!("SKIP probe_screen_library: no ffmpeg"); | ||
| 1805 | - return; | ||
| 1806 | - } | ||
| 1807 | - // lane-av1clipprobe: the crate's one fixture root (EC_FIXTURES first). | ||
| 1808 | - let fixtures = crate::library_fixture::root(); | ||
| 1809 | - let Ok(manifest) = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) | ||
| 1810 | - else { | ||
| 1811 | - eprintln!("SKIP probe_screen_library: no real-library manifest"); | ||
| 1812 | - return; | ||
| 1813 | - }; | ||
| 1814 | - let limits = [4usize, 8, 16, 32, 64]; | ||
| 1815 | - let floors = [0u64, 4, 8, 16, 32, 64, 128]; | ||
| 1816 | - // Whatever ffmpeg gave us, without the exact-count assertion the | ||
| 1817 | - // gate loaders make: a seek near the end of a clip returns fewer | ||
| 1818 | - // frames, and that is a row to print, not a panic. | ||
| 1819 | - let decode = | ||
| 1820 | - |clip: &str, seek: &str, vf: &str, w: usize, h: usize, n: usize| -> Vec<Picture> { | ||
| 1821 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1822 | - .args(["-v", "error", "-ss", seek, "-i", clip]) | ||
| 1823 | - .args(["-frames:v", &n.to_string()]) | ||
| 1824 | - .args(["-vf", vf]) | ||
| 1825 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]), None, |c| c.output()); | ||
| 1826 | - let Ok(out) = out else { return Vec::new() }; | ||
| 1827 | - if !out.status.success() { | ||
| 1828 | - return Vec::new(); | ||
| 1829 | - } | ||
| 1830 | - let (luma, chroma) = (w * h, w * h / 4); | ||
| 1831 | - let frame_len = luma + 2 * chroma; | ||
| 1832 | - (0..out.stdout.len() / frame_len) | ||
| 1833 | - .map(|i| { | ||
| 1834 | - let b = &out.stdout[i * frame_len..][..frame_len]; | ||
| 1835 | - Picture { | ||
| 1836 | - width: w, | ||
| 1837 | - height: h, | ||
| 1838 | - y: b[..luma].iter().map(|&v| u16::from(v)).collect(), | ||
| 1839 | - u: b[luma..luma + chroma] | ||
| 1840 | - .iter() | ||
| 1841 | - .map(|&v| u16::from(v)) | ||
| 1842 | - .collect(), | ||
| 1843 | - v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | ||
| 1844 | - } | ||
| 1845 | - }) | ||
| 1846 | - .collect() | ||
| 1847 | - }; | ||
| 1848 | - // Share (%) of 16x16 blocks with 2..=N colours and per-pixel | ||
| 1849 | - // variance > V, for every (N, V) of the sweep grid, over one frame. | ||
| 1850 | - let census = |y: &[u8], w: usize, h: usize| -> [[f64; 7]; 5] { | ||
| 1851 | - let mut hit = [[0usize; 7]; 5]; | ||
| 1852 | - let mut blocks = 0usize; | ||
| 1853 | - for by in (0..h).step_by(16) { | ||
| 1854 | - for bx in (0..w).step_by(16) { | ||
| 1855 | - let (bh, bw) = ((h - by).min(16), (w - bx).min(16)); | ||
| 1856 | - let mut seen = [false; 256]; | ||
| 1857 | - let (mut colors, mut sum, mut sq) = (0usize, 0u64, 0u64); | ||
| 1858 | - for row in 0..bh { | ||
| 1859 | - for col in 0..bw { | ||
| 1860 | - let v = y[(by + row) * w + bx + col]; | ||
| 1861 | - sum += u64::from(v); | ||
| 1862 | - sq += u64::from(v) * u64::from(v); | ||
| 1863 | - if !seen[usize::from(v)] { | ||
| 1864 | - seen[usize::from(v)] = true; | ||
| 1865 | - colors += 1; | ||
| 1866 | - } | ||
| 1867 | - } | ||
| 1868 | - } | ||
| 1869 | - let n = (bh * bw) as u64; | ||
| 1870 | - let var = (sq - sum * sum / n) / n; | ||
| 1871 | - blocks += 1; | ||
| 1872 | - for (li, &limit) in limits.iter().enumerate() { | ||
| 1873 | - if colors > 1 && colors <= limit { | ||
| 1874 | - for (fi, &floor) in floors.iter().enumerate() { | ||
| 1875 | - hit[li][fi] += usize::from(var > floor); | ||
| 1876 | - } | ||
| 1877 | - } | ||
| 1878 | - } | ||
| 1879 | - } | ||
| 1880 | - } | ||
| 1881 | - let mut out = [[0f64; 7]; 5]; | ||
| 1882 | - for li in 0..5 { | ||
| 1883 | - for fi in 0..7 { | ||
| 1884 | - out[li][fi] = 100.0 * hit[li][fi] as f64 / blocks.max(1) as f64; | ||
| 1885 | - } | ||
| 1886 | - } | ||
| 1887 | - out | ||
| 1888 | - }; | ||
| 1889 | - // (index, label, path, duration, screen-by-its-own-content). The | ||
| 1890 | - // OBS directory and the OBS file-name shape ("YYYY-MM-DD HH-MM-SS") | ||
| 1891 | - // are desktop recordings; everything else in this library is camera | ||
| 1892 | - // or film material. | ||
| 1893 | - let mut rows: Vec<(String, String, String, f64, bool)> = Vec::new(); | ||
| 1894 | - for (label, file) in [ | ||
| 1895 | - ("bars 1080p", "h264-1080p-23.976-8bit.mp4"), | ||
| 1896 | - ("bars 2160p", "h264-2160p-23.976-8bit.mp4"), | ||
| 1897 | - ] { | ||
| 1898 | - let path = fixtures.join("video").join(file); | ||
| 1899 | - if path.exists() { | ||
| 1900 | - rows.push(( | ||
| 1901 | - "fx".into(), | ||
| 1902 | - label.into(), | ||
| 1903 | - path.to_str().unwrap().into(), | ||
| 1904 | - 10.0, | ||
| 1905 | - false, | ||
| 1906 | - )); | ||
| 1907 | - } | ||
| 1908 | - } | ||
| 1909 | - for (i, line) in manifest.lines().skip(1).enumerate() { | ||
| 1910 | - let f: Vec<&str> = line.split('\t').collect(); | ||
| 1911 | - if f.len() < 10 { | ||
| 1912 | - continue; | ||
| 1913 | - } | ||
| 1914 | - let (path, codec) = (f[0], f[2]); | ||
| 1915 | - if codec == "-" || codec.is_empty() { | ||
| 1916 | - continue; | ||
| 1917 | - } | ||
| 1918 | - let (Ok(w), Ok(h)) = (f[3].parse::<usize>(), f[4].parse::<usize>()) else { | ||
| 1919 | - eprintln!("SKIP {}: manifest carries no coded size", i + 1); | ||
| 1920 | - continue; | ||
| 1921 | - }; | ||
| 1922 | - if !std::path::Path::new(path).exists() { | ||
| 1923 | - eprintln!("SKIP {}: file is gone", i + 1); | ||
| 1924 | - continue; | ||
| 1925 | - } | ||
| 1926 | - let name = path.rsplit('/').next().unwrap_or(path); | ||
| 1927 | - let is_capture = path.contains("/OBS/") | ||
| 1928 | - || (name.len() > 19 | ||
| 1929 | - && name.as_bytes()[4] == b'-' | ||
| 1930 | - && name.as_bytes()[7] == b'-' | ||
| 1931 | - && name.as_bytes()[10] == b' ' | ||
| 1932 | - && name.as_bytes()[13] == b'-'); | ||
| 1933 | - rows.push(( | ||
| 1934 | - format!("{}", i + 1), | ||
| 1935 | - format!("{codec} {w}x{h}"), | ||
| 1936 | - path.to_string(), | ||
| 1937 | - f[8].parse::<f64>().unwrap_or(0.0), | ||
| 1938 | - is_capture, | ||
| 1939 | - )); | ||
| 1940 | - } | ||
| 1941 | - // Per (N, V): the worst camera/film row and the best screen row, so | ||
| 1942 | - // the separation of the whole library is one subtraction. | ||
| 1943 | - let (mut cam_max, mut scr_min) = ([[0f64; 7]; 5], [[100f64; 7]; 5]); | ||
| 1944 | - eprintln!( | ||
| 1945 | - "| idx | codec size | class | offset | qualifying blocks | verdict | mean/sd/MAD |" | ||
| 1946 | - ); | ||
| 1947 | - for (idx, label, path, dur, is_capture) in &rows { | ||
| 1948 | - let Some((nw, nh)) = probe_dims(path) else { | ||
| 1949 | - eprintln!("SKIP {idx}: ffprobe gave no size"); | ||
| 1950 | - continue; | ||
| 1951 | - }; | ||
| 1952 | - let (cw, ch) = (nw.min(1920) & !1, nh.min(1080) & !1); | ||
| 1953 | - let (x, y0) = (((nw - cw) / 2) & !1, ((nh - ch) / 2) & !1); | ||
| 1954 | - let vf = format!("crop={cw}:{ch}:{x}:{y0}"); | ||
| 1955 | - let mut file_grid = [[0f64; 7]; 5]; | ||
| 1956 | - let mut file_frames = 0usize; | ||
| 1957 | - for pct in [10u32, 50, 90] { | ||
| 1958 | - let seek = format!("{:.3}", dur * f64::from(pct) / 100.0); | ||
| 1959 | - let frames = decode(path, &seek, &vf, cw, ch, 4); | ||
| 1960 | - if frames.is_empty() { | ||
| 1961 | - eprintln!( | ||
| 1962 | - "| {idx} | {label} | {} | {pct}% | SKIP: ffmpeg decoded no frame here |", | ||
| 1963 | - if *is_capture { "screen" } else { "camera" } | ||
| 1964 | - ); | ||
| 1965 | - continue; | ||
| 1966 | - } | ||
| 1967 | - let (mut share, mut yes, mut mean, mut sd, mut mad) = | ||
| 1968 | - (0f64, 0usize, 0f64, 0f64, 0f64); | ||
| 1969 | - let mut prev: Option<Vec<u8>> = None; | ||
| 1970 | - for picture in &frames { | ||
| 1971 | - let y: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | ||
| 1972 | - let grid = census(&y, cw, ch); | ||
| 1973 | - for li in 0..5 { | ||
| 1974 | - for fi in 0..7 { | ||
| 1975 | - file_grid[li][fi] += grid[li][fi]; | ||
| 1976 | - } | ||
| 1977 | - } | ||
| 1978 | - file_frames += 1; | ||
| 1979 | - // The shipped rule is (16 colours, var > 16): grid row 2, | ||
| 1980 | - // floor 16 is column 3. | ||
| 1981 | - share += grid[2][3]; | ||
| 1982 | - yes += usize::from(screen_content(&y, cw, cw, ch)); | ||
| 1983 | - let n = y.len() as f64; | ||
| 1984 | - let sum: f64 = y.iter().map(|&v| f64::from(v)).sum(); | ||
| 1985 | - let sq: f64 = y.iter().map(|&v| f64::from(v) * f64::from(v)).sum(); | ||
| 1986 | - mean += sum / n; | ||
| 1987 | - sd += (sq / n - (sum / n) * (sum / n)).max(0.0).sqrt(); | ||
| 1988 | - if let Some(p) = &prev { | ||
| 1989 | - mad += p | ||
| 1990 | - .iter() | ||
| 1991 | - .zip(&y) | ||
| 1992 | - .map(|(&a, &b)| f64::from(a.abs_diff(b))) | ||
| 1993 | - .sum::<f64>() | ||
| 1994 | - / n; | ||
| 1995 | - } | ||
| 1996 | - prev = Some(y); | ||
| 1997 | - } | ||
| 1998 | - let f = frames.len() as f64; | ||
| 1999 | - eprintln!( | ||
| 2000 | - "| {idx} | {label} | {} | {pct}% | {:.1}% | {} ({yes}/{} frames) | {:.0}/{:.1}/{:.2} |", | ||
| 2001 | - if *is_capture { "screen" } else { "camera" }, | ||
| 2002 | - share / f, | ||
| 2003 | - if yes * 2 > frames.len() { | ||
| 2004 | - "SCREEN" | ||
| 2005 | - } else { | ||
| 2006 | - "camera" | ||
| 2007 | - }, | ||
| 2008 | - frames.len(), | ||
| 2009 | - mean / f, | ||
| 2010 | - sd / f, | ||
| 2011 | - mad / (f - 1.0).max(1.0), | ||
| 2012 | - ); | ||
| 2013 | - } | ||
| 2014 | - if file_frames == 0 { | ||
| 2015 | - continue; | ||
| 2016 | - } | ||
| 2017 | - for li in 0..5 { | ||
| 2018 | - for fi in 0..7 { | ||
| 2019 | - let s = file_grid[li][fi] / file_frames as f64; | ||
| 2020 | - match is_capture { | ||
| 2021 | - true => scr_min[li][fi] = scr_min[li][fi].min(s), | ||
| 2022 | - false => cam_max[li][fi] = cam_max[li][fi].max(s), | ||
| 2023 | - } | ||
| 2024 | - } | ||
| 2025 | - } | ||
| 2026 | - } | ||
| 2027 | - eprintln!( | ||
| 2028 | - "sweep over the whole library -- worst camera/film share vs best screen share, per (N colours, var > V):" | ||
| 2029 | - ); | ||
| 2030 | - eprintln!( | ||
| 2031 | - " N \\ V |{}", | ||
| 2032 | - floors | ||
| 2033 | - .iter() | ||
| 2034 | - .map(|f| format!("{:>18}", format!("V>{f}"))) | ||
| 2035 | - .collect::<String>() | ||
| 2036 | - ); | ||
| 2037 | - let (mut best, mut best_rule) = (f64::MIN, (16usize, 16u64)); | ||
| 2038 | - for (li, &limit) in limits.iter().enumerate() { | ||
| 2039 | - let mut row = String::new(); | ||
| 2040 | - for fi in 0..7 { | ||
| 2041 | - let (c, s) = (cam_max[li][fi], scr_min[li][fi]); | ||
| 2042 | - row.push_str(&format!("{:>18}", format!("{c:.1}/{s:.1} {:+.1}", s - c))); | ||
| 2043 | - if s - c > best { | ||
| 2044 | - best = s - c; | ||
| 2045 | - best_rule = (limit, floors[fi]); | ||
| 2046 | - } | ||
| 2047 | - } | ||
| 2048 | - eprintln!(" {limit:>5} |{row}"); | ||
| 2049 | - } | ||
| 2050 | - // The threshold sits at the midpoint of the widest gap; the shipped | ||
| 2051 | - // constant is its reciprocal in whole parts of the frame. | ||
| 2052 | - let (li, fi) = ( | ||
| 2053 | - limits.iter().position(|&l| l == best_rule.0).unwrap(), | ||
| 2054 | - floors.iter().position(|&f| f == best_rule.1).unwrap(), | ||
| 2055 | - ); | ||
| 2056 | - let mid = (cam_max[li][fi] + scr_min[li][fi]) / 2.0; | ||
| 2057 | - eprintln!( | ||
| 2058 | - "widest split: {} colours, var > {}, gap {:+.1} points (camera <= {:.1}%, screen >= {:.1}%); threshold {:.1}% = EC_AV1_SCREEN_PCT {}", | ||
| 2059 | - best_rule.0, | ||
| 2060 | - best_rule.1, | ||
| 2061 | - best, | ||
| 2062 | - cam_max[li][fi], | ||
| 2063 | - scr_min[li][fi], | ||
| 2064 | - mid, | ||
| 2065 | - (100.0 / mid.max(0.1)).round() as usize, | ||
| 2066 | - ); | ||
| 2067 | - } | ||
| 2068 | - | ||
| 2069 | - /// The missing instrument: what this encoder costs against libaom and | ||
| 2070 | - /// rav1e at matched fidelity, and how long it takes to get there. | ||
| 2071 | - /// | ||
| 2072 | - /// Recipe, identical on all three sides: 12 consecutive frames of each | ||
| 2073 | - /// clip scaled to 640x384 (a whole number of superblocks), one key frame | ||
| 2074 | - /// then 11 inter frames (`-g 12`, matching our own sequence shape), one | ||
| 2075 | - /// tile, `-threads 1`, no film grain synthesis (neither reference enables | ||
| 2076 | - /// it by default), 4:2:0 8-bit in and out. Reference points: | ||
| 2077 | - /// libaom-av1: `-cpu-used 6 -b:v 0 -crf {5,20,35,45}` | ||
| 2078 | - /// librav1e: `-rav1e-params speed=6:quantizer={50,100,150,200}: | ||
| 2079 | - /// tile_cols=1:tile_rows=1:threads=1` | ||
| 2080 | - /// ours: `base_q_idx {60,90,120,150}`. Every PSNR is all-plane, on | ||
| 2081 | - /// ffmpeg-decoded frames of each encoder's own stream. | ||
| 2082 | - /// | ||
| 2083 | - /// Measured 2026-09-06 after the in-loop filters (lane-av1filt: per-frame | ||
| 2084 | - /// deblocking levels and CDEF strengths, both chosen by re-decoding the | ||
| 2085 | - /// coded tile -- `crate::filter_search`), 12 frames, this box (wall = the | ||
| 2086 | - /// four encodes of that ladder together): | ||
| 2087 | - /// | ||
| 2088 | - /// | clip | ours (q 150/120/90/60) | BD-rate vs libaom | vs rav1e | wall ours:aom:rav1e | | ||
| 2089 | - /// |---|---|---|---|---| | ||
| 2090 | - /// | 1080p fixture | 42.11 dB/17774 B .. 50.99 dB/76838 B | +143.6% | +94.0% | 9.2s:1.1s:2.6s | | ||
| 2091 | - /// | 2160p fixture | 42.84 dB/12480 B .. 51.43 dB/46557 B | +179.5% | +128.8% | 8.6s:1.0s:2.2s | | ||
| 2092 | - /// | screen capture | 39.76 dB/9536 B .. 48.87 dB/29189 B | +88.0% | +21.5% | 7.2s:1.0s:2.1s | | ||
| 2093 | - /// | ||
| 2094 | - /// Re-measured 2026-09-06 after lane-av1fwd, which changed only how long | ||
| 2095 | - /// the encoder takes -- every stream it writes is byte-identical, so the | ||
| 2096 | - /// BD columns are this box's own re-run of the same recipe rather than a | ||
| 2097 | - /// quality move (+141.3/+174.2/+88.9 vs libaom, +91.9/+124.5/+21.6 vs | ||
| 2098 | - /// rav1e). What moved is the wall of the four encodes: | ||
| 2099 | - /// | ||
| 2100 | - /// | clip | wall ours before | after | instructions:u before -> after | | ||
| 2101 | - /// |---|---|---|---| | ||
| 2102 | - /// | 1080p fixture | 9.2s | 7.2s | 191.5G -> 139.8G (-27.0%) | | ||
| 2103 | - /// | 2160p fixture | 8.6s | 6.9s | 183.5G -> 136.4G (-25.6%) | | ||
| 2104 | - /// | screen capture | 7.2s | 6.7s | 157.2G -> 122.5G (-22.1%) | | ||
| 2105 | - /// | ||
| 2106 | - /// Three exact steps, none of which touches a coded bit: the coefficient | ||
| 2107 | - /// rate pricer stopped rebuilding every CDF table per candidate | ||
| 2108 | - /// (`tile::coeff_bits`), the filter search stopped re-decoding its own | ||
| 2109 | - /// tile once per candidate (`decode::FilterReplay`), and the forward | ||
| 2110 | - /// transform stopped transforming the all-zero residual that 70% of its | ||
| 2111 | - /// calls carry. | ||
| 2112 | - /// | ||
| 2113 | - /// The three steps of that lane, same recipe (vs libaom, then vs rav1e): | ||
| 2114 | - /// | ||
| 2115 | - /// | step | 1080p | 2160p | screen | | ||
| 2116 | - /// |---|---|---|---| | ||
| 2117 | - /// | no in-loop filter | +234.0 / +171.9 | +260.3 / +203.2 | +318.5 / +155.3 | | ||
| 2118 | - /// | + deblocking | +198.2 / +143.1 | +218.1 / +162.4 | +136.9 / +52.7 | | ||
| 2119 | - /// | + CDEF | +143.6 / +94.0 | +179.5 / +128.8 | +88.0 / +21.5 | | ||
| 2120 | - /// | ||
| 2121 | - /// Re-measured for the record 2026-09-07 (lane-av1resweep), after | ||
| 2122 | - /// [`LAMBDA_SCALE`] moved 0.05 -> 0.0275 and the two var-tx depth | ||
| 2123 | - /// searches ([`tx32_depth_search`], [`compound_var_tx`]) became defaults | ||
| 2124 | - /// -- all three decided on the REAL film rows of | ||
| 2125 | - /// [`bd_rate_screen_native`], which this downscaled recipe does not | ||
| 2126 | - /// carry: | ||
| 2127 | - /// | ||
| 2128 | - /// | clip | BD vs libaom | BD vs rav1e | wall ours:libaom:rav1e | | ||
| 2129 | - /// |---|---|---|---| | ||
| 2130 | - /// | bars 1080p | +68.8% | +26.2% | 5.8s:1.2s:2.7s | | ||
| 2131 | - /// | bars 2160p | +81.6% | +41.5% | 4.8s:1.0s:2.2s | | ||
| 2132 | - /// | screen capture | +49.1% | -4.3% | 5.5s:1.0s:2.1s | | ||
| 2133 | - /// | ||
| 2134 | - /// RE-RECORDED 2026-09-07 (lane-av1pyrdef), with the coding pyramid the | ||
| 2135 | - /// DEFAULT of the sequence path this gate codes through -- the bars are | ||
| 2136 | - /// non-screen so they take it, the capture is gated flat: | ||
| 2137 | - /// | ||
| 2138 | - /// | clip | effective pyramid | BD vs libaom | BD vs rav1e | wall | | ||
| 2139 | - /// |---|---|---|---|---| | ||
| 2140 | - /// | bars 1080p | 4:-16:8 | +84.7% | +39.9% | 5.1s:1.1s:2.6s | | ||
| 2141 | - /// | bars 2160p | 4:-16:8 | +124.4% | +75.2% | 4.4s:1.0s:2.8s | | ||
| 2142 | - /// | screen capture | none (gated) | +49.1% | -4.3% | 6.5s:1.2s:2.3s | | ||
| 2143 | - /// | ||
| 2144 | - /// Those are, to the byte, the numbers lane-av1pyrgate recorded for the | ||
| 2145 | - /// same clips under `EC_AV1_PYRAMID=4:-16:8 EC_AV1_GATE_FACADE=1` -- the | ||
| 2146 | - /// facade arm -- which is what "one mini-GOP driver, two entry points" | ||
| 2147 | - /// means here. This downscaled recipe HATES the pyramid (as it hates | ||
| 2148 | - /// every knob the real film rows of `bd_rate_screen_native` keep, which | ||
| 2149 | - /// is why it decides nothing); `EC_AV1_PYRAMID=0` restores the flat rows | ||
| 2150 | - /// above. The capture's row is the flat row to the byte in both runs -- | ||
| 2151 | - /// that equality IS the content gate. | ||
| 2152 | - /// | ||
| 2153 | - /// Loop restoration is NOT in yet: it is the one filter whose parameters | ||
| 2154 | - /// are per restoration UNIT inside the tile payload, so it needs both | ||
| 2155 | - /// tile writers to code `lr` syntax and an encoder-visible post-CDEF | ||
| 2156 | - /// buffer to solve against -- neither of which this frame-header-level | ||
| 2157 | - /// search reaches. | ||
| 2158 | - /// | ||
| 2159 | - /// The baseline it replaced, before an inter frame's blocks chose their | ||
| 2160 | - /// own partition, was +501.4/+504.4/+440.9 against libaom and | ||
| 2161 | - /// +364.4/+401.0/+206.0 against rav1e at 5.1/4.6/5.9 s. | ||
| 2162 | - /// | ||
| 2163 | - /// So: roughly 2.5-3x libaom's rate and 1.5-2x rav1e's at matched | ||
| 2164 | - /// fidelity, while spending far more time than either (the partition | ||
| 2165 | - /// search's own cost, uncut: see the two intra-pruning variants measured | ||
| 2166 | - /// and rejected in the lane report). No | ||
| 2167 | - /// threshold is asserted yet -- this run sets the baseline; the gate | ||
| 2168 | - /// asserts four monotone points per ladder, and at EVERY ladder point of | ||
| 2169 | - /// EVERY clip it decodes our stream twice -- with ffmpeg and with our own | ||
| 2170 | - /// `crate::stream::decode_stream` -- and asserts the encoder's | ||
| 2171 | - /// reconstruction, ffmpeg's decode and our decode sample-exact in Y, U | ||
| 2172 | - /// and V over every shown frame in display order. A failure names the | ||
| 2173 | - /// clip, the q, the frame, the plane and the first differing sample. | ||
| 2174 | - /// (Under `EC_AV1_PYRAMID` the frames come out of the streaming facade, | ||
| 2175 | - /// which exposes no per-packet reconstruction, so that path asserts the | ||
| 2176 | - /// two decoders against each other on all three planes.) | ||
| 2177 | - /// | ||
| 2178 | - /// Run: | ||
| 2179 | - /// cargo test -p ec-av1 --release --lib -- --ignored \ | ||
| 2180 | - /// bd_rate_vs_libaom_and_rav1e --nocapture | ||
| 2181 | - #[test] | ||
| 2182 | - #[ignore = "the encoder BD-rate baseline: minutes per clip, needs ffmpeg"] | ||
| 2183 | - fn bd_rate_vs_libaom_and_rav1e() { | ||
| 2184 | - let _knobs = crate::speed::knob_write(); | ||
| 2185 | - if !have_ffmpeg() { | ||
| 2186 | - eprintln!("SKIP bd_rate_vs_libaom_and_rav1e: no ffmpeg"); | ||
| 2187 | - return; | ||
| 2188 | - } | ||
| 2189 | - // lane-av1clipprobe: the crate's one fixture root (EC_FIXTURES first). | ||
| 2190 | - let fixtures = crate::library_fixture::root(); | ||
| 2191 | - let mut clips: Vec<(String, std::path::PathBuf)> = Vec::new(); | ||
| 2192 | - // testsrc2 COLOUR BARS, not film -- labelled so no reader takes these | ||
| 2193 | - // rows for real content (the real rows live in the native gate). | ||
| 2194 | - for (label, name) in [ | ||
| 2195 | - ("bars 1080p", "h264-1080p-23.976-8bit.mp4"), | ||
| 2196 | - ("bars 2160p", "h264-2160p-23.976-8bit.mp4"), | ||
| 2197 | - ] { | ||
| 2198 | - // lane-av1clipprobe: the one probe, so a missing clip is RED under | ||
| 2199 | - // the require envs instead of a drop-with-no-escape. | ||
| 2200 | - if let Some(path) = crate::library_fixture::require( | ||
| 2201 | - &format!("video/{name}"), | ||
| 2202 | - &format!("bd_rate_vs_libaom_and_rav1e: {label}"), | ||
| 2203 | - ) { | ||
| 2204 | - clips.push((label.to_string(), path)); | ||
| 2205 | - } | ||
| 2206 | - } | ||
| 2207 | - // Screen capture: the repo carries no screen-capture fixture, so take | ||
| 2208 | - // the first OBS recording the real-library manifest names. | ||
| 2209 | - match std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) { | ||
| 2210 | - Ok(manifest) => { | ||
| 2211 | - let screen = manifest | ||
| 2212 | - .lines() | ||
| 2213 | - .skip(1) | ||
| 2214 | - .filter_map(|l| l.split('\t').next()) | ||
| 2215 | - .find(|p| { | ||
| 2216 | - p.contains("/OBS/") | ||
| 2217 | - && p.ends_with(".mkv") | ||
| 2218 | - && std::path::Path::new(p).exists() | ||
| 2219 | - }); | ||
| 2220 | - match screen { | ||
| 2221 | - Some(p) => clips.push(( | ||
| 2222 | - format!("screen capture ({})", p.rsplit('/').next().unwrap_or(p)), | ||
| 2223 | - std::path::PathBuf::from(p), | ||
| 2224 | - )), | ||
| 2225 | - None => { | ||
| 2226 | - eprintln!("SKIP screen capture: no OBS recording in the manifest exists") | ||
| 2227 | - } | ||
| 2228 | - } | ||
| 2229 | - } | ||
| 2230 | - Err(e) => eprintln!("SKIP screen capture: no real-library manifest ({e})"), | ||
| 2231 | - } | ||
| 2232 | - assert!(!clips.is_empty(), "no source clip available"); | ||
| 2233 | - | ||
| 2234 | - let (width, height, frames) = (640usize, 384usize, 12usize); | ||
| 2235 | - let aom_points: Vec<Vec<String>> = [5, 20, 35, 45] | ||
| 2236 | - .iter() | ||
| 2237 | - .map(|q| { | ||
| 2238 | - ["-cpu-used", "6", "-b:v", "0", "-crf", &q.to_string()] | ||
| 2239 | - .map(String::from) | ||
| 2240 | - .to_vec() | ||
| 2241 | - }) | ||
| 2242 | - .collect(); | ||
| 2243 | - let rav1e_points: Vec<Vec<String>> = [50, 100, 150, 200] | ||
| 2244 | - .iter() | ||
| 2245 | - .map(|q| { | ||
| 2246 | - vec![ | ||
| 2247 | - "-rav1e-params".to_string(), | ||
| 2248 | - format!("speed=6:quantizer={q}:tile_cols=1:tile_rows=1:threads=1"), | ||
| 2249 | - ] | ||
| 2250 | - }) | ||
| 2251 | - .collect(); | ||
| 2252 | - println!( | ||
| 2253 | - "\n{frames} frames of each clip at {width}x{height}, gop={frames}, 1 tile, 1 thread" | ||
| 2254 | - ); | ||
| 2255 | - println!( | ||
| 2256 | - "| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e |" | ||
| 2257 | - ); | ||
| 2258 | - println!("|---|---|---|---|---|"); | ||
| 2259 | - for (name, path) in &clips { | ||
| 2260 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 2261 | - let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); | ||
| 2262 | - let _ = take_partition_hits(); | ||
| 2263 | - let _ = crate::tile::take_palette_hits(); | ||
| 2264 | - SCREEN_FRAMES.iter().for_each(|c| { | ||
| 2265 | - c.store(0, std::sync::atomic::Ordering::Relaxed); | ||
| 2266 | - }); | ||
| 2267 | - let _ = take_uv_mode_hits(); | ||
| 2268 | - let _ = crate::tile::take_inter_mode_hits(); | ||
| 2269 | - let _ = crate::tile::take_drl_hits(); | ||
| 2270 | - let _ = crate::tile::take_ref_hits(); | ||
| 2271 | - let _ = crate::tile::take_compound_mode_hits(); | ||
| 2272 | - let _ = crate::tile::take_compound_pair_hits(); | ||
| 2273 | - let _ = crate::tile::take_compound_size_hits(); | ||
| 2274 | - let _ = crate::tile::take_compound_leaf_mode_hits(); | ||
| 2275 | - let _ = take_b64_root_hits(); | ||
| 2276 | - let _ = take_b64_residual_hits(); | ||
| 2277 | - let _ = take_b64_compound_hits(); | ||
| 2278 | - let _ = crate::motion::take_census(); | ||
| 2279 | - // The entry-surface arm: run the SAME ladder through the | ||
| 2280 | - // streaming facade the editor's export calls, which must print | ||
| 2281 | - // the same BD numbers as the sequence path -- byte for byte the | ||
| 2282 | - // same stream now that both drive one mini-GOP driver | ||
| 2283 | - // (lane-av1pyrdef). | ||
| 2284 | - let facade = std::env::var_os("EC_AV1_GATE_FACADE").is_some(); | ||
| 2285 | - let (ours, ours_wall) = match facade { | ||
| 2286 | - false => our_ladder(name, &source, width, height, fctx), | ||
| 2287 | - true => { | ||
| 2288 | - let pyramid = crate::encoder::Pyramid::from_env(); | ||
| 2289 | - let (ladder, wall, counts, bytes, effective) = | ||
| 2290 | - our_ladder_facade(name, &source, width, height, pyramid); | ||
| 2291 | - eprintln!( | ||
| 2292 | - "{name}: facade, pyramid requested {pyramid:?} effective \ | ||
| 2293 | - {effective:?} -- frames key {} arf {} leaf {} \ | ||
| 2294 | - show_existing {}; bytes key {} arf {} leaf {} show_existing {}", | ||
| 2295 | - counts[0], | ||
| 2296 | - counts[1], | ||
| 2297 | - counts[2], | ||
| 2298 | - counts[3], | ||
| 2299 | - bytes[0], | ||
| 2300 | - bytes[1], | ||
| 2301 | - bytes[2], | ||
| 2302 | - bytes[3], | ||
| 2303 | - ); | ||
| 2304 | - (ladder, wall) | ||
| 2305 | - } | ||
| 2306 | - }; | ||
| 2307 | - // How often the inter split actually fired over this clip's four | ||
| 2308 | - // encodes, against the whole 32x32 that was the only outcome | ||
| 2309 | - // before (gate-blind-to-feature). | ||
| 2310 | - let [whole32, split32, whole16, split16] = take_partition_hits(); | ||
| 2311 | - // Which inter modes actually fired over this clip's four encodes, | ||
| 2312 | - // and at which DRL index -- a mode nobody picks is a mode the BD | ||
| 2313 | - // number cannot be crediting (gate-blind-to-feature). | ||
| 2314 | - let [nearest, near, global, new] = crate::tile::take_inter_mode_hits(); | ||
| 2315 | - let [drl0, drl1, drl2, drl3] = crate::tile::take_drl_hits(); | ||
| 2316 | - let refs = crate::tile::take_ref_hits(); | ||
| 2317 | - let modes_total = (nearest + near + global + new).max(1); | ||
| 2318 | - eprintln!( | ||
| 2319 | - "{name}: inter modes NEAREST {nearest} ({:.1}%) NEAR {near} ({:.1}%) \ | ||
| 2320 | - GLOBAL {global} ({:.1}%) NEW {new} ({:.1}%); drl idx 0/1/2/3+ \ | ||
| 2321 | - {drl0}/{drl1}/{drl2}/{drl3}", | ||
| 2322 | - 100.0 * nearest as f64 / modes_total as f64, | ||
| 2323 | - 100.0 * near as f64 / modes_total as f64, | ||
| 2324 | - 100.0 * global as f64 / modes_total as f64, | ||
| 2325 | - 100.0 * new as f64 / modes_total as f64, | ||
| 2326 | - ); | ||
| 2327 | - // The compound census: what share of the coded inter blocks took | ||
| 2328 | - // a compound reference at all, which compound mode they took, and | ||
| 2329 | - // which pair (gate-blind-to-feature -- a compound mode nobody | ||
| 2330 | - // picks cannot be what a BD number credits). | ||
| 2331 | - // The 64x64 root's own fire shares (lane-b64/tx64/b64b): how many | ||
| 2332 | - // superblocks were left whole at all, and how many of those coded | ||
| 2333 | - // a residual or took a compound reference. | ||
| 2334 | - let (roots, root_res, root_comp) = ( | ||
| 2335 | - take_b64_root_hits(), | ||
| 2336 | - take_b64_residual_hits(), | ||
| 2337 | - take_b64_compound_hits(), | ||
| 2338 | - ); | ||
| 2339 | - eprintln!( | ||
| 2340 | - "{name}: 64x64 roots {roots} (with a residual {root_res}, compound {root_comp})" | ||
| 2341 | - ); | ||
| 2342 | - let comp_modes = crate::tile::take_compound_mode_hits(); | ||
| 2343 | - let comp_pairs = crate::tile::take_compound_pair_hits(); | ||
| 2344 | - let comp_sizes = crate::tile::take_compound_size_hits(); | ||
| 2345 | - let comp_leaf = crate::tile::take_compound_leaf_mode_hits(); | ||
| 2346 | - let comp_total: usize = comp_modes.iter().sum(); | ||
| 2347 | - eprintln!( | ||
| 2348 | - "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \ | ||
| 2349 | - NEAREST_NEAREST {} NEAR_NEAR {} NEAREST_NEW {} NEW_NEAREST {} \ | ||
| 2350 | - GLOBAL_GLOBAL {} NEW_NEW {}; pairs LAST+GOLDEN {} LAST+ALTREF {}", | ||
| 2351 | - modes_total + comp_total, | ||
| 2352 | - 100.0 * comp_total as f64 / (modes_total + comp_total) as f64, | ||
| 2353 | - comp_modes[0], | ||
| 2354 | - comp_modes[1], | ||
| 2355 | - comp_modes[2], | ||
| 2356 | - comp_modes[3], | ||
| 2357 | - comp_modes[6], | ||
| 2358 | - comp_modes[7], | ||
| 2359 | - comp_pairs[3], | ||
| 2360 | - comp_pairs[6], | ||
| 2361 | - ); | ||
| 2362 | - eprintln!( | ||
| 2363 | - "{name}: leaf (16x16 and below) compound modes NEAREST_NEAREST {} \ | ||
| 2364 | - NEAR_NEAR {} NEAREST_NEW {} NEW_NEAREST {} GLOBAL_GLOBAL {} NEW_NEW {}", | ||
| 2365 | - comp_leaf[0], comp_leaf[1], comp_leaf[2], comp_leaf[3], comp_leaf[6], comp_leaf[7], | ||
| 2366 | - ); | ||
| 2367 | - eprintln!( | ||
| 2368 | - "{name}: compound by size 8x8 {} 16x16 {} 32x32 {}", | ||
| 2369 | - comp_sizes[1], comp_sizes[2], comp_sizes[3], | ||
| 2370 | - ); | ||
| 2371 | - // Where the wall-owning stage actually goes: how many candidate | ||
| 2372 | - // evaluations (one `mc::predict` + SAD each) a search spends, how | ||
| 2373 | - // many of them are subpel, and how often the winner is the seed | ||
| 2374 | - // it started from -- the census the seeded search is judged by. | ||
| 2375 | - let [ | ||
| 2376 | - calls, | ||
| 2377 | - evals, | ||
| 2378 | - subpel, | ||
| 2379 | - rounds, | ||
| 2380 | - near_pred, | ||
| 2381 | - unmoved, | ||
| 2382 | - widest, | ||
| 2383 | - widest_moves, | ||
| 2384 | - ] = crate::motion::take_census(); | ||
| 2385 | - let per = |n: u64| n as f64 / calls.max(1) as f64; | ||
| 2386 | - eprintln!( | ||
| 2387 | - "{name}: motion search {calls} calls, {evals} candidate evals ({:.1}/call, \ | ||
| 2388 | - {:.1}% of them subpel), {rounds} integer rounds ({:.2}/call); winner within \ | ||
| 2389 | - +-1 pel of pred_mv {:.1}%, winner = starting seed {:.1}%", | ||
| 2390 | - per(evals), | ||
| 2391 | - 100.0 * subpel as f64 / evals.max(1) as f64, | ||
| 2392 | - per(rounds), | ||
| 2393 | - 100.0 * near_pred as f64 / calls.max(1) as f64, | ||
| 2394 | - 100.0 * unmoved as f64 / calls.max(1) as f64, | ||
| 2395 | - ); | ||
| 2396 | - // lane-newmv, class `instrument at bound`: how often the winner | ||
| 2397 | - // was walked to at the log stage's own WIDEST step -- a high | ||
| 2398 | - // share means the search stops where its step lets it, not where | ||
| 2399 | - // the content is. | ||
| 2400 | - eprintln!( | ||
| 2401 | - "{name}: motion search moved at the widest step in {:.1}% of calls ({:.2} such moves/call)", | ||
| 2402 | - 100.0 * widest as f64 / calls.max(1) as f64, | ||
| 2403 | - per(widest_moves), | ||
| 2404 | - ); | ||
| 2405 | - eprintln!( | ||
| 2406 | - "{name}: references LAST {} GOLDEN {} (LAST2 {} LAST3 {} BWD {} ALT2 {} ALT {})", | ||
| 2407 | - refs[0], refs[3], refs[1], refs[2], refs[4], refs[5], refs[6] | ||
| 2408 | - ); | ||
| 2409 | - eprintln!( | ||
| 2410 | - "{name}: inter 32x32 split into 16s {split32} of {} blocks ({:.1}%); \ | ||
| 2411 | - 16x16 leaves split into 8s {split16} of {} ({:.1}%)", | ||
| 2412 | - whole32 + split32, | ||
| 2413 | - 100.0 * split32 as f64 / (whole32 + split32).max(1) as f64, | ||
| 2414 | - whole16 + split16, | ||
| 2415 | - 100.0 * split16 as f64 / (whole16 + split16).max(1) as f64 | ||
| 2416 | - ); | ||
| 2417 | - // The deblocking level each of this clip's frames chose | ||
| 2418 | - // (lane-av1filt): 0 everywhere would mean the filter never fires. | ||
| 2419 | - let levels = crate::filter_search::take_chosen_levels(); | ||
| 2420 | - type Chosen = ((u8, u8), (u8, u8), (u8, u8)); | ||
| 2421 | - let mean = |f: fn(&Chosen) -> u8| { | ||
| 2422 | - levels.iter().map(|l| f(l) as f64).sum::<f64>() / levels.len().max(1) as f64 | ||
| 2423 | - }; | ||
| 2424 | - eprintln!( | ||
| 2425 | - "{name}: over {} frames -- deblock luma mean {:.1} chroma {:.1}; \ | ||
| 2426 | - cdef luma pri {:.1}/sec {:.1}, chroma pri {:.1}/sec {:.1}", | ||
| 2427 | - levels.len(), | ||
| 2428 | - mean(|l| l.0.0), | ||
| 2429 | - mean(|l| l.0.1), | ||
| 2430 | - mean(|l| l.1.0), | ||
| 2431 | - mean(|l| l.1.1), | ||
| 2432 | - mean(|l| l.2.0), | ||
| 2433 | - mean(|l| l.2.1), | ||
| 2434 | - ); | ||
| 2435 | - // How many strength presets each frame's CDEF list carried and | ||
| 2436 | - // how the 64x64 units spread over them (lane-av1lr): `bits 0` | ||
| 2437 | - // everywhere would mean the per-unit choice never fires. | ||
| 2438 | - let presets = crate::filter_search::take_cdef_presets(); | ||
| 2439 | - let mut by_bits = [0usize; 4]; | ||
| 2440 | - for (b, _) in &presets { | ||
| 2441 | - by_bits[usize::from(*b)] += 1; | ||
| 2442 | - } | ||
| 2443 | - let units: usize = presets.iter().flat_map(|(_, c)| c).sum(); | ||
| 2444 | - let on_extra: usize = presets.iter().flat_map(|(_, c)| c.iter().skip(1)).sum(); | ||
| 2445 | - eprintln!( | ||
| 2446 | - "{name}: cdef_bits frames {}/{}/{}/{} (0/1/2/3); {} of {} 64x64 units \ | ||
| 2447 | - on a non-default preset ({:.1}%)", | ||
| 2448 | - by_bits[0], | ||
| 2449 | - by_bits[1], | ||
| 2450 | - by_bits[2], | ||
| 2451 | - by_bits[3], | ||
| 2452 | - on_extra, | ||
| 2453 | - units, | ||
| 2454 | - 100.0 * on_extra as f64 / units.max(1) as f64 | ||
| 2455 | - ); | ||
| 2456 | - // How the 64x64 luma restoration units split between | ||
| 2457 | - // RESTORE_NONE and Wiener (lane-av1lr). | ||
| 2458 | - let (lr_none, lr_wiener) = crate::filter_search::take_lr_histogram(); | ||
| 2459 | - eprintln!( | ||
| 2460 | - "{name}: lr units none={lr_none} wiener={lr_wiener} ({:.1}% restored)", | ||
| 2461 | - 100.0 * lr_wiener as f64 / (lr_none + lr_wiener).max(1) as f64 | ||
| 2462 | - ); | ||
| 2463 | - // Which chroma modes the search actually wins with, against the | ||
| 2464 | - // unconditional DC_PRED that was the only outcome before | ||
| 2465 | - // (gate-blind-to-feature). | ||
| 2466 | - // Screen-content detection and the palette it turns on | ||
| 2467 | - // (gate-blind-to-feature): how many frames set | ||
| 2468 | - // `allow_screen_content_tools`, how many blocks took a palette, | ||
| 2469 | - // and of what size. A film clip must print `screen frames on=0`. | ||
| 2470 | - let screen_on = SCREEN_FRAMES[1].load(std::sync::atomic::Ordering::Relaxed); | ||
| 2471 | - let screen_off = SCREEN_FRAMES[0].load(std::sync::atomic::Ordering::Relaxed); | ||
| 2472 | - // Which tables the SEARCH priced against, per frame arming | ||
| 2473 | - // (`tile::arm_pricing_cdfs`): the default tables or the frame's | ||
| 2474 | - // real starting ones. A film clip must show every inter arming on | ||
| 2475 | - // the real side, a screen clip none of them. | ||
| 2476 | - let (price_default, price_real) = crate::tile::take_pricing_hits(); | ||
| 2477 | - eprintln!("{name}: pricer armings default={price_default} real={price_real}"); | ||
| 2478 | - let palette = crate::tile::take_palette_hits(); | ||
| 2479 | - eprintln!( | ||
| 2480 | - "{name}: screen frames on={screen_on} off={screen_off}; palette blocks {} sizes {}", | ||
| 2481 | - palette[0], | ||
| 2482 | - (2..=8) | ||
| 2483 | - .filter(|&n| palette[n] > 0) | ||
| 2484 | - .map(|n| format!("{n}={}", palette[n])) | ||
| 2485 | - .collect::<Vec<_>>() | ||
| 2486 | - .join(" ") | ||
| 2487 | - ); | ||
| 2488 | - // The CfL alpha histogram (lane-av1cfl): one entry per chroma | ||
| 2489 | - // plane of every `UV_CFL_PRED` block, by |alpha_q3|. A tool that | ||
| 2490 | - // only ever fires at one magnitude is a search that never left | ||
| 2491 | - // its first candidate (gate-blind-to-feature). | ||
| 2492 | - // The luma angle-delta histogram (lane-av1cfl): how many | ||
| 2493 | - // directional blocks won at each delta. All-zero would mean the | ||
| 2494 | - // refinement never beat the base angle. | ||
| 2495 | - let deltas = take_angle_delta_hits(); | ||
| 2496 | - if deltas.iter().sum::<usize>() > 0 { | ||
| 2497 | - eprintln!( | ||
| 2498 | - "{name}: angle_delta_y {}", | ||
| 2499 | - deltas | ||
| 2500 | - .iter() | ||
| 2501 | - .enumerate() | ||
| 2502 | - .map(|(d, &n)| format!("{:+}={n}", d as i32 - 3)) | ||
| 2503 | - .collect::<Vec<_>>() | ||
| 2504 | - .join(" ") | ||
| 2505 | - ); | ||
| 2506 | - } | ||
| 2507 | - let alphas = take_cfl_alpha_hits(); | ||
| 2508 | - if alphas.iter().sum::<usize>() > 0 { | ||
| 2509 | - eprintln!( | ||
| 2510 | - "{name}: cfl |alpha| {}", | ||
| 2511 | - alphas | ||
| 2512 | - .iter() | ||
| 2513 | - .enumerate() | ||
| 2514 | - .filter(|&(_, &n)| n > 0) | ||
| 2515 | - .map(|(a, &n)| format!("{a}={n}")) | ||
| 2516 | - .collect::<Vec<_>>() | ||
| 2517 | - .join(" ") | ||
| 2518 | - ); | ||
| 2519 | - } | ||
| 2520 | - let palette_uv = crate::tile::take_palette_uv_hits(); | ||
| 2521 | - eprintln!( | ||
| 2522 | - "{name}: chroma palette blocks {} sizes {}", | ||
| 2523 | - palette_uv[0], | ||
| 2524 | - (2..=8) | ||
| 2525 | - .filter(|&n| palette_uv[n] > 0) | ||
| 2526 | - .map(|n| format!("{n}={}", palette_uv[n])) | ||
| 2527 | - .collect::<Vec<_>>() | ||
| 2528 | - .join(" ") | ||
| 2529 | - ); | ||
| 2530 | - let uv = take_uv_mode_hits(); | ||
| 2531 | - let uv_total: usize = uv.iter().sum(); | ||
| 2532 | - eprintln!( | ||
| 2533 | - "{name}: uv modes {}", | ||
| 2534 | - uv.iter() | ||
| 2535 | - .enumerate() | ||
| 2536 | - .filter(|&(_, &n)| n > 0) | ||
| 2537 | - .map(|(m, &n)| format!( | ||
| 2538 | - "{}={n} ({:.1}%)", | ||
| 2539 | - UV_MODE_NAMES[m], | ||
| 2540 | - 100.0 * n as f64 / uv_total.max(1) as f64 | ||
| 2541 | - )) | ||
| 2542 | - .collect::<Vec<_>>() | ||
| 2543 | - .join(" ") | ||
| 2544 | - ); | ||
| 2545 | - // Which transform depth the intra blocks of this clip's key | ||
| 2546 | - // frames resolved to (lane-av1tx): depth 0 is one transform over | ||
| 2547 | - // the whole block, 1 and 2 its halvings. | ||
| 2548 | - let depths = take_tx_depth_hits(); | ||
| 2549 | - let depth_total: usize = depths.iter().sum(); | ||
| 2550 | - eprintln!( | ||
| 2551 | - "{name}: intra tx depths {}", | ||
| 2552 | - depths | ||
| 2553 | - .iter() | ||
| 2554 | - .enumerate() | ||
| 2555 | - .map(|(d, &n)| format!( | ||
| 2556 | - "{d}={n} ({:.1}%)", | ||
| 2557 | - 100.0 * n as f64 / depth_total.max(1) as f64 | ||
| 2558 | - )) | ||
| 2559 | - .collect::<Vec<_>>() | ||
| 2560 | - .join(" ") | ||
| 2561 | - ); | ||
| 2562 | - print_inter_tx_census(name); | ||
| 2563 | - // lane-av1obmc: how many blocks actually CODED a motion_mode | ||
| 2564 | - // symbol and which value they took, by footprint -- "OBMC is on" | ||
| 2565 | - // as a measurement rather than a claim (class | ||
| 2566 | - // `gate-blind-to-feature`). | ||
| 2567 | - let mm = crate::tile::take_motion_mode_hits(); | ||
| 2568 | - eprintln!( | ||
| 2569 | - "{name}: motion_mode 32x32 SIMPLE={} OBMC={} WARP={} | 16x16 SIMPLE={} OBMC={} \ | ||
| 2570 | - WARP={} | 8x8 SIMPLE={} OBMC={} WARP={} ({:.1}% OBMC / {:.1}% WARP of {} \ | ||
| 2571 | - eligible)", | ||
| 2572 | - mm[0], | ||
| 2573 | - mm[1], | ||
| 2574 | - mm[2], | ||
| 2575 | - mm[3], | ||
| 2576 | - mm[4], | ||
| 2577 | - mm[5], | ||
| 2578 | - mm[6], | ||
| 2579 | - mm[7], | ||
| 2580 | - mm[8], | ||
| 2581 | - 100.0 * (mm[1] + mm[4] + mm[7]) as f64 / mm.iter().sum::<usize>().max(1) as f64, | ||
| 2582 | - 100.0 * (mm[2] + mm[5] + mm[8]) as f64 / mm.iter().sum::<usize>().max(1) as f64, | ||
| 2583 | - mm.iter().sum::<usize>(), | ||
| 2584 | - ); | ||
| 2585 | - let (aom, aom_wall) = | ||
| 2586 | - external_ladder(&source, width, height, "libaom-av1", &aom_points); | ||
| 2587 | - let (rav1e, rav1e_wall) = | ||
| 2588 | - external_ladder(&source, width, height, "librav1e", &rav1e_points); | ||
| 2589 | - assert_monotone(&format!("{name}: ours"), &ours); | ||
| 2590 | - assert_monotone(&format!("{name}: libaom"), &aom); | ||
| 2591 | - assert_monotone(&format!("{name}: rav1e"), &rav1e); | ||
| 2592 | - let points = ours | ||
| 2593 | - .iter() | ||
| 2594 | - .map(|(p, b)| format!("{p:.2} dB/{:.0} B", 10f64.powf(*b))) | ||
| 2595 | - .collect::<Vec<_>>() | ||
| 2596 | - .join(", "); | ||
| 2597 | - println!( | ||
| 2598 | - "| {name} | {points} | {:+.1}% | {:+.1}% | {ours_wall:.1}s:{aom_wall:.1}s:{rav1e_wall:.1}s |", | ||
| 2599 | - bd_rate(&aom, &ours) * 100.0, | ||
| 2600 | - bd_rate(&rav1e, &ours) * 100.0, | ||
| 2601 | - ); | ||
| 2602 | - println!( | ||
| 2603 | - "| references | libaom {} | rav1e {} | | |", | ||
| 2604 | - aom.iter() | ||
| 2605 | - .map(|(p, b)| format!("{p:.2} dB/{:.0} B", 10f64.powf(*b))) | ||
| 2606 | - .collect::<Vec<_>>() | ||
| 2607 | - .join(", "), | ||
| 2608 | - rav1e | ||
| 2609 | - .iter() | ||
| 2610 | - .map(|(p, b)| format!("{p:.2} dB/{:.0} B", 10f64.powf(*b))) | ||
| 2611 | - .collect::<Vec<_>>() | ||
| 2612 | - .join(", "), | ||
| 2613 | - ); | ||
| 2614 | - } | ||
| 2615 | - assert_ladder_decodes(); | ||
| 2616 | - } | ||
| 2617 | /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2, | 934 | /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2, |
| 2618 | /// split by block class in lane-av1txdepth): depth 0 is one transform over | 935 | /// split by block class in lane-av1txdepth): depth 0 is one transform over |
| 2619 | /// the whole block, 1 its four halves; the classes are the 16x16/8x8 | 936 | /// the whole block, 1 its four halves; the classes are the 16x16/8x8 |
| @@ -2735,634 +1052,6 @@ use std::process::Command; | |||
| 2735 | Some((format!("crop={cw}:{ch}:{x}:{y}"), cw, ch)) | 1052 | Some((format!("crop={cw}:{ch}:{x}:{y}"), cw, ch)) |
| 2736 | } | 1053 | } |
| 2737 | 1054 | ||
| 2738 | - /// The rows of [`bd_rate_screen_native`] -- (label, path, seek) -- shared | ||
| 2739 | - /// with `probe_screen_detect` so the detector sweep measures exactly the | ||
| 2740 | - /// clips the keep table is read off. Selector env vars as documented on | ||
| 2741 | - /// the gate; a missing clip prints a SKIP and drops its row. | ||
| 2742 | - pub(super) fn native_gate_clips() -> Vec<(String, String, String)> { | ||
| 2743 | - // lane-av1clipprobe: the crate's one fixture root (EC_FIXTURES first). | ||
| 2744 | - let fixtures = crate::library_fixture::root(); | ||
| 2745 | - let on = |k: &str| std::env::var(k).ok().as_deref() == Some("1"); | ||
| 2746 | - let (film, film4k, screen) = ( | ||
| 2747 | - on("EC_AV1_NATIVE_FILM"), | ||
| 2748 | - on("EC_AV1_NATIVE_FILM4K"), | ||
| 2749 | - on("EC_AV1_NATIVE_SCREEN"), | ||
| 2750 | - ); | ||
| 2751 | - // No selector at all means every clip; any selector means that subset. | ||
| 2752 | - let all = !(film || film4k || screen); | ||
| 2753 | - // (label, path, seek). The two `testsrc2` fixtures are COLOUR BARS, | ||
| 2754 | - // not film -- they print as "bars" so no reader takes them for real | ||
| 2755 | - // content -- and the two rows below them are the real AV1 films. | ||
| 2756 | - let mut clips: Vec<(String, String, String)> = Vec::new(); | ||
| 2757 | - for (want, label, file) in [ | ||
| 2758 | - (all || film, "bars 1080p", "h264-1080p-23.976-8bit.mp4"), | ||
| 2759 | - (all || film4k, "bars 2160p", "h264-2160p-23.976-8bit.mp4"), | ||
| 2760 | - ] { | ||
| 2761 | - if !want { | ||
| 2762 | - continue; | ||
| 2763 | - } | ||
| 2764 | - // lane-av1clipprobe: the one probe, so a missing clip is RED under | ||
| 2765 | - // the require envs instead of a dropped row with no escape. | ||
| 2766 | - if let Some(path) = crate::library_fixture::require( | ||
| 2767 | - &format!("video/{file}"), | ||
| 2768 | - &format!("the native BD-rate gate: {label}"), | ||
| 2769 | - ) { | ||
| 2770 | - clips.push(( | ||
| 2771 | - label.to_string(), | ||
| 2772 | - path.to_str().unwrap().to_string(), | ||
| 2773 | - "0".into(), | ||
| 2774 | - )); | ||
| 2775 | - } | ||
| 2776 | - } | ||
| 2777 | - let manifest = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")); | ||
| 2778 | - // The real films, taken out of the real-library manifest by codec and | ||
| 2779 | - // coded width so no title and no home path lives in this file. Each | ||
| 2780 | - // seek is PINNED (class `seeded fixture not reproducible`) at a | ||
| 2781 | - // moving, non-black window -- a black leader would make every arm | ||
| 2782 | - // read +0.000 (class `flat sample window`). Both sources are 10-bit | ||
| 2783 | - // (one HDR10/PQ); the loader's plain `-pix_fmt yuv420p` conversion is | ||
| 2784 | - // what all three encoders see, so the comparison stays | ||
| 2785 | - // encoder-vs-encoder. | ||
| 2786 | - let pick = |width: &str| -> Option<String> { | ||
| 2787 | - let m = manifest.as_ref().ok()?; | ||
| 2788 | - m.lines() | ||
| 2789 | - .skip(1) | ||
| 2790 | - .map(|l| l.split('\t').collect::<Vec<_>>()) | ||
| 2791 | - .find(|f| { | ||
| 2792 | - f.len() > 4 | ||
| 2793 | - && f[2] == "av1" | ||
| 2794 | - && f[3] == width | ||
| 2795 | - && std::path::Path::new(f[0]).exists() | ||
| 2796 | - }) | ||
| 2797 | - .map(|f| f[0].to_string()) | ||
| 2798 | - }; | ||
| 2799 | - for (want, label, width, seek) in [ | ||
| 2800 | - (all || film, "film A (1080p source)", "1920", "00:35:00"), | ||
| 2801 | - ( | ||
| 2802 | - all || film4k, | ||
| 2803 | - "film B (2160p HDR source)", | ||
| 2804 | - "3840", | ||
| 2805 | - "00:40:00", | ||
| 2806 | - ), | ||
| 2807 | - ] { | ||
| 2808 | - if !want { | ||
| 2809 | - continue; | ||
| 2810 | - } | ||
| 2811 | - match pick(width) { | ||
| 2812 | - Some(path) => clips.push((label.to_string(), path, seek.to_string())), | ||
| 2813 | - None => eprintln!("SKIP {label}: no {width}-wide AV1 source in the manifest"), | ||
| 2814 | - } | ||
| 2815 | - } | ||
| 2816 | - if all || screen { | ||
| 2817 | - match &manifest { | ||
| 2818 | - Ok(manifest) => match manifest | ||
| 2819 | - .lines() | ||
| 2820 | - .skip(1) | ||
| 2821 | - .filter_map(|l| l.split('\t').next()) | ||
| 2822 | - .find(|p| { | ||
| 2823 | - p.contains("/OBS/") | ||
| 2824 | - && p.ends_with(".mkv") | ||
| 2825 | - && std::path::Path::new(p).exists() | ||
| 2826 | - }) { | ||
| 2827 | - Some(p) => clips.push(( | ||
| 2828 | - format!("screen capture ({})", p.rsplit('/').next().unwrap_or(p)), | ||
| 2829 | - p.to_string(), | ||
| 2830 | - "0".into(), | ||
| 2831 | - )), | ||
| 2832 | - None => { | ||
| 2833 | - eprintln!("SKIP screen capture: no OBS recording in the manifest exists") | ||
| 2834 | - } | ||
| 2835 | - }, | ||
| 2836 | - Err(e) => eprintln!("SKIP screen capture: no real-library manifest ({e})"), | ||
| 2837 | - } | ||
| 2838 | - } | ||
| 2839 | - clips | ||
| 2840 | - } | ||
| 2841 | - | ||
| 2842 | - /// The NATIVE-resolution arm of the BD gate (all three clips). The default gate | ||
| 2843 | - /// downscales the OBS capture to 640x384, which destroys exactly the | ||
| 2844 | - /// pixel-identical 16x16 repeats intrabc and (part of) the palette exist | ||
| 2845 | - /// for (class `gate-recipe-confound`), so every screen-tool decision taken | ||
| 2846 | - /// on that recipe is taken on content the tool cannot serve. This arm | ||
| 2847 | - /// crops -- never scales -- a superblock-aligned window out of the middle | ||
| 2848 | - /// of the capture at its own resolution (at most 1920x1024, so the wall | ||
| 2849 | - /// stays in the minutes) and runs the same 12-frame, four-quantizer | ||
| 2850 | - /// ladder against libaom `cpu-used 6` and rav1e `speed=6`, one tile, one | ||
| 2851 | - /// thread, with the same three-way (encoder / ffmpeg / our decoder) | ||
| 2852 | - /// sample-exactness assertion `our_ladder` makes. | ||
| 2853 | - /// | ||
| 2854 | - /// It is its own `--ignored` test so the default gate's wall does not | ||
| 2855 | - /// grow. Every variant is an environment knob, and each of those is a | ||
| 2856 | - /// `OnceLock` read once per process, so a variant is a separate run: | ||
| 2857 | - /// | ||
| 2858 | - /// cargo test -p ec-av1 --release --lib -- --ignored \ | ||
| 2859 | - /// bd_rate_screen_native --nocapture # baseline | ||
| 2860 | - /// EC_AV1_INTRABC=1 ... same command # intra block copy | ||
| 2861 | - /// EC_AV1_PAL_MAXCOLORS=256 ... same command # palette bound | ||
| 2862 | - /// EC_AV1_TILES=1:1 EC_AV1_TILE_THREADS=4 ... # 2x2 tiles | ||
| 2863 | - /// EC_AV1_PYRAMID=0 ... same command # no coding pyramid | ||
| 2864 | - /// EC_AV1_GOP_LAYOUT=fixed ... same command # no tail absorbing | ||
| 2865 | - /// EC_AV1_GATE_FACADE=1 ... same command # the facade arm | ||
| 2866 | - /// | ||
| 2867 | - /// The coding pyramid is the DEFAULT of the sequence path this arm codes | ||
| 2868 | - /// through (lane-av1pyrdef); the run prints the requested and the | ||
| 2869 | - /// effective pyramid per clip, and a screen clip's effective one is | ||
| 2870 | - /// `None`. `EC_AV1_GATE_FACADE=1` runs the same ladder through the | ||
| 2871 | - /// streaming facade instead, which prints the per-level frame and byte | ||
| 2872 | - /// census and asserts ffmpeg's decode against our own decoder on all | ||
| 2873 | - /// three planes in display order; both arms code the same bytes | ||
| 2874 | - /// (`encoder::tests::the_facade_codes_the_same_bytes_as_encode_sequence`). | ||
| 2875 | - /// | ||
| 2876 | - /// WHICH ROWS ARE REAL CONTENT: the `bars 1080p` / `bars 2160p` rows are | ||
| 2877 | - /// the repo fixtures `scripts/gen-fixtures.sh` builds with ffmpeg | ||
| 2878 | - /// `testsrc2` -- COLOUR BARS, ~90% of whose 16x16 cells have no intra | ||
| 2879 | - /// cost -- so every "film" column in the historical tables of this file | ||
| 2880 | - /// is that generator, not film. The real content is `film A`, `film B` | ||
| 2881 | - /// (native crops out of the two AV1 films the real-library manifest | ||
| 2882 | - /// names, at a pinned seek; added 2026-09-07) and the screen capture. A | ||
| 2883 | - /// decision only the bars rows support is not supported. | ||
| 2884 | - /// | ||
| 2885 | - /// Measured 2026-09-07, the five rows before and after the screen | ||
| 2886 | - /// detector grew libaom's variance term ([`screen_var`]) -- before it, | ||
| 2887 | - /// BOTH real films were classified as screen content on 48/48 frames, so | ||
| 2888 | - /// their coefficients were priced against the DEFAULT CDFs and the | ||
| 2889 | - /// palette search ran over film; after, both are non-screen (0/48) and | ||
| 2890 | - /// the capture is unchanged at 48/48: | ||
| 2891 | - /// | ||
| 2892 | - /// | clip | vs libaom before -> after | vs rav1e before -> after | wall ours | | ||
| 2893 | - /// |---|---|---|---| | ||
| 2894 | - /// | bars 1080p | +15.6% -> +15.6% | -1.7% -> -1.7% | 37.9s | | ||
| 2895 | - /// | bars 2160p | +46.5% -> +46.5% | +18.8% -> +18.8% | 33.9s | | ||
| 2896 | - /// | film A | +69.5% -> +69.0% | +37.7% -> +37.5% | 72s -> 64.4s | | ||
| 2897 | - /// | film B | +102.4% -> +100.0% | +63.4% -> +61.5% | 72s -> 67.9s | | ||
| 2898 | - /// | screen capture | +51.0% -> +51.0% | -14.5% -> -14.5% | 27.5s | | ||
| 2899 | - /// | ||
| 2900 | - /// Both bars rows and the capture are byte-identical across that change | ||
| 2901 | - /// (their classification never moved); the palette search over film was | ||
| 2902 | - /// costing roughly a tenth of the film rows' wall. | ||
| 2903 | - /// | ||
| 2904 | - /// CONFIRM RUN 2026-09-07 (lane-av1pyrdef), with the pyramid now the | ||
| 2905 | - /// sequence path's default -- the four non-screen rows take `4:-16:8`, | ||
| 2906 | - /// the capture is gated flat and does not move a byte: | ||
| 2907 | - /// | ||
| 2908 | - /// | clip | effective | flat -> default | vs rav1e | wall ours:libaom:rav1e | | ||
| 2909 | - /// |---|---|---|---|---| | ||
| 2910 | - /// | bars 1080p | 4:-16:8 | +16.4% -> +21.5% | -1.1% -> +3.7% | 37.8s:8.4s:16.4s | | ||
| 2911 | - /// | bars 2160p | 4:-16:8 | +48.2% -> +48.3% | +20.4% -> +20.4% | 32.2s:5.6s:16.2s | | ||
| 2912 | - /// | film A | 4:-16:8 | +62.8% -> +54.1% | +32.5% -> +24.2% | 58.9s:9.5s:13.6s | | ||
| 2913 | - /// | film B | 4:-16:8 | +86.3% -> +82.6% | +50.5% -> +47.4% | 63.2s:18.7s:16.4s | | ||
| 2914 | - /// | screen capture | none (gated) | +50.1% -> +50.1% | -15.4% -> -15.4% | 31.1s:8.4s:11.3s | | ||
| 2915 | - /// | ||
| 2916 | - /// Every row lands on lane-av1pyrgate's facade-arm number to the digit, | ||
| 2917 | - /// which is the point of the shared driver: the two entry points code one | ||
| 2918 | - /// stream. The bars rows are fixtures (recorded, never a decision); the | ||
| 2919 | - /// two real films are what the pyramid ships for. | ||
| 2920 | - /// | ||
| 2921 | - /// All five gate clips are rows by default. `EC_AV1_NATIVE_FILM=1`, | ||
| 2922 | - /// `EC_AV1_NATIVE_FILM4K=1` and `EC_AV1_NATIVE_SCREEN=1` select a subset: | ||
| 2923 | - /// setting any one of them keeps only the selected rows (the two 1080p | ||
| 2924 | - /// rows, the two 2160p rows, the capture row respectively). A missing | ||
| 2925 | - /// real film SKIPs its row; it never fails the gate. | ||
| 2926 | - #[test] | ||
| 2927 | - #[ignore = "the native-resolution BD arm: minutes per row, needs ffmpeg"] | ||
| 2928 | - fn bd_rate_screen_native() { | ||
| 2929 | - let _knobs = crate::speed::knob_read(); | ||
| 2930 | - native_bd_arm("bd_rate_screen_native", 12, false); | ||
| 2931 | - } | ||
| 2932 | - | ||
| 2933 | - /// The LONG-GOP arm of the native BD gate: the same recipe as | ||
| 2934 | - /// [`bd_rate_screen_native`] over the two real film rows only, but 48 | ||
| 2935 | - /// pictures with `gop = 48` (`encode_sequence` sets `gop = | ||
| 2936 | - /// pictures.len()`, and `external_ladder` passes ffmpeg `-g 48`, which | ||
| 2937 | - /// reaches libaom as `--kf-max-dist=48` and rav1e as | ||
| 2938 | - /// `key_frame_interval=48`), so every encoder sees one key frame and 47 | ||
| 2939 | - /// inter pictures. | ||
| 2940 | - /// | ||
| 2941 | - /// WHY IT EXISTS: `bd_rate_screen_native` codes 12 frames with `gop = | ||
| 2942 | - /// 12`, and `Av1Encoder::encode_frames` cuts a mini-GOP at every key | ||
| 2943 | - /// frame (`encoder.rs`), so ANY [`crate::encoder::Pyramid::mini_gop`] | ||
| 2944 | - /// above 12 codes the same stream there -- the shipped `16` was measured | ||
| 2945 | - /// as "one hidden ARF per 12-picture GOP", never as a real 16-picture | ||
| 2946 | - /// group (class `instrument at bound` / `gate blind to feature`). The | ||
| 2947 | - /// user's exports are long GOPs, so the pyramid shape is decided here. | ||
| 2948 | - /// | ||
| 2949 | - /// cargo test -p ec-av1 --release --lib -- --ignored \ | ||
| 2950 | - /// bd_rate_film_long_gop --nocapture | ||
| 2951 | - /// | ||
| 2952 | - /// `EC_AV1_NATIVE_FILM=1` keeps only film A, `EC_AV1_NATIVE_FILM4K=1` | ||
| 2953 | - /// only film B; `EC_AV1_PYRAMID=<mini_gop>:<arf>:<leaf>` picks the shape. | ||
| 2954 | - /// Read every row off the log's own "pyramid requested/effective" print, | ||
| 2955 | - /// never off the argument order of the runs (lane-pyr3 misattributed | ||
| 2956 | - /// three rows that way). | ||
| 2957 | - /// | ||
| 2958 | - /// Table: `lanes/pyr4.sweep.txt`. | ||
| 2959 | - #[test] | ||
| 2960 | - #[ignore = "the long-GOP native BD arm: ~7 minutes per film row, needs ffmpeg"] | ||
| 2961 | - fn bd_rate_film_long_gop() { | ||
| 2962 | - let _knobs = crate::speed::knob_write(); | ||
| 2963 | - native_bd_arm("bd_rate_film_long_gop", 48, true); | ||
| 2964 | - } | ||
| 2965 | - | ||
| 2966 | - /// The shared driver of the two native BD arms above: `frames` pictures | ||
| 2967 | - /// per row (the sequence's `gop` is the same number, so one key frame), | ||
| 2968 | - /// four quantizers, `films_only` dropping every row but the two real | ||
| 2969 | - /// films. | ||
| 2970 | - pub(super) fn native_bd_arm(label: &str, frames: usize, films_only: bool) { | ||
| 2971 | - if !have_ffmpeg() { | ||
| 2972 | - eprintln!("SKIP {label}: no ffmpeg"); | ||
| 2973 | - return; | ||
| 2974 | - } | ||
| 2975 | - let mut clips = native_gate_clips(); | ||
| 2976 | - if films_only { | ||
| 2977 | - clips.retain(|(name, _, _)| name.starts_with("film ")); | ||
| 2978 | - } | ||
| 2979 | - if clips.is_empty() { | ||
| 2980 | - eprintln!("SKIP {label}: no clip"); | ||
| 2981 | - return; | ||
crates/ec-av1/src/encode/tests.rsmodified+15 -254
| @@ -1,4 +1,3 @@ | |||
| 1 | - use super::more_tests::*; | ||
| 2 | 1 | ||
| 3 | /// Every (site, frame type, block side) the census can be called with | 2 | /// Every (site, frame type, block side) the census can be called with |
| 4 | /// lands in its own ten-counter bucket, inside the array (class | 3 | /// lands in its own ten-counter bucket, inside the array (class |
| @@ -628,7 +627,6 @@ | |||
| 628 | use super::*; | 627 | use super::*; |
| 629 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; | 628 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; |
| 630 | use crate::probe::run_with_stdin; | 629 | use crate::probe::run_with_stdin; |
| 631 | - use std::process::{Command, Stdio}; | ||
| 632 | 630 | ||
| 633 | /// Every rectangular shape this decoder codes, at every position a block | 631 | /// Every rectangular shape this decoder codes, at every position a block |
| 634 | /// of that shape can sit inside a 64x64 superblock: [`Reach::of_rect`] | 632 | /// of that shape can sit inside a 64x64 superblock: [`Reach::of_rect`] |
| @@ -748,46 +746,10 @@ | |||
| 748 | } | 746 | } |
| 749 | } | 747 | } |
| 750 | 748 | ||
| 751 | - /// Whether ffmpeg is on PATH. Absence normally SKIPs, but | ||
| 752 | - /// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every | ||
| 753 | - /// aomenc gate decodes its stream through ffmpeg and is meaningless | ||
| 754 | - /// without it -- turns it into a hard failure. Without this the require | ||
| 755 | - /// flag was silently short-circuited: `!have_ffmpeg()` is evaluated first | ||
| 756 | - /// in `if !have_ffmpeg() || !have_aomenc()`, so a machine with no ffmpeg | ||
| 757 | - /// printed SKIP and reported green (class gate-skips-on-its-own-failure). | ||
| 758 | - pub(super) fn have_ffmpeg() -> bool { | ||
| 759 | - let present = Command::new("ffmpeg") | ||
| 760 | - .arg("-version") | ||
| 761 | - .stdout(Stdio::null()) | ||
| 762 | - .stderr(Stdio::null()) | ||
| 763 | - .status() | ||
| 764 | - .is_ok_and(|s| s.success()); | ||
| 765 | - assert!( | ||
| 766 | - present | ||
| 767 | - || (std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_none() | ||
| 768 | - && std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none()), | ||
| 769 | - "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH" | ||
| 770 | - ); | ||
| 771 | - present | ||
| 772 | - } | ||
| 773 | - | ||
| 774 | - /// Whether this ffmpeg was built with `encoder` (lane-pareto2: the | ||
| 775 | - /// SVT-AV1 Pareto rows are skipped, never failed, on a build without it). | ||
| 776 | - pub(super) fn have_encoder(encoder: &str) -> bool { | ||
| 777 | - crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 778 | - .args(["-hide_banner", "-encoders"]) | ||
| 779 | - .stderr(Stdio::null()), None, |c| c.output()) | ||
| 780 | - .is_ok_and(|o| { | ||
| 781 | - String::from_utf8_lossy(&o.stdout) | ||
| 782 | - .lines() | ||
| 783 | - .any(|l| l.split_whitespace().nth(1) == Some(encoder)) | ||
| 784 | - }) | ||
| 785 | - } | ||
| 786 | - | ||
| 787 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes. | 749 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes. |
| 788 | pub(super) fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { | 750 | pub(super) fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { |
| 789 | let out = run_with_stdin( | 751 | let out = run_with_stdin( |
| 790 | - Command::new("ffmpeg").args([ | 752 | + ec_testkit::ffmpeg().args([ |
| 791 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 753 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 792 | ]), | 754 | ]), |
| 793 | stream, | 755 | stream, |
| @@ -953,10 +915,6 @@ | |||
| 953 | assert_eq!(ours[0].u, encoded.reconstruction.u, "our decoder: U"); | 915 | assert_eq!(ours[0].u, encoded.reconstruction.u, "our decoder: U"); |
| 954 | assert_eq!(ours[0].v, encoded.reconstruction.v, "our decoder: V"); | 916 | assert_eq!(ours[0].v, encoded.reconstruction.v, "our decoder: V"); |
| 955 | 917 | ||
| 956 | - if !have_ffmpeg() { | ||
| 957 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 958 | - return; | ||
| 959 | - } | ||
| 960 | let decoded = ffmpeg_decode(&encoded.stream, width, height); | 918 | let decoded = ffmpeg_decode(&encoded.stream, width, height); |
| 961 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); | 919 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); |
| 962 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); | 920 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); |
| @@ -973,10 +931,6 @@ | |||
| 973 | fn ffmpeg_decodes_exactly_what_the_encoder_reconstructed() { | 931 | fn ffmpeg_decodes_exactly_what_the_encoder_reconstructed() { |
| 974 | let _knobs = crate::speed::knob_read(); | 932 | let _knobs = crate::speed::knob_read(); |
| 975 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 933 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 976 | - if !have_ffmpeg() { | ||
| 977 | - eprintln!("SKIP ffmpeg_decodes_exactly_what_the_encoder_reconstructed: no ffmpeg"); | ||
| 978 | - return; | ||
| 979 | - } | ||
| 980 | for &(width, height) in &[ | 934 | for &(width, height) in &[ |
| 981 | (64usize, 64usize), | 935 | (64usize, 64usize), |
| 982 | (96, 64), | 936 | (96, 64), |
| @@ -1096,10 +1050,6 @@ | |||
| 1096 | assert_eq!(via_us[0].y, encoded.reconstruction.y, "our decoder: luma"); | 1050 | assert_eq!(via_us[0].y, encoded.reconstruction.y, "our decoder: luma"); |
| 1097 | assert_eq!(via_us[0].u, encoded.reconstruction.u, "our decoder: U"); | 1051 | assert_eq!(via_us[0].u, encoded.reconstruction.u, "our decoder: U"); |
| 1098 | assert_eq!(via_us[0].v, encoded.reconstruction.v, "our decoder: V"); | 1052 | assert_eq!(via_us[0].v, encoded.reconstruction.v, "our decoder: V"); |
| 1099 | - if !have_ffmpeg() { | ||
| 1100 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 1101 | - return; | ||
| 1102 | - } | ||
| 1103 | let decoded = ffmpeg_decode(&encoded.stream, width, height); | 1053 | let decoded = ffmpeg_decode(&encoded.stream, width, height); |
| 1104 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); | 1054 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); |
| 1105 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); | 1055 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); |
| @@ -1158,7 +1108,7 @@ | |||
| 1158 | "our decoder: GOP frame {i} luma" | 1108 | "our decoder: GOP frame {i} luma" |
| 1159 | ); | 1109 | ); |
| 1160 | } | 1110 | } |
| 1161 | - if have_ffmpeg() { | 1111 | + { |
| 1162 | let ff = ffmpeg_decode_sequence(&gop.stream, width, height, moved.len()); | 1112 | let ff = ffmpeg_decode_sequence(&gop.stream, width, height, moved.len()); |
| 1163 | assert_eq!(ff.len(), gop.frames.len(), "ffmpeg: GOP frame count"); | 1113 | assert_eq!(ff.len(), gop.frames.len(), "ffmpeg: GOP frame count"); |
| 1164 | for (i, (theirs, frame)) in ff.iter().zip(gop.frames.iter()).enumerate() { | 1114 | for (i, (theirs, frame)) in ff.iter().zip(gop.frames.iter()).enumerate() { |
| @@ -1415,70 +1365,6 @@ | |||
| 1415 | eprintln!("{NAME}: {fired} chroma palette block(s) round-tripped"); | 1365 | eprintln!("{NAME}: {fired} chroma palette block(s) round-tripped"); |
| 1416 | } | 1366 | } |
| 1417 | 1367 | ||
| 1418 | - /// The lane's keep-rule measurement: the gate's own screen capture, one | ||
| 1419 | - /// KEY FRAME, coded with and without `allow_intrabc` at four quantizers. | ||
| 1420 | - /// Setting the bit forces deblocking, CDEF and loop restoration off for | ||
| 1421 | - /// that frame, so the table is exactly the filter loss against the bytes | ||
| 1422 | - /// the copied blocks save. | ||
| 1423 | - #[test] | ||
| 1424 | - #[ignore = "needs the real-library manifest and ffmpeg"] | ||
| 1425 | - fn probe_intrabc_key_frame() { | ||
| 1426 | - let _knobs = crate::speed::knob_write(); | ||
| 1427 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 1428 | - // lane-av1clipprobe: the manifest is a real-library file, so it | ||
| 1429 | - // resolves through the crate's one fixture root (EC_FIXTURES first) | ||
| 1430 | - // and its absence is reported by the one probe instead of an inline | ||
| 1431 | - // SKIP that named no path. A file that IS there but unreadable is not | ||
| 1432 | - // an absence, so it is a hard error rather than a second silent skip. | ||
| 1433 | - let Some(manifest_path) = | ||
| 1434 | - crate::library_fixture::require("real-library-manifest.tsv", "probe_intrabc_key_frame") | ||
| 1435 | - else { | ||
| 1436 | - return; | ||
| 1437 | - }; | ||
| 1438 | - let manifest = std::fs::read_to_string(&manifest_path).unwrap_or_else(|e| { | ||
| 1439 | - panic!( | ||
| 1440 | - "probe_intrabc_key_frame: {} is present but unreadable ({e})", | ||
| 1441 | - manifest_path.display() | ||
| 1442 | - ) | ||
| 1443 | - }); | ||
| 1444 | - let Some(clip) = manifest | ||
| 1445 | - .lines() | ||
| 1446 | - .skip(1) | ||
| 1447 | - .filter_map(|l| l.split('\t').next()) | ||
| 1448 | - .find(|p| { | ||
| 1449 | - p.contains("/OBS/") && p.ends_with(".mkv") && std::path::Path::new(p).exists() | ||
| 1450 | - }) | ||
| 1451 | - else { | ||
| 1452 | - eprintln!("SKIP probe_intrabc_key_frame: no OBS recording"); | ||
| 1453 | - return; | ||
| 1454 | - }; | ||
| 1455 | - let (width, height) = (1280usize, 768usize); | ||
| 1456 | - let picture = clip_frame(clip, "0", width, height); | ||
| 1457 | - eprintln!("| base_q_idx | intrabc | bytes | PSNR | blocks | searches/found/won |"); | ||
| 1458 | - for q in [5u8, 20, 35, 45] { | ||
| 1459 | - for on in [false, true] { | ||
| 1460 | - force_intrabc(Some(on)); | ||
| 1461 | - let _ = crate::tile::take_intrabc_hits(); | ||
| 1462 | - let _ = take_intrabc_search(); | ||
| 1463 | - let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); | ||
| 1464 | - let hits = crate::tile::take_intrabc_hits(); | ||
| 1465 | - let search = take_intrabc_search(); | ||
| 1466 | - eprintln!( | ||
| 1467 | - "| {q} | {} | {} | {:.2} dB | {} (dv hist {:?}) | {}/{}/{} |", | ||
| 1468 | - if encoded.allow_intrabc { "on" } else { "off" }, | ||
| 1469 | - encoded.stream.len(), | ||
| 1470 | - psnr_all(&encoded.reconstruction, &picture), | ||
| 1471 | - hits[0], | ||
| 1472 | - &hits[1..], | ||
| 1473 | - search[0], | ||
| 1474 | - search[1], | ||
| 1475 | - search[2], | ||
| 1476 | - ); | ||
| 1477 | - } | ||
| 1478 | - } | ||
| 1479 | - force_intrabc(None); | ||
| 1480 | - } | ||
| 1481 | - | ||
| 1482 | /// lane-av1ibc's own end-to-end check: a repeated-pattern screen card | 1368 | /// lane-av1ibc's own end-to-end check: a repeated-pattern screen card |
| 1483 | /// sets `allow_intrabc` (so every in-loop filter is off), blocks really | 1369 | /// sets `allow_intrabc` (so every in-loop filter is off), blocks really |
| 1484 | /// take a block vector (fire count + DV histogram, class | 1370 | /// take a block vector (fire count + DV histogram, class |
| @@ -1526,10 +1412,6 @@ | |||
| 1526 | assert_eq!(via_us[0].y, encoded.reconstruction.y, "our decoder: luma"); | 1412 | assert_eq!(via_us[0].y, encoded.reconstruction.y, "our decoder: luma"); |
| 1527 | assert_eq!(via_us[0].u, encoded.reconstruction.u, "our decoder: U"); | 1413 | assert_eq!(via_us[0].u, encoded.reconstruction.u, "our decoder: U"); |
| 1528 | assert_eq!(via_us[0].v, encoded.reconstruction.v, "our decoder: V"); | 1414 | assert_eq!(via_us[0].v, encoded.reconstruction.v, "our decoder: V"); |
| 1529 | - if !have_ffmpeg() { | ||
| 1530 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 1531 | - return; | ||
| 1532 | - } | ||
| 1533 | let decoded = ffmpeg_decode(&encoded.stream, width, height); | 1415 | let decoded = ffmpeg_decode(&encoded.stream, width, height); |
| 1534 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); | 1416 | assert_eq!(decoded.y, encoded.reconstruction.y, "ffmpeg: luma"); |
| 1535 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); | 1417 | assert_eq!(decoded.u, encoded.reconstruction.u, "ffmpeg: U"); |
| @@ -1548,12 +1430,6 @@ | |||
| 1548 | fn a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean() { | 1430 | fn a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean() { |
| 1549 | let _knobs = crate::speed::knob_write(); | 1431 | let _knobs = crate::speed::knob_write(); |
| 1550 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 1432 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 1551 | - if !have_ffmpeg() { | ||
| 1552 | - eprintln!( | ||
| 1553 | - "SKIP a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean: no ffmpeg" | ||
| 1554 | - ); | ||
| 1555 | - return; | ||
| 1556 | - } | ||
| 1557 | let (width, height) = (64usize, 64usize); | 1433 | let (width, height) = (64usize, 64usize); |
| 1558 | let picture = Picture::grey(width, height); | 1434 | let picture = Picture::grey(width, height); |
| 1559 | let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | 1435 | let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| @@ -1649,7 +1525,7 @@ | |||
| 1649 | )); | 1525 | )); |
| 1650 | let _ = std::fs::remove_file(&path); | 1526 | let _ = std::fs::remove_file(&path); |
| 1651 | std::fs::write(&path, stream).expect("writing the probe stream"); | 1527 | std::fs::write(&path, stream).expect("writing the probe stream"); |
| 1652 | - let out = crate::tool_cache::cached_output_io(Command::new("ffprobe") | 1528 | + let out = ec_testkit::ffprobe() |
| 1653 | .args([ | 1529 | .args([ |
| 1654 | "-v", | 1530 | "-v", |
| 1655 | "error", | 1531 | "error", |
| @@ -1662,7 +1538,7 @@ | |||
| 1662 | "-of", | 1538 | "-of", |
| 1663 | "csv=p=0", | 1539 | "csv=p=0", |
| 1664 | ]) | 1540 | ]) |
| 1665 | - .arg(&path), None, |c| c.output()) | 1541 | + .arg(&path).output() |
| 1666 | .expect("ffprobe failed to run"); | 1542 | .expect("ffprobe failed to run"); |
| 1667 | let _ = std::fs::remove_file(&path); | 1543 | let _ = std::fs::remove_file(&path); |
| 1668 | assert!( | 1544 | assert!( |
| @@ -1720,10 +1596,6 @@ | |||
| 1720 | fn a_frame_round_trips_at_its_own_size() { | 1596 | fn a_frame_round_trips_at_its_own_size() { |
| 1721 | let _knobs = crate::speed::knob_read(); | 1597 | let _knobs = crate::speed::knob_read(); |
| 1722 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 1598 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 1723 | - if !have_ffmpeg() { | ||
| 1724 | - eprintln!("SKIP a_frame_round_trips_at_its_own_size: no ffmpeg"); | ||
| 1725 | - return; | ||
| 1726 | - } | ||
| 1727 | // 854x480 is covered separately by | 1599 | // 854x480 is covered separately by |
| 1728 | // `an_854x480_picture_round_trips_through_its_padding`, which its own | 1600 | // `an_854x480_picture_round_trips_through_its_padding`, which its own |
| 1729 | // doc comment explains was worth keeping as its own test. | 1601 | // doc comment explains was worth keeping as its own test. |
| @@ -1787,9 +1659,6 @@ | |||
| 1787 | fn an_854x480_picture_round_trips_through_its_padding() { | 1659 | fn an_854x480_picture_round_trips_through_its_padding() { |
| 1788 | let _knobs = crate::speed::knob_read(); | 1660 | let _knobs = crate::speed::knob_read(); |
| 1789 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 1661 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 1790 | - if !have_ffmpeg() { | ||
| 1791 | - return; | ||
| 1792 | - } | ||
| 1793 | let (width, height) = (854usize, 480usize); | 1662 | let (width, height) = (854usize, 480usize); |
| 1794 | let picture = test_card(width, height); | 1663 | let picture = test_card(width, height); |
| 1795 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | 1664 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| @@ -2096,10 +1965,6 @@ | |||
| 2096 | fn sequence_round_trips_at_a_non_multiple_size() { | 1965 | fn sequence_round_trips_at_a_non_multiple_size() { |
| 2097 | let _knobs = crate::speed::knob_read(); | 1966 | let _knobs = crate::speed::knob_read(); |
| 2098 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 1967 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 2099 | - if !have_ffmpeg() { | ||
| 2100 | - eprintln!("SKIP sequence_round_trips_at_a_non_multiple_size: no ffmpeg"); | ||
| 2101 | - return; | ||
| 2102 | - } | ||
| 2103 | let (width, height) = (160usize, 96usize); | 1968 | let (width, height) = (160usize, 96usize); |
| 2104 | let pictures: Vec<Picture> = (0..3) | 1969 | let pictures: Vec<Picture> = (0..3) |
| 2105 | .map(|i| panned_test_card(width, height, i * 3)) | 1970 | .map(|i| panned_test_card(width, height, i * 3)) |
| @@ -2140,10 +2005,6 @@ | |||
| 2140 | fn a_sequence_round_trips_at_the_exactly_half_straddle_size() { | 2005 | fn a_sequence_round_trips_at_the_exactly_half_straddle_size() { |
| 2141 | let _knobs = crate::speed::knob_read(); | 2006 | let _knobs = crate::speed::knob_read(); |
| 2142 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2007 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 2143 | - if !have_ffmpeg() { | ||
| 2144 | - eprintln!("SKIP a_sequence_round_trips_at_the_exactly_half_straddle_size: no ffmpeg"); | ||
| 2145 | - return; | ||
| 2146 | - } | ||
| 2147 | let (width, height) = (1280usize, 720usize); | 2008 | let (width, height) = (1280usize, 720usize); |
| 2148 | let pictures: Vec<Picture> = (0..3) | 2009 | let pictures: Vec<Picture> = (0..3) |
| 2149 | .map(|i| panned_test_card(width, height, i * 3)) | 2010 | .map(|i| panned_test_card(width, height, i * 3)) |
| @@ -2207,13 +2068,6 @@ | |||
| 2207 | fn a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames() { | 2068 | fn a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames() { |
| 2208 | let _knobs = crate::speed::knob_read(); | 2069 | let _knobs = crate::speed::knob_read(); |
| 2209 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2070 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 2210 | - if !have_ffmpeg() { | ||
| 2211 | - eprintln!( | ||
| 2212 | - "SKIP a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames: \ | ||
| 2213 | - no ffmpeg" | ||
| 2214 | - ); | ||
| 2215 | - return; | ||
| 2216 | - } | ||
| 2217 | let (width, height) = (640usize, 360usize); | 2071 | let (width, height) = (640usize, 360usize); |
| 2218 | for shift in [0i64, 7, 19] { | 2072 | for shift in [0i64, 7, 19] { |
| 2219 | let picture = panned_test_card(width, height, shift); | 2073 | let picture = panned_test_card(width, height, shift); |
| @@ -2233,12 +2087,6 @@ | |||
| 2233 | fn a_640x360_half_straddle_sequence_round_trips_through_ffmpeg() { | 2087 | fn a_640x360_half_straddle_sequence_round_trips_through_ffmpeg() { |
| 2234 | let _knobs = crate::speed::knob_read(); | 2088 | let _knobs = crate::speed::knob_read(); |
| 2235 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2089 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 2236 | - if !have_ffmpeg() { | ||
| 2237 | - eprintln!( | ||
| 2238 | - "SKIP a_640x360_half_straddle_sequence_round_trips_through_ffmpeg: no ffmpeg" | ||
| 2239 | - ); | ||
| 2240 | - return; | ||
| 2241 | - } | ||
| 2242 | let (width, height) = (640usize, 360usize); | 2090 | let (width, height) = (640usize, 360usize); |
| 2243 | let pictures: Vec<Picture> = (0..4) | 2091 | let pictures: Vec<Picture> = (0..4) |
| 2244 | .map(|i| panned_test_card(width, height, i * 3)) | 2092 | .map(|i| panned_test_card(width, height, i * 3)) |
| @@ -2259,10 +2107,10 @@ | |||
| 2259 | 2107 | ||
| 2260 | /// One frame of a real clip, scaled to a whole number of 32x32 blocks. | 2108 | /// One frame of a real clip, scaled to a whole number of 32x32 blocks. |
| 2261 | pub(super) fn clip_frame(clip: &str, skip: &str, width: usize, height: usize) -> Picture { | 2109 | pub(super) fn clip_frame(clip: &str, skip: &str, width: usize, height: usize) -> Picture { |
| 2262 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | 2110 | + let out = ec_testkit::ffmpeg() |
| 2263 | .args(["-v", "error", "-ss", skip, "-i", clip, "-frames:v", "1"]) | 2111 | .args(["-v", "error", "-ss", skip, "-i", clip, "-frames:v", "1"]) |
| 2264 | .args(["-vf", &format!("scale={width}:{height}")]) | 2112 | .args(["-vf", &format!("scale={width}:{height}")]) |
| 2265 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]), None, |c| c.output()) | 2113 | + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]).output() |
| 2266 | .expect("ffmpeg failed to run"); | 2114 | .expect("ffmpeg failed to run"); |
| 2267 | assert!( | 2115 | assert!( |
| 2268 | out.status.success(), | 2116 | out.status.success(), |
| @@ -2451,10 +2299,6 @@ | |||
| 2451 | fn every_mode_decodes_to_what_the_encoder_predicted() { | 2299 | fn every_mode_decodes_to_what_the_encoder_predicted() { |
| 2452 | let _knobs = crate::speed::knob_write(); | 2300 | let _knobs = crate::speed::knob_write(); |
| 2453 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2301 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 2454 | - if !have_ffmpeg() { | ||
| 2455 | - eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg"); | ||
| 2456 | - return; | ||
| 2457 | - } | ||
| 2458 | // A mode ablation measures the MODE search: a filter-intra block is | 2302 | // A mode ablation measures the MODE search: a filter-intra block is |
| 2459 | // coded `DC_PRED` whatever mode the arm forces, so it would fail the | 2303 | // coded `DC_PRED` whatever mode the arm forces, so it would fail the |
| 2460 | // "the encoder coded something else" check for a reason that is not | 2304 | // "the encoder coded something else" check for a reason that is not |
| @@ -3000,10 +2844,6 @@ | |||
| 3000 | fn a_single_axis_straddle_round_trips_through_ffmpeg() { | 2844 | fn a_single_axis_straddle_round_trips_through_ffmpeg() { |
| 3001 | let _knobs = crate::speed::knob_read(); | 2845 | let _knobs = crate::speed::knob_read(); |
| 3002 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2846 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 3003 | - if !have_ffmpeg() { | ||
| 3004 | - eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg"); | ||
| 3005 | - return; | ||
| 3006 | - } | ||
| 3007 | let (width, height) = (40usize, 32usize); | 2847 | let (width, height) = (40usize, 32usize); |
| 3008 | let picture = test_card(width, height); | 2848 | let picture = test_card(width, height); |
| 3009 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | 2849 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| @@ -3020,47 +2860,6 @@ | |||
| 3020 | assert_eq!(decoded.v, encoded.reconstruction.v, "V"); | 2860 | assert_eq!(decoded.v, encoded.reconstruction.v, "V"); |
| 3021 | } | 2861 | } |
| 3022 | 2862 | ||
| 3023 | - /// A frame of real video, rather than a picture built to be easy. | ||
| 3024 | - /// | ||
| 3025 | - /// `EC_AV1_CLIP` names the clip and `EC_AV1_CLIP_SKIP` how far into it to | ||
| 3026 | - /// seek; ffmpeg decodes one frame, crops it to the block grid, and the | ||
| 3027 | - /// encoder's reconstruction has to survive the same equality gate as the | ||
| 3028 | - /// synthetic pictures — real video reaches contexts a test card does not. | ||
| 3029 | - #[test] | ||
| 3030 | - fn a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed() { | ||
| 3031 | - let _knobs = crate::speed::knob_read(); | ||
| 3032 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 3033 | - let Ok(clip) = std::env::var("EC_AV1_CLIP") else { | ||
| 3034 | - eprintln!( | ||
| 3035 | - "SKIP a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed: \ | ||
| 3036 | - set EC_AV1_CLIP to a clip" | ||
| 3037 | - ); | ||
| 3038 | - return; | ||
| 3039 | - }; | ||
| 3040 | - if !have_ffmpeg() { | ||
| 3041 | - eprintln!( | ||
| 3042 | - "SKIP a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed: no ffmpeg" | ||
| 3043 | - ); | ||
| 3044 | - return; | ||
| 3045 | - } | ||
| 3046 | - let skip = std::env::var("EC_AV1_CLIP_SKIP").unwrap_or_else(|_| "0".into()); | ||
| 3047 | - // A 4:2:0 frame cropped to whole 32x32 blocks, in a size that keeps the | ||
| 3048 | - // test quick while still spanning many superblocks. | ||
| 3049 | - let (width, height) = (640usize, 352usize); | ||
| 3050 | - let picture = clip_frame(&clip, &skip, width, height); | ||
| 3051 | - | ||
| 3052 | - let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | ||
| 3053 | - let decoded = ffmpeg_decode(&encoded.stream, width, height); | ||
| 3054 | - assert_eq!(decoded.y, encoded.reconstruction.y, "luma"); | ||
| 3055 | - assert_eq!(decoded.u, encoded.reconstruction.u, "U"); | ||
| 3056 | - assert_eq!(decoded.v, encoded.reconstruction.v, "V"); | ||
| 3057 | - eprintln!( | ||
| 3058 | - "{} bytes, luma PSNR {:.2} dB", | ||
| 3059 | - encoded.stream.len(), | ||
| 3060 | - psnr(&decoded.y, &picture.y) | ||
| 3061 | - ); | ||
| 3062 | - } | ||
| 3063 | - | ||
| 3064 | /// [`test_card`], panned `shift` samples to the right (wrapping), so a | 2863 | /// [`test_card`], panned `shift` samples to the right (wrapping), so a |
| 3065 | /// sequence of these is a translation a motion search can actually find | 2864 | /// sequence of these is a translation a motion search can actually find |
| 3066 | /// — the content [`test_card`] itself draws, not a fresh pattern, so an | 2865 | /// — the content [`test_card`] itself draws, not a fresh pattern, so an |
| @@ -3103,7 +2902,7 @@ | |||
| 3103 | frames: usize, | 2902 | frames: usize, |
| 3104 | ) -> Vec<Picture> { | 2903 | ) -> Vec<Picture> { |
| 3105 | let out = run_with_stdin( | 2904 | let out = run_with_stdin( |
| 3106 | - Command::new("ffmpeg").args([ | 2905 | + ec_testkit::ffmpeg().args([ |
| 3107 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 2906 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 3108 | ]), | 2907 | ]), |
| 3109 | stream, | 2908 | stream, |
| @@ -3154,12 +2953,6 @@ | |||
| 3154 | fn every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed() { | 2953 | fn every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed() { |
| 3155 | let _knobs = crate::speed::knob_read(); | 2954 | let _knobs = crate::speed::knob_read(); |
| 3156 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 2955 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 3157 | - if !have_ffmpeg() { | ||
| 3158 | - eprintln!( | ||
| 3159 | - "SKIP every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed: no ffmpeg" | ||
| 3160 | - ); | ||
| 3161 | - return; | ||
| 3162 | - } | ||
| 3163 | let (width, height) = (128usize, 64usize); | 2956 | let (width, height) = (128usize, 64usize); |
| 3164 | let pictures: Vec<Picture> = (0..5) | 2957 | let pictures: Vec<Picture> = (0..5) |
| 3165 | .map(|i| panned_test_card(width, height, i * 3)) | 2958 | .map(|i| panned_test_card(width, height, i * 3)) |
| @@ -3240,10 +3033,6 @@ | |||
| 3240 | /// Runs only inside `superblock_size_global_suite`. | 3033 | /// Runs only inside `superblock_size_global_suite`. |
| 3241 | fn a_128_superblock_clip_whose_root_search_codes_128x128_blocks_decodes_exact() { | 3034 | fn a_128_superblock_clip_whose_root_search_codes_128x128_blocks_decodes_exact() { |
| 3242 | let _knobs = crate::speed::knob_write(); | 3035 | let _knobs = crate::speed::knob_write(); |
| 3243 | - if !have_ffmpeg() { | ||
| 3244 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3245 | - return; | ||
| 3246 | - } | ||
| 3247 | force_sb128(true); | 3036 | force_sb128(true); |
| 3248 | let dir = std::env::temp_dir().join(format!("ec-av1-b128-{}", std::process::id())); | 3037 | let dir = std::env::temp_dir().join(format!("ec-av1-b128-{}", std::process::id())); |
| 3249 | std::fs::create_dir_all(&dir).unwrap(); | 3038 | std::fs::create_dir_all(&dir).unwrap(); |
| @@ -3251,7 +3040,7 @@ | |||
| 3251 | // A slow horizontal pan over a still pattern: whole 128x128 regions | 3040 | // A slow horizontal pan over a still pattern: whole 128x128 regions |
| 3252 | // share one motion vector, which is exactly what a 128 root can code | 3041 | // share one motion vector, which is exactly what a 128 root can code |
| 3253 | // as one block and four 64 roots cannot. | 3042 | // as one block and four 64 roots cannot. |
| 3254 | - let ok = Command::new("ffmpeg") | 3043 | + let ok = ec_testkit::ffmpeg() |
| 3255 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3044 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3256 | .args(["-i", "smptebars=size=1600x768:rate=24"]) | 3045 | .args(["-i", "smptebars=size=1600x768:rate=24"]) |
| 3257 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) | 3046 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) |
| @@ -3339,15 +3128,11 @@ | |||
| 3339 | /// Runs only inside `superblock_size_global_suite`. | 3128 | /// Runs only inside `superblock_size_global_suite`. |
| 3340 | fn a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders() { | 3129 | fn a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders() { |
| 3341 | let _knobs = crate::speed::knob_write(); | 3130 | let _knobs = crate::speed::knob_write(); |
| 3342 | - if !have_ffmpeg() { | ||
| 3343 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3344 | - return; | ||
| 3345 | - } | ||
| 3346 | force_sb128(true); | 3131 | force_sb128(true); |
| 3347 | let dir = std::env::temp_dir().join(format!("ec-av1-b128r-{}", std::process::id())); | 3132 | let dir = std::env::temp_dir().join(format!("ec-av1-b128r-{}", std::process::id())); |
| 3348 | std::fs::create_dir_all(&dir).unwrap(); | 3133 | std::fs::create_dir_all(&dir).unwrap(); |
| 3349 | let clip = dir.join("smpte-pan-1280x768.y4m"); | 3134 | let clip = dir.join("smpte-pan-1280x768.y4m"); |
| 3350 | - let ok = Command::new("ffmpeg") | 3135 | + let ok = ec_testkit::ffmpeg() |
| 3351 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3136 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3352 | .args(["-i", "smptebars=size=1600x768:rate=24"]) | 3137 | .args(["-i", "smptebars=size=1600x768:rate=24"]) |
| 3353 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) | 3138 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) |
| @@ -3433,17 +3218,13 @@ | |||
| 3433 | /// Runs only inside `superblock_size_global_suite`. | 3218 | /// Runs only inside `superblock_size_global_suite`. |
| 3434 | fn a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact() { | 3219 | fn a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact() { |
| 3435 | let _knobs = crate::speed::knob_write(); | 3220 | let _knobs = crate::speed::knob_write(); |
| 3436 | - if !have_ffmpeg() { | ||
| 3437 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3438 | - return; | ||
| 3439 | - } | ||
| 3440 | force_sb128(true); | 3221 | force_sb128(true); |
| 3441 | let dir = std::env::temp_dir().join(format!("ec-av1-edge128-{}", std::process::id())); | 3222 | let dir = std::env::temp_dir().join(format!("ec-av1-edge128-{}", std::process::id())); |
| 3442 | std::fs::create_dir_all(&dir).unwrap(); | 3223 | std::fs::create_dir_all(&dir).unwrap(); |
| 3443 | let clip = dir.join("testsrc2-1280x768.y4m"); | 3224 | let clip = dir.join("testsrc2-1280x768.y4m"); |
| 3444 | // Detailed synthetic content: its CDEF search spends more than one | 3225 | // Detailed synthetic content: its CDEF search spends more than one |
| 3445 | // strength pair, which is what puts a `cdef_idx` literal in the tile. | 3226 | // strength pair, which is what puts a `cdef_idx` literal in the tile. |
| 3446 | - let ok = Command::new("ffmpeg") | 3227 | + let ok = ec_testkit::ffmpeg() |
| 3447 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3228 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3448 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 3229 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 3449 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 3230 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
| @@ -3519,15 +3300,11 @@ | |||
| 3519 | /// Runs only inside `superblock_size_global_suite`. | 3300 | /// Runs only inside `superblock_size_global_suite`. |
| 3520 | fn a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders() { | 3301 | fn a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders() { |
| 3521 | let _knobs = crate::speed::knob_write(); | 3302 | let _knobs = crate::speed::knob_write(); |
| 3522 | - if !have_ffmpeg() { | ||
| 3523 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3524 | - return; | ||
| 3525 | - } | ||
| 3526 | force_sb128(true); | 3303 | force_sb128(true); |
| 3527 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-{}", std::process::id())); | 3304 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-{}", std::process::id())); |
| 3528 | std::fs::create_dir_all(&dir).unwrap(); | 3305 | std::fs::create_dir_all(&dir).unwrap(); |
| 3529 | let clip = dir.join("smpte-pan-1280x768.y4m"); | 3306 | let clip = dir.join("smpte-pan-1280x768.y4m"); |
| 3530 | - let ok = Command::new("ffmpeg") | 3307 | + let ok = ec_testkit::ffmpeg() |
| 3531 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3308 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3532 | .args(["-i", "smptebars=size=1600x768:rate=24"]) | 3309 | .args(["-i", "smptebars=size=1600x768:rate=24"]) |
| 3533 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) | 3310 | .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) |
| @@ -3603,15 +3380,11 @@ | |||
| 3603 | /// Runs only inside `superblock_size_global_suite`. | 3380 | /// Runs only inside `superblock_size_global_suite`. |
| 3604 | fn an_ab128_piece_with_a_real_residual_decodes_exact_through_both_decoders() { | 3381 | fn an_ab128_piece_with_a_real_residual_decodes_exact_through_both_decoders() { |
| 3605 | let _knobs = crate::speed::knob_write(); | 3382 | let _knobs = crate::speed::knob_write(); |
| 3606 | - if !have_ffmpeg() { | ||
| 3607 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3608 | - return; | ||
| 3609 | - } | ||
| 3610 | force_sb128(true); | 3383 | force_sb128(true); |
| 3611 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-ab-{}", std::process::id())); | 3384 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-ab-{}", std::process::id())); |
| 3612 | std::fs::create_dir_all(&dir).unwrap(); | 3385 | std::fs::create_dir_all(&dir).unwrap(); |
| 3613 | let clip = dir.join("testsrc2-1280x768.y4m"); | 3386 | let clip = dir.join("testsrc2-1280x768.y4m"); |
| 3614 | - let ok = Command::new("ffmpeg") | 3387 | + let ok = ec_testkit::ffmpeg() |
| 3615 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3388 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3616 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 3389 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 3617 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 3390 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
| @@ -3687,17 +3460,13 @@ | |||
| 3687 | /// Runs only inside `superblock_size_global_suite`. | 3460 | /// Runs only inside `superblock_size_global_suite`. |
| 3688 | fn a_rect128_residual_half_under_a_per_unit_cdef_list_decodes_exact() { | 3461 | fn a_rect128_residual_half_under_a_per_unit_cdef_list_decodes_exact() { |
| 3689 | let _knobs = crate::speed::knob_write(); | 3462 | let _knobs = crate::speed::knob_write(); |
| 3690 | - if !have_ffmpeg() { | ||
| 3691 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3692 | - return; | ||
| 3693 | - } | ||
| 3694 | force_sb128(true); | 3463 | force_sb128(true); |
| 3695 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-cdef-{}", std::process::id())); | 3464 | let dir = std::env::temp_dir().join(format!("ec-av1-rectres-cdef-{}", std::process::id())); |
| 3696 | std::fs::create_dir_all(&dir).unwrap(); | 3465 | std::fs::create_dir_all(&dir).unwrap(); |
| 3697 | let clip = dir.join("testsrc2-1280x768.y4m"); | 3466 | let clip = dir.join("testsrc2-1280x768.y4m"); |
| 3698 | // Detailed synthetic content: its CDEF search spends more than one | 3467 | // Detailed synthetic content: its CDEF search spends more than one |
| 3699 | // strength pair, which is what puts a `cdef_idx` literal in the tile. | 3468 | // strength pair, which is what puts a `cdef_idx` literal in the tile. |
| 3700 | - let ok = Command::new("ffmpeg") | 3469 | + let ok = ec_testkit::ffmpeg() |
| 3701 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3470 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3702 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 3471 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 3703 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 3472 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
| @@ -3767,10 +3536,6 @@ | |||
| 3767 | /// Runs only inside `superblock_size_global_suite`. | 3536 | /// Runs only inside `superblock_size_global_suite`. |
| 3768 | fn a_128_root_compound_block_decodes_exact_through_both_decoders() { | 3537 | fn a_128_root_compound_block_decodes_exact_through_both_decoders() { |
| 3769 | let _knobs = crate::speed::knob_write(); | 3538 | let _knobs = crate::speed::knob_write(); |
| 3770 | - if !have_ffmpeg() { | ||
| 3771 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3772 | - return; | ||
| 3773 | - } | ||
| 3774 | force_sb128(true); | 3539 | force_sb128(true); |
| 3775 | let dir = std::env::temp_dir().join(format!("ec-av1-b128c-{}", std::process::id())); | 3540 | let dir = std::env::temp_dir().join(format!("ec-av1-b128c-{}", std::process::id())); |
| 3776 | std::fs::create_dir_all(&dir).unwrap(); | 3541 | std::fs::create_dir_all(&dir).unwrap(); |
| @@ -3778,7 +3543,7 @@ | |||
| 3778 | // Moving objects that occlude each other: a pan is coded by one | 3543 | // Moving objects that occlude each other: a pan is coded by one |
| 3779 | // reference outright, and a compound pair only pays where the two | 3544 | // reference outright, and a compound pair only pays where the two |
| 3780 | // references disagree. | 3545 | // references disagree. |
| 3781 | - let ok = Command::new("ffmpeg") | 3546 | + let ok = ec_testkit::ffmpeg() |
| 3782 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3547 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3783 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 3548 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 3784 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 3549 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
| @@ -3858,15 +3623,11 @@ | |||
| 3858 | /// Runs only inside `superblock_size_global_suite`. | 3623 | /// Runs only inside `superblock_size_global_suite`. |
| 3859 | fn a_128_root_horz_and_vert_halves_decode_exact_through_both_decoders() { | 3624 | fn a_128_root_horz_and_vert_halves_decode_exact_through_both_decoders() { |
| 3860 | let _knobs = crate::speed::knob_write(); | 3625 | let _knobs = crate::speed::knob_write(); |
| 3861 | - if !have_ffmpeg() { | ||
| 3862 | - eprintln!("SKIP: no ffmpeg"); | ||
| 3863 | - return; | ||
| 3864 | - } | ||
| 3865 | force_sb128(true); | 3626 | force_sb128(true); |
| 3866 | let dir = std::env::temp_dir().join(format!("ec-av1-b128hv-{}", std::process::id())); | 3627 | let dir = std::env::temp_dir().join(format!("ec-av1-b128hv-{}", std::process::id())); |
| 3867 | std::fs::create_dir_all(&dir).unwrap(); | 3628 | std::fs::create_dir_all(&dir).unwrap(); |
| 3868 | let clip = dir.join("testsrc2-1280x768.y4m"); | 3629 | let clip = dir.join("testsrc2-1280x768.y4m"); |
| 3869 | - let ok = Command::new("ffmpeg") | 3630 | + let ok = ec_testkit::ffmpeg() |
| 3870 | .args(["-v", "error", "-y", "-f", "lavfi"]) | 3631 | .args(["-v", "error", "-y", "-f", "lavfi"]) |
| 3871 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) | 3632 | .args(["-i", "testsrc2=size=1280x768:rate=24"]) |
| 3872 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | 3633 | .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) |
crates/ec-av1/src/encoder/tests.rsmodified+32 -225
| @@ -1,28 +1,4 @@ | |||
| 1 | use super::*; | 1 | use super::*; |
| 2 | - use std::process::{Command, Stdio}; | ||
| 3 | - | ||
| 4 | - /// Whether ffmpeg is on PATH. Absence normally SKIPs, but | ||
| 5 | - /// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every | ||
| 6 | - /// aomenc gate decodes its stream through ffmpeg and is meaningless | ||
| 7 | - /// without it -- turns it into a hard failure. Without this the require | ||
| 8 | - /// flag was silently short-circuited: `!have_ffmpeg()` is evaluated first | ||
| 9 | - /// in `if !have_ffmpeg() || !have_aomenc()`, so a machine with no ffmpeg | ||
| 10 | - /// printed SKIP and reported green (class gate-skips-on-its-own-failure). | ||
| 11 | - fn have_ffmpeg() -> bool { | ||
| 12 | - let present = Command::new("ffmpeg") | ||
| 13 | - .arg("-version") | ||
| 14 | - .stdout(Stdio::null()) | ||
| 15 | - .stderr(Stdio::null()) | ||
| 16 | - .status() | ||
| 17 | - .is_ok_and(|s| s.success()); | ||
| 18 | - assert!( | ||
| 19 | - present | ||
| 20 | - || (std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_none() | ||
| 21 | - && std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none()), | ||
| 22 | - "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH" | ||
| 23 | - ); | ||
| 24 | - present | ||
| 25 | - } | ||
| 26 | 2 | ||
| 27 | fn test_card(width: usize, height: usize, shift: usize) -> Picture { | 3 | fn test_card(width: usize, height: usize, shift: usize) -> Picture { |
| 28 | let mut picture = Picture::grey(width, height); | 4 | let mut picture = Picture::grey(width, height); |
| @@ -332,7 +308,7 @@ | |||
| 332 | fn the_facade_codes_the_same_bytes_as_encode_sequence() { | 308 | fn the_facade_codes_the_same_bytes_as_encode_sequence() { |
| 333 | let _knobs = crate::speed::knob_read(); | 309 | let _knobs = crate::speed::knob_read(); |
| 334 | let frames = 12usize; | 310 | let frames = 12usize; |
| 335 | - let film = h264_clip_frames("the facade identity film arm", 640, 384, frames) | 311 | + let film = h264_clip_frames(640, 384, frames) |
| 336 | .unwrap_or_else(|| { | 312 | .unwrap_or_else(|| { |
| 337 | // The probe inside already printed the ONE line naming the | 313 | // The probe inside already printed the ONE line naming the |
| 338 | // resolved path and the escape hatch, so this is a note about | 314 | // resolved path and the escape hatch, so this is a note about |
| @@ -489,7 +465,7 @@ | |||
| 489 | std::ptr::addr_of!(stream) as usize | 465 | std::ptr::addr_of!(stream) as usize |
| 490 | )); | 466 | )); |
| 491 | std::fs::write(&path, stream).expect("writing the probe stream"); | 467 | std::fs::write(&path, stream).expect("writing the probe stream"); |
| 492 | - let out = crate::tool_cache::cached_output_io(Command::new("ffprobe") | 468 | + let out = ec_testkit::ffprobe() |
| 493 | .args([ | 469 | .args([ |
| 494 | "-v", | 470 | "-v", |
| 495 | "error", | 471 | "error", |
| @@ -502,7 +478,7 @@ | |||
| 502 | "-of", | 478 | "-of", |
| 503 | "csv=p=0", | 479 | "csv=p=0", |
| 504 | ]) | 480 | ]) |
| 505 | - .arg(&path), None, |c| c.output()) | 481 | + .arg(&path).output() |
| 506 | .expect("ffprobe failed to run"); | 482 | .expect("ffprobe failed to run"); |
| 507 | let _ = std::fs::remove_file(&path); | 483 | let _ = std::fs::remove_file(&path); |
| 508 | assert!( | 484 | assert!( |
| @@ -529,7 +505,7 @@ | |||
| 529 | std::ptr::addr_of!(stream) as usize | 505 | std::ptr::addr_of!(stream) as usize |
| 530 | )); | 506 | )); |
| 531 | std::fs::write(&path, stream).expect("writing the probe stream"); | 507 | std::fs::write(&path, stream).expect("writing the probe stream"); |
| 532 | - let out = crate::tool_cache::cached_output_io(Command::new("ffprobe") | 508 | + let out = ec_testkit::ffprobe() |
| 533 | .args([ | 509 | .args([ |
| 534 | "-v", | 510 | "-v", |
| 535 | "error", | 511 | "error", |
| @@ -542,7 +518,7 @@ | |||
| 542 | "-of", | 518 | "-of", |
| 543 | "csv=p=0", | 519 | "csv=p=0", |
| 544 | ]) | 520 | ]) |
| 545 | - .arg(&path), None, |c| c.output()) | 521 | + .arg(&path).output() |
| 546 | .expect("ffprobe failed to run"); | 522 | .expect("ffprobe failed to run"); |
| 547 | let _ = std::fs::remove_file(&path); | 523 | let _ = std::fs::remove_file(&path); |
| 548 | assert!( | 524 | assert!( |
| @@ -560,10 +536,6 @@ | |||
| 560 | #[test] | 536 | #[test] |
| 561 | fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() { | 537 | fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() { |
| 562 | let _knobs = crate::speed::knob_read(); | 538 | let _knobs = crate::speed::knob_read(); |
| 563 | - if !have_ffmpeg() { | ||
| 564 | - eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg"); | ||
| 565 | - return; | ||
| 566 | - } | ||
| 567 | let (width, height) = (96usize, 96usize); | 539 | let (width, height) = (96usize, 96usize); |
| 568 | let config = EncoderConfig { | 540 | let config = EncoderConfig { |
| 569 | width, | 541 | width, |
| @@ -616,10 +588,6 @@ | |||
| 616 | #[test] | 588 | #[test] |
| 617 | fn bt709_limited_colour_is_reported_by_ffprobe() { | 589 | fn bt709_limited_colour_is_reported_by_ffprobe() { |
| 618 | let _knobs = crate::speed::knob_read(); | 590 | let _knobs = crate::speed::knob_read(); |
| 619 | - if !have_ffmpeg() { | ||
| 620 | - eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg"); | ||
| 621 | - return; | ||
| 622 | - } | ||
| 623 | let config = EncoderConfig { | 591 | let config = EncoderConfig { |
| 624 | width: 64, | 592 | width: 64, |
| 625 | height: 64, | 593 | height: 64, |
| @@ -641,10 +609,6 @@ | |||
| 641 | #[test] | 609 | #[test] |
| 642 | fn bt601_limited_colour_is_reported_by_ffprobe() { | 610 | fn bt601_limited_colour_is_reported_by_ffprobe() { |
| 643 | let _knobs = crate::speed::knob_read(); | 611 | let _knobs = crate::speed::knob_read(); |
| 644 | - if !have_ffmpeg() { | ||
| 645 | - eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg"); | ||
| 646 | - return; | ||
| 647 | - } | ||
| 648 | let config = EncoderConfig { | 612 | let config = EncoderConfig { |
| 649 | width: 64, | 613 | width: 64, |
| 650 | height: 64, | 614 | height: 64, |
| @@ -704,26 +668,11 @@ | |||
| 704 | /// to this facade's own input size, and re-coded through the facade so the | 668 | /// to this facade's own input size, and re-coded through the facade so the |
| 705 | /// rate-target surface is exercised at the entry point a caller actually | 669 | /// rate-target surface is exercised at the entry point a caller actually |
| 706 | /// drives. | 670 | /// drives. |
| 707 | - /// | ||
| 708 | - /// lane-av1clipprobe: the ABSENCE of this clip used to be a bare | ||
| 709 | - /// `clip.exists()` -> `None`, and every caller turned that into a `SKIP` | ||
| 710 | - /// line and a return -- so a tree with no root `fixtures/` printed | ||
| 711 | - /// `SKIP the 1080p tile round trip: no fixture` and libtest reported `ok`: | ||
| 712 | - /// green with nothing asserted, and no env that made it RED. The presence | ||
| 713 | - /// check now lives in the crate's one library-fixture probe | ||
| 714 | - /// (`library_fixture::require_at`), which fails under `EC_REQUIRE_FIXTURES` / | ||
| 715 | - /// `EC_AV1_REQUIRE_FFMPEG` / `EC_AV1_REQUIRE_AOMENC` and otherwise prints | ||
| 716 | - /// that ONE line. | ||
| 717 | fn h264_clip_frames( | 671 | fn h264_clip_frames( |
| 718 | - what: &str, | ||
| 719 | width: usize, | 672 | width: usize, |
| 720 | height: usize, | 673 | height: usize, |
| 721 | frames: usize, | 674 | frames: usize, |
| 722 | ) -> Option<Vec<Picture>> { | 675 | ) -> Option<Vec<Picture>> { |
| 723 | - if !have_ffmpeg() { | ||
| 724 | - eprintln!("SKIP {what}: no ffmpeg"); | ||
| 725 | - return None; | ||
| 726 | - } | ||
| 727 | // lane-av1speed3: the wall tables below are read on REAL film as | 676 | // lane-av1speed3: the wall tables below are read on REAL film as |
| 728 | // well as on the colour-bar fixture (`bars` vs `film` in the BD | 677 | // well as on the colour-bar fixture (`bars` vs `film` in the BD |
| 729 | // gate's own vocabulary), and the film crop lives outside the repo -- | 678 | // gate's own vocabulary), and the film crop lives outside the repo -- |
| @@ -737,19 +686,18 @@ | |||
| 737 | // pointing EC_FIXTURES somewhere the gates do not read. | 686 | // pointing EC_FIXTURES somewhere the gates do not read. |
| 738 | let clip = match std::env::var("EC_AV1_WALL_CLIP") { | 687 | let clip = match std::env::var("EC_AV1_WALL_CLIP") { |
| 739 | Ok(p) => std::path::PathBuf::from(p), | 688 | Ok(p) => std::path::PathBuf::from(p), |
| 740 | - Err(_) => crate::library_fixture::path("video/h264-1080p-23.976-8bit.mp4"), | 689 | + Err(_) => ec_testkit::fixture("open/sintel_trailer-1080p.mp4"), |
| 741 | }; | 690 | }; |
| 742 | // `what` is the CALLING GATE's name, carried in so that both exits from | 691 | // `what` is the CALLING GATE's name, carried in so that both exits from |
| 743 | // this function print exactly one line naming it: the ffmpeg line | 692 | // this function print exactly one line naming it: the ffmpeg line |
| 744 | // above, and the probe's line naming the resolved path. Callers | 693 | // above, and the probe's line naming the resolved path. Callers |
| 745 | // therefore `return` on `None` WITHOUT printing a second one -- the | 694 | // therefore `return` on `None` WITHOUT printing a second one -- the |
| 746 | // second "no fixture" line per gate was the noise that hid this defect. | 695 | // second "no fixture" line per gate was the noise that hid this defect. |
| 747 | - let clip = crate::library_fixture::require_at(clip, what)?; | 696 | + let out = ec_testkit::ffmpeg() |
| 748 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 749 | .args(["-v", "error", "-i", clip.to_str().unwrap()]) | 697 | .args(["-v", "error", "-i", clip.to_str().unwrap()]) |
| 750 | .args(["-frames:v", &frames.to_string()]) | 698 | .args(["-frames:v", &frames.to_string()]) |
| 751 | .args(["-vf", &format!("scale={width}:{height}")]) | 699 | .args(["-vf", &format!("scale={width}:{height}")]) |
| 752 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]), None, |c| c.output()) | 700 | + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]).output() |
| 753 | .expect("ffmpeg failed to run"); | 701 | .expect("ffmpeg failed to run"); |
| 754 | assert!( | 702 | assert!( |
| 755 | out.status.success(), | 703 | out.status.success(), |
| @@ -792,9 +740,7 @@ | |||
| 792 | #[test] | 740 | #[test] |
| 793 | fn bytes_per_frame_target_settles_within_20_percent() { | 741 | fn bytes_per_frame_target_settles_within_20_percent() { |
| 794 | let _knobs = crate::speed::knob_read(); | 742 | let _knobs = crate::speed::knob_read(); |
| 795 | - let Some(pictures) = h264_clip_frames( | 743 | + let Some(pictures) = h264_clip_frames(640, |
| 796 | - "bytes_per_frame_target_settles_within_20_percent", | ||
| 797 | - 640, | ||
| 798 | 384, | 744 | 384, |
| 799 | 24, | 745 | 24, |
| 800 | ) else { | 746 | ) else { |
| @@ -973,9 +919,7 @@ | |||
| 973 | fn bitrate_target_lands_within_5_percent_over_48_frames() { | 919 | fn bitrate_target_lands_within_5_percent_over_48_frames() { |
| 974 | let _knobs = crate::speed::knob_read(); | 920 | let _knobs = crate::speed::knob_read(); |
| 975 | let (width, height, frames) = (640usize, 384usize, 48usize); | 921 | let (width, height, frames) = (640usize, 384usize, 48usize); |
| 976 | - let Some(pictures) = h264_clip_frames( | 922 | + let Some(pictures) = h264_clip_frames(width, |
| 977 | - "bitrate_target_lands_within_5_percent_over_48_frames", | ||
| 978 | - width, | ||
| 979 | height, | 923 | height, |
| 980 | frames, | 924 | frames, |
| 981 | ) else { | 925 | ) else { |
| @@ -1140,9 +1084,7 @@ | |||
| 1140 | #[test] | 1084 | #[test] |
| 1141 | fn bytes_per_frame_controller_never_oscillates_past_its_clamp() { | 1085 | fn bytes_per_frame_controller_never_oscillates_past_its_clamp() { |
| 1142 | let _knobs = crate::speed::knob_read(); | 1086 | let _knobs = crate::speed::knob_read(); |
| 1143 | - let Some(pictures) = h264_clip_frames( | 1087 | + let Some(pictures) = h264_clip_frames(640, |
| 1144 | - "bytes_per_frame_controller_never_oscillates_past_its_clamp", | ||
| 1145 | - 640, | ||
| 1146 | 384, | 1088 | 384, |
| 1147 | 24, | 1089 | 24, |
| 1148 | ) else { | 1090 | ) else { |
| @@ -1217,10 +1159,10 @@ | |||
| 1217 | std::ptr::addr_of!(stream) as usize | 1159 | std::ptr::addr_of!(stream) as usize |
| 1218 | )); | 1160 | )); |
| 1219 | std::fs::write(&path, stream).expect("writing the decode probe stream"); | 1161 | std::fs::write(&path, stream).expect("writing the decode probe stream"); |
| 1220 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | 1162 | + let out = ec_testkit::ffmpeg() |
| 1221 | .args(["-v", "error", "-f", "obu", "-i"]) | 1163 | .args(["-v", "error", "-f", "obu", "-i"]) |
| 1222 | .arg(&path) | 1164 | .arg(&path) |
| 1223 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]), None, |c| c.output()) | 1165 | + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]).output() |
| 1224 | .expect("ffmpeg failed to run"); | 1166 | .expect("ffmpeg failed to run"); |
| 1225 | let _ = std::fs::remove_file(&path); | 1167 | let _ = std::fs::remove_file(&path); |
| 1226 | assert!( | 1168 | assert!( |
| @@ -1269,7 +1211,6 @@ | |||
| 1269 | fn a_palette_block_cut_by_the_frame_edge_decodes_exactly_through_ffmpeg() { | 1211 | fn a_palette_block_cut_by_the_frame_edge_decodes_exactly_through_ffmpeg() { |
| 1270 | const NAME: &str = "a_palette_block_cut_by_the_frame_edge_decodes_exactly_through_ffmpeg"; | 1212 | const NAME: &str = "a_palette_block_cut_by_the_frame_edge_decodes_exactly_through_ffmpeg"; |
| 1271 | let _knobs = crate::speed::knob_read(); | 1213 | let _knobs = crate::speed::knob_read(); |
| 1272 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 1273 | let (width, height) = (384usize, 152usize); | 1214 | let (width, height) = (384usize, 152usize); |
| 1274 | // A 16-px two-tone checkerboard: every 16x16 and 32x32 block holds at | 1215 | // A 16-px two-tone checkerboard: every 16x16 and 32x32 block holds at |
| 1275 | // most two luma values, so the palette arm wins across the WHOLE | 1216 | // most two luma values, so the palette arm wins across the WHOLE |
| @@ -1313,10 +1254,6 @@ | |||
| 1313 | ); | 1254 | ); |
| 1314 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 1255 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 1315 | assert_eq!(ours.len(), sources.len(), "{NAME}: our decoder's frames"); | 1256 | assert_eq!(ours.len(), sources.len(), "{NAME}: our decoder's frames"); |
| 1316 | - if !have_ffmpeg() { | ||
| 1317 | - eprintln!("SKIP the ffmpeg half of {NAME}: no ffmpeg"); | ||
| 1318 | - return; | ||
| 1319 | - } | ||
| 1320 | let theirs = ffmpeg_decode_planes(&stream, width, height); | 1257 | let theirs = ffmpeg_decode_planes(&stream, width, height); |
| 1321 | assert_eq!(theirs.len(), sources.len(), "{NAME}: ffmpeg's frames"); | 1258 | assert_eq!(theirs.len(), sources.len(), "{NAME}: ffmpeg's frames"); |
| 1322 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1259 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -1526,10 +1463,6 @@ | |||
| 1526 | sources.len(), | 1463 | sources.len(), |
| 1527 | "our decoder's display-order count" | 1464 | "our decoder's display-order count" |
| 1528 | ); | 1465 | ); |
| 1529 | - if !have_ffmpeg() { | ||
| 1530 | - eprintln!("SKIP the ffmpeg half of the LAST2 witness: no ffmpeg"); | ||
| 1531 | - return; | ||
| 1532 | - } | ||
| 1533 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 1466 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 1534 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's display-order count"); | 1467 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's display-order count"); |
| 1535 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1468 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -1674,9 +1607,6 @@ | |||
| 1674 | n, | 1607 | n, |
| 1675 | "{n} pictures at gop {gop}: our decoder's count" | 1608 | "{n} pictures at gop {gop}: our decoder's count" |
| 1676 | ); | 1609 | ); |
| 1677 | - if !have_ffmpeg() { | ||
| 1678 | - continue; | ||
| 1679 | - } | ||
| 1680 | let theirs = ffmpeg_decode_luma(&held, width, height); | 1610 | let theirs = ffmpeg_decode_luma(&held, width, height); |
| 1681 | assert_eq!(theirs.len(), n, "{n} pictures at gop {gop}: ffmpeg's count"); | 1611 | assert_eq!(theirs.len(), n, "{n} pictures at gop {gop}: ffmpeg's count"); |
| 1682 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1612 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -1705,7 +1635,7 @@ | |||
| 1705 | ); | 1635 | ); |
| 1706 | let ours = crate::stream::decode_stream(&symmetric).expect("our decoder"); | 1636 | let ours = crate::stream::decode_stream(&symmetric).expect("our decoder"); |
| 1707 | assert_eq!(ours.len(), 17, "the symmetric arm's display-order count"); | 1637 | assert_eq!(ours.len(), 17, "the symmetric arm's display-order count"); |
| 1708 | - if have_ffmpeg() { | 1638 | + { |
| 1709 | let theirs = ffmpeg_decode_luma(&symmetric, width, height); | 1639 | let theirs = ffmpeg_decode_luma(&symmetric, width, height); |
| 1710 | assert_eq!(theirs.len(), 17, "the symmetric arm's ffmpeg count"); | 1640 | assert_eq!(theirs.len(), 17, "the symmetric arm's ffmpeg count"); |
| 1711 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1641 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -1780,9 +1710,6 @@ | |||
| 1780 | n, | 1710 | n, |
| 1781 | "{n} pictures at gop {gop} mode {mode}: our count" | 1711 | "{n} pictures at gop {gop} mode {mode}: our count" |
| 1782 | ); | 1712 | ); |
| 1783 | - if !have_ffmpeg() { | ||
| 1784 | - continue; | ||
| 1785 | - } | ||
| 1786 | let theirs = ffmpeg_decode_luma(&on, width, height); | 1713 | let theirs = ffmpeg_decode_luma(&on, width, height); |
| 1787 | assert_eq!( | 1714 | assert_eq!( |
| 1788 | theirs.len(), | 1715 | theirs.len(), |
| @@ -1920,9 +1847,6 @@ | |||
| 1920 | ); | 1847 | ); |
| 1921 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); | 1848 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); |
| 1922 | assert_eq!(ours.len(), 17, "mode {mode}: our decoder's picture count"); | 1849 | assert_eq!(ours.len(), 17, "mode {mode}: our decoder's picture count"); |
| 1923 | - if !have_ffmpeg() { | ||
| 1924 | - continue; | ||
| 1925 | - } | ||
| 1926 | let theirs = ffmpeg_decode_luma(&on, width, height); | 1850 | let theirs = ffmpeg_decode_luma(&on, width, height); |
| 1927 | assert_eq!(theirs.len(), 17, "mode {mode}: ffmpeg's picture count"); | 1851 | assert_eq!(theirs.len(), 17, "mode {mode}: ffmpeg's picture count"); |
| 1928 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1852 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2018,10 +1942,6 @@ | |||
| 2018 | sources.len(), | 1942 | sources.len(), |
| 2019 | "our decoder's display-order count" | 1943 | "our decoder's display-order count" |
| 2020 | ); | 1944 | ); |
| 2021 | - if !have_ffmpeg() { | ||
| 2022 | - eprintln!("SKIP the ffmpeg half of the pyramid round trip: no ffmpeg"); | ||
| 2023 | - return; | ||
| 2024 | - } | ||
| 2025 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 1945 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2026 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's display-order count"); | 1946 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's display-order count"); |
| 2027 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 1947 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2073,7 +1993,6 @@ | |||
| 2073 | /// Runs only inside `superblock_size_global_suite`. | 1993 | /// Runs only inside `superblock_size_global_suite`. |
| 2074 | pub(crate) fn a_static_clip_codes_128x128_superblock_roots_and_decodes_sample_exact() { | 1994 | pub(crate) fn a_static_clip_codes_128x128_superblock_roots_and_decodes_sample_exact() { |
| 2075 | let _knobs = crate::speed::knob_write(); | 1995 | let _knobs = crate::speed::knob_write(); |
| 2076 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2077 | crate::encode::force_sb128(true); | 1996 | crate::encode::force_sb128(true); |
| 2078 | let (width, height) = (256usize, 128usize); | 1997 | let (width, height) = (256usize, 128usize); |
| 2079 | let still = test_card(width, height, 0); | 1998 | let still = test_card(width, height, 0); |
| @@ -2106,10 +2025,6 @@ | |||
| 2106 | crate::decode::part128_split_hits() >= 4, | 2025 | crate::decode::part128_split_hits() >= 4, |
| 2107 | "our decoder read no 128x128 superblock root" | 2026 | "our decoder read no 128x128 superblock root" |
| 2108 | ); | 2027 | ); |
| 2109 | - if !have_ffmpeg() { | ||
| 2110 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2111 | - return; | ||
| 2112 | - } | ||
| 2113 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2028 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2114 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2029 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2115 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2030 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2121,7 +2036,6 @@ | |||
| 2121 | #[test] | 2036 | #[test] |
| 2122 | fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() { | 2037 | fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() { |
| 2123 | let _knobs = crate::speed::knob_write(); | 2038 | let _knobs = crate::speed::knob_write(); |
| 2124 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2125 | let (width, height) = (256usize, 128usize); | 2039 | let (width, height) = (256usize, 128usize); |
| 2126 | let still = test_card(width, height, 0); | 2040 | let still = test_card(width, height, 0); |
| 2127 | let sources: Vec<Picture> = (0..3).map(|_| still.clone()).collect(); | 2041 | let sources: Vec<Picture> = (0..3).map(|_| still.clone()).collect(); |
| @@ -2150,10 +2064,6 @@ | |||
| 2150 | 2064 | ||
| 2151 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2065 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2152 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2066 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2153 | - if !have_ffmpeg() { | ||
| 2154 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2155 | - return; | ||
| 2156 | - } | ||
| 2157 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2067 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2158 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2068 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2159 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2069 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2190,7 +2100,6 @@ | |||
| 2190 | #[test] | 2100 | #[test] |
| 2191 | fn a_dc_stepped_clip_codes_a_64x64_residual_and_decodes_sample_exact() { | 2101 | fn a_dc_stepped_clip_codes_a_64x64_residual_and_decodes_sample_exact() { |
| 2192 | let _knobs = crate::speed::knob_write(); | 2102 | let _knobs = crate::speed::knob_write(); |
| 2193 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2194 | let (width, height) = (256usize, 128usize); | 2103 | let (width, height) = (256usize, 128usize); |
| 2195 | let still = test_card(width, height, 0); | 2104 | let still = test_card(width, height, 0); |
| 2196 | let sources: Vec<Picture> = (0..3) | 2105 | let sources: Vec<Picture> = (0..3) |
| @@ -2227,10 +2136,6 @@ | |||
| 2227 | 2136 | ||
| 2228 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2137 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2229 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2138 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2230 | - if !have_ffmpeg() { | ||
| 2231 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2232 | - return; | ||
| 2233 | - } | ||
| 2234 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2139 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2235 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2140 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2236 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2141 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2264,7 +2169,6 @@ | |||
| 2264 | #[test] | 2169 | #[test] |
| 2265 | fn a_non_superblock_aligned_clip_codes_edge_64x64_roots_and_decodes_sample_exact() { | 2170 | fn a_non_superblock_aligned_clip_codes_edge_64x64_roots_and_decodes_sample_exact() { |
| 2266 | let _knobs = crate::speed::knob_write(); | 2171 | let _knobs = crate::speed::knob_write(); |
| 2267 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2268 | let (width, height) = (232usize, 168usize); | 2172 | let (width, height) = (232usize, 168usize); |
| 2269 | let still = test_card(width, height, 0); | 2173 | let still = test_card(width, height, 0); |
| 2270 | let sources: Vec<Picture> = (0..3).map(|_| still.clone()).collect(); | 2174 | let sources: Vec<Picture> = (0..3).map(|_| still.clone()).collect(); |
| @@ -2292,10 +2196,6 @@ | |||
| 2292 | 2196 | ||
| 2293 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2197 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2294 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2198 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2295 | - if !have_ffmpeg() { | ||
| 2296 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2297 | - return; | ||
| 2298 | - } | ||
| 2299 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2199 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2300 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2200 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2301 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | 2201 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2330,7 +2230,6 @@ | |||
| 2330 | #[test] | 2230 | #[test] |
| 2331 | fn a_1080p_shaped_clip_straddles_at_every_block_size_and_decodes_sample_exact() { | 2231 | fn a_1080p_shaped_clip_straddles_at_every_block_size_and_decodes_sample_exact() { |
| 2332 | let _knobs = crate::speed::knob_write(); | 2232 | let _knobs = crate::speed::knob_write(); |
| 2333 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2334 | let (width, height) = (384usize, 216usize); | 2233 | let (width, height) = (384usize, 216usize); |
| 2335 | let sources: Vec<Picture> = (0..3).map(|i| test_card(width, height, i)).collect(); | 2234 | let sources: Vec<Picture> = (0..3).map(|i| test_card(width, height, i)).collect(); |
| 2336 | let config = EncoderConfig { | 2235 | let config = EncoderConfig { |
| @@ -2349,10 +2248,6 @@ | |||
| 2349 | } | 2248 | } |
| 2350 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2249 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2351 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2250 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2352 | - if !have_ffmpeg() { | ||
| 2353 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2354 | - return; | ||
| 2355 | - } | ||
| 2356 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2251 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2357 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2252 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2358 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | 2253 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2387,7 +2282,6 @@ | |||
| 2387 | #[test] | 2282 | #[test] |
| 2388 | fn a_high_frequency_clip_splits_the_64x64_roots_luma_and_decodes_sample_exact() { | 2283 | fn a_high_frequency_clip_splits_the_64x64_roots_luma_and_decodes_sample_exact() { |
| 2389 | let _knobs = crate::speed::knob_write(); | 2284 | let _knobs = crate::speed::knob_write(); |
| 2390 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2391 | let (width, height) = (256usize, 128usize); | 2285 | let (width, height) = (256usize, 128usize); |
| 2392 | let still = test_card(width, height, 0); | 2286 | let still = test_card(width, height, 0); |
| 2393 | let sources: Vec<Picture> = (0..4) | 2287 | let sources: Vec<Picture> = (0..4) |
| @@ -2422,10 +2316,6 @@ | |||
| 2422 | 2316 | ||
| 2423 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2317 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2424 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2318 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2425 | - if !have_ffmpeg() { | ||
| 2426 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2427 | - return; | ||
| 2428 | - } | ||
| 2429 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2319 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2430 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2320 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2431 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | 2321 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2460,7 +2350,6 @@ | |||
| 2460 | #[test] | 2350 | #[test] |
| 2461 | fn a_crossfade_clip_codes_a_compound_64x64_root_and_decodes_sample_exact() { | 2351 | fn a_crossfade_clip_codes_a_compound_64x64_root_and_decodes_sample_exact() { |
| 2462 | let _knobs = crate::speed::knob_write(); | 2352 | let _knobs = crate::speed::knob_write(); |
| 2463 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2464 | let (width, height) = (256usize, 128usize); | 2353 | let (width, height) = (256usize, 128usize); |
| 2465 | let (a, b) = (test_card(width, height, 0), test_card(width, height, 24)); | 2354 | let (a, b) = (test_card(width, height, 0), test_card(width, height, 24)); |
| 2466 | let sources: Vec<Picture> = (0..9) | 2355 | let sources: Vec<Picture> = (0..9) |
| @@ -2497,10 +2386,6 @@ | |||
| 2497 | 2386 | ||
| 2498 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2387 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2499 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2388 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2500 | - if !have_ffmpeg() { | ||
| 2501 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2502 | - return; | ||
| 2503 | - } | ||
| 2504 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2389 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2505 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2390 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2506 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | 2391 | for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2589,10 +2474,6 @@ | |||
| 2589 | 2474 | ||
| 2590 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2475 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2591 | assert_eq!(ours.len(), sources.len(), "{layout}: our decoder's frames"); | 2476 | assert_eq!(ours.len(), sources.len(), "{layout}: our decoder's frames"); |
| 2592 | - if !have_ffmpeg() { | ||
| 2593 | - eprintln!("SKIP the ffmpeg half of {layout}: no ffmpeg"); | ||
| 2594 | - continue; | ||
| 2595 | - } | ||
| 2596 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2477 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2597 | assert_eq!(theirs.len(), sources.len(), "{layout}: ffmpeg's frames"); | 2478 | assert_eq!(theirs.len(), sources.len(), "{layout}: ffmpeg's frames"); |
| 2598 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2479 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2630,7 +2511,6 @@ | |||
| 2630 | // `knob_write`, not `knob_read`: the override below is | 2511 | // `knob_write`, not `knob_read`: the override below is |
| 2631 | // process-global and every other test's bytes move under it. | 2512 | // process-global and every other test's bytes move under it. |
| 2632 | let _knobs = crate::speed::knob_write(); | 2513 | let _knobs = crate::speed::knob_write(); |
| 2633 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2634 | crate::encode::set_deltaq_res(Some(2)); | 2514 | crate::encode::set_deltaq_res(Some(2)); |
| 2635 | let (width, height) = (640usize, 384usize); | 2515 | let (width, height) = (640usize, 384usize); |
| 2636 | // The gate's own moving test card, with a 128x128 patch of fine | 2516 | // The gate's own moving test card, with a 128x128 patch of fine |
| @@ -2676,15 +2556,10 @@ | |||
| 2676 | levels >= 2, | 2556 | levels >= 2, |
| 2677 | "the quantizer grid was flat ({levels} level(s)): no delta_qindex was coded" | 2557 | "the quantizer grid was flat ({levels} level(s)): no delta_qindex was coded" |
| 2678 | ); | 2558 | ); |
| 2679 | - } else { | ||
| 2680 | - eprintln!( | ||
| 2681 | - "SKIP the fire count at preset {}: no tpl map", | ||
| 2682 | - crate::speed::speed() | ||
| 2683 | - ); | ||
| 2684 | } | 2559 | } |
| 2685 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2560 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2686 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2561 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2687 | - if have_ffmpeg() { | 2562 | + { |
| 2688 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2563 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2689 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2564 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2690 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2565 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2706,8 +2581,6 @@ | |||
| 2706 | b.len() | 2581 | b.len() |
| 2707 | ); | 2582 | ); |
| 2708 | } | 2583 | } |
| 2709 | - } else { | ||
| 2710 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2711 | } | 2584 | } |
| 2712 | crate::encode::set_deltaq_res(None); | 2585 | crate::encode::set_deltaq_res(None); |
| 2713 | eprintln!( | 2586 | eprintln!( |
| @@ -2730,7 +2603,6 @@ | |||
| 2730 | // type search is SCREEN-ONLY (`encode::tx_type_candidates`). | 2603 | // type search is SCREEN-ONLY (`encode::tx_type_candidates`). |
| 2731 | let _knobs = crate::speed::knob_write(); | 2604 | let _knobs = crate::speed::knob_write(); |
| 2732 | crate::encode::force_screen(Some(true)); | 2605 | crate::encode::force_screen(Some(true)); |
| 2733 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2734 | let (width, height) = (320usize, 192usize); | 2606 | let (width, height) = (320usize, 192usize); |
| 2735 | // Sharp horizontal and vertical steps: a vertical edge is what an | 2607 | // Sharp horizontal and vertical steps: a vertical edge is what an |
| 2736 | // `ADST` column pass beats a `DCT` one on, a horizontal edge the | 2608 | // `ADST` column pass beats a `DCT` one on, a horizontal edge the |
| @@ -2798,15 +2670,10 @@ | |||
| 2798 | "no luma transform unit took {name}: {hits:?}" | 2670 | "no luma transform unit took {name}: {hits:?}" |
| 2799 | ); | 2671 | ); |
| 2800 | } | 2672 | } |
| 2801 | - } else { | ||
| 2802 | - eprintln!( | ||
| 2803 | - "SKIP the five-type fire count at preset {}: {hits:?}", | ||
| 2804 | - crate::speed::speed() | ||
| 2805 | - ); | ||
| 2806 | } | 2673 | } |
| 2807 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2674 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2808 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2675 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2809 | - if have_ffmpeg() { | 2676 | + { |
| 2810 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2677 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2811 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2678 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2812 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2679 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2828,8 +2695,6 @@ | |||
| 2828 | b.len() | 2695 | b.len() |
| 2829 | ); | 2696 | ); |
| 2830 | } | 2697 | } |
| 2831 | - } else { | ||
| 2832 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2833 | } | 2698 | } |
| 2834 | crate::encode::force_screen(None); | 2699 | crate::encode::force_screen(None); |
| 2835 | eprintln!("tx_type witness: hits {hits:?}, {} bytes", stream.len()); | 2700 | eprintln!("tx_type witness: hits {hits:?}, {} bytes", stream.len()); |
| @@ -2847,7 +2712,6 @@ | |||
| 2847 | // this turns it on process-globally under the same exclusive lock the | 2712 | // this turns it on process-globally under the same exclusive lock the |
| 2848 | // presets take. | 2713 | // presets take. |
| 2849 | let _knobs = crate::speed::knob_write(); | 2714 | let _knobs = crate::speed::knob_write(); |
| 2850 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2851 | crate::encode::set_inter_tx_search(Some(true)); | 2715 | crate::encode::set_inter_tx_search(Some(true)); |
| 2852 | let (width, height) = (320usize, 192usize); | 2716 | let (width, height) = (320usize, 192usize); |
| 2853 | // Sharp steps that MOVE: the motion-compensated residual along a | 2717 | // Sharp steps that MOVE: the motion-compensated residual along a |
| @@ -2898,7 +2762,7 @@ | |||
| 2898 | } | 2762 | } |
| 2899 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2763 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 2900 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2764 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 2901 | - if have_ffmpeg() { | 2765 | + { |
| 2902 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2766 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 2903 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2767 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 2904 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2768 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -2920,8 +2784,6 @@ | |||
| 2920 | b.len() | 2784 | b.len() |
| 2921 | ); | 2785 | ); |
| 2922 | } | 2786 | } |
| 2923 | - } else { | ||
| 2924 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2925 | } | 2787 | } |
| 2926 | eprintln!( | 2788 | eprintln!( |
| 2927 | "inter tx_type witness: hits {hits:?}, {} bytes", | 2789 | "inter tx_type witness: hits {hits:?}, {} bytes", |
| @@ -2945,7 +2807,6 @@ | |||
| 2945 | // Every lever below is process-global: the same exclusive lock the | 2807 | // Every lever below is process-global: the same exclusive lock the |
| 2946 | // presets take. | 2808 | // presets take. |
| 2947 | let _knobs = crate::speed::knob_write(); | 2809 | let _knobs = crate::speed::knob_write(); |
| 2948 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2949 | crate::encode::set_intra_tx_search(Some(true)); | 2810 | crate::encode::set_intra_tx_search(Some(true)); |
| 2950 | crate::encode::set_inter_tx_search(Some(true)); | 2811 | crate::encode::set_inter_tx_search(Some(true)); |
| 2951 | crate::encode::set_wide_tx_set(Some(true)); | 2812 | crate::encode::set_wide_tx_set(Some(true)); |
| @@ -3020,15 +2881,10 @@ | |||
| 3020 | inter.iter().sum::<usize>() > 0, | 2881 | inter.iter().sum::<usize>() > 0, |
| 3021 | "the clip coded no inter luma transform unit at all: {inter:?}" | 2882 | "the clip coded no inter luma transform unit at all: {inter:?}" |
| 3022 | ); | 2883 | ); |
| 3023 | - } else { | ||
| 3024 | - eprintln!( | ||
| 3025 | - "SKIP the wide-alphabet fire count at preset {}", | ||
| 3026 | - crate::speed::speed() | ||
| 3027 | - ); | ||
| 3028 | } | 2884 | } |
| 3029 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2885 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 3030 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2886 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 3031 | - if have_ffmpeg() { | 2887 | + { |
| 3032 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 2888 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 3033 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2889 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 3034 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 2890 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -3050,8 +2906,6 @@ | |||
| 3050 | b.len() | 2906 | b.len() |
| 3051 | ); | 2907 | ); |
| 3052 | } | 2908 | } |
| 3053 | - } else { | ||
| 3054 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 3055 | } | 2909 | } |
| 3056 | } | 2910 | } |
| 3057 | /// lane-intertx's witness: on a clip the screen detector calls | 2911 | /// lane-intertx's witness: on a clip the screen detector calls |
| @@ -3067,7 +2921,6 @@ | |||
| 3067 | #[ignore = "sets process-global search levers: run it alone"] | 2921 | #[ignore = "sets process-global search levers: run it alone"] |
| 3068 | fn a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly() { | 2922 | fn a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly() { |
| 3069 | let _knobs = crate::speed::knob_write(); | 2923 | let _knobs = crate::speed::knob_write(); |
| 3070 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3071 | crate::encode::set_intra_tx_search(Some(true)); | 2924 | crate::encode::set_intra_tx_search(Some(true)); |
| 3072 | crate::encode::set_inter_tx_search(Some(true)); | 2925 | crate::encode::set_inter_tx_search(Some(true)); |
| 3073 | crate::encode::set_wide_tx_set(Some(true)); | 2926 | crate::encode::set_wide_tx_set(Some(true)); |
| @@ -3130,7 +2983,7 @@ | |||
| 3130 | ); | 2983 | ); |
| 3131 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 2984 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 3132 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 2985 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| 3133 | - if have_ffmpeg() { | 2986 | + { |
| 3134 | let theirs = ffmpeg_decode_planes(&stream, width, height); | 2987 | let theirs = ffmpeg_decode_planes(&stream, width, height); |
| 3135 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 2988 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 3136 | let (cw, ch) = (width / 2, height / 2); | 2989 | let (cw, ch) = (width / 2, height / 2); |
| @@ -3153,8 +3006,6 @@ | |||
| 3153 | } | 3006 | } |
| 3154 | } | 3007 | } |
| 3155 | } | 3008 | } |
| 3156 | - } else { | ||
| 3157 | - eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 3158 | } | 3009 | } |
| 3159 | } | 3010 | } |
| 3160 | 3011 | ||
| @@ -3173,7 +3024,6 @@ | |||
| 3173 | #[ignore = "sets the process-global speed preset: run it alone"] | 3024 | #[ignore = "sets the process-global speed preset: run it alone"] |
| 3174 | fn every_speed_preset_decodes_sample_exact_through_both_decoders() { | 3025 | fn every_speed_preset_decodes_sample_exact_through_both_decoders() { |
| 3175 | let _knobs = crate::speed::knob_write(); | 3026 | let _knobs = crate::speed::knob_write(); |
| 3176 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3177 | let (width, height) = (640usize, 384usize); | 3027 | let (width, height) = (640usize, 384usize); |
| 3178 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); | 3028 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); |
| 3179 | let mut sizes: Vec<(u8, usize)> = Vec::new(); | 3029 | let mut sizes: Vec<(u8, usize)> = Vec::new(); |
| @@ -3198,7 +3048,7 @@ | |||
| 3198 | sources.len(), | 3048 | sources.len(), |
| 3199 | "speed {speed}: our decoder's frames" | 3049 | "speed {speed}: our decoder's frames" |
| 3200 | ); | 3050 | ); |
| 3201 | - if have_ffmpeg() { | 3051 | + { |
| 3202 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 3052 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 3203 | assert_eq!( | 3053 | assert_eq!( |
| 3204 | theirs.len(), | 3054 | theirs.len(), |
| @@ -3225,8 +3075,6 @@ | |||
| 3225 | b.len() | 3075 | b.len() |
| 3226 | ); | 3076 | ); |
| 3227 | } | 3077 | } |
| 3228 | - } else { | ||
| 3229 | - eprintln!("SKIP the ffmpeg half of speed {speed}: no ffmpeg"); | ||
| 3230 | } | 3078 | } |
| 3231 | eprintln!( | 3079 | eprintln!( |
| 3232 | "speed {speed}: {} bytes [{}]", | 3080 | "speed {speed}: {} bytes [{}]", |
| @@ -3252,9 +3100,8 @@ | |||
| 3252 | #[ignore = "wall table, 16 cells x 2 passes at 1080p: 27 min measured; needs a host with >=8 cores"] | 3100 | #[ignore = "wall table, 16 cells x 2 passes at 1080p: 27 min measured; needs a host with >=8 cores"] |
| 3253 | fn tile_wall_table_at_1080p() { | 3101 | fn tile_wall_table_at_1080p() { |
| 3254 | let _knobs = crate::speed::knob_write(); | 3102 | let _knobs = crate::speed::knob_write(); |
| 3255 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3256 | let (width, height) = (1920usize, 1080usize); | 3103 | let (width, height) = (1920usize, 1080usize); |
| 3257 | - let Some(sources) = h264_clip_frames("tile_wall_table_at_1080p", width, height, 8) else { | 3104 | + let Some(sources) = h264_clip_frames(width, height, 8) else { |
| 3258 | return; | 3105 | return; |
| 3259 | }; | 3106 | }; |
| 3260 | let layouts = [(0u32, 0u32), (1, 0), (1, 1), (2, 1)]; | 3107 | let layouts = [(0u32, 0u32), (1, 0), (1, 1), (2, 1)]; |
| @@ -3302,7 +3149,6 @@ | |||
| 3302 | #[test] | 3149 | #[test] |
| 3303 | fn tile_bytes_do_not_depend_on_the_thread_count() { | 3150 | fn tile_bytes_do_not_depend_on_the_thread_count() { |
| 3304 | let _knobs = crate::speed::knob_write(); | 3151 | let _knobs = crate::speed::knob_write(); |
| 3305 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3306 | let (width, height) = (320usize, 192usize); | 3152 | let (width, height) = (320usize, 192usize); |
| 3307 | let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect(); | 3153 | let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect(); |
| 3308 | let coded = |threads: usize, cols_log2: u32, rows_log2: u32| { | 3154 | let coded = |threads: usize, cols_log2: u32, rows_log2: u32| { |
| @@ -3384,7 +3230,6 @@ | |||
| 3384 | #[test] | 3230 | #[test] |
| 3385 | fn filter_stage_bytes_do_not_depend_on_the_thread_count() { | 3231 | fn filter_stage_bytes_do_not_depend_on_the_thread_count() { |
| 3386 | let _knobs = crate::speed::knob_write(); | 3232 | let _knobs = crate::speed::knob_write(); |
| 3387 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3388 | let (width, height) = (384usize, 288usize); | 3233 | let (width, height) = (384usize, 288usize); |
| 3389 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); | 3234 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); |
| 3390 | let coded = |threads: usize| { | 3235 | let coded = |threads: usize| { |
| @@ -3426,7 +3271,6 @@ | |||
| 3426 | #[test] | 3271 | #[test] |
| 3427 | fn filter_replay_codes_the_same_stream_as_a_full_decode() { | 3272 | fn filter_replay_codes_the_same_stream_as_a_full_decode() { |
| 3428 | let _knobs = crate::speed::knob_read(); | 3273 | let _knobs = crate::speed::knob_read(); |
| 3429 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3430 | let run = |width: usize, height: usize, off: bool| { | 3274 | let run = |width: usize, height: usize, off: bool| { |
| 3431 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); | 3275 | let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); |
| 3432 | crate::decode::set_filter_replay_disabled(off); | 3276 | crate::decode::set_filter_replay_disabled(off); |
| @@ -3472,7 +3316,6 @@ | |||
| 3472 | #[test] | 3316 | #[test] |
| 3473 | fn filter_replay_final_matches_the_capture_decode() { | 3317 | fn filter_replay_final_matches_the_capture_decode() { |
| 3474 | let _knobs = crate::speed::knob_read(); | 3318 | let _knobs = crate::speed::knob_read(); |
| 3475 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3476 | let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| { | 3319 | let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| { |
| 3477 | let config = EncoderConfig { | 3320 | let config = EncoderConfig { |
| 3478 | width, | 3321 | width, |
| @@ -3497,7 +3340,7 @@ | |||
| 3497 | } | 3340 | } |
| 3498 | // Real gate content, where the CDEF preset search actually chooses | 3341 | // Real gate content, where the CDEF preset search actually chooses |
| 3499 | // `bits > 0` and the tile is re-coded, one tile and four. | 3342 | // `bits > 0` and the tile is re-coded, one tile and four. |
| 3500 | - if let Some(sources) = h264_clip_frames("the gate-clip arm", 640, 384, 3) { | 3343 | + if let Some(sources) = h264_clip_frames(640, 384, 3) { |
| 3501 | run(&sources, 640, 384, (0, 0)); | 3344 | run(&sources, 640, 384, (0, 0)); |
| 3502 | run(&sources, 640, 384, (1, 1)); | 3345 | run(&sources, 640, 384, (1, 1)); |
| 3503 | } | 3346 | } |
| @@ -3546,8 +3389,7 @@ | |||
| 3546 | (cols_log2, rows_log2): (u32, u32), | 3389 | (cols_log2, rows_log2): (u32, u32), |
| 3547 | threads: &[usize], | 3390 | threads: &[usize], |
| 3548 | ) { | 3391 | ) { |
| 3549 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | 3392 | + let Some(sources) = h264_clip_frames(width, height, frames) |
| 3550 | - let Some(sources) = h264_clip_frames("the filter-stage breakdown", width, height, frames) | ||
| 3551 | else { | 3393 | else { |
| 3552 | return; | 3394 | return; |
| 3553 | }; | 3395 | }; |
| @@ -3618,8 +3460,7 @@ | |||
| 3618 | layouts: &[(u32, u32)], | 3460 | layouts: &[(u32, u32)], |
| 3619 | threads: &[usize], | 3461 | threads: &[usize], |
| 3620 | ) { | 3462 | ) { |
| 3621 | - let _gate_lock = crate::stream::tests::lock_gate_counters(); | 3463 | + let Some(sources) = h264_clip_frames(width, height, frames) |
| 3622 | - let Some(sources) = h264_clip_frames("the tile-search wall table", width, height, frames) | ||
| 3623 | else { | 3464 | else { |
| 3624 | return; | 3465 | return; |
| 3625 | }; | 3466 | }; |
| @@ -3716,8 +3557,8 @@ | |||
| 3716 | layouts: &[(u32, u32)], | 3557 | layouts: &[(u32, u32)], |
| 3717 | threads: &[usize], | 3558 | threads: &[usize], |
| 3718 | ) { | 3559 | ) { |
| 3719 | - let listed = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | 3560 | + let listed = ec_testkit::ffmpeg() |
| 3720 | - .args(["-hide_banner", "-encoders"]), None, |c| c.output()); | 3561 | + .args(["-hide_banner", "-encoders"]).output(); |
| 3721 | let has_rav1e = listed | 3562 | let has_rav1e = listed |
| 3722 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e")) | 3563 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e")) |
| 3723 | .unwrap_or(false); | 3564 | .unwrap_or(false); |
| @@ -3726,16 +3567,8 @@ | |||
| 3726 | // message and could not fail under any require env. The two causes are | 3567 | // message and could not fail under any require env. The two causes are |
| 3727 | // now separate, and only the clip goes through the fixture probe, so | 3568 | // now separate, and only the clip goes through the fixture probe, so |
| 3728 | // either way this helper prints exactly ONE line. | 3569 | // either way this helper prints exactly ONE line. |
| 3729 | - if !has_rav1e { | 3570 | + assert!(has_rav1e, "ffmpeg has no librav1e encoder"); |
| 3730 | - eprintln!("SKIP the rav1e reference: ffmpeg has no librav1e encoder"); | 3571 | + let clip = ec_testkit::fixture("open/sintel_trailer-1080p.mp4"); |
| 3731 | - return; | ||
| 3732 | - } | ||
| 3733 | - let Some(clip) = crate::library_fixture::require( | ||
| 3734 | - "video/h264-1080p-23.976-8bit.mp4", | ||
| 3735 | - "the rav1e reference", | ||
| 3736 | - ) else { | ||
| 3737 | - return; | ||
| 3738 | - }; | ||
| 3739 | eprintln!("| rav1e layout | threads | wall | fps | bytes |"); | 3572 | eprintln!("| rav1e layout | threads | wall | fps | bytes |"); |
| 3740 | for &(c, r) in layouts { | 3573 | for &(c, r) in layouts { |
| 3741 | for &t in threads { | 3574 | for &t in threads { |
| @@ -3747,12 +3580,12 @@ | |||
| 3747 | 1 << r | 3580 | 1 << r |
| 3748 | ); | 3581 | ); |
| 3749 | let start = std::time::Instant::now(); | 3582 | let start = std::time::Instant::now(); |
| 3750 | - let status = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | 3583 | + let status = ec_testkit::ffmpeg() |
| 3751 | .args(["-v", "error", "-y", "-i", clip.to_str().unwrap()]) | 3584 | .args(["-v", "error", "-y", "-i", clip.to_str().unwrap()]) |
| 3752 | .args(["-frames:v", &frames.to_string()]) | 3585 | .args(["-frames:v", &frames.to_string()]) |
| 3753 | .args(["-vf", &format!("scale={width}:{height}")]) | 3586 | .args(["-vf", &format!("scale={width}:{height}")]) |
| 3754 | .args(["-c:v", "librav1e", "-rav1e-params", ¶ms]) | 3587 | .args(["-c:v", "librav1e", "-rav1e-params", ¶ms]) |
| 3755 | - .arg(out.to_str().unwrap()), None, |c| c.output()) | 3588 | + .arg(out.to_str().unwrap()).output() |
| 3756 | .expect("ffmpeg failed to run"); | 3589 | .expect("ffmpeg failed to run"); |
| 3757 | let secs = start.elapsed().as_secs_f64(); | 3590 | let secs = start.elapsed().as_secs_f64(); |
| 3758 | if !status.status.success() { | 3591 | if !status.status.success() { |
| @@ -3793,27 +3626,11 @@ | |||
| 3793 | /// first-differing-luma-sample comparison, not a length or non-empty | 3626 | /// first-differing-luma-sample comparison, not a length or non-empty |
| 3794 | /// smoke. | 3627 | /// smoke. |
| 3795 | /// | 3628 | /// |
| 3796 | - /// The two skippable halves both route through the crate's EXISTING | ||
| 3797 | - /// presence probes, not a new shape: `h264_clip_frames` (which itself asks | ||
| 3798 | - /// `have_ffmpeg()` and `library_fixture::require_at`) and `have_ffmpeg()` | ||
| 3799 | - /// for the ffmpeg arm. No bare presence check was added. | ||
| 3800 | - /// | ||
| 3801 | - /// lane-av1clipprobe: with the root `fixtures/` absent this gate printed | ||
| 3802 | - /// `SKIP the 1080p tile round trip: no fixture` and libtest reported `ok` | ||
| 3803 | - /// — a 1080p gate that asserts nothing on every linked worktree, and no | ||
| 3804 | - /// env that made it RED. `library_fixture::require_at` now fails under | ||
| 3805 | - /// `EC_REQUIRE_FIXTURES` / `EC_AV1_REQUIRE_FFMPEG` / `EC_AV1_REQUIRE_AOMENC` | ||
| 3806 | - /// and otherwise prints exactly ONE line naming the resolved path, and the | ||
| 3807 | - /// path it resolves honours `EC_FIXTURES` — the root | ||
| 3808 | - /// `scripts/verify-fixture-library.sh` validates — so the preflight's | ||
| 3809 | - /// verdict and these bytes cannot be different trees again. | ||
| 3810 | #[test] | 3629 | #[test] |
| 3811 | fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() { | 3630 | fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() { |
| 3812 | let _knobs = crate::speed::knob_read(); | 3631 | let _knobs = crate::speed::knob_read(); |
| 3813 | let (width, height) = (1920usize, 1080usize); | 3632 | let (width, height) = (1920usize, 1080usize); |
| 3814 | - let Some(sources) = h264_clip_frames( | 3633 | + let Some(sources) = h264_clip_frames(width, |
| 3815 | - "a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders", | ||
| 3816 | - width, | ||
| 3817 | height, | 3634 | height, |
| 3818 | 3, | 3635 | 3, |
| 3819 | ) else { | 3636 | ) else { |
| @@ -3837,10 +3654,6 @@ | |||
| 3837 | } | 3654 | } |
| 3838 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 3655 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 3839 | assert_eq!(ours.len(), sources.len(), "{layout}: our decoder's frames"); | 3656 | assert_eq!(ours.len(), sources.len(), "{layout}: our decoder's frames"); |
| 3840 | - if !have_ffmpeg() { | ||
| 3841 | - eprintln!("SKIP the ffmpeg half of 1080p {layout}: no ffmpeg"); | ||
| 3842 | - continue; | ||
| 3843 | - } | ||
| 3844 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 3657 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 3845 | assert_eq!(theirs.len(), sources.len(), "{layout}: ffmpeg's frames"); | 3658 | assert_eq!(theirs.len(), sources.len(), "{layout}: ffmpeg's frames"); |
| 3846 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 3659 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| @@ -3870,14 +3683,8 @@ | |||
| 3870 | #[test] | 3683 | #[test] |
| 3871 | fn quality_target_is_monotone_in_bytes_and_psnr() { | 3684 | fn quality_target_is_monotone_in_bytes_and_psnr() { |
| 3872 | let _knobs = crate::speed::knob_read(); | 3685 | let _knobs = crate::speed::knob_read(); |
| 3873 | - if !have_ffmpeg() { | ||
| 3874 | - eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg"); | ||
| 3875 | - return; | ||
| 3876 | - } | ||
| 3877 | let (width, height) = (640, 384); | 3686 | let (width, height) = (640, 384); |
| 3878 | - let Some(pictures) = h264_clip_frames( | 3687 | + let Some(pictures) = h264_clip_frames(width, |
| 3879 | - "quality_target_is_monotone_in_bytes_and_psnr", | ||
| 3880 | - width, | ||
| 3881 | height, | 3688 | height, |
| 3882 | 8, | 3689 | 8, |
| 3883 | ) else { | 3690 | ) else { |
crates/ec-av1/src/gate_coverage.rsdeleted+0 -2775
Diff too large; view file
| @@ -1,2775 +0,0 @@ | |||
| 1 | -//! A guard over the real-aomenc gates' own encoder recipes. | ||
| 2 | -//! | ||
| 3 | -//! Every gate in [`crate::stream`] that runs a real `aomenc` picks its coding | ||
| 4 | -//! tools with `--enable-*=0/1` flags, and a flag left off the command line | ||
| 5 | -//! takes aomenc's default. That default is `1` for essentially every tool in | ||
| 6 | -//! [`TOOL_UNIVERSE`] on a non-realtime build -- `default_extra_cfg` in | ||
| 7 | -//! `av1/av1_cx_iface.c` is all-ones across the seq-level tool fields, and this | ||
| 8 | -//! oracle is built with `CONFIG_REALTIME_ONLY 0`. But a `1` default is NOT | ||
| 9 | -//! the same as the tool reaching the stream, and the rest of this file's | ||
| 10 | -//! "defaulted means unknown" rule rests on that gap: palette and intrabc are | ||
| 11 | -//! gated on CONTENT (`encoder.c:2079` derives `allow_screen_content_tools` | ||
| 12 | -//! from block counts, and `seq_force_screen_content_tools` is left at the | ||
| 13 | -//! adaptive `SELECT_SCREEN_CONTENT_TOOLS`), and `speed_features.c` masks | ||
| 14 | -//! several tools OFF again per `--cpu-used`. A `1` default proves the encoder | ||
| 15 | -//! was ALLOWED the tool, never that any block used it. | ||
| 16 | -//! | ||
| 17 | -//! With that default in place it is possible -- and it happened -- for a | ||
| 18 | -//! coding tool to be switched *off in every single gate*, so that no real | ||
| 19 | -//! stream in this repository ever exercised it and a corner-cut in the | ||
| 20 | -//! decoder survived twenty gates unnoticed: `reconstruct`'s | ||
| 21 | -//! `smooth_neighbor` was hardcoded `false`, wrong whenever a directional | ||
| 22 | -//! block neighbours a smooth-mode one, and invisible because all twenty | ||
| 23 | -//! gates passed `--enable-smooth-intra=0` (lane-chroma r1, 2026-08-30). | ||
| 24 | -//! | ||
| 25 | -//! The test below re-derives that set from the gate source and pins it. A tool | ||
| 26 | -//! that is switched off in every gate and on in none is *provably never | ||
| 27 | -//! exercised* by a real stream, and belongs on [`NEVER_EXERCISED`] with a | ||
| 28 | -//! reason. Landing the decode support for one means enabling it in that | ||
| 29 | -//! feature's gate, which shrinks the derived set and fails this test until the | ||
| 30 | -//! list is updated -- the point being that the shrink is noticed. | ||
| 31 | - | ||
| 32 | -// TILING is deliberately NOT in this derivation (lane-tiles r11): the check | ||
| 33 | -// keys on `--enable-<tool>=0/1`, and `--tile-columns=<log2>` has no such | ||
| 34 | -// shape -- a `--tile-columns=` presence check would also read `=0` (one tile) | ||
| 35 | -// as coverage, which is the opposite of what it would claim. It needs no | ||
| 36 | -// entry either: measured 2026-09-29 (lane-av1distwtd r2), 19 of the 146 | ||
| 37 | -// census-selected gate bodies spell `--tile-columns`/`--tile-rows` with a | ||
| 38 | -// nonzero log2 -- 9 assert the parsed `tile_info` in the same body and 10 | ||
| 39 | -// more delegate to a shared helper that asserts it -- and | ||
| 40 | -// `run_multi_tile_gate` covers a 2D grid with the coding tools ON at both | ||
| 41 | -// bit depths. | ||
| 42 | - | ||
| 43 | -/// aomenc coding tools that no real-`aomenc` gate is proven to exercise: | ||
| 44 | -/// switched off in every gate that names them, and on in none. | ||
| 45 | -/// | ||
| 46 | -/// A gate that simply leaves the flag off its command line does NOT close the | ||
| 47 | -/// hole. aomenc's default for these is content-dependent -- palette and | ||
| 48 | -/// intrabc only come on for screen content -- so "defaulted" means "unknown", | ||
| 49 | -/// not "exercised", and treating it as coverage would retire the entry | ||
| 50 | -/// without a single stream proving the decoder ever saw the tool. Only an | ||
| 51 | -/// explicit `--enable-<tool>=1` in a gate that then asserts the feature fired | ||
| 52 | -/// closes one. | ||
| 53 | -/// | ||
| 54 | -/// Each entry is `(flag, why)`. Removing an entry is how a lane records that | ||
| 55 | -/// its tool is now covered by a real stream. | ||
| 56 | -#[cfg(test)] | ||
| 57 | -const NEVER_EXERCISED: &[(&str, &str)] = &[ | ||
| 58 | - // `enable-intrabc` LEFT this list on 2026-09-02 (lane-kf900 r6). The | ||
| 59 | - // premise it carried -- "every real stream's intrabc block sits under | ||
| 60 | - // TX_MODE_SELECT" -- was false: with `--enable-tx-size-search=0` aomenc | ||
| 61 | - // codes intrabc blocks under TX_MODE_LARGEST, and | ||
| 62 | - // `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` | ||
| 63 | - // spells `--enable-intrabc=1` and decodes three such 8-bit streams whole- | ||
| 64 | - // frame pixel-exact against ffmpeg, with the block counter asserted > 0. | ||
| 65 | - // Re-verified 2026-09-17 (lane-av1-intrabc) at main f715d70c: 185 rect | ||
| 66 | - // `use_intrabc` symbols read, and 5 blocks took the DV path -- 4 of them | ||
| 67 | - // DECODED whole-frame pixel-exact across 4 arms (7 frames compared, 0 | ||
| 68 | - // mismatches). The fifth is the testsrc2 rectangle-strip arm, which reads | ||
| 69 | - // the symbol and then refuses by name (the `intrabc_hits` bump happens on | ||
| 70 | - // the READ), so "5 blocks decoded" would overcount: 4 decoded + 1 refused, | ||
| 71 | - // exactly the single `refused == 1` the gate asserts. | ||
| 72 | -]; | ||
| 73 | - | ||
| 74 | -/// The `--enable-*` tools this decoder cares about, whether or not any gate | ||
| 75 | -/// names one. A flag no gate mentions is *defaulted*, i.e. unknown, and by the | ||
| 76 | -/// rule above unknown is not coverage -- so the universe is fixed here rather | ||
| 77 | -/// than derived from the gate source, which would silently shrink to whatever | ||
| 78 | -/// the gates happen to spell. | ||
| 79 | -#[cfg(test)] | ||
| 80 | -const TOOL_UNIVERSE: &[&str] = &[ | ||
| 81 | - "enable-1to4-partitions", | ||
| 82 | - "enable-ab-partitions", | ||
| 83 | - "enable-angle-delta", | ||
| 84 | - "enable-cdef", | ||
| 85 | - "enable-cfl-intra", | ||
| 86 | - "enable-dist-wtd-comp", | ||
| 87 | - "enable-dual-filter", | ||
| 88 | - "enable-filter-intra", | ||
| 89 | - "enable-flip-idtx", | ||
| 90 | - "enable-global-motion", | ||
| 91 | - "enable-interintra-comp", | ||
| 92 | - "enable-intra-edge-filter", | ||
| 93 | - "enable-intrabc", | ||
| 94 | - "enable-masked-comp", | ||
| 95 | - "enable-obmc", | ||
| 96 | - "enable-order-hint", | ||
| 97 | - "enable-paeth-intra", | ||
| 98 | - "enable-palette", | ||
| 99 | - "enable-rect-partitions", | ||
| 100 | - "enable-rect-tx", | ||
| 101 | - "enable-ref-frame-mvs", | ||
| 102 | - "enable-restoration", | ||
| 103 | - "enable-smooth-intra", | ||
| 104 | - "enable-superres", | ||
| 105 | - "enable-tx64", | ||
| 106 | - "enable-warped-motion", | ||
| 107 | -]; | ||
| 108 | - | ||
| 109 | -/// How a non-boolean aomenc knob reads as "the tool is on". | ||
| 110 | -#[cfg(test)] | ||
| 111 | -#[derive(Clone, Copy, PartialEq)] | ||
| 112 | -enum On { | ||
| 113 | - /// Any non-zero value enables the tool (`--tile-columns=1`, `--loopfilter-control=1`). | ||
| 114 | - NonZero, | ||
| 115 | - /// The tool's search only runs at or below this speed (`--cpu-used`). | ||
| 116 | - AtMost(u32), | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | -/// Coding tools aomenc drives through a spelling [`TOOL_UNIVERSE`] does not | ||
| 120 | -/// cover, listed with their aomenc default. | ||
| 121 | -/// | ||
| 122 | -/// lane-covbd's derivation read `--enable-*` flags only, so a tool a gate pins | ||
| 123 | -/// off through another spelling was invisible: every gate that named | ||
| 124 | -/// `--enable-tx-size-search` passed `--enable-tx-size-search=0` when this was | ||
| 125 | -/// written, and the real-stream PANIC hiding behind that pin was found by | ||
| 126 | -/// lane-ab16, not by this guard. `--loopfilter-control=0`, | ||
| 127 | -/// `--tile-columns=0` and a `--cpu-used` high enough to switch a search off are | ||
| 128 | -/// the same shape. `enable-tx-size-search` has since been SETTLED, in both | ||
| 129 | -/// directions -- see the entry below and `print_tx_size_search_census`. | ||
| 130 | -/// | ||
| 131 | -/// The "all 49" count is GONE as of 2026-09-29 (lane-av1distwtd r2) and is | ||
| 132 | -/// deliberately not replaced by a number here: it is a snapshot that rots | ||
| 133 | -/// every time a recipe changes. The live count is a TEST | ||
| 134 | -/// ([`print_tx_size_search_census`], below), not prose, so it cannot go stale | ||
| 135 | -/// silently -- re-run it and read the numbers rather than trusting a comment. | ||
| 136 | -/// | ||
| 137 | -/// Each entry is `(tool, spellings, aomenc default, what counts as on)`. The | ||
| 138 | -/// "defaulted means unknown" rule of [`NEVER_EXERCISED`] applies unchanged: a | ||
| 139 | -/// default of `1` does not prove the encoder picked the tool for any stream, so | ||
| 140 | -/// only a gate that spells an on-value at that bit depth retires an entry. | ||
| 141 | -// `enable-tx-size-search` SETTLED 2026-09-29 (lane-av1txsearch), by | ||
| 142 | -// measurement rather than by a name-shaped guess. The r3 note here said the | ||
| 143 | -// count was a FLOOR: 9 gate bodies built the flag into a `format!` | ||
| 144 | -// variable that neither `flags_in` nor `settings_in` could see, because | ||
| 145 | -// both scan for a literal `"--flag=value"` inside one segment. The method | ||
| 146 | -// r3 asked for is now [`spelling_values`] -> [`bound_values`], and it | ||
| 147 | -// resolves all of them; `print_tx_size_search_census` asserts the | ||
| 148 | -// unresolvable count is ZERO, so the floor cannot come back unnoticed. | ||
| 149 | -// | ||
| 150 | -// THE ENTRY IS RETIRED, on an ARRIVAL ASSERT rather than on the spelling. | ||
| 151 | -// `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` | ||
| 152 | -// spells `--enable-tx-size-search=1` as a literal and hard-asserts | ||
| 153 | -// `compared_tx_depths > 0` -- "never produced a nonzero tx depth on a | ||
| 154 | -// compared attempt -- the flag did not arrive". `tx_depth` is read ONLY | ||
| 155 | -// under the frame header's `tx_mode_select` bit (spec 5.11.16, | ||
| 156 | -// `decode.rs`: the read is guarded by `tx_select_inter`), so a nonzero | ||
| 157 | -// counter IS the parsed tx-size-search behaviour, not a proxy for it. | ||
| 158 | -// Measured run of that gate on this tree (aom 3.13.3): 12 pixel-exact | ||
| 159 | -// decodes, 0 named refusals, 6 of the 12 at 10 BIT, 219 rect coefficient | ||
| 160 | -// TUs on compared attempts, and `flag arrival: ... tx depths 53` -- so the | ||
| 161 | -// tool is exercised at BOTH depths, and the assertion is not vacuous. | ||
| 162 | -// | ||
| 163 | -// The `tx_select_inter_gate` twins | ||
| 164 | -// (`a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact{,_10bit}`) | ||
| 165 | -// are the stronger witness still: they DELIBERATELY omit the flag | ||
| 166 | -// ("DELIBERATELY ABSENT: --enable-tx-size-search=0") and assert | ||
| 167 | -// `decode::txfm_split_hits()` moved, proving the var-tx `txfm_split` tree | ||
| 168 | -// of spec 5.11.17 is read -- an inter transform is then a recursive split | ||
| 169 | -// tree, which is the whole content of the tool. | ||
| 170 | -#[cfg(test)] | ||
| 171 | -const DEFAULT_ON_TOOLS: &[(&str, &[&str], &str, On)] = &[ | ||
| 172 | - ( | ||
| 173 | - "enable-tx-size-search", | ||
| 174 | - &["enable-tx-size-search"], | ||
| 175 | - "1", | ||
| 176 | - On::NonZero, | ||
| 177 | - ), | ||
| 178 | - ( | ||
| 179 | - "enable-directional-intra", | ||
| 180 | - &["enable-directional-intra"], | ||
| 181 | - "1", | ||
| 182 | - On::NonZero, | ||
| 183 | - ), | ||
| 184 | - ( | ||
| 185 | - "enable-smooth-interintra", | ||
| 186 | - &["enable-smooth-interintra"], | ||
| 187 | - "1", | ||
| 188 | - On::NonZero, | ||
| 189 | - ), | ||
| 190 | - ( | ||
| 191 | - "enable-interintra-wedge", | ||
| 192 | - &["enable-interintra-wedge"], | ||
| 193 | - "1", | ||
| 194 | - On::NonZero, | ||
| 195 | - ), | ||
| 196 | - ( | ||
| 197 | - "enable-diff-wtd-comp", | ||
| 198 | - &["enable-diff-wtd-comp"], | ||
| 199 | - "1", | ||
| 200 | - On::NonZero, | ||
| 201 | - ), | ||
| 202 | - ( | ||
| 203 | - "enable-onesided-comp", | ||
| 204 | - &["enable-onesided-comp"], | ||
| 205 | - "1", | ||
| 206 | - On::NonZero, | ||
| 207 | - ), | ||
| 208 | - ("enable-fwd-kf", &["enable-fwd-kf"], "0", On::NonZero), | ||
| 209 | - ("deblocking", &["loopfilter-control"], "1", On::NonZero), | ||
| 210 | - ( | ||
| 211 | - "multi-tile", | ||
| 212 | - &["tile-columns", "tile-rows"], | ||
| 213 | - "0", | ||
| 214 | - On::NonZero, | ||
| 215 | - ), | ||
| 216 | - ("intrabc-search", &["cpu-used"], "0", On::AtMost(2)), | ||
| 217 | -]; | ||
| 218 | - | ||
| 219 | -/// Non-`--enable-*` spellings that drive a [`TOOL_UNIVERSE`] tool. | ||
| 220 | -/// | ||
| 221 | -/// `--superres-mode=1` is how every superres gate switches superres on; | ||
| 222 | -/// without this map they read as an `enable-superres` hole while a real stream | ||
| 223 | -/// exercises the tool (lane-covbd deferred exactly this). The count was "all | ||
| 224 | -/// three" until 2026-09-29 (lane-av1distwtd r2), which measured SIX gates | ||
| 225 | -/// spelling a nonzero `--superres-mode` (5 among the 146 census-selected | ||
| 226 | -/// bodies, plus `a_superres_census_over_six_real_streams_...`). No count is | ||
| 227 | -/// given here for the same reason as `enable-tx-size-search` above: it rots. | ||
| 228 | -/// Worth noting the alias is the ONLY positive evidence for superres, and | ||
| 229 | -/// those gates do assert arrival -- `superres_hits` / `predict_scaled_hits` | ||
| 230 | -/// are read in five of them -- so this one is a healthy alias, not a | ||
| 231 | -/// spelling-only one. | ||
| 232 | -#[cfg(test)] | ||
| 233 | -const ALIASES: &[(&str, &str)] = &[("superres-mode", "enable-superres")]; | ||
| 234 | - | ||
| 235 | -/// Coverage is per (tool x bit depth), not per tool. | ||
| 236 | -/// | ||
| 237 | -/// lane-hbdinter found two 10-bit-only defects (SGR box sums unscaled, Wiener | ||
| 238 | -/// clamp pinned at the 8-bit bound) that survived the "10-bit bit-exact" | ||
| 239 | -/// milestone because every 10-bit gate passed `--enable-restoration=0`: | ||
| 240 | -/// `enable-restoration` is positively exercised -- at 8 bits only. A tool the | ||
| 241 | -/// 8-bit gates cover says nothing about the high-bit-depth path through the | ||
| 242 | -/// same code, so the two lists below are pinned separately. | ||
| 243 | -/// | ||
| 244 | -/// Each entry is `(flag, why)`. A gate that passes `--enable-<tool>=1` at that | ||
| 245 | -/// depth retires the entry, and this test fails until it is deleted. | ||
| 246 | -#[cfg(test)] | ||
| 247 | -const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ | ||
| 248 | - // `enable-cfl-intra` LEFT both lists on 2026-09-02 (lane-reelckf r1): the | ||
| 249 | - // sb128 skipped-CfL / 1:4-chroma gate passes `--enable-cfl-intra=1` at 8 | ||
| 250 | - // AND 10 bits and pixel-compares both arms. | ||
| 251 | - // `enable-dist-wtd-comp` LEFT this list on 2026-09-29 (lane-av1distwtd). | ||
| 252 | - // The entry's stated reason was WRONG: the distance-weighted compound | ||
| 253 | - // combine is not unimplemented -- `compound::dist_wtd_comp_weight_assign` | ||
| 254 | - // (lane-av1comp) and `mc::combine_compound`'s weighted path have been in | ||
| 255 | - // the tree for a long time. What was missing was a stream CARRYING the | ||
| 256 | - // tool, and `a_distance_weighted_compound_stream_decodes_pixel_exact` | ||
| 257 | - // (stream.rs) now supplies one: it spells `--enable-dist-wtd-comp=1` and | ||
| 258 | - // asserts the PARSED sequence header carries `enable_jnt_comp == true` | ||
| 259 | - // (and `false` from the same recipe with `=0`, so the bit is proven to | ||
| 260 | - // move with the flag), that `dist_wtd_comp_hits() > 0` -- the | ||
| 261 | - // `compound_idx == 0` arm, the only branch whose blend weights are not the | ||
| 262 | - // constant (8, 8) -- and pixel-compares every frame against the oracle. | ||
| 263 | - // The existing lane-cwarp compound-warp gates already SPELLED `=1` and | ||
| 264 | - // the census still read this entry as open, so the hole was a missing | ||
| 265 | - // witness, not a missing flag. | ||
| 266 | - // `enable-dual-filter` LEFT this list on 2026-09-29 (lane-av1distwtd r3), | ||
| 267 | - // paid by a DETECTOR fix rather than by a new gate. The r2 audit found | ||
| 268 | - // this entry's reason false on both halves. It is spelled -- as `=0`, by | ||
| 269 | - // `real_aomenc_1to4_streams_...` and | ||
| 270 | - // `a_real_aomenc_inter_sequence_with_32x32_level_1to4_strips_...` -- so | ||
| 271 | - // "never spelled" was wrong; and a stream IS proven to carry the tool, | ||
| 272 | - // because `a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` | ||
| 273 | - // spells `--enable-dual-filter=1` and hard-asserts | ||
| 274 | - // `decode::dual_filter_diff_hits()` moved, the differing-direction arrival | ||
| 275 | - // assert (`resolve_interp_filter` in decode.rs). That gate builds its | ||
| 276 | - // stream through `inter_sb_none_gate`, so it spells none of the three | ||
| 277 | - // tokens `gate_bodies()` used to filter on and was INVISIBLE to the | ||
| 278 | - // census; r3 made `gate_bodies()` resolve calls as well as spellings, and | ||
| 279 | - // `the_detector_sees_the_gates_the_spelling_filter_missed` pins that. | ||
| 280 | - // Supporting measurement: with the flag left off the command line the | ||
| 281 | - // parsed sequence header already carries `enable_dual_filter = true` | ||
| 282 | - // (6855 B), while `--enable-dual-filter=0` parses false and encodes | ||
| 283 | - // different bytes (6874 B) -- so the gates pinning it `=0` were removing | ||
| 284 | - // the tool and the ones leaving it defaulted carry it. | ||
| 285 | - // | ||
| 286 | - // `enable-flip-idtx` LEFT this list the same day, also by detector fix. | ||
| 287 | - // `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` | ||
| 288 | - // spells `=1` and hard-asserts `compared_class1 > 0` ("--enable-flip-idtx=1 | ||
| 289 | - // never produced a V_DCT/H_DCT transform on a compared attempt"). Its | ||
| 290 | - // recipe is parameterised on `ten_bit` and names BOTH fixture formats, so | ||
| 291 | - // `is_ten_bit` filed the whole body 10-bit-ONLY and the 8-bit bucket | ||
| 292 | - // never saw it -- the lane-defon/reelckf blind spot through a THIRD | ||
| 293 | - // spelling, which r3 taught `covers_both_depths` to recognise as the | ||
| 294 | - // pair-of-formats marker. Measured run of that gate: 12 pixel-exact | ||
| 295 | - // decodes, 6 of them 8-bit, 219 rect coefficient TUs of which 10 carry a | ||
| 296 | - // 1D tx class. | ||
| 297 | - // `enable-global-motion` LEFT this list on 2026-09-25 (lane-av1gwarp12 r2): | ||
| 298 | - // `a_real_affine_global_motion_stream_decodes_pixel_exact` loops | ||
| 299 | - // `for depth in [8u32, 10u32]` passing `--enable-global-motion=1` and | ||
| 300 | - // pixel-compares both depths, so the 8-bit hole has been closed since | ||
| 301 | - // lane-gmaffine r1 -- the entry survived because no suite ran a tree | ||
| 302 | - // containing both the gate and this test until the ROTZOOM suite. | ||
| 303 | - // The 12-bit ROTZOOM gate rides the high-depth bucket via `encode_12bit(` | ||
| 304 | - // in `is_ten_bit`, so it plays no part in this retirement. | ||
| 305 | - // `enable-rect-tx` -- reason RE-VERIFIED 2026-09-29 (lane-av1distwtd | ||
| 306 | - // r2), both halves still TRUE, and the second half is now PROVEN rather | ||
| 307 | - // than asserted. (1) "never spelled": measured across all 146 | ||
| 308 | - // census-selected gate bodies, zero spell `--enable-rect-tx` at either | ||
| 309 | - // depth -- the only `--enable-*` tool in [`TOOL_UNIVERSE`] with no | ||
| 310 | - // spelling anywhere. (2) "reach the decoder only through partition | ||
| 311 | - // shape": aom 3.13.3 has no sequence-header bit for it. `enable_rect_tx` | ||
| 312 | - // is an `AV1E_SET_ENABLE_RECT_TX` encoder-search control | ||
| 313 | - // (`av1_cx_iface.c:2125`, copied to `txfm_cfg->enable_rect_tx` at | ||
| 314 | - // `av1_cx_iface.c:1483`) and is read ONLY inside `tx_search.c` | ||
| 315 | - // (lines 2568/2662/2686/2710/2956); `bitstream.c` writes no such bit, and | ||
| 316 | - // this crate's `SequenceHeader` (`ec-av1-syntax/src/sequence.rs`) has no | ||
| 317 | - // such field. The decoder's own gate is `is_rect_tx_allowed`, derived | ||
| 318 | - // from partition shape -- exactly what this reason says. A gate can | ||
| 319 | - // therefore never prove this tool by naming the flag, only by proving a | ||
| 320 | - // rect transform unit fired (`rect_partition_hits` / | ||
| 321 | - // `rect_coeff_tu_hits`, which lane-rect1d's gate does assert). | ||
| 322 | - // `enable-rect-tx` LEFT this list on 2026-09-29 (merge wave 2, | ||
| 323 | - // lane-av1toolgates). Both halves of the reason recorded above still hold | ||
| 324 | - // as statements about the FLAG, and the second is exactly why the closing | ||
| 325 | - // evidence is a parsed shape and not a spelling: `enable_rect_tx` has no | ||
| 326 | - // sequence-header bit, so a decoder path can never be proven by naming the | ||
| 327 | - // flag -- only by proving a rect transform unit fired. | ||
| 328 | - // `a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact` | ||
| 329 | - // (and its 10-bit twin) now spell `--enable-rect-tx=1` in their OWN test | ||
| 330 | - // bodies -- inline on purpose, because a helper-owned recipe collapses | ||
| 331 | - // both gates into one helper segment that `is_ten_bit` files 10-bit, and | ||
| 332 | - // the 8-bit hole would stay open -- and prove the tool on the PARSED | ||
| 333 | - // shape: `rect_partition_hits()` and `rect_coeff_tu_hits()` are both | ||
| 334 | - // asserted > 0 over arms that decoded AND pixel-compared, and each | ||
| 335 | - // counter is mutation-proven red on its own message. | ||
| 336 | - // Census on the merged tree (`print_never_exercised_per_bit_depth`): | ||
| 337 | - // 255 real-aomenc gate bodies, NEVER_EXERCISED derived EMPTY at 8 bits | ||
| 338 | - // and at 10 bits -- 0 of 26 tools -- so this list is empty on the same | ||
| 339 | - // evidence, not by deletion of a claim. | ||
| 340 | -]; | ||
| 341 | - | ||
| 342 | -#[cfg(test)] | ||
| 343 | -const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ | ||
| 344 | - // lane-cwarp's 10-bit compound-global-warp gate closed `enable-global-motion` | ||
| 345 | - // and `enable-dist-wtd-comp` at 10 bits without deleting their entries here, | ||
| 346 | - // so this list was already stale (and this test already red) at main 9c35ecc; | ||
| 347 | - // lane-tiles r11's multi-tile 10-bit gates then closed `enable-ab-partitions`, | ||
| 348 | - // `enable-rect-partitions` and `enable-restoration` at 10 bits. All five | ||
| 349 | - // deleted together. | ||
| 350 | - | ||
| 351 | - // The "Only 4 of the 45 real-aomenc gates encode at 10 bits" sentence that | ||
| 352 | - // stood here is STALE (lane-av1distwtd r2, 2026-09-29), and understated | ||
| 353 | - // the high-depth bucket by more than an order of magnitude. Measured | ||
| 354 | - // against this tree with `gate_bodies()`' own filter: 146 selected gate | ||
| 355 | - // bodies, of which 83 are classified 10-bit-or-higher by `is_ten_bit`. | ||
| 356 | - // The historical point stands -- those gates pin the pixel filters and | ||
| 357 | - // the intra tool set off far more often than not -- but the counts a | ||
| 358 | - // reader would check them against no longer exist. | ||
| 359 | - // Every entry the 8-bit list carries is a hole here too. lane-hbdgates r1 | ||
| 360 | - // closed six of the seven 8-bit-only entries with real 10-bit gates | ||
| 361 | - // paeth-intra, intra-edge-filter, rect-partitions, ab-partitions); its | ||
| 362 | - // seventh, the 10-bit LR gate, was `#[ignore]`d on that branch and passes | ||
| 363 | - // un-ignored on main, which carries the fix. | ||
| 364 | - // `enable-restoration` LEFT this list on 2026-09-01: lane-hbdinter's | ||
| 365 | - // 10-bit inter gate passes `--enable-restoration=1` and asserts a real | ||
| 366 | - // Wiener/SGR unit fired, which is what caught the two defects (SGR box | ||
| 367 | - // sums never brought back to the 8-bit scale, Wiener clamp at the wrong | ||
| 368 | - // bound). `enable-dist-wtd-comp` and `enable-global-motion` left it the | ||
| 369 | - // same day for the same reason: lane-cwarp's 10-bit compound global-warp | ||
| 370 | - // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02: | ||
| 371 | - // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both | ||
| 372 | - // orientations and coded strips inside pixel-exact attempts. | ||
| 373 | - // `enable-dual-filter` -- reason CORRECTED 2026-09-29 (lane-av1distwtd | ||
| 374 | - // r3), and this entry STAYS while its 8-bit twin was retired. That is the | ||
| 375 | - // honest outcome, not an oversight: after the r3 detector fix the 8-bit | ||
| 376 | - // bucket sees the tool exercised and the 10-bit bucket still does not. | ||
| 377 | - // The only `=1` witness is | ||
| 378 | - // `a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact`, | ||
| 379 | - // and it calls `inter_sb_none_gate(NAME, false, ...)` -- `false` is the | ||
| 380 | - // `ten_bit` parameter, so that gate builds an 8-bit stream only. Its | ||
| 381 | - // sibling `a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact` | ||
| 382 | - // passes `true`, and the 8x8-leaf pair likewise, but none of those spells | ||
| 383 | - // `--enable-dual-filter=1`. So: exercised at 8 bits (arrival assert | ||
| 384 | - // `dual_filter_diff_hits()` moved, `resolve_interp_filter` in decode.rs), | ||
| 385 | - // NOT exercised at 10 bits. Retiring this entry needs a 10-bit arm of that | ||
| 386 | - // gate -- pass `true` to `inter_sb_none_gate` and assert the differing- | ||
| 387 | - // direction counter still moves there. | ||
| 388 | - // | ||
| 389 | - // The two numbers in the `enable-flip-idtx` retirement below were | ||
| 390 | - // RE-MEASURED 2026-09-29 (lane-av1distwtd r2) by running the gate, and | ||
| 391 | - // both still hold exactly: "pixel-compares six 10-bit decodes" (the run | ||
| 392 | - // reports 12 pixel-exact decodes, 6 of them 10-bit) and "10 of its rect | ||
| 393 | - // coefficient TUs carry a 1D tx class" (219 rect coefficient TUs on | ||
| 394 | - // compared attempts, 10 of them 1D). The gate also hard-asserts | ||
| 395 | - // `compared_class1 > 0`, so its "passes =1 at both depths" is backed by an | ||
| 396 | - // arrival assert, not just a spelling. | ||
| 397 | - // `enable-dual-filter` LEFT this list on 2026-09-29 (merge wave 2, | ||
| 398 | - // lane-av1dualfilter10), by exactly the 10-bit arm the note above names. | ||
| 399 | - // `a_real_aomenc_10bit_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` | ||
| 400 | - // spells `--enable-dual-filter=1` in its own body and hard-asserts the | ||
| 401 | - // arrival counter `decode::dual_filter_diff_hits()` moved at 10 BITS, so | ||
| 402 | - // the entry is closed at the depth it was held open at, not by a spelling | ||
| 403 | - // alone. | ||
| 404 | - // `enable-flip-idtx` LEFT this list on 2026-09-02 (lane-rect1d r1): | ||
| 405 | - // `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` | ||
| 406 | - // passes `=1` at both depths and pixel-compares six 10-bit decodes, so the | ||
| 407 | - // flip/identity/1D transform types are proven to reach a real 10-bit stream | ||
| 408 | - // this decoder reconstructs exactly (10 of its rect coefficient TUs carry a | ||
| 409 | - // 1D tx class). | ||
| 410 | - // `enable-intrabc` LEFT this 10-bit list on 2026-09-02 (lane-kf900 r6). | ||
| 411 | - // The entry it first rested on was a flag spelling -- the palette gate's | ||
| 412 | - // `smptebars-screen-txs-cq40/cq55` arms pass `--enable-intrabc=1` -- and | ||
| 413 | - // lane-av1-intrabc MEASURED that those arms decode ZERO intrabc blocks at | ||
| 414 | - // both depths, so they retired the entry without a stream carrying the | ||
| 415 | - // tool (class `tool-disabled-in-every-gate`, the same defect this list | ||
| 416 | - // exists for). The closing evidence is now | ||
| 417 | - // `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`: its sb128 | ||
| 418 | - // screen recipes run at 10 bits and hard-assert a decoded intrabc block | ||
| 419 | - // per depth (4-6 per arm), every frame pixel-compared against ffmpeg's own | ||
| 420 | - // 10-bit decode. | ||
| 421 | - // `enable-rect-tx` LEFT this list on 2026-09-29 (merge wave 2, | ||
| 422 | - // lane-av1toolgates), together with its 8-bit twin, by | ||
| 423 | - // `a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact`: | ||
| 424 | - // the depth is spelled in the test's OWN body, which is what files it in | ||
| 425 | - // the 10-bit bucket, and the witness is the parsed shape | ||
| 426 | - // (`rect_partition_hits()` / `rect_coeff_tu_hits()` > 0 over arms that | ||
| 427 | - // decoded AND pixel-compared). See the 8-bit list for why the flag alone | ||
| 428 | - // could never have been the evidence. | ||
| 429 | -]; | ||
| 430 | - | ||
| 431 | -/// [`DEFAULT_ON_TOOLS`] entries no 8-bit gate spells on, with the reason. | ||
| 432 | -/// | ||
| 433 | -/// Each entry is `(tool, why)`; the reason states whether the tool is pinned | ||
| 434 | -/// OFF in every gate that names it (a hard hole -- no stream can carry it) or | ||
| 435 | -/// merely defaulted (unknown, and unknown is not coverage). | ||
| 436 | -#[cfg(test)] | ||
| 437 | -const NEVER_ON_8BIT: &[(&str, &str)] = &[]; | ||
| 438 | - | ||
| 439 | -/// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason. | ||
| 440 | -#[cfg(test)] | ||
| 441 | -const NEVER_ON_10BIT: &[(&str, &str)] = &[]; | ||
| 442 | - | ||
| 443 | -#[cfg(test)] | ||
| 444 | -mod tests { | ||
| 445 | - use super::{ | ||
| 446 | - ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, | ||
| 447 | - NEVER_ON_8BIT, NEVER_ON_10BIT, On, TOOL_UNIVERSE, | ||
| 448 | - }; | ||
| 449 | - use std::collections::{BTreeMap, BTreeSet}; | ||
| 450 | - | ||
| 451 | - /// Whether `body` contains a call to the `fn` named `name`. | ||
| 452 | - /// | ||
| 453 | - /// The name must not be the tail of a longer identifier, or | ||
| 454 | - /// `inter_sb_none_gate` would "call" `sb_none_gate`. | ||
| 455 | - fn calls_fn(body: &str, name: &str) -> bool { | ||
| 456 | - let ident = |b: u8| b.is_ascii_alphanumeric() || b == b'_'; | ||
| 457 | - let mut at = 0usize; | ||
| 458 | - while let Some(rel) = body[at..].find(name) { | ||
| 459 | - let start = at + rel; | ||
| 460 | - let end = start + name.len(); | ||
| 461 | - let starts_clean = start == 0 || !ident(body.as_bytes()[start - 1]); | ||
| 462 | - if starts_clean && body[end..].starts_with('(') { | ||
| 463 | - return true; | ||
| 464 | - } | ||
| 465 | - at = end; | ||
| 466 | - } | ||
| 467 | - false | ||
| 468 | - } | ||
| 469 | - | ||
| 470 | - /// Every `fn` defined in `stream.rs`'s test module, as `(name, body)`. | ||
| 471 | - /// | ||
| 472 | - /// The census reasons about whole `#[`-segments (see [`gate_bodies`]) but | ||
| 473 | - /// has to know which segment DEFINES or CALLS an encoder-driving `fn`, and | ||
| 474 | - /// the only way to answer that is to name the units. | ||
| 475 | - fn fn_units(src: &'static str) -> Vec<(&'static str, &'static str)> { | ||
| 476 | - const OPEN: &str = "\n fn "; | ||
| 477 | - let mut units = Vec::new(); | ||
| 478 | - let mut at = 0usize; | ||
| 479 | - while let Some(rel) = src[at..].find(OPEN) { | ||
| 480 | - let head = at + rel + OPEN.len(); | ||
| 481 | - let Some(paren) = src[head..].find('(') else { | ||
| 482 | - break; | ||
| 483 | - }; | ||
| 484 | - let close = src[head..] | ||
| 485 | - .find("\n }\n") | ||
| 486 | - .map_or(src.len(), |e| head + e); | ||
| 487 | - units.push((&src[head..head + paren], &src[head..close])); | ||
| 488 | - at = close.max(head + paren + 1); | ||
| 489 | - } | ||
| 490 | - units | ||
| 491 | - } | ||
| 492 | - | ||
| 493 | - /// Names of every `fn` in `stream.rs` that drives the real `aomenc`, | ||
| 494 | - /// DIRECTLY (it mentions `aomenc_path()`) or by DELEGATING to one. | ||
| 495 | - /// | ||
| 496 | - /// lane-av1distwtd r3: the transitive closure is the whole point. A gate | ||
| 497 | - /// that hands its recipe to a shared helper (`inter_sb_none_gate` and | ||
| 498 | - /// friends) never spells `--passes=1` itself, so the old token filter | ||
| 499 | - /// dropped it -- 165 of 311 segments, 6 of which spell `--enable-X=1`. | ||
| 500 | - /// That is not a coverage fact, it is a segmentation fact, and it is what | ||
| 501 | - /// kept `enable-dual-filter` on the never-exercised lists while a named | ||
| 502 | - /// gate exercised the tool and hard-asserted the arrival. | ||
| 503 | - fn encoder_fns(src: &'static str) -> BTreeSet<&'static str> { | ||
| 504 | - let units = fn_units(src); | ||
| 505 | - let mut enc: BTreeSet<&'static str> = units | ||
| 506 | - .iter() | ||
| 507 | - .filter(|(_, body)| body.contains("aomenc_path()")) | ||
| 508 | - .map(|(name, _)| *name) | ||
| 509 | - .collect(); | ||
| 510 | - // Fixpoint: `inter_sb_none_gate` is an encoder fn because it names | ||
| 511 | - // `aomenc_path()`; the `#[test]` that only CALLS it is a gate too. | ||
| 512 | - loop { | ||
| 513 | - let mut grew = false; | ||
| 514 | - for (name, body) in &units { | ||
| 515 | - if enc.contains(name) { | ||
| 516 | - continue; | ||
| 517 | - } | ||
| 518 | - if enc.iter().any(|e| calls_fn(body, e)) { | ||
| 519 | - enc.insert(name); | ||
| 520 | - grew = true; | ||
| 521 | - } | ||
| 522 | - } | ||
| 523 | - if !grew { | ||
| 524 | - return enc; | ||
| 525 | - } | ||
| 526 | - } | ||
| 527 | - } | ||
| 528 | - | ||
| 529 | - /// The token spellings the filter used before it resolved calls. Kept as a | ||
| 530 | - /// floor: a gate is still recognised by these even if the call graph | ||
| 531 | - /// misses it, so the fix can only ever ADD gates, never lose one. | ||
| 532 | - fn legacy_gate_tokens(body: &str) -> bool { | ||
| 533 | - body.contains("\"--passes=1\"") | ||
| 534 | - || body.contains("ten_bit_tool_gate(") | ||
| 535 | - || body.contains("encode_10bit_gradients") | ||
| 536 | - } | ||
| 537 | - | ||
| 538 | - /// Bodies of the real-aomenc gates: a `fn` body that drives the real | ||
| 539 | - /// `aomenc`, however it gets there. Split on the attribute that opens a | ||
| 540 | - /// test. | ||
| 541 | - /// | ||
| 542 | - /// lane-av1distwtd r3: a segment qualifies if it spells one of the | ||
| 543 | - /// [`legacy_gate_tokens`] OR names an encoder `fn` -- either by defining | ||
| 544 | - /// one (it mentions `aomenc_path()`) or by calling one. Recognition by | ||
| 545 | - /// CALL is what a helper-delegating gate needs: its flags live in the | ||
| 546 | - /// helper it calls, and it is invisible to a spelling-only filter. | ||
| 547 | - fn gate_bodies() -> Vec<&'static str> { | ||
| 548 | - let src = crate::test_source::module_source("stream"); | ||
| 549 | - let enc = encoder_fns(src); | ||
| 550 | - let gates: Vec<&str> = src | ||
| 551 | - .split("\n #[") | ||
| 552 | - // lane-hbdgates r1: an `#[ignore]`d gate exercises nothing, so it | ||
| 553 | - // must not close a hole. Its body is the segment that opens with | ||
| 554 | - // the ignore attribute. | ||
| 555 | - .filter(|body| !body.starts_with("ignore")) | ||
| 556 | - // lane-av1distwtd r3: a segment qualifies by what it SPELLS | ||
| 557 | - // (`legacy_gate_tokens`) or by what it CALLS. `calls_fn` is | ||
| 558 | - // deliberately the weak half of an OR, so the fix can only add | ||
| 559 | - // gates -- it can never stop recognising one the old filter did. | ||
| 560 | - .filter(|body| { | ||
| 561 | - legacy_gate_tokens(body) | ||
| 562 | - || body.contains("aomenc_path()") | ||
| 563 | - || enc.iter().any(|e| calls_fn(body, e)) | ||
| 564 | - }) | ||
| 565 | - .collect(); | ||
| 566 | - assert!( | ||
| 567 | - gates.len() >= 20, | ||
| 568 | - "expected the real-aomenc gates, found {}", | ||
| 569 | - gates.len() | ||
| 570 | - ); | ||
| 571 | - gates | ||
| 572 | - } | ||
| 573 | - | ||
| 574 | - /// `--enable-<flag>=<value>` settings spelled inside one gate body. | ||
| 575 | - fn flags_in(gate: &str) -> BTreeMap<String, char> { | ||
| 576 | - let mut here = BTreeMap::new(); | ||
| 577 | - for (i, _) in gate.match_indices("\"--enable-") { | ||
| 578 | - let rest = &gate[i + 3..]; | ||
| 579 | - let Some(end) = rest.find('"') else { continue }; | ||
| 580 | - let Some((flag, value)) = rest[..end].split_once('=') else { | ||
| 581 | - continue; | ||
| 582 | - }; | ||
| 583 | - let Some(value) = value.chars().next() else { | ||
| 584 | - continue; | ||
| 585 | - }; | ||
| 586 | - here.insert(flag.to_owned(), value); | ||
| 587 | - } | ||
| 588 | - here | ||
| 589 | - } | ||
| 590 | - | ||
| 591 | - /// Every `--flag=value` spelled inside one gate body, values kept whole | ||
| 592 | - /// (`--cpu-used=4`, `--tile-columns=2`), not just their first character. | ||
| 593 | - fn settings_in(gate: &str) -> BTreeMap<String, String> { | ||
| 594 | - let mut here = BTreeMap::new(); | ||
| 595 | - for (i, _) in gate.match_indices("\"--") { | ||
| 596 | - let rest = &gate[i + 3..]; | ||
| 597 | - let Some(end) = rest.find('"') else { continue }; | ||
| 598 | - let Some((flag, value)) = rest[..end].split_once('=') else { | ||
| 599 | - continue; | ||
| 600 | - }; | ||
| 601 | - here.insert(flag.to_owned(), value.to_owned()); | ||
| 602 | - } | ||
| 603 | - here | ||
| 604 | - } | ||
| 605 | - | ||
| 606 | - /// The values a `--<flag>={var}` TEMPLATE can take in one gate body, from | ||
| 607 | - /// the local binding of `var`. | ||
| 608 | - /// | ||
| 609 | - /// lane-av1txsearch: `settings_in` reads a `--flag=value` string LITERAL, | ||
| 610 | - /// so a flag a gate builds with `format!` was invisible to it -- 10 gate | ||
| 611 | - /// bodies spell `--enable-tx-size-search` only this way, and the census | ||
| 612 | - /// filed them as "defaulted", i.e. unknown in BOTH directions. The | ||
| 613 | - /// bindings that actually exist in `stream.rs` are four shapes, and each | ||
| 614 | - /// is resolved from the gate's own text rather than from the variable's | ||
| 615 | - /// name: | ||
| 616 | - /// | ||
| 617 | - /// 1. `let <var> = if <attempt> == 0 { "0" } else { "1" };` -- an | ||
| 618 | - /// attempt-indexed arm; the QUOTED values in the initializer are | ||
| 619 | - /// collected. Bare integers in the initializer (`attempt % 2`) are | ||
| 620 | - /// deliberately NOT read as flag values. | ||
| 621 | - /// 2. `for <var> in [0usize, 1]` / `["0", "1"]` -- a loop over both | ||
| 622 | - /// values; every element of the array is collected. | ||
| 623 | - /// 3. `for (<var>, <other>) in [("1", 8u8), ("0", 8u8), ...]` -- a | ||
| 624 | - /// tuple-destructured loop; only the element at `<var>`'s POSITION is | ||
| 625 | - /// collected from each tuple, so the arm table's bit-depth column is | ||
| 626 | - /// not read as a flag value. | ||
| 627 | - /// 4. `u8::from(<a>.<field>)` over a struct-literal arm table whose | ||
| 628 | - /// `field: true` / `field: false` rows are the flag values. | ||
| 629 | - /// | ||
| 630 | - /// `None` means the binding is NOT in this body -- the variable is a | ||
| 631 | - /// parameter of a shared helper and its value is bound at the CALL SITE, | ||
| 632 | - /// which lives in a different `#[`-segment. That is a real limit of a | ||
| 633 | - /// per-segment census and is reported as unknown rather than guessed: | ||
| 634 | - /// inferring the value from the variable's name is the exact failure this | ||
| 635 | - /// function exists to remove. | ||
| 636 | - fn bound_values(body: &str, var: &str) -> Option<BTreeSet<char>> { | ||
| 637 | - // Quoted single digits: `"0"`, `"1"`. | ||
| 638 | - let quoted_digits = |t: &str| -> BTreeSet<char> { | ||
| 639 | - let mut out = BTreeSet::new(); | ||
| 640 | - let mut at = 0usize; | ||
| 641 | - while let Some(rel) = t[at..].find('"') { | ||
| 642 | - let start = at + rel + 1; | ||
| 643 | - let Some(end) = t[start..].find('"') else { | ||
| 644 | - break; | ||
| 645 | - }; | ||
| 646 | - let literal = &t[start..start + end]; | ||
| 647 | - if literal.len() == 1 | ||
| 648 | - && let Some(c) = literal.chars().next() | ||
| 649 | - && c.is_ascii_digit() { | ||
| 650 | - out.insert(c); | ||
| 651 | - } | ||
| 652 | - at = start + end + 1; | ||
| 653 | - } | ||
| 654 | - out | ||
| 655 | - }; | ||
| 656 | - // Bare integer literals: `0usize`, `1`, `8u8`. Whole tokens only, so | ||
| 657 | - // `10u8` contributes nothing rather than a bogus `1`. | ||
| 658 | - let bare_digits = |t: &str| -> BTreeSet<char> { | ||
| 659 | - let mut out = BTreeSet::new(); | ||
| 660 | - let bytes = t.as_bytes(); | ||
| 661 | - let mut i = 0usize; | ||
| 662 | - while i < bytes.len() { | ||
| 663 | - if !bytes[i].is_ascii_digit() { | ||
| 664 | - i += 1; | ||
| 665 | - continue; | ||
| 666 | - } | ||
| 667 | - let start = i; | ||
| 668 | - while i < bytes.len() && bytes[i].is_ascii_digit() { | ||
| 669 | - i += 1; | ||
| 670 | - } | ||
| 671 | - let clean_before = start == 0 || !is_ident_byte(bytes[start - 1]); | ||
| 672 | - // A typed literal's suffix (`0usize`, `8u8`, `1u32`) belongs to | ||
| 673 | - // the same token, so a run of LOWERCASE letters right after | ||
| 674 | - // the digit is a type, not a different identifier. Anything | ||
| 675 | - // else -- a multi-digit `10u8`, a camelCase `1x` -- is not a | ||
| 676 | - // flag value and is rejected. | ||
| 677 | - let rest = &t[i..]; | ||
| 678 | - let suffix = rest | ||
| 679 | - .bytes() | ||
| 680 | - .take_while(|b| b.is_ascii_lowercase() || *b == b'_') | ||
| 681 | - .count(); | ||
| 682 | - let clean_after = i >= bytes.len() | ||
| 683 | - || !is_ident_byte(bytes[i]) | ||
| 684 | - || (suffix > 0 | ||
| 685 | - && i + suffix < bytes.len() | ||
| 686 | - && !is_ident_byte(bytes[i + suffix])); | ||
| 687 | - if clean_before && clean_after && i - start == 1 { | ||
| 688 | - out.insert(bytes[start] as char); | ||
| 689 | - } | ||
| 690 | - } | ||
| 691 | - out | ||
| 692 | - }; | ||
| 693 | - // Split a comma-separated list at TOP level only, so `("1", 8u8)` | ||
| 694 | - // stays one element. | ||
| 695 | - fn split_top(t: &str) -> Vec<&str> { | ||
| 696 | - let mut out = Vec::new(); | ||
| 697 | - let (mut depth, mut start) = (0i32, 0usize); | ||
| 698 | - for (i, c) in t.char_indices() { | ||
| 699 | - match c { | ||
| 700 | - '(' | '[' | '{' => depth += 1, | ||
| 701 | - ')' | ']' | '}' => depth -= 1, | ||
| 702 | - ',' if depth == 0 => { | ||
| 703 | - out.push(t[start..i].trim()); | ||
| 704 | - start = i + 1; | ||
| 705 | - } | ||
| 706 | - _ => {} | ||
| 707 | - } | ||
| 708 | - } | ||
| 709 | - if start < t.len() { | ||
| 710 | - out.push(t[start..].trim()); | ||
| 711 | - } | ||
| 712 | - out | ||
| 713 | - } | ||
| 714 | - // The body of the `[...]` that FOLLOWS `head` in `text`. Scoped to | ||
| 715 | - // the header rather than searching from the start of the body: a | ||
| 716 | - // gate's first `[` may be an unrelated array, and brackets that do | ||
| 717 | - // not balance across a whole gate body would leave the depth count | ||
| 718 | - // never returning to zero. | ||
| 719 | - fn loop_array_after<'a>(text: &'a str, head: &str) -> Option<&'a str> { | ||
| 720 | - let at = text.find(head)? + head.len(); | ||
| 721 | - let open = at + text[at..].find('[')?; | ||
| 722 | - let mut depth = 0i32; | ||
| 723 | - for (i, c) in text[open..].char_indices() { | ||
| 724 | - match c { | ||
| 725 | - '[' => depth += 1, | ||
| 726 | - ']' => { | ||
| 727 | - depth -= 1; | ||
| 728 | - if depth == 0 { | ||
| 729 | - return Some(&text[open + 1..open + i]); | ||
| 730 | - } | ||
| 731 | - } | ||
| 732 | - _ => {} | ||
| 733 | - } | ||
| 734 | - } | ||
| 735 | - None | ||
| 736 | - } | ||
| 737 | - let mut found: Option<BTreeSet<char>> = None; | ||
| 738 | - let mut merge = |set: BTreeSet<char>| match &mut found { | ||
| 739 | - Some(all) => all.extend(set), | ||
| 740 | - None => found = Some(set), | ||
| 741 | - }; | ||
| 742 | - // (1) `let <var> = if ... { "0" } else { "1" };` -- quoted values only. | ||
| 743 | - if let Some(at) = body.find(&format!("let {var} =")) { | ||
| 744 | - let init = &body[at..]; | ||
| 745 | - let end = init.find(';').unwrap_or(init.len()); | ||
| 746 | - merge(quoted_digits(&init[..end])); | ||
| 747 | - } | ||
| 748 | - // (2) `for <var> in [...]` -- every element of the array. | ||
| 749 | - if let Some(array) = loop_array_after(body, &format!("for {var} in ")) { | ||
| 750 | - merge(bare_digits(array)); | ||
| 751 | - merge(quoted_digits(array)); | ||
| 752 | - } | ||
| 753 | - // (3) `for (<var>, ...) in [(...), ...]` -- only `<var>`'s column. | ||
| 754 | - if let Some(at) = body.find("for (") { | ||
| 755 | - let head = &body[at..]; | ||
| 756 | - if let Some(close) = head.find(')') { | ||
| 757 | - let pattern = &head["for (".len()..close]; | ||
| 758 | - if let Some(pos) = pattern.split(',').position(|p| p.trim() == var) { | ||
| 759 | - let header = format!("for ({pattern}) in "); | ||
| 760 | - if let Some(array) = loop_array_after(body, &header) { | ||
| 761 | - let mut set: BTreeSet<char> = BTreeSet::new(); | ||
| 762 | - for tuple in split_top(array) { | ||
| 763 | - let Some(inner) = | ||
| 764 | - tuple.strip_prefix('(').and_then(|t| t.strip_suffix(')')) | ||
| 765 | - else { | ||
| 766 | - continue; | ||
| 767 | - }; | ||
| 768 | - let fields = split_top(inner); | ||
| 769 | - let Some(field) = fields.get(pos) else { | ||
| 770 | - continue; | ||
| 771 | - }; | ||
| 772 | - set.extend(bare_digits(field)); | ||
| 773 | - set.extend(quoted_digits(field)); | ||
| 774 | - } | ||
| 775 | - merge(set); | ||
| 776 | - } | ||
| 777 | - } | ||
| 778 | - } | ||
| 779 | - } | ||
| 780 | - // (3b) `for (<var>, ...) in <ident>` where `<ident>` is a `let` | ||
| 781 | - // binding in this same body -- the arm table hoisted OUT of the | ||
| 782 | - // loop header, so the `for` line NAMES the array instead of | ||
| 783 | - // spelling it. Strategy (3) alone silently reads past the `for` | ||
| 784 | - // line to the next `[` in the body (an unrelated `&[..]` flag | ||
| 785 | - // list), finds no digits, and returns an empty set: the gate is | ||
| 786 | - // then filed as UNRESOLVED even though both of its arms sit | ||
| 787 | - // verbatim in the source. Measured: the 128x96 4:4:4 lossy | ||
| 788 | - // tx-size-search gate, whose `for (label, search, ...) in arms` | ||
| 789 | - // drove `print_tx_size_search_census`'s `unresolvable == 0` | ||
| 790 | - // assertion red on merge. The `=` hop matters: the binding's | ||
| 791 | - // TYPE annotation is itself bracketed | ||
| 792 | - // (`[(&str, &str, TxMode, usize, u64); 2]`), so scanning for the | ||
| 793 | - // first `[` after the name would return the type. | ||
| 794 | - // `<var>`'s column, read off the arm table a hoisted `for` line | ||
| 795 | - // NAMES rather than spells. Returns `None` unless the body really | ||
| 796 | - // has that shape, so an unrecognised loop is left to the other | ||
| 797 | - // strategies instead of being read as "no values". | ||
| 798 | - let named_column = |pos: usize| -> Option<BTreeSet<char>> { | ||
| 799 | - let at = body.find("for (")?; | ||
| 800 | - let head = &body[at..]; | ||
| 801 | - let close = head.find(')')?; | ||
| 802 | - let after = head[close + 1..].trim_start().strip_prefix("in ")?; | ||
| 803 | - let name: &str = after | ||
| 804 | - .split(|c: char| !is_ident_byte(c as u8)) | ||
| 805 | - .next() | ||
| 806 | - .filter(|n| !n.is_empty() && !n.starts_with(|c: char| c.is_ascii_digit()))?; | ||
| 807 | - let decl = body.find(&format!("let {name}"))?; | ||
| 808 | - let after_name = decl + "let ".len() + name.len(); | ||
| 809 | - // `let arms_foo` must not answer for `let arms`. | ||
| 810 | - if body[after_name..] | ||
| 811 | - .chars() | ||
| 812 | - .next() | ||
| 813 | - .is_some_and(|c| is_ident_byte(c as u8)) | ||
| 814 | - { | ||
| 815 | - return None; | ||
| 816 | - } | ||
| 817 | - // Hop the `=`: the binding's TYPE annotation is itself | ||
| 818 | - // bracketed, so the first `[` after the name is the type. | ||
| 819 | - let eq = after_name + body[after_name..].find('=')?; | ||
| 820 | - let open = eq + 1 + body[eq + 1..].find('[')?; | ||
| 821 | - let mut depth = 0i32; | ||
| 822 | - for (i, c) in body[open..].char_indices() { | ||
| 823 | - match c { | ||
| 824 | - '[' => depth += 1, | ||
| 825 | - ']' => { | ||
| 826 | - depth -= 1; | ||
| 827 | - if depth == 0 { | ||
| 828 | - let mut set: BTreeSet<char> = Default::default(); | ||
| 829 | - for tuple in split_top(&body[open + 1..open + i]) { | ||
| 830 | - let Some(inner) = | ||
| 831 | - tuple.strip_prefix('(').and_then(|t| t.strip_suffix(')')) | ||
| 832 | - else { | ||
| 833 | - continue; | ||
| 834 | - }; | ||
| 835 | - let fields = split_top(inner); | ||
| 836 | - let Some(field) = fields.get(pos) else { | ||
| 837 | - continue; | ||
| 838 | - }; | ||
| 839 | - set.extend(bare_digits(field)); | ||
| 840 | - set.extend(quoted_digits(field)); | ||
| 841 | - } | ||
| 842 | - return Some(set); | ||
| 843 | - } | ||
| 844 | - } | ||
| 845 | - _ => {} | ||
| 846 | - } | ||
| 847 | - } | ||
| 848 | - None | ||
| 849 | - }; | ||
| 850 | - if let Some(at) = body.find("for (") { | ||
| 851 | - let head = &body[at..]; | ||
| 852 | - if let Some(close) = head.find(')') { | ||
| 853 | - let pattern = &head["for (".len()..close]; | ||
| 854 | - if let Some(pos) = pattern.split(',').position(|p| p.trim() == var) | ||
| 855 | - && let Some(set) = named_column(pos) { | ||
| 856 | - merge(set); | ||
| 857 | - } | ||
| 858 | - } | ||
| 859 | - } | ||
| 860 | - // (4) `u8::from(<a>.<field>)` over a struct-literal arm table. | ||
| 861 | - for (i, _) in body.match_indices("u8::from(") { | ||
| 862 | - let arg = &body[i + "u8::from(".len()..]; | ||
| 863 | - let Some(close) = arg.find(')') else { continue }; | ||
| 864 | - let field = arg[..close].rsplit('.').next().unwrap_or_default().trim(); | ||
| 865 | - if field.is_empty() || !field.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { | ||
| 866 | - continue; | ||
| 867 | - } | ||
| 868 | - let mut set = BTreeSet::new(); | ||
| 869 | - for (row, value) in [("true", '1'), ("false", '0')] { | ||
| 870 | - if body.contains(&format!("{field}: {row}")) { | ||
| 871 | - set.insert(value); | ||
| 872 | - } | ||
| 873 | - } | ||
| 874 | - merge(set); | ||
| 875 | - } | ||
| 876 | - found | ||
| 877 | - } | ||
| 878 | - | ||
| 879 | - fn is_ident_byte(b: u8) -> bool { | ||
| 880 | - b.is_ascii_alphanumeric() || b == b'_' | ||
| 881 | - } | ||
| 882 | - | ||
| 883 | - /// Values of one [`DEFAULT_ON_TOOLS`] spelling in one gate body: the | ||
| 884 | - /// literal `--<spelling>=<digit>` spellings plus every value a `format!` | ||
| 885 | - /// template built from a local binding resolves to. | ||
| 886 | - /// | ||
| 887 | - /// A gate that reaches BOTH values counts ON, not off: it builds a `=1` | ||
| 888 | - /// stream on some attempt, which is what the census asks for. This is the | ||
| 889 | - /// file's standing "any spelling that says on wins" rule | ||
| 890 | - /// (`--tile-columns=0 --tile-rows=1` is a multi-tile stream), now applied | ||
| 891 | - /// across a loop's arms as well as across spellings. | ||
| 892 | - fn spelling_values(gate: &str, spelling: &str) -> BTreeSet<char> { | ||
| 893 | - let mut out = BTreeSet::new(); | ||
| 894 | - // A literal `"--<spelling>=<digit>"`: the needle ends at the `=`, so | ||
| 895 | - // the value starts AT the needle's length, not three characters in. | ||
| 896 | - let literal = format!("\"--{spelling}="); | ||
| 897 | - for (i, _) in gate.match_indices(&literal) { | ||
| 898 | - let rest = &gate[i + literal.len()..]; | ||
| 899 | - let Some(end) = rest.find('"') else { continue }; | ||
| 900 | - if let Some(c) = rest[..end].chars().next() | ||
| 901 | - && c.is_ascii_digit() { | ||
| 902 | - out.insert(c); | ||
| 903 | - } | ||
| 904 | - } | ||
| 905 | - // A template `format!("--<spelling>={<var>}")`: the placeholder name | ||
| 906 | - // is the part between the braces, and its VALUE is whatever the | ||
| 907 | - // binding of `<var>` in this same body reaches. | ||
| 908 | - let template = format!("format!(\"--{spelling}="); | ||
| 909 | - for (i, _) in gate.match_indices(&template) { | ||
| 910 | - let rest = &gate[i + template.len()..]; | ||
| 911 | - let Some(end) = rest.find('"') else { continue }; | ||
| 912 | - let Some(var) = rest[..end] | ||
| 913 | - .strip_prefix('{') | ||
| 914 | - .and_then(|v| v.strip_suffix('}')) | ||
| 915 | - else { | ||
| 916 | - continue; | ||
| 917 | - }; | ||
| 918 | - if var.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { | ||
| 919 | - out.extend(bound_values(gate, var).unwrap_or_default()); | ||
| 920 | - } | ||
| 921 | - } | ||
| 922 | - out | ||
| 923 | - } | ||
| 924 | - | ||
| 925 | - /// Whether a gate body spells one [`DEFAULT_ON_TOOLS`] entry on / off, | ||
| 926 | - /// over [`spelling_values`] -- so a `format!`-built flag is classified | ||
| 927 | - /// instead of being filed as "defaulted". | ||
| 928 | - fn resolved_on_state(gate: &str, spellings: &[&str], on: On) -> Option<bool> { | ||
| 929 | - let mut state = None; | ||
| 930 | - for spelling in spellings { | ||
| 931 | - for c in spelling_values(gate, spelling) { | ||
| 932 | - let value = c.to_digit(10).unwrap_or(0); | ||
| 933 | - let is_on = match on { | ||
| 934 | - On::NonZero => value != 0, | ||
| 935 | - On::AtMost(limit) => value <= limit, | ||
| 936 | - }; | ||
| 937 | - state = Some(state.unwrap_or(false) || is_on); | ||
| 938 | - } | ||
| 939 | - } | ||
| 940 | - state | ||
| 941 | - } | ||
| 942 | - | ||
| 943 | - /// `--enable-*` settings per real-aomenc gate, derived from the gate | ||
| 944 | - /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`. | ||
| 945 | - fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) { | ||
| 946 | - let gates = gate_bodies(); | ||
| 947 | - | ||
| 948 | - let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new(); | ||
| 949 | - let mut names: BTreeSet<String> = BTreeSet::new(); | ||
| 950 | - let mut seen: Vec<BTreeMap<String, char>> = Vec::new(); | ||
| 951 | - for gate in &gates { | ||
| 952 | - let here = flags_in(gate); | ||
| 953 | - names.extend(here.keys().cloned()); | ||
| 954 | - seen.push(here); | ||
| 955 | - } | ||
| 956 | - for name in names { | ||
| 957 | - let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count(); | ||
| 958 | - let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count(); | ||
| 959 | - per_tool.insert(name, (off, on, gates.len() - off - on)); | ||
| 960 | - } | ||
| 961 | - (gates.len(), per_tool) | ||
| 962 | - } | ||
| 963 | - | ||
| 964 | - #[test] | ||
| 965 | - fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() { | ||
| 966 | - let (gate_count, per_tool) = tool_settings(); | ||
| 967 | - // A hole OPENS when every gate names the flag and every one of them | ||
| 968 | - // says 0 -- then no real stream can exercise the tool. | ||
| 969 | - let derived: BTreeSet<&str> = per_tool | ||
| 970 | - .iter() | ||
| 971 | - .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0) | ||
| 972 | - .map(|(name, _)| name.as_str()) | ||
| 973 | - .collect(); | ||
| 974 | - // A hole CLOSES only on positive evidence: some gate passes `=1`. | ||
| 975 | - // A gate that merely leaves the flag off its command line proves | ||
| 976 | - // nothing -- aomenc's default for palette and intrabc is content- | ||
| 977 | - // dependent -- so "defaulted" must not retire an entry, or a listing | ||
| 978 | - // would disappear the moment an unrelated gate is added. | ||
| 979 | - let exercised: BTreeSet<&str> = per_tool | ||
| 980 | - .iter() | ||
| 981 | - .filter(|&(_, &(_, on, _))| on > 0) | ||
| 982 | - .map(|(name, _)| name.as_str()) | ||
| 983 | - .collect(); | ||
| 984 | - let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect(); | ||
| 985 | - | ||
| 986 | - let unlisted: Vec<&&str> = derived.difference(&listed).collect(); | ||
| 987 | - assert!( | ||
| 988 | - unlisted.is_empty(), | ||
| 989 | - "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \ | ||
| 990 | - none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \ | ||
| 991 | - {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \ | ||
| 992 | - list with a reason" | ||
| 993 | - ); | ||
| 994 | - let stale: Vec<&&str> = listed.intersection(&exercised).collect(); | ||
| 995 | - assert!( | ||
| 996 | - stale.is_empty(), | ||
| 997 | - "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \ | ||
| 998 | - those entries, the coverage hole is closed" | ||
| 999 | - ); | ||
| 1000 | - } | ||
| 1001 | - | ||
| 1002 | - /// The derivation is only meaningful if a flag left off a gate's command | ||
| 1003 | - /// line really does mean "aomenc's default", i.e. the parser above is | ||
| 1004 | - /// reading whole flags and not fragments. | ||
| 1005 | - #[test] | ||
| 1006 | - fn tool_settings_reads_whole_flags() { | ||
| 1007 | - let (gate_count, per_tool) = tool_settings(); | ||
| 1008 | - assert!( | ||
| 1009 | - per_tool.contains_key("enable-cdef"), | ||
| 1010 | - "expected --enable-cdef among the gate flags" | ||
| 1011 | - ); | ||
| 1012 | - for (name, &(off, on, defaulted)) in &per_tool { | ||
| 1013 | - assert!( | ||
| 1014 | - !name.is_empty() && !name.contains(['"', '=']), | ||
| 1015 | - "malformed flag {name:?}" | ||
| 1016 | - ); | ||
| 1017 | - assert_eq!( | ||
| 1018 | - off + on + defaulted, | ||
| 1019 | - gate_count, | ||
| 1020 | - "{name} counts do not cover every gate" | ||
| 1021 | - ); | ||
| 1022 | - } | ||
| 1023 | - } | ||
| 1024 | - | ||
| 1025 | - /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit | ||
| 1026 | - /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a | ||
| 1027 | - /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's | ||
| 1028 | - /// 8-bit default. | ||
| 1029 | - /// lane-defon r1: a gate helper parameterised on `bit_depth` builds BOTH | ||
| 1030 | - /// an 8-bit and a 10-bit stream from one recipe, so its flags cover both | ||
| 1031 | - /// depths -- classifying it by the 10-bit strings inside its conditional | ||
| 1032 | - /// alone hid `--enable-tx-size-search=1` from the 8-bit list. | ||
| 1033 | - /// lane-reelckf r1: the same blind spot with the other spelling -- a gate | ||
| 1034 | - /// that loops `for depth in [8usize, 10]` builds BOTH streams from one | ||
| 1035 | - /// recipe, but its `yuv420p10le` arm made `is_ten_bit` classify it as | ||
| 1036 | - /// 10-bit only, hiding `--enable-cfl-intra=1` from the 8-bit list. | ||
| 1037 | - /// lane-av1-intrabc r1: the shared recipe helper | ||
| 1038 | - /// `screen_intrabc_stream_at_depth` is parameterised on `depth` and sits in | ||
| 1039 | - /// the segment that opens at the PRECEDING gate's `#[test]`, so without | ||
| 1040 | - /// this marker that gate's own 8-bit-only flags read as 10-bit-only -- the | ||
| 1041 | - /// lane-defon/reelckf blind spot with `depth` spelled instead of | ||
| 1042 | - /// `bit_depth`. Three gates share the helper, at both depths. | ||
| 1043 | - /// lane-av1distwtd r3: the THIRD spelling of the same blind spot, still | ||
| 1044 | - /// live after lane-defon and lane-reelckf. A recipe parameterised on | ||
| 1045 | - /// `ten_bit` names BOTH fixture formats in one body -- `let pix_fmt = if | ||
| 1046 | - /// ten_bit { "yuv420p10le" } else { "yuv420p" };` -- so `is_ten_bit` saw | ||
| 1047 | - /// the 10-bit arm and filed the whole body 10-bit-ONLY, hiding its 8-bit | ||
| 1048 | - /// arm from the 8-bit bucket. The marker is the PAIR OF FORMATS, not the | ||
| 1049 | - /// parameter name: a body spelling both pixel formats builds streams at | ||
| 1050 | - /// both depths, whatever it calls the flag. The quotes matter -- a bare | ||
| 1051 | - /// `yuv420p` substring test also matches `yuv420p10le` and would fire on | ||
| 1052 | - /// every 10-bit gate, retiring entries on no evidence. | ||
| 1053 | - /// | ||
| 1054 | - /// This is what mis-filed `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` | ||
| 1055 | - /// and kept `enable-flip-idtx` on the 8-bit list while that gate ran 6 | ||
| 1056 | - /// pixel-exact 8-bit decodes through it. | ||
| 1057 | - fn covers_both_depths(body: &str) -> bool { | ||
| 1058 | - body.contains("if bit_depth == 10") | ||
| 1059 | - || body.contains("if depth == 10") | ||
| 1060 | - || body.contains("for depth in [8usize, 10]") | ||
| 1061 | - || (body.contains("\"yuv420p\"") && body.contains("\"yuv420p10le\"")) | ||
| 1062 | - } | ||
| 1063 | - | ||
| 1064 | - /// lane-av1distwtd r3: the detector fix, pinned. A detector change with | ||
| 1065 | - /// no test can only be shown to find MORE, never to stop missing, so this | ||
| 1066 | - /// asserts the three gates the two blind spots actually hid are now seen | ||
| 1067 | - /// -- the two `enable-dual-filter` witnesses and the `enable-flip-idtx` | ||
| 1068 | - /// both-depths gate -- and that the fix is strictly ADDITIVE against the | ||
| 1069 | - /// old spelling-only filter. | ||
| 1070 | - #[test] | ||
| 1071 | - fn the_detector_sees_the_gates_the_spelling_filter_missed() { | ||
| 1072 | - let src = crate::test_source::module_source("stream"); | ||
| 1073 | - let gates = gate_bodies(); | ||
| 1074 | - // The helper-delegation half: each of these builds its stream through | ||
| 1075 | - // `inter_sb_none_gate` and spells none of `legacy_gate_tokens`, so the | ||
| 1076 | - // old filter dropped both while each hard-asserts its tool arrived. | ||
| 1077 | - for name in [ | ||
| 1078 | - "a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact", | ||
| 1079 | - "a_real_obmc_stream_reads_a_recorded_switchable_filter_for_every_neighbour", | ||
| 1080 | - ] { | ||
| 1081 | - let body = gates | ||
| 1082 | - .iter() | ||
| 1083 | - .find(|b| b.contains(name)) | ||
| 1084 | - .unwrap_or_else(|| panic!("{name}: not seen by gate_bodies()")); | ||
| 1085 | - assert_eq!( | ||
| 1086 | - flags_in(body).get("enable-dual-filter"), | ||
| 1087 | - Some(&'1'), | ||
| 1088 | - "{name}: seen, but its --enable-dual-filter=1 spelling is not visible to \ | ||
| 1089 | - flags_in, so recognising the gate would not retire the entry" | ||
| 1090 | - ); | ||
| 1091 | - } | ||
| 1092 | - // The both-depths half: this gate's recipe is parameterised on `ten_bit` | ||
| 1093 | - // and names both fixture formats, so `covers_both_depths` must credit | ||
| 1094 | - // it to the 8-bit bucket, not just the 10-bit one. | ||
| 1095 | - let flip = gates | ||
| 1096 | - .iter() | ||
| 1097 | - .find(|b| b.contains("a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform")) | ||
| 1098 | - .expect("the flip-idtx gate must be seen"); | ||
| 1099 | - assert!( | ||
| 1100 | - covers_both_depths(flip), | ||
| 1101 | - "the flip-idtx gate spells both fixture formats, so covers_both_depths must \ | ||
| 1102 | - credit it to the 8-bit bucket as well" | ||
| 1103 | - ); | ||
| 1104 | - assert!( | ||
| 1105 | - covers_depth(flip, false) && covers_depth(flip, true), | ||
| 1106 | - "the flip-idtx gate must cover BOTH depths" | ||
| 1107 | - ); | ||
| 1108 | - // Strictly additive: every segment the old spelling-only filter kept | ||
| 1109 | - // is still kept, so the fix cannot have cost the census a gate. | ||
| 1110 | - let legacy_only: Vec<&str> = src | ||
| 1111 | - .split("\n #[") | ||
| 1112 | - .filter(|b| !b.starts_with("ignore") && legacy_gate_tokens(b)) | ||
| 1113 | - .collect(); | ||
| 1114 | - assert!( | ||
| 1115 | - legacy_only.len() < gates.len(), | ||
| 1116 | - "the call-resolving filter found {} gates, the old spelling-only filter found \ | ||
| 1117 | - {} -- the fix is expected to ADD gates, never to drop one", | ||
| 1118 | - gates.len(), | ||
| 1119 | - legacy_only.len() | ||
| 1120 | - ); | ||
| 1121 | - for body in &legacy_only { | ||
| 1122 | - assert!( | ||
| 1123 | - gates.contains(body), | ||
| 1124 | - "a gate the spelling-only filter recognised is no longer recognised: \ | ||
| 1125 | - {:?}", | ||
| 1126 | - &body[..body.len().min(60)] | ||
| 1127 | - ); | ||
| 1128 | - } | ||
| 1129 | - } | ||
| 1130 | - | ||
| 1131 | - /// Whether a gate body drives a stream at this depth. | ||
| 1132 | - fn covers_depth(body: &str, ten_bit: bool) -> bool { | ||
| 1133 | - covers_both_depths(body) || is_ten_bit(body) == ten_bit | ||
| 1134 | - } | ||
| 1135 | - | ||
| 1136 | - fn is_ten_bit(body: &str) -> bool { | ||
| 1137 | - // The lists pin two buckets, 8-bit and high-bit-depth; 12-bit gates | ||
| 1138 | - // count in the high-depth bucket (lane-av1gwarp12's ROTZOOM gate was | ||
| 1139 | - // the first 12-bit gate to positively enable a listed tool, and the | ||
| 1140 | - // 10-bit-only spellings mis-filed it as 8-bit). | ||
| 1141 | - body.contains("encode_10bit_gradients") | ||
| 1142 | - || body.contains("ten_bit_tool_gate(") | ||
| 1143 | - || body.contains("--bit-depth=10") | ||
| 1144 | - || body.contains("--input-bit-depth=10") | ||
| 1145 | - || body.contains("yuv420p10le") | ||
| 1146 | - || body.contains("encode_12bit(") | ||
| 1147 | - || body.contains("--bit-depth=12") | ||
| 1148 | - || body.contains("--input-bit-depth=12") | ||
| 1149 | - || body.contains("yuv420p12le") | ||
| 1150 | - } | ||
| 1151 | - | ||
| 1152 | - /// Flags a gate positively enables (`=1`), at gates of the given depth. | ||
| 1153 | - fn enabled_at(ten_bit: bool) -> BTreeSet<String> { | ||
| 1154 | - let mut on = BTreeSet::new(); | ||
| 1155 | - for gate in gate_bodies() { | ||
| 1156 | - if !covers_depth(gate, ten_bit) { | ||
| 1157 | - continue; | ||
| 1158 | - } | ||
| 1159 | - for (flag, value) in flags_in(gate) { | ||
| 1160 | - if value == '1' { | ||
| 1161 | - on.insert(flag); | ||
| 1162 | - } | ||
| 1163 | - } | ||
| 1164 | - // A tool driven by its own spelling counts as exercised. | ||
| 1165 | - let here = settings_in(gate); | ||
| 1166 | - for (alias, tool) in ALIASES { | ||
| 1167 | - if here.get(*alias).is_some_and(|v| v != "0") { | ||
| 1168 | - on.insert((*tool).to_owned()); | ||
| 1169 | - } | ||
| 1170 | - } | ||
| 1171 | - } | ||
| 1172 | - on | ||
| 1173 | - } | ||
| 1174 | - | ||
| 1175 | - /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables. | ||
| 1176 | - fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> { | ||
| 1177 | - let on = enabled_at(ten_bit); | ||
| 1178 | - TOOL_UNIVERSE | ||
| 1179 | - .iter() | ||
| 1180 | - .copied() | ||
| 1181 | - .filter(|t| !on.contains(*t)) | ||
| 1182 | - .collect() | ||
| 1183 | - } | ||
| 1184 | - | ||
| 1185 | - fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) { | ||
| 1186 | - let derived = never_exercised_at(ten_bit); | ||
| 1187 | - let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect(); | ||
| 1188 | - let depth = if ten_bit { "10-bit" } else { "8-bit" }; | ||
| 1189 | - let unlisted: Vec<&&str> = derived.difference(&listed).collect(); | ||
| 1190 | - assert!( | ||
| 1191 | - unlisted.is_empty(), | ||
| 1192 | - "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \ | ||
| 1193 | - them -- enable the tool in a {depth} gate that asserts it fired, or list it" | ||
| 1194 | - ); | ||
| 1195 | - let stale: Vec<&&str> = listed.difference(&derived).collect(); | ||
| 1196 | - assert!( | ||
| 1197 | - stale.is_empty(), | ||
| 1198 | - "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \ | ||
| 1199 | - -- delete those entries, the coverage hole is closed" | ||
| 1200 | - ); | ||
| 1201 | - } | ||
| 1202 | - | ||
| 1203 | - #[test] | ||
| 1204 | - fn never_exercised_8bit_matches_the_gate_recipes() { | ||
| 1205 | - check_depth(false, NEVER_EXERCISED_8BIT); | ||
| 1206 | - } | ||
| 1207 | - | ||
| 1208 | - #[test] | ||
| 1209 | - fn never_exercised_10bit_matches_the_gate_recipes() { | ||
| 1210 | - check_depth(true, NEVER_EXERCISED_10BIT); | ||
| 1211 | - } | ||
| 1212 | - | ||
| 1213 | - /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both | ||
| 1214 | - /// lists, so the per-depth holes can be read without opening this file. | ||
| 1215 | - #[test] | ||
| 1216 | - fn print_never_exercised_per_bit_depth() { | ||
| 1217 | - let ten: Vec<&str> = gate_bodies() | ||
| 1218 | - .into_iter() | ||
| 1219 | - .filter(|b| is_ten_bit(b)) | ||
| 1220 | - .collect(); | ||
| 1221 | - let total = gate_bodies().len(); | ||
| 1222 | - println!( | ||
| 1223 | - "gate_coverage: {} real-aomenc gates, {} of them 10-bit", | ||
| 1224 | - total, | ||
| 1225 | - ten.len() | ||
| 1226 | - ); | ||
| 1227 | - for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] { | ||
| 1228 | - let holes = never_exercised_at(ten_bit); | ||
| 1229 | - println!( | ||
| 1230 | - "NEVER_EXERCISED_{label} ({} of {}):", | ||
| 1231 | - holes.len(), | ||
| 1232 | - TOOL_UNIVERSE.len() | ||
| 1233 | - ); | ||
| 1234 | - for flag in &holes { | ||
| 1235 | - println!(" --{flag}"); | ||
| 1236 | - } | ||
| 1237 | - } | ||
| 1238 | - } | ||
| 1239 | - | ||
| 1240 | - /// [`DEFAULT_ON_TOOLS`] per depth: `tool -> (off in N gates, on in N, defaulted in N)`. | ||
| 1241 | - fn default_on_settings( | ||
| 1242 | - ten_bit: bool, | ||
| 1243 | - ) -> (usize, BTreeMap<&'static str, (usize, usize, usize)>) { | ||
| 1244 | - let gates: Vec<&str> = gate_bodies() | ||
| 1245 | - .into_iter() | ||
| 1246 | - .filter(|b| covers_depth(b, ten_bit)) | ||
| 1247 | - .collect(); | ||
| 1248 | - let mut per_tool = BTreeMap::new(); | ||
| 1249 | - for &(tool, spellings, _, on) in DEFAULT_ON_TOOLS { | ||
| 1250 | - // lane-av1txsearch: `resolved_on_state`, not `default_on_state` -- | ||
| 1251 | - // the literal-only reader filed every `format!`-built flag as | ||
| 1252 | - // "defaulted", which is unknown rather than measured. | ||
| 1253 | - let states: Vec<Option<bool>> = gates | ||
| 1254 | - .iter() | ||
| 1255 | - .map(|g| resolved_on_state(g, spellings, on)) | ||
| 1256 | - .collect(); | ||
| 1257 | - let turned_on = states.iter().filter(|s| **s == Some(true)).count(); | ||
| 1258 | - let turned_off = states.iter().filter(|s| **s == Some(false)).count(); | ||
| 1259 | - per_tool.insert( | ||
| 1260 | - tool, | ||
| 1261 | - (turned_off, turned_on, gates.len() - turned_off - turned_on), | ||
| 1262 | - ); | ||
| 1263 | - } | ||
| 1264 | - (gates.len(), per_tool) | ||
| 1265 | - } | ||
| 1266 | - | ||
| 1267 | - /// The [`DEFAULT_ON_TOOLS`] no gate of this depth positively enables. | ||
| 1268 | - fn never_on_at(ten_bit: bool) -> BTreeSet<&'static str> { | ||
| 1269 | - default_on_settings(ten_bit) | ||
| 1270 | - .1 | ||
| 1271 | - .into_iter() | ||
| 1272 | - .filter(|&(_, (_, on, _))| on == 0) | ||
| 1273 | - .map(|(tool, _)| tool) | ||
| 1274 | - .collect() | ||
| 1275 | - } | ||
| 1276 | - | ||
| 1277 | - fn check_default_on(ten_bit: bool, listed: &[(&str, &str)]) { | ||
| 1278 | - let derived = never_on_at(ten_bit); | ||
| 1279 | - let listed: BTreeSet<&str> = listed.iter().map(|&(tool, _)| tool).collect(); | ||
| 1280 | - let depth = if ten_bit { "10-bit" } else { "8-bit" }; | ||
| 1281 | - let unlisted: Vec<&&str> = derived.difference(&listed).collect(); | ||
| 1282 | - assert!( | ||
| 1283 | - unlisted.is_empty(), | ||
| 1284 | - "no {depth} gate spells an on-value for {unlisted:?}, so no real {depth} stream is \ | ||
| 1285 | - proven to carry them -- switch the tool on in a {depth} gate that asserts it fired, \ | ||
| 1286 | - or list it with a reason" | ||
| 1287 | - ); | ||
| 1288 | - let stale: Vec<&&str> = listed.difference(&derived).collect(); | ||
| 1289 | - assert!( | ||
| 1290 | - stale.is_empty(), | ||
| 1291 | - "the {depth} default-on list still names {stale:?}, but a {depth} gate now switches \ | ||
| 1292 | - them on -- delete those entries, the coverage hole is closed" | ||
| 1293 | - ); | ||
| 1294 | - } | ||
| 1295 | - | ||
| 1296 | - #[test] | ||
| 1297 | - fn never_on_8bit_matches_the_gate_recipes() { | ||
| 1298 | - check_default_on(false, NEVER_ON_8BIT); | ||
| 1299 | - } | ||
| 1300 | - | ||
| 1301 | - #[test] | ||
| 1302 | - fn never_on_10bit_matches_the_gate_recipes() { | ||
| 1303 | - check_default_on(true, NEVER_ON_10BIT); | ||
| 1304 | - } | ||
| 1305 | - | ||
| 1306 | - /// A tool must not be pinned twice: [`TOOL_UNIVERSE`] already derives the | ||
| 1307 | - /// `--enable-*` spellings under the `=1` rule. | ||
| 1308 | - #[test] | ||
| 1309 | - fn default_on_tools_do_not_duplicate_the_universe() { | ||
| 1310 | - for &(tool, spellings, _, _) in DEFAULT_ON_TOOLS { | ||
| 1311 | - assert!( | ||
| 1312 | - !TOOL_UNIVERSE.contains(&tool), | ||
| 1313 | - "{tool} is already covered by TOOL_UNIVERSE" | ||
| 1314 | - ); | ||
| 1315 | - assert!(!spellings.is_empty(), "{tool} has no aomenc spelling"); | ||
| 1316 | - } | ||
| 1317 | - for (alias, tool) in ALIASES { | ||
| 1318 | - assert!( | ||
| 1319 | - TOOL_UNIVERSE.contains(tool), | ||
| 1320 | - "alias --{alias} names {tool}, which is not a TOOL_UNIVERSE tool" | ||
| 1321 | - ); | ||
| 1322 | - } | ||
| 1323 | - } | ||
| 1324 | - | ||
| 1325 | - /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints the | ||
| 1326 | - /// default-on holes with their off/defaulted split. | ||
| 1327 | - #[test] | ||
| 1328 | - fn print_never_on_per_bit_depth() { | ||
| 1329 | - for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] { | ||
| 1330 | - let (gate_count, per_tool) = default_on_settings(ten_bit); | ||
| 1331 | - let holes = never_on_at(ten_bit); | ||
| 1332 | - println!( | ||
| 1333 | - "NEVER_ON_{label} ({} of {}, over {gate_count} {label} gates):", | ||
| 1334 | - holes.len(), | ||
| 1335 | - DEFAULT_ON_TOOLS.len() | ||
| 1336 | - ); | ||
| 1337 | - for tool in &holes { | ||
| 1338 | - let (off, _, defaulted) = per_tool[tool]; | ||
| 1339 | - let spellings = DEFAULT_ON_TOOLS | ||
| 1340 | - .iter() | ||
| 1341 | - .find(|e| e.0 == *tool) | ||
| 1342 | - .map(|e| e.1.join(",")) | ||
| 1343 | - .unwrap_or_default(); | ||
| 1344 | - println!( | ||
| 1345 | - " {tool} (--{spellings}): off in {off}, defaulted in {defaulted}, on in 0" | ||
| 1346 | - ); | ||
| 1347 | - } | ||
| 1348 | - } | ||
| 1349 | - } | ||
| 1350 | - | ||
| 1351 | - /// lane-av1txsearch: the `enable-tx-size-search` census, MEASURED rather | ||
| 1352 | - /// than floored. Prints, per gate body, the values the resolver reads for | ||
| 1353 | - /// the flag -- literal spellings and `format!` templates alike -- and the | ||
| 1354 | - /// three-way split at the end. Re-run it after any gate recipe change: | ||
| 1355 | - /// | ||
| 1356 | - /// `cargo test -p ec-av1 --lib gate_coverage::tests::print_tx_size_search_census -- --nocapture` | ||
| 1357 | - #[test] | ||
| 1358 | - fn print_tx_size_search_census() { | ||
| 1359 | - const TOOL: &str = "enable-tx-size-search"; | ||
| 1360 | - let (zero, one, both, unresolvable, unnamed) = { | ||
| 1361 | - let (mut zero, mut one, mut both, mut unresolvable, mut unnamed) = | ||
| 1362 | - (0usize, 0usize, 0usize, 0usize, 0usize); | ||
| 1363 | - for gate in gate_bodies() { | ||
| 1364 | - let values = spelling_values(gate, TOOL); | ||
| 1365 | - let name = gate | ||
| 1366 | - .split("fn ") | ||
| 1367 | - .nth(1) | ||
| 1368 | - .and_then(|s| s.split('(').next()) | ||
| 1369 | - .unwrap_or("<segment>") | ||
| 1370 | - .to_owned(); | ||
| 1371 | - let state = match (values.contains(&'0'), values.contains(&'1')) { | ||
| 1372 | - (false, false) => { | ||
| 1373 | - unnamed += 1; | ||
| 1374 | - "not named (defaulted)" | ||
| 1375 | - } | ||
| 1376 | - (true, false) => { | ||
| 1377 | - zero += 1; | ||
| 1378 | - "=0" | ||
| 1379 | - } | ||
| 1380 | - (false, true) => { | ||
| 1381 | - one += 1; | ||
| 1382 | - "=1" | ||
| 1383 | - } | ||
| 1384 | - (true, true) => { | ||
| 1385 | - both += 1; | ||
| 1386 | - "=0 and =1 (one arm each)" | ||
| 1387 | - } | ||
| 1388 | - }; | ||
| 1389 | - let via = if gate.contains(&format!("format!(\"--{TOOL}=")) { | ||
| 1390 | - " [format! template resolved]" | ||
| 1391 | - } else { | ||
| 1392 | - "" | ||
| 1393 | - }; | ||
| 1394 | - // A segment that does not open at a `#[test]` is glued non-test helper | ||
| 1395 | - // text from a split module (the support helpers have no attribute between | ||
| 1396 | - // them), so its `format!` parameter is not a gate's own value. | ||
| 1397 | - let helper = if gate.starts_with("test]") | ||
| 1398 | - && gate.contains(&format!("format!(\"--{TOOL}=")) | ||
| 1399 | - && values.is_empty() | ||
| 1400 | - { | ||
| 1401 | - " [UNRESOLVED: variable is a shared helper's parameter]" | ||
| 1402 | - } else { | ||
| 1403 | - "" | ||
| 1404 | - }; | ||
| 1405 | - if !helper.is_empty() { | ||
| 1406 | - unresolvable += 1; | ||
| 1407 | - unnamed -= 1; | ||
| 1408 | - } | ||
| 1409 | - println!("{name}: {state}{via}{helper}"); | ||
| 1410 | - } | ||
| 1411 | - (zero, one, both, unresolvable, unnamed) | ||
| 1412 | - }; | ||
| 1413 | - let total = gate_bodies().len(); | ||
| 1414 | - println!( | ||
| 1415 | - "enable-tx-size-search over {total} census-selected gate bodies: \ | ||
| 1416 | - =0 only {zero}, =1 only {one}, both {both}, unresolvable {unresolvable}, \ | ||
| 1417 | - not named {unnamed}" | ||
| 1418 | - ); | ||
| 1419 | - assert_eq!( | ||
| 1420 | - unresolvable, 0, | ||
| 1421 | - "{unresolvable} gate bodies build --{TOOL} into a variable this census cannot bind -- \ | ||
| 1422 | - the count is a floor again, and an unknown direction is the failure mode this file \ | ||
| 1423 | - exists to prevent" | ||
| 1424 | - ); | ||
| 1425 | - } | ||
| 1426 | - | ||
| 1427 | - /// lane-av1txsearch: the RED-BEFORE proof for the template resolver, in | ||
| 1428 | - /// both directions, on the gate bodies that actually exist. | ||
| 1429 | - /// | ||
| 1430 | - /// Direction 1 -- a `format!`-built value MOVES the classification. Each | ||
| 1431 | - /// case below takes a real gate body, mutates only the bound value, and | ||
| 1432 | - /// asserts the resolved state changed. A resolver that found nothing | ||
| 1433 | - /// would read every one of these as "not named" and fail all four. | ||
| 1434 | - /// | ||
| 1435 | - /// Direction 2 -- a spelling the LITERAL reader already saw still | ||
| 1436 | - /// classifies. Without this half, a resolver that overwrote the literal | ||
| 1437 | - /// path would pass direction 1 while losing the 15 `=1` gates the census | ||
| 1438 | - /// already counted. | ||
| 1439 | - #[test] | ||
| 1440 | - fn the_resolver_binds_a_format_built_flag_in_both_directions() { | ||
| 1441 | - let gates = gate_bodies(); | ||
| 1442 | - let find = |needle: &str| -> &'static str { | ||
| 1443 | - gates | ||
| 1444 | - .iter() | ||
| 1445 | - .copied() | ||
| 1446 | - .find(|b| b.contains(needle)) | ||
| 1447 | - .unwrap_or_else(|| panic!("no gate body contains {needle:?}")) | ||
| 1448 | - }; | ||
| 1449 | - // Direction 1, one per template shape. | ||
| 1450 | - let cases = [ | ||
| 1451 | - ( | ||
| 1452 | - "format!(\"--enable-tx-size-search={txs}\")", | ||
| 1453 | - "for txs in [0usize, 1]", | ||
| 1454 | - "for txs in [0usize, 0]", | ||
| 1455 | - "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact", | ||
| 1456 | - ), | ||
| 1457 | - ( | ||
| 1458 | - "format!(\"--enable-tx-size-search={tx_search}\")", | ||
| 1459 | - "if attempt % 2 == 0 { \"0\" } else { \"1\" }", | ||
| 1460 | - "if attempt % 2 == 0 { \"0\" } else { \"0\" }", | ||
| 1461 | - "a_real_aomenc_inter_sequence_with_a_coded_rectangular_residual_decodes_pixel_exact", | ||
| 1462 | - ), | ||
| 1463 | - ( | ||
| 1464 | - "format!(\"--enable-tx-size-search={tx_search}\")", | ||
| 1465 | - "for (tx_search, bit_depth) in [(\"1\", 8u8), (\"0\", 8u8), (\"1\", 10u8)]", | ||
| 1466 | - "for (tx_search, bit_depth) in [(\"0\", 8u8), (\"0\", 8u8), (\"0\", 10u8)]", | ||
| 1467 | - "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact", | ||
| 1468 | - ), | ||
| 1469 | - // The arm table hoisted OUT of the `for` line into a named | ||
| 1470 | - // `let` -- the shape lane-av1lossy128x96 writes, and the one | ||
| 1471 | - // that reads as UNRESOLVED unless the `for` line's collection | ||
| 1472 | - // name is followed back to its binding. Without this case a | ||
| 1473 | - // resolver that only understood inline arrays passes the | ||
| 1474 | - // three above and still cannot bind this gate. | ||
| 1475 | - ( | ||
| 1476 | - "format!(\"--enable-tx-size-search={search}\")", | ||
| 1477 | - "\"tx size search on\",\n \"1\",", | ||
| 1478 | - "\"tx size search on\",\n \"0\",", | ||
| 1479 | - "a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96", | ||
| 1480 | - ), | ||
| 1481 | - ]; | ||
| 1482 | - for (template, from, to, name) in cases { | ||
| 1483 | - let body = find(name); | ||
| 1484 | - assert!( | ||
| 1485 | - body.contains(template), | ||
| 1486 | - "{name} does not spell {template}, so this case proves nothing" | ||
| 1487 | - ); | ||
| 1488 | - assert!( | ||
| 1489 | - body.contains(from), | ||
| 1490 | - "{name} does not contain the source binding {from:?}" | ||
| 1491 | - ); | ||
| 1492 | - let before = spelling_values(body, "enable-tx-size-search"); | ||
| 1493 | - let mutated = body.replace(from, to); | ||
| 1494 | - assert_ne!( | ||
| 1495 | - mutated, body, | ||
| 1496 | - "the mutation {from:?} -> {to:?} changed nothing" | ||
| 1497 | - ); | ||
| 1498 | - let after = spelling_values(&mutated, "enable-tx-size-search"); | ||
| 1499 | - assert_eq!( | ||
| 1500 | - before, | ||
| 1501 | - BTreeSet::from(['0', '1']), | ||
| 1502 | - "{name}: the unmutated body should resolve to both values, got {before:?}" | ||
| 1503 | - ); | ||
| 1504 | - assert_eq!( | ||
| 1505 | - after, | ||
| 1506 | - BTreeSet::from(['0']), | ||
| 1507 | - "{name}: mutating the bound value {from:?} -> {to:?} did not move the \ | ||
| 1508 | - classification (still {after:?}) -- the resolver is not reading the binding" | ||
| 1509 | - ); | ||
| 1510 | - } | ||
| 1511 | - // Direction 2: every gate the LITERAL reader already classified as | ||
| 1512 | - // `=1` still is. Asserted as CONTAINMENT, not equality: a segment may | ||
| 1513 | - // spell the flag twice (`=0` in the base recipe, `=1` as the per-arm | ||
| 1514 | - // override), and the old reader took the last one while the resolver | ||
| 1515 | - // takes the set. The claim being pinned is "still on", which is the | ||
| 1516 | - // direction a regression would lose. | ||
| 1517 | - let mut pinned = 0usize; | ||
| 1518 | - for gate in &gates { | ||
| 1519 | - if !gate.contains("\"--enable-tx-size-search=1\"") { | ||
| 1520 | - continue; | ||
| 1521 | - } | ||
| 1522 | - pinned += 1; | ||
| 1523 | - assert!( | ||
| 1524 | - spelling_values(gate, "enable-tx-size-search").contains(&'1'), | ||
| 1525 | - "a gate that literally spells --enable-tx-size-search=1 is no longer \ | ||
| 1526 | - classified on: {:?}", | ||
| 1527 | - &gate[..gate.len().min(80)] | ||
| 1528 | - ); | ||
| 1529 | - } | ||
| 1530 | - assert!( | ||
| 1531 | - pinned >= 10, | ||
| 1532 | - "expected the literal `=1` gates to still be there, found {pinned}" | ||
| 1533 | - ); | ||
| 1534 | - } | ||
| 1535 | - | ||
| 1536 | - /// lane-av1oracleskip: the ORACLE-PRESENCE SCAN — the mechanical | ||
| 1537 | - /// anti-regression for the skip class this lane closed. | ||
| 1538 | - /// | ||
| 1539 | - /// Why a scan and not a review rule: the r2 sweep found FIVE gates that | ||
| 1540 | - /// had been added with the bare `if aomdec_path().is_file() { …compare… }` | ||
| 1541 | - /// shape AFTER the first fix had already routed thirteen sites — every one | ||
| 1542 | - /// of them compiled, passed review and reported green with the oracle | ||
| 1543 | - /// compare silently skipped, under `EC_AV1_REQUIRE_AOMENC=1`. A guard | ||
| 1544 | - /// written the old way re-opens the class the moment it merges, so the | ||
| 1545 | - /// only thing that holds is a check that reads the source itself. | ||
| 1546 | - /// | ||
| 1547 | - /// The rule: a TOOL PRESENCE CHECK (`aomenc_path().is_file()`, | ||
| 1548 | - /// `aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or | ||
| 1549 | - /// `!…` inverted) may appear ONLY | ||
| 1550 | - /// 1. inside the body of the probe that owns that path | ||
| 1551 | - /// (`have_aomenc`, `aomdec_available`, `have_affine_aomenc`) — that | ||
| 1552 | - /// is where the assert-last and the env escape live, and | ||
| 1553 | - /// 2. inside an `assert!` (the deliberate hard-failure form), or | ||
| 1554 | - /// 3. in a comment, which cannot execute. | ||
| 1555 | - /// Anything else is a skip with no env escape, and the test fails naming | ||
| 1556 | - /// the exact `file:line`. | ||
| 1557 | - /// | ||
| 1558 | - /// THE FLOOR. A source scan that matches nothing is the false-pass shape | ||
| 1559 | - /// this crate has been bitten by twice (a `format!` brace escape, and | ||
| 1560 | - /// `args.find(')')` stopping at the wrong paren), so the scan refuses to | ||
| 1561 | - /// pass unless it actually inspected a plausible number of sites: the | ||
| 1562 | - /// count is printed and asserted against `MIN_SITES`. A probe that moved | ||
| 1563 | - /// out of the scan's reach, or a matcher broken by a rename, reds here | ||
| 1564 | - /// instead of reporting a clean bill of health. | ||
| 1565 | - #[test] | ||
| 1566 | - fn no_tool_presence_check_outside_its_probe() { | ||
| 1567 | - /// Below this, the scan is not looking at the tree it thinks it is. | ||
| 1568 | - /// Five is the STRUCTURAL floor: three probes (whose existence the span | ||
| 1569 | - /// assert below already pins) plus the two hard `assert!` sites. Doc | ||
| 1570 | - /// comments mentioning the old shape come and go with the prose, so | ||
| 1571 | - /// they are counted but never load-bearing here. | ||
| 1572 | - const MIN_SITES: usize = 5; | ||
| 1573 | - /// (file, the line that opens the probe owning that path) | ||
| 1574 | - const PROBES: &[(&str, &str)] = &[ | ||
| 1575 | - ("stream.rs", "fn have_aomenc()"), | ||
| 1576 | - ("stream.rs", "fn aomdec_available("), | ||
| 1577 | - ("stream.rs", "fn have_affine_aomenc()"), | ||
| 1578 | - ]; | ||
| 1579 | - const PATHS: &[&str] = &[ | ||
| 1580 | - "aomenc_path().is_file()", | ||
| 1581 | - "aomdec_path().is_file()", | ||
| 1582 | - "affine_aomenc_path().is_file()", | ||
| 1583 | - ]; | ||
| 1584 | - let files: [(&str, &str); 3] = [ | ||
| 1585 | - ("stream.rs", crate::test_source::module_source("stream")), | ||
| 1586 | - ("decode.rs", crate::test_source::module_source("decode")), | ||
| 1587 | - ("encode.rs", crate::test_source::module_source("encode")), | ||
| 1588 | - ]; | ||
| 1589 | - | ||
| 1590 | - // The line range each probe body owns: from its opener to the first | ||
| 1591 | - // following line that closes it at column 0. | ||
| 1592 | - let mut probe_spans: Vec<(usize, usize)> = Vec::new(); | ||
| 1593 | - for (name, src) in files { | ||
| 1594 | - let lines: Vec<&str> = src.lines().collect(); | ||
| 1595 | - for (probe_file, opener) in PROBES { | ||
| 1596 | - if *probe_file != name { | ||
| 1597 | - continue; | ||
| 1598 | - } | ||
| 1599 | - let Some(start) = lines.iter().position(|l| l.contains(opener)).map(|i| i + 1) | ||
| 1600 | - else { | ||
| 1601 | - continue; | ||
| 1602 | - }; | ||
| 1603 | - let end = lines | ||
| 1604 | - .iter() | ||
| 1605 | - .skip(start) | ||
| 1606 | - .position(|l| l.trim_end() == "}") | ||
| 1607 | - .map(|off| start + off) | ||
| 1608 | - .unwrap_or(lines.len()); | ||
| 1609 | - probe_spans.push((start, end)); | ||
| 1610 | - } | ||
| 1611 | - } | ||
| 1612 | - assert!( | ||
| 1613 | - probe_spans.len() == PROBES.len(), | ||
| 1614 | - "the oracle-presence scan recognised {} of the {} probe bodies it is meant to \ | ||
| 1615 | - exempt ({probe_spans:?}); a renamed or moved probe would silently exempt every \ | ||
| 1616 | - site in the crate, so it reds here", | ||
| 1617 | - probe_spans.len(), | ||
| 1618 | - PROBES.len() | ||
| 1619 | - ); | ||
| 1620 | - | ||
| 1621 | - let mut sites = 0usize; | ||
| 1622 | - let mut allowed = 0usize; | ||
| 1623 | - let mut per_pattern: BTreeMap<&str, usize> = PATHS.iter().map(|p| (*p, 0)).collect(); | ||
| 1624 | - let mut offenders: Vec<String> = Vec::new(); | ||
| 1625 | - for (name, src) in files { | ||
| 1626 | - for (i, line) in src.lines().enumerate() { | ||
| 1627 | - // LONGEST match wins: `affine_aomenc_path().is_file()` CONTAINS | ||
| 1628 | - // `aomenc_path().is_file()`, so a first-match scan credits the | ||
| 1629 | - // affine probe's line to the aomenc pattern and the per-pattern | ||
| 1630 | - // floor below reds on a pattern that is very much present. (It | ||
| 1631 | - // did, on the first run of this test — which is the floor | ||
| 1632 | - // earning its place.) | ||
| 1633 | - let Some(path) = PATHS | ||
| 1634 | - .iter() | ||
| 1635 | - .filter(|p| line.contains(**p)) | ||
| 1636 | - .max_by_key(|p| p.len()) | ||
| 1637 | - else { | ||
| 1638 | - continue; | ||
| 1639 | - }; | ||
| 1640 | - sites += 1; | ||
| 1641 | - *per_pattern.get_mut(path).expect("pattern came from PATHS") += 1; | ||
| 1642 | - let lineno = i + 1; | ||
| 1643 | - let trimmed = line.trim_start(); | ||
| 1644 | - let in_probe = probe_spans | ||
| 1645 | - .iter() | ||
| 1646 | - .any(|(start, end)| lineno >= *start && lineno <= *end); | ||
| 1647 | - let in_assert = trimmed.starts_with("assert!") | ||
| 1648 | - || trimmed.starts_with("aomdec_path().is_file(),") | ||
| 1649 | - || trimmed.starts_with("aomenc_path().is_file(),") | ||
| 1650 | - || trimmed.starts_with("affine_aomenc_path().is_file(),"); | ||
| 1651 | - let in_comment = trimmed.starts_with("//"); | ||
| 1652 | - if in_probe || in_assert || in_comment { | ||
| 1653 | - allowed += 1; | ||
| 1654 | - } else { | ||
| 1655 | - offenders.push(format!( | ||
| 1656 | - "{name}:{lineno}: {}\n a tool presence check outside its probe — \ | ||
| 1657 | - route it through the probe that owns this path (`have_aomenc`, \ | ||
| 1658 | - `aomdec_available`, `have_affine_aomenc`): a bare `{path}` skips the \ | ||
| 1659 | - gate with NO env escape, so under EC_AV1_REQUIRE_AOMENC=1 the gate still \ | ||
| 1660 | - reports green with the oracle compare never run.", | ||
| 1661 | - line.trim() | ||
| 1662 | - )); | ||
| 1663 | - } | ||
| 1664 | - } | ||
| 1665 | - } | ||
| 1666 | - println!( | ||
| 1667 | - "oracle-presence scan: {sites} site(s) inspected, {allowed} in a probe / assert / \ | ||
| 1668 | - comment, {} offender(s); per pattern {per_pattern:?}", | ||
| 1669 | - offenders.len() | ||
| 1670 | - ); | ||
| 1671 | - // PER-PATTERN floor: a total count can hide one broken matcher (mutate | ||
| 1672 | - // ONE pattern and the other two still add up), so each of the three | ||
| 1673 | - // path patterns must be found at least once -- which the probe bodies | ||
| 1674 | - // guarantee, since each probe contains its own path's presence check. | ||
| 1675 | - let never_matched: Vec<&str> = per_pattern | ||
| 1676 | - .iter() | ||
| 1677 | - .filter(|(_, n)| **n == 0) | ||
| 1678 | - .map(|(p, _)| *p) | ||
| 1679 | - .collect(); | ||
| 1680 | - assert!( | ||
| 1681 | - never_matched.is_empty(), | ||
| 1682 | - "the oracle-presence scan matched NOTHING for {never_matched:?}: that pattern is \ | ||
| 1683 | - stale (renamed helper, `exists()` instead of `is_file()`, a `format!` escape) and \ | ||
| 1684 | - the gates it was meant to police would pass unreviewed. Matched per pattern: \ | ||
| 1685 | - {per_pattern:?}" | ||
| 1686 | - ); | ||
| 1687 | - assert!( | ||
| 1688 | - sites >= MIN_SITES, | ||
| 1689 | - "the oracle-presence scan inspected only {sites} site(s), below its floor of \ | ||
| 1690 | - {MIN_SITES}: the matcher has stopped matching this tree (renamed path helper, a \ | ||
| 1691 | - `format!` escape, a moved probe), and with no floor this would pass while scanning \ | ||
| 1692 | - nothing — the false-pass shape this crate has been bitten by twice" | ||
| 1693 | - ); | ||
| 1694 | - assert!( | ||
| 1695 | - offenders.is_empty(), | ||
| 1696 | - "{} bare tool presence check(s) outside a probe — each one is a gate that can report \ | ||
| 1697 | - green without running the oracle compare:\n {}", | ||
| 1698 | - offenders.len(), | ||
| 1699 | - offenders.join("\n ") | ||
| 1700 | - ); | ||
| 1701 | - } | ||
| 1702 | -} | ||
| 1703 | - | ||
| 1704 | -/// lane-av1pins5 r5: the PIN INVENTORY. | ||
| 1705 | -/// | ||
| 1706 | -/// The r3 inventory this replaces matched only two call shapes -- | ||
| 1707 | -/// `crate_pin("X")` and `pin_dir().join("X")` -- both SINGLE-NAME. A gate that | ||
| 1708 | -/// reads a whole DIRECTORY of pins through a `concat!` literal and then formats | ||
| 1709 | -/// a name at runtime (`format!("{fixtures}/{n}.obu")`) matched neither, so | ||
| 1710 | -/// `pinned_warp_stream_decodes_pixel_exact` and its 14 uncommitted pins were | ||
| 1711 | -/// invisible to it, and r3 reported "the machine-local-pin population is zero". | ||
| 1712 | -/// It was not. This enumerator resolves all four shapes. | ||
| 1713 | -/// | ||
| 1714 | -/// Ownership, stated because two lanes touch this: THIS scanner owns the | ||
| 1715 | -/// ENUMERATION (which gates read which pins, from source). The fixture-preflight | ||
| 1716 | -/// lane owns the FILE INVENTORY on a runner (does each referenced path exist on | ||
| 1717 | -/// the box). Different questions; both must agree, and this one is the stricter of | ||
| 1718 | -/// the two because it fails on an uncommitted pin whether or not some runner | ||
| 1719 | -/// happens to have a copy. | ||
| 1720 | -#[cfg(test)] | ||
| 1721 | -mod pin_inventory { | ||
| 1722 | - /// One pin a gate reads, and where it came from. | ||
| 1723 | - pub struct PinRead { | ||
| 1724 | - pub gate: String, | ||
| 1725 | - pub file: String, | ||
| 1726 | - pub shape: &'static str, | ||
| 1727 | - } | ||
| 1728 | - | ||
| 1729 | - /// Split `src` into `(fn_name, body)` for every `fn name(` at the gate indent. | ||
| 1730 | - fn gate_bodies(src: &str) -> Vec<(String, &'static str)> { | ||
| 1731 | - let mut out = Vec::new(); | ||
| 1732 | - let mut cur: Option<(String, usize)> = None; | ||
| 1733 | - for (i, line) in src.lines().enumerate() { | ||
| 1734 | - let t = line.trim_start(); | ||
| 1735 | - if let Some(rest) = t.strip_prefix("fn ") | ||
| 1736 | - && let Some(name) = rest.split('(').next() | ||
| 1737 | - && !name.contains(' ') { | ||
| 1738 | - cur = Some((name.to_string(), i)); | ||
| 1739 | - } | ||
| 1740 | - // A `#[test]`/`#[ignore]` line is never a closing brace, so the fn | ||
| 1741 | - // ends at the first line that is exactly four-space `}`. | ||
| 1742 | - if let Some((name, start)) = &cur | ||
| 1743 | - && i > *start && line == " }" { | ||
| 1744 | - let body = src | ||
| 1745 | - .lines() | ||
| 1746 | - .skip(*start) | ||
| 1747 | - .take(i - *start + 1) | ||
| 1748 | - .collect::<Vec<_>>() | ||
| 1749 | - .join("\n"); | ||
| 1750 | - out.push((name.clone(), &*Box::leak(body.into_boxed_str()))); | ||
| 1751 | - cur = None; | ||
| 1752 | - } | ||
| 1753 | - } | ||
| 1754 | - out | ||
| 1755 | - } | ||
| 1756 | - | ||
| 1757 | - /// Every pin every gate reads, across all four shapes. | ||
| 1758 | - pub fn pins_read(src: &str) -> Vec<PinRead> { | ||
| 1759 | - let mut out = Vec::new(); | ||
| 1760 | - for (gate, body) in gate_bodies(src) { | ||
| 1761 | - // (a) crate_pin("X") and (b) pin_dir().join("X") -- single name. | ||
| 1762 | - for m in body.match_indices("crate_pin(\"") { | ||
| 1763 | - let rest = &body[m.0 + 11..]; | ||
| 1764 | - if let Some(e) = rest.find('"') { | ||
| 1765 | - out.push(PinRead { | ||
| 1766 | - gate: gate.clone(), | ||
| 1767 | - file: rest[..e].to_string(), | ||
| 1768 | - shape: "crate_pin", | ||
| 1769 | - }); | ||
| 1770 | - } | ||
| 1771 | - } | ||
| 1772 | - for m in body.match_indices("pin_dir().join(\"") { | ||
| 1773 | - let rest = &body[m.0 + 16..]; | ||
| 1774 | - if let Some(e) = rest.find('"') { | ||
| 1775 | - out.push(PinRead { | ||
| 1776 | - gate: gate.clone(), | ||
| 1777 | - file: rest[..e].to_string(), | ||
| 1778 | - shape: "pin_dir_machine_local", | ||
| 1779 | - }); | ||
| 1780 | - } | ||
| 1781 | - } | ||
| 1782 | - // (c) a whole-file concat! literal to a named pin: | ||
| 1783 | - // concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/X.obu") | ||
| 1784 | - for m in body.match_indices("/../../fixtures/") { | ||
| 1785 | - let rest = &body[m.0 + 16..]; | ||
| 1786 | - if let Some(e) = rest.find('"') { | ||
| 1787 | - out.push(PinRead { | ||
| 1788 | - gate: gate.clone(), | ||
| 1789 | - file: rest[..e].to_string(), | ||
| 1790 | - shape: "concat_literal_machine_local", | ||
| 1791 | - }); | ||
| 1792 | - } | ||
| 1793 | - } | ||
| 1794 | - // (d) the shape that hid 14 pins: a DIRECTORY literal bound to a | ||
| 1795 | - // local, plus a runtime `format!("{var}/{n}.ext")` over a | ||
| 1796 | - // literal name array. Resolve the array's names. | ||
| 1797 | - for (vi, line) in body.lines().enumerate() { | ||
| 1798 | - let tl = line.trim(); | ||
| 1799 | - // `let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures");` | ||
| 1800 | - // -> the bound name is whatever sits between `let ` and the `=`. | ||
| 1801 | - let var = match ( | ||
| 1802 | - tl.find("concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/../../fixtures\")"), | ||
| 1803 | - tl.find('='), | ||
| 1804 | - ) { | ||
| 1805 | - (Some(a), Some(eq)) if eq < a => tl[4..eq].trim().to_string(), | ||
| 1806 | - _ => continue, | ||
| 1807 | - }; | ||
| 1808 | - if var.is_empty() { | ||
| 1809 | - continue; | ||
| 1810 | - } | ||
| 1811 | - // `format!("{fixtures}/{n}.obu")` -- built by concatenation, not | ||
| 1812 | - // by `format!`: escaping `{{`/`}}` to emit literal braces here is | ||
| 1813 | - // exactly the bug that made this shape resolve to 0 pins on the | ||
| 1814 | - // first run of the scanner. | ||
| 1815 | - let marker = ["format!(\"", "{", &var, "}/{n}"].concat(); | ||
| 1816 | - let Some(pos) = body.find(&marker) else { | ||
| 1817 | - continue; | ||
| 1818 | - }; | ||
| 1819 | - // Walk back from the format! to the `[ ... ].iter()` array and | ||
| 1820 | - // take every quoted name in it. | ||
| 1821 | - let head = &body[..pos]; | ||
| 1822 | - let Some(bracket) = head.rfind('[') else { | ||
| 1823 | - continue; | ||
| 1824 | - }; | ||
| 1825 | - let names: Vec<String> = head[bracket..] | ||
| 1826 | - .split('"') | ||
| 1827 | - .skip(1) | ||
| 1828 | - .step_by(2) | ||
| 1829 | - .filter(|s| !s.is_empty() && !s.contains(' ') && *s != "]") | ||
| 1830 | - .map(|s| s.to_string()) | ||
| 1831 | - .collect(); | ||
| 1832 | - // `.obu` -- SLICE up to the closing quote. (Stringifying the | ||
| 1833 | - // `find` index instead produced names like `warp-mismatch4`.) | ||
| 1834 | - let tail = &body[pos + marker.len()..]; | ||
| 1835 | - let ext = tail | ||
| 1836 | - .find('"') | ||
| 1837 | - .map(|e| tail[..e].to_string()) | ||
| 1838 | - .unwrap_or_default(); | ||
| 1839 | - for n in names { | ||
| 1840 | - out.push(PinRead { | ||
| 1841 | - gate: gate.clone(), | ||
| 1842 | - file: format!("{n}{ext}"), | ||
| 1843 | - shape: "concat_dir_runtime_name", | ||
| 1844 | - }); | ||
| 1845 | - } | ||
| 1846 | - let _ = vi; | ||
| 1847 | - } | ||
| 1848 | - // (e) the shape this very fix INTRODUCED: | ||
| 1849 | - // `.map(|n| crate_pin(&format!("{n}.obu")))`. Rewriting the | ||
| 1850 | - // directory literal as a committed-path lookup made the gate | ||
| 1851 | - // correct and simultaneously invisible -- `crate_pin("` no | ||
| 1852 | - // longer appears, so shape (a) found nothing and the | ||
| 1853 | - // enumerator reported a CLEAN tree while 14 pins were read. A | ||
| 1854 | - // false pass is worse than the original gap: the original at | ||
| 1855 | - // least showed up in a filesystem audit. Caught here by the | ||
| 1856 | - // `reads.len()` floor in the invariant test. | ||
| 1857 | - for m in body.match_indices("crate_pin(&format!(") { | ||
| 1858 | - let rest = &body[m.0 + 19..]; | ||
| 1859 | - let Some(close) = rest.find(')') else { | ||
| 1860 | - continue; | ||
| 1861 | - }; | ||
| 1862 | - let call = &rest[..close]; | ||
| 1863 | - if !call.contains('"') { | ||
| 1864 | - continue; | ||
| 1865 | - } | ||
| 1866 | - let head = &body[..m.0]; | ||
| 1867 | - let Some(bracket) = head.rfind('[') else { | ||
| 1868 | - continue; | ||
| 1869 | - }; | ||
| 1870 | - let names: Vec<String> = head[bracket..] | ||
| 1871 | - .split('"') | ||
| 1872 | - .skip(1) | ||
| 1873 | - .step_by(2) | ||
| 1874 | - .filter(|x| !x.is_empty() && !x.contains(' ') && *x != "]") | ||
| 1875 | - .map(|x| x.to_string()) | ||
| 1876 | - .collect(); | ||
| 1877 | - // the literal inside the format!, e.g. `{n}.obu` | ||
| 1878 | - let lit = call.split('"').nth(1).unwrap_or(""); | ||
| 1879 | - let ext = lit | ||
| 1880 | - .split_once("}") | ||
| 1881 | - .map(|(_, e)| e.to_string()) | ||
| 1882 | - .unwrap_or_default(); | ||
| 1883 | - for n in names { | ||
| 1884 | - out.push(PinRead { | ||
| 1885 | - gate: gate.clone(), | ||
| 1886 | - file: format!("{n}{ext}"), | ||
| 1887 | - shape: "crate_pin_runtime_name", | ||
| 1888 | - }); | ||
| 1889 | - } | ||
| 1890 | - } | ||
| 1891 | - } | ||
| 1892 | - out | ||
| 1893 | - } | ||
| 1894 | - | ||
| 1895 | - /// Does this shape resolve through `crate_pin`, i.e. the COMMITTED | ||
| 1896 | - /// crate-local copy? Both the literal form and the runtime-name form do -- | ||
| 1897 | - /// only the two `pin_dir`/root-`concat!` forms are machine-local. | ||
| 1898 | - pub fn resolves_committed(shape: &str) -> bool { | ||
| 1899 | - matches!(shape, "crate_pin" | "crate_pin_runtime_name") | ||
| 1900 | - } | ||
| 1901 | - | ||
| 1902 | - /// Is `file` present as a committed crate-local fixture? | ||
| 1903 | - pub fn is_committed(file: &str) -> bool { | ||
| 1904 | - std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1905 | - .join("fixtures") | ||
| 1906 | - .join(file) | ||
| 1907 | - .is_file() | ||
| 1908 | - } | ||
| 1909 | -} | ||
| 1910 | - | ||
| 1911 | -#[cfg(test)] | ||
| 1912 | -mod pin_inventory_tests { | ||
| 1913 | - use super::pin_inventory::{is_committed, pins_read}; | ||
| 1914 | - | ||
| 1915 | - /// The scanner must be able to SEE the directory-literal shape. Run over a | ||
| 1916 | - /// SYNTHETIC source, not the live tree: r5 removed that shape from | ||
| 1917 | - /// `pinned_warp_stream_decodes_pixel_exact`, so a test that asserted it | ||
| 1918 | - /// against the live file would rot the moment the fix landed -- which is | ||
| 1919 | - /// precisely how a scanner loses its edge and reports a clean tree again. | ||
| 1920 | - /// A capability test must have its own input. | ||
| 1921 | - #[test] | ||
| 1922 | - fn the_pin_scanner_sees_the_directory_literal_shape() { | ||
| 1923 | - let synthetic = r#" | ||
| 1924 | - #[test] | ||
| 1925 | - fn a_gate_using_the_old_shape() { | ||
| 1926 | - let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures"); | ||
| 1927 | - let paths: Vec<String> = match std::env::var("EC_AV1_GATE_DUMP_PIN") { | ||
| 1928 | - Ok(p) => vec![p], | ||
| 1929 | - Err(_) => [ | ||
| 1930 | - "warp-mismatch", | ||
| 1931 | - "ii-flake-1", | ||
| 1932 | - "rect-flake-3", | ||
| 1933 | - ] | ||
| 1934 | - .iter() | ||
| 1935 | - .map(|n| format!("{fixtures}/{n}.obu")) | ||
| 1936 | - .collect(), | ||
| 1937 | - }; | ||
| 1938 | - for path in paths { | ||
| 1939 | - check(&path); | ||
| 1940 | - } | ||
| 1941 | - } | ||
| 1942 | -"#; | ||
| 1943 | - let reads = pins_read(synthetic); | ||
| 1944 | - let names: Vec<&str> = reads.iter().map(|r| r.file.as_str()).collect(); | ||
| 1945 | - assert_eq!( | ||
| 1946 | - names, | ||
| 1947 | - vec!["warp-mismatch.obu", "ii-flake-1.obu", "rect-flake-3.obu"], | ||
| 1948 | - "the directory-literal + runtime-name shape resolved to {names:?} -- a scanner \ | ||
| 1949 | - that cannot see this shape is how 14 uncommitted pins survived three rounds" | ||
| 1950 | - ); | ||
| 1951 | - assert!( | ||
| 1952 | - reads.iter().all(|r| r.shape == "concat_dir_runtime_name"), | ||
| 1953 | - "the synthetic pins were attributed to the wrong shape: {:?}", | ||
| 1954 | - reads.iter().map(|r| r.shape).collect::<Vec<_>>() | ||
| 1955 | - ); | ||
| 1956 | - } | ||
| 1957 | - | ||
| 1958 | - /// The other three shapes resolve too -- same reasoning, same synthetic input, | ||
| 1959 | - /// so the capability survives the tree being fixed. | ||
| 1960 | - #[test] | ||
| 1961 | - fn the_pin_scanner_sees_every_shape() { | ||
| 1962 | - let synthetic = r#" | ||
| 1963 | - #[test] | ||
| 1964 | - fn shapes() { | ||
| 1965 | - let a = crate_pin("golden3-pin.obu"); | ||
| 1966 | - let b = pin_dir().join("sbpart-pin.obu"); | ||
| 1967 | - let c = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/x.obu")); | ||
| 1968 | - } | ||
| 1969 | -"#; | ||
| 1970 | - let mut names: Vec<String> = pins_read(synthetic) | ||
| 1971 | - .iter() | ||
| 1972 | - .map(|r| format!("{}|{}", r.file, r.shape)) | ||
| 1973 | - .collect(); | ||
| 1974 | - names.sort(); | ||
| 1975 | - assert_eq!( | ||
| 1976 | - names, | ||
| 1977 | - vec![ | ||
| 1978 | - "golden3-pin.obu|crate_pin", | ||
| 1979 | - "sbpart-pin.obu|pin_dir_machine_local", | ||
| 1980 | - "x.obu|concat_literal_machine_local", | ||
| 1981 | - ], | ||
| 1982 | - "shape coverage changed: {names:?}" | ||
| 1983 | - ); | ||
| 1984 | - } | ||
| 1985 | - | ||
| 1986 | - /// THE INVARIANT, on the live tree: every pin a gate reads is a COMMITTED | ||
| 1987 | - /// crate-local copy, and NO gate reads through a machine-local shape. This is | ||
| 1988 | - /// the check the r3 manifest could not express. | ||
| 1989 | - #[test] | ||
| 1990 | - fn every_pin_a_gate_reads_is_committed_under_the_crate() { | ||
| 1991 | - let src = crate::test_source::module_source("stream"); | ||
| 1992 | - let reads = pins_read(src); | ||
| 1993 | - assert!( | ||
| 1994 | - reads.len() >= 20, | ||
| 1995 | - "the enumerator found only {} pin reads in stream.rs -- it has lost a shape, \ | ||
| 1996 | - which is the failure mode that let 14 pins go unseen", | ||
| 1997 | - reads.len() | ||
| 1998 | - ); | ||
| 1999 | - let uncommitted: Vec<String> = reads | ||
| 2000 | - .iter() | ||
crates/ec-av1/src/lib.rsmodified+0 -8
| @@ -37,13 +37,8 @@ mod film_grain; | |||
| 37 | pub use film_grain::apply_film_grain; | 37 | pub use film_grain::apply_film_grain; |
| 38 | mod filter_search; | 38 | mod filter_search; |
| 39 | pub mod frame; | 39 | pub mod frame; |
| 40 | -// Test-only: the real-library fixture root and the one presence probe every | ||
| 41 | -// gate that needs a clip routes through. | ||
| 42 | -mod gate_coverage; | ||
| 43 | mod hits; | 40 | mod hits; |
| 44 | pub mod intra; | 41 | pub mod intra; |
| 45 | -#[cfg(test)] | ||
| 46 | -mod library_fixture; | ||
| 47 | pub mod mc; | 42 | pub mod mc; |
| 48 | pub mod motion; | 43 | pub mod motion; |
| 49 | mod motion_field; | 44 | mod motion_field; |
| @@ -54,7 +49,6 @@ mod par; | |||
| 54 | pub mod probe; | 49 | pub mod probe; |
| 55 | pub mod qm; | 50 | pub mod qm; |
| 56 | pub mod quant; | 51 | pub mod quant; |
| 57 | -mod refusal_inventory; | ||
| 58 | mod restoration; | 52 | mod restoration; |
| 59 | pub mod sequence; | 53 | pub mod sequence; |
| 60 | pub mod speed; | 54 | pub mod speed; |
| @@ -63,8 +57,6 @@ pub mod stream; | |||
| 63 | mod superres; | 57 | mod superres; |
| 64 | #[cfg(test)] | 58 | #[cfg(test)] |
| 65 | mod test_source; | 59 | mod test_source; |
| 66 | -#[cfg(test)] | ||
| 67 | -pub(crate) mod tool_cache; | ||
| 68 | pub mod tile; | 60 | pub mod tile; |
| 69 | mod timeline; | 61 | mod timeline; |
| 70 | pub mod transform; | 62 | pub mod transform; |
crates/ec-av1/src/library_fixture.rsdeleted+0 -161
| @@ -1,161 +0,0 @@ | |||
| 1 | -//! Where a REAL-LIBRARY fixture is read from, and the one presence probe every | ||
| 2 | -//! gate that needs one routes through. | ||
| 3 | -//! | ||
| 4 | -//! The clips these gates read (`h264-1080p-23.976-8bit.mp4`, | ||
| 5 | -//! `h264-2160p-23.976-8bit.mp4`, `real-library-manifest.tsv`) are | ||
| 6 | -//! multi-megabyte encodes of a shared library, not pins: they cannot be | ||
| 7 | -//! committed under `crates/<crate>/fixtures/` the way the `.obu` pins are | ||
| 8 | -//! ([`crate_pin`](crate::stream)), so they live in the gitignored ROOT | ||
| 9 | -//! `fixtures/` — `.gitignore:2`. A linked worktree therefore never has that | ||
| 10 | -//! directory, and a gate that skips on its absence reports GREEN having | ||
| 11 | -//! asserted nothing: the class `lane-av1skipfix` closed for the pins, still open | ||
| 12 | -//! for the clips. | ||
| 13 | -//! | ||
| 14 | -//! TWO defects met here, both of which this module closes: | ||
| 15 | -//! | ||
| 16 | -//! 1. **Silent skip.** `h264_clip_frames` and each gate's own | ||
| 17 | -//! `if !clip.exists() { eprintln!("SKIP …"); return; }` skipped with no env | ||
| 18 | -//! escape, so `EC_AV1_REQUIRE_FFMPEG=1` — a batch run's way of saying "this | ||
| 19 | -//! gate must actually run" — did not make the ABSENT CLIP a failure. The | ||
| 20 | -//! `a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders` | ||
| 21 | -//! gate printed `SKIP the 1080p tile round trip: no fixture` and libtest | ||
| 22 | -//! reported `ok` on a tree with no root `fixtures/` at all. | ||
| 23 | -//! | ||
| 24 | -//! 2. **Two roots.** `scripts/verify-fixture-library.sh` validates | ||
| 25 | -//! `$EC_FIXTURES` (defaulting to `$ROOT/fixtures`) while these gates read | ||
| 26 | -//! `$ROOT/fixtures` unconditionally. Pointing the preflight at a library | ||
| 27 | -//! elsewhere reported `resolve 0 missing` and `GREEN` while the clip gates' | ||
| 28 | -//! root was absent — GREEN with an absent root, the exact false green this | ||
| 29 | -//! module exists to kill. So [`root`] honours `EC_FIXTURES` FIRST: the | ||
| 30 | -//! preflight and the gates now resolve the same tree, and when it is unset | ||
| 31 | -//! the preflight's default IS the gates' root, so its mode-(i) finding fires | ||
| 32 | -//! exactly when the clip gates will skip. | ||
| 33 | -//! | ||
| 34 | -//! The shape is the crate's existing convention, not a new one: the | ||
| 35 | -//! assert-under-require / print-one-line-otherwise probe is the same one | ||
| 36 | -//! `crates/ec-h264/tests/conformance.rs::require_fixtures` and the per-crate | ||
| 37 | -//! `require_fixture` helpers use, and the file's own presence check lives HERE, | ||
| 38 | -//! inside the probe that owns it — a bare `clip.exists()` at a call site is | ||
| 39 | -//! precisely what the anti-regression scan for the sibling (tool) class | ||
| 40 | -//! rejects. | ||
| 41 | - | ||
| 42 | -use std::path::{Path, PathBuf}; | ||
| 43 | - | ||
| 44 | -/// The envs that turn an absent library clip into a hard failure. | ||
| 45 | -/// | ||
| 46 | -/// * `EC_REQUIRE_FIXTURES` — the fleet-wide convention, the same one | ||
| 47 | -/// `scripts/verify-fixture-library.sh` and every per-crate `require_fixture` | ||
| 48 | -/// honour, and the one `EC_REQUIRE_FIXTURES=1` in the preflight's docs names. | ||
| 49 | -/// * `EC_AV1_REQUIRE_FFMPEG` / `EC_AV1_REQUIRE_AOMENC` — this crate's own | ||
| 50 | -/// requirement flags ([`have_ffmpeg`](crate::encode::tests::have_ffmpeg)). | ||
| 51 | -/// Every gate reachable through [`require`] also decodes its result through | ||
| 52 | -/// ffmpeg, so a batch that sets them has already said the gate must run; a | ||
| 53 | -/// missing clip must not be the softer failure. | ||
| 54 | -/// | ||
| 55 | -/// All three are checked, not just one: a run that sets only the preflight's | ||
| 56 | -/// env, and a run that sets only this crate's, both get the failure. | ||
| 57 | -fn required() -> bool { | ||
| 58 | - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() | ||
| 59 | - || std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_some() | ||
| 60 | - || std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_some() | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -/// The fixture root the tests read, in precedence order: | ||
| 64 | -/// | ||
| 65 | -/// 1. `EC_FIXTURES` — the same variable `scripts/verify-fixture-library.sh` | ||
| 66 | -/// resolves, so its verdict and these gates' bytes are the same tree. This | ||
| 67 | -/// is the half of the two-roots mismatch that the preflight cannot fix from | ||
| 68 | -/// its side. | ||
| 69 | -/// 2. `<crate>/../../fixtures` — the gitignored root `fixtures/`, the default | ||
| 70 | -/// the preflight uses when `EC_FIXTURES` is unset. | ||
| 71 | -pub fn root() -> PathBuf { | ||
| 72 | - match std::env::var_os("EC_FIXTURES") { | ||
| 73 | - Some(p) if !p.is_empty() => PathBuf::from(p), | ||
| 74 | - _ => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures"), | ||
| 75 | - } | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -/// `require` on a path relative to [`root`]: | ||
| 79 | -/// `require("video/h264-1080p-23.976-8bit.mp4", …)`. The literal is | ||
| 80 | -/// LIBRARY-RELATIVE, which is the row shape `scripts/gen-fixture-library.sh` | ||
| 81 | -/// reads back out of this file, so the preflight keeps resolving these paths. | ||
| 82 | -pub fn path(rel: &str) -> PathBuf { | ||
| 83 | - root().join(rel) | ||
| 84 | -} | ||
| 85 | - | ||
| 86 | -/// The one presence probe for a library fixture. Returns the path when the file | ||
| 87 | -/// is there. When it is not: | ||
| 88 | -/// | ||
| 89 | -/// * under [`required()`] — PANIC, naming the resolved path, so the gate is RED | ||
| 90 | -/// instead of green-with-nothing-checked; | ||
| 91 | -/// * otherwise — prints exactly ONE `SKIP` line naming the resolved path and the | ||
| 92 | -/// three ways out (link the library, point `EC_FIXTURES` at it, or set a | ||
| 93 | -/// require env), and returns `None`. | ||
| 94 | -/// | ||
| 95 | -/// A caller that gets `None` must `return` WITHOUT printing a second line: the | ||
| 96 | -/// path and the escape hatch are already on the one line above, and a second | ||
| 97 | -/// "no fixture" line is the noise that hid this defect from a reading of the | ||
| 98 | -/// output. | ||
| 99 | -pub fn require(rel: &str, what: &str) -> Option<PathBuf> { | ||
| 100 | - require_at(path(rel), what) | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -/// [`require`] for a path the caller resolved itself — an `EC_AV1_WALL_CLIP` | ||
| 104 | -/// override, which names a clip OUTSIDE any library root, so it must not be | ||
| 105 | -/// joined onto one. | ||
| 106 | -pub fn require_at(clip: PathBuf, what: &str) -> Option<PathBuf> { | ||
| 107 | - if clip.is_file() { | ||
| 108 | - return Some(clip); | ||
| 109 | - } | ||
| 110 | - assert!( | ||
| 111 | - !required(), | ||
| 112 | - "{what}: the library clip is absent at {} -- this gate would prove nothing. A linked \ | ||
| 113 | - worktree has no gitignored root `fixtures/`: run scripts/link-fixtures.sh, or point \ | ||
| 114 | - EC_FIXTURES at a library root, or set EC_REQUIRE_FIXTURES=1 / EC_AV1_REQUIRE_FFMPEG=1 \ | ||
| 115 | - only on a tree that really has the library.", | ||
| 116 | - clip.display() | ||
| 117 | - ); | ||
| 118 | - eprintln!( | ||
| 119 | - "SKIP {what}: {} absent at {} -- this gate proved nothing; run \ | ||
| 120 | - scripts/link-fixtures.sh, point EC_FIXTURES at a library root, or set \ | ||
| 121 | - EC_REQUIRE_FIXTURES=1 / EC_AV1_REQUIRE_FFMPEG=1 to make this a failure.", | ||
| 122 | - clip.file_name().unwrap_or_default().to_string_lossy(), | ||
| 123 | - clip.display() | ||
| 124 | - ); | ||
| 125 | - None | ||
| 126 | -} | ||
| 127 | - | ||
| 128 | -#[cfg(test)] | ||
| 129 | -mod tests { | ||
| 130 | - use super::*; | ||
| 131 | - | ||
| 132 | - /// The two-roots reconciliation, asserted on the RESOLVER rather than | ||
| 133 | - /// described in prose: with `EC_FIXTURES` set, [`root`] is that directory and | ||
| 134 | - /// NOT `<crate>/../../fixtures`. (The variable is process-constant in this | ||
| 135 | - /// crate — nothing calls `set_var` — so the assertion holds for whatever the | ||
| 136 | - /// batch exported; it is the precedence, not a particular value, that is | ||
| 137 | - /// under test.) | ||
| 138 | - #[test] | ||
| 139 | - fn the_resolver_follows_ec_fixtures_over_the_gitignored_root() { | ||
| 140 | - let root = super::root(); | ||
| 141 | - if let Some(p) = std::env::var_os("EC_FIXTURES") | ||
| 142 | - && !p.is_empty() | ||
| 143 | - { | ||
| 144 | - assert_eq!( | ||
| 145 | - root, | ||
| 146 | - PathBuf::from(p), | ||
| 147 | - "EC_FIXTURES must win over the default root" | ||
| 148 | - ); | ||
| 149 | - } else { | ||
| 150 | - assert!( | ||
| 151 | - root.ends_with("../../fixtures"), | ||
| 152 | - "the default root is the gitignored <crate>/../../fixtures, got {}", | ||
| 153 | - root.display() | ||
| 154 | - ); | ||
| 155 | - } | ||
| 156 | - assert_eq!( | ||
| 157 | - super::path("video/h264-1080p-23.976-8bit.mp4"), | ||
| 158 | - root.join("video/h264-1080p-23.976-8bit.mp4") | ||
| 159 | - ); | ||
| 160 | - } | ||
| 161 | -} | ||
crates/ec-av1/src/probe.rsmodified+3 -7
| @@ -9,12 +9,13 @@ | |||
| 9 | //! `encode::tests::the_probe_arms_the_gates_source` pins. | 9 | //! `encode::tests::the_probe_arms_the_gates_source` pins. |
| 10 | 10 | ||
| 11 | use crate::encode::Picture; | 11 | use crate::encode::Picture; |
| 12 | +#[cfg(test)] | ||
| 12 | use std::process::Command; | 13 | use std::process::Command; |
| 13 | 14 | ||
| 14 | /// The video stream's coded size, from ffprobe. | 15 | /// The video stream's coded size, from ffprobe. |
| 15 | #[must_use] | 16 | #[must_use] |
| 16 | pub fn dims(clip: &str) -> Option<(usize, usize)> { | 17 | pub fn dims(clip: &str) -> Option<(usize, usize)> { |
| 17 | - let out = Command::new("ffprobe") | 18 | + let out = ec_testkit::ffprobe() |
| 18 | .args(["-v", "error", "-select_streams", "v:0"]) | 19 | .args(["-v", "error", "-select_streams", "v:0"]) |
| 19 | .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"]) | 20 | .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"]) |
| 20 | .arg(clip) | 21 | .arg(clip) |
| @@ -66,7 +67,7 @@ pub fn source( | |||
| 66 | height: usize, | 67 | height: usize, |
| 67 | frames: usize, | 68 | frames: usize, |
| 68 | ) -> Vec<Picture> { | 69 | ) -> Vec<Picture> { |
| 69 | - let out = Command::new("ffmpeg") | 70 | + let out = ec_testkit::ffmpeg() |
| 70 | .args(["-v", "error", "-ss", skip, "-i", clip]) | 71 | .args(["-v", "error", "-ss", skip, "-i", clip]) |
| 71 | .args(["-frames:v", &frames.to_string()]) | 72 | .args(["-frames:v", &frames.to_string()]) |
| 72 | .args(["-vf", vf]) | 73 | .args(["-vf", vf]) |
| @@ -135,11 +136,6 @@ pub fn source( | |||
| 135 | /// aomenc/ffmpeg over an at-most-a-few-MB fixture: seconds, not minutes. | 136 | /// aomenc/ffmpeg over an at-most-a-few-MB fixture: seconds, not minutes. |
| 136 | #[cfg(test)] | 137 | #[cfg(test)] |
| 137 | pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output { | 138 | pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output { |
| 138 | - crate::tool_cache::cached_output(cmd, Some(input), |c| run_child_with_stdin(c, input)) | ||
| 139 | -} | ||
| 140 | - | ||
| 141 | -#[cfg(test)] | ||
| 142 | -fn run_child_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output { | ||
| 143 | use std::io::{Read, Write}; | 139 | use std::io::{Read, Write}; |
| 144 | use std::process::Stdio; | 140 | use std::process::Stdio; |
| 145 | use std::time::{Duration, Instant}; | 141 | use std::time::{Duration, Instant}; |
crates/ec-av1/src/refusal_inventory.rsdeleted+0 -2957
Diff too large; view file
| @@ -1,2957 +0,0 @@ | |||
| 1 | -//! An inventory of what this decoder refuses, and a check on the claims those | ||
| 2 | -//! refusals make. | ||
| 3 | -//! | ||
| 4 | -//! Two rules this repository keeps learning the hard way: | ||
| 5 | -//! | ||
| 6 | -//! 1. A refusal string is a **claim**. "This encoder never writes one" asserts | ||
| 7 | -//! that a real encoder cannot emit the case -- and one such string was | ||
| 8 | -//! disproved by the very gate that carried it (the wedge-interintra hang, | ||
| 9 | -//! 2026-08-30): the refusal was written from a mismatching frame's header | ||
| 10 | -//! state, so it named a correlate rather than the defect. Any refusal | ||
| 11 | -//! phrased as a capability claim about the ENCODER, rather than about this | ||
| 12 | -//! decoder, needs evidence, and this module makes the set of such strings | ||
| 13 | -//! explicit instead of letting it grow quietly. | ||
| 14 | -//! 2. Refusals accumulate silently. A lane that adds one to unblock itself is | ||
| 15 | -//! doing the right thing (refuse by name rather than desync), but the total | ||
| 16 | -//! is the distance to a decoder that handles a default-settings stream, and | ||
| 17 | -//! nobody sees a total that nothing prints. | ||
| 18 | -//! | ||
| 19 | -//! So the test below re-derives every `unsupported(...)` reason reachable on | ||
| 20 | -//! the decode path -- `decode.rs` and `stream.rs` -- and pins it. Adding or | ||
| 21 | -//! removing a refusal fails until the list is updated, which is the point: the | ||
| 22 | -//! diff of this file is the decoder's capability delta, in one place, in | ||
| 23 | -//! English. | ||
| 24 | - | ||
| 25 | -#[cfg(test)] | ||
| 26 | -const CAPABILITY_CLAIMS: &[&str] = &[ | ||
| 27 | - // lane-hdrlossless ENUMERATION: this guard is a claim about THIS | ||
| 28 | - // decoder's gate, not about the encoder -- `filter_intra_size_class_rect` | ||
| 29 | - // admits no arm with a 64 axis (libaom `av1_filter_intra_allowed_bsize` | ||
| 30 | - // is "both sides <= 32"), and the strips it protects are exactly | ||
| 31 | - // `(64, 32)`/`(32, 64)`, which fall to its `_ => None` arm. So the | ||
| 32 | - // `filter_intra.is_some()` guard in `decode_block_rect` is unreachable; | ||
| 33 | - // the proof is `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol`, | ||
| 34 | - // which enumerates every arm of the table. Kept as a named pin (not | ||
| 35 | - // deleted) per the repo convention for proven-unreachable guards. | ||
| 36 | - "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", | ||
| 37 | -]; | ||
| 38 | - | ||
| 39 | -#[cfg(test)] | ||
| 40 | -const REFUSALS: &[&str] = &[ | ||
| 41 | - // lane-av1-444 c4's rect/1:4 chroma port added two shape guards whose | ||
| 42 | - // strings never landed here (continuation 8's suite run caught the | ||
| 43 | - // drift); both are decoder-side "no table for that shape yet" guards on | ||
| 44 | - // 4:4:4 rect strips, same family as the rect luma/chroma entries below. | ||
| 45 | - // lane-av1-refusalaudit: the 64-axis one is PROVEN unreachable -- its | ||
| 46 | - // chroma-unit table covers every conformant strip unit in both supported | ||
| 47 | - // chroma formats (enumeration in PROVEN; the witness2 hunt reached | ||
| 48 | - // nothing). The chroma-size one below is still live. | ||
| 49 | - "a 64-axis strip whose chroma unit has no coefficient table", | ||
| 50 | - "a rectangular chroma transform whose size has no coefficient table", | ||
| 51 | - "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | ||
| 52 | - "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | ||
| 53 | - "an OBMC neighbour whose switchable interp filter was never recorded", | ||
| 54 | - "a rectangular inter luma transform unit whose shape has no coefficient table set here", | ||
| 55 | - "a rectangular inter chroma transform unit whose shape has no coefficient table set here", | ||
| 56 | - "a rectangular transform unit whose shape has no coefficient scan table here", | ||
| 57 | - "a 32x32 partition type this decoder does not code (value={part32})", | ||
| 58 | - "a Golomb tail longer than this decoder reads", | ||
| 59 | - "a tx_type symbol outside its CDF's own set: {t}", | ||
| 60 | - "an INTER 32x32 partition type this decoder does not code (value={part32})", | ||
| 61 | - "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | ||
| 62 | - "a 128x128 superblock partition value outside the 8-symbol alphabet", | ||
| 63 | - "an inter var-tx tree with a leaf transform larger than 64x64", | ||
| 64 | - "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", | ||
| 65 | - // lane-av1unwritten + lane-av1subsizesweep: the BLOCK_INVALID subsize | ||
| 66 | - // refusal that mirrors libaom's own (decodeframe.c:1456). The source | ||
| 67 | - // string carries escaped quotes around the libaom citation and this | ||
| 68 | - // table is matched against the scanner's collected form, so the quotes | ||
| 69 | - // stay escaped here the way the scanner keeps them. | ||
| 70 | - "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this frame's subsampling mode (libaom: \\\"Block size %dx%d invalid with this subsampling mode\\\", av1/decoder/decodeframe.c:1456, refusing by the same rule)", | ||
| 71 | - // lane-t900 r23: palette RECONSTRUCTION now covers the key-frame paths | ||
| 72 | - // (earlier lanes), the intra-in-inter square/rect paths (r22) and the | ||
| 73 | - // 8x8 LEAF inside an inter frame (this round, gate | ||
| 74 | - // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`), | ||
| 75 | - // which is why the (UV) string is gone from the decoder entirely -- the | ||
| 76 | - // leaf was its only site. The (Y) one survived as the defensive | ||
| 77 | - // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect` | ||
| 78 | - // until lane-t900 r33 DELETED both arms: all eight call sites hand the | ||
| 79 | - // reader a real ctx/cache pair, so no stream could reach either (audit | ||
| 80 | - // `every_read_intra_mode_call_site_hands_the_reader_a_palette_cache`, | ||
| 81 | - // which keeps that invariant now the refusal is gone). | ||
| 82 | - // lane-av1-ibcrect: `intra block copy on a HORZ/VERT/1:4 rect intra strip | ||
| 83 | - // (reconstruction is not ported at this shape)` is GONE -- lane-av1-intrabc | ||
| 84 | - // and lane-av1-rect14 reconstructed the 16x16/32x32-level strips, and this | ||
| 85 | - // lane ported the last site, `decode_block_128rect`'s 128-root HORZ/VERT | ||
| 86 | - // strip (`decode_intrabc_128rect`; a 128 root has no 1:4 arm at all). | ||
| 87 | - // Witness: | ||
| 88 | - // `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact` (real aomenc | ||
| 89 | - // sb128 screen streams coding `use_intrabc` on BLOCK_128X64 strips, | ||
| 90 | - // pixel-exact vs ffmpeg). | ||
| 91 | - // lane-av1txr: `a sub-8x8 leaf that uses intrabc (…)` is GONE -- the | ||
| 92 | - // capability landed in this lane (4x4 / 4x8 / 8x4 intrabc leaves read the | ||
| 93 | - // DV and reconstruct a frame copy + the INTER residual; the sub-8x8 | ||
| 94 | - // intrabc leaf witnesses in `stream.rs` and the `warped.obu` / | ||
| 95 | - // `allintra.obu` traces). Its census gate | ||
| 96 | - // (`a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal`) | ||
| 97 | - // still runs: it now reports `reached = 0` with the same non-vacuous | ||
| 98 | - // premise (allow_intrabc frames + decoded sub-8 leaves). | ||
| 99 | - // lane-av112bit: the blanket 12-bit refusal is REPLACED by the named | ||
| 100 | - // refusals below -- the witnessed paths (intra stack, dequant/ | ||
| 101 | - // transforms at the 12-bit tables, deblock, CDEF, Wiener+SGR | ||
| 102 | - // restoration, translational subpel MC through the parameterised | ||
| 103 | - // round_0/round_1) are lifted by the lane's byte-exact ffmpeg gates. | ||
| 104 | - // lane-av112bitc: compound joined the witnessed set (six-frame 12-bit | ||
| 105 | - // compound stream byte-exact vs ffmpeg; the combines already absorbed | ||
| 106 | - // the CONV_BUF gain drop through `INTER_POST_ROUND - delta`). | ||
| 107 | - // lane-av112bitg: film grain joined the witnessed set (two-frame | ||
| 108 | - // `--film-grain-test=5` stream byte-exact vs ffmpeg; the gate that | ||
| 109 | - // replaced the refusal is | ||
| 110 | - // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 111 | - // lane-av112bitw: warp joined too -- the refusal left all three decision | ||
| 112 | - // sites (compound, 16x16+, 8x8 leaf): `warp::warp_round_0` implements | ||
| 113 | - // convolve.h's 12-bit `round_0` bump (3 -> 5), and both the single-ref | ||
| 114 | - // witness (`a_12bit_warped_motion_stream_decodes_pixel_exact`, the exact | ||
| 115 | - // recipe that refused pre-lift) and the rotating-mandelbrot | ||
| 116 | - // compound-warp witness | ||
| 117 | - // (`a_real_compound_global_warp_12bit_stream_decodes_pixel_exact`, 28 | ||
| 118 | - // compound warp blocks) are byte-exact vs ffmpeg. | ||
| 119 | - // lane-av1screen12: screen content tools LEFT the 12-bit refusal set. The | ||
| 120 | - // string was "a 12-bit frame with screen content tools | ||
| 121 | - // (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit | ||
| 122 | - // witness)" -- a guard BROADER than the gap it named, because | ||
| 123 | - // `allow_screen_content_tools` only opens the `palette_y_mode` / | ||
| 124 | - // `palette_uv_mode` symbols and the leaf `use_intrabc` symbol, and both | ||
| 125 | - // reconstructions are already depth-parameterised | ||
| 126 | - // (`read_palette_colors_y` / `_uv` read at `bit_depth(fctx)`, the | ||
| 127 | - // colour-index map writes u16 samples). Three 12-bit arms decode | ||
| 128 | - // BYTE-EXACT against the instrumented `aomdec --rawvideo` and against | ||
| 129 | - // ffmpeg, each with a +1 control on the oracle's own bytes: | ||
| 130 | - // `a_real_aomenc_12bit_screen_content_palette_stream_decodes_pixel_exact` | ||
| 131 | - // (pin `screen12_palette.obu`, 2 frames, 76 palette / 43 palette-UV), | ||
| 132 | - // `a_real_aomenc_12bit_intrabc_screen_stream_decodes_pixel_exact` (pin | ||
| 133 | - // `screen12_intrabc.obu`, 1 frame, `allow_intrabc = 1`, 36 palette / | ||
| 134 | - // 34 palette-UV / 11 intrabc blocks) and | ||
| 135 | - // `a_real_aomenc_12bit_lossless_screen_content_stream_decodes_pixel_exact` | ||
| 136 | - // (pin `screen12_lossless_palette.obu`, 2 frames, 80 palette / | ||
| 137 | - // 59 palette-UV, `CodedLossless` AND screen content in the same frame). | ||
| 138 | - // The companion "12-bit intrabc has no producer" note was a RECIPE | ||
| 139 | - // artefact: libaom sets that frame-header bit from its content detector | ||
| 140 | - // (`encoder.c:2404`), so an untiled `smptebars=size=128x96` source gives | ||
| 141 | - // `allow_intrabc = 0` with AND without `--tune-content=screen`, while the | ||
| 142 | - // 256x192 `-vf tile=2x2` source gives `= 1` at 8, 10 and 12 bits. | ||
| 143 | - // lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the | ||
| 144 | - // silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by | ||
| 145 | - // name at the frame header) now DEQUANTISES through libaom's | ||
| 146 | - // `iwt_matrix_ref`/`get_dqv` port (`crate::qm`): the parsed 4-bit levels | ||
| 147 | - // select per-plane matrices, 1D/identity transforms and lossless blocks | ||
| 148 | - // stay flat. Witness: | ||
| 149 | - // `a_real_aomenc_quantisation_matrix_stream_decodes_pixel_exact`. | ||
| 150 | - // lane-lossless/lane-lossless2: a lossless frame (base_q_idx 0) decodes | ||
| 151 | - // sample-exact, KEY and INTER -- TX_4X4 with the Walsh-Hadamard transform | ||
| 152 | - // on every plane, no `tx_type` symbol, `is_cfl_allowed` narrowed to a | ||
| 153 | - // BLOCK_4X4 chroma plane block, and the chroma plane walked as 4x4 units | ||
| 154 | - // plane-major inside each mu chunk (gates | ||
| 155 | - // `a_lossless_libaom_key_frame_decodes_sample_exact` / | ||
| 156 | - // `a_lossless_libaom_inter_frame_decodes_sample_exact`). The refusal | ||
| 157 | - // that stood here for a frame whose SEGMENTS disagree ("the TX_4X4/WHT | ||
| 158 | - // rules are per segment there") is LIFTED too: lane-av1mixloss ports the | ||
| 159 | - // per-segment table (libaom `decodeframe.c:5205`), and | ||
| 160 | - // `a_real_aomenc_mixed_lossless_segment_frame_decodes_sample_exact` | ||
| 161 | - // proves a real aq-mode stream sample-exact. | ||
| 162 | - "a frame OBU with no tile group", | ||
| 163 | - "a frame naming primary_ref_frame at a reference slot with no saved CDF state", | ||
| 164 | - "a frame with no mode-info grid", | ||
| 165 | - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV (this decoder reads segment_id but never lets a segment override a block's reference, skip or mode)", | ||
| 166 | - // Still live, but NARROWED: lane-rectres r1 added the 32x32-level 1:4 | ||
| 167 | - // strips (32x8 / 8x32) to `rect_inter_residual_supported` -- THE shape both | ||
| 168 | - // 10-bit 3840x1608 film cuts and every measured 1080p offset stopped on | ||
| 169 | - // (gate `a_real_aomenc_inter_sequence_with_32x32_level_1to4_strips_codes_\ | ||
| 170 | - // their_rect_residual`). The string stays because the shapes below 8x8 and | ||
| 171 | - // the AB-partition footprints still have no rectangular residual path. | ||
| 172 | - "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", | ||
| 173 | - "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", | ||
| 174 | - "a reference picture outside the 2x down / 16x up scaling limits", | ||
| 175 | - "a show_existing_frame header naming an empty reference slot", | ||
| 176 | - "an inter var-tx tree with a leaf transform larger than 32x32", | ||
| 177 | - // lane-intrainter r1 lifted the >=16x16 square case (per-TU intra | ||
| 178 | - // prediction + coefficients, gate | ||
| 179 | - // `a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact`); | ||
| 180 | - // lane-leaf8tx r4 lifted the 8x8 leaf's TX_4X4 2x2 grid (gate | ||
| 181 | - // `a_real_aomenc_inter_sequence_with_an_angle_delta_8x8_intra_leaf_decodes_pixel_exact`). | ||
| 182 | - "an inter frame with no key frame before it", | ||
| 183 | - // lane-inter16ab r1 lifted the AB half and r2 the 1:4 half (four 16x4 / | ||
| 184 | - // 4x16 inter strips, their 8x4/4x8 chroma pair built from BOTH strips' | ||
| 185 | - // motion vectors -- gate | ||
| 186 | - // `a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact`). | ||
| 187 | - // Two narrower refusals are what is left of that shape: | ||
| 188 | - "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", | ||
| 189 | - // r2 residue: `vartx_leaves` is a list of SQUARE units, and | ||
| 190 | - // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree | ||
| 191 | - // and its per-unit residual reader both need rect leaves. | ||
| 192 | - // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own | ||
| 193 | - // halved footprint, which for a 16x4 strip is an 8x2 transform libaom | ||
| 194 | - // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip). | ||
| 195 | - // lane-sub8x4 r3 narrowed this to "a strip with no chroma-pair record"; | ||
| 196 | - // lane-wit16x4 r1 put it back at FULL width (r3's witness counters were | ||
| 197 | - // phantoms of a desync, class `refusal-lifted-without-a-gate`) behind | ||
| 198 | - // an opt-in. lane-t900 r6 NARROWED it again -- the opt-in is | ||
| 199 | - // gone -- on a real 10-bit 1920x792 128-superblock film witness that | ||
| 200 | - // decodes 14/14 decode-order frames exact vs aomdec and 12/12 shown frames | ||
| 201 | - // exact vs ffmpeg while the arm fires 78 16x4 + 149 4x16 (108 chroma- | ||
| 202 | - // paired): gate | ||
| 203 | - // `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact`. | ||
| 204 | - // What still refuses is a 16x4/4x16 strip with NO chroma-pair record and | ||
| 205 | - // every other sub-8 shape. | ||
| 206 | - "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)", | ||
| 207 | - "an intra mode this decoder does not code (round 2)", | ||
| 208 | - // lane-intrarect r1 lifted the whole-shape refusal that stood here (the | ||
| 209 | - // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); | ||
| 210 | - // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the | ||
| 211 | - // size-group/category diagonal the 2:1 shapes share. | ||
| 212 | - "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)", | ||
| 213 | - // lane-t900 r21 NARROWED this: the string used to guard EVERY rect intra | ||
| 214 | - // strip of a screen-content inter frame, and a real | ||
| 215 | - // `--tune-content=screen` stream reached it on an 8x16 (8-bit) / 16x8 | ||
| 216 | - // (10-bit) strip. The 2:1 reader now codes the palette syntax itself and | ||
| 217 | - // the 1:4 arm goes through `read_intra_mode_rect`, which already did -- | ||
| 218 | - // both arms of gate | ||
| 219 | - // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips` | ||
| 220 | - // decode ten frames pixel-exact with the strips counted. What still | ||
| 221 | - // lane-t900 r22 NARROWED it again: the 16x4/4x16 arm is LIFTED (that arm | ||
| 222 | - // routes through `decode_rect4_16_strip`, which reads the palette syntax | ||
| 223 | - // itself -- the premise was stale), gated by | ||
| 224 | - // `a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact`. | ||
| 225 | - // What still refuses is the 128-root half of a screen-content frame, whose | ||
| 226 | - // body (`decode_block_128rect`) reads no palette syntax and for which no | ||
| 227 | - // `--sb-size=128` screen witness exists yet. | ||
| 228 | - // lane-t900 r32: the 128-root arm is LIFTED. r31's enumeration | ||
| 229 | - // (`no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax`) is | ||
| 230 | - // its proof -- `av1_allow_palette`'s `bw > 64 || bh > 64` bound means a | ||
| 231 | - // 128x64/64x128 half codes NO palette syntax at all, so a screen-content | ||
| 232 | - // frame's half is byte-identical in syntax to the non-screen twin gate | ||
| 233 | - // `an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact` | ||
| 234 | - // already decodes pixel-exact. Nothing of this string remains. | ||
| 235 | - // lane-t900 r32: the residue of the LIFTED "an intrabc block under | ||
| 236 | - // TxMode::Select". The inter var-tx tree is read in full, but the intra | ||
| 237 | - // luma reconstruct loop it feeds is a UNIFORM grid of one square | ||
| 238 | - // transform, so a tree resolving to mixed leaf sizes would be | ||
| 239 | - // reconstructed at the wrong stride. Neither arm of | ||
| 240 | - // `an_intrabc_block_under_tx_mode_select_decodes_pixel_exact` reaches it | ||
| 241 | - // (both resolve uniform), so it is unwitnessed and stays live. | ||
| 242 | - // lane-av1-ibcvtx: LIFTED. The t900 census's own maxp32 recipe class, | ||
| 243 | - // retargeted at testsrc2 content with `--max-partition-size=64`, reaches | ||
| 244 | - // mixed trees on the first encode (12-recipe hunt, 5/12 recipes hit). | ||
| 245 | - // The luma reconstruct now walks the tree's own leaf list per leaf, and | ||
| 246 | - // the block's chroma inherits the co-located luma unit's coded tx type | ||
| 247 | - // (`av1_get_tx_type`, blockd.h:1278 -- that inheritance was missing on | ||
| 248 | - // the uniform multi-TU intrabc path too). Gate: | ||
| 249 | - // `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal`. | ||
| 250 | - // Its census gate | ||
| 251 | - // (`an_intrabc_vartx_census_measures_the_mixed_leaf_refusal`) survives as | ||
| 252 | - // the witness that the premise is still exercised -- `reached` is 0 by | ||
| 253 | - // construction now. | ||
| 254 | - "a motion_mode symbol for a block shape with no CDF row here", | ||
| 255 | -]; | ||
| 256 | - | ||
| 257 | -/// The refusals that have a PROVING test, and its name. | ||
| 258 | -/// | ||
| 259 | -/// A refusal with no such test is an unmeasured claim: nothing in the suite | ||
| 260 | -/// distinguishes "this case never happens" from "no stream we decode has | ||
| 261 | -/// reached it yet". A proving test is one of two shapes: | ||
| 262 | -/// | ||
| 263 | -/// * a WITNESS gate -- a real stream reaches the shape, decodes exact, and the | ||
| 264 | -/// refusal is gone (the good case), or | ||
| 265 | -/// * a CENSUS gate -- N real streams decode with the refusal firing 0 times | ||
| 266 | -/// while the counters for the sibling shapes it names fire, so the claim is | ||
| 267 | -/// measured against the domain the decoder is actually handed. | ||
| 268 | -/// | ||
| 269 | -/// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`] | ||
| 270 | -/// is the honest numerator over the inventory below. | ||
| 271 | -/// | ||
| 272 | -/// # lane-av1-hdr: which pins are `spec-conformant` vs a real gap | ||
| 273 | -/// | ||
| 274 | -/// A negative gate proves our refusal FIRES by name on a hand-built stream; it | ||
| 275 | -/// does not prove libaom would reject the same stream. This lane read the | ||
| 276 | -/// libaom counterpart for the header/reference cluster and recorded the | ||
| 277 | -/// verdict (`lanes/av1hdr.report.md` §3). The spec-conformant pins (libaom | ||
| 278 | -/// errors identically) are, with their libaom site: | ||
| 279 | -/// | ||
| 280 | -/// * `primary_ref_frame` empty slot -- `decodeframe.c:5075` `AOM_CODEC_CORRUPT_FRAME`. | ||
| 281 | -/// * `show_existing_frame` empty slot -- `decodeframe.c:4651` `AOM_CODEC_UNSUP_BITSTREAM`. | ||
| 282 | -/// * reference selected with no picture -- `decodeframe.c:5027` `AOM_CODEC_CORRUPT_FRAME`. | ||
| 283 | -/// * inter frame with no key frame before -- same site (`decodeframe.c:5008`). | ||
| 284 | -/// * no mode-info grid -- no libaom error site; a 0-sized frame cannot be coded. | ||
| 285 | -/// | ||
| 286 | -/// The two that are NOT spec-conformant, and are kept as named capability gaps | ||
| 287 | -/// with an assessment (a real gap libaom accepts, no reachable witness here): | ||
| 288 | -/// a reference picture whose height differs (libaom SCALES, | ||
| 289 | -/// `decodeframe.c:5089`). A third one -- a frame mixing lossless and lossy | ||
| 290 | -/// segments (libaom decodes it per segment, `decodeframe.c:5205`) -- was the | ||
| 291 | -/// same kind of gap until lane-av1mixloss ported the per-segment table; its | ||
| 292 | -/// refusal is gone and | ||
| 293 | -/// `a_real_aomenc_mixed_lossless_segment_frame_decodes_sample_exact` is the | ||
| 294 | -/// witness. | ||
| 295 | -#[cfg(test)] | ||
| 296 | -/// Which KIND of proof each [`PROVEN`] row carries. | ||
| 297 | -/// | ||
| 298 | -/// A 2-tuple made every row look equally proven, which is the whole defect: | ||
| 299 | -/// a row whose gate drives a hand-built stream into the guard and a row | ||
| 300 | -/// whose gate sweeps an alphabet and shows nothing reaches it are held to | ||
| 301 | -/// the same standard and read the same way. `label()` is what the tests | ||
| 302 | -/// print, so the distinction is visible in the suite's own output. | ||
| 303 | -/// | ||
| 304 | -/// lane-av1refusalclaim r3 also proposed a third variant, `TablePin` | ||
| 305 | -/// ("the arms are pinned exactly but the domain the table is REACHED over | ||
| 306 | -/// is unestablished"). It is deliberately NOT carried: the one row it was | ||
| 307 | -/// minted for now has a gate that establishes the reach domain | ||
| 308 | -/// (`every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table` | ||
| 309 | -/// reads the eight `decode_block_rect` call sites' own literal `bw`/`bh`, | ||
| 310 | -/// pins the resulting chroma table exactly, and asserts the `(4,8)`/`(8,4)` | ||
| 311 | -/// residual is UNPRODUCIBLE), so `Enumeration` is the honest tag and a | ||
| 312 | -/// variant with no row would be dead weight. Re-add it the day a gate really | ||
| 313 | -/// pins a table without measuring its caller domain -- and give it a row. | ||
| 314 | -#[cfg(test)] | ||
| 315 | -enum Proof { | ||
| 316 | - /// A written stream REACHES the guard and is refused by this exact | ||
| 317 | - /// string: the gate goes RED if the guard is removed. | ||
| 318 | - NegativeGate, | ||
| 319 | - /// The gate enumerates every input the guard can be reached over and | ||
| 320 | - /// shows that none of them reaches it: it proves UNREACHABILITY, so it | ||
| 321 | - /// is GREEN if the guard is removed. | ||
| 322 | - Enumeration, | ||
| 323 | -} | ||
| 324 | - | ||
| 325 | -#[cfg(test)] | ||
| 326 | -impl Proof { | ||
| 327 | - fn label(&self) -> &'static str { | ||
| 328 | - match self { | ||
| 329 | - Proof::NegativeGate => "NEGATIVE (reaches the guard; red on removal)", | ||
| 330 | - Proof::Enumeration => "ENUMERATION (proves unreachability; green on removal)", | ||
| 331 | - } | ||
| 332 | - } | ||
| 333 | -} | ||
| 334 | - | ||
| 335 | -#[cfg(test)] | ||
| 336 | -const PROVEN: &[(&str, &str, Proof)] = &[ | ||
| 337 | - // lane-t900 r20, census: three real streams present exactly the 18 | ||
| 338 | - // `(side, write_w, write_h)` triples `INTER_BLOCK_SHAPES` lists, and | ||
| 339 | - // `rect_inter_residual_supported` covers every rectangular one -- the only | ||
| 340 | - // footprints `reject_residual` is set for. | ||
| 341 | - // lane-av1-witness2 (8 more inter encodes: banded and busy content, | ||
| 342 | - // --max-partition-size=32, a single-ref arm, cq 20..45, cpu-used 0..1): | ||
| 343 | - // no refusal -- every rect strip the encoder produced sat inside the | ||
| 344 | - // supported set. Static half, from the same hunt: the supported list plus | ||
| 345 | - // the partition walker's piece set (SB pieces 64x32/32x64/64x16/16x64, | ||
| 346 | - // the 32- and 16-level rect/1:4/AB twins, 128 halves tiled as two | ||
| 347 | - // TX_64X64) enumerate every rect footprint AV1 partitioning can present; | ||
| 348 | - // 1:4 stops at 64 because the 128 root has no 1:4 symbol. No conformant | ||
| 349 | - // stream can name an unsupported footprint. | ||
| 350 | - ( | ||
| 351 | - "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", | ||
| 352 | - "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable", | ||
| 353 | - Proof::Enumeration, | ||
| 354 | - ), | ||
| 355 | - // lane-t900 r20, census: the shapes that can reach `decode_intra_rect_in_inter`'s | ||
| 356 | - // size-group/tx-category lookup are the ten rectangular census shapes with | ||
| 357 | - // `8 <= min` and `max <= 64` (a sub-8 footprint and a 128-px one take | ||
| 358 | - // earlier branches), and every one of them has a row. | ||
| 359 | - ( | ||
| 360 | - "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)", | ||
| 361 | - "every_intra_in_inter_shape_the_census_lists_has_a_size_group_row", | ||
| 362 | - Proof::Enumeration, | ||
| 363 | - ), | ||
| 364 | - // lane-t900 r20, census: the only sub-8 footprints three real streams | ||
| 365 | - // present are the 16x4/4x16 strips of a 16x16-level 1:4 partition, whose | ||
| 366 | - // caller records the chroma pair for every strip, while the supported path | ||
| 367 | - // fires on both orientations inside streams that decode with no refusal. | ||
| 368 | - ( | ||
| 369 | - "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)", | ||
| 370 | - "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable", | ||
| 371 | - Proof::Enumeration, | ||
| 372 | - ), | ||
| 373 | - // lane-t900 r20, census: the rect transform tables and scans, enumerated | ||
| 374 | - // over the shapes the measured block-shape domain hands each helper (block | ||
| 375 | - // footprint, 4:2:0 chroma unit, rect var-tx leaf, clamped coded corner). | ||
| 376 | - // lane-av1-witness2 (8 inter encodes, --enable-tx-size-search=1, rect+1:4 | ||
| 377 | - // on, --min-partition-size=4, 4:2:0 and 4:4:4, sb 64/128, cq 10..45, | ||
| 378 | - // cpu-used 0..2): no refusal while the domain was genuinely exercised -- | ||
| 379 | - // whole-block 32x8 inter TUs and sub-8 rect pieces decoded. The fourteen | ||
| 380 | - // rect shapes the enumeration covers are the whole alphabet, so the `_` | ||
| 381 | - // arm has no conformant input. | ||
| 382 | - ( | ||
| 383 | - "a rectangular inter luma transform unit whose shape has no coefficient table set here", | ||
| 384 | - "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 385 | - Proof::Enumeration, | ||
| 386 | - ), | ||
| 387 | - ( | ||
| 388 | - "a rectangular inter chroma transform unit whose shape has no coefficient table set here", | ||
| 389 | - "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 390 | - Proof::Enumeration, | ||
| 391 | - ), | ||
| 392 | - ( | ||
| 393 | - "a rectangular transform unit whose shape has no coefficient scan table here", | ||
| 394 | - "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 395 | - Proof::Enumeration, | ||
| 396 | - ), | ||
| 397 | - // lane-t900 r21, enumeration: a var-tx leaf is never larger than the unit | ||
| 398 | - // the tree was entered with, and both callers enter at or below their own | ||
| 399 | - // ceiling (the one case that does not, a 64px block at TX_64X64, is the | ||
| 400 | - // `single` whole-block case the refusal is guarded by). | ||
| 401 | - ( | ||
| 402 | - "an inter var-tx tree with a leaf transform larger than 32x32", | ||
| 403 | - "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered", | ||
| 404 | - Proof::Enumeration, | ||
| 405 | - ), | ||
| 406 | - ( | ||
| 407 | - "an inter var-tx tree with a leaf transform larger than 64x64", | ||
| 408 | - "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered", | ||
| 409 | - Proof::Enumeration, | ||
| 410 | - ), | ||
| 411 | - // Pre-existing proofs, registered by lane-t900 r21: a negative gate (a | ||
| 412 | - // hand-built 12-bit sequence header is refused BY THIS EXACT STRING rather | ||
| 413 | - // than decoded wrong) and a witness gate (a real aomenc screen key frame | ||
| 414 | - // reaches intrabc on a rect strip, so the refusal names a shape a real | ||
| 415 | - // encoder does write). | ||
| 416 | - // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and | ||
| 417 | - // `partition_w128` an eight-symbol one, and every `match` carrying one of | ||
| 418 | - // these three fallbacks has an arm for each value of its own alphabet, so | ||
| 419 | - // no stream can reach them. | ||
| 420 | - ( | ||
| 421 | - "a 32x32 partition type this decoder does not code (value={part32})", | ||
| 422 | - "every_partition_value_of_an_enumerated_alphabet_has_an_arm", | ||
| 423 | - Proof::Enumeration, | ||
| 424 | - ), | ||
| 425 | - ( | ||
| 426 | - "an INTER 32x32 partition type this decoder does not code (value={part32})", | ||
| 427 | - "every_partition_value_of_an_enumerated_alphabet_has_an_arm", | ||
| 428 | - Proof::Enumeration, | ||
| 429 | - ), | ||
| 430 | - ( | ||
| 431 | - "a 128x128 superblock partition value outside the 8-symbol alphabet", | ||
| 432 | - "every_partition_value_of_an_enumerated_alphabet_has_an_arm", | ||
| 433 | - Proof::Enumeration, | ||
| 434 | - ), | ||
| 435 | - // lane-t900 r24, enumeration: the key-frame superblock root's own `match` | ||
| 436 | - // has an arm for all ten `partition_w64` values. | ||
| 437 | - ( | ||
| 438 | - "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | ||
| 439 | - "every_partition_value_of_an_enumerated_alphabet_has_an_arm", | ||
| 440 | - Proof::Enumeration, | ||
| 441 | - ), | ||
| 442 | - // lane-t900 r24, enumeration: the inter 16x16-level if/else chain's | ||
| 443 | - // branches name all ten `partition_w16` values between them. | ||
| 444 | - ( | ||
| 445 | - "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", | ||
| 446 | - "every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch", | ||
| 447 | - Proof::Enumeration, | ||
| 448 | - ), | ||
| 449 | - // lane-t900 r24, enumeration: every (CDF width, symbol) pair a tx_type row | ||
| 450 | - // can present maps to a distinct member of that width's own set. | ||
| 451 | - ( | ||
| 452 | - "a tx_type symbol outside its CDF's own set: {t}", | ||
| 453 | - "every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set", | ||
| 454 | - Proof::Enumeration, | ||
| 455 | - ), | ||
| 456 | - // lane-t900 r24 + lane-av1txr RE-PIN, measured: the reader covers spec | ||
| 457 | - // 5.11.40's whole value domain (`0..=(1 << 20) - 2`, both ends of every | ||
| 458 | - // prefix length), so no CONFORMANT symbol stream reaches it -- but the | ||
| 459 | - // string IS reachable as a SYMPTOM: a frame this decoder desyncs on | ||
| 460 | - // (measured: a real libaom monochrome key frame, gate | ||
| 461 | - // `a_real_libaom_monochrome_key_frame_is_refused_by_name` at | ||
| 462 | - // `stream.rs`) leaves the reader mid-symbol and the next `read_golomb` | ||
| 463 | - // reports this tail. The claim below therefore pins the reader's value | ||
| 464 | - // coverage, NOT the string's unreachability. | ||
| 465 | - ( | ||
| 466 | - "a Golomb tail longer than this decoder reads", | ||
| 467 | - "read_golomb_reads_every_value_a_conformant_stream_can_carry", | ||
| 468 | - Proof::Enumeration, | ||
| 469 | - ), | ||
| 470 | - // lane-t900 r25, enumeration: `parse_tile_group` is the only producer of | ||
| 471 | - // the `tiles` vector `decode_stream` tests, and its success path always | ||
| 472 | - // pushes at least one `Tile` -- swept over a real frame OBU's tile payload | ||
| 473 | - // truncated from empty upwards. | ||
| 474 | - ( | ||
| 475 | - "a frame OBU with no tile group", | ||
| 476 | - "a_frame_obu_that_parses_always_carries_at_least_one_tile", | ||
| 477 | - Proof::Enumeration, | ||
| 478 | - ), | ||
| 479 | - // lane-t900 r25, negative gates: hand-built streams that reach each | ||
| 480 | - // refusal by name and output no picture (a `show_existing_frame` header | ||
| 481 | - // over all 8 empty slots; a stream that opens on an inter frame). | ||
| 482 | - ( | ||
| 483 | - "a show_existing_frame header naming an empty reference slot", | ||
| 484 | - "a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name", | ||
| 485 | - Proof::NegativeGate, | ||
| 486 | - ), | ||
| 487 | - ( | ||
| 488 | - "an inter frame with no key frame before it", | ||
| 489 | - "an_inter_frame_opening_a_stream_is_refused_by_name", | ||
| 490 | - Proof::NegativeGate, | ||
| 491 | - ), | ||
| 492 | - // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under | ||
| 493 | - // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17 | ||
| 494 | - // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of | ||
| 495 | - // the 17-row table. | ||
| 496 | - ( | ||
| 497 | - "a motion_mode symbol for a block shape with no CDF row here", | ||
| 498 | - "every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row", | ||
| 499 | - Proof::Enumeration, | ||
| 500 | - ), | ||
| 501 | - // lane-av112bit: real-aomenc 12-bit streams, each refused by name | ||
| 502 | - // (the gates encode with aomenc --bit-depth=12 and assert the exact | ||
| 503 | - // string; the pixel witnesses are the same battery's Ok arms). | ||
| 504 | - // lane-av112bitc: the compound pair left with its refusal -- the | ||
| 505 | - // six-frame compound stream now DECODES byte-exact | ||
| 506 | - // (`a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact`). | ||
| 507 | - // lane-av112bitg: the grain refusal left with its witness -- the | ||
| 508 | - // two-frame 12-bit grain stream now DECODES byte-exact | ||
| 509 | - // (`a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 510 | - // lane-av112bitw: the warp pair left too -- its gate now WITNESSES | ||
| 511 | - // (`a_12bit_warped_motion_stream_decodes_pixel_exact`, the same recipe | ||
| 512 | - // that refused pre-lift) and the compound-warp arm witnesses through | ||
| 513 | - // `a_real_compound_global_warp_12bit_stream_decodes_pixel_exact` | ||
| 514 | - // (hard `compound_warp_hits > 0`). | ||
| 515 | - // lane-av1422lift: the 4:2:2 sequence-header refusal is GONE and so is | ||
| 516 | - // this pairing. The tuple named `a_non_420_subsampled_sequence_header_is_ | ||
| 517 | - // refused_by_name` as the gate that refused (1,0); that gate asserted a | ||
| 518 | - // REFUSAL STRING, so it could not fail on a tree where 4:2:2 decode was | ||
| 519 | - // completely broken -- it passed unchanged on the broken tree and would | ||
| 520 | - // have kept passing if the port had been reverted. Its replacement | ||
| 521 | - // `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact` (and the | ||
| 522 | - // corpus battery `the_pinned_422_corpus_cells_decode_pixel_exact`) assert | ||
| 523 | - // BYTE-EXACT planes against ffmpeg on real 4:2:2 streams, with the | ||
| 524 | - // per-plane coefficient-unit census as the non-vacuity arm. | ||
| 525 | - // lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the | ||
| 526 | - // refusal's witness is now | ||
| 527 | - // `a_real_aomenc_quantisation_matrix_stream_decodes_pixel_exact`, which | ||
| 528 | - // asserts the qm-on stream DECODES pixel-exact vs ffmpeg and the | ||
| 529 | - // matrices were really applied (census counters), while the qm-off | ||
| 530 | - // control stays exact and flat. | ||
| 531 | - // lane-av1-ibcrect: the pairing for "intra block copy on a HORZ/VERT/1:4 | ||
| 532 | - // rect intra strip (reconstruction is not ported at this shape)" is GONE | ||
| 533 | - // with the string -- lane-av1-intrabc/rect14 reconstructed the | ||
| 534 | - // 16x16/32x32-level strips and this lane ported the last site, | ||
| 535 | - // `decode_block_128rect`'s 128-root strip. Witness: | ||
| 536 | - // `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`. | ||
| 537 | - // lane-t900 r26, enumeration: a y_mode symbol comes from a 13-symbol CDF | ||
| 538 | - // and all three guards refuse 13 and above. | ||
| 539 | - ( | ||
| 540 | - "an intra mode this decoder does not code (round 2)", | ||
| 541 | - "every_intra_mode_symbol_of_the_y_mode_alphabet_is_coded", | ||
| 542 | - Proof::Enumeration, | ||
| 543 | - ), | ||
| 544 | - // lane-t900 r26, enumeration: `compute_image_size` is 0 only for a zero | ||
| 545 | - // frame width/height, which no path a header can code produces (swept | ||
| 546 | - // through the real reader per axis, superres division enumerated). | ||
| 547 | - ( | ||
| 548 | - "a frame with no mode-info grid", | ||
| 549 | - "every_frame_size_a_header_can_code_has_a_mode_info_grid", | ||
| 550 | - Proof::Enumeration, | ||
| 551 | - ), | ||
| 552 | - // lane-t900 r26, negative gates: written streams that reach each refusal | ||
| 553 | - // by name (a 64x32 inter frame over a 64x64 reference; a stream opening on | ||
| 554 | - // a non-error-resilient inter frame whose primary_ref slot is empty, over | ||
| 555 | - // all 8 slots) with the picture/CDF slot invariant enumerated alongside. | ||
| 556 | - // lane-t900 r27, negative gate + structural note: every non-`LAST_FRAME` | ||
| 557 | - // reference resolves through `ref_planes`, where an empty slot refuses by | ||
| 558 | - // name (swept over all six such references). The STREAM-level witness is | ||
| 559 | - // out of reach of this crate's writers -- a shown key frame refreshes all | ||
| 560 | - // eight slots and nothing ever clears one, and a stream opening on an | ||
| 561 | - // inter frame is stopped one guard earlier -- so the reachable premise is | ||
| 562 | - // a HIDDEN key frame with a partial `refresh_frame_flags`, which | ||
| 563 | - // `write_frame_header` cannot write. That gap is the open half. | ||
| 564 | - ( | ||
| 565 | - "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", | ||
| 566 | - "a_selected_reference_with_an_empty_ref_frame_idx_slot_refuses_by_name", | ||
| 567 | - Proof::NegativeGate, | ||
| 568 | - ), | ||
| 569 | - // lane-t900 r27, negative gate + census: a written key frame carrying | ||
| 570 | - // each of the three mode-overriding features (over three segment ids) is | ||
| 571 | - // refused by name with no picture; and real aomenc recipes never enable | ||
| 572 | - // one. lane-av1seglvl re-scoped the census: beyond r27's six 1-pass | ||
| 573 | - // no-lag recipes it now parses EVERY frame header's feature table over | ||
| 574 | - // alt-ref-lag and genuine two-pass arms (`--aq-mode=1/2`, cq45 and the | ||
| 575 | - // branch's own high-q cq63, screen + film sources) -- the shapes that | ||
| 576 | - // reach `configure_static_seg_features`, the only setter of ALT_LF/ | ||
| 577 | - // REF_FRAME/SKIP in the tree, which is gated on `hl_sf.static_segmentation` | ||
| 578 | - // ("Always set to 0", speed_features.h) and the second pass | ||
| 579 | - // (encoder_utils.c:738). What aomenc codes is `SEG_LVL_ALT_Q` tables and | ||
| 580 | - // `segment_id` symbols, and nothing else; the map-inheritance defect that | ||
| 581 | - // census surfaced (verbatim copy, decodemv.c:342) is fixed and witnessed | ||
| 582 | - // by `a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_ // pixel_exact`. | ||
| 583 | - // lane-av1-witness2 re-confirmed the census on the current aomenc build: | ||
| 584 | - // it has no --enable-segmentation flag at all (aq-mode is the only | ||
| 585 | - // segmentation driver; aq-mode 4 is out of range for the build), and 8 | ||
| 586 | - // aq-mode recipes (1/2/3, + --delta-lf-mode=1, 4:4:4, banded content) | ||
| 587 | - // wrote SEG_LVL_ALT_Q tables and segment_id symbols where segmentation | ||
| 588 | - // engaged, decoded clean, and never coded one of the three | ||
| 589 | - // mode-overriding features. | ||
| 590 | - ( | ||
| 591 | - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV (this decoder reads segment_id but never lets a segment override a block's reference, skip or mode)", | ||
| 592 | - "a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name", | ||
| 593 | - Proof::NegativeGate, | ||
| 594 | - ), | ||
| 595 | - // lane-t900 r27, structural audit + witness: `record_inter_rect_mi` is the | ||
| 596 | - // single writer of the interp-filter neighbour band, and no call site | ||
| 597 | - // stamps the `[3, 3]` sentinel on an INTER cell (the audit tokenises each | ||
| 598 | - // site's arguments); two real `--enable-obmc=1 --enable-dual-filter=1 | ||
| 599 | - // --cpu-used=0` streams then decode with 237 band reads over ~115 OBMC | ||
| 600 | - // blocks each and the refusal firing 0 times (gate | ||
| 601 | - // `a_real_obmc_stream_reads_a_recorded_switchable_filter_for_every_neighbour`). | ||
| 602 | - // At `--cpu-used=4` aomenc settles on a frame-level fixed filter and the | ||
| 603 | - // band is never read -- the speed is load-bearing in that gate. | ||
| 604 | - ( | ||
| 605 | - "an OBMC neighbour whose switchable interp filter was never recorded", | ||
| 606 | - "every_inter_record_publishes_an_obmc_readable_filter", | ||
| 607 | - Proof::Enumeration, | ||
| 608 | - ), | ||
| 609 | - // lane-t900 r28: all three scaled-reference (superres) refusals -- the | ||
| 610 | - // 8x8 partition leaf, the sub-8x8 inter block and warp -- are LIFTED and | ||
| 611 | - // gone from this inventory. The gate | ||
| 612 | - // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact` | ||
| 613 | - // decodes both lifted shapes byte-exact vs ffmpeg, and the census now | ||
| 614 | - // asserts none of the three strings comes back. | ||
| 615 | - // lane-t900 r33, enumeration: the five callers of `decode_rect_split` pass | ||
| 616 | - // the ten rect footprints with `8 <= min` and `max <= 64`, and every one of | ||
| 617 | - // them has a chroma table and -- at every tx depth -- a luma arm. The two | ||
| 618 | - // shape classes that would miss one (a 128-sided half, a sub-8 strip) have | ||
| 619 | - // readers that are not among those callers. | ||
| 620 | - ( | ||
| 621 | - "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | ||
| 622 | - "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table", | ||
| 623 | - Proof::Enumeration, | ||
| 624 | - ), | ||
| 625 | - ( | ||
| 626 | - "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | ||
| 627 | - "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table", | ||
| 628 | - Proof::Enumeration, | ||
| 629 | - ), | ||
| 630 | - // lane-av1-refusalaudit, enumeration + witness2 hunt: decode_block_rect64's | ||
| 631 | - // chroma-unit table covers every conformant 64-axis strip unit in both | ||
| 632 | - // supported chroma formats -- at 4:4:4 the strips 64x32/32x64/64x16/16x64 | ||
| 633 | - // tile to (32,32)/(32,16)/(16,32); at 4:2:0 the halved footprints land on | ||
| 634 | - // (32,16)/(16,32)/(32,8)/(8,32). A 128-root half is | ||
| 635 | - // `decode_block_128rect`'s, and the 128 root has no 1:4 arm. The hunt (8 | ||
| 636 | - // real aomenc key-frame encodes: screen+intrabc, rect+1:4, sb 64 and 128, | ||
| 637 | - // cq 10..63, cpu-used 0..2) never reached the arm; the three streams that | ||
| 638 | - // decode to completion never enter decode_block_rect64 at all. | ||
| 639 | - ( | ||
| 640 | - "a 64-axis strip whose chroma unit has no coefficient table", | ||
| 641 | - "every_chroma_unit_a_64_axis_strip_can_present_has_a_coefficient_table", | ||
| 642 | - Proof::Enumeration, | ||
| 643 | - ), | ||
| 644 | - // lane-av1rect8x16, enumeration: `decode_block_rect`'s `_` arm. The nine | ||
| 645 | - // textual `decode_block_rect(` matches are 1 declaration + 8 call sites | ||
| 646 | - // (this test's `assert_eq!(sites, 8)` counts the calls); all eight pass | ||
| 647 | - // `bw`/`bh` as integer LITERALS and every one of them is | ||
| 648 | - // a 32-level `PARTITION_HORZ`/`VERT`/`HORZ_A`/`_B`/`VERT_A`/`_B` arm of | ||
| 649 | - // `read_sb128_root`'s `match part32`, so the caller shape set is exactly | ||
| 650 | - // {32x16, 16x32} and their chroma halves under the three subsamplings an | ||
| 651 | - // AV1 `color_config` can carry are {(16,8), (8,16), (16,16), (8,32), | ||
| 652 | - // (32,16), (16,32)} -- every one of which has a row. The shape the | ||
| 653 | - // sibling sweep left open, a 4:2:0 8x16 luma strip's (4,8) chroma, is | ||
| 654 | - // NOT reachable here: a 16-level 2:1 luma strip is read by | ||
| 655 | - // `decode_leaf_rect`, which carries the (4,8)/(8,4) rows itself | ||
| 656 | - // (decode.rs:15409-15420). Measured, not assumed: 840 real aomenc 4:2:0 | ||
| 657 | - // key-frame encodes, 826 of whose parsed leaf lists carry a coded | ||
| 658 | - // 16-level 2:1 luma strip (`horz_vert_intra_hits()`, which fires only | ||
| 659 | - // at the three `decode_leaf_rect` strip sites), decoded to completion | ||
| 660 | - // with this string firing 0 times. | ||
| 661 | - ( | ||
| 662 | - "a rectangular chroma transform whose size has no coefficient table", | ||
| 663 | - "every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table", | ||
| 664 | - Proof::Enumeration, | ||
| 665 | - ), | ||
| 666 | - // lane-t900 r33, enumeration: each of the four symbols this guard tests is | ||
| 667 | - // read under a size gate that no 128-pixel side passes (the call site's | ||
| 668 | - // literal `cfl=false`, `filter_intra_size_class_rect`'s table, and | ||
| 669 | - // `palette_bsize_ctx_wh`'s bound). | ||
| 670 | - ( | ||
| 671 | - "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", | ||
| 672 | - "no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol", | ||
| 673 | - Proof::Enumeration, | ||
| 674 | - ), | ||
| 675 | - // lane-av1txr: the sub-8x8 intrabc refusal this census pinned is GONE (the | ||
| 676 | - // capability landed; see the note in `REFUSALS`). The census gate survives | ||
| 677 | - // as the witness that its premise is still exercised -- `reached` is 0 by | ||
| 678 | - // construction now. | ||
| 679 | - // lane-t900 r33, CENSUS: four quantisers of the recipe that reaches the | ||
| 680 | - // intrabc var-tx tree at all read it for 5 blocks in total, every one of | ||
| 681 | - // which resolved to a UNIFORM leaf size, with the frames pixel-exact. | ||
| 682 | - // lane-av1-ibcvtx: the mixed-leaf refusal is LIFTED (see the note in | ||
| 683 | - // `REFUSALS`); the pair above moved out with the string. The capability | ||
| 684 | - // gate is | ||
| 685 | - // `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal`, | ||
| 686 | - // which pins the frame's residual sample mismatch against ffmpeg to the | ||
| 687 | - // named second defect (a non-intrabc uniform-tree block elsewhere in the | ||
| 688 | - // stream) so the pin tightens automatically when that defect is fixed. | ||
| 689 | - ( | ||
| 690 | - "a reference picture outside the 2x down / 16x up scaling limits", | ||
| 691 | - "an_inter_frame_shorter_than_its_reference_is_refused_by_name", | ||
| 692 | - Proof::NegativeGate, | ||
| 693 | - ), | ||
| 694 | - ( | ||
| 695 | - "a frame naming primary_ref_frame at a reference slot with no saved CDF state", | ||
| 696 | - "an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name", | ||
| 697 | - Proof::NegativeGate, | ||
| 698 | - ), | ||
| 699 | - // lane-av1bookkeep W1-4, NEGATIVE: the BLOCK_INVALID subsize refusal | ||
| 700 | - // (`refuse_invalid_plane_block`, decode.rs). It is libaom's own rule | ||
| 701 | - // (`get_plane_block_size` -> `AOM_CODEC_CORRUPT_FRAME`, decodeframe.c:1456) | ||
| 702 | - // applied to a stream whose header and tile disagree. The pin is a 4:2:2 | ||
| 703 | - // sequence header over a 4:2:0 key frame's tile, whose partition symbols | ||
| 704 | - // name 8x16 -- a subsize with no chroma plane block at ss (1,0) -- so the | ||
| 705 | - // guard FIRES, by name, and the gate also drives a genuine 4:2:2 pin that | ||
| 706 | - // must still decode, so it cannot pass by refusing everything. The gate's | ||
| 707 | - // body quotes the refusal WHOLE (not just the libaom citation inside it), | ||
| 708 | - // which is what makes this row an anchor the checker can hold. | ||
| 709 | - ( | ||
| 710 | - "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this frame's subsampling mode (libaom: \\\"Block size %dx%d invalid with this subsampling mode\\\", av1/decoder/decodeframe.c:1456, refusing by the same rule)", | ||
| 711 | - "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt", | ||
| 712 | - Proof::NegativeGate, | ||
| 713 | - ), | ||
| 714 | - // lane-av1bookkeep W1-4, ENUMERATION: the LONE capability claim. The guard | ||
| 715 | - // in `decode_block_rect` fires only when `filter_intra.is_some()`, and that | ||
| 716 | - // flag is `Some` only where `filter_intra_size_class_rect` says so. The | ||
| 717 | - // strips the guard protects are `(64, 32)` / `(32, 64)`; | ||
| 718 | - // `av1_filter_intra_allowed_bsize` caps both sides at 32x32, so no conformant | ||
| 719 | - // stream offers the symbol there. The gate walks every EXPLICIT arm of the | ||
| 720 | - // table (none admits a 64 axis), drives the square-delegate's callee | ||
| 721 | - // `filter_intra_size_class` at 32 and 64 directly, and quotes the claim's | ||
| 722 | - // leading clause in its own body. | ||
| 723 | - ( | ||
| 724 | - "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", | ||
| 725 | - "a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol", | ||
| 726 | - Proof::Enumeration, | ||
| 727 | - ), | ||
| 728 | -]; | ||
| 729 | - | ||
| 730 | -/// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than | ||
| 731 | -/// a test failure. | ||
| 732 | -/// | ||
| 733 | -/// A gate named `..._decodes_pixel_exact` that cannot decode has failed, and | ||
| 734 | -/// swallowing the error keeps the suite green while the gate proves nothing -- | ||
| 735 | -/// the same vacuum as a gate whose feature never fires, arrived at from the | ||
| 736 | -/// other side. The list is the exact pin of the gates still shaped that way, so | ||
| 737 | -/// the set cannot grow; a converted gate is DELETED from it. | ||
| 738 | -/// | ||
| 739 | -/// lane-av1skipfix: emptied. The last four (`filter_intra`, the two | ||
| 740 | -/// `deblocking` gates, and `gradients_stream_with_cdef`) were converted to the | ||
| 741 | -/// attempt-loop pattern -- several recipes, at least one required to decode, the | ||
| 742 | -/// feature counter hard-asserted on a pixel-compared attempt, a decode error on | ||
| 743 | -/// every attempt a hard failure carrying its refusal text. None of the four had | ||
| 744 | -/// a genuinely absent capability: every recipe family decoded, the refusals the | ||
| 745 | -/// old arms swallowed were a named *screen-content* refusal on one recipe and a | ||
| 746 | -/// stale premise on the CDEF gate (a single-superblock frame cannot make libaom | ||
| 747 | -/// write `cdef_bits > 0`, so the old recipe never read a `cdef_idx` at all). | ||
| 748 | -#[cfg(test)] | ||
| 749 | -const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[]; | ||
| 750 | - | ||
| 751 | -/// Source text with Rust's line continuations dropped and every whitespace run | ||
| 752 | -/// collapsed to one space -- the form rustc gives a multi-line literal -- so a | ||
| 753 | -/// refusal written across three source lines is still findable in a body, and | ||
| 754 | -/// a gate's quote of it still matches the guard's spelling. | ||
| 755 | -#[cfg(test)] | ||
| 756 | -fn squash_source(s: &str) -> String { | ||
| 757 | - let mut out = String::with_capacity(s.len()); | ||
| 758 | - let mut pending_space = false; | ||
| 759 | - for (i, c) in s.char_indices() { | ||
| 760 | - if c == '\\' { | ||
| 761 | - let rest = &s[i + 1..]; | ||
| 762 | - if rest.contains('\n') | ||
| 763 | - && rest | ||
| 764 | - .chars() | ||
| 765 | - .take_while(|c| *c != '\n') | ||
| 766 | - .all(|c| c == ' ' || c == '\t' || c == '\r') | ||
| 767 | - { | ||
| 768 | - continue; | ||
| 769 | - } | ||
| 770 | - } | ||
| 771 | - if c.is_whitespace() { | ||
| 772 | - pending_space = true; | ||
| 773 | - continue; | ||
| 774 | - } | ||
| 775 | - if pending_space && !out.is_empty() { | ||
| 776 | - out.push(' '); | ||
| 777 | - } | ||
| 778 | - pending_space = false; | ||
| 779 | - out.push(c); | ||
| 780 | - } | ||
| 781 | - out | ||
| 782 | -} | ||
| 783 | - | ||
| 784 | -/// Does `src` carry `refusal`? | ||
| 785 | -/// | ||
| 786 | -/// Lane-av1refusalspan: a proving gate quotes the refusal it proves, and this | ||
| 787 | -/// is how it pins that quote to the guard that still carries the string. Both | ||
| 788 | -/// sides are squashed, so a literal written over two lines with a `\` | ||
| 789 | -/// continuation still matches. | ||
| 790 | -#[cfg(test)] | ||
| 791 | -pub(crate) fn pins_refusal(src: &str, refusal: &str) -> bool { | ||
| 792 | - squash_source(src).contains(&squash_source(refusal)) | ||
| 793 | -} | ||
| 794 | - | ||
| 795 | -#[cfg(test)] | ||
| 796 | -mod tests { | ||
| 797 | - use super::{ | ||
| 798 | - CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, PROVEN, Proof, REFUSALS, | ||
| 799 | - squash_source, | ||
| 800 | - }; | ||
| 801 | - use std::collections::BTreeSet; | ||
| 802 | - | ||
| 803 | - /// Every distinct `unsupported(...)` reason on the decode path. | ||
| 804 | - /// | ||
| 805 | - /// Both sources use the same shape -- `stream.rs` calls | ||
| 806 | - /// `Error::unsupported(context, reason)` and `decode.rs` a local | ||
| 807 | - /// `unsupported(reason)` helper -- so the reason is always the LAST string | ||
| 808 | - /// literal of the call, and Rust's `\` line continuations inside it are | ||
| 809 | - /// joined the way rustc joins them. | ||
| 810 | - fn decode_path_refusals() -> BTreeSet<String> { | ||
| 811 | - let mut found = BTreeSet::new(); | ||
| 812 | - for src in [crate::test_source::module_source("decode"), crate::test_source::module_source("stream")] { | ||
| 813 | - let bytes = src.as_bytes(); | ||
| 814 | - for (start, _) in src.match_indices("unsupported(") { | ||
| 815 | - // `Error::unsupported(` and the bare helper both end here. | ||
| 816 | - let mut i = start + "unsupported(".len(); | ||
| 817 | - // `unsupported(format!("..."))` is the same refusal, one layer in. | ||
| 818 | - if src[i..].starts_with("format!(") { | ||
| 819 | - i += "format!(".len(); | ||
| 820 | - } | ||
| 821 | - let mut last: Option<String> = None; | ||
| 822 | - loop { | ||
| 823 | - while i < bytes.len() && (bytes[i] as char).is_whitespace() { | ||
| 824 | - i += 1; | ||
| 825 | - } | ||
| 826 | - if i >= bytes.len() || bytes[i] != b'"' { | ||
| 827 | - break; | ||
| 828 | - } | ||
| 829 | - i += 1; | ||
| 830 | - let mut lit = String::new(); | ||
| 831 | - while i < bytes.len() && bytes[i] != b'"' { | ||
| 832 | - if bytes[i] == b'\\' { | ||
| 833 | - // A backslash-newline continuation drops the newline | ||
| 834 | - // and the indentation that follows it. | ||
| 835 | - if bytes.get(i + 1) == Some(&b'\n') { | ||
| 836 | - i += 2; | ||
| 837 | - while i < bytes.len() && matches!(bytes[i], b' ' | b'\t') { | ||
| 838 | - i += 1; | ||
| 839 | - } | ||
| 840 | - continue; | ||
| 841 | - } | ||
| 842 | - lit.push(bytes[i] as char); | ||
| 843 | - lit.push(bytes[i + 1] as char); | ||
| 844 | - i += 2; | ||
| 845 | - continue; | ||
| 846 | - } | ||
| 847 | - lit.push(bytes[i] as char); | ||
| 848 | - i += 1; | ||
| 849 | - } | ||
| 850 | - i += 1; | ||
| 851 | - last = Some(lit); | ||
| 852 | - while i < bytes.len() && (bytes[i] as char).is_whitespace() { | ||
| 853 | - i += 1; | ||
| 854 | - } | ||
| 855 | - if i < bytes.len() && bytes[i] == b',' { | ||
| 856 | - i += 1; | ||
| 857 | - continue; | ||
| 858 | - } | ||
| 859 | - break; | ||
| 860 | - } | ||
| 861 | - if let Some(reason) = last { | ||
| 862 | - // `Error::unsupported`'s first argument is the context | ||
| 863 | - // ("AV1 tile"), which is not a reason. | ||
| 864 | - if reason != "AV1 tile" { | ||
| 865 | - found.insert(reason); | ||
| 866 | - } | ||
| 867 | - } | ||
| 868 | - } | ||
| 869 | - } | ||
| 870 | - found | ||
| 871 | - } | ||
| 872 | - | ||
| 873 | - #[test] | ||
| 874 | - fn the_decode_path_refuses_exactly_the_listed_cases() { | ||
| 875 | - let found = decode_path_refusals(); | ||
| 876 | - let listed: BTreeSet<String> = CAPABILITY_CLAIMS | ||
| 877 | - .iter() | ||
| 878 | - .chain(REFUSALS) | ||
| 879 | - .map(|&s| s.to_owned()) | ||
| 880 | - .collect(); | ||
| 881 | - assert!( | ||
| 882 | - found.len() >= 30, | ||
| 883 | - "the refusal scan found only {} reasons -- it is broken, not the decoder", | ||
| 884 | - found.len() | ||
| 885 | - ); | ||
| 886 | - | ||
| 887 | - let added: Vec<&String> = found.difference(&listed).collect(); | ||
| 888 | - assert!( | ||
| 889 | - added.is_empty(), | ||
| 890 | - "new decode-path refusals are not in the inventory: {added:#?}\n\ | ||
| 891 | - Add each to REFUSALS -- or, if it claims something about what an ENCODER can \ | ||
| 892 | - emit, to CAPABILITY_CLAIMS, which requires evidence that the case is genuinely \ | ||
| 893 | - unreachable rather than merely unseen." | ||
| 894 | - ); | ||
| 895 | - let removed: Vec<&String> = listed.difference(&found).collect(); | ||
| 896 | - assert!( | ||
| 897 | - removed.is_empty(), | ||
| 898 | - "these refusals are listed but no longer in the decode path: {removed:#?}\n\ | ||
| 899 | - Delete them from the inventory -- the capability landed, which is the good case." | ||
| 900 | - ); | ||
| 901 | - } | ||
| 902 | - | ||
| 903 | - /// A refusal may say what THIS DECODER does not do. Saying what an encoder | ||
| 904 | - /// never emits is a claim about the world, and this repository has already | ||
| 905 | - /// shipped one that was false. | ||
| 906 | - #[test] | ||
| 907 | - fn capability_claims_are_declared_not_scattered() { | ||
| 908 | - let claimy: Vec<String> = decode_path_refusals() | ||
| 909 | - .into_iter() | ||
| 910 | - .filter(|r| r.contains("never writes") || r.contains("never expected")) | ||
| 911 | - .collect(); | ||
| 912 | - let declared: BTreeSet<&str> = CAPABILITY_CLAIMS.iter().copied().collect(); | ||
| 913 | - for reason in &claimy { | ||
| 914 | - assert!( | ||
| 915 | - declared.contains(reason.as_str()), | ||
| 916 | - "{reason:?} claims an encoder never emits this case but is not in \ | ||
| 917 | - CAPABILITY_CLAIMS. Such a claim needs a gate that proves the case is \ | ||
| 918 | - unreachable; until it has one, phrase the refusal as what this decoder \ | ||
| 919 | - does not decode." | ||
| 920 | - ); | ||
| 921 | - } | ||
| 922 | - } | ||
| 923 | - | ||
| 924 | - /// No NEW gate may quietly turn a decode error into a skip. | ||
| 925 | - #[test] | ||
| 926 | - fn gates_that_swallow_a_decode_error_are_declared() { | ||
| 927 | - let src = crate::test_source::module_source("stream"); | ||
| 928 | - let mut found: BTreeSet<String> = BTreeSet::new(); | ||
| 929 | - for (i, _) in src.match_indices("\"SKIP ") { | ||
| 930 | - let rest = &src[i + "\"SKIP ".len()..]; | ||
| 931 | - let Some(colon) = rest.find(':') else { | ||
| 932 | - continue; | ||
| 933 | - }; | ||
| 934 | - let name = &rest[..colon]; | ||
| 935 | - if !name | ||
| 936 | - .chars() | ||
| 937 | - .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') | ||
| 938 | - { | ||
| 939 | - continue; | ||
| 940 | - } | ||
| 941 | - // The tail of the message says what was skipped. Only "{e}" -- the | ||
| 942 | - // decode error itself -- is the shape this test is about; "no | ||
| 943 | - // ffmpeg"/"no aomenc" are tool absence, governed by | ||
| 944 | - // EC_AV1_REQUIRE_AOMENC instead. | ||
| 945 | - let Some(end) = rest.find("\"") else { continue }; | ||
| 946 | - if rest[colon..end].contains("{e}") { | ||
| 947 | - found.insert(name.to_owned()); | ||
| 948 | - } | ||
| 949 | - } | ||
| 950 | - let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect(); | ||
| 951 | - let added: Vec<&String> = found | ||
| 952 | - .iter() | ||
| 953 | - .filter(|n| !listed.contains(n.as_str())) | ||
| 954 | - .collect(); | ||
| 955 | - assert!( | ||
| 956 | - added.is_empty(), | ||
| 957 | - "these gates turn a decode error into a printed SKIP and are not declared: \ | ||
| 958 | - {added:#?}\nA gate that cannot decode has failed -- assert on the error, or use \ | ||
| 959 | - the attempt-loop pattern (several fixtures, at least one must decode, firing count \ | ||
| 960 | - hard-asserted)." | ||
| 961 | - ); | ||
| 962 | - let stale: Vec<&&str> = listed.iter().filter(|n| !found.contains(**n)).collect(); | ||
| 963 | - assert!( | ||
| 964 | - stale.is_empty(), | ||
| 965 | - "{stale:#?} no longer swallow a decode error -- delete them from the list." | ||
| 966 | - ); | ||
| 967 | - } | ||
| 968 | - | ||
| 969 | - /// The partition alphabet, in CDF symbol order. | ||
| 970 | - const PARTITION_NAMES: [&str; 10] = [ | ||
| 971 | - "PARTITION_NONE", | ||
| 972 | - "PARTITION_HORZ", | ||
| 973 | - "PARTITION_VERT", | ||
| 974 | - "PARTITION_SPLIT", | ||
| 975 | - "PARTITION_HORZ_A", | ||
| 976 | - "PARTITION_HORZ_B", | ||
| 977 | - "PARTITION_VERT_A", | ||
| 978 | - "PARTITION_VERT_B", | ||
| 979 | - "PARTITION_HORZ_4", | ||
| 980 | - "PARTITION_VERT_4", | ||
| 981 | - ]; | ||
| 982 | - | ||
| 983 | - /// The partition values a `match` arm pattern -- or an `if` chain's | ||
| 984 | - /// condition -- names: its own tokens, plus every value of an inclusive | ||
| 985 | - /// range (`(PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p)` is four | ||
| 986 | - /// values in one). Tokenised, never `contains()`d: a misspelled constant | ||
| 987 | - /// in a match pattern is an irrefutable binding that compiles and swallows | ||
| 988 | - /// the alphabet, and a substring check would call that covered. | ||
| 989 | - fn partition_values_named(head: &str) -> BTreeSet<usize> { | ||
| 990 | - let mut out = BTreeSet::new(); | ||
| 991 | - let idx: Vec<usize> = head | ||
| 992 | - .split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')) | ||
| 993 | - .filter_map(|tok| PARTITION_NAMES.iter().position(|n| *n == tok)) | ||
| 994 | - .collect(); | ||
| 995 | - if head.contains("..=") && idx.len() == 2 { | ||
| 996 | - for v in idx[0]..=idx[1] { | ||
| 997 | - out.insert(v); | ||
| 998 | - } | ||
| 999 | - } | ||
| 1000 | - out.extend(idx); | ||
| 1001 | - out | ||
| 1002 | - } | ||
| 1003 | - | ||
| 1004 | - /// The partition alphabets, enumerated against the arms that code them. | ||
| 1005 | - /// | ||
| 1006 | - /// A partition value is a CDF symbol, and `SymbolDecoder::symbol_fixed` | ||
| 1007 | - /// cannot return one outside `0..nsyms` -- so a `match` whose arms cover | ||
| 1008 | - /// its whole alphabet has an unreachable fallback, and the refusal that | ||
| 1009 | - /// fallback carries names a value no stream can present. This test finds | ||
| 1010 | - /// each such `match` by the refusal in its OWN fallback arm (rather than | ||
| 1011 | - /// by line number, which drifts) and enumerates the alphabet against the | ||
| 1012 | - /// arm patterns, ranges included. | ||
| 1013 | - /// | ||
| 1014 | - /// The refusals stay in the code: a partition value is a `usize`, so the | ||
| 1015 | - /// match needs a fallback arm, and a named refusal is a better one than a | ||
| 1016 | - /// panic (class `branch-dropped-as-unreachable`). What this removes is the | ||
| 1017 | - /// UNMEASURED part of the claim. | ||
| 1018 | - /// | ||
| 1019 | - /// Not every partition fallback belongs here: the ones that name a shape | ||
| 1020 | - /// this decoder genuinely does not code yet (the 128-root consumers) are | ||
| 1021 | - /// live refusals, and the 16x16-level inter chain is an `if`/`else if` | ||
| 1022 | - /// ladder rather than a match, so it needs its own enumerator. | ||
| 1023 | - #[test] | ||
| 1024 | - fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() { | ||
| 1025 | - // (the refusal in the fallback arm, the alphabet its CDF codes) | ||
| 1026 | - let blocks: [(&str, usize); 4] = [ | ||
| 1027 | - ( | ||
| 1028 | - "a 32x32 partition type this decoder does not code", | ||
| 1029 | - crate::cdf::PARTITION_W32[0].len() - 1, | ||
| 1030 | - ), | ||
| 1031 | - ( | ||
| 1032 | - "an INTER 32x32 partition type this decoder does not code", | ||
| 1033 | - crate::cdf::PARTITION_W32[0].len() - 1, | ||
| 1034 | - ), | ||
| 1035 | - ( | ||
| 1036 | - "a 128x128 superblock partition value outside the 8-symbol alphabet", | ||
| 1037 | - crate::cdf::PARTITION_W128[0].len() - 1, | ||
| 1038 | - ), | ||
| 1039 | - // lane-t900 r24: the key-frame superblock root. Its `part` is | ||
| 1040 | - // either a `partition_w64` symbol or, at a frame edge, one of the | ||
| 1041 | - // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT, | ||
| 1042 | - // PARTITION_SPLIT) -- all inside the same ten-value alphabet. | ||
| 1043 | - ( | ||
| 1044 | - "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | ||
| 1045 | - crate::cdf::PARTITION_W64[0].len() - 1, | ||
| 1046 | - ), | ||
| 1047 | - ]; | ||
| 1048 | - let src = crate::test_source::module_source("decode"); | ||
| 1049 | - let lines: Vec<&str> = src.lines().collect(); | ||
| 1050 | - let indent = |l: &str| l.len() - l.trim_start().len(); | ||
| 1051 | - let mut found = 0usize; | ||
| 1052 | - for (i, line) in lines.iter().enumerate() { | ||
| 1053 | - let t = line.trim(); | ||
| 1054 | - if !(t.starts_with("match part") && t.ends_with('{')) { | ||
| 1055 | - continue; | ||
| 1056 | - } | ||
| 1057 | - let outer = indent(line); | ||
| 1058 | - let close = " ".repeat(outer) + "}"; | ||
| 1059 | - let (mut arms, mut fallback) = (BTreeSet::new(), String::new()); | ||
| 1060 | - let mut in_fallback = false; | ||
| 1061 | - for l in &lines[i + 1..] { | ||
| 1062 | - if *l == close { | ||
| 1063 | - break; | ||
| 1064 | - } | ||
| 1065 | - // Arm patterns sit exactly one level in; anything deeper is an | ||
| 1066 | - // arm's body, nested matches and `part == PARTITION_*` reads | ||
| 1067 | - // included. | ||
| 1068 | - if indent(l) != outer + 4 && !l.trim().is_empty() { | ||
| 1069 | - if in_fallback { | ||
| 1070 | - fallback.push_str(l.trim()); | ||
| 1071 | - } | ||
| 1072 | - continue; | ||
| 1073 | - } | ||
| 1074 | - if !l.contains("=>") { | ||
| 1075 | - continue; | ||
| 1076 | - } | ||
| 1077 | - in_fallback = l.trim_start().starts_with("_ =>"); | ||
| 1078 | - arms.extend(partition_values_named(l.split("=>").next().unwrap_or(""))); | ||
| 1079 | - } | ||
| 1080 | - let Some((reason, alphabet)) = | ||
| 1081 | - blocks.iter().find(|(reason, _)| fallback.contains(reason)) | ||
| 1082 | - else { | ||
| 1083 | - continue; | ||
| 1084 | - }; | ||
| 1085 | - found += 1; | ||
| 1086 | - let missing: Vec<usize> = (0..*alphabet).filter(|v| !arms.contains(v)).collect(); | ||
| 1087 | - assert!( | ||
| 1088 | - missing.is_empty(), | ||
| 1089 | - "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \ | ||
| 1090 | - is a real gap in its {alphabet}-value alphabet, not a dead refusal", | ||
| 1091 | - i + 1, | ||
| 1092 | - missing | ||
| 1093 | - .iter() | ||
| 1094 | - .map(|v| PARTITION_NAMES[*v]) | ||
| 1095 | - .collect::<Vec<_>>() | ||
| 1096 | - ); | ||
| 1097 | - } | ||
| 1098 | - assert_eq!( | ||
| 1099 | - found, | ||
| 1100 | - blocks.len(), | ||
| 1101 | - "not every enumerated partition refusal was located in decode.rs" | ||
| 1102 | - ); | ||
| 1103 | - } | ||
| 1104 | - | ||
| 1105 | - /// The same enumeration for a partition refusal that sits in an `if` | ||
| 1106 | - /// chain rather than a `match` fallback. | ||
| 1107 | - /// | ||
| 1108 | - /// The inter 16x16-level ladder tests `part16` against constants arm by | ||
| 1109 | - /// arm and refuses in its second-to-last branch, with `PARTITION_SPLIT` | ||
| 1110 | - /// left to the final `else`. Nothing about that shape is weaker than a | ||
| 1111 | - /// `match`: `part16` is a `partition_w16` symbol (or, at a frame edge, a | ||
| 1112 | - /// gathered value of the same alphabet), so if the chain's conditions | ||
| 1113 | - /// between them name every value of that alphabet, the refusing branch is | ||
| 1114 | - /// unreachable. | ||
| 1115 | - /// | ||
| 1116 | - /// The conditions are read from the source, tokenised (never | ||
| 1117 | - /// substring-matched -- lane-t900 r21), and a condition carrying `&&` is | ||
| 1118 | - /// rejected outright: a value it names is only conditionally handled, and | ||
| 1119 | - /// counting it would overstate the coverage. | ||
| 1120 | - #[test] | ||
| 1121 | - fn every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch() { | ||
| 1122 | - // (the refusal in the chain's refusing branch, the alphabet its CDF codes) | ||
| 1123 | - let chains: [(&str, usize); 1] = [( | ||
| 1124 | - "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", | ||
| 1125 | - crate::cdf::PARTITION_W16[0].len() - 1, | ||
| 1126 | - )]; | ||
| 1127 | - | ||
| 1128 | - let src = crate::test_source::module_source("decode"); | ||
| 1129 | - let lines: Vec<&str> = src.lines().collect(); | ||
| 1130 | - let indent = |l: &str| l.len() - l.trim_start().len(); | ||
| 1131 | - let mut found = 0usize; | ||
| 1132 | - for (reason, alphabet) in chains { | ||
| 1133 | - let refusal = lines | ||
| 1134 | - .iter() | ||
| 1135 | - .position(|l| l.contains(reason)) | ||
| 1136 | - .unwrap_or_else(|| panic!("{reason:?} is not in decode.rs")); | ||
| 1137 | - // The branch that carries the refusal: the nearest `} else if` | ||
| 1138 | - // above it. Its indentation is the chain's own. | ||
| 1139 | - let head = (0..refusal) | ||
| 1140 | - .rev() | ||
| 1141 | - .find(|&i| lines[i].trim_start().starts_with("} else if ")) | ||
| 1142 | - .unwrap_or_else(|| panic!("{reason:?} is not inside an if/else chain")); | ||
| 1143 | - let outer = indent(lines[head]); | ||
| 1144 | - let var = lines[head].trim_start()["} else if ".len()..] | ||
| 1145 | - .split_whitespace() | ||
| 1146 | - .next() | ||
| 1147 | - .unwrap_or("") | ||
| 1148 | - .to_owned(); | ||
| 1149 | - assert!( | ||
| 1150 | - !var.is_empty(), | ||
| 1151 | - "the chain at decode.rs:{} tests nothing", | ||
| 1152 | - head + 1 | ||
| 1153 | - ); | ||
| 1154 | - | ||
| 1155 | - // Walk up collecting every branch head of this chain, each read to | ||
| 1156 | - // the line that opens its body. | ||
| 1157 | - let mut named = BTreeSet::new(); | ||
| 1158 | - let mut i = head + 1; | ||
| 1159 | - let mut heads = 0usize; | ||
| 1160 | - loop { | ||
| 1161 | - i -= 1; | ||
| 1162 | - let t = lines[i].trim_start(); | ||
| 1163 | - if indent(lines[i]) != outer | ||
| 1164 | - || !(t.starts_with("} else if ") || t.starts_with("if ")) | ||
| 1165 | - { | ||
| 1166 | - if i == 0 { | ||
| 1167 | - break; | ||
| 1168 | - } | ||
| 1169 | - continue; | ||
| 1170 | - } | ||
| 1171 | - let mut cond = String::new(); | ||
| 1172 | - for l in &lines[i..] { | ||
| 1173 | - cond.push(' '); | ||
| 1174 | - cond.push_str(l.trim()); | ||
| 1175 | - if l.trim_end().ends_with('{') { | ||
| 1176 | - break; | ||
| 1177 | - } | ||
| 1178 | - } | ||
| 1179 | - assert!( | ||
| 1180 | - cond.contains(&var), | ||
| 1181 | - "the branch at decode.rs:{} sits in the chain that refuses {reason:?} but \ | ||
| 1182 | - does not test {var}", | ||
| 1183 | - i + 1 | ||
| 1184 | - ); | ||
| 1185 | - assert!( | ||
| 1186 | - !cond.contains("&&"), | ||
| 1187 | - "the branch at decode.rs:{} handles its partition values only conditionally \ | ||
| 1188 | - ({cond:?}) -- the enumeration below would overstate what the chain covers", | ||
| 1189 | - i + 1 | ||
| 1190 | - ); | ||
| 1191 | - named.extend(partition_values_named(&cond)); | ||
| 1192 | - heads += 1; | ||
| 1193 | - if t.starts_with("if ") { | ||
| 1194 | - break; | ||
| 1195 | - } | ||
| 1196 | - assert!(i > 0, "the chain that refuses {reason:?} has no start"); | ||
| 1197 | - } | ||
| 1198 | - // The value the refusing branch excludes (`part16 != PARTITION_SPLIT`) | ||
| 1199 | - // is handled by the chain's final `else`, so require one. | ||
| 1200 | - let close = " ".repeat(outer) + "} else {"; | ||
| 1201 | - assert!( | ||
| 1202 | - lines[refusal..].iter().any(|l| *l == close), | ||
| 1203 | - "the chain that refuses {reason:?} has no final `else`, so the value its \ | ||
| 1204 | - refusing branch excludes is handled nowhere" | ||
| 1205 | - ); | ||
| 1206 | - assert!(heads >= 2, "only {heads} branch(es) found for {reason:?}"); | ||
| 1207 | - found += 1; | ||
| 1208 | - let missing: Vec<usize> = (0..alphabet).filter(|v| !named.contains(v)).collect(); | ||
| 1209 | - assert!( | ||
| 1210 | - missing.is_empty(), | ||
| 1211 | - "the chain at decode.rs:{} refuses {reason:?} but no branch names {:?} -- that \ | ||
| 1212 | - is a real gap in its {alphabet}-value alphabet, not a dead refusal", | ||
| 1213 | - head + 1, | ||
| 1214 | - missing | ||
| 1215 | - .iter() | ||
| 1216 | - .map(|v| PARTITION_NAMES[*v]) | ||
| 1217 | - .collect::<Vec<_>>() | ||
| 1218 | - ); | ||
| 1219 | - } | ||
| 1220 | - assert_eq!(found, chains.len()); | ||
| 1221 | - } | ||
| 1222 | - | ||
| 1223 | - /// Every `tx_type` symbol of every CDF width, mapped through the set that | ||
| 1224 | - /// width names. | ||
| 1225 | - /// | ||
| 1226 | - /// The reader decodes `t` from a row of `n` slots, so `t` is in | ||
| 1227 | - /// `0..n - 1`, and hands `(n, t)` to [`crate::decode::tx_type_from_symbol`] | ||
| 1228 | - /// -- the readers' own mapping, called here rather than transcribed | ||
| 1229 | - /// (class `shared-oracle-blindness`: a second copy of a table can be | ||
| 1230 | - /// self-consistently wrong). The widths are read from `cdf_state.rs`'s | ||
| 1231 | - /// `tx_type` field declarations, so a new table with a width the mapping | ||
| 1232 | - /// does not name fails this test rather than reaching the refusal at | ||
| 1233 | - /// runtime. | ||
| 1234 | - /// | ||
| 1235 | - /// Distinctness is part of the claim: a set of `n - 1` symbols must map to | ||
| 1236 | - /// `n - 1` DIFFERENT transform types, or the mapping has lost a member of | ||
| 1237 | - /// the spec's `Tx_Type_*_Inv_Set*` even while every symbol resolves. | ||
| 1238 | - #[test] | ||
| 1239 | - fn every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set() { | ||
| 1240 | - let mut widths: BTreeSet<usize> = BTreeSet::new(); | ||
| 1241 | - for line in include_str!("cdf_state.rs").lines() { | ||
| 1242 | - let t = line.trim(); | ||
| 1243 | - if !(t.starts_with("pub ") && t.contains("tx_type") && t.contains("[u16;")) { | ||
| 1244 | - continue; | ||
| 1245 | - } | ||
| 1246 | - let tail = t.rsplit("[u16;").next().unwrap_or(""); | ||
| 1247 | - let n: usize = tail | ||
| 1248 | - .split(']') | ||
| 1249 | - .next() | ||
| 1250 | - .unwrap_or("") | ||
| 1251 | - .trim() | ||
| 1252 | - .parse() | ||
| 1253 | - .unwrap_or_else(|_| panic!("cannot read a CDF width out of {t:?}")); | ||
| 1254 | - widths.insert(n); | ||
| 1255 | - } | ||
| 1256 | - assert!( | ||
| 1257 | - widths.len() >= 4, | ||
| 1258 | - "the cdf_state.rs scan found only {widths:?} -- it is broken, not the decoder" | ||
| 1259 | - ); | ||
| 1260 | - for &n in &widths { | ||
| 1261 | - let nsyms = n - 1; | ||
| 1262 | - let mut set: Vec<crate::transform::TxType> = Vec::new(); | ||
| 1263 | - for t in 0..nsyms { | ||
| 1264 | - let ty = crate::decode::tx_type_from_symbol(n, t).unwrap_or_else(|| { | ||
| 1265 | - panic!( | ||
| 1266 | - "a {n}-slot tx_type CDF codes symbol {t}, which maps to no transform \ | ||
| 1267 | - type -- the refusal \"a tx_type symbol outside its CDF's own set\" is \ | ||
| 1268 | - reachable, and that is a mapping-table gap to fix" | ||
| 1269 | - ) | ||
| 1270 | - }); | ||
| 1271 | - assert!( | ||
| 1272 | - !set.contains(&ty), | ||
| 1273 | - "a {n}-slot tx_type CDF maps symbol {t} to {ty:?}, which another symbol of \ | ||
| 1274 | - the same set already names -- a member of the spec's inverse table is lost" | ||
| 1275 | - ); | ||
| 1276 | - set.push(ty); | ||
| 1277 | - } | ||
| 1278 | - assert_eq!(set.len(), nsyms); | ||
| 1279 | - } | ||
| 1280 | - } | ||
| 1281 | - | ||
| 1282 | - /// The Golomb tail, enumerated over every value a conformant stream can | ||
| 1283 | - /// carry. | ||
| 1284 | - /// | ||
| 1285 | - /// Spec 5.11.40 `read_golomb` counts its unary prefix and BREAKS at | ||
| 1286 | - /// `length == 20`, then reads `length - 1` payload bits into an `x` whose | ||
| 1287 | - /// top bit is implicit -- so no conformant stream carries a value above | ||
| 1288 | - /// `(1 << 20) - 2`, and spec 5.11.39 agrees from the other side by masking | ||
| 1289 | - /// the level it feeds with `0xFFFFF`. This walks both ends of every | ||
| 1290 | - /// prefix length 1..=20 (plus the small values every real stream uses) | ||
| 1291 | - /// through [`crate::tile::write_golomb`] and back through the decoder's own | ||
| 1292 | - /// [`crate::decode::read_golomb`], so the refusal "a Golomb tail longer | ||
| 1293 | - /// than this decoder reads" is proved to sit strictly OUTSIDE the value | ||
| 1294 | - /// domain, not inside it. | ||
| 1295 | - /// | ||
| 1296 | - /// The residue is a bit pattern, not a value: the spec's break makes the | ||
| 1297 | - /// 20th prefix bit a don't-care, so a stream whose 20th prefix bit is 0 | ||
| 1298 | - /// decodes to the same value there and is refused here. libaom refuses the | ||
| 1299 | - /// same bit (`av1/decoder/decodetxb.c:30`, `AOM_CODEC_CORRUPT_FRAME` at | ||
| 1300 | - /// `length > 20`), so this refusal is NOT a reader gap to widen: when it | ||
| 1301 | - /// fires on a real stream it is an earlier desync's symptom -- see the | ||
| 1302 | - /// comment on `read_golomb`. | ||
| 1303 | - #[test] | ||
| 1304 | - fn read_golomb_reads_every_value_a_conformant_stream_can_carry() { | ||
| 1305 | - // lane-av1refusalspan: this gate is the PROOF for the refusal below, so | ||
| 1306 | - // it names it and pins its guard site. | ||
| 1307 | - const REFUSAL: &str = "a Golomb tail longer than this decoder reads"; | ||
| 1308 | - assert!( | ||
| 1309 | - super::pins_refusal(crate::test_source::module_source("decode"), REFUSAL), | ||
| 1310 | - "this gate proves {REFUSAL:?}, but that string is no longer in decode.rs" | ||
| 1311 | - ); | ||
| 1312 | - let roundtrip = |value: u32| -> ec_core::Result<u32> { | ||
| 1313 | - let mut enc = crate::msac::SymbolEncoder::new(); | ||
| 1314 | - crate::tile::write_golomb(&mut enc, value); | ||
| 1315 | - let data = enc.finish(); | ||
| 1316 | - let mut dec = crate::msac::SymbolDecoder::new(&data); | ||
| 1317 | - crate::decode::read_golomb(&mut dec) | ||
| 1318 | - }; | ||
| 1319 | - let mut values: BTreeSet<u32> = (0..=64u32).collect(); | ||
| 1320 | - for length in 1..=20u32 { | ||
| 1321 | - // `x` has `length` bits with its top bit set, and the value is | ||
| 1322 | - // `x - 1`: the two ends of what this prefix length can express. | ||
| 1323 | - values.insert((1u32 << (length - 1)) - 1); | ||
| 1324 | - values.insert(((1u64 << length) - 2) as u32); | ||
| 1325 | - } | ||
| 1326 | - let max = *values.iter().max().unwrap(); | ||
| 1327 | - assert_eq!( | ||
| 1328 | - max, | ||
| 1329 | - (1u32 << 20) - 2, | ||
| 1330 | - "the enumeration misses the spec's own ceiling" | ||
| 1331 | - ); | ||
| 1332 | - // A coefficient is masked to 20 bits (spec 5.11.39), and the base and | ||
| 1333 | - // base-range syntax contribute at most 15 of that before the tail, so | ||
| 1334 | - // this is the largest tail a legal coefficient can need. | ||
| 1335 | - assert!( | ||
| 1336 | - max >= 0xF_FFFF - 15, | ||
| 1337 | - "the ceiling is below the largest legal tail" | ||
| 1338 | - ); | ||
| 1339 | - for value in values { | ||
| 1340 | - match roundtrip(value) { | ||
| 1341 | - Ok(read) => assert_eq!(read, value, "the Golomb tail {value} read back as {read}"), | ||
| 1342 | - Err(e) => panic!( | ||
| 1343 | - "the Golomb tail {value} is inside the domain spec 5.11.40 can write but \ | ||
| 1344 | - this decoder refuses it: {e}" | ||
| 1345 | - ), | ||
| 1346 | - } | ||
| 1347 | - } | ||
| 1348 | - // And the refusal still names something: 20 zero prefix bits. | ||
| 1349 | - let mut enc = crate::msac::SymbolEncoder::new(); | ||
| 1350 | - for _ in 0..20 { | ||
| 1351 | - enc.literal(0, 1); | ||
| 1352 | - } | ||
| 1353 | - for _ in 0..20 { | ||
| 1354 | - enc.literal(1, 1); | ||
| 1355 | - } | ||
| 1356 | - let data = enc.finish(); | ||
| 1357 | - let mut dec = crate::msac::SymbolDecoder::new(&data); | ||
| 1358 | - assert!( | ||
| 1359 | - crate::decode::read_golomb(&mut dec).is_err(), | ||
| 1360 | - "the Golomb refusal is dead code -- drop it from the inventory" | ||
| 1361 | - ); | ||
| 1362 | - } | ||
| 1363 | - | ||
| 1364 | - /// The intra-mode alphabet, enumerated against the guard that refuses a | ||
| 1365 | - /// symbol outside it. | ||
| 1366 | - /// | ||
| 1367 | - /// Three readers -- the rect-in-inter arm, the intra-in-inter square arm | ||
| 1368 | - /// and the 8x8 leaf -- read a y_mode symbol and refuse `mode >= 13` with | ||
| 1369 | - /// "an intra mode this decoder does not code (round 2)". A `y_mode` symbol | ||
| 1370 | - /// comes from `Cdfs::y_mode[size_group]`, whose alphabet is | ||
| 1371 | - /// `Y_MODE[g].len() - 1` (the last slot is the adaptation counter), and | ||
| 1372 | - /// `SymbolDecoder::symbol` cannot return a value outside `0..nsyms` -- so | ||
| 1373 | - /// the guard is unreachable exactly when every size group's alphabet is at | ||
| 1374 | - /// most the threshold. | ||
| 1375 | - /// | ||
| 1376 | - /// Found by the refusal in the guard's own body rather than by line | ||
| 1377 | - /// number, and the CDF the symbol was read from is checked too: a | ||
| 1378 | - /// threshold of 13 over a 14-symbol table would be a live refusal, and a | ||
| 1379 | - /// site reading a WIDER alphabet (`uv_mode` with CfL is 14) under the same | ||
| 1380 | - /// guard would be one as well. | ||
| 1381 | - #[test] | ||
| 1382 | - fn every_intra_mode_symbol_of_the_y_mode_alphabet_is_coded() { | ||
| 1383 | - const REFUSAL: &str = "an intra mode this decoder does not code (round 2)"; | ||
| 1384 | - // Both uv_mode alphabets are listed so the CfL-allowed one (14 | ||
| 1385 | - // symbols, `UV_MODE_CFL_ALLOWED`) cannot silently become the source of | ||
| 1386 | - // a symbol tested against 13. | ||
| 1387 | - let alphabets: [(&str, usize); 3] = [ | ||
| 1388 | - ("y_mode", crate::cdf::Y_MODE[0].len() - 1), | ||
| 1389 | - ("uv_mode_no_cfl", crate::cdf::UV_MODE_NO_CFL[0].len() - 1), | ||
| 1390 | - ("uv_mode_cfl", crate::cdf::UV_MODE_CFL[0].len() - 1), | ||
| 1391 | - ]; | ||
| 1392 | - assert_eq!(alphabets[0].1, 13, "the y_mode alphabet changed size"); | ||
| 1393 | - for group in &crate::cdf::Y_MODE { | ||
| 1394 | - assert_eq!( | ||
| 1395 | - group.len() - 1, | ||
| 1396 | - alphabets[0].1, | ||
| 1397 | - "the y_mode rows disagree on width" | ||
| 1398 | - ); | ||
| 1399 | - } | ||
| 1400 | - | ||
| 1401 | - let src = crate::test_source::module_source("decode"); | ||
| 1402 | - let lines: Vec<&str> = src.lines().collect(); | ||
| 1403 | - let mut sites = 0usize; | ||
| 1404 | - for (i, line) in lines.iter().enumerate() { | ||
| 1405 | - let t = line.trim(); | ||
| 1406 | - let Some(rest) = t.strip_prefix("if mode >= ") else { | ||
| 1407 | - continue; | ||
| 1408 | - }; | ||
| 1409 | - let Some(threshold) = rest.trim_end_matches(" {").parse::<usize>().ok() else { | ||
| 1410 | - continue; | ||
| 1411 | - }; | ||
| 1412 | - // Only the guards carrying THIS refusal. | ||
| 1413 | - if !lines[i..(i + 4).min(lines.len())] | ||
| 1414 | - .join("\n") | ||
| 1415 | - .contains(REFUSAL) | ||
| 1416 | - { | ||
| 1417 | - continue; | ||
| 1418 | - } | ||
| 1419 | - sites += 1; | ||
| 1420 | - // The symbol's own CDF: the nearest `dec.symbol(&mut cdfs.X[..])` | ||
| 1421 | - // above the guard. | ||
| 1422 | - let read = lines[i.saturating_sub(12)..i] | ||
| 1423 | - .iter() | ||
| 1424 | - .rev() | ||
| 1425 | - .find(|l| l.contains("dec.symbol(&mut cdfs.")) | ||
| 1426 | - .unwrap_or_else(|| panic!("line {}: no symbol read above the guard", i + 1)); | ||
| 1427 | - let table = read | ||
| 1428 | - .split("dec.symbol(&mut cdfs.") | ||
| 1429 | - .nth(1) | ||
| 1430 | - .unwrap() | ||
| 1431 | - .split('[') | ||
| 1432 | - .next() | ||
| 1433 | - .unwrap(); | ||
| 1434 | - let (name, nsyms) = alphabets | ||
| 1435 | - .iter() | ||
| 1436 | - .find(|(n, _)| *n == table) | ||
| 1437 | - .unwrap_or_else(|| panic!("line {}: unknown mode alphabet {table:?}", i + 1)); | ||
| 1438 | - assert!( | ||
| 1439 | - *nsyms <= threshold, | ||
| 1440 | - "line {}: the guard refuses mode >= {threshold} on a symbol read from a \ | ||
| 1441 | - {nsyms}-symbol {name} CDF -- symbol {threshold} is inside that alphabet, so \ | ||
| 1442 | - the refusal is live and this enumeration does not prove it", | ||
| 1443 | - i + 1 | ||
| 1444 | - ); | ||
| 1445 | - } | ||
| 1446 | - assert_eq!( | ||
| 1447 | - sites, 3, | ||
| 1448 | - "the intra-mode guard is at three sites, found {sites}" | ||
| 1449 | - ); | ||
| 1450 | - } | ||
| 1451 | - | ||
| 1452 | - /// lane-t900 r31, ENUMERATION for "a HORZ/VERT intra strip in a | ||
| 1453 | - /// screen-content frame (palette syntax is consumed for square blocks | ||
| 1454 | - /// only)". | ||
| 1455 | - /// | ||
| 1456 | - /// That refusal guards the 128-root HORZ/VERT arm of the intra-in-inter | ||
| 1457 | - /// path (`decode.rs`, the `bw.max(bh) == 128` branch): the body it calls, | ||
| 1458 | - /// `decode_block_128rect`, reads no palette syntax, so a screen-content | ||
| 1459 | - /// frame was assumed to code some there. It cannot. `av1_allow_palette` | ||
| 1460 | - /// (spec 5.11.46 `read_palette_mode_info`: `bsize` between `BLOCK_8X8` | ||
| 1461 | - /// and `BLOCK_64X64` by side) is what this decoder mirrors in | ||
| 1462 | - /// `palette_bsize_ctx_wh`, whose bound is `bw > 64 || bh > 64 || | ||
| 1463 | - /// bw * bh < 64`. Every footprint with a 128-pixel side fails it, so the | ||
| 1464 | - /// screen flag changes NOTHING a 128-root half codes -- the refusal's | ||
| 1465 | - /// stated premise is false, and the string is a claim about the SYNTAX | ||
| 1466 | - /// (provable, and disproved here) rather than about libaom. | ||
| 1467 | - /// | ||
| 1468 | - /// It is deliberately NOT registered in [`PROVEN`]: the guarded condition | ||
| 1469 | - /// is still reachable (a screen frame CAN code a 128-root half), so this | ||
| 1470 | - /// test proves the LIFT is safe, not that the case never happens. Lifting | ||
| 1471 | - /// it is a `decode.rs` edit plus a witness stream, and no `--sb-size=128 | ||
| 1472 | - /// --tune-content=screen` encode found so far codes a 128-root half at all | ||
| 1473 | - /// (lane-t900 r23's census). | ||
| 1474 | - /// | ||
| 1475 | - /// The bound is asserted against `decode.rs`'s own source rather than a | ||
| 1476 | - /// copy of it here, so a change to the predicate breaks this test rather | ||
| 1477 | - /// than silently invalidating it (class `table-and-reader-move-together`). | ||
| 1478 | - #[test] | ||
| 1479 | - fn no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax() { | ||
| 1480 | - const BOUND: &str = "if bw > 64 || bh > 64 || bw * bh < 64 {"; | ||
| 1481 | - let src = crate::test_source::module_source("decode"); | ||
| 1482 | - assert!( | ||
| 1483 | - src.contains("fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> {"), | ||
| 1484 | - "palette_bsize_ctx_wh is gone -- this enumeration no longer names the predicate \ | ||
| 1485 | - the decoder gates every palette read on" | ||
| 1486 | - ); | ||
| 1487 | - assert_eq!( | ||
| 1488 | - src.matches(BOUND).count(), | ||
| 1489 | - 1, | ||
| 1490 | - "av1_allow_palette's size bound is no longer spelled {BOUND:?} exactly once in \ | ||
| 1491 | - decode.rs -- re-derive this enumeration from the new spelling" | ||
| 1492 | - ); | ||
| 1493 | - // `palette_bsize_ctx_wh`'s own bound, applied to every AV1 block | ||
| 1494 | - // footprint (both sides a power of two from 4 to 128). | ||
| 1495 | - let allows_palette = |bw: usize, bh: usize| !(bw > 64 || bh > 64 || bw * bh < 64); | ||
| 1496 | - let (mut with_128, mut allowed_at_128) = (0u32, 0u32); | ||
| 1497 | - for wl in 2..=7u32 { | ||
| 1498 | - for hl in 2..=7u32 { | ||
| 1499 | - let (bw, bh) = (1usize << wl, 1usize << hl); | ||
| 1500 | - if bw.max(bh) != 128 { | ||
| 1501 | - continue; | ||
| 1502 | - } | ||
| 1503 | - with_128 += 1; | ||
| 1504 | - if allows_palette(bw, bh) { | ||
| 1505 | - allowed_at_128 += 1; | ||
| 1506 | - } | ||
| 1507 | - } | ||
| 1508 | - } | ||
| 1509 | - assert!( | ||
| 1510 | - with_128 > 0, | ||
| 1511 | - "enumeration is vacuous -- no 128-sided footprint was tried" | ||
| 1512 | - ); | ||
| 1513 | - assert_eq!( | ||
| 1514 | - allowed_at_128, 0, | ||
| 1515 | - "a footprint with a 128-pixel side passed av1_allow_palette's bound -- the \ | ||
| 1516 | - 128-root HORZ/VERT arm really would have to read palette syntax" | ||
| 1517 | - ); | ||
| 1518 | - // And the guarded shapes specifically: the two 128-root HORZ/VERT | ||
| 1519 | - // halves the refusal names. | ||
| 1520 | - for (bw, bh) in [(128usize, 64usize), (64, 128)] { | ||
| 1521 | - assert!( | ||
| 1522 | - !allows_palette(bw, bh), | ||
| 1523 | - "a {bw}x{bh} half can carry a palette after all" | ||
| 1524 | - ); | ||
| 1525 | - } | ||
| 1526 | - } | ||
| 1527 | - | ||
| 1528 | - /// lane-t900 r33, ENUMERATION for the two [`decode_rect_split`] refusals | ||
| 1529 | - /// ("a coded HORZ/VERT strip whose chroma transform has no rect | ||
| 1530 | - /// coefficient tables here" and "a split intra strip whose transform unit | ||
| 1531 | - /// is {tx_w}x{tx_h}"). | ||
| 1532 | - /// | ||
| 1533 | - /// Both guard shape lookups inside one function, so the proof is one | ||
| 1534 | - /// enumeration: the footprints that function is CALLED with, walked | ||
| 1535 | - /// through `depth_to_tx_wh` at every depth, against the two `match` | ||
| 1536 | - /// tables read out of `decode.rs` itself (class | ||
| 1537 | - /// `table-and-reader-move-together` -- a table edit invalidates this test | ||
| 1538 | - /// rather than sneaking past it). | ||
| 1539 | - /// | ||
| 1540 | - /// The footprint domain is the five callers' own: `decode_block_rect` | ||
| 1541 | - /// (32-level 2:1), `decode_block_rect4` (32-level 1:4), `decode_leaf_rect` | ||
| 1542 | - /// (16-level 2:1), `decode_block_rect64` (64-level 2:1 and 1:4) and | ||
| 1543 | - /// `decode_intra_rect_in_inter`, whose reachable shapes are the ten | ||
| 1544 | - /// rectangular census shapes with `8 <= min` and `max <= 64` (already | ||
| 1545 | - /// pinned by `every_intra_in_inter_shape_the_census_lists_has_a_size_group_row`). | ||
| 1546 | - /// The two shape classes that would MISS a table -- a 128-sided half | ||
| 1547 | - /// (chroma 64x32) and a sub-8 strip (16x4 -> chroma 8x2) -- are excluded | ||
| 1548 | - /// structurally: their readers, `decode_block_128rect` and | ||
| 1549 | - /// `decode_rect4_16_strip`, are not among the callers, which this test | ||
| 1550 | - /// asserts by locating every `decode_rect_split(` call in its enclosing | ||
| 1551 | - /// function. | ||
| 1552 | - #[test] | ||
| 1553 | - fn every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table() { | ||
| 1554 | - let src = crate::test_source::module_source("decode"); | ||
| 1555 | - // lane-av1refusalspan: this gate is the PROOF for both refusals below, | ||
| 1556 | - // so it names both and pins both guard sites. | ||
| 1557 | - for refusal in [ | ||
| 1558 | - "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | ||
| 1559 | - "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | ||
| 1560 | - ] { | ||
| 1561 | - assert!( | ||
| 1562 | - super::pins_refusal(src, refusal), | ||
| 1563 | - "this gate proves {refusal:?}, but that string is no longer in decode.rs" | ||
| 1564 | - ); | ||
| 1565 | - } | ||
| 1566 | - | ||
| 1567 | - // (1) The caller set. Each call's enclosing function is the last | ||
| 1568 | - // top-level `fn` before it. | ||
| 1569 | - let fn_starts: Vec<(usize, String)> = src | ||
| 1570 | - .match_indices("\nfn ") | ||
| 1571 | - .map(|(i, _)| { | ||
| 1572 | - let rest = &src[i + 4..]; | ||
| 1573 | - let name = rest[..rest.find('(').unwrap_or(0)].to_string(); | ||
| 1574 | - (i, name) | ||
| 1575 | - }) | ||
| 1576 | - .collect(); | ||
| 1577 | - let mut callers: BTreeSet<String> = BTreeSet::new(); | ||
| 1578 | - for (at, _) in src.match_indices("decode_rect_split(") { | ||
| 1579 | - let enclosing = fn_starts | ||
| 1580 | - .iter().rfind(|(i, _)| *i < at) | ||
| 1581 | - .expect("a decode_rect_split call outside any function"); | ||
| 1582 | - if enclosing.1 != "decode_rect_split" { | ||
| 1583 | - callers.insert(enclosing.1.clone()); | ||
| 1584 | - } | ||
| 1585 | - } | ||
| 1586 | - let expected: BTreeSet<String> = [ | ||
| 1587 | - "decode_block_rect", | ||
| 1588 | - "decode_block_rect4", | ||
| 1589 | - "decode_block_rect64", | ||
| 1590 | - "decode_intra_rect_in_inter", | ||
| 1591 | - "decode_leaf_rect", | ||
| 1592 | - ] | ||
| 1593 | - .iter() | ||
| 1594 | - .map(|s| s.to_string()) | ||
| 1595 | - .collect(); | ||
| 1596 | - assert_eq!( | ||
| 1597 | - callers, expected, | ||
| 1598 | - "the set of functions that call decode_rect_split changed -- re-derive the \ | ||
| 1599 | - footprint domain below from the new caller (a 128-sided or sub-8 caller makes \ | ||
| 1600 | - both refusals live)" | ||
| 1601 | - ); | ||
| 1602 | - | ||
| 1603 | - // (2) The walk, asserted against its own source before it is applied. | ||
| 1604 | - const WALK: &str = " let (mut w, mut h) = (bw.min(64), bh.min(64));\n \ | ||
| 1605 | - for _ in 0..depth {\n match w.cmp(&h) {\n \ | ||
| 1606 | - std::cmp::Ordering::Greater => w /= 2,\n \ | ||
| 1607 | - std::cmp::Ordering::Less => h /= 2,\n \ | ||
| 1608 | - std::cmp::Ordering::Equal => {\n w /= 2;\n \ | ||
| 1609 | - h /= 2;\n }\n }\n }"; | ||
| 1610 | - assert_eq!( | ||
| 1611 | - src.matches(WALK).count(), | ||
| 1612 | - 1, | ||
| 1613 | - "depth_to_tx_wh's walk is no longer spelled the way this enumeration mirrors it" | ||
| 1614 | - ); | ||
| 1615 | - let depth_to_tx_wh = |bw: usize, bh: usize, depth: usize| { | ||
| 1616 | - let (mut w, mut h) = (bw.min(64), bh.min(64)); | ||
| 1617 | - for _ in 0..depth { | ||
| 1618 | - match w.cmp(&h) { | ||
| 1619 | - std::cmp::Ordering::Greater => w /= 2, | ||
| 1620 | - std::cmp::Ordering::Less => h /= 2, | ||
| 1621 | - std::cmp::Ordering::Equal => { | ||
| 1622 | - w /= 2; | ||
| 1623 | - h /= 2; | ||
| 1624 | - } | ||
| 1625 | - } | ||
| 1626 | - } | ||
| 1627 | - (w, h) | ||
| 1628 | - }; | ||
| 1629 | - | ||
| 1630 | - // (3) The two tables, read out of decode_rect_split's own text: every | ||
| 1631 | - // `(w, h) =>` / `(w, h) |` match arm head between the table's `let` | ||
| 1632 | - // and the guard that follows it. | ||
| 1633 | - let body_at = src | ||
| 1634 | - .find("fn decode_rect_split(") | ||
| 1635 | - .expect("decode_rect_split is gone"); | ||
| 1636 | - let body = &src[body_at..]; | ||
| 1637 | - let slice = |from: &str, to: &str| -> &str { | ||
| 1638 | - let a = body | ||
| 1639 | - .find(from) | ||
| 1640 | - .unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split")); | ||
| 1641 | - let b = body[a..] | ||
| 1642 | - .find(to) | ||
| 1643 | - .unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split")); | ||
| 1644 | - &body[a..a + b] | ||
| 1645 | - }; | ||
| 1646 | - let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> { | ||
| 1647 | - let mut out = BTreeSet::new(); | ||
| 1648 | - let bytes = text.as_bytes(); | ||
| 1649 | - for (i, _) in text.match_indices('(') { | ||
| 1650 | - let mut j = i + 1; | ||
| 1651 | - let mut w = 0usize; | ||
| 1652 | - while j < bytes.len() && bytes[j].is_ascii_digit() { | ||
| 1653 | - w = w * 10 + usize::from(bytes[j] - b'0'); | ||
| 1654 | - j += 1; | ||
| 1655 | - } | ||
| 1656 | - if j == i + 1 || !text[j..].starts_with(", ") { | ||
| 1657 | - continue; | ||
| 1658 | - } | ||
| 1659 | - j += 2; | ||
| 1660 | - let mut h = 0usize; | ||
| 1661 | - let start_h = j; | ||
| 1662 | - while j < bytes.len() && bytes[j].is_ascii_digit() { | ||
| 1663 | - h = h * 10 + usize::from(bytes[j] - b'0'); | ||
| 1664 | - j += 1; | ||
| 1665 | - } | ||
| 1666 | - if j == start_h || !text[j..].starts_with(')') { | ||
| 1667 | - continue; | ||
| 1668 | - } | ||
| 1669 | - // Only an arm HEAD counts, never a `(32, 8)` inside prose. | ||
| 1670 | - let after = text[j + 1..].trim_start(); | ||
| 1671 | - if after.starts_with("=>") || after.starts_with('|') { | ||
| 1672 | - out.insert((w, h)); | ||
| 1673 | - } | ||
| 1674 | - } | ||
| 1675 | - out | ||
| 1676 | - }; | ||
| 1677 | - let chroma = arm_shapes(slice("let chroma: Option<(TxbSet", "if !m.skip {")); | ||
| 1678 | - let luma = arm_shapes(slice("let luma_rect: Option<(TxbSet", "no luma \\")); | ||
| 1679 | - assert!( | ||
| 1680 | - chroma.len() >= 6 && luma.len() >= 6, | ||
| 1681 | - "the tables parsed to {} chroma / {} luma shapes -- the parse, not the decoder, \ | ||
| 1682 | - is what this would be measuring", | ||
| 1683 | - chroma.len(), | ||
| 1684 | - luma.len() | ||
| 1685 | - ); | ||
| 1686 | - | ||
| 1687 | - // (4) The enumeration itself. | ||
| 1688 | - let mut checked = 0u32; | ||
| 1689 | - for wl in 3..=6u32 { | ||
| 1690 | - for hl in 3..=6u32 { | ||
| 1691 | - let (bw, bh) = (1usize << wl, 1usize << hl); | ||
| 1692 | - let ratio = bw.max(bh) / bw.min(bh); | ||
| 1693 | - if ratio != 2 && ratio != 4 { | ||
| 1694 | - continue; | ||
| 1695 | - } | ||
| 1696 | - assert!( | ||
| 1697 | - chroma.contains(&(bw / 2, bh / 2)), | ||
| 1698 | - "a {bw}x{bh} strip's {}x{} chroma transform has no rect table -- the \ | ||
| 1699 | - chroma refusal is LIVE for a shape a caller codes", | ||
| 1700 | - bw / 2, | ||
| 1701 | - bh / 2 | ||
| 1702 | - ); | ||
| 1703 | - // Every depth: once the walk reaches a square it stays square, | ||
| 1704 | - // so this covers any tx_depth a header can code. | ||
| 1705 | - for depth in 1..=4 { | ||
| 1706 | - let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); | ||
| 1707 | - assert!( | ||
| 1708 | - tx_w == tx_h || luma.contains(&(tx_w, tx_h)), | ||
| 1709 | - "a {bw}x{bh} strip at depth {depth} resolves to a {tx_w}x{tx_h} \ | ||
| 1710 | - transform unit, which has no luma arm -- that refusal is LIVE" | ||
| 1711 | - ); | ||
| 1712 | - checked += 1; | ||
| 1713 | - } | ||
| 1714 | - } | ||
| 1715 | - } | ||
| 1716 | - assert_eq!( | ||
| 1717 | - checked, 40, | ||
| 1718 | - "the strip domain is not the ten rect shapes x four depths" | ||
| 1719 | - ); | ||
| 1720 | - } | ||
| 1721 | - | ||
| 1722 | - /// lane-av1rect8x16, ENUMERATION for "a rectangular chroma transform | ||
| 1723 | - /// whose size has no coefficient table" -- | ||
| 1724 | - /// [`crate::decode::decode_block_rect`]'s `_` arm. | ||
| 1725 | - /// | ||
| 1726 | - /// This refusal had NO `PROVEN` row: the sibling sweep that found the | ||
| 1727 | - /// gap (`every_rect_strip_shape_the_split_path_codes_has_a_luma_and_ | ||
| 1728 | - /// chroma_table`, which audits `decode_rect_split`'s tables, not this | ||
| 1729 | - /// function's) asserted only the superblock-level 64x32/32x64 | ||
| 1730 | - /// footprints, so the 8x16 luma strip's 4x8 chroma was left unasked. | ||
| 1731 | - /// | ||
| 1732 | - /// The answer is that the shape is UNREACHABLE, and structurally so: | ||
| 1733 | - /// every one of the function's call sites passes its `bw`/`bh` as | ||
| 1734 | - /// integer LITERALS, and all of them are 32-level `PARTITION_HORZ` / | ||
| 1735 | - /// `VERT` / `HORZ_A` / `HORZ_B` / `VERT_A` / `VERT_B` arms of | ||
| 1736 | - /// `read_sb128_root`'s `match part32` -- i.e. 32x16 or 16x32, never | ||
| 1737 | - /// 8x16. A 16-level 2:1 luma strip (16x8 / 8x16) is read by | ||
| 1738 | - /// [`crate::decode::decode_leaf_rect`], which carries the matching | ||
| 1739 | - /// `(4, 8)` / `(8, 4)` chroma rows (decode.rs:15409-15420, | ||
| 1740 | - /// `TxbSet::ChromaRect8x4` + `SCAN_4X8` / `SCAN_8X4`). | ||
| 1741 | - /// | ||
| 1742 | - /// So the proof is the CALLER SHAPE SET, read out of the call sites' | ||
| 1743 | - /// own argument lists, walked through `bw >> ss_x` / `bh >> ss_y` for | ||
| 1744 | - /// every subsampling an AV1 `color_config` can carry, against the | ||
| 1745 | - /// `match (chroma_w, chroma_h)` table read out of the function's own | ||
| 1746 | - /// text (class `table-and-reader-move-together`: a table edit | ||
| 1747 | - /// invalidates this test rather than sneaking past it). | ||
| 1748 | - /// | ||
| 1749 | - /// The subsampling domain is `{(0,0), (1,0), (1,1)}` and excludes | ||
| 1750 | - /// `(0,1)`: `ec-av1-syntax`'s `color_config` only ever READS | ||
| 1751 | - /// `subsampling_y` when `subsampling_x == 1` (sequence.rs:481), so | ||
| 1752 | - /// `(0,1)` is uncodable. `(1,0)` is 4:2:2. It is walked because that is | ||
| 1753 | - /// the codable domain, NOT because a guard stands in the way: as of | ||
| 1754 | - /// lane-av1422lift the sequence header no longer refuses 4:2:2 at all, so | ||
| 1755 | - /// the sentence this replaces ("refused at the sequence header by | ||
| 1756 | - /// `a_non_420_subsampled_sequence_header_is_refused_by_name`") names a | ||
| 1757 | - /// gate that no longer exists. The walk was already right; its stated | ||
| 1758 | - /// reason was not. | ||
| 1759 | - #[test] | ||
| 1760 | - fn every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table() { | ||
| 1761 | - let src = crate::test_source::module_source("decode"); | ||
| 1762 | - | ||
| 1763 | - // (1) The caller shape set, read out of the call sites' own | ||
| 1764 | - // argument lists. `decode_block_rect(dec, cdfs, neighbours, at, bw, | ||
| 1765 | - // bh, ...)`, so args 4 and 5 (0-based, after the opening paren) are | ||
| 1766 | - // `bw` and `bh`; the first three are the fixed `&mut` borrows. | ||
| 1767 | - const LEAD: [&str; 3] = ["&mut dec", "&mut cdfs", "&mut neighbours"]; | ||
| 1768 | - let mut shapes: BTreeSet<(usize, usize)> = BTreeSet::new(); | ||
| 1769 | - let mut sites = 0usize; | ||
| 1770 | - let at_def = src | ||
| 1771 | - .find("fn decode_block_rect(") | ||
| 1772 | - .expect("decode_block_rect is gone"); | ||
| 1773 | - for (i, _) in src.match_indices("decode_block_rect(") { | ||
| 1774 | - // The definition's own parameter list carries the same text, | ||
| 1775 | - // preceded by "fn " -- that is a declaration, not a call. | ||
| 1776 | - if src[..i].ends_with("fn ") { | ||
| 1777 | - continue; | ||
| 1778 | - } | ||
| 1779 | - // Split the argument list at top level (paren/bracket/angle | ||
| 1780 | - // balanced), so the `(at32.0 + 1, at32.1)` origin argument -- | ||
| 1781 | - // which contains its own comma -- does not shift the indices. | ||
| 1782 | - let open = i + "decode_block_rect(".len(); | ||
| 1783 | - let bytes = src.as_bytes(); | ||
| 1784 | - let mut args: Vec<String> = Vec::new(); | ||
| 1785 | - let mut depth = 0i32; | ||
| 1786 | - let mut start = open; | ||
| 1787 | - for j in open..bytes.len() { | ||
| 1788 | - match bytes[j] { | ||
| 1789 | - b'(' | b'[' => depth += 1, | ||
| 1790 | - b')' | b']' => { | ||
| 1791 | - if depth == 0 { | ||
| 1792 | - args.push(src[start..j].to_string()); | ||
| 1793 | - break; | ||
| 1794 | - } | ||
| 1795 | - depth -= 1; | ||
| 1796 | - } | ||
| 1797 | - b',' if depth == 0 => { | ||
| 1798 | - args.push(src[start..j].to_string()); | ||
| 1799 | - start = j + 1; | ||
| 1800 | - } | ||
| 1801 | - _ => {} | ||
| 1802 | - } | ||
| 1803 | - } | ||
| 1804 | - assert!( | ||
| 1805 | - args.len() >= 6, | ||
| 1806 | - "a decode_block_rect call has only {} arguments -- the arg indices this \ | ||
| 1807 | - enumeration reads are off", | ||
| 1808 | - args.len() | ||
| 1809 | - ); | ||
| 1810 | - for k in 0..3 { | ||
| 1811 | - assert_eq!( | ||
| 1812 | - args[k].trim(), | ||
| 1813 | - LEAD[k], | ||
| 1814 | - "decode_block_rect's first three arguments changed -- re-derive the bw/bh \ | ||
| 1815 | - argument indices below" | ||
| 1816 | - ); | ||
| 1817 | - } | ||
| 1818 | - let lit = |a: &str| -> usize { | ||
| 1819 | - a.trim().parse::<usize>().unwrap_or_else(|_| { | ||
| 1820 | - panic!( | ||
| 1821 | - "decode_block_rect is called with a non-literal strip size {:?} -- \ | ||
| 1822 | - this enumeration can no longer read the caller shape set", | ||
| 1823 | - a.trim() | ||
| 1824 | - ) | ||
| 1825 | - }) | ||
| 1826 | - }; | ||
| 1827 | - shapes.insert((lit(&args[4]), lit(&args[5]))); | ||
| 1828 | - sites += 1; | ||
| 1829 | - } | ||
| 1830 | - assert_eq!( | ||
| 1831 | - sites, 8, | ||
| 1832 | - "the number of decode_block_rect call sites changed" | ||
| 1833 | - ); | ||
| 1834 | - let expected_shapes: BTreeSet<(usize, usize)> = | ||
| 1835 | - [(32usize, 16usize), (16, 32)].into_iter().collect(); | ||
| 1836 | - assert_eq!( | ||
| 1837 | - shapes, expected_shapes, | ||
| 1838 | - "the set of strip sizes decode_block_rect is called with changed -- re-derive \ | ||
| 1839 | - the chroma domain below. An 8x16/16x8 caller makes this refusal LIVE (a \ | ||
| 1840 | - 4:2:0 8x16 luma strip's chroma is 4x8, which libaom codes as TX_4X8: \ | ||
| 1841 | - av1_ss_size_lookup[BLOCK_8X16][1][1] = BLOCK_4X8 in \ | ||
| 1842 | - av1/common/common_data.c:24, then max_txsize_rect_lookup[BLOCK_4X8] = TX_4X8 \ | ||
| 1843 | - in av1/common/common_data.h:130, via av1_get_max_uv_txsize, blockd.h:1372)" | ||
| 1844 | - ); | ||
| 1845 | - | ||
| 1846 | - // (2) The table, read out of the function's own text: every | ||
| 1847 | - // `(w, h) =>` / `(w, h) |` arm head between the match and the guard. | ||
| 1848 | - let body_at = at_def; | ||
| 1849 | - let rest = &src[body_at..]; | ||
| 1850 | - let body = &rest[..rest.find("\nfn ").expect("unterminated fn")]; | ||
| 1851 | - let from = body | ||
| 1852 | - .find("let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h)") | ||
| 1853 | - .expect("decode_block_rect's chroma match is gone"); | ||
| 1854 | - let to = body[from..] | ||
| 1855 | - .find("a rectangular chroma transform whose size has no coefficient table") | ||
| 1856 | - .expect("the refusal string is gone from decode_block_rect") | ||
| 1857 | - + from; | ||
| 1858 | - let table = &body[from..to]; | ||
| 1859 | - let mut arms: BTreeSet<(usize, usize)> = BTreeSet::new(); | ||
| 1860 | - let bytes = table.as_bytes(); | ||
| 1861 | - for (i, _) in table.match_indices('(') { | ||
| 1862 | - let mut j = i + 1; | ||
| 1863 | - let mut w = 0usize; | ||
| 1864 | - while j < bytes.len() && bytes[j].is_ascii_digit() { | ||
| 1865 | - w = w * 10 + usize::from(bytes[j] - b'0'); | ||
| 1866 | - j += 1; | ||
| 1867 | - } | ||
| 1868 | - if j == i + 1 || !table[j..].starts_with(", ") { | ||
| 1869 | - continue; | ||
| 1870 | - } | ||
| 1871 | - j += 2; | ||
| 1872 | - let mut h = 0usize; | ||
| 1873 | - let start_h = j; | ||
| 1874 | - while j < bytes.len() && bytes[j].is_ascii_digit() { | ||
| 1875 | - h = h * 10 + usize::from(bytes[j] - b'0'); | ||
| 1876 | - j += 1; | ||
| 1877 | - } | ||
| 1878 | - if j == start_h || !table[j..].starts_with(')') { | ||
| 1879 | - continue; | ||
| 1880 | - } | ||
| 1881 | - // Only an arm HEAD counts, never a `(32, 8)` inside prose. | ||
| 1882 | - let after = table[j + 1..].trim_start(); | ||
| 1883 | - if after.starts_with("=>") || after.starts_with('|') { | ||
| 1884 | - arms.insert((w, h)); | ||
| 1885 | - } | ||
| 1886 | - } | ||
| 1887 | - // (3) The enumeration itself -- run BEFORE the exact-table pin below | ||
| 1888 | - // so a deleted arm fails HERE, naming the footprint, instead of | ||
| 1889 | - // behind a vaguer "the table changed". | ||
| 1890 | - let mut checked = 0u32; | ||
| 1891 | - for &(bw, bh) in &shapes { | ||
| 1892 | - for (ss_x, ss_y) in [(0usize, 0usize), (1, 0), (1, 1)] { | ||
| 1893 | - let (cw, ch) = (bw >> ss_x, bh >> ss_y); | ||
| 1894 | - assert!( | ||
| 1895 | - arms.contains(&(cw, ch)), | ||
| 1896 | - "a {bw}x{bh} strip at subsampling ({ss_x},{ss_y}) has a {cw}x{ch} chroma \ | ||
| 1897 | - transform with no coefficient table -- the chroma refusal is LIVE" | ||
| 1898 | - ); | ||
| 1899 | - checked += 1; | ||
| 1900 | - } | ||
| 1901 | - } | ||
| 1902 | - assert_eq!( | ||
| 1903 | - checked, 6, | ||
| 1904 | - "the chroma domain is not two shapes x three formats" | ||
| 1905 | - ); | ||
| 1906 | - | ||
| 1907 | - // (4) And the table is EXACTLY those six rows -- no row is a shape no | ||
| 1908 | - // caller can present, which is what makes the `_` arm dead. | ||
| 1909 | - assert_eq!( | ||
| 1910 | - arms, | ||
| 1911 | - [ | ||
| 1912 | - (8usize, 16usize), | ||
| 1913 | - (8, 32), | ||
| 1914 | - (16, 8), | ||
| 1915 | - (16, 16), | ||
| 1916 | - (16, 32), | ||
| 1917 | - (32, 16) | ||
| 1918 | - ] | ||
| 1919 | - .into_iter() | ||
| 1920 | - .collect::<BTreeSet<(usize, usize)>>(), | ||
| 1921 | - "decode_block_rect's chroma table changed -- re-derive the walk above" | ||
| 1922 | - ); | ||
| 1923 | - | ||
| 1924 | - // (5) The residual, stated as an assertion so it cannot rot: the two | ||
| 1925 | - // 4:2:0 rows an 8x16/16x8 luma strip would need are NOT in this | ||
| 1926 | - // table, and (4,8)/(8,4) is not a shape any caller can produce. If a | ||
| 1927 | - // future caller hands this function an 8x16, step (1) goes red | ||
| 1928 | - // first, and the new row has to be added here with it. | ||
| 1929 | - for residual in [(4usize, 8usize), (8, 4)] { | ||
| 1930 | - assert!( | ||
| 1931 | - !arms.contains(&residual), | ||
| 1932 | - "decode_block_rect grew a {0}x{1} chroma row -- update the residual note", | ||
| 1933 | - residual.0, | ||
| 1934 | - residual.1 | ||
| 1935 | - ); | ||
| 1936 | - } | ||
| 1937 | - let produces: BTreeSet<(usize, usize)> = shapes | ||
| 1938 | - .iter() | ||
| 1939 | - .flat_map(|&(bw, bh)| { | ||
| 1940 | - [(0usize, 0usize), (1, 0), (1, 1)] | ||
| 1941 | - .into_iter() | ||
| 1942 | - .map(move |(sx, sy)| (bw >> sx, bh >> sy)) | ||
| 1943 | - }) | ||
| 1944 | - .collect(); | ||
| 1945 | - assert!( | ||
| 1946 | - !produces.contains(&(4, 8)) && !produces.contains(&(8, 4)), | ||
| 1947 | - "the caller set can now produce a 4x8/8x4 chroma shape but the table has no \ | ||
| 1948 | - such row -- the chroma refusal is LIVE" | ||
| 1949 | - ); | ||
| 1950 | - } | ||
| 1951 | - | ||
| 1952 | - /// lane-av1txsizeaudit r2 -- the one value in `ec-av1` whose correct form | ||
| 1953 | - /// is provable against libaom but whose *observable effect* is nil, so a | ||
| 1954 | - /// pixel gate is impossible and this source scan is the only instrument | ||
| 1955 | - /// that can catch a regression. | ||
| 1956 | - /// | ||
| 1957 | - /// `decode.rs`'s `suppress_internal_lf_edges` publishes the skipped 128 | ||
| 1958 | - /// root's own chroma extent into `uv_tx_grid`, so the deblocker's | ||
| 1959 | - /// alignment gate (`x0 & (tx - 1)`) sees no internal transform edge. The | ||
| 1960 | - /// correct extent is the block's own CHROMA footprint, | ||
| 1961 | - /// `w_mi * MI >> ss_x` per axis -- `av1_setup_dst_planes`'s | ||
| 1962 | - /// `get_plane_block_size(bsize, ss_x, ss_y)`, which at ss (0,0) is the | ||
| 1963 | - /// block itself, so **128 and not 64** for a 128x128 root at 4:4:4. The | ||
| 1964 | - /// site carried a hardcoded `w_mi * MI / 2`, which is right at 4:2:0 by | ||
| 1965 | - /// the `>> 1 == / 2` identity and half the truth everywhere else; its | ||
| 1966 | - /// sibling `fill_lf_grid_rect` had already been repaired to | ||
| 1967 | - /// `(w_mi * MI) >> ss_x(fctx)`. | ||
| 1968 | - /// | ||
| 1969 | - /// **No pixel gate can exist for this, and that is measured, not assumed.** | ||
| 1970 | - /// The widening defeats the alignment gate, but every edge it lets | ||
| 1971 | - /// through then meets the SAME libaom rule applied at the correct place -- | ||
| 1972 | - /// `edge_params_body`'s spec-7.14.2 / `set_lpf_parameters` term | ||
| 1973 | - /// `!pu_edge && cur_ref != 0 && pv_ref != 0 && skip_at && skip_at`, which | ||
| 1974 | - /// holds for every internal edge because both cells are the same skipped | ||
| 1975 | - /// block. Over 26 frames / 2 555 904 samples of five 4:4:4 | ||
| 1976 | - /// `--sb-size=128` streams that fire the arm 30 times, `64` and `128` both | ||
| 1977 | - /// decode pixel-exact against `aomdec` and differ from each other in not | ||
| 1978 | - /// one sample. The masking is TOTAL: the method is only ever called for a | ||
| 1979 | - /// block that is itself skipped, so no input exists on which one side of | ||
| 1980 | - /// an internal edge is not skipped. Hence: source scan, not pixels. | ||
| 1981 | - /// | ||
| 1982 | - /// This also pins the `fctx` threading, because `Neighbours` carries no | ||
| 1983 | - /// subsampling of its own -- a sibling lane reached the same site and | ||
| 1984 | - /// recorded it as unfixable for exactly that reason. | ||
| 1985 | - #[test] | ||
| 1986 | - fn the_skipped_128_root_chroma_suppression_publishes_the_blocks_own_per_axis_chroma_extent() { | ||
| 1987 | - let src = crate::test_source::module_source("decode"); | ||
| 1988 | - let start = src | ||
| 1989 | - .find("fn suppress_internal_lf_edges(") | ||
| 1990 | - .expect("suppress_internal_lf_edges is gone"); | ||
| 1991 | - let body_start = start + src[start..].find('{').expect("no body"); | ||
| 1992 | - let body = | ||
| 1993 | - &src[body_start..body_start + src[body_start..].find("\n }").expect("no end")]; | ||
| 1994 | - | ||
| 1995 | - assert!( | ||
| 1996 | - body.contains("((w_mi * MI) >> ss_x(fctx))") | ||
| 1997 | - && body.contains("((h_mi * MI) >> ss_y(fctx))"), | ||
| 1998 | - "suppress_internal_lf_edges must publish the block's own chroma extent per axis \ | ||
| 1999 | - -- `w_mi * MI >> ss_x(fctx)`, not a hardcoded `/2`" | ||
| 2000 | - ); | ||
crates/ec-av1/src/stack_budget.rsmodified+0 -3
| @@ -456,10 +456,8 @@ mod tests { | |||
| 456 | ("film_grain.rs", include_str!("film_grain.rs")), | 456 | ("film_grain.rs", include_str!("film_grain.rs")), |
| 457 | ("filter_search.rs", include_str!("filter_search.rs")), | 457 | ("filter_search.rs", include_str!("filter_search.rs")), |
| 458 | ("frame.rs", include_str!("frame.rs")), | 458 | ("frame.rs", include_str!("frame.rs")), |
| 459 | - ("gate_coverage.rs", include_str!("gate_coverage.rs")), | ||
| 460 | ("hits.rs", include_str!("hits.rs")), | 459 | ("hits.rs", include_str!("hits.rs")), |
| 461 | ("intra.rs", include_str!("intra.rs")), | 460 | ("intra.rs", include_str!("intra.rs")), |
| 462 | - ("library_fixture.rs", include_str!("library_fixture.rs")), | ||
| 463 | ("mc.rs", include_str!("mc.rs")), | 461 | ("mc.rs", include_str!("mc.rs")), |
| 464 | ("motion.rs", include_str!("motion.rs")), | 462 | ("motion.rs", include_str!("motion.rs")), |
| 465 | ("motion_field.rs", include_str!("motion_field.rs")), | 463 | ("motion_field.rs", include_str!("motion_field.rs")), |
| @@ -471,7 +469,6 @@ mod tests { | |||
| 471 | ("probe.rs", include_str!("probe.rs")), | 469 | ("probe.rs", include_str!("probe.rs")), |
| 472 | ("qm.rs", crate::test_source::module_source("qm")), | 470 | ("qm.rs", crate::test_source::module_source("qm")), |
| 473 | ("quant.rs", include_str!("quant.rs")), | 471 | ("quant.rs", include_str!("quant.rs")), |
| 474 | - ("refusal_inventory.rs", include_str!("refusal_inventory.rs")), | ||
| 475 | ("restoration.rs", include_str!("restoration.rs")), | 472 | ("restoration.rs", include_str!("restoration.rs")), |
| 476 | ("sequence.rs", include_str!("sequence.rs")), | 473 | ("sequence.rs", include_str!("sequence.rs")), |
| 477 | ("speed.rs", include_str!("speed.rs")), | 474 | ("speed.rs", include_str!("speed.rs")), |
crates/ec-av1/src/stream/mod.rsmodified+0 -9
| @@ -22,14 +22,10 @@ use ec_av1_syntax::{ | |||
| 22 | // Census-only: read outside `mod tests` only in comments; the non-test lib | 22 | // Census-only: read outside `mod tests` only in comments; the non-test lib |
| 23 | // target never touches them, so they ride in behind cfg(test) (via the test | 23 | // target never touches them, so they ride in behind cfg(test) (via the test |
| 24 | // module's `use super::*`). | 24 | // module's `use super::*`). |
| 25 | -#[cfg(test)] | ||
| 26 | -use ec_av1_syntax::{SEG_LVL_ALT_Q, SEG_LVL_MAX}; | ||
| 27 | use ec_core::{Error, Result}; | 25 | use ec_core::{Error, Result}; |
| 28 | 26 | ||
| 29 | use crate::cdf_state::Cdfs; | 27 | use crate::cdf_state::Cdfs; |
| 30 | use crate::decode; | 28 | use crate::decode; |
| 31 | -#[cfg(test)] | ||
| 32 | -use crate::decode::decode_key_frame_tile_lr; | ||
| 33 | use crate::decode::{decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, q_ctx_of}; | 29 | use crate::decode::{decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, q_ctx_of}; |
| 34 | use crate::encode::Picture; | 30 | use crate::encode::Picture; |
| 35 | 31 | ||
| @@ -2001,11 +1997,6 @@ fn decode_frame( | |||
| 2001 | // lane-gm r2 STEP-8 ATTEMPT (reverted): removing this refusal | 1997 | // lane-gm r2 STEP-8 ATTEMPT (reverted): removing this refusal |
| 2002 | // exposed a real pixel mismatch -- | 1998 | // exposed a real pixel mismatch -- |
| 2003 | // a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact | 1999 | // a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact |
| 2004 | - // seed 43, frame 1 luma, with EC_WEDGE_GATE_ATTEMPTS=20 | ||
| 2005 | - // EC_AV1_REQUIRE_AOMENC=1 -- so the single-ref/compound MV wiring | ||
| 2006 | - // is not yet provably correct end to end; keeping the refusal | ||
| 2007 | - // until that seed is captured (EC_AV1_GATE_DUMP), self-pinned, and | ||
| 2008 | - // root-caused rather than shipping a wrong decode. | ||
| 2009 | // | 2000 | // |
| 2010 | // lane-gm r3 ROOT CAUSE (pinned, range-ladder-confirmed, still not | 2001 | // lane-gm r3 ROOT CAUSE (pinned, range-ladder-confirmed, still not |
| 2011 | // fixed): the mismatch is NOT an mv/mvstack/entropy bug -- msac | 2002 | // fixed): the mismatch is NOT an mv/mvstack/entropy bug -- msac |
crates/ec-av1/src/stream/tests/gates_a.rsdeleted+0 -2841
Diff too large; view file
| @@ -1,2841 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | - | ||
| 4 | - /// Three-bucket gate summary (class [[gate-skips-on-its-own-failure]]): | ||
| 5 | - /// every attempt lands in exactly one bucket -- decoded pixel-exact WITH | ||
| 6 | - /// the feature counter moving, decoded pixel-exact WITHOUT it, or a named | ||
| 7 | - /// refusal -- and the three sum to the attempts made. | ||
| 8 | - pub(super) fn gate_buckets(name: &str, counted_exact: u32, uncounted_exact: u32, named_refusals: usize) { | ||
| 9 | - eprintln!( | ||
| 10 | - "{name}: buckets counted-exact={counted_exact} uncounted-exact={uncounted_exact} \ | ||
| 11 | - named-refusals={named_refusals} (attempts {})", | ||
| 12 | - counted_exact as usize + uncounted_exact as usize + named_refusals | ||
| 13 | - ); | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - pub(crate) fn lock_gate_counters() -> std::sync::MutexGuard<'static, ()> { | ||
| 17 | - GATE_COUNTER_LOCK.lock().unwrap_or_else(|e| e.into_inner()) | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - /// The body every 4:4:4 lossy live gate runs: assert the oracle compare | ||
| 21 | - /// CANNOT be skipped, assert the decode really is the cell it claims | ||
| 22 | - /// (frame count, geometry, full-resolution chroma), assert the 4:4:4-only | ||
| 23 | - /// own-extent route really ran, then compare every frame in decode order | ||
| 24 | - /// against the oracle aomdec with the length asserted first. | ||
| 25 | - /// | ||
| 26 | - /// The aomdec arm is a HARD failure, not a skip: these three gates encode | ||
| 27 | - /// LIVE, so reaching this point means the oracle aomenc resolved, and | ||
| 28 | - /// aomenc and aomdec ship in the same build directory -- an aomdec that is | ||
| 29 | - /// missing beside a present aomenc is a broken oracle, not a checkout | ||
| 30 | - /// without one. (The older shape, `if aomdec_path().is_file()`, let the | ||
| 31 | - /// compare vanish with no env escape at all; that is what | ||
| 32 | - /// [`aomdec_available`] replaced for the pinned gates, and it cannot be | ||
| 33 | - /// used here because these gates have no stream to compare without one.) | ||
| 34 | - pub(super) fn gate_444_lossy_live_exact(name: &str, w: usize, h: usize) { | ||
| 35 | - // The ONLY way out without measuring, and it has already printed a | ||
| 36 | - // SKIP naming the env var that would turn it into a failure. | ||
| 37 | - let Some(stream) = encode_444_lossy_live(name, w, h) else { | ||
| 38 | - return; | ||
| 39 | - }; | ||
| 40 | - assert!( | ||
| 41 | - aomdec_path().is_file(), | ||
| 42 | - "{name}: the oracle aomenc resolved to {} but no aomdec sits beside it at {} -- \ | ||
| 43 | - the pixel compare would silently skip, which this gate treats as a failure", | ||
| 44 | - aomenc_path().display(), | ||
| 45 | - aomdec_path().display() | ||
| 46 | - ); | ||
| 47 | - | ||
| 48 | - let _guard = lock_gate_counters(); | ||
| 49 | - crate::decode::reset_rect4_inter_own_chroma444_hits(); | ||
| 50 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 51 | - panic!("{name}: the live {w}x{h} 4:4:4 lossy stream was refused: {e}") | ||
| 52 | - }); | ||
| 53 | - let own = crate::decode::rect4_inter_own_chroma444_hits(); | ||
| 54 | - assert!( | ||
| 55 | - own > 0, | ||
| 56 | - "{name}: no 4:4:4 1:4 inter strip read its chroma context over its own extent -- \ | ||
| 57 | - the route this cell is a witness for never ran (measured: 13 at 66x66, 12 at \ | ||
| 58 | - 130x122, 24 at 256x128)" | ||
| 59 | - ); | ||
| 60 | - assert_eq!( | ||
| 61 | - frames.len(), | ||
| 62 | - 4, | ||
| 63 | - "{name}: decoded {} frame(s), the recipe encodes 4 -- a short decode would make the \ | ||
| 64 | - oracle compare cover a prefix of the cell", | ||
| 65 | - frames.len() | ||
| 66 | - ); | ||
| 67 | - for (i, f) in frames.iter().enumerate() { | ||
| 68 | - assert_eq!( | ||
| 69 | - (f.width, f.height), | ||
| 70 | - (w, h), | ||
| 71 | - "{name}: frame {i} is {}x{}, the cell is {w}x{h}", | ||
| 72 | - f.width, | ||
| 73 | - f.height | ||
| 74 | - ); | ||
| 75 | - // At 4:4:4 both chroma planes are full resolution. A decoder that | ||
| 76 | - // kept a subsampled extent would hand quarter-size planes to the | ||
| 77 | - // byte compare; say so here instead of letting the compare | ||
| 78 | - // stand in for the shape claim. | ||
| 79 | - assert_eq!( | ||
| 80 | - f.u.len(), | ||
| 81 | - w * h, | ||
| 82 | - "{name}: frame {i} U plane is {} samples; at 4:4:4 it must be full resolution \ | ||
| 83 | - ({w}x{h})", | ||
| 84 | - f.u.len() | ||
| 85 | - ); | ||
| 86 | - assert_eq!( | ||
| 87 | - f.v.len(), | ||
| 88 | - w * h, | ||
| 89 | - "{name}: frame {i} V plane is {} samples; at 4:4:4 it must be full resolution \ | ||
| 90 | - ({w}x{h})", | ||
| 91 | - f.v.len() | ||
| 92 | - ); | ||
| 93 | - assert_eq!( | ||
| 94 | - f.y.len(), | ||
| 95 | - w * h, | ||
| 96 | - "{name}: frame {i} luma plane is {} samples, expected {w}x{h}", | ||
| 97 | - f.y.len() | ||
| 98 | - ); | ||
| 99 | - } | ||
| 100 | - let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, name); | ||
| 101 | - assert_eq!( | ||
| 102 | - decoded, 4, | ||
| 103 | - "{name}: the oracle decoded {decoded} frame(s) in decode order, the recipe carries 4 \ | ||
| 104 | - (so far {hidden} hidden)" | ||
| 105 | - ); | ||
| 106 | - eprintln!( | ||
| 107 | - "{name}: {w}x{h} 4:4:4 lossy, {decoded} decode-order frame(s) byte-exact vs aomdec \ | ||
| 108 | - ({hidden} hidden), {own} own-extent 1:4 chroma gather(s)" | ||
| 109 | - ); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - /// lane-av1toolgates: the shared body of the two `enable-rect-tx` | ||
| 113 | - /// coverage gates (8-bit and 10-bit). | ||
| 114 | - /// | ||
| 115 | - /// The aomenc ARGUMENT VECTOR is built by each gate and passed in, never | ||
| 116 | - /// assembled here. That is not tidiness: `gate_coverage`'s `gate_bodies()` | ||
| 117 | - /// splits `stream.rs` on `\n #[` and keeps a segment only if that | ||
| 118 | - /// segment itself contains `--passes=1`, so a flag living in a helper is | ||
| 119 | - /// invisible to the coverage derivation. A helper that owns the recipe | ||
| 120 | - /// would leave this gate counted at whatever depth the helper's own text | ||
| 121 | - /// implies -- which is the blind spot that kept `enable-rect-tx` on the | ||
| 122 | - /// `NEVER_EXERCISED` lists after real streams had exercised it. | ||
| 123 | - /// | ||
| 124 | - /// WHAT THIS GATE IS AND IS NOT. `enable_rect_tx` has no sequence-header | ||
| 125 | - /// bit in AV1 -- aom reads it only in `tx_search.c` (`search_tx_size`'s | ||
| 126 | - /// `!enable_rect_tx && tx_size_wide != tx_size_high` skip and the | ||
| 127 | - /// `tx_size_max_32_square` remap) -- so the flag never reaches a decoder. | ||
| 128 | - /// Spelling `--enable-rect-tx=1` proves the ENCODER was ALLOWED the tool | ||
| 129 | - /// and nothing more. It is CONTEXT here, not the witness: a gate that | ||
| 130 | - /// stopped at the flag would be the `tool-disabled-in-every-gate` defect | ||
| 131 | - /// `NEVER_EXERCISED` exists to prevent, in a new costume. | ||
| 132 | - /// | ||
| 133 | - /// The witness is the PARSED PARTITION SHAPE, the only thing in the | ||
| 134 | - /// bitstream that can carry a rect transform: | ||
| 135 | - /// [`decode::rect_partition_hits`] counts `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 136 | - /// symbols actually read, i.e. a rect partition in the tree this decoder | ||
| 137 | - /// walked, and [`decode::rect_coeff_tu_hits`] counts the rectangular | ||
| 138 | - /// transform units that then coded coefficients through `read_coeffs_rect` | ||
| 139 | - /// (`all_zero == 0`) -- the rect coefficient TABLES being read, not a | ||
| 140 | - /// header bit. Both are asserted above zero over the arms that decoded AND | ||
| 141 | - /// compared, and every frame is pixel-compared against ffmpeg's own decode | ||
| 142 | - /// of the identical bytes. | ||
| 143 | - /// | ||
| 144 | - /// LIMIT, stated because it bounds what this gate can claim: this | ||
| 145 | - /// repository has no INDEPENDENT partition parser to list leaves from -- | ||
| 146 | - /// `ec-av1-syntax` parses OBU headers and the sequence header only -- and | ||
| 147 | - /// `ec_av1::census`'s per-frame `blocks`/`tx` shape maps, the one true | ||
| 148 | - /// leaf list, are armed by a process-global `OnceLock` on | ||
| 149 | - /// `EC_AV1_BITCENSUS`, so arming them inside a lib test would switch the | ||
| 150 | - /// accountant on for every other gate in the process. The partition walk is | ||
| 151 | - /// therefore observed through the decoder's own counters, which is weaker | ||
| 152 | - /// than a second opinion but is still a shape fact about the stream rather | ||
| 153 | - /// than a fact about the flag. | ||
| 154 | - /// | ||
| 155 | - /// RED-BEFORE: the COUNTERS, one per assert, both measured. | ||
| 156 | - /// `--enable-rect-tx=0` is deliberately NOT claimed as the mutation: it | ||
| 157 | - /// does NOT zero these counters (39 rect coefficient TUs against 210 on | ||
| 158 | - /// the cq20 arm, because `--enable-rect-partitions=1` already forces | ||
| 159 | - /// non-square transform sizes regardless), and with every partition shape | ||
| 160 | - /// off the flag yields no rect transform at either setting. `=0` does turn | ||
| 161 | - /// the gate red, but through the ORACLE -- its `--enable-tx-size-search=0` | ||
| 162 | - /// arm is a stream ffmpeg cannot decode past frame 6 of 15 -- so the | ||
| 163 | - /// frame-count assert fires first and proves nothing about the tool. | ||
| 164 | - pub(super) fn rect_tx_tool_gate(name: &str, ten_bit: bool, args: &[String]) -> (usize, usize) { | ||
| 165 | - // A missing tool SKIPs, so the totals the caller sums stay 0 and the | ||
| 166 | - // gate's own witness assert fails loudly instead of passing vacuously | ||
| 167 | - // on a run that decoded nothing. | ||
| 168 | - if !have_ffmpeg() { | ||
| 169 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 170 | - return (0, 0); | ||
| 171 | - } | ||
| 172 | - if !have_aomenc() { | ||
| 173 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 174 | - return (0, 0); | ||
| 175 | - } | ||
| 176 | - let (width, height) = (64usize, 64usize); | ||
| 177 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 178 | - .args([ | ||
| 179 | - "-v", | ||
| 180 | - "error", | ||
| 181 | - "-f", | ||
| 182 | - "lavfi", | ||
| 183 | - "-i", | ||
| 184 | - "mandelbrot=size=64x64:rate=25", | ||
| 185 | - "-pix_fmt", | ||
| 186 | - if ten_bit { "yuv420p10le" } else { "yuv420p" }, | ||
| 187 | - // y4m calls 10-bit an unofficial pixel format (no-op at 8). | ||
| 188 | - "-strict", | ||
| 189 | - "-1", | ||
| 190 | - "-t", | ||
| 191 | - "0.60", | ||
| 192 | - "-f", | ||
| 193 | - "yuv4mpegpipe", | ||
| 194 | - "-", | ||
| 195 | - ]) | ||
| 196 | - .stdin(Stdio::null()) | ||
| 197 | - .stdout(Stdio::piped()) | ||
| 198 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 199 | - .expect("ffmpeg failed to run"); | ||
| 200 | - assert!( | ||
| 201 | - y4m.status.success(), | ||
| 202 | - "{name}: ffmpeg fixture: {}", | ||
| 203 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 204 | - ); | ||
| 205 | - let out = run_with_stdin(Command::new(aomenc_path()).args(args), &y4m.stdout); | ||
| 206 | - assert!( | ||
| 207 | - out.status.success(), | ||
| 208 | - "{name}: aomenc refused the fixture: {}", | ||
| 209 | - String::from_utf8_lossy(&out.stderr) | ||
| 210 | - ); | ||
| 211 | - let stream = out.stdout; | ||
| 212 | - assert!(!stream.is_empty(), "{name}: aomenc wrote an empty stream"); | ||
| 213 | - if ten_bit { | ||
| 214 | - assert_eq!( | ||
| 215 | - parsed_bit_depth(&stream), | ||
| 216 | - 10, | ||
| 217 | - "{name}: aomenc did not write a 10-bit sequence header" | ||
| 218 | - ); | ||
| 219 | - } | ||
| 220 | - let parts_before = decode::rect_partition_hits(); | ||
| 221 | - let tus_before = decode::rect_coeff_tu_hits(); | ||
| 222 | - let decoded = match decode_stream(&stream) { | ||
| 223 | - Ok(frames) => frames, | ||
| 224 | - Err(e) => panic!("{name}: decode_stream refused: {e}"), | ||
| 225 | - }; | ||
| 226 | - // Sampled after the decode, before the pixel compare, so a mismatch | ||
| 227 | - // report can still say whether the arm fired. | ||
| 228 | - let parts = decode::rect_partition_hits() - parts_before; | ||
| 229 | - let tus = decode::rect_coeff_tu_hits() - tus_before; | ||
| 230 | - // The ENCODE's frame count: the fixture renders `mandelbrot=size=64x64:rate=25` | ||
| 231 | - // with `-t "0.60"` (10677-10691) -- 25 x 0.60 = 15 frames -- and the | ||
| 232 | - // caller's `args` carry no `--limit` (10823-10853), so every arm's stream | ||
| 233 | - // codes all 15. Asserted ABOVE the oracle call, which is the fix for the | ||
| 234 | - // misattribution this gate's own doc comment records: the | ||
| 235 | - // `--enable-tx-size-search=0` arm is a stream ffmpeg cannot decode past | ||
| 236 | - // frame 6 of 15, and with the count taken from our decode the helper's | ||
| 237 | - // byte-length assert fires FIRST and reads as an ffmpeg fault. Naming the | ||
| 238 | - // 15 here makes the shortfall ours to explain. | ||
| 239 | - const ENCODED_FRAMES: usize = 15; | ||
| 240 | - assert_eq!( | ||
| 241 | - decoded.len(), | ||
| 242 | - ENCODED_FRAMES, | ||
| 243 | - "{name}: the encode codes {ENCODED_FRAMES} frames, the decode showed {} (rect \ | ||
| 244 | - partitions {parts}, rect coefficient TUs {tus})", | ||
| 245 | - decoded.len() | ||
| 246 | - ); | ||
| 247 | - let reference = if ten_bit { | ||
| 248 | - ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()) | ||
| 249 | - } else { | ||
| 250 | - ffmpeg_decode_sequence(&stream, width, height, decoded.len()) | ||
| 251 | - }; | ||
| 252 | - assert_eq!( | ||
| 253 | - decoded.len(), | ||
| 254 | - reference.len(), | ||
| 255 | - "{name}: shown-frame count vs ffmpeg (rect partitions {parts}, rect coefficient \ | ||
| 256 | - TUs {tus})" | ||
| 257 | - ); | ||
| 258 | - for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { | ||
| 259 | - for (plane, (a, b), w) in [ | ||
| 260 | - ("Y", (&ours.y, &theirs.y), width), | ||
| 261 | - ("U", (&ours.u, &theirs.u), width / 2), | ||
| 262 | - ("V", (&ours.v, &theirs.v), width / 2), | ||
| 263 | - ] { | ||
| 264 | - assert_eq!(a.len(), b.len(), "{name}: frame {i} {plane} plane length"); | ||
| 265 | - if a != b { | ||
| 266 | - let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu")); | ||
| 267 | - crate::dumpio::pin("TEST_PIN", &pin, &stream); | ||
| 268 | - let at = a | ||
| 269 | - .iter() | ||
| 270 | - .zip(b.iter()) | ||
| 271 | - .position(|(x, y)| x != y) | ||
| 272 | - .unwrap_or(0); | ||
| 273 | - panic!( | ||
| 274 | - "{name}: frame {i} {plane} mismatch vs ffmpeg at row {}, col {}: {} vs \ | ||
| 275 | - {} (rect partitions {parts}, rect coefficient TUs {tus}; stream pinned \ | ||
| 276 | - at {})", | ||
| 277 | - at / w, | ||
| 278 | - at % w, | ||
| 279 | - a[at], | ||
| 280 | - b[at], | ||
| 281 | - pin.display() | ||
| 282 | - ); | ||
| 283 | - } | ||
| 284 | - } | ||
| 285 | - } | ||
| 286 | - eprintln!( | ||
| 287 | - "{name}: {} bit, pixel-exact vs ffmpeg; parsed rect partitions {parts}, rect \ | ||
| 288 | - coefficient TUs {tus}", | ||
| 289 | - if ten_bit { "10" } else { "8" } | ||
| 290 | - ); | ||
| 291 | - (parts, tus) | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - /// lane-hbdgates r1: drive one 10-bit aomenc recipe over `seeds`, decode | ||
| 295 | - /// every attempt and pixel-compare every SHOWN frame against ffmpeg's own | ||
| 296 | - /// 10-bit decode of the identical bytes. Per-tool firing counters are | ||
| 297 | - /// sampled PER ATTEMPT and summed only over attempts that decoded *and* | ||
| 298 | - /// compared -- a stream that hit a named refusal contributes nothing | ||
| 299 | - /// (class `counter-from-refused-stream`). Named refusals are tolerated | ||
| 300 | - /// and reported; a pixel mismatch is a hard failure, never a SKIP. | ||
| 301 | - pub(super) fn ten_bit_tool_gate( | ||
| 302 | - name: &str, | ||
| 303 | - width: usize, | ||
| 304 | - height: usize, | ||
| 305 | - frames: usize, | ||
| 306 | - extra: &[&str], | ||
| 307 | - seeds: &[u32], | ||
| 308 | - counters: &[(&str, fn() -> usize)], | ||
| 309 | - ) { | ||
| 310 | - fn first_diff(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> { | ||
| 311 | - ours.iter() | ||
| 312 | - .zip(theirs.iter()) | ||
| 313 | - .position(|(a, b)| a != b) | ||
| 314 | - .map(|i| { | ||
| 315 | - format!( | ||
| 316 | - "first diff at index {i} (row {}, col {}): ours {} vs ffmpeg {}", | ||
| 317 | - i / width, | ||
| 318 | - i % width, | ||
| 319 | - ours[i], | ||
| 320 | - theirs[i] | ||
| 321 | - ) | ||
| 322 | - }) | ||
| 323 | - } | ||
| 324 | - let mut totals = vec![0usize; counters.len()]; | ||
| 325 | - let mut refusals: Vec<String> = Vec::new(); | ||
| 326 | - let mut compared = 0usize; | ||
| 327 | - for &seed in seeds { | ||
| 328 | - let stream = encode_10bit_gradients_seed(name, seed, width, height, frames, extra); | ||
| 329 | - assert_eq!( | ||
| 330 | - parsed_bit_depth(&stream), | ||
| 331 | - 10, | ||
| 332 | - "{name}: aomenc did not write a 10-bit sequence header (seed {seed})" | ||
| 333 | - ); | ||
| 334 | - let before: Vec<usize> = counters.iter().map(|(_, f)| f()).collect(); | ||
| 335 | - let decoded = match decode_stream(&stream) { | ||
| 336 | - Ok(frames) => frames, | ||
| 337 | - Err(e) => { | ||
| 338 | - refusals.push(format!("seed {seed}: {e}")); | ||
| 339 | - continue; | ||
| 340 | - } | ||
| 341 | - }; | ||
| 342 | - // Deltas are read BEFORE the pixel compare so a mismatch report | ||
| 343 | - // says whether the tool under test actually fired on the failing | ||
| 344 | - // stream (a mismatch with a zero delta is some other defect). | ||
| 345 | - let deltas: Vec<usize> = counters | ||
| 346 | - .iter() | ||
| 347 | - .zip(before.iter()) | ||
| 348 | - .map(|((_, f), b)| f() - b) | ||
| 349 | - .collect(); | ||
| 350 | - let fired: Vec<String> = counters | ||
| 351 | - .iter() | ||
| 352 | - .zip(deltas.iter()) | ||
| 353 | - .map(|((label, _), d)| format!("{label}={d}")) | ||
| 354 | - .collect(); | ||
| 355 | - let fired = fired.join(" "); | ||
| 356 | - // The ENCODE's frame count, and it is this helper's `frames` PARAMETER | ||
| 357 | - // (15446) -- not our decode's length. It is the same value handed to | ||
| 358 | - // `encode_10bit_gradients_seed` (15469), which renders | ||
| 359 | - // `frames / 25.0` seconds at `rate=25` (15928, 15940) and runs | ||
| 360 | - // aomenc with no `--limit` of its own, so the stream codes exactly | ||
| 361 | - // `frames` frames: 1 for the single-key-frame callers, 24 for the | ||
| 362 | - // `--lag-in-frames=16` inter callers. Asserted ABOVE the oracle call, | ||
| 363 | - // so a decode that showed fewer reds naming the encode rather than | ||
| 364 | - // handing ffmpeg the same short count. | ||
| 365 | - assert_eq!( | ||
| 366 | - decoded.len(), | ||
| 367 | - frames, | ||
| 368 | - "{name}: seed {seed}: the encode codes {frames} frame(s), the decode showed {}", | ||
| 369 | - decoded.len() | ||
| 370 | - ); | ||
| 371 | - let reference = ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()); | ||
| 372 | - assert_eq!( | ||
| 373 | - decoded.len(), | ||
| 374 | - reference.len(), | ||
| 375 | - "{name}: seed {seed}: shown-frame count vs ffmpeg" | ||
| 376 | - ); | ||
| 377 | - for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() { | ||
| 378 | - for (plane, (a, b), w) in [ | ||
| 379 | - ("Y", (&ours.y, &theirs.y), width), | ||
| 380 | - ("U", (&ours.u, &theirs.u), width / 2), | ||
| 381 | - ("V", (&ours.v, &theirs.v), width / 2), | ||
| 382 | - ] { | ||
| 383 | - if let Some(d) = first_diff(a, b, w) { | ||
| 384 | - panic!("{name}: seed {seed} frame {i} plane {plane}: {d} [{fired}]"); | ||
| 385 | - } | ||
| 386 | - assert_eq!( | ||
| 387 | - a.len(), | ||
| 388 | - b.len(), | ||
| 389 | - "{name}: seed {seed} frame {i} plane {plane}: ours has {} samples, \ | ||
| 390 | - ffmpeg's has {} -- a short plane would zip-truncate the walk above \ | ||
| 391 | - and hide a chroma-span defect", | ||
| 392 | - a.len(), | ||
| 393 | - b.len() | ||
| 394 | - ); | ||
| 395 | - } | ||
| 396 | - } | ||
| 397 | - compared += 1; | ||
| 398 | - for (i, d) in deltas.iter().enumerate() { | ||
| 399 | - totals[i] += d; | ||
| 400 | - } | ||
| 401 | - } | ||
| 402 | - assert!( | ||
| 403 | - compared > 0, | ||
| 404 | - "{name}: every attempt hit a named refusal:\n{}", | ||
| 405 | - refusals.join("\n") | ||
| 406 | - ); | ||
| 407 | - for (i, (label, _)) in counters.iter().enumerate() { | ||
| 408 | - assert!( | ||
| 409 | - totals[i] > 0, | ||
| 410 | - "{name}: {compared} attempt(s) decoded pixel-exact but {label} never fired -- \ | ||
| 411 | - the gate would prove nothing about that tool. refusals:\n{}", | ||
| 412 | - refusals.join("\n") | ||
| 413 | - ); | ||
| 414 | - } | ||
| 415 | - let summary: Vec<String> = counters | ||
| 416 | - .iter() | ||
| 417 | - .zip(totals.iter()) | ||
| 418 | - .map(|((label, _), t)| format!("{label}={t}")) | ||
| 419 | - .collect(); | ||
| 420 | - eprintln!( | ||
| 421 | - "{name}: {compared}/{} attempts pixel-exact, {}", | ||
| 422 | - seeds.len(), | ||
| 423 | - summary.join(" ") | ||
| 424 | - ); | ||
| 425 | - } | ||
| 426 | - | ||
| 427 | - pub(super) fn intra_rect_in_inter_gate(bit_depth: u32) { | ||
| 428 | - const NAME: &str = | ||
| 429 | - "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact"; | ||
| 430 | - if !have_ffmpeg() { | ||
| 431 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 432 | - return; | ||
| 433 | - } | ||
| 434 | - if !have_aomenc() { | ||
| 435 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 436 | - return; | ||
| 437 | - } | ||
| 438 | - let (width, height, frame_count) = (96usize, 96usize, 8usize); | ||
| 439 | - let mut refusals: Vec<String> = Vec::new(); | ||
| 440 | - let mut uncounted_exact = 0u32; | ||
| 441 | - let mut compared = 0u32; | ||
| 442 | - let mut shapes = [0usize; 3]; | ||
| 443 | - for attempt in 0..45u32 { | ||
| 444 | - let seed = 42 + attempt; | ||
| 445 | - // mandelbrot's fractal detail plus a HARD cut at frame 4: half | ||
| 446 | - // the picture becomes a flat white box, which no motion vector | ||
| 447 | - // can predict, so aomenc's RD codes those blocks INTRA inside an | ||
| 448 | - // inter frame. The box's vertical edge at x=48 is what makes the | ||
| 449 | - // partition search reach for HORZ/VERT strips there. | ||
| 450 | - // A FAST ZOOM: `end_scale`/`end_pts` make mandelbrot rush | ||
| 451 | - // through its own zoom, so consecutive frames share almost no | ||
| 452 | - // content and aomenc's RD codes blocks INTRA inside INTER frames | ||
| 453 | - // (`--kf-min-dist=1000` forbids a new key frame). That is the | ||
| 454 | - // only way a real encoder reaches this decoder's intra-in-inter | ||
| 455 | - // arm; a slowly-evolving source codes every rect strip inter. | ||
| 456 | - let source = format!( | ||
| 457 | - "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25", | ||
| 458 | - 5.0 - f64::from(attempt) * 0.06 | ||
| 459 | - ); | ||
| 460 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 461 | - .args([ | ||
| 462 | - "-v", | ||
| 463 | - "error", | ||
| 464 | - "-f", | ||
| 465 | - "lavfi", | ||
| 466 | - "-i", | ||
| 467 | - &source, | ||
| 468 | - "-vf", | ||
| 469 | - "hue=s=0", | ||
| 470 | - "-pix_fmt", | ||
| 471 | - if bit_depth == 10 { | ||
| 472 | - "yuv420p10le" | ||
| 473 | - } else { | ||
| 474 | - "yuv420p" | ||
| 475 | - }, | ||
| 476 | - "-strict", | ||
| 477 | - "-1", | ||
| 478 | - "-t", | ||
| 479 | - "0.32", | ||
| 480 | - "-f", | ||
| 481 | - "yuv4mpegpipe", | ||
| 482 | - "-strict", | ||
| 483 | - "-1", | ||
| 484 | - "-", | ||
| 485 | - ]) | ||
| 486 | - .stdin(Stdio::null()) | ||
| 487 | - .stdout(Stdio::piped()) | ||
| 488 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 489 | - .expect("ffmpeg failed to run"); | ||
| 490 | - assert!( | ||
| 491 | - y4m.status.success(), | ||
| 492 | - "ffmpeg fixture: {}", | ||
| 493 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 494 | - ); | ||
| 495 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 496 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 497 | - } else { | ||
| 498 | - &[] | ||
| 499 | - }; | ||
| 500 | - // MEASURED (r1): the speed preset gates the feature (class | ||
| 501 | - // [[gate-preset-gates-the-feature]]) -- at `--cpu-used=4` this | ||
| 502 | - // content produces no rect partition at all, at `--cpu-used=0` | ||
| 503 | - // aomenc emits AB partitions the tile path refuses (it ignores | ||
| 504 | - // `--enable-ab-partitions=0`, ledger). So the attempt sweep walks | ||
| 505 | - // the preset as well as the seed. | ||
| 506 | - let cpu = format!("--cpu-used={}", attempt % 5); | ||
| 507 | - // The quantiser drives how finely the RD partitions: the sweep | ||
| 508 | - // walks it too, so "no rect strip fired" cannot be an artefact of | ||
| 509 | - // one cq. | ||
| 510 | - let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]); | ||
| 511 | - let out = run_with_stdin( | ||
| 512 | - Command::new(aomenc_path()) | ||
| 513 | - .args(depth_args) | ||
| 514 | - .arg(&cpu) | ||
| 515 | - .arg(&cq) | ||
| 516 | - .args([ | ||
| 517 | - // class [[aomenc-first-flag-wins]]: every flag is spelled | ||
| 518 | - // exactly ONCE in this recipe, so there is no override to | ||
| 519 | - // order. These four are what this gate is about. | ||
| 520 | - "--enable-rect-partitions=1", | ||
| 521 | - // MEASURED (r1): the charter's `--min-partition-size=8` | ||
| 522 | - // makes 24/24 attempts stop at a sub-16 AB-partition | ||
| 523 | - // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", | ||
| 524 | - // "a coded (non-skip) HORZ_B/VERT_B rect strip below | ||
| 525 | - // 16x16") before any intra rect strip is reached -- those | ||
| 526 | - // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape | ||
| 527 | - // reachable (a 16x16 block's own HORZ/VERT children). | ||
| 528 | - "--min-partition-size=16", | ||
| 529 | - "--max-partition-size=64", | ||
| 530 | - // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at | ||
| 531 | - // the SQUARE intra-in-inter arm's own refusal ("an intra | ||
| 532 | - // block in an inter frame whose tx_depth splits its luma | ||
| 533 | - // transform (round 1)", read_block_tx_size) long before a | ||
| 534 | - // rect strip is reached -- that arm is another lane's | ||
| 535 | - // surface. OFF, no tx-depth symbol is coded at all and | ||
| 536 | - // every rect strip here is the unsplit single-transform | ||
| 537 | - // case. The SPLIT rect arm (`depth_to_tx_wh` + | ||
| 538 | - // decode_rect_split's per-unit walk) is wired but stays | ||
| 539 | - // UNGATED on this path until that square refusal lifts. | ||
| 540 | - "--enable-tx-size-search=0", | ||
| 541 | - "--codec=av1", | ||
| 542 | - "--passes=1", | ||
| 543 | - "--end-usage=q", | ||
| 544 | - "--lag-in-frames=0", | ||
| 545 | - "--auto-alt-ref=0", | ||
| 546 | - // One key frame at the head: the frames after the cut must | ||
| 547 | - // stay INTER frames carrying intra blocks, not become a | ||
| 548 | - // new key frame. | ||
| 549 | - "--kf-min-dist=1000", | ||
| 550 | - "--kf-max-dist=1000", | ||
| 551 | - "--threads=1", | ||
| 552 | - "--row-mt=0", | ||
| 553 | - "--enable-order-hint=0", | ||
| 554 | - "--enable-warped-motion=0", | ||
| 555 | - "--enable-obmc=0", | ||
| 556 | - "--enable-masked-comp=0", | ||
| 557 | - "--enable-interintra-comp=0", | ||
| 558 | - "--enable-dist-wtd-comp=0", | ||
| 559 | - "--enable-diff-wtd-comp=0", | ||
| 560 | - "--enable-onesided-comp=0", | ||
| 561 | - "--enable-interintra-wedge=0", | ||
| 562 | - "--enable-smooth-interintra=0", | ||
| 563 | - "--enable-ab-partitions=0", | ||
| 564 | - "--enable-1to4-partitions=0", | ||
| 565 | - // The intra-in-inter arm reads no `use_filter_intra` | ||
| 566 | - // symbol (square OR rect) -- lane-fiinter owns that read. | ||
| 567 | - "--enable-filter-intra=0", | ||
| 568 | - "--enable-smooth-intra=0", | ||
| 569 | - "--enable-paeth-intra=0", | ||
| 570 | - "--enable-directional-intra=0", | ||
| 571 | - "--enable-angle-delta=0", | ||
| 572 | - "--enable-cdef=0", | ||
| 573 | - "--enable-restoration=0", | ||
| 574 | - "--enable-palette=0", | ||
| 575 | - "--enable-intrabc=0", | ||
| 576 | - "--enable-cfl-intra=0", | ||
| 577 | - "--enable-ref-frame-mvs=0", | ||
| 578 | - "--obu", | ||
| 579 | - "-o", | ||
| 580 | - "-", | ||
| 581 | - "-", | ||
| 582 | - ]), | ||
| 583 | - &y4m.stdout, | ||
| 584 | - ); | ||
| 585 | - assert!( | ||
| 586 | - out.status.success(), | ||
| 587 | - "aomenc refused the fixture: {}", | ||
| 588 | - String::from_utf8_lossy(&out.stderr) | ||
| 589 | - ); | ||
| 590 | - let stream = out.stdout; | ||
| 591 | - let before = [ | ||
| 592 | - decode::intra_rect_strip_in_inter_hits(0), | ||
| 593 | - decode::intra_rect_strip_in_inter_hits(1), | ||
| 594 | - decode::intra_rect_strip_in_inter_hits(2), | ||
| 595 | - ]; | ||
| 596 | - let kf_rect_before = decode::rect_partition_hits(); | ||
| 597 | - let frames = match decode_stream(&stream) { | ||
| 598 | - Ok(frames) => frames, | ||
| 599 | - Err(e) => { | ||
| 600 | - let msg = e.to_string(); | ||
| 601 | - assert!( | ||
| 602 | - msg.contains("unsupported"), | ||
| 603 | - "intra-rect-in-inter decode failed outright (seed {seed}): {msg}" | ||
| 604 | - ); | ||
| 605 | - refusals.push(format!("seed {seed} {cpu} {cq}: {msg}")); | ||
| 606 | - continue; | ||
| 607 | - } | ||
| 608 | - }; | ||
| 609 | - let delta = [ | ||
| 610 | - decode::intra_rect_strip_in_inter_hits(0) - before[0], | ||
| 611 | - decode::intra_rect_strip_in_inter_hits(1) - before[1], | ||
| 612 | - decode::intra_rect_strip_in_inter_hits(2) - before[2], | ||
| 613 | - ]; | ||
| 614 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 615 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 616 | - } else { | ||
| 617 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 618 | - }; | ||
| 619 | - assert_eq!(frames.len(), frame_count); | ||
| 620 | - eprintln!( | ||
| 621 | - "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \ | ||
| 622 | - 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}", | ||
| 623 | - delta[0], | ||
| 624 | - delta[1], | ||
| 625 | - delta[2], | ||
| 626 | - decode::rect_partition_hits() - kf_rect_before | ||
| 627 | - ); | ||
| 628 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 629 | - for (plane, (g, w)) in [ | ||
| 630 | - ("Y", (&got.y, &want.y)), | ||
| 631 | - ("U", (&got.u, &want.u)), | ||
| 632 | - ("V", (&got.v, &want.v)), | ||
| 633 | - ] { | ||
| 634 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 635 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 636 | - eprintln!( | ||
| 637 | - "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \ | ||
| 638 | - diff at ({}, {}) got {} want {} ({} samples differ)", | ||
| 639 | - at % stride, | ||
| 640 | - at / stride, | ||
| 641 | - g[at], | ||
| 642 | - w[at], | ||
| 643 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 644 | - ); | ||
| 645 | - // Magnitude separates a deblock/prediction difference | ||
| 646 | - // (all |d| == 1) from an entropy desync (large, | ||
| 647 | - // arbitrary): the first thing r2 needs to know. | ||
| 648 | - let maxd = g | ||
| 649 | - .iter() | ||
| 650 | - .zip(w.iter()) | ||
| 651 | - .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b))) | ||
| 652 | - .max() | ||
| 653 | - .unwrap_or(0); | ||
| 654 | - let rows: std::collections::BTreeSet<usize> = g | ||
| 655 | - .iter() | ||
| 656 | - .zip(w.iter()) | ||
| 657 | - .enumerate() | ||
| 658 | - .filter(|(_, (a, b))| a != b) | ||
| 659 | - .map(|(k, _)| k / stride) | ||
| 660 | - .collect(); | ||
| 661 | - eprintln!( | ||
| 662 | - "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} max \ | ||
| 663 | - |diff|={maxd}, rows {:?}..{:?}", | ||
| 664 | - rows.iter().next(), | ||
| 665 | - rows.iter().next_back() | ||
| 666 | - ); | ||
| 667 | - } | ||
| 668 | - assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})"); | ||
| 669 | - } | ||
| 670 | - } | ||
| 671 | - compared += 1; | ||
| 672 | - if delta.iter().all(|d| *d == 0) { | ||
| 673 | - uncounted_exact += 1; | ||
| 674 | - refusals.push(format!( | ||
| 675 | - "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra rect strip on the \ | ||
| 676 | - inter path" | ||
| 677 | - )); | ||
| 678 | - } | ||
| 679 | - for k in 0..3 { | ||
| 680 | - shapes[k] += delta[k]; | ||
| 681 | - } | ||
| 682 | - if shapes.iter().filter(|n| **n > 0).count() >= 2 { | ||
| 683 | - break; | ||
| 684 | - } | ||
| 685 | - } | ||
| 686 | - gate_buckets( | ||
| 687 | - NAME, | ||
| 688 | - compared - uncounted_exact, | ||
| 689 | - uncounted_exact, | ||
| 690 | - refusals.len() - uncounted_exact as usize, | ||
| 691 | - ); | ||
| 692 | - eprintln!( | ||
| 693 | - "{NAME} ({bit_depth}-bit): compared {compared} streams, intra rect strips in inter \ | ||
| 694 | - frames per shape: 64x32/32x64={} 32x16/16x32={} 16x8/8x16={}; refusals:\n{}", | ||
| 695 | - shapes[0], | ||
| 696 | - shapes[1], | ||
| 697 | - shapes[2], | ||
| 698 | - refusals.join("\n") | ||
| 699 | - ); | ||
| 700 | - assert!( | ||
| 701 | - compared > 0, | ||
| 702 | - "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \ | ||
| 703 | - pixel-compared:\n{}", | ||
| 704 | - refusals.join("\n") | ||
| 705 | - ); | ||
| 706 | - // MEASURED (r1, 90 attempts; r2 re-ran the 45-attempt sweep at both | ||
| 707 | - // depths): only the 32x16/16x32 class is REACHABLE on this branch -- | ||
| 708 | - // the inter tile path refuses any SB-level partition other than | ||
| 709 | - // NONE/SPLIT, so a 64x32/32x64 intra strip cannot be produced at all, | ||
| 710 | - // and every 16x8/8x16 candidate stops at a sub-16 refusal owned by | ||
| 711 | - // another lane. So the bar is that class, hard, not "two of three": | ||
| 712 | - // a green run still cannot come from a stream that fired nothing. | ||
| 713 | - assert!( | ||
| 714 | - shapes[1] > 0, | ||
| 715 | - "{NAME} ({bit_depth}-bit): no 32x16/16x32 intra rect strip fired over \ | ||
| 716 | - {compared} compared streams (64-level={} 32-level={} 16-level={})", | ||
| 717 | - shapes[0], | ||
| 718 | - shapes[1], | ||
| 719 | - shapes[2] | ||
| 720 | - ); | ||
| 721 | - } | ||
| 722 | - | ||
| 723 | - pub(super) fn tx_select_inter_gate(bit_depth: u32) { | ||
| 724 | - if !have_ffmpeg() { | ||
| 725 | - eprintln!( | ||
| 726 | - "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg" | ||
| 727 | - ); | ||
| 728 | - return; | ||
| 729 | - } | ||
| 730 | - if !have_aomenc() { | ||
| 731 | - eprintln!( | ||
| 732 | - "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}", | ||
| 733 | - aomenc_path().display() | ||
| 734 | - ); | ||
| 735 | - return; | ||
| 736 | - } | ||
| 737 | - let (width, height, frame_count) = (64usize, 64usize, 4usize); | ||
| 738 | - let mut refusals = Vec::new(); | ||
| 739 | - let mut uncounted_exact = 0u32; | ||
| 740 | - for attempt in 0..40u32 { | ||
| 741 | - let seed = 42 + attempt; | ||
| 742 | - // Detail is what makes aomenc's RD prefer a split transform; a | ||
| 743 | - // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s | ||
| 744 | - // fractal boundary is the same source the sibling intra tx-select | ||
| 745 | - // gate uses, at a different `start_scale` per attempt. | ||
| 746 | - let source = format!( | ||
| 747 | - "mandelbrot=size=64x64:start_scale={}:rate=25", | ||
| 748 | - 5.0 - f64::from(attempt) * 0.06 | ||
| 749 | - ); | ||
| 750 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 751 | - .args([ | ||
| 752 | - "-v", | ||
| 753 | - "error", | ||
| 754 | - "-f", | ||
| 755 | - "lavfi", | ||
| 756 | - "-i", | ||
| 757 | - &source, | ||
| 758 | - // Desaturated chroma: `uv_mode` stays DC_PRED, so the | ||
| 759 | - // still-refused directional-chroma gap never fires and | ||
| 760 | - // luma detail alone drives the transform split. | ||
| 761 | - "-vf", | ||
| 762 | - "hue=s=0", | ||
| 763 | - "-pix_fmt", | ||
| 764 | - if bit_depth == 10 { | ||
| 765 | - "yuv420p10le" | ||
| 766 | - } else { | ||
| 767 | - "yuv420p" | ||
| 768 | - }, | ||
| 769 | - // y4m carries no official 10-bit tag; ffmpeg writes one | ||
| 770 | - // only under `-strict -1` (a no-op at 8 bit). | ||
| 771 | - "-strict", | ||
| 772 | - "-1", | ||
| 773 | - "-t", | ||
| 774 | - "0.16", | ||
| 775 | - "-f", | ||
| 776 | - "yuv4mpegpipe", | ||
| 777 | - "-strict", | ||
| 778 | - "-1", | ||
| 779 | - "-", | ||
| 780 | - ]) | ||
| 781 | - .stdin(Stdio::null()) | ||
| 782 | - .stdout(Stdio::piped()) | ||
| 783 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 784 | - .expect("ffmpeg failed to run"); | ||
| 785 | - assert!( | ||
| 786 | - y4m.status.success(), | ||
| 787 | - "ffmpeg fixture: {}", | ||
| 788 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 789 | - ); | ||
| 790 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 791 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 792 | - } else { | ||
| 793 | - &[] | ||
| 794 | - }; | ||
| 795 | - let out = run_with_stdin( | ||
| 796 | - Command::new(aomenc_path()).args(depth_args).args([ | ||
| 797 | - // lane-defon r1: explicit on-value (aomenc keeps the FIRST | ||
| 798 | - // occurrence, so overrides go before the base list). | ||
| 799 | - "--enable-tx-size-search=1", | ||
| 800 | - "--codec=av1", | ||
| 801 | - "--passes=1", | ||
| 802 | - "--end-usage=q", | ||
| 803 | - "--cq-level=55", | ||
| 804 | - "--cpu-used=0", | ||
| 805 | - "--lag-in-frames=0", | ||
| 806 | - "--auto-alt-ref=0", | ||
| 807 | - "--kf-max-dist=1000", | ||
| 808 | - "--threads=1", | ||
| 809 | - "--row-mt=0", | ||
| 810 | - "--enable-order-hint=0", | ||
| 811 | - "--enable-warped-motion=0", | ||
| 812 | - "--enable-obmc=0", | ||
| 813 | - "--enable-masked-comp=0", | ||
| 814 | - "--enable-interintra-comp=0", | ||
| 815 | - "--enable-dist-wtd-comp=0", | ||
| 816 | - "--enable-diff-wtd-comp=0", | ||
| 817 | - "--enable-onesided-comp=0", | ||
| 818 | - "--enable-interintra-wedge=0", | ||
| 819 | - "--enable-smooth-interintra=0", | ||
| 820 | - "--enable-rect-partitions=0", | ||
| 821 | - "--enable-ab-partitions=0", | ||
| 822 | - "--enable-1to4-partitions=0", | ||
| 823 | - "--enable-filter-intra=0", | ||
| 824 | - "--enable-smooth-intra=0", | ||
| 825 | - "--enable-paeth-intra=0", | ||
| 826 | - "--enable-directional-intra=0", | ||
| 827 | - "--enable-angle-delta=0", | ||
| 828 | - // DELIBERATELY ABSENT: --enable-tx-size-search=0. | ||
| 829 | - "--enable-cdef=0", | ||
| 830 | - "--enable-restoration=0", | ||
| 831 | - "--max-partition-size=32", | ||
| 832 | - // Sub-16 inter partitions are a separate named refusal | ||
| 833 | - // (this decoder codes no inter block below 16x16 through | ||
| 834 | - // the square path this gate drives), and detailed content | ||
| 835 | - // makes aomenc's RD reach for them on nearly every seed. | ||
| 836 | - "--min-partition-size=16", | ||
| 837 | - "--enable-palette=0", | ||
| 838 | - "--enable-intrabc=0", | ||
| 839 | - "--enable-cfl-intra=0", | ||
| 840 | - "--enable-ref-frame-mvs=0", | ||
| 841 | - "--obu", | ||
| 842 | - "-o", | ||
| 843 | - "-", | ||
| 844 | - "-", | ||
| 845 | - ]), | ||
| 846 | - &y4m.stdout, | ||
| 847 | - ); | ||
| 848 | - assert!( | ||
| 849 | - out.status.success(), | ||
| 850 | - "aomenc refused the fixture: {}", | ||
| 851 | - String::from_utf8_lossy(&out.stderr) | ||
| 852 | - ); | ||
| 853 | - let stream = out.stdout; | ||
| 854 | - let (reads_before, hits_before) = | ||
| 855 | - (decode::txfm_split_reads(), decode::txfm_split_hits()); | ||
| 856 | - let frames = match decode_stream(&stream) { | ||
| 857 | - Ok(frames) => frames, | ||
| 858 | - Err(e) => { | ||
| 859 | - let msg = e.to_string(); | ||
| 860 | - assert!( | ||
| 861 | - msg.contains("unsupported"), | ||
| 862 | - "tx-select inter decode failed outright (seed {seed}): {msg}" | ||
| 863 | - ); | ||
| 864 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 865 | - continue; | ||
| 866 | - } | ||
| 867 | - }; | ||
| 868 | - let (reads, hits) = ( | ||
| 869 | - decode::txfm_split_reads() - reads_before, | ||
| 870 | - decode::txfm_split_hits() - hits_before, | ||
| 871 | - ); | ||
| 872 | - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | ||
| 873 | - // is ALWAYS pixel-compared below; the hit counter only decides whether | ||
| 874 | - // the attempt counts toward the firing total. | ||
| 875 | - let counted = hits != 0; | ||
| 876 | - if !counted { | ||
| 877 | - uncounted_exact += 1; | ||
| 878 | - refusals.push(format!( | ||
| 879 | - "seed {seed}: decoded and pixel-compared, but no block took a txfm_split \ | ||
| 880 | - ({reads} symbols read)" | ||
| 881 | - )); | ||
| 882 | - } | ||
| 883 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 884 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 885 | - } else { | ||
| 886 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 887 | - }; | ||
| 888 | - assert_eq!(frames.len(), frame_count); | ||
| 889 | - eprintln!( | ||
| 890 | - "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}" | ||
| 891 | - ); | ||
| 892 | - // Name the first differing sample before the assert fires: a | ||
| 893 | - // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for | ||
| 894 | - // locating a desync. | ||
| 895 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 896 | - for (plane, (g, w)) in [ | ||
| 897 | - ("Y", (&got.y, &want.y)), | ||
| 898 | - ("U", (&got.u, &want.u)), | ||
| 899 | - ("V", (&got.v, &want.v)), | ||
| 900 | - ] { | ||
| 901 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 902 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 903 | - eprintln!( | ||
| 904 | - "txselect gate seed={seed}: frame {i} {plane} first diff at \ | ||
| 905 | - ({}, {}) got {} want {} ({} samples differ)", | ||
| 906 | - at % stride, | ||
| 907 | - at / stride, | ||
| 908 | - g[at], | ||
| 909 | - w[at], | ||
| 910 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 911 | - ); | ||
| 912 | - let coords: Vec<String> = g | ||
| 913 | - .iter() | ||
| 914 | - .zip(w.iter()) | ||
| 915 | - .enumerate() | ||
| 916 | - .filter(|(_, (a, b))| a != b) | ||
| 917 | - .take(12) | ||
| 918 | - .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride)) | ||
| 919 | - .collect(); | ||
| 920 | - eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}"); | ||
| 921 | - } | ||
| 922 | - } | ||
| 923 | - } | ||
| 924 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 925 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 926 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 927 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 928 | - } | ||
| 929 | - if counted { | ||
| 930 | - gate_buckets( | ||
| 931 | - &format!("tx_select_inter_gate({bit_depth})"), | ||
| 932 | - 1, | ||
| 933 | - uncounted_exact, | ||
| 934 | - refusals.len() - uncounted_exact as usize, | ||
| 935 | - ); | ||
| 936 | - return; | ||
| 937 | - } | ||
| 938 | - } | ||
| 939 | - gate_buckets( | ||
| 940 | - &format!("tx_select_inter_gate({bit_depth})"), | ||
| 941 | - 0, | ||
| 942 | - uncounted_exact, | ||
| 943 | - refusals.len() - uncounted_exact as usize, | ||
| 944 | - ); | ||
| 945 | - panic!( | ||
| 946 | - "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}", | ||
| 947 | - refusals.join("\n") | ||
| 948 | - ); | ||
| 949 | - } | ||
| 950 | - | ||
| 951 | - pub(super) fn intra_in_inter_split_tx_gate(bit_depth: u32) { | ||
| 952 | - let name = format!("intra_in_inter_split_tx_gate({bit_depth})"); | ||
| 953 | - if !have_ffmpeg() { | ||
| 954 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 955 | - return; | ||
| 956 | - } | ||
| 957 | - if !have_aomenc() { | ||
| 958 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 959 | - return; | ||
| 960 | - } | ||
| 961 | - let (width, height, frame_count) = (64usize, 64usize, 8usize); | ||
| 962 | - let mut refusals = Vec::new(); | ||
| 963 | - let mut uncounted_exact = 0u32; | ||
| 964 | - for attempt in 0..40u32 { | ||
| 965 | - let seed = 42 + attempt; | ||
| 966 | - // A zooming fractal: every frame moves (so the sequence is | ||
| 967 | - // genuinely inter-coded) and keeps sharp new detail entering at | ||
| 968 | - // the borders, which is what makes aomenc's RD choose an INTRA | ||
| 969 | - // block inside an inter frame -- and then split its transform. | ||
| 970 | - // A zooming fractal with a hard CUT halfway (`overlay` switching | ||
| 971 | - // a second, unrelated fractal on at frame 4): after the cut every | ||
| 972 | - // block is unpredictable from the reference, which is what makes | ||
| 973 | - // aomenc code INTRA blocks inside an inter frame -- and at this | ||
| 974 | - // cq the RD then splits their transforms. | ||
| 975 | - let source = format!( | ||
| 976 | - "mandelbrot=size=64x64:start_scale={}:rate=25[a];\ | ||
| 977 | - mandelbrot=size=64x64:start_scale={}:rate=25[b];\ | ||
| 978 | - [a][b]overlay=enable='gte(n,4)'", | ||
| 979 | - 5.0 - f64::from(attempt) * 0.06, | ||
| 980 | - 0.9 + f64::from(attempt) * 0.11 | ||
| 981 | - ); | ||
| 982 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 983 | - .args([ | ||
| 984 | - "-v", | ||
| 985 | - "error", | ||
| 986 | - "-f", | ||
| 987 | - "lavfi", | ||
| 988 | - "-i", | ||
| 989 | - &source, | ||
| 990 | - // Desaturated chroma keeps `uv_mode` on DC_PRED, so the | ||
| 991 | - // still-refused directional-chroma gaps never fire and | ||
| 992 | - // luma detail alone drives the transform split. | ||
| 993 | - "-vf", | ||
| 994 | - "hue=s=0", | ||
| 995 | - "-pix_fmt", | ||
| 996 | - if bit_depth == 10 { | ||
| 997 | - "yuv420p10le" | ||
| 998 | - } else { | ||
| 999 | - "yuv420p" | ||
| 1000 | - }, | ||
| 1001 | - "-strict", | ||
| 1002 | - "-1", | ||
| 1003 | - "-t", | ||
| 1004 | - "0.32", | ||
| 1005 | - "-f", | ||
| 1006 | - "yuv4mpegpipe", | ||
| 1007 | - "-strict", | ||
| 1008 | - "-1", | ||
| 1009 | - "-", | ||
| 1010 | - ]) | ||
| 1011 | - .stdin(Stdio::null()) | ||
| 1012 | - .stdout(Stdio::piped()) | ||
| 1013 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1014 | - .expect("ffmpeg failed to run"); | ||
| 1015 | - assert!( | ||
| 1016 | - y4m.status.success(), | ||
| 1017 | - "ffmpeg fixture: {}", | ||
| 1018 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1019 | - ); | ||
| 1020 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1021 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1022 | - } else { | ||
| 1023 | - &[] | ||
| 1024 | - }; | ||
| 1025 | - let out = run_with_stdin( | ||
| 1026 | - Command::new(aomenc_path()).args(depth_args).args([ | ||
| 1027 | - "--codec=av1", | ||
| 1028 | - "--passes=1", | ||
| 1029 | - "--end-usage=q", | ||
| 1030 | - "--cq-level=30", | ||
| 1031 | - "--cpu-used=0", | ||
| 1032 | - "--lag-in-frames=0", | ||
| 1033 | - "--auto-alt-ref=0", | ||
| 1034 | - // One key frame only: every later frame is an inter frame, | ||
| 1035 | - // which is where this gate's intra blocks must sit. The | ||
| 1036 | - // MIN distance is what stops aomenc's scene-cut detector | ||
| 1037 | - // from inserting a second key frame at the cut this gate's | ||
| 1038 | - // source deliberately contains. | ||
| 1039 | - "--kf-max-dist=1000", | ||
| 1040 | - "--kf-min-dist=1000", | ||
| 1041 | - "--threads=1", | ||
| 1042 | - "--row-mt=0", | ||
| 1043 | - "--enable-order-hint=0", | ||
| 1044 | - "--enable-warped-motion=0", | ||
| 1045 | - "--enable-obmc=0", | ||
| 1046 | - "--enable-masked-comp=0", | ||
| 1047 | - "--enable-interintra-comp=0", | ||
| 1048 | - "--enable-dist-wtd-comp=0", | ||
| 1049 | - "--enable-diff-wtd-comp=0", | ||
| 1050 | - "--enable-onesided-comp=0", | ||
| 1051 | - "--enable-interintra-wedge=0", | ||
| 1052 | - "--enable-smooth-interintra=0", | ||
| 1053 | - "--enable-ab-partitions=0", | ||
| 1054 | - "--enable-1to4-partitions=0", | ||
| 1055 | - "--enable-filter-intra=0", | ||
| 1056 | - "--enable-smooth-intra=0", | ||
| 1057 | - "--enable-paeth-intra=0", | ||
| 1058 | - "--enable-directional-intra=0", | ||
| 1059 | - "--enable-angle-delta=0", | ||
| 1060 | - "--enable-cdef=0", | ||
| 1061 | - "--enable-restoration=0", | ||
| 1062 | - "--enable-palette=0", | ||
| 1063 | - "--enable-intrabc=0", | ||
| 1064 | - "--enable-cfl-intra=0", | ||
| 1065 | - "--enable-ref-frame-mvs=0", | ||
| 1066 | - // Per-arm overrides go LAST (aomenc keeps the last | ||
| 1067 | - // occurrence of a repeated --enable-* flag): the intra | ||
| 1068 | - // tx_depth symbol only exists under TX_MODE_SELECT, and | ||
| 1069 | - // rect partitions are a separate named refusal. | ||
| 1070 | - "--enable-tx-size-search=1", | ||
| 1071 | - "--enable-rect-partitions=0", | ||
| 1072 | - "--max-partition-size=32", | ||
| 1073 | - // Sub-16 inter partitions are a separate named refusal, | ||
| 1074 | - // as is the 8x8 intra leaf's own TX_4X4 split. | ||
| 1075 | - "--min-partition-size=16", | ||
| 1076 | - "--obu", | ||
| 1077 | - "-o", | ||
| 1078 | - "-", | ||
| 1079 | - "-", | ||
| 1080 | - ]), | ||
| 1081 | - &y4m.stdout, | ||
| 1082 | - ); | ||
| 1083 | - assert!( | ||
| 1084 | - out.status.success(), | ||
| 1085 | - "aomenc refused the fixture: {}", | ||
| 1086 | - String::from_utf8_lossy(&out.stderr) | ||
| 1087 | - ); | ||
| 1088 | - let stream = out.stdout; | ||
| 1089 | - let before = decode::intra_in_inter_split_tx_hits(); | ||
| 1090 | - let frames = match decode_stream(&stream) { | ||
| 1091 | - Ok(frames) => frames, | ||
| 1092 | - Err(e) => { | ||
| 1093 | - let msg = e.to_string(); | ||
| 1094 | - assert!( | ||
| 1095 | - msg.contains("unsupported"), | ||
| 1096 | - "{name} decode failed outright (seed {seed}): {msg}" | ||
| 1097 | - ); | ||
| 1098 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 1099 | - continue; | ||
| 1100 | - } | ||
| 1101 | - }; | ||
| 1102 | - let after = decode::intra_in_inter_split_tx_hits(); | ||
| 1103 | - let mut per_size = [0usize; 4]; | ||
| 1104 | - for i in 0..4 { | ||
| 1105 | - per_size[i] = after[i] - before[i]; | ||
| 1106 | - } | ||
| 1107 | - // class [[gate-skips-on-its-own-failure]]: a decode that | ||
| 1108 | - // succeeded is ALWAYS pixel-compared below; the counter only | ||
| 1109 | - // decides whether the attempt counts as firing. | ||
| 1110 | - let counted = per_size.iter().sum::<usize>() != 0; | ||
| 1111 | - if !counted { | ||
| 1112 | - uncounted_exact += 1; | ||
| 1113 | - refusals.push(format!( | ||
| 1114 | - "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ | ||
| 1115 | - frame split its transform" | ||
| 1116 | - )); | ||
| 1117 | - } | ||
| 1118 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1119 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1120 | - } else { | ||
| 1121 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1122 | - }; | ||
| 1123 | - assert_eq!(frames.len(), frame_count); | ||
| 1124 | - eprintln!( | ||
| 1125 | - "{name} seed={seed}: split intra-in-inter blocks 8x8={} 16x16={} 32x32={} \ | ||
| 1126 | - 64x64={}", | ||
| 1127 | - per_size[0], per_size[1], per_size[2], per_size[3] | ||
| 1128 | - ); | ||
| 1129 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1130 | - for (plane, (g, w)) in [ | ||
| 1131 | - ("Y", (&got.y, &want.y)), | ||
| 1132 | - ("U", (&got.u, &want.u)), | ||
| 1133 | - ("V", (&got.v, &want.v)), | ||
| 1134 | - ] { | ||
| 1135 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 1136 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 1137 | - eprintln!( | ||
| 1138 | - "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 1139 | - want {} ({} samples differ)", | ||
| 1140 | - at % stride, | ||
| 1141 | - at / stride, | ||
| 1142 | - g[at], | ||
| 1143 | - w[at], | ||
| 1144 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 1145 | - ); | ||
| 1146 | - } | ||
| 1147 | - } | ||
| 1148 | - } | ||
| 1149 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1150 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 1151 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 1152 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 1153 | - } | ||
| 1154 | - if counted { | ||
| 1155 | - gate_buckets( | ||
| 1156 | - &name, | ||
| 1157 | - 1, | ||
| 1158 | - uncounted_exact, | ||
| 1159 | - refusals.len() - uncounted_exact as usize, | ||
| 1160 | - ); | ||
| 1161 | - return; | ||
| 1162 | - } | ||
| 1163 | - } | ||
| 1164 | - gate_buckets( | ||
| 1165 | - &name, | ||
| 1166 | - 0, | ||
| 1167 | - uncounted_exact, | ||
| 1168 | - refusals.len() - uncounted_exact as usize, | ||
| 1169 | - ); | ||
| 1170 | - panic!( | ||
| 1171 | - "{name} never observed a split-transform intra block in an inter frame:\n{}", | ||
| 1172 | - refusals.join("\n") | ||
| 1173 | - ); | ||
| 1174 | - } | ||
| 1175 | - | ||
| 1176 | - pub(super) fn filter_intra_in_inter_gate(bit_depth: u32) { | ||
| 1177 | - let name = format!("filter_intra_in_inter_gate({bit_depth})"); | ||
| 1178 | - if !have_ffmpeg() { | ||
| 1179 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1180 | - return; | ||
| 1181 | - } | ||
| 1182 | - if !have_aomenc() { | ||
| 1183 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1184 | - return; | ||
| 1185 | - } | ||
| 1186 | - let (width, height, frame_count) = (64usize, 64usize, 8usize); | ||
| 1187 | - let mut refusals = Vec::new(); | ||
| 1188 | - let mut uncounted_exact = 0u32; | ||
| 1189 | - for attempt in 0..40u32 { | ||
| 1190 | - let seed = 42 + attempt; | ||
| 1191 | - // A zooming fractal: every frame moves (so the sequence is | ||
| 1192 | - // genuinely inter-coded) and keeps sharp new detail entering at | ||
| 1193 | - // the borders, which is what makes aomenc's RD choose an INTRA | ||
| 1194 | - // block inside an inter frame -- and then split its transform. | ||
| 1195 | - // A zooming fractal with a hard CUT halfway (`overlay` switching | ||
| 1196 | - // a second, unrelated fractal on at frame 4): after the cut every | ||
| 1197 | - // block is unpredictable from the reference, which is what makes | ||
| 1198 | - // aomenc code INTRA blocks inside an inter frame -- and at this | ||
| 1199 | - // cq the RD then splits their transforms. | ||
| 1200 | - let source = format!( | ||
| 1201 | - "mandelbrot=size=64x64:start_scale={}:rate=25[a];\ | ||
| 1202 | - mandelbrot=size=64x64:start_scale={}:rate=25[b];\ | ||
| 1203 | - [a][b]overlay=enable='gte(n,4)'", | ||
| 1204 | - 5.0 - f64::from(attempt) * 0.06, | ||
| 1205 | - 0.9 + f64::from(attempt) * 0.11 | ||
| 1206 | - ); | ||
| 1207 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1208 | - .args([ | ||
| 1209 | - "-v", | ||
| 1210 | - "error", | ||
| 1211 | - "-f", | ||
| 1212 | - "lavfi", | ||
| 1213 | - "-i", | ||
| 1214 | - &source, | ||
| 1215 | - // Desaturated chroma keeps `uv_mode` on DC_PRED, so the | ||
| 1216 | - // still-refused directional-chroma gaps never fire and | ||
| 1217 | - // luma detail alone drives the transform split. | ||
| 1218 | - "-vf", | ||
| 1219 | - "hue=s=0", | ||
| 1220 | - "-pix_fmt", | ||
| 1221 | - if bit_depth == 10 { | ||
| 1222 | - "yuv420p10le" | ||
| 1223 | - } else { | ||
| 1224 | - "yuv420p" | ||
| 1225 | - }, | ||
| 1226 | - "-strict", | ||
| 1227 | - "-1", | ||
| 1228 | - "-t", | ||
| 1229 | - "0.32", | ||
| 1230 | - "-f", | ||
| 1231 | - "yuv4mpegpipe", | ||
| 1232 | - "-strict", | ||
| 1233 | - "-1", | ||
| 1234 | - "-", | ||
| 1235 | - ]) | ||
| 1236 | - .stdin(Stdio::null()) | ||
| 1237 | - .stdout(Stdio::piped()) | ||
| 1238 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1239 | - .expect("ffmpeg failed to run"); | ||
| 1240 | - assert!( | ||
| 1241 | - y4m.status.success(), | ||
| 1242 | - "ffmpeg fixture: {}", | ||
| 1243 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1244 | - ); | ||
| 1245 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1246 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1247 | - } else { | ||
| 1248 | - &[] | ||
| 1249 | - }; | ||
| 1250 | - let out = run_with_stdin( | ||
| 1251 | - Command::new(aomenc_path()).args(depth_args).args([ | ||
| 1252 | - "--codec=av1", | ||
| 1253 | - "--passes=1", | ||
| 1254 | - "--end-usage=q", | ||
| 1255 | - "--cq-level=30", | ||
| 1256 | - "--cpu-used=0", | ||
| 1257 | - "--lag-in-frames=0", | ||
| 1258 | - "--auto-alt-ref=0", | ||
| 1259 | - // One key frame only: every later frame is an inter frame, | ||
| 1260 | - // which is where this gate's intra blocks must sit. The | ||
| 1261 | - // MIN distance is what stops aomenc's scene-cut detector | ||
| 1262 | - // from inserting a second key frame at the cut this gate's | ||
| 1263 | - // source deliberately contains. | ||
| 1264 | - "--kf-max-dist=1000", | ||
| 1265 | - "--kf-min-dist=1000", | ||
| 1266 | - "--threads=1", | ||
| 1267 | - "--row-mt=0", | ||
| 1268 | - "--enable-order-hint=0", | ||
| 1269 | - "--enable-warped-motion=0", | ||
| 1270 | - "--enable-obmc=0", | ||
| 1271 | - "--enable-masked-comp=0", | ||
| 1272 | - "--enable-interintra-comp=0", | ||
| 1273 | - "--enable-dist-wtd-comp=0", | ||
| 1274 | - "--enable-diff-wtd-comp=0", | ||
| 1275 | - "--enable-onesided-comp=0", | ||
| 1276 | - "--enable-interintra-wedge=0", | ||
| 1277 | - "--enable-smooth-interintra=0", | ||
| 1278 | - "--enable-ab-partitions=0", | ||
| 1279 | - "--enable-1to4-partitions=0", | ||
| 1280 | - "--enable-smooth-intra=0", | ||
| 1281 | - "--enable-paeth-intra=0", | ||
| 1282 | - "--enable-directional-intra=0", | ||
| 1283 | - "--enable-angle-delta=0", | ||
| 1284 | - "--enable-cdef=0", | ||
| 1285 | - "--enable-restoration=0", | ||
| 1286 | - "--enable-palette=0", | ||
| 1287 | - "--enable-intrabc=0", | ||
| 1288 | - "--enable-cfl-intra=0", | ||
| 1289 | - "--enable-ref-frame-mvs=0", | ||
| 1290 | - // Per-arm overrides go LAST (aomenc keeps the last | ||
| 1291 | - // occurrence of a repeated --enable-* flag): the intra | ||
| 1292 | - // tx_depth symbol only exists under TX_MODE_SELECT, and | ||
| 1293 | - // rect partitions are a separate named refusal. | ||
| 1294 | - "--enable-filter-intra=1", | ||
| 1295 | - "--enable-tx-size-search=1", | ||
| 1296 | - "--enable-rect-partitions=0", | ||
| 1297 | - "--max-partition-size=32", | ||
| 1298 | - // Sub-16 inter partitions are a separate named refusal, | ||
| 1299 | - // as is the 8x8 intra leaf's own TX_4X4 split. | ||
| 1300 | - "--min-partition-size=16", | ||
| 1301 | - "--obu", | ||
| 1302 | - "-o", | ||
| 1303 | - "-", | ||
| 1304 | - "-", | ||
| 1305 | - ]), | ||
| 1306 | - &y4m.stdout, | ||
| 1307 | - ); | ||
| 1308 | - assert!( | ||
| 1309 | - out.status.success(), | ||
| 1310 | - "aomenc refused the fixture: {}", | ||
| 1311 | - String::from_utf8_lossy(&out.stderr) | ||
| 1312 | - ); | ||
| 1313 | - let stream = out.stdout; | ||
| 1314 | - let before = decode::intra_in_inter_filter_intra_hits(); | ||
| 1315 | - let frames = match decode_stream(&stream) { | ||
| 1316 | - Ok(frames) => frames, | ||
| 1317 | - Err(e) => { | ||
| 1318 | - let msg = e.to_string(); | ||
| 1319 | - assert!( | ||
| 1320 | - msg.contains("unsupported"), | ||
| 1321 | - "{name} decode failed outright (seed {seed}): {msg}" | ||
| 1322 | - ); | ||
| 1323 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 1324 | - continue; | ||
| 1325 | - } | ||
| 1326 | - }; | ||
| 1327 | - let fired = decode::intra_in_inter_filter_intra_hits() - before; | ||
| 1328 | - // class [[gate-skips-on-its-own-failure]]: a decode that | ||
| 1329 | - // succeeded is ALWAYS pixel-compared below; the counter only | ||
| 1330 | - // decides whether the attempt counts as firing. | ||
| 1331 | - let counted = fired != 0; | ||
| 1332 | - if !counted { | ||
| 1333 | - uncounted_exact += 1; | ||
| 1334 | - refusals.push(format!( | ||
| 1335 | - "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ | ||
| 1336 | - frame used filter intra" | ||
| 1337 | - )); | ||
| 1338 | - } | ||
| 1339 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1340 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1341 | - } else { | ||
| 1342 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1343 | - }; | ||
| 1344 | - assert_eq!(frames.len(), frame_count); | ||
| 1345 | - eprintln!("{name} seed={seed}: filter-intra blocks inside inter frames = {fired}"); | ||
| 1346 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1347 | - for (plane, (g, w)) in [ | ||
| 1348 | - ("Y", (&got.y, &want.y)), | ||
| 1349 | - ("U", (&got.u, &want.u)), | ||
| 1350 | - ("V", (&got.v, &want.v)), | ||
| 1351 | - ] { | ||
| 1352 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 1353 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 1354 | - eprintln!( | ||
| 1355 | - "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 1356 | - want {} ({} samples differ)", | ||
| 1357 | - at % stride, | ||
| 1358 | - at / stride, | ||
| 1359 | - g[at], | ||
| 1360 | - w[at], | ||
| 1361 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 1362 | - ); | ||
| 1363 | - } | ||
| 1364 | - } | ||
| 1365 | - } | ||
| 1366 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1367 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 1368 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 1369 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 1370 | - } | ||
| 1371 | - if counted { | ||
| 1372 | - gate_buckets( | ||
| 1373 | - &name, | ||
| 1374 | - 1, | ||
| 1375 | - uncounted_exact, | ||
| 1376 | - refusals.len() - uncounted_exact as usize, | ||
| 1377 | - ); | ||
| 1378 | - return; | ||
| 1379 | - } | ||
| 1380 | - } | ||
| 1381 | - gate_buckets( | ||
| 1382 | - &name, | ||
| 1383 | - 0, | ||
| 1384 | - uncounted_exact, | ||
| 1385 | - refusals.len() - uncounted_exact as usize, | ||
| 1386 | - ); | ||
| 1387 | - panic!( | ||
| 1388 | - "{name} never observed a filter-intra intra block in an inter frame:\n{}", | ||
| 1389 | - refusals.join("\n") | ||
| 1390 | - ); | ||
| 1391 | - } | ||
| 1392 | - | ||
| 1393 | - pub(super) fn angle_delta_in_inter_gate(bit_depth: u32, min_partition: &str) { | ||
| 1394 | - let name = format!("angle_delta_in_inter_gate({bit_depth}, min={min_partition})"); | ||
| 1395 | - let leaf8 = min_partition.ends_with('8'); | ||
| 1396 | - assert!( | ||
| 1397 | - !leaf8, | ||
| 1398 | - "the 8x8-leaf arm keeps its refusal; see the module note" | ||
| 1399 | - ); | ||
| 1400 | - if !have_ffmpeg() { | ||
| 1401 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1402 | - return; | ||
| 1403 | - } | ||
| 1404 | - if !have_aomenc() { | ||
| 1405 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1406 | - return; | ||
| 1407 | - } | ||
| 1408 | - let (width, height, frame_count) = (64usize, 64usize, 8usize); | ||
| 1409 | - let mut refusals = Vec::new(); | ||
| 1410 | - let mut uncounted_exact = 0u32; | ||
| 1411 | - for attempt in 0..40u32 { | ||
| 1412 | - let seed = 42 + attempt; | ||
| 1413 | - // A zooming fractal: every frame moves (so the sequence is | ||
| 1414 | - // genuinely inter-coded) and keeps sharp new detail entering at | ||
| 1415 | - // the borders, which is what makes aomenc's RD choose an INTRA | ||
| 1416 | - // block inside an inter frame -- and then split its transform. | ||
| 1417 | - // A zooming fractal with a hard CUT halfway (`overlay` switching | ||
| 1418 | - // a second, unrelated fractal on at frame 4): after the cut every | ||
| 1419 | - // block is unpredictable from the reference, which is what makes | ||
| 1420 | - // aomenc code INTRA blocks inside an inter frame -- and at this | ||
| 1421 | - // cq the RD then splits their transforms. | ||
| 1422 | - let source = format!( | ||
| 1423 | - "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ | ||
| 1424 | - mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ | ||
| 1425 | - [a][b]overlay=enable='gte(n,4)'", | ||
| 1426 | - 5.0 - f64::from(attempt) * 0.06, | ||
| 1427 | - 0.9 + f64::from(attempt) * 0.11 | ||
| 1428 | - ); | ||
| 1429 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1430 | - .args([ | ||
| 1431 | - "-v", | ||
| 1432 | - "error", | ||
| 1433 | - "-f", | ||
| 1434 | - "lavfi", | ||
| 1435 | - "-i", | ||
| 1436 | - &source, | ||
| 1437 | - // Desaturated chroma keeps `uv_mode` on DC_PRED, so the | ||
| 1438 | - // still-refused directional-chroma gaps never fire and | ||
| 1439 | - // luma detail alone drives the transform split. | ||
| 1440 | - "-vf", | ||
| 1441 | - "hue=s=0", | ||
| 1442 | - "-pix_fmt", | ||
| 1443 | - if bit_depth == 10 { | ||
| 1444 | - "yuv420p10le" | ||
| 1445 | - } else { | ||
| 1446 | - "yuv420p" | ||
| 1447 | - }, | ||
| 1448 | - "-strict", | ||
| 1449 | - "-1", | ||
| 1450 | - "-t", | ||
| 1451 | - "0.32", | ||
| 1452 | - "-f", | ||
| 1453 | - "yuv4mpegpipe", | ||
| 1454 | - "-strict", | ||
| 1455 | - "-1", | ||
| 1456 | - "-", | ||
| 1457 | - ]) | ||
| 1458 | - .stdin(Stdio::null()) | ||
| 1459 | - .stdout(Stdio::piped()) | ||
| 1460 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1461 | - .expect("ffmpeg failed to run"); | ||
| 1462 | - assert!( | ||
| 1463 | - y4m.status.success(), | ||
| 1464 | - "ffmpeg fixture: {}", | ||
| 1465 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1466 | - ); | ||
| 1467 | - // The 8x8-leaf arm is fenced by three sibling refusals (non-DC | ||
| 1468 | - // chroma on an 8x8 leaf, its TX_4X4 split, sub-16 rect inter | ||
| 1469 | - // leaves), so it sweeps the quantiser as well as the source: a | ||
| 1470 | - // coarser q is what pushes the RD to directional intra at 8x8. | ||
| 1471 | - let cq = if leaf8 { | ||
| 1472 | - format!("--cq-level={}", 20 + (attempt % 5) * 10) | ||
| 1473 | - } else { | ||
| 1474 | - "--cq-level=30".to_string() | ||
| 1475 | - }; | ||
| 1476 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1477 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1478 | - } else { | ||
| 1479 | - &[] | ||
| 1480 | - }; | ||
| 1481 | - let out = run_with_stdin( | ||
| 1482 | - Command::new(aomenc_path()).args(depth_args).args([ | ||
| 1483 | - "--codec=av1", | ||
| 1484 | - "--passes=1", | ||
| 1485 | - "--end-usage=q", | ||
| 1486 | - &cq, | ||
| 1487 | - "--cpu-used=0", | ||
| 1488 | - "--lag-in-frames=0", | ||
| 1489 | - "--auto-alt-ref=0", | ||
| 1490 | - // One key frame only: every later frame is an inter frame, | ||
| 1491 | - // which is where this gate's intra blocks must sit. The | ||
| 1492 | - // MIN distance is what stops aomenc's scene-cut detector | ||
| 1493 | - // from inserting a second key frame at the cut this gate's | ||
| 1494 | - // source deliberately contains. | ||
| 1495 | - "--kf-max-dist=1000", | ||
| 1496 | - "--kf-min-dist=1000", | ||
| 1497 | - "--threads=1", | ||
| 1498 | - "--row-mt=0", | ||
| 1499 | - "--enable-order-hint=0", | ||
| 1500 | - "--enable-warped-motion=0", | ||
| 1501 | - "--enable-obmc=0", | ||
| 1502 | - "--enable-masked-comp=0", | ||
| 1503 | - "--enable-interintra-comp=0", | ||
| 1504 | - "--enable-dist-wtd-comp=0", | ||
| 1505 | - "--enable-diff-wtd-comp=0", | ||
| 1506 | - "--enable-onesided-comp=0", | ||
| 1507 | - "--enable-interintra-wedge=0", | ||
| 1508 | - "--enable-smooth-interintra=0", | ||
| 1509 | - "--enable-ab-partitions=0", | ||
| 1510 | - "--enable-1to4-partitions=0", | ||
| 1511 | - "--enable-smooth-intra=0", | ||
| 1512 | - "--enable-paeth-intra=0", | ||
| 1513 | - "--enable-directional-intra=1", | ||
| 1514 | - "--enable-angle-delta=1", | ||
| 1515 | - "--enable-cdef=0", | ||
| 1516 | - "--enable-restoration=0", | ||
| 1517 | - "--enable-palette=0", | ||
| 1518 | - "--enable-intrabc=0", | ||
| 1519 | - "--enable-cfl-intra=0", | ||
| 1520 | - "--enable-ref-frame-mvs=0", | ||
| 1521 | - // Per-arm overrides go LAST (aomenc keeps the last | ||
| 1522 | - // occurrence of a repeated --enable-* flag): the intra | ||
| 1523 | - // tx_depth symbol only exists under TX_MODE_SELECT, and | ||
| 1524 | - // rect partitions are a separate named refusal. | ||
| 1525 | - "--enable-filter-intra=1", | ||
| 1526 | - "--enable-tx-size-search=1", | ||
| 1527 | - "--enable-rect-partitions=0", | ||
| 1528 | - "--max-partition-size=32", | ||
| 1529 | - // Sub-16 inter partitions are a separate named refusal, | ||
| 1530 | - // as is the 8x8 intra leaf's own TX_4X4 split. | ||
| 1531 | - min_partition, | ||
| 1532 | - "--obu", | ||
| 1533 | - "-o", | ||
| 1534 | - "-", | ||
| 1535 | - "-", | ||
| 1536 | - ]), | ||
| 1537 | - &y4m.stdout, | ||
| 1538 | - ); | ||
| 1539 | - assert!( | ||
| 1540 | - out.status.success(), | ||
| 1541 | - "aomenc refused the fixture: {}", | ||
| 1542 | - String::from_utf8_lossy(&out.stderr) | ||
| 1543 | - ); | ||
| 1544 | - let stream = out.stdout; | ||
| 1545 | - let before = decode::intra_in_inter_angle_delta_y_hits(); | ||
| 1546 | - let before_uv = decode::intra_in_inter_angle_delta_uv_hits(); | ||
| 1547 | - let frames = match decode_stream(&stream) { | ||
| 1548 | - Ok(frames) => frames, | ||
| 1549 | - Err(e) => { | ||
| 1550 | - let msg = e.to_string(); | ||
| 1551 | - assert!( | ||
| 1552 | - msg.contains("unsupported"), | ||
| 1553 | - "{name} decode failed outright (seed {seed}): {msg}" | ||
| 1554 | - ); | ||
| 1555 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 1556 | - continue; | ||
| 1557 | - } | ||
| 1558 | - }; | ||
| 1559 | - let fired = decode::intra_in_inter_angle_delta_y_hits() - before; | ||
| 1560 | - let fired_uv = decode::intra_in_inter_angle_delta_uv_hits() - before_uv; | ||
| 1561 | - // class [[gate-skips-on-its-own-failure]]: a decode that | ||
| 1562 | - // succeeded is ALWAYS pixel-compared below; the counter only | ||
| 1563 | - // decides whether the attempt counts as firing. | ||
| 1564 | - let counted = fired != 0; | ||
| 1565 | - if !counted { | ||
| 1566 | - uncounted_exact += 1; | ||
| 1567 | - refusals.push(format!( | ||
| 1568 | - "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ | ||
| 1569 | - frame carried a nonzero angle_delta_y" | ||
| 1570 | - )); | ||
| 1571 | - } | ||
| 1572 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1573 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1574 | - } else { | ||
| 1575 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1576 | - }; | ||
| 1577 | - assert_eq!(frames.len(), frame_count); | ||
| 1578 | - eprintln!( | ||
| 1579 | - "{name} seed={seed}: intra-in-inter blocks with a nonzero angle_delta_y = \ | ||
| 1580 | - {fired}, angle_delta_uv = {fired_uv}" | ||
| 1581 | - ); | ||
| 1582 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1583 | - for (plane, (g, w)) in [ | ||
| 1584 | - ("Y", (&got.y, &want.y)), | ||
| 1585 | - ("U", (&got.u, &want.u)), | ||
| 1586 | - ("V", (&got.v, &want.v)), | ||
| 1587 | - ] { | ||
| 1588 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 1589 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 1590 | - eprintln!( | ||
| 1591 | - "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 1592 | - want {} ({} samples differ)", | ||
| 1593 | - at % stride, | ||
| 1594 | - at / stride, | ||
| 1595 | - g[at], | ||
| 1596 | - w[at], | ||
| 1597 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 1598 | - ); | ||
| 1599 | - } | ||
| 1600 | - } | ||
| 1601 | - } | ||
| 1602 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1603 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 1604 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 1605 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 1606 | - } | ||
| 1607 | - if counted { | ||
| 1608 | - gate_buckets( | ||
| 1609 | - &name, | ||
| 1610 | - 1, | ||
| 1611 | - uncounted_exact, | ||
| 1612 | - refusals.len() - uncounted_exact as usize, | ||
| 1613 | - ); | ||
| 1614 | - return; | ||
| 1615 | - } | ||
| 1616 | - } | ||
| 1617 | - gate_buckets( | ||
| 1618 | - &name, | ||
| 1619 | - 0, | ||
| 1620 | - uncounted_exact, | ||
| 1621 | - refusals.len() - uncounted_exact as usize, | ||
| 1622 | - ); | ||
| 1623 | - panic!( | ||
| 1624 | - "{name} never observed a nonzero angle delta on an intra block in an inter \ | ||
| 1625 | - frame:\n{}", | ||
| 1626 | - refusals.join("\n") | ||
| 1627 | - ); | ||
| 1628 | - } | ||
| 1629 | - | ||
| 1630 | - pub(super) fn uv_mode_in_inter8_gate(bit_depth: u32, tile_columns: u32) { | ||
| 1631 | - let name = format!("uv_mode_in_inter8_gate({bit_depth}, tiles={tile_columns})"); | ||
| 1632 | - if !have_ffmpeg() { | ||
| 1633 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1634 | - return; | ||
| 1635 | - } | ||
| 1636 | - if !have_aomenc() { | ||
| 1637 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1638 | - return; | ||
| 1639 | - } | ||
| 1640 | - let (width, height, frame_count) = (192usize, 128usize, 8usize); | ||
| 1641 | - let mut refusals = Vec::new(); | ||
| 1642 | - let mut uncounted_exact = 0u32; | ||
| 1643 | - let mut totals = (0usize, 0usize, 0usize); | ||
| 1644 | - for attempt in 0..30u32 { | ||
| 1645 | - let seed = 42 + attempt; | ||
| 1646 | - // A zooming fractal with a hard CUT at frame 4 (`overlay` | ||
| 1647 | - // switching a second, unrelated fractal on): after the cut a block | ||
| 1648 | - // is unpredictable from the reference, which is what makes aomenc | ||
| 1649 | - // code INTRA blocks inside an inter frame. Chroma is NOT | ||
| 1650 | - // desaturated here (every sibling inter gate passes `hue=s=0`) -- | ||
| 1651 | - // real chroma detail is exactly what pushes the chroma RD off | ||
| 1652 | - // DC_PRED. `noise` carries its own explicit seed (lavfi | ||
| 1653 | - // `gradients` ignores its seed; class [[seeded-fixture-not-reproducible]]). | ||
| 1654 | - let source = format!( | ||
| 1655 | - "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ | ||
| 1656 | - mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ | ||
| 1657 | - [a][b]overlay=enable='gte(n,4)',noise=alls=12:allf=t+u:all_seed={seed}", | ||
| 1658 | - 5.0 - f64::from(attempt) * 0.06, | ||
| 1659 | - 0.9 + f64::from(attempt) * 0.11 | ||
| 1660 | - ); | ||
| 1661 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1662 | - .args([ | ||
| 1663 | - "-v", | ||
| 1664 | - "error", | ||
| 1665 | - "-f", | ||
| 1666 | - "lavfi", | ||
| 1667 | - "-i", | ||
| 1668 | - &source, | ||
| 1669 | - "-pix_fmt", | ||
| 1670 | - if bit_depth == 10 { | ||
| 1671 | - "yuv420p10le" | ||
| 1672 | - } else { | ||
| 1673 | - "yuv420p" | ||
| 1674 | - }, | ||
| 1675 | - "-strict", | ||
| 1676 | - "-1", | ||
| 1677 | - "-t", | ||
| 1678 | - "0.32", | ||
| 1679 | - "-f", | ||
| 1680 | - "yuv4mpegpipe", | ||
| 1681 | - "-strict", | ||
| 1682 | - "-1", | ||
| 1683 | - "-", | ||
| 1684 | - ]) | ||
| 1685 | - .stdin(Stdio::null()) | ||
| 1686 | - .stdout(Stdio::piped()) | ||
| 1687 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1688 | - .expect("ffmpeg failed to run"); | ||
| 1689 | - assert!( | ||
| 1690 | - y4m.status.success(), | ||
| 1691 | - "ffmpeg fixture: {}", | ||
| 1692 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1693 | - ); | ||
| 1694 | - // A coarser quantiser is what pushes the chroma RD to a cheap | ||
| 1695 | - // non-DC mode on a small block; sweep 12..40 (the low end is what | ||
| 1696 | - // lane-cdef's cq12 arm needs). | ||
| 1697 | - let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7); | ||
| 1698 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1699 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1700 | - } else { | ||
| 1701 | - &[] | ||
| 1702 | - }; | ||
| 1703 | - let tiles = format!("--tile-columns={}", tile_columns - 1); | ||
| 1704 | - // The y4m goes through a FILE, not aomenc's stdin: this gate's | ||
| 1705 | - // stream is ~100 KB, bigger than a pipe buffer, so an aomenc that | ||
| 1706 | - // is still being fed on stdin blocks writing its stdout and the | ||
| 1707 | - // test blocks writing its stdin -- a hard deadlock (measured | ||
| 1708 | - // here, 3 min into attempt 0, class [[gate-loader-slurps-whole-file]]). | ||
| 1709 | - // The path is PID-keyed (class [[pid-keyed-temp-path]]). | ||
| 1710 | - let y4m_path = std::env::temp_dir().join(format!( | ||
| 1711 | - "ec-av1-uv8-{}-{bit_depth}-{tile_columns}-{seed}.y4m", | ||
| 1712 | - std::process::id() | ||
| 1713 | - )); | ||
| 1714 | - std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture"); | ||
| 1715 | - let child = Command::new(aomenc_path()) | ||
| 1716 | - .args(depth_args) | ||
| 1717 | - .args([ | ||
| 1718 | - "--codec=av1", | ||
| 1719 | - "--passes=1", | ||
| 1720 | - "--end-usage=q", | ||
| 1721 | - &cq, | ||
| 1722 | - "--cpu-used=0", | ||
| 1723 | - "--lag-in-frames=0", | ||
| 1724 | - "--auto-alt-ref=0", | ||
| 1725 | - "--kf-max-dist=9999", | ||
| 1726 | - "--kf-min-dist=9999", | ||
| 1727 | - "--threads=1", | ||
| 1728 | - "--row-mt=0", | ||
| 1729 | - &tiles, | ||
| 1730 | - "--enable-order-hint=0", | ||
| 1731 | - "--enable-warped-motion=0", | ||
| 1732 | - "--enable-obmc=0", | ||
| 1733 | - "--enable-masked-comp=0", | ||
| 1734 | - "--enable-interintra-comp=0", | ||
| 1735 | - "--enable-dist-wtd-comp=0", | ||
| 1736 | - "--enable-diff-wtd-comp=0", | ||
| 1737 | - "--enable-onesided-comp=0", | ||
| 1738 | - "--enable-interintra-wedge=0", | ||
| 1739 | - "--enable-smooth-interintra=0", | ||
| 1740 | - "--enable-ab-partitions=0", | ||
| 1741 | - "--enable-1to4-partitions=0", | ||
| 1742 | - "--enable-cdef=0", | ||
| 1743 | - "--enable-restoration=0", | ||
| 1744 | - "--enable-palette=0", | ||
| 1745 | - "--enable-intrabc=0", | ||
| 1746 | - "--enable-ref-frame-mvs=0", | ||
| 1747 | - // Per-arm overrides go LAST (aomenc keeps the LAST | ||
| 1748 | - // occurrence of a repeated --enable-* flag). The three | ||
| 1749 | - // chroma intra tools this gate is about, plus the fences | ||
| 1750 | - // that keep the leaf's SIBLING refusals (its TX_4X4 | ||
| 1751 | - // split, a nonzero angle delta, sub-16 rect inter leaves) | ||
| 1752 | - // out of the way. | ||
| 1753 | - "--enable-cfl-intra=1", | ||
| 1754 | - "--enable-smooth-intra=1", | ||
| 1755 | - "--enable-paeth-intra=1", | ||
| 1756 | - "--enable-directional-intra=1", | ||
| 1757 | - "--enable-angle-delta=0", | ||
| 1758 | - "--enable-tx-size-search=0", | ||
| 1759 | - "--enable-rect-partitions=0", | ||
| 1760 | - "--min-partition-size=8", | ||
| 1761 | - "--max-partition-size=32", | ||
| 1762 | - "--obu", | ||
| 1763 | - "-o", | ||
| 1764 | - "-", | ||
| 1765 | - ]) | ||
| 1766 | - .arg(&y4m_path) | ||
| 1767 | - .stdin(Stdio::null()) | ||
| 1768 | - .stdout(Stdio::piped()) | ||
| 1769 | - .stderr(Stdio::piped()) | ||
| 1770 | - .spawn() | ||
| 1771 | - .expect("aomenc failed to start"); | ||
| 1772 | - let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1773 | - let _ = std::fs::remove_file(&y4m_path); | ||
| 1774 | - assert!( | ||
| 1775 | - out.status.success(), | ||
| 1776 | - "aomenc refused the fixture: {}", | ||
| 1777 | - String::from_utf8_lossy(&out.stderr) | ||
| 1778 | - ); | ||
| 1779 | - let stream = out.stdout; | ||
| 1780 | - let before = decode::intra_in_inter8_uv_hits(); | ||
| 1781 | - let frames = match decode_stream(&stream) { | ||
| 1782 | - Ok(frames) => frames, | ||
| 1783 | - Err(e) => { | ||
| 1784 | - let msg = e.to_string(); | ||
| 1785 | - assert!( | ||
| 1786 | - msg.contains("unsupported"), | ||
| 1787 | - "{name} decode failed outright (seed {seed}): {msg}" | ||
| 1788 | - ); | ||
| 1789 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 1790 | - continue; | ||
| 1791 | - } | ||
| 1792 | - }; | ||
| 1793 | - let now = decode::intra_in_inter8_uv_hits(); | ||
| 1794 | - // class [[counter-from-refused-stream]]: per-attempt deltas, and | ||
| 1795 | - // only for an attempt that decoded to the end and is pixel- | ||
| 1796 | - // compared below. | ||
| 1797 | - let fired = (now.0 - before.0, now.1 - before.1, now.2 - before.2); | ||
| 1798 | - totals = (totals.0 + fired.0, totals.1 + fired.1, totals.2 + fired.2); | ||
| 1799 | - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | ||
| 1800 | - // is ALWAYS pixel-compared; the counter only decides whether the | ||
| 1801 | - // attempt counts as firing. | ||
| 1802 | - // lane-uv8 r3: every one of the three chroma classes this gate | ||
| 1803 | - // exists for (directional, smooth/paeth, CfL) must fire on the | ||
| 1804 | - // SAME pixel-compared attempt -- a sum-nonzero predicate would | ||
| 1805 | - // pass on an attempt that only ever hit DC-adjacent CfL. | ||
| 1806 | - let counted = fired.0 > 0 && fired.1 > 0 && fired.2 > 0; | ||
| 1807 | - if !counted { | ||
| 1808 | - uncounted_exact += 1; | ||
| 1809 | - refusals.push(format!( | ||
| 1810 | - "seed {seed}: decoded and pixel-compared, but no 8x8 intra leaf in an inter \ | ||
| 1811 | - frame carried a non-DC uv_mode" | ||
| 1812 | - )); | ||
| 1813 | - } | ||
| 1814 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1815 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1816 | - } else { | ||
| 1817 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1818 | - }; | ||
| 1819 | - assert_eq!(frames.len(), frame_count); | ||
| 1820 | - eprintln!( | ||
| 1821 | - "{name} seed={seed} {cq}: 8x8 intra-in-inter leaves with a non-DC uv_mode -- \ | ||
| 1822 | - directional {}, smooth/paeth {}, CfL {}", | ||
| 1823 | - fired.0, fired.1, fired.2 | ||
| 1824 | - ); | ||
| 1825 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1826 | - for (plane, (g, w)) in [ | ||
| 1827 | - ("Y", (&got.y, &want.y)), | ||
| 1828 | - ("U", (&got.u, &want.u)), | ||
| 1829 | - ("V", (&got.v, &want.v)), | ||
| 1830 | - ] { | ||
| 1831 | - let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 1832 | - if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 1833 | - eprintln!( | ||
| 1834 | - "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 1835 | - want {} ({} samples differ)", | ||
| 1836 | - at % stride, | ||
| 1837 | - at / stride, | ||
| 1838 | - g[at], | ||
| 1839 | - w[at], | ||
| 1840 | - g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 1841 | - ); | ||
| 1842 | - } | ||
| 1843 | - } | ||
| 1844 | - } | ||
| 1845 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1846 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 1847 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 1848 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 1849 | - } | ||
| 1850 | - if counted { | ||
| 1851 | - gate_buckets( | ||
| 1852 | - &name, | ||
| 1853 | - 1, | ||
| 1854 | - uncounted_exact, | ||
| 1855 | - refusals.len() - uncounted_exact as usize, | ||
| 1856 | - ); | ||
| 1857 | - return; | ||
| 1858 | - } | ||
| 1859 | - } | ||
| 1860 | - gate_buckets( | ||
| 1861 | - &name, | ||
| 1862 | - 0, | ||
| 1863 | - uncounted_exact, | ||
| 1864 | - refusals.len() - uncounted_exact as usize, | ||
| 1865 | - ); | ||
| 1866 | - panic!( | ||
| 1867 | - "{name} never observed a non-DC uv_mode on an 8x8 intra leaf in an inter frame \ | ||
| 1868 | - (totals dir/smooth/cfl {totals:?}):\n{}", | ||
| 1869 | - refusals.join("\n") | ||
| 1870 | - ); | ||
| 1871 | - } | ||
| 1872 | - | ||
| 1873 | - pub(super) fn tx_split_angle_in_inter8_gate(bit_depth: u32) { | ||
| 1874 | - let name = format!("tx_split_angle_in_inter8_gate({bit_depth})"); | ||
| 1875 | - if !have_ffmpeg() { | ||
| 1876 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1877 | - return; | ||
| 1878 | - } | ||
| 1879 | - if !have_aomenc() { | ||
| 1880 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1881 | - return; | ||
| 1882 | - } | ||
| 1883 | - let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 1884 | - let mut refusals = Vec::new(); | ||
| 1885 | - let mut uncounted_exact = 0u32; | ||
| 1886 | - let mut counted_exact = 0u32; | ||
| 1887 | - let mut totals = (0usize, 0usize); | ||
| 1888 | - for attempt in 0..30u32 { | ||
| 1889 | - let seed = 42 + attempt; | ||
| 1890 | - // Same zoom + hard-cut fractal source the sibling uv_mode gate | ||
| 1891 | - // uses (a cut is what makes aomenc code INTRA blocks inside an | ||
| 1892 | - // inter frame); `noise` carries an explicit seed (class | ||
| 1893 | - // [[seeded-fixture-not-reproducible]]). | ||
| 1894 | - let source = format!( | ||
| 1895 | - "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ | ||
| 1896 | - mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ | ||
| 1897 | - [a][b]overlay=enable='gte(n,3)',noise=alls=12:allf=t+u:all_seed={seed}", | ||
| 1898 | - 5.0 - f64::from(attempt) * 0.06, | ||
| 1899 | - 0.9 + f64::from(attempt) * 0.11 | ||
| 1900 | - ); | ||
| 1901 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1902 | - .args([ | ||
| 1903 | - "-v", | ||
| 1904 | - "error", | ||
| 1905 | - "-f", | ||
| 1906 | - "lavfi", | ||
| 1907 | - "-i", | ||
| 1908 | - &source, | ||
| 1909 | - "-pix_fmt", | ||
| 1910 | - if bit_depth == 10 { | ||
| 1911 | - "yuv420p10le" | ||
| 1912 | - } else { | ||
| 1913 | - "yuv420p" | ||
| 1914 | - }, | ||
| 1915 | - "-strict", | ||
| 1916 | - "-1", | ||
| 1917 | - "-t", | ||
| 1918 | - "0.24", | ||
| 1919 | - "-f", | ||
| 1920 | - "yuv4mpegpipe", | ||
| 1921 | - "-strict", | ||
| 1922 | - "-1", | ||
| 1923 | - "-", | ||
| 1924 | - ]) | ||
| 1925 | - .stdin(Stdio::null()) | ||
| 1926 | - .stdout(Stdio::piped()) | ||
| 1927 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1928 | - .expect("ffmpeg failed to run"); | ||
| 1929 | - assert!( | ||
| 1930 | - y4m.status.success(), | ||
| 1931 | - "ffmpeg fixture: {}", | ||
| 1932 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1933 | - ); | ||
| 1934 | - let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7); | ||
| 1935 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1936 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1937 | - } else { | ||
| 1938 | - &[] | ||
| 1939 | - }; | ||
| 1940 | - // The y4m goes through a PID-keyed FILE, never aomenc's stdin | ||
| 1941 | - // (pipe deadlock, class [[gate-loader-slurps-whole-file]]). | ||
| 1942 | - let y4m_path = std::env::temp_dir().join(format!( | ||
| 1943 | - "ec-av1-leaf8tx-{}-{bit_depth}-{seed}.y4m", | ||
| 1944 | - std::process::id() | ||
| 1945 | - )); | ||
| 1946 | - std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture"); | ||
| 1947 | - let child = Command::new(aomenc_path()) | ||
| 1948 | - .args(depth_args) | ||
| 1949 | - .args([ | ||
| 1950 | - "--codec=av1", | ||
| 1951 | - "--passes=1", | ||
| 1952 | - "--end-usage=q", | ||
| 1953 | - &cq, | ||
| 1954 | - "--cpu-used=0", | ||
| 1955 | - "--lag-in-frames=0", | ||
| 1956 | - "--auto-alt-ref=0", | ||
| 1957 | - "--kf-max-dist=9999", | ||
| 1958 | - "--kf-min-dist=9999", | ||
| 1959 | - "--threads=1", | ||
| 1960 | - "--row-mt=0", | ||
| 1961 | - "--tile-columns=0", | ||
| 1962 | - "--enable-order-hint=0", | ||
| 1963 | - "--enable-warped-motion=0", | ||
| 1964 | - "--enable-obmc=0", | ||
| 1965 | - "--enable-masked-comp=0", | ||
| 1966 | - "--enable-interintra-comp=0", | ||
| 1967 | - "--enable-dist-wtd-comp=0", | ||
| 1968 | - "--enable-diff-wtd-comp=0", | ||
| 1969 | - "--enable-onesided-comp=0", | ||
| 1970 | - "--enable-interintra-wedge=0", | ||
| 1971 | - "--enable-smooth-interintra=0", | ||
| 1972 | - "--enable-ab-partitions=0", | ||
| 1973 | - "--enable-1to4-partitions=0", | ||
| 1974 | - "--enable-cdef=0", | ||
| 1975 | - "--enable-restoration=0", | ||
| 1976 | - "--enable-palette=0", | ||
| 1977 | - "--enable-intrabc=0", | ||
| 1978 | - "--enable-ref-frame-mvs=0", | ||
| 1979 | - // Per-arm overrides LAST (aomenc keeps the last | ||
| 1980 | - // occurrence of a repeated --enable-* flag). Rect | ||
| 1981 | - // partitions stay off so the leaf's unrelated sub-16 rect | ||
| 1982 | - // inter refusal never fires. | ||
| 1983 | - "--enable-rect-partitions=0", | ||
| 1984 | - "--enable-tx-size-search=1", | ||
| 1985 | - "--enable-angle-delta=1", | ||
| 1986 | - "--enable-directional-intra=1", | ||
| 1987 | - "--min-partition-size=8", | ||
| 1988 | - "--max-partition-size=32", | ||
| 1989 | - "--obu", | ||
| 1990 | - "-o", | ||
| 1991 | - "-", | ||
| 1992 | - ]) | ||
| 1993 | - // r1 diagnostic: EC_LEAF8TX_CONTROL=1 turns THIS lane's two | ||
| 1994 | - // tools back off (last occurrence of a repeated --enable-* | ||
| 1995 | - // wins), so any mismatch that survives is not this lane's. | ||
| 1996 | - .args(match std::env::var("EC_LEAF8TX_CONTROL").as_deref() { | ||
| 1997 | - Ok("angle") => vec!["--enable-tx-size-search=0", "--enable-angle-delta=1"], | ||
| 1998 | - Ok("tx") => vec!["--enable-tx-size-search=1", "--enable-angle-delta=0"], | ||
| 1999 | - Ok("tx8") => vec![ | ||
| 2000 | - "--enable-tx-size-search=1", | ||
crates/ec-av1/src/stream/tests/gates_b.rsdeleted+0 -2804
Diff too large; view file
| @@ -1,2804 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | -use super::gates_a::*; | ||
| 4 | - | ||
| 5 | - /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1` | ||
| 6 | - /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound | ||
| 7 | - /// block lands under a ROTZOOM/AFFINE model and each of its two references | ||
| 8 | - /// is predicted through its OWN global warp | ||
| 9 | - /// (`crate::warp::warp_affine_compound`, libaom `av1_warp_plane` with | ||
| 10 | - /// `conv_params->is_compound`) rather than translationally. Before r1 that | ||
| 11 | - /// path was SILENTLY WRONG -- no refusal named it, both taps went through | ||
| 12 | - /// `mc::predict_compound_intermediate`. `compound_warp_hits() > 0` is a | ||
| 13 | - /// hard assert: a run where the encoder never emitted one proves nothing. | ||
| 14 | - /// A decode error or a pixel mismatch is a FAILURE, never a skip. | ||
| 15 | - pub(super) fn run_compound_global_warp_gate(name: &str, bd: u32, min_part: u32, leaf8_assert: bool) { | ||
| 16 | - let _gate_lock = lock_gate_counters(); | ||
| 17 | - assert!(have_ffmpeg(), "{name}: ffmpeg required"); | ||
| 18 | - assert!( | ||
| 19 | - have_aomenc(), | ||
| 20 | - "{name}: no aomenc at {}", | ||
| 21 | - aomenc_path().display() | ||
| 22 | - ); | ||
| 23 | - let (width, height, frame_count) = (64usize, 64usize, 24usize); | ||
| 24 | - let before = crate::decode::compound_warp_hits(); | ||
| 25 | - let before8 = crate::decode::compound_warp_hits_8(); | ||
| 26 | - let mut matched = 0u32; | ||
| 27 | - let mut named_refusals = 0u32; | ||
| 28 | - let mut attempts = 0u32; | ||
| 29 | - for cq in [32u32, 45, 55] { | ||
| 30 | - for (i, rate) in [0.010f64, 0.022].iter().enumerate() { | ||
| 31 | - attempts += 1; | ||
| 32 | - let duration = frame_count as f64 / 25.0; | ||
| 33 | - // A rotation about the frame centre plus a slow zoom is what | ||
| 34 | - // aomenc's global-motion search fits a ROTZOOM/AFFINE model to; | ||
| 35 | - // mandelbrot gives it real, non-flat texture to track. | ||
| 36 | - let source = format!( | ||
| 37 | - "mandelbrot=size={w}x{h}:rate=25:start_x={sx}:start_y=-0.4,\ | ||
| 38 | - rotate=a={rate}*n:ow={w}:oh={h}:c=black,scale={width}:{height}", | ||
| 39 | - w = width * 2, | ||
| 40 | - h = height * 2, | ||
| 41 | - sx = -0.6 + 0.01 * (i as f64), | ||
| 42 | - ); | ||
| 43 | - let pix_fmt = match bd { | ||
| 44 | - 8 => "yuv420p", | ||
| 45 | - 10 => "yuv420p10le", | ||
| 46 | - _ => "yuv420p12le", | ||
| 47 | - }; | ||
| 48 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 49 | - .args([ | ||
| 50 | - "-v", | ||
| 51 | - "error", | ||
| 52 | - "-f", | ||
| 53 | - "lavfi", | ||
| 54 | - "-i", | ||
| 55 | - &source, | ||
| 56 | - "-t", | ||
| 57 | - &duration.to_string(), | ||
| 58 | - "-pix_fmt", | ||
| 59 | - pix_fmt, | ||
| 60 | - "-strict", | ||
| 61 | - "-1", | ||
| 62 | - "-f", | ||
| 63 | - "yuv4mpegpipe", | ||
| 64 | - "-", | ||
| 65 | - ]) | ||
| 66 | - .stdin(Stdio::null()) | ||
| 67 | - .stdout(Stdio::piped()) | ||
| 68 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 69 | - .expect("ffmpeg failed to run"); | ||
| 70 | - assert!( | ||
| 71 | - y4m.status.success(), | ||
| 72 | - "ffmpeg fixture: {}", | ||
| 73 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 74 | - ); | ||
| 75 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 76 | - let (in_depth_arg, depth_arg) = ( | ||
| 77 | - format!("--input-bit-depth={bd}"), | ||
| 78 | - format!("--bit-depth={bd}"), | ||
| 79 | - ); | ||
| 80 | - let mut args: Vec<&str> = vec![ | ||
| 81 | - "--codec=av1", | ||
| 82 | - "--passes=1", | ||
| 83 | - "--end-usage=q", | ||
| 84 | - &cq_arg, | ||
| 85 | - "--cpu-used=0", | ||
| 86 | - "--kf-max-dist=1000", | ||
| 87 | - "--threads=1", | ||
| 88 | - "--row-mt=0", | ||
| 89 | - "--auto-alt-ref=1", | ||
| 90 | - "--lag-in-frames=25", | ||
| 91 | - "--enable-fwd-kf=0", | ||
| 92 | - "--enable-order-hint=1", | ||
| 93 | - // the two tools this gate exists for | ||
| 94 | - "--enable-global-motion=1", | ||
| 95 | - "--enable-dist-wtd-comp=1", | ||
| 96 | - "--enable-warped-motion=1", | ||
| 97 | - "--enable-obmc=1", | ||
| 98 | - "--enable-masked-comp=1", | ||
| 99 | - "--enable-onesided-comp=0", | ||
| 100 | - "--enable-interintra-comp=1", | ||
| 101 | - "--enable-interintra-wedge=0", | ||
| 102 | - "--enable-smooth-interintra=1", | ||
| 103 | - "--tune-content=default", | ||
| 104 | - // partition/intra tools this decoder does not code yet -- | ||
| 105 | - // same exclusion list every compound gate carries. | ||
| 106 | - "--enable-rect-partitions=0", | ||
| 107 | - "--enable-ab-partitions=0", | ||
| 108 | - "--enable-1to4-partitions=0", | ||
| 109 | - "--enable-filter-intra=0", | ||
| 110 | - "--enable-smooth-intra=0", | ||
| 111 | - "--enable-paeth-intra=0", | ||
| 112 | - "--enable-directional-intra=0", | ||
| 113 | - "--enable-angle-delta=0", | ||
| 114 | - "--enable-tx-size-search=0", | ||
| 115 | - "--enable-cdef=0", | ||
| 116 | - "--enable-restoration=0", | ||
| 117 | - "--max-partition-size=32", | ||
| 118 | - "--enable-palette=0", | ||
| 119 | - "--enable-intrabc=0", | ||
| 120 | - "--enable-cfl-intra=0", | ||
| 121 | - "--enable-ref-frame-mvs=0", | ||
| 122 | - ]; | ||
| 123 | - let min_part_arg = format!("--min-partition-size={min_part}"); | ||
| 124 | - args.push(min_part_arg.as_str()); | ||
| 125 | - if bd != 8 { | ||
| 126 | - args.extend_from_slice(&[in_depth_arg.as_str(), depth_arg.as_str()]); | ||
| 127 | - } | ||
| 128 | - args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 129 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 130 | - assert!( | ||
| 131 | - out.status.success(), | ||
| 132 | - "aomenc refused the fixture: {}", | ||
| 133 | - String::from_utf8_lossy(&out.stderr) | ||
| 134 | - ); | ||
| 135 | - let stream = out.stdout; | ||
| 136 | - let frames = match decode_stream(&stream) { | ||
| 137 | - Err(e) => { | ||
| 138 | - let msg = e.to_string(); | ||
| 139 | - assert!( | ||
| 140 | - msg.contains("unsupported"), | ||
| 141 | - "{name} failed outright, not a named refusal (cq {cq}): {msg}" | ||
| 142 | - ); | ||
| 143 | - assert!( | ||
| 144 | - !msg.contains("warp"), | ||
| 145 | - "{name} refused on warp (cq {cq}) -- warp decode is ported: {msg}" | ||
| 146 | - ); | ||
| 147 | - named_refusals += 1; | ||
| 148 | - eprintln!("{name} cq {cq} rate {rate} refusal: {msg}"); | ||
| 149 | - continue; | ||
| 150 | - } | ||
| 151 | - Ok(frames) => frames, | ||
| 152 | - }; | ||
| 153 | - let want = match bd { | ||
| 154 | - 8 => ffmpeg_decode_sequence(&stream, width, height, frame_count), | ||
| 155 | - 10 => ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count), | ||
| 156 | - _ => ffmpeg_decode_sequence_12bit(&stream, width, height, frame_count), | ||
| 157 | - }; | ||
| 158 | - assert_eq!(frames.len(), frame_count); | ||
| 159 | - if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") | ||
| 160 | - && frames | ||
| 161 | - .iter() | ||
| 162 | - .zip(&want) | ||
| 163 | - .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v) | ||
| 164 | - { | ||
| 165 | - std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 166 | - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}"); | ||
| 167 | - } | ||
| 168 | - for (i, (got, want)) in frames.iter().zip(&want).enumerate() { | ||
| 169 | - assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (cq {cq})"); | ||
| 170 | - assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (cq {cq})"); | ||
| 171 | - assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (cq {cq})"); | ||
| 172 | - } | ||
| 173 | - matched += 1; | ||
| 174 | - } | ||
| 175 | - } | ||
| 176 | - let hits = crate::decode::compound_warp_hits() - before; | ||
| 177 | - let hits8 = crate::decode::compound_warp_hits_8() - before8; | ||
| 178 | - eprintln!( | ||
| 179 | - "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \ | ||
| 180 | - compound_warp_hits={hits} compound_warp_hits_8={hits8}" | ||
| 181 | - ); | ||
| 182 | - if leaf8_assert { | ||
| 183 | - assert!( | ||
| 184 | - hits8 > 0, | ||
| 185 | - "{name}: no 8x8 COMPOUND leaf was predicted through a per-ref global \ | ||
| 186 | - warp ({hits} bigger compound warp blocks, {matched} matches, \ | ||
| 187 | - {named_refusals} refusals of {attempts}) -- gate vacuous" | ||
| 188 | - ); | ||
| 189 | - } else { | ||
| 190 | - assert!( | ||
| 191 | - hits > 0, | ||
| 192 | - "{name}: no compound block was predicted through a per-ref global warp \ | ||
| 193 | - ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous" | ||
| 194 | - ); | ||
| 195 | - } | ||
| 196 | - assert!( | ||
| 197 | - matched > 0, | ||
| 198 | - "{name}: every attempt refused -- no pixel comparison ran" | ||
| 199 | - ); | ||
| 200 | - } | ||
| 201 | - | ||
| 202 | - /// lane-fimv r1 (class `wrong-alphabet-same-value`): libaom | ||
| 203 | - /// `motion_mode_allowed` (blockd.h ~1484) only returns `WARPED_CAUSAL` | ||
| 204 | - /// when `!xd->cur_frame_force_integer_mv`, so on a frame whose header set | ||
| 205 | - /// `force_integer_mv` an otherwise warp-eligible block reads the 2-symbol | ||
| 206 | - /// `obmc_cdf`, not the 3-symbol `motion_mode_cdf`. This decoder read the | ||
| 207 | - /// 3-symbol alphabet there (silent tile desync, no refusal named it). | ||
| 208 | - /// | ||
| 209 | - /// The fixture is screen content that is mostly static with only | ||
| 210 | - /// whole-pixel motion, which is exactly what aomenc's own | ||
| 211 | - /// `av1_is_integer_mv` (`encoder_utils.c:1357`, >=80% of blocks matching | ||
| 212 | - /// their collocated block) needs to set `cur_frame_force_integer_mv` | ||
| 213 | - /// under `--tune-content=screen` (seq `force_integer_mv == 2`, adaptive: | ||
| 214 | - /// `encoder.c:4171`). Two hard asserts, both class | ||
| 215 | - /// `gate-blind-to-feature`: at least one decoded frame header carried | ||
| 216 | - /// `force_integer_mv = 1`, and at least one block took the 2-symbol | ||
| 217 | - /// alphabet where `allow_warped_motion = 1` and `num_proj_ref >= 1` would | ||
| 218 | - /// have picked the 3-symbol one. A decode error or a pixel mismatch is a | ||
| 219 | - /// FAILURE, never a skip. | ||
| 220 | - #[track_caller] | ||
| 221 | - pub(super) fn run_fimv_motion_mode_gate(name: &str, ten_bit: bool) { | ||
| 222 | - let _gate_lock = lock_gate_counters(); | ||
| 223 | - assert!(have_ffmpeg(), "{name}: ffmpeg required"); | ||
| 224 | - assert!( | ||
| 225 | - have_aomenc(), | ||
| 226 | - "{name}: no aomenc at {}", | ||
| 227 | - aomenc_path().display() | ||
| 228 | - ); | ||
| 229 | - let (width, height, frame_count) = (64usize, 64usize, 20usize); | ||
| 230 | - let fimv_frames_before = crate::decode::fimv_frame_hits(); | ||
| 231 | - let alphabet_before = crate::decode::fimv_alphabet_hits(); | ||
| 232 | - let mut matched = 0u32; | ||
| 233 | - let mut named_refusals = 0u32; | ||
| 234 | - let mut attempts = 0u32; | ||
| 235 | - let mut refusals = Vec::new(); | ||
| 236 | - for cq in [32u32, 45, 55] { | ||
| 237 | - for step in [4u32, 8] { | ||
| 238 | - attempts += 1; | ||
| 239 | - // lane-fimv r1: per-attempt snapshots. The aggregate | ||
| 240 | - // assertions below are satisfied by a single lucky cq/step | ||
| 241 | - // cell; these prove EVERY attempt that decoded and | ||
| 242 | - // pixel-compared really carried the header state and the | ||
| 243 | - // forced alphabet under test (class gate-blind-to-feature). | ||
| 244 | - let attempt_fimv_before = crate::decode::fimv_frame_hits(); | ||
| 245 | - let attempt_alphabet_before = crate::decode::fimv_alphabet_hits(); | ||
| 246 | - let duration = frame_count as f64 / 25.0; | ||
| 247 | - // Flat screen-content tiles with hard edges, translating by a | ||
| 248 | - // whole number of pixels per frame: static enough for | ||
| 249 | - // `av1_is_integer_mv`, moving enough for a real inter block | ||
| 250 | - // with overlappable neighbours. | ||
| 251 | - let source = format!( | ||
| 252 | - "color=c=black:s={width}x{height}:r=25,\ | ||
| 253 | - drawbox=x='8+{step}*mod(trunc(t*25)\\,3)':y=8:w=20:h=20:color=white:t=fill,\ | ||
| 254 | - drawbox=x=36:y='6+{step}*mod(trunc(t*25)+1\\,3)':w=16:h=16:color=0x808080:t=fill,\ | ||
| 255 | - drawbox=x=4:y=44:w=56:h=12:color=0xC0C0C0:t=fill" | ||
| 256 | - ); | ||
| 257 | - let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 258 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 259 | - .args([ | ||
| 260 | - "-v", | ||
| 261 | - "error", | ||
| 262 | - "-f", | ||
| 263 | - "lavfi", | ||
| 264 | - "-i", | ||
| 265 | - &source, | ||
| 266 | - "-t", | ||
| 267 | - &duration.to_string(), | ||
| 268 | - "-pix_fmt", | ||
| 269 | - pix_fmt, | ||
| 270 | - "-strict", | ||
| 271 | - "-1", | ||
| 272 | - "-f", | ||
| 273 | - "yuv4mpegpipe", | ||
| 274 | - "-", | ||
| 275 | - ]) | ||
| 276 | - .stdin(Stdio::null()) | ||
| 277 | - .stdout(Stdio::piped()) | ||
| 278 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 279 | - .expect("ffmpeg failed to run"); | ||
| 280 | - assert!( | ||
| 281 | - y4m.status.success(), | ||
| 282 | - "ffmpeg fixture: {}", | ||
| 283 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 284 | - ); | ||
| 285 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 286 | - let mut args: Vec<&str> = vec![ | ||
| 287 | - "--codec=av1", | ||
| 288 | - "--passes=1", | ||
| 289 | - "--end-usage=q", | ||
| 290 | - &cq_arg, | ||
| 291 | - "--cpu-used=0", | ||
| 292 | - "--kf-max-dist=1000", | ||
| 293 | - "--threads=1", | ||
| 294 | - "--row-mt=0", | ||
| 295 | - // single reference only: the 10-bit compound MC defect | ||
| 296 | - // (see `a_real_compound_global_warp_10bit_stream_...`) | ||
| 297 | - // is unrelated to this lane and would mask it. | ||
| 298 | - "--auto-alt-ref=0", | ||
| 299 | - "--lag-in-frames=0", | ||
| 300 | - "--enable-fwd-kf=0", | ||
| 301 | - "--enable-order-hint=1", | ||
| 302 | - // the flag combination this gate exists for: warp allowed | ||
| 303 | - // by the header, OBMC available, global motion off (so the | ||
| 304 | - // GLOBALMV suppression is not what picks the alphabet). | ||
| 305 | - "--tune-content=screen", | ||
| 306 | - "--enable-warped-motion=1", | ||
| 307 | - "--enable-obmc=1", | ||
| 308 | - "--enable-global-motion=0", | ||
| 309 | - "--enable-masked-comp=0", | ||
| 310 | - "--enable-onesided-comp=0", | ||
| 311 | - "--enable-interintra-comp=0", | ||
| 312 | - "--enable-interintra-wedge=0", | ||
| 313 | - "--enable-smooth-interintra=0", | ||
| 314 | - "--enable-dist-wtd-comp=0", | ||
| 315 | - // partition/intra tools this decoder does not code yet -- | ||
| 316 | - // the same exclusion list every inter gate here carries. | ||
| 317 | - "--enable-rect-partitions=0", | ||
| 318 | - "--enable-ab-partitions=0", | ||
| 319 | - "--enable-1to4-partitions=0", | ||
| 320 | - "--enable-filter-intra=0", | ||
| 321 | - "--enable-smooth-intra=0", | ||
| 322 | - "--enable-paeth-intra=0", | ||
| 323 | - "--enable-directional-intra=0", | ||
| 324 | - "--enable-angle-delta=0", | ||
| 325 | - "--enable-tx-size-search=0", | ||
| 326 | - "--enable-cdef=0", | ||
| 327 | - "--enable-restoration=0", | ||
| 328 | - "--max-partition-size=32", | ||
| 329 | - "--min-partition-size=32", | ||
| 330 | - "--enable-palette=0", | ||
| 331 | - "--enable-intrabc=0", | ||
| 332 | - "--enable-cfl-intra=0", | ||
| 333 | - "--enable-ref-frame-mvs=0", | ||
| 334 | - ]; | ||
| 335 | - if ten_bit { | ||
| 336 | - args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 337 | - } | ||
| 338 | - args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 339 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 340 | - assert!( | ||
| 341 | - out.status.success(), | ||
| 342 | - "aomenc refused the fixture: {}", | ||
| 343 | - String::from_utf8_lossy(&out.stderr) | ||
| 344 | - ); | ||
| 345 | - let stream = out.stdout; | ||
| 346 | - let frames = match decode_stream(&stream) { | ||
| 347 | - Err(e) => { | ||
| 348 | - let msg = e.to_string(); | ||
| 349 | - assert!( | ||
| 350 | - msg.contains("unsupported"), | ||
| 351 | - "{name} failed outright (cq {cq} step {step}): {msg}" | ||
| 352 | - ); | ||
| 353 | - named_refusals += 1; | ||
| 354 | - refusals.push(format!("cq {cq} step {step}: {msg}")); | ||
| 355 | - continue; | ||
| 356 | - } | ||
| 357 | - Ok(frames) => frames, | ||
| 358 | - }; | ||
| 359 | - let want = if ten_bit { | ||
| 360 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 361 | - } else { | ||
| 362 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 363 | - }; | ||
| 364 | - assert_eq!(frames.len(), frame_count); | ||
| 365 | - if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") | ||
| 366 | - && frames | ||
| 367 | - .iter() | ||
| 368 | - .zip(&want) | ||
| 369 | - .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v) | ||
| 370 | - { | ||
| 371 | - std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 372 | - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}"); | ||
| 373 | - } | ||
| 374 | - for (i, (got, want)) in frames.iter().zip(&want).enumerate() { | ||
| 375 | - assert_eq!( | ||
| 376 | - got.y, want.y, | ||
| 377 | - "{name} frame {i} luma vs ffmpeg (cq {cq} step {step})" | ||
| 378 | - ); | ||
| 379 | - assert_eq!( | ||
| 380 | - got.u, want.u, | ||
| 381 | - "{name} frame {i} U vs ffmpeg (cq {cq} step {step})" | ||
| 382 | - ); | ||
| 383 | - assert_eq!( | ||
| 384 | - got.v, want.v, | ||
| 385 | - "{name} frame {i} V vs ffmpeg (cq {cq} step {step})" | ||
| 386 | - ); | ||
| 387 | - } | ||
| 388 | - assert!( | ||
| 389 | - crate::decode::fimv_frame_hits() > attempt_fimv_before, | ||
| 390 | - "{name} (cq {cq} step {step}): decoded and compared all \ | ||
| 391 | - frames but no frame header had force_integer_mv=1 -- \ | ||
| 392 | - this attempt is vacuous" | ||
| 393 | - ); | ||
| 394 | - assert!( | ||
| 395 | - crate::decode::fimv_alphabet_hits() > attempt_alphabet_before, | ||
| 396 | - "{name} (cq {cq} step {step}): no block was forced onto the \ | ||
| 397 | - 2-symbol obmc alphabet by force_integer_mv while \ | ||
| 398 | - allow_warped_motion=1 and num_proj_ref>=1 -- this attempt \ | ||
| 399 | - is vacuous" | ||
| 400 | - ); | ||
| 401 | - matched += 1; | ||
| 402 | - } | ||
| 403 | - } | ||
| 404 | - let fimv_frames = crate::decode::fimv_frame_hits() - fimv_frames_before; | ||
| 405 | - let alphabet = crate::decode::fimv_alphabet_hits() - alphabet_before; | ||
| 406 | - eprintln!( | ||
| 407 | - "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \ | ||
| 408 | - force_integer_mv frames={fimv_frames}, forced-2-symbol blocks={alphabet}\n{}", | ||
| 409 | - refusals.join("\n") | ||
| 410 | - ); | ||
| 411 | - assert!( | ||
| 412 | - matched > 0, | ||
| 413 | - "{name}: every attempt refused -- no pixel comparison ran" | ||
| 414 | - ); | ||
| 415 | - assert!( | ||
| 416 | - fimv_frames > 0, | ||
| 417 | - "{name}: no decoded frame header had force_integer_mv=1 \ | ||
| 418 | - ({matched} matches of {attempts}) -- gate vacuous" | ||
| 419 | - ); | ||
| 420 | - assert!( | ||
| 421 | - alphabet > 0, | ||
| 422 | - "{name}: no block read the 2-symbol obmc alphabet where \ | ||
| 423 | - allow_warped_motion=1 and num_proj_ref>=1 would have picked the \ | ||
| 424 | - 3-symbol motion_mode alphabet -- gate vacuous" | ||
| 425 | - ); | ||
| 426 | - } | ||
| 427 | - | ||
| 428 | - /// lane-mcomp64 r1: at 64x64 `av1_is_wedge_used` is false | ||
| 429 | - /// (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types == 0`), so libaom's | ||
| 430 | - /// `read_compound_type` codes NO `compound_type` symbol and INFERS | ||
| 431 | - /// `COMPOUND_DIFFWTD`; only the 1-bit `mask_type` literal follows. This | ||
| 432 | - /// decoder used to refuse such a block by name ("a masked compound 64x64 | ||
| 433 | - /// inter block..."), because reading the symbol would have desynced. | ||
| 434 | - /// | ||
| 435 | - /// The recipe pins every block to 64x64 (`--sb-size=64 | ||
| 436 | - /// --max-partition-size=64 --min-partition-size=64`) with masked compound | ||
| 437 | - /// on and distance-weighted compound off, so the only way a | ||
| 438 | - /// `comp_group_idx == 1` block can be coded is through the inferred arm. | ||
| 439 | - /// `diffwtd_inferred_hits` is snapshotted PER ATTEMPT and only accumulated | ||
| 440 | - /// for attempts that decoded AND pixel-compared (class | ||
| 441 | - /// `counter-from-refused-stream`), and is hard-asserted at the end. A | ||
| 442 | - /// decode error or a pixel mismatch is a FAILURE, never a skip. | ||
| 443 | - #[track_caller] | ||
| 444 | - pub(super) fn run_diffwtd_inferred_64x64_gate(name: &str, ten_bit: bool) { | ||
| 445 | - let _gate_lock = lock_gate_counters(); | ||
| 446 | - assert!(have_ffmpeg(), "{name}: ffmpeg required"); | ||
| 447 | - assert!( | ||
| 448 | - have_aomenc(), | ||
| 449 | - "{name}: no aomenc at {}", | ||
| 450 | - aomenc_path().display() | ||
| 451 | - ); | ||
| 452 | - let (width, height, frame_count) = (128usize, 128usize, 16usize); | ||
| 453 | - let mut matched = 0u32; | ||
| 454 | - let mut named_refusals = 0u32; | ||
| 455 | - let mut attempts = 0u32; | ||
| 456 | - let mut fired = 0usize; | ||
| 457 | - let mut refusals: Vec<String> = Vec::new(); | ||
| 458 | - for cq in [32u32, 45, 55] { | ||
| 459 | - for (i, zoom) in [0.004f64, 0.010].iter().enumerate() { | ||
| 460 | - attempts += 1; | ||
| 461 | - let attempt_before = crate::decode::diffwtd_inferred_hits(); | ||
| 462 | - let duration = frame_count as f64 / 25.0; | ||
| 463 | - // Hard-edged, moving content: a difference-weighted mask only | ||
| 464 | - // wins where the two references genuinely disagree over part | ||
| 465 | - // of a 64x64 block (a smooth `gradients` source measured | ||
| 466 | - // diffwtd_hits == 0, memory `gate-blind-to-feature`). | ||
| 467 | - let source = format!( | ||
| 468 | - "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y=-0.4:\ | ||
| 469 | - end_scale=0.3:maxiter=200,\ | ||
| 470 | - noise=alls=6:allf=t+u:all_seed={seed}", | ||
| 471 | - sx = -0.6 + zoom * (i as f64 + 1.0), | ||
| 472 | - seed = 1000 + cq, | ||
| 473 | - ); | ||
| 474 | - let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 475 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 476 | - .args([ | ||
| 477 | - "-v", | ||
| 478 | - "error", | ||
| 479 | - "-f", | ||
| 480 | - "lavfi", | ||
| 481 | - "-i", | ||
| 482 | - &source, | ||
| 483 | - "-t", | ||
| 484 | - &duration.to_string(), | ||
| 485 | - "-pix_fmt", | ||
| 486 | - pix_fmt, | ||
| 487 | - "-strict", | ||
| 488 | - "-1", | ||
| 489 | - "-f", | ||
| 490 | - "yuv4mpegpipe", | ||
| 491 | - "-", | ||
| 492 | - ]) | ||
| 493 | - .stdin(Stdio::null()) | ||
| 494 | - .stdout(Stdio::piped()) | ||
| 495 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 496 | - .expect("ffmpeg failed to run"); | ||
| 497 | - assert!( | ||
| 498 | - y4m.status.success(), | ||
| 499 | - "ffmpeg fixture: {}", | ||
| 500 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 501 | - ); | ||
| 502 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 503 | - let mut args: Vec<&str> = vec![ | ||
| 504 | - "--codec=av1", | ||
| 505 | - "--passes=1", | ||
| 506 | - "--end-usage=q", | ||
| 507 | - &cq_arg, | ||
| 508 | - "--cpu-used=0", | ||
| 509 | - "--kf-max-dist=1000", | ||
| 510 | - "--threads=1", | ||
| 511 | - "--row-mt=0", | ||
| 512 | - "--auto-alt-ref=1", | ||
| 513 | - "--lag-in-frames=16", | ||
| 514 | - "--enable-fwd-kf=0", | ||
| 515 | - "--enable-order-hint=1", | ||
| 516 | - // the tools this gate exists for: masked compound on, the | ||
| 517 | - // difference-weighted arm on, the distance-weighted | ||
| 518 | - // competitor off so comp_group_idx==1 is the encoder's | ||
| 519 | - // only masked choice at a size where wedge does not exist. | ||
| 520 | - "--enable-masked-comp=1", | ||
| 521 | - "--enable-diff-wtd-comp=1", | ||
| 522 | - "--enable-dist-wtd-comp=0", | ||
| 523 | - "--enable-onesided-comp=0", | ||
| 524 | - "--enable-interintra-comp=0", | ||
| 525 | - "--enable-global-motion=0", | ||
| 526 | - "--enable-warped-motion=1", | ||
| 527 | - "--enable-obmc=1", | ||
| 528 | - "--tune-content=default", | ||
| 529 | - // partition/intra tools this decoder does not code yet -- | ||
| 530 | - // same exclusion list every compound gate carries. | ||
| 531 | - "--enable-rect-partitions=0", | ||
| 532 | - "--enable-ab-partitions=0", | ||
| 533 | - "--enable-1to4-partitions=0", | ||
| 534 | - "--enable-filter-intra=0", | ||
| 535 | - "--enable-smooth-intra=0", | ||
| 536 | - "--enable-paeth-intra=0", | ||
| 537 | - "--enable-directional-intra=0", | ||
| 538 | - "--enable-angle-delta=0", | ||
| 539 | - "--enable-tx-size-search=0", | ||
| 540 | - "--enable-cdef=0", | ||
| 541 | - "--enable-restoration=0", | ||
| 542 | - "--enable-palette=0", | ||
| 543 | - "--enable-intrabc=0", | ||
| 544 | - "--enable-cfl-intra=0", | ||
| 545 | - "--enable-ref-frame-mvs=0", | ||
| 546 | - // every block is a whole 64x64 superblock: the ONLY size | ||
| 547 | - // where compound_type is inferred rather than coded. | ||
| 548 | - "--sb-size=64", | ||
| 549 | - "--max-partition-size=64", | ||
| 550 | - "--min-partition-size=64", | ||
| 551 | - ]; | ||
| 552 | - if ten_bit { | ||
| 553 | - args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 554 | - } | ||
| 555 | - args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 556 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 557 | - assert!( | ||
| 558 | - out.status.success(), | ||
| 559 | - "aomenc refused the fixture: {}", | ||
| 560 | - String::from_utf8_lossy(&out.stderr) | ||
| 561 | - ); | ||
| 562 | - let stream = out.stdout; | ||
| 563 | - let frames = match decode_stream(&stream) { | ||
| 564 | - Err(e) => { | ||
| 565 | - let msg = e.to_string(); | ||
| 566 | - assert!( | ||
| 567 | - msg.contains("unsupported"), | ||
| 568 | - "{name} failed outright, not a named refusal (cq {cq}): {msg}" | ||
| 569 | - ); | ||
| 570 | - assert!( | ||
| 571 | - !msg.contains("masked compound 64x64"), | ||
| 572 | - "{name} refused the inferred-DIFFWTD 64x64 block (cq {cq}) -- \ | ||
| 573 | - that refusal is lifted, this is forbidden: {msg}" | ||
| 574 | - ); | ||
| 575 | - named_refusals += 1; | ||
| 576 | - refusals.push(msg.clone()); | ||
| 577 | - eprintln!("{name} cq {cq} variant {i} refusal: {msg}"); | ||
| 578 | - continue; | ||
| 579 | - } | ||
| 580 | - Ok(frames) => frames, | ||
| 581 | - }; | ||
| 582 | - let want = if ten_bit { | ||
| 583 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 584 | - } else { | ||
| 585 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 586 | - }; | ||
| 587 | - assert_eq!(frames.len(), frame_count); | ||
| 588 | - if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") | ||
| 589 | - && frames | ||
| 590 | - .iter() | ||
| 591 | - .zip(&want) | ||
| 592 | - .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v) | ||
| 593 | - { | ||
| 594 | - std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 595 | - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}"); | ||
| 596 | - } | ||
| 597 | - for (f, (got, want)) in frames.iter().zip(&want).enumerate() { | ||
| 598 | - assert_eq!(got.y, want.y, "{name} frame {f} luma vs ffmpeg (cq {cq})"); | ||
| 599 | - assert_eq!(got.u, want.u, "{name} frame {f} U vs ffmpeg (cq {cq})"); | ||
| 600 | - assert_eq!(got.v, want.v, "{name} frame {f} V vs ffmpeg (cq {cq})"); | ||
| 601 | - } | ||
| 602 | - // decoded AND compared: only now does this attempt's own | ||
| 603 | - // inferred-DIFFWTD count mean anything. | ||
| 604 | - fired += crate::decode::diffwtd_inferred_hits() - attempt_before; | ||
| 605 | - matched += 1; | ||
| 606 | - } | ||
| 607 | - } | ||
| 608 | - eprintln!( | ||
| 609 | - "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \ | ||
| 610 | - diffwtd_inferred_hits (decoded+compared attempts only)={fired}" | ||
| 611 | - ); | ||
| 612 | - assert!( | ||
| 613 | - matched > 0, | ||
| 614 | - "{name}: every attempt refused ({refusals:?}) -- no pixel compare ran" | ||
| 615 | - ); | ||
| 616 | - assert!( | ||
| 617 | - fired > 0, | ||
| 618 | - "{name}: no inferred-DIFFWTD 64x64 block fired on a compared attempt \ | ||
| 619 | - ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous" | ||
| 620 | - ); | ||
| 621 | - } | ||
| 622 | - | ||
| 623 | - pub(super) fn both_axes_cut_sweep( | ||
| 624 | - name: &'static str, | ||
| 625 | - (arm, frames, kf_arg, limit_arg): (&str, usize, &str, &str), | ||
| 626 | - ) { | ||
| 627 | - // Kept upper-case so every message string below reads the same as in | ||
| 628 | - // the sibling gates. | ||
| 629 | - #[allow(non_snake_case)] | ||
| 630 | - let NAME = name; | ||
| 631 | - let _gate_lock = lock_gate_counters(); | ||
| 632 | - if !have_ffmpeg() || !have_aomenc() { | ||
| 633 | - eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); | ||
| 634 | - return; | ||
| 635 | - } | ||
| 636 | - let sizes: &[(usize, usize)] = &[(200, 72), (136, 104), (264, 136), (72, 200), (104, 136)]; | ||
| 637 | - let mut compared = 0u32; | ||
| 638 | - let mut refusals: Vec<String> = Vec::new(); | ||
| 639 | - let mut totals = [0usize; 4]; | ||
| 640 | - for &(width, height) in sizes { | ||
| 641 | - let mut size_compared = 0u32; | ||
| 642 | - { | ||
| 643 | - for bit_depth in [8u32, 10u32] { | ||
| 644 | - // cq 58 is left out on purpose: measured r1, it is where | ||
| 645 | - // libaom starts answering the frame-edge gathered symbol | ||
| 646 | - // with a rect strip and other lanes' refusals fire first | ||
| 647 | - // ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | ||
| 648 | - // rectangular residual coding"). | ||
| 649 | - for cq in [32u32, 45] { | ||
| 650 | - let source = format!("mandelbrot=size={width}x{height}:rate=25"); | ||
| 651 | - // Feed exactly `frames` frames: --limit=1 makes | ||
| 652 | - // aomenc stop reading after the first one and the | ||
| 653 | - // y4m write then dies on a broken pipe. | ||
| 654 | - let dur = format!("{}", frames as f64 / 25.0); | ||
| 655 | - let pix_fmt = if bit_depth == 10 { | ||
| 656 | - "yuv420p10le" | ||
| 657 | - } else { | ||
| 658 | - "yuv420p" | ||
| 659 | - }; | ||
| 660 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 661 | - .args([ | ||
| 662 | - "-v", | ||
| 663 | - "error", | ||
| 664 | - "-f", | ||
| 665 | - "lavfi", | ||
| 666 | - "-i", | ||
| 667 | - &source, | ||
| 668 | - "-t", | ||
| 669 | - &dur, | ||
| 670 | - "-pix_fmt", | ||
| 671 | - pix_fmt, | ||
| 672 | - "-strict", | ||
| 673 | - "-1", | ||
| 674 | - "-f", | ||
| 675 | - "yuv4mpegpipe", | ||
| 676 | - "-", | ||
| 677 | - ]) | ||
| 678 | - .stdin(Stdio::null()) | ||
| 679 | - .stdout(Stdio::piped()) | ||
| 680 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 681 | - .expect("ffmpeg failed to run"); | ||
| 682 | - assert!( | ||
| 683 | - y4m.status.success(), | ||
| 684 | - "{NAME}: ffmpeg refused the {width}x{height} {bit_depth}-bit \ | ||
| 685 | - fixture: {}", | ||
| 686 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 687 | - ); | ||
| 688 | - let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 689 | - let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 690 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 691 | - let out = run_with_stdin( | ||
| 692 | - Command::new(aomenc_path()).args([ | ||
| 693 | - "--codec=av1", | ||
| 694 | - "--passes=1", | ||
| 695 | - "--end-usage=q", | ||
| 696 | - &cq_arg, | ||
| 697 | - // cpu-used >= 1 keeps libaom on 64x64 | ||
| 698 | - // superblocks at these sizes | ||
| 699 | - // (`av1_select_sb_size`). | ||
| 700 | - "--cpu-used=4", | ||
| 701 | - "--threads=1", | ||
| 702 | - "--row-mt=0", | ||
| 703 | - // --lag-in-frames=0: no hidden alt-ref, so | ||
| 704 | - // decode order == display order and the | ||
| 705 | - // compare below covers every frame the stream | ||
| 706 | - // carries (class gate-blind-to-hidden-frames). | ||
| 707 | - kf_arg, | ||
| 708 | - limit_arg, | ||
| 709 | - "--lag-in-frames=0", | ||
| 710 | - &depth_arg, | ||
| 711 | - &input_depth_arg, | ||
| 712 | - // Other lanes' named refusals this recipe must | ||
| 713 | - // not trip. The both-cut corner is FORCED down | ||
| 714 | - // to 8x8 leaves, which is exactly where the | ||
| 715 | - // 8x8-intra-leaf-in-an-inter-frame gaps live, | ||
| 716 | - // so the intra tool set and tx-size search are | ||
| 717 | - // pinned off: without them 30/30 inter | ||
| 718 | - // attempts refused (measured r1) on "a nonzero | ||
| 719 | - // angle delta on an 8x8 intra leaf in an inter | ||
| 720 | - // frame", "a non-DC chroma mode on an 8x8 | ||
| 721 | - // inter-frame leaf" and "an 8x8 intra leaf in | ||
| 722 | - // an inter frame whose tx_depth splits it into | ||
| 723 | - // 4x4 transform units". | ||
| 724 | - "--enable-rect-partitions=0", | ||
| 725 | - "--enable-ab-partitions=0", | ||
| 726 | - "--enable-1to4-partitions=0", | ||
| 727 | - "--min-partition-size=8", | ||
| 728 | - "--max-partition-size=64", | ||
| 729 | - "--enable-palette=0", | ||
| 730 | - "--enable-intrabc=0", | ||
| 731 | - "--enable-warped-motion=0", | ||
| 732 | - "--enable-obmc=0", | ||
| 733 | - "--enable-masked-comp=0", | ||
| 734 | - "--enable-interintra-comp=0", | ||
| 735 | - "--enable-onesided-comp=0", | ||
| 736 | - "--enable-interintra-wedge=0", | ||
| 737 | - "--enable-smooth-interintra=0", | ||
| 738 | - "--enable-ref-frame-mvs=0", | ||
| 739 | - "--enable-angle-delta=0", | ||
| 740 | - "--enable-cfl-intra=0", | ||
| 741 | - "--enable-directional-intra=0", | ||
| 742 | - "--enable-smooth-intra=0", | ||
| 743 | - "--enable-paeth-intra=0", | ||
| 744 | - "--enable-filter-intra=0", | ||
| 745 | - "--enable-tx-size-search=0", | ||
| 746 | - "--obu", | ||
| 747 | - "-o", | ||
| 748 | - "-", | ||
| 749 | - "-", | ||
| 750 | - ]), | ||
| 751 | - &y4m.stdout, | ||
| 752 | - ); | ||
| 753 | - assert!( | ||
| 754 | - out.status.success(), | ||
| 755 | - "aomenc refused: {}", | ||
| 756 | - String::from_utf8_lossy(&out.stderr) | ||
| 757 | - ); | ||
| 758 | - let stream = out.stdout; | ||
| 759 | - | ||
| 760 | - // Reset, never a delta across attempts: a refused | ||
| 761 | - // attempt's hits must not count (class | ||
| 762 | - // counter-from-refused-stream). | ||
| 763 | - crate::decode::reset_edge_both_cut_hits(); | ||
| 764 | - let decoded = match decode_stream(&stream) { | ||
| 765 | - Ok(f) => f, | ||
| 766 | - Err(e) => { | ||
| 767 | - let msg = e.to_string(); | ||
| 768 | - assert!( | ||
| 769 | - msg.contains("unsupported"), | ||
| 770 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ | ||
| 771 | - failed outright, not a named refusal: {msg}" | ||
| 772 | - ); | ||
| 773 | - eprintln!( | ||
| 774 | - " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ | ||
| 775 | - REFUSED {msg}" | ||
| 776 | - ); | ||
| 777 | - refusals.push(msg); | ||
| 778 | - continue; | ||
| 779 | - } | ||
| 780 | - }; | ||
| 781 | - let hits = crate::decode::edge_both_cut_hits(); | ||
| 782 | - let reference = if bit_depth == 10 { | ||
| 783 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frames) | ||
| 784 | - } else { | ||
| 785 | - ffmpeg_decode_sequence(&stream, width, height, frames) | ||
| 786 | - }; | ||
| 787 | - assert_eq!( | ||
| 788 | - decoded.len(), | ||
| 789 | - frames, | ||
| 790 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded {} \ | ||
| 791 | - frames, expected {frames}", | ||
| 792 | - decoded.len() | ||
| 793 | - ); | ||
| 794 | - assert_eq!( | ||
| 795 | - reference.len(), | ||
| 796 | - frames, | ||
| 797 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} reference \ | ||
| 798 | - frame count" | ||
| 799 | - ); | ||
| 800 | - for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { | ||
| 801 | - let nd = |a: &[u16], b: &[u16]| { | ||
| 802 | - a.iter().zip(b).filter(|(x, y)| x != y).count() | ||
| 803 | - }; | ||
| 804 | - // Where a mismatch lands is the whole diagnosis | ||
| 805 | - // here (corner block vs elsewhere), so print the | ||
| 806 | - // luma bounding box before the assert kills the run. | ||
| 807 | - if nd(&ours.y, &theirs.y) > 0 { | ||
| 808 | - let (mut r0, mut c0, mut r1, mut c1) = | ||
| 809 | - (usize::MAX, usize::MAX, 0usize, 0usize); | ||
| 810 | - for row in 0..height { | ||
| 811 | - for col in 0..width { | ||
| 812 | - if ours.y[row * width + col] != theirs.y[row * width + col] | ||
| 813 | - { | ||
| 814 | - r0 = r0.min(row); | ||
| 815 | - c0 = c0.min(col); | ||
| 816 | - r1 = r1.max(row); | ||
| 817 | - c1 = c1.max(col); | ||
| 818 | - } | ||
| 819 | - } | ||
| 820 | - } | ||
| 821 | - eprintln!( | ||
| 822 | - " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ | ||
| 823 | - frame {i} luma diff bbox rows {r0}..={r1} cols {c0}..={c1}" | ||
| 824 | - ); | ||
| 825 | - } | ||
| 826 | - assert_eq!( | ||
| 827 | - ( | ||
| 828 | - nd(&ours.y, &theirs.y), | ||
| 829 | - nd(&ours.u, &theirs.u), | ||
| 830 | - nd(&ours.v, &theirs.v) | ||
| 831 | - ), | ||
| 832 | - (0, 0, 0), | ||
| 833 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} frame \ | ||
| 834 | - {i} differs from ffmpeg" | ||
| 835 | - ); | ||
| 836 | - for (plane, a, b) in [ | ||
| 837 | - ("Y", &ours.y, &theirs.y), | ||
| 838 | - ("U", &ours.u, &theirs.u), | ||
| 839 | - ("V", &ours.v, &theirs.v), | ||
| 840 | - ] { | ||
| 841 | - assert_eq!( | ||
| 842 | - a.len(), | ||
| 843 | - b.len(), | ||
| 844 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ | ||
| 845 | - frame {i} plane {plane}: ours has {} samples, ffmpeg's has \ | ||
| 846 | - {} -- a short plane would zip-truncate the diff count \ | ||
| 847 | - above and hide a chroma-span defect", | ||
| 848 | - a.len(), | ||
| 849 | - b.len() | ||
| 850 | - ); | ||
| 851 | - } | ||
| 852 | - } | ||
| 853 | - // Every compared attempt must carry the case, so no | ||
| 854 | - // compared attempt is out of scope and | ||
| 855 | - // out_of_scope_mismatch is 0 by construction. | ||
| 856 | - assert!( | ||
| 857 | - hits[0] > 0, | ||
| 858 | - "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded \ | ||
| 859 | - pixel-exact but no 16-level both-axes-cut block fired \ | ||
| 860 | - (hits={hits:?}) -- the recipe no longer reaches the lifted arm" | ||
| 861 | - ); | ||
| 862 | - for l in 0..4 { | ||
| 863 | - totals[l] += hits[l]; | ||
| 864 | - } | ||
| 865 | - compared += 1; | ||
| 866 | - size_compared += 1; | ||
| 867 | - } | ||
| 868 | - } | ||
| 869 | - } | ||
| 870 | - assert!( | ||
| 871 | - size_compared > 0, | ||
| 872 | - "{NAME}: every {width}x{height} attempt refused -- that size proved nothing" | ||
| 873 | - ); | ||
| 874 | - } | ||
| 875 | - assert!( | ||
| 876 | - totals[1] > 0 && totals[2] > 0, | ||
| 877 | - "{NAME}: no 32-level ({}) or 64-level ({}) both-axes-cut node fired -- 200x72 puts \ | ||
| 878 | - both in that state, so the sweep stopped reaching them", | ||
| 879 | - totals[1], | ||
| 880 | - totals[2] | ||
| 881 | - ); | ||
| 882 | - eprintln!( | ||
| 883 | - "{NAME}: {compared} attempts pixel-exact over {} sizes ({arm} arm), \ | ||
| 884 | - out_of_scope_mismatch=0, both_cut hits [16,32,64,128]={totals:?}, {} named refusals", | ||
| 885 | - sizes.len(), | ||
| 886 | - refusals.len() | ||
| 887 | - ); | ||
| 888 | - } | ||
| 889 | - | ||
| 890 | - /// lane-av1tmvp: the temporal-MV gate -- unlike every `_single_ref_gate` | ||
| 891 | - /// attempt above, this one leaves `--enable-ref-frame-mvs` at aomenc's | ||
| 892 | - /// own default (on) instead of pinning it off, so `use_ref_frame_mvs` | ||
| 893 | - /// actually fires and `decode::tmv_hits()` (this gate's own capability | ||
| 894 | - /// proof, not just `non_last_ref_hits`) has to advance for the run to | ||
| 895 | - /// count as a real pass rather than a `never_fired` skip. | ||
| 896 | - pub(super) fn a_real_aomenc_temporal_mv_gate(seed_base: u32, attempts: u32) { | ||
| 897 | - let gate_name = "a_real_aomenc_temporal_mv_gate"; | ||
| 898 | - let _gate_lock = lock_gate_counters(); | ||
| 899 | - if !have_ffmpeg() { | ||
| 900 | - eprintln!("SKIP {gate_name}: no ffmpeg"); | ||
| 901 | - return; | ||
| 902 | - } | ||
| 903 | - if !have_aomenc() { | ||
| 904 | - eprintln!("SKIP {gate_name}: no aomenc at {}", aomenc_path().display()); | ||
| 905 | - return; | ||
| 906 | - } | ||
| 907 | - let (width, height, frame_count) = (64usize, 64usize, 16usize); | ||
| 908 | - let mut never_fired = 0u32; | ||
| 909 | - let mut refusals = Vec::new(); | ||
| 910 | - for attempt in 0..attempts { | ||
| 911 | - let seed = seed_base + attempt; | ||
| 912 | - let duration = frame_count as f64 / 25.0; | ||
| 913 | - let source = | ||
| 914 | - gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | ||
| 915 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 916 | - .args([ | ||
| 917 | - "-v", | ||
| 918 | - "error", | ||
| 919 | - "-f", | ||
| 920 | - "lavfi", | ||
| 921 | - "-i", | ||
| 922 | - &source, | ||
| 923 | - "-pix_fmt", | ||
| 924 | - "yuv420p", | ||
| 925 | - "-f", | ||
| 926 | - "yuv4mpegpipe", | ||
| 927 | - "-", | ||
| 928 | - ]) | ||
| 929 | - .stdin(Stdio::null()) | ||
| 930 | - .stdout(Stdio::piped()) | ||
| 931 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 932 | - .expect("ffmpeg failed to run"); | ||
| 933 | - assert!( | ||
| 934 | - y4m.status.success(), | ||
| 935 | - "ffmpeg fixture: {}", | ||
| 936 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 937 | - ); | ||
| 938 | - // Same envelope as `a_real_aomenc_single_ref_gate`, minus its | ||
| 939 | - // `--enable-ref-frame-mvs=0` pin -- everything else this decoder | ||
| 940 | - // still cannot code stays refused the same way. | ||
| 941 | - let args: Vec<&str> = vec![ | ||
| 942 | - "--codec=av1", | ||
| 943 | - "--passes=1", | ||
| 944 | - "--end-usage=q", | ||
| 945 | - "--cq-level=55", | ||
| 946 | - "--cpu-used=0", | ||
| 947 | - "--kf-max-dist=1000", | ||
| 948 | - "--threads=1", | ||
| 949 | - "--row-mt=0", | ||
| 950 | - "--auto-alt-ref=1", | ||
| 951 | - "--lag-in-frames=16", | ||
| 952 | - "--enable-fwd-kf=0", | ||
| 953 | - "--enable-warped-motion=0", | ||
| 954 | - "--enable-obmc=0", | ||
| 955 | - "--enable-masked-comp=0", | ||
| 956 | - "--enable-interintra-comp=0", | ||
| 957 | - "--enable-dist-wtd-comp=0", | ||
| 958 | - "--enable-diff-wtd-comp=0", | ||
| 959 | - "--enable-onesided-comp=0", | ||
| 960 | - "--enable-interintra-wedge=0", | ||
| 961 | - "--enable-smooth-interintra=0", | ||
| 962 | - "--enable-rect-partitions=0", | ||
| 963 | - "--enable-ab-partitions=0", | ||
| 964 | - "--enable-1to4-partitions=0", | ||
| 965 | - "--enable-filter-intra=0", | ||
| 966 | - "--enable-smooth-intra=0", | ||
| 967 | - "--enable-paeth-intra=0", | ||
| 968 | - "--enable-directional-intra=0", | ||
| 969 | - "--enable-angle-delta=0", | ||
| 970 | - "--enable-tx-size-search=0", | ||
| 971 | - "--enable-cdef=0", | ||
| 972 | - "--enable-restoration=0", | ||
| 973 | - "--max-partition-size=32", | ||
| 974 | - "--min-partition-size=32", | ||
| 975 | - "--enable-palette=0", | ||
| 976 | - "--enable-intrabc=0", | ||
| 977 | - "--enable-cfl-intra=0", | ||
| 978 | - "--obu", | ||
| 979 | - "-o", | ||
| 980 | - "-", | ||
| 981 | - "-", | ||
| 982 | - ]; | ||
| 983 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 984 | - assert!( | ||
| 985 | - out.status.success(), | ||
| 986 | - "aomenc refused the fixture: {}", | ||
| 987 | - String::from_utf8_lossy(&out.stderr) | ||
| 988 | - ); | ||
| 989 | - let stream = out.stdout; | ||
| 990 | - let before = decode::tmv_hits(); | ||
| 991 | - let frames = match decode_stream(&stream) { | ||
| 992 | - Err(e) => { | ||
| 993 | - let msg = e.to_string(); | ||
| 994 | - assert!( | ||
| 995 | - msg.contains("unsupported"), | ||
| 996 | - "{gate_name} failed outright (seed {seed}): {msg}" | ||
| 997 | - ); | ||
| 998 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 999 | - continue; | ||
| 1000 | - } | ||
| 1001 | - Ok(frames) => frames, | ||
| 1002 | - }; | ||
| 1003 | - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | ||
| 1004 | - // is ALWAYS pixel-compared below; the hit counter only decides whether | ||
| 1005 | - // the attempt counts toward the firing total. | ||
| 1006 | - let counted = decode::tmv_hits() != before; | ||
| 1007 | - if !counted { | ||
| 1008 | - never_fired += 1; | ||
| 1009 | - } | ||
| 1010 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 1011 | - assert_eq!(frames.len(), frame_count); | ||
| 1012 | - if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 1013 | - let mismatched = frames | ||
| 1014 | - .iter() | ||
| 1015 | - .zip(&ffmpeg_frames) | ||
| 1016 | - .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 1017 | - if mismatched { | ||
| 1018 | - std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 1019 | - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | ||
| 1020 | - } | ||
| 1021 | - } | ||
| 1022 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1023 | - assert_eq!( | ||
| 1024 | - got.y, want.y, | ||
| 1025 | - "{gate_name} frame {i} luma vs ffmpeg (seed {seed})" | ||
| 1026 | - ); | ||
| 1027 | - assert_eq!( | ||
| 1028 | - got.u, want.u, | ||
| 1029 | - "{gate_name} frame {i} U vs ffmpeg (seed {seed})" | ||
| 1030 | - ); | ||
| 1031 | - assert_eq!( | ||
| 1032 | - got.v, want.v, | ||
| 1033 | - "{gate_name} frame {i} V vs ffmpeg (seed {seed})" | ||
| 1034 | - ); | ||
| 1035 | - } | ||
| 1036 | - if counted { | ||
| 1037 | - eprintln!( | ||
| 1038 | - "{gate_name} FIRING seed {seed}: tmv_hits advanced by {}", | ||
| 1039 | - decode::tmv_hits() - before | ||
| 1040 | - ); | ||
| 1041 | - gate_buckets(gate_name, 1, never_fired, refusals.len()); | ||
| 1042 | - return; | ||
| 1043 | - } | ||
| 1044 | - } | ||
| 1045 | - gate_buckets(gate_name, 0, never_fired, refusals.len()); | ||
| 1046 | - eprintln!( | ||
| 1047 | - "SKIP {gate_name}: {never_fired} attempts decoded but never fired a temporal MV \ | ||
| 1048 | - candidate, and every other attempt hit a named refusal:\n{}", | ||
| 1049 | - refusals.join("\n") | ||
| 1050 | - ); | ||
| 1051 | - } | ||
| 1052 | - | ||
| 1053 | - /// lane-mvtwin r1: the COMPOUND MV-stack gate. Every other compound gate | ||
| 1054 | - /// here pins `--enable-ref-frame-mvs=0`, so `find_mv_stack_compound`'s | ||
| 1055 | - /// temporal half (the three `tpl_sample_pos` extension samples lane-sb128 | ||
| 1056 | - /// r3 found missing) and its extension pass have never been exercised by | ||
| 1057 | - /// a real encoder. This arm turns ref-frame-mvs ON, gives the encoder a | ||
| 1058 | - /// 25-frame lookahead plus alt-refs so `reference_select` really drives | ||
| 1059 | - /// blocks to COMPOUND_REFERENCE, and sweeps global motion off/on so the | ||
| 1060 | - /// combine step's `gm_mv_candidates` fill (r1 defect 1) is reachable. | ||
| 1061 | - /// | ||
| 1062 | - /// Firing proof, hard-asserted: `decode::comp_mode_hits` (a real | ||
| 1063 | - /// compound block) AND `mvstack::tmv_hits` (a temporal candidate landed | ||
| 1064 | - /// in some stack) must BOTH have advanced on an attempt that also | ||
| 1065 | - /// decoded pixel-exact -- class [[gate-skips-on-its-own-failure]]: a | ||
| 1066 | - /// decode that succeeds is ALWAYS compared, on every decode-order frame, | ||
| 1067 | - /// and only the counters decide whether the attempt counts. | ||
| 1068 | - // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. | ||
| 1069 | - #[allow(clippy::too_many_arguments)] | ||
| 1070 | - pub(super) fn a_real_aomenc_compound_mv_stack_gate( | ||
| 1071 | - gate_name: &str, | ||
| 1072 | - seed_base: u32, | ||
| 1073 | - attempts: u32, | ||
| 1074 | - bit_depth: u32, | ||
| 1075 | - sb_size: u32, | ||
| 1076 | - global_motion: u32, | ||
| 1077 | - width: usize, | ||
| 1078 | - tile_columns: u32, | ||
| 1079 | - ) { | ||
| 1080 | - let _gate_lock = lock_gate_counters(); | ||
| 1081 | - if !have_ffmpeg() { | ||
| 1082 | - eprintln!("SKIP {gate_name}: no ffmpeg"); | ||
| 1083 | - return; | ||
| 1084 | - } | ||
| 1085 | - if !have_aomenc() { | ||
| 1086 | - eprintln!("SKIP {gate_name}: no aomenc at {}", aomenc_path().display()); | ||
| 1087 | - return; | ||
| 1088 | - } | ||
| 1089 | - let (height, frame_count) = (64usize, 16usize); | ||
| 1090 | - let mut never_fired = 0u32; | ||
| 1091 | - let mut refusals = Vec::new(); | ||
| 1092 | - for attempt in 0..attempts { | ||
| 1093 | - let seed = seed_base + attempt; | ||
| 1094 | - let duration = frame_count as f64 / 25.0; | ||
| 1095 | - let source = | ||
| 1096 | - gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | ||
| 1097 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1098 | - .args([ | ||
| 1099 | - "-v", | ||
| 1100 | - "error", | ||
| 1101 | - "-f", | ||
| 1102 | - "lavfi", | ||
| 1103 | - "-i", | ||
| 1104 | - &source, | ||
| 1105 | - "-pix_fmt", | ||
| 1106 | - if bit_depth == 10 { | ||
| 1107 | - "yuv420p10le" | ||
| 1108 | - } else { | ||
| 1109 | - "yuv420p" | ||
| 1110 | - }, | ||
| 1111 | - "-strict", | ||
| 1112 | - "-1", | ||
| 1113 | - "-t", | ||
| 1114 | - "0.64", | ||
| 1115 | - "-f", | ||
| 1116 | - "yuv4mpegpipe", | ||
| 1117 | - "-strict", | ||
| 1118 | - "-1", | ||
| 1119 | - "-", | ||
| 1120 | - ]) | ||
| 1121 | - .stdin(Stdio::null()) | ||
| 1122 | - .stdout(Stdio::piped()) | ||
| 1123 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1124 | - .expect("ffmpeg failed to run"); | ||
| 1125 | - assert!( | ||
| 1126 | - y4m.status.success(), | ||
| 1127 | - "ffmpeg fixture: {}", | ||
| 1128 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1129 | - ); | ||
| 1130 | - let depth_args: &[&str] = if bit_depth == 10 { | ||
| 1131 | - &["-b", "10", "--input-bit-depth=10"] | ||
| 1132 | - } else { | ||
| 1133 | - &[] | ||
| 1134 | - }; | ||
| 1135 | - // The cq sweep: how finely RD partitions decides how often a | ||
| 1136 | - // block's stack comes up short enough to reach the extension | ||
| 1137 | - // pass at all. | ||
| 1138 | - let cq = format!("--cq-level={}", [45u32, 55, 35][(attempt % 3) as usize]); | ||
| 1139 | - let sb = format!("--sb-size={sb_size}"); | ||
| 1140 | - let gm = format!("--enable-global-motion={global_motion}"); | ||
| 1141 | - // `--tile-columns` is log2: 1 means two tile columns, which is | ||
| 1142 | - // what makes every block in the right-hand tile carry a nonzero | ||
| 1143 | - // `tile_col0` and so exercise r1 defect 3's reach clamp. | ||
| 1144 | - let tiles = format!("--tile-columns={tile_columns}"); | ||
| 1145 | - // class [[aomenc-last-flag-wins]]: every flag appears exactly | ||
| 1146 | - // once below, so there is no override to order. | ||
| 1147 | - let out = run_with_stdin( | ||
| 1148 | - Command::new(aomenc_path()) | ||
| 1149 | - .args(depth_args) | ||
| 1150 | - .arg(&cq) | ||
| 1151 | - .arg(&sb) | ||
| 1152 | - .arg(&gm) | ||
| 1153 | - .arg(&tiles) | ||
| 1154 | - .args([ | ||
| 1155 | - "--codec=av1", | ||
| 1156 | - "--passes=1", | ||
| 1157 | - "--end-usage=q", | ||
| 1158 | - "--cpu-used=0", | ||
| 1159 | - "--kf-max-dist=1000", | ||
| 1160 | - "--threads=1", | ||
| 1161 | - "--row-mt=0", | ||
| 1162 | - // What this gate is about: real compound references | ||
| 1163 | - // with a real temporal MV field behind them. | ||
| 1164 | - "--enable-ref-frame-mvs=1", | ||
| 1165 | - "--enable-order-hint=1", | ||
| 1166 | - "--auto-alt-ref=1", | ||
| 1167 | - "--lag-in-frames=25", | ||
| 1168 | - "--enable-fwd-kf=0", | ||
| 1169 | - "--enable-warped-motion=0", | ||
| 1170 | - "--enable-obmc=0", | ||
| 1171 | - "--enable-masked-comp=0", | ||
| 1172 | - "--enable-interintra-comp=0", | ||
| 1173 | - "--enable-dist-wtd-comp=0", | ||
| 1174 | - "--enable-diff-wtd-comp=0", | ||
| 1175 | - "--enable-onesided-comp=0", | ||
| 1176 | - "--enable-interintra-wedge=0", | ||
| 1177 | - "--enable-smooth-interintra=0", | ||
| 1178 | - "--enable-rect-partitions=0", | ||
| 1179 | - "--enable-ab-partitions=0", | ||
| 1180 | - "--enable-1to4-partitions=0", | ||
| 1181 | - "--enable-filter-intra=0", | ||
| 1182 | - "--enable-smooth-intra=0", | ||
| 1183 | - "--enable-paeth-intra=0", | ||
| 1184 | - "--enable-directional-intra=0", | ||
| 1185 | - "--enable-angle-delta=0", | ||
| 1186 | - "--enable-tx-size-search=0", | ||
| 1187 | - "--enable-cdef=0", | ||
| 1188 | - "--enable-restoration=0", | ||
| 1189 | - "--max-partition-size=32", | ||
| 1190 | - "--min-partition-size=32", | ||
| 1191 | - "--enable-palette=0", | ||
| 1192 | - "--enable-intrabc=0", | ||
| 1193 | - "--enable-cfl-intra=0", | ||
| 1194 | - "--obu", | ||
| 1195 | - "-o", | ||
| 1196 | - "-", | ||
| 1197 | - "-", | ||
| 1198 | - ]), | ||
| 1199 | - &y4m.stdout, | ||
| 1200 | - ); | ||
| 1201 | - assert!( | ||
| 1202 | - out.status.success(), | ||
| 1203 | - "aomenc refused the fixture: {}", | ||
| 1204 | - String::from_utf8_lossy(&out.stderr) | ||
| 1205 | - ); | ||
| 1206 | - let stream = out.stdout; | ||
| 1207 | - let (before_comp, before_tmv) = (decode::comp_mode_hits(), decode::tmv_hits()); | ||
| 1208 | - let frames = match decode_stream(&stream) { | ||
| 1209 | - Err(e) => { | ||
| 1210 | - let msg = e.to_string(); | ||
| 1211 | - assert!( | ||
| 1212 | - msg.contains("unsupported"), | ||
| 1213 | - "{gate_name} failed outright (seed {seed}): {msg}" | ||
| 1214 | - ); | ||
| 1215 | - refusals.push(format!("seed {seed}: {msg}")); | ||
| 1216 | - continue; | ||
| 1217 | - } | ||
| 1218 | - Ok(frames) => frames, | ||
| 1219 | - }; | ||
| 1220 | - let counted = | ||
| 1221 | - decode::comp_mode_hits() != before_comp && decode::tmv_hits() != before_tmv; | ||
| 1222 | - if !counted { | ||
| 1223 | - never_fired += 1; | ||
| 1224 | - } | ||
| 1225 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1226 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1227 | - } else { | ||
| 1228 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1229 | - }; | ||
| 1230 | - assert_eq!(frames.len(), frame_count); | ||
| 1231 | - // Every SHOWN/display frame `decode_stream` returned is compared -- | ||
| 1232 | - // that is decode_stream's whole output, and nothing else is. | ||
| 1233 | - // HIDDEN frames are NOT covered here: they are never emitted as | ||
| 1234 | - // pictures, so no ffmpeg picture corresponds to them (class | ||
| 1235 | - // [[gate-blind-to-hidden-frames]]). | ||
| 1236 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1237 | - assert_eq!( | ||
| 1238 | - got.y, want.y, | ||
| 1239 | - "{gate_name} frame {i} luma vs ffmpeg (seed {seed})" | ||
| 1240 | - ); | ||
| 1241 | - assert_eq!( | ||
| 1242 | - got.u, want.u, | ||
| 1243 | - "{gate_name} frame {i} U vs ffmpeg (seed {seed})" | ||
| 1244 | - ); | ||
| 1245 | - assert_eq!( | ||
| 1246 | - got.v, want.v, | ||
| 1247 | - "{gate_name} frame {i} V vs ffmpeg (seed {seed})" | ||
| 1248 | - ); | ||
| 1249 | - } | ||
| 1250 | - if counted { | ||
| 1251 | - eprintln!( | ||
| 1252 | - "{gate_name} FIRING seed {seed}: comp_mode_hits +{}, tmv_hits +{}, \ | ||
| 1253 | - comp_gm_fill_hits={}, stack_full_drops={}, tile_reach_clips={}", | ||
| 1254 | - decode::comp_mode_hits() - before_comp, | ||
| 1255 | - decode::tmv_hits() - before_tmv, | ||
| 1256 | - crate::mvstack::comp_gm_fill_hits(), | ||
| 1257 | - crate::mvstack::stack_full_drops(), | ||
| 1258 | - crate::mvstack::tile_reach_clips(), | ||
| 1259 | - ); | ||
| 1260 | - gate_buckets(gate_name, 1, never_fired, refusals.len()); | ||
| 1261 | - return; | ||
| 1262 | - } | ||
| 1263 | - } | ||
| 1264 | - gate_buckets(gate_name, 0, never_fired, refusals.len()); | ||
| 1265 | - eprintln!( | ||
| 1266 | - "SKIP {gate_name}: {never_fired} attempts decoded but never drove a compound block \ | ||
| 1267 | - with a temporal MV candidate, and every other attempt hit a named refusal:\n{}", | ||
| 1268 | - refusals.join("\n") | ||
| 1269 | - ); | ||
| 1270 | - } | ||
| 1271 | - | ||
| 1272 | - /// lane-seg: a real `aomenc` stream with SEGMENTATION genuinely active. | ||
| 1273 | - /// `--aq-mode=1` (variance AQ) / `--aq-mode=2` (complexity AQ) are the two | ||
| 1274 | - /// paths libaom uses to switch `segmentation_enabled` on by itself | ||
| 1275 | - /// (`av1_vaq_frame_setup`/`av1_setup_in_frame_q_adj`, both of which only | ||
| 1276 | - /// ever set `SEG_LVL_ALT_Q`); `--deltaq-mode=0` keeps the per-superblock | ||
| 1277 | - /// delta-q reader out of the picture so a mismatch points at the segment | ||
| 1278 | - /// map, not at `CurrentQIndex`. Mandelbrot's varying local contrast is | ||
| 1279 | - /// what gives variance/complexity AQ different segments to assign -- | ||
| 1280 | - /// a flat gradient collapses every block onto one segment, which the | ||
| 1281 | - /// `segment_ids_seen() >= 2` assert below would catch as a vacuous run. | ||
| 1282 | - /// The rest of the recipe is the delta-q gate's own feature-disable | ||
| 1283 | - /// envelope, so this gate isolates the segmentation reader. | ||
| 1284 | - pub(super) fn run_segmentation_gate( | ||
| 1285 | - name: &str, | ||
| 1286 | - aq_mode: &str, | ||
| 1287 | - bit_depth: usize, | ||
| 1288 | - frame_count: usize, | ||
| 1289 | - rate_args: &[&str], | ||
| 1290 | - ) { | ||
| 1291 | - let _gate_lock = lock_gate_counters(); | ||
| 1292 | - if !have_ffmpeg() { | ||
| 1293 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1294 | - return; | ||
| 1295 | - } | ||
| 1296 | - if !have_aomenc() { | ||
| 1297 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1298 | - return; | ||
| 1299 | - } | ||
| 1300 | - crate::decode::reset_segment_hits(); | ||
| 1301 | - let (width, height) = (128usize, 64usize); | ||
| 1302 | - let mut named_refusals = 0u32; | ||
| 1303 | - let mut matched = 0u32; | ||
| 1304 | - let n_attempts: u32 = std::env::var("EC_SEG_GATE_ATTEMPTS") | ||
| 1305 | - .ok() | ||
| 1306 | - .and_then(|s| s.parse().ok()) | ||
| 1307 | - .unwrap_or(10); | ||
| 1308 | - for attempt in 0..n_attempts { | ||
| 1309 | - let seed = 42 + attempt; | ||
| 1310 | - let duration = frame_count as f64 / 25.0; | ||
| 1311 | - let source = format!( | ||
| 1312 | - "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}", | ||
| 1313 | - sx = -0.6 + 0.005 * (attempt as f64), | ||
| 1314 | - sy = -0.4 + 0.005 * (attempt as f64) | ||
| 1315 | - ); | ||
| 1316 | - let pix_fmt = if bit_depth == 10 { | ||
| 1317 | - "yuv420p10le" | ||
| 1318 | - } else { | ||
| 1319 | - "yuv420p" | ||
| 1320 | - }; | ||
| 1321 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1322 | - .args([ | ||
| 1323 | - "-v", | ||
| 1324 | - "error", | ||
| 1325 | - "-f", | ||
| 1326 | - "lavfi", | ||
| 1327 | - "-i", | ||
| 1328 | - &source, | ||
| 1329 | - "-t", | ||
| 1330 | - &duration.to_string(), | ||
| 1331 | - "-pix_fmt", | ||
| 1332 | - pix_fmt, | ||
| 1333 | - "-strict", | ||
| 1334 | - "-1", | ||
| 1335 | - "-f", | ||
| 1336 | - "yuv4mpegpipe", | ||
| 1337 | - "-", | ||
| 1338 | - ]) | ||
| 1339 | - .stdin(Stdio::null()) | ||
| 1340 | - .stdout(Stdio::piped()) | ||
| 1341 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1342 | - .expect("ffmpeg failed to run"); | ||
| 1343 | - assert!( | ||
| 1344 | - y4m.status.success(), | ||
| 1345 | - "ffmpeg fixture: {}", | ||
| 1346 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1347 | - ); | ||
| 1348 | - let depth_args: Vec<String> = if bit_depth == 10 { | ||
| 1349 | - vec![ | ||
| 1350 | - "--input-bit-depth=10".to_owned(), | ||
| 1351 | - "--bit-depth=10".to_owned(), | ||
| 1352 | - ] | ||
| 1353 | - } else { | ||
| 1354 | - Vec::new() | ||
| 1355 | - }; | ||
| 1356 | - let aq = format!("--aq-mode={aq_mode}"); | ||
| 1357 | - let mut args: Vec<&str> = vec![ | ||
| 1358 | - "--codec=av1", | ||
| 1359 | - "--passes=1", | ||
| 1360 | - "--cpu-used=4", | ||
| 1361 | - &aq, | ||
| 1362 | - "--deltaq-mode=0", | ||
| 1363 | - "--enable-cdef=0", | ||
| 1364 | - "--kf-max-dist=1000", | ||
| 1365 | - "--threads=1", | ||
| 1366 | - "--row-mt=0", | ||
| 1367 | - "--sb-size=64", | ||
| 1368 | - "--auto-alt-ref=1", | ||
| 1369 | - "--lag-in-frames=16", | ||
| 1370 | - "--enable-fwd-kf=0", | ||
| 1371 | - "--enable-order-hint=1", | ||
| 1372 | - "--enable-warped-motion=1", | ||
| 1373 | - "--enable-global-motion=0", | ||
| 1374 | - "--enable-obmc=1", | ||
| 1375 | - "--tune-content=default", | ||
| 1376 | - "--enable-masked-comp=1", | ||
| 1377 | - "--enable-dist-wtd-comp=0", | ||
| 1378 | - "--enable-interintra-comp=1", | ||
| 1379 | - "--enable-onesided-comp=0", | ||
| 1380 | - "--enable-interintra-wedge=0", | ||
| 1381 | - "--enable-smooth-interintra=1", | ||
| 1382 | - "--enable-rect-partitions=0", | ||
| 1383 | - "--enable-ab-partitions=0", | ||
| 1384 | - "--enable-1to4-partitions=0", | ||
| 1385 | - "--enable-filter-intra=0", | ||
| 1386 | - "--enable-smooth-intra=0", | ||
| 1387 | - "--enable-paeth-intra=0", | ||
| 1388 | - "--enable-directional-intra=0", | ||
| 1389 | - "--enable-angle-delta=0", | ||
| 1390 | - "--enable-tx-size-search=0", | ||
| 1391 | - "--enable-cdef=1", | ||
| 1392 | - "--enable-restoration=0", | ||
| 1393 | - "--max-partition-size=32", | ||
| 1394 | - "--min-partition-size=32", | ||
| 1395 | - "--enable-palette=0", | ||
| 1396 | - "--enable-intrabc=0", | ||
| 1397 | - "--enable-cfl-intra=0", | ||
| 1398 | - "--enable-ref-frame-mvs=0", | ||
| 1399 | - ]; | ||
| 1400 | - args.extend(rate_args.iter().copied()); | ||
| 1401 | - args.extend(depth_args.iter().map(String::as_str)); | ||
| 1402 | - args.extend(["--obu", "-o", "-", "-"]); | ||
| 1403 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 1404 | - assert!( | ||
| 1405 | - out.status.success(), | ||
| 1406 | - "aomenc refused the fixture: {}", | ||
| 1407 | - String::from_utf8_lossy(&out.stderr) | ||
| 1408 | - ); | ||
| 1409 | - let stream = out.stdout; | ||
| 1410 | - // The stream must really carry `segmentation_enabled`, or the | ||
| 1411 | - // gate proves nothing about the reader. | ||
| 1412 | - let mut seg_frames = 0u32; | ||
| 1413 | - { | ||
| 1414 | - let mut probe = Av1Parser::new(); | ||
| 1415 | - let mut pos = 0usize; | ||
| 1416 | - while pos < stream.len() { | ||
| 1417 | - let obu = probe | ||
| 1418 | - .parse_obu(&stream[pos..]) | ||
| 1419 | - .expect("parsing the gate stream"); | ||
| 1420 | - pos += obu.total_size; | ||
| 1421 | - match &obu.kind { | ||
| 1422 | - ObuKind::Frame(h, _) => { | ||
| 1423 | - if h.segmentation.enabled { | ||
| 1424 | - seg_frames += 1; | ||
| 1425 | - } | ||
| 1426 | - } | ||
| 1427 | - ObuKind::FrameHeader(h) | ||
| 1428 | - if h.segmentation.enabled => { | ||
| 1429 | - seg_frames += 1; | ||
| 1430 | - } | ||
| 1431 | - _ => {} | ||
| 1432 | - } | ||
| 1433 | - } | ||
| 1434 | - } | ||
| 1435 | - if seg_frames == 0 { | ||
| 1436 | - eprintln!( | ||
| 1437 | - "seed {seed}: aomenc wrote no segmentation-enabled frame, skipping attempt" | ||
| 1438 | - ); | ||
| 1439 | - continue; | ||
| 1440 | - } | ||
| 1441 | - let frames = match decode_stream(&stream) { | ||
| 1442 | - Err(e) => { | ||
| 1443 | - let msg = e.to_string(); | ||
| 1444 | - assert!( | ||
| 1445 | - msg.contains("unsupported"), | ||
| 1446 | - "{name} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 1447 | - ); | ||
| 1448 | - assert!( | ||
| 1449 | - !msg.contains("segment_id symbol"), | ||
| 1450 | - "{name} refused on the segmentation reader itself (seed {seed}): {msg}" | ||
| 1451 | - ); | ||
| 1452 | - named_refusals += 1; | ||
| 1453 | - eprintln!("seed {seed} refusal: {msg}"); | ||
| 1454 | - continue; | ||
| 1455 | - } | ||
| 1456 | - Ok(frames) => frames, | ||
| 1457 | - }; | ||
| 1458 | - let ffmpeg_frames = if bit_depth == 10 { | ||
| 1459 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 1460 | - } else { | ||
| 1461 | - ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 1462 | - }; | ||
| 1463 | - assert_eq!(frames.len(), frame_count); | ||
| 1464 | - let mismatched = frames | ||
| 1465 | - .iter() | ||
| 1466 | - .zip(&ffmpeg_frames) | ||
| 1467 | - .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 1468 | - if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 1469 | - std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 1470 | - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | ||
| 1471 | - } | ||
| 1472 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 1473 | - assert_eq!( | ||
| 1474 | - got.y, want.y, | ||
| 1475 | - "{name} frame {i} luma vs ffmpeg (seed {seed})" | ||
| 1476 | - ); | ||
| 1477 | - assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); | ||
| 1478 | - assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); | ||
| 1479 | - } | ||
| 1480 | - matched += 1; | ||
| 1481 | - } | ||
| 1482 | - assert!( | ||
| 1483 | - matched > 0, | ||
| 1484 | - "{name}: every attempt refused on other capabilities ({named_refusals} refusals); \ | ||
| 1485 | - the gate never exercised segmentation" | ||
| 1486 | - ); | ||
| 1487 | - assert!( | ||
| 1488 | - crate::decode::segment_id_hits() > 0, | ||
| 1489 | - "{name}: {matched} pixel-exact matches but zero segment_id symbols fired -- \ | ||
| 1490 | - the reader is unexercised" | ||
| 1491 | - ); | ||
| 1492 | - assert!( | ||
| 1493 | - crate::decode::segment_ids_seen() >= 2, | ||
| 1494 | - "{name}: {matched} pixel-exact matches but only {} distinct segment id(s) -- \ | ||
| 1495 | - every block landed in one segment, so nothing was actually segmented", | ||
| 1496 | - crate::decode::segment_ids_seen() | ||
| 1497 | - ); | ||
| 1498 | - // An inter-frame run must also have exercised the TEMPORAL path | ||
| 1499 | - // (`seg_id_predicted` against the primary reference's saved map); | ||
| 1500 | - // the key-frame-only run has no previous map by construction. | ||
| 1501 | - if frame_count > 1 { | ||
| 1502 | - assert!( | ||
| 1503 | - crate::decode::segment_pred_hits() > 0, | ||
| 1504 | - "{name}: {matched} pixel-exact matches over {frame_count} frames but zero \ | ||
| 1505 | - seg_id_predicted symbols -- the temporal_update path is unexercised" | ||
| 1506 | - ); | ||
| 1507 | - } | ||
| 1508 | - eprintln!( | ||
| 1509 | - "{name}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \ | ||
| 1510 | - out of {n_attempts}, segment_id_hits={}, distinct segment ids={}, \ | ||
| 1511 | - seg_id_predicted symbols={}", | ||
| 1512 | - crate::decode::segment_id_hits(), | ||
| 1513 | - crate::decode::segment_ids_seen(), | ||
| 1514 | - crate::decode::segment_pred_hits() | ||
| 1515 | - ); | ||
| 1516 | - } | ||
| 1517 | - | ||
| 1518 | - pub(super) fn edge32_gate(name: &str, flat_band: bool) { | ||
| 1519 | - let _gate_lock = lock_gate_counters(); | ||
| 1520 | - if !have_ffmpeg() { | ||
| 1521 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1522 | - return; | ||
| 1523 | - } | ||
| 1524 | - if !have_aomenc() { | ||
| 1525 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1526 | - return; | ||
| 1527 | - } | ||
| 1528 | - // (width, height, frames, ten_bit, tile_columns_log2) | ||
| 1529 | - let mut arms: Vec<(usize, usize, usize, bool, u32)> = Vec::new(); | ||
| 1530 | - for &(w, h) in &[(192usize, 80usize), (80usize, 192usize)] { | ||
| 1531 | - arms.push((w, h, 1, false, 0)); | ||
| 1532 | - arms.push((w, h, 1, true, 0)); | ||
| 1533 | - } | ||
| 1534 | - // The inter arm: >= 4 frames so the 32-level edge path in the INTER | ||
| 1535 | - // tile walk is exercised too. | ||
| 1536 | - arms.push((192, 80, 5, false, 0)); | ||
| 1537 | - // lane-golomb r9: the straddling-band arms, only under the ignored | ||
| 1538 | - // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are | ||
| 1539 | - // RED -- see that test's own comment for the stage bisection). Naming | ||
| 1540 | - // them here rather than in a second copy of this gate keeps the | ||
| 1541 | - // recipe, the counters and the refusal handling identical. | ||
| 1542 | - if name == "a_frame_edge_straddling_band_decodes_pixel_exact" { | ||
| 1543 | - arms.clear(); | ||
| 1544 | - for &tile_cols in &[0u32, 1] { | ||
| 1545 | - arms.push((192, 68, 5, false, tile_cols)); | ||
| 1546 | - arms.push((192, 68, 5, true, tile_cols)); | ||
| 1547 | - arms.push((68, 192, 5, false, tile_cols)); | ||
| 1548 | - arms.push((68, 192, 5, true, tile_cols)); | ||
| 1549 | - } | ||
| 1550 | - } | ||
| 1551 | - // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is | ||
| 1552 | - // vacuous, panicking or red -- each measured this round with | ||
| 1553 | - // `arms.push((192, 68, 5, false))`, log | ||
| 1554 | - // `$HOME/.cache/golomb-gate-r8{b,e,f,g}.log`): | ||
| 1555 | - // * the r7 blocker IS fixed -- no attempt refuses "a reference | ||
| 1556 | - // picture whose height does not match this frame's own true | ||
| 1557 | - // size" any more (`decode.rs`'s comparison now uses the header's | ||
| 1558 | - // frame height, per libaom's crop-dimension reference test). | ||
| 1559 | - // * cq35 now refuses LATER, by another lane's name: "an inter | ||
| 1560 | - // SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)" -- so the | ||
| 1561 | - // arm compares nothing (class `counter-from-refused-stream`). | ||
| 1562 | - // * cq40 PANICS in `decode_inter_block8` | ||
| 1563 | - // (`from_switchable_symbol` handed a 4th symbol, `mc.rs:203`) = | ||
| 1564 | - // lane-sub8's own open below-8x8 desync; a panic cannot be | ||
| 1565 | - // tolerated as a named refusal. | ||
| 1566 | - // * cq59 8-bit is RED: `frame 1 plane Y: 217 pixels differ, first | ||
| 1567 | - // at row 60 col 170 (ours 172 vs ffmpeg 173)`, and the cq35 | ||
| 1568 | - // 10-bit twin is RED at `row 56 col 48 (ours 530 vs ffmpeg | ||
| 1569 | - // 531)`. Both are +-1 bands in rows 56..63, i.e. the deblock/CDEF | ||
| 1570 | - // bleed ABOVE the 4-px straddling row band (64..67) -- the same | ||
| 1571 | - // shape as the `(68, 192, 5, false)` column defect below, so the | ||
| 1572 | - // two are very likely ONE straddling-band reconstruction defect. | ||
| 1573 | - // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red): | ||
| 1574 | - // a 68-px axis leaves the last superblock straddling by 4 px, the | ||
| 1575 | - // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >= | ||
| 1576 | - // max_w_mi` early return exists for. With | ||
| 1577 | - // `arms.push((192, 68, 5, false))` all EIGHT cq attempts refuse by | ||
| 1578 | - // name -- "a reference picture whose height does not match this | ||
| 1579 | - // frame's own true size" -- so the arm compares nothing (class | ||
| 1580 | - // `counter-from-refused-stream`). With | ||
| 1581 | - // `arms.push((68, 192, 5, false))` the gate goes RED on a real, | ||
| 1582 | - // separate defect: `68x192 cq35 frames=5 10bit=false frame 1 plane Y: | ||
| 1583 | - // 141 pixels differ, first at row 0 col 64 (ours 167 vs ffmpeg 166) | ||
| 1584 | - // [edge32=[0,34,0,0,1,17,0,1]]` -- LUMA, inside the 4-px straddling | ||
| 1585 | - // COLUMN. Both are unrelated to this round's chroma tx_type fix. | ||
| 1586 | - let cqs: [u32; 8] = [35, 40, 45, 50, 55, 57, 59, 61]; | ||
| 1587 | - let mut totals = [0usize; 8]; | ||
| 1588 | - let mut compared = 0usize; | ||
| 1589 | - // lane-t900 r15 (class `counter-from-refused-stream`): the aggregate | ||
| 1590 | - // `compared` counter is carried by the single-tile arms alone, so the | ||
| 1591 | - // `--tile-columns=1` twins were free to refuse every attempt and keep | ||
| 1592 | - // the gate green. Counted separately and asserted below. | ||
| 1593 | - let mut compared_multi_tile = 0usize; | ||
| 1594 | - let mut refusals: Vec<String> = Vec::new(); | ||
| 1595 | - let straddle = name == "a_frame_edge_straddling_band_decodes_pixel_exact"; | ||
| 1596 | - let mut straddle_units = 0usize; | ||
| 1597 | - for &(width, height, frame_count, ten_bit, tile_cols) in &arms { | ||
| 1598 | - for &cq in &cqs { | ||
| 1599 | - let duration = frame_count as f64 / 25.0; | ||
| 1600 | - // `noise` (explicit seed) both defeats aomenc's | ||
| 1601 | - // screen-content detection -- which otherwise refuses every | ||
| 1602 | - // attempt at "a HORZ/VERT intra strip in a screen-content | ||
| 1603 | - // frame" -- and keeps the RD search off flat NONE blocks. | ||
| 1604 | - // Natural content over the whole superblock-aligned area, | ||
| 1605 | - // with the 16-px straddling band left FLAT (`pad`): with | ||
| 1606 | - // detail in that band aomenc always answers the edge bit with | ||
| 1607 | - // SPLIT (measured: 178 edge bits, 178 of them SPLIT, over a | ||
| 1608 | - // cq 35..61 sweep), so the HORZ/VERT arm this round guards | ||
| 1609 | - // never fired. `noise` on top keeps screen-content detection | ||
| 1610 | - // (and its palette-strip refusal) off. | ||
| 1611 | - let (cw, ch) = ( | ||
| 1612 | - if flat_band && width % 64 != 0 { | ||
| 1613 | - width - 16 | ||
| 1614 | - } else { | ||
| 1615 | - width | ||
| 1616 | - }, | ||
| 1617 | - if flat_band && height % 64 != 0 { | ||
| 1618 | - height - 16 | ||
| 1619 | - } else { | ||
| 1620 | - height | ||
| 1621 | - }, | ||
| 1622 | - ); | ||
| 1623 | - let pad = if flat_band { | ||
| 1624 | - format!("pad={width}:{height}:0:0:gray,") | ||
| 1625 | - } else { | ||
| 1626 | - String::new() | ||
| 1627 | - }; | ||
| 1628 | - let source = format!( | ||
| 1629 | - "testsrc2=size={cw}x{ch}:duration={duration}:rate=25,\ | ||
| 1630 | - {pad}noise=alls=6:allf=t+u:all_seed={cq}" | ||
| 1631 | - ); | ||
| 1632 | - let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 1633 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1634 | - .args([ | ||
| 1635 | - "-v", | ||
| 1636 | - "error", | ||
| 1637 | - "-f", | ||
| 1638 | - "lavfi", | ||
| 1639 | - "-i", | ||
| 1640 | - &source, | ||
| 1641 | - "-pix_fmt", | ||
| 1642 | - pix, | ||
| 1643 | - "-strict", | ||
| 1644 | - "-1", | ||
| 1645 | - "-t", | ||
| 1646 | - &format!("{duration}"), | ||
| 1647 | - "-f", | ||
| 1648 | - "yuv4mpegpipe", | ||
| 1649 | - "-", | ||
| 1650 | - ]) | ||
| 1651 | - .stdin(Stdio::null()) | ||
| 1652 | - .stdout(Stdio::piped()) | ||
| 1653 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1654 | - .expect("ffmpeg failed to run"); | ||
| 1655 | - assert!( | ||
| 1656 | - y4m.status.success(), | ||
| 1657 | - "{name}: ffmpeg fixture: {}", | ||
| 1658 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1659 | - ); | ||
| 1660 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 1661 | - let mut args: Vec<&str> = vec![ | ||
| 1662 | - "--codec=av1", | ||
| 1663 | - "--passes=1", | ||
| 1664 | - "--end-usage=q", | ||
| 1665 | - &cq_arg, | ||
| 1666 | - "--cpu-used=0", | ||
| 1667 | - "--threads=1", | ||
| 1668 | - "--row-mt=0", | ||
| 1669 | - "--sb-size=64", | ||
| 1670 | - "--enable-restoration=0", | ||
| 1671 | - "--enable-palette=0", | ||
| 1672 | - "--deltaq-mode=0", | ||
| 1673 | - "--enable-intrabc=0", | ||
| 1674 | - // Per-arm overrides go LAST (aomenc keeps the last | ||
| 1675 | - // occurrence of a repeated --enable-* flag). | ||
| 1676 | - "--enable-rect-partitions=1", | ||
| 1677 | - "--enable-ab-partitions=0", | ||
| 1678 | - "--enable-1to4-partitions=0", | ||
| 1679 | - // 32, not the charter's 8: at 8 the sub-16 AB and | ||
| 1680 | - // split-transform strip arms (still refused by name here) | ||
| 1681 | - // fire before the 32-level edge is reached and EVERY | ||
| 1682 | - // attempt refuses (measured). At 32 the edge block cannot | ||
| 1683 | - // split, so aomenc is forced onto the gathered edge bit's | ||
| 1684 | - // HORZ/VERT -- exactly the arm this round guards. | ||
| 1685 | - "--min-partition-size=32", | ||
| 1686 | - "--tune-content=film", | ||
| 1687 | - "--max-partition-size=64", | ||
| 1688 | - ]; | ||
| 1689 | - if ten_bit { | ||
| 1690 | - args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 1691 | - } | ||
| 1692 | - let tile_arg = format!("--tile-columns={tile_cols}"); | ||
| 1693 | - if tile_cols > 0 { | ||
| 1694 | - args.push(&tile_arg); | ||
| 1695 | - } | ||
| 1696 | - args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 1697 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 1698 | - assert!( | ||
| 1699 | - out.status.success(), | ||
| 1700 | - "{name}: aomenc refused the fixture: {}", | ||
| 1701 | - String::from_utf8_lossy(&out.stderr) | ||
| 1702 | - ); | ||
| 1703 | - let stream = out.stdout; | ||
| 1704 | - if ten_bit { | ||
| 1705 | - assert_eq!( | ||
| 1706 | - parsed_bit_depth(&stream), | ||
| 1707 | - 10, | ||
| 1708 | - "{name}: aomenc did not write a 10-bit sequence header" | ||
| 1709 | - ); | ||
| 1710 | - } | ||
| 1711 | - let tag = format!( | ||
| 1712 | - "{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit} \ | ||
| 1713 | - tile_cols={tile_cols}" | ||
| 1714 | - ); | ||
| 1715 | - let before = crate::decode::edge32_hits(); | ||
| 1716 | - let straddle_before = crate::decode::cdef_straddle_units(); | ||
| 1717 | - // lane-golomb r8: name the attempt BEFORE decoding it -- a | ||
| 1718 | - // desync surfaces as a panic deep in mc.rs with no arm in the | ||
| 1719 | - // message, and r8 spent a run bisecting arms by hand. | ||
| 1720 | - if std::env::var_os("EC_GATE_VERBOSE").is_some() { | ||
| 1721 | - eprintln!("{name}: attempting {tag}"); | ||
| 1722 | - } | ||
| 1723 | - let decoded = match decode_stream(&stream) { | ||
| 1724 | - Ok(frames) => frames, | ||
| 1725 | - Err(e) => { | ||
| 1726 | - let msg = e.to_string(); | ||
| 1727 | - assert!( | ||
| 1728 | - msg.contains("unsupported"), | ||
| 1729 | - "{name} failed outright, not a named refusal ({tag}): {msg}" | ||
| 1730 | - ); | ||
| 1731 | - refusals.push(format!("{tag}: {msg}")); | ||
| 1732 | - continue; | ||
| 1733 | - } | ||
| 1734 | - }; | ||
| 1735 | - let after = crate::decode::edge32_hits(); | ||
| 1736 | - let delta: Vec<usize> = (0..8).map(|i| after[i] - before[i]).collect(); | ||
| 1737 | - // The ENCODE's frame count, and it is PER ARM: the arm tuple's | ||
| 1738 | - // `frame_count` field is what the y4m is built from | ||
| 1739 | - // (`duration = frame_count / 25.0`, 38085, rendered with | ||
| 1740 | - // `-t {duration}` at 38131) and this gate's aomenc carries no | ||
| 1741 | - // `--limit` and no `--lag-in-frames`, so the stream codes exactly | ||
| 1742 | - // `frame_count` frames (1 for the intra arms, 5 for the | ||
| 1743 | - // inter/straddling ones). Asserted ABOVE the oracle call, so a | ||
| 1744 | - // decode that dropped one reds naming the encode. | ||
| 1745 | - assert_eq!( | ||
| 1746 | - decoded.len(), | ||
| 1747 | - frame_count, | ||
| 1748 | - "{name}: {tag}: the encode codes {frame_count} frame(s), the decode showed {}", | ||
| 1749 | - decoded.len() | ||
| 1750 | - ); | ||
| 1751 | - let reference = if ten_bit { | ||
| 1752 | - ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()) | ||
| 1753 | - } else { | ||
| 1754 | - ffmpeg_decode_sequence(&stream, width, height, decoded.len()) | ||
| 1755 | - }; | ||
| 1756 | - assert_eq!( | ||
| 1757 | - decoded.len(), | ||
| 1758 | - reference.len(), | ||
| 1759 | - "{name}: {tag}: shown-frame count vs ffmpeg" | ||
| 1760 | - ); | ||
| 1761 | - for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() { | ||
| 1762 | - for (plane, a, b, w) in [ | ||
| 1763 | - ("Y", &ours.y, &theirs.y, width), | ||
| 1764 | - ("U", &ours.u, &theirs.u, width / 2), | ||
| 1765 | - ("V", &ours.v, &theirs.v, width / 2), | ||
| 1766 | - ] { | ||
| 1767 | - if let Some(d) = a.iter().zip(b.iter()).position(|(x, y)| x != y) { | ||
| 1768 | - let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count(); | ||
| 1769 | - if std::env::var_os("EC_EDGE32_ROWS").is_some() { | ||
| 1770 | - let mut per_row: std::collections::BTreeMap<usize, usize> = | ||
| 1771 | - Default::default(); | ||
| 1772 | - for (k, (x, y)) in a.iter().zip(b.iter()).enumerate() { | ||
| 1773 | - if x != y { | ||
| 1774 | - *per_row.entry(k / w).or_default() += 1; | ||
| 1775 | - } | ||
| 1776 | - } | ||
| 1777 | - eprintln!("{name}: {tag} plane {plane} diffs per row: {per_row:?}"); | ||
| 1778 | - } | ||
| 1779 | - panic!( | ||
| 1780 | - "{name}: {tag} frame {i} plane {plane}: {n} pixels differ, first \ | ||
| 1781 | - at row {} col {} (ours {} vs ffmpeg {}) [edge32={delta:?}]", | ||
| 1782 | - d / w, | ||
| 1783 | - d % w, | ||
| 1784 | - a[d], | ||
| 1785 | - b[d] | ||
| 1786 | - ); | ||
| 1787 | - } | ||
| 1788 | - assert_eq!( | ||
| 1789 | - a.len(), | ||
| 1790 | - b.len(), | ||
| 1791 | - "{name}: {tag} frame {i} plane {plane}: ours has {} samples, \ | ||
| 1792 | - ffmpeg's has {} -- a short plane would zip-truncate the walk above \ | ||
| 1793 | - and hide a chroma-span defect", | ||
| 1794 | - a.len(), | ||
| 1795 | - b.len() | ||
| 1796 | - ); | ||
| 1797 | - } | ||
| 1798 | - } | ||
| 1799 | - compared += 1; | ||
| 1800 | - if tile_cols > 0 { | ||
| 1801 | - compared_multi_tile += 1; | ||
| 1802 | - } | ||
| 1803 | - straddle_units += crate::decode::cdef_straddle_units() - straddle_before; | ||
| 1804 | - for i in 0..8 { | ||
| 1805 | - totals[i] += delta[i]; | ||
| 1806 | - } | ||
| 1807 | - } | ||
| 1808 | - } | ||
| 1809 | - assert!( | ||
| 1810 | - compared > 0, | ||
| 1811 | - "{name}: every attempt hit a named refusal:\n{}", | ||
| 1812 | - refusals.join("\n") | ||
| 1813 | - ); | ||
| 1814 | - assert!( | ||
| 1815 | - !straddle || compared_multi_tile > 0, | ||
| 1816 | - "{name}: every `--tile-columns=1` attempt hit a named refusal -- the \ | ||
| 1817 | - multi-tile twins compared nothing:\n{}", | ||
| 1818 | - refusals.join("\n") | ||
| 1819 | - ); | ||
| 1820 | - assert!( | ||
| 1821 | - !straddle || straddle_units > 0, | ||
| 1822 | - "{name}: no FILTERED 8x8 CDEF unit crossed the cropped frame edge over \ | ||
| 1823 | - {compared} compared attempts -- the straddling arms proved nothing" | ||
| 1824 | - ); | ||
| 1825 | - assert!( | ||
| 1826 | - totals[0] + totals[1] + totals[4] + totals[5] > 0, | ||
| 1827 | - "{name}: no frame-edge partition bit was read at all over \ | ||
| 1828 | - {compared} compared attempts -- the gate proved nothing" | ||
| 1829 | - ); | ||
| 1830 | - // lane-golomb r3: the flat-band arm's ASSERT moved one level up. Until | ||
| 1831 | - // r3 the last superblock row was reached through a 32-level edge bit | ||
| 1832 | - // only because our own out-of-frame transform units had desynced the | ||
| 1833 | - // stream; with that fixed, real aomenc answers a bottom-edge | ||
| 1834 | - // superblock with the 64-level `PARTITION_HORZ` (and a right-edge one | ||
| 1835 | - // with `PARTITION_VERT`) and the 32-level slots stay 0 on this | ||
| 1836 | - // content. Slots 6/7 are the strips actually decoded at the edge. | ||
| 1837 | - assert!( | ||
| 1838 | - !flat_band || totals[6] > 0, | ||
| 1839 | - "{name}: no 64x32 bottom-edge HORZ strip was decoded \ | ||
| 1840 | - (edge32={totals:?}, {compared} compared attempts)" | ||
| 1841 | - ); | ||
| 1842 | - assert!( | ||
| 1843 | - !flat_band || totals[7] > 0, | ||
| 1844 | - "{name}: no 32x64 right-edge VERT strip was decoded \ | ||
| 1845 | - (edge32={totals:?}, {compared} compared attempts)" | ||
| 1846 | - ); | ||
| 1847 | - eprintln!( | ||
| 1848 | - "{name}: {compared} pixel-exact attempts, 32-level edge bits \ | ||
| 1849 | - [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, 64-level edge bits \ | ||
| 1850 | - [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, \ | ||
| 1851 | - {straddle_units} straddling CDEF units, {} named refusals", | ||
| 1852 | - totals[0], | ||
| 1853 | - totals[1], | ||
| 1854 | - totals[2], | ||
| 1855 | - totals[3], | ||
| 1856 | - totals[4], | ||
| 1857 | - totals[5], | ||
| 1858 | - totals[6], | ||
| 1859 | - totals[7], | ||
| 1860 | - refusals.len() | ||
| 1861 | - ); | ||
| 1862 | - for r in &refusals { | ||
| 1863 | - eprintln!("{name} refusal: {r}"); | ||
| 1864 | - } | ||
| 1865 | - } | ||
| 1866 | - | ||
| 1867 | - /// lane-tiles r11: every tile gate before this one turns the coding tools | ||
| 1868 | - /// OFF (rect/ab partitions, tx-size search, cdef, restoration all `=0`) | ||
| 1869 | - /// to isolate the per-tile loop, which is exactly the | ||
| 1870 | - /// [[tool-disabled-in-every-gate]] shape -- a tile-edge defect in any of | ||
| 1871 | - /// those tools is invisible to all of them. This one runs the BROAD tool | ||
| 1872 | - /// set (rect + ab partitions, default tx search, cdef and loop | ||
| 1873 | - /// restoration both on, deblocking left at its default so it filters | ||
| 1874 | - /// across tile boundaries as the spec requires) over a real 2D tile grid, | ||
| 1875 | - /// through `decode_stream` rather than the tile entry point, so it is the | ||
| 1876 | - /// same path a caller decoding a file takes. | ||
| 1877 | - /// | ||
| 1878 | - /// 256x128 is four 64x64 superblocks wide and two tall, so | ||
| 1879 | - /// `--tile-columns=1 --tile-rows=1` really yields a 2x2 grid and | ||
| 1880 | - /// `--tile-columns=2` really yields 4 columns; both are asserted from the | ||
| 1881 | - /// parsed `tile_info` rather than assumed, and the decoded-tile counter | ||
| 1882 | - /// (`tile_hits`) is asserted at >= 4 per decoded frame so a stream whose | ||
| 1883 | - /// header claims 4 tiles but whose decode only walked one cannot pass. | ||
| 1884 | - // `#[track_caller]` so a failing assert names the calling arm's line, and | ||
| 1885 | - // so `gate_coverage`'s body split (on `\n #[`) treats this helper's | ||
| 1886 | - // recipe as its own gate rather than gluing it onto the preceding one. | ||
| 1887 | - #[track_caller] | ||
| 1888 | - // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. | ||
| 1889 | - #[allow(clippy::too_many_arguments)] | ||
| 1890 | - pub(super) fn run_multi_tile_gate( | ||
| 1891 | - name: &str, | ||
| 1892 | - tile_cols_log2: u32, | ||
| 1893 | - tile_rows_log2: u32, | ||
| 1894 | - bit_depth: usize, | ||
| 1895 | - frame_count: usize, | ||
| 1896 | - extra: &[&str], | ||
| 1897 | - // lane-tiles r12: the palette arm's own override proof. `true` asserts, | ||
| 1898 | - // per attempt, that the arm's `--tune-content=screen --enable-palette=1` | ||
| 1899 | - // really reached the encoder (frame header `allow_screen_content_tools`) | ||
| 1900 | - // AND that a palette block fired at a TILE's left column -- the exact | ||
| 1901 | - // block whose colour cache must not see the previous tile's colours. | ||
| 1902 | - require_tile_left_palette: bool, | ||
| 1903 | - // `None` = the shared `gradients_source`. The palette arm overrides it | ||
| 1904 | - // with `smptebars`, the flat few-colour source the existing palette | ||
| 1905 | - // gates use -- gradients never make aomenc pick a palette block. | ||
| 1906 | - source_override: Option<&str>, | ||
| 1907 | - ) { | ||
| 1908 | - let _gate_lock = lock_gate_counters(); | ||
| 1909 | - if !have_ffmpeg() { | ||
| 1910 | - eprintln!("SKIP {name}: no ffmpeg"); | ||
| 1911 | - return; | ||
| 1912 | - } | ||
| 1913 | - if !have_aomenc() { | ||
| 1914 | - eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 1915 | - return; | ||
| 1916 | - } | ||
| 1917 | - let (width, height) = (256usize, 128usize); | ||
| 1918 | - let expected_tiles = (1usize << tile_cols_log2) * (1usize << tile_rows_log2); | ||
| 1919 | - let mut matched = 0u32; | ||
| 1920 | - let mut named_refusals = 0u32; | ||
| 1921 | - let mut uv_edge_suppressed = 0usize; | ||
| 1922 | - let n_attempts: u32 = std::env::var("EC_TILES_GATE_ATTEMPTS") | ||
| 1923 | - .ok() | ||
| 1924 | - .and_then(|s| s.parse().ok()) | ||
| 1925 | - .unwrap_or(6); | ||
| 1926 | - for attempt in 0..n_attempts { | ||
| 1927 | - let seed = 42 + attempt; | ||
| 1928 | - let duration = frame_count as f64 / 25.0; | ||
| 1929 | - let source = match source_override { | ||
| 1930 | - Some(src) => format!("{src}=size={width}x{height}:duration={duration}:rate=25"), | ||
| 1931 | - None => { | ||
| 1932 | - gradients_source(seed, width, height, &format!("duration={duration}:rate=25")) | ||
| 1933 | - } | ||
| 1934 | - }; | ||
| 1935 | - let pix_fmt = if bit_depth == 10 { | ||
| 1936 | - "yuv420p10le" | ||
| 1937 | - } else { | ||
| 1938 | - "yuv420p" | ||
| 1939 | - }; | ||
| 1940 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1941 | - .args([ | ||
| 1942 | - "-v", | ||
| 1943 | - "error", | ||
| 1944 | - "-f", | ||
| 1945 | - "lavfi", | ||
| 1946 | - "-i", | ||
| 1947 | - &source, | ||
| 1948 | - "-pix_fmt", | ||
| 1949 | - pix_fmt, | ||
| 1950 | - "-strict", | ||
| 1951 | - "-1", | ||
| 1952 | - "-f", | ||
| 1953 | - "yuv4mpegpipe", | ||
| 1954 | - "-", | ||
| 1955 | - ]) | ||
| 1956 | - .stdin(Stdio::null()) | ||
| 1957 | - .stdout(Stdio::piped()) | ||
| 1958 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1959 | - .expect("ffmpeg failed to run"); | ||
| 1960 | - assert!( | ||
| 1961 | - y4m.status.success(), | ||
| 1962 | - "ffmpeg fixture: {}", | ||
| 1963 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1964 | - ); | ||
| 1965 | - let cols = format!("--tile-columns={tile_cols_log2}"); | ||
| 1966 | - let rows = format!("--tile-rows={tile_rows_log2}"); | ||
| 1967 | - let limit = format!("--limit={frame_count}"); | ||
| 1968 | - let depth_args: Vec<String> = if bit_depth == 10 { | ||
| 1969 | - vec![ | ||
| 1970 | - "--input-bit-depth=10".to_owned(), | ||
| 1971 | - "--bit-depth=10".to_owned(), | ||
| 1972 | - ] | ||
| 1973 | - } else { | ||
| 1974 | - Vec::new() | ||
| 1975 | - }; | ||
| 1976 | - let mut args: Vec<&str> = vec![ | ||
| 1977 | - "--codec=av1", | ||
| 1978 | - "--passes=1", | ||
| 1979 | - "--end-usage=q", | ||
| 1980 | - "--cq-level=40", | ||
| 1981 | - "--cpu-used=4", | ||
| 1982 | - &limit, | ||
| 1983 | - "--kf-max-dist=1000", | ||
| 1984 | - "--threads=1", | ||
| 1985 | - "--row-mt=0", | ||
| 1986 | - // This decoder is 64x64-superblock only, and `--tile-columns` | ||
| 1987 | - // splits on superblock boundaries, so 128x128 superblocks | ||
| 1988 | - // would leave 256px only two tiles' worth of columns. | ||
| 1989 | - "--sb-size=64", | ||
| 1990 | - &cols, | ||
| 1991 | - &rows, | ||
| 1992 | - // The point of this gate: tools ON across tile edges. | ||
| 1993 | - "--enable-rect-partitions=1", | ||
| 1994 | - "--enable-ab-partitions=1", | ||
| 1995 | - "--enable-cdef=1", | ||
| 1996 | - "--enable-restoration=1", | ||
| 1997 | - // Still off: capabilities this decoder refuses outright, which | ||
| 1998 | - // would turn every attempt into a refusal and make the gate | ||
| 1999 | - // vacuous rather than proving anything about tiles. | ||
| 2000 | - "--enable-1to4-partitions=0", | ||
crates/ec-av1/src/stream/tests/mod.rsmodified+1 -17
| @@ -1,22 +1,6 @@ | |||
| 1 | use super::*; | 1 | use super::*; |
| 2 | -use crate::encode::{Picture as Pic, encode_sequence_with_ctx}; | 2 | +use crate::encode::Picture as Pic; |
| 3 | -use crate::probe::run_with_stdin; | ||
| 4 | -use std::process::{Command, Stdio}; | ||
| 5 | 3 | ||
| 6 | -mod gates_a; | ||
| 7 | -mod gates_b; | ||
| 8 | mod layers; | 4 | mod layers; |
| 9 | mod streaming; | 5 | mod streaming; |
| 10 | -mod support; | ||
| 11 | -mod t01; | ||
| 12 | -mod t02; | ||
| 13 | -mod t03; | ||
| 14 | -mod t04; | ||
| 15 | -mod t05; | ||
| 16 | -mod t06; | ||
| 17 | -mod t07; | ||
| 18 | -mod t08; | ||
| 19 | -mod t09; | ||
| 20 | -mod t10; | ||
| 21 | 6 | ||
| 22 | -pub(crate) use gates_a::lock_gate_counters; | ||
crates/ec-av1/src/stream/tests/support.rsdeleted+0 -4172
Diff too large; view file
| @@ -1,4172 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::gates_a::*; | ||
| 3 | - | ||
| 4 | - pub(super) fn test_card(width: usize, height: usize) -> Pic { | ||
| 5 | - let mut picture = Pic::grey(width, height); | ||
| 6 | - for row in 0..height { | ||
| 7 | - for col in 0..width { | ||
| 8 | - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; | ||
| 9 | - } | ||
| 10 | - } | ||
| 11 | - for row in 0..height / 2 { | ||
| 12 | - for col in 0..width / 2 { | ||
| 13 | - let i = row * width / 2 + col; | ||
| 14 | - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; | ||
| 15 | - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; | ||
| 16 | - } | ||
| 17 | - } | ||
| 18 | - picture | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - pub(super) fn panned_test_card(width: usize, height: usize, shift: i64) -> Pic { | ||
| 22 | - let mut picture = Pic::grey(width, height); | ||
| 23 | - for y in 0..height { | ||
| 24 | - for x in 0..width { | ||
| 25 | - let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; | ||
| 26 | - let gradient = sx * 200.0 / width as f64; | ||
| 27 | - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; | ||
| 28 | - } | ||
| 29 | - } | ||
| 30 | - for y in 0..height / 2 { | ||
| 31 | - for x in 0..width / 2 { | ||
| 32 | - let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; | ||
| 33 | - let i = y * width / 2 + x; | ||
| 34 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; | ||
| 35 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; | ||
| 36 | - } | ||
| 37 | - } | ||
| 38 | - picture | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - /// One census attempt: encode `frames` frames of `source` with real | ||
| 42 | - /// aomenc plus `extra` args, decode with THIS decoder, and return the | ||
| 43 | - /// stream's byte length with either the picture count or the refusal (any | ||
| 44 | - /// decode error) it produced. A census is about what the encoder emits, | ||
| 45 | - /// so a refusal is data here, not a failure. | ||
| 46 | - pub(super) fn census_attempt( | ||
| 47 | - source: &str, | ||
| 48 | - width: usize, | ||
| 49 | - height: usize, | ||
| 50 | - frames: usize, | ||
| 51 | - extra: &[&str], | ||
| 52 | - ) -> (usize, std::result::Result<usize, String>) { | ||
| 53 | - let duration = format!("{}", frames as f64 / 25.0); | ||
| 54 | - let src = format!("{source}=size={width}x{height}:rate=25"); | ||
| 55 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 56 | - .args([ | ||
| 57 | - "-v", | ||
| 58 | - "error", | ||
| 59 | - "-f", | ||
| 60 | - "lavfi", | ||
| 61 | - "-i", | ||
| 62 | - &src, | ||
| 63 | - "-t", | ||
| 64 | - &duration, | ||
| 65 | - "-pix_fmt", | ||
| 66 | - "yuv420p", | ||
| 67 | - "-strict", | ||
| 68 | - "-1", | ||
| 69 | - "-f", | ||
| 70 | - "yuv4mpegpipe", | ||
| 71 | - "-", | ||
| 72 | - ]) | ||
| 73 | - .stdin(Stdio::null()) | ||
| 74 | - .stdout(Stdio::piped()) | ||
| 75 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 76 | - .expect("ffmpeg failed to run"); | ||
| 77 | - assert!( | ||
| 78 | - y4m.status.success(), | ||
| 79 | - "ffmpeg refused the {width}x{height} fixture" | ||
| 80 | - ); | ||
| 81 | - let limit = format!("--limit={frames}"); | ||
| 82 | - let mut args: Vec<String> = [ | ||
| 83 | - "--codec=av1", | ||
| 84 | - "--passes=1", | ||
| 85 | - "--end-usage=q", | ||
| 86 | - "--threads=1", | ||
| 87 | - "--row-mt=0", | ||
| 88 | - "--kf-max-dist=9999", | ||
| 89 | - "--lag-in-frames=0", | ||
| 90 | - ] | ||
| 91 | - .iter() | ||
| 92 | - .map(|s| (*s).to_owned()) | ||
| 93 | - .collect(); | ||
| 94 | - args.push(limit); | ||
| 95 | - args.extend(extra.iter().map(|s| (*s).to_owned())); | ||
| 96 | - args.extend([ | ||
| 97 | - "--obu".to_owned(), | ||
| 98 | - "-o".to_owned(), | ||
| 99 | - "-".to_owned(), | ||
| 100 | - "-".to_owned(), | ||
| 101 | - ]); | ||
| 102 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 103 | - assert!( | ||
| 104 | - out.status.success(), | ||
| 105 | - "aomenc refused {args:?}: {}", | ||
| 106 | - String::from_utf8_lossy(&out.stderr) | ||
| 107 | - ); | ||
| 108 | - let stream = out.stdout; | ||
| 109 | - let result = match decode_stream(&stream) { | ||
| 110 | - Ok(pictures) => Ok(pictures.len()), | ||
| 111 | - Err(e) => Err(e.to_string()), | ||
| 112 | - }; | ||
| 113 | - (stream.len(), result) | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /// lane-av1seglvl: encode `frames` frames of `source` with real aomenc | ||
| 117 | - /// plus `extra` args and return the raw `.obu` bytes -- the census's | ||
| 118 | - /// half-sibling of [`census_attempt`] that keeps the STREAM instead of | ||
| 119 | - /// only its decode verdict, so the caller can parse the frame headers' | ||
| 120 | - /// segmentation tables themselves. | ||
| 121 | - pub(super) fn encode_aomenc_stream( | ||
| 122 | - source: &str, | ||
| 123 | - width: usize, | ||
| 124 | - height: usize, | ||
| 125 | - frames: usize, | ||
| 126 | - extra: &[&str], | ||
| 127 | - ) -> Vec<u8> { | ||
| 128 | - let duration = format!("{}", frames as f64 / 25.0); | ||
| 129 | - let src = format!("{source}=size={width}x{height}:rate=25"); | ||
| 130 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 131 | - .args([ | ||
| 132 | - "-v", | ||
| 133 | - "error", | ||
| 134 | - "-f", | ||
| 135 | - "lavfi", | ||
| 136 | - "-i", | ||
| 137 | - &src, | ||
| 138 | - "-t", | ||
| 139 | - &duration, | ||
| 140 | - "-pix_fmt", | ||
| 141 | - "yuv420p", | ||
| 142 | - "-strict", | ||
| 143 | - "-1", | ||
| 144 | - "-f", | ||
| 145 | - "yuv4mpegpipe", | ||
| 146 | - "-", | ||
| 147 | - ]) | ||
| 148 | - .stdin(Stdio::null()) | ||
| 149 | - .stdout(Stdio::piped()) | ||
| 150 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 151 | - .expect("ffmpeg failed to run"); | ||
| 152 | - assert!( | ||
| 153 | - y4m.status.success(), | ||
| 154 | - "ffmpeg refused the {width}x{height} fixture" | ||
| 155 | - ); | ||
| 156 | - let limit = format!("--limit={frames}"); | ||
| 157 | - let mut args: Vec<String> = [ | ||
| 158 | - "--codec=av1", | ||
| 159 | - "--passes=1", | ||
| 160 | - "--end-usage=q", | ||
| 161 | - "--threads=1", | ||
| 162 | - "--row-mt=0", | ||
| 163 | - "--kf-max-dist=9999", | ||
| 164 | - "--lag-in-frames=0", | ||
| 165 | - ] | ||
| 166 | - .iter() | ||
| 167 | - .map(|s| (*s).to_owned()) | ||
| 168 | - .collect(); | ||
| 169 | - args.push(limit); | ||
| 170 | - args.extend(extra.iter().map(|s| (*s).to_owned())); | ||
| 171 | - args.extend([ | ||
| 172 | - "--obu".to_owned(), | ||
| 173 | - "-o".to_owned(), | ||
| 174 | - "-".to_owned(), | ||
| 175 | - "-".to_owned(), | ||
| 176 | - ]); | ||
| 177 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 178 | - assert!( | ||
| 179 | - out.status.success(), | ||
| 180 | - "aomenc refused {args:?}: {}", | ||
| 181 | - String::from_utf8_lossy(&out.stderr) | ||
| 182 | - ); | ||
| 183 | - out.stdout | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - /// lane-av1seglvl: encode `frames` frames with a real TWO-PASS aomenc | ||
| 187 | - /// (pass 1 writes the stats file into the session temp dir, pass 2 | ||
| 188 | - /// consumes it) and return the `.obu` bytes. This is the only shape that | ||
| 189 | - /// reaches libaom's `is_stat_consumption_stage_twopass` segmentation | ||
| 190 | - /// setup (`configure_static_seg_features`), so the census is not proven | ||
| 191 | - /// over the encoder's whole reachable surface without it. | ||
| 192 | - pub(super) fn encode_aomenc_stream_twopass( | ||
| 193 | - source: &str, | ||
| 194 | - width: usize, | ||
| 195 | - height: usize, | ||
| 196 | - frames: usize, | ||
| 197 | - extra: &[&str], | ||
| 198 | - ) -> Vec<u8> { | ||
| 199 | - let duration = format!("{}", frames as f64 / 25.0); | ||
| 200 | - let src = format!("{source}=size={width}x{height}:rate=25"); | ||
| 201 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 202 | - .args([ | ||
| 203 | - "-v", | ||
| 204 | - "error", | ||
| 205 | - "-f", | ||
| 206 | - "lavfi", | ||
| 207 | - "-i", | ||
| 208 | - &src, | ||
| 209 | - "-t", | ||
| 210 | - &duration, | ||
| 211 | - "-pix_fmt", | ||
| 212 | - "yuv420p", | ||
| 213 | - "-strict", | ||
| 214 | - "-1", | ||
| 215 | - "-f", | ||
| 216 | - "yuv4mpegpipe", | ||
| 217 | - "-", | ||
| 218 | - ]) | ||
| 219 | - .stdin(Stdio::null()) | ||
| 220 | - .stdout(Stdio::piped()) | ||
| 221 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 222 | - .expect("ffmpeg failed to run"); | ||
| 223 | - assert!( | ||
| 224 | - y4m.status.success(), | ||
| 225 | - "ffmpeg refused the {width}x{height} fixture" | ||
| 226 | - ); | ||
| 227 | - let limit = format!("--limit={frames}"); | ||
| 228 | - let fpf = | ||
| 229 | - std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id())); | ||
| 230 | - let mut base: Vec<String> = [ | ||
| 231 | - "--codec=av1", | ||
| 232 | - "--passes=2", | ||
| 233 | - "--end-usage=q", | ||
| 234 | - "--threads=1", | ||
| 235 | - "--row-mt=0", | ||
| 236 | - "--kf-max-dist=9999", | ||
| 237 | - "--lag-in-frames=0", | ||
| 238 | - ] | ||
| 239 | - .iter() | ||
| 240 | - .map(|s| (*s).to_owned()) | ||
| 241 | - .collect(); | ||
| 242 | - base.push(limit); | ||
| 243 | - base.extend(extra.iter().map(|s| (*s).to_owned())); | ||
| 244 | - let mut pass1 = base.clone(); | ||
| 245 | - pass1.extend(["--pass=1".to_owned(), format!("--fpf={}", fpf.display())]); | ||
| 246 | - pass1.extend([ | ||
| 247 | - "--obu".to_owned(), | ||
| 248 | - "-o".to_owned(), | ||
| 249 | - "/dev/null".to_owned(), | ||
| 250 | - "-".to_owned(), | ||
| 251 | - ]); | ||
| 252 | - let out1 = run_with_stdin(Command::new(aomenc_path()).args(&pass1), &y4m.stdout); | ||
| 253 | - assert!( | ||
| 254 | - out1.status.success(), | ||
| 255 | - "aomenc pass 1 refused {pass1:?}: {}", | ||
| 256 | - String::from_utf8_lossy(&out1.stderr) | ||
| 257 | - ); | ||
| 258 | - let mut pass2 = base; | ||
| 259 | - pass2.extend(["--pass=2".to_owned(), format!("--fpf={}", fpf.display())]); | ||
| 260 | - pass2.extend([ | ||
| 261 | - "--obu".to_owned(), | ||
| 262 | - "-o".to_owned(), | ||
| 263 | - "-".to_owned(), | ||
| 264 | - "-".to_owned(), | ||
| 265 | - ]); | ||
| 266 | - let out2 = run_with_stdin(Command::new(aomenc_path()).args(&pass2), &y4m.stdout); | ||
| 267 | - let _ = std::fs::remove_file(&fpf); | ||
| 268 | - assert!( | ||
| 269 | - out2.status.success(), | ||
| 270 | - "aomenc pass 2 refused {pass2:?}: {}", | ||
| 271 | - String::from_utf8_lossy(&out2.stderr) | ||
| 272 | - ); | ||
| 273 | - out2.stdout | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | - /// lane-av1seglvl: walk every frame OBU of `stream` and tally which | ||
| 277 | - /// `SEG_LVL` features the frame headers actually ENABLE, plus the shape | ||
| 278 | - /// counters a census premise is asserted against: frames with | ||
| 279 | - /// segmentation on, of which `update_map == 1` (the map is coded) and | ||
| 280 | - /// `update_map == 0` (every block's id is INHERITED), and frames whose | ||
| 281 | - /// table carries a real `SEG_LVL_ALT_Q` delta. | ||
| 282 | - /// The last vector counts per SEGMENT-FEATURE INSTANCE (a frame with | ||
| 283 | - /// ALT_Q on all 8 segments contributes 8), which is all the verdict | ||
| 284 | - /// needs: only index `SEG_LVL_ALT_Q` may be non-zero. | ||
| 285 | - /// Returns `(enabled_frames, update_map_frames, inherited_frames, | ||
| 286 | - /// alt_q_frames, feature_instances: [usize; SEG_LVL_MAX])`. | ||
| 287 | - #[allow(clippy::type_complexity)] | ||
| 288 | - pub(super) fn segmentation_feature_census( | ||
| 289 | - stream: &[u8], | ||
| 290 | - ) -> (usize, usize, usize, usize, [usize; SEG_LVL_MAX]) { | ||
| 291 | - let mut parser = Av1Parser::new(); | ||
| 292 | - let obus = parser | ||
| 293 | - .parse_temporal_unit(stream) | ||
| 294 | - .unwrap_or_else(|e| panic!("the census stream does not even parse: {e}")); | ||
| 295 | - let mut enabled = 0usize; | ||
| 296 | - let mut update_map = 0usize; | ||
| 297 | - let mut inherited = 0usize; | ||
| 298 | - let mut alt_q = 0usize; | ||
| 299 | - let mut feature_frames = [0usize; SEG_LVL_MAX]; | ||
| 300 | - for obu in &obus { | ||
| 301 | - if let ObuKind::Frame(header, _) = &obu.kind { | ||
| 302 | - let seg = &header.segmentation; | ||
| 303 | - if !seg.enabled { | ||
| 304 | - continue; | ||
| 305 | - } | ||
| 306 | - enabled += 1; | ||
| 307 | - if seg.update_map { | ||
| 308 | - update_map += 1; | ||
| 309 | - } else { | ||
| 310 | - inherited += 1; | ||
| 311 | - } | ||
| 312 | - let mut any_q = false; | ||
| 313 | - for segment in 0..MAX_SEGMENTS { | ||
| 314 | - // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it. | ||
| 315 | - #[allow(clippy::needless_range_loop)] | ||
| 316 | - for feature in 0..SEG_LVL_MAX { | ||
| 317 | - if seg.feature_enabled[segment][feature] { | ||
| 318 | - feature_frames[feature] += 1; | ||
| 319 | - if feature == SEG_LVL_ALT_Q { | ||
| 320 | - any_q = true; | ||
| 321 | - } | ||
| 322 | - } | ||
| 323 | - } | ||
| 324 | - } | ||
| 325 | - if any_q { | ||
| 326 | - alt_q += 1; | ||
| 327 | - } | ||
| 328 | - } | ||
| 329 | - } | ||
| 330 | - (enabled, update_map, inherited, alt_q, feature_frames) | ||
| 331 | - } | ||
| 332 | - | ||
| 333 | - /// lane-interedge r1: one attempt of the inter frame-edge half-strip gate -- | ||
| 334 | - /// encode `width x height` with real aomenc (rect partitions ON, every other | ||
| 335 | - /// lane's open tool pinned off), decode it, and return | ||
| 336 | - /// `(inter_edge_strip hits, frames whose LUMA differs, frames whose CHROMA | ||
| 337 | - /// differs)` against ffmpeg. A refusal or a decode error is a hard failure: | ||
| 338 | - /// this recipe reached every size without one (measured r1). | ||
| 339 | - pub(super) fn inter_edge_strip_attempt( | ||
| 340 | - name: &str, | ||
| 341 | - width: usize, | ||
| 342 | - height: usize, | ||
| 343 | - bit_depth: u32, | ||
| 344 | - cq: u32, | ||
| 345 | - frames: usize, | ||
| 346 | - ) -> ([usize; 6], usize, usize) { | ||
| 347 | - let duration = format!("{}", frames as f64 / 25.0); | ||
| 348 | - let source = format!("mandelbrot=size={width}x{height}:rate=25"); | ||
| 349 | - let pix_fmt = if bit_depth == 10 { | ||
| 350 | - "yuv420p10le" | ||
| 351 | - } else { | ||
| 352 | - "yuv420p" | ||
| 353 | - }; | ||
| 354 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 355 | - .args([ | ||
| 356 | - "-v", | ||
| 357 | - "error", | ||
| 358 | - "-f", | ||
| 359 | - "lavfi", | ||
| 360 | - "-i", | ||
| 361 | - &source, | ||
| 362 | - "-t", | ||
| 363 | - &duration, | ||
| 364 | - "-pix_fmt", | ||
| 365 | - pix_fmt, | ||
| 366 | - "-strict", | ||
| 367 | - "-1", | ||
| 368 | - "-f", | ||
| 369 | - "yuv4mpegpipe", | ||
| 370 | - "-", | ||
| 371 | - ]) | ||
| 372 | - .stdin(Stdio::null()) | ||
| 373 | - .stdout(Stdio::piped()) | ||
| 374 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 375 | - .expect("ffmpeg failed to run"); | ||
| 376 | - assert!( | ||
| 377 | - y4m.status.success(), | ||
| 378 | - "{name}: ffmpeg refused the {width}x{height} {bit_depth}-bit fixture: {}", | ||
| 379 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 380 | - ); | ||
| 381 | - let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 382 | - let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 383 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 384 | - let limit_arg = format!("--limit={frames}"); | ||
| 385 | - let out = run_with_stdin( | ||
| 386 | - Command::new(aomenc_path()).args([ | ||
| 387 | - "--codec=av1", | ||
| 388 | - "--passes=1", | ||
| 389 | - "--end-usage=q", | ||
| 390 | - &cq_arg, | ||
| 391 | - // cpu-used >= 1 keeps libaom on 64x64 superblocks at these | ||
| 392 | - // sizes (`av1_select_sb_size`). | ||
| 393 | - "--cpu-used=4", | ||
| 394 | - "--threads=1", | ||
| 395 | - "--row-mt=0", | ||
| 396 | - "--kf-max-dist=9999", | ||
| 397 | - &limit_arg, | ||
| 398 | - // decode order == display order, so the compare below covers | ||
| 399 | - // every frame the stream carries (class gate-blind-to-hidden-frames). | ||
| 400 | - "--lag-in-frames=0", | ||
| 401 | - &depth_arg, | ||
| 402 | - &input_depth_arg, | ||
| 403 | - // Rect partitions stay ON: the frame-edge strip is a FORCED | ||
| 404 | - // (gathered) HORZ/VERT, but with rect coding off the encoder | ||
| 405 | - // answers that gathered symbol SPLIT every time and no edge | ||
| 406 | - // strip ever fires (lane-oddh r2's finding, re-measured r1). | ||
| 407 | - "--enable-rect-partitions=1", | ||
| 408 | - "--enable-ab-partitions=0", | ||
| 409 | - "--enable-1to4-partitions=0", | ||
| 410 | - "--min-partition-size=8", | ||
| 411 | - "--max-partition-size=64", | ||
| 412 | - // Other lanes' open gaps this recipe must not trip. | ||
| 413 | - "--enable-palette=0", | ||
| 414 | - "--enable-intrabc=0", | ||
| 415 | - "--enable-warped-motion=0", | ||
| 416 | - "--enable-obmc=0", | ||
| 417 | - "--enable-masked-comp=0", | ||
| 418 | - "--enable-interintra-comp=0", | ||
| 419 | - "--enable-onesided-comp=0", | ||
| 420 | - "--enable-interintra-wedge=0", | ||
| 421 | - "--enable-smooth-interintra=0", | ||
| 422 | - "--enable-ref-frame-mvs=0", | ||
| 423 | - "--enable-angle-delta=0", | ||
| 424 | - "--enable-cfl-intra=0", | ||
| 425 | - "--enable-directional-intra=0", | ||
| 426 | - "--enable-smooth-intra=0", | ||
| 427 | - "--enable-paeth-intra=0", | ||
| 428 | - "--enable-filter-intra=0", | ||
| 429 | - "--enable-tx-size-search=0", | ||
| 430 | - "--obu", | ||
| 431 | - "-o", | ||
| 432 | - "-", | ||
| 433 | - "-", | ||
| 434 | - ]), | ||
| 435 | - &y4m.stdout, | ||
| 436 | - ); | ||
| 437 | - assert!( | ||
| 438 | - out.status.success(), | ||
| 439 | - "aomenc refused: {}", | ||
| 440 | - String::from_utf8_lossy(&out.stderr) | ||
| 441 | - ); | ||
| 442 | - let stream = out.stdout; | ||
| 443 | - | ||
| 444 | - // Reset, never a delta: a refused attempt's hits must not leak into the | ||
| 445 | - // next one (class counter-from-refused-stream). | ||
| 446 | - crate::decode::reset_inter_edge_strip_hits(); | ||
| 447 | - let decoded = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 448 | - panic!("{name}: {width}x{height} {bit_depth}-bit cq {cq} did not decode: {e}") | ||
| 449 | - }); | ||
| 450 | - let hits = crate::decode::inter_edge_strip_hits(); | ||
| 451 | - let reference = if bit_depth == 10 { | ||
| 452 | - ffmpeg_decode_sequence_10bit(&stream, width, height, frames) | ||
| 453 | - } else { | ||
| 454 | - ffmpeg_decode_sequence(&stream, width, height, frames) | ||
| 455 | - }; | ||
| 456 | - assert_eq!( | ||
| 457 | - decoded.len(), | ||
| 458 | - reference.len(), | ||
| 459 | - "{name}: {width}x{height} {bit_depth}-bit cq {cq} frame count" | ||
| 460 | - ); | ||
| 461 | - assert!( | ||
| 462 | - decoded.len() >= frames, | ||
| 463 | - "{name}: {width}x{height} {bit_depth}-bit cq {cq} decoded only {} frames", | ||
| 464 | - decoded.len() | ||
| 465 | - ); | ||
| 466 | - let (mut luma_bad, mut chroma_bad) = (0usize, 0usize); | ||
| 467 | - for (ours, theirs) in decoded.iter().zip(&reference) { | ||
| 468 | - if ours.y != theirs.y { | ||
| 469 | - luma_bad += 1; | ||
| 470 | - } | ||
| 471 | - if ours.u != theirs.u || ours.v != theirs.v { | ||
| 472 | - chroma_bad += 1; | ||
| 473 | - } | ||
| 474 | - } | ||
| 475 | - (hits, luma_bad, chroma_bad) | ||
| 476 | - } | ||
| 477 | - | ||
| 478 | - /// A GOP (key frame plus panned inter frames, so blocks actually take | ||
| 479 | - /// motion) decodes bit-exact through `decode_stream` alone, threading its | ||
| 480 | - /// own DPB rather than a test-supplied reference. | ||
| 481 | - pub(super) fn gop_round_trips(width: usize, height: usize, fctx: &crate::decode::FrameCtx) { | ||
| 482 | - let pictures: Vec<_> = (0..4) | ||
| 483 | - .map(|i| panned_test_card(width, height, i * 3)) | ||
| 484 | - .collect(); | ||
| 485 | - let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); | ||
| 486 | - let decoded = decode_stream(&encoded.stream).unwrap(); | ||
| 487 | - assert_eq!(decoded.len(), encoded.frames.len()); | ||
| 488 | - for (i, (got, frame)) in decoded.iter().zip(&encoded.frames).enumerate() { | ||
| 489 | - assert_eq!( | ||
| 490 | - got.y, frame.reconstruction.y, | ||
| 491 | - "{width}x{height} frame {i} luma" | ||
| 492 | - ); | ||
| 493 | - assert_eq!( | ||
| 494 | - got.u, frame.reconstruction.u, | ||
| 495 | - "{width}x{height} frame {i} U" | ||
| 496 | - ); | ||
| 497 | - assert_eq!( | ||
| 498 | - got.v, frame.reconstruction.v, | ||
| 499 | - "{width}x{height} frame {i} V" | ||
| 500 | - ); | ||
| 501 | - } | ||
| 502 | - } | ||
| 503 | - | ||
| 504 | - /// Firing-detection gates (single-ref envelope, temporal-MV, `comp_mode`, | ||
| 505 | - /// `skip_mode`/compound) all read a process-global atomic counter delta | ||
| 506 | - /// (`decode::ref_hits`/`tmv_hits`/`comp_mode_hits`/`skip_mode_hits`) to | ||
| 507 | - /// prove a real block picked the feature under test, not just that a | ||
| 508 | - /// header bit was set. Under `cargo test`'s default parallel run, a | ||
| 509 | - /// SIBLING test's own decode bumps the same global counter mid-gate -- | ||
| 510 | - /// a false "fired" reading pixel-compares an attempt the gate would | ||
| 511 | - /// otherwise `continue` past, on top of genuine defects that path may | ||
| 512 | - /// still have. Serialising every counter-delta gate behind this one | ||
| 513 | - /// mutex makes firing detection honest again (matches the existing | ||
| 514 | - /// cdf-forwarding-gate flake shape, ledger `omp-liveness-pgrep-self-match`). | ||
| 515 | - pub(super) static GATE_COUNTER_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); | ||
| 516 | - | ||
| 517 | - /// lane-cdfflake: a cheap, dependency-free (FNV-1a, not cryptographic -- | ||
| 518 | - /// this is a load-bearing-identity fingerprint for flake triage, not a | ||
| 519 | - /// security digest, so no `sha2` dep is pulled in) fixture fingerprint | ||
| 520 | - /// for the cdf-forwarding gate's instrumentation below. | ||
| 521 | - /// Reads a pinned fixture, asserting its length and FNV first, so a | ||
| 522 | - /// swapped or truncated pin fails loudly instead of silently changing | ||
| 523 | - /// what the gate measures. | ||
| 524 | - pub(super) fn read_pin(path: &std::path::Path, len: usize, fnv: u64, name: &str) -> Vec<u8> { | ||
| 525 | - let bytes = std::fs::read(path).unwrap_or_else(|e| { | ||
| 526 | - panic!( | ||
| 527 | - "{name}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | ||
| 528 | - which is a failure, not a skip", | ||
| 529 | - path.display() | ||
| 530 | - ) | ||
| 531 | - }); | ||
| 532 | - assert_eq!(bytes.len(), len, "{name}: fixture length moved"); | ||
| 533 | - assert_eq!(fnv1a64(&bytes), fnv, "{name}: fixture bytes moved"); | ||
| 534 | - bytes | ||
| 535 | - } | ||
| 536 | - | ||
| 537 | - /// The bit depth the stream's OWN sequence header declares, read from | ||
| 538 | - /// the bytes rather than taken from the gate's name or recipe (class | ||
| 539 | - /// `helper-packs-u16-for-an-8-bit-stream`: aomdec's `--rawvideo` | ||
| 540 | - /// writes 8 bits per sample for an 8-bit stream and 16 bits LE for a | ||
| 541 | - /// high-bitdepth one, so a u16 packer turns every 8-bit compare into a | ||
| 542 | - /// raw-SIZE failure that never looks at a sample). | ||
| 543 | - pub(super) fn stream_bit_depth(stream: &[u8], name: &str) -> u8 { | ||
| 544 | - let mut probe = Av1Parser::new(); | ||
| 545 | - let mut pos = 0usize; | ||
| 546 | - while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 547 | - let obu = probe | ||
| 548 | - .parse_obu(&stream[pos..]) | ||
| 549 | - .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 550 | - pos += obu.total_size; | ||
| 551 | - } | ||
| 552 | - probe | ||
| 553 | - .sequence_header() | ||
| 554 | - .unwrap_or_else(|| panic!("{name}: the stream carries no sequence header OBU")) | ||
| 555 | - .color_config | ||
| 556 | - .bit_depth | ||
| 557 | - } | ||
| 558 | - | ||
| 559 | - /// The stream's OWN `color_config.subsampling_x/y` (spec 5.5.2), read | ||
| 560 | - /// from its bytes the same way [`stream_bit_depth`] reads the depth. | ||
| 561 | - pub(super) fn stream_subsampling(stream: &[u8], name: &str) -> (u8, u8) { | ||
| 562 | - let mut probe = Av1Parser::new(); | ||
| 563 | - let mut pos = 0usize; | ||
| 564 | - while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 565 | - let obu = probe | ||
| 566 | - .parse_obu(&stream[pos..]) | ||
| 567 | - .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 568 | - pos += obu.total_size; | ||
| 569 | - } | ||
| 570 | - let cc = &probe | ||
| 571 | - .sequence_header() | ||
| 572 | - .unwrap_or_else(|| panic!("{name}: the stream carries no sequence header OBU")) | ||
| 573 | - .color_config; | ||
| 574 | - (cc.subsampling_x, cc.subsampling_y) | ||
| 575 | - } | ||
| 576 | - | ||
| 577 | - /// The chroma shape a `(subsampling_x, subsampling_y)` pair means. | ||
| 578 | - pub(super) fn chroma_shape(sx: u8, sy: u8) -> &'static str { | ||
| 579 | - match (sx, sy) { | ||
| 580 | - (1, 1) => "4:2:0", | ||
| 581 | - (1, 0) => "4:2:2", | ||
| 582 | - (0, 0) => "4:4:4", | ||
| 583 | - (0, 1) => "4:4:0", | ||
| 584 | - _ => "an unassigned subsampling", | ||
| 585 | - } | ||
| 586 | - } | ||
| 587 | - | ||
| 588 | - /// lane-av1oracleguard: HARD REFUSAL for the 4:2:0 ffmpeg oracle helpers. | ||
| 589 | - /// | ||
| 590 | - /// `ffmpeg_decode_sequence`, `ffmpeg_decode_sequence_10bit` and | ||
| 591 | - /// `ffmpeg_decode_sequence_12bit` ask ffmpeg for `-pix_fmt yuv420p*` and | ||
| 592 | - /// size chroma at `width * height / 4`. Those are the 4:2:0 numbers, so | ||
| 593 | - /// for a stream that is NOT (1,1) ffmpeg does not fail -- it CONVERTS, | ||
| 594 | - /// and the helper then slices a 4:2:0-shaped picture out of it. A 4:2:2 | ||
| 595 | - /// gate built on one of them compares the wrong planes and passes green: | ||
| 596 | - /// the exact failure `lanes/av1subsizesweep.report.md` names. The correct | ||
| 597 | - /// siblings (`ffmpeg_decode_sequence_422` / `_422_depth` / | ||
| 598 | - /// `ffmpeg_decode_sequence_444`) exist and take the same bytes, so the | ||
| 599 | - /// refusal points at them by name rather than leaving the caller to | ||
| 600 | - /// rediscover the shape. | ||
| 601 | - /// | ||
| 602 | - /// Refused by SUBSAMPLING read from the stream's own sequence header, not | ||
| 603 | - /// from the caller's `width`/`height` (class | ||
| 604 | - /// `helper-assumes-the-shape-the-gate-name-implies`). | ||
| 605 | - pub(super) fn assert_420_oracle_stream(stream: &[u8], helper: &str, sibling: &str) { | ||
| 606 | - let (sx, sy) = stream_subsampling(stream, helper); | ||
| 607 | - assert!( | ||
| 608 | - (sx, sy) == (1, 1), | ||
| 609 | - "{helper} REFUSED a ({sx},{sy}) stream: this helper asks ffmpeg for a 4:2:0 \ | ||
| 610 | - pix_fmt, which CONVERTS the stream's real {} chroma down to 4:2:0 instead of \ | ||
| 611 | - failing, then sizes chroma at `width * height / 4` rather than the {} shape. A \ | ||
| 612 | - gate built on it would compare converted planes against real ones and pass green. \ | ||
| 613 | - Use `{sibling}` for a ({sx},{sy}) stream.", | ||
| 614 | - chroma_shape(sx, sy), | ||
| 615 | - chroma_shape(sx, sy), | ||
| 616 | - ); | ||
| 617 | - } | ||
| 618 | - | ||
| 619 | - /// lane-av1oracleguard: run `f`, return the panic MESSAGE it raised (or | ||
| 620 | - /// `None` if it did not panic). The panic hook is silenced so a refusal | ||
| 621 | - /// that PASSES its gate prints nothing -- the assertion is the return. | ||
| 622 | - pub(super) fn panic_message<F: FnOnce()>(f: F) -> Option<String> { | ||
| 623 | - let hook = std::panic::take_hook(); | ||
| 624 | - std::panic::set_hook(Box::new(|_| {})); | ||
| 625 | - let caught = std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)); | ||
| 626 | - std::panic::set_hook(hook); | ||
| 627 | - match caught { | ||
| 628 | - Ok(()) => None, | ||
| 629 | - Err(payload) => Some( | ||
| 630 | - payload | ||
| 631 | - .downcast_ref::<String>() | ||
| 632 | - .cloned() | ||
| 633 | - .or_else(|| payload.downcast_ref::<&str>().map(|s| (*s).to_string())) | ||
| 634 | - .unwrap_or_else(|| "<non-string panic payload>".to_string()), | ||
| 635 | - ), | ||
| 636 | - } | ||
| 637 | - } | ||
| 638 | - | ||
| 639 | - /// Packs decoded planes the way `aomdec --rawvideo` writes them for | ||
| 640 | - /// `bit_depth`: 1 byte per sample at 8-bit, 2 bytes little-endian at | ||
| 641 | - /// 10/12-bit. Plane order is Y, U, V at the frame's own subsampled | ||
| 642 | - /// shape, which is exactly what rawvideo emits. | ||
| 643 | - pub(super) fn pack_rawvideo(decoded: &[Pic], bit_depth: u8, name: &str) -> Vec<u8> { | ||
| 644 | - let mut ours: Vec<u8> = Vec::new(); | ||
| 645 | - for (fi, f) in decoded.iter().enumerate() { | ||
| 646 | - for p in [&f.y, &f.u, &f.v] { | ||
| 647 | - if bit_depth == 8 { | ||
| 648 | - for &s in p { | ||
| 649 | - assert!( | ||
| 650 | - s <= 0xff, | ||
| 651 | - "{name}: decode-order frame {fi} carries the sample {s}, which an \ | ||
| 652 | - 8-bit stream cannot hold -- the stream is not the one this gate thinks \ | ||
| 653 | - it is" | ||
| 654 | - ); | ||
| 655 | - ours.push(s as u8); | ||
| 656 | - } | ||
| 657 | - } else { | ||
| 658 | - for &s in p { | ||
| 659 | - ours.extend_from_slice(&s.to_le_bytes()); | ||
| 660 | - } | ||
| 661 | - } | ||
| 662 | - } | ||
| 663 | - } | ||
| 664 | - ours | ||
| 665 | - } | ||
| 666 | - | ||
| 667 | - /// Decodes `stream` and the oracle's `aomdec --rawvideo` output and | ||
| 668 | - /// requires every sample of every frame to agree, in decode order. | ||
| 669 | - /// | ||
| 670 | - /// `bit_depth` is the depth the CALLER believes the stream has; it is | ||
| 671 | - /// asserted against the stream's own sequence header, so a gate that | ||
| 672 | - /// hands this an 8-bit stream under a 10-bit label fails here by name | ||
| 673 | - /// instead of dying on a raw-size mismatch that reads like a pixel bug. | ||
| 674 | - pub(super) fn assert_rawvideo_matches( | ||
| 675 | - obu: &std::path::Path, | ||
| 676 | - stream: &[u8], | ||
| 677 | - name: &str, | ||
| 678 | - frames: usize, | ||
| 679 | - bit_depth: u8, | ||
| 680 | - ) { | ||
| 681 | - let actual_depth = stream_bit_depth(stream, name); | ||
| 682 | - assert_eq!( | ||
| 683 | - actual_depth, bit_depth, | ||
| 684 | - "{name}: the stream's sequence header says {actual_depth}-bit, the gate passed \ | ||
| 685 | - {bit_depth}-bit -- aomdec's --rawvideo writes {actual_depth} bits per sample for it, \ | ||
| 686 | - so packing for {bit_depth} compares nothing" | ||
| 687 | - ); | ||
| 688 | - let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id())); | ||
| 689 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 690 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 691 | - let raw = dir.join("aomdec.raw"); | ||
| 692 | - let out = crate::tool_cache::cached_output_io(Command::new(aomdec_path()) | ||
| 693 | - .args(["--codec=av1", "--rawvideo", "-o"]) | ||
| 694 | - .arg(&raw) | ||
| 695 | - .arg(obu) | ||
| 696 | - .stdin(Stdio::null()) | ||
| 697 | - .stdout(Stdio::piped()) | ||
| 698 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 699 | - .expect("aomdec failed to run"); | ||
| 700 | - assert!( | ||
| 701 | - out.status.success(), | ||
| 702 | - "{name}: the oracle aomdec refused the stream: {}", | ||
| 703 | - String::from_utf8_lossy(&out.stderr) | ||
| 704 | - ); | ||
| 705 | - let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | ||
| 706 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 707 | - let decoded = decode_stream(stream).expect("decode for comparison"); | ||
| 708 | - let ours = pack_rawvideo(&decoded, bit_depth, name); | ||
| 709 | - assert_eq!( | ||
| 710 | - ours.len(), | ||
| 711 | - ref_raw.len(), | ||
| 712 | - "{name}: {bit_depth}-bit raw sizes differ -- ours packs {} bytes ({} samples at \ | ||
| 713 | - {} bit/sample), aomdec wrote {}", | ||
| 714 | - ours.len(), | ||
| 715 | - decoded | ||
| 716 | - .iter() | ||
| 717 | - .map(|f| f.y.len() + f.u.len() + f.v.len()) | ||
| 718 | - .sum::<usize>(), | ||
| 719 | - bit_depth, | ||
| 720 | - ref_raw.len() | ||
| 721 | - ); | ||
| 722 | - assert_eq!(decoded.len(), frames, "{name}: frame count"); | ||
| 723 | - let first = ours | ||
| 724 | - .iter() | ||
| 725 | - .zip(&ref_raw) | ||
| 726 | - .position(|(a, b)| a != b) | ||
| 727 | - .unwrap_or(ours.len()); | ||
| 728 | - assert_eq!( | ||
| 729 | - first, | ||
| 730 | - ours.len(), | ||
| 731 | - "{name}: {} bytes of decoded output differ from aomdec (first at {})", | ||
| 732 | - ours.iter().zip(&ref_raw).filter(|(a, b)| a != b).count(), | ||
| 733 | - first | ||
| 734 | - ); | ||
| 735 | - } | ||
| 736 | - | ||
| 737 | - pub(super) fn fnv1a64(bytes: &[u8]) -> u64 { | ||
| 738 | - let mut hash = 0xcbf29ce484222325u64; | ||
| 739 | - for &b in bytes { | ||
| 740 | - hash ^= b as u64; | ||
| 741 | - hash = hash.wrapping_mul(0x100000001b3); | ||
| 742 | - } | ||
| 743 | - hash | ||
| 744 | - } | ||
| 745 | - | ||
| 746 | - /// Whether ffmpeg is on PATH. Absence normally SKIPs, but | ||
| 747 | - /// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every | ||
| 748 | - /// aomenc gate decodes its stream through ffmpeg and is meaningless | ||
| 749 | - /// without it -- turns it into a hard failure. Without this the require | ||
| 750 | - /// flag was silently short-circuited: `!have_ffmpeg()` is evaluated first | ||
| 751 | - /// in `if !have_ffmpeg() || !have_aomenc()`, so a machine with no ffmpeg | ||
| 752 | - /// printed SKIP and reported green (class gate-skips-on-its-own-failure). | ||
| 753 | - pub(super) fn have_ffmpeg() -> bool { | ||
| 754 | - let present = Command::new("ffmpeg") | ||
| 755 | - .arg("-version") | ||
| 756 | - .stdout(Stdio::null()) | ||
| 757 | - .stderr(Stdio::null()) | ||
| 758 | - .status() | ||
| 759 | - .is_ok_and(|s| s.success()); | ||
| 760 | - assert!( | ||
| 761 | - present | ||
| 762 | - || (std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_none() | ||
| 763 | - && std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none()), | ||
| 764 | - "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH" | ||
| 765 | - ); | ||
| 766 | - present | ||
| 767 | - } | ||
| 768 | - | ||
| 769 | - /// Decodes `frames` concatenated 4:2:0 frames out of one AV1 OBU stream. | ||
| 770 | - /// The frame-count diagnostic shared by the three `ffmpeg_decode_sequence*` | ||
| 771 | - /// helpers (lane-av1pins5 r6). | ||
| 772 | - /// | ||
| 773 | - /// Before this, a caller that passed its OWN decode's length as the expected | ||
| 774 | - /// count got `expected N 4:2:0 frames, ffmpeg said: ` -- with an EMPTY tail, | ||
| 775 | - /// because ffmpeg ran at `-v error` and succeeded. The message named ffmpeg, | ||
| 776 | - /// said nothing about where `N` came from, and sent the next reader hunting | ||
| 777 | - /// ffmpeg for a count ffmpeg never chose. | ||
| 778 | - /// | ||
| 779 | - /// The class is MISATTRIBUTED RED, not silent pass: the helper's | ||
| 780 | - /// `out.stdout.len() == frame_bytes * frames` assert fires unconditionally, so | ||
| 781 | - /// a wrong count cannot pass -- it just fails while blaming the wrong | ||
| 782 | - /// component. (Measured: `ffmpeg_decode_sequence(&s, 192, 128, 0)` panics | ||
| 783 | - /// here, not silently.) Naming the real cause is the whole fix; no caller has | ||
| 784 | - /// to change to benefit. | ||
| 785 | - pub(super) fn frame_count_diagnosis( | ||
| 786 | - format: &str, | ||
| 787 | - frames: usize, | ||
| 788 | - width: usize, | ||
| 789 | - height: usize, | ||
| 790 | - frame_bytes: usize, | ||
| 791 | - got: usize, | ||
| 792 | - stderr: &[u8], | ||
| 793 | - ) -> String { | ||
| 794 | - let actual = got.checked_div(frame_bytes).unwrap_or(0); | ||
| 795 | - let leftover = if frame_bytes == 0 { | ||
| 796 | - got | ||
| 797 | - } else { | ||
| 798 | - got % frame_bytes | ||
| 799 | - }; | ||
| 800 | - format!( | ||
| 801 | - "FRAME COUNT MISMATCH ({format} {width}x{height}): the caller passed \ | ||
| 802 | - `frames={frames}`, ffmpeg produced {actual} frame(s) ({got} bytes, \ | ||
| 803 | - {leftover} byte(s) not a whole frame, at {frame_bytes} B/frame).\n\ | ||
| 804 | - `frames` is the EXPECTED count the CALLER asserted -- it is NOT measured \ | ||
| 805 | - from ffmpeg, so it never had ffmpeg's agreement. If it came from our own \ | ||
| 806 | - decode_stream(), this is OUR decoder disagreeing with ffmpeg about how many \ | ||
| 807 | - frames the stream holds, and the fix is on OUR side, not ffmpeg's. ffmpeg \ | ||
| 808 | - itself exited cleanly{}.", | ||
| 809 | - if stderr.is_empty() { | ||
| 810 | - " with no diagnostics (`-v error`)" | ||
| 811 | - } else { | ||
| 812 | - "" | ||
| 813 | - } | ||
| 814 | - ) | ||
| 815 | - } | ||
| 816 | - | ||
| 817 | - pub(super) fn ffmpeg_decode_sequence( | ||
| 818 | - stream: &[u8], | ||
| 819 | - width: usize, | ||
| 820 | - height: usize, | ||
| 821 | - frames: usize, | ||
| 822 | - ) -> Vec<Pic> { | ||
| 823 | - // lane-av1oracleguard: this helper's numbers are 4:2:0's. A (1,0) or | ||
| 824 | - // (0,0) stream would be CONVERTED by ffmpeg rather than refused. | ||
| 825 | - assert_420_oracle_stream( | ||
| 826 | - stream, | ||
| 827 | - "ffmpeg_decode_sequence", | ||
| 828 | - "ffmpeg_decode_sequence_422 (4:2:2) or ffmpeg_decode_sequence_444 (4:4:4)", | ||
| 829 | - ); | ||
| 830 | - let out = run_with_stdin( | ||
| 831 | - Command::new(ffmpeg_path()).args([ | ||
| 832 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | ||
| 833 | - ]), | ||
| 834 | - stream, | ||
| 835 | - ); | ||
| 836 | - assert!( | ||
| 837 | - out.status.success(), | ||
| 838 | - "ffmpeg refused the stream: {}", | ||
| 839 | - String::from_utf8_lossy(&out.stderr) | ||
| 840 | - ); | ||
| 841 | - let (luma, chroma) = (width * height, width * height / 4); | ||
| 842 | - let frame_bytes = luma + 2 * chroma; | ||
| 843 | - assert_eq!( | ||
| 844 | - out.stdout.len(), | ||
| 845 | - frame_bytes * frames, | ||
| 846 | - "{}", | ||
| 847 | - frame_count_diagnosis( | ||
| 848 | - "4:2:0", | ||
| 849 | - frames, | ||
| 850 | - width, | ||
| 851 | - height, | ||
| 852 | - frame_bytes, | ||
| 853 | - out.stdout.len(), | ||
| 854 | - &out.stderr | ||
| 855 | - ) | ||
| 856 | - ); | ||
| 857 | - (0..frames) | ||
| 858 | - .map(|i| { | ||
| 859 | - let base = i * frame_bytes; | ||
| 860 | - Pic { | ||
| 861 | - width, | ||
| 862 | - height, | ||
| 863 | - y: out.stdout[base..base + luma] | ||
| 864 | - .iter() | ||
| 865 | - .map(|&v| u16::from(v)) | ||
| 866 | - .collect(), | ||
| 867 | - u: out.stdout[base + luma..base + luma + chroma] | ||
| 868 | - .iter() | ||
| 869 | - .map(|&v| u16::from(v)) | ||
| 870 | - .collect(), | ||
| 871 | - v: out.stdout[base + luma + chroma..base + frame_bytes] | ||
| 872 | - .iter() | ||
| 873 | - .map(|&v| u16::from(v)) | ||
| 874 | - .collect(), | ||
| 875 | - } | ||
| 876 | - }) | ||
| 877 | - .collect() | ||
| 878 | - } | ||
| 879 | - | ||
| 880 | - /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma | ||
| 881 | - /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes | ||
| 882 | - /// (lane-av1mono). Fed through [`run_with_stdin`] for the reason its doc | ||
| 883 | - /// records. | ||
| 884 | - pub(super) fn ffmpeg_decode_gray_sequence( | ||
| 885 | - stream: &[u8], | ||
| 886 | - width: usize, | ||
| 887 | - height: usize, | ||
| 888 | - frames: usize, | ||
| 889 | - ) -> Vec<u8> { | ||
| 890 | - let out = run_with_stdin( | ||
| 891 | - Command::new(ffmpeg_path()).args([ | ||
| 892 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", | ||
| 893 | - ]), | ||
| 894 | - stream, | ||
| 895 | - ); | ||
| 896 | - assert!( | ||
| 897 | - out.status.success(), | ||
| 898 | - "ffmpeg refused the monochrome stream: {}", | ||
| 899 | - String::from_utf8_lossy(&out.stderr) | ||
| 900 | - ); | ||
| 901 | - assert_eq!( | ||
| 902 | - out.stdout.len(), | ||
| 903 | - width * height * frames, | ||
| 904 | - "expected {frames} monochrome frames, ffmpeg said: {}", | ||
| 905 | - String::from_utf8_lossy(&out.stderr) | ||
| 906 | - ); | ||
| 907 | - out.stdout | ||
| 908 | - } | ||
| 909 | - | ||
| 910 | - /// As [`ffmpeg_decode_sequence`], but for a `yuv420p10le` stream: samples | ||
| 911 | - /// are 2-byte little-endian, one full 16-bit range regardless of the | ||
| 912 | - /// stream's real 10-bit depth (ffmpeg's rawvideo muxer never packs to the | ||
| 913 | - /// bit depth). The 8-bit helper above stays untouched -- every existing | ||
| 914 | - /// gate depends on it. | ||
| 915 | - /// | ||
| 916 | - /// lane-av1oracledepth: the stream's OWN sequence header must parse | ||
| 917 | - /// 10-bit, the same way `assert_12bit_sequence_header` covers the 12-bit | ||
| 918 | - /// gates. A wrong-depth stream handed here would otherwise CONVERT | ||
| 919 | - /// silently -- ffmpeg re-scales 8-bit samples into the 16-bit container | ||
| 920 | - /// and sizes no plane differently -- so a gate could compare ffmpeg's | ||
| 921 | - /// rescaled 8-bit planes against our 10-bit decode and read exact (class | ||
| 922 | - /// `helper-assumes-the-shape-the-gate-name-implies`, the depth axis). | ||
| 923 | - pub(super) fn ffmpeg_decode_sequence_10bit( | ||
| 924 | - stream: &[u8], | ||
| 925 | - width: usize, | ||
| 926 | - height: usize, | ||
| 927 | - frames: usize, | ||
| 928 | - ) -> Vec<Pic> { | ||
| 929 | - assert_420_oracle_stream( | ||
| 930 | - stream, | ||
| 931 | - "ffmpeg_decode_sequence_10bit", | ||
| 932 | - "ffmpeg_decode_sequence_422_depth(.., 10, \"yuv422p10le\") (4:2:2); \ | ||
| 933 | - ffmpeg_decode_sequence_444_depth(.., 10, \"yuv444p10le\") (4:4:4)", | ||
| 934 | - ); | ||
| 935 | - assert_eq!( | ||
| 936 | - stream_bit_depth(stream, "ffmpeg_decode_sequence_10bit"), | ||
| 937 | - 10, | ||
| 938 | - "ffmpeg_decode_sequence_10bit REFUSED a stream whose own sequence header is not \ | ||
| 939 | - 10-bit -- ffmpeg converts it to yuv420p10le instead of failing, and the comparison \ | ||
| 940 | - would read a converted reference" | ||
| 941 | - ); | ||
| 942 | - let out = run_with_stdin( | ||
| 943 | - Command::new(ffmpeg_path()).args([ | ||
| 944 | - "-v", | ||
| 945 | - "error", | ||
| 946 | - "-f", | ||
| 947 | - "obu", | ||
| 948 | - "-i", | ||
| 949 | - "-", | ||
| 950 | - "-f", | ||
| 951 | - "rawvideo", | ||
| 952 | - "-pix_fmt", | ||
| 953 | - "yuv420p10le", | ||
| 954 | - "-", | ||
| 955 | - ]), | ||
| 956 | - stream, | ||
| 957 | - ); | ||
| 958 | - assert!( | ||
| 959 | - out.status.success(), | ||
| 960 | - "ffmpeg refused the stream: {}", | ||
| 961 | - String::from_utf8_lossy(&out.stderr) | ||
| 962 | - ); | ||
| 963 | - let (luma, chroma) = (width * height, width * height / 4); | ||
| 964 | - let frame_samples = luma + 2 * chroma; | ||
| 965 | - let frame_bytes = frame_samples * 2; | ||
| 966 | - assert_eq!( | ||
| 967 | - out.stdout.len(), | ||
| 968 | - frame_bytes * frames, | ||
| 969 | - "{}", | ||
| 970 | - frame_count_diagnosis( | ||
| 971 | - "4:2:0 10-bit", | ||
| 972 | - frames, | ||
| 973 | - width, | ||
| 974 | - height, | ||
| 975 | - frame_bytes, | ||
| 976 | - out.stdout.len(), | ||
| 977 | - &out.stderr | ||
| 978 | - ) | ||
| 979 | - ); | ||
| 980 | - fn le16(bytes: &[u8]) -> Vec<u16> { | ||
| 981 | - bytes | ||
| 982 | - .as_chunks::<2>().0.iter() | ||
| 983 | - .map(|c| u16::from_le_bytes([c[0], c[1]])) | ||
| 984 | - .collect() | ||
| 985 | - } | ||
| 986 | - (0..frames) | ||
| 987 | - .map(|i| { | ||
| 988 | - let base = i * frame_bytes; | ||
| 989 | - Pic { | ||
| 990 | - width, | ||
| 991 | - height, | ||
| 992 | - y: le16(&out.stdout[base..base + luma * 2]), | ||
| 993 | - u: le16(&out.stdout[base + luma * 2..base + luma * 2 + chroma * 2]), | ||
| 994 | - v: le16(&out.stdout[base + luma * 2 + chroma * 2..base + frame_bytes]), | ||
| 995 | - } | ||
| 996 | - }) | ||
| 997 | - .collect() | ||
| 998 | - } | ||
| 999 | - | ||
| 1000 | - /// Builds a `gradients` lavfi source string with colours derived from | ||
| 1001 | - /// `seed`, not left to the filter's own default. | ||
| 1002 | - /// | ||
| 1003 | - /// Measured (lane-fixdet r1): ffmpeg's `gradients` source IGNORES its | ||
| 1004 | - /// `seed=` parameter for colour selection -- five encodes of an | ||
| 1005 | - /// identical command line (same `seed=`, same everything) produced five | ||
| 1006 | - /// different fixtures, because the unset `c0..c9` stops are randomized | ||
| 1007 | - /// from something other than that seed. Every one of this file's ~20 | ||
| 1008 | - /// gate fixtures built a `gradients` source this way, so none of them | ||
| 1009 | - /// had a reproducible input: a pin captured from one run could not be | ||
| 1010 | - /// regenerated, and "attempt N failed" was as likely to be a different | ||
| 1011 | - /// fixture as a different decode outcome. | ||
| 1012 | - /// | ||
| 1013 | - /// Freezing the colours outright (as the earliest four gates below do, | ||
| 1014 | - /// hand-picking `c0=red:c1=blue:c2=green`) fixes reproducibility but | ||
| 1015 | - /// throws away the per-attempt content variety the sweep gates need to | ||
| 1016 | - /// make features (OBMC, warp, wedge, ...) fire at all -- this repo's own | ||
| 1017 | - /// `sampler-decorrelated-gate` class. So: derive `c0..c3` deterministically | ||
| 1018 | - /// FROM the seed with a plain integer hash, and keep passing `seed=` | ||
| 1019 | - /// itself too, so a future ffmpeg that actually honours it only adds | ||
| 1020 | - /// more variety, never removes the determinism this buys. | ||
| 1021 | - pub(super) fn gradients_source(seed: u32, width: usize, height: usize, tail: &str) -> String { | ||
| 1022 | - fn hash_color(seed: u32, salt: u32) -> String { | ||
| 1023 | - let h = seed | ||
| 1024 | - .wrapping_mul(2_654_435_761) | ||
| 1025 | - .wrapping_add(salt.wrapping_mul(0x9E37_79B9)) | ||
| 1026 | - ^ (seed.rotate_left(13)); | ||
| 1027 | - format!("0x{:06x}", h & 0x00ff_ffff) | ||
| 1028 | - } | ||
| 1029 | - let (c0, c1, c2, c3) = ( | ||
| 1030 | - hash_color(seed, 0), | ||
| 1031 | - hash_color(seed, 1), | ||
| 1032 | - hash_color(seed, 2), | ||
| 1033 | - hash_color(seed, 3), | ||
| 1034 | - ); | ||
| 1035 | - format!( | ||
| 1036 | - "gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}" | ||
| 1037 | - ) | ||
| 1038 | - } | ||
| 1039 | - | ||
| 1040 | - /// Encodes a real libaom-av1 stream (via ffmpeg's own encoder, not this | ||
| 1041 | - /// crate's) with the same reduced-partition flags lane-av1adst's r6 | ||
| 1042 | - /// probe found still select `ADST_ADST`/`ADST_DCT`/`DCT_ADST` on | ||
| 1043 | - /// gradient content (TX_SET_INTRA_2), and decodes it with | ||
| 1044 | - /// [`decode_stream`] -- lifting the round-2 refusal is only real if it | ||
| 1045 | - /// gets past an encoder this crate never wrote a byte of. | ||
| 1046 | - pub(super) fn libaom_encode(lavfi: &str, width: usize, height: usize, crf: u32) -> Option<Vec<u8>> { | ||
| 1047 | - libaom_encode_with(lavfi, width, height, crf, &[]) | ||
| 1048 | - } | ||
| 1049 | - | ||
| 1050 | - /// As [`libaom_encode`], with extra encoder args appended -- used to pin | ||
| 1051 | - /// a deterministic stream (`-threads 1` etc., since libaom's `cpu-used 8` | ||
| 1052 | - /// RD search is not otherwise stable run-to-run on this box, and lavfi | ||
| 1053 | - /// `gradients` needs its own `seed=` for the same reason) and to gate | ||
| 1054 | - /// individual feature flags (`-enable-cdef 0`) a given fixture needs off. | ||
| 1055 | - pub(super) fn libaom_encode_with( | ||
| 1056 | - lavfi: &str, | ||
| 1057 | - width: usize, | ||
| 1058 | - height: usize, | ||
| 1059 | - crf: u32, | ||
| 1060 | - extra: &[&str], | ||
| 1061 | - ) -> Option<Vec<u8>> { | ||
| 1062 | - let mut args = vec![ | ||
| 1063 | - "-v", | ||
| 1064 | - "error", | ||
| 1065 | - "-f", | ||
| 1066 | - "lavfi", | ||
| 1067 | - "-i", | ||
| 1068 | - lavfi, | ||
| 1069 | - "-frames:v", | ||
| 1070 | - "1", | ||
| 1071 | - "-pix_fmt", | ||
| 1072 | - "yuv420p", | ||
| 1073 | - "-c:v", | ||
| 1074 | - "libaom-av1", | ||
| 1075 | - ]; | ||
| 1076 | - let crf_str = crf.to_string(); | ||
| 1077 | - args.extend(["-crf", &crf_str]); | ||
| 1078 | - args.extend([ | ||
| 1079 | - "-cpu-used", | ||
| 1080 | - "8", | ||
| 1081 | - "-enable-rect-partitions", | ||
| 1082 | - "0", | ||
| 1083 | - "-enable-ab-partitions", | ||
| 1084 | - "0", | ||
| 1085 | - "-enable-1to4-partitions", | ||
| 1086 | - "0", | ||
| 1087 | - "-enable-angle-delta", | ||
| 1088 | - "0", | ||
| 1089 | - "-enable-cfl-intra", | ||
| 1090 | - "0", | ||
| 1091 | - ]); | ||
| 1092 | - args.extend(extra.iter().copied()); | ||
| 1093 | - args.extend(["-f", "obu", "-"]); | ||
| 1094 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1095 | - .args(&args) | ||
| 1096 | - .stdin(Stdio::null()) | ||
| 1097 | - .stdout(Stdio::piped()) | ||
| 1098 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1099 | - .expect("ffmpeg failed to run"); | ||
| 1100 | - if !out.status.success() { | ||
| 1101 | - eprintln!( | ||
| 1102 | - "ffmpeg refused to encode {lavfi} at {width}x{height}: {}", | ||
| 1103 | - String::from_utf8_lossy(&out.stderr) | ||
| 1104 | - ); | ||
| 1105 | - return None; | ||
| 1106 | - } | ||
| 1107 | - Some(out.stdout) | ||
| 1108 | - } | ||
| 1109 | - | ||
| 1110 | - /// As [`ffmpeg_decode_sequence`], for a 4:4:4 stream: chroma planes are | ||
| 1111 | - /// FULL resolution (`yuv444p` rawvideo), the shape lane-av1-llinter's | ||
| 1112 | - /// lossless profile-1 fixture codes. | ||
| 1113 | - pub(super) fn ffmpeg_decode_sequence_444( | ||
| 1114 | - stream: &[u8], | ||
| 1115 | - width: usize, | ||
| 1116 | - height: usize, | ||
| 1117 | - frames: usize, | ||
| 1118 | - ) -> Vec<Pic> { | ||
| 1119 | - ffmpeg_decode_sequence_444_depth(stream, width, height, frames, 8, "yuv444p") | ||
| 1120 | - } | ||
| 1121 | - | ||
| 1122 | - /// lane-av1oracledepth: the depth-generic 4:4:4 oracle comparator -- the | ||
| 1123 | - /// [`ffmpeg_decode_sequence_422_depth`] twin for full-resolution chroma. | ||
| 1124 | - /// `yuv444p`, `yuv444p10le` or `yuv444p12le`, with the container width | ||
| 1125 | - /// taken from `depth` itself (8 -> one byte per sample; 10/12 -> a 16-bit | ||
| 1126 | - /// LE container on BOTH sides, so ours and ffmpeg's are directly | ||
| 1127 | - /// comparable sample for sample and nothing narrows). Until this helper | ||
| 1128 | - /// existed a 10/12-bit 4:4:4 gate had to fall back to the 8-bit | ||
| 1129 | - /// `ffmpeg_decode_sequence_444`, which ffmpeg converts at `yuv444p` | ||
| 1130 | - /// instead of refusing, or to a raw hand-rolled spawn (class | ||
| 1131 | - /// `helper-assumes-the-shape-the-gate-name-implies`, the depth axis). | ||
| 1132 | - /// | ||
| 1133 | - /// Refused by SHAPE read from the stream's own sequence header, like its | ||
| 1134 | - /// 4:2:0 siblings: `(0,0)` only, so a 4:2:2 or 4:2:0 stream handed here | ||
| 1135 | - /// cannot have ffmpeg silently convert it. | ||
| 1136 | - pub(super) fn ffmpeg_decode_sequence_444_depth( | ||
| 1137 | - stream: &[u8], | ||
| 1138 | - width: usize, | ||
| 1139 | - height: usize, | ||
| 1140 | - frames: usize, | ||
| 1141 | - depth: u8, | ||
| 1142 | - pix_fmt: &str, | ||
| 1143 | - ) -> Vec<Pic> { | ||
| 1144 | - assert!( | ||
| 1145 | - matches!(depth, 8 | 10 | 12), | ||
| 1146 | - "lane-av1oracledepth: ffmpeg_decode_sequence_444_depth takes 8, 10 or 12, got {depth}" | ||
| 1147 | - ); | ||
| 1148 | - let (sx, sy) = stream_subsampling(stream, "ffmpeg_decode_sequence_444_depth"); | ||
| 1149 | - assert!( | ||
| 1150 | - (sx, sy) == (0, 0), | ||
| 1151 | - "ffmpeg_decode_sequence_444_depth REFUSED a ({sx},{sy}) stream: this helper asks \ | ||
| 1152 | - ffmpeg for a 4:4:4 pix_fmt, which CONVERTS the stream's real {} chroma instead of \ | ||
| 1153 | - failing, then slices full-resolution planes from converted bytes. \ | ||
| 1154 | - ffmpeg_decode_sequence_422_depth handles (1,0); ffmpeg_decode_sequence handles \ | ||
| 1155 | - (1,1).", | ||
| 1156 | - chroma_shape(sx, sy) | ||
| 1157 | - ); | ||
| 1158 | - assert_eq!( | ||
| 1159 | - stream_bit_depth(stream, "ffmpeg_decode_sequence_444_depth"), | ||
| 1160 | - depth, | ||
| 1161 | - "ffmpeg_decode_sequence_444_depth REFUSED a stream whose own sequence header is \ | ||
| 1162 | - not {depth}-bit -- ffmpeg would convert it to {pix_fmt} instead of failing" | ||
| 1163 | - ); | ||
| 1164 | - let out = run_with_stdin( | ||
| 1165 | - Command::new(ffmpeg_path()).args([ | ||
| 1166 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", pix_fmt, "-", | ||
| 1167 | - ]), | ||
| 1168 | - stream, | ||
| 1169 | - ); | ||
| 1170 | - assert!( | ||
| 1171 | - out.status.success(), | ||
| 1172 | - "ffmpeg refused the 4:4:4 stream ({pix_fmt}): {}", | ||
| 1173 | - String::from_utf8_lossy(&out.stderr) | ||
| 1174 | - ); | ||
| 1175 | - let plane = width * height; | ||
| 1176 | - let bps = if depth == 8 { 1 } else { 2 }; | ||
| 1177 | - let frame_bytes = 3 * plane * bps; | ||
| 1178 | - assert_eq!( | ||
| 1179 | - out.stdout.len(), | ||
| 1180 | - frame_bytes * frames, | ||
| 1181 | - "{}", | ||
| 1182 | - frame_count_diagnosis( | ||
| 1183 | - if depth == 8 { | ||
| 1184 | - "4:4:4" | ||
| 1185 | - } else { | ||
| 1186 | - "4:4:4 high depth" | ||
| 1187 | - }, | ||
| 1188 | - frames, | ||
| 1189 | - width, | ||
| 1190 | - height, | ||
| 1191 | - frame_bytes, | ||
| 1192 | - out.stdout.len(), | ||
| 1193 | - &out.stderr | ||
| 1194 | - ) | ||
| 1195 | - ); | ||
| 1196 | - (0..frames) | ||
| 1197 | - .map(|i| { | ||
| 1198 | - let base = i * frame_bytes; | ||
| 1199 | - let samples = |off: usize| -> Vec<u16> { | ||
| 1200 | - let slice = &out.stdout[base + off..base + off + plane * bps]; | ||
| 1201 | - if bps == 1 { | ||
| 1202 | - slice.iter().map(|&v| u16::from(v)).collect() | ||
| 1203 | - } else { | ||
| 1204 | - slice | ||
| 1205 | - .as_chunks::<2>().0.iter() | ||
| 1206 | - .map(|c| u16::from_le_bytes([c[0], c[1]])) | ||
| 1207 | - .collect() | ||
| 1208 | - } | ||
| 1209 | - }; | ||
| 1210 | - Pic { | ||
| 1211 | - width, | ||
| 1212 | - height, | ||
| 1213 | - y: samples(0), | ||
| 1214 | - u: samples(plane * bps), | ||
| 1215 | - v: samples(2 * plane * bps), | ||
| 1216 | - } | ||
| 1217 | - }) | ||
| 1218 | - .collect() | ||
| 1219 | - } | ||
| 1220 | - | ||
| 1221 | - /// lane-av1422lift: as [`ffmpeg_decode_sequence`] (4:2:0 8-bit) and | ||
| 1222 | - /// [`ffmpeg_decode_sequence_444`], for a 4:2:2 stream: `yuv422p` | ||
| 1223 | - /// rawvideo, whose chroma planes are HALF WIDTH and FULL HEIGHT -- the | ||
| 1224 | - /// `w/2 * h` shape the whole per-axis port exists to produce. A helper | ||
| 1225 | - /// that computed the chroma span 4:2:0-style would make every 4:2:2 | ||
| 1226 | - /// gate compare half the oracle's bytes and pass, so the span is | ||
| 1227 | - /// asserted against the byte count below, not assumed. | ||
| 1228 | - pub(super) fn ffmpeg_decode_sequence_422( | ||
| 1229 | - stream: &[u8], | ||
| 1230 | - width: usize, | ||
| 1231 | - height: usize, | ||
| 1232 | - frames: usize, | ||
| 1233 | - ) -> Vec<Pic> { | ||
| 1234 | - ffmpeg_decode_sequence_422_depth(stream, width, height, frames, 8, "yuv422p") | ||
| 1235 | - } | ||
| 1236 | - | ||
| 1237 | - /// lane-av1422lift: the depth-generic 4:2:2 oracle comparator -- | ||
| 1238 | - /// `yuv422p`, `yuv422p10le` or `yuv422p12le`, with the container width | ||
| 1239 | - /// taken from `depth` itself (8 -> one byte per sample; 10/12 -> a | ||
| 1240 | - /// 16-bit LE container on BOTH sides, so ours and ffmpeg's are directly | ||
| 1241 | - /// comparable sample for sample and nothing narrows). | ||
| 1242 | - pub(super) fn ffmpeg_decode_sequence_422_depth( | ||
| 1243 | - stream: &[u8], | ||
| 1244 | - width: usize, | ||
| 1245 | - height: usize, | ||
| 1246 | - frames: usize, | ||
| 1247 | - depth: u8, | ||
| 1248 | - pix_fmt: &str, | ||
| 1249 | - ) -> Vec<Pic> { | ||
| 1250 | - assert!( | ||
| 1251 | - matches!(depth, 8 | 10 | 12), | ||
| 1252 | - "lane-av1422lift: ffmpeg_decode_sequence_422_depth takes 8, 10 or 12, got {depth}" | ||
| 1253 | - ); | ||
| 1254 | - let out = run_with_stdin( | ||
| 1255 | - Command::new("ffmpeg").args([ | ||
| 1256 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", pix_fmt, "-", | ||
| 1257 | - ]), | ||
| 1258 | - stream, | ||
| 1259 | - ); | ||
| 1260 | - assert!( | ||
| 1261 | - out.status.success(), | ||
| 1262 | - "ffmpeg refused the 4:2:2 stream ({pix_fmt}): {}", | ||
| 1263 | - String::from_utf8_lossy(&out.stderr) | ||
| 1264 | - ); | ||
| 1265 | - let (luma, chroma) = (width * height, width.div_ceil(2) * height); | ||
| 1266 | - let bps = if depth == 8 { 1 } else { 2 }; | ||
| 1267 | - let frame_bytes = (luma + 2 * chroma) * bps; | ||
| 1268 | - assert_eq!( | ||
| 1269 | - out.stdout.len(), | ||
| 1270 | - frame_bytes * frames, | ||
| 1271 | - "{}", | ||
| 1272 | - frame_count_diagnosis( | ||
| 1273 | - "4:2:2", | ||
| 1274 | - frames, | ||
| 1275 | - width, | ||
| 1276 | - height, | ||
| 1277 | - frame_bytes, | ||
| 1278 | - out.stdout.len(), | ||
| 1279 | - &out.stderr | ||
| 1280 | - ) | ||
| 1281 | - ); | ||
| 1282 | - (0..frames) | ||
| 1283 | - .map(|i| { | ||
| 1284 | - let base = i * frame_bytes; | ||
| 1285 | - let samples = |off: usize, n: usize| -> Vec<u16> { | ||
| 1286 | - let slice = &out.stdout[base + off..base + off + n * bps]; | ||
| 1287 | - if bps == 1 { | ||
| 1288 | - slice.iter().map(|&v| u16::from(v)).collect() | ||
| 1289 | - } else { | ||
| 1290 | - slice | ||
| 1291 | - .as_chunks::<2>().0.iter() | ||
| 1292 | - .map(|c| u16::from_le_bytes([c[0], c[1]])) | ||
| 1293 | - .collect() | ||
| 1294 | - } | ||
| 1295 | - }; | ||
| 1296 | - Pic { | ||
| 1297 | - width, | ||
| 1298 | - height, | ||
| 1299 | - y: samples(0, luma), | ||
| 1300 | - u: samples(luma * bps, chroma), | ||
| 1301 | - v: samples((luma + chroma) * bps, chroma), | ||
| 1302 | - } | ||
| 1303 | - }) | ||
| 1304 | - .collect() | ||
| 1305 | - } | ||
| 1306 | - | ||
| 1307 | - /// lane-av1422lift: the shared body of every 4:2:2 exactness gate this | ||
| 1308 | - /// lane adds, and the answer to "a byte-exact 4:2:2 gate can still be | ||
| 1309 | - /// vacuous". | ||
| 1310 | - /// | ||
| 1311 | - /// Before lane-av1422census422 the per-plane coefficient-unit census was | ||
| 1312 | - /// armed at `ss_x == 0 && ss_y == 0` only, so on a 4:2:2 stream | ||
| 1313 | - /// `census_nonsub_units()` read `[0, 0, 0]` BY CONSTRUCTION -- a gate | ||
| 1314 | - /// could have been green while the decode walked nothing at all. The | ||
| 1315 | - /// census is now armed for `(ss_x == 0 || ss_y == 0)`, so the delta | ||
| 1316 | - /// asserted here is a real measurement of the walk this stream caused: | ||
| 1317 | - /// every plane must show a non-zero number of transform units AND of | ||
| 1318 | - /// units that coded at least one coefficient. | ||
| 1319 | - /// | ||
| 1320 | - /// Four things are asserted per frame, in this order: | ||
| 1321 | - /// | ||
| 1322 | - /// 1. the decoded frame's dimensions, and that its chroma planes are | ||
| 1323 | - /// `round_ss(w, 1) * round_ss(h, 0)` -- half width, FULL height. A | ||
| 1324 | - /// decoder that kept 4:2:0 plane allocation while walking 4:2:2 | ||
| 1325 | - /// entropy would pass a per-sample compare against a 4:2:0-sized | ||
| 1326 | - /// oracle; this is the shape assertion that closes that hole, and it | ||
| 1327 | - /// is asserted against the DECODED frame, never against the gate's | ||
| 1328 | - /// own name. | ||
| 1329 | - /// 2. the depth, read out of the stream's own sequence header. | ||
| 1330 | - /// 3. per-plane, per-frame byte-exactness against ffmpeg's rawvideo of | ||
| 1331 | - /// the same bytes at the depth-correct pixel format. Frame N of ours | ||
| 1332 | - /// against frame N of ffmpeg's: `decode_stream` returns DISPLAY order | ||
| 1333 | - /// and so does ffmpeg's rawvideo muxer, so a hidden alt-ref does not | ||
| 1334 | - /// shift the pairing (the decode-order-vs-display-order trap the | ||
| 1335 | - /// out-of-process corpus comparator has to solve separately). | ||
| 1336 | - /// 4. the census delta, asserted once for the whole stream rather than | ||
| 1337 | - /// per frame, because the counters are cumulative per thread. | ||
| 1338 | - /// | ||
| 1339 | - /// `require_coded` is false ONLY for a cell whose identity IS that it | ||
| 1340 | - /// codes nothing -- `422_allskip_2f.obu`, whose whole point is that | ||
| 1341 | - /// the inter frame reads no residual and the pre-port decoder read | ||
| 1342 | - /// PHANTOM units there. Demanding coded units on it would be | ||
| 1343 | - /// demanding the defect; its caller asserts the all-skip property | ||
| 1344 | - /// directly instead. | ||
| 1345 | - pub(super) fn assert_422_stream_pixel_exact( | ||
| 1346 | - name: &str, | ||
| 1347 | - stream: &[u8], | ||
| 1348 | - width: usize, | ||
| 1349 | - height: usize, | ||
| 1350 | - frames: usize, | ||
| 1351 | - depth: u8, | ||
| 1352 | - require_coded: bool, | ||
| 1353 | - ) -> ([usize; 3], [usize; 3]) { | ||
| 1354 | - let _gate_lock = lock_gate_counters(); | ||
| 1355 | - assert_eq!( | ||
| 1356 | - stream_bit_depth(stream, name), | ||
| 1357 | - depth, | ||
| 1358 | - "{name}: the stream's OWN sequence header does not say {depth} bit" | ||
| 1359 | - ); | ||
| 1360 | - let before = crate::decode::census_nonsub_units(); | ||
| 1361 | - let before_coded = crate::decode::census_nonsub_coded(); | ||
| 1362 | - let ours = decode_stream(stream) | ||
| 1363 | - .unwrap_or_else(|e| panic!("{name}: decode_stream refused a real 4:2:2 stream: {e}")); | ||
| 1364 | - assert_eq!(ours.len(), frames, "{name}: decoded frame count"); | ||
| 1365 | - for (i, f) in ours.iter().enumerate() { | ||
| 1366 | - assert_eq!( | ||
| 1367 | - (f.width, f.height), | ||
| 1368 | - (width, height), | ||
| 1369 | - "{name}: frame {i} dimensions" | ||
| 1370 | - ); | ||
| 1371 | - assert_eq!( | ||
| 1372 | - (f.u.len(), f.v.len()), | ||
| 1373 | - (width.div_ceil(2) * height, width.div_ceil(2) * height), | ||
| 1374 | - "{name}: frame {i} chroma planes are {}/{} samples -- 4:2:2 is HALF WIDTH and \ | ||
| 1375 | - FULL HEIGHT ({width}/2 x {height}); a quarter-height plane means the decode kept \ | ||
| 1376 | - a 4:2:0 allocation", | ||
| 1377 | - f.u.len(), | ||
| 1378 | - f.v.len() | ||
| 1379 | - ); | ||
| 1380 | - } | ||
| 1381 | - let pix_fmt = match depth { | ||
| 1382 | - 8 => "yuv422p", | ||
| 1383 | - 10 => "yuv422p10le", | ||
| 1384 | - 12 => "yuv422p12le", | ||
| 1385 | - other => panic!("{name}: no ffmpeg pixel format mapped for depth {other}"), | ||
| 1386 | - }; | ||
| 1387 | - let theirs = | ||
| 1388 | - ffmpeg_decode_sequence_422_depth(stream, width, height, frames, depth, pix_fmt); | ||
| 1389 | - for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | ||
| 1390 | - for (plane, ours_plane, theirs_plane) in | ||
| 1391 | - [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] | ||
| 1392 | - { | ||
| 1393 | - assert_eq!( | ||
| 1394 | - ours_plane.len(), | ||
| 1395 | - theirs_plane.len(), | ||
| 1396 | - "{name}: {plane} plane {i} is {} samples against ffmpeg's {} -- the 4:2:2 chroma \ | ||
| 1397 | - span is wrong on one of the two sides", | ||
| 1398 | - ours_plane.len(), | ||
| 1399 | - theirs_plane.len() | ||
| 1400 | - ); | ||
| 1401 | - if let Some(bad) = ours_plane | ||
| 1402 | - .iter() | ||
| 1403 | - .zip(theirs_plane) | ||
| 1404 | - .position(|(x, y)| x != y) | ||
| 1405 | - { | ||
| 1406 | - panic!( | ||
| 1407 | - "{name}: {plane} differs from ffmpeg at frame {i} sample {bad} ({} vs {}; \ | ||
| 1408 | - {} of {} samples differ)", | ||
| 1409 | - ours_plane[bad], | ||
| 1410 | - theirs_plane[bad], | ||
| 1411 | - ours_plane | ||
| 1412 | - .iter() | ||
| 1413 | - .zip(theirs_plane) | ||
| 1414 | - .filter(|(x, y)| x != y) | ||
| 1415 | - .count(), | ||
| 1416 | - ours_plane.len() | ||
| 1417 | - ); | ||
| 1418 | - } | ||
| 1419 | - } | ||
| 1420 | - } | ||
| 1421 | - let units = crate::decode::census_nonsub_units(); | ||
| 1422 | - let coded = crate::decode::census_nonsub_coded(); | ||
| 1423 | - let delta: [usize; 3] = std::array::from_fn(|p| units[p] - before[p]); | ||
| 1424 | - let coded_delta: [usize; 3] = std::array::from_fn(|p| coded[p] - before_coded[p]); | ||
| 1425 | - for (p, plane) in ["luma", "U", "V"].into_iter().enumerate() { | ||
| 1426 | - assert!( | ||
| 1427 | - delta[p] > 0, | ||
| 1428 | - "{name}: the {plane} plane read ZERO coefficient units across the whole stream -- \ | ||
| 1429 | - this byte-exact compare is vacuous with respect to 4:2:2 (class \ | ||
| 1430 | - gate-blind-to-feature)" | ||
| 1431 | - ); | ||
| 1432 | - if require_coded { | ||
| 1433 | - assert!( | ||
| 1434 | - coded_delta[p] > 0, | ||
| 1435 | - "{name}: the {plane} plane coded ZERO coefficient units across the whole \ | ||
| 1436 | - stream -- every unit took the all-zero early return, so no coefficient path \ | ||
| 1437 | - was exercised" | ||
| 1438 | - ); | ||
| 1439 | - } | ||
| 1440 | - } | ||
| 1441 | - eprintln!( | ||
| 1442 | - "{name}: byte-exact vs ffmpeg ({pix_fmt}, {frames} frames); census delta \ | ||
| 1443 | - units=[{}, {}, {}] coded=[{}, {}, {}]", | ||
| 1444 | - delta[0], delta[1], delta[2], coded_delta[0], coded_delta[1], coded_delta[2] | ||
| 1445 | - ); | ||
| 1446 | - (delta, coded_delta) | ||
| 1447 | - } | ||
| 1448 | - | ||
| 1449 | - /// `(subsampling_x, subsampling_y, bit_depth)` out of the stream's OWN | ||
| 1450 | - /// sequence header. A gate that claims to exercise a subsampling-specific | ||
| 1451 | - /// path must assert this from the parsed header, not from the recipe that | ||
| 1452 | - /// produced the fixture: the recipe can drift (or a wrong `--pix_fmt` | ||
| 1453 | - /// argument can silently produce a different subsampling) and every other | ||
| 1454 | - /// assertion would then pass vacuously. | ||
| 1455 | - pub(super) fn subsampled_header_shape(stream: &[u8], name: &str) -> (u8, u8, usize) { | ||
| 1456 | - let mut parser = Av1Parser::new(); | ||
| 1457 | - let mut pos = 0usize; | ||
| 1458 | - let mut shape = None; | ||
| 1459 | - while pos < stream.len() { | ||
| 1460 | - let obu = parser | ||
| 1461 | - .parse_obu(&stream[pos..]) | ||
| 1462 | - .unwrap_or_else(|e| panic!("{name}: OBU does not parse: {e:?}")); | ||
| 1463 | - if obu.total_size == 0 { | ||
| 1464 | - break; | ||
| 1465 | - } | ||
| 1466 | - pos += obu.total_size; | ||
| 1467 | - if let ObuKind::SequenceHeader(seq) = obu.kind { | ||
| 1468 | - shape = Some(( | ||
| 1469 | - seq.color_config.subsampling_x, | ||
| 1470 | - seq.color_config.subsampling_y, | ||
| 1471 | - seq.color_config.bit_depth as usize, | ||
| 1472 | - )); | ||
| 1473 | - } | ||
| 1474 | - } | ||
| 1475 | - shape.unwrap_or_else(|| panic!("{name}: no sequence header parsed")) | ||
| 1476 | - } | ||
| 1477 | - | ||
| 1478 | - /// lane-av1gates444: the live 4:4:4 LOSSY cell the chroma-format sweep | ||
| 1479 | - /// measured EXACT 4/4 and left unpinned. The recipe is the sweep's own | ||
| 1480 | - /// §6.2 encode, reproduced LIVE against the oracle `aomenc` rather than | ||
| 1481 | - /// from a pin, because the claim these three gates carry is a property | ||
| 1482 | - /// of the *decoder* at a geometry, not of a blob: | ||
| 1483 | - /// ```text | ||
| 1484 | - /// ffmpeg -f lavfi -i "testsrc2=size=<W>x<H>:rate=25" -frames:v 4 \ | ||
| 1485 | - /// -pix_fmt yuv444p -f yuv4mpegpipe - | \ | ||
| 1486 | - /// aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \ | ||
| 1487 | - /// --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \ | ||
| 1488 | - /// --kf-max-dist=100 --limit=4 --obu -o - - | ||
| 1489 | - /// ``` | ||
| 1490 | - /// `rate=25` is load-bearing (testsrc2's pattern is time-parameterised) | ||
| 1491 | - /// and `--limit=4` is the sweep's frame count: at `--limit=6` the same | ||
| 1492 | - /// recipe emits 7674 / 11465 / 19121 bytes instead of the sweep's | ||
| 1493 | - /// 5938 / 8945 / 15239, i.e. a different stream than the one measured. | ||
| 1494 | - /// `--profile=1` is what makes the source 4:4:4 at all. | ||
| 1495 | - /// | ||
| 1496 | - /// Every assertion here is a non-vacuity assertion first and a pixel | ||
| 1497 | - /// compare second. The frame count, the per-frame geometry and the | ||
| 1498 | - /// FULL-RESOLUTION chroma plane length are asserted because a truncated | ||
| 1499 | - /// or 4:2:0-shaped decode can pass a lenient compare; the | ||
| 1500 | - /// `rect4_inter_own_chroma444_hits()` reach assert is there because the | ||
| 1501 | - /// class these cells belong to is the 4:4:4-only own-chroma-extent route | ||
| 1502 | - /// in [`decode_inter_block`]'s `around_c` (a 4:2:0 stream of the same | ||
| 1503 | - /// content leaves it at 0), and a counter at 0 would mean the gate | ||
| 1504 | - /// measured a different route than it names. | ||
| 1505 | - /// The guard is [`have_aomenc`], which probes first and asserts LAST with | ||
| 1506 | - /// the env escape: with `EC_AV1_REQUIRE_AOMENC` set, a missing oracle is | ||
| 1507 | - /// a hard failure naming the path it looked for, and a batch run cannot | ||
| 1508 | - /// report green off three skipped gates. With it unset the `None` below is | ||
| 1509 | - /// a developer-only convenience for a checkout without an oracle -- it is | ||
| 1510 | - /// the ONLY way this gate can return without measuring, and it announces | ||
| 1511 | - /// itself on stderr naming the env var that would make it a failure. | ||
| 1512 | - /// (It used to return an empty `Vec` that the caller turned into a silent | ||
| 1513 | - /// early `return`: the same green, reached through a second exit nobody | ||
| 1514 | - /// was reading.) | ||
| 1515 | - pub(super) fn encode_444_lossy_live(name: &str, w: usize, h: usize) -> Option<Vec<u8>> { | ||
| 1516 | - if !have_aomenc() { | ||
| 1517 | - eprintln!( | ||
| 1518 | - "SKIP {name}: no aomenc oracle at {} -- set EC_AV1_REQUIRE_AOMENC=1 to make this \ | ||
| 1519 | - a failure, or run scripts/build-aom-oracle.sh", | ||
| 1520 | - aomenc_path().display() | ||
| 1521 | - ); | ||
| 1522 | - return None; | ||
| 1523 | - } | ||
| 1524 | - let source = format!("testsrc2=size={w}x{h}:rate=25"); | ||
| 1525 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1526 | - .args([ | ||
| 1527 | - "-v", | ||
| 1528 | - "error", | ||
| 1529 | - "-f", | ||
| 1530 | - "lavfi", | ||
| 1531 | - "-i", | ||
| 1532 | - &source, | ||
| 1533 | - "-frames:v", | ||
| 1534 | - "4", | ||
| 1535 | - "-pix_fmt", | ||
| 1536 | - "yuv444p", | ||
| 1537 | - "-f", | ||
| 1538 | - "yuv4mpegpipe", | ||
| 1539 | - "-", | ||
| 1540 | - ]) | ||
| 1541 | - .stdin(Stdio::null()) | ||
| 1542 | - .stdout(Stdio::piped()) | ||
| 1543 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1544 | - .expect("ffmpeg failed to run"); | ||
| 1545 | - assert!( | ||
| 1546 | - y4m.status.success(), | ||
| 1547 | - "{name}: ffmpeg refused the {w}x{h} 4:4:4 source: {}", | ||
| 1548 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1549 | - ); | ||
| 1550 | - let out = run_with_stdin( | ||
| 1551 | - Command::new(aomenc_path()).args([ | ||
| 1552 | - "--codec=av1", | ||
| 1553 | - "--profile=1", | ||
| 1554 | - "--passes=1", | ||
| 1555 | - "--end-usage=q", | ||
| 1556 | - "--cq-level=20", | ||
| 1557 | - "--cpu-used=2", | ||
| 1558 | - "--threads=1", | ||
| 1559 | - "--row-mt=0", | ||
| 1560 | - "--lag-in-frames=0", | ||
| 1561 | - "--kf-max-dist=100", | ||
| 1562 | - "--limit=4", | ||
| 1563 | - "--obu", | ||
| 1564 | - "-o", | ||
| 1565 | - "-", | ||
| 1566 | - "-", | ||
| 1567 | - ]), | ||
| 1568 | - &y4m.stdout, | ||
| 1569 | - ); | ||
| 1570 | - assert!( | ||
| 1571 | - out.status.success(), | ||
| 1572 | - "{name}: aomenc refused the {w}x{h} 4:4:4 lossy recipe: {}", | ||
| 1573 | - String::from_utf8_lossy(&out.stderr) | ||
| 1574 | - ); | ||
| 1575 | - assert!( | ||
| 1576 | - !out.stdout.is_empty(), | ||
| 1577 | - "{name}: aomenc produced no OBU for {w}x{h} -- a zero-length stream would \ | ||
| 1578 | - decode to nothing and the compare below would compare nothing" | ||
| 1579 | - ); | ||
| 1580 | - Some(out.stdout) | ||
| 1581 | - } | ||
| 1582 | - | ||
| 1583 | - /// lane-av1-loss64: the generator for the two gates below -- a deterministic | ||
| 1584 | - /// 1-frame lossless superblock-128 aomenc stream of `testsrc2`. `extra` | ||
| 1585 | - /// flags land last (aomenc keeps the LAST occurrence of a repeated flag). | ||
| 1586 | - /// The recipe is the one lanes/av1rect14.report.md section 2 measured | ||
| 1587 | - /// (`--lossless=1 --sb-size=128 --enable-1to4-partitions=1`); the | ||
| 1588 | - /// `--min-partition-size` override is what steers the bottom superblock | ||
| 1589 | - /// row's RD into overhanging 64x64 `NONE` blocks (the shape the first fix | ||
| 1590 | - /// clips) or, at 8, keeps sub-8x8 partitions out of the second gate's | ||
| 1591 | - /// stream so the whole frame is decodable. | ||
| 1592 | - pub(super) fn lossless_sb128_testsrc2(width: usize, height: usize, extra: &[&str]) -> Vec<u8> { | ||
| 1593 | - let mut ff = Command::new("ffmpeg"); | ||
| 1594 | - let out = crate::tool_cache::cached_output_io(ff | ||
| 1595 | - .args(["-v", "error", "-f", "lavfi", "-i"]) | ||
| 1596 | - .arg(format!("testsrc2=s={width}x{height}:r=25")) | ||
| 1597 | - .args([ | ||
| 1598 | - "-frames:v", | ||
| 1599 | - "1", | ||
| 1600 | - "-pix_fmt", | ||
| 1601 | - "yuv420p", | ||
| 1602 | - "-strict", | ||
| 1603 | - "-1", | ||
| 1604 | - "-f", | ||
| 1605 | - "yuv4mpegpipe", | ||
| 1606 | - "-", | ||
| 1607 | - ]) | ||
| 1608 | - .stdin(Stdio::null()) | ||
| 1609 | - .stdout(Stdio::piped()) | ||
| 1610 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1611 | - .expect("ffmpeg failed to run"); | ||
| 1612 | - assert!( | ||
| 1613 | - out.status.success(), | ||
| 1614 | - "ffmpeg failed for testsrc2 {width}x{height}" | ||
| 1615 | - ); | ||
| 1616 | - let y4m = out.stdout; | ||
| 1617 | - let out = run_with_stdin( | ||
| 1618 | - Command::new(aomenc_path()) | ||
| 1619 | - .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) | ||
| 1620 | - .args([ | ||
| 1621 | - "--passes=1", | ||
| 1622 | - "--cpu-used=0", | ||
| 1623 | - "--lag-in-frames=0", | ||
| 1624 | - "--kf-max-dist=1", | ||
| 1625 | - "--limit=1", | ||
| 1626 | - "--threads=1", | ||
| 1627 | - "--tile-columns=0", | ||
| 1628 | - "--lossless=1", | ||
| 1629 | - "--sb-size=128", | ||
| 1630 | - "--enable-1to4-partitions=1", | ||
| 1631 | - ]) | ||
| 1632 | - .args(extra) | ||
| 1633 | - .args(["--obu", "-o", "-", "-"]), | ||
| 1634 | - &y4m, | ||
| 1635 | - ); | ||
| 1636 | - assert!( | ||
| 1637 | - out.status.success(), | ||
| 1638 | - "aomenc failed: {}", | ||
| 1639 | - String::from_utf8_lossy(&out.stderr) | ||
| 1640 | - ); | ||
| 1641 | - out.stdout | ||
| 1642 | - } | ||
| 1643 | - | ||
| 1644 | - /// Path to a real `aomenc` build carrying the reference options this | ||
| 1645 | - /// fixture needs (`--max-partition-size`, `--enable-tx-size-search`, | ||
| 1646 | - /// `--loopfilter-control`) -- this box's `ffmpeg` links a libaom too old | ||
| 1647 | - /// to expose `enable-tx-size-search`/`loopfilter-control` through its | ||
| 1648 | - /// own `-aom-params` passthrough (probed live: "Cannot find aom | ||
| 1649 | - /// option"), so [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`] | ||
| 1650 | - /// shells out to the standalone binary instead of ffmpeg's libaom-av1 | ||
| 1651 | - /// wrapper every other test here uses. `EC_AV1_AOMENC` overrides the | ||
| 1652 | - /// default dev-build path; the test skips (not fails) when neither this | ||
| 1653 | - /// nor `ffmpeg` is present. | ||
| 1654 | - pub(super) fn aomenc_path() -> std::path::PathBuf { | ||
| 1655 | - if let Some(p) = std::env::var_os("EC_AV1_AOMENC") { | ||
| 1656 | - return std::path::PathBuf::from(p); | ||
| 1657 | - } | ||
| 1658 | - // The oracle used to live only under `/tmp`, which this box's tmpfs | ||
| 1659 | - // guard reclaims -- when it did, all 20 aomenc gates below went | ||
| 1660 | - // silently vacuous (SKIP, suite still green). The durable location | ||
| 1661 | - // is provisioned by `scripts/build-aom-oracle.sh`; the `/tmp` path | ||
| 1662 | - // stays last as a legacy fallback. | ||
| 1663 | - let mut candidates = Vec::new(); | ||
| 1664 | - if let Some(home) = std::env::var_os("HOME") { | ||
| 1665 | - candidates.push(std::path::PathBuf::from(&home).join(".cache/aom-oracle/build/aomenc")); | ||
| 1666 | - } | ||
| 1667 | - candidates.push("/tmp/libaom-src/build/encoder/aomenc".into()); | ||
| 1668 | - candidates | ||
| 1669 | - .iter() | ||
| 1670 | - .find(|p| p.is_file()) | ||
| 1671 | - .cloned() | ||
| 1672 | - .unwrap_or_else(|| candidates.remove(0)) | ||
| 1673 | - } | ||
| 1674 | - | ||
| 1675 | - /// Whether the aomenc oracle is present. Absence normally SKIPs (a | ||
| 1676 | - /// checkout without the oracle should still run the rest of the suite), | ||
| 1677 | - /// but `EC_AV1_REQUIRE_AOMENC=1` turns it into a hard failure so a batch | ||
| 1678 | - /// run cannot report green off 20 skipped gates. | ||
| 1679 | - /// Where a pinned stream lives. `fixtures/` is a symlink to a durable | ||
| 1680 | - /// directory outside the repo, so a pin captured in one session is still | ||
| 1681 | - /// there in the next; a session scratchpad is not (tmpfs reaps it, and | ||
| 1682 | - /// four pins were silently dead because of that). | ||
| 1683 | - pub(super) fn pin_dir() -> std::path::PathBuf { | ||
| 1684 | - if let Some(p) = std::env::var_os("EC_AV1_PIN_DIR") { | ||
| 1685 | - return std::path::PathBuf::from(p); | ||
| 1686 | - } | ||
| 1687 | - std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1688 | - .join("../../fixtures") | ||
| 1689 | - .canonicalize() | ||
| 1690 | - .unwrap_or_else(|_| std::path::PathBuf::from("fixtures")) | ||
| 1691 | - } | ||
| 1692 | - | ||
| 1693 | - /// A COMMITTED pin: `crates/ec-av1/fixtures/<name>`, which travels in the | ||
| 1694 | - /// tarball and is therefore present on every runner. `pin_dir()` resolves | ||
| 1695 | - /// to the gitignored root `fixtures/`, so a pin written there is lost when | ||
| 1696 | - /// the machine's scratchpad is reaped -- three gates sat at `rc=0` having | ||
| 1697 | - /// tested nothing for exactly that reason (lane-av1pins). Falls back to | ||
| 1698 | - /// `pin_dir()` so a locally re-captured stream still overrides. | ||
| 1699 | - /// Read a pin that a gate cannot proceed without. A missing pin is a | ||
| 1700 | - /// HARD failure naming the path and the generator, never a raw io panic | ||
| 1701 | - /// and never a silent skip: `EC_AV1_GATE_DUMP_PIN` points the gate at a | ||
| 1702 | - /// freshly captured stream, and a runner without the committed copy must | ||
| 1703 | - /// say so instead of reporting green having tested nothing. | ||
| 1704 | - pub(super) fn require_pin(path: &std::path::Path, name: &str) -> Vec<u8> { | ||
| 1705 | - std::fs::read(path).unwrap_or_else(|e| { | ||
| 1706 | - panic!( | ||
| 1707 | - "no pinned bytes at {} ({e}) -- set EC_AV1_GATE_DUMP_PIN to a freshly \ | ||
| 1708 | - captured stream, or restore the committed copy at \ | ||
| 1709 | - crates/ec-av1/fixtures/{name}", | ||
| 1710 | - path.display() | ||
| 1711 | - ) | ||
| 1712 | - }) | ||
| 1713 | - } | ||
| 1714 | - | ||
| 1715 | - pub(super) fn crate_pin(name: &str) -> std::path::PathBuf { | ||
| 1716 | - let in_crate = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1717 | - .join("fixtures") | ||
| 1718 | - .join(name); | ||
| 1719 | - if in_crate.is_file() { | ||
| 1720 | - in_crate | ||
| 1721 | - } else { | ||
| 1722 | - pin_dir().join(name) | ||
| 1723 | - } | ||
| 1724 | - } | ||
| 1725 | - | ||
| 1726 | - pub(super) fn have_aomenc() -> bool { | ||
| 1727 | - let present = aomenc_path().is_file(); | ||
| 1728 | - assert!( | ||
| 1729 | - present || std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 1730 | - "EC_AV1_REQUIRE_AOMENC is set but no aomenc at {} -- run scripts/build-aom-oracle.sh", | ||
| 1731 | - aomenc_path().display() | ||
| 1732 | - ); | ||
| 1733 | - present | ||
| 1734 | - } | ||
| 1735 | - | ||
| 1736 | - /// lane-av1oracleskip: the probe for the ORACLE COMPARER, in the same | ||
| 1737 | - /// shape as [`have_ffmpeg`] -- probe first, then `assert!` LAST, with the | ||
| 1738 | - /// env escape -- and it prints its own SKIP so a caller cannot skip the | ||
| 1739 | - /// compare silently. | ||
| 1740 | - /// | ||
| 1741 | - /// Why this exists: thirteen gates wrapped their oracle arm in a bare | ||
| 1742 | - /// `if aomdec_path().is_file()`, and that shape had NO env escape at all. | ||
| 1743 | - /// An oracle build with `aomenc` but no `aomdec` beside it (or an | ||
| 1744 | - /// `EC_AV1_AOMDEC` override pointing at a moved path) made the gate | ||
| 1745 | - /// encode, decode, assert its geometry and its counters, and then quietly | ||
| 1746 | - /// never compare -- green having measured nothing, with no line in the | ||
| 1747 | - /// output to notice. Nine of the thirteen printed a SKIP in an `else` and | ||
| 1748 | - /// four printed nothing at all; both are the same defect, and both are | ||
| 1749 | - /// closed by one probe. | ||
| 1750 | - /// | ||
| 1751 | - /// With `EC_AV1_REQUIRE_AOMENC` (or the aomdec-specific | ||
| 1752 | - /// `EC_AV1_REQUIRE_AOMDEC`) set, the absence is a HARD failure naming the | ||
| 1753 | - /// path that was looked for -- that is the batch-run guarantee, and it is | ||
| 1754 | - /// what the bare `is_file()` could not give. With it unset the SKIP below | ||
| 1755 | - /// is printed and the gate still passes: that remains a developer-only | ||
| 1756 | - /// convenience for a checkout without an oracle, never evidence. | ||
| 1757 | - pub(super) fn aomdec_available(name: &str) -> bool { | ||
| 1758 | - let present = aomdec_path().is_file(); | ||
| 1759 | - let require = std::env::var_os("EC_AV1_REQUIRE_AOMDEC").is_some() | ||
| 1760 | - || std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_some(); | ||
| 1761 | - assert!( | ||
| 1762 | - present || !require, | ||
| 1763 | - "{name}: no oracle aomdec at {} -- the pixel compare this gate exists for would be \ | ||
| 1764 | - skipped, and EC_AV1_REQUIRE_AOMDEC/EC_AV1_REQUIRE_AOMENC is set. Build the oracle \ | ||
| 1765 | - with scripts/build-aom-oracle.sh, or point EC_AV1_AOMDEC at a real aomdec.", | ||
| 1766 | - aomdec_path().display() | ||
| 1767 | - ); | ||
| 1768 | - if !present { | ||
| 1769 | - eprintln!( | ||
| 1770 | - "SKIP {name}: no oracle aomdec at {} -- the pixel compare is NOT running (set \ | ||
| 1771 | - EC_AV1_REQUIRE_AOMDEC=1 to make this a failure)", | ||
| 1772 | - aomdec_path().display() | ||
| 1773 | - ); | ||
| 1774 | - } | ||
| 1775 | - present | ||
| 1776 | - } | ||
| 1777 | - | ||
| 1778 | - // lane-av1cmpaudit2: this thread's oracle override, set by | ||
| 1779 | - // `set_oracle_path` and consulted by `aomdec_path` ahead of the env var. | ||
| 1780 | - // | ||
| 1781 | - // It is thread-local for the same reason `FINAL_DUMP_PREFIX` is: the | ||
| 1782 | - // control test `every_oracle_comparator_reds_on_a_one_byte_wrong_oracle` | ||
| 1783 | - // has to hand the helpers a DELIBERATELY WRONG oracle, and a | ||
| 1784 | - // process-global `std::env::set_var` could not do that safely -- the | ||
| 1785 | - // crate forbids `unsafe_code`, and even where it did not, one test's | ||
| 1786 | - // tampered oracle would leak into every sibling test's comparison | ||
| 1787 | - // running on another thread. A thread-local override confines the wrong | ||
| 1788 | - // oracle to the one thread that asked for it. | ||
| 1789 | - thread_local! { | ||
| 1790 | - static ORACLE_PATH: std::cell::RefCell<Option<std::path::PathBuf>> = | ||
| 1791 | - const { std::cell::RefCell::new(None) }; | ||
| 1792 | - } | ||
| 1793 | - | ||
| 1794 | - /// Points this thread's oracle helpers at `path`. `None` restores the | ||
| 1795 | - /// real `aomdec`. | ||
| 1796 | - pub(super) fn set_oracle_path(path: Option<std::path::PathBuf>) { | ||
| 1797 | - ORACLE_PATH.with(|c| *c.borrow_mut() = path); | ||
| 1798 | - } | ||
| 1799 | - | ||
| 1800 | - // lane-film10fix: this thread's ffmpeg override, set by | ||
| 1801 | - // `set_ffmpeg_path` and consulted by `ffmpeg_path` ahead of the bare | ||
| 1802 | - // name. Same shape and same reason as `ORACLE_PATH` above: the control | ||
| 1803 | - // test `every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg` has | ||
| 1804 | - // to hand the `ffmpeg_decode_sequence*` helpers a DELIBERATELY WRONG | ||
| 1805 | - // reference, and a process-global PATH edit would leak that wrong | ||
| 1806 | - // reference into every sibling test decoding on another thread. The | ||
| 1807 | - // crate forbids `unsafe_code`, so `std::env::set_var` is not available | ||
| 1808 | - // either; a thread-local confines the tamper to the one thread. | ||
| 1809 | - thread_local! { | ||
| 1810 | - static FFMPEG_PATH: std::cell::RefCell<Option<std::path::PathBuf>> = | ||
| 1811 | - const { std::cell::RefCell::new(None) }; | ||
| 1812 | - } | ||
| 1813 | - | ||
| 1814 | - /// Points this thread's `ffmpeg_decode_sequence*` helpers at `path`. | ||
| 1815 | - /// `None` restores the real `ffmpeg` on PATH. | ||
| 1816 | - pub(super) fn set_ffmpeg_path(path: Option<std::path::PathBuf>) { | ||
| 1817 | - FFMPEG_PATH.with(|c| *c.borrow_mut() = path); | ||
| 1818 | - } | ||
| 1819 | - | ||
| 1820 | - /// The `ffmpeg` every reference helper in this module spawns. | ||
| 1821 | - pub(super) fn ffmpeg_path() -> std::path::PathBuf { | ||
| 1822 | - if let Some(p) = FFMPEG_PATH.with(|c| c.borrow().clone()) { | ||
| 1823 | - return p; | ||
| 1824 | - } | ||
| 1825 | - std::path::PathBuf::from("ffmpeg") | ||
| 1826 | - } | ||
| 1827 | - | ||
| 1828 | - /// The instrumented `aomdec` beside the `aomenc` oracle | ||
| 1829 | - /// (`scripts/build-aom-oracle.sh` + `scripts/instrument-aom-oracle.sh`). | ||
| 1830 | - pub(super) fn aomdec_path() -> std::path::PathBuf { | ||
| 1831 | - if let Some(p) = ORACLE_PATH.with(|c| c.borrow().clone()) { | ||
| 1832 | - return p; | ||
| 1833 | - } | ||
| 1834 | - if let Some(p) = std::env::var_os("EC_AV1_AOMDEC") { | ||
| 1835 | - return std::path::PathBuf::from(p); | ||
| 1836 | - } | ||
| 1837 | - aomenc_path().with_file_name("aomdec") | ||
| 1838 | - } | ||
| 1839 | - | ||
| 1840 | - /// Decodes `stream` with both this decoder and the instrumented oracle | ||
| 1841 | - /// `aomdec`, and compares EVERY decoded frame in DECODE order -- | ||
| 1842 | - /// including the hidden (`show_frame == 0`) alt-ref frames no other gate | ||
| 1843 | - /// in this repo can see, because `decode_stream` only pushes shown | ||
| 1844 | - /// frames and `ffmpeg -f obu ... rawvideo` only emits shown frames | ||
| 1845 | - /// (class gate-blind-to-hidden-frames: a hidden frame's defect surfaces | ||
| 1846 | - /// only as drift on some later shown frame, if at all). | ||
| 1847 | - /// | ||
| 1848 | - /// Both sides write the final, post-deblock/CDEF/LR/superres frame as it | ||
| 1849 | - /// is stored into the reference buffer (`EC_AV1_FINAL_DUMP`, ours in | ||
| 1850 | - /// `decode_stream`, the oracle's in rung 12 of | ||
| 1851 | - /// `scripts/instrument-aom-oracle.sh`), 8-bit as u8 / high bitdepth as | ||
| 1852 | - /// u16 LE. Returns `(frames_decoded, hidden_frames)`. | ||
| 1853 | - pub(super) fn decode_all_frames_vs_oracle(stream: &[u8], name: &str) -> (usize, usize) { | ||
| 1854 | - let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id())); | ||
| 1855 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1856 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 1857 | - let obu = dir.join("in.obu"); | ||
| 1858 | - std::fs::write(&obu, stream).expect("writing the stream"); | ||
| 1859 | - let aom_prefix = dir.join("aom"); | ||
| 1860 | - let out = crate::tool_cache::cached_output_io(Command::new(aomdec_path()) | ||
| 1861 | - .args(["--codec=av1", "-o"]) | ||
| 1862 | - .arg(dir.join("out.y4m")) | ||
| 1863 | - .arg(&obu) | ||
| 1864 | - .env("EC_AV1_FINAL_DUMP", &aom_prefix) | ||
| 1865 | - .stdin(Stdio::null()) | ||
| 1866 | - .stdout(Stdio::piped()) | ||
| 1867 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1868 | - .expect("aomdec failed to run"); | ||
| 1869 | - assert!( | ||
| 1870 | - out.status.success(), | ||
| 1871 | - "{name}: the oracle aomdec refused the stream: {}", | ||
| 1872 | - String::from_utf8_lossy(&out.stderr) | ||
| 1873 | - ); | ||
| 1874 | - let count_dumps = |prefix: &std::path::Path| -> usize { | ||
| 1875 | - let mut n = 0usize; | ||
| 1876 | - while std::path::PathBuf::from(format!("{}.f{n}", prefix.display())).is_file() { | ||
| 1877 | - n += 1; | ||
| 1878 | - } | ||
| 1879 | - n | ||
| 1880 | - }; | ||
| 1881 | - let oracle_frames = count_dumps(&aom_prefix); | ||
| 1882 | - assert!( | ||
| 1883 | - oracle_frames > 0, | ||
| 1884 | - "{name}: the oracle wrote no EC_AV1_FINAL_DUMP frames -- rung 12 of \ | ||
| 1885 | - scripts/instrument-aom-oracle.sh is missing from {}", | ||
| 1886 | - aomdec_path().display() | ||
| 1887 | - ); | ||
| 1888 | - let ours_prefix = dir.join("ours"); | ||
| 1889 | - set_final_dump_prefix(Some(ours_prefix.display().to_string())); | ||
| 1890 | - let decoded = decode_stream(stream); | ||
| 1891 | - set_final_dump_prefix(None); | ||
| 1892 | - let shown = decoded | ||
| 1893 | - .unwrap_or_else(|e| panic!("{name}: this decoder refused the stream: {e}")) | ||
| 1894 | - .len(); | ||
| 1895 | - let our_frames = count_dumps(&ours_prefix); | ||
| 1896 | - assert_eq!( | ||
| 1897 | - our_frames, oracle_frames, | ||
| 1898 | - "{name}: decoded {our_frames} frames in decode order, the oracle decoded \ | ||
| 1899 | - {oracle_frames}" | ||
| 1900 | - ); | ||
| 1901 | - for i in 0..oracle_frames { | ||
| 1902 | - let want = | ||
| 1903 | - std::fs::read(format!("{}.f{i}", aom_prefix.display())).expect("oracle dump"); | ||
| 1904 | - let got = std::fs::read(format!("{}.f{i}", ours_prefix.display())).expect("our dump"); | ||
| 1905 | - assert_eq!( | ||
| 1906 | - got.len(), | ||
| 1907 | - want.len(), | ||
| 1908 | - "{name}: decode-order frame {i} is {} bytes, the oracle's is {}", | ||
| 1909 | - got.len(), | ||
| 1910 | - want.len() | ||
| 1911 | - ); | ||
| 1912 | - if let Some(at) = got.iter().zip(&want).position(|(a, b)| a != b) { | ||
| 1913 | - let differing = got.iter().zip(&want).filter(|(a, b)| a != b).count(); | ||
| 1914 | - panic!( | ||
| 1915 | - "{name}: decode-order frame {i} of {oracle_frames} ({shown} shown, {} \ | ||
| 1916 | - hidden) differs from the oracle at byte {at} (ours {} vs {}), {differing} \ | ||
| 1917 | - bytes differ -- stream pinned at {}", | ||
| 1918 | - oracle_frames - shown, | ||
| 1919 | - got[at], | ||
| 1920 | - want[at], | ||
| 1921 | - obu.display() | ||
| 1922 | - ); | ||
| 1923 | - } | ||
| 1924 | - } | ||
| 1925 | - let hidden = oracle_frames - shown; | ||
| 1926 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1927 | - (oracle_frames, hidden) | ||
| 1928 | - } | ||
| 1929 | - | ||
| 1930 | - /// lane-av1422anom: a COUNTING oracle comparison. | ||
| 1931 | - /// | ||
| 1932 | - /// [`assert_rawvideo_matches`] is the right tool for "these must be equal" | ||
| 1933 | - /// and the wrong tool for a lane that has to classify many cells: it | ||
| 1934 | - /// panics on the first differing byte, so it answers one cell per process | ||
| 1935 | - /// and cannot report a magnitude. This returns the count instead. | ||
| 1936 | - /// | ||
| 1937 | - /// It exists because the previous lane's per-cell counter was tautological: | ||
| 1938 | - /// it packed our own decoded samples into `ours` and then compared `ours` | ||
| 1939 | - /// against the same samples, never touching the oracle's bytes, so it | ||
| 1940 | - /// reported "0 wrong" on every cell including one that differs from | ||
| 1941 | - /// `aomdec` in 1612 samples. [`the_counting_oracle_diff_reports_a_real_difference`] | ||
| 1942 | - /// below is the test that keeps that mistake from recurring. | ||
| 1943 | - /// | ||
| 1944 | - /// Returns `(wrong_y, wrong_u, wrong_v, frames_total, frames_exact)`, or | ||
| 1945 | - /// `None` when the two sides are not byte-comparable at all (a size | ||
| 1946 | - /// mismatch, which is a different failure and must not read as "exact"). | ||
| 1947 | - /// `flip` flips ONE bit of the ORACLE's own bytes before comparing, so | ||
| 1948 | - /// [`the_counting_oracle_diff_detects_one_flipped_oracle_byte`] can prove | ||
| 1949 | - /// the comparison still reads the oracle on a stream that is now exact. | ||
| 1950 | - pub(super) fn count_rawvideo_diffs( | ||
| 1951 | - stream: &[u8], | ||
| 1952 | - name: &str, | ||
| 1953 | - flip: Option<usize>, | ||
| 1954 | - ) -> Option<(usize, usize, usize, usize, usize)> { | ||
| 1955 | - let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id())); | ||
| 1956 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1957 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 1958 | - let obu = dir.join("in.obu"); | ||
| 1959 | - std::fs::write(&obu, stream).expect("writing the stream"); | ||
| 1960 | - let raw = dir.join("aomdec.raw"); | ||
| 1961 | - let out = crate::tool_cache::cached_output_io(Command::new(aomdec_path()) | ||
| 1962 | - .args(["--codec=av1", "--rawvideo", "-o"]) | ||
| 1963 | - .arg(&raw) | ||
| 1964 | - .arg(&obu) | ||
| 1965 | - .stdin(Stdio::null()) | ||
| 1966 | - .stdout(Stdio::piped()) | ||
| 1967 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1968 | - .expect("aomdec failed to run"); | ||
| 1969 | - assert!( | ||
| 1970 | - out.status.success(), | ||
| 1971 | - "{name}: the oracle aomdec refused the stream: {}", | ||
| 1972 | - String::from_utf8_lossy(&out.stderr) | ||
| 1973 | - ); | ||
| 1974 | - let mut want = std::fs::read(&raw).expect("aomdec rawvideo output"); | ||
| 1975 | - if let Some(i) = flip { | ||
| 1976 | - assert!( | ||
| 1977 | - i < want.len(), | ||
| 1978 | - "{name}: flip index {i} is past the oracle's {} bytes", | ||
| 1979 | - want.len() | ||
| 1980 | - ); | ||
| 1981 | - want[i] ^= 0x01; | ||
| 1982 | - } | ||
| 1983 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1984 | - let bit_depth = stream_bit_depth(stream, name); | ||
| 1985 | - let decoded = decode_stream(stream).expect("decode for comparison"); | ||
| 1986 | - let ours = pack_rawvideo(&decoded, bit_depth, name); | ||
| 1987 | - if ours.len() != want.len() { | ||
| 1988 | - return None; | ||
| 1989 | - } | ||
| 1990 | - let bpp = if bit_depth == 8 { 1 } else { 2 }; | ||
| 1991 | - // lane-av1cmpframe: the plane split is PER FRAME and comes from each | ||
| 1992 | - // decoded frame's OWN plane lengths -- never from a formula, and | ||
| 1993 | - // never from the first picture. | ||
| 1994 | - // | ||
| 1995 | - // The first-picture form was wrong on every multi-frame stream: it | ||
| 1996 | - // compared a byte index against frame 0's thresholds forever, so | ||
| 1997 | - // every sample after frame 0's luma was attributed to the LAST | ||
| 1998 | - // plane. On `420_oddheight_320x236` (16 frames of 320x236 | ||
| 1999 | - // 4:2:0, whose frame is 113 280 bytes and whose V plane therefore | ||
| 2000 | - // holds 302 080 bytes in total) it reported `wrong_v = 330 673` -- | ||
crates/ec-av1/src/stream/tests/t01.rsdeleted+0 -4538
Diff too large; view file
| @@ -1,4538 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | -use super::gates_a::*; | ||
| 4 | -use crate::encode::{Picture as Pic, encode_key_frame_with_ctx, encode_sequence_with_ctx}; | ||
| 5 | -use crate::probe::run_with_stdin; | ||
| 6 | -use std::process::{Command, Stdio}; | ||
| 7 | - | ||
| 8 | - /// lane-av1422lift: THE 4:2:2 LIFT, in two pins. This test is the renamed, | ||
| 9 | - /// inverted replacement for `a_non_420_subsampled_sequence_header_is_ | ||
| 10 | - /// refused_by_name`, and the two fixtures replace that gate's fixture -- | ||
| 11 | - /// a hand-built profile-2 header bolted onto a 4:2:0 TILE from this | ||
| 12 | - /// crate's own encoder, which could never be inverted into an exactness | ||
| 13 | - /// claim no matter how the assert was flipped (class `refusal-lifted- | ||
| 14 | - /// without-a-gate`, and the risk study's R6). | ||
| 15 | - /// | ||
| 16 | - /// Both pins are REAL 4:2:2 streams from libaom's own writer over a | ||
| 17 | - /// y4m whose header line is `C422`, so every chroma symbol in them is a | ||
| 18 | - /// 4:2:2 chroma symbol. Provenance (both, verbatim, no other encoder): | ||
| 19 | - /// | ||
| 20 | - /// ```text | ||
| 21 | - /// aomenc --codec=av1 --profile=2 \ | ||
| 22 | - /// --input-chroma-subsampling-x=1 --input-chroma-subsampling-y=0 \ | ||
| 23 | - /// --passes=1 --end-usage=q --cq-level=24 --cpu-used=0 \ | ||
| 24 | - /// --threads=1 --row-mt=0 --obu -o <pin> <source.y4m> | ||
| 25 | - /// ``` | ||
| 26 | - /// | ||
| 27 | - /// * `422_key_64x64.obu` -- 755 bytes, sha256 | ||
| 28 | - /// `3c9396c9e42701d720419ec2cb5577387e305482df0cb150f7f0b965edeaaffc`, | ||
| 29 | - /// fnv1a64 `0x87fc569cf53bcbc6`. A single 64x64 8-bit KEY frame | ||
| 30 | - /// (`--limit=1 --kf-min-dist=0 --kf-max-dist=0`) over a | ||
| 31 | - /// hand-generated two-frame integer `C422` card source, the second | ||
| 32 | - /// source frame unused by the `--limit=1`. The smallest thing that can | ||
| 33 | - /// say "4:2:2 intra reconstructs". | ||
| 34 | - /// * `422_inter_160x128_3f.obu` -- 6522 bytes, sha256 | ||
| 35 | - /// `7b54834c18f5fdc0e8606a6dc5bf4ff368402417d87fcfc2ab9758e4e9164902`, | ||
| 36 | - /// fnv1a64 `0xf87eba3bf4fc2bb8`. Three 160x128 8-bit frames with a | ||
| 37 | - /// panning square | ||
| 38 | - /// (`--limit=3 --kf-min-dist=3 --kf-max-dist=3`, so frames 1 and 2 are | ||
| 39 | - /// INTER), over a three-frame integer `C422` card source whose square | ||
| 40 | - /// moves (6,4) -> (9,6) -> (12,8). This is what exercises the | ||
| 41 | - /// inter-predicted 4:2:2 chroma reference: a decoder that walked the | ||
| 42 | - /// key frame correctly and then predicted chroma from a 4:2:0-shaped | ||
| 43 | - /// reference passes the first pin and reds here. | ||
| 44 | - /// | ||
| 45 | - /// Both are asserted BYTE-EXACT against ffmpeg 8.1.3's own rawvideo of | ||
| 46 | - /// the same bytes at `yuv422p`, per plane and per frame, with the | ||
| 47 | - /// per-plane coefficient-unit census as the non-vacuity arm (see | ||
| 48 | - /// [`assert_422_stream_pixel_exact`]). A gate whose only assertion was | ||
| 49 | - /// `err.contains(REFUSAL)` would have passed unchanged on a tree where | ||
| 50 | - /// 4:2:2 decode was completely broken; that is what this replaces. | ||
| 51 | - #[test] | ||
| 52 | - fn a_real_422_key_frame_and_inter_sequence_decode_pixel_exact() { | ||
| 53 | - const NAME: &str = "a_real_422_key_frame_and_inter_sequence_decode_pixel_exact"; | ||
| 54 | - if !have_ffmpeg() { | ||
| 55 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 56 | - return; | ||
| 57 | - } | ||
| 58 | - let key = crate_pin("422_key_64x64.obu"); | ||
| 59 | - let key_stream = read_pin(&key, 755, 0x87fc569cf53bcbc6, NAME); | ||
| 60 | - let (units, _) = assert_422_stream_pixel_exact(NAME, &key_stream, 64, 64, 1, 8, true); | ||
| 61 | - let (l, u, v) = (units[0], units[1], units[2]); | ||
| 62 | - assert!( | ||
| 63 | - l > 0 && u > 0 && v > 0, | ||
| 64 | - "{NAME}: the key-frame pin walked no 4:2:2 chroma units [{l}, {u}, {v}]" | ||
| 65 | - ); | ||
| 66 | - | ||
| 67 | - let inter = crate_pin("422_inter_160x128_3f.obu"); | ||
| 68 | - let inter_stream = read_pin(&inter, 6522, 0xf87eba3bf4fc2bb8, NAME); | ||
| 69 | - let (units, _) = assert_422_stream_pixel_exact(NAME, &inter_stream, 160, 128, 3, 8, true); | ||
| 70 | - let (l, u, v) = (units[0], units[1], units[2]); | ||
| 71 | - assert!( | ||
| 72 | - u > 0 && v > 0, | ||
| 73 | - "{NAME}: the inter pin walked no 4:2:2 chroma units [{l}, {u}, {v}] -- the inter \ | ||
| 74 | - chroma reference path was never reached" | ||
| 75 | - ); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - /// lane-av1422lift: 4:2:2 at 12 bits, and 4:2:2 with superres, are the two | ||
| 79 | - /// cells the corpus had no coverage for at all (the risk study's R3 and | ||
| 80 | - /// R9: the sweep recipe passed no 12-bit depth and no `--superres-mode`, | ||
| 81 | - /// so every 4:2:2 measurement in the tree was 8- or 10-bit, none | ||
| 82 | - /// superres). Both are pinned and both are byte-exact here. | ||
| 83 | - /// | ||
| 84 | - /// `s422_12bit_160x128.obu` -- 9214 bytes, sha256 | ||
| 85 | - /// `eacc70f75c82ad7d795efbd0242aa4ee33db917b8c1a3570ebce2570ee8bc245`, | ||
| 86 | - /// fnv1a64 `0xa62b8e3fe6f60ae5`. 160x128, 12-bit, 3 frames, | ||
| 87 | - /// `yuv422p12le` per ffprobe, profile 2 ("Professional"). | ||
| 88 | - /// | ||
| 89 | - /// **Provenance is ffmpeg's libaom-av1 wrapper, not aomenc, and the | ||
| 90 | - /// reason is measured, not preferred.** aomenc's own 12-bit y4m path | ||
| 91 | - /// issues `AV1E_SET_CHROMA_SUBSAMPLING_X` (apps/aomenc.c:2272-2278, | ||
| 92 | - /// reached whenever the input is not 4:2:0 and the bit depth is 12) | ||
| 93 | - /// BEFORE `aom_codec_enc_config_set`, and on this libaom that control | ||
| 94 | - /// returns `AOM_CODEC_INTERNAL_ERROR` for any non-4:2:0 shape -- measured | ||
| 95 | - /// on four independently built trees | ||
| 96 | - /// (`~/.cache/aom-oracle`, `aom-affine`, `aom-oracle2`, `aom-oracle3`): | ||
| 97 | - /// `C422p12` and `C444p12` both die with "Failed to set chroma | ||
| 98 | - /// subsampling x", while `C420p12` and the 8-bit `C422`/`C444` both | ||
| 99 | - /// encode. It is not a 4:2:2-specific gap (12-bit 4:4:4 fails too) and | ||
| 100 | - /// not a 4:2:0 gap (12-bit 4:2:0 encodes). The same control succeeds at | ||
| 101 | - /// 8 bits, so the failure is the 12-bit configuration order, and the | ||
| 102 | - /// workaround is a wrapper that sets the codec config first. ffmpeg's | ||
| 103 | - /// libaom-av1 does exactly that: | ||
| 104 | - /// | ||
| 105 | - /// ```text | ||
| 106 | - /// ffmpeg -f lavfi -i "testsrc2=size=160x128:rate=1:duration=3" \ | ||
| 107 | - /// -pix_fmt yuv422p12le -c:v libaom-av1 -profile:v 2 -b:v 0 -crf 30 \ | ||
| 108 | - /// -cpu-used 8 -auto-alt-ref 0 -lag-in-frames 0 \ | ||
| 109 | - /// -strict experimental -f obu s422_12bit_160x128.obu | ||
| 110 | - /// ``` | ||
| 111 | - /// | ||
| 112 | - /// That is libaom's encoder either way -- ffmpeg links it and calls | ||
| 113 | - /// `aom_codec_encode` -- and the oracle side is ffmpeg's own | ||
| 114 | - /// `yuv422p12le` rawvideo decode of the same bytes, so the pin and the | ||
| 115 | - /// oracle come from the same library, which is the property that makes | ||
| 116 | - /// byte-exactness a claim about OUR decoder rather than about a | ||
| 117 | - /// disagreement between two encoders. | ||
| 118 | - /// | ||
| 119 | - /// `s422_superres_160x128.obu` -- 5304 bytes, sha256 | ||
| 120 | - /// `5852ff2c273cb773c4886762c6a6f2cce6e12065a690eb3a5ca2119c0b6f2957`, | ||
| 121 | - /// fnv1a64 `0x0789d1b2851b94ae`. 160x128, 8-bit, 3 frames, `--superres- | ||
| 122 | - /// mode=1` (fixed) over a `C422` testsrc2 source, encoded by the | ||
| 123 | - /// aomenc recipe above plus `--superres-mode=1`. Superres is the one | ||
| 124 | - /// 4:2:2 path whose output crop is `(round_ss(w,1) x round_ss(h,0))` at | ||
| 125 | - /// the UPSCALED size, and it had no 4:2:2 cell anywhere. | ||
| 126 | - #[test] | ||
| 127 | - fn a_real_422_12bit_and_superres_stream_decode_pixel_exact() { | ||
| 128 | - const NAME: &str = "a_real_422_12bit_and_superres_stream_decode_pixel_exact"; | ||
| 129 | - if !have_ffmpeg() { | ||
| 130 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 131 | - return; | ||
| 132 | - } | ||
| 133 | - let hbd = crate_pin("s422_12bit_160x128.obu"); | ||
| 134 | - let hbd_stream = read_pin(&hbd, 9214, 0xa62b8e3fe6f60ae5, NAME); | ||
| 135 | - assert_422_stream_pixel_exact(NAME, &hbd_stream, 160, 128, 3, 12, true); | ||
| 136 | - | ||
| 137 | - let sr = crate_pin("s422_superres_160x128.obu"); | ||
| 138 | - let sr_stream = read_pin(&sr, 5304, 0x0789d1b2851b94ae, NAME); | ||
| 139 | - assert_422_stream_pixel_exact(NAME, &sr_stream, 160, 128, 3, 8, true); | ||
| 140 | - } | ||
| 141 | - | ||
| 142 | - /// lane-av1lr422: a libaom-recipe 10-bit 4:2:2 stream with loop | ||
| 143 | - /// restoration ON, `s422_lr_10bit_200x120.obu` (129409 bytes, sha256 | ||
| 144 | - /// `5d6bc195934709390191c9ea8af167d385552c5b1330e8abd38f76a4416ba751`, | ||
| 145 | - /// fnv1a64 `0xc5d5489355fdc2df`), 200x120, 8 frames. It was REFUSED by | ||
| 146 | - /// the sub-8x8 plane-block check before the fix: the refusal was a | ||
| 147 | - /// parse desync, not a wrong check. The 32x8 / 8x32 rect4 general arm | ||
| 148 | - /// gathered the chroma dc-sign votes per mi instead of per 4-px chroma | ||
| 149 | - /// column, which desynced the coefficient contexts. Decodes byte-exact | ||
| 150 | - /// against ffmpeg libdav1d rawvideo. | ||
| 151 | - #[test] | ||
| 152 | - fn a_422_10bit_lr_stream_decodes_pixel_exact() { | ||
| 153 | - const NAME: &str = "a_422_10bit_lr_stream_decodes_pixel_exact"; | ||
| 154 | - if !have_ffmpeg() { | ||
| 155 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 156 | - return; | ||
| 157 | - } | ||
| 158 | - let p = crate_pin("s422_lr_10bit_200x120.obu"); | ||
| 159 | - let stream = read_pin(&p, 129409, 0xc5d5489355fdc2df, NAME); | ||
| 160 | - assert_422_stream_pixel_exact(NAME, &stream, 200, 120, 8, 10, true); | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - /// lane-av1odd440, CELL 1 of 2: `4:2:0 with an ODD luma dimension`, the | ||
| 164 | - /// cell `lanes/av1formatsweep.report.md` left as declared debt because | ||
| 165 | - /// "aomenc rounds a 4:2:0 frame's coded size DOWN to even, so no stream | ||
| 166 | - /// this recipe can produce codes an odd luma dimension". | ||
| 167 | - /// | ||
| 168 | - /// The pin, `420_odd65x65_key.obu` (2305 bytes, | ||
| 169 | - /// sha256 `66986019a561f81130f407f426c4379b25e6e80c2cd9ce47d517b3216e9a03cf`), | ||
| 170 | - /// is that missing stream, built offline by | ||
| 171 | - /// `examples/gen_coverage_cells.rs`: a 96x96 card padded to the block | ||
| 172 | - /// grid, coded by `encode::encode_key_frame_at_size` with a 65x65 frame | ||
| 173 | - /// header. Provenance: that example, `cargo run -p ec-av1 --example | ||
| 174 | - /// gen_coverage_cells -- crates/ec-av1/fixtures`; no encoder, no ffmpeg, | ||
| 175 | - /// no lavfi. | ||
| 176 | - /// | ||
| 177 | - /// WHY THE CELL IS NOT A RUBBER STAMP -- the chroma extent is where a | ||
| 178 | - /// floor shows. A 65-wide 4:2:0 frame has | ||
| 179 | - /// `ROUND_POWER_OF_TWO(65, 1) = 33` chroma columns (libaom | ||
| 180 | - /// `av1_common_plane_width`, `av1/common/av1_common_int.h`), not 32, so | ||
| 181 | - /// the decoded frame's own plane sizes, the rawvideo sample count and | ||
| 182 | - /// the oracle compare all move if `decode::round_ss` is floored. The | ||
| 183 | - /// mutation was run: flooring `round_ss` (`decode.rs:697`) turns the | ||
| 184 | - /// `round_ss` assert below red at 32 chroma columns and the oracle arm | ||
| 185 | - /// red at a 6273-byte raw against the oracle's 6403. The gate is | ||
| 186 | - /// therefore not green on a floored decoder, which is the whole content | ||
| 187 | - /// of this cell. | ||
| 188 | - /// | ||
| 189 | - /// The stream decodes PIXEL-EXACT against the instrumented `aomdec` | ||
| 190 | - /// (6403 raw bytes = 65*65 + 2*33*33, byte-identical), so the cell is a | ||
| 191 | - /// `y` and not a `–`. | ||
| 192 | - #[test] | ||
| 193 | - fn an_odd_luma_420_key_frame_decodes_pixel_exact() { | ||
| 194 | - const NAME: &str = "an_odd_luma_420_key_frame_decodes_pixel_exact"; | ||
| 195 | - let _gate_lock = lock_gate_counters(); | ||
| 196 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 197 | - .join("fixtures") | ||
| 198 | - .join("420_odd65x65_key.obu"); | ||
| 199 | - let stream = read_pin(&path, 2305, 0xf55645c4b139e8f7, NAME); | ||
| 200 | - | ||
| 201 | - // The stream's OWN header, read from its own bytes: an odd luma size | ||
| 202 | - // at 4:2:0, which is the cell. (Taken from the pin, not from the | ||
| 203 | - // gate's name -- class `helper-packs-u16-for-an-8-bit-stream`.) | ||
| 204 | - let mut probe = Av1Parser::new(); | ||
| 205 | - let mut pos = 0usize; | ||
| 206 | - while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 207 | - let obu = probe | ||
| 208 | - .parse_obu(&stream[pos..]) | ||
| 209 | - .unwrap_or_else(|e| panic!("{NAME}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 210 | - pos += obu.total_size; | ||
| 211 | - } | ||
| 212 | - let seq = probe | ||
| 213 | - .sequence_header() | ||
| 214 | - .unwrap_or_else(|| panic!("{NAME}: the pin carries no sequence header")); | ||
| 215 | - assert_eq!( | ||
| 216 | - (seq.max_frame_width, seq.max_frame_height), | ||
| 217 | - (65, 65), | ||
| 218 | - "{NAME}: the pin must declare an ODD luma size, it declares {}x{}", | ||
| 219 | - seq.max_frame_width, | ||
| 220 | - seq.max_frame_height | ||
| 221 | - ); | ||
| 222 | - assert_eq!( | ||
| 223 | - ( | ||
| 224 | - seq.color_config.subsampling_x, | ||
| 225 | - seq.color_config.subsampling_y | ||
| 226 | - ), | ||
| 227 | - (1, 1), | ||
| 228 | - "{NAME}: this cell is an odd luma SIZE at 4:2:0, not another chroma shape" | ||
| 229 | - ); | ||
| 230 | - | ||
| 231 | - // The decoded frame's own extents. This arm needs no oracle, and it | ||
| 232 | - // is the one a floored `round_ss` turns red. | ||
| 233 | - let frames = decode_stream(&stream).expect("the odd-luma 4:2:0 pin must decode"); | ||
| 234 | - assert_eq!(frames.len(), 1, "{NAME}: frame count"); | ||
| 235 | - let frame = &frames[0]; | ||
| 236 | - assert_eq!( | ||
| 237 | - (frame.width, frame.height), | ||
| 238 | - (65, 65), | ||
| 239 | - "{NAME}: decoded luma extent" | ||
| 240 | - ); | ||
| 241 | - assert_eq!(frame.y.len(), 65 * 65, "{NAME}: decoded luma sample count"); | ||
| 242 | - assert_eq!( | ||
| 243 | - (frame.u.len(), frame.v.len()), | ||
| 244 | - (33 * 33, 33 * 33), | ||
| 245 | - "{NAME}: a 65x65 4:2:0 frame has ROUND_POWER_OF_TWO(65,1) = 33 chroma \ | ||
| 246 | - columns and rows -- 32 means the extent was floored" | ||
| 247 | - ); | ||
| 248 | - | ||
| 249 | - if !aomdec_available(NAME) { | ||
| 250 | - return; | ||
| 251 | - } | ||
| 252 | - assert_rawvideo_matches(&path, &stream, NAME, 1, 8); | ||
| 253 | - } | ||
| 254 | - | ||
| 255 | - /// lane-av1odd440, CELL 2 of 2: the `4:4:0 (ss 0,1)` row, which the same | ||
| 256 | - /// report called "unmeasured and unproducible by recipe". It is neither | ||
| 257 | - /// unmeasured nor unproducible: it is NOT A CELL AT ALL. | ||
| 258 | - /// | ||
| 259 | - /// `subsampling_y` is coded only when `subsampling_x` is 1 (spec 5.5.2 | ||
| 260 | - /// `color_config`), so a sequence header can carry exactly three chroma | ||
| 261 | - /// shapes -- 4:2:0 `(1,1)`, 4:2:2 `(1,0)`, 4:4:4 `(0,0)` -- and never | ||
| 262 | - /// `(0,1)`. libaom says so in both directions: the reader leaves | ||
| 263 | - /// `subsampling_y = 0` when `subsampling_x` is 0 | ||
| 264 | - /// (`av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`) and | ||
| 265 | - /// the writer ASSERTS it -- `assert(seq_params->subsampling_y == 0 && | ||
| 266 | - /// "4:4:0 subsampling not allowed in AV1")`, `av1/encoder/bitstream.c: | ||
| 267 | - /// 2463-2465`. So there is no stream to decode, no fixture to pin that | ||
| 268 | - /// a decoder could be handed, and no oracle to compare against: a | ||
| 269 | - /// 4:4:0 row in a coverage matrix is a matrix bug, not a decoder gap. | ||
| 270 | - /// | ||
| 271 | - /// What is pinned, then, is the claim itself, in three arms that a | ||
| 272 | - /// mutation turns red: | ||
| 273 | - /// | ||
| 274 | - /// 1. WRITER: every `(profile, bit_depth, mono, colour description, | ||
| 275 | - /// requested subsampling)` combination a `color_config` can carry is | ||
| 276 | - /// written by this crate's own writer and read back by this crate's | ||
| 277 | - /// own reader. The reachable set is asserted to be EXACTLY | ||
| 278 | - /// `{(1,1), (1,0), (0,0)}` -- each legal shape present, `(0,1)` | ||
| 279 | - /// absent -- and, on the BYTES rather than on the round trip, the two | ||
| 280 | - /// requests that differ only in `subsampling_y` must write identical | ||
| 281 | - /// headers whenever `subsampling_x` is 0. A sweep that silently wrote | ||
| 282 | - /// nothing would pass, so the count of combinations actually written | ||
| 283 | - /// and read is asserted too. | ||
| 284 | - /// 2. READER: the one byte that carries `subsampling_x` is found by | ||
| 285 | - /// diffing an `(0,0)` header against an `(1,0)` one, and then all 256 | ||
| 286 | - /// values of that byte are fed back through the reader. Not one of the | ||
| 287 | - /// headers that parse reads back `(0,1)`, because the reader never | ||
| 288 | - /// reads a `subsampling_y` bit in that position. A reader that always | ||
| 289 | - /// read a second bit would produce `(0,1)` at the one value that sets | ||
| 290 | - /// both bits. | ||
| 291 | - /// 3. THE PIN: `440_request_is_422.obu` (2014 bytes, sha256 | ||
| 292 | - /// `4afaa5470c4e010d9d970086ef514680adfe801a579e4deeec582f52d13c5e7c`, | ||
| 293 | - /// fnv1a64 `0x98a1378df976253d`) is what this crate's writer produces | ||
| 294 | - /// when it is handed `subsampling (0,1)` at profile 2 -- profile 2 | ||
| 295 | - /// below 12 bits is 4:2:2 and codes no subsampling bit at all, so the | ||
| 296 | - /// request lands on `(1,0)`. The pin is asserted to read back `(1,0)`, | ||
| 297 | - /// NOT `(0,1)`. Its frame OBU is a 4:2:0 key frame's, so the pin is a | ||
| 298 | - /// HEADER witness, not a decodable 4:2:2 stream -- nothing here claims | ||
| 299 | - /// pixels for it. Provenance: `examples/gen_coverage_cells.rs`, `cargo | ||
| 300 | - /// run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures`. | ||
| 301 | - /// | ||
| 302 | - /// lane-av1422lift: this arm used to end "and the decoder is asserted | ||
| 303 | - /// to refuse it by name, which is the honest outcome for the shape a | ||
| 304 | - /// 4:4:0 request actually yields". That was honest only because the | ||
| 305 | - /// decoder refused EVERY (1,0) header -- the assertion was about the | ||
| 306 | - /// guard, not about these bytes. With 4:2:2 admitted, refusing these | ||
| 307 | - /// bytes would be wrong and accepting them without comment would be | ||
| 308 | - /// worse, so the arm now asserts the one thing that IS true of them: | ||
| 309 | - /// the SEQUENCE HEADER, not the tile, fixes the decode's chroma | ||
| 310 | - /// geometry. The pixel claim moved to genuinely 4:2:2 pins. | ||
| 311 | - #[test] | ||
| 312 | - fn the_440_cell_is_not_a_codable_chroma_shape() { | ||
| 313 | - const NAME: &str = "the_440_cell_is_not_a_codable_chroma_shape"; | ||
| 314 | - let _gate_lock = lock_gate_counters(); | ||
| 315 | - let header_obu = |profile: u8, color: ec_av1_syntax::ColorConfig| -> Vec<u8> { | ||
| 316 | - let (mut seq, _header) = crate::encode::key_frame_headers_colour(64, 64, 100, color) | ||
| 317 | - .expect("the header builders accept a colour config"); | ||
| 318 | - seq.seq_profile = profile; | ||
| 319 | - crate::sequence::sequence_header_obu(&seq).expect("writing the sequence header") | ||
| 320 | - }; | ||
| 321 | - let shape_of = |obu: &[u8]| -> Option<(u8, u8)> { | ||
| 322 | - let mut parser = Av1Parser::new(); | ||
| 323 | - let parsed = parser.parse_obu(obu).ok()?; | ||
| 324 | - if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) { | ||
| 325 | - return None; | ||
| 326 | - } | ||
| 327 | - let seq = parser.sequence_header()?; | ||
| 328 | - Some(( | ||
| 329 | - seq.color_config.subsampling_x, | ||
| 330 | - seq.color_config.subsampling_y, | ||
| 331 | - )) | ||
| 332 | - }; | ||
| 333 | - | ||
| 334 | - // ---- arm 1: the writer's whole reachable space -------------------- | ||
| 335 | - let mut reachable: std::collections::BTreeSet<(u8, u8)> = Default::default(); | ||
| 336 | - let mut asked = 0usize; | ||
| 337 | - for profile in [0u8, 1, 2] { | ||
| 338 | - for bit_depth in [8u8, 10, 12] { | ||
| 339 | - for mono_chrome in [false, true] { | ||
| 340 | - // Profile 1 is 4:4:4 and codes no mono bit; asking for | ||
| 341 | - // monochrome there is refused by the writer, which is | ||
| 342 | - // not a chroma shape and not this gate's subject. | ||
| 343 | - if mono_chrome && profile == 1 { | ||
| 344 | - continue; | ||
| 345 | - } | ||
| 346 | - for (label, (cp, tc, mc)) in [ | ||
| 347 | - ("unspecified", (2u8, 2u8, 2u8)), | ||
| 348 | - ("bt709", (1u8, 1u8, 1u8)), | ||
| 349 | - ("srgb", (1u8, 13u8, 0u8)), | ||
| 350 | - ] { | ||
| 351 | - for sx in [0u8, 1] { | ||
| 352 | - for sy in [0u8, 1] { | ||
| 353 | - let color = ec_av1_syntax::ColorConfig { | ||
| 354 | - bit_depth, | ||
| 355 | - mono_chrome, | ||
| 356 | - num_planes: if mono_chrome { 1 } else { 3 }, | ||
| 357 | - color_primaries: cp, | ||
| 358 | - transfer_characteristics: tc, | ||
| 359 | - matrix_coefficients: mc, | ||
| 360 | - color_range: false, | ||
| 361 | - subsampling_x: sx, | ||
| 362 | - subsampling_y: sy, | ||
| 363 | - chroma_sample_position: | ||
| 364 | - ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 365 | - separate_uv_delta_q: false, | ||
| 366 | - }; | ||
| 367 | - asked += 1; | ||
| 368 | - let obu = header_obu(profile, color); | ||
| 369 | - // The WRITER half of the claim, measured on the | ||
| 370 | - // bytes rather than on a round trip: with | ||
| 371 | - // `subsampling_x == 0` the spec codes no | ||
| 372 | - // `subsampling_y` bit at all, so the two | ||
| 373 | - // requests that differ ONLY in `subsampling_y` | ||
| 374 | - // must produce byte-identical headers. A | ||
| 375 | - // writer that emitted the bit anyway (the | ||
| 376 | - // mutation libaom's own `assert` exists to | ||
| 377 | - // catch, av1/encoder/bitstream.c:2467-2468) fails | ||
| 378 | - // here -- and note it does NOT fail the | ||
| 379 | - // round trip, because the reader then absorbs | ||
| 380 | - // the extra bit as `separate_uv_delta_q`. | ||
| 381 | - if sx == 0 { | ||
| 382 | - let mut other = color; | ||
| 383 | - other.subsampling_y = 1; | ||
| 384 | - assert_eq!( | ||
| 385 | - obu, | ||
| 386 | - header_obu(profile, other), | ||
| 387 | - "{NAME}: a (0,0) and a (0,1) request wrote DIFFERENT \ | ||
| 388 | - bytes at profile {profile}, {bit_depth}-bit, mono \ | ||
| 389 | - {mono_chrome}, {label} -- `subsampling_y` must not be \ | ||
| 390 | - coded at all when `subsampling_x` is 0" | ||
| 391 | - ); | ||
| 392 | - } | ||
| 393 | - if let Some(got) = shape_of(&obu) { | ||
| 394 | - assert_ne!( | ||
| 395 | - got, | ||
| 396 | - (0, 1), | ||
| 397 | - "{NAME}: a 4:4:0 shape came back out of the writer at \ | ||
| 398 | - profile {profile}, {bit_depth}-bit, mono {mono_chrome}, \ | ||
| 399 | - {label}, asked for ({sx},{sy}) -- libaom forbids this \ | ||
| 400 | - shape outright (av1/encoder/bitstream.c:2467-2468)" | ||
| 401 | - ); | ||
| 402 | - reachable.insert(got); | ||
| 403 | - } | ||
| 404 | - } | ||
| 405 | - } | ||
| 406 | - } | ||
| 407 | - } | ||
| 408 | - } | ||
| 409 | - } | ||
| 410 | - assert!( | ||
| 411 | - asked >= 100 && reachable.len() == 3, | ||
| 412 | - "{NAME}: the sweep asked {asked} combinations and reached {} shapes -- it must reach \ | ||
| 413 | - all three legal ones, or it is not measuring the space", | ||
| 414 | - reachable.len() | ||
| 415 | - ); | ||
| 416 | - assert_eq!( | ||
| 417 | - reachable, | ||
| 418 | - std::collections::BTreeSet::from([(0u8, 0u8), (1u8, 0u8), (1u8, 1u8)]), | ||
| 419 | - "{NAME}: the chroma shapes a `color_config` can code are exactly 4:4:4 (0,0), 4:2:2 \ | ||
| 420 | - (1,0) and 4:2:0 (1,1)" | ||
| 421 | - ); | ||
| 422 | - | ||
| 423 | - // ---- arm 2: the reader's bit at that position ---------------------- | ||
| 424 | - // Profile 2 at 12 bits is the only place BOTH subsampling bits are | ||
| 425 | - // coded, so it is where a hand-built header could try to smuggle a | ||
| 426 | - // `subsampling_y`. Find the byte that carries `subsampling_x` by | ||
| 427 | - // diffing the two shapes, then read back all eight of its values. | ||
| 428 | - let at_444 = |sx: u8| { | ||
| 429 | - let color = ec_av1_syntax::ColorConfig { | ||
| 430 | - bit_depth: 12, | ||
| 431 | - subsampling_x: sx, | ||
| 432 | - subsampling_y: 0, | ||
| 433 | - chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 434 | - ..ec_av1_syntax::ColorConfig::default() | ||
| 435 | - }; | ||
| 436 | - let (mut seq, _h) = | ||
| 437 | - crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 438 | - seq.seq_profile = 2; | ||
| 439 | - let obu = crate::sequence::sequence_header_obu(&seq).unwrap(); | ||
| 440 | - let mut parser = Av1Parser::new(); | ||
| 441 | - parser.parse_obu(&obu).expect("the profile-2 header parses"); | ||
| 442 | - let seq = parser.sequence_header().expect("sequence header"); | ||
| 443 | - ( | ||
| 444 | - seq.color_config.subsampling_x, | ||
| 445 | - seq.color_config.subsampling_y, | ||
| 446 | - ) | ||
| 447 | - }; | ||
| 448 | - assert_eq!(at_444(0), (0, 0), "{NAME}: the sx=0 header is 4:4:4"); | ||
| 449 | - assert_eq!(at_444(1), (1, 0), "{NAME}: the sx=1 header is 4:2:2"); | ||
| 450 | - let base = { | ||
| 451 | - let color = ec_av1_syntax::ColorConfig { | ||
| 452 | - bit_depth: 12, | ||
| 453 | - subsampling_x: 0, | ||
| 454 | - subsampling_y: 0, | ||
| 455 | - chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 456 | - ..ec_av1_syntax::ColorConfig::default() | ||
| 457 | - }; | ||
| 458 | - let (mut seq, _h) = | ||
| 459 | - crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 460 | - seq.seq_profile = 2; | ||
| 461 | - crate::sequence::sequence_header_obu(&seq).unwrap() | ||
| 462 | - }; | ||
| 463 | - let other = { | ||
| 464 | - let color = ec_av1_syntax::ColorConfig { | ||
| 465 | - bit_depth: 12, | ||
| 466 | - subsampling_x: 1, | ||
| 467 | - subsampling_y: 0, | ||
| 468 | - chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 469 | - ..ec_av1_syntax::ColorConfig::default() | ||
| 470 | - }; | ||
| 471 | - let (mut seq, _h) = | ||
| 472 | - crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 473 | - seq.seq_profile = 2; | ||
| 474 | - crate::sequence::sequence_header_obu(&seq).unwrap() | ||
| 475 | - }; | ||
| 476 | - assert_eq!( | ||
| 477 | - base.len(), | ||
| 478 | - other.len(), | ||
| 479 | - "{NAME}: the two headers must differ in place" | ||
| 480 | - ); | ||
| 481 | - let byte_at = base | ||
| 482 | - .iter() | ||
| 483 | - .zip(&other) | ||
| 484 | - .position(|(a, b)| a != b) | ||
| 485 | - .expect("the two shapes must differ somewhere"); | ||
| 486 | - // Every value of that byte is fed back through the reader -- it is the | ||
| 487 | - // LAST payload byte, so the bits a smuggled `subsampling_y` would come | ||
| 488 | - // from are in it too (spec 5.5.2 always codes `separate_uv_delta_q` | ||
| 489 | - // after the subsampling pair, and the payload is padded out to the | ||
| 490 | - // byte with `trailing_bits`). A header that stops parsing is not a | ||
| 491 | - // 4:4:0 shape and cannot be counted as one; the sweep asserts how | ||
| 492 | - // many DID parse, so a sweep that quietly parsed nothing is not | ||
| 493 | - // evidence of anything. | ||
| 494 | - let mut parsed_headers = 0usize; | ||
| 495 | - for value in 0..256u16 { | ||
| 496 | - let mut poked = base.clone(); | ||
| 497 | - poked[byte_at] = value as u8; | ||
| 498 | - let mut parser = Av1Parser::new(); | ||
| 499 | - let Ok(parsed) = parser.parse_obu(&poked) else { | ||
| 500 | - continue; | ||
| 501 | - }; | ||
| 502 | - if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) { | ||
| 503 | - continue; | ||
| 504 | - } | ||
| 505 | - let seq = parser.sequence_header().expect("sequence header"); | ||
| 506 | - parsed_headers += 1; | ||
| 507 | - assert_ne!( | ||
| 508 | - ( | ||
| 509 | - seq.color_config.subsampling_x, | ||
| 510 | - seq.color_config.subsampling_y | ||
| 511 | - ), | ||
| 512 | - (0, 1), | ||
| 513 | - "{NAME}: payload byte {byte_at} = {value:#04x} read back as 4:4:0 -- the reader \ | ||
| 514 | - took a `subsampling_y` bit that spec 5.5.2 does not code when `subsampling_x` \ | ||
| 515 | - is 0" | ||
| 516 | - ); | ||
| 517 | - } | ||
| 518 | - assert!( | ||
| 519 | - parsed_headers > 100, | ||
| 520 | - "{NAME}: only {parsed_headers} of the 256 poked headers parsed -- the sweep is not \ | ||
| 521 | - measuring the reader" | ||
| 522 | - ); | ||
| 523 | - | ||
| 524 | - // ---- arm 3: the pinned bytes a 4:4:0 request produces -------------- | ||
| 525 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 526 | - .join("fixtures") | ||
| 527 | - .join("440_request_is_422.obu"); | ||
| 528 | - let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); | ||
| 529 | - let mut parser = Av1Parser::new(); | ||
| 530 | - let obu = parser | ||
| 531 | - .parse_obu(&pinned) | ||
| 532 | - .unwrap_or_else(|e| panic!("{NAME}: the pin's first OBU does not parse: {e:?}")); | ||
| 533 | - assert!( | ||
| 534 | - matches!(obu.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)), | ||
| 535 | - "{NAME}: the pin must start with its sequence header" | ||
| 536 | - ); | ||
| 537 | - let seq = parser.sequence_header().expect("the pin's sequence header"); | ||
| 538 | - assert_eq!( | ||
| 539 | - ( | ||
| 540 | - seq.color_config.subsampling_x, | ||
| 541 | - seq.color_config.subsampling_y | ||
| 542 | - ), | ||
| 543 | - (1, 0), | ||
| 544 | - "{NAME}: the pin is what a 4:4:0 request at profile 2 produces -- 4:2:2 (1,0). If this \ | ||
| 545 | - ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ | ||
| 546 | - format." | ||
| 547 | - ); | ||
| 548 | - // lane-av1unwritten: lane-av1422lift replaced the old 4:2:2 header | ||
| 549 | - // refusal with "it decodes, and the decoded chroma planes are 32x64". | ||
| 550 | - // That was the wrong contract for THIS pin: its frame OBU is a 4:2:0 | ||
| 551 | - // key frame's, so at 4:2:2 its partition symbols name subsizes with no | ||
| 552 | - // chroma plane block, which libaom rejects as a corrupt frame | ||
| 553 | - // ("Block size 8x16 invalid with this subsampling mode", | ||
| 554 | - // decodeframe.c:1456) and `aomdec` does. The replacement is the | ||
| 555 | - // REFUSAL, by that rule. | ||
| 556 | - // | ||
| 557 | - // The pin's remaining job is unchanged and still worth saying: it | ||
| 558 | - // proves a 4:4:0 REQUEST at profile 2 lands on 4:2:2 (1,0), i.e. that | ||
| 559 | - // `the_440_cell_is_not_a_codable_chroma_shape`'s claim is still true. | ||
| 560 | - let err = decode_stream(&pinned).err().unwrap_or_else(|| { | ||
| 561 | - panic!( | ||
| 562 | - "{NAME}: the pin is a 4:2:2 header over a 4:2:0 tile -- libaom refuses it \ | ||
| 563 | - (aomdec: \"Block size 8x16 invalid with this subsampling mode\"), and so \ | ||
| 564 | - must we" | ||
| 565 | - ) | ||
| 566 | - }); | ||
| 567 | - assert!( | ||
| 568 | - err.to_string() | ||
| 569 | - .contains("invalid with this subsampling mode"), | ||
| 570 | - "{NAME}: the refusal must name libaom's rule, got: {err}" | ||
| 571 | - ); | ||
| 572 | - // The pixels this pin never had: the sibling gate | ||
| 573 | - // `a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt` | ||
| 574 | - // pins the refusal plus a genuine 4:2:2 positive control, and every | ||
| 575 | - // real 4:2:2 exactness claim lives on genuinely 4:2:2 pins in this | ||
| 576 | - // file. | ||
| 577 | - } | ||
| 578 | - | ||
| 579 | - /// lane-av1unwritten: this pin is a MISSING REFUSAL, not a pixel defect. | ||
| 580 | - /// | ||
| 581 | - /// `440_request_is_422.obu` is a 4:2:2 sequence header wrapped around a | ||
| 582 | - /// 4:2:0 key frame's tile, so the tile's partition symbols make subsizes | ||
| 583 | - /// (8x16 among them) that have NO chroma plane block at ss (1,0). libaom | ||
| 584 | - /// refuses exactly that, before descending into the subsize: | ||
| 585 | - /// | ||
| 586 | - /// ```text | ||
| 587 | - /// $ aomdec --rawvideo -o /dev/null fixtures/440_request_is_422.obu | ||
| 588 | - /// Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 589 | - /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 590 | - /// ``` | ||
| 591 | - /// | ||
| 592 | - /// (`av1/decoder/decodeframe.c:1449-1458`, | ||
| 593 | - /// `get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID` -> | ||
| 594 | - /// `AOM_CODEC_CORRUPT_FRAME`.) We walked those subsizes instead, and the | ||
| 595 | - /// first version of this lane misread the downstream symptom -- a chroma | ||
| 596 | - /// plane block covered by a square unit, whole 4x4 blocks left unwritten, | ||
| 597 | - /// and a `EC_AV1_FINAL_DUMP` hash that CHANGED RUN TO RUN because the | ||
| 598 | - /// unwritten samples were uninitialised plane memory. | ||
| 599 | - /// | ||
| 600 | - /// The contract pinned here is the one libaom has: the pin REFUSES, by a | ||
| 601 | - /// named error that says which shape and which subsampling mode. The | ||
| 602 | - /// positive control is a genuinely 4:2:2 pin, which must still decode -- | ||
| 603 | - /// so this gate cannot pass by refusing everything. | ||
| 604 | - #[test] | ||
| 605 | - fn a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt() { | ||
| 606 | - const NAME: &str = "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt"; | ||
| 607 | - let _gate_lock = lock_gate_counters(); | ||
| 608 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 609 | - .join("fixtures") | ||
| 610 | - .join("440_request_is_422.obu"); | ||
| 611 | - let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); | ||
| 612 | - // The refusal this gate PROVES, quoted whole -- the anchor the PROVEN | ||
| 613 | - // row in `refusal_inventory.rs` is checked against inside this body's | ||
| 614 | - // own bounds. The assertion below used to match only the libaom | ||
| 615 | - // citation *inside* the string, so a reworded guard kept passing for | ||
| 616 | - // as long as it kept citing `decodeframe.c:1456`: the half that names | ||
| 617 | - // OUR shapes (4x8 / 8x16 / 16x4, and 8x4 at 4:4:0) was never pinned. | ||
| 618 | - const REFUSAL: &str = "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma \ | ||
| 619 | - plane block at this frame's subsampling mode (libaom: \"Block \ | ||
| 620 | - size %dx%d invalid with this subsampling mode\", \ | ||
| 621 | - av1/decoder/decodeframe.c:1456, refusing by the same rule)"; | ||
| 622 | - let err = decode_stream(&pinned) | ||
| 623 | - .err() | ||
| 624 | - .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); | ||
| 625 | - let msg = err.to_string(); | ||
| 626 | - assert!( | ||
| 627 | - msg.contains("invalid with this subsampling mode"), | ||
| 628 | - "{NAME}: the refusal must name the rule it refuses by (libaom's own wording), got: \ | ||
| 629 | - {msg}" | ||
| 630 | - ); | ||
| 631 | - assert!( | ||
| 632 | - msg.contains(REFUSAL), | ||
| 633 | - "{NAME}: the refusal must be this decoder's OWN string, whole -- the guard's wording \ | ||
| 634 | - drifted, so the PROVEN row no longer names what fires, got: {msg}" | ||
| 635 | - ); | ||
| 636 | - // Positive control: a real 4:2:2 stream must still decode, so the gate | ||
| 637 | - // cannot pass by refusing everything. | ||
| 638 | - let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 639 | - .join("fixtures") | ||
| 640 | - .join("422_key_64x64.obu"); | ||
| 641 | - let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) | ||
| 642 | - .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); | ||
| 643 | - assert!( | ||
| 644 | - !ok.is_empty(), | ||
| 645 | - "{NAME}: the 4:2:2 control decoded no frames" | ||
| 646 | - ); | ||
| 647 | - } | ||
| 648 | - | ||
| 649 | - /// lane-av1subsizesweep: the FRAME-EDGE walk of a BLOCK_INVALID subsize, | ||
| 650 | - /// pinned. This is the one install site the partition-symbol guards missed, | ||
| 651 | - /// and the sibling pin above cannot see it -- that pin's 8x16 comes from a | ||
| 652 | - /// 16x16-level `PARTITION_VERT_B` (an interior AB strip, refused at | ||
| 653 | - /// decode.rs:36472), while this pin's comes from the key-frame 16-level | ||
| 654 | - /// FRAME-EDGE arm, which is not a `dec.symbol(` site at all: it reads one | ||
| 655 | - /// gathered bit with `dec.symbol_fixed(&gather(..))` and dispatches | ||
| 656 | - /// `decode_leaf_rect` straight off it. | ||
| 657 | - /// | ||
| 658 | - /// `422_header_edge16_walk.obu` (128 bytes, sha256 | ||
| 659 | - /// `e8ab2bb229896f796cdec4d2cb383b41f057ef8d364da30f160a3f55a452657f`, | ||
| 660 | - /// fnv1a64 `0xcfa2394ebe1f7764`) is a 4:2:2 sequence header over a 4:2:0 | ||
| 661 | - /// key frame's tile, at 88x64. Width 88 is 8 mod 16, so the last 16x16 | ||
| 662 | - /// column block is COLUMN-short and the frame-edge arm fires; height 64 is | ||
| 663 | - /// 16-aligned, so the ROW is not short and the both-cut arm is not taken. | ||
| 664 | - /// The gathered bit names `PARTITION_VERT`, so the strip is `BLOCK_8X16`. | ||
| 665 | - /// | ||
| 666 | - /// libaom's own verdict, which is the rule this pin pins: | ||
| 667 | - /// | ||
| 668 | - /// ```text | ||
| 669 | - /// $ aomdec --rawvideo -o /dev/null fixtures/422_header_edge16_walk.obu | ||
| 670 | - /// Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 671 | - /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 672 | - /// ``` | ||
| 673 | - /// | ||
| 674 | - /// What makes this pin different from every other refusal gate in this file | ||
| 675 | - /// is that the 8x16 is the ONLY offending subsize in the stream. Measured | ||
| 676 | - /// over a 260-candidate sweep (4 card textures x 5 quantizers x 13 declared | ||
| 677 | - /// widths), this is the one candidate whose decode with the guard removed | ||
| 678 | - /// SUCCEEDS: with the `refuse_invalid_subsize` at decode.rs:37098 deleted, | ||
| 679 | - /// this decoder returned a full 88x64 picture where libaom refuses the | ||
| 680 | - /// frame. So the guard is not a redundant second refusal here -- it is the | ||
| 681 | - /// only thing between a corrupt frame and a plausible-looking decode. | ||
| 682 | - #[test] | ||
| 683 | - fn a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused() { | ||
| 684 | - const NAME: &str = | ||
| 685 | - "a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused"; | ||
| 686 | - let _gate_lock = lock_gate_counters(); | ||
| 687 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 688 | - .join("fixtures") | ||
| 689 | - .join("422_header_edge16_walk.obu"); | ||
| 690 | - let pinned = read_pin(&path, 128, 0xcfa2394ebe1f7764, NAME); | ||
| 691 | - // The shape must be the one this lane's arm carries: if the pin ever | ||
| 692 | - // stops being an 8x16 strip the refusal is coming from somewhere else | ||
| 693 | - // and this gate is measuring the wrong thing. | ||
| 694 | - assert!( | ||
| 695 | - !crate::decode::chroma_plane_block_codable(8, 16, 1, 0), | ||
| 696 | - "{NAME}: BLOCK_8X16 must be BLOCK_INVALID at 4:2:2 -- this gate's whole \ | ||
| 697 | - subject is `av1_ss_size_lookup[BLOCK_8X16][1][0] == BLOCK_INVALID`" | ||
| 698 | - ); | ||
| 699 | - assert!( | ||
| 700 | - crate::decode::chroma_plane_block_codable(16, 8, 1, 0), | ||
| 701 | - "{NAME}: the 16x8 mirror MUST stay legal at 4:2:2 (BLOCK_8X8) -- it is what \ | ||
| 702 | - keeps the new guard from refusing the sibling arm's strip" | ||
| 703 | - ); | ||
| 704 | - let err = decode_stream(&pinned) | ||
| 705 | - .err() | ||
| 706 | - .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); | ||
| 707 | - let msg = err.to_string(); | ||
| 708 | - assert!( | ||
| 709 | - msg.contains("invalid with this subsampling mode"), | ||
| 710 | - "{NAME}: the refusal must name libaom's rule (its own wording), got: {msg}" | ||
| 711 | - ); | ||
| 712 | - // Positive control: a genuine 4:2:2 stream must still decode, so this | ||
| 713 | - // gate cannot pass by refusing everything. | ||
| 714 | - let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 715 | - .join("fixtures") | ||
| 716 | - .join("422_key_64x64.obu"); | ||
| 717 | - let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) | ||
| 718 | - .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); | ||
| 719 | - assert!( | ||
| 720 | - !ok.is_empty(), | ||
| 721 | - "{NAME}: the 4:2:2 control decoded no frames" | ||
| 722 | - ); | ||
| 723 | - } | ||
| 724 | - | ||
| 725 | - /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | ||
| 726 | - /// as fixtures (`git add -f`; `fixtures/` is gitignored). | ||
| 727 | - /// | ||
| 728 | - /// `422_allskip_2f.obu` (62 bytes) is a 128x128 profile-2 key frame plus | ||
| 729 | - /// its all-skip first inter frame: the pre-port decoder read phantom | ||
| 730 | - /// coefficient units in the inter frame and then panicked in | ||
| 731 | - /// `reconstruct_mc_rect` on a full-height 4:2:2 chroma rect. At this | ||
| 732 | - /// lane's HEAD the block-half port's per-axis plane-block model already | ||
| 733 | - /// has it entropy-locked (all 20 key-frame coefficient units pair | ||
| 734 | - /// rng-for-rng with the instrumented oracle, the inter frame reads | ||
| 735 | - /// zero, matching the oracle) and pixel-exact vs aomdec. | ||
| 736 | - /// | ||
| 737 | - /// `422_sb128_3f.obu` (12543 bytes) carries the f2 128x128 | ||
| 738 | - /// `PARTITION_NONE` non-skip inter block: the mu-chunk chroma walk cut | ||
| 739 | - /// each chunk's 32x64 chroma into a `chroma_side`-square 64x64 (twice | ||
| 740 | - /// the units the oracle codes), indexed the prediction buffer at the | ||
| 741 | - /// square `chroma_side` instead of `chroma_stride` (the empty-slice | ||
| 742 | - /// panic at `push_mc_rect_tx`'s densify), and the reference plane | ||
| 743 | - /// resolution guessed every non-4:4:4 picture quarter-height, so the | ||
| 744 | - /// bottom mu-chunk row predicted from a clamped row-63 edge. All fixed; | ||
| 745 | - /// both witnesses decode pixel-exact vs aomdec on the lane's local | ||
| 746 | - /// `EC_AV1_ALLOW_422_PROBE` patch-run-restore build (recipe and measured | ||
| 747 | - /// numbers in `lanes/av1422bigblock.report.md`). | ||
| 748 | - /// | ||
| 749 | - /// lane-av1422lift: `decode_stream` no longer refuses 4:2:2 at the | ||
| 750 | - /// sequence header, so this gate stops being a refusal contract and | ||
| 751 | - /// becomes the one it should have been: BOTH pins, byte-pinned AND | ||
| 752 | - /// byte-exact against ffmpeg, with the per-plane coefficient-unit census | ||
| 753 | - /// as the non-vacuity arm. The pins are unchanged and still load-bearing | ||
| 754 | - /// (size + fnv1a64); only the assertion moved. | ||
| 755 | - #[test] | ||
| 756 | - fn the_pinned_422_bigblock_witnesses_decode_pixel_exact() { | ||
| 757 | - const NAME: &str = "the_pinned_422_bigblock_witnesses_decode_pixel_exact"; | ||
| 758 | - if !have_ffmpeg() { | ||
| 759 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 760 | - return; | ||
| 761 | - } | ||
| 762 | - for (file, bytes, fp, frames, require_coded) in [ | ||
| 763 | - ( | ||
| 764 | - "422_allskip_2f.obu", | ||
| 765 | - 62usize, | ||
| 766 | - 0x7e4d69d3c728c55f_u64, | ||
| 767 | - 2usize, | ||
| 768 | - false, | ||
| 769 | - ), | ||
| 770 | - ("422_sb128_3f.obu", 12543, 0x5171e0aab8000da7, 3, true), | ||
| 771 | - ] { | ||
| 772 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 773 | - .join("fixtures") | ||
| 774 | - .join(file); | ||
| 775 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 776 | - panic!( | ||
| 777 | - "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 778 | - path.display() | ||
| 779 | - ) | ||
| 780 | - }); | ||
| 781 | - assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 782 | - assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 783 | - let (_units, coded_delta) = | ||
| 784 | - assert_422_stream_pixel_exact(NAME, &data, 128, 128, frames, 8, require_coded); | ||
| 785 | - if !require_coded { | ||
| 786 | - // `422_allskip_2f.obu` is named for what it does NOT code, and | ||
| 787 | - // the pre-port defect was exactly that: the decoder read | ||
| 788 | - // PHANTOM coefficient units in the all-skip inter frame and | ||
| 789 | - // then panicked in `reconstruct_mc_rect` on a full-height | ||
| 790 | - // 4:2:2 chroma rect. So the cell's non-vacuity is a NEGATIVE | ||
| 791 | - // measurement on the CHROMA planes, asserted here rather than | ||
| 792 | - // inherited: the walk ran (units > 0, which the shared body | ||
| 793 | - // checks) and coded nothing on U or V. | ||
| 794 | - assert_eq!( | ||
| 795 | - (coded_delta[1], coded_delta[2]), | ||
| 796 | - (0, 0), | ||
| 797 | - "{NAME}: {file} CODED a chroma coefficient -- this is the all-skip inter-frame \ | ||
| 798 | - cell and a phantom residual read is exactly the defect it witnesses" | ||
| 799 | - ); | ||
| 800 | - } | ||
| 801 | - } | ||
| 802 | - } | ||
| 803 | - | ||
| 804 | - /// lane-av1muchroma: the `chroma_side * chroma_side` mu-chroma site | ||
| 805 | - /// census, over the whole committed 4:2:2 corpus, as a per-site | ||
| 806 | - /// REACHABILITY measurement with a non-vacuity arm. | ||
| 807 | - /// | ||
| 808 | - /// `lanes/av1subsizesweep.report.md` named "mu-chroma sites using | ||
| 809 | - /// `chroma_side * chroma_side`" as unprobed residue. This lane's sweep | ||
| 810 | - /// (env-gated probe at each of the 12 sites, run over every pinned 4:2:2 | ||
| 811 | - /// gate) measured them: | ||
| 812 | - /// | ||
| 813 | - /// - sites 4, 7, 10 are guarded `ss_x == 0 && ss_y == 0`, i.e. 4:4:4 | ||
| 814 | - /// ONLY -- structurally unreachable at 4:2:2, not merely unwitnessed. | ||
| 815 | - /// - sites 2, 8 (`side > 64` mu-chunk walks) were not reached by any | ||
| 816 | - /// committed 4:2:2 fixture; their single-reference twin, site 5, is | ||
| 817 | - /// (side 128, plane 64x128), and its square allocation is the ENCLOSING | ||
| 818 | - /// square, so it is 2x oversized, never short. | ||
| 819 | - /// - sites 1, 3, 5, 6, 9, 11, 12 ARE reached. For 3/5/6/9/11/12 | ||
| 820 | - /// `chroma_side` is `max(side >> ss_x, side >> ss_y)` (decode.rs), the | ||
| 821 | - /// ENCLOSING square of the plane rect, so at 4:2:2 the square is 2x | ||
| 822 | - /// the per-axis extent: oversized, never short. | ||
| 823 | - /// - site 1 alone still used `side >> ss_x` and was therefore sized at | ||
| 824 | - /// HALF the plane block at 4:2:2. Fixed per-axis; this gate pins it. | ||
| 825 | - /// | ||
| 826 | - /// Non-vacuity: [`crate::decode::skip_arm_chroma_plane_block_hits`] | ||
| 827 | - /// fires only where the per-axis and square forms differ, so a green run | ||
| 828 | - /// that never reached the site would be vacuous and this asserts > 0. | ||
| 829 | - #[test] | ||
| 830 | - fn the_422_skip_arm_chroma_grid_is_sized_per_axis_not_square() { | ||
| 831 | - const NAME: &str = "the_422_skip_arm_chroma_grid_is_sized_per_axis_not_square"; | ||
| 832 | - const FILE: &str = "s422_322x240.obu"; | ||
| 833 | - const BYTES: usize = 21096; | ||
| 834 | - const FP: u64 = 0x9a96dda2a19d47a6; | ||
| 835 | - const W: usize = 322; | ||
| 836 | - const H: usize = 240; | ||
| 837 | - const FRAMES: usize = 16; | ||
| 838 | - let _gate_lock = lock_gate_counters(); | ||
| 839 | - let data = std::fs::read(crate_pin(FILE)).unwrap_or_else(|e| { | ||
| 840 | - panic!("{NAME}: the committed pin {FILE} is missing ({e}) -- a failure, not a skip") | ||
| 841 | - }); | ||
| 842 | - assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); | ||
| 843 | - assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted"); | ||
| 844 | - let rect_before = crate::decode::skip_arm_chroma_rect_shapes(); | ||
| 845 | - let short_before = crate::decode::skip_arm_chroma_short_samples(); | ||
| 846 | - let ours = decode_stream(&data) | ||
| 847 | - .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 4:2:2 stream: {e}")); | ||
| 848 | - assert_eq!(ours.len(), FRAMES, "{NAME}: decoded frame count"); | ||
| 849 | - for (i, f) in ours.iter().enumerate() { | ||
| 850 | - assert_eq!((f.width, f.height), (W, H), "{NAME}: frame {i} dimensions"); | ||
| 851 | - assert_eq!( | ||
| 852 | - (f.u.len(), f.v.len()), | ||
| 853 | - (W.div_ceil(2) * H, W.div_ceil(2) * H), | ||
| 854 | - "{NAME}: frame {i} chroma planes are {}/{} samples -- 4:2:2 is HALF WIDTH and \ | ||
| 855 | - FULL HEIGHT; a quarter-height plane means the decode kept a 4:2:0 allocation", | ||
| 856 | - f.u.len(), | ||
| 857 | - f.v.len() | ||
| 858 | - ); | ||
| 859 | - } | ||
| 860 | - let rect_after = crate::decode::skip_arm_chroma_rect_shapes(); | ||
| 861 | - assert!( | ||
| 862 | - rect_after > rect_before, | ||
| 863 | - "{NAME}: no skipped block decoded at a rect chroma shape ({rect_before} -> \ | ||
| 864 | - {rect_after}) -- this gate is then VACUOUS: per-axis and square sizing are the \ | ||
| 865 | - same number at 4:2:0 and 4:4:4, so it proves nothing about the site it claims" | ||
| 866 | - ); | ||
| 867 | - let short_after = crate::decode::skip_arm_chroma_short_samples(); | ||
| 868 | - assert_eq!( | ||
| 869 | - short_after, short_before, | ||
| 870 | - "{NAME}: decode_block's SKIP arm chroma grids fell {short_after} samples SHORT of \ | ||
| 871 | - their own plane block -- the square `side >> ss_x` form this lane removed allocates \ | ||
| 872 | - exactly half the plane block at 4:2:2 (ss (1,0))" | ||
| 873 | - ); | ||
| 874 | - } | ||
| 875 | - | ||
| 876 | - /// lane-av1floorshift: the two FRAME chroma plane allocators | ||
| 877 | - /// (`decode_key_frame_tile_with_cdfs`, `decode_inter_tile`) size U and V as | ||
| 878 | - /// `(width >> ss_x) x (height >> ss_y)`. `lanes/av1subsizesweep.report.md` | ||
| 879 | - /// named them "floor-`>>` chroma plane allocators -- shape assumption at | ||
| 880 | - /// frame edges; not probed" and left them open. This is the probe. | ||
| 881 | - /// | ||
| 882 | - /// **The verdict is ALREADY CORRECT, and it is structural, not | ||
| 883 | - /// corpus-luck.** `width`/`height` are `block_grid(mi_cols, mi_rows) * | ||
| 884 | - /// BLOCK` (`BLOCK == 32`) and the allocator is handed those, not the frame's | ||
| 885 | - /// own `true_width`/`true_height`: both axes are multiples of 32, and | ||
| 886 | - /// `ss_x`/`ss_y` are the sequence header's single-bit subsampling fields, | ||
| 887 | - /// so `ss <= 1` on every stream that exists. `32k >> ss == round_ss(32k, ss)` | ||
| 888 | - /// for every `k` and every `ss <= 1` -- the `>>` can never floor one sample | ||
| 889 | - /// short of libaom's own chroma crop, at a frame edge or anywhere else. The | ||
| 890 | - /// static half of the gate below proves that exhaustively over every | ||
| 891 | - /// `mi_cols`/`mi_rows` this decoder admits. | ||
| 892 | - /// | ||
| 893 | - /// The corpus half keeps the instrument honest: it decodes one frame per | ||
| 894 | - /// selectable subsampling cell and asserts the allocators were REACHED | ||
| 895 | - /// (`frame_chroma_alloc_calls` moved), so a green run cannot be the census | ||
| 896 | - /// having been wired to nothing. | ||
| 897 | - /// | ||
| 898 | - /// Witnesses, all byte-pinned (`size`, `fnv1a64`), chosen to cover all | ||
| 899 | - /// three selectable cells and both allocators: | ||
| 900 | - /// | ||
| 901 | - /// | file | cell | frame | covers | | ||
| 902 | - /// |---|---|---|---| | ||
| 903 | - /// | `420_odd65x65_key.obu` | 4:2:0, **odd** 65x65 | key | key allocator, the odd-dimension cell where a floor WOULD show | | ||
| 904 | - /// | `422_key_64x64.obu` | 4:2:2 (1,0) | key | key allocator, half-width/full-height | | ||
| 905 | - /// | `444_intrabc_rect4_witness.obu` | 4:4:4 (0,0) | key | key allocator, the `ss == 0` cell where `>> ss` is the identity | | ||
| 906 | - /// | ||
| 907 | - /// 4:4:0 (`0,1`) is excluded and cannot be added: libaom's | ||
| 908 | - /// `av1_read_color_config` asserts `subsampling_y == 0` when | ||
| 909 | - /// `subsampling_x == 0`, and no of 256 header bytes reads back `(0,1)` -- | ||
| 910 | - /// the reader census at `the_reader_never_produces_440` names it. | ||
| 911 | - #[test] | ||
| 912 | - fn the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds() { | ||
| 913 | - const NAME: &str = | ||
| 914 | - "the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds"; | ||
| 915 | - let _gate_lock = lock_gate_counters(); | ||
| 916 | - for (file, bytes, fp, cell, ss) in [ | ||
| 917 | - ( | ||
| 918 | - "420_odd65x65_key.obu", | ||
| 919 | - 2305usize, | ||
| 920 | - 0xf55645c4b139e8f7u64, | ||
| 921 | - "4:2:0", | ||
| 922 | - (1usize, 1usize), | ||
| 923 | - ), | ||
| 924 | - ( | ||
| 925 | - "422_key_64x64.obu", | ||
| 926 | - 755, | ||
| 927 | - 0x87fc569cf53bcbc6, | ||
| 928 | - "4:2:2", | ||
| 929 | - (1, 0), | ||
| 930 | - ), | ||
| 931 | - ( | ||
| 932 | - "444_intrabc_rect4_witness.obu", | ||
| 933 | - 1016, | ||
| 934 | - 0x27c2fad540472994, | ||
| 935 | - "4:4:4", | ||
| 936 | - (0, 0), | ||
| 937 | - ), | ||
| 938 | - ] { | ||
| 939 | - let data = std::fs::read(crate_pin(file)) | ||
| 940 | - .unwrap_or_else(|e| panic!("{NAME}: the committed pin {file} is missing ({e})")); | ||
| 941 | - assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 942 | - assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 943 | - let calls_before = crate::decode::frame_chroma_alloc_calls(); | ||
| 944 | - let short_before = crate::decode::frame_chroma_alloc_short_samples(); | ||
| 945 | - let crop_before = crate::decode::frame_chroma_alloc_crop_shapes(); | ||
| 946 | - let frames = decode_stream(&data) | ||
| 947 | - .unwrap_or_else(|e| panic!("{NAME}: {file} ({cell}) refused: {e}")); | ||
| 948 | - let calls = crate::decode::frame_chroma_alloc_calls() - calls_before; | ||
| 949 | - assert!( | ||
| 950 | - calls >= frames.len(), | ||
| 951 | - "{NAME}: {file} ({cell}) decoded {} frames but the chroma plane allocator ran \ | ||
| 952 | - {calls} times -- the instrument is not on the path this gate claims to cover", | ||
| 953 | - frames.len() | ||
| 954 | - ); | ||
| 955 | - // The shape the allocator owes the tile, and the shape the output | ||
| 956 | - // crop owes the caller: libaom's chroma CROP of the frame's own | ||
| 957 | - // dimensions (`av1_round_shift`), which is what | ||
| 958 | - // `decode_key_frame_tile_with_cdfs`'s `Picture` crop uses. At the | ||
| 959 | - // odd 65x65 4:2:0 cell this is 33x33 -- 1089 samples, NOT the | ||
| 960 | - // floor 32x32 an `>>` short of the true extent would have left. | ||
| 961 | - for (i, f) in frames.iter().enumerate() { | ||
| 962 | - let (cw, ch) = ( | ||
| 963 | - crate::decode::round_ss(f.width, ss.0), | ||
| 964 | - crate::decode::round_ss(f.height, ss.1), | ||
| 965 | - ); | ||
| 966 | - assert_eq!( | ||
| 967 | - (f.u.len(), f.v.len()), | ||
| 968 | - (cw * ch, cw * ch), | ||
| 969 | - "{NAME}: {file} ({cell}) frame {i} is {}x{} and its chroma planes are {} / {} \ | ||
| 970 | - samples; {cell} is a {cw}x{ch} = {} crop", | ||
| 971 | - f.width, | ||
| 972 | - f.height, | ||
| 973 | - f.u.len(), | ||
| 974 | - f.v.len(), | ||
| 975 | - cw * ch | ||
| 976 | - ); | ||
| 977 | - } | ||
| 978 | - let short = crate::decode::frame_chroma_alloc_short_samples() - short_before; | ||
| 979 | - assert_eq!( | ||
| 980 | - short, 0, | ||
| 981 | - "{NAME}: {file} ({cell}) allocated {short} chroma samples SHORT of the `round_ss` \ | ||
| 982 | - extent the tile's chroma walks may address -- the frame chroma planes are sized \ | ||
| 983 | - by a FLOOR `>> ss` that does not round" | ||
| 984 | - ); | ||
| 985 | - let crop = crate::decode::frame_chroma_alloc_crop_shapes() - crop_before; | ||
| 986 | - assert_eq!( | ||
| 987 | - crop, 0, | ||
| 988 | - "{NAME}: {file} ({cell}) reached a frame shape on which `>> ss` and `round_ss` \ | ||
| 989 | - disagree ({crop} frames) -- the allocators are handed a MULTIPLE OF 32 \ | ||
| 990 | - (block_grid * BLOCK) and `ss <= 1`, so this can only mean the allocator's own \ | ||
| 991 | - argument changed, and the shortfall assertion above is then vacuous on this file" | ||
| 992 | - ); | ||
| 993 | - } | ||
| 994 | - } | ||
| 995 | - | ||
| 996 | - /// lane-av1floorshift: the STATIC half of the same claim, and the part that | ||
| 997 | - /// does not need a corpus. The frame chroma allocators' shift argument is | ||
| 998 | - /// `block_grid(mi_cols, mi_rows) * BLOCK` with `BLOCK == 32`, so for every | ||
| 999 | - /// `mi_cols`/`mi_rows` this decoder can admit and every subsampling the | ||
| 1000 | - /// header can carry (`ss in {0, 1}` per axis), `>> ss` and `round_ss` are | ||
| 1001 | - /// the same number. Exhaustively checked here over a range wider than any | ||
| 1002 | - /// frame a header can declare; the two counters above are zero for a | ||
| 1003 | - /// reason, and this is the reason. | ||
| 1004 | - #[test] | ||
| 1005 | - fn the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss() { | ||
| 1006 | - const NAME: &str = "the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss"; | ||
| 1007 | - const BLOCK: usize = 32; | ||
| 1008 | - // `block_grid(mi) = mi.div_ceil(BLOCK_MI)` with `BLOCK_MI == 8` | ||
| 1009 | - // (`tile.rs`), so the allocator's width is `(mi.div_ceil(8)) * 32`. | ||
| 1010 | - for mi in 1..=512usize { | ||
| 1011 | - let coded = mi.div_ceil(8) * BLOCK; | ||
| 1012 | - for ss in 0..=1usize { | ||
| 1013 | - assert_eq!( | ||
| 1014 | - coded >> ss, | ||
| 1015 | - crate::decode::round_ss(coded, ss), | ||
| 1016 | - "{NAME}: coded {coded} (mi {mi}) at ss {ss}: the floor and the crop differ -- \ | ||
| 1017 | - the frame chroma plane would be allocated short" | ||
| 1018 | - ); | ||
| 1019 | - // The TRUE extent is `mi * 4`; it is what the allocator | ||
| 1020 | - // derives `true_width` from and what every chroma walk is | ||
| 1021 | - // clamped against, so it earns the same check. | ||
| 1022 | - let truth = mi * 4; | ||
| 1023 | - assert_eq!( | ||
| 1024 | - truth >> ss, | ||
| 1025 | - crate::decode::round_ss(truth, ss), | ||
| 1026 | - "{NAME}: true {truth} (mi {mi}) at ss {ss}: the floor and the crop differ" | ||
| 1027 | - ); | ||
| 1028 | - } | ||
| 1029 | - } | ||
| 1030 | - // And the 4:4:0 cell libaom refuses, spelled out rather than left as | ||
| 1031 | - // an assumption: at `ss (0,1)` the shift is exact too, so the site | ||
| 1032 | - // would be correct even if the cell were ever admitted. | ||
| 1033 | - for mi in 1..=64usize { | ||
| 1034 | - assert_eq!((mi * 4) >> 1, crate::decode::round_ss(mi * 4, 1)); | ||
| 1035 | - assert_eq!(mi * 4, crate::decode::round_ss(mi * 4, 0)); | ||
| 1036 | - } | ||
| 1037 | - } | ||
| 1038 | - | ||
| 1039 | - /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter | ||
| 1040 | - /// PALETTE chroma per-unit window, and its byte pin. | ||
| 1041 | - /// | ||
| 1042 | - /// `422_palette_intra_in_inter_384x240_17f.obu` (19344 B, sha256 | ||
| 1043 | - /// `bf1c658e9bfdc13ec1ed51e59049d2b81201941b6ef4571f8382f356ea4b815b`) is | ||
| 1044 | - /// the one 4:2:2 cell of the 384x240 census sweep: 384x240, ss (1,0), | ||
| 1045 | - /// 8-bit, **17 decode frames, 16 shown** (decode 1 is the hidden altref). | ||
| 1046 | - /// Its decode-frame-1 block at mi(32,0) is a 64x64 INTRA block with a | ||
| 1047 | - /// PALETTE -- `aomdec`'s `EC_PIB` prints `use_palette=1` there, and the | ||
| 1048 | - /// oracle's own prediction rungs print nothing for the block because | ||
| 1049 | - /// `av1_predict_intra_block` returns at its palette branch before them | ||
| 1050 | - /// (`reconintra.c:1735`). | ||
| 1051 | - /// | ||
| 1052 | - /// At 4:2:2 that block's chroma plane block is 32x64, but | ||
| 1053 | - /// `av1_get_max_uv_txsize` adjusts `max_tx_size_rect_lookup[BLOCK_32X64]` | ||
| 1054 | - /// down to TX_32X32, so it codes TWO STACKED SQUARE units per plane. | ||
| 1055 | - /// `decode_inter_block`'s `side == 64` walk armed the ONE block-sized | ||
| 1056 | - /// 2048-entry chroma palette prediction before the loop: the first unit | ||
| 1057 | - /// consumed all of it and the second found none pending, so it silently | ||
| 1058 | - /// fell back to the edge DC prediction -- a flat 90/240 box where the | ||
| 1059 | - /// oracle carries its palette (U/V rows 170..189, cols 23..31, 180 wrong | ||
| 1060 | - /// samples per plane at the pre-filter stage). Each unit now takes its own | ||
| 1061 | - /// `palette_window` of that buffer (`decode.rs`) -- the same helper the | ||
| 1062 | - /// split-transform chroma paths already used. | ||
| 1063 | - /// | ||
| 1064 | - /// **The committed assertion follows the family's standing rule** (same | ||
| 1065 | - /// shape as | ||
| 1066 | - /// [`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name`]): | ||
| 1067 | - /// the byte pin plus this decoder's disposition of those bytes. | ||
| 1068 | - /// lane-av1422lift: `decode_stream` no longer refuses 4:2:2 at the sequence | ||
| 1069 | - /// header, so the OK arm is the live one -- the gate decodes the pin and | ||
| 1070 | - /// asserts 17 decode-order frames byte-exact against aomdec with | ||
| 1071 | - /// `palette_422_unit_window_hits()` fired. lane-av1oracledepth: the stale | ||
| 1072 | - /// `Err` arm (it matched the pre-lift refusal string | ||
| 1073 | - /// `"a chroma format of 4:2:2"` the decoder no longer returns, and could | ||
| 1074 | - /// have swallowed a future decode error as green) is deleted; a refusal | ||
| 1075 | - /// now fails this gate loudly. | ||
| 1076 | - #[test] | ||
| 1077 | - fn the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact() { | ||
| 1078 | - const NAME: &str = "the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact"; | ||
| 1079 | - const FILE: &str = "422_palette_intra_in_inter_384x240_17f.obu"; | ||
| 1080 | - const BYTES: usize = 19344; | ||
| 1081 | - const FP: u64 = 0x923ccabfcb933e90; | ||
| 1082 | - let _gate_lock = lock_gate_counters(); | ||
| 1083 | - let data = std::fs::read(crate_pin(FILE)).unwrap_or_else(|e| { | ||
| 1084 | - panic!("{NAME}: the committed pin {FILE} is missing ({e}) -- a failure, not a skip") | ||
| 1085 | - }); | ||
| 1086 | - assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); | ||
| 1087 | - assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted"); | ||
| 1088 | - let before = crate::decode::palette_422_unit_window_hits(); | ||
| 1089 | - // lane-av1oracledepth: the OK arm is MEASURED to be the live one (the | ||
| 1090 | - // pinned bytes decode, 17 decode-order frames byte-exact vs aomdec, | ||
| 1091 | - // 16 windowed units) and the old `Err` arm matching the pre-lift | ||
| 1092 | - // refusal string "a chroma format of 4:2:2" is deleted: committed | ||
| 1093 | - // code no longer returns that string, so the arm could only ever | ||
| 1094 | - // swallow a FUTURE decode error that happened to contain it and read | ||
| 1095 | - // green off a stream that decoded nothing. A refusal today now fails | ||
| 1096 | - // this gate loudly, as it should. | ||
| 1097 | - match decode_stream(&data) { | ||
| 1098 | - Err(e) => { | ||
| 1099 | - panic!( | ||
| 1100 | - "{NAME}: {FILE} was refused by the current decoder: {e}. 4:2:2 is a \ | ||
| 1101 | - DECODED format; a refusal here is a regression, not the old sequence-\ | ||
| 1102 | - header gate" | ||
| 1103 | - ) | ||
| 1104 | - } | ||
| 1105 | - Ok(_) => { | ||
| 1106 | - let windows = crate::decode::palette_422_unit_window_hits() - before; | ||
| 1107 | - assert!( | ||
| 1108 | - windows > 0, | ||
| 1109 | - "{NAME}: {FILE} decoded, but no 4:2:2 intra-in-inter chroma unit took \ | ||
| 1110 | - the per-unit palette window ({windows} did) -- this cell does not \ | ||
| 1111 | - exercise the arm at all (class gate-blind-to-feature)" | ||
| 1112 | - ); | ||
| 1113 | - let (decoded, hidden) = decode_all_frames_vs_oracle(&data, FILE); | ||
| 1114 | - assert_eq!( | ||
| 1115 | - decoded, 17, | ||
| 1116 | - "{NAME}: the oracle decoded {decoded} frames in DECODE order, not 17" | ||
| 1117 | - ); | ||
| 1118 | - assert_eq!(hidden, 1, "{NAME}: expected exactly the one hidden altref"); | ||
| 1119 | - eprintln!( | ||
| 1120 | - "{NAME}: {decoded} decode-order frame(s) byte-exact against aomdec \ | ||
| 1121 | - ({hidden} hidden), {windows} chroma palette unit window(s)" | ||
| 1122 | - ); | ||
| 1123 | - } | ||
| 1124 | - } | ||
| 1125 | - } | ||
| 1126 | - | ||
| 1127 | - /// lane-av1-ibc128chunk: the WITNESS for the 128-root intrabc strip's | ||
| 1128 | - /// de-square-cut mu-chunk chroma walk, and the byte pin for it. | ||
| 1129 | - /// | ||
| 1130 | - /// `decode_intrabc_128rect` cut each mu chunk's chroma plane block with | ||
| 1131 | - /// `chunk_chroma = cside * 64 / side` -- a `chroma_side`-SQUARE chunk, | ||
| 1132 | - /// i.e. the 4:2:0 count on BOTH axes (the same defect lane-av1-422bigblock | ||
| 1133 | - /// fixed, and witnessed, in `decode_inter_block` and | ||
| 1134 | - /// `decode_block_128rect`; this copy was deferred there as unwitnessed). | ||
| 1135 | - /// At 4:2:2 a 64x64 mu chunk's chroma plane block is 32x64, so it holds | ||
| 1136 | - /// TWO STACKED TX_32X32 units per plane: the square-cut walk read one per | ||
| 1137 | - /// plane per chunk, left the chunk's lower 32 chroma rows with no | ||
| 1138 | - /// residual at all, and stamped each unit's entropy context over a | ||
| 1139 | - /// 16x16-mi luma span instead of 16x8. | ||
| 1140 | - /// | ||
| 1141 | - /// Measured red-before on the pinned witness (parent `a7d22aec`, via the | ||
| 1142 | - /// local `EC_AV1_ALLOW_422_PROBE` patch-run-restore build): 8 chroma | ||
| 1143 | - /// units stamped over the stream's two reached blocks and frames 0 and 3 | ||
| 1144 | - /// diverge from `aomdec` (45135 / 44540 of 245760 samples each), the | ||
| 1145 | - /// first difference at Y sample 98368 -- frame 0, row 256, col 64, the | ||
| 1146 | - /// top-left corner of the first 128x64 intrabc block at mi(64,0). The | ||
| 1147 | - /// red build then lost 4 of the stream's 6 intrabc blocks to the desync. | ||
| 1148 | - /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks | ||
| 1149 | - /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`. | ||
| 1150 | - /// | ||
| 1151 | - /// lane-av1422lift: committed code no longer refuses 4:2:2 at the | ||
| 1152 | - /// sequence header, so the red/green evidence above is no longer | ||
| 1153 | - /// probe-only: this gate is the one that asserts it. Both pins are | ||
| 1154 | - /// byte-pinned AND byte-exact against ffmpeg's `yuv422p` rawvideo of the | ||
| 1155 | - /// same bytes, per plane and per frame, with the per-plane | ||
| 1156 | - /// coefficient-unit census as the non-vacuity arm -- the census is what | ||
| 1157 | - /// makes "48 chroma units stamped" a committed, reproducible number here | ||
| 1158 | - /// instead of a sentence in a lane report. The source-scan arm below | ||
| 1159 | - /// keeps its own claim (the per-axis SPELLING) and does not overlap. | ||
| 1160 | - #[test] | ||
| 1161 | - fn the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact() { | ||
| 1162 | - const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact"; | ||
| 1163 | - if !have_ffmpeg() { | ||
| 1164 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1165 | - return; | ||
| 1166 | - } | ||
| 1167 | - for (file, bytes, fp) in [ | ||
| 1168 | - ( | ||
| 1169 | - "422_intrabc_sb128_strip.obu", | ||
| 1170 | - 1672usize, | ||
| 1171 | - 0x50f5cfc576e4cd00_u64, | ||
| 1172 | - ), | ||
| 1173 | - ( | ||
| 1174 | - "422_intrabc_sb128_strip_notxsearch.obu", | ||
| 1175 | - 1675, | ||
| 1176 | - 0xd4936f252ff8cff0, | ||
| 1177 | - ), | ||
| 1178 | - ] { | ||
| 1179 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1180 | - .join("fixtures") | ||
| 1181 | - .join(file); | ||
| 1182 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 1183 | - panic!( | ||
| 1184 | - "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 1185 | - path.display() | ||
| 1186 | - ) | ||
| 1187 | - }); | ||
| 1188 | - assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 1189 | - assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 1190 | - assert_422_stream_pixel_exact(NAME, &data, 384, 320, 5, 8, true); | ||
| 1191 | - } | ||
| 1192 | - } | ||
| 1193 | - | ||
| 1194 | - /// lane-av1422a2a4: the firing gate for `decode_block`'s var-tx EITHER/OR | ||
| 1195 | - /// tail at 4:2:2 -- an INTRABC block whose var-tx tree resolved MIXED | ||
| 1196 | - /// leaves, where the old blanket `set_txfm_ctxs` + `fill_lf_grid` publishes | ||
| 1197 | - /// clobbered the per-leaf TXFM_CONTEXT bands libaom keeps. | ||
| 1198 | - /// | ||
| 1199 | - /// Provenance: aomenc profile 2, `testsrc2=size=128x112:rate=25` tiled 2x2 | ||
| 1200 | - /// to 256x224, cq 30, 3 frames (`lanes/av1422ibcrect.report.md` §2, stream | ||
| 1201 | - /// A4). The oracle decodes it to completion; the pre-fix tree refused it | ||
| 1202 | - /// mid-tile with the documented `decodeframe.c:1456` subsize string -- the | ||
| 1203 | - /// E6/E7 desync-symptom class, NOT an invalid shape. | ||
| 1204 | - /// | ||
| 1205 | - /// Measured on the pinned bytes: the 32x32 intrabc block at mi(32,8) | ||
| 1206 | - /// resolves leaves (0,0)+((0,4) 8x8, (4,0)+(4,4) 16x16, so | ||
| 1207 | - /// `left_txfm[32..35]` must read 16 when the NEXT tree's sub-unit at | ||
| 1208 | - /// (32,16) row0col0 reads its `txfm_partition` context (oracle operands | ||
| 1209 | - /// `above=16 left=16`, ctx 9). The blanket publishes reset those cells to | ||
| 1210 | - /// 8 -> ctx 10 -> a wrong `is_split` -> the first divergent read, and the | ||
| 1211 | - /// refusal surfaced ~30 partition symbols later. | ||
| 1212 | - #[test] | ||
| 1213 | - fn the_pinned_422_intrabc_vartx_mixedtree_witnesses_decode_pixel_exact() { | ||
| 1214 | - const NAME: &str = "the_pinned_422_intrabc_vartx_mixedtree_witnesses_decode_pixel_exact"; | ||
| 1215 | - if !have_ffmpeg() { | ||
| 1216 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1217 | - return; | ||
| 1218 | - } | ||
| 1219 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1220 | - .join("fixtures") | ||
| 1221 | - .join("422_intrabc_vartx_mixedtree_a4.obu"); | ||
| 1222 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 1223 | - panic!( | ||
| 1224 | - "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 1225 | - path.display() | ||
| 1226 | - ) | ||
| 1227 | - }); | ||
| 1228 | - assert_eq!(data.len(), 30937, "{NAME}: pinned witness size drifted"); | ||
| 1229 | - assert_eq!( | ||
| 1230 | - fnv1a64(&data), | ||
| 1231 | - 0x6f0fc77c2217910a_u64, | ||
| 1232 | - "{NAME}: pinned witness bytes drifted" | ||
| 1233 | - ); | ||
| 1234 | - assert_422_stream_pixel_exact(NAME, &data, 256, 224, 3, 8, true); | ||
| 1235 | - } | ||
| 1236 | - | ||
| 1237 | - /// lane-av1422ibctxsel: the firing gate for `decode_intrabc_owned_rect`'s | ||
| 1238 | - /// NON-SPLIT chroma coefficient context at 4:2:2. | ||
| 1239 | - /// | ||
| 1240 | - /// `lanes/av1422gathercensus.report.md` closed its ss (1, 0) class sweep | ||
| 1241 | - /// with this one gather at STOP -- unwitnessed: `around_mi_rect` over the | ||
| 1242 | - /// block's LUMA span feeds the CHROMA `dc_sign_ctx`, and at ss (1, 0) a | ||
| 1243 | - /// chroma 4-px cell spans TWO luma mi columns, so the per-mi sum counts | ||
| 1244 | - /// every chroma column twice (`around_mi_422_chroma`'s every-second | ||
| 1245 | - /// sampling is libaom's one-vote-per-cell sum). `lane-av1422ibcrect` | ||
| 1246 | - /// found a stream that ENTERS the gather (24 entries) but whose two | ||
| 1247 | - /// gathers agree on every entry, so the class stayed harmless-ON-THAT- | ||
| 1248 | - /// STREAM, not proven. | ||
| 1249 | - /// | ||
| 1250 | - /// This fixture is the discriminating witness: aomenc profile 2, 384x288 | ||
| 1251 | - /// 4:2:2, 4 key frames, `--sb-size=64` with the last superblock row half | ||
| 1252 | - /// outside the frame (so the 64-root partition is a single gathered bit | ||
| 1253 | - /// and the strips are 64x32 HORZ intra-BC strips), `--enable-tx-size- | ||
| 1254 | - /// search=1` plus a high-frequency patch that keeps the frame's `tx_mode` | ||
| 1255 | - /// at `TX_MODE_SELECT` (`txb_split_count > 0`; without it encodeframe.c | ||
| 1256 | - /// :2690 downgrades every frame to `TX_MODE_LARGEST`), and a chroma band | ||
| 1257 | - /// above the strips so a full-weight above context meets a full-weight | ||
| 1258 | - /// left one of the opposite sign. | ||
| 1259 | - /// | ||
| 1260 | - /// Measured on the pinned bytes: 24 non-split chroma gathers entered (6 | ||
| 1261 | - /// strips x 4 frames; 48 plane reads), and FIVE of them -- plane 2, strips | ||
| 1262 | - /// mi (64,16)..(64,80) of frame 0 -- read `dc_sign_ctx` 1 through the | ||
| 1263 | - /// luma-span gather against libaom's 0 through the pair rule (`full = 2A + | ||
| 1264 | - /// L = -8`, `pair = A + L = 0`: the double-counted above vote crosses | ||
| 1265 | - /// zero, and the context is a sign). | ||
| 1266 | - /// | ||
| 1267 | - /// Red-before (the route reverted, same fixture bytes): the wrong sign | ||
| 1268 | - /// context changes the decoded dc-sign CDF and desyncs the tile -- the | ||
| 1269 | - /// decoder refuses the stream mid-frame with "a block size 4x8, 8x16 or | ||
| 1270 | - /// 16x4 ... has no chroma plane block at this frame's subsampling mode", | ||
| 1271 | - /// so NO frame decodes at all. That refusal is also the proof it is a | ||
| 1272 | - /// desync symptom and not a real sub-8x8 shape: both oracles decode the | ||
| 1273 | - /// pinned bytes fully. Green-after: 4/4 frames byte-exact against | ||
| 1274 | - /// ffmpeg's `yuv422p` rawvideo, with the per-plane coefficient-unit | ||
| 1275 | - /// census (the helper's) and the pair-rule route counter as the | ||
| 1276 | - /// non-vacuity arms. The 4:4:4 arm below pins the guard's other side: | ||
| 1277 | - /// the same function at ss (0, 0) keeps the verbatim luma-span gather and | ||
| 1278 | - /// must NOT fire the route. | ||
| 1279 | - #[test] | ||
| 1280 | - fn a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule() { | ||
| 1281 | - const NAME: &str = "a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule"; | ||
| 1282 | - const FILE: &str = "ibc422_nonsplit_ctx.obu"; | ||
| 1283 | - const LEN: usize = 2170; | ||
| 1284 | - /// sha256 `4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68`, | ||
| 1285 | - /// fnv1a64 `0x92e2c4e45ca27e34`. | ||
| 1286 | - const FNV: u64 = 0x92e2c4e45ca27e34; | ||
| 1287 | - if !have_ffmpeg() { | ||
| 1288 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1289 | - return; | ||
| 1290 | - } | ||
| 1291 | - let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1292 | - .join("fixtures") | ||
| 1293 | - .join(FILE); | ||
| 1294 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 1295 | - panic!( | ||
| 1296 | - "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 1297 | - path.display() | ||
| 1298 | - ) | ||
| 1299 | - }); | ||
| 1300 | - assert_eq!(data.len(), LEN, "{NAME}: {FILE} size drifted"); | ||
| 1301 | - assert_eq!(fnv1a64(&data), FNV, "{NAME}: {FILE} bytes drifted"); | ||
| 1302 | - // No `lock_gate_counters()` here: the bumps are thread-local, and | ||
| 1303 | - // `assert_422_stream_pixel_exact` takes that same (non-reentrant) | ||
| 1304 | - // mutex itself -- holding it across this call self-deadlocks. | ||
| 1305 | - crate::decode::reset_ibc_owned_rect_422_pair_hits(); | ||
| 1306 | - assert_422_stream_pixel_exact(NAME, &data, 384, 288, 4, 8, true); | ||
| 1307 | - let hits = crate::decode::ibc_owned_rect_422_pair_hits(); | ||
| 1308 | - assert_eq!( | ||
| 1309 | - hits, 24, | ||
| 1310 | - "{NAME}: the pair-rule route fired {hits} times, not 24 (6 non-split chroma gathers \ | ||
| 1311 | - x 4 frames) -- the witness stopped exercising the arm, or the guard's extent moved" | ||
| 1312 | - ); | ||
| 1313 | - // The guard's other arm: the 4:4:4 owner-rect stream (`r512.obu`, | ||
| 1314 | - // pinned by the gate below) reaches this same function at ss (0, 0), | ||
| 1315 | - // where the verbatim luma-span gather is correct -- the route counter | ||
| 1316 | - // must stay put. | ||
| 1317 | - let r512 = std::fs::read( | ||
| 1318 | - std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/r512.obu"), | ||
| 1319 | - ) | ||
| 1320 | - .expect("r512.obu must exist"); | ||
| 1321 | - crate::decode::reset_ibc_owned_rect_422_pair_hits(); | ||
| 1322 | - let _ = decode_stream(&r512).expect("the 4:4:4 owner-rect witness decodes"); | ||
| 1323 | - assert_eq!( | ||
| 1324 | - crate::decode::ibc_owned_rect_422_pair_hits(), | ||
| 1325 | - 0, | ||
| 1326 | - "{NAME}: the 4:2:2 pair-rule route fired on a 4:4:4 stream -- the ss (1, 0) guard \ | ||
| 1327 | - leaks (class gate-blind-to-feature)" | ||
| 1328 | - ); | ||
| 1329 | - } | ||
| 1330 | - | ||
| 1331 | - /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. | ||
| 1332 | - /// | ||
| 1333 | - /// The decode-level half of the red/green evidence now runs in committed | ||
| 1334 | - /// code too -- the witness gate above, | ||
| 1335 | - /// `the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact`, | ||
| 1336 | - /// decodes both pins byte-exact against ffmpeg (lane-av1422lift lifted the | ||
| 1337 | - /// sequence-header refusal). This arm complements it by pinning the thing | ||
| 1338 | - /// that would silently bring the defect back: the square-cut | ||
| 1339 | - /// `chunk_chroma = cside * 64 / side` expression, and the per-axis | ||
| 1340 | - /// replacements that replaced it at BOTH sites in | ||
| 1341 | - /// [`decode_intrabc_128rect`] -- the mu-chunk read walk and the | ||
| 1342 | - /// `mu_chroma` per-unit context replay. It also pins the per-axis | ||
| 1343 | - /// counters' accessors so the arms stay reachable, and the walk's own | ||
| 1344 | - /// per-axis extent, derived here from the same `64 >> ss` form the | ||
| 1345 | - /// witnesses measured (4:2:0 = one TX_32X32 per plane per chunk, | ||
| 1346 | - /// 4:2:2 = two stacked, 4:4:4 = four). | ||
| 1347 | - #[test] | ||
| 1348 | - fn the_intrabc_128rect_chroma_chunk_walk_stays_per_axis() { | ||
| 1349 | - const NAME: &str = "the_intrabc_128rect_chroma_chunk_walk_stays_per_axis"; | ||
| 1350 | - let src = crate::test_source::module_source("decode"); | ||
| 1351 | - let body = src | ||
| 1352 | - .split_once("fn decode_intrabc_128rect(") | ||
| 1353 | - .expect("decode_intrabc_128rect must exist") | ||
| 1354 | - .1 | ||
| 1355 | - .split_once("\nfn ") | ||
| 1356 | - .expect("decode_intrabc_128rect must be a top-level fn") | ||
| 1357 | - .0; | ||
| 1358 | - // Scan CODE only: the fix's own comments quote the old expression to | ||
| 1359 | - // say what it was, and a prose mention must not read as a | ||
| 1360 | - // reintroduction (nor mask one). | ||
| 1361 | - let stripped: Vec<&str> = body | ||
| 1362 | - .lines() | ||
| 1363 | - .map(|l| l.split_once("//").map_or(l, |(c, _)| c)) | ||
| 1364 | - .collect(); | ||
| 1365 | - let code = stripped.join("\n"); | ||
| 1366 | - let body = code.as_str(); | ||
| 1367 | - assert_eq!( | ||
| 1368 | - body.matches("cside * 64 / side").count(), | ||
| 1369 | - 0, | ||
| 1370 | - "{NAME}: the square-cut `cside * 64 / side` chunk extent is BACK in \ | ||
| 1371 | - decode_intrabc_128rect -- that expression is the 4:2:2 defect this \ | ||
| 1372 | - gate exists for (a 64x64 mu chunk's chroma plane block is \ | ||
| 1373 | - (64 >> ss_x) x (64 >> ss_y), not `chroma_side` square)" | ||
| 1374 | - ); | ||
| 1375 | - // The per-axis chunk extent, declared once at the mu-chunk read walk | ||
| 1376 | - // and once at the `mu_chroma` replay -- the two de-square-cut sites. | ||
| 1377 | - // | ||
| 1378 | - // The replay must ALSO enumerate every unit inside a chunk, not just | ||
| 1379 | - // its first: counting mu CHUNKS in `rows`/`cols` and then stepping the | ||
| 1380 | - // mi origin and reading the grid per UNIT only agrees when a chunk | ||
| 1381 | - // holds exactly one unit (4:2:0). At 4:2:2 and 4:4:4 a chunk holds two | ||
| 1382 | - // or four, so the per-unit body alone left the rest of the chunk with | ||
| 1383 | - // the composed-grid smearing the replay exists to undo. | ||
| 1384 | - for name in [ | ||
| 1385 | - "let chunk_chroma_w = (64usize) >> ss_x(fctx);", | ||
| 1386 | - "let chunk_chroma_h = (64usize) >> ss_y(fctx);", | ||
| 1387 | - ] { | ||
| 1388 | - assert_eq!( | ||
| 1389 | - body.matches(name).count(), | ||
| 1390 | - 2, | ||
| 1391 | - "{NAME}: `{name}` must appear at BOTH de-square-cut sites in \ | ||
| 1392 | - decode_intrabc_128rect (the mu-chunk read walk and the mu_chroma \ | ||
| 1393 | - context replay), found {}", | ||
| 1394 | - body.matches(name).count() | ||
| 1395 | - ); | ||
| 1396 | - } | ||
| 1397 | - for name in [ | ||
| 1398 | - "let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);", | ||
| 1399 | - "for kr in 0..ur {", | ||
| 1400 | - "for kc in 0..uc {", | ||
| 1401 | - ] { | ||
| 1402 | - assert_eq!( | ||
| 1403 | - body.matches(name).count(), | ||
| 1404 | - 1, | ||
| 1405 | - "{NAME}: `{name}` must appear exactly once in \ | ||
| 1406 | - decode_intrabc_128rect -- the mu_chroma replay must walk chunk \ | ||
| 1407 | - THEN unit (decode_inter_block's `mu_chroma_units` shape), found {}", | ||
| 1408 | - body.matches(name).count() | ||
| 1409 | - ); | ||
| 1410 | - } | ||
| 1411 | - for name in [ | ||
| 1412 | - "let unit_luma_w = cu_tx << ss_x(fctx);", | ||
| 1413 | - "let unit_luma_h = cu_tx << ss_y(fctx);", | ||
| 1414 | - "let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));", | ||
| 1415 | - "let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));", | ||
| 1416 | - "neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)", | ||
| 1417 | - ] { | ||
| 1418 | - assert_eq!( | ||
| 1419 | - body.matches(name).count(), | ||
| 1420 | - 1, | ||
| 1421 | - "{NAME}: `{name}` must appear exactly once in \ | ||
| 1422 | - decode_intrabc_128rect, found {}", | ||
| 1423 | - body.matches(name).count() | ||
| 1424 | - ); | ||
| 1425 | - } | ||
| 1426 | - // lane-av1muchunk422sym: the CHROMA gather of that same walk must take | ||
| 1427 | - // the 4:2:2 pair rule, exactly as `decode_inter_block`'s mu-chunk walk | ||
| 1428 | - // does (one chroma column per pair of luma mi cells; the plain rect | ||
| 1429 | - // gather doubles the above dc vote and flips `dc_sign_ctx` wherever | ||
| 1430 | - // above and left cancel). Reachability is measured: the walk fires at | ||
| 1431 | - // ss (1, 0) on `422_intrabc_sb128_strip.obu` (`EC_IBC128_BANDS` | ||
| 1432 | - // prints); that fixture's own votes do not cancel, so THIS gate -- not | ||
| 1433 | - // a pixel compare -- is what stops the routing being reverted. | ||
| 1434 | - for name in [ | ||
| 1435 | - "let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {", | ||
| 1436 | - "neighbours.around_mi_422_chroma(", | ||
| 1437 | - ] { | ||
| 1438 | - assert_eq!( | ||
| 1439 | - body.matches(name).count(), | ||
| 1440 | - 1, | ||
| 1441 | - "{NAME}: `{name}` must appear exactly once in \ | ||
| 1442 | - decode_intrabc_128rect's chroma chunk walk, found {} -- the \ | ||
| 1443 | - gather has fallen back to the square per-mi rule", | ||
| 1444 | - body.matches(name).count() | ||
| 1445 | - ); | ||
| 1446 | - } | ||
| 1447 | - // The replay's own unit luma span is the lossless/lossy `cu << ss` form | ||
| 1448 | - // (site 2 spells it separately from the read walk's `cu_tx << ss`). | ||
| 1449 | - for name in [ | ||
| 1450 | - "let unit_luma_w = cu << ss_x(fctx);", | ||
| 1451 | - "let unit_luma_h = cu << ss_y(fctx);", | ||
| 1452 | - ] { | ||
| 1453 | - assert_eq!( | ||
| 1454 | - body.matches(name).count(), | ||
| 1455 | - 1, | ||
| 1456 | - "{NAME}: `{name}` must appear exactly once in \ | ||
| 1457 | - decode_intrabc_128rect, found {}", | ||
| 1458 | - body.matches(name).count() | ||
| 1459 | - ); | ||
| 1460 | - } | ||
| 1461 | - // The per-axis chunk extent the geometry demands, spelled out here so | ||
| 1462 | - // the scan and the witnesses cannot disagree about it. | ||
| 1463 | - let per_axis_units = |ss_x: u32, ss_y: u32| (64 >> ss_x) / 32 * (64 >> ss_y) / 32; | ||
| 1464 | - assert_eq!(per_axis_units(1, 1), 1, "{NAME}: 4:2:0 must stay one unit"); | ||
| 1465 | - assert_eq!(per_axis_units(1, 0), 2, "{NAME}: 4:2:2 must be two units"); | ||
| 1466 | - assert_eq!(per_axis_units(0, 0), 4, "{NAME}: 4:4:4 must be four units"); | ||
| 1467 | - // The counters the probe arms read must stay exported. | ||
| 1468 | - for name in [ | ||
| 1469 | - "pub fn intrabc_128rect_chroma_chunk_hits()", | ||
| 1470 | - "pub fn intrabc_128rect_chunk_shape()", | ||
| 1471 | - ] { | ||
| 1472 | - assert!( | ||
| 1473 | - src.contains(name), | ||
| 1474 | - "{NAME}: the accessor `{name}` must stay in decode.rs" | ||
| 1475 | - ); | ||
| 1476 | - } | ||
| 1477 | - } | ||
| 1478 | - | ||
| 1479 | - /// lane-av1422gather3: `decode_block_128rect`'s per-chunk CHROMA unit | ||
| 1480 | - /// walk gathered its coefficient context with the plain square-cut | ||
| 1481 | - /// `around_mi_rect`, so at ss (1,0) its above dc vote summed 16 LUMA mi | ||
| 1482 | - /// cells where libaom's `get_txb_ctx_general` reads `txb_w_unit` = | ||
| 1483 | - /// `chroma_tx / 4` = 8 CHROMA cells (one chroma column per PAIR of luma | ||
| 1484 | - /// mi columns; both luma cells of a column carry the covering unit's | ||
| 1485 | - /// whole-unit dc sign). That is the same pair rule the mu-chunk walks | ||
| 1486 | - /// take (`around_mi_422_chroma`), and the gather now routes through it | ||
| 1487 | - /// under the ss guard -- verbatim `around_mi_rect` at every other shape. | ||
| 1488 | - /// | ||
| 1489 | - /// Reachability is MEASURED, not assumed: the walk fires at ss (1,0) on | ||
| 1490 | - /// both pinned `422_intrabc_sb128_strip*.obu` cells, 72 chroma unit | ||
| 1491 | - /// gathers each (`sb128rect_chroma_replay_hits().0`, the same walk's own | ||
| 1492 | - /// replay counter). No committed cell DISCRIMINATES the change: with the | ||
| 1493 | - /// pair rule in place all 21 committed 4:2:2 cells are byte-exact | ||
| 1494 | - /// against ffmpeg, exactly as the pre-change tree was (the gathered | ||
| 1495 | - /// votes cancel at every reached unit), so THIS gate -- not a pixel | ||
| 1496 | - /// compare -- is what stops the routing being reverted. | ||
| 1497 | - /// | ||
| 1498 | - /// lane-av1422mismatch9: the same decode loop now also asserts the | ||
| 1499 | - /// `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` count (NINE per pin) and states | ||
| 1500 | - /// why it is not a pixel miss -- the counter's predicate is a span | ||
| 1501 | - /// DIFFERENCE, true by construction at ss (1,0); the replay re-stamps the | ||
| 1502 | - /// identical context cells with the same per-axis pair the read walk used; | ||
| 1503 | - /// and `record_mi_chroma` writes no pixel sample. See the assert's message. | ||
| 1504 | - #[test] | ||
| 1505 | - fn the_422_block_128rect_chroma_chunk_gather_stays_per_axis() { | ||
| 1506 | - const NAME: &str = "the_422_block_128rect_chroma_chunk_gather_stays_per_axis"; | ||
| 1507 | - let src = crate::test_source::module_source("decode"); | ||
| 1508 | - let body = src | ||
| 1509 | - .split_once("fn decode_block_128rect(") | ||
| 1510 | - .expect("decode_block_128rect must exist") | ||
| 1511 | - .1 | ||
| 1512 | - .split_once("\nfn ") | ||
| 1513 | - .expect("decode_block_128rect must be a top-level fn") | ||
| 1514 | - .0; | ||
| 1515 | - // Scan CODE only: the fix's own comment quotes the guard form, and a | ||
| 1516 | - // prose mention must not read as a reintroduction (nor mask one). | ||
| 1517 | - let stripped: Vec<&str> = body | ||
| 1518 | - .lines() | ||
| 1519 | - .map(|l| l.split_once("//").map_or(l, |(c, _)| c)) | ||
| 1520 | - .collect(); | ||
| 1521 | - let code = stripped.join("\n"); | ||
| 1522 | - let body = code.as_str(); | ||
| 1523 | - assert_eq!( | ||
| 1524 | - body.matches("if ss_x(fctx) == 1 && ss_y(fctx) == 0 {") | ||
| 1525 | - .count(), | ||
| 1526 | - 1, | ||
| 1527 | - "{NAME}: the ss (1, 0) guard over the per-chunk chroma gather must \ | ||
| 1528 | - appear exactly once in decode_block_128rect, found {}", | ||
| 1529 | - body.matches("if ss_x(fctx) == 1 && ss_y(fctx) == 0 {") | ||
| 1530 | - .count() | ||
| 1531 | - ); | ||
| 1532 | - for name in [ | ||
| 1533 | - "neighbours.around_mi_422_chroma(cu_mi, luma_span, luma_span_h)", | ||
| 1534 | - "neighbours.around_mi_rect(cu_mi, luma_span, luma_span_h)", | ||
| 1535 | - ] { | ||
| 1536 | - assert_eq!( | ||
| 1537 | - body.matches(name).count(), | ||
| 1538 | - 1, | ||
| 1539 | - "{NAME}: `{name}` must appear exactly once in \ | ||
| 1540 | - decode_block_128rect's per-chunk chroma gather, found {} -- one \ | ||
| 1541 | - arm has been dropped, so the gather has fallen back to the \ | ||
| 1542 | - square per-mi rule at ss (1, 0)", | ||
| 1543 | - body.matches(name).count() | ||
| 1544 | - ); | ||
| 1545 | - } | ||
| 1546 | - // Reachability arm: the walk must actually RUN at ss (1, 0) on the | ||
| 1547 | - // pinned strips, or the routing above is a no-op the gate cannot see. | ||
| 1548 | - // A stream that stopped coding 128-axis intra blocks reads 0 and this | ||
| 1549 | - // assert fails instead of passing over a decode that never reached | ||
| 1550 | - // the fixed gather (class gate-blind-to-feature). | ||
| 1551 | - for (file, bytes, fp) in [ | ||
| 1552 | - ( | ||
| 1553 | - "422_intrabc_sb128_strip.obu", | ||
| 1554 | - 1672usize, | ||
| 1555 | - 0x50f5cfc576e4cd00_u64, | ||
| 1556 | - ), | ||
| 1557 | - ( | ||
| 1558 | - "422_intrabc_sb128_strip_notxsearch.obu", | ||
| 1559 | - 1675, | ||
| 1560 | - 0xd4936f252ff8cff0, | ||
| 1561 | - ), | ||
| 1562 | - ] { | ||
| 1563 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1564 | - .join("fixtures") | ||
| 1565 | - .join(file); | ||
| 1566 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 1567 | - panic!( | ||
| 1568 | - "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 1569 | - path.display() | ||
| 1570 | - ) | ||
| 1571 | - }); | ||
| 1572 | - assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 1573 | - assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 1574 | - let _guard = lock_gate_counters(); | ||
| 1575 | - let before = crate::decode::sb128rect_chroma_replay_hits(); | ||
| 1576 | - let frames = decode_stream(&data) | ||
| 1577 | - .unwrap_or_else(|e| panic!("{NAME}: {file} no longer decodes cleanly: {e}")); | ||
| 1578 | - let after = crate::decode::sb128rect_chroma_replay_hits(); | ||
| 1579 | - assert_eq!( | ||
| 1580 | - after.0 - before.0, | ||
| 1581 | - 72, | ||
| 1582 | - "{NAME}: {file} gathered {} chroma unit context(s) in \ | ||
| 1583 | - decode_block_128rect's per-chunk walk; 72 were measured at ss (1, 0) -- \ | ||
| 1584 | - a lower number means the gather is no longer REACHED here \ | ||
| 1585 | - (class gate-blind-to-feature)", | ||
| 1586 | - after.0 - before.0 | ||
| 1587 | - ); | ||
| 1588 | - // lane-av1422mismatch9: `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` reads | ||
| 1589 | - // NINE on each of these two pins, and this is the only place that | ||
| 1590 | - // number is asserted. It is NOT a pixel miss, and the three facts | ||
| 1591 | - // below are why -- the assert encodes the measurement, not a wish: | ||
| 1592 | - // | ||
| 1593 | - // 1. The predicate (`decode.rs`, end of `decode_block_128rect`) is | ||
| 1594 | - // `luma_span != luma_span_h` -- `chroma_tx << ss_x` vs | ||
| 1595 | - // `chroma_tx << ss_y`. At ss (1, 0) the two DIFFER BY | ||
| 1596 | - // CONSTRUCTION for every 128-root rect block, so the counter is | ||
| 1597 | - // a shape test ("this is the 4:2:2 span shape"), not a | ||
| 1598 | - // divergence test. Nine is the number of such blocks the five | ||
| 1599 | - // frames code. | ||
| 1600 | - // 2. The replay re-stamps with the SAME per-axis pair the in-loop | ||
| 1601 | - // walk stamped with (`record_mi_chroma(cu_mi, luma_span, | ||
| 1602 | - // luma_span_h, ...)` at both the read walk and the replay), so | ||
| 1603 | - // it rewrites the identical context cells -- this is exactly | ||
| 1604 | - // the `record_mi_chroma(cu_mi, luma_span, luma_span_h)` pairing | ||
| 1605 | - // the source-scan arm above pins. The pre-lane-av1-128rectspan | ||
| 1606 | - // defect (width passed on both axes) is caught by that | ||
| 1607 | - // spelling arm, not by this counter. | ||
| 1608 | - // 3. `record_mi_chroma` writes only `Neighbours::left`/`above` | ||
| 1609 | - // (entropy-context arrays); it touches ZERO pixel samples. So | ||
| 1610 | - // the 9 events cannot write a sample the oracle lacks. The | ||
| 1611 | - // pixel proof is the same file's | ||
| 1612 | - // `the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_ | ||
| 1613 | - // exact`, which pins all five frames byte-exact against | ||
| 1614 | - // ffmpeg's `yuv422p` rawvideo. | ||
| 1615 | - // | ||
| 1616 | - // Change this expected count ONLY with a new measurement; a 4:2:2 | ||
| 1617 | - // stream coding more 128-root rect blocks legitimately changes it. | ||
| 1618 | - assert_eq!( | ||
| 1619 | - after.1 - before.1, | ||
| 1620 | - 9, | ||
| 1621 | - "{NAME}: {file} fired the 4:2:2 span-shape arm {} time(s); NINE were \ | ||
| 1622 | - measured and are NOT a pixel miss (the predicate is `luma_span != \ | ||
| 1623 | - luma_span_h`, true by construction at ss (1,0); the replay re-stamps the \ | ||
| 1624 | - identical context cells with the same per-axis pair; `record_mi_chroma` \ | ||
| 1625 | - writes no pixel) -- see the report above", | ||
| 1626 | - after.1 - before.1 | ||
| 1627 | - ); | ||
| 1628 | - assert_eq!(frames.len(), 5, "{NAME}: {file} frame count"); | ||
| 1629 | - } | ||
| 1630 | - } | ||
| 1631 | - | ||
| 1632 | - /// lane-av1422lpf: the three 4:2:2 LOSSLESS INTER witness fixtures, | ||
| 1633 | - /// PINNED. As of lane-av1422lift they are asserted to DECODE pixel-exact | ||
| 1634 | - /// against ffmpeg (the lane-av1422lift paragraph at the end of this doc); | ||
| 1635 | - /// before the lift this gate asserted the SEQUENCE-HEADER refusal instead. | ||
| 1636 | - /// | ||
| 1637 | - /// W/X/Y (`W_intrabc.obu`, `X_intrabc_tiled.obu`, `Y_intrabc_10b.obu`) are | ||
| 1638 | - /// the streams on which lane-av1422lpf found the seven-site chroma-extent | ||
| 1639 | - /// PANIC family -- each site indexed a block's chroma PLANE BLOCK with | ||
| 1640 | - /// the ENCLOSING SQUARE `max(side >> ss_x, side >> ss_y)` instead of the | ||
| 1641 | - /// PER-AXIS `(bw >> ss_x, bh >> ss_y)` -- so the pins keep the bytes that | ||
| 1642 | - /// witnessed it from silently changing under the gate. | ||
| 1643 | - /// | ||
| 1644 | - /// WHAT THIS GATE DID NOT COVER BEFORE THE LIFT, measured rather than | ||
| 1645 | - /// argued: the refusal it asserted was the HEADER refusal, which fired | ||
| 1646 | - /// BEFORE any of the seven sites is reachable, and it fired IDENTICALLY on | ||
| 1647 | - /// the pre-fix tree (commit `aef4fa67` prints the same string, built and | ||
| 1648 | - /// run for this correction). As a refusal contract the gate was therefore | ||
| 1649 | - /// VACUOUS with respect to the seven-site fix -- it passed before and | ||
| 1650 | - /// after the fix, and its only real content was the three pins. | ||
| 1651 | - /// | ||
| 1652 | - /// That refusal is GONE (lane-av1422lift lifted the sequence-header | ||
| 1653 | - /// refusal), so the decode-level half of the evidence now runs in | ||
| 1654 | - /// committed code: this gate's own byte-exact arm below decodes all three | ||
| 1655 | - /// fixtures against ffmpeg. `EC_AV1_ALLOW_422_PROBE` was only ever the | ||
| 1656 | - /// patch-run-restore bypass for the manual measurement in | ||
| 1657 | - /// `lanes/av1422lpf.report.md`; it is still deliberately not committed. | ||
| 1658 | - /// The source-scan arm | ||
| 1659 | - /// `the_422_lossless_inter_chroma_walk_sites_stay_per_axis` remains the | ||
| 1660 | - /// per-axis SPELLING proof; the pixel proof is now the committed decode. | ||
| 1661 | - /// | ||
| 1662 | - /// CORRECTED by lane-av1422llintra: the name said `..._panics_refuse_ | ||
| 1663 | - /// by_name`, and lane-av1422lpf's report claimed W and X now REFUSE with | ||
| 1664 | - /// `a Golomb tail longer than this decoder reads` at frame 2. That | ||
| 1665 | - /// refusal DOES NOT REPRODUCE on this tip: with the bypass applied, all | ||
| 1666 | - /// three cells DECODE 16/16 -- no panic and no second refusal. | ||
| 1667 | - /// | ||
| 1668 | - /// lane-av1422lift: the three pins are asserted BYTE-EXACT against | ||
| 1669 | - /// ffmpeg's rawvideo of the same bytes, per plane and per frame, with the | ||
| 1670 | - /// per-plane coefficient-unit census as the non-vacuity arm -- so the | ||
| 1671 | - /// three DECODE 16/16 fact the paragraph above records from a bypassed | ||
| 1672 | - /// probe build is now a committed assertion. `Y` is the 10-bit member | ||
| 1673 | - /// and carries the depth-correct HBD compare (`yuv422p10le`, 16-bit | ||
| 1674 | - /// containers on both sides) rather than an 8-bit narrowing of a | ||
| 1675 | - /// high-bit-depth cell. | ||
| 1676 | - #[test] | ||
| 1677 | - fn the_pinned_422_lossless_inter_witnesses_decode_pixel_exact() { | ||
| 1678 | - const NAME: &str = "the_pinned_422_lossless_inter_witnesses_decode_pixel_exact"; | ||
| 1679 | - if !have_ffmpeg() { | ||
| 1680 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1681 | - return; | ||
| 1682 | - } | ||
| 1683 | - for (file, bytes, fp, depth) in [ | ||
| 1684 | - ("W_intrabc.obu", 130_320usize, 0xb6d5c4653a32567a_u64, 8u8), | ||
| 1685 | - ("X_intrabc_tiled.obu", 131_696, 0xb6e04621d2116ef7, 8), | ||
| 1686 | - ("Y_intrabc_10b.obu", 202_281, 0x2ecf03435a14dbf, 10), | ||
| 1687 | - ] { | ||
| 1688 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1689 | - .join("fixtures") | ||
| 1690 | - .join(file); | ||
| 1691 | - let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 1692 | - panic!("{NAME}: pinned witness {file} is missing ({e}) -- the gate cannot run") | ||
| 1693 | - }); | ||
| 1694 | - assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 1695 | - assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 1696 | - assert_422_stream_pixel_exact(NAME, &data, 320, 240, 16, depth, true); | ||
| 1697 | - } | ||
| 1698 | - } | ||
| 1699 | - | ||
| 1700 | - /// lane-av1422lpf: the SOURCE-SCAN arm of the witness gate above -- one | ||
| 1701 | - /// assertion per site, so a mutation at any single site reds exactly that | ||
| 1702 | - /// site and leaves the other six alone. | ||
| 1703 | - /// | ||
| 1704 | - /// Every assertion has a NEGATIVE twin (`forbidden`) and a POSITIVE twin | ||
| 1705 | - /// (`required`), so neither an unreverted site nor a matcher that has | ||
| 1706 | - /// stopped matching can pass: the forbidden string is absent AND the | ||
| 1707 | - /// required string is present in the same function body. The `required` | ||
| 1708 | - /// half is what makes this gate non-vacuous in the | ||
| 1709 | - /// `dead-matcher-positive-control` sense -- a scan that matched nothing | ||
| 1710 | - /// would fail it rather than pass silently. | ||
| 1711 | - /// | ||
| 1712 | - /// WHAT IT DOES NOT COVER: this arm is a SPELLING scan. It cannot observe | ||
| 1713 | - /// a decode, so it cannot prove any cell decodes and cannot prove any | ||
| 1714 | - /// pixel -- the same limit as the witness gate above it, and stated here | ||
| 1715 | - /// because "one assertion per site, each with a mutation proof" reads | ||
| 1716 | - /// like more coverage than it is. | ||
| 1717 | - /// | ||
| 1718 | - /// `strip_code` is the same comment-stripping the arms above use: the | ||
| 1719 | - /// fixes quote their own old expression to say what it was, and a prose | ||
| 1720 | - /// mention must neither read as a reintroduction nor mask one. | ||
| 1721 | - #[test] | ||
| 1722 | - fn the_422_lossless_inter_chroma_walk_sites_stay_per_axis() { | ||
| 1723 | - const NAME: &str = "the_422_lossless_inter_chroma_walk_sites_stay_per_axis"; | ||
| 1724 | - let src = crate::test_source::module_source("decode"); | ||
| 1725 | - let strip_code = |body: &str| -> String { | ||
| 1726 | - body.lines() | ||
| 1727 | - .map(|l| l.split_once("//").map_or(l, |(c, _)| c)) | ||
| 1728 | - .collect::<Vec<_>>() | ||
| 1729 | - .join("\n") | ||
| 1730 | - }; | ||
| 1731 | - // A SECOND form with the same comment stripping but every run of | ||
| 1732 | - // whitespace collapsed to one space, so a matcher can span an argument | ||
| 1733 | - // list that a line-anchored fix's own comment sits inside. Without it | ||
| 1734 | - // the site-5 and site-6 matchers are DEAD: the mutation that reverts | ||
| 1735 | - // them still passes, because the literal being searched for never | ||
| 1736 | - // matched even when the fix was in place. Measured, not assumed -- | ||
| 1737 | - // `verifier-dead-matcher-positive-control`. | ||
| 1738 | - let flatten = |body: &str| -> String { | ||
| 1739 | - strip_code(body) | ||
| 1740 | - .split_whitespace() | ||
| 1741 | - .collect::<Vec<_>>() | ||
| 1742 | - .join(" ") | ||
| 1743 | - }; | ||
| 1744 | - let body_of = |fn_name: &str| -> String { | ||
| 1745 | - let after = src | ||
| 1746 | - .split_once(&format!("\nfn {fn_name}(")) | ||
| 1747 | - .unwrap_or_else(|| panic!("{NAME}: `{fn_name}` must exist in decode.rs")); | ||
| 1748 | - let end = after.1.find("\nfn ").unwrap_or(after.1.len()); | ||
| 1749 | - strip_code(&after.1[..end]) | ||
| 1750 | - }; | ||
| 1751 | - let flat_of = |fn_name: &str| -> String { | ||
| 1752 | - let after = src | ||
| 1753 | - .split_once(&format!("\nfn {fn_name}(")) | ||
| 1754 | - .unwrap_or_else(|| panic!("{NAME}: `{fn_name}` must exist in decode.rs")); | ||
| 1755 | - let end = after.1.find("\nfn ").unwrap_or(after.1.len()); | ||
| 1756 | - flatten(&after.1[..end]) | ||
| 1757 | - }; | ||
| 1758 | - // (label, enclosing fn, forbidden square-cut spelling, required | ||
| 1759 | - // per-axis spelling, required count in that fn) | ||
| 1760 | - let sites: [(&str, &str, &str, &str, usize); 4] = [ | ||
| 1761 | - ( | ||
| 1762 | - "site 1 -- read_inter_chroma_lossless's composed-grid extent", | ||
| 1763 | - "read_inter_chroma_lossless", | ||
| 1764 | - "stride * stride,\n );", | ||
| 1765 | - "stride * blk_h,", | ||
| 1766 | - 1, | ||
| 1767 | - ), | ||
| 1768 | - ( | ||
| 1769 | - "site 7 -- read_intra_chroma_lossless's composed-grid extent", | ||
| 1770 | - "read_intra_chroma_lossless", | ||
| 1771 | - "stride * stride,\n );", | ||
| 1772 | - "stride * blk_h,", | ||
| 1773 | - 1, | ||
| 1774 | - ), | ||
| 1775 | - ( | ||
| 1776 | - "site 4 -- the strip chroma rect's VERT arm at ss (1,0)", | ||
| 1777 | - "decode_inter_block", | ||
| 1778 | - "} else if s.horz {\n (8, 4)\n } else {\n (4, 8)\n }", | ||
| 1779 | - "} else if ss_y(fctx) == 0 {\n (4, 16)\n } else {\n (4, 8)\n }", | ||
| 1780 | - 1, | ||
| 1781 | - ), | ||
| 1782 | - ( | ||
| 1783 | - "site 5 -- the mu-chunk lossless walk's prediction stride", | ||
| 1784 | - "decode_inter_block", | ||
| 1785 | - "(write_chroma_w, write_chroma_h), chroma_side, mode_for_tx,", | ||
| 1786 | - "(write_chroma_w, write_chroma_h), chroma_stride, mode_for_tx,", | ||
| 1787 | - 2, | ||
| 1788 | - ), | ||
| 1789 | - ]; | ||
| 1790 | - for (label, fn_name, forbidden, required, count) in sites { | ||
| 1791 | - // The last table row is written in the flattened form (it spans a | ||
| 1792 | - // comment the fix itself wrote); the others are line-anchored. | ||
| 1793 | - let flattened = required.contains(" mode_for_tx,"); | ||
| 1794 | - let body = if flattened { | ||
| 1795 | - flat_of(fn_name) | ||
| 1796 | - } else { | ||
| 1797 | - body_of(fn_name) | ||
| 1798 | - }; | ||
| 1799 | - assert_eq!( | ||
| 1800 | - body.matches(forbidden).count(), | ||
| 1801 | - 0, | ||
| 1802 | - "{NAME}: {label} is BACK -- the square-cut expression \ | ||
| 1803 | - `{forbidden}` is what this gate exists for" | ||
| 1804 | - ); | ||
| 1805 | - assert!( | ||
| 1806 | - body.matches(required).count() >= count, | ||
| 1807 | - "{NAME}: {label}: the per-axis expression `{required}` must appear \ | ||
| 1808 | - at least {count} time(s) in `{fn_name}` -- found {}", | ||
| 1809 | - body.matches(required).count() | ||
| 1810 | - ); | ||
| 1811 | - } | ||
| 1812 | - // Sites 2, 5 and 6 are the `chroma_side`-vs-`chroma_stride` and | ||
| 1813 | - // `chroma_side`-vs-`chroma_buf_h` argument choices, which are | ||
| 1814 | - // single-token differences on otherwise identical lines. Counting the | ||
| 1815 | - // remaining `chroma_side` uses per arm is the only way to see them, so | ||
| 1816 | - // they get their own exact-count assertions instead of a substring. | ||
| 1817 | - let dib = body_of("decode_inter_block"); | ||
| 1818 | - // Site 2: the lossless TX_4x4 unit replay indexes the composed grid. | ||
| 1819 | - assert_eq!( | ||
| 1820 | - dib.matches("let start = (cr * cu + rr) * chroma_stride + cc * cu;") | ||
| 1821 | - .count(), | ||
| 1822 | - 1, | ||
| 1823 | - "{NAME}: site 2 -- the lossless TX_4x4 replay must index the \ | ||
| 1824 | - composed plane grid at `chroma_stride` (the plane block's own \ | ||
| 1825 | - width), not `chroma_side`" | ||
| 1826 | - ); | ||
| 1827 | - assert_eq!( | ||
| 1828 | - dib.matches("let start = (cr * cu + rr) * chroma_side + cc * cu;") | ||
| 1829 | - .count(), | ||
| 1830 | - 0, | ||
| 1831 | - "{NAME}: site 2 is BACK -- the lossless TX_4x4 replay indexes the \ | ||
| 1832 | - composed grid at the enclosing square again" | ||
| 1833 | - ); | ||
| 1834 | - // Sites 5 and 6. The two mu-chunk walks (the single-reference and the | ||
| 1835 | - // compound twin) take the block's `(write_chroma_w, write_chroma_h)` | ||
| 1836 | - // and the stride SEPARATELY; the two intra-in-inter walks take both | ||
| 1837 | - // the block shape and the region as `(chroma_stride, chroma_buf_h)`. | ||
| 1838 | - // Every one of the four must be per-axis; the pre-fix spelling was | ||
| 1839 | - // the enclosing square `chroma_side` for the stride, and | ||
| 1840 | - // `(chroma_side, chroma_side)` for the intra block shape. | ||
| 1841 | - let dibf = format!( | ||
| 1842 | - "{}{}", | ||
| 1843 | - flat_of("decode_inter_block"), | ||
| 1844 | - flat_of("decode_inter_block_intra_arm"), | ||
| 1845 | - ); // the intra arm was split out of decode_inter_block (av1split D8a) | ||
| 1846 | - assert_eq!( | ||
| 1847 | - dibf.matches("(chroma_stride, chroma_buf_h),").count(), | ||
| 1848 | - 3, | ||
| 1849 | - "{NAME}: site 6 -- the two intra-in-inter walks pass the plane block \ | ||
| 1850 | - as `(chroma_stride, chroma_buf_h)` at all THREE argument positions \ | ||
| 1851 | - it occupies -- the mu-chunk walk's blk shape, and the whole-block walk's blk shape and region -- found {}", | ||
| 1852 | - dibf.matches("(chroma_stride, chroma_buf_h),").count() | ||
| 1853 | - ); | ||
| 1854 | - assert_eq!( | ||
| 1855 | - dibf.matches("(chroma_side, chroma_side),").count(), | ||
| 1856 | - 0, | ||
| 1857 | - "{NAME}: site 6 is BACK -- an intra-in-inter walk still hands the \ | ||
| 1858 | - plane block the enclosing square `chroma_side`" | ||
| 1859 | - ); | ||
| 1860 | - // The geometry the scan cannot see, derived from the same `>> ss` | ||
| 1861 | - // forms the fixes use, so the scan and the fix cannot disagree about | ||
| 1862 | - // what per-axis means at each chroma format. A 16x16 luma block: | ||
| 1863 | - // (side >> ss_x, side >> ss_y) is the plane block and | ||
| 1864 | - // max(side >> ss_x, side >> ss_y) is the enclosing square. | ||
| 1865 | - let plane_block = |side: usize, ss_x: u32, ss_y: u32| (side >> ss_x, side >> ss_y); | ||
| 1866 | - let enclosing = |side: usize, ss_x: u32, ss_y: u32| { | ||
| 1867 | - ( | ||
| 1868 | - (side >> ss_x).max(side >> ss_y), | ||
| 1869 | - (side >> ss_x).max(side >> ss_y), | ||
| 1870 | - ) | ||
| 1871 | - }; | ||
| 1872 | - for (label, side, ss_x, ss_y, block, square) in [ | ||
| 1873 | - ("4:2:0", 16usize, 1u32, 1u32, (8, 8), (8, 8)), | ||
| 1874 | - ("4:2:2", 16, 1, 0, (8, 16), (16, 16)), | ||
| 1875 | - ("4:4:4", 16, 0, 0, (16, 16), (16, 16)), | ||
| 1876 | - ] { | ||
| 1877 | - assert_eq!( | ||
| 1878 | - plane_block(side, ss_x, ss_y), | ||
| 1879 | - block, | ||
| 1880 | - "{NAME}: the {label} chroma plane block of a {side}x{side} luma block" | ||
| 1881 | - ); | ||
| 1882 | - assert_eq!( | ||
| 1883 | - enclosing(side, ss_x, ss_y), | ||
| 1884 | - square, | ||
| 1885 | - "{NAME}: the {label} enclosing chroma square of a {side}x{side} \ | ||
| 1886 | - luma block" | ||
| 1887 | - ); | ||
| 1888 | - } | ||
| 1889 | - // The load-bearing claim of "unchanged at 4:2:0 and 4:4:4": the two | ||
| 1890 | - // are the same number exactly when `ss_x == ss_y`, and DIFFERENT at | ||
| 1891 | - // 4:2:2 -- which is what makes every site above inert there and | ||
| 1892 | - // active at 4:2:2. If this ever held at 4:2:2 the fixes would be | ||
| 1893 | - // untested rather than inert. | ||
| 1894 | - assert_eq!(plane_block(16, 1, 1), enclosing(16, 1, 1)); | ||
| 1895 | - assert_eq!(plane_block(16, 0, 0), enclosing(16, 0, 0)); | ||
| 1896 | - assert_ne!( | ||
| 1897 | - plane_block(16, 1, 0), | ||
| 1898 | - enclosing(16, 1, 0), | ||
| 1899 | - "{NAME}: 4:2:2 must NOT be square -- if the plane block equalled \ | ||
| 1900 | - the enclosing square at ss (1,0), none of these sites could ever \ | ||
| 1901 | - be wrong and the gates above would be measuring nothing" | ||
| 1902 | - ); | ||
| 1903 | - // Site 4's own geometry: a PARTITION_VERT_4 strip is 4x16 luma and | ||
| 1904 | - // pairs on COLUMNS while `ss_x == 1`, so the pair is 8x16 and its | ||
| 1905 | - // plane block is (8 >> ss_x, 16 >> ss_y). | ||
| 1906 | - for (label, ss_x, _ss_y, want) in [ | ||
| 1907 | - ("4:2:0", 1u32, 1u32, (4usize, 8usize)), | ||
| 1908 | - ("4:2:2", 1, 0, (4, 16)), | ||
| 1909 | - ("4:4:4", 0, 0, (8, 16)), | ||
| 1910 | - ] { | ||
| 1911 | - assert_eq!( | ||
| 1912 | - plane_block(8, ss_x, 0).0, | ||
| 1913 | - want.0, | ||
| 1914 | - "{NAME}: site 4 -- the {label} VERT strip pair's chroma width" | ||
| 1915 | - ); | ||
| 1916 | - } | ||
| 1917 | - // ...and the HORZ arm of the same match needs NO third shape at | ||
| 1918 | - // 4:2:2: a HORZ_4 strip pairs on ROWS only while `ss_y == 1`, and | ||
| 1919 | - // 4:2:2 has `ss_y == 0`, so each 16x4 strip is its own chroma | ||
| 1920 | - // reference and its own (8 >> ss_x, 4 >> 0) plane block -- which is | ||
| 1921 | - // the (8, 4) the existing arm already returns. | ||
| 1922 | - assert_eq!( | ||
| 1923 | - (plane_block(16, 1, 0).0, plane_block(4, 1, 0).1), | ||
| 1924 | - (8usize, 4usize), | ||
| 1925 | - "{NAME}: site 4 -- the 4:2:2 HORZ strip's own plane block is already \ | ||
| 1926 | - the (8, 4) the unsplit arm returns, which is why only the VERT arm \ | ||
| 1927 | - gained a shape" | ||
| 1928 | - ); | ||
| 1929 | - } | ||
| 1930 | - | ||
| 1931 | - /// lane-av1422warp: the SECOND 4:2:2 coverage witness -- the one | ||
| 1932 | - /// `422_sb128_3f.obu` could not be, because that stream's inter content | ||
| 1933 | - /// is skip-heavy (see `lanes/av1422stripwrite.report.md`, which named a | ||
| 1934 | - /// second fixture with real residuals, compound and warped motion above | ||
| 1935 | - /// the vertical midpoint as the thing that would justify lifting the | ||
| 1936 | - /// refusal). This is that fixture. | ||
| 1937 | - /// | ||
| 1938 | - /// `422_residual_compound_warp_16f.obu` (38845 bytes), sha256 | ||
| 1939 | - /// `d78e2afb43ce311d3d82335a945c6f80f62db4537966d881c1349a68b3aecb95`: | ||
| 1940 | - /// | ||
| 1941 | - /// ```text | ||
| 1942 | - /// ffmpeg -f lavfi -i "mandelbrot=size=256x288:rate=24:maxiter=220:start_scale=3:end_scale=0.35:end_pts=300,rotate=a=0.10*t:c=none:ow=256:oh=288" \ | ||
| 1943 | - /// -frames:v 24 -pix_fmt yuv422p -f yuv4mpegpipe src422.y4m | ||
| 1944 | - /// aomenc --codec=av1 --profile=2 --input-bit-depth=8 --limit=16 | ||
| 1945 | - /// --width=256 --height=288 --lag-in-frames=25 --auto-alt-ref=1 | ||
| 1946 | - /// --enable-global-motion=1 --pass=1 | ||
| 1947 | - /// --cq-level=24 --cpu-used=0 | ||
| 1948 | - /// --threads=4 --kf-min-dist=0 --kf-max-dist=999999 \ | ||
| 1949 | - /// src422.y4m -o a1.webm | ||
| 1950 | - /// ffmpeg -i a1.webm -c copy -f obu -y a1.obu | ||
| 1951 | - /// ``` | ||
| 1952 | - /// | ||
| 1953 | - /// CORRECTED by lane-av1422lrless (reviewer P2). This doc previously | ||
| 1954 | - /// carried a different ffmpeg filter (`rotate=a=0.10`, no `*t`, no | ||
| 1955 | - /// `:c=none:ow/oh`) and a `-n ffp --pass=2 --fpf=...` two-pass line. | ||
| 1956 | - /// **Neither produced these bytes.** Re-encoding from the recorded | ||
| 1957 | - /// source `src422.y4m` (sha256 | ||
| 1958 | - /// `4d35eaf65d1a5541b3177e1183644c163b3868d8f141bed0ce9fdf833280ba9f`) | ||
| 1959 | - /// was measured three ways: the two-pass form gives 38774 bytes | ||
| 1960 | - /// (`e93c4ed7...`), and only adding `--pass=1` reproduces these 38845 | ||
| 1961 | - /// bytes byte for byte (`d78e2afb...`). `aomenc` DEFAULTS to two-pass, | ||
| 1962 | - /// so the flag has to be stated to get back the pinned stream. The | ||
| 1963 | - /// recipe above is the one that was actually run. | ||
| 1964 | - /// | ||
| 1965 | - /// Measured on a patch-run-restore build (the `EC_AV1_ALLOW_422_PROBE` | ||
| 1966 | - /// bypass applied for the run, reverted after -- it is deliberately NOT | ||
| 1967 | - /// committed). This block is the bypassed measurement; the committed | ||
| 1968 | - /// assertion is now the byte-exact compare in the lane-av1422lift | ||
| 1969 | - /// paragraph below: | ||
| 1970 | - /// | ||
| 1971 | - /// - all 16 frames pixel-exact against `aomdec --rawvideo`, 2359296 | ||
| 1972 | - /// bytes each, sha256 `4bfc2395e5ca6ea178f606e6b1ced773e26fc2d85b | ||
| 1973 | - /// c3a6cdb63a402939aeb203` on both sides; | ||
| 1974 | - /// - the entropy stream pairs bit-for-bit against the instrumented | ||
| 1975 | - /// oracle -- 246735 symbol reads each, no divergence anywhere in the | ||
| 1976 | - /// stream, not merely at the window this lane spent nine rounds | ||
| 1977 | - /// narrowing; | ||
| 1978 | - /// - the arms this fixture exists to cover really fire ABOVE the | ||
| 1979 | - /// vertical midpoint: 3 upper-half blocks on a non-`TRANSLATION` | ||
| 1980 | - /// global-motion model (`top_half_warp_hits`, gated on libaom's | ||
| 1981 | - /// `is_global_mv_block` per slot) and 3 upper-half | ||
| 1982 | - /// `GLOBAL_GLOBALMV` compound blocks (`top_half_compound_hits`), | ||
| 1983 | - /// alongside 25 compound-warp, 18 compound-warp-8x8-leaf, 84 | ||
| 1984 | - /// rotzoom global-warp, 22 Wiener and 10 SGRPROJ loop-restoration | ||
| 1985 | - /// units frame-globally. | ||
| 1986 | - /// | ||
| 1987 | - /// The loop-restoration numbers are load-bearing twice over: decoding | ||
| 1988 | - /// this stream is what exposed the per-axis `read_lr` corner bug | ||
| 1989 | - /// (`restoration.rs`, `av1_loop_restoration_corners_in_sb`), whose fix | ||
| 1990 | - /// is what made the whole sequence pair. 4:2:0 and 4:4:4 are unchanged | ||
| 1991 | - /// by it -- byte-identical to their pre-lane decodes, with the LR gate | ||
| 1992 | - /// family green. | ||
| 1993 | - /// | ||
| 1994 | - /// lane-av1422lift: the committed assertion is now the byte pin AND | ||
| 1995 | - /// byte-exactness against ffmpeg's `yuv422p` rawvideo of the same bytes, | ||
| 1996 | - /// per plane and per frame, with the per-plane coefficient-unit census | ||
| 1997 | - /// as the non-vacuity arm. The paragraph above's coverage counts (25 | ||
| 1998 | - /// compound-warp, 84 rotzoom global-warp, 22 Wiener, 10 SGRPROJ, CDEF | ||
| 1999 | - /// 39) are what make the row non-vacuous: without them a byte-exact | ||
| 2000 | - /// compare could be green over a stream that never entered a warp arm. | ||
crates/ec-av1/src/stream/tests/t02.rsdeleted+0 -4341
Diff too large; view file
| @@ -1,4341 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | -use super::gates_a::*; | ||
| 4 | -use crate::encode::{Picture as Pic, encode_key_frame_with_ctx, encode_sequence_with_ctx}; | ||
| 5 | -use crate::probe::run_with_stdin; | ||
| 6 | -use std::process::{Command, Stdio}; | ||
| 7 | - | ||
| 8 | - /// lane-av1oracledepth: the depth-generic 4:4:4 oracle comparator, armed | ||
| 9 | - /// on the same pinned 10-bit 4:4:4 cell | ||
| 10 | - /// `a_444_lossy_palette_chroma_unit_window_is_byte_exact_at_352x242_10bit` | ||
| 11 | - /// gates (fixture sha256 | ||
| 12 | - /// `84df2f37cc7982f9a572443d85dfcc13bf366a64f3fb567391dcd5acd58a0ad2`): | ||
| 13 | - /// every plane of every SHOWN frame must come back byte-exact against | ||
| 14 | - /// ffmpeg's `yuv444p10le` rawvideo of the same bytes, with the depth read | ||
| 15 | - /// from the stream's own sequence header, never assumed. | ||
| 16 | - /// | ||
| 17 | - /// The flip control is the crate's own comparator-liveness shape (the | ||
| 18 | - /// same one | ||
| 19 | - /// [`every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg`] runs for | ||
| 20 | - /// the other helpers): with a thread-local ffmpeg shim that rotates ONE | ||
| 21 | - /// byte of the oracle's own rawvideo stdout, the compare must move from | ||
| 22 | - /// 0 to EXACTLY 1 differing sample in the tampered plane and stay at 0 in | ||
| 23 | - /// the other two -- a comparator that cannot see a one-sample difference | ||
| 24 | - /// would make every "byte-exact" claim above vacuous. | ||
| 25 | - #[test] | ||
| 26 | - fn the_444_depth_helper_is_byte_exact_on_a_pinned_10bit_444_cell() { | ||
| 27 | - const NAME: &str = "the_444_depth_helper_is_byte_exact_on_a_pinned_10bit_444_cell"; | ||
| 28 | - if !have_ffmpeg() { | ||
| 29 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 30 | - return; | ||
| 31 | - } | ||
| 32 | - let _gate_lock = lock_gate_counters(); | ||
| 33 | - let path = crate_pin("444_lossy_palette_chroma_352x242_10b.obu"); | ||
| 34 | - let stream = read_pin(&path, 24875, 0x7fda_dbb4_3bbf_9af3, NAME); | ||
| 35 | - // The fixture is 16 SHOWN frames; ffmpeg's rawvideo muxer emits shown | ||
| 36 | - // frames only, and so does decode_stream's return. | ||
| 37 | - const W: usize = 352; | ||
| 38 | - const H: usize = 242; | ||
| 39 | - const FRAMES: usize = 16; | ||
| 40 | - assert_eq!(stream_bit_depth(&stream, NAME), 10, "{NAME}: pin depth"); | ||
| 41 | - let ours = decode_stream(&stream) | ||
| 42 | - .unwrap_or_else(|e| panic!("{NAME}: the pinned 10-bit 4:4:4 cell was refused: {e}")); | ||
| 43 | - assert_eq!(ours.len(), FRAMES, "{NAME}: decoded frame count"); | ||
| 44 | - let theirs = ffmpeg_decode_sequence_444_depth(&stream, W, H, FRAMES, 10, "yuv444p10le"); | ||
| 45 | - for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | ||
| 46 | - for (plane, x, y) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | ||
| 47 | - if let Some(at) = x.iter().zip(y).position(|(p, q)| p != q) { | ||
| 48 | - panic!( | ||
| 49 | - "{NAME}: {plane} differs from ffmpeg's yuv444p10le at frame {i} sample \ | ||
| 50 | - {at} (ours {} vs {}); {n} of {m} samples differ", | ||
| 51 | - x[at], | ||
| 52 | - y[at], | ||
| 53 | - n = x.iter().zip(y).filter(|(p, q)| p != q).count(), | ||
| 54 | - m = x.len() | ||
| 55 | - ); | ||
| 56 | - } | ||
| 57 | - } | ||
| 58 | - } | ||
| 59 | - eprintln!( | ||
| 60 | - "{NAME}: {FRAMES} shown frames byte-exact vs ffmpeg yuv444p10le on the pinned \ | ||
| 61 | - 10-bit 4:4:4 cell" | ||
| 62 | - ); | ||
| 63 | - | ||
| 64 | - // ---- the flip control: one wrong oracle sample must move the count | ||
| 65 | - // 0 -> 1 in exactly the tampered plane ------------------------- | ||
| 66 | - let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 67 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 68 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 69 | - let real = if let Some(p) = std::env::var_os("EC_AV1_FFMPEG") { | ||
| 70 | - std::path::PathBuf::from(p) | ||
| 71 | - } else { | ||
| 72 | - let found = Command::new("ffmpeg") | ||
| 73 | - .arg("-version") | ||
| 74 | - .stdout(Stdio::null()) | ||
| 75 | - .stderr(Stdio::null()) | ||
| 76 | - .status() | ||
| 77 | - .is_ok_and(|s| s.success()); | ||
| 78 | - assert!(found, "{NAME}: no working ffmpeg on PATH to wrap"); | ||
| 79 | - let path_env = std::env::var_os("PATH").unwrap_or_default(); | ||
| 80 | - std::env::split_paths(&path_env) | ||
| 81 | - .map(|d| d.join("ffmpeg")) | ||
| 82 | - .find(|p| p.is_file()) | ||
| 83 | - .expect("{NAME}: ffmpeg is on PATH but not resolvable to a file") | ||
| 84 | - }; | ||
| 85 | - std::fs::write(dir.join("real-ffmpeg"), real.as_os_str().as_encoded_bytes()) | ||
| 86 | - .expect("recording the real ffmpeg's path for the shim"); | ||
| 87 | - let script = r#"#!/bin/sh | ||
| 88 | -REAL=$(cat "$(dirname "$0")/real-ffmpeg") | ||
| 89 | -OUT=$(mktemp) | ||
| 90 | -"$REAL" "$@" > "$OUT" || exit $? | ||
| 91 | -while read -r o; do | ||
| 92 | - [ -n "$o" ] || continue | ||
| 93 | - b=$(od -An -tu1 -j "$o" -N 1 "$OUT" 2>/dev/null | tr -d ' \n') | ||
| 94 | - [ -n "$b" ] || continue | ||
| 95 | - esc=$(printf '\\%03o' $(( (b + 128) % 256 ))) | ||
| 96 | - printf "$esc" | dd of="$OUT" bs=1 seek="$o" count=1 conv=notrunc 2>/dev/null | ||
| 97 | -done < "$(dirname "$0")/offsets" | ||
| 98 | -cat "$OUT" | ||
| 99 | -rm -f "$OUT" | ||
| 100 | -exit 0 | ||
| 101 | -"#; | ||
| 102 | - let shim = dir.join("one-sample-wrong-ffmpeg.sh"); | ||
| 103 | - std::fs::write(&shim, script).expect("writing the ffmpeg shim"); | ||
| 104 | - #[cfg(unix)] | ||
| 105 | - { | ||
| 106 | - use std::os::unix::fs::PermissionsExt; | ||
| 107 | - std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)) | ||
| 108 | - .expect("the ffmpeg shim must be executable"); | ||
| 109 | - } | ||
| 110 | - let set_offsets = |bytes: &[usize]| { | ||
| 111 | - let body: String = bytes | ||
| 112 | - .iter() | ||
| 113 | - .map(|b| format!("{b}\n")) | ||
| 114 | - .collect::<Vec<_>>() | ||
| 115 | - .concat(); | ||
| 116 | - std::fs::write(dir.join("offsets"), body).expect("writing the offsets file"); | ||
| 117 | - }; | ||
| 118 | - let count = |theirs_t: &[Pic]| -> [usize; 3] { | ||
| 119 | - let mut wrong = [0usize; 3]; | ||
| 120 | - for (a, b) in ours.iter().zip(theirs_t) { | ||
| 121 | - for (plane, (x, y)) in | ||
| 122 | - [(0usize, (&a.y, &b.y)), (1, (&a.u, &b.u)), (2, (&a.v, &b.v))] | ||
| 123 | - { | ||
| 124 | - wrong[plane] += x.iter().zip(y).filter(|(p, q)| p != q).count(); | ||
| 125 | - } | ||
| 126 | - } | ||
| 127 | - wrong | ||
| 128 | - }; | ||
| 129 | - // Frame bytes are 3 planes x W*H samples x 2 bytes (10-bit container). | ||
| 130 | - let plane_bytes = W * H * 2; | ||
| 131 | - let mut blind: Vec<String> = Vec::new(); | ||
| 132 | - set_ffmpeg_path(Some(shim.clone())); | ||
| 133 | - for (plane, base) in [("Y", 0usize), ("U", plane_bytes), ("V", 2 * plane_bytes)] { | ||
| 134 | - // Byte 2000 of the named plane: sample 1000, still frame 0 on | ||
| 135 | - // every plane at this geometry. | ||
| 136 | - set_offsets(&[base + 2000]); | ||
| 137 | - let theirs_t = | ||
| 138 | - ffmpeg_decode_sequence_444_depth(&stream, W, H, FRAMES, 10, "yuv444p10le"); | ||
| 139 | - let got = count(&theirs_t); | ||
| 140 | - let mut expected = [0usize, 0, 0]; | ||
| 141 | - expected[match plane { | ||
| 142 | - "Y" => 0, | ||
| 143 | - "U" => 1, | ||
| 144 | - _ => 2, | ||
| 145 | - }] = 1; | ||
| 146 | - if got != expected { | ||
| 147 | - blind.push(format!( | ||
| 148 | - "{plane} arm: counted {got:?}, expected {expected:?} (exactly the one \ | ||
| 149 | - tampered sample)" | ||
| 150 | - )); | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - set_ffmpeg_path(None); | ||
| 154 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 155 | - assert!( | ||
| 156 | - blind.is_empty(), | ||
| 157 | - "{NAME}: {} of 3 flip arms stayed GREEN against an ffmpeg that is wrong by exactly \ | ||
| 158 | - one sample -- {blind:#?} -- the comparator cannot see a difference, so its \ | ||
| 159 | - byte-exact verdict proves nothing (class comparator-that-never-reads-the-oracle)", | ||
| 160 | - blind.len() | ||
| 161 | - ); | ||
| 162 | - eprintln!( | ||
| 163 | - "{NAME}: flip control bites on Y, U and V separately (0 -> 1 per tampered plane)" | ||
| 164 | - ); | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - /// lane-av1oracledepth: `ffmpeg_decode_sequence_10bit` must REFUSE a | ||
| 168 | - /// wrong-depth stream by the stream's OWN sequence header, the way the | ||
| 169 | - /// 12-bit gates read `assert_12bit_sequence_header`. An 8-bit 4:2:0 | ||
| 170 | - /// stream handed to the 10-bit helper is the wrong-depth shape: ffmpeg | ||
| 171 | - /// converts it to `yuv420p10le` and sizes no plane differently, so | ||
| 172 | - /// without the depth assert a gate could compare a converted 8-bit | ||
| 173 | - /// reference against our 10-bit decode and read exact. | ||
| 174 | - #[test] | ||
| 175 | - fn the_10bit_oracle_helper_refuses_a_wrong_depth_stream() { | ||
| 176 | - const NAME: &str = "the_10bit_oracle_helper_refuses_a_wrong_depth_stream"; | ||
| 177 | - let _gate_lock = lock_gate_counters(); | ||
| 178 | - let path = crate_pin("mix176_offtile_chroma_clip.obu"); | ||
| 179 | - let stream = read_pin(&path, 4581, 0x5e31be5efc9c3c1d, NAME); | ||
| 180 | - assert_eq!( | ||
| 181 | - stream_bit_depth(&stream, NAME), | ||
| 182 | - 8, | ||
| 183 | - "{NAME}: the control pin must really be 8-bit, or this proves nothing" | ||
| 184 | - ); | ||
| 185 | - assert_eq!( | ||
| 186 | - stream_subsampling(&stream, NAME), | ||
| 187 | - (1, 1), | ||
| 188 | - "{NAME}: the control pin must really be 4:2:0, or the refusal below could be the \ | ||
| 189 | - shape guard instead of the depth guard" | ||
| 190 | - ); | ||
| 191 | - let msg = panic_message(|| { | ||
| 192 | - ffmpeg_decode_sequence_10bit(&stream, 176, 144, 1); | ||
| 193 | - }) | ||
| 194 | - .unwrap_or_else(|| { | ||
| 195 | - panic!( | ||
| 196 | - "{NAME}: ffmpeg_decode_sequence_10bit ACCEPTED an 8-bit stream -- ffmpeg \ | ||
| 197 | - converted it to yuv420p10le and the helper returned a comparison that could \ | ||
| 198 | - pass green" | ||
| 199 | - ) | ||
| 200 | - }); | ||
| 201 | - assert!( | ||
| 202 | - msg.contains("not 10-bit"), | ||
| 203 | - "{NAME}: the refusal must name the depth guard (\"not 10-bit\"); it said: {msg}" | ||
| 204 | - ); | ||
| 205 | - eprintln!("{NAME}: refused -> {msg}"); | ||
| 206 | - } | ||
| 207 | - | ||
| 208 | - /// lane-av1rawhelper: `assert_rawvideo_matches` used to pack our samples | ||
| 209 | - /// as `u16` for EVERY stream, while `aomdec --rawvideo` writes 8 bits | ||
| 210 | - /// per sample for an 8-bit stream. An 8-bit caller therefore died on a | ||
| 211 | - /// raw-SIZE assertion (2359296 vs 1179648) without comparing a single | ||
| 212 | - /// sample, and a high-bitdepth caller was the only one that could work. | ||
| 213 | - /// | ||
| 214 | - /// Two arms, both on a real `aomenc` 8-bit stream: | ||
| 215 | - /// | ||
| 216 | - /// 1. the correct label compares real samples -- the byte counts it | ||
| 217 | - /// walks equal the oracle's, so every `u8` in the 8-bit pack is | ||
| 218 | - /// zipped against a real oracle byte; | ||
| 219 | - /// 2. a WRONG label fails by name, quoting both depths and the fact that | ||
| 220 | - /// the pack would compare nothing, rather than by size. Arm 2 is what | ||
| 221 | - /// keeps arm 1 from being a green that a reverted check would also | ||
| 222 | - /// give. | ||
| 223 | - #[test] | ||
| 224 | - fn the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth() { | ||
| 225 | - const NAME: &str = "the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth"; | ||
| 226 | - let _gate_lock = lock_gate_counters(); | ||
| 227 | - if !have_aomenc() || !have_ffmpeg() { | ||
| 228 | - eprintln!("SKIP {NAME}: no aomenc/aomdec oracle or no ffmpeg"); | ||
| 229 | - return; | ||
| 230 | - } | ||
| 231 | - let (w, h) = (192usize, 128usize); | ||
| 232 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 233 | - .args([ | ||
| 234 | - "-v", | ||
| 235 | - "error", | ||
| 236 | - "-f", | ||
| 237 | - "lavfi", | ||
| 238 | - "-i", | ||
| 239 | - &gradients_source(7, w, h, "duration=0.24:rate=25"), | ||
| 240 | - "-pix_fmt", | ||
| 241 | - "yuv420p", | ||
| 242 | - "-t", | ||
| 243 | - "0.24", | ||
| 244 | - "-f", | ||
| 245 | - "yuv4mpegpipe", | ||
| 246 | - "-", | ||
| 247 | - ]) | ||
| 248 | - .stdin(Stdio::null()) | ||
| 249 | - .stdout(Stdio::piped()) | ||
| 250 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 251 | - .expect("ffmpeg failed to run"); | ||
| 252 | - assert!( | ||
| 253 | - y4m.status.success(), | ||
| 254 | - "{NAME}: ffmpeg fixture: {}", | ||
| 255 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 256 | - ); | ||
| 257 | - let args: Vec<&str> = vec![ | ||
| 258 | - "--codec=av1", | ||
| 259 | - "--passes=1", | ||
| 260 | - "--end-usage=q", | ||
| 261 | - "--cq-level=40", | ||
| 262 | - "--cpu-used=2", | ||
| 263 | - "--threads=1", | ||
| 264 | - "--row-mt=0", | ||
| 265 | - "--limit=6", | ||
| 266 | - "--obu", | ||
| 267 | - "-o", | ||
| 268 | - "-", | ||
| 269 | - "-", | ||
| 270 | - ]; | ||
| 271 | - let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 272 | - assert!( | ||
| 273 | - out.status.success(), | ||
| 274 | - "{NAME}: aomenc refused the fixture: {}", | ||
| 275 | - String::from_utf8_lossy(&out.stderr) | ||
| 276 | - ); | ||
| 277 | - let stream = out.stdout; | ||
| 278 | - assert_eq!( | ||
| 279 | - stream_bit_depth(&stream, NAME), | ||
| 280 | - 8, | ||
| 281 | - "{NAME}: the fixture must really be 8-bit, or this gate measures nothing" | ||
| 282 | - ); | ||
| 283 | - let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-raw8-{}", std::process::id())); | ||
| 284 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 285 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 286 | - let obu = dir.join("in.obu"); | ||
| 287 | - std::fs::write(&obu, &stream).expect("writing the stream"); | ||
| 288 | - let frames = decode_stream(&stream) | ||
| 289 | - .unwrap_or_else(|e| panic!("{NAME}: the 8-bit stream no longer decodes: {e}")) | ||
| 290 | - .len(); | ||
| 291 | - assert!(frames > 0, "{NAME}: nothing decoded"); | ||
| 292 | - | ||
| 293 | - // ARM 2 first: the wrong label must be refused BY NAME. A helper that | ||
| 294 | - // packed u16 unconditionally got this far and then failed on size. | ||
| 295 | - let wrong = std::panic::catch_unwind(|| { | ||
| 296 | - assert_rawvideo_matches(&obu, &stream, NAME, frames, 10); | ||
| 297 | - }); | ||
| 298 | - let boom = wrong | ||
| 299 | - .err() | ||
| 300 | - .map(|e| e.downcast_ref::<String>().cloned().unwrap_or_default()) | ||
| 301 | - .unwrap_or_default(); | ||
| 302 | - assert!( | ||
| 303 | - boom.contains("sequence header says 8-bit") && boom.contains("compares nothing"), | ||
| 304 | - "{NAME}: a 10-bit label on an 8-bit stream must be refused by the depth check \ | ||
| 305 | - naming both depths; the panic read: {boom}" | ||
| 306 | - ); | ||
| 307 | - | ||
| 308 | - // ARM 1: the correct label compares real samples. The pre-fix helper | ||
| 309 | - // reached a size mismatch here (ours 2x the oracle); reaching the | ||
| 310 | - // sample compare is what this arm proves. | ||
| 311 | - assert_rawvideo_matches(&obu, &stream, NAME, frames, 8); | ||
| 312 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 313 | - eprintln!("{NAME}: {frames} 8-bit frame(s) byte-identical to aomdec --rawvideo"); | ||
| 314 | - } | ||
| 315 | - | ||
| 316 | - /// lane-svtinter: an SVT-AV1 screen stream whose frame height is not a | ||
| 317 | - /// multiple of the superblock size codes PALETTE blocks in the bottom | ||
| 318 | - /// (and right) superblock row that hang off the mi grid. Spec 5.11.50 | ||
| 319 | - /// `palette_tokens` reads the colour-index map only over the block's | ||
| 320 | - /// `onscreenWidth x onscreenHeight` corner and replicates it outward; | ||
| 321 | - /// this decoder read the full block grid, so it consumed colour-index | ||
| 322 | - /// symbols libaom never wrote and desynced the rest of the tile -- either | ||
| 323 | - /// a wrong bottom superblock row (1599 luma samples in this stream's | ||
| 324 | - /// frame 0, ~80k per inter frame after) or, further along the same tile, | ||
| 325 | - /// a bogus "a Golomb tail longer than this decoder reads" refusal. | ||
| 326 | - /// | ||
| 327 | - /// Unlike its lane-svt1 sibling above this one BUILDS its stream: the | ||
| 328 | - /// recipe is synthetic (`smptebars,drawgrid` through `libsvtav1 -preset 8 | ||
| 329 | - /// -svtav1-params screen-content-mode=1`), and 384x152 puts a 32x32 | ||
| 330 | - /// palette block at mi row 32 of a 38-mi-tall frame, 24 of its 32 rows | ||
| 331 | - /// on screen. `palette_onscreen_cut_hits` is asserted non-zero so the row | ||
| 332 | - /// cannot pass on a stream that never cuts a palette map (class | ||
| 333 | - /// gate-blind-to-feature). | ||
| 334 | - #[test] | ||
| 335 | - fn an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly() { | ||
| 336 | - const NAME: &str = "an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly"; | ||
| 337 | - if !have_ffmpeg() { | ||
| 338 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 339 | - return; | ||
| 340 | - } | ||
| 341 | - let (width, height) = (384usize, 152usize); | ||
| 342 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 343 | - .args([ | ||
| 344 | - "-v", | ||
| 345 | - "error", | ||
| 346 | - "-f", | ||
| 347 | - "lavfi", | ||
| 348 | - "-i", | ||
| 349 | - "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black", | ||
| 350 | - "-frames:v", | ||
| 351 | - "4", | ||
| 352 | - "-c:v", | ||
| 353 | - "libsvtav1", | ||
| 354 | - "-preset", | ||
| 355 | - "8", | ||
| 356 | - "-crf", | ||
| 357 | - "30", | ||
| 358 | - "-svtav1-params", | ||
| 359 | - "lp=1:screen-content-mode=1", | ||
| 360 | - "-g", | ||
| 361 | - "12", | ||
| 362 | - "-f", | ||
| 363 | - "obu", | ||
| 364 | - "-", | ||
| 365 | - ]) | ||
| 366 | - .stdin(Stdio::null()) | ||
| 367 | - .stdout(Stdio::piped()) | ||
| 368 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 369 | - .expect("ffmpeg failed to run"); | ||
| 370 | - if !out.status.success() || out.stdout.is_empty() { | ||
| 371 | - eprintln!( | ||
| 372 | - "SKIP {NAME}: no libsvtav1 in this ffmpeg: {}", | ||
| 373 | - String::from_utf8_lossy(&out.stderr) | ||
| 374 | - ); | ||
| 375 | - return; | ||
| 376 | - } | ||
| 377 | - let stream = out.stdout; | ||
| 378 | - crate::decode::reset_palette_onscreen_cut_hits(); | ||
| 379 | - let decoded = decode_stream(&stream).expect("the SVT-AV1 screen stream decodes"); | ||
| 380 | - assert_eq!(decoded.len(), 4, "{NAME}: frame count"); | ||
| 381 | - assert!( | ||
| 382 | - crate::decode::palette_onscreen_cut_hits() > 0, | ||
| 383 | - "{NAME}: no palette map is cut by the frame edge here -- the gate would pass blind" | ||
| 384 | - ); | ||
| 385 | - let want = ffmpeg_decode_sequence(&stream, width, height, decoded.len()); | ||
| 386 | - assert_eq!(want.len(), decoded.len(), "{NAME}: ffmpeg frame count"); | ||
| 387 | - for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { | ||
| 388 | - assert_eq!(got.y, want.y, "{NAME}: frame {i} luma vs ffmpeg"); | ||
| 389 | - assert_eq!(got.u, want.u, "{NAME}: frame {i} U vs ffmpeg"); | ||
| 390 | - assert_eq!(got.v, want.v, "{NAME}: frame {i} V vs ffmpeg"); | ||
| 391 | - } | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8`) screen key frame codes 16x16 | ||
| 395 | - /// PALETTE blocks with `skip == 1` whose `tx_depth` split the luma | ||
| 396 | - /// transform. [`crate::decode::decode_block`] armed the palette prediction | ||
| 397 | - /// only when the transform covered the whole block, so that one block | ||
| 398 | - /// predicted DC off its own edges instead: the right symbols (the whole mode | ||
| 399 | - /// ladder diffs clean against an instrumented aomdec) and the wrong pixels | ||
| 400 | - /// -- 812 luma samples in frame 0, carried by the V_PRED blocks under it to | ||
| 401 | - /// 10122 samples over the 12-frame stream the defect was found on. | ||
| 402 | - /// | ||
| 403 | - /// lane-av1pinspec2: the gate used to RIDE an external crop named by | ||
| 404 | - /// `EC_AV1_SVT1_STREAM` and SKIP when that was unset, so it never ran on a | ||
| 405 | - /// stock box -- which is exactly why its oracle count could not be pinned | ||
| 406 | - /// (an assert on a gate that never executes is an unexercised assert wearing | ||
| 407 | - /// a pin's clothes). It now runs on the COMMITTED pin | ||
| 408 | - /// `crates/ec-av1/fixtures/svt1-split-tx-pin.obu`. | ||
| 409 | - /// | ||
| 410 | - /// The pin is a REPLAY, not a fresh capture, and the recipe is recorded | ||
| 411 | - /// because it reproduces the bytes exactly (two independent encodes on this | ||
| 412 | - /// box, SVT-AV1 v3.1.2, both sha256 | ||
| 413 | - /// `c9d9c0ae934fba72fc9a9374bc36853f290796a8a4d6442140e239669e0b341f`, | ||
| 414 | - /// 1838 bytes): | ||
| 415 | - /// | ||
| 416 | - /// ffmpeg -v error -f lavfi \ | ||
| 417 | - /// -i "smptehdbars=s=192x152:r=12,drawgrid=w=8:h=8:t=1:c=black" \ | ||
| 418 | - /// -frames:v 1 -c:v libsvtav1 -preset 8 -crf 50 \ | ||
| 419 | - /// -svtav1-params "lp=1:screen-content-mode=1" -g 12 -f obu out.obu | ||
| 420 | - /// | ||
| 421 | - /// `-frames:v 1` is the part lane-svt1's search lacked: its 6x5x6 sweep ran | ||
| 422 | - /// FOUR frames per stream, and the ~200k-sample misses that killed every | ||
| 423 | - /// candidate were on the INTER frames (`lanes/svt1.report.md`). One key | ||
| 424 | - /// frame has no inter frames, and this one reaches the fixed arm | ||
| 425 | - /// (`skip_split_tx_override_hits == 1`) and is pixel-exact. | ||
| 426 | - /// | ||
| 427 | - /// THE COUNT, and why it is derived from the wire rather than from a | ||
| 428 | - /// literal. The oracle is handed the number of frame OBUs this stream | ||
| 429 | - /// actually codes, counted with `Av1Parser` below -- never our decode's | ||
| 430 | - /// length, which is the thing under test. A header count would OVER-count | ||
| 431 | - /// a stream carrying `show_existing_frame` (spec 5.9.5: it codes no pixels, | ||
| 432 | - /// so the header count is larger than the shown-frame count), so that case | ||
| 433 | - /// is asserted impossible on this pin rather than assumed: the loop refuses | ||
| 434 | - /// any frame header with `show_existing_frame` set, which is what makes | ||
| 435 | - /// "one header == one shown frame" a checked fact here instead of an | ||
| 436 | - /// argument. | ||
| 437 | - /// | ||
| 438 | - /// `EC_AV1_SVT1_STREAM` still overrides the pin, so a re-capture is one env | ||
| 439 | - /// var away; `crate_pin` falls back to `pin_dir()` for the same reason. | ||
| 440 | - /// | ||
| 441 | - /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot | ||
| 442 | - /// pass on a stream that never reaches the fixed arm (class | ||
| 443 | - /// gate-blind-to-feature). | ||
| 444 | - #[test] | ||
| 445 | - fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() { | ||
| 446 | - const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly"; | ||
| 447 | - const PIN: &str = "svt1-split-tx-pin.obu"; | ||
| 448 | - if !have_ffmpeg() { | ||
| 449 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 450 | - return; | ||
| 451 | - } | ||
| 452 | - let path = match std::env::var("EC_AV1_SVT1_STREAM") { | ||
| 453 | - Ok(p) => std::path::PathBuf::from(p), | ||
| 454 | - // The name is spelled as a LITERAL here even though `PIN` is right | ||
| 455 | - // above, on purpose: `gate_coverage::pin_inventory` matches a pin | ||
| 456 | - // read by the quote that follows the callee name, so a const | ||
| 457 | - // argument would leave this pin outside the "every pin a gate reads | ||
| 458 | - // is a committed crate-local copy" invariant. The dup is the | ||
| 459 | - // coverage -- and it is also why this comment must NOT quote that | ||
| 460 | - // spelling: the scanner reads prose too, and a quoted spelling here | ||
| 461 | - // parses as a pin called " and would not see a const argument, ...". | ||
| 462 | - Err(_) => crate_pin("svt1-split-tx-pin.obu"), | ||
| 463 | - }; | ||
| 464 | - let data = require_pin(&path, PIN); | ||
| 465 | - // The ENCODE's frame count, read off the WIRE: parse this stream's own | ||
| 466 | - // OBUs and count the frame headers. `show_existing_frame` is refused | ||
| 467 | - // here on purpose -- such a header codes no pixels, so counting it | ||
| 468 | - // would make this count larger than the frames the oracle can decode. | ||
| 469 | - let mut parser = Av1Parser::new(); | ||
| 470 | - let mut pos = 0usize; | ||
| 471 | - let mut frame_headers = 0usize; | ||
| 472 | - while pos < data.len() { | ||
| 473 | - let Ok(obu) = parser.parse_obu(&data[pos..]) else { | ||
| 474 | - break; | ||
| 475 | - }; | ||
| 476 | - pos += obu.total_size.max(1); | ||
| 477 | - let header = match &obu.kind { | ||
| 478 | - ObuKind::Frame(h, _) | ObuKind::FrameHeader(h) => h, | ||
| 479 | - _ => continue, | ||
| 480 | - }; | ||
| 481 | - assert!( | ||
| 482 | - !header.show_existing_frame, | ||
| 483 | - "{NAME}: frame header {frame_headers} sets show_existing_frame, so the header \ | ||
| 484 | - count is not the shown-frame count and this gate's oracle budget would be wrong" | ||
| 485 | - ); | ||
| 486 | - frame_headers += 1; | ||
| 487 | - } | ||
| 488 | - assert!( | ||
| 489 | - frame_headers > 0, | ||
| 490 | - "{NAME}: {} carries no frame header at all", | ||
| 491 | - path.display() | ||
| 492 | - ); | ||
| 493 | - crate::decode::reset_skip_split_tx_override_hits(); | ||
| 494 | - let decoded = decode_stream(&data).expect("the pinned SVT-AV1 screen stream decodes"); | ||
| 495 | - assert!( | ||
| 496 | - crate::decode::skip_split_tx_override_hits() > 0, | ||
| 497 | - "{NAME}: no skipped split-transform palette block in {} -- the gate would pass blind", | ||
| 498 | - path.display() | ||
| 499 | - ); | ||
| 500 | - assert_eq!( | ||
| 501 | - decoded.len(), | ||
| 502 | - frame_headers, | ||
| 503 | - "{NAME}: the stream codes {frame_headers} frame(s), the decode showed {}", | ||
| 504 | - decoded.len() | ||
| 505 | - ); | ||
| 506 | - let (width, height) = (decoded[0].width, decoded[0].height); | ||
| 507 | - let want = ffmpeg_decode_sequence(&data, width, height, frame_headers); | ||
| 508 | - for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { | ||
| 509 | - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg"); | ||
| 510 | - assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg"); | ||
| 511 | - assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg"); | ||
| 512 | - } | ||
| 513 | - } | ||
| 514 | - | ||
| 515 | - /// `decode_stream` agrees with ffmpeg/dav1d on the same wire bytes -- an | ||
| 516 | - /// independent decoder, not just this crate checking its own tile path. | ||
| 517 | - #[test] | ||
| 518 | - fn decode_stream_agrees_with_ffmpeg_on_a_gop() { | ||
| 519 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 520 | - if !have_ffmpeg() { | ||
| 521 | - eprintln!("SKIP decode_stream_agrees_with_ffmpeg_on_a_gop: no ffmpeg"); | ||
| 522 | - return; | ||
| 523 | - } | ||
| 524 | - // lane-av1straddle: 216x96 joins 128x64 because only a size whose | ||
| 525 | - // 32x32 blocks straddle the right-hand frame edge can see the writer | ||
| 526 | - // coding a transform unit that starts outside the frame -- libdav1d | ||
| 527 | - // AND libaom both refused the whole key frame while it did, and this | ||
| 528 | - // crate's own (lenient) decoder only differed in the last block's V. | ||
| 529 | - for &(width, height) in &[(128usize, 64usize), (216usize, 96usize)] { | ||
| 530 | - let pictures: Vec<_> = (0..3) | ||
| 531 | - .map(|i| panned_test_card(width, height, i * 3)) | ||
| 532 | - .collect(); | ||
| 533 | - let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); | ||
| 534 | - let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, 3); | ||
| 535 | - let decoded = decode_stream(&encoded.stream).unwrap(); | ||
| 536 | - assert_eq!(decoded.len(), 3); | ||
| 537 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 538 | - assert_eq!(got.y, want.y, "{width}x{height} frame {i} luma vs ffmpeg"); | ||
| 539 | - assert_eq!(got.u, want.u, "{width}x{height} frame {i} U vs ffmpeg"); | ||
| 540 | - assert_eq!(got.v, want.v, "{width}x{height} frame {i} V vs ffmpeg"); | ||
| 541 | - } | ||
| 542 | - // ... and the encoder's own reconstruction is what ffmpeg sees, | ||
| 543 | - // so the check fails on a writer-side desync too, not only on a | ||
| 544 | - // decoder-side one. | ||
| 545 | - for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 546 | - let rec = &frame.reconstruction; | ||
| 547 | - assert_eq!( | ||
| 548 | - rec.y, want.y, | ||
| 549 | - "{width}x{height} frame {i} luma: reconstruction vs ffmpeg" | ||
| 550 | - ); | ||
| 551 | - assert_eq!( | ||
| 552 | - rec.u, want.u, | ||
| 553 | - "{width}x{height} frame {i} U: reconstruction vs ffmpeg" | ||
| 554 | - ); | ||
| 555 | - assert_eq!( | ||
| 556 | - rec.v, want.v, | ||
| 557 | - "{width}x{height} frame {i} V: reconstruction vs ffmpeg" | ||
| 558 | - ); | ||
| 559 | - } | ||
| 560 | - } | ||
| 561 | - } | ||
| 562 | - | ||
| 563 | - /// lane-av1rect: the encoder used to REFUSE every size where a 32x32 | ||
| 564 | - /// block straddles BOTH true frame edges at once ("straddles the true | ||
| 565 | - /// frame edge in a way that needs a rectangular (HORZ/VERT) transform | ||
| 566 | - /// this encoder does not code yet"). That refusal was a misreading of | ||
| 567 | - /// spec 5.11.4: a block whose `hasRows` and `hasCols` are BOTH false | ||
| 568 | - /// reads no partition symbol at all and is `PARTITION_SPLIT` by | ||
| 569 | - /// inference, down to the 8x8 leaves whose own mi origin is inside the | ||
| 570 | - /// frame -- exactly the leaves this writer already codes for the | ||
| 571 | - /// one-axis case, and no rectangular transform anywhere. The sweep walks | ||
| 572 | - /// the corners around the 32-multiples (each width has a 16x16 column | ||
| 573 | - /// whose right half is outside, each height a row whose bottom half is, | ||
| 574 | - /// so the bottom-right 16x16 of every size here is cut on both axes) and | ||
| 575 | - /// three-way compares: our decoder, the encoder's own reconstruction and | ||
| 576 | - /// ffmpeg, over a 4-frame GOP so the inter writer's copy of the same | ||
| 577 | - /// signaling is covered too. `edge_both_cut_hits` proves the decoder | ||
| 578 | - /// really took the inferred-split path rather than the gate passing on | ||
| 579 | - /// geometry that never fires it. | ||
| 580 | - #[test] | ||
| 581 | - fn a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg() { | ||
| 582 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 583 | - if !have_ffmpeg() { | ||
| 584 | - eprintln!( | ||
| 585 | - "SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg" | ||
| 586 | - ); | ||
| 587 | - return; | ||
| 588 | - } | ||
| 589 | - const FRAMES: usize = 4; | ||
| 590 | - let mut both_cut = 0usize; | ||
| 591 | - for &width in &[200usize, 216, 232, 248] { | ||
| 592 | - for &height in &[104usize, 120, 136, 152] { | ||
| 593 | - let pictures: Vec<_> = (0..FRAMES as i64) | ||
| 594 | - .map(|i| panned_test_card(width, height, i * 3)) | ||
| 595 | - .collect(); | ||
| 596 | - let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx) | ||
| 597 | - .unwrap_or_else(|e| panic!("{width}x{height}: encoder refused: {e}")); | ||
| 598 | - // Reset per attempt, never a delta across sizes (class | ||
| 599 | - // counter-from-refused-stream). | ||
| 600 | - crate::decode::reset_edge_both_cut_hits(); | ||
| 601 | - let decoded = decode_stream(&encoded.stream) | ||
| 602 | - .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}")); | ||
| 603 | - both_cut += crate::decode::edge_both_cut_hits().iter().sum::<usize>(); | ||
| 604 | - let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES); | ||
| 605 | - assert_eq!( | ||
| 606 | - ffmpeg_frames.len(), | ||
| 607 | - FRAMES, | ||
| 608 | - "{width}x{height}: ffmpeg decoded {} of {FRAMES} frames", | ||
| 609 | - ffmpeg_frames.len() | ||
| 610 | - ); | ||
| 611 | - assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count"); | ||
| 612 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 613 | - assert_eq!(got.y, want.y, "{width}x{height} frame {i} luma vs ffmpeg"); | ||
| 614 | - assert_eq!(got.u, want.u, "{width}x{height} frame {i} U vs ffmpeg"); | ||
| 615 | - assert_eq!(got.v, want.v, "{width}x{height} frame {i} V vs ffmpeg"); | ||
| 616 | - } | ||
| 617 | - for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 618 | - let rec = &frame.reconstruction; | ||
| 619 | - assert_eq!( | ||
| 620 | - rec.y, want.y, | ||
| 621 | - "{width}x{height} frame {i} luma: recon vs ffmpeg" | ||
| 622 | - ); | ||
| 623 | - assert_eq!( | ||
| 624 | - rec.u, want.u, | ||
| 625 | - "{width}x{height} frame {i} U: recon vs ffmpeg" | ||
| 626 | - ); | ||
| 627 | - assert_eq!( | ||
| 628 | - rec.v, want.v, | ||
| 629 | - "{width}x{height} frame {i} V: recon vs ffmpeg" | ||
| 630 | - ); | ||
| 631 | - } | ||
| 632 | - } | ||
| 633 | - } | ||
| 634 | - assert!( | ||
| 635 | - both_cut > 0, | ||
| 636 | - "no partition node in the whole sweep was coded as the both-axes-cut \ | ||
| 637 | - inferred split -- the gate is blind to the feature it pins" | ||
| 638 | - ); | ||
| 639 | - } | ||
| 640 | - | ||
| 641 | - /// lane-corner: sizes whose LAST superblock is cut by the true frame | ||
| 642 | - /// edge on BOTH axes with more than half of each still inside -- so | ||
| 643 | - /// `has_cols` and `has_rows` are both true and the spec lets that | ||
| 644 | - /// superblock stay a whole 64x64 `PARTITION_NONE` block, which this | ||
| 645 | - /// encoder's roots take (`EC_AV1_B64EDGE` on the inter side, the key | ||
| 646 | - /// frame's own `Superblock::Whole`). The sibling luma-only test | ||
| 647 | - /// (`encoder.rs`'s `a_non_superblock_aligned_clip_...`) is blind to | ||
| 648 | - /// chroma (class `metric-blind-to-a-plane`), so this one compares all | ||
| 649 | - /// three planes three ways: our decoder, the encoder's own | ||
| 650 | - /// reconstruction, and ffmpeg. | ||
| 651 | - #[test] | ||
| 652 | - fn a_doubly_cut_superblock_root_round_trips_in_every_plane() { | ||
| 653 | - let fctx = &crate::decode::FrameCtx::for_encoder(); | ||
| 654 | - if !have_ffmpeg() { | ||
| 655 | - eprintln!("SKIP a_doubly_cut_superblock_root_round_trips_in_every_plane: no ffmpeg"); | ||
| 656 | - return; | ||
| 657 | - } | ||
| 658 | - const FRAMES: usize = 4; | ||
| 659 | - // Each size leaves MORE than half of its last superblock row (and, | ||
| 660 | - // but for 200x120's 8-px column, of its last column) inside, which is | ||
| 661 | - // what makes the root legal there at all; 248x168/232x168/248x184 are | ||
| 662 | - // cut on BOTH axes at once. 1920x1080 -- the user's own export shape | ||
| 663 | - // -- is the same case: 1080 = 16*64 + 56, a 56-px bottom straddle. | ||
| 664 | - for &(width, height) in &[(248usize, 168usize), (232, 168), (200, 120), (248, 184)] { | ||
| 665 | - let pictures: Vec<_> = (0..FRAMES as i64) | ||
| 666 | - .map(|i| panned_test_card(width, height, i * 3)) | ||
| 667 | - .collect(); | ||
| 668 | - let _ = crate::encode::take_b64_edge_hits(); | ||
| 669 | - let _ = crate::encode::take_i64_root_hits(); | ||
| 670 | - let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx) | ||
| 671 | - .unwrap_or_else(|e| panic!("{width}x{height}: encoder refused: {e}")); | ||
| 672 | - let edges = crate::encode::take_b64_edge_hits(); | ||
| 673 | - let [i64_whole, i64_offered, i64_edge] = crate::encode::take_i64_root_hits(); | ||
| 674 | - eprintln!( | ||
| 675 | - "{width}x{height}: edge inter 64 roots {edges}, key 64 roots {i64_whole} of \ | ||
| 676 | - {i64_offered} offered, {i64_edge} of them cut by the frame edge" | ||
| 677 | - ); | ||
| 678 | - // gate-blind-to-feature: without this the three-way compare below | ||
| 679 | - // passes on a stream that never coded a whole root at the cut | ||
| 680 | - // superblock at all. | ||
| 681 | - assert!( | ||
| 682 | - i64_edge > 0, | ||
| 683 | - "{width}x{height}: no 64x64 root sat on a superblock the frame edge cuts" | ||
| 684 | - ); | ||
| 685 | - let decoded = decode_stream(&encoded.stream) | ||
| 686 | - .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}")); | ||
| 687 | - let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES); | ||
| 688 | - assert_eq!( | ||
| 689 | - ffmpeg_frames.len(), | ||
| 690 | - FRAMES, | ||
| 691 | - "{width}x{height}: ffmpeg frame count" | ||
| 692 | - ); | ||
| 693 | - assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count"); | ||
| 694 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 695 | - assert_eq!( | ||
| 696 | - got.y, want.y, | ||
| 697 | - "{width}x{height} frame {i} luma: ours vs ffmpeg" | ||
| 698 | - ); | ||
| 699 | - assert_eq!( | ||
| 700 | - got.u, want.u, | ||
| 701 | - "{width}x{height} frame {i} U: ours vs ffmpeg" | ||
| 702 | - ); | ||
| 703 | - assert_eq!( | ||
| 704 | - got.v, want.v, | ||
| 705 | - "{width}x{height} frame {i} V: ours vs ffmpeg" | ||
| 706 | - ); | ||
| 707 | - } | ||
| 708 | - for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 709 | - let rec = &frame.reconstruction; | ||
| 710 | - assert_eq!( | ||
| 711 | - rec.y, want.y, | ||
| 712 | - "{width}x{height} frame {i} luma: recon vs ffmpeg" | ||
| 713 | - ); | ||
| 714 | - assert_eq!( | ||
| 715 | - rec.u, want.u, | ||
| 716 | - "{width}x{height} frame {i} U: recon vs ffmpeg" | ||
| 717 | - ); | ||
| 718 | - assert_eq!( | ||
| 719 | - rec.v, want.v, | ||
| 720 | - "{width}x{height} frame {i} V: recon vs ffmpeg" | ||
| 721 | - ); | ||
| 722 | - } | ||
| 723 | - } | ||
| 724 | - } | ||
| 725 | - | ||
| 726 | - /// A hand-built 3-frame stream that actually fires `GOLDEN_FRAME` | ||
| 727 | - /// through [`decode_stream`], proving the round-4 flip (`decode.rs`'s | ||
| 728 | - /// `decode_inter_block` `GOLDEN_FRAME` arm) the way 120+ real aomenc | ||
| 729 | - /// attempts never could: frame 0 is a real key frame (this crate's own | ||
| 730 | - /// encoder, real texture), refreshing all 8 DPB slots as spec requires -- | ||
| 731 | - /// slot 3 keeps that exact picture from here on. Frame 1 is a hand-coded | ||
| 732 | - /// inter frame whose lone 32x32 block is *intra* (`DC_PRED`, `skip`), | ||
| 733 | - /// refreshing only slot 0 with a flat 128 block -- distinguishable from | ||
| 734 | - /// frame 0's real texture, so slot 0 (`LAST_FRAME`) and slot 3 | ||
| 735 | - /// (`GOLDEN_FRAME`) hold visibly different pictures once frame 2 runs. | ||
| 736 | - /// Frame 2 is a hand-coded inter frame naming `ref_frame_idx[3] = 3` | ||
| 737 | - /// (GOLDEN_FRAME's slot) and `ref_frame_idx[0] = 0` (LAST_FRAME's), whose | ||
| 738 | - /// lone block codes `single_ref` all the way out to `GOLDEN_FRAME` | ||
| 739 | - /// (`p1=0, p3=1, p5=1`) and a `skip` zero-MV `NEARESTMV`: a direct copy | ||
| 740 | - /// of GOLDEN's picture, so its output must equal frame 0's own | ||
| 741 | - /// reconstruction exactly, and must differ from frame 1's -- proof the | ||
| 742 | - /// decoder actually read the golden plane, not silently substituted | ||
| 743 | - /// `LAST_FRAME`'s. Rounds 4-9 masked and re-masked this arm chasing a | ||
| 744 | - /// deblock/MC residue that turned out to be film-grain synthesis | ||
| 745 | - /// (lane-av1golden7's `apply_grain` refusal, unrelated to GOLDEN); | ||
| 746 | - /// lane-av1golden8 fixed mvstack's single-ref extension pass, clearing | ||
| 747 | - /// the last real defect (`pinned_golden7` non_last_ref_hits 0->2), so | ||
| 748 | - /// this fixture flips back to its round-4 pixel-exact form. ffmpeg | ||
| 749 | - /// decodes the identical wire bytes as the foreign oracle | ||
| 750 | - /// (shared-oracle-blindness class): this crate's own decoder agreeing | ||
| 751 | - /// with itself would prove nothing. | ||
| 752 | - #[test] | ||
| 753 | - fn a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg() { | ||
| 754 | - let fctx = &crate::decode::FrameCtx::new(); | ||
| 755 | - if !have_ffmpeg() { | ||
| 756 | - eprintln!( | ||
| 757 | - "SKIP a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg: no ffmpeg" | ||
| 758 | - ); | ||
| 759 | - return; | ||
| 760 | - } | ||
| 761 | - use crate::cdf_state::Cdfs; | ||
| 762 | - use crate::decode::{intra_inter_ctx, non_last_ref_hits, q_ctx_of}; | ||
| 763 | - use crate::encode::{inter_frame_headers, key_frame_headers}; | ||
| 764 | - use crate::frame::frame_obu; | ||
| 765 | - use crate::msac::SymbolEncoder; | ||
| 766 | - use crate::mvstack::{ | ||
| 767 | - GOLDEN_FRAME, MiGrid, find_mv_stack, single_ref_p1_ctx, single_ref_p3_ctx, | ||
| 768 | - single_ref_p5_ctx, | ||
| 769 | - }; | ||
| 770 | - use crate::obu::temporal_delimiter; | ||
| 771 | - | ||
| 772 | - let (width, height) = (32usize, 32usize); | ||
| 773 | - let base_q_idx = 100u8; | ||
| 774 | - // The whole picture is one 32x32 block: `partition_ctx`/`skip_ctx`/ | ||
| 775 | - // `intra_inter_ctx`'s neighbour inputs are all "no neighbour yet" -- | ||
| 776 | - // a fresh `Neighbours`' `above_side_mi`/`left_side_mi` start at `SB` | ||
| 777 | - // (64), so `partition_ctx_mi`'s `side_mi * 2 <= side` (32) is false | ||
| 778 | - // on both axes (ctx 0), and `above_skip`/`left_skip`/`above_inter`/ | ||
| 779 | - // `left_inter`/`above_ref`/`left_ref` all start `false`/`-1` | ||
| 780 | - // (decode.rs `Neighbours::new`) -- computed here without | ||
| 781 | - // constructing the (module-private) `Neighbours` itself. | ||
| 782 | - const PARTITION_NONE: usize = 0; | ||
| 783 | - let ii_ctx = intra_inter_ctx(false, false, false, false); | ||
| 784 | - let sr_p1_ctx = single_ref_p1_ctx(None, None, None, None); | ||
| 785 | - let sr_p3_ctx = single_ref_p3_ctx(None, None, None, None); | ||
| 786 | - let sr_p5_ctx = single_ref_p5_ctx(None, None, None, None); | ||
| 787 | - | ||
| 788 | - for run in 0..4 { | ||
| 789 | - let picture = test_card(width, height); | ||
| 790 | - let key = encode_key_frame_with_ctx(&picture, base_q_idx, 0.5, fctx).unwrap(); | ||
| 791 | - let (seq, _) = key_frame_headers(width, height, base_q_idx).unwrap(); | ||
| 792 | - | ||
| 793 | - // Frame 1: hand-coded, intra-only, refreshes slot 0 with a flat | ||
| 794 | - // 128 block (no neighbours to predict `DC_PRED` from). | ||
| 795 | - let (_, mut header1) = inter_frame_headers(width, height, base_q_idx, 1, 0).unwrap(); | ||
| 796 | - // These two tiles are hand-coded from a FRESH `Cdfs`, so the | ||
| 797 | - // frames must not carry CDF state the way the encoder's own inter | ||
| 798 | - // frames now do (spec 7.20): with the bit set, what each frame | ||
| 799 | - // stores is what it started from -- the defaults -- which is | ||
| 800 | - // exactly what the next hand-coded tile assumes. | ||
| 801 | - header1.disable_frame_end_update_cdf = true; | ||
| 802 | - let tile1 = { | ||
| 803 | - let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx)); | ||
| 804 | - let mut enc = SymbolEncoder::new(); | ||
| 805 | - enc.symbol(PARTITION_NONE, &mut cdfs.partition_w32[0]); | ||
| 806 | - enc.symbol(1, &mut cdfs.skip[0]); // skip | ||
| 807 | - enc.symbol(0, &mut cdfs.intra_inter[ii_ctx]); // is_inter = false | ||
| 808 | - enc.symbol(0, &mut cdfs.y_mode[3]); // DC_PRED, size group 3 (32x32) | ||
| 809 | - enc.symbol(0, &mut cdfs.uv_mode_cfl[0]); // DC_PRED | ||
| 810 | - enc.finish() | ||
| 811 | - }; | ||
| 812 | - let mut stream = key.stream.clone(); | ||
| 813 | - stream.extend(temporal_delimiter()); | ||
| 814 | - stream.extend(frame_obu(&seq, &header1, &tile1).unwrap()); | ||
| 815 | - | ||
| 816 | - // Frame 2: hand-coded, single_ref all the way to GOLDEN_FRAME, | ||
| 817 | - // skip zero-MV NEARESTMV -- a direct copy of slot 3 (frame 0). | ||
| 818 | - let (_, mut header2) = inter_frame_headers(width, height, base_q_idx, 2, 0).unwrap(); | ||
| 819 | - header2.disable_frame_end_update_cdf = true; | ||
| 820 | - header2.ref_frame_idx[3] = 3; // GOLDEN_FRAME's own slot: frame 0's, untouched by frame 1 | ||
| 821 | - let tile2 = { | ||
| 822 | - let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx)); | ||
| 823 | - let mut enc = SymbolEncoder::new(); | ||
| 824 | - let grid = MiGrid::new(8, 8); | ||
| 825 | - let stack = find_mv_stack(&grid, 0, 0, 8, 8, GOLDEN_FRAME, 8, 8); | ||
| 826 | - enc.symbol(PARTITION_NONE, &mut cdfs.partition_w32[0]); | ||
| 827 | - enc.symbol(1, &mut cdfs.skip[0]); // skip | ||
| 828 | - enc.symbol(1, &mut cdfs.intra_inter[ii_ctx]); // is_inter = true | ||
| 829 | - enc.symbol(0, &mut cdfs.single_ref[sr_p1_ctx][0]); // p1: LAST/LAST2/LAST3/GOLDEN group | ||
| 830 | - enc.symbol(1, &mut cdfs.single_ref[sr_p3_ctx][2]); // p3: GOLDEN/LAST3 sub-group | ||
| 831 | - enc.symbol(1, &mut cdfs.single_ref[sr_p5_ctx][4]); // p5: GOLDEN_FRAME | ||
| 832 | - enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not_new -> not NEWMV | ||
| 833 | - enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not_zero -> not GLOBALMV | ||
| 834 | - enc.symbol(0, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // nearest -> NEARESTMV, (0, 0) | ||
| 835 | - enc.finish() | ||
| 836 | - }; | ||
| 837 | - stream.extend(temporal_delimiter()); | ||
| 838 | - stream.extend(frame_obu(&seq, &header2, &tile2).unwrap()); | ||
| 839 | - | ||
| 840 | - let before = non_last_ref_hits(); | ||
| 841 | - let decoded = decode_stream(&stream).unwrap(); | ||
| 842 | - assert_eq!(decoded.len(), 3, "run {run}: expected 3 pictures"); | ||
| 843 | - assert!( | ||
| 844 | - non_last_ref_hits() > before, | ||
| 845 | - "run {run}: GOLDEN_FRAME never fired" | ||
| 846 | - ); | ||
| 847 | - | ||
| 848 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 3); | ||
| 849 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 850 | - assert_eq!(got.y, want.y, "run {run} frame {i}: luma vs ffmpeg"); | ||
| 851 | - assert_eq!(got.u, want.u, "run {run} frame {i}: U vs ffmpeg"); | ||
| 852 | - assert_eq!(got.v, want.v, "run {run} frame {i}: V vs ffmpeg"); | ||
| 853 | - } | ||
| 854 | - assert_eq!( | ||
| 855 | - decoded[0].y, key.reconstruction.y, | ||
| 856 | - "run {run}: frame 0 vs the encoder's own reconstruction" | ||
| 857 | - ); | ||
| 858 | - assert_eq!( | ||
| 859 | - decoded[2].y, key.reconstruction.y, | ||
| 860 | - "run {run}: GOLDEN_FRAME's block did not reproduce the keyframe it names" | ||
| 861 | - ); | ||
| 862 | - assert_ne!( | ||
| 863 | - decoded[2].y, decoded[1].y, | ||
| 864 | - "run {run}: LAST_FRAME's and GOLDEN_FRAME's slots were not actually \ | ||
| 865 | - distinguishable -- the gate proves nothing" | ||
| 866 | - ); | ||
| 867 | - } | ||
| 868 | - } | ||
| 869 | - | ||
| 870 | - /// The determinism guard: same seed twice must byte-match ffmpeg's own | ||
| 871 | - /// output; different seeds must not. Regresses this fix if it ever | ||
| 872 | - /// breaks. | ||
| 873 | - #[test] | ||
| 874 | - fn gradients_source_is_reproducible_per_seed() { | ||
| 875 | - if !have_ffmpeg() { | ||
| 876 | - eprintln!("SKIP gradients_source_is_reproducible_per_seed: no ffmpeg"); | ||
| 877 | - return; | ||
| 878 | - } | ||
| 879 | - fn render_hash(lavfi: &str) -> Vec<u8> { | ||
| 880 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 881 | - .args([ | ||
| 882 | - "-v", | ||
| 883 | - "error", | ||
| 884 | - "-f", | ||
| 885 | - "lavfi", | ||
| 886 | - "-i", | ||
| 887 | - lavfi, | ||
| 888 | - "-frames:v", | ||
| 889 | - "1", | ||
| 890 | - "-f", | ||
| 891 | - "rawvideo", | ||
| 892 | - "-", | ||
| 893 | - ]) | ||
| 894 | - .stdin(Stdio::null()) | ||
| 895 | - .stdout(Stdio::piped()) | ||
| 896 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 897 | - .expect("ffmpeg failed to run"); | ||
| 898 | - assert!(out.status.success(), "ffmpeg refused {lavfi}"); | ||
| 899 | - out.stdout | ||
| 900 | - } | ||
| 901 | - let a1 = render_hash(&gradients_source(42, 64, 64, "duration=0.04:rate=25")); | ||
| 902 | - let a2 = render_hash(&gradients_source(43, 64, 64, "duration=0.04:rate=25")); | ||
| 903 | - let a3 = render_hash(&gradients_source(42, 64, 64, "duration=0.04:rate=25")); | ||
| 904 | - assert_eq!(a1, a3, "same seed must reproduce byte-identical output"); | ||
| 905 | - assert_ne!(a1, a2, "different seeds must not collide"); | ||
| 906 | - } | ||
| 907 | - | ||
| 908 | - /// The end-to-end gate: two real libaom-av1 configs, decoded with | ||
| 909 | - /// [`decode_stream`] and checked against ffmpeg's own decode of the same | ||
| 910 | - /// bytes. Not every config this encoder writes decodes yet (partitions | ||
| 911 | - /// below 16x16, AB partitions, CfL and others remain round-2 gaps per the | ||
| 912 | - /// r6 catalogue) -- both configs here pick `cpu-used 8` plus the | ||
| 913 | - /// partition/angle-delta/CfL flags r6 found narrow the encoder onto this | ||
| 914 | - /// decoder's supported syntax, while still landing on non-`DCT_DCT` tx | ||
| 915 | - /// types on gradient content. | ||
| 916 | - #[test] | ||
| 917 | - fn a_real_libaom_stream_with_adst_decodes_end_to_end() { | ||
| 918 | - if !have_ffmpeg() { | ||
| 919 | - eprintln!("SKIP a_real_libaom_stream_with_adst_decodes_end_to_end: no ffmpeg"); | ||
| 920 | - return; | ||
| 921 | - } | ||
| 922 | - let configs: [(String, usize, usize, u32); 2] = [ | ||
| 923 | - ("testsrc2=size=64x64:rate=1".to_string(), 64, 64, 15), | ||
| 924 | - (gradients_source(42, 64, 64, "rate=1"), 64, 64, 15), | ||
| 925 | - ]; | ||
| 926 | - let mut verdicts = Vec::new(); | ||
| 927 | - for (lavfi, width, height, crf) in configs { | ||
| 928 | - let lavfi = lavfi.as_str(); | ||
| 929 | - let Some(stream) = libaom_encode(lavfi, width, height, crf) else { | ||
| 930 | - verdicts.push(format!("{lavfi}: ffmpeg itself refused to encode")); | ||
| 931 | - continue; | ||
| 932 | - }; | ||
| 933 | - match decode_stream(&stream) { | ||
| 934 | - Ok(frames) => { | ||
| 935 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 936 | - let matches = frames[0].y == ffmpeg_frames[0].y | ||
| 937 | - && frames[0].u == ffmpeg_frames[0].u | ||
| 938 | - && frames[0].v == ffmpeg_frames[0].v; | ||
| 939 | - verdicts.push(format!( | ||
| 940 | - "{lavfi}: decoded, {} ffmpeg's own decode", | ||
| 941 | - if matches { "MATCHES" } else { "MISMATCHES" } | ||
| 942 | - )); | ||
| 943 | - // Not a hard `assert!`: libaom's own mode decisions at | ||
| 944 | - // `cpu-used 8` are not observed stable run-to-run on this | ||
| 945 | - // box (multi-threaded RD search), so a run that happens | ||
| 946 | - // to land on a still-unsupported syntax element (e.g. a | ||
| 947 | - // partition below 16x16, a separate round-2 gap) can | ||
| 948 | - // decode without erroring yet disagree -- that failure | ||
| 949 | - // mode belongs to those other gaps, not to this round's | ||
| 950 | - // ADST wiring, and the eprintln below reports it either | ||
| 951 | - // way rather than hiding it. | ||
| 952 | - } | ||
| 953 | - Err(e) => { | ||
| 954 | - verdicts.push(format!("{lavfi}: still refuses ({e})")); | ||
| 955 | - } | ||
| 956 | - } | ||
| 957 | - } | ||
| 958 | - eprintln!("libaom ADST end-to-end verdicts:"); | ||
| 959 | - for v in &verdicts { | ||
| 960 | - eprintln!(" {v}"); | ||
| 961 | - } | ||
| 962 | - } | ||
| 963 | - | ||
| 964 | - /// lane-dgolomb: the `force_integer_mv` gate. libaom turns screen-content | ||
| 965 | - /// tools on for DARK, SMOOTH content -- its `av1_set_screen_content_options` | ||
| 966 | - /// counts 16x16 blocks with 2..=4 distinct luma values -- and then sets | ||
| 967 | - /// `force_integer_mv` on any inter frame whose source is pixel-identical to | ||
| 968 | - /// the previously coded source (`av1_is_integer_mv`: `cs_rate >= 0.8` and | ||
| 969 | - /// `C == T`, every collocated 8x8 block matching, is the only path that | ||
| 970 | - /// returns 1). Both hold on his real AV1 films, and this decoder used to | ||
| 971 | - /// drop `lower_mv_precision`'s `is_integer` half as unreachable, so every | ||
| 972 | - /// temporal MV candidate on such a frame came out at eighth-pel: the frame | ||
| 973 | - /// decoded without any error into a whole-frame prediction mismatch, and | ||
| 974 | - /// the desync surfaced blocks later as "a Golomb tail longer than this | ||
| 975 | - /// decoder reads". | ||
| 976 | - /// | ||
| 977 | - /// The source is SYNTHETIC (no film sample lives in `fixtures`): the | ||
| 978 | - /// near-flat dark pattern libaom's own screen-content detector counts as | ||
| 979 | - /// screen content, at the film-B crop size 1920x1024, SCROLLING globally | ||
| 980 | - /// 5 px per frame and frozen on frame 8 -- an exact duplicate of frame 7 | ||
| 981 | - /// (the `C == T` trigger) whose twin is not among its own references, so | ||
| 982 | - /// its blocks still code real motion under `force_integer_mv`. | ||
| 983 | - /// | ||
| 984 | - /// lane-dpm1 made this gate SENSITIVE: with the `force_integer_mv` branch | ||
| 985 | - /// of [`crate::motion_field::lower_mv_precision`] stubbed out (`if false | ||
| 986 | - /// &&`) the stream decodes WRONG -- frame 8, luma sample 25695, 20 against | ||
| 987 | - /// ffmpeg's 19 -- where the previous patch-in-a-static-background recipe | ||
| 988 | - /// (and two others tried) still decoded byte-exact: there the used mv-stack | ||
| 989 | - /// slots came from agreeing spatial neighbours and the rounded temporal | ||
| 990 | - /// entries never won one. The gate asserts both halves: at least one INTER | ||
| 991 | - /// frame really carries `force_integer_mv` (class `gate-blind-to-feature`), | ||
| 992 | - /// and every shown frame decodes sample-exact against ffmpeg's own decode. | ||
| 993 | - #[test] | ||
| 994 | - fn a_libaom_force_integer_mv_stream_decodes_exact() { | ||
| 995 | - const NAME: &str = "a_libaom_force_integer_mv_stream_decodes_exact"; | ||
| 996 | - if !have_ffmpeg() { | ||
| 997 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 998 | - return; | ||
| 999 | - } | ||
| 1000 | - let (w, h, frames) = (1920usize, 1024usize, 16usize); | ||
| 1001 | - let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); | ||
| 1002 | - let mut off = 0usize; | ||
| 1003 | - for f in 0..frames { | ||
| 1004 | - // lane-dpm1: the WHOLE picture scrolls 5 px per frame and freezes | ||
| 1005 | - // on frame 8, so (a) every block of the frozen frame -- including | ||
| 1006 | - // mi(0,0), which has no spatial neighbour at all -- still codes | ||
| 1007 | - // real motion against the references that are not its twin, and | ||
| 1008 | - // (b) 40 eighth-pels projected over the pyramid's distances lands | ||
| 1009 | - // on non-multiples of 8 (40/2 = 20 -> 16). A patch moving inside a | ||
| 1010 | - // static background was NOT sensitive: there the used stack slots | ||
| 1011 | - // came from spatial neighbours that agreed, and the rounded | ||
| 1012 | - // temporal entries never won one. | ||
| 1013 | - if f > 0 && f != 8 { | ||
| 1014 | - off = (off + 5) % h; | ||
| 1015 | - } | ||
| 1016 | - let mut y = vec![0u8; w * h]; | ||
| 1017 | - for row in 0..h { | ||
| 1018 | - let src = (row + off) % h; | ||
| 1019 | - for col in 0..w { | ||
| 1020 | - // 2..=4 distinct values per 16x16 block, all dark: the | ||
| 1021 | - // screen-content detector's own counting rule. | ||
| 1022 | - y[row * w + col] = | ||
| 1023 | - 16 + ((col / 32 + src / 32) % 5) as u8 + ((col / 4 + src / 4) % 3) as u8; | ||
| 1024 | - } | ||
| 1025 | - } | ||
| 1026 | - raw.extend_from_slice(&y); | ||
| 1027 | - raw.extend(std::iter::repeat_n(128u8, w * h / 2)); | ||
| 1028 | - } | ||
| 1029 | - // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | ||
| 1030 | - let src = std::env::temp_dir().join(format!("ec-av1-intmv-{}.yuv", std::process::id())); | ||
| 1031 | - std::fs::write(&src, &raw).expect("raw source"); | ||
| 1032 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1033 | - .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | ||
| 1034 | - .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | ||
| 1035 | - .arg(&src) | ||
| 1036 | - .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"]) | ||
| 1037 | - .args([ | ||
| 1038 | - "-cpu-used", | ||
| 1039 | - "6", | ||
| 1040 | - "-b:v", | ||
| 1041 | - "0", | ||
| 1042 | - "-crf", | ||
| 1043 | - "35", | ||
| 1044 | - "-f", | ||
| 1045 | - "obu", | ||
| 1046 | - "-", | ||
| 1047 | - ]) | ||
| 1048 | - .stdin(Stdio::null()) | ||
| 1049 | - .stdout(Stdio::piped()) | ||
| 1050 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1051 | - .expect("ffmpeg failed to run"); | ||
| 1052 | - let _ = std::fs::remove_file(&src); | ||
| 1053 | - if !out.status.success() { | ||
| 1054 | - eprintln!( | ||
| 1055 | - "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | ||
| 1056 | - String::from_utf8_lossy(&out.stderr) | ||
| 1057 | - ); | ||
| 1058 | - return; | ||
| 1059 | - } | ||
| 1060 | - let stream = out.stdout; | ||
| 1061 | - | ||
| 1062 | - // Half of the gate: the stream must actually carry the feature. | ||
| 1063 | - let mut parser = Av1Parser::new(); | ||
| 1064 | - let (mut pos, mut int_mv_inter) = (0usize, 0usize); | ||
| 1065 | - while pos < stream.len() { | ||
| 1066 | - let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses"); | ||
| 1067 | - pos += obu.total_size.max(1); | ||
| 1068 | - let header = match &obu.kind { | ||
| 1069 | - ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, | ||
| 1070 | - _ => continue, | ||
| 1071 | - }; | ||
| 1072 | - if header.force_integer_mv && !header.frame_is_intra && header.use_ref_frame_mvs { | ||
| 1073 | - int_mv_inter += 1; | ||
| 1074 | - } | ||
| 1075 | - } | ||
| 1076 | - assert!( | ||
| 1077 | - int_mv_inter > 0, | ||
| 1078 | - "{NAME} went blind: libaom coded no inter frame with force_integer_mv" | ||
| 1079 | - ); | ||
| 1080 | - | ||
| 1081 | - let ours = decode_stream(&stream).expect("libaom screen-content stream decodes"); | ||
| 1082 | - let theirs = ffmpeg_decode_sequence(&stream, w, h, frames); | ||
| 1083 | - assert_eq!(ours.len(), frames, "shown frame count"); | ||
| 1084 | - for (i, (a, b)) in ours.iter().zip(theirs.iter()).enumerate() { | ||
| 1085 | - for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | ||
| 1086 | - let first = l.iter().zip(r.iter()).position(|(x, y)| x != y); | ||
| 1087 | - assert!( | ||
| 1088 | - first.is_none(), | ||
| 1089 | - "frame {i} plane {plane} differs from ffmpeg at sample {} \ | ||
| 1090 | - ({int_mv_inter} force_integer_mv inter frames in this stream)", | ||
| 1091 | - first.unwrap() | ||
| 1092 | - ); | ||
| 1093 | - assert_eq!( | ||
| 1094 | - l.len(), | ||
| 1095 | - r.len(), | ||
| 1096 | - "frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a short \ | ||
| 1097 | - plane would zip-truncate the compare above and hide a chroma-span defect", | ||
| 1098 | - l.len(), | ||
| 1099 | - r.len() | ||
| 1100 | - ); | ||
| 1101 | - } | ||
| 1102 | - } | ||
| 1103 | - } | ||
| 1104 | - | ||
| 1105 | - /// lane-dpm1: the 128x128-INTRA-inside-an-INTER-frame chroma context gate. | ||
| 1106 | - /// A 128x128 block codes its chroma as four TX_32X32 units, one per 64x64 | ||
| 1107 | - /// mu chunk, and libaom stamps the coefficient context PER UNIT. The two | ||
| 1108 | - /// INTER mu-chunk sites set `mu_chroma` so the block tail re-stamps the | ||
| 1109 | - /// four units in mu order; the INTRA-in-inter site did not, so the | ||
| 1110 | - /// whole-block record left every unit carrying the TOP-LEFT unit's level. | ||
| 1111 | - /// The next block then read its `txb_skip` off ctx 11 where libaom reads | ||
| 1112 | - /// ctx 10 (class `override-slot-on-one-arm`) -- one symbol on the wrong | ||
| 1113 | - /// CDF row, tile desynced, and because the loop-restoration coefficients | ||
| 1114 | - /// live in the same tile data the damage showed up as a +-1 luma sample at | ||
| 1115 | - /// the TOP of the frame (measured: frame 1, luma sample 66, ours 146 / | ||
| 1116 | - /// ffmpeg 145, with 1.7M samples wrong behind it). | ||
| 1117 | - /// | ||
| 1118 | - /// Source: the repository's own 2160p colour-bar fixture at the native | ||
| 1119 | - /// gate's crop (1920x1024 out of the middle), 12 frames, libaom | ||
| 1120 | - /// `-cpu-used 6 -crf 45 -g 12` -- the first reference point of | ||
| 1121 | - /// `bd_rate_screen_native`'s "bars 2160p" row, which is where the assertion | ||
| 1122 | - /// caught it. The gate asserts the tool fired (class | ||
| 1123 | - /// `gate-blind-to-feature`) and that every shown frame decodes sample-exact | ||
| 1124 | - /// against ffmpeg's own decode. | ||
| 1125 | - #[test] | ||
| 1126 | - fn a_libaom_stream_with_128_intra_blocks_in_inter_frames_decodes_exact() { | ||
| 1127 | - const NAME: &str = "a_libaom_stream_with_128_intra_blocks_in_inter_frames_decodes_exact"; | ||
| 1128 | - if !have_ffmpeg() { | ||
| 1129 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1130 | - return; | ||
| 1131 | - } | ||
| 1132 | - // lane-av1clipprobe: the bare `clip.exists()` -> SKIP had no env | ||
| 1133 | - // escape, so on a tree with no root `fixtures/` this 128-intra-block | ||
| 1134 | - // gate reported green having decoded nothing. | ||
| 1135 | - let Some(clip) = crate::library_fixture::require("video/h264-2160p-23.976-8bit.mp4", NAME) | ||
| 1136 | - else { | ||
| 1137 | - return; | ||
| 1138 | - }; | ||
| 1139 | - let (w, h, frames) = (1920usize, 1024usize, 12usize); | ||
| 1140 | - // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | ||
| 1141 | - let src = std::env::temp_dir().join(format!("ec-av1-i128-{}.yuv", std::process::id())); | ||
| 1142 | - let load = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1143 | - .args(["-v", "error", "-y", "-i"]) | ||
| 1144 | - .arg(&clip) | ||
| 1145 | - .args([ | ||
| 1146 | - "-frames:v", | ||
| 1147 | - &frames.to_string(), | ||
| 1148 | - "-vf", | ||
| 1149 | - "crop=1920:1024:960:568", | ||
| 1150 | - ]) | ||
| 1151 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) | ||
| 1152 | - .arg(&src), None, |c| c.output()) | ||
| 1153 | - .expect("ffmpeg failed to run"); | ||
| 1154 | - assert!( | ||
| 1155 | - load.status.success(), | ||
| 1156 | - "{NAME}: {}", | ||
| 1157 | - String::from_utf8_lossy(&load.stderr) | ||
| 1158 | - ); | ||
| 1159 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1160 | - .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | ||
| 1161 | - .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | ||
| 1162 | - .arg(&src) | ||
| 1163 | - .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) | ||
| 1164 | - .args([ | ||
| 1165 | - "-cpu-used", | ||
| 1166 | - "6", | ||
| 1167 | - "-b:v", | ||
| 1168 | - "0", | ||
| 1169 | - "-crf", | ||
| 1170 | - "45", | ||
| 1171 | - "-f", | ||
| 1172 | - "obu", | ||
| 1173 | - "-", | ||
| 1174 | - ]) | ||
| 1175 | - .stdin(Stdio::null()) | ||
| 1176 | - .stdout(Stdio::piped()) | ||
| 1177 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1178 | - .expect("ffmpeg failed to run"); | ||
| 1179 | - let _ = std::fs::remove_file(&src); | ||
| 1180 | - if !out.status.success() { | ||
| 1181 | - eprintln!( | ||
| 1182 | - "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | ||
| 1183 | - String::from_utf8_lossy(&out.stderr) | ||
| 1184 | - ); | ||
| 1185 | - return; | ||
| 1186 | - } | ||
| 1187 | - let stream = out.stdout; | ||
| 1188 | - let before = crate::decode::intra_128_in_inter_hits(); | ||
| 1189 | - let ours = decode_stream(&stream).expect("libaom bars stream decodes"); | ||
| 1190 | - assert!( | ||
| 1191 | - crate::decode::intra_128_in_inter_hits() > before, | ||
| 1192 | - "{NAME} went blind: no 128-rooted intra block inside an inter frame" | ||
| 1193 | - ); | ||
| 1194 | - let theirs = ffmpeg_decode_sequence(&stream, w, h, frames); | ||
| 1195 | - assert_eq!(ours.len(), frames, "shown frame count"); | ||
| 1196 | - for (i, (a, b)) in ours.iter().zip(theirs.iter()).enumerate() { | ||
| 1197 | - for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | ||
| 1198 | - let first = l.iter().zip(r.iter()).position(|(x, y)| x != y); | ||
| 1199 | - assert!( | ||
| 1200 | - first.is_none(), | ||
| 1201 | - "frame {i} plane {plane} differs from ffmpeg at sample {}", | ||
| 1202 | - first.unwrap() | ||
| 1203 | - ); | ||
| 1204 | - assert_eq!( | ||
| 1205 | - l.len(), | ||
| 1206 | - r.len(), | ||
| 1207 | - "frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a short \ | ||
| 1208 | - plane would zip-truncate the compare above and hide a chroma-span defect", | ||
| 1209 | - l.len(), | ||
| 1210 | - r.len() | ||
| 1211 | - ); | ||
| 1212 | - } | ||
| 1213 | - } | ||
| 1214 | - } | ||
| 1215 | - | ||
| 1216 | - /// lane-lossless: the refusal became an implementation, so its gate became | ||
| 1217 | - /// a DECODE-EXACT one (class `refusal-lifted-without-a-gate`). libaom at | ||
| 1218 | - /// `-crf 0` codes `base_q_idx == 0` -- the same lossless frame his | ||
| 1219 | - /// screen-capture row gets at `-crf 5` -- where every plane is TX_4X4 with | ||
| 1220 | - /// the Walsh-Hadamard transform, no `tx_type` symbol is coded | ||
| 1221 | - /// (`read_tx_type`, `decodetxb.c`: "No need to read transform type for | ||
| 1222 | - /// lossless mode(qindex==0)") and `is_cfl_allowed` (`blockd.h`) narrows to | ||
| 1223 | - /// a BLOCK_4X4 chroma plane block. The gate asserts the stream really is | ||
| 1224 | - /// lossless (class `gate-blind-to-feature`), that every KEY frame decodes | ||
| 1225 | - /// sample-exact against ffmpeg, and that the still-unimplemented lossless | ||
| 1226 | - /// INTER frame is refused BY NAME rather than decoded wrong. | ||
| 1227 | - #[test] | ||
| 1228 | - fn a_lossless_libaom_key_frame_decodes_sample_exact() { | ||
| 1229 | - const NAME: &str = "a_lossless_libaom_key_frame_decodes_sample_exact"; | ||
| 1230 | - if !have_ffmpeg() { | ||
| 1231 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1232 | - return; | ||
| 1233 | - } | ||
| 1234 | - let (w, h, frames) = (256usize, 128usize, 2usize); | ||
| 1235 | - let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); | ||
| 1236 | - for f in 0..frames { | ||
| 1237 | - for row in 0..h { | ||
| 1238 | - for col in 0..w { | ||
| 1239 | - raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8); | ||
| 1240 | - } | ||
| 1241 | - } | ||
| 1242 | - // lane-lossless2: TEXTURED chroma. A flat chroma plane codes one | ||
| 1243 | - // `txb_skip` symbol per 4x4 unit with every context at 0, which | ||
| 1244 | - // is blind to both the unit ORDER and the per-unit contexts | ||
| 1245 | - // (class `gate-blind-to-feature`). | ||
| 1246 | - for row in 0..h / 2 { | ||
| 1247 | - for col in 0..w / 2 { | ||
| 1248 | - raw.push((((col + f) * 11 + row * 5) % 251) as u8); | ||
| 1249 | - } | ||
| 1250 | - } | ||
| 1251 | - for row in 0..h / 2 { | ||
| 1252 | - for col in 0..w / 2 { | ||
| 1253 | - raw.push(((col * 3 + (row + f) * 17) % 251) as u8); | ||
| 1254 | - } | ||
| 1255 | - } | ||
| 1256 | - } | ||
| 1257 | - // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | ||
| 1258 | - let src = std::env::temp_dir().join(format!("ec-av1-lossless-{}.yuv", std::process::id())); | ||
| 1259 | - std::fs::write(&src, &raw).expect("raw source"); | ||
| 1260 | - let encode = |gop: &str| { | ||
| 1261 | - | ||
| 1262 | - crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1263 | - .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | ||
| 1264 | - .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | ||
| 1265 | - .arg(&src) | ||
| 1266 | - .args(["-an", "-threads", "1", "-g", gop, "-c:v", "libaom-av1"]) | ||
| 1267 | - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "0", "-f", "obu", "-"]) | ||
| 1268 | - .stdin(Stdio::null()) | ||
| 1269 | - .stdout(Stdio::piped()) | ||
| 1270 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1271 | - .expect("ffmpeg failed to run") | ||
| 1272 | - }; | ||
| 1273 | - let out = encode("1"); | ||
| 1274 | - let _ = std::fs::remove_file(&src); | ||
| 1275 | - if !out.status.success() { | ||
| 1276 | - eprintln!( | ||
| 1277 | - "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | ||
| 1278 | - String::from_utf8_lossy(&out.stderr) | ||
| 1279 | - ); | ||
| 1280 | - return; | ||
| 1281 | - } | ||
| 1282 | - let stream = out.stdout; | ||
| 1283 | - // Half of the gate: the stream must really carry a lossless frame | ||
| 1284 | - // (class `gate-blind-to-feature`). | ||
| 1285 | - let mut parser = Av1Parser::new(); | ||
| 1286 | - let (mut pos, mut lossless) = (0usize, 0usize); | ||
| 1287 | - while pos < stream.len() { | ||
| 1288 | - let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses"); | ||
| 1289 | - pos += obu.total_size.max(1); | ||
| 1290 | - let header = match &obu.kind { | ||
| 1291 | - ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, | ||
| 1292 | - _ => continue, | ||
| 1293 | - }; | ||
| 1294 | - if header.lossless.iter().all(|&l| l) { | ||
| 1295 | - lossless += 1; | ||
| 1296 | - } | ||
| 1297 | - } | ||
| 1298 | - assert_eq!( | ||
| 1299 | - lossless, frames, | ||
| 1300 | - "{NAME} went blind: libaom coded no lossless key frame at -crf 0" | ||
| 1301 | - ); | ||
| 1302 | - let ours = decode_stream(&stream).expect("a lossless key-frame stream decodes"); | ||
| 1303 | - let refs = ffmpeg_decode_sequence(&stream, w, h, frames); | ||
| 1304 | - assert_eq!(ours.len(), frames, "{NAME}: frame count"); | ||
| 1305 | - for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() { | ||
| 1306 | - for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 1307 | - .iter() | ||
| 1308 | - .enumerate() | ||
| 1309 | - { | ||
| 1310 | - let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | ||
| 1311 | - assert_eq!( | ||
| 1312 | - bad, 0, | ||
| 1313 | - "{NAME}: frame {i} plane {plane}: {bad} samples differ" | ||
| 1314 | - ); | ||
| 1315 | - assert_eq!( | ||
| 1316 | - g.len(), | ||
| 1317 | - r.len(), | ||
| 1318 | - "{NAME}: frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 1319 | - short plane would zip-truncate the compare above and hide a chroma-span \ | ||
| 1320 | - defect", | ||
| 1321 | - g.len(), | ||
| 1322 | - r.len() | ||
| 1323 | - ); | ||
| 1324 | - } | ||
| 1325 | - } | ||
| 1326 | - } | ||
| 1327 | - | ||
| 1328 | - /// lane-lossless2: the refusal `a_lossless_inter_frame_is_refused_by_name` | ||
| 1329 | - /// pinned became an implementation, so its gate became a DECODE-EXACT one | ||
| 1330 | - /// (class `refusal-lifted-without-a-gate`). A lossless INTER frame codes | ||
| 1331 | - /// its chroma plane as 4x4 transform units, plane-major inside each 64x64 | ||
| 1332 | - /// mu chunk (libaom `read_tx_size` returns TX_4X4 for every plane under | ||
| 1333 | - /// `xd->lossless[..]`, and `decode_token_recon_block` walks | ||
| 1334 | - /// `for (plane..) for (blk_row..) for (blk_col..)`), which is what | ||
| 1335 | - /// `decode::read_inter_chroma_lossless` reads. The source carries TEXTURED | ||
| 1336 | - /// CHROMA and real motion on purpose: a flat-chroma source codes one | ||
| 1337 | - /// `txb_skip` symbol per unit and is blind to both the unit order and the | ||
| 1338 | - /// per-unit contexts (class `gate-blind-to-feature`). | ||
| 1339 | - #[test] | ||
| 1340 | - fn a_lossless_libaom_inter_frame_decodes_sample_exact() { | ||
| 1341 | - const NAME: &str = "a_lossless_libaom_inter_frame_decodes_sample_exact"; | ||
| 1342 | - if !have_ffmpeg() { | ||
| 1343 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1344 | - return; | ||
| 1345 | - } | ||
| 1346 | - // (w, h, frames, gop, bit depth, 128-superblock, screen content) | ||
| 1347 | - // lane-lossless2: the SCREEN rows carry palette blocks, which is what | ||
| 1348 | - // caught the whole-block palette prediction being handed to a 4x4 | ||
| 1349 | - // chroma unit. | ||
| 1350 | - // lane-lossless3: the last row is a screen source with INTER frames -- | ||
| 1351 | - // the row that caught both of this lane's defects (a skip 8x8 leaf | ||
| 1352 | - // restoring the previous block's luma level band over the zeros | ||
| 1353 | - // `av1_reset_entropy_context` writes, and a rect sub-8x8 INTRA leaf | ||
| 1354 | - // reading one TX_4X8 unit where a lossless frame codes two TX_4X4). | ||
| 1355 | - let cases: [(usize, usize, usize, &str, u32, bool, bool); 7] = [ | ||
| 1356 | - (256, 128, 8, "4", 8, false, false), | ||
| 1357 | - (192, 96, 6, "3", 10, false, false), | ||
| 1358 | - (320, 192, 6, "3", 8, false, false), | ||
| 1359 | - (256, 256, 4, "2", 8, true, false), | ||
| 1360 | - (320, 192, 2, "1", 8, false, true), | ||
| 1361 | - (640, 384, 2, "1", 8, false, true), | ||
| 1362 | - (640, 384, 6, "3", 8, false, true), | ||
| 1363 | - ]; | ||
| 1364 | - for &(w, h, frames, gop, depth, sb128, screen) in &cases { | ||
| 1365 | - let tag = format!( | ||
| 1366 | - "{w}x{h} {depth}-bit gop {gop}{}{}", | ||
| 1367 | - if sb128 { " sb128" } else { "" }, | ||
| 1368 | - if screen { " screen" } else { "" } | ||
| 1369 | - ); | ||
| 1370 | - let mut raw: Vec<u8> = Vec::new(); | ||
| 1371 | - let put = |v: u32, raw: &mut Vec<u8>| { | ||
| 1372 | - if depth == 10 { | ||
| 1373 | - raw.extend_from_slice(&((v * 4) as u16).to_le_bytes()); | ||
| 1374 | - } else { | ||
| 1375 | - raw.push(v as u8); | ||
| 1376 | - } | ||
| 1377 | - }; | ||
| 1378 | - // A screen source is a few flat colours in 16x16 tiles plus | ||
| 1379 | - // 1-px text-like rows -- what makes libaom code palette blocks. | ||
| 1380 | - const PAL: [u32; 8] = [16, 60, 110, 145, 180, 210, 235, 128]; | ||
| 1381 | - for f in 0..frames { | ||
| 1382 | - for row in 0..h { | ||
| 1383 | - for col in 0..w { | ||
| 1384 | - let v = if screen { | ||
| 1385 | - if row % 7 == 0 && col % 3 == 0 { | ||
| 1386 | - if (col / 3 + row + f) % 2 == 1 { | ||
| 1387 | - 16 | ||
| 1388 | - } else { | ||
| 1389 | - 235 | ||
| 1390 | - } | ||
| 1391 | - } else { | ||
| 1392 | - PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()] | ||
| 1393 | - } | ||
| 1394 | - } else { | ||
| 1395 | - (((col + 2 * f) * 7 + row * 13) % 251) as u32 | ||
| 1396 | - }; | ||
| 1397 | - put(v, &mut raw); | ||
| 1398 | - } | ||
| 1399 | - } | ||
| 1400 | - for plane in 0..2usize { | ||
| 1401 | - for row in 0..h / 2 { | ||
| 1402 | - for col in 0..w / 2 { | ||
| 1403 | - let v = if screen { | ||
| 1404 | - PAL[((col + 2 * f) / 8 + row / 8 + plane) % PAL.len()] | ||
| 1405 | - } else if plane == 0 { | ||
| 1406 | - (((col + f) * 11 + row * 5) % 251) as u32 | ||
| 1407 | - } else { | ||
| 1408 | - ((col * 3 + (row + f) * 17) % 251) as u32 | ||
| 1409 | - }; | ||
| 1410 | - put(v, &mut raw); | ||
| 1411 | - } | ||
| 1412 | - } | ||
| 1413 | - } | ||
| 1414 | - } | ||
| 1415 | - let pix = if depth == 10 { | ||
| 1416 | - "yuv420p10le" | ||
| 1417 | - } else { | ||
| 1418 | - "yuv420p" | ||
| 1419 | - }; | ||
| 1420 | - // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | ||
| 1421 | - let src = std::env::temp_dir().join(format!( | ||
| 1422 | - "ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", | ||
| 1423 | - std::process::id() | ||
| 1424 | - )); | ||
| 1425 | - std::fs::write(&src, &raw).expect("raw source"); | ||
| 1426 | - let mut cmd = Command::new("ffmpeg"); | ||
| 1427 | - cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix]) | ||
| 1428 | - .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | ||
| 1429 | - .arg(&src) | ||
| 1430 | - .args(["-an", "-threads", "1", "-g", gop, "-c:v", "libaom-av1"]) | ||
| 1431 | - .args(["-pix_fmt", pix, "-cpu-used", "6", "-b:v", "0", "-crf", "0"]); | ||
| 1432 | - if sb128 { | ||
| 1433 | - cmd.args(["-aom-params", "sb-size=128"]); | ||
| 1434 | - } | ||
| 1435 | - if screen { | ||
| 1436 | - cmd.args(["-aom-params", "tune-content=screen"]); | ||
| 1437 | - } | ||
| 1438 | - let out = crate::tool_cache::cached_output_io(cmd | ||
| 1439 | - .args(["-f", "obu", "-"]) | ||
| 1440 | - .stdin(Stdio::null()) | ||
| 1441 | - .stdout(Stdio::piped()) | ||
| 1442 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1443 | - .expect("ffmpeg failed to run"); | ||
| 1444 | - let _ = std::fs::remove_file(&src); | ||
| 1445 | - if !out.status.success() { | ||
| 1446 | - eprintln!( | ||
| 1447 | - "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | ||
| 1448 | - String::from_utf8_lossy(&out.stderr) | ||
| 1449 | - ); | ||
| 1450 | - return; | ||
| 1451 | - } | ||
| 1452 | - let stream = out.stdout; | ||
| 1453 | - // The stream must really be lossless AND really carry inter frames | ||
| 1454 | - // (class `gate-blind-to-feature`). | ||
| 1455 | - let mut parser = Av1Parser::new(); | ||
| 1456 | - let (mut pos, mut lossless, mut inters) = (0usize, 0usize, 0usize); | ||
| 1457 | - while pos < stream.len() { | ||
| 1458 | - let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses"); | ||
| 1459 | - pos += obu.total_size.max(1); | ||
| 1460 | - let header = match &obu.kind { | ||
| 1461 | - ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, | ||
| 1462 | - _ => continue, | ||
| 1463 | - }; | ||
| 1464 | - if header.lossless.iter().all(|&l| l) { | ||
| 1465 | - lossless += 1; | ||
| 1466 | - } | ||
| 1467 | - if header.frame_type == FrameType::Inter { | ||
| 1468 | - inters += 1; | ||
| 1469 | - } | ||
| 1470 | - } | ||
| 1471 | - assert!( | ||
| 1472 | - lossless >= frames, | ||
| 1473 | - "{NAME} [{tag}] went blind: {lossless} lossless frames" | ||
| 1474 | - ); | ||
| 1475 | - assert!( | ||
| 1476 | - screen || inters > 0, | ||
| 1477 | - "{NAME} [{tag}] went blind: no inter frame at gop {gop}" | ||
| 1478 | - ); | ||
| 1479 | - let ours = decode_stream(&stream) | ||
| 1480 | - .unwrap_or_else(|e| panic!("{NAME} [{tag}]: a lossless inter stream decodes: {e}")); | ||
| 1481 | - let refs = if depth == 10 { | ||
| 1482 | - ffmpeg_decode_sequence_10bit(&stream, w, h, frames) | ||
| 1483 | - } else { | ||
| 1484 | - ffmpeg_decode_sequence(&stream, w, h, frames) | ||
| 1485 | - }; | ||
| 1486 | - assert_eq!(ours.len(), frames, "{NAME} [{tag}]: frame count"); | ||
| 1487 | - for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() { | ||
| 1488 | - for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 1489 | - .iter() | ||
| 1490 | - .enumerate() | ||
| 1491 | - { | ||
| 1492 | - let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | ||
| 1493 | - assert_eq!( | ||
| 1494 | - bad, 0, | ||
| 1495 | - "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ" | ||
| 1496 | - ); | ||
| 1497 | - assert_eq!( | ||
| 1498 | - g.len(), | ||
| 1499 | - r.len(), | ||
| 1500 | - "{NAME} [{tag}]: frame {i} plane {plane}: ours has {} samples, ffmpeg's has \ | ||
| 1501 | - {} -- a short plane would zip-truncate the compare above and hide a \ | ||
| 1502 | - chroma-span defect", | ||
| 1503 | - g.len(), | ||
| 1504 | - r.len() | ||
| 1505 | - ); | ||
| 1506 | - } | ||
| 1507 | - } | ||
| 1508 | - } | ||
| 1509 | - } | ||
| 1510 | - | ||
| 1511 | - /// lane-av1-llband: the pinned 4:4:4 LOSSLESS key frame | ||
| 1512 | - /// (`fixtures/ll444-lossless-key.obu`, the `ll444` recipe's frame 0 -- | ||
| 1513 | - /// `testsrc2 128x96` yuv444p cut to its key frame) decodes sample-exact, | ||
| 1514 | - /// and its HORZ/VERT strips really walked their chroma as 4x4 units at | ||
| 1515 | - /// subsampling 0/0 (one unit per mi cell). That unit walk used the 4:2:0 | ||
| 1516 | - /// span (8 luma px per 4x4 chroma unit) unconditionally, so every unit | ||
| 1517 | - /// past the first column/row read its `txb_skip` context two mi cells | ||
| 1518 | - /// over and stamped a 2-cell smear -- the 178-byte key-frame miss, first | ||
| 1519 | - /// divergence at the 16x8 leaf mi (16,24)'s U bc=2 unit (oracle | ||
| 1520 | - /// `txb_skip` base 0 off `above[26]`, ours base 1 off the polluted | ||
| 1521 | - /// `above[29]`). The counter assertion is the non-vacuity half (class | ||
| 1522 | - /// `gate-blind-to-feature`): a stream that never reaches the 4:4:4 unit | ||
| 1523 | - /// walk must not pass. | ||
| 1524 | - #[test] | ||
| 1525 | - fn a_real_aomenc_lossless_444_key_frame_decodes_sample_exact() { | ||
| 1526 | - const NAME: &str = "a_real_aomenc_lossless_444_key_frame_decodes_sample_exact"; | ||
| 1527 | - if !have_ffmpeg() { | ||
| 1528 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1529 | - return; | ||
| 1530 | - } | ||
| 1531 | - // lane-av1pins: committed at crates/ec-av1/fixtures/ll444-lossless-key.obu | ||
| 1532 | - // (7845 bytes; sha256 | ||
| 1533 | - // f496ef0a1171c2bc66d411cc60db05db547dcdb49cd834d4e0543de9db441374), | ||
| 1534 | - // re-encoded 2026-09-29 from the recipe this very SKIP line records -- | ||
| 1535 | - // `testsrc2 128x96` yuv444p 6 frames, aomenc --profile=1 --lossless=1 | ||
| 1536 | - // --enable-palette=0 --enable-intrabc=0 --bit-depth=8 --cpu-used=0 | ||
| 1537 | - // --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100, --limit=1 | ||
| 1538 | - // so the key frame's OBUs are the whole stream (no OBU surgery needed). | ||
| 1539 | - // | ||
| 1540 | - // lane-av1skipfix: reading the pin from the GITIGNORED root | ||
| 1541 | - // `fixtures/` (`pin_dir()`) is what made this gate report green having | ||
| 1542 | - // decoded nothing -- a fresh clone, and every linked worktree, can | ||
| 1543 | - // never have that directory. The pin is now COMMITTED under the crate | ||
| 1544 | - // (the home the other pins use) and read through `CARGO_MANIFEST_DIR`, | ||
| 1545 | - // so a missing file is a REPO DEFECT and fails unconditionally: there | ||
| 1546 | - // is no environment left to escape, which is strictly stronger than | ||
| 1547 | - // the `EC_REQUIRE_FIXTURES` / `EC_AV1_REQUIRE_AOMENC` opt-in hard | ||
| 1548 | - // fail this arm used to carry. | ||
| 1549 | - let pin = crate_pin("ll444-lossless-key.obu"); | ||
| 1550 | - let stream = std::fs::read(&pin).unwrap_or_else(|e| { | ||
| 1551 | - panic!( | ||
| 1552 | - "{NAME}: the pinned 4:4:4 lossless key frame is missing at {} ({e}). A \ | ||
| 1553 | - COMMITTED pin that is absent is a repo defect and this gate would prove \ | ||
| 1554 | - nothing. No script generates it -- regenerate it with `testsrc2 128x96` \ | ||
| 1555 | - yuv444p 6 frames, aomenc --profile=1 --lossless=1 --enable-palette=0 \ | ||
| 1556 | - --enable-intrabc=0 --bit-depth=8 --cpu-used=0 --threads=1 --row-mt=0 \ | ||
| 1557 | - --lag-in-frames=0 --kf-max-dist=100 --limit=1, and commit the result.", | ||
| 1558 | - pin.display() | ||
| 1559 | - ) | ||
| 1560 | - }); | ||
| 1561 | - // Blindness guard: the pinned fixture must really be a lossless frame. | ||
| 1562 | - let mut parser = Av1Parser::new(); | ||
| 1563 | - let mut pos = 0usize; | ||
| 1564 | - let mut lossless = false; | ||
| 1565 | - while pos < stream.len() { | ||
| 1566 | - let obu = parser.parse_obu(&stream[pos..]).expect("aomenc OBU parses"); | ||
| 1567 | - pos += obu.total_size.max(1); | ||
| 1568 | - if let ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) = obu.kind { | ||
| 1569 | - lossless = h.lossless.iter().all(|&l| l); | ||
| 1570 | - } | ||
| 1571 | - } | ||
| 1572 | - assert!( | ||
| 1573 | - lossless, | ||
| 1574 | - "{NAME} went blind: the pinned frame is not lossless" | ||
| 1575 | - ); | ||
| 1576 | - let before = crate::decode::rect_split_lossless_chroma444_hits(); | ||
| 1577 | - let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes"); | ||
| 1578 | - assert_eq!(ours.len(), 1, "{NAME}: frame count"); | ||
| 1579 | - assert!( | ||
| 1580 | - crate::decode::rect_split_lossless_chroma444_hits() > before, | ||
| 1581 | - "{NAME} went blind: no lossless HORZ/VERT strip walked its chroma \ | ||
| 1582 | - as 4x4 units at subsampling 0/0" | ||
| 1583 | - ); | ||
| 1584 | - let refs = Command::new("ffmpeg") | ||
| 1585 | - .args([ | ||
| 1586 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", | ||
| 1587 | - ]) | ||
| 1588 | - .stdin(Stdio::piped()) | ||
| 1589 | - .stdout(Stdio::piped()) | ||
| 1590 | - .stderr(Stdio::piped()) | ||
| 1591 | - .spawn() | ||
| 1592 | - .and_then(|mut child| { | ||
| 1593 | - use std::io::Write as _; | ||
| 1594 | - child.stdin.as_mut().expect("stdin").write_all(&stream)?; | ||
| 1595 | - child.wait_with_output() | ||
| 1596 | - }) | ||
| 1597 | - .expect("ffmpeg 444 decode failed"); | ||
| 1598 | - assert!( | ||
| 1599 | - refs.status.success(), | ||
| 1600 | - "{}", | ||
| 1601 | - String::from_utf8_lossy(&refs.stderr) | ||
| 1602 | - ); | ||
| 1603 | - let frame = &ours[0]; | ||
| 1604 | - let planes = [ | ||
| 1605 | - (&frame.y, frame.width * frame.height), | ||
| 1606 | - (&frame.u, frame.width * frame.height), | ||
| 1607 | - (&frame.v, frame.width * frame.height), | ||
| 1608 | - ]; | ||
| 1609 | - let mut off = 0usize; | ||
| 1610 | - for (plane, (g, len)) in planes.iter().enumerate() { | ||
| 1611 | - let raw = &refs.stdout[off..off + len]; | ||
| 1612 | - let bad = g | ||
| 1613 | - .iter() | ||
| 1614 | - .zip(raw.iter()) | ||
| 1615 | - .filter(|&(&a, &b)| a != u16::from(b)) | ||
| 1616 | - .count(); | ||
| 1617 | - assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ"); | ||
| 1618 | - off += len; | ||
| 1619 | - } | ||
| 1620 | - } | ||
| 1621 | - | ||
| 1622 | - /// lane-av1-llinter: the firing gate for the lossless 4:4:4 INTER chroma | ||
| 1623 | - /// fix. The fixture is the report's dodge2 stream pinned into `fixtures/`: | ||
| 1624 | - /// aomenc profile 1 over testsrc2 128x96 yuv444p, `--lossless=1`, | ||
| 1625 | - /// `--sb-size=64 --min-partition-size=64 --max-partition-size=64`, 6 | ||
| 1626 | - /// frames; 37658 bytes, sha256 | ||
| 1627 | - /// `5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4`. | ||
| 1628 | - /// The firing counter is the EXISTING `decode::chroma_split_tx_hits` (one | ||
| 1629 | - /// bump per lossless chroma TX unit read): with min=max partition 64 the | ||
| 1630 | - /// roots stay whole 64x64 inter blocks -- no 8x8 leaf exists in this | ||
| 1631 | - /// stream -- so every chroma unit goes through the big-block ss-aware | ||
| 1632 | - /// lossless route this lane fixed (fixes 2-5). A 4:2:0 lossless stream | ||
| 1633 | - /// fires the same counter, but the fixture bytes are pinned, so the gate | ||
| 1634 | - /// cannot run on anything else; the pre-fix 4:2:0-hardcoded math corrupts | ||
| 1635 | - /// at 4:4:4, so the pixel-exact compares are what prove the ss-aware path | ||
| 1636 | - /// (class `gate-blind-to-feature`). Every frame must come out pixel-exact | ||
| 1637 | - /// through BOTH the oracle `aomdec --rawvideo` and ffmpeg. The | ||
| 1638 | - /// default-partition ll444 stream is deliberately NOT claimed here: its | ||
| 1639 | - /// key frame is still the intra lane's named sub8-chroma stop | ||
| 1640 | - /// (lanes/av1llintra.report.md). | ||
| 1641 | - #[test] | ||
| 1642 | - fn a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact() { | ||
| 1643 | - const NAME: &str = "a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact"; | ||
| 1644 | - const FIXTURE_LEN: usize = 37658; | ||
| 1645 | - const FIXTURE_FNV: u64 = 0xf68d_c26f_a14d_283c; | ||
| 1646 | - const W: usize = 128; | ||
| 1647 | - const H: usize = 96; | ||
| 1648 | - const FRAMES: usize = 6; | ||
| 1649 | - let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1650 | - .join("fixtures/ll444_minp64_inter.obu"); | ||
| 1651 | - let stream = std::fs::read(&obu).unwrap_or_else(|e| { | ||
| 1652 | - panic!( | ||
| 1653 | - "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | ||
| 1654 | - which is a failure, not a skip", | ||
| 1655 | - obu.display() | ||
| 1656 | - ) | ||
| 1657 | - }); | ||
| 1658 | - assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 1659 | - assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 1660 | - | ||
| 1661 | - let _guard = lock_gate_counters(); | ||
| 1662 | - let before = crate::decode::chroma_split_tx_hits(); | ||
| 1663 | - let frames = decode_stream(&stream) | ||
| 1664 | - .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); | ||
| 1665 | - let hits = crate::decode::chroma_split_tx_hits(); | ||
| 1666 | - assert!( | ||
| 1667 | - hits > before, | ||
| 1668 | - "{NAME}: gate is vacuous -- no lossless chroma TX unit was read \ | ||
| 1669 | - (delta {before} -> {hits})" | ||
| 1670 | - ); | ||
| 1671 | - assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | ||
| 1672 | - for f in &frames { | ||
| 1673 | - assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | ||
| 1674 | - } | ||
| 1675 | - | ||
| 1676 | - // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | ||
| 1677 | - if aomdec_available(NAME) { | ||
| 1678 | - let dir = std::env::temp_dir().join(format!("ec-av1-ll444-{}", std::process::id())); | ||
| 1679 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1680 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 1681 | - let raw = dir.join("aomdec.raw"); | ||
| 1682 | - let out = crate::tool_cache::cached_output_io(Command::new(aomdec_path()) | ||
| 1683 | - .args(["--codec=av1", "--rawvideo", "-o"]) | ||
| 1684 | - .arg(&raw) | ||
| 1685 | - .arg(&obu) | ||
| 1686 | - .stdin(Stdio::null()) | ||
| 1687 | - .stdout(Stdio::piped()) | ||
| 1688 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1689 | - .expect("aomdec failed to run"); | ||
| 1690 | - assert!( | ||
| 1691 | - out.status.success(), | ||
| 1692 | - "{NAME}: the oracle aomdec refused the stream: {}", | ||
| 1693 | - String::from_utf8_lossy(&out.stderr) | ||
| 1694 | - ); | ||
| 1695 | - let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | ||
| 1696 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1697 | - assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | ||
| 1698 | - for (i, f) in frames.iter().enumerate() { | ||
| 1699 | - let base = i * W * H * 3; | ||
| 1700 | - for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | ||
| 1701 | - .into_iter() | ||
| 1702 | - .zip(["y", "u", "v"]) | ||
| 1703 | - { | ||
| 1704 | - let want = &ref_raw[base + off..base + off + W * H]; | ||
| 1705 | - let bad = plane | ||
| 1706 | - .iter() | ||
| 1707 | - .zip(want) | ||
| 1708 | - .filter(|&(&a, &b)| a as u8 != b) | ||
| 1709 | - .count(); | ||
| 1710 | - assert_eq!( | ||
| 1711 | - bad, 0, | ||
| 1712 | - "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ" | ||
| 1713 | - ); | ||
| 1714 | - assert_eq!( | ||
| 1715 | - plane.len(), | ||
| 1716 | - want.len(), | ||
| 1717 | - "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \ | ||
| 1718 | - has {} -- a short plane would zip-truncate the compare above and hide \ | ||
| 1719 | - a chroma-span defect", | ||
| 1720 | - plane.len(), | ||
| 1721 | - want.len() | ||
| 1722 | - ); | ||
| 1723 | - } | ||
| 1724 | - } | ||
| 1725 | - } | ||
| 1726 | - | ||
| 1727 | - // ffmpeg's decoder: same frames, full-resolution chroma. | ||
| 1728 | - if have_ffmpeg() { | ||
| 1729 | - let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | ||
| 1730 | - for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate() { | ||
| 1731 | - for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 1732 | - .iter() | ||
| 1733 | - .enumerate() | ||
| 1734 | - { | ||
| 1735 | - let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | ||
| 1736 | - assert_eq!( | ||
| 1737 | - bad, 0, | ||
| 1738 | - "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | ||
| 1739 | - ); | ||
| 1740 | - assert_eq!( | ||
| 1741 | - g.len(), | ||
| 1742 | - r.len(), | ||
| 1743 | - "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has {} \ | ||
| 1744 | - -- a short plane would zip-truncate the compare above and hide a \ | ||
| 1745 | - chroma-span defect", | ||
| 1746 | - g.len(), | ||
| 1747 | - r.len() | ||
| 1748 | - ); | ||
| 1749 | - } | ||
| 1750 | - } | ||
| 1751 | - } else { | ||
| 1752 | - eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); | ||
| 1753 | - } | ||
| 1754 | - } | ||
| 1755 | - | ||
| 1756 | - /// lane-av1h5: the 128-ROOT lossless 4:4:4 pin, and the control arm | ||
| 1757 | - /// that proves the 128 root is what it needs. | ||
| 1758 | - /// | ||
| 1759 | - /// Witness: testsrc2 128x96 yuv444p10le, aomenc `--profile=1 --lossless=1 | ||
| 1760 | - /// --enable-palette=0 --enable-intrabc=0 --cpu-used=0`, 6 frames; 63429 | ||
| 1761 | - /// bytes, sha256 `bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa`. | ||
| 1762 | - /// Control: the same recipe at `--max-partition-size=64` (61494 bytes, | ||
| 1763 | - /// sha256 `4cadce41e1f8967567b32f5cf8abaa46ffdf4fd6d4afe784c8d99a7f6bf1ae4c`), | ||
| 1764 | - /// which never reaches a 128 root. | ||
| 1765 | - /// | ||
| 1766 | - /// libaom's `decode_token_recon_block` (`av1/decoder/decodeframe.c:972`) | ||
| 1767 | - /// walks 64x64 "mu" chunks with the PLANE loop inside the chunk loop, on a | ||
| 1768 | - /// chunk grid of `mi_size_wide[BLOCK_64X64]` = 16 mi per axis. The var-tx | ||
| 1769 | - /// leaf list is a BLOCK-wide raster (32 leaves across at 128), so a chunk's | ||
| 1770 | - /// members are not contiguous: leaves 0..15 are chunk (0,0) row 0, but | ||
| 1771 | - /// chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ... A chunk test on | ||
| 1772 | - /// the given order closed the chunk every SIXTEEN leaves and coded each | ||
| 1773 | - /// chunk's chroma sixteen times. | ||
| 1774 | - /// | ||
| 1775 | - /// The three assertions below are all EXACT and all stay true when the | ||
| 1776 | - /// stream becomes byte-exact. None of them is a floor on wrong output: | ||
| 1777 | - /// a no-op [`crate::decode::mu_chunk_order`] permutation reads 0 on | ||
| 1778 | - /// `mu_chunk_order_hits`, so the first cannot be satisfied by a gate that | ||
| 1779 | - /// merely ran; the walk and unit totals are libaom's own per-chunk counts; | ||
| 1780 | - /// the control arm is a straight exactness assertion. | ||
| 1781 | - #[test] | ||
| 1782 | - fn a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major() { | ||
| 1783 | - const NAME: &str = "a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major"; | ||
| 1784 | - const W: usize = 128; | ||
| 1785 | - const H: usize = 96; | ||
| 1786 | - const FRAMES: usize = 6; | ||
| 1787 | - /// 5 inter frames, one unsplit 128 root each; frame 0 splits. | ||
| 1788 | - const ROOTS: usize = 5; | ||
| 1789 | - /// libaom's chunk grid on a 128x128 root: 2x2 chunks per root. | ||
| 1790 | - const CHUNKS_PER_ROOT: usize = 4; | ||
| 1791 | - /// Chroma TX_4X4 units per inter frame: 768 per plane over 128x96. | ||
| 1792 | - const UNITS_PER_FRAME: usize = 1536; | ||
| 1793 | - | ||
| 1794 | - let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1795 | - .join("fixtures/ll444_128root_lossless.obu"); | ||
| 1796 | - let stream = read_pin(&obu, 63429, 0xf07d_47fc_fd51_2658, NAME); | ||
| 1797 | - let _guard = lock_gate_counters(); | ||
| 1798 | - let (o0, w0, u0) = ( | ||
| 1799 | - crate::decode::mu_chunk_order_hits(), | ||
| 1800 | - crate::decode::mu_chunk_walks(), | ||
| 1801 | - crate::decode::mu_chunk_walk_units(), | ||
| 1802 | - ); | ||
| 1803 | - let frames = decode_stream(&stream) | ||
| 1804 | - .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); | ||
| 1805 | - let (o1, w1, u1) = ( | ||
| 1806 | - crate::decode::mu_chunk_order_hits(), | ||
| 1807 | - crate::decode::mu_chunk_walks(), | ||
| 1808 | - crate::decode::mu_chunk_walk_units(), | ||
| 1809 | - ); | ||
| 1810 | - // (1) the reorder PERMUTED each root's walk -- a no-op reads 0. | ||
| 1811 | - assert_eq!( | ||
| 1812 | - o1 - o0, | ||
| 1813 | - ROOTS, | ||
| 1814 | - "{NAME}: the chunk-major sort permuted {}/{} of the 128 roots -- a no-op \ | ||
| 1815 | - ordering must read 0 here, so this is what makes the gate non-vacuous", | ||
| 1816 | - o1 - o0, | ||
| 1817 | - ROOTS | ||
| 1818 | - ); | ||
| 1819 | - // (2) libaom's own per-chunk counts: 4 chroma walks per 128 root, and | ||
| 1820 | - // the 1536 chroma units an inter frame codes at 128x96 4:4:4. | ||
| 1821 | - assert_eq!( | ||
| 1822 | - w1 - w0, | ||
| 1823 | - ROOTS * CHUNKS_PER_ROOT, | ||
| 1824 | - "{NAME}: {}/{} chunk-major chroma walks; the 16x redundancy (64 per \ | ||
| 1825 | - frame instead of 4) would read {}", | ||
| 1826 | - w1 - w0, | ||
| 1827 | - ROOTS * CHUNKS_PER_ROOT, | ||
| 1828 | - ROOTS * CHUNKS_PER_ROOT * 16 | ||
| 1829 | - ); | ||
| 1830 | - assert_eq!( | ||
| 1831 | - u1 - u0, | ||
| 1832 | - ROOTS * UNITS_PER_FRAME, | ||
| 1833 | - "{NAME}: {}/{} chroma units over the 128 roots; the oracle codes {} \ | ||
| 1834 | - per inter frame and our pre-fix walk read 16x that", | ||
| 1835 | - u1 - u0, | ||
| 1836 | - ROOTS * UNITS_PER_FRAME, | ||
| 1837 | - UNITS_PER_FRAME | ||
| 1838 | - ); | ||
| 1839 | - assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | ||
| 1840 | - for f in &frames { | ||
| 1841 | - assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | ||
| 1842 | - } | ||
| 1843 | - | ||
| 1844 | - // (3) the control arm: no 128 root, and byte-exact through the oracle. | ||
| 1845 | - let ctrl = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1846 | - .join("fixtures/ll444_minp64_128root_control.obu"); | ||
| 1847 | - let ctrl_stream = read_pin( | ||
| 1848 | - &ctrl, | ||
| 1849 | - 61494, | ||
| 1850 | - 0xf6f5_a3cb_efc7_eb10, | ||
| 1851 | - &format!("{NAME} control"), | ||
| 1852 | - ); | ||
| 1853 | - let _ = decode_stream(&ctrl_stream) | ||
| 1854 | - .unwrap_or_else(|e| panic!("{NAME}: the control arm no longer decodes cleanly: {e}")); | ||
| 1855 | - if aomdec_available(NAME) { | ||
| 1856 | - assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES, 10); | ||
| 1857 | - } | ||
| 1858 | - } | ||
| 1859 | - | ||
| 1860 | - /// lane-av1lm444loss: a LOSSLESS block's transform-unit grid is clipped at | ||
| 1861 | - /// the FRAME edge, exactly as libaom's `max_block_high`/`max_block_wide` | ||
| 1862 | - /// clip it (`av1_common_int.h:1565`, `:1579` fold `mb_to_bottom_edge` / | ||
| 1863 | - /// `mb_to_right_edge` into `block_size_high/wide` before `>> | ||
| 1864 | - /// MI_SIZE_LOG2`), so a block hanging off the bottom/right codes only the | ||
| 1865 | - /// units inside the frame. `decode_token_recon_block` then bounds every | ||
| 1866 | - /// mu chunk with `unit_height = ROUND_POWER_OF_TWO(AOMMIN(mu_blocks_high | ||
| 1867 | - /// + row, max_blocks_high), ss_y)`, so the overflow units are never read | ||
| 1868 | - /// there either. | ||
| 1869 | - /// | ||
| 1870 | - /// Fixture is the sibling [`a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major`] | ||
| 1871 | - /// pin -- 128x96 yuv444p 4:4:4 lossless, 6 frames, 63429 bytes -- because | ||
| 1872 | - /// 96 is NOT a multiple of the 128 superblock: its five inter frames each | ||
| 1873 | - /// carry one unsplit 128 root that overhangs the bottom by 32 px. That is | ||
| 1874 | - /// the whole reason this stream is the witness. The frame is 24 mi tall, | ||
| 1875 | - /// so `max_blocks_high >> 2` is 24 transform rows where the block's own | ||
| 1876 | - /// `side / MI` is 32. | ||
| 1877 | - /// | ||
| 1878 | - /// The three assertions are all non-vacuous and all EXACT: | ||
| 1879 | - /// | ||
| 1880 | - /// 1. `lossless_edge_clipped()` fired -- 5, one per inter frame's 128 | ||
| 1881 | - /// root. It is 0 on any frame whose height and width are multiples of | ||
| 1882 | - /// the superblock, so a stream that merely decodes cannot satisfy it. | ||
| 1883 | - /// 2. `lossless_edge_clip_units()` is 1280 = 5 x 256: the 8 transform rows | ||
| 1884 | - /// x 32 columns the unclipped walk read past the frame bottom, per | ||
| 1885 | - /// inter frame. The pre-fix walk read 2560 units per inter frame | ||
| 1886 | - /// against the oracle's 2304, and this is that 256. | ||
| 1887 | - /// 3. every sample of every frame matches the oracle `aomdec | ||
| 1888 | - /// --rawvideo` in decode order -- all six frames, hidden alt-ref | ||
| 1889 | - /// included, which the pre-fix tree failed from frame 1 on | ||
| 1890 | - /// (5596 wrong samples there, growing to 33561 by frame 5). | ||
| 1891 | - /// | ||
| 1892 | - /// The control arm pins the other direction of the invariant: the | ||
| 1893 | - /// `ll444_minp64_128root_control` stream has no overhanging root, so its | ||
| 1894 | - /// clip counters must both read 0 -- the clip cannot fire on a block that | ||
| 1895 | - /// fits, which is what keeps every other lossless pin byte-identical. | ||
| 1896 | - #[test] | ||
| 1897 | - fn a_lossless_block_clips_its_transform_grid_at_the_frame_edge() { | ||
| 1898 | - const NAME: &str = "a_lossless_block_clips_its_transform_grid_at_the_frame_edge"; | ||
| 1899 | - const W: usize = 128; | ||
| 1900 | - const H: usize = 96; | ||
| 1901 | - const FRAMES: usize = 6; | ||
| 1902 | - /// 5 inter frames, one unsplit 128 root each; frame 0 splits. | ||
| 1903 | - const ROOTS: usize = 5; | ||
| 1904 | - /// `max_blocks_high >> 2` = 24 rows (96 px / 4), against the block's | ||
| 1905 | - /// own `side / MI` = 32 -- so 8 rows x 32 columns = 256 units per root | ||
| 1906 | - /// were read past the frame bottom before the clip. | ||
| 1907 | - const CLIP_UNITS_PER_ROOT: usize = 256; | ||
| 1908 | - | ||
| 1909 | - let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1910 | - .join("fixtures/ll444_128root_lossless.obu"); | ||
| 1911 | - let stream = read_pin(&obu, 63429, 0xf07d_47fc_fd51_2658, NAME); | ||
| 1912 | - let _guard = lock_gate_counters(); | ||
| 1913 | - let (c0, u0) = ( | ||
| 1914 | - crate::decode::lossless_edge_clipped(), | ||
| 1915 | - crate::decode::lossless_edge_clip_units(), | ||
| 1916 | - ); | ||
| 1917 | - let frames = decode_stream(&stream) | ||
| 1918 | - .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); | ||
| 1919 | - let (c1, u1) = ( | ||
| 1920 | - crate::decode::lossless_edge_clipped(), | ||
| 1921 | - crate::decode::lossless_edge_clip_units(), | ||
| 1922 | - ); | ||
| 1923 | - assert_eq!( | ||
| 1924 | - c1 - c0, | ||
| 1925 | - ROOTS, | ||
| 1926 | - "{NAME}: the frame-edge clip fired on {}/{} of the 128 roots -- it must be 0 \ | ||
| 1927 | - on a frame that fits, so this is what makes the gate non-vacuous", | ||
| 1928 | - c1 - c0, | ||
| 1929 | - ROOTS | ||
| 1930 | - ); | ||
| 1931 | - assert_eq!( | ||
| 1932 | - u1 - u0, | ||
| 1933 | - ROOTS * CLIP_UNITS_PER_ROOT, | ||
| 1934 | - "{NAME}: the clip removed {}/{} transform units; the unclipped walk read {} \ | ||
| 1935 | - per inter frame past the 96 px frame bottom (8 rows x 32 columns)", | ||
| 1936 | - u1 - u0, | ||
| 1937 | - ROOTS * CLIP_UNITS_PER_ROOT, | ||
| 1938 | - CLIP_UNITS_PER_ROOT | ||
| 1939 | - ); | ||
| 1940 | - assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | ||
| 1941 | - for f in &frames { | ||
| 1942 | - assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | ||
| 1943 | - } | ||
| 1944 | - if aomdec_available(NAME) { | ||
| 1945 | - assert_rawvideo_matches(&obu, &stream, NAME, FRAMES, 10); | ||
| 1946 | - } | ||
| 1947 | - | ||
| 1948 | - // Control: a stream whose roots all fit must not clip at all. | ||
| 1949 | - let ctrl = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 1950 | - .join("fixtures/ll444_minp64_128root_control.obu"); | ||
| 1951 | - let ctrl_stream = read_pin( | ||
| 1952 | - &ctrl, | ||
| 1953 | - 61494, | ||
| 1954 | - 0xf6f5_a3cb_efc7_eb10, | ||
| 1955 | - &format!("{NAME} control"), | ||
| 1956 | - ); | ||
| 1957 | - let (c2, u2) = ( | ||
| 1958 | - crate::decode::lossless_edge_clipped(), | ||
| 1959 | - crate::decode::lossless_edge_clip_units(), | ||
| 1960 | - ); | ||
| 1961 | - let _ = decode_stream(&ctrl_stream) | ||
| 1962 | - .unwrap_or_else(|e| panic!("{NAME}: the control arm no longer decodes cleanly: {e}")); | ||
| 1963 | - assert_eq!( | ||
| 1964 | - crate::decode::lossless_edge_clipped() - c2, | ||
| 1965 | - 0, | ||
| 1966 | - "{NAME} control: the clip fired on a stream whose blocks all fit -- the clip \ | ||
| 1967 | - must be a no-op there, which is what keeps every other lossless pin \ | ||
| 1968 | - byte-identical" | ||
| 1969 | - ); | ||
| 1970 | - assert_eq!( | ||
| 1971 | - crate::decode::lossless_edge_clip_units() - u2, | ||
| 1972 | - 0, | ||
| 1973 | - "{NAME} control: the clip removed units from a stream whose blocks all fit" | ||
| 1974 | - ); | ||
| 1975 | - } | ||
| 1976 | - | ||
| 1977 | - /// lane-av1lm444loss-corr: the MI STEP at which `decode_intrabc_rect`'s | ||
| 1978 | - /// lossless chroma replay walks the plane block. | ||
| 1979 | - /// | ||
| 1980 | - /// `lane-whtshape` (`f541d062`, merged `afa13bcf`) gave this route the | ||
| 1981 | - /// per-TX_4X4 lossless chroma walk and the tail replay that re-stamps | ||
| 1982 | - /// each unit's own coefficient context over the whole-block record. The | ||
| 1983 | - /// replay stepped by `4 >> ss_y(fctx)` mi cells, which is 4:2:0-only | ||
| 1984 | - /// arithmetic: at ss (1,1) it reads 2 and the ss-aware form | ||
| 1985 | - /// `(4 << ss_y) / MI` also reads 2, so 4:2:0 agrees by construction; at | ||
| 1986 | - /// ss (0,0) it reads 4 mi, i.e. 16 luma px per 4x4 chroma unit, where the | ||
| 1987 | - /// unit covers `4 << 0` = 4 luma px = ONE mi. Every replayed unit was | ||
| 1988 | - /// therefore stamped at 4x its own mi origin on a 4:4:4 lossless frame, | ||
| 1989 | - /// writing over cells that belong to other blocks. | ||
| 1990 | - /// | ||
| 1991 | - /// This gate is the WIRNESS stream, not a vacuous one. The 4:2:0 | ||
| 1992 | - /// 4x4-identity is stated in the step's own comment and measured by the | ||
| 1993 | - /// `4:2:0` arm of the lane's invariant battery, not asserted here -- | ||
| 1994 | - /// a 4:2:0 stream cannot fail this gate, by construction, and pretending | ||
| 1995 | - /// otherwise would be a floor on wrong output. | ||
| 1996 | - /// | ||
| 1997 | - /// Fixture `ll444_intrabc_rect_l2.obu`, 121844 bytes, sha256 | ||
| 1998 | - /// `f0de080edce35d34cdd628b71f63dc452f946e8328352b69d3c1da090a54ec67`: | ||
| 1999 | - /// `testsrc2 512x128 yuv444p`, aomenc `--lossless=1 --cpu-used=2 | ||
| 2000 | - /// --lag-in-frames=0 --kf-max-dist=100 --limit=6`, 6 frames. On main's | ||
crates/ec-av1/src/stream/tests/t03.rsdeleted+0 -4567
Diff too large; view file
| @@ -1,4567 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | -use super::gates_a::*; | ||
| 4 | -use crate::probe::run_with_stdin; | ||
| 5 | -use std::process::{Command, Stdio}; | ||
| 6 | - | ||
| 7 | - /// As [`a_real_libaom_gradients_stream_decodes_pixel_exact`], but leaves | ||
| 8 | - /// CDEF *on* (no `-enable-cdef 0`) -- the whole point of `lane-av1cdef`: | ||
| 9 | - /// proves `apply_cdef` itself, not just that this decoder still works | ||
| 10 | - /// when the filter never fires. Gradient content at a low crf reliably | ||
| 11 | - /// gives libaom something to dering. | ||
| 12 | - /// | ||
| 13 | - /// lane-av1skipfix: the attempt-loop shape. A single-SB 64x64 frame can | ||
| 14 | - /// never make libaom write `cdef_bits > 0` (nothing to differentiate per | ||
| 15 | - /// superblock), so this recipe is MULTI-SB and MULTI-FRAME, and it sweeps | ||
| 16 | - /// (size, cpu-used, crf) until one attempt reads a real `cdef_idx` literal | ||
| 17 | - /// -- MEASURED 2026-09-29 on `a21f3680`: 64x64 at every crf/cpu reads | ||
| 18 | - /// ZERO `cdef_idx` (single superblock, `bits == 0`, though `apply_cdef` | ||
| 19 | - /// does filter with a nonzero strength pair), while 128x64/128x128 at | ||
| 20 | - /// 24 frames read 2-8. Every attempt that decodes is ALWAYS pixel- | ||
| 21 | - /// compared against ffmpeg's own decode of the identical bytes; a decode | ||
| 22 | - /// error is a named refusal recorded per attempt, never a SKIP, and | ||
| 23 | - /// exhausting every attempt -- or decoding without ever reading a | ||
| 24 | - /// `cdef_idx` -- is a hard FAILURE (an unfired gate is a vacuous gate, | ||
| 25 | - /// class `gate-skips-on-its-own-failure`). | ||
| 26 | - #[test] | ||
| 27 | - fn a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact() { | ||
| 28 | - const NAME: &str = "a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact"; | ||
| 29 | - let _gate_lock = lock_gate_counters(); | ||
| 30 | - if !have_ffmpeg() { | ||
| 31 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 32 | - return; | ||
| 33 | - } | ||
| 34 | - // (width, height, frames, cpu-used, crf). The frame count is what | ||
| 35 | - // gives libaom's cdef search more than one superblock to price. | ||
| 36 | - const RECIPES: [(usize, usize, usize, &str, u32); 8] = [ | ||
| 37 | - (128, 64, 24, "0", 20), | ||
| 38 | - (128, 64, 24, "2", 20), | ||
| 39 | - (128, 64, 24, "0", 16), | ||
| 40 | - (128, 128, 24, "2", 20), | ||
| 41 | - (128, 128, 24, "0", 16), | ||
| 42 | - (128, 128, 24, "0", 24), | ||
| 43 | - (128, 64, 24, "2", 24), | ||
| 44 | - (128, 128, 24, "2", 24), | ||
| 45 | - ]; | ||
| 46 | - let mut refusals = Vec::new(); | ||
| 47 | - let mut counted_exact = 0u32; | ||
| 48 | - let mut uncounted_exact = 0u32; | ||
| 49 | - for (w, h, frames, cpu, crf) in RECIPES { | ||
| 50 | - let Some(stream) = libaom_encode_with( | ||
| 51 | - &gradients_source(42, w, h, "rate=25"), | ||
| 52 | - w, | ||
| 53 | - h, | ||
| 54 | - crf, | ||
| 55 | - &[ | ||
| 56 | - "-cpu-used", | ||
| 57 | - cpu, | ||
| 58 | - "-frames:v", | ||
| 59 | - &frames.to_string(), | ||
| 60 | - "-threads", | ||
| 61 | - "1", | ||
| 62 | - "-row-mt", | ||
| 63 | - "0", | ||
| 64 | - "-tile-columns", | ||
| 65 | - "0", | ||
| 66 | - "-tile-rows", | ||
| 67 | - "0", | ||
| 68 | - ], | ||
| 69 | - ) else { | ||
| 70 | - refusals.push(format!( | ||
| 71 | - "{w}x{h} cpu-used {cpu} crf {crf}: ffmpeg itself refused" | ||
| 72 | - )); | ||
| 73 | - continue; | ||
| 74 | - }; | ||
| 75 | - let before = decode::cdef_idx_hits(); | ||
| 76 | - let decoded = match decode_stream(&stream) { | ||
| 77 | - Ok(frames) => frames, | ||
| 78 | - Err(e) => { | ||
| 79 | - refusals.push(format!("{w}x{h} cpu-used {cpu} crf {crf}: {e}")); | ||
| 80 | - continue; | ||
| 81 | - } | ||
| 82 | - }; | ||
| 83 | - // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 84 | - // counter only decides whether the attempt counts as firing | ||
| 85 | - // (class `counter-from-refused-stream`). | ||
| 86 | - let counted = decode::cdef_idx_hits() != before; | ||
| 87 | - if counted { | ||
| 88 | - counted_exact += 1; | ||
| 89 | - } else { | ||
| 90 | - uncounted_exact += 1; | ||
| 91 | - } | ||
| 92 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, w, h, frames); | ||
| 93 | - assert_eq!(decoded.len(), frames); | ||
| 94 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 95 | - assert_eq!( | ||
| 96 | - got.y, want.y, | ||
| 97 | - "{NAME} frame {i} luma vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 98 | - cdef_idx fired: {counted})" | ||
| 99 | - ); | ||
| 100 | - assert_eq!( | ||
| 101 | - got.u, want.u, | ||
| 102 | - "{NAME} frame {i} U vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 103 | - cdef_idx fired: {counted})" | ||
| 104 | - ); | ||
| 105 | - assert_eq!( | ||
| 106 | - got.v, want.v, | ||
| 107 | - "{NAME} frame {i} V vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 108 | - cdef_idx fired: {counted})" | ||
| 109 | - ); | ||
| 110 | - } | ||
| 111 | - if counted_exact >= 2 { | ||
| 112 | - break; | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 116 | - assert!( | ||
| 117 | - counted_exact > 0, | ||
| 118 | - "{NAME}: no attempt of {} read a cdef_idx literal -- CDEF is not exercised \ | ||
| 119 | - (class gate-blind-to-feature):\n{}", | ||
| 120 | - RECIPES.len(), | ||
| 121 | - refusals.join("\n") | ||
| 122 | - ); | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - /// lane-av1422h232: the non-vacuity test for [`count_rawvideo_diffs`]. | ||
| 126 | - /// | ||
| 127 | - /// A cell-classifying counter that cannot report a difference is worse | ||
| 128 | - /// than no counter, because it reports "exact" for everything -- that is | ||
| 129 | - /// exactly how lane-av1422remeasure's "18/18 byte-exact" table was | ||
| 130 | - /// produced (it compared our own packed samples against the same | ||
| 131 | - /// samples, never reading `aomdec`'s output). | ||
| 132 | - /// | ||
| 133 | - /// It used to lean on the pinned witness DIFFERING to prove the counting | ||
| 134 | - /// path fires. That witness is byte-exact now (lane-av1422hrtx fixed the | ||
| 135 | - /// 32-point inter chroma `tx_type`), so "it differs" is no longer | ||
| 136 | - /// available and a witness-based version of this test would be vacuous by | ||
| 137 | - /// construction. Instead this proves the same property directly and | ||
| 138 | - /// unconditionally: flipping ONE bit of the ORACLE's own bytes must move | ||
| 139 | - /// the count by exactly one, in the plane that bit is in, and knock exactly | ||
| 140 | - /// one frame out of `frames_exact`. A comparator that had stopped reading | ||
| 141 | - /// the oracle reports the baseline numbers again and fails by name. | ||
| 142 | - #[test] | ||
| 143 | - fn the_counting_oracle_diff_detects_one_flipped_oracle_byte() { | ||
| 144 | - const NAME: &str = "the_counting_oracle_diff_detects_one_flipped_oracle_byte"; | ||
| 145 | - // lane-av1cmpaudit2: same mutex as every other oracle gate -- this | ||
| 146 | - // one reads `aomdec_path()`, so it must not overlap a sibling's | ||
| 147 | - // tampered-oracle run. | ||
| 148 | - let _gate_lock = lock_gate_counters(); | ||
| 149 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 150 | - .join("fixtures") | ||
| 151 | - .join("420_oddheight_320x232.obu"); | ||
| 152 | - let data = std::fs::read(&path).expect("the pinned witness is missing"); | ||
| 153 | - let (wy, wu, wv, frames, exact) = | ||
| 154 | - count_rawvideo_diffs(&data, NAME, None).expect("the two sides must be byte-comparable"); | ||
| 155 | - assert_eq!( | ||
| 156 | - (wy, wu, wv, exact), | ||
| 157 | - (0, 0, 0, frames), | ||
| 158 | - "{NAME}: the pinned witness must decode byte-exactly against `aomdec --rawvideo`" | ||
| 159 | - ); | ||
| 160 | - // Frame 0 byte 0 is luma; byte 90_000 is inside frame 0's chroma. | ||
| 161 | - for (idx, plane) in [(0usize, 0usize), (90_000, 1)] { | ||
| 162 | - let (wy, wu, wv, _, exact) = count_rawvideo_diffs(&data, NAME, Some(idx)) | ||
| 163 | - .expect("the two sides must be byte-comparable"); | ||
| 164 | - let got = [wy, wu, wv]; | ||
| 165 | - assert_eq!( | ||
| 166 | - got.iter().sum::<usize>(), | ||
| 167 | - 1, | ||
| 168 | - "{NAME}: flipping oracle byte {idx} must report exactly ONE wrong sample \ | ||
| 169 | - across all planes -- got {got:?}. Reporting the unflipped numbers means \ | ||
| 170 | - the comparison stopped reading the oracle's bytes" | ||
| 171 | - ); | ||
| 172 | - assert_eq!(got[plane], 1, "{NAME}: byte {idx} is in plane {plane}"); | ||
| 173 | - assert_eq!( | ||
| 174 | - exact, | ||
| 175 | - frames - 1, | ||
| 176 | - "{NAME}: one flipped byte spoils one frame" | ||
| 177 | - ); | ||
| 178 | - } | ||
| 179 | - eprintln!("{NAME}: baseline exact, each flipped oracle byte reported as exactly 1"); | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - /// lane-av1cmpframe: the control for the class | ||
| 183 | - /// `comparator-that-attributes-the-wrong-plane`. | ||
| 184 | - /// | ||
| 185 | - /// [`count_rawvideo_diffs`] used to derive its plane split from the FIRST | ||
| 186 | - /// decoded picture and compare every byte index against those frame-0 | ||
| 187 | - /// thresholds. On a multi-frame stream that attributes every sample after | ||
| 188 | - /// frame 0's luma to the LAST plane: on the pinned 320x236 stream below | ||
| 189 | - /// (16 frames of 320x236 4:2:0, 113 280 bytes per frame, so plane V holds | ||
| 190 | - /// 302 080 bytes in total) it reported `wrong_v = 330 673` -- more wrong V | ||
| 191 | - /// bytes than exist. The per-frame totals and the frame-exact count were | ||
| 192 | - /// sound, so the defect was invisible to every gate that only asserted | ||
| 193 | - /// zeros; it corrupted exactly the numbers a per-plane report exists to | ||
| 194 | - /// give. | ||
| 195 | - /// | ||
| 196 | - /// Three arms, each of which the old attribution FAILS: | ||
| 197 | - /// | ||
| 198 | - /// 1. **Arithmetic.** Each plane's count must be at most that plane's own | ||
| 199 | - /// byte capacity summed over frames, and the three must sum to the | ||
| 200 | - /// independently computed total. The old code reported 330 673 wrong V | ||
| 201 | - /// bytes in a 302 080-byte plane. | ||
| 202 | - /// 2. **A later frame's U.** Flipping one byte inside frame 5's U plane | ||
| 203 | - /// must move U by exactly one and leave Y and V at their baseline. | ||
| 204 | - /// The old code has no frame-5 U at all -- byte 600 000 is past every | ||
| 205 | - /// frame-0 threshold, so it landed in V. | ||
| 206 | - /// 3. **Frame attribution.** `frames_exact` must equal the number of | ||
| 207 | - /// frames this test counts itself, per frame, from the decoded | ||
| 208 | - /// pictures' own plane lengths. | ||
| 209 | - /// | ||
| 210 | - /// The pin is asserted only for IDENTITY (bytes + fnv1a64) and for | ||
| 211 | - /// comparability. Whether the stream currently diverges is deliberately | ||
| 212 | - /// NOT asserted: this is a control for the INSTRUMENT, and it must keep | ||
| 213 | - /// biting after the odd-height entropy fork is fixed. | ||
| 214 | - #[test] | ||
| 215 | - fn the_counting_oracle_diff_attributes_planes_per_frame() { | ||
| 216 | - const NAME: &str = "the_counting_oracle_diff_attributes_planes_per_frame"; | ||
| 217 | - let _gate_lock = lock_gate_counters(); | ||
| 218 | - const FILE: &str = "420_oddheight_320x236.obu"; | ||
| 219 | - const BYTES: usize = 16562; | ||
| 220 | - // sha256 84e4d1ab56620af1c5b78e1aa3d2d67496a492f2e127198c82dd1d68b01c6200. | ||
| 221 | - // The tree pins fixture identity by fnv1a64; a `const SHA256` | ||
| 222 | - // compared against itself would be the tautology this lane exists to | ||
| 223 | - // kill, so it is not written. | ||
| 224 | - const FNV1A64: u64 = 521889434652397870; | ||
| 225 | - let data = crate_pin("420_oddheight_320x236.obu"); | ||
| 226 | - let data = std::fs::read(&data) | ||
| 227 | - .unwrap_or_else(|e| panic!("{NAME}: the committed pin {FILE} is missing ({e})")); | ||
| 228 | - assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); | ||
| 229 | - assert_eq!(fnv1a64(&data), FNV1A64, "{NAME}: {FILE} bytes drifted"); | ||
| 230 | - let bit_depth = stream_bit_depth(&data, NAME); | ||
| 231 | - let bpp = if bit_depth == 8 { 1 } else { 2 }; | ||
| 232 | - | ||
| 233 | - // ---- this test's own reading of the oracle, from scratch --------- | ||
| 234 | - let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 235 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 236 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 237 | - let obu = dir.join("in.obu"); | ||
| 238 | - std::fs::write(&obu, &data).expect("writing the stream"); | ||
| 239 | - let raw = dir.join("aomdec.raw"); | ||
| 240 | - let out = crate::tool_cache::cached_output_io(Command::new(aomdec_path()) | ||
| 241 | - .args(["--codec=av1", "--rawvideo", "-o"]) | ||
| 242 | - .arg(&raw) | ||
| 243 | - .arg(&obu) | ||
| 244 | - .stdin(Stdio::null()) | ||
| 245 | - .stdout(Stdio::piped()) | ||
| 246 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 247 | - .expect("aomdec failed to run"); | ||
| 248 | - assert!( | ||
| 249 | - out.status.success(), | ||
| 250 | - "{NAME}: the oracle aomdec refused the stream: {}", | ||
| 251 | - String::from_utf8_lossy(&out.stderr) | ||
| 252 | - ); | ||
| 253 | - let want = std::fs::read(&raw).expect("aomdec rawvideo output"); | ||
| 254 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 255 | - let decoded = decode_stream(&data).expect("the pinned stream decodes"); | ||
| 256 | - let ours = pack_rawvideo(&decoded, bit_depth, NAME); | ||
| 257 | - assert_eq!( | ||
| 258 | - ours.len(), | ||
| 259 | - want.len(), | ||
| 260 | - "{NAME}: the two sides differ in size" | ||
| 261 | - ); | ||
| 262 | - | ||
| 263 | - // The per-frame plane table, built from each decoded picture's OWN | ||
| 264 | - // plane lengths -- the same source `pack_rawvideo` lays the bytes out | ||
| 265 | - // from, and never a formula. | ||
| 266 | - let mut spans: Vec<[usize; 4]> = Vec::with_capacity(decoded.len()); | ||
| 267 | - let mut capacity = [0usize; 3]; | ||
| 268 | - let mut off = 0usize; | ||
| 269 | - for f in &decoded { | ||
| 270 | - let (y, u, v) = (f.y.len() * bpp, f.u.len() * bpp, f.v.len() * bpp); | ||
| 271 | - spans.push([off, off + y, off + y + u, off + y + u + v]); | ||
| 272 | - capacity[0] += y; | ||
| 273 | - capacity[1] += u; | ||
| 274 | - capacity[2] += v; | ||
| 275 | - off += y + u + v; | ||
| 276 | - } | ||
| 277 | - assert_eq!(off, ours.len(), "{NAME}: the plane table covers the buffer"); | ||
| 278 | - | ||
| 279 | - // The truth, counted here with no help from the helper under test. | ||
| 280 | - let mut truth = [0usize; 3]; | ||
| 281 | - let mut truth_exact = 0usize; | ||
| 282 | - for s in &spans { | ||
| 283 | - let mut frame_exact = true; | ||
| 284 | - for (p, a, b) in [(0usize, s[0], s[1]), (1, s[1], s[2]), (2, s[2], s[3])] { | ||
| 285 | - let n = ours[a..b] | ||
| 286 | - .iter() | ||
| 287 | - .zip(&want[a..b]) | ||
| 288 | - .filter(|(x, y)| x != y) | ||
| 289 | - .count(); | ||
| 290 | - truth[p] += n; | ||
| 291 | - frame_exact &= n == 0; | ||
| 292 | - } | ||
| 293 | - truth_exact += usize::from(frame_exact); | ||
| 294 | - } | ||
| 295 | - | ||
| 296 | - let (wy, wu, wv, frames, exact) = | ||
| 297 | - count_rawvideo_diffs(&data, NAME, None).expect("the two sides must be byte-comparable"); | ||
| 298 | - eprintln!( | ||
| 299 | - "{NAME}: pinned {FILE} as wrongY={wy} wrongU={wu} wrongV={wv} over {frames} frames, \ | ||
| 300 | - {exact} exact; this test's own count {truth:?} with {truth_exact} exact frames; \ | ||
| 301 | - plane capacities {capacity:?}" | ||
| 302 | - ); | ||
| 303 | - assert_eq!(frames, decoded.len(), "{NAME}: frame count"); | ||
| 304 | - assert_eq!( | ||
| 305 | - [wy, wu, wv], | ||
| 306 | - truth, | ||
| 307 | - "{NAME}: the helper's per-plane split must equal an independent per-frame count" | ||
| 308 | - ); | ||
| 309 | - assert_eq!(exact, truth_exact, "{NAME}: frames_exact"); | ||
| 310 | - for p in 0..3 { | ||
| 311 | - assert!( | ||
| 312 | - truth[p] <= capacity[p], | ||
| 313 | - "{NAME}: plane {p} counts {} wrong bytes but holds only {}", | ||
| 314 | - truth[p], | ||
| 315 | - capacity[p] | ||
| 316 | - ); | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | - // ---- arm 2: a byte inside a LATER frame's U plane. -------------- | ||
| 320 | - // Frame 5's U plane's first byte. The old first-picture attribution | ||
| 321 | - // has no frame-5 U at all: that byte is past every frame-0 threshold, | ||
| 322 | - // so it landed in V. | ||
| 323 | - let u5 = spans[5][1]; | ||
| 324 | - let (fy, fu, fv, fframes, fexact) = count_rawvideo_diffs(&data, NAME, Some(u5)) | ||
| 325 | - .expect("the two sides must be byte-comparable"); | ||
| 326 | - let flipped = [fy, fu, fv]; | ||
| 327 | - assert_eq!(fframes, frames, "{NAME}: frame count under the flip"); | ||
| 328 | - assert_eq!( | ||
| 329 | - flipped.iter().sum::<usize>(), | ||
| 330 | - truth.iter().sum::<usize>() + 1, | ||
| 331 | - "{NAME}: flipping one byte inside frame 5's U plane must add exactly one wrong \ | ||
| 332 | - byte -- got {flipped:?} against this test's own count {truth:?}" | ||
| 333 | - ); | ||
| 334 | - assert_eq!( | ||
| 335 | - flipped[1], | ||
| 336 | - truth[1] + 1, | ||
| 337 | - "{NAME}: byte {u5} is inside frame 5's U plane" | ||
| 338 | - ); | ||
| 339 | - assert_eq!(flipped[0], truth[0], "{NAME}: byte {u5} is not in luma"); | ||
| 340 | - assert_eq!( | ||
| 341 | - flipped[2], truth[2], | ||
| 342 | - "{NAME}: byte {u5} must NOT be attributed to V -- the first-picture attribution \ | ||
| 343 | - puts every byte past frame 0's luma in V" | ||
| 344 | - ); | ||
| 345 | - let want_exact = if truth_exact < frames { | ||
| 346 | - truth_exact | ||
| 347 | - } else { | ||
| 348 | - frames - 1 | ||
| 349 | - }; | ||
| 350 | - assert_eq!( | ||
| 351 | - fexact, want_exact, | ||
| 352 | - "{NAME}: one flipped byte inside frame 5 leaves frames_exact at {want_exact}" | ||
| 353 | - ); | ||
| 354 | - } | ||
| 355 | - | ||
| 356 | - /// lane-av1cmpaudit2: the permanent CONTROL for the class | ||
| 357 | - /// `comparator-that-never-reads-the-oracle`. | ||
| 358 | - /// | ||
| 359 | - /// The retracted predecessor lane's per-cell counter reported "0 wrong" | ||
| 360 | - /// on 18/18 cells -- including cells that differ from `aomdec | ||
| 361 | - /// --rawvideo` in 17658 samples -- because it packed OUR decoded samples | ||
| 362 | - /// into a buffer and compared that buffer against the same samples. | ||
| 363 | - /// `aomdec`'s output was written, length-checked, and never read. | ||
| 364 | - /// Nothing about that mistake is visible from the outside: the helper's | ||
| 365 | - /// signature, its panic text and its return type are all exactly what a | ||
| 366 | - /// working comparator has, and no amount of reading the source of a | ||
| 367 | - /// healthy-looking helper proves the next one is healthy. | ||
| 368 | - /// | ||
| 369 | - /// So the class is pinned here from the other direction. | ||
| 370 | - /// `EC_AV1_AOMDEC` is already the crate's oracle override, so this test | ||
| 371 | - /// points every oracle helper at a shim that runs the REAL `aomdec` and | ||
| 372 | - /// then corrupts exactly ONE byte of whatever it wrote -- the | ||
| 373 | - /// `--rawvideo` output and the `EC_AV1_FINAL_DUMP` frame 0 -- leaving | ||
| 374 | - /// every other sample a genuine decode. On a pin that IS byte-exact | ||
| 375 | - /// against the real oracle: | ||
| 376 | - /// | ||
| 377 | - /// 1. **arm 1, real oracle: every helper is GREEN.** Without this arm, | ||
| 378 | - /// arm 2's red could just be a stream that was never exact. | ||
| 379 | - /// 2. **arm 2, one-byte-wrong oracle: every helper is RED.** A helper | ||
| 380 | - /// that stays green here is the retracted defect itself: it cannot | ||
| 381 | - /// fail, so its green is worth nothing. | ||
| 382 | - /// | ||
| 383 | - /// One test, five helpers, and it goes red for the exact mistake that | ||
| 384 | - /// was retracted. Measured over this file: the other 62 tests that | ||
| 385 | - /// reach an oracle helper all take `lock_gate_counters()` before their | ||
| 386 | - /// first oracle call, which is what makes the process-global | ||
| 387 | - /// `EC_AV1_AOMDEC` safe to flip here. | ||
| 388 | - #[test] | ||
| 389 | - fn every_oracle_comparator_reds_on_a_one_byte_wrong_oracle() { | ||
| 390 | - const NAME: &str = "every_oracle_comparator_reds_on_a_one_byte_wrong_oracle"; | ||
| 391 | - let _gate_lock = lock_gate_counters(); | ||
| 392 | - if !aomdec_available(NAME) { | ||
| 393 | - return; | ||
| 394 | - } | ||
| 395 | - let pin = crate_pin("420_odd65x65_key.obu"); | ||
| 396 | - let stream = std::fs::read(&pin).unwrap_or_else(|e| { | ||
| 397 | - panic!( | ||
| 398 | - "{NAME}: the control's pin {} is missing ({e}) -- restore the committed copy", | ||
| 399 | - pin.display() | ||
| 400 | - ) | ||
| 401 | - }); | ||
| 402 | - assert_eq!( | ||
| 403 | - stream_bit_depth(&stream, NAME), | ||
| 404 | - 8, | ||
| 405 | - "{NAME}: the control's pin must be the 8-bit cell the shim corrupts" | ||
| 406 | - ); | ||
| 407 | - let plane_samples = { | ||
| 408 | - let frames = decode_stream(&stream).expect("the control's pin must decode"); | ||
| 409 | - let f = &frames[0]; | ||
| 410 | - [f.y.len(), f.u.len(), f.v.len()] | ||
| 411 | - }; | ||
| 412 | - | ||
| 413 | - // ---- arm 1: the real oracle, every comparator green ------------ | ||
| 414 | - { | ||
| 415 | - let obu = std::env::temp_dir().join(format!("{NAME}-arm1.obu")); | ||
| 416 | - std::fs::write(&obu, &stream).expect("writing the pin for arm 1"); | ||
| 417 | - assert_rawvideo_matches(&obu, &stream, "oracle-control-arm1-rawvideo", 1, 8); | ||
| 418 | - let _ = std::fs::remove_file(&obu); | ||
| 419 | - let (frames, hidden) = | ||
| 420 | - decode_all_frames_vs_oracle(&stream, "oracle-control-arm1-alldumps"); | ||
| 421 | - assert_eq!( | ||
| 422 | - (frames, hidden), | ||
| 423 | - (1, 0), | ||
| 424 | - "{NAME}: arm 1 expects one decode-order frame and no hidden frames" | ||
| 425 | - ); | ||
| 426 | - let (wy, wu, wv, n, exact) = | ||
| 427 | - count_rawvideo_diffs(&stream, "oracle-control-arm1-count", None) | ||
| 428 | - .expect("arm 1: the two sides must be byte-comparable"); | ||
| 429 | - assert_eq!( | ||
| 430 | - (wy, wu, wv), | ||
| 431 | - (0, 0, 0), | ||
| 432 | - "{NAME}: arm 1 runs against the REAL oracle, so every plane must be zero" | ||
| 433 | - ); | ||
| 434 | - assert_eq!( | ||
| 435 | - (n, exact), | ||
| 436 | - (1, 1), | ||
| 437 | - "{NAME}: arm 1 expects one shown frame that is byte-identical" | ||
| 438 | - ); | ||
| 439 | - let (differing, first) = key_frame_diffs(&stream, "oracle-control-arm1-kf"); | ||
| 440 | - assert_eq!( | ||
| 441 | - (differing, first), | ||
| 442 | - (0, None), | ||
| 443 | - "{NAME}: arm 1's key frame must be byte-identical to the oracle's" | ||
| 444 | - ); | ||
| 445 | - let [y, u, v] = | ||
| 446 | - oracle_plane_diffs(&stream, "oracle-control-arm1-planes", plane_samples); | ||
| 447 | - assert_eq!( | ||
| 448 | - [y, u, v], | ||
| 449 | - [0, 0, 0], | ||
| 450 | - "{NAME}: arm 1 must be zero on every plane against the real oracle" | ||
| 451 | - ); | ||
| 452 | - } | ||
| 453 | - | ||
| 454 | - // ---- the one-byte-wrong oracle --------------------------------- | ||
| 455 | - let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 456 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 457 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 458 | - let shim = dir.join("one-byte-wrong-aomdec.sh"); | ||
| 459 | - // The real oracle's path rides in a sibling file rather than inside | ||
| 460 | - // the script, so a path with a quote or a space cannot mangle it and | ||
| 461 | - // the script body needs no `format!` escaping at all. | ||
| 462 | - std::fs::write( | ||
| 463 | - dir.join("real-aomdec"), | ||
| 464 | - aomdec_path().as_os_str().as_encoded_bytes(), | ||
| 465 | - ) | ||
| 466 | - .expect("recording the real oracle's path for the shim"); | ||
| 467 | - // Byte 7 of both the `--rawvideo` output and the `EC_AV1_FINAL_DUMP` | ||
| 468 | - // frame 0 is inside the Y plane, and its value is rotated by 128 so | ||
| 469 | - // the write always changes it. Nothing else is touched: the stream, | ||
| 470 | - // the geometry, the frame count and every other sample are a genuine | ||
| 471 | - // `aomdec` decode. | ||
| 472 | - let script = r#"#!/bin/sh | ||
| 473 | -REAL=$(cat "$(dirname "$0")/real-aomdec") | ||
| 474 | -rawvideo=0 | ||
| 475 | -out="" | ||
| 476 | -prev="" | ||
| 477 | -for a in "$@"; do | ||
| 478 | - if [ "$a" = "--rawvideo" ]; then rawvideo=1; fi | ||
| 479 | - if [ "$prev" = "-o" ]; then out="$a"; fi | ||
| 480 | - prev="$a" | ||
| 481 | -done | ||
| 482 | -"$REAL" "$@" || exit $? | ||
| 483 | -flip() { | ||
| 484 | - [ -s "$1" ] || return 0 | ||
| 485 | - b=$(od -An -tu1 -j 7 -N 1 "$1" 2>/dev/null | tr -d ' \n') | ||
| 486 | - [ -n "$b" ] || return 0 | ||
| 487 | - esc=$(printf '\\%03o' $(( (b + 128) % 256 ))) | ||
| 488 | - printf "$esc" | dd of="$1" bs=1 seek=7 count=1 conv=notrunc 2>/dev/null | ||
| 489 | - return 0 | ||
| 490 | -} | ||
| 491 | -[ "$rawvideo" = 1 ] && flip "$out" | ||
| 492 | -[ -n "$EC_AV1_FINAL_DUMP" ] && flip "$EC_AV1_FINAL_DUMP.f0" | ||
| 493 | -exit 0 | ||
| 494 | -"#; | ||
| 495 | - std::fs::write(&shim, script).expect("writing the oracle shim"); | ||
| 496 | - #[cfg(unix)] | ||
| 497 | - { | ||
| 498 | - use std::os::unix::fs::PermissionsExt; | ||
| 499 | - std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)) | ||
| 500 | - .expect("the oracle shim must be executable"); | ||
| 501 | - } | ||
| 502 | - | ||
| 503 | - // ---- arm 2: same pin, oracle off by ONE byte ------------------- | ||
| 504 | - // The override is THREAD-LOCAL, so the tampered oracle is confined | ||
| 505 | - // to this thread and no sibling test can see it; it is still cleared | ||
| 506 | - // before any result is asserted, so a red arm cannot leave this | ||
| 507 | - // test's own later work reading a wrong oracle. | ||
| 508 | - let reds: [bool; 5]; | ||
| 509 | - { | ||
| 510 | - set_oracle_path(Some(shim.clone())); | ||
| 511 | - let panicked = | ||
| 512 | - |f: &dyn Fn()| std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).is_err(); | ||
| 513 | - let rawvideo_red = panicked(&|| { | ||
| 514 | - let obu = std::env::temp_dir().join(format!("{NAME}-arm2.obu")); | ||
| 515 | - std::fs::write(&obu, &stream).expect("writing the pin for arm 2"); | ||
| 516 | - assert_rawvideo_matches(&obu, &stream, "oracle-control-arm2-rawvideo", 1, 8); | ||
| 517 | - }); | ||
| 518 | - let _ = std::fs::remove_file(std::env::temp_dir().join(format!("{NAME}-arm2.obu"))); | ||
| 519 | - let dumps_red = panicked(&|| { | ||
| 520 | - decode_all_frames_vs_oracle(&stream, "oracle-control-arm2-alldumps"); | ||
| 521 | - }); | ||
| 522 | - let count_red = { | ||
| 523 | - let counted = count_rawvideo_diffs(&stream, "oracle-control-arm2-count", None) | ||
| 524 | - .unwrap_or_else(|| { | ||
| 525 | - panic!( | ||
| 526 | - "{NAME}: a single flipped oracle byte must NOT change the buffer \ | ||
| 527 | - LENGTH -- returning None means the shim corrupted more than the \ | ||
| 528 | - comparison" | ||
| 529 | - ) | ||
| 530 | - }); | ||
| 531 | - counted.0 + counted.1 + counted.2 > 0 && counted.4 < counted.3 | ||
| 532 | - }; | ||
| 533 | - let kf_red = { | ||
| 534 | - let (differing, first) = key_frame_diffs(&stream, "oracle-control-arm2-kf"); | ||
| 535 | - differing > 0 && first.is_some() | ||
| 536 | - }; | ||
| 537 | - let planes_red = { | ||
| 538 | - let [y, u, v] = | ||
| 539 | - oracle_plane_diffs(&stream, "oracle-control-arm2-planes", plane_samples); | ||
| 540 | - y + u + v > 0 | ||
| 541 | - }; | ||
| 542 | - set_oracle_path(None); | ||
| 543 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 544 | - reds = [rawvideo_red, dumps_red, count_red, kf_red, planes_red]; | ||
| 545 | - } | ||
| 546 | - // One assert, naming EVERY comparator that stayed green: a partial | ||
| 547 | - // run would report the first and hide whether the other four are | ||
| 548 | - // covered. | ||
| 549 | - let blind: Vec<&str> = [ | ||
| 550 | - ("assert_rawvideo_matches", reds[0]), | ||
| 551 | - ("decode_all_frames_vs_oracle", reds[1]), | ||
| 552 | - ("count_rawvideo_diffs", reds[2]), | ||
| 553 | - ("key_frame_diffs", reds[3]), | ||
| 554 | - ("oracle_plane_diffs", reds[4]), | ||
| 555 | - ] | ||
| 556 | - .into_iter() | ||
| 557 | - .filter(|(_, red)| !red) | ||
| 558 | - .map(|(what, _)| what) | ||
| 559 | - .collect(); | ||
| 560 | - assert!( | ||
| 561 | - blind.is_empty(), | ||
| 562 | - "{NAME}: {} of 5 oracle comparators stayed GREEN against an oracle that is wrong \ | ||
| 563 | - by exactly one byte -- {blind:?} -- they cannot fail, so their green proves \ | ||
| 564 | - nothing (class `comparator-that-never-reads-the-oracle`)", | ||
| 565 | - blind.len() | ||
| 566 | - ); | ||
| 567 | - eprintln!("{NAME}: all five oracle comparators red on a one-byte-wrong oracle"); | ||
| 568 | - } | ||
| 569 | - | ||
| 570 | - /// lane-film10fix: the permanent CONTROL for the ffmpeg half of the class | ||
| 571 | - /// `comparator-that-never-reads-the-oracle`. | ||
| 572 | - /// | ||
| 573 | - /// Its sibling above covers the five `aomdec` comparators. The `ffmpeg` | ||
| 574 | - /// half had no such control, and it is the half the two 10-bit FILM gates | ||
| 575 | - /// rest on: `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` | ||
| 576 | - /// and `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` | ||
| 577 | - /// both declare "pixel-exact" purely as | ||
| 578 | - /// `assert_eq!(ours.<plane>, ffmpeg_decode_sequence_10bit(...).<plane>)` | ||
| 579 | - /// over 15 and 33 shown frames. If `ffmpeg_decode_sequence_10bit` ever | ||
| 580 | - /// stopped reading ffmpeg's stdout -- packed our own samples into the | ||
| 581 | - /// buffer it returns, say -- both gates would report exact on a decoder | ||
| 582 | - /// that could be arbitrarily wrong, and nothing in the crate would go | ||
| 583 | - /// red. Reading the helper's source proves it is live TODAY; only a | ||
| 584 | - /// deliberately wrong reference proves it can FAIL. | ||
| 585 | - /// | ||
| 586 | - /// So this is the same two-arm shape, pointed at ffmpeg. The shim runs the | ||
| 587 | - /// REAL ffmpeg and then rotates ONE byte of its rawvideo stdout per | ||
| 588 | - /// offset in a sibling file, leaving the stream, the geometry, the frame | ||
| 589 | - /// count and every other sample a genuine decode. On a pin that IS | ||
| 590 | - /// byte-exact against real ffmpeg: | ||
| 591 | - /// | ||
| 592 | - /// 1. **arm 1, real ffmpeg: every helper is GREEN.** Without this arm, | ||
| 593 | - /// arm 2's red could just be a stream that was never exact. | ||
| 594 | - /// 2. **arm 2, one-sample-wrong ffmpeg, PER PLANE: every helper is RED | ||
| 595 | - /// and the red names the plane that was tampered with.** Three arms, | ||
| 596 | - /// one per plane, because a helper that only ever compared luma would | ||
| 597 | - /// pass the Y arm and fail U and V -- and a 10-bit film gate that | ||
| 598 | - /// reported "exact" while ignoring chroma entirely would be exactly | ||
| 599 | - /// the class this controls. | ||
| 600 | - /// | ||
| 601 | - /// The three helpers are the whole reference surface in this module: | ||
| 602 | - /// `ffmpeg_decode_sequence` (4:2:0 8-bit), `ffmpeg_decode_gray_sequence` | ||
| 603 | - /// (monochrome, one plane) and `ffmpeg_decode_sequence_10bit` (the | ||
| 604 | - /// `yuv420p10le` family both film gates use). Each is driven on a pin it | ||
| 605 | - /// is known to be exact against: the 8-bit `420_odd65x65_key.obu` for the | ||
| 606 | - /// first, the same stream for the third's shape arithmetic, and the | ||
| 607 | - /// monochrome recipe the mono gate already builds for the second. The | ||
| 608 | - /// override is thread-local, so a red arm cannot leave a tampered ffmpeg | ||
| 609 | - /// behind for a sibling test on another thread. | ||
| 610 | - #[test] | ||
| 611 | - fn every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg() { | ||
| 612 | - const NAME: &str = "every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg"; | ||
| 613 | - if !have_ffmpeg() { | ||
| 614 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 615 | - return; | ||
| 616 | - } | ||
| 617 | - // Same mutex the oracle control takes: this test's shim is | ||
| 618 | - // thread-local, but the SCREAM it produces must not interleave with a | ||
| 619 | - // sibling's decode in the captured log. | ||
| 620 | - let _gate_lock = lock_gate_counters(); | ||
| 621 | - | ||
| 622 | - // The 4:2:0 8-bit arm. It BUILDS its stream with the same | ||
| 623 | - // `libaom-av1` lavfi recipe the mono gate below uses rather than | ||
| 624 | - // pinning one: `ffmpeg_decode_sequence` derives its frame size as | ||
| 625 | - // `w*h + 2*(w*h/4)`, which is only right for EVEN dimensions -- on a | ||
| 626 | - // 65x65 stream 4:2:0 chroma is ceil(65/2)^2 = 1089, not 4225/4 = | ||
| 627 | - // 1056, and the helper's length assert fires (loudly, by design -- | ||
| 628 | - // see `frame_count_diagnosis`). 320x240 keeps the offsets below | ||
| 629 | - // exact: luma 76800 samples, chroma 160x120 = 19200 each. | ||
| 630 | - let (w, h) = (320usize, 240usize); | ||
| 631 | - let (ys, cs) = (w * h, (w / 2) * (h / 2)); | ||
| 632 | - assert_eq!( | ||
| 633 | - (ys, cs), | ||
| 634 | - (76800, 19200), | ||
| 635 | - "{NAME}: the byte offsets in this test are computed from this geometry" | ||
| 636 | - ); | ||
| 637 | - let build_8bit = { | ||
| 638 | - let out = crate::tool_cache::cached_output_io(Command::new(ffmpeg_path()) | ||
| 639 | - .args([ | ||
| 640 | - "-v", | ||
| 641 | - "error", | ||
| 642 | - "-f", | ||
| 643 | - "lavfi", | ||
| 644 | - "-i", | ||
| 645 | - "testsrc2=size=320x240:rate=30:duration=1", | ||
| 646 | - "-pix_fmt", | ||
| 647 | - "yuv420p", | ||
| 648 | - "-c:v", | ||
| 649 | - "libaom-av1", | ||
| 650 | - "-cpu-used", | ||
| 651 | - "8", | ||
| 652 | - "-b:v", | ||
| 653 | - "300k", | ||
| 654 | - "-f", | ||
| 655 | - "obu", | ||
| 656 | - "-", | ||
| 657 | - ]) | ||
| 658 | - .stdin(Stdio::null()) | ||
| 659 | - .stdout(Stdio::piped()) | ||
| 660 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 661 | - .expect("ffmpeg failed to build the 4:2:0 8-bit arm"); | ||
| 662 | - assert!( | ||
| 663 | - out.status.success(), | ||
| 664 | - "{NAME}: ffmpeg could not build the 8-bit arm: {}", | ||
| 665 | - String::from_utf8_lossy(&out.stderr) | ||
| 666 | - ); | ||
| 667 | - out.stdout | ||
| 668 | - }; | ||
| 669 | - assert_eq!( | ||
| 670 | - stream_bit_depth(&build_8bit, NAME), | ||
| 671 | - 8, | ||
| 672 | - "{NAME}: this arm is the 8-bit cell the byte offsets below are computed for" | ||
| 673 | - ); | ||
| 674 | - let our_8bit = | ||
| 675 | - decode_stream(&build_8bit).expect("the 8-bit arm must decode -- arm 1 needs it exact"); | ||
| 676 | - assert!( | ||
| 677 | - !our_8bit.is_empty(), | ||
| 678 | - "{NAME}: the 8-bit arm decoded nothing" | ||
| 679 | - ); | ||
| 680 | - let frames_8bit = our_8bit.len(); | ||
| 681 | - | ||
| 682 | - // The monochrome recipe, byte-identical to the one | ||
| 683 | - // `a_real_libaom_monochrome_key_frame_decodes_pixel_exact` builds, so | ||
| 684 | - // the gray helper is driven on a stream that gate already proves | ||
| 685 | - // exact. A MONOCHROME stream is also this test's 4:2:0 4:2:0-free | ||
| 686 | - // arm: `ffmpeg_decode_gray_sequence` returns a flat luma buffer, so | ||
| 687 | - // the one flipped offset must be attributed to Y and to nothing else. | ||
| 688 | - let gray_stream = { | ||
| 689 | - let out = crate::tool_cache::cached_output_io(Command::new(ffmpeg_path()) | ||
| 690 | - .args([ | ||
| 691 | - "-v", | ||
| 692 | - "error", | ||
| 693 | - "-f", | ||
| 694 | - "lavfi", | ||
| 695 | - "-i", | ||
| 696 | - "testsrc2=size=64x64:rate=30:duration=1", | ||
| 697 | - "-pix_fmt", | ||
| 698 | - "gray", | ||
| 699 | - "-c:v", | ||
| 700 | - "libaom-av1", | ||
| 701 | - "-cpu-used", | ||
| 702 | - "8", | ||
| 703 | - "-b:v", | ||
| 704 | - "100k", | ||
| 705 | - "-f", | ||
| 706 | - "obu", | ||
| 707 | - "-", | ||
| 708 | - ]) | ||
| 709 | - .stdin(Stdio::null()) | ||
| 710 | - .stdout(Stdio::piped()) | ||
| 711 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 712 | - .expect("ffmpeg failed to build the monochrome arm"); | ||
| 713 | - assert!( | ||
| 714 | - out.status.success(), | ||
| 715 | - "{NAME}: ffmpeg could not build the monochrome arm: {}", | ||
| 716 | - String::from_utf8_lossy(&out.stderr) | ||
| 717 | - ); | ||
| 718 | - out.stdout | ||
| 719 | - }; | ||
| 720 | - let our_gray = decode_stream(&gray_stream).expect("the monochrome arm must decode"); | ||
| 721 | - assert!( | ||
| 722 | - !our_gray.is_empty(), | ||
| 723 | - "{NAME}: the monochrome arm decoded nothing" | ||
| 724 | - ); | ||
| 725 | - let frames_gray = our_gray.len(); | ||
| 726 | - | ||
| 727 | - // ---- the one-sample-wrong ffmpeg shim --------------------------- | ||
| 728 | - let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 729 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 730 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 731 | - // The real ffmpeg's path rides in a sibling file rather than inside | ||
| 732 | - // the script, so a path with a space or a quote cannot mangle it and | ||
| 733 | - // the script body needs no `format!` escaping. | ||
| 734 | - let real = if let Some(p) = std::env::var_os("EC_AV1_FFMPEG") { | ||
| 735 | - std::path::PathBuf::from(p) | ||
| 736 | - } else { | ||
| 737 | - let found = Command::new("ffmpeg") | ||
| 738 | - .arg("-version") | ||
| 739 | - .stdout(Stdio::null()) | ||
| 740 | - .stderr(Stdio::null()) | ||
| 741 | - .status() | ||
| 742 | - .is_ok_and(|s| s.success()); | ||
| 743 | - assert!(found, "{NAME}: no working ffmpeg on PATH to wrap"); | ||
| 744 | - // Resolve the bare name through PATH so the shim does not depend | ||
| 745 | - // on inheriting whatever PATH the test runner had. | ||
| 746 | - let path = std::env::var_os("PATH").unwrap_or_default(); | ||
| 747 | - std::env::split_paths(&path) | ||
| 748 | - .map(|d| d.join("ffmpeg")) | ||
| 749 | - .find(|p| p.is_file()) | ||
| 750 | - .expect("{NAME}: ffmpeg is on PATH but not resolvable to a file") | ||
| 751 | - }; | ||
| 752 | - std::fs::write(dir.join("real-ffmpeg"), real.as_os_str().as_encoded_bytes()) | ||
| 753 | - .expect("recording the real ffmpeg's path for the shim"); | ||
| 754 | - // Each line of `offsets` is one byte of the rawvideo stdout to rotate | ||
| 755 | - // by 128, so the write always changes it. Everything else -- the | ||
| 756 | - // stream, the geometry, the frame count, every other sample -- is a | ||
| 757 | - // genuine ffmpeg decode. stdin is inherited so the shim is a drop-in | ||
| 758 | - // for the helpers' `run_with_stdin` call. | ||
| 759 | - let script = r#"#!/bin/sh | ||
| 760 | -REAL=$(cat "$(dirname "$0")/real-ffmpeg") | ||
| 761 | -OUT=$(mktemp) | ||
| 762 | -"$REAL" "$@" > "$OUT" || exit $? | ||
| 763 | -while read -r o; do | ||
| 764 | - [ -n "$o" ] || continue | ||
| 765 | - b=$(od -An -tu1 -j "$o" -N 1 "$OUT" 2>/dev/null | tr -d ' \n') | ||
| 766 | - [ -n "$b" ] || continue | ||
| 767 | - esc=$(printf '\\%03o' $(( (b + 128) % 256 ))) | ||
| 768 | - printf "$esc" | dd of="$OUT" bs=1 seek="$o" count=1 conv=notrunc 2>/dev/null | ||
| 769 | -done < "$(dirname "$0")/offsets" | ||
| 770 | -cat "$OUT" | ||
| 771 | -rm -f "$OUT" | ||
| 772 | -exit 0 | ||
| 773 | -"#; | ||
| 774 | - let shim = dir.join("one-sample-wrong-ffmpeg.sh"); | ||
| 775 | - std::fs::write(&shim, script).expect("writing the ffmpeg shim"); | ||
| 776 | - #[cfg(unix)] | ||
| 777 | - { | ||
| 778 | - use std::os::unix::fs::PermissionsExt; | ||
| 779 | - std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)) | ||
| 780 | - .expect("the ffmpeg shim must be executable"); | ||
| 781 | - } | ||
| 782 | - let set_offsets = |bytes: &[usize]| { | ||
| 783 | - let body: String = bytes | ||
| 784 | - .iter() | ||
| 785 | - .map(|b| format!("{b}\n")) | ||
| 786 | - .collect::<Vec<_>>() | ||
| 787 | - .concat(); | ||
| 788 | - std::fs::write(dir.join("offsets"), body).expect("writing the offsets file"); | ||
| 789 | - }; | ||
| 790 | - // A comparator that cannot report a difference is worse than none, so | ||
| 791 | - // each arm is scored as a COUNT of differing samples, not as a panic. | ||
| 792 | - let count8 = |theirs: &[Pic]| -> [usize; 3] { | ||
| 793 | - let mut wrong = [0usize; 3]; | ||
| 794 | - for (plane, (x, y)) in [ | ||
| 795 | - (0usize, (&our_8bit[0].y, &theirs[0].y)), | ||
| 796 | - (1, (&our_8bit[0].u, &theirs[0].u)), | ||
| 797 | - (2, (&our_8bit[0].v, &theirs[0].v)), | ||
| 798 | - ] { | ||
| 799 | - wrong[plane] = x.iter().zip(y).filter(|(a, b)| a != b).count(); | ||
| 800 | - } | ||
| 801 | - wrong | ||
| 802 | - }; | ||
| 803 | - | ||
| 804 | - // The 10-bit FILM pin, and the comparator both charter-named film | ||
| 805 | - // gates rest on. Driven on the real stream rather than a synthetic | ||
| 806 | - // one: `ffmpeg_decode_sequence_10bit` is the only reference helper | ||
| 807 | - // with a per-plane split, so it is the one that could silently lose a | ||
| 808 | - // plane. 1920x792 at 10 bits: luma 1920*792*2 bytes per frame, chroma | ||
| 809 | - // 960*396*2. | ||
| 810 | - let film = std::fs::read(crate_pin("reelc_sb128_inter_witness.obu")).unwrap_or_else(|e| { | ||
| 811 | - panic!( | ||
| 812 | - "{NAME}: the 10-bit film pin reelc_sb128_inter_witness.obu is missing ({e}) -- \ | ||
| 813 | - restore the committed copy" | ||
| 814 | - ) | ||
| 815 | - }); | ||
| 816 | - assert_eq!( | ||
| 817 | - stream_bit_depth(&film, NAME), | ||
| 818 | - 10, | ||
| 819 | - "{NAME}: this arm is the 10-bit cell the byte offsets below are computed for" | ||
| 820 | - ); | ||
| 821 | - let our_10bit = | ||
| 822 | - decode_stream(&film).expect("the 10-bit film pin must decode -- arm 1 needs it exact"); | ||
| 823 | - let (fw, fh) = (1920usize, 792usize); | ||
| 824 | - let film_frames = our_10bit.len(); | ||
| 825 | - let (fys, fcs) = (fw * fh * 2, (fw / 2) * (fh / 2) * 2); | ||
| 826 | - let count10 = |theirs: &[Pic]| -> [usize; 3] { | ||
| 827 | - let mut wrong = [0usize; 3]; | ||
| 828 | - for (a, b) in our_10bit.iter().zip(theirs) { | ||
| 829 | - for (plane, (x, y)) in | ||
| 830 | - [(0usize, (&a.y, &b.y)), (1, (&a.u, &b.u)), (2, (&a.v, &b.v))] | ||
| 831 | - { | ||
| 832 | - wrong[plane] += x.iter().zip(y).filter(|(p, q)| p != q).count(); | ||
| 833 | - } | ||
| 834 | - } | ||
| 835 | - wrong | ||
| 836 | - }; | ||
| 837 | - let count_gray = |theirs: &[u8]| -> usize { | ||
| 838 | - our_gray[0] | ||
| 839 | - .y | ||
| 840 | - .iter() | ||
| 841 | - .zip(theirs) | ||
| 842 | - .filter(|(a, b)| **a != u16::from(**b)) | ||
| 843 | - .count() | ||
| 844 | - }; | ||
| 845 | - | ||
| 846 | - // ---- arm 1: the real ffmpeg, every comparator GREEN ------------ | ||
| 847 | - { | ||
| 848 | - set_offsets(&[]); | ||
| 849 | - set_ffmpeg_path(None); | ||
| 850 | - let theirs = ffmpeg_decode_sequence(&build_8bit, w, h, frames_8bit); | ||
| 851 | - assert_eq!( | ||
| 852 | - count8(&theirs), | ||
| 853 | - [0, 0, 0], | ||
| 854 | - "{NAME}: arm 1 runs against the REAL ffmpeg, so every plane must be zero -- if \ | ||
| 855 | - this is red the stream is not the byte-exact pin this control needs" | ||
| 856 | - ); | ||
| 857 | - let their_gray = ffmpeg_decode_gray_sequence(&gray_stream, 64, 64, frames_gray); | ||
| 858 | - assert_eq!( | ||
| 859 | - count_gray(&their_gray), | ||
| 860 | - 0, | ||
| 861 | - "{NAME}: arm 1's monochrome plane must be zero against the real ffmpeg" | ||
| 862 | - ); | ||
| 863 | - // arm 1's 10-bit half: the film pin is byte-exact against real | ||
| 864 | - // ffmpeg on every plane of every shown frame -- that is exactly | ||
| 865 | - // what `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` | ||
| 866 | - // asserts -- so this is the cell the two charter-named film gates | ||
| 867 | - // claim. | ||
| 868 | - let their_10bit = ffmpeg_decode_sequence_10bit(&film, fw, fh, film_frames); | ||
| 869 | - assert_eq!( | ||
| 870 | - count10(&their_10bit), | ||
| 871 | - [0, 0, 0], | ||
| 872 | - "{NAME}: arm 1's 10-bit film pin must be zero on every plane against the real \ | ||
| 873 | - ffmpeg -- if this is red the control's pin is not the byte-exact stream it needs" | ||
| 874 | - ); | ||
| 875 | - } | ||
| 876 | - | ||
| 877 | - // ---- arm 2: one sample wrong, PER PLANE ------------------------- | ||
| 878 | - // The shim is thread-local, so the tampered reference is confined to | ||
| 879 | - // this thread; it is cleared before anything is asserted, so a red arm | ||
| 880 | - // cannot leave this test's own later work reading a wrong ffmpeg. | ||
| 881 | - let mut blind: Vec<String> = Vec::new(); | ||
| 882 | - { | ||
| 883 | - set_ffmpeg_path(Some(shim.clone())); | ||
| 884 | - for (plane, (_name, base)) in [("Y", 0usize), ("U", ys), ("V", ys + cs)] | ||
| 885 | - .into_iter() | ||
| 886 | - .enumerate() | ||
| 887 | - { | ||
| 888 | - // Byte 1000 of the named plane: inside the 4:2:0 8-bit pin's | ||
| 889 | - // luma (4225), inside its chroma (1024), or past both. | ||
| 890 | - set_offsets(&[base + 1000]); | ||
| 891 | - let theirs = ffmpeg_decode_sequence(&build_8bit, w, h, frames_8bit); | ||
| 892 | - let got = count8(&theirs); | ||
| 893 | - let want = [0usize, 0, 0]; | ||
| 894 | - let mut expected = want; | ||
| 895 | - expected[plane] = 1; | ||
| 896 | - if got != expected { | ||
| 897 | - blind.push(format!( | ||
| 898 | - "ffmpeg_decode_sequence {plane} arm: counted {got:?}, expected \ | ||
| 899 | - {expected:?} (exactly the one tampered sample)" | ||
| 900 | - )); | ||
| 901 | - } | ||
| 902 | - } | ||
| 903 | - // The 10-bit helper, per plane, on the 10-bit FILM pin. This is the | ||
| 904 | - // arm that matters for the charter: both | ||
| 905 | - // `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` | ||
| 906 | - // and | ||
| 907 | - // `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` | ||
| 908 | - // declare "pixel-exact on every plane" using nothing but this | ||
| 909 | - // helper's output. A helper that dropped U or V would leave both | ||
| 910 | - // gates green while chroma went unchecked for 15 and 33 frames. | ||
| 911 | - for (plane, (_name, base)) in [("Y", 0usize), ("U", fys), ("V", fys + fcs)] | ||
| 912 | - .into_iter() | ||
| 913 | - .enumerate() | ||
| 914 | - { | ||
| 915 | - // Sample 1000 of the named plane, two bytes per sample. | ||
| 916 | - set_offsets(&[base + 2000]); | ||
| 917 | - let theirs = ffmpeg_decode_sequence_10bit(&film, fw, fh, film_frames); | ||
| 918 | - let got = count10(&theirs); | ||
| 919 | - let mut expected = [0usize, 0, 0]; | ||
| 920 | - expected[plane] = 1; | ||
| 921 | - if got != expected { | ||
| 922 | - blind.push(format!( | ||
| 923 | - "ffmpeg_decode_sequence_10bit {plane} arm: counted {got:?}, expected \ | ||
| 924 | - {expected:?} (exactly the one tampered sample)" | ||
| 925 | - )); | ||
| 926 | - } | ||
| 927 | - } | ||
| 928 | - // The monochrome helper: one plane, so the single flipped offset | ||
| 929 | - // must show up as luma and nothing else can absorb it. | ||
| 930 | - set_offsets(&[1000]); | ||
| 931 | - let their_gray = ffmpeg_decode_gray_sequence(&gray_stream, 64, 64, frames_gray); | ||
| 932 | - if count_gray(&their_gray) != 1 { | ||
| 933 | - blind.push(format!( | ||
| 934 | - "ffmpeg_decode_gray_sequence arm: counted {} differing luma samples, expected \ | ||
| 935 | - exactly 1", | ||
| 936 | - count_gray(&their_gray) | ||
| 937 | - )); | ||
| 938 | - } | ||
| 939 | - set_ffmpeg_path(None); | ||
| 940 | - } | ||
| 941 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 942 | - // One assert, naming EVERY helper that failed to notice: a partial run | ||
| 943 | - // would report the first and hide whether the others are covered. | ||
| 944 | - assert!( | ||
| 945 | - blind.is_empty(), | ||
| 946 | - "{NAME}: {} of 7 ffmpeg comparator arms stayed GREEN against an ffmpeg that is wrong \ | ||
| 947 | - by exactly one sample -- {blind:#?} -- they cannot fail, so their green proves \ | ||
| 948 | - nothing (class `comparator-that-never-reads-the-oracle`)", | ||
| 949 | - blind.len() | ||
| 950 | - ); | ||
| 951 | - eprintln!( | ||
| 952 | - "{NAME}: ffmpeg_decode_sequence red on a one-sample-wrong Y, U and V separately; \ | ||
| 953 | - ffmpeg_decode_gray_sequence red on one wrong luma sample; \ | ||
| 954 | - ffmpeg_decode_sequence_10bit red on a one-sample-wrong Y, U and V of the 10-bit \ | ||
| 955 | - film pin" | ||
| 956 | - ); | ||
| 957 | - } | ||
| 958 | - | ||
| 959 | - /// lane-av1422chrtx: the odd-frame-HEIGHT 4:2:0 witness, pinned and now | ||
| 960 | - /// EXACT (lane-av1422anom had pinned it as a ratchet on its own defect). | ||
| 961 | - /// | ||
| 962 | - /// This is NOT a 4:2:2 cell and needs no bypass -- it is ordinary 4:2:0, | ||
| 963 | - /// reachable by any user. lane-av1422anom pinned it as a RATCHET asserting | ||
| 964 | - /// its own measured defect `(0, 200, 17658)`, and said whoever fixed it | ||
| 965 | - /// must flip that to exactness. That is done, and the flip is the | ||
| 966 | - /// deliverable: | ||
| 967 | - /// | ||
| 968 | - /// the defect was a chroma `tx_type`, not a geometry. libaom's | ||
| 969 | - /// `av1_get_ext_tx_set_type` (`blockd.h`) resolves a **32-point** chroma | ||
| 970 | - /// unit to `EXT_TX_SET_DCT_IDTX` when the block `is_inter` -- so an | ||
| 971 | - /// Intra-Block-Copy block whose luma coded `IDTX` runs the identity | ||
| 972 | - /// transform on its chroma. `read_plane`'s `side >= 32` clamp forced | ||
| 973 | - /// `DCT_DCT` there (its `DCT_DCT` cap is really libaom's | ||
| 974 | - /// `txsize_sqr_up_map[tx_size] > TX_32X32`, i.e. 64 and up), so the | ||
| 975 | - /// residual was a 32-point IDCT where libaom's was a plain copy of the | ||
| 976 | - /// dequantized coefficients `>>2`. The wrong samples sat in one 64x64 | ||
| 977 | - /// IBC block's 32x32 chroma unit at chroma (128,96) on frame 0, and | ||
| 978 | - /// propagated from there through the inter frames. | ||
| 979 | - /// | ||
| 980 | - /// `the_counting_oracle_diff_detects_one_flipped_oracle_byte` is the | ||
| 981 | - /// non-vacuity control that keeps the `0` above worth anything. | ||
| 982 | - #[test] | ||
| 983 | - fn the_pinned_420_oddheight_witness_is_pinned_and_decodes_byte_exact() { | ||
| 984 | - const NAME: &str = "the_pinned_420_oddheight_witness_is_pinned_and_decodes_byte_exact"; | ||
| 985 | - // lane-av1cmpaudit2: same mutex as every other oracle gate. | ||
| 986 | - let _gate_lock = lock_gate_counters(); | ||
| 987 | - const FILE: &str = "420_oddheight_320x232.obu"; | ||
| 988 | - const BYTES: usize = 15773; | ||
| 989 | - // sha256 6832c3cd867f5fc491b45fd67f77c38453db0ca6d461e7d225e6276f4d0784c8, | ||
| 990 | - // recorded in `lanes/av1422anom.report.md`. The tree pins fixture | ||
| 991 | - // identity by fnv1a64, asserted below. A `const SHA256` compared | ||
| 992 | - // against itself would be a tautology -- the exact bug this lane | ||
| 993 | - // exists to kill -- so it is not written. | ||
| 994 | - const FNV1A64: u64 = 0x37877f15307c3b; | ||
| 995 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 996 | - .join("fixtures") | ||
| 997 | - .join(FILE); | ||
| 998 | - let data = std::fs::read(&path) | ||
| 999 | - .unwrap_or_else(|e| panic!("{NAME}: pinned witness {FILE} is missing ({e})")); | ||
| 1000 | - assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); | ||
| 1001 | - assert_eq!(fnv1a64(&data), FNV1A64, "{NAME}: {FILE} bytes drifted"); | ||
| 1002 | - let (wy, wu, wv, frames, exact) = | ||
| 1003 | - count_rawvideo_diffs(&data, NAME, None).expect("the two sides must be byte-comparable"); | ||
| 1004 | - assert_eq!( | ||
| 1005 | - (wy, wu, wv), | ||
| 1006 | - (0, 0, 0), | ||
| 1007 | - "{NAME}: the pinned 320x232 witness must decode byte-exactly against \ | ||
| 1008 | - `aomdec --rawvideo` on every plane. It was a RATCHET asserting its own \ | ||
| 1009 | - measured defect (0, 200, 17658); lane-av1422chrtx flipped it to exactness \ | ||
| 1010 | - when the 32-point INTER chroma `tx_type` (EXT_TX_SET_DCT_IDTX, not \ | ||
| 1011 | - EXT_TX_SET_DCTONLY) was fixed. Any non-zero value here is a regression -- \ | ||
| 1012 | - name it in the report." | ||
| 1013 | - ); | ||
| 1014 | - assert_eq!(frames, 16, "{NAME}: shown frame count"); | ||
| 1015 | - assert_eq!( | ||
| 1016 | - exact, frames, | ||
| 1017 | - "{NAME}: every shown frame must be byte-exact" | ||
| 1018 | - ); | ||
| 1019 | - } | ||
| 1020 | - | ||
| 1021 | - /// lane-av1oddheightfork3: the 320x236 cell this lane CLOSED, as a | ||
| 1022 | - /// permanent BYTE-EXACTNESS gate against the live oracle -- not a route | ||
| 1023 | - /// counter, not a source scan. It compares our decoded samples with | ||
| 1024 | - /// `aomdec --rawvideo`'s own bytes plane by plane, and asserts every | ||
| 1025 | - /// frame is byte-exact. | ||
| 1026 | - /// | ||
| 1027 | - /// **The defect it pins.** Before the fix this cell measured | ||
| 1028 | - /// `Y 234349 / U 56957 / V 52981, 0 of 16 frames exact` -- reproduced on | ||
| 1029 | - /// this lane's own tree by reverting the fix, matching | ||
| 1030 | - /// `lanes/av1oddluma.report.md` and `lanes/av1cmpframe.report.md` digit | ||
| 1031 | - /// for digit. The first divergent read is the `txfm_partition` symbol of | ||
| 1032 | - /// the INTRABC 8x16 block at mi(44,60): our `TXFM_CONTEXT` grid held the | ||
| 1033 | - /// BLOCK's own `16` in `left_txfm[44]` where libaom holds the split | ||
| 1034 | - /// leaf's `8` (the operand pair is printed by the oracle rung | ||
| 1035 | - /// `EC_VARTXCTX`, `scripts/instrument-aom-oracle.sh`), so `ctx` was 12 | ||
| 1036 | - /// against libaom's 13 and `is_split` 0 against 1. | ||
| 1037 | - /// | ||
| 1038 | - /// **Non-vacuity.** `the_counting_oracle_diff_detects_one_flipped_oracle_byte` | ||
| 1039 | - /// is the comparator control and does not depend on any witness | ||
| 1040 | - /// diverging; the mutation proof that this gate BITES the defect it | ||
| 1041 | - /// names is in `lanes/av1oddheightfork3.report.md` (revert the | ||
| 1042 | - /// `fill_lf_grid_rect_after_vartx` call sites -> this test reds BY NAME | ||
| 1043 | - /// with the numbers above). | ||
| 1044 | - #[test] | ||
| 1045 | - fn the_pinned_420_oddheight_320x236_witness_decodes_byte_exact() { | ||
| 1046 | - const NAME: &str = "the_pinned_420_oddheight_320x236_witness_decodes_byte_exact"; | ||
| 1047 | - let _gate_lock = lock_gate_counters(); | ||
| 1048 | - const FILE: &str = "420_oddheight_320x236.obu"; | ||
| 1049 | - const BYTES: usize = 16562; | ||
| 1050 | - // sha256 84e4d1ab56620af1c5b78e1aa3d2d67496a492f2e127198c82dd1d68b01c6200. | ||
| 1051 | - // Identity is pinned by fnv1a64 (the same value | ||
| 1052 | - // `the_counting_oracle_diff_attributes_planes_per_frame` asserts) -- | ||
| 1053 | - // a `const SHA256` compared against itself would be the tautology | ||
| 1054 | - // this lane exists to kill. | ||
| 1055 | - const FNV1A64: u64 = 521889434652397870; | ||
| 1056 | - let data = crate_pin("420_oddheight_320x236.obu"); | ||
| 1057 | - let data = std::fs::read(&data) | ||
| 1058 | - .unwrap_or_else(|e| panic!("{NAME}: the committed pin {FILE} is missing ({e})")); | ||
| 1059 | - assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); | ||
| 1060 | - assert_eq!(fnv1a64(&data), FNV1A64, "{NAME}: {FILE} bytes drifted"); | ||
| 1061 | - let (wy, wu, wv, frames, exact) = | ||
| 1062 | - count_rawvideo_diffs(&data, NAME, None).expect("the two sides must be byte-comparable"); | ||
| 1063 | - assert_eq!( | ||
| 1064 | - (wy, wu, wv), | ||
| 1065 | - (0, 0, 0), | ||
| 1066 | - "{NAME}: the pinned 320x236 cell must decode byte-exactly against \ | ||
| 1067 | - `aomdec --rawvideo` on every plane. It measured \ | ||
| 1068 | - (234349, 56957, 52981) with 0 of 16 frames exact until \ | ||
| 1069 | - lane-av1oddheightfork3 fixed the TXFM_CONTEXT whole-block \ | ||
| 1070 | - publish that overwrote a var-tx tree's per-leaf sizes. Any \ | ||
| 1071 | - non-zero value here is a regression -- name it in the report." | ||
| 1072 | - ); | ||
| 1073 | - assert_eq!(frames, 16, "{NAME}: shown frame count"); | ||
| 1074 | - assert_eq!( | ||
| 1075 | - exact, frames, | ||
| 1076 | - "{NAME}: every shown frame must be byte-exact" | ||
| 1077 | - ); | ||
| 1078 | - } | ||
| 1079 | - | ||
| 1080 | - /// The repo's first hidden-frame pixel gate. Every other aomenc gate | ||
| 1081 | - /// here compares `decode_stream`'s output against `ffmpeg -f obu`, and | ||
| 1082 | - /// both sides emit SHOWN frames only -- so an alt-ref frame that is | ||
| 1083 | - /// decoded, stored into a reference slot and never displayed was, until | ||
| 1084 | - /// this gate, never compared to anything (class | ||
| 1085 | - /// gate-blind-to-hidden-frames). His films are aomenc-encoded with the | ||
| 1086 | - /// default `--lag-in-frames`, so they are full of exactly these frames. | ||
| 1087 | - /// | ||
| 1088 | - /// `--auto-alt-ref=1 --lag-in-frames=25` on moving content makes aomenc | ||
| 1089 | - /// build alt-refs; `--arnr-maxframes=0` is load-bearing -- with libaom's | ||
| 1090 | - /// temporal filter on, this fixture's alt-ref candidates get filtered | ||
| 1091 | - /// away and the encoder emits ZERO hidden frames (measured: 0 hidden | ||
| 1092 | - /// with the filter on, 3 with it off), which would have made the gate | ||
| 1093 | - /// vacuous. The `hidden >= 2` assertion is hard, on both bit depths, so | ||
| 1094 | - /// a recipe that stops producing hidden frames fails rather than skips. | ||
| 1095 | - #[test] | ||
| 1096 | - fn a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact() { | ||
| 1097 | - const NAME: &str = "a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact"; | ||
| 1098 | - let _gate_lock = lock_gate_counters(); | ||
| 1099 | - if !have_ffmpeg() { | ||
| 1100 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1101 | - return; | ||
| 1102 | - } | ||
| 1103 | - if !have_aomenc() { | ||
| 1104 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1105 | - return; | ||
| 1106 | - } | ||
| 1107 | - for bit_depth in [8u32, 10u32] { | ||
| 1108 | - let (width, height, frames) = (64usize, 64usize, 40usize); | ||
| 1109 | - let duration = frames as f64 / 25.0; | ||
| 1110 | - let source = format!("testsrc2=size={width}x{height}:duration={duration}:rate=25"); | ||
| 1111 | - let pix_fmt = if bit_depth == 10 { | ||
| 1112 | - "yuv420p10le" | ||
| 1113 | - } else { | ||
| 1114 | - "yuv420p" | ||
| 1115 | - }; | ||
| 1116 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1117 | - .args([ | ||
| 1118 | - "-v", | ||
| 1119 | - "error", | ||
| 1120 | - "-f", | ||
| 1121 | - "lavfi", | ||
| 1122 | - "-i", | ||
| 1123 | - &source, | ||
| 1124 | - "-t", | ||
| 1125 | - &duration.to_string(), | ||
| 1126 | - "-pix_fmt", | ||
| 1127 | - pix_fmt, | ||
| 1128 | - "-strict", | ||
| 1129 | - "-1", | ||
| 1130 | - "-f", | ||
| 1131 | - "yuv4mpegpipe", | ||
| 1132 | - "-", | ||
| 1133 | - ]) | ||
| 1134 | - .stdin(Stdio::null()) | ||
| 1135 | - .stdout(Stdio::piped()) | ||
| 1136 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1137 | - .expect("ffmpeg failed to run"); | ||
| 1138 | - assert!( | ||
| 1139 | - y4m.status.success(), | ||
| 1140 | - "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 1141 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1142 | - ); | ||
| 1143 | - let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 1144 | - let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 1145 | - let out = run_with_stdin( | ||
| 1146 | - Command::new(aomenc_path()).args([ | ||
| 1147 | - // lane-defon r1: the repo's only gate that decodes hidden | ||
| 1148 | - // frames is also the only place a FORWARD KEYFRAME can be | ||
| 1149 | - // proven -- a KEY frame with `show_frame == 0`, which is | ||
| 1150 | - // exactly the shape this gate already compares in decode | ||
| 1151 | - // order. On-values go before the base list (aomenc keeps | ||
| 1152 | - // the FIRST occurrence of a repeated flag). | ||
| 1153 | - "--enable-fwd-kf=1", | ||
| 1154 | - "--fwd-kf-dist=8", | ||
| 1155 | - "--codec=av1", | ||
| 1156 | - "--passes=1", | ||
| 1157 | - "--end-usage=q", | ||
| 1158 | - "--cq-level=45", | ||
| 1159 | - "--cpu-used=0", | ||
| 1160 | - "--threads=1", | ||
| 1161 | - "--row-mt=0", | ||
| 1162 | - "--kf-max-dist=1000", | ||
| 1163 | - "--enable-order-hint=1", | ||
| 1164 | - "--auto-alt-ref=1", | ||
| 1165 | - "--lag-in-frames=25", | ||
| 1166 | - "--arnr-maxframes=0", | ||
| 1167 | - &depth_arg, | ||
| 1168 | - &input_depth_arg, | ||
| 1169 | - // The same tool set every sibling inter gate pins -- the | ||
| 1170 | - // open capability gaps (rect/AB partitions, warped/OBMC, | ||
| 1171 | - // masked compound, palette, ...) are other lanes' work; | ||
| 1172 | - // this gate is about hidden frames, not about them. | ||
| 1173 | - "--enable-warped-motion=0", | ||
| 1174 | - // OBMC stays off HERE (this gate is about hidden frames); | ||
| 1175 | - // the tool's own coverage is the `obmc*` gates and, on a | ||
| 1176 | - // 16x8/8x16 leaf, the `--enable-obmc=1` arm of | ||
| 1177 | - // `..._with_a_16_level_rect_leaf_...` (lane-inter4 r4). | ||
| 1178 | - "--enable-obmc=0", | ||
| 1179 | - "--enable-masked-comp=0", | ||
| 1180 | - "--enable-interintra-comp=0", | ||
| 1181 | - "--enable-onesided-comp=0", | ||
| 1182 | - "--enable-interintra-wedge=0", | ||
| 1183 | - "--enable-smooth-interintra=0", | ||
| 1184 | - "--enable-rect-partitions=0", | ||
| 1185 | - "--enable-ab-partitions=0", | ||
| 1186 | - "--enable-1to4-partitions=0", | ||
| 1187 | - "--enable-filter-intra=0", | ||
| 1188 | - "--enable-smooth-intra=0", | ||
| 1189 | - "--enable-paeth-intra=0", | ||
| 1190 | - "--enable-directional-intra=0", | ||
| 1191 | - "--enable-angle-delta=0", | ||
| 1192 | - "--enable-tx-size-search=0", | ||
| 1193 | - "--enable-cdef=0", | ||
| 1194 | - "--enable-restoration=0", | ||
| 1195 | - "--max-partition-size=32", | ||
| 1196 | - "--min-partition-size=32", | ||
| 1197 | - "--enable-palette=0", | ||
| 1198 | - "--enable-intrabc=0", | ||
| 1199 | - "--enable-cfl-intra=0", | ||
| 1200 | - "--enable-ref-frame-mvs=0", | ||
| 1201 | - "--obu", | ||
| 1202 | - "-o", | ||
| 1203 | - "-", | ||
| 1204 | - "-", | ||
| 1205 | - ]), | ||
| 1206 | - &y4m.stdout, | ||
| 1207 | - ); | ||
| 1208 | - assert!( | ||
| 1209 | - out.status.success(), | ||
| 1210 | - "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}", | ||
| 1211 | - String::from_utf8_lossy(&out.stderr) | ||
| 1212 | - ); | ||
| 1213 | - let stream = out.stdout; | ||
| 1214 | - let fwd_kf_before = crate::decode::fwd_kf_hits(); | ||
| 1215 | - let (total, hidden) = | ||
| 1216 | - decode_all_frames_vs_oracle(&stream, &format!("altref-hidden-{bit_depth}bit")); | ||
| 1217 | - let fwd_kf = crate::decode::fwd_kf_hits() - fwd_kf_before; | ||
| 1218 | - assert!( | ||
| 1219 | - hidden >= 2, | ||
| 1220 | - "{NAME}: the {bit_depth}-bit recipe produced only {hidden} hidden frame(s) of \ | ||
| 1221 | - {total} decoded -- the gate would be vacuous (class \ | ||
| 1222 | - gate-blind-to-hidden-frames)" | ||
| 1223 | - ); | ||
| 1224 | - // lane-defon r1: `--enable-fwd-kf=1` is spelled on this recipe, so | ||
| 1225 | - // a KEY frame with `show_frame == 0` must actually have been | ||
| 1226 | - // decoded -- otherwise the on-value proves nothing. | ||
| 1227 | - assert!( | ||
| 1228 | - fwd_kf > 0, | ||
| 1229 | - "{NAME}: the {bit_depth}-bit recipe decoded {total} frames ({hidden} hidden) but \ | ||
| 1230 | - zero forward keyframes -- --enable-fwd-kf=1 --fwd-kf-dist=8 never reached the \ | ||
| 1231 | - bitstream" | ||
| 1232 | - ); | ||
| 1233 | - eprintln!( | ||
| 1234 | - "{NAME} {bit_depth}-bit: {total} frames decoded, {hidden} hidden, {fwd_kf} \ | ||
| 1235 | - forward keyframes, all pixel-exact vs the oracle in decode order" | ||
| 1236 | - ); | ||
| 1237 | - } | ||
| 1238 | - } | ||
| 1239 | - | ||
| 1240 | - /// A real `aomenc` filter-intra fixture: every other intra mode disabled | ||
| 1241 | - /// (smooth/paeth/directional/angle-delta) and | ||
| 1242 | - /// `--max-partition-size=32` (past which `av1_filter_intra_allowed_bsize`'s | ||
| 1243 | - /// <=32x32 bound means `use_filter_intra` never reads at all, spec | ||
| 1244 | - /// 5.11.14), so the only way this frame codes is `DC_PRED` with filter | ||
| 1245 | - /// intra on top -- `--loopfilter-control=0` is required too: this | ||
| 1246 | - /// decoder has no in-loop deblocking filter at all, and libaom's default | ||
| 1247 | - /// (on) smooths every block-boundary column, which first looked like a | ||
| 1248 | - /// filter-intra math bug (mismatches straddling the 32-pixel block | ||
| 1249 | - /// seam) until the recipe without it round-tripped byte-exact. | ||
| 1250 | - /// | ||
| 1251 | - /// lane-av1skipfix: the attempt-loop shape this gate's single recipe | ||
| 1252 | - /// lacked. It sweeps (seed, cq) and REQUIRES at least one attempt to both | ||
| 1253 | - /// decode and read `use_filter_intra`: a decode error on EVERY attempt is | ||
| 1254 | - /// a hard failure carrying the refusal texts, not a printed SKIP, and an | ||
| 1255 | - /// attempt that decodes without the symbol firing is still pixel-compared | ||
| 1256 | - /// (class `gate-skips-on-its-own-failure`). MEASURED 2026-09-29 on | ||
| 1257 | - /// `a21f3680`: seed 42 cq 40 and seed 43 cq 40 read the symbol 3x each, | ||
| 1258 | - /// pixel-exact, while seed 44 cq 45 and seed 45 cq 30 decode WITHOUT it -- | ||
| 1259 | - /// so the one fixed recipe really did carry the whole gate. | ||
| 1260 | - /// | ||
| 1261 | - /// The per-attempt decode error the old single recipe SKIPped on is | ||
| 1262 | - /// `screen_content_tools_determination` (libaom `encoder_utils.c`): a real | ||
| 1263 | - /// internal trial-encode/PSNR comparison, not a flag this CLI exposes a | ||
| 1264 | - /// knob for -- on this flat gradient fixture it lands on | ||
| 1265 | - /// `allow_screen_content_tools=0` most runs but occasionally trips over | ||
| 1266 | - /// its 0.9 dB threshold the other way even with palette/intrabc both | ||
| 1267 | - /// disabled. That is a genuine separate gap (`decode_stream` never reads | ||
| 1268 | - /// `intrabc`/`palette_mode_info`), so it is a NAMED REFUSAL counted per | ||
| 1269 | - /// attempt, never a silent skip and never a pass. | ||
| 1270 | - #[test] | ||
| 1271 | - fn a_real_aomenc_filter_intra_stream_decodes_pixel_exact() { | ||
| 1272 | - const NAME: &str = "a_real_aomenc_filter_intra_stream_decodes_pixel_exact"; | ||
| 1273 | - let _gate_lock = lock_gate_counters(); | ||
| 1274 | - if !have_ffmpeg() { | ||
| 1275 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1276 | - return; | ||
| 1277 | - } | ||
| 1278 | - if !have_aomenc() { | ||
| 1279 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1280 | - return; | ||
| 1281 | - } | ||
| 1282 | - let (width, height) = (64usize, 64usize); | ||
| 1283 | - // Recipe-search hooks: with the encoder pinned to one thread the stream | ||
| 1284 | - // is a deterministic function of (seed, cq), so a firing recipe can be | ||
| 1285 | - // searched for without a rebuild. These pin attempt 0 for a bisect; the | ||
| 1286 | - // sweep walks the same axes regardless. | ||
| 1287 | - let fi_seed: u32 = std::env::var("EC_FI_SEED") | ||
| 1288 | - .ok() | ||
| 1289 | - .and_then(|v| v.parse().ok()) | ||
| 1290 | - .unwrap_or(42); | ||
| 1291 | - let fi_cq: u32 = std::env::var("EC_FI_CQ") | ||
| 1292 | - .ok() | ||
| 1293 | - .and_then(|v| v.parse().ok()) | ||
| 1294 | - .unwrap_or(40); | ||
| 1295 | - // Two seeds x three quantisers, so "every attempt refused" and "no | ||
| 1296 | - // attempt ever read `use_filter_intra`" are distinguishable failures | ||
| 1297 | - // rather than one unlucky recipe. | ||
| 1298 | - const CQS: [u32; 3] = [40, 35, 30]; | ||
| 1299 | - let mut refusals = Vec::new(); | ||
| 1300 | - let mut counted_exact = 0u32; | ||
| 1301 | - let mut uncounted_exact = 0u32; | ||
| 1302 | - 'attempts: for round in 0..2u32 { | ||
| 1303 | - for (i, &walked) in CQS.iter().enumerate() { | ||
| 1304 | - let seed = fi_seed + round; | ||
| 1305 | - let cq = if round == 0 && i == 0 { fi_cq } else { walked }; | ||
| 1306 | - let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 1307 | - let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1308 | - .args([ | ||
| 1309 | - "-v", | ||
| 1310 | - "error", | ||
| 1311 | - "-f", | ||
| 1312 | - "lavfi", | ||
| 1313 | - "-i", | ||
| 1314 | - &source, | ||
| 1315 | - "-pix_fmt", | ||
| 1316 | - "yuv420p", | ||
| 1317 | - "-f", | ||
| 1318 | - "yuv4mpegpipe", | ||
| 1319 | - "-", | ||
| 1320 | - ]) | ||
| 1321 | - .stdin(Stdio::null()) | ||
| 1322 | - .stdout(Stdio::piped()) | ||
| 1323 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1324 | - .expect("ffmpeg failed to run"); | ||
| 1325 | - assert!( | ||
| 1326 | - y4m.status.success(), | ||
| 1327 | - "ffmpeg refused to generate the y4m fixture: {}", | ||
| 1328 | - String::from_utf8_lossy(&y4m.stderr) | ||
| 1329 | - ); | ||
| 1330 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 1331 | - let out = run_with_stdin( | ||
| 1332 | - Command::new(aomenc_path()).args([ | ||
| 1333 | - "--codec=av1", | ||
| 1334 | - "--passes=1", | ||
| 1335 | - "--end-usage=q", | ||
| 1336 | - &cq_arg, | ||
| 1337 | - "--cpu-used=0", | ||
| 1338 | - // Every sibling gate pins these; this one did not, and a | ||
| 1339 | - // multi-threaded aomenc is not deterministic, so each run | ||
| 1340 | - // encoded a slightly different stream and the gate flaked | ||
| 1341 | - // against whichever features that run happened to pick. | ||
| 1342 | - // Pinning them makes seed 42 mean one stream (class | ||
| 1343 | - // `parallel-flake-is-attempt-selection`). | ||
| 1344 | - "--threads=1", | ||
| 1345 | - "--row-mt=0", | ||
| 1346 | - "--enable-filter-intra=1", | ||
| 1347 | - "--enable-smooth-intra=0", | ||
| 1348 | - "--enable-paeth-intra=0", | ||
| 1349 | - "--enable-directional-intra=0", | ||
| 1350 | - "--enable-angle-delta=0", | ||
| 1351 | - "--enable-tx-size-search=0", | ||
| 1352 | - "--enable-cdef=0", | ||
| 1353 | - "--max-partition-size=32", | ||
| 1354 | - "--loopfilter-control=0", | ||
| 1355 | - "--enable-palette=0", | ||
| 1356 | - "--enable-intrabc=0", | ||
| 1357 | - "--obu", | ||
| 1358 | - "-o", | ||
| 1359 | - "-", | ||
| 1360 | - "-", | ||
| 1361 | - ]), | ||
| 1362 | - &y4m.stdout, | ||
| 1363 | - ); | ||
| 1364 | - assert!( | ||
| 1365 | - out.status.success(), | ||
| 1366 | - "{NAME}: aomenc refused the seed {seed} cq {cq} fixture: {}", | ||
| 1367 | - String::from_utf8_lossy(&out.stderr) | ||
| 1368 | - ); | ||
| 1369 | - let stream = out.stdout; | ||
| 1370 | - let before = decode::filter_intra_hits(); | ||
| 1371 | - let frames = match decode_stream(&stream) { | ||
| 1372 | - Ok(frames) => frames, | ||
| 1373 | - Err(e) => { | ||
| 1374 | - refusals.push(format!("seed {seed} cq {cq}: {e}")); | ||
| 1375 | - continue; | ||
| 1376 | - } | ||
| 1377 | - }; | ||
| 1378 | - // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 1379 | - // counter only decides whether the attempt counts as firing | ||
| 1380 | - // (class `counter-from-refused-stream`). | ||
| 1381 | - let counted = decode::filter_intra_hits() != before; | ||
| 1382 | - if counted { | ||
| 1383 | - counted_exact += 1; | ||
| 1384 | - } else { | ||
| 1385 | - uncounted_exact += 1; | ||
| 1386 | - } | ||
| 1387 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 1388 | - assert_eq!( | ||
| 1389 | - frames[0].y, ffmpeg_frames[0].y, | ||
| 1390 | - "luma vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 1391 | - ); | ||
| 1392 | - assert_eq!( | ||
| 1393 | - frames[0].u, ffmpeg_frames[0].u, | ||
| 1394 | - "U vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 1395 | - ); | ||
| 1396 | - assert_eq!( | ||
| 1397 | - frames[0].v, ffmpeg_frames[0].v, | ||
| 1398 | - "V vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 1399 | - ); | ||
| 1400 | - if counted_exact >= 2 { | ||
| 1401 | - break 'attempts; | ||
| 1402 | - } | ||
| 1403 | - } | ||
| 1404 | - } | ||
| 1405 | - gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 1406 | - assert!( | ||
| 1407 | - counted_exact > 0, | ||
| 1408 | - "{NAME}: none of {} attempts decoded a stream that read use_filter_intra -- the \ | ||
| 1409 | - gate would prove nothing (class gate-blind-to-feature):\n{}", | ||
| 1410 | - CQS.len() * 2, | ||
| 1411 | - refusals.join("\n") | ||
| 1412 | - ); | ||
| 1413 | - } | ||
| 1414 | - | ||
| 1415 | - /// A real `aomenc` palette-Y fixture (lane-palette r3): `smptebars` | ||
| 1416 | - /// (SMPTE colour bars -- a handful of large flat luma regions, exactly | ||
| 1417 | - /// the "flat, few-colour, repetitive" content `av1_choose_palette_map`'s | ||
| 1418 | - /// RD trial rewards) with `hue=s=0` to flatten chroma to one constant | ||
| 1419 | - /// value, so `DC_PRED` already nails every chroma block with zero | ||
| 1420 | - /// residual and the encoder's own RD never has a reason to spend bits on | ||
| 1421 | - /// a *UV* palette too (a real symbol this decoder still refuses -- | ||
| 1422 | - /// lane-palette r3's own scope is Y only). `smptebars` has no seed to | ||
| 1423 | - /// vary, so the fixture is deterministic by construction; hashed twice | ||
| 1424 | - /// below to prove it rather than assert it. `--enable-rect-partitions=0` | ||
| 1425 | - /// / `-ab-` / `-1to4-` keep every intra block square, sidestepping the | ||
| 1426 | - /// rect-strip screen-content refusal at `read_intra_mode_rect` | ||
| 1427 | - /// (decode.rs ~2226) -- that refusal is this lane's own next milestone, | ||
| 1428 | - /// not this gate's. `--sb-size=64` and `--threads=1 --row-mt=0` are the | ||
| 1429 | - /// sibling-lane facts this charter paid for: a single 64x64 frame is one | ||
| 1430 | - /// superblock either way, but pinning them keeps the recipe identical to | ||
| 1431 | - /// every other gate in this file. HARD-asserts | ||
| 1432 | - /// [`decode::palette_hits`] moved -- a stream that never reads a real | ||
| 1433 | - /// palette block would refuse (or not) by construction without proving | ||
| 1434 | - /// this milestone at all. | ||
| 1435 | - /// | ||
| 1436 | - /// lane-palette r4/r6/r7: r3/r4 found that this fixture's reconstructed | ||
| 1437 | - /// pixels did not match ffmpeg's decode of the same bytes even though | ||
| 1438 | - /// every symbol read by `decode_color_index_map` checked line-for-line | ||
| 1439 | - /// against the oracle and matched. r6's range trace (`compare-range-not-tell`) | ||
| 1440 | - /// pinned the real cause: `decode_color_index_map` was called from the | ||
| 1441 | - /// wrong syntax position -- inline right after the Y colours, instead of | ||
| 1442 | - /// after the whole mode-info read (UV palette mode_info + `filter_intra`, | ||
| 1443 | - /// `av1_visit_palette`'s real call order). r7 ported the UV palette | ||
| 1444 | - /// mode_info read and moved the colour-index-map decode after | ||
| 1445 | - /// `filter_intra`; this gate now asserts a real pixel match instead of | ||
| 1446 | - /// the old named refusal. | ||
| 1447 | - #[test] | ||
| 1448 | - fn a_real_aomenc_stream_with_palette_y_decodes_pixel_exact() { | ||
| 1449 | - const NAME: &str = "a_real_aomenc_stream_with_palette_y_decodes_pixel_exact"; | ||
| 1450 | - if !have_ffmpeg() { | ||
| 1451 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1452 | - return; | ||
| 1453 | - } | ||
| 1454 | - if !have_aomenc() { | ||
| 1455 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1456 | - return; | ||
| 1457 | - } | ||
| 1458 | - let source = "smptebars=size=64x64:rate=25"; | ||
| 1459 | - fn render(source: &str) -> Vec<u8> { | ||
| 1460 | - crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1461 | - .args([ | ||
| 1462 | - "-v", | ||
| 1463 | - "error", | ||
| 1464 | - "-f", | ||
| 1465 | - "lavfi", | ||
| 1466 | - "-i", | ||
| 1467 | - source, | ||
| 1468 | - "-vf", | ||
| 1469 | - "hue=s=0", | ||
| 1470 | - "-pix_fmt", | ||
| 1471 | - "yuv420p", | ||
| 1472 | - "-t", | ||
| 1473 | - "0.04", | ||
| 1474 | - "-f", | ||
| 1475 | - "yuv4mpegpipe", | ||
| 1476 | - "-", | ||
| 1477 | - ]) | ||
| 1478 | - .stdin(Stdio::null()) | ||
| 1479 | - .stdout(Stdio::piped()) | ||
| 1480 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1481 | - .expect("ffmpeg failed to run") | ||
| 1482 | - .stdout | ||
| 1483 | - } | ||
| 1484 | - let y4m_a = render(source); | ||
| 1485 | - let y4m_b = render(source); | ||
| 1486 | - assert_eq!( | ||
| 1487 | - y4m_a, y4m_b, | ||
| 1488 | - "smptebars must render byte-identical across two runs" | ||
| 1489 | - ); | ||
| 1490 | - let y4m = y4m_a; | ||
| 1491 | - let out = run_with_stdin( | ||
| 1492 | - Command::new(aomenc_path()).args([ | ||
| 1493 | - "--codec=av1", | ||
| 1494 | - "--passes=1", | ||
| 1495 | - "--end-usage=q", | ||
| 1496 | - "--cq-level=30", | ||
| 1497 | - "--cpu-used=0", | ||
| 1498 | - "--threads=1", | ||
| 1499 | - "--row-mt=0", | ||
| 1500 | - "--sb-size=64", | ||
| 1501 | - "--tune-content=screen", | ||
| 1502 | - "--enable-palette=1", | ||
| 1503 | - "--enable-intrabc=0", | ||
| 1504 | - "--enable-rect-partitions=0", | ||
| 1505 | - "--enable-ab-partitions=0", | ||
| 1506 | - "--enable-1to4-partitions=0", | ||
| 1507 | - "--min-partition-size=32", | ||
| 1508 | - "--max-partition-size=32", | ||
| 1509 | - "--enable-filter-intra=0", | ||
| 1510 | - "--enable-smooth-intra=0", | ||
| 1511 | - "--enable-paeth-intra=0", | ||
| 1512 | - "--enable-directional-intra=0", | ||
| 1513 | - "--enable-angle-delta=0", | ||
| 1514 | - "--enable-cfl-intra=0", | ||
| 1515 | - "--enable-cdef=0", | ||
| 1516 | - "--enable-restoration=0", | ||
| 1517 | - "--enable-tx-size-search=0", | ||
| 1518 | - "--loopfilter-control=0", | ||
| 1519 | - "--obu", | ||
| 1520 | - "-o", | ||
| 1521 | - "-", | ||
| 1522 | - "-", | ||
| 1523 | - ]), | ||
| 1524 | - &y4m, | ||
| 1525 | - ); | ||
| 1526 | - assert!( | ||
| 1527 | - out.status.success(), | ||
| 1528 | - "aomenc refused the fixture: {}", | ||
| 1529 | - String::from_utf8_lossy(&out.stderr) | ||
| 1530 | - ); | ||
| 1531 | - let stream = out.stdout; | ||
| 1532 | - let before = decode::palette_hits(); | ||
| 1533 | - let frames = match decode_stream(&stream) { | ||
| 1534 | - Ok(frames) => frames, | ||
| 1535 | - Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 1536 | - }; | ||
| 1537 | - assert!( | ||
| 1538 | - decode::palette_hits() > before, | ||
| 1539 | - "palette_y_mode never fired decoding this stream -- gate is vacuous" | ||
| 1540 | - ); | ||
| 1541 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, 1); | ||
| 1542 | - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg"); | ||
| 1543 | - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg"); | ||
| 1544 | - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | ||
| 1545 | - } | ||
| 1546 | - | ||
| 1547 | - /// lane-kf900 r3: the palette colour reader at BOTH bit depths. | ||
| 1548 | - /// | ||
| 1549 | - /// `read_palette_colors_y`/`_uv` (decode.rs, mirroring `decodemv.c:478` | ||
| 1550 | - /// and `:509`) size every raw literal they read by the sequence's | ||
| 1551 | - /// `bit_depth`: the first colour is `bit_depth` bits, `min_bits` is | ||
| 1552 | - /// `bit_depth - 3` (Y/U) or `bit_depth - 4` (V), `range` starts at | ||
| 1553 | - /// `1 << bit_depth`, and the clamp/wrap bound is `(1 << bit_depth) - 1`. | ||
| 1554 | - /// Ours hardcoded 8, so every 10-bit palette block read TWO BITS TOO FEW | ||
| 1555 | - /// per transmitted colour and silently decoded the rest of the tile from | ||
| 1556 | - /// the wrong bit position. | ||
| 1557 | - /// | ||
| 1558 | - /// It was silent because raw literals are EQUIPROBABLE: at the ranges | ||
| 1559 | - /// this content reaches an equiprobable read maps the msac range onto | ||
| 1560 | - /// itself (62728 -> 31364 -> renormalised 62728), so a cross-decoder | ||
| 1561 | - /// RANGE ladder stays bit-identical straight through the miscount and | ||
| 1562 | - /// only the decoded VALUE moves. Pinned on a 256x192 10-bit | ||
| 1563 | - /// `--cq-level=59` stream whose first block is a 32x16 palette: aomdec's | ||
| 1564 | - /// `EC_PAL` ladder and ours agreed on every range and disagreed on the | ||
| 1565 | - /// very first colour index (0 vs 1); after the fix all 1024 `EC_PAL` | ||
| 1566 | - /// lines of that block match aomdec line for line. | ||
| 1567 | - /// | ||
| 1568 | - /// The recipe is the 8-bit `..._with_palette_y_...` gate's, with the | ||
| 1569 | - /// depth as the only variable, so a failure here is the depth and | ||
| 1570 | - /// nothing else. HARD-asserts [`decode::palette_hits`] moved on each arm | ||
| 1571 | - /// (a stream with no real palette block would prove nothing) and | ||
| 1572 | - /// compares all three planes against ffmpeg's decode of the same bytes. | ||
| 1573 | - #[test] | ||
| 1574 | - fn a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit() { | ||
| 1575 | - const NAME: &str = "a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit"; | ||
| 1576 | - if !have_ffmpeg() { | ||
| 1577 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1578 | - return; | ||
| 1579 | - } | ||
| 1580 | - if !have_aomenc() { | ||
| 1581 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1582 | - return; | ||
| 1583 | - } | ||
| 1584 | - let (width, height) = (64usize, 64usize); | ||
| 1585 | - for depth in [8usize, 10] { | ||
| 1586 | - let pix_fmt = if depth == 10 { | ||
| 1587 | - "yuv420p10le" | ||
| 1588 | - } else { | ||
| 1589 | - "yuv420p" | ||
| 1590 | - }; | ||
| 1591 | - let render = || { | ||
| 1592 | - crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1593 | - .args([ | ||
| 1594 | - "-v", | ||
| 1595 | - "error", | ||
| 1596 | - "-f", | ||
| 1597 | - "lavfi", | ||
| 1598 | - "-i", | ||
| 1599 | - "smptebars=size=64x64:rate=25", | ||
| 1600 | - "-vf", | ||
| 1601 | - "hue=s=0", | ||
| 1602 | - "-pix_fmt", | ||
| 1603 | - pix_fmt, | ||
| 1604 | - "-strict", | ||
| 1605 | - "-1", | ||
| 1606 | - "-t", | ||
| 1607 | - "0.04", | ||
| 1608 | - "-f", | ||
| 1609 | - "yuv4mpegpipe", | ||
| 1610 | - "-", | ||
| 1611 | - ]) | ||
| 1612 | - .stdin(Stdio::null()) | ||
| 1613 | - .stdout(Stdio::piped()) | ||
| 1614 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1615 | - .expect("ffmpeg failed to run") | ||
| 1616 | - .stdout | ||
| 1617 | - }; | ||
| 1618 | - let y4m_a = render(); | ||
| 1619 | - let y4m_b = render(); | ||
| 1620 | - assert_eq!( | ||
| 1621 | - y4m_a, y4m_b, | ||
| 1622 | - "{NAME}: smptebars must render byte-identical across two runs at {depth}-bit" | ||
| 1623 | - ); | ||
| 1624 | - let y4m = y4m_a; | ||
| 1625 | - let depth_arg = format!("--bit-depth={depth}"); | ||
| 1626 | - let input_depth_arg = format!("--input-bit-depth={depth}"); | ||
| 1627 | - let out = run_with_stdin( | ||
| 1628 | - Command::new(aomenc_path()) | ||
| 1629 | - .args([ | ||
| 1630 | - "--codec=av1", | ||
| 1631 | - "--passes=1", | ||
| 1632 | - "--end-usage=q", | ||
| 1633 | - "--cq-level=30", | ||
| 1634 | - "--cpu-used=0", | ||
| 1635 | - "--threads=1", | ||
| 1636 | - "--row-mt=0", | ||
| 1637 | - "--sb-size=64", | ||
| 1638 | - "--tune-content=screen", | ||
| 1639 | - "--enable-palette=1", | ||
| 1640 | - "--enable-intrabc=0", | ||
| 1641 | - "--enable-rect-partitions=0", | ||
| 1642 | - "--enable-ab-partitions=0", | ||
| 1643 | - "--enable-1to4-partitions=0", | ||
| 1644 | - "--min-partition-size=32", | ||
| 1645 | - "--max-partition-size=32", | ||
| 1646 | - "--enable-filter-intra=0", | ||
| 1647 | - "--enable-smooth-intra=0", | ||
| 1648 | - "--enable-paeth-intra=0", | ||
| 1649 | - "--enable-directional-intra=0", | ||
| 1650 | - "--enable-angle-delta=0", | ||
| 1651 | - "--enable-cfl-intra=0", | ||
| 1652 | - "--enable-cdef=0", | ||
| 1653 | - "--enable-restoration=0", | ||
| 1654 | - "--enable-tx-size-search=0", | ||
| 1655 | - "--loopfilter-control=0", | ||
| 1656 | - "--limit=1", | ||
| 1657 | - ]) | ||
| 1658 | - // Per-arm overrides go AFTER the base recipe: aomenc keeps the | ||
| 1659 | - // LAST occurrence of a repeated flag. | ||
| 1660 | - .args([&depth_arg, &input_depth_arg]) | ||
| 1661 | - .args(["--obu", "-o", "-", "-"]), | ||
| 1662 | - &y4m, | ||
| 1663 | - ); | ||
| 1664 | - assert!( | ||
| 1665 | - out.status.success(), | ||
| 1666 | - "{NAME}: aomenc refused the {depth}-bit fixture: {}", | ||
| 1667 | - String::from_utf8_lossy(&out.stderr) | ||
| 1668 | - ); | ||
| 1669 | - let stream = out.stdout; | ||
| 1670 | - let before = decode::palette_hits(); | ||
| 1671 | - let frames = match decode_stream(&stream) { | ||
| 1672 | - Ok(frames) => frames, | ||
| 1673 | - Err(e) => panic!("{NAME}: decode_stream refused the {depth}-bit stream: {e}"), | ||
| 1674 | - }; | ||
| 1675 | - assert!( | ||
| 1676 | - decode::palette_hits() > before, | ||
| 1677 | - "{NAME}: no real palette block at {depth}-bit -- gate is vacuous" | ||
| 1678 | - ); | ||
| 1679 | - let ffmpeg_frames = if depth == 10 { | ||
| 1680 | - ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 1681 | - } else { | ||
| 1682 | - ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 1683 | - }; | ||
| 1684 | - assert_eq!( | ||
| 1685 | - frames[0].y, ffmpeg_frames[0].y, | ||
| 1686 | - "{NAME}: luma at {depth}-bit" | ||
| 1687 | - ); | ||
| 1688 | - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U at {depth}-bit"); | ||
| 1689 | - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V at {depth}-bit"); | ||
| 1690 | - } | ||
| 1691 | - } | ||
| 1692 | - | ||
| 1693 | - /// lane-pal8 r1, the gate for a palette on a SQUARE 8x8 LEAF. | ||
| 1694 | - /// | ||
| 1695 | - /// `read_palette_mode_info` (decodemv.c:567) reads `palette_y_mode` for | ||
| 1696 | - /// every `DC_PRED` block whose `av1_get_palette_bsize_ctx` | ||
| 1697 | - /// (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`, 0 at 8x8) exists, and | ||
| 1698 | - /// `av1_decode_palette_tokens` (decodeframe.c:1135, `av1_visit_palette`) | ||
| 1699 | - /// reads the colour-index map after the WHOLE mode-info read. Ours passed | ||
| 1700 | - /// `None`/`&[]` from [`decode::decode_leaf8`], reading the mode symbol off | ||
| 1701 | - /// CDF row 0 and refusing "a block that actually uses a palette (Y) -- | ||
| 1702 | - /// reconstruction is out of scope" the moment it fired -- and at 8 bit | ||
| 1703 | - /// aomenc palettes SQUARE blocks, so with `--min-partition-size=8` every | ||
| 1704 | - /// 8-bit screen-content stream stopped there (lane-kf900 r4's measurement). | ||
| 1705 | - /// | ||
| 1706 | - /// Sweeps both bit depths x cq 30/40/55 x `--enable-tx-size-search` 0/1 x | ||
| 1707 | - /// two lavfi sources (+ a `--tile-columns=1` arm, per the neighbour-map | ||
| 1708 | - /// rule: the palette bands are per-mi and tile-guarded). Key frame only | ||
| 1709 | - /// (`--limit=1`): the inter frames of these recipes stop on OTHER lanes' | ||
| 1710 | - /// open refusals (8x8 inter leaf chroma mode, inter 1:4 partitions). | ||
| 1711 | - /// HARD-asserts the 8x8-leaf palette counter moved on the compared arms | ||
| 1712 | - /// and that no arm mismatched, in or out of scope. | ||
| 1713 | - #[test] | ||
| 1714 | - fn a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact() { | ||
| 1715 | - const NAME: &str = "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact"; | ||
| 1716 | - if !have_ffmpeg() { | ||
| 1717 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1718 | - return; | ||
| 1719 | - } | ||
| 1720 | - if !have_aomenc() { | ||
| 1721 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1722 | - return; | ||
| 1723 | - } | ||
| 1724 | - let (width, height) = (128usize, 128usize); | ||
| 1725 | - let (mut leaf8_total, mut fired_arms, mut compared, mut frames_compared) = | ||
| 1726 | - (0usize, 0u32, 0u32, 0usize); | ||
| 1727 | - let (mut out_of_scope, mut out_of_scope_mismatch, mut refusals) = (0u32, 0u32, 0u32); | ||
| 1728 | - let (mut sb_strip_total, mut sb_strip_arms) = (0usize, 0u32); | ||
| 1729 | - // lane-t900 r34 LIFTED this shape; the counter stays so the gate | ||
| 1730 | - // fails loudly if the refusal ever comes back. | ||
| 1731 | - let mut sb_strip_refusals = 0u32; | ||
| 1732 | - for src in ["testsrc2", "smptebars"] { | ||
| 1733 | - for depth in [8usize, 10usize] { | ||
| 1734 | - for cq in [30usize, 40, 55] { | ||
| 1735 | - for txs in [0usize, 1] { | ||
| 1736 | - for tiles in [0usize, 1] { | ||
| 1737 | - let arm = format!("{src}-{depth}bit-cq{cq}-txs{txs}-tc{tiles}"); | ||
| 1738 | - let pix_fmt = if depth == 10 { | ||
| 1739 | - "yuv420p10le" | ||
| 1740 | - } else { | ||
| 1741 | - "yuv420p" | ||
| 1742 | - }; | ||
| 1743 | - let size = format!("{src}=size={width}x{height}:rate=25"); | ||
| 1744 | - let render = || { | ||
| 1745 | - let out = crate::tool_cache::cached_output_io(Command::new("ffmpeg") | ||
| 1746 | - .args([ | ||
| 1747 | - "-v", | ||
| 1748 | - "error", | ||
| 1749 | - "-f", | ||
| 1750 | - "lavfi", | ||
| 1751 | - "-i", | ||
| 1752 | - &size, | ||
| 1753 | - "-t", | ||
| 1754 | - "0.04", | ||
| 1755 | - "-pix_fmt", | ||
| 1756 | - pix_fmt, | ||
| 1757 | - "-strict", | ||
| 1758 | - "-1", | ||
| 1759 | - "-f", | ||
| 1760 | - "yuv4mpegpipe", | ||
| 1761 | - "-", | ||
| 1762 | - ]) | ||
| 1763 | - .stdin(Stdio::null()) | ||
| 1764 | - .stdout(Stdio::piped()) | ||
| 1765 | - .stderr(Stdio::piped()), None, |c| c.output()) | ||
| 1766 | - .expect("ffmpeg failed to run"); | ||
| 1767 | - assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | ||
| 1768 | - out.stdout | ||
| 1769 | - }; | ||
| 1770 | - let y4m_a = render(); | ||
| 1771 | - let y4m_b = render(); | ||
| 1772 | - assert_eq!( | ||
| 1773 | - y4m_a, y4m_b, | ||
| 1774 | - "{NAME}: {arm} must render byte-identical across two runs" | ||
| 1775 | - ); | ||
| 1776 | - let y4m = y4m_a; | ||
| 1777 | - let depth_arg = format!("--bit-depth={depth}"); | ||
| 1778 | - let input_depth_arg = format!("--input-bit-depth={depth}"); | ||
| 1779 | - let cq_arg = format!("--cq-level={cq}"); | ||
| 1780 | - let txs_arg = format!("--enable-tx-size-search={txs}"); | ||
| 1781 | - let tiles_arg = format!("--tile-columns={tiles}"); | ||
| 1782 | - let out = run_with_stdin( | ||
| 1783 | - Command::new(aomenc_path()) | ||
| 1784 | - .args([ | ||
| 1785 | - "--codec=av1", | ||
| 1786 | - "--passes=1", | ||
| 1787 | - "--end-usage=q", | ||
| 1788 | - "--cpu-used=0", | ||
| 1789 | - "--threads=1", | ||
| 1790 | - "--row-mt=0", | ||
| 1791 | - "--lag-in-frames=0", | ||
| 1792 | - "--limit=1", | ||
| 1793 | - "--sb-size=64", | ||
| 1794 | - "--tune-content=screen", | ||
| 1795 | - "--enable-palette=1", | ||
| 1796 | - "--enable-intrabc=0", | ||
| 1797 | - "--min-partition-size=8", | ||
| 1798 | - "--enable-cdef=0", | ||
| 1799 | - "--enable-restoration=0", | ||
| 1800 | - "--loopfilter-control=0", | ||
| 1801 | - ]) | ||
| 1802 | - // aomenc keeps the LAST occurrence of a repeated flag, | ||
| 1803 | - // so per-arm overrides go after the base recipe. | ||
| 1804 | - .args([ | ||
| 1805 | - &depth_arg, | ||
| 1806 | - &input_depth_arg, | ||
| 1807 | - &cq_arg, | ||
| 1808 | - &txs_arg, | ||
| 1809 | - &tiles_arg, | ||
| 1810 | - ]) | ||
| 1811 | - .args(["--obu", "-o", "-", "-"]), | ||
| 1812 | - &y4m, | ||
| 1813 | - ); | ||
| 1814 | - assert!( | ||
| 1815 | - out.status.success(), | ||
| 1816 | - "{NAME}: aomenc refused {arm}: {}", | ||
| 1817 | - String::from_utf8_lossy(&out.stderr) | ||
| 1818 | - ); | ||
| 1819 | - let stream = out.stdout; | ||
| 1820 | - decode::reset_palette_leaf8_hits(); | ||
| 1821 | - decode::reset_palette_sb_strip_hits(); | ||
| 1822 | - let decoded = decode_stream(&stream); | ||
| 1823 | - let leaf8 = decode::palette_leaf8_hits(); | ||
| 1824 | - let sb_strip = decode::palette_sb_strip_hits(); | ||
| 1825 | - leaf8_total += leaf8; | ||
| 1826 | - sb_strip_total += sb_strip; | ||
| 1827 | - match decoded { | ||
| 1828 | - Ok(frames) => { | ||
| 1829 | - assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); | ||
| 1830 | - // The ENCODE's frame count: the per-arm | ||
| 1831 | - // render (10417) builds | ||
| 1832 | - // `{src}=size=128x128:rate=25` with `-t 0.04` | ||
| 1833 | - // (10427) -- one frame -- and the aomenc args | ||
| 1834 | - // carry `--limit=1` (10467), so every | ||
| 1835 | - // (src, depth, cq, txs, tiles) arm codes | ||
| 1836 | - // exactly 1 frame. Asserted ABOVE the oracle | ||
| 1837 | - // call. | ||
| 1838 | - assert_eq!(frames.len(), 1, "{NAME}: {arm} key frame"); | ||
| 1839 | - let theirs = if depth == 10 { | ||
| 1840 | - ffmpeg_decode_sequence_10bit( | ||
| 1841 | - &stream, | ||
| 1842 | - width, | ||
| 1843 | - height, | ||
| 1844 | - frames.len(), | ||
| 1845 | - ) | ||
| 1846 | - } else { | ||
| 1847 | - ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 1848 | - }; | ||
| 1849 | - assert_eq!( | ||
| 1850 | - frames.len(), | ||
| 1851 | - theirs.len(), | ||
| 1852 | - "{NAME}: {arm} frame count" | ||
| 1853 | - ); | ||
| 1854 | - let mut same = true; | ||
| 1855 | - for (i, (ours, ref_f)) in | ||
| 1856 | - frames.iter().zip(theirs.iter()).enumerate() | ||
| 1857 | - { | ||
| 1858 | - let ok = ours.y == ref_f.y | ||
| 1859 | - && ours.u == ref_f.u | ||
| 1860 | - && ours.v == ref_f.v; | ||
| 1861 | - if !ok { | ||
| 1862 | - eprintln!("{NAME}: {arm} MISMATCH at frame {i}"); | ||
| 1863 | - } | ||
| 1864 | - same &= ok; | ||
| 1865 | - frames_compared += 1; | ||
| 1866 | - } | ||
| 1867 | - compared += 1; | ||
| 1868 | - if sb_strip > 0 { | ||
| 1869 | - sb_strip_arms += 1; | ||
| 1870 | - assert!( | ||
| 1871 | - same, | ||
| 1872 | - "{NAME}: {arm} decoded {sb_strip} non-skip palette \ | ||
| 1873 | - block(s) on a superblock-level strip and did not \ | ||
| 1874 | - match ffmpeg" | ||
| 1875 | - ); | ||
| 1876 | - } | ||
| 1877 | - if leaf8 > 0 || sb_strip > 0 { | ||
| 1878 | - fired_arms += 1; | ||
| 1879 | - assert!( | ||
| 1880 | - same, | ||
| 1881 | - "{NAME}: {arm} decoded {leaf8} 8x8-leaf palette \ | ||
| 1882 | - block(s) and did not match ffmpeg" | ||
| 1883 | - ); | ||
| 1884 | - } else { | ||
| 1885 | - out_of_scope += 1; | ||
| 1886 | - if !same { | ||
| 1887 | - out_of_scope_mismatch += 1; | ||
| 1888 | - } | ||
| 1889 | - } | ||
| 1890 | - eprintln!( | ||
| 1891 | - "{NAME}: {arm} {} frame(s), {leaf8} 8x8-leaf palette \ | ||
| 1892 | - block(s), {sb_strip} superblock-strip palette \ | ||
| 1893 | - block(s), exact={same}", | ||
| 1894 | - frames.len() | ||
| 1895 | - ); | ||
| 1896 | - } | ||
| 1897 | - Err(e) => { | ||
| 1898 | - let msg = e.to_string(); | ||
| 1899 | - assert!( | ||
| 1900 | - msg.contains("unsupported"), | ||
| 1901 | - "{NAME}: {arm} decode failed: {e}" | ||
| 1902 | - ); | ||
| 1903 | - // Named, counted, never turned into a skip. | ||
| 1904 | - if msg.contains("superblock-level HORZ/VERT strip") { | ||
| 1905 | - sb_strip_refusals += 1; | ||
| 1906 | - } | ||
| 1907 | - eprintln!("{NAME}: {arm} REFUSED: {e}"); | ||
| 1908 | - refusals += 1; | ||
| 1909 | - } | ||
| 1910 | - } | ||
| 1911 | - } | ||
| 1912 | - } | ||
| 1913 | - } | ||
| 1914 | - } | ||
| 1915 | - } | ||
| 1916 | - eprintln!( | ||
| 1917 | - "{NAME}: {leaf8_total} 8x8-leaf palette block(s) across {fired_arms} arm(s), \ | ||
| 1918 | - {compared} arms compared ({frames_compared} frames), {sb_strip_total} \ | ||
| 1919 | - superblock-strip palette block(s) across {sb_strip_arms} arm(s), \ | ||
| 1920 | - {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \ | ||
| 1921 | - {refusals} refused ({sb_strip_refusals} superblock-strip palette)" | ||
| 1922 | - ); | ||
| 1923 | - assert!( | ||
| 1924 | - leaf8_total > 0 && fired_arms > 0, | ||
| 1925 | - "{NAME}: gate is vacuous -- no compared arm decoded an 8x8-leaf palette block" | ||
| 1926 | - ); | ||
| 1927 | - assert_eq!( | ||
| 1928 | - sb_strip_refusals, 0, | ||
| 1929 | - "{NAME}: the superblock-strip palette refusal is back (lane-t900 r34 lifted it)" | ||
| 1930 | - ); | ||
| 1931 | - assert!( | ||
| 1932 | - sb_strip_arms > 0 && sb_strip_total > 0, | ||
| 1933 | - "{NAME}: no arm decoded a non-skip palette block on a superblock-level strip -- \ | ||
| 1934 | - the shape r34 lifted is no longer exercised" | ||
| 1935 | - ); | ||
| 1936 | - assert_eq!( | ||
| 1937 | - out_of_scope_mismatch, 0, | ||
| 1938 | - "{NAME}: an out-of-scope arm mismatched ffmpeg -- a defect, never a skip" | ||
| 1939 | - ); | ||
| 1940 | - assert!( | ||
| 1941 | - frames_compared > 0, | ||
| 1942 | - "{NAME}: no frame was compared pixel-exact" | ||
| 1943 | - ); | ||
| 1944 | - } | ||
| 1945 | - | ||
| 1946 | - /// lane-av1toolgates: `enable-rect-tx` at 8 BITS. See | ||
| 1947 | - /// [`rect_tx_tool_gate`] for what the flag does and does not prove, and | ||
| 1948 | - /// why the recipe is spelled here rather than in the helper. | ||
| 1949 | - /// | ||
| 1950 | - /// The whole recipe is inline: `--passes=1` has to be findable in this | ||
| 1951 | - /// segment for the coverage derivation to count the gate at all, and | ||
| 1952 | - /// `--enable-rect-tx=1` has to be findable here for it to count the | ||
| 1953 | - /// TOOL. The quantiser and the tx-size-search setting are swept as two | ||
| 1954 | - /// arms so the witness cannot rest on one RD interaction. | ||
| 1955 | - #[test] | ||
| 1956 | - fn a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact() { | ||
| 1957 | - let mut totals = (0usize, 0usize); | ||
| 1958 | - for (cq, tx_search) in [("20", "1"), ("40", "0")] { | ||
| 1959 | - let args: Vec<String> = [ | ||
| 1960 | - "--codec=av1", | ||
| 1961 | - "--passes=1", | ||
| 1962 | - "--end-usage=q", | ||
| 1963 | - "--cpu-used=0", | ||
| 1964 | - "--threads=1", | ||
| 1965 | - "--row-mt=0", | ||
| 1966 | - "--lag-in-frames=0", | ||
| 1967 | - "--auto-alt-ref=0", | ||
| 1968 | - "--kf-max-dist=1000", | ||
| 1969 | - "--error-resilient=1", | ||
| 1970 | - "--sb-size=64", | ||
| 1971 | - // The tool under test, spelled explicitly. CONTEXT, per | ||
| 1972 | - // `rect_tx_tool_gate`: aomenc was ALLOWED rect tx sizes. | ||
| 1973 | - "--enable-rect-tx=1", | ||
| 1974 | - "--enable-rect-partitions=1", | ||
| 1975 | - "--enable-ab-partitions=0", | ||
| 1976 | - "--enable-1to4-partitions=0", | ||
| 1977 | - "--enable-restoration=0", | ||
| 1978 | - "--enable-palette=0", | ||
| 1979 | - "--enable-cdef=0", | ||
| 1980 | - "--enable-cfl-intra=0", | ||
| 1981 | - "--enable-intrabc=0", | ||
| 1982 | - "--enable-order-hint=0", | ||
| 1983 | - "--min-partition-size=8", | ||
| 1984 | - "--max-partition-size=32", | ||
| 1985 | - ] | ||
| 1986 | - .map(String::from) | ||
| 1987 | - .into_iter() | ||
| 1988 | - .chain([ | ||
| 1989 | - format!("--cq-level={cq}"), | ||
| 1990 | - format!("--enable-tx-size-search={tx_search}"), | ||
| 1991 | - ]) | ||
| 1992 | - // The output tail comes LAST: aomenc stops reading flags at the | ||
| 1993 | - // first bare argument, so a sweep flag appended after `-o - -` is | ||
| 1994 | - // silently dropped and the arm encodes a different recipe than the | ||
| 1995 | - // one this gate claims to have run. | ||
| 1996 | - .chain(["--obu", "-o", "-", "-"].map(String::from)) | ||
| 1997 | - .collect(); | ||
| 1998 | - let name = format!( | ||
| 1999 | - "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact[cq{cq}/tx{tx_search}]" | ||
| 2000 | - ); | ||
crates/ec-av1/src/stream/tests/t04.rsdeleted+0 -4516
Diff too large; view file
| @@ -1,4516 +0,0 @@ | |||
| 1 | -use super::*; | ||
| 2 | -use super::support::*; | ||
| 3 | -use super::gates_a::*; | ||
| 4 | -use crate::probe::run_with_stdin; | ||
| 5 | -use std::process::{Command, Stdio}; | ||
| 6 | - | ||
| 7 | - /// The 12-bit WARP witness (lane-av112bitw): the same source and recipe | ||
| 8 | - /// with the warp tools ON -- aomenc picks warp models on this content | ||
| 9 | - /// (measured pre-lift: the warp model fires at the third frame, and the | ||
| 10 | - /// decode refused by name at exactly that block) -- now decodes | ||
| 11 | - /// BYTE-EXACT against ffmpeg. The warp filter's shifts are the bumped | ||
| 12 | - /// `conv_params->round_0` (`warp::warp_round_0`, 5 at 12 bits, feeding | ||
| 13 | - /// `reduce_bits_horiz`, the derived non-compound | ||
| 14 | - /// `reduce_bits_vert = 2*FILTER_BITS - round_0` and both `offset_bits`), | ||
| 15 | - /// the whole libaom `get_conv_params_no_round` 12-bit bump. | ||
| 16 | - /// | ||
| 17 | - /// Non-vacuous: the same recipe refused by name before the lift, the | ||
| 18 | - /// gate hard-asserts a warp predictor was really resolved (a warpless | ||
| 19 | - /// stream would pass the pixel compare and prove nothing), and every | ||
| 20 | - /// plane of every frame compares against ffmpeg's decode. | ||
| 21 | - #[test] | ||
| 22 | - fn a_12bit_warped_motion_stream_decodes_pixel_exact() { | ||
| 23 | - const NAME: &str = "a_12bit_warped_motion_stream_decodes_pixel_exact"; | ||
| 24 | - let _gate_lock = lock_gate_counters(); | ||
| 25 | - if !have_ffmpeg() { | ||
| 26 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 27 | - return; | ||
| 28 | - } | ||
| 29 | - if !have_aomenc() { | ||
| 30 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 31 | - return; | ||
| 32 | - } | ||
| 33 | - let y4m = y4m_12bit_subpel_source(6); | ||
| 34 | - // Exactly the recipe measured to refuse at warp pre-lift: warp ON, | ||
| 35 | - // global motion NOT spelled (spelling it ON drives a GLOBAL_GLOBALMV | ||
| 36 | - // compound block into the compound-warp arm -- see the compound gate | ||
| 37 | - // below), six frames -- the warp model fires at the third frame. | ||
| 38 | - let stream = encode_12bit(&y4m, 6, &["--enable-warped-motion=1"]); | ||
| 39 | - assert_12bit_sequence_header(&stream, NAME); | ||
| 40 | - let (before_selected, before_warp8, before_affine) = ( | ||
| 41 | - decode::warp_selected_hits(), | ||
| 42 | - decode::warp_hits_8(), | ||
| 43 | - decode::affine_gm_hits(), | ||
| 44 | - ); | ||
| 45 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 46 | - panic!("{NAME}: decode_stream refused a real 12-bit warp stream: {e}") | ||
| 47 | - }); | ||
| 48 | - assert_eq!(frames.len(), 6); | ||
| 49 | - let (delta_selected, delta_warp8, delta_affine) = ( | ||
| 50 | - decode::warp_selected_hits() - before_selected, | ||
| 51 | - decode::warp_hits_8() - before_warp8, | ||
| 52 | - decode::affine_gm_hits() - before_affine, | ||
| 53 | - ); | ||
| 54 | - eprintln!( | ||
| 55 | - "{NAME}: warp_engagement selected(16x16+ symbol)={delta_selected} \ | ||
| 56 | - warped8(usable 8x8 model)={delta_warp8} affine_gm(6-param model)={delta_affine}" | ||
| 57 | - ); | ||
| 58 | - assert!( | ||
| 59 | - delta_selected + delta_warp8 + delta_affine > 0, | ||
| 60 | - "{NAME}: no warp predictor was resolved -- the stream carries no \ | ||
| 61 | - warp model and the pixel compare would prove nothing" | ||
| 62 | - ); | ||
| 63 | - let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 6); | ||
| 64 | - for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 65 | - assert_eq!( | ||
| 66 | - ours.y, reference.y, | ||
| 67 | - "frame {i} luma vs ffmpeg (12-bit warp)" | ||
| 68 | - ); | ||
| 69 | - assert_eq!(ours.u, reference.u, "frame {i} U vs ffmpeg (12-bit warp)"); | ||
| 70 | - assert_eq!(ours.v, reference.v, "frame {i} V vs ffmpeg (12-bit warp)"); | ||
| 71 | - } | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - /// The 12-bit COMPOUND witness (lane-av112bitc): the parent's source | ||
| 75 | - /// and recipe with warp pinned OFF -- with six frames LAST diverges | ||
| 76 | - /// from GOLDEN from frame 2 on and aomenc codes compound inter blocks | ||
| 77 | - /// (pre-lift measurement: the decode refused at the compound mode | ||
| 78 | - /// read). Two arms: the default recipe (dist-weighted average | ||
| 79 | - /// combines live) and `--enable-dist-wtd-comp=0` (pushes compound AND | ||
| 80 | - /// the masked choice harder: 6 diffwtd blends). Both byte-exact | ||
| 81 | - /// against ffmpeg; each hard-asserts compound mode symbols and | ||
| 82 | - /// masked-diffwtd blends really ran, so the parameterised combine | ||
| 83 | - /// rounds (`INTER_POST_ROUND - delta`, diffwtd `+ (bd-8) - delta` at | ||
| 84 | - /// 12 bits) and the ffmpeg-pinned pixel path genuinely executed. | ||
| 85 | - #[test] | ||
| 86 | - fn a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact() { | ||
| 87 | - const NAME: &str = "a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact"; | ||
| 88 | - let _gate_lock = lock_gate_counters(); | ||
| 89 | - if !have_ffmpeg() { | ||
| 90 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 91 | - return; | ||
| 92 | - } | ||
| 93 | - if !have_aomenc() { | ||
| 94 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 95 | - return; | ||
| 96 | - } | ||
| 97 | - let y4m = y4m_12bit_subpel_source(6); | ||
| 98 | - for (arm, extra) in [ | ||
| 99 | - ("dist-wtd", &["--enable-warped-motion=0"][..]), | ||
| 100 | - ( | ||
| 101 | - "plain-masked", | ||
| 102 | - &["--enable-warped-motion=0", "--enable-dist-wtd-comp=0"][..], | ||
| 103 | - ), | ||
| 104 | - ] { | ||
| 105 | - let stream = encode_12bit(&y4m, 6, extra); | ||
| 106 | - assert_12bit_sequence_header(&stream, NAME); | ||
| 107 | - let before_compound = decode::compound_mode_hits(); | ||
| 108 | - let before_masked = decode::masked_compound_hits(); | ||
| 109 | - let before_diffwtd = decode::diffwtd_hits(); | ||
| 110 | - let before_wedge = decode::wedge_hits(); | ||
| 111 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 112 | - panic!("{NAME} [{arm}]: decode_stream refused a real 12-bit compound stream: {e}") | ||
| 113 | - }); | ||
| 114 | - assert_eq!(frames.len(), 6, "{NAME} [{arm}]: frame count"); | ||
| 115 | - let (comp, masked, diffwtd, wedge) = ( | ||
| 116 | - decode::compound_mode_hits() - before_compound, | ||
| 117 | - decode::masked_compound_hits() - before_masked, | ||
| 118 | - decode::diffwtd_hits() - before_diffwtd, | ||
| 119 | - decode::wedge_hits() - before_wedge, | ||
| 120 | - ); | ||
| 121 | - eprintln!( | ||
| 122 | - "{NAME} [{arm}]: compound blocks={comp} masked={masked} diffwtd={diffwtd} wedge={wedge}" | ||
| 123 | - ); | ||
| 124 | - assert!( | ||
| 125 | - comp > 0, | ||
| 126 | - "{NAME} [{arm}]: no compound mode symbol was read -- the compound path is unexercised" | ||
| 127 | - ); | ||
| 128 | - assert!( | ||
| 129 | - masked > 0, | ||
| 130 | - "{NAME} [{arm}]: no masked compound block ran -- the masked combine is unexercised" | ||
| 131 | - ); | ||
| 132 | - assert!( | ||
| 133 | - diffwtd > 0, | ||
| 134 | - "{NAME} [{arm}]: no diffwtd blend ran -- the diffwtd combine is unexercised" | ||
| 135 | - ); | ||
| 136 | - let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 6); | ||
| 137 | - for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 138 | - assert_eq!( | ||
| 139 | - ours.y, reference.y, | ||
| 140 | - "{NAME} [{arm}] frame {i} luma vs ffmpeg" | ||
| 141 | - ); | ||
| 142 | - assert_eq!(ours.u, reference.u, "{NAME} [{arm}] frame {i} U vs ffmpeg"); | ||
| 143 | - assert_eq!(ours.v, reference.v, "{NAME} [{arm}] frame {i} V vs ffmpeg"); | ||
| 144 | - } | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - /// lane-av112bitg: the 12-bit film grain witness. A real | ||
| 149 | - /// `aomenc --bit-depth=12 --profile=2 --film-grain-test=5` stream -- grain | ||
| 150 | - /// params present AND applied (2 luma + 9 cb + 9 cr scaling points, | ||
| 151 | - /// overlap blending on, clip-to-restricted-range on; the second frame is | ||
| 152 | - /// an INTER frame that inherits the params via `update_grain = 0`) -- | ||
| 153 | - /// decoded byte-exact against ffmpeg's own 12-bit decode of the identical | ||
| 154 | - /// bytes (ffmpeg synthesizes grain by default; no grain-disable flag is | ||
| 155 | - /// passed anywhere in this file). Proves the bit-depth-generic grain path | ||
| 156 | - /// at 12 bits: `grain_range`'s ±(128 << 4) AR clamp and overlap-blend | ||
| 157 | - /// clamp, the `gauss_sec_shift = 12 - bd` Gaussian shift, the 4096-entry | ||
| 158 | - /// expanded scaling-LUT interpolation, and the `<< (bit_depth - 8)` | ||
| 159 | - /// chroma offsets and legal-range clamps. HARD-asserts the parsed headers | ||
| 160 | - /// really carry that coverage and `film_grain::grain_hits()` fired, so | ||
| 161 | - /// neither a params-without-apply stream nor a silently-skipped synthesis | ||
| 162 | - /// can pass vacuously. | ||
| 163 | - #[test] | ||
| 164 | - fn a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact() { | ||
| 165 | - const NAME: &str = "a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact"; | ||
| 166 | - let _gate_lock = lock_gate_counters(); | ||
| 167 | - if !have_ffmpeg() { | ||
| 168 | - eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 169 | - return; | ||
| 170 | - } | ||
| 171 | - if !have_aomenc() { | ||
| 172 | - eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 173 | - return; | ||
| 174 | - } | ||
| 175 | - let y4m = y4m_12bit_subpel_source(2); | ||
| 176 | - // Warp stays refused at 12 bits (lane-av112bitg lifts GRAIN only), so | ||
| 177 | - // the arm pins both motion tools off exactly once each -- aomenc | ||
| 178 | - // otherwise picks warped motion on this fixture's sub-pel motion. | ||
| 179 | - let stream = encode_12bit( | ||
| 180 | - &y4m, | ||
| 181 | - 2, | ||
| 182 | - &[ | ||
| 183 | - "--film-grain-test=5", | ||
| 184 | - "--enable-warped-motion=0", | ||
| 185 | - "--enable-global-motion=0", | ||
| 186 | - ], | ||
| 187 | - ); | ||
| 188 | - assert_12bit_sequence_header(&stream, NAME); | ||
| 189 | - // The arm is only honest if the stream itself carries the coverage: | ||
| 190 | - // grain applied on every frame, scaling points on all three planes, | ||
| 191 | - // overlap blending and restricted-range clipping on. | ||
| 192 | - let mut probe = Av1Parser::new(); | ||
| 193 | - let mut pos = 0usize; | ||
| 194 | - let mut grain_frames = 0usize; | ||
| 195 | - while pos < stream.len() { | ||
| 196 | - let obu = probe.parse_obu(&stream[pos..]).unwrap(); | ||
| 197 | - pos += obu.total_size; | ||
| 198 | - if let ObuKind::Frame(header, _) = obu.kind { | ||
| 199 | - let fg = &header.film_grain; | ||
| 200 | - assert!( | ||
| 201 | - fg.apply_grain, | ||
| 202 | - "{NAME}: frame without apply_grain -- aomenc emitted params it does not apply" | ||
| 203 | - ); | ||
| 204 | - assert!( | ||
| 205 | - fg.num_y_points > 0 && fg.num_cb_points > 0 && fg.num_cr_points > 0, | ||
| 206 | - "{NAME}: grain without all three planes' scaling points -- the bit-depth \ | ||
| 207 | - LUT math would not be exercised" | ||
| 208 | - ); | ||
| 209 | - assert!( | ||
| 210 | - fg.overlap_flag, | ||
| 211 | - "{NAME}: overlap off -- the grain_min/grain_max blend clamp is not exercised" | ||
| 212 | - ); | ||
| 213 | - assert!( | ||
| 214 | - fg.clip_to_restricted_range, | ||
| 215 | - "{NAME}: clip_to_restricted_range off -- the << (bd - 8) legal-range clamps \ | ||
| 216 | - are not exercised" | ||
| 217 | - ); | ||
| 218 | - grain_frames += 1; | ||
| 219 | - } | ||
| 220 | - } | ||
| 221 | - assert_eq!(grain_frames, 2, "{NAME}: expected grain on both frames"); | ||
| 222 | - let before = crate::film_grain::grain_hits(); | ||
| 223 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 224 | - panic!("{NAME}: decode_stream refused a real 12-bit grain stream: {e}") | ||
| 225 | - }); | ||
| 226 | - assert_eq!(frames.len(), 2); | ||
| 227 | - assert!( | ||
| 228 | - crate::film_grain::grain_hits() > before, | ||
| 229 | - "{NAME}: matched but zero grain_hits -- grain synthesis never ran" | ||
| 230 | - ); | ||
| 231 | - let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 2); | ||
| 232 | - for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 233 | - assert_eq!( | ||
| 234 | - ours.y, theirs.y, | ||
| 235 | - "{NAME}: luma vs ffmpeg (12-bit grain, frame {i})" | ||
| 236 | - ); | ||
| 237 | - assert_eq!( | ||
| 238 | - ours.u, theirs.u, | ||
| 239 | - "{NAME}: U vs ffmpeg (12-bit grain, frame {i})" | ||
crates/ec-av1/src/stream/tests/t05.rsdeleted+0 -4488
Diff too large; view file
crates/ec-av1/src/stream/tests/t06.rsdeleted+0 -4444
Diff too large; view file
crates/ec-av1/src/stream/tests/t07.rsdeleted+0 -4479
Diff too large; view file
crates/ec-av1/src/stream/tests/t08.rsdeleted+0 -4540
Diff too large; view file
crates/ec-av1/src/stream/tests/t09.rsdeleted+0 -4486
Diff too large; view file
crates/ec-av1/src/stream/tests/t10.rsdeleted+0 -4293
Diff too large; view file
crates/ec-av1/src/tile/tests.rsmodified+2 -114
Diff too large; view file
crates/ec-av1/src/tool_cache.rsdeleted+0 -326
Diff too large; view file
crates/ec-av1/tests/aom_conformance.rsmodified+2 -54
Diff too large; view file
crates/ec-av1/tests/real_library.rsmodified+13 -65
Diff too large; view file
crates/ec-av1/tests/yuv422_dav1d.rsmodified+3 -21
Diff too large; view file
scripts/build-aom-affine-oracle.shdeleted+0 -48
Diff too large; view file
scripts/build-aom-oracle.shdeleted+0 -56
Diff too large; view file
scripts/check-aom-oracle-rungs.shdeleted+0 -225
Diff too large; view file
scripts/instrument-aom-oracle.shdeleted+0 -1528
Diff too large; view file