Skip to content

Commit 5e54a2d

Browse files
authored
Merge pull request #132 from youennf/generateKeyFrameAsSingleRid
Make generateKeyFrame take a single RID or none. Resolve the promise with the frame timestamp
2 parents da20661 + d33d388 commit 5e54a2d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

index.bs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ interface RTCRtpScriptTransformer {
337337
readonly attribute ReadableStream readable;
338338
readonly attribute WritableStream writable;
339339
readonly attribute any options;
340-
Promise<undefined> generateKeyFrame(optional sequence <DOMString> rids);
340+
Promise<unsigned long long> generateKeyFrame(optional DOMString rid);
341341
Promise<undefined> sendKeyFrameRequest();
342342
};
343343

@@ -381,9 +381,9 @@ Each RTCRtpScriptTransform has the following set of [=association steps=], given
381381
1. Set |transformer|.`[[encoder]]` to |encoder|.
382382
1. Set |transformer|.`[[depacketizer]]` to |depacketizer|.
383383

384-
The <dfn method for="RTCRtpScriptTransformer">generateKeyFrame(|rids|)</dfn> method steps are:
384+
The <dfn method for="RTCRtpScriptTransformer">generateKeyFrame(|rid|)</dfn> method steps are:
385385
1. Let |promise| be a new promise.
386-
1. Run the [=generate key frame algorithm=] with |promise|, |this|.`[[encoder]]` and |rids|.
386+
1. Run the [=generate key frame algorithm=] with |promise|, |this|.`[[encoder]]` and |rid|.
387387
1. Return |promise|.
388388

389389
The <dfn method for="RTCRtpScriptTransformer">sendKeyFrameRequest()</dfn> method steps are:
@@ -408,23 +408,24 @@ The <dfn attribute for="RTCRtpScriptTransformer">writable</dfn> getter steps are
408408

409409
## KeyFrame Algorithms ## {#KeyFrame-algorithms}
410410

411-
The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rids|, is defined by running these steps:
411+
The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
412412
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
413413
1. If |encoder| is not processing video frames, reject |promise| with {{InvalidStateError}}, abort these steps.
414-
1. If |rids| is defined, validate each of the RID values in |rids|.
415-
If any RID value is invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
414+
1. If |rid| is defined, validate its value. If invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
416415
1. [=In parallel=], run the following steps:
417-
1. Gather a list of video encoders, named |videoEncoders| from |encoder|.
418-
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
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.
419419
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
420420
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
421-
1. For each |rid| in |rids|, run the following substeps:
422-
1. Create a pending key frame task called |task| with ||task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|.
423-
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
424-
1. If |encoder|.`[[pendingKeyFrameTasks]]` contains a task which is matching |rid|, remove |rid| from |rids|.
425-
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
426-
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
427-
1. For each |videoEncoder| in |videoEncoders|, instruct |videoEncoder| to generate a key frame for the next provided video frame.
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.
428429

429430
For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`:
430431
1. Let |encoder| be |transformer|.`[[encoder]]`.
@@ -433,7 +434,7 @@ For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are
433434
1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps:
434435
1. If |frame| was generated by a video encoder identified by |task|.`[[rid]]`, run the following steps:
435436
1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
436-
1. Resolve |task|.`[[promise]]` with undefined.
437+
1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.
437438

438439
By resolving the promises just before enqueuing the corresponding key frame in a {{RTCRtpScriptTransformer}}'s readable,
439440
the resolution callbacks of the promises are always executed just before the corresponding key frame is exposed.

0 commit comments

Comments
 (0)