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/dist/geometry.js CHANGED
@@ -1,19 +1,16 @@
1
1
  /**
2
- * Shape geometry for editors, answered in wasm by the code the engine draws shapes with: where a
3
- * shapes generator's items are, which paint is under a point, how long a path is, and paths cut,
4
- * resampled, or converted. A hit test or a trim here agrees with what a frame shows.
2
+ * Shape geometry queries for editors, computed in wasm by the engine's shape code so results match
3
+ * rendered frames.
5
4
  *
6
- * Positions are normalized as the project document's are, `(0, 0)` top-left to `(1, 1)`
7
- * bottom-right of a `width` by `height` picture; lengths and distances are in its pixels. Times
8
- * are ticks, as keyframe times are.
5
+ * Positions are normalized, `(0, 0)` top-left to `(1, 1)` bottom-right of a `width` by `height`
6
+ * picture. Lengths and distances are in pixels; times are in ticks.
9
7
  *
10
8
  * Every function throws an `INVALID_INPUT` error for a picture outside 1 to 16384 pixels a side, a
11
- * time that is not a whole number of ticks, or input the model rejects (a content tree or geometry
12
- * that is not valid, a path point or tangent that is not finite).
9
+ * non-integer tick time, or input the model rejects (invalid content tree or geometry, non-finite
10
+ * point or tangent).
13
11
  */
14
12
  /**
15
- * Each item's bounds at `time`, in document order: a group's are its items', a stroke's include
16
- * its width.
13
+ * Each item's bounds at `time`, in document order. Stroke bounds include the stroke width.
17
14
  *
18
15
  * @throws When `items` is not a valid content tree.
19
16
  */
@@ -21,15 +18,15 @@ export function shapeBounds(binding, items, time, size) {
21
18
  return JSON.parse(binding.shapeBounds(JSON.stringify(items), time, size.width, size.height));
22
19
  }
23
20
  /**
24
- * The front-most fill or stroke at normalized `point` at `time`, by its fill rule (a stroke by
25
- * its outline): its place in the tree, or `undefined` where nothing is painted.
21
+ * Tree path of the front-most fill or stroke at normalized `point` at `time`, honoring fill rules,
22
+ * or `undefined` where nothing is painted.
26
23
  *
27
24
  * @throws When `items` is not a valid content tree.
28
25
  */
29
26
  export function hitTest(binding, items, time, size, point) {
30
27
  return (binding.hitTest(JSON.stringify(items), time, size.width, size.height, point.x, point.y) ?? undefined);
31
28
  }
32
- /** The point of `path` nearest normalized `point`, or `undefined` for an empty path. */
29
+ /** Closest point of `path` to normalized `point`, or `undefined` for an empty path. */
33
30
  export function nearestPoint(binding, path, size, point) {
34
31
  return (JSON.parse(binding.nearestPoint(JSON.stringify(path), size.width, size.height, point.x, point.y)) ?? undefined);
35
32
  }
@@ -38,18 +35,16 @@ export function pathLength(binding, path, size) {
38
35
  return JSON.parse(binding.pathLength(JSON.stringify(path), size.width, size.height));
39
36
  }
40
37
  /**
41
- * The part of `path` a trim item keeps: from `start` to `end` (fractions of its pixel length, all
42
- * subpaths end to end, clamped to `0..=1`), shifted by `offset` turns. Nothing when `start` is not
43
- * before `end`.
38
+ * The part of `path` a trim item keeps. `start` and `end` are fractions of the total length of all
39
+ * subpaths, clamped to `0..=1`; `offset` is in turns. Empty when `start >= end`.
44
40
  */
45
41
  export function trimPath(binding, path, size, start, end, offset = 0) {
46
42
  return JSON.parse(binding.trimPath(JSON.stringify(path), size.width, size.height, start, end, offset));
47
43
  }
