alpha2 0.4.6 → 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.
Files changed (119) hide show
  1. package/README.md +5 -4
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/dist/abort.d.ts +12 -0
  4. package/dist/abort.js +48 -0
  5. package/dist/active-clock.d.ts +35 -0
  6. package/dist/active-clock.js +99 -0
  7. package/dist/assets.d.ts +28 -22
  8. package/dist/assets.js +8 -12
  9. package/dist/audio-layout.d.ts +52 -74
  10. package/dist/audio-layout.js +114 -148
  11. package/dist/audio-timeline.d.ts +89 -117
  12. package/dist/audio-timeline.js +102 -118
  13. package/dist/audio-worker.d.ts +12 -21
  14. package/dist/audio-worker.js +8 -13
  15. package/dist/audio-worklet-processor.js +45 -58
  16. package/dist/audio-worklet.d.ts +45 -76
  17. package/dist/audio-worklet.js +44 -79
  18. package/dist/audio.d.ts +15 -23
  19. package/dist/audio.js +9 -13
  20. package/dist/builder.d.ts +45 -63
  21. package/dist/builder.js +49 -45
  22. package/dist/capabilities.d.ts +99 -16
  23. package/dist/capabilities.js +2 -2
  24. package/dist/captions.d.ts +45 -22
  25. package/dist/captions.js +60 -15
  26. package/dist/chroma-siting.d.ts +24 -41
  27. package/dist/chroma-siting.js +38 -71
  28. package/dist/containers.d.ts +41 -30
  29. package/dist/containers.js +59 -27
  30. package/dist/decoder-fallback.d.ts +13 -0
  31. package/dist/decoder-fallback.js +38 -0
  32. package/dist/decoder-order.d.ts +24 -39
  33. package/dist/decoder-order.js +28 -42
  34. package/dist/edit.d.ts +77 -154
  35. package/dist/edit.js +98 -180
  36. package/dist/effects.d.ts +108 -177
  37. package/dist/effects.js +7 -9
  38. package/dist/export-destination.d.ts +25 -41
  39. package/dist/export-destination.js +20 -32
  40. package/dist/export-failure.d.ts +34 -59
  41. package/dist/export-failure.js +54 -48
  42. package/dist/export-metrics.d.ts +116 -0
  43. package/dist/export-metrics.js +74 -0
  44. package/dist/export-retry.d.ts +46 -29
  45. package/dist/export-retry.js +86 -51
  46. package/dist/exporter.d.ts +67 -116
  47. package/dist/exporter.js +133 -133
  48. package/dist/extensions.d.ts +69 -115
  49. package/dist/extensions.js +55 -82
  50. package/dist/frame-intake.d.ts +92 -0
  51. package/dist/frame-intake.js +114 -0
  52. package/dist/frame-supply.d.ts +96 -162
  53. package/dist/frame-supply.js +181 -171
  54. package/dist/generated/project-schema.d.ts +701 -485
  55. package/dist/generated/project-schema.js +55 -2
  56. package/dist/generated/project-shape.js +261 -16
  57. package/dist/geometry.d.ts +28 -34
  58. package/dist/geometry.js +18 -23
  59. package/dist/gpu-recovery.d.ts +92 -0
  60. package/dist/gpu-recovery.js +135 -0
  61. package/dist/hdr-frames.d.ts +82 -67
  62. package/dist/hdr-frames.js +112 -49
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.js +4 -0
  65. package/dist/json-text.d.ts +13 -23
  66. package/dist/json-text.js +10 -20
  67. package/dist/layout-values.d.ts +14 -22
  68. package/dist/layout-values.js +18 -21
  69. package/dist/layout.d.ts +48 -63
  70. package/dist/layout.js +37 -37
  71. package/dist/loudness.d.ts +27 -32
  72. package/dist/loudness.js +19 -23
  73. package/dist/media.d.ts +85 -237
  74. package/dist/media.js +133 -287
  75. package/dist/mediabunny.d.ts +166 -245
  76. package/dist/mediabunny.js +741 -580
  77. package/dist/physical-frames.d.ts +5 -17
  78. package/dist/physical-frames.js +4 -11
  79. package/dist/player.d.ts +56 -47
  80. package/dist/player.js +155 -40
  81. package/dist/presented-frames.d.ts +2 -7
  82. package/dist/presented-frames.js +3 -8
  83. package/dist/project.d.ts +73 -117
  84. package/dist/project.js +384 -445
  85. package/dist/rate-control.d.ts +9 -23
  86. package/dist/rate-control.js +7 -18
  87. package/dist/renderer-choice.d.ts +41 -0
  88. package/dist/renderer-choice.js +82 -0
  89. package/dist/repacked-bytes.d.ts +0 -2
  90. package/dist/repacked-bytes.js +2 -5
  91. package/dist/robustness.d.ts +25 -37
  92. package/dist/robustness.js +71 -54
  93. package/dist/sha256.d.ts +5 -13
  94. package/dist/sha256.js +9 -24
  95. package/dist/text.d.ts +97 -71
  96. package/dist/text.js +33 -70
  97. package/dist/video-frames.d.ts +7 -25
  98. package/dist/video-frames.js +12 -29
  99. package/dist/waveform.d.ts +5 -11
  100. package/dist/waveform.js +4 -9
  101. package/dist/worker-error.d.ts +5 -20
  102. package/dist/worker-error.js +8 -25
  103. package/dist/worker.d.ts +82 -95
  104. package/dist/worker.js +235 -143
  105. package/package.json +26 -2
  106. package/wasm/alpha2_audio_worklet.wasm +0 -0
  107. package/wasm/alpha2_extensions.d.ts +26 -47
  108. package/wasm/alpha2_extensions.js +26 -47
  109. package/wasm/alpha2_extensions_bg.wasm +0 -0
  110. package/wasm/alpha2_wasm.d.ts +460 -567
  111. package/wasm/alpha2_wasm.js +594 -594
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/README.md CHANGED
@@ -10,7 +10,7 @@ For an editor with documents, undo, and a ready preview and export bridge, see [
10
10
  npm install alpha2
11
11
  ```
12
12
 
13
- - The WebAssembly modules need Chrome 96, Firefox 89 or Safari 16.4, or later.
13
+ - The WebAssembly modules need Chrome 96, Firefox 89 or Safari 26, or later.
14
14
  - Serve `.wasm` files as `application/wasm`; otherwise the loader falls back to a slower way of compiling them and warns.
15
15
  - Audio preview needs a cross-origin isolated page (`Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Embedder-Policy: require-corp`).
16
16
  - [mediabunny](https://www.npmjs.com/package/mediabunny) is an optional dependency, for the decoders and the MP4, MOV, MKV and WebM writer in `alpha2/mediabunny`. It installs `@types/dom-webcodecs` 0.1.13, whose declarations clash with TypeScript 5.9's DOM library. A TypeScript application either compiles with `skipLibCheck` or adds `"overrides": { "@types/dom-webcodecs": "0.1.19" }` to its `package.json`; one that imports `alpha2/mediabunny` also needs `"ESNext.Disposable"` in its `lib`.
@@ -36,8 +36,8 @@ engine.renderAt(0n); // draws the frame at time 0 on the canvas
36
36
  ```
37
37
 
38
38
  - `init()` loads `alpha2_wasm_bg.wasm` from beside the module. A bundler that moves it passes its URL, a `Response`, its bytes or a compiled `WebAssembly.Module` as `init({ module_or_path })`; the files are `alpha2/wasm/alpha2_wasm_bg.wasm` (the engine), `alpha2/wasm/alpha2_audio_worklet.wasm` (the audio worklet) and `alpha2/wasm/alpha2_extensions_bg.wasm` (SVG, animated images, Lottie, OpenEXR and image sequences, loaded only for such a source).
39
- - `createForHtmlCanvas` draws on a page canvas; a worker passes an `OffscreenCanvas` to `createForCanvas`. Either renders with WebGPU, or with WebGL2 when the browser has no WebGPU.
40
- - With neither (Chrome with acceleration off, a blocklisted GPU), `WebEffectRegistry.createCpu(canvas)` makes the engine's CPU renderer: the same calls, drawn in wasm on one thread, the preview put on the canvas's 2D context. It draws exactly what the native CPU renderer draws, refuses runtime WGSL effects with `EFFECT_ERROR`, and needs no canvas to export. `detectBrowserCapabilities()` reports which renderer the browser gets (`renderer`).
39
+ - `createForHtmlCanvas` draws on a page canvas; a worker passes an `OffscreenCanvas` to `createForCanvas`. Either renders with WebGPU, or with WebGL2 when the browser has no WebGPU. The WebGPU device is opened before the canvas is bound, so a failure leaves the canvas free for another context. `{ softwareAdapter: "refuse" }` refuses software adapters (SwiftShader, llvmpipe, WARP, a WebGPU fallback adapter) and rejects `GPU_INIT_FAILED` when the browser offers nothing else.
40
+ - With neither (Chrome with acceleration off, a blocklisted GPU), `WebEffectRegistry.createCpu(canvas)` makes the engine's CPU renderer: the same calls, drawn in wasm on one thread, the preview put on the canvas's 2D context. It draws exactly what the native CPU renderer draws, refuses runtime WGSL effects with `EFFECT_ERROR`, and needs no canvas to export. `createRenderer(binding, canvas, mode)` in `alpha2/renderer-choice` makes the renderer a mode asks for (`"auto"` draws on a hardware GPU, else on the CPU renderer, as the native host's `auto` does) and says which it made. `detectBrowserCapabilities()` reports which renderer `"auto"` gets on the calling thread (`renderer`), probing WebGL2 on an `OffscreenCanvas`, as render hosts draw; a worker host's answer comes from `WorkerRenderBackend.detectCapabilities()`.
41
41
  - A project is the engine's JSON document. `alpha2/project` has its TypeScript types, tick conversions and `validateProject`, which reports what the engine would refuse before the document is sent; `alpha2/builder` writes one with times in seconds. `loadProject` checks the document again and throws what it refuses.
42
42
  - `renderAt(ticks)` returns JSON that names the sources it had no frame for (`missingSources`, `missingFrames`). The engine decides which frame of each source a time needs: `frameNeeds(ticks)` lists them with the exact source time, and the application decodes and uploads those (`uploadVideoFrame` for a `VideoFrame`, `uploadRgbaFrame` for pixels at a source time, `uploadRgbaImage` for a still). `FrameSupply` in `alpha2/frame-supply` does this for a decoder per clip, and keeps the uploads within a byte budget.
43
43
 
@@ -77,7 +77,7 @@ For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread
77
77
 
78
78
  ## Preview in a worker
79
79
 
80
- `alpha2/worker` runs the engine in a worker that owns the GPU device and an `OffscreenCanvas` (`installRenderWorker`, `createWasmRenderWorkerHost`), and `WorkerRenderBackend` drives it from the page. The host's `renderer` option is `"auto"` (WebGPU, else WebGL2, else the CPU renderer), `"gpu"` or `"cpu"`; `WorkerRenderBackend.rendererChoice` says which renderer the worker made and why it draws on the CPU, as the native host's `renderer` and `rendererReason` do. `Alpha2Player` in `alpha2/player` presents times through such a backend: it serializes presentations, asks for the frames a presentation lacks and shows them once they arrive, and makes the device again after a device loss.
80
+ `alpha2/worker` runs the engine in a worker that owns the GPU device and an `OffscreenCanvas` (`installRenderWorker`, `createWasmRenderWorkerHost`), and `WorkerRenderBackend` drives it from the page. The host's `renderer` option is `"auto"` (WebGPU, else WebGL2, on a hardware adapter, else the CPU renderer), `"gpu"` (any adapter, software ones included) or `"cpu"`; `WorkerRenderBackend.rendererChoice` says which renderer the worker made and why it draws on the CPU, as the native host's `renderer` and `rendererReason` do. `Alpha2Player` in `alpha2/player` presents times through such a backend: it serializes presentations, asks for the frames a presentation lacks and shows them once they arrive, and recovers a lost GPU through `GpuRecoveryLadder` (`alpha2/gpu-recovery`): the GPU again after a first external loss, the CPU renderer once the loss was the work's own (`GPU_DEVICE_HUNG`), recurred at the same frame, or the page has lost the GPU twice (the browser withdraws GPU access after its next reset). A recovery that needs a new canvas takes one from the player's `replaceSurface` option; `@alpha2-sh/react` supplies it.
81
81
 
82
82
  ## Subpaths
83
83
 
@@ -99,6 +99,7 @@ For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread
99
99
  | `alpha2/mediabunny` | Decoders and an MP4, MOV, MKV and WebM sink on mediabunny (an optional dependency). |
100
100
  | `alpha2/hdr-frames`, `alpha2/video-frames` | Uploading planar and HDR `VideoFrame`s; `VideoFrame`s from exported I420 planes. |
101
101
  | `alpha2/player`, `alpha2/worker` | `Alpha2Player` and the render worker. |
102
+ | `alpha2/renderer-choice`, `alpha2/gpu-recovery` | Making the renderer a mode asks for; what a host does after a GPU loss. |
102
103
  | `alpha2/exporter` | `Alpha2Exporter` and `exportToSink`. |
103
104
  | `alpha2/export-destination` | Where an export's bytes go: a file, or memory. |
104
105
  | `alpha2/export-failure`, `alpha2/export-retry` | How export failures are classified, and a retry policy over them. |
@@ -10,6 +10,10 @@ The `alpha2` npm package and the native archives each list the third-party Rust
10
10
 
11
11
  The native archives load FFmpeg 8, built as shared libraries under the LGPL 2.1 or later with its GPL and nonfree components disabled. Each archive carries the license texts of FFmpeg and the libraries it is built with in `licenses/`, and says where to get the corresponding source in `compliance/SOURCE.md`.
12
12
 
13
+ ## DirectX Shader Compiler
14
+
15
+ The Windows archive (and the wheel and Node install built from it) carries `bin/dxcompiler.dll` from Microsoft's DirectX Shader Compiler release v1.9.2609 (https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.9.2609), which `alpha2-host` loads to compile its DX12 shaders. It is under the University of Illinois/NCSA Open Source License (the LLVM release license), the MIT License, and the Microsoft Software License Terms for the DirectX Shader Compiler; the texts are in `licenses/DirectXShaderCompiler/`, and `compliance/DXC.toml` records the release and the checksums of what was shipped.
16
+
13
17
  ## OpenH264
14
18
 
15
19
  alpha2 does not include OpenH264. On request (`python -m alpha2 install --openh264`, `npx @alpha2-sh/node install --openh264`) it downloads Cisco's prebuilt OpenH264 binary from Cisco to the user's machine, and `alpha2-host` loads it to encode H.264 in software; `ALPHA2_OPENH264=0` turns it off. Cisco's binary comes with the licence below (https://www.openh264.org/BINARY_LICENSE.txt, v1.0, its typographic quotes and copyright sign written in ASCII).
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The signal's reason as an `Error`. An `Error` reason passes through; anything else becomes a
3
+ * `DOMException` named `AbortError`.
4
+ */
5
+ export declare function abortError(signal: AbortSignal): Error;
6
+ /** Throws {@link abortError} when `signal` has aborted. */
7
+ export declare function throwIfAborted(signal?: AbortSignal): void;
8
+ /**
9
+ * Resolves with `work`, or rejects with `cancelled(signal)` as soon as `signal` aborts. A value that
10
+ * arrives after the abort is passed to `onLate` so its resources can be released.
11
+ */
12
+ export declare function raceAbort<T>(work: Promise<T>, signal: AbortSignal | undefined, onLate?: (value: T) => void, cancelled?: (signal: AbortSignal) => Error): Promise<T>;
package/dist/abort.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The signal's reason as an `Error`. An `Error` reason passes through; anything else becomes a
3
+ * `DOMException` named `AbortError`.
4
+ */
5
+ export function abortError(signal) {
6
+ const reason = signal.reason;
7
+ if (reason instanceof Error)
8
+ return reason;
9
+ if (typeof reason === "string")
10
+ return new DOMException(reason, "AbortError");
11
+ return new DOMException("Aborted", "AbortError");
12
+ }
13
+ /** Throws {@link abortError} when `signal` has aborted. */
14
+ export function throwIfAborted(signal) {
15
+ if (signal?.aborted === true)
16
+ throw abortError(signal);
17
+ }
18
+ /**
19
+ * Resolves with `work`, or rejects with `cancelled(signal)` as soon as `signal` aborts. A value that
20
+ * arrives after the abort is passed to `onLate` so its resources can be released.
21
+ */
22
+ export async function raceAbort(work, signal, onLate, cancelled = abortError) {
23
+ if (signal === undefined)
24
+ return work;
25
+ let lost = false;
26
+ void work.then((value) => {
27
+ if (lost)
28
+ onLate?.(value);
29
+ }, () => { });
30
+ let abort;
31
+ const aborted = new Promise((_, reject) => {
32
+ abort = () => {
33
+ lost = true;
34
+ reject(cancelled(signal));
35
+ };
36
+ if (signal.aborted)
37
+ abort();
38
+ else
39
+ signal.addEventListener("abort", abort, { once: true });
40
+ });
41
+ try {
42
+ return await Promise.race([work, aborted]);
43
+ }
44
+ finally {
45
+ if (abort !== undefined)
46
+ signal.removeEventListener("abort", abort);
47
+ }
48
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Timeouts that count active time, not wall-clock time.
3
+ *
4
+ * A frozen or sleeping page would otherwise fire every pending timeout on resume and report a
5
+ * paused decoder or encoder as stalled. Each tick credits at most {@link MAX_CREDIT_MS}, so a long
6
+ * freeze counts as one tick while a throttled one-second timer still counts in full.
7
+ */
8
+ /** Most active time one tick credits, in milliseconds. */
9
+ export declare const MAX_CREDIT_MS = 1100;
10
+ /** Stopwatch tick interval, in milliseconds. */
11
+ export declare const ACTIVE_TICK_MS = 250;
12
+ /** Clock source for a stopwatch; replaceable in tests. */
13
+ export interface ActiveClock {
14
+ now(): number;
15
+ every(ms: number, tick: () => void): () => void;
16
+ }
17
+ /** Active time since it started or was last reset. */
18
+ export declare class ActiveStopwatch {
19
+ #private;
20
+ constructor(clock?: ActiveClock);
21
+ /** Active milliseconds so far. */
22
+ elapsed(): number;
23
+ reset(): void;
24
+ /** Calls `listener` after every tick until the returned function is called. */
25
+ onTick(listener: () => void): () => void;
26
+ /** Stops the ticks; `elapsed()` still answers. */
27
+ dispose(): void;
28
+ }
29
+ /**
30
+ * Resolves once `ms` of active time has passed. Aborting `signal` stops the count and leaves the
31
+ * promise pending forever.
32
+ */
33
+ export declare function activeTimeout(ms: number, signal?: AbortSignal, clock?: ActiveClock): Promise<void>;
34
+ /** Resolves with `work`, or rejects with `timeout()` if `ms` of active time passes first. */
35
+ export declare function withinActiveTime<T>(work: Promise<T>, ms: number, timeout: () => unknown, clock?: ActiveClock): Promise<T>;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Timeouts that count active time, not wall-clock time.
3
+ *
4
+ * A frozen or sleeping page would otherwise fire every pending timeout on resume and report a
5
+ * paused decoder or encoder as stalled. Each tick credits at most {@link MAX_CREDIT_MS}, so a long
6
+ * freeze counts as one tick while a throttled one-second timer still counts in full.
7
+ */
8
+ /** Most active time one tick credits, in milliseconds. */
9
+ export const MAX_CREDIT_MS = 1_100;
10
+ /** Stopwatch tick interval, in milliseconds. */
11
+ export const ACTIVE_TICK_MS = 250;
12
+ const browserClock = {
13
+ now: () => performance.now(),
14
+ every: (ms, tick) => {
15
+ const timer = setInterval(tick, ms);
16
+ return () => clearInterval(timer);
17
+ },
18
+ };
19
+ /** Active time since it started or was last reset. */
20
+ export class ActiveStopwatch {
21
+ #clock;
22
+ #elapsed = 0;
23
+ #last;
24
+ #stop;
25
+ #listeners = new Set();
26
+ constructor(clock = browserClock) {
27
+ this.#clock = clock;
28
+ this.#last = clock.now();
29
+ this.#stop = clock.every(ACTIVE_TICK_MS, () => this.#tick());
30
+ }
31
+ #credit() {
32
+ const now = this.#clock.now();
33
+ const credit = Math.min(Math.max(0, now - this.#last), MAX_CREDIT_MS);
34
+ this.#last = now;
35
+ return credit;
36
+ }
37
+ #tick() {
38
+ this.#elapsed += this.#credit();
39
+ for (const listener of [...this.#listeners])
40
+ listener();
41
+ }
42
+ /** Active milliseconds so far. */
43
+ elapsed() {
44
+ this.#elapsed += this.#credit();
45
+ return this.#elapsed;
46
+ }
47
+ reset() {
48
+ this.#elapsed = 0;
49
+ this.#last = this.#clock.now();
50
+ }
51
+ /** Calls `listener` after every tick until the returned function is called. */
52
+ onTick(listener) {
53
+ this.#listeners.add(listener);
54
+ return () => this.#listeners.delete(listener);
55
+ }
56
+ /** Stops the ticks; `elapsed()` still answers. */
57
+ dispose() {
58
+ this.#stop?.();
59
+ this.#stop = undefined;
60
+ this.#listeners.clear();
61
+ }
62
+ }
63
+ /**
64
+ * Resolves once `ms` of active time has passed. Aborting `signal` stops the count and leaves the
65
+ * promise pending forever.
66
+ */
67
+ export function activeTimeout(ms, signal, clock = browserClock) {
68
+ return new Promise((resolve) => {
69
+ if (signal?.aborted === true)
70
+ return;
71
+ const watch = new ActiveStopwatch(clock);
72
+ const stop = () => {
73
+ watch.dispose();
74
+ signal?.removeEventListener("abort", stop);
75
+ };
76
+ watch.onTick(() => {
77
+ if (watch.elapsed() < ms)
78
+ return;
79
+ stop();
80
+ resolve();
81
+ });
82
+ signal?.addEventListener("abort", stop, { once: true });
83
+ });
84
+ }
85
+ /** Resolves with `work`, or rejects with `timeout()` if `ms` of active time passes first. */
86
+ export async function withinActiveTime(work, ms, timeout, clock = browserClock) {
87
+ const done = new AbortController();
88
+ try {
89
+ return await Promise.race([
90
+ work,
91
+ activeTimeout(ms, done.signal, clock).then(() => {
92
+ throw timeout();
93
+ }),
94
+ ]);
95
+ }
96
+ finally {
97
+ done.abort();
98
+ }
99
+ }
package/dist/assets.d.ts CHANGED
@@ -7,6 +7,8 @@ export type OriginalState = {
7
7
  readonly fingerprint: MediaFingerprint;
8
8
  } | {
9
9
  readonly state: "offline";
10
+ /** The path the host looked the media up at, when it had one. */
11
+ readonly path?: string;
10
12
  } | {
11
13
  readonly state: "unsupported";
12
14
  readonly reason: string;
@@ -23,9 +25,8 @@ export type ProxyState = {
23
25
  /** A lighter copy of a source's media. */
24
26
  export interface ProxyVariant {
25
27
  readonly id: string;
26
- /** The source revision it was made from. */
27
28
  readonly source_revision: number;
28
- /** Evidence of the original it was made from. */
29
+ /** Fingerprint of the original it was made from. */
29
30
  readonly made_from: MediaFingerprint;
30
31
  /** Displayed size in pixels. */
31
32
  readonly width: number;
@@ -36,20 +37,25 @@ export interface ProxyVariant {
36
37
  };
37
38
  readonly duration_ticks?: number;
38
39
  readonly audio_sample_rate?: number;
39
- /** The color pipeline baked in, when it was tone-mapped. */
40
+ /** Color pipeline baked in when it was tone-mapped. */
40
41
  readonly color_pipeline?: string;
41
42
  readonly state: ProxyState;
42
43
  }
43
44
  /** One source's media, as a host sees it now. */
44
45
  export interface AssetEntry {
45
46
  readonly source_id: string;
46
- /** The host's revision of the media; relinking makes a new one. */
47
+ /** Host revision of the media; relinking bumps it. */
47
48
  readonly revision: number;
48
49
  readonly original: OriginalState;
49
50
  /** In the host's order of preference. */
50
51
  readonly proxies?: readonly ProxyVariant[];
52
+ /**
53
+ * Why the host drops the original's alpha, when it cannot decode it (for example HEVC auxiliary
54
+ * alpha, or VP9 alpha without `libvpx`).
55
+ */
56
+ readonly alpha_dropped?: string;
51
57
  }
52
- /** Every source's media as one host sees it now. Runtime state, never part of a project. */
58
+ /** Media state of every source on one host. Runtime state, never part of a project. */
53
59
  export interface AssetCatalog {
54
60
  readonly assets: readonly AssetEntry[];
55
61
  }
@@ -62,9 +68,8 @@ export type Selection = {
62
68
  } | {
63
69
  readonly media: "unavailable";
64
70
  };
65
- /** A part of a fingerprint. */
66
71
  export type FingerprintField = "content" | "byte_length" | "video" | "audio" | "streams" | "duration" | "color";
67
- /** What comparing a recorded fingerprint with a found one shows. */
72
+ /** Result of comparing a recorded fingerprint with a found one. */
68
73
  export type FingerprintMatch = {
69
74
  readonly kind: "identical";
70
75
  } | {
@@ -98,6 +103,8 @@ export type ConformIssue = {
98
103
  readonly kind: "missing";
99
104
  } | {
100
105
  readonly kind: "offline";
106
+ /** The path the host looked the media up at, when it had one. */
107
+ readonly path?: string;
101
108
  } | {
102
109
  readonly kind: "unsupported";
103
110
  readonly reason: string;
@@ -116,12 +123,14 @@ export type ConformIssue = {
116
123
  } | {
117
124
  readonly kind: "hdr_rejected";
118
125
  }
119
- /**
120
- * Neither the project nor the video declares its color: it is read as BT.709 limited-range SDR.
121
- * Never blocking.
122
- */
126
+ /** No declared color, so the video is read as BT.709 limited-range SDR. Never blocking. */
123
127
  | {
124
128
  readonly kind: "undeclared_color";
129
+ }
130
+ /** The host cannot decode the original's alpha, so it draws opaque. Never blocking. */
131
+ | {
132
+ readonly kind: "alpha_dropped";
133
+ readonly reason: string;
125
134
  });
126
135
  /** One source's media for the purpose. */
127
136
  export interface SourceConform {
@@ -134,12 +143,12 @@ export interface SourceConform {
134
143
  /** Whether a project's sources can be read for a purpose, before a render starts. */
135
144
  export interface ConformReport {
136
145
  readonly purpose: MediaPurpose;
137
- /** Whether no issue blocks the purpose. */
146
+ /** True when no issue blocks the purpose. */
138
147
  readonly ready: boolean;
139
148
  /** Each host-supplied source a render reads, in project order. */
140
149
  readonly sources: readonly SourceConform[];
141
150
  }
142
- /** Every blocking issue, with its source. */
151
+ /** Lists every blocking issue with its source id. */
143
152
  export declare function blockingIssues(report: ConformReport): readonly {
144
153
  readonly sourceId: string;
145
154
  readonly issue: ConformIssue;
@@ -151,21 +160,18 @@ export interface AssetBinding {
151
160
  colorPipelineFingerprint(pipeline: string): string;
152
161
  }
153
162
  /**
154
- * Whether `found` is the media `recorded` describes, decided by the engine: hashes decide alone;
155
- * otherwise every part both recorded must agree, within demuxer tolerances.
163
+ * Asks the engine whether `found` is the media `recorded` describes. Content hashes decide alone;
164
+ * otherwise every part both record must agree within demuxer tolerances.
156
165
  *
157
- * @throws When either fingerprint has a part that is not well formed, such as a hash in uppercase:
158
- * an input error, not other media.
166
+ * @throws When either fingerprint is malformed (for example an uppercase hash).
159
167
  */
160
168
  export declare function compareFingerprints(binding: AssetBinding, recorded: MediaFingerprint, found: MediaFingerprint): FingerprintMatch;
161
169
  /**
162
- * Whether `project`'s media, as `catalog` describes it, is ready for `purpose`, decided by the
163
- * engine.
170
+ * Asks the engine whether `project`'s media, as `catalog` describes it, is ready for `purpose`.
164
171
  *
165
- * @throws When the project or catalog does not load, or the catalog holds a fingerprint that is not
166
- * well formed.
172
+ * @throws When the project or catalog does not load, or the catalog holds a malformed fingerprint.
167
173
  */
168
174
  export declare function conformProject(binding: AssetBinding, project: Project, catalog: AssetCatalog, purpose: MediaPurpose): ConformReport;
169
- /** A color pipeline's identity, as a proxy that bakes it in records it. */
175
+ /** Identity string a tone-mapped proxy records for `pipeline`. */
170
176
  export declare function colorPipelineFingerprint(binding: AssetBinding, pipeline: ColorPipeline): string;
171
177
  export * from "./sha256.js";
package/dist/assets.js CHANGED
@@ -1,32 +1,28 @@
1
- // The wire form of the engine's asset decisions (`alpha2-assets`). The engine makes the decisions;
2
- // they are never re-derived here.
3
- /** Every blocking issue, with its source. */
1
+ // Wire types for the engine's asset decisions (`alpha2-assets`); nothing is re-derived here.
2
+ /** Lists every blocking issue with its source id. */
4
3
  export function blockingIssues(report) {
5
4
  return report.sources.flatMap((source) => source.issues
6
5
  .filter((issue) => issue.blocking)
7
6
  .map((issue) => ({ sourceId: source.source_id, issue })));
8
7
  }
9
8
  /**
10
- * Whether `found` is the media `recorded` describes, decided by the engine: hashes decide alone;
11
- * otherwise every part both recorded must agree, within demuxer tolerances.
9
+ * Asks the engine whether `found` is the media `recorded` describes. Content hashes decide alone;
10
+ * otherwise every part both record must agree within demuxer tolerances.
12
11
  *
13
- * @throws When either fingerprint has a part that is not well formed, such as a hash in uppercase:
14
- * an input error, not other media.
12
+ * @throws When either fingerprint is malformed (for example an uppercase hash).
15
13
  */
16
14
  export function compareFingerprints(binding, recorded, found) {
17
15
  return JSON.parse(binding.compareFingerprints(JSON.stringify(recorded), JSON.stringify(found)));
18
16
  }
19
17
  /**
20
- * Whether `project`'s media, as `catalog` describes it, is ready for `purpose`, decided by the
21
- * engine.
18
+ * Asks the engine whether `project`'s media, as `catalog` describes it, is ready for `purpose`.
22
19
  *
23
- * @throws When the project or catalog does not load, or the catalog holds a fingerprint that is not
24
- * well formed.
20
+ * @throws When the project or catalog does not load, or the catalog holds a malformed fingerprint.
25
21
  */
26
22
  export function conformProject(binding, project, catalog, purpose) {
27
23
  return JSON.parse(binding.conformProject(JSON.stringify(project), JSON.stringify(catalog), purpose));
28
24
  }
29
- /** A color pipeline's identity, as a proxy that bakes it in records it. */
25
+ /** Identity string a tone-mapped proxy records for `pipeline`. */
30
26
  export function colorPipelineFingerprint(binding, pipeline) {
31
27
  return binding.colorPipelineFingerprint(JSON.stringify(pipeline));
32
28
  }
@@ -1,35 +1,35 @@
1
1
  /**
2
- * The speaker layout a browser-decoded audio source declares, read as a native host reads it.
2
+ * Reads the speaker layout of a browser-decoded audio source the way the native host does.
3
3
  *
4
- * WebCodecs `AudioData` and mediabunny's demuxers carry only a channel count, so the layout comes
5
- * from the bytes: a WAVE `dwChannelMask`, a QuickTime `chan` or ISO `chnl` box, a FLAC
6
- * `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment, or the codec's own headers (an AAC channel
7
- * configuration or program config element, an Opus head, an AC-3, E-AC-3 or DTS frame header).
8
- * Each rule is `FFmpeg`'s (`riffdec.c`, `mov_chan.c`, the FLAC and Matroska demuxers, the AAC,
9
- * Opus, Vorbis, FLAC, AC-3 and DTS decoders), so the speakers reported here are the ones the native
10
- * decoder reports for the same file. `null` means the source declares none, or the native decoder
11
- * would leave its layout unspecified; the engine then assumes `FFmpeg`'s default for the channel
12
- * count, as a native host does.
4
+ * WebCodecs and mediabunny expose only a channel count, so the layout is parsed from the bytes
5
+ * (WAVE channel mask, QuickTime `chan` or ISO `chnl` box, FLAC channel-mask comment, or codec
6
+ * headers). Every rule mirrors `FFmpeg`'s demuxers and decoders. `null` means no declared layout;
7
+ * the engine then uses `FFmpeg`'s default for the channel count.
13
8
  */
14
9
  import type { AudioSpeaker } from "./media.js";
15
- /** Every name a speaker list may hold: the named `FFmpeg` channels plus `UNK`. */
10
+ /** Valid speaker names: the named `FFmpeg` channels plus `UNK`. */
16
11
  export declare const AUDIO_SPEAKERS: ReadonlySet<string>;
12
+ /** Speakers of a native-order channel mask in bit order (`av_channel_layout_from_mask`). */
13
+ export declare function speakersOfMask(mask: bigint): AudioSpeaker[];
17
14
  /**
18
- * The speakers of a native-order channel mask, in bit order, as `FFmpeg`'s
19
- * `av_channel_layout_from_mask` lists them. A set bit with no named channel is `UNK`.
15
+ * `speakers` with an LFE inserted in native order, plus its plane index, for decoders that add a
16
+ * silent LFE (a WebCodecs decoder does for E-AC-3 5.0). `null` when there is already an LFE or the
17
+ * list is not native-order named speakers.
20
18
  */
21
- export declare function speakersOfMask(mask: bigint): AudioSpeaker[];
19
+ export declare function speakersWithLfe(speakers: readonly AudioSpeaker[]): {
20
+ speakers: AudioSpeaker[];
21
+ lfePlane: number;
22
+ } | null;
22
23
  /**
23
- * The speakers of a WAVE `fmt ` chunk payload's `WAVE_FORMAT_EXTENSIBLE` channel mask, as
24
- * `FFmpeg`'s RIFF demuxer reads it: a mask whose bit count is not `channels` says nothing.
25
- * `null` for any other WAVE format, a payload shorter than 24 bytes, or a mask naming no speaker.
24
+ * Speakers of a `WAVE_FORMAT_EXTENSIBLE` channel mask in a `fmt ` chunk payload, as `FFmpeg`'s RIFF
25
+ * demuxer reads it. `null` for other formats, short payloads, or a mask whose bit count is not
26
+ * `channels`.
26
27
  */
27
28
  export declare function wavSpeakers(fmt: Uint8Array, channels: number): AudioSpeaker[] | null;
28
29
  /**
29
- * The speakers a QuickTime `chan` box's payload (after its version and flags) declares, as
30
- * `FFmpeg`'s `ff_mov_read_chan` reads it: channel descriptions, a channel bitmap whose bit count
31
- * is the channel count, or a layout tag of that count that `mov_chan.c` knows. `null` for anything
32
- * else, including a truncated payload.
30
+ * Speakers a QuickTime `chan` payload (after version and flags) declares, per `ff_mov_read_chan`:
31
+ * channel descriptions, a bitmap, or a known layout tag, each matching `channels`. `null`
32
+ * otherwise, including for truncated payloads.
33
33
  */
34
34
  export declare function movChanSpeakers(chan: Uint8Array, channels: number): AudioSpeaker[] | null;
35
35
  /**
@@ -38,87 +38,65 @@ export declare function movChanSpeakers(chan: Uint8Array, channels: number): Aud
38
38
  */
39
39
  export type ByteReader = (offset: number, length: number) => Promise<Uint8Array>;
40
40
  /**
41
- * The speakers an ISO/IEC 23001-8 `chnl` box's payload (after its version and flags) declares, as
42
- * `FFmpeg`'s `ff_mov_read_chnl` reads it: a speaker position per channel, or a channel
43
- * configuration of the channel count less its omitted channels. `null` for a box that carries no
44
- * channels, a configuration `FFmpeg` does not know or of another count, a truncated payload, or
45
- * one naming no speaker.
41
+ * Speakers an ISO `chnl` payload (after version and flags) declares, per `ff_mov_read_chnl`:
42
+ * explicit positions, or a channel configuration minus omitted channels. `null` for no channels,
43
+ * an unknown or mismatched configuration, a truncated payload, or no named speaker.
46
44
  */
47
45
  export declare function chnlSpeakers(chnl: Uint8Array, channels: number): AudioSpeaker[] | null;
48
46
  /**
49
- * The speakers `FFmpeg`'s AAC decoder lays an `AudioSpecificConfig` out as: its channel
50
- * configuration's or program config element's elements, assigned and ordered as
51
- * `ff_aac_output_configure` does. `null` when `FFmpeg` leaves the layout unspecified;
52
- * `undefined` when it would not decode the config at all.
47
+ * Speakers of an `AudioSpecificConfig` as `ff_aac_output_configure` orders them. `null` when the
48
+ * layout stays unspecified; `undefined` when `FFmpeg` would not decode the config.
53
49
  */
54
50
  export declare function aacSpeakers(config: Uint8Array): AudioSpeaker[] | null | undefined;
55
51
  /**
56
- * The output elements a program config element in an `AudioSpecificConfig` declares, in its
57
- * order, each its type then its position: `SF CF CB LL` is a front SCE, a front CPE, a back CPE
58
- * and an LFE (`S`, `C`, `L`; front, side, back, LFE). `null` for a config with a channel
59
- * configuration or one `FFmpeg` would not decode.
52
+ * PCE output elements as type then position letters: `SF CF CB LL` is a front SCE, a front CPE,
53
+ * a back CPE and an LFE. `null` for a config with a channel configuration or one `FFmpeg` would not
54
+ * decode.
60
55
  */
61
56
  export declare function aacProgramConfigElements(config: Uint8Array): string | null;
62
57
  /**
63
- * The speakers `FFmpeg`'s AC-3 or E-AC-3 decoder lays a packet out as: its first frame's channel
64
- * mode and LFE, and the channels an E-AC-3 dependent frame after it adds by its channel map.
65
- * `undefined` when the packet does not start with a frame `FFmpeg` decodes.
58
+ * Speakers `FFmpeg`'s AC-3 or E-AC-3 decoder produces for a packet, including channels added by an
59
+ * E-AC-3 dependent frame. `undefined` when the packet does not start with a decodable frame.
66
60
  */
67
61
  export declare function ac3Speakers(packet: Uint8Array): AudioSpeaker[] | undefined;
68
62
  /**
69
- * The speakers `FFmpeg`'s DTS decoder lays a packet of a core alone out as: the core's channel
70
- * arrangement and LFE. `null` when the packet carries more than a core `FFmpeg` would decode
71
- * (channel extensions, an extension substream, a substream without a core) or is not a 16-bit
72
- * core; those layouts are not read.
63
+ * Speakers of a core-only DTS packet. `null` for anything beyond a 16-bit core (channel extensions,
64
+ * extension substreams, coreless substreams), whose layouts are not read.
73
65
  */
74
66
  export declare function dtsSpeakers(packet: Uint8Array): AudioSpeaker[] | null;
75
- /** The AAC channel configuration of each ADTS channel count (ADTS carries 1 to 7). */
67
+ /** AAC channel configuration for each ADTS channel count (configurations 1 to 7). */
76
68
  export declare const ADTS_CONFIGURATIONS: Readonly<Record<number, number>>;
77
- /**
78
- * The AAC channel configuration of an `AudioSpecificConfig`. `null` for a truncated config or for
79
- * configuration 0, which defers to a program config element.
80
- */
69
+ /** AAC channel configuration, or `null` when truncated or 0 (defers to a PCE). */
81
70
  export declare function aacChannelConfiguration(config: Uint8Array): number | null;
82
- /** The channel mapping family of an `OpusHead`, 0 when there is none. */
71
+ /** `OpusHead` channel mapping family; 0 without a head. */
83
72
  export declare function opusMappingFamily(description: Uint8Array | null): number;
84
73
  /**
85
- * The speakers a codec's own headers declare, in the order `FFmpeg`'s decoder delivers its planes
86
- * (the native order of the layout it sets): an AAC channel configuration or program config
87
- * element (an ADTS stream's configuration, without a description), an Opus mapping family 0 or 1
88
- * head, Vorbis's and FLAC's fixed orders, an AC-3 or E-AC-3 frame's channel mode, LFE and
89
- * dependent channel map, a DTS core's channel arrangement, and mono or stereo for any codec.
90
- * `null` when the codec says nothing the decoder would read, or the decoder would leave the layout
91
- * unspecified.
74
+ * Speakers a codec's own headers declare, in `FFmpeg`'s decoder plane order. Covers AAC, Opus
75
+ * mapping families 0 and 1, Vorbis and FLAC fixed orders, AC-3/E-AC-3, DTS cores, and mono or
76
+ * stereo for any codec. `null` when the decoder would leave the layout unspecified.
92
77
  *
93
- * @param codec mediabunny's codec name (`aac`, `opus`, `vorbis`, `flac`, `ac3`, `eac3`, `dts`,
94
- * ...).
95
- * @param description The decoder configuration's description (`AudioSpecificConfig`,
96
- * `OpusHead`), when the track has one.
97
- * @param packet The track's first packet, which an AC-3, E-AC-3 or DTS decoder reads its layout
98
- * from.
78
+ * Other decoders may deliver another order (Safari's AAC keeps bitstream order);
79
+ * `decoder-order.ts` measures and corrects for that.
99
80
  *
100
- * Chromium's decoders, which are `FFmpeg`'s, deliver this order. WebCodecs leaves the order to the
101
- * decoder, and Safari's AAC decoder keeps the bitstream's; the mediabunny adapter measures the
102
- * order a decoder delivers and puts its planes back in this one (`decoder-order.ts`).
81
+ * @param codec mediabunny's codec name (`aac`, `opus`, `vorbis`, `flac`, `ac3`, `eac3`, `dts`).
82
+ * @param description The decoder configuration description (`AudioSpecificConfig`, `OpusHead`).
83
+ * @param packet The first packet, from which AC-3, E-AC-3 and DTS layouts are read.
103
84
  */
104
85
  export declare function codecSpeakers(codec: string | null, description: Uint8Array | null, channels: number, packet?: Uint8Array | null): AudioSpeaker[] | null;
105
86
  /**
106
- * The speakers a source's primary audio track declares, or `null` when it declares none.
87
+ * Speakers the source's primary audio track declares, or `null`.
107
88
  *
108
- * A codec whose decoder sets a layout is laid out as `FFmpeg`'s decoder lays it out
109
- * ({@link codecSpeakers}), whatever the container says. FLAC's decoder keeps a layout of its
110
- * channel count from the demuxer: a `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment in a FLAC file or
111
- * Matroska, a QuickTime `chan` or ISO `chnl` box, and FLAC's own order otherwise. PCM, and any
112
- * other codec, is laid out by its container: a WAVE channel mask, a QuickTime `chan` box, an ISO
113
- * `chnl` box.
89
+ * Codecs whose decoder sets a layout use {@link codecSpeakers} regardless of the container. FLAC
90
+ * takes a matching container layout (channel-mask comment, `chan` or `chnl`), else its own order.
91
+ * PCM and other codecs use the container's WAVE mask, `chan` or `chnl` box.
114
92
  *
115
93
  * @param read Reads the source file's bytes.
116
94
  * @param size The source file's size in bytes.
117
- * @param track The audio track; `id` picks the matching `trak` in a QuickTime file, and the first
118
- * track with a `chan` or `chnl` box is used when none matches.
95
+ * @param track `id` selects the QuickTime `trak`; without a match, the first track with a layout
96
+ * box is used.
119
97
  * @param description The track's decoder configuration description, if any.
120
- * @param firstPacket Reads the track's first packet, for a codec that declares its layout there
121
- * (AC-3, E-AC-3, DTS); resolves `null` when there is none.
98
+ * @param firstPacket Reads the first packet, for AC-3, E-AC-3 and DTS; resolves `null` when there
99
+ * is none.
122
100
  *
123
101
  * Rejects only when `read` or `firstPacket` rejects; malformed bytes resolve to `null`.
124
102
  */