@hyperframes/studio 0.9.20 → 0.9.22
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/codec-DLDwVbqW.js +314 -0
- package/dist/assets/{hyperframes-player-ZQZslutT.js → hyperframes-player-C5DA6O5u.js} +3 -3
- package/dist/assets/index-B6RxZt-8.js +150 -0
- package/dist/assets/{index-Bz2pYyGM.js → index-Buvugo_O.js} +120 -119
- package/dist/assets/pausedVideoDecoder-BGKlQc66.js +1 -0
- package/dist/{chunk-3EAFE522.js → chunk-45KKBU63.js} +1 -1
- package/dist/chunk-4SPHDECE.js +165 -0
- package/dist/{chunk-OGIOFEC7.js → chunk-63DH4LRB.js} +13 -2
- package/dist/{chunk-NUS5R2HO.js → chunk-AX6G6YL5.js} +1 -1
- package/dist/{domEditingLayers-7Z6J4UOK.js → domEditingLayers-7Q56QAU5.js} +2 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.html +1 -1
- package/dist/index.js +104 -195
- package/dist/pausedVideoDecoder-KBQXSWFQ.js +393 -0
- package/dist/player.js +2 -2
- package/package.json +9 -9
- package/src/components/editor/domEditingDom.preview.test.ts +75 -0
- package/src/components/editor/domEditingDom.ts +19 -2
- package/src/components/nle/NLEContext.tsx +4 -1
- package/src/hooks/useElementPicker.test.ts +13 -0
- package/src/hooks/useElementPicker.ts +3 -2
- package/src/player/components/PlayerControls.test.tsx +1 -1
- package/src/player/components/PlayerControls.tsx +1 -1
- package/src/player/components/PreviewSeekBar.test.tsx +42 -0
- package/src/player/components/PreviewSeekBar.tsx +20 -3
- package/src/player/hooks/usePlaybackKeyboard.test.ts +1 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +2 -1
- package/src/player/hooks/useTimelinePlayer.ts +3 -1
- package/src/player/lib/mediaFetch.test.ts +3 -4
- package/src/player/lib/pausedVideoDecoder.test.ts +644 -0
- package/src/player/lib/pausedVideoDecoder.ts +428 -0
- package/src/player/lib/pausedVideoProvider.test.ts +53 -0
- package/src/player/lib/pausedVideoProvider.ts +54 -0
- package/src/player/lib/playbackTypes.ts +8 -2
- package/src/player/lib/previewVideoTime.test.ts +38 -0
- package/src/player/lib/previewVideoTime.ts +39 -0
- package/src/utils/authoredSource.test.ts +11 -0
- package/src/utils/authoredSource.ts +2 -0
- package/dist/assets/index-Bn5atbhb.js +0 -531
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
3
|
+
import { createPausedVideoDecoder } from "./pausedVideoDecoder";
|
|
4
|
+
|
|
5
|
+
const inputs: { source: string; dispose: ReturnType<typeof vi.fn> }[] = [];
|
|
6
|
+
const getTrack = vi.fn();
|
|
7
|
+
const getSample = vi.fn();
|
|
8
|
+
const cancelReads = vi.fn();
|
|
9
|
+
const iterateSamples = vi.fn();
|
|
10
|
+
const finiteSamples = vi.fn();
|
|
11
|
+
const canvasContext = vi.fn();
|
|
12
|
+
const createBitmap = vi.fn();
|
|
13
|
+
let qualityChosenBy = "person";
|
|
14
|
+
let previewQuality = 1;
|
|
15
|
+
let displayScale = 1;
|
|
16
|
+
|
|
17
|
+
vi.mock("mediabunny", () => ({
|
|
18
|
+
ALL_FORMATS: [],
|
|
19
|
+
UrlSource: class {
|
|
20
|
+
constructor(readonly url: string) {}
|
|
21
|
+
},
|
|
22
|
+
Input: class {
|
|
23
|
+
dispose = vi.fn();
|
|
24
|
+
constructor(readonly options: { source: { url: string } }) {
|
|
25
|
+
inputs.push({ source: options.source.url, dispose: this.dispose });
|
|
26
|
+
}
|
|
27
|
+
getPrimaryVideoTrack() {
|
|
28
|
+
return getTrack(this.options.source.url);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
VideoSampleSink: class {
|
|
32
|
+
constructor(readonly track: { source: string }) {}
|
|
33
|
+
getSample(time: number) {
|
|
34
|
+
return getSample(this.track.source, time);
|
|
35
|
+
}
|
|
36
|
+
samples(start: number, end: number) {
|
|
37
|
+
return iterateSamples(this.track.source, start, end);
|
|
38
|
+
}
|
|
39
|
+
samplesAtTimestamps(times: Iterable<number>) {
|
|
40
|
+
return finiteSamples(this.track.source, times);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}));
|
|
44
|
+
vi.mock("./mediaFetch", () => ({ mediaUrlSourceOptions: () => ({ cancelReads }) }));
|
|
45
|
+
vi.mock("../store/playerStore", () => ({
|
|
46
|
+
usePlayerStore: {
|
|
47
|
+
getState: () => ({ previewQuality, previewQualityChosenBy: qualityChosenBy }),
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
vi.mock("@hyperframes/core/runtime/protocol", () => ({ frameDisplayScale: () => displayScale }));
|
|
51
|
+
|
|
52
|
+
const providers: ReturnType<typeof createPausedVideoDecoder>[] = [];
|
|
53
|
+
function provider(
|
|
54
|
+
facts?: Record<
|
|
55
|
+
string,
|
|
56
|
+
{ width: number; height: number; frameRate?: number; variableFrameRate?: boolean }
|
|
57
|
+
>,
|
|
58
|
+
rootSize?: { width: number; height: number },
|
|
59
|
+
) {
|
|
60
|
+
const iframe = document.createElement("iframe");
|
|
61
|
+
document.body.append(iframe);
|
|
62
|
+
if (facts) Object.assign(iframe.contentWindow, { __HF_MEDIA_SOURCE_FACTS__: facts });
|
|
63
|
+
if (rootSize)
|
|
64
|
+
Object.defineProperties(iframe.contentDocument!.documentElement, {
|
|
65
|
+
clientWidth: { value: rootSize.width, configurable: true },
|
|
66
|
+
clientHeight: { value: rootSize.height, configurable: true },
|
|
67
|
+
});
|
|
68
|
+
const result = createPausedVideoDecoder(iframe);
|
|
69
|
+
providers.push(result);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
const request = (source: string) => ({
|
|
73
|
+
source: `http://localhost/${source}.webm`,
|
|
74
|
+
time: 0,
|
|
75
|
+
video: document.createElement("video"),
|
|
76
|
+
});
|
|
77
|
+
const signal = () => new AbortController().signal;
|
|
78
|
+
const sample = (timestamp = 0) => ({
|
|
79
|
+
timestamp,
|
|
80
|
+
duration: 1 / 30,
|
|
81
|
+
close: vi.fn(),
|
|
82
|
+
drawWithFit: vi.fn(),
|
|
83
|
+
});
|
|
84
|
+
const bitmap = (bytes = 4) => ({ width: bytes / 4, height: 1, close: vi.fn() });
|
|
85
|
+
const track = (source: string) => ({
|
|
86
|
+
source,
|
|
87
|
+
getDisplayWidth: async () => 100,
|
|
88
|
+
getDisplayHeight: async () => 100,
|
|
89
|
+
getFirstTimestamp: async () => 0,
|
|
90
|
+
getTimeResolution: async () => 1000,
|
|
91
|
+
async getSquarePixelWidth() {
|
|
92
|
+
return this.getDisplayWidth();
|
|
93
|
+
},
|
|
94
|
+
async getSquarePixelHeight() {
|
|
95
|
+
return this.getDisplayHeight();
|
|
96
|
+
},
|
|
97
|
+
getRotation: async () => 0,
|
|
98
|
+
getFlip: async () => false,
|
|
99
|
+
canBeTransparent: async () => false,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
inputs.length = 0;
|
|
104
|
+
getTrack.mockReset().mockImplementation(async (source: string) => track(source));
|
|
105
|
+
getSample.mockReset().mockImplementation(async () => sample());
|
|
106
|
+
iterateSamples.mockReset();
|
|
107
|
+
finiteSamples.mockReset().mockImplementation(async function* (
|
|
108
|
+
source: string,
|
|
109
|
+
times: Iterable<number>,
|
|
110
|
+
) {
|
|
111
|
+
for (const time of times) yield await getSample(source, time);
|
|
112
|
+
});
|
|
113
|
+
canvasContext.mockReset().mockReturnValue({ clearRect: vi.fn(), imageSmoothingQuality: "low" });
|
|
114
|
+
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockImplementation(canvasContext);
|
|
115
|
+
createBitmap.mockReset().mockImplementation(async () => bitmap());
|
|
116
|
+
cancelReads.mockClear();
|
|
117
|
+
qualityChosenBy = "person";
|
|
118
|
+
previewQuality = 1;
|
|
119
|
+
displayScale = 1;
|
|
120
|
+
vi.stubGlobal("createImageBitmap", createBitmap);
|
|
121
|
+
});
|
|
122
|
+
afterEach(async () => {
|
|
123
|
+
for (const owner of providers.splice(0)) owner.dispose();
|
|
124
|
+
await Promise.resolve();
|
|
125
|
+
document.body.innerHTML = "";
|
|
126
|
+
vi.useRealTimers();
|
|
127
|
+
vi.unstubAllGlobals();
|
|
128
|
+
vi.restoreAllMocks();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("rejects a two-source frame set that cannot fit without closing a leased bitmap", async () => {
|
|
132
|
+
const first = bitmap(40 * 1024 * 1024),
|
|
133
|
+
second = bitmap(40 * 1024 * 1024);
|
|
134
|
+
createBitmap.mockResolvedValueOnce(first).mockResolvedValueOnce(second);
|
|
135
|
+
await expect(provider().decode([request("a"), request("b")], signal())).rejects.toThrow(
|
|
136
|
+
"Preview frame budget reached",
|
|
137
|
+
);
|
|
138
|
+
expect(first.close).not.toHaveBeenCalled();
|
|
139
|
+
expect(second.close).toHaveBeenCalledOnce();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("reserves the reader budget before opening and keeps concurrent same-source leases alive", async () => {
|
|
143
|
+
let finishOpen: (() => void) | undefined;
|
|
144
|
+
const opened = new Promise<void>((resolve) => {
|
|
145
|
+
finishOpen = resolve;
|
|
146
|
+
});
|
|
147
|
+
getTrack.mockImplementation(async (source: string) => {
|
|
148
|
+
await opened;
|
|
149
|
+
return track(source);
|
|
150
|
+
});
|
|
151
|
+
const owner = provider();
|
|
152
|
+
const first = owner.decode([request("a"), request("b"), request("c"), request("d")], signal());
|
|
153
|
+
const shared = owner.decode([request("a")], signal());
|
|
154
|
+
await expect(owner.decode([request("e")], signal())).rejects.toThrow(
|
|
155
|
+
"Preview decoder budget reached",
|
|
156
|
+
);
|
|
157
|
+
expect(inputs).toHaveLength(4);
|
|
158
|
+
expect(inputs.every((input) => input.dispose.mock.calls.length === 0)).toBe(true);
|
|
159
|
+
finishOpen?.();
|
|
160
|
+
const frames = await first,
|
|
161
|
+
other = await shared;
|
|
162
|
+
expect(frames).toHaveLength(4);
|
|
163
|
+
expect(other).toHaveLength(1);
|
|
164
|
+
expect(inputs.every((input) => input.dispose.mock.calls.length === 0)).toBe(true);
|
|
165
|
+
for (const frame of [...frames, ...other]) frame.release();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("releases successful source leases when another source fails", async () => {
|
|
169
|
+
const first = bitmap(40 * 1024 * 1024),
|
|
170
|
+
next = bitmap(40 * 1024 * 1024);
|
|
171
|
+
createBitmap.mockResolvedValueOnce(first).mockResolvedValueOnce(next);
|
|
172
|
+
getSample.mockImplementation(async (source: string) => {
|
|
173
|
+
if (source.endsWith("/b.webm")) throw new Error("decoder failed");
|
|
174
|
+
return sample();
|
|
175
|
+
});
|
|
176
|
+
const owner = provider();
|
|
177
|
+
await expect(owner.decode([request("a"), request("b")], signal())).rejects.toThrow(
|
|
178
|
+
"decoder failed",
|
|
179
|
+
);
|
|
180
|
+
const [frame] = await owner.decode([request("c")], signal());
|
|
181
|
+
expect(first.close).toHaveBeenCalledOnce();
|
|
182
|
+
expect(next.close).not.toHaveBeenCalled();
|
|
183
|
+
frame!.release();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("retires idle readers even when decoding fails before a frame is returned", async () => {
|
|
187
|
+
vi.useFakeTimers();
|
|
188
|
+
getSample.mockRejectedValueOnce(new Error("decoder failed"));
|
|
189
|
+
await expect(provider().decode([request("a")], signal())).rejects.toThrow("decoder failed");
|
|
190
|
+
expect(inputs[0]!.dispose).not.toHaveBeenCalled();
|
|
191
|
+
await vi.advanceTimersByTimeAsync(10000);
|
|
192
|
+
expect(inputs[0]!.dispose).toHaveBeenCalledOnce();
|
|
193
|
+
expect(cancelReads).toHaveBeenCalledOnce();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("closes a bitmap completed after provider disposal and rejects later requests without opening", async () => {
|
|
197
|
+
let finish: ((image: ReturnType<typeof bitmap>) => void) | undefined;
|
|
198
|
+
createBitmap.mockImplementationOnce(
|
|
199
|
+
() =>
|
|
200
|
+
new Promise((resolve) => {
|
|
201
|
+
finish = resolve;
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
const owner = provider(),
|
|
205
|
+
pending = owner.decode([request("a")], signal());
|
|
206
|
+
await vi.waitFor(() => expect(createBitmap).toHaveBeenCalledOnce());
|
|
207
|
+
owner.dispose();
|
|
208
|
+
const image = bitmap();
|
|
209
|
+
finish?.(image);
|
|
210
|
+
await expect(pending).rejects.toThrow("Preview disposed");
|
|
211
|
+
expect(image.close).toHaveBeenCalledOnce();
|
|
212
|
+
await expect(owner.decode([request("b")], signal())).rejects.toMatchObject({
|
|
213
|
+
name: "AbortError",
|
|
214
|
+
});
|
|
215
|
+
expect(inputs).toHaveLength(1);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("shares full-resolution readers when animation changes only an oversized display box", async () => {
|
|
219
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
220
|
+
...track(source),
|
|
221
|
+
getDisplayWidth: async () => 1000,
|
|
222
|
+
getDisplayHeight: async () => 500,
|
|
223
|
+
}));
|
|
224
|
+
const owner = provider({ "a.webm": { width: 1000, height: 500 } }),
|
|
225
|
+
item = request("a");
|
|
226
|
+
const rect = vi.spyOn(item.video, "getBoundingClientRect");
|
|
227
|
+
rect.mockReturnValue(new DOMRect(0, 0, 2600, 1800));
|
|
228
|
+
const first = await owner.decode([item], signal());
|
|
229
|
+
first[0]!.release();
|
|
230
|
+
rect.mockReturnValue(new DOMRect(0, 0, 1900, 1300));
|
|
231
|
+
const second = await owner.decode([item], signal());
|
|
232
|
+
second[0]!.release();
|
|
233
|
+
expect(inputs).toHaveLength(1);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("keeps original resolution across hidden cuts, viewport changes and automatic playback quality", async () => {
|
|
237
|
+
qualityChosenBy = "app";
|
|
238
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
239
|
+
...track(source),
|
|
240
|
+
getDisplayWidth: async () => 2100,
|
|
241
|
+
getDisplayHeight: async () => 1800,
|
|
242
|
+
}));
|
|
243
|
+
const owner = provider({ "a.webm": { width: 2100, height: 1800 } });
|
|
244
|
+
for (const [width, scale, quality] of [
|
|
245
|
+
[2300, 1, 1],
|
|
246
|
+
[0, 0.5, 0.25],
|
|
247
|
+
[400, 0.25, 0.5],
|
|
248
|
+
]) {
|
|
249
|
+
displayScale = scale!;
|
|
250
|
+
previewQuality = quality!;
|
|
251
|
+
const item = request("a");
|
|
252
|
+
vi.spyOn(item.video, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, width, 200));
|
|
253
|
+
const frames = await owner.decode([item], signal());
|
|
254
|
+
frames[0]!.release();
|
|
255
|
+
}
|
|
256
|
+
expect(inputs).toHaveLength(1);
|
|
257
|
+
expect(inputs[0]!.source).toBe("http://localhost/a.webm");
|
|
258
|
+
expect(createBitmap.mock.calls[0]![0]).toMatchObject({ width: 2100, height: 1800 });
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const cfrFacts = { "a.webm": { width: 100, height: 100, frameRate: 30, variableFrameRate: false } };
|
|
262
|
+
|
|
263
|
+
it("closes skipped raw samples and rasterizes only selected frames across a 0.3 second forward gap", async () => {
|
|
264
|
+
const one = sample(0.1),
|
|
265
|
+
skipA = sample(0.2),
|
|
266
|
+
skipB = sample(0.3),
|
|
267
|
+
last = sample(0.4);
|
|
268
|
+
iterateSamples.mockImplementation(async function* () {
|
|
269
|
+
yield one;
|
|
270
|
+
yield skipA;
|
|
271
|
+
yield skipB;
|
|
272
|
+
yield last;
|
|
273
|
+
});
|
|
274
|
+
const owner = provider(cfrFacts),
|
|
275
|
+
item = request("a");
|
|
276
|
+
for (const time of [0, 0.1, 0.4]) {
|
|
277
|
+
const frames = await owner.decode([{ ...item, time }], signal());
|
|
278
|
+
frames[0]!.release();
|
|
279
|
+
}
|
|
280
|
+
expect(iterateSamples).toHaveBeenCalledOnce();
|
|
281
|
+
for (const skipped of [skipA, skipB]) {
|
|
282
|
+
expect(skipped.close).toHaveBeenCalledOnce();
|
|
283
|
+
expect(skipped.drawWithFit).not.toHaveBeenCalled();
|
|
284
|
+
}
|
|
285
|
+
for (const selected of [one, last]) {
|
|
286
|
+
expect(selected.close).toHaveBeenCalledOnce();
|
|
287
|
+
expect(selected.drawWithFit).toHaveBeenCalledWith(expect.anything(), {
|
|
288
|
+
fit: "fill",
|
|
289
|
+
rotation: 0,
|
|
290
|
+
flip: false,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
expect(createBitmap).toHaveBeenCalledTimes(3);
|
|
294
|
+
expect(canvasContext).toHaveBeenCalledWith("2d", { alpha: true });
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("closes the sequential reader and uses demand decoding beyond the bounded forward gap", async () => {
|
|
298
|
+
const returned = vi.fn();
|
|
299
|
+
iterateSamples.mockImplementation(async function* () {
|
|
300
|
+
try {
|
|
301
|
+
yield sample(0.1);
|
|
302
|
+
yield sample(0.2);
|
|
303
|
+
} finally {
|
|
304
|
+
returned();
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
getSample.mockImplementation(async (_source: string, time: number) =>
|
|
308
|
+
sample(Math.floor(time * 30) / 30),
|
|
309
|
+
);
|
|
310
|
+
const owner = provider(cfrFacts),
|
|
311
|
+
item = request("a");
|
|
312
|
+
for (const time of [0, 0.1, 1]) {
|
|
313
|
+
const frames = await owner.decode([{ ...item, time }], signal());
|
|
314
|
+
frames[0]!.release();
|
|
315
|
+
}
|
|
316
|
+
expect(returned).toHaveBeenCalledOnce();
|
|
317
|
+
expect(getSample).toHaveBeenCalledTimes(2);
|
|
318
|
+
expect(getSample).toHaveBeenLastCalledWith(item.source, expect.closeTo(1.00001, 8));
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("closes a raw sample arriving after cancellation without drawing it", async () => {
|
|
322
|
+
let finish: ((result: { done: false; value: ReturnType<typeof sample> }) => void) | undefined;
|
|
323
|
+
const next = vi.fn(
|
|
324
|
+
() =>
|
|
325
|
+
new Promise((resolve) => {
|
|
326
|
+
finish = resolve;
|
|
327
|
+
}),
|
|
328
|
+
),
|
|
329
|
+
returned = vi.fn().mockResolvedValue({ done: true });
|
|
330
|
+
iterateSamples.mockReturnValue({ next, return: returned });
|
|
331
|
+
const owner = provider(cfrFacts),
|
|
332
|
+
item = request("a");
|
|
333
|
+
const initial = await owner.decode([item], signal());
|
|
334
|
+
initial[0]!.release();
|
|
335
|
+
const controller = new AbortController(),
|
|
336
|
+
pending = owner.decode([{ ...item, time: 0.1 }], controller.signal);
|
|
337
|
+
await vi.waitFor(() => expect(next).toHaveBeenCalledOnce());
|
|
338
|
+
controller.abort();
|
|
339
|
+
const late = sample(0.1);
|
|
340
|
+
finish?.({ done: false, value: late });
|
|
341
|
+
await expect(pending).rejects.toMatchObject({ name: "AbortError" });
|
|
342
|
+
expect(late.close).toHaveBeenCalledOnce();
|
|
343
|
+
expect(late.drawWithFit).not.toHaveBeenCalled();
|
|
344
|
+
expect(returned).toHaveBeenCalledOnce();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("closes selected samples when rasterization or bitmap copying fails", async () => {
|
|
348
|
+
const drawing = sample();
|
|
349
|
+
drawing.drawWithFit.mockImplementationOnce(() => {
|
|
350
|
+
throw new Error("drawing failed");
|
|
351
|
+
});
|
|
352
|
+
getSample.mockResolvedValueOnce(drawing);
|
|
353
|
+
const owner = provider();
|
|
354
|
+
await expect(owner.decode([request("a")], signal())).rejects.toThrow("drawing failed");
|
|
355
|
+
expect(drawing.close).toHaveBeenCalledOnce();
|
|
356
|
+
const copying = sample();
|
|
357
|
+
getSample.mockResolvedValueOnce(copying);
|
|
358
|
+
createBitmap.mockRejectedValueOnce(new Error("copying failed"));
|
|
359
|
+
await expect(owner.decode([request("b")], signal())).rejects.toThrow("copying failed");
|
|
360
|
+
expect(copying.close).toHaveBeenCalledOnce();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("closes a demand sample completed after provider disposal before rasterization", async () => {
|
|
364
|
+
let finish: ((value: ReturnType<typeof sample>) => void) | undefined;
|
|
365
|
+
getSample.mockImplementationOnce(
|
|
366
|
+
() =>
|
|
367
|
+
new Promise((resolve) => {
|
|
368
|
+
finish = resolve;
|
|
369
|
+
}),
|
|
370
|
+
);
|
|
371
|
+
const owner = provider(),
|
|
372
|
+
pending = owner.decode([request("a")], signal());
|
|
373
|
+
await vi.waitFor(() => expect(getSample).toHaveBeenCalledOnce());
|
|
374
|
+
owner.dispose();
|
|
375
|
+
const late = sample();
|
|
376
|
+
finish?.(late);
|
|
377
|
+
await expect(pending).rejects.toThrow("Preview disposed");
|
|
378
|
+
expect(late.close).toHaveBeenCalledOnce();
|
|
379
|
+
expect(late.drawWithFit).not.toHaveBeenCalled();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("keeps original pixels throughout automatic dragging and settling", async () => {
|
|
383
|
+
qualityChosenBy = "auto";
|
|
384
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
385
|
+
...track(source),
|
|
386
|
+
getDisplayWidth: async () => 1000,
|
|
387
|
+
getDisplayHeight: async () => 500,
|
|
388
|
+
}));
|
|
389
|
+
const owner = provider({ "a.webm": { width: 1000, height: 500 } }),
|
|
390
|
+
item = request("a");
|
|
391
|
+
vi.spyOn(item.video, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 2600, 1800));
|
|
392
|
+
const drag = await owner.decode([{ ...item, settled: false }], signal());
|
|
393
|
+
drag[0]!.release();
|
|
394
|
+
const settled = await owner.decode([{ ...item, settled: true }], signal());
|
|
395
|
+
settled[0]!.release();
|
|
396
|
+
expect(createBitmap.mock.calls.map(([canvas]) => [canvas.width, canvas.height])).toEqual([
|
|
397
|
+
[1000, 500],
|
|
398
|
+
]);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("restores full paused resolution after automatic playback quality was lowered", async () => {
|
|
402
|
+
qualityChosenBy = "app";
|
|
403
|
+
previewQuality = 0.25;
|
|
404
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
405
|
+
...track(source),
|
|
406
|
+
getDisplayWidth: async () => 1000,
|
|
407
|
+
getDisplayHeight: async () => 500,
|
|
408
|
+
}));
|
|
409
|
+
const owner = provider({ "a.webm": { width: 1000, height: 500 } });
|
|
410
|
+
const item = request("a");
|
|
411
|
+
vi.spyOn(item.video, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 1000, 500));
|
|
412
|
+
const frame = await owner.decode([{ ...item, settled: true }], signal());
|
|
413
|
+
frame[0]!.release();
|
|
414
|
+
expect(createBitmap.mock.calls[0]![0]).toMatchObject({ width: 1000, height: 500 });
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("uses original resolution even when a lower playback quality was saved", async () => {
|
|
418
|
+
previewQuality = 0.25;
|
|
419
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
420
|
+
...track(source),
|
|
421
|
+
getDisplayWidth: async () => 1000,
|
|
422
|
+
getDisplayHeight: async () => 500,
|
|
423
|
+
}));
|
|
424
|
+
const owner = provider({ "a.webm": { width: 1000, height: 500 } }),
|
|
425
|
+
item = request("a");
|
|
426
|
+
vi.spyOn(item.video, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 2600, 1800));
|
|
427
|
+
const drag = await owner.decode([{ ...item, settled: false }], signal());
|
|
428
|
+
drag[0]!.release();
|
|
429
|
+
const settled = await owner.decode([{ ...item, settled: true }], signal());
|
|
430
|
+
settled[0]!.release();
|
|
431
|
+
expect(createBitmap).toHaveBeenCalledOnce();
|
|
432
|
+
expect(createBitmap.mock.calls[0]![0]).toMatchObject({ width: 1000, height: 500 });
|
|
433
|
+
expect(inputs).toHaveLength(1);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it.each([
|
|
437
|
+
{ rotation: 0, flip: false, width: 320, height: 200 },
|
|
438
|
+
{ rotation: 90, flip: true, width: 200, height: 320 },
|
|
439
|
+
])(
|
|
440
|
+
"preserves track rotation $rotation, flip and non-square-pixel display geometry",
|
|
441
|
+
async ({ rotation, flip, width, height }) => {
|
|
442
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
443
|
+
...track(source),
|
|
444
|
+
getDisplayWidth: async () => width,
|
|
445
|
+
getDisplayHeight: async () => height,
|
|
446
|
+
getSquarePixelWidth: async () => 320,
|
|
447
|
+
getSquarePixelHeight: async () => 200,
|
|
448
|
+
getRotation: async () => rotation,
|
|
449
|
+
getFlip: async () => flip,
|
|
450
|
+
}));
|
|
451
|
+
const decoded = sample();
|
|
452
|
+
getSample.mockResolvedValueOnce(decoded);
|
|
453
|
+
const [frame] = await provider().decode([request("a")], signal());
|
|
454
|
+
expect(createBitmap.mock.calls[0]![0]).toMatchObject({ width, height });
|
|
455
|
+
expect(decoded.drawWithFit).toHaveBeenCalledWith(expect.anything(), {
|
|
456
|
+
fit: "fill",
|
|
457
|
+
rotation,
|
|
458
|
+
flip,
|
|
459
|
+
});
|
|
460
|
+
expect(frame).toMatchObject({ width, height });
|
|
461
|
+
frame!.release();
|
|
462
|
+
},
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
it("releases sequential decoders before native playback and lazily recreates them", async () => {
|
|
466
|
+
const returned = vi.fn();
|
|
467
|
+
iterateSamples.mockImplementation(async function* () {
|
|
468
|
+
try {
|
|
469
|
+
yield sample(0.1);
|
|
470
|
+
yield sample(0.2);
|
|
471
|
+
} finally {
|
|
472
|
+
returned();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
getSample.mockImplementation(async (_source: string, time: number) =>
|
|
476
|
+
sample(Math.floor(time * 30) / 30),
|
|
477
|
+
);
|
|
478
|
+
const owner = provider(cfrFacts),
|
|
479
|
+
item = request("a");
|
|
480
|
+
for (const time of [0, 0.1]) {
|
|
481
|
+
const [frame] = await owner.decode([{ ...item, time }], signal());
|
|
482
|
+
frame!.release();
|
|
483
|
+
}
|
|
484
|
+
expect(returned).not.toHaveBeenCalled();
|
|
485
|
+
await owner.suspend!();
|
|
486
|
+
expect(returned).toHaveBeenCalledOnce();
|
|
487
|
+
expect(inputs[0]!.dispose).toHaveBeenCalledOnce();
|
|
488
|
+
expect(cancelReads).toHaveBeenCalledOnce();
|
|
489
|
+
const [next] = await owner.decode([{ ...item, time: 0.2 }], signal());
|
|
490
|
+
expect(inputs).toHaveLength(2);
|
|
491
|
+
expect([next!.width, next!.height]).toEqual([100, 100]);
|
|
492
|
+
next!.release();
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("closes a bitmap copied after native-play suspension without retaining its decoder", async () => {
|
|
496
|
+
let finish: ((image: ReturnType<typeof bitmap>) => void) | undefined;
|
|
497
|
+
createBitmap.mockImplementationOnce(
|
|
498
|
+
() =>
|
|
499
|
+
new Promise((resolve) => {
|
|
500
|
+
finish = resolve;
|
|
501
|
+
}),
|
|
502
|
+
);
|
|
503
|
+
const owner = provider();
|
|
504
|
+
const pending = owner.decode([request("a")], signal());
|
|
505
|
+
await vi.waitFor(() => expect(createBitmap).toHaveBeenCalledOnce());
|
|
506
|
+
await owner.suspend!();
|
|
507
|
+
const image = bitmap();
|
|
508
|
+
finish!(image);
|
|
509
|
+
await expect(pending).rejects.toThrow("Preview disposed");
|
|
510
|
+
expect(image.close).toHaveBeenCalledOnce();
|
|
511
|
+
const [next] = await owner.decode([request("a")], signal());
|
|
512
|
+
expect(inputs).toHaveLength(2);
|
|
513
|
+
next!.release();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("does not poison a reopened source when an older suspended input settles late", async () => {
|
|
517
|
+
let rejectOpen: (error: Error) => void = () => {};
|
|
518
|
+
getTrack.mockImplementationOnce(
|
|
519
|
+
() =>
|
|
520
|
+
new Promise((_resolve, reject) => {
|
|
521
|
+
rejectOpen = reject;
|
|
522
|
+
}),
|
|
523
|
+
);
|
|
524
|
+
const owner = provider();
|
|
525
|
+
const old = owner.decode([request("a")], signal());
|
|
526
|
+
await vi.waitFor(() => expect(inputs).toHaveLength(1));
|
|
527
|
+
const suspended = owner.suspend!();
|
|
528
|
+
expect(inputs[0]!.dispose).toHaveBeenCalled();
|
|
529
|
+
const [current] = await owner.decode([request("a")], signal());
|
|
530
|
+
current!.release();
|
|
531
|
+
rejectOpen(new DOMException("Suspended", "AbortError"));
|
|
532
|
+
await expect(old).rejects.toMatchObject({ name: "AbortError" });
|
|
533
|
+
await suspended;
|
|
534
|
+
const [cached] = await owner.decode([request("a")], signal());
|
|
535
|
+
expect(inputs).toHaveLength(2);
|
|
536
|
+
expect(inputs[1]!.dispose).not.toHaveBeenCalled();
|
|
537
|
+
cached!.release();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("uses finite queries for alpha tracks while preserving original dimensions and closing samples", async () => {
|
|
541
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
542
|
+
...track(source),
|
|
543
|
+
canBeTransparent: async () => true,
|
|
544
|
+
}));
|
|
545
|
+
const samples = [sample(0), sample(0.1), sample(0.2)];
|
|
546
|
+
getSample.mockImplementation(async () => samples[getSample.mock.calls.length - 1]);
|
|
547
|
+
iterateSamples.mockImplementation(async function* () {
|
|
548
|
+
yield sample(0.1);
|
|
549
|
+
yield sample(0.2);
|
|
550
|
+
});
|
|
551
|
+
const owner = provider(cfrFacts),
|
|
552
|
+
item = request("a");
|
|
553
|
+
for (const time of [0, 0.1, 0.2]) {
|
|
554
|
+
const [frame] = await owner.decode([{ ...item, time }], signal());
|
|
555
|
+
expect([frame!.width, frame!.height]).toEqual([100, 100]);
|
|
556
|
+
frame!.release();
|
|
557
|
+
}
|
|
558
|
+
expect(iterateSamples).not.toHaveBeenCalled();
|
|
559
|
+
expect(getSample).toHaveBeenCalledTimes(3);
|
|
560
|
+
for (const frame of samples) expect(frame.close).toHaveBeenCalledOnce();
|
|
561
|
+
await owner.suspend!();
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it.each(["suspend", "dispose"] as const)(
|
|
565
|
+
"drains an in-flight alpha query before %s",
|
|
566
|
+
async (action) => {
|
|
567
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
568
|
+
...track(source),
|
|
569
|
+
canBeTransparent: async () => true,
|
|
570
|
+
}));
|
|
571
|
+
let finish: (value: ReturnType<typeof sample>) => void = () => {};
|
|
572
|
+
getSample.mockImplementationOnce(
|
|
573
|
+
() =>
|
|
574
|
+
new Promise((resolve) => {
|
|
575
|
+
finish = resolve;
|
|
576
|
+
}),
|
|
577
|
+
);
|
|
578
|
+
const owner = provider();
|
|
579
|
+
const pending = owner.decode([request("a")], signal());
|
|
580
|
+
await vi.waitFor(() => expect(getSample).toHaveBeenCalledOnce());
|
|
581
|
+
const rejected = expect(pending).rejects.toThrow("Preview disposed");
|
|
582
|
+
const suspended = action === "suspend" ? owner.suspend!() : owner.dispose();
|
|
583
|
+
await Promise.resolve();
|
|
584
|
+
expect(inputs[0]!.dispose).not.toHaveBeenCalled();
|
|
585
|
+
expect(cancelReads).not.toHaveBeenCalled();
|
|
586
|
+
if (action === "suspend") {
|
|
587
|
+
const [next] = await owner.decode([request("a")], signal());
|
|
588
|
+
expect(inputs).toHaveLength(2);
|
|
589
|
+
next!.release();
|
|
590
|
+
}
|
|
591
|
+
const final = sample();
|
|
592
|
+
finish(final);
|
|
593
|
+
await rejected;
|
|
594
|
+
await suspended;
|
|
595
|
+
expect(final.close).toHaveBeenCalledOnce();
|
|
596
|
+
expect(inputs[0]!.dispose).toHaveBeenCalledOnce();
|
|
597
|
+
if (action === "suspend") expect(inputs[1]!.dispose).not.toHaveBeenCalled();
|
|
598
|
+
},
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
it("finishes the alpha timestamp iterator before publishing its selected sample", async () => {
|
|
602
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
603
|
+
...track(source),
|
|
604
|
+
canBeTransparent: async () => true,
|
|
605
|
+
}));
|
|
606
|
+
let drain: () => void = () => {};
|
|
607
|
+
const drained = new Promise<void>((resolve) => {
|
|
608
|
+
drain = resolve;
|
|
609
|
+
});
|
|
610
|
+
const selected = sample();
|
|
611
|
+
finiteSamples.mockImplementation(async function* () {
|
|
612
|
+
yield selected;
|
|
613
|
+
await drained;
|
|
614
|
+
});
|
|
615
|
+
const owner = provider();
|
|
616
|
+
let published = false;
|
|
617
|
+
const decoding = owner.decode([request("a")], signal()).then((frames) => {
|
|
618
|
+
published = true;
|
|
619
|
+
return frames;
|
|
620
|
+
});
|
|
621
|
+
await vi.waitFor(() => expect(finiteSamples).toHaveBeenCalledOnce());
|
|
622
|
+
await Promise.resolve();
|
|
623
|
+
expect(published).toBe(false);
|
|
624
|
+
expect(createBitmap).not.toHaveBeenCalled();
|
|
625
|
+
drain();
|
|
626
|
+
const [frame] = await decoding;
|
|
627
|
+
expect(selected.close).toHaveBeenCalledOnce();
|
|
628
|
+
frame!.release();
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it("closes the selected alpha sample when the finite iterator fails while draining", async () => {
|
|
632
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
633
|
+
...track(source),
|
|
634
|
+
canBeTransparent: async () => true,
|
|
635
|
+
}));
|
|
636
|
+
const selected = sample();
|
|
637
|
+
finiteSamples.mockImplementation(async function* () {
|
|
638
|
+
yield selected;
|
|
639
|
+
throw new Error("Alpha drain failed");
|
|
640
|
+
});
|
|
641
|
+
const owner = provider();
|
|
642
|
+
await expect(owner.decode([request("a")], signal())).rejects.toThrow("Alpha drain failed");
|
|
643
|
+
expect(selected.close).toHaveBeenCalledOnce();
|
|
644
|
+
});
|