1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
6 * The origin of this IDL file is
7 * https://w3c.github.io/webcodecs/#audioencoder
9 * Some members of this API are codec-specific, in which case the source of the
10 * IDL are in the codec-specific registry entries, that are listed in
11 * https://w3c.github.io/webcodecs/codec_registry.html. Those members are
12 * commented with a link of the document in which the member is listed.
15 dictionary AudioEncoderSupport {
17 AudioEncoderConfig config;
20 dictionary AudioEncoderConfig {
21 required DOMString codec;
22 [EnforceRange] unsigned long sampleRate;
23 [EnforceRange] unsigned long numberOfChannels;
24 [EnforceRange] unsigned long long bitrate;
25 BitrateMode bitrateMode = "variable";
26 OpusEncoderConfig opus;
29 // Opus specific configuration options:
30 // https://w3c.github.io/webcodecs/opus_codec_registration.html
31 enum OpusBitstreamFormat {
36 dictionary OpusEncoderConfig {
37 OpusBitstreamFormat format = "opus";
38 [EnforceRange] unsigned long long frameDuration = 20000;
39 [EnforceRange] unsigned long complexity;
40 [EnforceRange] unsigned long packetlossperc = 0;
41 boolean useinbandfec = false;
42 boolean usedtx = false;
45 [Exposed=(Window,DedicatedWorker), SecureContext, Pref="dom.media.webcodecs.enabled"]
46 interface AudioEncoder : EventTarget {
48 constructor(AudioEncoderInit init);
50 readonly attribute CodecState state;
51 readonly attribute unsigned long encodeQueueSize;
52 attribute EventHandler ondequeue;
55 undefined configure(AudioEncoderConfig config);
56 [Throws, BinaryName="AudioEncoder::EncodeAudioData"]
57 undefined encode(AudioData data);
59 Promise<undefined> flush();
66 static Promise<AudioEncoderSupport> isConfigSupported(AudioEncoderConfig config);
69 dictionary AudioEncoderInit {
70 required EncodedAudioChunkOutputCallback output;
71 required WebCodecsErrorCallback error;
74 callback EncodedAudioChunkOutputCallback =
75 undefined (EncodedAudioChunk output,
76 optional EncodedAudioChunkMetadata metadata = {});
78 dictionary EncodedAudioChunkMetadata {
79 AudioDecoderConfig decoderConfig;