-
Notifications
You must be signed in to change notification settings - Fork 172
Description
Describe the feature
Follow up stemming from WebAudio/web-audio-api-v2#111. Once AudioBuffer is exposed to DedicatedWorker, we'll want to transfer AudioBuffers created elsewhere into the DedicatedWorker.
Is there a prototype?
Chromium would like to prototype ASAP and ship this alongside the rest of the WebCodecs API.
Describe the feature in more detail
The pressing use case is using WebCodecs to encode audio in a worker that originated from the user's microphone (getUserMedia). The audio will be sent to the worker by transferring the MediaStreamTrackProcessor readable ReadableStream. The individual AudioFrames in the stream will themselves be transferred, which would trigger transfer of their nested AudioBuffers.
Transferring is a move operation, so we must consider what happens to the object that is left behind. I propose that we follow the model of ArrayBuffer.
- transferring an ArrayBuffer detaches it
- detaching sets length 0, clears underlying data, marks it "detached"
- you can no longer use it for things like making a Uin8ArrayBuffer (throws TypeError)
Doing the same for AudioBuffer, would probably entail
- add a "detached" slot to AudioBuffer.
- update APIs where AudioBuffer is an input to throw TypeError if given a detached AudioBuffer. At a glance, those are:
- AudioBufferSourceNode constructor
- AudioBufferSourceNode.buffer setter steps
- ConvolverNode constructor
- ConvolverNode setter steps
- and the WebCodecs AudioFrame constructor
- update AudioBuffer the 3 methods to throw InvalidStateError if called when detached is true
- add transfer steps for AudioBuffer
- assign true to [[detached]]
- assign 0 to [[number of channels]]
- assign 0 to [[length]]
- assign 0 to [[sample rate]]
- assign null to [[internal data]]