|
39 | 39 | type: attribute; text: resizeWidth; url:#dom-imagebitmapoptions-resizewidth |
40 | 40 | type: attribute; text: resizeHeight; url:#dom-imagebitmapoptions-resizeheight |
41 | 41 | type: dfn; text: cropped to the source rectangle with formatting; url: imagebitmap-and-animations.html#cropped-to-the-source-rectangle-with-formatting |
42 | | - type: dfn; text: global object; url: webappapis.html#global-object |
| 42 | + type: dfn; text: bitmap data; url: imagebitmap-and-animations.html#concept-imagebitmap-bitmap-data |
| 43 | + for: Canvas; |
| 44 | + type: dfn; text: Check the usability of the image argument; url: canvas.html#check-the-usability-of-the-image-argument |
| 45 | + for: origin; |
| 46 | + type: dfn; text: origin; url: origin.html#concept-origin |
| 47 | + for: webappapis; |
| 48 | + type: dfn; text: global object; url: webappapis.html#global-object |
| 49 | + type: dfn; text: entry settings object; url: webappapis.html#entry-settings-object |
| 50 | + for: media; |
| 51 | + type: dfn; text: current playback position; url: media.html#current-playback-position |
43 | 52 |
|
44 | 53 | spec: mediacapture-streams; urlPrefix: https://www.w3.org/TR/mediacapture-streams/ |
45 | 54 | for: mediaDevices; |
|
74 | 83 | type: dfn; text: acquire the content; url: #acquire-the-content |
75 | 84 | for: AudioBuffer |
76 | 85 | type: method; text: copyToChannel(); url: #dom-audiobuffer-copytochannel |
| 86 | + |
| 87 | +spec: css-images-3; urlPrefix: https://www.w3.org/TR/css-images-3/ |
| 88 | + type: dfn; text: natural dimensions; url: #natural-dimensions |
| 89 | + type: dfn; text: natural width; url: #natural-width |
| 90 | + type: dfn; text: natural height; url: #natural-height |
77 | 91 | </pre> |
78 | 92 |
|
79 | 93 | <pre class='biblio'> |
|
139 | 153 | The <dfn>control thread</dfn> is the thread from which authors will construct |
140 | 154 | a [=codec=] and invoke its methods. Invoking a codec's methods will typically |
141 | 155 | result in the creation of [=control messages=] which are later executed on the |
142 | | -[=codec thread=]. Each [=global object=] has a separate control thread. |
| 156 | +[=codec thread=]. Each [=webappapis/global object=] has a separate control |
| 157 | +thread. |
143 | 158 |
|
144 | 159 | The <dfn>codec thread</dfn> is the thread from which a [=codec=] will |
145 | 160 | [=dequeue=] [=control messages=] and execute their steps. Each [=codec=] |
146 | 161 | instance has a separate codec thread. The lifetime of a codec thread matches |
147 | 162 | that of its associated [=codec=] instance. |
148 | 163 |
|
149 | | -The [=control thread=] uses a traditional event loop, as described in [[!HTML]]. |
| 164 | +The [=control thread=] uses a traditional event loop, as described in |
| 165 | +[[!HTML]]. |
150 | 166 |
|
151 | 167 | The [=codec thread=] uses a specialized [=codec processing loop=]. |
152 | 168 |
|
|
1017 | 1033 | 2. Set {{VideoEncoder/[[active encoder config]]}} to `config`. |
1018 | 1034 | </dd> |
1019 | 1035 |
|
1020 | | - <dt><dfn method for=VideoEncoder>encode(frame, options)</dfn></dt> |
| 1036 | + <dt><dfn method for=VideoEncoder>encode(|frame|, |options|)</dfn></dt> |
1021 | 1037 | <dd> |
1022 | 1038 | [=Enqueues a control message=] to encode the given |frame|. |
1023 | 1039 |
|
|
2021 | 2037 | VideoFrame Interface {#videoframe-interface} |
2022 | 2038 | -------------------------------------------- |
2023 | 2039 |
|
| 2040 | +NOTE: {{VideoFrame}} is a {{CanvasImageSource}}. A {{VideoFrame}} may be |
| 2041 | + passed to any method accepting a {{CanvasImageSource}}, including |
| 2042 | + {{CanvasDrawImage}}'s {{CanvasDrawImage/drawImage()}}. |
| 2043 | + |
2024 | 2044 | <pre class='idl'> |
2025 | 2045 | <xmp> |
2026 | 2046 | [Exposed=(Window,DedicatedWorker)] |
2027 | 2047 | interface VideoFrame { |
2028 | | - constructor(ImageBitmap imageBitmap, optional VideoFrameInit init = {}); |
| 2048 | + constructor(CanvasImageSource image, optional VideoFrameInit init = {}); |
2029 | 2049 | constructor(sequence<(Plane or PlaneInit)> planes, |
2030 | 2050 | VideoFramePlaneInit init); |
2031 | 2051 |
|
|
2044 | 2064 |
|
2045 | 2065 | VideoFrame clone(); |
2046 | 2066 | undefined close(); |
2047 | | - |
2048 | | - Promise<ImageBitmap> createImageBitmap( |
2049 | | - optional ImageBitmapOptions options = {}); |
2050 | | - |
2051 | 2067 | }; |
2052 | 2068 |
|
2053 | 2069 | dictionary VideoFrameInit { |
|
2081 | 2097 |
|
2082 | 2098 | ### Constructors ###{#videoframe-constructors} |
2083 | 2099 |
|
2084 | | -<dfn constructor for=VideoFrame title="VideoFrame(imageBitmap, init)"> |
2085 | | - VideoFrame(imageBitmap, init) |
| 2100 | +<dfn constructor for=VideoFrame title="VideoFrame(image, init)"> |
| 2101 | + VideoFrame(image, init) |
2086 | 2102 | </dfn> |
2087 | | -1. If the value of |imageBitmap|'s' {{PlatformObject/[[Detached]]}} internal |
2088 | | - slot is `true`, then throw an {{InvalidStateError}} |
| 2103 | +1. [=Canvas/Check the usability of the image argument=]. If this throws an |
| 2104 | + exception or returns <var ignore=''>bad</var>, then throw an {{InvalidStateError}} {{DOMException}}. |
| 2105 | +2. If the [=origin/origin=] of |image|'s image data is not [=same origin=] |
| 2106 | + with the [=webappapis/entry settings object=]'s |
| 2107 | + [=origin/origin=], then throw a {{SecurityError}} |
2089 | 2108 | {{DOMException}}. |
2090 | | -2. Let |resource| be the [=frame resource=] containing the bitmap data for |
2091 | | - |imageBitmap|. |
2092 | | -3. Let |resourceReference| be a reference to |resource|. |
2093 | | -4. Let |frame| be a new {{VideoFrame}}, initialized as follows: |
2094 | | - 1. Assign |resourceReference| to |
2095 | | - {{VideoFrame/[[resource reference]]}}. |
2096 | | - 2. If |resource| uses a recognized {{PixelFormat}}: |
2097 | | - 1. Assign the {{PixelFormat}} of |resource| to {{VideoFrame/format}}. |
2098 | | - 2. Let |planes| be a list of {{Plane}}s describing the |
2099 | | - [=frame resource=] in accordance with the {{VideoFrame/format}}. |
| 2109 | +3. Let |frame| be a new {{VideoFrame}}. |
| 2110 | +5. Switch on |image|: |
| 2111 | + - {{HTMLImageElement}} |
| 2112 | + - {{SVGImageElement}} |
| 2113 | + 1. If {{VideoFramePlaneInit/timestamp}} does not [=map/exist=] in |
| 2114 | + |init|, throw a {{TypeError}}. |
| 2115 | + 2. If image's media data has no [=natural dimensions=] |
| 2116 | + (e.g., it's a vector graphic with no specified content size), then |
| 2117 | + throw an {{InvalidStateError}} {{DOMException}}. |
| 2118 | + 3. Let |resource| be a new [=frame resource=] containing a copy of |
| 2119 | + |image|'s media data. If this is an animated image, |image|'s |
| 2120 | + [=bitmap data=] must only be taken from the default image of the |
| 2121 | + animation (the one that the format defines is to be used when |
| 2122 | + animation is not supported or is disabled), or, if there is no |
| 2123 | + such image, the first frame of the animation. |
| 2124 | + 4. Let |width| and |height| be the [=natural width=] and |
| 2125 | + [=natural height=] of |image|. |
| 2126 | + 5. Run the [=VideoFrame/Initialize Frame With Resource and Size=] |
| 2127 | + algorithm with |init|, |frame|, |resource|, |width|, and |height| |
| 2128 | + |
| 2129 | + - {{HTMLVideoElement}} |
| 2130 | + 1. If |image|'s {{HTMLMediaElement/networkState}} attribute is |
| 2131 | + {{HTMLMediaElement/NETWORK_EMPTY}}, then throw an |
| 2132 | + {{InvalidStateError}} {{DOMException}}. |
| 2133 | + 2. Let |currentPlaybackFrame| be the {{VideoFrame}} at the [=current |
| 2134 | + playback position=]. |
| 2135 | + 3. Run the [=VideoFrame/Initialize Frame From Other Frame=] algoirhtm |
| 2136 | + with |init|, |frame|, and |currentPlaybackFrame|. |
| 2137 | + |
| 2138 | + - {{HTMLCanvasElement}} |
| 2139 | + - {{ImageBitmap}} |
| 2140 | + - {{OffscreenCanvas}} |
| 2141 | + 1. If {{VideoFramePlaneInit/timestamp}} does not [=map/exist=] in |
| 2142 | + |init|, throw a {{TypeError}}. |
| 2143 | + 2. Let |resource| be a new [=frame resource=] containing a copy of |
| 2144 | + |image|'s [=bitmap data=]. |
| 2145 | + 3. Let |width| be `image.width` and |height| be `image.height`. |
| 2146 | + 4. Run the [=VideoFrame/Initialize Frame With Resource and Size=] |
| 2147 | + algorithm with |init|, |frame|, |resource|, |width|, and |height|. |
| 2148 | + |
| 2149 | + - {{VideoFrame}} |
| 2150 | + 1. Run the [=VideoFrame/Initialize Frame From Other Frame=] algorithm |
| 2151 | + with |init|, |frame|, and |image|. |
2100 | 2152 |
|
2101 | | - ISSUE: The spec should define explicit rules for each |
2102 | | - {{PixelFormat}} and reference them in the step above. See |
2103 | | - [#165](https://github.com/w3c/webcodecs/issues/165). |
| 2153 | +6. Return |frame|. |
2104 | 2154 |
|
2105 | | - 3. Assign |planes| to {{VideoFrame/planes}}. |
2106 | | - 3. Otherwise (|resource| does not use a recognized {{PixelFormat}}): |
2107 | | - 1. Assign `""` to {{VideoFrame/format}}. |
2108 | | - 2. Assign `null` to {{VideoFrame/planes}}. |
2109 | | - 4. Assign |imageBitmap|.{{ImageBitmap/width}} to {{VideoFrame/codedWidth}}, |
2110 | | - {{VideoFrame/cropWidth}}, and {{VideoFrame/displayWidth}}. |
2111 | | - 5. Assign |imageBitmap|.{{ImageBitmap/height}} to |
2112 | | - {{VideoFrame/codedHeight}}, {{VideoFrame/cropHeight}}, and |
2113 | | - {{VideoFrame/displayHeight}}. |
2114 | | - 6. Assign `0` to {{VideoFrame/cropTop}} and {{VideoFrame/cropLeft}}. |
2115 | | - 7. If {{VideoFrameInit/timestamp}} [=map/exists=] in |init|, assign |
2116 | | - `init.timestamp` to {{VideoFrame/timestamp}}. Otherwise, assign |
2117 | | - `null` to {{VideoFrame/timestamp}}. |
2118 | | - 8. If {{VideoFrameInit/duration}} [=map/exists=] in |init|, assign |
2119 | | - `init.duration` to {{VideoFrame/duration}}. Otherwise, assign |
2120 | | - `null` to {{VideoFrame/duration}}. |
2121 | | -5. Return |frame|. |
2122 | 2155 |
|
2123 | 2156 | <dfn constructor for=VideoFrame title="VideoFrame(planes, init)"> |
2124 | 2157 | VideoFrame(planes, init) |
|
2286 | 2319 | {{VideoFrame/displayWidth}}, and {{VideoFrame/displayHeight}}. |
2287 | 2320 | 6. Assign `null` to {{VideoFrame/duration}} and {{VideoFrame/timestamp}}. |
2288 | 2321 |
|
2289 | | -: <dfn method for=VideoFrame>createImageBitmap(options)</dfn> |
2290 | | -:: Creates an ImageBitmap from this {{VideoFrame}}. |
2291 | | - |
2292 | | - When invoked, run these steps: |
2293 | | - 1. Let |p| be a new Promise. |
2294 | | - 2. If either |options|'s {{ImageBitmapOptions/resizeWidth}} or |
2295 | | - {{ImageBitmap/resizeHeight}} is present and is 0, then return |p| |
2296 | | - rejected with an {{InvalidStateError}} {{DOMException}}. |
2297 | | - 3. If the <a>this'</a> {{VideoFrame/[[detached]]}} internal slot is set to |
2298 | | - `true`, then return |p| rejected with an {{InvalidStateError}} |
2299 | | - {{DOMException}}. |
2300 | | - 4. Let |imageBitmap| be a new {{ImageBitmap}} object. |
2301 | | - 5. Set |imageBitmap|'s bitmap data to a copy of the {{VideoFrame}} pixel |
2302 | | - data, at the frame's intrinsic width and intrinsic height (`i.e`., |
2303 | | - after any aspect-ratio correction has been applied), |
2304 | | - [=ImageBitmap/cropped to the source rectangle with formatting=]. |
2305 | | - 6. If the origin of |imageBitmap|'s image is not same origin with entry |
2306 | | - settings object's origin, then set the origin-clean flag of |
2307 | | - |imageBitmap|'s bitmap to `false`. |
2308 | | - 7. Run this step in parallel: |
2309 | | - 1. Resolve p with imageBitmap. |
2310 | | - |
2311 | 2322 | ### Algorithms ###{#videoframe-algorithms} |
2312 | 2323 | : To check if a {{VideoFramePlaneInit}} is a |
2313 | 2324 | <dfn>valid VideoFramePlaneInit</dfn>, run these steps: |
|
2325 | 2336 | {{VideoFramePlaneInit/displayHeight}} = 0, return `false`. |
2326 | 2337 | 6. Return `true`. |
2327 | 2338 |
|
| 2339 | +: <dfn for=VideoFrame>Initialize Frame From Other Frame</dfn> (with |init|, |
| 2340 | + |frame|, and |otherFrame|) |
| 2341 | +:: 1. Let |resource| be the [=frame resource=] referenced by |otherFrame|'s |
| 2342 | + {{VideoFrame/[[resource reference]]}}. |
| 2343 | + 2. Assign a new reference for |resource| to |frame|'s |
| 2344 | + {{VideoFrame/[[resource reference]]}}. |
| 2345 | + 3. Assign the following attributes from |otherFrame| to |frame|: |
| 2346 | + {{VideoFrame/format}}, {{VideoFrame/codedWidth}}, |
| 2347 | + {{VideoFrame/codedHeight}}, {{VideoFrame/cropLeft}}, |
| 2348 | + {{VideoFrame/cropTop}}, {{VideoFrame/cropWidth}}, |
| 2349 | + {{VideoFrame/cropHeight}}, {{VideoFrame/displayWidth}}, |
| 2350 | + {{VideoFrame/displayHeight}}. |
| 2351 | + 4. Let |planes| be a new [=list=]. |
| 2352 | + 5. For each |otherPlane| in |otherFrame|.{{VideoFrame/planes}}: |
| 2353 | + 1. Let |plane| be a new {{Plane}}. |
| 2354 | + 2. Assign a reference for |frame| to |plane|'s |
| 2355 | + {{Plane/[[parent frame]]}}. |
| 2356 | + 3. Assign the following attributes from |otherPlane| to |plane|: |
| 2357 | + {{Plane/stride}}, {{Plane/rows}}, {{Plane/length}}. |
| 2358 | + 4. Append |plane| to |planes|. |
| 2359 | + 6. Assign |planes| to |frame|.{{VideoFrame/planes}}. |
| 2360 | + 7. If {{VideoFrameInit/duration}} [=map/exists=] in |init|, assign it to |
| 2361 | + |frame|.{{VideoFrame/duration}}. Otherwise, assign |
| 2362 | + |otherFrame|.{{VideoFrame/duration}} to |
| 2363 | + |frame|.{{VideoFrame/duration}}. |
| 2364 | + 8. If {{VideoFrameInit/timestamp}} [=map/exists=] in |init|, assign it to |
| 2365 | + |frame|.{{VideoFrame/timestamp}}. Otherwise, assign |
| 2366 | + |otherFrame|.{{VideoFrame/timestamp}} to |
| 2367 | + |frame|.{{VideoFrame/timestamp}}. |
| 2368 | + |
| 2369 | +: <dfn for=VideoFrame>Initialize Frame With Resource and Size</dfn> (with |
| 2370 | + |init|, |frame|, |resource|, |width| and |height|) |
| 2371 | +:: 1. Assign a new reference for |resource| to |frame|'s |
| 2372 | + {{VideoFrame/[[resource reference]]}}. |
| 2373 | + 2. If |resource| uses a recognized {{PixelFormat}}: |
| 2374 | + 1. Assign the {{PixelFormat}} of |resource| to {{VideoFrame/format}}. |
| 2375 | + 2. Let |planes| be a list of {{Plane}}s describing the |
| 2376 | + [=frame resource=] in accordance with the {{VideoFrame/format}}. |
| 2377 | + |
| 2378 | + ISSUE: The spec should define explicit rules for each |
| 2379 | + {{PixelFormat}} and reference them in the step above. See |
| 2380 | + [#165](https://github.com/w3c/webcodecs/issues/165). |
| 2381 | + |
| 2382 | + 3. Assign |planes| to {{VideoFrame/planes}}. |
| 2383 | + 3. Otherwise (|resource| does not use a recognized {{PixelFormat}}): |
| 2384 | + 1. Assign `""` to {{VideoFrame/format}}. |
| 2385 | + 2. Assign `null` to {{VideoFrame/planes}}. |
| 2386 | + 4. Assign |width| to the following attributes of |frame|: |
| 2387 | + {{VideoFrame/codedWidth}}, {{VideoFrame/cropWidth}}, |
| 2388 | + {{VideoFrame/displayWidth}}. |
| 2389 | + 5. Assign |height| to the following attributes of |frame|: |
| 2390 | + {{VideoFrame/codedHeight}}, {{VideoFrame/cropHeight}}, |
| 2391 | + {{VideoFrame/displayHeight}}. |
| 2392 | + 6. Assign `0` to frame's {{VideoFrame/cropTop}} and |
| 2393 | + {{VideoFrame/cropLeft}}. |
| 2394 | + 7. Assign `init`.{{VideoFrameInit/duration}} to |
| 2395 | + |frame|.{{VideoFrame/duration}}. |
| 2396 | + 8. Assign `init`.{{VideoFrameInit/timestamp}} to |
| 2397 | + |frame|.{{VideoFrame/timestamp}}. |
| 2398 | + |
2328 | 2399 | : <dfn>Clone VideoFrame</dfn> (with |frame|) |
2329 | 2400 | :: 1. Let |clone| be a new {{VideoFrame}} initialized as follows: |
2330 | 2401 | 1. Assign |frame|.{{VideoFrame/[[resource reference]]}} to |
|
0 commit comments