alpha2 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +109 -173
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +98 -157
- package/dist/frame-supply.js +191 -162
- package/dist/generated/project-schema.d.ts +742 -464
- package/dist/generated/project-schema.js +63 -2
- package/dist/generated/project-shape.js +663 -118
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +88 -62
- package/dist/hdr-frames.js +123 -46
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +55 -55
- package/dist/layout.js +37 -36
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +173 -237
- package/dist/mediabunny.js +943 -518
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +83 -110
- package/dist/project.js +421 -447
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +106 -63
- package/dist/text.js +44 -69
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -92
- package/dist/worker.js +239 -144
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +487 -543
- package/wasm/alpha2_wasm.js +669 -572
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/video-frames.js
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* passes `layout` so the frame reads the planes where they are instead of script repacking them.
|
|
6
|
-
* Safari (measured on 26.6.2) ignores `layout` in the buffer constructor and reads the planes as if
|
|
7
|
-
* packed tightly from offset 0, so every width whose rows are padded (640 and 1920 among them)
|
|
8
|
-
* encodes a sheared, miscoloured picture. Chrome honours it. Which one this browser is gets
|
|
9
|
-
* measured once, on a tiny frame, rather than guessed from the user agent; where `layout` is
|
|
10
|
-
* ignored the planes are copied tight first.
|
|
2
|
+
* Export frames arrive as I420 with rows padded to the GPU copy alignment, read through `layout`.
|
|
3
|
+
* Safari ignores `layout` in the buffer constructor and reads the planes as tightly packed, which
|
|
4
|
+
* shears the picture, so support is probed once and the planes are repacked where it is missing.
|
|
11
5
|
*/
|
|
12
6
|
import { recordRepackedBytes, repackedBytesOf } from "./repacked-bytes.js";
|
|
13
7
|
let layoutHonoured;
|
|
14
8
|
let bufferTransferSupported;
|
|
15
|
-
/**
|
|
16
|
-
* Whether this browser's `VideoFrame` buffer constructor reads planes through `layout`.
|
|
17
|
-
*
|
|
18
|
-
* Builds a 2x2 I420 frame whose luma rows are padded, copies it back out, and compares. A browser
|
|
19
|
-
* that ignores `layout` returns the padding as picture.
|
|
20
|
-
*/
|
|
9
|
+
/** Whether this browser's `VideoFrame` buffer constructor reads planes through `layout`. */
|
|
21
10
|
export function videoFrameHonoursLayout() {
|
|
22
11
|
layoutHonoured ??= measureLayoutHonoured();
|
|
23
12
|
return layoutHonoured;
|
|
24
13
|
}
|
|
25
14
|
async function measureLayoutHonoured() {
|
|
26
|
-
//
|
|
27
|
-
// else.
|
|
15
|
+
// 2x2 I420 with luma stride 8 and 0xff padding; a browser ignoring `layout` returns padding.
|
|
28
16
|
const pixels = new Uint8Array(20).fill(0xff);
|
|
29
17
|
pixels.set([10, 20], 0);
|
|
30
18
|
pixels.set([30, 40], 8);
|
|
@@ -62,14 +50,13 @@ async function measureLayoutHonoured() {
|
|
|
62
50
|
}
|
|
63
51
|
}
|
|
64
52
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* `pixels` is owned by the caller and handed over: where the browser can take the buffer without
|
|
68
|
-
* copying it, it does. Where the browser ignores `layout`, and the layout is not already the tight
|
|
69
|
-
* one, the planes are copied tight into a new buffer first; {@link videoFrameRepackedBytes} reports
|
|
70
|
-
* that copy.
|
|
53
|
+
* Builds an I420 frame over `pixels`, transferring the buffer where possible. Repacks the planes
|
|
54
|
+
* where the browser ignores `layout`; {@link videoFrameRepackedBytes} reports that copy.
|
|
71
55
|
*/
|
|
72
56
|
export async function videoFrameFromI420(pixels, init) {
|
|
57
|
+
// Alpha and 10-bit frames arrive with tight planes.
|
|
58
|
+
if (init.format !== "I420")
|
|
59
|
+
return ownedVideoFrame(pixels, init);
|
|
73
60
|
const layout = init.layout ? [...init.layout] : undefined;
|
|
74
61
|
if (layout === undefined ||
|
|
75
62
|
isTightI420(layout, init.codedWidth, init.codedHeight) ||
|
|
@@ -77,16 +64,13 @@ export async function videoFrameFromI420(pixels, init) {
|
|
|
77
64
|
return ownedVideoFrame(pixels, init);
|
|
78
65
|
}
|
|
79
66
|
const tight = packI420(pixels, layout, init.codedWidth, init.codedHeight);
|
|
80
|
-
// Read before the
|
|
67
|
+
// Read before the transfer detaches the buffer.
|
|
81
68
|
const bytes = tight.byteLength;
|
|
82
69
|
const frame = ownedVideoFrame(tight, { ...init, layout: undefined });
|
|
83
70
|
recordRepackedBytes(frame, bytes);
|
|
84
71
|
return frame;
|
|
85
72
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Bytes script copied to build `frame` because the browser ignores `layout`; 0 for any other frame.
|
|
88
|
-
* A frame the SDK's render worker built and posted reports the worker's copy.
|
|
89
|
-
*/
|
|
73
|
+
/** Bytes copied to build `frame` because the browser ignores `layout`, or 0. */
|
|
90
74
|
export function videoFrameRepackedBytes(frame) {
|
|
91
75
|
return repackedBytesOf(frame);
|
|
92
76
|
}
|
|
@@ -134,7 +118,6 @@ function ownedVideoFrame(pixels, init) {
|
|
|
134
118
|
}
|
|
135
119
|
return new VideoFrame(pixels, init);
|
|
136
120
|
}
|
|
137
|
-
/** Whether the constructor's `transfer` option takes the buffer (detaches it), measured once. */
|
|
138
121
|
function supportsBufferTransfer() {
|
|
139
122
|
if (bufferTransferSupported !== undefined)
|
|
140
123
|
return bufferTransferSupported;
|
package/dist/waveform.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Waveform summaries for timeline display, computed by the engine
|
|
3
|
-
*
|
|
4
|
-
* A timeline draws a clip's audio as columns: the extremes and RMS of the
|
|
5
|
-
* samples under each. {@link summarizeWaveform} computes them at a finest
|
|
6
|
-
* bucket size and at coarser zoom levels, each four times the last, with the
|
|
7
|
-
* same code a native host uses (`alpha2-audio`), so the numbers are identical
|
|
8
|
-
* wherever they are computed.
|
|
2
|
+
* Waveform summaries (min, max, RMS per bucket) for timeline display, computed by the same engine
|
|
3
|
+
* code a native host uses, so results match across hosts.
|
|
9
4
|
*/
|
|
10
5
|
/** The wasm-bindgen classes `alpha2/wasm` exports for waveforms. */
|
|
11
6
|
export interface WaveformBinding {
|
|
@@ -28,13 +23,12 @@ export interface WaveformLevel {
|
|
|
28
23
|
/** One array per channel of `[min, max, rms]` triples, in time order. */
|
|
29
24
|
readonly channels: readonly Float32Array[];
|
|
30
25
|
}
|
|
31
|
-
/** A waveform summary
|
|
26
|
+
/** A waveform summary with its levels finest first. */
|
|
32
27
|
export interface Waveform {
|
|
33
28
|
/** Samples summarized per channel. */
|
|
34
29
|
readonly frames: number;
|
|
35
30
|
readonly levels: readonly WaveformLevel[];
|
|
36
31
|
}
|
|
37
|
-
/** How {@link summarizeWaveform} buckets audio. */
|
|
38
32
|
export interface WaveformOptions {
|
|
39
33
|
/** Samples per bucket at the finest level; the engine refuses zero. */
|
|
40
34
|
readonly bucketSamples: number;
|
|
@@ -44,8 +38,8 @@ export interface WaveformOptions {
|
|
|
44
38
|
readonly blockFrames?: number;
|
|
45
39
|
}
|
|
46
40
|
/**
|
|
47
|
-
* Summarizes planar audio
|
|
48
|
-
*
|
|
41
|
+
* Summarizes planar audio, one `Float32Array` per channel of equal length. The planes are not
|
|
42
|
+
* modified.
|
|
49
43
|
*
|
|
50
44
|
* @throws RangeError When there are no planes, their lengths differ, or
|
|
51
45
|
* `blockFrames` is not a positive integer.
|
package/dist/waveform.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Waveform summaries for timeline display, computed by the engine
|
|
3
|
-
*
|
|
4
|
-
* A timeline draws a clip's audio as columns: the extremes and RMS of the
|
|
5
|
-
* samples under each. {@link summarizeWaveform} computes them at a finest
|
|
6
|
-
* bucket size and at coarser zoom levels, each four times the last, with the
|
|
7
|
-
* same code a native host uses (`alpha2-audio`), so the numbers are identical
|
|
8
|
-
* wherever they are computed.
|
|
2
|
+
* Waveform summaries (min, max, RMS per bucket) for timeline display, computed by the same engine
|
|
3
|
+
* code a native host uses, so results match across hosts.
|
|
9
4
|
*/
|
|
10
5
|
/**
|
|
11
|
-
* Summarizes planar audio
|
|
12
|
-
*
|
|
6
|
+
* Summarizes planar audio, one `Float32Array` per channel of equal length. The planes are not
|
|
7
|
+
* modified.
|
|
13
8
|
*
|
|
14
9
|
* @throws RangeError When there are no planes, their lengths differ, or
|
|
15
10
|
* `blockFrames` is not a positive integer.
|
package/dist/worker-error.d.ts
CHANGED
|
@@ -1,41 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An error as it crosses a worker boundary (`postMessage`), and the error the other side rebuilds
|
|
3
|
-
* from it.
|
|
4
|
-
*
|
|
5
|
-
* Structured clone keeps an `Error`'s message and little else, and a `DOMException`'s name only in
|
|
6
|
-
* some engines, so the worker sends what the failure's classification reads: the code, whether the
|
|
7
|
-
* binding can still be used, the error's name (`QuotaExceededError`, `RangeError`, ...), and the
|
|
8
|
-
* `failure` it carries, whole (an `ExportFailureError`'s) or partial (an engine readback's).
|
|
9
|
-
*/
|
|
10
1
|
/** An error as plain data that survives `postMessage`. */
|
|
11
2
|
export interface SerializedAlpha2Error {
|
|
12
|
-
/** The error's own `code
|
|
3
|
+
/** The error's own `code`, else a wasm trap code or the worker's default. */
|
|
13
4
|
readonly code: string;
|
|
14
5
|
readonly message: string;
|
|
15
6
|
/** Whether the worker's binding is unusable and the worker must be replaced. */
|
|
16
7
|
readonly fatal: boolean;
|
|
17
|
-
/**
|
|
8
|
+
/** Present when the name is not `Error`. */
|
|
18
9
|
readonly name?: string;
|
|
19
|
-
/** The `failure` the error carried, as plain data. */
|
|
20
10
|
readonly failure?: Readonly<Record<string, unknown>>;
|
|
21
11
|
}
|
|
22
|
-
/**
|
|
23
|
-
* A worker's error rebuilt on the host side, with the code, fatality, name,
|
|
24
|
-
* and `failure` it had in the worker.
|
|
25
|
-
*/
|
|
12
|
+
/** A worker's error rebuilt on the host side, keeping its code, fatality, name and `failure`. */
|
|
26
13
|
export declare class Alpha2WasmError extends Error {
|
|
27
14
|
readonly code: string;
|
|
28
15
|
readonly fatal: boolean;
|
|
29
|
-
/** The failure the error carried in the worker, if any. */
|
|
30
16
|
readonly failure?: Readonly<Record<string, unknown>>;
|
|
31
17
|
constructor(failure: SerializedAlpha2Error);
|
|
32
18
|
}
|
|
33
19
|
/**
|
|
34
20
|
* Normalizes a thrown value for the other side of a worker boundary.
|
|
35
21
|
*
|
|
36
|
-
* `trapped`
|
|
37
|
-
*
|
|
38
|
-
* afterwards is retryable. `uncoded` is the code of an error that names none.
|
|
22
|
+
* Pass `trapped` once the worker has seen a wasm trap: borrows are still held, so every later error
|
|
23
|
+
* is fatal. `uncoded` is the code for an error without one.
|
|
39
24
|
*/
|
|
40
25
|
export declare function serializeError(error: unknown, trapped?: boolean, uncoded?: string): SerializedAlpha2Error;
|
|
41
26
|
/** Classifies the unrecoverable `WebAssembly` failures, or `undefined`. */
|
package/dist/worker-error.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Structured clone keeps an `Error`'s message and little else, and a `DOMException`'s name only in
|
|
6
|
-
* some engines, so the worker sends what the failure's classification reads: the code, whether the
|
|
7
|
-
* binding can still be used, the error's name (`QuotaExceededError`, `RangeError`, ...), and the
|
|
8
|
-
* `failure` it carries, whole (an `ExportFailureError`'s) or partial (an engine readback's).
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* A worker's error rebuilt on the host side, with the code, fatality, name,
|
|
12
|
-
* and `failure` it had in the worker.
|
|
13
|
-
*/
|
|
1
|
+
// Structured clone keeps little more than an `Error`'s message, so errors cross a worker boundary
|
|
2
|
+
// as plain data with the fields failure classification reads.
|
|
3
|
+
/** A worker's error rebuilt on the host side, keeping its code, fatality, name and `failure`. */
|
|
14
4
|
export class Alpha2WasmError extends Error {
|
|
15
5
|
code;
|
|
16
6
|
fatal;
|
|
17
|
-
/** The failure the error carried in the worker, if any. */
|
|
18
7
|
failure;
|
|
19
8
|
constructor(failure) {
|
|
20
9
|
super(failure.message);
|
|
21
|
-
//
|
|
10
|
+
// Keep the original name for classification by name (quota, range).
|
|
22
11
|
this.name = failure.name ?? "Alpha2WasmError";
|
|
23
12
|
this.code = failure.code;
|
|
24
13
|
this.fatal = failure.fatal;
|
|
@@ -29,17 +18,15 @@ export class Alpha2WasmError extends Error {
|
|
|
29
18
|
/**
|
|
30
19
|
* Normalizes a thrown value for the other side of a worker boundary.
|
|
31
20
|
*
|
|
32
|
-
* `trapped`
|
|
33
|
-
*
|
|
34
|
-
* afterwards is retryable. `uncoded` is the code of an error that names none.
|
|
21
|
+
* Pass `trapped` once the worker has seen a wasm trap: borrows are still held, so every later error
|
|
22
|
+
* is fatal. `uncoded` is the code for an error without one.
|
|
35
23
|
*/
|
|
36
24
|
export function serializeError(error, trapped = false, uncoded = "RENDER_WORKER_ERROR") {
|
|
37
25
|
const message = error instanceof Error ? error.message : String(error);
|
|
38
26
|
const name = nameOf(error);
|
|
39
27
|
const trap = wasmTrapCode(error);
|
|
40
28
|
if (trap !== undefined) {
|
|
41
|
-
//
|
|
42
|
-
// that can only trap again.
|
|
29
|
+
// Fatal, or the host would retry a call that can only trap again.
|
|
43
30
|
return {
|
|
44
31
|
code: trap,
|
|
45
32
|
message: `wasm ${message}; the module is no longer usable and the worker must be replaced`,
|
|
@@ -86,11 +73,7 @@ function nameOf(error) {
|
|
|
86
73
|
? name
|
|
87
74
|
: undefined;
|
|
88
75
|
}
|
|
89
|
-
|
|
90
|
-
* `failure` as data `postMessage` can carry. A failure is plain data by contract; one that is not
|
|
91
|
-
* (a function, a host object) is dropped rather than left to make the reply itself throw and never
|
|
92
|
-
* arrive.
|
|
93
|
-
*/
|
|
76
|
+
// A non-cloneable failure is dropped so it cannot make the reply itself throw.
|
|
94
77
|
function plainFailure(failure) {
|
|
95
78
|
if (typeof failure !== "object" || failure === null || Array.isArray(failure))
|
|
96
79
|
return undefined;
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { DecodedVideoFrame, PresentedFrame, RenderBackend } from "./player.js";
|
|
2
2
|
import type { EffectDefinition, EffectResourceData, WasmEffectRegistryBinding } from "./effects.js";
|
|
3
3
|
import type { ExportBackend, ExportTicket } from "./exporter.js";
|
|
4
|
+
import { type GpuLossReport, type RecoveryStep, type SurfaceProbe } from "./gpu-recovery.js";
|
|
5
|
+
import { type RendererChoice, type RendererMode } from "./renderer-choice.js";
|
|
6
|
+
import { type BrowserCapabilities } from "./robustness.js";
|
|
4
7
|
import type { EngineVideoCodec } from "./rate-control.js";
|
|
5
|
-
import { type FrameRetentionOptions } from "./frame-supply.js";
|
|
8
|
+
import { type FrameRetentionOptions, type SourceTransferStats } from "./frame-supply.js";
|
|
9
|
+
import { type ReadbackRecoveryStats } from "./frame-intake.js";
|
|
6
10
|
import { type ChromaSiting, type VideoConversion } from "./hdr-frames.js";
|
|
7
11
|
import { type SerializedAlpha2Error } from "./worker-error.js";
|
|
8
|
-
/**
|
|
9
|
-
* A message the main thread posts to the render worker. Every request carries an `id` the worker
|
|
10
|
-
* echoes in its answer; the worker handles requests one at a time, in arrival order.
|
|
11
|
-
*/
|
|
12
|
+
/** A request to the render worker. The worker handles requests serially and echoes each `id`. */
|
|
12
13
|
export type RenderWorkerRequest = {
|
|
13
14
|
readonly id: number;
|
|
14
15
|
readonly type: "initialize";
|
|
@@ -24,6 +25,7 @@ export type RenderWorkerRequest = {
|
|
|
24
25
|
readonly rotationDegrees?: 0 | 90 | 180 | 270;
|
|
25
26
|
readonly mirror?: boolean;
|
|
26
27
|
readonly chromaSiting?: ChromaSiting;
|
|
28
|
+
readonly decode?: "software";
|
|
27
29
|
} | {
|
|
28
30
|
readonly id: number;
|
|
29
31
|
readonly type: "present";
|
|
@@ -36,19 +38,30 @@ export type RenderWorkerRequest = {
|
|
|
36
38
|
readonly type: "begin-export-frame";
|
|
37
39
|
readonly timeTicks: bigint;
|
|
38
40
|
readonly codec: EngineVideoCodec;
|
|
39
|
-
/**
|
|
41
|
+
/** Stamped as the frame's `VideoFrame.timestamp`. */
|
|
40
42
|
readonly outputTimeTicks: bigint;
|
|
43
|
+
/** FFmpeg pixel format name; I420 when absent. */
|
|
44
|
+
readonly pixels?: string;
|
|
41
45
|
} | {
|
|
42
46
|
readonly id: number;
|
|
43
47
|
readonly type: "recover";
|
|
48
|
+
readonly step: RecoveryStep;
|
|
49
|
+
/** Transferred surface for a `"fresh"` step. */
|
|
50
|
+
readonly canvas?: OffscreenCanvas;
|
|
51
|
+
} | {
|
|
52
|
+
readonly id: number;
|
|
53
|
+
readonly type: "probe-surface";
|
|
54
|
+
} | {
|
|
55
|
+
readonly id: number;
|
|
56
|
+
readonly type: "detect-capabilities";
|
|
44
57
|
} | {
|
|
45
58
|
readonly id: number;
|
|
46
59
|
readonly type: "dispose";
|
|
47
60
|
};
|
|
48
61
|
/**
|
|
49
|
-
* A message the render worker
|
|
50
|
-
* `export-frame-
|
|
51
|
-
*
|
|
62
|
+
* A message from the render worker. `export-frame-ready` later delivers the readback of a
|
|
63
|
+
* `begin-export-frame` that answered `rendered`; `device-lost` precedes the answer of any request
|
|
64
|
+
* that found the device lost.
|
|
52
65
|
*/
|
|
53
66
|
export type RenderWorkerResponse = {
|
|
54
67
|
readonly id: number;
|
|
@@ -63,10 +76,7 @@ export type RenderWorkerResponse = {
|
|
|
63
76
|
readonly id: number;
|
|
64
77
|
readonly ok: true;
|
|
65
78
|
readonly frame: VideoFrame;
|
|
66
|
-
/**
|
|
67
|
-
* Bytes the worker copied to pack the frame's planes tight (`videoFrameRepackedBytes`), which
|
|
68
|
-
* the frame object that arrives cannot carry itself.
|
|
69
|
-
*/
|
|
79
|
+
/** The worker's `videoFrameRepackedBytes`, which the transferred frame cannot carry. */
|
|
70
80
|
readonly repackedBytes: number;
|
|
71
81
|
} | {
|
|
72
82
|
readonly type: "export-frame-ready";
|
|
@@ -75,35 +85,36 @@ export type RenderWorkerResponse = {
|
|
|
75
85
|
readonly error: SerializedAlpha2Error;
|
|
76
86
|
} | {
|
|
77
87
|
readonly type: "device-lost";
|
|
88
|
+
readonly report?: GpuLossReport;
|
|
78
89
|
};
|
|
79
90
|
export { Alpha2WasmError, type SerializedAlpha2Error } from "./worker-error.js";
|
|
80
91
|
/**
|
|
81
|
-
* The GPU/wasm implementation
|
|
82
|
-
*
|
|
83
|
-
* rejection is serialized back to the caller as an `Alpha2WasmError`.
|
|
92
|
+
* The GPU/wasm implementation inside the render worker, driven by {@link installRenderWorker}.
|
|
93
|
+
* Methods mirror `RenderBackend`; errors reach the caller as `Alpha2WasmError`.
|
|
84
94
|
*/
|
|
85
95
|
export interface RenderWorkerHost {
|
|
86
96
|
/** Takes ownership of `frame.frame`. */
|
|
87
97
|
uploadVideoFrame(frame: DecodedVideoFrame): Promise<void> | void;
|
|
88
98
|
present(timeTicks: bigint): Promise<PresentedFrame>;
|
|
89
99
|
reset(): Promise<void> | void;
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*/
|
|
94
|
-
beginExport(timeTicks: bigint, codec: EngineVideoCodec, outputTimeTicks: bigint): ExportTicket;
|
|
95
|
-
/**
|
|
96
|
-
* The renderer the host draws with; `initialize` answers it. Absent for a host that does not
|
|
97
|
-
* say.
|
|
98
|
-
*/
|
|
100
|
+
/** Renders `timeTicks` for export with chroma sited for `codec`, stamped at `outputTimeTicks`. */
|
|
101
|
+
beginExport(timeTicks: bigint, codec: EngineVideoCodec, outputTimeTicks: bigint, pixels?: string): ExportTicket;
|
|
102
|
+
/** Answered by `initialize` and each `recover`. */
|
|
99
103
|
readonly rendererChoice?: RendererChoice;
|
|
100
|
-
/**
|
|
104
|
+
/** Cumulative raw source video copied through script memory. */
|
|
105
|
+
readonly sourceTransfer?: SourceTransferStats;
|
|
106
|
+
/** Cumulative unreadable or non-planar frames and how they were recovered. */
|
|
107
|
+
readonly readbackRecovery?: ReadbackRecoveryStats;
|
|
108
|
+
/** Checked after every request; a throw is read as lost. */
|
|
101
109
|
isDeviceLost(): boolean;
|
|
102
|
-
/**
|
|
103
|
-
|
|
110
|
+
/** Read before `recover` frees the lost renderer. */
|
|
111
|
+
lossReport?(): GpuLossReport | undefined;
|
|
112
|
+
probeSurface?(): Promise<SurfaceProbe>;
|
|
113
|
+
/** Called while `isDeviceLost()` is true, or with a fresh surface in `canvas`. */
|
|
114
|
+
recover(step: RecoveryStep, canvas?: OffscreenCanvas): Promise<void>;
|
|
104
115
|
dispose(): void;
|
|
105
116
|
}
|
|
106
|
-
/**
|
|
117
|
+
/** Satisfied by a `DedicatedWorkerGlobalScope`. */
|
|
107
118
|
export interface RenderWorkerScope {
|
|
108
119
|
onmessage: ((event: MessageEvent<RenderWorkerRequest>) => void) | null;
|
|
109
120
|
postMessage(message: RenderWorkerResponse, transfer?: Transferable[]): void;
|
|
@@ -112,108 +123,84 @@ export interface RenderWorkerScope {
|
|
|
112
123
|
export interface TextFont {
|
|
113
124
|
readonly family: string;
|
|
114
125
|
readonly bytes: Uint8Array;
|
|
115
|
-
/**
|
|
126
|
+
/** One face of a collection; without it every face of the file is registered. */
|
|
116
127
|
readonly faceIndex?: number;
|
|
117
128
|
}
|
|
118
129
|
/** What {@link createWasmRenderWorkerHost} registers on every binding it makes. */
|
|
119
130
|
export interface WasmRenderWorkerHostOptions {
|
|
120
|
-
/**
|
|
131
|
+
/** Compiled and registered before the project loads. */
|
|
121
132
|
readonly effects?: readonly EffectDefinition[];
|
|
122
133
|
/** Effect resources (3D LUTs) the effects and project reference. */
|
|
123
134
|
readonly resources?: readonly EffectResourceData[];
|
|
124
|
-
/**
|
|
125
|
-
* Fonts caption tracks and text generators draw with, in fallback order. Give the export host
|
|
126
|
-
* the same files and preview text matches exported text.
|
|
127
|
-
*/
|
|
135
|
+
/** Fonts in fallback order. Give the export host the same files so preview text matches. */
|
|
128
136
|
readonly fonts?: readonly TextFont[];
|
|
129
|
-
/** How long uploaded frame generations stay resident
|
|
137
|
+
/** How long uploaded frame generations stay resident. */
|
|
130
138
|
readonly uploadRetention?: FrameRetentionOptions;
|
|
131
|
-
/**
|
|
132
|
-
* Who converts a decoded SDR `VideoFrame`: the engine, from its planes (`"engine"`, the
|
|
133
|
-
* default), or the browser (`"browser"`); see {@link VideoConversion}.
|
|
134
|
-
*/
|
|
139
|
+
/** Who converts decoded SDR frames (default `"engine"`); see {@link VideoConversion}. */
|
|
135
140
|
readonly videoConversion?: VideoConversion;
|
|
136
141
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* and opens no GPU context. The CPU renderer previews at half resolution by default and refuses
|
|
141
|
-
* runtime effects (`effects`) with `EFFECT_ERROR`; it needs the binding's `createCpu`, without
|
|
142
|
-
* which `"auto"` is `"gpu"`. The host reports the renderer it chose ({@link RendererChoice}).
|
|
142
|
+
* Renderer selection (default `"auto"`; see {@link RendererMode}). The CPU renderer previews at
|
|
143
|
+
* half resolution by default and refuses runtime `effects` with `EFFECT_ERROR`. Without the
|
|
144
|
+
* binding's `createCpu`, `"auto"` behaves as `"gpu"`.
|
|
143
145
|
*/
|
|
144
146
|
readonly renderer?: RendererMode;
|
|
145
|
-
}
|
|
146
|
-
/** The renderer a browser render host is asked for; see {@link WasmRenderWorkerHostOptions}. */
|
|
147
|
-
export type RendererMode = "auto" | "gpu" | "cpu";
|
|
148
|
-
/** The renderer a render host draws with, as the native host reports it. */
|
|
149
|
-
export interface RendererChoice {
|
|
150
|
-
/** The renderer that draws the frames. */
|
|
151
|
-
readonly renderer: "gpu" | "cpu";
|
|
152
147
|
/**
|
|
153
|
-
*
|
|
154
|
-
* `
|
|
148
|
+
* Handling of a frame whose planes the browser cannot read back. `"redecode"` (default) rejects
|
|
149
|
+
* the upload with `SOFTWARE_DECODE_REQUIRED` so `Alpha2Player` and `exportToSink` refill it in
|
|
150
|
+
* software. `"present"` hands it to the browser's conversion instead, unless the engine must
|
|
151
|
+
* convert it (HDR or project-declared color). A software-decoded frame still without planes
|
|
152
|
+
* rejects with `PlanarDecodeUnavailableError`.
|
|
155
153
|
*/
|
|
156
|
-
readonly
|
|
154
|
+
readonly unreadableFrames?: "redecode" | "present";
|
|
157
155
|
}
|
|
158
156
|
/**
|
|
159
157
|
* Installs a serial request loop in the worker that owns the GPU device, replacing
|
|
160
158
|
* `scope.onmessage`.
|
|
161
159
|
*
|
|
162
|
-
* `
|
|
163
|
-
*
|
|
164
|
-
* host reports a lost device. A wasm trap is latched: every later error is reported as fatal,
|
|
165
|
-
* because the module is no longer usable even when a later call fails with an ordinary-looking
|
|
166
|
-
* error.
|
|
160
|
+
* Requests other than `dispose` fail until `initialize` has called `createHost`. After a wasm trap
|
|
161
|
+
* every later error is reported as fatal.
|
|
167
162
|
*/
|
|
168
163
|
export declare function installRenderWorker(scope: RenderWorkerScope, createHost: (canvas: OffscreenCanvas) => Promise<RenderWorkerHost>): void;
|
|
169
164
|
/**
|
|
170
|
-
* Returns
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* The renderer is the one `options.renderer` picks (see {@link WasmRenderWorkerHostOptions}); the
|
|
175
|
-
* host's `rendererChoice` says which, and `initialize` answers it.
|
|
165
|
+
* Returns a `createHost` callback for {@link installRenderWorker} backed by the wasm binding. It
|
|
166
|
+
* creates the renderer `options.renderer` picks, registers effects, resources and fonts, then
|
|
167
|
+
* loads `projectJson`; `recover` repeats the same registration.
|
|
176
168
|
*
|
|
177
|
-
* The callback rejects when the binding lacks the constructor
|
|
178
|
-
*
|
|
179
|
-
* effect or loading the project fails. After a device loss, `recover()` repeats the same
|
|
180
|
-
* registration on a new renderer of the same kind.
|
|
169
|
+
* The callback rejects when the binding lacks the needed constructor, or when creating the
|
|
170
|
+
* renderer, compiling an effect or loading the project fails.
|
|
181
171
|
*/
|
|
182
172
|
export declare function createWasmRenderWorkerHost(binding: WasmEffectRegistryBinding, projectJson: string, options?: WasmRenderWorkerHostOptions): (canvas: OffscreenCanvas) => Promise<RenderWorkerHost>;
|
|
183
173
|
/**
|
|
184
|
-
* A `RenderBackend` that forwards every call to a worker running {@link installRenderWorker}
|
|
185
|
-
* exclusively owns the wasm and GPU state.
|
|
174
|
+
* A `RenderBackend` that forwards every call to a worker running {@link installRenderWorker}.
|
|
186
175
|
*
|
|
187
|
-
* Calls reject with `Alpha2WasmError` for
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* replaced.
|
|
176
|
+
* Calls reject with `Alpha2WasmError` for worker errors, and with a plain `Error` after
|
|
177
|
+
* {@link WorkerRenderBackend.dispose}. After an uncaught worker error, every pending and later call
|
|
178
|
+
* rejects with a fatal `RENDER_WORKER_FAILED` and the worker must be replaced.
|
|
191
179
|
*/
|
|
192
180
|
export declare class WorkerRenderBackend implements RenderBackend {
|
|
193
181
|
#private;
|
|
194
182
|
constructor(worker: Worker);
|
|
195
|
-
/**
|
|
196
|
-
* The renderer the worker's host draws with, once {@link WorkerRenderBackend.initialize} has
|
|
197
|
-
* resolved; `undefined` before, or for a host that does not say.
|
|
198
|
-
*/
|
|
183
|
+
/** Set by {@link WorkerRenderBackend.initialize} and each recovery; `undefined` before. */
|
|
199
184
|
get rendererChoice(): RendererChoice | undefined;
|
|
200
185
|
/** Transfers `canvas` to the worker and creates its host there. */
|
|
201
186
|
initialize(canvas: OffscreenCanvas): Promise<void>;
|
|
202
|
-
/**
|
|
203
|
-
* Transfers `frame.frame` to the worker; it is closed here if it cannot be posted, including
|
|
204
|
-
* after {@link WorkerRenderBackend.dispose} or a worker failure.
|
|
205
|
-
*/
|
|
187
|
+
/** Transfers `frame.frame` to the worker, closing it here if it cannot be posted. */
|
|
206
188
|
uploadVideoFrame(frame: DecodedVideoFrame): Promise<void>;
|
|
207
189
|
present(timeTicks: bigint): Promise<PresentedFrame>;
|
|
208
190
|
reset(): Promise<void>;
|
|
209
191
|
/**
|
|
210
|
-
* Renders
|
|
211
|
-
*
|
|
212
|
-
* ticket's `readback` settles when the worker posts the frame.
|
|
192
|
+
* Renders `timeTicks` for export with chroma sited for `codec`, stamped at `outputTimeTicks`. A
|
|
193
|
+
* `rendered` ticket's `readback` settles when the worker posts the frame.
|
|
213
194
|
*/
|
|
214
|
-
beginExport(timeTicks: bigint, codec: EngineVideoCodec, outputTimeTicks: bigint): Promise<ExportTicket>;
|
|
195
|
+
beginExport(timeTicks: bigint, codec: EngineVideoCodec, outputTimeTicks: bigint, pixels?: string): Promise<ExportTicket>;
|
|
215
196
|
isDeviceLost(): boolean;
|
|
216
|
-
|
|
197
|
+
/** Cleared by a recovery. */
|
|
198
|
+
lossReport(): GpuLossReport | undefined;
|
|
199
|
+
probeSurface(): Promise<SurfaceProbe>;
|
|
200
|
+
/** Resolves to the renderer the worker made. On rejection the backend stays lost. */
|
|
201
|
+
recover(step: RecoveryStep, canvas?: OffscreenCanvas): Promise<RendererChoice | undefined>;
|
|
202
|
+
/** Capabilities probed inside the worker, which can differ from the page's. */
|
|
203
|
+
detectCapabilities(): Promise<BrowserCapabilities>;
|
|
217
204
|
/** Terminates the worker and rejects every pending call. Idempotent. */
|
|
218
205
|
dispose(): void;
|
|
219
206
|
}
|
|
@@ -223,8 +210,11 @@ export declare class WorkerRenderBackend implements RenderBackend {
|
|
|
223
210
|
*/
|
|
224
211
|
export declare class WorkerExportBackend implements ExportBackend {
|
|
225
212
|
#private;
|
|
226
|
-
/**
|
|
227
|
-
|
|
213
|
+
/**
|
|
214
|
+
* `pixels` is `resolvePixels(...).format` from `alpha2/containers` (I420 when absent). Pictures
|
|
215
|
+
* with alpha are drawn without the project background.
|
|
216
|
+
*/
|
|
217
|
+
constructor(renderer: WorkerRenderBackend, codec: EngineVideoCodec, pixels?: string);
|
|
228
218
|
begin(timeTicks: bigint, outputTimeTicks: bigint): Promise<ExportTicket>;
|
|
229
219
|
isDeviceLost(): boolean;
|
|
230
220
|
abort(reason: Error): void;
|