Skip to content

Commit ae121de

Browse files
committed
Make RTCEncodedVideoFrame and RTCEncodedAudioFrame transferable
1 parent 4b61373 commit ae121de

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

index.bs

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ The <dfn abstract-op>writeEncodedData</dfn> algorithm is given a |rtcObject| as
142142
1. Set |rtcObject|.`[[lastReceivedFrameCounter]]` to |frame|`[[counter]]`.
143143
1. Let |data| be |frame|.`[[data]]`.
144144
1. Let |serializedFrame| be [$StructuredSerializeWithTransfer$](|frame|, « |data| »).
145-
1. Let |frameCopy| be [$StructuredDeserialize$](|serializedFrame|, |frame|'s [=relevant realm=]).
146-
1. Enqueue |frameCopy| for processing as if it came directly from the encoded data source, by running one of the following steps:
147-
* If |rtcObject| is a {{RTCRtpSender}}, enqueue |frameCopy| to |rtcObject|'s packetizer, to be processed [=in parallel=].
148-
* If |rtcObject| is a {{RTCRtpReceiver}}, enqueue |frameCopy| it to |rtcObject|'s decoder, to be processed [=in parallel=].
145+
1. Let |transferredFrame| be [$StructuredDeserializeWithTransfer$](|serializedFrame|, |frame|'s [=relevant realm=]).
146+
1. Enqueue |transferredFrame| for processing as if it came directly from the encoded data source, by running one of the following steps:
147+
* If |rtcObject| is a {{RTCRtpSender}}, enqueue |transferredFrame| to |rtcObject|'s packetizer, to be processed [=in parallel=].
148+
* If |rtcObject| is a {{RTCRtpReceiver}}, enqueue |transferredFrame| it to |rtcObject|'s decoder, to be processed [=in parallel=].
149149
1. Return [=a promise resolved with=] undefined.
150150

151151
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.
@@ -451,7 +451,7 @@ dictionary RTCEncodedVideoFrameOptions {
451451

452452
// New interfaces to define encoded video and audio frames. Will eventually
453453
// re-use or extend the equivalent defined in WebCodecs.
454-
[Exposed=(Window,DedicatedWorker), Serializable]
454+
[Exposed=(Window,DedicatedWorker), Serializable, Transferable]
455455
interface RTCEncodedVideoFrame {
456456
constructor(RTCEncodedVideoFrame originalFrame, optional RTCEncodedVideoFrameOptions options = {});
457457
readonly attribute RTCEncodedVideoFrameType type;
@@ -580,26 +580,41 @@ interface RTCEncodedVideoFrame {
580580
</dd>
581581
</dl>
582582

583-
### Serialization ### {#RTCEncodedVideoFrame-serialization}
583+
### Transfer and Serialization ### {#RTCEncodedVideoFrame-serialization}
584+
585+
{{RTCEncodedVideoFrame}} objects are [=serializable objects=] and [=transferable objects=].
584586

585-
{{RTCEncodedVideoFrame}} objects are serializable objects [[HTML]].
586587
Their [=serialization steps=], given |value|, |serialized|, and |forStorage|, are:
587588

588589
1. If |forStorage| is true, then throw a {{DataCloneError}}.
589-
1. Set |serialized|.`[[type]]` to the value of |value|.{{RTCEncodedVideoFrame/type}}
590+
1. Set |serialized|.`[[type]]` to the value of |value|.{{RTCEncodedVideoFrame/type}}.
590591
1. Set |serialized|.`[[metadata]]` to an internal representation of |value|'s metadata.
591-
1. Set |serialized|.`[[data]]` to |value|.`[[data]]`
592+
1. Set |serialized|.`[[data]]` to a copy of |value|.`[[data]]`.
592593

593594
Their [=deserialization steps=], given |serialized|, |value| and |realm|, are:
594595

595-
1. Set |value|.{{RTCEncodedVideoFrame/type}} to |serialized|.`[[type]]`
596-
1. Set |value|'s metadata to the platform object representation of |serialized|.`[[metadata]]`
596+
1. Set |value|.{{RTCEncodedVideoFrame/type}} to |serialized|.`[[type]]`.
597+
1. Set |value|'s metadata to the platform object representation of |serialized|.`[[metadata]]`.
597598
1. Set |value|.`[[data]]` to |serialized|.`[[data]]`.
598599

600+
Their [=transfer steps=], given |value| and |dataHolder|, are:
601+
602+
1. Set |dataHolder|.`[[type]]` to the value of |value|.{{RTCEncodedVideoFrame/type}}.
603+
1. Set |dataHolder|.`[[metadata]]` to an internal representation of |value|'s metadata.
604+
1. Set |dataHolder|.`[[data]]` to |value|.`[[data]]`.
605+
1. Unset |value|.`[[data]]`.
606+
607+
Their [=transfer-receiving steps=], given |dataHolder| and |value|, are:
608+
609+
1. Set |value|.{{RTCEncodedVideoFrame/type}} to |dataHolder|.`[[type]]`
610+
1. Set |value|'s metadata to the platform object representation of |dataHolder|.`[[metadata]]`.
611+
1. Set |value|.`[[data]]` to |dataHolder|.`[[data]]`.
612+
599613
<p class="note">
600614
The internal form of a serialized RTCEncodedVideoFrame is not observable;
601-
it is defined chiefly so that it can be used with frame cloning in the
602-
[$writeEncodedData$] algorithm and in the {{WindowOrWorkerGlobalScope/structuredClone()}} operation.
615+
transfer is used to hand off frames in the
616+
[$writeEncodedData$] algorithm, and serialization is used in the
617+
{{WindowOrWorkerGlobalScope/structuredClone()}} operation.
603618
An implementation is therefore free to choose whatever method works best.
604619
</p>
605620

@@ -681,7 +696,7 @@ dictionary RTCEncodedAudioFrameOptions {
681696
RTCEncodedAudioFrameMetadata metadata;
682697
};
683698

684-
[Exposed=(Window,DedicatedWorker), Serializable]
699+
[Exposed=(Window,DedicatedWorker), Serializable, Transferable]
685700
interface RTCEncodedAudioFrame {
686701
constructor(RTCEncodedAudioFrame originalFrame, optional RTCEncodedAudioFrameOptions options = {});
687702
attribute ArrayBuffer data;
@@ -806,20 +821,32 @@ interface RTCEncodedAudioFrame {
806821
</dl>
807822

808823

809-
### Serialization ### {#RTCEncodedAudioFrame-serialization}
824+
### Transfer and Serialization ### {#RTCEncodedAudioFrame-serialization}
825+
826+
{{RTCEncodedAudioFrame}} objects are [=serializable objects=] and [=transferable objects=].
810827

811-
{{RTCEncodedAudioFrame}} objects are serializable objects [[HTML]].
812828
Their [=serialization steps=], given |value|, |serialized|, and |forStorage|, are:
813829

814830
1. If |forStorage| is true, then throw a {{DataCloneError}}.
815831
1. Set |serialized|.`[[metadata]]` to an internal representation of |value|'s metadata.
816-
1. Set |serialized|.`[[data]]` to |value|.`[[data]]`
832+
1. Set |serialized|.`[[data]]` to a copy of |value|.`[[data]]`
817833

818834
Their [=deserialization steps=], given |serialized|, |value| and |realm|, are:
819835

820836
1. Set |value|'s metadata to the platform object representation of |serialized|.`[[metadata]]`
821837
1. Set |value|.`[[data]]` to |serialized|.`[[data]]`.
822838

839+
Their [=transfer steps=], given |value| and |dataHolder|, are:
840+
841+
1. Set |dataHolder|.`[[metadata]]` to an internal representation of |value|'s metadata.
842+
1. Set |dataHolder|.`[[data]]` to |value|.`[[data]]`.
843+
1. Unset |value|.`[[data]]`.
844+
845+
Their [=transfer-receiving steps=], given |dataHolder| and |value|, are:
846+
847+
1. Set |value|'s metadata to the platform object representation of |dataHolder|.`[[metadata]]`.
848+
1. Set |value|.`[[data]]` to |dataHolder|.`[[data]]`.
849+
823850
## Interfaces ## {#RTCRtpScriptTransformer-interfaces}
824851
<pre class="idl">
825852
[Exposed=DedicatedWorker]
@@ -867,9 +894,9 @@ The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worke
867894
6. Let |serializedReadable| be the result of [$StructuredSerializeWithTransfer$](|t1|.`[[readable]]`, « |t1|.`[[readable]]` »).
868895
7. Let |serializedWritable| be the result of [$StructuredSerializeWithTransfer$](|t2|.`[[writable]]`, « |t2|.`[[writable]]` »).
869896
8. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
870-
1. Let |transformerOptions| be the result of [$StructuredDeserialize$](|serializedOptions|, the current Realm).
871-
2. Let |readable| be the result of [$StructuredDeserialize$](|serializedReadable|, the current Realm).
872-
3. Let |writable| be the result of [$StructuredDeserialize$](|serializedWritable|, the current Realm).
897+
1. Let |transformerOptions| be the result of [$StructuredDeserializeWithTransfer$](|serializedOptions|, the current Realm).
898+
2. Let |readable| be the result of [$StructuredDeserializeWithTransfer$](|serializedReadable|, the current Realm).
899+
3. Let |writable| be the result of [$StructuredDeserializeWithTransfer$](|serializedWritable|, the current Realm).
873900
4. Let |transformer| be a new {{RTCRtpScriptTransformer}}.
874901
5. Set |transformer|.`[[options]]` to |transformerOptions|.
875902
6. Set |transformer|.`[[readable]]` to |readable|.

0 commit comments

Comments
 (0)