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.
Files changed (119) hide show
  1. package/README.md +5 -4
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/dist/abort.d.ts +12 -0
  4. package/dist/abort.js +48 -0
  5. package/dist/active-clock.d.ts +35 -0
  6. package/dist/active-clock.js +99 -0
  7. package/dist/assets.d.ts +28 -22
  8. package/dist/assets.js +8 -12
  9. package/dist/audio-layout.d.ts +52 -74
  10. package/dist/audio-layout.js +114 -148
  11. package/dist/audio-timeline.d.ts +89 -117
  12. package/dist/audio-timeline.js +102 -118
  13. package/dist/audio-worker.d.ts +12 -21
  14. package/dist/audio-worker.js +8 -13
  15. package/dist/audio-worklet-processor.js +45 -58
  16. package/dist/audio-worklet.d.ts +45 -76
  17. package/dist/audio-worklet.js +44 -79
  18. package/dist/audio.d.ts +15 -23
  19. package/dist/audio.js +9 -13
  20. package/dist/builder.d.ts +45 -63
  21. package/dist/builder.js +49 -45
  22. package/dist/capabilities.d.ts +99 -16
  23. package/dist/capabilities.js +2 -2
  24. package/dist/captions.d.ts +45 -22
  25. package/dist/captions.js +60 -15
  26. package/dist/chroma-siting.d.ts +24 -41
  27. package/dist/chroma-siting.js +38 -71
  28. package/dist/containers.d.ts +41 -30
  29. package/dist/containers.js +59 -27
  30. package/dist/decoder-fallback.d.ts +13 -0
  31. package/dist/decoder-fallback.js +38 -0
  32. package/dist/decoder-order.d.ts +24 -39
  33. package/dist/decoder-order.js +28 -42
  34. package/dist/edit.d.ts +77 -154
  35. package/dist/edit.js +98 -180
  36. package/dist/effects.d.ts +108 -177
  37. package/dist/effects.js +7 -9
  38. package/dist/export-destination.d.ts +25 -41
  39. package/dist/export-destination.js +20 -32
  40. package/dist/export-failure.d.ts +34 -59
  41. package/dist/export-failure.js +54 -48
  42. package/dist/export-metrics.d.ts +116 -0
  43. package/dist/export-metrics.js +74 -0
  44. package/dist/export-retry.d.ts +46 -29
  45. package/dist/export-retry.js +86 -51
  46. package/dist/exporter.d.ts +67 -116
  47. package/dist/exporter.js +133 -133
  48. package/dist/extensions.d.ts +69 -115
  49. package/dist/extensions.js +55 -82
  50. package/dist/frame-intake.d.ts +92 -0
  51. package/dist/frame-intake.js +114 -0
  52. package/dist/frame-supply.d.ts +96 -162
  53. package/dist/frame-supply.js +181 -171
  54. package/dist/generated/project-schema.d.ts +701 -485
  55. package/dist/generated/project-schema.js +55 -2
  56. package/dist/generated/project-shape.js +261 -16
  57. package/dist/geometry.d.ts +28 -34
  58. package/dist/geometry.js +18 -23
  59. package/dist/gpu-recovery.d.ts +92 -0
  60. package/dist/gpu-recovery.js +135 -0
  61. package/dist/hdr-frames.d.ts +82 -67
  62. package/dist/hdr-frames.js +112 -49
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.js +4 -0
  65. package/dist/json-text.d.ts +13 -23
  66. package/dist/json-text.js +10 -20
  67. package/dist/layout-values.d.ts +14 -22
  68. package/dist/layout-values.js +18 -21
  69. package/dist/layout.d.ts +48 -63
  70. package/dist/layout.js +37 -37
  71. package/dist/loudness.d.ts +27 -32
  72. package/dist/loudness.js +19 -23
  73. package/dist/media.d.ts +85 -237
  74. package/dist/media.js +133 -287
  75. package/dist/mediabunny.d.ts +166 -245
  76. package/dist/mediabunny.js +741 -580
  77. package/dist/physical-frames.d.ts +5 -17
  78. package/dist/physical-frames.js +4 -11
  79. package/dist/player.d.ts +56 -47
  80. package/dist/player.js +155 -40
  81. package/dist/presented-frames.d.ts +2 -7
  82. package/dist/presented-frames.js +3 -8
  83. package/dist/project.d.ts +73 -117
  84. package/dist/project.js +384 -445
  85. package/dist/rate-control.d.ts +9 -23
  86. package/dist/rate-control.js +7 -18
  87. package/dist/renderer-choice.d.ts +41 -0
  88. package/dist/renderer-choice.js +82 -0
  89. package/dist/repacked-bytes.d.ts +0 -2
  90. package/dist/repacked-bytes.js +2 -5
  91. package/dist/robustness.d.ts +25 -37
  92. package/dist/robustness.js +71 -54
  93. package/dist/sha256.d.ts +5 -13
  94. package/dist/sha256.js +9 -24
  95. package/dist/text.d.ts +97 -71
  96. package/dist/text.js +33 -70
  97. package/dist/video-frames.d.ts +7 -25
  98. package/dist/video-frames.js +12 -29
  99. package/dist/waveform.d.ts +5 -11
  100. package/dist/waveform.js +4 -9
  101. package/dist/worker-error.d.ts +5 -20
  102. package/dist/worker-error.js +8 -25
  103. package/dist/worker.d.ts +82 -95
  104. package/dist/worker.js +235 -143
  105. package/package.json +26 -2
  106. package/wasm/alpha2_audio_worklet.wasm +0 -0
  107. package/wasm/alpha2_extensions.d.ts +26 -47
  108. package/wasm/alpha2_extensions.js +26 -47
  109. package/wasm/alpha2_extensions_bg.wasm +0 -0
  110. package/wasm/alpha2_wasm.d.ts +460 -567
  111. package/wasm/alpha2_wasm.js +594 -594
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
@@ -0,0 +1,13 @@
1
+ import { type TrackDecodeFacts } from "./hdr-frames.js";
2
+ /** Whether `error` is a WebCodecs decoder failure (not an abort, stall or end of stream). */
3
+ export declare function isDecoderFailure(error: unknown): boolean;
4
+ /**
5
+ * Runs `decodeOnce`; on a decoder failure, if `reopenSoftware` is given, reopens in software and
6
+ * runs it once more.
7
+ */
8
+ export declare function withSoftwareFallback<T>(decodeOnce: () => Promise<T>, reopenSoftware: ((cause: DOMException) => Promise<void>) | undefined): Promise<T>;
9
+ /**
10
+ * Turns a decoder failure into {@link DecodeUnavailableError} when no frame of the track was ever
11
+ * decoded. Other errors are returned unchanged.
12
+ */
13
+ export declare function decodeFailureOf(error: unknown, name: string, facts: TrackDecodeFacts, decodedAny: boolean): unknown;
@@ -0,0 +1,38 @@
1
+ // Shared decoder failure policy: retry once in software, and report a track that never produced a
2
+ // frame as undecodable rather than as a retryable failure.
3
+ import { DecodeUnavailableError, decodeRefusalMessage, } from "./hdr-frames.js";
4
+ /** Whether `error` is a WebCodecs decoder failure (not an abort, stall or end of stream). */
5
+ export function isDecoderFailure(error) {
6
+ return (error instanceof DOMException &&
7
+ ["EncodingError", "NotSupportedError", "OperationError"].includes(error.name));
8
+ }
9
+ /**
10
+ * Runs `decodeOnce`; on a decoder failure, if `reopenSoftware` is given, reopens in software and
11
+ * runs it once more.
12
+ */
13
+ export async function withSoftwareFallback(decodeOnce, reopenSoftware) {
14
+ try {
15
+ return await decodeOnce();
16
+ }
17
+ catch (error) {
18
+ if (reopenSoftware === undefined || !isDecoderFailure(error))
19
+ throw error;
20
+ await reopenSoftware(error);
21
+ return decodeOnce();
22
+ }
23
+ }
24
+ /**
25
+ * Turns a decoder failure into {@link DecodeUnavailableError} when no frame of the track was ever
26
+ * decoded. Other errors are returned unchanged.
27
+ */
28
+ export function decodeFailureOf(error, name, facts, decodedAny) {
29
+ if (decodedAny || !isDecoderFailure(error))
30
+ return error;
31
+ const refused = {
32
+ ...facts,
33
+ browserError: `${error.name}: ${error.message}`,
34
+ };
35
+ return new DecodeUnavailableError(decodeRefusalMessage(name, refused), refused, {
36
+ cause: error,
37
+ });
38
+ }
@@ -1,66 +1,51 @@
1
1
  /**
2
- * A short 48 kHz file whose plane `k`, decoded in the order `FFmpeg`'s decoder delivers, holds the
3
- * tone `tones[k]` and nothing else: what a browser decoder's channel order is measured with
4
- * (`scripts/generate-decoder-order-fixtures.mjs` writes them).
2
+ * A short 48 kHz file whose plane `k`, in `FFmpeg`'s order, holds only tone `tones[k]`. Written by
3
+ * `scripts/generate-decoder-order-fixtures.mjs`.
5
4
  */
