alpha2 0.5.3 → 0.6.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 +68 -3
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +636 -37
- package/dist/generated/project-schema.js +55 -0
- package/dist/generated/project-shape.js +950 -381
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +43 -10
- package/dist/media.js +255 -66
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +24 -1
- package/dist/project.js +456 -38
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +26 -1
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +5 -61
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
package/dist/edit.d.ts
CHANGED
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
|
|
19
19
|
* sync track with content across the edit point, or where pulled content would land on content
|
|
20
|
-
* that stays, refuses the whole edit (`sync_conflict`).
|
|
20
|
+
* that stays, refuses the whole edit (`sync_conflict`). The track and bus keyframes of every track
|
|
21
|
+
* a ripple reaches move with it; a ripple that reaches every track also edits the master bus keys
|
|
22
|
+
* and timeline-anchored data sets, as the engine's `remove_ranges` with `ripple: "timeline"` does.
|
|
23
|
+
* Time the edit closes is cut out of them and time it opens opens in them. Source-anchored data
|
|
24
|
+
* never changes. A ripple's result reports the change in `timeline`, so a host can move its own
|
|
25
|
+
* timeline items (markers) by the same rule.
|
|
21
26
|
*
|
|
22
27
|
* Use {@link deferValidation} for a batch of edits that is valid only as a whole.
|
|
23
28
|
*/
|
|
@@ -38,6 +43,8 @@ export type EditErrorCode =
|
|
|
38
43
|
| "in_fade"
|
|
39
44
|
/** Another clip uses this one as its matte. */
|
|
40
45
|
| "matte_source"
|
|
46
|
+
/** A data binding of another clip reads through this one (`via`). */
|
|
47
|
+
| "read_through"
|
|
41
48
|
/** A loop cannot start part way through a pass. */
|
|
42
49
|
| "unsupported_time_map"
|
|
43
50
|
/** The clip's source kind does not belong on that track. */
|
|
@@ -59,10 +66,29 @@ export interface EditError {
|
|
|
59
66
|
/** For `invalid_result`, what {@link validateProject} reported. */
|
|
60
67
|
readonly problems?: readonly string[];
|
|
61
68
|
}
|
|
62
|
-
/**
|
|
69
|
+
/** What a ripple did to timeline time. Ticks are the old timeline's. */
|
|
70
|
+
export interface TimelineChange {
|
|
71
|
+
/** The time the ripple closed. */
|
|
72
|
+
readonly removed?: TimeRange;
|
|
73
|
+
/** The time the ripple opened: `length` ticks at `at`. */
|
|
74
|
+
readonly opened?: {
|
|
75
|
+
readonly at: number;
|
|
76
|
+
readonly length: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Whether the ripple reached every track, so the master bus keys and timeline data moved and a
|
|
80
|
+
* host's own timeline items should too.
|
|
81
|
+
*/
|
|
82
|
+
readonly everyTrack: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The new project, or why the edit was refused. The input is never modified. A ripple that moved
|
|
86
|
+
* time reports how in `timeline`.
|
|
87
|
+
*/
|
|
63
88
|
export type EditResult = {
|
|
64
89
|
readonly ok: true;
|
|
65
90
|
readonly project: Project;
|
|
91
|
+
readonly timeline?: TimelineChange;
|
|
66
92
|
} | {
|
|
67
93
|
readonly ok: false;
|
|
68
94
|
readonly error: EditError;
|
|
@@ -81,8 +107,8 @@ export interface PlaceOptions extends RippleOptions {
|
|
|
81
107
|
/**
|
|
82
108
|
* Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
|
|
83
109
|
* part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
|
|
84
|
-
* ({@link copyComposition}).
|
|
85
|
-
* loop.
|
|
110
|
+
* ({@link copyComposition}). The right part's bindings that read through the clip read through
|
|
111
|
+
* `newId`. Refused inside a transition or fade, for a matte source, and for a loop.
|
|
86
112
|
*/
|
|
87
113
|
export declare function split(project: Project, clipId: string, at: number, newId: string): EditResult;
|
|
88
114
|
/**
|
|
@@ -92,12 +118,14 @@ export declare function split(project: Project, clipId: string, at: number, newI
|
|
|
92
118
|
export declare function trim(project: Project, clipId: string, edge: ClipEdge, to: number): EditResult;
|
|
93
119
|
/**
|
|
94
120
|
* Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
|
|
95
|
-
* keeps the clip's start in place, so `to` may be before the timeline start.
|
|
121
|
+
* keeps the clip's start in place, so `to` may be before the timeline start. Sync tracks and
|
|
122
|
+
* timeline data close or open time at the trimmed edge, which for a start trim is the clip's start.
|
|
96
123
|
*/
|
|
97
124
|
export declare function rippleTrim(project: Project, clipId: string, edge: ClipEdge, to: number, options?: RippleOptions): EditResult;
|
|
98
125
|
/**
|
|
99
126
|
* Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
|
|
100
|
-
* matte source, and when a sync track has content
|
|
127
|
+
* matte source, for a clip another clip's binding reads through, and when a sync track has content
|
|
128
|
+
* in that span.
|
|
101
129
|
*/
|
|
102
130
|
export declare function rippleDelete(project: Project, clipId: string, options?: RippleOptions): EditResult;
|
|
103
131
|
/**
|
|
@@ -165,8 +193,8 @@ export declare function insert(project: Project, trackId: string, clip: Clip, at
|
|
|
165
193
|
/**
|
|
166
194
|
* Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
|
|
167
195
|
* across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
|
|
168
|
-
* a transition
|
|
169
|
-
* edges.
|
|
196
|
+
* a transition, matte source or clip a binding reads through would be cut, and (`needs_id`) when
|
|
197
|
+
* more than one clip spans both edges.
|
|
170
198
|
*/
|
|
171
199
|
export declare function overwrite(project: Project, trackId: string, clip: Clip, at: number, options?: PlaceOptions): EditResult;
|
|
172
200
|
/** Places `clip` after the track's last clip, or at 0. */
|
|
@@ -196,6 +224,11 @@ export declare function moveClips(project: Project, moves: readonly ClipMove[]):
|
|
|
196
224
|
* synchronous and may nest.
|
|
197
225
|
*/
|
|
198
226
|
export declare function deferValidation<T>(run: () => T): T;
|
|
227
|
+
/**
|
|
228
|
+
* Gives `clip` the id `id`, for a paste or a duplicate. Its bindings that read through itself
|
|
229
|
+
* read through `id`, and those through other clips stay.
|
|
230
|
+
*/
|
|
231
|
+
export declare function withClipId(clip: Clip, id: string): Clip;
|
|
199
232
|
/**
|
|
200
233
|
* Copies composition `id` and every group definition it draws (recursively) so clip `clipId` can
|
|
201
234
|
* be edited independently. Copies take the first free id of `<root>~<clipId>`, `<root>~<clipId>~2`
|
package/dist/edit.js
CHANGED
|
@@ -17,16 +17,24 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
|
|
19
19
|
* sync track with content across the edit point, or where pulled content would land on content
|
|
20
|
-
* that stays, refuses the whole edit (`sync_conflict`).
|
|
20
|
+
* that stays, refuses the whole edit (`sync_conflict`). The track and bus keyframes of every track
|
|
21
|
+
* a ripple reaches move with it; a ripple that reaches every track also edits the master bus keys
|
|
22
|
+
* and timeline-anchored data sets, as the engine's `remove_ranges` with `ripple: "timeline"` does.
|
|
23
|
+
* Time the edit closes is cut out of them and time it opens opens in them. Source-anchored data
|
|
24
|
+
* never changes. A ripple's result reports the change in `timeline`, so a host can move its own
|
|
25
|
+
* timeline items (markers) by the same rule.
|
|
21
26
|
*
|
|
22
27
|
* Use {@link deferValidation} for a batch of edits that is valid only as a whole.
|
|
23
28
|
*/
|
|
24
29
|
import { validateProject } from "./project.js";
|
|
30
|
+
import { dataReferences } from "./project-data.js";
|
|
31
|
+
import { renameVia, rippleTimelineData } from "./edit-data.js";
|
|
32
|
+
import { closeKeys, openKeys } from "./edit-keys.js";
|
|
25
33
|
/**
|
|
26
34
|
* Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
|
|
27
35
|
* part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
|
|
28
|
-
* ({@link copyComposition}).
|
|
29
|
-
* loop.
|
|
36
|
+
* ({@link copyComposition}). The right part's bindings that read through the clip read through
|
|
37
|
+
* `newId`. Refused inside a transition or fade, for a matte source, and for a loop.
|
|
30
38
|
*/
|
|
31
39
|
export function split(project, clipId, at, newId) {
|
|
32
40
|
const time = notTicks(at, "the split time");
|
|
@@ -77,9 +85,8 @@ export function split(project, clipId, at, newId) {
|
|
|
77
85
|
id: copy.id,
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
|
-
const right = {
|
|
88
|
+
const right = withClipId({
|
|
81
89
|
...clip,
|
|
82
|
-
id: newId,
|
|
83
90
|
timeline_range: { start: at, end: range.end },
|
|
84
91
|
source_range: sources.right,
|
|
85
92
|
...(audio?.fade_in === undefined
|
|
@@ -88,7 +95,7 @@ export function split(project, clipId, at, newId) {
|
|
|
88
95
|
...(rightComposition === undefined
|
|
89
96
|
? {}
|
|
90
97
|
: { composition: rightComposition }),
|
|
91
|
-
};
|
|
98
|
+
}, newId);
|
|
92
99
|
const transitions = (track.transitions ?? []).map((transition) => transition.from_clip === clipId
|
|
93
100
|
? { ...transition, from_clip: newId }
|
|
94
101
|
: transition);
|
|
@@ -113,7 +120,8 @@ export function trim(project, clipId, edge, to) {
|
|
|
113
120
|
}
|
|
114
121
|
/**
|
|
115
122
|
* Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
|
|
116
|
-
* keeps the clip's start in place, so `to` may be before the timeline start.
|
|
123
|
+
* keeps the clip's start in place, so `to` may be before the timeline start. Sync tracks and
|
|
124
|
+
* timeline data close or open time at the trimmed edge, which for a start trim is the clip's start.
|
|
117
125
|
*/
|
|
118
126
|
export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
119
127
|
const time = notTicks(to, "the trim time");
|
|
@@ -126,6 +134,7 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
126
134
|
const before = trimmed.original.timeline_range;
|
|
127
135
|
let edited = clip;
|
|
128
136
|
let delta;
|
|
137
|
+
let pivot = before.end;
|
|
129
138
|
if (edge === "end") {
|
|
130
139
|
delta = to - before.end;
|
|
131
140
|
}
|
|
@@ -133,9 +142,14 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
133
142
|
// Trim the head, then slide the clip back to its original start.
|
|
134
143
|
delta = before.start - to;
|
|
135
144
|
edited = shift(clip, delta);
|
|
145
|
+
pivot = before.start;
|
|
136
146
|
}
|
|
137
147
|
if (pullsOnto(track, before.end, delta, clipId))
|
|
138
148
|
return pulledOnto(track);
|
|
149
|
+
if (edge === "start" && delta < 0)
|
|
150
|
+
for (const other of syncTracksOf(project, options.syncTracks, track.id))
|
|
151
|
+
if (occupies(other, { start: before.start, end: to }))
|
|
152
|
+
return failure("sync_conflict", `track ${other.id} has content in the time the trim closes`);
|
|
139
153
|
const shifted = (track.clips ?? []).map((candidate) => {
|
|
140
154
|
if (candidate.id === clipId)
|
|
141
155
|
return edited;
|
|
@@ -143,18 +157,23 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
143
157
|
? shift(candidate, delta)
|
|
144
158
|
: candidate;
|
|
145
159
|
});
|
|
146
|
-
|
|
147
|
-
if (!synced.ok)
|
|
148
|
-
return synced;
|
|
149
|
-
return finish(replaceTrack(synced.project, {
|
|
160
|
+
return rippled(replaceTrack(project, {
|
|
150
161
|
...track,
|
|
151
162
|
clips: shifted,
|
|
152
163
|
transitions: shiftTransitions(track, before.end, delta),
|
|
153
|
-
})
|
|
164
|
+
}), track.id, options.syncTracks, delta < 0
|
|
165
|
+
? {
|
|
166
|
+
removed: {
|
|
167
|
+
start: pivot + (edge === "start" ? 0 : delta),
|
|
168
|
+
end: edge === "start" ? to : pivot,
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
: { opened: { at: pivot, length: delta } });
|
|
154
172
|
}
|
|
155
173
|
/**
|
|
156
174
|
* Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
|
|
157
|
-
* matte source, and when a sync track has content
|
|
175
|
+
* matte source, for a clip another clip's binding reads through, and when a sync track has content
|
|
176
|
+
* in that span.
|
|
158
177
|
*/
|
|
159
178
|
export function rippleDelete(project, clipId, options = {}) {
|
|
160
179
|
const found = locate(project, clipId);
|
|
@@ -164,6 +183,9 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
164
183
|
if (isMatteSource(project, clipId)) {
|
|
165
184
|
return failure("matte_source", `clip ${clipId} is another clip's matte`);
|
|
166
185
|
}
|
|
186
|
+
const reader = readThrough(project, clipId);
|
|
187
|
+
if (reader)
|
|
188
|
+
return reader;
|
|
167
189
|
const range = clip.timeline_range;
|
|
168
190
|
const gap = aloneSpan(track, clip);
|
|
169
191
|
const delta = gap.start - gap.end;
|
|
@@ -180,10 +202,7 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
180
202
|
for (const other of syncTracksOf(project, options.syncTracks, track.id))
|
|
181
203
|
if (occupies(other, gap))
|
|
182
204
|
return failure("sync_conflict", `track ${other.id} has content in the time the delete closes`);
|
|
183
|
-
|
|
184
|
-
if (!synced.ok)
|
|
185
|
-
return synced;
|
|
186
|
-
return finish(replaceTrack(synced.project, { ...track, clips, transitions }));
|
|
205
|
+
return rippled(replaceTrack(project, { ...track, clips, transitions }), track.id, options.syncTracks, { removed: gap });
|
|
187
206
|
}
|
|
188
207
|
/**
|
|
189
208
|
* The span {@link rippleDelete} closes: the part of the clip's span no other clip on its track
|
|
@@ -432,14 +451,13 @@ export function retime(project, clipId, duration, options = {}) {
|
|
|
432
451
|
: candidate.timeline_range.start >= range.end
|
|
433
452
|
? shift(candidate, delta)
|
|
434
453
|
: candidate);
|
|
435
|
-
|
|
436
|
-
if (!synced.ok)
|
|
437
|
-
return synced;
|
|
438
|
-
return finish(replaceTrack(synced.project, {
|
|
454
|
+
return rippled(replaceTrack(project, {
|
|
439
455
|
...track,
|
|
440
456
|
clips,
|
|
441
457
|
transitions: shiftTransitions(track, range.end, delta),
|
|
442
|
-
})
|
|
458
|
+
}), track.id, options.syncTracks, delta < 0
|
|
459
|
+
? { removed: { start: range.end + delta, end: range.end } }
|
|
460
|
+
: { opened: { at: range.end, length: delta } });
|
|
443
461
|
}
|
|
444
462
|
/**
|
|
445
463
|
* Inserts `clip` at `at`, pushing later content on the track and `syncTracks` by its length. A clip
|
|
@@ -465,23 +483,20 @@ export function insert(project, trackId, clip, at, options = {}) {
|
|
|
465
483
|
track = edited.timeline.tracks.find((t) => t.id === trackId);
|
|
466
484
|
}
|
|
467
485
|
const length = placed.clip.timeline_range.end - at;
|
|
468
|
-
|
|
469
|
-
if (!synced.ok)
|
|
470
|
-
return synced;
|
|
471
|
-
return finish(replaceTrack(synced.project, {
|
|
486
|
+
return rippled(replaceTrack(edited, {
|
|
472
487
|
...track,
|
|
473
488
|
clips: [
|
|
474
489
|
...(track.clips ?? []).map((c) => c.timeline_range.start >= at ? shift(c, length) : c),
|
|
475
490
|
placed.clip,
|
|
476
491
|
],
|
|
477
492
|
transitions: shiftTransitions(track, at, length),
|
|
478
|
-
}));
|
|
493
|
+
}), trackId, options.syncTracks, { opened: { at, length } });
|
|
479
494
|
}
|
|
480
495
|
/**
|
|
481
496
|
* Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
|
|
482
497
|
* across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
|
|
483
|
-
* a transition
|
|
484
|
-
* edges.
|
|
498
|
+
* a transition, matte source or clip a binding reads through would be cut, and (`needs_id`) when
|
|
499
|
+
* more than one clip spans both edges.
|
|
485
500
|
*/
|
|
486
501
|
export function overwrite(project, trackId, clip, at, options = {}) {
|
|
487
502
|
const placed = placeAt(project, trackId, clip, at);
|
|
@@ -516,6 +531,9 @@ export function overwrite(project, trackId, clip, at, options = {}) {
|
|
|
516
531
|
if (start >= range.start && end <= range.end) {
|
|
517
532
|
if (isMatteSource(edited, candidate.id))
|
|
518
533
|
return failure("matte_source", `clip ${candidate.id} is another clip's matte`);
|
|
534
|
+
const reader = readThrough(edited, candidate.id);
|
|
535
|
+
if (reader)
|
|
536
|
+
return reader;
|
|
519
537
|
continue;
|
|
520
538
|
}
|
|
521
539
|
const edge = start < range.start ? "end" : "start";
|
|
@@ -596,7 +614,7 @@ function rippleSyncTracks(project, ids, edited, pivot, delta) {
|
|
|
596
614
|
? {
|
|
597
615
|
captions: {
|
|
598
616
|
...track.captions,
|
|
599
|
-
cues: track.captions.cues.map((cue) => cue.timeline_range.start >= pivot
|
|
617
|
+
cues: (track.captions.cues ?? []).map((cue) => cue.timeline_range.start >= pivot
|
|
600
618
|
? {
|
|
601
619
|
...cue,
|
|
602
620
|
timeline_range: offset(cue.timeline_range, delta),
|
|
@@ -901,6 +919,81 @@ function transitionsOf(track, clipId) {
|
|
|
901
919
|
function isMatteSource(project, clipId) {
|
|
902
920
|
return project.timeline.tracks.some((track) => (track.clips ?? []).some((clip) => clip.matte?.source === clipId));
|
|
903
921
|
}
|
|
922
|
+
/** The `read_through` refusal when a binding of another clip reads through `clipId`. */
|
|
923
|
+
function readThrough(project, clipId) {
|
|
924
|
+
if (!project.data?.length)
|
|
925
|
+
return undefined;
|
|
926
|
+
const reader = dataReferences(project).find((reference) => reference.via !== undefined &&
|
|
927
|
+
"clip" in reference.via &&
|
|
928
|
+
reference.via.clip === clipId &&
|
|
929
|
+
!(reference.owner.kind === "clip" && reference.owner.clip === clipId));
|
|
930
|
+
if (!reader)
|
|
931
|
+
return undefined;
|
|
932
|
+
const owner = reader.owner.kind === "clip" ? `clip ${reader.owner.clip} ` : "";
|
|
933
|
+
return failure("read_through", `${owner}${reader.property} reads data through clip ${clipId}`);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Gives `clip` the id `id`, for a paste or a duplicate. Its bindings that read through itself
|
|
937
|
+
* read through `id`, and those through other clips stay.
|
|
938
|
+
*/
|
|
939
|
+
export function withClipId(clip, id) {
|
|
940
|
+
return { ...renameVia(clip, clip.id, id), id };
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Finishes a ripple whose edited track `trackId` is already in `project`: sync tracks shift (or
|
|
944
|
+
* refuse), the bus keys of every reached track move, and when the ripple reaches every track the
|
|
945
|
+
* master bus keys and timeline data move too. The one place a ripple changes time beyond its track.
|
|
946
|
+
*/
|
|
947
|
+
function rippled(project, trackId, syncTracks, change) {
|
|
948
|
+
const removed = "removed" in change ? change.removed : undefined;
|
|
949
|
+
const opened = "opened" in change ? change.opened : undefined;
|
|
950
|
+
const pivot = removed ? removed.end : opened.at;
|
|
951
|
+
const delta = removed ? removed.start - removed.end : opened.length;
|
|
952
|
+
if (delta === 0)
|
|
953
|
+
return finish(project);
|
|
954
|
+
const synced = rippleSyncTracks(project, syncTracks, trackId, pivot, delta);
|
|
955
|
+
if (!synced.ok)
|
|
956
|
+
return synced;
|
|
957
|
+
const reached = new Set([
|
|
958
|
+
trackId,
|
|
959
|
+
...syncTracksOf(project, syncTracks, trackId).map((track) => track.id),
|
|
960
|
+
]);
|
|
961
|
+
const everyTrack = project.timeline.tracks.every((track) => reached.has(track.id));
|
|
962
|
+
const keys = (value) => (removed
|
|
963
|
+
? closeKeys(value, [[removed.start, removed.end]])
|
|
964
|
+
: openKeys(value, opened.at, opened.length));
|
|
965
|
+
let result = {
|
|
966
|
+
...synced.project,
|
|
967
|
+
timeline: {
|
|
968
|
+
...synced.project.timeline,
|
|
969
|
+
tracks: synced.project.timeline.tracks.map((track) => reached.has(track.id) && track.audio
|
|
970
|
+
? {
|
|
971
|
+
...track,
|
|
972
|
+
audio: {
|
|
973
|
+
...track.audio,
|
|
974
|
+
...(track.audio.gain ? { gain: keys(track.audio.gain) } : {}),
|
|
975
|
+
...(track.audio.pan ? { pan: keys(track.audio.pan) } : {}),
|
|
976
|
+
},
|
|
977
|
+
}
|
|
978
|
+
: track),
|
|
979
|
+
},
|
|
980
|
+
};
|
|
981
|
+
if (everyTrack) {
|
|
982
|
+
if (result.audio?.gain)
|
|
983
|
+
result = {
|
|
984
|
+
...result,
|
|
985
|
+
audio: { ...result.audio, gain: keys(result.audio.gain) },
|
|
986
|
+
};
|
|
987
|
+
result = rippleTimelineData(result, pivot, delta);
|
|
988
|
+
}
|
|
989
|
+
const finished = finish(result);
|
|
990
|
+
return finished.ok
|
|
991
|
+
? {
|
|
992
|
+
...finished,
|
|
993
|
+
timeline: { ...(removed ? { removed } : { opened }), everyTrack },
|
|
994
|
+
}
|
|
995
|
+
: finished;
|
|
996
|
+
}
|
|
904
997
|
function replaceTrack(project, track) {
|
|
905
998
|
return {
|
|
906
999
|
...project,
|
package/dist/export-failure.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Failure class. `RESOURCE_LIMIT` means the export was stopped before exceeding a budget.
|
|
9
9
|
* `RESOURCE_BUSY` means a device is held by other work (for example all hardware encoder
|
|
10
|
-
* sessions) and may free up later.
|
|
10
|
+
* sessions) and may free up later. `DEFECT` is an engine fault (a panic or a wasm trap), which a
|
|
11
|
+
* fresh worker or host may not repeat.
|
|
11
12
|
*/
|
|
12
|
-
export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "DEVICE_HUNG" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "RESOURCE_BUSY" | "CANCELLED" | "UNKNOWN";
|
|
13
|
+
export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "DEVICE_HUNG" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "RESOURCE_BUSY" | "CANCELLED" | "DEFECT" | "UNKNOWN";
|
|
13
14
|
/** Export step a failure belongs to. Steps overlap in a pipelined export. */
|
|
14
15
|
export type ExportPhase = "prepare" | "decode" | "upload" | "render" | "readback" | "encode" | "mux" | "publish" | "download" | "cleanup";
|
|
15
16
|
/** Reporting process. `node` is `@alpha2-sh/node` and `python` the `alpha2` Python package. */
|
|
@@ -83,6 +84,13 @@ export interface FailureClass {
|
|
|
83
84
|
readonly code: ExportFailureCode;
|
|
84
85
|
readonly resource: MemoryResource;
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Codes only the browser runtime makes: decode refusals, the frame supply, wasm traps, its
|
|
89
|
+
* workers, and the wasm binding's own `INVALID_STATE`.
|
|
90
|
+
*/
|
|
91
|
+
export declare const BROWSER_ERROR_CODES: readonly ["DECODE_UNAVAILABLE", "PLANAR_DECODE_UNAVAILABLE", "NON_PLANAR_FRAME", "FRAME_SUPPLY_FAILED", "SOFTWARE_DECODE_REQUIRED", "WASM_TRAP", "WASM_TRAPPED", "WASM_COMPILE_ERROR", "WASM_LINK_ERROR", "RENDER_WORKER_ERROR", "RENDER_WORKER_FAILED", "AUDIO_WORKER_ERROR", "INVALID_STATE"];
|
|
92
|
+
/** A code the browser runtime makes; see {@link BROWSER_ERROR_CODES}. */
|
|
93
|
+
export type BrowserErrorCode = (typeof BROWSER_ERROR_CODES)[number];
|
|
86
94
|
/** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
|
|
87
95
|
export declare function failureClassOfCode(code: unknown): FailureClass;
|
|
88
96
|
/** Context for {@link failureForCode}. */
|
package/dist/export-failure.js
CHANGED
|
@@ -43,6 +43,7 @@ const CODES = new Set([
|
|
|
43
43
|
"RESOURCE_LIMIT",
|
|
44
44
|
"RESOURCE_BUSY",
|
|
45
45
|
"CANCELLED",
|
|
46
|
+
"DEFECT",
|
|
46
47
|
"UNKNOWN",
|
|
47
48
|
]);
|
|
48
49
|
/** The well-formed failure `error` carries, if any. */
|
|
@@ -104,10 +105,29 @@ export function classifyBrowserFailure(error, context) {
|
|
|
104
105
|
}
|
|
105
106
|
const permanent = { code: "INVALID_INPUT", resource: "unknown" };
|
|
106
107
|
const unknown = { code: "UNKNOWN", resource: "unknown" };
|
|
108
|
+
const defect = { code: "DEFECT", resource: "unknown" };
|
|
107
109
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
110
|
+
* Codes only the browser runtime makes: decode refusals, the frame supply, wasm traps, its
|
|
111
|
+
* workers, and the wasm binding's own `INVALID_STATE`.
|
|
112
|
+
*/
|
|
113
|
+
export const BROWSER_ERROR_CODES = [
|
|
114
|
+
"DECODE_UNAVAILABLE",
|
|
115
|
+
"PLANAR_DECODE_UNAVAILABLE",
|
|
116
|
+
"NON_PLANAR_FRAME",
|
|
117
|
+
"FRAME_SUPPLY_FAILED",
|
|
118
|
+
"SOFTWARE_DECODE_REQUIRED",
|
|
119
|
+
"WASM_TRAP",
|
|
120
|
+
"WASM_TRAPPED",
|
|
121
|
+
"WASM_COMPILE_ERROR",
|
|
122
|
+
"WASM_LINK_ERROR",
|
|
123
|
+
"RENDER_WORKER_ERROR",
|
|
124
|
+
"RENDER_WORKER_FAILED",
|
|
125
|
+
"AUDIO_WORKER_ERROR",
|
|
126
|
+
"INVALID_STATE",
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* Failure class of each error code. Must match the host's `classify_failure`;
|
|
130
|
+
* `tests/cases/failure-classes.json` checks both.
|
|
111
131
|
*/
|
|
112
132
|
const CODE_CLASSES = Object.freeze({
|
|
113
133
|
UNSUPPORTED_PROTOCOL: permanent,
|
|
@@ -130,13 +150,33 @@ const CODE_CLASSES = Object.freeze({
|
|
|
130
150
|
OUTPUT_PUBLISH_FAILED: { code: "OUTPUT_IO_FAILED", resource: "unknown" },
|
|
131
151
|
CANCELLED: { code: "CANCELLED", resource: "unknown" },
|
|
132
152
|
RESOURCE_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
|
|
153
|
+
// Never started: the host was retiring, and another host runs it.
|
|
154
|
+
HOST_RETIRING: { code: "HOST_EXITED", resource: "unknown" },
|
|
155
|
+
// An extractor's own output or failure repeats on a retry; a slow client may not.
|
|
156
|
+
INVALID_EMIT: permanent,
|
|
157
|
+
EXTRACTOR_FAILED: permanent,
|
|
158
|
+
EXTRACTOR_TIMEOUT: unknown,
|
|
159
|
+
// A plugin that is refused, does not load or traps does so again; a server may answer later.
|
|
160
|
+
PLUGIN_FETCH_FAILED: unknown,
|
|
161
|
+
PLUGIN_HASH_MISMATCH: permanent,
|
|
162
|
+
PLUGIN_ABI_UNSUPPORTED: permanent,
|
|
163
|
+
PLUGIN_NO_ARTIFACT: permanent,
|
|
164
|
+
PLUGIN_NATIVE_REFUSED: permanent,
|
|
165
|
+
PLUGIN_REFUSED: permanent,
|
|
166
|
+
PLUGIN_DESCRIPTOR_MISMATCH: permanent,
|
|
167
|
+
PLUGIN_UNSUPPORTED_FEATURE: permanent,
|
|
168
|
+
PLUGIN_LOAD_FAILED: permanent,
|
|
169
|
+
PLUGIN_TRAPPED: permanent,
|
|
170
|
+
PLUGIN_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
|
|
133
171
|
GPU_INIT_FAILED: unknown,
|
|
134
172
|
ENCODE_ERROR: unknown,
|
|
135
173
|
ENCODER_BUSY: { code: "RESOURCE_BUSY", resource: "gpu" },
|
|
136
|
-
|
|
174
|
+
// A caught panic of the host.
|
|
175
|
+
INTERNAL: defect,
|
|
137
176
|
ALPHA2_ERROR: unknown,
|
|
138
177
|
// `@alpha2-sh/node` setup errors that a retry does not fix.
|
|
139
178
|
HOST_NOT_FOUND: permanent,
|
|
179
|
+
HOST_VERSION_MISMATCH: permanent,
|
|
140
180
|
HOST_NOT_EXECUTABLE: permanent,
|
|
141
181
|
HOST_LOAD_FAILED: permanent,
|
|
142
182
|
HOST_START_FAILED: unknown,
|
|
@@ -157,6 +197,17 @@ const CODE_CLASSES = Object.freeze({
|
|
|
157
197
|
NON_PLANAR_FRAME: permanent,
|
|
158
198
|
FRAME_SUPPLY_FAILED: unknown,
|
|
159
199
|
SOFTWARE_DECODE_REQUIRED: unknown,
|
|
200
|
+
// A module that does not compile or link, and a call the binding's state refuses, repeat.
|
|
201
|
+
WASM_COMPILE_ERROR: permanent,
|
|
202
|
+
WASM_LINK_ERROR: permanent,
|
|
203
|
+
INVALID_STATE: permanent,
|
|
204
|
+
// A trap is an engine fault; a fresh worker may not meet it again.
|
|
205
|
+
WASM_TRAP: defect,
|
|
206
|
+
WASM_TRAPPED: defect,
|
|
207
|
+
// A worker's error without a code of its own says nothing about a retry.
|
|
208
|
+
RENDER_WORKER_ERROR: unknown,
|
|
209
|
+
RENDER_WORKER_FAILED: unknown,
|
|
210
|
+
AUDIO_WORKER_ERROR: unknown,
|
|
160
211
|
});
|
|
161
212
|
/** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
|
|
162
213
|
export function failureClassOfCode(code) {
|
package/dist/export-retry.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - Memory exhaustion steps down to a smaller profile.
|
|
11
11
|
* - An encode failure retries once with the software video encoder when available.
|
|
12
12
|
* - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
|
|
13
|
+
* - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
|
|
14
|
+
* or host; a second one stops.
|
|
13
15
|
* - Other transient failures retry unchanged and step down only if they recur at the same point.
|
|
14
16
|
* A browser that has already lost the GPU twice moves to the CPU or stops, since the browser
|
|
15
17
|
* withdraws GPU access at the next reset.
|
|
@@ -41,7 +43,10 @@ export interface AttemptOutcome {
|
|
|
41
43
|
export interface RetryPolicyOptions {
|
|
42
44
|
/** Total attempts, including the first. Default 3. */
|
|
43
45
|
readonly maxAttempts?: number;
|
|
44
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Delay before attempt `n + 1`, given `n` failed attempts. Default `1000 * 2^(n-1)` ms, the
|
|
48
|
+
* exponent capped at 16.
|
|
49
|
+
*/
|
|
45
50
|
readonly backoffMs?: (failedAttempts: number) => number;
|
|
46
51
|
/** Profiles to step down through, largest first. Default {@link RETRY_PROFILES}. */
|
|
47
52
|
readonly profiles?: readonly RetryProfile[];
|
package/dist/export-retry.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - Memory exhaustion steps down to a smaller profile.
|
|
11
11
|
* - An encode failure retries once with the software video encoder when available.
|
|
12
12
|
* - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
|
|
13
|
+
* - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
|
|
14
|
+
* or host; a second one stops.
|
|
13
15
|
* - Other transient failures retry unchanged and step down only if they recur at the same point.
|
|
14
16
|
* A browser that has already lost the GPU twice moves to the CPU or stops, since the browser
|
|
15
17
|
* withdraws GPU access at the next reset.
|
|
@@ -56,7 +58,8 @@ export function isRetryableFailure(failure) {
|
|
|
56
58
|
export function decideRetry(history, options = {}) {
|
|
57
59
|
const maxAttempts = options.maxAttempts ?? 3;
|
|
58
60
|
const profiles = options.profiles ?? RETRY_PROFILES;
|
|
59
|
-
const backoff = options.backoffMs ??
|
|
61
|
+
const backoff = options.backoffMs ??
|
|
62
|
+
((failed) => 1_000 * 2 ** Math.min(failed - 1, 16));
|
|
60
63
|
const last = history.at(-1);
|
|
61
64
|
if (last === undefined)
|
|
62
65
|
return { retry: false, reason: "nothing failed", failure: undefined };
|
|
@@ -97,6 +100,14 @@ export function decideRetry(history, options = {}) {
|
|
|
97
100
|
? "it failed on the CPU renderer too"
|
|
98
101
|
: "there is no CPU renderer to retry on"}`, hung);
|
|
99
102
|
}
|
|
103
|
+
if (failure.code === "DEFECT") {
|
|
104
|
+
const defects = history.filter((attempt) => attempt.failure.code === "DEFECT").length;
|
|
105
|
+
if (defects > 1)
|
|
106
|
+
return stop("DEFECT again on a fresh attempt: the engine fails this export the same way");
|
|
107
|
+
if (!attemptsLeft)
|
|
108
|
+
return stop(`all ${maxAttempts} attempts failed`);
|
|
109
|
+
return retry(`DEFECT: an engine fault; retrying once on a fresh ${failure.origin === "browser" ? "worker" : "host"}`, { delayMs: 0 });
|
|
110
|
+
}
|
|
100
111
|
if (!isRetryableFailure(failure))
|
|
101
112
|
return stop(`${failure.code} at ${failure.phase} is not helped by a retry`);
|
|
102
113
|
if (!attemptsLeft)
|
package/dist/exporter.d.ts
CHANGED
|
@@ -93,7 +93,10 @@ export interface BrowserEncodeSink {
|
|
|
93
93
|
writeVideo(frame: ExportedFrame): Promise<void>;
|
|
94
94
|
/** Flushes the encoder and finalizes the container after the last frame. */
|
|
95
95
|
finish(): Promise<void>;
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Discards partial output; called once when the export fails, also while `finish` is pending. A
|
|
98
|
+
* `finish` that settles after `abort` must not commit the output.
|
|
99
|
+
*/
|
|
97
100
|
abort(reason: Error): Promise<void> | void;
|
|
98
101
|
/** Copied into the result when present. */
|
|
99
102
|
readonly videoLatencyProbe?: VideoLatencyProbe;
|
|
@@ -172,11 +175,12 @@ export declare class Alpha2Exporter {
|
|
|
172
175
|
* 0), not the preview's. The preview's coordinator moves past generation 0 after its first seek
|
|
173
176
|
* and would silently drop the export's requests.
|
|
174
177
|
*
|
|
175
|
-
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal
|
|
176
|
-
* `finish()
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
178
|
+
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal` before
|
|
179
|
+
* `finish()` resolves, even while it is pending, rejects immediately; late results are closed. An
|
|
180
|
+
* abort after `finish()` resolved is ignored. On other failures, held frames are closed and pending
|
|
181
|
+
* writes awaited. In both cases `sink.abort` is called once and the promise rejects with an
|
|
182
|
+
* {@link ExportAbortedError}, a `RESOURCE_LIMIT` `ExportFailureError`, a `RangeError` for an
|
|
183
|
+
* invalid option, or the error from the backend, `refill` or sink. An error thrown by
|
|
184
|
+
* `sink.abort` does not replace it.
|
|
181
185
|
*/
|
|
182
186
|
export declare function exportToSink(exporter: Alpha2Exporter, sink: BrowserEncodeSink, refill: (waiting: ExportWaiting) => Promise<void>, options?: BrowserExportOptions): Promise<BrowserExportResult>;
|
package/dist/exporter.js
CHANGED
|
@@ -157,12 +157,13 @@ export class Alpha2Exporter {
|
|
|
157
157
|
* 0), not the preview's. The preview's coordinator moves past generation 0 after its first seek
|
|
158
158
|
* and would silently drop the export's requests.
|
|
159
159
|
*
|
|
160
|
-
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal
|
|
161
|
-
* `finish()
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
160
|
+
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal` before
|
|
161
|
+
* `finish()` resolves, even while it is pending, rejects immediately; late results are closed. An
|
|
162
|
+
* abort after `finish()` resolved is ignored. On other failures, held frames are closed and pending
|
|
163
|
+
* writes awaited. In both cases `sink.abort` is called once and the promise rejects with an
|
|
164
|
+
* {@link ExportAbortedError}, a `RESOURCE_LIMIT` `ExportFailureError`, a `RangeError` for an
|
|
165
|
+
* invalid option, or the error from the backend, `refill` or sink. An error thrown by
|
|
166
|
+
* `sink.abort` does not replace it.
|
|
166
167
|
*/
|
|
167
168
|
export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
168
169
|
const started = performance.now();
|
|
@@ -206,7 +207,7 @@ export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
|
206
207
|
encodeQueueBytes -= write.retainedBytes;
|
|
207
208
|
}
|
|
208
209
|
};
|
|
209
|
-
// Also checked
|
|
210
|
+
// Also checked before finish(), so a cancel after the last submission still wins.
|
|
210
211
|
const cancelledError = (signal) => new ExportAbortedError("cancelled", "browser export cancelled", {
|
|
211
212
|
cause: signal.reason,
|
|
212
213
|
});
|
|
@@ -364,9 +365,9 @@ export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
|
364
365
|
pendingWrites.length = 0;
|
|
365
366
|
throwIfCancelled();
|
|
366
367
|
const finishStarted = performance.now();
|
|
367
|
-
|
|
368
|
+
// Once `finish` has resolved the output is committed, so the signal is not read again.
|
|
369
|
+
await cancellable(sink.finish());
|
|
368
370
|
metrics.finishMs = performance.now() - finishStarted;
|
|
369
|
-
throwIfCancelled();
|
|
370
371
|
const renderMs = performance.now() - started;
|
|
371
372
|
const completed = exporter.progress.completed;
|
|
372
373
|
const frames = Number(completed);
|