@alpha2-sh/editor 0.5.2 → 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 +60 -3
- package/dist/browser/bridge.d.ts +5 -4
- package/dist/browser/bridge.js +390 -67
- package/dist/browser/extensions-worker.d.ts +4 -3
- package/dist/browser/extensions-worker.js +13 -6
- package/dist/browser/jobs.d.ts +17 -0
- package/dist/browser/jobs.js +40 -0
- package/dist/browser/resources.d.ts +9 -4
- package/dist/browser/resources.js +17 -5
- package/dist/browser/runtime/assets.d.ts +14 -2
- package/dist/browser/runtime/assets.js +37 -27
- package/dist/browser/runtime/audio.d.ts +12 -2
- package/dist/browser/runtime/audio.js +124 -14
- package/dist/browser/runtime/engine.js +8 -1
- package/dist/browser/runtime/exporter.d.ts +2 -1
- package/dist/browser/runtime/exporter.js +15 -4
- package/dist/browser/runtime/extension-import.d.ts +30 -10
- package/dist/browser/runtime/extension-import.js +52 -9
- package/dist/browser/runtime/preview-utils.d.ts +12 -0
- package/dist/browser/runtime/preview-utils.js +45 -0
- package/dist/browser/runtime/sources.d.ts +2 -2
- package/dist/browser/runtime/sources.js +23 -40
- package/dist/browser/runtime/wasm.d.ts +5 -5
- package/dist/browser/runtime/wasm.js +6 -13
- package/dist/browser/types.d.ts +138 -26
- package/dist/browser/worker.d.ts +4 -2
- package/dist/browser/worker.js +75 -25
- package/dist/core/commands.d.ts +46 -3
- package/dist/core/commands.js +212 -40
- package/dist/core/compositions.d.ts +27 -0
- package/dist/core/compositions.js +43 -0
- package/dist/core/data.d.ts +34 -0
- package/dist/core/data.js +69 -0
- package/dist/core/document.d.ts +20 -1
- package/dist/core/document.js +138 -8
- package/dist/core/keyframes.d.ts +3 -2
- package/dist/core/keyframes.js +6 -2
- package/dist/core/sameness.d.ts +6 -0
- package/dist/core/sameness.js +42 -0
- package/dist/core/session.d.ts +85 -7
- package/dist/core/session.js +124 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/native-client/index.d.ts +2 -2
- package/dist/native-client/index.js +2 -2
- package/dist/ports/index.d.ts +5 -4
- package/package.json +3 -3
|
@@ -9,19 +9,20 @@ export function installExtensionsWorker(scope: {
|
|
|
9
9
|
postMessage(message: unknown): void;
|
|
10
10
|
}): void;
|
|
11
11
|
/**
|
|
12
|
-
* Runs an extensions call (`read`, `svg-diagnostics
|
|
12
|
+
* Runs an extensions call (`read`, `svg-diagnostics`, `exr-first-frame` or `describe`) on
|
|
13
|
+
* `request.file`, which `describe` omits for a provider that reads no file.
|
|
13
14
|
* With `factory`, the call runs in a new worker running {@link installExtensionsWorker}, terminated
|
|
14
15
|
* once it answers, when `signal` aborts (rejecting with its reason), or after `timeoutMs`
|
|
15
16
|
* (rejecting as `provider_stalled`). Without a factory, or if the worker script fails to load, the
|
|
16
17
|
* call runs on this thread, where it cannot be stopped and `signal` is checked between steps.
|
|
17
18
|
*
|
|
18
|
-
* @param {{ factory?: () => Worker, wasmUrl?: string | URL }} module
|
|
19
|
+
* @param {{ factory?: () => Worker, wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls }} module
|
|
19
20
|
* @param {{ call: string, file: Blob & { name?: string }, [key: string]: unknown }} request
|
|
20
21
|
* @param {{ signal?: AbortSignal, timeoutMs?: number, operation?: string }} [options]
|
|
21
22
|
*/
|
|
22
23
|
export function callExtensions({ factory, wasmUrl }: {
|
|
23
24
|
factory?: () => Worker;
|
|
24
|
-
wasmUrl?: string | URL;
|
|
25
|
+
wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls;
|
|
25
26
|
}, request: {
|
|
26
27
|
call: string;
|
|
27
28
|
file: Blob & {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// `@alpha2-sh/editor/extensions-worker` entry pass `runtimeAssets.extensionsWorkerFactory`; each
|
|
4
4
|
// call gets its own worker, terminated on cancel or past `EXTENSIONS_CALL_TIMEOUT_MS`.
|
|
5
5
|
import { EditorError } from "../core/document.js";
|
|
6
|
-
import { exrFirstFrame, readProviderFile, svgDiagnostics, } from "./runtime/extension-import.js";
|
|
6
|
+
import { exrFirstFrame, readProviderFile, readProviderSource, svgDiagnostics, } from "./runtime/extension-import.js";
|
|
7
7
|
/**
|
|
8
8
|
* How long one extensions worker call may run before the worker is terminated and the call fails as
|
|
9
9
|
* `provider_stalled`. Matches the 40 s a native decode shard may spend in one provider or decoder
|
|
@@ -22,6 +22,8 @@ const CALLS = {
|
|
|
22
22
|
"svg-diagnostics": (extensions, bytes, { provider, fonts }) => svgDiagnostics(extensions, provider, bytes, fonts),
|
|
23
23
|
/** An OpenEXR sequence's first frame: its thumbnail and report. */
|
|
24
24
|
"exr-first-frame": (extensions, bytes) => exrFirstFrame(extensions, bytes),
|
|
25
|
+
/** A provider source's report and thumbnail; no file for one that reads none. */
|
|
26
|
+
describe: (extensions, bytes, { provider }) => readProviderSource(extensions, provider, bytes),
|
|
25
27
|
};
|
|
26
28
|
async function run(request, wasmUrl, load, signal) {
|
|
27
29
|
const call = CALLS[request.call];
|
|
@@ -29,7 +31,9 @@ async function run(request, wasmUrl, load, signal) {
|
|
|
29
31
|
throw new Error(`unknown extensions call ${request.call}`);
|
|
30
32
|
const extensions = await load(wasmUrl);
|
|
31
33
|
signal?.throwIfAborted();
|
|
32
|
-
const bytes =
|
|
34
|
+
const bytes = request.file
|
|
35
|
+
? new Uint8Array(await request.file.arrayBuffer())
|
|
36
|
+
: undefined;
|
|
33
37
|
signal?.throwIfAborted();
|
|
34
38
|
return call(extensions, bytes, request);
|
|
35
39
|
}
|
|
@@ -58,21 +62,24 @@ export function installExtensionsWorker(scope) {
|
|
|
58
62
|
};
|
|
59
63
|
scope.postMessage({ type: "started" });
|
|
60
64
|
}
|
|
61
|
-
/** `url
|
|
65
|
+
/** Makes `url`, or each URL in a map of them, absolute, so a worker resolves it like the page. */
|
|
62
66
|
function absolute(url) {
|
|
63
67
|
if (url === undefined)
|
|
64
68
|
return undefined;
|
|
69
|
+
if (typeof url === "object" && !(url instanceof URL))
|
|
70
|
+
return Object.fromEntries(Object.entries(url).map(([name, each]) => [name, absolute(each)]));
|
|
65
71
|
const base = globalThis.location?.href;
|
|
66
72
|
return base ? new URL(String(url), base).href : String(url);
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
|
-
* Runs an extensions call (`read`, `svg-diagnostics
|
|
75
|
+
* Runs an extensions call (`read`, `svg-diagnostics`, `exr-first-frame` or `describe`) on
|
|
76
|
+
* `request.file`, which `describe` omits for a provider that reads no file.
|
|
70
77
|
* With `factory`, the call runs in a new worker running {@link installExtensionsWorker}, terminated
|
|
71
78
|
* once it answers, when `signal` aborts (rejecting with its reason), or after `timeoutMs`
|
|
72
79
|
* (rejecting as `provider_stalled`). Without a factory, or if the worker script fails to load, the
|
|
73
80
|
* call runs on this thread, where it cannot be stopped and `signal` is checked between steps.
|
|
74
81
|
*
|
|
75
|
-
* @param {{ factory?: () => Worker, wasmUrl?: string | URL }} module
|
|
82
|
+
* @param {{ factory?: () => Worker, wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls }} module
|
|
76
83
|
* @param {{ call: string, file: Blob & { name?: string }, [key: string]: unknown }} request
|
|
77
84
|
* @param {{ signal?: AbortSignal, timeoutMs?: number, operation?: string }} [options]
|
|
78
85
|
*/
|
|
@@ -103,7 +110,7 @@ export function callExtensions({ factory, wasmUrl }, request, { signal, timeoutM
|
|
|
103
110
|
};
|
|
104
111
|
const timer = setTimeout(() => {
|
|
105
112
|
end();
|
|
106
|
-
reject(new EditorError("provider_stalled", `${request.file
|
|
113
|
+
reject(new EditorError("provider_stalled", `${request.file?.name ?? "The source"} took the extension provider more than ${timeoutMs / 1000} s to read; it was stopped`, operation));
|
|
107
114
|
}, timeoutMs);
|
|
108
115
|
signal?.addEventListener("abort", abort, { once: true });
|
|
109
116
|
worker.onmessage = ({ data }) => {
|
package/dist/browser/jobs.d.ts
CHANGED
|
@@ -78,3 +78,20 @@ export declare class ExportJob {
|
|
|
78
78
|
*/
|
|
79
79
|
cancel(): Promise<void>;
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* One extraction running on the page. It stops when `signal` aborts, on {@link cancel}, or when
|
|
83
|
+
* the bridge is disposed; a stopped run rejects with `EditorError` `cancelled`.
|
|
84
|
+
*/
|
|
85
|
+
export declare class ExtractionJob<T> {
|
|
86
|
+
#private;
|
|
87
|
+
/** What `run` resolves to. */
|
|
88
|
+
readonly result: Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Starts `run` with the job's own signal.
|
|
91
|
+
*
|
|
92
|
+
* @param release Called once when the job settles.
|
|
93
|
+
*/
|
|
94
|
+
constructor(run: (signal: AbortSignal) => Promise<T>, signal: AbortSignal | undefined, release: () => void);
|
|
95
|
+
/** Stops the run; resolves once it has settled. */
|
|
96
|
+
cancel(): Promise<void>;
|
|
97
|
+
}
|
package/dist/browser/jobs.js
CHANGED
|
@@ -302,3 +302,43 @@ function phaseOf(progress) {
|
|
|
302
302
|
return "prepare";
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* One extraction running on the page. It stops when `signal` aborts, on {@link cancel}, or when
|
|
307
|
+
* the bridge is disposed; a stopped run rejects with `EditorError` `cancelled`.
|
|
308
|
+
*/
|
|
309
|
+
export class ExtractionJob {
|
|
310
|
+
/** What `run` resolves to. */
|
|
311
|
+
result;
|
|
312
|
+
#controller = new AbortController();
|
|
313
|
+
/**
|
|
314
|
+
* Starts `run` with the job's own signal.
|
|
315
|
+
*
|
|
316
|
+
* @param release Called once when the job settles.
|
|
317
|
+
*/
|
|
318
|
+
constructor(run, signal, release) {
|
|
319
|
+
const own = this.#controller.signal;
|
|
320
|
+
const abort = () => this.#controller.abort(signal?.reason);
|
|
321
|
+
if (signal?.aborted)
|
|
322
|
+
abort();
|
|
323
|
+
else
|
|
324
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
325
|
+
this.result = Promise.resolve()
|
|
326
|
+
.then(() => run(own))
|
|
327
|
+
.catch((cause) => {
|
|
328
|
+
if (!own.aborted)
|
|
329
|
+
throw cause;
|
|
330
|
+
throw new EditorError("cancelled", "Extraction cancelled", "extract", undefined, true, { cause });
|
|
331
|
+
})
|
|
332
|
+
.finally(() => {
|
|
333
|
+
signal?.removeEventListener("abort", abort);
|
|
334
|
+
release();
|
|
335
|
+
});
|
|
336
|
+
// A run cancelled before anyone awaits it is not an unhandled rejection.
|
|
337
|
+
void this.result.catch(() => { });
|
|
338
|
+
}
|
|
339
|
+
/** Stops the run; resolves once it has settled. */
|
|
340
|
+
cancel() {
|
|
341
|
+
this.#controller.abort();
|
|
342
|
+
return this.result.then(() => { }, () => { });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
@@ -13,20 +13,25 @@ export interface Lease<T> {
|
|
|
13
13
|
export declare class ResourceRegistry<T> {
|
|
14
14
|
#private;
|
|
15
15
|
readonly limit: number;
|
|
16
|
-
/** @param limit Most entries held at once (default 128). */
|
|
16
|
+
/** @param limit Most counted entries held at once (default 128). */
|
|
17
17
|
constructor(limit?: number);
|
|
18
18
|
/**
|
|
19
19
|
* Stores `value` under `id` at `revision` and returns its first lease. `dispose` runs once,
|
|
20
|
-
* when the last lease is released or the registry is disposed.
|
|
20
|
+
* when the last lease is released or the registry is disposed. An entry put with
|
|
21
|
+
* `counted: false` is held whatever the limit and does not use its room.
|
|
21
22
|
*
|
|
22
23
|
* Throws `EditorError` `disposed` after {@link dispose}, `duplicate_resource` if that revision
|
|
23
|
-
* is already stored, and `resource_budget` when `limit` entries
|
|
24
|
+
* is already stored, and `resource_budget` when a counted entry finds `limit` counted entries.
|
|
24
25
|
*/
|
|
25
|
-
put(id: string, revision: number, value: T, dispose: () => void
|
|
26
|
+
put(id: string, revision: number, value: T, dispose: () => void, { counted }?: {
|
|
27
|
+
counted?: boolean;
|
|
28
|
+
}): Lease<T>;
|
|
26
29
|
/** Takes another lease on a stored entry. Throws `EditorError` `missing_asset` if absent. */
|
|
27
30
|
acquire(id: string, revision: number): Lease<T>;
|
|
28
31
|
/** Entries currently held. */
|
|
29
32
|
get size(): number;
|
|
33
|
+
/** Entries currently held that count against `limit`. */
|
|
34
|
+
get counted(): number;
|
|
30
35
|
/**
|
|
31
36
|
* Disposes every entry regardless of outstanding leases and refuses later `put` calls.
|
|
32
37
|
* Idempotent.
|
|
@@ -6,30 +6,35 @@ import { EditorError } from "../core/document.js";
|
|
|
6
6
|
export class ResourceRegistry {
|
|
7
7
|
limit;
|
|
8
8
|
#entries = new Map();
|
|
9
|
+
#counted = 0;
|
|
9
10
|
#closed = false;
|
|
10
|
-
/** @param limit Most entries held at once (default 128). */
|
|
11
|
+
/** @param limit Most counted entries held at once (default 128). */
|
|
11
12
|
constructor(limit = 128) {
|
|
12
13
|
this.limit = limit;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Stores `value` under `id` at `revision` and returns its first lease. `dispose` runs once,
|
|
16
|
-
* when the last lease is released or the registry is disposed.
|
|
17
|
+
* when the last lease is released or the registry is disposed. An entry put with
|
|
18
|
+
* `counted: false` is held whatever the limit and does not use its room.
|
|
17
19
|
*
|
|
18
20
|
* Throws `EditorError` `disposed` after {@link dispose}, `duplicate_resource` if that revision
|
|
19
|
-
* is already stored, and `resource_budget` when `limit` entries
|
|
21
|
+
* is already stored, and `resource_budget` when a counted entry finds `limit` counted entries.
|
|
20
22
|
*/
|
|
21
|
-
put(id, revision, value, dispose) {
|
|
23
|
+
put(id, revision, value, dispose, { counted = true } = {}) {
|
|
22
24
|
if (this.#closed)
|
|
23
25
|
throw new EditorError("disposed", "Resources are closed", "resource");
|
|
24
26
|
const key = JSON.stringify([id, revision]);
|
|
25
27
|
if (this.#entries.has(key))
|
|
26
28
|
throw new EditorError("duplicate_resource", "Resource revision already exists", "resource", id);
|
|
27
|
-
if (this.#
|
|
29
|
+
if (counted && this.#counted >= this.limit)
|
|
28
30
|
throw new EditorError("resource_budget", "Resource budget reached", "resource", id);
|
|
29
31
|
let closed = false;
|
|
32
|
+
if (counted)
|
|
33
|
+
this.#counted++;
|
|
30
34
|
this.#entries.set(key, {
|
|
31
35
|
value,
|
|
32
36
|
refs: 0,
|
|
37
|
+
counted,
|
|
33
38
|
dispose: () => {
|
|
34
39
|
if (!closed) {
|
|
35
40
|
closed = true;
|
|
@@ -55,6 +60,8 @@ export class ResourceRegistry {
|
|
|
55
60
|
released = true;
|
|
56
61
|
if (--entry.refs === 0) {
|
|
57
62
|
this.#entries.delete(key);
|
|
63
|
+
if (entry.counted)
|
|
64
|
+
this.#counted--;
|
|
58
65
|
entry.dispose();
|
|
59
66
|
}
|
|
60
67
|
},
|
|
@@ -64,6 +71,10 @@ export class ResourceRegistry {
|
|
|
64
71
|
get size() {
|
|
65
72
|
return this.#entries.size;
|
|
66
73
|
}
|
|
74
|
+
/** Entries currently held that count against `limit`. */
|
|
75
|
+
get counted() {
|
|
76
|
+
return this.#counted;
|
|
77
|
+
}
|
|
67
78
|
/**
|
|
68
79
|
* Disposes every entry regardless of outstanding leases and refuses later `put` calls.
|
|
69
80
|
* Idempotent.
|
|
@@ -75,5 +86,6 @@ export class ResourceRegistry {
|
|
|
75
86
|
for (const entry of this.#entries.values())
|
|
76
87
|
entry.dispose();
|
|
77
88
|
this.#entries.clear();
|
|
89
|
+
this.#counted = 0;
|
|
78
90
|
}
|
|
79
91
|
}
|
|
@@ -23,6 +23,17 @@ export function probeVideo(file: any): Promise<{
|
|
|
23
23
|
* `facts` describe the video track when the probe read one.
|
|
24
24
|
*/
|
|
25
25
|
export function importFailureReason(error: any, kind: any, facts: any): string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this browser decodes a file's primary audio, using the preview decoder's trial decode
|
|
28
|
+
* (`probeAudioSource`), and the refusal facts when not.
|
|
29
|
+
*/
|
|
30
|
+
export function audioDecoding(file: any): Promise<{
|
|
31
|
+
decodable: boolean;
|
|
32
|
+
facts: null;
|
|
33
|
+
} | {
|
|
34
|
+
decodable: boolean;
|
|
35
|
+
facts: import("alpha2/hdr-frames").TrackDecodeFacts;
|
|
36
|
+
}>;
|
|
26
37
|
/**
|
|
27
38
|
* Streams a file's primary audio track into per-bucket peak magnitudes (`bucketsPerSecond`, capped
|
|
28
39
|
* at `maxBuckets`) with bounded memory. A bucket's peak is its loudest sample in any channel,
|
|
@@ -153,8 +164,9 @@ export class AssetLibrary {
|
|
|
153
164
|
}>;
|
|
154
165
|
/**
|
|
155
166
|
* Imports one browser file as an image, video or audio asset. Rejects with an `EditorError`:
|
|
156
|
-
* `unsupported_media` for a file that is none of those
|
|
157
|
-
*
|
|
167
|
+
* `unsupported_media` for a file that is none of those or a video this browser decodes none of
|
|
168
|
+
* (its `cause` a `DecodeUnavailableError` with the track's `facts`), `unreadable_media` when this
|
|
169
|
+
* browser cannot read it (with the decoder's or demuxer's reason as message and `cause`), or with
|
|
158
170
|
* `signal`'s reason once it aborts a decode.
|
|
159
171
|
*/
|
|
160
172
|
importFile(file: any, { signal }?: {}): Promise<{
|
|
@@ -7,7 +7,7 @@ import { OffscreenTextRasterizer } from "alpha2/text";
|
|
|
7
7
|
import { ALL_FORMATS, AudioSampleSink, BlobSource, Input } from "mediabunny";
|
|
8
8
|
const uid = (prefix) => `${prefix}-${crypto.randomUUID()}`;
|
|
9
9
|
import { drawGenerator, generatorLabel } from "./generators.js";
|
|
10
|
-
import { seekVideoFrame } from "./preview-utils.js";
|
|
10
|
+
import { loadedOrFailed, seekVideoFrame, unloadVideo, } from "./preview-utils.js";
|
|
11
11
|
import { decodeStill } from "./still.js";
|
|
12
12
|
import { readUserText } from "./text.js";
|
|
13
13
|
import { EditorError } from "../../core/document.js";
|
|
@@ -171,8 +171,9 @@ export class AssetLibrary {
|
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* Imports one browser file as an image, video or audio asset. Rejects with an `EditorError`:
|
|
174
|
-
* `unsupported_media` for a file that is none of those
|
|
175
|
-
*
|
|
174
|
+
* `unsupported_media` for a file that is none of those or a video this browser decodes none of
|
|
175
|
+
* (its `cause` a `DecodeUnavailableError` with the track's `facts`), `unreadable_media` when this
|
|
176
|
+
* browser cannot read it (with the decoder's or demuxer's reason as message and `cause`), or with
|
|
176
177
|
* `signal`'s reason once it aborts a decode.
|
|
177
178
|
*/
|
|
178
179
|
async importFile(file, { signal } = {}) {
|
|
@@ -202,7 +203,11 @@ export class AssetLibrary {
|
|
|
202
203
|
throw signal.reason;
|
|
203
204
|
if (error instanceof EditorError)
|
|
204
205
|
throw error;
|
|
205
|
-
|
|
206
|
+
const facts = probe?.video?.facts;
|
|
207
|
+
const refused = as === "video" && facts && !probe.video.decodable && undecodable(error)
|
|
208
|
+
? new DecodeUnavailableError(decodeRefusalMessage(file.name, facts), facts, { cause: error })
|
|
209
|
+
: null;
|
|
210
|
+
throw new EditorError(refused ? "unsupported_media" : "unreadable_media", `Cannot read ${file.name} as ${as}: ${importFailureReason(error, as, facts)}`, "import", undefined, true, { cause: refused ?? error });
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
/** A still keeps its file, size and thumbnail; `SourcePixels` decodes it again per frame. */
|
|
@@ -277,17 +282,20 @@ export class AssetLibrary {
|
|
|
277
282
|
preload: "auto",
|
|
278
283
|
loop: false,
|
|
279
284
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
video.removeAttribute("src");
|
|
285
|
+
let failed = null;
|
|
286
|
+
try {
|
|
287
|
+
await loadedOrFailed(video, { signal });
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
unloadVideo(video);
|
|
291
|
+
if (signal?.aborted)
|
|
292
|
+
throw signal.reason;
|
|
293
|
+
failed = error;
|
|
290
294
|
}
|
|
295
|
+
// The element is a fallback reader, not the gate: Chrome's media pipeline refuses some files
|
|
296
|
+
// WebCodecs decodes (a stream copy cut inside an open GOP), and some never finish loading.
|
|
297
|
+
if (failed && !probe?.video?.decodable)
|
|
298
|
+
throw failed;
|
|
291
299
|
const element = failed ? null : video;
|
|
292
300
|
if (!probe && !video.videoWidth)
|
|
293
301
|
throw new Error("the browser found no picture in it");
|
|
@@ -545,20 +553,26 @@ export async function probeVideo(file) {
|
|
|
545
553
|
/** `MediaError` codes: the source is in a format the element does not read, or did not decode. */
|
|
546
554
|
const MEDIA_ERR_DECODE = 3;
|
|
547
555
|
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
|
556
|
+
function mediaOrBrowserError(error) {
|
|
557
|
+
return ((typeof DOMException !== "undefined" && error instanceof DOMException) ||
|
|
558
|
+
(!(error instanceof Error) && typeof error?.code === "number"));
|
|
559
|
+
}
|
|
560
|
+
function undecodable(error) {
|
|
561
|
+
if (!mediaOrBrowserError(error))
|
|
562
|
+
return false;
|
|
563
|
+
return ((typeof DOMException !== "undefined" && error instanceof DOMException) ||
|
|
564
|
+
error?.code === MEDIA_ERR_DECODE ||
|
|
565
|
+
error?.code === MEDIA_ERR_SRC_NOT_SUPPORTED);
|
|
566
|
+
}
|
|
548
567
|
/**
|
|
549
568
|
* Why an import failed, in this editor's words. Browser error text (`MediaError`, decoder
|
|
550
569
|
* `DOMException`) exposes engine internals, so it is never shown and stays the error's cause.
|
|
551
570
|
* `facts` describe the video track when the probe read one.
|
|
552
571
|
*/
|
|
553
572
|
export function importFailureReason(error, kind, facts) {
|
|
554
|
-
|
|
555
|
-
const mediaError = !(error instanceof Error) && typeof error?.code === "number";
|
|
556
|
-
if (!mediaError && !browserError && error instanceof Error)
|
|
573
|
+
if (!mediaOrBrowserError(error) && error instanceof Error)
|
|
557
574
|
return error.message;
|
|
558
|
-
|
|
559
|
-
error?.code === MEDIA_ERR_DECODE ||
|
|
560
|
-
error?.code === MEDIA_ERR_SRC_NOT_SUPPORTED;
|
|
561
|
-
if (!undecodable)
|
|
575
|
+
if (!undecodable(error))
|
|
562
576
|
return `this browser could not read the ${kind}`;
|
|
563
577
|
if (kind !== "video" || !facts)
|
|
564
578
|
return `this browser cannot decode this ${kind}`;
|
|
@@ -586,7 +600,7 @@ async function containerDuration(file) {
|
|
|
586
600
|
* Whether this browser decodes a file's primary audio, using the preview decoder's trial decode
|
|
587
601
|
* (`probeAudioSource`), and the refusal facts when not.
|
|
588
602
|
*/
|
|
589
|
-
async function audioDecoding(file) {
|
|
603
|
+
export async function audioDecoding(file) {
|
|
590
604
|
try {
|
|
591
605
|
await probeAudioSource(file.name, file);
|
|
592
606
|
return { decodable: true, facts: null };
|
|
@@ -719,11 +733,7 @@ async function videoThumbnail(video, width, height) {
|
|
|
719
733
|
const clone = video.cloneNode(true);
|
|
720
734
|
clone.muted = true;
|
|
721
735
|
try {
|
|
722
|
-
await
|
|
723
|
-
clone.onloadeddata = resolve;
|
|
724
|
-
clone.onerror = () => reject(clone.error);
|
|
725
|
-
clone.load();
|
|
726
|
-
});
|
|
736
|
+
await loadedOrFailed(clone);
|
|
727
737
|
await seekVideoFrame(clone, Math.min(0.25 * (clone.duration || 1), 1));
|
|
728
738
|
return thumbnailFrom(clone, width, height);
|
|
729
739
|
}
|
|
@@ -18,12 +18,22 @@ export function playbackStartSample(tick: any, sampleRate: any): number;
|
|
|
18
18
|
/**
|
|
19
19
|
* Supplies bounded source windows requested by the engine. Page-synthesized audio keeps its
|
|
20
20
|
* AudioBuffer, but only the requested slice enters wasm.
|
|
21
|
+
*
|
|
22
|
+
* With `onError` (preview), a stream this browser cannot decode or the file does not have plays
|
|
23
|
+
* silent for the rest of the session and is reported to it once; without it (export) its supply
|
|
24
|
+
* rejects.
|
|
21
25
|
*/
|
|
22
26
|
export class AudioWindowSupplier {
|
|
23
|
-
constructor(library: any);
|
|
27
|
+
constructor(library: any, { onError }?: {});
|
|
24
28
|
configure(engine: any, project: any): void;
|
|
25
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Uploads what the engine needs for `frames` samples from `startSample`. `forceSources` are
|
|
31
|
+
* uploaded again even where the engine holds a window; `silentSources` are uploaded as silence
|
|
32
|
+
* that covers any channel selection.
|
|
33
|
+
*/
|
|
34
|
+
supply(startSample: any, frames: any, { signal, forceSources, silentSources }?: {
|
|
26
35
|
forceSources?: never[] | undefined;
|
|
36
|
+
silentSources?: Set<any> | undefined;
|
|
27
37
|
}): Promise<void>;
|
|
28
38
|
close(): Promise<void>;
|
|
29
39
|
#private;
|