Repository navigation
fix(ios): keep small AAC packets alive while the AudioConverter reads them - #10
Merged
Merged
Conversation
… them provide() passed AudioToolbox a pointer from Data.withUnsafeMutableBytes, which is only valid inside the closure. A Data of 14 bytes or less is stored inline, so for silent AAC packets (4 bytes) the converter read a temporary copy and put out nothing, with no error. The packet and its description now live in memory the decoder owns until the next call. pull() also checks for a converter error before treating 0 frames as the end, so such a failure is reported instead of swallowed.
A new converter on flush was a workaround for samples missing after a flush on CI. The real cause was the small packets fixed in the previous commit: the decode after the flush was of silent, 4-byte packets. AudioConverterReset is enough.
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 25, 2026
## [0.1.3](v0.1.2...v0.1.3) (2026-11-25) ### Bug Fixes * **android:** put out a GOP that goes back in time after the one before it ([e0eb929](e0eb929)) * **example:** load the export's sound in Android release builds ([0cd1af8](0cd1af8)) * **ios:** decode AAC from its AudioSpecificConfig, ADTS, and restart the AudioDecoder on flush ([b78c863](b78c863)), closes [#3](#3) [#2](#2) [#10](#10) [#2](#2) * **ios:** decode from a CRA or recovery point, drain the reorder buffer when a key frame goes back in time ([5c3e02a](5c3e02a)) * **ios:** forward bitrateMode, refuse quantizer, and tag the range the encoder writes ([05e9063](05e9063)) * **ios:** keep small AAC packets alive while the AudioConverter reads them ([d8f2742](d8f2742)) * **ios:** pin a wrapped surface's use count until the frame is closed ([99d3aa6](99d3aa6)) * **ios:** start an AudioDecoder over on flush with a new AudioConverter ([9cb6fd4](9cb6fd4))
|
🎉 This PR is included in version 0.1.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
The iOS
AudioDecoderput out nothing for AAC packets of 14 bytes or less, and reported no error. This is why "starts an AudioDecoder over after a flush (iOS)" has failed on every CI run onmain.Cause
provide()inios/Audio.swiftpassed AudioToolbox a pointer fromData.withUnsafeMutableBytes, which is only valid inside the closure. ADataof 14 bytes or less keeps its bytes inline, so the pointer pointed at a temporary copy. The converter reads the packet afterprovide()returns, so it read whatever was left there. The silent packets in the test clip are 4 bytes each. On a local Mac the memory happened to still hold the packet, so the test passed there.Fix
AudioStreamPacketDescriptionnow live in memory the decoder allocates. They stay valid until the next input call and are freed then, or indeinit. The encoder already did this.pull()checks for a converter error before it treats 0 frames as the end of the stream. A failure is now reported instead of being swallowed.How it was found
A diagnostic run on CI (run 45649412237, branch
diag/audio-flush-ci, not for merging) showed:So
flush()was not the problem.Simplification
flush()used to make a new AudioConverter instead of callingAudioConverterReset, because the samples after a flush were missing on CI. Those samples were the 4-byte silent packets, so the reset was never the cause.flush()now callsAudioConverterResetagain, and the three fields that were kept only to rebuild the converter are gone.Tests
mainruns.yarn tscpasses.