diff --git a/crates/ec-aac/tests/obs_real_content.rs b/crates/ec-aac/tests/obs_real_content.rs index 40c23550..58d4f2c7 100644 --- a/crates/ec-aac/tests/obs_real_content.rs +++ b/crates/ec-aac/tests/obs_real_content.rs @@ -28,11 +28,23 @@ fn ffmpeg_decode(path: &Path, channels: usize) -> Vec> { .args(["-v", "error", "-i"]) .arg(path) .args([ - "-map", "0:a:0", "-t", "10", "-f", "f32le", "-acodec", "pcm_f32le", "-", + "-map", + "0:a:0", + "-t", + "10", + "-f", + "f32le", + "-acodec", + "pcm_f32le", + "-", ]) .output() .expect("ffmpeg runs"); - assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "{}", + String::from_utf8_lossy(&out.stderr) + ); let samples: Vec = out .stdout .chunks_exact(4) @@ -48,7 +60,10 @@ fn ffmpeg_decode(path: &Path, channels: usize) -> Vec> { fn extract_aac_track(path: &Path) -> Option<(Vec, Vec>)> { let f = File::open(path).ok()?; let mut d = Mp4Demuxer::new(BufReader::new(f)).ok()?; - let aac = d.streams().iter().find(|s| s.params.codec == CodecId::Aac)?; + let aac = d + .streams() + .iter() + .find(|s| s.params.codec == CodecId::Aac)?; let idx = aac.index; let asc = aac.params.extradata.as_ref()?.to_vec(); let mut aus = Vec::new(); @@ -90,11 +105,18 @@ fn our_decode(path: &Path) -> Option>> { } } eprintln!(" {failed}/{} AUs failed", aus.len()); - if planes.is_empty() { None } else { Some(planes) } + if planes.is_empty() { + None + } else { + Some(planes) + } } fn dot(a: &[f32], b: &[f32]) -> f64 { - a.iter().zip(b).map(|(x, y)| f64::from(*x) * f64::from(*y)).sum() + a.iter() + .zip(b) + .map(|(x, y)| f64::from(*x) * f64::from(*y)) + .sum() } fn correlation(a: &[f32], b: &[f32]) -> f64 { @@ -114,14 +136,28 @@ fn correlation(a: &[f32], b: &[f32]) -> f64 { fn best_lag_correlation(ours: &[f32], theirs: &[f32]) -> (i64, f64) { const COARSE: usize = 4_096; - let start = ours.len().min(theirs.len()).saturating_sub(WINDOW).min(ours.len() / 4); + let start = ours + .len() + .min(theirs.len()) + .saturating_sub(WINDOW) + .min(ours.len() / 4); let slice_at = |lag: i64, len: usize| -> Option<(usize, usize)> { - let (oa, ob) = if lag >= 0 { (start, start + lag as usize) } else { (start + (-lag) as usize, start) }; - if oa + len > ours.len() || ob + len > theirs.len() { None } else { Some((oa, ob)) } + let (oa, ob) = if lag >= 0 { + (start, start + lag as usize) + } else { + (start + (-lag) as usize, start) + }; + if oa + len > ours.len() || ob + len > theirs.len() { + None + } else { + Some((oa, ob)) + } }; let mut coarse_best = (0i64, -1.0f64, 0.0f64); for lag in -(LAG_MAX as i64)..=(LAG_MAX as i64) { - let Some((oa, ob)) = slice_at(lag, COARSE) else { continue }; + let Some((oa, ob)) = slice_at(lag, COARSE) else { + continue; + }; let c = correlation(&ours[oa..oa + COARSE], &theirs[ob..ob + COARSE]); if c.abs() > coarse_best.1 { coarse_best = (lag, c.abs(), c); @@ -129,7 +165,9 @@ fn best_lag_correlation(ours: &[f32], theirs: &[f32]) -> (i64, f64) { } let mut best = (coarse_best.0, -1.0f64, 0.0f64); for lag in (coarse_best.0 - 8)..=(coarse_best.0 + 8) { - let Some((oa, ob)) = slice_at(lag, WINDOW) else { continue }; + let Some((oa, ob)) = slice_at(lag, WINDOW) else { + continue; + }; let c = correlation(&ours[oa..oa + WINDOW], &theirs[ob..ob + WINDOW]); if c.abs() > best.1 { best = (lag, c.abs(), c); @@ -148,7 +186,13 @@ fn obs_content_table() { eprintln!("skip: no ffmpeg"); return; } - let dir = PathBuf::from(std::env::var("HOME").unwrap()).join("Videos/OBS"); + // lane-h264reallib: `unwrap_or_default()` rather than a bare `unwrap()`. + // A host with no HOME -- a fleet runner -- panicked here before reaching + // the `read_dir` guard one line down, which already reports an absent + // directory correctly. With an empty HOME the guard simply reports + // `skip: no ./Videos/OBS`, so the test degrades to the silent skip its + // own guard was written for instead of a red that says nothing about AAC. + let dir = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join("Videos/OBS"); let Ok(rd) = std::fs::read_dir(&dir) else { eprintln!("skip: no {}", dir.display()); return; @@ -188,11 +232,21 @@ fn obs_content_table() { let rows = &all_rows[before..]; let (mut pns, mut is_, mut ms, mut tns, mut cpe) = (0usize, 0usize, 0usize, 0usize, 0usize); for r in rows { - if r.pns_bands > 0 { pns += 1; } - if r.is_bands > 0 { is_ += 1; } - if r.ms_bands > 0 { ms += 1; } - if r.tns_present { tns += 1; } - if r.is_cpe { cpe += 1; } + if r.pns_bands > 0 { + pns += 1; + } + if r.is_bands > 0 { + is_ += 1; + } + if r.ms_bands > 0 { + ms += 1; + } + if r.tns_present { + tns += 1; + } + if r.is_cpe { + cpe += 1; + } } eprintln!( " tools over {} AUs: cpe={cpe} pns_aus={pns} is_aus={is_} ms_aus={ms} tns_aus={tns}", diff --git a/crates/ec-aac/tests/sbr_real_library.rs b/crates/ec-aac/tests/sbr_real_library.rs index 6c27cf9e..edc3dc85 100644 --- a/crates/ec-aac/tests/sbr_real_library.rs +++ b/crates/ec-aac/tests/sbr_real_library.rs @@ -437,7 +437,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 +2117,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 +2238,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,9 +2441,8 @@ 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!( @@ -2444,8 +2456,21 @@ 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 @@ -2479,8 +2504,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 +2528,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 +2575,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), @@ -2886,8 +2915,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 +3189,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 +3597,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,9 +3753,8 @@ 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() { for rate in [48_000u32, 44_100] { @@ -3746,8 +3786,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 +3817,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 +3833,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 +3862,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 +3962,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,9 +4041,8 @@ 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() { per_au_low_band_probe("synthetic 44100 48k (failing)", &failing, 0); @@ -4097,7 +4188,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 +4204,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,9 +4331,8 @@ 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()); @@ -4256,7 +4347,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 +4423,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 +4449,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 +4506,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,9 +4679,8 @@ 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] = [ ( @@ -4690,9 +4799,8 @@ 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()); @@ -4748,7 +4856,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::>() ); } } @@ -4794,7 +4905,13 @@ fn sbr_residual_locator() { if !have_ffmpeg() { return; } - let home = std::env::var("HOME").unwrap(); + // lane-h264reallib: `unwrap_or_default()`, the shape this file's five + // other HOME reads already use (:2710, :3426, :4109, :4182, :4575). A bare + // `unwrap()` panicked on any host with no HOME -- a fleet runner -- which + // is a red with no bearing on the decoder. The `path.exists()` guard below + // already handles the absent-file case, so an empty HOME just makes the + // fallback path relative-and-nonexistent and the test returns. + let home = std::env::var("HOME").unwrap_or_default(); // `EC_AAC_SBR_LOCATOR_FILE` points the same instrument at any other // HE-AAC file (e.g. a mono, uncoupled, noise-only probe encode). let path = std::env::var("EC_AAC_SBR_LOCATOR_FILE") @@ -4803,7 +4920,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 +4934,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 +4989,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-matroska/tests/matroska.rs b/crates/ec-matroska/tests/matroska.rs index c7405411..1b37c3bb 100644 --- a/crates/ec-matroska/tests/matroska.rs +++ b/crates/ec-matroska/tests/matroska.rs @@ -32,7 +32,9 @@ fn aac_priming_round_trips_through_codec_delay() { let dst = work().join("aac-priming-round-trip.mkv"); let mut muxer = MatroskaMuxer::new(File::create(&dst).expect("output")); let stream = muxer.add_stream(info).expect("stream declared"); - muxer.set_track_delay(stream, 21_333_333).expect("declare delay"); // 1024/48000s + muxer + .set_track_delay(stream, 21_333_333) + .expect("declare delay"); // 1024/48000s for _ in 0..10i64 { let mut packet = Packet::new(0, rate, vec![0u8; 8]); packet.duration = Some(1024); @@ -44,7 +46,8 @@ fn aac_priming_round_trips_through_codec_delay() { let demuxer = MatroskaDemuxer::new(BufReader::new(File::open(&dst).expect("opens"))).expect("reopens"); assert_eq!( - demuxer.streams()[0].initial_padding, 1024, + demuxer.streams()[0].initial_padding, + 1024, "CodecDelay round trips to a sample count" ); } @@ -802,7 +805,11 @@ fn truncated_prefixes_are_eof_not_corrupt() { table.join("\n") ); } - println!("{}\nidx,cut,class,packets\n{}", path.display(), table.join("\n")); + println!( + "{}\nidx,cut,class,packets\n{}", + path.display(), + table.join("\n") + ); } fn matroska_prefix_class(data: &[u8]) -> (&'static str, u64) { @@ -823,7 +830,6 @@ fn matroska_prefix_class(data: &[u8]) -> (&'static str, u64) { } } - /// Where our own demuxer's seek lands on a real 5.1 E-AC-3 Matroska, in /// *timestamp* -- split from decode, per the round's charter: this measures /// only [`MatroskaDemuxer::seek`] plus the first packet's `pts`, against what @@ -963,7 +969,12 @@ fn same_class_sweep(path: &str, wants: &[f64], tolerance_ms: f64) { #[test] #[ignore = "sweeps his real library, run manually with --ignored"] fn laced_audio_sweep_across_his_library() { - let manifest = Path::new("/home/user/Documents/Code/Rust/edith_codecs/fixtures/real-library-manifest.tsv"); + // lane-h264reallib: `fixtures()` like every sibling, instead of a + // hardcoded absolute path into the primary checkout. The absolute form + // silently defeated worktree isolation: a run in a worktree or a gate tree + // read the MAIN checkout's manifest, so this test measured a different + // tree's library than the one it was compiled from. + let manifest = &fixtures().join("real-library-manifest.tsv"); let Ok(rows) = std::fs::read_to_string(manifest) else { eprintln!("skipped: {} not present", manifest.display()); return; @@ -987,8 +998,7 @@ fn laced_audio_sweep_across_his_library() { if !film.exists() { continue; } - let Ok(mut demux) = - MatroskaDemuxer::new(BufReader::new(File::open(film).expect("opens"))) + let Ok(mut demux) = MatroskaDemuxer::new(BufReader::new(File::open(film).expect("opens"))) else { eprintln!("{path}: failed to open"); continue; @@ -1004,8 +1014,7 @@ fn laced_audio_sweep_across_his_library() { for frac in [0.3, 0.7] { let want = duration * frac; let target = Timestamp::new( - (want * audio.time_base.den() as f64 / audio.time_base.num() as f64).round() - as i64, + (want * audio.time_base.den() as f64 / audio.time_base.num() as f64).round() as i64, audio.time_base, ); if demux @@ -1096,8 +1105,8 @@ fn real_hdr_film_container_states_no_light_metadata() { // duplication, pts) or the shared decoder crate, and which physical channel // our 5.1 decode calls "channel 0". -use ec_ac3::Ac3Decoder; use ec_aac::AacDecoder; +use ec_ac3::Ac3Decoder; /// Opens whichever container `path` actually is — both crates implement the /// same `Demuxer` trait, so the rest of the harness never has to know which. @@ -1109,9 +1118,15 @@ fn open_any(path: &Path) -> Box { .read_exact(&mut head) .expect("read head"); if ec_mp4::is_mp4(&head) { - Box::new(ec_mp4::Mp4Demuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mp4 opens")) + Box::new( + ec_mp4::Mp4Demuxer::new(BufReader::new(File::open(path).expect("open"))) + .expect("mp4 opens"), + ) } else { - Box::new(MatroskaDemuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mkv opens")) + Box::new( + MatroskaDemuxer::new(BufReader::new(File::open(path).expect("open"))) + .expect("mkv opens"), + ) } } @@ -1201,7 +1216,15 @@ fn ffmpeg_decode_planar(path: &Path, channels: usize) -> Vec> { .args(["-v", "error", "-i"]) .arg(path) .args([ - "-map", "0:a:0", "-t", "20", "-f", "f32le", "-acodec", "pcm_f32le", "-", + "-map", + "0:a:0", + "-t", + "20", + "-f", + "f32le", + "-acodec", + "pcm_f32le", + "-", ]) .output() .expect("ffmpeg runs"); @@ -1251,8 +1274,14 @@ fn best_lag_correlation(ours: &[f32], theirs: &[f32]) -> (i64, f64) { let mut best_abs = -1.0f64; let mut best = (0i64, 0.0f64); for lag in -LAG_MAX..=LAG_MAX { - let (oa, ob) = if lag >= 0 { (0usize, lag as usize) } else { ((-lag) as usize, 0usize) }; - let len = WINDOW.min(ours.len().saturating_sub(oa)).min(theirs.len().saturating_sub(ob)); + let (oa, ob) = if lag >= 0 { + (0usize, lag as usize) + } else { + ((-lag) as usize, 0usize) + }; + let len = WINDOW + .min(ours.len().saturating_sub(oa)) + .min(theirs.len().saturating_sub(ob)); if len < 1024 { continue; } @@ -1387,7 +1416,11 @@ fn mkv_51_channel_order() { pkts.iter().take(5).map(|(p, _)| *p).collect::>() ); let planes = decode_ac3(&pkts); - assert!(!planes.is_empty(), "{}: no channels decoded", path.display()); + assert!( + !planes.is_empty(), + "{}: no channels decoded", + path.display() + ); let ffref = ffmpeg_decode_planar(path, planes.len()); for (i, ch) in planes.iter().enumerate() { let (lag, c) = best_lag_correlation(ch, &ffref[0]); diff --git a/crates/ec-probe/tests/library.rs b/crates/ec-probe/tests/library.rs index 223a2cc2..98c6f16f 100644 --- a/crates/ec-probe/tests/library.rs +++ b/crates/ec-probe/tests/library.rs @@ -487,7 +487,20 @@ fn a_real_library_sweep() { taken += 1; } } - assert!(!chosen.is_empty(), "no readable files in the manifest"); + // lane-h264reallib: NOT an `assert!` here. The file's own header, lines + // 5-6, is the spec: "Files that have since moved are skipped and + // reported, never failed -- the manifest is a snapshot of a moving + // library." An empty `chosen` IS the moved-files case, so failing on it + // contradicted the contract this file declares. It was also red on any + // host whose manifest paths no longer resolve, for a reason that had + // nothing to do with the probe. Reported and returned, which is what + // "skipped and reported, never failed" asks for. + if chosen.is_empty() { + eprintln!( + "skipped: no readable file in the manifest (every row has moved or is unreadable)" + ); + return; + } let mut rows = Vec::new(); let mut failures = Vec::new(); diff --git a/lanes/h264reallib.report.md b/lanes/h264reallib.report.md index 3e0c02e6..66f40a73 100644 --- a/lanes/h264reallib.report.md +++ b/lanes/h264reallib.report.md @@ -76,6 +76,7 @@ still stands, and still holds, on the machine that can run it (it did: 15 ≥ 3) Verified — the target is no longer red, and the reason is printed verbatim: ``` + test real_library_streams_match_ffmpeg ... ignored, sweeps the PERSONAL media library (~/Videos, ~/Downloads, ~/Music) through the gitignored fixtures/real-library-manifest.tsv; MINUTES of wall time (measured past 840 s on @@ -169,12 +170,35 @@ with a soft skip, so it is harmless today, and it also silently defeats worktree isolation. Worth converting to the relative form if that ignore is ever lifted. +### Round 2 — the four approved follow-ups (all now fixed) + +| site | change | before | after | +|---|---|---|---| +| `crates/ec-probe/tests/library.rs:490` | `assert!(!chosen.is_empty())` → named SKIP + `return` | red-on-runner whenever every manifest path had moved | `1 passed; 0 failed; 0 ignored` | +| `crates/ec-aac/tests/sbr_real_library.rs:4797` | `env::var("HOME").unwrap()` → `.unwrap_or_default()` | `FAILED. 0 passed; 1 failed` — `called Result::unwrap() on an Err value: NotPresent` | `1 passed; 0 failed; 0 ignored` | +| `crates/ec-aac/tests/obs_real_content.rs:151` | same | `FAILED. 0 passed; 1 failed` — same panic | `1 passed; 0 failed; 0 ignored` | +| `crates/ec-matroska/tests/matroska.rs:966` | hardcoded absolute manifest path → `fixtures()` | read the PRIMARY checkout's manifest from any worktree | `fixtures()` = `CARGO_MANIFEST_DIR/../../fixtures`, like every sibling | + +The two HOME fixes were proved by running them under `env -u HOME` (the +runner shape) before and after; the probe fix was proved by running the test +with its manifest paths unresolvable. + +**Sweep disposition after round 2: 6 fixed, 0 remaining, 14 already correct, +the rest already `#[ignore]`d or false positives.** No member of this class is +left red-on-runner. + ## Change list | file | change | |---|---| | `crates/ec-h264/tests/conformance.rs:1870` | `#[ignore = "…"]` + 25-line reason above the test; assertion untouched | | `crates/ec-aac/tests/oracle.rs:688` | `#[ignore = "…"]` + reason; identical shape, assertion untouched | - -No decoder change. No new `#[ignore]` beyond the two class members above (both -were red-on-runner, never green). No assertion weakened anywhere. +| `crates/ec-probe/tests/library.rs:490` | minimum-count assert → named SKIP + return; restores the file's own :5-6 contract | +| `crates/ec-aac/tests/sbr_real_library.rs:4797` | bare `env::var("HOME").unwrap()` → `unwrap_or_default()` | +| `crates/ec-aac/tests/obs_real_content.rs:151` | same | +| `crates/ec-matroska/tests/matroska.rs:966` | hardcoded absolute manifest path → `fixtures()` | + +No decoder change anywhere. Two new `#[ignore]`s, both previously +red-on-runner and never green. The only assertion removed is the +`ec-probe` minimum count, and removing it RESTORES the contract that file's +own header declares rather than hiding a failure; no other assertion weakened.