WebCodecs

Editor’s Draft,

More details about this document
This version:
https://w3c.github.io/webcodecs/
Latest published version:
https://www.w3.org/TR/webcodecs/
Feedback:
GitHub
Inline In Spec
Editors:
Paul Adenot (Mozilla)
Eugene Zemtsov (Google LLC)
Former Editors:
Bernard Aboba (Microsoft Corporation)
Chris Cunningham (Google LLC)
Participate:
Git Repository.
File an issue.
Version History:
https://github.com/w3c/webcodecs/commits

Abstract

This specification defines interfaces to codecs for encoding and decoding of audio, video, and images.

This specification does not specify or require any particular codec or method of encoding or decoding. The purpose of this specification is to provide JavaScript interfaces to implementations of existing codec technology developed elsewhere. Implementers are free to support any combination of codecs or none at all.

Status of this document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C standards and drafts index.

Feedback and comments on this specification are welcome. GitHub Issues are preferred for discussion on this specification. Alternatively, you can send comments to the Media Working Group’s mailing-list, public-media-wg@w3.org (archives). This draft highlights some of the pending issues that are still to be discussed in the working group. No decision has been taken on the outcome of these issues including whether they are valid.

This document was published by the Media Working Group as an Editor’s Draft. This document is intended to become a W3C Recommendation.

Publication as an Editor’s Draft does not imply endorsement by W3C and its Members.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent that the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 18 August 2025 W3C Process Document.

1. Definitions

Codec

Refers generically to an instance of AudioDecoder, AudioEncoder, VideoDecoder, or VideoEncoder.

Key Chunk

An encoded chunk that does not depend on any other frames for decoding. Also commonly referred to as a "key frame".

Internal Pending Output

Codec outputs such as VideoFrames that currently reside in the internal pipeline of the underlying codec implementation. The underlying codec implementation MAY emit new outputs only when new inputs are provided. The underlying codec implementation MUST emit all outputs in response to a flush.

Codec System Resources

Resources including CPU memory, GPU memory, and exclusive handles to specific decoding/encoding hardware that MAY be allocated by the User Agent as part of codec configuration or generation of AudioData and VideoFrame objects. Such resources MAY be quickly exhausted and SHOULD be released immediately when no longer in use.

Temporal Layer

A grouping of EncodedVideoChunks whose timestamp cadence produces a particular framerate. See scalabilityMode.

Progressive Image

An image that supports decoding to multiple levels of detail, with lower levels becoming available while the encoded data is not yet fully buffered.

Progressive Image Frame Generation

A generational identifier for a given Progressive Image decoded output. Each successive generation adds additional detail to the decoded output. The mechanism for computing a frame’s generation is implementer defined.

Primary Image Track

An image track that is marked by the given image file as being the default track. The mechanism for indicating a primary track is format defined.

RGB Format

A VideoPixelFormat containing red, green, and blue color channels in any order or layout (interleaved or planar), and irrespective of whether an alpha channel is present.

sRGB Color Space

A VideoColorSpace object, initialized as follows:

  1. [[primaries]] is set to bt709,

  2. [[transfer]] is set to iec61966-2-1,

  3. [[matrix]] is set to rgb,

  4. [[full range]] is set to true

Display P3 Color Space

A VideoColorSpace object, initialized as follows:

  1. [[primaries]] is set to smpte432,

  2. [[transfer]] is set to iec61966-2-1,

  3. [[matrix]] is set to rgb,

  4. [[full range]] is set to true

REC709 Color Space

A VideoColorSpace object, initialized as follows:

  1. [[primaries]] is set to bt709,

  2. [[transfer]] is set to bt709,

  3. [[matrix]] is set to bt709,

  4. [[full range]] is set to false

Codec Saturation

The state of an underlying codec implementation where the number of active decoding or encoding requests has reached an implementation specific maximum such that it is temporarily unable to accept more work. The maximum may be any value greater than 1, including infinity (no maximum). While saturated, additional calls to decode() or encode() will be buffered in the control message queue, and will increment the respective decodeQueueSize and encodeQueueSize attributes. The codec implementation will become unsaturated after making sufficient progress on the current workload.

2. Codec Processing Model

2.1. Background

This section is non-normative.

