alpha2 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +108 -177
- 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/generated/project-schema.d.ts +701 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +261 -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 +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +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 +166 -245
- package/dist/mediabunny.js +741 -580
- 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 +73 -117
- 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 +460 -567
- package/wasm/alpha2_wasm.js +594 -594
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/builder.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* seconds (or exact ticks) and ids generated deterministically.
|
|
2
|
+
* Fluent builder for project documents. Times are seconds or exact ticks; ids are deterministic.
|
|
4
3
|
*
|
|
5
4
|
* ```ts
|
|
6
5
|
* const project = new ProjectBuilder({ name: "Intro", width: 1920, height: 1080, frameRate: 30 });
|
|
@@ -10,7 +9,11 @@
|
|
|
10
9
|
* ```
|
|
11
10
|
*/
|
|
12
11
|
import { CURRENT_SCHEMA_VERSION, secondsToTicks, validateProject, } from "./project.js";
|
|
13
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* An exact time of `count` ticks.
|
|
14
|
+
*
|
|
15
|
+
* @throws RangeError Unless `count` is a safe integer.
|
|
16
|
+
*/
|
|
14
17
|
export function ticks(count) {
|
|
15
18
|
if (!Number.isSafeInteger(count)) {
|
|
16
19
|
throw new RangeError(`ticks must be a safe integer, not ${count}`);
|
|
@@ -18,9 +21,9 @@ export function ticks(count) {
|
|
|
18
21
|
return { ticks: count };
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
24
|
+
* Converts to ticks, rounding seconds to the nearest tick.
|
|
22
25
|
*
|
|
23
|
-
* @throws RangeError For seconds
|
|
26
|
+
* @throws RangeError For non-finite seconds.
|
|
24
27
|
*/
|
|
25
28
|
export function toTicks(time) {
|
|
26
29
|
if (typeof time === "number") {
|
|
@@ -30,7 +33,7 @@ export function toTicks(time) {
|
|
|
30
33
|
}
|
|
31
34
|
return time.ticks;
|
|
32
35
|
}
|
|
33
|
-
/** `source-1`, `track-1`, `clip-1
|
|
36
|
+
/** Generates `source-1`, `track-1`, `clip-1` and so on, counted per kind. */
|
|
34
37
|
export function sequentialIds() {
|
|
35
38
|
const counts = new Map();
|
|
36
39
|
return (kind) => {
|
|
@@ -39,10 +42,7 @@ export function sequentialIds() {
|
|
|
39
42
|
return `${kind}-${next}`;
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Builds one project document. Nothing is checked until {@link ProjectBuilder.build}
|
|
44
|
-
* validates the whole document.
|
|
45
|
-
*/
|
|
45
|
+
/** Builds one project document. Validation happens only in {@link ProjectBuilder.build}. */
|
|
46
46
|
export class ProjectBuilder {
|
|
47
47
|
#settings;
|
|
48
48
|
#id;
|
|
@@ -69,7 +69,7 @@ export class ProjectBuilder {
|
|
|
69
69
|
this.#name = options.name;
|
|
70
70
|
this.#ids = options.ids ?? sequentialIds();
|
|
71
71
|
}
|
|
72
|
-
/** Adds a media source
|
|
72
|
+
/** Adds a host-resolved media source and returns its id. */
|
|
73
73
|
source(kind, locator, options = {}) {
|
|
74
74
|
const id = this.#claim("source", options.id);
|
|
75
75
|
this.#sources.push({
|
|
@@ -83,23 +83,20 @@ export class ProjectBuilder {
|
|
|
83
83
|
return id;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* Source ids mapped to locators, usable as the `assets` of a native export (`@alpha2-sh/node`)
|
|
87
|
+
* when locators are file paths. Relative paths resolve against the exporting process's working
|
|
88
|
+
* directory.
|
|
89
89
|
*/
|
|
90
90
|
assets() {
|
|
91
91
|
return Object.fromEntries(this.#sources.flatMap((source) => source.locator === undefined ? [] : [[source.id, source.locator]]));
|
|
92
92
|
}
|
|
93
|
-
/** Adds a source
|
|
93
|
+
/** Adds a generated source and returns its id. */
|
|
94
94
|
generated(generator, options = {}) {
|
|
95
95
|
const id = this.#claim("source", options.id);
|
|
96
96
|
this.#sources.push({ id, kind: "generated", generator });
|
|
97
97
|
return id;
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Adds a composition graph for clips to show (with `ClipOptions.with`'s `composition`); returns
|
|
101
|
-
* its id.
|
|
102
|
-
*/
|
|
99
|
+
/** Adds a composition graph for clips to reference via `with.composition`; returns its id. */
|
|
103
100
|
composition(nodes, output, options = {}) {
|
|
104
101
|
const id = this.#claim("composition", options.id);
|
|
105
102
|
this.#compositions.push({
|
|
@@ -109,26 +106,21 @@ export class ProjectBuilder {
|
|
|
109
106
|
});
|
|
110
107
|
return id;
|
|
111
108
|
}
|
|
112
|
-
/** Adds a visual track, drawn over
|
|
109
|
+
/** Adds a visual track, drawn over earlier tracks. */
|
|
113
110
|
videoTrack(options = {}) {
|
|
114
111
|
return this.#track("video", options);
|
|
115
112
|
}
|
|
116
|
-
/** Adds an audio track. */
|
|
117
113
|
audioTrack(options = {}) {
|
|
118
114
|
return this.#track("audio", options);
|
|
119
115
|
}
|
|
120
|
-
/** Adds a caption track
|
|
116
|
+
/** Adds a caption track. Cues pick from the named `styles` by `style` or `speaker`. */
|
|
121
117
|
captionTrack(options = {}) {
|
|
122
118
|
const id = this.#claim("track", options.id);
|
|
123
|
-
const track = new CaptionTrackBuilder(id, options.name ?? id, options.style ?? {});
|
|
119
|
+
const track = new CaptionTrackBuilder(id, options.name ?? id, options.style ?? {}, options.styles ?? {});
|
|
124
120
|
this.#tracks.push(track);
|
|
125
121
|
return track;
|
|
126
122
|
}
|
|
127
|
-
/**
|
|
128
|
-
* The document.
|
|
129
|
-
*
|
|
130
|
-
* @throws {RangeError} Listing every problem when it does not validate.
|
|
131
|
-
*/
|
|
123
|
+
/** @throws {RangeError} Listing every problem when the document does not validate. */
|
|
132
124
|
build() {
|
|
133
125
|
const project = {
|
|
134
126
|
schema_version: CURRENT_SCHEMA_VERSION,
|
|
@@ -165,9 +157,7 @@ export class ProjectBuilder {
|
|
|
165
157
|
return track;
|
|
166
158
|
}
|
|
167
159
|
/**
|
|
168
|
-
* `explicit
|
|
169
|
-
* way the id is held from now on. An explicit id is taken as given: a repeat is for `build` to
|
|
170
|
-
* report.
|
|
160
|
+
* Reserves `explicit` (duplicates are left for `build` to report) or the next free generated id.
|
|
171
161
|
*
|
|
172
162
|
* @throws RangeError When the generator offers only ids already held.
|
|
173
163
|
*/
|
|
@@ -181,7 +171,7 @@ export class ProjectBuilder {
|
|
|
181
171
|
used.add(explicit);
|
|
182
172
|
return explicit;
|
|
183
173
|
}
|
|
184
|
-
// A generator
|
|
174
|
+
// A counting generator reaches a free id within one call per id held.
|
|
185
175
|
let id = "";
|
|
186
176
|
for (let attempt = 0; attempt <= used.size; attempt += 1) {
|
|
187
177
|
id = this.#ids(kind);
|
|
@@ -210,16 +200,14 @@ export class TrackBuilder {
|
|
|
210
200
|
this.#clipId = clipId;
|
|
211
201
|
this.#chain = chain;
|
|
212
202
|
}
|
|
213
|
-
/** The track's id. */
|
|
214
203
|
get id() {
|
|
215
204
|
return this.#id;
|
|
216
205
|
}
|
|
217
206
|
/**
|
|
218
|
-
* Places a clip
|
|
219
|
-
* is added to the project and the clip shows it.
|
|
207
|
+
* Places a clip and returns its id. `effects` adds a composition chaining them.
|
|
220
208
|
*
|
|
221
|
-
* @throws RangeError For `effects`
|
|
222
|
-
*
|
|
209
|
+
* @throws RangeError For `effects` with `with.composition`, or a non-finite time; nothing is
|
|
210
|
+
* added then.
|
|
223
211
|
*/
|
|
224
212
|
clip(options) {
|
|
225
213
|
const effects = options.effects ?? [];
|
|
@@ -233,6 +221,14 @@ export class TrackBuilder {
|
|
|
233
221
|
const id = this.#clipId(options.id);
|
|
234
222
|
this.#clips.push({
|
|
235
223
|
...options.with,
|
|
224
|
+
...(options.preservePitch === undefined
|
|
225
|
+
? {}
|
|
226
|
+
: {
|
|
227
|
+
audio: {
|
|
228
|
+
...options.with?.audio,
|
|
229
|
+
preserve_pitch: options.preservePitch,
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
236
232
|
...(effects.length === 0
|
|
237
233
|
? {}
|
|
238
234
|
: { composition: { id: this.#chain(effects) } }),
|
|
@@ -244,11 +240,10 @@ export class TrackBuilder {
|
|
|
244
240
|
return id;
|
|
245
241
|
}
|
|
246
242
|
/**
|
|
247
|
-
*
|
|
248
|
-
* meet.
|
|
243
|
+
* Adds a transition from `from` to `to` over the time the two clips overlap.
|
|
249
244
|
*
|
|
250
|
-
* @throws RangeError When either clip is not on this track. An overlap
|
|
251
|
-
*
|
|
245
|
+
* @throws RangeError When either clip is not on this track. An invalid overlap is reported by
|
|
246
|
+
* {@link ProjectBuilder.build}.
|
|
252
247
|
*/
|
|
253
248
|
transition(from, to, effect, easing = { type: "linear" }) {
|
|
254
249
|
const first = this.#clips.find((clip) => clip.id === from);
|
|
@@ -284,23 +279,26 @@ export class CaptionTrackBuilder {
|
|
|
284
279
|
#id;
|
|
285
280
|
#name;
|
|
286
281
|
#style;
|
|
282
|
+
#styles;
|
|
287
283
|
#cues = [];
|
|
288
284
|
/** @internal */
|
|
289
|
-
constructor(id, name, style) {
|
|
285
|
+
constructor(id, name, style, styles) {
|
|
290
286
|
this.#id = id;
|
|
291
287
|
this.#name = name;
|
|
292
288
|
this.#style = style;
|
|
289
|
+
this.#styles = styles;
|
|
293
290
|
}
|
|
294
|
-
/** The track's id. */
|
|
295
291
|
get id() {
|
|
296
292
|
return this.#id;
|
|
297
293
|
}
|
|
298
|
-
/**
|
|
294
|
+
/** Adds a cue. Cues may be added in any order. */
|
|
299
295
|
cue(options) {
|
|
300
296
|
const start = toTicks(options.at);
|
|
301
297
|
this.#cues.push({
|
|
302
298
|
timeline_range: { start, end: start + toTicks(options.duration) },
|
|
303
299
|
text: options.text,
|
|
300
|
+
...(options.speaker === undefined ? {} : { speaker: options.speaker }),
|
|
301
|
+
...(options.style === undefined ? {} : { style: options.style }),
|
|
304
302
|
});
|
|
305
303
|
return this;
|
|
306
304
|
}
|
|
@@ -312,7 +310,13 @@ export class CaptionTrackBuilder {
|
|
|
312
310
|
name: this.#name,
|
|
313
311
|
kind: "caption",
|
|
314
312
|
clips: [],
|
|
315
|
-
captions: {
|
|
313
|
+
captions: {
|
|
314
|
+
style: this.#style,
|
|
315
|
+
...(Object.keys(this.#styles).length > 0
|
|
316
|
+
? { styles: { ...this.#styles } }
|
|
317
|
+
: {}),
|
|
318
|
+
cues,
|
|
319
|
+
},
|
|
316
320
|
};
|
|
317
321
|
}
|
|
318
322
|
}
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -1,68 +1,151 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* browser bridge
|
|
2
|
+
* Runtime capability report (`alpha2-capabilities`, version 2), shared by the native host and the
|
|
3
|
+
* browser bridge.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
5
|
+
/** How real-time playback picks frames and whether sound plays. */
|
|
6
6
|
export type PlaybackPolicy =
|
|
7
7
|
/** Sound leads at 1x; late frames are dropped, a missing one holds the last. */
|
|
8
8
|
"drop_video_keep_audio"
|
|
9
9
|
/** Every frame in order, paced by the rate but never skipped; silent. */
|
|
10
10
|
| "preserve_every_video_frame"
|
|
11
|
-
/**
|
|
11
|
+
/** Follows the wall clock at any rate, holding the last frame while one is missing; silent. */
|
|
12
12
|
| "silent_scrub"
|
|
13
13
|
/** Every frame in order as fast as it renders, as an export does; silent. */
|
|
14
14
|
| "offline_exact";
|
|
15
|
-
/** One feature: whether it works here, and why not. */
|
|
16
15
|
export interface CapabilityFeature {
|
|
17
16
|
readonly available: boolean;
|
|
18
|
-
/** Why the feature is unavailable
|
|
17
|
+
/** Why the feature is unavailable, or a caveat on an available one. */
|
|
19
18
|
readonly reason?: string;
|
|
20
19
|
}
|
|
21
|
-
/** The GPU a runtime renders with. */
|
|
22
20
|
export interface GpuCapability {
|
|
23
21
|
readonly adapter: string;
|
|
24
22
|
readonly backend: string;
|
|
25
23
|
readonly driver: string;
|
|
26
24
|
readonly driverInfo: string;
|
|
27
|
-
/**
|
|
25
|
+
/** DX12 shader compiler (`FXC`, `DXC <path>`); empty on other backends and in browsers. */
|
|
26
|
+
readonly shaderCompiler: string;
|
|
27
|
+
/** `a`: full `WebGPU` adapter; `b`: downlevel adapter (GL, WebGL2). */
|
|
28
28
|
readonly tier: "a" | "b" | "unknown";
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* The tier does not decide it.
|
|
30
|
+
* Format between render passes: half float where the adapter can render, filter and copy it,
|
|
31
|
+
* 8-bit elsewhere. Independent of `tier`.
|
|
33
32
|
*/
|
|
34
33
|
readonly intermediateFormat: "rgba16float" | "rgba8unorm";
|
|
35
34
|
readonly maxTextureDimension2d: number;
|
|
36
35
|
readonly timestampQueries: boolean;
|
|
36
|
+
/** Byte budget of the idle intermediate texture pool. */
|
|
37
37
|
readonly textureBudgetBytes: number;
|
|
38
|
+
readonly memory: {
|
|
39
|
+
/**
|
|
40
|
+
* Device memory budget reported by the graphics API; `null` when unreported, in a browser and
|
|
41
|
+
* on the CPU renderer. A native host caps idle texture pools and the default in-flight budget
|
|
42
|
+
* at a quarter of it.
|
|
43
|
+
*/
|
|
44
|
+
readonly budgetBytes: number | null;
|
|
45
|
+
};
|
|
38
46
|
}
|
|
39
47
|
/** How a runtime handles color. */
|
|
40
48
|
export interface ColorCapability {
|
|
41
49
|
readonly workingSpace: "linear_bt709_sdr";
|
|
42
50
|
/** Whether PQ and HLG sources are tone-mapped into the working space. */
|
|
43
51
|
readonly hdrSources: boolean;
|
|
44
|
-
/**
|
|
52
|
+
/** Always `false`; no runtime encodes HDR output yet. */
|
|
45
53
|
readonly hdrOutput: boolean;
|
|
46
54
|
/** Whether linear float sources keep values beyond SDR until compositing. */
|
|
47
55
|
readonly extendedRangeSources: boolean;
|
|
48
56
|
}
|
|
49
|
-
/** How a runtime's real-time playback behaves. */
|
|
50
57
|
export interface PlaybackCapability {
|
|
51
58
|
readonly policies: readonly PlaybackPolicy[];
|
|
52
59
|
readonly defaultPolicy: PlaybackPolicy;
|
|
53
60
|
/** Whether sound plays at rates other than 1x. */
|
|
54
61
|
readonly audioAtNonUnitRate: boolean;
|
|
55
62
|
}
|
|
56
|
-
/**
|
|
63
|
+
/** Why a native host renders on the adapter it chose. */
|
|
64
|
+
export type AdapterChoiceReason =
|
|
65
|
+
/** It encodes more codecs on the GPU than the runner-up. */
|
|
66
|
+
"most-gpu-encoders"
|
|
67
|
+
/** It encodes as many codecs and decodes on the GPU where the runner-up does not. */
|
|
68
|
+
| "decodes"
|
|
69
|
+
/** Tie with the runner-up, broken by high-performance order. */
|
|
70
|
+
| "high-performance-order"
|
|
71
|
+
/** `ALPHA2_GPU_ADAPTER=performance`: the first hardware adapter in the high-performance order. */
|
|
72
|
+
| "performance-policy"
|
|
73
|
+
/** `ALPHA2_GPU_ADAPTER` names it. */
|
|
74
|
+
| "pinned"
|
|
75
|
+
/** It is the only hardware adapter that renders. */
|
|
76
|
+
| "only-adapter"
|
|
77
|
+
/** No adapter could share a device with the video decoder and encoder. */
|
|
78
|
+
| "no-shared-device";
|
|
79
|
+
/** An adapter a native host considered. */
|
|
80
|
+
export interface AdapterCandidate {
|
|
81
|
+
/** Position in the backend's enumeration, as used by `ALPHA2_GPU_ADAPTER=index:<n>`. */
|
|
82
|
+
readonly index: number;
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly backend: "dx12" | "vulkan" | "metal";
|
|
85
|
+
/** DXGI adapter LUID as hex (`0x...`); `null` off Windows. */
|
|
86
|
+
readonly luid: string | null;
|
|
87
|
+
readonly software: boolean;
|
|
88
|
+
readonly renders: boolean;
|
|
89
|
+
readonly rendersReason: string | null;
|
|
90
|
+
/** Whether hardware decode imports into its device. */
|
|
91
|
+
readonly decodes: boolean;
|
|
92
|
+
readonly decodesReason: string | null;
|
|
93
|
+
/** Codecs it encodes on the GPU (`h264`, `hevc`, `av1`). */
|
|
94
|
+
readonly gpuEncodes: readonly string[];
|
|
95
|
+
/** Set when `gpuEncodes` is empty. */
|
|
96
|
+
readonly gpuEncodeReason: string | null;
|
|
97
|
+
}
|
|
98
|
+
export interface AdapterChoice {
|
|
99
|
+
/**
|
|
100
|
+
* `ALPHA2_GPU_ADAPTER` policy: `auto`, `performance`, `index:<n>` or `name:<text>`. Defaults to
|
|
101
|
+
* `auto` on Linux and macOS and `performance` on Windows.
|
|
102
|
+
*/
|
|
103
|
+
readonly policy: string;
|
|
104
|
+
/** `index` of the chosen candidate; `null` when the device came from none of them. */
|
|
105
|
+
readonly chosen: number | null;
|
|
106
|
+
readonly reason: AdapterChoiceReason;
|
|
107
|
+
/** One sentence naming the chosen adapter, and the runner-up when compared. */
|
|
108
|
+
readonly explanation: string;
|
|
109
|
+
readonly candidates: readonly AdapterCandidate[];
|
|
110
|
+
}
|
|
111
|
+
/** A runtime's capabilities. `Decode` and `Encode` are runtime-specific. */
|
|
57
112
|
export interface CapabilityReport<Decode = unknown, Encode = unknown> {
|
|
58
113
|
readonly schema: "alpha2-capabilities";
|
|
59
|
-
readonly version:
|
|
114
|
+
readonly version: 2;
|
|
60
115
|
readonly runtime: "native" | "browser";
|
|
61
|
-
/**
|
|
116
|
+
/** `null` before a browser's engine has started. */
|
|
62
117
|
readonly gpu: GpuCapability | null;
|
|
63
118
|
readonly color: ColorCapability | null;
|
|
64
119
|
readonly playback: PlaybackCapability;
|
|
65
120
|
readonly decode: Decode;
|
|
66
121
|
readonly encode: Encode;
|
|
67
122
|
readonly features: Readonly<Record<string, CapabilityFeature>>;
|
|
123
|
+
/** `null` in a browser and on the CPU renderer. */
|
|
124
|
+
readonly adapters: AdapterChoice | null;
|
|
125
|
+
/** `null` in a browser. */
|
|
126
|
+
readonly memory: MemoryCapability | null;
|
|
127
|
+
}
|
|
128
|
+
/** Machine memory and the native host process's use of it. */
|
|
129
|
+
export interface MemoryCapability {
|
|
130
|
+
readonly capacity: {
|
|
131
|
+
readonly physicalBytes: number | null;
|
|
132
|
+
/** Memory available now without paging. */
|
|
133
|
+
readonly availableBytes: number | null;
|
|
134
|
+
/** Lower of the cgroup or job limit and physical memory. */
|
|
135
|
+
readonly limitBytes: number | null;
|
|
136
|
+
readonly limitSource: "cgroup-v2" | "cgroup-v1" | "job" | "physical";
|
|
137
|
+
/** Usage charged against the cgroup limit; `null` for a job or physical limit. */
|
|
138
|
+
readonly usedInLimitBytes: number | null;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Current and peak process memory. Resident includes shared pages; footprint is what the
|
|
142
|
+
* OS charges (Linux anonymous plus shared resident, macOS physical footprint, Windows private
|
|
143
|
+
* commit).
|
|
144
|
+
*/
|
|
145
|
+
readonly process: {
|
|
146
|
+
readonly residentBytes: number | null;
|
|
147
|
+
readonly peakResidentBytes: number | null;
|
|
148
|
+
readonly footprintBytes: number | null;
|
|
149
|
+
readonly peakFootprintBytes: number | null;
|
|
150
|
+
};
|
|
68
151
|
}
|
package/dist/capabilities.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* browser bridge
|
|
2
|
+
* Runtime capability report (`alpha2-capabilities`, version 2), shared by the native host and the
|
|
3
|
+
* browser bridge.
|
|
4
4
|
*/
|
|
5
5
|
export {};
|
package/dist/captions.d.ts
CHANGED
|
@@ -1,40 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* SRT and WebVTT import into caption tracks, using the engine's parser in wasm.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* give the same caption pixels.
|
|
4
|
+
* Captions draw with the fonts given to the renderer (`WasmRenderWorkerHostOptions.fonts` in the
|
|
5
|
+
* browser, `fonts` on a native export request); the same font files give the same pixels.
|
|
7
6
|
*/
|
|
8
|
-
import type { CaptionCue, TextStyle, Track } from "./generated/project-schema.js";
|
|
9
|
-
/** The
|
|
7
|
+
import type { CaptionCue, TextStyle, TextStylePatch, Track } from "./generated/project-schema.js";
|
|
8
|
+
/** The `alpha2/wasm` function caption import uses. */
|
|
10
9
|
export interface CaptionBinding {
|
|
11
10
|
parseCaptions(text: string, format: "srt" | "webvtt"): string;
|
|
12
11
|
}
|
|
13
12
|
/** Cues read from a subtitle file. */
|
|
14
13
|
export interface ImportedCaptions {
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
* `MAX_CLIPS_PER_TRACK
|
|
15
|
+
* One caption track's cues per row. Cues in a row do not overlap, and a row holds at most
|
|
16
|
+
* `MAX_CLIPS_PER_TRACK`.
|
|
18
17
|
*/
|
|
19
18
|
readonly rows: readonly (readonly CaptionCue[])[];
|
|
20
|
-
/**
|
|
21
|
-
* Blocks that were not cues and could not be read as one, including a cue later than a project
|
|
22
|
-
* holds (a time past `Number.MAX_SAFE_INTEGER` ticks).
|
|
23
|
-
*/
|
|
19
|
+
/** Unreadable blocks, including cues past `Number.MAX_SAFE_INTEGER` ticks. */
|
|
24
20
|
readonly skipped: number;
|
|
21
|
+
readonly notes: CaptionImportNotes;
|
|
22
|
+
}
|
|
23
|
+
/** Counts of markup the import read but could not keep. */
|
|
24
|
+
export interface CaptionImportNotes {
|
|
25
|
+
/** Voices after a cue's first; only the first becomes its speaker. */
|
|
26
|
+
readonly extraVoices: number;
|
|
27
|
+
/** Inline timestamps out of order or outside their cue. */
|
|
28
|
+
readonly droppedTimestamps: number;
|
|
29
|
+
/** Class names a run cannot carry. */
|
|
30
|
+
readonly droppedClasses: number;
|
|
31
|
+
/** Cues with more runs than a text holds, imported as plain text. */
|
|
32
|
+
readonly flattened: number;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
28
|
-
* millisecond is 120 ticks); markup is dropped.
|
|
35
|
+
* Parses SubRip (`.srt`) or WebVTT (`.vtt`) text. Timestamps are exact (1 ms is 120 ticks).
|
|
29
36
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
37
|
+
* A WebVTT voice sets the cue's `speaker`. Voices, `<c.class>`, `<b>`, `<i>` and `<u>` become run
|
|
38
|
+
* classes, and inline timestamps split the cue into runs timed from its start. Other markup is
|
|
39
|
+
* dropped.
|
|
33
40
|
*
|
|
34
|
-
* @throws For an unknown format, a WebVTT file without its header, a file
|
|
35
|
-
*
|
|
36
|
-
*
|
|
41
|
+
* @throws For an unknown format, a WebVTT file without its header, a file over
|
|
42
|
+
* `MAX_CAPTION_FILE_BYTES` or `MAX_CAPTION_FILE_CUES`, or cues needing more than `MAX_TRACKS`
|
|
43
|
+
* caption tracks.
|
|
37
44
|
*/
|
|
38
45
|
export declare function parseCaptions(binding: CaptionBinding, text: string, format: "srt" | "webvtt"): ImportedCaptions;
|
|
39
|
-
/**
|
|
40
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Builds a caption track. Cues pick from the named `styles` by their `style` or `speaker`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function captionTrack(id: string, name: string, cues: readonly CaptionCue[], style?: TextStyle, styles?: Readonly<Record<string, TextStylePatch>>): Track;
|
|
50
|
+
/**
|
|
51
|
+
* Splits `cue` at timeline tick `at`. Each half keeps the runs timed within it (untimed runs go to
|
|
52
|
+
* both), with run times clipped and rebased as in {@link trimCue}.
|
|
53
|
+
*
|
|
54
|
+
* @throws RangeError when `at` does not lie strictly inside the cue.
|
|
55
|
+
*/
|
|
56
|
+
export declare function splitCue(cue: CaptionCue, at: number): readonly [CaptionCue, CaptionCue];
|
|
57
|
+
/**
|
|
58
|
+
* Narrows `cue` to `start..end`. Run times are rebased to the new start and clipped to the range;
|
|
59
|
+
* runs wholly outside it are dropped.
|
|
60
|
+
*
|
|
61
|
+
* @throws RangeError when the new range is empty or outside the cue's, or no run is left.
|
|
62
|
+
*/
|
|
63
|
+
export declare function trimCue(cue: CaptionCue, start: number, end: number): CaptionCue;
|
package/dist/captions.js
CHANGED
|
@@ -1,32 +1,77 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* SRT and WebVTT import into caption tracks, using the engine's parser in wasm.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* give the same caption pixels.
|
|
4
|
+
* Captions draw with the fonts given to the renderer (`WasmRenderWorkerHostOptions.fonts` in the
|
|
5
|
+
* browser, `fonts` on a native export request); the same font files give the same pixels.
|
|
7
6
|
*/
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
* millisecond is 120 ticks); markup is dropped.
|
|
8
|
+
* Parses SubRip (`.srt`) or WebVTT (`.vtt`) text. Timestamps are exact (1 ms is 120 ticks).
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* A WebVTT voice sets the cue's `speaker`. Voices, `<c.class>`, `<b>`, `<i>` and `<u>` become run
|
|
11
|
+
* classes, and inline timestamps split the cue into runs timed from its start. Other markup is
|
|
12
|
+
* dropped.
|
|
15
13
|
*
|
|
16
|
-
* @throws For an unknown format, a WebVTT file without its header, a file
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* @throws For an unknown format, a WebVTT file without its header, a file over
|
|
15
|
+
* `MAX_CAPTION_FILE_BYTES` or `MAX_CAPTION_FILE_CUES`, or cues needing more than `MAX_TRACKS`
|
|
16
|
+
* caption tracks.
|
|
19
17
|
*/
|
|
20
18
|
export function parseCaptions(binding, text, format) {
|
|
21
19
|
return JSON.parse(binding.parseCaptions(text, format));
|
|
22
20
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Builds a caption track. Cues pick from the named `styles` by their `style` or `speaker`.
|
|
23
|
+
*/
|
|
24
|
+
export function captionTrack(id, name, cues, style = {}, styles = {}) {
|
|
25
25
|
return {
|
|
26
26
|
id,
|
|
27
27
|
name,
|
|
28
28
|
kind: "caption",
|
|
29
29
|
clips: [],
|
|
30
|
-
captions: {
|
|
30
|
+
captions: {
|
|
31
|
+
style,
|
|
32
|
+
...(Object.keys(styles).length > 0 ? { styles: { ...styles } } : {}),
|
|
33
|
+
cues: [...cues],
|
|
34
|
+
},
|
|
31
35
|
};
|
|
32
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Splits `cue` at timeline tick `at`. Each half keeps the runs timed within it (untimed runs go to
|
|
39
|
+
* both), with run times clipped and rebased as in {@link trimCue}.
|
|
40
|
+
*
|
|
41
|
+
* @throws RangeError when `at` does not lie strictly inside the cue.
|
|
42
|
+
*/
|
|
43
|
+
export function splitCue(cue, at) {
|
|
44
|
+
const { start, end } = cue.timeline_range;
|
|
45
|
+
if (!(at > start && at < end)) {
|
|
46
|
+
throw new RangeError(`a cue from ${start} to ${end} cannot be split at ${at}`);
|
|
47
|
+
}
|
|
48
|
+
return [trimCue(cue, start, at), trimCue(cue, at, end)];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Narrows `cue` to `start..end`. Run times are rebased to the new start and clipped to the range;
|
|
52
|
+
* runs wholly outside it are dropped.
|
|
53
|
+
*
|
|
54
|
+
* @throws RangeError when the new range is empty or outside the cue's, or no run is left.
|
|
55
|
+
*/
|
|
56
|
+
export function trimCue(cue, start, end) {
|
|
57
|
+
const range = cue.timeline_range;
|
|
58
|
+
if (!(start >= range.start && end <= range.end && start < end)) {
|
|
59
|
+
throw new RangeError(`a cue from ${range.start} to ${range.end} cannot be trimmed to ${start}..${end}`);
|
|
60
|
+
}
|
|
61
|
+
const trimmed = { ...cue, timeline_range: { start, end } };
|
|
62
|
+
if (typeof cue.text === "string")
|
|
63
|
+
return trimmed;
|
|
64
|
+
const shift = start - range.start;
|
|
65
|
+
const duration = end - start;
|
|
66
|
+
const runs = cue.text.flatMap((run) => {
|
|
67
|
+
if (run.time == null)
|
|
68
|
+
return [run];
|
|
69
|
+
const from = Math.max(run.time.start - shift, 0);
|
|
70
|
+
const to = Math.min(run.time.end - shift, duration);
|
|
71
|
+
return from < to ? [{ ...run, time: { start: from, end: to } }] : [];
|
|
72
|
+
});
|
|
73
|
+
if (runs.length === 0) {
|
|
74
|
+
throw new RangeError("no run of the cue is said in the trimmed range");
|
|
75
|
+
}
|
|
76
|
+
return { ...trimmed, text: runs };
|
|
77
|
+
}
|