Skip to content

Keep AAC frames that span more than two PES - #8200

Open
JayPokale wants to merge 1 commit into
video-dev:masterfrom
JayPokale:fix-aac-pes-overflow-span
Open

JayPokale wants to merge 1 commit into
video-dev:masterfrom
JayPokale:fix-aac-pes-overflow-span

Conversation

@JayPokale

Copy link
Copy Markdown

This PR will...

Keep collecting the bytes of an AAC (ADTS) frame when it continues through a PES that is too short to finish it, instead of pushing the half-filled frame and dropping the rest.

Why is this Pull Request needed?

When an ADTS frame is cut off at the end of a PES, parseAACPES stores the partly filled sample in aacOverFlow and fills in the missing bytes from the next PES. It assumes the next PES holds all of them. If the next PES is shorter than aacOverFlow.missing (audio repacked into small PES, as in the report), data.subarray(0, missing) is shorter than expected. The sample is pushed with a zero-filled tail, startOffset ends up past the end of the data, the overflow is cleared, and the PES after that no longer starts at an ADTS header. That gives AAC PES did not start with ADTS header,offset:N and, after the retries, a fatal fragParsingError.

Now, when the PES is shorter than the missing byte count, all of its bytes are copied into the pending sample, missing is reduced by that amount, and parsing continues with the next PES.

Are there any points in the code the reviewer needs to double check?

Only the early return in the else branch of parseAACPES. The case where the PES is exactly as long as missing still takes the old path.

Resolves issues:

Resolves #8197

I did not run the attached repro stream in a browser. The new unit test builds a TS segment with the same shape (a frame that starts in one PES, fills a second PES and ends in a third).

Verified locally:

  • npm run test:unit (Chrome headless): 1284 passed. With the src change reverted, the new test fails with a fragParsingError; with it, it passes.
  • npm run type-check, eslint and prettier --check on the two changed files: clean.
  • Not run: npm run build, npm run docs, npm run test:func.

I used an AI assistant (Claude Code) while working on this; I reviewed and tested the change.

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md (no API change)

This branch has not been deployed

No deployments
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.

parseAACPES drops overflow when ADTS frame spans more than two PES

1 participant