6
5
  export interface DecoderOrderFixture {
7
- /** The speakers `FFmpeg` decodes the file into, in its order. */
6
+ /** Speakers in `FFmpeg`'s order. */
8
7
  readonly speakers: readonly string[];
9
- /** Each plane's tone in hertz, by plane in `FFmpeg`'s order: 93.75 Hz for the LFE. */
8
+ /** Tone per plane in hertz, in `FFmpeg`'s order (93.75 Hz for the LFE). */
10
9
  readonly tones: readonly number[];
11
- /**
12
- * The sample of the decoded planes the tones are read from, 1024 samples on: past the codec's
13
- * priming and the encoder's first frame.
14
- */
10
+ /** First sample analyzed, past the codec priming and the encoder's first frame. */
15
11
  readonly start: number;
16
- /** The file, base64. */
12
+ /** Base64 file contents. */
17
13
  readonly file: string;
18
14
  }
19
15
  /**
20
- * What decides the order `codec`'s decoder delivers a stream's planes in, as a fixture key, or
21
- * `null` for a stream of one or two channels, which every decoder delivers in one order, and for
22
- * a codec whose decoders deliver one order (`FFmpeg` keeps FLAC's, PCM's and an unspecified
23
- * layout's), or that no browser path decodes:
16
+ * Fixture key for the stream property that decides decoder plane order, or `null` when order
17
+ * cannot vary (one or two channels, or codecs with a single order such as FLAC and PCM):
24
18
  *
25
- * - AAC: the channel configuration (`aac:6`), the ADTS header's for a stream without a
26
- * description (`aac:adts:6`), or the elements of a program config element (`aac:pce:SF CF CB LL`,
27
- * {@link aacProgramConfigElements});
28
- * - Opus mapping family 1: the channel count (`opus:1:6`);
29
- * - Vorbis: the channel count (`vorbis:6`);
30
- * - AC-3 and E-AC-3: the speakers the first packet's frame header declares
31
- * (`ac3:FL FR FC LFE SL SR`).
19
+ * - AAC: channel configuration (`aac:6`), ADTS configuration without a description
20
+ * (`aac:adts:6`), or program config elements (`aac:pce:SF CF CB LL`);
21
+ * - Opus mapping family 1: channel count (`opus:1:6`);
22
+ * - Vorbis: channel count (`vorbis:6`);
23
+ * - AC-3 and E-AC-3: speakers in the first frame header (`ac3:FL FR FC LFE SL SR`).
32
24
  *
33
- * A key without a fixture is not measured, and its decoder's order is taken as `FFmpeg`'s.
25
+ * Keys without a fixture are assumed to decode in `FFmpeg`'s order.
34
26
  */
