Skip to content

Commit

Permalink
webcodecs: Buffer transfer symantics in contructors (mdn#31796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Djuffin authored Jan 20, 2024
1 parent 31041de commit 39cb1e7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions files/en-us/web/api/audiodata/audiodata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ new AudioData(init)
- : An integer indicating the data's time in microseconds .
- `data`
- : A typed array of the audio data for this sample.
- `transfer`
- : An array of {{jsxref("ArrayBuffer")}}s that `AudioData` will detach and take ownership of. If the array contains the {{jsxref("ArrayBuffer")}} backing `data`, `AudioData` will use that buffer directly instead of copying from it.

## Exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ new EncodedAudioChunk(options)
- : An integer representing the length of the audio in microseconds.
- `data`
- : An {{jsxref("ArrayBuffer")}}, a {{jsxref("TypedArray")}}, or a {{jsxref("DataView")}} containing the audio data.
- `transfer`
- : An array of {{jsxref("ArrayBuffer")}}s that `EncodedAudioChunk` will detach and take ownership of. If the array contains the {{jsxref("ArrayBuffer")}} backing `data`, `EncodedAudioChunk` will use that buffer directly instead of copying from it.

## Examples

Expand All @@ -45,6 +47,7 @@ const init = {
data: audioBuffer,
timestamp: 23000000,
duration: 2000000,
transfer: [audioBuffer],
};
chunk = new EncodedAudioChunk(init);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ new EncodedVideoChunk(options)
- : An integer representing the length of the video in microseconds.
- `data`
- : An {{jsxref("ArrayBuffer")}}, a {{jsxref("TypedArray")}}, or a {{jsxref("DataView")}} containing the video data.
- `transfer`
- : An array of {{jsxref("ArrayBuffer")}}s that `EncodedVideoChunk` will detach and take ownership of. If the array contains the {{jsxref("ArrayBuffer")}} backing `data`, `EncodedVideoChunk` will use that buffer directly instead of copying from it.

## Examples

Expand All @@ -43,6 +45,7 @@ const init = {
data: videoBuffer,
timestamp: 23000000,
duration: 2000000,
transfer: [videoBuffer],
};
chunk = new EncodedVideoChunk(init);
```
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/imagedecoder/imagedecoder/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ new ImageDecoder(init)
- : An integer indicating the desired height for the decoded output. Has no effect unless the image codec supports variable resolution decoding.
- `preferAnimation` {{optional_inline}}
- : A {{jsxref("Boolean")}} indicating whether the initial track selection should prefer an animated track.
- `transfer`
- : An array of {{jsxref("ArrayBuffer")}}s that `ImageDecoder` will detach and take ownership of. If the array contains the {{jsxref("ArrayBuffer")}} backing `data`, `ImageDecoder` will use that buffer directly instead of copying from it.

## Examples

Expand Down
7 changes: 5 additions & 2 deletions files/en-us/web/api/videoframe/videoframe/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The first type of constructor (see above) creates a new {{domxref("VideoFrame")}
The second type of constructor (see above) creates a new {{domxref("VideoFrame")}} from an {{jsxref("ArrayBuffer")}}. Its parameters are:

- `data`
- : An {{jsxref("ArrayBuffer")}} containing the data for the new `VideoFrame`.
- : An {{jsxref("ArrayBuffer")}}, a {{jsxref("TypedArray")}}, or a {{jsxref("DataView")}} containing the data for the new `VideoFrame`.
- `options`
- : An object containing the following:
- `format`
Expand Down Expand Up @@ -111,6 +111,8 @@ The second type of constructor (see above) creates a new {{domxref("VideoFrame")
- : A string representing the video color matrix, described on the page for the {{domxref("VideoColorSpace.matrix")}} property.
- `fullRange`
- : A Boolean. If `true`, indicates that full-range color values are used.
- `transfer`
- : An array of {{jsxref("ArrayBuffer")}}s that `VideoFrame` will detach and take ownership of. If the array contains the {{jsxref("ArrayBuffer")}} backing `data`, `VideoFrame` will use that buffer directly instead of copying from it.

## Examples

Expand All @@ -127,7 +129,7 @@ In the following example a `VideoFrame` is created from a {{jsxref("TypedArray")

```js
const pixelSize = 4;
const init = {
let init = {
timestamp: 0,
codedWidth: 320,
codedHeight: 200,
Expand All @@ -143,6 +145,7 @@ for (let x = 0; x < init.codedWidth; x++) {
data[offset + 3] = 0x0ff; // Alpha
}
}
init.transfer = [data.buffer];
let frame = new VideoFrame(data, init);
```

Expand Down

0 comments on commit 39cb1e7

Please sign in to comment.