Repository navigation
fix(ios): decoder entry at CRA, reorder drain, AAC config and ADTS, bitrateMode, range and surface pinning - #4
Merged
Merged
Conversation
…goes back in time
…e encoder writes VideoToolbox gets bitrateMode: "quantizer" is refused (no per-frame QP outside the low-latency H.264 mode), so Mediabunny's Quality presets fall back to a bitrate instead of VT's default rate; "constant" uses ConstantBitRate on iOS 16+ when the encoder has it; "variable" caps each second at 1.5x the bitrate with DataRateLimits. The decoder config's colorSpace says limited range, as the encoders write, instead of copying the frames' fullRange (Mediabunny wrote a full-range colr over a video-range SPS). Decoded RGB frames are tagged full range.
A CVPixelBufferPool reuses an IOSurface once its use count is zero, whatever its retain count, so a producer (camera, AVAssetWriter) could write a newer image into a wrapped frame held before encode().
…er when a key frame goes back in time Drop kVTVideoDecoderReferenceMissingErr frames instead of failing, set ResetDecoderBeforeDecoding on a stream's first key frame, and skip HEVC RASL pictures after a CRA/BLA entry until the next IRAP. A key frame earlier than what was decoded since the last flush drains the held frames first; flush() and that drain restore the stream's reorder depth. failed is written under the reorder lock.
…the AudioDecoder on flush - AudioDecoder wraps config.description in an esds magic cookie, takes the format from it (kAudioFormatProperty_FormatList: HE-AAC and HE-AAC v2 at their full rate and channels, 2048 frames a packet) and reports the converter's output rate and channels (#3). - AAC without a description is ADTS: JS builds the AudioSpecificConfig and strips each chunk's header, on both platforms; mp4a.40.5/29 decode (#2). - flush() ends the converter's stream and resets it, so what is decoded after it does not overlap what came before (#10). Refs #2
…ast swings; no ADTS config for 7 channels
… in time comes out The emulator's c2 decoders put the earlier GOP out in decode order and hold the later GOP's last frames until the end of the stream; iOS keeps the strict order check.
After the end of the stream, a reset AudioConverter put out no more audio on the CI Simulator, so the decode after a flush gave no samples. flush() now makes a new converter from the same formats and magic cookie.
…scratch - Audio: makeConverter moves to file scope, and the AudioEncoder uses it instead of its own AudioConverterNew call. - Audio: the AudioDecoder's pull() allocates its sample buffer once per call rather than once per pass of the drain loop. - VideoDecoder: flush() and a key frame that goes back in time share one endStream() helper. - VideoDecoder: the HEVC NAL length size comes from the format description VideoToolbox made of the hvcC record, rather than reading the record a second time.
This was referenced Nov 25, 2026
|
🎉 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.
This fixes 8 items from issue 2 (iOS problems that other projects ran into with VideoToolbox, AudioToolbox and IOSurface). Each fix comes with an e2e test that fails on
mainon the iOS Simulator and passes here.Video decoder (
ios/VideoDecoder.swift)kVTVideoDecoderReferenceMissingErr(-17694) now drops the frame instead of failing the decoder. The first key sample after configure, flush or a backward jump getsResetDecoderBeforeDecoding. For HEVC, RASL pictures after a CRA/BLA entry are skipped until the next IRAP.depthgoes back to the SPS value on flush.failedflag is now written under the reorder lock.Audio (
ios/Audio.swift,src/lib/audio.ts)kAudioFormatProperty_FormatInfo, so HE-AAC and HE-AACv2 decode at the right rate and length.AudioDecoder.flush()ends the stream and starts the next one on a new AudioConverter, made from the same formats and magic cookie. A reset converter put out no audio after the end of the stream on the CI Simulator.Video encoder (
src/lib/video.ts,ios/VideoEncoder.swift,ios/Surface.swift)bitrateMode. It is now passed to native."quantizer"is reported as unsupported, so Mediabunny's Quality presets fall back to a bitrate.fullRange.decoderConfig.colorSpace.fullRangereports what the encoder wrote. RGB output frames from the decoder are tagged correctly.Tests
mainand pass here. The full e2e suite passes 65/65. It also passes 65/65 on a physical iPhone (iOS 27.2.1), and the audio and key-frame tests pass again there after the flush change.mainpasses 65/65. The branch changes no Android code; it only adds an optionalbitrateModefield to the shared config struct, which Android ignores.main, so the Android run only checks that every frame comes out. A separate fix for that is in progress.yarn tsc,yarn lintandyarn test:unitpass.Not covered by tests
Nothing was tried on a physical iPhone.