@alpha2-sh/editor 0.4.6 → 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 +396 -312
- 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 +47 -28
- package/dist/browser/runtime/assets.js +129 -45
- 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 +39 -44
- package/dist/browser/runtime/engine.js +78 -64
- 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 +85 -103
- 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 +233 -238
- package/dist/browser/worker.d.ts +8 -9
- package/dist/browser/worker.js +50 -21
- 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 +64 -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 -20
- 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,10 +548,7 @@ export class SourcePixels {
|
|
|
556
548
|
chromaSiting: decoded.chromaSiting,
|
|
557
549
|
};
|
|
558
550
|
}
|
|
559
|
-
/**
|
|
560
|
-
* Decoder cursors the budget counts, one per consumer: a software cursor beside its consumer's
|
|
561
|
-
* own cursor is not counted again.
|
|
562
|
-
*/
|
|
551
|
+
/** Decoder cursors the budget counts; a software cursor beside its consumer's is not counted. */
|
|
563
552
|
#cursorCount() {
|
|
564
553
|
const consumers = new Set();
|
|
565
554
|
for (const decoder of this.#decoders.values())
|
|
@@ -567,8 +556,8 @@ export class SourcePixels {
|
|
|
567
556
|
return consumers.size;
|
|
568
557
|
}
|
|
569
558
|
/**
|
|
570
|
-
* Opens `decoder`'s source
|
|
571
|
-
*
|
|
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`.
|
|
572
561
|
*/
|
|
573
562
|
async #openVideo(decoder) {
|
|
574
563
|
const { asset } = decoder;
|
|
@@ -596,14 +585,13 @@ export class SourcePixels {
|
|
|
596
585
|
}
|
|
597
586
|
}
|
|
598
587
|
/**
|
|
599
|
-
* The frame at `seconds` decoded on the CPU, on
|
|
600
|
-
* `FrameSupply`
|
|
601
|
-
*
|
|
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.
|
|
602
591
|
*
|
|
603
|
-
* The cursor shares the consumer's
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
* the browser decodes to opaque frames) has no other cursor, so this one opens within the budget.
|
|
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.
|
|
607
595
|
*/
|
|
608
596
|
async #softwareFrame(asset, seconds, consumerId, sourceId) {
|
|
609
597
|
if (!asset.file)
|
|
@@ -650,15 +638,11 @@ export class SourcePixels {
|
|
|
650
638
|
};
|
|
651
639
|
}
|
|
652
640
|
catch (error) {
|
|
653
|
-
// The next request opens it again.
|
|
654
641
|
closeOpened(decoder);
|
|
655
642
|
throw error;
|
|
656
643
|
}
|
|
657
644
|
}
|
|
658
|
-
/**
|
|
659
|
-
* Records that `decoder`'s frame falls back to an element seek because of `error`; `permanent`
|
|
660
|
-
* applies it to every later frame of the cursor.
|
|
661
|
-
*/
|
|
645
|
+
/** Records an element-seek fallback for `decoder`; `permanent` covers its later frames too. */
|
|
662
646
|
#fallBack(decoder, error, permanent) {
|
|
663
647
|
if (permanent)
|
|
664
648
|
decoder.failed = true;
|
|
@@ -677,11 +661,11 @@ export class SourcePixels {
|
|
|
677
661
|
return null;
|
|
678
662
|
}
|
|
679
663
|
/**
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* (
|
|
683
|
-
* `"software-unavailable"
|
|
684
|
-
*
|
|
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).
|
|
685
669
|
*/
|
|
686
670
|
get decodeFallbacks() {
|
|
687
671
|
return [...this.#fallbacks.values()].map((entry) => ({ ...entry }));
|
|
@@ -718,7 +702,7 @@ export class SourcePixels {
|
|
|
718
702
|
await seekVideoFrame(video, Math.min(Math.max(0, seconds), Math.max(0, duration - 1e-3)));
|
|
719
703
|
return video;
|
|
720
704
|
}
|
|
721
|
-
/** Keeps decoder sessions
|
|
705
|
+
/** Keeps decoder sessions to the consumers the current frame needs. */
|
|
722
706
|
retainConsumers = async (liveConsumerIds) => {
|
|
723
707
|
for (const [cursor, decoder] of this.#decoders) {
|
|
724
708
|
if (liveConsumerIds.has(decoder.consumerId))
|
|
@@ -734,8 +718,8 @@ export class SourcePixels {
|
|
|
734
718
|
}
|
|
735
719
|
};
|
|
736
720
|
/**
|
|
737
|
-
* Drops decoders, extension sources
|
|
738
|
-
*
|
|
721
|
+
* Drops decoders, extension sources and rasters for source IDs not in `liveIds`. The engine calls
|
|
722
|
+
* it before each frame reads its sources.
|
|
739
723
|
*/
|
|
740
724
|
async release(liveIds) {
|
|
741
725
|
this.#frame += 1;
|
|
@@ -770,13 +754,13 @@ export class SourcePixels {
|
|
|
770
754
|
await this.release(new Set());
|
|
771
755
|
}
|
|
772
756
|
}
|
|
773
|
-
/** Whether two raster keys
|
|
757
|
+
/** Whether two raster keys match field by field (same objects and sizes). */
|
|
774
758
|
function sameKey(a, b) {
|
|
775
759
|
const fields = Object.keys(a);
|
|
776
760
|
return (fields.length === Object.keys(b).length &&
|
|
777
761
|
fields.every((field) => Object.is(a[field], b[field])));
|
|
778
762
|
}
|
|
779
|
-
/**
|
|
763
|
+
/** Bytes a raster holds: a text raster's pixels, or a still's raster frame. */
|
|
780
764
|
function rasterBytes(raster) {
|
|
781
765
|
return (raster.pixels ?? raster).byteLength;
|
|
782
766
|
}
|
|
@@ -787,13 +771,13 @@ async function closeDecoder(decoder) {
|
|
|
787
771
|
decoder.video = null;
|
|
788
772
|
decoder.opening = null;
|
|
789
773
|
}
|
|
790
|
-
/** Closes a cursor's opened decoder
|
|
774
|
+
/** Closes a cursor's opened decoder so its next read opens another. */
|
|
791
775
|
function closeOpened(decoder) {
|
|
792
776
|
decoder.video?.close();
|
|
793
777
|
decoder.video = null;
|
|
794
778
|
decoder.opening = null;
|
|
795
779
|
}
|
|
796
|
-
/**
|
|
780
|
+
/** Releases a fallback seek element's media. */
|
|
797
781
|
function unloadVideo(video) {
|
|
798
782
|
video.removeAttribute("src");
|
|
799
783
|
video.load();
|
|
@@ -810,8 +794,9 @@ function premultiplyInPlace(pixels) {
|
|
|
810
794
|
}
|
|
811
795
|
function waitForLoad(video) {
|
|
812
796
|
return new Promise((resolve, reject) => {
|
|
797
|
+
const timer = new AbortController();
|
|
813
798
|
const cleanup = () => {
|
|
814
|
-
|
|
799
|
+
timer.abort();
|
|
815
800
|
video.removeEventListener("loadeddata", ready);
|
|
816
801
|
video.removeEventListener("error", failed);
|
|
817
802
|
};
|
|
@@ -823,19 +808,20 @@ function waitForLoad(video) {
|
|
|
823
808
|
cleanup();
|
|
824
809
|
reject(video.error ?? new Error("video load failed"));
|
|
825
810
|
};
|
|
826
|
-
|
|
811
|
+
// Active time, so a page frozen while the element loads does not time out.
|
|
812
|
+
void activeTimeout(10_000, timer.signal).then(() => {
|
|
827
813
|
cleanup();
|
|
828
814
|
reject(new Error("video load timed out"));
|
|
829
|
-
}
|
|
815
|
+
});
|
|
830
816
|
video.addEventListener("loadeddata", ready, { once: true });
|
|
831
817
|
video.addEventListener("error", failed, { once: true });
|
|
832
818
|
video.load();
|
|
833
819
|
});
|
|
834
820
|
}
|
|
835
821
|
/**
|
|
836
|
-
* Which open extension source answers `consumerId`'s read of `asset`.
|
|
837
|
-
* order and
|
|
838
|
-
*
|
|
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.
|
|
839
825
|
*/
|
|
840
826
|
function providerKey(asset, consumerId) {
|
|
841
827
|
return asset.provider.format === "animated_image"
|
|
@@ -844,10 +830,7 @@ function providerKey(asset, consumerId) {
|
|
|
844
830
|
}
|
|
845
831
|
/** Serialized settings by provider object; settings are never mutated, so each serializes once. */
|
|
846
832
|
const providerSettingsKeys = new WeakMap();
|
|
847
|
-
/**
|
|
848
|
-
* `provider`'s settings as one comparable string, serialized once per provider object: an image
|
|
849
|
-
* sequence's holds every frame's locator.
|
|
850
|
-
*/
|
|
833
|
+
/** `provider`'s settings as one comparable string, serialized once per provider object. */
|
|
851
834
|
export function providerSettings(provider) {
|
|
852
835
|
if (provider === null || typeof provider !== "object")
|
|
853
836
|
return JSON.stringify(provider ?? null);
|
|
@@ -858,11 +841,10 @@ export function providerSettings(provider) {
|
|
|
858
841
|
}
|
|
859
842
|
return key;
|
|
860
843
|
}
|
|
861
|
-
/** Results of {@link sameProviderSettings}, by the first provider, then the second. */
|
|
862
844
|
const providerSettingsEqual = new WeakMap();
|
|
863
845
|
/**
|
|
864
|
-
* Whether two providers have
|
|
865
|
-
*
|
|
846
|
+
* Whether two providers have equal settings. Each pair is compared once, so per-frame checks cost
|
|
847
|
+
* no serialization.
|
|
866
848
|
*/
|
|
867
849
|
export function sameProviderSettings(a, b) {
|
|
868
850
|
if (a === b)
|
|
@@ -889,11 +871,11 @@ function sameFonts(a, b) {
|
|
|
889
871
|
return (a.length === b.length &&
|
|
890
872
|
a.every((font, index) => font.bytes === b[index].bytes));
|
|
891
873
|
}
|
|
892
|
-
/**
|
|
874
|
+
/** {@link openProvider} errors (module load or file read) a later open may not hit. */
|
|
893
875
|
const retryableOpen = new WeakSet();
|
|
894
876
|
/**
|
|
895
|
-
* Opens an asset's extension source, an SVG with `fonts`.
|
|
896
|
-
*
|
|
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.
|
|
897
879
|
*/
|
|
898
880
|
async function openProvider(asset, wasmUrl, fonts) {
|
|
899
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;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// What an export frame holds in flight, computed without loading the runtime.
|
|
2
|
-
// `tests/cases/staging-bytes-corpus.json
|
|
1
|
+
// What an export frame holds in flight, computed without loading the runtime. Checked against the
|
|
2
|
+
// renderer's `yuv420p_staging_bytes` by `tests/cases/staging-bytes-corpus.json`.
|
|
3
3
|
/** The canary the renderer stages after the planes, to prove the GPU wrote them. */
|
|
4
4
|
const CANARY_BYTES = 16;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* alignment
|
|
8
|
-
*
|
|
6
|
+
* Plane bytes of a `width`x`height` I420 readback as the renderer lays them out: rows padded to
|
|
7
|
+
* 256-byte copy alignment, each plane on a 512-byte boundary. The packed encoder frame is this
|
|
8
|
+
* long.
|
|
9
9
|
*/
|
|
10
10
|
function planeBytes(width, height) {
|
|
11
11
|
const row = (bytes) => Math.ceil(bytes / 256) * 256;
|
|
@@ -17,16 +17,12 @@ function planeBytes(width, height) {
|
|
|
17
17
|
return v + chroma;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* the renderer's 16-byte canary, what a readback ticket reports as `retainedBytes`.
|
|
20
|
+
* Staged bytes of the engine's I420 readback (planes plus canary), as a ticket's `retainedBytes`.
|
|
22
21
|
*/
|
|
23
22
|
export function estimatedStagingBytes(width, height) {
|
|
24
23
|
return planeBytes(width, height) + CANARY_BYTES;
|
|
25
24
|
}
|
|
26
|
-
/**
|
|
27
|
-
* The least an export of `width`x`height` frames can run with in flight: one frame's readback
|
|
28
|
-
* staged and the packed copy of one frame the encoder holds.
|
|
29
|
-
*/
|
|
25
|
+
/** The minimum in-flight bytes of an export: one staged readback plus one packed encoder frame. */
|
|
30
26
|
export function minimumExportWorkingSet(width, height) {
|
|
31
27
|
return estimatedStagingBytes(width, height) + planeBytes(width, height);
|
|
32
28
|
}
|