The codec interfaces defined by the specification are designed such that new codec tasks can be scheduled while previous tasks are still pending. For example, web authors can call decode() without waiting for a previous decode() to complete. This is achieved by offloading underlying codec tasks to a separate parallel queue for parallel execution.

This section describes threading behaviors as they are visible from the perspective of web authors. Implementers can choose to use more threads, as long as the externally visible behaviors of blocking and sequencing are maintained as follows.

2.2. Control Messages

A control message defines a sequence of steps corresponding to a method invocation on a codec instance (e.g. encode()).

A control message queue is a queue of control messages. Each codec instance has a control message queue stored in an internal slot named [[control message queue]].

Queuing a control message means enqueuing the message to a codec’s [[control message queue]]. Invoking codec methods will generally queue a control message to schedule work.

Running a control message means performing a sequence of steps specified by the method that enqueued the message.

The steps of a given control message can block processing later messages in the control message queue. Each codec instance has a boolean internal slot named [[message queue blocked]] that is set to true when this occurs. A blocking message will conclude by setting [[message queue blocked]] to false and rerunning the Process the control message queue steps.

All control messages will return either "processed" or "not processed". Returning "processed" indicates the message steps are being (or have been) executed and the message may be removed from the control message queue. "not processed" indicates the message must not be processed at this time and should remain in the control message queue to be retried later.

To Process the control message queue, run these steps:

  1. While [[message queue blocked]] is false and [[control message queue]] is not empty:

    1. Let front message be the first message in [[control message queue]].

    2. Let outcome be the result of running the control message steps described by front message.

    3. If outcome equals "not processed", break.

    4. Otherwise, dequeue front message from the [[control message queue]].

2.3. Codec Work Parallel Queue

Each codec instance has an internal slot named [[codec work queue]] that is a parallel queue.

Each codec instance has an internal slot named [[codec implementation]] that refers to the underlying platform encoder or decoder. Except for the initial assignment, any steps that reference [[codec implementation]] will be enqueued to the [[codec work queue]].

Each codec instance has a unique codec task source. Tasks queued from the [[codec work queue]] to the event loop will use the codec task source.

3. AudioDecoder Interface

[Exposed=(Window,DedicatedWorker), SecureContext]
interface AudioDecoder : EventTarget {
  constructor(AudioDecoderInit init);

  readonly attribute CodecState state;
  readonly attribute unsigned long decodeQueueSize;
  attribute EventHandler ondequeue;

  undefined configure(AudioDecoderConfig config);
  undefined decode(EncodedAudioChunk chunk);
  Promise<undefined> flush();
  undefined reset();
  undefined close();

  static Promise<AudioDecoderSupport> isConfigSupported(AudioDecoderConfig config);
};

dictionary AudioDecoderInit {
  required AudioDataOutputCallback output;
  required WebCodecsErrorCallback error;
};

callback AudioDataOutputCallback = undefined(AudioData output);

3.1. Internal Slots

[[control message queue]]

A queue of control messages to be performed upon this codec instance. See [[control message queue]].

[[message queue blocked]]

A boolean indicating when processing the [[control message queue]] is blocked by a pending control message. See [[message queue blocked]].

[[codec implementation]]

Underlying decoder implementation provided by the User Agent. See [[codec implementation]].

[[codec work queue]]

A parallel queue used for running parallel steps that reference the [[codec implementation]]. See [[codec work queue]].

[[codec saturated]]

A boolean indicating when the [[codec implementation]] is unable to accept additional decoding work.

[[output callback]]

Callback given at construction for decoded outputs.

[[error callback]]

Callback given at construction for decode errors.

[[key chunk required]]

A boolean indicating that the next chunk passed to decode() MUST describe a key chunk as indicated by [[type]].

[[state]]

The current CodecState of this AudioDecoder.

[[decodeQueueSize]]

The number of pending decode requests. This number will decrease as the underlying codec is ready to accept new input.

[[pending flush promises]]

A list of unresolved promises returned by calls to flush().

[[dequeue event scheduled]]

A boolean indicating whether a dequeue event is already scheduled to fire. Used to avoid event spam.

3.2. Constructors

