alpha2 0.4.5 → 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 +109 -173
  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 +98 -157
  53. package/dist/frame-supply.js +191 -162
  54. package/dist/generated/project-schema.d.ts +742 -464
  55. package/dist/generated/project-schema.js +63 -2
  56. package/dist/generated/project-shape.js +663 -118
  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 +88 -62
  62. package/dist/hdr-frames.js +123 -46
  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 +55 -55
  70. package/dist/layout.js +37 -36
  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 +173 -237
  76. package/dist/mediabunny.js +943 -518
  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 +83 -110
  84. package/dist/project.js +421 -447
  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 +106 -63
  96. package/dist/text.js +44 -69
  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 -92
  104. package/dist/worker.js +239 -144
  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 +487 -543
  111. package/wasm/alpha2_wasm.js +669 -572
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
@@ -1,6 +1,4 @@
1
- /**
2
- * `FFmpeg`'s channel names, by channel number (`enum AVChannel`); a number without one is `UNK`.
3
- */
1
+ /** `FFmpeg` channel names by `enum AVChannel` number; unnamed numbers are `UNK`. */
4
2
  const SPEAKER_BY_CHANNEL = new Map([
5
3
  [0, "FL"],
6
4
  [1, "FR"],
@@ -39,7 +37,7 @@ const SPEAKER_BY_CHANNEL = new Map([
39
37
  [61, "BIL"],
40
38
  [62, "BIR"],
41
39
  ]);
42
- /** Every name a speaker list may hold: the named `FFmpeg` channels plus `UNK`. */
40
+ /** Valid speaker names: the named `FFmpeg` channels plus `UNK`. */
43
41
  export const AUDIO_SPEAKERS = new Set([
44
42
  ...SPEAKER_BY_CHANNEL.values(),
45
43
  "UNK",
@@ -47,10 +45,7 @@ export const AUDIO_SPEAKERS = new Set([
47
45
  function speakerOfChannel(channel) {
48
46
  return SPEAKER_BY_CHANNEL.get(channel) ?? "UNK";
49
47
  }
50
- /**
51
- * The speakers of a native-order channel mask, in bit order, as `FFmpeg`'s
52
- * `av_channel_layout_from_mask` lists them. A set bit with no named channel is `UNK`.
53
- */
48
+ /** Speakers of a native-order channel mask in bit order (`av_channel_layout_from_mask`). */
54
49
  export function speakersOfMask(mask) {
55
50
  const speakers = [];
56
51
  for (let bit = 0; bit < 64; bit += 1)
@@ -58,19 +53,41 @@ export function speakersOfMask(mask) {
58
53
  speakers.push(speakerOfChannel(bit));
59
54
  return speakers;
60
55
  }
61
- const list = (names) => names.split(" ");
56
+ const CHANNEL_OF_SPEAKER = new Map([...SPEAKER_BY_CHANNEL].map(([channel, speaker]) => [speaker, channel]));
62
57
  /**
63
- * A layout, or `null` when it names no speaker, as `SpeakerLayout::declared_or_default` reads it.
58
+ * `speakers` with an LFE inserted in native order, plus its plane index, for decoders that add a
59
+ * silent LFE (a WebCodecs decoder does for E-AC-3 5.0). `null` when there is already an LFE or the
60
+ * list is not native-order named speakers.
64
61
  */
62
+ export function speakersWithLfe(speakers) {
63
+ const channels = speakers.map((speaker) => CHANNEL_OF_SPEAKER.get(speaker));
64
+ const lfe = CHANNEL_OF_SPEAKER.get("LFE");
65
+ if (channels.some((channel, index) => channel === undefined ||
66
+ channel === lfe ||
67
+ (index > 0 && channel <= channels[index - 1])))
68
+ return null;
69
+ const at = channels.findIndex((channel) => channel > lfe);
70
+ const lfePlane = at === -1 ? speakers.length : at;
71
+ return {
72
+ speakers: [
73
+ ...speakers.slice(0, lfePlane),
74
+ "LFE",
75
+ ...speakers.slice(lfePlane),
76
+ ],
77
+ lfePlane,
78
+ };
79
+ }
80
+ const list = (names) => names.split(" ");
81
+ /** `null` when the layout names no speaker, as `SpeakerLayout::declared_or_default` reads it. */
65
82
  function declared(speakers) {
66
83
  if (speakers === null || speakers.every((speaker) => speaker === "UNK"))
67
84
  return null;
68
85
  return speakers;
69
86
  }
70
87
  /**
71
- * The speakers of a WAVE `fmt ` chunk payload's `WAVE_FORMAT_EXTENSIBLE` channel mask, as
72
- * `FFmpeg`'s RIFF demuxer reads it: a mask whose bit count is not `channels` says nothing.
73
- * `null` for any other WAVE format, a payload shorter than 24 bytes, or a mask naming no speaker.
88
+ * Speakers of a `WAVE_FORMAT_EXTENSIBLE` channel mask in a `fmt ` chunk payload, as `FFmpeg`'s RIFF
89
+ * demuxer reads it. `null` for other formats, short payloads, or a mask whose bit count is not
90
+ * `channels`.
74
91
  */
75
92
  export function wavSpeakers(fmt, channels) {
76
93
  if (fmt.length < 24)
@@ -109,9 +126,8 @@ const MOV_LABELS = {
109
126
  LFE1: "LFE",
110
127
  };
111
128
  /**
112
- * QuickTime channel layout tags (`kAudioChannelLayoutTag_*`, `mov_chan.h`) and the channels
113
- * `mov_chan.c` lays each out as. A label it has no channel for (ambisonic W X Y Z, Csd, HI, VI,
114
- * Haptic) is unnamed.
129
+ * QuickTime channel layout tags (`mov_chan.h`) and their channels per `mov_chan.c`. Labels without
130
+ * an `FFmpeg` channel (ambisonics, Csd, HI, VI, Haptic) are unnamed.
115
131
  */
116
132
  const MOV_LAYOUT_TAGS = new Map([
117
133
  [100, "C"],
@@ -200,17 +216,16 @@ const MOV_LAYOUT_TAGS = new Map([
200
216
  [181, "Lc C Rc L R Ls Cs Rs LFE"],
201
217
  [182, "C L R Ls Rs LFE Cs"],
202
218
  ]);
203
- /** A QuickTime channel label's channel (`mov_get_channel_id`). */
219
+ /** `mov_get_channel_id`. */
204
220
  function movLabelSpeaker(label) {
205
221
  if (label >= 1 && label <= 18)
206
222
  return speakerOfChannel(label - 1);
207
223
  return ({ 35: "WL", 36: "WR", 37: "LFE2", 38: "DL", 39: "DR" }[label] ?? "UNK");
208
224
  }
209
225
  /**
210
- * The speakers a QuickTime `chan` box's payload (after its version and flags) declares, as
211
- * `FFmpeg`'s `ff_mov_read_chan` reads it: channel descriptions, a channel bitmap whose bit count
212
- * is the channel count, or a layout tag of that count that `mov_chan.c` knows. `null` for anything
213
- * else, including a truncated payload.
226
+ * Speakers a QuickTime `chan` payload (after version and flags) declares, per `ff_mov_read_chan`:
227
+ * channel descriptions, a bitmap, or a known layout tag, each matching `channels`. `null`
228
+ * otherwise, including for truncated payloads.
214
229
  */
215
230
  export function movChanSpeakers(chan, channels) {
216
231
  if (chan.length < 12)
@@ -243,15 +258,12 @@ export function movChanSpeakers(chan, channels) {
243
258
  return declared(labels.split(" ").map((label) => MOV_LABELS[label] ?? "UNK"));
244
259
  }
245
260
  const CONTAINERS = new Set(["moov", "trak", "mdia", "minf", "stbl", "wave"]);
246
- /** The largest `moov` box read whole to find a `chan`; a larger one declares none. */
261
+ /** Largest `moov` box read to find a `chan`; larger ones are treated as declaring none. */
247
262
  const MAX_MOOV_BYTES = 64 * 1024 * 1024;
248
263
  function boxType(bytes, at) {
249
264
  return String.fromCharCode(...bytes.subarray(at, at + 4));
250
265
  }
251
- /**
252
- * The boxes inside `bytes[start, end)`: type, payload start and end. Stops at the first malformed
253
- * one.
254
- */
266
+ /** Iterates the boxes in `bytes[start, end)`, stopping at the first malformed one. */
255
267
  function* boxes(bytes, start, end) {
256
268
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
257
269
  let at = start;
@@ -277,9 +289,8 @@ function* boxes(bytes, start, end) {
277
289
  }
278
290
  }
279
291
  /**
280
- * The first channel layout box in a `trak`'s sound sample description, searched where `FFmpeg`
281
- * reads one: a `chan` (its payload after the version and flags) or a version 0 `chnl` (after its
282
- * version and flags; `FFmpeg` ignores any other version).
292
+ * First `chan` or version 0 `chnl` box in a `trak`'s sound sample description, where `FFmpeg` looks
293
+ * for one. Payloads start after version and flags.
283
294
  */
284
295
  function findLayoutBox(bytes, start, end) {
285
296
  for (const box of boxes(bytes, start, end)) {
@@ -301,13 +312,12 @@ function findLayoutBox(bytes, start, end) {
301
312
  return found;
302
313
  }
303
314
  if (box.type === "stsd") {
304
- // Full box, then the entry count; each entry is a sample description whose extensions
305
- // follow its fixed fields.
315
+ // Skip the full-box header and entry count.
306
316
  for (const entry of boxes(bytes, box.payload + 8, box.end)) {
307
317
  const view = new DataView(bytes.buffer, bytes.byteOffset);
308
318
  const version = view.getUint16(entry.payload + 8);
309
- // QuickTime sound descriptions grow by 16 (version 1) or 36 (version 2) bytes; an ISO
310
- // entry of version 1 does not, so both offsets are tried.
319
+ // QuickTime sound descriptions grow by 16 (v1) or 36 (v2) bytes; ISO v1 does not, so try
320
+ // both offsets.
311
321
  const offsets = version === 2 ? [56] : version === 1 ? [36, 20] : [20];
312
322
  for (const offset of offsets) {
313
323
  const found = findLayoutBox(bytes, entry.payload + 8 + offset, entry.end);
@@ -319,7 +329,7 @@ function findLayoutBox(bytes, start, end) {
319
329
  }
320
330
  return null;
321
331
  }
322
- /** The track ID of a `trak` (`tkhd`), or `null`. */
332
+ /** Track ID from a `trak`'s `tkhd`, or `null`. */
323
333
  function trackId(bytes, trak) {
324
334
  for (const box of boxes(bytes, trak.payload, trak.end)) {
325
335
  if (box.type !== "tkhd")
@@ -330,7 +340,7 @@ function trackId(bytes, trak) {
330
340
  }
331
341
  return null;
332
342
  }
333
- /** The ASCII text of `length` bytes at `offset`, or `null` when the source is shorter. */
343
+ /** ASCII text of `length` bytes at `offset`, or `null` when the source is shorter. */
334
344
  async function readTag(read, offset, length) {
335
345
  const bytes = await read(offset, length);
336
346
  return bytes.length < length ? null : boxType(bytes, 0).slice(0, length);
@@ -391,9 +401,9 @@ async function movLayoutBox(read, size, track) {
391
401
  }
392
402
  return null;
393
403
  }
394
- /** ISO/IEC 23001-8 speaker positions (table 8), as `mov_chan.c` maps them; others are unnamed. */
404
+ /** ISO/IEC 23001-8 speaker positions (table 8), mapped as in `mov_chan.c`. */
395
405
  const ISO_POSITIONS = list("FL FR FC LFE SL SR FLC FRC BL BR BC SDL SDR SSL SSR WL WR TFL TFR TFC TBL TBR TBC TSL TSR TC LFE2 BFL BFR BFC TTL TTR");
396
- /** ISO/IEC 23001-8 channel configurations, as `mov_chan.c` lays each out. */
406
+ /** ISO/IEC 23001-8 channel configurations, laid out as in `mov_chan.c`. */
397
407
  const ISO_CONFIGURATIONS = {
398
408
  1: "FC",
399
409
  2: "FL FR",
@@ -410,11 +420,9 @@ const ISO_CONFIGURATIONS = {
410
420
  14: "FC FL FR SL SR LFE TFL TFR",
411
421
  };
412
422
  /**
413
- * The speakers an ISO/IEC 23001-8 `chnl` box's payload (after its version and flags) declares, as
414
- * `FFmpeg`'s `ff_mov_read_chnl` reads it: a speaker position per channel, or a channel
415
- * configuration of the channel count less its omitted channels. `null` for a box that carries no
416
- * channels, a configuration `FFmpeg` does not know or of another count, a truncated payload, or
417
- * one naming no speaker.
423
+ * Speakers an ISO `chnl` payload (after version and flags) declares, per `ff_mov_read_chnl`:
424
+ * explicit positions, or a channel configuration minus omitted channels. `null` for no channels,
425
+ * an unknown or mismatched configuration, a truncated payload, or no named speaker.
418
426
  */
419
427
  export function chnlSpeakers(chnl, channels) {
420
428
  if (chnl.length < 2 || !(chnl[0] & 1))
@@ -427,7 +435,7 @@ export function chnlSpeakers(chnl, channels) {
427
435
  const position = chnl[at];
428
436
  if (position === undefined)
429
437
  return null;
430
- // An explicit position carries its azimuth and elevation, which name no speaker.
438
+ // Explicit position: skip azimuth and elevation.
431
439
  at += position === 126 ? 4 : 1;
432
440
  speakers.push(ISO_POSITIONS[position] ?? "UNK");
433
441
  }
@@ -448,7 +456,6 @@ export function chnlSpeakers(chnl, channels) {
448
456
  return null;
449
457
  return declared(all.filter((_, channel) => !((omitted >> BigInt(channel)) & 1n)));
450
458
  }
451
- /** The channel layout a QuickTime or ISO sample description declares, or `null`. */
452
459
  async function movSpeakers(read, size, track, channels) {
453
460
  const box = await movLayoutBox(read, size, track);
454
461
  if (box === null)
@@ -457,7 +464,7 @@ async function movSpeakers(read, size, track, channels) {
457
464
  ? movChanSpeakers(box.payload, channels)
458
465
  : chnlSpeakers(box.payload, channels);
459
466
  }
460
- /** A big-endian bit reader. Reading past the end throws a `RangeError`. */
467
+ /** Big-endian bit reader; reading past the end throws `RangeError`. */
461
468
  class Bits {
462
469
  #bit;
463
470
  #bytes;
@@ -496,21 +503,18 @@ class Bits {
496
503
  return new Bits(this.#bytes, this.#bit);
497
504
  }
498
505
  }
499
- /** `FFmpeg`'s native-order channel bits (`AV_CH_*`) by speaker name. */
506
+ /** `AV_CH_*` bits by speaker name. */
500
507
  const CHANNEL_BIT = new Map([...SPEAKER_BY_CHANNEL].map(([channel, speaker]) => [
501
508
  speaker,
502
509
  1n << BigInt(channel),
503
510
  ]));
504
511
  const bitsOf = (names) => list(names).reduce((mask, speaker) => mask | CHANNEL_BIT.get(speaker), 0n);
505
- /**
506
- * The speakers of a native-order mask of `channels` bits, or `null` for a mask of another count
507
- * (`FFmpeg` would deliver planes the mask does not name).
508
- */
512
+ /** Speakers of a native-order mask, or `null` when its bit count is not `channels`. */
509
513
  function maskSpeakers(mask, channels) {
510
514
  const speakers = speakersOfMask(mask);
511
515
  return speakers.length === channels ? declared(speakers) : null;
512
516
  }
513
- // AAC syntax elements and the positions a program config element gives them (`aacdec.h`).
517
+ // AAC syntax elements and program config element positions (`aacdec.h`).
514
518
  const SCE = 0;
515
519
  const CPE = 1;
516
520
  const CCE = 2;
@@ -522,10 +526,7 @@ const LFE = 4;
522
526
  const CC = 5;
523
527
  const AAC_NONE = -1;
524
528
  const AAC_UNUSED = 0x200;
525
- /**
526
- * The channels `FFmpeg`'s AAC decoder assigns elements at each position, by height layer, then
527
- * position (front, side, back, LFE): `ff_aac_channel_map`.
528
- */
529
+ /** `ff_aac_channel_map`: channels by height layer, then position (front, side, back, LFE). */
529
530
  const AAC_CHANNEL_MAP = [
530
531
  [
531
532
  [2, 6, 7, 0, 1, AAC_NONE],
@@ -551,10 +552,9 @@ const elements = (spec) => spec.split(" ").map((element) => ({
551
552
  position: { F: FRONT, S: SIDE, B: BACK, L: LFE }[element[1]],
552
553
  }));
553
554
  /**
554
- * The elements of each AAC channel configuration, as `FFmpeg` lays them out
555
- * (`ff_aac_channel_layout_map`): an element's type (SCE, CPE, LFE) then its position (front, side,
556
- * back, LFE). Configuration 7's second front pair is a back pair: `FFmpeg` decodes it as 7.1, as
557
- * encoders write it, rather than the specification's 7.1(wide), unless asked to be strict.
555
+ * `ff_aac_channel_layout_map`: elements of each AAC channel configuration. Configuration 7's
556
+ * second front pair is a back pair, since `FFmpeg` decodes it as 7.1 (as encoders write it) rather
557
+ * than the specification's 7.1(wide).
558
558
  */
559
559
  const AAC_CONFIGURATION_ELEMENTS = {
560
560
  1: elements("SF"),
@@ -569,11 +569,11 @@ const AAC_CONFIGURATION_ELEMENTS = {
569
569
  13: elements("SF CF CF CB CB SB LL LL SF CF CS SS CB SB SF CF"),
570
570
  14: elements("SF CF CB LL CF"),
571
571
  };
572
- /** The channel count `FFmpeg` gives each channel configuration (`ff_mpeg4audio_channels`). */
572
+ /** `ff_mpeg4audio_channels`. */
573
573
  const AAC_CONFIGURATION_CHANNELS = [
574
574
  0, 1, 2, 3, 4, 5, 6, 8, 0, 0, 0, 7, 8, 24, 8,
575
575
  ];
576
- /** The sampling frequency of each index (`ff_mpeg4audio_sample_rates`). */
576
+ /** `ff_mpeg4audio_sample_rates`. */
577
577
  const AAC_SAMPLE_RATES = [
578
578
  96_000, 88_200, 64_000, 48_000, 44_100, 32_000, 24_000, 22_050, 16_000,
579
579
  12_000, 11_025, 8_000, 7_350,
@@ -581,9 +581,9 @@ const AAC_SAMPLE_RATES = [
581
581
  const AOT_AAC_LC = 2;
582
582
  const AOT_SBR = 5;
583
583
  const AOT_PS = 29;
584
- /** Object types whose `GASpecificConfig` `FFmpeg` reads, a program config element included. */
584
+ /** Object types whose `GASpecificConfig` (including a PCE) `FFmpeg` reads. */
585
585
  const AAC_GA_OBJECT_TYPES = new Set([1, 2, 3, 4, 17, 23]);
586
- /** `count_paired_channels`: the channels of the elements at `position` from `current`. */
586
+ /** `count_paired_channels`. */
587
587
  function countPairedChannels(map, position, current) {
588
588
  let channels = 0;
589
589
  let firstCpe = false;
@@ -611,10 +611,7 @@ function countPairedChannels(map, position, current) {
611
611
  return -1;
612
612
  return channels;
613
613
  }
614
- /**
615
- * `assign_channels`: the channels of the elements at `position` in `layer`, from `state.current`,
616
- * added to `state.mask`. `false` where `FFmpeg` gives up on the layout.
617
- */
614
+ /** `assign_channels`; returns `false` where `FFmpeg` gives up on the layout. */
618
615
  function assignChannels(map, layer, position, state) {
619
616
  const channelsOf = AAC_CHANNEL_MAP[layer][position - 1];
620
617
  let channels = countPairedChannels(map, position, state.current);
@@ -662,9 +659,8 @@ function assignChannels(map, layer, position, state) {
662
659
  return channels === 0;
663
660
  }
664
661
  /**
665
- * The channel mask `FFmpeg`'s AAC decoder sets for these elements (`sniff_channel_order`), or `0n`
666
- * when it finds none and leaves the layout unspecified. `FFmpeg` delivers its planes in the mask's
667
- * native order.
662
+ * Channel mask from `sniff_channel_order`, or `0n` when the layout stays unspecified. Planes are
663
+ * delivered in the mask's native order.
668
664
  */
669
665
  function aacElementsMask(map, ps) {
670
666
  const state = { current: 0, mask: 0n };
@@ -682,8 +678,8 @@ function aacElementsMask(map, ps) {
682
678
  return state.mask;
683
679
  }
684
680
  /**
685
- * A program config element's elements (`decode_pce`), from just after its element instance tag,
686
- * or `null` when it is truncated. `alignment` is the bit the comment's byte alignment counts from.
681
+ * `decode_pce`, starting after the element instance tag; `null` when truncated. `alignment` is the
682
+ * bit the comment's byte alignment counts from.
687
683
  */
688
684
  function programConfigElements(bits, alignment) {
689
685
  bits.skip(2 + 4); // object type, sampling frequency index
@@ -732,9 +728,8 @@ function aacObjectType(bits) {
732
728
  return type === 31 ? 32 + bits.read(6) : type;
733
729
  }
734
730
  /**
735
- * The elements an `AudioSpecificConfig` declares, its channel configuration's or its program
736
- * config element's, as `FFmpeg` reads them, and whether parametric stereo makes a lone SCE two
737
- * channels. `undefined` when `FFmpeg` would not decode the config.
731
+ * Elements an `AudioSpecificConfig` declares (from its channel configuration or PCE), plus whether
732
+ * parametric stereo applies. `undefined` when `FFmpeg` would not decode the config.
738
733
  */
739
734
  function aacConfigElements(config) {
740
735
  try {
@@ -763,7 +758,7 @@ function aacConfigElements(config) {
763
758
  bits.skip(4);
764
759
  }
765
760
  if (!explicitSbr) {
766
- // A backward-compatible SBR or PS signal after the specific config.
761
+ // Backward-compatible SBR or PS signalling after the specific config.
767
762
  const sync = bits.copy();
768
763
  while (sync.left > 15) {
769
764
  if (sync.show(11) !== 0x2b7) {
@@ -828,10 +823,8 @@ function aacConfigElements(config) {
828
823
  }
829
824
  }
830
825
  /**
831
- * The speakers `FFmpeg`'s AAC decoder lays an `AudioSpecificConfig` out as: its channel
832
- * configuration's or program config element's elements, assigned and ordered as
833
- * `ff_aac_output_configure` does. `null` when `FFmpeg` leaves the layout unspecified;
834
- * `undefined` when it would not decode the config at all.
826
+ * Speakers of an `AudioSpecificConfig` as `ff_aac_output_configure` orders them. `null` when the
827
+ * layout stays unspecified; `undefined` when `FFmpeg` would not decode the config.
835
828
  */
836
829
  export function aacSpeakers(config) {
837
830
  const elements = aacConfigElements(config);
@@ -841,10 +834,9 @@ export function aacSpeakers(config) {
841
834
  return mask === 0n ? null : speakersOfMask(mask);
842
835
  }
843
836
  /**
844
- * The output elements a program config element in an `AudioSpecificConfig` declares, in its
845
- * order, each its type then its position: `SF CF CB LL` is a front SCE, a front CPE, a back CPE
846
- * and an LFE (`S`, `C`, `L`; front, side, back, LFE). `null` for a config with a channel
847
- * configuration or one `FFmpeg` would not decode.
837
+ * PCE output elements as type then position letters: `SF CF CB LL` is a front SCE, a front CPE,
838
+ * a back CPE and an LFE. `null` for a config with a channel configuration or one `FFmpeg` would not
839
+ * decode.
848
840
  */
849
841
  export function aacProgramConfigElements(config) {
850
842
  const elements = aacConfigElements(config);
@@ -855,7 +847,7 @@ export function aacProgramConfigElements(config) {
855
847
  .map((element) => ["S", "C", "", "L"][element.type] + " FSBL"[element.position])
856
848
  .join(" ");
857
849
  }
858
- /** The channels of each AC-3 channel mode (`acmod`), as `FFmpeg` lays them out. */
850
+ /** Channels of each AC-3 `acmod`, as `FFmpeg` lays them out. */
859
851
  const AC3_MODE_MASKS = [
860
852
  "FL FR",
861
853
  "FC",
@@ -866,7 +858,7 @@ const AC3_MODE_MASKS = [
866
858
  "FL FR SL SR",
867
859
  "FL FR FC SL SR",
868
860
  ].map(bitsOf);
869
- /** What each bit of an E-AC-3 dependent substream's channel map adds, most significant first. */
861
+ /** Channels each E-AC-3 dependent substream channel map bit adds, most significant first. */
870
862
  const EAC3_CHANNEL_MAP = [
871
863
  "FL",
872
864
  "FC",
@@ -976,9 +968,8 @@ function ac3Header(frame) {
976
968
  }
977
969
  }
978
970
  /**
979
- * The speakers `FFmpeg`'s AC-3 or E-AC-3 decoder lays a packet out as: its first frame's channel
980
- * mode and LFE, and the channels an E-AC-3 dependent frame after it adds by its channel map.
981
- * `undefined` when the packet does not start with a frame `FFmpeg` decodes.
971
+ * Speakers `FFmpeg`'s AC-3 or E-AC-3 decoder produces for a packet, including channels added by an
972
+ * E-AC-3 dependent frame. `undefined` when the packet does not start with a decodable frame.
982
973
  */
983
974
  export function ac3Speakers(packet) {
984
975
  const first = ac3Header(packet);
@@ -997,7 +988,7 @@ export function ac3Speakers(packet) {
997
988
  }
998
989
  return speakersOfMask(mask);
999
990
  }
1000
- /** The speakers of each DTS core audio channel arrangement (`AMODE`) `FFmpeg` decodes. */
991
+ /** Speakers of each DTS core `AMODE` that `FFmpeg` decodes. */
1001
992
  const DTS_MODE_MASKS = [
1002
993
  "FC",
1003
994
  "FL FR",
@@ -1013,13 +1004,11 @@ const DTS_MODE_MASKS = [
1013
1004
  const DTS_CORE_SYNC = 0x7ffe8001;
1014
1005
  const DTS_CORE_SYNC_LE = 0xfe7f0180;
1015
1006
  const DTS_SUBSTREAM_SYNC = 0x64582025;
1016
- /** The core extension types that add channels: XCH and XXCH (X96 adds none). */
1007
+ /** Core extension types that add channels: XCH and XXCH. */
1017
1008
  const DTS_CHANNEL_EXTENSIONS = new Set([0, 6]);
1018
1009
  /**
1019
- * The speakers `FFmpeg`'s DTS decoder lays a packet of a core alone out as: the core's channel
1020
- * arrangement and LFE. `null` when the packet carries more than a core `FFmpeg` would decode
1021
- * (channel extensions, an extension substream, a substream without a core) or is not a 16-bit
1022
- * core; those layouts are not read.
1010
+ * Speakers of a core-only DTS packet. `null` for anything beyond a 16-bit core (channel extensions,
1011
+ * extension substreams, coreless substreams), whose layouts are not read.
1023
1012
  */
1024
1013
  export function dtsSpeakers(packet) {
1025
1014
  if (packet.length < 16)
@@ -1072,10 +1061,7 @@ export function dtsSpeakers(packet) {
1072
1061
  return null;
1073
1062
  }
1074
1063
  }
1075
- /**
1076
- * `strtol(text, NULL, 0)` as a 64-bit two's-complement value: leading space, a sign, then a hex
1077
- * (`0x`), octal (`0`) or decimal number, read up to the first character that is not a digit.
1078
- */
1064
+ /** C `strtol(text, NULL, 0)` as a 64-bit two's-complement value. */
1079
1065
  function strtol(text) {
1080
1066
  const match = /^[\t\n\v\f\r ]*([+-]?)(0[xX](?=[0-9a-fA-F])|0?)([0-9a-fA-F]*)/.exec(text);
1081
1067
  const [, sign, prefix, rest] = match;
@@ -1096,9 +1082,8 @@ function strtol(text) {
1096
1082
  return BigInt.asUintN(64, value);
1097
1083
  }
1098
1084
  /**
1099
- * The channel mask a FLAC `VORBIS_COMMENT` block's first `WAVEFORMATEXTENSIBLE_CHANNEL_MASK`
1100
- * comment declares, as `FFmpeg`'s FLAC and Matroska demuxers read it, or `null` for no comment or
1101
- * a mask `FFmpeg` refuses (zero, or past its first 18 speakers).
1085
+ * Mask from the first `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment in a FLAC `VORBIS_COMMENT` block,
1086
+ * or `null` when absent or refused by `FFmpeg` (zero, or beyond its first 18 speakers).
1102
1087
  */
1103
1088
  function vorbisCommentMask(block) {
1104
1089
  const view = new DataView(block.buffer, block.byteOffset, block.byteLength);
@@ -1128,10 +1113,7 @@ function vorbisCommentMask(block) {
1128
1113
  }
1129
1114
  return null;
1130
1115
  }
1131
- /**
1132
- * The first FLAC `VORBIS_COMMENT` block among the metadata blocks from `offset`, read through
1133
- * `read`, or `null`.
1134
- */
1116
+ /** First FLAC `VORBIS_COMMENT` block among the metadata blocks from `offset`, or `null`. */
1135
1117
  async function flacVorbisComment(read, offset) {
1136
1118
  let at = offset;
1137
1119
  for (let block = 0; block < 128; block += 1) {
@@ -1148,12 +1130,11 @@ async function flacVorbisComment(read, offset) {
1148
1130
  return null;
1149
1131
  }
1150
1132
  /**
1151
- * The channel mask a FLAC track declares in a `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment where
1152
- * `FFmpeg` reads one: a FLAC file's metadata blocks, or Matroska codec private data whose first
1153
- * block is the stream info (`description`). `FFmpeg`'s MP4 and Ogg demuxers read none.
1133
+ * FLAC channel-mask comment from a FLAC file's metadata or Matroska codec private data
1134
+ * (`description`). `FFmpeg`'s MP4 and Ogg demuxers do not read it.
1154
1135
  */
1155
1136
  async function flacMask(read, description) {
1156
- // An ID3v2 tag before the stream is skipped, as `FFmpeg` skips it.
1137
+ // Skip a leading ID3v2 tag, as `FFmpeg` does.
1157
1138
  let start = 0;
1158
1139
  const id3 = await read(0, 10);
1159
1140
  if (id3.length === 10 && boxType(id3, 0).startsWith("ID3"))
@@ -1178,7 +1159,7 @@ async function flacMask(read, description) {
1178
1159
  const block = await flacVorbisComment((offset, length) => Promise.resolve(description.subarray(offset, offset + length)), 42);
1179
1160
  return block === null ? null : vorbisCommentMask(block);
1180
1161
  }
1181
- /** Vorbis's channel orders, and Opus's mapping family 1, as `FFmpeg` reorders them. */
1162
+ /** Vorbis and Opus mapping family 1 channel orders, as `FFmpeg` reorders them. */
1182
1163
  const VORBIS_LAYOUTS = [
1183
1164
  "FC",
1184
1165
  "FL FR",
@@ -1200,7 +1181,7 @@ const FLAC_LAYOUTS = [
1200
1181
  "FL FR FC LFE BC SL SR",
1201
1182
  "FL FR FC LFE BL BR SL SR",
1202
1183
  ];
1203
- /** The AAC channel configuration of each ADTS channel count (ADTS carries 1 to 7). */
1184
+ /** AAC channel configuration for each ADTS channel count (configurations 1 to 7). */
1204
1185
  export const ADTS_CONFIGURATIONS = {
1205
1186
  1: 1,
1206
1187
  2: 2,
@@ -1210,10 +1191,7 @@ export const ADTS_CONFIGURATIONS = {
1210
1191
  6: 6,
1211
1192
  8: 7,
1212
1193
  };
1213
- /**
1214
- * The AAC channel configuration of an `AudioSpecificConfig`. `null` for a truncated config or for
1215
- * configuration 0, which defers to a program config element.
1216
- */
1194
+ /** AAC channel configuration, or `null` when truncated or 0 (defers to a PCE). */
1217
1195
  export function aacChannelConfiguration(config) {
1218
1196
  try {
1219
1197
  const bits = new Bits(config);
@@ -1227,7 +1205,7 @@ export function aacChannelConfiguration(config) {
1227
1205
  return null;
1228
1206
  }
1229
1207
  }
1230
- /** The channel mapping family of an `OpusHead`, 0 when there is none. */
1208
+ /** `OpusHead` channel mapping family; 0 without a head. */
1231
1209
  export function opusMappingFamily(description) {
1232
1210
  return description !== null &&
1233
1211
  description.length >= 19 &&
@@ -1236,15 +1214,14 @@ export function opusMappingFamily(description) {
1236
1214
  : 0;
1237
1215
  }
1238
1216
  /**
1239
- * The layout a codec's decoder sets, where the decoder sets one: `undefined` when the codec leaves
1240
- * the layout to the container, `null` when the decoder leaves it unspecified.
1217
+ * Layout the codec's decoder sets. `undefined` when the container decides, `null` when the decoder
1218
+ * leaves it unspecified.
1241
1219
  */
1242
1220
  function decoderLayout(codec, description, channels, packet) {
1243
1221
  const fixed = (layouts) => layouts[channels - 1] === undefined ? null : list(layouts[channels - 1]);
1244
1222
  switch (codec) {
1245
1223
  case "aac": {
1246
- // Without an `AudioSpecificConfig` the stream is ADTS, whose header names configurations 1
1247
- // to 7 by their distinct channel counts.
1224
+ // No `AudioSpecificConfig` means ADTS, whose configurations 1 to 7 have distinct counts.
1248
1225
  const configuration = ADTS_CONFIGURATIONS[channels];
1249
1226
  const config = description ??
1250
1227
  (configuration === undefined
@@ -1280,24 +1257,16 @@ function decoderLayout(codec, description, channels, packet) {
1280
1257
  return channels <= 2 ? fixed(VORBIS_LAYOUTS) : undefined;
1281
1258
  }
1282
1259
  /**
1283
- * The speakers a codec's own headers declare, in the order `FFmpeg`'s decoder delivers its planes
1284
- * (the native order of the layout it sets): an AAC channel configuration or program config
1285
- * element (an ADTS stream's configuration, without a description), an Opus mapping family 0 or 1
1286
- * head, Vorbis's and FLAC's fixed orders, an AC-3 or E-AC-3 frame's channel mode, LFE and
1287
- * dependent channel map, a DTS core's channel arrangement, and mono or stereo for any codec.
1288
- * `null` when the codec says nothing the decoder would read, or the decoder would leave the layout
1289
- * unspecified.
1260
+ * Speakers a codec's own headers declare, in `FFmpeg`'s decoder plane order. Covers AAC, Opus
1261
+ * mapping families 0 and 1, Vorbis and FLAC fixed orders, AC-3/E-AC-3, DTS cores, and mono or
1262
+ * stereo for any codec. `null` when the decoder would leave the layout unspecified.
1290
1263
  *
1291
- * @param codec mediabunny's codec name (`aac`, `opus`, `vorbis`, `flac`, `ac3`, `eac3`, `dts`,
1292
- * ...).
1293
- * @param description The decoder configuration's description (`AudioSpecificConfig`,
1294
- * `OpusHead`), when the track has one.
1295
- * @param packet The track's first packet, which an AC-3, E-AC-3 or DTS decoder reads its layout
1296
- * from.
1264
+ * Other decoders may deliver another order (Safari's AAC keeps bitstream order);
1265
+ * `decoder-order.ts` measures and corrects for that.
1297
1266
  *
1298
- * Chromium's decoders, which are `FFmpeg`'s, deliver this order. WebCodecs leaves the order to the
1299
- * decoder, and Safari's AAC decoder keeps the bitstream's; the mediabunny adapter measures the
1300
- * order a decoder delivers and puts its planes back in this one (`decoder-order.ts`).
1267
+ * @param codec mediabunny's codec name (`aac`, `opus`, `vorbis`, `flac`, `ac3`, `eac3`, `dts`).
1268
+ * @param description The decoder configuration description (`AudioSpecificConfig`, `OpusHead`).
1269
+ * @param packet The first packet, from which AC-3, E-AC-3 and DTS layouts are read.
1301
1270
  */
1302
1271
  export function codecSpeakers(codec, description, channels, packet = null) {
1303
1272
  const speakers = decoderLayout(codec, description, channels, packet);
@@ -1308,22 +1277,19 @@ export function codecSpeakers(codec, description, channels, packet = null) {
1308
1277
  : null;
1309
1278
  }
1310
1279
  /**
1311
- * The speakers a source's primary audio track declares, or `null` when it declares none.
1280
+ * Speakers the source's primary audio track declares, or `null`.
1312
1281
  *
1313
- * A codec whose decoder sets a layout is laid out as `FFmpeg`'s decoder lays it out
1314
- * ({@link codecSpeakers}), whatever the container says. FLAC's decoder keeps a layout of its
1315
- * channel count from the demuxer: a `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment in a FLAC file or
1316
- * Matroska, a QuickTime `chan` or ISO `chnl` box, and FLAC's own order otherwise. PCM, and any
1317
- * other codec, is laid out by its container: a WAVE channel mask, a QuickTime `chan` box, an ISO
1318
- * `chnl` box.
1282
+ * Codecs whose decoder sets a layout use {@link codecSpeakers} regardless of the container. FLAC
1283
+ * takes a matching container layout (channel-mask comment, `chan` or `chnl`), else its own order.
1284
+ * PCM and other codecs use the container's WAVE mask, `chan` or `chnl` box.
1319
1285
  *
1320
1286
  * @param read Reads the source file's bytes.
1321
1287
  * @param size The source file's size in bytes.
1322
- * @param track The audio track; `id` picks the matching `trak` in a QuickTime file, and the first
1323
- * track with a `chan` or `chnl` box is used when none matches.
1288
+ * @param track `id` selects the QuickTime `trak`; without a match, the first track with a layout
1289
+ * box is used.
1324
1290
  * @param description The track's decoder configuration description, if any.
1325
- * @param firstPacket Reads the track's first packet, for a codec that declares its layout there
1326
- * (AC-3, E-AC-3, DTS); resolves `null` when there is none.
1291
+ * @param firstPacket Reads the first packet, for AC-3, E-AC-3 and DTS; resolves `null` when there
1292
+ * is none.
1327
1293
  *
1328
1294
  * Rejects only when `read` or `firstPacket` rejects; malformed bytes resolve to `null`.
1329
1295
  */