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
@@ -1,24 +1,17 @@
1
1
  /**
2
- * Where a browser export's encoded bytes go.
2
+ * Destinations for a browser export's encoded bytes.
3
3
  *
4
- * The default is a file: bytes are written as the muxer produces them, a bounded queue in between,
5
- * so the encoded video never accumulates in memory and finishing adds no copy of it. Keeping an
6
- * export in memory is a separate, explicit mode for small outputs, sized before the export starts.
4
+ * The default streams to a file through a bounded queue, so the output never accumulates in
5
+ * memory. In-memory output is an explicit mode for small exports, sized before the export starts.
7
6
  */
8
7
  import { type ExportFailure } from "./export-failure.js";
9
- /**
10
- * One positioned write, as mediabunny's `StreamTarget` emits it and
11
- * `FileSystemWritableFileStream.write` takes it.
12
- */
8
+ /** A positioned write, as emitted by mediabunny's `StreamTarget`. */
13
9
  export interface PositionedWrite {
14
10
  readonly type: "write";
15
11
  readonly data: Uint8Array;
16
12
  readonly position: number;
17
13
  }
18
- /**
19
- * A file that takes positioned writes: a `FileSystemWritableFileStream` (a user-picked file or an
20
- * origin-private one), or anything shaped like it.
21
- */
14
+ /** A file that takes positioned writes, such as a `FileSystemWritableFileStream`. */
22
15
  export interface PositionalFile {
23
16
  /** Writes `chunk.data` at `chunk.position`; a rejection fails the export. */
24
17
  write(chunk: PositionedWrite): Promise<void>;
@@ -27,29 +20,28 @@ export interface PositionalFile {
27
20
  /** Discards the file instead of committing it. */
28
21
  abort?(reason?: unknown): Promise<void>;
29
22
  }
30
- /** What a file destination has done so far. */
23
+ /** Progress of a file destination. */
31
24
  export interface FileDestinationStats {
32
25
  /** Bytes handed to the file, counting rewrites of earlier positions. */
33
26
  readonly bytesWritten: number;
34
- /** The file's length: the furthest position written. */
27
+ /** Furthest position written. */
35
28
  readonly size: number;
36
- /** The most bytes ever queued between the muxer and the file. */
29
+ /** Peak bytes queued between the muxer and the file. */
37
30
  readonly peakQueuedBytes: number;
38
- /** The queue's bound: past it, the muxer waits for the file. */
31
+ /** Queue bound; past it the muxer waits for the file. */
39
32
  readonly maxQueuedBytes: number;
40
33
  }
41
34
  /** Bytes queued for the file before the muxer is made to wait. */
42
35
  export declare const DEFAULT_MAX_QUEUED_BYTES: number;
43
36
  /**
44
- * A seekable file as an export destination.
37
+ * A seekable file as an export destination. `writable` is the stream for mediabunny's
38
+ * `StreamTarget`.
45
39
  *
46
- * `writable` is the stream mediabunny's `StreamTarget` writes into. The
47
- * constructor throws a `RangeError` when `maxQueuedBytes` (default
48
- * {@link DEFAULT_MAX_QUEUED_BYTES}) is not a positive safe integer. Its queue is bounded in bytes,
49
- * and mediabunny waits while it is full, so a slow disk slows the export instead of growing memory;
50
- * the encoder and the renderer wait behind the muxer. A write the file refuses fails the export at
51
- * step `publish`, as `STORAGE_QUOTA_EXCEEDED` when the browser says the quota is exhausted and
52
- * `OUTPUT_IO_FAILED` otherwise.
40
+ * The queue is bounded by `maxQueuedBytes` (default {@link DEFAULT_MAX_QUEUED_BYTES}), so a slow
41
+ * disk slows the export instead of growing memory. A refused write fails the export in phase
42
+ * `publish` with `STORAGE_QUOTA_EXCEEDED` or `OUTPUT_IO_FAILED`.
43
+ *
44
+ * @throws RangeError When `maxQueuedBytes` is not a positive safe integer.
53
45
  */
54
46
  export declare class WritableFileDestination {
55
47
  #private;
@@ -57,35 +49,27 @@ export declare class WritableFileDestination {
57
49
  constructor(file: PositionalFile, options?: {
58
50
  readonly maxQueuedBytes?: number;
59
51
  });
60
- /** A snapshot of what has been written and queued so far. */
61
52
  get stats(): FileDestinationStats;
62
53
  /**
63
- * Discards the file: writes still queued are dropped, and a close the muxer sends afterwards does
64
- * not commit it. A `FileSystemWritableFileStream` then leaves the file as it was before the
65
- * export.
54
+ * Discards the file. Queued writes are dropped and a later close from the muxer does not commit
55
+ * it.
66
56
  */
67
57
  abort(reason?: unknown): Promise<void>;
68
- /** The failure the file reported, if it refused a write or its close. */
58
+ /** Set when the file refused a write or the close. */
69
59
  get failure(): ExportFailure | undefined;
70
60
  }
71
61
  /**
72
- * What an in-memory output of `estimatedBytes` can hold at its peak.
62
+ * Peak memory of an in-memory output of `estimatedBytes`.
73
63
  *
74
- * A growing `ArrayBuffer` doubles, so its capacity reaches up to twice the output; without in-place
75
- * resizing, the old and new buffers briefly coexist, which costs no more than that. Finishing
76
- * copies the used part out (one more output), and handing it on as a `Blob` copies it once more.
77
- * Four times the output, then, and the estimate itself is a guess about a variable-rate encoder,
78
- * which `margin` covers.
64
+ * A doubling `ArrayBuffer` reaches up to twice the output, finishing copies it once and the `Blob`
65
+ * copies it again, so four output-sized buffers. `margin` covers the variable-rate estimate.
79
66
  */
80
67
  export declare function memoryOutputPeakBytes(estimatedBytes: number, margin?: number): number;
81
- /** How many output-sized buffers an in-memory output can hold at once. */
68
+ /** Output-sized buffers an in-memory output can hold at once. */
82
69
  export declare const MEMORY_OUTPUT_COPIES = 4;
83
- /** How far a variable-rate encoder is allowed past its estimated size. */
70
+ /** Allowed overshoot of a variable-rate encoder past its estimated size. */
84
71
  export declare const MEMORY_OUTPUT_MARGIN = 1.5;
85
- /**
86
- * The size an export's encoded output is expected to reach: the rates it encodes at over its
87
- * duration, plus a fixed allowance for the container.
88
- */
72
+ /** Expected output size: bitrates times duration, plus a fixed container allowance. */
89
73
  export declare function estimatedOutputBytes(options: {
90
74
  readonly durationSeconds: number;
91
75
  readonly videoBitrate: number;
@@ -1,23 +1,21 @@
1
1
  /**
2
- * Where a browser export's encoded bytes go.
2
+ * Destinations for a browser export's encoded bytes.
3
3
  *
4
- * The default is a file: bytes are written as the muxer produces them, a bounded queue in between,
5
- * so the encoded video never accumulates in memory and finishing adds no copy of it. Keeping an
6
- * export in memory is a separate, explicit mode for small outputs, sized before the export starts.
4
+ * The default streams to a file through a bounded queue, so the output never accumulates in
5
+ * memory. In-memory output is an explicit mode for small exports, sized before the export starts.
7
6
  */
8
7
  import { ExportFailureError } from "./export-failure.js";
9
8
  /** Bytes queued for the file before the muxer is made to wait. */
10
9
  export const DEFAULT_MAX_QUEUED_BYTES = 8 * 1024 * 1024;
11
10
  /**
12
- * A seekable file as an export destination.
11
+ * A seekable file as an export destination. `writable` is the stream for mediabunny's
12
+ * `StreamTarget`.
13
13
  *
14
- * `writable` is the stream mediabunny's `StreamTarget` writes into. The
15
- * constructor throws a `RangeError` when `maxQueuedBytes` (default
16
- * {@link DEFAULT_MAX_QUEUED_BYTES}) is not a positive safe integer. Its queue is bounded in bytes,
17
- * and mediabunny waits while it is full, so a slow disk slows the export instead of growing memory;
18
- * the encoder and the renderer wait behind the muxer. A write the file refuses fails the export at
19
- * step `publish`, as `STORAGE_QUOTA_EXCEEDED` when the browser says the quota is exhausted and
20
- * `OUTPUT_IO_FAILED` otherwise.
14
+ * The queue is bounded by `maxQueuedBytes` (default {@link DEFAULT_MAX_QUEUED_BYTES}), so a slow
15
+ * disk slows the export instead of growing memory. A refused write fails the export in phase
16
+ * `publish` with `STORAGE_QUOTA_EXCEEDED` or `OUTPUT_IO_FAILED`.
17
+ *
18
+ * @throws RangeError When `maxQueuedBytes` is not a positive safe integer.
21
19
  */
22
20
  export class WritableFileDestination {
23
21
  writable;
@@ -58,8 +56,7 @@ export class WritableFileDestination {
58
56
  this.#size = Math.max(this.#size, chunk.position + chunk.data.byteLength);
59
57
  },
60
58
  close: async () => {
61
- // A muxer cancelled after `abort` still closes its stream; the file was already
62
- // discarded.
59
+ // A muxer cancelled after `abort` still closes its stream.
63
60
  if (this.#aborted)
64
61
  return;
65
62
  try {
@@ -81,7 +78,6 @@ export class WritableFileDestination {
81
78
  },
82
79
  });
83
80
  }
84
- /** A snapshot of what has been written and queued so far. */
85
81
  get stats() {
86
82
  return {
87
83
  bytesWritten: this.#bytesWritten,
@@ -91,9 +87,8 @@ export class WritableFileDestination {
91
87
  };
92
88
  }
93
89
  /**
94
- * Discards the file: writes still queued are dropped, and a close the muxer sends afterwards does
95
- * not commit it. A `FileSystemWritableFileStream` then leaves the file as it was before the
96
- * export.
90
+ * Discards the file. Queued writes are dropped and a later close from the muxer does not commit
91
+ * it.
97
92
  */
98
93
  async abort(reason) {
99
94
  if (this.#aborted)
@@ -101,7 +96,7 @@ export class WritableFileDestination {
101
96
  this.#aborted = true;
102
97
  await this.#file.abort?.(reason);
103
98
  }
104
- /** The failure the file reported, if it refused a write or its close. */
99
+ /** Set when the file refused a write or the close. */
105
100
  get failure() {
106
101
  return this.#failure?.failure;
107
102
  }
@@ -122,29 +117,22 @@ function writeFailure(error) {
122
117
  }, { cause: error });
123
118
  }
124
119
  /**
125
- * What an in-memory output of `estimatedBytes` can hold at its peak.
120
+ * Peak memory of an in-memory output of `estimatedBytes`.
126
121
  *
127
- * A growing `ArrayBuffer` doubles, so its capacity reaches up to twice the output; without in-place
128
- * resizing, the old and new buffers briefly coexist, which costs no more than that. Finishing
129
- * copies the used part out (one more output), and handing it on as a `Blob` copies it once more.
130
- * Four times the output, then, and the estimate itself is a guess about a variable-rate encoder,
131
- * which `margin` covers.
122
+ * A doubling `ArrayBuffer` reaches up to twice the output, finishing copies it once and the `Blob`
123
+ * copies it again, so four output-sized buffers. `margin` covers the variable-rate estimate.
132
124
  */
133
125
  export function memoryOutputPeakBytes(estimatedBytes, margin = MEMORY_OUTPUT_MARGIN) {
134
126
  return Math.ceil(estimatedBytes * margin) * MEMORY_OUTPUT_COPIES;
135
127
  }
136
- /** How many output-sized buffers an in-memory output can hold at once. */
128
+ /** Output-sized buffers an in-memory output can hold at once. */
137
129
  export const MEMORY_OUTPUT_COPIES = 4;
138
- /** How far a variable-rate encoder is allowed past its estimated size. */
130
+ /** Allowed overshoot of a variable-rate encoder past its estimated size. */
139
131
  export const MEMORY_OUTPUT_MARGIN = 1.5;
140
- /**
141
- * The size an export's encoded output is expected to reach: the rates it encodes at over its
142
- * duration, plus a fixed allowance for the container.
143
- */
132
+ /** Expected output size: bitrates times duration, plus a fixed container allowance. */
144
133
  export function estimatedOutputBytes(options) {
145
134
  const bitsPerSecond = options.videoBitrate + (options.audioBitrate ?? 0);
146
135
  return (Math.ceil((bitsPerSecond * Math.max(0, options.durationSeconds)) / 8) +
147
136
  CONTAINER_ALLOWANCE_BYTES);
148
137
  }
149
- /** Container overhead an estimate allows for: headers and the sample tables. */
150
138
  const CONTAINER_ALLOWANCE_BYTES = 1024 * 1024;
@@ -1,42 +1,28 @@
1
1
  /**
2
- * The shape every alpha2 export failure is reported in, whichever process and backend it came from,
3
- * and the rules for classifying one.
2
+ * The export failure shape shared by every process and backend, and the rules for classifying one.
4
3
  *
5
- * A class is named only on evidence. A refused GPU mapping carries no cause, so it stays
6
- * `READBACK_FAILED` unless the device itself reported running out of memory or being lost; a
7
- * JavaScript `RangeError` is an allocation failure only when the engine said so in its own words. A
8
- * classification that cannot be made is `UNKNOWN`, never a guess.
4
+ * A class is assigned only on evidence; otherwise the failure is `UNKNOWN`. For example, a refused
5
+ * GPU mapping stays `READBACK_FAILED` unless the device reported memory exhaustion or loss.
9
6
  */
10
7
  /**
11
- * What an export failure is evidence of. `RESOURCE_LIMIT` is a refusal, not a failure: the export
12
- * would need more than a budget allows, and was stopped before it could exhaust it.
13
- */
14
- export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "CANCELLED" | "UNKNOWN";
15
- /**
16
- * The export step a failure belongs to. Steps overlap in a pipelined export, so each event names
17
- * its own step.
8
+ * Failure class. `RESOURCE_LIMIT` means the export was stopped before exceeding a budget.
9
+ * `RESOURCE_BUSY` means a device is held by other work (for example all hardware encoder
10
+ * sessions) and may free up later.
18
11
  */
12
+ export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "DEVICE_HUNG" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "RESOURCE_BUSY" | "CANCELLED" | "UNKNOWN";
13
+ /** Export step a failure belongs to. Steps overlap in a pipelined export. */
19
14
  export type ExportPhase = "prepare" | "decode" | "upload" | "render" | "readback" | "encode" | "mux" | "publish" | "download" | "cleanup";
20
- /**
21
- * Which process reported the failure: `node` is `@alpha2-sh/node` and `python` the `alpha2` Python
22
- * package, each a client of the native host.
23
- */
15
+ /** Reporting process. `node` is `@alpha2-sh/node` and `python` the `alpha2` Python package. */
24
16
  export type ExportOrigin = "browser" | "node" | "python" | "native-host";
25
- /**
26
- * The memory a failure's evidence names. `js` is JavaScript `ArrayBuffer` and object memory, `wasm`
27
- * the engine's linear memory; neither is the GPU's.
28
- */
17
+ /** Memory named by the evidence. `js` is the JavaScript heap; `wasm` the engine's linear memory. */
29
18
  export type MemoryResource = "cpu" | "gpu" | "js" | "wasm" | "unknown";
30
- /** A later event recorded beside a failure without replacing it. */
19
+ /** A later event recorded alongside a failure without replacing it. */
31
20
  export interface ExportFailureNote {
32
21
  readonly code: ExportFailureCode;
33
22
  readonly phase: ExportPhase;
34
23
  readonly message: string;
35
24
  }
36
- /**
37
- * One classified export failure, serializable as JSON so it crosses worker and process boundaries
38
- * unchanged.
39
- */
25
+ /** A classified export failure. JSON-serializable so it crosses worker and process boundaries. */
40
26
  export interface ExportFailure {
41
27
  readonly code: ExportFailureCode;
42
28
  readonly message: string;
@@ -45,36 +31,37 @@ export interface ExportFailure {
45
31
  /** `browser-webgpu`, `browser-webgl`, `native`, or `unknown`. */
46
32
  readonly backend: string;
47
33
  readonly phase: ExportPhase;
48
- /** The step inside the phase, such as a readback's `map-failed`. */
34
+ /** Step within the phase, such as a readback's `map-failed`. */
49
35
  readonly stage?: string | null;
50
36
  readonly frameIndex?: number | null;
51
- /** Timeline ticks as a decimal string, so no value loses precision. */
37
+ /** Timeline ticks as a decimal string to keep full precision. */
52
38
  readonly timeTicks?: string | null;
53
39
  readonly resource: MemoryResource;
54
40
  /** Bytes the failed allocation asked for, when known. */
55
41
  readonly requestedBytes?: number | null;
56
- /** The code the native host's protocol error had. */
42
+ /** Original native host protocol error code. */
57
43
  readonly hostCode?: string;
44
+ /** For `RESOURCE_BUSY`, how long to wait before retrying. */
45
+ readonly retryAfterMs?: number;
58
46
  readonly jobId?: string;
59
47
  readonly attemptId?: string;
60
48
  readonly stack?: string;
61
- /** The last part of the native host's standard error. */
49
+ /** Tail of the native host's standard error. */
62
50
  readonly stderr?: string;
63
51
  readonly exitCode?: number | null;
64
52
  readonly signal?: string | null;
65
53
  /** Device events, memory, paths, and environment recorded up to the failure. */
66
54
  readonly diagnostics?: Readonly<Record<string, unknown>>;
67
- /** Failures that followed the first, such as a cleanup that also failed. */
55
+ /** Later failures, such as a failed cleanup. */
68
56
  readonly secondary?: readonly ExportFailureNote[];
69
57
  }
70
58
  /** An error carrying a classified {@link ExportFailure}. */
71
59
  export declare class ExportFailureError extends Error {
72
60
  readonly failure: ExportFailure;
73
61
  constructor(failure: ExportFailure, options?: ErrorOptions);
74
- /** The failure's class, for callers that switch on `error.code`. */
75
62
  get code(): ExportFailureCode;
76
63
  }
77
- /** Where a browser export was when something went wrong. */
64
+ /** Browser export state at the time of a failure. */
78
65
  export interface BrowserFailureContext {
79
66
  readonly phase: ExportPhase;
80
67
  readonly backend?: string;
@@ -82,29 +69,23 @@ export interface BrowserFailureContext {
82
69
  readonly requestedBytes?: number;
83
70
  readonly diagnostics?: Readonly<Record<string, unknown>>;
84
71
  }
85
- /** The failure `error` carries, if it carries a well-formed one. */
72
+ /** The well-formed failure `error` carries, if any. */
86
73
  export declare function failureOf(error: unknown): ExportFailure | undefined;
87
74
  /**
88
75
  * Classifies an error a browser export threw at `context`.
89
76
  *
90
- * An error that already carries a complete failure (one with an `origin`) is returned as it is.
91
- * An engine readback error arrives with a partial `failure` of its own (the class the device
92
- * evidence supports, the stage, the frame), as does an upload the export's working set does not
93
- * fit (`RESOURCE_LIMIT` at stage `working-set-over-budget`, with the bytes it needs), and keeps it;
94
- * anything else is classified here from its type and the platform's own words.
77
+ * A complete failure (one with an `origin`) is returned as is. A partial engine `failure` (such as
78
+ * a readback error or `RESOURCE_LIMIT` at `working-set-over-budget`) keeps its fields. Anything
79
+ * else is classified from its type and message.
95
80
  */
96
81
  export declare function classifyBrowserFailure(error: unknown, context: BrowserFailureContext): ExportFailure;
97
- /** A failure class and the memory region its evidence names. */
98
82
  export interface FailureClass {
99
83
  readonly code: ExportFailureCode;
100
84
  readonly resource: MemoryResource;
101
85
  }
102
- /**
103
- * The class `code`, a protocol or `@alpha2-sh/node` error code, is evidence of on its own; `UNKNOWN`
104
- * for any other.
105
- */
86
+ /** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
106
87
  export declare function failureClassOfCode(code: unknown): FailureClass;
107
- /** What is known where a coded error with no failure of its own is reported. */
88
+ /** Context for {@link failureForCode}. */
108
89
  export interface CodeFailureContext {
109
90
  readonly message: string;
110
91
  readonly origin: ExportOrigin;
@@ -117,25 +98,19 @@ export interface CodeFailureContext {
117
98
  readonly diagnostics?: Readonly<Record<string, unknown>>;
118
99
  }
119
100
  /**
120
- * The failure an error with protocol or `@alpha2-sh/node` code `code` and no failure of its own
121
- * reports: classified by the code (see {@link failureClassOfCode}), which it keeps as `hostCode`;
122
- * `UNKNOWN` without one. A process boundary that receives such an error (`@alpha2-sh/node`, a service
123
- * relaying it) classifies it with this, never by its own default.
101
+ * Builds a failure for an error that has only a protocol or `@alpha2-sh/node` code, classified by
102
+ * {@link failureClassOfCode} and keeping the code as `hostCode`. Process boundaries relaying such
103
+ * errors should classify with this rather than their own defaults.
124
104
  */
125
105
  export declare function failureForCode(code: string | undefined, context: CodeFailureContext): ExportFailure;
126
106
  /**
127
- * Records `later` beside `failure` without replacing it: the first failure is the cause. Returns a
128
- * new failure that keeps the latest 8 secondary notes; `failure` is not modified.
107
+ * Returns a copy of `failure` with `later` appended to its secondary notes (latest 8 kept). The
108
+ * first failure remains the cause.
129
109
  */
130
110
  export declare function withSecondaryFailure(failure: ExportFailure, later: ExportFailureNote): ExportFailure;
131
111
  /**
132
- * Records that cleaning up after `error` failed too, without replacing it: an export runner calls
133
- * this when its sink's `abort` throws, then rethrows `error` itself.
134
- *
135
- * An {@link ExportFailureError} gains a `cleanup` note in its `failure` (see
136
- * {@link withSecondaryFailure}), classified from `cleanup`; the error stays the same object, so a
137
- * caller comparing it with an abort signal's reason still finds it. Any other error has no
138
- * classified failure to note it in, and the cleanup failure is dropped: the first failure is the
139
- * cause.
112
+ * Records a cleanup failure on `error` without replacing it. An {@link ExportFailureError} gains a
113
+ * `cleanup` note in place, so identity comparisons with an abort reason still hold. Other errors
114
+ * are left unchanged and the cleanup failure is dropped.
140
115
  */
141
116
  export declare function recordCleanupFailure(error: unknown, cleanup: unknown): void;
@@ -1,11 +1,8 @@
1
1
  /**
2
- * The shape every alpha2 export failure is reported in, whichever process and backend it came from,
3
- * and the rules for classifying one.
2
+ * The export failure shape shared by every process and backend, and the rules for classifying one.
4
3
  *
5
- * A class is named only on evidence. A refused GPU mapping carries no cause, so it stays
6
- * `READBACK_FAILED` unless the device itself reported running out of memory or being lost; a
7
- * JavaScript `RangeError` is an allocation failure only when the engine said so in its own words. A
8
- * classification that cannot be made is `UNKNOWN`, never a guess.
4
+ * A class is assigned only on evidence; otherwise the failure is `UNKNOWN`. For example, a refused
5
+ * GPU mapping stays `READBACK_FAILED` unless the device reported memory exhaustion or loss.
9
6
  */
10
7
  /** An error carrying a classified {@link ExportFailure}. */
11
8
  export class ExportFailureError extends Error {
@@ -15,7 +12,6 @@ export class ExportFailureError extends Error {
15
12
  this.name = "ExportFailureError";
16
13
  this.failure = failure;
17
14
  }
18
- /** The failure's class, for callers that switch on `error.code`. */
19
15
  get code() {
20
16
  return this.failure.code;
21
17
  }
@@ -36,6 +32,7 @@ const CODES = new Set([
36
32
  "OUT_OF_MEMORY",
37
33
  "ALLOCATION_FAILED",
38
34
  "DEVICE_LOST",
35
+ "DEVICE_HUNG",
39
36
  "READBACK_FAILED",
40
37
  "GPU_TIMEOUT",
41
38
  "VALIDATION_FAILED",
@@ -44,10 +41,11 @@ const CODES = new Set([
44
41
  "OUTPUT_IO_FAILED",
45
42
  "STORAGE_QUOTA_EXCEEDED",
46
43
  "RESOURCE_LIMIT",
44
+ "RESOURCE_BUSY",
47
45
  "CANCELLED",
48
46
  "UNKNOWN",
49
47
  ]);
50
- /** The failure `error` carries, if it carries a well-formed one. */
48
+ /** The well-formed failure `error` carries, if any. */
51
49
  export function failureOf(error) {
52
50
  const failure = error?.failure;
53
51
  if (!isRecord(failure))
@@ -62,11 +60,9 @@ export function failureOf(error) {
62
60
  /**
63
61
  * Classifies an error a browser export threw at `context`.
64
62
  *
65
- * An error that already carries a complete failure (one with an `origin`) is returned as it is.
66
- * An engine readback error arrives with a partial `failure` of its own (the class the device
67
- * evidence supports, the stage, the frame), as does an upload the export's working set does not
68
- * fit (`RESOURCE_LIMIT` at stage `working-set-over-budget`, with the bytes it needs), and keeps it;
69
- * anything else is classified here from its type and the platform's own words.
63
+ * A complete failure (one with an `origin`) is returned as is. A partial engine `failure` (such as
64
+ * a readback error or `RESOURCE_LIMIT` at `working-set-over-budget`) keeps its fields. Anything
65
+ * else is classified from its type and message.
70
66
  */
71
67
  export function classifyBrowserFailure(error, context) {
72
68
  const existing = failureOf(error);
@@ -109,13 +105,11 @@ export function classifyBrowserFailure(error, context) {
109
105
  const permanent = { code: "INVALID_INPUT", resource: "unknown" };
110
106
  const unknown = { code: "UNKNOWN", resource: "unknown" };
111
107
  /**
112
- * The class each error code is evidence of on its own: the native host protocol's codes, which
113
- * `alpha2-wasm` shares, as the host's own `classify_failure` reads them, and the codes only
114
- * `@alpha2-sh/node` makes. `tests/cases/failure-classes.json` holds the same table, and the host's tests and
115
- * these read it, so the two cannot drift.
108
+ * Failure class of each error code: native host protocol codes (shared by `alpha2-wasm`), codes
109
+ * only `@alpha2-sh/node` produces, and browser decode refusals. Must match the host's
110
+ * `classify_failure`; `tests/cases/failure-classes.json` checks both.
116
111
  */
117
112
  const CODE_CLASSES = Object.freeze({
118
- // The request would meet the same refusal again.
119
113
  UNSUPPORTED_PROTOCOL: permanent,
120
114
  INVALID_REQUEST: permanent,
121
115
  INVALID_INPUT: permanent,
@@ -128,44 +122,52 @@ const CODE_CLASSES = Object.freeze({
128
122
  GPU_OUTPUT_UNAVAILABLE: permanent,
129
123
  OUTPUT_IN_USE: permanent,
130
124
  GPU_DEVICE_LOST: { code: "DEVICE_LOST", resource: "gpu" },
125
+ GPU_DEVICE_HUNG: { code: "DEVICE_HUNG", resource: "gpu" },
131
126
  GPU_TIMEOUT: { code: "GPU_TIMEOUT", resource: "gpu" },
132
- // A stuck decoder or encoder; the host names the region when it knows the session was a hardware
133
- // one.
134
127
  DECODE_STALLED: { code: "GPU_TIMEOUT", resource: "unknown" },
135
128
  ENCODE_STALLED: { code: "GPU_TIMEOUT", resource: "unknown" },
136
129
  IO_ERROR: { code: "OUTPUT_IO_FAILED", resource: "unknown" },
130
+ OUTPUT_PUBLISH_FAILED: { code: "OUTPUT_IO_FAILED", resource: "unknown" },
137
131
  CANCELLED: { code: "CANCELLED", resource: "unknown" },
138
132
  RESOURCE_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
139
133
  GPU_INIT_FAILED: unknown,
140
134
  ENCODE_ERROR: unknown,
135
+ ENCODER_BUSY: { code: "RESOURCE_BUSY", resource: "gpu" },
141
136
  INTERNAL: unknown,
142
137
  ALPHA2_ERROR: unknown,
143
- // @alpha2-sh/node's own: a host it cannot run is setup that a retry does not change.
138
+ // `@alpha2-sh/node` setup errors that a retry does not fix.
144
139
  HOST_NOT_FOUND: permanent,
145
140
  HOST_NOT_EXECUTABLE: permanent,
146
- // The loader refused the host (a missing or mismatched FFmpeg): the machine's setup again.
147
141
  HOST_LOAD_FAILED: permanent,
148
142
  HOST_START_FAILED: unknown,
143
+ // A loaded machine may start the host late, so a retry may work.
144
+ HOST_START_TIMEOUT: unknown,
145
+ HOST_QUARANTINED: permanent,
146
+ HOST_BLOCKED: permanent,
149
147
  HOST_WRITE_FAILED: unknown,
150
148
  HOST_EXITED: { code: "HOST_EXITED", resource: "unknown" },
149
+ // The cgroup's `oom_kill` count rose; a retry with a smaller `memory.scale` may fit.
150
+ HOST_OOM_KILLED: { code: "OUT_OF_MEMORY", resource: "cpu" },
151
151
  INVALID_RESPONSE: unknown,
152
152
  PROGRESS_CALLBACK_FAILED: unknown,
153
153
  ABORTED: { code: "CANCELLED", resource: "unknown" },
154
+ // Browser decode refusals repeat on every attempt.
155
+ DECODE_UNAVAILABLE: permanent,
156
+ PLANAR_DECODE_UNAVAILABLE: permanent,
157
+ NON_PLANAR_FRAME: permanent,
158
+ FRAME_SUPPLY_FAILED: unknown,
159
+ SOFTWARE_DECODE_REQUIRED: unknown,
154
160
  });
155
- /**
156
- * The class `code`, a protocol or `@alpha2-sh/node` error code, is evidence of on its own; `UNKNOWN`
157
- * for any other.
158
- */
161
+ /** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
159
162
  export function failureClassOfCode(code) {
160
163
  return ((typeof code === "string" && Object.hasOwn(CODE_CLASSES, code)
161
164
  ? CODE_CLASSES[code]
162
165
  : undefined) ?? unknown);
163
166
  }
164
167
  /**
165
- * The failure an error with protocol or `@alpha2-sh/node` code `code` and no failure of its own
166
- * reports: classified by the code (see {@link failureClassOfCode}), which it keeps as `hostCode`;
167
- * `UNKNOWN` without one. A process boundary that receives such an error (`@alpha2-sh/node`, a service
168
- * relaying it) classifies it with this, never by its own default.
168
+ * Builds a failure for an error that has only a protocol or `@alpha2-sh/node` code, classified by
169
+ * {@link failureClassOfCode} and keeping the code as `hostCode`. Process boundaries relaying such
170
+ * errors should classify with this rather than their own defaults.
169
171
  */
170
172
  export function failureForCode(code, context) {
171
173
  const { code: failureCode, resource } = failureClassOfCode(code);
@@ -189,7 +191,7 @@ export function failureForCode(code, context) {
189
191
  : { diagnostics: context.diagnostics }),
190
192
  };
191
193
  }
192
- function browserClass(error, message, phase, engine) {
194
+ function browserClass(error, message, phase, engine, depth = 0) {
193
195
  if (typeof engine?.code === "string" && CODES.has(engine.code))
194
196
  return [
195
197
  engine.code,
@@ -203,20 +205,29 @@ function browserClass(error, message, phase, engine) {
203
205
  return ["CANCELLED", "unknown"];
204
206
  if (code === "device-lost")
205
207
  return ["DEVICE_LOST", "gpu"];
206
- // An error that knows its own class names it.
208
+ if (code === "device-hung")
209
+ return ["DEVICE_HUNG", "gpu"];
207
210
  const own = error?.failureCode;
208
211
  if (typeof own === "string" && CODES.has(own))
209
212
  return [own, "unknown"];
210
213
  const coded = failureClassOfCode(code);
211
214
  if (coded.code !== "UNKNOWN")
212
215
  return [coded.code, coded.resource];
213
- // SpiderMonkey reports running out of memory by throwing this string, not an error.
216
+ // A wrapper takes its cause's class, one level deep.
217
+ const cause = error?.cause;
218
+ if (depth === 0 && cause !== undefined && cause !== null) {
219
+ const partial = cause.failure;
220
+ const inner = browserClass(cause, messageOf(cause), phase, isRecord(partial) ? partial : undefined, 1);
221
+ if (inner[0] !== "UNKNOWN")
222
+ return inner;
223
+ }
224
+ // SpiderMonkey throws this string, not an error, when out of memory.
214
225
  if (error === "out of memory")
215
226
  return ["ALLOCATION_FAILED", "js"];
216
- // A worker relays the name, not the type: `RangeError` by name is the same evidence.
227
+ // A worker relays the name, not the type.
217
228
  if (error instanceof RangeError || name === "RangeError") {
218
- // V8's and JavaScriptCore's words for a backing store they could not allocate, as opposed to
219
- // a length they refused.
229
+ // V8 and JavaScriptCore messages for a failed backing-store allocation, as opposed to an
230
+ // invalid length.
220
231
  if (/array buffer allocation failed/i.test(message))
221
232
  return ["ALLOCATION_FAILED", "js"];
222
233
  if (message === "Out of memory" || message.startsWith("Out of memory: "))
@@ -225,8 +236,8 @@ function browserClass(error, message, phase, engine) {
225
236
  return ["ALLOCATION_FAILED", "wasm"];
226
237
  }
227
238
  if (name === "QuotaExceededError")
228
- // A codec reclaimed under memory pressure reports the same name as a full disk; only where the
229
- // export was tells them apart.
239
+ // A codec reclaimed under memory pressure reports the same name as a full disk; only the
240
+ // phase tells them apart.
230
241
  return phase === "publish" || phase === "mux"
231
242
  ? ["STORAGE_QUOTA_EXCEEDED", "unknown"]
232
243
  : ["ALLOCATION_FAILED", "unknown"];
@@ -239,8 +250,8 @@ function browserClass(error, message, phase, engine) {
239
250
  return ["UNKNOWN", "unknown"];
240
251
  }
241
252
  /**
242
- * Records `later` beside `failure` without replacing it: the first failure is the cause. Returns a
243
- * new failure that keeps the latest 8 secondary notes; `failure` is not modified.
253
+ * Returns a copy of `failure` with `later` appended to its secondary notes (latest 8 kept). The
254
+ * first failure remains the cause.
244
255
  */
245
256
  export function withSecondaryFailure(failure, later) {
246
257
  return {
@@ -249,14 +260,9 @@ export function withSecondaryFailure(failure, later) {
249
260
  };
250
261
  }
251
262
  /**
252
- * Records that cleaning up after `error` failed too, without replacing it: an export runner calls
253
- * this when its sink's `abort` throws, then rethrows `error` itself.
254
- *
255
- * An {@link ExportFailureError} gains a `cleanup` note in its `failure` (see
256
- * {@link withSecondaryFailure}), classified from `cleanup`; the error stays the same object, so a
257
- * caller comparing it with an abort signal's reason still finds it. Any other error has no
258
- * classified failure to note it in, and the cleanup failure is dropped: the first failure is the
259
- * cause.
263
+ * Records a cleanup failure on `error` without replacing it. An {@link ExportFailureError} gains a
264
+ * `cleanup` note in place, so identity comparisons with an abort reason still hold. Other errors
265
+ * are left unchanged and the cleanup failure is dropped.
260
266
  */
261
267
  export function recordCleanupFailure(error, cleanup) {
262
268
  if (!(error instanceof ExportFailureError))