AudioDecoder(init)
  1. Let d be a new AudioDecoder object.

  2. Assign a new queue to [[control message queue]].

  3. Assign false to [[message queue blocked]].

  4. Assign null to [[codec implementation]].

  5. Assign the result of starting a new parallel queue to [[codec work queue]].

  6. Assign false to [[codec saturated]].

  7. Assign init.output to [[output callback]].

  8. Assign init.error to [[error callback]].

  9. Assign true to [[key chunk required]].

  10. Assign "unconfigured" to [[state]]

  11. Assign 0 to [[decodeQueueSize]].

  12. Assign a new list to [[pending flush promises]].

  13. Assign false to [[dequeue event scheduled]].

  14. Return d.

3.3. Attributes

state, of type CodecState, readonly

Returns the value of [[state]].

decodeQueueSize, of type unsigned long, readonly

Returns the value of [[decodeQueueSize]].

ondequeue, of type EventHandler

An event handler IDL attribute whose event handler event type is dequeue.

3.4. Event Summary

dequeue

Fired at the AudioDecoder when the decodeQueueSize has decreased.

3.5. Methods

configure(config)
Enqueues a control message to configure the audio decoder for decoding chunks as described by config.

NOTE: This method will trigger a NotSupportedError if the User Agent does not support config. Authors are encouraged to first check support by calling isConfigSupported() with config. User Agents don’t have to support any particular codec type or configuration.

When invoked, run these steps:

  1. If config is not a valid AudioDecoderConfig, throw a TypeError.

  2. If [[state]] is “closed”, throw an InvalidStateError.

  3. Set [[state]] to "configured".

  4. Set [[key chunk required]] to true.

  5. Queue a control message to configure the decoder with config.

  6. Process the control message queue.

Running a control message to configure the decoder means running these steps:

  1. Assign true to [[message queue blocked]].

  2. Enqueue the following steps to [[codec work queue]]:

    1. Let supported be the result of running the Check Configuration Support algorithm with config.

    2. If supported is false, queue a task to run the Close AudioDecoder algorithm with NotSupportedError and abort these steps.

    3. If needed, assign [[codec implementation]] with an implementation supporting config.

    4. Configure [[codec implementation]] with config.

    5. queue a task to run the following steps:

      1. Assign false to [[message queue blocked]].

      2. Queue a task to Process the control message queue.

  3. Return "processed".

decode(chunk)
Enqueues a control message to decode the given chunk.

When invoked, run these steps:

  1. If [[state]] is not "configured", throw an InvalidStateError.

  2. If [[key chunk required]] is true:

    1. If chunk.[[type]] is not key, throw a DataError.

    2. Implementers SHOULD inspect the chunk’s [[internal data]] to verify that it is truly a key chunk. If a mismatch is detected, throw a DataError.

    3. Otherwise, assign false to [[key chunk required]].

  3. Increment [[decodeQueueSize]].

  4. Queue a control message to decode the chunk.

  5. Process the control message queue.

Running a control message to decode the chunk means performing these steps:

  1. If [[codec saturated]] equals true, return "not processed".

  2. If decoding chunk will cause the [[codec implementation]] to become saturated, assign true to [[codec saturated]].

  3. Decrement [[decodeQueueSize]] and run the Schedule Dequeue Event algorithm.

  4. Enqueue the following steps to the [[codec work queue]]:

    1. Attempt to use [[codec implementation]] to decode the chunk.

    2. If decoding results in an error, queue a task to run the Close AudioDecoder algorithm with EncodingError and return.

    3. If [[codec saturated]] equals true and [[codec implementation]] is no longer saturated, queue a task to perform the following steps:

      1. Assign false to [[codec saturated]].

      2. Process the control message queue.

    4. Let decoded outputs be a list of decoded audio data outputs emitted by [[codec implementation]].

    5. If decoded outputs is not empty, queue a task to run the Output AudioData algorithm with decoded outputs.

  5. Return "processed".

flush()
Completes all control messages in the control message queue and emits all outputs.

When invoked, run these steps:

  1. If [[state]] is not "configured", return a promise rejected with InvalidStateError DOMException.

  2. Set [[key chunk required]] to true.

  3. Let promise be a new Promise.

  4. Append promise to [[pending flush promises]].

  5. Queue a control message to flush the codec with promise.

  6. Process the control message queue.

  7. Return promise.

