Skip to content

Commit 25c6e3e

Browse files
author
Dan Sanders
committed
Add orientation to VideoFrame
1 parent a2770c1 commit 25c6e3e

File tree

1 file changed

+153
-58
lines changed

1 file changed

+153
-58
lines changed

index.src.html

Lines changed: 153 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,8 @@
33373337
readonly attribute unsigned long codedHeight;
33383338
readonly attribute DOMRectReadOnly? codedRect;
33393339
readonly attribute DOMRectReadOnly? visibleRect;
3340+
readonly attribute double rotation;
3341+
readonly attribute boolean flip;
33403342
readonly attribute unsigned long displayWidth;
33413343
readonly attribute unsigned long displayHeight;
33423344
readonly attribute unsigned long long? duration; // microseconds
@@ -3364,6 +3366,9 @@
33643366
// aspect ratio unless an explicit displayWidth and displayHeight are given.
33653367
DOMRectInit visibleRect;
33663368

3369+
double rotation = 0;
3370+
boolean flip = false;
3371+
33673372
// Default matches image unless visibleRect is provided.
33683373
[EnforceRange] unsigned long displayWidth;
33693374
[EnforceRange] unsigned long displayHeight;
@@ -3384,6 +3389,9 @@
33843389
// Default visible rect is coded size positioned at (0,0)
33853390
DOMRectInit visibleRect;
33863391

3392+
double rotation = 0;
3393+
boolean flip = false;
3394+
33873395
// Default display dimensions match visibleRect.
33883396
[EnforceRange] unsigned long displayWidth;
33893397
[EnforceRange] unsigned long displayHeight;
@@ -3433,6 +3441,14 @@
34333441
:: The height of pixels to include in visible rectangle, starting from
34343442
{{VideoFrame/[[visible top]]}}.
34353443

3444+
: <dfn attribute for=VideoFrame>\[[rotation]]</dfn>
3445+
:: The rotation to applied to the {{VideoFrame}} when rendered, in degrees
3446+
clockwise. Rotation applies before flip.
3447+
3448+
: <dfn attribute for=VideoFrame>\[[flip]]</dfn>
3449+
:: Whether a horizontal flip is applied to the {{VideoFrame}} when rendered.
3450+
Flip is applied after rotation.
3451+
34363452
: <dfn attribute for=VideoFrame>[[display width]]</dfn>
34373453
:: Width of the {{VideoFrame}} when displayed after applying aspect ratio
34383454
adjustments.
@@ -3489,10 +3505,16 @@
34893505
default image of the animation (the one that the format defines is
34903506
to be used when animation is not supported or is disabled), or, if
34913507
there is no such image, the first frame of the animation.
3492-
4. Let |width| and |height| be the [=natural width=] and
3493-
[=natural height=] of |image|.
3494-
5. Run the [=VideoFrame/Initialize Frame With Resource and Size=]
3495-
algorithm with |init|, |frame|, |resource|, |width|, and |height|
3508+
4. Let |codedWidth| and |codedHeight| be the width and height of
3509+
|resource|.
3510+
5. Let |baseRotation| and |baseFlip| describe the rotation and flip of
3511+
|image| relative to |resource|.
3512+
6. Let |defaultDisplayWidth| and |defaultDisplayHeight| be the
3513+
[=natural width=] and [=natural height=] of |image|.
3514+
7. Run the [=VideoFrame/Initialize Frame With Resource=]
3515+
algorithm with |init|, |frame|, |resource|, |codedWidth|,
3516+
|codedHeight|, |baseRotation|, |baseFlip|, |defaultDisplayWidth|,
3517+
and |defaultDisplayHeight|.
34963518

34973519
- {{HTMLVideoElement}}
34983520
1. If |image|'s {{HTMLMediaElement/networkState}} attribute is
@@ -3517,8 +3539,9 @@
35173539
reference counting where feasible.
35183540