48
44
  /**
49
- * `path` with `vertexCounts[i]` vertices on subpath `i`, evenly along its length, so two paths can
50
- * be given the same structure and their keyframes can morph. The engine never resamples on its
51
- * own. A subpath whose count is missing, below 2 (3 when closed), or that has no length is kept as
52
- * it is.
45
+ * Resamples subpath `i` to `vertexCounts[i]` evenly spaced vertices, so two paths can share a
46
+ * structure and morph between keyframes. Subpaths with a missing count, a count below 2 (3 when
47
+ * closed), or zero length are kept unchanged.
53
48
  *
54
49
  * @throws When a count is over `MAX_PATH_VERTICES`.
55
50
  */
@@ -57,15 +52,15 @@ export function resamplePath(binding, path, size, vertexCounts) {
57
52
  return JSON.parse(binding.resamplePath(JSON.stringify(path), size.width, size.height, Uint32Array.from(vertexCounts)));
58
53
  }
59
54
  /**
60
- * A rectangle, ellipse, or polystar at `time` as a path of the same outline, from the same start
61
- * point and in the same direction: "convert to path".
55
+ * Converts a rectangle, ellipse or polystar at `time` to a path with the same outline, start point
56
+ * and direction.
62
57
  *
63
58
  * @throws When `geometry` is not valid.
64
59
  */
65
60
  export function toPath(binding, geometry, time, size) {
66
61
  return JSON.parse(binding.toPath(JSON.stringify(geometry), time, size.width, size.height));
67
62
  }
68
- /** The polyline a position travels between its keyframes, along their spatial tangents. */
63
+ /** Polyline a position follows between keyframes, along their spatial tangents. */
69
64
  export function motionPath(binding, position, size) {
70
65
  return JSON.parse(binding.motionPath(JSON.stringify(position), size.width, size.height));
71
66
  }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Recovery decisions for a browser render host after a GPU loss.