Running a control message to flush the codec means performing these steps with promise.

  1. Enqueue the following steps to the [[codec work queue]]:

    1. Signal [[codec implementation]] to emit all internal pending outputs.

    2. Let decoded outputs be a list of decoded audio data outputs emitted by [[codec implementation]].

    3. Queue a task to perform these steps:

      1. If decoded outputs is not empty, run the Output AudioData algorithm with decoded outputs.

      2. Remove promise from [[pending flush promises]].

      3. Resolve promise.

  2. Return "processed".

reset()
Immediately resets all state including configuration, control messages in the control message queue, and all pending callbacks.

When invoked, run the Reset AudioDecoder algorithm with an AbortError DOMException.

close()
Immediately aborts all pending work and releases system resources. Close is final.

When invoked, run the Close AudioDecoder algorithm with an AbortError DOMException.

isConfigSupported(config)
Returns a promise indicating whether the provided config is supported by the User Agent.

NOTE: The returned AudioDecoderSupport config will contain only the dictionary members that User Agent recognized. Unrecognized dictionary members will be ignored. Authors can detect unrecognized dictionary members by comparing config to their provided config.

When invoked, run these steps:

  1. If config is not a valid AudioDecoderConfig, return a promise rejected with TypeError.

  2. Let p be a new Promise.

  3. Let checkSupportQueue be the result of starting a new parallel queue.

  4. Enqueue the following steps to checkSupportQueue:

    1. Let supported be the result of running the Check Configuration Support algorithm with config.

    2. Queue a task to run the following steps:

      1. Let decoderSupport be a newly constructed AudioDecoderSupport, initialized as follows:

        1. Set config to the result of running the Clone Configuration algorithm with config.

        2. Set supported to supported.

      2. Resolve p with decoderSupport.

  5. Return p.

3.6. Algorithms

Schedule Dequeue Event
  1. If [[dequeue event scheduled]] equals true, return.

  2. Assign true to [[dequeue event scheduled]].

  3. Queue a task to run the following steps:

    1. Fire a simple event named dequeue at this.

    2. Assign false to [[dequeue event scheduled]].

Output AudioData (with outputs)
Run these steps:
  1. For each output in outputs:

    1. Let data be an AudioData, initialized as follows:

      1. Assign false to [[Detached]].

      2. Let resource be the media resource described by output.

      3. Let resourceReference be a reference to resource.

      4. Assign resourceReference to [[resource reference]].

      5. Let timestamp be the [[timestamp]] of the EncodedAudioChunk associated with output.

      6. Assign timestamp to [[timestamp]].

      7. If output uses a recognized AudioSampleFormat, assign that format to [[format]]. Otherwise, assign null to [[format]].

      8. Assign values to [[sample rate]], [[number of frames]], and [[number of channels]] as determined by output.

    2. Invoke [[output callback]] with data.

Reset AudioDecoder (with exception)
Run these steps:
  1. If [[state]] is "closed", throw an InvalidStateError.

  2. Set [[state]] to "unconfigured".

  3. Signal [[codec implementation]] to cease producing output for the previous configuration.

  4. Remove all control messages from the [[control message queue]].

  5. If [[decodeQueueSize]] is greater than zero:

    1. Set [[decodeQueueSize]] to zero.

    2. Run the Schedule Dequeue Event algorithm.

  6. For each promise in [[pending flush promises]]:

    1. Reject promise with exception.

    2. Remove promise from [[pending flush promises]].

Close AudioDecoder (with exception)
Run these steps:
  1. Run the Reset AudioDecoder algorithm with exception.

  2. Set [[state]] to "closed".

  3. Clear [[codec implementation]] and release associated system resources.

  4. If exception is not an AbortError DOMException, invoke the [[error callback]] with exception.

4. VideoDecoder Interface

[Exposed=(Window,DedicatedWorker), SecureContext]
interface VideoDecoder : EventTarget {
  constructor(VideoDecoderInit init);

  readonly attribute CodecState state;
  readonly attribute unsigned long decodeQueueSize;
  attribute EventHandler ondequeue;

  undefined configure(VideoDecoderConfig config);
  undefined decode(EncodedVideoChunk chunk);
  Promise<undefined> flush();
  undefined reset();
  undefined close();

