Skip to content

Commit 875da35

Browse files
Merge branch 'main' into idl-types
2 parents 219dc98 + d5ef0b0 commit 875da35

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

index.bs

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ As [=writeEncodedData=] ensures that the transform cannot reorder frames, this w
140140

141141
A RTCRtpTransform has two private slots called `[[readable]]` and `[[writable]]`.
142142

143+
Each RTCRtpTransform has an <dfn>association steps</dfn> set, which is empty by default.
144+
143145
The <dfn attribute for="RTCRtpSender,RTCRtpReceiver">transform</dfn> getter steps are:
144146
1. Return [=this=].`[[transform]]`.
145147

@@ -155,6 +157,7 @@ The `transform` setter steps are:
155157
7. Else, run the [=chain transform algorithm=] steps.
156158
8. Set [=this=].`[[pipeToController]]` to |newPipeToController|.
157159
9. Set [=this=].`[[transform]]` to |transform|.
160+
10. Run the steps in the set of [=association steps=] of |transform| with [=this=].
158161

159162
The <dfn>chain transform algorithm</dfn> steps are defined as:
160163
1. If |newPipeToController| is [=AbortSignal/aborted=], abort these steps.
@@ -290,27 +293,29 @@ dictionary RTCEncodedVideoFrameMetadata {
290293
unsigned long spatialIndex;
291294
unsigned long temporalIndex;
292295
unsigned long synchronizationSource;
293-
sequence&lt;unsigned long&gt; contributingSources;
296+
octet payloadType;
297+
sequence&lt;unsigned long&gt; contributingSources;
294298
};
295299

296300
// New interfaces to define encoded video and audio frames. Will eventually
297301
// re-use or extend the equivalent defined in WebCodecs.
298302
[Exposed=(Window,DedicatedWorker)]
299303
interface RTCEncodedVideoFrame {
300304
readonly attribute RTCEncodedVideoFrameType type;
301-
readonly attribute unsigned long long timestamp;
305+
readonly attribute unsigned long timestamp; // RTP timestamp.
302306
attribute ArrayBuffer data;
303307
RTCEncodedVideoFrameMetadata getMetadata();
304308
};
305309

306310
dictionary RTCEncodedAudioFrameMetadata {
307311
unsigned long synchronizationSource;
312+
octet payloadType;
308313
sequence&lt;unsigned long&gt; contributingSources;
309314
};
310315

311316
[Exposed=(Window,DedicatedWorker)]
312317
interface RTCEncodedAudioFrame {
313-
readonly attribute unsigned long long timestamp;
318+
readonly attribute unsigned long timestamp; // RTP timestamp.
314319
attribute ArrayBuffer data;
315320
RTCEncodedAudioFrameMetadata getMetadata();
316321
};
@@ -332,6 +337,8 @@ interface RTCRtpScriptTransformer {
332337
readonly attribute ReadableStream readable;
333338
readonly attribute WritableStream writable;
334339
readonly attribute any options;
340+
Promise&lt;unsigned long long&gt; generateKeyFrame(optional DOMString rid);
341+
Promise&lt;undefined&gt; sendKeyFrameRequest();
335342
};
336343

337344
[Exposed=Window]
@@ -365,9 +372,30 @@ The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worke
365372

366373
// FIXME: Describe error handling (worker closing flag true at RTCRtpScriptTransform creation time. And worker being terminated while transform is processing data).
367374

375+
Each RTCRtpScriptTransform has the following set of [=association steps=], given |rtcObject|:
376+
1. Let |transform| be the {{RTCRtpScriptTransform}} object that owns the [=association steps=].
377+
1. Let |encoder| be |rtcObject|'s encoder if |rtcObject| is a {{RTCRtpSender}} or undefined otherwise.
378+
1. Let |depacketizer| be |rtcObject|'s depacketizer if |rtcObject| is a {{RTCRtpReceiver}} or undefined otherwise.
379+
1. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
380+
1. Let |transformer| be the {{RTCRtpScriptTransformer}} object associated to |transform|.
381+
1. Set |transformer|.`[[encoder]]` to |encoder|.
382+
1. Set |transformer|.`[[depacketizer]]` to |depacketizer|.
383+
384+
The <dfn method for="RTCRtpScriptTransformer">generateKeyFrame(|rid|)</dfn> method steps are:
385+
1. Let |promise| be a new promise.
386+
1. Run the [=generate key frame algorithm=] with |promise|, |this|.`[[encoder]]` and |rid|.
387+
1. Return |promise|.
388+
389+
The <dfn method for="RTCRtpScriptTransformer">sendKeyFrameRequest()</dfn> method steps are:
390+
1. Let |promise| be a new promise.
391+
1. Run the [=send request key frame algorithm=] with |promise| and |this|.`[[depacketizer]]`.
392+
1. Return |promise|.
393+
368394
## Attributes ## {#RTCRtpScriptTransformer-attributes}
369395

