alpha2 0.6.1 → 0.7.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 (47) hide show
  1. package/README.md +3 -3
  2. package/dist/effects.d.ts +3 -2
  3. package/dist/export-failure.d.ts +6 -0
  4. package/dist/export-failure.js +18 -1
  5. package/dist/export-retry.d.ts +2 -1
  6. package/dist/export-retry.js +12 -5
  7. package/dist/extract.d.ts +0 -5
  8. package/dist/extract.js +5 -12
  9. package/dist/extractor.d.ts +16 -3
  10. package/dist/extractor.js +2 -1
  11. package/dist/generated/project-schema.d.ts +31 -1
  12. package/dist/generated/project-schema.js +5 -0
  13. package/dist/generated/project-shape.js +14 -1
  14. package/dist/gpu-recovery.d.ts +13 -5
  15. package/dist/gpu-recovery.js +19 -8
  16. package/dist/hdr-frames.js +2 -0
  17. package/dist/media-source.d.ts +3 -0
  18. package/dist/media-source.js +13 -0
  19. package/dist/media.d.ts +12 -1
  20. package/dist/media.js +15 -1
  21. package/dist/mediabunny.d.ts +4 -1
  22. package/dist/mediabunny.js +22 -23
  23. package/dist/player.js +2 -0
  24. package/dist/plugin-manifest.d.ts +119 -0
  25. package/dist/plugin-manifest.js +583 -0
  26. package/dist/plugin-supplied.d.ts +55 -0
  27. package/dist/plugin-supplied.js +221 -0
  28. package/dist/plugins.d.ts +87 -9
  29. package/dist/plugins.js +196 -47
  30. package/dist/project-data.d.ts +19 -0
  31. package/dist/project-data.js +210 -7
  32. package/dist/project.d.ts +1 -1
  33. package/dist/project.js +1 -1
  34. package/dist/sha256.d.ts +1 -1
  35. package/package.json +1 -1
  36. package/wasm/alpha2_compose_bg.wasm +0 -0
  37. package/wasm/alpha2_extensions_bg.wasm +0 -0
  38. package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
  39. package/wasm/alpha2_wasm.d.ts +14 -12
  40. package/wasm/alpha2_wasm.js +48 -46
  41. package/wasm/alpha2_wasm_bg.wasm +0 -0
  42. package/wasm/alpha2_wasm_bg.wasm.d.ts +6 -6
  43. /package/wasm/snippets/{alpha2-wasm-6749ed8b34a74067/inline4.js → alpha2-wasm-7cccf477e10e3d0d/inline0.js} +0 -0
  44. /package/wasm/snippets/{alpha2-wasm-6749ed8b34a74067/inline0.js → alpha2-wasm-7cccf477e10e3d0d/inline1.js} +0 -0
  45. /package/wasm/snippets/{alpha2-wasm-6749ed8b34a74067/inline1.js → alpha2-wasm-7cccf477e10e3d0d/inline2.js} +0 -0
  46. /package/wasm/snippets/{alpha2-wasm-6749ed8b34a74067/inline2.js → alpha2-wasm-7cccf477e10e3d0d/inline3.js} +0 -0
  47. /package/wasm/snippets/{alpha2-wasm-6749ed8b34a74067/inline3.js → alpha2-wasm-7cccf477e10e3d0d/inline4.js} +0 -0
package/README.md CHANGED
@@ -109,7 +109,7 @@ const { dataSets } = await runExtractor(
109
109
  );