  static Promise<VideoDecoderSupport> isConfigSupported(VideoDecoderConfig config);
};

dictionary VideoDecoderInit {
  required VideoFrameOutputCallback output;
  required WebCodecsErrorCallback error;
};

callback VideoFrameOutputCallback = undefined(VideoFrame output);

4.1. Internal Slots

[[control message queue]]

A queue of control messages to be performed upon this codec instance. See [[control message queue]].

[[message queue blocked]]

A boolean indicating when processing the [[control message queue]] is blocked by a pending control message. See [[message queue blocked]].

[[codec implementation]]

Underlying decoder implementation provided by the User Agent. See [[codec implementation]].

[[codec work queue]]

A parallel queue used for running parallel steps that reference the [[codec implementation]]. See [[codec work queue]].

[[codec saturated]]

A boolean indicating when the [[codec implementation]] is unable to accept additional decoding work.

[[output callback]]

Callback given at construction for decoded outputs.

[[error callback]]

Callback given at construction for decode errors.

[[active decoder config]]

The VideoDecoderConfig that is actively applied.

[[key chunk required]]

A boolean indicating that the next chunk passed to decode() MUST describe a key chunk as indicated by type.

[[state]]

The current CodecState of this VideoDecoder.

[[decodeQueueSize]]

The number of pending decode requests. This number will decrease as the underlying codec is ready to accept new input.

[[pending flush promises]]

A list of unresolved promises returned by calls to flush().

[[dequeue event scheduled]]

A boolean indicating whether a dequeue event is already scheduled to fire. Used to avoid event spam.

4.2. Constructors

VideoDecoder(init)
  1. Let d be a new VideoDecoder object.

  2. Assign a new queue to [[control message queue]].

  3. Assign false to [[message queue blocked]].

  4. Assign null to [[codec implementation]].

  5. Assign the result of starting a new parallel queue to [[codec work queue]].

  6. Assign false to [[codec saturated]].

  7. Assign init.output to [[output callback]].

  8. Assign init.error to [[error callback]].

  9. Assign null to [[active decoder config]].

  10. Assign true to [[key chunk required]].

  11. Assign "unconfigured" to [[state]]

  12. Assign 0 to [[decodeQueueSize]].

  13. Assign a new list to [[pending flush promises]].

  14. Assign false to [[dequeue event scheduled]].

  15. Return d.

4.3. Attributes

state, of type CodecState, readonly

Returns the value of [[state]].

decodeQueueSize, of type unsigned long, readonly

Returns the value of [[decodeQueueSize]].

ondequeue, of type EventHandler

An event handler IDL attribute whose event handler event type is dequeue.

4.4. Event Summary

dequeue

Fired at the VideoDecoder when the decodeQueueSize has decreased.

4.5. Methods

configure(config)
Enqueues a control message to configure the video decoder for decoding chunks as described by config.

NOTE: This method will trigger a NotSupportedError if the User Agent does not support config. Authors are encouraged to first check support by calling isConfigSupported() with config. User Agents don’t have to support any particular codec type or configuration.

When invoked, run these steps:

  1. If config is not a valid VideoDecoderConfig, throw a TypeError.

  2. If [[state]] is “closed”, throw an InvalidStateError.

  3. Set [[state]] to "configured".

  4. Set [[key chunk required]] to true.

  5. Queue a control message to configure the decoder with config.

  6. Process the control message queue.

Running a control message to configure the decoder means running these steps:

  1. Assign true to [[message queue blocked]].

  2. Enqueue the following steps to [[codec work queue]]:

    1. Let supported be the result of running the Check Configuration Support algorithm with config.

    2. If supported is false, queue a task to run the Close VideoDecoder algorithm with NotSupportedError and abort these steps.

    3. If needed, assign [[codec implementation]] with an implementation supporting config.

    4. Configure [[codec implementation]] with config.

    5. Assign config to [[active decoder config]].

    6. queue a task to run the following steps:

      1. Assign false to [[message queue blocked]].

      2. Queue a task to Process the control message queue.

  3. Return "processed".

decode(chunk)
Enqueues a control message to decode the given chunk.

