Skip to content

Commit 48cfad4

Browse files
committed
Introduce VideoFrame metadata
1 parent 938df12 commit 48cfad4

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

index.src.html

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999

100100
spec: webrtc-svc; urlPrefix: https://w3c.github.io/webrtc-svc/
101101
type: dfn; text: scalability mode identifier; url:#scalabilitymodes*
102+
103+
spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/
104+
type: dfn; text: the current Realm; url: #current-realm
105+
type: dfn; text: SetIntegrityLevel; url: #sec-setintegritylevel
102106
</pre>
103107

104108
<pre class='biblio'>
@@ -3182,6 +3186,8 @@
31823186
readonly attribute long long? timestamp; // microseconds
31833187
readonly attribute VideoColorSpace colorSpace;
31843188

3189+
VideoFrameMetadata getMetadata();
3190+
31853191
unsigned long allocationSize(
31863192
optional VideoFrameCopyToOptions options = {});
31873193
Promise<sequence<PlaneLayout>> copyTo(
@@ -3204,6 +3210,8 @@
32043210
// Default matches image unless visibleRect is provided.
32053211
[EnforceRange] unsigned long displayWidth;
32063212
[EnforceRange] unsigned long displayHeight;
3213+
3214+
VideoFrameMetadata metadata;
32073215
};
32083216

32093217
dictionary VideoFrameBufferInit {
@@ -3225,6 +3233,10 @@
32253233

32263234
VideoColorSpaceInit colorSpace;
32273235
};
3236+
3237+
dictionary VideoFrameMetadata {
3238+
any user;
3239+
};
32283240
</xmp>
32293241

32303242
### Internal Slots ###{#videoframe-internal-slots}
@@ -3279,6 +3291,10 @@
32793291
: <dfn attribute for=VideoFrame>[[color space]]</dfn>
32803292
:: The {{VideoColorSpace}} associated with this frame.
32813293

3294+
: <dfn attribute for=VideoFrame>\[[metadata]]</dfn>
3295+
:: The {{VideoFrameMetadata}} associated with this frame.
3296+
3297+
32823298
### Constructors ###{#videoframe-constructors}
32833299

32843300
<dfn constructor for=VideoFrame title="VideoFrame(image, init)">
@@ -3291,8 +3307,11 @@
32913307
with the [=webappapis/entry settings object=]'s
32923308
[=origin/origin=], then throw a {{SecurityError}}
32933309
{{DOMException}}.
3294-
3. Let |frame| be a new {{VideoFrame}}.
3295-
5. Switch on |image|:
3310+
3. Let |metadata| be the result of calling [=Copy VideoFrame metadata=]
3311+
with |init|'s {{VideoFrameInit/metadata}}.
3312+
4. Let |frame| be a new {{VideoFrame}}.
3313+
5. Assign |metadata| to |frame|'s {{VideoFrame/metadata}}.
3314+
6. Switch on |image|:
32963315
- {{HTMLImageElement}}
32973316
- {{SVGImageElement}}
32983317
1. If {{VideoFrameInit/timestamp}} does not [=map/exist=] in
@@ -3339,7 +3358,7 @@
33393358
1. Run the [=VideoFrame/Initialize Frame From Other Frame=] algorithm
33403359
with |init|, |frame|, and |image|.
33413360

3342-
6. Return |frame|.
3361+
7. Return |frame|.
33433362

33443363