35193541
3. Let |width| be `image.width` and |height| be `image.height`.
3520-
4. Run the [=VideoFrame/Initialize Frame With Resource and Size=]
3521-
algorithm with |init|, |frame|, |resource|, |width|, and |height|.
3542+
4. Run the [=VideoFrame/Initialize Frame With Resource=]
3543+
algorithm with |init|, |frame|, |resource|, |width|, |height|,
3544+
`0`, `false`, |width|, and |height|.
35223545

35233546
- {{VideoFrame}}
35243547
1. Run the [=VideoFrame/Initialize Frame From Other Frame=] algorithm
@@ -3609,24 +3632,38 @@
36093632
{{VideoFrame/[[visible width]]}}.
36103633
2. Assign {{VideoFrame/[[coded height]]}} to
36113634
{{VideoFrame/[[visible height]]}}.
3612-
4. If |init|.{{VideoFrameBufferInit/displayWidth}} [=map/exists=], assign
3613-
it to {{VideoFrame/[[display width]]}}. Otherwise, assign
3614-
{{VideoFrame/[[visible width]]}} to {{VideoFrame/[[display width]]}}.
3615-
5. If |init|.{{VideoFrameBufferInit/displayHeight}} [=map/exists=], assign
3616-
it to {{VideoFrame/[[display height]]}}. Otherwise, assign
3617-
{{VideoFrame/[[visible height]]}} to {{VideoFrame/[[display height]]}}.
3618-
6. Assign |init|'s {{VideoFrameBufferInit/timestamp}} and
3635+
4. Assign the result of running the [=VideoFrame/Parse Rotation=] algorithm,
3636+
with |init|.{{VideoFrameBufferInit/rotation}}, to
3637+
{{VideoFrame/[[rotation]]}}.
3638+
5. Assign |init|.{{VideoFrameBufferInit/flip}} to
3639+
{{VideoFrame/[[flip]]}}.
3640+
6. If {{VideoFrameBufferInit/displayWidth}} and
3641+
{{VideoFrameBufferInit/displayHeight}} [=map/exist=] in |init|, assign
3642+
them to {{VideoFrame/[[display width]]}} and
3643+
{{VideoFrame/[[display height]]}} respectively.
3644+
7. Otherwise:
3645+
1. If {{VideoFrame/[[rotation]]}} is equal to `0` or `180`:
3646+
1. Assign {{VideoFrame/[[visible width]]}} to
3647+
{{VideoFrame/[[display width]]}}.
3648+
2. Assign {{VideoFrame/[[visible height]]}} to
3649+
{{VideoFrame/[[display height]]}}.
3650+
2. Otherwise:
3651+
1. Assign {{VideoFrame/[[visible height]]}} to
3652+
{{VideoFrame/[[display width]]}}.
3653+
2. Assign {{VideoFrame/[[visible width]]}} to
3654+
{{VideoFrame/[[display height]]}}.
3655+
8. Assign |init|'s {{VideoFrameBufferInit/timestamp}} and
36193656
{{VideoFrameBufferInit/duration}} to {{VideoFrame/[[timestamp]]}} and
36203657
{{VideoFrame/[[duration]]}} respectively.
3621-
7. Let |colorSpace| be `undefined`.
3622-
8. If |init|.{{VideoFrameBufferInit/colorSpace}} [=map/exists=], assign its
3658+
9. Let |colorSpace| be `undefined`.
3659+
10. If |init|.{{VideoFrameBufferInit/colorSpace}} [=map/exists=], assign its
36233660
value to |colorSpace|.
3624-
9. Assign |init|'s {{VideoFrameBufferInit/format}} to
3661+
11. Assign |init|'s {{VideoFrameBufferInit/format}} to
36253662
{{VideoFrame/[[format]]}}.
3626-
10. Assign the result of running the [=VideoFrame/Pick Color Space=]
3663+
12. Assign the result of running the [=VideoFrame/Pick Color Space=]
36273664
algorithm, with |colorSpace| and {{VideoFrame/[[format]]}}, to
36283665
{{VideoFrame/[[color space]]}}.
3629-
11. Assign the result of calling [=Copy VideoFrame metadata=]
3666+
13. Assign the result of calling [=Copy VideoFrame metadata=]
36303667
with |init|'s {{VideoFrameBufferInit/metadata}} to
36313668
|frame|.{{VideoFrame/[[metadata]]}}.
36323669
22. Return |frame|.
@@ -3685,16 +3722,29 @@
36853722
{{DOMRectReadOnly/height}} respectively.
36863723
3. Return |rect|.
36873724

