Cesium imageryFrames: a timed-out seek is not drawn as done, and a failed video is not kept

After a seek timed out its video already had the target time, so the next
frame skipped seeking and drew whatever showed as a finished tile; a video
still seeking is now seeked again. The seek past its end that learns a
video's length waits 60 s, not the 10 s of a frame's seek, and a video whose
load or length probe failed is dropped, so the next frame starts over
instead of failing until the video is evicted.
This commit is contained in:
Sameh Khamis committed 2026-11-11 20:03:20 -08:00
1 parent b3c6f35023
commit 7b07ddeefd
3 files changed
+106 -8

No files matched your search

+25 -6
View File
@@ -23,6 +23,11 @@ export const VIDEO_STEPS_MAX = 1200;
export const VIDEO_CACHE = 48;
/** How long a tile video's seek may take before its frame fails, ms. */
export const VIDEO_SEEK_TIMEOUT_MS = 10000;
/**
* How long the seek past its end that learns a video's length may take, ms:
* it may read the whole video first.
*/
export const VIDEO_DURATION_TIMEOUT_MS = 60000;
/**
* The frames of a timed source, in time order: `{time, url}`, and for
@@ -127,9 +132,9 @@ function tileUrlOf(template, tilingScheme, x, y, level) {
* Seek a video, resolving once it has: on a `seeked` that leaves it no
* longer seeking (one a seek before it sends late does not count), and its
* frame there presented where the browser says so. Rejects on an error, or
* after `VIDEO_SEEK_TIMEOUT_MS` with no seek.
* after `timeoutMs` with no seek.
*/
function seekTo(video, time, url) {
function seekTo(video, time, url, timeoutMs = VIDEO_SEEK_TIMEOUT_MS) {
return new Promise((resolve, reject) => {
const stop = () => {
clearTimeout(timeout);
@@ -140,7 +145,7 @@ function seekTo(video, time, url) {
stop();
reject(new Error(`The video tile did not seek: ${url}`));
};
const timeout = setTimeout(failed, VIDEO_SEEK_TIMEOUT_MS);
const timeout = setTimeout(failed, timeoutMs);
const seeked = () => {
if (video.seeking) return;
stop();
@@ -202,10 +207,14 @@ export function createTileVideos(limit = VIDEO_CACHE) {
// seeked past its end once to learn it.
const ready = loaded.then(async () => {
if (!Number.isFinite(video.duration))
await seekTo(video, Number.MAX_SAFE_INTEGER, url);
await seekTo(
video,
Number.MAX_SAFE_INTEGER,
url,
VIDEO_DURATION_TIMEOUT_MS,
);
return video;
});
ready.catch(() => {});
video.src = url;
let releaseWith;
const gone = new Promise((_, reject) => {
@@ -221,6 +230,14 @@ export function createTileVideos(limit = VIDEO_CACHE) {
released: false,
};
videos.set(url, entry);
// A video that failed to load (or to say how long it is) is not kept:
// the next frame asked of it starts over.
const loadedEntry = entry;
ready.catch(() => {
if (videos.get(url) !== loadedEntry) return;
videos.delete(url);
release(loadedEntry, url);
});
while (videos.size > limit) {
const [oldest, old] = videos.entries().next().value;
videos.delete(oldest);
@@ -238,7 +255,9 @@ export function createTileVideos(limit = VIDEO_CACHE) {
const video = await until(entry.ready);
const duration = Number.isFinite(video.duration) ? video.duration : 0;
const at = Math.max(0, Math.min(duration - 1e-3, fraction * duration));
if (Math.abs(video.currentTime - at) > 1e-4)
// Still seeking (a seek that timed out may have set the time without
// ever ending): seeked again, never drawn as it stands.
if (video.seeking || Math.abs(video.currentTime - at) > 1e-4)
await until(seekTo(video, at, url));
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth || 1;
+77 -1
View File
@@ -7,6 +7,7 @@ import {
heldFrames,
layerDrawn,
shownAt,
VIDEO_DURATION_TIMEOUT_MS,
VIDEO_SEEK_TIMEOUT_MS,
VIDEO_STEP_MS,
videoProvider,
@@ -167,9 +168,17 @@ function fakeVideoPage() {
createElement(tag) {
if (tag === 'canvas') return { getContext: () => ({ drawImage() {} }) };
const target = new EventTarget();
let time = 0;
// Setting the time starts a seek, which the test ends (`seeked`).
Object.defineProperty(target, 'currentTime', {
get: () => time,
set: (t) => {
time = t;
target.seeking = true;
},
});
const video = Object.assign(target, {
duration: NaN,
currentTime: 0,
seeking: false,
videoWidth: 2,
videoHeight: 2,
@@ -225,3 +234,70 @@ test('a tile video seek that never ends fails its frame after the seek timeout',
restore();
}
});
/** Let promise callbacks run. */
const flush = async () => {
for (let i = 0; i < 10; i++) await Promise.resolve();
};
/** End a fake video's seek. */
const endSeek = (video) => {
video.seeking = false;
video.dispatchEvent(new Event('seeked'));
};
test('after a seek that timed out, the next frame seeks again rather than drawing what shows', async () => {
const { made, restore } = fakeVideoPage();
mock.timers.enable({ apis: ['setTimeout'] });
try {
const videos = createTileVideos(4);
const first = videos.frame('a.webm', 0.5);
first.catch(() => {});
made[0].duration = 10;
made[0].dispatchEvent(new Event('loadeddata'));
await flush();
mock.timers.tick(VIDEO_SEEK_TIMEOUT_MS);
await assert.rejects(first, /did not seek/);
// Its time is the target, but it never got there.
let drawn = false;
const second = videos.frame('a.webm', 0.5).then(() => (drawn = true));
await flush();
assert.equal(drawn, false, 'waits for its own seek');
endSeek(made[0]);
await second;
assert.equal(drawn, true);
} finally {
mock.timers.reset();
restore();
}
});
test('a video’s length is learnt with a longer wait, and a failed one is not kept', async () => {
const { made, restore } = fakeVideoPage();
mock.timers.enable({ apis: ['setTimeout'] });
try {
const videos = createTileVideos(4);
let failed = null;
videos.frame('a.webm', 0.5).catch((error) => (failed = error));
// No duration: it seeks past its end to learn it.
made[0].dispatchEvent(new Event('loadeddata'));
await flush();
mock.timers.tick(VIDEO_SEEK_TIMEOUT_MS);
await flush();
assert.equal(failed, null, 'not on the short seek wait');
mock.timers.tick(VIDEO_DURATION_TIMEOUT_MS);
await flush();
assert.match(String(failed), /did not seek/);
// Asked again: a fresh video, which loads this time.
const again = videos.frame('a.webm', 0.5);
assert.equal(made.length, 2, 'started over');
made[1].duration = 10;
made[1].dispatchEvent(new Event('loadeddata'));
await flush();
endSeek(made[1]);
assert.ok(await again);
} finally {
mock.timers.reset();
restore();
}
});