Land a driven video's seek without a frame so it is never empty (#404)
game-maker / gate (push) Successful in 4m9s
game-maker / suite (push) Successful in 17m18s

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:
adminandClaude Opus 5.5 committed 2026-10-11 19:04:40 +02:00
1 parent 8118b8042b
commit 36ffd9a61a
4 files changed
+110 -18

No files matched your search

+58
View File
@@ -1,3 +1,4 @@
import type * as Pixi from 'pixi.js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
/**
@@ -6,6 +7,17 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
* sweeper's timer goes on; a sprite still wearing the video lost it and Pixi warned about the
* destroyed source on the way back.
*/
// Pixi's own video source reads the page as it is made; a plain source stands in for it.
vi.mock('pixi.js', async (load) => {
const pixi = await load<typeof Pixi>();
class VideoSource extends pixi.TextureSource {
constructor() {
super({ width: 320, height: 180 });
}
}
return { ...pixi, VideoSource };
});
const KEY = `video:a1b2c3d4e5f6/${'c7'.repeat(32)}.mp4#0~0~1~1`;
let videosMade = 0;
@@ -155,6 +167,52 @@ describe('VideoLibrary driven players (#404)', () => {
expect(videos.debugInfo()[0]!.speed).toBeCloseTo(1, 6);
});
it('lands a seek that Chrome hands over no frame for', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'setInterval', 'clearInterval'] });
const events = new Map<string, (() => void)[]>();
let frames: (() => void)[] = [];
const element = {
...fakeVideo(),
seeking: false,
ended: false,
duration: 2,
playbackRate: 1,
readyState: 4,
videoWidth: 320,
videoHeight: 180,
at: 0,
get currentTime() {
return this.at;
},
set currentTime(time: number) {
this.at = time;
this.seeking = true;
},
addEventListener: (type: string, listener: () => void) =>
events.set(type, [...(events.get(type) ?? []), listener]),
requestVideoFrameCallback: (callback: () => void) => frames.push(callback),
};
const fire = (type: string) => events.get(type)?.forEach((listener) => listener());
const seekDone = () => {
element.seeking = false;
fire('seeked');
};
vi.stubGlobal('document', { hidden: false, addEventListener: () => {}, createElement: () => element });
const videos = await freshLibrary();
const key = videos.wear(REF, { videoClock: 'driven', videoTime: 0.5 }, 'view1:a', false).file;
fire('loadeddata');
seekDone();
[frames] = [[], ...frames.map((frame) => frame())];
expect(videos.showsAsked(key)).toBe(true);
// Switched on at 1.2 s: the seek is done, and no frame follows it.
videos.wear(REF, { videoClock: 'driven', videoTime: 1.2 }, 'view1:a', false);
expect(videos.showsAsked(key)).toBe(false);
seekDone();
vi.advanceTimersByTime(200);
vi.useRealTimers();
expect(videos.showsAsked(key)).toBe(true);
});
it('tells a view whether one of its driven players still waits for its first picture', async () => {
const videos = await freshLibrary();
videos.get(KEY);