3725+
: <dfn attribute for=VideoFrame>rotation</dfn>
3726+
:: The rotation to applied to the VideoFrame when rendered, in degrees
3727+
clockwise. Rotation applies before flip.
3728+
3729+
The {{VideoFrame/rotation}} getter steps are to return
3730+
{{VideoFrame/[[rotation]]}}.
3731+
3732+
: <dfn attribute for=VideoFrame>flip</dfn>
3733+
:: Whether a horizontal flip is applied to the {{VideoFrame}} when rendered.
3734+
Flip applies after rotation.
3735+
3736+
The {{VideoFrame/flip}} getter steps are to return {{VideoFrame/[[flip]]}}.
3737+
36883738
: <dfn attribute for=VideoFrame>displayWidth</dfn>
3689-
:: Width of the VideoFrame when displayed after applying aspect ratio
3690-
adjustments.
3739+
:: Width of the VideoFrame when displayed after applying rotation and aspect
3740+
ratio adjustments.
36913741

36923742
The {{VideoFrame/displayWidth}} getter steps are to return
36933743
{{VideoFrame/[[display width]]}}.
36943744

36953745
: <dfn attribute for=VideoFrame>displayHeight</dfn>
3696-
:: Height of the VideoFrame when displayed after applying aspect ratio
3697-
adjustments.
3746+
:: Height of the VideoFrame when displayed after applying rotation and aspect
3747+
ratio adjustments.
36983748

36993749
The {{VideoFrame/displayHeight}} getter steps are to return
37003750
{{VideoFrame/[[display height]]}}.
@@ -3961,26 +4011,29 @@
39614011
{{VideoFrame/colorSpace}}.
39624012
6. Let |defaultVisibleRect| be the result of performing the getter steps
39634013
for {{VideoFrame/visibleRect}} on |otherFrame|.
3964-
7. Let |defaultDisplayWidth|, and |defaultDisplayHeight| be |otherFrame|'s
3965-
{{VideoFrame/[[display width]]}}, and {{VideoFrame/[[display height]]}}
4014+
7. Let |baseRotation| and |baseFlip| be |otherFrame|'s
4015+
{{VideoFrame/[[rotation]]}} and {{VideoFrame/[[flip]]}}, respectively.
4016+
8. Let |defaultDisplayWidth| and |defaultDisplayHeight| be |otherFrame|'s
4017+
{{VideoFrame/[[display width]]}} and {{VideoFrame/[[display height]]}},
39664018
respectively.
3967-
8. Run the [=VideoFrame/Initialize Visible Rect and Display Size=]
3968-
algorithm with |init|, |frame|, |defaultVisibleRect|,
3969-
|defaultDisplayWidth|, and |defaultDisplayHeight|.
3970-
9. If {{VideoFrameInit/duration}} [=map/exists=] in |init|, assign it to
4019+
9. Run the [=VideoFrame/Initialize Visible Rect, Orientation, and Display Size=]
4020+
algorithm with |init|, |frame|, |defaultVisibleRect|, |baseRotation|,
4021+
|baseFlip|, |defaultDisplayWidth|, and |defaultDisplayHeight|.
4022+
10. If {{VideoFrameInit/duration}} [=map/exists=] in |init|, assign it to
39714023
|frame|'s {{VideoFrame/[[duration]]}}. Otherwise, assign
39724024
|otherFrame|.{{VideoFrame/duration}} to
39734025
|frame|'s {{VideoFrame/[[duration]]}}.
3974-
10. If {{VideoFrameInit/timestamp}} [=map/exists=] in |init|, assign it to
4026+
11. If {{VideoFrameInit/timestamp}} [=map/exists=] in |init|, assign it to
39754027
|frame|'s {{VideoFrame/[[timestamp]]}}. Otherwise, assign
39764028
|otherFrame|'s {{VideoFrame/timestamp}} to
39774029
|frame|'s {{VideoFrame/[[timestamp]]}}.
3978-
11. Assign |format| to |frame|.{{VideoFrame/[[format]]}}.
3979-
12. Assign the result of calling [=Copy VideoFrame metadata=]
4030+
12. Assign |format| to |frame|.{{VideoFrame/[[format]]}}.
4031+
13. Assign the result of calling [=Copy VideoFrame metadata=]
39804032
with |init|'s {{VideoFrameInit/metadata}} to |frame|.{{VideoFrame/[[metadata]]}}.
39814033

