alpha2 0.5.3 → 0.6.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/README.md +68 -3
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +636 -37
- package/dist/generated/project-schema.js +55 -0
- package/dist/generated/project-shape.js +950 -381
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +43 -10
- package/dist/media.js +255 -66
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +24 -1
- package/dist/project.js +456 -38
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +26 -1
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +5 -61
- package/wasm/snippets/alpha2-wasm-6749ed8b34a74067/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline1.js → alpha2-wasm-6749ed8b34a74067/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline2.js → alpha2-wasm-6749ed8b34a74067/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline3.js → alpha2-wasm-6749ed8b34a74067/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline0.js → alpha2-wasm-6749ed8b34a74067/inline4.js} +0 -0
package/dist/player.js
CHANGED
|
@@ -8,6 +8,10 @@ import { decoderConsumerId, } from "./media.js";
|
|
|
8
8
|
* It keeps no clock: `present` shows the time it is given. For playback with audio, pass
|
|
9
9
|
* `AudioPlaybackClock.timelineTicks` so the picture follows the audio device.
|
|
10
10
|
*
|
|
11
|
+
* At most one presentation runs on the backend at a time, and at most one waits: a `present` or
|
|
12
|
+
* `seek` that arrives while another is waiting replaces it, so a caller may present on every
|
|
13
|
+
* animation frame without building a backlog.
|
|
14
|
+
*
|
|
11
15
|
* A presentation that lacks source frames asks `onRefill` for them, then presents the same time
|
|
12
16
|
* again. Frames uploaded after `onRefill` resolves show only on the next presentation.
|
|
13
17
|
*
|
|
@@ -21,8 +25,16 @@ import { decoderConsumerId, } from "./media.js";
|
|
|
21
25
|
export class Alpha2Player {
|
|
22
26
|
#backend;
|
|
23
27
|
#initialized = false;
|
|
28
|
+
#disposed = false;
|
|
24
29
|
#latestRequest = 0;
|
|
25
30
|
#generation = 0;
|
|
31
|
+
#waiting;
|
|
32
|
+
#running = false;
|
|
33
|
+
// A seek's backend reset still to run; a later request that supersedes the seek runs it.
|
|
34
|
+
#resetOwed = false;
|
|
35
|
+
#seeks = 0;
|
|
36
|
+
// A recovery finished and no presentation ran since, so the next refills are recovery refills.
|
|
37
|
+
#recovered = false;
|
|
26
38
|
// Skips re-presenting after a refill that uploaded nothing.
|
|
27
39
|
#uploads = 0;
|
|
28
40
|
// Shared by every presentation that finds the device lost.
|
|
@@ -86,7 +98,8 @@ export class Alpha2Player {
|
|
|
86
98
|
}
|
|
87
99
|
/**
|
|
88
100
|
* Presents `timeTicks`, recovering a lost device first and refilling missing frames through
|
|
89
|
-
* `onRefill`. Resolves `undefined` when a later `present` or `seek` superseded this one
|
|
101
|
+
* `onRefill`. Resolves `undefined` when a later `present` or `seek` superseded this one, whether
|
|
102
|
+
* it was still waiting (then the backend never saw it) or already running.
|
|
90
103
|
*
|
|
91
104
|
* Rejects with a fatal `GPU_DEVICE_LOST` when no renderer can be made (or a fresh surface was
|
|
92
105
|
* needed without `replaceSurface`); every later presentation rejects the same way.
|
|
@@ -97,18 +110,12 @@ export class Alpha2Player {
|
|
|
97
110
|
this.#assertInitialized();
|
|
98
111
|
if (this.#terminal !== undefined)
|
|
99
112
|
throw this.#terminal;
|
|
100
|
-
|
|
101
|
-
let reason = "prefetch";
|
|
102
|
-
if (this.#recovering !== undefined || this.#backend.isDeviceLost()) {
|
|
103
|
-
await this.#recover();
|
|
104
|
-
reason = "device-recovery";
|
|
105
|
-
}
|
|
106
|
-
const result = await this.#presentFilled(timeTicks, request, reason);
|
|
107
|
-
return request === this.#latestRequest ? result : undefined;
|
|
113
|
+
return this.#enqueue(timeTicks);
|
|
108
114
|
}
|
|
109
115
|
/**
|
|
110
116
|
* Seeks to `timeTicks`, dropping frames decoded for earlier requests, and presents the target
|
|
111
|
-
* once `onRefill` has delivered
|
|
117
|
+
* once `onRefill` has delivered, recovering a lost device first as `present` does. Resolves
|
|
118
|
+
* `undefined` when a later request superseded it.
|
|
112
119
|
*
|
|
113
120
|
* @throws Before {@link Alpha2Player.initialize} has resolved.
|
|
114
121
|
*/
|
|
@@ -117,16 +124,97 @@ export class Alpha2Player {
|
|
|
117
124
|
this.#generation += 1;
|
|
118
125
|
this.#softwareFrames.clear();
|
|
119
126
|
this.#reissued.clear();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return this.#
|
|
127
|
+
this.#resetOwed = true;
|
|
128
|
+
this.#seeks += 1;
|
|
129
|
+
return this.#enqueue(timeTicks);
|
|
123
130
|
}
|
|
124
|
-
/** Disposes the backend;
|
|
131
|
+
/** Disposes the backend; presentations waiting or in flight resolve `undefined`. */
|
|
125
132
|
dispose() {
|
|
133
|
+
this.#disposed = true;
|
|
126
134
|
this.#latestRequest += 1;
|
|
135
|
+
const waiting = this.#waiting;
|
|
136
|
+
this.#waiting = undefined;
|
|
137
|
+
waiting?.resolve(undefined);
|
|
127
138
|
this.#backend.dispose();
|
|
128
139
|
this.#initialized = false;
|
|
129
140
|
}
|
|
141
|
+
#enqueue(timeTicks) {
|
|
142
|
+
const request = ++this.#latestRequest;
|
|
143
|
+
const replaced = this.#waiting;
|
|
144
|
+
const done = new Promise((resolve, reject) => {
|
|
145
|
+
this.#waiting = {
|
|
146
|
+
timeTicks,
|
|
147
|
+
request,
|
|
148
|
+
seeks: this.#seeks,
|
|
149
|
+
resolve,
|
|
150
|
+
reject,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
replaced?.resolve(undefined);
|
|
154
|
+
if (!this.#running)
|
|
155
|
+
void this.#run();
|
|
156
|
+
return done;
|
|
157
|
+
}
|
|
158
|
+
async #run() {
|
|
159
|
+
this.#running = true;
|
|
160
|
+
try {
|
|
161
|
+
for (let next = this.#waiting; next !== undefined; next = this.#waiting) {
|
|
162
|
+
this.#waiting = undefined;
|
|
163
|
+
try {
|
|
164
|
+
next.resolve(await this.#presentOne(next));
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
// A disposed backend rejects its pending calls.
|
|
168
|
+
if (this.#disposed)
|
|
169
|
+
next.resolve(undefined);
|
|
170
|
+
else
|
|
171
|
+
next.reject(error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
this.#running = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async #presentOne(presentation) {
|
|
180
|
+
try {
|
|
181
|
+
return await this.#presentOnce(presentation);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
// A device lost during the presentation is refused by the renderer; recover and retry once.
|
|
185
|
+
if (error?.code !== "GPU_DEVICE_LOST" ||
|
|
186
|
+
error === this.#terminal ||
|
|
187
|
+
this.#disposed ||
|
|
188
|
+
!this.#backend.isDeviceLost())
|
|
189
|
+
throw error;
|
|
190
|
+
return this.#presentOnce(presentation);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async #presentOnce({ timeTicks, request, seeks, }) {
|
|
194
|
+
if (this.#disposed)
|
|
195
|
+
return undefined;
|
|
196
|
+
if (this.#terminal !== undefined)
|
|
197
|
+
throw this.#terminal;
|
|
198
|
+
if (this.#recovering !== undefined || this.#backend.isDeviceLost()) {
|
|
199
|
+
await this.#recover();
|
|
200
|
+
this.#recovered = true;
|
|
201
|
+
}
|
|
202
|
+
if (request !== this.#latestRequest || this.#disposed)
|
|
203
|
+
return undefined;
|
|
204
|
+
let reason = this.#recovered
|
|
205
|
+
? "device-recovery"
|
|
206
|
+
: "prefetch";
|
|
207
|
+
if (this.#resetOwed) {
|
|
208
|
+
this.#resetOwed = false;
|
|
209
|
+
await this.#backend.reset();
|
|
210
|
+
reason = "seek";
|
|
211
|
+
}
|
|
212
|
+
this.#recovered = false;
|
|
213
|
+
const result = await this.#presentFilled(timeTicks, request, seeks, reason);
|
|
214
|
+
return request === this.#latestRequest && !this.#disposed
|
|
215
|
+
? result
|
|
216
|
+
: undefined;
|
|
217
|
+
}
|
|
130
218
|
#recover() {
|
|
131
219
|
this.#recovering ??= (async () => {
|
|
132
220
|
try {
|
|
@@ -197,19 +285,27 @@ export class Alpha2Player {
|
|
|
197
285
|
}
|
|
198
286
|
}
|
|
199
287
|
// Re-presents after each refill while frames are missing. Each round must lack fewer frames
|
|
200
|
-
// than the last, so a source that never arrives ends the loop.
|
|
201
|
-
|
|
288
|
+
// than the last, so a source that never arrives ends the loop. A presentation superseded by a
|
|
289
|
+
// later `present` still shows the frames it refilled once, so a caller that presents faster than
|
|
290
|
+
// frames arrive sees the picture advance; a seek or recovery ends it at once.
|
|
291
|
+
async #presentFilled(timeTicks, request, seeks, reason) {
|
|
292
|
+
const generation = this.#generation;
|
|
293
|
+
const current = () => generation === this.#generation &&
|
|
294
|
+
seeks === this.#seeks &&
|
|
295
|
+
!this.#disposed;
|
|
202
296
|
let result = await this.#backend.present(timeTicks);
|
|
203
297
|
let lacking = Number.POSITIVE_INFINITY;
|
|
204
298
|
while (result.missingFrames.length > 0 &&
|
|
205
299
|
result.missingFrames.length < lacking &&
|
|
206
|
-
|
|
300
|
+
current()) {
|
|
207
301
|
lacking = result.missingFrames.length;
|
|
208
302
|
const uploads = this.#uploads;
|
|
209
303
|
await this.#requestMissing(result, reason);
|
|
210
|
-
if (uploads === this.#uploads ||
|
|
304
|
+
if (uploads === this.#uploads || !current())
|
|
211
305
|
break;
|
|
212
306
|
result = await this.#backend.present(timeTicks);
|
|
307
|
+
if (request !== this.#latestRequest)
|
|
308
|
+
break;
|
|
213
309
|
}
|
|
214
310
|
return result;
|
|
215
311
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Extractor, ExtractorDescriptor } from "./extract.js";
|
|
2
|
+
/** The ABI this loader implements. */
|
|
3
|
+
export declare const PLUGIN_ABI = "alpha2-plugin/1";
|
|
4
|
+
/** Linear memory a plugin may grow to when the caller sets no cap. */
|
|
5
|
+
export declare const DEFAULT_PLUGIN_MEMORY_BYTES: number;
|
|
6
|
+
/** A plugin that was refused, did not load or failed, with the code every surface uses. */
|
|
7
|
+
export declare class PluginError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
constructor(code: string, message: string, options?: ErrorOptions);
|
|
10
|
+
}
|
|
11
|
+
/** Where {@link loadPlugin} reads a plugin from. */
|
|
12
|
+
export interface LoadPluginOptions {
|
|
13
|
+
/** The most linear memory the module may have, in bytes; at most 2 GiB. */
|
|
14
|
+
readonly memoryBytes?: number;
|
|
15
|
+
/** Fetches the manifest's files; `globalThis.fetch` when left out. */
|
|
16
|
+
readonly fetch?: typeof fetch;
|
|
17
|
+
readonly signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
/** A loaded plugin: its manifest's identity and an extractor per run. */
|
|
20
|
+
export interface LoadedPlugin {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly version: string;
|
|
23
|
+
/** SHA-256 of the artifact that runs, as `made_by.plugin` records it. */
|
|
24
|
+
readonly artifactSha256: string;
|
|
25
|
+
readonly descriptor: ExtractorDescriptor;
|
|
26
|
+
/** An extractor that runs the module with `params`; each run instantiates it anew. */
|
|
27
|
+
extractor(params?: Readonly<Record<string, unknown>>): Extractor;
|
|
28
|
+
}
|
|
29
|
+
/** One record of an `emit` batch, as `docs/plugin-abi.md` lays it out. */
|
|
30
|
+
type PluginRecord = {
|
|
31
|
+
readonly kind: "sample";
|
|
32
|
+
readonly output: number;
|
|
33
|
+
readonly time: number;
|
|
34
|
+
readonly values: (number | null)[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: "word";
|
|
37
|
+
readonly output: number;
|
|
38
|
+
readonly start: number;
|
|
39
|
+
readonly end: number;
|
|
40
|
+
readonly text: string;
|
|
41
|
+
readonly speaker?: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "interval";
|
|
44
|
+
readonly output: number;
|
|
45
|
+
readonly start: number;
|
|
46
|
+
readonly end: number;
|
|
47
|
+
readonly label?: string;
|
|
48
|
+
readonly score?: number;
|
|
49
|
+
};
|
|
50
|
+
/** Reads a whole batch; throws a reason for the first record that does not read. */
|
|
51
|
+
export declare function decodeRecords(batch: Uint8Array): PluginRecord[];
|
|
52
|
+
/**
|
|
53
|
+
* Loads the plugin whose manifest is at `manifest` (a URL, absolute or relative to the page) and
|
|
54
|
+
* whose bytes have SHA-256 `sha256`, with its wasm artifact and resources, each checked against
|
|
55
|
+
* the hash and length the manifest pins.
|
|
56
|
+
*
|
|
57
|
+
* Rejects with a {@link PluginError} whose code is `PLUGIN_FETCH_FAILED`, `PLUGIN_HASH_MISMATCH`,
|
|
58
|
+
* `PLUGIN_ABI_UNSUPPORTED`, `PLUGIN_NO_ARTIFACT` (no wasm artifact), `PLUGIN_UNSUPPORTED_FEATURE`,
|
|
59
|
+
* `PLUGIN_LOAD_FAILED` or `PLUGIN_DESCRIPTOR_MISMATCH`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function loadPlugin(manifest: string | URL, sha256: string, options?: LoadPluginOptions): Promise<LoadedPlugin>;
|
|
62
|
+
export {};
|