diff --git a/crates/ec-aac/tests/oracle.rs b/crates/ec-aac/tests/oracle.rs index 7ddde830..eec0efb6 100644 --- a/crates/ec-aac/tests/oracle.rs +++ b/crates/ec-aac/tests/oracle.rs @@ -19,6 +19,30 @@ fn have_ffmpeg() -> bool { .unwrap_or(false) } +/// Fixture-presence probe for the committed `fixtures/audio` media this file +/// decodes. Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + /// ffmpeg's decode of a file, as planar-by-channel `f32`. fn ffmpeg_decode(path: &Path, channels: usize) -> Vec> { let out = Command::new("ffmpeg") @@ -128,8 +152,7 @@ fn adts_fixtures_match_ffmpeg_per_channel() { "aac-adts-5.1-48000.aac", ] { let path = dir.join(name); - if !path.exists() { - eprintln!("SKIP {name}: fixture missing"); + if !require_fixture(&path, "scripts/gen-fixtures.sh") { continue; } let corr = compare(&path); @@ -164,8 +187,7 @@ fn mp4_fixtures_match_ffmpeg_per_channel() { "aac-mp4-5.1-48000.mp4", ] { let path = dir.join(name); - if !path.exists() { - eprintln!("SKIP {name}: fixture missing"); + if !require_fixture(&path, "scripts/gen-fixtures.sh") { continue; } // The mp4 side of the family is another slice; the elementary stream @@ -209,8 +231,7 @@ fn aac_coding_tools_match_ffmpeg_in_isolation() { for tool in ["pns", "is", "ms", "tns", "all"] { let name = format!("aac-tool-{tool}-mp4-stereo-48000.m4a"); let path = dir.join(&name); - if !path.exists() { - eprintln!("SKIP {name}: fixture missing"); + if !require_fixture(&path, "scripts/gen-fixtures.sh") { continue; } let adts = tmp.join(format!("{name}.aac")); @@ -421,8 +442,7 @@ fn encoder_beats_the_incumbent_bar() { let mut checked = 0; for (name, channels, kbps, bar) in INCUMBENT_BAR { let src = dir.join(format!("flac-{name}-48000.flac")); - if !src.exists() { - eprintln!("SKIP {name}: fixture missing"); + if !require_fixture(&src, "scripts/gen-fixtures.sh") { continue; } let source = ffmpeg_decode(&src, *channels); @@ -801,8 +821,7 @@ fn aac_stream(path: &Path) -> Option<(usize, usize, String)> { #[test] fn five_one_decodes_faster_than_realtime() { let path = fixtures().join("audio/aac-adts-5.1-48000.aac"); - if !path.exists() { - eprintln!("SKIP: 5.1 fixture missing"); + if !require_fixture(&path, "scripts/gen-fixtures.sh") { return; } let data = std::fs::read(&path).expect("fixture readable"); diff --git a/crates/ec-aac/tests/sbr_real_library.rs b/crates/ec-aac/tests/sbr_real_library.rs index 6c27cf9e..13e15d20 100644 --- a/crates/ec-aac/tests/sbr_real_library.rs +++ b/crates/ec-aac/tests/sbr_real_library.rs @@ -38,6 +38,33 @@ fn have_ffmpeg() -> bool { .unwrap_or(false) } +/// Fixture-presence probe for the generated HE-AAC matrix under +/// `/.cache/heaac-fixtures` (`scripts/aac-tables/make-heaac-fixtures.sh`). +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. The `~/Music` / `~/Downloads` / `~/Videos` +/// scans in this file are host corpora, not the committed fixture library, and +/// keep their plain skip. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + /// A film's audio track is hours long; the correlation only needs a bounded /// window near the start, so both sides cap how much they ever decode. const MAX_SAMPLES: usize = 1_000_000; @@ -437,7 +464,13 @@ fn exhaustive_lag_correlation(ours: &[f32], theirs: &[f32], lag_max: i64) -> (i6 } /// bucket (true if ITS coarse lag sat at the +/-`lag_max` search bound). -fn robust_lag_topk(ours: &[f32], theirs: &[f32], lag_max: i64, rate: u32, k: usize) -> (i64, f64, bool) { +fn robust_lag_topk( + ours: &[f32], + theirs: &[f32], + lag_max: i64, + rate: u32, + k: usize, +) -> (i64, f64, bool) { const COARSE: usize = 4_096; let start = ours .len() @@ -2111,7 +2144,10 @@ fn our_decode_core_only(path: &Path, stream_index: usize) -> Option<(Vec = frame.samples.iter().skip(c).step_by(ch).copied().collect(); - let rms = (plane.iter().map(|v| f64::from(*v) * f64::from(*v)).sum::() + let rms = (plane + .iter() + .map(|v| f64::from(*v) * f64::from(*v)) + .sum::() / plane.len().max(1) as f64) .sqrt(); eprintln!( @@ -2229,7 +2265,11 @@ fn core_only_matches_reference() { if at_edge { (lag, corr, at_edge) = exhaustive_lag_correlation(&ol, &tl, SEARCH_LAG_MAX); } - let edge = if at_edge { " (AT SEARCH BOUND -- noise, not a measurement)" } else { "" }; + let edge = if at_edge { + " (AT SEARCH BOUND -- noise, not a measurement)" + } else { + "" + }; println!(" ch{ch}: below {cutoff:.0}Hz lag {lag}, corr {corr:.6}{edge}"); } } @@ -2428,15 +2468,10 @@ fn synthetic_heaac_matrix() { eprintln!("SKIP: ffmpeg not on PATH"); return; } - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let dir = PathBuf::from(dir); - if !dir.is_dir() { - eprintln!( - "SKIP: {} absent -- run scripts/aac-tables/make-heaac-fixtures.sh first", - dir.display() - ); + if !require_fixture(&dir, "scripts/aac-tables/make-heaac-fixtures.sh") { return; } unsafe { @@ -2444,14 +2479,31 @@ fn synthetic_heaac_matrix() { } println!( "{:>5} {:>6} {:>4} {:>4} {:>4} {:>8} {:>8} {:>8} {:>6} {:>11} {:>8} {:>10} {:>8} {:>9} {:>9}", - "rate", "kbps", "prof", "kx", "k2", "full", "below", "above", "lag", "ours_v_core", "ovc_lag", - "core_v_ref", "cvr_lag", "core_rate", "full_rate" + "rate", + "kbps", + "prof", + "kx", + "k2", + "full", + "below", + "above", + "lag", + "ours_v_core", + "ovc_lag", + "core_v_ref", + "cvr_lag", + "core_rate", + "full_rate" ); // Wide enough that the WIDE_LAG_MAX==LC's own decoder priming delay // (2048) plus a full SBR-chain worth of extra delay (a few thousand // samples at the doubled/full output rate) both land well inside it, // not right at the edge the way the plain (LAG_MAX=4000) search did. const WIDE_LAG_MAX: i64 = 20_000; + // Floor: the matrix is 2 rates x 4 bitrates x 2 profiles. Without a count + // the whole test is green having probed nothing, which is the same + // false-green this file's `require_fixture` exists to kill. + let mut probed = 0usize; for rate in [48_000u32, 44_100] { for br in ["32k", "48k", "64k", "96k"] { // LC first: its winning lag is the pure container/decoder @@ -2460,10 +2512,10 @@ fn synthetic_heaac_matrix() { let mut lc_lag: Option = None; for (profile, prefix) in [("LC", "lc"), ("HE", "heaac")] { let path = dir.join(format!("{prefix}_{rate}_{br}.m4a")); - if !path.exists() { - eprintln!("SKIP {}: missing", path.display()); + if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { continue; } + probed += 1; let before = ec_aac::sbr_sideinfo_log().len(); let Some((ours, _sbr, our_rate)) = our_decode(&path, 0) else { eprintln!("SKIP {}: could not decode", path.display()); @@ -2479,8 +2531,7 @@ fn synthetic_heaac_matrix() { let o = &ours[0]; let t = &theirs[0]; const TOPK: usize = 5; - let (mut lag, mut full, edge) = - robust_lag_topk(o, t, WIDE_LAG_MAX, our_rate, TOPK); + let (mut lag, mut full, edge) = robust_lag_topk(o, t, WIDE_LAG_MAX, our_rate, TOPK); assert!( !edge, "{}: {profile} row's refined winning lag {lag} sits at the \ @@ -2504,8 +2555,11 @@ fn synthetic_heaac_matrix() { if profile == "HE" && ours.len() >= 2 && theirs.len() >= 2 { let mono_o: Vec = ours[0].iter().zip(&ours[1]).map(|(a, b)| a + b).collect(); - let mono_t: Vec = - theirs[0].iter().zip(&theirs[1]).map(|(a, b)| a + b).collect(); + let mono_t: Vec = theirs[0] + .iter() + .zip(&theirs[1]) + .map(|(a, b)| a + b) + .collect(); let (mono_lag, _, mono_edge) = robust_lag_topk(&mono_o, &mono_t, WIDE_LAG_MAX, our_rate, TOPK); assert!( @@ -2548,7 +2602,9 @@ fn synthetic_heaac_matrix() { } else { ((-lag) as usize, 0usize) }; - let n = WINDOW.min(o.len().saturating_sub(oa)).min(t.len().saturating_sub(ob)); + let n = WINDOW + .min(o.len().saturating_sub(oa)) + .min(t.len().saturating_sub(ob)); let above = if n >= 1024 { correlation( &highpass(&o[oa..oa + n], our_rate, crossover_hz), @@ -2704,6 +2760,11 @@ fn synthetic_heaac_matrix() { } } } + assert!( + probed >= 16, + "only {probed} of 16 HE-AAC matrix fixtures were present -- rerun \ + scripts/aac-tables/make-heaac-fixtures.sh" + ); } fn candidates() -> Vec { @@ -2886,8 +2947,14 @@ fn sbr_real_library_matches_reference() { let high = if n >= 1024 { let oh = highpass(&o[oa..oa + n], rate, c.crossover_hz); let th = highpass(&t[ob..ob + n], rate, c.crossover_hz); - let rms = |v: &[f32]| (v.iter().map(|x| f64::from(*x).powi(2)).sum::() / v.len().max(1) as f64).sqrt(); - println!(" ch{ch} above-crossover RMS ours/ref = {:.4}", rms(&oh) / rms(&th).max(1e-12)); + let rms = |v: &[f32]| { + (v.iter().map(|x| f64::from(*x).powi(2)).sum::() / v.len().max(1) as f64) + .sqrt() + }; + println!( + " ch{ch} above-crossover RMS ours/ref = {:.4}", + rms(&oh) / rms(&th).max(1e-12) + ); correlation(&oh, &th) } else { 0.0 @@ -3154,7 +3221,10 @@ fn sbr_real_library_matches_reference() { ci += c.im; } let coh = (cr * cr + ci * ci).sqrt() / (eo * et).sqrt().max(1e-30); - println!(" band{band:>3}: {:>7.2} dB coh {coh:.4}", 10.0 * (eo / et.max(1e-30)).log10()); + println!( + " band{band:>3}: {:>7.2} dB coh {coh:.4}", + 10.0 * (eo / et.max(1e-30)).log10() + ); } } let mean_in = |rows: &[(usize, f64)], lo: usize, hi: usize| { @@ -3559,7 +3629,10 @@ fn sbr_actual_noise_fraction() { // has nonzero entries for QMF bands up to `k2`). let band_hz = f64::from(rate) / 128.0; let kx_band = bookkept.iter().map(|(b, ..)| *b).min().unwrap_or(0); - println!(" (crossover: QMF band {kx_band}, {:.0} Hz -- rows below it are core-decoded and excluded from the total)", kx_band as f64 * band_hz); + println!( + " (crossover: QMF band {kx_band}, {:.0} Hz -- rows below it are core-decoded and excluded from the total)", + kx_band as f64 * band_hz + ); println!( " ACTUAL noise fraction (band_hz, energy_on, energy_off, actual_fraction, bookkept_fraction):" ); @@ -3712,15 +3785,14 @@ fn sbr_header_feature_table() { ffmpeg_stream: c.ffmpeg_stream, }) .collect(); - let fixtures = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let fixtures = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let fixtures = PathBuf::from(fixtures); - if fixtures.is_dir() { + if require_fixture(&fixtures, "scripts/aac-tables/make-heaac-fixtures.sh") { for rate in [48_000u32, 44_100] { for br in ["32k", "48k", "64k", "96k"] { let p = fixtures.join(format!("heaac_{rate}_{br}.m4a")); - if p.exists() { + if require_fixture(&p, "scripts/aac-tables/make-heaac-fixtures.sh") { rows.push(Row { label: format!("synth-{rate}-{br}"), path: p, @@ -3730,11 +3802,6 @@ fn sbr_header_feature_table() { } } } - } else { - eprintln!( - "SKIP synthetic rows: {} absent -- run scripts/aac-tables/make-heaac-fixtures.sh first", - fixtures.display() - ); } if rows.is_empty() { eprintln!("SKIP: no real HE-AAC files and no synthetic fixtures found"); @@ -3746,8 +3813,25 @@ fn sbr_header_feature_table() { const WIDE_LAG_MAX: i64 = 20_000; println!( "{:<20} {:>6} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>5} {:>10} {:>10} {:>8} {:>8} {:>10} {:>6}", - "stream", "rate", "kx", "k2", "xovr", "sfrq", "efrq", "fscl", "ascl", "nbnd", "lbnd", "lgn", - "ifrq", "smooth", "envs", "invf", "harm", "df%", "corr" + "stream", + "rate", + "kx", + "k2", + "xovr", + "sfrq", + "efrq", + "fscl", + "ascl", + "nbnd", + "lbnd", + "lgn", + "ifrq", + "smooth", + "envs", + "invf", + "harm", + "df%", + "corr" ); for r in &rows { let before = ec_aac::sbr_sideinfo_log().len(); @@ -3760,7 +3844,11 @@ fn sbr_header_feature_table() { continue; } let log = ec_aac::sbr_sideinfo_log(); - let frames: Vec<_> = log[before..].iter().filter(|row| row.ch == 0).take(20).collect(); + let frames: Vec<_> = log[before..] + .iter() + .filter(|row| row.ch == 0) + .take(20) + .collect(); if frames.is_empty() { eprintln!("SKIP {}: no sideinfo rows captured", r.label); continue; @@ -3772,13 +3860,24 @@ fn sbr_header_feature_table() { let mut df_total = 0usize; let mut df_ones = 0usize; for row in &frames { - *env_counts.entry(row.t_env.len().saturating_sub(1)).or_default() += 1; + *env_counts + .entry(row.t_env.len().saturating_sub(1)) + .or_default() += 1; invf_seen.extend(&row.invf_mode); - if row.add_harmonic.as_ref().is_some_and(|h| h.iter().any(|&v| v != 0)) { + if row + .add_harmonic + .as_ref() + .is_some_and(|h| h.iter().any(|&v| v != 0)) + { any_harmonic = true; } df_total += row.df_env.len() + row.df_noise.len(); - df_ones += row.df_env.iter().chain(&row.df_noise).filter(|&&b| b != 0).count(); + df_ones += row + .df_env + .iter() + .chain(&row.df_noise) + .filter(|&&b| b != 0) + .count(); } let df_pct = if df_total > 0 { 100.0 * df_ones as f64 / df_total as f64 @@ -3790,20 +3889,36 @@ fn sbr_header_feature_table() { .map(|(k, v)| format!("{k}x{v}")) .collect::>() .join(","); - let invf_str: String = invf_seen.iter().map(|v| v.to_string()).collect::>().join(""); + let invf_str: String = invf_seen + .iter() + .map(|v| v.to_string()) + .collect::>() + .join(""); let theirs = ffmpeg_decode(&r.path, r.ffmpeg_stream, ours.len()); let (_, corr) = best_lag_correlation_wide(&ours[0], &theirs[0], WIDE_LAG_MAX); println!( "{:<20} {:>6} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>4} {:>5} {:>10} {:>10} {:>8} {:>8} {:>10.1} {:>6.3}", - r.label, our_rate, f0.kx, f0.k2, f0.xover_band, f0.start_freq, f0.stop_freq, - f0.freq_scale, f0.alter_scale, f0.noise_bands, f0.limiter_bands, f0.limiter_gains, - f0.interpol_freq, f0.smoothing_mode, envs_hist, invf_str, - any_harmonic, df_pct, corr - ); - println!( - " patches (frame0): {:?}", - f0.patch_lengths + r.label, + our_rate, + f0.kx, + f0.k2, + f0.xover_band, + f0.start_freq, + f0.stop_freq, + f0.freq_scale, + f0.alter_scale, + f0.noise_bands, + f0.limiter_bands, + f0.limiter_gains, + f0.interpol_freq, + f0.smoothing_mode, + envs_hist, + invf_str, + any_harmonic, + df_pct, + corr ); + println!(" patches (frame0): {:?}", f0.patch_lengths); } } @@ -3874,7 +3989,11 @@ fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) { } } if core_ch0.is_empty() || full_ch0.is_empty() { - eprintln!("SKIP {label}: empty decode (core {} full {})", core_ch0.len(), full_ch0.len()); + eprintln!( + "SKIP {label}: empty decode (core {} full {})", + core_ch0.len(), + full_ch0.len() + ); return; } @@ -3949,14 +4068,11 @@ fn per_au_low_band_divergence() { for c in &candidates() { per_au_low_band_probe(&c.path.display().to_string(), &c.path, c.aac_stream); } - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let failing = PathBuf::from(&dir).join("heaac_44100_48k.m4a"); - if failing.exists() { + if require_fixture(&failing, "scripts/aac-tables/make-heaac-fixtures.sh") { per_au_low_band_probe("synthetic 44100 48k (failing)", &failing, 0); - } else { - eprintln!("SKIP synthetic 44100 48k: {} absent", failing.display()); } } @@ -4003,7 +4119,20 @@ fn probe_explicit_config_and_wide_lag() { (planes, rate) } - for (label, path, aac_stream, ffmpeg_stream, core_sf_index, core_rate, ext_rate, channels) in [ + // `synthetic` marks the case as coming from the committed fixture library + // (`scripts/aac-tables/make-heaac-fixtures.sh`); the FMJ row is a + // `~/Downloads` host corpus and keeps its plain skip. + for ( + label, + path, + aac_stream, + ffmpeg_stream, + core_sf_index, + core_rate, + ext_rate, + channels, + synthetic, + ) in [ ( "FMJ", format!( @@ -4016,6 +4145,7 @@ fn probe_explicit_config_and_wide_lag() { 24_000u32, 48_000u32, 2u16, + false, ), ( "heaac_44100_48k", @@ -4029,10 +4159,15 @@ fn probe_explicit_config_and_wide_lag() { 44_100, 0, // filled below from parsed cfg's own extension_sample_rate 2, + true, ), ] { let path = PathBuf::from(path); - if !path.exists() { + if synthetic { + if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { + continue; + } + } else if !path.exists() { eprintln!("SKIP {label}: {} absent", path.display()); continue; } @@ -4097,7 +4232,9 @@ fn probe_explicit_config_and_wide_lag() { let theirs = ffmpeg_decode(&path, ffmpeg_stream, hand_planes.len()); if let (Some(o), Some(t)) = (hand_planes.first(), theirs.first()) { let (lag, corr) = best_lag_correlation_wide(o, t, 100_000); - println!(" hand-built explicit config: full-band vs reference: lag={lag} corr={corr:.6}"); + println!( + " hand-built explicit config: full-band vs reference: lag={lag} corr={corr:.6}" + ); } } @@ -4111,10 +4248,9 @@ fn probe_explicit_config_and_wide_lag() { "{home}/Downloads/reelp/reelp.mkv" )); if fmj.exists() { - if let (Some((core, core_rate)), Some((full, sbr, full_rate))) = ( - our_decode_core_only(&fmj, 1), - our_decode(&fmj, 1), - ) { + if let (Some((core, core_rate)), Some((full, sbr, full_rate))) = + (our_decode_core_only(&fmj, 1), our_decode(&fmj, 1)) + { if sbr == ec_aac::SbrSupport::V1 { let up: Vec = core[0].iter().flat_map(|&s| [s, s]).collect(); let cutoff = f64::from(core_rate) * 0.4; @@ -4239,12 +4375,10 @@ fn coupled_cpe_channel_swap_probe() { eprintln!("SKIP: ffmpeg not on PATH"); return; } - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let path = PathBuf::from(&dir).join("heaac_44100_48k.m4a"); - if !path.exists() { - eprintln!("SKIP: {} absent", path.display()); + if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { return; } let Some((ours, sbr, out_rate)) = our_decode(&path, 0) else { @@ -4256,7 +4390,10 @@ fn coupled_cpe_channel_swap_probe() { let ref_r = ffmpeg_decode_pan_channel(&path, 0, 1); { let n = ref_l.len().min(ref_r.len()).min(WINDOW); - println!("ref L vs ref R (no lag): corr={:.6}", correlation(&ref_l[..n], &ref_r[..n])); + println!( + "ref L vs ref R (no lag): corr={:.6}", + correlation(&ref_l[..n], &ref_r[..n]) + ); let (lag, corr) = best_lag_correlation_wide(&ref_l, &ref_r, SEARCH_LAG_MAX); println!("ref L vs ref R (best lag search): lag={lag} corr={corr:.6}"); } @@ -4329,11 +4466,17 @@ fn coupled_cpe_channel_swap_probe() { let (core_lag0, core_corr0) = best_lag_correlation_wide(&core_planes[0], &ref_core[0], SEARCH_LAG_MAX); let core_implied_lag = core_lag0 * 2; - println!("core ch0 vs ref L best lag={core_lag0} corr={core_corr0:.6} -> implied full-rate lag={core_implied_lag}"); + println!( + "core ch0 vs ref L best lag={core_lag0} corr={core_corr0:.6} -> implied full-rate lag={core_implied_lag}" + ); let mono_ours: Vec = ours[0].iter().zip(&ours[1]).map(|(a, b)| a + b).collect(); let mono_ref: Vec = { let n = ref_l.len().min(ref_r.len()); - ref_l[..n].iter().zip(&ref_r[..n]).map(|(a, b)| a + b).collect() + ref_l[..n] + .iter() + .zip(&ref_r[..n]) + .map(|(a, b)| a + b) + .collect() }; let (mono_lag, mono_corr) = best_lag_correlation_wide(&mono_ours, &mono_ref, SEARCH_LAG_MAX); println!("mono (ch0+ch1) vs ref (L+R) best lag={mono_lag} corr={mono_corr:.6}"); @@ -4349,7 +4492,15 @@ fn coupled_cpe_channel_swap_probe() { // corr=0.873 above). So the TRUE best lag among our 4 candidates is // whichever one actually maximizes the fixed-lag mono correlation, not // whatever `mono_lag` the free search reported. - let mut true_best = (mono_lag, "mono-best lag (free search)", 0.0f64, 0.0f64, 0.0f64, 0.0f64, mono_corr); + let mut true_best = ( + mono_lag, + "mono-best lag (free search)", + 0.0f64, + 0.0f64, + 0.0f64, + 0.0f64, + mono_corr, + ); for (lag, label) in fixed_lags { let c0l = correlation_at_lag(&ours[0], &ref_l, lag); let c0r = correlation_at_lag(&ours[0], &ref_r, lag); @@ -4398,7 +4549,9 @@ fn coupled_cpe_channel_swap_probe() { } let cl = correlation(&ours[0][oa..oa + step], &ref_l[ob..ob + step]); let cr = correlation(&ours[0][oa..oa + step], &ref_r[ob..ob + step]); - println!("subwindow t={w}s ch0 vs ref L/R @ lag {best_lag}: corr(L)={cl:.6} corr(R)={cr:.6}"); + println!( + "subwindow t={w}s ch0 vs ref L/R @ lag {best_lag}: corr(L)={cl:.6} corr(R)={cr:.6}" + ); w += 1; } } @@ -4569,15 +4722,18 @@ fn sbr441_family_sample_drift_probe() { eprintln!("SKIP: ffmpeg not on PATH"); return; } - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let home = std::env::var("HOME").unwrap_or_default(); - let cases: [(&str, PathBuf, i64); 3] = [ + // `synthetic` marks the rows served by the committed fixture library + // (`scripts/aac-tables/make-heaac-fixtures.sh`); the reeln control is + // a `~/Music` host corpus and keeps its plain skip. + let cases: [(&str, PathBuf, i64, bool); 3] = [ ( "heaac_44100_48k (FAIL family)", PathBuf::from(&dir).join("heaac_44100_48k.m4a"), -4674, + true, ), ( "heaac_48000_48k (48k control)", @@ -4586,6 +4742,7 @@ fn sbr441_family_sample_drift_probe() { // (below) -- 0 was a bad guess, true fixed lag is -4673, same // as the failing family's. -4673, + true, ), ( "reeln (44.1k control)", @@ -4595,11 +4752,16 @@ fn sbr441_family_sample_drift_probe() { // from an earlier probe, not its full-chain-vs-ffmpeg-reference // lag, which is +385. 385, + false, ), ]; - for (label, path, seed_lag) in cases { + for (label, path, seed_lag, synthetic) in cases { println!("\n=== {label}: {} ===", path.display()); - if !path.exists() { + if synthetic { + if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { + continue; + } + } else if !path.exists() { eprintln!("SKIP {label}: {} absent", path.display()); continue; } @@ -4690,12 +4852,10 @@ fn sbr_hf_window_band_probe() { eprintln!("SKIP: ffmpeg not on PATH"); return; } - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| { - format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR")) - }); + let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") + .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); let path = PathBuf::from(&dir).join("heaac_48000_64k.m4a"); - if !path.exists() { - eprintln!("SKIP: {} absent", path.display()); + if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { return; } const LAG: i64 = -4673; @@ -4748,7 +4908,10 @@ fn sbr_hf_window_band_probe() { let mean_t: f64 = mags_t.iter().sum::() / 8.0; println!( " band{band:>3}: |ours|dB mean={mean_o:>7.2} |ref|dB mean={mean_t:>7.2} dphase(deg)={:?}", - dphase_deg.iter().map(|d| format!("{d:.0}")).collect::>() + dphase_deg + .iter() + .map(|d| format!("{d:.0}")) + .collect::>() ); } } @@ -4803,7 +4966,9 @@ fn sbr_residual_locator() { if !path.exists() { return; } - let Some((ours, _, rate)) = our_decode(&path, 0) else { return }; + let Some((ours, _, rate)) = our_decode(&path, 0) else { + return; + }; let theirs = ffmpeg_decode(&path, 0, ours.len()); const W: usize = 2048; const FFT_LEN: usize = 2048; @@ -4815,7 +4980,12 @@ fn sbr_residual_locator() { let n = ours[ch].len().min(theirs[ch].len()); let (o, t) = (&ours[ch][..n], &theirs[ch][..n]); let mut wins: Vec<(f64, usize)> = (0..n / W) - .map(|w| (correlation(&o[w * W..(w + 1) * W], &t[w * W..(w + 1) * W]), w)) + .map(|w| { + ( + correlation(&o[w * W..(w + 1) * W], &t[w * W..(w + 1) * W]), + w, + ) + }) .collect(); wins.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); println!("ch{ch} worst windows (corr, frame): {:?}", &wins[..12]); @@ -4865,7 +5035,9 @@ fn sbr_residual_locator() { } } // group into 250 Hz bands up to 8 kHz, then 1 kHz - let mut edges: Vec = (0..=32).map(|i| ((i as f64 * 250.0) / hz) as usize).collect(); + let mut edges: Vec = (0..=32) + .map(|i| ((i as f64 * 250.0) / hz) as usize) + .collect(); edges.extend((9..=22).map(|i| ((i as f64 * 1000.0) / hz) as usize)); for e in edges.windows(2) { let (mut c, mut po, mut pt) = (0.0, 0.0, 0.0); diff --git a/crates/ec-flac/tests/encode_matrix.rs b/crates/ec-flac/tests/encode_matrix.rs index 8eebeabf..24a3180c 100644 --- a/crates/ec-flac/tests/encode_matrix.rs +++ b/crates/ec-flac/tests/encode_matrix.rs @@ -20,6 +20,30 @@ struct Source { bits: u32, } +/// Fixture-presence probe for the encoder matrix corpus. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + fn fixtures() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures") } @@ -124,7 +148,12 @@ fn matrix() -> Vec { let audio = fixtures().join("audio"); let vectors = fixtures().join("vectors/flac-xiph/flac-test-files-main/subset"); let mut paths: Vec = Vec::new(); - if let Ok(entries) = std::fs::read_dir(&audio) { + // Probe first, assert inside the helper, and only then take the empty-list + // branch: under EC_REQUIRE_FIXTURES the assert fires instead of a silent + // skip that leaves every loop below running zero times. + if require_fixture(&audio, "scripts/gen-fixtures.sh") { + let entries = std::fs::read_dir(&audio) + .unwrap_or_else(|e| panic!("read fixture dir {}: {e}", audio.display())); let mut found: Vec = entries .filter_map(|e| e.ok().map(|e| e.path())) .filter(|p| { @@ -136,13 +165,15 @@ fn matrix() -> Vec { paths.append(&mut found); } // Depth coverage the generated fixtures do not have: 24- and 20-bit. - for name in [ - "28 - high resolution audio, default settings.flac", - "37 - 20 bit per sample.flac", - ] { - let p = vectors.join(name); - if p.exists() { - paths.push(p); + if require_fixture(&vectors, "scripts/fetch-vectors.sh") { + for name in [ + "28 - high resolution audio, default settings.flac", + "37 - 20 bit per sample.flac", + ] { + let p = vectors.join(name); + if p.exists() { + paths.push(p); + } } } paths.iter().filter_map(|p| probe(p)).collect() @@ -155,6 +186,12 @@ fn encoded_streams_decode_back_bit_exact_through_ffmpeg() { eprintln!("skipped: fixtures not generated"); return; } + // Non-empty floor: the loop below must run, not zero times. + assert!( + sources.len() >= 5, + "encoder matrix holds {} usable sources, expected at least 5", + sources.len() + ); let dir = workdir("roundtrip"); let config = EncoderConfig::default(); let mut failures = Vec::new(); @@ -227,10 +264,18 @@ fn encoded_streams_decode_back_bit_exact_through_ffmpeg() { #[test] fn our_streams_survive_a_probe_and_state_their_shape() { - let Some(source) = matrix().into_iter().find(|s| s.channels == 6) else { - eprintln!("skipped: no 5.1 fixture"); + // The 5.1 source this test needs is a named fixture, not a shape we hope the + // matrix happens to contain: probe it first so EC_REQUIRE_FIXTURES fails on + // a drifted library instead of skipping. + let surround = fixtures().join("audio/flac-5.1-44100.flac"); + if !require_fixture(&surround, "scripts/gen-fixtures.sh") { return; - }; + } + let source = matrix() + .into_iter() + .find(|s| s.channels == 6) + .or_else(|| probe(&surround)) + .expect("5.1 source in the encoder matrix"); let dir = workdir("probe"); let pcm = ffmpeg_pcm(&source.path, source.bits); let samples = samples_from_pcm(&pcm, source.bits); diff --git a/crates/ec-flac/tests/xiph_vectors.rs b/crates/ec-flac/tests/xiph_vectors.rs index dcbbef53..f613f615 100644 --- a/crates/ec-flac/tests/xiph_vectors.rs +++ b/crates/ec-flac/tests/xiph_vectors.rs @@ -6,7 +6,11 @@ //! must be identical. Lossless codec, no tolerance. //! //! The corpus is fetched by `scripts/fetch-vectors.sh`; without it every test -//! here skips rather than fails, so a fresh clone still runs green. +//! here skips rather than fails, so a fresh clone still runs green. Set +//! `EC_REQUIRE_FIXTURES=1` to turn an absent or empty corpus into a hard +//! failure instead (class: gate-skips-on-its-own-failure; model `have_ffmpeg` +//! in crates/ec-av1/src/stream.rs, silently short-circuited because the probe +//! ran first in a compound `if`). //! //! Run the tables: //! cargo test -p ec-flac --release --test xiph_vectors -- --nocapture @@ -17,15 +21,47 @@ use std::process::Command; use ec_flac::checksum::md5_of_samples; use ec_flac::decode::FlacReader; +/// Fixture-presence probe for the Xiph FLAC corpus. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + fn corpus(kind: &str) -> Option> { let dir = Path::new(env!("CARGO_MANIFEST_DIR")) .join("../../fixtures/vectors/flac-xiph/flac-test-files-main") .join(kind); - let mut files: Vec = std::fs::read_dir(dir) - .ok()? - .filter_map(|e| e.ok().map(|e| e.path())) - .filter(|p| p.extension().is_some_and(|e| e == "flac")) - .collect(); + // Probe first, and never as part of the `ok()?` escape: a missing directory + // must assert under EC_REQUIRE_FIXTURES instead of short-circuiting the + // whole helper into a silent skip. + if !require_fixture(&dir, "scripts/fetch-vectors.sh") { + return None; + } + let mut files: Vec = match std::fs::read_dir(&dir) { + Ok(entries) => entries + .filter_map(|e| e.ok().map(|e| e.path())) + .filter(|p| p.extension().is_some_and(|e| e == "flac")) + .collect(), + Err(e) => panic!("read fixture dir {}: {e}", dir.display()), + }; files.sort(); match files.is_empty() { true => None, @@ -64,6 +100,12 @@ fn subset_vectors_decode_bit_exact_against_ffmpeg() { eprintln!("skipped: fixtures/vectors/flac-xiph not fetched"); return; }; + // Non-empty floor: a zero-file corpus would loop zero times and pass. + assert!( + files.len() >= 5, + "subset corpus holds {} .flac files, expected at least 5", + files.len() + ); let mut failures = Vec::new(); let mut passed = 0; for path in &files { @@ -135,6 +177,11 @@ fn uncommon_vectors_decode_bit_exact_or_refuse_by_name() { eprintln!("skipped: fixtures/vectors/flac-xiph not fetched"); return; }; + assert!( + files.len() >= 5, + "uncommon corpus holds {} .flac files, expected at least 5", + files.len() + ); let mut failures = Vec::new(); for path in &files { let bytes = std::fs::read(path).expect("read fixture"); @@ -170,6 +217,11 @@ fn faulty_vectors_error_and_never_panic() { eprintln!("skipped: fixtures/vectors/flac-xiph not fetched"); return; }; + assert!( + files.len() >= 5, + "faulty corpus holds {} .flac files, expected at least 5", + files.len() + ); // Faults our reader is expected to catch outright rather than decode past: // these break the structure a decoder must trust. let must_reject = ["06 - ", "07 - ", "08 - ", "09 - ", "11 - "]; @@ -196,6 +248,11 @@ fn seek_table_positions_the_reader_at_a_frame() { eprintln!("skipped: fixtures/vectors/flac-xiph not fetched"); return; }; + assert!( + files.len() >= 5, + "subset corpus holds {} .flac files, expected at least 5", + files.len() + ); // "48 - Extremely large SEEKTABLE" is the file with a seek table worth // exercising; any file carrying one proves the hook. let mut checked = 0; @@ -226,4 +283,10 @@ fn seek_table_positions_the_reader_at_a_frame() { } } println!("seek: {checked} files with a seek table exercised"); + // The loop skips every file without a seek table, so it can reach zero + // iterations even with a full corpus: floor the exercised count. + assert!( + checked >= 1, + "no subset fixture carried a SEEKTABLE, so the seek hook went unexercised" + ); } diff --git a/crates/ec-h264/tests/conformance.rs b/crates/ec-h264/tests/conformance.rs index c8b38314..67ff55d4 100644 --- a/crates/ec-h264/tests/conformance.rs +++ b/crates/ec-h264/tests/conformance.rs @@ -68,6 +68,47 @@ fn vectors_dir() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt") } +/// Fixture-presence probe for the JVT vector library these tests decode. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that populates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} +/// The same probe for one vector directory: `find_stream` returning `None` +/// means the JVT vector was extracted without its bitstream, which is a hole +/// in the fixture library and not a reason to test one vector fewer silently. +/// Probe first, assert unconditionally, return last — same order as +/// [`require_fixture`]. +fn require_stream(dir: &Path) -> Option { + let found = find_stream(dir); + assert!( + found.is_some() || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but {} holds no bitstream file -- regenerate with: scripts/fetch-vectors.sh", + dir.display() + ); + if found.is_none() { + eprintln!("SKIP: no bitstream file in {}", dir.display()); + } + found +} + /// Every vector directory `scripts/fetch-vectors.sh` has populated, in name /// order. /// @@ -76,6 +117,9 @@ fn vectors_dir() -> PathBuf { /// regressed from bit-exact to refused would be invisible. Walking the /// directory makes every fixture on disk a claim this test has to account for. fn all_vectors(base: &Path) -> Vec { + // Probe first, assert inside the helper, build the list last: a missing + // vector directory must not read as "zero vectors, nothing to check". + require_fixture(base, "scripts/fetch-vectors.sh"); let mut names: Vec = std::fs::read_dir(base) .into_iter() .flatten() @@ -102,6 +146,23 @@ fn find_stream(dir: &Path) -> Option { fallback } +/// Same shape for a file the JVT vector is supposed to carry besides its +/// bitstream: the reference decoder YUV. Every vector `scripts/fetch-vectors.sh` +/// populates ships one, so its absence is a hole in the fixture library, not a +/// licence to verify that vector against nothing. +fn require_ref_yuv(dir: &Path) -> Option { + let found = find_ref_yuv(dir); + assert!( + found.is_some() || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but {} holds no reference YUV -- regenerate with: scripts/fetch-vectors.sh", + dir.display() + ); + if found.is_none() { + eprintln!("SKIP: no reference YUV in {}", dir.display()); + } + found +} + fn find_ref_yuv(dir: &Path) -> Option { for entry in std::fs::read_dir(dir).ok()? { let p = entry.ok()?.path(); @@ -289,11 +350,7 @@ fn compare_sequence(stream: &Path) -> Result { #[test] fn jvt_cavlc_first_idr_bit_exact() { let base = vectors_dir(); - if !base.is_dir() { - eprintln!( - "SKIP: {} missing — run scripts/fetch-vectors.sh", - base.display() - ); + if !require_fixture(&base, "scripts/fetch-vectors.sh") { return; } let mut passed = Vec::new(); @@ -302,8 +359,7 @@ fn jvt_cavlc_first_idr_bit_exact() { for name in all_vectors(&base) { let name = name.as_str(); let dir = base.join(name); - let Some(stream) = find_stream(&dir) else { - eprintln!("SKIP {name}: no bitstream file"); + let Some(stream) = require_stream(&dir) else { continue; }; let bytes = std::fs::read(&stream).unwrap(); @@ -312,7 +368,7 @@ fn jvt_cavlc_first_idr_bit_exact() { let frame_len = w * h * 3 / 2; // Oracle 1: reference decoder YUV, first frame. let mut ok = true; - if let Some(ref_path) = find_ref_yuv(&dir) { + if let Some(ref_path) = require_ref_yuv(&dir) { let reference = std::fs::read(&ref_path).unwrap(); assert!( reference.len() >= frame_len, @@ -396,14 +452,13 @@ fn jvt_cavlc_first_idr_bit_exact() { #[test] fn steady_state_decode_loop_zero_alloc() { let base = vectors_dir(); - if !base.is_dir() { - eprintln!("SKIP: fixtures missing"); + if !require_fixture(&base, "scripts/fetch-vectors.sh") { return; } // One stream per entropy coder, and one with B slices and multiple // reference frames so the decoded picture buffer really recycles pictures. for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] { - let Some(stream) = find_stream(&base.join(name)) else { + let Some(stream) = require_stream(&base.join(name)) else { continue; }; let bytes = std::fs::read(stream).unwrap(); @@ -480,10 +535,11 @@ fn steady_state_decode_loop_zero_alloc() { #[test] fn ns_per_macroblock_measurement() { let base = vectors_dir(); - if !base.is_dir() { - eprintln!("SKIP: fixtures missing"); + if !require_fixture(&base, "scripts/fetch-vectors.sh") { return; } + + let mut measured = 0usize; for name in [ "BA1_Sony_D", "CI_MW_D", @@ -491,7 +547,7 @@ fn ns_per_macroblock_measurement() { "CABA1_SVA_B", "CABA3_SVA_B", ] { - let Some(stream) = find_stream(&base.join(name)) else { + let Some(stream) = require_stream(&base.join(name)) else { continue; }; let bytes = std::fs::read(stream).unwrap(); @@ -520,7 +576,11 @@ fn ns_per_macroblock_measurement() { "PERF {name}: {w}x{h}, {mbs} MBs, {ns_per_mb:.0} ns/MB, {mpx_s:.1} Mpx/s \ (intra IDR, single thread, deblock included, output copy excluded)" ); + measured += 1; } + // A run that measured nothing printed no number and proved nothing: the + // floor keeps a fixture-less host from reporting PASS for it. + assert!(measured > 0, "no vector was measured: {measured}"); perf_whole_sequence(); } @@ -529,7 +589,7 @@ fn ns_per_macroblock_measurement() { fn perf_whole_sequence() { let base = vectors_dir(); for name in ["BA_MW_D", "CABA3_SVA_B", "MR1_BT_A"] { - let Some(stream) = find_stream(&base.join(name)) else { + let Some(stream) = require_stream(&base.join(name)) else { continue; }; let bytes = std::fs::read(stream).unwrap(); @@ -564,8 +624,7 @@ fn perf_whole_sequence() { #[test] fn corrupt_streams_never_panic() { let base = vectors_dir(); - if !base.is_dir() { - eprintln!("SKIP: fixtures missing"); + if !require_fixture(&base, "scripts/fetch-vectors.sh") { return; } // One stream per entropy coder, plus one with B slices and multiple @@ -573,12 +632,17 @@ fn corrupt_streams_never_panic() { // arrays from stream-derived values, and inter prediction indexes the // decoded picture buffer, the reference lists and the motion arrays from // them too. All of it needs the same no-panic floor as the CAVLC tables. + let mut swept = 0usize; for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B", "BA_MW_D"] { - let Some(stream) = find_stream(&base.join(name)) else { + let Some(stream) = require_stream(&base.join(name)) else { continue; }; corrupt_sweep(&std::fs::read(stream).unwrap()); + swept += 1; } + // A sweep over zero streams never panics because it never decodes + // anything; the invariant is only proven by real inputs. + assert!(swept > 0, "no vector streams were swept: {swept}"); } /// Truncate and bit-flip `bytes` many ways; every decode must return, error or @@ -1070,8 +1134,7 @@ fn p_only_gop_matches_ffmpeg_every_frame() { #[test] fn jvt_full_sequence_bit_exact() { let base = vectors_dir(); - if !base.is_dir() { - eprintln!("SKIP: {} missing", base.display()); + if !require_fixture(&base, "scripts/fetch-vectors.sh") { return; } let mut table = String::new(); @@ -1080,7 +1143,7 @@ fn jvt_full_sequence_bit_exact() { let mut failed = Vec::new(); for name in all_vectors(&base) { let dir = base.join(&name); - let Some(stream) = find_stream(&dir) else { + let Some(stream) = require_stream(&dir) else { continue; }; let bytes = std::fs::read(&stream).unwrap(); @@ -1090,7 +1153,7 @@ fn jvt_full_sequence_bit_exact() { } Ok(frames) => { let len = frames[0].len(); - let Some(ref_path) = find_ref_yuv(&dir) else { + let Some(ref_path) = require_ref_yuv(&dir) else { table.push_str(&format!( "{name:<16} {:>3} frames, no reference YUV\n", frames.len() @@ -1159,6 +1222,13 @@ fn jvt_full_sequence_bit_exact() { failed.len() ); assert!(failed.is_empty(), "{failed:#?}"); + // `failed.is_empty()` over a loop that can run zero times is vacuously + // green; the floor is the one its first-IDR sibling at the top of this + // file already carries. + assert!( + passed >= 5, + "fewer than 5 full-sequence JVT conformance streams verified bit-exact: {passed}" + ); } /// Decode a whole stream in decode order rather than display order. @@ -1850,10 +1920,10 @@ fn real_library_streams_match_ffmpeg() { } let manifest = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv"); - let Ok(text) = std::fs::read_to_string(&manifest) else { - eprintln!("SKIP: {} missing", manifest.display()); + if !require_fixture(&manifest, "scripts/scan-real-library.sh") { return; - }; + } + let text = std::fs::read_to_string(&manifest).expect("manifest reads"); let dir = scratch("real-library"); const FRAMES: usize = 500; /// A file counts as swept only when the oracle stayed with us this long. @@ -2313,8 +2383,7 @@ fn h264_seek_matches_linear_open_gop() { return; } let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/video/h264-open-gop.mp4"); - if !src.is_file() { - eprintln!("SKIP: no fixtures/video/h264-open-gop.mp4 (run scripts/gen-fixtures.sh)"); + if !require_fixture(&src, "scripts/gen-fixtures.sh") { return; } let dir = scratch("open-gop"); diff --git a/crates/ec-h264/tests/encode.rs b/crates/ec-h264/tests/encode.rs index 6e82eae0..54472a26 100644 --- a/crates/ec-h264/tests/encode.rs +++ b/crates/ec-h264/tests/encode.rs @@ -435,6 +435,30 @@ fn have_ffmpeg() -> bool { .is_ok_and(|s| s.success()) } +/// Fixture-presence probe for ``. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + /// Decode an Annex B stream with ffmpeg, returning one I420 triple per picture. fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option> { // Distinct per call, not per process: several #[test]s in this binary @@ -702,10 +726,10 @@ fn real_library_frames_encode_and_decode_exactly() { } let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("../../fixtures/real-library-manifest.tsv"); - let Ok(text) = std::fs::read_to_string(&manifest) else { - eprintln!("SKIP real_library_frames: {} missing", manifest.display()); + if !require_fixture(&manifest, "scripts/scan-real-library.sh") { return; - }; + } + let text = std::fs::read_to_string(&manifest).expect("manifest reads"); // The first 8-bit 4:2:0 H.264 mp4 of at least 720p in the manifest. let mut source = None; for line in text.lines().skip(1) { @@ -726,6 +750,14 @@ fn real_library_frames_encode_and_decode_exactly() { break; } let Some((path, w, h)) = source else { + // A manifest with no qualifying row is a corpus that drifted, not a + // reason to report PASS for a sweep that never ran. + assert!( + std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but {} lists no H.264 4:2:0 mp4 of at least \ + 720p -- regenerate with: scripts/scan-real-library.sh", + manifest.display() + ); eprintln!("SKIP real_library_frames: no H.264 4:2:0 mp4 in the manifest"); return; }; diff --git a/crates/ec-mp3/tests/encode_matrix.rs b/crates/ec-mp3/tests/encode_matrix.rs index 0342de24..73a45b25 100644 --- a/crates/ec-mp3/tests/encode_matrix.rs +++ b/crates/ec-mp3/tests/encode_matrix.rs @@ -45,6 +45,30 @@ fn fixtures() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures") } +/// Fixture-presence probe for the encoder matrix corpus. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + fn workdir(test: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!("ec-mp3-{}-{test}", std::process::id())); std::fs::create_dir_all(&dir).expect("create work dir"); @@ -360,11 +384,15 @@ fn vbr_mean_bitrate_tracks_quality_on_music() { #[test] fn encodes_above_the_incumbent_bar() { let dir = fixtures().join("audio"); + // Probe first, assert inside the helper, and only then take the empty-list + // branch: under EC_REQUIRE_FIXTURES the assert fires instead of a silent + // skip that leaves every row below running zero times. + if !require_fixture(&dir, "scripts/gen-fixtures.sh") { + return; + } let mut sources: Vec = std::fs::read_dir(&dir) - .into_iter() - .flatten() - .flatten() - .map(|e| e.path()) + .unwrap_or_else(|e| panic!("read fixture dir {}: {e}", dir.display())) + .filter_map(|e| e.ok().map(|e| e.path())) .filter(|p| { let name = p.file_name().map(|n| n.to_string_lossy().to_string()); name.is_some_and(|n| n.starts_with("wav16-") || n.starts_with("mp3src-")) @@ -376,10 +404,17 @@ fn encodes_above_the_incumbent_bar() { let name = p.file_name().unwrap().to_string_lossy().to_string(); name.contains("mono") || name.contains("stereo") }); - if sources.is_empty() { - eprintln!("no WAV fixtures: run scripts/gen-fixtures.sh"); - return; - } + // The corpus is eight committed WAVs (four `mp3src-*`, four `wav16-*`), + // all produced by `scripts/gen-fixtures.sh`. Fewer than all eight means + // the library drifted, not that the rows passed. + assert!( + sources.len() >= 8, + "only {} of the 8 mp3 encoder-matrix WAV fixtures are present in {} -- \ + regenerate with: scripts/gen-fixtures.sh", + sources.len(), + dir.display() + ); + let mut decoded_rows = 0usize; let work = workdir("encode"); println!( "{:<30} {:>5} {:>6} {:>3} {:>9} {:>8} {:>9}", @@ -390,6 +425,7 @@ fn encodes_above_the_incumbent_bar() { let Some((pcm, rate, channels)) = read_wav(source) else { continue; }; + decoded_rows += 1; for kbps in BITRATES { let bar = bar_for(&source.file_name().unwrap().to_string_lossy(), kbps); let bytes = encode(&pcm, rate, channels, kbps); @@ -455,6 +491,14 @@ fn encodes_above_the_incumbent_bar() { } } } + // A present-but-unreadable WAV takes the `read_wav` skip above, so the + // corpus count alone would leave this green having measured nothing. + assert!( + decoded_rows == sources.len(), + "only {decoded_rows} of {} fixtures decoded; a present fixture that \ + ffmpeg cannot read is a broken fixture, not a passing row", + sources.len() + ); assert!(failures.is_empty(), "{failures:#?}"); } diff --git a/crates/ec-opus/tests/conformance.rs b/crates/ec-opus/tests/conformance.rs index 6437aa9c..645a0108 100644 --- a/crates/ec-opus/tests/conformance.rs +++ b/crates/ec-opus/tests/conformance.rs @@ -87,6 +87,62 @@ fn vectors_dir() -> PathBuf { .join("../../fixtures/vectors/opus-rfc6716/opus_testvectors") } +/// Fixture-presence probe for the fixtures these tests read. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + +/// Presence probe for a HOST media file (`~/Music/...`, `~/Downloads/...`). +/// Deliberately NOT [`require_fixture`]: those paths are a developer's +/// personal corpus, not the committed fixture library, so `EC_REQUIRE_FIXTURES` +/// must not turn one person's home directory into a red suite on every other +/// host. It skips, and says so. +fn require_host_media(path: &Path, tag: &str) -> bool { + let present = path.exists(); + if !present { + eprintln!("SKIP {tag}: host media file {} absent", path.display()); + } + present +} + +/// An RFC 6716 test vector, probed through [`require_fixture`]. `None` means +/// absent (and already reported, or already asserted). +fn vector(name: &str) -> Option { + let path = vectors_dir().join(format!("{name}.bit")); + match require_fixture(&path, "scripts/fetch-vectors.sh") { + true => Some(path), + false => None, + } +} + +/// One of the generated `fixtures/audio` files, probed the same way. +fn audio_fixture(name: &str) -> Option { + let path = fixture(name); + match require_fixture(&path, "scripts/gen-fixtures.sh") { + true => Some(path), + false => None, + } +} + /// Decodes a vector at 48 kHz stereo, returning the samples and how many /// packets ended with the reference range state. fn decode_vector(packets: &[VectorPacket]) -> (Vec, usize, usize) { @@ -413,12 +469,12 @@ const VECTORS: [&str; 12] = [ #[test] fn rfc6716_test_vectors() { let mut table = Vec::new(); + let mut ran = 0usize; for name in VECTORS { - let path = vectors_dir().join(format!("{name}.bit")); - if !path.exists() { - eprintln!("{name}: missing, skipped (run scripts/fetch-vectors.sh)"); + let Some(path) = vector(name) else { continue; - } + }; + ran += 1; let packets = read_vector(&path); let (pcm, matched, decoded) = decode_vector(&packets); let reference = read_i16(&vectors_dir().join(format!("{name}.dec"))); @@ -446,6 +502,13 @@ fn rfc6716_test_vectors() { "{name}: opus_compare quality {quality:.2} %" ); } + // Non-empty floor: without a vector the loop above runs zero times and the + // table prints nothing at all. + assert!( + ran >= 5, + "only {ran} of {} RFC 6716 vectors were exercised, expected at least 5", + VECTORS.len() + ); for line in table { println!("{line}"); } @@ -606,16 +669,16 @@ fn ogg_opus_fixtures_match_ffmpeg() { // Mapping family 1 puts 5.1 in Vorbis order; ffmpeg hands its own order // back, so the comparison permutes one into the other. const VORBIS_TO_FFMPEG_5_1: [usize; 6] = [0, 2, 1, 4, 5, 3]; + let mut ran = 0usize; for (name, channels) in [ ("opus-ogg-mono-48000.opus", 1usize), ("opus-ogg-stereo-48000.opus", 2), ("opus-ogg-5.1-48000.opus", 6), ] { - let path = fixture(name); - if !path.exists() { - eprintln!("{name}: missing, skipped (run scripts/gen-fixtures.sh)"); + let Some(path) = audio_fixture(name) else { continue; - } + }; + ran += 1; let Some(reference) = ffmpeg_decode(&path, channels) else { eprintln!("{name}: ffmpeg unavailable, skipped"); continue; @@ -642,6 +705,11 @@ fn ogg_opus_fixtures_match_ffmpeg() { "{name}: worst channel correlation {worst:.5}" ); } + // Non-empty floor: the loop above must have compared something. + assert!( + ran >= 2, + "only {ran} of 3 Ogg-Opus fixtures were compared against ffmpeg, expected at least 2" + ); } #[test] @@ -653,11 +721,9 @@ fn five_one_channels_land_in_the_right_places() { // Vorbis-order output is the reference's 5.1-order output permuted. const VORBIS_TO_FFMPEG_5_1: [usize; 6] = [0, 2, 1, 4, 5, 3]; const TONES: [f64; 6] = [220.0, 440.0, 660.0, 55.0, 880.0, 1320.0]; - let path = fixture("opus-ogg-5.1-48000.opus"); - if !path.exists() { - eprintln!("5.1 fixture missing, skipped"); + let Some(path) = audio_fixture("opus-ogg-5.1-48000.opus") else { return; - } + }; let Some(reference) = ffmpeg_decode(&path, 6) else { eprintln!("ffmpeg unavailable, skipped"); return; @@ -694,14 +760,15 @@ fn decode_speed() { eprintln!("decode speed is only meaningful in release; skipped"); return; } + let mut measured = 0usize; for (name, channels) in [ ("opus-ogg-stereo-48000.opus", 2usize), ("opus-ogg-5.1-48000.opus", 6), ] { - let path = fixture(name); - if !path.exists() { + let Some(path) = audio_fixture(name) else { continue; - } + }; + measured += 1; let data = fs::read(&path).unwrap(); let packets = ogg_packets(&data); let head = parse_opus_head(&packets[0]); @@ -734,11 +801,17 @@ fn decode_speed() { "{name}: {realtime:.0}x realtime is below the {floor}x floor" ); } + // Non-empty floor: with both fixtures absent the loop measured nothing and + // every speed floor above went unexercised. + assert!( + measured >= 1, + "no Ogg-Opus fixture was measured, so the decode-speed floor went untested" + ); // The fixtures are sine tones, which are cheap; testvector01 is real music // at a high rate and is the honest stereo number. - let path = vectors_dir().join("testvector01.bit"); - if path.exists() { + let stereo_music = vector("testvector01"); + if let Some(path) = stereo_music { let packets = read_vector(&path); let mut dec = Decoder::new(48000, 2).unwrap(); let mut out = vec![0.0f32; 5760 * 2]; @@ -1595,7 +1668,14 @@ fn ogg_opus_round_trip_duration_is_exact() { let packets = encode_packets(&mut enc, &pcm, 2); let path = temp_path("duration.opus"); let pre_skip = enc.look_ahead(960); - write_ogg_opus(&path, &packets, opus_head(2, pre_skip as u16, None), 2, total, pre_skip as i64); + write_ogg_opus( + &path, + &packets, + opus_head(2, pre_skip as u16, None), + 2, + total, + pre_skip as i64, + ); let probe = Command::new("ffprobe") .args([ "-v", @@ -1849,8 +1929,7 @@ fn garbage_payloads_never_panic() { } } // Truncations of a real packet, which exercise the mid-frame paths. - let path = vectors_dir().join("testvector10.bit"); - if path.exists() { + if let Some(path) = vector("testvector10") { for p in read_vector(&path).iter().take(200) { for cut in 1..p.payload.len().min(64) { let _ = dec.decode_float(&p.payload[..cut], &mut out); @@ -2031,9 +2110,8 @@ fn aligned_corr(reference: &[f32], decoded: &[f32], max_lag: usize) -> (f64, usi #[test] fn silk_mono_nb_wb_roundtrip() { - let wav = fixture("wav16-mono-48000.wav"); let mut sources = vec![("synthetic", speech_like())]; - if wav.exists() { + if let Some(wav) = audio_fixture("wav16-mono-48000.wav") { let w = read_wav_mono(&wav); sources.push(("wav16-mono-48000", w[..w.len().min(96000)].to_vec())); } @@ -2380,7 +2458,14 @@ fn oracle_decode( return None; } let path = temp_path(&format!("{name}.opus")); - write_ogg_opus(&path, packets, opus_head(1, pre_skip as u16, None), 1, samples, pre_skip as i64); + write_ogg_opus( + &path, + packets, + opus_head(1, pre_skip as u16, None), + 1, + samples, + pre_skip as i64, + ); let out = Command::new("ffmpeg") .args(["-v", "warning", "-c:a", "libopus", "-i"]) .arg(&path) @@ -2398,9 +2483,8 @@ fn oracle_decode( } fn silk_sources() -> Vec<(&'static str, Vec)> { - let wav = fixture("wav16-mono-48000.wav"); let mut sources = vec![("synthetic", speech_like())]; - if wav.exists() { + if let Some(wav) = audio_fixture("wav16-mono-48000.wav") { let w = read_wav_mono(&wav); sources.push(("wav16-mono-48000", w[..w.len().min(96000)].to_vec())); } @@ -2557,7 +2641,10 @@ fn hybrid_layers_align() { (plb - phb).abs() <= 3, "layers misaligned: LB +{plb} vs HB +{phb}" ); - assert!((phb - delay).abs() <= 2, "HB peak +{phb}, look_ahead {delay}"); + assert!( + (phb - delay).abs() <= 2, + "HB peak +{phb}, look_ahead {delay}" + ); } /// 20 ms FB hybrid at 32 kbps: decodes in our decoder range-exactly, tracks @@ -2845,7 +2932,12 @@ fn ffmpeg_encode_libopus(src: &Path, kbps: u32, out: &Path, secs: f64) { /// file — and the correlation is computed inline without per-lag allocations. /// The delay lands the peak at a positive lag; the symmetric scan keeps the /// gate honest if a reference decoder shifts the other way. -fn align_to_source(source: &[f32], decoded: &[f32], channels: usize, max_lag: usize) -> (i32, Vec) { +fn align_to_source( + source: &[f32], + decoded: &[f32], + channels: usize, + max_lag: usize, +) -> (i32, Vec) { let sf = source.len() / channels; let df = decoded.len() / channels; let scan_frames = sf.min(df).min(48000 * 10); @@ -2881,7 +2973,11 @@ fn align_to_source(source: &[f32], decoded: &[f32], channels: usize, max_lag: us } // Build a source-length aligned copy using the chosen lag. let mut aligned = vec![0.0f32; sf * channels]; - let i0 = if best_lag < 0 { (-best_lag) as usize } else { 0 }; + let i0 = if best_lag < 0 { + (-best_lag) as usize + } else { + 0 + }; let j0 = if best_lag < 0 { 0 } else { best_lag as usize }; let len = sf.saturating_sub(i0).min(df.saturating_sub(j0)); for i in 0..len { @@ -3017,7 +3113,9 @@ fn reelm64_persecond_diag() { let (_, ours_aligned) = align_to_source(&source_pcm, &ours_dec, CHANNELS, MAX_LAG); // Per-second correlation for both - let n_frames = (source_frames).min(ours_aligned.len() / CHANNELS).min(ref_aligned.len() / CHANNELS); + let n_frames = (source_frames) + .min(ours_aligned.len() / CHANNELS) + .min(ref_aligned.len() / CHANNELS); let sec_samples = 48000usize; let frames_per_sec = sec_samples / FRAME; // 50 @@ -3034,11 +3132,19 @@ fn reelm64_persecond_diag() { let s = source_pcm[(start + i) * CHANNELS + ch] as f64; let o = ours_aligned[(start + i) * CHANNELS + ch] as f64; let r = ref_aligned[(start + i) * CHANNELS + ch] as f64; - sxy_o += s * o; sxx_o += s * s; syy_o += o * o; - sxy_r += s * r; sxx_r += s * s; syy_r += r * r; + sxy_o += s * o; + sxx_o += s * s; + syy_o += o * o; + sxy_r += s * r; + sxx_r += s * s; + syy_r += r * r; + } + if sxx_o > 0.0 && syy_o > 0.0 { + acc_o += sxy_o / (sxx_o * syy_o).sqrt(); + } + if sxx_r > 0.0 && syy_r > 0.0 { + acc_r += sxy_r / (sxx_r * syy_r).sqrt(); } - if sxx_o > 0.0 && syy_o > 0.0 { acc_o += sxy_o / (sxx_o * syy_o).sqrt(); } - if sxx_r > 0.0 && syy_r > 0.0 { acc_r += sxy_r / (sxx_r * syy_r).sqrt(); } } let co = acc_o / CHANNELS as f64; let cr = acc_r / CHANNELS as f64; @@ -3054,10 +3160,19 @@ fn reelm64_persecond_diag() { let mut out_str = String::new(); out_str.push_str("# reelm@64k per-second diagnostic (r1, current code)\n"); out_str.push_str("# 120s cap, 20ms frames, VBR constrained, 48kHz stereo\n"); - out_str.push_str(&format!("# total frames: ours={} ref={}\n", diags.len(), ref_payload.len())); + out_str.push_str(&format!( + "# total frames: ours={} ref={}\n", + diags.len(), + ref_payload.len() + )); let total_corr_o: f64 = sec_rows.iter().map(|r| r.1).sum::() / sec_rows.len() as f64; let total_corr_r: f64 = sec_rows.iter().map(|r| r.2).sum::() / sec_rows.len() as f64; - out_str.push_str(&format!("# avg corr: ours={:.4} ref={:.4} gap={:+.4}\n\n", total_corr_o, total_corr_r, total_corr_r - total_corr_o)); + out_str.push_str(&format!( + "# avg corr: ours={:.4} ref={:.4} gap={:+.4}\n\n", + total_corr_o, + total_corr_r, + total_corr_r - total_corr_o + )); // Per-second summary table out_str.push_str("# sec\tcorr_ours\tcorr_ref\tgap\tavg_trim\tdual_n\tint_typ\tavg_B_ours\tavg_B_ref\ttf_chng_n\ttrans_n\n"); @@ -3067,19 +3182,35 @@ fn reelm64_persecond_diag() { let sec_diags = &diags[f0..f1.min(diags.len())]; let avg_trim: f64 = if !sec_diags.is_empty() { sec_diags.iter().map(|d| d.alloc_trim as f64).sum::() / sec_diags.len() as f64 - } else { -1.0 }; + } else { + -1.0 + }; let dual_n = sec_diags.iter().filter(|d| d.dual_stereo).count(); let int_typ = if !sec_diags.is_empty() { sec_diags.iter().map(|d| d.intensity).max().unwrap_or(0) - } else { 0 }; + } else { + 0 + }; let avg_b_o: f64 = if !sec_diags.is_empty() { - sec_diags.iter().map(|d| d.nb_compressed as f64).sum::() / sec_diags.len() as f64 - } else { 0.0 }; + sec_diags + .iter() + .map(|d| d.nb_compressed as f64) + .sum::() + / sec_diags.len() as f64 + } else { + 0.0 + }; let ref_f0 = f0.min(ref_payload.len()); let ref_f1 = f1.min(ref_payload.len()); let avg_b_r: f64 = if ref_f1 > ref_f0 { - ref_payload[ref_f0..ref_f1].iter().map(|&b| b as f64).sum::() / (ref_f1 - ref_f0) as f64 - } else { 0.0 }; + ref_payload[ref_f0..ref_f1] + .iter() + .map(|&b| b as f64) + .sum::() + / (ref_f1 - ref_f0) as f64 + } else { + 0.0 + }; // tf_changed: count bands where tf_res != 0 (we don't have tf_res in diag, // but is_transient tells us if short blocks were used) let trans_n = sec_diags.iter().filter(|d| d.is_transient).count(); @@ -3103,10 +3234,23 @@ fn reelm64_persecond_diag() { let f5: Vec = (0..5).map(|i| format!("{}", d.fine_quant[i])).collect(); out_str.push_str(&format!( "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", - fi, fi * 20, d.nb_compressed, b_ref, - d.is_transient as u8, d.short_blocks, d.intra as u8, d.silence as u8, - d.lm, d.start, d.coded_bands, d.intensity, d.dual_stereo as u8, - d.alloc_trim, d.vbr_reservoir, p5.join(","), f5.join(",") + fi, + fi * 20, + d.nb_compressed, + b_ref, + d.is_transient as u8, + d.short_blocks, + d.intra as u8, + d.silence as u8, + d.lm, + d.start, + d.coded_bands, + d.intensity, + d.dual_stereo as u8, + d.alloc_trim, + d.vbr_reservoir, + p5.join(","), + f5.join(",") )); } out_str.push('\n'); @@ -3116,30 +3260,50 @@ fn reelm64_persecond_diag() { out_str.push_str("# --- global stats ---\n"); let trim_hist: Vec<(i32, usize)> = { let mut h = std::collections::HashMap::new(); - for d in &diags { *h.entry(d.alloc_trim).or_insert(0) += 1; } + for d in &diags { + *h.entry(d.alloc_trim).or_insert(0) += 1; + } let mut v: Vec<_> = h.into_iter().collect(); v.sort(); v }; out_str.push_str(&format!("# alloc_trim histogram: {:?}\n", trim_hist)); let dual_count = diags.iter().filter(|d| d.dual_stereo).count(); - out_str.push_str(&format!("# dual_stereo frames: {}/{}\n", dual_count, diags.len())); + out_str.push_str(&format!( + "# dual_stereo frames: {}/{}\n", + dual_count, + diags.len() + )); let trans_count = diags.iter().filter(|d| d.is_transient).count(); - out_str.push_str(&format!("# transient frames: {}/{}\n", trans_count, diags.len())); + out_str.push_str(&format!( + "# transient frames: {}/{}\n", + trans_count, + diags.len() + )); let intensity_hist: Vec<(usize, usize)> = { let mut h = std::collections::HashMap::new(); - for d in &diags { *h.entry(d.intensity).or_insert(0) += 1; } + for d in &diags { + *h.entry(d.intensity).or_insert(0) += 1; + } let mut v: Vec<_> = h.into_iter().collect(); v.sort(); v }; out_str.push_str(&format!("# intensity histogram: {:?}\n", intensity_hist)); - let avg_b_ours: f64 = diags.iter().map(|d| d.nb_compressed as f64).sum::() / diags.len() as f64; - let avg_b_ref: f64 = ref_payload.iter().map(|&b| b as f64).sum::() / ref_payload.len() as f64; - out_str.push_str(&format!("# avg bytes/frame: ours={:.1} ref={:.1}\n", avg_b_ours, avg_b_ref)); + let avg_b_ours: f64 = + diags.iter().map(|d| d.nb_compressed as f64).sum::() / diags.len() as f64; + let avg_b_ref: f64 = + ref_payload.iter().map(|&b| b as f64).sum::() / ref_payload.len() as f64; + out_str.push_str(&format!( + "# avg bytes/frame: ours={:.1} ref={:.1}\n", + avg_b_ours, avg_b_ref + )); let ours_kbps = ours_bytes.iter().map(|&b| b as f64).sum::() * 8.0 / seconds / 1000.0; let ref_kbps = ref_payload.iter().map(|&b| b as f64).sum::() * 8.0 / seconds / 1000.0; - out_str.push_str(&format!("# realised kbps: ours={:.1} ref={:.1}\n", ours_kbps, ref_kbps)); + out_str.push_str(&format!( + "# realised kbps: ours={:.1} ref={:.1}\n", + ours_kbps, ref_kbps + )); let out_path = lanes_dir.join("opus-64-r1.seconds.txt"); fs::write(&out_path, out_str).unwrap(); @@ -3160,7 +3324,10 @@ fn encoder_library_gate_vs_libopus() { ("reell", "~/Music/reell.mp4"), ("reelm", "~/Music/reelm.wav"), ("dl8a", "~/Downloads/8a3b6d1d19.mp3"), - ("hein", "~/Downloads/reelm.mp3"), + ( + "hein", + "~/Downloads/reelm.mp3", + ), ]; let only: Vec = std::env::var("SWEEP_ONLY") .unwrap_or_default() @@ -3183,12 +3350,14 @@ fn encoder_library_gate_vs_libopus() { let mut rows: Vec = Vec::new(); let mut rate_violations: Vec = Vec::new(); let mut dropout_violations: Vec = Vec::new(); + let mut swept = 0usize; for (tag, src) in &sources { - if !src.exists() { + if !require_host_media(src, tag) { eprintln!("SKIP {tag}: missing {}", src.display()); continue; } + swept += 1; let source_pcm = ffmpeg_decode_pcm(src, SECS); let source_frames = source_pcm.len() / CHANNELS; assert!(source_frames > 48_000, "{tag}: source too short"); @@ -3198,7 +3367,9 @@ fn encoder_library_gate_vs_libopus() { for &kbps in &[64u32, 96u32] { // Reference: ffmpeg libopus, VBR on, realised rate from file size. ffmpeg_encode_libopus(src, kbps, &scratch, SECS); - let ref_bytes = fs::metadata(&scratch).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&scratch) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let (ref_dec, ref_ch) = decode_ogg(&scratch); assert_eq!(ref_ch, CHANNELS, "{tag}@{kbps}: ref not stereo"); @@ -3206,8 +3377,7 @@ fn encoder_library_gate_vs_libopus() { // Ours: ec-opus encoder at the reference's realised rate, decoded // by our own decoder; payload bytes give the realised rate. - let mut enc = - Encoder::new(48000, CHANNELS, Application::Audio).expect("encoder"); + let mut enc = Encoder::new(48000, CHANNELS, Application::Audio).expect("encoder"); enc.set_bitrate((ref_kbps * 1000.0).round() as u32); enc.set_vbr_constrained(true); let (ours_dec, ours_bytes) = roundtrip_own(&mut enc, &source_pcm, CHANNELS, FRAME); @@ -3233,7 +3403,11 @@ fn encoder_library_gate_vs_libopus() { let q_ref = opus_compare(&s_i, &r_i, CHANNELS); let err_ours = opus_compare_err(&s_i, &o_i, CHANNELS); let err_ref = opus_compare_err(&s_i, &r_i, CHANNELS); - let err_ratio = if err_ref > 0.0 { err_ours / err_ref } else { f64::INFINITY }; + let err_ratio = if err_ref > 0.0 { + err_ours / err_ref + } else { + f64::INFINITY + }; let corr_ours = corr_interleaved(&source_pcm, &ours_aligned, CHANNELS); let corr_ref = corr_interleaved(&source_pcm, &ref_aligned, CHANNELS); @@ -3266,13 +3440,20 @@ fn encoder_library_gate_vs_libopus() { )); } } + // Non-empty floor: no source means the whole gate measured nothing. + assert!( + swept >= 1, + "no library-gate source was present, so the gate measured nothing" + ); let _ = fs::remove_file(&scratch); let mut table = String::new(); table.push_str("# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1)\n"); table.push_str("# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo\n"); - table.push_str("# source\tkbps\tours_kbps\tref_kbps\trate%\tcorr_ours\tcorr_ref\tgap\t\ - Q_ours\tQ_ref\terr_ratio\tminsec_ours\tminsec_ref\tdrop_ours\tdrop_ref\n"); + table.push_str( + "# source\tkbps\tours_kbps\tref_kbps\trate%\tcorr_ours\tcorr_ref\tgap\t\ + Q_ours\tQ_ref\terr_ratio\tminsec_ours\tminsec_ref\tdrop_ours\tdrop_ref\n", + ); for r in &rows { table.push_str(r); table.push('\n'); @@ -3335,8 +3516,18 @@ fn ffmpeg_decode_pcm_mono(path: &Path, secs: f64) -> Vec { .args(["-v", "error", "-i"]) .arg(path) .args([ - "-vn", "-t", &format!("{secs}"), "-ac", "1", "-ar", "48000", "-f", "f32le", - "-acodec", "pcm_f32le", "-", + "-vn", + "-t", + &format!("{secs}"), + "-ac", + "1", + "-ar", + "48000", + "-f", + "f32le", + "-acodec", + "pcm_f32le", + "-", ]) .output() .expect("ffmpeg runs"); @@ -3359,8 +3550,21 @@ fn ffmpeg_encode_libopus_mono_voip(src: &Path, kbps: u32, out: &Path, secs: f64) .args(["-y", "-v", "error", "-i"]) .arg(src) .args([ - "-vn", "-t", &format!("{secs}"), "-ac", "1", "-ar", "48000", "-c:a", "libopus", - "-application", "voip", "-b:a", &format!("{kbps}k"), "-vbr", "on", + "-vn", + "-t", + &format!("{secs}"), + "-ac", + "1", + "-ar", + "48000", + "-c:a", + "libopus", + "-application", + "voip", + "-b:a", + &format!("{kbps}k"), + "-vbr", + "on", ]) .arg(out) .output() @@ -3475,7 +3679,9 @@ fn silk_library_gate_vs_libopus() { // Reference: ffmpeg libopus, mono, voip, VBR; realised rate from size. ffmpeg_encode_libopus_mono_voip(&src, kbps, &ref_ogg, SECS); - let ref_bytes = fs::metadata(&ref_ogg).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&ref_ogg) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; // SYMMETRY: ref decoded through ffmpeg libopus (the reference decoder), // NOT our own decoder — so both sides cross the same decoder. (r1 used @@ -3526,17 +3732,24 @@ fn silk_library_gate_vs_libopus() { pre_skip, ); let ours_dec = ffmpeg_decode(&ours_ogg, CHANNELS).expect("ffmpeg libopus decode of ours"); - let ours_trim: Vec = ours_dec.into_iter().take(source_frames * CHANNELS).collect(); + let ours_trim: Vec = ours_dec + .into_iter() + .take(source_frames * CHANNELS) + .collect(); let (lag_ours, ours_aligned) = align_to_source(&source_pcm, &ours_trim, CHANNELS, MAX_LAG); // Own-decoder aligned (extra column: decoder drift visibility). - let ours_own_trim: Vec = - ours_own_dec.into_iter().take(source_frames * CHANNELS).collect(); + let ours_own_trim: Vec = ours_own_dec + .into_iter() + .take(source_frames * CHANNELS) + .collect(); let (_, ours_own_aligned) = align_to_source(&source_pcm, &ours_own_trim, CHANNELS, MAX_LAG); // LAG GATE: a lag at the scan bound is an invalid measurement, not a result. if (lag_ours as i64).abs() >= MAX_LAG as i64 { - lag_violations.push(format!("{tag}: ours lag {lag_ours} hit scan bound {MAX_LAG}")); + lag_violations.push(format!( + "{tag}: ours lag {lag_ours} hit scan bound {MAX_LAG}" + )); } if (lag_ref as i64).abs() >= MAX_LAG as i64 { lag_violations.push(format!("{tag}: ref lag {lag_ref} hit scan bound {MAX_LAG}")); @@ -3555,7 +3768,11 @@ fn silk_library_gate_vs_libopus() { let q_ref = opus_compare(&s_i, &r_i, CHANNELS); let err_ours = opus_compare_err(&s_i, &o_i, CHANNELS); let err_ref = opus_compare_err(&s_i, &r_i, CHANNELS); - let err_ratio = if err_ref > 0.0 { err_ours / err_ref } else { f64::INFINITY }; + let err_ratio = if err_ref > 0.0 { + err_ours / err_ref + } else { + f64::INFINITY + }; // Primary corr: band-limited reference. Secondary: full-band source. let corr_ours_bl = corr_interleaved(&ref_source, &ours_aligned, CHANNELS); @@ -3672,7 +3889,9 @@ fn silk_silkq_persecond_diag() { // Reference: ffmpeg libopus mono voip VBR at 12k; realised rate from size. ffmpeg_encode_libopus_mono_voip(&src, KBPS, &ref_ogg, SECS); - let ref_bytes = fs::metadata(&ref_ogg).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&ref_ogg) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let ref_dec = ffmpeg_decode(&ref_ogg, CHANNELS).expect("ffmpeg libopus decode of ref"); let ref_trim: Vec = ref_dec.into_iter().take(source_frames * CHANNELS).collect(); @@ -3711,11 +3930,16 @@ fn silk_silkq_persecond_diag() { let len = enc.encode_float(block, FRAME, &mut out).expect("encode"); let d = enc.last_silk_diag().cloned(); ours_bytes.push(len); - if let Some(d) = d { diags.push(d); } + if let Some(d) = d { + diags.push(d); + } let n = dec.decode_float(&out[..len], &mut buf).expect("decode"); ours_dec.extend_from_slice(&buf[..n * CHANNELS]); } - let ours_trim: Vec = ours_dec.into_iter().take(source_frames * CHANNELS).collect(); + let ours_trim: Vec = ours_dec + .into_iter() + .take(source_frames * CHANNELS) + .collect(); let (_, ours_aligned) = align_to_source(&source_pcm, &ours_trim, CHANNELS, MAX_LAG); // Per-second correlation ours vs ref against the full-band source (matches @@ -3736,11 +3960,23 @@ fn silk_silkq_persecond_diag() { let s = source_pcm[start + i] as f64; let o = ours_aligned[start + i] as f64; let r = ref_aligned[start + i] as f64; - sxy_o += s * o; sxx_o += s * s; syy_o += o * o; - sxy_r += s * r; sxx_r += s * s; syy_r += r * r; + sxy_o += s * o; + sxx_o += s * s; + syy_o += o * o; + sxy_r += s * r; + sxx_r += s * s; + syy_r += r * r; } - let co = if sxx_o > 0.0 && syy_o > 0.0 { sxy_o / (sxx_o * syy_o).sqrt() } else { 0.0 }; - let cr = if sxx_r > 0.0 && syy_r > 0.0 { sxy_r / (sxx_r * syy_r).sqrt() } else { 0.0 }; + let co = if sxx_o > 0.0 && syy_o > 0.0 { + sxy_o / (sxx_o * syy_o).sqrt() + } else { + 0.0 + }; + let cr = if sxx_r > 0.0 && syy_r > 0.0 { + sxy_r / (sxx_r * syy_r).sqrt() + } else { + 0.0 + }; sec_rows.push((sec_idx, co, cr, cr - co)); start += sec_samples; sec_idx += 1; @@ -3752,13 +3988,20 @@ fn silk_silkq_persecond_diag() { let mut out_str = String::new(); out_str.push_str("# reelm@12k SILK per-second diagnostic (r1)\n"); out_str.push_str("# mono, 120s cap, 20ms frames, VBR constrained, 48kHz, Application::Voip\n"); - out_str.push_str(&format!("# total frames: ours={} ref={}\n", diags.len(), ref_payload.len())); + out_str.push_str(&format!( + "# total frames: ours={} ref={}\n", + diags.len(), + ref_payload.len() + )); let avg_o: f64 = sec_rows.iter().map(|r| r.1).sum::() / sec_rows.len().max(1) as f64; let avg_r: f64 = sec_rows.iter().map(|r| r.2).sum::() / sec_rows.len().max(1) as f64; let gap_avg = avg_r - avg_o; out_str.push_str(&format!( "# avg corr: ours={:.4} ref={:.4} gap={:+.4} ref_kbps={:.1} ours_kbps={:.1}\n\n", - avg_o, avg_r, gap_avg, ref_kbps, + avg_o, + avg_r, + gap_avg, + ref_kbps, ours_bytes.iter().map(|&b| b as f64).sum::() * 8.0 / seconds / 1000.0 )); @@ -3770,27 +4013,45 @@ fn silk_silkq_persecond_diag() { let sd = &diags[f0..f1.min(diags.len())]; let gain_mean: f64 = if !sd.is_empty() { sd.iter().map(|d| d.gain_idx[0] as f64).sum::() / sd.len() as f64 - } else { -1.0 }; + } else { + -1.0 + }; let voiced_n = sd.iter().filter(|d| d.voiced).count(); let nlsf_int = if !sd.is_empty() { sd.iter().map(|d| d.nlsf_interp).max().unwrap_or(0) - } else { 0 }; + } else { + 0 + }; let avg_b_o: f64 = if !sd.is_empty() { sd.iter().map(|d| d.bytes as f64).sum::() / sd.len() as f64 - } else { 0.0 }; + } else { + 0.0 + }; let ref_f0 = f0.min(ref_payload.len()); let ref_f1 = f1.min(ref_payload.len()); let avg_b_r: f64 = if ref_f1 > ref_f0 { - ref_payload[ref_f0..ref_f1].iter().map(|&b| b as f64).sum::() + ref_payload[ref_f0..ref_f1] + .iter() + .map(|&b| b as f64) + .sum::() / (ref_f1 - ref_f0) as f64 - } else { 0.0 }; + } else { + 0.0 + }; let ltp_mean: f64 = if !sd.is_empty() { sd.iter().map(|d| d.ltp_gain as f64).sum::() / sd.len() as f64 - } else { 0.0 }; + } else { + 0.0 + }; let pitch_mean: f64 = if !sd.is_empty() { - sd.iter().filter(|d| d.voiced).map(|d| d.pitch_l[0] as f64).sum::() + sd.iter() + .filter(|d| d.voiced) + .map(|d| d.pitch_l[0] as f64) + .sum::() / sd.iter().filter(|d| d.voiced).count().max(1) as f64 - } else { 0.0 }; + } else { + 0.0 + }; out_str.push_str(&format!( "{}\t{:.4}\t{:.4}\t{:+.4}\t{:.1}\t{}\t{}\t{:.1}\t{:.1}\t{:.3}\t{:.1}\n", s, co, cr, g, gain_mean, voiced_n, nlsf_int, avg_b_o, avg_b_r, ltp_mean, pitch_mean @@ -3809,9 +4070,18 @@ fn silk_silkq_persecond_diag() { let b_ref = ref_payload.get(fi).copied().unwrap_or(0); out_str.push_str(&format!( "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{:.3}\t{}\n", - fi, fi * 20, d.bytes, b_ref, - d.voiced as u8, d.signal_type, d.gain_idx[0], d.lag_index, - d.pitch_l[0], d.nlsf_interp, d.ltp_gain, d.nb_subfr + fi, + fi * 20, + d.bytes, + b_ref, + d.voiced as u8, + d.signal_type, + d.gain_idx[0], + d.lag_index, + d.pitch_l[0], + d.nlsf_interp, + d.ltp_gain, + d.nb_subfr )); } out_str.push('\n'); @@ -3820,10 +4090,16 @@ fn silk_silkq_persecond_diag() { // Global stats. out_str.push_str("# --- global stats ---\n"); let voiced_count = diags.iter().filter(|d| d.voiced).count(); - out_str.push_str(&format!("# voiced frames: {}/{}\n", voiced_count, diags.len())); + out_str.push_str(&format!( + "# voiced frames: {}/{}\n", + voiced_count, + diags.len() + )); let gain_hist: Vec<(i8, usize)> = { let mut h = std::collections::HashMap::new(); - for d in &diags { *h.entry(d.gain_idx[0]).or_insert(0) += 1; } + for d in &diags { + *h.entry(d.gain_idx[0]).or_insert(0) += 1; + } let mut v: Vec<_> = h.into_iter().collect(); v.sort(); v @@ -3831,16 +4107,24 @@ fn silk_silkq_persecond_diag() { out_str.push_str(&format!("# gain_idx[0] histogram: {:?}\n", gain_hist)); let nlsf_hist: Vec<(i32, usize)> = { let mut h = std::collections::HashMap::new(); - for d in &diags { *h.entry(d.nlsf_interp).or_insert(0) += 1; } + for d in &diags { + *h.entry(d.nlsf_interp).or_insert(0) += 1; + } let mut v: Vec<_> = h.into_iter().collect(); v.sort(); v }; out_str.push_str(&format!("# nlsf_interp histogram: {:?}\n", nlsf_hist)); - let avg_b_ours: f64 = diags.iter().map(|d| d.bytes as f64).sum::() / diags.len().max(1) as f64; - let avg_b_ref: f64 = ref_payload.iter().map(|&b| b as f64).sum::() / ref_payload.len().max(1) as f64; - out_str.push_str(&format!("# avg bytes/frame: ours={:.1} ref={:.1}\n", avg_b_ours, avg_b_ref)); - let ltp_mean_all: f64 = diags.iter().map(|d| d.ltp_gain as f64).sum::() / diags.len().max(1) as f64; + let avg_b_ours: f64 = + diags.iter().map(|d| d.bytes as f64).sum::() / diags.len().max(1) as f64; + let avg_b_ref: f64 = + ref_payload.iter().map(|&b| b as f64).sum::() / ref_payload.len().max(1) as f64; + out_str.push_str(&format!( + "# avg bytes/frame: ours={:.1} ref={:.1}\n", + avg_b_ours, avg_b_ref + )); + let ltp_mean_all: f64 = + diags.iter().map(|d| d.ltp_gain as f64).sum::() / diags.len().max(1) as f64; out_str.push_str(&format!("# mean ltp_gain: {:.4}\n", ltp_mean_all)); let out_path = lanes_dir.join("opus-silkq-r1.seconds.txt"); @@ -3902,25 +4186,37 @@ fn silk_silkq_oracle() { ours_packets.push(out[..len].to_vec()); } - let ours_ix = collect_indices(&ours_packets); let ref_ix = collect_indices(&ref_packets); - eprintln!("ours frames: {} ref frames: {}", ours_ix.len(), ref_ix.len()); + eprintln!( + "ours frames: {} ref frames: {}", + ours_ix.len(), + ref_ix.len() + ); // Print side-by-side for target seconds (50 frames/sec at 20ms). let frames_per_sec = 50usize; let mut out_str = String::new(); out_str.push_str("# reelm@12k SILK oracle: ours vs ffmpeg-libopus indices (r1)\n"); out_str.push_str("# mono, 120s, 20ms frames, VBR constrained, 48kHz, Application::Voip\n"); - out_str.push_str(&format!("# ours_frames={} ref_frames={}\n", ours_ix.len(), ref_ix.len())); + out_str.push_str(&format!( + "# ours_frames={} ref_frames={}\n", + ours_ix.len(), + ref_ix.len() + )); out_str.push_str("# sig: 0=unvoiced 2=voiced | per: LTP codebook | nlsf_i: 4=nointerp\n"); out_str.push_str("# gains/ltp are 4 subframe indices; lag/contour only for voiced\n\n"); for &sec in TARGET_SECS { let start = sec * frames_per_sec; let end = start + frames_per_sec; - out_str.push_str(&format!("=== second {} (frames {}–{}) ===\n", sec, start, end - 1)); + out_str.push_str(&format!( + "=== second {} (frames {}–{}) ===\n", + sec, + start, + end - 1 + )); out_str.push_str("frame side sig qoff gains[4] nlsf_i lag cont per ltp[4] ltpscl seed bytes\n"); for f in start..end { let ours = ours_ix.get(f); @@ -3948,7 +4244,10 @@ fn silk_silkq_oracle() { "-".to_string() }; let ltp_str = if voiced { - format!("[{},{},{},{}]", ix.ltp_index[0], ix.ltp_index[1], ix.ltp_index[2], ix.ltp_index[3]) + format!( + "[{},{},{},{}]", + ix.ltp_index[0], ix.ltp_index[1], ix.ltp_index[2], ix.ltp_index[3] + ) } else { "[-,-,-,-]".to_string() }; @@ -3990,14 +4289,26 @@ fn silk_silkq_oracle() { for i in 0..n { let (o, ob) = &ours_ix[i]; let (r, rb) = &ref_ix[i]; - if o.signal_type != r.signal_type { sig_mismatch += 1; } - if o.quant_offset_type != r.quant_offset_type { qoff_mismatch += 1; } - for k in 0..4 { gain_diff_sum += (o.gains[k] as i64 - r.gains[k] as i64).abs(); } - if o.nlsf_interp_coef_q2 != r.nlsf_interp_coef_q2 { nlsf_interp_diff += 1; } + if o.signal_type != r.signal_type { + sig_mismatch += 1; + } + if o.quant_offset_type != r.quant_offset_type { + qoff_mismatch += 1; + } + for k in 0..4 { + gain_diff_sum += (o.gains[k] as i64 - r.gains[k] as i64).abs(); + } + if o.nlsf_interp_coef_q2 != r.nlsf_interp_coef_q2 { + nlsf_interp_diff += 1; + } if o.signal_type == 2 && r.signal_type == 2 { voiced_both += 1; - if o.per_index != r.per_index { ltp_per_mismatch += 1; } - for k in 0..4 { ltp_idx_diff_sum += (o.ltp_index[k] as i64 - r.ltp_index[k] as i64).abs(); } + if o.per_index != r.per_index { + ltp_per_mismatch += 1; + } + for k in 0..4 { + ltp_idx_diff_sum += (o.ltp_index[k] as i64 - r.ltp_index[k] as i64).abs(); + } lag_diff_sum += (o.lag_index as i64 - r.lag_index as i64).abs(); } bytes_ours += *ob as u64; @@ -4005,15 +4316,45 @@ fn silk_silkq_oracle() { } out_str.push_str("=== divergence summary (all frames) ===\n"); out_str.push_str(&format!("frames compared: {}\n", n)); - out_str.push_str(&format!("signal_type mismatch: {} ({:.1}%)\n", sig_mismatch, 100.0 * sig_mismatch as f64 / n as f64)); - out_str.push_str(&format!("quant_offset mismatch: {} ({:.1}%)\n", qoff_mismatch, 100.0 * qoff_mismatch as f64 / n as f64)); - out_str.push_str(&format!("avg |gain diff| per subframe: {:.2}\n", gain_diff_sum as f64 / (n as f64 * 4.0))); - out_str.push_str(&format!("nlsf_interp mismatch: {} ({:.1}%)\n", nlsf_interp_diff, 100.0 * nlsf_interp_diff as f64 / n as f64)); + out_str.push_str(&format!( + "signal_type mismatch: {} ({:.1}%)\n", + sig_mismatch, + 100.0 * sig_mismatch as f64 / n as f64 + )); + out_str.push_str(&format!( + "quant_offset mismatch: {} ({:.1}%)\n", + qoff_mismatch, + 100.0 * qoff_mismatch as f64 / n as f64 + )); + out_str.push_str(&format!( + "avg |gain diff| per subframe: {:.2}\n", + gain_diff_sum as f64 / (n as f64 * 4.0) + )); + out_str.push_str(&format!( + "nlsf_interp mismatch: {} ({:.1}%)\n", + nlsf_interp_diff, + 100.0 * nlsf_interp_diff as f64 / n as f64 + )); out_str.push_str(&format!("voiced_both: {}\n", voiced_both)); - out_str.push_str(&format!(" LTP per_index mismatch: {} ({:.1}%)\n", ltp_per_mismatch, 100.0 * ltp_per_mismatch as f64 / voiced_both.max(1) as f64)); - out_str.push_str(&format!(" avg |ltp_index diff| per subframe: {:.2}\n", ltp_idx_diff_sum as f64 / (voiced_both.max(1) as f64 * 4.0))); - out_str.push_str(&format!(" avg |lag diff|: {:.2}\n", lag_diff_sum as f64 / voiced_both.max(1) as f64)); - out_str.push_str(&format!("total bytes: ours={} ref={} ratio={:.3}\n", bytes_ours, bytes_ref, bytes_ours as f64 / bytes_ref.max(1) as f64)); + out_str.push_str(&format!( + " LTP per_index mismatch: {} ({:.1}%)\n", + ltp_per_mismatch, + 100.0 * ltp_per_mismatch as f64 / voiced_both.max(1) as f64 + )); + out_str.push_str(&format!( + " avg |ltp_index diff| per subframe: {:.2}\n", + ltp_idx_diff_sum as f64 / (voiced_both.max(1) as f64 * 4.0) + )); + out_str.push_str(&format!( + " avg |lag diff|: {:.2}\n", + lag_diff_sum as f64 / voiced_both.max(1) as f64 + )); + out_str.push_str(&format!( + "total bytes: ours={} ref={} ratio={:.3}\n", + bytes_ours, + bytes_ref, + bytes_ours as f64 / bytes_ref.max(1) as f64 + )); let out_path = lanes_dir.join("opus-silkq-r1.oracle.txt"); fs::write(&out_path, &out_str).unwrap(); @@ -4059,14 +4400,7 @@ fn collect_indices(packets: &[Vec]) -> Vec<(ec_opus::SilkDecIndices, usize)> continue; } let mut dec = ec_opus::RangeDecoder::new(frame_data); - let _ = silk.decode( - &mut dec, - &mut silk_pcm, - payload_ms, - internal_rate, - 1, - first, - ); + let _ = silk.decode(&mut dec, &mut silk_pcm, payload_ms, internal_rate, 1, first); let ix = silk.last_indices(); let bytes = frame_data.len(); results.push((ix, bytes)); @@ -4110,7 +4444,9 @@ fn silk_spectral_divergence_12k() { // Reference: ffmpeg libopus mono voip at 12k, decoded by ffmpeg libopus. ffmpeg_encode_libopus_mono_voip(&src, KBPS, &ref_ogg, SECS); - let ref_bytes = fs::metadata(&ref_ogg).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&ref_ogg) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let ref_dec = ffmpeg_decode(&ref_ogg, CHANNELS).expect("ffmpeg libopus decode of ref"); let ref_trim: Vec = ref_dec.into_iter().take(source_frames * CHANNELS).collect(); @@ -4156,7 +4492,10 @@ fn silk_spectral_divergence_12k() { let ours_kbps = ours_bytes as f64 * 8.0 / seconds / 1000.0; let ours_dec = ffmpeg_decode(&ours_ogg, CHANNELS).expect("ffmpeg libopus decode of ours"); let _ = fs::remove_file(&ours_ogg); - let ours_trim: Vec = ours_dec.into_iter().take(source_frames * CHANNELS).collect(); + let ours_trim: Vec = ours_dec + .into_iter() + .take(source_frames * CHANNELS) + .collect(); let (_, ours_aligned) = align_to_source(&source_pcm, &ours_trim, CHANNELS, MAX_LAG); // opus_compare totals, per-band eb², per-frame ef² — both vs the source. @@ -4178,9 +4517,27 @@ fn silk_spectral_divergence_12k() { let mut bands_o = Vec::new(); let mut bands_r = Vec::new(); let mut scratch_ps = Vec::new(); - band_energy(&as_f64(&s_i), CHANNELS, nframes, &mut Some(&mut bands_s), &mut scratch_ps); - band_energy(&as_f64(&o_i), CHANNELS, nframes, &mut Some(&mut bands_o), &mut scratch_ps); - band_energy(&as_f64(&r_i), CHANNELS, nframes, &mut Some(&mut bands_r), &mut scratch_ps); + band_energy( + &as_f64(&s_i), + CHANNELS, + nframes, + &mut Some(&mut bands_s), + &mut scratch_ps, + ); + band_energy( + &as_f64(&o_i), + CHANNELS, + nframes, + &mut Some(&mut bands_o), + &mut scratch_ps, + ); + band_energy( + &as_f64(&r_i), + CHANNELS, + nframes, + &mut Some(&mut bands_r), + &mut scratch_ps, + ); // Oracle indices both sides; FFT frame xi -> 20 ms packet index. let ours_ix = collect_indices(&ours_packets); @@ -4213,7 +4570,11 @@ fn silk_spectral_divergence_12k() { } dol /= nframes as f64; drl /= nframes as f64; - let ratio = if eb2_r[bi] > 0.0 { eb2_o[bi] / eb2_r[bi] } else { f64::INFINITY }; + let ratio = if eb2_r[bi] > 0.0 { + eb2_o[bi] / eb2_r[bi] + } else { + f64::INFINITY + }; report.push_str(&format!( "{:5} {:5} {:6} {:+.3} {:+.3} {:.3e} {:.3e} {:>7} {:5.1}% {:5.1}%\n", bi, @@ -4318,7 +4679,10 @@ fn silk_spectral_divergence_12k() { "# tail: top-1% ({k} frames) carry {:.2}% of ours' Σef2 vs {:.2}% of ref's; \ 50% of ours' err sits in the worst {half_o} frames ({:.2}%) \ vs ref's worst {half_r} ({:.2}%)\n", - 100.0 * sh1_o, 100.0 * sh1_r, 100.0 * halff_o, 100.0 * halff_r + 100.0 * sh1_o, + 100.0 * sh1_r, + 100.0 * halff_o, + 100.0 * halff_r )); // De-tailed: drop each side's worst 50 frames (of 24k FFT frames/pkt-mapped). let clip50 = |ef2: &[f64]| -> f64 { @@ -4351,7 +4715,11 @@ fn silk_spectral_divergence_12k() { if i >= pkt_ef2.len() { break; } - let mean = if pkt_cnt[i] > 0 { pkt_ef2[i] / pkt_cnt[i] as f64 } else { 0.0 }; + let mean = if pkt_cnt[i] > 0 { + pkt_ef2[i] / pkt_cnt[i] as f64 + } else { + 0.0 + }; if ix.gains[0] >= 60 { g_hi.0 += mean; g_hi.1 += 1; @@ -4373,12 +4741,28 @@ fn silk_spectral_divergence_12k() { >20 bytes: mean ef2 {:.3e}\n", g_hi.1, g_hi.1 + g_lo.1, - if g_hi.1 > 0 { g_hi.0 / g_hi.1 as f64 } else { f64::NAN }, - if g_lo.1 > 0 { g_lo.0 / g_lo.1 as f64 } else { f64::NAN }, + if g_hi.1 > 0 { + g_hi.0 / g_hi.1 as f64 + } else { + f64::NAN + }, + if g_lo.1 > 0 { + g_lo.0 / g_lo.1 as f64 + } else { + f64::NAN + }, b_lo.1, b_lo.1 + b_hi.1, - if b_lo.1 > 0 { b_lo.0 / b_lo.1 as f64 } else { f64::NAN }, - if b_hi.1 > 0 { b_hi.0 / b_hi.1 as f64 } else { f64::NAN }, + if b_lo.1 > 0 { + b_lo.0 / b_lo.1 as f64 + } else { + f64::NAN + }, + if b_hi.1 > 0 { + b_hi.0 / b_hi.1 as f64 + } else { + f64::NAN + }, )); let out_path = lanes_dir.join("opus-silkq-r2.bands.txt"); @@ -4415,7 +4799,10 @@ fn opus_compare_harness() { ); let err = opus_compare_err(&x, &y, channels); let q = opus_compare(&x, &y, channels); - println!("HARNESS err={err:.6} Q={q:.4} ch={channels} n={}", x.len() / channels); + println!( + "HARNESS err={err:.6} Q={q:.4} ch={channels} n={}", + x.len() / channels + ); } // --------------------------------------------------------------------------- @@ -4454,10 +4841,12 @@ fn opus_compare_harness_ours() { let mut d_i16 = vec![0i16; n * channels]; for i in 0..n { for ch in 0..channels { - s_i16[i * channels + ch] = - (src_f32[i * channels + ch] * 32768.0).round().clamp(-32768.0, 32767.0) as i16; - d_i16[i * channels + ch] = - (aligned[i * channels + ch] * 32768.0).round().clamp(-32768.0, 32767.0) as i16; + s_i16[i * channels + ch] = (src_f32[i * channels + ch] * 32768.0) + .round() + .clamp(-32768.0, 32767.0) as i16; + d_i16[i * channels + ch] = (aligned[i * channels + ch] * 32768.0) + .round() + .clamp(-32768.0, 32767.0) as i16; } } fs::write(&out_src, bytemap(&s_i16)).unwrap(); @@ -4465,9 +4854,7 @@ fn opus_compare_harness_ours() { let err = opus_compare_err(&s_i16, &d_i16, channels); let q = opus_compare(&s_i16, &d_i16, channels); let c = corr_interleaved(&src_f32[..n * channels], &aligned, channels); - println!( - "HARNESS_OURS lag={lag} corr={c:.4} err={err:.6} Q={q:.4} kbps={kbps} n={n}" - ); + println!("HARNESS_OURS lag={lag} corr={c:.4} err={err:.6} Q={q:.4} kbps={kbps} n={n}"); } fn bytemap(p: &[i16]) -> Vec { @@ -4533,7 +4920,8 @@ fn opus_compare_err_pinned_against_c() { // Case 2: mild perturbation (+0.5 dB on L, quiet 1500 Hz partial on L). let gain = 10f64.powf(0.5 / 10.0); - let lp: Vec = t.iter() + let lp: Vec = t + .iter() .zip(b0.iter()) .map(|(&tt, &bv)| bv * gain + 0.02 * (2.0 * std::f64::consts::PI * 1500.0 * tt).sin()) .collect(); @@ -4575,7 +4963,10 @@ fn spectral_divergence_vs_libopus() { const FRAME: usize = 960; const CHANNELS: usize = 2; const MAX_LAG: usize = 2000; - let kbps_env: u32 = std::env::var("SWEEP_KBPS").ok().and_then(|v| v.parse().ok()).unwrap_or(96); + let kbps_env: u32 = std::env::var("SWEEP_KBPS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(96); #[allow(non_snake_case)] let KBPS: u32 = kbps_env; @@ -4586,7 +4977,10 @@ fn spectral_divergence_vs_libopus() { ("dl8a", "~/Downloads/8a3b6d1d19.mp3"), ("her", "~/Music/reeli.mp3"), ("reelm", "~/Music/reelm.wav"), - ("hein", "~/Downloads/reelm.mp3"), + ( + "hein", + "~/Downloads/reelm.mp3", + ), ]; let only: Vec = std::env::var("SWEEP_ONLY") .unwrap_or_else(|_| "reell,dl8a".to_owned()) @@ -4609,12 +5003,14 @@ fn spectral_divergence_vs_libopus() { let scratch = lanes_dir.join("opus-reell-r1.scratch.ogg"); let mut frames_all = String::new(); let mut report = String::new(); + let mut swept = 0usize; for (tag, src) in &sources { - if !src.exists() { + if !require_host_media(src, tag) { eprintln!("SKIP {tag}: missing {}", src.display()); continue; } + swept += 1; let source_pcm = ffmpeg_decode_pcm(src, SECS); let source_frames = source_pcm.len() / CHANNELS; let seconds = source_frames as f64 / 48000.0; @@ -4622,13 +5018,15 @@ fn spectral_divergence_vs_libopus() { // Reference: ffmpeg libopus at 96k, VBR, decoded by our decoder. ffmpeg_encode_libopus(src, KBPS, &scratch, SECS); - let ref_bytes = fs::metadata(&scratch).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&scratch) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let ref_pkts: Vec> = ogg_packets(&fs::read(&scratch).unwrap()) .into_iter() .skip(2) .collect(); - let (ref_dec, ref_ch) = decode_ogg(&scratch); + let (ref_dec, ref_ch) = decode_ogg(&scratch); assert_eq!(ref_ch, CHANNELS, "{tag}: ref not stereo"); let (_, ref_aligned) = align_to_source(&source_pcm, &ref_dec, CHANNELS, MAX_LAG); @@ -4641,16 +5039,18 @@ fn spectral_divergence_vs_libopus() { let mut dbuf = vec![0.0f32; 5760 * CHANNELS]; let mut ours_dec = Vec::new(); let mut first_pkts: Vec> = Vec::new(); - let mut diags = Vec::new(); + let mut diags = Vec::new(); let mut ours_bytes = 0usize; for block in source_pcm.chunks(FRAME * CHANNELS) { let mut padded = block.to_vec(); padded.resize(FRAME * CHANNELS, 0.0); - let len = enc.encode_float(&padded, FRAME, &mut packet).expect("encode"); + let len = enc + .encode_float(&padded, FRAME, &mut packet) + .expect("encode"); if first_pkts.len() < 10 { first_pkts.push(packet[..len].to_vec()); } - ours_bytes += len; + ours_bytes += len; let n = dec.decode_float(&packet[..len], &mut dbuf).expect("decode"); ours_dec.extend_from_slice(&dbuf[..n * CHANNELS]); diags.push(enc.last_celt_diag().clone()); @@ -4674,7 +5074,10 @@ fn spectral_divergence_vs_libopus() { "{tag}@{KBPS}k transient frames: ours {ours_tr}/{} ref {ref_tr}/{ref_n}", diags.len() ); - let ours_trim: Vec = ours_dec.into_iter().take(source_frames * CHANNELS).collect(); + let ours_trim: Vec = ours_dec + .into_iter() + .take(source_frames * CHANNELS) + .collect(); let (_, ours_aligned) = align_to_source(&source_pcm, &ours_trim, CHANNELS, MAX_LAG); let ours_i16 = to_i16(&ours_aligned); let ref_i16 = to_i16(&ref_aligned); @@ -4700,9 +5103,27 @@ fn spectral_divergence_vs_libopus() { let mut bands_o = Vec::new(); let mut bands_r = Vec::new(); let mut scratch_ps = Vec::new(); - band_energy(&as_f64(&s_i), CHANNELS, nframes, &mut Some(&mut bands_s), &mut scratch_ps); - band_energy(&as_f64(&o_i), CHANNELS, nframes, &mut Some(&mut bands_o), &mut scratch_ps); - band_energy(&as_f64(&r_i), CHANNELS, nframes, &mut Some(&mut bands_r), &mut scratch_ps); + band_energy( + &as_f64(&s_i), + CHANNELS, + nframes, + &mut Some(&mut bands_s), + &mut scratch_ps, + ); + band_energy( + &as_f64(&o_i), + CHANNELS, + nframes, + &mut Some(&mut bands_o), + &mut scratch_ps, + ); + band_energy( + &as_f64(&r_i), + CHANNELS, + nframes, + &mut Some(&mut bands_r), + &mut scratch_ps, + ); report.push_str(&format!( "\n# source {tag} @{KBPS}k: ours {ours_kbps:.1} kbps, ref {ref_kbps:.1} kbps; \ @@ -4800,11 +5221,9 @@ fn spectral_divergence_vs_libopus() { let dual = fr.iter().filter(|d| d.dual_stereo).count(); let intra = fr.iter().filter(|d| d.intra).count(); let cbb_min = fr.iter().map(|d| d.coded_bands).min().unwrap_or(0); - let cbb_mean = - fr.iter().map(|d| d.coded_bands).sum::() as f64 / dn as f64; + let cbb_mean = fr.iter().map(|d| d.coded_bands).sum::() as f64 / dn as f64; let int_mean = fr.iter().map(|d| d.intensity).sum::() as f64 / dn as f64; - let bits = - fr.iter().map(|d| d.nb_compressed).sum::() as f64 * 8.0 / dn as f64; + let bits = fr.iter().map(|d| d.nb_compressed).sum::() as f64 * 8.0 / dn as f64; report.push_str(&format!( "{}\t{:.3e}\t{}/{}\t{}\t{}\t{}\t{}/{}\t{}/{}\t{:.0}\n", s, @@ -4829,8 +5248,7 @@ fn spectral_divergence_vs_libopus() { let dual = diags.iter().filter(|d| d.dual_stereo).count(); let intra = diags.iter().filter(|d| d.intra).count(); let cbb_min = diags.iter().map(|d| d.coded_bands).min().unwrap_or(0); - let cbb_mean = - diags.iter().map(|d| d.coded_bands).sum::() as f64 / dn as f64; + let cbb_mean = diags.iter().map(|d| d.coded_bands).sum::() as f64 / dn as f64; let int_mean = diags.iter().map(|d| d.intensity).sum::() as f64 / dn as f64; let bits = diags.iter().map(|d| d.nb_compressed).sum::() as f64 * 8.0 / dn as f64; @@ -4854,9 +5272,14 @@ fn spectral_divergence_vs_libopus() { // frame each window lands in. let mut byf: Vec<(usize, f64)> = ef2_o.iter().cloned().enumerate().collect(); byf.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap()); - report.push_str("# top-8 metric windows by ours ef²: offset_ms ours ref | enc frame diag\n"); + report + .push_str("# top-8 metric windows by ours ef²: offset_ms ours ref | enc frame diag\n"); for &(xi, v) in &byf[..byf.len().min(8)] { - let rv = if xi < ef2_r.len() { ef2_r[xi] } else { f64::NAN }; + let rv = if xi < ef2_r.len() { + ef2_r[xi] + } else { + f64::NAN + }; let ms = xi * WIN_STEP * 1000 / 48000; let eidx = xi * WIN_STEP / FRAME; let d = diags.get(eidx); @@ -4882,9 +5305,8 @@ fn spectral_divergence_vs_libopus() { } // Startup behavior: first 10 encoder frames. - report.push_str( - "# first encoder frames: idx trans intra silence cbb_hz int_hz dual bytes\n", - ); + report + .push_str("# first encoder frames: idx trans intra silence cbb_hz int_hz dual bytes\n"); for (i, d) in diags.iter().take(10).enumerate() { report.push_str(&format!( "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", @@ -4901,11 +5323,12 @@ fn spectral_divergence_vs_libopus() { // Per-window per-band ln-energies for the metric windows 12..=20 // (+120..+200 ms): the leak's shape, band by band. - report.push_str( - "# windows 12..=20: win +ms band lo-hi | lnE src/ours/ref, ch L then R\n", - ); + report.push_str("# windows 12..=20: win +ms band lo-hi | lnE src/ours/ref, ch L then R\n"); // WIN_CENTRE= recentres the dump on another window. - let wc: usize = std::env::var("WIN_CENTRE").ok().and_then(|v| v.parse().ok()).unwrap_or(16); + let wc: usize = std::env::var("WIN_CENTRE") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(16); for xi in wc.saturating_sub(4)..=wc + 4 { if xi >= nframes { break; @@ -4951,7 +5374,8 @@ fn spectral_divergence_vs_libopus() { g.total_bits, )); for (ch, name) in [(0usize, 'L'), (1usize, 'R')] { - let band = &g.old_band_e[ch * ec_opus::celt::NB_BANDS..(ch + 1) * ec_opus::celt::NB_BANDS]; + let band = &g.old_band_e + [ch * ec_opus::celt::NB_BANDS..(ch + 1) * ec_opus::celt::NB_BANDS]; let e: Vec = band.iter().map(|v| format!("{v:+6.1}")).collect(); frames_all.push_str(&format!(" {name} {}\n", e.join(" "))); } @@ -4962,6 +5386,12 @@ fn spectral_divergence_vs_libopus() { err_o / err_r ); } + // Non-empty floor: no source means the report below is empty and the whole + // divergence analysis went unexercised. + assert!( + swept >= 1, + "no spectral-divergence source was present, so nothing was measured" + ); let _ = fs::remove_file(&scratch); let header = format!( "# spectral divergence vs libopus @ {KBPS}k, {SECS:.0}s cap, sources {}\n", @@ -4981,8 +5411,7 @@ fn celt_silence_then_attack_decodes_bounded() { let fs = 960usize; let ch = 2usize; let src = shellexpand("~/Music/reell.mp4"); - if !src.exists() { - eprintln!("SKIP: missing {}", src.display()); + if !require_host_media(&src, "host-media") { return; } let pcm = ffmpeg_decode_pcm(&src, 1.0); @@ -5021,16 +5450,23 @@ fn celt_silence_then_attack_decodes_bounded() { fn reell_startup_hop_energies() { const CH: usize = 2; // HOP_SRC / HOP_MS pick another source and window centre (diagnostic). - let src_s = std::env::var("HOP_SRC").unwrap_or_else(|_| "~/Music/reell.mp4".into()); - let centre_ms: f64 = std::env::var("HOP_MS").ok().and_then(|v| v.parse().ok()).unwrap_or(42.5); + let src_s = + std::env::var("HOP_SRC").unwrap_or_else(|_| "~/Music/reell.mp4".into()); + let centre_ms: f64 = std::env::var("HOP_MS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(42.5); let src = shellexpand(&src_s); - if !src.exists() { + if !require_host_media(&src, "host-media") { return; } let secs = (centre_ms / 1000.0 + 1.0).max(2.0); let pcm = ffmpeg_decode_pcm(&src, secs); let scratch = std::env::temp_dir().join("ec-opus-reell-startup.opus"); - let kbps: u32 = std::env::var("HOP_KBPS").ok().and_then(|v| v.parse().ok()).unwrap_or(96); + let kbps: u32 = std::env::var("HOP_KBPS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(96); ffmpeg_encode_libopus(&src, kbps, &scratch, secs); let (ref_dec, _) = decode_ogg(&scratch); let (lag_r, ref_al) = align_to_source(&pcm, &ref_dec, CH, 2000); @@ -5048,11 +5484,22 @@ fn reell_startup_hop_energies() { ours_dec.extend_from_slice(&buf[..m * CH]); let e = enc.last_celt_diag().clone(); let d = dec.last_celt_diag().clone(); - frames_diag.push((n, e.is_transient, e.intra, d.tf_res.clone(), d.anti_collapse)); + frames_diag.push(( + n, + e.is_transient, + e.intra, + d.tf_res.clone(), + d.anti_collapse, + )); } let (lag_o, ours_al) = align_to_source(&pcm, &ours_dec, CH, 2000); let first = |v: &[f32]| v.iter().position(|x| x.abs() > 1e-4).map(|i| i / CH); - println!("lag ref {lag_r} ours {lag_o}; first>1e-4: src {:?} ours {:?} ref {:?}", first(&pcm), first(&ours_al), first(&ref_al)); + println!( + "lag ref {lag_r} ours {lag_o}; first>1e-4: src {:?} ours {:?} ref {:?}", + first(&pcm), + first(&ours_al), + first(&ref_al) + ); let e = |v: &[f32], h: usize| -> f64 { let a = (h * 120 * CH).min(v.len()); let b = ((h + 1) * 120 * CH).min(v.len()); @@ -5061,12 +5508,21 @@ fn reell_startup_hop_energies() { let hc = (centre_ms / 2.5) as usize; for f in (hc / 8).saturating_sub(1)..=(hc / 8 + 1) { if let Some((n, t, i, tf, ac)) = frames_diag.get(f) { - println!("frame {f} ({:.1} ms): bytes {n} trans {t} intra {i} ac {ac} tf {tf:?}", f as f64 * 20.0); + println!( + "frame {f} ({:.1} ms): bytes {n} trans {t} intra {i} ac {ac} tf {tf:?}", + f as f64 * 20.0 + ); } } println!("hop(ms)\tsrc\tours\tref"); for h in hc.saturating_sub(8)..hc + 8 { - println!("{:.1}\t{:.3e}\t{:.3e}\t{:.3e}", h as f64 * 2.5, e(&pcm, h), e(&ours_al, h), e(&ref_al, h)); + println!( + "{:.1}\t{:.3e}\t{:.3e}\t{:.3e}", + h as f64 * 2.5, + e(&pcm, h), + e(&ours_al, h), + e(&ref_al, h) + ); } } @@ -5083,9 +5539,18 @@ fn celt_click_peak_offset() { enc.set_mode(Some(ec_opus::Mode::Celt)); enc.set_bitrate(bps); let (dec, _) = roundtrip_own(&mut enc, &click, 1, 960); - let p = dec.iter().enumerate().max_by(|a, b| a.1.abs().partial_cmp(&b.1.abs()).unwrap()).unwrap().0; + let p = dec + .iter() + .enumerate() + .max_by(|a, b| a.1.abs().partial_cmp(&b.1.abs()).unwrap()) + .unwrap() + .0; let d = enc.last_celt_diag().clone(); - println!("celt click {bps}: peak +{} (lm {})", p as i64 - at as i64, d.lm); + println!( + "celt click {bps}: peak +{} (lm {})", + p as i64 - at as i64, + d.lm + ); } } @@ -5136,18 +5601,22 @@ fn short_block_bits_vs_libopus() { let scratch = lanes_dir.join("opus-sb-r1.scratch.ogg"); let nb = ec_opus::celt::NB_BANDS; let mut report = String::new(); + let mut swept = 0usize; for (tag, src) in &sources { - if !src.exists() { + if !require_host_media(src, tag) { eprintln!("SKIP {tag}: missing {}", src.display()); continue; } + swept += 1; let source_pcm = ffmpeg_decode_pcm(src, SECS); let seconds = source_pcm.len() as f64 / CHANNELS as f64 / 48000.0; // Reference: ffmpeg libopus at KBPS, VBR. ffmpeg_encode_libopus(src, KBPS, &scratch, SECS); - let ref_bytes = fs::metadata(&scratch).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&scratch) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let ref_pkts: Vec> = ogg_packets(&fs::read(&scratch).unwrap()) .into_iter() @@ -5182,7 +5651,9 @@ fn short_block_bits_vs_libopus() { for block in source_pcm.chunks(FRAME * CHANNELS) { let mut padded = block.to_vec(); padded.resize(FRAME * CHANNELS, 0.0); - let len = enc.encode_float(&padded, FRAME, &mut packet).expect("encode"); + let len = enc + .encode_float(&padded, FRAME, &mut packet) + .expect("encode"); ours_bytes += len; let toc = ec_opus::Toc::new(packet[0]); if dec.decode_float(&packet[..len], &mut dbuf).is_ok() && toc.mode() != Mode::Silk { @@ -5199,10 +5670,14 @@ fn short_block_bits_vs_libopus() { )); for (label, is_trans) in [("LONG", false), ("SHORT", true)] { - let ours_t: Vec<&ec_opus::celt::CeltDecDiag> = - ours_diags.iter().filter(|d| d.transient == is_trans).collect(); - let ref_t: Vec<&ec_opus::celt::CeltDecDiag> = - ref_diags.iter().filter(|d| d.transient == is_trans).collect(); + let ours_t: Vec<&ec_opus::celt::CeltDecDiag> = ours_diags + .iter() + .filter(|d| d.transient == is_trans) + .collect(); + let ref_t: Vec<&ec_opus::celt::CeltDecDiag> = ref_diags + .iter() + .filter(|d| d.transient == is_trans) + .collect(); let on = ours_t.len(); let rn = ref_t.len(); if on == 0 && rn == 0 { @@ -5235,19 +5710,18 @@ fn short_block_bits_vs_libopus() { ours_t.iter().map(|d| d.fine_quant[i] as f64).sum::() / on.max(1) as f64; let rm: f64 = ref_t.iter().map(|d| d.fine_quant[i] as f64).sum::() / rn.max(1) as f64; - report.push_str(&format!( - "{}\t{:.2}\t{:.2}\n", - CELT_EBANDS[i] * 240, - om, - rm - )); + report.push_str(&format!("{}\t{:.2}\t{:.2}\n", CELT_EBANDS[i] * 240, om, rm)); } // Aggregate stats. - let mean = |v: &[&ec_opus::celt::CeltDecDiag], f: &dyn Fn(&ec_opus::celt::CeltDecDiag) -> f64| -> f64 { + let mean = |v: &[&ec_opus::celt::CeltDecDiag], + f: &dyn Fn(&ec_opus::celt::CeltDecDiag) -> f64| + -> f64 { v.iter().map(|d| f(d)).sum::() / v.len().max(1) as f64 }; - let mean_band_hz = |v: &[&ec_opus::celt::CeltDecDiag], f: &dyn Fn(&ec_opus::celt::CeltDecDiag) -> usize| -> f64 { + let mean_band_hz = |v: &[&ec_opus::celt::CeltDecDiag], + f: &dyn Fn(&ec_opus::celt::CeltDecDiag) -> usize| + -> f64 { let m = v.iter().map(|d| f(d)).sum::() / v.len().max(1); CELT_EBANDS[m] as f64 * 240.0 }; @@ -5291,16 +5765,22 @@ fn short_block_bits_vs_libopus() { )); report.push_str("# mean dynalloc boost per band (1/8 bit) ours / ref\n"); for b in 0..nb { - let mo = mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| d.offsets[b] as f64); - let mr = mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| d.offsets[b] as f64); + let mo = mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| { + d.offsets[b] as f64 + }); + let mr = mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| { + d.offsets[b] as f64 + }); if mo != 0.0 || mr != 0.0 { report.push_str(&format!("{}\t{:.1}\t{:.1}\n", CELT_EBANDS[b] * 240, mo, mr)); } } report.push_str(&format!( "# alloc_trim mean: ours {:.2} ref {:.2}\n", - mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| d.alloc_trim as f64), - mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| d.alloc_trim as f64), + mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| d.alloc_trim + as f64), + mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| d.alloc_trim + as f64), )); report.push_str(&format!( "# coded_bands mean Hz: ours {:.0} ref {:.0}\n", @@ -5319,8 +5799,10 @@ fn short_block_bits_vs_libopus() { )); report.push_str(&format!( "# total_bits mean: ours {:.0} ref {:.0}\n", - mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| d.total_bits as f64), - mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| d.total_bits as f64), + mean(&ours_t, &|d: &ec_opus::celt::CeltDecDiag| d.total_bits + as f64), + mean(&ref_t, &|d: &ec_opus::celt::CeltDecDiag| d.total_bits + as f64), )); report.push_str(&format!( "# balance mean: ours {:.0} ref {:.0}\n", @@ -5339,6 +5821,11 @@ fn short_block_bits_vs_libopus() { )); } } + // Non-empty floor: no source means an empty report and no measurement. + assert!( + swept >= 1, + "no short-block-bits source was present, so nothing was measured" + ); fs::write(&out_path, &report).unwrap(); eprintln!("wrote {}", out_path.display()); @@ -5377,8 +5864,7 @@ fn err_map_vs_libopus() { let src = shellexpand( &std::env::var("EC_ERRMAP_SRC").unwrap_or_else(|_| "~/Music/reeli.mp3".to_string()), ); - if !src.exists() { - eprintln!("SKIP: missing {}", src.display()); + if !require_host_media(&src, "host-media") { return; } let lanes_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../lanes"); @@ -5393,7 +5879,9 @@ fn err_map_vs_libopus() { // Reference: ffmpeg libopus, VBR — the gate's path. ffmpeg_encode_libopus(&src, kbps_env, &scratch, SECS); - let ref_bytes = fs::metadata(&scratch).map(|m| m.len() as usize).unwrap_or(0); + let ref_bytes = fs::metadata(&scratch) + .map(|m| m.len() as usize) + .unwrap_or(0); let ref_kbps = ref_bytes as f64 * 8.0 / seconds / 1000.0; let (ref_dec, ref_ch) = decode_ogg(&scratch); assert_eq!(ref_ch, CH, "ref not stereo"); @@ -5421,7 +5909,11 @@ fn err_map_vs_libopus() { let toc = ec_opus::Toc::new(p[0]); let got = d.decode_float(p, &mut buf).unwrap_or(0); if toc.mode() != Mode::Silk { - ref_fd.push(FD { sample: at, enc: None, dec: d.last_celt_diag().clone() }); + ref_fd.push(FD { + sample: at, + enc: None, + dec: d.last_celt_diag().clone(), + }); } at += got; } @@ -5465,7 +5957,11 @@ fn err_map_vs_libopus() { // 1 s windows. let nwin = hop_o.len() / HOPS_PER_WIN; - let sum = |h: &[f64], w: usize| h[w * HOPS_PER_WIN..(w + 1) * HOPS_PER_WIN].iter().sum::(); + let sum = |h: &[f64], w: usize| { + h[w * HOPS_PER_WIN..(w + 1) * HOPS_PER_WIN] + .iter() + .sum::() + }; let tot_o: f64 = hop_o.iter().sum(); let tot_r: f64 = hop_r.iter().sum(); let mut wins: Vec<(usize, f64, f64, f64)> = (0..nwin) @@ -5500,9 +5996,9 @@ fn err_map_vs_libopus() { f.dec.spread, f.dec.anti_collapse as u8, f.dec.total_bits, - ) + &e.map(|e| format!( - " | ENC sb{} vbr{}", e.short_blocks, e.vbr_reservoir - )).unwrap_or_default() + ) + &e + .map(|e| format!(" | ENC sb{} vbr{}", e.short_blocks, e.vbr_reservoir)) + .unwrap_or_default() }; let ref_at = |s: usize| -> Option<&FD> { let i = ref_fd.partition_point(|f| f.sample <= s); @@ -5569,13 +6065,19 @@ fn err_map_vs_libopus() { ) }) .collect(); - out.push_str(&format!(" Δlog2E L {}\n R {}\n", d0.join(" "), d1.join(" "))); + out.push_str(&format!( + " Δlog2E L {}\n R {}\n", + d0.join(" "), + d1.join(" ") + )); } } } // The single worst ours window, frame by frame: where do decisions diverge. - let worst = (0..nwin).max_by(|&a, &b| wins[a].1.total_cmp(&wins[b].1)).unwrap(); + let worst = (0..nwin) + .max_by(|&a, &b| wins[a].1.total_cmp(&wins[b].1)) + .unwrap(); out.push_str(&format!( "\n== WORST WINDOW t={}..{}s, ALL FRAMES (OUR | REF) ==\n", worst, @@ -5583,7 +6085,9 @@ fn err_map_vs_libopus() { )); for fi in worst * 50..(worst + 1) * 50 { let our = ours_fd.get(fi).map(&fmt_fd).unwrap_or_else(|| "-".into()); - let rf = ref_at(fi * FRAME + 480).map(&fmt_fd).unwrap_or_else(|| "-".into()); + let rf = ref_at(fi * FRAME + 480) + .map(&fmt_fd) + .unwrap_or_else(|| "-".into()); out.push_str(&format!("f{fi}: OUR {our}\n REF {rf}\n")); } @@ -5599,31 +6103,52 @@ fn err_map_vs_libopus() { #[ignore] fn frame_decisions_vs_libopus() { const CH: usize = 2; - let src_s = std::env::var("FRAME_SRC") - .unwrap_or_else(|_| "~/Music/reell.mp4".into()); + let src_s = + std::env::var("FRAME_SRC").unwrap_or_else(|_| "~/Music/reell.mp4".into()); let src = shellexpand(&src_s); - if !src.exists() { - eprintln!("SKIP: missing {}", src.display()); + if !require_host_media(&src, "host-media") { return; } - let kbps: u32 = std::env::var("FRAME_KBPS").ok().and_then(|v| v.parse().ok()).unwrap_or(64); - let from: usize = std::env::var("FRAME_FROM").ok().and_then(|v| v.parse().ok()).unwrap_or(0); - let to: usize = std::env::var("FRAME_TO").ok().and_then(|v| v.parse().ok()).unwrap_or(6); + let kbps: u32 = std::env::var("FRAME_KBPS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(64); + let from: usize = std::env::var("FRAME_FROM") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(0); + let to: usize = std::env::var("FRAME_TO") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(6); let secs = (to as f64 * 0.02 + 1.0).max(2.0); let pcm = ffmpeg_decode_pcm(&src, secs); let scratch = std::env::temp_dir().join("ec-opus-frame-dec.opus"); ffmpeg_encode_libopus(&src, kbps, &scratch, secs); - let ref_pkts: Vec> = - ogg_packets(&fs::read(&scratch).unwrap()).into_iter().skip(2).collect(); + let ref_pkts: Vec> = ogg_packets(&fs::read(&scratch).unwrap()) + .into_iter() + .skip(2) + .collect(); let show = |tag: &str, f: usize, bytes: usize, d: &ec_opus::celt::CeltDecDiag| { - let e: Vec = d.old_band_e[..NB_BANDS_DIAG].iter().map(|v| format!("{v:.1}")).collect(); + let e: Vec = d.old_band_e[..NB_BANDS_DIAG] + .iter() + .map(|v| format!("{v:.1}")) + .collect(); println!( "f{f} {tag}: bytes {bytes} sil {} intra {} trans {} ac {} trim {} spread {} cb {} \ tf {:?} pulses {:?} fine {:?} E {}", - d.silence, d.intra, d.transient, d.anti_collapse, d.alloc_trim, d.spread, - d.coded_bands, &d.tf_res[..NB_BANDS_DIAG], &d.pulses[..NB_BANDS_DIAG], - &d.fine_quant[..NB_BANDS_DIAG], e.join(",") + d.silence, + d.intra, + d.transient, + d.anti_collapse, + d.alloc_trim, + d.spread, + d.coded_bands, + &d.tf_res[..NB_BANDS_DIAG], + &d.pulses[..NB_BANDS_DIAG], + &d.fine_quant[..NB_BANDS_DIAG], + e.join(",") ); }; @@ -5634,7 +6159,11 @@ fn frame_decisions_vs_libopus() { let ok = !p.is_empty() && ec_opus::Toc::new(p[0]).mode() != Mode::Silk && d.decode_float(p, &mut buf).is_ok(); - ref_rows.push(if ok { Some((p.len(), d.last_celt_diag().clone())) } else { None }); + ref_rows.push(if ok { + Some((p.len(), d.last_celt_diag().clone())) + } else { + None + }); } // Encode at the reference's REALISED rate, like the library gate does: @@ -5653,7 +6182,11 @@ fn frame_decisions_vs_libopus() { let n = enc.encode_float(block, 960, &mut out).unwrap(); let ok = ec_opus::Toc::new(out[0]).mode() != Mode::Silk && dec.decode_float(&out[..n], &mut buf).is_ok(); - ours_rows.push(if ok { Some((n, dec.last_celt_diag().clone())) } else { None }); + ours_rows.push(if ok { + Some((n, dec.last_celt_diag().clone())) + } else { + None + }); } if to - from <= 40 { @@ -5674,9 +6207,10 @@ fn frame_decisions_vs_libopus() { let mut agg = [(0usize, [0.0f64; 8]); 2]; let mut trans_diff = 0usize; for f in from..to { - let (Some((no, o)), Some((nr, r))) = - (ours_rows.get(f).and_then(|x| x.as_ref()), ref_rows.get(f).and_then(|x| x.as_ref())) - else { + let (Some((no, o)), Some((nr, r))) = ( + ours_rows.get(f).and_then(|x| x.as_ref()), + ref_rows.get(f).and_then(|x| x.as_ref()), + ) else { continue; }; if o.transient != r.transient { @@ -5689,10 +6223,14 @@ fn frame_decisions_vs_libopus() { let a = &mut agg[slot]; a.0 += 1; for (k, v) in [ - *no as f64, *nr as f64, - o.alloc_trim as f64, r.alloc_trim as f64, - tf(o), tf(r), - f64::from(u8::from(o.anti_collapse)), f64::from(u8::from(r.anti_collapse)), + *no as f64, + *nr as f64, + o.alloc_trim as f64, + r.alloc_trim as f64, + tf(o), + tf(r), + f64::from(u8::from(o.anti_collapse)), + f64::from(u8::from(r.anti_collapse)), ] .into_iter() .enumerate() @@ -5710,7 +6248,14 @@ fn frame_decisions_vs_libopus() { println!( "{name} n={n}: bytes o {:.1} r {:.1} | trim o {:.2} r {:.2} | mean tf_res o {:.3} \ r {:.3} | anti_collapse o {:.2} r {:.2}", - m(0), m(1), m(2), m(3), m(4), m(5), m(6), m(7) + m(0), + m(1), + m(2), + m(3), + m(4), + m(5), + m(6), + m(7) ); } } @@ -5730,7 +6275,11 @@ fn analysis_music_prob_separates_speech_from_music() { const FRAME: usize = 960; const CHANNELS: usize = 2; let sources: &[(&str, &str, bool)] = &[ - ("hein", "~/Downloads/reelm.mp3", false), + ( + "hein", + "~/Downloads/reelm.mp3", + false, + ), ("reell", "~/Music/reell.mp4", true), ("reelo", "~/Music/reelo.mp3", true), ]; @@ -5749,7 +6298,7 @@ fn analysis_music_prob_separates_speech_from_music() { let mut means: Vec<(String, bool, f64)> = Vec::new(); for (tag, path, is_music) in sources { let src = shellexpand(path); - if !src.exists() { + if !require_host_media(&src, "host-media") { eprintln!("SKIP {tag}: missing {}", src.display()); continue; } @@ -5781,7 +6330,10 @@ fn analysis_music_prob_separates_speech_from_music() { bw_hist[(d.analysis_bandwidth.clamp(0, 20)) as usize] += 1; } } - assert!(valid * 10 > n * 9, "{tag}: analysis valid on only {valid}/{n} frames"); + assert!( + valid * 10 > n * 9, + "{tag}: analysis valid on only {valid}/{n} frames" + ); let bw: Vec = bw_hist .iter() .enumerate() @@ -5816,7 +6368,12 @@ fn analysis_music_prob_separates_speech_from_music() { let speech: Vec<_> = means.iter().filter(|m| !m.1).collect(); let music: Vec<_> = means.iter().filter(|m| m.1).collect(); for s in &speech { - assert!(s.2 < 0.5, "{}: speech music_prob {:.3} should be < 0.5", s.0, s.2); + assert!( + s.2 < 0.5, + "{}: speech music_prob {:.3} should be < 0.5", + s.0, + s.2 + ); for m in &music { assert!( m.2 - s.2 > 0.2, @@ -5829,6 +6386,11 @@ fn analysis_music_prob_separates_speech_from_music() { } } for m in &music { - assert!(m.2 > 0.5, "{}: music music_prob {:.3} should be > 0.5", m.0, m.2); + assert!( + m.2 > 0.5, + "{}: music music_prob {:.3} should be > 0.5", + m.0, + m.2 + ); } } diff --git a/crates/ec-vorbis/tests/oracle.rs b/crates/ec-vorbis/tests/oracle.rs index c112af42..bc0f4de5 100644 --- a/crates/ec-vorbis/tests/oracle.rs +++ b/crates/ec-vorbis/tests/oracle.rs @@ -603,7 +603,11 @@ fn onset_after_silence_has_no_pre_echo() { // last few hundred samples before it cannot hide behind a guard band, and // the peak is barred too. let amp = 0.7f64; - for (rate, layouts) in [(44_100u32, &[1usize, 2][..]), (48_000, &[1, 2, 6]), (96_000, &[6])] { + for (rate, layouts) in [ + (44_100u32, &[1usize, 2][..]), + (48_000, &[1, 2, 6]), + (96_000, &[6]), + ] { let grid = 16 * 1024usize; let onsets = [0.3333f64, 0.5, 0.7321, 0.9137, 1.0] .into_iter() @@ -618,7 +622,8 @@ fn onset_after_silence_has_no_pre_echo() { let start = onset + 11 * c; for i in 0..tone_len { let t = i as f64 / f64::from(rate); - plane[start + i] = (amp * (2.0 * std::f64::consts::PI * hz * t).sin()) as f32; + plane[start + i] = + (amp * (2.0 * std::f64::consts::PI * hz * t).sin()) as f32; } } let name = format!("onset-{rate}-{channels}ch-{onset}.ogg"); @@ -650,7 +655,10 @@ fn onset_after_silence_has_no_pre_echo() { gap_rms <= 0.002 * tone_rms, "{name}/{label} ch{c}: gap RMS {gap_rms:.6} vs tone RMS {tone_rms:.6}" ); - assert!(f64::from(peak) <= 0.01 * amp, "{name}/{label} ch{c}: gap peak {peak:.4}"); + assert!( + f64::from(peak) <= 0.01 * amp, + "{name}/{label} ch{c}: gap peak {peak:.4}" + ); } }; let (ours, _) = our_decode(&path); @@ -717,8 +725,8 @@ fn the_rate_loop_tracks_the_target_bitrate() { fn quiet_content_reaches_the_target_or_is_transparent() { let rate = 48_000u32; let samples = rate as usize * 3; - let fixture = ffmpeg_decode(&fixtures().join("audio/wav16-stereo-48000.wav")) - .expect("fixture decodes"); + let fixture = + ffmpeg_decode(&fixtures().join("audio/wav16-stereo-48000.wav")).expect("fixture decodes"); assert_eq!(fixture.1, rate); let attenuate = |mut source: Vec>| { for channel in source.iter_mut() { @@ -740,7 +748,10 @@ fn quiet_content_reaches_the_target_or_is_transparent() { .fold(1.0f64, f64::min) }; let loud = busy(2, rate, samples); - let loud_corr = corr_at(&encode_to_file(&loud, rate, 128_000, "loud-128k.ogg"), &loud); + let loud_corr = corr_at( + &encode_to_file(&loud, rate, 128_000, "loud-128k.ogg"), + &loud, + ); let quiet_noise = attenuate(loud); let mut quiet_tones = attenuate(tones(2, rate, samples)); for (channel, noise) in quiet_tones.iter_mut().zip(busy(2, rate, samples)) { @@ -757,11 +768,19 @@ fn quiet_content_reaches_the_target_or_is_transparent() { let mut measured = Vec::new(); let mut spent = Vec::new(); for target in [96_000i32, 128_000, 192_000] { - let path = encode_to_file(source, rate, target, &format!("{name}-{}k.ogg", target / 1000)); + let path = encode_to_file( + source, + rate, + target, + &format!("{name}-{}k.ogg", target / 1000), + ); let bytes = std::fs::metadata(&path).expect("file").len(); let kbps = bytes as f64 * 8.0 * f64::from(rate) / source[0].len() as f64 / 1000.0; let corr = corr_at(&path, source); - println!("{name}: target {} kbps -> {kbps:.0} kbps, corr {corr:.4}", target / 1000); + println!( + "{name}: target {} kbps -> {kbps:.0} kbps, corr {corr:.4}", + target / 1000 + ); let target_kbps = f64::from(target) / 1000.0; let within_25pct = (kbps - target_kbps).abs() / target_kbps < 0.25; let transparent_undershoot = kbps < target_kbps && corr >= 0.999; @@ -776,7 +795,10 @@ fn quiet_content_reaches_the_target_or_is_transparent() { } } if spent.iter().all(|&s| s) { - assert!(measured[0] < measured[1] && measured[1] < measured[2], "{name}: {measured:?}"); + assert!( + measured[0] < measured[1] && measured[1] < measured[2], + "{name}: {measured:?}" + ); } } } @@ -800,7 +822,10 @@ fn residue_histogram_vs_reference() { ("reell", "~/Music/reell.mp4"), ("reelm", "~/Music/reelm.wav"), ("dl8a", "~/Downloads/8a3b6d1d19.mp3"), - ("hein", "~/Downloads/reelm.mp3"), + ( + "hein", + "~/Downloads/reelm.mp3", + ), ]; let bitrate = 128_000i32; let rate = 48_000u32; @@ -812,11 +837,17 @@ fn residue_histogram_vs_reference() { std::fs::create_dir_all(&out_dir).expect("out dir"); let mut report = String::new(); report.push_str("# Residue histogram: ours vs libvorbis reference\n\n"); - report.push_str(&format!("Bitrate: {} kbps, {} Hz, {}ch, {} s max\n\n", - bitrate / 1000, rate, channels, max_samples / rate as usize)); + report.push_str(&format!( + "Bitrate: {} kbps, {} Hz, {}ch, {} s max\n\n", + bitrate / 1000, + rate, + channels, + max_samples / rate as usize + )); let mut total_ours_bytes = 0u64; let mut total_ref_bytes = 0u64; + let mut rows = 0usize; for &(name, src_path) in sources { let expanded = shellexpand(src_path); let src = PathBuf::from(&expanded); @@ -824,6 +855,7 @@ fn residue_histogram_vs_reference() { report.push_str(&format!("## {name}: SKIP (file not found: {expanded})\n\n")); continue; } + rows += 1; // Decode source with ffmpeg, limit duration. let Some((source_pcm, src_rate)) = ffmpeg_decode_limited(&src, rate, max_samples) else { report.push_str(&format!("## {name}: SKIP (ffmpeg decode failed)\n\n")); @@ -856,9 +888,19 @@ fn residue_histogram_vs_reference() { // target; audio-only input encodes at the requested rate. .args(["-y", "-v", "error", "-i"]) .arg(&src) - .args(["-vn", "-t", &format!("{}", max_samples / rate as usize), - "-ac", "2", "-ar", "48000", - "-c:a", "libvorbis", "-b:a", "128k"]) + .args([ + "-vn", + "-t", + &format!("{}", max_samples / rate as usize), + "-ac", + "2", + "-ar", + "48000", + "-c:a", + "libvorbis", + "-b:a", + "128k", + ]) .arg(&ref_ogg) .status(); let (ref_residue, ref_split) = match ref_status { @@ -919,11 +961,27 @@ fn residue_histogram_vs_reference() { let r_spend: u64 = r[1..].iter().sum(); let ratio = if r_spend > 0 { o_spend as f64 / r_spend as f64 - } else { f64::INFINITY }; + } else { + f64::INFINITY + }; report.push_str(&format!( "| {} | {}/{} | {}/{} | {}/{} | {}/{} | {}/{} | {}/{} | {}/{} | {:.2} |\n", - band, o[0], r[0], o[1], r[1], o[2], r[2], o[3], r[3], o[4], r[4], o[5], r[5], - o_total, r_total, ratio, + band, + o[0], + r[0], + o[1], + r[1], + o[2], + r[2], + o[3], + r[3], + o[4], + r[4], + o[5], + r[5], + o_total, + r_total, + ratio, )); } @@ -967,18 +1025,26 @@ fn residue_histogram_vs_reference() { report.push_str(&format!( "\nshape Bark 3-22: max dist {max_d:.3}, bands >= 0.15: {over}/{} — {}\n", in_scope.len(), - if over == 0 { "SHAPE PASS" } else { "shape fail" }, + if over == 0 { + "SHAPE PASS" + } else { + "shape fail" + }, )); } report.push_str("\n"); } + // The seven sources are the user's own library, so each may be absent on a + // given host -- but a run that encoded none of them is a measurement of + // nothing, and the report it writes looks the same as a real one. + assert!(rows > 0, "no library sources were readable"); report.push_str(&format!( "\nTotal bytes: ours {total_ours_bytes} vs ref {total_ref_bytes} ({:.2}x)\n", total_ours_bytes as f64 / total_ref_bytes as f64, )); - let report_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../lanes/vorbis-psy-r1.histogram.txt"); + let report_path = + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../lanes/vorbis-psy-r1.histogram.txt"); let mut f = File::create(&report_path).expect("create report"); f.write_all(report.as_bytes()).expect("write report"); println!("Histogram report: {}", report_path.display()); @@ -1028,7 +1094,10 @@ fn decode_capture(path: &Path) -> Vec<(usize, Vec>)> { /// Bit split summed over the stream: (floor bits, residue bits, packet bits, /// non-zero residue count) — bits per coded value is the coding-efficiency oracle. -fn bit_split_summary(split: &[(u64, u64, u64)], residue: &[(usize, Vec>)]) -> (u64, u64, u64, u64) { +fn bit_split_summary( + split: &[(u64, u64, u64)], + residue: &[(usize, Vec>)], +) -> (u64, u64, u64, u64) { let (mut f, mut r, mut p) = (0u64, 0u64, 0u64); for &(a, b, c) in split { f += a; @@ -1037,7 +1106,11 @@ fn bit_split_summary(split: &[(u64, u64, u64)], residue: &[(usize, Vec> } let nz: u64 = residue .iter() - .map(|(_, chs)| chs.iter().map(|c| c.iter().filter(|&&v| v != 0).count() as u64).sum::()) + .map(|(_, chs)| { + chs.iter() + .map(|c| c.iter().filter(|&&v| v != 0).count() as u64) + .sum::() + }) .sum(); (f, r, p, nz) } @@ -1100,25 +1173,45 @@ fn compare_captures( } } if diffs.is_empty() { - (true, format!("identical histograms ({} vs {} blocks)", a.len(), b.len())) + ( + true, + format!("identical histograms ({} vs {} blocks)", a.len(), b.len()), + ) } else { - (false, format!( - "{} vs {} blocks; first diffs: {}", - a.len(), - b.len(), - diffs.iter().take(5).cloned().collect::>().join("; ") - )) + ( + false, + format!( + "{} vs {} blocks; first diffs: {}", + a.len(), + b.len(), + diffs.iter().take(5).cloned().collect::>().join("; ") + ), + ) } } /// Decode with ffmpeg into planar f32, resampled to `rate`, limited to `max_samples`. -fn ffmpeg_decode_limited(path: &Path, rate: u32, max_samples: usize) -> Option<(Vec>, u32)> { +fn ffmpeg_decode_limited( + path: &Path, + rate: u32, + max_samples: usize, +) -> Option<(Vec>, u32)> { let out = Command::new("ffmpeg") .args(["-v", "error", "-i"]) .arg(path) - .args(["-t", &format!("{}", max_samples / rate as usize), - "-ac", "2", "-ar", &rate.to_string(), - "-f", "f32le", "-acodec", "pcm_f32le", "-"]) + .args([ + "-t", + &format!("{}", max_samples / rate as usize), + "-ac", + "2", + "-ar", + &rate.to_string(), + "-f", + "f32le", + "-acodec", + "pcm_f32le", + "-", + ]) .output() .expect("ffmpeg runs"); if !out.stderr.is_empty() { @@ -1179,7 +1272,6 @@ fn shellexpand(path: &str) -> String { } } - /// Full-file sweep over the user's library at the two managed rates: ours /// encoded at the size libvorbis actually produced (ffmpeg's -b:a is /// unmanaged VBR, 10-30% under nominal on real music), bytes within ±3% of @@ -1196,19 +1288,28 @@ fn real_library_sweep_vs_reference() { ("reell", "~/Music/reell.mp4"), ("reelm", "~/Music/reelm.wav"), ("dl8a", "~/Downloads/8a3b6d1d19.mp3"), - ("hein", "~/Downloads/reelm.mp3"), + ( + "hein", + "~/Downloads/reelm.mp3", + ), ]; let rate = 48_000u32; let max_samples = rate as usize * 600; let out_dir = scratch().join("vorbis7-sweep"); std::fs::create_dir_all(&out_dir).expect("out dir"); - let mut table = String::from("source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap minsec_o minsec_r drops verdict\n"); + let mut table = String::from( + "source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap minsec_o minsec_r drops verdict\n", + ); let mut failures = Vec::new(); let only = std::env::var("SWEEP_ONLY").ok(); let dump_drops = std::env::var("DROPS_DUMP").is_ok(); let mut drops = String::new(); + let mut rows = 0usize; for &(name, src_path) in sources { - if only.as_deref().is_some_and(|o| !o.split(',').any(|n| n == name)) { + if only + .as_deref() + .is_some_and(|o| !o.split(',').any(|n| n == name)) + { continue; } let src = PathBuf::from(shellexpand(src_path)); @@ -1216,6 +1317,7 @@ fn real_library_sweep_vs_reference() { table.push_str(&format!("{name:<7} - SKIP (missing)\n")); continue; } + rows += 1; let Some((source_pcm, _)) = ffmpeg_decode_limited(&src, rate, max_samples) else { table.push_str(&format!("{name:<7} - SKIP (decode)\n")); continue; @@ -1229,14 +1331,31 @@ fn real_library_sweep_vs_reference() { let status = Command::new("ffmpeg") .args(["-y", "-v", "error", "-i"]) .arg(&src) - .args(["-vn", "-t", "600", "-ac", "2", "-ar", "48000", "-c:a", "libvorbis", "-b:a", &format!("{kbps}k")]) + .args([ + "-vn", + "-t", + "600", + "-ac", + "2", + "-ar", + "48000", + "-c:a", + "libvorbis", + "-b:a", + &format!("{kbps}k"), + ]) .arg(&reference) .status() .expect("ffmpeg runs"); assert!(status.success(), "libvorbis encode of {name} at {kbps}k"); let bytes = |p: &Path| std::fs::metadata(p).expect("size").len() as f64; let ref_kbps = bytes(&reference) * 8.0 / seconds / 1000.0; - let (ours, block_log) = encode_to_file_with_log(&source_pcm, rate, (ref_kbps * 1000.0).round() as i32, &format!("vorbis7-sweep/ours-{name}-{kbps}k.ogg")); + let (ours, block_log) = encode_to_file_with_log( + &source_pcm, + rate, + (ref_kbps * 1000.0).round() as i32, + &format!("vorbis7-sweep/ours-{name}-{kbps}k.ogg"), + ); let ours_kbps = bytes(&ours) * 8.0 / seconds / 1000.0; let rate_pct = (ours_kbps / ref_kbps - 1.0) * 100.0; // Whole-file corr plus a per-second trace: a dropout (the @@ -1246,12 +1365,18 @@ fn real_library_sweep_vs_reference() { let corr_of = |p: &Path| -> (f64, Vec) { let (pcm, _) = our_decode(p); let n = pcm[0].len().min(source_pcm[0].len()); - let mean = (0..2).map(|c| correlation(&pcm[c][..n], &source_pcm[c][..n])).sum::() / 2.0; + let mean = (0..2) + .map(|c| correlation(&pcm[c][..n], &source_pcm[c][..n])) + .sum::() + / 2.0; let step = rate as usize; let per_second = (0..n / step) .map(|s| { let r = s * step..(s + 1) * step; - (0..2).map(|c| correlation(&pcm[c][r.clone()], &source_pcm[c][r.clone()])).sum::() / 2.0 + (0..2) + .map(|c| correlation(&pcm[c][r.clone()], &source_pcm[c][r.clone()])) + .sum::() + / 2.0 }) .collect(); (mean, per_second) @@ -1275,7 +1400,9 @@ fn real_library_sweep_vs_reference() { .collect(); let pass = rate_pct.abs() <= 3.0 && gap <= 0.005 && dropouts == 0; if !pass { - failures.push(format!("{name}@{kbps}k rate {rate_pct:+.2}% gap {gap:.4} dropouts {dropouts}")); + failures.push(format!( + "{name}@{kbps}k rate {rate_pct:+.2}% gap {gap:.4} dropouts {dropouts}" + )); } table.push_str(&format!( "{name:<7} {kbps:<6} {ours_kbps:<9.1} {ref_kbps:<8.1} {rate_pct:+6.2} {corr_ours:<9.4} {corr_ref:<8.4} {gap:<7.4} {min_ours:<8.3} {min_ref:<7.3} {dropouts:<5} {}\n", @@ -1326,6 +1453,7 @@ fn real_library_sweep_vs_reference() { Path::new(env!("CARGO_MANIFEST_DIR")).join("../../lanes/vorbis-psy-r1.sweep.txt"), &table, ); + assert!(rows > 0, "no library sources were readable"); assert!(failures.is_empty(), "sweep failures: {failures:?}"); } @@ -1385,7 +1513,10 @@ fn band_error_vs_reference() { ("reell", "~/Music/reell.mp4"), ("reelm", "~/Music/reelm.wav"), ("dl8a", "~/Downloads/8a3b6d1d19.mp3"), - ("hein", "~/Downloads/reelm.mp3"), + ( + "hein", + "~/Downloads/reelm.mp3", + ), ]; let rate = 48_000u32; let max_samples = rate as usize * 600; @@ -1412,8 +1543,12 @@ fn band_error_vs_reference() { let mut bands = String::from("# Band error: ours vs libvorbis, both via our decoder\n\n"); let mut bits = String::from("# Bit split over full sources, same rows as the band error\n\n"); let only = std::env::var("SWEEP_ONLY").ok(); + let mut rows = 0usize; for &(name, src_path) in sources { - if only.as_deref().is_some_and(|o| !o.split(',').any(|n| n == name)) { + if only + .as_deref() + .is_some_and(|o| !o.split(',').any(|n| n == name)) + { continue; } let src = PathBuf::from(shellexpand(src_path)); @@ -1421,6 +1556,7 @@ fn band_error_vs_reference() { bands.push_str(&format!("## {name}: SKIP (missing)\n\n")); continue; } + rows += 1; let Some((source_pcm, _)) = ffmpeg_decode_limited(&src, rate, max_samples) else { bands.push_str(&format!("## {name}: SKIP (decode)\n\n")); continue; @@ -1433,7 +1569,19 @@ fn band_error_vs_reference() { let status = Command::new("ffmpeg") .args(["-y", "-v", "error", "-i"]) .arg(&src) - .args(["-vn", "-t", "600", "-ac", "2", "-ar", "48000", "-c:a", "libvorbis", "-b:a", &format!("{kbps}k")]) + .args([ + "-vn", + "-t", + "600", + "-ac", + "2", + "-ar", + "48000", + "-c:a", + "libvorbis", + "-b:a", + &format!("{kbps}k"), + ]) .arg(&reference) .status() .expect("ffmpeg runs"); @@ -1457,7 +1605,10 @@ fn band_error_vs_reference() { }; let (ref_pcm, ref_split) = { let (residue, split) = decode_capture_with_bits(&reference); - (our_decode(&reference).0, bit_split_summary(&split, &residue)) + ( + our_decode(&reference).0, + bit_split_summary(&split, &residue), + ) }; // Bit-split block: (floor, residue, packet, non-zero) per stream. @@ -1494,8 +1645,9 @@ fn band_error_vs_reference() { let (mut e_src, mut e_ours, mut e_ref) = (vec![0f64; nb], vec![0f64; nb], vec![0f64; nb]); let (mut err_ours, mut err_ref) = (vec![0f64; nb], vec![0f64; nb]); - let mut spec: Vec<(Vec, Vec)> = - (0..3).map(|_| (vec![0.0; FRAME], vec![0.0; FRAME])).collect(); + let mut spec: Vec<(Vec, Vec)> = (0..3) + .map(|_| (vec![0.0; FRAME], vec![0.0; FRAME])) + .collect(); let mut start = 0; while start + FRAME <= n { for ch in 0..2 { @@ -1523,7 +1675,13 @@ fn band_error_vs_reference() { } start += HOP; } - let db = |e: f64, s: f64| if s > 0.0 { 10.0 * (e / s).log10() } else { f64::NAN }; + let db = |e: f64, s: f64| { + if s > 0.0 { + 10.0 * (e / s).log10() + } else { + f64::NAN + } + }; bands.push_str(&format!( "## {name} @ {kbps}k (ours {ours_kbps:.1} vs ref {ref_kbps:.1} kbps)\n" )); @@ -1560,13 +1718,16 @@ fn band_error_vs_reference() { ); } } + // Both report files above are written unconditionally, so a run that + // measured no source writes a report indistinguishable from a real one. + assert!(rows > 0, "no library sources were readable"); for (text, file) in [ (&bands, "vorbis-psy-r1.bands.txt"), (&bits, "vorbis-psy-r1.bits.txt"), ] { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("../../lanes") - .join(file); + .join(file); let mut f = File::create(&path).expect("create report"); f.write_all(text.as_bytes()).expect("write report"); println!("{file}: {}", path.display()); diff --git a/crates/ec-vp9/tests/hbd_exact.rs b/crates/ec-vp9/tests/hbd_exact.rs index bcd4d984..893180f8 100644 --- a/crates/ec-vp9/tests/hbd_exact.rs +++ b/crates/ec-vp9/tests/hbd_exact.rs @@ -3,21 +3,47 @@ //! yuv420p10le -`). Pre-fix the decoder refuses `profile 2` by name, so this //! test fails at the first frame; post-fix every shown frame matches. //! -//! Media-gated: the 10-bit corpus streams are gitignored, so the test skips -//! by name when the fixture is absent (set the fixture tree up per the lane -//! notes). The 4:4:4 and 12-bit shapes are covered by `subsampling_exact.rs`. +//! Media-gated: the 10-bit corpus streams are gitignored, so the test prints +//! SKIP when the fixture is absent (set the fixture tree up per the lane +//! notes) -- and goes RED instead under `EC_REQUIRE_FIXTURES=1`, so a drifted +//! fixture library can never read as a pass. The 4:4:4 and 12-bit shapes are +//! covered by `subsampling_exact.rs`. mod ivf; use ec_vp9::decode::Decoder; use std::path::{Path, PathBuf}; -fn fixture(name: &str) -> Option { +/// Fixture-presence probe for the 10-bit corpus IVF `profile2_10bit_is_byte_exact` +/// decodes and compares against ffmpeg. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + +fn fixture(name: &str) -> PathBuf { let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR")); p.pop(); p.pop(); - p = p.join("fixtures/bitstreams").join(name); - p.exists().then_some(p) + p.join("fixtures/bitstreams").join(name) } /// ffmpeg's rawvideo `yuv420p10le` bytes (little-endian u16 samples, @@ -56,10 +82,10 @@ fn decode_all(path: &Path) -> (Vec>, u8) { /// produces, sample for sample. #[test] fn profile2_10bit_is_byte_exact() { - let Some(a) = fixture("vp9-1080p-23.976-10bit.ivf") else { - eprintln!("SKIP profile2_10bit_is_byte_exact: 10-bit fixture absent"); + let a = fixture("vp9-1080p-23.976-10bit.ivf"); + if !require_fixture(&a, "scripts/gen-bitstream-fixtures.sh") { return; - }; + } let (ours, bd) = decode_all(&a); assert_eq!(bd, 10, "the fixture must decode at 10 bits"); let want = ffmpeg_raw_yuv10(&a); diff --git a/crates/ec-vp9/tests/inter_pixels_exact.rs b/crates/ec-vp9/tests/inter_pixels_exact.rs index 689beed4..795d4c16 100644 --- a/crates/ec-vp9/tests/inter_pixels_exact.rs +++ b/crates/ec-vp9/tests/inter_pixels_exact.rs @@ -9,6 +9,30 @@ mod ivf; use ec_vp9::decode::Decoder; +/// Fixture-presence probe for the 120-frame 1080p corpus IVF +/// `corpus_1080p_60fps_matches_ffmpeg_past_frame_72` decodes. +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} /// Generate a GOP fixture with libvpx: 6 frames of testsrc2 at 320x240, /// `-g 10` so frames 1..5 are inter frames. @@ -137,17 +161,14 @@ fn inter_gop_with_tile_columns_matches_ffmpeg() { /// TAIL slot set (`write_tx_context`), and the next row of blocks read it /// as an entropy context. Every shown frame must match ffmpeg. /// -/// Media-gated: the corpus fixture is not versioned, so the witness skips -/// when `fixtures/bitstreams/vp9-1080p-60-8bit.ivf` is absent. +/// Media-gated: the corpus fixture is not versioned, so the witness prints +/// SKIP when `fixtures/bitstreams/vp9-1080p-60-8bit.ivf` is absent -- and goes +/// RED instead under `EC_REQUIRE_FIXTURES=1`. #[test] fn corpus_1080p_60fps_matches_ffmpeg_past_frame_72() { - let Some(dir) = ivf::fixture_dir() else { - println!("SKIP: fixtures/bitstreams absent (media-gated witness)"); - return; - }; - let path = dir.join("vp9-1080p-60-8bit.ivf"); - if !path.exists() { - println!("SKIP: {} absent (media-gated witness)", path.display()); + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../fixtures/bitstreams/vp9-1080p-60-8bit.ivf"); + if !require_fixture(&path, "scripts/gen-bitstream-fixtures.sh") { return; } let shown = compare(&path); diff --git a/crates/ec-vp9/tests/scratch_interdump.rs b/crates/ec-vp9/tests/scratch_interdump.rs index 7eca0835..08c31aab 100644 --- a/crates/ec-vp9/tests/scratch_interdump.rs +++ b/crates/ec-vp9/tests/scratch_interdump.rs @@ -27,6 +27,30 @@ mod ivf; use ec_vp9::decode::Decoder; +/// Fixture-presence probe for the inter-frame IVF this gate parses (the +/// `INTER_IVF` path, or its generated `/tmp/inter1.ivf` default). +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and how to regenerate it, so a host whose fixture library drifted reports +/// RED instead of a green SKIP (class: gate-skips-on-its-own-failure; model +/// `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} #[test] fn inter_syntax_dump() { @@ -43,17 +67,25 @@ fn inter_syntax_dump() { } else { expect_raw .split(',') - .map(|t| t.trim().parse().expect("INTER_EXPECT entries are block counts")) + .map(|t| { + t.trim() + .parse() + .expect("INTER_EXPECT entries are block counts") + }) .collect() }; - let Ok(bytes) = std::fs::read(&path) else { + if !require_fixture( + std::path::Path::new(&path), + "INTER_IVF=; the default is generated, not committed \ + (ffmpeg -f lavfi -i testsrc2=... -c:v libvpx-vp9 -f ivf)", + ) { assert!( explicit.is_none(), "INTER_IVF={path} was set explicitly but the file does not exist" ); - println!("SKIP: fixture {path} not found - set INTER_IVF= to run"); return; - }; + } + let bytes = std::fs::read(&path).expect("fixture presence was just probed"); let (_fourcc, w, h, frames) = ivf::parse_ivf(&bytes); println!("IVF {w}x{h} frames={}", frames.len()); let mut dec = Decoder::new(); diff --git a/crates/ec-vp9/tests/subsampling_exact.rs b/crates/ec-vp9/tests/subsampling_exact.rs index 348a4aa7..49ad3fe3 100644 --- a/crates/ec-vp9/tests/subsampling_exact.rs +++ b/crates/ec-vp9/tests/subsampling_exact.rs @@ -5,7 +5,9 @@ //! Every fixture under `tests/data/` is committed (see the lane report for //! the exact generator commands), so these cases always run; the two //! `corpus_*` cases additionally cover the media-gated 4:4:4 corpus streams -//! and skip by name when the fixture tree is absent. +//! and print SKIP when the fixture is absent -- RED instead under +//! `EC_REQUIRE_FIXTURES=1`, so a drifted fixture library can never read as a +//! pass. //! //! The comparison is the whole flattened plane stream (u16 samples) against //! ffmpeg's `rawvideo` output for the matching `pix_fmt` — full-resolution @@ -17,18 +19,42 @@ mod ivf; use ec_vp9::decode::Decoder; use std::path::{Path, PathBuf}; +/// Fixture-presence probe for the media-gated 4:4:4 corpus IVFs the `corpus_*` +/// cases decode (`corpus()` below, and any path a `scripts/*` generator makes). +/// Returns whether the fixture is present, but never silently: under +/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path +/// and the script that regenerates it, so a host whose fixture library drifted +/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; +/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently +/// short-circuited because the probe ran first in a compound `if`). +/// +/// Order is load-bearing: probe, assert, return. Never merge the probe into +/// the same `if` as the escape. +fn require_fixture(path: &std::path::Path, generator: &str) -> bool { + let present = path.exists(); + assert!( + present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), + "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", + path.display(), + generator + ); + if !present { + eprintln!("SKIP: fixture {} absent", path.display()); + } + present +} + fn data(name: &str) -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")) .join("tests/data") .join(name) } -fn corpus(name: &str) -> Option { +fn corpus(name: &str) -> PathBuf { let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR")); p.pop(); p.pop(); - let p = p.join("fixtures/bitstreams").join(name); - p.exists().then_some(p) + p.join("fixtures/bitstreams").join(name) } /// ffmpeg's decoded samples as a flat u16 stream (8-bit zero-extended, @@ -133,18 +159,18 @@ fn profile2_420_12bit_is_byte_exact() { #[test] fn corpus_profile1_444_matches_ffmpeg() { - let Some(p) = corpus("vp9-profile1-444.ivf") else { - eprintln!("SKIP corpus_profile1_444_matches_ffmpeg: fixture absent"); + let p = corpus("vp9-profile1-444.ivf"); + if !require_fixture(&p, "scripts/gen-bitstream-fixtures.sh") { return; - }; + } check(&p, "yuv444p", 8); } #[test] fn corpus_profile3_444_10bit_matches_ffmpeg() { - let Some(p) = corpus("vp9-profile3-444-10bit.ivf") else { - eprintln!("SKIP corpus_profile3_444_10bit_matches_ffmpeg: fixture absent"); + let p = corpus("vp9-profile3-444-10bit.ivf"); + if !require_fixture(&p, "scripts/gen-bitstream-fixtures.sh") { return; - }; + } check(&p, "yuv444p10le", 10); } diff --git a/scripts/fixture-library.tsv b/scripts/fixture-library.tsv new file mode 100644 index 00000000..be58a66c --- /dev/null +++ b/scripts/fixture-library.tsv @@ -0,0 +1,280 @@ +# GENERATED by scripts/gen-fixture-library.sh -- do not hand-edit. +# Regenerate: scripts/gen-fixture-library.sh +# Verify: scripts/verify-fixture-library.sh +# path required-by file:line provenance status sha256 +# +# Enumeration is grep-derived. It cannot see a fixture name that is not a +# string literal in the same file (manifest rows, vectors.sha256 names, +# format! interpolation); such names are only covered through their parent +# directory, which the verifier requires to exist AND be non-empty. +# 191 media-name literal(s) in this tree resolved under no enumerated +# fixture directory and are therefore not listed individually. +# +# ROOT FIXTURE ROOT: /home/user/.cache/wt/av1fixlib/fixtures +# +# VECTORS consumers (fixtures/vectors/*): crates/ec-flac/tests/xiph_vectors.rs crates/ec-h264/tests/conformance.rs crates/ec-opus/tests/conformance.rs +# VECTORS .tar.gz blob referenced by: nothing +# The three fleet hosts carry the EXTRACTED vector sets (~470 files) and the +# sync deliberately excluded the .tar.gz blobs; nothing in crates/ reads a +# blob, so the extracted directories are the whole requirement. +# Unreferenced committed pins carried as rows: 4 +crates/ec-av1/fixtures/420_intrabc_rect4_witness.obu crates/ec-av1/src/stream.rs:7434 none (prose provenance only) ok d01352af5059919cdce733abdcbae8e8240ac3c2a6190fa1bd96d3c6f945b979 +crates/ec-av1/fixtures/422_allskip_2f.obu crates/ec-av1/src/stream.rs:2295 none (prose provenance only) ok ba4932c14f95971b5f25321b04abce80c9fdd5de4b1fe6fffcdad82aaea87ce1 +crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obu crates/ec-av1/src/stream.rs:2357 none (prose provenance only) ok 80dd0d4e93fd6c3d4b7188a43e69d9638f2bece38edfab60ff3582628314b5ec +crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu crates/ec-av1/src/stream.rs:2352 none (prose provenance only) ok f92000db86df7acc577d60dd1d0d97454bff4705799ea59d9de34eb5a71dbbcd +crates/ec-av1/fixtures/422_residual_compound_warp_16f.obu crates/ec-av1/src/stream.rs:2574 none (prose provenance only) ok d78e2afb43ce311d3d82335a945c6f80f62db4537966d881c1349a68b3aecb95 +crates/ec-av1/fixtures/422_residual_compound_warp_nolr_16f.obu crates/ec-av1/src/stream.rs:2653 none (prose provenance only) ok 8bed368f7ec4bca772137c6a9c2af89e1b2767ed5f937b91bd9e72ec60aeb42f +crates/ec-av1/fixtures/422_sb128_3f.obu crates/ec-av1/src/stream.rs:2296 none (prose provenance only) ok 0b851799d99cb4d141a7d042138a3999aad7e0fb24d69c670bca1d38c286dce9 +crates/ec-av1/fixtures/444_intrabc_rect4_witness.obu crates/ec-av1/src/stream.rs:7428 none (prose provenance only) ok 7fe888edf18caa74bdb415f0de643dc59963e87e0255d77191200b7a62eb2542 +crates/ec-av1/fixtures/444_leaf8_oob.obu crates/ec-av1/src/stream.rs:7853 none (prose provenance only) ok 72bed2791d1ceba8be7926a052c7838c5d96d4f9d56d28fb69789a753d3593af +crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu crates/ec-av1/src/stream.rs:7248 none (prose provenance only) ok 77f727e76d81fe48cd03709f799131677c04869b163e18d78e96bc742ec69153 +crates/ec-av1/fixtures/444_quad_leaf_tx_type.obu crates/ec-av1/src/stream.rs:19221 none (prose provenance only) ok a06c9f7a0862252f6ab7ebdcec340d0602e730e38089365f14747db37f8e78d5 +crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu crates/ec-av1/src/stream.rs:13207 none (prose provenance only) ok 27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80 +crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu crates/ec-av1/src/stream.rs:7042 none (prose provenance only) ok 27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80 +crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu crates/ec-av1/src/stream.rs:7525 none (prose provenance only) ok 27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80 +crates/ec-av1/fixtures/av112bit-compound-masked.obu (committed pin: NO source reference found) none (prose provenance only) ok 83625de2ed347d457eb67f9781eed3fea598ef035f29bbc311d7025fe178c691 +crates/ec-av1/fixtures/av112bit-compound.obu (committed pin: NO source reference found) none (prose provenance only) ok a839cff534b89d5cd52681dd43a7dedc10131d8dd7725bdfa5502d6bc4421740 +crates/ec-av1/fixtures/av112bit-inter.obu (committed pin: NO source reference found) none (prose provenance only) ok e679d577e61b4a8bc99685355cca8c0473cfb637284b07786a6c53b1755553d9 +crates/ec-av1/fixtures/av112bit-key.obu (committed pin: NO source reference found) none (prose provenance only) ok c74f62b57f71f7c36c49ea1feeb482786a2650e5c7f66610949b5f65fbbed8d1 +crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu crates/ec-av1/src/stream.rs:19154 none (prose provenance only) ok e4cff46cb1700527c68efc866db27a2835705e949d646f73f0c9df577d594bd6 +crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu crates/ec-av1/src/stream.rs:19254 none (prose provenance only) ok e4cff46cb1700527c68efc866db27a2835705e949d646f73f0c9df577d594bd6 +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:13210 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:13259 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:13316 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:2299 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:2363 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:2578 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:2657 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:42059 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:42136 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures crates/ec-av1/src/stream.rs:8661 scripts/gen-fixtures.sh ok - +crates/ec-av1/fixtures/filter_intra_8x16_strip_seed49.obu crates/ec-av1/src/stream.rs:36907 none (prose provenance only) ok 6f837e47ad0a67f31c3998aa789cf0811e7540ac2114981853a0148744cb76c2 +crates/ec-av1/fixtures/gm_small_side_witness.obu crates/ec-av1/src/stream.rs:42064 none (prose provenance only) ok f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca +crates/ec-av1/fixtures/gm_small_side_witness.obu crates/ec-av1/src/stream.rs:42141 none (prose provenance only) ok f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca +crates/ec-av1/fixtures/gm_small_side_witness.obu crates/ec-av1/src/stream.rs:42224 none (prose provenance only) ok f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca +crates/ec-av1/fixtures/grain_cdef_lr_128x128.obu crates/ec-av1/src/stream.rs:13313 none (prose provenance only) ok 06f210b87b5c79eb729c559050e073abbe226c4dad1df3dcaa113b03011ad732 +crates/ec-av1/fixtures/reelb_arf_witness.obu crates/ec-av1/src/stream.rs:13198 none (prose provenance only) ok 7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37 +crates/ec-av1/fixtures/reelb_arf_witness.obu crates/ec-av1/src/stream.rs:41286 none (prose provenance only) ok 7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37 +crates/ec-av1/fixtures/reelb_arf_witness.obu crates/ec-av1/src/stream.rs:41368 none (prose provenance only) ok 7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37 +crates/ec-av1/fixtures/reelb_head_key_frame.obu crates/ec-av1/src/stream.rs:13451 none (prose provenance only) ok 53c311dec790bb2413afdde92cb24de498a7c4f66f6f0c7f4f5910ab0d2c65dc +crates/ec-av1/fixtures/reelb_head_mvclamp_witness.obu crates/ec-av1/src/stream.rs:42306 none (prose provenance only) ok 451a9b138995e636f22308847a123b5c8621d4908cd93772cf5bbf2b37df39d7 +crates/ec-av1/fixtures/reelb_intra14_witness.obu crates/ec-av1/src/stream.rs:41115 none (prose provenance only) ok 0eff603bf1608e47faf5e6729670c4c77cf5c674dbad3a1533ac6660151fd90e +crates/ec-av1/fixtures/reelb_kf900.obu crates/ec-av1/src/stream.rs:13593 none (prose provenance only) ok a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83 +crates/ec-av1/fixtures/reelb_kf900.obu crates/ec-av1/src/stream.rs:43081 none (prose provenance only) ok a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83 +crates/ec-av1/fixtures/reelb_rect64_intra16x4_witness.obu crates/ec-av1/src/stream.rs:41204 none (prose provenance only) ok c9e721088766163b9dbeb9fa8dd8b257ff0ec7f9157fc350de4d3c33cd9ec4e4 +crates/ec-av1/fixtures/reelb_ss300_key_frame.obu crates/ec-av1/src/stream.rs:13542 none (prose provenance only) ok 7e3ddf0d602f9496b2f7eb11f051fd4a045020e094d5bc02f83825e2c494ef12 +crates/ec-av1/fixtures/reelb_ss600_key_frame.obu crates/ec-av1/src/stream.rs:13634 none (prose provenance only) ok 36de46676ed7de7049d4dabe8571d8cd31c8a1f53d72011c0ee532a7c6725cd6 +crates/ec-av1/fixtures/intra128_in_inter_screen_witness.obu crates/ec-av1/src/stream.rs:41786 none (prose provenance only) ok c84a493f90327f5d2bea038a42e87cbfe56762b5c6a856d76b4bff9797c5ea09 +crates/ec-av1/fixtures/intra128_in_inter_witness2.obu crates/ec-av1/src/stream.rs:41718 none (prose provenance only) ok cace4cc3a5ba4dc5f8c7c219e87c9052351e832cad3d7f4c8ffe09288a6d7ccf +crates/ec-av1/fixtures/intra128_in_inter_witness2.obu crates/ec-av1/src/stream.rs:42063 none (prose provenance only) ok cace4cc3a5ba4dc5f8c7c219e87c9052351e832cad3d7f4c8ffe09288a6d7ccf +crates/ec-av1/fixtures/intra128_in_inter_witness2.obu crates/ec-av1/src/stream.rs:42140 none (prose provenance only) ok cace4cc3a5ba4dc5f8c7c219e87c9052351e832cad3d7f4c8ffe09288a6d7ccf +crates/ec-av1/fixtures/intra128_in_inter_witness.obu crates/ec-av1/src/stream.rs:41622 none (prose provenance only) ok dd41fc39367a3d38bf8a8a8106dc30d91b716b2a9123fdfa4716930f4f98caf9 +crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu crates/ec-av1/src/stream.rs:11185 none (prose provenance only) ok bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd +crates/ec-av1/fixtures/ll444_128root_lossless.obu crates/ec-av1/src/stream.rs:6791 none (prose provenance only) ok bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa +crates/ec-av1/fixtures/ll444_defaultp_inter_strip.obu crates/ec-av1/src/stream.rs:7701 none (prose provenance only) ok 1e6dd4e05038c8d51e2c8d29f8c337130c4fea0aed629415535e6e53af9a2c72 +crates/ec-av1/fixtures/ll444_ibc_rect.obu crates/ec-av1/src/stream.rs:8270 none (prose provenance only) ok 482dedca0201beea9b0a05720b5da7fe93c350c9fea7699cdb010c3fbc227ec0 +crates/ec-av1/fixtures/ll444_minp64_128root_control.obu crates/ec-av1/src/stream.rs:6842 none (prose provenance only) ok 4cadce41e1f8967567b32f5cf8abaa46ffdf4fd6d4afe784c8d99a7f6bf1ae4c +crates/ec-av1/fixtures/ll444_minp64_inter.obu crates/ec-av1/src/stream.rs:6640 none (prose provenance only) ok 5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4 +crates/ec-av1/fixtures/ll444_minp8_inter.obu crates/ec-av1/src/stream.rs:6899 none (prose provenance only) ok 04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc +crates/ec-av1/fixtures/ll444_rect16x4_chroma_reach.obu crates/ec-av1/src/stream.rs:10259 none (prose provenance only) ok 382e67c0cc0988d14c500a62f5c3457a3f3b5f76d05acce2f655b1089bb8e7e3 +crates/ec-av1/fixtures/lossless_sb128_rect_kf.obu crates/ec-av1/src/stream.rs:7949 none (prose provenance only) ok 013b07979c8be999c70d47f32768c2bf959be086a893f60dde1b0f5e35d4f475 +crates/ec-av1/fixtures/palette_screen_leaf8_witness.obu crates/ec-av1/src/stream.rs:41962 none (prose provenance only) ok 8d036606116913c82b774286bb0a3efe616d54151784897ba62b13d12fdef06e +crates/ec-av1/fixtures/palette_screen_strip16_witness_10bit.obu crates/ec-av1/src/stream.rs:42006 none (prose provenance only) ok aaabbb001d87f61ee534fd17c2d558ad906d1c33d357decb86cfd26e593da0db +crates/ec-av1/fixtures/palette_screen_witness_10bit.obu crates/ec-av1/src/stream.rs:13200 none (prose provenance only) ok a60a8bc132e5db7bed3eb46e03e9ed9828811bdffb96914958f3c94b107c3cda +crates/ec-av1/fixtures/palette_screen_witness_10bit.obu crates/ec-av1/src/stream.rs:41881 none (prose provenance only) ok a60a8bc132e5db7bed3eb46e03e9ed9828811bdffb96914958f3c94b107c3cda +crates/ec-av1/fixtures/palette_screen_witness.obu crates/ec-av1/src/stream.rs:13199 none (prose provenance only) ok 635a512b866f0fab7d45eb4f94f2a5b15008fe5a5317ac1ca45ffd3381198b8b +crates/ec-av1/fixtures/palette_screen_witness.obu crates/ec-av1/src/stream.rs:41287 none (prose provenance only) ok 635a512b866f0fab7d45eb4f94f2a5b15008fe5a5317ac1ca45ffd3381198b8b +crates/ec-av1/fixtures/palette_screen_witness.obu crates/ec-av1/src/stream.rs:41880 none (prose provenance only) ok 635a512b866f0fab7d45eb4f94f2a5b15008fe5a5317ac1ca45ffd3381198b8b +crates/ec-av1/fixtures/superres_alltools_sb128_320x180.obu crates/ec-av1/src/stream.rs:13260 none (prose provenance only) ok e2b515ce487acd2d720d5a000a6f26e66fd03ef2b1a4cb12daa6fdf31a55d519 +crates/ec-av1/fixtures/superres_alltools_sb128_320x180.obu crates/ec-av1/src/stream.rs:13312 none (prose provenance only) ok e2b515ce487acd2d720d5a000a6f26e66fd03ef2b1a4cb12daa6fdf31a55d519 +crates/ec-av1/fixtures/superres_alltools_sb128_320x180.obu crates/ec-av1/src/stream.rs:13415 none (prose provenance only) ok e2b515ce487acd2d720d5a000a6f26e66fd03ef2b1a4cb12daa6fdf31a55d519 +crates/ec-av1/fixtures/superres_kf_cdef_lr_64x64.obu crates/ec-av1/src/stream.rs:13145 none (prose provenance only) ok 5912e251bcd5d0f284f647616f91b19b579238c16fa85c0294a06548088d7336 +crates/ec-av1/fixtures/reelc_kf2700.obu crates/ec-av1/src/stream.rs:13489 none (prose provenance only) ok 16981094eaab516bd1007b0a47d1fc653fbb58b7e18a40af6c12d934bf96fe63 +crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu crates/ec-av1/src/stream.rs:41459 none (prose provenance only) ok 09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc +crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu crates/ec-av1/src/stream.rs:42062 none (prose provenance only) ok 09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc +crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu crates/ec-av1/src/stream.rs:42139 none (prose provenance only) ok 09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc +fixtures/audio/aac-adts-5.1-44100.aac crates/ec-aac/tests/oracle.rs:151 scripts/gen-fixtures.sh ok 2b615b45e7c45136e2d477bd5ed489822ddadcb5f1b7fe2da0a66dcc288881b4 +fixtures/audio/aac-adts-5.1-48000.aac crates/ec-aac/tests/oracle.rs:152 scripts/gen-fixtures.sh ok f416a2059766b6ce751bdf272836897c191073ca9f4f302552e949eeeeb01a44 +fixtures/audio/aac-adts-5.1-48000.aac crates/ec-probe/tests/matrix.rs:95 scripts/gen-fixtures.sh ok f416a2059766b6ce751bdf272836897c191073ca9f4f302552e949eeeeb01a44 +fixtures/audio/aac-adts-mono-44100.aac crates/ec-aac/tests/oracle.rs:147 scripts/gen-fixtures.sh ok 19b3870bc9e6e87dd20f448795899514e8cf5abfc770173c4c928468811dbdb7 +fixtures/audio/aac-adts-mono-44100.aac crates/ec-probe/tests/matrix.rs:93 scripts/gen-fixtures.sh ok 19b3870bc9e6e87dd20f448795899514e8cf5abfc770173c4c928468811dbdb7 +fixtures/audio/aac-adts-mono-48000.aac crates/ec-aac/tests/oracle.rs:148 scripts/gen-fixtures.sh ok 8e65736140a0dc7939060569250611ab822c7f489bddca3c0934728648c99180 +fixtures/audio/aac-adts-stereo-44100.aac crates/ec-aac/tests/oracle.rs:149 scripts/gen-fixtures.sh ok 99cf6fad337acd097dabfb22b165984feedcf0f47427d093be7f5f76b5f515dd +fixtures/audio/aac-adts-stereo-48000.aac crates/ec-aac/tests/oracle.rs:150 scripts/gen-fixtures.sh ok 3a8ce7512b5d8f9bda4f4e605023a2e68d793f4bc7697bbcd7c92e419b21edca +fixtures/audio/aac-adts-stereo-48000.aac crates/ec-probe/tests/matrix.rs:94 scripts/gen-fixtures.sh ok 3a8ce7512b5d8f9bda4f4e605023a2e68d793f4bc7697bbcd7c92e419b21edca +fixtures/audio/aac-mka-stereo-48000.mka crates/ec-probe/src/lib.rs:1145 scripts/gen-fixtures.sh ok 5ca5f13047f8f5a3e1876aa0d8d0c22251a45d0220e7c95326aea52e184c9260 +fixtures/audio/aac-mp4-5.1-44100.mp4 crates/ec-probe/tests/matrix.rs:97 scripts/gen-fixtures.sh ok 6e9ec3be717f3dcd011a1ac832f04405897a406ef21f831dc7ee04ab70880680 +fixtures/audio/aac-mp4-5.1-48000.mp4 crates/ec-aac/tests/oracle.rs:187 scripts/gen-fixtures.sh ok 5896e86836a0717e34b27ee44510cb879fe5460e53dfdd9f4c75cf0be432ba8a +fixtures/audio/aac-mp4-mono-48000.mp4 crates/ec-aac/tests/oracle.rs:185 scripts/gen-fixtures.sh ok 787b45a7348acdde7fc8f9793ce9edc587b1df5ab98cba79eea0f2744c10c633 +fixtures/audio/aac-mp4-stereo-48000.mp4 crates/ec-aac/tests/oracle.rs:186 scripts/gen-fixtures.sh ok 68b9f0d0e99868c010743362ffc03126a1a6b69fce4f3740bdfa0c8c06f7e57b +fixtures/audio/aac-mp4-stereo-48000.mp4 crates/ec-probe/tests/matrix.rs:96 scripts/gen-fixtures.sh ok 68b9f0d0e99868c010743362ffc03126a1a6b69fce4f3740bdfa0c8c06f7e57b +fixtures/audio/alac24-mp4-5.1-48000.m4a crates/ec-alac/tests/oracle.rs:72 scripts/gen-fixtures.sh ok b9007c453614808e4f5f777e51bef7baab1419c80b7d502c9e30a60878aa6de5 +fixtures/audio/alac24-mp4-stereo-48000.m4a crates/ec-alac/tests/oracle.rs:71 scripts/gen-fixtures.sh ok cf3fffc6723e86344c1d2d626d4e1e22f5164bdf7ccccad1d6052b2ce70409ae +fixtures/audio/alac24-mp4-stereo-48000.m4a crates/ec-probe/tests/matrix.rs:100 scripts/gen-fixtures.sh ok cf3fffc6723e86344c1d2d626d4e1e22f5164bdf7ccccad1d6052b2ce70409ae +fixtures/audio/alac-mp4-5.1-44100.m4a crates/ec-alac/tests/oracle.rs:69 scripts/gen-fixtures.sh ok 037c576aa9f0ebe4dff5a0b41278d9ea1967b3a1eaf0fb9b893ff00e2dbccdf1 +fixtures/audio/alac-mp4-5.1-48000.m4a crates/ec-alac/tests/oracle.rs:70 scripts/gen-fixtures.sh ok d9e224c52f2efc71cb6be4d18e840d58a941eafe96d80fe6b219f605aebb7d01 +fixtures/audio/alac-mp4-5.1-48000.m4a crates/ec-probe/tests/matrix.rs:99 scripts/gen-fixtures.sh ok d9e224c52f2efc71cb6be4d18e840d58a941eafe96d80fe6b219f605aebb7d01 +fixtures/audio/alac-mp4-mono-44100.m4a crates/ec-alac/tests/oracle.rs:65 scripts/gen-fixtures.sh ok c390c7674f81a3bdea622f4bcace2b593aae848e26563e09929b32a99a2a9869 +fixtures/audio/alac-mp4-mono-48000.m4a crates/ec-alac/tests/oracle.rs:66 scripts/gen-fixtures.sh ok d765d1adbba124e97c8bcb27a0a2e5aa7b3a181c0c1d7d134a18675f62597205 +fixtures/audio/alac-mp4-stereo-44100.m4a crates/ec-alac/tests/oracle.rs:112 scripts/gen-fixtures.sh ok 014d2691a0f8490e4d5da626e046d2680ff554db72cfdc688c5697c1bc350114 +fixtures/audio/alac-mp4-stereo-44100.m4a crates/ec-alac/tests/oracle.rs:67 scripts/gen-fixtures.sh ok 014d2691a0f8490e4d5da626e046d2680ff554db72cfdc688c5697c1bc350114 +fixtures/audio/alac-mp4-stereo-44100.m4a crates/ec-probe/tests/matrix.rs:98 scripts/gen-fixtures.sh ok 014d2691a0f8490e4d5da626e046d2680ff554db72cfdc688c5697c1bc350114 +fixtures/audio/alac-mp4-stereo-48000.m4a crates/ec-alac/tests/oracle.rs:68 scripts/gen-fixtures.sh ok f35830614c8f32a0f00ac689377ea45cd281740485322daa0fcb6aa131a398e5 +fixtures/audio/av-h264-aac-stereo-48000.mkv crates/ec-probe/tests/matrix.rs:110 scripts/gen-fixtures.sh ok da4cd8ad5a9be7b148926fdda36969569c3528279c73bdd2f4a36d8266612560 +fixtures/audio/cover-mp4-stereo-44100.m4a crates/ec-probe/tests/matrix.rs:260 scripts/gen-fixtures.sh ok b8ef543bdc0aa4d05628efaa9648121af00a159fb1d80cfb1c8a53dfdb9d6941 +fixtures/audio crates/ec-ac3/tests/decode_matrix.rs:23 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-ac3/tests/decode_matrix.rs:25 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-ac3/tests/encode_matrix.rs:291 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-alac/tests/encode.rs:15 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-alac/tests/oracle.rs:17 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-ogg/tests/ogg.rs:32 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-opus/tests/conformance.rs:584 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-probe/tests/matrix.rs:17 scripts/gen-fixtures.sh ok - +fixtures/audio crates/ec-riff/tests/wav.rs:432 scripts/gen-fixtures.sh ok - +fixtures/audio/flac-5.1-44100.flac crates/ec-probe/tests/matrix.rs:90 scripts/gen-fixtures.sh ok 83f3731bcf67f9f4ff12f793ed89c6cf73f17a985403648e2f3c7908b4705e99 +fixtures/audio/flac-mono-44100.flac crates/ec-probe/tests/matrix.rs:88 scripts/gen-fixtures.sh ok f55187711aaf27af6bbb5cd493ce2fdc53c82dff33472b7918eda7e76c024258 +fixtures/audio/flac-stereo-48000.flac crates/ec-probe/tests/matrix.rs:300 scripts/gen-fixtures.sh ok 50cfaa89da637107348d1986711d37e4f313a502df72fb2b6b53ca699d5f17b0 +fixtures/audio/flac-stereo-48000.flac crates/ec-probe/tests/matrix.rs:89 scripts/gen-fixtures.sh ok 50cfaa89da637107348d1986711d37e4f313a502df72fb2b6b53ca699d5f17b0 +fixtures/audio/opus-ogg-5.1-48000.opus crates/ec-opus/tests/conformance.rs:676 scripts/gen-fixtures.sh ok b005631cb93ed64166199cdcacfb2d22635abe703d6d6750ad0f900d03766c69 +fixtures/audio/opus-ogg-5.1-48000.opus crates/ec-opus/tests/conformance.rs:724 scripts/gen-fixtures.sh ok b005631cb93ed64166199cdcacfb2d22635abe703d6d6750ad0f900d03766c69 +fixtures/audio/opus-ogg-5.1-48000.opus crates/ec-opus/tests/conformance.rs:766 scripts/gen-fixtures.sh ok b005631cb93ed64166199cdcacfb2d22635abe703d6d6750ad0f900d03766c69 +fixtures/audio/opus-ogg-5.1-48000.opus crates/ec-probe/tests/matrix.rs:106 scripts/gen-fixtures.sh ok b005631cb93ed64166199cdcacfb2d22635abe703d6d6750ad0f900d03766c69 +fixtures/audio/opus-ogg-mono-48000.opus crates/ec-opus/tests/conformance.rs:674 scripts/gen-fixtures.sh ok bf6b453b057bf0fbaffc8a84c417d667fc70e7545fe6af1aaa51d873ef7403dc +fixtures/audio/opus-ogg-mono-48000.opus crates/ec-probe/tests/matrix.rs:104 scripts/gen-fixtures.sh ok bf6b453b057bf0fbaffc8a84c417d667fc70e7545fe6af1aaa51d873ef7403dc +fixtures/audio/opus-ogg-stereo-48000.opus crates/ec-opus/tests/conformance.rs:675 scripts/gen-fixtures.sh ok 829e1a5d104b6d161d748dca82fef1fe28b35d10398b230bbddb39f8b1769cc9 +fixtures/audio/opus-ogg-stereo-48000.opus crates/ec-opus/tests/conformance.rs:765 scripts/gen-fixtures.sh ok 829e1a5d104b6d161d748dca82fef1fe28b35d10398b230bbddb39f8b1769cc9 +fixtures/audio/opus-ogg-stereo-48000.opus crates/ec-probe/tests/matrix.rs:105 scripts/gen-fixtures.sh ok 829e1a5d104b6d161d748dca82fef1fe28b35d10398b230bbddb39f8b1769cc9 +fixtures/audio/vorbis-ogg-5.1-48000.ogg crates/ec-probe/tests/matrix.rs:103 scripts/gen-fixtures.sh ok 571dc4a174c340e29f3dfba1f5bee42c32d3b537106816e511e18ebbe1b8e717 +fixtures/audio/vorbis-ogg-mono-44100.ogg crates/ec-probe/tests/matrix.rs:101 scripts/gen-fixtures.sh ok e77309d1a04df5a5a76f3ed4e121c0c427787fd85c81f13fb84b99d801ef9483 +fixtures/audio/vorbis-ogg-stereo-48000.ogg crates/ec-probe/tests/matrix.rs:102 scripts/gen-fixtures.sh ok ce3b2c4d5c5be06ba85d6dab9c32f8e94cd27062c4cff161e1fde04cb96c832a +fixtures/audio/wav16-5.1-48000.wav crates/ec-probe/tests/matrix.rs:87 scripts/gen-fixtures.sh ok 96a432a3138c9d5055f9cdce8ab9306001f825d948cbd2d337568e34b0c806de +fixtures/audio/wav16-mono-44100.wav crates/ec-probe/tests/matrix.rs:85 scripts/gen-fixtures.sh ok 855f3b42a349299bae47db14cc76aceca2822071a55cf82f9423ff9de9f9d169 +fixtures/audio/wav16-mono-48000.wav crates/ec-opus/tests/conformance.rs:2107 scripts/gen-fixtures.sh ok 739259114f735e36fa603b6d48457fd2953b5026cc33a7637aaad8b0b3d86f7d +fixtures/audio/wav16-mono-48000.wav crates/ec-opus/tests/conformance.rs:2473 scripts/gen-fixtures.sh ok 739259114f735e36fa603b6d48457fd2953b5026cc33a7637aaad8b0b3d86f7d +fixtures/audio/wav16-stereo-48000.wav crates/ec-alac/tests/encode.rs:102 scripts/gen-fixtures.sh ok 75a89990315315eb3f64ece40c791a8a0c7b72f71c7c4b9f46ed6a9f60200207 +fixtures/audio/wav16-stereo-48000.wav crates/ec-alac/tests/encode.rs:185 scripts/gen-fixtures.sh ok 75a89990315315eb3f64ece40c791a8a0c7b72f71c7c4b9f46ed6a9f60200207 +fixtures/audio/wav16-stereo-48000.wav crates/ec-alac/tests/encode.rs:210 scripts/gen-fixtures.sh ok 75a89990315315eb3f64ece40c791a8a0c7b72f71c7c4b9f46ed6a9f60200207 +fixtures/audio/wav16-stereo-48000.wav crates/ec-probe/tests/matrix.rs:86 scripts/gen-fixtures.sh ok 75a89990315315eb3f64ece40c791a8a0c7b72f71c7c4b9f46ed6a9f60200207 +fixtures/bitstreams/av1-altref.ivf crates/ec-av1-syntax/tests/streams.rs:239 scripts/gen-bitstream-fixtures.sh ok 3904cc9fd01624689f824b91c83530943027ac0097e80332daf310c660fec48f +fixtures/bitstreams/av1-profile1-444.ivf crates/ec-hw/tests/gpu.rs:495 scripts/gen-bitstream-fixtures.sh ok 2e04b08114aeba5af059f93026046675584af940e23d0cfde325caf7969ca783 +fixtures/bitstreams crates/ec-av1-syntax/tests/streams.rs:14 scripts/gen-fixtures.sh ok - +fixtures/bitstreams crates/ec-hw/tests/gpu.rs:28 scripts/gen-fixtures.sh ok - +fixtures/bitstreams crates/ec-vp9-syntax/tests/streams.rs:14 scripts/gen-fixtures.sh ok - +fixtures/bitstreams crates/ec-vp9/tests/hbd_exact.rs:46 scripts/gen-fixtures.sh ok - +fixtures/bitstreams crates/ec-vp9/tests/ivf.rs:54 scripts/gen-fixtures.sh ok - +fixtures/bitstreams crates/ec-vp9/tests/subsampling_exact.rs:57 scripts/gen-fixtures.sh ok - +fixtures/bitstreams/h264-1080p-23.976-8bit.264 crates/ec-hw/tests/gpu.rs:1841 scripts/gen-bitstream-fixtures.sh ok 44dc00696534ba5302b44e8791347439216c9e40068ae0e45009faf08bddfaae +fixtures/bitstreams/h264-1080p-23.976-8bit.264 crates/ec-hw/tests/gpu.rs:1920 scripts/gen-bitstream-fixtures.sh ok 44dc00696534ba5302b44e8791347439216c9e40068ae0e45009faf08bddfaae +fixtures/bitstreams/h264-1080p-23.976-8bit.264 crates/ec-hw/tests/gpu.rs:1988 scripts/gen-bitstream-fixtures.sh ok 44dc00696534ba5302b44e8791347439216c9e40068ae0e45009faf08bddfaae +fixtures/bitstreams/h264-1080p-23.976-8bit.264 crates/ec-hw/tests/gpu.rs:711 scripts/gen-bitstream-fixtures.sh ok 44dc00696534ba5302b44e8791347439216c9e40068ae0e45009faf08bddfaae +fixtures/bitstreams/vp9-1080p-23.976-10bit.ivf crates/ec-vp9/tests/hbd_exact.rs:85 scripts/gen-bitstream-fixtures.sh ok 731abcc45857ade311689065defae7166e25394386de01300174f5f4f122cef3 +fixtures/bitstreams/vp9-1080p-60-8bit.ivf crates/ec-vp9/tests/inter_pixels_exact.rs:170 scripts/gen-bitstream-fixtures.sh ok - +fixtures/bitstreams/vp9-profile1-444.ivf crates/ec-hw/tests/gpu.rs:490 scripts/gen-bitstream-fixtures.sh ok ceebede9c2df73b3e8c1b279f70eb8af658096abc2d8bd00aaa97afdd7900d86 +fixtures/bitstreams/vp9-profile1-444.ivf crates/ec-vp9/tests/subsampling_exact.rs:122 scripts/gen-bitstream-fixtures.sh ok ceebede9c2df73b3e8c1b279f70eb8af658096abc2d8bd00aaa97afdd7900d86 +fixtures/bitstreams/vp9-profile1-444.ivf crates/ec-vp9/tests/subsampling_exact.rs:162 scripts/gen-bitstream-fixtures.sh ok ceebede9c2df73b3e8c1b279f70eb8af658096abc2d8bd00aaa97afdd7900d86 +fixtures/bitstreams/vp9-profile3-444-10bit.ivf crates/ec-vp9/tests/subsampling_exact.rs:127 scripts/gen-bitstream-fixtures.sh ok ba1af75f2b270b9e0ebb877cef72d9e741748482bd19924a4e1721682ee3f197 +fixtures/bitstreams/vp9-profile3-444-10bit.ivf crates/ec-vp9/tests/subsampling_exact.rs:171 scripts/gen-bitstream-fixtures.sh ok ba1af75f2b270b9e0ebb877cef72d9e741748482bd19924a4e1721682ee3f197 +fixtures/bitstreams/vp9-superframe-altref.ivf crates/ec-vp9-syntax/tests/streams.rs:200 scripts/gen-bitstream-fixtures.sh ok bfc59a9604aaddc6709971e0e81eca1178b0c0a32be83a3d5c7b5c078aa7a873 +fixtures/bitstreams/vp9-superframe-altref.ivf crates/ec-vp9/tests/keyframe_exact.rs:163 scripts/gen-bitstream-fixtures.sh ok bfc59a9604aaddc6709971e0e81eca1178b0c0a32be83a3d5c7b5c078aa7a873 +fixtures/bitstreams/vp9-superframe-altref.ivf crates/ec-vp9/tests/scratch_err.rs:10 scripts/gen-bitstream-fixtures.sh ok bfc59a9604aaddc6709971e0e81eca1178b0c0a32be83a3d5c7b5c078aa7a873 +fixtures/bitstreams/vp9-superframe-altref.ivf crates/ec-vp9/tests/scratch_err.rs:6 scripts/gen-bitstream-fixtures.sh ok bfc59a9604aaddc6709971e0e81eca1178b0c0a32be83a3d5c7b5c078aa7a873 +fixtures/bitstreams/vp9-superframe-altref.ivf crates/ec-vp9/tests/scratch_hdr3.rs:6 scripts/gen-bitstream-fixtures.sh ok bfc59a9604aaddc6709971e0e81eca1178b0c0a32be83a3d5c7b5c078aa7a873 +fixtures crates/ec-aac/tests/oracle.rs:11 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:16812 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:19755 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:21170 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:21552 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:22103 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/encode.rs:22659 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/stream.rs:29415 scripts/gen-fixtures.sh ok - +fixtures crates/ec-av1/src/stream.rs:8659 scripts/gen-fixtures.sh ok - +fixtures crates/ec-flac/tests/encode_matrix.rs:48 scripts/gen-fixtures.sh ok - +fixtures crates/ec-matroska/tests/matroska.rs:89 scripts/gen-fixtures.sh ok - +fixtures crates/ec-mp3/tests/decode_matrix.rs:19 scripts/gen-fixtures.sh ok - +fixtures crates/ec-mp3/tests/encode_matrix.rs:45 scripts/gen-fixtures.sh ok - +fixtures crates/ec-mp4/tests/mp4.rs:19 scripts/gen-fixtures.sh ok - +fixtures crates/ec-vorbis/tests/oracle.rs:18 scripts/gen-fixtures.sh ok - +fixtures/golden3-pin.obu (named absent pin) absent pin -- gate is #[ignore]d; no encoder recipe recorded absent-pin - +fixtures/golden4-pin.obu crates/ec-av1/src/stream.rs:22046 none (prose provenance only) ok 1754023e44e46edaebc2c05065bf1c65db1a41354577cbf71c0e8ebe737ae14a +fixtures/golden6-mismatch.obu crates/ec-av1/src/stream.rs:31517 none (prose provenance only) ok c56909b98542192b03f3a945e153475aa57a58a1586bf166513297296cb225b3 +fixtures/golden7-forwarding-mismatch.obu crates/ec-av1/src/stream.rs:22083 none (prose provenance only) ok 81b3bf657a85e95085287b30d97dee93ba5aea0ed1db1e1f4fcd19a06afc17be +fixtures/ll444-lossless-key.obu (named absent pin) absent pin -- gate a_real_aomenc_lossless_444_key_frame (converted to an EC_REQUIRE_FIXTURES hard fail; pin never committed) absent-pin - +fixtures/lr-sgr-r7.obu crates/ec-av1/src/stream.rs:28582 none (prose provenance only) ok 6b95b20e3377430ffae0b2ce86fad9502e0dedf13cd6c38ab7f5af4a8b21f33d +fixtures/sbpart-pin.obu (named absent pin) absent pin -- gate is #[ignore]d; no encoder recipe recorded absent-pin - +fixtures/stills crates/ec-image/tests/differential.rs:24 scripts/gen-fixtures.sh ok - +fixtures/stills crates/ec-image/tests/fuzz.rs:15 scripts/gen-fixtures.sh ok - +fixtures/subs crates/ec-subs/tests/real_library.rs:15 scripts/gen-fixtures.sh ok - +fixtures/subs/real.ass crates/ec-subs/tests/real_library.rs:55 scripts/gen-subtitle-fixtures.sh ok 519a838783208edd8140e7d034e6969298b66c6435594336326c6996b95b3bf6 +fixtures/subs/real.srt crates/ec-subs/tests/real_library.rs:28 scripts/gen-subtitle-fixtures.sh ok 0b4b59d1044e78c3520c9baa265e25d3eb55decb514c61a97712beac070953c2 +fixtures/vectors/flac-xiph/flac-test-files-main crates/ec-flac/tests/xiph_vectors.rs:50 scripts/fetch-vectors.sh ok - +fixtures/vectors/h264-jvt crates/ec-h264/tests/conformance.rs:68 scripts/fetch-vectors.sh ok - +fixtures/vectors/opus-rfc6716/opus_testvectors crates/ec-opus/tests/conformance.rs:87 scripts/fetch-vectors.sh ok - +fixtures/video crates/ec-av1/src/encode.rs:20484 scripts/gen-fixtures.sh ok - +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encoder.rs:3263 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encoder.rs:6032 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:20335 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:20400 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:20480 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:20903 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:21258 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:21557 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:22117 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:22661 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-23.976-8bit.mp4 crates/ec-av1/src/stream.rs:42809 scripts/gen-fixtures.sh ok db7275c361b07985088e80337a6c8c144d232d12f4d57cb84645effe27195784 +fixtures/video/h264-1080p-60-8bit.mp4 crates/ec-av1/src/encode.rs:20481 scripts/gen-fixtures.sh ok - +fixtures/video/h264-2160p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:21259 scripts/gen-fixtures.sh ok - +fixtures/video/h264-2160p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:21558 scripts/gen-fixtures.sh ok - +fixtures/video/h264-2160p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:22118 scripts/gen-fixtures.sh ok - +fixtures/video/h264-2160p-23.976-8bit.mp4 crates/ec-av1/src/encode.rs:22662 scripts/gen-fixtures.sh ok - +fixtures/video/h264-2160p-23.976-8bit.mp4 crates/ec-av1/src/stream.rs:6090 scripts/gen-fixtures.sh ok - +fixtures/video/h264-open-gop.mp4 crates/ec-h264/tests/conformance.rs:2386 scripts/gen-fixtures.sh ok 0b3b316c3f786cf4cb158de1b9c81aa871b1bb0d8e2da30d451f741cacd5d0ff +fixtures/video/h264-open-gop.mp4 crates/ec-hw/tests/gpu.rs:2793 scripts/gen-fixtures.sh ok 0b3b316c3f786cf4cb158de1b9c81aa871b1bb0d8e2da30d451f741cacd5d0ff +fixtures/vp8/altref-160x96.ivf crates/ec-vp8/tests/keyframe_exact.rs:108 scripts/gen_vp8_fixtures.sh ok 32d610dc278e528a7d69c3543764cb000e927c6988e61ef0c4ba560e7d89b49e +fixtures/vp8/altref-160x96.ivf crates/ec-vp8/tests/keyframe_exact.rs:110 scripts/gen_vp8_fixtures.sh ok 32d610dc278e528a7d69c3543764cb000e927c6988e61ef0c4ba560e7d89b49e +fixtures/vp8/altref-160x96.ivf crates/ec-vp8/tests/stream_exact.rs:23 scripts/gen_vp8_fixtures.sh ok 32d610dc278e528a7d69c3543764cb000e927c6988e61ef0c4ba560e7d89b49e +fixtures/vp8/altref-160x96.ivf crates/ec-vp8/tests/stream_exact.rs:65 scripts/gen_vp8_fixtures.sh ok 32d610dc278e528a7d69c3543764cb000e927c6988e61ef0c4ba560e7d89b49e +fixtures/vp8/clip-obs-320x192.ivf crates/ec-vp8/tests/keyframe_exact.rs:107 scripts/gen_vp8_fixtures.sh ok e55b3dd585d6ea918cb7ffa9319e53b5e43b73db2d1db2c8b6a0ea7750e99cf2 +fixtures/vp8/clip-obs-320x192.ivf crates/ec-vp8/tests/stream_exact.rs:24 scripts/gen_vp8_fixtures.sh ok e55b3dd585d6ea918cb7ffa9319e53b5e43b73db2d1db2c8b6a0ea7750e99cf2 +fixtures/vp8 crates/ec-vp8/tests/ivf.rs:81 scripts/gen-fixtures.sh ok - +fixtures/vp8/gop-160x96.ivf crates/ec-vp8/tests/header_parse.rs:114 scripts/gen_vp8_fixtures.sh ok 96a8cfbde1923df7f8df945f553cf20d0bf7088e025a2498c8910e98ffa43155 +fixtures/vp8/gop-160x96.ivf crates/ec-vp8/tests/keyframe_exact.rs:106 scripts/gen_vp8_fixtures.sh ok 96a8cfbde1923df7f8df945f553cf20d0bf7088e025a2498c8910e98ffa43155 +fixtures/vp8/gop-160x96.ivf crates/ec-vp8/tests/stream_exact.rs:124 scripts/gen_vp8_fixtures.sh ok 96a8cfbde1923df7f8df945f553cf20d0bf7088e025a2498c8910e98ffa43155 +fixtures/vp8/gop-160x96.ivf crates/ec-vp8/tests/stream_exact.rs:21 scripts/gen_vp8_fixtures.sh ok 96a8cfbde1923df7f8df945f553cf20d0bf7088e025a2498c8910e98ffa43155 +fixtures/vp8/gop-96x80-v1.ivf crates/ec-vp8/tests/stream_exact.rs:20 scripts/gen_vp8_fixtures.sh ok 5d4ed5fc0884e283de2c7508a9bcaa33e5d46a0ae10aa55dcca61bed63d5d786 +fixtures/vp8/kf-160x96-q20.ivf crates/ec-vp8/tests/header_parse.rs:11 scripts/gen_vp8_fixtures.sh ok dd4ff6bd44711c98356687867fd724bd8ce5fc5e0f7262d993c31dffd58b438a +fixtures/vp8/kf-160x96-q20.ivf crates/ec-vp8/tests/keyframe_exact.rs:82 scripts/gen_vp8_fixtures.sh ok dd4ff6bd44711c98356687867fd724bd8ce5fc5e0f7262d993c31dffd58b438a +fixtures/vp8/kf-160x96-q20.ivf crates/ec-vp8/tests/stream_exact.rs:17 scripts/gen_vp8_fixtures.sh ok dd4ff6bd44711c98356687867fd724bd8ce5fc5e0f7262d993c31dffd58b438a +fixtures/vp8/kf-160x96-q40.ivf crates/ec-vp8/tests/header_parse.rs:12 scripts/gen_vp8_fixtures.sh ok d079b3ee1c16c2b566f31c9bd57aa0a1af7b4a9fd13d555b0581d1e8d84f9ab2 +fixtures/vp8/kf-160x96-q40.ivf crates/ec-vp8/tests/keyframe_exact.rs:83 scripts/gen_vp8_fixtures.sh ok d079b3ee1c16c2b566f31c9bd57aa0a1af7b4a9fd13d555b0581d1e8d84f9ab2 +fixtures/vp8/kf-160x96-q40.ivf crates/ec-vp8/tests/stream_exact.rs:18 scripts/gen_vp8_fixtures.sh ok d079b3ee1c16c2b566f31c9bd57aa0a1af7b4a9fd13d555b0581d1e8d84f9ab2 +fixtures/vp8/kf-16x16-black-q0.ivf crates/ec-vp8/tests/stream_exact.rs:13 scripts/gen_vp8_fixtures.sh ok 1e95a39ffe58f3046f675412c51bfbdc17344ff10c47ee0af3ca4b382022f43e +fixtures/vp8/kf-172x144-q25.ivf crates/ec-vp8/tests/header_parse.rs:15 scripts/gen_vp8_fixtures.sh ok 4e29b24c86091051381a877d17a68a3195e44f65cc9ed1e01311e6e72d8d249d +fixtures/vp8/kf-172x144-q25.ivf crates/ec-vp8/tests/keyframe_exact.rs:86 scripts/gen_vp8_fixtures.sh ok 4e29b24c86091051381a877d17a68a3195e44f65cc9ed1e01311e6e72d8d249d +fixtures/vp8/kf-172x144-q25.ivf crates/ec-vp8/tests/stream_exact.rs:19 scripts/gen_vp8_fixtures.sh ok 4e29b24c86091051381a877d17a68a3195e44f65cc9ed1e01311e6e72d8d249d +fixtures/vp8/kf-32x16-q35.ivf crates/ec-vp8/tests/header_parse.rs:14 scripts/gen_vp8_fixtures.sh ok 3d9bad9c985539ac24fb2f58b34d064b42e2e736584a2a250fccf0233a9c9eb3 +fixtures/vp8/kf-32x16-q35.ivf crates/ec-vp8/tests/keyframe_exact.rs:85 scripts/gen_vp8_fixtures.sh ok 3d9bad9c985539ac24fb2f58b34d064b42e2e736584a2a250fccf0233a9c9eb3 +fixtures/vp8/kf-32x16-q35.ivf crates/ec-vp8/tests/stream_exact.rs:14 scripts/gen_vp8_fixtures.sh ok 3d9bad9c985539ac24fb2f58b34d064b42e2e736584a2a250fccf0233a9c9eb3 +fixtures/vp8/kf-76x52-q30.ivf crates/ec-vp8/tests/header_parse.rs:13 scripts/gen_vp8_fixtures.sh ok 15d05cb9ebd6bbfd4d8519b30256b28f2f55738754f68f00afef1cae9e66ad3a +fixtures/vp8/kf-76x52-q30.ivf crates/ec-vp8/tests/keyframe_exact.rs:84 scripts/gen_vp8_fixtures.sh ok 15d05cb9ebd6bbfd4d8519b30256b28f2f55738754f68f00afef1cae9e66ad3a +fixtures/vp8/kf-76x52-q30.ivf crates/ec-vp8/tests/stream_exact.rs:15 scripts/gen_vp8_fixtures.sh ok 15d05cb9ebd6bbfd4d8519b30256b28f2f55738754f68f00afef1cae9e66ad3a +fixtures/vp8/kf-96x80-q63.ivf crates/ec-vp8/tests/header_parse.rs:16 scripts/gen_vp8_fixtures.sh ok 9c6052448106ad6adf84e905be881815befb3d45abf80bc3c8b17507c324555e +fixtures/vp8/kf-96x80-q63.ivf crates/ec-vp8/tests/keyframe_exact.rs:87 scripts/gen_vp8_fixtures.sh ok 9c6052448106ad6adf84e905be881815befb3d45abf80bc3c8b17507c324555e +fixtures/vp8/kf-96x80-q63.ivf crates/ec-vp8/tests/stream_exact.rs:16 scripts/gen_vp8_fixtures.sh ok 9c6052448106ad6adf84e905be881815befb3d45abf80bc3c8b17507c324555e +fixtures/vp8/mparts-160x96.ivf crates/ec-vp8/tests/header_parse.rs:17 scripts/gen_vp8_fixtures.sh ok eb656c9e4547ad99bfe5a3a4ce5bf9c54daa4ba657fb7c3327d448a059760282 +fixtures/vp8/mparts-160x96.ivf crates/ec-vp8/tests/header_parse.rs:81 scripts/gen_vp8_fixtures.sh ok eb656c9e4547ad99bfe5a3a4ce5bf9c54daa4ba657fb7c3327d448a059760282 +fixtures/vp8/mparts-160x96.ivf crates/ec-vp8/tests/keyframe_exact.rs:95 scripts/gen_vp8_fixtures.sh ok eb656c9e4547ad99bfe5a3a4ce5bf9c54daa4ba657fb7c3327d448a059760282 +fixtures/vp8/mparts-160x96.ivf crates/ec-vp8/tests/stream_exact.rs:22 scripts/gen_vp8_fixtures.sh ok eb656c9e4547ad99bfe5a3a4ce5bf9c54daa4ba657fb7c3327d448a059760282 +fixtures/vp9 crates/ec-vp9/tests/keyframe_exact.rs:116 scripts/gen-fixtures.sh ok - +fixtures/vp9 crates/ec-vp9/tests/scratch_hdr.rs:7 scripts/gen-fixtures.sh ok - +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/dump_probe.rs:11 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/dump_probe.rs:6 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/keyframe_exact.rs:117 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/scratch_hdr.rs:4 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/scratch_lfdump.rs:22 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/key-320.ivf crates/ec-vp9/tests/scratch_tok.rs:11 scripts/gen-fixtures.sh ok bcd5a1df6c944a79b1f52cfe669e7c12f7f9b84ffbec8d3daf33475c4a0b7e67 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/keyframe_exact.rs:125 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/scratch_bool.rs:7 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/scratch_hdr2.rs:6 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/scratch_hdr.rs:4 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/scratch_lossless.rs:6 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 +fixtures/vp9/lossless-64.ivf crates/ec-vp9/tests/scratch_sweep.rs:8 scripts/gen-fixtures.sh ok 2cf9473fa47ec47f7ab94d77640aa0d58494edacc72cf151a784a76283c55147 diff --git a/scripts/gen-fixture-library.sh b/scripts/gen-fixture-library.sh new file mode 100755 index 00000000..1055e5ed --- /dev/null +++ b/scripts/gen-fixture-library.sh @@ -0,0 +1,257 @@ +#!/usr/bin/env bash +# gen-fixture-library.sh — GENERATE scripts/fixture-library.tsv from source. +# +# The tsv is committed output, never hand-typed. Regenerate with: +# scripts/gen-fixture-library.sh && git diff --exit-code scripts/fixture-library.tsv +# so drift between "what the tests reach for" and "the manifest" is a +# one-command diff. `scripts/verify-fixture-library.sh` runs that same diff as +# part of its exit status. +# +# COLUMNS (tab separated) +# 1 path repo-relative; `fixtures/...` is relative to $EC_FIXTURES +# 2 required-by file:line of every reference (one row per reference) +# 3 provenance the script/recipe that reproduces the bytes, or +# `none (prose provenance only)` — a FINDING, not a +# placeholder: a pinned fixture claim must cite the +# originating encoder program and the artifact sha256, or the +# pin is unreproducible (the IVF-container drift incident is +# why that rule exists) +# 4 status ok | missing | empty-dir | absent-pin +# 5 sha256 of the artefact, when it is a regular file under 4 MiB +# +# ENUMERATION SHAPES the scan is derived from: +# CARGO_MANIFEST_DIR env!("CARGO_MANIFEST_DIR") / concat!(env!(...)) +# concat!(env!( a fixture root assembled from the manifest dir +# include_bytes! include_bytes!/include_str! argument literals +# "fixtures/ any string literal naming the fixture tree +# ../../fixtures crate-relative literals (CWD is the crate dir) +# Path::new( Path::new("...") argument literals +# fs::read fs::read / read_dir / File::open argument literals +# +# TWO PASSES: +# 1. fixture-root / fixture-path literals -> the row is the literal itself. +# 2. bare media-file literals ("aac-adts-5.1-44100.aac", "entry-tx3g.mp4") +# joined onto each fixture directory literal seen in the SAME file, then +# onto the standard top-level library directories. Only joins that +# resolve are emitted; unresolved names are counted in the header as the +# declared blind spot. +# +# BLIND SPOT (honest: this is a preflight, not a proof). The scan is literal- +# and grep-derived, so it cannot see a path assembled at runtime from a value +# that is not a literal in the same file -- a vector name read from +# scripts/vectors.sha256, a row from fixtures/real-library-manifest.tsv, a +# format! interpolation, a name in a table. For those, the parent DIRECTORY is +# still enumerated, and the verifier requires every listed directory to exist +# AND be non-empty -- that is what catches the "three hosts whose fixture +# libraries differed" class. A single missing member of a runtime-named corpus +# shows up as a regeneration diff, not as a resolve failure. + +set -uo pipefail + +ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd) +OUT=${1:-$ROOT/scripts/fixture-library.tsv} +FIXTURES=${EC_FIXTURES:-$ROOT/fixtures} + +MEDIA_RE='\.(mp4|m4a|m4s|m4v|mkv|ivf|obu|flac|opus|ogg|oga|webm|265|264|h264|h265|hevc|y4m|yuv|wav|aac|ts|bin|ttml|srt|vtt|ass|json)' + +# Pins that are KNOWN ABSENT and must not vanish from the manifest. Each is +# recorded as an `absent-pin` row naming the gate that wants it, so the gap is +# visible instead of silently skipped. +absent_pin() { + case $1 in + fixtures/ll444-lossless-key.obu) + echo "absent pin -- gate a_real_aomenc_lossless_444_key_frame (converted to an EC_REQUIRE_FIXTURES hard fail; pin never committed)" ;; + fixtures/golden3-pin.obu | fixtures/sbpart-pin.obu) + echo "absent pin -- gate is #[ignore]d; no encoder recipe recorded" ;; + *) return 1 ;; + esac +} + +# --- 1. collect the source files that can name a fixture ----------------- +mapfile -t FILES < <( + grep -rl --include='*.rs' \ + -e 'fixtures' -e 'include_bytes!' -e 'include_str!' \ + "$ROOT"/crates/*/tests "$ROOT"/crates/*/src 2>/dev/null | sort +) + +is_fixture_literal() { # $1 = literal without quotes + local lit=$1 + case $lit in + *[[:space:]]* | *'{'* | *'}'* | *'$'* | *'%'* | *'*'* | *'?'* | \ + *'('* | *')'* | *','* | *'='* | *';'* | *':'*) return 1 ;; + *.sh | *.py | *.md | *.tsv) return 1 ;; # a script name, not a path + /home/* | /Users/* | /tmp/*) return 1 ;; # developer path, not the library + esac + [[ $lit == *fixtures* || $lit == */vectors/* ]] || return 1 + return 0 +} + +# Provenance: which script reproduces these bytes. An empty answer is a +# finding -- committed pins whose only provenance is prose in a gate comment. +generator_for() { # $1 = repo-relative path + case $1 in + fixtures/vectors/*) echo "scripts/fetch-vectors.sh" ;; + fixtures/bitstreams/*) echo "scripts/gen-bitstream-fixtures.sh" ;; + fixtures/stills/*) echo "scripts/gen-still-fixtures.sh" ;; + fixtures/subs/*) echo "scripts/gen-subtitle-fixtures.sh" ;; + fixtures/real-library-manifest.tsv) echo "scripts/scan-real-library.sh" ;; + fixtures/vp8/*) echo "scripts/gen_vp8_fixtures.sh" ;; + fixtures/*.obu) echo "none (prose provenance only)" ;; + crates/*/fixtures/*.obu) echo "none (prose provenance only)" ;; + fixtures/audio/mp3* | fixtures/audio/*mp3*) echo "scripts/gen-mp3-fixtures.sh" ;; + *) echo "scripts/gen-fixtures.sh" ;; + esac +} + +abs_path() { # $1 = manifest path -> absolute path + case $1 in + fixtures/*) printf '%s\n' "$FIXTURES/${1#fixtures/}" ;; + *) printf '%s\n' "$ROOT/$1" ;; + esac +} + +# Resolve a source literal to a manifest path. Cargo runs tests with the crate +# directory as CWD, so `../../fixtures` and `CARGO_MANIFEST_DIR` both anchor at +# the crate; a bare `fixtures/...` is accepted from either anchor. +resolve() { # $1 = literal, $2 = crate dir; prints manifest path + local lit=$1 crate=$2 base cand + for base in "$crate" "$ROOT" "$ROOT/crates"; do + if [ -e "$base/$lit" ]; then + cand=$(realpath -m -- "$base/$lit") + printf '%s\n' "${cand#"$ROOT"/}" + return 0 + fi + done + # Unresolved: normalise against the repo root so the verifier reports the + # row loudly instead of it silently vanishing from the manifest. + cand=$(realpath -m -- "$ROOT/$lit") + printf '%s\n' "${cand#"$ROOT"/}" +} + +row() { # $1 path, $2 required-by, $3 provenance (optional), $4 status override + local path=$1 required_by=$2 prov=${3:-} status_override=${4:-} + local abs status sum + abs=$(abs_path "$path") + if [ -n "$status_override" ]; then + status=$status_override + elif [ ! -e "$abs" ]; then + status=missing + elif [ -d "$abs" ] && [ -z "$(ls -A -- "$abs" 2>/dev/null)" ]; then + status=empty-dir + else + status=ok + fi + if [ -z "$prov" ]; then prov=$(generator_for "$path"); fi + if [ -f "$abs" ] && [ "$(stat -c %s -- "$abs")" -lt 4194304 ]; then + sum=$(sha256sum -- "$abs" | cut -d' ' -f1) + else + sum='-' + fi + printf '%s\t%s\t%s\t%s\t%s\n' "$path" "$required_by" "$prov" "$status" "$sum" +} + +tmp=$(mktemp) +trap 'rm -f "$tmp"' EXIT +unnamed=0 +seen_absent=() + +for f in "${FILES[@]}"; do + crate=$(dirname "$(dirname "$f")") + rel=${f#"$ROOT"/} + file_dirs=() + + # Pass 1 -- fixture-root / fixture-path literals. + while IFS= read -r hit; do + lineno=${hit%%:*} + lit=${hit#*:} + lit=${lit#\"} + lit=${lit%\"} + is_fixture_literal "$lit" || continue + path=$(resolve "$lit" "$crate") + prov=$(absent_pin "$path") && { + row "$path" "$rel:$lineno" "$prov" absent-pin >>"$tmp" + seen_absent+=("$path") + continue + } + row "$path" "$rel:$lineno" >>"$tmp" + [ -d "$(abs_path "$path")" ] && file_dirs+=("$path") + done < <(grep -noE '"[^"]*"' "$f") + + # Pass 2 -- bare media names joined onto this file's fixture directories, + # then onto the standard top-level library directories (a file may name + # its corpus directory in a helper module rather than in this file). + for d in audio video bitstreams subs stills realworld vp8 vp9 hbd-r5; do + [ -d "$FIXTURES/$d" ] && file_dirs+=("fixtures/$d") + done + ((${#file_dirs[@]})) || continue + while IFS= read -r hit; do + lineno=${hit%%:*} + name=${hit#*:} + name=${name#\"} + name=${name%\"} + for d in "${file_dirs[@]}"; do + if [ -e "$(abs_path "$d/$name")" ]; then + row "$d/$name" "$rel:$lineno" >>"$tmp" + continue 2 + fi + done + unnamed=$((unnamed + 1)) + done < <(grep -noE '"[^"/]*'"$MEDIA_RE"'"' "$f") +done + +# Pass 3 -- committed pins that NO source literal reaches. A committed +# fixture nothing references is either dead weight or a reference built at +# runtime from a name the grep cannot see; either way it must be a row, not a +# gap. Scanned over the crate-local committed pin directories. +orphans=0 +while IFS= read -r pin; do + [ -n "$pin" ] || continue + if ! grep -qP "^\Q$pin\E\t" "$tmp"; then + row "$pin" "(committed pin: NO source reference found)" \ + "none (prose provenance only)" >>"$tmp" + orphans=$((orphans + 1)) + fi +done < <(find "$ROOT"/crates/*/fixtures -maxdepth 1 -type f 2>/dev/null | + sed "s#^$ROOT/##" | sort) + +# Known-absent pins that no source literal reached still belong in the +# manifest: a missing pin must be a row, not a gap. +for p in fixtures/ll444-lossless-key.obu fixtures/golden3-pin.obu fixtures/sbpart-pin.obu; do + grep -qP "^\Q$p\E\t" "$tmp" && continue + row "$p" "(named absent pin)" "$(absent_pin "$p")" absent-pin >>"$tmp" +done + +# Which tests consume the fetched vector sets, and does anything need the +# .tar.gz blobs? The fleet sync excluded them deliberately, so a test that +# wanted a blob would be red on three hosts for a reason nobody wrote down. +vector_consumers=$(awk -F'\t' '$1 ~ /^fixtures\/vectors\// {split($2,a,":"); print a[1]}' "$tmp" | sort -u | tr '\n' ' ') +blob_users=$(grep -rl --include='*.rs' '\.tar\.gz' "$ROOT"/crates 2>/dev/null | tr '\n' ' ') + +{ + cat < required-by file:line provenance status sha256 +# +# Enumeration is grep-derived. It cannot see a fixture name that is not a +# string literal in the same file (manifest rows, vectors.sha256 names, +# format! interpolation); such names are only covered through their parent +# directory, which the verifier requires to exist AND be non-empty. +# $unnamed media-name literal(s) in this tree resolved under no enumerated +# fixture directory and are therefore not listed individually. +# +# ROOT FIXTURE ROOT: $FIXTURES +# +# VECTORS consumers (fixtures/vectors/*): ${vector_consumers:-none} +# VECTORS .tar.gz blob referenced by: ${blob_users:-nothing} +# The three fleet hosts carry the EXTRACTED vector sets (~470 files) and the +# sync deliberately excluded the .tar.gz blobs; nothing in crates/ reads a +# blob, so the extracted directories are the whole requirement. +# Unreferenced committed pins carried as rows: $orphans +EOF + sort -u "$tmp" +} >"$OUT" + +rows=$(grep -cv '^#' "$OUT") +echo "gen-fixture-library: $rows rows -> ${OUT#"$ROOT"/} ($unnamed unnamed media literals, $orphans unreferenced committed pins)" >&2 diff --git a/scripts/verify-fixture-library.sh b/scripts/verify-fixture-library.sh new file mode 100755 index 00000000..bf9fe2b5 --- /dev/null +++ b/scripts/verify-fixture-library.sh @@ -0,0 +1,183 @@ +#!/usr/bin/env bash +# verify-fixture-library.sh — preflight: does the on-disk fixture library match +# what the tests actually reach for? +# +# CHECKS +# SHAPE the manifest exists, is non-empty, and every row has 5 columns +# RESOLVE every referenced path exists, and every referenced DIRECTORY is +# non-empty (a present-but-empty corpus is the same false green as +# an absent one) +# DRIFT regenerating the manifest from source reproduces the committed +# file -- so a host whose library is behind the code fails here +# instead of reporting a green suite full of SKIPs +# +# TWO FAILURE MODES ARE DISTINGUISHED, because they have different fixes: +# (i) the fixture ROOT itself is absent. Root `fixtures/` is .gitignore:2, +# so no linked worktree ever has it: every vector gate skips GREEN in +# every worktree run. Fix: link or provision the library, not the code. +# (ii) a path under a PRESENT root is absent (or an empty dir). Fix: the +# generator named in the row, or the pin is genuinely missing. +# +# ENFORCEMENT ENV: EC_REQUIRE_FIXTURES=1 -- the same env the per-crate +# `require_fixture` asserts honour, so one convention covers the fleet batch +# units and a local run: +# set -> any absent referenced path is RED, and the drift diff is RED +# unset -> the same findings are printed SKIP-shaped and the exit stays 0, +# so an unprepared local checkout is not blocked +# +# Usage: scripts/verify-fixture-library.sh +# Env: EC_FIXTURES= fixture root, as every generator takes +# EC_REQUIRE_FIXTURES=1|0 enforcement (see above) +# +# ENUMERATION BLIND SPOT: the scan is grep-derived, so a fixture name that is +# not a string literal in the same file (a row of +# fixtures/real-library-manifest.tsv, a name in scripts/vectors.sha256, a +# format! interpolation) is not enumerated individually. Its parent directory +# is, and RESOLVE requires that directory to exist and be non-empty. This is a +# preflight against silent drift, not a proof that every byte a test reads is +# present. + +set -uo pipefail + +ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd) +MANIFEST=$ROOT/scripts/fixture-library.tsv +FIXTURES=${EC_FIXTURES:-$ROOT/fixtures} +REQUIRE=${EC_REQUIRE_FIXTURES:-0} +LINK_SCRIPT=$ROOT/scripts/link-fixtures.sh + +fail=0 +note() { [ "$REQUIRE" = 0 ] || echo "$@"; } + +echo "verify-fixture-library: root=$ROOT fixtures=$FIXTURES EC_REQUIRE_FIXTURES=${REQUIRE:-0}" + +# --- SHAPE --------------------------------------------------------------- +if [ ! -f "$MANIFEST" ]; then + echo "FAIL: $MANIFEST is missing -- run scripts/gen-fixture-library.sh" >&2 + exit 1 +fi +rows=$(grep -cv '^#' "$MANIFEST") +if [ "$rows" -eq 0 ]; then + echo "FAIL: $MANIFEST has no rows" >&2 + exit 1 +fi +malformed=$(awk -F'\t' '!/^#/ && NF != 5 { print NR": "$0 }' "$MANIFEST") +if [ -n "$malformed" ]; then + echo "FAIL: malformed rows in $MANIFEST (want 5 tab-separated columns):" >&2 + echo "$malformed" >&2 + exit 1 +fi +note " shape: $rows rows" + +# --- ROOT MODE (i) -------------------------------------------------------- +root_present=1 +[ -d "$FIXTURES" ] || root_present=0 +if [ "$root_present" -eq 0 ]; then + tag=SKIP + [ "$REQUIRE" != 0 ] && tag=FAIL + echo "$tag [mode i]: fixture root $FIXTURES does not exist." >&2 + echo " Root fixtures/ is .gitignore:2, so a linked worktree never has it --" >&2 + echo " that is why the vector gates skip GREEN here. Fix the TREE, not the" >&2 + echo " code: provision the library, or run the fixture-linking script once" >&2 + if [ -x "$LINK_SCRIPT" ]; then + echo " it lands: $LINK_SCRIPT" + else + echo " it exists (scripts/link-fixtures.sh -- another lane; not in this tree yet)." + fi + [ "$REQUIRE" != 0 ] && fail=1 +fi + +# --- RESOLVE -------------------------------------------------------------- +missing=() +empty=() +while IFS=$'\t' read -r path required_by provenance status sum; do + case $path in + \#* | '') continue ;; + esac + [ "$status" = absent-pin ] && continue # known gap, reported as a finding + case $path in + fixtures/*) abs=$FIXTURES/${path#fixtures/} ;; + *) abs=$ROOT/$path ;; + esac + if [ ! -e "$abs" ]; then + missing+=("$path <- $required_by (provenance: $provenance)") + elif [ -d "$abs" ] && [ -z "$(ls -A -- "$abs" 2>/dev/null)" ]; then + empty+=("$path <- $required_by (provenance: $provenance)") + fi +done <"$MANIFEST" + +if ((${#missing[@]})) && [ "$root_present" -eq 1 ]; then + if [ "$REQUIRE" != 0 ]; then + echo "FAIL [mode ii]: ${#missing[@]} referenced fixture path(s) do not resolve," >&2 + echo " inside a tree that HAS a fixture root -- the generator or the pin is" >&2 + echo " genuinely missing:" >&2 + printf ' %s\n' "${missing[@]}" >&2 + fail=1 + else + echo "SKIP: ${#missing[@]} referenced fixture path(s) do not resolve" >&2 + echo " (EC_REQUIRE_FIXTURES unset, so this is reported, not failed):" >&2 + printf ' %s\n' "${missing[@]}" >&2 + fi +fi +if ((${#empty[@]})); then + if [ "$REQUIRE" != 0 ]; then + echo "FAIL [mode ii]: ${#empty[@]} referenced fixture DIRECTORY(ies) exist but are empty:" >&2 + printf ' %s\n' "${empty[@]}" >&2 + fail=1 + else + echo "SKIP: ${#empty[@]} referenced fixture DIRECTORY(ies) exist but are empty:" >&2 + printf ' %s\n' "${empty[@]}" >&2 + fi +fi +note " resolve: ${#missing[@]} missing, ${#empty[@]} empty" + +# --- FINDINGS (not failures, but stated) --------------------------------- +no_prov=$(awk -F'\t' '!/^#/ && $3 ~ /^none/ {print $1}' "$MANIFEST" | sort -u) +absent=$(awk -F'\t' '!/^#/ && $4 == "absent-pin" {print $1"\t"$3}' "$MANIFEST" | sort -u) +if [ -n "$no_prov" ]; then + n=$(printf '%s\n' "$no_prov" | wc -l) + echo "FINDING: $n pinned fixture(s) have NO generator -- provenance is prose in a" >&2 + echo " gate comment only. A pin claim must cite the originating encoder" >&2 + echo " program and the artefact sha256 (the sha256 IS recorded in column 5):" >&2 + printf ' %s\n' $no_prov >&2 +fi +if [ -n "$absent" ]; then + echo "FINDING: $(printf '%s\n' "$absent" | wc -l) KNOWN-ABSENT pin(s), kept as rows so the gap stays visible:" >&2 + printf ' %s\n' "$absent" >&2 +fi + +# --- VECTORS ------------------------------------------------------------- +vec_rows=$(awk -F'\t' '!/^#/ && $1 ~ /^fixtures\/vectors\//' "$MANIFEST" | wc -l) +vec_missing=$(awk -F'\t' '!/^#/ && $1 ~ /^fixtures\/vectors\// && $4 != "ok"' "$MANIFEST" | wc -l) +echo " vectors: $vec_rows referenced rows, $vec_missing not ok" >&2 +echo " vectors: nothing in crates/ reads a .tar.gz; the fleet hosts carry the" >&2 +echo " EXTRACTED sets, so the blobs are not required at test time" >&2 + +# --- DRIFT ---------------------------------------------------------------- +regen=$(mktemp) +patch=$(mktemp) +trap 'rm -f "$regen" "$patch"' EXIT +if ! "$ROOT/scripts/gen-fixture-library.sh" "$regen" >/dev/null 2>&1; then + echo "FAIL: scripts/gen-fixture-library.sh did not run" >&2 + exit 1 +fi +if ! diff -u "$MANIFEST" "$regen" >"$patch" 2>&1; then + if [ "$REQUIRE" != 0 ]; then + echo "FAIL: scripts/fixture-library.tsv is stale -- the code reaches fixtures" >&2 + echo " this host does not have. Commit the regenerated manifest, or fetch" >&2 + echo " the missing library. (patch follows)" >&2 + sed -n '1,40p' "$patch" >&2 + fail=1 + else + echo "SKIP: scripts/fixture-library.tsv is stale (EC_REQUIRE_FIXTURES unset, so this" >&2 + echo " is reported, not failed). The code reaches fixtures this host lacks." >&2 + sed -n '1,20p' "$patch" >&2 + fi +else + note " drift: manifest matches the code" +fi + +if [ "$fail" -ne 0 ]; then + echo "verify-fixture-library: RED" >&2 + exit 1 +fi +echo "verify-fixture-library: GREEN ($rows rows)"