@alpha2-sh/editor 0.4.5 → 0.5.0
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/browser/bridge.d.ts +15 -16
- package/dist/browser/bridge.js +533 -387
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +52 -31
- package/dist/browser/runtime/assets.js +206 -47
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +58 -31
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +40 -43
- package/dist/browser/runtime/engine.js +82 -63
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +10 -17
- package/dist/browser/runtime/proxies.js +33 -45
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +98 -105
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +243 -221
- package/dist/browser/worker.d.ts +8 -9
- package/dist/browser/worker.js +55 -22
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +65 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -19
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `provider`'s settings as one comparable string, serialized once per provider object: an image
|
|
3
|
-
* sequence's holds every frame's locator.
|
|
4
|
-
*/
|
|
1
|
+
/** `provider`'s settings as one comparable string, serialized once per provider object. */
|
|
5
2
|
export function providerSettings(provider: any): any;
|
|
6
3
|
/**
|
|
7
|
-
* Whether two providers have
|
|
8
|
-
*
|
|
4
|
+
* Whether two providers have equal settings. Each pair is compared once, so per-frame checks cost
|
|
5
|
+
* no serialization.
|
|
9
6
|
*/
|
|
10
7
|
export function sameProviderSettings(a: any, b: any): any;
|
|
11
8
|
/** Default byte budget of still and text rasters, matching the frame supply's image cache. */
|
|
12
9
|
export const DEFAULT_RASTER_BUDGET_BYTES: number;
|
|
13
10
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* Default byte budget for open extension sources (decoded frames in the provider module plus the
|
|
12
|
+
* last shown frame), matching the native host's `providerSourceBytes`.
|
|
16
13
|
*/
|
|
17
14
|
export const DEFAULT_PROVIDER_SOURCE_BYTES: number;
|
|
18
15
|
/** The host side of the engine's per-frame source requests for one renderer (preview or export). */
|
|
@@ -29,10 +26,9 @@ export class SourcePixels {
|
|
|
29
26
|
library: any;
|
|
30
27
|
extensionsWasmUrl: any;
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `decodeFallbacks`.
|
|
29
|
+
* `"auto"` lets the browser pick, hardware where available; `"software"` decodes on the CPU so
|
|
30
|
+
* no frame needs a GPU readback. Sources without a software decoder decode as `"auto"` and are
|
|
31
|
+
* reported in `decodeFallbacks`.
|
|
36
32
|
*/
|
|
37
33
|
videoDecode: string;
|
|
38
34
|
get diagnostics(): {
|
|
@@ -50,42 +46,38 @@ export class SourcePixels {
|
|
|
50
46
|
};
|
|
51
47
|
setOutputSize(width: any, height: any): void;
|
|
52
48
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* opened with other fonts opens again on its next frame; other sources are not touched.
|
|
49
|
+
* Sets the fonts SVG text draws with, in fallback order (the engine's caption stack, `{ bytes }`
|
|
50
|
+
* each), as the native host does. An SVG opened with other fonts reopens on its next frame.
|
|
56
51
|
*/
|
|
57
52
|
setFonts(fonts: any): void;
|
|
58
53
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* neither changes.
|
|
54
|
+
* A source's content identity for `FrameSupply`'s `contentOf`: its runtime asset, plus the fonts
|
|
55
|
+
* for an SVG so a font change redraws it. Stable while neither changes.
|
|
62
56
|
*/
|
|
63
57
|
contentOf(asset: any): any;
|
|
64
|
-
/** Drops the cached raster of `assetId`, so its next read makes it again. */
|
|
65
58
|
invalidate(assetId: any): void;
|
|
66
59
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* the CPU (see `#softwareFrame`).
|
|
60
|
+
* `FrameSupply`'s `pixelsFor` callback. `sourceId` is the source the engine asked for, which the
|
|
61
|
+
* layer may stand in for (a proxy has its own ID); decoders are kept per source, as `release`
|
|
62
|
+
* names them. `decode: "software"` asks for a CPU-decoded frame (see `#softwareFrame`).
|
|
71
63
|
*/
|
|
72
64
|
pixelsFor: (layer: any, seconds: any, { preferVideoFrame, consumerId, sourceId, decode }?: {
|
|
73
65
|
preferVideoFrame?: boolean | undefined;
|
|
74
66
|
consumerId?: any;
|
|
75
67
|
}) => Promise<any>;
|
|
76
68
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* (
|
|
80
|
-
* `"software-unavailable"
|
|
81
|
-
*
|
|
69
|
+
* Fallbacks per source and kind, reported by browser exports. `"element-seek"`: frames read by
|
|
70
|
+
* element seeks instead of decoding, with the last reason, count, and whether decoding stopped
|
|
71
|
+
* for good (failed to open or failed {@link MAX_DECODE_FAILURES} frames running).
|
|
72
|
+
* `"software-unavailable"`: `videoDecode: "software"` decoded as `"auto"` for lack of a software
|
|
73
|
+
* decoder (`frames` 0).
|
|
82
74
|
*/
|
|
83
75
|
get decodeFallbacks(): any[];
|
|
84
|
-
/** Keeps decoder sessions
|
|
76
|
+
/** Keeps decoder sessions to the consumers the current frame needs. */
|
|
85
77
|
retainConsumers: (liveConsumerIds: any) => Promise<void>;
|
|
86
78
|
/**
|
|
87
|
-
* Drops decoders, extension sources
|
|
88
|
-
*
|
|
79
|
+
* Drops decoders, extension sources and rasters for source IDs not in `liveIds`. The engine calls
|
|
80
|
+
* it before each frame reads its sources.
|
|
89
81
|
*/
|
|
90
82
|
release(liveIds: any): Promise<void>;
|
|
91
83
|
dispose(): Promise<void>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Answers per-frame source requests with decoded VideoFrames; Canvas2D premultiplied RGBA remains
|
|
2
|
-
// for text rasters and for
|
|
2
|
+
// for text rasters and for engines that cannot take a VideoFrame.
|
|
3
3
|
//
|
|
4
|
-
// Still and text rasters share one LRU cache
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
// cannot open or frames that keep failing (`decodeFallbacks`).
|
|
4
|
+
// Still and text rasters share one byte-bounded LRU cache, but rasters the current frame reads are
|
|
5
|
+
// never evicted, even past the budget. Decoder cursors are scoped per clip consumer so overlapping
|
|
6
|
+
// uses of one source cannot seek each other. An `HTMLVideoElement` seek is the fallback for codecs
|
|
7
|
+
// WebCodecs cannot open or frames that keep failing.
|
|
8
|
+
import { activeTimeout } from "alpha2/active-clock";
|
|
10
9
|
import { decoderCursorKey } from "alpha2/frame-supply";
|
|
11
10
|
import { MediabunnyVideoDecoder } from "alpha2/mediabunny";
|
|
12
11
|
import { containRect, seekVideoFrame } from "./preview-utils.js";
|
|
@@ -17,8 +16,8 @@ const MAX_DECODE_FAILURES = 3;
|
|
|
17
16
|
/** Default byte budget of still and text rasters, matching the frame supply's image cache. */
|
|
18
17
|
export const DEFAULT_RASTER_BUDGET_BYTES = 256 * 1024 * 1024;
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* Default byte budget for open extension sources (decoded frames in the provider module plus the
|
|
20
|
+
* last shown frame), matching the native host's `providerSourceBytes`.
|
|
22
21
|
*/
|
|
23
22
|
export const DEFAULT_PROVIDER_SOURCE_BYTES = 512 * 1024 * 1024;
|
|
24
23
|
/** The host side of the engine's per-frame source requests for one renderer (preview or export). */
|
|
@@ -29,29 +28,27 @@ export class SourcePixels {
|
|
|
29
28
|
#seekVideos = new Map();
|
|
30
29
|
/**
|
|
31
30
|
* Rasters by asset ID in LRU order: `{ key, raster, bytes, frame }`, where `key` is what the
|
|
32
|
-
* raster was made from and `frame` the frame that
|
|
31
|
+
* raster was made from and `frame` the last frame that read it.
|
|
33
32
|
*/
|
|
34
33
|
#rasters = new Map();
|
|
35
34
|
#rasterBytes = 0;
|
|
36
|
-
/**
|
|
35
|
+
/** Frame counter; the engine releases once before each frame reads its sources. */
|
|
37
36
|
#frame = 0;
|
|
38
37
|
#staging = null;
|
|
39
|
-
/** What fell back from WebCodecs decoding, by source (see `decodeFallbacks`). */
|
|
40
38
|
#fallbacks = new Map();
|
|
41
|
-
/**
|
|
39
|
+
/** Open extension sources by `providerKey`, least recently shown first. */
|
|
42
40
|
#providers = new Map();
|
|
43
|
-
/** Sources the provider budget closed and a later frame opened again. */
|
|
44
41
|
#providerReopens = 0;
|
|
45
|
-
/** Asset IDs by `providerKey` of sources the
|
|
42
|
+
/** Asset IDs by `providerKey` of sources the budget closed, until they reopen. */
|
|
46
43
|
#providersClosed = new Map();
|
|
47
44
|
/**
|
|
48
|
-
* Per animated-image asset, `{ asset, provider, opened }`:
|
|
49
|
-
*
|
|
45
|
+
* Per animated-image asset, `{ asset, provider, opened }`: one opened reader whose file and kept
|
|
46
|
+
* frames all its readers share (see `#openReader`).
|
|
50
47
|
*/
|
|
51
48
|
#readerMakers = new Map();
|
|
52
|
-
/** The fonts
|
|
49
|
+
/** The engine's caption fonts, which SVG text draws with (see `setFonts`). */
|
|
53
50
|
#fonts = [];
|
|
54
|
-
/**
|
|
51
|
+
/** Each SVG's content identity with the fonts it was drawn with, for `contentOf`. */
|
|
55
52
|
#fontContents = new WeakMap();
|
|
56
53
|
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionsWasmUrl, videoDecode = "auto", } = {}) {
|
|
57
54
|
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
@@ -66,10 +63,9 @@ export class SourcePixels {
|
|
|
66
63
|
this.library = library;
|
|
67
64
|
this.extensionsWasmUrl = extensionsWasmUrl;
|
|
68
65
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* `decodeFallbacks`.
|
|
66
|
+
* `"auto"` lets the browser pick, hardware where available; `"software"` decodes on the CPU so
|
|
67
|
+
* no frame needs a GPU readback. Sources without a software decoder decode as `"auto"` and are
|
|
68
|
+
* reported in `decodeFallbacks`.
|
|
73
69
|
*/
|
|
74
70
|
this.videoDecode = videoDecode;
|
|
75
71
|
}
|
|
@@ -102,9 +98,8 @@ export class SourcePixels {
|
|
|
102
98
|
this.#dropRaster(id, entry);
|
|
103
99
|
}
|
|
104
100
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* opened with other fonts opens again on its next frame; other sources are not touched.
|
|
101
|
+
* Sets the fonts SVG text draws with, in fallback order (the engine's caption stack, `{ bytes }`
|
|
102
|
+
* each), as the native host does. An SVG opened with other fonts reopens on its next frame.
|
|
108
103
|
*/
|
|
109
104
|
setFonts(fonts) {
|
|
110
105
|
if (sameFonts(this.#fonts, fonts))
|
|
@@ -112,9 +107,8 @@ export class SourcePixels {
|
|
|
112
107
|
this.#fonts = [...fonts];
|
|
113
108
|
}
|
|
114
109
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* neither changes.
|
|
110
|
+
* A source's content identity for `FrameSupply`'s `contentOf`: its runtime asset, plus the fonts
|
|
111
|
+
* for an SVG so a font change redraws it. Stable while neither changes.
|
|
118
112
|
*/
|
|
119
113
|
contentOf(asset) {
|
|
120
114
|
if (!asset || !drawsText(asset.provider))
|
|
@@ -126,17 +120,15 @@ export class SourcePixels {
|
|
|
126
120
|
this.#fontContents.set(asset, content);
|
|
127
121
|
return content;
|
|
128
122
|
}
|
|
129
|
-
/** Drops the cached raster of `assetId`, so its next read makes it again. */
|
|
130
123
|
invalidate(assetId) {
|
|
131
124
|
const entry = this.#rasters.get(assetId);
|
|
132
125
|
if (entry)
|
|
133
126
|
this.#dropRaster(assetId, entry);
|
|
134
127
|
}
|
|
135
128
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* the CPU (see `#softwareFrame`).
|
|
129
|
+
* `FrameSupply`'s `pixelsFor` callback. `sourceId` is the source the engine asked for, which the
|
|
130
|
+
* layer may stand in for (a proxy has its own ID); decoders are kept per source, as `release`
|
|
131
|
+
* names them. `decode: "software"` asks for a CPU-decoded frame (see `#softwareFrame`).
|
|
140
132
|
*/
|
|
141
133
|
pixelsFor = async (layer, seconds, { preferVideoFrame = false, consumerId = layer.id, sourceId, decode } = {}) => {
|
|
142
134
|
const asset = layer.asset ?? layer;
|
|
@@ -153,8 +145,8 @@ export class SourcePixels {
|
|
|
153
145
|
/** A frame an extension provider draws at its own size; `key` is its open source. */
|
|
154
146
|
async #providerPixels(asset, key, seconds, reopened = false) {
|
|
155
147
|
let opened = this.#providers.get(key);
|
|
156
|
-
//
|
|
157
|
-
//
|
|
148
|
+
// Reopen when the asset, its provider settings or an SVG's fonts change. Providers compare by
|
|
149
|
+
// identity first so a shown frame does not serialize them.
|
|
158
150
|
const { provider } = asset;
|
|
159
151
|
const fonts = drawsText(provider) ? this.#fonts : null;
|
|
160
152
|
if (opened?.asset !== asset ||
|
|
@@ -170,7 +162,7 @@ export class SourcePixels {
|
|
|
170
162
|
? this.#openReader(asset)
|
|
171
163
|
: openProvider(asset, this.extensionsWasmUrl, fonts),
|
|
172
164
|
};
|
|
173
|
-
// Keep
|
|
165
|
+
// Keep provider reports, but retry load or read failures next frame.
|
|
174
166
|
opening.source.catch((error) => {
|
|
175
167
|
if (retryableOpen.has(error) && this.#providers.get(key) === opening)
|
|
176
168
|
this.#providers.delete(key);
|
|
@@ -180,7 +172,7 @@ export class SourcePixels {
|
|
|
180
172
|
if (this.#providersClosed.delete(key))
|
|
181
173
|
this.#providerReopens += 1;
|
|
182
174
|
}
|
|
183
|
-
//
|
|
175
|
+
// The budget keeps it for this frame and the next.
|
|
184
176
|
opened.frame = this.#frame;
|
|
185
177
|
this.#providers.delete(key);
|
|
186
178
|
this.#providers.set(key, opened);
|
|
@@ -188,8 +180,8 @@ export class SourcePixels {
|
|
|
188
180
|
opened.open = source;
|
|
189
181
|
const ticks = BigInt(Math.round(seconds * TICKS_PER_SECOND));
|
|
190
182
|
const fit = { width: this.#width, height: this.#height };
|
|
191
|
-
// The frame
|
|
192
|
-
//
|
|
183
|
+
// The last frame answers every time it covers as the same object, so a still is not uploaded
|
|
184
|
+
// again each frame.
|
|
193
185
|
const shown = opened.shown;
|
|
194
186
|
if (shown &&
|
|
195
187
|
shown.width === fit.width &&
|
|
@@ -199,11 +191,11 @@ export class SourcePixels {
|
|
|
199
191
|
return shown.result;
|
|
200
192
|
let frame;
|
|
201
193
|
try {
|
|
202
|
-
//
|
|
194
|
+
// Image sequence frames enter the provider module for this render only.
|
|
203
195
|
frame = await extensions.withResources(read, () => source.needs(ticks), () => source.render(ticks, fit));
|
|
204
196
|
}
|
|
205
197
|
catch (error) {
|
|
206
|
-
// The provider module restarted after another source stopped it
|
|
198
|
+
// The provider module restarted after another source stopped it, so reopen this one.
|
|
207
199
|
if (error?.name !== "StaleExtensionSourceError" || reopened)
|
|
208
200
|
throw error;
|
|
209
201
|
if (this.#providers.get(key) === opened)
|
|
@@ -234,8 +226,8 @@ export class SourcePixels {
|
|
|
234
226
|
return result;
|
|
235
227
|
}
|
|
236
228
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
229
|
+
* An animated-image reader of its own (see `providerKey`), made from what the asset's readers
|
|
230
|
+
* share so the file is decoded once, as on the native host.
|
|
239
231
|
*/
|
|
240
232
|
async #openReader(asset) {
|
|
241
233
|
const { provider } = asset;
|
|
@@ -249,7 +241,7 @@ export class SourcePixels {
|
|
|
249
241
|
return { source, extensions, read };
|
|
250
242
|
}
|
|
251
243
|
catch {
|
|
252
|
-
//
|
|
244
|
+
// The maker failed to open or a module restart left it stale, so open again.
|
|
253
245
|
}
|
|
254
246
|
if (this.#readerMakers.get(asset.id) === made)
|
|
255
247
|
this.#dropReaderMaker(asset.id);
|
|
@@ -273,7 +265,7 @@ export class SourcePixels {
|
|
|
273
265
|
this.#readerMakers.set(asset.id, entry);
|
|
274
266
|
return opening;
|
|
275
267
|
}
|
|
276
|
-
/**
|
|
268
|
+
/** Drops what makes an animated image's readers; readers already made stay open. */
|
|
277
269
|
#dropReaderMaker(assetId) {
|
|
278
270
|
const made = this.#readerMakers.get(assetId);
|
|
279
271
|
if (!made)
|
|
@@ -281,7 +273,7 @@ export class SourcePixels {
|
|
|
281
273
|
this.#readerMakers.delete(assetId);
|
|
282
274
|
made.opened.then(({ maker }) => maker?.release()).catch(() => { });
|
|
283
275
|
}
|
|
284
|
-
/**
|
|
276
|
+
/** Drops reader makers no open source reads. */
|
|
285
277
|
#dropUnreadMakers() {
|
|
286
278
|
if (this.#readerMakers.size === 0)
|
|
287
279
|
return;
|
|
@@ -292,7 +284,7 @@ export class SourcePixels {
|
|
|
292
284
|
if (!read.has(assetId))
|
|
293
285
|
this.#dropReaderMaker(assetId);
|
|
294
286
|
}
|
|
295
|
-
/**
|
|
287
|
+
/** Bytes open extension sources hold; an animated image's shared file counts once per asset. */
|
|
296
288
|
#providerBytes() {
|
|
297
289
|
let bytes = 0;
|
|
298
290
|
const shared = new Map();
|
|
@@ -309,8 +301,8 @@ export class SourcePixels {
|
|
|
309
301
|
return bytes;
|
|
310
302
|
}
|
|
311
303
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
304
|
+
* Closes least recently shown extension sources until within `providerSourceBytes`. Sources shown
|
|
305
|
+
* by this frame or the previous one stay open even past the budget.
|
|
314
306
|
*/
|
|
315
307
|
#boundProviders() {
|
|
316
308
|
let bytes = this.#providerBytes();
|
|
@@ -339,8 +331,8 @@ export class SourcePixels {
|
|
|
339
331
|
return this.#staging.getContext("2d", { willReadFrequently: true });
|
|
340
332
|
}
|
|
341
333
|
/**
|
|
342
|
-
* The raster `make` makes for `id` from `key`, cached while `key` is unchanged.
|
|
343
|
-
*
|
|
334
|
+
* The raster `make` makes for `id` from `key`, cached while `key` is unchanged. Rasters the
|
|
335
|
+
* current frame read are not evicted until a later frame; failures are not cached.
|
|
344
336
|
*/
|
|
345
337
|
#cachedRaster(id, key, make) {
|
|
346
338
|
let entry = this.#rasters.get(id);
|
|
@@ -375,8 +367,8 @@ export class SourcePixels {
|
|
|
375
367
|
this.#rasters.delete(id);
|
|
376
368
|
}
|
|
377
369
|
/**
|
|
378
|
-
* Evicts
|
|
379
|
-
*
|
|
370
|
+
* Evicts least recently used rasters the current frame has not read, until within budget or only
|
|
371
|
+
* this frame's remain.
|
|
380
372
|
*/
|
|
381
373
|
#evictRasters() {
|
|
382
374
|
for (const [id, entry] of this.#rasters) {
|
|
@@ -485,7 +477,7 @@ export class SourcePixels {
|
|
|
485
477
|
return null;
|
|
486
478
|
const cursor = decoderCursorKey(sourceId, consumerId);
|
|
487
479
|
let decoder = this.#decoders.get(cursor);
|
|
488
|
-
// The source now reads other media (
|
|
480
|
+
// The source now reads other media (proxy or original), so the cursor starts over.
|
|
489
481
|
if (decoder && decoder.asset !== asset) {
|
|
490
482
|
await closeDecoder(decoder);
|
|
491
483
|
this.#decoders.delete(cursor);
|
|
@@ -511,7 +503,7 @@ export class SourcePixels {
|
|
|
511
503
|
this.#fallbacks.get(sourceId).frames += 1;
|
|
512
504
|
return null;
|
|
513
505
|
}
|
|
514
|
-
// A decoder that cannot open (
|
|
506
|
+
// A decoder that cannot open (unsupported codec) falls back for good.
|
|
515
507
|
try {
|
|
516
508
|
decoder.video ??= await (decoder.opening ??= this.#openVideo(decoder));
|
|
517
509
|
}
|
|
@@ -530,7 +522,7 @@ export class SourcePixels {
|
|
|
530
522
|
decoded = await decoder.video.refill(request);
|
|
531
523
|
}
|
|
532
524
|
catch {
|
|
533
|
-
//
|
|
525
|
+
// Retry a failed read (stall, decoder error) once with a new decoder, which a stalled
|
|
534
526
|
// decoder's surfaces do not hold up.
|
|
535
527
|
closeOpened(decoder);
|
|
536
528
|
try {
|
|
@@ -556,17 +548,16 @@ export class SourcePixels {
|
|
|
556
548
|
chromaSiting: decoded.chromaSiting,
|
|
557
549
|
};
|
|
558
550
|
}
|
|
559
|
-
/** Decoder cursors the budget counts
|
|
551
|
+
/** Decoder cursors the budget counts; a software cursor beside its consumer's is not counted. */
|
|
560
552
|
#cursorCount() {
|
|
561
|
-
|
|
553
|
+
const consumers = new Set();
|
|
562
554
|
for (const decoder of this.#decoders.values())
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return count;
|
|
555
|
+
consumers.add(decoderCursorKey(decoder.sourceId, decoder.consumerId));
|
|
556
|
+
return consumers.size;
|
|
566
557
|
}
|
|
567
558
|
/**
|
|
568
|
-
* Opens `decoder`'s source
|
|
569
|
-
*
|
|
559
|
+
* Opens `decoder`'s source per `videoDecode`. A source with no software decoder opens as
|
|
560
|
+
* `"auto"` for good and is reported once in `decodeFallbacks`.
|
|
570
561
|
*/
|
|
571
562
|
async #openVideo(decoder) {
|
|
572
563
|
const { asset } = decoder;
|
|
@@ -594,18 +585,19 @@ export class SourcePixels {
|
|
|
594
585
|
}
|
|
595
586
|
}
|
|
596
587
|
/**
|
|
597
|
-
* The frame at `seconds` decoded on the CPU, on
|
|
598
|
-
* `FrameSupply`
|
|
599
|
-
*
|
|
588
|
+
* The frame at `seconds` decoded on the CPU, on its own cursor beside the consumer's, for when
|
|
589
|
+
* `FrameSupply` could not read a hardware frame back. Rejects rather than falling back to an
|
|
590
|
+
* element seek, whose frame would be the browser's again.
|
|
600
591
|
*
|
|
601
|
-
* The cursor shares the consumer's
|
|
602
|
-
*
|
|
603
|
-
*
|
|
592
|
+
* The cursor shares the consumer's IDs, so `retainConsumers` and `release` close it with the
|
|
593
|
+
* consumer's. It stays open between frames because readback failures come in runs. A consumer
|
|
594
|
+
* whose frames all decode here has no other cursor, so this one opens within the budget.
|
|
604
595
|
*/
|
|
605
596
|
async #softwareFrame(asset, seconds, consumerId, sourceId) {
|
|
606
597
|
if (!asset.file)
|
|
607
598
|
throw new Error(`${asset.id} has no file to decode in software`);
|
|
608
|
-
const
|
|
599
|
+
const primary = decoderCursorKey(sourceId, consumerId);
|
|
600
|
+
const cursor = `${primary}\u0000software`;
|
|
609
601
|
let decoder = this.#decoders.get(cursor);
|
|
610
602
|
if (decoder && decoder.asset !== asset) {
|
|
611
603
|
await closeDecoder(decoder);
|
|
@@ -613,6 +605,11 @@ export class SourcePixels {
|
|
|
613
605
|
decoder = undefined;
|
|
614
606
|
}
|
|
615
607
|
if (!decoder) {
|
|
608
|
+
if (!this.#decoders.has(primary) &&
|
|
609
|
+
this.#cursorCount() >= this.decoderLimit)
|
|
610
|
+
throw Object.assign(new Error("Video decoder budget reached"), {
|
|
611
|
+
code: "resource_budget",
|
|
612
|
+
});
|
|
616
613
|
decoder = {
|
|
617
614
|
sourceId,
|
|
618
615
|
asset,
|
|
@@ -641,15 +638,11 @@ export class SourcePixels {
|
|
|
641
638
|
};
|
|
642
639
|
}
|
|
643
640
|
catch (error) {
|
|
644
|
-
// The next request opens it again.
|
|
645
641
|
closeOpened(decoder);
|
|
646
642
|
throw error;
|
|
647
643
|
}
|
|
648
644
|
}
|
|
649
|
-
/**
|
|
650
|
-
* Records that `decoder`'s frame falls back to an element seek because of `error`; `permanent`
|
|
651
|
-
* applies it to every later frame of the cursor.
|
|
652
|
-
*/
|
|
645
|
+
/** Records an element-seek fallback for `decoder`; `permanent` covers its later frames too. */
|
|
653
646
|
#fallBack(decoder, error, permanent) {
|
|
654
647
|
if (permanent)
|
|
655
648
|
decoder.failed = true;
|
|
@@ -668,18 +661,20 @@ export class SourcePixels {
|
|
|
668
661
|
return null;
|
|
669
662
|
}
|
|
670
663
|
/**
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
* (
|
|
674
|
-
* `"software-unavailable"
|
|
675
|
-
*
|
|
664
|
+
* Fallbacks per source and kind, reported by browser exports. `"element-seek"`: frames read by
|
|
665
|
+
* element seeks instead of decoding, with the last reason, count, and whether decoding stopped
|
|
666
|
+
* for good (failed to open or failed {@link MAX_DECODE_FAILURES} frames running).
|
|
667
|
+
* `"software-unavailable"`: `videoDecode: "software"` decoded as `"auto"` for lack of a software
|
|
668
|
+
* decoder (`frames` 0).
|
|
676
669
|
*/
|
|
677
670
|
get decodeFallbacks() {
|
|
678
671
|
return [...this.#fallbacks.values()].map((entry) => ({ ...entry }));
|
|
679
672
|
}
|
|
680
673
|
async #seekFallback(asset, seconds, consumerId, sourceId) {
|
|
681
674
|
if (!asset.video)
|
|
682
|
-
throw Object.assign(new Error(
|
|
675
|
+
throw Object.assign(new Error(asset.video === null
|
|
676
|
+
? `${asset.id} has no media element to seek (the browser's media pipeline could not open it)`
|
|
677
|
+
: `No worker decoder for ${asset.id}; use the main-thread media fallback`), { code: "unsupported_codec" });
|
|
683
678
|
const cursor = decoderCursorKey(sourceId, consumerId);
|
|
684
679
|
let fallback = this.#seekVideos.get(cursor);
|
|
685
680
|
if (fallback && fallback.asset !== asset) {
|
|
@@ -707,7 +702,7 @@ export class SourcePixels {
|
|
|
707
702
|
await seekVideoFrame(video, Math.min(Math.max(0, seconds), Math.max(0, duration - 1e-3)));
|
|
708
703
|
return video;
|
|
709
704
|
}
|
|
710
|
-
/** Keeps decoder sessions
|
|
705
|
+
/** Keeps decoder sessions to the consumers the current frame needs. */
|
|
711
706
|
retainConsumers = async (liveConsumerIds) => {
|
|
712
707
|
for (const [cursor, decoder] of this.#decoders) {
|
|
713
708
|
if (liveConsumerIds.has(decoder.consumerId))
|
|
@@ -723,8 +718,8 @@ export class SourcePixels {
|
|
|
723
718
|
}
|
|
724
719
|
};
|
|
725
720
|
/**
|
|
726
|
-
* Drops decoders, extension sources
|
|
727
|
-
*
|
|
721
|
+
* Drops decoders, extension sources and rasters for source IDs not in `liveIds`. The engine calls
|
|
722
|
+
* it before each frame reads its sources.
|
|
728
723
|
*/
|
|
729
724
|
async release(liveIds) {
|
|
730
725
|
this.#frame += 1;
|
|
@@ -759,13 +754,13 @@ export class SourcePixels {
|
|
|
759
754
|
await this.release(new Set());
|
|
760
755
|
}
|
|
761
756
|
}
|
|
762
|
-
/** Whether two raster keys
|
|
757
|
+
/** Whether two raster keys match field by field (same objects and sizes). */
|
|
763
758
|
function sameKey(a, b) {
|
|
764
759
|
const fields = Object.keys(a);
|
|
765
760
|
return (fields.length === Object.keys(b).length &&
|
|
766
761
|
fields.every((field) => Object.is(a[field], b[field])));
|
|
767
762
|
}
|
|
768
|
-
/**
|
|
763
|
+
/** Bytes a raster holds: a text raster's pixels, or a still's raster frame. */
|
|
769
764
|
function rasterBytes(raster) {
|
|
770
765
|
return (raster.pixels ?? raster).byteLength;
|
|
771
766
|
}
|
|
@@ -776,13 +771,13 @@ async function closeDecoder(decoder) {
|
|
|
776
771
|
decoder.video = null;
|
|
777
772
|
decoder.opening = null;
|
|
778
773
|
}
|
|
779
|
-
/** Closes a cursor's opened decoder
|
|
774
|
+
/** Closes a cursor's opened decoder so its next read opens another. */
|
|
780
775
|
function closeOpened(decoder) {
|
|
781
776
|
decoder.video?.close();
|
|
782
777
|
decoder.video = null;
|
|
783
778
|
decoder.opening = null;
|
|
784
779
|
}
|
|
785
|
-
/**
|
|
780
|
+
/** Releases a fallback seek element's media. */
|
|
786
781
|
function unloadVideo(video) {
|
|
787
782
|
video.removeAttribute("src");
|
|
788
783
|
video.load();
|
|
@@ -799,8 +794,9 @@ function premultiplyInPlace(pixels) {
|
|
|
799
794
|
}
|
|
800
795
|
function waitForLoad(video) {
|
|
801
796
|
return new Promise((resolve, reject) => {
|
|
797
|
+
const timer = new AbortController();
|
|
802
798
|
const cleanup = () => {
|
|
803
|
-
|
|
799
|
+
timer.abort();
|
|
804
800
|
video.removeEventListener("loadeddata", ready);
|
|
805
801
|
video.removeEventListener("error", failed);
|
|
806
802
|
};
|
|
@@ -812,19 +808,20 @@ function waitForLoad(video) {
|
|
|
812
808
|
cleanup();
|
|
813
809
|
reject(video.error ?? new Error("video load failed"));
|
|
814
810
|
};
|
|
815
|
-
|
|
811
|
+
// Active time, so a page frozen while the element loads does not time out.
|
|
812
|
+
void activeTimeout(10_000, timer.signal).then(() => {
|
|
816
813
|
cleanup();
|
|
817
814
|
reject(new Error("video load timed out"));
|
|
818
|
-
}
|
|
815
|
+
});
|
|
819
816
|
video.addEventListener("loadeddata", ready, { once: true });
|
|
820
817
|
video.addEventListener("error", failed, { once: true });
|
|
821
818
|
video.load();
|
|
822
819
|
});
|
|
823
820
|
}
|
|
824
821
|
/**
|
|
825
|
-
* Which open extension source answers `consumerId`'s read of `asset`.
|
|
826
|
-
* order and
|
|
827
|
-
*
|
|
822
|
+
* Which open extension source answers `consumerId`'s read of `asset`. Animated images decode in
|
|
823
|
+
* order and keep only a window of frames, so each reader gets its own; other providers share one
|
|
824
|
+
* source, as on the native host.
|
|
828
825
|
*/
|
|
829
826
|
function providerKey(asset, consumerId) {
|
|
830
827
|
return asset.provider.format === "animated_image"
|
|
@@ -833,10 +830,7 @@ function providerKey(asset, consumerId) {
|
|
|
833
830
|
}
|
|
834
831
|
/** Serialized settings by provider object; settings are never mutated, so each serializes once. */
|
|
835
832
|
const providerSettingsKeys = new WeakMap();
|
|
836
|
-
/**
|
|
837
|
-
* `provider`'s settings as one comparable string, serialized once per provider object: an image
|
|
838
|
-
* sequence's holds every frame's locator.
|
|
839
|
-
*/
|
|
833
|
+
/** `provider`'s settings as one comparable string, serialized once per provider object. */
|
|
840
834
|
export function providerSettings(provider) {
|
|
841
835
|
if (provider === null || typeof provider !== "object")
|
|
842
836
|
return JSON.stringify(provider ?? null);
|
|
@@ -847,11 +841,10 @@ export function providerSettings(provider) {
|
|
|
847
841
|
}
|
|
848
842
|
return key;
|
|
849
843
|
}
|
|
850
|
-
/** Results of {@link sameProviderSettings}, by the first provider, then the second. */
|
|
851
844
|
const providerSettingsEqual = new WeakMap();
|
|
852
845
|
/**
|
|
853
|
-
* Whether two providers have
|
|
854
|
-
*
|
|
846
|
+
* Whether two providers have equal settings. Each pair is compared once, so per-frame checks cost
|
|
847
|
+
* no serialization.
|
|
855
848
|
*/
|
|
856
849
|
export function sameProviderSettings(a, b) {
|
|
857
850
|
if (a === b)
|
|
@@ -878,11 +871,11 @@ function sameFonts(a, b) {
|
|
|
878
871
|
return (a.length === b.length &&
|
|
879
872
|
a.every((font, index) => font.bytes === b[index].bytes));
|
|
880
873
|
}
|
|
881
|
-
/**
|
|
874
|
+
/** {@link openProvider} errors (module load or file read) a later open may not hit. */
|
|
882
875
|
const retryableOpen = new WeakSet();
|
|
883
876
|
/**
|
|
884
|
-
* Opens an asset's extension source, an SVG with `fonts`.
|
|
885
|
-
*
|
|
877
|
+
* Opens an asset's extension source, an SVG with `fonts`. Image sequence frames enter the provider
|
|
878
|
+
* module only for the call that reads them.
|
|
886
879
|
*/
|
|
887
880
|
async function openProvider(asset, wasmUrl, fonts) {
|
|
888
881
|
const retryable = (error) => {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* the renderer's 16-byte canary, what a readback ticket reports as `retainedBytes`.
|
|
2
|
+
* Staged bytes of the engine's I420 readback (planes plus canary), as a ticket's `retainedBytes`.
|
|
4
3
|
*/
|
|
5
4
|
export function estimatedStagingBytes(width: any, height: any): number;
|
|
6
|
-
/**
|
|
7
|
-
* The least an export of `width`x`height` frames can run with in flight: one frame's readback
|
|
8
|
-
* staged and the packed copy of one frame the encoder holds.
|
|
9
|
-
*/
|
|
5
|
+
/** The minimum in-flight bytes of an export: one staged readback plus one packed encoder frame. */
|
|
10
6
|
export function minimumExportWorkingSet(width: any, height: any): number;
|