Re: [whatwg/streams] Allow web devs to synchronize branches with tee()? (#1157)

> Say we use a renderer and an encoder and are using tee as these are two different consumers.
> Renderer processes at 60 fps, encoder processes at 30 fps.

I have this [working in Chrome now](https://jsfiddle.net/jib1/hade3nf7/). Self-view is 30 fps for me which is all my camera can muster, and encoder is 15 fps from induced delay, but the self-view stays smooth, even when the encoder struggles.

Dropping frames in a TransformStream turned out to be trivial:
```js
  function FrameDropper() {
    return new TransformStream({
      transform(frame, controller) {
        if (controller.desiredSize < 2) {
          frame.close();
        } else {
          controller.enqueue(frame);
        }
      }
    }, {highWaterMark: 1}, {highWaterMark: 2});
  }
```
I couldn't use `{highWaterMark: 0}, {highWaterMark: 1}` because that would stall due to #1158 so the encoder is a frame behind. Depending on how #1158 is resolved, perhaps we could get to `{highWaterMark: 0}, {highWaterMark: 0}` even?

I also use @MattiasBuelens's `tee({synchronized: true})` polyfill from [above](https://github.com/whatwg/streams/issues/1157#issuecomment-893769058), which I think provides a predictable baseline for video work. I modified it to be `tee({synchronized: true, structuredClone: true})` because #1156, or Chrome would error about closed frames.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1157#issuecomment-918547406

Received on Monday, 13 September 2021 20:24:23 UTC