35
27
  export declare function decoderOrderKey(codec: string | null, description: Uint8Array | null, channels: number, packet?: Uint8Array | null): string | null;
36
- /** The fixture that measures streams keyed `key` ({@link decoderOrderKey}), or `null`. */
28
+ /** Fixture for a {@link decoderOrderKey} key, or `null`. */
37
29
  export declare function decoderOrderFixture(key: string): Promise<DecoderOrderFixture | null>;
38
30
  /**
39
- * For each decoded plane, the plane of `FFmpeg`'s order it holds: the plane whose tone it holds
40
- * well above every other. `null` unless that names every plane once, or when a plane is too short
41
- * to read.
31
+ * Maps each decoded plane to its index in `FFmpeg`'s order by its dominant tone. Returns `null`
32
+ * unless every plane is identified exactly once.
42
33
  *
43
- * @param planes A fixture's decoded planes, in the decoder's order.
44
- * @param tones Each plane's tone in `FFmpeg`'s order.
45
- * @param start The sample the tones are read from.
34
+ * @param planes Decoded fixture planes, in the decoder's order.
35
+ * @param tones Tone per plane in `FFmpeg`'s order.
36
+ * @param start First sample analyzed.
46
37
  */
47
38
  export declare function planeOrderOfTones(planes: readonly Float32Array[], tones: readonly number[], sampleRate: number, start: number): number[] | null;
