@blockcast/mmt-container 2.2.0-main.cc080e5a56f2 → 2.2.0-main.cc3fe0684403

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 (137) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +88 -16
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +164 -56
  5. package/dist/block-policy.js.map +3 -3
  6. package/dist/browser-runtime.js +1485 -172
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +40 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +163 -10
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +48 -1
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.js +34 -0
  17. package/dist/catalog-network-source.js.map +3 -3
  18. package/dist/cmaf-block-assembler.js +92 -1
  19. package/dist/cmaf-block-assembler.js.map +2 -2
  20. package/dist/codec-utils.d.ts.map +1 -1
  21. package/dist/codec-utils.js +92 -1
  22. package/dist/codec-utils.js.map +2 -2
  23. package/dist/datagram-leg-deadline.d.ts +118 -0
  24. package/dist/datagram-leg-deadline.d.ts.map +1 -0
  25. package/dist/datagram-leg-deadline.js +217 -0
  26. package/dist/datagram-leg-deadline.js.map +7 -0
  27. package/dist/delivery-catalog.js +68 -0
  28. package/dist/delivery-catalog.js.map +4 -4
  29. package/dist/delta-fallback-config.js +39 -1
  30. package/dist/delta-fallback-config.js.map +4 -4
  31. package/dist/fec-manager.d.ts +155 -10
  32. package/dist/fec-manager.d.ts.map +1 -1
  33. package/dist/fec-manager.js +596 -81
  34. package/dist/fec-manager.js.map +4 -4
  35. package/dist/fec-state.d.ts +17 -5
  36. package/dist/fec-state.d.ts.map +1 -1
  37. package/dist/fec-state.js +41 -1
  38. package/dist/fec-state.js.map +3 -3
  39. package/dist/fec-worker-setup.js +34 -0
  40. package/dist/fec-worker-setup.js.map +3 -3
  41. package/dist/held-layer-admission.js +34 -0
  42. package/dist/held-layer-admission.js.map +3 -3
  43. package/dist/index.d.ts +7 -5
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +15 -1
  46. package/dist/index.js.map +2 -2
  47. package/dist/iso-block-locator.d.ts +16 -0
  48. package/dist/iso-block-locator.d.ts.map +1 -1
  49. package/dist/iso-block-locator.js +62 -0
  50. package/dist/iso-block-locator.js.map +3 -3
  51. package/dist/mfu-reassembler.js +34 -0
  52. package/dist/mfu-reassembler.js.map +3 -3
  53. package/dist/mmtp-container-parser.d.ts +30 -2
  54. package/dist/mmtp-container-parser.d.ts.map +1 -1
  55. package/dist/mmtp-container-parser.js +140 -2
  56. package/dist/mmtp-container-parser.js.map +3 -3
  57. package/dist/mmtp-container-parser.no-modules.js +293 -18
  58. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  59. package/dist/mmtp-decode-pipeline.js +140 -2
  60. package/dist/mmtp-decode-pipeline.js.map +3 -3
  61. package/dist/mmtp-fec-session.js +34 -0
  62. package/dist/mmtp-fec-session.js.map +3 -3
  63. package/dist/mmtp-mode-selection.d.ts +48 -0
  64. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  65. package/dist/mmtp-mode-selection.js +79 -0
  66. package/dist/mmtp-mode-selection.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +66 -8
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +348 -27
  70. package/dist/mmtp-router.js.map +4 -4
  71. package/dist/multicast-auth-catalog.js +42 -2
  72. package/dist/multicast-auth-catalog.js.map +3 -3
  73. package/dist/multicast-input.js +42 -2
  74. package/dist/multicast-input.js.map +3 -3
  75. package/dist/multicast-manager.d.ts +108 -1
  76. package/dist/multicast-manager.d.ts.map +1 -1
  77. package/dist/multicast-manager.js +1067 -138
  78. package/dist/multicast-manager.js.map +4 -4
  79. package/dist/multicast-transport.js +68 -0
  80. package/dist/multicast-transport.js.map +4 -4
  81. package/dist/multicast-unwrap.js +34 -0
  82. package/dist/multicast-unwrap.js.map +3 -3
  83. package/dist/no-modules.d.ts +1 -0
  84. package/dist/no-modules.d.ts.map +1 -1
  85. package/dist/no-modules.js +295 -19
  86. package/dist/no-modules.js.map +4 -4
  87. package/dist/phase14-catalog-override.d.ts +2 -1
  88. package/dist/phase14-catalog-override.d.ts.map +1 -1
  89. package/dist/phase14-catalog-override.js +69 -2
  90. package/dist/phase14-catalog-override.js.map +3 -3
  91. package/dist/repair-fetch.d.ts.map +1 -1
  92. package/dist/repair-fetch.js +50 -0
  93. package/dist/repair-fetch.js.map +3 -3
  94. package/dist/repair-layer-subscriptions.js +34 -0
  95. package/dist/repair-layer-subscriptions.js.map +3 -3
  96. package/dist/signaling.js +34 -0
  97. package/dist/signaling.js.map +3 -3
  98. package/dist/timestamp-codec.js +34 -0
  99. package/dist/timestamp-codec.js.map +3 -3
  100. package/dist/wasm-mfu-reassembler.js +34 -0
  101. package/dist/wasm-mfu-reassembler.js.map +3 -3
  102. package/dist/wasm-mmtp-container-parser.js +140 -2
  103. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  104. package/package.json +5 -5
  105. package/schemas/catalog.schema.json +2 -2
  106. package/src/block-policy.ts +324 -83
  107. package/src/carp-catalog.ts +165 -5
  108. package/src/catalog-fec-params.ts +1 -0
  109. package/src/codec-utils.ts +121 -1
  110. package/src/datagram-leg-deadline.ts +342 -0
  111. package/src/fec-manager.ts +534 -41
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +38 -0
  114. package/src/iso-block-locator.ts +34 -0
  115. package/src/mmtp-container-parser.ts +57 -11
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +287 -42
  118. package/src/multicast-manager.ts +218 -10
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +23 -0
  122. package/test-vectors/catalog/README.md +36 -2
  123. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  124. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  127. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  128. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  130. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  131. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  134. package/test-vectors/catalog/section-codes.json +3 -3
  135. package/test-vectors/catalog-timing.json +559 -1
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -311,6 +311,40 @@ var RUNTIME_FEC_RECEIVER = Object.freeze({
311
311
  overlays: true
312
312
  });
313
313
 
314
+ // ../mmt-base/dist/mmtp-siblings.js
315
+ var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
316
+ var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
317
+ "namespace",
318
+ "timescale",
319
+ "presentationAnchorTicks",
320
+ "groupDuration"
321
+ ]);
322
+ var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
323
+ "codec",
324
+ "width",
325
+ "height",
326
+ "framerate",
327
+ "bitrate",
328
+ "samplerate",
329
+ "channelConfig",
330
+ "lang"
331
+ ]);
332
+ var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
333
+ "initRef",
334
+ "keyframeIntervalMs",
335
+ "keyframeIntervalTicks",
336
+ "isLive",
337
+ "altGroup"
338
+ ]);
339
+
340
+ // ../mmt-base/dist/datagram-leg-size.js
341
+ var DATAGRAM_LEG_UDP_FLOOR = 1200;
342
+ var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
343
+ var DATAGRAM_LEG_OBJECT_HEADER = 13;
344
+ var DATAGRAM_LEG_RELAY_ROOM = 16;
345
+ var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
346
+ var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
347
+
314
348
  // src/iso-block-locator.ts
