Skip to content

Commit 48523cd

Browse files
authored
Merge pull request #754 from Djuffin/rgb
Spec optional conversion to RGB in VideoFrame.copyTo()
2 parents 871ccb3 + 0df4aee commit 48523cd

1 file changed

Lines changed: 76 additions & 18 deletions

File tree

index.src.html

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
<pre class=link-defaults>
3232
spec:html; type:attribute; text:hidden
33+
spec:html; type:enum-value; text:srgb
3334
spec:infra; type:dfn; text:list
3435
spec:infra; type:dfn; text:enqueue
3536
</pre>
@@ -38,6 +39,8 @@
3839
spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/;
3940
for: ImageBitmap;
4041
type: dfn; text: bitmap data; url: imagebitmap-and-animations.html#concept-imagebitmap-bitmap-data
42+
for: ImageData
43+
type: dfn; text: canvas pixel data; url: canvas.html#imagedata
4144
for: Canvas;
4245
type: dfn; text: Check the usability of the image argument; url: canvas.html#check-the-usability-of-the-image-argument
4346
type: dfn; text: is not origin-clean; url: canvas.html#the-image-argument-is-not-origin-clean
@@ -3745,29 +3748,39 @@
37453748

37463749
: <dfn method for=VideoFrame>copyTo(|destination|, |options|)</dfn>
37473750
:: Asynchronously copies the planes of this frame into |destination| according
3748-
to |options|. The format of the data is the same as this {{VideoFrame}}'s
3749-
{{VideoFrame/format}}.
3751+
to |options|. The format of the data is |options|.{{VideoFrameCopyToOptions/format}},
3752+
if it [=map/exists=] or [=this=] {{VideoFrame}}'s {{VideoFrame/format}} otherwise.
37503753

37513754
NOTE: Promises that are returned by several calls to
37523755
{{VideoFrame/copyTo()}} are not guaranteed to resolve in the order they
37533756
were returned.
37543757

37553758
When invoked, run these steps:
3756-
1. If {{platform object/[[Detached]]}} is `true`, throw an
3757-
{{InvalidStateError}} {{DOMException}}.
3758-
2. If {{VideoFrame/[[format]]}} is `null`, throw a {{NotSupportedError}}
3759-
{{DOMException}}.
3759+
1. If {{platform object/[[Detached]]}} is `true`, return a promise rejected
3760+
with a {{InvalidStateError}} {{DOMException}}.
3761+
2. If {{VideoFrame/[[format]]}} is `null`, return a promise rejected with a
3762+
{{NotSupportedError}} {{DOMException}}.
37603763
3. Let |combinedLayout| be the result of running the [=Parse
37613764
VideoFrameCopyToOptions=] algorithm with |options|.
37623765
4. If |combinedLayout| is an exception, return a promise rejected with
37633766
|combinedLayout|.
37643767
5. If `destination.byteLength` is less than |combinedLayout|'s [=combined
37653768
buffer layout/allocationSize=], return a promise rejected with a
37663769
{{TypeError}}.
3767-
6. Let |p| be a new {{Promise}}.
3768-
7. Let |copyStepsQueue| be the result of starting a new [=parallel queue=].
3769-
8. Let |planeLayouts| be a new [=list=].
3770-
9. Enqueue the following steps to |copyStepsQueue|:
3770+
6. If |options|.{{VideoFrameCopyToOptions/format}} is equal to one of
3771+
{{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}} then:
3772+
1. Let |newOptions| be the result of running the <a>Clone Configuration</a>
3773+
algorithm with |options|.
3774+
2. Assign `undefined` to |newOptions|.{{VideoFrameCopyToOptions/format}}.
3775+
3. Let |rgbFrame| be the result of running the [=VideoFrame/Convert to RGB frame=]
3776+
algorithm with [=this=], |options|.{{VideoFrameCopyToOptions/format}},
3777+
and |options|.{{VideoFrameCopyToOptions/colorSpace}}.
3778+
4. Return the result of calling {{VideoFrame/copyTo()}} on |rgbFrame| with
3779+
|destination| and |newOptions|.
3780+
7. Let |p| be a new {{Promise}}.
3781+
8. Let |copyStepsQueue| be the result of starting a new [=parallel queue=].
3782+
9. Let |planeLayouts| be a new [=list=].
3783+
10. Enqueue the following steps to |copyStepsQueue|:
37713784
1. Let resource be the [=media resource=] referenced by
37723785
[[resource reference]].
37733786
2. Let |numPlanes| be the number of planes as defined by
@@ -3804,7 +3817,7 @@
38043817
10. Increment |planeIndex| by `1`.
38053818
11. Append |layout| to |planeLayouts|.
38063819
5. [=Queue a task=] to resolve |p| with |planeLayouts|.
3807-
10. Return |p|.
3820+
11. Return |p|.
38083821

38093822
: <dfn method for=VideoFrame>clone()</dfn>
38103823
:: Creates a new {{VideoFrame}} with a reference to the same
@@ -4048,10 +4061,17 @@
40484061
6. Let |optLayout| be `undefined`.
40494062
7. If |options|.{{VideoFrameCopyToOptions/layout}} [=map/exists=], assign
40504063
its value to |optLayout|.
4051-
8. Let |combinedLayout| be the result of running the [=VideoFrame/Compute
4052-
Layout and Allocation Size=] algorithm with |parsedRect|,
4053-
{{VideoFrame/[[format]]}}, and |optLayout|.
4054-
9. Return |combinedLayout|.
4064+
8. Let |format| be `undefined`.
4065+
9. If |options|.{{VideoFrameCopyToOptions/format}} does not [=map/exist=],
4066+
assign {{VideoFrame/[[format]]}} to |format|.
4067+
10. Otherwise, if |options|.{{VideoFrameCopyToOptions/format}} is equal to
4068+
one of {{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}}, then assign
4069+
|options|.{{VideoFrameCopyToOptions/format}} to |format|,
4070+
otherwise return {{NotSupportedError}}.
4071+
11. Let |combinedLayout| be the result of running the [=VideoFrame/Compute
4072+
Layout and Allocation Size=] algorithm with |parsedRect|, |format|,
4073+
and |optLayout|.
4074+
12. Return |combinedLayout|.
40554075