48
- /** A fixture decoded: its planes in the decoder's order and their sample rate. */
39
+ /** Decoded fixture planes in the decoder's order. */
49
40
  export interface DecodedFixture {
50
41
  readonly planes: readonly Float32Array[];
51
42
  readonly sampleRate: number;
52
43
  }
53
- /** Decodes a fixture file's primary audio track whole. */
54
44
  export type FixtureDecode = (file: Uint8Array) => Promise<DecodedFixture>;
55
- /**
56
- * The plane order `decode` delivers `fixture` in ({@link planeOrderOfTones}), or `null` when it
57
- * cannot be measured: the decode fails, or its planes do not each hold one tone.
58
- */
45
+ /** Plane order of `fixture` as `decode` delivers it, or `null` when it cannot be measured. */
59
46
  export declare function measurePlaneOrder(fixture: DecoderOrderFixture, decode: FixtureDecode): Promise<number[] | null>;
60
47
  /**
61
- * For each plane mediabunny's decoder delivers for streams keyed `key` ({@link decoderOrderKey}),
62
- * the plane of `FFmpeg`'s order it holds. Measured once per key ({@link measurePlaneOrder}) and
63
- * kept; resolves `null` when there is nothing to measure (no key, or no fixture for it) or the
64
- * measurement fails, and the decoder's order is then taken as `FFmpeg`'s. Never rejects.
48
+ * Decoder plane order for streams with this key, measured once and cached. Resolves `null` (use
49
+ * `FFmpeg`'s order) when there is no key or fixture, or measurement fails. Never rejects.
65
50
  */
66
51
  export declare function decoderPlaneOrder(key: string | null): Promise<readonly number[] | null>;