3
+ *
4
+ * Browsers withdraw GPU access from a page after repeated GPU process resets: after the second,
5
+ * Chrome withholds WebGPU and page-canvas WebGL2 (`OffscreenCanvas` WebGL2 stays), and after the
6
+ * third nothing GPU-backed works. A loss caused by the page's own work recurs on the GPU. So the
7
+ * GPU is retried only for a first external loss; otherwise recovery moves to the CPU renderer on a
8
+ * fresh surface. Each rung is tried once per loss.
9
+ */
10
+ /** GPU loss details, read before the lost renderer is freed. */
11
+ export interface GpuLossReport {
12
+ /**
13
+ * The longest recent submission ran for at least half the GPU watchdog, so the loss was most
14
+ * likely caused by this work and would recur.
15
+ */
16
+ readonly hung: boolean;
17
+ /** Export frame index of the longest submission, when known. */
18
+ readonly frameIndex: number | null;
19
+ /** Timeline time of the longest submission, when known. */
20
+ readonly timeTicks: bigint | null;
21
+ /** GPU time of the longest recent submission. */
22
+ readonly gpuMs: number | null;
23
+ /** One-line message for the user. */
24
+ readonly message: string;
25
+ }
26
+ /** Renderer and surface to use after a loss. */
27
+ export interface RecoveryStep {
28
+ /** `gpu` uses WebGPU, else WebGL2, as the browser now offers. */
29
+ readonly renderer: "gpu" | "cpu";
30
+ /**
31
+ * `"same"` reuses the lost renderer's canvas, possible only for a WebGPU canvas while an adapter
32
+ * is still offered. `"fresh"` needs a new canvas, since a canvas keeps its first context kind.
33
+ */
34
+ readonly surface: "same" | "fresh";
35
+ /** Diagnostic reason. */
36
+ readonly reason: string;
37
+ }
38
+ /** State of the lost renderer's surface after the loss. */
39
+ export interface SurfaceProbe {
40
+ /** Context kind the surface is bound to; `"none"` when no renderer held it. */
41
+ readonly kind: "webgpu" | "webgl2" | "cpu" | "none";
42
+ /** Whether `navigator.gpu.requestAdapter()` now returns an adapter in the host's context. */
43
+ readonly webgpuAdapter: boolean;
44
+ }
45
+ /** See {@link pageGpuLosses}. */
46
+ export interface PageGpuLosses {
47
+ /** Losses counted in this JavaScript realm so far. */
48
+ count(): number;
49
+ add(): void;
50
+ }
51
+ /**
52
+ * GPU losses in this JavaScript realm, stored on `globalThis` so duplicate copies of the package
53
+ * share it. {@link GpuRecoveryLadder.onLoss} counts its own losses; code that handles a loss
54
+ * outside a ladder should call `add()` and pass `count()` as the retry policy's `pageGpuLosses`.
55
+ * Losses in other tabs or realms are not counted.
56
+ */
57
+ export declare const pageGpuLosses: PageGpuLosses;
58
+ /**
59
+ * Decides recovery after each GPU loss of one host. Once it moves to the CPU it stays there, as
60
+ * reported by {@link GpuRecoveryLadder.renderer}.
61
+ */
62
+ export declare class GpuRecoveryLadder {
63
+ #private;
64
+ /**
65
+ * @param options.maxGpuLosses Page losses after which the GPU is not tried again. Default 2,
66
+ * since the browser withdraws GPU access at the next reset.
67
+ * @param options.losses Loss counter to use. Default {@link pageGpuLosses}.
68
+ * @throws RangeError When `maxGpuLosses` is not a positive integer.
69
+ */
70
+ constructor(options?: {
71
+ readonly maxGpuLosses?: number;
72
+ readonly losses?: PageGpuLosses;
73
+ });
74
+ /** Current renderer; `"cpu"` is permanent once reached. */
75
+ get renderer(): "gpu" | "cpu";
76
+ /**
77
+ * Counts the loss and decides the first step. Moves to the CPU when the loss was `hung`, recurred
78
+ * at the previous loss's time, or the page reached `maxGpuLosses`. Otherwise retries the GPU, on
79
+ * the same surface when it is WebGPU-bound and an adapter is still offered.
80
+ */
81
+ onLoss(report: GpuLossReport, surface: SurfaceProbe): RecoveryStep;
82
+ /**
83
+ * Next step after `step` failed: GPU on the same surface, GPU on a fresh one, then CPU on a fresh
84
+ * one, skipping rungs already tried for this loss. `"terminal"` after the CPU.
85
+ */
86
+ onRecoveryFailed(step: RecoveryStep, error: unknown): RecoveryStep | "terminal";
87
+ }
88
+ /**
89
+ * Parses a wasm renderer's `lossReport` JSON, or returns a plain lost-device report with
90
+ * `fallbackMessage` when there is none.
91
+ */
92
+ export declare function lossReportFromJson(json: string | undefined, fallbackMessage?: string): GpuLossReport;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Recovery decisions for a browser render host after a GPU loss.
3
+ *
4
+ * Browsers withdraw GPU access from a page after repeated GPU process resets: after the second,
5
+ * Chrome withholds WebGPU and page-canvas WebGL2 (`OffscreenCanvas` WebGL2 stays), and after the
6
+ * third nothing GPU-backed works. A loss caused by the page's own work recurs on the GPU. So the
7
+ * GPU is retried only for a first external loss; otherwise recovery moves to the CPU renderer on a
8
+ * fresh surface. Each rung is tried once per loss.
9
+ */
10
+ const LOSSES = Symbol.for("alpha2.pageGpuLosses");
11
+ /**
12
+ * GPU losses in this JavaScript realm, stored on `globalThis` so duplicate copies of the package
13
+ * share it. {@link GpuRecoveryLadder.onLoss} counts its own losses; code that handles a loss
14
+ * outside a ladder should call `add()` and pass `count()` as the retry policy's `pageGpuLosses`.
15
+ * Losses in other tabs or realms are not counted.
16
+ */
17
+ export const pageGpuLosses = Object.freeze({
18
+ count() {
19
+ const holder = globalThis;
20
+ return holder[LOSSES] ?? 0;
21
+ },
22
+ add() {
23
+ const holder = globalThis;
24
+ holder[LOSSES] = (holder[LOSSES] ?? 0) + 1;
25
+ },
26
+ });
27
+ /** Recovery rungs in order; recovery never moves back up. */
28
+ const RUNGS = ["gpu", "gpu", "cpu"];
29
+ const RUNG_SURFACES = [
30
+ "same",
31
+ "fresh",
32
+ "fresh",
33
+ ];
34
+ /**
35
+ * Decides recovery after each GPU loss of one host. Once it moves to the CPU it stays there, as
36
+ * reported by {@link GpuRecoveryLadder.renderer}.
37
+ */
38
+ export class GpuRecoveryLadder {
39
+ #maxGpuLosses;
40
+ #losses;
41
+ /** Indices into `RUNGS` tried since the last loss. */
42
+ #tried = new Set();
43
+ #lastLossTicks = null;
44
+ #renderer = "gpu";
45
+ /**
46
+ * @param options.maxGpuLosses Page losses after which the GPU is not tried again. Default 2,
47
+ * since the browser withdraws GPU access at the next reset.
48
+ * @param options.losses Loss counter to use. Default {@link pageGpuLosses}.
49
+ * @throws RangeError When `maxGpuLosses` is not a positive integer.
50
+ */
51
+ constructor(options = {}) {
52
+ const max = options.maxGpuLosses ?? 2;
53
+ if (!Number.isSafeInteger(max) || max < 1)
54
+ throw new RangeError("maxGpuLosses must be a positive integer");
55
+ this.#maxGpuLosses = max;
56
+ this.#losses = options.losses ?? pageGpuLosses;
57
+ }
58
+ /** Current renderer; `"cpu"` is permanent once reached. */
59
+ get renderer() {
60
+ return this.#renderer;
61
+ }
62
+ /**
63
+ * Counts the loss and decides the first step. Moves to the CPU when the loss was `hung`, recurred
64
+ * at the previous loss's time, or the page reached `maxGpuLosses`. Otherwise retries the GPU, on
65
+ * the same surface when it is WebGPU-bound and an adapter is still offered.
66
+ */
67
+ onLoss(report, surface) {
68
+ this.#losses.add();
69
+ this.#tried = new Set();
70
+ const recurred = report.timeTicks !== null && report.timeTicks === this.#lastLossTicks;
71
+ this.#lastLossTicks = report.timeTicks;
72
+ if (this.#renderer === "cpu")
73
+ return this.#take(2, "recovery already moved to the CPU renderer");
74
+ if (report.hung)
75
+ return this.#take(2, `the GPU was lost while this work ran ${report.gpuMs ?? "?"} ms in one submission; the same work on the GPU would stop it again`);
76
+ if (recurred)
77
+ return this.#take(2, "the GPU was lost again at the same frame");
78
+ if (this.#losses.count() >= this.#maxGpuLosses)
79
+ return this.#take(2, `the page has lost the GPU ${this.#losses.count()} times; the browser withdraws GPU access after another reset`);
80
+ if (surface.kind === "webgpu" && surface.webgpuAdapter)
81
+ return this.#take(0, "a first GPU loss: the WebGPU canvas takes a new device");
82
+ return this.#take(1, surface.kind === "webgpu"
83
+ ? "a first GPU loss, and the browser gives no WebGPU adapter now: a fresh canvas takes WebGL2"
84
+ : "a first GPU loss: a WebGL2 canvas keeps its lost context, so a fresh canvas takes the GPU");
85
+ }
86
+ /**
87
+ * Next step after `step` failed: GPU on the same surface, GPU on a fresh one, then CPU on a fresh
88
+ * one, skipping rungs already tried for this loss. `"terminal"` after the CPU.
89
+ */
90
+ onRecoveryFailed(step, error) {
91
+ const failed = RUNGS.findIndex((renderer, index) => renderer === step.renderer && RUNG_SURFACES[index] === step.surface);
92
+ const message = error instanceof Error ? error.message : String(error);
93
+ for (let next = failed + 1; next < RUNGS.length; next += 1) {
94
+ if (this.#tried.has(next))
95
+ continue;
96
+ return this.#take(next, `the ${step.renderer} renderer on the ${step.surface} surface failed (${message})`);
97
+ }
98
+ return "terminal";
99
+ }
100
+ #take(index, reason) {
101
+ this.#tried.add(index);
102
+ for (let below = 0; below < index; below += 1)
103
+ this.#tried.add(below);
104
+ const renderer = RUNGS[index];
105
+ if (renderer === "cpu")
106
+ this.#renderer = "cpu";
107
+ return Object.freeze({ renderer, surface: RUNG_SURFACES[index], reason });
108
+ }
109
+ }
110
+ /**
111
+ * Parses a wasm renderer's `lossReport` JSON, or returns a plain lost-device report with
112
+ * `fallbackMessage` when there is none.
113
+ */
114
+ export function lossReportFromJson(json, fallbackMessage = "the GPU device was lost") {
115
+ if (json === undefined)
116
+ return {
117
+ hung: false,
118
+ frameIndex: null,
119
+ timeTicks: null,
120
+ gpuMs: null,
121
+ message: fallbackMessage,
122
+ };
123
+ const value = JSON.parse(json);
124
+ const hung = value.hung === true;
125
+ const gpuMs = typeof value.gpuMs === "number" ? value.gpuMs : null;
126
+ return {
127
+ hung,
128
+ frameIndex: typeof value.frameIndex === "number" ? value.frameIndex : null,
129
+ timeTicks: typeof value.timeTicks === "string" ? BigInt(value.timeTicks) : null,
130
+ gpuMs,
131
+ message: hung
132
+ ? `the GPU device hung: one submission ran ${gpuMs} ms against a ${value.watchdogMs} ms watchdog`
133
+ : fallbackMessage,
134
+ };
135
+ }
@@ -2,19 +2,19 @@ import type { ChromaSiting } from "./chroma-siting.js";
2
2
  import type { FrameUploadReceipt } from "./effects.js";
3
3
  import type { ColorMetadata } from "./generated/project-schema.js";
4
4
  export { type ChromaSiting, chromaSitingForCodec, chromaSitingForStream, type SampleAspect, sampleAspectForStream, } from "./chroma-siting.js";
5
- /** What a planar copy carries of its frame's identity beyond the frame itself. */
5
+ /** Frame metadata a planar copy carries beyond the `VideoFrame` itself. */
6
6
  export interface PlanarFrameIdentity {
7
7
  readonly physicalTimeMicroseconds?: number;
8
8
  readonly rotation?: 0 | 90 | 180 | 270;
9
9
  readonly mirror?: boolean;
10
10
  readonly chromaSiting?: ChromaSiting;
11
11
  }
12
- /** A decoded frame copied out as planar YUV, with the color it carries. */
12
+ /** A decoded frame copied out as planar YUV. */
13
13
  export interface PlanarYuvFrame {
14
14
  readonly kind: "yuv-frame";
15
- /** WebCodecs pixel format, one of the planar formats the engine reads. */
15
+ /** WebCodecs pixel format. */
16
16
  readonly format: string;
17
- /** Size of the copied planes: the frame's visible picture. */
17
+ /** Size of the copied planes, which hold only the visible picture. */
18
18
  readonly codedWidth: number;
19
19
  readonly codedHeight: number;
20
20
  readonly data: Uint8Array;
@@ -24,115 +24,130 @@ export interface PlanarYuvFrame {
24
24
  readonly visibleRect: readonly [number, number, number, number];
25
25
  readonly color: ColorMetadata;
26
26
  readonly chromaSiting: ChromaSiting;
27
- /**
28
- * Size the picture is shown at before it turns: its pixel aspect ratio, which the engine applies.
29
- */
27
+ /** Display size before rotation; carries the pixel aspect ratio. */
30
28
  readonly displayWidth: number;
31
29
  readonly displayHeight: number;
32
30
  readonly physicalTimeMicroseconds: number;
33
31
  readonly durationMicroseconds?: number;
34
32
  /** Clockwise turn that shows the frame upright, after {@link mirror}. */
35
33
  readonly rotation?: 0 | 90 | 180 | 270;
36
- /** Whether the frame is mirrored left to right before it turns. */
34
+ /** Mirror left to right before rotating. */
37
35
  readonly mirror?: boolean;
38
36
  }
39
37
  /** Engine surface that converts planar YUV with the project's color pipeline. */
40
38
  export interface PlanarYuvEngine {
41
- /**
42
- * Uploads one planar frame for `sourceId` at `mediaTimeTicks`, to be
43
- * converted with the project's color pipeline and shown upright at
44
- * `outputWidth` x `outputHeight`.
45
- */
39
+ /** Uploads one planar frame, shown upright at `outputWidth` by `outputHeight`. */
46
40
  uploadYuvFrame(sourceId: string, mediaTimeTicks: bigint, format: string, codedWidth: number, codedHeight: number, data: Uint8Array, layout: Uint32Array, visibleRect: Uint32Array,
47
- /**
48
- * Size the visible picture is shown at before it turns (a `VideoFrame`'s display size): its
49
- * pixel aspect ratio.
50
- */
41
+ /** Display size before rotation; carries the pixel aspect ratio. */
51
42
  displayWidth: number, displayHeight: number, colorJson: string, chromaSiting: ChromaSiting, outputWidth: number, outputHeight: number, rotationDegrees: number, mirror: boolean): FrameUploadReceipt;
52
43
  }
53
44
  /**
54
- * The engine's color description of a WebCodecs color space.
55
- *
56
- * Unspecified parts take the SDR BT.709 limited-range defaults; a PQ or HLG
57
- * transfer makes the signal HDR.
45
+ * Converts a WebCodecs color space to engine color metadata. Unspecified parts default to SDR
46
+ * BT.709 limited range; a PQ or HLG transfer marks the signal HDR.
58
47
  */
59
48
  export declare function colorMetadataFromVideoColorSpace(space: VideoColorSpaceInit | null | undefined): ColorMetadata;
60
49
  /**
61
- * How a host turns decoded SDR `VideoFrame`s into the engine's pixels.
50
+ * How a host converts decoded SDR `VideoFrame`s.
62
51
  *
63
- * `"engine"` (the default) copies each frame that has a planar format the engine reads out with
64
- * `copyTo` and converts it with the engine's shader, as a native host converts the same stream:
65
- * the frame's own color space, and the chroma siting its decoder reports (`chromaSiting`). A
66
- * frame without such a format (an opaque hardware frame) still goes through the browser.
67
- * `"browser"` imports SDR frames as textures instead, which saves the copy (in Chrome on a desktop
68
- * GPU about 1 ms a 1080p frame, 4 to 5 ms a 4K one) but leaves the conversion to the browser, which
69
- * does not read the stream's siting: Chrome converts H.264 and HEVC chroma, sited left, as if
70
- * centered, so every sharp chroma edge lands apart from a native export's. HDR frames, and frames
71
- * of a source whose color the project declares, are the engine's either way.
52
+ * `"engine"` (default) copies planar frames with `copyTo` and converts them in the engine's shader,
53
+ * matching a native export; opaque hardware frames still go through the browser. `"browser"`
54
+ * imports SDR frames as textures, saving the copy (roughly 1 ms per 1080p frame, 4 to 5 ms per 4K
55
+ * frame on a desktop GPU) but ignoring chroma siting, so chroma edges differ from a native export.
56
+ * HDR frames and sources with project-declared color always use the engine.
72
57
  */
73
58
  export type VideoConversion = "engine" | "browser";
74
59
  /**
75
- * A frame with no planar YUV format the engine reads: an opaque frame (a hardware frame the
76
- * browser does not map to the CPU, `format` null) or an RGB one. Reading it again cannot help;
77
- * decoding it again in software can.
60
+ * The frame has no planar YUV format the engine reads: it is opaque (`format` null) or RGB.
61
+ * Retrying the read cannot help.
78
62
  */
79
63
  export declare class NonPlanarVideoFrameError extends Error {
64
+ readonly code = "NON_PLANAR_FRAME";
80
65
  readonly format: VideoPixelFormat | null;
81
66
  constructor(format: VideoPixelFormat | null);
82
67
  }
83
- /** Whether `frame` has a planar format the engine converts (`copyPlanarYuvFrame` can copy it). */
68
+ /** Facts about a track the browser could not decode, used to build the refusal message. */
69
+ export interface TrackDecodeFacts {
70
+ readonly kind: "video" | "audio";
71
+ /** WebCodecs string (`hvc1.2.4.L93.B0`) or short name; null when unknown. */
72
+ readonly codec: string | null;
73
+ readonly bitDepth?: number;
74
+ readonly chroma?: "420" | "422" | "444";
75
+ /** Transfer (`pq`, `hlg`, `bt709`); null when undeclared. */
76
+ readonly transfer?: string | null;
77
+ readonly channels?: number;
78
+ /** Speaker names (`FL FR FC`). */
79
+ readonly layout?: readonly string[];
80
+ /** Decoded frame format; null for an opaque frame. */
81
+ readonly frameFormat?: VideoPixelFormat | null;
82
+ readonly softwareDecoder?: "none" | "opaque" | "planar";
83
+ /** The browser's error, for diagnostics only. */
84
+ readonly browserError?: string;
85
+ }
86
+ /** A refused track is invalid input, since the same file always fails the same way. */
87
+ export interface DecodeRefusalFailure {
88
+ readonly code: "INVALID_INPUT";
89
+ readonly phase: "decode";
90
+ readonly stage: "decode-unavailable" | "planar-decode-unavailable";
91
+ }
92
+ /** This browser cannot decode the track at all. */
93
+ export declare class DecodeUnavailableError extends Error {
94
+ readonly code = "DECODE_UNAVAILABLE";
95
+ readonly facts: TrackDecodeFacts;
96
+ readonly failure: DecodeRefusalFailure;
97
+ constructor(message: string, facts: TrackDecodeFacts, options?: ErrorOptions);
98
+ }
99
+ /**
100
+ * The browser decodes the track only to opaque or RGB frames and has no planar software decoder,
101
+ * but the source needs planes (HDR or project-declared color).
102
+ */
103
+ export declare class PlanarDecodeUnavailableError extends Error {
104
+ readonly code = "PLANAR_DECODE_UNAVAILABLE";
105
+ readonly facts: TrackDecodeFacts;
106
+ readonly failure: DecodeRefusalFailure;
107
+ constructor(message: string, facts: TrackDecodeFacts, options?: ErrorOptions);
108
+ }
109
+ /** Human-readable codec name: `hvc1.2.4.L93.B0` is `HEVC`. */
110
+ export declare function codecName(codec: string | null): string;
111
+ /** Human-readable bit depth and chroma, such as `10-bit` and `4:2:2`. */
112
+ export declare function pictureDetails(facts: TrackDecodeFacts): string[];
113
+ /** User-facing refusal message built from `facts` alone, with a suggested workaround. */
114
+ export declare function decodeRefusalMessage(name: string, facts: TrackDecodeFacts): string;
115
+ /** Whether `copyPlanarYuvFrame` can copy `frame`. */
84
116
  export declare function isPlanarVideoFrame(frame: VideoFrame): boolean;
85
- /** Whether a decoded frame's own color space says it is HDR. */
117
+ /** Whether the frame's own color space is HDR. */
86
118
  export declare function isHdrVideoFrame(frame: VideoFrame): boolean;
87
119
  /**
88
- * Buffers planar copies reuse: a 4K 10-bit frame is 25 MB, which a fresh allocation zero-fills
89
- * and the garbage collector reclaims at the frame rate. A copy takes a buffer with
90
- * {@link PlanarCopyPool.acquire} and gives it back with {@link PlanarCopyPool.release} once its
91
- * upload has taken the bytes (an engine upload copies them into wasm memory before it returns).
92
- * Copies that overlap each take their own buffer.
120
+ * Reusable buffers for planar copies, avoiding a fresh zero-filled allocation per frame (25 MB for
121
+ * a 4K 10-bit frame). Release a buffer once its upload returns, since the engine copies the bytes
122
+ * into wasm memory.
93
123
  */
94
124
  export declare class PlanarCopyPool {
95
125
  #private;
96
- /** Keeps at most `maxFree` (default 2) buffers between copies. */
126
+ /** Keeps at most `maxFree` idle buffers. */
97
127
  constructor(maxFree?: number);
98
- /** `bytes` bytes to copy into: a kept buffer large enough, or a new one. */
128
+ /** Returns a view of `bytes` bytes over a kept buffer, or a new one. */
99
129
  acquire(bytes: number): Uint8Array;
100
- /** Gives back the buffer under `data`; nothing may read `data` afterwards. */
130
+ /** Returns the buffer under `data` to the pool; `data` must not be used afterwards. */
101
131
  release(data: Uint8Array): void;
102
- /** Drops every kept buffer. */
103
132
  clear(): void;
104
- /** Bytes the kept buffers hold. */
133
+ /** Total bytes of idle buffers. */
105
134
  get keptBytes(): number;
106
135
  }
107
136
  /**
108
- * Copies `frame` out as planar YUV and closes it.
109
- *
110
- * `declared` is the color the project declares for the source, which wins
111
- * over the frame's own color space, as it does natively. A frame without a
112
- * CPU-readable planar format (a hardware frame the browser will not map) is
113
- * refused rather than converted by the browser.
137
+ * Copies `frame` out as planar YUV and always closes it. `declared` color overrides the frame's own
138
+ * color space.
114
139
  *
115
- * `frame` is closed whether the copy succeeds or not. Rejects with
116
- * {@link NonPlanarVideoFrameError} when the frame has no planar format the
117
- * engine reads, and otherwise when it has no visible rectangle or `copyTo`
118
- * fails.
140
+ * With `pool`, `data` comes from the pool and the caller releases it after uploading.
119
141
  *
120
- * With `pool`, the copy's `data` is a buffer from it, which the caller gives back with
121
- * {@link PlanarCopyPool.release} after uploading; a failed copy gives it back itself.
142
+ * Rejects with {@link NonPlanarVideoFrameError} for a frame without a planar format, and otherwise
143
+ * when it has no visible rectangle or `copyTo` fails.
122
144
  */
123
145
  export declare function copyPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
124
146
  /**
125
- * {@link copyPlanarYuvFrame} without closing `frame`: the caller owns it whether the copy succeeds
126
- * or not, so a frame whose planes the browser could not read back can be read again. Rejects as
127
- * {@link copyPlanarYuvFrame} does, with {@link NonPlanarVideoFrameError} for a frame no read can
128
- * copy; with `pool`, a failed copy gives its buffer back.
147
+ * {@link copyPlanarYuvFrame} without closing `frame`, so a failed readback can be retried.
129
148
  *
130
149
  * @internal For `FrameSupply`.
131
150
  */
132
151
  export declare function readPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
133
- /**
134
- * Uploads a planar frame for the engine to convert and present at
135
- * `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
136
- * the engine's `uploadYuvFrame` throws.
137
- */
152
+ /** Uploads a planar frame, shown upright at `outputWidth` by `outputHeight`. */
138
153
  export declare function uploadPlanarYuvFrame(engine: PlanarYuvEngine, sourceId: string, mediaTimeTicks: bigint, frame: PlanarYuvFrame, outputWidth: number, outputHeight: number): FrameUploadReceipt;