40564076
: <dfn for=VideoFrame>Verify Rect Offset Alignment</dfn> (with |format| and
40574077
|rect|)
@@ -4183,10 +4203,34 @@
41834203
[=combined buffer layout/allocationSize=].
41844204
9. Return |combinedLayout|.
41854205

4206+
: <dfn for=VideoFrame>Convert to RGB frame</dfn> (with |frame|, |format| and |colorSpace|)
4207+
:: 1. This algorithm <em class="rfc2119">MUST</em> be called only if |format|
4208+
is equal to one of {{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}}.
4209+
2. Let |convertedFrame| be a new {{VideoFrame}}, constructed as follows:
4210+
1. Assign `false` to {{platform object/[[Detached]]}}.
4211+
2. Assign |format| to {{VideoFrame/[[format]]}}.
4212+
3. Let |width| be |frame|'s {{VideoFrame/[[visible width]]}}.
4213+
4. Let |height| be |frame|'s {{VideoFrame/[[visible height]]}}.
4214+
5. Assign |width|, |height|, 0, 0, |width|, |height|, |width|, and
4215+
|height| to {{VideoFrame/[[coded width]]}},
4216+
{{VideoFrame/[[coded height]]}}, {{VideoFrame/[[visible left]]}},
4217+
{{VideoFrame/[[visible top]]}}, {{VideoFrame/[[visible width]]}},
4218+
and {{VideoFrame/[[visible height]]}} respectively.
4219+
6. Assign |frame|'s {{VideoFrame/[[duration]]}} and |frame|'s
4220+
{{VideoFrame/[[timestamp]]}} to {{VideoFrame/[[duration]]}} and
4221+
{{VideoFrame/[[timestamp]]}} respectively.
4222+
7. Assign |colorSpace| to {{VideoFrame/[[color space]]}}.
4223+
8. Let |resource| be a new [=media resource=] containing the result of
4224+
conversion of [=media resource=] referenced by |frame|'s
4225+
{{VideoFrame/[[resource reference]]}} into a color space and pixel
4226+
format specified by |colorSpace| and |format| respectively.
4227+
9. Assign the reference to |resource| to {{VideoFrame/[[resource reference]]}}
4228+
3. Return |convertedFrame|.
4229+
41864230
: <dfn for=VideoFrame>Copy VideoFrame metadata</dfn> (with |metadata|)
41874231
:: 1. Let |metadataCopySerialized| be [$StructuredSerialize$](|metadata|).
41884232
2. Let |metadataCopy| be [$StructuredDeserialize$](|metadataCopySerialized|, [=the current Realm=]).
4189-
3. return |metadataCopy|.
4233+
3. Return |metadataCopy|.
41904234

41914235
The goal of this algorithm is to ensure that metadata owned by a {{VideoFrame}} is immutable.
41924236

@@ -4239,13 +4283,15 @@
42394283

42404284
VideoFrame CopyTo() Options {#videoframe-copyto-options}
42414285
------------------------------------------------------------
4242-
Options to specify a rectangle of pixels to copy and the offset and stride of
4243-
planes in the destination buffer.
4286+
Options to specify a rectangle of pixels to copy, their format, and the offset
4287+
and stride of planes in the destination buffer.
42444288

42454289
<xmp class='idl'>
42464290
dictionary VideoFrameCopyToOptions {
42474291
DOMRectInit rect;
42484292
sequence<PlaneLayout> layout;
4293+
VideoPixelFormat format;
4294+
PredefinedColorSpace colorSpace;
42494295
};
42504296
</xmp>
42514297

@@ -4273,6 +4319,18 @@
42734319
to specify an offset and stride for each plane in the destination
42744320
{{BufferSource}}. If unspecified, the planes will be tightly packed. It is
42754321
invalid to specify planes that overlap.
4322+
: <dfn dict-member for=VideoFrameCopyToOptions>format</dfn>
4323+
:: A {{VideoPixelFormat}} for the pixel data in the destination
4324+
{{BufferSource}}. Potential values are: {{RGBA}}, {{RGBX}}, {{BGRA}},
4325+
{{BGRX}}. If it does not [=map/exist=], the destination
4326+
{{BufferSource}} will be in the same format as {{VideoFrame/format}} .
4327+
: <dfn dict-member for=VideoFrameCopyToOptions>colorSpace</dfn>
4328+
:: A {{PredefinedColorSpace}} that <em class="rfc2119">MUST</em> be used as
4329+
a target color space for the pixel data in the destination
4330+
{{BufferSource}}, but only if {{VideoFrameCopyToOptions/format}} is one of
4331+
{{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}}, otherwise it is ignored.
4332+
If it does not [=map/exist=], {{srgb}} is used.
4333+
42764334

42774335
DOMRects in VideoFrame {#videoframe-domrect}
42784336
--------------------------------------------

0 commit comments

Comments
 (0)