Skip to content

Commit b7924b1

Browse files
committed
Add WebCodecs: VideoEncoder
1 parent 7259fac commit b7924b1

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

baselines/dom.generated.d.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ interface AuthenticatorSelectionCriteria {
133133
userVerification?: UserVerificationRequirement;
134134
}
135135

136+
interface AvcEncoderConfig {
137+
format?: AvcBitstreamFormat;
138+
}
139+
136140
interface BiquadFilterOptions extends AudioNodeOptions {
137141
Q?: number;
138142
detune?: number;
@@ -445,6 +449,10 @@ interface EncodedVideoChunkInit {
445449
type: EncodedVideoChunkType;
446450
}
447451

452+
interface EncodedVideoChunkMetadata {
453+
decoderConfig?: VideoDecoderConfig;
454+
}
455+
448456
interface ErrorEventInit extends EventInit {
449457
colno?: number;
450458
error?: any;
@@ -1980,6 +1988,36 @@ interface VideoDecoderSupport {
19801988
supported?: boolean;
19811989
}
19821990

1991+
interface VideoEncoderConfig {
1992+
alpha?: AlphaOption;
1993+
avc?: AvcEncoderConfig;
1994+
bitrate?: number;
1995+
bitrateMode?: BitrateMode;
1996+
codec: string;
1997+
displayHeight?: number;
1998+
displayWidth?: number;
1999+
framerate?: number;
2000+
hardwareAcceleration?: HardwareAcceleration;
2001+
height: number;
2002+
latencyMode?: LatencyMode;
2003+
scalabilityMode?: string;
2004+
width: number;
2005+
}
2006+
2007+
interface VideoEncoderEncodeOptions {
2008+
keyFrame?: boolean;
2009+
}
2010+
2011+
interface VideoEncoderInit {
2012+
error: WebCodecsErrorCallback;
2013+
output: EncodedVideoChunkOutputCallback;
2014+
}
2015+
2016+
interface VideoEncoderSupport {
2017+
config?: VideoEncoderConfig;
2018+
supported?: boolean;
2019+
}
2020+
19832021
interface VideoFrameBufferInit {
19842022
codedHeight: number;
19852023
codedWidth: number;
@@ -15283,6 +15321,32 @@ declare var VideoDecoder: {
1528315321
isConfigSupported(config: VideoDecoderConfig): Promise<VideoDecoderSupport>;
1528415322
};
1528515323

15324+
interface VideoEncoderEventMap {
15325+
"dequeue": Event;
15326+
}
15327+
15328+
/** Available only in secure contexts. */
15329+
interface VideoEncoder extends EventTarget {
15330+
readonly encodeQueueSize: number;
15331+
ondequeue: ((this: VideoEncoder, ev: Event) => any) | null;
15332+
readonly state: CodecState;
15333+
close(): void;
15334+
configure(config: VideoEncoderConfig): void;
15335+
encode(frame: VideoFrame, options?: VideoEncoderEncodeOptions): void;
15336+
flush(): Promise<void>;
15337+
reset(): void;
15338+
addEventListener<K extends keyof VideoEncoderEventMap>(type: K, listener: (this: VideoEncoder, ev: VideoEncoderEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
15339+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
15340+
removeEventListener<K extends keyof VideoEncoderEventMap>(type: K, listener: (this: VideoEncoder, ev: VideoEncoderEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
15341+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
15342+
}
15343+
15344+
declare var VideoEncoder: {
15345+
prototype: VideoEncoder;
15346+
new(init: VideoEncoderInit): VideoEncoder;
15347+
isConfigSupported(config: VideoEncoderConfig): Promise<VideoEncoderSupport>;
15348+
};
15349+
1528615350
interface VideoFrame {
1528715351
readonly codedHeight: number;
1528815352
readonly codedRect: DOMRectReadOnly | null;
@@ -18272,6 +18336,10 @@ interface DecodeSuccessCallback {
1827218336
(decodedData: AudioBuffer): void;
1827318337
}
1827418338

18339+
interface EncodedVideoChunkOutputCallback {
18340+
(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadata): void;
18341+
}
18342+
1827518343
interface ErrorCallback {
1827618344
(err: DOMException): void;
1827718345
}
@@ -19194,8 +19262,10 @@ type AuthenticatorAttachment = "cross-platform" | "platform";
1919419262
type AuthenticatorTransport = "ble" | "hybrid" | "internal" | "nfc" | "usb";
1919519263
type AutoKeyword = "auto";
1919619264
type AutomationRate = "a-rate" | "k-rate";
19265+
type AvcBitstreamFormat = "annexb" | "avc";
1919719266
type BinaryType = "arraybuffer" | "blob";
1919819267
type BiquadFilterType = "allpass" | "bandpass" | "highpass" | "highshelf" | "lowpass" | "lowshelf" | "notch" | "peaking";
19268+
type BitrateMode = "constant" | "variable";
1919919269
type CSSMathOperator = "clamp" | "invert" | "max" | "min" | "negate" | "product" | "sum";
1920019270
type CSSNumericBaseType = "angle" | "flex" | "frequency" | "length" | "percent" | "resolution" | "time";
1920119271
type CanPlayTypeResult = "" | "maybe" | "probably";
@@ -19251,6 +19321,7 @@ type IterationCompositeOperation = "accumulate" | "replace";
1925119321
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
1925219322
type KeyType = "private" | "public" | "secret";
1925319323
type KeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey";
19324+
type LatencyMode = "quality" | "realtime";
1925419325
type LineAlignSetting = "center" | "end" | "start";
1925519326
type LockMode = "exclusive" | "shared";
1925619327
type MIDIPortConnectionState = "closed" | "open" | "pending";

baselines/webworker.generated.d.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ interface AudioConfiguration {
4747
spatialRendering?: boolean;
4848
}
4949

50+
interface AvcEncoderConfig {
51+
format?: AvcBitstreamFormat;
52+
}
53+
5054
interface BlobPropertyBag {
5155
endings?: EndingType;
5256
type?: string;
@@ -166,6 +170,10 @@ interface EncodedVideoChunkInit {
166170
type: EncodedVideoChunkType;
167171
}
168172

173+
interface EncodedVideoChunkMetadata {
174+
decoderConfig?: VideoDecoderConfig;
175+
}
176+
169177
interface ErrorEventInit extends EventInit {
170178
colno?: number;
171179
error?: any;
@@ -763,6 +771,36 @@ interface VideoDecoderSupport {
763771
supported?: boolean;
764772
}
765773

774+
interface VideoEncoderConfig {
775+
alpha?: AlphaOption;
776+
avc?: AvcEncoderConfig;
777+
bitrate?: number;
778+
bitrateMode?: BitrateMode;
779+
codec: string;
780+
displayHeight?: number;
781+
displayWidth?: number;
782+
framerate?: number;
783+
hardwareAcceleration?: HardwareAcceleration;
784+
height: number;
785+
latencyMode?: LatencyMode;
786+
scalabilityMode?: string;
787+
width: number;
788+
}
789+
790+
interface VideoEncoderEncodeOptions {
791+
keyFrame?: boolean;
792+
}
793+
794+
interface VideoEncoderInit {
795+
error: WebCodecsErrorCallback;
796+
output: EncodedVideoChunkOutputCallback;
797+
}
798+
799+
interface VideoEncoderSupport {
800+
config?: VideoEncoderConfig;
801+
supported?: boolean;
802+
}
803+
766804
interface VideoFrameBufferInit {
767805
codedHeight: number;
768806
codedWidth: number;
@@ -3887,6 +3925,32 @@ declare var VideoDecoder: {
38873925
isConfigSupported(config: VideoDecoderConfig): Promise<VideoDecoderSupport>;
38883926
};
38893927

3928+
interface VideoEncoderEventMap {
3929+
"dequeue": Event;
3930+
}
3931+
3932+
/** Available only in secure contexts. */
3933+
interface VideoEncoder extends EventTarget {
3934+
readonly encodeQueueSize: number;
3935+
ondequeue: ((this: VideoEncoder, ev: Event) => any) | null;
3936+
readonly state: CodecState;
3937+
close(): void;
3938+
configure(config: VideoEncoderConfig): void;
3939+
encode(frame: VideoFrame, options?: VideoEncoderEncodeOptions): void;
3940+
flush(): Promise<void>;
3941+
reset(): void;
3942+
addEventListener<K extends keyof VideoEncoderEventMap>(type: K, listener: (this: VideoEncoder, ev: VideoEncoderEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
3943+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
3944+
removeEventListener<K extends keyof VideoEncoderEventMap>(type: K, listener: (this: VideoEncoder, ev: VideoEncoderEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
3945+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
3946+
}
3947+
3948+
declare var VideoEncoder: {
3949+
prototype: VideoEncoder;
3950+
new(init: VideoEncoderInit): VideoEncoder;
3951+
isConfigSupported(config: VideoEncoderConfig): Promise<VideoEncoderSupport>;
3952+
};
3953+
38903954
interface VideoFrame {
38913955
readonly codedHeight: number;
38923956
readonly codedRect: DOMRectReadOnly | null;
@@ -6459,6 +6523,10 @@ declare namespace WebAssembly {
64596523
function validate(bytes: BufferSource): boolean;
64606524
}
64616525

6526+
interface EncodedVideoChunkOutputCallback {
6527+
(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadata): void;
6528+
}
6529+
64626530
interface FrameRequestCallback {
64636531
(time: DOMHighResTimeStamp): void;
64646532
}
@@ -6640,7 +6708,9 @@ type Uint32List = Uint32Array | GLuint[];
66406708
type VibratePattern = number | number[];
66416709
type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string;
66426710
type AlphaOption = "discard" | "keep";
6711+
type AvcBitstreamFormat = "annexb" | "avc";
66436712
type BinaryType = "arraybuffer" | "blob";
6713+
type BitrateMode = "constant" | "variable";
66446714
type CSSMathOperator = "clamp" | "invert" | "max" | "min" | "negate" | "product" | "sum";
66456715
type CSSNumericBaseType = "angle" | "flex" | "frequency" | "length" | "percent" | "resolution" | "time";
66466716
type CanvasDirection = "inherit" | "ltr" | "rtl";
@@ -6677,6 +6747,7 @@ type ImageSmoothingQuality = "high" | "low" | "medium";
66776747
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
66786748
type KeyType = "private" | "public" | "secret";
66796749
type KeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey";
6750+
type LatencyMode = "quality" | "realtime";
66806751
type LockMode = "exclusive" | "shared";
66816752
type MediaDecodingType = "file" | "media-source" | "webrtc";
66826753
type MediaEncodingType = "record" | "webrtc";

inputfiles/removedTypes.jsonc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@
240240
}
241241
}
242242
},
243+
"EncodedVideoChunkMetadata": {
244+
"members": {
245+
"member": {
246+
"alphaSideData": null, // Blink only as of 2023-03
247+
"svc": null // Blink only as of 2023-03
248+
}
249+
}
250+
},
243251
"FocusOptions": {
244252
"members": {
245253
"member": {
@@ -580,10 +588,17 @@
580588
}
581589
}
582590
},
591+
"VideoEncoderConfig": {
592+
"members": {
593+
"member": {
594+
"hevc": null // Blink only as of 2023-03
595+
}
596+
}
597+
},
583598
"VideoFrameInit": {
584599
"members": {
585600
"member": {
586-
"metadata": null // No implementation as of 2023-04. Linked to VideoFrame.metadata()
601+
"metadata": null // No implementation as of 2023-03. Linked to VideoFrame.metadata()
587602
}
588603
}
589604
},

0 commit comments

Comments
 (0)