Skip to content

Make AudioBuffer Transferable  #2390

@chcunningham

Description

@chcunningham

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.

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]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: enhancementSubstantive changes that do not add new features. https://www.w3.org/policies/process/#class-3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions