diff --git a/index.bs b/index.bs index 80eaae5..e30ba38 100644 --- a/index.bs +++ b/index.bs @@ -1003,26 +1003,39 @@ The generate key frame algorithm, given |promise|, |encod in Section 10 of [[!RFC8851]], then reject |promise| with {{TypeError}} and abort these steps. 1. [=In parallel=], run the following steps: - 1. Gather a list of video encoders, named |videoEncoders| from |encoder|, ordered according negotiated RIDs if any. - 1. If |rid| is defined, remove from |videoEncoders| any video encoder that does not match |rid|. - 1. If |rid| is undefined, remove from |videoEncoders| all video encoders except the first one. + 1. Let |videoEncoders| be a list of video encoders from |encoder|, ordered according to their negotiated RIDs if any. + 1. Let |allRids| be the list of rids from |videoEncoders|, using `null` in place of any missing rids. + 1. Assert that |allRids| either [=list/contains=] no `null` values or a single entry that is `null`. + + Note: This algorithm internally uses `null` to identify the single video encoder in unicast. + + 1. If |rid| is not undefined, remove from |videoEncoders| any video encoder that does not match |rid|. + + Note: If no |rid| is passed in, keyframes are generated for all layers. + 1. If |videoEncoders| is empty, [=queue a task=] to reject |promise| with {{NotFoundError}} and abort these steps. - |videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended. - 1. Let |videoEncoder| be the first encoder in |videoEncoders|. - 1. If |rid| is undefined, set |rid| to the RID value corresponding to |videoEncoder|. - 1. Create a pending key frame task called |task| with |task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|. + + Note: |videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} encoding is not + {{RTCRtpEncodingParameters/active}}, or the corresponding {{RTCRtpSender}} track is ended. + + 1. Let |rids| be [|rid|] if |rid| is not undefined, or |allRids| otherwise. + 1. Create a pending key frame task called |task| with |task|.`[[rids]]` set to |rids| and |task|.`[[promise]]` set to |promise|. 1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set. - 1. Let |shouldTriggerKeyFrame| be false if |encoder|.`[[pendingKeyFrameTasks]]` contains a task whose `[[rid]]` - value is equal to |rid|, and true otherwise. + 1. Remove from |videoEncoders| any video encoder whose identifying |rid| (or `null` value if it has no rid) + already [=list/contained|exists=] in any `[[rids]]` of any tasks in |encoder|.`[[pendingKeyFrameTasks]]`. 1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`. - 1. If |shouldTriggerKeyFrame| is true, instruct |videoEncoder| to generate a key frame for the next provided video frame. + 1. For each |videoEncoder| in |videoEncoders| (if any), instruct |videoEncoder| to generate a key frame for its + next provided video frame. For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`: 1. Let |encoder| be |transformer|.`[[encoder]]`. 1. If |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps. 1. If |frame| is not a video {{RTCEncodedVideoFrameType/"key"}} frame, abort these steps. 1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps: - 1. If |frame| was generated by a video encoder identified by |task|.`[[rid]]`, run the following steps: + 1. If |frame| was generated by a video encoder identified by a value + [=list/contained=] in |task|.`[[rids]]`, and this brings to zero the number of + video encoders identified in |task|.`[[rids]]` that still haven't finished + generating its keyframe, then run the following steps: 1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`. 1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.