Merged
Conversation
Library packages should not commit pubspec.lock per Dart guidelines.
Prevents the rule from matching example/pubspec.lock, which caused a publish warning about checked-in files being gitignored.
Comprehensive analysis of all dart:ffi and wasm_ffi usage across the project, cross-referenced against the wasm_ffi documentation. Catalogues memory management patterns, pointer lifecycles, binding signatures, and identifies 19 potential risks including missing WASM exports, buffer sizing bugs, and use-after-destroy hazards.
All public methods on SimpleOpusEncoder, BufferedOpusEncoder, SimpleOpusDecoder, and BufferedOpusDecoder now throw OpusDestroyedError before touching native pointers if destroy() was already called. This prevents undefined behavior from dangling pointer access. Adds 10 regression tests covering every affected method.
- BufferedOpusDecoder: default maxOutputBufferSizeBytes now uses 4 * maxSamplesPerPacket to accommodate float output (was using raw sample count as byte count, 4x too small for floats). - StreamOpusDecoder: fix inverted multiplier from (floats ? 2 : 4) to (floats ? 4 : 2). - init_web.dart: replace duplicate OpusRepacketizer registration with missing OpusCustomMode. - Add unit tests confirming buffer sizing and update ffi-analysis.md.
- _asString now caps scanning at maxStringLength (256 bytes) and throws StateError if no null terminator is found, preventing unbounded loops. - Add _opus_encoder_ctl to EXPORTED_FUNCTIONS in Dockerfile so encoder CTL calls work on web. - Add unit tests for _asString bounds checking. - Update ffi-analysis.md to mark these issues as fixed.
Wrap both native allocations in try/finally for SimpleOpusEncoder, SimpleOpusDecoder, and pcmSoftClip. The second pointer is nullable and only freed if allocated, ensuring the first is always cleaned up. Add _FailingAllocator test helper and 5 new tests verifying that previously allocated memory is freed when a subsequent allocation fails.
Attach a Finalizer to SimpleOpusEncoder, SimpleOpusDecoder, BufferedOpusEncoder, and BufferedOpusDecoder so native memory is released if destroy() is never called. The cleanup closure captures only raw pointers (not this) and destroy() detaches the finalizer to prevent double-free.
StreamOpusEncoder and StreamOpusDecoder now always copy output to the Dart heap, eliminating use-after-write hazards when the native buffer is overwritten on the next encode/decode call. Also fixes FEC double-yield data corruption in StreamOpusDecoder. The copyOutput parameter is retained for API compatibility. Mark free(nullptr) as fixed in docs (resolved by earlier nullable inputNative change).
Emscripten compiles variadic C functions with a different ABI where args are passed via a stack buffer, not as direct WASM parameters. Add a non-variadic C wrapper (opus_encoder_ctl_int) compiled into the WASM module, and update the Dart binding to prefer the wrapper via try/catch fallback to the variadic symbol on native platforms.
Output getters (outputBuffer, outputBufferAsInt16List, outputBufferAsFloat32List) now return Dart-heap copies instead of native-backed views. StreamOpusEncoder.bind no longer caches the inputBuffer view. This prevents detached TypedArray errors when ALLOW_MEMORY_GROWTH replaces the underlying ArrayBuffer. Refactor StreamOpusEncoder.bind into focused private methods (_mapStream, _processChunk, _encodeCurrentBuffer, _flushRemaining, _padInputBuffer) with documentation.
Extract _createOpusEncoder helper shared by both factory constructors. Extract SimpleOpusEncoder._doEncode for common output-buffer lifecycle. Extract BufferedOpusEncoder._encodeBuffer with bool flag (no closure allocation). Improve BufferedOpusEncoder factory error handling so input buffer is freed if output allocation or encoder creation fails. Replace raw 2/4 literals with bytesPerInt16Sample and bytesPerFloatSample constants defined in opus_dart_misc.dart.
Correct misspellings across opus_dart_encoder.dart, opus_dart_decoder.dart and opus_dart_misc.dart (e.g. returnes, initalization, sampels, enocde, deocde, represntation, occurse, recieved, choosen, sucessfull, Wheter, maxDataByes, and grammar issues like 'this calls', 'to small', 'their is', 'an method').
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.
No description provided.