370-
A RTCRtpScriptTransformer has three private slots called `[[options]]`, `[[readable]]` and `[[writable]]`.
396+
A {{RTCRtpScriptTransformer}} has the following private slots called `[[depacketizer]]`, `[[encoder]]`, `[[options]]`, `[[readable]]` and `[[writable]]`.
397+
In addition, a {{RTCRtpScriptTransformer}} is always associated with its parent {{RTCRtpScriptTransform}} transform.
398+
This allows algorithms to go from an {{RTCRtpScriptTransformer}} object to its {{RTCRtpScriptTransform}} parent and vice versa.
371399

372400
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
373401
1. Return [=this=].`[[options]]`.
@@ -378,6 +406,66 @@ The <dfn attribute for="RTCRtpScriptTransformer">readable</dfn> getter steps are
378406
The <dfn attribute for="RTCRtpScriptTransformer">writable</dfn> getter steps are:
379407
1. Return [=this=].`[[writable]]`.
380408

409+
## KeyFrame Algorithms ## {#KeyFrame-algorithms}
410+
411+
The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
412+
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
413+
1. If |encoder| is not processing video frames, reject |promise| with {{InvalidStateError}}, abort these steps.
414+
1. If |rid| is defined, validate its value. If invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
415+
1. [=In parallel=], run the following steps:
416+
1. Gather a list of video encoders, named |videoEncoders| from |encoder|, ordered according negotiated RIDs if any.
417+
1. If |rid| is defined, remove from |videoEncoders| any video encoder that does not match |rid|.
418+
1. If |rid| is undefined, remove from |videoEncoders| all video encoders except the first one.
419+
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
420+
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
421+
1. Let |videoEncoder| be the first encoder in |videoEncoders|.
422+
1. If |rid| is undefined, set |rid| to the RID value corresponding to |videoEncoder|.
423+
1. Create a pending key frame task called |task| with |task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|.
424+
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
425+
1. Let |shouldTriggerKeyFrame| be <code>true</code> if |encoder|.`[[pendingKeyFrameTasks]]` contains a task whose `[[rid]]`
426+
value is equal to |rid|, and <code>false</code> otherwise.
427+
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
428+
1. If |shouldTriggerKeyFrame| is <code>true</code>, instruct |videoEncoder| to generate a key frame for the next provided video frame.
429+
430+
For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`:
431+
1. Let |encoder| be |transformer|.`[[encoder]]`.
432+
1. If |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps.
433+
1. If |frame| is not a video key frame, abort these steps.
434+
1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps:
435+
1. If |frame| was generated by a video encoder identified by |task|.`[[rid]]`, run the following steps:
436+
1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
437+
1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.
438+
439+
By resolving the promises just before enqueuing the corresponding key frame in a {{RTCRtpScriptTransformer}}'s readable,
440+
the resolution callbacks of the promises are always executed just before the corresponding key frame is exposed.
441+
If the promise is associated to several rid values, it will be resolved when the first key frame corresponding to one the rid value is enqueued.
442+
443+
The <dfn>send request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
444+
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
445+
1. If |depacketizer| is not processing video packets, reject |promise| with {{InvalidStateError}}, abort these steps.
446+
1. [=In parallel=], run the following steps:
447+
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.
448+
Section 4.3.1 of [[RFC5104]] provides guidelines of how and when it is appropriate to sending a Full Intra Request.
449+
1. Generate a Full Intra Request (FIR) packet as defined in section 4.3.1 of [[RFC5104]] and send it through |depacketizer|'s receiver.
450+
1. [=Resolve=] |promise| with undefined.
451+
452+
# RTCRtpSender extension # {#rtcrtpsender-extension}
453+
454+
An additional API on {{RTCRtpSender}} is added to complement the generation of key frame added to {{RTCRtpScriptTransformer}}.
455+
456+
<pre class="idl">
457+
partial interface RTCRtpSender {
458+
Promise&lt;undefined&gt; generateKeyFrame(optional sequence &lt;DOMString&gt; rids);
459+
};
460+
</pre>
461+
462+
## Extension operation ## {#sender-operation}
463+
464+
The <dfn method for="RTCRtpSender">generateKeyFrame(|rids|)</dfn> method steps are:
465+
466+
1. Let |promise| be a new promise.
467+
1. [=In parallel=], run the [=generate key frame algorithm=] with |promise|, |this|'s encoder and |rids|.
468+
1. Return |promise|.
381469

382470
# Privacy and security considerations # {#privacy}
383471

0 commit comments

Comments
 (0)