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
@@ -2,19 +2,19 @@ import type { ChromaSiting } from "./chroma-siting.js";
2
2
  import type { FrameUploadReceipt } from "./effects.js";
3
3
  import type { ColorMetadata } from "./generated/project-schema.js";
4
4
  export { type ChromaSiting, chromaSitingForCodec, chromaSitingForStream, type SampleAspect, sampleAspectForStream, } from "./chroma-siting.js";
5
- /** What a planar copy carries of its frame's identity beyond the frame itself. */
5
+ /** Frame metadata a planar copy carries beyond the `VideoFrame` itself. */
6
6
  export interface PlanarFrameIdentity {
7
7
  readonly physicalTimeMicroseconds?: number;
8
8
  readonly rotation?: 0 | 90 | 180 | 270;
9
9
  readonly mirror?: boolean;
10
10
  readonly chromaSiting?: ChromaSiting;
11
11
  }
12
- /** A decoded frame copied out as planar YUV, with the color it carries. */
12
+ /** A decoded frame copied out as planar YUV. */
13
13
  export interface PlanarYuvFrame {
14
14
  readonly kind: "yuv-frame";
15
- /** WebCodecs pixel format, one of the planar formats the engine reads. */
15
+ /** WebCodecs pixel format. */
16
16
  readonly format: string;
17
- /** Size of the copied planes: the frame's visible picture. */
17
+ /** Size of the copied planes, which hold only the visible picture. */
18
18
  readonly codedWidth: number;
19
19
  readonly codedHeight: number;
20
20
  readonly data: Uint8Array;
@@ -24,104 +24,130 @@ export interface PlanarYuvFrame {
24
24
  readonly visibleRect: readonly [number, number, number, number];
25
25
  readonly color: ColorMetadata;
26
26
  readonly chromaSiting: ChromaSiting;
27
- /**
28
- * Size the picture is shown at before it turns: its pixel aspect ratio, which the engine applies.
29
- */
27
+ /** Display size before rotation; carries the pixel aspect ratio. */
30
28
  readonly displayWidth: number;
31
29
  readonly displayHeight: number;
32
30
  readonly physicalTimeMicroseconds: number;
33
31
  readonly durationMicroseconds?: number;
34
32
  /** Clockwise turn that shows the frame upright, after {@link mirror}. */
35
33
  readonly rotation?: 0 | 90 | 180 | 270;
36
- /** Whether the frame is mirrored left to right before it turns. */
34
+ /** Mirror left to right before rotating. */
37
35
  readonly mirror?: boolean;
38
36
  }
39
37
  /** Engine surface that converts planar YUV with the project's color pipeline. */
40
38
  export interface PlanarYuvEngine {
41
- /**
42
- * Uploads one planar frame for `sourceId` at `mediaTimeTicks`, to be
43
- * converted with the project's color pipeline and shown upright at
44
- * `outputWidth` x `outputHeight`.
45
- */
39
+ /** Uploads one planar frame, shown upright at `outputWidth` by `outputHeight`. */
46
40
  uploadYuvFrame(sourceId: string, mediaTimeTicks: bigint, format: string, codedWidth: number, codedHeight: number, data: Uint8Array, layout: Uint32Array, visibleRect: Uint32Array,
47
- /**
48
- * Size the visible picture is shown at before it turns (a `VideoFrame`'s display size): its
49
- * pixel aspect ratio.
50
- */
41
+ /** Display size before rotation; carries the pixel aspect ratio. */
51
42
  displayWidth: number, displayHeight: number, colorJson: string, chromaSiting: ChromaSiting, outputWidth: number, outputHeight: number, rotationDegrees: number, mirror: boolean): FrameUploadReceipt;
52
43
  }
53
44
  /**
54
- * The engine's color description of a WebCodecs color space.
55
- *
56
- * Unspecified parts take the SDR BT.709 limited-range defaults; a PQ or HLG
57
- * transfer makes the signal HDR.
45
+ * Converts a WebCodecs color space to engine color metadata. Unspecified parts default to SDR
46
+ * BT.709 limited range; a PQ or HLG transfer marks the signal HDR.
58
47
  */
59
48
  export declare function colorMetadataFromVideoColorSpace(space: VideoColorSpaceInit | null | undefined): ColorMetadata;
60
49
  /**
61
- * How a host turns decoded SDR `VideoFrame`s into the engine's pixels.
50
+ * How a host converts decoded SDR `VideoFrame`s.
62
51
  *
63
- * `"engine"` (the default) copies each frame that has a planar format the engine reads out with
64
- * `copyTo` and converts it with the engine's shader, as a native host converts the same stream:
65
- * the frame's own color space, and the chroma siting its decoder reports (`chromaSiting`). A
66
- * frame without such a format (an opaque hardware frame) still goes through the browser.
67
- * `"browser"` imports SDR frames as textures instead, which saves the copy (in Chrome on a desktop
68
- * GPU about 1 ms a 1080p frame, 4 to 5 ms a 4K one) but leaves the conversion to the browser, which
69
- * does not read the stream's siting: Chrome converts H.264 and HEVC chroma, sited left, as if
70
- * centered, so every sharp chroma edge lands apart from a native export's. HDR frames, and frames
71
- * of a source whose color the project declares, are the engine's either way.
52
+ * `"engine"` (default) copies planar frames with `copyTo` and converts them in the engine's shader,
53
+ * matching a native export; opaque hardware frames still go through the browser. `"browser"`
54
+ * imports SDR frames as textures, saving the copy (roughly 1 ms per 1080p frame, 4 to 5 ms per 4K
55
+ * frame on a desktop GPU) but ignoring chroma siting, so chroma edges differ from a native export.
56
+ * HDR frames and sources with project-declared color always use the engine.
72
57
  */
73
58
  export type VideoConversion = "engine" | "browser";
74
- /** Whether `frame` has a planar format the engine converts (`copyPlanarYuvFrame` can copy it). */
59
+ /**
60
+ * The frame has no planar YUV format the engine reads: it is opaque (`format` null) or RGB.
61
+ * Retrying the read cannot help.
62
+ */
63
+ export declare class NonPlanarVideoFrameError extends Error {
64
+ readonly code = "NON_PLANAR_FRAME";
65
+ readonly format: VideoPixelFormat | null;
66
+ constructor(format: VideoPixelFormat | null);
67
+ }
68
+ /** Facts about a track the browser could not decode, used to build the refusal message. */
69
+ export interface TrackDecodeFacts {
70
+ readonly kind: "video" | "audio";
71
+ /** WebCodecs string (`hvc1.2.4.L93.B0`) or short name; null when unknown. */
72
+ readonly codec: string | null;
73
+ readonly bitDepth?: number;
74
+ readonly chroma?: "420" | "422" | "444";
75
+ /** Transfer (`pq`, `hlg`, `bt709`); null when undeclared. */
76
+ readonly transfer?: string | null;
77
+ readonly channels?: number;
78
+ /** Speaker names (`FL FR FC`). */
79
+ readonly layout?: readonly string[];
80
+ /** Decoded frame format; null for an opaque frame. */
81
+ readonly frameFormat?: VideoPixelFormat | null;
82
+ readonly softwareDecoder?: "none" | "opaque" | "planar";
83
+ /** The browser's error, for diagnostics only. */
84
+ readonly browserError?: string;
85
+ }
86
+ /** A refused track is invalid input, since the same file always fails the same way. */
87
+ export interface DecodeRefusalFailure {
88
+ readonly code: "INVALID_INPUT";
89
+ readonly phase: "decode";
90
+ readonly stage: "decode-unavailable" | "planar-decode-unavailable";
91
+ }
92
+ /** This browser cannot decode the track at all. */
93
+ export declare class DecodeUnavailableError extends Error {
94
+ readonly code = "DECODE_UNAVAILABLE";
95
+ readonly facts: TrackDecodeFacts;
96
+ readonly failure: DecodeRefusalFailure;
97
+ constructor(message: string, facts: TrackDecodeFacts, options?: ErrorOptions);
98
+ }
99
+ /**
100
+ * The browser decodes the track only to opaque or RGB frames and has no planar software decoder,
101
+ * but the source needs planes (HDR or project-declared color).
102
+ */
103
+ export declare class PlanarDecodeUnavailableError extends Error {
104
+ readonly code = "PLANAR_DECODE_UNAVAILABLE";
105
+ readonly facts: TrackDecodeFacts;
106
+ readonly failure: DecodeRefusalFailure;
107
+ constructor(message: string, facts: TrackDecodeFacts, options?: ErrorOptions);
108
+ }
109
+ /** Human-readable codec name: `hvc1.2.4.L93.B0` is `HEVC`. */
110
+ export declare function codecName(codec: string | null): string;
111
+ /** Human-readable bit depth and chroma, such as `10-bit` and `4:2:2`. */
112
+ export declare function pictureDetails(facts: TrackDecodeFacts): string[];
113
+ /** User-facing refusal message built from `facts` alone, with a suggested workaround. */
114
+ export declare function decodeRefusalMessage(name: string, facts: TrackDecodeFacts): string;
115
+ /** Whether `copyPlanarYuvFrame` can copy `frame`. */
75
116
  export declare function isPlanarVideoFrame(frame: VideoFrame): boolean;
76
- /** Whether a decoded frame's own color space says it is HDR. */
117
+ /** Whether the frame's own color space is HDR. */
77
118
  export declare function isHdrVideoFrame(frame: VideoFrame): boolean;
78
119
  /**
79
- * Buffers planar copies reuse: a 4K 10-bit frame is 25 MB, which a fresh allocation zero-fills
80
- * and the garbage collector reclaims at the frame rate. A copy takes a buffer with
81
- * {@link PlanarCopyPool.acquire} and gives it back with {@link PlanarCopyPool.release} once its
82
- * upload has taken the bytes (an engine upload copies them into wasm memory before it returns).
83
- * Copies that overlap each take their own buffer.
120
+ * Reusable buffers for planar copies, avoiding a fresh zero-filled allocation per frame (25 MB for
121
+ * a 4K 10-bit frame). Release a buffer once its upload returns, since the engine copies the bytes
122
+ * into wasm memory.
84
123
  */
85
124
  export declare class PlanarCopyPool {
86
125
  #private;
87
- /** Keeps at most `maxFree` (default 2) buffers between copies. */
126
+ /** Keeps at most `maxFree` idle buffers. */
88
127
  constructor(maxFree?: number);
89
- /** `bytes` bytes to copy into: a kept buffer large enough, or a new one. */
128
+ /** Returns a view of `bytes` bytes over a kept buffer, or a new one. */
90
129
  acquire(bytes: number): Uint8Array;
91
- /** Gives back the buffer under `data`; nothing may read `data` afterwards. */
130
+ /** Returns the buffer under `data` to the pool; `data` must not be used afterwards. */
92
131
  release(data: Uint8Array): void;
93
- /** Drops every kept buffer. */
94
132
  clear(): void;
95
- /** Bytes the kept buffers hold. */
133
+ /** Total bytes of idle buffers. */
96
134
  get keptBytes(): number;
97
135
  }
98
136
  /**
99
- * Copies `frame` out as planar YUV and closes it.
137
+ * Copies `frame` out as planar YUV and always closes it. `declared` color overrides the frame's own
138
+ * color space.
100
139
  *
101
- * `declared` is the color the project declares for the source, which wins
102
- * over the frame's own color space, as it does natively. A frame without a
103
- * CPU-readable planar format (a hardware frame the browser will not map) is
104
- * refused rather than converted by the browser.
140
+ * With `pool`, `data` comes from the pool and the caller releases it after uploading.
105
141
  *
106
- * `frame` is closed whether the copy succeeds or not. Rejects when the frame
107
- * has no planar format the engine reads or no visible rectangle, or when
108
- * `copyTo` fails.
109
- *
110
- * With `pool`, the copy's `data` is a buffer from it, which the caller gives back with
111
- * {@link PlanarCopyPool.release} after uploading; a failed copy gives it back itself.
142
+ * Rejects with {@link NonPlanarVideoFrameError} for a frame without a planar format, and otherwise
143
+ * when it has no visible rectangle or `copyTo` fails.
112
144
  */
113
145
  export declare function copyPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
114
146
  /**
115
- * {@link copyPlanarYuvFrame} without closing `frame`: the caller owns it whether the copy succeeds
116
- * or not, so a frame whose planes the browser could not read back can be read again. Rejects as
117
- * {@link copyPlanarYuvFrame} does; with `pool`, a failed copy gives its buffer back.
147
+ * {@link copyPlanarYuvFrame} without closing `frame`, so a failed readback can be retried.
118
148
  *
119
149
  * @internal For `FrameSupply`.
120
150
  */
121
151
  export declare function readPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
122
- /**
123
- * Uploads a planar frame for the engine to convert and present at
124
- * `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
125
- * the engine's `uploadYuvFrame` throws.
126
- */
152
+ /** Uploads a planar frame, shown upright at `outputWidth` by `outputHeight`. */
127
153
  export declare function uploadPlanarYuvFrame(engine: PlanarYuvEngine, sourceId: string, mediaTimeTicks: bigint, frame: PlanarYuvFrame, outputWidth: number, outputHeight: number): FrameUploadReceipt;
@@ -1,6 +1,5 @@
1
- // Decoded frames reach the engine as planar YUV and are converted by the engine's shader, as
2
- // natively: a canvas or external texture would tone-map or clip HDR and misplace subsampled chroma.
3
- // SDR frames take this path too unless the host sets `videoConversion: "browser"`.
1
+ // Decoded frames reach the engine as planar YUV for its own shader to convert, because a canvas or
2
+ // external texture would tone-map or clip HDR and misplace subsampled chroma.
4
3
  /** WebCodecs pixel formats the engine converts from planar YUV. */
5
4
  const PLANAR_FORMATS = new Set([
6
5
  "I420",
@@ -25,14 +24,11 @@ const PLANAR_FORMATS = new Set([
25
24
  ]);
26
25
  export { chromaSitingForCodec, chromaSitingForStream, sampleAspectForStream, } from "./chroma-siting.js";
27
26
  /**
28
- * The engine's color description of a WebCodecs color space.
29
- *
30
- * Unspecified parts take the SDR BT.709 limited-range defaults; a PQ or HLG
31
- * transfer makes the signal HDR.
27
+ * Converts a WebCodecs color space to engine color metadata. Unspecified parts default to SDR
28
+ * BT.709 limited range; a PQ or HLG transfer marks the signal HDR.
32
29
  */
33
30
  export function colorMetadataFromVideoColorSpace(space) {
34
- // TypeScript's DOM library predates WebCodecs' HDR values ("pq", "hlg", "bt2020", "bt2020-ncl"),
35
- // so the fields are read as strings.
31
+ // TypeScript's DOM library lacks the HDR enum values, so read the fields as strings.
36
32
  const named = space;
37
33
  const transfer = (() => {
38
34
  switch (named?.transfer) {
@@ -78,71 +74,159 @@ export function colorMetadataFromVideoColorSpace(space) {
78
74
  transfer,
79
75
  };
80
76
  }
81
- /** Whether `frame` has a planar format the engine converts (`copyPlanarYuvFrame` can copy it). */
77
+ /**
78
+ * The frame has no planar YUV format the engine reads: it is opaque (`format` null) or RGB.
79
+ * Retrying the read cannot help.
80
+ */
81
+ export class NonPlanarVideoFrameError extends Error {
82
+ code = "NON_PLANAR_FRAME";
83
+ format;
84
+ constructor(format) {
85
+ super(`frame has no planar YUV format the engine reads (${format ?? "opaque"})`);
86
+ this.name = "NonPlanarVideoFrameError";
87
+ this.format = format;
88
+ }
89
+ }
90
+ /** This browser cannot decode the track at all. */
91
+ export class DecodeUnavailableError extends Error {
92
+ code = "DECODE_UNAVAILABLE";
93
+ facts;
94
+ failure = {
95
+ code: "INVALID_INPUT",
96
+ phase: "decode",
97
+ stage: "decode-unavailable",
98
+ };
99
+ constructor(message, facts, options) {
100
+ super(message, options);
101
+ this.name = "DecodeUnavailableError";
102
+ this.facts = facts;
103
+ }
104
+ }
105
+ /**
106
+ * The browser decodes the track only to opaque or RGB frames and has no planar software decoder,
107
+ * but the source needs planes (HDR or project-declared color).
108
+ */
109
+ export class PlanarDecodeUnavailableError extends Error {
110
+ code = "PLANAR_DECODE_UNAVAILABLE";
111
+ facts;
112
+ failure = {
113
+ code: "INVALID_INPUT",
114
+ phase: "decode",
115
+ stage: "planar-decode-unavailable",
116
+ };
117
+ constructor(message, facts, options) {
118
+ super(message, options);
119
+ this.name = "PlanarDecodeUnavailableError";
120
+ this.facts = facts;
121
+ }
122
+ }
123
+ const CODEC_NAMES = [
124
+ [/^(hvc1|hev1|hevc)/i, "HEVC"],
125
+ [/^(avc1|avc3|avc|h264)/i, "H.264"],
126
+ [/^(av01|av1)/i, "AV1"],
127
+ [/^(vp09|vp9)/i, "VP9"],
128
+ [/^vp8/i, "VP8"],
129
+ [/^(mp4a|aac)/i, "AAC"],
130
+ [/^opus/i, "Opus"],
131
+ [/^vorbis/i, "Vorbis"],
132
+ [/^flac/i, "FLAC"],
133
+ ];
134
+ /** Human-readable codec name: `hvc1.2.4.L93.B0` is `HEVC`. */
135
+ export function codecName(codec) {
136
+ if (codec === null || codec === "")
137
+ return "unknown";
138
+ return CODEC_NAMES.find(([pattern]) => pattern.test(codec))?.[1] ?? codec;
139
+ }
140
+ /** Human-readable bit depth and chroma, such as `10-bit` and `4:2:2`. */
141
+ export function pictureDetails(facts) {
142
+ return [
143
+ ...(facts.bitDepth === undefined ? [] : [`${facts.bitDepth}-bit`]),
144
+ ...(facts.chroma === undefined || facts.chroma === "420"
145
+ ? []
146
+ : [`4:${facts.chroma.slice(1, 2)}:${facts.chroma.slice(2)}`]),
147
+ ];
148
+ }
149
+ /** User-facing refusal message built from `facts` alone, with a suggested workaround. */
150
+ export function decodeRefusalMessage(name, facts) {
151
+ const codec = codecName(facts.codec);
152
+ if (facts.kind === "audio") {
153
+ const channels = facts.channels === undefined
154
+ ? ""
155
+ : ` with ${facts.channels} channel${facts.channels === 1 ? "" : "s"}${facts.layout && facts.layout.length > 0
156
+ ? ` (${facts.layout.join(" ")})`
157
+ : ""}`;
158
+ const stereo = facts.channels !== undefined && facts.channels > 2
159
+ ? " or convert it to stereo"
160
+ : " or convert it to AAC";
161
+ return `${name}: this browser cannot decode ${codec} audio${channels}. Use another browser${stereo}.`;
162
+ }
163
+ const hdr = facts.transfer === "pq" || facts.transfer === "hlg";
164
+ const details = [
165
+ codec,
166
+ ...pictureDetails(facts),
167
+ ...(hdr ? [facts.transfer === "pq" ? "PQ" : "HLG"] : []),
168
+ ].join(", ");
169
+ const what = `${name} is ${hdr ? "HDR " : ""}video (${details})`;
170
+ if (facts.softwareDecoder !== undefined || facts.frameFormat !== undefined)
171
+ return `${what}: this browser decodes it only to frames the engine cannot read and has no software decoder that gives planes. Convert it to H.264 High 10 or AV1 10-bit, or export with the native host.`;
172
+ return `${what}: this browser cannot decode it. Convert it to H.264 or AV1, use another browser, or export with the native host.`;
173
+ }
174
+ /** Whether `copyPlanarYuvFrame` can copy `frame`. */
82
175
  export function isPlanarVideoFrame(frame) {
83
176
  return frame.format !== null && PLANAR_FORMATS.has(frame.format);
84
177
  }
85
- /** Whether a decoded frame's own color space says it is HDR. */
178
+ /** Whether the frame's own color space is HDR. */
86
179
  export function isHdrVideoFrame(frame) {
87
180
  const transfer = frame.colorSpace?.transfer;
88
181
  return transfer === "pq" || transfer === "hlg";
89
182
  }
90
183
  /**
91
- * Buffers planar copies reuse: a 4K 10-bit frame is 25 MB, which a fresh allocation zero-fills
92
- * and the garbage collector reclaims at the frame rate. A copy takes a buffer with
93
- * {@link PlanarCopyPool.acquire} and gives it back with {@link PlanarCopyPool.release} once its
94
- * upload has taken the bytes (an engine upload copies them into wasm memory before it returns).
95
- * Copies that overlap each take their own buffer.
184
+ * Reusable buffers for planar copies, avoiding a fresh zero-filled allocation per frame (25 MB for
185
+ * a 4K 10-bit frame). Release a buffer once its upload returns, since the engine copies the bytes
186
+ * into wasm memory.
96
187
  */
97
188
  export class PlanarCopyPool {
98
189
  #maxFree;
99
190
  #free = [];
100
- /** Keeps at most `maxFree` (default 2) buffers between copies. */
191
+ /** Keeps at most `maxFree` idle buffers. */
101
192
  constructor(maxFree = 2) {
102
193
  if (!Number.isSafeInteger(maxFree) || maxFree < 0)
103
194
  throw new RangeError("maxFree must be a non-negative safe integer");
104
195
  this.#maxFree = maxFree;
105
196
  }
106
- /** `bytes` bytes to copy into: a kept buffer large enough, or a new one. */
197
+ /** Returns a view of `bytes` bytes over a kept buffer, or a new one. */
107
198
  acquire(bytes) {
108
- // Kept smallest first: the first one large enough is the smallest that fits.
199
+ // Sorted smallest first, so this finds the best fit.
109
200
  const index = this.#free.findIndex((buffer) => buffer.byteLength >= bytes);
110
201
  const kept = index < 0 ? undefined : this.#free.splice(index, 1)[0];
111
202
  return new Uint8Array(kept ?? new ArrayBuffer(bytes), 0, bytes);
112
203
  }
113
- /** Gives back the buffer under `data`; nothing may read `data` afterwards. */
204
+ /** Returns the buffer under `data` to the pool; `data` must not be used afterwards. */
114
205
  release(data) {
115
206
  const buffer = data.buffer;
116
207
  if (!(buffer instanceof ArrayBuffer) || this.#free.includes(buffer))
117
208
  return;
118
209
  this.#free.push(buffer);
119
210
  this.#free.sort((left, right) => left.byteLength - right.byteLength);
120
- // The largest serve every size, so past the limit the smallest go.
211
+ // Evict the smallest, since larger buffers serve every size.
121
212
  this.#free.splice(0, Math.max(0, this.#free.length - this.#maxFree));
122
213
  }
123
- /** Drops every kept buffer. */
124
214
  clear() {
125
215
  this.#free = [];
126
216
  }
127
- /** Bytes the kept buffers hold. */
217
+ /** Total bytes of idle buffers. */
128
218
  get keptBytes() {
129
219
  return this.#free.reduce((sum, buffer) => sum + buffer.byteLength, 0);
130
220
  }
131
221
  }
132
222
  /**
133
- * Copies `frame` out as planar YUV and closes it.
134
- *
135
- * `declared` is the color the project declares for the source, which wins
136
- * over the frame's own color space, as it does natively. A frame without a
137
- * CPU-readable planar format (a hardware frame the browser will not map) is
138
- * refused rather than converted by the browser.
223
+ * Copies `frame` out as planar YUV and always closes it. `declared` color overrides the frame's own
224
+ * color space.
139
225
  *
140
- * `frame` is closed whether the copy succeeds or not. Rejects when the frame
141
- * has no planar format the engine reads or no visible rectangle, or when
142
- * `copyTo` fails.
226
+ * With `pool`, `data` comes from the pool and the caller releases it after uploading.
143
227
  *
144
- * With `pool`, the copy's `data` is a buffer from it, which the caller gives back with
145
- * {@link PlanarCopyPool.release} after uploading; a failed copy gives it back itself.
228
+ * Rejects with {@link NonPlanarVideoFrameError} for a frame without a planar format, and otherwise
229
+ * when it has no visible rectangle or `copyTo` fails.
146
230
  */
147
231
  export async function copyPlanarYuvFrame(frame, declared, identity = {}, pool) {
148
232
  try {
@@ -153,21 +237,18 @@ export async function copyPlanarYuvFrame(frame, declared, identity = {}, pool) {
153
237
  }
154
238
  }
155
239
  /**
156
- * {@link copyPlanarYuvFrame} without closing `frame`: the caller owns it whether the copy succeeds
157
- * or not, so a frame whose planes the browser could not read back can be read again. Rejects as
158
- * {@link copyPlanarYuvFrame} does; with `pool`, a failed copy gives its buffer back.
240
+ * {@link copyPlanarYuvFrame} without closing `frame`, so a failed readback can be retried.
159
241
  *
160
242
  * @internal For `FrameSupply`.
161
243
  */
162
244
  export async function readPlanarYuvFrame(frame, declared, identity = {}, pool) {
163
245
  const format = frame.format;
164
- if (format === null || !isPlanarVideoFrame(frame)) {
165
- throw new Error(`frame has no planar YUV format the engine reads (${format ?? "opaque"}); decode HDR sources, and sources whose color the project declares, in software`);
166
- }
246
+ if (format === null || !isPlanarVideoFrame(frame))
247
+ throw new NonPlanarVideoFrameError(format);
167
248
  const visible = frame.visibleRect;
168
249
  if (!visible)
169
250
  throw new Error("frame has no visible rectangle");
170
- // copyTo copies the visible rectangle by default, so the copy is exactly the picture.
251
+ // `copyTo` copies only the visible rectangle by default.
171
252
  const size = frame.allocationSize();
172
253
  const data = pool?.acquire(size) ?? new Uint8Array(size);
173
254
  let planes;
@@ -198,11 +279,7 @@ export async function readPlanarYuvFrame(frame, declared, identity = {}, pool) {
198
279
  ...(identity.mirror === undefined ? {} : { mirror: identity.mirror }),
199
280
  };
200
281
  }
201
- /**
202
- * Uploads a planar frame for the engine to convert and present at
203
- * `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
204
- * the engine's `uploadYuvFrame` throws.
205
- */
282
+ /** Uploads a planar frame, shown upright at `outputWidth` by `outputHeight`. */
206
283
  export function uploadPlanarYuvFrame(engine, sourceId, mediaTimeTicks, frame, outputWidth, outputHeight) {
207
284
  return engine.uploadYuvFrame(sourceId, mediaTimeTicks, frame.format, frame.codedWidth, frame.codedHeight, frame.data, Uint32Array.from(frame.layout), Uint32Array.from(frame.visibleRect), frame.displayWidth, frame.displayHeight, JSON.stringify(frame.color), frame.chromaSiting, outputWidth, outputHeight, frame.rotation ?? 0, frame.mirror ?? false);
208
285
  }
package/dist/index.d.ts CHANGED
@@ -7,14 +7,18 @@ export * from "./audio-worker.js";
7
7
  export * from "./containers.js";
8
8
  export * from "./effects.js";
9
9
  export * from "./exporter.js";
10
+ export * from "./export-metrics.js";
10
11
  export * from "./extensions.js";
11
12
  export * from "./frame-supply.js";
13
+ export * from "./frame-intake.js";
14
+ export * from "./gpu-recovery.js";
12
15
  export * from "./hdr-frames.js";
13
16
  export * from "./loudness.js";
14
17
  export * from "./media.js";
15
18
  export * from "./player.js";
16
19
  export * from "./project.js";
17
20
  export * from "./rate-control.js";
21
+ export * from "./renderer-choice.js";
18
22
  export * from "./robustness.js";
19
23
  export * from "./text.js";
20
24
  export * from "./waveform.js";
package/dist/index.js CHANGED
@@ -7,14 +7,18 @@ export * from "./audio-worker.js";
7
7
  export * from "./containers.js";
8
8
  export * from "./effects.js";
9
9
  export * from "./exporter.js";
10
+ export * from "./export-metrics.js";
10
11
  export * from "./extensions.js";
11
12
  export * from "./frame-supply.js";
13
+ export * from "./frame-intake.js";
14
+ export * from "./gpu-recovery.js";
12
15
  export * from "./hdr-frames.js";
13
16
  export * from "./loudness.js";
14
17
  export * from "./media.js";
15
18
  export * from "./player.js";
16
19
  export * from "./project.js";
17
20
  export * from "./rate-control.js";
21
+ export * from "./renderer-choice.js";
18
22
  export * from "./robustness.js";
19
23
  export * from "./text.js";
20
24
  export * from "./waveform.js";
@@ -1,40 +1,30 @@
1
1
  /**
2
- * Reads JSON text as the engine's parser (serde_json) does, keeping what
3
- * `JSON.parse` forgets.
2
+ * Reads JSON text the way the engine's parser (`serde_json`) does.
4
3
  *
5
- * `JSON.parse` keeps the last of a repeated key, turns `1920.0`, `1.92e3`,
6
- * and `-0` into numbers like any other, and rounds an integer past 2^53. The
7
- * engine refuses a struct field given twice, reads those three spellings as
8
- * floating point, which no integer field accepts, and reads a 64-bit integer
9
- * exactly. {@link readJsonText} returns the same value as `JSON.parse`
10
- * together with where the text said any of these, so the shape check can
11
- * decide them field by field: a repeated key is allowed where the document
12
- * holds a map, a fractional spelling where it holds a float, and an integer
13
- * by its digits against the field's integer type.
4
+ * `JSON.parse` hides repeated keys, float spellings of integers (`1920.0`, `1.92e3`, `-0`) and
5
+ * integers past 2^53, all of which the engine treats differently. {@link readJsonText} records
6
+ * where they occur so the shape check can judge each field by its type.
14
7
  */
15
- /** Where the text said something its parsed value does not show. */
8
+ /** Source details the parsed value does not show. */
16
9
  export interface JsonSpelling {
17
10
  /**
18
- * Containers whose member, by key or index, is a number its parsed value does not spell: one
19
- * written as a float (with a fraction, an exponent, or as `-0`) or an integer past
20
- * `Number.MAX_SAFE_INTEGER`, with the member's text: every such text of a repeated key, which
21
- * the engine reads each of.
11
+ * Per container and member key or index, the source text of numbers written as floats
12
+ * (fraction, exponent or `-0`) or as integers past `Number.MAX_SAFE_INTEGER`. A repeated key
13
+ * keeps every text.
22
14
  */
23
15
  readonly numbers: WeakMap<object, Map<string | number, string[]>>;
24
- /** Objects whose text gives a key more than once, with those keys. */
16
+ /** Keys given more than once, per object. */
25
17
  readonly repeated: WeakMap<object, Set<string>>;
26
18
  }
27
- /** The deepest nesting the engine's parser reads (serde_json's recursion limit). */
19
+ /** Deepest nesting the engine's parser accepts (the `serde_json` recursion limit). */
28
20
  export declare const MAX_JSON_DEPTH = 127;
29
21
  /**
30
- * The value of `json`, which `JSON.parse` has already accepted, with its
31
- * spelling; `undefined` when it nests deeper than {@link MAX_JSON_DEPTH}.
22
+ * Parses `json`, which `JSON.parse` must already accept, with its spelling details. Returns
23
+ * `undefined` when it nests deeper than {@link MAX_JSON_DEPTH}.
32
24
  */
33
25
  export declare function readJsonText(json: string): {
34
26
  value: unknown;
35
27
  spelling: JsonSpelling;
36
28
  } | undefined;
37
- /**
38
- * Whether `text` has a UTF-16 surrogate without its pair, which UTF-8 (and the engine) cannot hold.
39
- */
29
+ /** Whether `text` has an unpaired UTF-16 surrogate, which UTF-8 cannot encode. */
40
30
  export declare function hasLoneSurrogate(text: string): boolean;
package/dist/json-text.js CHANGED
@@ -1,22 +1,15 @@
1
1
  /**
2
- * Reads JSON text as the engine's parser (serde_json) does, keeping what
3
- * `JSON.parse` forgets.
2
+ * Reads JSON text the way the engine's parser (`serde_json`) does.
4
3
  *
5
- * `JSON.parse` keeps the last of a repeated key, turns `1920.0`, `1.92e3`,
6
- * and `-0` into numbers like any other, and rounds an integer past 2^53. The
7
- * engine refuses a struct field given twice, reads those three spellings as
8
- * floating point, which no integer field accepts, and reads a 64-bit integer
9
- * exactly. {@link readJsonText} returns the same value as `JSON.parse`
10
- * together with where the text said any of these, so the shape check can
11
- * decide them field by field: a repeated key is allowed where the document
12
- * holds a map, a fractional spelling where it holds a float, and an integer
13
- * by its digits against the field's integer type.
4
+ * `JSON.parse` hides repeated keys, float spellings of integers (`1920.0`, `1.92e3`, `-0`) and
5
+ * integers past 2^53, all of which the engine treats differently. {@link readJsonText} records
6
+ * where they occur so the shape check can judge each field by its type.
14
7
  */
15
- /** The deepest nesting the engine's parser reads (serde_json's recursion limit). */
8
+ /** Deepest nesting the engine's parser accepts (the `serde_json` recursion limit). */
16
9
  export const MAX_JSON_DEPTH = 127;
17
10
  /**
18
- * The value of `json`, which `JSON.parse` has already accepted, with its
19
- * spelling; `undefined` when it nests deeper than {@link MAX_JSON_DEPTH}.
11
+ * Parses `json`, which `JSON.parse` must already accept, with its spelling details. Returns
12
+ * `undefined` when it nests deeper than {@link MAX_JSON_DEPTH}.
20
13
  */
21
14
  export function readJsonText(json) {
22
15
  const spelling = {
@@ -61,8 +54,7 @@ export function readJsonText(json) {
61
54
  ? JSON.parse(json.slice(start, at))
62
55
  : json.slice(start + 1, at - 1);
63
56
  };
64
- // Returns the member's value, and its text if it is a number its value does not spell (see
65
- // `JsonSpelling.numbers`).
57
+ // Returns the value and, for numbers recorded in `JsonSpelling.numbers`, the source text.
66
58
  const readValue = (depth) => {
67
59
  skipSpace();
68
60
  const char = json[at];
@@ -96,7 +88,7 @@ export function readJsonText(json) {
96
88
  skipSpace();
97
89
  const key = readString();
98
90
  skipSpace();
99
- at += 1; // Skip the `:`.
91
+ at += 1;
100
92
  const [item, text] = readValue(depth + 1);
101
93
  if (Object.hasOwn(object, key))
102
94
  note(spelling.repeated, object, key);
@@ -137,9 +129,7 @@ export function readJsonText(json) {
137
129
  }
138
130
  class TooDeep extends Error {
139
131
  }
140
- /**
141
- * Whether `text` has a UTF-16 surrogate without its pair, which UTF-8 (and the engine) cannot hold.
142
- */
132
+ /** Whether `text` has an unpaired UTF-16 surrogate, which UTF-8 cannot encode. */
143
133
  export function hasLoneSurrogate(text) {
144
134
  return /\p{Surrogate}/u.test(text);
145
135
  }