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/#videoencoder
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 [Exposed=(Window,DedicatedWorker), SecureContext, Pref="dom.media.webcodecs.enabled"]
16 interface VideoEncoder : EventTarget {
18 constructor(VideoEncoderInit init);
20 readonly attribute CodecState state;
21 readonly attribute unsigned long encodeQueueSize;
22 attribute EventHandler ondequeue;
25 undefined configure(VideoEncoderConfig config);
26 [Throws, BinaryName="VideoEncoder::EncodeVideoFrame"]
27 undefined encode(VideoFrame frame , optional VideoEncoderEncodeOptions options = {});
29 Promise<undefined> flush();
36 static Promise<VideoEncoderSupport> isConfigSupported(VideoEncoderConfig config);
39 dictionary VideoEncoderInit {
40 required EncodedVideoChunkOutputCallback output;
41 required WebCodecsErrorCallback error;
44 callback EncodedVideoChunkOutputCallback =
45 undefined (EncodedVideoChunk chunk,
46 optional EncodedVideoChunkMetadata metadata = {});
48 // AVC (H264)-specific
49 // https://w3c.github.io/webcodecs/avc_codec_registration.html
50 enum AvcBitstreamFormat {
55 // AVC (H264)-specific
56 // https://w3c.github.io/webcodecs/avc_codec_registration.html
57 dictionary AvcEncoderConfig {
58 AvcBitstreamFormat format = "avc";
61 dictionary VideoEncoderConfig {
62 required DOMString codec;
63 required [EnforceRange] unsigned long width;
64 required [EnforceRange] unsigned long height;
65 [EnforceRange] unsigned long displayWidth;
66 [EnforceRange] unsigned long displayHeight;
67 [EnforceRange] unsigned long long bitrate;
69 HardwareAcceleration hardwareAcceleration = "no-preference";
70 AlphaOption alpha = "discard";
71 DOMString scalabilityMode;
72 VideoEncoderBitrateMode bitrateMode = "variable";
73 LatencyMode latencyMode = "quality";
74 DOMString contentHint;
75 // AVC (H264)-specific
76 // https://w3c.github.io/webcodecs/avc_codec_registration.html
80 dictionary VideoEncoderEncodeOptions {
81 boolean keyFrame = false;
82 // AVC (H264)-specific
83 // https://w3c.github.io/webcodecs/avc_codec_registration.html
84 VideoEncoderEncodeOptionsForAvc avc;
87 // AVC (H264)-specific
88 // https://w3c.github.io/webcodecs/avc_codec_registration.html
89 dictionary VideoEncoderEncodeOptionsForAvc {
90 unsigned short? quantizer;
93 enum VideoEncoderBitrateMode {
96 // AVC (H264)-specific
97 // https://w3c.github.io/webcodecs/avc_codec_registration.html
106 dictionary VideoEncoderSupport {
108 VideoEncoderConfig config;
111 dictionary EncodedVideoChunkMetadata {
112 VideoDecoderConfig decoderConfig;
113 SvcOutputMetadata svc;
114 // Not implemented https://bugzilla.mozilla.org/show_bug.cgi?id=1867067
115 // BufferSource alphaSideData;
118 dictionary SvcOutputMetadata {
119 unsigned long temporalLayerId;