3982-
: <dfn for=VideoFrame>Initialize Frame With Resource and Size</dfn> (with
3983-
|init|, |frame|, |resource|, |width| and |height|)
4034+
: <dfn for=VideoFrame>Initialize Frame With Resource</dfn> (with
4035+
|init|, |frame|, |resource|, |codedWidth|, |codedHeight|, |baseRotation|,
4036+
|baseFlip|, |defaultDisplayWidth|, and |defaultDisplayHeight|)
39844037
:: 1. Let |format| be `null`.
39854038
2. If |resource| uses a recognized {{VideoPixelFormat}}, assign the
39864039
{{VideoPixelFormat}} of |resource| to |format|.
@@ -3992,13 +4045,14 @@
39924045
6. If |init|.{{VideoFrameInit/alpha}} is {{AlphaOption/discard}}, assign
39934046
|format|'s [=equivalent opaque format=] to |format|.
39944047
7. Assign |format| to {{VideoFrame/[[format]]}}
3995-
8. Assign |width| and |height| to |frame|'s {{VideoFrame/[[coded width]]}}
3996-
and {{VideoFrame/[[coded height]]}} respectively.
4048+
8. Assign |codedWidth| and |codedHeight| to |frame|'s
4049+
{{VideoFrame/[[coded width]]}} and {{VideoFrame/[[coded height]]}}
4050+
respectively.
39974051
9. Let |defaultVisibleRect| be a new {{DOMRect}} constructed with
3998-
«[ "x:" → `0`, "y" → `0`, "width" → |width|, "height" → |height| ]»
3999-
10. Run the [=VideoFrame/Initialize Visible Rect and Display Size=]
4000-
algorithm with |init|, |frame|, |defaultVisibleRect|, |width|, and
4001-
|height|.
4052+
«[ "x:" → `0`, "y" → `0`, "width" → |codedWidth|, "height" → |codedHeight| ]»
4053+
10. Run the [=VideoFrame/Initialize Visible Rect, Orientation, and Display Size=]
4054+
algorithm with |init|, |frame|, |defaultVisibleRect|,
4055+
|defaultDisplayWidth|, and |defaultDisplayHeight|.
40024056
11. Assign `init`.{{VideoFrameInit/duration}} to
40034057
|frame|'s {{VideoFrame/[[duration]]}}.
40044058
12. Assign `init`.{{VideoFrameInit/timestamp}} to
@@ -4008,30 +4062,55 @@
40084062
14. Otherwise, assign a new {{VideoColorSpace}}, constructed with an empty
40094063
{{VideoColorSpaceInit}}, to {{VideoFrame/[[color space]]}}.
40104064

