Skip to content

Commit 482c9bf

Browse files
committed
Add API to request key frames
1 parent 31f09c9 commit 482c9bf

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

index.bs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ spec:webidl; type:dfn; text:resolve
2525
}
2626
}
2727
</pre>
28+
<pre class=biblio>
29+
{
30+
"RFC-5104": {
31+
"href":
32+
"https://www.rfc-editor.org/rfc/rfc5104",
33+
"title": "RFC-5104"
34+
}
35+
}
36+
</pre>
2837
<pre class=link-defaults>
2938
spec:streams; type:interface; text:ReadableStream
3039
</pre>
@@ -139,6 +148,8 @@ As [=writeEncodedData=] ensures that the transform cannot reorder frames, this w
139148

140149
A RTCRtpTransform has two private slots called `[[readable]]` and `[[writable]]`.
141150

151+
Each RTCRtpTransform has an <dfn>association steps</dfn> set, which is empty by default.
152+
142153
The <dfn attribute for="RTCRtpSender,RTCRtpReceiver">transform</dfn> getter steps are:
143154
1. Return [=this=].`[[transform]]`.
144155

@@ -154,6 +165,7 @@ The `transform` setter steps are:
154165
7. Else, run the [=chain transform algorithm=] steps.
155166
8. Set [=this=].`[[pipeToController]]` to |newPipeToController|.
156167
9. Set [=this=].`[[transform]]` to |transform|.
168+
10. Run the steps in the set of [=association steps=] of |transform| with [=this=].
157169

158170
The <dfn>chain transform algorithm</dfn> steps are defined as:
159171
1. If |newPipeToController| is [=AbortSignal/aborted=], abort these steps.
@@ -331,6 +343,8 @@ interface RTCRtpScriptTransformer {
331343
readonly attribute ReadableStream readable;
332344
readonly attribute WritableStream writable;
333345
readonly attribute any options;
346+
Promise&lt;undefined&gt; generateKeyFrame(optional sequence &lt;DOMString&gt; rids);
347+
Promise&lt;undefined&gt; requestKeyFrame();
334348
};
335349

336350
[Exposed=Window]
@@ -364,9 +378,30 @@ The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worke
364378

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

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

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

371406
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
372407
1. Return [=this=].`[[options]]`.
@@ -377,6 +412,44 @@ The <dfn attribute for="RTCRtpScriptTransformer">readable</dfn> getter steps are
377412
The <dfn attribute for="RTCRtpScriptTransformer">writable</dfn> getter steps are:
378413
1. Return [=this=].`[[writable]]`.
379414

415+
## KeyFrame Algorithms ## {#KeyFrame-algorithms}
416+
417+
The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rids|, is defined by running these steps:
418+
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
419+
1. If |rids| is defined, validate each of the RID values in |rids|.
420+
If any RID value is invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
421+
1. Gather a list of video encoders, named |videoEncoders| from |encoder|.
422+
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
423+
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
424+
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
425+
1. For each |videoEncoder| in |videoEncoders|, instruct |videoEncoder| to generate a key frame for the next provided video frame.
426+
1. Wait until a new video frame is provided to each |videoEncoder| in |videoEncoders|.
427+
1. [=Resolve=] |promise| with undefined.
428+
429+
The <dfn>request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
430+
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
431+
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.
432+
Section 4.3.1 of [[RFC-5104]] provides guidelines of how and when it is appropriate to sending a Full Intra Request.
433+
1. Generate a Full Intra Request (FIR) packet as defined in section 4.3.1 of [[RFC-5104]] and send it through |depacketizer|'s receiver.
434+
1. [=Resolve=] |promise| with undefined.
435+
436+
# RTCRtpSender extension # {#rtcrtpsender-extension}
437+
438+
An additional API on {{RTCRtpSender}} is added to complement the generation of key frame added to {{RTCRtpScriptTransformer}}.
439+
440+
<pre class="idl">
441+
partial interface RTCRtpSender {
442+
Promise&lt;undefined&gt; generateKeyFrame(optional sequence &lt;DOMString&gt; rids);
443+
};
444+
</pre>
445+
446+
## Extension operation ## {#sender-operation}
447+
448+
The <dfn method for="RTCRtpSender">generateKeyFrame(|rids|)</dfn> method steps are:
449+
450+
1. Let |promise| be a new promise.
451+
1. [=In parallel=], run the [=generate key frame algorithm=] with |promise|, |this|'s encoder and |rids|.
452+
1. Return |promise|.
380453

381454
# Privacy and security considerations # {#privacy}
382455

0 commit comments

Comments
 (0)