VideoEncoder.webidl (3586B)
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/. 5 * 6 * The origin of this IDL file is 7 * https://w3c.github.io/webcodecs/#videoencoder 8 * 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. 13 */ 14 15 [Exposed=(Window,DedicatedWorker), SecureContext, Func="nsRFPService::ExposeWebCodecsAPI"] 16 interface VideoEncoder : EventTarget { 17 [Throws] 18 constructor(VideoEncoderInit init); 19 20 readonly attribute CodecState state; 21 readonly attribute unsigned long encodeQueueSize; 22 attribute EventHandler ondequeue; 23 24 [Throws] 25 undefined configure(VideoEncoderConfig config); 26 [Throws, BinaryName="VideoEncoder::EncodeVideoFrame"] 27 undefined encode(VideoFrame frame , optional VideoEncoderEncodeOptions options = {}); 28 [Throws] 29 Promise<undefined> flush(); 30 [Throws] 31 undefined reset(); 32 [Throws] 33 undefined close(); 34 35 [NewObject, Throws] 36 static Promise<VideoEncoderSupport> isConfigSupported(VideoEncoderConfig config); 37 }; 38 39 dictionary VideoEncoderInit { 40 required EncodedVideoChunkOutputCallback output; 41 required WebCodecsErrorCallback error; 42 }; 43 44 callback EncodedVideoChunkOutputCallback = 45 undefined (EncodedVideoChunk chunk, 46 optional EncodedVideoChunkMetadata metadata = {}); 47 48 // AVC (H264)-specific 49 // https://w3c.github.io/webcodecs/avc_codec_registration.html 50 enum AvcBitstreamFormat { 51 "annexb", 52 "avc", 53 }; 54 55 // AVC (H264)-specific 56 // https://w3c.github.io/webcodecs/avc_codec_registration.html 57 dictionary AvcEncoderConfig { 58 AvcBitstreamFormat format = "avc"; 59 }; 60 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; 68 double framerate; 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 77 AvcEncoderConfig avc; 78 }; 79 80 dictionary VideoEncoderEncodeOptions { 81 boolean keyFrame = false; 82 // AVC (H264)-specific 83 // https://w3c.github.io/webcodecs/avc_codec_registration.html 84 VideoEncoderEncodeOptionsForAvc avc; 85 }; 86 87 // AVC (H264)-specific 88 // https://w3c.github.io/webcodecs/avc_codec_registration.html 89 dictionary VideoEncoderEncodeOptionsForAvc { 90 unsigned short? quantizer; 91 }; 92 93 enum VideoEncoderBitrateMode { 94 "constant", 95 "variable", 96 // AVC (H264)-specific 97 // https://w3c.github.io/webcodecs/avc_codec_registration.html 98 "quantizer" 99 }; 100 101 enum LatencyMode { 102 "quality", 103 "realtime" 104 }; 105 106 dictionary VideoEncoderSupport { 107 boolean supported; 108 VideoEncoderConfig config; 109 }; 110 111 dictionary EncodedVideoChunkMetadata { 112 VideoDecoderConfig decoderConfig; 113 SvcOutputMetadata svc; 114 // Not implemented https://bugzilla.mozilla.org/show_bug.cgi?id=1867067 115 // BufferSource alphaSideData; 116 }; 117 118 dictionary SvcOutputMetadata { 119 unsigned long temporalLayerId; 120 };