@alpha2-sh/editor 0.4.6 → 0.5.1
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 +393 -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 +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- 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 +44 -44
- package/dist/browser/runtime/engine.js +87 -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 +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- 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 +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -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 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PlaybackClock, WebEffectRegistry } from "alpha2/wasm";
|
|
2
2
|
import { loadEngineWasm } from "./wasm.js";
|
|
3
3
|
import { FrameSupply } from "alpha2/frame-supply";
|
|
4
|
+
import { lossReportFromJson } from "alpha2/gpu-recovery";
|
|
5
|
+
import { createRenderer } from "alpha2/renderer-choice";
|
|
4
6
|
import { secondsToTicks } from "alpha2/project";
|
|
5
7
|
import { registerCaptionFonts } from "./caption-fonts.js";
|
|
6
8
|
import { drawnEffectResources } from "../../core/compositions.js";
|
|
@@ -9,7 +11,6 @@ import { EditorError } from "../../core/document.js";
|
|
|
9
11
|
const RESULT_CACHE_FRAMES = 6;
|
|
10
12
|
/** The diagnostics panel refreshes at this rate, not at the render rate. */
|
|
11
13
|
const DIAGNOSTICS_INTERVAL_MS = 250;
|
|
12
|
-
/** A runtime effect definition's identity, `id@version`, as the engine names it. */
|
|
13
14
|
const effectKey = (definition) => `${definition.id}@${definition.version}`;
|
|
14
15
|
/**
|
|
15
16
|
* The wasm renderer of one preview or export: owns the engine instance, its frame supply, and a
|
|
@@ -27,19 +28,20 @@ export class Engine {
|
|
|
27
28
|
#lastDiagnosticsAt = 0;
|
|
28
29
|
#fps = [];
|
|
29
30
|
#effectResources = new Map();
|
|
30
|
-
/** The runtime effects registered on this renderer, as `id@version`. */
|
|
31
31
|
#effects = new Set();
|
|
32
|
-
/**
|
|
32
|
+
/** Cumulative: frames the player drew, and frames equal to the one shown. */
|
|
33
33
|
#renders = 0;
|
|
34
34
|
#unchanged = 0;
|
|
35
|
-
/** What `supply` uploaded for the export frame
|
|
35
|
+
/** What `supply` uploaded for the export frame not rendered yet. */
|
|
36
36
|
#exportUploads = [];
|
|
37
|
-
constructor(canvas, sources, library, runtimeAssets = {}, { unreadableFrames, videoConversion } = {}) {
|
|
37
|
+
constructor(canvas, sources, library, runtimeAssets = {}, { unreadableFrames, videoConversion, opaqueEngineFrames, renderer = "auto", } = {}) {
|
|
38
|
+
/** `"auto"` (hardware GPU, else CPU), `"gpu"` or `"cpu"`, as `createRenderer` takes them. */
|
|
39
|
+
this.renderer = renderer;
|
|
40
|
+
this.rendererChoice = null;
|
|
38
41
|
this.runtimeAssets = runtimeAssets;
|
|
39
|
-
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
40
42
|
this.unreadableFrames = unreadableFrames;
|
|
41
|
-
/** Who converts decoded SDR frames, the engine or the browser (`FrameSupply`). */
|
|
42
43
|
this.videoConversion = videoConversion;
|
|
44
|
+
this.opaqueEngineFrames = opaqueEngineFrames;
|
|
43
45
|
this.canvas = canvas;
|
|
44
46
|
this.sources = sources;
|
|
45
47
|
this.library = library;
|
|
@@ -56,10 +58,9 @@ export class Engine {
|
|
|
56
58
|
throw new Error("WebCodecs and OffscreenCanvas are required by this demo");
|
|
57
59
|
}
|
|
58
60
|
await loadEngineWasm(this.runtimeAssets.wasmUrl);
|
|
59
|
-
this
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
: await WebEffectRegistry.createForHtmlCanvas(this.canvas);
|
|
61
|
+
const { wasm, choice } = await createRenderer(WebEffectRegistry, this.canvas, this.renderer);
|
|
62
|
+
this.#registry = wasm;
|
|
63
|
+
this.rendererChoice = choice;
|
|
63
64
|
this.#effectResources = new Map();
|
|
64
65
|
this.#sizeResultCache();
|
|
65
66
|
this.#supply = new FrameSupply(this.#registry, {
|
|
@@ -69,6 +70,9 @@ export class Engine {
|
|
|
69
70
|
...(this.videoConversion === undefined
|
|
70
71
|
? {}
|
|
71
72
|
: { videoConversion: this.videoConversion }),
|
|
73
|
+
...(this.opaqueEngineFrames === undefined
|
|
74
|
+
? {}
|
|
75
|
+
: { opaqueEngineFrames: this.opaqueEngineFrames }),
|
|
72
76
|
});
|
|
73
77
|
// `engine.traceUploads = true` in the console logs every source upload, to tell a host decode
|
|
74
78
|
// bug from an engine one when a clip shows another clip's picture.
|
|
@@ -85,23 +89,23 @@ export class Engine {
|
|
|
85
89
|
};
|
|
86
90
|
}
|
|
87
91
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
92
|
+
* Sizes the result cache for revisits (stills, paused or scrubbed-back frames) to about six
|
|
93
|
+
* half-float frames at the canvas size.
|
|
90
94
|
*/
|
|
91
95
|
#sizeResultCache() {
|
|
92
96
|
this.#registry.setResultCacheBudget(RESULT_CACHE_FRAMES * this.canvas.width * this.canvas.height * 8);
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
|
-
* Turns per-pass GPU and CPU timing on or off;
|
|
96
|
-
*
|
|
99
|
+
* Turns per-pass GPU and CPU timing on or off (off by default); passes appear in
|
|
100
|
+
* `lastDiagnostics`.
|
|
97
101
|
*/
|
|
98
102
|
setPassTiming(enabled) {
|
|
99
103
|
this.#registry?.setPassTiming(enabled);
|
|
100
104
|
}
|
|
101
105
|
/**
|
|
102
|
-
* Sets the preview resolution scale (the
|
|
103
|
-
*
|
|
104
|
-
*
|
|
106
|
+
* Sets the preview resolution scale (1 renders at the document's size) and returns the loaded
|
|
107
|
+
* project's render size as `[width, height]`, or null with no project. Throws for a scale the
|
|
108
|
+
* engine refuses.
|
|
105
109
|
*/
|
|
106
110
|
setPreviewScale(scale) {
|
|
107
111
|
if (!this.#registry)
|
|
@@ -110,23 +114,41 @@ export class Engine {
|
|
|
110
114
|
this.#revision += 1;
|
|
111
115
|
return this.previewSize;
|
|
112
116
|
}
|
|
113
|
-
/** The loaded project's render size at the preview scale, `[width, height]`, or null. */
|
|
114
117
|
get previewSize() {
|
|
115
118
|
if (!this.#registry || !this.#project)
|
|
116
119
|
return null;
|
|
117
120
|
return Array.from(this.#registry.previewSize);
|
|
118
121
|
}
|
|
119
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* The renderer's part of the capability report: GPU, color, playback, and `renderer` (which
|
|
124
|
+
* renderer draws and whether it runs runtime effects).
|
|
125
|
+
*/
|
|
120
126
|
capabilityReport() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
if (!this.#registry)
|
|
128
|
+
return null;
|
|
129
|
+
const choice = this.rendererChoice;
|
|
130
|
+
return {
|
|
131
|
+
...JSON.parse(this.#registry.capabilityReport()),
|
|
132
|
+
renderer: {
|
|
133
|
+
renderer: choice?.renderer ?? "gpu",
|
|
134
|
+
rendererReason: choice?.rendererReason ?? null,
|
|
135
|
+
backend: choice?.backend ?? null,
|
|
136
|
+
adapter: choice?.adapter ?? null,
|
|
137
|
+
runtimeEffects: (choice?.renderer ?? "gpu") === "gpu",
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** The `GpuLossReport` after a GPU loss; undefined before a loss and on the CPU renderer. */
|
|
142
|
+
lossReport() {
|
|
143
|
+
const registry = this.#registry;
|
|
144
|
+
if (!registry?.deviceLost)
|
|
145
|
+
return undefined;
|
|
146
|
+
return lossReportFromJson(registry.lossReport);
|
|
124
147
|
}
|
|
125
148
|
/** A clock for one run of playback; see the engine's `PlaybackPolicy`. */
|
|
126
149
|
playbackClock(policy, frameRate, rate, tick, now) {
|
|
127
150
|
return new PlaybackClock(policy, frameRate.num, frameRate.den, rate, tick, now);
|
|
128
151
|
}
|
|
129
|
-
/** Whether sound plays under `policy` at `rate`. */
|
|
130
152
|
audible(policy, rate) {
|
|
131
153
|
return PlaybackClock.audible(policy, rate);
|
|
132
154
|
}
|
|
@@ -137,8 +159,8 @@ export class Engine {
|
|
|
137
159
|
return this.#registry?.deviceLost ?? false;
|
|
138
160
|
}
|
|
139
161
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
162
|
+
* Cumulative: raw source video copied through script memory, and frames that could not be read
|
|
163
|
+
* back and how they were recovered.
|
|
142
164
|
*/
|
|
143
165
|
get sourceTransfer() {
|
|
144
166
|
return {
|
|
@@ -157,27 +179,23 @@ export class Engine {
|
|
|
157
179
|
presentedFrames: 0,
|
|
158
180
|
});
|
|
159
181
|
}
|
|
160
|
-
/** The wasm object, for callers that drive audio directly. */
|
|
161
182
|
get wasm() {
|
|
162
183
|
return this.#registry;
|
|
163
184
|
}
|
|
164
|
-
/** Engine instance used by the realtime browser audio transport. */
|
|
165
185
|
get audioEngine() {
|
|
166
186
|
return this.#registry;
|
|
167
187
|
}
|
|
168
|
-
/** The project document most recently handed to the engine. */
|
|
169
188
|
get project() {
|
|
170
189
|
return this.#project;
|
|
171
190
|
}
|
|
172
191
|
/**
|
|
173
|
-
* Loads `project`
|
|
174
|
-
* draws (`drawnEffectResources`)
|
|
175
|
-
*
|
|
176
|
-
* are dropped.
|
|
192
|
+
* Loads `project` and syncs its LUT resources with the library, registering only those the
|
|
193
|
+
* project draws (`drawnEffectResources`). Bumps the revision so in-flight renders for the old
|
|
194
|
+
* project are dropped.
|
|
177
195
|
*
|
|
178
|
-
* Throws `missing_asset`
|
|
179
|
-
*
|
|
180
|
-
*
|
|
196
|
+
* Throws `missing_asset` for a drawn resource the library lacks and `invalid_effect_resource` for
|
|
197
|
+
* one the engine cannot parse. Resources registered before the failure stay known, so the next
|
|
198
|
+
* load neither leaks nor repeats them.
|
|
181
199
|
*/
|
|
182
200
|
loadProject(project, operation = "preview") {
|
|
183
201
|
if (!this.#registry)
|
|
@@ -185,7 +203,7 @@ export class Engine {
|
|
|
185
203
|
const drawn = project.effect_resources?.length
|
|
186
204
|
? drawnEffectResources(project)
|
|
187
205
|
: new Set();
|
|
188
|
-
// Parsing a LUT is
|
|
206
|
+
// Parsing a LUT is costly and edits rarely change one, so unchanged resources stay.
|
|
189
207
|
for (const resource of project.effect_resources ?? []) {
|
|
190
208
|
if (!drawn.has(resource.id))
|
|
191
209
|
continue;
|
|
@@ -214,19 +232,25 @@ export class Engine {
|
|
|
214
232
|
this.#registry.resetPlayer();
|
|
215
233
|
}
|
|
216
234
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
235
|
+
* The registered runtime effects the loaded project can draw, as `id@version`. The CPU renderer
|
|
236
|
+
* registers them but refuses to render or export a project that draws one.
|
|
237
|
+
*/
|
|
238
|
+
projectRuntimeEffects() {
|
|
239
|
+
if (!this.#registry)
|
|
240
|
+
throw new Error("the renderer is not initialized");
|
|
241
|
+
return this.#registry.projectRuntimeEffects();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Compiles runtime effect definitions on this renderer's device and registers them, all or none.
|
|
245
|
+
* An `id@version` already held is skipped, since a definition never changes under its version.
|
|
246
|
+
* Throws `invalid_effect` naming the first refused definition, with its diagnostics.
|
|
223
247
|
*/
|
|
224
248
|
async registerEffects(definitions, operation = "preview") {
|
|
225
249
|
if (!this.#registry)
|
|
226
250
|
throw new Error("the renderer is not initialized");
|
|
227
251
|
const fresh = definitions.filter((definition) => !this.#effects.has(effectKey(definition)));
|
|
228
252
|
const refusal = (definition, error) => new EditorError("invalid_effect", `Effect ${effectKey(definition)} is not one the engine runs: ${error instanceof Error ? error.message : String(error)}`, operation, effectKey(definition), true, { cause: error });
|
|
229
|
-
// `compileEffect` throws for
|
|
253
|
+
// `compileEffect` throws for definitions it refuses before compiling; otherwise its promise
|
|
230
254
|
// rejects with the shader's diagnostics.
|
|
231
255
|
const compiled = await Promise.allSettled(fresh.map(async (definition) => this.#registry.compileEffect(JSON.stringify(definition))));
|
|
232
256
|
const failed = compiled.findIndex(({ status }) => status === "rejected");
|
|
@@ -254,9 +278,8 @@ export class Engine {
|
|
|
254
278
|
this.#effects.add(effectKey(definition));
|
|
255
279
|
}
|
|
256
280
|
/**
|
|
257
|
-
* Registers
|
|
258
|
-
*
|
|
259
|
-
* could not parse, as `{ font, error }`: they are left out, and the others draw.
|
|
281
|
+
* Registers caption fonts in fallback order; SVG text uses them too, as on the native host.
|
|
282
|
+
* Returns the fonts the engine could not parse as `{ font, error }`; those are left out.
|
|
260
283
|
*/
|
|
261
284
|
setCaptionFonts(fonts) {
|
|
262
285
|
if (!this.#registry)
|
|
@@ -280,11 +303,9 @@ export class Engine {
|
|
|
280
303
|
this.#revision += 1;
|
|
281
304
|
}
|
|
282
305
|
/**
|
|
283
|
-
* Uploads the sources the engine needs at a timestamp without rendering
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* The uploads stay until `beginExportFrame` renders their frame; retired earlier, a frame whose
|
|
287
|
-
* uploads outgrow the retained budget would evict its own first ones and wait forever.
|
|
306
|
+
* Uploads the sources the engine needs at a timestamp without rendering, for export, where the
|
|
307
|
+
* engine owns the frame schedule. Uploads stay until `beginExportFrame` renders their frame;
|
|
308
|
+
* retiring them earlier could make a frame evict its own first uploads and wait forever.
|
|
288
309
|
*/
|
|
289
310
|
async supply(seconds, { context }) {
|
|
290
311
|
if (!this.#registry)
|
|
@@ -305,9 +326,8 @@ export class Engine {
|
|
|
305
326
|
return Boolean(supplied);
|
|
306
327
|
}
|
|
307
328
|
/**
|
|
308
|
-
* Renders the next export frame
|
|
309
|
-
*
|
|
310
|
-
* here.
|
|
329
|
+
* Renders the next export frame. Once a ticket is not `waiting`, the engine has consumed the
|
|
330
|
+
* frame's uploads, so they are retired here.
|
|
311
331
|
*/
|
|
312
332
|
beginExportFrame() {
|
|
313
333
|
if (!this.#registry)
|
|
@@ -320,9 +340,9 @@ export class Engine {
|
|
|
320
340
|
return ticket;
|
|
321
341
|
}
|
|
322
342
|
/**
|
|
323
|
-
* A source's
|
|
324
|
-
* or
|
|
325
|
-
*
|
|
343
|
+
* A source's content identity is the runtime asset the library opens for it, so a relink,
|
|
344
|
+
* provider setting or proxy re-uploads only that source. An SVG's also includes its fonts (see
|
|
345
|
+
* `SourcePixels.contentOf`).
|
|
326
346
|
*/
|
|
327
347
|
#contentOf = (id) => {
|
|
328
348
|
const asset = this.library.get(id) ?? null;
|
|
@@ -337,10 +357,9 @@ export class Engine {
|
|
|
337
357
|
return this.#generation;
|
|
338
358
|
}
|
|
339
359
|
/**
|
|
340
|
-
* Requests one frame. Concurrent requests collapse to the
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* nothing was drawn or presented and the surface still shows it.
|
|
360
|
+
* Requests one frame. Concurrent requests collapse to the newest so scrubbing never queues stale
|
|
361
|
+
* frames. Resolves `{ rendered, unchanged }`: `rendered` is false when superseded, and
|
|
362
|
+
* `unchanged` means the frame equals the one shown, so nothing was drawn or presented.
|
|
344
363
|
*/
|
|
345
364
|
render(seconds, { generation = null, context } = {}) {
|
|
346
365
|
if (!this.#registry)
|
|
@@ -411,7 +430,11 @@ export class Engine {
|
|
|
411
430
|
this.#renders += 1;
|
|
412
431
|
this.lastRenderMs = performance.now() - started;
|
|
413
432
|
this.#sampleDiagnostics();
|
|
414
|
-
return {
|
|
433
|
+
return {
|
|
434
|
+
rendered: true,
|
|
435
|
+
unchanged,
|
|
436
|
+
degradedSources: playback.degradedSources ?? [],
|
|
437
|
+
};
|
|
415
438
|
}
|
|
416
439
|
#sampleDiagnostics() {
|
|
417
440
|
const now = performance.now();
|
|
@@ -422,7 +445,7 @@ export class Engine {
|
|
|
422
445
|
this.#fps.shift();
|
|
423
446
|
if (!this.#registry?.diagnostics)
|
|
424
447
|
return;
|
|
425
|
-
// Serializing a snapshot every frame would
|
|
448
|
+
// Serializing a snapshot every frame would slow the critical path.
|
|
426
449
|
if (now - this.#lastDiagnosticsAt < DIAGNOSTICS_INTERVAL_MS)
|
|
427
450
|
return;
|
|
428
451
|
this.#lastDiagnosticsAt = now;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The project-rate samples the running export's audio covers
|
|
3
|
-
*
|
|
4
|
-
* `
|
|
2
|
+
* The project-rate samples the running export's audio covers (`exportProgress().audioWindow`):
|
|
3
|
+
* `startSample` is the mix position at the output's zero, `frames` the count. Read after
|
|
4
|
+
* `beginExport`.
|
|
5
5
|
*/
|
|
6
6
|
export function exportAudioWindow(engine: any): {
|
|
7
7
|
startSample: number;
|
|
8
8
|
frames: any;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Writes the running export's audio
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Writes the running export's audio into `sink` as the video advances: `writeThrough(seconds)`
|
|
12
|
+
* mixes and encodes every block up to `seconds` past the output's zero (`Infinity` for the rest).
|
|
13
|
+
* Create it after `beginExport`.
|
|
14
14
|
*/
|
|
15
15
|
export function exportAudioWriter({ engine, audioSupplier, sink, sampleRate, signal, metrics, enter, }: {
|
|
16
16
|
engine: any;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// Export audio covers the export's effective range (widened to the frame grid) as the engine
|
|
2
|
-
// decides it on every host; its first sample
|
|
2
|
+
// decides it on every host; its first sample aligns with the first frame at the output's zero.
|
|
3
3
|
import { missingAudioSources, mixBlock } from "./audio.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* `audioMaxBlock`.
|
|
5
|
+
* Samples mixed and encoded per block, as on the native host; at most the engine's `audioMaxBlock`.
|
|
7
6
|
*/
|
|
8
7
|
const AUDIO_BLOCK_FRAMES = 4_096;
|
|
9
8
|
/**
|
|
10
|
-
* The project-rate samples the running export's audio covers
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
9
|
+
* The project-rate samples the running export's audio covers (`exportProgress().audioWindow`):
|
|
10
|
+
* `startSample` is the mix position at the output's zero, `frames` the count. Read after
|
|
11
|
+
* `beginExport`.
|
|
13
12
|
*/
|
|
14
13
|
export function exportAudioWindow(engine) {
|
|
15
14
|
const { audioWindow } = JSON.parse(engine.exportProgress());
|
|
@@ -19,9 +18,9 @@ export function exportAudioWindow(engine) {
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
|
-
* Writes the running export's audio
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* Writes the running export's audio into `sink` as the video advances: `writeThrough(seconds)`
|
|
22
|
+
* mixes and encodes every block up to `seconds` past the output's zero (`Infinity` for the rest).
|
|
23
|
+
* Create it after `beginExport`.
|
|
25
24
|
*/
|
|
26
25
|
export function exportAudioWriter({ engine, audioSupplier, sink, sampleRate, signal, metrics, enter, }) {
|
|
27
26
|
const window = exportAudioWindow(engine);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** The engine's quality level names, lowest first. */
|
|
2
2
|
export function qualityLevelNames(): readonly string[];
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* function the native host calls.
|
|
4
|
+
* The video rate an export at `quality` encodes at, resolved by the engine as on the native host.
|
|
6
5
|
*/
|
|
7
6
|
export function resolvedVideoRate({ codec, width, height, frameRate, quality, }: {
|
|
8
7
|
codec: any;
|
|
@@ -12,10 +11,10 @@ export function resolvedVideoRate({ codec, width, height, frameRate, quality, }:
|
|
|
12
11
|
quality: any;
|
|
13
12
|
}): import("alpha2/rate-control").VideoRateControl;
|
|
14
13
|
/**
|
|
15
|
-
* Which video codecs this browser encodes for an export at `width`x`height`, `frameRate
|
|
16
|
-
* `videoQuality` (default `high`),
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* Which video codecs this browser encodes for an export at `width`x`height`, `frameRate` and
|
|
15
|
+
* `videoQuality` (default `high`), probed with the configurations the export would open (for H.264:
|
|
16
|
+
* High, Main or Constrained Baseline). A codec answered `false` is refused when such an export
|
|
17
|
+
* starts.
|
|
19
18
|
*/
|
|
20
19
|
export function probeEncoders(width: any, height: any, { frameRate, videoQuality }?: {
|
|
21
20
|
frameRate?: {
|
|
@@ -25,15 +24,16 @@ export function probeEncoders(width: any, height: any, { frameRate, videoQuality
|
|
|
25
24
|
videoQuality?: string | undefined;
|
|
26
25
|
}): Promise<{}>;
|
|
27
26
|
/**
|
|
28
|
-
* Renders `range` (seconds) of the loaded project
|
|
29
|
-
*
|
|
30
|
-
* opened output (not yet finished)
|
|
31
|
-
* rethrown as an `ExportFailureError` with
|
|
32
|
-
* abort reason. `createSink(options)` makes the muxer
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* Renders `range` (seconds) of the loaded project on the engine's export schedule and writes it
|
|
28
|
+
* with its mixed audio to the output `openOutput` opens (given the container and a size estimate).
|
|
29
|
+
* Resolves to the sink's output, the opened output (not yet finished) and the export report. Any
|
|
30
|
+
* failure discards the output and is rethrown as an `ExportFailureError` with its phase; a
|
|
31
|
+
* cancellation rethrows the abort reason. `createSink(options)` makes the muxer (a `MediabunnySink`
|
|
32
|
+
* unless a test supplies another). `videoEncoder: "software"` asks for a software video encoder
|
|
33
|
+
* where available, and `onSoftwareEncoder(available)` reports before rendering whether there is
|
|
34
|
+
* one.
|
|
35
35
|
*/
|
|
36
|
-
export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engine, project, doc, library, audioSupplier, range, options, openOutput, onProgress, signal, createSink, }: {
|
|
36
|
+
export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engine, project, doc, library, audioSupplier, range, options, openOutput, onProgress, signal, createSink, videoEncoder, onSoftwareEncoder, }: {
|
|
37
37
|
supplyFrame: any;
|
|
38
38
|
renderFrame: any;
|
|
39
39
|
sourceTransfer: any;
|
|
@@ -48,6 +48,8 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
48
48
|
onProgress: any;
|
|
49
49
|
signal: any;
|
|
50
50
|
createSink?: ((sinkOptions: any) => MediabunnySink) | undefined;
|
|
51
|
+
videoEncoder?: string | undefined;
|
|
52
|
+
onSoftwareEncoder: any;
|
|
51
53
|
}): Promise<{
|
|
52
54
|
written: import("alpha2/mediabunny").ExportOutput;
|
|
53
55
|
output: any;
|
|
@@ -66,6 +68,9 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
66
68
|
};
|
|
67
69
|
appliedVideoRateControl: import("alpha2/mediabunny").AppliedVideoRateControl | null;
|
|
68
70
|
videoLatencyMode: import("alpha2/mediabunny").VideoEncoderLatencyMode | null;
|
|
71
|
+
videoLatencyProbe: import("alpha2/export-metrics").VideoLatencyProbe | null;
|
|
72
|
+
aacPrimingProbe: import("alpha2/export-metrics").AacEncoderProbe | null;
|
|
73
|
+
videoEncoderAcceleration: "no-preference" | "prefer-software" | null;
|
|
69
74
|
videoCodecString: string | null;
|
|
70
75
|
videoCodecProfile: import("alpha2/mediabunny").AvcProfile | null;
|
|
71
76
|
videoEncoderFallbacks: readonly import("alpha2/mediabunny").VideoEncoderFallback[];
|
|
@@ -79,59 +84,23 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
79
84
|
status: string;
|
|
80
85
|
reason: string;
|
|
81
86
|
};
|
|
82
|
-
performance:
|
|
83
|
-
pipelineEnabled: any;
|
|
84
|
-
sourceConvertUploadMs: any;
|
|
85
|
-
frameSubmitMs: any;
|
|
86
|
-
readbackMapLatencyMs: any;
|
|
87
|
-
readbackWaitMs: any;
|
|
88
|
-
readbackBlockingMs: any;
|
|
89
|
-
encodeQueueWaitMs: any;
|
|
90
|
-
videoEncodeMs: any;
|
|
91
|
-
audioDecodeMs: any;
|
|
92
|
-
audioMixMs: any;
|
|
93
|
-
audioEncodeMs: any;
|
|
94
|
-
muxFinishMs: any;
|
|
95
|
-
inFlightDepth: number;
|
|
96
|
-
encodeChannelDepth: number;
|
|
97
|
-
stagingBytesPerFrame: any;
|
|
98
|
-
packedBytesPerFrame: any;
|
|
99
|
-
peakReadbackBytes: any;
|
|
100
|
-
outputReadbackBytes: any;
|
|
101
|
-
outputRepackBytes: any;
|
|
102
|
-
sourcePlanarCopyFrames: any;
|
|
103
|
-
sourcePlanarCopyBytes: any;
|
|
104
|
-
sourceUnreadableFrames: any;
|
|
105
|
-
sourceReadbackRetries: any;
|
|
106
|
-
sourceRedecodedFrames: any;
|
|
107
|
-
peakEncodeQueueBytes: any;
|
|
108
|
-
maxPendingMediaEvents: any;
|
|
109
|
-
averagePendingMediaEvents: number;
|
|
110
|
-
maxInFlightReadbacks: any;
|
|
111
|
-
maxEncodeQueueEvents: any;
|
|
112
|
-
encodeBackpressureCount: any;
|
|
113
|
-
pipelineOverlapFrames: any;
|
|
114
|
-
audioBlocksInterleaved: any;
|
|
115
|
-
memory: any;
|
|
116
|
-
output: any;
|
|
117
|
-
};
|
|
87
|
+
performance: any;
|
|
118
88
|
};
|
|
119
89
|
}>;
|
|
120
90
|
/**
|
|
121
|
-
* The export's container and video codec,
|
|
122
|
-
*
|
|
123
|
-
*
|
|
91
|
+
* The export's container and video codec, defaulting to `mp4` and its `avc`. A container that does
|
|
92
|
+
* not offer a requested codec (`webm` with `avc`, `mov` with `opus`) is refused before rendering,
|
|
93
|
+
* as
|
|
94
|
+
* `INVALID_INPUT`.
|
|
124
95
|
*/
|
|
125
96
|
export function exportFormat(options: any): import("alpha2/containers").ExportFormat;
|
|
126
97
|
/**
|
|
127
|
-
* The audio codec
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* AudioEncoder; Firefox on Linux has no AAC encoder for a MOV) is refused here, before anything
|
|
134
|
-
* renders, as `INVALID_INPUT`: a retry would meet the same browser.
|
|
98
|
+
* The audio codec and encoder sample rate for the export: `codec` when given, else the first of the
|
|
99
|
+
* container's codecs this browser encodes (AAC then Opus in MP4 and MKV, AAC in MOV, Opus in WebM).
|
|
100
|
+
* Each runs at the project rate where the encoder accepts it, else at the rate a native host would
|
|
101
|
+
* convert to (`audioEncoderSampleRate`), so every project rate exports. A browser that encodes none
|
|
102
|
+
* of them (Safari before 26 has no AudioEncoder; Firefox on Linux has no AAC encoder for MOV) is
|
|
103
|
+
* refused before rendering as `INVALID_INPUT`, since a retry would meet the same browser.
|
|
135
104
|
*
|
|
136
105
|
* @returns {Promise<{ codec: "aac" | "opus", sampleRate: number }>}
|
|
137
106
|
*/
|
|
@@ -142,11 +111,9 @@ export function chooseAudioCodec(sampleRate: any, audioQuality: any, { container
|
|
|
142
111
|
sampleRate: number;
|
|
143
112
|
}>;
|
|
144
113
|
/**
|
|
145
|
-
* How this browser encodes the export's video (
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* anything renders, as `INVALID_INPUT`: WebCodecs leaves the codecs to the browser, and a retry
|
|
149
|
-
* would meet the same browser.
|
|
114
|
+
* How this browser encodes the export's video (for H.264, the first of High, Main and Constrained
|
|
115
|
+
* Baseline it supports). Refuses before rendering, as `INVALID_INPUT`, when it cannot encode the
|
|
116
|
+
* codec at the export's size and rate, since a retry would meet the same browser.
|
|
150
117
|
*/
|
|
151
118
|
export function requireVideoEncoder(codec: any, { width, height }: {
|
|
152
119
|
width: any;
|