alpha2 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/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 +51 -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 +125 -176
- 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 +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/frames.d.ts +23 -0
- package/dist/frames.js +34 -0
- package/dist/generated/project-schema.d.ts +712 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +276 -16
- 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 +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -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 +48 -63
- package/dist/layout.js +37 -37
- 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 +178 -246
- package/dist/mediabunny.js +781 -583
- package/dist/paint.d.ts +23 -0
- package/dist/paint.js +37 -0
- 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 +74 -118
- package/dist/project.js +384 -445
- 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 +97 -71
- package/dist/text.js +33 -70
- 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 -95
- package/dist/worker.js +235 -143
- 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 +501 -587
- package/wasm/alpha2_wasm.js +661 -616
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
package/dist/rate-control.d.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Output rate control for browser exports
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `alpha2/wasm` are the same functions the native host calls, so a browser export and a native
|
|
6
|
-
* export at one level and one output receive the same numbers. An app resolves once, at the top of
|
|
7
|
-
* an export, and hands the numbers to whichever sink it built; a sink never sees a level, and
|
|
8
|
-
* neither does anything in this package; the level names come from the engine too, through
|
|
9
|
-
* `qualityLevels`.
|
|
2
|
+
* Output rate control for browser exports. Quality levels resolve through the same engine functions
|
|
3
|
+
* the native host calls, so both get the same numbers. Resolve once per export and pass the numbers
|
|
4
|
+
* to the sink.
|
|
10
5
|
*/
|
|
11
|
-
/** The rate-control exports of the `alpha2/wasm` binding. */
|
|
12
6
|
export interface RateControlBinding {
|
|
13
7
|
resolveRateControl(codec: string, width: number, height: number, frameRateNum: number, frameRateDen: number, level: string): string;
|
|
14
8
|
resolveAudioBitrate(codec: string, level: string): number;
|
|
15
9
|
qualityLevels(): string;
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** The WebCodecs/mediabunny spellings of the same codecs. */
|
|
11
|
+
export type EngineVideoCodec = "h264" | "hevc" | "vp9" | "av1" | "mpeg4-part2" | "prores";
|
|
12
|
+
/** WebCodecs/mediabunny codec names. */
|
|
20
13
|
export type BrowserVideoCodec = "avc" | "hevc" | "vp9" | "av1";
|
|
21
|
-
/** A resolved video rate control, in the shape a browser sink receives. */
|
|
22
14
|
export interface VideoRateControl {
|
|
23
15
|
/** Target, or with a quantizer the fallback, bits per second. */
|
|
24
16
|
readonly bitrate: number;
|
|
@@ -37,18 +29,13 @@ export type VideoQualityRequest = string | {
|
|
|
37
29
|
export type AudioQualityRequest = string | {
|
|
38
30
|
readonly bitrate: number;
|
|
39
31
|
};
|
|
40
|
-
/**
|
|
41
|
-
* Maps a browser codec name onto the engine's.
|
|
42
|
-
*
|
|
43
|
-
* This is the one place `avc` becomes `h264`: the engine's mapping is keyed on one codec
|
|
44
|
-
* vocabulary, and the browser's is translated at this edge.
|
|
45
|
-
*/
|
|
32
|
+
/** Maps a browser codec name onto the engine's (`avc` becomes `h264`). */
|
|
46
33
|
export declare function engineVideoCodec(codec: BrowserVideoCodec): EngineVideoCodec;
|
|
47
34
|
/** The engine's quality level names, lowest first. */
|
|
48
35
|
export declare function qualityLevels(binding: RateControlBinding): readonly string[];
|
|
49
36
|
/**
|
|
50
|
-
* Resolves a
|
|
51
|
-
*
|
|
37
|
+
* Resolves a level name through the engine for this codec, size and rate. An explicit rate is
|
|
38
|
+
* returned as given, `variable` by default.
|
|
52
39
|
*
|
|
53
40
|
* @throws RangeError When an explicit `bitrate` is not a positive integer.
|
|
54
41
|
* @throws When the engine does not know the level or codec.
|
|
@@ -64,8 +51,7 @@ export declare function resolveVideoRateControl(binding: RateControlBinding, req
|
|
|
64
51
|
readonly quality: VideoQualityRequest;
|
|
65
52
|
}): VideoRateControl;
|
|
66
53
|
/**
|
|
67
|
-
* Resolves an audio quality request to bits per second
|
|
68
|
-
* the engine, an explicit bitrate as given.
|
|
54
|
+
* Resolves an audio quality request to bits per second.
|
|
69
55
|
*
|
|
70
56
|
* @throws RangeError When an explicit `bitrate` is not a positive integer.
|
|
71
57
|
* @throws When the engine does not know the level.
|
package/dist/rate-control.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Output rate control for browser exports
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `alpha2/wasm` are the same functions the native host calls, so a browser export and a native
|
|
6
|
-
* export at one level and one output receive the same numbers. An app resolves once, at the top of
|
|
7
|
-
* an export, and hands the numbers to whichever sink it built; a sink never sees a level, and
|
|
8
|
-
* neither does anything in this package; the level names come from the engine too, through
|
|
9
|
-
* `qualityLevels`.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Maps a browser codec name onto the engine's.
|
|
13
|
-
*
|
|
14
|
-
* This is the one place `avc` becomes `h264`: the engine's mapping is keyed on one codec
|
|
15
|
-
* vocabulary, and the browser's is translated at this edge.
|
|
2
|
+
* Output rate control for browser exports. Quality levels resolve through the same engine functions
|
|
3
|
+
* the native host calls, so both get the same numbers. Resolve once per export and pass the numbers
|
|
4
|
+
* to the sink.
|
|
16
5
|
*/
|
|
6
|
+
/** Maps a browser codec name onto the engine's (`avc` becomes `h264`). */
|
|
17
7
|
export function engineVideoCodec(codec) {
|
|
18
8
|
return codec === "avc" ? "h264" : codec;
|
|
19
9
|
}
|
|
@@ -22,8 +12,8 @@ export function qualityLevels(binding) {
|
|
|
22
12
|
return JSON.parse(binding.qualityLevels());
|
|
23
13
|
}
|
|
24
14
|
/**
|
|
25
|
-
* Resolves a
|
|
26
|
-
*
|
|
15
|
+
* Resolves a level name through the engine for this codec, size and rate. An explicit rate is
|
|
16
|
+
* returned as given, `variable` by default.
|
|
27
17
|
*
|
|
28
18
|
* @throws RangeError When an explicit `bitrate` is not a positive integer.
|
|
29
19
|
* @throws When the engine does not know the level or codec.
|
|
@@ -48,8 +38,7 @@ export function resolveVideoRateControl(binding, request) {
|
|
|
48
38
|
};
|
|
49
39
|
}
|
|
50
40
|
/**
|
|
51
|
-
* Resolves an audio quality request to bits per second
|
|
52
|
-
* the engine, an explicit bitrate as given.
|
|
41
|
+
* Resolves an audio quality request to bits per second.
|
|
53
42
|
*
|
|
54
43
|
* @throws RangeError When an explicit `bitrate` is not a positive integer.
|
|
55
44
|
* @throws When the engine does not know the level.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { WasmCanvasRenderer, WasmEffectRegistryBinding } from "./effects.js";
|
|
2
|
+
/**
|
|
3
|
+
* Renderer selection for a browser render host.
|
|
4
|
+
*
|
|
5
|
+
* - `"auto"` uses a hardware GPU (WebGPU, else WebGL2) and falls back to the wasm CPU renderer when
|
|
6
|
+
* only a software adapter or none is available.
|
|
7
|
+
* - `"gpu"` uses any GPU adapter, software included, and never falls back.
|
|
8
|
+
* - `"cpu"` uses the CPU renderer and opens no GPU context.
|
|
9
|
+
*/
|
|
10
|
+
export type RendererMode = "auto" | "gpu" | "cpu";
|
|
11
|
+
/** The renderer a render host draws with, in the same shape the native host reports. */
|
|
12
|
+
export interface RendererChoice {
|
|
13
|
+
readonly renderer: "gpu" | "cpu";
|
|
14
|
+
/** Why it draws on the CPU (no hardware GPU, asked for, or GPU loss); `null` on a GPU. */
|
|
15
|
+
readonly rendererReason: string | null;
|
|
16
|
+
readonly backend: "webgpu" | "webgl2" | "cpu";
|
|
17
|
+
/** The browser's adapter name; `null` on the CPU or when the browser names none. */
|
|
18
|
+
readonly adapter: string | null;
|
|
19
|
+
}
|
|
20
|
+
export type RendererSurface = OffscreenCanvas | HTMLCanvasElement;
|
|
21
|
+
/**
|
|
22
|
+
* Creates the renderer `mode` asks for on `surface` and reports which one it is.
|
|
23
|
+
*
|
|
24
|
+
* `"auto"` falls back to the CPU renderer on the same surface when the GPU renderer fails with
|
|
25
|
+
* `GPU_INIT_FAILED` or `INVALID_INPUT`. A failed GPU attempt leaves the surface free for the CPU
|
|
26
|
+
* renderer's 2D context.
|
|
27
|
+
*
|
|
28
|
+
* Rejects when the binding lacks the constructor `mode` needs, or with the GPU's error when `"gpu"`
|
|
29
|
+
* fails, `"auto"` fails for another reason, or the CPU fallback also fails.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createRenderer(binding: WasmEffectRegistryBinding, surface: RendererSurface, mode: RendererMode): Promise<{
|
|
32
|
+
wasm: WasmCanvasRenderer;
|
|
33
|
+
choice: RendererChoice;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a GPU renderer on `surface`. Rejects as the constructor does, or when the binding has no
|
|
37
|
+
* constructor for the surface's kind.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createGpuRenderer(binding: WasmEffectRegistryBinding, surface: RendererSurface, softwareAdapter: "allow" | "refuse"): Promise<WasmCanvasRenderer>;
|
|
40
|
+
/** The choice a GPU renderer reports; a binding that names no backend is WebGPU. */
|
|
41
|
+
export declare function gpuChoice(wasm: WasmCanvasRenderer): RendererChoice;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the renderer `mode` asks for on `surface` and reports which one it is.
|
|
3
|
+
*
|
|
4
|
+
* `"auto"` falls back to the CPU renderer on the same surface when the GPU renderer fails with
|
|
5
|
+
* `GPU_INIT_FAILED` or `INVALID_INPUT`. A failed GPU attempt leaves the surface free for the CPU
|
|
6
|
+
* renderer's 2D context.
|
|
7
|
+
*
|
|
8
|
+
* Rejects when the binding lacks the constructor `mode` needs, or with the GPU's error when `"gpu"`
|
|
9
|
+
* fails, `"auto"` fails for another reason, or the CPU fallback also fails.
|
|
10
|
+
*/
|
|
11
|
+
export async function createRenderer(binding, surface, mode) {
|
|
12
|
+
if (mode !== "auto" && mode !== "gpu" && mode !== "cpu")
|
|
13
|
+
throw new RangeError('renderer must be "auto", "gpu" or "cpu"');
|
|
14
|
+
const cpu = (rendererReason) => {
|
|
15
|
+
if (binding.createCpu === undefined)
|
|
16
|
+
throw new Error("wasm binding does not expose createCpu");
|
|
17
|
+
return {
|
|
18
|
+
wasm: binding.createCpu(surface),
|
|
19
|
+
choice: {
|
|
20
|
+
renderer: "cpu",
|
|
21
|
+
rendererReason,
|
|
22
|
+
backend: "cpu",
|
|
23
|
+
adapter: null,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
if (mode === "cpu")
|
|
28
|
+
return cpu('the CPU renderer was asked for (renderer "cpu")');
|
|
29
|
+
try {
|
|
30
|
+
const wasm = await createGpuRenderer(binding, surface, mode === "auto" ? "refuse" : "allow");
|
|
31
|
+
return { wasm, choice: gpuChoice(wasm) };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const code = error?.code;
|
|
35
|
+
const missing = error instanceof MissingConstructorError;
|
|
36
|
+
if (mode !== "auto" ||
|
|
37
|
+
binding.createCpu === undefined ||
|
|
38
|
+
(!missing && code !== "GPU_INIT_FAILED" && code !== "INVALID_INPUT"))
|
|
39
|
+
throw error;
|
|
40
|
+
if (missing)
|
|
41
|
+
return cpu("the wasm binding has no GPU renderer");
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
try {
|
|
44
|
+
return cpu(message.startsWith("the browser offers only the software adapter")
|
|
45
|
+
? `${message}, which renderer "auto" does not draw on`
|
|
46
|
+
: `the browser offers no WebGPU adapter and no WebGL2 context (${message})`);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Report the GPU's failure, which explains why there is no renderer at all.
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class MissingConstructorError extends Error {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a GPU renderer on `surface`. Rejects as the constructor does, or when the binding has no
|
|
58
|
+
* constructor for the surface's kind.
|
|
59
|
+
*/
|
|
60
|
+
export async function createGpuRenderer(binding, surface, softwareAdapter) {
|
|
61
|
+
const html = typeof HTMLCanvasElement !== "undefined" &&
|
|
62
|
+
surface instanceof HTMLCanvasElement;
|
|
63
|
+
if (html) {
|
|
64
|
+
if (binding.createForHtmlCanvas === undefined)
|
|
65
|
+
throw new MissingConstructorError("wasm binding does not expose createForHtmlCanvas");
|
|
66
|
+
return binding.createForHtmlCanvas(surface, { softwareAdapter });
|
|
67
|
+
}
|
|
68
|
+
if (binding.createForCanvas === undefined)
|
|
69
|
+
throw new MissingConstructorError("wasm binding does not expose createForCanvas");
|
|
70
|
+
return binding.createForCanvas(surface, {
|
|
71
|
+
softwareAdapter,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** The choice a GPU renderer reports; a binding that names no backend is WebGPU. */
|
|
75
|
+
export function gpuChoice(wasm) {
|
|
76
|
+
return {
|
|
77
|
+
renderer: "gpu",
|
|
78
|
+
rendererReason: null,
|
|
79
|
+
backend: wasm.backend ?? "webgpu",
|
|
80
|
+
adapter: wasm.adapter ? wasm.adapter : null,
|
|
81
|
+
};
|
|
82
|
+
}
|
package/dist/repacked-bytes.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
/** Records that building `frame` copied `bytes`; 0 records nothing. */
|
|
2
1
|
export declare function recordRepackedBytes(frame: VideoFrame, bytes: number): void;
|
|
3
|
-
/** Bytes recorded for `frame`; 0 for a frame nothing was recorded for. */
|
|
4
2
|
export declare function repackedBytesOf(frame: VideoFrame): number;
|
package/dist/repacked-bytes.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Bytes
|
|
3
|
-
*
|
|
4
|
-
* across and records it on the frame that arrives.
|
|
2
|
+
* Bytes copied to pack a `VideoFrame`'s planes tight. A frame posted to another agent arrives as a
|
|
3
|
+
* new object, so whoever transfers one must re-record its count on the arriving frame.
|
|
5
4
|
*/
|
|
6
5
|
const repackedBytes = new WeakMap();
|
|
7
|
-
/** Records that building `frame` copied `bytes`; 0 records nothing. */
|
|
8
6
|
export function recordRepackedBytes(frame, bytes) {
|
|
9
7
|
if (bytes > 0)
|
|
10
8
|
repackedBytes.set(frame, bytes);
|
|
11
9
|
}
|
|
12
|
-
/** Bytes recorded for `frame`; 0 for a frame nothing was recorded for. */
|
|
13
10
|
export function repackedBytesOf(frame) {
|
|
14
11
|
return repackedBytes.get(frame) ?? 0;
|
|
15
12
|
}
|
package/dist/robustness.d.ts
CHANGED
|
@@ -2,78 +2,66 @@
|
|
|
2
2
|
export type BrowserCapabilityDiagnostic = "webgpu-unavailable" | "webgl2-unavailable" | "webcodecs-unavailable" | "offscreen-canvas-unavailable" | "wasm-simd-unavailable" | "wasm-reference-types-unavailable" | "visibility-suspended" | "memory-pressure" | "decoder-session-limit" | "context-lost";
|
|
3
3
|
/** Caller-configured browser resource limits; both must be positive integers. */
|
|
4
4
|
export interface BrowserResourceBudget {
|
|
5
|
-
/** GPU texture memory the host allows, in bytes. */
|
|
6
5
|
readonly textureBytes: number;
|
|
7
|
-
/** Video decoders
|
|
6
|
+
/** Video decoders allowed open at once. */
|
|
8
7
|
readonly decoderSessions: number;
|
|
9
8
|
}
|
|
10
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Facts hosts use to select WebGPU, WebGL2 and media fallbacks. They hold only for the probing
|
|
11
|
+
* thread: a worker can get different answers than the page, so worker hosts should use
|
|
12
|
+
* `WorkerRenderBackend.detectCapabilities()`.
|
|
13
|
+
*/
|
|
11
14
|
export interface BrowserCapabilities {
|
|
12
|
-
/**
|
|
15
|
+
/** A non-fallback (hardware) WebGPU adapter is available. */
|
|
13
16
|
readonly webgpu: boolean;
|
|
14
|
-
/**
|
|
17
|
+
/** Whether the WebGPU adapter is the software fallback; `null` when there is none. */
|
|
18
|
+
readonly webgpuFallbackAdapter: boolean | null;
|
|
15
19
|
readonly webgl2: boolean;
|
|
20
|
+
/** The WebGL2 renderer name, unmasked where allowed; `null` without a context. */
|
|
21
|
+
readonly webgl2Renderer: string | null;
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
23
|
+
* What `renderer: "auto"` would draw with here. Software rasterizers (SwiftShader, llvmpipe,
|
|
24
|
+
* WARP, a WebGPU fallback adapter) count as `"cpu"`.
|
|
19
25
|
*/
|
|
20
26
|
readonly renderer: "gpu" | "cpu";
|
|
21
27
|
readonly webcodecs: boolean;
|
|
22
28
|
readonly offscreenCanvas: boolean;
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
25
|
-
* worklet,
|
|
26
|
-
* `diagnostics` names each missing feature.
|
|
30
|
+
* WebAssembly SIMD and reference types are supported. Without them neither the engine, the audio
|
|
31
|
+
* worklet, nor extension modules load; `diagnostics` names the missing feature.
|
|
27
32
|
*/
|
|
28
33
|
readonly wasm: boolean;
|
|
29
34
|
readonly diagnostics: readonly BrowserCapabilityDiagnostic[];
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
|
-
* Probes the
|
|
37
|
+
* Probes the calling thread's environment (see {@link BrowserCapabilities}).
|
|
33
38
|
*
|
|
34
|
-
* `webgpu`
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* browser with no usable GPU, such as Chrome with acceleration off), it runs on the CPU, which
|
|
38
|
-
* `renderer` says and `diagnostics` explains. `webgl2` is probed on a canvas of its own, since a
|
|
39
|
-
* canvas's first context fixes its kind for good: a caller's canvas probed for WebGL2 could no
|
|
40
|
-
* longer render WebGPU or be transferred to a worker. `wasm` validates
|
|
41
|
-
* two tiny modules, one per WebAssembly feature the packaged modules need past what every WebCodecs
|
|
42
|
-
* browser has (SIMD and reference types; Chrome 94 and 95 have WebCodecs and SIMD but no reference
|
|
43
|
-
* types), so a browser that cannot load the engine is told so before it fetches and compiles it.
|
|
39
|
+
* `webgpu` requests an adapter, since `navigator.gpu` can exist without one. `webgl2` is probed on
|
|
40
|
+
* a throwaway canvas because a canvas's first context fixes its kind. `wasm` validates tiny probe
|
|
41
|
+
* modules, so it is cheap to check before fetching the engine.
|
|
44
42
|
*/
|
|
45
43
|
export declare function detectBrowserCapabilities(): Promise<BrowserCapabilities>;
|
|
46
44
|
/**
|
|
47
|
-
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and
|
|
48
|
-
*
|
|
49
|
-
* the host acts on what it reports.
|
|
45
|
+
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and reports each
|
|
46
|
+
* degradation through `notify`. The host acts on what it reports.
|
|
50
47
|
*
|
|
51
|
-
* @throws RangeError From the constructor when either budget is not a positive
|
|
52
|
-
* safe integer.
|
|
48
|
+
* @throws RangeError From the constructor when either budget is not a positive safe integer.
|
|
53
49
|
*/
|
|
54
50
|
export declare class BrowserRobustnessCoordinator {
|
|
55
51
|
#private;
|
|
56
52
|
constructor(budget: BrowserResourceBudget, notify: (diagnostic: BrowserCapabilityDiagnostic) => void);
|
|
57
53
|
/**
|
|
58
|
-
* Sizes `canvas`'s backing store to its CSS size times `scale` (
|
|
59
|
-
* pixel ratio), rounded, at least 1x1.
|
|
54
|
+
* Sizes `canvas`'s backing store to its CSS size times `scale` (device pixel ratio), min 1x1.
|
|
60
55
|
*
|
|
61
56
|
* @throws RangeError When the scaled size is not a safe integer.
|
|
62
57
|
*/
|
|
63
58
|
resize(canvas: HTMLCanvasElement | OffscreenCanvas, cssWidth: number, cssHeight: number, scale?: number): void;
|
|
64
59
|
/** Records page visibility; hiding a visible page reports `visibility-suspended`. */
|
|
65
60
|
setVisible(visible: boolean): void;
|
|
66
|
-
/**
|
|
67
|
-
* Reports `memory-pressure` and returns the texture budget to fall back to:
|
|
68
|
-
* half the configured one, at least one byte.
|
|
69
|
-
*/
|
|
61
|
+
/** Reports `memory-pressure` and returns the reduced texture budget (half, at least 1 byte). */
|
|
70
62
|
memoryPressure(): number;
|
|
71
|
-
/** Reports `context-lost`. */
|
|
72
63
|
contextLost(): void;
|
|
73
|
-
/**
|
|
74
|
-
* Takes one decoder session. Returns `false`, and reports
|
|
75
|
-
* `decoder-session-limit`, when all of the budget's sessions are taken.
|
|
76
|
-
*/
|
|
64
|
+
/** Takes one decoder session, or reports `decoder-session-limit` and returns `false`. */
|
|
77
65
|
acquireDecoder(): boolean;
|
|
78
66
|
/** Returns a session taken by {@link acquireDecoder}; extra calls are ignored. */
|
|
79
67
|
releaseDecoder(): void;
|
package/dist/robustness.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Probes the
|
|
2
|
+
* Probes the calling thread's environment (see {@link BrowserCapabilities}).
|
|
3
3
|
*
|
|
4
|
-
* `webgpu`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* browser with no usable GPU, such as Chrome with acceleration off), it runs on the CPU, which
|
|
8
|
-
* `renderer` says and `diagnostics` explains. `webgl2` is probed on a canvas of its own, since a
|
|
9
|
-
* canvas's first context fixes its kind for good: a caller's canvas probed for WebGL2 could no
|
|
10
|
-
* longer render WebGPU or be transferred to a worker. `wasm` validates
|
|
11
|
-
* two tiny modules, one per WebAssembly feature the packaged modules need past what every WebCodecs
|
|
12
|
-
* browser has (SIMD and reference types; Chrome 94 and 95 have WebCodecs and SIMD but no reference
|
|
13
|
-
* types), so a browser that cannot load the engine is told so before it fetches and compiles it.
|
|
4
|
+
* `webgpu` requests an adapter, since `navigator.gpu` can exist without one. `webgl2` is probed on
|
|
5
|
+
* a throwaway canvas because a canvas's first context fixes its kind. `wasm` validates tiny probe
|
|
6
|
+
* modules, so it is cheap to check before fetching the engine.
|
|
14
7
|
*/
|
|
15
8
|
export async function detectBrowserCapabilities() {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
9
|
+
const adapter = await detectWebgpu();
|
|
10
|
+
const webgpu = adapter !== null && !adapter.fallback;
|
|
11
|
+
const webgl2Renderer = detectWebgl2();
|
|
12
|
+
const webgl2 = webgl2Renderer !== null;
|
|
18
13
|
const webcodecs = globalThis.VideoDecoder !== undefined &&
|
|
19
14
|
globalThis.VideoEncoder !== undefined;
|
|
20
15
|
const offscreenCanvas = globalThis.OffscreenCanvas !== undefined;
|
|
@@ -33,27 +28,29 @@ export async function detectBrowserCapabilities() {
|
|
|
33
28
|
diagnostics.push("wasm-simd-unavailable");
|
|
34
29
|
if (!referenceTypes)
|
|
35
30
|
diagnostics.push("wasm-reference-types-unavailable");
|
|
31
|
+
const hardwareWebgl2 = webgl2Renderer !== null && !softwareRenderer(webgl2Renderer);
|
|
36
32
|
return {
|
|
37
33
|
webgpu,
|
|
34
|
+
webgpuFallbackAdapter: adapter === null ? null : adapter.fallback,
|
|
38
35
|
webgl2,
|
|
39
|
-
|
|
36
|
+
webgl2Renderer,
|
|
37
|
+
renderer: webgpu || hardwareWebgl2 ? "gpu" : "cpu",
|
|
40
38
|
webcodecs,
|
|
41
39
|
offscreenCanvas,
|
|
42
40
|
wasm: simd && referenceTypes,
|
|
43
41
|
diagnostics,
|
|
44
42
|
};
|
|
45
43
|
}
|
|
46
|
-
|
|
44
|
+
// `(func (result v128) i32.const 0 i8x16.splat i8x16.popcnt)`, valid only with final SIMD.
|
|
47
45
|
const WASM_SIMD_PROBE = [
|
|
48
46
|
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8,
|
|
49
47
|
0, 65, 0, 253, 15, 253, 98, 11,
|
|
50
48
|
];
|
|
51
|
-
|
|
49
|
+
// `(func ref.null func drop)`, valid only with reference types.
|
|
52
50
|
const WASM_REFERENCE_TYPES_PROBE = [
|
|
53
51
|
0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0,
|
|
54
52
|
208, 112, 26, 11,
|
|
55
53
|
];
|
|
56
|
-
/** Whether `WebAssembly.validate` accepts `bytes`; no `WebAssembly` at all accepts nothing. */
|
|
57
54
|
function validatesWasm(bytes) {
|
|
58
55
|
try {
|
|
59
56
|
return globalThis.WebAssembly?.validate(new Uint8Array(bytes)) === true;
|
|
@@ -62,46 +59,74 @@ function validatesWasm(bytes) {
|
|
|
62
59
|
return false;
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
|
|
62
|
+
// Case-insensitive; must match the engine's native and wasm adapter selection list.
|
|
63
|
+
const SOFTWARE_RENDERERS = [
|
|
64
|
+
"mesa offscreen",
|
|
65
|
+
"swiftshader",
|
|
66
|
+
"llvmpipe",
|
|
67
|
+
"microsoft basic render",
|
|
68
|
+
];
|
|
69
|
+
function softwareRenderer(name) {
|
|
70
|
+
const lower = name.toLowerCase();
|
|
71
|
+
return SOFTWARE_RENDERERS.some((software) => lower.includes(software));
|
|
72
|
+
}
|
|
73
|
+
// Older browsers flag `isFallbackAdapter` on the adapter rather than its `info`.
|
|
66
74
|
async function detectWebgpu() {
|
|
67
75
|
const gpu = globalThis.navigator?.gpu;
|
|
68
76
|
if (gpu === undefined)
|
|
69
|
-
return
|
|
77
|
+
return null;
|
|
70
78
|
try {
|
|
71
|
-
|
|
79
|
+
const adapter = await gpu.requestAdapter();
|
|
80
|
+
if (adapter == null)
|
|
81
|
+
return null;
|
|
82
|
+
const info = adapter.info ?? {};
|
|
83
|
+
const fallback = info.isFallbackAdapter === true ||
|
|
84
|
+
adapter.isFallbackAdapter === true ||
|
|
85
|
+
[info.vendor, info.architecture, info.description].some((field) => typeof field === "string" && softwareRenderer(field));
|
|
86
|
+
return { fallback };
|
|
72
87
|
}
|
|
73
88
|
catch {
|
|
74
|
-
return
|
|
89
|
+
return null;
|
|
75
90
|
}
|
|
76
91
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*/
|
|
92
|
+
const UNMASKED_RENDERER = 0x9246;
|
|
93
|
+
const RENDERER = 0x1f01;
|
|
94
|
+
// The probe context is lost at once because browsers cap live WebGL contexts.
|
|
81
95
|
function detectWebgl2() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
let surface;
|
|
97
|
+
if (globalThis.OffscreenCanvas !== undefined)
|
|
98
|
+
surface = new OffscreenCanvas(1, 1);
|
|
99
|
+
else if (typeof document !== "undefined")
|
|
100
|
+
surface = document.createElement("canvas");
|
|
101
|
+
else
|
|
102
|
+
return null;
|
|
103
|
+
let context;
|
|
104
|
+
try {
|
|
105
|
+
context = surface.getContext("webgl2");
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (context == null)
|
|
111
|
+
return null;
|
|
112
|
+
let renderer = "";
|
|
113
|
+
try {
|
|
114
|
+
const unmasked = context.getExtension("WEBGL_debug_renderer_info");
|
|
115
|
+
const name = context.getParameter(unmasked === null ? RENDERER : UNMASKED_RENDERER);
|
|
116
|
+
if (typeof name === "string")
|
|
117
|
+
renderer = name;
|
|
118
|
+
context.getExtension("WEBGL_lose_context")?.loseContext();
|
|
92
119
|
}
|
|
93
|
-
|
|
94
|
-
|
|
120
|
+
catch {
|
|
121
|
+
// The context exists even if its name is unknown.
|
|
95
122
|
}
|
|
96
|
-
return
|
|
123
|
+
return renderer;
|
|
97
124
|
}
|
|
98
125
|
/**
|
|
99
|
-
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and
|
|
100
|
-
*
|
|
101
|
-
* the host acts on what it reports.
|
|
126
|
+
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and reports each
|
|
127
|
+
* degradation through `notify`. The host acts on what it reports.
|
|
102
128
|
*
|
|
103
|
-
* @throws RangeError From the constructor when either budget is not a positive
|
|
104
|
-
* safe integer.
|
|
129
|
+
* @throws RangeError From the constructor when either budget is not a positive safe integer.
|
|
105
130
|
*/
|
|
106
131
|
export class BrowserRobustnessCoordinator {
|
|
107
132
|
#budget;
|
|
@@ -119,8 +144,7 @@ export class BrowserRobustnessCoordinator {
|
|
|
119
144
|
this.#notify = notify;
|
|
120
145
|
}
|
|
121
146
|
/**
|
|
122
|
-
* Sizes `canvas`'s backing store to its CSS size times `scale` (
|
|
123
|
-
* pixel ratio), rounded, at least 1x1.
|
|
147
|
+
* Sizes `canvas`'s backing store to its CSS size times `scale` (device pixel ratio), min 1x1.
|
|
124
148
|
*
|
|
125
149
|
* @throws RangeError When the scaled size is not a safe integer.
|
|
126
150
|
*/
|
|
@@ -139,22 +163,15 @@ export class BrowserRobustnessCoordinator {
|
|
|
139
163
|
this.#notify("visibility-suspended");
|
|
140
164
|
this.#visible = visible;
|
|
141
165
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Reports `memory-pressure` and returns the texture budget to fall back to:
|
|
144
|
-
* half the configured one, at least one byte.
|
|
145
|
-
*/
|
|
166
|
+
/** Reports `memory-pressure` and returns the reduced texture budget (half, at least 1 byte). */
|
|
146
167
|
memoryPressure() {
|
|
147
168
|
this.#notify("memory-pressure");
|
|
148
169
|
return Math.max(1, Math.floor(this.#budget.textureBytes / 2));
|
|
149
170
|
}
|
|
150
|
-
/** Reports `context-lost`. */
|
|
151
171
|
contextLost() {
|
|
152
172
|
this.#notify("context-lost");
|
|
153
173
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Takes one decoder session. Returns `false`, and reports
|
|
156
|
-
* `decoder-session-limit`, when all of the budget's sessions are taken.
|
|
157
|
-
*/
|
|
174
|
+
/** Takes one decoder session, or reports `decoder-session-limit` and returns `false`. */
|
|
158
175
|
acquireDecoder() {
|
|
159
176
|
if (this.#decoders >= this.#budget.decoderSessions) {
|
|
160
177
|
this.#notify("decoder-session-limit");
|
package/dist/sha256.d.ts
CHANGED
|
@@ -3,24 +3,16 @@ export declare class Sha256 {
|
|
|
3
3
|
#private;
|
|
4
4
|
/** Adds `bytes` to the message. Throws once {@link Sha256.hex} has been called. */
|
|
5
5
|
update(bytes: Uint8Array): this;
|
|
6
|
-
/**
|
|
7
|
-
* Finishes the message and returns its hash as 64 lowercase hex digits.
|
|
8
|
-
* The hash can be finished once; a second call throws.
|
|
9
|
-
*/
|
|
6
|
+
/** Returns the hash as 64 lowercase hex digits. Throws if called twice. */
|
|
10
7
|
hex(): string;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
10
|
+
* Streams a blob through SHA-256 and returns 64 lowercase hex digits.
|
|
14
11
|
*
|
|
15
|
-
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB.
|
|
16
|
-
*
|
|
12
|
+
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB. Hashing yields
|
|
13
|
+
* to the event loop about every 8 ms so the page stays responsive and `signal` can abort it.
|
|
17
14
|
*
|
|
18
|
-
*
|
|
19
|
-
* between, so hashing yields to the event loop about every 8 ms: the page keeps painting and
|
|
20
|
-
* handling input, and `signal` can abort it partway.
|
|
21
|
-
*
|
|
22
|
-
* Rejects with `signal.reason` when `signal` aborts, and with the stream's error when the blob
|
|
23
|
-
* cannot be read.
|
|
15
|
+
* Rejects with `signal.reason` on abort, or with the stream's error when the blob cannot be read.
|
|
24
16
|
*/
|
|
25
17
|
export declare function sha256Blob(blob: Blob, options?: {
|
|
26
18
|
readonly signal?: AbortSignal;
|