Skip to content
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

Add an API for a "keyframe has been requested" event #215

Merged
merged 9 commits into from
Dec 12, 2023
46 changes: 39 additions & 7 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,28 @@ partial interface DedicatedWorkerGlobalScope {
};

[Exposed=DedicatedWorker]
interface RTCRtpScriptTransformer {
interface RTCRtpScriptTransformer : EventTarget {
// Attributes and methods related to the transformer source
alvestrand marked this conversation as resolved.
Show resolved Hide resolved
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
readonly attribute any options;
Promise<unsigned long long> generateKeyFrame(optional DOMString rid);
Promise<undefined> sendKeyFrameRequest();
// Attributes and methods related to the transformer sink
readonly attribute WritableStream writable;
attribute EventHandler onkeyframerequest;
// Attributes for configuring the Javascript code
readonly attribute any options;
};

[Exposed=Window]
interface RTCRtpScriptTransform {
constructor(Worker worker, optional any options, optional sequence<object> transfer);
};

[Exposed=DedicatedWorker]
interface KeyFrameRequestEvent : Event {
constructor(DOMString type, optional DOMString rid);
readonly attribute DOMString? rid;
};
</pre>

## Operations ## {#RTCRtpScriptTransform-operations}
Expand Down Expand Up @@ -636,12 +646,12 @@ 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(|rid|)</dfn> method steps are:
The <dfn method for="RTCRtpScriptTransform">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 |rid|.
1. Return |promise|.

The <dfn method for="RTCRtpScriptTransformer">sendKeyFrameRequest()</dfn> method steps are:
The <dfn method for="RTCRtpScriptTransform">sendKeyFrameRequest()</dfn> method steps are:
1. Let |promise| be a new promise.
1. Run the [$send request key frame algorithm$] with |promise| and |this|.`[[depacketizer]]`.
1. Return |promise|.
Expand All @@ -655,12 +665,34 @@ This allows algorithms to go from an {{RTCRtpScriptTransformer}} object to its {
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
1. Return [=this=].`[[options]]`.

The <dfn attribute for="RTCRtpScriptTransformer">readable</dfn> getter steps are:
The <dfn attribute for="RTCRtpScriptTransform">readable</dfn> getter steps are:
1. Return [=this=].`[[readable]]`.

The <dfn attribute for="RTCRtpScriptTransformer">writable</dfn> getter steps are:
The <dfn attribute for="RTCRtpScriptTransform">writable</dfn> getter steps are:
1. Return [=this=].`[[writable]]`.

The <dfn attribute for="RTCRtpScriptTransform">onbandwidthestimate</dfn> EventHandler has type bandwidthestimate.

The <dfn attribute for="RTCRtpScriptTransform">onkeyframerequest</dfn> EventHandler has type keyframerequest.

## Events ## {#RTCRtpScriptTransformer-events}

The following event fires on an {{RTCRtpScriptTransformer}}:

* keyframerequest of type {{KeyFrameRequestEvent}} - fired when the sink determines that a key frame has been requested.

The steps that generate an event of type {{KeyFrameRequestEvent}} are as follows:

Given a {{RTCRtpScriptTransformer}} |transform|:

When |transform|'s `[[encoder]]` receives a keyframe request, for instance from an incoming RTCP Picture Loss Indication (PLI)
or Full Intra Refresh (FIR), queue a task to perform the following steps:

1. Set |rid| to the RID of the appropriate layer, or undefined if the request is not for a specific layer.
1. [=Fire an event=] named `keyframerequest` at |transform| using {{KeyFrameRequestEvent}} with its {{Event/cancelable}} attribute initialized to "true", and with {{KeyFrameRequestEvent/rid}} set to |rid|.
1. If the event's [=Event/canceled flag=] is true, abort these steps.
1. Run the [$generate key frame algorithm$] with a new promise, |transform|.`[[encoder]]` and |rid|.

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

The <dfn abstract-op>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
Expand Down
Loading