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.
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 +109 -173
  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 +98 -157
  53. package/dist/frame-supply.js +191 -162
  54. package/dist/generated/project-schema.d.ts +742 -464
  55. package/dist/generated/project-schema.js +63 -2
  56. package/dist/generated/project-shape.js +663 -118
  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 +88 -62
  62. package/dist/hdr-frames.js +123 -46
  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 +55 -55
  70. package/dist/layout.js +37 -36
  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 +173 -237
  76. package/dist/mediabunny.js +943 -518
  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 +83 -110
  84. package/dist/project.js +421 -447
  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 +106 -63
  96. package/dist/text.js +44 -69
  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 -92
  104. package/dist/worker.js +239 -144
  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 +487 -543
  111. package/wasm/alpha2_wasm.js +669 -572
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
@@ -1,51 +1,43 @@
1
1
  import type { MissingFrame } from "./player.js";
2
- /** A frame rate of `num / den` frames per second; both terms must be positive. */
2
+ import { type AacEncoderProbe, type BrowserExportPerformance, type EncodeLatency, type VideoLatencyProbe } from "./export-metrics.js";
3
+ /** `num / den` frames per second; both terms must be positive. */
3
4
  export interface RationalFrameRate {
4
5
  readonly num: bigint;
5
6
  readonly den: bigint;
6
7
  }
7
8
  /** One rendered output frame, in output order. */
8
9
  export interface ExportedFrame {
9
- /** Zero-based position in the output. */
10
10
  readonly index: bigint;
11
11
  /**
12
- * When the frame starts in the output, in 1/120000 s ticks: counted from the output's zero, the
13
- * start of {@link Alpha2Exporter.effectiveRange}, so the first frame is at 0. A sink writes it as
14
- * the sample's timestamp.
12
+ * Output start time in 1/120000 s ticks, relative to {@link Alpha2Exporter.effectiveRange}'s
13
+ * start, so the first frame is at 0.
15
14
  */
16
15
  readonly timeTicks: bigint;
17
- /** Owned by whoever holds this value; the receiver must close it. */
16
+ /** The receiver must close it. */
18
17
  readonly frame: VideoFrame;
19
18
  }
20
19
  /**
21
- * A backend's answer to one frame request: either the source frames it still needs uploaded, or a
22
- * submitted render whose readback holds `retainedBytes` until it resolves.
20
+ * A backend's answer to one frame request: the source frames still needed, or a submitted render
21
+ * whose readback holds `retainedBytes` until it resolves.
23
22
  */
24
23
  export type ExportTicket = {
25
24
  readonly kind: "waiting";
26
25
  readonly missingSources: readonly string[];
27
- /** Each clip's missing frame, with the source time to decode, as a preview reports it. */
26
+ /** Each clip's missing frame, with the source time to decode. */
28
27
  readonly missingFrames: readonly MissingFrame[];
29
28
  } | {
30
29
  readonly kind: "rendered";
31
30
  readonly retainedBytes: number;
32
31
  readonly readback: Promise<VideoFrame>;
33
32
  };
