chromium/third_party/blink/renderer/modules/webcodecs/audio_decoder.idl

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://github.com/WICG/web-codecs

[
    Exposed=(Window,DedicatedWorker),
    SecureContext,
    ActiveScriptWrappable
] interface AudioDecoder : EventTarget {
  // |init| includes an |output| callback for emitting AudioBuffers and an
  // |error| callback for emitting decode errors. All errors are permanent;
  // construct a new decoder to recover.
  //
  // TODO(sandersd): Consider adding a state or last error attribute.
  [CallWith=ScriptState, RaisesException, MeasureAs=WebCodecsAudioDecoder] constructor(AudioDecoderInit init);

  // The number of pending decode requests. This does not include requests that
  // have been sent to the underlying codec.
  //
  // Applications can minimize underflow by enqueueing decode requests until
  // |decodeQueueSize| is greater than a constant.
  readonly attribute unsigned long decodeQueueSize;

  // Fires to signal a decrease in decodeQueueSize. Will fire at most once for a
  // given turn of the event loop.
  attribute EventHandler ondequeue;

  // Which state the decoder is in, indicating which methods can be called.
  readonly attribute CodecState state;

  // Set the stream configuration for future decode() requests.
  //
  // The next decode request must be for a keyframe.
  [RaisesException] void configure(AudioDecoderConfig config);

  // Request decoding of an input chunk.
  //
  // You must call configure() before calling decode() for the first time.
  [RaisesException] void decode(EncodedAudioChunk chunk);

  // Request output from all previous decode requests.
  //
  // Resolved after all output for earlier decode requests has been emitted.
  //
  // The next decode request must be for a keyframe.
  [RaisesException] Promise<undefined> flush();

  // Reset all codec state, including all pending requests.
  //
  // You must call configure() before submitting the next decode.
  [RaisesException] void reset();

  // Immediately shut down the decoder and free its resources. All pending
  // decode requests are aborted.
  //
  // Not recoverable: make a new AudioDecoder if needed.
  [RaisesException] void close();

  // Call prior to configure() to determine whether config will be supported.
  [CallWith=ScriptState, RaisesException]
  static Promise<AudioDecoderSupport> isConfigSupported(AudioDecoderConfig config);
};