-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What happens if the callback takes too long? #3
Comments
This is based on the current state of the implementation, rather than from a formal spec POV, but it's a good question that should be addressed in the spec. The frame would still be presented, and video.rAF callbacks shouldn't hold anything up. In practice, it's because the presenting is happening on the compositor thread, and the callbacks are queued on the main thread immediately after the frame has been updated. video.requestAnimationFrame((x, metadata) => { |
Since this issue asks about the current implementation of the callbacks I want to pitch in. I have a use case in which you would want to block the immediate display of the next video frame. I'm currently developing a Chrome extension that surrounds ambilight effect around YouTube video's with a canvas element. With the current implementation of requestAnimationFrame in the Chrome Beta channel the video and canvas frames are perfectly in sync. But that's only for video's up to 1080p and depends on the power of the graphics card. The canvas is a frame too late for video's larger or faster than that (1440p/24fps and up), but the canvas can still maintain the same framerate as the video on a 144hz monitor. Currently, to workaround this issue I position another canvas on top of the video element. Then in the same requestAnimationFrame callback I execute drawImage on the canvas and the canvas on top of the video. This works pretty well. But when other things are happening on the main thread the video & ambilight canvasses are dropping frames, which is undesirable. To be clear, I don't know a perfect solution for this. But the goal for my application is to keep the canvas and video in sync with each other. Possible solution It could look like this in code:
|
@Yay295, here's the latest version of the spec, and you can raise any other issues on that github. The callbacks now always fire right before window.requestAnimationFrame(), after a new frame has been presented. We also pull the info for the last frame presented, right before running the callbacks. This means that if there were two frames presented between window.rAF calls, only the second would have its metadata surfaced via callbacks. If the code in the callback takes a long time to run, it should not delay frames from being displayed. It would be the same behavior as when a call to window.rAF takes a long time to execute (which can be tested via this demo. Chrome has a different composition path for videos, which allow them to play smoothly even if the page blocks up. It seems like Firefox has a similar mechanism too. @WesselKroos, part of the complexity of perfectly syncing a canvas and a video element in Chrome comes from the fact that videos have their own composition path. Blocking or buffering frames has a performance cost in cases where HW decoders have a limited frame buffer pool. Video.requestAnimationFrame won't be adding a way to synchronize paints on the main thread with video frames being presented on the compositor thread. I think the WebCodecs API will give you the opportunity to buffer frames yourself, but that also involves decoding the video yourself, instead of using HTMLVideoElement. |
If the function passed to
video.requestAnimationFrame
doesn't complete beforeexpectedPresentationTime
, will the frame still be presented, or would it be delayed until the function completes?The text was updated successfully, but these errors were encountered: