Skip to content

Commit 1dca761

Browse files
committed
Relocate more internal slots; add [[frameSource]] to simplify
1 parent b64841d commit 1dca761

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

index.bs

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ partial interface RTCRtpReceiver {
9595

9696
This allows manipulation of encoded frames in the media pipeline
9797
between the processing steps of an {{RTCRtpSender}}'s underlying
98-
<dfn>encoder</dfn> and <dfn ignore=''>packetizer</dfn>, and/or
98+
<dfn>encoder</dfn> and <dfn>packetizer</dfn>, and/or
9999
between an {{RTCRtpReceiver}}'s underlying <dfn>depacketizer</dfn>
100-
and <dfn ignore=''>decoder</dfn>.
100+
and <dfn>decoder</dfn>.
101101

102102
## Extension operation ## {#operation}
103103

@@ -108,8 +108,6 @@ argument, ensure that the codec is disabled and produces no output.
108108
At construction of each {{RTCRtpSender}} or {{RTCRtpReceiver}}, run the following steps:
109109
1. Initialize [=this=].`[[transform]]` to null.
110110
1. Initialize [=this=].`[[pipeToController]]` to null.
111-
1. Initialize [=this=].`[[lastReceivedFrameCounter]]` to <code>0</code>.
112-
1. Initialize [=this=].`[[lastEnqueuedFrameCounter]]` to <code>0</code>.
113111
1. [=Queue a task=] to run the following steps:
114112
1. If [=this=].`[[pipeToController]]` is not null, abort these steps.
115113
2. Set [=this=].`[[pipeToController]]` to a new {{AbortController}}.
@@ -128,13 +126,14 @@ The User Agent is responsible for doing these adaptations, especially since it c
128126
For those reasons, streams backpressure is disabled in WebRTC encoded transforms.
129127
</p>
130128

131-
The <dfn abstract-op>readEncodedData</dfn> algorithm is given a |rtcObject| as parameter. It is defined by running the following steps:
132-
1. Wait for a frame to be produced by |rtcObject|'s encoder if it is a {{RTCRtpSender}} or |rtcObject|'s packetizer if it is a {{RTCRtpReceiver}}.
133-
1. Increment |rtcObject|.`[[lastEnqueuedFrameCounter]]` by <code>1</code>.
129+
The <dfn abstract-op>readEncodedData</dfn> algorithm is given an {{RTCRtpScriptTransformer}}
130+
|transformer| as parameter. It is defined by running the following steps:
131+
1. Wait for a frame to be produced by |transformer|.{{[[frameSource]]}}.
132+
1. Increment |transformer|.`[[lastEnqueuedFrameCounter]]` by <code>1</code>.
134133
1. Let |frame| be the newly produced frame.
135-
1. Set |frame|.`[[owner]]` to |rtcObject|.
136-
1. Set |frame|.`[[counter]]` to |rtcObject|.`[[lastEnqueuedFrameCounter]]`.
137-
1. If the frame has been produced by a {{RTCRtpReceiver}}:
134+
1. Set |frame|.`[[owner]]` to |transformer|.{{[[frameSource]]}}.
135+
1. Set |frame|.`[[counter]]` to |transformer|.{{[[lastEnqueuedFrameCounter]]}}.
136+
1. If |frame|.`[[owner]]` is a [=depacketizer=]:
138137
1. If the relevant RTP packet contains the
139138
[[RTP-EXT-CAPTURE-TIME|RTP Header Extension for Absolute Capture Time]], set |frame|.`[[captureTime]]` to the
140139
[[RTP-EXT-CAPTURE-TIME#absolute-capture-timestamp|absolute capture timestamp]] field and set |frame|.`[[senderCaptureTimeOffset]]`
@@ -145,30 +144,32 @@ The <dfn abstract-op>readEncodedData</dfn> algorithm is given a |rtcObject| as p
145144
[[RTP-EXT-CAPTURE-TIME#timestamp-interpolation|timestamp interpolation]] and set |frame|.`[[senderCaptureTimeOffset]]`
146145
to the most recent value that was present.
147146
1. Otherwise, set |frame|.`[[captureTime]]` to undefined and set |frame|.`[[senderCaptureTimeOffset]]` to undefined.
148-
1. If the frame has been produced by a {{RTCRtpSender}}, set |frame|.`[[captureTime]]` to the capture timestamp
147+
1. If |frame|.`[[owner]]` is an [=encoder=], set |frame|.`[[captureTime]]` to the capture timestamp
149148
using the methodology described in [[RTP-EXT-CAPTURE-TIME#absolute-capture-timestamp]] and set frame.`[[senderCaptureTimeOffset]]`
150149
to undefined.
151-
1. [=ReadableStream/Enqueue=] |frame| in |rtcObject|.`[[readable]]`.
150+
1. [=ReadableStream/Enqueue=] |frame| into |transformer|.{{[[readable]]}}.
152151

153-
The <dfn abstract-op>writeEncodedData</dfn> algorithm is given a |rtcObject| as parameter and a |frame| as input. It is defined by running the following steps:
154-
1. If |frame|.`[[owner]]` is not equal to |rtcObject|, abort these steps and return [=a promise resolved with=] undefined. A processor cannot create frames, or move frames between streams.
155-
1. If |frame|.`[[counter]]` is equal or smaller than |rtcObject|.`[[lastReceivedFrameCounter]]`, abort these steps and return [=a promise resolved with=] undefined. A processor cannot reorder frames, although it may delay them or drop them.
156-
1. Set |rtcObject|.`[[lastReceivedFrameCounter]]` to |frame|`[[counter]]`.
152+
The <dfn abstract-op>writeEncodedData</dfn> algorithm is given an {{RTCRtpScriptTransformer}}
153+
|transformer| as parameter and a |frame| as input. It is defined by running the following steps:
154+
1. If |frame|.`[[owner]]` is not equal to |transformer|.{{[[frameSource]]}}, abort these steps and return [=a promise resolved with=] undefined. A processor cannot create frames, or move frames between streams.
155+
1. If |frame|.`[[counter]]` is equal or smaller than |transformer|.`[[lastReceivedFrameCounter]]`, abort these steps and return [=a promise resolved with=] undefined. A processor cannot reorder frames, although it may delay them or drop them.
156+
1. Set |transformer|.`[[lastReceivedFrameCounter]]` to |frame|.`[[counter]]`.
157157
1. Let |data| be |frame|.`[[data]]`.
158158
1. Let |serializedFrame| be [$StructuredSerializeWithTransfer$](|frame|, « |data| »).
159159
1. Let |frameCopy| be [$StructuredDeserializeWithTransfer$](|serializedFrame|, |frame|'s [=relevant realm=]).
160160
1. Enqueue |frameCopy| for processing as if it came directly from the encoded data source, by running one of the following steps:
161-
* If |rtcObject| is a {{RTCRtpSender}}, enqueue |frameCopy| to |rtcObject|'s packetizer, to be processed [=in parallel=].
162-
* If |rtcObject| is a {{RTCRtpReceiver}}, enqueue |frameCopy| it to |rtcObject|'s decoder, to be processed [=in parallel=].
161+
* If |transformer|.{{[[frameSource]]}} is an [=encoder=], enqueue |frameCopy| to its
162+
associated [=packetizer=], to be processed [=in parallel=].
163+
* If |transformer|.{{[[frameSource]]}} is a [=depacketizer=], enqueue |frameCopy| to its associated [=decoder=], to be processed [=in parallel=].
163164
1. Return [=a promise resolved with=] undefined.
164165

165-
On sender side, as part of [$readEncodedData$], frames produced by |rtcObject|'s encoder MUST be enqueued in |rtcObject|.`[[readable]]` in the encoder's output order.
166+
On the sender side, as part of [$readEncodedData$], frames produced by the [=encoder=] MUST be [=ReadableStream/enqueued=] into |transformer|.{{[[readable]]}} in the [=encoder=]'s output order.
166167
As [$writeEncodedData$] ensures that the transform cannot reorder frames, the encoder's output order is also the order followed by packetizers to generate RTP packets and assign RTP packet sequence numbers.
167-
The packetizer may expect the transformed data to still conform to the original format, e.g. a series of NAL units separated by Annex B start codes.
168+
The [=packetizer=] may expect the transformed data to still conform to the original format, e.g. a series of NAL units separated by Annex B start codes.
168169

169-
On receiver side, as part of [$readEncodedData$], frames produced by |rtcObject|'s packetizer MUST be enqueued in |rtcObject|.`[[readable]]` in the same encoder's output order.
170-
To ensure the order is respected, the depacketizer will typically use RTP packet sequence numbers to reorder RTP packets as needed before enqueuing frames in |rtcObject|.`[[readable]]`.
171-
As [$writeEncodedData$] ensures that the transform cannot reorder frames, this will be the order expected by |rtcObject|'s decoder.
170+
On the receiver side, as part of [$readEncodedData$], frames produced by the [=depacketizer=] MUST be [=ReadableStream/enqueued=] into |transformer|.{{[[readable]]}} in the same [=encoder=]'s output order.
171+
To ensure the order is respected, the [=depacketizer=] will typically use RTP packet sequence numbers to reorder RTP packets as needed before [=ReadableStream/enqueuing=] frames into |transformer|.{{[[readable]]}}.
172+
As [$writeEncodedData$] ensures that the transform cannot reorder frames, this will be the order expected by the [=decoder=].
172173

173174
## Extension attribute ## {#attribute}
174175

@@ -202,7 +203,7 @@ The <dfn abstract-op>chain transform algorithm</dfn> steps are defined as:
202203
1. If |newPipeToController|'s [=AbortController/signal=] is [=AbortSignal/aborted=], abort these steps.
203204
2. [=ReadableStreamDefaultReader/Release=] |reader|.
204205
3. [=WritableStreamDefaultWriter/Release=] |writer|.
205-
4. Assert that |newPipeToController| is the same object as |rtcObject|.`[[pipeToController]]`.
206+
4. [=Assert=] that |newPipeToController| is the same object as |rtcObject|.`[[pipeToController]]`.
206207
<!-- FIXME: Use pipeTo algorithm when available. -->
207208
5. Call <a href="https://streams.spec.whatwg.org/#readable-stream-pipe-to">pipeTo</a> with |rtcObject|.`[[readable]]`, |checkedTransform|.`[[writable]]`, preventClose equal to false, preventAbort equal to false, preventCancel equal to true and |newPipeToController|'s [=AbortController/signal=].
208209
6. Call <a href="https://streams.spec.whatwg.org/#readable-stream-pipe-to">pipeTo</a> with |checkedTransform|.`[[readable]]`, |rtcObject|.`[[writable]]`, preventClose equal to true, preventAbort equal to true, preventCancel equal to false and |newPipeToController|'s [=AbortController/signal=].
@@ -930,12 +931,10 @@ The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worke
930931

931932
Each {{RTCRtpScriptTransform}} has the following set of [$association steps$], given |rtcObject|:
932933
1. Let |transform| be the {{RTCRtpScriptTransform}} object that owns the [$association steps$].
933-
1. Let |encoder| be |rtcObject|'s encoder if |rtcObject| is a {{RTCRtpSender}} or undefined otherwise.
934-
1. Let |depacketizer| be |rtcObject|'s depacketizer if |rtcObject| is a {{RTCRtpReceiver}} or undefined otherwise.
934+
1. Let |frameSource| be |rtcObject|'s [=encoder=] if |rtcObject| is an {{RTCRtpSender}} or |rtcObject|'s [=depacketizer=] otherwise.
935935
1. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
936936
1. Let |transformer| be the {{RTCRtpScriptTransformer}} object associated to |transform|.
937-
1. Set |transformer|.`[[encoder]]` to |encoder|.
938-
1. Set |transformer|.`[[depacketizer]]` to |depacketizer|.
937+
1. Set |transformer|.{{[[frameSource]]}} to |frameSource|.
939938

940939
# <dfn interface>RTCRtpScriptTransformer</dfn> interface # {#RTCRtpScriptTransformer-interface}
941940
<pre class="idl">
@@ -955,7 +954,7 @@ interface RTCRtpScriptTransformer : EventTarget {
955954

956955
## Internal slots ## {#RTCRtpScriptTransformer-internal-slots}
957956

958-
A {{RTCRtpScriptTransformer}} object has the following internal slots.
957+
An {{RTCRtpScriptTransformer}} object has the following internal slots.
959958

960959
<table class="data" dfn-for="RTCRtpScriptTransformer" dfn-type="attribute">
961960
<thead>
@@ -966,12 +965,8 @@ A {{RTCRtpScriptTransformer}} object has the following internal slots.
966965
</thead>
967966
<tbody>
968967
<tr>
969-
<td><dfn>`[[depacketizer]]`</dfn>
970-
<td class="non-normative">A [=depacketizer=] or undefined.
971-
</tr>
972-
<tr>
973-
<td><dfn>`[[encoder]]`</dfn>
974-
<td class="non-normative">An [=encoder=] or undefined.
968+
<td><dfn>`[[frameSource]]`</dfn>
969+
<td class="non-normative">An [=encoder=], a [=depacketizer=], or undefined.
975970
</tr>
976971
<tr>
977972
<td><dfn>`[[options]]`</dfn>
@@ -985,23 +980,33 @@ A {{RTCRtpScriptTransformer}} object has the following internal slots.
985980
<td><dfn>`[[writable]]`</dfn>
986981
<td class="non-normative">A {{WritableStream}}.
987982
</tr>
983+
<tr>
984+
<td><dfn>`[[lastReceivedFrameCounter]]`</dfn>
985+
<td class="non-normative">A count of frames received.
986+
</tr>
987+
<tr>
988+
<td><dfn>`[[lastEnqueuedFrameCounter]]`</dfn>
989+
<td class="non-normative">A count of frames enqueued.
990+
</tr>
988991
</tbody>
989992
</table>
990993

991994
<div algorithm="create|creating">
992995
To <dfn for="RTCRtpScriptTransformer" lt="create|creating">create</dfn> an
993996
{{RTCRtpScriptTransformer}}, given an |options| object, perform the following steps:
994997
1. Let |transformer| be a [=new=] {{RTCRtpScriptTransformer}}, with:
995-
: {{RTCRtpScriptTransformer/[[depacketizer]]}}
996-
:: undefined
997-
: {{RTCRtpScriptTransformer/[[encoder]]}}
998+
: {{RTCRtpScriptTransformer/[[frameSource]]}}
998999
:: undefined
9991000
: {{RTCRtpScriptTransformer/[[options]]}}
10001001
:: |options|
10011002
: {{RTCRtpScriptTransformer/[[readable]]}}
1002-
:: A new {{ReadableStream}}.
1003+
:: A new {{ReadableStream}}
10031004
: {{RTCRtpScriptTransformer/[[writable]]}}
1004-
:: A new {{WritableStream}}.
1005+
:: A new {{WritableStream}}
1006+
: {{RTCRtpScriptTransformer/[[lastReceivedFrameCounter]]}}
1007+
:: 0
1008+
: {{RTCRtpScriptTransformer/[[lastEnqueuedFrameCounter]]}}
1009+
:: 0
10051010
1. [=ReadableStream/Set up=] |transformer|.{{[[readable]]}}. <p class="note">The
10061011
[$readEncodedData$] algorithm, given |this| as parameter, provides encoded frames to it.
10071012
</p>
@@ -1030,20 +1035,16 @@ To <dfn for="RTCRtpScriptTransformer" lt="create|creating">create</dfn> an
10301035

10311036
The <dfn method for="RTCRtpScriptTransformer">generateKeyFrame(|rid|)</dfn> method steps are:
10321037
1. Let |promise| be a new promise.
1033-
1. Run the [$generate key frame algorithm$] with |promise|, |this|.`[[encoder]]` and |rid|.
1038+
1. Run the [$generate key frame algorithm$] with |promise|, |this|.`[[frameSource]]` and |rid|.
10341039
1. Return |promise|.
10351040

10361041
The <dfn method for="RTCRtpScriptTransformer">sendKeyFrameRequest()</dfn> method steps are:
10371042
1. Let |promise| be a new promise.
1038-
1. Run the [$send request key frame algorithm$] with |promise| and |this|.`[[depacketizer]]`.
1043+
1. Run the [$send request key frame algorithm$] with |promise| and |this|.`[[frameSource]]`.
10391044
1. Return |promise|.
10401045

10411046
## Attributes ## {#RTCRtpScriptTransformer-attributes}
10421047

1043-
A {{RTCRtpScriptTransformer}} has the following private slots called `[[depacketizer]]`, `[[encoder]]`, `[[options]]`, `[[readable]]` and `[[writable]]`.
1044-
In addition, a {{RTCRtpScriptTransformer}} is always associated with its parent {{RTCRtpScriptTransform}} transform.
1045-
This allows algorithms to go from an {{RTCRtpScriptTransformer}} object to its {{RTCRtpScriptTransform}} parent and vice versa.
1046-
10471048
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
10481049
1. Return [=this=].`[[options]]`.
10491050

@@ -1082,21 +1083,19 @@ The following event fires on an {{RTCRtpScriptTransformer}}:
10821083

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

1085-
Given a {{RTCRtpScriptTransformer}} |transform|:
1086-
1087-
When |transform|'s `[[encoder]]` receives a keyframe request, for instance from an incoming RTCP Picture Loss Indication (PLI)
1086+
When the [=encoder=] of an associated {{RTCRtpScriptTransformer}} |transformer| receives a keyframe request, for instance from an incoming RTCP Picture Loss Indication (PLI)
10881087
or Full Intra Refresh (FIR), queue a task to perform the following steps:
10891088

10901089
1. Set |rid| to the RID of the appropriate layer, or undefined if the request is not for a specific layer.
1091-
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|.
1090+
1. [=Fire an event=] named `keyframerequest` at |transformer| using {{KeyFrameRequestEvent}} with its {{Event/cancelable}} attribute initialized to "true", and with {{KeyFrameRequestEvent/rid}} set to |rid|.
10921091
1. If the event's [=Event/canceled flag=] is true, abort these steps.
1093-
1. Run the [$generate key frame algorithm$] with a new promise, |transform|.`[[encoder]]` and |rid|.
1092+
1. Run the [$generate key frame algorithm$] with a new promise, |transformer|.`[[frameSource]]` and |rid|.
10941093

10951094
## KeyFrame Algorithms ## {#KeyFrame-algorithms}
10961095

10971096
The <dfn abstract-op>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
1098-
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
1099-
1. If |encoder| does not belong to a video {{RTCRtpReceiver}}, reject |promise| with {{InvalidStateError}}, abort these steps.
1097+
1. If |encoder| is not an [=encoder=], reject |promise| with {{InvalidStateError}}, abort these steps.
1098+
1. If |encoder| does not belong to a video {{RTCRtpSender}}, reject |promise| with {{InvalidStateError}}, abort these steps.
11001099
1. If |rid| is defined, but does not conform to the grammar requirements specified
11011100
in Section 10 of [[!RFC8851]], then reject |promise| with {{TypeError}} and abort
11021101
these steps.
@@ -1116,9 +1115,9 @@ The <dfn abstract-op>generate key frame algorithm</dfn>, given |promise|, |encod
11161115
1. For each |layer| in |layers| (if any), instruct |encoder| to generate a key frame for its
11171116
next provided video frame to that |layer|.
11181117

1119-
For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`:
1120-
1. Let |encoder| be |transformer|.`[[encoder]]`.
1121-
1. If |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps.
1118+
For any [=encoder=] associated with an {{RTCRtpScriptTransformer}} |transformer|, the user agent MUST run the following steps just before any |frame| is [=ReadableStream/enqueued=] into |transformer|.{{[[readable]]}}:
1119+
1. Let |encoder| be |transformer|.{{[[frameSource]]}}.
1120+
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps.
11221121
1. If |frame| is not a video {{RTCEncodedVideoFrameType/"key"}} frame, abort these steps.
11231122
1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps:
11241123
1. If |frame| was generated for a layer [=list/contained=] in |task|.`[[layers]]`,
@@ -1133,7 +1132,7 @@ the resolution callbacks of the promises are always executed just before the cor
11331132
If the promise is associated with several layers, it will be resolved once key frames have been enqueued for all of them.
11341133

11351134
The <dfn abstract-op>send request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
1136-
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
1135+
1. If |depacketizer| is not a [=depacketizer=], reject |promise| with {{InvalidStateError}}, abort these steps.
11371136
1. If |depacketizer| does not belong to a video {{RTCRtpReceiver}}, reject |promise| with {{InvalidStateError}}, abort these steps.
11381137
1. [=In parallel=], run the following steps:
11391138
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.

0 commit comments

Comments
 (0)