33453364
<dfn constructor for=VideoFrame title="VideoFrame(data, init)">
@@ -3365,9 +3384,11 @@
33653384
Layout and Allocation Size=] algorithm with |parsedRect|,
33663385
|init|.{{VideoFrameBufferInit/format}}, and |optLayout|.
33673386
9. If |combinedLayout| is an exception, throw |combinedLayout|.
3368-
10. If `data.byteLength` is less than |combinedLayout|’s
3387+
10. Let |metadata| be the result of calling [=Copy VideoFrame metadata]
3388+
with |init|'s {{VideoFrameInit/metadata}}.
3389+
11. If `data.byteLength` is less than |combinedLayout|’s
33693390
[=combined buffer layout/allocationSize=], throw a {{TypeError}}.
3370-
11. Let |resource| be a new [=media resource=] containing a copy of |data|. Use
3391+
12. Let |resource| be a new [=media resource=] containing a copy of |data|. Use
33713392
{{VideoFrameBufferInit/visibleRect}} and {{VideoFrameBufferInit/layout}}
33723393
to determine where in |data| the pixels for each plane reside.
33733394

@@ -3380,18 +3401,18 @@
33803401
reposition the visible rectangle within |resource|. The final position
33813402
will be reflected by {{VideoFrame/visibleRect}}.
33823403

3383-
12. Let |resourceCodedWidth| be the coded width of |resource|.
3384-
13. Let |resourceCodedHeight| be the coded height of |resource|.
3385-
14. Let |resourceVisibleLeft| be the left offset for the visible rectangle of
3404+
13. Let |resourceCodedWidth| be the coded width of |resource|.
3405+
14. Let |resourceCodedHeight| be the coded height of |resource|.
3406+
15. Let |resourceVisibleLeft| be the left offset for the visible rectangle of
33863407
|resource|.
3387-
15. Let |resourceVisibleTop| be the top offset for the visible rectangle of
3408+
16. Let |resourceVisibleTop| be the top offset for the visible rectangle of
33883409
|resource|.
33893410

