Skip to content

Commit 84e6ef0

Browse files
authored
Merge pull request #62 from youennf/rtcrtpscripttransform-worker-api
Add API and algorithm to expose transform to workers
2 parents d721a4c + 146a751 commit 84e6ef0

File tree

1 file changed

+99
-55
lines changed

1 file changed

+99
-55
lines changed

index.bs

Lines changed: 99 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -63,54 +63,6 @@ an additional API on {{RTCRtpSender}} and {{RTCRtpReceiver}} to
6363
insert the processing into the pipeline.
6464

6565
<pre class="idl">
66-
// New dictionary.
67-
dictionary RTCInsertableStreams {
68-
ReadableStream readable;
69-
WritableStream writable;
70-
};
71-
72-
// New enum for video frame types. Will eventually re-use the equivalent defined
73-
// by WebCodecs.
74-
enum RTCEncodedVideoFrameType {
75-
"empty",
76-
"key",
77-
"delta",
78-
};
79-
80-
dictionary RTCEncodedVideoFrameMetadata {
81-
long long frameId;
82-
sequence&lt;long long&gt; dependencies;
83-
unsigned short width;
84-
unsigned short height;
85-
long spatialIndex;
86-
long temporalIndex;
87-
long synchronizationSource;
88-
sequence&lt;long&gt; contributingSources;
89-
};
90-
91-
// New interfaces to define encoded video and audio frames. Will eventually
92-
// re-use or extend the equivalent defined in WebCodecs.
93-
[Exposed=Window]
94-
interface RTCEncodedVideoFrame {
95-
readonly attribute RTCEncodedVideoFrameType type;
96-
readonly attribute unsigned long long timestamp;
97-
attribute ArrayBuffer data;
98-
RTCEncodedVideoFrameMetadata getMetadata();
99-
};
100-
101-
dictionary RTCEncodedAudioFrameMetadata {
102-
long synchronizationSource;
103-
sequence&lt;long&gt; contributingSources;
104-
};
105-
106-
[Exposed=Window]
107-
interface RTCEncodedAudioFrame {
108-
readonly attribute unsigned long long timestamp;
109-
attribute ArrayBuffer data;
110-
RTCEncodedAudioFrameMetadata getMetadata();
111-
};
112-
113-
11466
// New fields in RTCConfiguration
11567
partial dictionary RTCConfiguration {
11668
boolean encodedInsertableStreams = false;
@@ -142,13 +94,13 @@ argument, ensure that the codec is disabled and produces no output.
14294
At construction of each {{RTCRtpSender}} or {{RTCRtpReceiver}}, run the following steps:
14395
1. Initialize [=this=].`[[Streams]]` to null.
14496
2. Initialize [=this=].`[[transform]]` to null.
145-
3. Initialize [=this=].`[[readable]]` to the result of <a dfn for="ReadableStream">creating</a> a {{ReadableStream}}. `[[readable]]` is provided frames using the [=readEncodedData=] algorithm given |this| as parameter.
97+
3. Initialize [=this=].`[[readable]]` to the result of <a dfn for="ReadableStream">creating</a> a {{ReadableStream}}. [=this=].`[[readable]]` is provided frames using the [=readEncodedData=] algorithm given |this| as parameter.
14698
4. Set [=this=].`[[readable]]`.`[[owner]]` to |this|.
14799
5. Initialize [=this=].`[[writable]]` to the result of [=WritableStream/creating=] a {{WritableStream}}, its [=WritableStream/create/writeAlgorithm=] set to [=writeEncodedData=] given |this| as parameter.
148100
6. Set [=this=].`[[writable]]`.`[[owner]]` to |this|.
149101
7. Initialize [=this=].`[[pipeToController]]` to null.
150102
8. Initialize [=this=].`[[lastReceivedFrameTimestamp]]` to zero.
151-
9. If the {{RTCPeerConnection}}'s configuration does not have {{RTCConfiguration/encodedInsertableStreams}} set to "true", queue a task to run the following steps:
103+
9. If the {{RTCPeerConnection}}'s configuration does not have {{RTCConfiguration/encodedInsertableStreams}} set to "true", [=queue a task=] to run the following steps:
152104
1. If [=this=].`[[pipeToController]]` is not null, abort these steps.
153105
2. Set [=this=].`[[pipeToController]]` to a new {{AbortController}}.
154106
<!-- FIXME: Use pipeTo algorithm when available. -->
@@ -172,7 +124,7 @@ The <dfn>readEncodedData</dfn> algorithm is given a |rtcObject| as parameter. It
172124
1. Wait for a frame to be produced by |rtcObject|'s encoder if it is a {{RTCRtpSender}} or |rtcObject|'s packetizer if it is a {{RTCRtpReceiver}}.
173125
2. Let |frame| be the newly produced frame.
174126
3. Set |frame|.`[[owner]]` to |rtcObject|.
175-
4. [=ReadableStream/enqueue=] |frame| in |rtcObject|.`[[readable]]`.
127+
4. [=ReadableStream/Enqueue=] |frame| in |rtcObject|.`[[readable]]`.
176128

177129
The <dfn>writeEncodedData</dfn> algorithm is given a |rtcObject| as parameter and a |frame| as input. It is defined by running the following steps:
178130
1. If |frame|.`[[owner]]` is not equal to |rtcObject|, abort these steps and return [=a promise resolved with=] undefined. A processor cannot create frames, or move frames between streams.
@@ -246,7 +198,7 @@ The <dfn constructor for="SFrameTransform" lt="SFrameTransform(options)"><code>n
246198
5. Set |this|.`[[readable]]` to |this|.`[[transform]]`.`[[readable]]`.
247199
6. Set |this|.`[[writable]]` to |this|.`[[transform]]`.`[[writable]]`.
248200

249-
## SFrame transform algorithm ## {#sframe-transform-algorithm}
201+
## Algorithm ## {#sframe-transform-algorithm}
250202

251203
The SFrame transform algorithm, given |sframe| as a SFrameTransform object and |frame|, runs these steps:
252204
1. Let |role| be |sframe|.`[[role]]`.
@@ -276,20 +228,112 @@ The <dfn method for="SFrameTransform">setEncryptionKey(|key|, |keyID|)</dfn> met
276228
# RTCRtpScriptTransform # {#scriptTransform}
277229

278230
<pre class="idl">
231+
// New enum for video frame types. Will eventually re-use the equivalent defined
232+
// by WebCodecs.
233+
enum RTCEncodedVideoFrameType {
234+
"empty",
235+
"key",
236+
"delta",
237+
};
238+
239+
dictionary RTCEncodedVideoFrameMetadata {
240+
long long frameId;
241+
sequence&lt;long long&gt; dependencies;
242+
unsigned short width;
243+
unsigned short height;
244+
long spatialIndex;
245+
long temporalIndex;
246+
long synchronizationSource;
247+
sequence&lt;long&gt; contributingSources;
248+
};
249+
250+
// New interfaces to define encoded video and audio frames. Will eventually
251+
// re-use or extend the equivalent defined in WebCodecs.
252+
[Exposed=Window]
253+
interface RTCEncodedVideoFrame {
254+
readonly attribute RTCEncodedVideoFrameType type;
255+
readonly attribute unsigned long long timestamp;
256+
attribute ArrayBuffer data;
257+
RTCEncodedVideoFrameMetadata getMetadata();
258+
};
259+
260+
dictionary RTCEncodedAudioFrameMetadata {
261+
long synchronizationSource;
262+
sequence&lt;long&gt; contributingSources;
263+
};
264+
265+
[Exposed=Window]
266+
interface RTCEncodedAudioFrame {
267+
readonly attribute unsigned long long timestamp;
268+
attribute ArrayBuffer data;
269+
RTCEncodedAudioFrameMetadata getMetadata();
270+
};
271+
272+
273+
// New interfaces to expose JavaScript-based transforms.
274+
275+
[Global=(Worker,DedicatedWorker),Exposed=DedicatedWorker]
276+
interface RTCTransformEvent : Event {
277+
readonly attribute RTCRtpScriptTransformer transformer;
278+
};
279+
280+
[Global=(Worker,DedicatedWorker),Exposed=DedicatedWorker]
281+
partial interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
282+
attribute EventHandler onrtctransform;
283+
};
284+
285+
[Global=(Worker,DedicatedWorker),Exposed=DedicatedWorker]
286+
interface RTCRtpScriptTransformer {
287+
readonly attribute ReadableStream readable;
288+
readonly attribute WritableStream writable;
289+
readonly attribute any options;
290+
};
291+
279292
[Exposed=(Window)]
280293
interface RTCRtpScriptTransform {
281-
constructor(Worker worker, optional object options);
294+
constructor(Worker worker, optional any options);
282295
// FIXME: add messaging methods.
283296
};
284297
</pre>
285298