NOTE: Authors are encouraged to call close() on output VideoFrames immediately when frames are no longer needed. The underlying media resources are owned by the VideoDecoder and failing to release them (or waiting for garbage collection) can cause decoding to stall.

NOTE: VideoDecoder requires that frames are output in the order they expect to be presented, commonly known as presentation order. When using some [[codec implementation]]s the User Agent will have to reorder outputs into presentation order.

When invoked, run these steps:

  1. If [[state]] is not "configured", throw an InvalidStateError.

  2. If [[key chunk required]] is true:

    1. If chunk.type is not key, throw a DataError.

    2. Implementers SHOULD inspect the chunk’s [[internal data]] to verify that it is truly a key chunk. If a mismatch is detected, throw a DataError.

    3. Otherwise, assign false to [[key chunk required]].

  3. Increment [[decodeQueueSize]].

  4. Queue a control message to decode the chunk.

  5. Process the control message queue.

Running a control message to decode the chunk means performing these steps:

  1. If [[codec saturated]] equals true, return "not processed".

  2. If decoding chunk will cause the [[codec implementation]] to become saturated, assign true to [[codec saturated]].

  3. Decrement [[decodeQueueSize]] and run the Schedule Dequeue Event algorithm.

  4. Enqueue the following steps to the [[codec work queue]]:

    1. Attempt to use [[codec implementation]] to decode the chunk.

    2. If decoding results in an error, queue a task to run the Close VideoDecoder algorithm with EncodingError and return.

    3. If [[codec saturated]] equals true and [[codec implementation]] is no longer saturated, queue a task to perform the following steps:

      1. Assign false to [[codec saturated]].

      2. Process the control message queue.

    4. Let decoded outputs be a list of decoded video data outputs emitted by [[codec implementation]] in presentation order.

    5. If decoded outputs is not empty, queue a task to run the Output VideoFrame algorithm with decoded outputs.

  5. Return "processed".

flush()
Completes all control messages in the control message queue and emits all outputs.

When invoked, run these steps:

  1. If [[state]] is not "configured", return a promise rejected with InvalidStateError DOMException.

  2. Set [[key chunk required]] to true.

  3. Let promise be a new Promise.

  4. Append promise to [[pending flush promises]].

  5. Queue a control message to flush the codec with promise.

  6. Process the control message queue.

  7. Return promise.

Running a control message to flush the codec means performing these steps with promise.

  1. Enqueue the following steps to the [[codec work queue]]:

    1. Signal [[codec implementation]] to emit all internal pending outputs.

    2. Let decoded outputs be a list of decoded video data outputs emitted by [[codec implementation]].

    3. Queue a task to perform these steps:

      1. If decoded outputs is not empty, run the Output VideoFrame algorithm with decoded outputs.

      2. Remove promise from [[pending flush promises]].

      3. Resolve promise.

  2. Return "processed".

reset()
Immediately resets all state including configuration, control messages in the control message queue, and all pending callbacks.

When invoked, run the Reset VideoDecoder algorithm with an AbortError DOMException.

close()
Immediately aborts all pending work and releases system resources. Close is final.

When invoked, run the Close VideoDecoder algorithm with an AbortError DOMException.

isConfigSupported(config)
Returns a promise indicating whether the provided config is supported by the User Agent.

NOTE: The returned VideoDecoderSupport config will contain only the dictionary members that User Agent recognized. Unrecognized dictionary members will be ignored. Authors can detect unrecognized dictionary members by comparing config to their provided config.

When invoked, run these steps:

  1. If config is not a valid VideoDecoderConfig, return a promise rejected with TypeError.

  2. Let p be a new Promise.

  3. Let checkSupportQueue be the result of starting a new parallel queue.

  4. Enqueue the following steps to checkSupportQueue:

    1. Let supported be the result of running the Check Configuration Support algorithm with config.

    2. Queue a task to run the following steps:

      1. Let decoderSupport be a newly constructed VideoDecoderSupport, initialized as follows:

        1. Set config to the result of running the Clone Configuration algorithm with config.

        2. Set supported to supported.

      2. Resolve p with decoderSupport.

  5. Return p.

4.6. Algorithms

Schedule Dequeue Event
  1. If [[dequeue event scheduled]] equals true, return.

  2. Assign true to [[dequeue event scheduled]].

  3. Queue a task to run the following steps:

    1. Fire a simple event named dequeue at this.

    2. Assign false to [[dequeue event scheduled]].

