@alpha2-sh/editor 0.3.0 → 0.3.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.js +12 -2
- package/dist/browser/runtime/engine.d.ts +7 -2
- package/dist/browser/runtime/engine.js +27 -6
- package/dist/browser/runtime/exporter.d.ts +3 -0
- package/dist/browser/runtime/exporter.js +14 -0
- package/dist/browser/runtime/sources.d.ts +17 -6
- package/dist/browser/runtime/sources.js +114 -9
- package/dist/browser/types.d.ts +12 -1
- package/dist/browser/worker.js +1 -1
- package/dist/core/document.js +1 -0
- package/dist/ports/index.d.ts +4 -2
- package/package.json +3 -3
package/dist/browser/bridge.js
CHANGED
|
@@ -1302,7 +1302,9 @@ export function createBrowserBridge(options) {
|
|
|
1302
1302
|
workerPreview = null;
|
|
1303
1303
|
workerDiagnostics = null;
|
|
1304
1304
|
const useWorker = features.worker.available && typeof canvas.getContext === "function";
|
|
1305
|
-
engine = new Engine(useWorker ? new OffscreenCanvas(canvas.width, canvas.height) : canvas, sources, library, runtimeAssets
|
|
1305
|
+
engine = new Engine(useWorker ? new OffscreenCanvas(canvas.width, canvas.height) : canvas, sources, library, runtimeAssets,
|
|
1306
|
+
// A frame shown at once matters more in a preview than the engine's conversion of it.
|
|
1307
|
+
{ unreadableFrames: "present" });
|
|
1306
1308
|
mixer = new EngineAudioMixer(runtimeAssets, { enabled: audio });
|
|
1307
1309
|
mixer.setMasterVolume(monitorVolume);
|
|
1308
1310
|
stalledAudio = null;
|
|
@@ -1737,6 +1739,9 @@ export function createBrowserBridge(options) {
|
|
|
1737
1739
|
if (jobs.size)
|
|
1738
1740
|
throw new EditorError("export_busy", "Only one export may run per bridge", "export");
|
|
1739
1741
|
requireExportFrameRate(options.frameRate);
|
|
1742
|
+
const videoDecode = options.videoDecode ?? "auto";
|
|
1743
|
+
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
1744
|
+
throw new EditorError("invalid_video_decode", `Export videoDecode must be "auto" or "software"; received ${JSON.stringify(videoDecode)}`, "export");
|
|
1740
1745
|
materializeText(editor.document);
|
|
1741
1746
|
const snapshot = editor.document, revision = editor.revision, effects = keptEffects();
|
|
1742
1747
|
const compiled = compileEditorDocument(snapshot);
|
|
@@ -1782,6 +1787,7 @@ export function createBrowserBridge(options) {
|
|
|
1782
1787
|
const project = compiled.project, lib = { get: (id) => map.get(id) };
|
|
1783
1788
|
const pixels = new SourcePixels(lib, {
|
|
1784
1789
|
extensionsWasmUrl: runtimeAssets.extensionsWasmUrl,
|
|
1790
|
+
videoDecode,
|
|
1785
1791
|
});
|
|
1786
1792
|
const renderer = new Engine(new OffscreenCanvas(project.settings.width, project.settings.height), pixels, lib, runtimeAssets);
|
|
1787
1793
|
const audio = new AudioWindowSupplier(lib);
|
|
@@ -1854,7 +1860,11 @@ export function createBrowserBridge(options) {
|
|
|
1854
1860
|
return {
|
|
1855
1861
|
...artifact,
|
|
1856
1862
|
media: Object.fromEntries(selection),
|
|
1857
|
-
report: {
|
|
1863
|
+
report: {
|
|
1864
|
+
...result,
|
|
1865
|
+
videoDecode,
|
|
1866
|
+
decodeFallbacks: pixels.decodeFallbacks,
|
|
1867
|
+
},
|
|
1858
1868
|
};
|
|
1859
1869
|
}
|
|
1860
1870
|
finally {
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* render queue that collapses to the newest request.
|
|
4
4
|
*/
|
|
5
5
|
export class Engine {
|
|
6
|
-
constructor(canvas: any, sources: any, library: any, runtimeAssets?: {});
|
|
6
|
+
constructor(canvas: any, sources: any, library: any, runtimeAssets?: {}, { unreadableFrames }?: {});
|
|
7
7
|
runtimeAssets: {};
|
|
8
|
+
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
9
|
+
unreadableFrames: any;
|
|
8
10
|
canvas: any;
|
|
9
11
|
sources: any;
|
|
10
12
|
library: any;
|
|
@@ -42,7 +44,10 @@ export class Engine {
|
|
|
42
44
|
audible(policy: any, rate: any): boolean;
|
|
43
45
|
get ready(): boolean;
|
|
44
46
|
get deviceLost(): any;
|
|
45
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Raw source video the frame supply copied through script memory, and the frames it could not
|
|
49
|
+
* read back and how it recovered them; cumulative.
|
|
50
|
+
*/
|
|
46
51
|
get sourceTransfer(): any;
|
|
47
52
|
/** The wasm object, for callers that drive audio directly. */
|
|
48
53
|
get wasm(): null;
|
|
@@ -34,8 +34,10 @@ export class Engine {
|
|
|
34
34
|
#unchanged = 0;
|
|
35
35
|
/** What `supply` uploaded for the export frame the engine has not rendered yet. */
|
|
36
36
|
#exportUploads = [];
|
|
37
|
-
constructor(canvas, sources, library, runtimeAssets = {}) {
|
|
37
|
+
constructor(canvas, sources, library, runtimeAssets = {}, { unreadableFrames } = {}) {
|
|
38
38
|
this.runtimeAssets = runtimeAssets;
|
|
39
|
+
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
40
|
+
this.unreadableFrames = unreadableFrames;
|
|
39
41
|
this.canvas = canvas;
|
|
40
42
|
this.sources = sources;
|
|
41
43
|
this.library = library;
|
|
@@ -58,7 +60,11 @@ export class Engine {
|
|
|
58
60
|
: await WebEffectRegistry.createForHtmlCanvas(this.canvas);
|
|
59
61
|
this.#effectResources = new Map();
|
|
60
62
|
this.#sizeResultCache();
|
|
61
|
-
this.#supply = new FrameSupply(this.#registry
|
|
63
|
+
this.#supply = new FrameSupply(this.#registry, {
|
|
64
|
+
...(this.unreadableFrames === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: { unreadableFrames: this.unreadableFrames }),
|
|
67
|
+
});
|
|
62
68
|
// `engine.traceUploads = true` in the console logs every source upload, to tell a host decode
|
|
63
69
|
// bug from an engine one when a clip shows another clip's picture.
|
|
64
70
|
this.#supply.onUpload = (entry) => {
|
|
@@ -125,11 +131,25 @@ export class Engine {
|
|
|
125
131
|
get deviceLost() {
|
|
126
132
|
return this.#registry?.deviceLost ?? false;
|
|
127
133
|
}
|
|
128
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Raw source video the frame supply copied through script memory, and the frames it could not
|
|
136
|
+
* read back and how it recovered them; cumulative.
|
|
137
|
+
*/
|
|
129
138
|
get sourceTransfer() {
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
return {
|
|
140
|
+
...(this.#supply?.sourceTransfer ?? {
|
|
141
|
+
planarCopyFrames: 0,
|
|
142
|
+
planarCopyBytes: 0,
|
|
143
|
+
}),
|
|
144
|
+
...this.#readbackRecovery(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
#readbackRecovery() {
|
|
148
|
+
return (this.#supply?.readbackRecovery ?? {
|
|
149
|
+
unreadableFrames: 0,
|
|
150
|
+
readbackRetries: 0,
|
|
151
|
+
redecodedFrames: 0,
|
|
152
|
+
presentedFrames: 0,
|
|
133
153
|
});
|
|
134
154
|
}
|
|
135
155
|
/** The wasm object, for callers that drive audio directly. */
|
|
@@ -411,6 +431,7 @@ export class Engine {
|
|
|
411
431
|
unchanged: this.#unchanged,
|
|
412
432
|
renderSize: [this.canvas.width, this.canvas.height],
|
|
413
433
|
backend: this.backend,
|
|
434
|
+
readbackRecovery: this.#readbackRecovery(),
|
|
414
435
|
};
|
|
415
436
|
this.lastDiagnostics = diagnostics;
|
|
416
437
|
this.onDiagnostics?.(diagnostics);
|
|
@@ -97,6 +97,9 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
97
97
|
outputRepackBytes: any;
|
|
98
98
|
sourcePlanarCopyFrames: any;
|
|
99
99
|
sourcePlanarCopyBytes: any;
|
|
100
|
+
sourceUnreadableFrames: any;
|
|
101
|
+
sourceReadbackRetries: any;
|
|
102
|
+
sourceRedecodedFrames: any;
|
|
100
103
|
peakEncodeQueueBytes: any;
|
|
101
104
|
maxPendingMediaEvents: any;
|
|
102
105
|
averagePendingMediaEvents: number;
|
|
@@ -381,6 +381,12 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
381
381
|
transferAfter.planarCopyFrames - transferBefore.planarCopyFrames;
|
|
382
382
|
metrics.sourcePlanarCopyBytes =
|
|
383
383
|
transferAfter.planarCopyBytes - transferBefore.planarCopyBytes;
|
|
384
|
+
metrics.sourceUnreadableFrames =
|
|
385
|
+
transferAfter.unreadableFrames - transferBefore.unreadableFrames;
|
|
386
|
+
metrics.sourceReadbackRetries =
|
|
387
|
+
transferAfter.readbackRetries - transferBefore.readbackRetries;
|
|
388
|
+
metrics.sourceRedecodedFrames =
|
|
389
|
+
transferAfter.redecodedFrames - transferBefore.redecodedFrames;
|
|
384
390
|
}
|
|
385
391
|
const result = {
|
|
386
392
|
renderMs,
|
|
@@ -577,6 +583,9 @@ function browserExportMetrics() {
|
|
|
577
583
|
outputRepackBytes: 0,
|
|
578
584
|
sourcePlanarCopyFrames: 0,
|
|
579
585
|
sourcePlanarCopyBytes: 0,
|
|
586
|
+
sourceUnreadableFrames: 0,
|
|
587
|
+
sourceReadbackRetries: 0,
|
|
588
|
+
sourceRedecodedFrames: 0,
|
|
580
589
|
peakEncodeQueueBytes: 0,
|
|
581
590
|
maxPendingMediaEvents: 0,
|
|
582
591
|
pendingDepthTotal: 0,
|
|
@@ -615,6 +624,11 @@ function finishBrowserExportMetrics(metrics, before, after) {
|
|
|
615
624
|
outputRepackBytes: metrics.outputRepackBytes,
|
|
616
625
|
sourcePlanarCopyFrames: metrics.sourcePlanarCopyFrames,
|
|
617
626
|
sourcePlanarCopyBytes: metrics.sourcePlanarCopyBytes,
|
|
627
|
+
// Source frames the browser could not read back, the reads repeated, and the frames decoded
|
|
628
|
+
// again in software for it.
|
|
629
|
+
sourceUnreadableFrames: metrics.sourceUnreadableFrames,
|
|
630
|
+
sourceReadbackRetries: metrics.sourceReadbackRetries,
|
|
631
|
+
sourceRedecodedFrames: metrics.sourceRedecodedFrames,
|
|
618
632
|
peakEncodeQueueBytes: metrics.peakEncodeQueueBytes,
|
|
619
633
|
maxPendingMediaEvents: metrics.maxPendingMediaEvents,
|
|
620
634
|
averagePendingMediaEvents: metrics.pendingDepthSamples === 0
|
|
@@ -17,16 +17,24 @@ export const DEFAULT_RASTER_BUDGET_BYTES: number;
|
|
|
17
17
|
export const DEFAULT_PROVIDER_SOURCE_BYTES: number;
|
|
18
18
|
/** The host side of the engine's per-frame source requests for one renderer (preview or export). */
|
|
19
19
|
export class SourcePixels {
|
|
20
|
-
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes, extensionsWasmUrl, }?: {
|
|
20
|
+
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes, extensionsWasmUrl, videoDecode, }?: {
|
|
21
21
|
decoderLimit?: number | undefined;
|
|
22
22
|
rasterBudgetBytes?: number | undefined;
|
|
23
23
|
providerSourceBytes?: number | undefined;
|
|
24
|
+
videoDecode?: string | undefined;
|
|
24
25
|
});
|
|
25
26
|
decoderLimit: number;
|
|
26
27
|
rasterBudgetBytes: number;
|
|
27
28
|
providerSourceBytes: number;
|
|
28
29
|
library: any;
|
|
29
30
|
extensionsWasmUrl: any;
|
|
31
|
+
/**
|
|
32
|
+
* How video decodes: `"auto"` lets the browser pick, a hardware decoder where it has one;
|
|
33
|
+
* `"software"` decodes on the CPU, so no frame needs a GPU readback, except a source the
|
|
34
|
+
* browser has no software decoder for, which decodes as `"auto"` and is reported in
|
|
35
|
+
* `decodeFallbacks`.
|
|
36
|
+
*/
|
|
37
|
+
videoDecode: string;
|
|
30
38
|
get diagnostics(): {
|
|
31
39
|
liveDecoders: number;
|
|
32
40
|
retainedFrameBytes: any;
|
|
@@ -58,16 +66,19 @@ export class SourcePixels {
|
|
|
58
66
|
/**
|
|
59
67
|
* Bound method handed to `FrameSupply` as its `pixelsFor` callback. `sourceId` is the source the
|
|
60
68
|
* engine asked for, which the layer may stand in for (a proxy has an ID of its own): decoders are
|
|
61
|
-
* kept per source, as `release` names them.
|
|
69
|
+
* kept per source, as `release` names them. `decode: "software"` asks for the frame decoded on
|
|
70
|
+
* the CPU (see `#softwareFrame`).
|
|
62
71
|
*/
|
|
63
|
-
pixelsFor: (layer: any, seconds: any, { preferVideoFrame, consumerId, sourceId }?: {
|
|
72
|
+
pixelsFor: (layer: any, seconds: any, { preferVideoFrame, consumerId, sourceId, decode }?: {
|
|
64
73
|
preferVideoFrame?: boolean | undefined;
|
|
65
74
|
consumerId?: any;
|
|
66
75
|
}) => Promise<any>;
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
69
|
-
* how many frames, and whether its decoding stopped for good
|
|
70
|
-
* {@link MAX_DECODE_FAILURES} frames running)
|
|
77
|
+
* What fell back, per source and kind: `"element-seek"`, frames read by element seeks rather
|
|
78
|
+
* than decoded, with the last reason, how many frames, and whether its decoding stopped for good
|
|
79
|
+
* (it could not open, or failed {@link MAX_DECODE_FAILURES} frames running);
|
|
80
|
+
* `"software-unavailable"`, a source `videoDecode: "software"` decoded as `"auto"` because the
|
|
81
|
+
* browser has no software decoder for it (`frames` 0). A browser export reports it.
|
|
71
82
|
*/
|
|
72
83
|
get decodeFallbacks(): any[];
|
|
73
84
|
/** Keeps decoder sessions bounded to consumers needed by the current frame. */
|
|
@@ -53,7 +53,9 @@ export class SourcePixels {
|
|
|
53
53
|
#fonts = [];
|
|
54
54
|
/** What each SVG's pixels are with the fonts it was drawn with, for `contentOf`. */
|
|
55
55
|
#fontContents = new WeakMap();
|
|
56
|
-
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionsWasmUrl, } = {}) {
|
|
56
|
+
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionsWasmUrl, videoDecode = "auto", } = {}) {
|
|
57
|
+
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
58
|
+
throw new RangeError('videoDecode must be "auto" or "software"');
|
|
57
59
|
if (!Number.isSafeInteger(rasterBudgetBytes) || rasterBudgetBytes <= 0)
|
|
58
60
|
throw new RangeError("rasterBudgetBytes must be a positive integer");
|
|
59
61
|
if (!Number.isSafeInteger(providerSourceBytes) || providerSourceBytes <= 0)
|
|
@@ -63,6 +65,13 @@ export class SourcePixels {
|
|
|
63
65
|
this.providerSourceBytes = providerSourceBytes;
|
|
64
66
|
this.library = library;
|
|
65
67
|
this.extensionsWasmUrl = extensionsWasmUrl;
|
|
68
|
+
/**
|
|
69
|
+
* How video decodes: `"auto"` lets the browser pick, a hardware decoder where it has one;
|
|
70
|
+
* `"software"` decodes on the CPU, so no frame needs a GPU readback, except a source the
|
|
71
|
+
* browser has no software decoder for, which decodes as `"auto"` and is reported in
|
|
72
|
+
* `decodeFallbacks`.
|
|
73
|
+
*/
|
|
74
|
+
this.videoDecode = videoDecode;
|
|
66
75
|
}
|
|
67
76
|
get diagnostics() {
|
|
68
77
|
const decoders = [...this.#decoders.values()]
|
|
@@ -126,10 +135,13 @@ export class SourcePixels {
|
|
|
126
135
|
/**
|
|
127
136
|
* Bound method handed to `FrameSupply` as its `pixelsFor` callback. `sourceId` is the source the
|
|
128
137
|
* engine asked for, which the layer may stand in for (a proxy has an ID of its own): decoders are
|
|
129
|
-
* kept per source, as `release` names them.
|
|
138
|
+
* kept per source, as `release` names them. `decode: "software"` asks for the frame decoded on
|
|
139
|
+
* the CPU (see `#softwareFrame`).
|
|
130
140
|
*/
|
|
131
|
-
pixelsFor = async (layer, seconds, { preferVideoFrame = false, consumerId = layer.id, sourceId } = {}) => {
|
|
141
|
+
pixelsFor = async (layer, seconds, { preferVideoFrame = false, consumerId = layer.id, sourceId, decode } = {}) => {
|
|
132
142
|
const asset = layer.asset ?? layer;
|
|
143
|
+
if (decode === "software")
|
|
144
|
+
return this.#softwareFrame(asset, seconds, consumerId, sourceId ?? asset.id);
|
|
133
145
|
if (asset.provider)
|
|
134
146
|
return this.#providerPixels(asset, providerKey(asset, consumerId), seconds);
|
|
135
147
|
if (asset.kind === "text")
|
|
@@ -480,7 +492,7 @@ export class SourcePixels {
|
|
|
480
492
|
decoder = undefined;
|
|
481
493
|
}
|
|
482
494
|
if (!decoder) {
|
|
483
|
-
if (this.#
|
|
495
|
+
if (this.#cursorCount() >= this.decoderLimit)
|
|
484
496
|
throw Object.assign(new Error("Video decoder budget reached"), {
|
|
485
497
|
code: "resource_budget",
|
|
486
498
|
});
|
|
@@ -501,7 +513,7 @@ export class SourcePixels {
|
|
|
501
513
|
}
|
|
502
514
|
// A decoder that cannot open (a codec the browser cannot decode) is the fallback's for good.
|
|
503
515
|
try {
|
|
504
|
-
decoder.video ??= await (decoder.opening ??=
|
|
516
|
+
decoder.video ??= await (decoder.opening ??= this.#openVideo(decoder));
|
|
505
517
|
}
|
|
506
518
|
catch (error) {
|
|
507
519
|
decoder.opening = null;
|
|
@@ -522,7 +534,7 @@ export class SourcePixels {
|
|
|
522
534
|
// decoder's surfaces do not hold up.
|
|
523
535
|
closeOpened(decoder);
|
|
524
536
|
try {
|
|
525
|
-
decoder.opening =
|
|
537
|
+
decoder.opening = this.#openVideo(decoder);
|
|
526
538
|
decoder.video = await decoder.opening;
|
|
527
539
|
decoded = await decoder.video.refill(request);
|
|
528
540
|
}
|
|
@@ -544,6 +556,96 @@ export class SourcePixels {
|
|
|
544
556
|
chromaSiting: decoded.chromaSiting,
|
|
545
557
|
};
|
|
546
558
|
}
|
|
559
|
+
/** Decoder cursors the budget counts: the software cursors of recovered frames are not. */
|
|
560
|
+
#cursorCount() {
|
|
561
|
+
let count = 0;
|
|
562
|
+
for (const decoder of this.#decoders.values())
|
|
563
|
+
if (!decoder.software)
|
|
564
|
+
count += 1;
|
|
565
|
+
return count;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Opens `decoder`'s source as `videoDecode` says. A source the browser has no software decoder
|
|
569
|
+
* for opens as `"auto"`, for good, and is reported once in `decodeFallbacks`.
|
|
570
|
+
*/
|
|
571
|
+
async #openVideo(decoder) {
|
|
572
|
+
const { asset } = decoder;
|
|
573
|
+
if (this.videoDecode !== "software" || decoder.softwareUnavailable)
|
|
574
|
+
return MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
575
|
+
try {
|
|
576
|
+
return await MediabunnyVideoDecoder.open(asset.id, asset.file, {
|
|
577
|
+
hardwareAcceleration: "prefer-software",
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
if (error?.code !== "software_decode_unavailable")
|
|
582
|
+
throw error;
|
|
583
|
+
decoder.softwareUnavailable = true;
|
|
584
|
+
const key = `software-unavailable\u0000${decoder.sourceId}`;
|
|
585
|
+
if (!this.#fallbacks.has(key))
|
|
586
|
+
this.#fallbacks.set(key, {
|
|
587
|
+
kind: "software-unavailable",
|
|
588
|
+
sourceId: decoder.sourceId,
|
|
589
|
+
reason: String(error.message),
|
|
590
|
+
frames: 0,
|
|
591
|
+
permanent: false,
|
|
592
|
+
});
|
|
593
|
+
return MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* The frame at `seconds` decoded on the CPU, on a cursor of its own beside the consumer's: what
|
|
598
|
+
* `FrameSupply` asks for when the browser could not read a hardware frame back. Rejects rather
|
|
599
|
+
* than falling back to an element seek, whose frame would be the browser's again.
|
|
600
|
+
*
|
|
601
|
+
* The cursor shares the consumer's source and consumer IDs, so `retainConsumers` and `release`
|
|
602
|
+
* close it with the consumer's; it stays open between frames, as readback failures come in runs
|
|
603
|
+
* and the next one then decodes on from it.
|
|
604
|
+
*/
|
|
605
|
+
async #softwareFrame(asset, seconds, consumerId, sourceId) {
|
|
606
|
+
if (!asset.file)
|
|
607
|
+
throw new Error(`${asset.id} has no file to decode in software`);
|
|
608
|
+
const cursor = `${decoderCursorKey(sourceId, consumerId)}\u0000software`;
|
|
609
|
+
let decoder = this.#decoders.get(cursor);
|
|
610
|
+
if (decoder && decoder.asset !== asset) {
|
|
611
|
+
await closeDecoder(decoder);
|
|
612
|
+
this.#decoders.delete(cursor);
|
|
613
|
+
decoder = undefined;
|
|
614
|
+
}
|
|
615
|
+
if (!decoder) {
|
|
616
|
+
decoder = {
|
|
617
|
+
sourceId,
|
|
618
|
+
asset,
|
|
619
|
+
consumerId,
|
|
620
|
+
software: true,
|
|
621
|
+
opening: null,
|
|
622
|
+
video: null,
|
|
623
|
+
};
|
|
624
|
+
this.#decoders.set(cursor, decoder);
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
decoder.video ??= await (decoder.opening ??= MediabunnyVideoDecoder.open(asset.id, asset.file, { hardwareAcceleration: "prefer-software" }));
|
|
628
|
+
const decoded = await decoder.video.refill({
|
|
629
|
+
sourceId: asset.id,
|
|
630
|
+
mediaTimeTicks: BigInt(Math.round(seconds * TICKS_PER_SECOND)),
|
|
631
|
+
reason: "prefetch",
|
|
632
|
+
generation: 0,
|
|
633
|
+
});
|
|
634
|
+
return {
|
|
635
|
+
kind: "video-frame",
|
|
636
|
+
frame: decoded.frame,
|
|
637
|
+
rotation: decoded.rotationDegrees ?? 0,
|
|
638
|
+
mirror: decoded.mirror ?? false,
|
|
639
|
+
chromaSiting: decoded.chromaSiting,
|
|
640
|
+
physicalTimeMicroseconds: decoded.frame.timestamp,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
// The next request opens it again.
|
|
645
|
+
closeOpened(decoder);
|
|
646
|
+
throw error;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
547
649
|
/**
|
|
548
650
|
* Records that `decoder`'s frame falls back to an element seek because of `error`; `permanent`
|
|
549
651
|
* applies it to every later frame of the cursor.
|
|
@@ -554,6 +656,7 @@ export class SourcePixels {
|
|
|
554
656
|
const reason = String(error?.message ?? error);
|
|
555
657
|
const known = this.#fallbacks.get(decoder.sourceId);
|
|
556
658
|
this.#fallbacks.set(decoder.sourceId, {
|
|
659
|
+
kind: "element-seek",
|
|
557
660
|
sourceId: decoder.sourceId,
|
|
558
661
|
reason,
|
|
559
662
|
frames: (known?.frames ?? 0) + 1,
|
|
@@ -565,9 +668,11 @@ export class SourcePixels {
|
|
|
565
668
|
return null;
|
|
566
669
|
}
|
|
567
670
|
/**
|
|
568
|
-
*
|
|
569
|
-
* how many frames, and whether its decoding stopped for good
|
|
570
|
-
* {@link MAX_DECODE_FAILURES} frames running)
|
|
671
|
+
* What fell back, per source and kind: `"element-seek"`, frames read by element seeks rather
|
|
672
|
+
* than decoded, with the last reason, how many frames, and whether its decoding stopped for good
|
|
673
|
+
* (it could not open, or failed {@link MAX_DECODE_FAILURES} frames running);
|
|
674
|
+
* `"software-unavailable"`, a source `videoDecode: "software"` decoded as `"auto"` because the
|
|
675
|
+
* browser has no software decoder for it (`frames` 0). A browser export reports it.
|
|
571
676
|
*/
|
|
572
677
|
get decodeFallbacks() {
|
|
573
678
|
return [...this.#fallbacks.values()].map((entry) => ({ ...entry }));
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -259,6 +259,16 @@ export interface BrowserExportOptions {
|
|
|
259
259
|
readonly memory?: {
|
|
260
260
|
readonly inFlightBytes?: number;
|
|
261
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* How source video decodes: `auto` (the default) lets the browser pick, a hardware decoder where
|
|
264
|
+
* it has one; `software` decodes on the CPU, so no frame is read back from the GPU, except a
|
|
265
|
+
* source the browser has no software decoder for, which decodes as `auto` and is reported in the
|
|
266
|
+
* result's `report.decodeFallbacks` (`kind: "software-unavailable"`). Either way the engine
|
|
267
|
+
* converts the same decoded values; a frame the browser cannot read back is decoded again in
|
|
268
|
+
* software. Another value is refused when the export starts, with an `EditorError`
|
|
269
|
+
* `invalid_video_decode`.
|
|
270
|
+
*/
|
|
271
|
+
readonly videoDecode?: "auto" | "software";
|
|
262
272
|
}
|
|
263
273
|
/** Where a browser export writes its file. */
|
|
264
274
|
export type ExportOutputTarget = {
|
|
@@ -620,7 +630,8 @@ export interface BrowserBridge {
|
|
|
620
630
|
* decisions must be loaded: call {@link BrowserBridge.conform} first, or pass `assetDecisions`.
|
|
621
631
|
*
|
|
622
632
|
* Throws synchronously when the bridge is disposed (`disposed`), another export runs
|
|
623
|
-
* (`export_busy`), `frameRate` is not one the engine reads (`invalid_frame_rate`),
|
|
633
|
+
* (`export_busy`), `frameRate` is not one the engine reads (`invalid_frame_rate`), `videoDecode`
|
|
634
|
+
* is not `auto` or `software` (`invalid_video_decode`), the asset
|
|
624
635
|
* decisions are not loaded (`conform_pending`), the media is not ready (`ConformError`), or the
|
|
625
636
|
* document does not compile. Everything later is reported through the job's `result`.
|
|
626
637
|
*/
|
package/dist/browser/worker.js
CHANGED
|
@@ -61,7 +61,7 @@ export function installEditorWorker(scope) {
|
|
|
61
61
|
});
|
|
62
62
|
const { Engine } = await import("./runtime/engine.js");
|
|
63
63
|
engine = new Engine(request.canvas ??
|
|
64
|
-
new OffscreenCanvas(request.width ?? 16, request.height ?? 16), pixels, library, request.runtimeAssets);
|
|
64
|
+
new OffscreenCanvas(request.width ?? 16, request.height ?? 16), pixels, library, request.runtimeAssets, { unreadableFrames: "present" });
|
|
65
65
|
audio = new AudioWindowSupplier(library);
|
|
66
66
|
engine.backend = "worker";
|
|
67
67
|
await engine.start();
|
package/dist/core/document.js
CHANGED
|
@@ -35,6 +35,7 @@ const EDITOR_FAILURE_CODES = Object.freeze({
|
|
|
35
35
|
invalid_rate: "INVALID_INPUT",
|
|
36
36
|
invalid_time: "INVALID_INPUT",
|
|
37
37
|
invalid_transition: "INVALID_INPUT",
|
|
38
|
+
invalid_video_decode: "INVALID_INPUT",
|
|
38
39
|
locked: "INVALID_INPUT",
|
|
39
40
|
missing_asset: "INVALID_INPUT",
|
|
40
41
|
preview_worker_failed: "UNKNOWN",
|
package/dist/ports/index.d.ts
CHANGED
|
@@ -96,8 +96,10 @@ export type ExportArtifact = ({
|
|
|
96
96
|
readonly bytes?: number;
|
|
97
97
|
/**
|
|
98
98
|
* What the exporter reported about the run: timings, `performance` (with `memory` and `output`),
|
|
99
|
-
* rates. A browser export adds `
|
|
100
|
-
*
|
|
99
|
+
* rates. A browser export adds `videoDecode`, the decode mode it ran with, and `decodeFallbacks`:
|
|
100
|
+
* per source, frames read by element seeks rather than decoded (`kind: "element-seek"`), with
|
|
101
|
+
* why, how many frames, and whether for good, and sources `videoDecode: "software"` could not
|
|
102
|
+
* decode in software (`kind: "software-unavailable"`).
|
|
101
103
|
*/
|
|
102
104
|
readonly report?: Readonly<Record<string, unknown>>;
|
|
103
105
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Headless Project-based editing sessions and browser adapters for alpha2.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"build": "rm -rf dist && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.3.
|
|
63
|
+
"alpha2": "0.3.1",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.3.
|
|
67
|
+
"alpha2": "0.3.1",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|