@@ -1,19 +1,15 @@
1
1
  /**
2
- * The channel order a browser's audio decoder delivers, measured rather than assumed.
2
+ * Measures the channel order a browser's audio decoder delivers.
3
3
  *
4
- * WebCodecs leaves the order of an `AudioData`'s planes to the decoder. The speakers
5
- * `codecSpeakers` reports are in the order `FFmpeg`'s decoder delivers (the order a native host
6
- * decodes in), which Chromium's and Firefox's decoders keep; Safari's AAC decoder delivers the
7
- * bitstream's order instead (C L R for configuration 3), and a decoder that delivers libopus's or
8
- * libvorbis's own order (Vorbis's: L C R) or an AC-3 frame's (L C R) would differ the same way. So
9
- * the order is measured: a short built-in file whose planes each hold a tone of their own is
10
- * decoded through the same decoder a source is, once per kind of stream in each page or worker,
11
- * and each plane's tone says which of `FFmpeg`'s planes it is. A source's blocks are then laid out
12
- * in `FFmpeg`'s order whatever the decoder delivers.
4
+ * WebCodecs leaves `AudioData` plane order to the decoder. `codecSpeakers` assumes `FFmpeg`'s
5
+ * order, which Chromium and Firefox keep, but Safari's AAC decoder delivers bitstream order (C L R
6
+ * for configuration 3), and Vorbis or AC-3 native order would differ the same way. A built-in file
7
+ * with a distinct tone per plane is decoded once per stream kind, and the tones map each decoded
8
+ * plane back to `FFmpeg`'s order.
13
9
  */
14
10
  import { ALL_FORMATS, AudioSampleSink, BufferSource, Input } from "mediabunny";
15
11
  import { ADTS_CONFIGURATIONS, aacChannelConfiguration, aacProgramConfigElements, ac3Speakers, opusMappingFamily, } from "./audio-layout.js";
