@blockcast/mmt-container 2.2.0-main.a5b276c121d4 → 2.2.0-main.aee8d33d2cc8

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 (80) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +55 -13
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +104 -32
  5. package/dist/block-policy.js.map +2 -2
  6. package/dist/browser-runtime.js +420 -55
  7. package/dist/browser-runtime.js.map +3 -3
  8. package/dist/carp-catalog.js.map +2 -2
  9. package/dist/catalog-fec-params.d.ts +1 -1
  10. package/dist/catalog-fec-params.d.ts.map +1 -1
  11. package/dist/catalog-fec-params.js +14 -1
  12. package/dist/catalog-fec-params.js.map +2 -2
  13. package/dist/catalog-network-source.js.map +2 -2
  14. package/dist/cmaf-block-assembler.js +92 -1
  15. package/dist/cmaf-block-assembler.js.map +2 -2
  16. package/dist/codec-utils.d.ts.map +1 -1
  17. package/dist/codec-utils.js +92 -1
  18. package/dist/codec-utils.js.map +2 -2
  19. package/dist/delivery-catalog.js.map +2 -2
  20. package/dist/delta-fallback-config.js +5 -1
  21. package/dist/delta-fallback-config.js.map +3 -3
  22. package/dist/fec-manager.d.ts +44 -3
  23. package/dist/fec-manager.d.ts.map +1 -1
  24. package/dist/fec-manager.js +245 -46
  25. package/dist/fec-manager.js.map +2 -2
  26. package/dist/fec-state.js +5 -1
  27. package/dist/fec-state.js.map +2 -2
  28. package/dist/fec-worker-setup.js.map +2 -2
  29. package/dist/held-layer-admission.js.map +2 -2
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +3 -1
  33. package/dist/index.js.map +2 -2
  34. package/dist/iso-block-locator.js.map +2 -2
  35. package/dist/mfu-reassembler.js.map +2 -2
  36. package/dist/mmtp-container-parser.d.ts +27 -2
  37. package/dist/mmtp-container-parser.d.ts.map +1 -1
  38. package/dist/mmtp-container-parser.js +106 -2
  39. package/dist/mmtp-container-parser.js.map +2 -2
  40. package/dist/mmtp-container-parser.no-modules.js +126 -5
  41. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  42. package/dist/mmtp-decode-pipeline.js +106 -2
  43. package/dist/mmtp-decode-pipeline.js.map +2 -2
  44. package/dist/mmtp-fec-session.js.map +2 -2
  45. package/dist/mmtp-router.d.ts +2 -0
  46. package/dist/mmtp-router.d.ts.map +1 -1
  47. package/dist/mmtp-router.js +150 -3
  48. package/dist/mmtp-router.js.map +3 -3
  49. package/dist/multicast-auth-catalog.js.map +2 -2
  50. package/dist/multicast-input.js.map +2 -2
  51. package/dist/multicast-manager.d.ts.map +1 -1
  52. package/dist/multicast-manager.js +409 -53
  53. package/dist/multicast-manager.js.map +3 -3
  54. package/dist/multicast-transport.js.map +2 -2
  55. package/dist/multicast-unwrap.js.map +2 -2
  56. package/dist/no-modules.d.ts +1 -0
  57. package/dist/no-modules.d.ts.map +1 -1
  58. package/dist/no-modules.js +128 -6
  59. package/dist/no-modules.js.map +4 -4
  60. package/dist/repair-fetch.d.ts +2 -0
  61. package/dist/repair-fetch.d.ts.map +1 -1
  62. package/dist/repair-fetch.js +2 -2
  63. package/dist/repair-fetch.js.map +2 -2
  64. package/dist/repair-layer-subscriptions.js.map +2 -2
  65. package/dist/signaling.js.map +2 -2
  66. package/dist/timestamp-codec.js.map +2 -2
  67. package/dist/wasm-mfu-reassembler.js.map +2 -2
  68. package/dist/wasm-mmtp-container-parser.js +106 -2
  69. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  70. package/package.json +5 -5
  71. package/src/block-policy.ts +216 -52
  72. package/src/catalog-fec-params.ts +1 -0
  73. package/src/codec-utils.ts +121 -1
  74. package/src/fec-manager.ts +195 -14
  75. package/src/index.ts +2 -0
  76. package/src/mmtp-container-parser.ts +55 -11
  77. package/src/mmtp-router.ts +70 -6
  78. package/src/multicast-manager.ts +19 -3
  79. package/src/no-modules.ts +3 -0
  80. package/src/repair-fetch.ts +4 -2
@@ -1797,13 +1797,25 @@ function fecCatalogTracks(catalog) {
1797
1797
  });
1798
1798
  return { tracks, pointers };
1799
1799
  }
