Land a driven video's seek without a frame so it is never empty (#404)
Since b9fcf48 a seek of a driven video only counted as done once
Chrome handed over the next frame. For some seeks Chrome hands over
none. The player then waited for good, the view left the sprite out
after 0.3 s, and the picture stayed empty until the next jump.
- A seek now lands after `seeked` with the next frame, or after
150 ms at the latest. The worst case is a picture 150 ms late.
- The landing is set up in the `seeked` handler instead of `seek`.
A frame from before the last seek of a chase no longer counts.
- `__gm.videos()` reports `landing`, so an empty picture can be told
apart from a player that is still loading.
Findings:
- The empty picture could not be reproduced in Chrome headless.
The test video is 320x180 and decoded in software. The user's
videos are 1080p60 H.264, likely decoded in hardware.
- The user confirmed the fix in the editor.
Tests:
- Unit video-library + video-follow: 20 green (1 new). The new test
plays a video that hands over no frame after a seek. With the old
code it stays not ready, so it fails.
- e2e 66 on melektaus-atx: ALL PASSED, 29 checks. The new 66r cuts
LATE ten times quickly and was also green with the old code.
- Gate on melektaus-atx: CHECK EXIT 0, 297 files, 4563 tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8118b8042b
commit
36ffd9a61a
4 files changed
+110
-18
No files matched your search
@@ -33,6 +33,8 @@ const END_SLACK = 1 / 60;
|
||||
const IDLE_MS = 2000;
|
||||
/** Closer than this a seek that waited for the one before it is not worth another. */
|
||||
const SEEK_SLACK = 1 / 120;
|
||||
/** How long after `seeked` a seek counts as landed when Chrome hands over no frame for it. */
|
||||
const LAND_MS = 150;
|
||||
/** How long a run waits at its start for the driven videos it shows (#404) before it goes anyway. */
|
||||
export const VIDEO_WAIT_MS = 3000;
|
||||
|
||||
@@ -204,27 +206,14 @@ export class VideoLibrary {
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks, or, while a seek is still running, remembers the newest wish for when it is done. The
|
||||
* seek has landed with the first frame Chrome hands over once all of them are done: at `seeked`
|
||||
* the picture was not there yet, and Pixi, which loads a paused video's picture only then, kept
|
||||
* the one before it for a frame.
|
||||
* Seeks, or, while a seek is still running, remembers the newest wish for when it is done. It has
|
||||
* landed once the last of them is done, see `chase`.
|
||||
*/
|
||||
private seek(player: Player, drive: Drive, time: number): void {
|
||||
const { element } = player;
|
||||
if (element.seeking) drive.wanted = time;
|
||||
else element.currentTime = time;
|
||||
if (drive.landing) return;
|
||||
drive.landing = true;
|
||||
const land = () => {
|
||||
if (player.gone) return;
|
||||
if (element.seeking || drive.wanted !== null) {
|
||||
element.requestVideoFrameCallback(land);
|
||||
return;
|
||||
}
|
||||
player.texture?.source.update();
|
||||
drive.landing = false;
|
||||
};
|
||||
element.requestVideoFrameCallback(land);
|
||||
}
|
||||
|
||||
/** Lets every player go: a session that ends takes its videos along. */
|
||||
@@ -266,6 +255,8 @@ export class VideoLibrary {
|
||||
seeking: boolean;
|
||||
/** How fast its wearer's time runs, as read for a driven player; 0 for a free one. */
|
||||
speed: number;
|
||||
/** Whether a driven player still waits for the picture of a seek, see `seek`. */
|
||||
landing: boolean;
|
||||
}[] {
|
||||
return [...this.players].map(([key, { element, texture, drive }]) => ({
|
||||
key,
|
||||
@@ -276,6 +267,7 @@ export class VideoLibrary {
|
||||
rate: element.playbackRate,
|
||||
seeking: element.seeking,
|
||||
speed: drive?.reading?.speed ?? 0,
|
||||
landing: drive?.landing ?? false,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -313,14 +305,33 @@ export class VideoLibrary {
|
||||
return player;
|
||||
}
|
||||
|
||||
/** Once a seek is done, the newest one asked for meanwhile follows. */
|
||||
/**
|
||||
* Once a seek is done, the newest one asked for meanwhile follows. When none does, the seek lands
|
||||
* with the next frame Chrome hands over: at `seeked` the picture was not there yet, and Pixi, which
|
||||
* loads a paused video's picture only then, kept the one before it for a frame. Chrome hands over
|
||||
* no frame for some seeks, though, and a player waiting for one stayed empty until the next jump;
|
||||
* after `LAND_MS` it lands without.
|
||||
*/
|
||||
private chase(player: Player, drive: Drive): void {
|
||||
const { element } = player;
|
||||
let round = 0;
|
||||
element.addEventListener('seeked', () => {
|
||||
if (player.gone) return;
|
||||
const wanted = drive.wanted;
|
||||
drive.wanted = null;
|
||||
if (!player.gone && wanted !== null && Math.abs(wanted - element.currentTime) > SEEK_SLACK)
|
||||
if (wanted !== null && Math.abs(wanted - element.currentTime) > SEEK_SLACK) {
|
||||
element.currentTime = wanted;
|
||||
return;
|
||||
}
|
||||
if (!drive.landing) return;
|
||||
const now = ++round;
|
||||
const land = () => {
|
||||
if (player.gone || now !== round || element.seeking || !drive.landing) return;
|
||||
player.texture?.source.update();
|
||||
drive.landing = false;
|
||||
};
|
||||
element.requestVideoFrameCallback(land);
|
||||
setTimeout(land, LAND_MS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user