4011-
: <dfn for=VideoFrame>Initialize Visible Rect and Display Size</dfn> (with
4012-
|init|, |frame|, |defaultVisibleRect|, |defaultDisplayWidth| and
4013-
|defaultDisplayHeight|)
4065+
: <dfn for=VideoFrame>Initialize Visible Rect, Orientation, and Display Size</dfn>
4066+
(with |init|, |frame|, |defaultVisibleRect|, |baseRotation|, |baseFlip|,
4067+
|defaultDisplayWidth| and |defaultDisplayHeight|)
40144068
:: 1. Let |visibleRect| be |defaultVisibleRect|.
40154069
2. If |init|.{{VideoFrameInit/visibleRect}} [=map/exists=], assign it to
40164070
|visibleRect|.
40174071
3. Assign |visibleRect|'s {{DOMRect/x}}, {{DOMRect/y}}, {{DOMRect/width}},
40184072
and {{DOMRect/height}}, to |frame|'s {{VideoFrame/[[visible left]]}},
40194073
{{VideoFrame/[[visible top]]}}, {{VideoFrame/[[visible width]]}}, and
40204074
{{VideoFrame/[[visible height]]}} respectively.
4021-
4. If {{VideoFrameInit/displayWidth}} and {{VideoFrameInit/displayHeight}}
4075+
4. Let |rotation| be the result of running the [=VideoFrame/Parse Rotation=]
4076+
algorithm, with |init|.{{VideoFrameInit/rotation}}.
4077+
5. Assign the result of running the [=VideoFrame/Add Rotations=] algorithm,
4078+
with |baseRotation|, |baseFlip|, and |rotation|, to |frame|'s
4079+
{{VideoFrame/[[rotation]]}}.
4080+
6. If |baseFlip| is equal to |init|.{{VideoFrameInit/flip}}, assign `false`
4081+
to |frame|'s {{VideoFrame/[[flip]]}}. Otherwise, assign `true` to
4082+
|frame|'s {{VideoFrame/[[flip]]}}.
4083+
7. If {{VideoFrameInit/displayWidth}} and {{VideoFrameInit/displayHeight}}
40224084
[=map/exist=] in |init|, assign them to {{VideoFrame/[[display width]]}}
40234085
and {{VideoFrame/[[display height]]}} respectively.
4024-
5. Otherwise:
4025-
1. Let |widthScale| be the result of dividing |defaultDisplayWidth| by
4026-
|defaultVisibleRect|.{{DOMRect/width}}.
4027-
2. Let |heightScale| be the result of dividing |defaultDisplayHeight| by
4028-
|defaultVisibleRect|.{{DOMRect/height}}.
4029-
3. Multiply |frame|'s {{VideoFrame/[[visible width]]}} by |widthScale|
4030-
and round the result. Assign the rounded result to
4031-
{{VideoFrame/[[display width]]}}.
4032-
4. Multiply |frame|'s {{VideoFrame/[[visible height]]}} by
4033-
|heightScale| and round the result. Assign the rounded result to
4034-
|frame|'s {{VideoFrame/[[display height]]}}.
4086+
8. Otherwise:
4087+
1. If |baseRotation| is equal to `0` or `180`:
4088+
1. Let |widthScale| be the result of dividing |defaultDisplayWidth|
4089+
by |defaultVisibleRect|.{{DOMRect/width}}.
4090+
2. Let |heightScale| be the result of dividing
4091+
|defaultDisplayHeight| by
4092+
|defaultVisibleRect|.{{DOMRect/height}}.
4093+
2. Otherwise:
4094+
1. Let |widthScale| be the result of dividing |defaultDisplayHeight|
4095+
by |defaultVisibleRect|.{{DOMRect/width}}.
4096+
2. Let |heightScale| be the result of dividing |defaultDisplayWidth|
4097+
by |defaultVisibleRect|.{{DOMRect/height}}.
4098+
3. Let |displayWidth| be
4099+
`|frame|'s {{VideoFrame/[[visible width]]}} * |widthScale|`, rounded
4100+
to the nearest integer.
4101+
4. Let |displayHeight| be
4102+
`|frame|'s {{VideoFrame/[[visible height]]}} * |heightScale|`,
4103+
rounded to the nearest integer.
4104+
5. If |rotation| is equal to `0` or `180`:
4105+
1. Assign |displayWidth| to |frame|'s
4106+
{{VideoFrame/[[display width]]}}.
4107+
2. Assign |displayHeight| to |frame|'s
4108+
{{VideoFrame/[[display height]]}}.
4109+
6. Otherwise:
4110+
1. Assign |displayHeight| to |frame|'s
4111+
{{VideoFrame/[[display width]]}}.
4112+
2. Assign |displayWidth| to |frame|'s
4113+
{{VideoFrame/[[display height]]}}.
40354114