1800
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1800
+ function runtimeView(catalog, receiver) {
1801
1801
  const { tracks, pointers } = fecCatalogTracks(catalog);
1802
1802
  const report = validateFecCatalog({ tracks }, receiver);
1803
1803
  const at2 = (path) => {
1804
1804
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
1805
1805
  return m ? pointers[Number(m[1])] + m[2] : path;
1806
1806
  };
1807
+ return { tracks, pointers, report, at: at2 };
1808
+ }
1809
+ function runtimeFecCatalogReport(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1810
+ const { report, at: at2 } = runtimeView(catalog, receiver);
1811
+ const issue = (i) => Object.freeze({ code: i.code, path: at2(i.path) });
1812
+ return Object.freeze({
1813
+ instances: Object.freeze(report.instances.map((i) => Object.freeze({ ...i, path: at2(i.path), issues: Object.freeze(i.issues.map(issue)) }))),
1814
+ issues: Object.freeze(report.issues.map(issue))
1815
+ });
1816
+ }
1817
+ function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1818
+ const { tracks, pointers, report, at: at2 } = runtimeView(catalog, receiver);
1807
1819
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
1808
1820
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
1809
1821
  const why = (i) => Object.freeze({
@@ -6099,9 +6111,10 @@ function isH264IntraSlice(nal) {
6099
6111
  const sliceType = readH264SliceType(nal);
6100
6112
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
6101
6113
  }
6114
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
6102
6115
  function readH264SliceType(nal) {
6103
6116
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
6104
- const rbsp = removeEmulationPrevention(nal.subarray(1));
6117
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
6105
6118
  const state = { bitOffset: 0 };
6106
6119
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
6107
6120
  return readUnsignedExpGolomb(rbsp, state);
@@ -6470,6 +6483,96 @@ if (void 0) {
6470
6483
  ]))).toBe(false);
6471
6484
  });
6472
6485
  });
