From 57e171699c296ec31a07db0982590b4a66ada5c0 Mon Sep 17 00:00:00 2001 From: Youenn Fablet Date: Wed, 5 Jul 2023 09:30:10 +0200 Subject: [PATCH] Make use of the pullAlgorithm by rewriting readEncodedData to return a promise. Set the highWaterMark to Infinity to keep the same behavior (no backpressure) and add a note about this. Fixes https://github.com/w3c/webrtc-encoded-transform/issues/187. --- index.bs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.bs b/index.bs index f3d0baf..a7411bd 100644 --- a/index.bs +++ b/index.bs @@ -86,7 +86,8 @@ argument, ensure that the codec is disabled and produces no output. At construction of each {{RTCRtpSender}} or {{RTCRtpReceiver}}, run the following steps: 2. Initialize [=this=].`[[transform]]` to null. 3. Initialize [=this=].`[[readable]]` to a new {{ReadableStream}}. -4. Set up [=this=].`[[readable]]`. [=this=].`[[readable]]` is provided frames using the [$readEncodedData$] algorithm given |this| as parameter. +4. Set up [=this=].`[[readable]]` with its [=ReadableStream/set up/pullAlgorithm=] set to [$readEncodedData$] given |this| as parameter and its [=ReadableStream/set up/highWaterMark=] set to Infinity. +

highWaterMark is set to Infinity to explicitly disable backpressure. The goal is to limit buffering as much as possible.

5. Set [=this=].`[[readable]]`.`[[owner]]` to |this|. 6. Initialize [=this=].`[[writable]]` to a new {{WritableStream}}. 7. Set up [=this=].`[[writable]]` with its [=WritableStream/set up/writeAlgorithm=] set to [$writeEncodedData$] given |this| as parameter and its [=WritableStream/set up/sizeAlgorithm=] to an algorithm that returns 0. @@ -104,12 +105,16 @@ At construction of each {{RTCRtpSender}} or {{RTCRtpReceiver}}, run the followin ### Stream processing ### {#stream-processing} The readEncodedData algorithm is given a |rtcObject| as parameter. It is defined by running the following steps: -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}}. -1. Increment |rtcObject|.`[[lastEnqueuedFrameCounter]]` by 1. -1. Let |frame| be the newly produced frame. -1. Set |frame|.`[[owner]]` to |rtcObject|. -1. Set |frame|.`[[counter]]` to |rtcObject|.`[[lastEnqueuedFrameCounter]]`. -1. [=ReadableStream/Enqueue=] |frame| in |rtcObject|.`[[readable]]`. +1. Let |p| be a new promise. +1. Run the following steps in parallel: + 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}}. + 1. Increment |rtcObject|.`[[lastEnqueuedFrameCounter]]` by 1. + 1. Let |frame| be the newly produced frame. + 1. Set |frame|.`[[owner]]` to |rtcObject|. + 1. Set |frame|.`[[counter]]` to |rtcObject|.`[[lastEnqueuedFrameCounter]]`. + 1. [=ReadableStream/Enqueue=] |frame| into |rtcObject|.`[[readable]]`. + 1. Resolve |p| with undefined. +1. return |p|. The writeEncodedData algorithm is given a |rtcObject| as parameter and a |frame| as input. It is defined by running the following steps: 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.