315
349
  var IsoBlockLocator = class _IsoBlockLocator {
316
350
  /**
@@ -506,6 +540,34 @@ var IsoBlockLocator = class _IsoBlockLocator {
506
540
  isHeld(ssId) {
507
541
  return this.#held.has(ssId);
508
542
  }
543
+ /** The payload held unplaced for `ssId`, if any. */
544
+ heldSource(ssId) {
545
+ return this.#held.get(ssId);
546
+ }
547
+ /**
548
+ * The SS_IDs strictly between `a` and `b` that no repair has delimited a
549
+ * block of yet: those from the coverage end on, or all of them before the
550
+ * first repair. `missing` is the highest of them no source is held for;
551
+ * absent, every one of them arrived (C.5.2: SS_IDs are consecutive). Null
552
+ * when none lies past coverage. `flagged` is whether a source held among
553
+ * them satisfies `flag` (a RAP fragment, say): the held packets read as
554
+ * fec-multicast-00 Block Classification item 1 reads bounding packets.
555
+ */
556
+ undelimitedBetween(a, b, flag) {
557
+ if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return null;
558
+ const first = a + 1 >>> 0;
559
+ const end = this.#coverageEnd;
560
+ const start = end !== void 0 && serial32Precedes(first, end) ? end : first;
561
+ if (!serial32Precedes(start, b)) return null;
562
+ const length = serial32Distance(start, b);
563
+ const missing = this.#highestMissing(start, length);
564
+ let flagged = false;
565
+ for (let i = 0; flag !== void 0 && !flagged && i < length; i++) {
566
+ const payload = this.#held.get(serial32Add(start, i));
567
+ flagged = payload !== void 0 && flag(payload);
568
+ }
569
+ return missing === void 0 ? { start, flagged } : { start, missing, flagged };
570
+ }
509
571
  /**
510
572
  * Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
511
573
  * block states its range and places every held source in it; later repair
@@ -721,7 +783,7 @@ var INACTIVE = Object.freeze({
721
783
  // src/block-policy.ts
722
784
  import { deriveFecInterleaveDepth } from "@blockcast/mmt-fec";
723
785
  function keyframeIntervalMediaTicks(geometry, mediaTimescale) {
724
- if (geometry.trackKind !== "video" || geometry.mode !== "classifying") return null;
786
+ if (geometry.trackKind !== "video" || geometry.keyframeInterval === void 0) return null;
725
787
  if (!Number.isSafeInteger(mediaTimescale) || mediaTimescale <= 0) return null;
726
788
  const { ticks, timescale } = geometry.keyframeInterval;
727
789
  if (!Number.isSafeInteger(ticks) || !Number.isSafeInteger(timescale)) return null;
@@ -730,9 +792,15 @@ function keyframeIntervalMediaTicks(geometry, mediaTimescale) {
730
792
  if (scaled % divisor !== 0n) return null;
731
793
  return scaled / divisor;
732
794
  }
795
+ function keyframeInstantBetween(start, interval, from, to) {
796
+ const k = from >= start ? (from - start) / interval + 1n : 1n;
797
+ return start + k * interval <= to;
798
+ }
733
799
  function compareDataUnitStarts(a, b) {
734
- return a.movieFragment - b.movieFragment || a.idx - b.idx || a.offset - b.offset;
800
+ return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
735
801
  }
802
+ var LATE_RAP_MAX_MPUS_BACK = 64;
803
+ var UNPLACED = { rapNotMpuStart: false };
736
804
  var BlockClassifier = class {
737
805
  #geometry;
738
806
  #mode;
@@ -755,8 +823,24 @@ var BlockClassifier = class {
755
823
  #mpuSbnSpans = /* @__PURE__ */ new Map();
756
824
  #dataUnitStarts = /* @__PURE__ */ new Map();
757
825
  #highestMpu = null;
758
- /** MPU → movie_fragment_sequence_number observed in it. */
759
- #mpuFragments = /* @__PURE__ */ new Map();
826
+ /**
827
+ * P3 layout, kept for the MPUs within the classification horizon and valid
828
+ * within one continuous SBN sequence (`noteSourceDiscontinuity`).
829
+ */
830
+ #mpus = /* @__PURE__ */ new Map();
831
+ /** An MPU of this sequence showed two movie fragments: each frame is one. */
832
+ #fragmentPerFrame = false;
833
+ /** A DU header of this sequence stated sample_number above 1. */
834
+ #multiSampleFragment = false;
835
+ /**
836
+ * The anchor received last, whether or not its MPU is still in the
837
+ * horizon. Each new anchor, and the anchor of every DU header's MPU, is
838
+ * checked against it.
839
+ */
840
+ #lastAnchor = null;
841
+ /** Two anchors were exactly G fragments per MPU apart. */
842
+ #fragmentsProven = false;
843
+ /** The first RAP released of the latest MPU a RAP was released in, recorded in every mode. */
760
844
  #lastRap = null;
761
845
  constructor(geometry) {
762
846
  this.#geometry = geometry;
@@ -786,7 +870,7 @@ var BlockClassifier = class {
786
870
  this.#geometry = geometry;
787
871
  this.#blocks.clear();
788
872
  this.#clearContiguityLedger();
789
- this.#mpuFragments.clear();
873
+ this.#clearMpuLayout();
790
874
  this.#lastRap = null;
791
875
  this.#mpuBoundsRaps = true;
792
876
  if (geometry.trackKind === "video" && geometry.mode === "all-protected") {
@@ -820,11 +904,14 @@ var BlockClassifier = class {
820
904
  /**
821
905
  * The stream's SBN sequence restarted (FECManager source discontinuity:
822
906
  * a publisher restart, or the SS_ID space wrapped). Authored order and SBN
823
- * order are comparable only within one continuous sequence, so the P1
824
- * ledger starts again.
907
+ * order are comparable only within one continuous sequence, and a
908
+ * restarted publisher numbers MPUs and movie fragments again, so the P1
909
+ * ledger and the P3 layout start again.
825
910
  */
826
911
  noteSourceDiscontinuity() {
827
912
  this.#clearContiguityLedger();
913
+ this.#clearMpuLayout();
914
+ this.#lastRap = null;
828
915
  }
829
916
  /** Register a block that exists without evidence (a vanished block). */
830
917
  touch(sbn) {
@@ -843,16 +930,16 @@ var BlockClassifier = class {
843
930
  if (this.#geometry.trackKind === "audio") return [];
844
931
  const changes = [];
845
932
  const block = this.#blockFor(sbn);
933
+ const placement = this.#place(evidence);
846
934
  if (evidence.rap) block.rapSeen = true;
847
935
  if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
848
- if (evidence.idx !== void 0) {
849
- block.idxMin = block.idxMin === void 0 ? evidence.idx : Math.min(block.idxMin, evidence.idx);
850
- block.idxMax = block.idxMax === void 0 ? evidence.idx : Math.max(block.idxMax, evidence.idx);
851
- }
852
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
853
- this.#mpuBoundsRaps = false;
936
+ const { position } = placement;
937
+ if (position !== void 0) {
938
+ block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
939
+ block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
854
940
  }
855
- const violation = this.#checkInvariants(sbn, block, evidence);
941
+ if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
942
+ const violation = this.#checkInvariants(sbn, block, evidence, placement);
856
943
  if (violation !== null) changes.push(...this.#disable(violation));
857
944
  const next = this.#classify(block);
858
945
  if (next !== block.cls && this.#allowed(block.cls, next)) {
@@ -877,18 +964,35 @@ var BlockClassifier = class {
877
964
  * RAP-bearing block is the one a wrong G calls delta), because the next
878
965
  * released RAP then belongs to m+2. Every MPU is one interval long, so the
879
966
  * span to any later released RAP proves or refutes all MPUs in between.
967
+ *
968
+ * In every mode it keeps each MPU's first released RAP, with its decode
969
+ * time, as the start keyframeFreeBetween measures the catalog interval
970
+ * from, and a second RAP released inside one MPU refutes `mpuBoundsRaps`
971
+ * when it lies off the catalog lattice (not a whole number of intervals
972
+ * after the first; draft-ramadan-moq-mmt-02 4.4.3 binds every keyframe to
973
+ * it): with no repair, released RAPs are the only evidence of where they
974
+ * lie. Without a usable interval, or a decode time on either, any second
975
+ * RAP with another presentation time refutes.
880
976
  */
881
- noteReleasedRap(mpu, presentationTime, mediaTimescale) {
882
- if (this.#geometry.trackKind === "audio" || this.#mode === "all-protected") {
883
- return [];
884
- }
885
- const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
886
- if (interval === null) return this.#disable("keyframe-interval-not-media-integral");
977
+ noteReleasedRap(mpu, presentationTime, mediaTimescale, decodeTime) {
978
+ if (this.#geometry.trackKind === "audio") return [];
887
979
  const previous = this.#lastRap;
888
980
  if (previous !== null && previous.mpu === mpu && previous.mediaTimescale === mediaTimescale) {
981
+ if (presentationTime === previous.presentationTime) return [];
982
+ const interval2 = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
983
+ if (interval2 === null || decodeTime === void 0 || previous.decodeTime === void 0 || (decodeTime - previous.decodeTime) % interval2 !== 0n) {
984
+ this.#mpuBoundsRaps = false;
985
+ }
889
986
  return [];
890
987
  }
891
- this.#lastRap = { mpu, presentationTime, mediaTimescale };
988
+ if (previous !== null && previous.mediaTimescale === mediaTimescale) {
989
+ const back = previous.mpu - mpu >>> 0;
990
+ if (back !== 0 && back <= LATE_RAP_MAX_MPUS_BACK && presentationTime < previous.presentationTime) return [];
991
+ }
992
+ this.#lastRap = { mpu, presentationTime, mediaTimescale, ...decodeTime === void 0 ? {} : { decodeTime } };
993
+ if (this.#mode === "all-protected") return [];
994
+ const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
995
+ if (interval === null) return this.#disable("keyframe-interval-not-media-integral");
892
996
  if (previous === null || mpu < previous.mpu || previous.mediaTimescale !== mediaTimescale) {
893
997
  return [];
894
998
  }
@@ -897,6 +1001,22 @@ var BlockClassifier = class {
897
1001
  }
898
1002
  return this.#disable("rap-spacing-mismatch");
899
1003
  }
1004
+ /**
1005
+ * Whether a gap inside MPU `mpu`, between the decode times `from` and `to`
1006
+ * of the frames on either side, holds no keyframe: MPU boundaries still
1007
+ * bound RAPs, the catalog states an interval exact in this timescale, and
1008
+ * none of its instants after the MPU's first released RAP lies in
1009
+ * `(from, to]` (fec-multicast-00 Block Classification item 3). Anything
1010
+ * unknown counts as a keyframe.
1011
+ */
1012
+ keyframeFreeBetween(mpu, from, to, mediaTimescale) {
1013
+ const rap = this.#lastRap;
1014
+ if (!this.#mpuBoundsRaps || rap?.mpu !== mpu || rap.mediaTimescale !== mediaTimescale || rap.decodeTime === void 0) {
1015
+ return false;
1016
+ }
1017
+ const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
1018
+ return interval !== null && !keyframeInstantBetween(rap.decodeTime, interval, from, to);
1019
+ }
900
1020
  #blockFor(sbn) {
901
1021
  let block = this.#blocks.get(sbn);
902
1022
  if (!block) {
@@ -905,35 +1025,89 @@ var BlockClassifier = class {
905
1025
  }
906
1026
  return block;
907
1027
  }
908
- #checkInvariants(sbn, block, evidence) {
1028
+ #checkInvariants(sbn, block, evidence, placement) {
909
1029
  if (this.#mode === "all-protected" || this.#geometry.trackKind !== "video") return null;
910
1030
  const geometry = this.#geometry;
911
1031
  if (geometry.mode !== "classifying") return null;
912
- if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
913
- return "rap-not-mpu-start";
914
- }
915
- if (evidence.idx !== void 0 && evidence.idx >= geometry.gopFrames) {
1032
+ if (placement.rapNotMpuStart) return "rap-not-mpu-start";
1033
+ if (placement.position !== void 0 && placement.position >= geometry.gopFrames) {
916
1034
  return "mpu-longer-than-gop";
917
1035
  }
918
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0 && block.idxMax - block.idxMin >= geometry.interleaveUnits) {
1036
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0 && block.positionMax - block.positionMin >= geometry.interleaveUnits) {
919
1037
  return "block-wider-than-interleave";
920
1038
  }
921
- if (evidence.mpu !== void 0 && evidence.movieFragment !== void 0) {
922
- const fragment = this.#mpuFragments.get(evidence.mpu);
923
- if (fragment === void 0) {
924
- this.#mpuFragments.set(evidence.mpu, evidence.movieFragment);
925
- for (const mpu of this.#mpuFragments.keys()) {
926
- if (mpu + 1 < evidence.mpu) this.#mpuFragments.delete(mpu);
927
- }
928
- } else if (fragment !== evidence.movieFragment) {
929
- return "mpu-multiple-fragments";
930
- }
931
- }
1039
+ if (placement.violation !== void 0) return placement.violation;
932
1040
  if (evidence.mpu !== void 0 && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {
933
1041
  return "block-not-contiguous";
934
1042
  }
935
1043
  return null;
936
1044
  }
1045
+ /**
1046
+ * The MPU position a source symbol's DU header proves (P3), and what it
1047
+ * refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.
1048
+ */
1049
+ #place(evidence) {
1050
+ const { mpu, idx, movieFragment: fragment } = evidence;
1051
+ if (idx === void 0) return UNPLACED;
1052
+ const bySample = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 };
1053
+ if (mpu === void 0 || fragment === void 0) {
1054
+ return this.#fragmentPerFrame && !this.#multiSampleFragment ? { rapNotMpuStart: bySample.rapNotMpuStart } : bySample;
1055
+ }
1056
+ let layout = this.#mpus.get(mpu);
1057
+ if (layout === void 0) {
1058
+ layout = { low: fragment };
1059
+ this.#mpus.set(mpu, layout);
1060
+ for (const other of this.#mpus.keys()) {
1061
+ if (other + 1 < mpu) this.#mpus.delete(other);
1062
+ }
1063
+ } else if (fragment !== layout.low) {
1064
+ this.#fragmentPerFrame = true;
1065
+ if ((fragment - layout.low | 0) < 0) layout.low = fragment;
1066
+ }
1067
+ if (idx !== 0) this.#multiSampleFragment = true;
1068
+ let arrival;
1069
+ if (evidence.rap && layout.anchor === void 0) {
1070
+ layout.anchor = fragment;
1071
+ arrival = this.#anchorDrift(mpu, fragment);
1072
+ if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true;
1073
+ this.#lastAnchor = { mpu, fragment };
1074
+ }
1075
+ if (!this.#fragmentPerFrame) return bySample;
1076
+ if (this.#multiSampleFragment) return { ...bySample, violation: "mpu-multiple-fragments" };
1077
+ const { anchor } = layout;
1078
+ if (anchor === void 0) return UNPLACED;
1079
+ const drift = arrival ?? this.#anchorDrift(mpu, anchor);
1080
+ const offset = fragment - anchor | 0;
1081
+ return {
1082
+ ...offset === 0 || offset > 0 && this.#fragmentsProven ? { position: offset } : {},
1083
+ rapNotMpuStart: evidence.rap && offset !== 0 || (layout.low - anchor | 0) < 0 || // Fragments count frames: an anchor arriving past the spacing is a
1084
+ // RAP inside its MPU, or an earlier MPU outran G.
1085
+ arrival !== void 0 && arrival > 0 && this.#fragmentsProven,
1086
+ ...drift === void 0 || drift === 0 ? {} : { violation: "rap-spacing-mismatch" }
1087
+ };
1088
+ }
1089
+ /**
1090
+ * How many fragments MPU m's anchor `fragment` lies past the start that
1091
+ * the anchor received last predicts for MPU m: one frame per fragment and
1092
+ * G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')
1093
+ * fragments apart, modulo 2^32. Undefined without a last anchor, a
1094
+ * cadence, or this layout.
1095
+ */
1096
+ #anchorDrift(mpu, fragment) {
1097
+ const geometry = this.#geometry;
1098
+ const last = this.#lastAnchor;
1099
+ if (last === null || !this.#fragmentPerFrame || this.#multiSampleFragment || geometry.trackKind !== "video" || geometry.mode !== "classifying") {
1100
+ return void 0;
1101
+ }
1102
+ return fragment - last.fragment - geometry.gopFrames * (mpu - last.mpu) | 0;
1103
+ }
1104
+ #clearMpuLayout() {
1105
+ this.#mpus.clear();
1106
+ this.#fragmentPerFrame = false;
1107
+ this.#multiSampleFragment = false;
1108
+ this.#lastAnchor = null;
1109
+ this.#fragmentsProven = false;
1110
+ }
937
1111
  #clearContiguityLedger() {
938
1112
  this.#mpuSbnSpans.clear();
939
1113
  this.#dataUnitStarts.clear();
@@ -1033,9 +1207,9 @@ var BlockClassifier = class {
1033
1207
  if (this.#mode === "all-protected") return "unknown";
1034
1208
  const geometry = this.#geometry;
1035
1209
  if (geometry.trackKind !== "video" || geometry.mode !== "classifying") return "unknown";
1036
- if (block.mpus.size === 1 && block.idxMin !== void 0 && block.idxMax !== void 0) {
1210
+ if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
1037
1211
  const span = geometry.interleaveUnits - 1;
1038
- if (block.idxMax - span >= 1 && block.idxMin + span <= geometry.gopFrames - 1) {
1212
+ if (block.positionMax - span >= 1 && block.positionMin + span <= geometry.gopFrames - 1) {
1039
1213
  return "delta";
1040
1214
  }
1041
1215
  }
@@ -1235,7 +1409,12 @@ var FECManager = class _FECManager {
1235
1409
  this.#repairHoldUntilMs = /* @__PURE__ */ new Map();
1236
1410
  // Receiver-measured multicast delivery gap: the late-symbol wait's jitter
1237
1411
  // term (see DeliveryGapEstimator for the statistic and why).
1238
- this.#deliveryGaps = new DeliveryGapEstimator();
1412
+ // One estimator per lossy path, so a hybrid session never lets one leg's
1413
+ // stall widen the other's wait; the wait reads the larger peak.
1414
+ this.#deliveryGaps = {
1415
+ multicast: new DeliveryGapEstimator(),
1416
+ "moq-datagram": new DeliveryGapEstimator()
1417
+ };
1239
1418
  this.#lifecycleTrace = [];
1240
1419
  // Worker-backed timeouts enqueue cleanup behind all prior symbol messages.
1241
1420
  // Failure remains pending until cleanupComplete acknowledges that queue drain.
@@ -1273,7 +1452,8 @@ var FECManager = class _FECManager {
1273
1452
  this.#ssbLengthConflictCount = 0;
1274
1453
  this.#blockRepairRsIds = /* @__PURE__ */ new Map();
1275
1454
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
1276
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
1455
+ // symbols its repair group carries; 0 for a repair-less span no repair can
1456
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
1277
1457
  this.#blockRsbLengths = /* @__PURE__ */ new Map();
1278
1458
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
1279
1459
  this.#heldLayerStates = /* @__PURE__ */ new Map();
@@ -1426,6 +1606,14 @@ var FECManager = class _FECManager {
1426
1606
  // iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
1427
1607
  // block only once a repair symbol stated the block's (SS_Start, SSB_length).
1428
1608
  this.#isoLocators = /* @__PURE__ */ new Map();
1609
+ // The ts of the run behind the gap the release gate last asked about, per
1610
+ // stream (isoRepairlessWaitMs), keyed on the frame before the gap: kept, as
1611
+ // the source it came from may retire before the run's deadline, and the
1612
+ // earliest found wins, so a late frame that becomes the head restarts
1613
+ // nothing. It stays until the next run gap: a source discontinuity drops
1614
+ // it, and one older than twice the hold ceiling is not this gap's.
1615
+ // `counted` once the deadline passed (onUndelimitedRunGap).
1616
+ this.#runAnchors = /* @__PURE__ */ new Map();
1429
1617
  this.#deferIsoGaps = false;
1430
1618
  this.#isoRepairRefusedCount = 0;
1431
1619
  this.#isoSourceOversizeCount = 0;
@@ -1461,6 +1649,8 @@ var FECManager = class _FECManager {
1461
1649
  this.#workerErrorCounts = /* @__PURE__ */ new Map();
1462
1650
  this.#decoderUnavailableEvents = 0;
1463
1651
  this.#repairSymbolSizeMismatchCount = 0;
1652
+ this.#unlistedRepairTrackRefusals = 0;
1653
+ this.#unresolvedRepairOwnerDrops = { unregistered: 0, ownerAbsent: 0, ownerAmbiguous: 0 };
1464
1654
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
1465
1655
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
1466
1656
  // feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
@@ -1520,6 +1710,18 @@ var FECManager = class _FECManager {
1520
1710
  this.onBlockResolved = null;
1521
1711
  /** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
1522
1712
  this.onSourceDiscontinuity = null;
1713
+ /** The FEC deadline of a run no repair delimited passed, releasing the gap behind it (once per gap). */
1714
+ this.onUndelimitedRunGap = null;
1715
+ /**
1716
+ * The span and tolerance the catalog states for a keyframe overlay
1717
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
1718
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
1719
+ * undefined while none is installed. A stated block only a late source
1720
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
1721
+ * late source can fill, also wait for that overlay's repair
1722
+ * (#overlayLateWaitMs).
1723
+ */
1724
+ this.keyframeOverlayTiming = null;
1523
1725
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
1524
1726
  /**
1525
1727
  * A recovered source symbol. Return false when admission refused the
@@ -1610,6 +1812,7 @@ var FECManager = class _FECManager {
1610
1812
  #highestSbn;
1611
1813
  #sourceFrontiers;
1612
1814
  #isoLocators;
1815
+ #runAnchors;
1613
1816
  #deferIsoGaps;
1614
1817
  #isoRepairRefusedCount;
1615
1818
  #isoSourceOversizeCount;
@@ -1624,6 +1827,8 @@ var FECManager = class _FECManager {
1624
1827
  #workerErrorCounts;
1625
1828
  #decoderUnavailableEvents;
1626
1829
  #repairSymbolSizeMismatchCount;
1830
+ #unlistedRepairTrackRefusals;
1831
+ #unresolvedRepairOwnerDrops;
1627
1832
  #onUndelimitedLoss;
1628
1833
  #onIsoHoleExpired;
1629
1834
  #encodeTrackName(catalogTrackName) {
@@ -2273,6 +2478,7 @@ var FECManager = class _FECManager {
2273
2478
  const discontinuity = () => {
2274
2479
  this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
2275
2480
  this.#noSpanRaps.delete(streamKey);
2481
+ this.#runAnchors.delete(streamKey);
2276
2482
  this.#highestSbn.set(streamKey, { sbn, atMs: now });
2277
2483
  this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
2278
2484
  if (psn === void 0) this.#sourceAnchors.delete(streamKey);
@@ -2443,7 +2649,7 @@ var FECManager = class _FECManager {
2443
2649
  consider(geometry, this.#parseStreamKey(streamKey).packetId);
2444
2650
  }
2445
2651
  for (const [packetId, config] of this.#trackConfigs) consider(config.geometry, packetId);
2446
- this.#deliveryGaps.setWindowMs(windowMs);
2652
+ for (const estimator of Object.values(this.#deliveryGaps)) estimator.setWindowMs(windowMs);
2447
2653
  }
2448
2654
  /**
2449
2655
  * The multicast late-symbol wait: the block span plus the larger of the
@@ -2456,14 +2662,14 @@ var FECManager = class _FECManager {
2456
2662
  * stream order and never feeds the estimator.
2457
2663
  */
2458
2664
  #multicastWaitMs(config) {
2459
- return this.#waitForGapMs(config, this.#deliveryGaps.peakGapMs(performance.now()));
2665
+ return this.#waitForGapMs(config, this.#peakDeliveryGapMs());
2460
2666
  }
2461
2667
  /**
2462
2668
  * The widest #multicastWaitMs can become: the estimator reports at most its
2463
2669
  * catalog window, so this is a catalog quantity that no measurement moves.
2464
2670
  */
2465
2671
  #maxMulticastWaitMs(config) {
2466
- return this.#waitForGapMs(config, this.#deliveryGaps.windowMs ?? 0);
2672
+ return this.#waitForGapMs(config, this.#deliveryGaps.multicast.windowMs ?? 0);
2467
2673
  }
2468
2674
  #waitForGapMs(config, gapMs) {
2469
2675
  if (!(gapMs > 0) || !(config.interleaveDepthMs > 0)) return config.timeoutMs;
@@ -2647,6 +2853,7 @@ var FECManager = class _FECManager {
2647
2853
  ...(config.trackKind ?? previous.trackKind) === void 0 ? {} : { trackKind: config.trackKind ?? previous.trackKind },
2648
2854
  ...(config.codec ?? previous.codec) === void 0 ? {} : { codec: config.codec ?? previous.codec },
2649
2855
  ...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry },
2856
+ ...(config.groupDurationMs ?? previous.groupDurationMs) === void 0 ? {} : { groupDurationMs: config.groupDurationMs ?? previous.groupDurationMs },
2650
2857
  ...(config.repairLayers ?? previous.repairLayers) === void 0 ? {} : { repairLayers: config.repairLayers ?? previous.repairLayers },
2651
2858
  ...(config.heldLayers ?? previous.heldLayers) === void 0 ? {} : { heldLayers: config.heldLayers ?? previous.heldLayers }
2652
2859
  };
@@ -2753,6 +2960,10 @@ var FECManager = class _FECManager {
2753
2960
  lifecycleTrace: this.#lifecycleTrace.map((entry) => ({ ...entry }))
2754
2961
  };
2755
2962
  }
2963
+ /** Count a repair packet the router dropped for want of an owning track (BLO-55759). */
2964
+ countUnresolvedRepairOwner(reason) {
2965
+ this.#unresolvedRepairOwnerDrops[reason]++;
2966
+ }
2756
2967
  get fecStats() {
2757
2968
  const s = this.#fecStats;
2758
2969
  const affected = s.blocksRecovered + s.blocksFailed;
@@ -2792,6 +3003,8 @@ var FECManager = class _FECManager {
2792
3003
  packetId
2793
3004
  })),
2794
3005
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
3006
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
3007
+ unresolvedRepairOwnerDrops: { ...this.#unresolvedRepairOwnerDrops },
2795
3008
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
2796
3009
  workerErrors: Object.fromEntries(this.#workerErrorCounts)
2797
3010
  };
@@ -2816,6 +3029,16 @@ var FECManager = class _FECManager {
2816
3029
  this.#startupRepairBoundaryCounts.clear();
2817
3030
  this.#startupRepairFailOpenPackets.clear();
2818
3031
  }
3032
+ /**
3033
+ * Start a new "mfu-datagram" leg (mmt-02 4.3.1) without discarding
3034
+ * track/decoder state: the same join-boundary rules as a multicast join,
3035
+ * since the leg starts at an arbitrary datagram too. It resets the whole
3036
+ * join boundary of this manager, a multicast ordered-relay frontier
3037
+ * included, so a host gives the leg a manager of its own.
3038
+ */
3039
+ beginLegJoin() {
3040
+ this.beginMulticastJoin();
3041
+ }
2819
3042
  /** How the multicast leg currently delivers symbols. */
2820
3043
  get multicastSymbolDelivery() {
2821
3044
  return this.#multicastSymbolDelivery;
@@ -2838,7 +3061,8 @@ var FECManager = class _FECManager {
2838
3061
  );
2839
3062
  }
2840
3063
  if (delivery === this.#multicastSymbolDelivery) return;
2841
- this.#deliveryGaps.reset();
3064
+ this.#deliveryGaps.multicast.reset();
3065
+ this.#runAnchors.clear();
2842
3066
  if (delivery === "ordered-relay") {
2843
3067
  for (const [packetId, config] of this.#trackConfigs) {
2844
3068
  this.#orderedHorizonBlocksFor(packetId, config);
@@ -2927,6 +3151,7 @@ var FECManager = class _FECManager {
2927
3151
  resetMap(this.#highestSbn);
2928
3152
  resetMap(this.#sourceFrontiers);
2929
3153
  resetMap(this.#isoLocators);
3154
+ resetMap(this.#runAnchors);
2930
3155
  resetMap(this.#sourceAnchors);
2931
3156
  this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
2932
3157
  this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName));
@@ -3036,6 +3261,7 @@ var FECManager = class _FECManager {
3036
3261
  dropMap(this.#highestSbn);
3037
3262
  dropMap(this.#sourceFrontiers);
3038
3263
  dropMap(this.#isoLocators);
3264
+ dropMap(this.#runAnchors);
3039
3265
  dropMap(this.#sourceAnchors);
3040
3266
  dropMap(this.#classifiers);
3041
3267
  dropMap(this.#noSpanRaps);
@@ -3103,8 +3329,8 @@ var FECManager = class _FECManager {
3103
3329
  const sourceSymbols = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? this.#trackConfig(packetId).k;
3104
3330
  const isSourceSymbol = esi >= 0 && esi < sourceSymbols;
3105
3331
  const isStartupPartial = this.#startupPartialBlocks.has(blockKey);
3106
- const isReadyMulticastRepair = this.#startupRequireRepairReady && source === "multicast" && !isSourceSymbol && this.#startupRepairReadyPackets.has(streamKey);
3107
- const awaitingMulticastRepair = this.#startupRequireRepairReady && source === "multicast" && !this.#startupRepairReadyPackets.has(streamKey) && !this.#startupRepairFailOpenPackets.has(streamKey);
3332
+ const isReadyMulticastRepair = this.#startupRequireRepairReady && source !== "moq" && !isSourceSymbol && this.#startupRepairReadyPackets.has(streamKey);
3333
+ const awaitingMulticastRepair = this.#startupRequireRepairReady && source !== "moq" && !this.#startupRepairReadyPackets.has(streamKey) && !this.#startupRepairFailOpenPackets.has(streamKey);
3108
3334
  if (awaitingMulticastRepair) {
3109
3335
  if (!isSourceSymbol) {
3110
3336
  this.#startupRepairReadyPackets.add(streamKey);
@@ -3158,12 +3384,14 @@ var FECManager = class _FECManager {
3158
3384
  ...catalogTrackName === void 0 ? {} : { catalogTrackName },
3159
3385
  multicastSymbols: 0,
3160
3386
  moqSymbols: 0,
3387
+ datagramSymbols: 0,
3161
3388
  complete: false
3162
3389
  };
3163
3390
  const receivedAtMs = this.#receiptNow();
3164
3391
  const anchorMs = this.#blockAnchorsMs.get(blockKey);
3165
3392
  if (anchorMs === void 0 || receivedAtMs < anchorMs) this.#blockAnchorsMs.set(blockKey, receivedAtMs);
3166
3393
  if (source === "multicast") counts.multicastSymbols++;
3394
+ else if (source === "moq-datagram") counts.datagramSymbols++;
3167
3395
  else counts.moqSymbols++;
3168
3396
  this.#blockPathCounts.set(blockKey, counts);
3169
3397
  this.#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName);
@@ -3184,7 +3412,7 @@ var FECManager = class _FECManager {
3184
3412
  this.#unindexBlockKey(key);
3185
3413
  }
3186
3414
  }
3187
- if (isSourceSymbol && source === "multicast") {
3415
+ if (isSourceSymbol && source !== "moq") {
3188
3416
  this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), sbn + esi >>> 0, packetId, catalogTrackName);
3189
3417
  }
3190
3418
  return true;
@@ -3273,8 +3501,22 @@ var FECManager = class _FECManager {
3273
3501
  * DeliveryGapEstimator). Datagram delivery only.
3274
3502
  */
3275
3503
  noteMulticastArrival(packetId, packetSequenceNumber) {
3276
- if (this.#multicastSymbolDelivery !== "datagram") return;
3277
- this.#deliveryGaps.noteArrival(performance.now(), packetId, packetSequenceNumber);
3504
+ this.noteArrival("multicast", packetId, packetSequenceNumber);
3505
+ }
3506
+ /**
3507
+ * Record one MMTP packet arrival on a lossy path for that path's
3508
+ * delivery-gap measurement: the multicast leg (datagram delivery only; an
3509
+ * ordered relay settles by stream order) or an "mfu-datagram" leg, whose
3510
+ * datagrams are always a lossy path (#lossyDatagramPath).
3511
+ */
3512
+ noteArrival(path, packetId, packetSequenceNumber) {
3513
+ if (!this.#lossyDatagramPath(path)) return;
3514
+ this.#deliveryGaps[path].noteArrival(performance.now(), packetId, packetSequenceNumber);
3515
+ }
3516
+ /** The largest delivery gap any lossy path measured over its window. */
3517
+ #peakDeliveryGapMs() {
3518
+ const now = performance.now();
3519
+ return Math.max(...Object.values(this.#deliveryGaps).map((estimator) => estimator.peakGapMs(now)));
3278
3520
  }
3279
3521
  /**
3280
3522
  * Resolved per-track multicast late-symbol wait in milliseconds: the span
@@ -3288,16 +3530,18 @@ var FECManager = class _FECManager {
3288
3530
  * Largest multicast delivery gap measured over the current window (ms), and
3289
3531
  * that window (undefined: held since the last reset). Diagnostics.
3290
3532
  */
3291
- multicastDeliveryGap() {
3533
+ multicastDeliveryGap(path = "multicast") {
3292
3534
  return {
3293
- peakGapMs: this.#deliveryGaps.peakGapMs(performance.now()),
3294
- windowMs: this.#deliveryGaps.windowMs
3535
+ peakGapMs: this.#deliveryGaps[path].peakGapMs(performance.now()),
3536
+ windowMs: this.#deliveryGaps[path].windowMs
3295
3537
  };
3296
3538
  }
3297
3539
  /**
3298
3540
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
3299
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
3300
- * Undefined for a block that is not open.
3541
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
3542
+ * repair-less span states its length, and RSB_length 0 when it is longer
3543
+ * than K, since no repair can reach it). Undefined for a block that is not
3544
+ * open.
3301
3545
  */
3302
3546
  blockSymbolCounts(sbn, packetId, catalogTrackName) {
3303
3547
  const key = this.#blockKey(sbn, packetId, catalogTrackName);
@@ -3387,6 +3631,23 @@ var FECManager = class _FECManager {
3387
3631
  const config = this.#trackConfigs.get(packetId);
3388
3632
  return config === void 0 ? void 0 : this.#blockLifetimeMs(config);
3389
3633
  }
3634
+ /**
3635
+ * How long an "mfu-datagram" leg's duplicate ledgers must remember a packet
3636
+ * so a legal reorder never reads as a publisher restart: one block span,
3637
+ * the reorder tolerance (`timeoutMs` is span + tolerance) and one group,
3638
+ * since a datagram may trail the stream by a whole group behind a joining
3639
+ * FETCH (mmt-02 6.1 step 3). The group is the catalog group duration
3640
+ * (`groupDurationMs`), whatever the track kind; a video track configured
3641
+ * without one falls back to its keyframe interval (one GOP per group).
3642
+ * Undefined for an unconfigured packet id.
3643
+ */
3644
+ datagramLegLedgerRetentionMsForPacket(packetId) {
3645
+ const config = this.#trackConfigs.get(packetId);
3646
+ if (config === void 0) return void 0;
3647
+ const geometry = config.geometry;
3648
+ const groupMs = config.groupDurationMs ?? (geometry?.trackKind === "video" && geometry.mode === "classifying" ? geometry.keyframeInterval.ticks / geometry.keyframeInterval.timescale * 1e3 : 0);
3649
+ return config.timeoutMs + (Number.isFinite(groupMs) ? groupMs : 0);
3650
+ }
3390
3651
  /**
3391
3652
  * How long a terminal (clean, recovered or failed) block stays authoritative,
3392
3653
  * for late symbols and for the in-order release gate. It is also the gate's
@@ -3413,7 +3674,7 @@ var FECManager = class _FECManager {
3413
3674
  }
3414
3675
  const trackConfig = this.#trackConfigs.get(packetId);
3415
3676
  if (trackConfig === void 0) return void 0;
3416
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig));
3677
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
3417
3678
  }
3418
3679
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
3419
3680
  // -----------------------------------------------------------------------
@@ -3455,6 +3716,9 @@ var FECManager = class _FECManager {
3455
3716
  for (const key of [...this.#isoLocators.keys()]) {
3456
3717
  if (this.#belongsToPacket(key, packetId)) this.#isoLocators.delete(key);
3457
3718
  }
3719
+ for (const key of [...this.#runAnchors.keys()]) {
3720
+ if (this.#belongsToPacket(key, packetId)) this.#runAnchors.delete(key);
3721
+ }
3458
3722
  }
3459
3723
  /**
3460
3724
  * The iso-ssbg1-v1 locator horizon in blocks: every block the manager can
@@ -3504,9 +3768,9 @@ var FECManager = class _FECManager {
3504
3768
  holdIsoSource(packetId, catalogTrackName, ssId, source) {
3505
3769
  const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
3506
3770
  const evictedBefore = locator.heldEvicted;
3507
- const held = locator.hold(ssId, source);
3771
+ const held = locator.hold(ssId, source.arrivedAtMs === void 0 ? { ...source, arrivedAtMs: this.#receiptNow() } : source);
3508
3772
  this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
3509
- if (held && source.source === "multicast") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
3773
+ if (held && source.source !== "moq") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
3510
3774
  const evicted = locator.heldEvicted - evictedBefore;
3511
3775
  if (evicted > 0) {
3512
3776
  const before = this.#isoHeldEvictedCount;
@@ -3599,12 +3863,24 @@ var FECManager = class _FECManager {
3599
3863
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
3600
3864
  * SS_ID of which vanished resolves through its deadline like any vanished
3601
3865
  * block.
3866
+ *
3867
+ * A span longer than K holds more than one block (SSB_length <= K), and the
3868
+ * locator states no block inside a span, only one exactly its range
3869
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
3870
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
3871
+ * Group of it (group-cannot-complete). Every span still keeps its whole
3872
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
3873
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
3874
+ * gate lets those frames go once only a late source can fill the gap
3875
+ * before them, as long after they arrived as the gap's decision allows
3876
+ * (isoRepairlessWaitMs).
3602
3877
  */
3603
3878
  #openIsoSpan(span, packetId, catalogTrackName) {
3604
3879
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
3605
3880
  if (!this.#blockAuthoredLengths.has(key)) {
3606
3881
  this.#blockAuthoredLengths.set(key, span.block.length);
3607
3882
  this.#isoSpanKeys.add(key);
3883
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
3608
3884
  }
3609
3885
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
3610
3886
  }
@@ -3612,7 +3888,12 @@ var FECManager = class _FECManager {
3612
3888
  * Resolution of the SS_IDs strictly between two released frames' SS_IDs on
3613
3889
  * an iso-ssbg1-v1 stream, for in-order frame release: null while a block
3614
3890
  * that could hold them is pending or not yet stated by a repair, else the
3615
- * starts of the blocks that failed or vanished.
3891
+ * starts of the blocks that failed or vanished. SS_IDs no repair has
3892
+ * delimited yet that all arrived lost nothing and wait for no repair, only
3893
+ * the late-source allowance after the datagram of a lossy path that clocks
3894
+ * them arrived (#lossFreeRunReadyAtMs), and not even that when none of them
3895
+ * came as one; one missing makes a run that waits as one block
3896
+ * (isoRepairlessWaitMs).
3616
3897
  *
3617
3898
  * `untracked` reads as the release gate reads it (MmtpRouter
3618
3899
  * #createFecReleaseGate): a block holding either released frame's SS_ID
@@ -3625,7 +3906,16 @@ var FECManager = class _FECManager {
3625
3906
  isoSpanResolution(packetId, catalogTrackName, fromSsId, toSsId) {
3626
3907
  if (!serial32Precedes(fromSsId, toSsId) || serial32Distance(fromSsId, toSsId) <= 1) return [];
3627
3908
  const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
3628
- if (!locator || !locator.coversBetween(fromSsId, toSsId)) return null;
3909
+ if (!locator) return null;
3910
+ const run = locator.undelimitedBetween(fromSsId, toSsId);
3911
+ if (run?.missing !== void 0) return null;
3912
+ if (run !== null) {
3913
+ const config = this.#trackConfigs.get(packetId);
3914
+ const readyAtMs = config === void 0 ? void 0 : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId);
3915
+ if (readyAtMs !== void 0 && this.#receiptNow() < readyAtMs) return null;
3916
+ }
3917
+ if (locator.coverageEnd === void 0) return [];
3918
+ if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return null;
3629
3919
  const highest = this.highestSbn(packetId, catalogTrackName);
3630
3920
  const lost = [];
3631
3921
  for (const block of locator.blocksBetween(fromSsId, toSsId)) {
@@ -3643,6 +3933,162 @@ var FECManager = class _FECManager {
3643
3933
  }
3644
3934
  return lost;
3645
3935
  }
3936
+ /**
3937
+ * When undelimited SS_IDs from `runStart` up to `toSsId` that all arrived
3938
+ * stop holding its frame: the late-source allowance after the receipt of
3939
+ * a datagram of a lossy path (#lossyDatagramPath: a multicast datagram, or
3940
+ * one of an "mfu-datagram" leg). Until then a frame between them may still
3941
+ * complete from a packet with no SS_ID (an untagged FT=0/FT=1 reordered
3942
+ * behind the next frame), and a repair may delimit them. The receipt is
3943
+ * `toSsId`'s own when it is held from such a datagram. Otherwise (its
3944
+ * packet came only as an overlap copy or from a MoQ stream, or was evicted
3945
+ * or retired) it is the newest among those SS_IDs, every one of which is
3946
+ * held and states its path. So the time moves at most once, when the
3947
+ * head's own datagram copy arrives while its frame waits or its held
3948
+ * source is dropped, and never on a later ask.
3949
+ *
3950
+ * Undefined, so the range releases at once, when no SS_ID of it came as
3951
+ * such a datagram: a MoQ arrival, an ordered relay's and the frame's own
3952
+ * are no clock for datagram reordering (#lossyReceiptMs). Undefined too
3953
+ * on a track with no catalog span, which states no allowance: the local
3954
+ * timeout is a cleanup bound, and isoRepairlessWaitMs arms no wake there,
3955
+ * so a wait would hold the frame until the next packet. The cost, on
3956
+ * multicast and on the leg too: an untagged FT=0/FT=1 reordered behind
3957
+ * the next frame of such a track is dropped stale.
3958
+ */
3959
+ #lossFreeRunReadyAtMs(config, locator, runStart, toSsId) {
3960
+ if (!_FECManager.#hasCatalogTiming(config)) return void 0;
3961
+ let clockMs = this.#lossyReceiptMs(locator.heldSource(toSsId));
3962
+ if (clockMs === void 0) {
3963
+ for (let ssId = runStart; ssId !== toSsId; ssId = ssId + 1 >>> 0) {
3964
+ const atMs = this.#lossyReceiptMs(locator.heldSource(ssId));
3965
+ if (atMs !== void 0 && (clockMs === void 0 || atMs > clockMs)) clockMs = atMs;
3966
+ }
3967
+ }
3968
+ if (clockMs === void 0) return void 0;
3969
+ return clockMs + Math.max(0, this.#multicastWaitMs(config) - config.interleaveDepthMs);
3970
+ }
3971
+ /**
3972
+ * Receipt time of a held source that came as a datagram of a lossy path
3973
+ * (#lossyDatagramPath), else undefined: a MoQ stream and an ordered relay
3974
+ * deliver in order, so their arrivals clock no reorder allowance and no
3975
+ * FEC deadline. The path is the one the feed stated (IsoHeldSource.source,
3976
+ * and MulticastSymbolDelivery for a multicast source), never a guess.
3977
+ */
3978
+ #lossyReceiptMs(held) {
3979
+ return held !== void 0 && this.#lossyDatagramPath(held.source) ? held.arrivedAtMs : void 0;
3980
+ }
3981
+ /**
3982
+ * The one path predicate of the loss gates: whether a symbol fed as
3983
+ * `source` reached this manager as a datagram of its own, on a path that
3984
+ * loses and reorders (mmt-02 Section 2, a datagram leg). A multicast
3985
+ * symbol does unless its provider declared an ordered relay. An
3986
+ * "mfu-datagram" object always does (4.3.1): MulticastSymbolDelivery is
3987
+ * the multicast provider's statement and is never read for the leg. A MoQ
3988
+ * stream object never does, a stream copy of the leg included.
3989
+ */
3990
+ #lossyDatagramPath(source) {
3991
+ return source === "moq-datagram" || source === "multicast" && this.#multicastSymbolDelivery === "datagram";
3992
+ }
3993
+ /**
3994
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
3995
+ * between two released frames' SS_IDs once only a late source can still
3996
+ * fill them, else undefined. That is when every one missing (neither
3997
+ * arrived nor held) lies in a repair-less span longer than K, which no
3998
+ * repair can state a block of (#openIsoSpan), or in a stated block its
3999
+ * own repair group cannot complete every SS_ID of which it misses lies
4000
+ * between them (so the gap's decision covers all it lost), and a source of
4001
+ * a lossy leg (multicast, or an "mfu-datagram" leg's datagram) at or past
4002
+ * `toSsId` arrived, so each is lost or reordered behind it (a MoQ source
4003
+ * shows nothing: MoQ streams overtake one another). The span or block
4004
+ * itself keeps its own wait.
4005
+ *
4006
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
4007
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
4008
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
4009
+ * Then the frame waits as a stated block its group cannot complete does
4010
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
4011
+ * overlay's span plus the larger of the allowance and its tolerance, or,
4012
+ * for an overlay that states no span, the span's whole wait (undefined).
4013
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
4014
+ * the gap holds a stated block's loss.
4015
+ *
4016
+ * A run of SS_IDs no repair has delimited yet, one of which never arrived,
4017
+ * is one block of its own instead (draft-ramadan-moq-fec-multicast-00,
4018
+ * Receiver Repair Policy; on an "mfu-datagram" leg fec-core-00 9.3 and
4019
+ * mmt-02 5.3.3): the frame then waits for that block's FEC deadline,
4020
+ * whatever the flags: ts plus the whole multicast wait (fec-core-00 9.3),
4021
+ * ts the receipt of the lowest held source above the run that came as a
4022
+ * datagram of a lossy path (#lossyDatagramPath), up to the newest
4023
+ * (fec-multicast-00, Deadline Anchoring; under reordering at or after the
4024
+ * draft's first signal, never before). The wait returned counts from
4025
+ * `arrivedAtMs`, the frame's arrival; without it, it is the whole wait.
4026
+ * With no such source held (never arrived, retired, or evicted, or every
4027
+ * one from a MoQ stream or an ordered relay) the frame keeps the hold
4028
+ * ceiling: a stream arrival is no clock for a datagram deadline.
4029
+ */
4030
+ isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false, arrivedAtMs) {
4031
+ const config = this.#trackConfigs.get(packetId);
4032
+ if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
4033
+ const streamKey = this.#streamKey(packetId, catalogTrackName);
4034
+ const locator = this.#isoLocators.get(streamKey);
4035
+ if (locator === void 0) return void 0;
4036
+ const run = locator.undelimitedBetween(fromSsId, toSsId);
4037
+ const readyAtMs = run === null || run.missing !== void 0 ? void 0 : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId);
4038
+ if (readyAtMs !== void 0 && this.#receiptNow() < readyAtMs) {
4039
+ return Math.max(0, readyAtMs - (arrivedAtMs ?? this.#receiptNow()));
4040
+ }
4041
+ const newestSource = locator.newestSource;
4042
+ if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
4043
+ if (run?.missing !== void 0) {
4044
+ if (this.isoSpanResolution(packetId, catalogTrackName, fromSsId, run.start) === null) return void 0;
4045
+ const kept = this.#runAnchors.get(streamKey);
4046
+ const anchor = kept?.fromSsId === fromSsId && this.#receiptNow() - kept.tsMs <= 2 * (config.interleaveDepthMs + 2 * this.#blockLifetimeMs(config)) ? kept : void 0;
4047
+ let tsMs = anchor?.tsMs;
4048
+ for (let ssId = run.missing + 1 >>> 0; !serial32Precedes(newestSource, ssId); ssId = ssId + 1 >>> 0) {
4049
+ const atMs = this.#lossyReceiptMs(locator.heldSource(ssId));
4050
+ if (atMs === void 0) continue;
4051
+ if (tsMs === void 0 || atMs < tsMs) tsMs = atMs;
4052
+ break;
4053
+ }
4054
+ if (tsMs === void 0) return void 0;
4055
+ const waitMs2 = this.#multicastWaitMs(config);
4056
+ let counted = anchor?.counted === true;
4057
+ if (!counted && tsMs + waitMs2 <= this.#receiptNow()) {
4058
+ counted = true;
4059
+ this.onUndelimitedRunGap?.(packetId, catalogTrackName);
4060
+ }
4061
+ this.#runAnchors.set(streamKey, { fromSsId, tsMs, counted });
4062
+ return arrivedAtMs === void 0 ? waitMs2 : Math.max(0, tsMs + waitMs2 - arrivedAtMs);
4063
+ }
4064
+ if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return void 0;
4065
+ let repairless = false;
4066
+ let stated = false;
4067
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
4068
+ const key = this.#blockKey(block.start, packetId, catalogTrackName);
4069
+ if (this.#completedBlocks.has(key)) continue;
4070
+ if (block.span && block.length > locator.kMax) {
4071
+ repairless = true;
4072
+ continue;
4073
+ }
4074
+ const received = this.#blockSourceEsis.get(key);
4075
+ const rebuilt = this.#blockRebuiltEsis.get(key);
4076
+ let missesInGap = false;
4077
+ let missesOutside = false;
4078
+ for (let esi = 0; esi < block.length; esi++) {
4079
+ const ssId = serial32Add(block.start, esi);
4080
+ if (received?.has(esi) || locator.isHeld(ssId)) continue;
4081
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
4082
+ else if (!rebuilt?.has(esi)) missesOutside = true;
4083
+ }
4084
+ if (!missesInGap) continue;
4085
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
4086
+ repairless = stated = true;
4087
+ }
4088
+ if (!repairless) return void 0;
4089
+ const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
4090
+ return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
4091
+ }
3646
4092
  /**
3647
4093
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
3648
4094
  * the sources held now for a block no repair has stated yet, and the held
@@ -3696,11 +4142,31 @@ var FECManager = class _FECManager {
3696
4142
  * it does not. A stream with no classifier yet has shown nothing against it,
3697
4143
  * and neither has a stream without catalog timing until it releases two
3698
4144
  * RAPs inside one MPU.
4145
+ *
4146
+ * With catalog timing and a `gap` inside one MPU, between the authored
4147
+ * timing of the frames on either side, it also takes the catalog keyframe
4148
+ * interval to rule a keyframe out of the gap
4149
+ * (`BlockClassifier.keyframeFreeBetween`, fec-multicast-00 Block
4150
+ * Classification item 3), and no source held between the frames' SS_IDs
4151
+ * may carry the RAP flag or another MPU's number (item 1 read on the held
4152
+ * packets: a RAP the loss cut in two is never released, so the frames
4153
+ * alone cannot show it); anything unknown counts as a keyframe.
3699
4154
  */
3700
- mpuBoundsRapsFor(packetId, catalogTrackName) {
4155
+ mpuBoundsRapsFor(packetId, catalogTrackName, gap) {
3701
4156
  const streamKey = this.#streamKey(packetId, catalogTrackName);
3702
4157
  if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true;
3703
- return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true;
4158
+ const classifier = this.#classifiers.get(streamKey);
4159
+ if (gap === void 0) return classifier?.mpuBoundsRaps ?? true;
4160
+ const { mpu, from, to, fromSsId, toSsId } = gap;
4161
+ if (fromSsId !== void 0 && toSsId !== void 0) {
4162
+ const run = this.#isoLocators.get(streamKey)?.undelimitedBetween(
4163
+ fromSsId,
4164
+ toSsId,
4165
+ ({ evidence }) => evidence.rap || evidence.mpu !== void 0 && evidence.mpu !== mpu
4166
+ );
4167
+ if (run?.flagged) return false;
4168
+ }
4169
+ return classifier !== void 0 && from !== void 0 && to !== void 0 && from.mediaTimescale === to.mediaTimescale && classifier.keyframeFreeBetween(mpu, from.decodeTime, to.decodeTime, from.mediaTimescale);
3704
4170
  }
3705
4171
  /** A block's class now, or frozen at its resolution. */
3706
4172
  blockClassFor(sbn, packetId, catalogTrackName) {
@@ -3723,9 +4189,11 @@ var FECManager = class _FECManager {
3723
4189
  }
3724
4190
  /**
3725
4191
  * Record a RAP frame released in order, for the classifier's RAP-spacing
3726
- * invariant (consecutive MPUs exactly one keyframe interval apart).
4192
+ * invariant (consecutive MPUs exactly one keyframe interval apart) and,
4193
+ * with its decode time, as the MPU start gap decisions measure the catalog
4194
+ * keyframe interval from (mpuBoundsRapsFor).
3727
4195
  */
3728
- noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale) {
4196
+ noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale, decodeTime) {
3729
4197
  if (!this.#trackConfigs.has(packetId)) return;
3730
4198
  if (!this.#hasCatalogTimingForPacket(packetId)) {
3731
4199
  const streamKey = this.#streamKey(packetId, catalogTrackName);
@@ -3740,7 +4208,8 @@ var FECManager = class _FECManager {
3740
4208
  this.#classifierFor(packetId, catalogTrackName).noteReleasedRap(
3741
4209
  mpu,
3742
4210
  presentationTime,
3743
- mediaTimescale
4211
+ mediaTimescale,
4212
+ decodeTime
3744
4213
  )
3745
4214
  );
3746
4215
  }
@@ -4291,7 +4760,10 @@ var FECManager = class _FECManager {
4291
4760
  this.#layerAnchorHorizon(packetId),
4292
4761
  this.#sourceFrontiers.get(streamKey)?.sbn
4293
4762
  );
4294
- if (verdict === "discard") return false;
4763
+ if (verdict === "discard") {
4764
+ this.#unlistedRepairTrackRefusals++;
4765
+ return false;
4766
+ }
4295
4767
  if (verdict !== void 0) {
4296
4768
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
4297
4769
  return false;
@@ -4440,15 +4912,17 @@ var FECManager = class _FECManager {
4440
4912
  * its sources in send order, so one that moves the stream's newest source
4441
4913
  * position past a block leaves the sources that block still misses
4442
4914
  * reordered behind it at best: it shortens the wait of every block it
4443
- * passed that only a late source can complete. MoQ is left out: its streams
4444
- * can overtake one another, so a MoQ source shows nothing about the sources
4445
- * sent before it.
4915
+ * passed that only a late source can complete. Reliable MoQ is left out:
4916
+ * its streams can overtake one another, so a MoQ source shows nothing
4917
+ * about the sources sent before it. An "mfu-datagram" leg is in: its
4918
+ * datagrams leave the publisher in send order and reorder only within the
4919
+ * path's tolerance, as multicast does.
4446
4920
  */
4447
4921
  #noteMulticastSource(locator, ssId, packetId, catalogTrackName) {
4448
4922
  const previous = locator.newestSource;
4449
4923
  if (!locator.noteSource(ssId) || previous === void 0) return;
4450
4924
  for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
4451
- if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
4925
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
4452
4926
  this.#shortenUnrecoverableWait(
4453
4927
  this.#blockKey(block.start, packetId, catalogTrackName),
4454
4928
  block.start,
@@ -4466,21 +4940,61 @@ var FECManager = class _FECManager {
4466
4940
  * covers repair symbols paced after its sources, buys it nothing: it waits
4467
4941
  * the late-symbol allowance alone, the multicast wait less the span (the
4468
4942
  * catalog tolerance or the measured delivery gap). Undefined for any other
4469
- * block.
4943
+ * block. While a keyframe overlay is installed, the block waits for its
4944
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
4945
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
4946
+ * resolution is what releases the frames behind it, and failing it early
4947
+ * released them past a keyframe the overlay was still rebuilding, which
4948
+ * then arrived stale. The release gate lets them go instead
4949
+ * (isoRepairlessWaitMs).
4470
4950
  */
4471
4951
  #lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
4952
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
4472
4953
  const authoredLength = this.#blockAuthoredLengths.get(key);
4473
- const rsbLength = this.#blockRsbLengths.get(key);
4474
- if (authoredLength === void 0 || rsbLength === void 0) return void 0;
4475
- let present = this.#blockSourceCounts.get(key) ?? 0;
4476
- const received = this.#blockSourceEsis.get(key);
4477
- for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
4478
- if (present + rsbLength >= authoredLength) return void 0;
4479
4954
  const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
4480
4955
  if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
4481
4956
  return void 0;
4482
4957
  }
4483
- return this.#multicastWaitMs(config) - config.interleaveDepthMs;
4958
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
4959
+ }
4960
+ /**
4961
+ * A repair stated the block, and its sources plus every symbol its repair
4962
+ * group carries (RSB_length) are short of its SSB_length.
4963
+ */
4964
+ #groupCannotComplete(key) {
4965
+ const authoredLength = this.#blockAuthoredLengths.get(key);
4966
+ const rsbLength = this.#blockRsbLengths.get(key);
4967
+ if (authoredLength === void 0 || rsbLength === void 0) return false;
4968
+ let present = this.#blockSourceCounts.get(key) ?? 0;
4969
+ const received = this.#blockSourceEsis.get(key);
4970
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
4971
+ return present + rsbLength < authoredLength;
4972
+ }
4973
+ /**
4974
+ * How long a loss only a late source or an installed keyframe overlay can
4975
+ * still fill waits once a later source passed it: the late-symbol
4976
+ * allowance alone (the multicast wait less the span) while no overlay is
4977
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
4978
+ * RAP packet the loss took: a second FEC instance over the same packets
4979
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
4980
+ * span, unrelated to the base's. That packet can complete a stated block
4981
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
4982
+ * first lets the release gate pass the keyframe, whose rebuild then lands
4983
+ * stale. The overlay repair of a packet the loss took goes out within the
4984
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
4985
+ * sent after it, so the loss waits that span plus the larger of the
4986
+ * allowance and the overlay's own tolerance. An overlay that states no
4987
+ * span (its block may then span keyframes), or one whose wait is not
4988
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
4989
+ */
4990
+ #overlayLateWaitMs(packetId, catalogTrackName, config) {
4991
+ const waitMs = this.#multicastWaitMs(config);
4992
+ const allowanceMs = waitMs - config.interleaveDepthMs;
4993
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
4994
+ if (overlay === void 0) return allowanceMs;
4995
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
4996
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
4997
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
4484
4998
  }
4485
4999
  /**
4486
5000
  * Bring an open block's wait in to its late-source wait, when it has one.
@@ -4869,7 +5383,7 @@ var FECManager = class _FECManager {
4869
5383
  blockDeliveryProvenance(sbn, packetId, catalogTrackName) {
4870
5384
  const counts = this.blockPathCount(sbn, packetId, catalogTrackName);
4871
5385
  if (!counts) return "unknown";
4872
- if (counts.moqSymbols > 0) return "mixed";
5386
+ if (counts.moqSymbols > 0 || counts.datagramSymbols > 0) return "mixed";
4873
5387
  if (counts.multicastSymbols > 0) return "multicast";
4874
5388
  return "unknown";
4875
5389
  }
@@ -4896,7 +5410,7 @@ var FECManager = class _FECManager {
4896
5410
  this.#activeBlockDeadlinesMs.clear();
4897
5411
  this.#blockWaitDeadlinesMs.clear();
4898
5412
  this.#repairHoldUntilMs.clear();
4899
- this.#deliveryGaps.reset();
5413
+ for (const estimator of Object.values(this.#deliveryGaps)) estimator.reset();
4900
5414
  this.#pendingWorkerCleanups.clear();
4901
5415
  this.#pendingWorkerCleanupClients.clear();
4902
5416
  for (const bound of this.#pendingWorkerCleanupBounds.values()) clearTimeout(bound.handle);
@@ -4947,6 +5461,7 @@ var FECManager = class _FECManager {
4947
5461
  this.#highestSbn.clear();
4948
5462
  this.#sourceFrontiers.clear();
4949
5463
  this.#isoLocators.clear();
5464
+ this.#runAnchors.clear();
4950
5465
  this.#sourceAnchors.clear();
4951
5466
  this.#trackConfigs.clear();
4952
5467
  this.#fecDecoders.clear();