33903411
ISSUE: The spec <em class="rfc2119">SHOULD</em> provide definitions (and
33913412
possibly diagrams) for coded size, visible rectangle, and display size.
33923413
See [#166](https://github.com/w3c/webcodecs/issues/166).
33933414

3394-
16. Let |frame| be a new {{VideoFrame}} object initialized as follows:
3415+
17. Let |frame| be a new {{VideoFrame}} object initialized as follows:
33953416
1. Assign |resourceCodedWidth|, |resourceCodedHeight|,
33963417
|resourceVisibleLeft|, and |resourceVisibleTop| to
33973418
{{VideoFrame/[[coded width]]}}, {{VideoFrame/[[coded height]]}},
@@ -3426,7 +3447,8 @@
34263447
9. Assign the result of running the [=VideoFrame/Pick Color Space=]
34273448
algorithm, with |colorSpace| and {{VideoFrame/[[format]]}}, to
34283449
{{VideoFrame/[[color space]]}}.
3429-
17. Return |frame|.
3450+
10. Assign |metadata| to {{VideoFrame/[[metadata]]}}.
3451+
18. Return |frame|.
34303452

34313453
### Attributes ###{#videoframe-attributes}
34323454
: <dfn attribute for=VideoFrame>format</dfn>
@@ -3624,6 +3646,11 @@
36243646

36253647
When invoked, run the [=Close VideoFrame=] algorithm with [=this=].
36263648

3649+
: <dfn method for=VideoFrame>getMetadata()</dfn>
3650+
:: Gets the {{VideoFrameMetadata}} associated with this frame.
3651+
3652+
When invoked, return [=this=] {{VideoFrame/[[metadata]]}}.
3653+
36273654
### Algorithms ###{#videoframe-algorithms}
36283655
: <dfn>Create a VideoFrame</dfn> (with |output|, |timestamp|, |duration|, |displayAspectWidth|, |displayAspectHeight|, and |colorSpace|)
36293656
:: 1. Let |frame| be a new {{VideoFrame}}, constructed as follows:
@@ -3825,6 +3852,8 @@
38253852
and {{VideoFrame/[[display height]]}}.
38263853
5. Assign `null` to |frame|'s {{VideoFrame/[[duration]]}} and
38273854
{{VideoFrame/[[timestamp]]}}.
3855+
6. Assign `null` to |frame|'s {{VideoFrame/[[metadata]]}}.
3856+
38283857

38293858
: <dfn for=VideoFrame>Parse VideoFrameCopyToOptions</dfn> (with |options|)
38303859
:: 1. Let |defaultRect| be the result of performing the getter steps for
@@ -3998,19 +4027,29 @@
39984027
[=combined buffer layout/allocationSize=].
39994028
9. Return |combinedLayout|.
40004029

4030+
4031+
: <dfn for=VideoFrame>Copy VideoFrame metadata</dfn> (with |metadata|)
4032+
:: 1. Let |metadataCopySerialized| be [$StructuredSerialize$](|metadata|).
4033+
2. Let |metadataCopy| be [$StructuredDeserialize$](|metadataCopySerialized|, [=the current Realm=]).
4034+
3. Let |userMetadataCopy| be |metadataCopy|'s {{VideoFrameMetadata/user}}.
4035+
4. Call [=SetIntegrityLevel=] with |userMetadataCopy| and frozen.
4036+
5. return |metadataCopy|.
4037+
40014038
### Transfer and Serialization ###{#videoframe-transfer-serialization}
40024039

40034040
: The {{VideoFrame}} [=transfer steps=] (with |value| and |dataHolder|) are:
40044041
:: 1. If |value|'s {{platform object/[[Detached]]}} is `true`, throw a
40054042
{{DataCloneError}} {{DOMException}}.
4006-
2. For all {{VideoFrame}} internal slots in |value|, assign the value of
4043+
2. Let |metadata| be |value|'s {{VideoFrame/metadata}}.
4044+
3. Assign [$StructuredSerialize$](|metadata|) to |dataHolder|.[[metadata]].
4045+
4. For all other {{VideoFrame}} internal slots in |value|, assign the value of
40074046
each internal slot to a field in |dataHolder| with the same name as the
40084047
internal slot.
4009-
3. Run the [=Close VideoFrame=] algorithm with |value|.
4048+
5. Run the [=Close VideoFrame=] algorithm with |value|.
40104049

40114050
: The {{VideoFrame}} [=transfer-receiving steps=] (with |dataHolder| and
40124051
|value|) are:
4013-
:: 1. For all named fields in |dataHolder|, assign the value of each named
4052+
:: 1. For all other named fields in |dataHolder|, assign the value of each named
40144053
field to the {{VideoFrame}} internal slot in |value| with the same name
40154054
as the named field.
40164055

@@ -4023,14 +4062,18 @@
40234062
|value|'s {{VideoFrame/[[resource reference]]}}.
40244063
4. Let |newReference| be a new reference to |resource|.
40254064
5. Assign |newReference| to |serialized|.[[resource reference]].
4026-
6. For all remaining {{VideoFrame}} internal slots (excluding
4027-
{{VideoFrame/[[resource reference]]}}) in |value|, assign the value of
4065+
6. Let |metadata| be |value|'s {{VideoFrame/metadata}}.
4066+
7. Assign [$StructuredSerialize$](|metadata|) to |serialized|.[[metadata]].
4067+
8. For all remaining {{VideoFrame}} internal slots (excluding
4068+
{{VideoFrame/[[resource reference]]}} and {{VideoFrame/[[metadata]]}}) in |value|, assign the value of
40284069
each internal slot to a field in |serialized| with the same name as the
40294070
internal slot.
40304071

40314072
: The {{VideoFrame}} [=deserialization steps=] (with |serialized| and |value|)
40324073
are:
4033-
:: 1. For all named fields in |serialized|, assign the value of each named
4074+
:: 1. Let |metadata| be [$StructuredDeserialize$](|serialized|.[[metadata]], [=the current Realm=]).
4075+
2. Assign |metadata| to |value|'s {{VideoFrame/metadata}}.
4076+
3. For all other named fields in |serialized|, assign the value of each named
40344077
field to the {{VideoFrame}} internal slot in |value| with the same name
40354078
as the named field.
40364079

0 commit comments

Comments
 (0)