@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,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,17 +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 } = {}) {
|
|
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;
|
|
43
|
+
this.videoConversion = videoConversion;
|
|
44
|
+
this.opaqueEngineFrames = opaqueEngineFrames;
|
|
41
45
|
this.canvas = canvas;
|
|
42
46
|
this.sources = sources;
|
|
43
47
|
this.library = library;
|
|
@@ -54,16 +58,21 @@ export class Engine {
|
|
|
54
58
|
throw new Error("WebCodecs and OffscreenCanvas are required by this demo");
|
|
55
59
|
}
|
|
56
60
|
await loadEngineWasm(this.runtimeAssets.wasmUrl);
|
|
57
|
-
this
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
: await WebEffectRegistry.createForHtmlCanvas(this.canvas);
|
|
61
|
+
const { wasm, choice } = await createRenderer(WebEffectRegistry, this.canvas, this.renderer);
|
|
62
|
+
this.#registry = wasm;
|
|
63
|
+
this.rendererChoice = choice;
|
|
61
64
|
this.#effectResources = new Map();
|
|
62
65
|
this.#sizeResultCache();
|
|
63
66
|
this.#supply = new FrameSupply(this.#registry, {
|
|
64
67
|
...(this.unreadableFrames === undefined
|
|
65
68
|
? {}
|
|
66
69
|
: { unreadableFrames: this.unreadableFrames }),
|
|
70
|
+
...(this.videoConversion === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: { videoConversion: this.videoConversion }),
|
|
73
|
+
...(this.opaqueEngineFrames === undefined
|
|
74
|
+
? {}
|
|
75
|
+
: { opaqueEngineFrames: this.opaqueEngineFrames }),
|
|
67
76
|
});
|
|
68
77
|
// `engine.traceUploads = true` in the console logs every source upload, to tell a host decode
|
|
69
78
|
// bug from an engine one when a clip shows another clip's picture.
|
|
@@ -80,23 +89,23 @@ export class Engine {
|
|
|
80
89
|
};
|
|
81
90
|
}
|
|
82
91
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
92
|
+
* Sizes the result cache for revisits (stills, paused or scrubbed-back frames) to about six
|
|
93
|
+
* half-float frames at the canvas size.
|
|
85
94
|
*/
|
|
86
95
|
#sizeResultCache() {
|
|
87
96
|
this.#registry.setResultCacheBudget(RESULT_CACHE_FRAMES * this.canvas.width * this.canvas.height * 8);
|
|
88
97
|
}
|
|
89
98
|
/**
|
|
90
|
-
* Turns per-pass GPU and CPU timing on or off;
|
|
91
|
-
*
|
|
99
|
+
* Turns per-pass GPU and CPU timing on or off (off by default); passes appear in
|
|
100
|
+
* `lastDiagnostics`.
|
|
92
101
|
*/
|
|
93
102
|
setPassTiming(enabled) {
|
|
94
103
|
this.#registry?.setPassTiming(enabled);
|
|
95
104
|
}
|
|
96
105
|
/**
|
|
97
|
-
* Sets the preview resolution scale (the
|
|
98
|
-
*
|
|
99
|
-
*
|
|
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.
|
|
100
109
|
*/
|
|
101
110
|
setPreviewScale(scale) {
|
|
102
111
|
if (!this.#registry)
|
|
@@ -105,23 +114,41 @@ export class Engine {
|
|
|
105
114
|
this.#revision += 1;
|
|
106
115
|
return this.previewSize;
|
|
107
116
|
}
|
|
108
|
-
/** The loaded project's render size at the preview scale, `[width, height]`, or null. */
|
|
109
117
|
get previewSize() {
|
|
110
118
|
if (!this.#registry || !this.#project)
|
|
111
119
|
return null;
|
|
112
120
|
return Array.from(this.#registry.previewSize);
|
|
113
121
|
}
|
|
114
|
-
/**
|
|
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
|
+
*/
|
|
115
126
|
capabilityReport() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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);
|
|
119
147
|
}
|
|
120
148
|
/** A clock for one run of playback; see the engine's `PlaybackPolicy`. */
|
|
121
149
|
playbackClock(policy, frameRate, rate, tick, now) {
|
|
122
150
|
return new PlaybackClock(policy, frameRate.num, frameRate.den, rate, tick, now);
|
|
123
151
|
}
|
|
124
|
-
/** Whether sound plays under `policy` at `rate`. */
|
|
125
152
|
audible(policy, rate) {
|
|
126
153
|
return PlaybackClock.audible(policy, rate);
|
|
127
154
|
}
|
|
@@ -132,8 +159,8 @@ export class Engine {
|
|
|
132
159
|
return this.#registry?.deviceLost ?? false;
|
|
133
160
|
}
|
|
134
161
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
162
|
+
* Cumulative: raw source video copied through script memory, and frames that could not be read
|
|
163
|
+
* back and how they were recovered.
|
|
137
164
|
*/
|
|
138
165
|
get sourceTransfer() {
|
|
139
166
|
return {
|
|
@@ -152,27 +179,23 @@ export class Engine {
|
|
|
152
179
|
presentedFrames: 0,
|
|
153
180
|
});
|
|
154
181
|
}
|
|
155
|
-
/** The wasm object, for callers that drive audio directly. */
|
|
156
182
|
get wasm() {
|
|
157
183
|
return this.#registry;
|
|
158
184
|
}
|
|
159
|
-
/** Engine instance used by the realtime browser audio transport. */
|
|
160
185
|
get audioEngine() {
|
|
161
186
|
return this.#registry;
|
|
162
187
|
}
|
|
163
|
-
/** The project document most recently handed to the engine. */
|
|
164
188
|
get project() {
|
|
165
189
|
return this.#project;
|
|
166
190
|
}
|
|
167
191
|
/**
|
|
168
|
-
* Loads `project`
|
|
169
|
-
* draws (`drawnEffectResources`)
|
|
170
|
-
*
|
|
171
|
-
* 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.
|
|
172
195
|
*
|
|
173
|
-
* Throws `missing_asset`
|
|
174
|
-
*
|
|
175
|
-
*
|
|
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.
|
|
176
199
|
*/
|
|
177
200
|
loadProject(project, operation = "preview") {
|
|
178
201
|
if (!this.#registry)
|
|
@@ -180,7 +203,7 @@ export class Engine {
|
|
|
180
203
|
const drawn = project.effect_resources?.length
|
|
181
204
|
? drawnEffectResources(project)
|
|
182
205
|
: new Set();
|
|
183
|
-
// Parsing a LUT is
|
|
206
|
+
// Parsing a LUT is costly and edits rarely change one, so unchanged resources stay.
|
|
184
207
|
for (const resource of project.effect_resources ?? []) {
|
|
185
208
|
if (!drawn.has(resource.id))
|
|
186
209
|
continue;
|
|
@@ -209,19 +232,16 @@ export class Engine {
|
|
|
209
232
|
this.#registry.resetPlayer();
|
|
210
233
|
}
|
|
211
234
|
/**
|
|
212
|
-
* Compiles runtime effect definitions
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* Throws `invalid_effect` naming the first definition the engine refuses, with its diagnostics;
|
|
217
|
-
* then none of the call's definitions is registered.
|
|
235
|
+
* Compiles runtime effect definitions on this renderer's device and registers them, all or none.
|
|
236
|
+
* An `id@version` already held is skipped, since a definition never changes under its version.
|
|
237
|
+
* Throws `invalid_effect` naming the first refused definition, with its diagnostics.
|
|
218
238
|
*/
|
|
219
239
|
async registerEffects(definitions, operation = "preview") {
|
|
220
240
|
if (!this.#registry)
|
|
221
241
|
throw new Error("the renderer is not initialized");
|
|
222
242
|
const fresh = definitions.filter((definition) => !this.#effects.has(effectKey(definition)));
|
|
223
243
|
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 });
|
|
224
|
-
// `compileEffect` throws for
|
|
244
|
+
// `compileEffect` throws for definitions it refuses before compiling; otherwise its promise
|
|
225
245
|
// rejects with the shader's diagnostics.
|
|
226
246
|
const compiled = await Promise.allSettled(fresh.map(async (definition) => this.#registry.compileEffect(JSON.stringify(definition))));
|
|
227
247
|
const failed = compiled.findIndex(({ status }) => status === "rejected");
|
|
@@ -249,9 +269,8 @@ export class Engine {
|
|
|
249
269
|
this.#effects.add(effectKey(definition));
|
|
250
270
|
}
|
|
251
271
|
/**
|
|
252
|
-
* Registers
|
|
253
|
-
*
|
|
254
|
-
* could not parse, as `{ font, error }`: they are left out, and the others draw.
|
|
272
|
+
* Registers caption fonts in fallback order; SVG text uses them too, as on the native host.
|
|
273
|
+
* Returns the fonts the engine could not parse as `{ font, error }`; those are left out.
|
|
255
274
|
*/
|
|
256
275
|
setCaptionFonts(fonts) {
|
|
257
276
|
if (!this.#registry)
|
|
@@ -275,11 +294,9 @@ export class Engine {
|
|
|
275
294
|
this.#revision += 1;
|
|
276
295
|
}
|
|
277
296
|
/**
|
|
278
|
-
* Uploads the sources the engine needs at a timestamp without rendering
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
* The uploads stay until `beginExportFrame` renders their frame; retired earlier, a frame whose
|
|
282
|
-
* uploads outgrow the retained budget would evict its own first ones and wait forever.
|
|
297
|
+
* Uploads the sources the engine needs at a timestamp without rendering, for export, where the
|
|
298
|
+
* engine owns the frame schedule. Uploads stay until `beginExportFrame` renders their frame;
|
|
299
|
+
* retiring them earlier could make a frame evict its own first uploads and wait forever.
|
|
283
300
|
*/
|
|
284
301
|
async supply(seconds, { context }) {
|
|
285
302
|
if (!this.#registry)
|
|
@@ -300,9 +317,8 @@ export class Engine {
|
|
|
300
317
|
return Boolean(supplied);
|
|
301
318
|
}
|
|
302
319
|
/**
|
|
303
|
-
* Renders the next export frame
|
|
304
|
-
*
|
|
305
|
-
* here.
|
|
320
|
+
* Renders the next export frame. Once a ticket is not `waiting`, the engine has consumed the
|
|
321
|
+
* frame's uploads, so they are retired here.
|
|
306
322
|
*/
|
|
307
323
|
beginExportFrame() {
|
|
308
324
|
if (!this.#registry)
|
|
@@ -315,9 +331,9 @@ export class Engine {
|
|
|
315
331
|
return ticket;
|
|
316
332
|
}
|
|
317
333
|
/**
|
|
318
|
-
* A source's
|
|
319
|
-
* or
|
|
320
|
-
*
|
|
334
|
+
* A source's content identity is the runtime asset the library opens for it, so a relink,
|
|
335
|
+
* provider setting or proxy re-uploads only that source. An SVG's also includes its fonts (see
|
|
336
|
+
* `SourcePixels.contentOf`).
|
|
321
337
|
*/
|
|
322
338
|
#contentOf = (id) => {
|
|
323
339
|
const asset = this.library.get(id) ?? null;
|
|
@@ -332,10 +348,9 @@ export class Engine {
|
|
|
332
348
|
return this.#generation;
|
|
333
349
|
}
|
|
334
350
|
/**
|
|
335
|
-
* Requests one frame. Concurrent requests collapse to the
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* nothing was drawn or presented and the surface still shows it.
|
|
351
|
+
* Requests one frame. Concurrent requests collapse to the newest so scrubbing never queues stale
|
|
352
|
+
* frames. Resolves `{ rendered, unchanged }`: `rendered` is false when superseded, and
|
|
353
|
+
* `unchanged` means the frame equals the one shown, so nothing was drawn or presented.
|
|
339
354
|
*/
|
|
340
355
|
render(seconds, { generation = null, context } = {}) {
|
|
341
356
|
if (!this.#registry)
|
|
@@ -406,7 +421,11 @@ export class Engine {
|
|
|
406
421
|
this.#renders += 1;
|
|
407
422
|
this.lastRenderMs = performance.now() - started;
|
|
408
423
|
this.#sampleDiagnostics();
|
|
409
|
-
return {
|
|
424
|
+
return {
|
|
425
|
+
rendered: true,
|
|
426
|
+
unchanged,
|
|
427
|
+
degradedSources: playback.degradedSources ?? [],
|
|
428
|
+
};
|
|
410
429
|
}
|
|
411
430
|
#sampleDiagnostics() {
|
|
412
431
|
const now = performance.now();
|
|
@@ -417,7 +436,7 @@ export class Engine {
|
|
|
417
436
|
this.#fps.shift();
|
|
418
437
|
if (!this.#registry?.diagnostics)
|
|
419
438
|
return;
|
|
420
|
-
// Serializing a snapshot every frame would
|
|
439
|
+
// Serializing a snapshot every frame would slow the critical path.
|
|
421
440
|
if (now - this.#lastDiagnosticsAt < DIAGNOSTICS_INTERVAL_MS)
|
|
422
441
|
return;
|
|
423
442
|
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;
|