@hyperframes/studio 0.8.212 → 0.8.214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{hyperframes-player-DHfuW7Lt.js → hyperframes-player-H1DIJsJZ.js} +1 -1
- package/dist/assets/{index-CWgIsKzV.js → index-BftVE_0y.js} +119 -119
- package/dist/assets/{index-CkjUY33q.js → index-v_hWj6Kv.js} +1 -1
- package/dist/{chunk-HD6NXWGI.js → chunk-UNZTUFD7.js} +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.html +1 -1
- package/dist/index.js +1079 -846
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/hooks/timelineEditingHelpers.test.ts +25 -0
- package/src/hooks/timelineEditingHelpers.ts +17 -1
- package/src/player/hooks/previewMessageRouter.test.ts +40 -0
- package/src/player/hooks/previewMessageRouter.ts +12 -0
- package/src/player/lib/mediaFetch.ts +7 -2
- package/src/player/lib/thumbnailDiskCache.test.ts +185 -0
- package/src/player/lib/thumbnailDiskCache.ts +223 -0
- package/src/player/lib/thumbnailSourcePool.ts +3 -1
- package/src/player/lib/thumbnailVideoDecoder.test.ts +79 -0
- package/src/player/lib/thumbnailVideoDecoder.ts +97 -3
- package/src/player/store/previewQualitySlice.ts +5 -0
|
@@ -16,6 +16,8 @@ const input = {
|
|
|
16
16
|
getPrimaryVideoTrack: vi.fn(),
|
|
17
17
|
dispose,
|
|
18
18
|
};
|
|
19
|
+
// The ETag the mocked server answers the reader's reads with; none unless a test sets one.
|
|
20
|
+
let servedEtag: string | undefined;
|
|
19
21
|
|
|
20
22
|
vi.mock("mediabunny", () => ({
|
|
21
23
|
ALL_FORMATS: {},
|
|
@@ -25,6 +27,7 @@ vi.mock("mediabunny", () => ({
|
|
|
25
27
|
readonly options?: { getRetryDelay?: unknown; cancelReads?: () => void },
|
|
26
28
|
) {
|
|
27
29
|
sourceRetryRules.push(typeof options?.getRetryDelay);
|
|
30
|
+
if (servedEtag && options) Object.assign(options, { etagOf: () => servedEtag });
|
|
28
31
|
// Spied where the pool reads it, after constructing the source.
|
|
29
32
|
if (options?.cancelReads)
|
|
30
33
|
cancelledReads.push((options.cancelReads = vi.fn(options.cancelReads)));
|
|
@@ -69,6 +72,8 @@ let sources = 0;
|
|
|
69
72
|
let source = "";
|
|
70
73
|
|
|
71
74
|
beforeEach(() => {
|
|
75
|
+
vi.unstubAllGlobals();
|
|
76
|
+
servedEtag = undefined;
|
|
72
77
|
source = `/clip-${++sources}.mp4`;
|
|
73
78
|
// Released frames outlive their test; evict them so each test counts only its own revokes.
|
|
74
79
|
releaseSharedFrames([], 0);
|
|
@@ -109,6 +114,26 @@ describe("videoThumbnailTimestamps", () => {
|
|
|
109
114
|
});
|
|
110
115
|
});
|
|
111
116
|
|
|
117
|
+
/** Cache Storage as a Map of Maps, empty, with an empty index: what a browser keeps across sessions. */
|
|
118
|
+
function stubCacheStorage(): Map<string, Map<string, Response>> {
|
|
119
|
+
const stores = new Map<string, Map<string, Response>>();
|
|
120
|
+
vi.stubGlobal("caches", {
|
|
121
|
+
open: async (name: string) => {
|
|
122
|
+
const store = stores.get(name) ?? new Map<string, Response>();
|
|
123
|
+
stores.set(name, store);
|
|
124
|
+
return {
|
|
125
|
+
match: async (url: string) => store.get(url)?.clone(),
|
|
126
|
+
put: async (url: string, response: Response) => void store.set(url, response),
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
has: async (name: string) => stores.has(name),
|
|
130
|
+
keys: async () => [...stores.keys()],
|
|
131
|
+
delete: async (name: string) => stores.delete(name),
|
|
132
|
+
});
|
|
133
|
+
localStorage.clear();
|
|
134
|
+
return stores;
|
|
135
|
+
}
|
|
136
|
+
|
|
112
137
|
describe("decodeVideoThumbnail", () => {
|
|
113
138
|
it("extracts sparse frames, returns object URLs, and disposes once", async () => {
|
|
114
139
|
const decoded: number[][] = [];
|
|
@@ -927,4 +952,58 @@ describe("decodeVideoThumbnail's shared source", () => {
|
|
|
927
952
|
// A UrlSource counts its own retries (mediaUrlSourceOptions), so a fresh one retries afresh.
|
|
928
953
|
expect(sourceRetryRules).toEqual(["function", "function"]);
|
|
929
954
|
});
|
|
955
|
+
|
|
956
|
+
it("paints a strip from a past session's frames on disk, without opening the file", async () => {
|
|
957
|
+
const stores = stubCacheStorage();
|
|
958
|
+
const signal = new AbortController().signal;
|
|
959
|
+
servedEtag = '"take-v1"';
|
|
960
|
+
recordDecodes([]);
|
|
961
|
+
const request = { source, sourceStart: 0, sourceRangeDuration: 4, frameCount: 2 };
|
|
962
|
+
await decodeVideoThumbnail({ ...request, contentVersion: "session-1" }, signal);
|
|
963
|
+
// the source's facts and its three frames, then the index the next session reads
|
|
964
|
+
await vi.waitFor(() => expect([...stores.values()][0]?.size).toBe(4));
|
|
965
|
+
await vi.waitFor(
|
|
966
|
+
() => expect(localStorage.getItem("hf-thumbnails-index")).toContain("take-v1"),
|
|
967
|
+
{
|
|
968
|
+
timeout: 3000,
|
|
969
|
+
},
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
vi.resetModules();
|
|
973
|
+
const nextSession = await import("./thumbnailVideoDecoder");
|
|
974
|
+
const validate = vi.fn(async () => new Response(null, { status: 304 }));
|
|
975
|
+
vi.stubGlobal("fetch", validate);
|
|
976
|
+
input.getPrimaryVideoTrack.mockClear();
|
|
977
|
+
canvasesAtTimestamps.mockClear();
|
|
978
|
+
const result = await nextSession.decodeVideoThumbnail(
|
|
979
|
+
{ ...request, contentVersion: "session-2" },
|
|
980
|
+
signal,
|
|
981
|
+
);
|
|
982
|
+
|
|
983
|
+
expect(validate).toHaveBeenCalledTimes(1);
|
|
984
|
+
expect(input.getPrimaryVideoTrack).not.toHaveBeenCalled();
|
|
985
|
+
expect(canvasesAtTimestamps).not.toHaveBeenCalled();
|
|
986
|
+
expect(result.value).toMatchObject({ kind: "filmstrip" });
|
|
987
|
+
expect((result.value as { urls: string[] }).urls).toHaveLength(3);
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
it("checks the file again when a project opens anew, so a replaced video never paints its old frames", async () => {
|
|
991
|
+
const stores = stubCacheStorage();
|
|
992
|
+
const signal = new AbortController().signal;
|
|
993
|
+
servedEtag = '"v1"';
|
|
994
|
+
recordDecodes([]);
|
|
995
|
+
const request = { source, sourceStart: 0, sourceRangeDuration: 4, frameCount: 2 };
|
|
996
|
+
await decodeVideoThumbnail({ ...request, contentVersion: "open-1" }, signal);
|
|
997
|
+
await vi.waitFor(() => expect([...stores.values()][0]?.size).toBe(4));
|
|
998
|
+
|
|
999
|
+
// the video is replaced at the same path, then its project opened again in this page
|
|
1000
|
+
servedEtag = '"v2"';
|
|
1001
|
+
vi.stubGlobal(
|
|
1002
|
+
"fetch",
|
|
1003
|
+
vi.fn(async () => new Response("x", { status: 206, headers: { ETag: '"v2"' } })),
|
|
1004
|
+
);
|
|
1005
|
+
await decodeVideoThumbnail({ ...request, contentVersion: "open-2" }, signal);
|
|
1006
|
+
|
|
1007
|
+
expect(input.getPrimaryVideoTrack).toHaveBeenCalledTimes(2);
|
|
1008
|
+
});
|
|
930
1009
|
});
|
|
@@ -17,6 +17,15 @@ import {
|
|
|
17
17
|
takeSharedFrame,
|
|
18
18
|
type HeldFrame,
|
|
19
19
|
} from "./thumbnailFrameCache";
|
|
20
|
+
import {
|
|
21
|
+
readStoredFrame,
|
|
22
|
+
readStoredInfo,
|
|
23
|
+
rememberVersion,
|
|
24
|
+
storedVersion,
|
|
25
|
+
storeFrame,
|
|
26
|
+
storeInfo,
|
|
27
|
+
type StoredSource,
|
|
28
|
+
} from "./thumbnailDiskCache";
|
|
20
29
|
|
|
21
30
|
export interface VideoThumbnailDecodeRequest {
|
|
22
31
|
source: string;
|
|
@@ -52,6 +61,17 @@ interface FrameWindow {
|
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
const sourceInfos = new Map<string, { version: string | undefined; info: SourceInfo }>();
|
|
64
|
+
const storedVersions = new Map<string, Promise<StoredSource | undefined>>();
|
|
65
|
+
const storedInfos = new Set<string>();
|
|
66
|
+
|
|
67
|
+
const openOf = (request: VideoThumbnailDecodeRequest) =>
|
|
68
|
+
`${request.source}\u0000${request.contentVersion ?? ""}`;
|
|
69
|
+
|
|
70
|
+
function storedVersionOf(request: VideoThumbnailDecodeRequest): Promise<StoredSource | undefined> {
|
|
71
|
+
let pending = storedVersions.get(openOf(request));
|
|
72
|
+
if (!pending) storedVersions.set(openOf(request), (pending = storedVersion(request.source)));
|
|
73
|
+
return pending;
|
|
74
|
+
}
|
|
55
75
|
|
|
56
76
|
const accepts = (window: FrameWindow, time: number, decodedAt: number) =>
|
|
57
77
|
decodedAt >= window.sourceStart && time - decodedAt <= (time >= window.end ? 0 : window.lead);
|
|
@@ -79,6 +99,7 @@ interface DecodedResources {
|
|
|
79
99
|
held: HeldFrame[];
|
|
80
100
|
canvases: Set<HTMLCanvasElement | OffscreenCanvas>;
|
|
81
101
|
releasedFrameBytes: number;
|
|
102
|
+
store?: (slot: number, decodedAt: number, blob: Blob) => void;
|
|
82
103
|
}
|
|
83
104
|
|
|
84
105
|
interface ThumbnailCanvasSink {
|
|
@@ -186,6 +207,7 @@ async function decodeFrames(
|
|
|
186
207
|
throwIfAborted(signal);
|
|
187
208
|
const frame = shareFrame(target.key, target.decodedAt, URL.createObjectURL(blob), blob.size);
|
|
188
209
|
progress.framesFromAnyJob += 1;
|
|
210
|
+
resources.store?.(target.slot, target.decodedAt, blob);
|
|
189
211
|
resources.urls[target.slot] = frame.url;
|
|
190
212
|
resources.held.push({ key: target.key, frame });
|
|
191
213
|
}
|
|
@@ -218,6 +240,64 @@ function loadedResult(
|
|
|
218
240
|
};
|
|
219
241
|
}
|
|
220
242
|
|
|
243
|
+
const storedFrameName =
|
|
244
|
+
(fit: string, info: SourceInfo, budgets: Readonly<TimelineViewportBudgets>) => (time: number) => {
|
|
245
|
+
const { width, height } = targetDimensions(info.aspect, budgets);
|
|
246
|
+
return `${fit} ${width}x${height} ${time}`;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
async function takeStoredFrames(
|
|
250
|
+
{ timestamps, window }: ReturnType<typeof stripTimes>,
|
|
251
|
+
slots: number[],
|
|
252
|
+
keyOf: (time: number) => string,
|
|
253
|
+
nameOf: (time: number) => string,
|
|
254
|
+
resources: DecodedResources,
|
|
255
|
+
stored: StoredSource,
|
|
256
|
+
): Promise<number[]> {
|
|
257
|
+
const found = await Promise.all(
|
|
258
|
+
slots.map((slot) => readStoredFrame(stored, nameOf(timestamps[slot]!))),
|
|
259
|
+
);
|
|
260
|
+
return slots.filter((slot, i) => {
|
|
261
|
+
const time = timestamps[slot]!;
|
|
262
|
+
const hit = found[i];
|
|
263
|
+
if (!hit || !accepts(window, time, hit.decodedAt)) return true;
|
|
264
|
+
const key = keyOf(time);
|
|
265
|
+
const frame = shareFrame(key, hit.decodedAt, URL.createObjectURL(hit.blob), hit.blob.size);
|
|
266
|
+
resources.urls[slot] = frame.url;
|
|
267
|
+
resources.held.push({ key, frame });
|
|
268
|
+
return false;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function versionRead(
|
|
273
|
+
request: VideoThumbnailDecodeRequest,
|
|
274
|
+
source: ThumbnailSource,
|
|
275
|
+
): StoredSource | undefined {
|
|
276
|
+
if (!source.etag) return undefined;
|
|
277
|
+
const version = { source: request.source, etag: source.etag };
|
|
278
|
+
storedVersions.set(openOf(request), Promise.resolve(version));
|
|
279
|
+
return version;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function storeForNextSession(
|
|
283
|
+
request: VideoThumbnailDecodeRequest,
|
|
284
|
+
info: SourceInfo,
|
|
285
|
+
budgets: Readonly<TimelineViewportBudgets>,
|
|
286
|
+
resources: DecodedResources,
|
|
287
|
+
version: StoredSource | undefined,
|
|
288
|
+
): void {
|
|
289
|
+
if (!version) return;
|
|
290
|
+
const id = `${version.source}\u0000${version.etag}`;
|
|
291
|
+
if (!storedInfos.has(id)) {
|
|
292
|
+
storedInfos.add(id);
|
|
293
|
+
void rememberVersion(version).then(() => storeInfo(version, info));
|
|
294
|
+
}
|
|
295
|
+
const nameOf = storedFrameName(request.fit ?? "cover", info, budgets);
|
|
296
|
+
const { timestamps } = stripTimes(request, info, budgets);
|
|
297
|
+
resources.store = (slot, decodedAt, blob) =>
|
|
298
|
+
void storeFrame(version, nameOf(timestamps[slot]!), decodedAt, blob);
|
|
299
|
+
}
|
|
300
|
+
|
|
221
301
|
/** Sparse Mediabunny extraction with one pooled canvas and one cleanup owner. */
|
|
222
302
|
export async function decodeVideoThumbnail(
|
|
223
303
|
request: VideoThumbnailDecodeRequest,
|
|
@@ -234,16 +314,28 @@ export async function decodeVideoThumbnail(
|
|
|
234
314
|
releasedFrameBytes: budgets.sharedFrameCacheBytes,
|
|
235
315
|
};
|
|
236
316
|
const entry = sourceInfos.get(request.source);
|
|
237
|
-
const known = entry?.version === request.contentVersion ? entry?.info : undefined;
|
|
238
317
|
try {
|
|
318
|
+
const stored = await storedVersionOf(request);
|
|
319
|
+
const known =
|
|
320
|
+
entry && entry.version === request.contentVersion
|
|
321
|
+
? entry.info
|
|
322
|
+
: stored && (await readStoredInfo(stored));
|
|
239
323
|
if (known) {
|
|
240
|
-
|
|
324
|
+
sourceInfos.set(request.source, { version: request.contentVersion, info: known });
|
|
325
|
+
const strip = stripTimes(request, known, budgets);
|
|
326
|
+
const missing = takeDecodedFrames(strip, keyOf, resources);
|
|
327
|
+
const nameOf = storedFrameName(fit, known, budgets);
|
|
328
|
+
const left =
|
|
329
|
+
stored && missing.length > 0
|
|
330
|
+
? await takeStoredFrames(strip, missing, keyOf, nameOf, resources, stored)
|
|
331
|
+
: missing;
|
|
332
|
+
if (left.length === 0) {
|
|
241
333
|
throwIfAborted(signal);
|
|
242
334
|
return loadedResult(resources, known.aspect, budgets);
|
|
243
335
|
}
|
|
244
336
|
releaseDecodedResources(resources);
|
|
245
337
|
}
|
|
246
|
-
return await decodeMissingFrames(request, signal, budgets, keyOf, resources);
|
|
338
|
+
return await decodeMissingFrames(request, signal, budgets, keyOf, resources, stored);
|
|
247
339
|
} catch (error) {
|
|
248
340
|
releaseDecodedResources(resources);
|
|
249
341
|
reportMediaFetchFailure(error);
|
|
@@ -257,6 +349,7 @@ async function decodeMissingFrames(
|
|
|
257
349
|
budgets: Readonly<TimelineViewportBudgets>,
|
|
258
350
|
keyOf: (time: number) => string,
|
|
259
351
|
resources: DecodedResources,
|
|
352
|
+
stored: StoredSource | undefined,
|
|
260
353
|
): Promise<ThumbnailLoadedResult> {
|
|
261
354
|
let source: ThumbnailSource;
|
|
262
355
|
try {
|
|
@@ -284,6 +377,7 @@ async function decodeMissingFrames(
|
|
|
284
377
|
sourceInfos.set(request.source, { version: request.contentVersion, info });
|
|
285
378
|
const strip = stripTimes(request, info, budgets);
|
|
286
379
|
const { timestamps, window } = strip;
|
|
380
|
+
storeForNextSession(request, info, budgets, resources, stored ?? versionRead(request, source));
|
|
287
381
|
const slots: { slot: number; key: string; decodedAt?: number }[] = takeDecodedFrames(
|
|
288
382
|
strip,
|
|
289
383
|
keyOf,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StoreApi } from "zustand";
|
|
2
2
|
import { isPreviewQuality, type PreviewQuality } from "@hyperframes/core/preview-quality";
|
|
3
|
+
import type { MediaLoadFailure } from "@hyperframes/core/runtime/protocol";
|
|
3
4
|
import { readStudioUiPreferences, writeStudioUiPreferences } from "../../utils/studioUiPreferences";
|
|
4
5
|
|
|
5
6
|
/** The lighter copies of heavy videos the preview wants at its current quality. */
|
|
@@ -53,6 +54,8 @@ export interface PreviewQualitySlice {
|
|
|
53
54
|
setPlaybackHealth: (health: PlaybackHealth | null) => void;
|
|
54
55
|
previewFacts: PreviewFacts | null;
|
|
55
56
|
setPreviewFacts: (facts: PreviewFacts | null) => void;
|
|
57
|
+
mediaLoadFailure: MediaLoadFailure | null;
|
|
58
|
+
setMediaLoadFailure: (failure: MediaLoadFailure | null) => void;
|
|
56
59
|
/** Bumped by requestPreviewFacts; the preview owner forwards each bump and the answer lands in previewFacts. */
|
|
57
60
|
previewFactsRequests: number;
|
|
58
61
|
requestPreviewFacts: () => void;
|
|
@@ -87,6 +90,8 @@ export function createPreviewQualitySlice(
|
|
|
87
90
|
setPlaybackHealth: (playbackHealth) => set({ playbackHealth }),
|
|
88
91
|
previewFacts: null,
|
|
89
92
|
setPreviewFacts: (previewFacts) => set({ previewFacts }),
|
|
93
|
+
mediaLoadFailure: null,
|
|
94
|
+
setMediaLoadFailure: (mediaLoadFailure) => set({ mediaLoadFailure }),
|
|
90
95
|
previewFactsRequests: 0,
|
|
91
96
|
requestPreviewFacts: () =>
|
|
92
97
|
set((state) => ({ previewFactsRequests: state.previewFactsRequests + 1 })),
|