mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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:
1 parent
b3c6f35023
commit
7b07ddeefd
3 files changed
+106
-8
No files matched your search
@@ -217,7 +217,10 @@ seen every 250 ms of each segment (at most 1,200 times a segment), each tile
|
|||||||
the video its URL names for it (or one video over the layer's rectangle for a
|
the video its URL names for it (or one video over the layer's rectangle for a
|
||||||
`single-image` layer), seeked to the time's share of its length. A layer
|
`single-image` layer), seeked to the time's share of its length. A layer
|
||||||
keeps its 48 most recently seen tile videos; a tile waiting on one it lets
|
keeps its 48 most recently seen tile videos; a tile waiting on one it lets
|
||||||
go, or on a seek that takes over 10 s, fails rather than waiting. `frameReady`
|
go, or on a seek that takes over 10 s (60 s for the seek past its end that
|
||||||
|
learns the length of a video that does not state it), fails rather than
|
||||||
|
waiting; a video that failed to load is asked for afresh by the next tile, and
|
||||||
|
one still seeking is seeked again rather than drawn as it stands. `frameReady`
|
||||||
names the nearest frame's time once every globe tile drawn shows that
|
names the nearest frame's time once every globe tile drawn shows that
|
||||||
frame's own imagery (`src/render/cesium/imageryFrames.js`). The checks
|
frame's own imagery (`src/render/cesium/imageryFrames.js`). The checks
|
||||||
`globe.imagery.frames` and `globe.imagery.video` cover both.
|
`globe.imagery.frames` and `globe.imagery.video` cover both.
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ export const VIDEO_STEPS_MAX = 1200;
|
|||||||
export const VIDEO_CACHE = 48;
|
export const VIDEO_CACHE = 48;
|
||||||
/** How long a tile video's seek may take before its frame fails, ms. */
|
/** How long a tile video's seek may take before its frame fails, ms. */
|
||||||
export const VIDEO_SEEK_TIMEOUT_MS = 10000;
|
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
|
* 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
|
* 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
|
* 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
|
* 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) => {
|
return new Promise((resolve, reject) => {
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
@@ -140,7 +145,7 @@ function seekTo(video, time, url) {
|
|||||||
stop();
|
stop();
|
||||||
reject(new Error(`The video tile did not seek: ${url}`));
|
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 = () => {
|
const seeked = () => {
|
||||||
if (video.seeking) return;
|
if (video.seeking) return;
|
||||||
stop();
|
stop();
|
||||||
@@ -202,10 +207,14 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
// seeked past its end once to learn it.
|
// seeked past its end once to learn it.
|
||||||
const ready = loaded.then(async () => {
|
const ready = loaded.then(async () => {
|
||||||
if (!Number.isFinite(video.duration))
|
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;
|
return video;
|
||||||
});
|
});
|
||||||
ready.catch(() => {});
|
|
||||||
video.src = url;
|
video.src = url;
|
||||||
let releaseWith;
|
let releaseWith;
|
||||||
const gone = new Promise((_, reject) => {
|
const gone = new Promise((_, reject) => {
|
||||||
@@ -221,6 +230,14 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
released: false,
|
released: false,
|
||||||
};
|
};
|
||||||
videos.set(url, entry);
|
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) {
|
while (videos.size > limit) {
|
||||||
const [oldest, old] = videos.entries().next().value;
|
const [oldest, old] = videos.entries().next().value;
|
||||||
videos.delete(oldest);
|
videos.delete(oldest);
|
||||||
@@ -238,7 +255,9 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
const video = await until(entry.ready);
|
const video = await until(entry.ready);
|
||||||
const duration = Number.isFinite(video.duration) ? video.duration : 0;
|
const duration = Number.isFinite(video.duration) ? video.duration : 0;
|
||||||
const at = Math.max(0, Math.min(duration - 1e-3, fraction * duration));
|
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));
|
await until(seekTo(video, at, url));
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = video.videoWidth || 1;
|
canvas.width = video.videoWidth || 1;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
heldFrames,
|
heldFrames,
|
||||||
layerDrawn,
|
layerDrawn,
|
||||||
shownAt,
|
shownAt,
|
||||||
|
VIDEO_DURATION_TIMEOUT_MS,
|
||||||
VIDEO_SEEK_TIMEOUT_MS,
|
VIDEO_SEEK_TIMEOUT_MS,
|
||||||
VIDEO_STEP_MS,
|
VIDEO_STEP_MS,
|
||||||
videoProvider,
|
videoProvider,
|
||||||
@@ -167,9 +168,17 @@ function fakeVideoPage() {
|
|||||||
createElement(tag) {
|
createElement(tag) {
|
||||||
if (tag === 'canvas') return { getContext: () => ({ drawImage() {} }) };
|
if (tag === 'canvas') return { getContext: () => ({ drawImage() {} }) };
|
||||||
const target = new EventTarget();
|
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, {
|
const video = Object.assign(target, {
|
||||||
duration: NaN,
|
duration: NaN,
|
||||||
currentTime: 0,
|
|
||||||
seeking: false,
|
seeking: false,
|
||||||
videoWidth: 2,
|
videoWidth: 2,
|
||||||
videoHeight: 2,
|
videoHeight: 2,
|
||||||
@@ -225,3 +234,70 @@ test('a tile video seek that never ends fails its frame after the seek timeout',
|
|||||||
restore();
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in new issue
Block a user