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/#videoframe
15 // [Serializable, Transferable] are implemented without adding attributes here.
16 [Exposed=(Window,DedicatedWorker), Pref="dom.media.webcodecs.enabled"]
17 interface VideoFrame {
18 // The constructors should be shorten to:
20 // constructor([AllowShared] BufferSource data, VideoFrameBufferInit init);
21 // constructor(CanvasImageSource image, optional VideoFrameInit init = {});
23 // However, `[AllowShared] BufferSource` doesn't work for now (bug 1696216), and
24 // `No support for unions as distinguishing arguments yet` error occurs when using
25 // `constructor(CanvasImageSource image, optional VideoFrameInit init = {})` and
26 // `constructor(([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) data, VideoFrameBufferInit init)`
27 // at the same time (bug 1786410).
29 constructor(HTMLImageElement imageElement, optional VideoFrameInit init = {});
31 constructor(SVGImageElement svgImageElement, optional VideoFrameInit init = {});
33 constructor(HTMLCanvasElement canvasElement, optional VideoFrameInit init = {});
35 constructor(HTMLVideoElement videoElement, optional VideoFrameInit init = {});
37 constructor(OffscreenCanvas offscreenCanvas, optional VideoFrameInit init = {});
39 constructor(ImageBitmap imageBitmap, optional VideoFrameInit init = {});
41 constructor(VideoFrame videoFrame, optional VideoFrameInit init = {});
43 constructor([AllowShared] ArrayBufferView bufferView, VideoFrameBufferInit init);
45 constructor([AllowShared] ArrayBuffer buffer, VideoFrameBufferInit init);
48 readonly attribute VideoPixelFormat? format;
49 readonly attribute unsigned long codedWidth;
50 readonly attribute unsigned long codedHeight;
51 readonly attribute DOMRectReadOnly? codedRect;
52 readonly attribute DOMRectReadOnly? visibleRect;
53 readonly attribute unsigned long displayWidth;
54 readonly attribute unsigned long displayHeight;
55 readonly attribute unsigned long long? duration; // microseconds
56 readonly attribute long long timestamp; // microseconds
57 readonly attribute VideoColorSpace colorSpace;
60 unsigned long allocationSize(
61 optional VideoFrameCopyToOptions options = {});
63 Promise<sequence<PlaneLayout>> copyTo(
64 // bug 1696216: Should be `copyTo([AllowShared] BufferSource destination, ...)`
65 ([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) destination,
66 optional VideoFrameCopyToOptions options = {});
72 dictionary VideoFrameInit {
73 unsigned long long duration; // microseconds
74 long long timestamp; // microseconds
75 AlphaOption alpha = "keep";
77 // Default matches image. May be used to efficiently crop. Will trigger
78 // new computation of displayWidth and displayHeight using image’s pixel
79 // aspect ratio unless an explicit displayWidth and displayHeight are given.
80 DOMRectInit visibleRect;
82 // Default matches image unless visibleRect is provided.
83 [EnforceRange] unsigned long displayWidth;
84 [EnforceRange] unsigned long displayHeight;
87 dictionary VideoFrameBufferInit {
88 required VideoPixelFormat format;
89 required [EnforceRange] unsigned long codedWidth;
90 required [EnforceRange] unsigned long codedHeight;
91 required [EnforceRange] long long timestamp; // microseconds
92 [EnforceRange] unsigned long long duration; // microseconds
94 // Default layout is tightly-packed.
95 sequence<PlaneLayout> layout;
97 // Default visible rect is coded size positioned at (0,0)
98 DOMRectInit visibleRect;
100 // Default display dimensions match visibleRect.
101 [EnforceRange] unsigned long displayWidth;
102 [EnforceRange] unsigned long displayHeight;
104 VideoColorSpaceInit colorSpace;
107 dictionary VideoFrameCopyToOptions {
109 sequence<PlaneLayout> layout;
112 dictionary PlaneLayout {
113 // TODO: https://github.com/w3c/webcodecs/pull/488
114 required [EnforceRange] unsigned long offset;
115 required [EnforceRange] unsigned long stride;
118 enum VideoPixelFormat {
131 // 32bpp RGBX (opaque)
135 // 32bpp BGRX (opaque)