@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
@@ -954,13 +954,17 @@ function fecCatalogTracks(catalog) {
954
954
  });
955
955
  return { tracks, pointers };
956
956
  }
957
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
957
+ function runtimeView(catalog, receiver) {
958
958
  const { tracks, pointers } = fecCatalogTracks(catalog);
959
959
  const report = validateFecCatalog({ tracks }, receiver);
960
960
  const at = (path) => {
961
961
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
962
962
  return m ? pointers[Number(m[1])] + m[2] : path;
963
963
  };
964
+ return { tracks, pointers, report, at };
965
+ }
966
+ function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
967
+ const { tracks, pointers, report, at } = runtimeView(catalog, receiver);
964
968
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
965
969
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
966
970
  const why = (i) => Object.freeze({
@@ -1658,8 +1662,9 @@ function keyframeIntervalMediaTicks(geometry2, mediaTimescale) {
1658
1662
  return scaled / divisor;
1659
1663
  }
1660
1664
  function compareDataUnitStarts(a, b) {
1661
- return a.movieFragment - b.movieFragment || a.idx - b.idx || a.offset - b.offset;
1665
+ return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
1662
1666
  }
1667
+ var UNPLACED = { rapNotMpuStart: false };
1663
1668
  var BlockClassifier = class {
1664
1669
  #geometry;
1665
1670
  #mode;
@@ -1682,8 +1687,23 @@ var BlockClassifier = class {
1682
1687
  #mpuSbnSpans = /* @__PURE__ */ new Map();
1683
1688
  #dataUnitStarts = /* @__PURE__ */ new Map();
1684
1689
  #highestMpu = null;
1685
- /** MPU → movie_fragment_sequence_number observed in it. */
1686
- #mpuFragments = /* @__PURE__ */ new Map();
1690
+ /**
1691
+ * P3 layout, kept for the MPUs within the classification horizon and valid
1692
+ * within one continuous SBN sequence (`noteSourceDiscontinuity`).
1693
+ */
1694
+ #mpus = /* @__PURE__ */ new Map();
1695
+ /** An MPU of this sequence showed two movie fragments: each frame is one. */
1696
+ #fragmentPerFrame = false;
1697
+ /** A DU header of this sequence stated sample_number above 1. */
1698
+ #multiSampleFragment = false;
1699
+ /**
1700
+ * The anchor received last, whether or not its MPU is still in the
1701
+ * horizon. Each new anchor, and the anchor of every DU header's MPU, is
1702
+ * checked against it.
1703
+ */
1704
+ #lastAnchor = null;
1705
+ /** Two anchors were exactly G fragments per MPU apart. */
1706
+ #fragmentsProven = false;
1687
1707
  #lastRap = null;
1688
1708
  constructor(geometry2) {
1689
1709
  this.#geometry = geometry2;
@@ -1713,7 +1733,7 @@ var BlockClassifier = class {
1713
1733
  this.#geometry = geometry2;
1714
1734
  this.#blocks.clear();
1715
1735
  this.#clearContiguityLedger();
1716
- this.#mpuFragments.clear();
1736
+ this.#clearMpuLayout();
1717
1737
  this.#lastRap = null;
1718
1738
  this.#mpuBoundsRaps = true;
1719
1739
  if (geometry2.trackKind === "video" && geometry2.mode === "all-protected") {
@@ -1747,11 +1767,13 @@ var BlockClassifier = class {
1747
1767
  /**
1748
1768
  * The stream's SBN sequence restarted (FECManager source discontinuity:
1749
1769
  * a publisher restart, or the SS_ID space wrapped). Authored order and SBN
1750
- * order are comparable only within one continuous sequence, so the P1
1751
- * ledger starts again.
1770
+ * order are comparable only within one continuous sequence, and a
1771
+ * restarted publisher numbers MPUs and movie fragments again, so the P1
1772
+ * ledger and the P3 layout start again.
1752
1773
  */
1753
1774
  noteSourceDiscontinuity() {
1754
1775
  this.#clearContiguityLedger();
1776
+ this.#clearMpuLayout();
1755
1777
  }
1756
1778
  /** Register a block that exists without evidence (a vanished block). */
1757
1779
  touch(sbn) {
@@ -1770,16 +1792,16 @@ var BlockClassifier = class {
1770
1792
  if (this.#geometry.trackKind === "audio") return [];
1771
1793
  const changes = [];
1772
1794
  const block = this.#blockFor(sbn);
1795
+ const placement = this.#place(evidence);
1773
1796
  if (evidence.rap) block.rapSeen = true;
1774
1797
  if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
1775
- if (evidence.idx !== void 0) {
1776
- block.idxMin = block.idxMin === void 0 ? evidence.idx : Math.min(block.idxMin, evidence.idx);
1777
- block.idxMax = block.idxMax === void 0 ? evidence.idx : Math.max(block.idxMax, evidence.idx);
1798
+ const { position } = placement;
1799
+ if (position !== void 0) {
1800
+ block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
1801
+ block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
1778
1802
  }
1779
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
1780
- this.#mpuBoundsRaps = false;
1781
- }
1782
- const violation = this.#checkInvariants(sbn, block, evidence);
1803
+ if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
1804
+ const violation = this.#checkInvariants(sbn, block, evidence, placement);
1783
1805
  if (violation !== null) changes.push(...this.#disable(violation));
1784
1806
  const next = this.#classify(block);
1785
1807
  if (next !== block.cls && this.#allowed(block.cls, next)) {
@@ -1832,35 +1854,89 @@ var BlockClassifier = class {
1832
1854
  }
1833
1855
  return block;
1834
1856
  }
1835
- #checkInvariants(sbn, block, evidence) {
1857
+ #checkInvariants(sbn, block, evidence, placement) {
1836
1858
  if (this.#mode === "all-protected" || this.#geometry.trackKind !== "video") return null;
1837
1859
  const geometry2 = this.#geometry;
1838
1860
  if (geometry2.mode !== "classifying") return null;
1839
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
1840
- return "rap-not-mpu-start";
1841
- }
1842
- if (evidence.idx !== void 0 && evidence.idx >= geometry2.gopFrames) {
1861
+ if (placement.rapNotMpuStart) return "rap-not-mpu-start";
1862
+ if (placement.position !== void 0 && placement.position >= geometry2.gopFrames) {
1843
1863
  return "mpu-longer-than-gop";
1844
1864
  }
1845
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0 && block.idxMax - block.idxMin >= geometry2.interleaveUnits) {
1865
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0 && block.positionMax - block.positionMin >= geometry2.interleaveUnits) {
1846
1866
  return "block-wider-than-interleave";
1847
1867
  }
1848
- if (evidence.mpu !== void 0 && evidence.movieFragment !== void 0) {
1849
- const fragment = this.#mpuFragments.get(evidence.mpu);
1850
- if (fragment === void 0) {
1851
- this.#mpuFragments.set(evidence.mpu, evidence.movieFragment);
1852
- for (const mpu of this.#mpuFragments.keys()) {
1853
- if (mpu + 1 < evidence.mpu) this.#mpuFragments.delete(mpu);
1854
- }
1855
- } else if (fragment !== evidence.movieFragment) {
1856
- return "mpu-multiple-fragments";
1857
- }
1858
- }
1868
+ if (placement.violation !== void 0) return placement.violation;
1859
1869
  if (evidence.mpu !== void 0 && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {
1860
1870
  return "block-not-contiguous";
1861
1871
  }
1862
1872
  return null;
1863
1873
  }
1874
+ /**
1875
+ * The MPU position a source symbol's DU header proves (P3), and what it
1876
+ * refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.
1877
+ */
1878
+ #place(evidence) {
1879
+ const { mpu, idx, movieFragment: fragment } = evidence;
1880
+ if (idx === void 0) return UNPLACED;
1881
+ const bySample = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 };
1882
+ if (mpu === void 0 || fragment === void 0) {
1883
+ return this.#fragmentPerFrame && !this.#multiSampleFragment ? { rapNotMpuStart: bySample.rapNotMpuStart } : bySample;
1884
+ }
1885
+ let layout = this.#mpus.get(mpu);
1886
+ if (layout === void 0) {
1887
+ layout = { low: fragment };
1888
+ this.#mpus.set(mpu, layout);
1889
+ for (const other of this.#mpus.keys()) {
1890
+ if (other + 1 < mpu) this.#mpus.delete(other);
1891
+ }
1892
+ } else if (fragment !== layout.low) {
1893
+ this.#fragmentPerFrame = true;
1894
+ if ((fragment - layout.low | 0) < 0) layout.low = fragment;
1895
+ }
1896
+ if (idx !== 0) this.#multiSampleFragment = true;
1897
+ let arrival;
1898
+ if (evidence.rap && layout.anchor === void 0) {
1899
+ layout.anchor = fragment;
1900
+ arrival = this.#anchorDrift(mpu, fragment);
1901
+ if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true;
1902
+ this.#lastAnchor = { mpu, fragment };
1903
+ }
1904
+ if (!this.#fragmentPerFrame) return bySample;
1905
+ if (this.#multiSampleFragment) return { ...bySample, violation: "mpu-multiple-fragments" };
1906
+ const { anchor } = layout;
1907
+ if (anchor === void 0) return UNPLACED;
1908
+ const drift = arrival ?? this.#anchorDrift(mpu, anchor);
1909
+ const offset = fragment - anchor | 0;
1910
+ return {
1911
+ ...offset === 0 || offset > 0 && this.#fragmentsProven ? { position: offset } : {},
1912
+ rapNotMpuStart: evidence.rap && offset !== 0 || (layout.low - anchor | 0) < 0 || // Fragments count frames: an anchor arriving past the spacing is a
1913
+ // RAP inside its MPU, or an earlier MPU outran G.
1914
+ arrival !== void 0 && arrival > 0 && this.#fragmentsProven,
1915
+ ...drift === void 0 || drift === 0 ? {} : { violation: "rap-spacing-mismatch" }
1916
+ };
1917
+ }
1918
+ /**
1919
+ * How many fragments MPU m's anchor `fragment` lies past the start that
1920
+ * the anchor received last predicts for MPU m: one frame per fragment and
1921
+ * G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')
1922
+ * fragments apart, modulo 2^32. Undefined without a last anchor, a
1923
+ * cadence, or this layout.
1924
+ */
1925
+ #anchorDrift(mpu, fragment) {
1926
+ const geometry2 = this.#geometry;
1927
+ const last = this.#lastAnchor;
1928
+ if (last === null || !this.#fragmentPerFrame || this.#multiSampleFragment || geometry2.trackKind !== "video" || geometry2.mode !== "classifying") {
1929
+ return void 0;
1930
+ }
1931
+ return fragment - last.fragment - geometry2.gopFrames * (mpu - last.mpu) | 0;
1932
+ }
1933
+ #clearMpuLayout() {
1934
+ this.#mpus.clear();
1935
+ this.#fragmentPerFrame = false;
1936
+ this.#multiSampleFragment = false;
1937
+ this.#lastAnchor = null;
1938
+ this.#fragmentsProven = false;
1939
+ }
1864
1940
  #clearContiguityLedger() {
1865
1941
  this.#mpuSbnSpans.clear();
1866
1942
  this.#dataUnitStarts.clear();
@@ -1960,9 +2036,9 @@ var BlockClassifier = class {
1960
2036
  if (this.#mode === "all-protected") return "unknown";
1961
2037
  const geometry2 = this.#geometry;
1962
2038
  if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return "unknown";
1963
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0) {
2039
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
1964
2040
  const span = geometry2.interleaveUnits - 1;
1965
- if (block.idxMax - span >= 1 && block.idxMin + span <= geometry2.gopFrames - 1) {
2041
+ if (block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1) {
1966
2042
  return "delta";
1967
2043
  }
1968
2044
  }
@@ -2259,7 +2335,8 @@ var FECManager = class _FECManager {
2259
2335
  this.#ssbLengthConflictCount = 0;
2260
2336
  this.#blockRepairRsIds = /* @__PURE__ */ new Map();
2261
2337
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
2262
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
2338
+ // symbols its repair group carries; 0 for a repair-less span no repair can
2339
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
2263
2340
  this.#blockRsbLengths = /* @__PURE__ */ new Map();
2264
2341
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
2265
2342
  this.#heldLayerStates = /* @__PURE__ */ new Map();
@@ -2447,6 +2524,7 @@ var FECManager = class _FECManager {
2447
2524
  this.#workerErrorCounts = /* @__PURE__ */ new Map();
2448
2525
  this.#decoderUnavailableEvents = 0;
2449
2526
  this.#repairSymbolSizeMismatchCount = 0;
2527
+ this.#unlistedRepairTrackRefusals = 0;
2450
2528
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
2451
2529
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
2452
2530
  // feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
@@ -2506,6 +2584,16 @@ var FECManager = class _FECManager {
2506
2584
  this.onBlockResolved = null;
2507
2585
  /** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
2508
2586
  this.onSourceDiscontinuity = null;
2587
+ /**
2588
+ * The span and tolerance the catalog states for a keyframe overlay
2589
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
2590
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
2591
+ * undefined while none is installed. A stated block only a late source
2592
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
2593
+ * late source can fill, also wait for that overlay's repair
2594
+ * (#overlayLateWaitMs).
2595
+ */
2596
+ this.keyframeOverlayTiming = null;
2509
2597
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
2510
2598
  /**
2511
2599
  * A recovered source symbol. Return false when admission refused the
@@ -2610,6 +2698,7 @@ var FECManager = class _FECManager {
2610
2698
  #workerErrorCounts;
2611
2699
  #decoderUnavailableEvents;
2612
2700
  #repairSymbolSizeMismatchCount;
2701
+ #unlistedRepairTrackRefusals;
2613
2702
  #onUndelimitedLoss;
2614
2703
  #onIsoHoleExpired;
2615
2704
  #encodeTrackName(catalogTrackName) {
@@ -3778,6 +3867,7 @@ var FECManager = class _FECManager {
3778
3867
  packetId
3779
3868
  })),
3780
3869
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
3870
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
3781
3871
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
3782
3872
  workerErrors: Object.fromEntries(this.#workerErrorCounts)
3783
3873
  };
@@ -4282,8 +4372,10 @@ var FECManager = class _FECManager {
4282
4372
  }
4283
4373
  /**
4284
4374
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
4285
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
4286
- * Undefined for a block that is not open.
4375
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
4376
+ * repair-less span states its length, and RSB_length 0 when it is longer
4377
+ * than K, since no repair can reach it). Undefined for a block that is not
4378
+ * open.
4287
4379
  */
4288
4380
  blockSymbolCounts(sbn, packetId, catalogTrackName) {
4289
4381
  const key = this.#blockKey(sbn, packetId, catalogTrackName);
@@ -4399,7 +4491,7 @@ var FECManager = class _FECManager {
4399
4491
  }
4400
4492
  const trackConfig = this.#trackConfigs.get(packetId);
4401
4493
  if (trackConfig === void 0) return void 0;
4402
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig));
4494
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
4403
4495
  }
4404
4496
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
4405
4497
  // -----------------------------------------------------------------------
@@ -4585,12 +4677,24 @@ var FECManager = class _FECManager {
4585
4677
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
4586
4678
  * SS_ID of which vanished resolves through its deadline like any vanished
4587
4679
  * block.
4680
+ *
4681
+ * A span longer than K holds more than one block (SSB_length <= K), and the
4682
+ * locator states no block inside a span, only one exactly its range
4683
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
4684
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
4685
+ * Group of it (group-cannot-complete). Every span still keeps its whole
4686
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
4687
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
4688
+ * gate lets those frames go once only a late source can fill the gap
4689
+ * before them, as long after they arrived as the gap's decision allows
4690
+ * (isoRepairlessWaitMs).
4588
4691
  */
4589
4692
  #openIsoSpan(span, packetId, catalogTrackName) {
4590
4693
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
4591
4694
  if (!this.#blockAuthoredLengths.has(key)) {
4592
4695
  this.#blockAuthoredLengths.set(key, span.block.length);
4593
4696
  this.#isoSpanKeys.add(key);
4697
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
4594
4698
  }
4595
4699
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
4596
4700
  }
@@ -4629,6 +4733,62 @@ var FECManager = class _FECManager {
4629
4733
  }
4630
4734
  return lost;
4631
4735
  }
4736
+ /**
4737
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
4738
+ * between two released frames' SS_IDs once only a late source can still
4739
+ * fill them, else undefined. That is when every one missing (neither
4740
+ * arrived nor held) lies in a repair-less span longer than K, which no
4741
+ * repair can state a block of (#openIsoSpan), or in a stated block its
4742
+ * own repair group cannot complete every SS_ID of which it misses lies
4743
+ * between them (so the gap's decision covers all it lost), and a multicast
4744
+ * source at or past `toSsId` arrived, so each is lost or reordered behind
4745
+ * it (a MoQ source shows nothing: MoQ streams overtake one another). The
4746
+ * span or block itself keeps its own wait.
4747
+ *
4748
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
4749
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
4750
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
4751
+ * Then the frame waits as a stated block its group cannot complete does
4752
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
4753
+ * overlay's span plus the larger of the allowance and its tolerance, or,
4754
+ * for an overlay that states no span, the span's whole wait (undefined).
4755
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
4756
+ * the gap holds a stated block's loss.
4757
+ */
4758
+ isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false) {
4759
+ const config = this.#trackConfigs.get(packetId);
4760
+ if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
4761
+ const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
4762
+ if (locator === void 0 || !locator.coversBetween(fromSsId, toSsId)) return void 0;
4763
+ const newestSource = locator.newestSource;
4764
+ if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
4765
+ let repairless = false;
4766
+ let stated = false;
4767
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
4768
+ const key = this.#blockKey(block.start, packetId, catalogTrackName);
4769
+ if (this.#completedBlocks.has(key)) continue;
4770
+ if (block.span && block.length > locator.kMax) {
4771
+ repairless = true;
4772
+ continue;
4773
+ }
4774
+ const received = this.#blockSourceEsis.get(key);
4775
+ const rebuilt = this.#blockRebuiltEsis.get(key);
4776
+ let missesInGap = false;
4777
+ let missesOutside = false;
4778
+ for (let esi = 0; esi < block.length; esi++) {
4779
+ const ssId = serial32Add(block.start, esi);
4780
+ if (received?.has(esi) || locator.isHeld(ssId)) continue;
4781
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
4782
+ else if (!rebuilt?.has(esi)) missesOutside = true;
4783
+ }
4784
+ if (!missesInGap) continue;
4785
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
4786
+ repairless = stated = true;
4787
+ }
4788
+ if (!repairless) return void 0;
4789
+ const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
4790
+ return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
4791
+ }
4632
4792
  /**
4633
4793
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
4634
4794
  * the sources held now for a block no repair has stated yet, and the held
@@ -5277,7 +5437,10 @@ var FECManager = class _FECManager {
5277
5437
  this.#layerAnchorHorizon(packetId),
5278
5438
  this.#sourceFrontiers.get(streamKey)?.sbn
5279
5439
  );
5280
- if (verdict === "discard") return false;
5440
+ if (verdict === "discard") {
5441
+ this.#unlistedRepairTrackRefusals++;
5442
+ return false;
5443
+ }
5281
5444
  if (verdict !== void 0) {
5282
5445
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
5283
5446
  return false;
@@ -5434,7 +5597,7 @@ var FECManager = class _FECManager {
5434
5597
  const previous = locator.newestSource;
5435
5598
  if (!locator.noteSource(ssId) || previous === void 0) return;
5436
5599
  for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
5437
- if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
5600
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
5438
5601
  this.#shortenUnrecoverableWait(
5439
5602
  this.#blockKey(block.start, packetId, catalogTrackName),
5440
5603
  block.start,
@@ -5452,21 +5615,61 @@ var FECManager = class _FECManager {
5452
5615
  * covers repair symbols paced after its sources, buys it nothing: it waits
5453
5616
  * the late-symbol allowance alone, the multicast wait less the span (the
5454
5617
  * catalog tolerance or the measured delivery gap). Undefined for any other
5455
- * block.
5618
+ * block. While a keyframe overlay is installed, the block waits for its
5619
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
5620
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
5621
+ * resolution is what releases the frames behind it, and failing it early
5622
+ * released them past a keyframe the overlay was still rebuilding, which
5623
+ * then arrived stale. The release gate lets them go instead
5624
+ * (isoRepairlessWaitMs).
5456
5625
  */
5457
5626
  #lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
5627
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
5458
5628
  const authoredLength = this.#blockAuthoredLengths.get(key);
5459
- const rsbLength = this.#blockRsbLengths.get(key);
5460
- if (authoredLength === void 0 || rsbLength === void 0) return void 0;
5461
- let present = this.#blockSourceCounts.get(key) ?? 0;
5462
- const received = this.#blockSourceEsis.get(key);
5463
- for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
5464
- if (present + rsbLength >= authoredLength) return void 0;
5465
5629
  const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
5466
5630
  if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
5467
5631
  return void 0;
5468
5632
  }
5469
- return this.#multicastWaitMs(config) - config.interleaveDepthMs;
5633
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
5634
+ }
5635
+ /**
5636
+ * A repair stated the block, and its sources plus every symbol its repair
5637
+ * group carries (RSB_length) are short of its SSB_length.
5638
+ */
5639
+ #groupCannotComplete(key) {
5640
+ const authoredLength = this.#blockAuthoredLengths.get(key);
5641
+ const rsbLength = this.#blockRsbLengths.get(key);
5642
+ if (authoredLength === void 0 || rsbLength === void 0) return false;
5643
+ let present = this.#blockSourceCounts.get(key) ?? 0;
5644
+ const received = this.#blockSourceEsis.get(key);
5645
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
5646
+ return present + rsbLength < authoredLength;
5647
+ }
5648
+ /**
5649
+ * How long a loss only a late source or an installed keyframe overlay can
5650
+ * still fill waits once a later source passed it: the late-symbol
5651
+ * allowance alone (the multicast wait less the span) while no overlay is
5652
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
5653
+ * RAP packet the loss took: a second FEC instance over the same packets
5654
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
5655
+ * span, unrelated to the base's. That packet can complete a stated block
5656
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
5657
+ * first lets the release gate pass the keyframe, whose rebuild then lands
5658
+ * stale. The overlay repair of a packet the loss took goes out within the
5659
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
5660
+ * sent after it, so the loss waits that span plus the larger of the
5661
+ * allowance and the overlay's own tolerance. An overlay that states no
5662
+ * span (its block may then span keyframes), or one whose wait is not
5663
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
5664
+ */
5665
+ #overlayLateWaitMs(packetId, catalogTrackName, config) {
5666
+ const waitMs = this.#multicastWaitMs(config);
5667
+ const allowanceMs = waitMs - config.interleaveDepthMs;
5668
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
5669
+ if (overlay === void 0) return allowanceMs;
5670
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
5671
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
5672
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
5470
5673
  }
5471
5674
  /**
5472
5675
  * Bring an open block's wait in to its late-source wait, when it has one.
@@ -10616,9 +10819,10 @@ function isH264IntraSlice(nal) {
10616
10819
  const sliceType = readH264SliceType(nal);
10617
10820
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
10618
10821
  }
10822
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
10619
10823
  function readH264SliceType(nal) {
10620
10824
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
10621
- const rbsp = removeEmulationPrevention(nal.subarray(1));
10825
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
10622
10826
  const state = { bitOffset: 0 };
10623
10827
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
10624
10828
  return readUnsignedExpGolomb(rbsp, state);
@@ -10765,6 +10969,96 @@ if (void 0) {
10765
10969
  ]))).toBe(false);
10766
10970
  });
10767
10971
  });
10972
+ describe("readH264SliceType", () => {
10973
+ const wholeNalSliceType = (nal) => {
10974
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
10975
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
10976
+ const state = { bitOffset: 0 };
10977
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
10978
+ return readUnsignedExpGolomb(rbsp, state);
10979
+ };
10980
+ const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
10981
+ const ue = (value) => {
10982
+ const code = (value + 1).toString(2);
10983
+ return "0".repeat(code.length - 1) + code;
10984
+ };
10985
+ const sliceNal = (bits) => {
10986
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
10987
+ const nal = [1];
10988
+ let zeros = 0;
10989
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
10990
+ if (zeros >= 2 && byte <= 3) {
10991
+ nal.push(3);
10992
+ zeros = 0;
10993
+ }
10994
+ nal.push(byte);
10995
+ zeros = byte === 0 ? zeros + 1 : 0;
10996
+ }
10997
+ return Uint8Array.from(nal);
10998
+ };
10999
+ const x264Slices = [
11000
+ ["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
11001
+ ["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
11002
+ ["64x48 non-IDR I", hex2(
11003
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
11004
+ ), 7, true],
11005
+ ["1280x720 B, escape at byte 10", hex2(
11006
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
11007
+ ), 6, false],
11008
+ ["1280x720 P, escape at byte 15", hex2(
11009
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
11010
+ ), 5, false],
11011
+ ["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
11012
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex2(
11013
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
11014
+ ), null, true],
11015
+ ["7680x4320 P, first_mb_in_slice 32640", hex2(
11016
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
11017
+ ), 5, false],
11018
+ ["7680x4320 P, first_mb_in_slice 97440", hex2(
11019
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
11020
+ ), 5, false]
11021
+ ];
11022
+ const syntheticSlices = [
11023
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
11024
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
11025
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
11026
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
11027
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
11028
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
11029
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
11030
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
11031
+ ];
11032
+ test("reads the slice_type of real and synthetic slices", () => {
11033
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
11034
+ expect(readH264SliceType(nal), name).toBe(sliceType);
11035
+ }
11036
+ });
11037
+ test("matches the whole-NAL unescape at every truncation", () => {
11038
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
11039
+ for (let end = 0; end <= nal.length; end++) {
11040
+ const cut = nal.subarray(0, end);
11041
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
11042
+ }
11043
+ }
11044
+ });
11045
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
11046
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
11047
+ let seed = 1;
11048
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
11049
+ for (let i = 0; i < 5e3; i++) {
11050
+ const nal = new Uint8Array(2 + next() % 63);
11051
+ nal[0] = 65;
11052
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
11053
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
11054
+ }
11055
+ });
11056
+ test("classifies the x264 slices as keyframes or not", () => {
11057
+ for (const [name, nal, , keyframe] of x264Slices) {
11058
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
11059
+ }
11060
+ });
11061
+ });
10768
11062
  describe("avccToAnnexB", () => {
10769
11063
  test("converts with SPS/PPS on keyframe", () => {
10770
11064
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -14118,7 +14412,7 @@ var FecReleaseSequencer = class {
14118
14412
  from
14119
14413
  );
14120
14414
  unresolved = resolved === null;
14121
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
14415
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
14122
14416
  const heldMs = performance.now() - head.arrivedAtMs;
14123
14417
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
14124
14418
  this.#recordStat("forcedWindowFlushes");
@@ -14136,6 +14430,19 @@ var FecReleaseSequencer = class {
14136
14430
  );
14137
14431
  }
14138
14432
  }
14433
+ /**
14434
+ * The head has waited out a gap only a late source can still fill
14435
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
14436
+ * the stream when it has (`wakeAt`), since no packet may come by then.
14437
+ */
14438
+ #unrepairableWaitOver(stream, last, head, from, to) {
14439
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
14440
+ if (waitMs === void 0) return false;
14441
+ const atMs = head.arrivedAtMs + waitMs;
14442
+ if (performance.now() >= atMs) return true;
14443
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
14444
+ return false;
14445
+ }
14139
14446
  /**
14140
14447
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
14141
14448
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -18716,6 +19023,8 @@ var MmtpRouter = class {
18716
19023
  // end: a synchronous recovery completes its block BEFORE routing the
18717
19024
  // recovered frames, and releasing a held gap in between would strand them.
18718
19025
  #fecPokeDepth = 0;
19026
+ /** FecReleaseGate.wakeAt timers, by media stream key. */
19027
+ #fecWakes = /* @__PURE__ */ new Map();
18719
19028
  #pendingFecPokes = /* @__PURE__ */ new Map();
18720
19029
  // ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
18721
19030
  /** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
@@ -20776,6 +21085,8 @@ var MmtpRouter = class {
20776
21085
  this.#disposed = true;
20777
21086
  this.#staged = null;
20778
21087
  this.cancelKeyframeLostTimer();
21088
+ for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
21089
+ this.#fecWakes.clear();
20779
21090
  this.#parser.dispose();
20780
21091
  this.#streams.clear();
20781
21092
  this.#trackPacketCallbacks.clear();
@@ -20957,6 +21268,31 @@ var MmtpRouter = class {
20957
21268
  if (!fec?.terminalRetentionMsForPacket) return Infinity;
20958
21269
  return fec.terminalRetentionMsForPacket(packetId) ?? 0;
20959
21270
  },
21271
+ // Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
21272
+ // late source can), its frame waits the late-symbol allowance when the
21273
+ // gap holds no RAP an installed keyframe overlay could still rebuild:
21274
+ // lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
21275
+ // that opens the next one while MPU boundaries bound RAPs (rap-next,
21276
+ // unless the gap holds a stated block's loss: the overlay may rebuild
21277
+ // that MPU's FT=0, and the block's group then complete it), or
21278
+ // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
21279
+ // other rap-next, whose gap may hold a whole MPU and the keyframe the
21280
+ // overlay protects) waits for that overlay's repair too (BLO-52085
21281
+ // D4). The FEC check comes first: most held gaps are not behind such a
21282
+ // span, and deciding one scans both frames' bitstreams.
21283
+ unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
21284
+ const fec = this.#fecManager;
21285
+ const { packetId, catalogTrackName } = after.meta;
21286
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
21287
+ if (!fec || allowanceMs === void 0) return void 0;
21288
+ const decision = this.#decideGap(before, after, [], false);
21289
+ const mpu = before.meta.mpuSequenceNumber;
21290
+ const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
21291
+ if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
21292
+ return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
21293
+ }
21294
+ return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
21295
+ },
20960
21296
  decide: (before, after, lostBlocks, discontinuity) => {
20961
21297
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
20962
21298
  this.#onFrameGap?.(decision);
@@ -20966,6 +21302,20 @@ var MmtpRouter = class {
20966
21302
  onRap: (packetId, catalogTrackName, ssId) => {
20967
21303
  for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
20968
21304
  },
21305
+ // One timer per stream, at the earliest wake asked: its drain re-arms
21306
+ // for the next frame still waiting.
21307
+ wakeAt: (packetId, catalogTrackName, atMs) => {
21308
+ if (this.#disposed) return;
21309
+ const key = this.#mediaStreamKey(packetId, catalogTrackName);
21310
+ const armed = this.#fecWakes.get(key);
21311
+ if (armed !== void 0 && armed.atMs <= atMs) return;
21312
+ if (armed !== void 0) clearTimeout(armed.timer);
21313
+ const timer = setTimeout(() => {
21314
+ this.#fecWakes.delete(key);
21315
+ this.#requestFecPoke(packetId, catalogTrackName);
21316
+ }, Math.max(0, Math.ceil(atMs - performance.now())));
21317
+ this.#fecWakes.set(key, { atMs, timer });
21318
+ },
20969
21319
  // A staged switch commits on when each side's frames reach it
20970
21320
  // (#interceptSwitchFrame): both sides' overlay keyframes reach it when
20971
21321
  // they did unanchored.
@@ -21001,7 +21351,7 @@ var MmtpRouter = class {
21001
21351
  #decideGap(before, after, lostBlocks, discontinuity) {
21002
21352
  const { packetId, catalogTrackName } = after.meta;
21003
21353
  const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
21004
- const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying";
21354
+ const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" && before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
21005
21355
  const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
21006
21356
  const evidence = (frame) => {
21007
21357
  const timing = frame.meta.authoredTiming;
@@ -23845,6 +24195,11 @@ var MulticastManager = class {
23845
24195
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
23846
24196
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
23847
24197
  };
24198
+ this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
24199
+ const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
24200
+ if (binding === void 0) return void 0;
24201
+ return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
24202
+ };
23848
24203
  this.#fec.onDecoderUnavailable = (event) => {
23849
24204
  this.#emitRepairLifecycle({
23850
24205
  version: 2,
@@ -24532,7 +24887,7 @@ var MulticastManager = class {
24532
24887
  console.warn("[MulticastManager] repair group release failed", error);
24533
24888
  }
24534
24889
  };
24535
- const usedFlows = /* @__PURE__ */ new Set();
24890
+ const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
24536
24891
  const preparedProvenance = endpoints.map((endpoint) => {
24537
24892
  if (endpoint.provenance === void 0) return void 0;
24538
24893
  const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
@@ -25091,7 +25446,8 @@ var MulticastManager = class {
25091
25446
  blockProfile: parseFecBlockProfile(
25092
25447
  geometry2.blockProfile,
25093
25448
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
25094
- )
25449
+ ),
25450
+ geometry: geometry2
25095
25451
  });
25096
25452
  }
25097
25453
  }
@@ -25130,7 +25486,7 @@ var MulticastManager = class {
25130
25486
  for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
25131
25487
  const before = this.#overlayBindings.get(sourcePacketId);
25132
25488
  const after = overlayBindings.get(sourcePacketId);
25133
- const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
25489
+ const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
25134
25490
  if (!same) install.dispose();
25135
25491
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
25136
25492
  else install.reattach();