Re: [whatwg/streams] Reset for TransformStream (and WritableStream?) (#1026)

> I mean flush as in #960.

Ah, that does make more sense. 😅

I'm still a bit hesitant though. The way I understand the proposed `sync()` method: it's completely optional whether or not the transformer provides a `sync()` method, or whether the transform stream actually calls the transformer's `sync()` method at all. In the Zlib example, even if you never call `sync()`, you'll still get a valid compressed stream.

However, with `reset()`, those calls are not optional. The transform stream will call `reset()` when there's a "discontinuity" in the source (e.g. a video seek), and the transformer needs to be made aware of that. Otherwise, if the transformer does not implement `reset()`, the transformer will still think that the next chunk passed to `transform()` will be a "continuation" of the previous chunk (e.g. the video frames are part of the same [GOP](https://en.wikipedia.org/wiki/Group_of_pictures)).

I'm also not sure whether "call `sync()` and clear the queues" is always a valid fall-back scenario in case no `reset()` method is provided. For example:
* For a video decoder stream, `sync()` could mean: finish decoding any pending frames and enqueue them. (For example, you might have been holding onto the last few frames whose PTS > DTS, since perhaps a future frame will need to be presented out-of-order: DTS1 < DTS2 < PTS2 < PTS1.) Nothing about `sync()`'s current definition requires the video decoder to start a new GOP on the next `transform()` call.
* For a [TextDecoderStream](https://encoding.spec.whatwg.org/#interface-textdecoderstream), `sync()` would be empty: while the decoder might still be holding onto one or more bytes from the end of the previous chunk, it should not yet try to decode them inside `sync()`. Instead, a TextDecoderStream would need to explicitly implement `reset()`, so that it can first "process end-of-stream" on its decoder to get rid of those buffered bytes (possibly enqueuing a replacement character), and then reset its decoder in preparation for the next `transform()` call.

-- 
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/1026#issuecomment-581685510

Received on Tuesday, 4 February 2020 00:29:05 UTC