Skip to content

Commit 5b1fb6e

Browse files
committed
Make Encoded*Chunk interfaces immutable.
Provides a readInto() method for copying the data out. Fixes #80. Also, see #127.
1 parent a5e12fc commit 5b1fb6e

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

index.src.html

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,9 @@
17201720
constructor(EncodedAudioChunkInit init);
17211721
readonly attribute EncodedAudioChunkType type;
17221722
readonly attribute unsigned long long timestamp; // microseconds
1723-
readonly attribute ArrayBuffer data;
1723+
readonly attribute unsigned long byteLength;
1724+
1725+
undefined readInto(ArrayBufferView dst);
17241726
};
17251727

17261728
dictionary EncodedAudioChunkInit {
@@ -1735,27 +1737,39 @@
17351737
};
17361738
</xmp>
17371739

1740+
### Internal Slots ### {#encodedaudiochunk-internal-slots}
1741+
: <dfn attribute for=EncodedAudioChunk>[[internal data]]</dfn></dt>
1742+
:: An array of bytes repsenting the encoded chunk data.
1743+
17381744
### Constructors ###{#encodedaudiochunk-constructors}
17391745
<dfn constructor for=EncodedAudioChunk title="EncodedAudioChunk(init)">
17401746
EncodedAudioChunk(init)
17411747
</dfn>
17421748
1. Let |chunk| be a new {{EncodedAudioChunk}} object, initialized as follows
1743-
1. Assign `init.type` to `chunk.type`.
1744-
2. Assign `init.timestamp` to `chunk.timestamp`.
1745-
3. Assign a copy of `init.data` to `chunk.data`.
1749+
1. Assign `init.type` to {{EncodedAudioChunk/type}}.
1750+
2. Assign `init.timestamp` to {{EncodedAudioChunk/timestamp}}.
1751+
3. Assign a copy of `init.data` to {{EncodedAudioChunk/[[internal data]]}}.
1752+
4. Assign `init.data.byteLength` to {{EncodedAudioChunk/byteLength}};
17461753
5. Return |chunk|.
17471754

17481755
### Attributes ###{#encodedaudiochunk-attributes}
17491756
<dl>
1750-
<dt><dfn attribute for=EncodedAudioChunk>type</dfn></dt>
1751-
<dd>Describes whether the chunk is a key frame.</dd>
1757+
: <dfn attribute for=EncodedAudioChunk>type</dfn>
1758+
:: Describes whether the chunk is a key frame.
17521759

1753-
<dt><dfn attribute for=EncodedAudioChunk>timestamp</dfn></dt>
1754-
<dd>The presentation timestamp, given in microseconds.</dd>
1760+
: <dfn attribute for=EncodedAudioChunk>timestamp</dfn>
1761+
:: The presentation timestamp, given in microseconds.
17551762

1756-
<dt><dfn attribute for=EncodedAudioChunk>data</dfn></dt>
1757-
<dd>A sequence of bytes containing encoded audio data.</dd>
1758-
</dl>
1763+
: <dfn attribute for=EncodedAudioChunk>byteLength</dfn>
1764+
:: The byte length of {{EncodedAudioChunk/[[internal data]]}}.
1765+
1766+
### Methods ###{#encodedaudiochunk-methods}
1767+
: <dfn method for=EncodedAudioChunk>readInto(dst)</dfn>
1768+
:: When invoked, run these steps:
1769+
1. If {{EncodedAudioChunk/byteLength}} is greater than
1770+
|dst|.`byteLength`,
1771+
throw a {{TypeError}}.
1772+
2. Copy the {{EncodedAudioChunk/[[internal data]]}} into |dst|.
17591773

17601774
EncodedVideoChunk Interface{#encodedvideochunk-interface}
17611775
-----------------------------------------------------------
@@ -1766,7 +1780,9 @@
17661780
readonly attribute EncodedVideoChunkType type;
17671781
readonly attribute unsigned long long timestamp; // microseconds
17681782
readonly attribute unsigned long long? duration; // microseconds
1769-
readonly attribute ArrayBuffer data;
1783+
readonly attribute unsigned long byteLength;
1784+
1785+
undefined readInto(ArrayBufferView dst);
17701786
};
17711787

