Skip to content

Commit cf7670a

Browse files
authored
Update raw video explainer according proposed spec PR
The "transfer" stream type has been renamed to "owning". Change streams-for-raw-video-explainer.md to match.
1 parent 1222f88 commit cf7670a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

streams-for-raw-video-explainer.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The proposed solution is to transfer ownership of a chunk to the stream when it
2121
By doing so, the processing unit that enqueues/writes chunks will not be able to mutate chunks manipulated by the stream and is relieved of the lifetime management of these chunks.
2222
Conversely, processing units take ownership of chunks when they receive them from a stream.
2323

24-
Transferring ownership should be opt-in. For that purpose, a new streams type, named 'transfer' in this document, would be added.
24+
Transferring ownership should be opt-in. For that purpose, a new streams type, named 'owning' in this document, would be added.
2525

2626
## Example
2727

@@ -37,7 +37,7 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
3737
transform: async (videoFrame, controller) => {
3838
try {
3939
// videoFrame is under the responsibility of the script and must be closed when no longer needed.
40-
controller.enqueue(videoFrame);
40+
controller.enqueue(videoFrame, { transfer: [videoFrame] });
4141
// controller.enqueue was called, videoFrame is transferred.
4242
if (!(++frameCount % 30) && doLogging)
4343
doLogging(frameCount);
@@ -48,10 +48,10 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
4848
controller.error(e);
4949
}
5050
},
51-
readableType: 'transfer',
52-
writableType: 'transfer'
51+
readableType: 'owning',
52+
writableType: 'owning'
5353
});
54-
// Native transform is of type 'transfer'
54+
// Native transform is of type 'owning'
5555
const backgroundBlurTransform = new BackgroundBlurTransform();
5656

5757
return videoFrameStream.pipeThrough(backgroundBlurTransform)
@@ -63,7 +63,7 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
6363

6464
* Permit `ReadableStream`, `WritableStream` and `TransformStream` objects to take ownership of chunks they manipulate.
6565
* Permit to build a safe and optimal video pipeline using `ReadableStream`, `WritableStream` and `TransformStream` objects that manipulate `VideoFrame` objects.
66-
* Permit both native and JavaScript-based streams of type 'transfer'.
66+
* Permit both native and JavaScript-based streams of type 'owning'.
6767
* Permit to optimize streams pipelines of transferable chunks like `ArrayBuffer`, `RTCEncodedVideoFrame` or `RTCEncodedAudioFrame`.
6868
* Permit to tee a `ReadableStream` of `VideoFrame` objects without tight coupling between the teed branches.
6969

@@ -86,21 +86,21 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
8686
## Principles
8787

8888
The envisioned changes to the streams specification could look like the following:
89-
* Add a new 'transfer' value that can be passed to `ReadableStream` type, `WritableStream` type and `TransformStream` readableType/writableType.
90-
For streams that do not use the 'transfer' type, nothing changes.
89+
* Add a new 'owning' value that can be passed to `ReadableStream` type, `WritableStream` type and `TransformStream` readableType/writableType.
90+
For streams that do not use the 'owning' type, nothing changes.
9191
* Streams of the 'transfer' type can only manipulate chunks that are marked both as Transferable and Serializable.
9292
* If a chunk that is either not Transferable or not Serializable is enqueued or written, the chunk is ignored as if it was never enqueued/written.
93-
* If a Transferable and Serializable chunk is enqueueud/written in a 'transfer' type `ReadableStreamDefaultController`, `TransformStreamDefaultController`
93+
* If a Transferable and Serializable chunk is enqueueud/written in a 'owning' type `ReadableStreamDefaultController`, `TransformStreamDefaultController`
9494
or `WritableStreamDefaultWriter`, create a transferred version of the chunk using StructuredSerializeWithTransfer/StructuredDeserializeWithTransfer.
9595
Proceed with the regular stream algorithm by using the transferred chunk instead of the chunk itself.
9696
* Introduce a WhatWG streams 'close-able' concept. A chunk that is 'close-able' defines closing steps.
9797
For instance `VideoFrame` closing steps could be defined using https://www.w3.org/TR/webcodecs/#close-videoframe.
9898
`ArrayBuffer` closing steps could be defined using https://tc39.es/ecma262/#sec-detacharraybuffer.
9999
The 'close-able' steps should be a no-op on a transferred chunk.
100-
* Execute the closing steps of a 'close-able' chunk for streams with the 'transfer' type when resetting the queue of `ReadableStreamDefaultController`
100+
* Execute the closing steps of a 'close-able' chunk for streams with the 'owning' type when resetting the queue of `ReadableStreamDefaultController`
101101
or emptying `WritableStream`.[[writeRequests]] in case of abort/error.
102-
* When calling tee() on a `ReadableStream` of the 'transfer' type, call ReadableStream with cloneForBranch2 equal to true.
103-
* To solve https://github.com/whatwg/streams/issues/1186, tee() on a `ReadableStream` of the 'transfer' type can take a 'realtime' parameter.
102+
* When calling tee() on a `ReadableStream` of the 'owning' type, call ReadableStream with cloneForBranch2 equal to true.
103+
* To solve https://github.com/whatwg/streams/issues/1186, tee() on a `ReadableStream` of the 'owning' type can take a 'realtime' parameter.
104104
When the 'realtime' parameter is used, chunks will be dropped on the branch that consumes more slowly to keep buffering limited to one chunk.
105105
The closing steps should be called for any chunk that gets dropped in that situation.
106106

0 commit comments

Comments
 (0)