@alpha2-sh/editor 0.2.1 → 0.3.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/README.md +3 -3
- package/dist/browser/bridge.js +223 -26
- package/dist/browser/runtime/engine.d.ts +27 -1
- package/dist/browser/runtime/engine.js +89 -4
- package/dist/browser/runtime/exporter.d.ts +24 -11
- package/dist/browser/runtime/exporter.js +61 -14
- package/dist/browser/runtime/generators.d.ts +34 -55
- package/dist/browser/runtime/generators.js +37 -19
- package/dist/browser/runtime/output.d.ts +4 -1
- package/dist/browser/runtime/output.js +12 -7
- package/dist/browser/types.d.ts +151 -10
- package/dist/browser/worker.js +54 -9
- package/dist/core/commands.js +2 -2
- package/dist/core/compositions.d.ts +16 -4
- package/dist/core/compositions.js +59 -4
- package/dist/core/document.js +3 -0
- package/dist/native-client/index.d.ts +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ editor.dispose();
|
|
|
38
38
|
|
|
39
39
|
## Browser bridge
|
|
40
40
|
|
|
41
|
-
`@alpha2-sh/editor/browser` connects a session to the engine in the browser: import, preview, playback with audio, and export to an MP4 file through WebCodecs.
|
|
41
|
+
`@alpha2-sh/editor/browser` connects a session to the engine in the browser: import, preview, playback with audio, and export to an MP4, MOV, MKV or WebM file through WebCodecs.
|
|
42
42
|
|
|
43
43
|
```js
|
|
44
44
|
import { createEditor, createEmptyDocument } from "@alpha2-sh/editor";
|
|
@@ -75,7 +75,7 @@ const placed = editor.dispatch({
|
|
|
75
75
|
if (!placed.ok) throw placed.error;
|
|
76
76
|
await bridge.seek(0);
|
|
77
77
|
|
|
78
|
-
const artifact = await bridge.startExport({
|
|
78
|
+
const artifact = await bridge.startExport({ container: "webm" }).result;
|
|
79
79
|
// artifact.kind "file": a temporary file in the origin's private storage; release it once downloaded.
|
|
80
80
|
if (artifact.kind === "file") await artifact.release();
|
|
81
81
|
|
|
@@ -86,7 +86,7 @@ await editor.dispose();
|
|
|
86
86
|
- Import checks each file with the engine (media, fonts, `.cube` LUTs, SRT and WebVTT captions through `importCaptions`) and adds it to the document in one undoable step. `importSequence` imports numbered PNG or OpenEXR files as one image sequence.
|
|
87
87
|
- `bindPreview` draws on a canvas. With `runtimeAssets.workerFactory`, a worker running the `@alpha2-sh/editor/preview-worker` entry renders the preview off the main thread; without one, or when the worker fails, the main thread does. `hashWorkerFactory` (`@alpha2-sh/editor/hash-worker`) and `extensionsWorkerFactory` (`@alpha2-sh/editor/extensions-worker`, with `extensionsWasmUrl`) move file hashing and SVG, animated image, Lottie and OpenEXR reading into workers too.
|
|
88
88
|
- `seek`, `play` and `pause` move the playhead; with audio, playback follows the audio clock. Audio preview needs a cross-origin isolated page; editing and video preview do not.
|
|
89
|
-
- `startExport` returns a job with `result`, progress (`subscribe`) and `cancel`. The output goes to a temporary file in the origin's private storage by default (`release()` deletes it), to a file the user picked (`output: { kind: "file", handle }`), or to memory (`output: { kind: "memory", maxBytes }`). Whether the browser encodes a codec is the browser's to say: `bridge.videoEncoders()` asks ahead, and an export with a codec the browser does not encode is refused before it renders.
|
|
89
|
+
- `startExport` returns a job with `result`, progress (`subscribe`) and `cancel`. `container` (`mp4` by default, `mov`, `mkv` or `webm`) names the file and decides the codecs: an absent `videoCodec` or `audioCodec` is the container's default (H.264 and AAC, or VP9 and Opus for WebM, with Opus where a browser cannot encode AAC in MP4 or MKV), and one the container does not offer is refused. The output goes to a temporary file in the origin's private storage by default (`release()` deletes it), to a file the user picked (`output: { kind: "file", handle }`), or to memory (`output: { kind: "memory", maxBytes }`). Whether the browser encodes a codec is the browser's to say: `bridge.videoEncoders()` asks ahead, and an export with a codec the browser does not encode is refused before it renders.
|
|
90
90
|
|
|
91
91
|
## React
|
|
92
92
|
|
package/dist/browser/bridge.js
CHANGED
|
@@ -2,11 +2,13 @@ import { frameAt, frameStart } from "../core/time.js";
|
|
|
2
2
|
import { compileEditorDocument, EditorError, sequenceEnd, } from "../core/document.js";
|
|
3
3
|
import { captionsAsset } from "../core/captions.js";
|
|
4
4
|
import { MAX_CAPTION_FILE_BYTES } from "alpha2/project";
|
|
5
|
+
import { containerPolicy } from "alpha2/containers";
|
|
5
6
|
import { drawnEffectResources, shownSources } from "../core/compositions.js";
|
|
6
7
|
import { ResourceRegistry } from "./resources.js";
|
|
7
8
|
import { ExportJob, requireExportFrameRate } from "./jobs.js";
|
|
8
9
|
import { attemptOptions } from "./runtime/budget.js";
|
|
9
10
|
import { createWorkerPreview } from "./worker.js";
|
|
11
|
+
import { registerCaptionFonts } from "./runtime/caption-fonts.js";
|
|
10
12
|
import { AssetLibrary, streamPeaks } from "./runtime/assets.js";
|
|
11
13
|
import { SourcePixels, providerSettings, sameProviderSettings, } from "./runtime/sources.js";
|
|
12
14
|
import { fingerprintFile } from "./runtime/fingerprint.js";
|
|
@@ -196,7 +198,8 @@ export function createMediaAdapter({ extensionsWasmUrl, wasmUrl, hashWorkerFacto
|
|
|
196
198
|
* @returns {import("./types.js").BrowserBridge}
|
|
197
199
|
*/
|
|
198
200
|
export function createBrowserBridge(options) {
|
|
199
|
-
const { editor, runtimeAssets = {}, mediaAdapter = createMediaAdapter(runtimeAssets), resourceLimit = 128, audio = true, onError = () => { }, assetDecisions, } = options;
|
|
201
|
+
const { editor, runtimeAssets = {}, mediaAdapter = createMediaAdapter(runtimeAssets), resourceLimit = 128, audio = true, onError = () => { }, assetDecisions, previewScale: initialPreviewScale = 0.5, } = options;
|
|
202
|
+
let previewScale = checkedPreviewScale(initialPreviewScale);
|
|
200
203
|
// A test's stand-in for origin storage, kept out of the public options.
|
|
201
204
|
const proxyStore =
|
|
202
205
|
/** @type {{ proxyStore?: ProxyStore }} */ (options).proxyStore ??
|
|
@@ -212,6 +215,8 @@ export function createBrowserBridge(options) {
|
|
|
212
215
|
};
|
|
213
216
|
/** The engine's asset decisions, from the wasm module, loaded on first use. */
|
|
214
217
|
const decisions = async () => (decisionBinding ??= await loadWasm());
|
|
218
|
+
/** What `measureText` lays text out with, made on first use, and the font stack it holds. */
|
|
219
|
+
let measurer = null, measuredFonts = null;
|
|
215
220
|
const registry = new ResourceRegistry(resourceLimit);
|
|
216
221
|
/**
|
|
217
222
|
* The runtimes this session holds, by {@link ownerKey}: a lease and the registry revision it was
|
|
@@ -425,7 +430,12 @@ export function createBrowserBridge(options) {
|
|
|
425
430
|
// How the current or last playback was asked for, so a recovered preview plays on alike.
|
|
426
431
|
playRequest = null, renderScheduled = false, raf = 0, playClock = null, loadRevision = 0, loadedAssets = new Map(), loadedSelection = "", loadedFonts = null, audioKey = null,
|
|
427
432
|
// What the preview worker holds from its last load.
|
|
428
|
-
workerSent = new Map(), workerFonts = null, refreshFrame = 0, monitorVolume = 1,
|
|
433
|
+
workerSent = new Map(), workerFonts = null, refreshFrame = 0, monitorVolume = 1,
|
|
434
|
+
// Tracing the drawing renderer applies, kept for every renderer a binding makes.
|
|
435
|
+
passTiming = false, traceUploads = false,
|
|
436
|
+
// The worker's last renderer diagnostics snapshot, and counters since `bindPreview`: playback
|
|
437
|
+
// refreshes that asked for no frame, and frames copied to the bound canvas.
|
|
438
|
+
workerDiagnostics = null, skippedRequests = 0, bitmapTransfers = 0, playGeneration = 0, sessionGeneration = editor.generation;
|
|
429
439
|
/**
|
|
430
440
|
* Preview's media for a source of `document`: what the engine selected, the original unless it is
|
|
431
441
|
* offline, opened as the document's source says.
|
|
@@ -741,11 +751,11 @@ export function createBrowserBridge(options) {
|
|
|
741
751
|
reportRefusedFonts(refused, "preview");
|
|
742
752
|
}
|
|
743
753
|
engine.loadProject(compiled.project);
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
754
|
+
// Frames render at the document's size times the preview scale, and the surfaces are that
|
|
755
|
+
// size: the engine rounds it.
|
|
756
|
+
let renderSize = engine.previewSize;
|
|
757
|
+
engine.resize(renderSize[0], renderSize[1]);
|
|
758
|
+
// Sources are fitted in document space; the render scales them.
|
|
749
759
|
sources.setOutputSize(compiled.project.settings.width, compiled.project.settings.height);
|
|
750
760
|
audioKey = null;
|
|
751
761
|
if (workerPreview) {
|
|
@@ -789,15 +799,18 @@ export function createBrowserBridge(options) {
|
|
|
789
799
|
workerSent = new Map();
|
|
790
800
|
workerFonts = null;
|
|
791
801
|
try {
|
|
792
|
-
await workerPreview.replaceProject(compiled.project, ++loadRevision, workerAssets, sendFonts ? allFonts : null, keep);
|
|
802
|
+
const reply = await workerPreview.replaceProject(compiled.project, ++loadRevision, workerAssets, sendFonts ? allFonts : null, keep);
|
|
793
803
|
workerSent = new Map(used);
|
|
794
804
|
workerFonts = allFonts;
|
|
805
|
+
if (reply?.renderSize)
|
|
806
|
+
renderSize = reply.renderSize;
|
|
795
807
|
}
|
|
796
808
|
catch (error) {
|
|
797
809
|
// The main renderer has just loaded the same project.
|
|
798
810
|
await abandonWorker(error);
|
|
799
811
|
}
|
|
800
812
|
}
|
|
813
|
+
sizeBoundCanvas(renderSize);
|
|
801
814
|
renderKey = key;
|
|
802
815
|
}
|
|
803
816
|
if (settled && audioKey !== key) {
|
|
@@ -1033,10 +1046,15 @@ export function createBrowserBridge(options) {
|
|
|
1033
1046
|
if (workerPreview) {
|
|
1034
1047
|
try {
|
|
1035
1048
|
const result = await workerPreview.seek(at);
|
|
1036
|
-
if (result.
|
|
1049
|
+
if (result.engineDiagnostics)
|
|
1050
|
+
workerDiagnostics = result.engineDiagnostics;
|
|
1051
|
+
// An unchanged frame comes without a bitmap: the canvas still shows it.
|
|
1052
|
+
if (result.bitmap) {
|
|
1037
1053
|
boundCanvas
|
|
1038
1054
|
.getContext("bitmaprenderer")
|
|
1039
1055
|
.transferFromImageBitmap(result.bitmap);
|
|
1056
|
+
bitmapTransfers += 1;
|
|
1057
|
+
}
|
|
1040
1058
|
return result.rendered;
|
|
1041
1059
|
}
|
|
1042
1060
|
catch (error) {
|
|
@@ -1046,16 +1064,38 @@ export function createBrowserBridge(options) {
|
|
|
1046
1064
|
await abandonWorker(error);
|
|
1047
1065
|
}
|
|
1048
1066
|
}
|
|
1049
|
-
const rendered = await engine.render(at / 120000, {
|
|
1067
|
+
const { rendered, unchanged } = await engine.render(at / 120000, {
|
|
1050
1068
|
generation: engine.generation,
|
|
1051
1069
|
context: context(project, library),
|
|
1052
1070
|
});
|
|
1053
|
-
|
|
1071
|
+
// An unchanged frame was not presented: the bound canvas still shows the last copy.
|
|
1072
|
+
if (rendered && !unchanged && copySurface) {
|
|
1054
1073
|
boundCanvas
|
|
1055
1074
|
.getContext("bitmaprenderer")
|
|
1056
1075
|
.transferFromImageBitmap(engine.canvas.transferToImageBitmap());
|
|
1076
|
+
bitmapTransfers += 1;
|
|
1077
|
+
}
|
|
1057
1078
|
return rendered;
|
|
1058
1079
|
}
|
|
1080
|
+
/** Gives the bound canvas the size frames render at, which `size` is, unless it has it. */
|
|
1081
|
+
function sizeBoundCanvas(size) {
|
|
1082
|
+
if (!boundCanvas || !size)
|
|
1083
|
+
return;
|
|
1084
|
+
if (boundCanvas.width !== size[0])
|
|
1085
|
+
boundCanvas.width = size[0];
|
|
1086
|
+
if (boundCanvas.height !== size[1])
|
|
1087
|
+
boundCanvas.height = size[1];
|
|
1088
|
+
}
|
|
1089
|
+
/** Applies the bridge's tracing to the renderers drawing now. */
|
|
1090
|
+
function applyTracing() {
|
|
1091
|
+
if (engine) {
|
|
1092
|
+
engine.traceUploads = traceUploads;
|
|
1093
|
+
engine.setPassTiming?.(passTiming);
|
|
1094
|
+
}
|
|
1095
|
+
void workerPreview
|
|
1096
|
+
?.setTracing({ passTiming, traceUploads })
|
|
1097
|
+
.catch(() => { });
|
|
1098
|
+
}
|
|
1059
1099
|
/**
|
|
1060
1100
|
* Gives up the preview worker after `error`, whether it failed to start, to load a project or to
|
|
1061
1101
|
* draw: the main renderer, which loads every project the worker does, draws from then on, off
|
|
@@ -1176,7 +1216,7 @@ export function createBrowserBridge(options) {
|
|
|
1176
1216
|
playing = true;
|
|
1177
1217
|
playRequest = { rate, loop, policy };
|
|
1178
1218
|
const clock = (playClock = engine.playbackClock(policy, project.settings.frame_rate, rate, tick, performance.now()));
|
|
1179
|
-
//
|
|
1219
|
+
// The tick last asked for, and for a policy that waits for frames, whether it has been shown.
|
|
1180
1220
|
let requested = null, presented = false;
|
|
1181
1221
|
const step = (now) => {
|
|
1182
1222
|
if (!playing || disposed || generation !== playGeneration)
|
|
@@ -1205,15 +1245,17 @@ export function createBrowserBridge(options) {
|
|
|
1205
1245
|
.catch(onError);
|
|
1206
1246
|
return;
|
|
1207
1247
|
}
|
|
1208
|
-
//
|
|
1209
|
-
//
|
|
1210
|
-
|
|
1211
|
-
|
|
1248
|
+
// The clock asks for frame starts, so every policy asks for each frame once however often
|
|
1249
|
+
// the display refreshes; a waiting policy also moves on only after it is shown, and the
|
|
1250
|
+
// others let late frames go.
|
|
1251
|
+
const due = requested !== tick;
|
|
1252
|
+
if (!due)
|
|
1253
|
+
skippedRequests += 1;
|
|
1254
|
+
else if (!renderScheduled) {
|
|
1212
1255
|
renderScheduled = true;
|
|
1213
|
-
|
|
1214
|
-
|
|
1256
|
+
requested = tick;
|
|
1257
|
+
if (waits)
|
|
1215
1258
|
presented = false;
|
|
1216
|
-
}
|
|
1217
1259
|
const at = tick;
|
|
1218
1260
|
void enqueue(() => generation !== playGeneration ? false : renderAt(at, project))
|
|
1219
1261
|
.then(() => {
|
|
@@ -1251,12 +1293,14 @@ export function createBrowserBridge(options) {
|
|
|
1251
1293
|
extensionsWasmUrl: runtimeAssets.extensionsWasmUrl,
|
|
1252
1294
|
});
|
|
1253
1295
|
const { Engine } = await import("./runtime/engine.js");
|
|
1296
|
+
// Until a project loads and gives the render size (see `loaded`).
|
|
1254
1297
|
canvas.width = editor.document.project.settings.width;
|
|
1255
1298
|
canvas.height = editor.document.project.settings.height;
|
|
1256
1299
|
boundCanvas = canvas;
|
|
1257
1300
|
copySurface = false;
|
|
1258
1301
|
await workerPreview?.dispose();
|
|
1259
1302
|
workerPreview = null;
|
|
1303
|
+
workerDiagnostics = null;
|
|
1260
1304
|
const useWorker = features.worker.available && typeof canvas.getContext === "function";
|
|
1261
1305
|
engine = new Engine(useWorker ? new OffscreenCanvas(canvas.width, canvas.height) : canvas, sources, library, runtimeAssets);
|
|
1262
1306
|
mixer = new EngineAudioMixer(runtimeAssets, { enabled: audio });
|
|
@@ -1265,7 +1309,9 @@ export function createBrowserBridge(options) {
|
|
|
1265
1309
|
supplier = new AudioWindowSupplier(library);
|
|
1266
1310
|
try {
|
|
1267
1311
|
await engine.start();
|
|
1312
|
+
engine.setPreviewScale(previewScale);
|
|
1268
1313
|
capabilities = capabilityReport(engine.capabilityReport());
|
|
1314
|
+
await registerKeptEffects();
|
|
1269
1315
|
// The surface already shows copied frames (its context is a bitmap renderer's).
|
|
1270
1316
|
if (useWorker && workerGivenUp)
|
|
1271
1317
|
copySurface = true;
|
|
@@ -1287,11 +1333,16 @@ export function createBrowserBridge(options) {
|
|
|
1287
1333
|
// A worker that cannot start leaves the surface to the main renderer.
|
|
1288
1334
|
try {
|
|
1289
1335
|
await workerPreview.ready;
|
|
1336
|
+
await workerPreview.setPreviewScale(previewScale);
|
|
1337
|
+
if (effectDefinitions.size)
|
|
1338
|
+
await workerPreview.registerEffects(keptEffects());
|
|
1290
1339
|
}
|
|
1291
1340
|
catch (error) {
|
|
1292
1341
|
await abandonWorker(error);
|
|
1293
1342
|
}
|
|
1294
1343
|
}
|
|
1344
|
+
if (passTiming || traceUploads)
|
|
1345
|
+
applyTracing();
|
|
1295
1346
|
if (disposed || token !== binding) {
|
|
1296
1347
|
await engine.dispose();
|
|
1297
1348
|
engine = null;
|
|
@@ -1343,6 +1394,68 @@ export function createBrowserBridge(options) {
|
|
|
1343
1394
|
}
|
|
1344
1395
|
return true;
|
|
1345
1396
|
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Runtime effects `registerEffects` kept, by `id@version`, with their JSON text, in the order they
|
|
1399
|
+
* came: every renderer the bridge makes registers them.
|
|
1400
|
+
*/
|
|
1401
|
+
const effectDefinitions = new Map();
|
|
1402
|
+
const keptEffects = () => [...effectDefinitions.values()].map(({ definition }) => definition);
|
|
1403
|
+
function registerEffects(definitions) {
|
|
1404
|
+
return enqueue(async () => {
|
|
1405
|
+
const added = new Map();
|
|
1406
|
+
for (const definition of definitions) {
|
|
1407
|
+
if (typeof definition?.id !== "string" ||
|
|
1408
|
+
!Number.isInteger(definition.version))
|
|
1409
|
+
throw new EditorError("invalid_effect", "An effect definition needs a string id and an integer version", "effects");
|
|
1410
|
+
const key = `${definition.id}@${definition.version}`;
|
|
1411
|
+
const text = JSON.stringify(definition);
|
|
1412
|
+
const known = (added.get(key) ?? effectDefinitions.get(key))?.text;
|
|
1413
|
+
if (known === text)
|
|
1414
|
+
continue;
|
|
1415
|
+
if (known !== undefined)
|
|
1416
|
+
throw new EditorError("effect_conflict", `Effect ${key} is registered with another definition; a changed effect takes another version`, "effects", key);
|
|
1417
|
+
added.set(key, { definition, text });
|
|
1418
|
+
}
|
|
1419
|
+
if (!added.size)
|
|
1420
|
+
return;
|
|
1421
|
+
const fresh = [...added.values()].map(({ definition }) => definition);
|
|
1422
|
+
// The main renderer loads every project the worker does, so both hold every effect.
|
|
1423
|
+
if (engine)
|
|
1424
|
+
await engine.registerEffects(fresh);
|
|
1425
|
+
if (workerPreview) {
|
|
1426
|
+
try {
|
|
1427
|
+
await workerPreview.registerEffects(fresh);
|
|
1428
|
+
}
|
|
1429
|
+
catch (error) {
|
|
1430
|
+
// The main renderer has just registered the same definitions.
|
|
1431
|
+
await abandonWorker(error);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
for (const [key, entry] of added)
|
|
1435
|
+
effectDefinitions.set(key, entry);
|
|
1436
|
+
// A frame that drew one of them failed; it draws now.
|
|
1437
|
+
if (engine)
|
|
1438
|
+
refreshPreview();
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Registers the kept runtime effects on the main renderer `buildPreview` just started, one by
|
|
1443
|
+
* one: one its device refuses (kept while no preview was bound, so never compiled) is dropped and
|
|
1444
|
+
* reported, and the others draw. A device lost meanwhile drops none: the next render makes the
|
|
1445
|
+
* preview again, which registers them again.
|
|
1446
|
+
*/
|
|
1447
|
+
async function registerKeptEffects() {
|
|
1448
|
+
const kept = [...effectDefinitions];
|
|
1449
|
+
const results = await Promise.allSettled(kept.map(([, { definition }]) => engine.registerEffects([definition])));
|
|
1450
|
+
if (engine.deviceLost)
|
|
1451
|
+
return;
|
|
1452
|
+
for (const [index, result] of results.entries()) {
|
|
1453
|
+
if (result.status === "fulfilled")
|
|
1454
|
+
continue;
|
|
1455
|
+
effectDefinitions.delete(kept[index][0]);
|
|
1456
|
+
onError(result.reason);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1346
1459
|
/** Whether a renderer is ready, making it again first if a lost GPU left none. */
|
|
1347
1460
|
async function previewReady() {
|
|
1348
1461
|
if (engine)
|
|
@@ -1351,11 +1464,43 @@ export function createBrowserBridge(options) {
|
|
|
1351
1464
|
return false;
|
|
1352
1465
|
return recoverPreview();
|
|
1353
1466
|
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Renders the preview at `scale` times the document's size from now on, sizing the surfaces to
|
|
1469
|
+
* it, and draws the current frame again. Resolves once that frame is drawn.
|
|
1470
|
+
*/
|
|
1471
|
+
async function setPreviewScale(scale) {
|
|
1472
|
+
const next = checkedPreviewScale(scale);
|
|
1473
|
+
if (next === previewScale)
|
|
1474
|
+
return;
|
|
1475
|
+
previewScale = next;
|
|
1476
|
+
await enqueue(async () => {
|
|
1477
|
+
if (!engine || disposed)
|
|
1478
|
+
return;
|
|
1479
|
+
engine.setPreviewScale(previewScale);
|
|
1480
|
+
let size = renderKey === null ? null : engine.previewSize;
|
|
1481
|
+
if (size)
|
|
1482
|
+
engine.resize(size[0], size[1]);
|
|
1483
|
+
if (workerPreview) {
|
|
1484
|
+
try {
|
|
1485
|
+
const reply = await workerPreview.setPreviewScale(previewScale);
|
|
1486
|
+
if (reply?.renderSize)
|
|
1487
|
+
size = reply.renderSize;
|
|
1488
|
+
}
|
|
1489
|
+
catch (error) {
|
|
1490
|
+
await abandonWorker(error);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
sizeBoundCanvas(size);
|
|
1494
|
+
await renderAt(tick, await loaded());
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1354
1497
|
async function bindPreview(canvas) {
|
|
1355
1498
|
const token = ++binding;
|
|
1356
1499
|
await enqueue(async () => {
|
|
1357
1500
|
recoveryPending = false;
|
|
1358
1501
|
workerGivenUp = false;
|
|
1502
|
+
skippedRequests = 0;
|
|
1503
|
+
bitmapTransfers = 0;
|
|
1359
1504
|
if (!(await buildPreview(canvas, token)))
|
|
1360
1505
|
return;
|
|
1361
1506
|
// The surface is bound; a failing first frame is reported like any later one.
|
|
@@ -1593,7 +1738,7 @@ export function createBrowserBridge(options) {
|
|
|
1593
1738
|
throw new EditorError("export_busy", "Only one export may run per bridge", "export");
|
|
1594
1739
|
requireExportFrameRate(options.frameRate);
|
|
1595
1740
|
materializeText(editor.document);
|
|
1596
|
-
const snapshot = editor.document, revision = editor.revision;
|
|
1741
|
+
const snapshot = editor.document, revision = editor.revision, effects = keptEffects();
|
|
1597
1742
|
const compiled = compileEditorDocument(snapshot);
|
|
1598
1743
|
if (compiled.diagnostics.length)
|
|
1599
1744
|
throw compiled.diagnostics[0];
|
|
@@ -1644,6 +1789,8 @@ export function createBrowserBridge(options) {
|
|
|
1644
1789
|
signal.throwIfAborted();
|
|
1645
1790
|
await renderer.start();
|
|
1646
1791
|
signal.throwIfAborted();
|
|
1792
|
+
await renderer.registerEffects(effects, "export");
|
|
1793
|
+
signal.throwIfAborted();
|
|
1647
1794
|
renderer.loadProject(project, "export");
|
|
1648
1795
|
const refused = renderer.setCaptionFonts(fontStack);
|
|
1649
1796
|
// Heard once per job, not once per attempt.
|
|
@@ -1659,7 +1806,6 @@ export function createBrowserBridge(options) {
|
|
|
1659
1806
|
if (range.end <= range.start)
|
|
1660
1807
|
throw new EditorError("empty_export", "Project has no exportable range", "export");
|
|
1661
1808
|
const settings = project.settings;
|
|
1662
|
-
const name = `${project.name}.mp4`;
|
|
1663
1809
|
const { written, output, result } = await exportTimeline({
|
|
1664
1810
|
engine: renderer.wasm,
|
|
1665
1811
|
project,
|
|
@@ -1676,9 +1822,10 @@ export function createBrowserBridge(options) {
|
|
|
1676
1822
|
audioSupplier: audio,
|
|
1677
1823
|
range: { start: range.start / 120000, end: range.end / 120000 },
|
|
1678
1824
|
options: attemptOptions(options, attempt, project.settings),
|
|
1679
|
-
openOutput: (estimate) => openExportOutput({
|
|
1825
|
+
openOutput: ({ container, ...estimate }) => openExportOutput({
|
|
1680
1826
|
jobId: attempt.id.replace(/[^\w-]/g, "_"),
|
|
1681
|
-
name
|
|
1827
|
+
name: `${project.name}.${containerPolicy(container).extensions[0]}`,
|
|
1828
|
+
container,
|
|
1682
1829
|
target: options.output,
|
|
1683
1830
|
...estimate,
|
|
1684
1831
|
}),
|
|
@@ -1774,6 +1921,8 @@ export function createBrowserBridge(options) {
|
|
|
1774
1921
|
proxies.clear();
|
|
1775
1922
|
registry.dispose();
|
|
1776
1923
|
engine = null;
|
|
1924
|
+
measurer?.free();
|
|
1925
|
+
measurer = null;
|
|
1777
1926
|
detachOwner();
|
|
1778
1927
|
})();
|
|
1779
1928
|
return disposal;
|
|
@@ -1874,6 +2023,22 @@ export function createBrowserBridge(options) {
|
|
|
1874
2023
|
}
|
|
1875
2024
|
return families;
|
|
1876
2025
|
},
|
|
2026
|
+
async measureText(generator) {
|
|
2027
|
+
const { WasmTextMeasurer } = await loadWasm();
|
|
2028
|
+
if (disposed)
|
|
2029
|
+
throw new EditorError("disposed", "Bridge is disposed", "browser");
|
|
2030
|
+
// The fonts and canvas preview draws the draft with.
|
|
2031
|
+
const document = editor.draft;
|
|
2032
|
+
const fonts = fontStackOf(document);
|
|
2033
|
+
measurer ??= new WasmTextMeasurer();
|
|
2034
|
+
if (!sameList(measuredFonts, fonts)) {
|
|
2035
|
+
// A font the engine refuses is left out here as preview leaves it out, and reported there.
|
|
2036
|
+
registerCaptionFonts(measurer, fonts);
|
|
2037
|
+
measuredFonts = fonts;
|
|
2038
|
+
}
|
|
2039
|
+
const { width, height } = document.project.settings;
|
|
2040
|
+
return JSON.parse(measurer.measure(JSON.stringify(generator), width, height));
|
|
2041
|
+
},
|
|
1877
2042
|
conform,
|
|
1878
2043
|
/**
|
|
1879
2044
|
* Makes a proxy of a source whose original this session holds, keeps it, and previews from it
|
|
@@ -2140,11 +2305,33 @@ export function createBrowserBridge(options) {
|
|
|
2140
2305
|
return monitorVolume;
|
|
2141
2306
|
},
|
|
2142
2307
|
setTraceUploads(value) {
|
|
2143
|
-
|
|
2144
|
-
|
|
2308
|
+
traceUploads = value === true;
|
|
2309
|
+
applyTracing();
|
|
2145
2310
|
},
|
|
2311
|
+
setPassTiming(enabled) {
|
|
2312
|
+
passTiming = enabled === true;
|
|
2313
|
+
applyTracing();
|
|
2314
|
+
},
|
|
2315
|
+
get previewScale() {
|
|
2316
|
+
return previewScale;
|
|
2317
|
+
},
|
|
2318
|
+
setPreviewScale,
|
|
2146
2319
|
get diagnostics() {
|
|
2147
|
-
|
|
2320
|
+
// The renderer that draws: in worker mode the main-thread one does not.
|
|
2321
|
+
const snapshot = workerPreview
|
|
2322
|
+
? workerDiagnostics
|
|
2323
|
+
: (engine?.lastDiagnostics ?? null);
|
|
2324
|
+
if (!snapshot)
|
|
2325
|
+
return null;
|
|
2326
|
+
return {
|
|
2327
|
+
...snapshot,
|
|
2328
|
+
host: {
|
|
2329
|
+
...snapshot.host,
|
|
2330
|
+
skippedRequests,
|
|
2331
|
+
bitmapTransfers,
|
|
2332
|
+
previewScale,
|
|
2333
|
+
},
|
|
2334
|
+
};
|
|
2148
2335
|
},
|
|
2149
2336
|
get tick() {
|
|
2150
2337
|
return tick;
|
|
@@ -2175,6 +2362,7 @@ export function createBrowserBridge(options) {
|
|
|
2175
2362
|
get catalog() {
|
|
2176
2363
|
return engine?.catalog ?? null;
|
|
2177
2364
|
},
|
|
2365
|
+
registerEffects,
|
|
2178
2366
|
// A source's own media while it is online, whichever preview reads: its size, file and peaks
|
|
2179
2367
|
// are the original's.
|
|
2180
2368
|
getAsset: (id) => (preferredPreviewMedia === "proxies" &&
|
|
@@ -2182,6 +2370,15 @@ export function createBrowserBridge(options) {
|
|
|
2182
2370
|
library.get(id),
|
|
2183
2371
|
};
|
|
2184
2372
|
}
|
|
2373
|
+
/**
|
|
2374
|
+
* `scale` as a preview resolution scale: finite, above 0 and at most 8, as the engine's quality
|
|
2375
|
+
* profile takes it.
|
|
2376
|
+
*/
|
|
2377
|
+
function checkedPreviewScale(scale) {
|
|
2378
|
+
if (typeof scale !== "number" || !(scale > 0 && scale <= 8))
|
|
2379
|
+
throw new EditorError("invalid_preview_scale", "The preview scale must be a number above 0 and at most 8", "preview");
|
|
2380
|
+
return scale;
|
|
2381
|
+
}
|
|
2185
2382
|
/**
|
|
2186
2383
|
* Whether the engine draws a source itself, so no file backs it: a generated source or a
|
|
2187
2384
|
* composition.
|
|
@@ -10,6 +10,8 @@ export class Engine {
|
|
|
10
10
|
library: any;
|
|
11
11
|
kind: string;
|
|
12
12
|
traceUploads: boolean;
|
|
13
|
+
/** Which preview draws with this renderer, as its diagnostics report it. */
|
|
14
|
+
backend: string;
|
|
13
15
|
lastDiagnostics: any;
|
|
14
16
|
lastRenderMs: number;
|
|
15
17
|
onDiagnostics: any;
|
|
@@ -19,6 +21,19 @@ export class Engine {
|
|
|
19
21
|
effectCatalog: any;
|
|
20
22
|
}>;
|
|
21
23
|
catalog: any;
|
|
24
|
+
/**
|
|
25
|
+
* Turns per-pass GPU and CPU timing on or off; the passes then appear in `lastDiagnostics`.
|
|
26
|
+
* Off by default: timing is profiling cost, not rendering work.
|
|
27
|
+
*/
|
|
28
|
+
setPassTiming(enabled: any): void;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the preview resolution scale (the engine's `QualityProfile` resolution scale; 1 renders
|
|
31
|
+
* at the document's size) and returns the loaded project's render size as `[width, height]`, or
|
|
32
|
+
* null with no project loaded. Throws for a scale the engine refuses.
|
|
33
|
+
*/
|
|
34
|
+
setPreviewScale(scale: any): any[] | null;
|
|
35
|
+
/** The loaded project's render size at the preview scale, `[width, height]`, or null. */
|
|
36
|
+
get previewSize(): any[] | null;
|
|
22
37
|
/** The renderer's part of the capability report: GPU, color, and playback. */
|
|
23
38
|
capabilityReport(): any;
|
|
24
39
|
/** A clock for one run of playback; see the engine's `PlaybackPolicy`. */
|
|
@@ -46,6 +61,15 @@ export class Engine {
|
|
|
46
61
|
* failure stay known, so the next load neither leaks nor repeats them.
|
|
47
62
|
*/
|
|
48
63
|
loadProject(project: any, operation?: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Compiles runtime effect definitions (`alpha2/effects` `EffectDefinition`s) on this renderer's
|
|
66
|
+
* device and registers them, all or none. An `id@version` this renderer holds already is skipped:
|
|
67
|
+
* a definition never changes under its version.
|
|
68
|
+
*
|
|
69
|
+
* Throws `invalid_effect` naming the first definition the engine refuses, with its diagnostics;
|
|
70
|
+
* then none of the call's definitions is registered.
|
|
71
|
+
*/
|
|
72
|
+
registerEffects(definitions: any, operation?: string): Promise<void>;
|
|
49
73
|
/**
|
|
50
74
|
* Registers the fonts caption tracks draw with, in fallback order. An SVG's text draws with the
|
|
51
75
|
* same fonts, as the native host draws it with its caption fonts. Returns the fonts the engine
|
|
@@ -77,7 +101,9 @@ export class Engine {
|
|
|
77
101
|
get generation(): number;
|
|
78
102
|
/**
|
|
79
103
|
* Requests one frame. Concurrent requests collapse to the most recent one so that scrubbing never
|
|
80
|
-
* queues a backlog of stale frames.
|
|
104
|
+
* queues a backlog of stale frames. Resolves `{ rendered, unchanged }`: `rendered` is false when
|
|
105
|
+
* the request was superseded, and `unchanged` says the frame equals the one already shown, so
|
|
106
|
+
* nothing was drawn or presented and the surface still shows it.
|
|
81
107
|
*/
|
|
82
108
|
render(seconds: any, { generation, context }?: {
|
|
83
109
|
generation?: null | undefined;
|