Skip to content

Commit ad75548

Browse files
committed
Add generateKeyFrame specific promise resolution timing by checking at the first enqueued key frame since generateKeyFrame was called
Also make the possible error checks synchronously instead of within the in parallel steps.
1 parent 2f5b0d8 commit ad75548

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

index.bs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ Each RTCRtpScriptTransform has the following set of [=association steps=], given
381381

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

387387
The <dfn method for="RTCRtpScriptTransformer">sendKeyFrameRequest()</dfn> method steps are:
388388
1. Let |promise| be a new promise.
389-
1. [=In parallel=], run the [=send request key frame algorithm=] with |promise| and |this|.`[[depacketizer]]`.
389+
1. Run the [=send request key frame algorithm=] with |promise| and |this|.`[[depacketizer]]`.
390390
1. Return |promise|.
391391

392392
## Attributes ## {#RTCRtpScriptTransformer-attributes}
@@ -411,21 +411,40 @@ The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid
411411
1. If |encoder| is not processing video frames, reject |promise| with {{InvalidStateError}}, abort these steps.
412412
1. If |rids| is defined, validate each of the RID values in |rids|.
413413
If any RID value is invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
414-
1. Gather a list of video encoders, named |videoEncoders| from |encoder|.
415-
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
416-
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
417-
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
418-
1. For each |videoEncoder| in |videoEncoders|, instruct |videoEncoder| to generate a key frame for the next provided video frame.
419-
1. Wait until a new video frame is provided to each |videoEncoder| in |videoEncoders|.
420-
1. [=Resolve=] |promise| with undefined.
414+
1. [=In parallel=], run the following steps:
415+
1. Gather a list of video encoders, named |videoEncoders| from |encoder|.
416+
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
417+
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
418+
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
419+
1. For each |rid| in |rids|, run the following substeps:
420+
1. Create a pending key frame task called |task| with ||task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|.
421+
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
422+
1. If |encoder|.`[[pendingKeyFrameTasks]]` contains a task which is matching |rid|, remove |rid| from |rids|.
423+
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
424+
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
425+
1. For each |videoEncoder| in |videoEncoders|, instruct |videoEncoder| to generate a key frame for the next provided video frame.
426+
427+
For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`:
428+
1. Let |encoder| be |transformer|.`[[encoder]]`.
429+
1. If |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps.
430+
1. If |frame| is not a video key frame, abort these steps.
431+
1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps:
432+
1. If |frame| was generated by a video encoder identified by |task|.`[[rid]]`, run the following steps:
433+
1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
434+
1. Resolve |task|.`[[promise]]` with undefined.
435+
436+
By resolving the promises just before enqueuing the corresponding key frame in a {{RTCRtpScriptTransformer}}'s readable,
437+
the resolution callbacks of the promises are always executed just before the corresponding key frame is exposed.
438+
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.
421439

422440
The <dfn>send request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
423441
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
424442
1. If |depacketizer| is not processing video packets, reject |promise| with {{InvalidStateError}}, abort these steps.
425-
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.
426-
Section 4.3.1 of [[RFC5104]] provides guidelines of how and when it is appropriate to sending a Full Intra Request.
427-
1. Generate a Full Intra Request (FIR) packet as defined in section 4.3.1 of [[RFC5104]] and send it through |depacketizer|'s receiver.
428-
1. [=Resolve=] |promise| with undefined.
443+
1. [=In parallel=], run the following steps:
444+
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.
445+
Section 4.3.1 of [[RFC5104]] provides guidelines of how and when it is appropriate to sending a Full Intra Request.
446+
1. Generate a Full Intra Request (FIR) packet as defined in section 4.3.1 of [[RFC5104]] and send it through |depacketizer|'s receiver.
447+
1. [=Resolve=] |promise| with undefined.
429448

430449
# RTCRtpSender extension # {#rtcrtpsender-extension}
431450

0 commit comments

Comments
 (0)