110
110
  ```
111
111
 
112
- A timeline input needs `timelineFrame(time, width, height)`, such as the CPU renderer's `readRgbaAt`, and an audio input `audioBinding: wasm`. `loadPlugin(manifest, sha256)` in `alpha2/plugins` loads an [extractor plugin](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md)'s wasm artifact, checked against its pinned hashes; pass it as `plugin` with `plugin.extractor(params)`. `applyEdit` in `alpha2/apply-edit` then applies data to the project, such as `remove_ranges` over silences.
112
+ A timeline input needs `timelineFrame(time, width, height)`, such as the CPU renderer's `readRgbaAt`, and an audio input `audioBinding: wasm`. `loadPlugin(manifest, sha256)` in `alpha2/plugins` loads an [extractor plugin](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md)'s wasm artifact, checked against its pinned hashes, with `onProgress` as its files arrive and `supplied` filling its resource slots (a `File`, or a directory handle or a directory picker's files); run `plugin.extractor(params)`, which records `made_by.plugin` with the slot files it read. `transferablePlugin(plugin)` is a value `postMessage` copies to a worker, where `restorePlugin` makes the plugin again without fetching or compiling it. `parsePluginManifest(text)` checks a manifest by the same rules without fetching anything, for an interface that shows a plugin before it is installed, with `about` and the outputs' `label`s. `applyEdit` in `alpha2/apply-edit` then applies data to the project, such as `remove_ranges` over silences.
113
113
 
114
114
  ## Compose
115
115
 
@@ -142,11 +142,11 @@ const { project, assets, loudness, warnings } = compileCompose(compose, spec, {
142
142
  | Import | What it has |
143
143
  | --- | --- |
144
144
  | `alpha2/wasm` | The engine: `init`, `WebEffectRegistry` (rendering, export, audio mixing), and the engine's functions for rate control, captions, loudness and waveforms. |
145
- | `alpha2/project` | The project document's types and limits, tick conversions, `validateProject`. |
145
+ | `alpha2/project` | The project document's types and limits, tick conversions, `validateProject`; `dataReferences` (where a project reads data) and `bindableProperties` (where it could, with the data kinds each place reads). |
146
146
  | `alpha2/builder` | `ProjectBuilder`: documents from seconds, with generated ids. |
147
147
  | `alpha2/edit` | Editing operations on a project: split, trim, ripple, roll, slip, slide, retime, insert, overwrite, append, move. |
148
148
  | `alpha2/apply-edit` | `applyEdit`: the engine's edit operations that apply data to a project (`remove_ranges`, `split_at`, `bake`), the same canonical result on every surface. |
149
- | `alpha2/extract`, `alpha2/plugins` | `runExtractor`: extractors of your own over a source or the timeline, decoded in the browser; `loadPlugin`: [extractor plugins](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md) run sandboxed. |
149
+ | `alpha2/extract`, `alpha2/plugins` | `runExtractor`: extractors of your own over a source or the timeline, decoded in the browser; `loadPlugin`: [extractor plugins](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md) run sandboxed; `parsePluginManifest` and the `MAX_PLUGIN_*` limits. |
150
150
  | `alpha2/extractor` | The extractor contract every surface shares (`Extractor`, `ExtractorDescriptor`, `ExtractRun`, `ExtractResult`), types only, without a media library. |
151
151
  | `alpha2/compose`, `alpha2/compose-wasm` | Compose specs and templates (`loadCompose`, `composeRequirements`, `compileCompose`, `bindTemplate`, `templateDataSchema`, `lintTemplate`, `builtinTemplates`), and the wasm module they load. See [Compose](#compose). |
152
152
  | `alpha2/captions` | SRT and WebVTT import into caption tracks. |
package/dist/effects.d.ts CHANGED
@@ -153,8 +153,9 @@ export interface WasmCanvasRenderer extends WasmEffectRegistry {
153
153
  /** Browser-reported adapter name; may be empty. */
154
154
  readonly adapter?: string;
155
155
  /**
156
- * After a loss, JSON `{ hung, gpuMs, watchdogMs, timeTicks, frameIndex, effects }` with
157
- * `timeTicks` as a decimal string; `undefined` before any loss and on the CPU renderer.
156
+ * After a loss, JSON `{ hung, gpuMs, measured, submissions, watchdogMs, timeTicks, frameIndex,
157
+ * effects, predictedMs }` with `timeTicks` as a decimal string; `undefined` before any loss and
158
+ * on the CPU renderer.
158
159
  */
159
160
  readonly lossReport?: string;
160
161
  /** A lost renderer rejects export readbacks and must be recreated. Never set on the CPU. */
@@ -93,6 +93,12 @@ export declare const BROWSER_ERROR_CODES: readonly ["DECODE_UNAVAILABLE", "PLANA
93
93
  export type BrowserErrorCode = (typeof BROWSER_ERROR_CODES)[number];
94
94
  /** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
95
95
  export declare function failureClassOfCode(code: unknown): FailureClass;
96
+ /**
97
+ * Failure class of an export service's HTTP error status: `413` (a body past the service's limit)
98
+ * is `RESOURCE_LIMIT`, `429` and `503` are `RESOURCE_BUSY`, `507` is `STORAGE_QUOTA_EXCEEDED`, and
99
+ * any other status is `UNKNOWN`.
100
+ */
101
+ export declare function failureClassOfHttpStatus(status: number): FailureClass;
96
102
  /** Context for {@link failureForCode}. */
97
103
  export interface CodeFailureContext {
98
104
  readonly message: string;
@@ -168,10 +168,11 @@ const CODE_CLASSES = Object.freeze({
168
168
  PLUGIN_LOAD_FAILED: permanent,
169
169
  PLUGIN_TRAPPED: permanent,
170
170
  PLUGIN_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
171
+ PLUGIN_RESOURCE_INVALID: permanent,
171
172
  GPU_INIT_FAILED: unknown,
172
173
  ENCODE_ERROR: unknown,
173
174
  ENCODER_BUSY: { code: "RESOURCE_BUSY", resource: "gpu" },
174
- // A caught panic of the host.
175
+ // A defect in the host or the engine: a caught panic or an internal error.
175
176
  INTERNAL: defect,
176
177
  ALPHA2_ERROR: unknown,
177
178
  // `@alpha2-sh/node` setup errors that a retry does not fix.
@@ -215,6 +216,22 @@ export function failureClassOfCode(code) {
215
216
  ? CODE_CLASSES[code]
216
217
  : undefined) ?? unknown);
217
218
  }
219
+ const HTTP_STATUS_CLASSES = Object.freeze({
220
+ 413: { code: "RESOURCE_LIMIT", resource: "unknown" },
221
+ 429: { code: "RESOURCE_BUSY", resource: "unknown" },
222
+ 503: { code: "RESOURCE_BUSY", resource: "unknown" },
223
+ 507: { code: "STORAGE_QUOTA_EXCEEDED", resource: "unknown" },
224
+ });
225
+ /**
226
+ * Failure class of an export service's HTTP error status: `413` (a body past the service's limit)
227
+ * is `RESOURCE_LIMIT`, `429` and `503` are `RESOURCE_BUSY`, `507` is `STORAGE_QUOTA_EXCEEDED`, and
228
+ * any other status is `UNKNOWN`.
229
+ */
230
+ export function failureClassOfHttpStatus(status) {
231
+ return ((Object.hasOwn(HTTP_STATUS_CLASSES, status)
232
+ ? HTTP_STATUS_CLASSES[status]
233
+ : undefined) ?? unknown);
234
+ }
218
235
  /**
219
236
  * Builds a failure for an error that has only a protocol or `@alpha2-sh/node` code, classified by
220
237
  * {@link failureClassOfCode} and keeping the code as `hostCode`. Process boundaries relaying such
@@ -7,7 +7,8 @@
7
7
  *
8
8
  * - `DEVICE_HUNG`, or a GPU loss recurring at the same frame, is never retried on the GPU; it moves
9
9
  * to the CPU renderer when available, else stops.
10
- * - Memory exhaustion steps down to a smaller profile.
10
+ * - Memory exhaustion steps down to a smaller profile, then GPU memory exhaustion moves to the CPU
11
+ * renderer when the client allows it.
11
12
  * - An encode failure retries once with the software video encoder when available.
12
13
  * - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
13
14
  * - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
@@ -7,7 +7,8 @@
7
7
  *
8
8
  * - `DEVICE_HUNG`, or a GPU loss recurring at the same frame, is never retried on the GPU; it moves
9
9
  * to the CPU renderer when available, else stops.
10
- * - Memory exhaustion steps down to a smaller profile.
10
+ * - Memory exhaustion steps down to a smaller profile, then GPU memory exhaustion moves to the CPU
11
+ * renderer when the client allows it.
11
12
  * - An encode failure retries once with the software video encoder when available.
12
13
  * - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
13
14
  * - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
@@ -112,10 +113,16 @@ export function decideRetry(history, options = {}) {
112
113
  return stop(`${failure.code} at ${failure.phase} is not helped by a retry`);
113
114
  if (!attemptsLeft)
114
115
  return stop(`all ${maxAttempts} attempts failed`);
115
- if (MEMORY.has(failure.code))
116
- return smaller
117
- ? retry(`${failure.code}: retrying with less in flight (${smaller.name})`, { profile: smaller })
118
- : stop(`${failure.code} with the smallest profile (${last.profile.name}): nothing left to reduce`);
116
+ if (MEMORY.has(failure.code)) {
117
+ if (smaller)
118
+ return retry(`${failure.code}: retrying with less in flight (${smaller.name})`, { profile: smaller });
119
+ if (failure.code === "OUT_OF_MEMORY" &&
120
+ failure.resource === "gpu" &&
121
+ last.renderer === "gpu" &&
122
+ options.cpuRenderer === true)
123
+ return retry(`${failure.code} with the smallest profile (${last.profile.name}): the GPU cannot hold the export; retrying on the CPU renderer`, { renderer: "cpu" });
124
+ return stop(`${failure.code} with the smallest profile (${last.profile.name}): nothing left to reduce`);
125
+ }
119
126
  if (failure.phase === "encode" && last.videoEncoder === "default") {
120
127
  if (options.softwareVideoEncoder !== false)
121
128
  return retry(`${failure.code} while encoding: retrying with the software video encoder`, { videoEncoder: "software" });
package/dist/extract.d.ts CHANGED
@@ -44,11 +44,6 @@ export interface RunExtractorRequest {
44
44
  readonly timelineFrame?: (time: bigint, width: number, height: number) => Promise<TimelineFrame> | TimelineFrame;
45
45
  /** The original source's fingerprint, recorded as `made_from` on source-anchored data. */
46
46
  readonly madeFrom?: unknown;
47
- /** The plugin `extractor` came from (`loadPlugin`), recorded as `made_by.plugin`. */
48
- readonly plugin?: {
49
- readonly version: string;
50
- readonly artifactSha256: string;
51
- };
52
47
  readonly signal?: AbortSignal;
53
48
  readonly onProgress?: (progress: ExtractProgress) => void;
54
49
  }
package/dist/extract.js CHANGED
@@ -1,10 +1,11 @@
1
1
  // `runExtractor` drives the engine's session in wasm over media the page or a worker decodes.
2
2
  // Re-exports the shared contract from `alpha2/extractor`.
3
- import { ALL_FORMATS, BlobSource, BufferSource, EncodedPacketSink, Input, VideoSampleSink, } from "mediabunny";
3
+ import { ALL_FORMATS, EncodedPacketSink, Input, VideoSampleSink, } from "mediabunny";
4
4
  import { collectEmits, schemaProblem, } from "./extractor.js";
5
5
  export { collectEmits, schemaProblem } from "./extractor.js";
6
6
  import { copyPlanarYuvFrame, DecodeUnavailableError, decodeRefusalMessage, } from "./hdr-frames.js";
7
7
  import { microsecondsToTicks, readVideoOrientation } from "./media.js";
8
+ import { mediaSource } from "./media-source.js";
8
9
  import { MediabunnyAudioDecoder, streamChromaSiting, videoTrackFacts, } from "./mediabunny.js";
9
10
  const TICKS_PER_SECOND = 120_000;
10
11
  /** An error with the code the native host answers with. */
@@ -28,9 +29,7 @@ class SourceFrames {
28
29
  this.#chromaSiting = chromaSiting;
29
30
  }
30
31
  static async open(resource, id) {
31
- const source = resource instanceof Blob
32
- ? new BlobSource(resource)
33
- : new BufferSource(resource);
32
+ const source = mediaSource(resource);
34
33
  const input = new Input({ source, formats: ALL_FORMATS });
35
34
  const track = await input.getPrimaryVideoTrack();
36
35
  if (track === null) {
@@ -264,18 +263,12 @@ export async function runExtractor(request, extractor) {
264
263
  const dataSets = JSON.parse(session.finish(request.madeFrom === undefined
265
264
  ? undefined
266
265
  : JSON.stringify(request.madeFrom)));
267
- const plugin = request.plugin;
266
+ const plugin = extractor.madeByPlugin?.();
268
267
  const recorded = plugin === undefined
269
268
  ? dataSets
270
269
  : dataSets.map((set) => ({
271
270
  ...set,
272
- made_by: {
273
- ...set.made_by,
274
- plugin: {
275
- version: plugin.version,
276
- artifact_sha256: plugin.artifactSha256,
277
- },
278
- },
271
+ made_by: { ...set.made_by, plugin },
279
272
  }));
280
273
  return {
281
274
  dataSets: recorded,
@@ -1,4 +1,4 @@
1
- import type { DataSet } from "./generated/project-schema.js";
1
+ import type { DataSet, MadeByPlugin } from "./generated/project-schema.js";
2
2
  /** What an extractor reads and emits; the same object `describe()` returns on every surface. */
3
3
  export interface ExtractorDescriptor {
4
4
  /** Reverse-DNS id; `alpha2.` is reserved for first-party plugins. */
@@ -18,7 +18,10 @@ export interface ExtractorDescriptor {
18
18
  readonly channels?: "mono" | "source";
19
19
  readonly block_frames?: number;
20
20
  };
21
- /** JSON Schema of the request's `params`; checked before the request is sent. */
21
+ /**
22
+ * JSON Schema of the request's `params`; checked before the request is sent. Its interface
23
+ * annotations (`title`, `description`, `default`, `x-alpha2-*`) are not checked.
24
+ */
22
25
  readonly params_schema?: unknown;
23
26
  readonly outputs: readonly {
24
27
  readonly name: string;
@@ -26,6 +29,10 @@ export interface ExtractorDescriptor {
26
29
  readonly channels?: readonly string[];
27
30
  readonly interpolation?: "hold" | "linear";
28
31
  readonly suggest?: "bind" | "remove_ranges" | "split_at";
32
+ /** The output's name in an interface: 1 to 80 characters, no control characters. */
33
+ readonly label?: string;
34
+ /** What the output holds, for an interface: up to 400 characters, no control characters. */
35
+ readonly description?: string;
29
36
  }[];
30
37
  }
31
38
  /** One run: the descriptor's id and version, its params, the input read and the data set ids. */
@@ -121,6 +128,11 @@ export interface Extractor {
121
128
  audio?(block: ExtractAudio, out: ExtractEmitter): void | Promise<void>;
122
129
  /** Whole-range work (speech recognition) belongs here and may emit anywhere in the range. */
123
130
  end?(out: ExtractEmitter): void | Promise<void>;
131
+ /**
132
+ * The plugin build that ran, as the data's `made_by.plugin` records it; read once the run has
133
+ * ended. A plugin's extractor (`LoadedPlugin.extractor`) has it; an app's own has none.
134
+ */
135
+ madeByPlugin?(): MadeByPlugin;
124
136
  }
125
137
  /** Progress of one pass; `total` is `null` for source frames, whose count is not known ahead. */
126
138
  export interface ExtractProgress {
@@ -146,6 +158,7 @@ export declare function collectEmits(): {
146
158
  * Where `value` breaks `schema`, as a path and reason, or `undefined`. Covers the JSON Schema
147
159
  * keywords descriptors use, which are `type`, `enum`, `const`, `properties`, `required`,
148
160
  * `additionalProperties`, `items`, `minItems`, `maxItems`, `minimum`, `maximum`, `minLength` and
149
- * `maxLength`.
161
+ * `maxLength`; every other keyword, the interface annotations of `docs/plugin-abi.md` among them,
162
+ * is ignored.
150
163
  */
151
164
  export declare function schemaProblem(schema: unknown, value: unknown, at?: string): string | undefined;
package/dist/extractor.js CHANGED
@@ -66,7 +66,8 @@ export function collectEmits() {
66
66
  * Where `value` breaks `schema`, as a path and reason, or `undefined`. Covers the JSON Schema
67
67
  * keywords descriptors use, which are `type`, `enum`, `const`, `properties`, `required`,
68
68
  * `additionalProperties`, `items`, `minItems`, `maxItems`, `minimum`, `maximum`, `minLength` and
69
- * `maxLength`.
69
+ * `maxLength`; every other keyword, the interface annotations of `docs/plugin-abi.md` among them,
70
+ * is ignored.
70
71
  */
71
72
  export function schemaProblem(schema, value, at = "params") {
72
73
  if (typeof schema !== "object" || schema === null)
@@ -174,6 +174,10 @@ export declare const MAX_SEQUENCE_FRAMES = 100000;
174
174
  export declare const MAX_SHAPE_DEPTH = 32;
175
175
  /** Mirrors `alpha2_model::MAX_SHAPE_ITEMS`. */
176
176
  export declare const MAX_SHAPE_ITEMS = 1024;
177
+ /** Mirrors `alpha2_model::MAX_SUPPLIED_FILES`. */
178
+ export declare const MAX_SUPPLIED_FILES = 1024;
179
+ /** Mirrors `alpha2_model::MAX_SUPPLIED_NAME_BYTES`. */
180
+ export declare const MAX_SUPPLIED_NAME_BYTES = 512;
177
181
  /** Mirrors `alpha2_model::MAX_SVG_DOCUMENT_BYTES`. */
178
182
  export declare const MAX_SVG_DOCUMENT_BYTES = 33554432;
179
183
  /** Mirrors `alpha2_model::MAX_TEXT_ANIMATORS`. */
@@ -923,7 +927,7 @@ export interface ColorPipeline {
923
927
  /**
924
928
  * RGB primary chromaticities a source or export declares.
925
929
  */
926
- export type ColorPrimaries = "bt601" | "bt709" | "bt2020";
930
+ export type ColorPrimaries = "bt601" | "bt709" | "bt2020" | "display_p3";
927
931
  /**
928
932
  * Nominal encoded component range.
929
933
  */
@@ -2096,6 +2100,14 @@ export interface MadeByPlugin {
2096
2100
  * SHA-256 of the artifact that ran, as 64 lowercase hexadecimal digits.
2097
2101
  */
2098
2102
  readonly artifact_sha256: string;
2103
+ /**
2104
+ * SHA-256 of the manifest's bytes, 64 lowercase hex digits; it covers the pinned resources.
2105
+ */
2106
+ readonly manifest_sha256: string;
2107
+ /**
2108
+ * The slot files the run read, sorted by name; at most `MAX_SUPPLIED_FILES`.
2109
+ */
2110
+ readonly supplied?: readonly SuppliedFile[];
2099
2111
  /**
2100
2112
  * The package's semantic version.
2101
2113
  */
@@ -3277,6 +3289,24 @@ export interface Subpath {
3277
3289
  */
3278
3290
  readonly vertices: readonly PathVertex[];
3279
3291
  }
3292
+ /**
3293
+ * A file of a resource slot that a plugin run read, by name and content, never by path.
3294
+ */
3295
+ export interface SuppliedFile {
3296
+ /**
3297
+ * Its length in bytes.
3298
+ */
3299
+ readonly bytes: number;
3300
+ /**
3301
+ * The resource name the plugin read it by, `<slot>` or `<slot>/<relative path>`; at most
3302
+ * `MAX_SUPPLIED_NAME_BYTES` bytes.
3303
+ */
3304
+ readonly name: string;
3305
+ /**
3306
+ * SHA-256 of its bytes, as 64 lowercase hexadecimal digits.
3307
+ */
3308
+ readonly sha256: string;
3309
+ }
3280
3310
  /**
3281
3311
  * How lines of text align within it.
3282
3312
  */
@@ -177,6 +177,10 @@ export const MAX_SEQUENCE_FRAMES = 100000;
177
177
  export const MAX_SHAPE_DEPTH = 32;
178
178
  /** Mirrors `alpha2_model::MAX_SHAPE_ITEMS`. */
179
179
  export const MAX_SHAPE_ITEMS = 1024;
180
+ /** Mirrors `alpha2_model::MAX_SUPPLIED_FILES`. */
181
+ export const MAX_SUPPLIED_FILES = 1024;
182
+ /** Mirrors `alpha2_model::MAX_SUPPLIED_NAME_BYTES`. */
183
+ export const MAX_SUPPLIED_NAME_BYTES = 512;
180
184
  /** Mirrors `alpha2_model::MAX_SVG_DOCUMENT_BYTES`. */
181
185
  export const MAX_SVG_DOCUMENT_BYTES = 33554432;
182
186
  /** Mirrors `alpha2_model::MAX_TEXT_ANIMATORS`. */
@@ -291,6 +295,7 @@ export const COLOR_PRIMARIES_VALUES = [
291
295
  "bt601",
292
296
  "bt709",
293
297
  "bt2020",
298
+ "display_p3",
294
299
  ];
295
300
  /** Every {@link ColorRange}, in the model's order. */
296
301
  export const COLOR_RANGE_VALUES = ["limited", "full"];
@@ -554,6 +554,7 @@ export const PROJECT_SHAPE = {
554
554
  { const: "bt601", type: "string" },
555
555
  { const: "bt709", type: "string" },
556
556
  { const: "bt2020", type: "string" },
557
+ { const: "display_p3", type: "string" },
557
558
  ],
558
559
  },
559
560
  ColorRange: {
@@ -1875,9 +1876,11 @@ export const PROJECT_SHAPE = {
1875
1876
  additionalProperties: false,
1876
1877
  properties: {
1877
1878
  artifact_sha256: { type: "string" },
1879
+ manifest_sha256: { type: "string" },
1880
+ supplied: { items: { $ref: "#/$defs/SuppliedFile" }, type: "array" },
1878
1881
  version: { type: "string" },
1879
1882
  },
1880
- required: ["version", "artifact_sha256"],
1883
+ required: ["version", "artifact_sha256", "manifest_sha256"],
1881
1884
  type: "object",
1882
1885
  },
1883
1886
  MaskMode: {
@@ -2775,6 +2778,16 @@ export const PROJECT_SHAPE = {
2775
2778
  required: ["vertices"],
2776
2779
  type: "object",
2777
2780
  },
2781
+ SuppliedFile: {
2782
+ additionalProperties: false,
2783
+ properties: {
2784
+ bytes: { format: "uint64", minimum: 0, type: "integer" },
2785
+ name: { type: "string" },
2786
+ sha256: { type: "string" },
2787
+ },
2788
+ required: ["name", "sha256", "bytes"],
2789
+ type: "object",
2790
+ },
2778
2791
  TextAlign: {
2779
2792
  oneOf: [
2780
2793
  { const: "start", type: "string" },
@@ -10,16 +10,24 @@
10
10
  /** GPU loss details, read before the lost renderer is freed. */
11
11
  export interface GpuLossReport {
12
12
  /**
13
- * The longest recent submission ran for at least half the GPU watchdog, so the loss was most
14
- * likely caused by this work and would recur.
13
+ * A recent submission ran for at least half the GPU watchdog, or submissions completed together
14
+ * did and ran more than twice their predicted time, so the loss was most likely caused by this
15
+ * work and would recur. The other fields describe that submission, else the longest.
15
16
  */
16
17
  readonly hung: boolean;
17
- /** Export frame index of the longest submission, when known. */
18
+ /** Export frame index of the submission, the first one's for several, when known. */
18
19
  readonly frameIndex: number | null;
19
- /** Timeline time of the longest submission, when known. */
20
+ /** Timeline time of that frame, when known. */
20
21
  readonly timeTicks: bigint | null;
21
- /** GPU time of the longest recent submission. */
22
+ /**
23
+ * GPU time of the submission, or of all `submissions` together; an upper bound unless
24
+ * `measured`.
25
+ */
22
26
  readonly gpuMs: number | null;
27
+ /** Whether `gpuMs` was measured: its start and its end were each seen as they happened. */
28
+ readonly measured: boolean;
29
+ /** Submissions whose completions were seen together, so only their total is known. */
30
+ readonly submissions: number | null;
23
31
  /** One-line message for the user. */
24
32
  readonly message: string;
25
33
  }
@@ -72,7 +72,7 @@ export class GpuRecoveryLadder {
72
72
  if (this.#renderer === "cpu")
73
73
  return this.#take(2, "recovery already moved to the CPU renderer");
74
74
  if (report.hung)
75
- return this.#take(2, `the GPU was lost while this work ran ${report.gpuMs ?? "?"} ms in one submission; the same work on the GPU would stop it again`);
75
+ return this.#take(2, `the GPU was lost after ${ranFor(report)}; the same work on the GPU would stop it again`);
76
76
  if (recurred)
77
77
  return this.#take(2, "the GPU was lost again at the same frame");
78
78
  if (this.#losses.count() >= this.#maxGpuLosses)
@@ -107,6 +107,12 @@ export class GpuRecoveryLadder {
107
107
  return Object.freeze({ renderer, surface: RUNG_SURFACES[index], reason });
108
108
  }
109
109
  }
110
+ function ranFor(report) {
111
+ const ms = report.gpuMs ?? "?";
112
+ return report.submissions !== null && report.submissions > 1
113
+ ? `${report.submissions} submissions completed together ${report.measured ? "in" : "within"} ${ms} ms`
114
+ : `one submission ran ${report.measured ? "" : "up to "}${ms} ms`;
115
+ }
110
116
  /**
111
117
  * Parses a wasm renderer's `lossReport` JSON, or returns a plain lost-device report with
112
118
  * `fallbackMessage` when there is none.
@@ -118,18 +124,23 @@ export function lossReportFromJson(json, fallbackMessage = "the GPU device was l
118
124
  frameIndex: null,
119
125
  timeTicks: null,
120
126
  gpuMs: null,
127
+ measured: false,
128
+ submissions: null,
121
129
  message: fallbackMessage,
122
130
  };
123
131
  const value = JSON.parse(json);
124
- const hung = value.hung === true;
125
- const gpuMs = typeof value.gpuMs === "number" ? value.gpuMs : null;
126
- return {
127
- hung,
132
+ const report = {
133
+ hung: value.hung === true,
128
134
  frameIndex: typeof value.frameIndex === "number" ? value.frameIndex : null,
129
135
  timeTicks: typeof value.timeTicks === "string" ? BigInt(value.timeTicks) : null,
130
- gpuMs,
131
- message: hung
132
- ? `the GPU device hung: one submission ran ${gpuMs} ms against a ${value.watchdogMs} ms watchdog`
136
+ gpuMs: typeof value.gpuMs === "number" ? value.gpuMs : null,
137
+ measured: value.measured === true,
138
+ submissions: typeof value.submissions === "number" ? value.submissions : null,
139
+ };
140
+ return {
141
+ ...report,
142
+ message: report.hung
143
+ ? `the GPU device hung: ${ranFor(report)} against a ${value.watchdogMs} ms watchdog`
133
144
  : fallbackMessage,
134
145
  };
135
146
  }
@@ -46,6 +46,8 @@ export function colorMetadataFromVideoColorSpace(space) {
46
46
  switch (named?.primaries) {
47
47
  case "bt2020":
48
48
  return "bt2020";
49
+ case "smpte432":
50
+ return "display_p3";
49
51
  case "bt470bg":
50
52
  case "smpte170m":
51
53
  return "bt601";
@@ -0,0 +1,3 @@
1
+ import { type Source } from "mediabunny";
2
+ import type { MediabunnyInput } from "./mediabunny.js";
3
+ export declare function mediaSource(resource: MediabunnyInput): Source;
@@ -0,0 +1,13 @@
1
+ import { BlobSource, BufferSource, CustomSource, } from "mediabunny";
2
+ import { isRangeReader } from "./media.js";
3
+ export function mediaSource(resource) {
4
+ if (resource instanceof Blob)
5
+ return new BlobSource(resource);
6
+ if (isRangeReader(resource))
7
+ return new CustomSource({
8
+ getSize: () => resource.size,
9
+ read: (start, end) => resource.read(start, end),
10
+ prefetchProfile: "network",
11
+ });
12
+ return new BufferSource(resource);
13
+ }
package/dist/media.d.ts CHANGED
@@ -75,7 +75,18 @@ export interface VideoOrientation {
75
75
  }
76
76
  /** Shown as stored. */
77
77
  export declare const UPRIGHT: VideoOrientation;
78
- export type ContainerBytes = Blob | ArrayBuffer | ArrayBufferView;
78
+ /**
79
+ * Media read in byte ranges rather than held whole, such as a file a URL serves. `read` resolves
80
+ * bytes `[start, end)`, `0 <= start <= end <= size`.
81
+ */
82
+ export interface RangeReader {
83
+ readonly size: number;
84
+ readonly name?: string;
85
+ read(start: number, end: number): Promise<Uint8Array>;
86
+ }
87
+ /** Whether `value` is a {@link RangeReader} rather than a `Blob` or bytes. */
88
+ export declare function isRangeReader(value: unknown): value is RangeReader;
89
+ export type ContainerBytes = Blob | ArrayBuffer | ArrayBufferView | RangeReader;
79
90
  /**
80
91
  * Reads track `trackId`'s orientation, mirror included, from MP4/QuickTime `tkhd`/`mvhd` matrices
81
92
  * or the Matroska projection pose, as `FFmpeg` does. `trackId` is mediabunny's `InputTrack.id`.
package/dist/media.js CHANGED
@@ -209,6 +209,16 @@ export const UPRIGHT = Object.freeze({
209
209
  rotationDegrees: 0,
210
210
  mirror: false,
211
211
  });
212
+ /** Whether `value` is a {@link RangeReader} rather than a `Blob` or bytes. */
213
+ export function isRangeReader(value) {
214
+ return (typeof value === "object" &&
215
+ value !== null &&
216
+ !(value instanceof Blob) &&
217
+ !(value instanceof ArrayBuffer) &&
218
+ !ArrayBuffer.isView(value) &&
219
+ typeof value.read === "function" &&
220
+ typeof value.size === "number");
221
+ }
212
222
  const MAX_HEADER_SCAN_BYTES = 64 * 1024 * 1024;
213
223
  /** Boxes one level of an MP4 walk visits; each costs one 16-byte read, wherever it starts. */
214
224
  const MAX_BOXES_PER_LEVEL = 4096;
@@ -235,7 +245,9 @@ class ByteReader {
235
245
  constructor(container) {
236
246
  this.#container = container;
237
247
  this.size =
238
- container instanceof Blob ? container.size : container.byteLength;
248
+ container instanceof Blob || isRangeReader(container)
249
+ ? container.size
250
+ : container.byteLength;
239
251
  }
240
252
  async read(offset, length) {
241
253
  const end = Math.min(this.size, offset + length);
@@ -244,6 +256,8 @@ class ByteReader {
244
256
  const container = this.#container;
245
257
  if (container instanceof Blob)
246
258
  return new Uint8Array(await container.slice(offset, end).arrayBuffer());
259
+ if (isRangeReader(container))
260
+ return container.read(offset, end);
247
261
  if (container instanceof ArrayBuffer)
248
262
  return new Uint8Array(container, offset, end - offset);
249
263
  return new Uint8Array(container.buffer, container.byteOffset + offset, end - offset);
@@ -2,6 +2,7 @@ import { type ChromaSiting } from "./chroma-siting.js";
2
2
  import type { AacEncoderProbe, VideoLatencyProbe } from "./export-metrics.js";
3
3
  export type { AacEncoderProbe, AacProbeOutcome, EncoderProbeOutcome, VideoLatencyProbe, } from "./export-metrics.js";
4
4
  import { EncodedPacketSink, type InputAudioTrack, type InputVideoTrack, Quality } from "mediabunny";
5
+ import { type RangeReader } from "./media.js";
5
6
  import type { AudioDecoderRefillRequest, AudioSpeaker, BrowserDecodedFrame, BrowserAudioBlock, BrowserAudioDecoder, BrowserVideoDecoder, BrowserVideoDecoderOptions, DecoderRefillRequest, OptionalMediaAdapterFactory } from "./media.js";
6
7
  import { type TrackDecodeFacts } from "./hdr-frames.js";
7
8
  import type { ColorMetadata } from "./generated/project-schema.js";
@@ -11,7 +12,9 @@ import type { BrowserEncodeSink, ExportedFrame } from "./exporter.js";
11
12
  import type { VideoRateControl } from "./rate-control.js";
12
13
  import { type ExportContainer } from "./containers.js";
13
14
  import type { PositionedWrite } from "./export-destination.js";
14
- export type MediabunnyInput = Blob | ArrayBuffer | ArrayBufferView;
15
+ export type { RangeReader } from "./media.js";
16
+ /** Media to read: a `Blob`, bytes, or a {@link RangeReader} read by byte range. */
17
+ export type MediabunnyInput = Blob | ArrayBuffer | ArrayBufferView | RangeReader;
15
18
  /** Limits for {@link MediabunnyVideoDecoder.open}, on top of the shared decoder options. */
16
19
  export interface MediabunnyVideoDecoderOptions extends BrowserVideoDecoderOptions {
17
20
  /**