@alpha2-sh/editor 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bridge.d.ts +15 -16
- package/dist/browser/bridge.js +393 -312
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +44 -44
- package/dist/browser/runtime/engine.js +87 -64
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +85 -103
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -22
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +65 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
|
@@ -9,14 +9,11 @@ import { MediabunnyAudioDecoder } from "alpha2/mediabunny";
|
|
|
9
9
|
import * as engineBinding from "alpha2/wasm";
|
|
10
10
|
const TICKS_PER_SECOND = 120000n;
|
|
11
11
|
const PREFETCH_TICKS = 2n * TICKS_PER_SECOND;
|
|
12
|
-
/** How much of a source is kept behind the earliest tick a mix
|
|
12
|
+
/** How much of a source is kept behind the earliest tick a mix reads (backward prefetch). */
|
|
13
13
|
const KEEP_BEHIND_TICKS = PREFETCH_TICKS;
|
|
14
14
|
/** How far that point moves forward before the source is trimmed again. */
|
|
15
15
|
const TRIM_STEP_TICKS = PREFETCH_TICKS;
|
|
16
|
-
/**
|
|
17
|
-
* Sorts one source's needed tick ranges and joins the ones less than a prefetch apart, which are
|
|
18
|
-
* cheaper to decode as one window than as two.
|
|
19
|
-
*/
|
|
16
|
+
/** Sorts a source's needed tick ranges, joining those closer than a prefetch into one window. */
|
|
20
17
|
function coalesceRanges(ranges) {
|
|
21
18
|
const sorted = [...ranges].sort((a, b) => a.start < b.start ? -1 : a.start > b.start ? 1 : 0);
|
|
22
19
|
const merged = [];
|
|
@@ -35,11 +32,13 @@ function coalesceRanges(ranges) {
|
|
|
35
32
|
function minBigInt(a, b) {
|
|
36
33
|
return a < b ? a : b;
|
|
37
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
|
+
}
|
|
38
39
|
/**
|
|
39
|
-
* Sources that contribute to the mix,
|
|
40
|
-
*
|
|
41
|
-
* A video file with a sound track counts: it declares `has_audio`, so its clip on a video track is
|
|
42
|
-
* mixed without a second clip on an audio lane.
|
|
40
|
+
* Sources that contribute to the mix, with their browser-side asset. A video file with a sound
|
|
41
|
+
* track declares `has_audio`, so its clip on a video track is mixed without a separate audio clip.
|
|
43
42
|
*/
|
|
44
43
|
export function audibleSources(project, library) {
|
|
45
44
|
const items = [];
|
|
@@ -62,10 +61,11 @@ export class AudioWindowSupplier {
|
|
|
62
61
|
#sampleRate = 48_000;
|
|
63
62
|
#generation = 0;
|
|
64
63
|
#controller = new AbortController();
|
|
64
|
+
/** Open decoders by `laneKey`. */
|
|
65
65
|
#decoders = new Map();
|
|
66
|
-
/** Per source, the earliest tick the previous request needed. */
|
|
66
|
+
/** Per source stream (`laneKey`), the earliest tick the previous request needed. */
|
|
67
67
|
#lastStarts = new Map();
|
|
68
|
-
/** Per source, the tick the engine's audio was last trimmed below
|
|
68
|
+
/** Per source, the tick the engine's audio was last trimmed below (or would have been). */
|
|
69
69
|
#trimmed = new Map();
|
|
70
70
|
/** The earliest tick each running `supply` needs, per source. */
|
|
71
71
|
#inFlight = new Set();
|
|
@@ -81,12 +81,12 @@ export class AudioWindowSupplier {
|
|
|
81
81
|
this.#lastStarts.clear();
|
|
82
82
|
this.#trimmed.clear();
|
|
83
83
|
const audible = new Set(audibleSources(project, this.#library).map(({ id }) => id));
|
|
84
|
-
for (const [
|
|
85
|
-
const asset = this.#library.get(sourceId);
|
|
86
|
-
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)
|
|
87
87
|
continue;
|
|
88
88
|
closeDecoder(entry.promise);
|
|
89
|
-
this.#decoders.delete(
|
|
89
|
+
this.#decoders.delete(lane);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
async supply(startSample, frames, { signal, forceSources = [] } = {}) {
|
|
@@ -100,33 +100,39 @@ export class AudioWindowSupplier {
|
|
|
100
100
|
try {
|
|
101
101
|
const needs = JSON.parse(engine.audioNeeds(BigInt(startSample), frames));
|
|
102
102
|
const forced = new Set(forceSources);
|
|
103
|
-
const
|
|
103
|
+
const byLane = new Map();
|
|
104
104
|
for (const need of needs) {
|
|
105
|
-
const
|
|
106
|
-
|
|
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({
|
|
107
112
|
start: BigInt(need.startTicks),
|
|
108
113
|
end: BigInt(need.endTicks),
|
|
109
114
|
});
|
|
110
|
-
|
|
115
|
+
byLane.set(lane, entry);
|
|
111
116
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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));
|
|
116
122
|
running = earliest;
|
|
117
123
|
this.#inFlight.add(running);
|
|
118
124
|
for (const [sourceId, start] of earliest)
|
|
119
125
|
this.#trim(sourceId, start);
|
|
120
|
-
// 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
|
|
121
127
|
// and each prefetch stops short of the next request.
|
|
122
|
-
await Promise.all([...
|
|
128
|
+
await Promise.all([...byLane].map(async ([lane, { sourceId, stream, ranges }]) => {
|
|
123
129
|
const requests = coalesceRanges(ranges);
|
|
124
|
-
//
|
|
125
|
-
const previous = this.#lastStarts.get(
|
|
130
|
+
// Reversed clips and ping-pong backward passes read backwards, so prefetch goes that way.
|
|
131
|
+
const previous = this.#lastStarts.get(lane);
|
|
126
132
|
const backward = previous !== undefined &&
|
|
127
133
|
requests[0].start < previous &&
|
|
128
134
|
previous - requests[0].start <= TICKS_PER_SECOND;
|
|
129
|
-
this.#lastStarts.set(
|
|
135
|
+
this.#lastStarts.set(lane, requests[0].start);
|
|
130
136
|
for (let index = 0; index < requests.length; index += 1) {
|
|
131
137
|
const { start, end } = requests[index];
|
|
132
138
|
const neighbour = requests[backward ? index - 1 : index + 1];
|
|
@@ -141,7 +147,7 @@ export class AudioWindowSupplier {
|
|
|
141
147
|
const window = backward
|
|
142
148
|
? { start: start > prefetch ? start - prefetch : 0n, end }
|
|
143
149
|
: { start, end: end + prefetch };
|
|
144
|
-
await this.#supplyRange(sourceId, start, end, window, {
|
|
150
|
+
await this.#supplyRange(sourceId, stream, start, end, window, {
|
|
145
151
|
forced: forced.has(sourceId),
|
|
146
152
|
generation,
|
|
147
153
|
signal: combined.signal,
|
|
@@ -156,8 +162,8 @@ export class AudioWindowSupplier {
|
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
/**
|
|
159
|
-
* Drops what the engine holds of `sourceId` well before `start`,
|
|
160
|
-
*
|
|
165
|
+
* Drops what the engine holds of `sourceId` well before `start`, short of the earliest tick any
|
|
166
|
+
* running mix needs. Runs once per `TRIM_STEP_TICKS` of progress; seeking back resets it.
|
|
161
167
|
*/
|
|
162
168
|
#trim(sourceId, start) {
|
|
163
169
|
let floor = start;
|
|
@@ -179,30 +185,33 @@ export class AudioWindowSupplier {
|
|
|
179
185
|
this.#engine.trimAudioBefore(sourceId, before);
|
|
180
186
|
this.#trimmed.set(sourceId, before);
|
|
181
187
|
}
|
|
182
|
-
async #supplyRange(sourceId, startTicks, endTicks, decodeWindow, { forced, generation, signal }) {
|
|
188
|
+
async #supplyRange(sourceId, stream, startTicks, endTicks, decodeWindow, { forced, generation, signal }) {
|
|
183
189
|
const engine = this.#engine;
|
|
184
190
|
const requiredStart = Math.max(0, ticksToSampleFloor(startTicks, this.#sampleRate) - 2);
|
|
185
191
|
const requiredEnd = ticksToSampleCeil(endTicks, this.#sampleRate) + 2;
|
|
186
|
-
//
|
|
192
|
+
// The engine extends, replaces and drops windows itself, so ask what it holds.
|
|
187
193
|
if (!forced &&
|
|
188
|
-
JSON.parse(engine.audioRetainedWindows(sourceId)).some((window) => window.startSample <= requiredStart &&
|
|
194
|
+
JSON.parse(engine.audioRetainedWindows(sourceId, stream)).some((window) => window.startSample <= requiredStart &&
|
|
189
195
|
window.endSample >= requiredEnd))
|
|
190
196
|
return;
|
|
191
197
|
const asset = this.#library.get(sourceId);
|
|
192
198
|
if (!asset)
|
|
193
199
|
throw new Error(`audio source ${sourceId} is unavailable`);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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) {
|
|
204
|
+
// Undecodable here (`RuntimeAsset.audioDecodable`): silent, though the document keeps it.
|
|
205
|
+
engine.uploadAudioBlock(sourceId, BigInt(requiredStart), this.#sampleRate, 1, new Float32Array(Math.max(1, requiredEnd - requiredStart)), false, stream);
|
|
197
206
|
return;
|
|
198
207
|
}
|
|
199
208
|
const block = asset.audioBuffer
|
|
200
209
|
? blockFromAudioBuffer(sourceId, asset.audioBuffer, decodeWindow.start, decodeWindow.end, this.#sampleRate, generation)
|
|
201
|
-
: await this.#decode(sourceId, asset, decodeWindow.start, decodeWindow.end, generation, signal);
|
|
210
|
+
: await this.#decode(sourceId, stream, asset, decodeWindow.start, decodeWindow.end, generation, signal);
|
|
202
211
|
throwIfAborted(signal);
|
|
203
212
|
if (generation !== this.#generation)
|
|
204
213
|
return;
|
|
205
|
-
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);
|
|
206
215
|
}
|
|
207
216
|
async close() {
|
|
208
217
|
this.#controller.abort();
|
|
@@ -212,19 +221,21 @@ export class AudioWindowSupplier {
|
|
|
212
221
|
this.#engine = null;
|
|
213
222
|
await Promise.allSettled(closing);
|
|
214
223
|
}
|
|
215
|
-
async #decode(sourceId, asset, startTicks, endTicks, generation, signal) {
|
|
224
|
+
async #decode(sourceId, stream, asset, startTicks, endTicks, generation, signal) {
|
|
216
225
|
if (!asset.file)
|
|
217
226
|
throw new Error(`audio source ${sourceId} has no decodable file`);
|
|
218
|
-
|
|
227
|
+
const lane = laneKey(sourceId, stream);
|
|
228
|
+
let entry = this.#decoders.get(lane);
|
|
219
229
|
if (!entry || entry.file !== asset.file) {
|
|
220
230
|
if (entry)
|
|
221
231
|
closeDecoder(entry.promise);
|
|
222
232
|
entry = {
|
|
233
|
+
sourceId,
|
|
223
234
|
file: asset.file,
|
|
224
|
-
// The engine's own resampler, as on native; alpha2/wasm is loaded by
|
|
225
|
-
promise: MediabunnyAudioDecoder.open(sourceId, asset.file, engineBinding),
|
|
235
|
+
// The engine's own resampler, as on native; alpha2/wasm is loaded by now.
|
|
236
|
+
promise: MediabunnyAudioDecoder.open(sourceId, asset.file, engineBinding, stream === undefined ? {} : { stream }),
|
|
226
237
|
};
|
|
227
|
-
this.#decoders.set(
|
|
238
|
+
this.#decoders.set(lane, entry);
|
|
228
239
|
}
|
|
229
240
|
const decoder = await entry.promise;
|
|
230
241
|
return decoder.refill({
|
|
@@ -261,15 +272,33 @@ const PUMP_INTERVAL_MS = 40;
|
|
|
261
272
|
* thread; the worklet applies no second master chain.
|
|
262
273
|
*/
|
|
263
274
|
export class EngineAudioMixer {
|
|
264
|
-
|
|
275
|
+
/**
|
|
276
|
+
* `onInterrupted` is called after the mixer stops because output stopped under playing audio
|
|
277
|
+
* (context suspended or interrupted by the system, as when another app takes the device).
|
|
278
|
+
*/
|
|
279
|
+
constructor(runtimeAssets = {}, { enabled = true, onInterrupted } = {}) {
|
|
265
280
|
this.runtimeAssets = runtimeAssets;
|
|
266
281
|
this.#enabled = enabled;
|
|
282
|
+
this.#onInterrupted = onInterrupted ?? null;
|
|
267
283
|
}
|
|
268
284
|
#enabled = true;
|
|
269
285
|
#clock = null;
|
|
286
|
+
#onInterrupted = null;
|
|
287
|
+
/** User A/V offset in milliseconds, for output delay the browser does not report. */
|
|
288
|
+
#offsetMs = 0;
|
|
270
289
|
get tick() {
|
|
271
290
|
return this.#clock ? Number(this.#clock.timelineTicks) : null;
|
|
272
291
|
}
|
|
292
|
+
/** Where the playing clock's output latency comes from (`AudioLatencySource`), else null. */
|
|
293
|
+
get latencySource() {
|
|
294
|
+
return this.#clock?.latencySource ?? null;
|
|
295
|
+
}
|
|
296
|
+
/** Sets the A/V offset in milliseconds (positive shows the picture later), playing or not. */
|
|
297
|
+
setLatencyOffset(ms) {
|
|
298
|
+
this.#offsetMs = ms;
|
|
299
|
+
if (this.#clock)
|
|
300
|
+
this.#clock.latencyOffsetSeconds = ms / 1000;
|
|
301
|
+
}
|
|
273
302
|
#context = null;
|
|
274
303
|
#node = null;
|
|
275
304
|
#setup = null;
|
|
@@ -291,10 +320,9 @@ export class EngineAudioMixer {
|
|
|
291
320
|
return this.#context;
|
|
292
321
|
}
|
|
293
322
|
/**
|
|
294
|
-
* Associates a loaded project with the preview mixer. Safe to call again.
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* AudioWorkletProcessor until a user gesture.
|
|
323
|
+
* Associates a loaded project with the preview mixer. Safe to call again. Worklet creation waits
|
|
324
|
+
* for `resume()`, since a suspended AudioContext may not construct an AudioWorkletProcessor
|
|
325
|
+
* before a user gesture.
|
|
298
326
|
*/
|
|
299
327
|
async attach(engine, project, supplier, onUnderrun, onError) {
|
|
300
328
|
this.stop();
|
|
@@ -303,8 +331,8 @@ export class EngineAudioMixer {
|
|
|
303
331
|
const sampleRate = project.settings.sample_rate;
|
|
304
332
|
if (this.#context && this.#sampleRate !== sampleRate)
|
|
305
333
|
await this.close();
|
|
306
|
-
// Continue across
|
|
307
|
-
//
|
|
334
|
+
// Continue across gaps of a block or less instead of replaying effect history; seeks reset and
|
|
335
|
+
// export is exact either way.
|
|
308
336
|
engine.setAudioContinuity("continue-small-gaps");
|
|
309
337
|
this.#engine = engine;
|
|
310
338
|
this.#supplier = supplier;
|
|
@@ -346,7 +374,7 @@ export class EngineAudioMixer {
|
|
|
346
374
|
return this.#setup;
|
|
347
375
|
const setup = this.#create(context);
|
|
348
376
|
this.#setup = setup;
|
|
349
|
-
// A rejected setup must be retryable on a later Play
|
|
377
|
+
// A rejected setup must be retryable on a later Play, even if its caller was interrupted.
|
|
350
378
|
void setup.catch(() => {
|
|
351
379
|
if (this.#setup === setup)
|
|
352
380
|
this.#setup = null;
|
|
@@ -360,7 +388,19 @@ export class EngineAudioMixer {
|
|
|
360
388
|
if (!this.supported || !this.#engine)
|
|
361
389
|
return;
|
|
362
390
|
// Construct and resume before the first await to keep Play's user activation.
|
|
363
|
-
|
|
391
|
+
let context = this.#context;
|
|
392
|
+
if (!context) {
|
|
393
|
+
context = new AudioContext({ sampleRate: this.#sampleRate });
|
|
394
|
+
context.addEventListener("statechange", () => {
|
|
395
|
+
// Only while playing; stopping clears the clock, so a stop reports once.
|
|
396
|
+
if (!this.#clock || this.#context !== context)
|
|
397
|
+
return;
|
|
398
|
+
if (context.state !== "suspended" && context.state !== "interrupted")
|
|
399
|
+
return;
|
|
400
|
+
this.stop();
|
|
401
|
+
this.#onInterrupted?.(context.state);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
364
404
|
this.#context = context;
|
|
365
405
|
const resumed = context.state === "suspended" ? context.resume() : Promise.resolve();
|
|
366
406
|
const setup = this.#node ? Promise.resolve() : this.#beginSetup(context);
|
|
@@ -374,7 +414,7 @@ export class EngineAudioMixer {
|
|
|
374
414
|
return;
|
|
375
415
|
if (!this.#node || !this.#ring || !this.#engine)
|
|
376
416
|
return;
|
|
377
|
-
// Playback rate is
|
|
417
|
+
// Playback rate is preview-only; the engine always mixes at 1x.
|
|
378
418
|
if (rate !== 1) {
|
|
379
419
|
this.stop();
|
|
380
420
|
return;
|
|
@@ -397,7 +437,7 @@ export class EngineAudioMixer {
|
|
|
397
437
|
await this.#pump.fill();
|
|
398
438
|
}
|
|
399
439
|
catch (error) {
|
|
400
|
-
// A stop or close
|
|
440
|
+
// A stop or close during the first block's decode ends this start quietly.
|
|
401
441
|
if (signal.aborted)
|
|
402
442
|
return;
|
|
403
443
|
throw error;
|
|
@@ -408,7 +448,10 @@ export class EngineAudioMixer {
|
|
|
408
448
|
}
|
|
409
449
|
if (signal.aborted)
|
|
410
450
|
return;
|
|
411
|
-
this.#clock = new AudioPlaybackClock(this.#pump, this.#ring, this.#context,
|
|
451
|
+
this.#clock = new AudioPlaybackClock(this.#pump, this.#ring, this.#context, {
|
|
452
|
+
processing: Alpha2AudioWorkletHost.latency(this.#node),
|
|
453
|
+
latencyOffsetSeconds: this.#offsetMs / 1000,
|
|
454
|
+
});
|
|
412
455
|
this.#timer = setInterval(() => {
|
|
413
456
|
void this.#pump?.fill().catch((error) => {
|
|
414
457
|
if (error?.name === "AbortError")
|
|
@@ -431,7 +474,7 @@ export class EngineAudioMixer {
|
|
|
431
474
|
}
|
|
432
475
|
async close() {
|
|
433
476
|
this.stop();
|
|
434
|
-
// Let
|
|
477
|
+
// Let in-flight setup settle so it cannot resurrect a closed node.
|
|
435
478
|
await this.#setup?.catch(() => { });
|
|
436
479
|
this.#setup = null;
|
|
437
480
|
if (this.#node)
|
|
@@ -506,8 +549,8 @@ function flattenPlanes(channels) {
|
|
|
506
549
|
return flat;
|
|
507
550
|
}
|
|
508
551
|
/**
|
|
509
|
-
* The sample
|
|
510
|
-
*
|
|
552
|
+
* The first sample at or after `tick`. The audio clock reports the tick at or before the sample
|
|
553
|
+
* heard, so rounding to nearest could be heard a frame early.
|
|
511
554
|
*/
|
|
512
555
|
export function playbackStartSample(tick, sampleRate) {
|
|
513
556
|
return ticksToSampleCeil(BigInt(Math.max(0, tick)), sampleRate);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The export options one attempt
|
|
3
|
-
*
|
|
4
|
-
* into a refusal.
|
|
2
|
+
* The export options for one attempt. A retry scales the byte budget by its profile, but never
|
|
3
|
+
* below one frame's working set, which would only turn the retry into a refusal.
|
|
5
4
|
*/
|
|
6
5
|
export function attemptOptions(options: any, attempt: any, settings: any): any;
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* `maxInFlightBytes
|
|
7
|
+
* Default bytes of rendered frames an export keeps in flight, matching the SDK's
|
|
8
|
+
* `maxInFlightBytes`.
|
|
10
9
|
*/
|
|
11
10
|
export const DEFAULT_IN_FLIGHT_BYTES: number;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// The browser export's byte budget, readable without loading the runtime.
|
|
2
2
|
import { minimumExportWorkingSet } from "./staging.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `maxInFlightBytes
|
|
4
|
+
* Default bytes of rendered frames an export keeps in flight, matching the SDK's
|
|
5
|
+
* `maxInFlightBytes`.
|
|
6
6
|
*/
|
|
7
7
|
export const DEFAULT_IN_FLIGHT_BYTES = 128 * 1024 * 1024;
|
|
8
8
|
/**
|
|
9
|
-
* The export options one attempt
|
|
10
|
-
*
|
|
11
|
-
* into a refusal.
|
|
9
|
+
* The export options for one attempt. A retry scales the byte budget by its profile, but never
|
|
10
|
+
* below one frame's working set, which would only turn the retry into a refusal.
|
|
12
11
|
*/
|
|
13
12
|
export function attemptOptions(options, attempt, settings) {
|
|
14
13
|
const scale = attempt?.profile?.memoryScale ?? 1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Replaces an engine registry's caption fonts with `fonts`, in order. A font the engine cannot
|
|
3
|
-
* parse
|
|
4
|
-
*
|
|
3
|
+
* parse is left out and the rest, built-in fallbacks included, still register. Returns what was
|
|
4
|
+
* left out as `{ font, error }`.
|
|
5
5
|
*/
|
|
6
6
|
export function registerCaptionFonts(registry: any, fonts: any): {
|
|
7
7
|
font: any;
|
|
@@ -15,13 +15,9 @@ export class CaptionFonts {
|
|
|
15
15
|
name: any;
|
|
16
16
|
builtIn: any;
|
|
17
17
|
}[];
|
|
18
|
-
/** The fonts in fallback order, for an engine to register. */
|
|
19
18
|
get stack(): any[];
|
|
20
19
|
loadDefault(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Adds a font file ahead of the others, so it draws every glyph it has and the fonts after it
|
|
23
|
-
* fill in the rest (a Korean font before DejaVu, say).
|
|
24
|
-
*/
|
|
20
|
+
/** Adds a font ahead of the others, so the fonts after it fill in glyphs it lacks. */
|
|
25
21
|
add(file: any): Promise<{
|
|
26
22
|
id: string;
|
|
27
23
|
name: any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Fonts caption tracks draw with, in fallback order. The engine rasterizes captions from these
|
|
2
|
-
// files, so preview and every export draw the same pixels
|
|
2
|
+
// files, so preview and every export draw the same pixels. Fonts are not part of the document.
|
|
3
3
|
export class CaptionFonts {
|
|
4
4
|
constructor(defaultFontUrl) {
|
|
5
5
|
this.defaultFontUrl = defaultFontUrl;
|
|
@@ -10,7 +10,6 @@ export class CaptionFonts {
|
|
|
10
10
|
get list() {
|
|
11
11
|
return this.#fonts.map(({ id, name, builtIn }) => ({ id, name, builtIn }));
|
|
12
12
|
}
|
|
13
|
-
/** The fonts in fallback order, for an engine to register. */
|
|
14
13
|
get stack() {
|
|
15
14
|
return this.#fonts;
|
|
16
15
|
}
|
|
@@ -28,10 +27,7 @@ export class CaptionFonts {
|
|
|
28
27
|
builtIn: true,
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Adds a font file ahead of the others, so it draws every glyph it has and the fonts after it
|
|
33
|
-
* fill in the rest (a Korean font before DejaVu, say).
|
|
34
|
-
*/
|
|
30
|
+
/** Adds a font ahead of the others, so the fonts after it fill in glyphs it lacks. */
|
|
35
31
|
async add(file) {
|
|
36
32
|
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
37
33
|
const font = {
|
|
@@ -50,8 +46,8 @@ export class CaptionFonts {
|
|
|
50
46
|
}
|
|
51
47
|
/**
|
|
52
48
|
* Replaces an engine registry's caption fonts with `fonts`, in order. A font the engine cannot
|
|
53
|
-
* parse
|
|
54
|
-
*
|
|
49
|
+
* parse is left out and the rest, built-in fallbacks included, still register. Returns what was
|
|
50
|
+
* left out as `{ font, error }`.
|
|
55
51
|
*/
|
|
56
52
|
export function registerCaptionFonts(registry, fonts) {
|
|
57
53
|
registry.clearFonts();
|
|
@@ -3,12 +3,16 @@
|
|
|
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?: {}, { unreadableFrames, videoConversion }?: {
|
|
6
|
+
constructor(canvas: any, sources: any, library: any, runtimeAssets?: {}, { unreadableFrames, videoConversion, opaqueEngineFrames, renderer, }?: {
|
|
7
|
+
renderer?: string | undefined;
|
|
8
|
+
});
|
|
9
|
+
/** `"auto"` (hardware GPU, else CPU), `"gpu"` or `"cpu"`, as `createRenderer` takes them. */
|
|
10
|
+
renderer: string;
|
|
11
|
+
rendererChoice: import("alpha2/renderer-choice").RendererChoice | null;
|
|
7
12
|
runtimeAssets: {};
|
|
8
|
-
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
9
13
|
unreadableFrames: any;
|
|
10
|
-
/** Who converts decoded SDR frames, the engine or the browser (`FrameSupply`). */
|
|
11
14
|
videoConversion: any;
|
|
15
|
+
opaqueEngineFrames: any;
|
|
12
16
|
canvas: any;
|
|
13
17
|
sources: any;
|
|
14
18
|
library: any;
|
|
@@ -26,61 +30,61 @@ export class Engine {
|
|
|
26
30
|
}>;
|
|
27
31
|
catalog: any;
|
|
28
32
|
/**
|
|
29
|
-
* Turns per-pass GPU and CPU timing on or off;
|
|
30
|
-
*
|
|
33
|
+
* Turns per-pass GPU and CPU timing on or off (off by default); passes appear in
|
|
34
|
+
* `lastDiagnostics`.
|
|
31
35
|
*/
|
|
32
36
|
setPassTiming(enabled: any): void;
|
|
33
37
|
/**
|
|
34
|
-
* Sets the preview resolution scale (the
|
|
35
|
-
*
|
|
36
|
-
*
|
|
38
|
+
* Sets the preview resolution scale (1 renders at the document's size) and returns the loaded
|
|
39
|
+
* project's render size as `[width, height]`, or null with no project. Throws for a scale the
|
|
40
|
+
* engine refuses.
|
|
37
41
|
*/
|
|
38
42
|
setPreviewScale(scale: any): any[] | null;
|
|
39
|
-
/** The loaded project's render size at the preview scale, `[width, height]`, or null. */
|
|
40
43
|
get previewSize(): any[] | null;
|
|
41
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* The renderer's part of the capability report: GPU, color, playback, and `renderer` (which
|
|
46
|
+
* renderer draws and whether it runs runtime effects).
|
|
47
|
+
*/
|
|
42
48
|
capabilityReport(): any;
|
|
49
|
+
/** The `GpuLossReport` after a GPU loss; undefined before a loss and on the CPU renderer. */
|
|
50
|
+
lossReport(): import("alpha2/gpu-recovery").GpuLossReport | undefined;
|
|
43
51
|
/** A clock for one run of playback; see the engine's `PlaybackPolicy`. */
|
|
44
52
|
playbackClock(policy: any, frameRate: any, rate: any, tick: any, now: any): PlaybackClock;
|
|
45
|
-
/** Whether sound plays under `policy` at `rate`. */
|
|
46
53
|
audible(policy: any, rate: any): boolean;
|
|
47
54
|
get ready(): boolean;
|
|
48
55
|
get deviceLost(): any;
|
|
49
56
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
57
|
+
* Cumulative: raw source video copied through script memory, and frames that could not be read
|
|
58
|
+
* back and how they were recovered.
|
|
52
59
|
*/
|
|
53
60
|
get sourceTransfer(): any;
|
|
54
|
-
/** The wasm object, for callers that drive audio directly. */
|
|
55
61
|
get wasm(): null;
|
|
56
|
-
/** Engine instance used by the realtime browser audio transport. */
|
|
57
62
|
get audioEngine(): null;
|
|
58
|
-
/** The project document most recently handed to the engine. */
|
|
59
63
|
get project(): null;
|
|
60
64
|
/**
|
|
61
|
-
* Loads `project`
|
|
62
|
-
* draws (`drawnEffectResources`)
|
|
63
|
-
*
|
|
64
|
-
* are dropped.
|
|
65
|
+
* Loads `project` and syncs its LUT resources with the library, registering only those the
|
|
66
|
+
* project draws (`drawnEffectResources`). Bumps the revision so in-flight renders for the old
|
|
67
|
+
* project are dropped.
|
|
65
68
|
*
|
|
66
|
-
* Throws `missing_asset`
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
+
* Throws `missing_asset` for a drawn resource the library lacks and `invalid_effect_resource` for
|
|
70
|
+
* one the engine cannot parse. Resources registered before the failure stay known, so the next
|
|
71
|
+
* load neither leaks nor repeats them.
|
|
69
72
|
*/
|
|
70
73
|
loadProject(project: any, operation?: string): void;
|
|
71
74
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
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;
|
|
79
|
+
/**
|
|
80
|
+
* Compiles runtime effect definitions on this renderer's device and registers them, all or none.
|
|
81
|
+
* An `id@version` already held is skipped, since a definition never changes under its version.
|
|
82
|
+
* Throws `invalid_effect` naming the first refused definition, with its diagnostics.
|
|
78
83
|
*/
|
|
79
84
|
registerEffects(definitions: any, operation?: string): Promise<void>;
|
|
80
85
|
/**
|
|
81
|
-
* Registers
|
|
82
|
-
*
|
|
83
|
-
* could not parse, as `{ font, error }`: they are left out, and the others draw.
|
|
86
|
+
* Registers caption fonts in fallback order; SVG text uses them too, as on the native host.
|
|
87
|
+
* Returns the fonts the engine could not parse as `{ font, error }`; those are left out.
|
|
84
88
|
*/
|
|
85
89
|
setCaptionFonts(fonts: any): {
|
|
86
90
|
font: any;
|
|
@@ -88,29 +92,25 @@ export class Engine {
|
|
|
88
92
|
}[];
|
|
89
93
|
resize(width: any, height: any): void;
|
|
90
94
|
/**
|
|
91
|
-
* Uploads the sources the engine needs at a timestamp without rendering
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* The uploads stay until `beginExportFrame` renders their frame; retired earlier, a frame whose
|
|
95
|
-
* uploads outgrow the retained budget would evict its own first ones and wait forever.
|
|
95
|
+
* Uploads the sources the engine needs at a timestamp without rendering, for export, where the
|
|
96
|
+
* engine owns the frame schedule. Uploads stay until `beginExportFrame` renders their frame;
|
|
97
|
+
* retiring them earlier could make a frame evict its own first uploads and wait forever.
|
|
96
98
|
*/
|
|
97
99
|
supply(seconds: any, { context }: {
|
|
98
100
|
context: any;
|
|
99
101
|
}): Promise<boolean>;
|
|
100
102
|
/**
|
|
101
|
-
* Renders the next export frame
|
|
102
|
-
*
|
|
103
|
-
* here.
|
|
103
|
+
* Renders the next export frame. Once a ticket is not `waiting`, the engine has consumed the
|
|
104
|
+
* frame's uploads, so they are retired here.
|
|
104
105
|
*/
|
|
105
106
|
beginExportFrame(): any;
|
|
106
107
|
/** Invalidates outstanding playback renders, for example on seek or pause. */
|
|
107
108
|
invalidate(): number;
|
|
108
109
|
get generation(): number;
|
|
109
110
|
/**
|
|
110
|
-
* Requests one frame. Concurrent requests collapse to the
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* nothing was drawn or presented and the surface still shows it.
|
|
111
|
+
* Requests one frame. Concurrent requests collapse to the newest so scrubbing never queues stale
|
|
112
|
+
* frames. Resolves `{ rendered, unchanged }`: `rendered` is false when superseded, and
|
|
113
|
+
* `unchanged` means the frame equals the one shown, so nothing was drawn or presented.
|
|
114
114
|
*/
|
|
115
115
|
render(seconds: any, { generation, context }?: {
|
|
116
116
|
generation?: null | undefined;
|