34
- /**
35
- * One step of {@link Alpha2Exporter.next}: sources to upload before the same frame is asked for
36
- * again, a submitted frame, or the end of the range.
37
- */
33
+ /** Result of {@link Alpha2Exporter.next}. */
38
34
  export type ExportAdvance = {
39
35
  readonly kind: "waiting";
40
- /** The waiting frame's position in the output. */
41
36
  readonly index: bigint;
42
- /** The waiting frame's timeline time, in 1/120000 s ticks. */
37
+ /** Timeline time in 1/120000 s ticks. */
43
38
  readonly timelineTicks: bigint;
44
39
  readonly missingSources: readonly string[];
45
- /**
46
- * Each clip's missing frame, with the source time to decode: a trimmed, offset, or retimed
47
- * clip needs its source at a time other than `timelineTicks`.
48
- */
40
+ /** Each clip's missing frame, with the source time to decode. */
49
41
  readonly missingFrames: readonly MissingFrame[];
50
42
  } | {
51
43
  readonly kind: "rendered";
@@ -54,108 +46,72 @@ export type ExportAdvance = {
54
46
  } | {
55
47
  readonly kind: "complete";
56
48
  };
57
- /** An {@link ExportAdvance} that waits for sources: what {@link exportToSink} asks a refill for. */
49
+ /** The waiting {@link ExportAdvance} that {@link exportToSink} passes to `refill`. */
58
50
  export type ExportWaiting = Extract<ExportAdvance, {
59
51
  kind: "waiting";
60
52
  }>;
61
53
  /** Options for {@link exportToSink}. */
62
54
  export interface BrowserExportOptions {
63
- /** Cancels the export; it then rejects with an {@link ExportAbortedError} coded `cancelled`. */
55
+ /** Aborting rejects with an {@link ExportAbortedError} coded `cancelled`. */
64
56
  readonly signal?: AbortSignal;
65
- /** Frames rendering, reading back or encoding at once, a positive integer (default 3). */
57
+ /** Frames rendering, reading back or encoding at once (default 3). */
66
58
  readonly maxInFlightFrames?: number;
67
59
  /**
68
- * Readback bytes those frames may hold at once, a positive integer (default 128 MiB). One frame
69
- * over it fails the export with `RESOURCE_LIMIT`.
60
+ * Readback bytes in flight at once (default 128 MiB). A single frame over it fails the export
61
+ * with `RESOURCE_LIMIT`.
70
62
  */
71
63
  readonly maxInFlightBytes?: number;
72
64
  }
73
- /** Browser export measurements whose names match native `performance` fields. */
74
- export interface BrowserExportMetrics {
75
- readonly pipelineEnabled: true;
76
- /** Time spent waiting for the host to decode and upload missing sources. */
77
- readonly sourceConvertUploadMs: number;
78
- /** Worker/Wasm evaluation, render, submission, and response time. */
79
- readonly frameSubmitMs: number;
80
- /** End-to-end GPU mapping latency, including time overlapped with other work. */
81
- readonly readbackMapLatencyMs: number;
82
- /** Time for which ordered export progress was blocked on GPU mapping. */
83
- readonly readbackWaitMs: number;
84
- /** Alias retained for direct comparison with native metrics. */
85
- readonly readbackBlockingMs: number;
86
- /** Time a rendered frame waited behind earlier encoder work. */
87
- readonly encodeQueueWaitMs: number;
88
- /** Time spent inside the browser encoder/muxer video-write adapter. */
89
- readonly videoEncodeMs: number;
90
- /** Time spent finalizing the encoder and muxer. */
91
- readonly muxFinishMs: number;
92
- readonly inFlightDepth: number;
93
- readonly encodeChannelDepth: number;
94
- readonly inFlightByteBudget: number;
95
- readonly stagingBytesPerFrame: number;
96
- readonly peakReadbackBytes: number;
97
- /**
98
- * Mapped staging bytes the export read back: the raw video that crossed from the GPU to script.
99
- * Native reports the same field.
100
- */
101
- readonly outputReadbackBytes: number;
102
- /**
103
- * Bytes script copied to pack read-back planes tight, because this browser's `VideoFrame` ignores
104
- * `layout` (Safari). 0 where the frame reads the padded planes in place.
105
- */
106
- readonly outputRepackBytes: number;
107
- readonly peakEncodeQueueBytes: number;
108
- readonly maxPendingMediaEvents: number;
109
- readonly averagePendingMediaEvents: number;
110
- readonly maxInFlightReadbacks: number;
111
- readonly maxEncodeQueueEvents: number;
112
- readonly encodeBackpressureCount: number;
113
- readonly pipelineOverlapFrames: number;
114
- }
115
- /** Completion data shaped like the comparable part of a native export result. */
65
+ /** Completion data, shaped like the comparable part of a native export result. */
116
66
  export interface BrowserExportResult {
117
67
  readonly renderMs: number;
118
68
  readonly frames: number;
119
69
  readonly fps: number;
120
- readonly performance: BrowserExportMetrics;
70
+ readonly performance: BrowserExportPerformance;
71
+ /** Present when the sink reports it. */
72
+ readonly videoLatencyProbe?: VideoLatencyProbe;
73
+ /** Present when the sink reports it. */
74
+ readonly aacPrimingProbe?: AacEncoderProbe;
75
+ /** Present when the sink reports it. */
76
+ readonly videoEncoderAcceleration?: "no-preference" | "prefer-software";
121
77
  }
122
78
  /** Backend implemented by the worker that owns the shared wasm renderer. */
123
79
  export interface ExportBackend {
124
80
  /**
125
- * Renders the frame starting at timeline time `timeTicks`, or reports which sources it still
126
- * needs. The `VideoFrame` a rendered ticket reads back is stamped at `outputTimeTicks`, the
127
- * frame's {@link ExportedFrame.timeTicks} (its `timestamp` is that time in whole microseconds,
128
- * rounded down), so a sink that encodes the frame as it arrives starts its file at 0 too.
81
+ * Renders the frame at timeline time `timeTicks`, or reports which sources it still needs. The
82
+ * read-back `VideoFrame`'s `timestamp` is `outputTimeTicks` in whole microseconds, rounded down.
129
83
  */
130
84
  begin(timeTicks: bigint, outputTimeTicks: bigint): Promise<ExportTicket>;
131
- /** Whether the GPU device is lost; the exporter checks it before every frame. */
85
+ /** Checked before every frame. */
132
86
  isDeviceLost(): boolean;
133
- /** Abandons the export after a failure the exporter detected itself. */
87
+ /** Abandons the export after a failure the exporter detected. */
134
88
  abort(reason: Error): void;
135
89
  }
136
- /**
137
- * Encoder/muxer adapter. Ownership of a frame transfers to `writeVideo`. Frame times count from the
138
- * output's zero ({@link ExportedFrame.timeTicks}).
139
- */
90
+ /** Encoder and muxer adapter. Ownership of a frame transfers to `writeVideo`. */
140
91
  export interface BrowserEncodeSink {
141
- /** Encodes one frame. Calls are serialized and arrive in output order. */
92
+ /** Calls are serialized and arrive in output order. */
142
93
  writeVideo(frame: ExportedFrame): Promise<void>;
143
94
  /** Flushes the encoder and finalizes the container after the last frame. */
144
95
  finish(): Promise<void>;
145
96
  /** Discards partial output; called once when the export fails. */
146
97
  abort(reason: Error): Promise<void> | void;
98
+ /** Copied into the result when present. */
99
+ readonly videoLatencyProbe?: VideoLatencyProbe;
100
+ readonly aacPrimingProbe?: AacEncoderProbe;
101
+ readonly videoEncoderAcceleration?: "no-preference" | "prefer-software";
102
+ readonly videoEncodeLatencyMs?: EncodeLatency;
147
103
  }
148
104
  /**
149
105
  * An export stopped by cancellation (`cancelled`), a lost GPU device (`device-lost`) or a sink that
150
- * threw a non-`Error` value (`adapter`). Each may be restarted cleanly.
106
+ * threw a non-`Error` value (`adapter`). The export can be restarted cleanly.
151
107
  */
152
108
  export declare class ExportAbortedError extends Error {
153
109
  readonly code: "cancelled" | "device-lost" | "adapter";
154
110
  constructor(code: "cancelled" | "device-lost" | "adapter", message: string, options?: ErrorOptions);
155
111
  }
156
112
  /**
157
- * Exact, retryable browser export scheduler. It walks the frame grid of `rate` over a timeline
158
- * range; encoding and muxing stay host-owned.
113
+ * Browser export scheduler that walks the frame grid of `rate` over a timeline range. Encoding and
114
+ * muxing stay with the host.
159
115
  */
160
116
  export declare class Alpha2Exporter {
161
117
  #private;
@@ -167,19 +123,17 @@ export declare class Alpha2Exporter {
167
123
  */
168
124
  constructor(backend: ExportBackend, rate: RationalFrameRate, startTicks: bigint, endTicks: bigint);
169
125
  /**
170
- * The timeline range this export covers: the requested range widened to the frame grid,
171
- * `[floor(start), ceil(end))`. Its start is the output's zero, which is where a host starts the
172
- * export's audio.
126
+ * The requested range widened to the frame grid, `[floor(start), ceil(end))`. Its start is
127
+ * output time zero, where the host should also start the audio.
173
128
  */
174
129
  get effectiveRange(): {
175
130
  readonly startTicks: bigint;
176
131
  readonly endTicks: bigint;
177
132
  };
178
133
  /**
179
- * The project-rate samples this export's audio covers at `sampleRate`: from the sample nearest
180
- * {@link effectiveRange}'s start to the one nearest its end, as the engine's
181
- * `export_audio_window` places audio on every host. `startSample` is the mix position written at
182
- * the output's zero.
134
+ * The audio samples this export covers at `sampleRate`, from the sample nearest
135
+ * {@link effectiveRange}'s start to the one nearest its end, matching the engine's
136
+ * `export_audio_window`. `startSample` is the mix position at output time zero.
183
137
  *
184
138
  * @throws RangeError when `sampleRate` is not a positive safe integer.
185
139
  */
@@ -187,45 +141,42 @@ export declare class Alpha2Exporter {
187
141
  readonly startSample: bigint;
188
142
  readonly frames: bigint;
189
143
  };
190
- /** Frames whose readback has resolved, out of the frames the range holds. */
144
+ /** Frames whose readback has resolved, out of the total. */
191
145
  get progress(): {
192
146
  readonly completed: bigint;
193
147
  readonly total: bigint;
194
148
  };
195
149
  /**
196
- * Submits the next frame. Calls are serialized, so frames are submitted in order even when
197
- * several calls are pending. A `waiting` answer leaves the frame unsubmitted; call again after
198
- * uploading the missing sources.
150
+ * Submits the next frame. Calls are serialized. A `waiting` result leaves the frame unsubmitted;
151
+ * call again after uploading the missing sources.
199
152
  *
200
153
  * Rejects with an {@link ExportAbortedError} coded `device-lost` (after aborting the backend)
201
- * when the GPU device is lost, and with whatever the backend rejects with.
154
+ * when the GPU device is lost, or with the backend's error.
202
155
  */
203
156
  next(): Promise<ExportAdvance>;
204
157
  }
205
158
  /**
206
- * Runs an exporter into any WebCodecs/mediabunny-compatible public sink, keeping at most
207
- * `maxInFlightFrames` frames and `maxInFlightBytes` readback bytes in flight. `refill` uploads the
208
- * source frames a frame is waiting for, which its `missingFrames` name with the source time to
209
- * decode, before the same frame is asked for again; a frame still waiting after four refills fails
210
- * the export with an `ExportFailureError` coded `RESOURCE_LIMIT` at step `upload`, stage
211
- * `sources-not-held`, naming the sources: the refill does not upload them. A frame whose sources
212
- * outgrow the binding's uploaded-frame budget fails sooner: the binding refuses the upload that
213
- * would overflow it (`RESOURCE_LIMIT`, stage `working-set-over-budget`), and `refill` rejects with
214
- * that. Neither is retried by `decideRetry`.
159
+ * Runs an exporter into a WebCodecs or mediabunny-compatible sink, keeping at most
160
+ * `maxInFlightFrames` frames and `maxInFlightBytes` readback bytes in flight.
161
+ *
162
+ * `refill` uploads the source frames named in `missingFrames` before the frame is requested again.
163
+ * A frame still waiting after four refills fails with `RESOURCE_LIMIT` at stage
164
+ * `sources-not-held`; an upload over the binding's frame budget fails with `RESOURCE_LIMIT` at
165
+ * stage `working-set-over-budget`. `decideRetry` retries neither.
166
+ *
167
+ * A refill rejected with `SOFTWARE_DECODE_REQUIRED` is retried once with `decode: "software"` on
168
+ * that `missingFrames` entry, and a `non-planar` source is requested in software from then on.
169
+ * `refill` must honor `decode`.
215
170
  *
216
- * `refill` must deliver through a decoder refill of the export's own, not the preview's: a
217
- * `DecoderRefillCoordinator` made for the export, whose `deliver` uploads to the backend the
218
- * export renders with and whose requests carry generation 0 (an {@link ExportWaiting} has none).
219
- * A coordinator resolves a request from a generation older than its own without delivering it,
220
- * so the preview's, past generation 0 after its first seek, would drop the export's refills
221
- * silently and the frame would fail at `sources-not-held`.
171
+ * `refill` must use a `DecoderRefillCoordinator` created for this export (requests at generation
172
+ * 0), not the preview's. The preview's coordinator moves past generation 0 after its first seek
173
+ * and would silently drop the export's requests.
222
174
  *
223
- * Resolves after `sink.finish()` with timing and memory metrics; a `signal` that aborts before
224
- * then, during `finish()` included, rejects instead. On any failure it closes the
225
- * frames it still holds, waits for pending writes, calls `sink.abort` once and rejects with the
226
- * failure: an {@link ExportAbortedError} for cancellation or a lost device, an
227
- * `ExportFailureError` coded `RESOURCE_LIMIT` when one frame exceeds `maxInFlightBytes`, a
228
- * `RangeError` for an invalid option, or the error the backend, `refill` or the sink raised. An
229
- * `abort` that throws does not replace that failure ({@link recordCleanupFailure}).
175
+ * Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal`, even during
176
+ * `finish()`, rejects immediately; late results are closed. On other failures, held frames are
177
+ * closed and pending writes awaited. In both cases `sink.abort` is called once and the promise
178
+ * rejects with an {@link ExportAbortedError}, a `RESOURCE_LIMIT` `ExportFailureError`, a
179
+ * `RangeError` for an invalid option, or the error from the backend, `refill` or sink. An error
180
+ * thrown by `sink.abort` does not replace it.
230
181
  */
231
182
  export declare function exportToSink(exporter: Alpha2Exporter, sink: BrowserEncodeSink, refill: (waiting: ExportWaiting) => Promise<void>, options?: BrowserExportOptions): Promise<BrowserExportResult>;