6486
+ describe("readH264SliceType", () => {
6487
+ const wholeNalSliceType = (nal) => {
6488
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
6489
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
6490
+ const state = { bitOffset: 0 };
6491
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
6492
+ return readUnsignedExpGolomb(rbsp, state);
6493
+ };
6494
+ const hex3 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
6495
+ const ue = (value) => {
6496
+ const code = (value + 1).toString(2);
6497
+ return "0".repeat(code.length - 1) + code;
6498
+ };
6499
+ const sliceNal = (bits) => {
6500
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
6501
+ const nal = [1];
6502
+ let zeros = 0;
6503
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
6504
+ if (zeros >= 2 && byte <= 3) {
6505
+ nal.push(3);
6506
+ zeros = 0;
6507
+ }
6508
+ nal.push(byte);
6509
+ zeros = byte === 0 ? zeros + 1 : 0;
6510
+ }
6511
+ return Uint8Array.from(nal);
6512
+ };
6513
+ const x264Slices = [
6514
+ ["64x48 P", hex3("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
6515
+ ["64x48 B", hex3("419e414212fffeeade283707cb70f7"), 6, false],
6516
+ ["64x48 non-IDR I", hex3(
6517
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
6518
+ ), 7, true],
6519
+ ["1280x720 B, escape at byte 10", hex3(
6520
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
6521
+ ), 6, false],
6522
+ ["1280x720 P, escape at byte 15", hex3(
6523
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
6524
+ ), 5, false],
6525
+ ["1280x720 B, escape at byte 22", hex3("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
6526
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex3(
6527
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
6528
+ ), null, true],
6529
+ ["7680x4320 P, first_mb_in_slice 32640", hex3(
6530
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
6531
+ ), 5, false],
6532
+ ["7680x4320 P, first_mb_in_slice 97440", hex3(
6533
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
6534
+ ), 5, false]
6535
+ ];
6536
+ const syntheticSlices = [
6537
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
6538
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
6539
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
6540
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
6541
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
6542
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
6543
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
6544
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
6545
+ ];
6546
+ test("reads the slice_type of real and synthetic slices", () => {
6547
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
6548
+ expect(readH264SliceType(nal), name).toBe(sliceType);
6549
+ }
6550
+ });
6551
+ test("matches the whole-NAL unescape at every truncation", () => {
6552
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
6553
+ for (let end = 0; end <= nal.length; end++) {
6554
+ const cut = nal.subarray(0, end);
6555
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
6556
+ }
6557
+ }
6558
+ });
6559
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
6560
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
6561
+ let seed = 1;
6562
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
6563
+ for (let i = 0; i < 5e3; i++) {
6564
+ const nal = new Uint8Array(2 + next() % 63);
6565
+ nal[0] = 65;
6566
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
6567
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
6568
+ }
6569
+ });
6570
+ test("classifies the x264 slices as keyframes or not", () => {
6571
+ for (const [name, nal, , keyframe] of x264Slices) {
6572
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
6573
+ }
6574
+ });
6575
+ });
6473
6576
  describe("avccToAnnexB", () => {
6474
6577
  test("converts with SPS/PPS on keyframe", () => {
6475
6578
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -13440,8 +13543,9 @@ function keyframeIntervalMediaTicks(geometry2, mediaTimescale) {
13440
13543
  return scaled / divisor;
13441
13544
  }
13442
13545
  function compareDataUnitStarts(a, b) {
13443
- return a.movieFragment - b.movieFragment || a.idx - b.idx || a.offset - b.offset;
13546
+ return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
13444
13547
  }
13548
+ var UNPLACED = { rapNotMpuStart: false };
13445
13549
  var BlockClassifier = class {
13446
13550
  #geometry;
13447
13551
  #mode;
@@ -13464,8 +13568,23 @@ var BlockClassifier = class {
13464
13568
  #mpuSbnSpans = /* @__PURE__ */ new Map();
13465
13569
  #dataUnitStarts = /* @__PURE__ */ new Map();
13466
13570
  #highestMpu = null;
13467
- /** MPU → movie_fragment_sequence_number observed in it. */
13468
- #mpuFragments = /* @__PURE__ */ new Map();
13571
+ /**
13572
+ * P3 layout, kept for the MPUs within the classification horizon and valid
13573
+ * within one continuous SBN sequence (`noteSourceDiscontinuity`).
13574
+ */
13575
+ #mpus = /* @__PURE__ */ new Map();
13576
+ /** An MPU of this sequence showed two movie fragments: each frame is one. */
13577
+ #fragmentPerFrame = false;
13578
+ /** A DU header of this sequence stated sample_number above 1. */
13579
+ #multiSampleFragment = false;
13580
+ /**
13581
+ * The anchor received last, whether or not its MPU is still in the
13582
+ * horizon. Each new anchor, and the anchor of every DU header's MPU, is
13583
+ * checked against it.
13584
+ */
13585
+ #lastAnchor = null;
13586
+ /** Two anchors were exactly G fragments per MPU apart. */
13587
+ #fragmentsProven = false;
13469
13588
  #lastRap = null;
13470
13589
  constructor(geometry2) {
13471
13590
  this.#geometry = geometry2;
@@ -13495,7 +13614,7 @@ var BlockClassifier = class {
13495
13614
  this.#geometry = geometry2;
13496
13615
  this.#blocks.clear();
13497
13616
  this.#clearContiguityLedger();
13498
- this.#mpuFragments.clear();
13617
+ this.#clearMpuLayout();
13499
13618
  this.#lastRap = null;
13500
13619
  this.#mpuBoundsRaps = true;
13501
13620
  if (geometry2.trackKind === "video" && geometry2.mode === "all-protected") {
@@ -13529,11 +13648,13 @@ var BlockClassifier = class {
13529
13648
  /**
13530
13649
  * The stream's SBN sequence restarted (FECManager source discontinuity:
13531
13650
  * a publisher restart, or the SS_ID space wrapped). Authored order and SBN
13532
- * order are comparable only within one continuous sequence, so the P1
13533
- * ledger starts again.
13651
+ * order are comparable only within one continuous sequence, and a
13652
+ * restarted publisher numbers MPUs and movie fragments again, so the P1
13653
+ * ledger and the P3 layout start again.
13534
13654
  */
13535
13655
  noteSourceDiscontinuity() {
13536
13656
  this.#clearContiguityLedger();
13657
+ this.#clearMpuLayout();
13537
13658
  }
13538
13659
  /** Register a block that exists without evidence (a vanished block). */
13539
13660
  touch(sbn) {
@@ -13552,16 +13673,16 @@ var BlockClassifier = class {
13552
13673
  if (this.#geometry.trackKind === "audio") return [];
13553
13674
  const changes = [];
13554
13675
  const block = this.#blockFor(sbn);
13676
+ const placement = this.#place(evidence);
13555
13677
  if (evidence.rap) block.rapSeen = true;
13556
13678
  if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
13557
- if (evidence.idx !== void 0) {
13558
- block.idxMin = block.idxMin === void 0 ? evidence.idx : Math.min(block.idxMin, evidence.idx);
13559
- block.idxMax = block.idxMax === void 0 ? evidence.idx : Math.max(block.idxMax, evidence.idx);
13560
- }
13561
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
13562
- this.#mpuBoundsRaps = false;
13679
+ const { position } = placement;
13680
+ if (position !== void 0) {
13681
+ block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
13682
+ block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
13563
13683
  }
13564
- const violation = this.#checkInvariants(sbn, block, evidence);
13684
+ if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
13685
+ const violation = this.#checkInvariants(sbn, block, evidence, placement);
13565
13686
  if (violation !== null) changes.push(...this.#disable(violation));
13566
13687
  const next = this.#classify(block);
13567
13688
  if (next !== block.cls && this.#allowed(block.cls, next)) {
@@ -13614,35 +13735,89 @@ var BlockClassifier = class {
13614
13735
  }
13615
13736
  return block;
13616
13737
  }
13617
- #checkInvariants(sbn, block, evidence) {
13738
+ #checkInvariants(sbn, block, evidence, placement) {
13618
13739
  if (this.#mode === "all-protected" || this.#geometry.trackKind !== "video") return null;
13619
13740
  const geometry2 = this.#geometry;
13620
13741
  if (geometry2.mode !== "classifying") return null;
13621
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
13622
- return "rap-not-mpu-start";
13623
- }
13624
- if (evidence.idx !== void 0 && evidence.idx >= geometry2.gopFrames) {
13742
+ if (placement.rapNotMpuStart) return "rap-not-mpu-start";
13743
+ if (placement.position !== void 0 && placement.position >= geometry2.gopFrames) {
13625
13744
  return "mpu-longer-than-gop";
13626
13745
  }
13627
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0 && block.idxMax - block.idxMin >= geometry2.interleaveUnits) {
13746
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0 && block.positionMax - block.positionMin >= geometry2.interleaveUnits) {
13628
13747
  return "block-wider-than-interleave";
13629
13748
  }
13630
- if (evidence.mpu !== void 0 && evidence.movieFragment !== void 0) {
13631
- const fragment = this.#mpuFragments.get(evidence.mpu);
13632
- if (fragment === void 0) {
13633
- this.#mpuFragments.set(evidence.mpu, evidence.movieFragment);
13634
- for (const mpu of this.#mpuFragments.keys()) {
13635
- if (mpu + 1 < evidence.mpu) this.#mpuFragments.delete(mpu);
13636
- }
13637
- } else if (fragment !== evidence.movieFragment) {
13638
- return "mpu-multiple-fragments";
13639
- }
13640
- }
13749
+ if (placement.violation !== void 0) return placement.violation;
13641
13750
  if (evidence.mpu !== void 0 && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {
13642
13751
  return "block-not-contiguous";
13643
13752
  }
13644
13753
  return null;
13645
13754
  }
13755
+ /**
13756
+ * The MPU position a source symbol's DU header proves (P3), and what it
13757
+ * refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.
13758
+ */
13759
+ #place(evidence) {
13760
+ const { mpu, idx, movieFragment: fragment } = evidence;
13761
+ if (idx === void 0) return UNPLACED;
13762
+ const bySample = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 };
13763
+ if (mpu === void 0 || fragment === void 0) {
13764
+ return this.#fragmentPerFrame && !this.#multiSampleFragment ? { rapNotMpuStart: bySample.rapNotMpuStart } : bySample;
13765
+ }
13766
+ let layout = this.#mpus.get(mpu);
13767
+ if (layout === void 0) {
13768
+ layout = { low: fragment };
13769
+ this.#mpus.set(mpu, layout);
13770
+ for (const other of this.#mpus.keys()) {
13771
+ if (other + 1 < mpu) this.#mpus.delete(other);
13772
+ }
13773
+ } else if (fragment !== layout.low) {
13774
+ this.#fragmentPerFrame = true;
13775
+ if ((fragment - layout.low | 0) < 0) layout.low = fragment;
13776
+ }
13777
+ if (idx !== 0) this.#multiSampleFragment = true;
13778
+ let arrival;
13779
+ if (evidence.rap && layout.anchor === void 0) {
13780
+ layout.anchor = fragment;
13781
+ arrival = this.#anchorDrift(mpu, fragment);
13782
+ if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true;
13783
+ this.#lastAnchor = { mpu, fragment };
13784
+ }
13785
+ if (!this.#fragmentPerFrame) return bySample;
13786
+ if (this.#multiSampleFragment) return { ...bySample, violation: "mpu-multiple-fragments" };
13787
+ const { anchor } = layout;
13788
+ if (anchor === void 0) return UNPLACED;
13789
+ const drift = arrival ?? this.#anchorDrift(mpu, anchor);
13790
+ const offset = fragment - anchor | 0;
13791
+ return {
13792
+ ...offset === 0 || offset > 0 && this.#fragmentsProven ? { position: offset } : {},
13793
+ rapNotMpuStart: evidence.rap && offset !== 0 || (layout.low - anchor | 0) < 0 || // Fragments count frames: an anchor arriving past the spacing is a
13794
+ // RAP inside its MPU, or an earlier MPU outran G.
13795
+ arrival !== void 0 && arrival > 0 && this.#fragmentsProven,
13796
+ ...drift === void 0 || drift === 0 ? {} : { violation: "rap-spacing-mismatch" }
13797
+ };
13798
+ }
13799
+ /**
13800
+ * How many fragments MPU m's anchor `fragment` lies past the start that
13801
+ * the anchor received last predicts for MPU m: one frame per fragment and
13802
+ * G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')
13803
+ * fragments apart, modulo 2^32. Undefined without a last anchor, a
13804
+ * cadence, or this layout.
13805
+ */
13806
+ #anchorDrift(mpu, fragment) {
13807
+ const geometry2 = this.#geometry;
13808
+ const last = this.#lastAnchor;
13809
+ if (last === null || !this.#fragmentPerFrame || this.#multiSampleFragment || geometry2.trackKind !== "video" || geometry2.mode !== "classifying") {
13810
+ return void 0;
13811
+ }
13812
+ return fragment - last.fragment - geometry2.gopFrames * (mpu - last.mpu) | 0;
13813
+ }
13814
+ #clearMpuLayout() {
13815
+ this.#mpus.clear();
13816
+ this.#fragmentPerFrame = false;
13817
+ this.#multiSampleFragment = false;
13818
+ this.#lastAnchor = null;
13819
+ this.#fragmentsProven = false;
13820
+ }
13646
13821
  #clearContiguityLedger() {
13647
13822
  this.#mpuSbnSpans.clear();
13648
13823
  this.#dataUnitStarts.clear();
@@ -13742,9 +13917,9 @@ var BlockClassifier = class {
13742
13917
  if (this.#mode === "all-protected") return "unknown";
13743
13918
  const geometry2 = this.#geometry;
13744
13919
  if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return "unknown";
13745
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0) {
13920
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
13746
13921
  const span = geometry2.interleaveUnits - 1;
13747
- if (block.idxMax - span >= 1 && block.idxMin + span <= geometry2.gopFrames - 1) {
13922
+ if (block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1) {
13748
13923
  return "delta";
13749
13924
  }
13750
13925
  }
@@ -14041,7 +14216,8 @@ var FECManager = class _FECManager {
14041
14216
  this.#ssbLengthConflictCount = 0;
14042
14217
  this.#blockRepairRsIds = /* @__PURE__ */ new Map();
14043
14218
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
14044
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
14219
+ // symbols its repair group carries; 0 for a repair-less span no repair can
14220
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
14045
14221
  this.#blockRsbLengths = /* @__PURE__ */ new Map();
14046
14222
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
14047
14223
  this.#heldLayerStates = /* @__PURE__ */ new Map();
@@ -14229,6 +14405,7 @@ var FECManager = class _FECManager {
14229
14405
  this.#workerErrorCounts = /* @__PURE__ */ new Map();
14230
14406
  this.#decoderUnavailableEvents = 0;
14231
14407
  this.#repairSymbolSizeMismatchCount = 0;
14408
+ this.#unlistedRepairTrackRefusals = 0;
14232
14409
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
14233
14410
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
14234
14411
  // feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
@@ -14288,6 +14465,16 @@ var FECManager = class _FECManager {
14288
14465
  this.onBlockResolved = null;
14289
14466
  /** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
14290
14467
  this.onSourceDiscontinuity = null;
14468
+ /**
14469
+ * The span and tolerance the catalog states for a keyframe overlay
14470
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
14471
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
14472
+ * undefined while none is installed. A stated block only a late source
14473
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
14474
+ * late source can fill, also wait for that overlay's repair
14475
+ * (#overlayLateWaitMs).
14476
+ */
14477
+ this.keyframeOverlayTiming = null;
14291
14478
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
14292
14479
  /**
14293
14480
  * A recovered source symbol. Return false when admission refused the
@@ -14392,6 +14579,7 @@ var FECManager = class _FECManager {
14392
14579
  #workerErrorCounts;
14393
14580
  #decoderUnavailableEvents;
14394
14581
  #repairSymbolSizeMismatchCount;
14582
+ #unlistedRepairTrackRefusals;
14395
14583
  #onUndelimitedLoss;
14396
14584
  #onIsoHoleExpired;
14397
14585
  #encodeTrackName(catalogTrackName) {
@@ -15560,6 +15748,7 @@ var FECManager = class _FECManager {
15560
15748
  packetId
15561
15749
  })),
15562
15750
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
15751
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
15563
15752
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
15564
15753
  workerErrors: Object.fromEntries(this.#workerErrorCounts)
15565
15754
  };
@@ -16064,8 +16253,10 @@ var FECManager = class _FECManager {
16064
16253
  }
16065
16254
  /**
16066
16255
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
16067
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
16068
- * Undefined for a block that is not open.
16256
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
16257
+ * repair-less span states its length, and RSB_length 0 when it is longer
16258
+ * than K, since no repair can reach it). Undefined for a block that is not
16259
+ * open.
16069
16260
  */
16070
16261
  blockSymbolCounts(sbn, packetId, catalogTrackName) {
16071
16262
  const key = this.#blockKey(sbn, packetId, catalogTrackName);
@@ -16181,7 +16372,7 @@ var FECManager = class _FECManager {
16181
16372
  }
16182
16373
  const trackConfig = this.#trackConfigs.get(packetId);
16183
16374
  if (trackConfig === void 0) return void 0;
16184
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig));
16375
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
16185
16376
  }
16186
16377
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
16187
16378
  // -----------------------------------------------------------------------
@@ -16367,12 +16558,24 @@ var FECManager = class _FECManager {
16367
16558
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
16368
16559
  * SS_ID of which vanished resolves through its deadline like any vanished
16369
16560
  * block.
16561
+ *
16562
+ * A span longer than K holds more than one block (SSB_length <= K), and the
16563
+ * locator states no block inside a span, only one exactly its range
16564
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
16565
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
16566
+ * Group of it (group-cannot-complete). Every span still keeps its whole
16567
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
16568
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
16569
+ * gate lets those frames go once only a late source can fill the gap
16570
+ * before them, as long after they arrived as the gap's decision allows
16571
+ * (isoRepairlessWaitMs).
16370
16572
  */
16371
16573
  #openIsoSpan(span, packetId, catalogTrackName) {
16372
16574
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
16373
16575
  if (!this.#blockAuthoredLengths.has(key)) {
16374
16576
  this.#blockAuthoredLengths.set(key, span.block.length);
16375
16577
  this.#isoSpanKeys.add(key);
16578
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
16376
16579
  }
16377
16580
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
16378
16581
  }
@@ -16411,6 +16614,62 @@ var FECManager = class _FECManager {
16411
16614
  }
16412
16615
  return lost;
16413
16616
  }
16617
+ /**
16618
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
16619
+ * between two released frames' SS_IDs once only a late source can still
16620
+ * fill them, else undefined. That is when every one missing (neither
16621
+ * arrived nor held) lies in a repair-less span longer than K, which no
16622
+ * repair can state a block of (#openIsoSpan), or in a stated block its
16623
+ * own repair group cannot complete every SS_ID of which it misses lies
16624
+ * between them (so the gap's decision covers all it lost), and a multicast
16625
+ * source at or past `toSsId` arrived, so each is lost or reordered behind
16626
+ * it (a MoQ source shows nothing: MoQ streams overtake one another). The
16627
+ * span or block itself keeps its own wait.
16628
+ *
16629
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
16630
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
16631
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
16632
+ * Then the frame waits as a stated block its group cannot complete does
16633
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
16634
+ * overlay's span plus the larger of the allowance and its tolerance, or,
16635
+ * for an overlay that states no span, the span's whole wait (undefined).
16636
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
16637
+ * the gap holds a stated block's loss.
16638
+ */
16639
+ isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false) {
16640
+ const config = this.#trackConfigs.get(packetId);
16641
+ if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
16642
+ const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
16643
+ if (locator === void 0 || !locator.coversBetween(fromSsId, toSsId)) return void 0;
16644
+ const newestSource = locator.newestSource;
16645
+ if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
16646
+ let repairless = false;
16647
+ let stated = false;
16648
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
16649
+ const key = this.#blockKey(block.start, packetId, catalogTrackName);
16650
+ if (this.#completedBlocks.has(key)) continue;
16651
+ if (block.span && block.length > locator.kMax) {
16652
+ repairless = true;
16653
+ continue;
16654
+ }
16655
+ const received = this.#blockSourceEsis.get(key);
16656
+ const rebuilt = this.#blockRebuiltEsis.get(key);
16657
+ let missesInGap = false;
16658
+ let missesOutside = false;
16659
+ for (let esi = 0; esi < block.length; esi++) {
16660
+ const ssId = serial32Add(block.start, esi);
16661
+ if (received?.has(esi) || locator.isHeld(ssId)) continue;
16662
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
16663
+ else if (!rebuilt?.has(esi)) missesOutside = true;
16664
+ }
16665
+ if (!missesInGap) continue;
16666
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
16667
+ repairless = stated = true;
16668
+ }
16669
+ if (!repairless) return void 0;
16670
+ const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
16671
+ return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
16672
+ }
16414
16673
  /**
16415
16674
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
16416
16675
  * the sources held now for a block no repair has stated yet, and the held
@@ -17059,7 +17318,10 @@ var FECManager = class _FECManager {
17059
17318
  this.#layerAnchorHorizon(packetId),
17060
17319
  this.#sourceFrontiers.get(streamKey)?.sbn
17061
17320
  );
17062
- if (verdict === "discard") return false;
17321
+ if (verdict === "discard") {
17322
+ this.#unlistedRepairTrackRefusals++;
17323
+ return false;
17324
+ }
17063
17325
  if (verdict !== void 0) {
17064
17326
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
17065
17327
  return false;
@@ -17216,7 +17478,7 @@ var FECManager = class _FECManager {
17216
17478
  const previous = locator.newestSource;
17217
17479
  if (!locator.noteSource(ssId) || previous === void 0) return;
17218
17480
  for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
17219
- if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
17481
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
17220
17482
  this.#shortenUnrecoverableWait(
17221
17483
  this.#blockKey(block.start, packetId, catalogTrackName),
17222
17484
  block.start,
@@ -17234,21 +17496,61 @@ var FECManager = class _FECManager {
17234
17496
  * covers repair symbols paced after its sources, buys it nothing: it waits
17235
17497
  * the late-symbol allowance alone, the multicast wait less the span (the
17236
17498
  * catalog tolerance or the measured delivery gap). Undefined for any other
17237
- * block.
17499
+ * block. While a keyframe overlay is installed, the block waits for its
17500
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
17501
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
17502
+ * resolution is what releases the frames behind it, and failing it early
17503
+ * released them past a keyframe the overlay was still rebuilding, which
17504
+ * then arrived stale. The release gate lets them go instead
17505
+ * (isoRepairlessWaitMs).
17238
17506
  */
17239
17507
  #lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
17508
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
17240
17509
  const authoredLength = this.#blockAuthoredLengths.get(key);
17241
- const rsbLength = this.#blockRsbLengths.get(key);
17242
- if (authoredLength === void 0 || rsbLength === void 0) return void 0;
17243
- let present = this.#blockSourceCounts.get(key) ?? 0;
17244
- const received = this.#blockSourceEsis.get(key);
17245
- for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
17246
- if (present + rsbLength >= authoredLength) return void 0;
17247
17510
  const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
17248
17511
  if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
17249
17512
  return void 0;
17250
17513
  }
17251
- return this.#multicastWaitMs(config) - config.interleaveDepthMs;
17514
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
17515
+ }
17516
+ /**
17517
+ * A repair stated the block, and its sources plus every symbol its repair
17518
+ * group carries (RSB_length) are short of its SSB_length.
17519
+ */
17520
+ #groupCannotComplete(key) {
17521
+ const authoredLength = this.#blockAuthoredLengths.get(key);
17522
+ const rsbLength = this.#blockRsbLengths.get(key);
17523
+ if (authoredLength === void 0 || rsbLength === void 0) return false;
17524
+ let present = this.#blockSourceCounts.get(key) ?? 0;
17525
+ const received = this.#blockSourceEsis.get(key);
17526
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
17527
+ return present + rsbLength < authoredLength;
17528
+ }
17529
+ /**
17530
+ * How long a loss only a late source or an installed keyframe overlay can
17531
+ * still fill waits once a later source passed it: the late-symbol
17532
+ * allowance alone (the multicast wait less the span) while no overlay is
17533
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
17534
+ * RAP packet the loss took: a second FEC instance over the same packets
17535
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
17536
+ * span, unrelated to the base's. That packet can complete a stated block
17537
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
17538
+ * first lets the release gate pass the keyframe, whose rebuild then lands
17539
+ * stale. The overlay repair of a packet the loss took goes out within the
17540
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
17541
+ * sent after it, so the loss waits that span plus the larger of the
17542
+ * allowance and the overlay's own tolerance. An overlay that states no
17543
+ * span (its block may then span keyframes), or one whose wait is not
17544
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
17545
+ */
17546
+ #overlayLateWaitMs(packetId, catalogTrackName, config) {
17547
+ const waitMs = this.#multicastWaitMs(config);
17548
+ const allowanceMs = waitMs - config.interleaveDepthMs;
17549
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
17550
+ if (overlay === void 0) return allowanceMs;
17551
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
17552
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
17553
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
17252
17554
  }
17253
17555
  /**
17254
17556
  * Bring an open block's wait in to its late-source wait, when it has one.
@@ -18889,7 +19191,7 @@ var FecReleaseSequencer = class {
18889
19191
  from
18890
19192
  );
18891
19193
  unresolved = resolved === null;
18892
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
19194
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
18893
19195
  const heldMs = performance.now() - head.arrivedAtMs;
18894
19196
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
18895
19197
  this.#recordStat("forcedWindowFlushes");
@@ -18907,6 +19209,19 @@ var FecReleaseSequencer = class {
18907
19209
  );
18908
19210
  }
18909
19211
  }
19212
+ /**
19213
+ * The head has waited out a gap only a late source can still fill
19214
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
19215
+ * the stream when it has (`wakeAt`), since no packet may come by then.
19216
+ */
19217
+ #unrepairableWaitOver(stream, last, head, from, to) {
19218
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
19219
+ if (waitMs === void 0) return false;
19220
+ const atMs = head.arrivedAtMs + waitMs;
19221
+ if (performance.now() >= atMs) return true;
19222
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
19223
+ return false;
19224
+ }
18910
19225
  /**
18911
19226
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
18912
19227
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -23488,6 +23803,8 @@ var MmtpRouter = class {
23488
23803
  // end: a synchronous recovery completes its block BEFORE routing the
23489
23804
  // recovered frames, and releasing a held gap in between would strand them.
23490
23805
  #fecPokeDepth = 0;
23806
+ /** FecReleaseGate.wakeAt timers, by media stream key. */
23807
+ #fecWakes = /* @__PURE__ */ new Map();
23491
23808
  #pendingFecPokes = /* @__PURE__ */ new Map();
23492
23809
  // ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
23493
23810
  /** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
@@ -25548,6 +25865,8 @@ var MmtpRouter = class {
25548
25865
  this.#disposed = true;
25549
25866
  this.#staged = null;
25550
25867
  this.cancelKeyframeLostTimer();
25868
+ for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
25869
+ this.#fecWakes.clear();
25551
25870
  this.#parser.dispose();
25552
25871
  this.#streams.clear();
25553
25872
  this.#trackPacketCallbacks.clear();
@@ -25729,6 +26048,31 @@ var MmtpRouter = class {
25729
26048
  if (!fec?.terminalRetentionMsForPacket) return Infinity;
25730
26049
  return fec.terminalRetentionMsForPacket(packetId) ?? 0;
25731
26050
  },
26051
+ // Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
26052
+ // late source can), its frame waits the late-symbol allowance when the
26053
+ // gap holds no RAP an installed keyframe overlay could still rebuild:
26054
+ // lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
26055
+ // that opens the next one while MPU boundaries bound RAPs (rap-next,
26056
+ // unless the gap holds a stated block's loss: the overlay may rebuild
26057
+ // that MPU's FT=0, and the block's group then complete it), or
26058
+ // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
26059
+ // other rap-next, whose gap may hold a whole MPU and the keyframe the
26060
+ // overlay protects) waits for that overlay's repair too (BLO-52085
26061
+ // D4). The FEC check comes first: most held gaps are not behind such a
26062
+ // span, and deciding one scans both frames' bitstreams.
26063
+ unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
26064
+ const fec = this.#fecManager;
26065
+ const { packetId, catalogTrackName } = after.meta;
26066
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
26067
+ if (!fec || allowanceMs === void 0) return void 0;
26068
+ const decision = this.#decideGap(before, after, [], false);
26069
+ const mpu = before.meta.mpuSequenceNumber;
26070
+ const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
26071
+ if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
26072
+ return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
26073
+ }
26074
+ return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
26075
+ },
25732
26076
  decide: (before, after, lostBlocks, discontinuity) => {
25733
26077
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
25734
26078
  this.#onFrameGap?.(decision);
@@ -25738,6 +26082,20 @@ var MmtpRouter = class {
25738
26082
  onRap: (packetId, catalogTrackName, ssId) => {
25739
26083
  for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
25740
26084
  },
26085
+ // One timer per stream, at the earliest wake asked: its drain re-arms
26086
+ // for the next frame still waiting.
26087
+ wakeAt: (packetId, catalogTrackName, atMs) => {
26088
+ if (this.#disposed) return;
26089
+ const key = this.#mediaStreamKey(packetId, catalogTrackName);
26090
+ const armed = this.#fecWakes.get(key);
26091
+ if (armed !== void 0 && armed.atMs <= atMs) return;
26092
+ if (armed !== void 0) clearTimeout(armed.timer);
26093
+ const timer = setTimeout(() => {
26094
+ this.#fecWakes.delete(key);
26095
+ this.#requestFecPoke(packetId, catalogTrackName);
26096
+ }, Math.max(0, Math.ceil(atMs - performance.now())));
26097
+ this.#fecWakes.set(key, { atMs, timer });
26098
+ },
25741
26099
  // A staged switch commits on when each side's frames reach it
25742
26100
  // (#interceptSwitchFrame): both sides' overlay keyframes reach it when
25743
26101
  // they did unanchored.
@@ -25773,7 +26131,7 @@ var MmtpRouter = class {
25773
26131
  #decideGap(before, after, lostBlocks, discontinuity) {
25774
26132
  const { packetId, catalogTrackName } = after.meta;
25775
26133
  const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
25776
- const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying";
26134
+ const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" && before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
25777
26135
  const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
25778
26136
  const evidence = (frame) => {
25779
26137
  const timing = frame.meta.authoredTiming;
@@ -28867,6 +29225,11 @@ var MulticastManager = class {
28867
29225
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
28868
29226
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
28869
29227
  };
29228
+ this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
29229
+ const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
29230
+ if (binding === void 0) return void 0;
29231
+ return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
29232
+ };
28870
29233
  this.#fec.onDecoderUnavailable = (event) => {
28871
29234
  this.#emitRepairLifecycle({
28872
29235
  version: 2,
@@ -29554,7 +29917,7 @@ var MulticastManager = class {
29554
29917
  console.warn("[MulticastManager] repair group release failed", error);
29555
29918
  }
29556
29919
  };
29557
- const usedFlows = /* @__PURE__ */ new Set();
29920
+ const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
29558
29921
  const preparedProvenance = endpoints.map((endpoint) => {
29559
29922
  if (endpoint.provenance === void 0) return void 0;
29560
29923
  const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
@@ -30113,7 +30476,8 @@ var MulticastManager = class {
30113
30476
  blockProfile: parseFecBlockProfile(
30114
30477
  geometry2.blockProfile,
30115
30478
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
30116
- )
30479
+ ),
30480
+ geometry: geometry2
30117
30481
  });
30118
30482
  }
30119
30483
  }
@@ -30152,7 +30516,7 @@ var MulticastManager = class {
30152
30516
  for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
30153
30517
  const before = this.#overlayBindings.get(sourcePacketId);
30154
30518
  const after = overlayBindings.get(sourcePacketId);
30155
- const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
30519
+ const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
30156
30520
  if (!same) install.dispose();
30157
30521
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
30158
30522
  else install.reattach();
@@ -33196,7 +33560,7 @@ function wireRepairFetch(mc, opts) {
33196
33560
  if (!run) return;
33197
33561
  entry.running = null;
33198
33562
  run.stopped = reason;
33199
- run.controller.abort();
33563
+ run.controller.abort(reason);
33200
33564
  if (reason === "preempted") releaseHold(entry);
33201
33565
  mc.noteRepairStopped?.(reason, entry.sbn, entry.packetId, entry.catalogTrackName);
33202
33566
  };
@@ -33494,7 +33858,7 @@ function wireRepairFetch(mc, opts) {
33494
33858
  if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
33495
33859
  const rsIds = /* @__PURE__ */ new Set();
33496
33860
  const group = new AbortController();
33497
- const cancel = () => group.abort();
33861
+ const cancel = () => group.abort(common.signal.reason);
33498
33862
  common.signal.addEventListener("abort", cancel, { once: true });
33499
33863
  walk.group = { sbn, controller: group };
33500
33864
  try {
@@ -34030,6 +34394,7 @@ export {
34030
34394
  resolveGroupDurationMs,
34031
34395
  resolveGroupDurationTicks,
34032
34396
  resolveRepairLayers,
34397
+ runtimeFecCatalogReport,
34033
34398
  secondsFromTicks,
34034
34399
  setupFecWorkerForTrack,
34035
34400
  setupTrackPipeline,