299+
## Operations ## {#RTCRtpScriptTransform-operations}
300+
286301
The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worker, options)"><code>new RTCRtpScriptTransform(<var>worker</var>, <var>options</var>)</code></dfn> constructor steps are:
287302
1. Set |t1| to an [=identity transform stream=].
288303
2. Set |t2| to an [=identity transform stream=].
289304
3. Set |this|.`[[writable]]` to |t1|.`[[writable]]`.
290305
4. Set |this|.`[[readable]]` to |t2|.`[[readable]]`.
291-
5. FIXME: transfer |t1|.`[[readable]]` and |t2|.`[[writable]]` to the dedicated worker.
292-
6. FIXME: Create counterpart of |this| in dedicated worker, for instance expose transfered |t1|.`[[readable]]` and |t2|.`[[writable]]`.
306+
5. Let |serializedOptions| be the result of [$StructuredSerialize$](|object|).
307+
6. Let |serializedReadable| be the result of [$StructuredSerializeWithTransfer$](|t1|.`[[readable]]`, « |t1|.`[[readable]]` »).
308+
7. Let |serializedWritable| be the result of [$StructuredSerializeWithTransfer$](|t2|.`[[writable]]`, « |t2|.`[[writable]]` »).
309+
8. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
310+
1. Let |transformerOptions| be the result of [$StructuredDeserialize$](|serializedOptions|, the current Realm).
311+
2. Let |readable| be the result of [$StructuredDeserialize$](|serializedReadable|, the current Realm).
312+
3. Let |writable| be the result of [$StructuredDeserialize$](|serializedWritable|, the current Realm).
313+
4. Let |transformer| be a new {{RTCRtpScriptTransformer}}.
314+
5. Set |transformer|.`[[options]]` to |transformerOptions|.
315+
6. Set |transformer|.`[[readable]]` to |readable|.
316+
7. Set |transformer|.`[[writable]]` to |writable|.
317+
8. Let |event| be the result of [=creating an event=] with {{RTCTransformEvent}}.
318+
9. Set |event|.type attribute to "rtctransform".
319+
10. Set |event|.transformer to |transformer|.
320+
11. Dispatch |event| on |worker|’s global scope.
321+
322+
// FIXME: Describe error handling (worker closing flag true at RTCRtpScriptTransform creation time. And worker being terminated while transform is processing data).
323+
324+
## Attributes ## {#RTCRtpScriptTransformer-attributes}
325+
326+
A RTCRtpScriptTransformer has three private slots called `[[options]]`, `[[readable]]` and `[[writable]]`.
327+
328+
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
329+
1. Return [=this=].`[[options]]`.
330+
331+
The <dfn attribute for="RTCRtpScriptTransformer">readable</dfn> getter steps are:
332+
1. Return [=this=].`[[readable]]`.
333+
334+
The <dfn attribute for="RTCRtpScriptTransformer">writable</dfn> getter steps are:
335+
1. Return [=this=].`[[writable]]`.
336+
293337

294338
# Privacy and security considerations # {#privacy}
295339

0 commit comments

Comments
 (0)