You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: streams-for-raw-video-explainer.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The proposed solution is to transfer ownership of a chunk to the stream when it
21
21
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.
22
22
Conversely, processing units take ownership of chunks when they receive them from a stream.
23
23
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.
25
25
26
26
## Example
27
27
@@ -37,7 +37,7 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
37
37
transform:async (videoFrame, controller) => {
38
38
try {
39
39
// videoFrame is under the responsibility of the script and must be closed when no longer needed.
@@ -63,7 +63,7 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
63
63
64
64
* Permit `ReadableStream`, `WritableStream` and `TransformStream` objects to take ownership of chunks they manipulate.
65
65
* 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'.
67
67
* Permit to optimize streams pipelines of transferable chunks like `ArrayBuffer`, `RTCEncodedVideoFrame` or `RTCEncodedAudioFrame`.
68
68
* Permit to tee a `ReadableStream` of `VideoFrame` objects without tight coupling between the teed branches.
69
69
@@ -86,21 +86,21 @@ function doBackgroundBlurOnVideoFrames(videoFrameStream, doLogging)
86
86
## Principles
87
87
88
88
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.
91
91
* Streams of the 'transfer' type can only manipulate chunks that are marked both as Transferable and Serializable.
92
92
* 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`
94
94
or `WritableStreamDefaultWriter`, create a transferred version of the chunk using StructuredSerializeWithTransfer/StructuredDeserializeWithTransfer.
95
95
Proceed with the regular stream algorithm by using the transferred chunk instead of the chunk itself.
96
96
* Introduce a WhatWG streams 'close-able' concept. A chunk that is 'close-able' defines closing steps.
97
97
For instance `VideoFrame` closing steps could be defined using https://www.w3.org/TR/webcodecs/#close-videoframe.
98
98
`ArrayBuffer` closing steps could be defined using https://tc39.es/ecma262/#sec-detacharraybuffer.
99
99
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`
101
101
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.
104
104
When the 'realtime' parameter is used, chunks will be dropped on the branch that consumes more slowly to keep buffering limited to one chunk.
105
105
The closing steps should be called for any chunk that gets dropped in that situation.
0 commit comments