@alpha2-sh/editor 0.5.0 → 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.js +16 -19
- package/dist/browser/runtime/assets.d.ts +5 -0
- package/dist/browser/runtime/assets.js +8 -1
- package/dist/browser/runtime/audio.js +44 -28
- package/dist/browser/runtime/engine.d.ts +5 -0
- package/dist/browser/runtime/engine.js +9 -0
- package/dist/browser/runtime/proxies.d.ts +9 -2
- package/dist/browser/runtime/proxies.js +39 -6
- package/dist/browser/types.d.ts +16 -6
- package/dist/browser/worker.d.ts +2 -1
- package/dist/browser/worker.js +14 -1
- package/dist/core/document.js +1 -0
- package/package.json +3 -3
package/dist/browser/bridge.js
CHANGED
|
@@ -297,12 +297,16 @@ export function createBrowserBridge(options) {
|
|
|
297
297
|
const descriptor = document.assets[source.id];
|
|
298
298
|
const record = proxies.get(hashOf(descriptor))?.record;
|
|
299
299
|
const revision = descriptor?.contentRevision ?? 0;
|
|
300
|
+
const original = originalOf(document, source.id);
|
|
300
301
|
return {
|
|
301
302
|
source_id: source.id,
|
|
302
303
|
revision,
|
|
303
|
-
original:
|
|
304
|
+
original: original
|
|
304
305
|
? { state: "online", fingerprint: descriptor?.fingerprint ?? {} }
|
|
305
306
|
: { state: "offline" },
|
|
307
|
+
...(original?.audioStreams
|
|
308
|
+
? { audio_streams: original.audioStreams }
|
|
309
|
+
: {}),
|
|
306
310
|
proxies: record
|
|
307
311
|
? [
|
|
308
312
|
{
|
|
@@ -774,6 +778,8 @@ export function createBrowserBridge(options) {
|
|
|
774
778
|
reportRefusedFonts(refused, "preview");
|
|
775
779
|
}
|
|
776
780
|
engine.loadProject(compiled.project);
|
|
781
|
+
if (onCpu())
|
|
782
|
+
reportCpuEffects(engine.projectRuntimeEffects());
|
|
777
783
|
// A worker given up for one project is tried again for the next.
|
|
778
784
|
if (renderKey !== null && !workerPreview)
|
|
779
785
|
workerGivenUp = false;
|
|
@@ -1431,7 +1437,7 @@ export function createBrowserBridge(options) {
|
|
|
1431
1437
|
try {
|
|
1432
1438
|
await workerPreview.ready;
|
|
1433
1439
|
await workerPreview.setPreviewScale(previewScale);
|
|
1434
|
-
if (effectDefinitions.size
|
|
1440
|
+
if (effectDefinitions.size)
|
|
1435
1441
|
await workerPreview.registerEffects(keptEffects());
|
|
1436
1442
|
}
|
|
1437
1443
|
catch (error) {
|
|
@@ -1508,11 +1514,11 @@ export function createBrowserBridge(options) {
|
|
|
1508
1514
|
}
|
|
1509
1515
|
return true;
|
|
1510
1516
|
}
|
|
1511
|
-
/** Whether the main renderer draws on the CPU, where runtime effects
|
|
1517
|
+
/** Whether the main renderer draws on the CPU, where projects drawing runtime effects fail. */
|
|
1512
1518
|
function onCpu() {
|
|
1513
1519
|
return engine?.rendererChoice?.renderer === "cpu";
|
|
1514
1520
|
}
|
|
1515
|
-
/**
|
|
1521
|
+
/** Drawn runtime effects already reported on the CPU renderer, by `id@version`. */
|
|
1516
1522
|
const cpuRefusedEffects = new Set();
|
|
1517
1523
|
function reportCpuEffects(keys) {
|
|
1518
1524
|
for (const key of keys) {
|
|
@@ -1547,13 +1553,6 @@ export function createBrowserBridge(options) {
|
|
|
1547
1553
|
if (!added.size)
|
|
1548
1554
|
return;
|
|
1549
1555
|
const fresh = [...added.values()].map(({ definition }) => definition);
|
|
1550
|
-
if (onCpu()) {
|
|
1551
|
-
// Kept for a GPU preview or export even though the current CPU renderer refuses them.
|
|
1552
|
-
for (const [key, entry] of added)
|
|
1553
|
-
effectDefinitions.set(key, entry);
|
|
1554
|
-
reportCpuEffects([...added.keys()]);
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
1556
|
// The main renderer loads every project the worker does, so both hold every effect.
|
|
1558
1557
|
if (engine)
|
|
1559
1558
|
await engine.registerEffects(fresh);
|
|
@@ -1576,14 +1575,9 @@ export function createBrowserBridge(options) {
|
|
|
1576
1575
|
/**
|
|
1577
1576
|
* Registers kept effects on the main renderer `buildPreview` just started, one at a time. One its
|
|
1578
1577
|
* device refuses (kept unbound, so never compiled) is dropped and reported. A device lost
|
|
1579
|
-
* meanwhile drops none, since the next render rebuilds and re-registers.
|
|
1580
|
-
* is dropped (a later GPU preview or export runs them) and each is reported once.
|
|
1578
|
+
* meanwhile drops none, since the next render rebuilds and re-registers.
|
|
1581
1579
|
*/
|
|
1582
1580
|
async function registerKeptEffects() {
|
|
1583
|
-
if (onCpu()) {
|
|
1584
|
-
reportCpuEffects([...effectDefinitions.keys()]);
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1587
1581
|
const kept = [...effectDefinitions];
|
|
1588
1582
|
const results = await Promise.allSettled(kept.map(([, { definition }]) => engine.registerEffects([definition])));
|
|
1589
1583
|
if (engine.deviceLost)
|
|
@@ -1976,6 +1970,9 @@ export function createBrowserBridge(options) {
|
|
|
1976
1970
|
await renderer.registerEffects(effects, "export");
|
|
1977
1971
|
signal.throwIfAborted();
|
|
1978
1972
|
renderer.loadProject(project, "export");
|
|
1973
|
+
// Only an export that draws no runtime effect can move to the CPU renderer.
|
|
1974
|
+
retryPolicy.cpuRenderer =
|
|
1975
|
+
renderer.projectRuntimeEffects().length === 0;
|
|
1979
1976
|
const refused = renderer.setCaptionFonts(fontStack);
|
|
1980
1977
|
// Reported once per job, not per attempt.
|
|
1981
1978
|
if (!fontsReported)
|
|
@@ -2064,8 +2061,8 @@ export function createBrowserBridge(options) {
|
|
|
2064
2061
|
}
|
|
2065
2062
|
},
|
|
2066
2063
|
};
|
|
2067
|
-
//
|
|
2068
|
-
const retryPolicy = { cpuRenderer:
|
|
2064
|
+
// Narrowed by each attempt once its renderer has loaded the project.
|
|
2065
|
+
const retryPolicy = { cpuRenderer: true };
|
|
2069
2066
|
const job = new ExportJob(revision, snapshot, backend, () => {
|
|
2070
2067
|
held.forEach((l) => l.release());
|
|
2071
2068
|
jobs.delete(job);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* has audio. Null when the demuxer cannot read the container.
|
|
5
5
|
*/
|
|
6
6
|
export function probeVideo(file: any): Promise<{
|
|
7
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
7
8
|
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
8
9
|
video: {
|
|
9
10
|
colorMetadata: import("alpha2/project").ColorMetadata | null;
|
|
@@ -115,6 +116,7 @@ export class AssetLibrary {
|
|
|
115
116
|
fit: string;
|
|
116
117
|
thumbnail: null;
|
|
117
118
|
peaks: null;
|
|
119
|
+
audioStreams?: any;
|
|
118
120
|
audioDecodeFacts?: any;
|
|
119
121
|
id: any;
|
|
120
122
|
kind: string;
|
|
@@ -132,6 +134,7 @@ export class AssetLibrary {
|
|
|
132
134
|
} | {
|
|
133
135
|
peaks: null;
|
|
134
136
|
thumbnail: null;
|
|
137
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
135
138
|
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
136
139
|
id: any;
|
|
137
140
|
kind: string;
|
|
@@ -171,6 +174,7 @@ export class AssetLibrary {
|
|
|
171
174
|
fit: string;
|
|
172
175
|
thumbnail: null;
|
|
173
176
|
peaks: null;
|
|
177
|
+
audioStreams?: any;
|
|
174
178
|
audioDecodeFacts?: any;
|
|
175
179
|
id: any;
|
|
176
180
|
kind: string;
|
|
@@ -188,6 +192,7 @@ export class AssetLibrary {
|
|
|
188
192
|
} | {
|
|
189
193
|
peaks: null;
|
|
190
194
|
thumbnail: null;
|
|
195
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
191
196
|
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
192
197
|
id: any;
|
|
193
198
|
kind: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Media library: import, probe, and keep browser-side resources for each source. The engine only
|
|
2
2
|
// learns that a source exists (`browser://<id>`); this module answers its per-frame requests.
|
|
3
3
|
import { codecName, colorMetadataFromVideoColorSpace, DecodeUnavailableError, decodeRefusalMessage, pictureDetails, PlanarDecodeUnavailableError, } from "alpha2/hdr-frames";
|
|
4
|
-
import { MediabunnyVideoDecoder, probeAudioSource, probePlanarDecode, videoTrackFacts, } from "alpha2/mediabunny";
|
|
4
|
+
import { MediabunnyVideoDecoder, probeAudioSource, probeAudioStreams, probePlanarDecode, videoTrackFacts, } from "alpha2/mediabunny";
|
|
5
5
|
import { TICKS_PER_SECOND } from "alpha2/project";
|
|
6
6
|
import { OffscreenTextRasterizer } from "alpha2/text";
|
|
7
7
|
import { ALL_FORMATS, AudioSampleSink, BlobSource, Input } from "mediabunny";
|
|
@@ -319,6 +319,7 @@ export class AssetLibrary {
|
|
|
319
319
|
...(probe?.audioDecodeFacts
|
|
320
320
|
? { audioDecodeFacts: probe.audioDecodeFacts }
|
|
321
321
|
: {}),
|
|
322
|
+
...(probe?.audioStreams ? { audioStreams: probe.audioStreams } : {}),
|
|
322
323
|
colorMetadata: read.colorMetadata,
|
|
323
324
|
// Whether this browser hands frames over as planes (a session fact). "unavailable" previews
|
|
324
325
|
// degraded and is never exported here.
|
|
@@ -342,6 +343,7 @@ export class AssetLibrary {
|
|
|
342
343
|
}
|
|
343
344
|
async #importAudio(file, reference = null) {
|
|
344
345
|
const { duration, decodable, facts } = await probeAudio(file);
|
|
346
|
+
const audioStreams = await probeAudioStreams(file).catch(() => null);
|
|
345
347
|
const asset = {
|
|
346
348
|
id: reference?.id ?? uid("src"),
|
|
347
349
|
kind: "audio",
|
|
@@ -352,6 +354,7 @@ export class AssetLibrary {
|
|
|
352
354
|
hasAudio: true,
|
|
353
355
|
audioDecodable: decodable,
|
|
354
356
|
...(facts ? { audioDecodeFacts: facts } : {}),
|
|
357
|
+
...(audioStreams ? { audioStreams } : {}),
|
|
355
358
|
peaks: null,
|
|
356
359
|
thumbnail: null,
|
|
357
360
|
};
|
|
@@ -520,11 +523,15 @@ export async function probeVideo(file) {
|
|
|
520
523
|
};
|
|
521
524
|
}
|
|
522
525
|
const audioDecode = audio ? await audioDecoding(file) : null;
|
|
526
|
+
const audioStreams = audio
|
|
527
|
+
? await probeAudioStreams(file).catch(() => null)
|
|
528
|
+
: [];
|
|
523
529
|
return {
|
|
524
530
|
video,
|
|
525
531
|
hasAudio: audio !== null,
|
|
526
532
|
audioDecodable: audioDecode?.decodable ?? false,
|
|
527
533
|
...(audioDecode?.facts ? { audioDecodeFacts: audioDecode.facts } : {}),
|
|
534
|
+
...(audioStreams ? { audioStreams } : {}),
|
|
528
535
|
};
|
|
529
536
|
}
|
|
530
537
|
catch (error) {
|
|
@@ -32,6 +32,10 @@ function coalesceRanges(ranges) {
|
|
|
32
32
|
function minBigInt(a, b) {
|
|
33
33
|
return a < b ? a : b;
|
|
34
34
|
}
|
|
35
|
+
/** One audio stream of a source as `audioNeeds` names it; `stream` is undefined for the default. */
|
|
36
|
+
function laneKey(sourceId, stream) {
|
|
37
|
+
return stream === undefined ? sourceId : JSON.stringify([sourceId, stream]);
|
|
38
|
+
}
|
|
35
39
|
/**
|
|
36
40
|
* Sources that contribute to the mix, with their browser-side asset. A video file with a sound
|
|
37
41
|
* track declares `has_audio`, so its clip on a video track is mixed without a separate audio clip.
|
|
@@ -57,8 +61,9 @@ export class AudioWindowSupplier {
|
|
|
57
61
|
#sampleRate = 48_000;
|
|
58
62
|
#generation = 0;
|
|
59
63
|
#controller = new AbortController();
|
|
64
|
+
/** Open decoders by `laneKey`. */
|
|
60
65
|
#decoders = new Map();
|
|
61
|
-
/** Per source, the earliest tick the previous request needed. */
|
|
66
|
+
/** Per source stream (`laneKey`), the earliest tick the previous request needed. */
|
|
62
67
|
#lastStarts = new Map();
|
|
63
68
|
/** Per source, the tick the engine's audio was last trimmed below (or would have been). */
|
|
64
69
|
#trimmed = new Map();
|
|
@@ -76,12 +81,12 @@ export class AudioWindowSupplier {
|
|
|
76
81
|
this.#lastStarts.clear();
|
|
77
82
|
this.#trimmed.clear();
|
|
78
83
|
const audible = new Set(audibleSources(project, this.#library).map(({ id }) => id));
|
|
79
|
-
for (const [
|
|
80
|
-
const asset = this.#library.get(sourceId);
|
|
81
|
-
if (audible.has(sourceId) && asset?.file === entry.file)
|
|
84
|
+
for (const [lane, entry] of this.#decoders) {
|
|
85
|
+
const asset = this.#library.get(entry.sourceId);
|
|
86
|
+
if (audible.has(entry.sourceId) && asset?.file === entry.file)
|
|
82
87
|
continue;
|
|
83
88
|
closeDecoder(entry.promise);
|
|
84
|
-
this.#decoders.delete(
|
|
89
|
+
this.#decoders.delete(lane);
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
async supply(startSample, frames, { signal, forceSources = [] } = {}) {
|
|
@@ -95,33 +100,39 @@ export class AudioWindowSupplier {
|
|
|
95
100
|
try {
|
|
96
101
|
const needs = JSON.parse(engine.audioNeeds(BigInt(startSample), frames));
|
|
97
102
|
const forced = new Set(forceSources);
|
|
98
|
-
const
|
|
103
|
+
const byLane = new Map();
|
|
99
104
|
for (const need of needs) {
|
|
100
|
-
const
|
|
101
|
-
|
|
105
|
+
const lane = laneKey(need.sourceId, need.stream);
|
|
106
|
+
const entry = byLane.get(lane) ?? {
|
|
107
|
+
sourceId: need.sourceId,
|
|
108
|
+
stream: need.stream,
|
|
109
|
+
ranges: [],
|
|
110
|
+
};
|
|
111
|
+
entry.ranges.push({
|
|
102
112
|
start: BigInt(need.startTicks),
|
|
103
113
|
end: BigInt(need.endTicks),
|
|
104
114
|
});
|
|
105
|
-
|
|
115
|
+
byLane.set(lane, entry);
|
|
106
116
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
// Trimming drops every stream of a source, so it stops short of the earliest of them.
|
|
118
|
+
const earliest = new Map();
|
|
119
|
+
for (const { sourceId, ranges } of byLane.values())
|
|
120
|
+
for (const { start } of ranges)
|
|
121
|
+
earliest.set(sourceId, minBigInt(earliest.get(sourceId) ?? start, start));
|
|
111
122
|
running = earliest;
|
|
112
123
|
this.#inFlight.add(running);
|
|
113
124
|
for (const [sourceId, start] of earliest)
|
|
114
125
|
this.#trim(sourceId, start);
|
|
115
|
-
// The engine replaces any window an upload overlaps, so one
|
|
126
|
+
// The engine replaces any window an upload overlaps, so one stream's requests run in order
|
|
116
127
|
// and each prefetch stops short of the next request.
|
|
117
|
-
await Promise.all([...
|
|
128
|
+
await Promise.all([...byLane].map(async ([lane, { sourceId, stream, ranges }]) => {
|
|
118
129
|
const requests = coalesceRanges(ranges);
|
|
119
130
|
// Reversed clips and ping-pong backward passes read backwards, so prefetch goes that way.
|
|
120
|
-
const previous = this.#lastStarts.get(
|
|
131
|
+
const previous = this.#lastStarts.get(lane);
|
|
121
132
|
const backward = previous !== undefined &&
|
|
122
133
|
requests[0].start < previous &&
|
|
123
134
|
previous - requests[0].start <= TICKS_PER_SECOND;
|
|
124
|
-
this.#lastStarts.set(
|
|
135
|
+
this.#lastStarts.set(lane, requests[0].start);
|
|
125
136
|
for (let index = 0; index < requests.length; index += 1) {
|
|
126
137
|
const { start, end } = requests[index];
|
|
127
138
|
const neighbour = requests[backward ? index - 1 : index + 1];
|
|
@@ -136,7 +147,7 @@ export class AudioWindowSupplier {
|
|
|
136
147
|
const window = backward
|
|
137
148
|
? { start: start > prefetch ? start - prefetch : 0n, end }
|
|
138
149
|
: { start, end: end + prefetch };
|
|
139
|
-
await this.#supplyRange(sourceId, start, end, window, {
|
|
150
|
+
await this.#supplyRange(sourceId, stream, start, end, window, {
|
|
140
151
|
forced: forced.has(sourceId),
|
|
141
152
|
generation,
|
|
142
153
|
signal: combined.signal,
|
|
@@ -174,30 +185,33 @@ export class AudioWindowSupplier {
|
|
|
174
185
|
this.#engine.trimAudioBefore(sourceId, before);
|
|
175
186
|
this.#trimmed.set(sourceId, before);
|
|
176
187
|
}
|
|
177
|
-
async #supplyRange(sourceId, startTicks, endTicks, decodeWindow, { forced, generation, signal }) {
|
|
188
|
+
async #supplyRange(sourceId, stream, startTicks, endTicks, decodeWindow, { forced, generation, signal }) {
|
|
178
189
|
const engine = this.#engine;
|
|
179
190
|
const requiredStart = Math.max(0, ticksToSampleFloor(startTicks, this.#sampleRate) - 2);
|
|
180
191
|
const requiredEnd = ticksToSampleCeil(endTicks, this.#sampleRate) + 2;
|
|
181
192
|
// The engine extends, replaces and drops windows itself, so ask what it holds.
|
|
182
193
|
if (!forced &&
|
|
183
|
-
JSON.parse(engine.audioRetainedWindows(sourceId)).some((window) => window.startSample <= requiredStart &&
|
|
194
|
+
JSON.parse(engine.audioRetainedWindows(sourceId, stream)).some((window) => window.startSample <= requiredStart &&
|
|
184
195
|
window.endSample >= requiredEnd))
|
|
185
196
|
return;
|
|
186
197
|
const asset = this.#library.get(sourceId);
|
|
187
198
|
if (!asset)
|
|
188
199
|
throw new Error(`audio source ${sourceId} is unavailable`);
|
|
189
|
-
|
|
200
|
+
// A page-made `AudioBuffer` is a single stream.
|
|
201
|
+
const missingStream = asset.audioBuffer && (stream ?? 0) > 0;
|
|
202
|
+
if ((asset.audioDecodable === false && !asset.audioBuffer) ||
|
|
203
|
+
missingStream) {
|
|
190
204
|
// Undecodable here (`RuntimeAsset.audioDecodable`): silent, though the document keeps it.
|
|
191
|
-
engine.uploadAudioBlock(sourceId, BigInt(requiredStart), this.#sampleRate, 1, new Float32Array(Math.max(1, requiredEnd - requiredStart)));
|
|
205
|
+
engine.uploadAudioBlock(sourceId, BigInt(requiredStart), this.#sampleRate, 1, new Float32Array(Math.max(1, requiredEnd - requiredStart)), false, stream);
|
|
192
206
|
return;
|
|
193
207
|
}
|
|
194
208
|
const block = asset.audioBuffer
|
|
195
209
|
? blockFromAudioBuffer(sourceId, asset.audioBuffer, decodeWindow.start, decodeWindow.end, this.#sampleRate, generation)
|
|
196
|
-
: await this.#decode(sourceId, asset, decodeWindow.start, decodeWindow.end, generation, signal);
|
|
210
|
+
: await this.#decode(sourceId, stream, asset, decodeWindow.start, decodeWindow.end, generation, signal);
|
|
197
211
|
throwIfAborted(signal);
|
|
198
212
|
if (generation !== this.#generation)
|
|
199
213
|
return;
|
|
200
|
-
engine.uploadAudioBlock(sourceId, block.startSample, block.sampleRate, block.speakers ?? block.channels.length, flattenPlanes(block.channels));
|
|
214
|
+
engine.uploadAudioBlock(sourceId, block.startSample, block.sampleRate, block.speakers ?? block.channels.length, flattenPlanes(block.channels), false, stream);
|
|
201
215
|
}
|
|
202
216
|
async close() {
|
|
203
217
|
this.#controller.abort();
|
|
@@ -207,19 +221,21 @@ export class AudioWindowSupplier {
|
|
|
207
221
|
this.#engine = null;
|
|
208
222
|
await Promise.allSettled(closing);
|
|
209
223
|
}
|
|
210
|
-
async #decode(sourceId, asset, startTicks, endTicks, generation, signal) {
|
|
224
|
+
async #decode(sourceId, stream, asset, startTicks, endTicks, generation, signal) {
|
|
211
225
|
if (!asset.file)
|
|
212
226
|
throw new Error(`audio source ${sourceId} has no decodable file`);
|
|
213
|
-
|
|
227
|
+
const lane = laneKey(sourceId, stream);
|
|
228
|
+
let entry = this.#decoders.get(lane);
|
|
214
229
|
if (!entry || entry.file !== asset.file) {
|
|
215
230
|
if (entry)
|
|
216
231
|
closeDecoder(entry.promise);
|
|
217
232
|
entry = {
|
|
233
|
+
sourceId,
|
|
218
234
|
file: asset.file,
|
|
219
235
|
// The engine's own resampler, as on native; alpha2/wasm is loaded by now.
|
|
220
|
-
promise: MediabunnyAudioDecoder.open(sourceId, asset.file, engineBinding),
|
|
236
|
+
promise: MediabunnyAudioDecoder.open(sourceId, asset.file, engineBinding, stream === undefined ? {} : { stream }),
|
|
221
237
|
};
|
|
222
|
-
this.#decoders.set(
|
|
238
|
+
this.#decoders.set(lane, entry);
|
|
223
239
|
}
|
|
224
240
|
const decoder = await entry.promise;
|
|
225
241
|
return decoder.refill({
|
|
@@ -71,6 +71,11 @@ export class Engine {
|
|
|
71
71
|
* load neither leaks nor repeats them.
|
|
72
72
|
*/
|
|
73
73
|
loadProject(project: any, operation?: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* The registered runtime effects the loaded project can draw, as `id@version`. The CPU renderer
|
|
76
|
+
* registers them but refuses to render or export a project that draws one.
|
|
77
|
+
*/
|
|
78
|
+
projectRuntimeEffects(): any;
|
|
74
79
|
/**
|
|
75
80
|
* Compiles runtime effect definitions on this renderer's device and registers them, all or none.
|
|
76
81
|
* An `id@version` already held is skipped, since a definition never changes under its version.
|
|
@@ -231,6 +231,15 @@ export class Engine {
|
|
|
231
231
|
this.#revision += 1;
|
|
232
232
|
this.#registry.resetPlayer();
|
|
233
233
|
}
|
|
234
|
+
/**
|
|
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
|
+
}
|
|
234
243
|
/**
|
|
235
244
|
* Compiles runtime effect definitions on this renderer's device and registers them, all or none.
|
|
236
245
|
* An `id@version` already held is skipped, since a definition never changes under its version.
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** A proxy's longer displayed edge, in pixels. */
|
|
2
2
|
export const PROXY_LONG_EDGE: 960;
|
|
3
|
+
/**
|
|
4
|
+
* How long a proxy conversion may go without progress before it fails as `proxy_stalled`. Some
|
|
5
|
+
* browser encoders stop emitting chunks without an error.
|
|
6
|
+
*/
|
|
7
|
+
export const PROXY_STALL_MS: 30000;
|
|
3
8
|
/**
|
|
4
9
|
* @typedef {{
|
|
5
10
|
* made_from: import("alpha2/project").MediaFingerprint,
|
|
@@ -15,8 +20,9 @@ export const PROXY_LONG_EDGE: 960;
|
|
|
15
20
|
* within {@link DEFAULT_MEMORY_OUTPUT_LIMIT} by default.
|
|
16
21
|
*/
|
|
17
22
|
export class ProxyStore {
|
|
18
|
-
constructor({ memoryLimit }?: {
|
|
23
|
+
constructor({ memoryLimit, stallMs, }?: {
|
|
19
24
|
memoryLimit?: number | undefined;
|
|
25
|
+
stallMs?: number | undefined;
|
|
20
26
|
});
|
|
21
27
|
/** Holds the proxy of `hash` in use until `release()` so no page removes it (see `holdProxy`). */
|
|
22
28
|
hold(hash: any): Promise<{
|
|
@@ -44,7 +50,8 @@ export class ProxyStore {
|
|
|
44
50
|
* hash (`whileMakingProxy`).
|
|
45
51
|
*
|
|
46
52
|
* Refuses before encoding when the conversion would drop a track the fingerprint records. Rejects
|
|
47
|
-
* with `signal.reason` if `signal` aborts before the proxy is kept
|
|
53
|
+
* with `signal.reason` if `signal` aborts before the proxy is kept, and with `proxy_stalled` when
|
|
54
|
+
* the conversion makes no progress for {@link PROXY_STALL_MS}; neither keeps a file.
|
|
48
55
|
*/
|
|
49
56
|
generate(file: any, fingerprint: any, { signal, onProgress }?: {}): Promise<{
|
|
50
57
|
record: any;
|
|
@@ -10,6 +10,11 @@ import { DEFAULT_MEMORY_OUTPUT_LIMIT } from "./output.js";
|
|
|
10
10
|
import { holdProxy, keptProxies, proxyDirectory, removeKeptProxies, removeUnfinishedProxies, unfinishedProxyName, whileMakingProxy, } from "./proxy-storage.js";
|
|
11
11
|
/** A proxy's longer displayed edge, in pixels. */
|
|
12
12
|
export const PROXY_LONG_EDGE = 960;
|
|
13
|
+
/**
|
|
14
|
+
* How long a proxy conversion may go without progress before it fails as `proxy_stalled`. Some
|
|
15
|
+
* browser encoders stop emitting chunks without an error.
|
|
16
|
+
*/
|
|
17
|
+
export const PROXY_STALL_MS = 30_000;
|
|
13
18
|
/**
|
|
14
19
|
* @typedef {{
|
|
15
20
|
* made_from: import("alpha2/project").MediaFingerprint,
|
|
@@ -28,8 +33,10 @@ export class ProxyStore {
|
|
|
28
33
|
/** @type {Map<string, { record: ProxyRecord, file: File }>} */
|
|
29
34
|
#memory = new Map();
|
|
30
35
|
#memoryLimit;
|
|
31
|
-
|
|
36
|
+
#stallMs;
|
|
37
|
+
constructor({ memoryLimit = DEFAULT_MEMORY_OUTPUT_LIMIT, stallMs = PROXY_STALL_MS, } = {}) {
|
|
32
38
|
this.#memoryLimit = memoryLimit;
|
|
39
|
+
this.#stallMs = stallMs;
|
|
33
40
|
}
|
|
34
41
|
/** Holds the proxy of `hash` in use until `release()` so no page removes it (see `holdProxy`). */
|
|
35
42
|
hold(hash) {
|
|
@@ -77,7 +84,8 @@ export class ProxyStore {
|
|
|
77
84
|
* hash (`whileMakingProxy`).
|
|
78
85
|
*
|
|
79
86
|
* Refuses before encoding when the conversion would drop a track the fingerprint records. Rejects
|
|
80
|
-
* with `signal.reason` if `signal` aborts before the proxy is kept
|
|
87
|
+
* with `signal.reason` if `signal` aborts before the proxy is kept, and with `proxy_stalled` when
|
|
88
|
+
* the conversion makes no progress for {@link PROXY_STALL_MS}; neither keeps a file.
|
|
81
89
|
*/
|
|
82
90
|
async generate(file, fingerprint, { signal, onProgress } = {}) {
|
|
83
91
|
signal?.throwIfAborted();
|
|
@@ -179,16 +187,41 @@ export class ProxyStore {
|
|
|
179
187
|
};
|
|
180
188
|
sink.onOverflow = cancel;
|
|
181
189
|
signal?.throwIfAborted();
|
|
182
|
-
|
|
183
|
-
|
|
190
|
+
// Raced against the conversion, since a stalled encoder may not settle even when cancelled.
|
|
191
|
+
let stalled = null;
|
|
192
|
+
let stallTimer = 0;
|
|
193
|
+
let failStalled = () => { };
|
|
194
|
+
const stall = new Promise((_, reject) => {
|
|
195
|
+
failStalled = reject;
|
|
196
|
+
});
|
|
197
|
+
const armStall = () => {
|
|
198
|
+
clearTimeout(stallTimer);
|
|
199
|
+
stallTimer = setTimeout(() => {
|
|
200
|
+
stalled = new EditorError("proxy_stalled", `The proxy of ${file.name} made no progress for ${Math.round(this.#stallMs / 1000)} s; the browser's video decoder or encoder stopped`, "proxy");
|
|
201
|
+
failStalled(stalled);
|
|
202
|
+
cancel();
|
|
203
|
+
}, this.#stallMs);
|
|
204
|
+
};
|
|
205
|
+
conversion.onProgress = (fraction) => {
|
|
206
|
+
armStall();
|
|
207
|
+
onProgress?.(fraction);
|
|
208
|
+
};
|
|
209
|
+
armStall();
|
|
210
|
+
const executed = conversion.execute();
|
|
211
|
+
executed.catch(() => { });
|
|
184
212
|
try {
|
|
185
|
-
await
|
|
213
|
+
await Promise.race([executed, stall]);
|
|
186
214
|
}
|
|
187
215
|
catch (error) {
|
|
188
216
|
signal?.throwIfAborted();
|
|
189
|
-
throw sink.failure ?? error;
|
|
217
|
+
throw stalled ?? sink.failure ?? error;
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
clearTimeout(stallTimer);
|
|
190
221
|
}
|
|
191
222
|
signal?.throwIfAborted();
|
|
223
|
+
if (stalled)
|
|
224
|
+
throw stalled;
|
|
192
225
|
if (sink.failure)
|
|
193
226
|
throw sink.failure;
|
|
194
227
|
// From here a failure discards the file; an abort after keeping leaves it kept.
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Generator, MediaFingerprint, Project } from "alpha2/project";
|
|
2
2
|
import type { LayoutBounds } from "alpha2/layout";
|
|
3
|
-
import type { AssetBinding, ConformReport, MediaPurpose } from "alpha2/assets";
|
|
3
|
+
import type { AssetBinding, AudioStreamFacts, ConformReport, MediaPurpose } from "alpha2/assets";
|
|
4
4
|
import type { BuiltinEffectCatalog, EffectDefinition } from "alpha2/effects";
|
|
5
5
|
import type { TrackDecodeFacts } from "alpha2/hdr-frames";
|
|
6
6
|
import type { EditorSession } from "../core/session.js";
|
|
@@ -82,6 +82,11 @@ export interface RuntimeAsset {
|
|
|
82
82
|
readonly audioDecodable?: boolean;
|
|
83
83
|
/** When `audioDecodable` is `false`, what the trial decode at import found. */
|
|
84
84
|
readonly audioDecodeFacts?: TrackDecodeFacts;
|
|
85
|
+
/**
|
|
86
|
+
* Every audio stream of the file, which a clip's `audio.stream` counts over. Conform refuses a
|
|
87
|
+
* clip choosing a stream or channel not listed here.
|
|
88
|
+
*/
|
|
89
|
+
readonly audioStreams?: readonly AudioStreamFacts[];
|
|
85
90
|
/**
|
|
86
91
|
* For a video, `unavailable` when this browser decodes it only to frames the engine cannot read
|
|
87
92
|
* (HDR, see `BrowserBridgeOptions.hdrWithoutPlanes`). It then previews degraded and cannot export
|
|
@@ -179,8 +184,9 @@ export interface BrowserBridgeOptions {
|
|
|
179
184
|
/**
|
|
180
185
|
* `"auto"` (the default) draws with a hardware GPU through WebGPU or WebGL2, else with the
|
|
181
186
|
* engine's CPU renderer (also when only a software adapter exists). `"gpu"` accepts any adapter,
|
|
182
|
-
* software included. `"cpu"` uses the CPU renderer, which
|
|
183
|
-
* recovery may still move the preview, or an export retry, to the
|
|
187
|
+
* software included. `"cpu"` uses the CPU renderer, which cannot draw runtime effects. GPU-loss
|
|
188
|
+
* recovery may still move the preview, or an export retry that draws no runtime effect, to the
|
|
189
|
+
* CPU. `capabilities.renderer`
|
|
184
190
|
* reports the preview's. Another value is refused when the bridge is made, with a `RangeError`.
|
|
185
191
|
*/
|
|
186
192
|
readonly renderer?: "auto" | "gpu" | "cpu";
|
|
@@ -343,7 +349,10 @@ export interface PreviewRenderer {
|
|
|
343
349
|
readonly backend: "webgpu" | "webgl2" | "cpu" | null;
|
|
344
350
|
/** The GPU adapter as the browser names it; `null` on the CPU or when it names none. */
|
|
345
351
|
readonly adapter: string | null;
|
|
346
|
-
/**
|
|
352
|
+
/**
|
|
353
|
+
* Whether runtime effects draw. On the CPU renderer each one a loaded project draws is reported
|
|
354
|
+
* once as `effect_unavailable`, and an export that draws one fails with `EFFECT_ERROR`.
|
|
355
|
+
*/
|
|
347
356
|
readonly runtimeEffects: boolean;
|
|
348
357
|
}
|
|
349
358
|
/**
|
|
@@ -586,8 +595,9 @@ export interface BrowserBridge {
|
|
|
586
595
|
* a time and never during an export: this waits for a running export or another proxy, and an
|
|
587
596
|
* export that starts restarts the conversion from 0 once it ends. Rejects for a source without a
|
|
588
597
|
* single video file (`unsupported_media`, including HDR video), without its original in this
|
|
589
|
-
* session (`missing_asset`), with a proxy already being made (`proxy_busy`),
|
|
590
|
-
*
|
|
598
|
+
* session (`missing_asset`), with a proxy already being made (`proxy_busy`), when the conversion
|
|
599
|
+
* makes no progress for 30 s (`proxy_stalled`; preview keeps reading the original), or when
|
|
600
|
+
* `signal` aborts.
|
|
591
601
|
*/
|
|
592
602
|
generateProxy(id: string, options?: {
|
|
593
603
|
signal?: AbortSignal;
|
package/dist/browser/worker.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Serves the editor's preview protocol (`createWorkerPreview`) on `scope`, a dedicated worker's
|
|
3
3
|
* global. Requests run one at a time in arrival order. A `cancel` or `replace-project` stops the
|
|
4
4
|
* render in flight and drops seeks that arrived before it. Requests from another session or an
|
|
5
|
-
* older revision are answered with an error.
|
|
5
|
+
* older revision are answered with an error. A second call on the same scope returns the first
|
|
6
|
+
* call's handle and leaves its handler in place.
|
|
6
7
|
* @param {import("./types.js").EditorWorkerScope} scope
|
|
7
8
|
* @returns {{ dispose(): Promise<void> }} Waits for queued requests, releases the engine and
|
|
8
9
|
* decoders, and detaches the message handler.
|
package/dist/browser/worker.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { Alpha2WasmError, serializeError } from "alpha2/worker-error";
|
|
2
2
|
import { SourcePixels } from "./runtime/sources.js";
|
|
3
3
|
import { AudioWindowSupplier, mixBlock } from "./runtime/audio.js";
|
|
4
|
+
const INSTALLED = Symbol.for("alpha2.editorWorker");
|
|
4
5
|
/**
|
|
5
6
|
* Serves the editor's preview protocol (`createWorkerPreview`) on `scope`, a dedicated worker's
|
|
6
7
|
* global. Requests run one at a time in arrival order. A `cancel` or `replace-project` stops the
|
|
7
8
|
* render in flight and drops seeks that arrived before it. Requests from another session or an
|
|
8
|
-
* older revision are answered with an error.
|
|
9
|
+
* older revision are answered with an error. A second call on the same scope returns the first
|
|
10
|
+
* call's handle and leaves its handler in place.
|
|
9
11
|
* @param {import("./types.js").EditorWorkerScope} scope
|
|
10
12
|
* @returns {{ dispose(): Promise<void> }} Waits for queued requests, releases the engine and
|
|
11
13
|
* decoders, and detaches the message handler.
|
|
12
14
|
*/
|
|
13
15
|
export function installEditorWorker(scope) {
|
|
16
|
+
// Bundles whose lazy engine chunk imports the worker's entry chunk evaluate the entry again in
|
|
17
|
+
// some browsers; a fresh handler there would answer every request after `init` as stale.
|
|
18
|
+
const installed = scope[INSTALLED];
|
|
19
|
+
if (installed)
|
|
20
|
+
return installed;
|
|
21
|
+
const handle = serveEditorWorker(scope);
|
|
22
|
+
scope[INSTALLED] = handle;
|
|
23
|
+
return handle;
|
|
24
|
+
}
|
|
25
|
+
function serveEditorWorker(scope) {
|
|
14
26
|
let engine = null, pixels = null, audio = null, sessionId = null, bitmapOutput = false, currentProject = null, revision = -1,
|
|
15
27
|
// The last posted renderer diagnostics; a seek reply carries only newer ones.
|
|
16
28
|
sentDiagnostics = null, tail = Promise.resolve();
|
|
@@ -197,6 +209,7 @@ export function installEditorWorker(scope) {
|
|
|
197
209
|
await pixels?.dispose();
|
|
198
210
|
assets.clear();
|
|
199
211
|
scope.onmessage = null;
|
|
212
|
+
delete scope[INSTALLED];
|
|
200
213
|
},
|
|
201
214
|
};
|
|
202
215
|
}
|
package/dist/core/document.js
CHANGED
|
@@ -44,6 +44,7 @@ const EDITOR_FAILURE_CODES = Object.freeze({
|
|
|
44
44
|
preview_worker_failed: "UNKNOWN",
|
|
45
45
|
provider_stalled: "RESOURCE_LIMIT",
|
|
46
46
|
proxy_busy: "UNKNOWN",
|
|
47
|
+
proxy_stalled: "UNKNOWN",
|
|
47
48
|
relink_conflict: "INVALID_INPUT",
|
|
48
49
|
resource_budget: "RESOURCE_LIMIT",
|
|
49
50
|
resource_limit: "RESOURCE_LIMIT",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.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": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.5.
|
|
63
|
+
"alpha2": "0.5.1",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.5.
|
|
67
|
+
"alpha2": "0.5.1",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|