The multichannel AAC decode seat is an ec-aac native — rusty_aac stays encoder-only
Browse files at this commitfc0891facc9eaa7a64e0da798bafd2e3dc80398cParent: f0a2ecc- feat
- the multichannel AAC decode seat is an ec-aac native — rusty_aac stays encoder-only
7 changed files +106 -23
- Cargo.lock +9 -0
- crates/engine/Cargo.toml +15 -12
- crates/engine/src/audio.rs +8 -8
- crates/engine/src/caps.rs +3 -1
- crates/engine/src/waveform.rs +1 -1
- crates/engine/tests/audio_seek.rs +69 -0
- crates/engine/tests/hevc_mkv.rs +1 -1
Cargo.lockmodified+9 -0
| @@ -1588,6 +1588,14 @@ version = "1.0.20" | |||
| 1588 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1588 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1589 | checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" | 1589 | checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" |
| 1590 | 1590 | ||
| 1591 | +[[package]] | ||
| 1592 | +name = "ec-aac" | ||
| 1593 | +version = "0.1.0" | ||
| 1594 | +dependencies = [ | ||
| 1595 | + "ec-core", | ||
| 1596 | + "ec-dsp", | ||
| 1597 | +] | ||
| 1598 | + | ||
| 1591 | [[package]] | 1599 | [[package]] |
| 1592 | name = "ec-core" | 1600 | name = "ec-core" |
| 1593 | version = "0.1.0" | 1601 | version = "0.1.0" |
| @@ -1673,6 +1681,7 @@ checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" | |||
| 1673 | name = "engine" | 1681 | name = "engine" |
| 1674 | version = "0.1.0" | 1682 | version = "0.1.0" |
| 1675 | dependencies = [ | 1683 | dependencies = [ |
| 1684 | + "ec-aac", | ||
| 1676 | "ec-core", | 1685 | "ec-core", |
| 1677 | "ec-h264", | 1686 | "ec-h264", |
| 1678 | "ec-opus", | 1687 | "ec-opus", |
crates/engine/Cargo.tomlmodified+15 -12
| @@ -58,18 +58,21 @@ ec-h264 = { path = "../../../edith_codecs/crates/ec-h264" } | |||
| 58 | # Its shared IR (packets, frames, the registry decoder contract the seat is | 58 | # Its shared IR (packets, frames, the registry decoder contract the seat is |
| 59 | # written against), direct because decode.rs names those types itself. | 59 | # written against), direct because decode.rs names those types itself. |
| 60 | ec-core = { path = "../../../edith_codecs/crates/ec-core" } | 60 | ec-core = { path = "../../../edith_codecs/crates/ec-core" } |
| 61 | -# Both halves of AAC, and the only crate here that is asked for both. The | 61 | +# The multichannel AAC decode seat: symphonia's own refuses anything wider than |
| 62 | -# *encoder*, so an mp4's sound can be a mix rather than a copy: an equalized (or | 62 | +# stereo outright (`aac/mod.rs:93`, "aac: aac too complex"), and a 5.1 or 7.1 |
| 63 | -# otherwise processed) lane has to be decoded, and what is decoded has to be | 63 | +# film soundtrack is exactly that. `ec-aac`, the family's own decoder, took the |
| 64 | -# encoded again. The *decoder*, because symphonia's own refuses anything wider | 64 | +# seat the vendored `rusty_aac` held -- it hands 5.1 back already reordered |
| 65 | -# than stereo outright (`aac/mod.rs:93`, "aac: aac too complex") and a 5.1 film | 65 | +# into FL, FR, FC, LFE, BL, BR, the order the downmix in `audio` folds, the |
| 66 | -# soundtrack in an mkv is exactly that -- this one hands 5.1 back already | 66 | +# same one the seat always delivered. |
| 67 | -# reordered into FL, FR, FC, LFE, BL, BR, which is the order the downmix in | 67 | +ec-aac = { path = "../../../edith_codecs/crates/ec-aac" } |
| 68 | -# `audio` folds. Pure Rust with no C or FFI, Apache-2.0, the same Mata Network | 68 | +# The AAC *encoder*, and its last seat in the tree: so an mp4's sound can be a |
| 69 | -# family the retired `rusty_h264` came from. Nothing else in the ecosystem | 69 | +# mix rather than a copy, an equalized (or otherwise processed) lane has to be |
| 70 | -# encodes AAC without linking | 70 | +# decoded, and what is decoded has to be encoded again. Pure Rust with no C or |
| 71 | -# Fraunhofer's C library, which this project's no-install rule forbids. Built | 71 | +# FFI, Apache-2.0, the same Mata Network family the retired `rusty_h264` came |
| 72 | -# from `vendor/rusty_aac` -- see the patch table in the workspace manifest. | 72 | +# from. Nothing else in the ecosystem encodes AAC without linking Fraunhofer's |
| 73 | +# C library, which this project's no-install rule forbids. Built from | ||
| 74 | +# `vendor/rusty_aac` -- see the patch table in the workspace manifest. Its | ||
| 75 | +# *decoder* left the tree when `ec-aac` above took the multichannel seat. | ||
| 73 | rusty_aac = "0.5" | 76 | rusty_aac = "0.5" |
| 74 | # The MP3 encoder, so that format is a row a user can pick rather than a licence | 77 | # The MP3 encoder, so that format is a row a user can pick rather than a licence |
| 75 | # note: pure Rust, Apache-2.0, CBR and VBR. The decoder side of mp3 is | 78 | # note: pure Rust, Apache-2.0, CBR and VBR. The decoder side of mp3 is |
crates/engine/src/audio.rsmodified+8 -8
| @@ -1077,7 +1077,7 @@ impl AudioSession { | |||
| 1077 | // The profile still gates -- the writer rebuilds an | 1077 | // The profile still gates -- the writer rebuilds an |
| 1078 | // AudioSpecificConfig and calls it LC -- but the layout no | 1078 | // AudioSpecificConfig and calls it LC -- but the layout no |
| 1079 | // longer does: a 5.1 or 7.1 AAC track decodes through | 1079 | // longer does: a 5.1 or 7.1 AAC track decodes through |
| 1080 | - // `rusty_aac` and folds to the pair the timeline carries | 1080 | + // `ec-aac` and folds to the pair the timeline carries |
| 1081 | // ([`aac_decoder`]). | 1081 | // ([`aac_decoder`]). |
| 1082 | decodable: ac3.is_some() | 1082 | decodable: ac3.is_some() |
| 1083 | || aac | 1083 | || aac |
| @@ -1699,7 +1699,7 @@ impl SymTrack { | |||
| 1699 | /// Which decoder is not the caller's business, and it is not always | 1699 | /// Which decoder is not the caller's business, and it is not always |
| 1700 | /// symphonia's: its AAC decoder refuses anything wider than stereo outright | 1700 | /// symphonia's: its AAC decoder refuses anything wider than stereo outright |
| 1701 | /// (`aac/mod.rs:93`, "aac: aac too complex"), which is exactly the 5.1 and | 1701 | /// (`aac/mod.rs:93`, "aac: aac too complex"), which is exactly the 5.1 and |
| 1702 | - /// 7.1 tracks of a film, so those go to `rusty_aac` instead | 1702 | + /// 7.1 tracks of a film, so those go to `ec-aac` instead |
| 1703 | /// ([`aac_decoder`]), and it has no Opus decoder at all, so that one goes to | 1703 | /// ([`aac_decoder`]), and it has no Opus decoder at all, so that one goes to |
| 1704 | /// `ec-opus` ([`SymDecoder::Opus`]). | 1704 | /// `ec-opus` ([`SymDecoder::Opus`]). |
| 1705 | fn decoder(&self) -> crate::Result<SymDecoder> { | 1705 | fn decoder(&self) -> crate::Result<SymDecoder> { |
| @@ -1836,7 +1836,7 @@ enum SymDecoder { | |||
| 1836 | Sym(Box<dyn AudioDecoder>, usize), | 1836 | Sym(Box<dyn AudioDecoder>, usize), |
| 1837 | /// Boxed because the decoder carries its own IMDCT tables and this enum is | 1837 | /// Boxed because the decoder carries its own IMDCT tables and this enum is |
| 1838 | /// moved into the worker. | 1838 | /// moved into the worker. |
| 1839 | - Aac(Box<rusty_aac::AacDecoder>, usize), | 1839 | + Aac(Box<ec_aac::AacDecoder>, usize), |
| 1840 | /// Every Opus track, mono to 7.1: one multistream decoder -- the streams of | 1840 | /// Every Opus track, mono to 7.1: one multistream decoder -- the streams of |
| 1841 | /// a packet, the channel mapping table and the routing between them are all | 1841 | /// a packet, the channel mapping table and the routing between them are all |
| 1842 | /// its business -- and the same width. | 1842 | /// its business -- and the same width. |
| @@ -1875,7 +1875,7 @@ impl SymDecoder { | |||
| 1875 | /// The decoder an AAC track of `from` channels needs: symphonia's own refuses | 1875 | /// The decoder an AAC track of `from` channels needs: symphonia's own refuses |
| 1876 | /// anything wider than stereo outright (`aac/mod.rs:93`, "aac: aac too | 1876 | /// anything wider than stereo outright (`aac/mod.rs:93`, "aac: aac too |
| 1877 | /// complex"), which is exactly the 5.1 and 7.1 tracks of a film, so those go to | 1877 | /// complex"), which is exactly the 5.1 and 7.1 tracks of a film, so those go to |
| 1878 | -/// `rusty_aac` instead -- the same routing [`SymTrack::decoder`] does for a | 1878 | +/// `ec-aac` instead -- the same routing [`SymTrack::decoder`] does for a |
| 1879 | /// Matroska file, asked once here so an mp4's multichannel track takes it too. | 1879 | /// Matroska file, asked once here so an mp4's multichannel track takes it too. |
| 1880 | fn aac_decoder(params: &AudioCodecParameters, from: usize) -> crate::Result<SymDecoder> { | 1880 | fn aac_decoder(params: &AudioCodecParameters, from: usize) -> crate::Result<SymDecoder> { |
| 1881 | if from > 2 { | 1881 | if from > 2 { |
| @@ -1883,7 +1883,7 @@ fn aac_decoder(params: &AudioCodecParameters, from: usize) -> crate::Result<SymD | |||
| 1883 | .extra_data | 1883 | .extra_data |
| 1884 | .as_deref() | 1884 | .as_deref() |
| 1885 | .ok_or("a multichannel AAC track with no AudioSpecificConfig")?; | 1885 | .ok_or("a multichannel AAC track with no AudioSpecificConfig")?; |
| 1886 | - let decoder = rusty_aac::AacDecoder::with_config_bytes(asc) | 1886 | + let decoder = ec_aac::AacDecoder::with_config_bytes(asc) |
| 1887 | .map_err(|e| format!("multichannel AAC decoder init failed: {e}"))?; | 1887 | .map_err(|e| format!("multichannel AAC decoder init failed: {e}"))?; |
| 1888 | return Ok(SymDecoder::Aac(Box::new(decoder), from)); | 1888 | return Ok(SymDecoder::Aac(Box::new(decoder), from)); |
| 1889 | } | 1889 | } |
| @@ -1986,9 +1986,9 @@ fn vorbis_to_film_order(samples: &mut [f32], from: usize) { | |||
| 1986 | /// player's puts it there. | 1986 | /// player's puts it there. |
| 1987 | /// | 1987 | /// |
| 1988 | /// The film order is FL, FR, FC, LFE, BL, BR, SL, SR, which is what symphonia's | 1988 | /// The film order is FL, FR, FC, LFE, BL, BR, SL, SR, which is what symphonia's |
| 1989 | -/// decoders and `rusty_aac` both hand back (the latter reorders AAC's own | 1989 | +/// decoders and `ec-aac` both hand back (the latter reorders AAC's own |
| 1990 | -/// C, L, R, Ls, Rs, LFE element order into it: `decode.rs:779`) and what the AC-3 | 1990 | +/// C, L, R, Ls, Rs, LFE element order into it: its `film_order`) and what the |
| 1991 | -/// decoder's own passthrough uses. | 1991 | +/// AC-3 decoder's own passthrough uses. |
| 1992 | /// | 1992 | /// |
| 1993 | /// corner-cut: a width past 7.1 (22.2, ambisonics) keeps its front pair and drops | 1993 | /// corner-cut: a width past 7.1 (22.2, ambisonics) keeps its front pair and drops |
| 1994 | /// the rest -- no table here places those, and inventing one silently would be | 1994 | /// the rest -- no table here places those, and inventing one silently would be |
crates/engine/src/caps.rsmodified+3 -1
| @@ -35,7 +35,9 @@ const SW_CODECS: [(&str, &str, bool, bool); 10] = [ | |||
| 35 | ("H.264", "ec-h264", true, true), | 35 | ("H.264", "ec-h264", true, true), |
| 36 | ("HEVC", "oxideav-h265 intra", false, true), | 36 | ("HEVC", "oxideav-h265 intra", false, true), |
| 37 | ("AV1", "rav1e", false, true), | 37 | ("AV1", "rav1e", false, true), |
| 38 | - ("AAC", "rusty_aac", true, true), | 38 | + // Decode is split by width: symphonia carries stereo and narrower, `ec-aac` |
| 39 | + // everything wider; the encoder is `rusty_aac`. | ||
| 40 | + ("AAC", "symphonia / ec-aac / rusty_aac", true, true), | ||
| 39 | ("MP3", "symphonia / rusty_mp3", true, true), | 41 | ("MP3", "symphonia / rusty_mp3", true, true), |
| 40 | ("FLAC", "symphonia / flacenc", true, true), | 42 | ("FLAC", "symphonia / flacenc", true, true), |
| 41 | ("PCM", "symphonia / hound", true, true), | 43 | ("PCM", "symphonia / hound", true, true), |
crates/engine/src/waveform.rsmodified+1 -1
| @@ -19,7 +19,7 @@ use crate::audio::AudioChunk; | |||
| 19 | /// straddles zero, so silence draws as a flat line. | 19 | /// straddles zero, so silence draws as a flat line. |
| 20 | /// | 20 | /// |
| 21 | /// Decoding the whole file runs at ~1700x realtime for an mp4's stereo AAC and | 21 | /// Decoding the whole file runs at ~1700x realtime for an mp4's stereo AAC and |
| 22 | -/// ~50x for a film's 5.1 AAC in an mkv (six channels through `rusty_aac`), but | 22 | +/// ~260x for a film's 5.1 AAC in an mkv (six channels through `ec-aac`), but |
| 23 | /// it is linear in source length either way: callers cache the result per source | 23 | /// it is linear in source length either way: callers cache the result per source |
| 24 | /// *and stream* — two streams of one file are two different envelopes, and a | 24 | /// *and stream* — two streams of one file are two different envelopes, and a |
| 25 | /// cache keyed on the path alone would draw the first one under both. Memory is | 25 | /// cache keyed on the path alone would draw the first one under both. Memory is |
crates/engine/tests/audio_seek.rsmodified+69 -0
| @@ -256,6 +256,75 @@ fn a_seek_into_real_film_lands_on_the_second_it_asked_for() { | |||
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | +/// The 5.1 **AAC** film: the multichannel seat `ec-aac` took from the vendored | ||
| 260 | +/// `rusty_aac`, exercised on the kind of track it exists for -- a BluRay | ||
| 261 | +/// remux's 48 kHz AAC-LC 5.1, decoded, folded to the pair the timeline | ||
| 262 | +/// carries, seeked across the film, and correlated against ffmpeg's own decode | ||
| 263 | +/// of the same window. A wrong channel order, a wrong rate, or a fold that | ||
| 264 | +/// lost a side all move the correlation; a seat that refuses the track fails | ||
| 265 | +/// the open. | ||
| 266 | +/// | ||
| 267 | +/// Skipped, not failed, where the film or ffmpeg is not -- it is a 4K remux | ||
| 268 | +/// named by the local `real_library.toml`, not a fixture in this repository. | ||
| 269 | +#[test] | ||
| 270 | +fn a_seek_into_real_five_one_aac_film_lands_on_the_second_it_asked_for() { | ||
| 271 | + let Some(film) = engine::real_library::film("hevc_4k_pgs") else { | ||
| 272 | + return; | ||
| 273 | + }; | ||
| 274 | + if std::process::Command::new("ffmpeg") | ||
| 275 | + .arg("-version") | ||
| 276 | + .stdout(std::process::Stdio::null()) | ||
| 277 | + .stderr(std::process::Stdio::null()) | ||
| 278 | + .status() | ||
| 279 | + .map(|s| !s.success()) | ||
| 280 | + .unwrap_or(true) | ||
| 281 | + { | ||
| 282 | + eprintln!("skipped: no ffmpeg to decode the reference window with"); | ||
| 283 | + return; | ||
| 284 | + } | ||
| 285 | + const SEARCH: f64 = 5.0; | ||
| 286 | + for want in [600.0, 2400.0, 5400.0] { | ||
| 287 | + let (meta, rx) = AudioSession::open_at(&film, want) | ||
| 288 | + .expect("open") | ||
| 289 | + .expect("the film has audio"); | ||
| 290 | + assert_eq!(meta.sample_rate, 48_000); | ||
| 291 | + assert_eq!(meta.channels, 2, "5.1 reaches the timeline as a pair"); | ||
| 292 | + let rate = f64::from(meta.sample_rate); | ||
| 293 | + let channels = usize::from(meta.channels); | ||
| 294 | + let mut probe: Vec<f32> = Vec::with_capacity(meta.sample_rate as usize); | ||
| 295 | + for chunk in &rx { | ||
| 296 | + probe.extend( | ||
| 297 | + chunk | ||
| 298 | + .samples | ||
| 299 | + .chunks_exact(channels) | ||
| 300 | + .map(|f| f.iter().sum::<f32>() / channels as f32), | ||
| 301 | + ); | ||
| 302 | + if probe.len() >= meta.sample_rate as usize { | ||
| 303 | + break; | ||
| 304 | + } | ||
| 305 | + } | ||
| 306 | + drop(rx); | ||
| 307 | + probe.truncate(meta.sample_rate as usize); | ||
| 308 | + assert_eq!(probe.len(), meta.sample_rate as usize, "a second to locate"); | ||
| 309 | + | ||
| 310 | + let from = want - SEARCH; | ||
| 311 | + let reference = ffmpeg_mono(&film, from, 2.0 * SEARCH + 2.0, meta.sample_rate); | ||
| 312 | + let (lag, score) = best_lag(&probe, &reference); | ||
| 313 | + let at = from + lag as f64 / rate; | ||
| 314 | + eprintln!("asked {want}s, content at {at:.3}s (correlation {score:.3})"); | ||
| 315 | + assert!( | ||
| 316 | + score > 0.5, | ||
| 317 | + "asked {want}s: nothing in the reference window correlates ({score:.3}) -- \ | ||
| 318 | + the measurement, not the seek, is what failed" | ||
| 319 | + ); | ||
| 320 | + assert!( | ||
| 321 | + (at - want).abs() <= 0.05, | ||
| 322 | + "asked {want}s, heard {at:.3}s -- {:+.3}s of sound against picture", | ||
| 323 | + at - want | ||
| 324 | + ); | ||
| 325 | + } | ||
| 326 | +} | ||
| 327 | + | ||
| 259 | /// `dur` seconds of `path`'s first audio track from `start`, decoded by ffmpeg, | 328 | /// `dur` seconds of `path`'s first audio track from `start`, decoded by ffmpeg, |
| 260 | /// summed to mono at `rate`. The reference this engine's own landing is measured | 329 | /// summed to mono at `rate`. The reference this engine's own landing is measured |
| 261 | /// against, because a decoder cannot be its own witness about where it landed. | 330 | /// against, because a decoder cannot be its own witness about where it landed. |
crates/engine/tests/hevc_mkv.rsmodified+1 -1
| @@ -4,7 +4,7 @@ | |||
| 4 | //! Three things meet here and each is checked on its own: the demuxer reads an | 4 | //! Three things meet here and each is checked on its own: the demuxer reads an |
| 5 | //! `hvcC` out of a `CodecPrivate` and reframes Matroska blocks to Annex-B, the | 5 | //! `hvcC` out of a `CodecPrivate` and reframes Matroska blocks to Annex-B, the |
| 6 | //! plugin decodes Main 10 through a P010 surface pool, and the sound -- 5.1 AAC | 6 | //! plugin decodes Main 10 through a P010 surface pool, and the sound -- 5.1 AAC |
| 7 | -//! at 48 kHz -- is read by symphonia's mkv reader, decoded by `rusty_aac` and | 7 | +//! at 48 kHz -- is read by symphonia's mkv reader, decoded by `ec-aac` and |
| 8 | //! folded to the stereo one output device carries. | 8 | //! folded to the stereo one output device carries. |
| 9 | //! | 9 | //! |
| 10 | //! The container and audio checks need nothing installed. The decode twins need | 10 | //! The container and audio checks need nothing installed. The decode twins need |