Skip to content

fix(mux): parse the AAC program config element instead of guessing stereo - #4093

Merged
kixelated merged 5 commits into
quest/m1/audio-codecs/READMEfrom
quest/m1/audio-codecs/aac-pce
Sep 25, 2026
Merged

kixelated merged 5 commits into
quest/m1/audio-codecs/READMEfrom
quest/m1/audio-codecs/aac-pce

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Problem

An AAC channelConfiguration of 0 means a program config element (PCE) describes the channels. Both the AudioSpecificConfig parser and the ADTS (MPEG-TS) importer in moq-mux mapped 0, and every value from 8 to 15, to stereo with a warning. ffmpeg picks a PCE for any layout outside the standard table (quad, for example), so its 4-channel stream was advertised as stereo, and the synthesized description told decoders the same thing.

Approach

  • aac::Config::parse: config 0 walks the GASpecificConfig into the PCE and counts front, side, and back elements (2 per channel pair element, 1 per single channel element) plus LFEs. Explicit SBR/PS configs (AOT 5/29) are followed through to their core type. A non-general-audio object type with config 0 (for example ALS) is refused.
  • Configs 8 to 15: 11 is 7, 12 and 14 are 8, and 13 is 24 (ISO 14496-3 Table 1.19 as amended, matching ffmpeg's ff_mpeg4audio_channels). 8, 9, 10, and 15 are reserved and refused.
  • ADTS: the importer builds the description with a new crate-private aac::in_band_config. With config 0, it moves the PCE that leads the first raw data block into the AudioSpecificConfig, redoing the PCE's byte alignment, and then parses that config back with aac::config. The catalog count and the description therefore come from one parser. On the ffmpeg fixture, the result matches ffmpeg's own MP4 extradata byte for byte, apart from ffmpeg's trailing sync extension.
  • ADTS config 0 without a PCE leading the first block is refused. The he-aac-refusal finding holds: reaching an element after the channel data needs a full Huffman walk. The leading position is where ffmpeg puts the PCE, so no walk is needed here. A stream joined after its only PCE (ffmpeg writes it once) is refused.
  • Regression tests: an ffmpeg quad TS fixture (aac_quad.ts, 2.6 KB) and ffmpeg's quad ASC report 4 channels (both reported 2 before this change). The tests also cover synthesized 5.1 and 3/2/2 PCEs, a PCE behind explicit SBR, empty and truncated PCEs, a non-GA AOT, an ADTS block without a leading PCE, and every config value from 1 to 15.

Impact

  • moq_mux::codec::aac::Error gains ReservedChannelConfig, ProgramConfigUnsupported, ProgramConfigMissing, ProgramConfigTruncated, and ProgramConfigEmpty. The enum is #[non_exhaustive], so this is additive.
  • Behavior: Config::parse, and every importer built on it (MKV, FLV, MSF, import::Track, TS), now reports a PCE's real count and refuses reserved configs instead of reporting stereo.
  • No wire or catalog format change.

Alternatives

  • Add a pce field to the public aac::Config so encode() can reproduce it. That breaks the published struct literal, and the crate-private in_band_config covers the only caller that needs it. Not done.
  • Error variant naming: the quest said Error::Unsupported. I used typed variants following the existing UnsupportedSampleRateIndex(u8) so callers can match on the reason. A single Unsupported(String) is the alternative.
  • In ADTS, drop frames until one leads with a PCE, instead of refusing. ffmpeg writes the PCE only once, so this would wait forever. Refusing matches "supported or refused".

Follow-ups

  • aac::Config::encode (and js/hang's audioSpecificConfig) still warn and write stereo for a count the table can't name. Making them fail needs a fallible signature, which is a dev break.
  • MPEG-TS export writes an ADTS channel_config from the count, so a PCE-described track re-exported to TS is mislabeled. It should write 0 and emit the PCE from the description.
  • The PCE's layout (front/side/back/LFE) is not mapped to a Layout yet. That belongs to the Layout quest.
  • he-aac-refusal.md loses its Related link here, and chore(quest): abandon he-aac-refusal #4090 deletes that file. Whichever merges second resolves a trivial modify/delete conflict.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 2 commits September 24, 2026 19:37
…ereo

A channelConfiguration of 0 now takes its count from the PCE, in the
AudioSpecificConfig or leading the first ADTS raw data block; reserved
configurations are refused and 11 to 14 map to their real counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review September 25, 2026 03:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T06:57:01.825378Z 68aab63 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 696adeb995

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +31 to +32
#[error("reserved channelConfiguration: {0}")]
ReservedChannelConfig(u8),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the new public error variants

Add one-line rustdoc comments to all five new Error variants. The #[error(...)] attributes only implement Display and do not appear as API documentation, so these newly exported symbols violate the repository's public API documentation requirement.

AGENTS.md reference: AGENTS.md:L67-L67

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push: each new variant now has a one-line doc comment.

(Written by Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Pushed a quest-only commit to this branch as part of the spawn-quests follow-up planning (see #4105), so the follow-up rides with the PR that surfaced it. No code changes.

(Written by Claude Opus 5.5)

kixelated and others added 2 commits September 24, 2026 23:41
@kixelated
kixelated merged commit c31063b into quest/m1/audio-codecs/README Sep 25, 2026
4 checks passed
@kixelated
kixelated deleted the quest/m1/audio-codecs/aac-pce branch September 25, 2026 07:17
@kixelated

Copy link
Copy Markdown
Collaborator Author

Landed. Before merging:

  • Merged main into the line branch quest/m1/audio-codecs/README (21 commits behind), then merged the line into this branch.
  • Added one-line rustdoc to the five new aac::Error variants (Codex finding).
  • CI (Check, Test, Android) passed on 68aab63, and Codex reviewed it with no findings.

#4090 targets the same line and resolves the he-aac-refusal.md modify/delete conflict next.

(Written by Claude Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant