Skip to content

Release 3.0.5#3

Merged
ppamorim merged 21 commits intomasterfrom
development
Feb 25, 2026
Merged

Release 3.0.5#3
ppamorim merged 21 commits intomasterfrom
development

Conversation

@ppamorim
Copy link
Member

No description provided.

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').
@ppamorim ppamorim changed the title Development Release 3.0.5 Feb 25, 2026
@ppamorim ppamorim merged commit 7e0233f into master Feb 25, 2026
7 checks passed
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.

1 participant