Tests: ec-aac/ac3/alac/amr use ec-testkit fixtures and ffmpeg; skip branches removed, missing fixtures panic
Browse files at this commitae257263c0cd3fe86d9e778a4854adc16dd60016Parent: 155ce7436 changed files +418 -1988
- Cargo.lock +4 -0
- crates/ec-aac/Cargo.toml +1 -0
- crates/ec-aac/fuzz/seed.sh +2 -2
- crates/ec-aac/tests/common/mod.rs +0 -18
- crates/ec-aac/tests/it/implicit_sbr.rs +2 -40
- crates/ec-aac/tests/it/main.rs +0 -2
- crates/ec-aac/tests/it/multichannel_parity.rs +10 -51
- crates/ec-aac/tests/it/no_panic.rs +1 -28
- crates/ec-aac/tests/it/ps_mp4.rs +2 -9
- crates/ec-aac/tests/it/ps_oracle.rs +1 -18
- crates/ec-aac/tests/it/reelh_per_frame.rs +4 -15
- crates/ec-aac/tests/obs_real_content.rs +0 -249
- crates/ec-aac/tests/oracle.rs +15 -403
- crates/ec-aac/tests/sbr_real_library/chunk_a.rs +189 -345
- crates/ec-aac/tests/sbr_real_library/chunk_b.rs +25 -181
- crates/ec-aac/tests/sbr_real_library/chunk_c.rs +17 -112
- crates/ec-aac/tests/sbr_real_library/helpers.rs +14 -29
- crates/ec-aac/tests/sbr_real_library/main.rs +5 -10
- crates/ec-ac3/Cargo.toml +3 -0
- crates/ec-ac3/fuzz/seed.sh +2 -2
- crates/ec-ac3/tests/it/common.rs +0 -9
- crates/ec-ac3/tests/it/decode_matrix.rs +13 -53
- crates/ec-ac3/tests/it/dependent.rs +11 -77
- crates/ec-ac3/tests/it/encode_matrix.rs +26 -43
- crates/ec-ac3/tests/it/ffmpeg_parity.rs +2 -9
- crates/ec-ac3/tests/it/main.rs +0 -1
- crates/ec-ac3/tests/it/packet_walk.rs +7 -47
- crates/ec-ac3/tests/it/real_library.rs +22 -120
- crates/ec-alac/Cargo.toml +1 -0
- crates/ec-alac/tests/encode.rs +13 -37
- crates/ec-alac/tests/oracle.rs +7 -23
- crates/ec-amr/Cargo.toml +1 -0
- crates/ec-amr/fuzz/seed.sh +3 -2
- crates/ec-amr/tests/container_roundtrip.rs +3 -16
- crates/ec-amr/tests/oracle.rs +8 -18
- crates/ec-amr/tests/wb_oracle.rs +4 -19
Cargo.lockmodified+4 -0
| @@ -330,6 +330,7 @@ dependencies = [ | |||
| 330 | "ec-dsp", | 330 | "ec-dsp", |
| 331 | "ec-matroska", | 331 | "ec-matroska", |
| 332 | "ec-mp4", | 332 | "ec-mp4", |
| 333 | + "ec-testkit", | ||
| 333 | ] | 334 | ] |
| 334 | 335 | ||
| 335 | [[package]] | 336 | [[package]] |
| @@ -338,6 +339,7 @@ version = "0.1.0" | |||
| 338 | dependencies = [ | 339 | dependencies = [ |
| 339 | "ec-core", | 340 | "ec-core", |
| 340 | "ec-dsp", | 341 | "ec-dsp", |
| 342 | + "ec-testkit", | ||
| 341 | ] | 343 | ] |
| 342 | 344 | ||
| 343 | [[package]] | 345 | [[package]] |
| @@ -347,6 +349,7 @@ dependencies = [ | |||
| 347 | "ec-core", | 349 | "ec-core", |
| 348 | "ec-mp4", | 350 | "ec-mp4", |
| 349 | "ec-riff", | 351 | "ec-riff", |
| 352 | + "ec-testkit", | ||
| 350 | ] | 353 | ] |
| 351 | 354 | ||
| 352 | [[package]] | 355 | [[package]] |
| @@ -356,6 +359,7 @@ dependencies = [ | |||
| 356 | "ec-core", | 359 | "ec-core", |
| 357 | "ec-mp4", | 360 | "ec-mp4", |
| 358 | "ec-riff", | 361 | "ec-riff", |
| 362 | + "ec-testkit", | ||
| 359 | ] | 363 | ] |
| 360 | 364 | ||
| 361 | [[package]] | 365 | [[package]] |
crates/ec-aac/Cargo.tomlmodified+1 -0
| @@ -13,3 +13,4 @@ ec-dsp = { workspace = true } | |||
| 13 | [dev-dependencies] | 13 | [dev-dependencies] |
| 14 | ec-mp4 = { workspace = true } | 14 | ec-mp4 = { workspace = true } |
| 15 | ec-matroska = { workspace = true } | 15 | ec-matroska = { workspace = true } |
| 16 | +ec-testkit.workspace = true | ||
crates/ec-aac/fuzz/seed.shmodified+2 -2
| @@ -18,8 +18,8 @@ mkdir -p "$HE_CORPUS" | |||
| 18 | for f in "$HE_DIR"/*.aac; do cp -f "$f" "$HE_CORPUS/"; done | 18 | for f in "$HE_DIR"/*.aac; do cp -f "$f" "$HE_CORPUS/"; done |
| 19 | echo "seeded $(ls "$HE_CORPUS" | wc -l) decode_he seeds" | 19 | echo "seeded $(ls "$HE_CORPUS" | wc -l) decode_he seeds" |
| 20 | 20 | ||
| 21 | -FIXTURES=$(cd -- "$FUZZ_DIR/../../.." && pwd)/fixtures/audio | 21 | +FIXTURES=${EC_FIXTURES:-$(cd -- "$FUZZ_DIR/../../.." && pwd)/fixtures}/audio |
| 22 | -[ -d "$FIXTURES" ] || { echo "seed.sh: $FIXTURES missing; run scripts/link-fixtures.sh (decode_he is seeded)" >&2; exit 0; } | 22 | +[ -d "$FIXTURES" ] || { echo "seed.sh: $FIXTURES missing; run scripts/fixtures.sh" >&2; exit 2; } |
| 23 | 23 | ||
| 24 | ADTS=("$FIXTURES"/aac-adts-*.aac) | 24 | ADTS=("$FIXTURES"/aac-adts-*.aac) |
| 25 | [ -e "${ADTS[0]}" ] || { echo "seed.sh: no aac-adts-*.aac fixtures in $FIXTURES" >&2; exit 2; } | 25 | [ -e "${ADTS[0]}" ] || { echo "seed.sh: no aac-adts-*.aac fixtures in $FIXTURES" >&2; exit 2; } |
crates/ec-aac/tests/common/mod.rsdeleted+0 -18
| @@ -1,18 +0,0 @@ | |||
| 1 | -//! Helpers shared by the ec-aac test binaries that need them: `oracle`, | ||
| 2 | -//! `obs_real_content`, `sbr_real_library` and the merged `it` binary. | ||
| 3 | - | ||
| 4 | -use std::path::{Path, PathBuf}; | ||
| 5 | -use std::process::Command; | ||
| 6 | - | ||
| 7 | -pub fn have_ffmpeg() -> bool { | ||
| 8 | - Command::new("ffmpeg") | ||
| 9 | - .arg("-version") | ||
| 10 | - .output() | ||
| 11 | - .map(|o| o.status.success()) | ||
| 12 | - .unwrap_or(false) | ||
| 13 | -} | ||
| 14 | - | ||
| 15 | -#[allow(dead_code)] // not used by the sbr_real_library binary | ||
| 16 | -pub fn fixtures() -> PathBuf { | ||
| 17 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures") | ||
| 18 | -} | ||
crates/ec-aac/tests/it/implicit_sbr.rsmodified+2 -40
| @@ -2,28 +2,10 @@ | |||
| 2 | //! ADTS header says plain AAC-LC, but whose frames carry an SBR extension | 2 | //! ADTS header says plain AAC-LC, but whose frames carry an SBR extension |
| 3 | //! payload, is decoded as HE-AAC at twice the core rate, as ffmpeg does. | 3 | //! payload, is decoded as HE-AAC at twice the core rate, as ffmpeg does. |
| 4 | 4 | ||
| 5 | -use crate::shared::fixtures; | ||
| 6 | -use crate::shared::have_ffmpeg; | ||
| 7 | use std::path::{Path, PathBuf}; | 5 | use std::path::{Path, PathBuf}; |
| 8 | -use std::process::Command; | ||
| 9 | 6 | ||
| 10 | use ec_aac::{AacDecoder, SbrSupport}; | 7 | use ec_aac::{AacDecoder, SbrSupport}; |
| 11 | 8 | ||
| 12 | -/// Same contract as `oracle.rs`: an absent fixture skips loudly, and under | ||
| 13 | -/// `EC_REQUIRE_FIXTURES=1` it is a hard failure instead. | ||
| 14 | -fn require_fixture(path: &Path) -> bool { | ||
| 15 | - let present = path.exists(); | ||
| 16 | - assert!( | ||
| 17 | - present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 18 | - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent", | ||
| 19 | - path.display() | ||
| 20 | - ); | ||
| 21 | - if !present { | ||
| 22 | - eprintln!("SKIP: fixture {} absent", path.display()); | ||
| 23 | - } | ||
| 24 | - present | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | /// The implicit-signalling HE-AAC fixture: 2 s of `heaac_44100_48k.m4a` remuxed to | 9 | /// The implicit-signalling HE-AAC fixture: 2 s of `heaac_44100_48k.m4a` remuxed to |
| 28 | /// bare ADTS with `ffmpeg -c copy -f adts`. Its headers say AAC-LC at 22050 Hz. | 10 | /// bare ADTS with `ffmpeg -c copy -f adts`. Its headers say AAC-LC at 22050 Hz. |
| 29 | fn implicit_fixture() -> PathBuf { | 11 | fn implicit_fixture() -> PathBuf { |
| @@ -32,7 +14,7 @@ fn implicit_fixture() -> PathBuf { | |||
| 32 | 14 | ||
| 33 | /// ffmpeg's decode of a file, as planar-by-channel `f32`. | 15 | /// ffmpeg's decode of a file, as planar-by-channel `f32`. |
| 34 | fn ffmpeg_decode(path: &Path) -> Vec<Vec<f32>> { | 16 | fn ffmpeg_decode(path: &Path) -> Vec<Vec<f32>> { |
| 35 | - let out = Command::new("ffmpeg") | 17 | + let out = ec_testkit::ffmpeg() |
| 36 | .args(["-v", "error", "-i"]) | 18 | .args(["-v", "error", "-i"]) |
| 37 | .arg(path) | 19 | .arg(path) |
| 38 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-"]) | 20 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-"]) |
| @@ -112,9 +94,6 @@ fn decode_adts(path: &Path) -> (Vec<Vec<f32>>, Option<u32>, Vec<u32>, AacDecoder | |||
| 112 | #[test] | 94 | #[test] |
| 113 | fn implicit_he_aac_adts_switches_to_double_rate() { | 95 | fn implicit_he_aac_adts_switches_to_double_rate() { |
| 114 | let path = implicit_fixture(); | 96 | let path = implicit_fixture(); |
| 115 | - if !require_fixture(&path) { | ||
| 116 | - return; | ||
| 117 | - } | ||
| 118 | let (ours, before, rates, decoder) = decode_adts(&path); | 97 | let (ours, before, rates, decoder) = decode_adts(&path); |
| 119 | 98 | ||
| 120 | // Headers say 22050 Hz AAC-LC: nothing is known about the rate before frame 1. | 99 | // Headers say 22050 Hz AAC-LC: nothing is known about the rate before frame 1. |
| @@ -139,14 +118,7 @@ fn implicit_he_aac_adts_switches_to_double_rate() { | |||
| 139 | 118 | ||
| 140 | #[test] | 119 | #[test] |
| 141 | fn implicit_he_aac_adts_matches_ffmpeg_per_channel() { | 120 | fn implicit_he_aac_adts_matches_ffmpeg_per_channel() { |
| 142 | - if !have_ffmpeg() { | ||
| 143 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 144 | - return; | ||
| 145 | - } | ||
| 146 | let path = implicit_fixture(); | 121 | let path = implicit_fixture(); |
| 147 | - if !require_fixture(&path) { | ||
| 148 | - return; | ||
| 149 | - } | ||
| 150 | let (ours, _, _, _) = decode_adts(&path); | 122 | let (ours, _, _, _) = decode_adts(&path); |
| 151 | let theirs = ffmpeg_decode(&path); | 123 | let theirs = ffmpeg_decode(&path); |
| 152 | assert_eq!(theirs.len(), ours.len()); | 124 | assert_eq!(theirs.len(), ours.len()); |
| @@ -158,14 +130,7 @@ fn implicit_he_aac_adts_matches_ffmpeg_per_channel() { | |||
| 158 | 130 | ||
| 159 | #[test] | 131 | #[test] |
| 160 | fn plain_aac_lc_adts_is_unchanged_by_implicit_detection() { | 132 | fn plain_aac_lc_adts_is_unchanged_by_implicit_detection() { |
| 161 | - if !have_ffmpeg() { | 133 | + let path = ec_testkit::fixture("audio/aac-adts-stereo-44100.aac"); |
| 162 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 163 | - return; | ||
| 164 | - } | ||
| 165 | - let path = fixtures().join("audio/aac-adts-stereo-44100.aac"); | ||
| 166 | - if !require_fixture(&path) { | ||
| 167 | - return; | ||
| 168 | - } | ||
| 169 | let (ours, _, rates, decoder) = decode_adts(&path); | 134 | let (ours, _, rates, decoder) = decode_adts(&path); |
| 170 | 135 | ||
| 171 | // A plain LC stream has no SBR payload: no switch, and the rate stays at the core. | 136 | // A plain LC stream has no SBR payload: no switch, and the rate stays at the core. |
| @@ -189,9 +154,6 @@ fn plain_aac_lc_adts_is_unchanged_by_implicit_detection() { | |||
| 189 | #[test] | 154 | #[test] |
| 190 | fn core_only_decode_of_implicit_he_aac_stays_at_core_rate() { | 155 | fn core_only_decode_of_implicit_he_aac_stays_at_core_rate() { |
| 191 | let path = implicit_fixture(); | 156 | let path = implicit_fixture(); |
| 192 | - if !require_fixture(&path) { | ||
| 193 | - return; | ||
| 194 | - } | ||
| 195 | let data = std::fs::read(&path).expect("fixture readable"); | 157 | let data = std::fs::read(&path).expect("fixture readable"); |
| 196 | let mut decoder = AacDecoder::new().core_only(); | 158 | let mut decoder = AacDecoder::new().core_only(); |
| 197 | let mut frames = 0usize; | 159 | let mut frames = 0usize; |
crates/ec-aac/tests/it/main.rsmodified+0 -2
| @@ -1,8 +1,6 @@ | |||
| 1 | #![forbid(unsafe_code)] | 1 | #![forbid(unsafe_code)] |
| 2 | //! Merged integration tests for ec-aac: one module per former `tests/*.rs` file. | 2 | //! Merged integration tests for ec-aac: one module per former `tests/*.rs` file. |
| 3 | 3 | ||
| 4 | -#[path = "../common/mod.rs"] | ||
| 5 | -mod shared; | ||
| 6 | mod common; | 4 | mod common; |
| 7 | 5 | ||
| 8 | mod he_parity; | 6 | mod he_parity; |
crates/ec-aac/tests/it/multichannel_parity.rsmodified+10 -51
| @@ -11,13 +11,12 @@ | |||
| 11 | //! then each channel's correlation must reach 0.999. For 5.1 and 7.1 the channel | 11 | //! then each channel's correlation must reach 0.999. For 5.1 and 7.1 the channel |
| 12 | //! order is also checked: our channel k must correlate best with FFmpeg's channel k. | 12 | //! order is also checked: our channel k must correlate best with FFmpeg's channel k. |
| 13 | //! | 13 | //! |
| 14 | -//! Fixtures are generated at test time, so no media is committed. Without ffmpeg | 14 | +//! Fixtures are generated at test time, so no media is committed. A missing |
| 15 | -//! the test skips loudly; with `EC_REQUIRE_FIXTURES=1` a missing ffmpeg is a failure. | 15 | +//! ffmpeg or encoder fails the test. |
| 16 | 16 | ||
| 17 | use std::fs::File; | 17 | use std::fs::File; |
| 18 | use std::io::BufReader; | 18 | use std::io::BufReader; |
| 19 | use std::path::{Path, PathBuf}; | 19 | use std::path::{Path, PathBuf}; |
| 20 | -use std::process::Command; | ||
| 21 | 20 | ||
| 22 | use ec_aac::{AacDecoder, is_adts, parse_adts}; | 21 | use ec_aac::{AacDecoder, is_adts, parse_adts}; |
| 23 | use ec_core::{CodecId, Demuxer, Packet}; | 22 | use ec_core::{CodecId, Demuxer, Packet}; |
| @@ -74,41 +73,15 @@ const LAYOUTS: &[Layout] = &[ | |||
| 74 | Layout { name: "7.1", channels: 8, freqs: &[300, 450, 620, 780, 960, 1130, 1310, 1500] }, | 73 | Layout { name: "7.1", channels: 8, freqs: &[300, 450, 620, 780, 960, 1130, 1310, 1500] }, |
| 75 | ]; | 74 | ]; |
| 76 | 75 | ||
| 77 | -/// The encoders under test. Native `aac` is always present; `libfdk_aac` is used | 76 | +/// The encoders under test, both built into the pinned ffmpeg. |
| 78 | -/// only when the local ffmpeg lists it. | ||
| 79 | const ENCODERS: &[&str] = &["aac", "libfdk_aac"]; | 77 | const ENCODERS: &[&str] = &["aac", "libfdk_aac"]; |
| 80 | 78 | ||
| 81 | fn fixtures_dir() -> PathBuf { | 79 | fn fixtures_dir() -> PathBuf { |
| 82 | PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("aac_multichannel") | 80 | PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("aac_multichannel") |
| 83 | } | 81 | } |
| 84 | 82 | ||
| 85 | -fn ffmpeg_ok(args: &[&str]) -> bool { | 83 | +/// Encodes a multitone of `layout` with `encoder` into `container`. Returns the path. |
| 86 | - Command::new("ffmpeg") | 84 | +fn encode(layout: &Layout, encoder: &str, container: Container) -> PathBuf { |
| 87 | - .args(args) | ||
| 88 | - .output() | ||
| 89 | - .map(|o| o.status.success()) | ||
| 90 | - .unwrap_or(false) | ||
| 91 | -} | ||
| 92 | - | ||
| 93 | -fn have_ffmpeg() -> bool { | ||
| 94 | - ffmpeg_ok(&["-version"]) | ||
| 95 | -} | ||
| 96 | - | ||
| 97 | -fn have_encoder(name: &str) -> bool { | ||
| 98 | - let out = Command::new("ffmpeg") | ||
| 99 | - .args(["-hide_banner", "-encoders"]) | ||
| 100 | - .output(); | ||
| 101 | - match out { | ||
| 102 | - Ok(o) => String::from_utf8_lossy(&o.stdout) | ||
| 103 | - .lines() | ||
| 104 | - .any(|l| l.split_whitespace().nth(1) == Some(name)), | ||
| 105 | - Err(_) => false, | ||
| 106 | - } | ||
| 107 | -} | ||
| 108 | - | ||
| 109 | -/// Encodes a multitone of `layout` with `encoder` into `container`. Returns the path, | ||
| 110 | -/// or `None` when the encoder refuses the configuration. | ||
| 111 | -fn encode(layout: &Layout, encoder: &str, container: Container) -> Option<PathBuf> { | ||
| 112 | let dir = fixtures_dir(); | 85 | let dir = fixtures_dir(); |
| 113 | std::fs::create_dir_all(&dir).expect("fixture dir"); | 86 | std::fs::create_dir_all(&dir).expect("fixture dir"); |
| 114 | let out = dir.join(format!( | 87 | let out = dir.join(format!( |
| @@ -130,19 +103,20 @@ fn encode(layout: &Layout, encoder: &str, container: Container) -> Option<PathBu | |||
| 130 | ); | 103 | ); |
| 131 | // 48 kbit/s per channel keeps every layout in a comfortable quality range. | 104 | // 48 kbit/s per channel keeps every layout in a comfortable quality range. |
| 132 | let bitrate = format!("{}k", 48 * layout.channels); | 105 | let bitrate = format!("{}k", 48 * layout.channels); |
| 133 | - let status = Command::new("ffmpeg") | 106 | + let status = ec_testkit::ffmpeg() |
| 134 | .args(["-v", "error", "-y", "-f", "lavfi", "-i", &source]) | 107 | .args(["-v", "error", "-y", "-f", "lavfi", "-i", &source]) |
| 135 | .args(["-c:a", encoder, "-profile:a", "aac_low", "-b:a", &bitrate]) | 108 | .args(["-c:a", encoder, "-profile:a", "aac_low", "-b:a", &bitrate]) |
| 136 | .args(["-ac", &layout.channels.to_string(), "-f", container.muxer()]) | 109 | .args(["-ac", &layout.channels.to_string(), "-f", container.muxer()]) |
| 137 | .arg(&out) | 110 | .arg(&out) |
| 138 | .status() | 111 | .status() |
| 139 | .expect("ffmpeg runs"); | 112 | .expect("ffmpeg runs"); |
| 140 | - status.success().then_some(out) | 113 | + assert!(status.success(), "{encoder} refused the {} layout", layout.name); |
| 114 | + out | ||
| 141 | } | 115 | } |
| 142 | 116 | ||
| 143 | /// FFmpeg's decode of `path` as planar-by-channel `f32`, in its own channel order. | 117 | /// FFmpeg's decode of `path` as planar-by-channel `f32`, in its own channel order. |
| 144 | fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { | 118 | fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { |
| 145 | - let out = Command::new("ffmpeg") | 119 | + let out = ec_testkit::ffmpeg() |
| 146 | .args(["-v", "error", "-i"]) | 120 | .args(["-v", "error", "-i"]) |
| 147 | .arg(path) | 121 | .arg(path) |
| 148 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-ac"]) | 122 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-ac"]) |
| @@ -310,10 +284,7 @@ fn matrix(ours: &[Vec<f32>], theirs: &[Vec<f32>], lag: i64) -> Vec<Vec<f64>> { | |||
| 310 | 284 | ||
| 311 | fn check_case(layout: &Layout, encoder: &str, container: Container, failures: &mut Vec<String>) { | 285 | fn check_case(layout: &Layout, encoder: &str, container: Container, failures: &mut Vec<String>) { |
| 312 | let label = format!("{:<6} {:<5} {:<10}", layout.name, container.label(), encoder); | 286 | let label = format!("{:<6} {:<5} {:<10}", layout.name, container.label(), encoder); |
| 313 | - let Some(path) = encode(layout, encoder, container) else { | 287 | + let path = encode(layout, encoder, container); |
| 314 | - println!("SKIP {label}: encoder refused the configuration"); | ||
| 315 | - return; | ||
| 316 | - }; | ||
| 317 | let theirs = ffmpeg_decode(&path, layout.channels); | 288 | let theirs = ffmpeg_decode(&path, layout.channels); |
| 318 | let (ours, channels, rate) = match container { | 289 | let (ours, channels, rate) = match container { |
| 319 | Container::Adts => ours_adts(&path), | 290 | Container::Adts => ours_adts(&path), |
| @@ -369,20 +340,8 @@ fn check_case(layout: &Layout, encoder: &str, container: Container, failures: &m | |||
| 369 | 340 | ||
| 370 | #[test] | 341 | #[test] |
| 371 | fn multichannel_matches_ffmpeg_per_channel() { | 342 | fn multichannel_matches_ffmpeg_per_channel() { |
| 372 | - if !have_ffmpeg() { | ||
| 373 | - assert!( | ||
| 374 | - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 375 | - "EC_REQUIRE_FIXTURES=1 but ffmpeg is not installed" | ||
| 376 | - ); | ||
| 377 | - eprintln!("SKIP: ffmpeg not installed"); | ||
| 378 | - return; | ||
| 379 | - } | ||
| 380 | let mut failures = Vec::new(); | 343 | let mut failures = Vec::new(); |
| 381 | for encoder in ENCODERS { | 344 | for encoder in ENCODERS { |
| 382 | - if *encoder != "aac" && !have_encoder(encoder) { | ||
| 383 | - println!("SKIP encoder {encoder}: not built into this ffmpeg"); | ||
| 384 | - continue; | ||
| 385 | - } | ||
| 386 | for layout in LAYOUTS { | 345 | for layout in LAYOUTS { |
| 387 | for container in [Container::Adts, Container::Mp4] { | 346 | for container in [Container::Adts, Container::Mp4] { |
| 388 | check_case(layout, encoder, container, &mut failures); | 347 | check_case(layout, encoder, container, &mut failures); |
crates/ec-aac/tests/it/no_panic.rsmodified+1 -28
| @@ -6,7 +6,6 @@ | |||
| 6 | //! produced it instead of aborting the whole run. | 6 | //! produced it instead of aborting the whole run. |
| 7 | 7 | ||
| 8 | use std::panic::{catch_unwind, AssertUnwindSafe}; | 8 | use std::panic::{catch_unwind, AssertUnwindSafe}; |
| 9 | -use std::path::{Path, PathBuf}; | ||
| 10 | 9 | ||
| 11 | use ec_aac::AacDecoder; | 10 | use ec_aac::AacDecoder; |
| 12 | 11 | ||
| @@ -40,10 +39,6 @@ impl Rng { | |||
| 40 | } | 39 | } |
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | -fn audio_dir() -> PathBuf { | ||
| 44 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | /// Decodes one packet with a fresh decoder. Returns false if it panicked. | 42 | /// Decodes one packet with a fresh decoder. Returns false if it panicked. |
| 48 | fn decode_no_panic(label: &str, packet: &[u8]) -> bool { | 43 | fn decode_no_panic(label: &str, packet: &[u8]) -> bool { |
| 49 | let outcome = catch_unwind(AssertUnwindSafe(|| { | 44 | let outcome = catch_unwind(AssertUnwindSafe(|| { |
| @@ -76,27 +71,11 @@ fn adts_frame_starts(data: &[u8]) -> Vec<usize> { | |||
| 76 | 71 | ||
| 77 | #[test] | 72 | #[test] |
| 78 | fn fixtures_truncated_and_corrupted_never_panic() { | 73 | fn fixtures_truncated_and_corrupted_never_panic() { |
| 79 | - let dir = audio_dir(); | ||
| 80 | - let mut found = 0usize; | ||
| 81 | let mut failures: Vec<String> = Vec::new(); | 74 | let mut failures: Vec<String> = Vec::new(); |
| 82 | let mut rng = Rng(SEED); | 75 | let mut rng = Rng(SEED); |
| 83 | 76 | ||
| 84 | for name in ADTS_FIXTURES { | 77 | for name in ADTS_FIXTURES { |
| 85 | - let path = dir.join(name); | 78 | + let data = std::fs::read(ec_testkit::fixture(&format!("audio/{name}"))).expect("fixture"); |
| 86 | - let data = match std::fs::read(&path) { | ||
| 87 | - Ok(d) => d, | ||
| 88 | - Err(_) => { | ||
| 89 | - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { | ||
| 90 | - panic!( | ||
| 91 | - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: scripts/gen-fixtures.sh", | ||
| 92 | - path.display() | ||
| 93 | - ); | ||
| 94 | - } | ||
| 95 | - eprintln!("SKIP: fixture {} absent", path.display()); | ||
| 96 | - continue; | ||
| 97 | - } | ||
| 98 | - }; | ||
| 99 | - found += 1; | ||
| 100 | assert!(!adts_frame_starts(&data).is_empty(), "{name} is not an ADTS stream"); | 79 | assert!(!adts_frame_starts(&data).is_empty(), "{name} is not an ADTS stream"); |
| 101 | 80 | ||
| 102 | // Ten truncation points spread across the file (never the full length). | 81 | // Ten truncation points spread across the file (never the full length). |
| @@ -124,12 +103,6 @@ fn fixtures_truncated_and_corrupted_never_panic() { | |||
| 124 | } | 103 | } |
| 125 | } | 104 | } |
| 126 | 105 | ||
| 127 | - if found == 0 { | ||
| 128 | - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { | ||
| 129 | - panic!("no ADTS fixtures found under {}", dir.display()); | ||
| 130 | - } | ||
| 131 | - eprintln!("SKIP: no ADTS fixtures under {}", dir.display()); | ||
| 132 | - } | ||
| 133 | assert!(failures.is_empty(), "{} inputs panicked: {:?}", failures.len(), failures); | 106 | assert!(failures.is_empty(), "{} inputs panicked: {:?}", failures.len(), failures); |
| 134 | } | 107 | } |
| 135 | 108 | ||
crates/ec-aac/tests/it/ps_mp4.rsmodified+2 -9
| @@ -7,12 +7,10 @@ | |||
| 7 | //! produce two channels at the extension rate, matching FFmpeg's own decode of | 7 | //! produce two channels at the extension rate, matching FFmpeg's own decode of |
| 8 | //! the same mp4. | 8 | //! the same mp4. |
| 9 | 9 | ||
| 10 | -use crate::shared::have_ffmpeg; | ||
| 11 | use crate::common::fixture; | 10 | use crate::common::fixture; |
| 12 | use std::fs::File; | 11 | use std::fs::File; |
| 13 | use std::io::BufReader; | 12 | use std::io::BufReader; |
| 14 | use std::path::{Path, PathBuf}; | 13 | use std::path::{Path, PathBuf}; |
| 15 | -use std::process::Command; | ||
| 16 | 14 | ||
| 17 | use ec_aac::AacDecoder; | 15 | use ec_aac::AacDecoder; |
| 18 | use ec_core::{CodecId, Demuxer, Packet}; | 16 | use ec_core::{CodecId, Demuxer, Packet}; |
| @@ -23,7 +21,7 @@ const RATE: u32 = 48_000; | |||
| 23 | 21 | ||
| 24 | /// FFmpeg's decode of `path` as interleaved f32, two channels at `RATE`. | 22 | /// FFmpeg's decode of `path` as interleaved f32, two channels at `RATE`. |
| 25 | fn ffmpeg_stereo(path: &Path) -> Vec<f32> { | 23 | fn ffmpeg_stereo(path: &Path) -> Vec<f32> { |
| 26 | - let out = Command::new("ffmpeg") | 24 | + let out = ec_testkit::ffmpeg() |
| 27 | .args(["-v", "error", "-i"]) | 25 | .args(["-v", "error", "-i"]) |
| 28 | .arg(path) | 26 | .arg(path) |
| 29 | .args(["-f", "f32le", "-ac", "2", "-ar", "48000", "-"]) | 27 | .args(["-f", "f32le", "-ac", "2", "-ar", "48000", "-"]) |
| @@ -50,16 +48,11 @@ fn correlation(a: &[f32], b: &[f32]) -> f64 { | |||
| 50 | 48 | ||
| 51 | #[test] | 49 | #[test] |
| 52 | fn ps_in_mp4_decodes_to_stereo_like_ffmpeg() { | 50 | fn ps_in_mp4_decodes_to_stereo_like_ffmpeg() { |
| 53 | - if !have_ffmpeg() { | ||
| 54 | - eprintln!("SKIP: ffmpeg not installed"); | ||
| 55 | - return; | ||
| 56 | - } | ||
| 57 | let src = fixture(FIXTURE); | 51 | let src = fixture(FIXTURE); |
| 58 | - assert!(src.exists(), "fixture {} is absent", src.display()); | ||
| 59 | let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")); | 52 | let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")); |
| 60 | std::fs::create_dir_all(&dir).expect("temp dir"); | 53 | std::fs::create_dir_all(&dir).expect("temp dir"); |
| 61 | let mp4 = dir.join("ps_48000_music.m4a"); | 54 | let mp4 = dir.join("ps_48000_music.m4a"); |
| 62 | - let status = Command::new("ffmpeg") | 55 | + let status = ec_testkit::ffmpeg() |
| 63 | .args(["-v", "error", "-y", "-i"]) | 56 | .args(["-v", "error", "-y", "-i"]) |
| 64 | .arg(&src) | 57 | .arg(&src) |
| 65 | .args(["-c", "copy", "-f", "mp4"]) | 58 | .args(["-c", "copy", "-f", "mp4"]) |
crates/ec-aac/tests/it/ps_oracle.rsmodified+1 -18
| @@ -6,13 +6,11 @@ | |||
| 6 | //! at least 0.999 after a bounded lag search, which absorbs decoder priming | 6 | //! at least 0.999 after a bounded lag search, which absorbs decoder priming |
| 7 | //! delay, as `sbr_real_library.rs` does for HE-AAC v1. | 7 | //! delay, as `sbr_real_library.rs` does for HE-AAC v1. |
| 8 | 8 | ||
| 9 | -use crate::shared::have_ffmpeg; | ||
| 10 | use crate::common::fixture; | 9 | use crate::common::fixture; |
| 11 | use crate::common::deinterleave; | 10 | use crate::common::deinterleave; |
| 12 | use crate::common::correlation; | 11 | use crate::common::correlation; |
| 13 | use ec_aac::AacDecoder; | 12 | use ec_aac::AacDecoder; |
| 14 | use std::path::Path; | 13 | use std::path::Path; |
| 15 | -use std::process::Command; | ||
| 16 | 14 | ||
| 17 | /// Per-channel correlation the reconstruction must reach against FFmpeg. | 15 | /// Per-channel correlation the reconstruction must reach against FFmpeg. |
| 18 | const MIN_CORR: f64 = 0.999; | 16 | const MIN_CORR: f64 = 0.999; |
| @@ -39,7 +37,7 @@ const FIXTURES: &[(&str, u32)] = &[ | |||
| 39 | 37 | ||
| 40 | /// FFmpeg's decode of `path` as planar stereo `f32`. | 38 | /// FFmpeg's decode of `path` as planar stereo `f32`. |
| 41 | fn ffmpeg_reference(path: &Path) -> Vec<Vec<f32>> { | 39 | fn ffmpeg_reference(path: &Path) -> Vec<Vec<f32>> { |
| 42 | - let out = Command::new("ffmpeg") | 40 | + let out = ec_testkit::ffmpeg() |
| 43 | .args(["-v", "error", "-i"]) | 41 | .args(["-v", "error", "-i"]) |
| 44 | .arg(path) | 42 | .arg(path) |
| 45 | .args(["-ac", "2", "-f", "f32le", "-acodec", "pcm_f32le", "-"]) | 43 | .args(["-ac", "2", "-f", "f32le", "-acodec", "pcm_f32le", "-"]) |
| @@ -97,24 +95,9 @@ fn best_lag(ours: &[f32], theirs: &[f32]) -> (i64, f64) { | |||
| 97 | 95 | ||
| 98 | #[test] | 96 | #[test] |
| 99 | fn ps_fixtures_decode_to_stereo_matching_ffmpeg() { | 97 | fn ps_fixtures_decode_to_stereo_matching_ffmpeg() { |
| 100 | - let require = std::env::var_os("EC_REQUIRE_FIXTURES").is_some(); | ||
| 101 | - if !have_ffmpeg() { | ||
| 102 | - assert!(!require, "EC_REQUIRE_FIXTURES=1 but ffmpeg is not installed"); | ||
| 103 | - eprintln!("SKIP: ffmpeg not installed"); | ||
| 104 | - return; | ||
| 105 | - } | ||
| 106 | let mut failures = Vec::new(); | 98 | let mut failures = Vec::new(); |
| 107 | for &(name, rate) in FIXTURES { | 99 | for &(name, rate) in FIXTURES { |
| 108 | let path = fixture(name); | 100 | let path = fixture(name); |
| 109 | - assert!( | ||
| 110 | - path.exists() || !require, | ||
| 111 | - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent", | ||
| 112 | - path.display() | ||
| 113 | - ); | ||
| 114 | - if !path.exists() { | ||
| 115 | - eprintln!("SKIP: fixture {} absent", path.display()); | ||
| 116 | - continue; | ||
| 117 | - } | ||
| 118 | let bytes = std::fs::read(&path).expect("fixture reads"); | 101 | let bytes = std::fs::read(&path).expect("fixture reads"); |
| 119 | let audio = AacDecoder::new() | 102 | let audio = AacDecoder::new() |
| 120 | .decode(&bytes, None) | 103 | .decode(&bytes, None) |
crates/ec-aac/tests/it/reelh_per_frame.rsmodified+4 -15
| @@ -3,11 +3,8 @@ | |||
| 3 | //! collapses mid-stream, sequentially, with no seek/reset. Finds the first | 3 | //! collapses mid-stream, sequentially, with no seek/reset. Finds the first |
| 4 | //! bad frame and its side info, to compare with the frame before. | 4 | //! bad frame and its side info, to compare with the frame before. |
| 5 | 5 | ||
| 6 | -use crate::shared::have_ffmpeg; | ||
| 7 | use std::fs::File; | 6 | use std::fs::File; |
| 8 | use std::io::BufReader; | 7 | use std::io::BufReader; |
| 9 | -use std::path::Path; | ||
| 10 | -use std::process::Command; | ||
| 11 | 8 | ||
| 12 | use ec_aac::AacDecoder; | 9 | use ec_aac::AacDecoder; |
| 13 | use ec_core::{CodecId, Demuxer, Packet}; | 10 | use ec_core::{CodecId, Demuxer, Packet}; |
| @@ -15,21 +12,13 @@ use ec_mp4::Mp4Demuxer; | |||
| 15 | 12 | ||
| 16 | #[test] | 13 | #[test] |
| 17 | fn reelh_per_frame_scan() { | 14 | fn reelh_per_frame_scan() { |
| 18 | - if !have_ffmpeg() { | 15 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 19 | - eprintln!("skip: no ffmpeg"); | ||
| 20 | - return; | ||
| 21 | - } | ||
| 22 | - let path = Path::new("/home/user/Downloads/reelh.mp4"); | ||
| 23 | - if !path.exists() { | ||
| 24 | - eprintln!("skip: file not present"); | ||
| 25 | - return; | ||
| 26 | - } | ||
| 27 | let _knob = ec_aac::knobs::set_tool_sideinfo_debug(Some(true)); | 16 | let _knob = ec_aac::knobs::set_tool_sideinfo_debug(Some(true)); |
| 28 | 17 | ||
| 29 | // ffmpeg's channel-0-only decode (pan, not -ac, per the repro). | 18 | // ffmpeg's channel-0-only decode (pan, not -ac, per the repro). |
| 30 | - let out = Command::new("ffmpeg") | 19 | + let out = ec_testkit::ffmpeg() |
| 31 | .args(["-v", "error", "-i"]) | 20 | .args(["-v", "error", "-i"]) |
| 32 | - .arg(path) | 21 | + .arg(&path) |
| 33 | .args([ | 22 | .args([ |
| 34 | "-map", "0:a:0", "-af", "pan=1c|c0=c0", "-f", "f32le", "-acodec", "pcm_f32le", "-", | 23 | "-map", "0:a:0", "-af", "pan=1c|c0=c0", "-f", "f32le", "-acodec", "pcm_f32le", "-", |
| 35 | ]) | 24 | ]) |
| @@ -43,7 +32,7 @@ fn reelh_per_frame_scan() { | |||
| 43 | .collect(); | 32 | .collect(); |
| 44 | 33 | ||
| 45 | // Our sequential decode: one decoder, no reset, packet 0 onward. | 34 | // Our sequential decode: one decoder, no reset, packet 0 onward. |
| 46 | - let f = File::open(path).unwrap(); | 35 | + let f = File::open(&path).unwrap(); |
| 47 | let mut d = Mp4Demuxer::new(BufReader::new(f)).unwrap(); | 36 | let mut d = Mp4Demuxer::new(BufReader::new(f)).unwrap(); |
| 48 | let aac = d | 37 | let aac = d |
| 49 | .streams() | 38 | .streams() |
crates/ec-aac/tests/obs_real_content.rsdeleted+0 -249
| @@ -1,249 +0,0 @@ | |||
| 1 | -//! Table over every screen recording under `~/Videos/OBS`, diagnosing the | ||
| 2 | -//! PNS/M/S decorrelation the consumer sweep found in that encoder's output | ||
| 3 | -//! (see repo ledger). Real files, read-only, absent directory skips loudly. | ||
| 4 | - | ||
| 5 | -mod common; | ||
| 6 | - | ||
| 7 | -use common::have_ffmpeg; | ||
| 8 | -use std::path::{Path, PathBuf}; | ||
| 9 | -use std::process::Command; | ||
| 10 | - | ||
| 11 | -use ec_aac::AacDecoder; | ||
| 12 | -use ec_core::{CodecId, Demuxer, Packet}; | ||
| 13 | -use ec_mp4::Mp4Demuxer; | ||
| 14 | -use std::fs::File; | ||
| 15 | -use std::io::BufReader; | ||
| 16 | - | ||
| 17 | -const MAX_SAMPLES: usize = 480_000; // 10s @ 48kHz | ||
| 18 | -const LAG_MAX: usize = 4_000; | ||
| 19 | -const WINDOW: usize = 200_000; | ||
| 20 | - | ||
| 21 | -fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { | ||
| 22 | - let out = Command::new("ffmpeg") | ||
| 23 | - .args(["-v", "error", "-i"]) | ||
| 24 | - .arg(path) | ||
| 25 | - .args([ | ||
| 26 | - "-map", | ||
| 27 | - "0:a:0", | ||
| 28 | - "-t", | ||
| 29 | - "10", | ||
| 30 | - "-f", | ||
| 31 | - "f32le", | ||
| 32 | - "-acodec", | ||
| 33 | - "pcm_f32le", | ||
| 34 | - "-", | ||
| 35 | - ]) | ||
| 36 | - .output() | ||
| 37 | - .expect("ffmpeg runs"); | ||
| 38 | - assert!( | ||
| 39 | - out.status.success(), | ||
| 40 | - "{}", | ||
| 41 | - String::from_utf8_lossy(&out.stderr) | ||
| 42 | - ); | ||
| 43 | - let samples: Vec<f32> = out | ||
| 44 | - .stdout | ||
| 45 | - .as_chunks::<4>().0.iter() | ||
| 46 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 47 | - .collect(); | ||
| 48 | - let mut planes = vec![Vec::with_capacity(samples.len() / channels.max(1)); channels]; | ||
| 49 | - for (i, &v) in samples.iter().enumerate() { | ||
| 50 | - planes[i % channels].push(v); | ||
| 51 | - } | ||
| 52 | - planes | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -fn extract_aac_track(path: &Path) -> Option<(Vec<u8>, Vec<Vec<u8>>)> { | ||
| 56 | - let f = File::open(path).ok()?; | ||
| 57 | - let mut d = Mp4Demuxer::new(BufReader::new(f)).ok()?; | ||
| 58 | - let aac = d | ||
| 59 | - .streams() | ||
| 60 | - .iter() | ||
| 61 | - .find(|s| s.params.codec == CodecId::Aac)?; | ||
| 62 | - let idx = aac.index; | ||
| 63 | - let asc = aac.params.extradata.as_ref()?.to_vec(); | ||
| 64 | - let mut aus = Vec::new(); | ||
| 65 | - while aus.len() < 1_500 { | ||
| 66 | - match d.next_packet() { | ||
| 67 | - Ok(Packet { stream, data, .. }) if stream == idx => aus.push(data.to_vec()), | ||
| 68 | - Ok(_) => continue, | ||
| 69 | - Err(_) => break, | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | - Some((asc, aus)) | ||
| 73 | -} | ||
| 74 | - | ||
| 75 | -fn our_decode(path: &Path) -> Option<Vec<Vec<f32>>> { | ||
| 76 | - let (asc, aus) = extract_aac_track(path)?; | ||
| 77 | - let mut decoder = AacDecoder::with_config_bytes(&asc).ok()?; | ||
| 78 | - let mut planes: Vec<Vec<f32>> = Vec::new(); | ||
| 79 | - let mut failed = 0usize; | ||
| 80 | - for au in &aus { | ||
| 81 | - let frame = match decoder.decode(au, None) { | ||
| 82 | - Ok(f) => f, | ||
| 83 | - Err(_) => { | ||
| 84 | - failed += 1; | ||
| 85 | - continue; | ||
| 86 | - } | ||
| 87 | - }; | ||
| 88 | - let ch = usize::from(frame.channels); | ||
| 89 | - if ch == 0 { | ||
| 90 | - continue; | ||
| 91 | - } | ||
| 92 | - if planes.is_empty() { | ||
| 93 | - planes = vec![Vec::new(); ch]; | ||
| 94 | - } | ||
| 95 | - for (i, v) in frame.samples.iter().enumerate() { | ||
| 96 | - planes[i % ch].push(*v); | ||
| 97 | - } | ||
| 98 | - if planes[0].len() >= MAX_SAMPLES { | ||
| 99 | - break; | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - eprintln!(" {failed}/{} AUs failed", aus.len()); | ||
| 103 | - if planes.is_empty() { | ||
| 104 | - None | ||
| 105 | - } else { | ||
| 106 | - Some(planes) | ||
| 107 | - } | ||
| 108 | -} | ||
| 109 | - | ||
| 110 | -fn dot(a: &[f32], b: &[f32]) -> f64 { | ||
| 111 | - a.iter() | ||
| 112 | - .zip(b) | ||
| 113 | - .map(|(x, y)| f64::from(*x) * f64::from(*y)) | ||
| 114 | - .sum() | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | -fn correlation(a: &[f32], b: &[f32]) -> f64 { | ||
| 118 | - let n = a.len().min(b.len()); | ||
| 119 | - if n < 1024 { | ||
| 120 | - return 0.0; | ||
| 121 | - } | ||
| 122 | - let (a, b) = (&a[..n], &b[..n]); | ||
| 123 | - let ma = a.iter().map(|v| f64::from(*v)).sum::<f64>() / n as f64; | ||
| 124 | - let mb = b.iter().map(|v| f64::from(*v)).sum::<f64>() / n as f64; | ||
| 125 | - let ac: Vec<f32> = a.iter().map(|v| (f64::from(*v) - ma) as f32).collect(); | ||
| 126 | - let bc: Vec<f32> = b.iter().map(|v| (f64::from(*v) - mb) as f32).collect(); | ||
| 127 | - let num = dot(&ac, &bc); | ||
| 128 | - let den = (dot(&ac, &ac) * dot(&bc, &bc)).sqrt(); | ||
| 129 | - if den == 0.0 { 0.0 } else { num / den } | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | -fn best_lag_correlation(ours: &[f32], theirs: &[f32]) -> (i64, f64) { | ||
| 133 | - const COARSE: usize = 4_096; | ||
| 134 | - let start = ours | ||
| 135 | - .len() | ||
| 136 | - .min(theirs.len()) | ||
| 137 | - .saturating_sub(WINDOW) | ||
| 138 | - .min(ours.len() / 4); | ||
| 139 | - let slice_at = |lag: i64, len: usize| -> Option<(usize, usize)> { | ||
| 140 | - let (oa, ob) = if lag >= 0 { | ||
| 141 | - (start, start + lag as usize) | ||
| 142 | - } else { | ||
| 143 | - (start + (-lag) as usize, start) | ||
| 144 | - }; | ||
| 145 | - if oa + len > ours.len() || ob + len > theirs.len() { | ||
| 146 | - None | ||
| 147 | - } else { | ||
| 148 | - Some((oa, ob)) | ||
| 149 | - } | ||
| 150 | - }; | ||
| 151 | - let mut coarse_best = (0i64, -1.0f64, 0.0f64); | ||
| 152 | - for lag in -(LAG_MAX as i64)..=(LAG_MAX as i64) { | ||
| 153 | - let Some((oa, ob)) = slice_at(lag, COARSE) else { | ||
| 154 | - continue; | ||
| 155 | - }; | ||
| 156 | - let c = correlation(&ours[oa..oa + COARSE], &theirs[ob..ob + COARSE]); | ||
| 157 | - if c.abs() > coarse_best.1 { | ||
| 158 | - coarse_best = (lag, c.abs(), c); | ||
| 159 | - } | ||
| 160 | - } | ||
| 161 | - let mut best = (coarse_best.0, -1.0f64, 0.0f64); | ||
| 162 | - for lag in (coarse_best.0 - 8)..=(coarse_best.0 + 8) { | ||
| 163 | - let Some((oa, ob)) = slice_at(lag, WINDOW) else { | ||
| 164 | - continue; | ||
| 165 | - }; | ||
| 166 | - let c = correlation(&ours[oa..oa + WINDOW], &theirs[ob..ob + WINDOW]); | ||
| 167 | - if c.abs() > best.1 { | ||
| 168 | - best = (lag, c.abs(), c); | ||
| 169 | - } | ||
| 170 | - } | ||
| 171 | - (best.0, best.2) | ||
| 172 | -} | ||
| 173 | - | ||
| 174 | -fn rms(a: &[f32]) -> f64 { | ||
| 175 | - (a.iter().map(|v| f64::from(*v) * f64::from(*v)).sum::<f64>() / a.len().max(1) as f64).sqrt() | ||
| 176 | -} | ||
| 177 | - | ||
| 178 | -#[test] | ||
| 179 | -fn obs_content_table() { | ||
| 180 | - if !have_ffmpeg() { | ||
| 181 | - eprintln!("skip: no ffmpeg"); | ||
| 182 | - return; | ||
| 183 | - } | ||
| 184 | - // lane-h264reallib: `unwrap_or_default()` rather than a bare `unwrap()`. | ||
| 185 | - // A host with no HOME -- a fleet runner -- panicked here before reaching | ||
| 186 | - // the `read_dir` guard one line down, which already reports an absent | ||
| 187 | - // directory correctly. With an empty HOME the guard simply reports | ||
| 188 | - // `skip: no ./Videos/OBS`, so the test degrades to the silent skip its | ||
| 189 | - // own guard was written for instead of a red that says nothing about AAC. | ||
| 190 | - let dir = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join("Videos/OBS"); | ||
| 191 | - let Ok(rd) = std::fs::read_dir(&dir) else { | ||
| 192 | - eprintln!("skip: no {}", dir.display()); | ||
| 193 | - return; | ||
| 194 | - }; | ||
| 195 | - let mut files: Vec<PathBuf> = rd | ||
| 196 | - .filter_map(|e| e.ok()) | ||
| 197 | - .map(|e| e.path()) | ||
| 198 | - .filter(|p| p.extension().and_then(|e| e.to_str()) == Some("mp4")) | ||
| 199 | - .collect(); | ||
| 200 | - files.sort(); | ||
| 201 | - let _knob = ec_aac::knobs::set_tool_sideinfo_debug(Some(true)); | ||
| 202 | - for path in files { | ||
| 203 | - eprintln!("== {}", path.display()); | ||
| 204 | - let before = ec_aac::tool_sideinfo_log().len(); | ||
| 205 | - let Some(ours) = our_decode(&path) else { | ||
| 206 | - eprintln!(" our_decode: None"); | ||
| 207 | - continue; | ||
| 208 | - }; | ||
| 209 | - let theirs = ffmpeg_decode(&path, ours.len()); | ||
| 210 | - for (ch, (o, t)) in ours.iter().zip(theirs.iter()).enumerate() { | ||
| 211 | - let (lag, corr) = best_lag_correlation(o, t); | ||
| 212 | - // Also the direct, un-windowed corr from t=0 (no lag search) -- | ||
| 213 | - // this is what the consumer sweep that found this regression | ||
| 214 | - // measured, and can disagree with the windowed/lag-searched | ||
| 215 | - // number above if only part of the file is corrupted. | ||
| 216 | - let corr0 = correlation(o, t); | ||
| 217 | - let non_finite = o.iter().filter(|v| !v.is_finite()).count(); | ||
| 218 | - eprintln!( | ||
| 219 | - " ch{ch}: corr={corr:.4} corr@lag0={corr0:.4} lag={lag} rms_ours={:.5} rms_ffmpeg={:.5} non_finite={non_finite}", | ||
| 220 | - rms(o), | ||
| 221 | - rms(t) | ||
| 222 | - ); | ||
| 223 | - } | ||
| 224 | - let all_rows = ec_aac::tool_sideinfo_log(); | ||
| 225 | - let rows = &all_rows[before..]; | ||
| 226 | - let (mut pns, mut is_, mut ms, mut tns, mut cpe) = (0usize, 0usize, 0usize, 0usize, 0usize); | ||
| 227 | - for r in rows { | ||
| 228 | - if r.pns_bands > 0 { | ||
| 229 | - pns += 1; | ||
| 230 | - } | ||
| 231 | - if r.is_bands > 0 { | ||
| 232 | - is_ += 1; | ||
| 233 | - } | ||
| 234 | - if r.ms_bands > 0 { | ||
| 235 | - ms += 1; | ||
| 236 | - } | ||
| 237 | - if r.tns_present { | ||
| 238 | - tns += 1; | ||
| 239 | - } | ||
| 240 | - if r.is_cpe { | ||
| 241 | - cpe += 1; | ||
| 242 | - } | ||
| 243 | - } | ||
| 244 | - eprintln!( | ||
| 245 | - " tools over {} AUs: cpe={cpe} pns_aus={pns} is_aus={is_} ms_aus={ms} tns_aus={tns}", | ||
| 246 | - rows.len() | ||
| 247 | - ); | ||
| 248 | - } | ||
| 249 | -} | ||
crates/ec-aac/tests/oracle.rsmodified+15 -403
| @@ -1,42 +1,13 @@ | |||
| 1 | -//! Decoder and encoder against ffmpeg, on the generated fixtures and on the | 1 | +//! Decoder and encoder against ffmpeg, on the generated fixtures. A missing |
| 2 | -//! real library. Every test that needs a fixture or ffmpeg skips loudly when it | 2 | +//! fixture or ffmpeg fails the test. |
| 3 | -//! is absent rather than passing quietly. | ||
| 4 | 3 | ||
| 5 | -mod common; | ||
| 6 | - | ||
| 7 | -use common::{fixtures, have_ffmpeg}; | ||
| 8 | use std::path::{Path, PathBuf}; | 4 | use std::path::{Path, PathBuf}; |
| 9 | -use std::process::Command; | ||
| 10 | 5 | ||
| 11 | use ec_aac::{AacDecoder, AacEncoder, AacEncoderConfig}; | 6 | use ec_aac::{AacDecoder, AacEncoder, AacEncoderConfig}; |
| 12 | 7 | ||
| 13 | -/// Fixture-presence probe for the committed `fixtures/audio` media this file | ||
| 14 | -/// decodes. Returns whether the fixture is present, but never silently: under | ||
| 15 | -/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path | ||
| 16 | -/// and the script that regenerates it, so a host whose fixture library drifted | ||
| 17 | -/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; | ||
| 18 | -/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently | ||
| 19 | -/// short-circuited because the probe ran first in a compound `if`). | ||
| 20 | -/// | ||
| 21 | -/// Order is load-bearing: probe, assert, return. Never merge the probe into | ||
| 22 | -/// the same `if` as the escape. | ||
| 23 | -fn require_fixture(path: &Path, generator: &str) -> bool { | ||
| 24 | - let present = path.exists(); | ||
| 25 | - assert!( | ||
| 26 | - present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 27 | - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", | ||
| 28 | - path.display(), | ||
| 29 | - generator | ||
| 30 | - ); | ||
| 31 | - if !present { | ||
| 32 | - eprintln!("SKIP: fixture {} absent", path.display()); | ||
| 33 | - } | ||
| 34 | - present | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | /// ffmpeg's decode of a file, as planar-by-channel `f32`. | 8 | /// ffmpeg's decode of a file, as planar-by-channel `f32`. |
| 38 | fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { | 9 | fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { |
| 39 | - let out = Command::new("ffmpeg") | 10 | + let out = ec_testkit::ffmpeg() |
| 40 | .args(["-v", "error", "-i"]) | 11 | .args(["-v", "error", "-i"]) |
| 41 | .arg(path) | 12 | .arg(path) |
| 42 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-"]) | 13 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-"]) |
| @@ -128,11 +99,6 @@ fn compare(path: &Path) -> Vec<f64> { | |||
| 128 | 99 | ||
| 129 | #[test] | 100 | #[test] |
| 130 | fn adts_fixtures_match_ffmpeg_per_channel() { | 101 | fn adts_fixtures_match_ffmpeg_per_channel() { |
| 131 | - if !have_ffmpeg() { | ||
| 132 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 133 | - return; | ||
| 134 | - } | ||
| 135 | - let dir = fixtures().join("audio"); | ||
| 136 | let mut checked = 0; | 102 | let mut checked = 0; |
| 137 | for name in [ | 103 | for name in [ |
| 138 | "aac-adts-mono-44100.aac", | 104 | "aac-adts-mono-44100.aac", |
| @@ -142,10 +108,7 @@ fn adts_fixtures_match_ffmpeg_per_channel() { | |||
| 142 | "aac-adts-5.1-44100.aac", | 108 | "aac-adts-5.1-44100.aac", |
| 143 | "aac-adts-5.1-48000.aac", | 109 | "aac-adts-5.1-48000.aac", |
| 144 | ] { | 110 | ] { |
| 145 | - let path = dir.join(name); | 111 | + let path = ec_testkit::fixture(&format!("audio/{name}")); |
| 146 | - if !require_fixture(&path, "scripts/gen-fixtures.sh") { | ||
| 147 | - continue; | ||
| 148 | - } | ||
| 149 | let corr = compare(&path); | 112 | let corr = compare(&path); |
| 150 | println!("{name}: {corr:?}"); | 113 | println!("{name}: {corr:?}"); |
| 151 | for (ch, c) in corr.iter().enumerate() { | 114 | for (ch, c) in corr.iter().enumerate() { |
| @@ -164,11 +127,6 @@ fn adts_fixtures_match_ffmpeg_per_channel() { | |||
| 164 | 127 | ||
| 165 | #[test] | 128 | #[test] |
| 166 | fn mp4_fixtures_match_ffmpeg_per_channel() { | 129 | fn mp4_fixtures_match_ffmpeg_per_channel() { |
| 167 | - if !have_ffmpeg() { | ||
| 168 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 169 | - return; | ||
| 170 | - } | ||
| 171 | - let dir = fixtures().join("audio"); | ||
| 172 | let tmp = std::env::temp_dir().join("ec-aac-mp4-oracle"); | 130 | let tmp = std::env::temp_dir().join("ec-aac-mp4-oracle"); |
| 173 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 131 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 174 | let mut checked = 0; | 132 | let mut checked = 0; |
| @@ -177,14 +135,11 @@ fn mp4_fixtures_match_ffmpeg_per_channel() { | |||
| 177 | "aac-mp4-stereo-48000.mp4", | 135 | "aac-mp4-stereo-48000.mp4", |
| 178 | "aac-mp4-5.1-48000.mp4", | 136 | "aac-mp4-5.1-48000.mp4", |
| 179 | ] { | 137 | ] { |
| 180 | - let path = dir.join(name); | 138 | + let path = ec_testkit::fixture(&format!("audio/{name}")); |
| 181 | - if !require_fixture(&path, "scripts/gen-fixtures.sh") { | ||
| 182 | - continue; | ||
| 183 | - } | ||
| 184 | // The mp4 side of the family is another slice; the elementary stream | 139 | // The mp4 side of the family is another slice; the elementary stream |
| 185 | // comes out with a stream copy so this test stays about AAC. | 140 | // comes out with a stream copy so this test stays about AAC. |
| 186 | let adts = tmp.join(format!("{name}.aac")); | 141 | let adts = tmp.join(format!("{name}.aac")); |
| 187 | - let out = Command::new("ffmpeg") | 142 | + let out = ec_testkit::ffmpeg() |
| 188 | .args(["-v", "error", "-y", "-i"]) | 143 | .args(["-v", "error", "-y", "-i"]) |
| 189 | .arg(&path) | 144 | .arg(&path) |
| 190 | .args(["-c:a", "copy", "-f", "adts"]) | 145 | .args(["-c:a", "copy", "-f", "adts"]) |
| @@ -211,22 +166,14 @@ fn mp4_fixtures_match_ffmpeg_per_channel() { | |||
| 211 | /// its bands before M/S and intensity stereo combine them. | 166 | /// its bands before M/S and intensity stereo combine them. |
| 212 | #[test] | 167 | #[test] |
| 213 | fn aac_coding_tools_match_ffmpeg_in_isolation() { | 168 | fn aac_coding_tools_match_ffmpeg_in_isolation() { |
| 214 | - if !have_ffmpeg() { | ||
| 215 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 216 | - return; | ||
| 217 | - } | ||
| 218 | - let dir = fixtures().join("audio"); | ||
| 219 | let tmp = std::env::temp_dir().join("ec-aac-tools-oracle"); | 169 | let tmp = std::env::temp_dir().join("ec-aac-tools-oracle"); |
| 220 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 170 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 221 | let mut checked = 0; | 171 | let mut checked = 0; |
| 222 | for tool in ["pns", "is", "ms", "tns", "all"] { | 172 | for tool in ["pns", "is", "ms", "tns", "all"] { |
| 223 | let name = format!("aac-tool-{tool}-mp4-stereo-48000.m4a"); | 173 | let name = format!("aac-tool-{tool}-mp4-stereo-48000.m4a"); |
| 224 | - let path = dir.join(&name); | 174 | + let path = ec_testkit::fixture(&format!("audio/{name}")); |
| 225 | - if !require_fixture(&path, "scripts/gen-fixtures.sh") { | ||
| 226 | - continue; | ||
| 227 | - } | ||
| 228 | let adts = tmp.join(format!("{name}.aac")); | 175 | let adts = tmp.join(format!("{name}.aac")); |
| 229 | - let out = Command::new("ffmpeg") | 176 | + let out = ec_testkit::ffmpeg() |
| 230 | .args(["-v", "error", "-y", "-i"]) | 177 | .args(["-v", "error", "-y", "-i"]) |
| 231 | .arg(&path) | 178 | .arg(&path) |
| 232 | .args(["-c:a", "copy", "-f", "adts"]) | 179 | .args(["-c:a", "copy", "-f", "adts"]) |
| @@ -258,17 +205,13 @@ fn aac_coding_tools_match_ffmpeg_in_isolation() { | |||
| 258 | /// wrong element order shows up as the wrong tone on the wrong channel. | 205 | /// wrong element order shows up as the wrong tone on the wrong channel. |
| 259 | #[test] | 206 | #[test] |
| 260 | fn five_one_comes_out_in_film_order() { | 207 | fn five_one_comes_out_in_film_order() { |
| 261 | - if !have_ffmpeg() { | ||
| 262 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 263 | - return; | ||
| 264 | - } | ||
| 265 | let tmp = std::env::temp_dir().join("ec-aac-order"); | 208 | let tmp = std::env::temp_dir().join("ec-aac-order"); |
| 266 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 209 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 267 | let src = tmp.join("order.aac"); | 210 | let src = tmp.join("order.aac"); |
| 268 | // The LFE tone stays low: the reference encoder band-limits that channel, | 211 | // The LFE tone stays low: the reference encoder band-limits that channel, |
| 269 | // and a 1.5 kHz tone would simply not survive the trip. | 212 | // and a 1.5 kHz tone would simply not survive the trip. |
| 270 | let tones = [300.0, 700.0, 1100.0, 60.0, 1900.0, 2300.0]; | 213 | let tones = [300.0, 700.0, 1100.0, 60.0, 1900.0, 2300.0]; |
| 271 | - let mut cmd = Command::new("ffmpeg"); | 214 | + let mut cmd = ec_testkit::ffmpeg(); |
| 272 | cmd.args(["-v", "error", "-y"]); | 215 | cmd.args(["-v", "error", "-y"]); |
| 273 | for f in tones { | 216 | for f in tones { |
| 274 | cmd.args([ | 217 | cmd.args([ |
| @@ -424,19 +367,11 @@ fn best_correlation(source: &[f32], decoded: &[f32]) -> f64 { | |||
| 424 | /// lossless fixtures at the same bitrates. | 367 | /// lossless fixtures at the same bitrates. |
| 425 | #[test] | 368 | #[test] |
| 426 | fn encoder_beats_the_incumbent_bar() { | 369 | fn encoder_beats_the_incumbent_bar() { |
| 427 | - if !have_ffmpeg() { | ||
| 428 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 429 | - return; | ||
| 430 | - } | ||
| 431 | - let dir = fixtures().join("audio"); | ||
| 432 | let tmp = std::env::temp_dir().join("ec-aac-bar"); | 370 | let tmp = std::env::temp_dir().join("ec-aac-bar"); |
| 433 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 371 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 434 | let mut checked = 0; | 372 | let mut checked = 0; |
| 435 | for (name, channels, kbps, bar) in INCUMBENT_BAR { | 373 | for (name, channels, kbps, bar) in INCUMBENT_BAR { |
| 436 | - let src = dir.join(format!("flac-{name}-48000.flac")); | 374 | + let src = ec_testkit::fixture(&format!("audio/flac-{name}-48000.flac")); |
| 437 | - if !require_fixture(&src, "scripts/gen-fixtures.sh") { | ||
| 438 | - continue; | ||
| 439 | - } | ||
| 440 | let source = ffmpeg_decode(&src, *channels); | 375 | let source = ffmpeg_decode(&src, *channels); |
| 441 | let mut interleaved = Vec::with_capacity(source[0].len() * channels); | 376 | let mut interleaved = Vec::with_capacity(source[0].len() * channels); |
| 442 | for i in 0..source[0].len() { | 377 | for i in 0..source[0].len() { |
| @@ -493,20 +428,12 @@ const LAYOUT_BAR: &[(&str, usize, u32, f64, &str)] = &[ | |||
| 493 | /// ADTS rate within 5% of the target. | 428 | /// ADTS rate within 5% of the target. |
| 494 | #[test] | 429 | #[test] |
| 495 | fn encoder_meets_every_layout_bar() { | 430 | fn encoder_meets_every_layout_bar() { |
| 496 | - if !have_ffmpeg() { | ||
| 497 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 498 | - return; | ||
| 499 | - } | ||
| 500 | - let dir = fixtures().join("audio"); | ||
| 501 | let tmp = std::env::temp_dir().join("ec-aac-layout-bar"); | 431 | let tmp = std::env::temp_dir().join("ec-aac-layout-bar"); |
| 502 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 432 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 503 | let mut checked = 0; | 433 | let mut checked = 0; |
| 504 | let mut failed = Vec::new(); | 434 | let mut failed = Vec::new(); |
| 505 | for (name, channels, kbps, bar, incumbent) in LAYOUT_BAR { | 435 | for (name, channels, kbps, bar, incumbent) in LAYOUT_BAR { |
| 506 | - let src = dir.join(format!("flac-{name}-48000.flac")); | 436 | + let src = ec_testkit::fixture(&format!("audio/flac-{name}-48000.flac")); |
| 507 | - if !require_fixture(&src, "scripts/gen-aac-layouts.sh OUTDIR (3.0, 4.0, 5.0, 7.1)") { | ||
| 508 | - continue; | ||
| 509 | - } | ||
| 510 | let source = ffmpeg_decode(&src, *channels); | 437 | let source = ffmpeg_decode(&src, *channels); |
| 511 | let mut interleaved = Vec::with_capacity(source[0].len() * channels); | 438 | let mut interleaved = Vec::with_capacity(source[0].len() * channels); |
| 512 | for i in 0..source[0].len() { | 439 | for i in 0..source[0].len() { |
| @@ -622,7 +549,7 @@ fn noisy_clip(name: &str, dir: &Path) -> PathBuf { | |||
| 622 | .iter() | 549 | .iter() |
| 623 | .find(|(n, _, _)| *n == name) | 550 | .find(|(n, _, _)| *n == name) |
| 624 | .expect("a NOISY_CLIPS entry"); | 551 | .expect("a NOISY_CLIPS entry"); |
| 625 | - let mut cmd = Command::new("ffmpeg"); | 552 | + let mut cmd = ec_testkit::ffmpeg(); |
| 626 | cmd.args(["-v", "error", "-y"]); | 553 | cmd.args(["-v", "error", "-y"]); |
| 627 | for input in *inputs { | 554 | for input in *inputs { |
| 628 | cmd.args(["-f", "lavfi", "-i", input]); | 555 | cmd.args(["-f", "lavfi", "-i", input]); |
| @@ -642,10 +569,6 @@ fn noisy_clip(name: &str, dir: &Path) -> PathBuf { | |||
| 642 | /// correlation against the incumbent's bar, and the ADTS rate within 5% of the target. | 569 | /// correlation against the incumbent's bar, and the ADTS rate within 5% of the target. |
| 643 | #[test] | 570 | #[test] |
| 644 | fn encoder_meets_noisy_bar() { | 571 | fn encoder_meets_noisy_bar() { |
| 645 | - if !have_ffmpeg() { | ||
| 646 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 647 | - return; | ||
| 648 | - } | ||
| 649 | let tmp = std::env::temp_dir().join("ec-aac-noisy-bar"); | 572 | let tmp = std::env::temp_dir().join("ec-aac-noisy-bar"); |
| 650 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 573 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 651 | let mut failed = Vec::new(); | 574 | let mut failed = Vec::new(); |
| @@ -706,10 +629,6 @@ fn tone_pcm(rate: u32, channels: usize, secs: f64) -> Vec<f32> { | |||
| 706 | 629 | ||
| 707 | #[test] | 630 | #[test] |
| 708 | fn encoder_output_decodes_in_ffmpeg_without_warnings() { | 631 | fn encoder_output_decodes_in_ffmpeg_without_warnings() { |
| 709 | - if !have_ffmpeg() { | ||
| 710 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 711 | - return; | ||
| 712 | - } | ||
| 713 | let tmp = std::env::temp_dir().join("ec-aac-enc"); | 632 | let tmp = std::env::temp_dir().join("ec-aac-enc"); |
| 714 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 633 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 715 | for (channels, kbps) in [(1u16, 96u32), (2, 128), (2, 192), (6, 384)] { | 634 | for (channels, kbps) in [(1u16, 96u32), (2, 128), (2, 192), (6, 384)] { |
| @@ -719,7 +638,7 @@ fn encoder_output_decodes_in_ffmpeg_without_warnings() { | |||
| 719 | assert!(!adts.is_empty(), "{channels}ch encode produced nothing"); | 638 | assert!(!adts.is_empty(), "{channels}ch encode produced nothing"); |
| 720 | let path = tmp.join(format!("enc-{channels}ch-{kbps}k.aac")); | 639 | let path = tmp.join(format!("enc-{channels}ch-{kbps}k.aac")); |
| 721 | std::fs::write(&path, &adts).expect("write"); | 640 | std::fs::write(&path, &adts).expect("write"); |
| 722 | - let out = Command::new("ffmpeg") | 641 | + let out = ec_testkit::ffmpeg() |
| 723 | .args(["-v", "warning", "-i"]) | 642 | .args(["-v", "warning", "-i"]) |
| 724 | .arg(&path) | 643 | .arg(&path) |
| 725 | .args(["-f", "null", "-"]) | 644 | .args(["-f", "null", "-"]) |
| @@ -816,10 +735,6 @@ fn band_tables_span_the_window() { | |||
| 816 | /// means in practice. | 735 | /// means in practice. |
| 817 | #[test] | 736 | #[test] |
| 818 | fn asc_matches_the_one_ffmpeg_writes() { | 737 | fn asc_matches_the_one_ffmpeg_writes() { |
| 819 | - if !have_ffmpeg() { | ||
| 820 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 821 | - return; | ||
| 822 | - } | ||
| 823 | let tmp = std::env::temp_dir().join("ec-aac-esds"); | 738 | let tmp = std::env::temp_dir().join("ec-aac-esds"); |
| 824 | std::fs::create_dir_all(&tmp).expect("temp dir"); | 739 | std::fs::create_dir_all(&tmp).expect("temp dir"); |
| 825 | for (channels, rate) in [(1u16, 48_000u32), (2, 48_000), (2, 44_100), (6, 48_000)] { | 740 | for (channels, rate) in [(1u16, 48_000u32), (2, 48_000), (2, 44_100), (6, 48_000)] { |
| @@ -828,7 +743,7 @@ fn asc_matches_the_one_ffmpeg_writes() { | |||
| 828 | let src = tmp.join(format!("asc-{channels}-{rate}.aac")); | 743 | let src = tmp.join(format!("asc-{channels}-{rate}.aac")); |
| 829 | std::fs::write(&src, &adts).expect("write"); | 744 | std::fs::write(&src, &adts).expect("write"); |
| 830 | let mp4 = tmp.join(format!("asc-{channels}-{rate}.mp4")); | 745 | let mp4 = tmp.join(format!("asc-{channels}-{rate}.mp4")); |
| 831 | - let out = Command::new("ffmpeg") | 746 | + let out = ec_testkit::ffmpeg() |
| 832 | .args(["-v", "error", "-y", "-i"]) | 747 | .args(["-v", "error", "-y", "-i"]) |
| 833 | .arg(&src) | 748 | .arg(&src) |
| 834 | .args(["-c:a", "copy"]) | 749 | .args(["-c:a", "copy"]) |
| @@ -903,146 +818,10 @@ fn esds_asc(mp4: &[u8]) -> Option<Vec<u8>> { | |||
| 903 | None | 818 | None |
| 904 | } | 819 | } |
| 905 | 820 | ||
| 906 | -/// AAC tracks from the machine's own library, not just generated fixtures: the | ||
| 907 | -/// elementary stream is copied out to ADTS and decoded both ways. | ||
| 908 | -// lane-h264reallib: same shape as the ec-h264 `real_library_streams_match_ffmpeg` | ||
| 909 | -// fix, same reason. The manifest is generated by `scripts/scan-real-library.sh` | ||
| 910 | -// from `~/Videos ~/Downloads ~/Music` and is gitignored because it is | ||
| 911 | -// machine-local. The guard below makes a host with NO manifest print green | ||
| 912 | -// (nothing was checked), and a host that ran the scan but has since moved or | ||
| 913 | -// deleted files falls through to `checked >= 3` and goes red for a reason that | ||
| 914 | -// has nothing to do with the decoder. An ignore is visible in `--list` and | ||
| 915 | -// cannot go green silently, which an env gate would. | ||
| 916 | -// Run on the workstation: cargo test -p ec-aac --test oracle real_library_tracks_match_ffmpeg -- --ignored | ||
| 917 | -#[ignore = "sweeps the PERSONAL media library (~/Videos, ~/Downloads, ~/Music) through the gitignored fixtures/real-library-manifest.tsv and asserts >= 3 tracks swept; a runner host has no such library, so it is either a silent green or a red for the wrong reason. Run it on the workstation with --ignored."] | ||
| 918 | -#[test] | ||
| 919 | -fn real_library_tracks_match_ffmpeg() { | ||
| 920 | - if !have_ffmpeg() { | ||
| 921 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 922 | - return; | ||
| 923 | - } | ||
| 924 | - let manifest = fixtures().join("real-library-manifest.tsv"); | ||
| 925 | - let Ok(text) = std::fs::read_to_string(&manifest) else { | ||
| 926 | - eprintln!("SKIP: no real-library manifest; run scripts/scan-real-library.sh"); | ||
| 927 | - return; | ||
| 928 | - }; | ||
| 929 | - let tmp = std::env::temp_dir().join("ec-aac-real"); | ||
| 930 | - std::fs::create_dir_all(&tmp).expect("temp dir"); | ||
| 931 | - let mut stereo = 0; | ||
| 932 | - let mut wide = 0; | ||
| 933 | - let mut checked = 0; | ||
| 934 | - for line in text.lines().skip(1) { | ||
| 935 | - if stereo >= 3 && wide >= 2 { | ||
| 936 | - break; | ||
| 937 | - } | ||
| 938 | - let path = line.split('\t').next().unwrap_or_default(); | ||
| 939 | - if path.is_empty() || !line.to_lowercase().contains("aac") { | ||
| 940 | - continue; | ||
| 941 | - } | ||
| 942 | - let file = Path::new(path); | ||
| 943 | - if !file.exists() { | ||
| 944 | - continue; | ||
| 945 | - } | ||
| 946 | - let Some((index, channels, profile)) = aac_stream(file) else { | ||
| 947 | - continue; | ||
| 948 | - }; | ||
| 949 | - // HE-AAC is reported, not decoded: see `sbr_is_reported_not_silently_upsampled`. | ||
| 950 | - if profile.contains("HE-AAC") { | ||
| 951 | - continue; | ||
| 952 | - } | ||
| 953 | - if channels <= 2 { | ||
| 954 | - if stereo >= 3 { | ||
| 955 | - continue; | ||
| 956 | - } | ||
| 957 | - stereo += 1; | ||
| 958 | - } else { | ||
| 959 | - if wide >= 2 { | ||
| 960 | - continue; | ||
| 961 | - } | ||
| 962 | - wide += 1; | ||
| 963 | - } | ||
| 964 | - let adts = tmp.join(format!("real-{checked}.aac")); | ||
| 965 | - let out = Command::new("ffmpeg") | ||
| 966 | - .args(["-v", "error", "-y", "-t", "20", "-i"]) | ||
| 967 | - .arg(file) | ||
| 968 | - .args(["-map", &format!("0:{index}"), "-c:a", "copy", "-f", "adts"]) | ||
| 969 | - .arg(&adts) | ||
| 970 | - .output() | ||
| 971 | - .expect("ffmpeg runs"); | ||
| 972 | - if !out.status.success() { | ||
| 973 | - eprintln!("SKIP {path}: stream copy failed"); | ||
| 974 | - continue; | ||
| 975 | - } | ||
| 976 | - let corr = compare(&adts); | ||
| 977 | - let worst = corr.iter().copied().fold(f64::MAX, f64::min); | ||
| 978 | - println!( | ||
| 979 | - "real {channels}ch {profile} worst {worst:.6} -- {}", | ||
| 980 | - file.file_name().unwrap_or_default().to_string_lossy() | ||
| 981 | - ); | ||
| 982 | - for (ch, c) in corr.iter().enumerate() { | ||
| 983 | - assert!( | ||
| 984 | - *c >= 0.999, | ||
| 985 | - "channel {ch} correlation {c:.6} < 0.999 for {path}" | ||
| 986 | - ); | ||
| 987 | - } | ||
| 988 | - checked += 1; | ||
| 989 | - } | ||
| 990 | - assert!( | ||
| 991 | - checked >= 3, | ||
| 992 | - "wanted at least three library tracks, swept {checked}" | ||
| 993 | - ); | ||
| 994 | - assert!(wide >= 1, "no multichannel AAC track was swept"); | ||
| 995 | -} | ||
| 996 | - | ||
| 997 | -/// The first AAC audio stream of a file: `(stream index, channels, profile)`. | ||
| 998 | -fn aac_stream(path: &Path) -> Option<(usize, usize, String)> { | ||
| 999 | - let out = Command::new("ffprobe") | ||
| 1000 | - .args([ | ||
| 1001 | - "-v", | ||
| 1002 | - "error", | ||
| 1003 | - "-select_streams", | ||
| 1004 | - "a", | ||
| 1005 | - "-show_entries", | ||
| 1006 | - "stream=index,codec_name,channels,profile", | ||
| 1007 | - "-of", | ||
| 1008 | - "default=noprint_wrappers=1", | ||
| 1009 | - ]) | ||
| 1010 | - .arg(path) | ||
| 1011 | - .output() | ||
| 1012 | - .ok()?; | ||
| 1013 | - let text = String::from_utf8_lossy(&out.stdout); | ||
| 1014 | - let (mut index, mut channels, mut codec, mut profile) = | ||
| 1015 | - (None, None, String::new(), String::new()); | ||
| 1016 | - for line in text.lines() { | ||
| 1017 | - let (key, value) = line.split_once('=')?; | ||
| 1018 | - match key { | ||
| 1019 | - "index" => { | ||
| 1020 | - if codec == "aac" { | ||
| 1021 | - return Some((index?, channels?, profile)); | ||
| 1022 | - } | ||
| 1023 | - index = value.parse().ok(); | ||
| 1024 | - codec.clear(); | ||
| 1025 | - profile.clear(); | ||
| 1026 | - } | ||
| 1027 | - "codec_name" => codec = value.to_string(), | ||
| 1028 | - "channels" => channels = value.parse().ok(), | ||
| 1029 | - "profile" => profile = value.to_string(), | ||
| 1030 | - _ => {} | ||
| 1031 | - } | ||
| 1032 | - } | ||
| 1033 | - if codec == "aac" { | ||
| 1034 | - return Some((index?, channels?, profile)); | ||
| 1035 | - } | ||
| 1036 | - None | ||
| 1037 | -} | ||
| 1038 | - | ||
| 1039 | /// Decode speed on 5.1, the shape a film soundtrack has. | 821 | /// Decode speed on 5.1, the shape a film soundtrack has. |
| 1040 | #[test] | 822 | #[test] |
| 1041 | fn five_one_decodes_faster_than_realtime() { | 823 | fn five_one_decodes_faster_than_realtime() { |
| 1042 | - let path = fixtures().join("audio/aac-adts-5.1-48000.aac"); | 824 | + let path = ec_testkit::fixture("audio/aac-adts-5.1-48000.aac"); |
| 1043 | - if !require_fixture(&path, "scripts/gen-fixtures.sh") { | ||
| 1044 | - return; | ||
| 1045 | - } | ||
| 1046 | let data = std::fs::read(&path).expect("fixture readable"); | 825 | let data = std::fs::read(&path).expect("fixture readable"); |
| 1047 | let rounds = 8; | 826 | let rounds = 8; |
| 1048 | let start = std::time::Instant::now(); | 827 | let start = std::time::Instant::now(); |
| @@ -1078,170 +857,3 @@ fn five_one_decodes_faster_than_realtime() { | |||
| 1078 | ); | 857 | ); |
| 1079 | } | 858 | } |
| 1080 | } | 859 | } |
| 1081 | - | ||
| 1082 | -/// The one HE-AAC track in this machine's library, decoded to its AAC-LC core. | ||
| 1083 | -/// The claim under test is the honest one: the core comes out, at the core | ||
| 1084 | -/// rate, matching what a reference decoder makes of the same core band. | ||
| 1085 | -#[test] | ||
| 1086 | -fn he_aac_library_track_decodes_to_its_core() { | ||
| 1087 | - if !have_ffmpeg() { | ||
| 1088 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 1089 | - return; | ||
| 1090 | - } | ||
| 1091 | - let manifest = fixtures().join("real-library-manifest.tsv"); | ||
| 1092 | - let Ok(text) = std::fs::read_to_string(&manifest) else { | ||
| 1093 | - eprintln!("SKIP: no real-library manifest"); | ||
| 1094 | - return; | ||
| 1095 | - }; | ||
| 1096 | - let tmp = std::env::temp_dir().join("ec-aac-he"); | ||
| 1097 | - std::fs::create_dir_all(&tmp).expect("temp dir"); | ||
| 1098 | - for line in text.lines().skip(1) { | ||
| 1099 | - let path = line.split('\t').next().unwrap_or_default(); | ||
| 1100 | - let file = Path::new(path); | ||
| 1101 | - if path.is_empty() || !file.exists() { | ||
| 1102 | - continue; | ||
| 1103 | - } | ||
| 1104 | - let Some((index, _, profile)) = aac_stream_matching(file, "HE-AAC") else { | ||
| 1105 | - continue; | ||
| 1106 | - }; | ||
| 1107 | - let _ = profile; | ||
| 1108 | - let adts = tmp.join("he.aac"); | ||
| 1109 | - let out = Command::new("ffmpeg") | ||
| 1110 | - .args(["-v", "error", "-y", "-t", "10", "-i"]) | ||
| 1111 | - .arg(file) | ||
| 1112 | - .args(["-map", &format!("0:{index}"), "-c:a", "copy", "-f", "adts"]) | ||
| 1113 | - .arg(&adts) | ||
| 1114 | - .output() | ||
| 1115 | - .expect("ffmpeg runs"); | ||
| 1116 | - if !out.status.success() { | ||
| 1117 | - continue; | ||
| 1118 | - } | ||
| 1119 | - let (ours, rate) = our_decode(&adts); | ||
| 1120 | - assert!(!ours.is_empty(), "the HE-AAC core decoded to nothing"); | ||
| 1121 | - // The reference decode carries SBR, so it runs at twice this rate; | ||
| 1122 | - // resampling it down to the core rate low-passes exactly the band the | ||
| 1123 | - // core carries, which is the part we are claiming to reproduce. | ||
| 1124 | - let core = tmp.join("he-core.f32"); | ||
| 1125 | - let out = Command::new("ffmpeg") | ||
| 1126 | - .args(["-v", "error", "-y", "-i"]) | ||
| 1127 | - .arg(&adts) | ||
| 1128 | - .args(["-ar", &rate.to_string(), "-f", "f32le"]) | ||
| 1129 | - .arg(&core) | ||
| 1130 | - .output() | ||
| 1131 | - .expect("ffmpeg runs"); | ||
| 1132 | - assert!( | ||
| 1133 | - out.status.success(), | ||
| 1134 | - "reference decode of the HE-AAC track failed" | ||
| 1135 | - ); | ||
| 1136 | - let theirs = deinterleave( | ||
| 1137 | - &bytes_to_f32(&std::fs::read(&core).expect("read")), | ||
| 1138 | - ours.len(), | ||
| 1139 | - ); | ||
| 1140 | - // Sample-by-sample comparison would need the reference resampler's own | ||
| 1141 | - // delay; the claim here is about *content*, so it is checked on the | ||
| 1142 | - // long-term band energies, which no delay moves. | ||
| 1143 | - let corr: Vec<f64> = ours | ||
| 1144 | - .iter() | ||
| 1145 | - .zip(&theirs) | ||
| 1146 | - .map(|(a, b)| pearson(&band_energies(a, rate), &band_energies(b, rate))) | ||
| 1147 | - .collect(); | ||
| 1148 | - let worst = corr.iter().copied().fold(f64::MAX, f64::min); | ||
| 1149 | - println!("HE-AAC core at {rate} Hz: band-energy match, worst channel {worst:.4} {corr:?}"); | ||
| 1150 | - assert!( | ||
| 1151 | - worst >= 0.95, | ||
| 1152 | - "the AAC-LC core of an HE-AAC track should carry the reference's \ | ||
| 1153 | - core band; worst channel {worst:.4}" | ||
| 1154 | - ); | ||
| 1155 | - return; | ||
| 1156 | - } | ||
| 1157 | - eprintln!("SKIP: no HE-AAC track in the library manifest"); | ||
| 1158 | -} | ||
| 1159 | - | ||
| 1160 | -/// Pearson correlation with no minimum length: for short feature vectors. | ||
| 1161 | -fn pearson(a: &[f32], b: &[f32]) -> f64 { | ||
| 1162 | - let n = a.len().min(b.len()); | ||
| 1163 | - let ma = a[..n].iter().map(|v| f64::from(*v)).sum::<f64>() / n as f64; | ||
| 1164 | - let mb = b[..n].iter().map(|v| f64::from(*v)).sum::<f64>() / n as f64; | ||
| 1165 | - let (mut num, mut da, mut db) = (0.0, 0.0, 0.0); | ||
| 1166 | - for i in 0..n { | ||
| 1167 | - let (x, y) = (f64::from(a[i]) - ma, f64::from(b[i]) - mb); | ||
| 1168 | - num += x * y; | ||
| 1169 | - da += x * x; | ||
| 1170 | - db += y * y; | ||
| 1171 | - } | ||
| 1172 | - if da == 0.0 || db == 0.0 { | ||
| 1173 | - return 1.0; | ||
| 1174 | - } | ||
| 1175 | - num / (da * db).sqrt() | ||
| 1176 | -} | ||
| 1177 | - | ||
| 1178 | -/// Long-term energy in 32 logarithmic bands: a spectral fingerprint that a | ||
| 1179 | -/// resampler's delay cannot shift. | ||
| 1180 | -fn band_energies(samples: &[f32], rate: u32) -> Vec<f32> { | ||
| 1181 | - let bands = 32usize; | ||
| 1182 | - let mut out = vec![0.0f64; bands]; | ||
| 1183 | - let n = 1024usize; | ||
| 1184 | - let mut blocks = 0usize; | ||
| 1185 | - for chunk in samples.chunks_exact(n).take(400) { | ||
| 1186 | - blocks += 1; | ||
| 1187 | - for (b, slot) in out.iter_mut().enumerate() { | ||
| 1188 | - // Geometric spacing from 100 Hz to the Nyquist limit. | ||
| 1189 | - let lo = 100.0 * (f64::from(rate) / 2.0 / 100.0).powf(b as f64 / bands as f64); | ||
| 1190 | - let hi = 100.0 * (f64::from(rate) / 2.0 / 100.0).powf((b + 1) as f64 / bands as f64); | ||
| 1191 | - let (mut re, mut im) = (0.0f64, 0.0f64); | ||
| 1192 | - let f = (lo * hi).sqrt(); | ||
| 1193 | - let w = 2.0 * std::f64::consts::PI * f / f64::from(rate); | ||
| 1194 | - for (i, &v) in chunk.iter().enumerate() { | ||
| 1195 | - re += f64::from(v) * (w * i as f64).cos(); | ||
| 1196 | - im += f64::from(v) * (w * i as f64).sin(); | ||
| 1197 | - } | ||
| 1198 | - *slot += (re * re + im * im).sqrt(); | ||
| 1199 | - } | ||
| 1200 | - } | ||
| 1201 | - out.iter() | ||
| 1202 | - .map(|v| ((v / blocks.max(1) as f64) + 1e-9).ln() as f32) | ||
| 1203 | - .collect() | ||
| 1204 | -} | ||
| 1205 | - | ||
| 1206 | -fn aac_stream_matching(path: &Path, want: &str) -> Option<(usize, usize, String)> { | ||
| 1207 | - let out = Command::new("ffprobe") | ||
| 1208 | - .args([ | ||
| 1209 | - "-v", | ||
| 1210 | - "error", | ||
| 1211 | - "-select_streams", | ||
| 1212 | - "a", | ||
| 1213 | - "-show_entries", | ||
| 1214 | - "stream=index,codec_name,channels,profile", | ||
| 1215 | - "-of", | ||
| 1216 | - "default=noprint_wrappers=1", | ||
| 1217 | - ]) | ||
| 1218 | - .arg(path) | ||
| 1219 | - .output() | ||
| 1220 | - .ok()?; | ||
| 1221 | - let text = String::from_utf8_lossy(&out.stdout); | ||
| 1222 | - let mut index = None; | ||
| 1223 | - let mut channels = None; | ||
| 1224 | - let mut codec = String::new(); | ||
| 1225 | - let mut profile = String::new(); | ||
| 1226 | - for line in text.lines() { | ||
| 1227 | - let (key, value) = line.split_once('=')?; | ||
| 1228 | - match key { | ||
| 1229 | - "index" => { | ||
| 1230 | - if codec == "aac" && profile.contains(want) { | ||
| 1231 | - return Some((index?, channels?, profile)); | ||
| 1232 | - } | ||
| 1233 | - index = value.parse().ok(); | ||
| 1234 | - codec.clear(); | ||
| 1235 | - profile.clear(); | ||
| 1236 | - } | ||
| 1237 | - "codec_name" => codec = value.to_string(), | ||
| 1238 | - "channels" => channels = value.parse().ok(), | ||
| 1239 | - "profile" => profile = value.to_string(), | ||
| 1240 | - _ => {} | ||
| 1241 | - } | ||
| 1242 | - } | ||
| 1243 | - if codec == "aac" && profile.contains(want) { | ||
| 1244 | - return Some((index?, channels?, profile)); | ||
| 1245 | - } | ||
| 1246 | - None | ||
| 1247 | -} | ||
crates/ec-aac/tests/sbr_real_library/chunk_a.rsmodified+189 -345
| @@ -25,15 +25,8 @@ use super::*; | |||
| 25 | #[test] | 25 | #[test] |
| 26 | pub(super) fn core_only_matches_reference() { | 26 | pub(super) fn core_only_matches_reference() { |
| 27 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 27 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 28 | - if !have_ffmpeg() { | ||
| 29 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 30 | - return; | ||
| 31 | - } | ||
| 32 | for c in &candidates() { | 28 | for c in &candidates() { |
| 33 | - let Some((ours, core_rate)) = our_decode_core_only(&c.path, c.aac_stream) else { | 29 | + let (ours, core_rate) = our_decode_core_only(&c.path, c.aac_stream).expect("core decode"); |
| 34 | - eprintln!("SKIP {}: could not core-decode", c.path.display()); | ||
| 35 | - continue; | ||
| 36 | - }; | ||
| 37 | let theirs = ffmpeg_decode_at_rate(&c.path, c.ffmpeg_stream, ours.len(), core_rate); | 30 | let theirs = ffmpeg_decode_at_rate(&c.path, c.ffmpeg_stream, ours.len(), core_rate); |
| 38 | println!( | 31 | println!( |
| 39 | "{} core-only ({} ch, {} Hz):", | 32 | "{} core-only ({} ch, {} Hz):", |
| @@ -101,10 +94,6 @@ pub(super) fn dump_sideinfo_kx() { | |||
| 101 | #[test] | 94 | #[test] |
| 102 | pub(super) fn wide_lag_search_full_chain() { | 95 | pub(super) fn wide_lag_search_full_chain() { |
| 103 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 96 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 104 | - if !have_ffmpeg() { | ||
| 105 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 106 | - return; | ||
| 107 | - } | ||
| 108 | for c in &candidates() { | 97 | for c in &candidates() { |
| 109 | let Some((ours, sbr, rate)) = our_decode(&c.path, c.aac_stream) else { | 98 | let Some((ours, sbr, rate)) = our_decode(&c.path, c.aac_stream) else { |
| 110 | continue; | 99 | continue; |
| @@ -227,42 +216,15 @@ pub(super) fn full_chain_low_band_matches_own_core() { | |||
| 227 | } | 216 | } |
| 228 | } | 217 | } |
| 229 | 218 | ||
| 230 | -/// Round-52: a controlled fixture matrix -- unlike reeln/FMJ (one real | 219 | +/// SBR rows over the open FATE HE-AAC streams (`fate_aac`), each decoded |
| 231 | -/// file each, whose sample rate, bitrate and content all differ at once), | 220 | +/// through its container and compared with ffmpeg, with the sideinfo and |
| 232 | -/// every row here decodes the SAME synthesized source (three summed sine | 221 | +/// instrumentation printed per row. Instrumentation only, not a regression gate. |
| 233 | -/// sweeps 100 Hz-18 kHz + seeded pink noise, per-channel phase offset), | ||
| 234 | -/// varying only sample rate (44100/48000) and bitrate (32k/48k/64k/96k, | ||
| 235 | -/// which sweeps the SBR crossover `kx`/`k2`), so a break tied to a rate | ||
| 236 | -/// FAMILY or to `kx` GEOMETRY shows as a pattern across the table instead | ||
| 237 | -/// of being confounded with one file's own content. `aac_low` control rows | ||
| 238 | -/// (no SBR at all) prove the harness itself -- container extraction, | ||
| 239 | -/// decode, correlation -- is sound before the HE-AAC rows next to them are | ||
| 240 | -/// trusted; those are the only asserted numbers here, everything else is | ||
| 241 | -/// instrumentation for the ledger, not a regression gate yet. | ||
| 242 | -/// | ||
| 243 | -/// Env-gated on `EC_AAC_HEAAC_FIXTURES` (defaults to the same | ||
| 244 | -/// `<repo>/.cache/heaac-fixtures` `scripts/aac-tables/make-heaac-fixtures.sh` | ||
| 245 | -/// writes to) -- skips loudly, generates nothing itself, when that | ||
| 246 | -/// directory is absent. | ||
| 247 | #[test] | 222 | #[test] |
| 248 | pub(super) fn synthetic_heaac_matrix() { | 223 | pub(super) fn synthetic_heaac_matrix() { |
| 249 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 224 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 250 | - if !have_ffmpeg() { | ||
| 251 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 252 | - return; | ||
| 253 | - } | ||
| 254 | - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 255 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 256 | - let dir = PathBuf::from(dir); | ||
| 257 | - if !require_fixture(&dir, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 258 | - return; | ||
| 259 | - } | ||
| 260 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); | 225 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); |
| 261 | println!( | 226 | println!( |
| 262 | - "{:>5} {:>6} {:>4} {:>4} {:>4} {:>8} {:>8} {:>8} {:>6} {:>11} {:>8} {:>10} {:>8} {:>9} {:>9}", | 227 | + "{:>4} {:>4} {:>8} {:>8} {:>8} {:>6} {:>11} {:>8} {:>10} {:>8} {:>9} {:>9}", |
| 263 | - "rate", | ||
| 264 | - "kbps", | ||
| 265 | - "prof", | ||
| 266 | "kx", | 228 | "kx", |
| 267 | "k2", | 229 | "k2", |
| 268 | "full", | 230 | "full", |
| @@ -281,295 +243,195 @@ pub(super) fn synthetic_heaac_matrix() { | |||
| 281 | // samples at the doubled/full output rate) both land well inside it, | 243 | // samples at the doubled/full output rate) both land well inside it, |
| 282 | // not right at the edge the way the plain (LAG_MAX=4000) search did. | 244 | // not right at the edge the way the plain (LAG_MAX=4000) search did. |
| 283 | const WIDE_LAG_MAX: i64 = 20_000; | 245 | const WIDE_LAG_MAX: i64 = 20_000; |
| 284 | - // Floor: the matrix is 2 rates x 4 bitrates x 2 profiles. Without a count | 246 | + for path in fate_aac() { |
| 285 | - // the whole test is green having probed nothing, which is the same | 247 | + let before = ec_aac::sbr_sideinfo_log().len(); |
| 286 | - // false-green this file's `require_fixture` exists to kill. | 248 | + let (ours, _sbr, our_rate) = our_decode(&path, 0).expect("decodes"); |
| 287 | - let mut probed = 0usize; | 249 | + let rows = ec_aac::sbr_sideinfo_log(); |
| 288 | - for rate in [48_000u32, 44_100] { | 250 | + let (kx, k2) = rows[before..] |
| 289 | - for br in ["32k", "48k", "64k", "96k"] { | 251 | + .iter() |
| 290 | - // LC first: its winning lag is the pure container/decoder | 252 | + .find(|r| r.ch == 0) |
| 291 | - // priming delay with no SBR chain involved, and is reused below | 253 | + .map(|r| (r.kx, r.k2)) |
| 292 | - // as the anchor for the HE row's own delay-candidate probe. | 254 | + .unwrap_or((-1, -1)); |
| 293 | - let mut lc_lag: Option<i64> = None; | 255 | + let theirs = ffmpeg_decode(&path, 0, ours.len()); |
| 294 | - for (profile, prefix) in [("LC", "lc"), ("HE", "heaac")] { | 256 | + let o = &ours[0]; |
| 295 | - let path = dir.join(format!("{prefix}_{rate}_{br}.m4a")); | 257 | + let t = &theirs[0]; |
| 296 | - if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { | 258 | + const TOPK: usize = 5; |
| 297 | - continue; | 259 | + let (mut lag, mut full, edge) = robust_lag_topk(o, t, WIDE_LAG_MAX, our_rate, TOPK); |
| 298 | - } | 260 | + assert!( |
| 299 | - probed += 1; | 261 | + !edge, |
| 300 | - let before = ec_aac::sbr_sideinfo_log().len(); | 262 | + "{}: HE row's refined winning lag {lag} sits at the \ |
| 301 | - let Some((ours, _sbr, our_rate)) = our_decode(&path, 0) else { | 263 | + +/-{WIDE_LAG_MAX} search's own edge", |
| 302 | - eprintln!("SKIP {}: could not decode", path.display()); | 264 | + path.display() |
| 303 | - continue; | 265 | + ); |
| 304 | - }; | 266 | + // HE rows: a per-channel free lag search on periodic/tonal |
| 305 | - let rows = ec_aac::sbr_sideinfo_log(); | 267 | + // content is unreliable (coupled_cpe_channel_swap_probe |
| 306 | - let (kx, k2) = rows[before..] | 268 | + // proved this file's ref L vs ref R itself mis-searches -- |
| 307 | - .iter() | 269 | + // lag=-24 corr=0.213 vs the fixed lag=0 corr=0.873 -- and |
| 308 | - .find(|r| r.ch == 0) | 270 | + // the same coarse search can land two channels of the SAME |
| 309 | - .map(|r| (r.kx, r.k2)) | 271 | + // stream on DIFFERENT, individually-wrong lags, faking a |
| 310 | - .unwrap_or((-1, -1)); | 272 | + // channel swap that a fixed-lag check rules out). Derive |
| 311 | - let theirs = ffmpeg_decode(&path, 0, ours.len()); | 273 | + // ONE lag per stream from the summed (mono) signal instead, |
| 312 | - let o = &ours[0]; | 274 | + // and reuse it for both channels -- more robust than |
| 313 | - let t = &theirs[0]; | 275 | + // trusting a single, possibly-periodic channel's own search |
| 314 | - const TOPK: usize = 5; | 276 | + // -- via the same top-K/refine-on-first-10s robust method. |
| 315 | - let (mut lag, mut full, edge) = robust_lag_topk(o, t, WIDE_LAG_MAX, our_rate, TOPK); | 277 | + if ours.len() >= 2 && theirs.len() >= 2 { |
| 316 | - assert!( | 278 | + let mono_o: Vec<f32> = |
| 317 | - !edge, | 279 | + ours[0].iter().zip(&ours[1]).map(|(a, b)| a + b).collect(); |
| 318 | - "{}: {profile} row's refined winning lag {lag} sits at the \ | 280 | + let mono_t: Vec<f32> = theirs[0] |
| 319 | - +/-{WIDE_LAG_MAX} search's own edge", | 281 | + .iter() |
| 320 | - path.display() | 282 | + .zip(&theirs[1]) |
| 321 | - ); | 283 | + .map(|(a, b)| a + b) |
| 322 | - if profile == "LC" { | 284 | + .collect(); |
| 323 | - lc_lag = Some(lag); | 285 | + let (mono_lag, _, mono_edge) = |
| 324 | - } | 286 | + robust_lag_topk(&mono_o, &mono_t, WIDE_LAG_MAX, our_rate, TOPK); |
| 325 | - // HE rows: a per-channel free lag search on periodic/tonal | 287 | + assert!( |
| 326 | - // content is unreliable (coupled_cpe_channel_swap_probe | 288 | + !mono_edge, |
| 327 | - // proved this file's ref L vs ref R itself mis-searches -- | 289 | + "{}: HE row's mono-derived refined lag {mono_lag} sits at the \ |
| 328 | - // lag=-24 corr=0.213 vs the fixed lag=0 corr=0.873 -- and | 290 | + +/-{WIDE_LAG_MAX} search's own edge", |
| 329 | - // the same coarse search can land two channels of the SAME | 291 | + path.display() |
| 330 | - // stream on DIFFERENT, individually-wrong lags, faking a | 292 | + ); |
| 331 | - // channel swap that a fixed-lag check rules out). Derive | 293 | + lag = mono_lag; |
| 332 | - // ONE lag per stream from the summed (mono) signal instead, | 294 | + full = correlation_at_lag(o, t, lag); |
| 333 | - // and reuse it for both channels -- more robust than | 295 | + } |
| 334 | - // trusting a single, possibly-periodic channel's own search | 296 | + // Crossover in Hz from the actual parsed kx (band width |
| 335 | - // -- via the same top-K/refine-on-first-10s robust method. | 297 | + // rate/128, same domain `sbr_chain.rs`'s own doc comment |
| 336 | - if profile == "HE" && ours.len() >= 2 && theirs.len() >= 2 { | 298 | + // gives `kx`/`k2` in) when SBR engaged; a fixed quarter-Nyquist |
| 337 | - let mono_o: Vec<f32> = | 299 | + // split for the LC controls, which carry no kx at all. |
| 338 | - ours[0].iter().zip(&ours[1]).map(|(a, b)| a + b).collect(); | 300 | + let crossover_hz = if kx > 0 { |
| 339 | - let mono_t: Vec<f32> = theirs[0] | 301 | + f64::from(our_rate) * (kx as f64) / 128.0 |
| 340 | - .iter() | 302 | + } else { |
| 341 | - .zip(&theirs[1]) | 303 | + f64::from(our_rate) * 0.25 |
| 342 | - .map(|(a, b)| a + b) | 304 | + }; |
| 343 | - .collect(); | 305 | + // Same single robust `lag` the full/above bands use, not an |
| 344 | - let (mono_lag, _, mono_edge) = | 306 | + // independent search: a narrowband low-passed signal's |
| 345 | - robust_lag_topk(&mono_o, &mono_t, WIDE_LAG_MAX, our_rate, TOPK); | 307 | + // correlation surface is broad and flat across nearby lags, |
| 346 | - assert!( | 308 | + // which used to let an independent search here silently |
| 347 | - !mono_edge, | 309 | + // report a different (and unvalidated) alignment than the |
| 348 | - "{}: HE row's mono-derived refined lag {mono_lag} sits at the \ | 310 | + // one everything else in the row is anchored at. |
| 349 | - +/-{WIDE_LAG_MAX} search's own edge", | 311 | + let below = correlation_at_lag( |
| 350 | - path.display() | 312 | + &lowpass(o, our_rate, crossover_hz), |
| 351 | - ); | 313 | + &lowpass(t, our_rate, crossover_hz), |
| 352 | - lag = mono_lag; | 314 | + lag, |
| 353 | - full = correlation_at_lag(o, t, lag); | 315 | + ); |
| 354 | - } | 316 | + // `above` re-slices at the FULL-band winning `lag` before |
| 355 | - // Crossover in Hz from the actual parsed kx (band width | 317 | + // splitting, same convention `sbr_real_library_matches_reference` |
| 356 | - // rate/128, same domain `sbr_chain.rs`'s own doc comment | 318 | + // uses -- round-52's first cut of this row measured `o[..n]` |
| 357 | - // gives `kx`/`k2` in) when SBR engaged; a fixed quarter-Nyquist | 319 | + // against `t[..n]` with no lag offset at all, which is only |
| 358 | - // split for the LC controls, which carry no kx at all. | 320 | + // valid by accident at lag 0 and was silently wrong for |
| 359 | - let crossover_hz = if kx > 0 { | 321 | + // every other winning lag in that table. |
| 360 | - f64::from(our_rate) * (kx as f64) / 128.0 | 322 | + let (oa, ob) = if lag >= 0 { |
| 361 | - } else { | 323 | + (0usize, lag as usize) |
| 362 | - f64::from(our_rate) * 0.25 | 324 | + } else { |
| 363 | - }; | 325 | + ((-lag) as usize, 0usize) |
| 364 | - // Same single robust `lag` the full/above bands use, not an | 326 | + }; |
| 365 | - // independent search: a narrowband low-passed signal's | 327 | + let n = WINDOW |
| 366 | - // correlation surface is broad and flat across nearby lags, | 328 | + .min(o.len().saturating_sub(oa)) |
| 367 | - // which used to let an independent search here silently | 329 | + .min(t.len().saturating_sub(ob)); |
| 368 | - // report a different (and unvalidated) alignment than the | 330 | + let above = if n >= 1024 { |
| 369 | - // one everything else in the row is anchored at. | 331 | + correlation( |
| 370 | - let below = correlation_at_lag( | 332 | + &highpass(&o[oa..oa + n], our_rate, crossover_hz), |
| 371 | - &lowpass(o, our_rate, crossover_hz), | 333 | + &highpass(&t[ob..ob + n], our_rate, crossover_hz), |
| 372 | - &lowpass(t, our_rate, crossover_hz), | 334 | + ) |
| 373 | - lag, | 335 | + } else { |
| 374 | - ); | 336 | + 0.0 |
| 375 | - // `above` re-slices at the FULL-band winning `lag` before | 337 | + }; |
| 376 | - // splitting, same convention `sbr_real_library_matches_reference` | 338 | + // Round-51's self-consistency probe (our full chain's low |
| 377 | - // uses -- round-52's first cut of this row measured `o[..n]` | 339 | + // band vs our own core-only decode), run per-row so a |
| 378 | - // against `t[..n]` with no lag offset at all, which is only | 340 | + // rate/kx-specific self-inconsistency shows in the same |
| 379 | - // valid by accident at lag 0 and was silently wrong for | 341 | + // table instead of needing a second pass. |
| 380 | - // every other winning lag in that table. | 342 | + // |
| 381 | - let (oa, ob) = if lag >= 0 { | 343 | + // Fixed (this round): the original convention naively |
| 382 | - (0usize, lag as usize) | 344 | + // nearest-neighbor UPSAMPLED the core 2x and compared it |
| 383 | - } else { | 345 | + // against the full-rate signal, low-passed at |
| 384 | - ((-lag) as usize, 0usize) | 346 | + // `core_rate*0.4` -- that stairstep-and-lowpass round trip |
| 385 | - }; | 347 | + // is lossy enough on its own to sink a genuinely-correct |
| 386 | - let n = WINDOW | 348 | + // pair's correlation (measured flat ~-0.12 here even on |
| 387 | - .min(o.len().saturating_sub(oa)) | 349 | + // rows whose `full`/`below` columns read 0.999+ against the |
| 388 | - .min(t.len().saturating_sub(ob)); | 350 | + // real reference). `core_only_matches_reference` already |
| 389 | - let above = if n >= 1024 { | 351 | + // proved a clean pattern for this exact comparison: stay in |
| 390 | - correlation( | 352 | + // the CORE's own native rate (DECIMATE the full/reference |
| 391 | - &highpass(&o[oa..oa + n], our_rate, crossover_hz), | 353 | + // signal down instead of upsampling the core up) and use a |
| 392 | - &highpass(&t[ob..ob + n], our_rate, crossover_hz), | 354 | + // wide lag search there. `decimate` below is a lowpass |
| 355 | + // (well under the core Nyquist) followed by a plain | ||
| 356 | + // every-other-sample drop -- the inverse of the old | ||
| 357 | + // `[s, s]` upsample, at the same information cost but | ||
| 358 | + // without its stairstep artifact. | ||
| 359 | + let decimate = |s: &[f32], from_rate: u32, to_rate: u32| -> Vec<f32> { | ||
| 360 | + let cutoff = f64::from(to_rate) * 0.45; | ||
| 361 | + lowpass(s, from_rate, cutoff) | ||
| 362 | + .iter() | ||
| 363 | + .step_by((from_rate / to_rate.max(1)).max(1) as usize) | ||
| 364 | + .copied() | ||
| 365 | + .collect() | ||
| 366 | + }; | ||
| 367 | + let core_lag_max = WIDE_LAG_MAX / 2; | ||
| 368 | + let ours_v_core = if kx > 0 { | ||
| 369 | + our_decode_core_only(&path, 0).map(|(core, core_rate)| { | ||
| 370 | + let full_at_core_rate = decimate(o, our_rate, core_rate); | ||
| 371 | + best_lag_correlation_wide(&full_at_core_rate, &core[0], core_lag_max) | ||
| 372 | + }) | ||
| 373 | + } else { | ||
| 374 | + None | ||
| 375 | + }; | ||
| 376 | + // Coordinator follow-up 2: splits "our core decode of THIS | ||
| 377 | + // fixture is wrong" (core_v_ref ~0) from "the SBR chain | ||
| 378 | + // scrambles a good core" (core_v_ref >= ~0.99 while `below`/ | ||
| 379 | + // `above` stays ~0/negative) -- OUR core-only decode, same | ||
| 380 | + // native-core-rate convention `ours_v_core` now uses, against | ||
| 381 | + // the REFERENCE decoder's own decode resampled to that same | ||
| 382 | + // core rate (`ffmpeg_decode_at_rate`, the same helper | ||
| 383 | + // `core_only_matches_reference` already trusts) -- wide lag | ||
| 384 | + // search since this is an independent alignment from | ||
| 385 | + // `full`/`below`'s (core-only carries no SBR delay). | ||
| 386 | + let (core_v_ref, core_rate_str) = if kx > 0 { | ||
| 387 | + match our_decode_core_only(&path, 0) { | ||
| 388 | + Some((core, core_rate)) => { | ||
| 389 | + let ref_at_core_rate = | ||
| 390 | + ffmpeg_decode_at_rate(&path, 0, core.len(), core_rate); | ||
| 391 | + ( | ||
| 392 | + Some(best_lag_correlation_wide( | ||
| 393 | + &core[0], | ||
| 394 | + &ref_at_core_rate[0], | ||
| 395 | + core_lag_max, | ||
| 396 | + )), | ||
| 397 | + core_rate.to_string(), | ||
| 393 | ) | 398 | ) |
| 394 | - } else { | ||
| 395 | - 0.0 | ||
| 396 | - }; | ||
| 397 | - // Round-51's self-consistency probe (our full chain's low | ||
| 398 | - // band vs our own core-only decode), run per-row so a | ||
| 399 | - // rate/kx-specific self-inconsistency shows in the same | ||
| 400 | - // table instead of needing a second pass. | ||
| 401 | - // | ||
| 402 | - // Fixed (this round): the original convention naively | ||
| 403 | - // nearest-neighbor UPSAMPLED the core 2x and compared it | ||
| 404 | - // against the full-rate signal, low-passed at | ||
| 405 | - // `core_rate*0.4` -- that stairstep-and-lowpass round trip | ||
| 406 | - // is lossy enough on its own to sink a genuinely-correct | ||
| 407 | - // pair's correlation (measured flat ~-0.12 here even on | ||
| 408 | - // rows whose `full`/`below` columns read 0.999+ against the | ||
| 409 | - // real reference). `core_only_matches_reference` already | ||
| 410 | - // proved a clean pattern for this exact comparison: stay in | ||
| 411 | - // the CORE's own native rate (DECIMATE the full/reference | ||
| 412 | - // signal down instead of upsampling the core up) and use a | ||
| 413 | - // wide lag search there. `decimate` below is a lowpass | ||
| 414 | - // (well under the core Nyquist) followed by a plain | ||
| 415 | - // every-other-sample drop -- the inverse of the old | ||
| 416 | - // `[s, s]` upsample, at the same information cost but | ||
| 417 | - // without its stairstep artifact. | ||
| 418 | - let decimate = |s: &[f32], from_rate: u32, to_rate: u32| -> Vec<f32> { | ||
| 419 | - let cutoff = f64::from(to_rate) * 0.45; | ||
| 420 | - lowpass(s, from_rate, cutoff) | ||
| 421 | - .iter() | ||
| 422 | - .step_by((from_rate / to_rate.max(1)).max(1) as usize) | ||
| 423 | - .copied() | ||
| 424 | - .collect() | ||
| 425 | - }; | ||
| 426 | - let core_lag_max = WIDE_LAG_MAX / 2; | ||
| 427 | - let ours_v_core = if kx > 0 { | ||
| 428 | - our_decode_core_only(&path, 0).map(|(core, core_rate)| { | ||
| 429 | - let full_at_core_rate = decimate(o, our_rate, core_rate); | ||
| 430 | - best_lag_correlation_wide(&full_at_core_rate, &core[0], core_lag_max) | ||
| 431 | - }) | ||
| 432 | - } else { | ||
| 433 | - None | ||
| 434 | - }; | ||
| 435 | - // Coordinator follow-up 2: splits "our core decode of THIS | ||
| 436 | - // fixture is wrong" (core_v_ref ~0) from "the SBR chain | ||
| 437 | - // scrambles a good core" (core_v_ref >= ~0.99 while `below`/ | ||
| 438 | - // `above` stays ~0/negative) -- OUR core-only decode, same | ||
| 439 | - // native-core-rate convention `ours_v_core` now uses, against | ||
| 440 | - // the REFERENCE decoder's own decode resampled to that same | ||
| 441 | - // core rate (`ffmpeg_decode_at_rate`, the same helper | ||
| 442 | - // `core_only_matches_reference` already trusts) -- wide lag | ||
| 443 | - // search since this is an independent alignment from | ||
| 444 | - // `full`/`below`'s (core-only carries no SBR delay). | ||
| 445 | - let (core_v_ref, core_rate_str) = if kx > 0 { | ||
| 446 | - match our_decode_core_only(&path, 0) { | ||
| 447 | - Some((core, core_rate)) => { | ||
| 448 | - let ref_at_core_rate = | ||
| 449 | - ffmpeg_decode_at_rate(&path, 0, core.len(), core_rate); | ||
| 450 | - ( | ||
| 451 | - Some(best_lag_correlation_wide( | ||
| 452 | - &core[0], | ||
| 453 | - &ref_at_core_rate[0], | ||
| 454 | - core_lag_max, | ||
| 455 | - )), | ||
| 456 | - core_rate.to_string(), | ||
| 457 | - ) | ||
| 458 | - } | ||
| 459 | - None => (None, "n/a".into()), | ||
| 460 | - } | ||
| 461 | - } else { | ||
| 462 | - (None, "n/a".into()) | ||
| 463 | - }; | ||
| 464 | - println!( | ||
| 465 | - "{rate:>5} {br:>6} {profile:>4} {kx:>4} {k2:>4} {full:>8.4} {below:>8.4} {above:>8.4} {lag:>6} {:>11} {:>8} {:>10} {:>8} {:>9} {:>9}", | ||
| 466 | - ours_v_core | ||
| 467 | - .map(|(_, c)| format!("{c:.4}")) | ||
| 468 | - .unwrap_or_else(|| "n/a".into()), | ||
| 469 | - ours_v_core | ||
| 470 | - .map(|(l, _)| l.to_string()) | ||
| 471 | - .unwrap_or_else(|| "n/a".into()), | ||
| 472 | - core_v_ref | ||
| 473 | - .map(|(_, c)| format!("{c:.4}")) | ||
| 474 | - .unwrap_or_else(|| "n/a".into()), | ||
| 475 | - core_v_ref | ||
| 476 | - .map(|(l, _)| l.to_string()) | ||
| 477 | - .unwrap_or_else(|| "n/a".into()), | ||
| 478 | - core_rate_str, | ||
| 479 | - our_rate, | ||
| 480 | - ); | ||
| 481 | - // 44.1k-family HE rows: print per-second full-band corr at | ||
| 482 | - // the row's own robust `lag` over 30s, so a content- | ||
| 483 | - // dependent HF-reconstruction dip (real, not an alignment | ||
| 484 | - // artifact -- `sbr441_family_sample_drift_probe` isolated | ||
| 485 | - // one at t=13-27s on heaac_44100_48k.m4a) is visible per | ||
| 486 | - // second instead of averaged away by the single `full` | ||
| 487 | - // column above. | ||
| 488 | - if profile == "HE" && rate == 44_100 { | ||
| 489 | - println!(" per-second full-band corr @ lag {lag} (t, corr):"); | ||
| 490 | - let step = our_rate.max(1) as usize; | ||
| 491 | - for sec in 0..30usize { | ||
| 492 | - let oa0 = sec * step; | ||
| 493 | - if oa0 + step > o.len() { | ||
| 494 | - break; | ||
| 495 | - } | ||
| 496 | - let ob0 = oa0 as i64 + lag; | ||
| 497 | - if ob0 < 0 { | ||
| 498 | - continue; | ||
| 499 | - } | ||
| 500 | - let ob0 = ob0 as usize; | ||
| 501 | - if ob0 + step > t.len() { | ||
| 502 | - continue; | ||
| 503 | - } | ||
| 504 | - let c = correlation(&o[oa0..oa0 + step], &t[ob0..ob0 + step]); | ||
| 505 | - println!(" t={sec:>2}s corr={c:.6}"); | ||
| 506 | - } | ||
| 507 | - } | ||
| 508 | - // Coordinator follow-up (4): on the two named rows, probe | ||
| 509 | - // candidate total HE-vs-reference delays built from LC's own | ||
| 510 | - // priming lag plus a guessed SBR-chain contribution, to see | ||
| 511 | - // which (if any) actually lands near 1.0 -- and whether that | ||
| 512 | - // offset is constant across the two rows. | ||
| 513 | - if profile == "HE" | ||
| 514 | - && ((rate == 44_100 && br == "48k") || (rate == 48_000 && br == "64k")) | ||
| 515 | - { | ||
| 516 | - let lc = lc_lag.unwrap_or(-2048); | ||
| 517 | - println!(" ch0 delay probe (LC lag {lc}):"); | ||
| 518 | - for (label, extra) in [ | ||
| 519 | - ("2990", 2990i64), | ||
| 520 | - ("3010", 3010), | ||
| 521 | - ("3020", 3020), | ||
| 522 | - ("1505x2", 1505 * 2), | ||
| 523 | - ("962x2", 962 * 2), | ||
| 524 | - ] { | ||
| 525 | - let candidate = (lc - 2048) + extra; | ||
| 526 | - println!( | ||
| 527 | - " offset={label:>6} -> lag={candidate:>6} corr={:.6}", | ||
| 528 | - correlation_at_lag(o, t, candidate) | ||
| 529 | - ); | ||
| 530 | - } | ||
| 531 | - } | ||
| 532 | - if profile == "LC" { | ||
| 533 | - assert!( | ||
| 534 | - full >= 0.999, | ||
| 535 | - "{}: LC control full-band corr {full:.6} < 0.999 -- the \ | ||
| 536 | - harness itself (extraction/decode/correlation) is broken, \ | ||
| 537 | - not the SBR chain this fixture matrix is meant to isolate", | ||
| 538 | - path.display() | ||
| 539 | - ); | ||
| 540 | } | 399 | } |
| 400 | + None => (None, "n/a".into()), | ||
| 541 | } | 401 | } |
| 542 | - } | 402 | + } else { |
| 403 | + (None, "n/a".into()) | ||
| 404 | + }; | ||
| 405 | + println!( | ||
| 406 | + "{kx:>4} {k2:>4} {full:>8.4} {below:>8.4} {above:>8.4} {lag:>6} {:>11} {:>8} {:>10} {:>8} {:>9} {:>9}", | ||
| 407 | + ours_v_core | ||
| 408 | + .map(|(_, c)| format!("{c:.4}")) | ||
| 409 | + .unwrap_or_else(|| "n/a".into()), | ||
| 410 | + ours_v_core | ||
| 411 | + .map(|(l, _)| l.to_string()) | ||
| 412 | + .unwrap_or_else(|| "n/a".into()), | ||
| 413 | + core_v_ref | ||
| 414 | + .map(|(_, c)| format!("{c:.4}")) | ||
| 415 | + .unwrap_or_else(|| "n/a".into()), | ||
| 416 | + core_v_ref | ||
| 417 | + .map(|(l, _)| l.to_string()) | ||
| 418 | + .unwrap_or_else(|| "n/a".into()), | ||
| 419 | + core_rate_str, | ||
| 420 | + our_rate, | ||
| 421 | + ); | ||
| 543 | } | 422 | } |
| 544 | - assert!( | ||
| 545 | - probed >= 16, | ||
| 546 | - "only {probed} of 16 HE-AAC matrix fixtures were present -- rerun \ | ||
| 547 | - scripts/aac-tables/make-heaac-fixtures.sh" | ||
| 548 | - ); | ||
| 549 | } | 423 | } |
| 550 | 424 | ||
| 551 | pub(super) fn candidates() -> Vec<Candidate> { | 425 | pub(super) fn candidates() -> Vec<Candidate> { |
| 552 | - let home = std::env::var("HOME").unwrap_or_default(); | 426 | + fate_aac() |
| 553 | - [ | 427 | + .into_iter() |
| 554 | - (format!("{home}/Music/reeln.mp4"), 0, 0, 5_000.0), | 428 | + .map(|path| Candidate { |
| 555 | - ( | 429 | + path, |
| 556 | - format!( | 430 | + aac_stream: 0, |
| 557 | - "{home}/Downloads/reelp/reelp.mkv" | 431 | + ffmpeg_stream: 0, |
| 558 | - ), | 432 | + crossover_hz: 5_000.0, |
| 559 | - 1, | 433 | + }) |
| 560 | - 3, | 434 | + .collect() |
| 561 | - 5_000.0, | ||
| 562 | - ), | ||
| 563 | - ] | ||
| 564 | - .into_iter() | ||
| 565 | - .map(|(p, aac_stream, ffmpeg_stream, crossover_hz)| Candidate { | ||
| 566 | - path: PathBuf::from(p), | ||
| 567 | - aac_stream, | ||
| 568 | - ffmpeg_stream, | ||
| 569 | - crossover_hz, | ||
| 570 | - }) | ||
| 571 | - .filter(|c| c.path.exists()) | ||
| 572 | - .collect() | ||
| 573 | } | 435 | } |
| 574 | 436 | ||
| 575 | /// The SBR chain against the reference decoder on every real HE-AAC file this | 437 | /// The SBR chain against the reference decoder on every real HE-AAC file this |
| @@ -581,29 +443,14 @@ pub(super) fn candidates() -> Vec<Candidate> { | |||
| 581 | #[test] | 443 | #[test] |
| 582 | pub(super) fn sbr_real_library_matches_reference() { | 444 | pub(super) fn sbr_real_library_matches_reference() { |
| 583 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 445 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 584 | - if !have_ffmpeg() { | ||
| 585 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 586 | - return; | ||
| 587 | - } | ||
| 588 | let list = candidates(); | 446 | let list = candidates(); |
| 589 | - if list.is_empty() { | ||
| 590 | - eprintln!("SKIP: no HE-AAC files found under ~/Music, ~/Downloads, ~/Videos"); | ||
| 591 | - return; | ||
| 592 | - } | ||
| 593 | let mut checked = 0; | 447 | let mut checked = 0; |
| 594 | let mut worst_full = 1.0f64; | 448 | let mut worst_full = 1.0f64; |
| 595 | let mut worst_low = 1.0f64; | 449 | let mut worst_low = 1.0f64; |
| 596 | let mut any_at_edge: Option<String> = None; | 450 | let mut any_at_edge: Option<String> = None; |
| 597 | for c in &list { | 451 | for c in &list { |
| 598 | - let Some((ours, sbr, rate)) = our_decode(&c.path, c.aac_stream) else { | 452 | + let (ours, sbr, rate) = our_decode(&c.path, c.aac_stream).expect("decode"); |
| 599 | - eprintln!("SKIP {}: could not decode", c.path.display()); | ||
| 600 | - continue; | ||
| 601 | - }; | ||
| 602 | if sbr != ec_aac::SbrSupport::V1 { | 453 | if sbr != ec_aac::SbrSupport::V1 { |
| 603 | - eprintln!( | ||
| 604 | - "SKIP {}: sbr_support() is {sbr:?}, not a plain-SBR (v1) stream this chain reconstructs", | ||
| 605 | - c.path.display() | ||
| 606 | - ); | ||
| 607 | continue; | 454 | continue; |
| 608 | } | 455 | } |
| 609 | let theirs = ffmpeg_decode(&c.path, c.ffmpeg_stream, ours.len()); | 456 | let theirs = ffmpeg_decode(&c.path, c.ffmpeg_stream, ours.len()); |
| @@ -1163,10 +1010,7 @@ pub(super) fn sbr_real_library_matches_reference() { | |||
| 1163 | } | 1010 | } |
| 1164 | checked += 1; | 1011 | checked += 1; |
| 1165 | } | 1012 | } |
| 1166 | - if checked == 0 { | 1013 | + assert!(checked > 0, "no plain-SBR real files decoded"); |
| 1167 | - eprintln!("SKIP: no plain-SBR real files decoded"); | ||
| 1168 | - return; | ||
| 1169 | - } | ||
| 1170 | assert!( | 1014 | assert!( |
| 1171 | any_at_edge.is_none(), | 1015 | any_at_edge.is_none(), |
| 1172 | "lag search hit its bound: {} -- the reported correlations are noise \ | 1016 | "lag search hit its bound: {} -- the reported correlations are noise \ |
crates/ec-aac/tests/sbr_real_library/chunk_b.rsmodified+25 -181
| @@ -23,23 +23,7 @@ use super::*; | |||
| 23 | #[test] | 23 | #[test] |
| 24 | pub(super) fn sbr_instrument_anchor_controls() { | 24 | pub(super) fn sbr_instrument_anchor_controls() { |
| 25 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 25 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 26 | - if std::env::var("EC_AAC_SBR_INSTRUMENT_ANCHOR").is_err() { | 26 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 27 | - eprintln!( | ||
| 28 | - "SKIP (round-41 Task 1): EC_AAC_SBR_INSTRUMENT_ANCHOR=1 cargo test -p ec-aac \ | ||
| 29 | - --release --test sbr_real_library sbr_instrument_anchor_controls -- --nocapture" | ||
| 30 | - ); | ||
| 31 | - return; | ||
| 32 | - } | ||
| 33 | - if !have_ffmpeg() { | ||
| 34 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 35 | - return; | ||
| 36 | - } | ||
| 37 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 38 | - let path = PathBuf::from(format!("{home}/Music/reeln.mp4")); | ||
| 39 | - if !path.exists() { | ||
| 40 | - eprintln!("SKIP: {} not found", path.display()); | ||
| 41 | - return; | ||
| 42 | - } | ||
| 43 | const MIN_BAND: usize = 14; | 27 | const MIN_BAND: usize = 14; |
| 44 | const TOP_N: usize = 128; // larger than any real band count -- keeps every HF band | 28 | const TOP_N: usize = 128; // larger than any real band count -- keeps every HF band |
| 45 | 29 | ||
| @@ -103,25 +87,7 @@ pub(super) fn sbr_instrument_anchor_controls() { | |||
| 103 | #[test] | 87 | #[test] |
| 104 | pub(super) fn sbr_actual_noise_fraction() { | 88 | pub(super) fn sbr_actual_noise_fraction() { |
| 105 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 89 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 106 | - if std::env::var("EC_AAC_SBR_NOISE_ANCHOR").is_err() { | 90 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 107 | - eprintln!( | ||
| 108 | - "SKIP (round-41 Task 2): EC_AAC_SBR_NOISE_ANCHOR=1 cargo test -p ec-aac \ | ||
| 109 | - --release --test sbr_real_library sbr_actual_noise_fraction -- \ | ||
| 110 | - --nocapture --test-threads=1 (env-gated because it sets process \ | ||
| 111 | - env vars mid-run, which is unsound alongside parallel tests)" | ||
| 112 | - ); | ||
| 113 | - return; | ||
| 114 | - } | ||
| 115 | - if !have_ffmpeg() { | ||
| 116 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 117 | - return; | ||
| 118 | - } | ||
| 119 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 120 | - let path = PathBuf::from(format!("{home}/Music/reeln.mp4")); | ||
| 121 | - if !path.exists() { | ||
| 122 | - eprintln!("SKIP: {} not found", path.display()); | ||
| 123 | - return; | ||
| 124 | - } | ||
| 125 | const MIN_BAND: usize = 14; | 91 | const MIN_BAND: usize = 14; |
| 126 | const TOP_N: usize = 128; | 92 | const TOP_N: usize = 128; |
| 127 | 93 | ||
| @@ -295,17 +261,13 @@ pub(super) fn sbr_actual_noise_fraction() { | |||
| 295 | #[test] | 261 | #[test] |
| 296 | pub(super) fn sbr_header_feature_table() { | 262 | pub(super) fn sbr_header_feature_table() { |
| 297 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 263 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 298 | - if !have_ffmpeg() { | ||
| 299 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 300 | - return; | ||
| 301 | - } | ||
| 302 | struct Row { | 264 | struct Row { |
| 303 | label: String, | 265 | label: String, |
| 304 | path: PathBuf, | 266 | path: PathBuf, |
| 305 | aac_stream: usize, | 267 | aac_stream: usize, |
| 306 | ffmpeg_stream: usize, | 268 | ffmpeg_stream: usize, |
| 307 | } | 269 | } |
| 308 | - let mut rows: Vec<Row> = candidates() | 270 | + let rows: Vec<Row> = candidates() |
| 309 | .into_iter() | 271 | .into_iter() |
| 310 | .map(|c| Row { | 272 | .map(|c| Row { |
| 311 | label: c | 273 | label: c |
| @@ -318,28 +280,6 @@ pub(super) fn sbr_header_feature_table() { | |||
| 318 | ffmpeg_stream: c.ffmpeg_stream, | 280 | ffmpeg_stream: c.ffmpeg_stream, |
| 319 | }) | 281 | }) |
| 320 | .collect(); | 282 | .collect(); |
| 321 | - let fixtures = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 322 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 323 | - let fixtures = PathBuf::from(fixtures); | ||
| 324 | - if require_fixture(&fixtures, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 325 | - for rate in [48_000u32, 44_100] { | ||
| 326 | - for br in ["32k", "48k", "64k", "96k"] { | ||
| 327 | - let p = fixtures.join(format!("heaac_{rate}_{br}.m4a")); | ||
| 328 | - if require_fixture(&p, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 329 | - rows.push(Row { | ||
| 330 | - label: format!("synth-{rate}-{br}"), | ||
| 331 | - path: p, | ||
| 332 | - aac_stream: 0, | ||
| 333 | - ffmpeg_stream: 0, | ||
| 334 | - }); | ||
| 335 | - } | ||
| 336 | - } | ||
| 337 | - } | ||
| 338 | - } | ||
| 339 | - if rows.is_empty() { | ||
| 340 | - eprintln!("SKIP: no real HE-AAC files and no synthetic fixtures found"); | ||
| 341 | - return; | ||
| 342 | - } | ||
| 343 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); | 283 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); |
| 344 | const WIDE_LAG_MAX: i64 = 20_000; | 284 | const WIDE_LAG_MAX: i64 = 20_000; |
| 345 | println!( | 285 | println!( |
| @@ -366,12 +306,8 @@ pub(super) fn sbr_header_feature_table() { | |||
| 366 | ); | 306 | ); |
| 367 | for r in &rows { | 307 | for r in &rows { |
| 368 | let before = ec_aac::sbr_sideinfo_log().len(); | 308 | let before = ec_aac::sbr_sideinfo_log().len(); |
| 369 | - let Some((ours, sbr, our_rate)) = our_decode(&r.path, r.aac_stream) else { | 309 | + let (ours, sbr, our_rate) = our_decode(&r.path, r.aac_stream).expect("decode"); |
| 370 | - eprintln!("SKIP {}: could not decode", r.label); | ||
| 371 | - continue; | ||
| 372 | - }; | ||
| 373 | if sbr != ec_aac::SbrSupport::V1 { | 310 | if sbr != ec_aac::SbrSupport::V1 { |
| 374 | - eprintln!("SKIP {}: not SBR v1", r.label); | ||
| 375 | continue; | 311 | continue; |
| 376 | } | 312 | } |
| 377 | let log = ec_aac::sbr_sideinfo_log(); | 313 | let log = ec_aac::sbr_sideinfo_log(); |
| @@ -380,10 +316,7 @@ pub(super) fn sbr_header_feature_table() { | |||
| 380 | .filter(|row| row.ch == 0) | 316 | .filter(|row| row.ch == 0) |
| 381 | .take(20) | 317 | .take(20) |
| 382 | .collect(); | 318 | .collect(); |
| 383 | - if frames.is_empty() { | 319 | + assert!(!frames.is_empty(), "{}: no sideinfo rows captured", r.label); |
| 384 | - eprintln!("SKIP {}: no sideinfo rows captured", r.label); | ||
| 385 | - continue; | ||
| 386 | - } | ||
| 387 | let f0 = &frames[0]; | 320 | let f0 = &frames[0]; |
| 388 | let mut env_counts: std::collections::BTreeMap<usize, usize> = Default::default(); | 321 | let mut env_counts: std::collections::BTreeMap<usize, usize> = Default::default(); |
| 389 | let mut invf_seen: std::collections::BTreeSet<u8> = Default::default(); | 322 | let mut invf_seen: std::collections::BTreeSet<u8> = Default::default(); |
| @@ -467,18 +400,9 @@ pub(super) fn sbr_header_feature_table() { | |||
| 467 | /// -- divergence from the very first AU means a per-stream setup mismatch, | 400 | /// -- divergence from the very first AU means a per-stream setup mismatch, |
| 468 | /// not a per-frame trigger. | 401 | /// not a per-frame trigger. |
| 469 | pub(super) fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) { | 402 | pub(super) fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) { |
| 470 | - let Some((asc, aus)) = extract_aac_track(path, aac_stream) else { | 403 | + let (asc, aus) = extract_aac_track(path, aac_stream).expect("extract_aac_track"); |
| 471 | - eprintln!("SKIP {label}: extract_aac_track failed"); | 404 | + let full_cfg = parse_audio_specific_config(&asc).expect("asc parse"); |
| 472 | - return; | 405 | + assert!(full_cfg.sbr_present, "{label}: no SBR"); |
| 473 | - }; | ||
| 474 | - let Ok(full_cfg) = parse_audio_specific_config(&asc) else { | ||
| 475 | - eprintln!("SKIP {label}: asc parse failed"); | ||
| 476 | - return; | ||
| 477 | - }; | ||
| 478 | - if !full_cfg.sbr_present { | ||
| 479 | - eprintln!("SKIP {label}: no SBR"); | ||
| 480 | - return; | ||
| 481 | - } | ||
| 482 | let mut core_cfg = full_cfg.clone(); | 406 | let mut core_cfg = full_cfg.clone(); |
| 483 | core_cfg.sbr_present = false; | 407 | core_cfg.sbr_present = false; |
| 484 | core_cfg.ps_present = false; | 408 | core_cfg.ps_present = false; |
| @@ -519,14 +443,12 @@ pub(super) fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) | |||
| 519 | break; | 443 | break; |
| 520 | } | 444 | } |
| 521 | } | 445 | } |
| 522 | - if core_ch0.is_empty() || full_ch0.is_empty() { | 446 | + assert!( |
| 523 | - eprintln!( | 447 | + !core_ch0.is_empty() && !full_ch0.is_empty(), |
| 524 | - "SKIP {label}: empty decode (core {} full {})", | 448 | + "{label}: empty decode (core {} full {})", |
| 525 | - core_ch0.len(), | 449 | + core_ch0.len(), |
| 526 | - full_ch0.len() | 450 | + full_ch0.len() |
| 527 | - ); | 451 | + ); |
| 528 | - return; | ||
| 529 | - } | ||
| 530 | 452 | ||
| 531 | // Same convention `full_chain_low_band_matches_own_core` already | 453 | // Same convention `full_chain_low_band_matches_own_core` already |
| 532 | // validated (0.9967 on reeln): naive nearest-neighbor 2x-upsample | 454 | // validated (0.9967 on reeln): naive nearest-neighbor 2x-upsample |
| @@ -589,20 +511,10 @@ pub(super) fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) | |||
| 589 | #[test] | 511 | #[test] |
| 590 | pub(super) fn per_au_low_band_divergence() { | 512 | pub(super) fn per_au_low_band_divergence() { |
| 591 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 513 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 592 | - if !have_ffmpeg() { | ||
| 593 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 594 | - return; | ||
| 595 | - } | ||
| 596 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); | 514 | let _knob = ec_aac::knobs::set_sbr_sideinfo_debug(Some(true)); |
| 597 | for c in &candidates() { | 515 | for c in &candidates() { |
| 598 | per_au_low_band_probe(&c.path.display().to_string(), &c.path, c.aac_stream); | 516 | per_au_low_band_probe(&c.path.display().to_string(), &c.path, c.aac_stream); |
| 599 | } | 517 | } |
| 600 | - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 601 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 602 | - let failing = PathBuf::from(&dir).join("heaac_44100_48k.m4a"); | ||
| 603 | - if require_fixture(&failing, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 604 | - per_au_low_band_probe("synthetic 44100 48k (failing)", &failing, 0); | ||
| 605 | - } | ||
| 606 | } | 518 | } |
| 607 | 519 | ||
| 608 | /// Coordinator follow-up: prints what `parse_audio_specific_config` actually | 520 | /// Coordinator follow-up: prints what `parse_audio_specific_config` actually |
| @@ -618,10 +530,6 @@ pub(super) fn per_au_low_band_divergence() { | |||
| 618 | #[test] | 530 | #[test] |
| 619 | pub(super) fn probe_explicit_config_and_wide_lag() { | 531 | pub(super) fn probe_explicit_config_and_wide_lag() { |
| 620 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 532 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 621 | - if !have_ffmpeg() { | ||
| 622 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 623 | - return; | ||
| 624 | - } | ||
| 625 | fn decode_with(cfg: ec_aac::AudioSpecificConfig, aus: &[Vec<u8>]) -> (Vec<Vec<f32>>, u32) { | 533 | fn decode_with(cfg: ec_aac::AudioSpecificConfig, aus: &[Vec<u8>]) -> (Vec<Vec<f32>>, u32) { |
| 626 | let rate = match (cfg.sbr_present, cfg.ps_present) { | 534 | let rate = match (cfg.sbr_present, cfg.ps_present) { |
| 627 | (true, false) => cfg.extension_sample_rate.unwrap_or(cfg.sample_rate * 2), | 535 | (true, false) => cfg.extension_sample_rate.unwrap_or(cfg.sample_rate * 2), |
| @@ -648,71 +556,14 @@ pub(super) fn probe_explicit_config_and_wide_lag() { | |||
| 648 | (planes, rate) | 556 | (planes, rate) |
| 649 | } | 557 | } |
| 650 | 558 | ||
| 651 | - // `synthetic` marks the case as coming from the committed fixture library | 559 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 652 | - // (`scripts/aac-tables/make-heaac-fixtures.sh`); the FMJ row is a | 560 | + let (label, aac_stream, ffmpeg_stream, core_sf_index, core_rate, ext_rate, channels) = |
| 653 | - // `~/Downloads` host corpus and keeps its plain skip. | 561 | + ("al_sbr_cm_48_2", 0usize, 0usize, 6u8, 24_000u32, 0u32, 2u16); |
| 654 | - for ( | 562 | + { |
| 655 | - label, | 563 | + let (asc, aus) = extract_aac_track(&path, aac_stream).expect("extract"); |
| 656 | - path, | ||
| 657 | - aac_stream, | ||
| 658 | - ffmpeg_stream, | ||
| 659 | - core_sf_index, | ||
| 660 | - core_rate, | ||
| 661 | - ext_rate, | ||
| 662 | - channels, | ||
| 663 | - synthetic, | ||
| 664 | - ) in [ | ||
| 665 | - ( | ||
| 666 | - "FMJ", | ||
| 667 | - format!( | ||
| 668 | - "{}/Downloads/reelp/reelp.mkv", | ||
| 669 | - std::env::var("HOME").unwrap_or_default() | ||
| 670 | - ), | ||
| 671 | - 1usize, | ||
| 672 | - 3usize, | ||
| 673 | - 6u8, | ||
| 674 | - 24_000u32, | ||
| 675 | - 48_000u32, | ||
| 676 | - 2u16, | ||
| 677 | - false, | ||
| 678 | - ), | ||
| 679 | - ( | ||
| 680 | - "heaac_44100_48k", | ||
| 681 | - format!( | ||
| 682 | - "{}/heaac_44100_48k.m4a", | ||
| 683 | - std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| format!( | ||
| 684 | - "{}/../../.cache/heaac-fixtures", | ||
| 685 | - env!("CARGO_MANIFEST_DIR") | ||
| 686 | - )) | ||
| 687 | - ), | ||
| 688 | - 0, | ||
| 689 | - 0, | ||
| 690 | - 4, | ||
| 691 | - 44_100, | ||
| 692 | - 0, // filled below from parsed cfg's own extension_sample_rate | ||
| 693 | - 2, | ||
| 694 | - true, | ||
| 695 | - ), | ||
| 696 | - ] { | ||
| 697 | - let path = PathBuf::from(path); | ||
| 698 | - if synthetic { | ||
| 699 | - if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 700 | - continue; | ||
| 701 | - } | ||
| 702 | - } else if !path.exists() { | ||
| 703 | - eprintln!("SKIP {label}: {} absent", path.display()); | ||
| 704 | - continue; | ||
| 705 | - } | ||
| 706 | - let Some((asc, aus)) = extract_aac_track(&path, aac_stream) else { | ||
| 707 | - eprintln!("SKIP {label}: extract failed"); | ||
| 708 | - continue; | ||
| 709 | - }; | ||
| 710 | let parsed = parse_audio_specific_config(&asc); | 564 | let parsed = parse_audio_specific_config(&asc); |
| 711 | println!("{label}: asc={asc:02x?} parsed={parsed:?}"); | 565 | println!("{label}: asc={asc:02x?} parsed={parsed:?}"); |
| 712 | - let Ok(parsed_cfg) = parsed else { | 566 | + let parsed_cfg = parsed.expect("asc parse"); |
| 713 | - eprintln!("SKIP {label}: parse failed"); | ||
| 714 | - continue; | ||
| 715 | - }; | ||
| 716 | let d = AacDecoder::with_config(parsed_cfg.clone()); | 567 | let d = AacDecoder::with_config(parsed_cfg.clone()); |
| 717 | println!( | 568 | println!( |
| 718 | " runtime: sbr_support={:?} output_sample_rate={:?}", | 569 | " runtime: sbr_support={:?} output_sample_rate={:?}", |
| @@ -740,10 +591,7 @@ pub(super) fn probe_explicit_config_and_wide_lag() { | |||
| 740 | pce: Vec::new(), | 591 | pce: Vec::new(), |
| 741 | }; | 592 | }; |
| 742 | let (hand_planes, hand_rate) = decode_with(hand_cfg.clone(), &aus); | 593 | let (hand_planes, hand_rate) = decode_with(hand_cfg.clone(), &aus); |
| 743 | - if hand_planes.is_empty() { | 594 | + assert!(!hand_planes.is_empty(), "{label}: hand-built config decoded no channels"); |
| 744 | - eprintln!(" hand-built config: no channels decoded"); | ||
| 745 | - continue; | ||
| 746 | - } | ||
| 747 | // Own-core self-consistency (upsample+lowpass convention). | 595 | // Own-core self-consistency (upsample+lowpass convention). |
| 748 | let core_cfg = ec_aac::AudioSpecificConfig { | 596 | let core_cfg = ec_aac::AudioSpecificConfig { |
| 749 | sbr_present: false, | 597 | sbr_present: false, |
| @@ -777,13 +625,9 @@ pub(super) fn probe_explicit_config_and_wide_lag() { | |||
| 777 | // tests use) -- the coarse search in `full_chain_low_band_matches_own_ | 625 | // tests use) -- the coarse search in `full_chain_low_band_matches_own_ |
| 778 | // core` landed right at that bound's edge (20005), so this checks | 626 | // core` landed right at that bound's edge (20005), so this checks |
| 779 | // whether FMJ's true delay simply lies further out. | 627 | // whether FMJ's true delay simply lies further out. |
| 780 | - let home = std::env::var("HOME").unwrap_or_default(); | 628 | + let fmj = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 781 | - let fmj = PathBuf::from(format!( | 629 | + if let (Some((core, core_rate)), Some((full, sbr, full_rate))) = |
| 782 | - "{home}/Downloads/reelp/reelp.mkv" | 630 | + (our_decode_core_only(&fmj, 0), our_decode(&fmj, 0)) |
| 783 | - )); | ||
| 784 | - if fmj.exists() | ||
| 785 | - && let (Some((core, core_rate)), Some((full, sbr, full_rate))) = | ||
| 786 | - (our_decode_core_only(&fmj, 1), our_decode(&fmj, 1)) | ||
| 787 | && sbr == ec_aac::SbrSupport::V1 | 631 | && sbr == ec_aac::SbrSupport::V1 |
| 788 | { | 632 | { |
| 789 | let up: Vec<f32> = core[0].iter().flat_map(|&s| [s, s]).collect(); | 633 | let up: Vec<f32> = core[0].iter().flat_map(|&s| [s, s]).collect(); |
| @@ -800,7 +644,7 @@ pub(super) fn probe_explicit_config_and_wide_lag() { | |||
| 800 | /// rule (see `ffmpeg_decode`'s doc and the ledger's "never use -ac 1", which | 644 | /// rule (see `ffmpeg_decode`'s doc and the ledger's "never use -ac 1", which |
| 801 | /// applies just as much to picking one of N channels as to downmixing). | 645 | /// applies just as much to picking one of N channels as to downmixing). |
| 802 | pub(super) fn ffmpeg_decode_pan_channel(path: &Path, absolute_stream: usize, channel: usize) -> Vec<f32> { | 646 | pub(super) fn ffmpeg_decode_pan_channel(path: &Path, absolute_stream: usize, channel: usize) -> Vec<f32> { |
| 803 | - let out = Command::new("ffmpeg") | 647 | + let out = ec_testkit::ffmpeg() |
| 804 | .args(["-v", "error", "-i"]) | 648 | .args(["-v", "error", "-i"]) |
| 805 | .arg(path) | 649 | .arg(path) |
| 806 | .args([ | 650 | .args([ |
crates/ec-aac/tests/sbr_real_library/chunk_c.rsmodified+17 -112
| @@ -16,26 +16,15 @@ use super::*; | |||
| 16 | #[test] | 16 | #[test] |
| 17 | pub(super) fn reelq_multichannel_lc_matches_reference() { | 17 | pub(super) fn reelq_multichannel_lc_matches_reference() { |
| 18 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 18 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 19 | - if !have_ffmpeg() { | 19 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_5.1.mp4"); |
| 20 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 21 | - return; | ||
| 22 | - } | ||
| 23 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 24 | - let path = PathBuf::from(format!( | ||
| 25 | - "{home}/Downloads/reelq/reelq.mp4" | ||
| 26 | - )); | ||
| 27 | - if !path.exists() { | ||
| 28 | - eprintln!("SKIP: {} not present", path.display()); | ||
| 29 | - return; | ||
| 30 | - } | ||
| 31 | let Some((ours, _sbr, rate)) = our_decode(&path, 0) else { | 20 | let Some((ours, _sbr, rate)) = our_decode(&path, 0) else { |
| 32 | - panic!("ReelQ AAC track failed to decode at all"); | 21 | + panic!("AAC track failed to decode at all"); |
| 33 | }; | 22 | }; |
| 34 | - assert_eq!(ours.len(), 8, "expected 7.1 (8 channels)"); | 23 | + assert_eq!(ours.len(), 6, "expected 5.1 (6 channels)"); |
| 35 | let want = (rate as usize) * 10; // 10s per the charter | 24 | let want = (rate as usize) * 10; // 10s per the charter |
| 36 | for (ch, o) in ours.iter().enumerate() { | 25 | for (ch, o) in ours.iter().enumerate() { |
| 37 | let o = &o[..o.len().min(want)]; | 26 | let o = &o[..o.len().min(want)]; |
| 38 | - let t = ffmpeg_decode_pan_channel(&path, 2, ch); | 27 | + let t = ffmpeg_decode_pan_channel(&path, 0, ch); |
| 39 | let t = &t[..t.len().min(want)]; | 28 | let t = &t[..t.len().min(want)]; |
| 40 | let (lag, corr) = best_lag_correlation(o, t); | 29 | let (lag, corr) = best_lag_correlation(o, t); |
| 41 | println!("ReelQ ch{ch}: lag {lag}, corr {corr:.6}"); | 30 | println!("ReelQ ch{ch}: lag {lag}, corr {corr:.6}"); |
| @@ -76,18 +65,9 @@ pub(super) fn reelq_multichannel_lc_matches_reference() { | |||
| 76 | #[test] | 65 | #[test] |
| 77 | pub(super) fn coupled_cpe_channel_swap_probe() { | 66 | pub(super) fn coupled_cpe_channel_swap_probe() { |
| 78 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 67 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 79 | - if !have_ffmpeg() { | 68 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 80 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 81 | - return; | ||
| 82 | - } | ||
| 83 | - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 84 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 85 | - let path = PathBuf::from(&dir).join("heaac_44100_48k.m4a"); | ||
| 86 | - if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 87 | - return; | ||
| 88 | - } | ||
| 89 | let Some((ours, sbr, out_rate)) = our_decode(&path, 0) else { | 69 | let Some((ours, sbr, out_rate)) = our_decode(&path, 0) else { |
| 90 | - panic!("heaac_44100_48k failed to decode"); | 70 | + panic!("al_sbr_cm_48_2 failed to decode"); |
| 91 | }; | 71 | }; |
| 92 | assert_eq!(sbr, ec_aac::SbrSupport::V1); | 72 | assert_eq!(sbr, ec_aac::SbrSupport::V1); |
| 93 | assert_eq!(ours.len(), 2, "expect stereo"); | 73 | assert_eq!(ours.len(), 2, "expect stereo"); |
| @@ -337,7 +317,7 @@ pub(super) fn our_decode_uncapped(path: &Path, stream_index: usize) -> Option<(V | |||
| 337 | /// AAC stream, interleaved-`f32` byte count / 4 -- i.e. `channels * | 317 | /// AAC stream, interleaved-`f32` byte count / 4 -- i.e. `channels * |
| 338 | /// per_channel_samples`, not capped at 30s the way `ffmpeg_decode` is. | 318 | /// per_channel_samples`, not capped at 30s the way `ffmpeg_decode` is. |
| 339 | pub(super) fn ffmpeg_total_interleaved_samples(path: &Path, absolute_stream: usize) -> u64 { | 319 | pub(super) fn ffmpeg_total_interleaved_samples(path: &Path, absolute_stream: usize) -> u64 { |
| 340 | - let out = Command::new("ffmpeg") | 320 | + let out = ec_testkit::ffmpeg() |
| 341 | .args(["-v", "error", "-i"]) | 321 | .args(["-v", "error", "-i"]) |
| 342 | .arg(path) | 322 | .arg(path) |
| 343 | .args([ | 323 | .args([ |
| @@ -364,7 +344,7 @@ pub(super) fn ffmpeg_total_interleaved_samples(path: &Path, absolute_stream: usi | |||
| 364 | /// `duration` against what our decoder derives and what ffmpeg actually | 344 | /// `duration` against what our decoder derives and what ffmpeg actually |
| 365 | /// produces. | 345 | /// produces. |
| 366 | pub(super) fn ffprobe_field(path: &Path, entry: &str) -> String { | 346 | pub(super) fn ffprobe_field(path: &Path, entry: &str) -> String { |
| 367 | - let out = Command::new("ffprobe") | 347 | + let out = ec_testkit::ffprobe() |
| 368 | .args([ | 348 | .args([ |
| 369 | "-v", | 349 | "-v", |
| 370 | "error", | 350 | "error", |
| @@ -423,58 +403,14 @@ pub(super) fn narrow_lag_at( | |||
| 423 | #[test] | 403 | #[test] |
| 424 | pub(super) fn sbr441_family_sample_drift_probe() { | 404 | pub(super) fn sbr441_family_sample_drift_probe() { |
| 425 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 405 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 426 | - if !have_ffmpeg() { | 406 | + let cases: [(&str, PathBuf, i64); 2] = [ |
| 427 | - eprintln!("SKIP: ffmpeg not on PATH"); | 407 | + ("al_sbr_cm_48_2", ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"), 0), |
| 428 | - return; | 408 | + ("al_sbr_sr_48_2_fsaac48", ec_testkit::fixture("open/fate/aac/al_sbr_sr_48_2_fsaac48.mp4"), 0), |
| 429 | - } | ||
| 430 | - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 431 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 432 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 433 | - // `synthetic` marks the rows served by the committed fixture library | ||
| 434 | - // (`scripts/aac-tables/make-heaac-fixtures.sh`); the reeln control is | ||
| 435 | - // a `~/Music` host corpus and keeps its plain skip. | ||
| 436 | - let cases: [(&str, PathBuf, i64, bool); 3] = [ | ||
| 437 | - ( | ||
| 438 | - "heaac_44100_48k (FAIL family)", | ||
| 439 | - PathBuf::from(&dir).join("heaac_44100_48k.m4a"), | ||
| 440 | - -4674, | ||
| 441 | - true, | ||
| 442 | - ), | ||
| 443 | - ( | ||
| 444 | - "heaac_48000_48k (48k control)", | ||
| 445 | - PathBuf::from(&dir).join("heaac_48000_48k.m4a"), | ||
| 446 | - // corrected via this test's own wide free-search cross-check | ||
| 447 | - // (below) -- 0 was a bad guess, true fixed lag is -4673, same | ||
| 448 | - // as the failing family's. | ||
| 449 | - -4673, | ||
| 450 | - true, | ||
| 451 | - ), | ||
| 452 | - ( | ||
| 453 | - "reeln (44.1k control)", | ||
| 454 | - PathBuf::from(format!("{home}/Music/reeln.mp4")), | ||
| 455 | - // corrected via this test's own wide free-search cross-check | ||
| 456 | - // (below) -- -576 was this file's CORE-vs-FULL-chain delay | ||
| 457 | - // from an earlier probe, not its full-chain-vs-ffmpeg-reference | ||
| 458 | - // lag, which is +385. | ||
| 459 | - 385, | ||
| 460 | - false, | ||
| 461 | - ), | ||
| 462 | ]; | 409 | ]; |
| 463 | - for (label, path, seed_lag, synthetic) in cases { | 410 | + for (label, path, seed_lag) in cases { |
| 464 | println!("\n=== {label}: {} ===", path.display()); | 411 | println!("\n=== {label}: {} ===", path.display()); |
| 465 | - if synthetic { | ||
| 466 | - if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 467 | - continue; | ||
| 468 | - } | ||
| 469 | - } else if !path.exists() { | ||
| 470 | - eprintln!("SKIP {label}: {} absent", path.display()); | ||
| 471 | - continue; | ||
| 472 | - } | ||
| 473 | let holds_before = ec_aac::hold_call_count(); | 412 | let holds_before = ec_aac::hold_call_count(); |
| 474 | - let Some((ours, out_rate, au_count)) = our_decode_uncapped(&path, 0) else { | 413 | + let (ours, out_rate, au_count) = our_decode_uncapped(&path, 0).expect("our_decode_uncapped"); |
| 475 | - eprintln!("SKIP {label}: our_decode_uncapped failed"); | ||
| 476 | - continue; | ||
| 477 | - }; | ||
| 478 | // `ffmpeg_decode_pan_channel` caps at 10s (per its own charter, | 414 | // `ffmpeg_decode_pan_channel` caps at 10s (per its own charter, |
| 479 | // shared with `reelq_multichannel_lc_matches_reference`); | 415 | // shared with `reelq_multichannel_lc_matches_reference`); |
| 480 | // this probe walks out to t=29s, so it needs `ffmpeg_decode`'s 30s | 416 | // this probe walks out to t=29s, so it needs `ffmpeg_decode`'s 30s |
| @@ -553,22 +489,10 @@ pub(super) fn sbr441_family_sample_drift_probe() { | |||
| 553 | #[test] | 489 | #[test] |
| 554 | pub(super) fn sbr_hf_window_band_probe() { | 490 | pub(super) fn sbr_hf_window_band_probe() { |
| 555 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 491 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 556 | - if !have_ffmpeg() { | 492 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 557 | - eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 558 | - return; | ||
| 559 | - } | ||
| 560 | - let dir = std::env::var("EC_AAC_HEAAC_FIXTURES") | ||
| 561 | - .unwrap_or_else(|_| format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))); | ||
| 562 | - let path = PathBuf::from(&dir).join("heaac_48000_64k.m4a"); | ||
| 563 | - if !require_fixture(&path, "scripts/aac-tables/make-heaac-fixtures.sh") { | ||
| 564 | - return; | ||
| 565 | - } | ||
| 566 | const LAG: i64 = -4673; | 493 | const LAG: i64 = -4673; |
| 567 | 494 | ||
| 568 | - let Some((ours, out_rate, _au_count)) = our_decode_uncapped(&path, 0) else { | 495 | + let (ours, out_rate, _au_count) = our_decode_uncapped(&path, 0).expect("our_decode_uncapped"); |
| 569 | - eprintln!("SKIP: our_decode_uncapped failed"); | ||
| 570 | - return; | ||
| 571 | - }; | ||
| 572 | let ref_l = ffmpeg_decode(&path, 0, 2).swap_remove(0); | 496 | let ref_l = ffmpeg_decode(&path, 0, 2).swap_remove(0); |
| 573 | let ch0 = &ours[0]; | 497 | let ch0 = &ours[0]; |
| 574 | 498 | ||
| @@ -661,27 +585,8 @@ pub(super) fn sbr_hf_window_band_probe() { | |||
| 661 | #[test] | 585 | #[test] |
| 662 | pub(super) fn sbr_residual_locator() { | 586 | pub(super) fn sbr_residual_locator() { |
| 663 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | 587 | let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); |
| 664 | - if !have_ffmpeg() { | 588 | + let path = ec_testkit::fixture("open/fate/aac/al_sbr_cm_48_2.mp4"); |
| 665 | - return; | 589 | + let (ours, _, rate) = our_decode(&path, 0).expect("decode"); |
| 666 | - } | ||
| 667 | - // lane-h264reallib: `unwrap_or_default()`, the shape this file's five | ||
| 668 | - // other HOME reads already use (:2710, :3426, :4109, :4182, :4575). A bare | ||
| 669 | - // `unwrap()` panicked on any host with no HOME -- a fleet runner -- which | ||
| 670 | - // is a red with no bearing on the decoder. The `path.exists()` guard below | ||
| 671 | - // already handles the absent-file case, so an empty HOME just makes the | ||
| 672 | - // fallback path relative-and-nonexistent and the test returns. | ||
| 673 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 674 | - // `EC_AAC_SBR_LOCATOR_FILE` points the same instrument at any other | ||
| 675 | - // HE-AAC file (e.g. a mono, uncoupled, noise-only probe encode). | ||
| 676 | - let path = std::env::var("EC_AAC_SBR_LOCATOR_FILE") | ||
| 677 | - .map(PathBuf::from) | ||
| 678 | - .unwrap_or_else(|_| PathBuf::from(format!("{home}/Music/reeln.mp4"))); | ||
| 679 | - if !path.exists() { | ||
| 680 | - return; | ||
| 681 | - } | ||
| 682 | - let Some((ours, _, rate)) = our_decode(&path, 0) else { | ||
| 683 | - return; | ||
| 684 | - }; | ||
| 685 | let theirs = ffmpeg_decode(&path, 0, ours.len()); | 590 | let theirs = ffmpeg_decode(&path, 0, ours.len()); |
| 686 | const W: usize = 2048; | 591 | const W: usize = 2048; |
| 687 | const FFT_LEN: usize = 2048; | 592 | const FFT_LEN: usize = 2048; |
crates/ec-aac/tests/sbr_real_library/helpers.rsmodified+14 -29
| @@ -1,33 +1,18 @@ | |||
| 1 | -//! Shared analysis helpers for the SBR real-library probes. | 1 | +//! Shared analysis helpers for the SBR probes. |
| 2 | 2 | ||
| 3 | use super::*; | 3 | use super::*; |
| 4 | 4 | ||
| 5 | -pub(super) use crate::common::have_ffmpeg; | 5 | +pub(super) fn fate_aac() -> Vec<PathBuf> { |
| 6 | -/// Fixture-presence probe for the generated HE-AAC matrix under | 6 | + [ |
| 7 | -/// `<repo>/.cache/heaac-fixtures` (`scripts/aac-tables/make-heaac-fixtures.sh`). | 7 | + "open/fate/aac/al_sbr_cm_48_2.mp4", |
| 8 | -/// Returns whether the fixture is present, but never silently: under | 8 | + "open/fate/aac/al_sbr_cm_48_5.1.mp4", |
| 9 | -/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path | 9 | + "open/fate/aac/al_sbr_ps_04_new.mp4", |
| 10 | -/// and the script that regenerates it, so a host whose fixture library drifted | 10 | + "open/fate/aac/al_sbr_ps_06_new.mp4", |
| 11 | -/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; | 11 | + "open/fate/aac/al_sbr_sr_48_2_fsaac48.mp4", |
| 12 | -/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently | 12 | + ] |
| 13 | -/// short-circuited because the probe ran first in a compound `if`). | 13 | + .iter() |
| 14 | -/// | 14 | + .map(|rel| ec_testkit::fixture(rel)) |
| 15 | -/// Order is load-bearing: probe, assert, return. Never merge the probe into | 15 | + .collect() |
| 16 | -/// the same `if` as the escape. The `~/Music` / `~/Downloads` / `~/Videos` | ||
| 17 | -/// scans in this file are host corpora, not the committed fixture library, and | ||
| 18 | -/// keep their plain skip. | ||
| 19 | -pub(super) fn require_fixture(path: &Path, generator: &str) -> bool { | ||
| 20 | - let present = path.exists(); | ||
| 21 | - assert!( | ||
| 22 | - present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 23 | - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", | ||
| 24 | - path.display(), | ||
| 25 | - generator | ||
| 26 | - ); | ||
| 27 | - if !present { | ||
| 28 | - eprintln!("SKIP: fixture {} absent", path.display()); | ||
| 29 | - } | ||
| 30 | - present | ||
| 31 | } | 16 | } |
| 32 | 17 | ||
| 33 | /// A film's audio track is hours long; the correlation only needs a bounded | 18 | /// A film's audio track is hours long; the correlation only needs a bounded |
| @@ -37,7 +22,7 @@ pub(super) const MAX_SAMPLES: usize = 1_000_000; | |||
| 37 | /// ffmpeg's decode of a file's given absolute stream index, as | 22 | /// ffmpeg's decode of a file's given absolute stream index, as |
| 38 | /// planar-by-channel `f32`. | 23 | /// planar-by-channel `f32`. |
| 39 | pub(super) fn ffmpeg_decode(path: &Path, absolute_stream: usize, channels: usize) -> Vec<Vec<f32>> { | 24 | pub(super) fn ffmpeg_decode(path: &Path, absolute_stream: usize, channels: usize) -> Vec<Vec<f32>> { |
| 40 | - let out = Command::new("ffmpeg") | 25 | + let out = ec_testkit::ffmpeg() |
| 41 | .args(["-v", "error", "-i"]) | 26 | .args(["-v", "error", "-i"]) |
| 42 | .arg(path) | 27 | .arg(path) |
| 43 | .args([ | 28 | .args([ |
| @@ -2149,7 +2134,7 @@ pub(super) fn ffmpeg_decode_at_rate( | |||
| 2149 | channels: usize, | 2134 | channels: usize, |
| 2150 | target_rate: u32, | 2135 | target_rate: u32, |
| 2151 | ) -> Vec<Vec<f32>> { | 2136 | ) -> Vec<Vec<f32>> { |
| 2152 | - let out = Command::new("ffmpeg") | 2137 | + let out = ec_testkit::ffmpeg() |
| 2153 | .args(["-v", "error", "-i"]) | 2138 | .args(["-v", "error", "-i"]) |
| 2154 | .arg(path) | 2139 | .arg(path) |
| 2155 | .args([ | 2140 | .args([ |
crates/ec-aac/tests/sbr_real_library/main.rsmodified+5 -10
| @@ -1,15 +1,12 @@ | |||
| 1 | -//! The SBR chain, against real HE-AAC files pulled from the user's own media | 1 | +//! The SBR chain, against the open FATE HE-AAC files (`open/fate/aac`), |
| 2 | -//! directories, decoded through their real container (mp4 `esds` / Matroska | 2 | +//! decoded through their real container (mp4 `esds` / Matroska `CodecPrivate`) |
| 3 | -//! `CodecPrivate`) so `AacDecoder::with_config_bytes` actually arms the SBR | 3 | +//! so `AacDecoder::with_config_bytes` actually arms the SBR path -- `tests/oracle.rs` |
| 4 | -//! path -- `tests/oracle.rs` remuxes everything to bare ADTS first, and an | 4 | +//! remuxes everything to bare ADTS first, and an ADTS stream carries no |
| 5 | -//! ADTS stream carries no AudioSpecificConfig, so its SBR chain never sees a | 5 | +//! AudioSpecificConfig, so its SBR chain never sees a frame. |
| 6 | -//! frame. Every file here is a live discovery over `~/Music`, `~/Downloads`, | ||
| 7 | -//! `~/Videos`: absent files skip loudly, nothing is generated or bundled. | ||
| 8 | 6 | ||
| 9 | use std::fs::File; | 7 | use std::fs::File; |
| 10 | use std::io::{BufReader, Read}; | 8 | use std::io::{BufReader, Read}; |
| 11 | use std::path::{Path, PathBuf}; | 9 | use std::path::{Path, PathBuf}; |
| 12 | -use std::process::Command; | ||
| 13 | 10 | ||
| 14 | use ec_aac::{AacDecoder, parse_audio_specific_config}; | 11 | use ec_aac::{AacDecoder, parse_audio_specific_config}; |
| 15 | use ec_core::{CodecId, Demuxer, Packet}; | 12 | use ec_core::{CodecId, Demuxer, Packet}; |
| @@ -28,8 +25,6 @@ use ec_mp4::Mp4Demuxer; | |||
| 28 | /// each test. | 25 | /// each test. |
| 29 | static DECODE_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(()); | 26 | static DECODE_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(()); |
| 30 | 27 | ||
| 31 | -#[path = "../common/mod.rs"] | ||
| 32 | -mod common; | ||
| 33 | mod helpers; | 28 | mod helpers; |
| 34 | mod chunk_a; | 29 | mod chunk_a; |
| 35 | mod chunk_b; | 30 | mod chunk_b; |
crates/ec-ac3/Cargo.tomlmodified+3 -0
| @@ -9,3 +9,6 @@ authors.workspace = true | |||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | ec-core.workspace = true | 10 | ec-core.workspace = true |
| 11 | ec-dsp.workspace = true | 11 | ec-dsp.workspace = true |
| 12 | + | ||
| 13 | +[dev-dependencies] | ||
| 14 | +ec-testkit.workspace = true | ||
crates/ec-ac3/fuzz/seed.shmodified+2 -2
| @@ -11,8 +11,8 @@ | |||
| 11 | set -euo pipefail | 11 | set -euo pipefail |
| 12 | 12 | ||
| 13 | FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd) | 13 | FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd) |
| 14 | -FIXTURES=$(cd -- "$FUZZ_DIR/../../.." && pwd)/fixtures/audio | 14 | +FIXTURES=${EC_FIXTURES:-$(cd -- "$FUZZ_DIR/../../.." && pwd)/fixtures}/audio |
| 15 | -[ -d "$FIXTURES" ] || { echo "seed.sh: $FIXTURES missing; run scripts/link-fixtures.sh" >&2; exit 2; } | 15 | +[ -d "$FIXTURES" ] || { echo "seed.sh: $FIXTURES missing; run scripts/fixtures.sh" >&2; exit 2; } |
| 16 | 16 | ||
| 17 | FILES=("$FIXTURES"/ac3-*.ac3 "$FIXTURES"/eac3-*.eac3 "$FIXTURES"/ac3dep-*.eac3) | 17 | FILES=("$FIXTURES"/ac3-*.ac3 "$FIXTURES"/eac3-*.eac3 "$FIXTURES"/ac3dep-*.eac3) |
| 18 | [ -e "${FILES[0]}" ] || { echo "seed.sh: no ac3-*.ac3 or eac3-*.eac3 fixtures in $FIXTURES" >&2; exit 2; } | 18 | [ -e "${FILES[0]}" ] || { echo "seed.sh: no ac3-*.ac3 or eac3-*.eac3 fixtures in $FIXTURES" >&2; exit 2; } |
crates/ec-ac3/tests/it/common.rsdeleted+0 -9
| @@ -1,9 +0,0 @@ | |||
| 1 | -use std::process::Command; | ||
| 2 | - | ||
| 3 | -/// Whether `ffmpeg -version` runs successfully. | ||
| 4 | -pub fn have_ffmpeg() -> bool { | ||
| 5 | - Command::new("ffmpeg") | ||
| 6 | - .arg("-version") | ||
| 7 | - .output() | ||
| 8 | - .is_ok_and(|o| o.status.success()) | ||
| 9 | -} | ||
crates/ec-ac3/tests/it/decode_matrix.rsmodified+13 -53
| @@ -2,16 +2,12 @@ | |||
| 2 | //! compared against ffmpeg, plus the header surface a container reads and the | 2 | //! compared against ffmpeg, plus the header surface a container reads and the |
| 3 | //! no-panic contract on damaged input. | 3 | //! no-panic contract on damaged input. |
| 4 | //! | 4 | //! |
| 5 | -//! ffmpeg is test tooling — it is driven through `std::process` so the crate | 5 | +//! ffmpeg is test tooling, driven through `ec_testkit::ffmpeg()`. A missing |
| 6 | -//! itself never gains a media dependency. Missing fixtures or a missing ffmpeg | 6 | +//! fixture or ffmpeg fails the test. |
| 7 | -//! skip the comparison rather than fail it; `scripts/gen-fixtures.sh` writes | ||
| 8 | -//! the fixtures. | ||
| 9 | 7 | ||
| 10 | -use std::path::{Path, PathBuf}; | 8 | +use std::path::Path; |
| 11 | -use std::process::Command; | ||
| 12 | 9 | ||
| 13 | use ec_ac3::{Ac3Decoder, Downmix, Options, Syntax, bsi, eac3, syncinfo}; | 10 | use ec_ac3::{Ac3Decoder, Downmix, Options, Syntax, bsi, eac3, syncinfo}; |
| 14 | -use crate::common::have_ffmpeg; | ||
| 15 | 11 | ||
| 16 | /// Per-channel correlation floor (rubric: audio-ac3 MUST). | 12 | /// Per-channel correlation floor (rubric: audio-ac3 MUST). |
| 17 | const MIN_CORR: f64 = 0.999; | 13 | const MIN_CORR: f64 = 0.999; |
| @@ -19,16 +15,9 @@ const MIN_CORR: f64 = 0.999; | |||
| 19 | /// synthetic material. | 15 | /// synthetic material. |
| 20 | const MAX_RMS: f64 = 1e-3; | 16 | const MAX_RMS: f64 = 1e-3; |
| 21 | 17 | ||
| 22 | -fn fixtures() -> PathBuf { | ||
| 23 | - Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 24 | - .join("../../fixtures/audio") | ||
| 25 | - .canonicalize() | ||
| 26 | - .unwrap_or_else(|_| PathBuf::from("../../fixtures/audio")) | ||
| 27 | -} | ||
| 28 | - | ||
| 29 | /// ffmpeg's decode of `path` as interleaved `f32`. | 18 | /// ffmpeg's decode of `path` as interleaved `f32`. |
| 30 | fn reference(path: &Path) -> Vec<f32> { | 19 | fn reference(path: &Path) -> Vec<f32> { |
| 31 | - let out = Command::new("ffmpeg") | 20 | + let out = ec_testkit::ffmpeg() |
| 32 | .args(["-v", "error", "-i"]) | 21 | .args(["-v", "error", "-i"]) |
| 33 | .arg(path) | 22 | .arg(path) |
| 34 | .args(["-f", "f32le", "-"]) | 23 | .args(["-f", "f32le", "-"]) |
| @@ -96,13 +85,8 @@ fn correlation(a: &[f32], b: &[f32]) -> (f64, f64) { | |||
| 96 | 85 | ||
| 97 | #[test] | 86 | #[test] |
| 98 | fn fixture_matrix_matches_ffmpeg() { | 87 | fn fixture_matrix_matches_ffmpeg() { |
| 99 | - let dir = fixtures(); | ||
| 100 | - if !dir.exists() || !have_ffmpeg() { | ||
| 101 | - eprintln!("skipping: no fixtures or no ffmpeg"); | ||
| 102 | - return; | ||
| 103 | - } | ||
| 104 | let mut checked = 0; | 88 | let mut checked = 0; |
| 105 | - for entry in std::fs::read_dir(&dir).expect("fixtures dir") { | 89 | + for entry in std::fs::read_dir(ec_testkit::root().join("audio")).expect("audio fixtures") { |
| 106 | let path = entry.expect("entry").path(); | 90 | let path = entry.expect("entry").path(); |
| 107 | let name = path.file_name().unwrap_or_default().to_string_lossy(); | 91 | let name = path.file_name().unwrap_or_default().to_string_lossy(); |
| 108 | if !(name.starts_with("ac3-") || name.starts_with("eac3-")) { | 92 | if !(name.starts_with("ac3-") || name.starts_with("eac3-")) { |
| @@ -140,10 +124,7 @@ fn fixture_matrix_matches_ffmpeg() { | |||
| 140 | 124 | ||
| 141 | #[test] | 125 | #[test] |
| 142 | fn dither_only_adds_noise_below_the_signal() { | 126 | fn dither_only_adds_noise_below_the_signal() { |
| 143 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 127 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 144 | - if !path.exists() { | ||
| 145 | - return; | ||
| 146 | - } | ||
| 147 | let (with, channels) = decode(&path, Options::default()); | 128 | let (with, channels) = decode(&path, Options::default()); |
| 148 | let (without, _) = decode( | 129 | let (without, _) = decode( |
| 149 | &path, | 130 | &path, |
| @@ -160,10 +141,7 @@ fn dither_only_adds_noise_below_the_signal() { | |||
| 160 | 141 | ||
| 161 | #[test] | 142 | #[test] |
| 162 | fn headers_state_what_the_container_needs() { | 143 | fn headers_state_what_the_container_needs() { |
| 163 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 144 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 164 | - if !path.exists() { | ||
| 165 | - return; | ||
| 166 | - } | ||
| 167 | let data = std::fs::read(&path).expect("fixture"); | 145 | let data = std::fs::read(&path).expect("fixture"); |
| 168 | // The exact call shape a container makes: syncinfo from the frame start, | 146 | // The exact call shape a container makes: syncinfo from the frame start, |
| 169 | // bsi from five bytes in. | 147 | // bsi from five bytes in. |
| @@ -176,7 +154,7 @@ fn headers_state_what_the_container_needs() { | |||
| 176 | assert_eq!(bsi.channels, 6); | 154 | assert_eq!(bsi.channels, 6); |
| 177 | assert!((1..=31).contains(&bsi.dialnorm)); | 155 | assert!((1..=31).contains(&bsi.dialnorm)); |
| 178 | 156 | ||
| 179 | - let eac3_path = fixtures().join("eac3-5.1-48000.eac3"); | 157 | + let eac3_path = ec_testkit::fixture("audio/eac3-5.1-48000.eac3"); |
| 180 | let data = std::fs::read(&eac3_path).expect("fixture"); | 158 | let data = std::fs::read(&eac3_path).expect("fixture"); |
| 181 | let hdr = eac3::bsi::parse(&data[2..]).expect("eac3 bsi"); | 159 | let hdr = eac3::bsi::parse(&data[2..]).expect("eac3 bsi"); |
| 182 | assert_eq!(hdr.sample_rate, 48_000); | 160 | assert_eq!(hdr.sample_rate, 48_000); |
| @@ -190,10 +168,7 @@ fn headers_state_what_the_container_needs() { | |||
| 190 | 168 | ||
| 191 | #[test] | 169 | #[test] |
| 192 | fn frame_info_surfaces_the_metadata_the_rubric_asks_for() { | 170 | fn frame_info_surfaces_the_metadata_the_rubric_asks_for() { |
| 193 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 171 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 194 | - if !path.exists() { | ||
| 195 | - return; | ||
| 196 | - } | ||
| 197 | let data = std::fs::read(&path).expect("fixture"); | 172 | let data = std::fs::read(&path).expect("fixture"); |
| 198 | let size = ec_ac3::frame_size(&data).expect("frame size"); | 173 | let size = ec_ac3::frame_size(&data).expect("frame size"); |
| 199 | let mut decoder = Ac3Decoder::new(); | 174 | let mut decoder = Ac3Decoder::new(); |
| @@ -210,10 +185,7 @@ fn frame_info_surfaces_the_metadata_the_rubric_asks_for() { | |||
| 210 | 185 | ||
| 211 | #[test] | 186 | #[test] |
| 212 | fn stereo_downmix_folds_five_one_without_clipping() { | 187 | fn stereo_downmix_folds_five_one_without_clipping() { |
| 213 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 188 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 214 | - if !path.exists() { | ||
| 215 | - return; | ||
| 216 | - } | ||
| 217 | let (stereo, channels) = decode( | 189 | let (stereo, channels) = decode( |
| 218 | &path, | 190 | &path, |
| 219 | Options { | 191 | Options { |
| @@ -240,10 +212,7 @@ fn stereo_downmix_folds_five_one_without_clipping() { | |||
| 240 | 212 | ||
| 241 | #[test] | 213 | #[test] |
| 242 | fn damaged_input_never_panics() { | 214 | fn damaged_input_never_panics() { |
| 243 | - let path = fixtures().join("ac3-stereo-48000.ac3"); | 215 | + let path = ec_testkit::fixture("audio/ac3-stereo-48000.ac3"); |
| 244 | - if !path.exists() { | ||
| 245 | - return; | ||
| 246 | - } | ||
| 247 | let data = std::fs::read(&path).expect("fixture"); | 216 | let data = std::fs::read(&path).expect("fixture"); |
| 248 | let size = ec_ac3::frame_size(&data).expect("frame size"); | 217 | let size = ec_ac3::frame_size(&data).expect("frame size"); |
| 249 | let frame = &data[..size]; | 218 | let frame = &data[..size]; |
| @@ -281,13 +250,8 @@ fn damaged_input_never_panics() { | |||
| 281 | /// answers the same way for an AC-3 tail. | 250 | /// answers the same way for an AC-3 tail. |
| 282 | #[test] | 251 | #[test] |
| 283 | fn a_concatenated_tail_is_refused_by_name_not_dropped() { | 252 | fn a_concatenated_tail_is_refused_by_name_not_dropped() { |
| 284 | - let dir = fixtures(); | ||
| 285 | - if !dir.join("eac3-5.1-48000.eac3").exists() { | ||
| 286 | - eprintln!("skipping: no fixtures"); | ||
| 287 | - return; | ||
| 288 | - } | ||
| 289 | for name in ["ac3-5.1-48000.ac3", "eac3-5.1-48000.eac3"] { | 253 | for name in ["ac3-5.1-48000.ac3", "eac3-5.1-48000.eac3"] { |
| 290 | - let data = std::fs::read(dir.join(name)).expect("fixture"); | 254 | + let data = std::fs::read(ec_testkit::fixture(&format!("audio/{name}"))).expect("fixture"); |
| 291 | let first = ec_ac3::frame_size(&data).expect("first frame size"); | 255 | let first = ec_ac3::frame_size(&data).expect("first frame size"); |
| 292 | let second = ec_ac3::frame_size(&data[first..]).expect("second frame size"); | 256 | let second = ec_ac3::frame_size(&data[first..]).expect("second frame size"); |
| 293 | let mut packet = data[..first].to_vec(); | 257 | let mut packet = data[..first].to_vec(); |
| @@ -328,11 +292,7 @@ fn a_concatenated_tail_is_refused_by_name_not_dropped() { | |||
| 328 | /// frame — sample for sample, whatever its length. | 292 | /// frame — sample for sample, whatever its length. |
| 329 | #[test] | 293 | #[test] |
| 330 | fn padding_that_is_not_a_syncframe_still_decodes() { | 294 | fn padding_that_is_not_a_syncframe_still_decodes() { |
| 331 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 295 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 332 | - if !path.exists() { | ||
| 333 | - eprintln!("skipping: no fixtures"); | ||
| 334 | - return; | ||
| 335 | - } | ||
| 336 | let data = std::fs::read(&path).expect("fixture"); | 296 | let data = std::fs::read(&path).expect("fixture"); |
| 337 | let first = ec_ac3::frame_size(&data).expect("frame size"); | 297 | let first = ec_ac3::frame_size(&data).expect("frame size"); |
| 338 | let frame = &data[..first]; | 298 | let frame = &data[..first]; |
crates/ec-ac3/tests/it/dependent.rsmodified+11 -77
| @@ -2,12 +2,9 @@ | |||
| 2 | //! spliced stream: its channel placement (the replace-or-add rule of Table E2.5) | 2 | //! spliced stream: its channel placement (the replace-or-add rule of Table E2.5) |
| 3 | //! and its channel order, which ffprobe names in `channel_layout`. | 3 | //! and its channel order, which ffprobe names in `channel_layout`. |
| 4 | //! | 4 | //! |
| 5 | -//! The fixtures come from `scripts/gen-ac3dep-fixtures.sh`. Missing fixtures or | 5 | +//! A missing fixture or ffmpeg fails the test. |
| 6 | -//! a missing ffmpeg skip the comparison, as in `decode_matrix.rs`, unless | ||
| 7 | -//! `EC_REQUIRE_FIXTURES=1`, which makes an absent fixture a failure. | ||
| 8 | 6 | ||
| 9 | -use std::path::{Path, PathBuf}; | 7 | +use std::path::Path; |
| 10 | -use std::process::Command; | ||
| 11 | 8 | ||
| 12 | use ec_ac3::{Ac3Decoder, Error, Options, eac3, frame_size}; | 9 | use ec_ac3::{Ac3Decoder, Error, Options, eac3, frame_size}; |
| 13 | use ec_core::{ChannelLayout, ChannelPosition}; | 10 | use ec_core::{ChannelLayout, ChannelPosition}; |
| @@ -16,48 +13,9 @@ use ec_core::{ChannelLayout, ChannelPosition}; | |||
| 16 | const MIN_CORR: f64 = 0.999; | 13 | const MIN_CORR: f64 = 0.999; |
| 17 | const MAX_RMS: f64 = 1e-3; | 14 | const MAX_RMS: f64 = 1e-3; |
| 18 | 15 | ||
| 19 | -fn fixtures() -> PathBuf { | ||
| 20 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -/// Whether every path is present. A missing one skips the test, or fails it | ||
| 24 | -/// under `EC_REQUIRE_FIXTURES=1`. | ||
| 25 | -fn present(name: &str, paths: &[PathBuf]) -> bool { | ||
| 26 | - let missing: Vec<_> = paths.iter().filter(|p| !p.exists()).collect(); | ||
| 27 | - if missing.is_empty() { | ||
| 28 | - return true; | ||
| 29 | - } | ||
| 30 | - assert!( | ||
| 31 | - std::env::var("EC_REQUIRE_FIXTURES").as_deref() != Ok("1"), | ||
| 32 | - "{name}: fixture missing: {missing:?}" | ||
| 33 | - ); | ||
| 34 | - eprintln!("skipping {name}: fixture missing: {missing:?}"); | ||
| 35 | - false | ||
| 36 | -} | ||
| 37 | - | ||
| 38 | -/// Whether ffmpeg and ffprobe run. Missing tools skip, or fail under | ||
| 39 | -/// `EC_REQUIRE_FIXTURES=1`. | ||
| 40 | -fn have_ffmpeg(name: &str) -> bool { | ||
| 41 | - let ok = |tool: &str| { | ||
| 42 | - Command::new(tool) | ||
| 43 | - .arg("-version") | ||
| 44 | - .output() | ||
| 45 | - .is_ok_and(|o| o.status.success()) | ||
| 46 | - }; | ||
| 47 | - if ok("ffmpeg") && ok("ffprobe") { | ||
| 48 | - return true; | ||
| 49 | - } | ||
| 50 | - assert!( | ||
| 51 | - std::env::var("EC_REQUIRE_FIXTURES").as_deref() != Ok("1"), | ||
| 52 | - "{name}: ffmpeg and ffprobe are required" | ||
| 53 | - ); | ||
| 54 | - eprintln!("skipping {name}: ffmpeg or ffprobe missing"); | ||
| 55 | - false | ||
| 56 | -} | ||
| 57 | - | ||
| 58 | /// ffprobe's `channel_layout` name for the first audio stream of `path`. | 16 | /// ffprobe's `channel_layout` name for the first audio stream of `path`. |
| 59 | fn ffprobe_layout(path: &Path) -> String { | 17 | fn ffprobe_layout(path: &Path) -> String { |
| 60 | - let out = Command::new("ffprobe") | 18 | + let out = ec_testkit::ffprobe() |
| 61 | .args(["-v", "error", "-f", "eac3", "-select_streams", "a:0"]) | 19 | .args(["-v", "error", "-f", "eac3", "-select_streams", "a:0"]) |
| 62 | .args(["-show_entries", "stream=channel_layout", "-of", "csv=p=0"]) | 20 | .args(["-show_entries", "stream=channel_layout", "-of", "csv=p=0"]) |
| 63 | .arg(path) | 21 | .arg(path) |
| @@ -68,7 +26,7 @@ fn ffprobe_layout(path: &Path) -> String { | |||
| 68 | 26 | ||
| 69 | /// ffmpeg's decode of `path` as interleaved `f32`, in ffmpeg's channel order. | 27 | /// ffmpeg's decode of `path` as interleaved `f32`, in ffmpeg's channel order. |
| 70 | fn reference(path: &Path, channels: usize) -> Vec<Vec<f32>> { | 28 | fn reference(path: &Path, channels: usize) -> Vec<Vec<f32>> { |
| 71 | - let out = Command::new("ffmpeg") | 29 | + let out = ec_testkit::ffmpeg() |
| 72 | .args(["-v", "error", "-f", "eac3", "-i"]) | 30 | .args(["-v", "error", "-f", "eac3", "-i"]) |
| 73 | .arg(path) | 31 | .arg(path) |
| 74 | .args(["-f", "f32le", "-"]) | 32 | .args(["-f", "f32le", "-"]) |
| @@ -170,15 +128,8 @@ fn correlation(a: &[f32], b: &[f32]) -> (f64, f64, f64) { | |||
| 170 | /// repeats the dependent's left channel. The core decode is ffmpeg's own | 128 | /// repeats the dependent's left channel. The core decode is ffmpeg's own |
| 171 | /// unchanged 5.1 path, so it is the reference that ffmpeg itself gets right. | 129 | /// unchanged 5.1 path, so it is the reference that ffmpeg itself gets right. |
| 172 | fn check_against_ffmpeg(name: &str, ffprobe_name: &str, layout: &ChannelLayout, side_from_core: bool) { | 130 | fn check_against_ffmpeg(name: &str, ffprobe_name: &str, layout: &ChannelLayout, side_from_core: bool) { |
| 173 | - let stream = fixtures().join(name); | 131 | + let stream = ec_testkit::fixture(&format!("audio/{name}")); |
| 174 | - let core = fixtures().join("ac3dep-src-5.1.eac3"); | 132 | + let core_side = side_from_core.then(|| reference(&ec_testkit::fixture("audio/ac3dep-src-5.1.eac3"), 6)); |
| 175 | - let mut paths = vec![stream.clone()]; | ||
| 176 | - if side_from_core { | ||
| 177 | - paths.push(core.clone()); | ||
| 178 | - } | ||
| 179 | - if !present(name, &paths) || !have_ffmpeg(name) { | ||
| 180 | - return; | ||
| 181 | - } | ||
| 182 | assert_eq!(ffprobe_layout(&stream), ffprobe_name, "{name}: ffprobe channel_layout"); | 133 | assert_eq!(ffprobe_layout(&stream), ffprobe_name, "{name}: ffprobe channel_layout"); |
| 183 | let data = std::fs::read(&stream).expect("fixture"); | 134 | let data = std::fs::read(&stream).expect("fixture"); |
| 184 | let (ours, channels, ours_layout) = decode(&data); | 135 | let (ours, channels, ours_layout) = decode(&data); |
| @@ -186,7 +137,6 @@ fn check_against_ffmpeg(name: &str, ffprobe_name: &str, layout: &ChannelLayout, | |||
| 186 | assert_eq!(channels, layout.channel_count(), "{name}: channels"); | 137 | assert_eq!(channels, layout.channel_count(), "{name}: channels"); |
| 187 | 138 | ||
| 188 | let theirs = reference(&stream, channels); | 139 | let theirs = reference(&stream, channels); |
| 189 | - let core_side = side_from_core.then(|| reference(&core, 6)); | ||
| 190 | let frames = ours.len() / channels; | 140 | let frames = ours.len() / channels; |
| 191 | assert_eq!(frames, theirs[0].len(), "{name}: frame count vs ffmpeg"); | 141 | assert_eq!(frames, theirs[0].len(), "{name}: frame count vs ffmpeg"); |
| 192 | 142 | ||
| @@ -246,12 +196,8 @@ fn side_pair_replacement_carries_the_dependent_signal() { | |||
| 246 | // The replaced pair is the dependent stereo source (880 Hz and 1320 Hz | 196 | // The replaced pair is the dependent stereo source (880 Hz and 1320 Hz |
| 247 | // sines), not the core's: compare the side channels with ffmpeg's decode | 197 | // sines), not the core's: compare the side channels with ffmpeg's decode |
| 248 | // of that source on its own. | 198 | // of that source on its own. |
| 249 | - let dir = fixtures(); | 199 | + let repl = ec_testkit::fixture("audio/ac3dep-repl-48000.eac3"); |
| 250 | - let repl = dir.join("ac3dep-repl-48000.eac3"); | 200 | + let src20 = ec_testkit::fixture("audio/ac3dep-src-2.0.eac3"); |
| 251 | - let src20 = dir.join("ac3dep-src-2.0.eac3"); | ||
| 252 | - if !present("ac3dep-repl-48000.eac3", &[repl.clone(), src20.clone()]) || !have_ffmpeg("replacement signal") { | ||
| 253 | - return; | ||
| 254 | - } | ||
| 255 | let data = std::fs::read(&repl).expect("fixture"); | 201 | let data = std::fs::read(&repl).expect("fixture"); |
| 256 | let (ours, channels, _) = decode(&data); | 202 | let (ours, channels, _) = decode(&data); |
| 257 | assert_eq!(channels, 6, "replacement keeps the 5.1 channel count"); | 203 | assert_eq!(channels, 6, "replacement keeps the 5.1 channel count"); |
| @@ -266,11 +212,7 @@ fn side_pair_replacement_carries_the_dependent_signal() { | |||
| 266 | 212 | ||
| 267 | #[test] | 213 | #[test] |
| 268 | fn dependent_without_an_independent_is_named_not_decoded() { | 214 | fn dependent_without_an_independent_is_named_not_decoded() { |
| 269 | - let dir = fixtures(); | 215 | + let stream = ec_testkit::fixture("audio/ac3dep-7.1-48000.eac3"); |
| 270 | - let stream = dir.join("ac3dep-7.1-48000.eac3"); | ||
| 271 | - if !present("ac3dep-7.1-48000.eac3", std::slice::from_ref(&stream)) { | ||
| 272 | - return; | ||
| 273 | - } | ||
| 274 | let data = std::fs::read(&stream).expect("fixture"); | 216 | let data = std::fs::read(&stream).expect("fixture"); |
| 275 | let packet = packets(&data)[0]; | 217 | let packet = packets(&data)[0]; |
| 276 | // The dependent frame alone, as a first substream. | 218 | // The dependent frame alone, as a first substream. |
| @@ -285,11 +227,7 @@ fn dependent_without_an_independent_is_named_not_decoded() { | |||
| 285 | 227 | ||
| 286 | #[test] | 228 | #[test] |
| 287 | fn truncated_dependent_substream_is_an_error_not_a_panic() { | 229 | fn truncated_dependent_substream_is_an_error_not_a_panic() { |
| 288 | - let dir = fixtures(); | 230 | + let stream = ec_testkit::fixture("audio/ac3dep-7.1-48000.eac3"); |
| 289 | - let stream = dir.join("ac3dep-7.1-48000.eac3"); | ||
| 290 | - if !present("ac3dep-7.1-48000.eac3", std::slice::from_ref(&stream)) { | ||
| 291 | - return; | ||
| 292 | - } | ||
| 293 | let data = std::fs::read(&stream).expect("fixture"); | 231 | let data = std::fs::read(&stream).expect("fixture"); |
| 294 | let packet = packets(&data)[0]; | 232 | let packet = packets(&data)[0]; |
| 295 | for cut in [1, 2, 8, 100, 500] { | 233 | for cut in [1, 2, 8, 100, 500] { |
| @@ -300,11 +238,7 @@ fn truncated_dependent_substream_is_an_error_not_a_panic() { | |||
| 300 | 238 | ||
| 301 | #[test] | 239 | #[test] |
| 302 | fn a_second_independent_substream_in_the_packet_is_still_refused() { | 240 | fn a_second_independent_substream_in_the_packet_is_still_refused() { |
| 303 | - let dir = fixtures(); | 241 | + let src20 = ec_testkit::fixture("audio/ac3dep-src-2.0.eac3"); |
| 304 | - let src20 = dir.join("ac3dep-src-2.0.eac3"); | ||
| 305 | - if !present("ac3dep-src-2.0.eac3", std::slice::from_ref(&src20)) { | ||
| 306 | - return; | ||
| 307 | - } | ||
| 308 | let data = std::fs::read(&src20).expect("fixture"); | 242 | let data = std::fs::read(&src20).expect("fixture"); |
| 309 | let first = packets(&data)[0]; | 243 | let first = packets(&data)[0]; |
| 310 | let mut two = first.to_vec(); | 244 | let mut two = first.to_vec(); |
crates/ec-ac3/tests/it/encode_matrix.rsmodified+26 -43
| @@ -1,13 +1,11 @@ | |||
| 1 | //! Encoder coverage: frames our own decoder round-trips, and that ffmpeg | 1 | //! Encoder coverage: frames our own decoder round-trips, and that ffmpeg |
| 2 | -//! (when present) accepts as valid AC-3 and decodes to the same audio — on | 2 | +//! accepts as valid AC-3 and decodes to the same audio — on |
| 3 | //! synthetic signals and on the real 16-bit fixtures, at every rate and | 3 | //! synthetic signals and on the real 16-bit fixtures, at every rate and |
| 4 | //! layout the encoder offers. | 4 | //! layout the encoder offers. |
| 5 | 5 | ||
| 6 | use std::path::Path; | 6 | use std::path::Path; |
| 7 | -use std::process::Command; | ||
| 8 | 7 | ||
| 9 | use ec_ac3::{Ac3Decoder, Ac3Encoder, EncoderConfig}; | 8 | use ec_ac3::{Ac3Decoder, Ac3Encoder, EncoderConfig}; |
| 10 | -use crate::common::have_ffmpeg; | ||
| 11 | 9 | ||
| 12 | /// 440 Hz tone for 1 s, then 0.5 s of silence, interleaved across `channels`. | 10 | /// 440 Hz tone for 1 s, then 0.5 s of silence, interleaved across `channels`. |
| 13 | fn tone_then_silence(sample_rate: u32, channels: usize) -> Vec<f32> { | 11 | fn tone_then_silence(sample_rate: u32, channels: usize) -> Vec<f32> { |
| @@ -80,18 +78,15 @@ fn take_channel(interleaved: &[f32], channels: usize, ch: usize) -> Vec<f32> { | |||
| 80 | .collect() | 78 | .collect() |
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | -/// The fixture's PCM decoded by ffmpeg, with its rate and channel count; None | 81 | +/// The fixture's PCM decoded by ffmpeg, with its rate and channel count. |
| 84 | -/// without ffmpeg. | 82 | +fn read_wav(path: &Path) -> (Vec<f32>, u32, usize) { |
| 85 | -fn read_wav(path: &Path) -> Option<(Vec<f32>, u32, usize)> { | 83 | + let out = ec_testkit::ffmpeg() |
| 86 | - let out = Command::new("ffmpeg") | ||
| 87 | .args(["-v", "error", "-i"]) | 84 | .args(["-v", "error", "-i"]) |
| 88 | .arg(path) | 85 | .arg(path) |
| 89 | .args(["-f", "f32le", "-"]) | 86 | .args(["-f", "f32le", "-"]) |
| 90 | .output() | 87 | .output() |
| 91 | - .ok()?; | 88 | + .expect("ffmpeg"); |
| 92 | - if !out.status.success() { | 89 | + assert!(out.status.success(), "ffmpeg cannot read {}", path.display()); |
| 93 | - return None; | ||
| 94 | - } | ||
| 95 | let samples = out | 90 | let samples = out |
| 96 | .stdout | 91 | .stdout |
| 97 | .as_chunks::<4>().0.iter() | 92 | .as_chunks::<4>().0.iter() |
| @@ -99,11 +94,11 @@ fn read_wav(path: &Path) -> Option<(Vec<f32>, u32, usize)> { | |||
| 99 | .collect(); | 94 | .collect(); |
| 100 | let probe = ffprobe(path, "channels,sample_rate"); | 95 | let probe = ffprobe(path, "channels,sample_rate"); |
| 101 | let field = |key: &str| probe_field(&probe, key).and_then(|v| v.parse::<u32>().ok()); | 96 | let field = |key: &str| probe_field(&probe, key).and_then(|v| v.parse::<u32>().ok()); |
| 102 | - Some((samples, field("sample_rate")?, field("channels")? as usize)) | 97 | + (samples, field("sample_rate").unwrap(), field("channels").unwrap() as usize) |
| 103 | } | 98 | } |
| 104 | 99 | ||
| 105 | fn ffprobe(path: &Path, entries: &str) -> String { | 100 | fn ffprobe(path: &Path, entries: &str) -> String { |
| 106 | - let out = Command::new("ffprobe") | 101 | + let out = ec_testkit::ffprobe() |
| 107 | .args(["-v", "error", "-select_streams", "a:0", "-show_entries"]) | 102 | .args(["-v", "error", "-select_streams", "a:0", "-show_entries"]) |
| 108 | .arg(format!("stream={entries}")) | 103 | .arg(format!("stream={entries}")) |
| 109 | .args(["-of", "default=noprint_wrappers=1"]) | 104 | .args(["-of", "default=noprint_wrappers=1"]) |
| @@ -121,7 +116,7 @@ fn probe_field(text: &str, key: &str) -> Option<String> { | |||
| 121 | 116 | ||
| 122 | /// ffmpeg's decode of an AC-3 file, asserting it voiced no complaint. | 117 | /// ffmpeg's decode of an AC-3 file, asserting it voiced no complaint. |
| 123 | fn oracle_decode(path: &Path) -> Vec<f32> { | 118 | fn oracle_decode(path: &Path) -> Vec<f32> { |
| 124 | - let out = Command::new("ffmpeg") | 119 | + let out = ec_testkit::ffmpeg() |
| 125 | .args(["-v", "warning", "-i"]) | 120 | .args(["-v", "warning", "-i"]) |
| 126 | .arg(path) | 121 | .arg(path) |
| 127 | .args(["-f", "f32le", "-"]) | 122 | .args(["-f", "f32le", "-"]) |
| @@ -227,10 +222,6 @@ fn silence_and_tone_frames_decode_in_our_decoder() { | |||
| 227 | 222 | ||
| 228 | #[test] | 223 | #[test] |
| 229 | fn oracle_accepts_our_frames() { | 224 | fn oracle_accepts_our_frames() { |
| 230 | - if !have_ffmpeg() { | ||
| 231 | - eprintln!("skipping: ffmpeg not found"); | ||
| 232 | - return; | ||
| 233 | - } | ||
| 234 | let config = EncoderConfig { | 225 | let config = EncoderConfig { |
| 235 | sample_rate: 48_000, | 226 | sample_rate: 48_000, |
| 236 | channels: 2, | 227 | channels: 2, |
| @@ -242,7 +233,7 @@ fn oracle_accepts_our_frames() { | |||
| 242 | let path = dir.join("ec_ac3_encode_matrix_oracle.ac3"); | 233 | let path = dir.join("ec_ac3_encode_matrix_oracle.ac3"); |
| 243 | std::fs::write(&path, &data).unwrap(); | 234 | std::fs::write(&path, &data).unwrap(); |
| 244 | 235 | ||
| 245 | - let out = Command::new("ffmpeg") | 236 | + let out = ec_testkit::ffmpeg() |
| 246 | .args(["-v", "warning", "-i"]) | 237 | .args(["-v", "warning", "-i"]) |
| 247 | .arg(&path) | 238 | .arg(&path) |
| 248 | .args(["-f", "f32le", "-"]) | 239 | .args(["-f", "f32le", "-"]) |
| @@ -278,16 +269,12 @@ fn oracle_accepts_our_frames() { | |||
| 278 | /// asked for. Prints the per-file numbers and the stereo strategy shares. | 269 | /// asked for. Prints the per-file numbers and the stereo strategy shares. |
| 279 | #[test] | 270 | #[test] |
| 280 | fn real_fixtures_round_trip_through_our_decoder_and_the_oracle() { | 271 | fn real_fixtures_round_trip_through_our_decoder_and_the_oracle() { |
| 281 | - if !have_ffmpeg() { | 272 | + let root = ec_testkit::root().join("audio"); |
| 282 | - eprintln!("skipping: ffmpeg not found"); | ||
| 283 | - return; | ||
| 284 | - } | ||
| 285 | - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio"); | ||
| 286 | let mut failures = Vec::new(); | 273 | let mut failures = Vec::new(); |
| 287 | for layout in ["mono", "stereo", "5.1"] { | 274 | for layout in ["mono", "stereo", "5.1"] { |
| 288 | for rate in [48_000u32, 44_100] { | 275 | for rate in [48_000u32, 44_100] { |
| 289 | let path = root.join(format!("wav16-{layout}-{rate}.wav")); | 276 | let path = root.join(format!("wav16-{layout}-{rate}.wav")); |
| 290 | - let (pcm, sample_rate, channels) = read_wav(&path).unwrap_or_else(|| panic!("{}", path.display())); | 277 | + let (pcm, sample_rate, channels) = read_wav(&path); |
| 291 | assert_eq!(sample_rate, rate); | 278 | assert_eq!(sample_rate, rate); |
| 292 | let bitrate_kbps = match channels { 1 => 96, 2 => 192, _ => 448 }; | 279 | let bitrate_kbps = match channels { 1 => 96, 2 => 192, _ => 448 }; |
| 293 | let config = EncoderConfig { sample_rate, channels: channels as u16, bitrate_kbps }; | 280 | let config = EncoderConfig { sample_rate, channels: channels as u16, bitrate_kbps }; |
| @@ -356,14 +343,12 @@ fn click_train_switches_blocks_and_still_round_trips() { | |||
| 356 | let corr = worst_corr(&pcm, &decode_all(&data, channels), channels); | 343 | let corr = worst_corr(&pcm, &decode_all(&data, channels), channels); |
| 357 | eprintln!("click train: ours {corr:.4}, {stats:?}"); | 344 | eprintln!("click train: ours {corr:.4}, {stats:?}"); |
| 358 | assert!(corr >= 0.95, "click train corr {corr}"); | 345 | assert!(corr >= 0.95, "click train corr {corr}"); |
| 359 | - if have_ffmpeg() { | 346 | + let out = std::env::temp_dir().join("ec_ac3_encode_matrix_clicks.ac3"); |
| 360 | - let out = std::env::temp_dir().join("ec_ac3_encode_matrix_clicks.ac3"); | 347 | + std::fs::write(&out, &data).unwrap(); |
| 361 | - std::fs::write(&out, &data).unwrap(); | 348 | + let corr = worst_corr(&pcm, &oracle_decode(&out), channels); |
| 362 | - let corr = worst_corr(&pcm, &oracle_decode(&out), channels); | 349 | + let _ = std::fs::remove_file(&out); |
| 363 | - let _ = std::fs::remove_file(&out); | 350 | + eprintln!("click train: oracle {corr:.4}"); |
| 364 | - eprintln!("click train: oracle {corr:.4}"); | 351 | + assert!(corr >= 0.95, "click train oracle corr {corr}"); |
| 365 | - assert!(corr >= 0.95, "click train oracle corr {corr}"); | ||
| 366 | - } | ||
| 367 | } | 352 | } |
| 368 | 353 | ||
| 369 | #[test] | 354 | #[test] |
| @@ -380,16 +365,14 @@ fn tone_at_32khz_round_trips() { | |||
| 380 | let data = encode(config, &pcm); | 365 | let data = encode(config, &pcm); |
| 381 | let corr = worst_corr(&pcm, &decode_all(&data, 2), 2); | 366 | let corr = worst_corr(&pcm, &decode_all(&data, 2), 2); |
| 382 | assert!(corr >= 0.99, "32 kHz ours corr {corr}"); | 367 | assert!(corr >= 0.99, "32 kHz ours corr {corr}"); |
| 383 | - if have_ffmpeg() { | 368 | + let out = std::env::temp_dir().join("ec_ac3_encode_matrix_32k.ac3"); |
| 384 | - let out = std::env::temp_dir().join("ec_ac3_encode_matrix_32k.ac3"); | 369 | + std::fs::write(&out, &data).unwrap(); |
| 385 | - std::fs::write(&out, &data).unwrap(); | 370 | + let corr = worst_corr(&pcm, &oracle_decode(&out), 2); |
| 386 | - let corr = worst_corr(&pcm, &oracle_decode(&out), 2); | 371 | + let probe = ffprobe(&out, "sample_rate,bit_rate"); |
| 387 | - let probe = ffprobe(&out, "sample_rate,bit_rate"); | 372 | + let _ = std::fs::remove_file(&out); |
| 388 | - let _ = std::fs::remove_file(&out); | 373 | + assert!(corr >= 0.99, "32 kHz oracle corr {corr}"); |
| 389 | - assert!(corr >= 0.99, "32 kHz oracle corr {corr}"); | 374 | + assert_eq!(probe_field(&probe, "sample_rate").as_deref(), Some("32000"), "{probe}"); |
| 390 | - assert_eq!(probe_field(&probe, "sample_rate").as_deref(), Some("32000"), "{probe}"); | 375 | + assert_eq!(probe_field(&probe, "bit_rate").as_deref(), Some("96000"), "{probe}"); |
| 391 | - assert_eq!(probe_field(&probe, "bit_rate").as_deref(), Some("96000"), "{probe}"); | ||
| 392 | - } | ||
| 393 | } | 376 | } |
| 394 | 377 | ||
| 395 | /// 200 random (rate, channels, bit rate) configurations, two frames of | 378 | /// 200 random (rate, channels, bit rate) configurations, two frames of |
crates/ec-ac3/tests/it/ffmpeg_parity.rsmodified+2 -9
| @@ -11,13 +11,10 @@ | |||
| 11 | //! with the LFE (which carries only rounding-level content here) also held to | 11 | //! with the LFE (which carries only rounding-level content here) also held to |
| 12 | //! the same correlation since it is not silent. | 12 | //! the same correlation since it is not silent. |
| 13 | //! | 13 | //! |
| 14 | -//! Needs ffmpeg on PATH; without it the test skips loudly. | ||
| 15 | 14 | ||
| 16 | use std::path::{Path, PathBuf}; | 15 | use std::path::{Path, PathBuf}; |
| 17 | -use std::process::Command; | ||
| 18 | 16 | ||
| 19 | use ec_ac3::{Ac3Decoder, Options}; | 17 | use ec_ac3::{Ac3Decoder, Options}; |
| 20 | -use crate::common::have_ffmpeg; | ||
| 21 | 18 | ||
| 22 | const MIN_CORR: f64 = 0.999; | 19 | const MIN_CORR: f64 = 0.999; |
| 23 | /// Seconds of noise per fixture. Long enough for a few hundred frames. | 20 | /// Seconds of noise per fixture. Long enough for a few hundred frames. |
| @@ -59,14 +56,14 @@ fn encode(work: &Path, name: &str, channels: usize, bitrate: &str) -> PathBuf { | |||
| 59 | "ac3".into(), | 56 | "ac3".into(), |
| 60 | ]); | 57 | ]); |
| 61 | args.push(out.display().to_string()); | 58 | args.push(out.display().to_string()); |
| 62 | - let status = Command::new("ffmpeg").args(&args).status().expect("ffmpeg"); | 59 | + let status = ec_testkit::ffmpeg().args(&args).status().expect("ffmpeg"); |
| 63 | assert!(status.success(), "ffmpeg encode of {name} failed"); | 60 | assert!(status.success(), "ffmpeg encode of {name} failed"); |
| 64 | out | 61 | out |
| 65 | } | 62 | } |
| 66 | 63 | ||
| 67 | /// ffmpeg's decode of the stream as interleaved `f32`. | 64 | /// ffmpeg's decode of the stream as interleaved `f32`. |
| 68 | fn reference(path: &Path, channels: usize) -> Vec<f32> { | 65 | fn reference(path: &Path, channels: usize) -> Vec<f32> { |
| 69 | - let out = Command::new("ffmpeg") | 66 | + let out = ec_testkit::ffmpeg() |
| 70 | .args(["-v", "error", "-nostdin", "-i"]) | 67 | .args(["-v", "error", "-nostdin", "-i"]) |
| 71 | .arg(path) | 68 | .arg(path) |
| 72 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-ac"]) | 69 | .args(["-f", "f32le", "-acodec", "pcm_f32le", "-ac"]) |
| @@ -136,10 +133,6 @@ fn correlation(ours: &[f32], theirs: &[f32], channels: usize, ch: usize) -> f64 | |||
| 136 | } | 133 | } |
| 137 | 134 | ||
| 138 | fn check(name: &str, channels: usize, bitrate: &str) { | 135 | fn check(name: &str, channels: usize, bitrate: &str) { |
| 139 | - if !have_ffmpeg() { | ||
| 140 | - eprintln!("skip {name}: ffmpeg not on PATH"); | ||
| 141 | - return; | ||
| 142 | - } | ||
| 143 | let work = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("ffmpeg-parity"); | 136 | let work = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("ffmpeg-parity"); |
| 144 | std::fs::create_dir_all(&work).expect("work dir"); | 137 | std::fs::create_dir_all(&work).expect("work dir"); |
| 145 | let stream = encode(&work, name, channels, bitrate); | 138 | let stream = encode(&work, name, channels, bitrate); |
crates/ec-ac3/tests/it/main.rsmodified+0 -1
| @@ -1,7 +1,6 @@ | |||
| 1 | //! One integration-test binary for ec-ac3; each module is one former `tests/*.rs` file. | 1 | //! One integration-test binary for ec-ac3; each module is one former `tests/*.rs` file. |
| 2 | #![forbid(unsafe_code)] | 2 | #![forbid(unsafe_code)] |
| 3 | 3 | ||
| 4 | -mod common; | ||
| 5 | mod decode_matrix; | 4 | mod decode_matrix; |
| 6 | mod dependent; | 5 | mod dependent; |
| 7 | mod encode_matrix; | 6 | mod encode_matrix; |
crates/ec-ac3/tests/it/packet_walk.rsmodified+7 -47
| @@ -5,32 +5,10 @@ | |||
| 5 | //! syncframe in the packet against one decoder state. The reference is the | 5 | //! syncframe in the packet against one decoder state. The reference is the |
| 6 | //! same bytes decoded one frame at a time on a fresh decoder, which the | 6 | //! same bytes decoded one frame at a time on a fresh decoder, which the |
| 7 | //! per-frame matrix already holds to ffmpeg, so equality here is exact. | 7 | //! per-frame matrix already holds to ffmpeg, so equality here is exact. |
| 8 | -//! | ||
| 9 | -//! Missing fixtures skip, or fail under `EC_REQUIRE_FIXTURES=1`. | ||
| 10 | - | ||
| 11 | -use std::path::{Path, PathBuf}; | ||
| 12 | 8 | ||
| 13 | use ec_ac3::{Ac3Decoder, Error, eac3, frame_size}; | 9 | use ec_ac3::{Ac3Decoder, Error, eac3, frame_size}; |
| 14 | use ec_core::{Decoder, Frame, Packet, TimeBase}; | 10 | use ec_core::{Decoder, Frame, Packet, TimeBase}; |
| 15 | 11 | ||
| 16 | -fn fixtures() -> PathBuf { | ||
| 17 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") | ||
| 18 | -} | ||
| 19 | - | ||
| 20 | -/// Whether the fixture is present. A missing one skips the test, or fails it | ||
| 21 | -/// under `EC_REQUIRE_FIXTURES=1`. | ||
| 22 | -fn present(path: &Path) -> bool { | ||
| 23 | - if path.exists() { | ||
| 24 | - return true; | ||
| 25 | - } | ||
| 26 | - assert!( | ||
| 27 | - std::env::var("EC_REQUIRE_FIXTURES").as_deref() != Ok("1"), | ||
| 28 | - "fixture missing: {path:?}" | ||
| 29 | - ); | ||
| 30 | - eprintln!("skipping: fixture missing: {path:?}"); | ||
| 31 | - false | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | /// Every syncframe of an AC-3 or E-AC-3 stream without dependent substreams. | 12 | /// Every syncframe of an AC-3 or E-AC-3 stream without dependent substreams. |
| 35 | fn frames(data: &[u8]) -> Vec<&[u8]> { | 13 | fn frames(data: &[u8]) -> Vec<&[u8]> { |
| 36 | let mut out = Vec::new(); | 14 | let mut out = Vec::new(); |
| @@ -95,10 +73,7 @@ fn decode_packet_bytes(packets: &[&[u8]]) -> (Vec<u8>, u64) { | |||
| 95 | 73 | ||
| 96 | #[test] | 74 | #[test] |
| 97 | fn ac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { | 75 | fn ac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { |
| 98 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 76 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 99 | - if !present(&path) { | ||
| 100 | - return; | ||
| 101 | - } | ||
| 102 | let data = std::fs::read(&path).expect("fixture"); | 77 | let data = std::fs::read(&path).expect("fixture"); |
| 103 | let all = frames(&data); | 78 | let all = frames(&data); |
| 104 | assert!(all.len() >= 3, "fixture has too few frames"); | 79 | assert!(all.len() >= 3, "fixture has too few frames"); |
| @@ -112,10 +87,7 @@ fn ac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { | |||
| 112 | 87 | ||
| 113 | #[test] | 88 | #[test] |
| 114 | fn eac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { | 89 | fn eac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { |
| 115 | - let path = fixtures().join("eac3-5.1-48000.eac3"); | 90 | + let path = ec_testkit::fixture("audio/eac3-5.1-48000.eac3"); |
| 116 | - if !present(&path) { | ||
| 117 | - return; | ||
| 118 | - } | ||
| 119 | let data = std::fs::read(&path).expect("fixture"); | 91 | let data = std::fs::read(&path).expect("fixture"); |
| 120 | let all = frames(&data); | 92 | let all = frames(&data); |
| 121 | assert!(all.len() >= 3, "fixture has too few frames"); | 93 | assert!(all.len() >= 3, "fixture has too few frames"); |
| @@ -130,10 +102,7 @@ fn eac3_packets_of_two_and_three_syncframes_decode_to_their_frames() { | |||
| 130 | /// that carries several (7.1 DD+ assembled as 5.1 plus a dependent). | 102 | /// that carries several (7.1 DD+ assembled as 5.1 plus a dependent). |
| 131 | #[test] | 103 | #[test] |
| 132 | fn e_ac3_dependent_packets_inside_a_multi_syncframe_packet_keep_their_channels() { | 104 | fn e_ac3_dependent_packets_inside_a_multi_syncframe_packet_keep_their_channels() { |
| 133 | - let path = fixtures().join("ac3dep-7.1-48000.eac3"); | 105 | + let path = ec_testkit::fixture("audio/ac3dep-7.1-48000.eac3"); |
| 134 | - if !present(&path) { | ||
| 135 | - return; | ||
| 136 | - } | ||
| 137 | let data = std::fs::read(&path).expect("fixture"); | 106 | let data = std::fs::read(&path).expect("fixture"); |
| 138 | let all = packets(&data); | 107 | let all = packets(&data); |
| 139 | assert!(all.len() >= 3, "fixture has too few packets"); | 108 | assert!(all.len() >= 3, "fixture has too few packets"); |
| @@ -150,10 +119,7 @@ fn e_ac3_dependent_packets_inside_a_multi_syncframe_packet_keep_their_channels() | |||
| 150 | /// bare frames. | 119 | /// bare frames. |
| 151 | #[test] | 120 | #[test] |
| 152 | fn padding_after_several_syncframes_is_ignored() { | 121 | fn padding_after_several_syncframes_is_ignored() { |
| 153 | - let path = fixtures().join("ac3-5.1-48000.ac3"); | 122 | + let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 154 | - if !present(&path) { | ||
| 155 | - return; | ||
| 156 | - } | ||
| 157 | let data = std::fs::read(&path).expect("fixture"); | 123 | let data = std::fs::read(&path).expect("fixture"); |
| 158 | let all = frames(&data); | 124 | let all = frames(&data); |
| 159 | let mut packet: Vec<u8> = all[..3].concat(); | 125 | let mut packet: Vec<u8> = all[..3].concat(); |
| @@ -166,11 +132,8 @@ fn padding_after_several_syncframes_is_ignored() { | |||
| 166 | /// A second frame of another channel layout cannot share one output frame. | 132 | /// A second frame of another channel layout cannot share one output frame. |
| 167 | #[test] | 133 | #[test] |
| 168 | fn syncframes_of_different_layouts_in_one_packet_are_refused_by_name() { | 134 | fn syncframes_of_different_layouts_in_one_packet_are_refused_by_name() { |
| 169 | - let surround = fixtures().join("ac3-5.1-48000.ac3"); | 135 | + let surround = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); |
| 170 | - let stereo = fixtures().join("ac3-stereo-48000.ac3"); | 136 | + let stereo = ec_testkit::fixture("audio/ac3-stereo-48000.ac3"); |
| 171 | - if !present(&surround) || !present(&stereo) { | ||
| 172 | - return; | ||
| 173 | - } | ||
| 174 | let a = std::fs::read(&surround).expect("fixture"); | 137 | let a = std::fs::read(&surround).expect("fixture"); |
| 175 | let b = std::fs::read(&stereo).expect("fixture"); | 138 | let b = std::fs::read(&stereo).expect("fixture"); |
| 176 | let mut packet = frames(&a)[0].to_vec(); | 139 | let mut packet = frames(&a)[0].to_vec(); |
| @@ -188,10 +151,7 @@ fn syncframes_of_different_layouts_in_one_packet_are_refused_by_name() { | |||
| 188 | /// there and decoded by the packet call. | 151 | /// there and decoded by the packet call. |
| 189 | #[test] | 152 | #[test] |
| 190 | fn decode_frame_still_takes_one_syncframe() { | 153 | fn decode_frame_still_takes_one_syncframe() { |
| 191 | - let path = fixtures().join("ac3-stereo-48000.ac3"); | 154 | + let path = ec_testkit::fixture("audio/ac3-stereo-48000.ac3"); |
| 192 | - if !present(&path) { | ||
| 193 | - return; | ||
| 194 | - } | ||
| 195 | let data = std::fs::read(&path).expect("fixture"); | 155 | let data = std::fs::read(&path).expect("fixture"); |
| 196 | let all = frames(&data); | 156 | let all = frames(&data); |
| 197 | let packet = [all[0], all[1]].concat(); | 157 | let packet = [all[0], all[1]].concat(); |
crates/ec-ac3/tests/it/real_library.rsmodified+22 -120
| @@ -1,23 +1,13 @@ | |||
| 1 | -//! AC-3 and E-AC-3 decode of the real files named in `real_library.toml`, | 1 | +//! AC-3 and E-AC-3 decode of the open FATE streams, compared against ffmpeg |
| 2 | -//! compared against ffmpeg. | 2 | +//! per channel. Every stream under `open/fate/ac3` and `open/fate/eac3` is |
| 3 | -//! | 3 | +//! decoded whole. |
| 4 | -//! Local media only: the file list is the user's `real_library.toml` (path in | ||
| 5 | -//! `EC_REAL_LIBRARY`, default `~/Documents/Code/Rust/edith/real_library.toml`). | ||
| 6 | -//! Each entry whose first audio track is `ac3` or `eac3` has its first | ||
| 7 | -//! `EC_REAL_SECONDS` seconds (default 20) of that track copied out as a raw | ||
| 8 | -//! elementary stream (`-c copy`, no re-encode), decoded by `ec-ac3` and by | ||
| 9 | -//! ffmpeg, and compared per channel. Entries that are missing on disk, or that | ||
| 10 | -//! hold no AC-3 or E-AC-3 track, are skipped loudly. Without ffmpeg the whole | ||
| 11 | -//! test skips. | ||
| 12 | //! | 4 | //! |
| 13 | //! Gate: per-channel correlation >= 0.999 (the matrix floor), and the | 5 | //! Gate: per-channel correlation >= 0.999 (the matrix floor), and the |
| 14 | //! exact-sample share and RMS delta are reported for each file. | 6 | //! exact-sample share and RMS delta are reported for each file. |
| 15 | 7 | ||
| 16 | use std::path::{Path, PathBuf}; | 8 | use std::path::{Path, PathBuf}; |
| 17 | -use std::process::Command; | ||
| 18 | 9 | ||
| 19 | use ec_ac3::{Ac3Decoder, Options}; | 10 | use ec_ac3::{Ac3Decoder, Options}; |
| 20 | -use crate::common::have_ffmpeg; | ||
| 21 | 11 | ||
| 22 | const MIN_CORR: f64 = 0.999; | 12 | const MIN_CORR: f64 = 0.999; |
| 23 | /// Reference RMS below which a channel counts as silent (-80 dBFS). | 13 | /// Reference RMS below which a channel counts as silent (-80 dBFS). |
| @@ -25,71 +15,9 @@ const SILENT_RMS: f64 = 1e-4; | |||
| 25 | /// RMS delta ceiling on a silent channel: 1/30 of a 16-bit LSB. | 15 | /// RMS delta ceiling on a silent channel: 1/30 of a 16-bit LSB. |
| 26 | const SILENT_DELTA: f64 = 1e-6; | 16 | const SILENT_DELTA: f64 = 1e-6; |
| 27 | 17 | ||
| 28 | -fn library_toml() -> PathBuf { | 18 | +/// ffmpeg's decode of the stream as interleaved `f32`. |
| 29 | - if let Ok(p) = std::env::var("EC_REAL_LIBRARY") { | ||
| 30 | - return PathBuf::from(p); | ||
| 31 | - } | ||
| 32 | - let home = std::env::var("HOME").unwrap_or_default(); | ||
| 33 | - PathBuf::from(home).join("Documents/Code/Rust/edith/real_library.toml") | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -/// `key = "path"` lines of the TOML file, as (key, path). Only the flat form | ||
| 37 | -/// the library file uses; comments and other lines are ignored. | ||
| 38 | -fn entries(toml: &Path) -> Vec<(String, PathBuf)> { | ||
| 39 | - let Ok(text) = std::fs::read_to_string(toml) else { | ||
| 40 | - return Vec::new(); | ||
| 41 | - }; | ||
| 42 | - text.lines() | ||
| 43 | - .filter_map(|line| { | ||
| 44 | - let line = line.trim(); | ||
| 45 | - if line.starts_with('#') { | ||
| 46 | - return None; | ||
| 47 | - } | ||
| 48 | - let (key, value) = line.split_once('=')?; | ||
| 49 | - let value = value.trim().strip_prefix('"')?.strip_suffix('"')?; | ||
| 50 | - Some((key.trim().to_string(), PathBuf::from(value))) | ||
| 51 | - }) | ||
| 52 | - .collect() | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -/// The codec and channel count of the file's first audio track. | ||
| 56 | -fn first_audio(path: &Path) -> Option<(String, usize)> { | ||
| 57 | - let out = Command::new("ffprobe") | ||
| 58 | - .args([ | ||
| 59 | - "-v", | ||
| 60 | - "error", | ||
| 61 | - "-select_streams", | ||
| 62 | - "a:0", | ||
| 63 | - "-show_entries", | ||
| 64 | - "stream=codec_name,channels", | ||
| 65 | - "-of", | ||
| 66 | - "csv=p=0", | ||
| 67 | - ]) | ||
| 68 | - .arg(path) | ||
| 69 | - .output() | ||
| 70 | - .ok()?; | ||
| 71 | - let text = String::from_utf8_lossy(&out.stdout); | ||
| 72 | - let mut parts = text.trim().split(','); | ||
| 73 | - Some((parts.next()?.to_string(), parts.next()?.parse().ok()?)) | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -/// Copies the first `seconds` of the first audio track to `out` as a raw | ||
| 77 | -/// elementary stream of the same codec. Returns false when that fails. | ||
| 78 | -fn extract(path: &Path, codec: &str, seconds: u32, out: &Path) -> bool { | ||
| 79 | - let muxer = if codec == "eac3" { "eac3" } else { "ac3" }; | ||
| 80 | - Command::new("ffmpeg") | ||
| 81 | - .args(["-v", "error", "-nostdin", "-y", "-i"]) | ||
| 82 | - .arg(path) | ||
| 83 | - .args(["-map", "0:a:0", "-t", &seconds.to_string(), "-c", "copy", "-f", muxer]) | ||
| 84 | - .arg(out) | ||
| 85 | - .status() | ||
| 86 | - .map(|s| s.success()) | ||
| 87 | - .unwrap_or(false) | ||
| 88 | -} | ||
| 89 | - | ||
| 90 | -/// ffmpeg's decode of the raw stream as interleaved `f32`. | ||
| 91 | fn reference(path: &Path) -> Vec<f32> { | 19 | fn reference(path: &Path) -> Vec<f32> { |
| 92 | - let out = Command::new("ffmpeg") | 20 | + let out = ec_testkit::ffmpeg() |
| 93 | .args(["-v", "error", "-nostdin", "-i"]) | 21 | .args(["-v", "error", "-nostdin", "-i"]) |
| 94 | .arg(path) | 22 | .arg(path) |
| 95 | .args(["-f", "f32le", "-"]) | 23 | .args(["-f", "f32le", "-"]) |
| @@ -103,10 +31,10 @@ fn reference(path: &Path) -> Vec<f32> { | |||
| 103 | .collect() | 31 | .collect() |
| 104 | } | 32 | } |
| 105 | 33 | ||
| 106 | -/// Our decode of the raw stream (dither off, as in the matrix test) and the | 34 | +/// Our decode of the stream (dither off, as in the matrix test) and the |
| 107 | /// channel count. | 35 | /// channel count. |
| 108 | fn decode(path: &Path) -> (Vec<f32>, usize) { | 36 | fn decode(path: &Path) -> (Vec<f32>, usize) { |
| 109 | - let data = std::fs::read(path).expect("extracted stream"); | 37 | + let data = std::fs::read(path).expect("fixture"); |
| 110 | let options = Options { | 38 | let options = Options { |
| 111 | dither: false, | 39 | dither: false, |
| 112 | ..Options::default() | 40 | ..Options::default() |
| @@ -171,41 +99,17 @@ fn compare(a: &[f32], b: &[f32]) -> (f64, f64, usize, usize) { | |||
| 171 | } | 99 | } |
| 172 | 100 | ||
| 173 | #[test] | 101 | #[test] |
| 174 | -fn real_library_ac3_and_eac3_match_ffmpeg() { | 102 | +fn fate_ac3_and_eac3_match_ffmpeg() { |
| 175 | - if !have_ffmpeg() { | 103 | + let files: Vec<PathBuf> = ec_testkit::fixtures("open/fate/ac3", "ac3") |
| 176 | - eprintln!("skip: ffmpeg not on PATH"); | 104 | + .into_iter() |
| 177 | - return; | 105 | + .chain(ec_testkit::fixtures("open/fate/eac3", "eac3")) |
| 178 | - } | 106 | + .collect(); |
| 179 | - let toml = library_toml(); | 107 | + for path in files { |
| 180 | - let seconds: u32 = std::env::var("EC_REAL_SECONDS") | 108 | + let name = path.file_name().unwrap().to_string_lossy().into_owned(); |
| 181 | - .ok() | 109 | + let (ours, decoded_channels) = decode(&path); |
| 182 | - .and_then(|s| s.parse().ok()) | 110 | + let theirs = reference(&path); |
| 183 | - .unwrap_or(20); | 111 | + assert_eq!(ours.len(), theirs.len(), "{name}: sample count vs ffmpeg"); |
| 184 | - let work = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("real-library-ac3"); | 112 | + assert!(!ours.is_empty(), "{name}: nothing decoded"); |
| 185 | - std::fs::create_dir_all(&work).expect("work dir"); | ||
| 186 | - | ||
| 187 | - let mut checked = 0; | ||
| 188 | - for (key, path) in entries(&toml) { | ||
| 189 | - if !path.exists() { | ||
| 190 | - eprintln!("skip {key}: {} not on disk", path.display()); | ||
| 191 | - continue; | ||
| 192 | - } | ||
| 193 | - let Some((codec, channels)) = first_audio(&path) else { | ||
| 194 | - eprintln!("skip {key}: ffprobe found no audio track"); | ||
| 195 | - continue; | ||
| 196 | - }; | ||
| 197 | - if codec != "ac3" && codec != "eac3" { | ||
| 198 | - eprintln!("skip {key}: first audio track is {codec}, not AC-3 or E-AC-3"); | ||
| 199 | - continue; | ||
| 200 | - } | ||
| 201 | - let raw = work.join(format!("{key}.{codec}")); | ||
| 202 | - assert!(extract(&path, &codec, seconds, &raw), "{key}: extract failed"); | ||
| 203 | - | ||
| 204 | - let (ours, decoded_channels) = decode(&raw); | ||
| 205 | - let theirs = reference(&raw); | ||
| 206 | - assert_eq!(decoded_channels, channels, "{key}: channel count"); | ||
| 207 | - assert_eq!(ours.len(), theirs.len(), "{key}: sample count vs ffmpeg"); | ||
| 208 | - assert!(!ours.is_empty(), "{key}: nothing decoded"); | ||
| 209 | 113 | ||
| 210 | let mut worst = 1.0f64; | 114 | let mut worst = 1.0f64; |
| 211 | let mut worst_rms = 0.0f64; | 115 | let mut worst_rms = 0.0f64; |
| @@ -215,7 +119,7 @@ fn real_library_ac3_and_eac3_match_ffmpeg() { | |||
| 215 | let a: Vec<f32> = ours[ch..].iter().step_by(decoded_channels).copied().collect(); | 119 | let a: Vec<f32> = ours[ch..].iter().step_by(decoded_channels).copied().collect(); |
| 216 | let b: Vec<f32> = theirs[ch..].iter().step_by(decoded_channels).copied().collect(); | 120 | let b: Vec<f32> = theirs[ch..].iter().step_by(decoded_channels).copied().collect(); |
| 217 | let (corr, rms, exact, n) = compare(&a, &b); | 121 | let (corr, rms, exact, n) = compare(&a, &b); |
| 218 | - eprintln!("{key} {codec} ch{ch}: corr {corr:.6} rms {rms:.3e} exact {exact}/{n}"); | 122 | + eprintln!("{name} ch{ch}: corr {corr:.6} rms {rms:.3e} exact {exact}/{n}"); |
| 219 | // A channel whose reference is numerically silent (an LFE that | 123 | // A channel whose reference is numerically silent (an LFE that |
| 220 | // carries nothing but rounding) has no meaningful correlation, so | 124 | // carries nothing but rounding) has no meaningful correlation, so |
| 221 | // it is gated on RMS against one 16-bit LSB / 30 instead. | 125 | // it is gated on RMS against one 16-bit LSB / 30 instead. |
| @@ -223,9 +127,9 @@ fn real_library_ac3_and_eac3_match_ffmpeg() { | |||
| 223 | / b.len().max(1) as f64) | 127 | / b.len().max(1) as f64) |
| 224 | .sqrt(); | 128 | .sqrt(); |
| 225 | if ref_rms < SILENT_RMS { | 129 | if ref_rms < SILENT_RMS { |
| 226 | - assert!(rms <= SILENT_DELTA, "{key} ch{ch}: silent-channel RMS delta {rms:.3e}"); | 130 | + assert!(rms <= SILENT_DELTA, "{name} ch{ch}: silent-channel RMS delta {rms:.3e}"); |
| 227 | } else { | 131 | } else { |
| 228 | - assert!(corr >= MIN_CORR, "{key} ch{ch}: correlation {corr:.6}"); | 132 | + assert!(corr >= MIN_CORR, "{name} ch{ch}: correlation {corr:.6}"); |
| 229 | } | 133 | } |
| 230 | worst = worst.min(corr); | 134 | worst = worst.min(corr); |
| 231 | worst_rms = worst_rms.max(rms); | 135 | worst_rms = worst_rms.max(rms); |
| @@ -233,10 +137,8 @@ fn real_library_ac3_and_eac3_match_ffmpeg() { | |||
| 233 | total += n; | 137 | total += n; |
| 234 | } | 138 | } |
| 235 | eprintln!( | 139 | eprintln!( |
| 236 | - "RESULT {key} {codec} {decoded_channels}ch {seconds}s: min corr {worst:.6}, max rms {worst_rms:.3e}, exact {:.4}%", | 140 | + "RESULT {name} {decoded_channels}ch: min corr {worst:.6}, max rms {worst_rms:.3e}, exact {:.4}%", |
| 237 | 100.0 * exact_total as f64 / total.max(1) as f64 | 141 | 100.0 * exact_total as f64 / total.max(1) as f64 |
| 238 | ); | 142 | ); |
| 239 | - checked += 1; | ||
| 240 | } | 143 | } |
| 241 | - eprintln!("{checked} real-library AC-3/E-AC-3 entries checked"); | ||
| 242 | } | 144 | } |
crates/ec-alac/Cargo.tomlmodified+1 -0
| @@ -12,3 +12,4 @@ ec-core = { workspace = true } | |||
| 12 | [dev-dependencies] | 12 | [dev-dependencies] |
| 13 | ec-mp4 = { workspace = true } | 13 | ec-mp4 = { workspace = true } |
| 14 | ec-riff = { workspace = true } | 14 | ec-riff = { workspace = true } |
| 15 | +ec-testkit.workspace = true | ||
crates/ec-alac/tests/encode.rsmodified+13 -37
| @@ -1,20 +1,15 @@ | |||
| 1 | //! Round-trip the encoder through the decoder it was written to feed, then | 1 | //! Round-trip the encoder through the decoder it was written to feed, then |
| 2 | -//! through a real mp4 mux and (when the oracle is present) ffmpeg/ffprobe. | 2 | +//! through a real mp4 mux and ffmpeg/ffprobe. |
| 3 | 3 | ||
| 4 | use std::fs::File; | 4 | use std::fs::File; |
| 5 | use std::io::{BufReader, Cursor}; | 5 | use std::io::{BufReader, Cursor}; |
| 6 | use std::path::{Path, PathBuf}; | 6 | use std::path::{Path, PathBuf}; |
| 7 | -use std::process::Command; | ||
| 8 | 7 | ||
| 9 | use ec_alac::{AlacDecoder, AlacEncoder}; | 8 | use ec_alac::{AlacDecoder, AlacEncoder}; |
| 10 | use ec_core::registry::{CodecId, Demuxer, Encoder, Muxer, StreamInfo}; | 9 | use ec_core::registry::{CodecId, Demuxer, Encoder, Muxer, StreamInfo}; |
| 11 | use ec_core::timebase::TimeBase; | 10 | use ec_core::timebase::TimeBase; |
| 12 | use ec_core::Packet; | 11 | use ec_core::Packet; |
| 13 | 12 | ||
| 14 | -fn fixtures() -> PathBuf { | ||
| 15 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | /// A small deterministic PRNG so a "random data" test does not depend on an | 13 | /// A small deterministic PRNG so a "random data" test does not depend on an |
| 19 | /// external crate: xorshift32. | 14 | /// external crate: xorshift32. |
| 20 | struct Rng(u32); | 15 | struct Rng(u32); |
| @@ -80,17 +75,16 @@ fn mux_to_m4a(enc: &AlacEncoder, channels: usize, sample_rate: u32, samples: &[i | |||
| 80 | (dir, out_path) | 75 | (dir, out_path) |
| 81 | } | 76 | } |
| 82 | 77 | ||
| 83 | -/// ffmpeg's decode of `path` in raw format `fmt`, or None when no oracle is | 78 | +/// ffmpeg's decode of `path` in raw format `fmt`. |
| 84 | -/// installed. | 79 | +fn ffmpeg_decode(path: &Path, fmt: &str) -> Vec<u8> { |
| 85 | -fn ffmpeg_decode(path: &Path, fmt: &str) -> Option<Vec<u8>> { | 80 | + let decode = ec_testkit::ffmpeg() |
| 86 | - let decode = Command::new("ffmpeg") | ||
| 87 | .args(["-nostdin", "-v", "error", "-i"]) | 81 | .args(["-nostdin", "-v", "error", "-i"]) |
| 88 | .arg(path) | 82 | .arg(path) |
| 89 | .args(["-f", fmt, "-"]) | 83 | .args(["-f", fmt, "-"]) |
| 90 | .output() | 84 | .output() |
| 91 | - .ok()?; | 85 | + .expect("ffmpeg"); |
| 92 | assert!(decode.status.success(), "{}", String::from_utf8_lossy(&decode.stderr)); | 86 | assert!(decode.status.success(), "{}", String::from_utf8_lossy(&decode.stderr)); |
| 93 | - Some(decode.stdout) | 87 | + decode.stdout |
| 94 | } | 88 | } |
| 95 | 89 | ||
| 96 | #[test] | 90 | #[test] |
| @@ -99,11 +93,7 @@ fn twenty_four_bit_uses_byte_shift_when_cheaper() { | |||
| 99 | // byte: exactly the shape a 24-bit master of 16-bit source material has, | 93 | // byte: exactly the shape a 24-bit master of 16-bit source material has, |
| 100 | // and exactly what bytes_shifted exists for — the high bits alone | 94 | // and exactly what bytes_shifted exists for — the high bits alone |
| 101 | // predict well, but folded together with the dither's noise they do not. | 95 | // predict well, but folded together with the dither's noise they do not. |
| 102 | - let path = fixtures().join("wav16-stereo-48000.wav"); | 96 | + let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav"); |
| 103 | - if !path.exists() { | ||
| 104 | - eprintln!("fixtures/audio absent (gitignored) — skipping"); | ||
| 105 | - return; | ||
| 106 | - } | ||
| 107 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); | 97 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); |
| 108 | let spec = reader.spec(); | 98 | let spec = reader.spec(); |
| 109 | let mut rng = Rng(0xdead_beef); | 99 | let mut rng = Rng(0xdead_beef); |
| @@ -161,7 +151,6 @@ fn twenty_four_bit_tonal_content_round_trips_bit_exactly() { | |||
| 161 | let (dir, out_path) = mux_to_m4a(&enc, channels as usize, 48_000, samples); | 151 | let (dir, out_path) = mux_to_m4a(&enc, channels as usize, 48_000, samples); |
| 162 | let got = ffmpeg_decode(&out_path, "s32le"); | 152 | let got = ffmpeg_decode(&out_path, "s32le"); |
| 163 | std::fs::remove_dir_all(&dir).ok(); | 153 | std::fs::remove_dir_all(&dir).ok(); |
| 164 | - let Some(got) = got else { continue }; | ||
| 165 | let want: Vec<u8> = samples.iter().flat_map(|&s| (s << 8).to_le_bytes()).collect(); | 154 | let want: Vec<u8> = samples.iter().flat_map(|&s| (s << 8).to_le_bytes()).collect(); |
| 166 | assert!(got == want, "{channels}ch 24-bit tone, shift={allow_shift}: reference decode differs"); | 155 | assert!(got == want, "{channels}ch 24-bit tone, shift={allow_shift}: reference decode differs"); |
| 167 | } | 156 | } |
| @@ -182,11 +171,7 @@ fn escape_frames_round_trip_random_data() { | |||
| 182 | 171 | ||
| 183 | #[test] | 172 | #[test] |
| 184 | fn real_audio_round_trips_and_compresses() { | 173 | fn real_audio_round_trips_and_compresses() { |
| 185 | - let path = fixtures().join("wav16-stereo-48000.wav"); | 174 | + let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav"); |
| 186 | - if !path.exists() { | ||
| 187 | - eprintln!("fixtures/audio absent (gitignored) — skipping"); | ||
| 188 | - return; | ||
| 189 | - } | ||
| 190 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); | 175 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); |
| 191 | let spec = reader.spec(); | 176 | let spec = reader.spec(); |
| 192 | let samples = reader.read_all_i32().expect("pcm"); | 177 | let samples = reader.read_all_i32().expect("pcm"); |
| @@ -207,11 +192,7 @@ fn real_audio_round_trips_and_compresses() { | |||
| 207 | 192 | ||
| 208 | #[test] | 193 | #[test] |
| 209 | fn muxed_stream_is_alac_at_the_right_rate_and_ffmpeg_agrees() { | 194 | fn muxed_stream_is_alac_at_the_right_rate_and_ffmpeg_agrees() { |
| 210 | - let path = fixtures().join("wav16-stereo-48000.wav"); | 195 | + let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav"); |
| 211 | - if !path.exists() { | ||
| 212 | - eprintln!("fixtures/audio absent (gitignored) — skipping"); | ||
| 213 | - return; | ||
| 214 | - } | ||
| 215 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); | 196 | let mut reader = ec_riff::WavReader::open(&path).expect("open wav"); |
| 216 | let spec = reader.spec(); | 197 | let spec = reader.spec(); |
| 217 | let samples = reader.read_all_i32().expect("pcm"); | 198 | let samples = reader.read_all_i32().expect("pcm"); |
| @@ -245,11 +226,7 @@ fn muxed_stream_is_alac_at_the_right_rate_and_ffmpeg_agrees() { | |||
| 245 | 226 | ||
| 246 | // The oracle: ffprobe reads the track back as alac at the right rate and | 227 | // The oracle: ffprobe reads the track back as alac at the right rate and |
| 247 | // channel count, and ffmpeg's own decode matches the source exactly. | 228 | // channel count, and ffmpeg's own decode matches the source exactly. |
| 248 | - if Command::new("ffprobe").arg("-version").output().is_err() { | 229 | + let probe = ec_testkit::ffprobe() |
| 249 | - eprintln!("ffprobe absent — skipping oracle checks"); | ||
| 250 | - return; | ||
| 251 | - } | ||
| 252 | - let probe = Command::new("ffprobe") | ||
| 253 | .args([ | 230 | .args([ |
| 254 | "-v", "error", "-select_streams", "a:0", "-show_entries", | 231 | "-v", "error", "-select_streams", "a:0", "-show_entries", |
| 255 | "stream=codec_name,sample_rate,channels", | 232 | "stream=codec_name,sample_rate,channels", |
| @@ -263,7 +240,7 @@ fn muxed_stream_is_alac_at_the_right_rate_and_ffmpeg_agrees() { | |||
| 263 | assert!(info.contains(&format!("sample_rate={}", spec.sample_rate)), "{info}"); | 240 | assert!(info.contains(&format!("sample_rate={}", spec.sample_rate)), "{info}"); |
| 264 | assert!(info.contains(&format!("channels={}", spec.channels)), "{info}"); | 241 | assert!(info.contains(&format!("channels={}", spec.channels)), "{info}"); |
| 265 | 242 | ||
| 266 | - let Some(stdout) = ffmpeg_decode(&out_path, "s16le") else { return }; | 243 | + let stdout = ffmpeg_decode(&out_path, "s16le"); |
| 267 | let want: Vec<i16> = samples.iter().map(|&s| s as i16).collect(); | 244 | let want: Vec<i16> = samples.iter().map(|&s| s as i16).collect(); |
| 268 | let got: Vec<i16> = stdout | 245 | let got: Vec<i16> = stdout |
| 269 | .as_chunks::<2>().0.iter() | 246 | .as_chunks::<2>().0.iter() |
| @@ -275,8 +252,8 @@ fn muxed_stream_is_alac_at_the_right_rate_and_ffmpeg_agrees() { | |||
| 275 | } | 252 | } |
| 276 | 253 | ||
| 277 | 254 | ||
| 278 | -/// Encode through our encoder, decode through ours and (when installed) the | 255 | +/// Encode through our encoder, decode through ours and the reference decoder |
| 279 | -/// reference decoder via a real m4a; both must hand back `samples` exactly. | 256 | +/// via a real m4a; both must hand back `samples` exactly. |
| 280 | fn round_trip_both_decoders(channels: u8, samples: &[i32], allow_shift: bool, what: &str) { | 257 | fn round_trip_both_decoders(channels: u8, samples: &[i32], allow_shift: bool, what: &str) { |
| 281 | let mut enc = AlacEncoder::new(48_000, channels, 24, 4096).expect("encoder"); | 258 | let mut enc = AlacEncoder::new(48_000, channels, 24, 4096).expect("encoder"); |
| 282 | enc.set_byte_shift(allow_shift); | 259 | enc.set_byte_shift(allow_shift); |
| @@ -291,7 +268,6 @@ fn round_trip_both_decoders(channels: u8, samples: &[i32], allow_shift: bool, wh | |||
| 291 | let (dir, out_path) = mux_to_m4a(&enc, channels as usize, 48_000, samples); | 268 | let (dir, out_path) = mux_to_m4a(&enc, channels as usize, 48_000, samples); |
| 292 | let got = ffmpeg_decode(&out_path, "s32le"); | 269 | let got = ffmpeg_decode(&out_path, "s32le"); |
| 293 | std::fs::remove_dir_all(&dir).ok(); | 270 | std::fs::remove_dir_all(&dir).ok(); |
| 294 | - let Some(got) = got else { return }; | ||
| 295 | let want: Vec<u8> = samples.iter().flat_map(|&s| (s << 8).to_le_bytes()).collect(); | 271 | let want: Vec<u8> = samples.iter().flat_map(|&s| (s << 8).to_le_bytes()).collect(); |
| 296 | assert!(got == want, "{what}: {channels}ch 24-bit, shift={allow_shift}: reference decode differs"); | 272 | assert!(got == want, "{what}: {channels}ch 24-bit, shift={allow_shift}: reference decode differs"); |
| 297 | } | 273 | } |
crates/ec-alac/tests/oracle.rsmodified+7 -23
| @@ -2,21 +2,15 @@ | |||
| 2 | //! same bytes ffmpeg's decoder produces, sample for sample, in the same channel | 2 | //! same bytes ffmpeg's decoder produces, sample for sample, in the same channel |
| 3 | //! order. | 3 | //! order. |
| 4 | //! | 4 | //! |
| 5 | -//! Fixtures come from `scripts/gen-fixtures.sh`; a missing one skips its row | 5 | +//! Fixtures come from `scripts/fixtures.sh`; a missing one fails the test. |
| 6 | -//! rather than failing, so a checkout without generated fixtures still builds. | ||
| 7 | 6 | ||
| 8 | use std::fs::File; | 7 | use std::fs::File; |
| 9 | use std::io::BufReader; | 8 | use std::io::BufReader; |
| 10 | -use std::path::{Path, PathBuf}; | 9 | +use std::path::Path; |
| 11 | -use std::process::Command; | ||
| 12 | 10 | ||
| 13 | use ec_alac::{AlacDecoder, MagicCookie}; | 11 | use ec_alac::{AlacDecoder, MagicCookie}; |
| 14 | use ec_core::registry::{CodecId, Demuxer}; | 12 | use ec_core::registry::{CodecId, Demuxer}; |
| 15 | 13 | ||
| 16 | -fn fixtures() -> PathBuf { | ||
| 17 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") | ||
| 18 | -} | ||
| 19 | - | ||
| 20 | /// Every sample of `path`'s ALAC track, interleaved, as this crate decodes it. | 14 | /// Every sample of `path`'s ALAC track, interleaved, as this crate decodes it. |
| 21 | fn decode(path: &Path) -> (MagicCookie, Vec<i32>) { | 15 | fn decode(path: &Path) -> (MagicCookie, Vec<i32>) { |
| 22 | let mut demuxer = | 16 | let mut demuxer = |
| @@ -43,7 +37,7 @@ fn decode(path: &Path) -> (MagicCookie, Vec<i32>) { | |||
| 43 | 37 | ||
| 44 | /// ffmpeg's own decode of the same file, in the raw format `fmt` names. | 38 | /// ffmpeg's own decode of the same file, in the raw format `fmt` names. |
| 45 | fn ffmpeg(path: &Path, fmt: &str) -> Vec<u8> { | 39 | fn ffmpeg(path: &Path, fmt: &str) -> Vec<u8> { |
| 46 | - let out = Command::new("ffmpeg") | 40 | + let out = ec_testkit::ffmpeg() |
| 47 | .args(["-nostdin", "-v", "error", "-i"]) | 41 | .args(["-nostdin", "-v", "error", "-i"]) |
| 48 | .arg(path) | 42 | .arg(path) |
| 49 | .args(["-f", fmt, "-"]) | 43 | .args(["-f", fmt, "-"]) |
| @@ -71,10 +65,7 @@ fn every_alac_fixture_decodes_bit_exactly() { | |||
| 71 | "alac24-mp4-stereo-48000.m4a", | 65 | "alac24-mp4-stereo-48000.m4a", |
| 72 | "alac24-mp4-5.1-48000.m4a", | 66 | "alac24-mp4-5.1-48000.m4a", |
| 73 | ] { | 67 | ] { |
| 74 | - let path = fixtures().join(name); | 68 | + let path = ec_testkit::fixture(&format!("audio/{name}")); |
| 75 | - if !path.exists() { | ||
| 76 | - continue; | ||
| 77 | - } | ||
| 78 | let (cookie, got) = decode(&path); | 69 | let (cookie, got) = decode(&path); |
| 79 | let (fmt, width) = match cookie.bit_depth <= 16 { | 70 | let (fmt, width) = match cookie.bit_depth <= 16 { |
| 80 | true => ("s16le", 2), | 71 | true => ("s16le", 2), |
| @@ -102,17 +93,14 @@ fn every_alac_fixture_decodes_bit_exactly() { | |||
| 102 | assert_eq!(bad, None, "{name}: first differing sample"); | 93 | assert_eq!(bad, None, "{name}: first differing sample"); |
| 103 | checked += 1; | 94 | checked += 1; |
| 104 | } | 95 | } |
| 105 | - assert!(checked > 0, "no ALAC fixtures found — run gen-fixtures.sh"); | 96 | + assert!(checked > 0, "no ALAC fixtures found"); |
| 106 | eprintln!("alac oracle: {checked} fixtures bit-exact vs ffmpeg"); | 97 | eprintln!("alac oracle: {checked} fixtures bit-exact vs ffmpeg"); |
| 107 | } | 98 | } |
| 108 | 99 | ||
| 109 | /// A truncated frame is an error, not a panic — the fuzz floor in miniature. | 100 | /// A truncated frame is an error, not a panic — the fuzz floor in miniature. |
| 110 | #[test] | 101 | #[test] |
| 111 | fn truncated_frames_are_refused_without_panicking() { | 102 | fn truncated_frames_are_refused_without_panicking() { |
| 112 | - let path = fixtures().join("alac-mp4-stereo-44100.m4a"); | 103 | + let path = ec_testkit::fixture("audio/alac-mp4-stereo-44100.m4a"); |
| 113 | - if !path.exists() { | ||
| 114 | - return; | ||
| 115 | - } | ||
| 116 | let mut demuxer = | 104 | let mut demuxer = |
| 117 | ec_mp4::Mp4Demuxer::new(BufReader::new(File::open(&path).expect("open"))).expect("mp4"); | 105 | ec_mp4::Mp4Demuxer::new(BufReader::new(File::open(&path).expect("open"))).expect("mp4"); |
| 118 | let stream = demuxer.streams()[0].clone(); | 106 | let stream = demuxer.streams()[0].clone(); |
| @@ -135,10 +123,6 @@ fn truncated_frames_are_refused_without_panicking() { | |||
| 135 | /// the checked-in fixtures (16-bit, or 24-bit with a shifted low byte) carry. | 123 | /// the checked-in fixtures (16-bit, or 24-bit with a shifted low byte) carry. |
| 136 | #[test] | 124 | #[test] |
| 137 | fn reference_encoded_24_bit_tone_decodes_bit_exactly() { | 125 | fn reference_encoded_24_bit_tone_decodes_bit_exactly() { |
| 138 | - if Command::new("ffmpeg").arg("-version").output().is_err() { | ||
| 139 | - eprintln!("ffmpeg absent — skipping"); | ||
| 140 | - return; | ||
| 141 | - } | ||
| 142 | let dir = std::env::temp_dir().join(format!("ec-alac-tone-{}", std::process::id())); | 126 | let dir = std::env::temp_dir().join(format!("ec-alac-tone-{}", std::process::id())); |
| 143 | std::fs::create_dir_all(&dir).expect("tmp"); | 127 | std::fs::create_dir_all(&dir).expect("tmp"); |
| 144 | let raw = dir.join("tone.raw"); | 128 | let raw = dir.join("tone.raw"); |
| @@ -154,7 +138,7 @@ fn reference_encoded_24_bit_tone_decodes_bit_exactly() { | |||
| 154 | }) | 138 | }) |
| 155 | .collect(); | 139 | .collect(); |
| 156 | std::fs::write(&raw, &pcm).expect("raw"); | 140 | std::fs::write(&raw, &pcm).expect("raw"); |
| 157 | - let enc = Command::new("ffmpeg") | 141 | + let enc = ec_testkit::ffmpeg() |
| 158 | .args(["-nostdin", "-y", "-v", "error", "-f", "s32le", "-ar", "48000", "-ac", "2", "-i"]) | 142 | .args(["-nostdin", "-y", "-v", "error", "-f", "s32le", "-ar", "48000", "-ac", "2", "-i"]) |
| 159 | .arg(&raw) | 143 | .arg(&raw) |
| 160 | .args(["-c:a", "alac", "-sample_fmt", "s32p"]) | 144 | .args(["-c:a", "alac", "-sample_fmt", "s32p"]) |
crates/ec-amr/Cargo.tomlmodified+1 -0
| @@ -12,3 +12,4 @@ ec-core = { workspace = true } | |||
| 12 | [dev-dependencies] | 12 | [dev-dependencies] |
| 13 | ec-mp4 = { workspace = true } | 13 | ec-mp4 = { workspace = true } |
| 14 | ec-riff = { workspace = true } | 14 | ec-riff = { workspace = true } |
| 15 | +ec-testkit.workspace = true | ||
crates/ec-amr/fuzz/seed.shmodified+3 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # seed.sh: fill fuzz/corpus/<target>/ with synthetic AMR-NB files, one per mode. | 2 | # seed.sh: fill fuzz/corpus/<target>/ with synthetic AMR-NB files, one per mode. |
| 3 | -# Needs ffmpeg with libopencore_amrnb. fuzz_container gets each .amr as-is; | 3 | +# Needs the pinned ffmpeg (EC_FFMPEG) with libopencore_amrnb. fuzz_container gets each .amr as-is; |
| 4 | # fuzz_nb_decode gets it with the 6-byte magic stripped (ToC + frames). | 4 | # fuzz_nb_decode gets it with the 6-byte magic stripped (ToC + frames). |
| 5 | # Corpus lives under fuzz/corpus, which is git-ignored. | 5 | # Corpus lives under fuzz/corpus, which is git-ignored. |
| 6 | set -euo pipefail | 6 | set -euo pipefail |
| @@ -9,13 +9,14 @@ FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd) | |||
| 9 | CONT="$FUZZ_DIR/corpus/fuzz_container" | 9 | CONT="$FUZZ_DIR/corpus/fuzz_container" |
| 10 | DEC="$FUZZ_DIR/corpus/fuzz_nb_decode" | 10 | DEC="$FUZZ_DIR/corpus/fuzz_nb_decode" |
| 11 | mkdir -p "$CONT" "$DEC" | 11 | mkdir -p "$CONT" "$DEC" |
| 12 | +FF=${EC_FFMPEG:-$HOME/.cache/ec-ffmpeg/ffmpeg} | ||
| 12 | TMP=$(mktemp -d) | 13 | TMP=$(mktemp -d) |
| 13 | trap 'rm -rf "$TMP"' EXIT | 14 | trap 'rm -rf "$TMP"' EXIT |
| 14 | 15 | ||
| 15 | i=0 | 16 | i=0 |
| 16 | for rate in 4750 5150 5900 6700 7400 7950 10200 12200; do | 17 | for rate in 4750 5150 5900 6700 7400 7950 10200 12200; do |
| 17 | f="$TMP/m$i.amr" | 18 | f="$TMP/m$i.amr" |
| 18 | - ffmpeg -nostdin -v error -f lavfi -i "sine=frequency=$((300 + 150 * i)):duration=2" \ | 19 | + "$FF" -nostdin -v error -f lavfi -i "sine=frequency=$((300 + 150 * i)):duration=2" \ |
| 19 | -ar 8000 -ac 1 -c:a libopencore_amrnb -b:a "$rate" -f amr "$f" | 20 | -ar 8000 -ac 1 -c:a libopencore_amrnb -b:a "$rate" -f amr "$f" |
| 20 | cp -f "$f" "$CONT/mode$i.amr" | 21 | cp -f "$f" "$CONT/mode$i.amr" |
| 21 | tail -c +7 "$f" > "$DEC/mode$i" | 22 | tail -c +7 "$f" > "$DEC/mode$i" |
crates/ec-amr/tests/container_roundtrip.rsmodified+3 -16
| @@ -5,7 +5,6 @@ | |||
| 5 | 5 | ||
| 6 | use std::fs::File; | 6 | use std::fs::File; |
| 7 | use std::io::BufReader; | 7 | use std::io::BufReader; |
| 8 | -use std::process::Command; | ||
| 9 | 8 | ||
| 10 | use ec_amr::container::{AmrDemuxer, Kind, probe}; | 9 | use ec_amr::container::{AmrDemuxer, Kind, probe}; |
| 11 | use ec_core::registry::{CodecId, Demuxer, MediaParameters, SeekMode}; | 10 | use ec_core::registry::{CodecId, Demuxer, MediaParameters, SeekMode}; |
| @@ -15,7 +14,7 @@ const RATES: [u32; 8] = [4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200]; | |||
| 15 | const PAYLOAD: [usize; 8] = [12, 13, 15, 17, 19, 20, 26, 31]; | 14 | const PAYLOAD: [usize; 8] = [12, 13, 15, 17, 19, 20, 26, 31]; |
| 16 | 15 | ||
| 17 | fn ffmpeg(args: &[&str]) -> bool { | 16 | fn ffmpeg(args: &[&str]) -> bool { |
| 18 | - Command::new("ffmpeg") | 17 | + ec_testkit::ffmpeg() |
| 19 | .args(["-nostdin", "-v", "error", "-y"]) | 18 | .args(["-nostdin", "-v", "error", "-y"]) |
| 20 | .args(args) | 19 | .args(args) |
| 21 | .status() | 20 | .status() |
| @@ -23,15 +22,6 @@ fn ffmpeg(args: &[&str]) -> bool { | |||
| 23 | .unwrap_or(false) | 22 | .unwrap_or(false) |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | -fn skip(why: &str) -> bool { | ||
| 27 | - assert!( | ||
| 28 | - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 29 | - "EC_REQUIRE_FIXTURES=1 but {why}" | ||
| 30 | - ); | ||
| 31 | - eprintln!("SKIP: {why}"); | ||
| 32 | - true | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | fn drain(d: &mut dyn Demuxer) -> Vec<Vec<u8>> { | 25 | fn drain(d: &mut dyn Demuxer) -> Vec<Vec<u8>> { |
| 36 | let mut out = Vec::new(); | 26 | let mut out = Vec::new(); |
| 37 | loop { | 27 | loop { |
| @@ -54,10 +44,7 @@ fn amr_3gp_mp4_agree_for_all_modes() { | |||
| 54 | "-c:a", "libopencore_amrnb", "-b:a", &rate.to_string(), "-f", "amr", | 44 | "-c:a", "libopencore_amrnb", "-b:a", &rate.to_string(), "-f", "amr", |
| 55 | amr.to_str().unwrap(), | 45 | amr.to_str().unwrap(), |
| 56 | ]); | 46 | ]); |
| 57 | - if !enc { | 47 | + assert!(enc, "ffmpeg with libopencore_amrnb is required"); |
| 58 | - skip("ffmpeg with libopencore_amrnb is not available"); | ||
| 59 | - return; | ||
| 60 | - } | ||
| 61 | let bytes = std::fs::read(&amr).unwrap(); | 48 | let bytes = std::fs::read(&amr).unwrap(); |
| 62 | assert_eq!(probe(&bytes), Some(Kind::Nb)); | 49 | assert_eq!(probe(&bytes), Some(Kind::Nb)); |
| 63 | 50 | ||
| @@ -82,7 +69,7 @@ fn amr_3gp_mp4_agree_for_all_modes() { | |||
| 82 | } | 69 | } |
| 83 | // ffprobe's own packet count for the same file (75 frames of 20 ms plus | 70 | // ffprobe's own packet count for the same file (75 frames of 20 ms plus |
| 84 | // the encoder's flush frame). | 71 | // the encoder's flush frame). |
| 85 | - let probed = Command::new("ffprobe") | 72 | + let probed = ec_testkit::ffprobe() |
| 86 | .args(["-v", "error", "-count_packets", "-select_streams", "a:0"]) | 73 | .args(["-v", "error", "-count_packets", "-select_streams", "a:0"]) |
| 87 | .args(["-show_entries", "stream=nb_read_packets", "-of", "csv=p=0"]) | 74 | .args(["-show_entries", "stream=nb_read_packets", "-of", "csv=p=0"]) |
| 88 | .arg(&amr) | 75 | .arg(&amr) |
crates/ec-amr/tests/oracle.rsmodified+8 -18
| @@ -3,11 +3,9 @@ | |||
| 3 | //! reference this port follows) the output must be bit-exact; against ffmpeg's native `amrnb` | 3 | //! reference this port follows) the output must be bit-exact; against ffmpeg's native `amrnb` |
| 4 | //! decoder the SNR is reported and must stay high. | 4 | //! decoder the SNR is reported and must stay high. |
| 5 | //! | 5 | //! |
| 6 | -//! The fixtures are generated on the fly with ffmpeg from lavfi sources. Without ffmpeg (or | 6 | +//! The fixtures are generated on the fly with the pinned ffmpeg from lavfi sources. |
| 7 | -//! without libopencore) the tests skip, unless `EC_REQUIRE_FIXTURES=1`, which makes that a failure. | ||
| 8 | 7 | ||
| 9 | use std::path::{Path, PathBuf}; | 8 | use std::path::{Path, PathBuf}; |
| 10 | -use std::process::Command; | ||
| 11 | 9 | ||
| 12 | use ec_amr::nb::bitstream::frame_bytes; | 10 | use ec_amr::nb::bitstream::frame_bytes; |
| 13 | use ec_amr::nb::decoder::AmrNbDecoder; | 11 | use ec_amr::nb::decoder::AmrNbDecoder; |
| @@ -39,10 +37,6 @@ fn sources() -> Vec<(&'static str, String)> { | |||
| 39 | ] | 37 | ] |
| 40 | } | 38 | } |
| 41 | 39 | ||
| 42 | -fn require() -> bool { | ||
| 43 | - std::env::var("EC_REQUIRE_FIXTURES").map(|v| v == "1").unwrap_or(false) | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | fn workdir() -> PathBuf { | 40 | fn workdir() -> PathBuf { |
| 47 | let d = std::env::temp_dir().join(format!("ec-amr-oracle-{}", std::process::id())); | 41 | let d = std::env::temp_dir().join(format!("ec-amr-oracle-{}", std::process::id())); |
| 48 | std::fs::create_dir_all(&d).unwrap(); | 42 | std::fs::create_dir_all(&d).unwrap(); |
| @@ -50,7 +44,7 @@ fn workdir() -> PathBuf { | |||
| 50 | } | 44 | } |
| 51 | 45 | ||
| 52 | fn ffmpeg_ok() -> bool { | 46 | fn ffmpeg_ok() -> bool { |
| 53 | - Command::new("ffmpeg") | 47 | + ec_testkit::ffmpeg() |
| 54 | .args(["-hide_banner", "-h", "decoder=libopencore_amrnb"]) | 48 | .args(["-hide_banner", "-h", "decoder=libopencore_amrnb"]) |
| 55 | .output() | 49 | .output() |
| 56 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("libopencore_amrnb")) | 50 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("libopencore_amrnb")) |
| @@ -58,7 +52,7 @@ fn ffmpeg_ok() -> bool { | |||
| 58 | } | 52 | } |
| 59 | 53 | ||
| 60 | fn run(args: &[&str]) -> Option<Vec<u8>> { | 54 | fn run(args: &[&str]) -> Option<Vec<u8>> { |
| 61 | - let out = Command::new("ffmpeg").args(["-nostdin", "-v", "error", "-y"]).args(args).output().ok()?; | 55 | + let out = ec_testkit::ffmpeg().args(["-nostdin", "-v", "error", "-y"]).args(args).output().ok()?; |
| 62 | out.status.success().then_some(out.stdout) | 56 | out.status.success().then_some(out.stdout) |
| 63 | } | 57 | } |
| 64 | 58 | ||
| @@ -132,18 +126,14 @@ fn first_diff(a: &[i16], b: &[i16]) -> Option<usize> { | |||
| 132 | (0..a.len().min(b.len())).find(|&i| a[i] != b[i]).or((a.len() != b.len()).then_some(a.len().min(b.len()))) | 126 | (0..a.len().min(b.len())).find(|&i| a[i] != b[i]).or((a.len() != b.len()).then_some(a.len().min(b.len()))) |
| 133 | } | 127 | } |
| 134 | 128 | ||
| 135 | -fn setup() -> Option<PathBuf> { | 129 | +fn setup() -> PathBuf { |
| 136 | - if !ffmpeg_ok() { | 130 | + assert!(ffmpeg_ok(), "ffmpeg with libopencore_amrnb is required"); |
| 137 | - assert!(!require(), "EC_REQUIRE_FIXTURES=1 but ffmpeg with libopencore_amrnb is unavailable"); | 131 | + workdir() |
| 138 | - eprintln!("skipping: ffmpeg/libopencore_amrnb not available"); | ||
| 139 | - return None; | ||
| 140 | - } | ||
| 141 | - Some(workdir()) | ||
| 142 | } | 132 | } |
| 143 | 133 | ||
| 144 | #[test] | 134 | #[test] |
| 145 | fn all_modes_bit_exact_vs_libopencore() { | 135 | fn all_modes_bit_exact_vs_libopencore() { |
| 146 | - let Some(dir) = setup() else { return }; | 136 | + let dir = setup(); |
| 147 | let mut checked = 0; | 137 | let mut checked = 0; |
| 148 | for dtx in [false, true] { | 138 | for dtx in [false, true] { |
| 149 | for (rate, label) in MODES { | 139 | for (rate, label) in MODES { |
| @@ -192,7 +182,7 @@ fn rng(state: &mut u64) -> u64 { | |||
| 192 | 182 | ||
| 193 | #[test] | 183 | #[test] |
| 194 | fn lost_and_bit_flipped_frames_vs_libopencore() { | 184 | fn lost_and_bit_flipped_frames_vs_libopencore() { |
| 195 | - let Some(dir) = setup() else { return }; | 185 | + let dir = setup(); |
| 196 | let mut seed = 0x1234_5678_9abc_def1u64; | 186 | let mut seed = 0x1234_5678_9abc_def1u64; |
| 197 | for (rate, label) in MODES { | 187 | for (rate, label) in MODES { |
| 198 | let (sname, src) = &sources()[2]; | 188 | let (sname, src) = &sources()[2]; |
crates/ec-amr/tests/wb_oracle.rsmodified+4 -19
| @@ -2,13 +2,11 @@ | |||
| 2 | //! the 3GPP TS 26.173 reference code: the output must match it sample for sample. | 2 | //! the 3GPP TS 26.173 reference code: the output must match it sample for sample. |
| 3 | //! | 3 | //! |
| 4 | //! Fixtures are made here with ffmpeg's `libvo_amrwbenc` from a synthetic source, one file per | 4 | //! Fixtures are made here with ffmpeg's `libvo_amrwbenc` from a synthetic source, one file per |
| 5 | -//! mode, as `.awb` and as mp4 (`sawb`). A machine without those ffmpeg codecs skips loudly; with | 5 | +//! mode, as `.awb` and as mp4 (`sawb`). The pinned ffmpeg must have those codecs. |
| 6 | -//! `EC_REQUIRE_FIXTURES=1` that is a failure. | ||
| 7 | 6 | ||
| 8 | use std::fs::File; | 7 | use std::fs::File; |
| 9 | use std::io::{BufReader, Cursor}; | 8 | use std::io::{BufReader, Cursor}; |
| 10 | use std::path::{Path, PathBuf}; | 9 | use std::path::{Path, PathBuf}; |
| 11 | -use std::process::Command; | ||
| 12 | 10 | ||
| 13 | use ec_amr::container::AmrDemuxer; | 11 | use ec_amr::container::AmrDemuxer; |
| 14 | use ec_amr::wb::AmrWbDecoder; | 12 | use ec_amr::wb::AmrWbDecoder; |
| @@ -18,7 +16,7 @@ const RATES: [u32; 9] = [6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 2 | |||
| 18 | const PAYLOAD: [usize; 10] = [17, 23, 32, 36, 40, 46, 50, 58, 60, 5]; | 16 | const PAYLOAD: [usize; 10] = [17, 23, 32, 36, 40, 46, 50, 58, 60, 5]; |
| 19 | 17 | ||
| 20 | fn ffmpeg(args: &[&str]) -> Option<Vec<u8>> { | 18 | fn ffmpeg(args: &[&str]) -> Option<Vec<u8>> { |
| 21 | - let out = Command::new("ffmpeg") | 19 | + let out = ec_testkit::ffmpeg() |
| 22 | .args(["-nostdin", "-v", "error", "-y"]) | 20 | .args(["-nostdin", "-v", "error", "-y"]) |
| 23 | .args(args) | 21 | .args(args) |
| 24 | .output() | 22 | .output() |
| @@ -26,15 +24,6 @@ fn ffmpeg(args: &[&str]) -> Option<Vec<u8>> { | |||
| 26 | out.status.success().then_some(out.stdout) | 24 | out.status.success().then_some(out.stdout) |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | -fn skip(why: &str) -> bool { | ||
| 30 | - assert!( | ||
| 31 | - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), | ||
| 32 | - "EC_REQUIRE_FIXTURES=1 but {why}" | ||
| 33 | - ); | ||
| 34 | - eprintln!("SKIP: {why}"); | ||
| 35 | - true | ||
| 36 | -} | ||
| 37 | - | ||
| 38 | struct Dir(PathBuf); | 27 | struct Dir(PathBuf); |
| 39 | impl Dir { | 28 | impl Dir { |
| 40 | fn new(tag: &str) -> Dir { | 29 | fn new(tag: &str) -> Dir { |
| @@ -136,9 +125,7 @@ fn have_tools() -> bool { | |||
| 136 | 125 | ||
| 137 | #[test] | 126 | #[test] |
| 138 | fn every_mode_matches_the_reference_decoder_in_awb_and_mp4() { | 127 | fn every_mode_matches_the_reference_decoder_in_awb_and_mp4() { |
| 139 | - if !have_tools() && skip("ffmpeg lacks libvo_amrwbenc/libopencore_amrwb") { | 128 | + assert!(have_tools(), "ffmpeg lacks libvo_amrwbenc/libopencore_amrwb"); |
| 140 | - return; | ||
| 141 | - } | ||
| 142 | let dir = Dir::new("modes"); | 129 | let dir = Dir::new("modes"); |
| 143 | for rate in RATES { | 130 | for rate in RATES { |
| 144 | let awb = dir.path(&format!("m{rate}.awb")); | 131 | let awb = dir.path(&format!("m{rate}.awb")); |
| @@ -183,9 +170,7 @@ fn lcg(state: &mut u64) -> u8 { | |||
| 183 | 170 | ||
| 184 | #[test] | 171 | #[test] |
| 185 | fn comfort_noise_lost_and_corrupted_frames_match_the_reference() { | 172 | fn comfort_noise_lost_and_corrupted_frames_match_the_reference() { |
| 186 | - if !have_tools() && skip("ffmpeg lacks libvo_amrwbenc/libopencore_amrwb") { | 173 | + assert!(have_tools(), "ffmpeg lacks libvo_amrwbenc/libopencore_amrwb"); |
| 187 | - return; | ||
| 188 | - } | ||
| 189 | let dir = Dir::new("chaos"); | 174 | let dir = Dir::new("chaos"); |
| 190 | // Real frames of three modes, mixed with SID, lost and corrupted ones (quality bit kept set: | 175 | // Real frames of three modes, mixed with SID, lost and corrupted ones (quality bit kept set: |
| 191 | // the reference wrapper ignores it). | 176 | // the reference wrapper ignores it). |