edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # Lane aacimplicit: implicit SBR signalling in ec-aac |
| 2 | |
| 3 | Base: main `fc963179`. Branch `lane/aacimplicit`. |
| 4 | |
| 5 | ## Goal |
| 6 | A stream whose AudioSpecificConfig or ADTS header says plain AAC-LC, but whose raw_data_block |
| 7 | carries an SBR extension payload, is HE-AAC by implicit signalling (ISO/IEC 14496-3 1.6.5.2). |
| 8 | ffmpeg, FAAD and the ISO reference decode it at twice the core rate. ec-aac used to output the |
| 9 | core rate only, at half bandwidth. edith hit this with bare ADTS HE-AAC files |
| 10 | (`lanes/edith-aacall.report.md`, "Known gap"). |
| 11 | |
| 12 | ## What changed |
| 13 | - `crates/ec-aac/src/decode.rs` (`BlockDecoder`): |
| 14 | - New fields `implicit_core` (core rate an implicit payload may double, `None` when off) and |
| 15 | `implicit_on` (switched on by a payload). |
| 16 | - `set_implicit_core(core_rate)`: arms detection only when no SBR is set, and only for a core |
| 17 | rate of at most 24000 Hz (doubled rate <= 48000). Above that the SBR payload is skipped and |
| 18 | the output stays at the core rate. |
| 19 | - In the FIL branch: on the first SBR extension (type 13/14) that follows an SCE/CPE, the SBR |
| 20 | chain is created at 2x the core rate for that element. If its payload does not parse, the |
| 21 | chain is dropped again, so a non-SBR fill never switches the rate. |
| 22 | - `implicit_sbr()` accessor. |
| 23 | - `crates/ec-aac/src/lib.rs` (`AacDecoder`): |
| 24 | - `with_config`: a plain-LC config (no SBR, no PS) arms implicit detection at its sample rate. |
| 25 | - ADTS decode path: arms implicit detection from the first frame's header rate. |
| 26 | - `sbr_implicit()` (new, public): true once an implicit payload has switched SBR on. |
| 27 | - `sbr_support()`: returns `SbrSupport::V1` once implicit SBR is on, so the stream reports |
| 28 | the SBR it actually decodes. Explicit behaviour is unchanged. |
| 29 | - `output_sample_rate()`: now also answers for ADTS-only decoders, so it is `None` before the |
| 30 | first frame and the core rate after it. It is the doubled rate once implicit SBR is on. |
| 31 | Explicit SBR and LC configs return the same values as before. |
| 32 | - Doc comments updated to say that callers should re-read the rate after each packet. |
| 33 | - `crates/ec-aac/tests/implicit_sbr.rs` (new): 3 tests (see below). |
| 34 | - `crates/ec-aac/tests/data/heaac_44100_48k_implicit_2s.aac` (new, 13.6 KB): 2 s of |
| 35 | `heaac_44100_48k.m4a` (HE-AAC v1, stereo, 44100 Hz) remuxed to bare ADTS with |
| 36 | `ffmpeg -t 2 -c copy -f adts`. ffprobe reads it as HE-AAC at 44100 Hz. Its ADTS headers say |
| 37 | LC at 22050 Hz, so the SBR signalling is implicit. |
| 38 | |
| 39 | ## Behaviour notes and limits |
| 40 | - The switch happens in the frame that first carries the SBR payload, so that frame is already |
| 41 | output at the doubled rate. This matches ffmpeg, which decodes the first frame with SBR. |
| 42 | - Frames before the first SBR payload would be at the core rate. In practice every SBR frame |
| 43 | carries its payload, so this does not arise in the fixture. |
| 44 | - Downsampled SBR (core above 24 kHz with SBR present): not implemented. The SBR chain has no |
| 45 | downsampled mode, so the SBR payload is skipped and the output stays at the core rate. An |
| 46 | implicit stream at 32/44.1/48 kHz core would therefore still be at the core rate, half the |
| 47 | bandwidth. This is documented, not silently claimed. |
| 48 | - Once an implicit payload has enabled SBR, a later frame with no SBR payload uses the last |
| 49 | payload's data (`apply_last`). This is the same as explicit streams. |
| 50 | - The detection is keyed on extension type 13/14 at the start of a FIL right after an SCE/CPE. |
| 51 | It is not a full syntax check, so a plain LC stream whose fill payload happens to start with |
| 52 | those bits and parses as SBR would be switched. Not seen in any fixture here. |
| 53 | |
| 54 | ## Tests |
| 55 | - `cargo test -p ec-aac --release --no-fail-fast` on the server (`remote-run`): all green. |
| 56 | - lib unit tests: 43 passed, 0 failed. |
| 57 | - `tests/implicit_sbr.rs` (new): 3 passed. |
| 58 | - `implicit_he_aac_adts_switches_to_double_rate`: no rate before frame 1; SBR implicit; rate |
| 59 | 44100 for every frame; stereo; about 2 s; both channels non-silent. |
| 60 | - `implicit_he_aac_adts_matches_ffmpeg_per_channel`: correlation with |
| 61 | `ffmpeg -i X -f f32le -` >= 0.999 per channel. |
| 62 | - `plain_aac_lc_adts_is_unchanged_by_implicit_detection`: `fixtures/audio/aac-adts-stereo-44100.aac` |
| 63 | stays at 44100 with no implicit switch (`NotSignalled`) and correlation >= 0.999 with ffmpeg. |
| 64 | - `oracle.rs`: 13 passed, 1 ignored (`real_library_tracks_match_ffmpeg`, pre-existing ignore for |
| 65 | the personal library). |
| 66 | - `sbr_real_library.rs`: 16 passed. `no_panic.rs`: 2 passed. `reelh_per_frame.rs`: 1 passed. |
| 67 | `obs_real_content.rs`: 1 passed. |
| 68 | - `cargo clippy -p ec-aac --all-targets -- -D warnings` on the server: clean, exit 0. |
| 69 | - `cargo check --workspace --all-targets` on the server: see the final message for the result. |
| 70 | - Caveat: test output was not captured with `--nocapture`, so the ffmpeg-correlation tests |
| 71 | reported ok without a visible SKIP. I did not verify that ffmpeg was on the server PATH, so the |
| 72 | ffmpeg comparison is only confirmed where ffmpeg runs. |
| 73 | |
| 74 | ## API change (for edith) |
| 75 | - `AacDecoder::sbr_implicit() -> bool` (new). |
| 76 | - `AacDecoder::sbr_support()` returns `V1` for an implicit stream once switched. |
| 77 | - `AacDecoder::output_sample_rate()` changes after the first implicit frame: the core rate |
| 78 | becomes 2x. For an ADTS decoder it is `None` until the first frame. |
| 79 | - edith impact: `crates/engine/src/audio.rs` takes the track rate from `aac_output_rate` at open, |
| 80 | which is still the core rate for bare ADTS HE-AAC. Edith needs to read the rate again after |
| 81 | the first decoded frame (or the rate must be handled in the packet path) before this fixes |
| 82 | edith playback. This lane does not change edith. |
| 83 | |
| 84 | ## Not done |
| 85 | - Downsampled SBR for core above 24 kHz. |
| 86 | - Edith-side rate refresh after the first implicit frame. |