alpha2 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +109 -173
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +98 -157
- package/dist/frame-supply.js +191 -162
- package/dist/generated/project-schema.d.ts +742 -464
- package/dist/generated/project-schema.js +63 -2
- package/dist/generated/project-shape.js +663 -118
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +88 -62
- package/dist/hdr-frames.js +123 -46
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +55 -55
- package/dist/layout.js +37 -36
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +173 -237
- package/dist/mediabunny.js +943 -518
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +83 -110
- package/dist/project.js +421 -447
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +106 -63
- package/dist/text.js +44 -69
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -92
- package/dist/worker.js +239 -144
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +487 -543
- package/wasm/alpha2_wasm.js +669 -572
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Destinations for a browser export's encoded bytes.
|
|
3
3
|
*
|
|
4
|
-
* The default
|
|
5
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
27
|
+
/** Furthest position written. */
|
|
35
28
|
readonly size: number;
|
|
36
|
-
/**
|
|
29
|
+
/** Peak bytes queued between the muxer and the file. */
|
|
37
30
|
readonly peakQueuedBytes: number;
|
|
38
|
-
/**
|
|
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
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
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
|
|
64
|
-
*
|
|
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
|
-
/**
|
|
58
|
+
/** Set when the file refused a write or the close. */
|
|
69
59
|
get failure(): ExportFailure | undefined;
|
|
70
60
|
}
|
|
71
61
|
/**
|
|
72
|
-
*
|
|
62
|
+
* Peak memory of an in-memory output of `estimatedBytes`.
|
|
73
63
|
*
|
|
74
|
-
* A
|
|
75
|
-
*
|
|
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
|
-
/**
|
|
68
|
+
/** Output-sized buffers an in-memory output can hold at once. */
|
|
82
69
|
export declare const MEMORY_OUTPUT_COPIES = 4;
|
|
83
|
-
/**
|
|
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
|
-
*
|
|
2
|
+
* Destinations for a browser export's encoded bytes.
|
|
3
3
|
*
|
|
4
|
-
* The default
|
|
5
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
|
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
|
|
95
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
120
|
+
* Peak memory of an in-memory output of `estimatedBytes`.
|
|
126
121
|
*
|
|
127
|
-
* A
|
|
128
|
-
*
|
|
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
|
-
/**
|
|
128
|
+
/** Output-sized buffers an in-memory output can hold at once. */
|
|
137
129
|
export const MEMORY_OUTPUT_COPIES = 4;
|
|
138
|
-
/**
|
|
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;
|
package/dist/export-failure.d.ts
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
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
|
|
6
|
-
* `READBACK_FAILED` unless the device
|
|
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
|
-
*
|
|
12
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
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
|
-
*
|
|
128
|
-
*
|
|
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
|
|
133
|
-
*
|
|
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;
|
package/dist/export-failure.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
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
|
|
6
|
-
* `READBACK_FAILED` unless the device
|
|
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
|
|
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
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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
|
-
//
|
|
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
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
|
227
|
+
// A worker relays the name, not the type.
|
|
217
228
|
if (error instanceof RangeError || name === "RangeError") {
|
|
218
|
-
// V8
|
|
219
|
-
//
|
|
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
|
|
229
|
-
//
|
|
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
|
-
*
|
|
243
|
-
*
|
|
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
|
|
253
|
-
*
|
|
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))
|