Skip to content

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

Open
andretorresdg wants to merge 1 commit into
video-dev:masterfrom
andretorresdg:bugfix/aac-overflow-multi-pes
Open

andretorresdg wants to merge 1 commit into
video-dev:masterfrom
andretorresdg:bugfix/aac-overflow-multi-pes

Conversation

@andretorresdg

Copy link
Copy Markdown

This PR will...

Keep an incomplete ADTS frame pending in TSDemuxer.parseAACPES until a later PES completes it, instead of assuming the next PES always holds the rest of the frame.

Why is this Pull Request needed?

When an ADTS frame overflows a PES, parseAACPES stores it in aacOverFlow with the number of missing bytes. On the next PES it copies data.subarray(0, missing) into the frame, pushes the sample and starts scanning at missing. If the next PES is shorter than missing (the frame spans three or more PES, e.g. 320 kb/s AAC repacked into 720-byte PES as in #8197):

  • the sample is pushed with its tail still zero-filled,
  • the overflow state is dropped, so the remaining frame bytes in the following PES are not recognised,
  • that PES raises AAC PES did not start with ADTS header, and the retries eventually end in a fatal fragParsingError.

With this change, when the PES carries fewer bytes than the frame is missing, they are copied into the frame, missing is reduced and the overflow is kept for the next PES. The existing path (frame completed by the next PES) is unchanged.

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

  • A PES that only carries the middle of a frame returns early, so its PTS (if any) is not used. No frame starts in that PES, so there is no sample for it to apply to; the next frame's PTS is still derived from the overflowing frame as before.
  • fix: skip AAC PES without ADTS headers instead of triggering fragPars… #7952 also touches parseAACPES (skipping PES without ADTS headers). This change is independent: it covers frames that are split across more than two PES, which are valid streams.

Resolves issues:

Fixes #8197

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)

How I tested

  • Added a unit test in tests/unit/demuxer/tsdemuxer.ts that feeds a 2000-byte ADTS frame followed by a 100-byte frame to parseAACPES as three 720-byte PES. It checks that no error is emitted and that both samples have the full payload and contiguous PTS. It fails on master (AAC PES did not start with ADTS header / No ADTS header found in AAC PES) and passes with the fix.
  • Unit suite in headless Chromium (all specs except the e2e/cmcd one, which times out in my sandbox without network): 1266 passing. eslint and prettier --check on the changed files, and npm run type-check.

When an ADTS frame overflowed a PES, parseAACPES assumed the next PES
held the rest of it. If the frame also spanned that PES (small PES
repacked by broadcast muxers), the incomplete frame was pushed, the
overflow state was dropped, and the following PES raised
"AAC PES did not start with ADTS header" parsing errors.

Keep the overflow pending until a PES completes the frame.

Fixes video-dev#8197

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