Skip to content

Commit

Permalink
Make Encoded*Chunk interfaces immutable.
Browse files Browse the repository at this point in the history
Provides a readInto() method for copying the data out.

Fixes #80. Also, see #127.
  • Loading branch information
chcunningham committed Apr 9, 2021
1 parent a5e12fc commit 5b1fb6e
Showing 1 changed file with 53 additions and 29 deletions.
82 changes: 53 additions & 29 deletions index.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,9 @@
constructor(EncodedAudioChunkInit init);
readonly attribute EncodedAudioChunkType type;
readonly attribute unsigned long long timestamp; // microseconds
readonly attribute ArrayBuffer data;
readonly attribute unsigned long byteLength;

undefined readInto(ArrayBufferView dst);
};

dictionary EncodedAudioChunkInit {
Expand All @@ -1735,27 +1737,39 @@
};
</xmp>

### Internal Slots ### {#encodedaudiochunk-internal-slots}
: <dfn attribute for=EncodedAudioChunk>[[internal data]]</dfn></dt>
:: An array of bytes repsenting the encoded chunk data.

### Constructors ###{#encodedaudiochunk-constructors}
<dfn constructor for=EncodedAudioChunk title="EncodedAudioChunk(init)">
EncodedAudioChunk(init)
</dfn>
1. Let |chunk| be a new {{EncodedAudioChunk}} object, initialized as follows
1. Assign `init.type` to `chunk.type`.
2. Assign `init.timestamp` to `chunk.timestamp`.
3. Assign a copy of `init.data` to `chunk.data`.
1. Assign `init.type` to {{EncodedAudioChunk/type}}.
2. Assign `init.timestamp` to {{EncodedAudioChunk/timestamp}}.
3. Assign a copy of `init.data` to {{EncodedAudioChunk/[[internal data]]}}.
4. Assign `init.data.byteLength` to {{EncodedAudioChunk/byteLength}};
5. Return |chunk|.

### Attributes ###{#encodedaudiochunk-attributes}
<dl>
<dt><dfn attribute for=EncodedAudioChunk>type</dfn></dt>
<dd>Describes whether the chunk is a key frame.</dd>
: <dfn attribute for=EncodedAudioChunk>type</dfn>
:: Describes whether the chunk is a key frame.

<dt><dfn attribute for=EncodedAudioChunk>timestamp</dfn></dt>
<dd>The presentation timestamp, given in microseconds.</dd>
: <dfn attribute for=EncodedAudioChunk>timestamp</dfn>
:: The presentation timestamp, given in microseconds.

<dt><dfn attribute for=EncodedAudioChunk>data</dfn></dt>
<dd>A sequence of bytes containing encoded audio data.</dd>
</dl>
: <dfn attribute for=EncodedAudioChunk>byteLength</dfn>
:: The byte length of {{EncodedAudioChunk/[[internal data]]}}.

### Methods ###{#encodedaudiochunk-methods}
: <dfn method for=EncodedAudioChunk>readInto(dst)</dfn>
:: When invoked, run these steps:
1. If {{EncodedAudioChunk/byteLength}} is greater than
|dst|.`byteLength`,
throw a {{TypeError}}.
2. Copy the {{EncodedAudioChunk/[[internal data]]}} into |dst|.

EncodedVideoChunk Interface{#encodedvideochunk-interface}
-----------------------------------------------------------
Expand All @@ -1766,7 +1780,9 @@
readonly attribute EncodedVideoChunkType type;
readonly attribute unsigned long long timestamp; // microseconds
readonly attribute unsigned long long? duration; // microseconds
readonly attribute ArrayBuffer data;
readonly attribute unsigned long byteLength;

undefined readInto(ArrayBufferView dst);
};

dictionary EncodedVideoChunkInit {
Expand All @@ -1782,33 +1798,44 @@
};
</xmp>

### Internal Slots ### {#encodedvideochunk-internal-slots}
: <dfn attribute for=EncodedVideoChunk>[[internal data]]</dfn></dt>
:: An array of bytes repsenting the encoded chunk data.

### Constructors ###{#encodedvideochunk-constructors}
<dfn constructor for=EncodedVideoChunk title="EncodedVideoChunk(init)">
EncodedVideoChunk(init)
</dfn>
1. Let |chunk| be a new {{EncodedVideoChunk}} object, initialized as follows
1. Assign `init.type` to `chunk.type`.
2. Assign `init.timestamp` to `chunk.timestamp`.
1. Assign `init.type` to {{EncodedVideoChunk/type}}.
2. Assign `init.timestamp` to {{EncodedVideoChunk/timestamp}}.
3. If duration is present in init, assign `init.duration` to
`chunk.duration`. Otherwise, assign null to `chunk.duration`.
2. Assign a copy of `init.data` to `chunk.data`.
{{EncodedVideoChunk/duration}}. Otherwise, assign `null` to
{{EncodedVideoChunk/duration}}.
4. Assign a copy of `init.data` to {{EncodedVideoChunk/[[internal data]]}}.
5. Assign `init.data.byteLength` to {{EncodedVideoChunk/byteLength}};
3. Return |chunk|.

### Attributes ###{#encodedvideochunk-attributes}
<dl>
<dt><dfn attribute for=EncodedVideoChunk>type</dfn></dt>
<dd>Describes whether the chunk is a key frame or not.</dd>
: <dfn attribute for=EncodedVideoChunk>type</dfn>
:: Describes whether the chunk is a key frame or not.

<dt><dfn attribute for=EncodedVideoChunk>timestamp</dfn></dt>
<dd>The presentation timestamp, given in microseconds.</dd>
: <dfn attribute for=EncodedVideoChunk>timestamp</dfn>
:: The presentation timestamp, given in microseconds.

<dt><dfn attribute for=EncodedVideoChunk>duration</dfn></dt>
<dd>The presentation duration, given in microseconds.</dd>
: <dfn attribute for=EncodedVideoChunk>duration</dfn>
:: The presentation duration, given in microseconds.

<dt><dfn attribute for=EncodedVideoChunk>data</dfn></dt>
<dd>A sequence of bytes containing encoded video data.</dd>
</dl>
: <dfn attribute for=EncodedVideoChunk>byteLength</dfn>
:: The byte length of {{EncodedVideoChunk/[[internal data]]}}.

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

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

ISSUE: EncodedVideoChunk and EncodedAudioChunk currently expose a mutable
data. See <a href="https://github.com/w3c/webcodecs/issues/80">#80</a>.

Privacy Considerations{#privacy-considerations}
===============================================
The primary privacy impact is an increased ability to fingerprint users by
Expand Down

0 comments on commit 5b1fb6e

Please sign in to comment.