alpha2 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +51 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +125 -176
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/frames.d.ts +23 -0
- package/dist/frames.js +34 -0
- package/dist/generated/project-schema.d.ts +712 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +276 -16
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +48 -63
- package/dist/layout.js +37 -37
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +178 -246
- package/dist/mediabunny.js +781 -583
- package/dist/paint.d.ts +23 -0
- package/dist/paint.js +37 -0
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +74 -118
- package/dist/project.js +384 -445
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +97 -71
- package/dist/text.js +33 -70
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -95
- package/dist/worker.js +235 -143
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +501 -587
- package/wasm/alpha2_wasm.js +661 -616
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
package/dist/hdr-frames.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
12
|
+
/** A decoded frame copied out as planar YUV. */
|
|
13
13
|
export interface PlanarYuvFrame {
|
|
14
14
|
readonly kind: "yuv-frame";
|
|
15
|
-
/** WebCodecs pixel format
|
|
15
|
+
/** WebCodecs pixel format. */
|
|
16
16
|
readonly format: string;
|
|
17
|
-
/** Size of the copied planes
|
|
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,115 +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
|
-
/**
|
|
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
|
-
*
|
|
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
|
|
50
|
+
* How a host converts decoded SDR `VideoFrame`s.
|
|
62
51
|
*
|
|
63
|
-
* `"engine"` (
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* frame
|
|
67
|
-
*
|
|
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
59
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* decoding it again in software can.
|
|
60
|
+
* The frame has no planar YUV format the engine reads: it is opaque (`format` null) or RGB.
|
|
61
|
+
* Retrying the read cannot help.
|
|
78
62
|
*/
|
|
79
63
|
export declare class NonPlanarVideoFrameError extends Error {
|
|
64
|
+
readonly code = "NON_PLANAR_FRAME";
|
|
80
65
|
readonly format: VideoPixelFormat | null;
|
|
81
66
|
constructor(format: VideoPixelFormat | null);
|
|
82
67
|
}
|
|
83
|
-
/**
|
|
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`. */
|
|
84
116
|
export declare function isPlanarVideoFrame(frame: VideoFrame): boolean;
|
|
85
|
-
/** Whether
|
|
117
|
+
/** Whether the frame's own color space is HDR. */
|
|
86
118
|
export declare function isHdrVideoFrame(frame: VideoFrame): boolean;
|
|
87
119
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* upload has taken the bytes (an engine upload copies them into wasm memory before it returns).
|
|
92
|
-
* 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.
|
|
93
123
|
*/
|
|
94
124
|
export declare class PlanarCopyPool {
|
|
95
125
|
#private;
|
|
96
|
-
/** Keeps at most `maxFree`
|
|
126
|
+
/** Keeps at most `maxFree` idle buffers. */
|
|
97
127
|
constructor(maxFree?: number);
|
|
98
|
-
/** `bytes` bytes
|
|
128
|
+
/** Returns a view of `bytes` bytes over a kept buffer, or a new one. */
|
|
99
129
|
acquire(bytes: number): Uint8Array;
|
|
100
|
-
/**
|
|
130
|
+
/** Returns the buffer under `data` to the pool; `data` must not be used afterwards. */
|
|
101
131
|
release(data: Uint8Array): void;
|
|
102
|
-
/** Drops every kept buffer. */
|
|
103
132
|
clear(): void;
|
|
104
|
-
/**
|
|
133
|
+
/** Total bytes of idle buffers. */
|
|
105
134
|
get keptBytes(): number;
|
|
106
135
|
}
|
|
107
136
|
/**
|
|
108
|
-
* Copies `frame` out as planar YUV and closes it.
|
|
109
|
-
*
|
|
110
|
-
* `declared` is the color the project declares for the source, which wins
|
|
111
|
-
* over the frame's own color space, as it does natively. A frame without a
|
|
112
|
-
* CPU-readable planar format (a hardware frame the browser will not map) is
|
|
113
|
-
* refused rather than converted by the browser.
|
|
137
|
+
* Copies `frame` out as planar YUV and always closes it. `declared` color overrides the frame's own
|
|
138
|
+
* color space.
|
|
114
139
|
*
|
|
115
|
-
* `
|
|
116
|
-
* {@link NonPlanarVideoFrameError} when the frame has no planar format the
|
|
117
|
-
* engine reads, and otherwise when it has no visible rectangle or `copyTo`
|
|
118
|
-
* fails.
|
|
140
|
+
* With `pool`, `data` comes from the pool and the caller releases it after uploading.
|
|
119
141
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
142
|
+
* Rejects with {@link NonPlanarVideoFrameError} for a frame without a planar format, and otherwise
|
|
143
|
+
* when it has no visible rectangle or `copyTo` fails.
|
|
122
144
|
*/
|
|
123
145
|
export declare function copyPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
|
|
124
146
|
/**
|
|
125
|
-
* {@link copyPlanarYuvFrame} without closing `frame
|
|
126
|
-
* or not, so a frame whose planes the browser could not read back can be read again. Rejects as
|
|
127
|
-
* {@link copyPlanarYuvFrame} does, with {@link NonPlanarVideoFrameError} for a frame no read can
|
|
128
|
-
* copy; with `pool`, a failed copy gives its buffer back.
|
|
147
|
+
* {@link copyPlanarYuvFrame} without closing `frame`, so a failed readback can be retried.
|
|
129
148
|
*
|
|
130
149
|
* @internal For `FrameSupply`.
|
|
131
150
|
*/
|
|
132
151
|
export declare function readPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
|
|
133
|
-
/**
|
|
134
|
-
* Uploads a planar frame for the engine to convert and present at
|
|
135
|
-
* `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
|
|
136
|
-
* the engine's `uploadYuvFrame` throws.
|
|
137
|
-
*/
|
|
152
|
+
/** Uploads a planar frame, shown upright at `outputWidth` by `outputHeight`. */
|
|
138
153
|
export declare function uploadPlanarYuvFrame(engine: PlanarYuvEngine, sourceId: string, mediaTimeTicks: bigint, frame: PlanarYuvFrame, outputWidth: number, outputHeight: number): FrameUploadReceipt;
|
package/dist/hdr-frames.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// Decoded frames reach the engine as planar YUV
|
|
2
|
-
//
|
|
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
|
-
*
|
|
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
|
|
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) {
|
|
@@ -79,84 +75,158 @@ export function colorMetadataFromVideoColorSpace(space) {
|
|
|
79
75
|
};
|
|
80
76
|
}
|
|
81
77
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* decoding it again in software can.
|
|
78
|
+
* The frame has no planar YUV format the engine reads: it is opaque (`format` null) or RGB.
|
|
79
|
+
* Retrying the read cannot help.
|
|
85
80
|
*/
|
|
86
81
|
export class NonPlanarVideoFrameError extends Error {
|
|
82
|
+
code = "NON_PLANAR_FRAME";
|
|
87
83
|
format;
|
|
88
84
|
constructor(format) {
|
|
89
|
-
super(`frame has no planar YUV format the engine reads (${format ?? "opaque"})
|
|
85
|
+
super(`frame has no planar YUV format the engine reads (${format ?? "opaque"})`);
|
|
90
86
|
this.name = "NonPlanarVideoFrameError";
|
|
91
87
|
this.format = format;
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
|
-
/**
|
|
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`. */
|
|
95
175
|
export function isPlanarVideoFrame(frame) {
|
|
96
176
|
return frame.format !== null && PLANAR_FORMATS.has(frame.format);
|
|
97
177
|
}
|
|
98
|
-
/** Whether
|
|
178
|
+
/** Whether the frame's own color space is HDR. */
|
|
99
179
|
export function isHdrVideoFrame(frame) {
|
|
100
180
|
const transfer = frame.colorSpace?.transfer;
|
|
101
181
|
return transfer === "pq" || transfer === "hlg";
|
|
102
182
|
}
|
|
103
183
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* upload has taken the bytes (an engine upload copies them into wasm memory before it returns).
|
|
108
|
-
* 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.
|
|
109
187
|
*/
|
|
110
188
|
export class PlanarCopyPool {
|
|
111
189
|
#maxFree;
|
|
112
190
|
#free = [];
|
|
113
|
-
/** Keeps at most `maxFree`
|
|
191
|
+
/** Keeps at most `maxFree` idle buffers. */
|
|
114
192
|
constructor(maxFree = 2) {
|
|
115
193
|
if (!Number.isSafeInteger(maxFree) || maxFree < 0)
|
|
116
194
|
throw new RangeError("maxFree must be a non-negative safe integer");
|
|
117
195
|
this.#maxFree = maxFree;
|
|
118
196
|
}
|
|
119
|
-
/** `bytes` bytes
|
|
197
|
+
/** Returns a view of `bytes` bytes over a kept buffer, or a new one. */
|
|
120
198
|
acquire(bytes) {
|
|
121
|
-
//
|
|
199
|
+
// Sorted smallest first, so this finds the best fit.
|
|
122
200
|
const index = this.#free.findIndex((buffer) => buffer.byteLength >= bytes);
|
|
123
201
|
const kept = index < 0 ? undefined : this.#free.splice(index, 1)[0];
|
|
124
202
|
return new Uint8Array(kept ?? new ArrayBuffer(bytes), 0, bytes);
|
|
125
203
|
}
|
|
126
|
-
/**
|
|
204
|
+
/** Returns the buffer under `data` to the pool; `data` must not be used afterwards. */
|
|
127
205
|
release(data) {
|
|
128
206
|
const buffer = data.buffer;
|
|
129
207
|
if (!(buffer instanceof ArrayBuffer) || this.#free.includes(buffer))
|
|
130
208
|
return;
|
|
131
209
|
this.#free.push(buffer);
|
|
132
210
|
this.#free.sort((left, right) => left.byteLength - right.byteLength);
|
|
133
|
-
//
|
|
211
|
+
// Evict the smallest, since larger buffers serve every size.
|
|
134
212
|
this.#free.splice(0, Math.max(0, this.#free.length - this.#maxFree));
|
|
135
213
|
}
|
|
136
|
-
/** Drops every kept buffer. */
|
|
137
214
|
clear() {
|
|
138
215
|
this.#free = [];
|
|
139
216
|
}
|
|
140
|
-
/**
|
|
217
|
+
/** Total bytes of idle buffers. */
|
|
141
218
|
get keptBytes() {
|
|
142
219
|
return this.#free.reduce((sum, buffer) => sum + buffer.byteLength, 0);
|
|
143
220
|
}
|
|
144
221
|
}
|
|
145
222
|
/**
|
|
146
|
-
* Copies `frame` out as planar YUV and closes it.
|
|
147
|
-
*
|
|
148
|
-
* `declared` is the color the project declares for the source, which wins
|
|
149
|
-
* over the frame's own color space, as it does natively. A frame without a
|
|
150
|
-
* CPU-readable planar format (a hardware frame the browser will not map) is
|
|
151
|
-
* 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.
|
|
152
225
|
*
|
|
153
|
-
* `
|
|
154
|
-
* {@link NonPlanarVideoFrameError} when the frame has no planar format the
|
|
155
|
-
* engine reads, and otherwise when it has no visible rectangle or `copyTo`
|
|
156
|
-
* fails.
|
|
226
|
+
* With `pool`, `data` comes from the pool and the caller releases it after uploading.
|
|
157
227
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
228
|
+
* Rejects with {@link NonPlanarVideoFrameError} for a frame without a planar format, and otherwise
|
|
229
|
+
* when it has no visible rectangle or `copyTo` fails.
|
|
160
230
|
*/
|
|
161
231
|
export async function copyPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
162
232
|
try {
|
|
@@ -167,10 +237,7 @@ export async function copyPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
|
167
237
|
}
|
|
168
238
|
}
|
|
169
239
|
/**
|
|
170
|
-
* {@link copyPlanarYuvFrame} without closing `frame
|
|
171
|
-
* or not, so a frame whose planes the browser could not read back can be read again. Rejects as
|
|
172
|
-
* {@link copyPlanarYuvFrame} does, with {@link NonPlanarVideoFrameError} for a frame no read can
|
|
173
|
-
* copy; with `pool`, a failed copy gives its buffer back.
|
|
240
|
+
* {@link copyPlanarYuvFrame} without closing `frame`, so a failed readback can be retried.
|
|
174
241
|
*
|
|
175
242
|
* @internal For `FrameSupply`.
|
|
176
243
|
*/
|
|
@@ -181,7 +248,7 @@ export async function readPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
|
181
248
|
const visible = frame.visibleRect;
|
|
182
249
|
if (!visible)
|
|
183
250
|
throw new Error("frame has no visible rectangle");
|
|
184
|
-
// copyTo copies the visible rectangle by default
|
|
251
|
+
// `copyTo` copies only the visible rectangle by default.
|
|
185
252
|
const size = frame.allocationSize();
|
|
186
253
|
const data = pool?.acquire(size) ?? new Uint8Array(size);
|
|
187
254
|
let planes;
|
|
@@ -212,11 +279,7 @@ export async function readPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
|
212
279
|
...(identity.mirror === undefined ? {} : { mirror: identity.mirror }),
|
|
213
280
|
};
|
|
214
281
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Uploads a planar frame for the engine to convert and present at
|
|
217
|
-
* `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
|
|
218
|
-
* the engine's `uploadYuvFrame` throws.
|
|
219
|
-
*/
|
|
282
|
+
/** Uploads a planar frame, shown upright at `outputWidth` by `outputHeight`. */
|
|
220
283
|
export function uploadPlanarYuvFrame(engine, sourceId, mediaTimeTicks, frame, outputWidth, outputHeight) {
|
|
221
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);
|
|
222
285
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,14 +7,20 @@ 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 "./frames.js";
|
|
14
|
+
export * from "./frame-intake.js";
|
|
15
|
+
export * from "./gpu-recovery.js";
|
|
12
16
|
export * from "./hdr-frames.js";
|
|
13
17
|
export * from "./loudness.js";
|
|
14
18
|
export * from "./media.js";
|
|
19
|
+
export * from "./paint.js";
|
|
15
20
|
export * from "./player.js";
|
|
16
21
|
export * from "./project.js";
|
|
17
22
|
export * from "./rate-control.js";
|
|
23
|
+
export * from "./renderer-choice.js";
|
|
18
24
|
export * from "./robustness.js";
|
|
19
25
|
export * from "./text.js";
|
|
20
26
|
export * from "./waveform.js";
|
package/dist/index.js
CHANGED
|
@@ -7,14 +7,20 @@ 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 "./frames.js";
|
|
14
|
+
export * from "./frame-intake.js";
|
|
15
|
+
export * from "./gpu-recovery.js";
|
|
12
16
|
export * from "./hdr-frames.js";
|
|
13
17
|
export * from "./loudness.js";
|
|
14
18
|
export * from "./media.js";
|
|
19
|
+
export * from "./paint.js";
|
|
15
20
|
export * from "./player.js";
|
|
16
21
|
export * from "./project.js";
|
|
17
22
|
export * from "./rate-control.js";
|
|
23
|
+
export * from "./renderer-choice.js";
|
|
18
24
|
export * from "./robustness.js";
|
|
19
25
|
export * from "./text.js";
|
|
20
26
|
export * from "./waveform.js";
|
package/dist/json-text.d.ts
CHANGED
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads JSON text
|
|
3
|
-
* `JSON.parse` forgets.
|
|
2
|
+
* Reads JSON text the way the engine's parser (`serde_json`) does.
|
|
4
3
|
*
|
|
5
|
-
* `JSON.parse`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
/**
|
|
8
|
+
/** Source details the parsed value does not show. */
|
|
16
9
|
export interface JsonSpelling {
|
|
17
10
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
-
/**
|
|
16
|
+
/** Keys given more than once, per object. */
|
|
25
17
|
readonly repeated: WeakMap<object, Set<string>>;
|
|
26
18
|
}
|
|
27
|
-
/**
|
|
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
|
-
*
|
|
31
|
-
*
|
|
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
|
|
3
|
-
* `JSON.parse` forgets.
|
|
2
|
+
* Reads JSON text the way the engine's parser (`serde_json`) does.
|
|
4
3
|
*
|
|
5
|
-
* `JSON.parse`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
/**
|
|
8
|
+
/** Deepest nesting the engine's parser accepts (the `serde_json` recursion limit). */
|
|
16
9
|
export const MAX_JSON_DEPTH = 127;
|
|
17
10
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
|
|
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;
|
|
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
|
}
|