Output VideoFrames (with outputs)
Run these steps:
  1. For each output in outputs:

    1. Let timestamp and duration be the timestamp and duration from the EncodedVideoChunk associated with output.

    2. Let displayAspectWidth and displayAspectHeight be undefined.

    3. If displayAspectWidth and displayAspectHeight exist in the [[active decoder config]], assign their values to displayAspectWidth and displayAspectHeight respectively.

    4. Let colorSpace be the VideoColorSpace for output as detected by the codec implementation. If no VideoColorSpace is detected, let colorSpace be undefined.

      NOTE: The codec implementation can detect a VideoColorSpace by analyzing the bitstream. Detection is made on a best-effort basis. The exact method of detection is implementer defined and codec-specific. Authors can override the detected VideoColorSpace by providing a colorSpace in the VideoDecoderConfig.

    5. If colorSpace exists in the [[active decoder config]], assign its value to colorSpace. In that case, User Agents MAY replace null members of colorSpace with the corresponding values detected by the codec implementation. FIXME: Properly specify the case of null members.

    6. Assign the values of rotation and flip to rotation and flip respectively.

    7. Let frame be the result of running the Create a VideoFrame algorithm with output, timestamp, duration, displayAspectWidth, displayAspectHeight, colorSpace, rotation, and flip.

    8. Invoke [[output callback]] with frame.

Reset VideoDecoder (with exception)
Run these steps:
  1. If state is "closed", throw an InvalidStateError.

  2. Set state to "unconfigured".

  3. Signal [[codec implementation]] to cease producing output for the previous configuration.

  4. Remove all control messages from the [[control message queue]].

  5. If [[decodeQueueSize]] is greater than zero:

    1. Set [[decodeQueueSize]] to zero.

    2. Run the Schedule Dequeue Event algorithm.

  6. For each promise in [[pending flush promises]]:

    1. Reject promise with exception.

    2. Remove promise from [[pending flush promises]].

Close VideoDecoder (with exception)
Run these steps:
  1. Run the Reset VideoDecoder algorithm with exception.

  2. Set state to "closed".

  3. Clear [[codec implementation]] and release associated system resources.

  4. If exception is not an AbortError DOMException, invoke the [[error callback]] with exception.

5. AudioEncoder Interface

[Exposed=(Window,DedicatedWorker), SecureContext]
interface AudioEncoder : EventTarget {
  constructor(AudioEncoderInit init);

  readonly attribute CodecState state;
  readonly attribute unsigned long encodeQueueSize;
  attribute EventHandler ondequeue;

  undefined configure(AudioEncoderConfig config);
  undefined encode(AudioData data);
  Promise<undefined> flush();
  undefined reset();
  undefined close();

  static Promise<AudioEncoderSupport> isConfigSupported(AudioEncoderConfig config);
};

dictionary AudioEncoderInit {
  required EncodedAudioChunkOutputCallback output;
  required WebCodecsErrorCallback error;
};

callback EncodedAudioChunkOutputCallback =
    undefined (EncodedAudioChunk output,
               optional EncodedAudioChunkMetadata metadata = {});

5.1. Internal Slots

[[control message queue]]

A queue of control messages to be performed upon this codec instance. See [[control message queue]].

[[message queue blocked]]

A boolean indicating when processing the [[control message queue]] is blocked by a pending control message. See [[message queue blocked]].

[[codec implementation]]

Underlying encoder implementation provided by the User Agent. See [[codec implementation]].

[[codec work queue]]

A parallel queue used for running parallel steps that reference the [[codec implementation]]. See [[codec work queue]].

[[codec saturated]]

A boolean indicating when the [[codec implementation]] is unable to accept additional encoding work.

[[output callback]]

Callback given at construction for encoded outputs.

[[error callback]]

Callback given at construction for encode errors.

[[active encoder config]]

The AudioEncoderConfig that is actively applied.

[[active output config]]

The AudioDecoderConfig that describes how to decode the most recently emitted EncodedAudioChunk.

[[state]]

The current CodecState of this AudioEncoder.

[[encodeQueueSize]]

The number of pending encode requests. This number will decrease as