16
- /** Each codec's fixtures, loaded when a stream of it is first measured. */
12
+ /** Fixtures per codec, loaded on first use. */
17
13
  const FIXTURES = {
18
14
  aac: () => import("./generated/aac-order-fixtures.js"),
19
15
  opus: () => import("./generated/opus-order-fixtures.js"),
@@ -21,25 +17,21 @@ const FIXTURES = {
21
17
  ac3: () => import("./generated/ac3-order-fixtures.js"),
22
18
  eac3: () => import("./generated/eac3-order-fixtures.js"),
23
19
  };
24
- /** How many samples of each plane are read. Each fixture tone sits on a bin of it at 48 kHz. */
20
+ /** Samples analyzed per plane. Each fixture tone sits on a bin of this length at 48 kHz. */
25
21
  const ANALYSIS_FRAMES = 1_024;
26
- /** How many times the next tone's power a plane's loudest tone must have to name the plane. */
22
+ /** Power ratio the loudest tone needs over the next to identify a plane. */
27
23
  const TONE_DOMINANCE = 10;
28
24
  /**
29
- * What decides the order `codec`'s decoder delivers a stream's planes in, as a fixture key, or
30
- * `null` for a stream of one or two channels, which every decoder delivers in one order, and for
31
- * a codec whose decoders deliver one order (`FFmpeg` keeps FLAC's, PCM's and an unspecified
32
- * layout's), or that no browser path decodes:
25
+ * Fixture key for the stream property that decides decoder plane order, or `null` when order
26
+ * cannot vary (one or two channels, or codecs with a single order such as FLAC and PCM):
33
27
  *
34
- * - AAC: the channel configuration (`aac:6`), the ADTS header's for a stream without a
35
- * description (`aac:adts:6`), or the elements of a program config element (`aac:pce:SF CF CB LL`,
36
- * {@link aacProgramConfigElements});
37
- * - Opus mapping family 1: the channel count (`opus:1:6`);
38
- * - Vorbis: the channel count (`vorbis:6`);
39
- * - AC-3 and E-AC-3: the speakers the first packet's frame header declares
40
- * (`ac3:FL FR FC LFE SL SR`).
28
+ * - AAC: channel configuration (`aac:6`), ADTS configuration without a description
29
+ * (`aac:adts:6`), or program config elements (`aac:pce:SF CF CB LL`);
30
+ * - Opus mapping family 1: channel count (`opus:1:6`);
31
+ * - Vorbis: channel count (`vorbis:6`);
32
+ * - AC-3 and E-AC-3: speakers in the first frame header (`ac3:FL FR FC LFE SL SR`).
41
33
  *
42
- * A key without a fixture is not measured, and its decoder's order is taken as `FFmpeg`'s.
34
+ * Keys without a fixture are assumed to decode in `FFmpeg`'s order.
43
35
  */
44
36
  export function decoderOrderKey(codec, description, channels, packet = null) {
45
37
  if (channels <= 2)
@@ -69,7 +61,7 @@ export function decoderOrderKey(codec, description, channels, packet = null) {
69
61
  return null;
70
62
  }
71
63
  }
72
- /** The fixture that measures streams keyed `key` ({@link decoderOrderKey}), or `null`. */
64
+ /** Fixture for a {@link decoderOrderKey} key, or `null`. */
73
65
  export async function decoderOrderFixture(key) {
74
66
  const load = FIXTURES[key.slice(0, key.indexOf(":"))];
75
67
  if (load === undefined)
@@ -88,13 +80,12 @@ function tonePower(samples, frequency, sampleRate) {
88
80
  return (previous * previous + before * before - coefficient * previous * before);
89
81
  }
90
82
  /**
91
- * For each decoded plane, the plane of `FFmpeg`'s order it holds: the plane whose tone it holds
92
- * well above every other. `null` unless that names every plane once, or when a plane is too short
93
- * to read.
83
+ * Maps each decoded plane to its index in `FFmpeg`'s order by its dominant tone. Returns `null`
84
+ * unless every plane is identified exactly once.
94
85
  *
95
- * @param planes A fixture's decoded planes, in the decoder's order.
96
- * @param tones Each plane's tone in `FFmpeg`'s order.
97
- * @param start The sample the tones are read from.
86
+ * @param planes Decoded fixture planes, in the decoder's order.
87
+ * @param tones Tone per plane in `FFmpeg`'s order.
88
+ * @param start First sample analyzed.
98
89
  */
99
90
  export function planeOrderOfTones(planes, tones, sampleRate, start) {
100
91
  if (planes.length !== tones.length)
@@ -113,10 +104,7 @@ export function planeOrderOfTones(planes, tones, sampleRate, start) {
113
104
  }
114
105
  return new Set(order).size === order.length ? order : null;
115
106
  }
116
- /**
117
- * The plane order `decode` delivers `fixture` in ({@link planeOrderOfTones}), or `null` when it
118
- * cannot be measured: the decode fails, or its planes do not each hold one tone.
119
- */
107
+ /** Plane order of `fixture` as `decode` delivers it, or `null` when it cannot be measured. */
120
108
  export async function measurePlaneOrder(fixture, decode) {
121
109
  let decoded;
122
110
  try {
@@ -134,7 +122,7 @@ function base64Bytes(text) {
134
122
  bytes[index] = binary.charCodeAt(index);
135
123
  return bytes;
136
124
  }
137
- /** Decodes `file` with mediabunny, through the decoder a source of the same codec gets. */
125
+ /** Decodes through the same mediabunny path a source of this codec uses. */
138
126
  async function decodeWithMediabunny(file) {
139
127
  const input = new Input({
140
128
  source: new BufferSource(file),
@@ -179,13 +167,11 @@ async function decodeWithMediabunny(file) {
179
167
  input.dispose();
180
168
  }
181
169
  }
182
- /** Measured orders by fixture key; a measurement that failed stays `null`. */
170
+ /** Cached orders by fixture key; failed measurements cache `null`. */
183
171
  const measured = new Map();
184
172
  /**
185
- * For each plane mediabunny's decoder delivers for streams keyed `key` ({@link decoderOrderKey}),
186
- * the plane of `FFmpeg`'s order it holds. Measured once per key ({@link measurePlaneOrder}) and
187
- * kept; resolves `null` when there is nothing to measure (no key, or no fixture for it) or the
188
- * measurement fails, and the decoder's order is then taken as `FFmpeg`'s. Never rejects.
173
+ * Decoder plane order for streams with this key, measured once and cached. Resolves `null` (use
174
+ * `FFmpeg`'s order) when there is no key or fixture, or measurement fails. Never rejects.
189
175
  */
190
176
  export function decoderPlaneOrder(key) {
191
177
  if (key === null)