-
Notifications
You must be signed in to change notification settings - Fork 671
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
Simplify startPlayingAndWaitForVideo with modern async/await. #3319
Conversation
@dalecurtis do you think this mechanism will work reliably in Chromium? We've iterated on this primitive over and over in order to eliminate flakiness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is safe.
sdk/tests/js/webgl-test-utils.js
Outdated
video.preload = 'auto'; | ||
video.play(); | ||
(async () => { | ||
video.load(); // reset it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will trigger a significant amount of unnecessary work since a load is already in flight.
timeWatcher(); | ||
} else { | ||
// Calls video.requestVideoFrameCallback(_ => { callback(video) }) | ||
rvfc.call(video, _ => { callback(video) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be preserved since the play promise resolving doesn't mean that a frame can be drawn from it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it probably does mean this? (see comments in main thread)
sdk/tests/js/webgl-test-utils.js
Outdated
// See whether setting the preload flag de-flakes video-related tests. | ||
video.preload = 'auto'; | ||
try { | ||
await video.play(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is safe, see #3263 where I reverted this previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dalecurtis for your review.
At the specification level:
https://html.spec.whatwg.org/multipage/media.html#dom-media-play
is one issue that the play()
Promise can be resolved when the network state is still HAVE_FUTURE_DATA
? In other words, per spec, it's not guaranteed that data's available for the first frame when this Promise resolves?
Do we need to await on |
I think HAVE_FUTURE_DATA ought to be enough to ensure we can texImage(video). At worst this might causes a wait-for-decode, but the data is ready at least. |
image-bitmap-from-video failures are likely #3322. |
Big thanks for finding #3322 . The failures that were seen previously were more widespread, and included widespread conformance/textures/video failures: https://chromium-review.googlesource.com/c/chromium/src/+/2775887/5 e.g. https://ci.chromium.org/ui/p/chromium/builders/try/linux-rel/644735/overview so unfortunately this change is incompatible with Chromium's implementation of the HTMLVideoElement.play() spec, at least. |
I do think we sort of fall short here of defining what should happen and-then-therefore testing that. We need to define at what point calling texImage(video) should succeed, and what should happen otherwise. My intuition is that we should try to define it such that |
We've generally interpreted
Emphasis on "ready to be" mine. If we interpret that to mean the decoded frame must have been rendered, then significant load deferral optimizations for offscreen and/or autoplay-rejected videos are not possible. Which turns into a chicken or the egg problem since some sites won't try to play an element until HAVE_FUTURE_DATA.
|
I'm not sure we actually need the first frame to have been rendered in the general sense, though we should test that for sure. (gotta make sure the fastpaths work) For instance, we need to support videos that are never rendered to the screen, and only exist floating loose from the DOM, yet still play and can be uploaded into textures. |
By rendered I just meant decoded and available to script. rVFC() works for offscreen elements. In Chromium's implementation we let |
I think that |
Probably, I don't see any immediate perils, but as noted in #3319 (comment) it'll need some real world testing. Certainly simpler sounding things have ended up as very hairy yaks in the past :| |
FYI I recently ported startPlayingAndWaitForVideo into the WebGPU CTS. If any changes end up landing here I'd like to port them over too. |
…ted. Chrome needs this currently. Also make function async. TODO: Update callsites to use async instead of callback.
0de4f23
to
b0914ba
Compare
@dalecurtis PTAL |
} | ||
|
||
if (video.requestVideoFrameCallback) { | ||
await new Promise(go => video.requestVideoFrameCallback(go)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dalecurtis do you think this will have the same basic semantics as the earlier code in Chromium?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will have different semantics as I note in the comment thread below, but it should be okay % potential for minor slowness.
Thanks all! |
No description provided.