Skip to content

fix android: detect ADTS before AC-3 syncwords - #611

Merged
alnitak merged 1 commit into
alnitak:mainfrom
EmiDS17:fix/android-adts-ac3-misdetection
Nov 10, 2026
Merged

alnitak merged 1 commit into
alnitak:mainfrom
EmiDS17:fix/android-adts-ac3-misdetection

Conversation

@EmiDS17

@EmiDS17 EmiDS17 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #610

On Android, valid AAC audio in ADTS framing could be misdetected as AC-3 when its compressed payload contained the byte sequence 0x0B77.

NativeAudioDecoder::decodeMemory() previously searched the entire input for an AC-3/E-AC-3 syncword before checking the ADTS header at the beginning of the input.
This could select BUFFER_AC3 for valid AAC data and attempt to initialize an audio/ac3 decoder, producing:

  Failed to pre-create AMediaCodec for audio/ac3
  Failed to initialize elementary stream decoder on Android for format 11

This PR changes both decodeMemory() and decodeFile() to check for an ADTS header at the start of the input, after an optional ID3 tag, before searching for AC-3/E-AC-3. Genuine AC-3/E-AC-3 detection remains unchanged.

A native regression test was added using the existing sample-AAC.aac fixture with an AC-3-like suffix.
The test verifies that:

  • The input is decoded successfully as AAC.
  • The decoded sample rate, channel count, and PCM frame count are unchanged.
  • The decoded PCM is identical to the original AAC fixture.

Testing:

  • Android ARM64 physical device: all Android native decoder tests passed.
  • Android x86_64 emulator: the new regression test passed. One unrelated mono-M4A duration failure remains and was also present before these changes.
  • git diff --check passed.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

AAC payloads can contain 0x0B77, causing whole-file loads to be misclassified as AC-3. Prefer an ADTS header at the start of the input in both file and memory decoding, and cover it with a native regression test.
@alnitak

alnitak commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thank you!

@alnitak
alnitak merged commit c3e4382 into alnitak:main Nov 10, 2026
1 check passed
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.

fix: Android - valid AAC ADTS is misdetected as AC-3 when its payload contains an AC-3 syncword

2 participants