40364115
: <dfn export>Clone VideoFrame</dfn> (with |frame|)
40374116
:: 1. Let |clone| be a new {{VideoFrame}} initialized as follows:
@@ -4052,9 +4131,25 @@
40524131
4. Assign `0` to |frame|'s {{VideoFrame/[[coded width]]}},
40534132
{{VideoFrame/[[coded height]]}}, {{VideoFrame/[[visible left]]}},
40544133
{{VideoFrame/[[visible top]]}}, {{VideoFrame/[[visible width]]}},
4055-
{{VideoFrame/[[visible height]]}}, {{VideoFrame/[[display width]]}},
4056-
and {{VideoFrame/[[display height]]}}.
4057-
5. Assign a new {{VideoFrameMetadata}} to |frame|.{{VideoFrame/[[metadata]]}}.
4134+
{{VideoFrame/[[visible height]]}}, {{VideoFrame/[[rotation]]}},
4135+
{{VideoFrame/[[display width]]}}, and {{VideoFrame/[[display height]]}}.
4136+
5. Assign `false` to |frame|'s {{VideoFrame/[[flip]]}}.
4137+
6. Assign a new {{VideoFrameMetadata}} to |frame|.{{VideoFrame/[[metadata]]}}.
4138+
4139+
: <dfn for=VideoFrame>Parse Rotation</dfn> (with |rotation|)
4140+
:: 1. Let |alignedRotation| be the nearest multiple of `90` to |rotation|.
4141+
2. Let |fullTurns| be the greatest multiple of `360` less than or equal to
4142+
|alignedRotation|.
4143+
3. Return `|alignedRotation| - |fullTurns|`.
4144+
4145+
: <dfn for=VideoFrame>Add Rotations</dfn> (with |baseRotation|, |baseFlip|,
4146+
and |rotation|)
4147+
:: 1. If |baseFlip| is `false`, let |combinedRotation| be
4148+
`|baseRotation| + |rotation|`. Otherwise, let |combinedRotation| be
4149+
`|baseRotation| - |rotation|`.
4150+
2. Let |fullTurns| be the greatest multiple of `360` less than or equal to
4151+
|combinedRotation|.
4152+
3. Return `|combinedRotation| - |fullTurns|`.
40584153

40594154
: <dfn for=VideoFrame>Parse VideoFrameCopyToOptions</dfn> (with |options|)
40604155
:: 1. Let |defaultRect| be the result of performing the getter steps for
@@ -4232,7 +4327,7 @@
42324327
{{VideoFrame/[[coded height]]}}, {{VideoFrame/[[visible left]]}},
42334328
{{VideoFrame/[[visible top]]}}, {{VideoFrame/[[visible width]]}},
42344329
and {{VideoFrame/[[visible height]]}} respectively.
4235-
6. Assign |frame|'s {{VideoFrame/[[duration]]}} and |frame|'s
4330+
6. Assign |frame|'s {{VideoFrame/[[duration]]}} and |frame|'s
42364331
{{VideoFrame/[[timestamp]]}} to {{VideoFrame/[[duration]]}} and
42374332
{{VideoFrame/[[timestamp]]}} respectively.
42384333
7. Assign the result of running the <a>Convert

0 commit comments

Comments
 (0)