Closed anthumchris closed 3 years ago
The discussion in #39 is related. In general Bring You Own Buffer (often refered to as BYOB) are favored these days when designing new specs.
We've had the BYOB request from WASM folks as well, and we're keen to do something here. Unfortunately, using a SAB for output creates security concerns because the decoder may internally reference a decoded frame for sometime while it continues to decode later frames. Apps could manipulate the SAB during this period and cause crashes.
We're involved in a cross team (WASM, WebGPU, ...) discussion for memory re-use / reducing copies. The WebCodecs position is here: https://github.com/WICG/reducing-memory-copies/issues/1
I'll go ahead and close and continue tracking in that repo.
Would it be helpful to offer APIs that use pre-defined ring buffers to reduce garbage collection and maintain low latency?
SharedArrayBuffer
(SAB) could also be used for cross-realm/thread processing and browser support is returning.Additionally, would it be helpful to control the decoder by specifying how many samples/frames to decode per call? We could decode quickly at first for low-latency playback and then gradually increase frame sizes after we have enough decoded data for playback continuity.
For example, consider a streaming audio AudioWorklet where GC is reduced using ring buffers and specifying 128 samples to decode synchronously (relates to https://github.com/WICG/web-codecs/issues/19).
audio-worklet-processer.js