Open padenot opened 6 months ago
Spec is indeed not very precise. It makes sense to me for reset()
to cancel all previous tasks.
According https://wpt.fyi/results/webcodecs/video-encoder-flush.https.any.html?label=master&label=experimental&aligned, it seems Chrome and Safari agree here.
To me it looks like the spec does say things about callbacks and promises, but we can probably make it more explicit in the callback algo.
Immediately resets all state including configuration, control messages in the control message queue, and all pending callbacks. When invoked, run the Reset VideoEncoder algorithm with an AbortError DOMException.
Run these steps:
If [[state]] is "closed", throw an InvalidStateError.
Set [[state]] to "unconfigured".
Set [[active encoder config]] to null.
Set [[active output config]] to null.
Signal [[codec implementation]] to cease producing output for the previous configuration.
Remove all control messages from the [[control message queue]].
If [[encodeQueueSize]] is greater than zero:
Set [[encodeQueueSize]] to zero.
Run the Schedule Dequeue Event algorithm.
For each promise in [[pending flush promises]]:
Reject promise with exception.
Remove promise from [[pending flush promises]].
Yes but the point is that depending on the encoder being used, reset()
hasn't been called when flush()
is called, details are in the proposed change, there are comments.
See https://github.com/web-platform-tests/interop/issues/614
Let's say I have an encoder that has quite a long latency, e.g. 16 frames.
If we enqueue 15 frames for encoding, call
flush()
and in output callback, callreset()
on the encoder after e.g. the 8th callback, what should happen?Firefox outputs the 15 frames, the
flush()
succeeds, and then the encoder is reset, because there's no prose to check that the encoder has been reset in the algorithm that calls the callback. But the description of thereset()
method says that callbacks are not to continue (paraphrasing).The intent might have been to not call the callbacks after a reset, and we should make it explicit if that's the case.