Repository navigation
Ignore parse errors on trailing data after the mdat atom of MP4 streams - #147
Open
chrizzchrizz wants to merge 1 commit into
Open
chrizzchrizz wants to merge 1 commit into
chrizzchrizz wants to merge 1 commit into
Conversation
Some M4A files carry trailing padding after mdat (e.g. zero bytes left by tag editors). AudioFileStreamParseBytes rejects it with kAudioFileStreamError_InvalidFile once the stream reaches it, although all audio packets have been parsed already, which raised streamParseBytesFailure shortly before the end of the song. Track the stream byte offset passed to the parser. When parsing fails after dataOffset + audioDataByteCount of an MP4 stream, ignore the error and the rest of the stream. All bytes are still parsed as before, so no audio can be dropped, and errors inside the audio data are reported as before.
Author
|
Audio streaming isn't my area of expertise. So I had to rely on Claude Code to fix the issue. In my opinion, it worked well and the bug is gone, but I need your expertise for the final assessment. Thx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some M4A files carry trailing data after the
mdatatom, for example zero bytes left as padding by tag editors. Once the stream reaches it,AudioFileStreamParseBytesfails withkAudioFileStreamError_InvalidFile('dta?'), although every audio packet has been parsed already. The player then raisesstreamParseBytesFailurewhile the entry is still playing, about one buffer length before the audible end of the track.Seen with a real file:
ftyp,moov,free,mdat(ends at byte 4885649), then 32648 zero bytes up to the end of the file. The same happens with a plainAudioFileStreamoutside the library, and all 7756 audio packets are delivered before the error.Change
AudioFileStreamProcessortracks the stream byte offset of the data passed to the parser (reset on open, set to the seek offset inprocessSeek).dataOffset + audioDataByteCount, the error is ignored and the rest of the stream is dropped. The final flush is skipped in that case.audioDataByteCountis smaller than themdatatom (e.g. chapter tracks insidemdat). Errors inside the audio data are reported as before.Tests
Mp4TrailingDataTests:mdat, fed in 1 KB chunks throughAudioFileStreamProcessor: all chunks and the final flush returnnoErrand no error is raised. Without the change this test fails with1685348671('dta?') at the chunk that crosses the end ofmdat.The full test suite passes on macOS.