mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Cesium imagery frames: a tile video whose seek timed out or failed is failed for the retry window like one that failed to load, so a url that always hangs is not waited on by every tile; expired failures are pruned and clear() forgets them
This commit is contained in:
1 parent
dbe026b109
commit
9549e561e5
2 files changed
+50
-9
No files matched your search
@@ -29,9 +29,9 @@ export const VIDEO_SEEK_TIMEOUT_MS = 10000;
|
|||||||
*/
|
*/
|
||||||
export const VIDEO_DURATION_TIMEOUT_MS = 60000;
|
export const VIDEO_DURATION_TIMEOUT_MS = 60000;
|
||||||
/**
|
/**
|
||||||
* How long a video that failed to load (or to say how long it is) fails its
|
* How long a video that failed to load (to say how long it is, or to seek)
|
||||||
* frames at once, ms, before it is loaded again: not downloaded afresh for
|
* fails its frames at once, ms, before it is loaded again: not downloaded
|
||||||
* every tile that asks.
|
* afresh for every tile that asks.
|
||||||
*/
|
*/
|
||||||
export const VIDEO_RETRY_MS = 180000;
|
export const VIDEO_RETRY_MS = 180000;
|
||||||
|
|
||||||
@@ -180,8 +180,18 @@ function seekTo(video, time, url, timeoutMs = VIDEO_SEEK_TIMEOUT_MS) {
|
|||||||
export function createTileVideos(limit = VIDEO_CACHE) {
|
export function createTileVideos(limit = VIDEO_CACHE) {
|
||||||
/** url → {video, ready: Promise, queue: Promise, gone: Promise, release} */
|
/** url → {video, ready: Promise, queue: Promise, gone: Promise, release} */
|
||||||
const videos = new Map();
|
const videos = new Map();
|
||||||
/** url → when a video that failed to load may be loaded again, epoch ms. */
|
/**
|
||||||
|
* url → when a video that failed to load (or to seek) may be loaded again,
|
||||||
|
* epoch ms; pruned as it is added to.
|
||||||
|
*/
|
||||||
const failed = new Map();
|
const failed = new Map();
|
||||||
|
/** Fail a url's frames at once for `VIDEO_RETRY_MS`. */
|
||||||
|
function fail(url) {
|
||||||
|
const now = Date.now();
|
||||||
|
for (const [other, retryAt] of failed)
|
||||||
|
if (retryAt <= now) failed.delete(other);
|
||||||
|
failed.set(url, now + VIDEO_RETRY_MS);
|
||||||
|
}
|
||||||
/** Let go of a url's video, if `entry` is still the one it holds. */
|
/** Let go of a url's video, if `entry` is still the one it holds. */
|
||||||
function drop(url, entry) {
|
function drop(url, entry) {
|
||||||
if (videos.get(url) !== entry) return;
|
if (videos.get(url) !== entry) return;
|
||||||
@@ -249,7 +259,7 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
const loadedEntry = entry;
|
const loadedEntry = entry;
|
||||||
ready.catch(() => {
|
ready.catch(() => {
|
||||||
if (videos.get(url) !== loadedEntry) return;
|
if (videos.get(url) !== loadedEntry) return;
|
||||||
failed.set(url, Date.now() + VIDEO_RETRY_MS);
|
fail(url);
|
||||||
drop(url, loadedEntry);
|
drop(url, loadedEntry);
|
||||||
});
|
});
|
||||||
while (videos.size > limit) {
|
while (videos.size > limit) {
|
||||||
@@ -283,8 +293,11 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
try {
|
try {
|
||||||
await until(seekTo(video, at, url));
|
await until(seekTo(video, at, url));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// A video whose seek did not end is let go: the next frame asked
|
// A video whose seek did not end (or failed) is let go and, like
|
||||||
// of it loads a fresh one rather than waiting on this one again.
|
// one that failed to load, loaded again only after
|
||||||
|
// `VIDEO_RETRY_MS`: a url that always hangs is not waited on by
|
||||||
|
// every tile that asks. One let go meanwhile has not failed.
|
||||||
|
if (!entry.released) fail(url);
|
||||||
drop(url, entry);
|
drop(url, entry);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -302,6 +315,7 @@ export function createTileVideos(limit = VIDEO_CACHE) {
|
|||||||
clear() {
|
clear() {
|
||||||
for (const [url, entry] of videos) release(entry, url);
|
for (const [url, entry] of videos) release(entry, url);
|
||||||
videos.clear();
|
videos.clear();
|
||||||
|
failed.clear();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,9 +247,9 @@ const endSeek = (video) => {
|
|||||||
video.dispatchEvent(new Event('seeked'));
|
video.dispatchEvent(new Event('seeked'));
|
||||||
};
|
};
|
||||||
|
|
||||||
test('after a seek that timed out, the next frame loads a fresh video rather than drawing what shows', async () => {
|
test('after a seek that timed out, the video is not loaded again for a while, then afresh rather than drawing what shows', async () => {
|
||||||
const { made, restore } = fakeVideoPage();
|
const { made, restore } = fakeVideoPage();
|
||||||
mock.timers.enable({ apis: ['setTimeout'] });
|
mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
||||||
try {
|
try {
|
||||||
const videos = createTileVideos(4);
|
const videos = createTileVideos(4);
|
||||||
const first = videos.frame('a.webm', 0.5);
|
const first = videos.frame('a.webm', 0.5);
|
||||||
@@ -260,6 +260,10 @@ test('after a seek that timed out, the next frame loads a fresh video rather tha
|
|||||||
mock.timers.tick(VIDEO_SEEK_TIMEOUT_MS);
|
mock.timers.tick(VIDEO_SEEK_TIMEOUT_MS);
|
||||||
await assert.rejects(first, /did not seek/);
|
await assert.rejects(first, /did not seek/);
|
||||||
assert.equal(made[0].src, '', 'the stuck video is let go');
|
assert.equal(made[0].src, '', 'the stuck video is let go');
|
||||||
|
// Asked again soon: failed at once, never waited on for another timeout.
|
||||||
|
await assert.rejects(videos.frame('a.webm', 0.5), /failed to load lately/);
|
||||||
|
assert.equal(made.length, 1, 'not loaded again');
|
||||||
|
mock.timers.tick(VIDEO_RETRY_MS);
|
||||||
let drawn = false;
|
let drawn = false;
|
||||||
const second = videos.frame('a.webm', 0.5).then(() => (drawn = true));
|
const second = videos.frame('a.webm', 0.5).then(() => (drawn = true));
|
||||||
assert.equal(made.length, 2, 'a fresh video');
|
assert.equal(made.length, 2, 'a fresh video');
|
||||||
@@ -276,6 +280,29 @@ test('after a seek that timed out, the next frame loads a fresh video rather tha
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('clear forgets the videos that failed, so each is loaded again at once', async () => {
|
||||||
|
const { made, restore } = fakeVideoPage();
|
||||||
|
mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
||||||
|
try {
|
||||||
|
const videos = createTileVideos(4);
|
||||||
|
const first = videos.frame('a.webm', 0.5);
|
||||||
|
made[0].dispatchEvent(new Event('error'));
|
||||||
|
await assert.rejects(first, /did not load/);
|
||||||
|
await assert.rejects(videos.frame('a.webm', 0.5), /failed to load lately/);
|
||||||
|
videos.clear();
|
||||||
|
const again = videos.frame('a.webm', 0.5);
|
||||||
|
assert.equal(made.length, 2, 'loaded again');
|
||||||
|
made[1].duration = 10;
|
||||||
|
made[1].dispatchEvent(new Event('loadeddata'));
|
||||||
|
await flush();
|
||||||
|
endSeek(made[1]);
|
||||||
|
assert.ok(await again);
|
||||||
|
} finally {
|
||||||
|
mock.timers.reset();
|
||||||
|
restore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('a video’s length is learnt with a longer wait, and a failed one is not loaded again for a while', async () => {
|
test('a video’s length is learnt with a longer wait, and a failed one is not loaded again for a while', async () => {
|
||||||
const { made, restore } = fakeVideoPage();
|
const { made, restore } = fakeVideoPage();
|
||||||
mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
||||||
|
|||||||
Reference in new issue
Block a user