Skip to content

Update generateKeyFrame to take single optional rid and remove timestamp #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ partial interface DedicatedWorkerGlobalScope {
interface RTCRtpScriptTransformer : EventTarget {
// Attributes and methods related to the transformer source
readonly attribute ReadableStream readable;
Promise<unsigned long long> generateKeyFrame(optional DOMString rid);
Promise<undefined> generateKeyFrame(optional DOMString rid);
Promise<undefined> sendKeyFrameRequest();
// Attributes and methods related to the transformer sink
readonly attribute WritableStream writable;
Expand Down Expand Up @@ -997,32 +997,34 @@ The <dfn abstract-op>generate key frame algorithm</dfn>, 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. If |rid| is not undefined, remove from |videoEncoders| any video encoder that does not match |rid|.
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|.

Note: |videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} encoding is not
{{RTCRtpEncodingParameters/active}}, or the corresponding {{RTCRtpSender}} track is ended.

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>false</code> if |encoder|.`[[pendingKeyFrameTasks]]` contains a task whose `[[rid]]`
value is equal to |rid|, and <code>true</code> otherwise.
value is either undefined or equal to |rid|, and <code>true</code> otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes undefined a special value and coalescing will not happen between undefined and rid1.
It might be better to coalesce and replace the undefined value by the list of all rids.

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.
1. If |shouldTriggerKeyFrame| is <code>true</code>, then for each |videoEncoder| in |videoEncoders|, 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 |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` are 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 |task|.`[[rid]]`, or |task|.`[[rid]]` is undefined and
all video encoders have generated one frame since the generation of |frame| was triggered, run the following steps:
1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.
1. Resolve |task|.`[[promise]]` with undefined.

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.
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.
If the promise is associated with several video encoders, it is resolved when all of them have generated a key frame.

The <dfn abstract-op>send request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
Expand All @@ -1039,16 +1041,16 @@ An additional API on {{RTCRtpSender}} is added to complement the generation of k

<pre class="idl">
partial interface RTCRtpSender {
Promise&lt;undefined&gt; generateKeyFrame(optional sequence &lt;DOMString&gt; rids);
Promise&lt;undefined&gt; generateKeyFrame(optional DOMString rid);
};
</pre>

## Extension operation ## {#sender-operation}

The <dfn method for="RTCRtpSender">generateKeyFrame(|rids|)</dfn> method steps are:
The <dfn method for="RTCRtpSender">generateKeyFrame(|rid|)</dfn> method steps are:

1. Let |promise| be a new promise.
1. [=In parallel=], run the [$generate key frame algorithm$] with |promise|, |this|'s encoder and |rids|.
1. [=In parallel=], run the [$generate key frame algorithm$] with |promise|, |this|'s encoder and |rid|.
1. Return |promise|.

# Privacy and security considerations # {#privacy}
Expand Down