Skip to content

Commit

Permalink
Make generateKeyFrame take a single RID or none. Resolve the promise …
Browse files Browse the repository at this point in the history
…with the frame timestamp
  • Loading branch information
youennf committed Apr 7, 2022
1 parent da20661 commit 36c965e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ interface RTCRtpScriptTransformer {
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
readonly attribute any options;
Promise<undefined> generateKeyFrame(optional sequence <DOMString> rids);
Promise<unsigned long long> generateKeyFrame(optional DOMString rid);
Promise<undefined> sendKeyFrameRequest();
};

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

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

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

## KeyFrame Algorithms ## {#KeyFrame-algorithms}

The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rids|, is defined by running these steps:
The <dfn>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
1. If |encoder| is not processing video frames, reject |promise| with {{InvalidStateError}}, abort these steps.
1. If |rids| is defined, validate each of the RID values in |rids|.
If any RID value is invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
1. If |rid| is defined, validate its value. If invalid, reject |promise| with {{NotAllowedError}} and abort these steps.
1. [=In parallel=], run the following steps:
1. Gather a list of video encoders, named |videoEncoders| from |encoder|.
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
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. If |videoEncoders| is empty, 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. For each |rid| in |rids|, run the following substeps:
1. Create a pending key frame task called |task| with ||task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|.
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
1. If |encoder|.`[[pendingKeyFrameTasks]]` contains a task which is matching |rid|, remove |rid| from |rids|.
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
1. If |rids| is not empty, remove from |videoEncoders| any video encoder that does not match a value in |rids|.
1. For each |videoEncoder| in |videoEncoders|, instruct |videoEncoder| to generate a key frame for the next provided video frame.
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|.
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
1. Let |shouldTriggerKeyFrame| be <code>true</code> if |encoder|.`[[pendingKeyFrameTasks]]` contains a task whose `[[rid]]`
value which is equal to |rid|, and <code>false</code> otherwise.
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
1. If |shouldTriggerKeyFrame| is <code>true</code>, instruct |videoEncoder| to generate a key frame for the 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]]`.
Expand All @@ -433,7 +434,7 @@ For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are
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. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
1. Resolve |task|.`[[promise]]` with undefined.
1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.

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

0 comments on commit 36c965e

Please sign in to comment.