17721788
dictionary EncodedVideoChunkInit {
@@ -1782,33 +1798,44 @@
17821798
};
17831799
</xmp>
17841800

1801+
### Internal Slots ### {#encodedvideochunk-internal-slots}
1802+
: <dfn attribute for=EncodedVideoChunk>[[internal data]]</dfn></dt>
1803+
:: An array of bytes repsenting the encoded chunk data.
1804+
17851805
### Constructors ###{#encodedvideochunk-constructors}
17861806
<dfn constructor for=EncodedVideoChunk title="EncodedVideoChunk(init)">
17871807
EncodedVideoChunk(init)
17881808
</dfn>
17891809
1. Let |chunk| be a new {{EncodedVideoChunk}} object, initialized as follows
1790-
1. Assign `init.type` to `chunk.type`.
1791-
2. Assign `init.timestamp` to `chunk.timestamp`.
1810+
1. Assign `init.type` to {{EncodedVideoChunk/type}}.
1811+
2. Assign `init.timestamp` to {{EncodedVideoChunk/timestamp}}.
17921812
3. If duration is present in init, assign `init.duration` to
1793-
`chunk.duration`. Otherwise, assign null to `chunk.duration`.
1794-
2. Assign a copy of `init.data` to `chunk.data`.
1813+
{{EncodedVideoChunk/duration}}. Otherwise, assign `null` to
1814+
{{EncodedVideoChunk/duration}}.
1815+
4. Assign a copy of `init.data` to {{EncodedVideoChunk/[[internal data]]}}.
1816+
5. Assign `init.data.byteLength` to {{EncodedVideoChunk/byteLength}};
17951817
3. Return |chunk|.
17961818

17971819
### Attributes ###{#encodedvideochunk-attributes}
1798-
<dl>
1799-
<dt><dfn attribute for=EncodedVideoChunk>type</dfn></dt>
1800-
<dd>Describes whether the chunk is a key frame or not.</dd>
1820+
: <dfn attribute for=EncodedVideoChunk>type</dfn>
1821+
:: Describes whether the chunk is a key frame or not.
18011822

1802-
<dt><dfn attribute for=EncodedVideoChunk>timestamp</dfn></dt>
1803-
<dd>The presentation timestamp, given in microseconds.</dd>
1823+
: <dfn attribute for=EncodedVideoChunk>timestamp</dfn>
1824+
:: The presentation timestamp, given in microseconds.
18041825

1805-
<dt><dfn attribute for=EncodedVideoChunk>duration</dfn></dt>
1806-
<dd>The presentation duration, given in microseconds.</dd>
1826+
: <dfn attribute for=EncodedVideoChunk>duration</dfn>
1827+
:: The presentation duration, given in microseconds.
18071828

1808-
<dt><dfn attribute for=EncodedVideoChunk>data</dfn></dt>
1809-
<dd>A sequence of bytes containing encoded video data.</dd>
1810-
</dl>
1829+
: <dfn attribute for=EncodedVideoChunk>byteLength</dfn>
1830+
:: The byte length of {{EncodedVideoChunk/[[internal data]]}}.
18111831

1832+
### Methods ###{#encodedvideochunk-methods}
1833+
: <dfn method for=EncodedVideoChunk>readInto(dst)</dfn>
1834+
:: When invoked, run these steps:
1835+
1. If {{EncodedVideoChunk/byteLength}} is greater than
1836+
|dst|.`byteLength`,
1837+
throw a {{TypeError}}.
1838+
2. Copy the {{EncodedVideoChunk/[[internal data]]}} into |dst|.
18121839

18131840
Raw Media Interfaces (Frames){#raw-media-interfaces}
18141841
====================================================
@@ -2300,9 +2327,6 @@
23002327
This concern is mitigated by ensuring that input and output interfaces are
23012328
immutable.
23022329

2303-
ISSUE: EncodedVideoChunk and EncodedAudioChunk currently expose a mutable
2304-
data. See <a href="https://github.com/w3c/webcodecs/issues/80">#80</a>.
2305-
23062330
Privacy Considerations{#privacy-considerations}
23072331
===============================================
23082332
The primary privacy impact is an increased ability to fingerprint users by

0 commit comments

Comments
 (0)