@blockcast/mmt-container 2.2.0-main.f480a7ede8b1 → 2.2.0-main.fde7aee36726

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 +2163 -303
  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/delivery-catalog.js +68 -0
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/delta-fallback-config.js +39 -1
  26. package/dist/delta-fallback-config.js.map +4 -4
  27. package/dist/fec-manager.d.ts +222 -21
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +875 -131
  30. package/dist/fec-manager.js.map +4 -4
  31. package/dist/fec-state.d.ts +17 -5
  32. package/dist/fec-state.d.ts.map +1 -1
  33. package/dist/fec-state.js +41 -1
  34. package/dist/fec-state.js.map +3 -3
  35. package/dist/fec-worker-setup.js +34 -0
  36. package/dist/fec-worker-setup.js.map +3 -3
  37. package/dist/held-layer-admission.js +34 -0
  38. package/dist/held-layer-admission.js.map +3 -3
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +9 -1
  42. package/dist/index.js.map +2 -2
  43. package/dist/iso-block-locator.d.ts +55 -13
  44. package/dist/iso-block-locator.d.ts.map +1 -1
  45. package/dist/iso-block-locator.js +142 -25
  46. package/dist/iso-block-locator.js.map +3 -3
  47. package/dist/media-router.js.map +1 -1
  48. package/dist/mfu-reassembler.js +34 -0
  49. package/dist/mfu-reassembler.js.map +3 -3
  50. package/dist/mmtp-container-parser.d.ts +72 -10
  51. package/dist/mmtp-container-parser.d.ts.map +1 -1
  52. package/dist/mmtp-container-parser.js +260 -18
  53. package/dist/mmtp-container-parser.js.map +3 -3
  54. package/dist/mmtp-container-parser.no-modules.js +411 -34
  55. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  56. package/dist/mmtp-decode-pipeline.js +260 -18
  57. package/dist/mmtp-decode-pipeline.js.map +3 -3
  58. package/dist/mmtp-fec-session.js +34 -0
  59. package/dist/mmtp-fec-session.js.map +3 -3
  60. package/dist/mmtp-mode-selection.d.ts +48 -0
  61. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  62. package/dist/mmtp-mode-selection.js +79 -0
  63. package/dist/mmtp-mode-selection.js.map +7 -0
  64. package/dist/mmtp-router.d.ts +94 -16
  65. package/dist/mmtp-router.d.ts.map +1 -1
  66. package/dist/mmtp-router.js +754 -78
  67. package/dist/mmtp-router.js.map +4 -4
  68. package/dist/multicast-auth-catalog.js +42 -2
  69. package/dist/multicast-auth-catalog.js.map +3 -3
  70. package/dist/multicast-input.js +42 -2
  71. package/dist/multicast-input.js.map +3 -3
  72. package/dist/multicast-manager.d.ts +121 -4
  73. package/dist/multicast-manager.d.ts.map +1 -1
  74. package/dist/multicast-manager.js +1774 -248
  75. package/dist/multicast-manager.js.map +4 -4
  76. package/dist/multicast-transport.js +70 -2
  77. package/dist/multicast-transport.js.map +4 -4
  78. package/dist/multicast-unwrap.js +34 -0
  79. package/dist/multicast-unwrap.js.map +3 -3
  80. package/dist/no-modules.d.ts +1 -0
  81. package/dist/no-modules.d.ts.map +1 -1
  82. package/dist/no-modules.js +415 -35
  83. package/dist/no-modules.js.map +4 -4
  84. package/dist/phase14-catalog-override.d.ts +2 -1
  85. package/dist/phase14-catalog-override.d.ts.map +1 -1
  86. package/dist/phase14-catalog-override.js +69 -2
  87. package/dist/phase14-catalog-override.js.map +3 -3
  88. package/dist/repair-fetch.d.ts +38 -8
  89. package/dist/repair-fetch.d.ts.map +1 -1
  90. package/dist/repair-fetch.js +336 -27
  91. package/dist/repair-fetch.js.map +3 -3
  92. package/dist/repair-layer-subscriptions.js +34 -0
  93. package/dist/repair-layer-subscriptions.js.map +3 -3
  94. package/dist/signaling.js +34 -0
  95. package/dist/signaling.js.map +3 -3
  96. package/dist/timestamp-codec.js +34 -0
  97. package/dist/timestamp-codec.js.map +3 -3
  98. package/dist/track-session.d.ts.map +1 -1
  99. package/dist/track-session.js +1 -0
  100. package/dist/track-session.js.map +2 -2
  101. package/dist/wasm-mfu-reassembler.js +34 -0
  102. package/dist/wasm-mfu-reassembler.js.map +3 -3
  103. package/dist/wasm-mmtp-container-parser.js +260 -18
  104. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  105. package/package.json +5 -5
  106. package/schemas/catalog.schema.json +2 -2
  107. package/src/block-policy.ts +324 -83
  108. package/src/carp-catalog.ts +165 -5
  109. package/src/catalog-fec-params.ts +1 -0
  110. package/src/codec-utils.ts +121 -1
  111. package/src/fec-manager.ts +835 -66
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +25 -0
  114. package/src/iso-block-locator.ts +148 -31
  115. package/src/mmtp-container-parser.ts +259 -24
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +774 -86
  118. package/src/multicast-manager.ts +262 -16
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +389 -50
  122. package/src/track-session.ts +3 -0
  123. package/test-vectors/catalog/README.md +36 -2
  124. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  127. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  128. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  130. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  131. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  134. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  135. package/test-vectors/catalog/section-codes.json +3 -3
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -27,6 +27,7 @@ import {
27
27
  serial32Precedes,
28
28
  ssbg1FitsSymbol,
29
29
  type FecBlockProfile,
30
+ type FecInstanceGeometry,
30
31
  admitMmtpRepairObject,
31
32
  parseMoqRepairFrameWithHeader,
32
33
  type MMTPHeader,
@@ -54,6 +55,7 @@ import {
54
55
 
55
56
  import { HeldLayerAdmission, heldLayerAnchorHorizon, type FecFailClosedReason } from './held-layer-admission.js'
56
57
  import type { MmtpDeliveryProvenance } from './mfu-reassembler.js'
58
+ import type { AuthoredTiming } from './authored-timing.js'
57
59
  import type {
58
60
  FecWorkerClient,
59
61
  FecTrackStats,
@@ -137,6 +139,20 @@ export interface FecStats {
137
139
  workers: Array<FecTrackStats & { packetId: number }>
138
140
  /** Main-thread repair symbols rejected before dispatch because their size did not match T. */
139
141
  repairSymbolSizeMismatches: number
142
+ /**
143
+ * Repair packets discarded because they arrived on a repair track the
144
+ * catalog does not list for their instance (fec-01 6.3.9): they delimit no
145
+ * block and anchor nothing.
146
+ */
147
+ unlistedRepairTrackRefusals: number
148
+ /**
149
+ * Repair packets the router dropped before any FEC instance saw them,
150
+ * because it could not name the track they repair (BLO-55759): the physical
151
+ * PID is not in the catalog (`unregistered`), or no endpoint on this ingress
152
+ * holds its catalog owner (`ownerAbsent`) or more than one does
153
+ * (`ownerAmbiguous`). Cumulative.
154
+ */
155
+ unresolvedRepairOwnerDrops: UnresolvedRepairOwnerDrops
140
156
  /**
141
157
  * Repair objects discarded on admission (draft-ramadan-moq-fec-core-00 7.5,
142
158
  * draft-ramadan-moq-mmt-02 7.3), per FEC instance and reason. The instance
@@ -147,6 +163,10 @@ export interface FecStats {
147
163
  workerErrors: Record<string, number>
148
164
  }
149
165
 
166
+ /** Why the router could not name a repair packet's owning track. */
167
+ export type UnresolvedRepairOwnerReason = 'unregistered' | 'ownerAbsent' | 'ownerAmbiguous'
168
+ export type UnresolvedRepairOwnerDrops = Record<UnresolvedRepairOwnerReason, number>
169
+
150
170
  /** One FEC instance's repair-object admission discards, by reason. */
151
171
  export type FecRepairObjectRejects = {
152
172
  packetId: number
@@ -168,7 +188,33 @@ export interface FecPacketStats {
168
188
  packetLossRate: number
169
189
  }
170
190
 
171
- export type FecSymbolSource = 'multicast' | 'moq'
191
+ /**
192
+ * The transport a symbol arrived on: a multicast/AMT leg, a reliable MoQ
193
+ * subscription (unicast fallback or an overlap copy), or an "mfu-datagram"
194
+ * subscription (mmt-02 4.3.1), which is a lossy unicast leg. The loss rules
195
+ * ask one of two questions of it, and the answers differ on an ordered
196
+ * relay. Is the symbol in the publisher's own send order: `source !== 'moq'`
197
+ * (late-source shortening, startup partial blocks). Did it reach this
198
+ * manager as a datagram of its own, on a path that loses and reorders:
199
+ * FECManager #lossyDatagramPath (the late-source allowance of a loss-free
200
+ * range, the FEC deadline of a run no repair delimited, the delivery-gap
201
+ * sample). Only the ordered-relay frontier is multicast's.
202
+ */
203
+ export type FecSymbolSource = 'multicast' | 'moq' | 'moq-datagram'
204
+
205
+ /** The lossy paths the delivery-gap estimator samples, each with its own window. */
206
+ export type DeliveryGapPath = 'multicast' | 'moq-datagram'
207
+
208
+ /**
209
+ * What feedRebuiltSourceSymbol did with a rebuilt source: whether its block
210
+ * took it, and the block the synchronous decoder recovered with it, if any.
211
+ */
212
+ export interface RebuiltSourceFeed {
213
+ readonly taken: boolean
214
+ readonly recovered: Uint8Array | null
215
+ }
216
+
217
+ const NOT_TAKEN: RebuiltSourceFeed = Object.freeze({ taken: false, recovered: null })
172
218
 
173
219
  /**
174
220
  * One iso-ssbg1-v1 first-arrival source symbol MmtpRouter holds until a repair
@@ -181,6 +227,13 @@ export interface IsoHeldSource {
181
227
  readonly evidence: SourceSymbolEvidence
182
228
  /** Larger than one ssbg_mode1 symbol: counted, never decoded. */
183
229
  readonly oversized: boolean
230
+ /**
231
+ * Receipt time (performance.now() clock; holdIsoSource stamps it when
232
+ * absent): a run's FEC deadline is anchored at it (isoRepairlessWaitMs),
233
+ * and a loss-free range's late-source allowance counts from it
234
+ * (#lossFreeRunReadyAtMs).
235
+ */
236
+ readonly arrivedAtMs?: number
184
237
  }
185
238
 
186
239
  /**
@@ -202,6 +255,25 @@ export interface UndelimitedIsoLoss {
202
255
  readonly previousBlockStart?: number
203
256
  }
204
257
 
258
+ /**
259
+ * A pending hole the stream ran more than the locator's horizon past before
260
+ * its range repair ended (BLO-52085): no repair can state its blocks any
261
+ * more, and the release gate no longer waits for it.
262
+ */
263
+ export type ExpiredIsoHole = Pick<UndelimitedIsoLoss, 'packetId' | 'catalogTrackName' | 'holeStart' | 'holeLength'>
264
+
265
+ /**
266
+ * What a failed iso-ssbg1-v1 repair-less span was: the `length` SS_IDs from
267
+ * its start, between two stated blocks, of which `sources` arrived. No repair
268
+ * stated the blocks inside it, so the receiver cannot tell its complete
269
+ * blocks from the ones that lost a source: the span failed, not the block
270
+ * that starts it.
271
+ */
272
+ export interface IsoSpanFailure {
273
+ readonly length: number
274
+ readonly sources: number
275
+ }
276
+
205
277
  /**
206
278
  * How the multicast leg hands its symbols to this manager.
207
279
  *
@@ -233,6 +305,8 @@ export interface FecBlockPathCount {
233
305
  catalogTrackName?: string
234
306
  multicastSymbols: number
235
307
  moqSymbols: number
308
+ /** Symbols of an "mfu-datagram" leg: lossy, counted apart from reliable MoQ. */
309
+ datagramSymbols: number
236
310
  complete: boolean
237
311
  }
238
312
 
@@ -292,6 +366,8 @@ export interface FECManagerConfig {
292
366
  * block `unknown` (fail-closed: protected).
293
367
  */
294
368
  geometry?: BlockClassifierGeometry
369
+ /** The track's catalog group duration in ms: one term of an "mfu-datagram" leg's ledger retention. */
370
+ groupDurationMs?: number
295
371
  /**
296
372
  * fec-01 6.3.9: the source track's base repair layers (catalog
297
373
  * `TrackFecParams.repairLayers`). Layer i's held total is
@@ -329,6 +405,7 @@ interface ResolvedFECTrackConfig {
329
405
  trackKind?: TrackKind
330
406
  codec?: string
331
407
  geometry?: BlockClassifierGeometry
408
+ groupDurationMs?: number
332
409
  repairLayers?: readonly FecRepairLayer[]
333
410
  heldLayers?: readonly number[]
334
411
  }
@@ -499,7 +576,12 @@ export class FECManager {
499
576
  #repairHoldUntilMs = new Map<string, number>()
500
577
  // Receiver-measured multicast delivery gap: the late-symbol wait's jitter
501
578
  // term (see DeliveryGapEstimator for the statistic and why).
502
- #deliveryGaps = new DeliveryGapEstimator()
579
+ // One estimator per lossy path, so a hybrid session never lets one leg's
580
+ // stall widen the other's wait; the wait reads the larger peak.
581
+ #deliveryGaps: Record<DeliveryGapPath, DeliveryGapEstimator> = {
582
+ multicast: new DeliveryGapEstimator(),
583
+ 'moq-datagram': new DeliveryGapEstimator(),
584
+ }
503
585
  #lifecycleTrace: FecLifecycleTrace[] = []
504
586
  // Worker-backed timeouts enqueue cleanup behind all prior symbol messages.
505
587
  // Failure remains pending until cleanupComplete acknowledges that queue drain.
@@ -511,10 +593,21 @@ export class FECManager {
511
593
  // 'pending' forever, which would park every later frame of its stream in
512
594
  // the in-order release gate. Each entry owns its handle; the callback
513
595
  // checks it still owns the key, so a settled or reset key is never touched.
514
- #pendingWorkerCleanupBounds = new Map<string, { handle: ReturnType<typeof setTimeout> }>()
596
+ /**
597
+ * Per owed Worker cleanup: the bound on its acknowledgement, when its block
598
+ * was due, and when its cleanup was asked for (see `onCleanupComplete`).
599
+ */
600
+ #pendingWorkerCleanupBounds = new Map<
601
+ string,
602
+ { handle: ReturnType<typeof setTimeout>; dueAtMs: number; askedAtMs: number }
603
+ >()
515
604
  // Source symbol count per track-scoped block — marks complete when K symbols arrive.
516
605
  #blockSourceCounts = new Map<string, number>()
517
606
  #blockSourceEsis = new Map<string, Set<number>>()
607
+ // Source ESIs per block that another FEC instance rebuilt and fed in
608
+ // (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
609
+ // not network arrivals and never make a block clean.
610
+ #blockRebuiltEsis = new Map<string, Set<number>>()
518
611
  // Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
519
612
  // first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
520
613
  // media units, usually before it holds K symbols; under iso-ssbg1-v1
@@ -523,10 +616,14 @@ export class FECManager {
523
616
  // SSB_length source arrivals and recoverable from SSB_length received
524
617
  // symbols; waiting for K fails every one of them.
525
618
  #blockAuthoredLengths = new Map<string, number>()
619
+ // Keys whose authored length is a repair-less span's (#openIsoSpan), until
620
+ // a repair states the block there or the span resolves.
621
+ #isoSpanKeys = new Set<string>()
526
622
  #ssbLengthConflictCount = 0
527
623
  #blockRepairRsIds = new Map<string, Set<number>>()
528
624
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
529
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
625
+ // symbols its repair group carries; 0 for a repair-less span no repair can
626
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
530
627
  #blockRsbLengths = new Map<string, number>()
531
628
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
532
629
  #heldLayerStates = new Map<string, HeldLayerAdmission>()
@@ -681,6 +778,14 @@ export class FECManager {
681
778
  // iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
682
779
  // block only once a repair symbol stated the block's (SS_Start, SSB_length).
683
780
  #isoLocators = new Map<string, IsoBlockLocator<IsoHeldSource>>()
781
+ // The ts of the run behind the gap the release gate last asked about, per
782
+ // stream (isoRepairlessWaitMs), keyed on the frame before the gap: kept, as
783
+ // the source it came from may retire before the run's deadline, and the
784
+ // earliest found wins, so a late frame that becomes the head restarts
785
+ // nothing. It stays until the next run gap: a source discontinuity drops
786
+ // it, and one older than twice the hold ceiling is not this gap's.
787
+ // `counted` once the deadline passed (onUndelimitedRunGap).
788
+ #runAnchors = new Map<string, { fromSsId: number; tsMs: number; counted: boolean }>()
684
789
  #deferIsoGaps = false
685
790
  #isoRepairRefusedCount = 0
686
791
  #isoSourceOversizeCount = 0
@@ -719,6 +824,8 @@ export class FECManager {
719
824
  #workerErrorCounts = new Map<string, number>()
720
825
  #decoderUnavailableEvents = 0
721
826
  #repairSymbolSizeMismatchCount = 0
827
+ #unlistedRepairTrackRefusals = 0
828
+ readonly #unresolvedRepairOwnerDrops: UnresolvedRepairOwnerDrops = { unregistered: 0, ownerAbsent: 0, ownerAmbiguous: 0 }
722
829
 
723
830
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
724
831
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
@@ -730,13 +837,17 @@ export class FECManager {
730
837
  onBlockComplete:
731
838
  | ((sbn: number, packetId: number, catalogTrackName?: string) => void)
732
839
  | null = null
733
- /** A block reached its fail bound. `blockClass` is its class at failure. */
840
+ /**
841
+ * A block reached its fail bound. `blockClass` is its class at failure.
842
+ * `span` is set when what failed is a repair-less span starting at `sbn`.
843
+ */
734
844
  onBlockFailed:
735
845
  | ((
736
846
  sbn: number,
737
847
  packetId: number,
738
848
  catalogTrackName: string | undefined,
739
849
  blockClass: BlockClass,
850
+ span?: IsoSpanFailure,
740
851
  ) => void)
741
852
  | null = null
742
853
  /**
@@ -820,6 +931,8 @@ export class FECManager {
820
931
  * for it, which it must be.
821
932
  */
822
933
  #onUndelimitedLoss: ((loss: UndelimitedIsoLoss) => void) | null = null
934
+ /** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
935
+ #onIsoHoleExpired: ((hole: ExpiredIsoHole) => boolean) | null = null
823
936
  /** A block every symbol of which vanished was created by SBN evidence. */
824
937
  onBlockVanished:
825
938
  | ((sbn: number, packetId: number, catalogTrackName: string | undefined) => void)
@@ -832,6 +945,25 @@ export class FECManager {
832
945
  onSourceDiscontinuity:
833
946
  | ((packetId: number, catalogTrackName: string | undefined) => void)
834
947
  | null = null
948
+ /** The FEC deadline of a run no repair delimited passed, releasing the gap behind it (once per gap). */
949
+ onUndelimitedRunGap:
950
+ | ((packetId: number, catalogTrackName: string | undefined) => void)
951
+ | null = null
952
+ /**
953
+ * The span and tolerance the catalog states for a keyframe overlay
954
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
955
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
956
+ * undefined while none is installed. A stated block only a late source
957
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
958
+ * late source can fill, also wait for that overlay's repair
959
+ * (#overlayLateWaitMs).
960
+ */
961
+ keyframeOverlayTiming:
962
+ | ((
963
+ packetId: number,
964
+ catalogTrackName: string | undefined,
965
+ ) => Pick<FecInstanceGeometry, 'interleaveDepthMs' | 'reorderToleranceMs'> | undefined)
966
+ | null = null
835
967
 
836
968
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
837
969
  /**
@@ -1474,7 +1606,12 @@ export class FECManager {
1474
1606
  timer.handle = null
1475
1607
  this.#requestRepair(sbn, packetId, catalogTrackName)
1476
1608
  }
1477
- timer.handle = setTimeout(onFire, Math.max(0, deadlineMs - performance.now()))
1609
+ timer.handle = setTimeout(
1610
+ onFire,
1611
+ this.#receiptAtMs === undefined
1612
+ ? Math.max(0, deadlineMs - performance.now())
1613
+ : this.#receiptTimerDelayMs(deadlineMs, 0),
1614
+ )
1478
1615
  this.#repairDeadlines.set(key, timer)
1479
1616
  }
1480
1617
 
@@ -1668,6 +1805,12 @@ export class FECManager {
1668
1805
  * Vanished blocks are not enumerated here: their starts are unknown until a
1669
1806
  * repair states them. The SS_IDs between two stated blocks become one
1670
1807
  * repair-less span when the later block's repair arrives (placeIsoRepair).
1808
+ *
1809
+ * A `held` source arrived before its block was known and is fed only now
1810
+ * that a repair, a span or a closed hole placed it: how far its block start
1811
+ * then lies behind the frontier measures how long the receiver held it, not
1812
+ * where the stream was, so only its SS_ID and packet_sequence_number judge
1813
+ * it (BLO-52085).
1671
1814
  */
1672
1815
  #noteSbnSeen(
1673
1816
  sbn: number,
@@ -1676,6 +1819,7 @@ export class FECManager {
1676
1819
  symbol: 'source' | 'repair',
1677
1820
  packetSequenceNumber?: number,
1678
1821
  ssId = sbn,
1822
+ held = false,
1679
1823
  ): void {
1680
1824
  const streamKey = this.#streamKey(packetId, catalogTrackName)
1681
1825
  // Arrival at FEC, not receipt (withReceiptTime): this bounds how far SS_ID
@@ -1712,6 +1856,7 @@ export class FECManager {
1712
1856
  // one continuous SBN sequence.
1713
1857
  this.#classifiers.get(streamKey)?.noteSourceDiscontinuity()
1714
1858
  this.#noSpanRaps.delete(streamKey)
1859
+ this.#runAnchors.delete(streamKey)
1715
1860
  this.#highestSbn.set(streamKey, { sbn, atMs: now })
1716
1861
  this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
1717
1862
  if (psn === undefined) this.#sourceAnchors.delete(streamKey)
@@ -1732,7 +1877,7 @@ export class FECManager {
1732
1877
  }
1733
1878
  if (!this.#blockPrecedes(previous.sbn, sbn)) {
1734
1879
  if (symbol === 'source' && window !== null && this.#blockPrecedes(sbn, previous.sbn) && (
1735
- this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) ||
1880
+ (!held && this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId)) ||
1736
1881
  (psn !== undefined && anchor !== undefined && serial32Precedes(ssId, anchor.ssId) &&
1737
1882
  psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))
1738
1883
  )) {
@@ -1941,7 +2086,7 @@ export class FECManager {
1941
2086
  consider(geometry, this.#parseStreamKey(streamKey).packetId)
1942
2087
  }
1943
2088
  for (const [packetId, config] of this.#trackConfigs) consider(config.geometry, packetId)
1944
- this.#deliveryGaps.setWindowMs(windowMs)
2089
+ for (const estimator of Object.values(this.#deliveryGaps)) estimator.setWindowMs(windowMs)
1945
2090
  }
1946
2091
 
1947
2092
  /**
@@ -1955,7 +2100,7 @@ export class FECManager {
1955
2100
  * stream order and never feeds the estimator.
1956
2101
  */
1957
2102
  #multicastWaitMs(config: ResolvedFECTrackConfig): number {
1958
- return this.#waitForGapMs(config, this.#deliveryGaps.peakGapMs(performance.now()))
2103
+ return this.#waitForGapMs(config, this.#peakDeliveryGapMs())
1959
2104
  }
1960
2105
 
1961
2106
  /**
@@ -1963,7 +2108,7 @@ export class FECManager {
1963
2108
  * catalog window, so this is a catalog quantity that no measurement moves.
1964
2109
  */
1965
2110
  #maxMulticastWaitMs(config: ResolvedFECTrackConfig): number {
1966
- return this.#waitForGapMs(config, this.#deliveryGaps.windowMs ?? 0)
2111
+ return this.#waitForGapMs(config, this.#deliveryGaps.multicast.windowMs ?? 0)
1967
2112
  }
1968
2113
 
1969
2114
  #waitForGapMs(config: ResolvedFECTrackConfig, gapMs: number): number {
@@ -2086,21 +2231,28 @@ export class FECManager {
2086
2231
  this.#blockWaitDeadlinesMs.delete(key)
2087
2232
  this.#repairHoldUntilMs.delete(key)
2088
2233
  this.#traceLifecycle('timeout-queued', sbn, packetId, catalogTrackName)
2089
- this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName)
2234
+ this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs)
2090
2235
  }
2091
- timer.handle = setTimeout(onFire, Math.max(1, Math.ceil(deadlineMs - nowMs)))
2236
+ timer.handle = setTimeout(
2237
+ onFire,
2238
+ this.#receiptAtMs === undefined
2239
+ ? Math.max(1, Math.ceil(deadlineMs - nowMs))
2240
+ : this.#receiptTimerDelayMs(deadlineMs, 1),
2241
+ )
2092
2242
  this.#activeBlocks.set(key, timer)
2093
2243
  this.#indexBlockKey(key, sbn, packetId)
2094
2244
  }
2095
2245
 
2096
2246
  /**
2097
2247
  * Hand a block whose delivery is over to its decoder for finalization: the
2098
- * datagram deadline fired, or the ordered relay moved past it.
2248
+ * datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
2249
+ * is when it was due: its deadline, or now.
2099
2250
  */
2100
2251
  #finalizeExpiredBlock(
2101
2252
  sbn: number,
2102
2253
  packetId: number,
2103
2254
  catalogTrackName: string | undefined,
2255
+ dueAtMs = performance.now(),
2104
2256
  ): void {
2105
2257
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
2106
2258
  // A vanished block that never received a symbol holds no decoder state
@@ -2124,7 +2276,7 @@ export class FECManager {
2124
2276
  if (workerClient) {
2125
2277
  this.#pendingWorkerCleanups.add(key)
2126
2278
  this.#pendingWorkerCleanupClients.set(key, workerClient)
2127
- this.#boundOwedCleanup(key, packetId, workerClient)
2279
+ this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs)
2128
2280
  workerClient.cleanup(sbn)
2129
2281
  } else {
2130
2282
  const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client
@@ -2221,6 +2373,9 @@ export class FECManager {
2221
2373
  ...((config.geometry ?? previous.geometry) === undefined
2222
2374
  ? {}
2223
2375
  : { geometry: config.geometry ?? previous.geometry }),
2376
+ ...((config.groupDurationMs ?? previous.groupDurationMs) === undefined
2377
+ ? {}
2378
+ : { groupDurationMs: config.groupDurationMs ?? previous.groupDurationMs }),
2224
2379
  ...((config.repairLayers ?? previous.repairLayers) === undefined
2225
2380
  ? {}
2226
2381
  : { repairLayers: config.repairLayers ?? previous.repairLayers }),
@@ -2377,6 +2532,11 @@ export class FECManager {
2377
2532
  }
2378
2533
  }
2379
2534
 
2535
+ /** Count a repair packet the router dropped for want of an owning track (BLO-55759). */
2536
+ countUnresolvedRepairOwner(reason: UnresolvedRepairOwnerReason): void {
2537
+ this.#unresolvedRepairOwnerDrops[reason]++
2538
+ }
2539
+
2380
2540
  get fecStats(): FecStats {
2381
2541
  const s = this.#fecStats
2382
2542
  const affected = s.blocksRecovered + s.blocksFailed
@@ -2422,6 +2582,8 @@ export class FECManager {
2422
2582
  packetId,
2423
2583
  })),
2424
2584
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
2585
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
2586
+ unresolvedRepairOwnerDrops: { ...this.#unresolvedRepairOwnerDrops },
2425
2587
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
2426
2588
  workerErrors: Object.fromEntries(this.#workerErrorCounts),
2427
2589
  }
@@ -2454,6 +2616,17 @@ export class FECManager {
2454
2616
  this.#startupRepairFailOpenPackets.clear()
2455
2617
  }
2456
2618
 
2619
+ /**
2620
+ * Start a new "mfu-datagram" leg (mmt-02 4.3.1) without discarding
2621
+ * track/decoder state: the same join-boundary rules as a multicast join,
2622
+ * since the leg starts at an arbitrary datagram too. It resets the whole
2623
+ * join boundary of this manager, a multicast ordered-relay frontier
2624
+ * included, so a host gives the leg a manager of its own.
2625
+ */
2626
+ beginLegJoin(): void {
2627
+ this.beginMulticastJoin()
2628
+ }
2629
+
2457
2630
  /** How the multicast leg currently delivers symbols. */
2458
2631
  get multicastSymbolDelivery(): MulticastSymbolDelivery {
2459
2632
  return this.#multicastSymbolDelivery
@@ -2479,8 +2652,11 @@ export class FECManager {
2479
2652
  }
2480
2653
  if (delivery === this.#multicastSymbolDelivery) return
2481
2654
  // A different delivery path: gaps measured on the old one say nothing
2482
- // about it (and ordered-relay never feeds the estimator).
2483
- this.#deliveryGaps.reset()
2655
+ // about it (and ordered-relay never feeds the estimator), and a run
2656
+ // anchored on its receipts is not timed on the new one. The leg's
2657
+ // estimator is not the multicast provider's to reset.
2658
+ this.#deliveryGaps.multicast.reset()
2659
+ this.#runAnchors.clear()
2484
2660
  if (delivery === 'ordered-relay') {
2485
2661
  for (const [packetId, config] of this.#trackConfigs) {
2486
2662
  this.#orderedHorizonBlocksFor(packetId, config)
@@ -2541,7 +2717,9 @@ export class FECManager {
2541
2717
  }
2542
2718
  resetMap(this.#blockSourceCounts)
2543
2719
  resetMap(this.#blockSourceEsis)
2720
+ resetMap(this.#blockRebuiltEsis)
2544
2721
  resetMap(this.#blockAuthoredLengths)
2722
+ resetSet(this.#isoSpanKeys)
2545
2723
  resetMap(this.#blockRepairRsIds)
2546
2724
  resetMap(this.#blockRsbLengths)
2547
2725
  resetMap(this.#heldLayerStates)
@@ -2572,6 +2750,7 @@ export class FECManager {
2572
2750
  resetMap(this.#highestSbn)
2573
2751
  resetMap(this.#sourceFrontiers)
2574
2752
  resetMap(this.#isoLocators)
2753
+ resetMap(this.#runAnchors)
2575
2754
  resetMap(this.#sourceAnchors)
2576
2755
  this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName))
2577
2756
  this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName))
@@ -2673,7 +2852,9 @@ export class FECManager {
2673
2852
  dropMap(this.#pendingWorkerCleanupClients)
2674
2853
  dropMap(this.#blockSourceCounts)
2675
2854
  dropMap(this.#blockSourceEsis)
2855
+ dropMap(this.#blockRebuiltEsis)
2676
2856
  dropMap(this.#blockAuthoredLengths)
2857
+ dropSet(this.#isoSpanKeys)
2677
2858
  dropMap(this.#blockRepairRsIds)
2678
2859
  dropMap(this.#blockRsbLengths)
2679
2860
  dropMap(this.#blockPathCounts)
@@ -2687,6 +2868,7 @@ export class FECManager {
2687
2868
  dropMap(this.#highestSbn)
2688
2869
  dropMap(this.#sourceFrontiers)
2689
2870
  dropMap(this.#isoLocators)
2871
+ dropMap(this.#runAnchors)
2690
2872
  dropMap(this.#sourceAnchors)
2691
2873
  dropMap(this.#classifiers)
2692
2874
  dropMap(this.#noSpanRaps)
@@ -2782,14 +2964,16 @@ export class FECManager {
2782
2964
  this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? this.#trackConfig(packetId).k
2783
2965
  const isSourceSymbol = esi >= 0 && esi < sourceSymbols
2784
2966
  const isStartupPartial = this.#startupPartialBlocks.has(blockKey)
2967
+ // The join-boundary rules are about loss, so they hold on every lossy
2968
+ // path: a reliable MoQ symbol is never a join partial.
2785
2969
  const isReadyMulticastRepair =
2786
2970
  this.#startupRequireRepairReady &&
2787
- source === 'multicast' &&
2971
+ source !== 'moq' &&
2788
2972
  !isSourceSymbol &&
2789
2973
  this.#startupRepairReadyPackets.has(streamKey)
2790
2974
  const awaitingMulticastRepair =
2791
2975
  this.#startupRequireRepairReady &&
2792
- source === 'multicast' &&
2976
+ source !== 'moq' &&
2793
2977
  !this.#startupRepairReadyPackets.has(streamKey) &&
2794
2978
  !this.#startupRepairFailOpenPackets.has(streamKey)
2795
2979
  if (awaitingMulticastRepair) {
@@ -2857,6 +3041,7 @@ export class FECManager {
2857
3041
  ...(catalogTrackName === undefined ? {} : { catalogTrackName }),
2858
3042
  multicastSymbols: 0,
2859
3043
  moqSymbols: 0,
3044
+ datagramSymbols: 0,
2860
3045
  complete: false,
2861
3046
  }
2862
3047
  // The block's absolute anchor (fecBlockDeadlineMs): the receiver-local
@@ -2867,6 +3052,7 @@ export class FECManager {
2867
3052
  const anchorMs = this.#blockAnchorsMs.get(blockKey)
2868
3053
  if (anchorMs === undefined || receivedAtMs < anchorMs) this.#blockAnchorsMs.set(blockKey, receivedAtMs)
2869
3054
  if (source === 'multicast') counts.multicastSymbols++
3055
+ else if (source === 'moq-datagram') counts.datagramSymbols++
2870
3056
  else counts.moqSymbols++
2871
3057
  this.#blockPathCounts.set(blockKey, counts)
2872
3058
  this.#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName)
@@ -2892,7 +3078,7 @@ export class FECManager {
2892
3078
  }
2893
3079
  }
2894
3080
 
2895
- if (isSourceSymbol && source === 'multicast') {
3081
+ if (isSourceSymbol && source !== 'moq') {
2896
3082
  this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), (sbn + esi) >>> 0, packetId, catalogTrackName)
2897
3083
  }
2898
3084
 
@@ -2998,8 +3184,22 @@ export class FECManager {
2998
3184
  * DeliveryGapEstimator). Datagram delivery only.
2999
3185
  */
3000
3186
  noteMulticastArrival(packetId: number, packetSequenceNumber: number): void {
3001
- if (this.#multicastSymbolDelivery !== 'datagram') return
3002
- this.#deliveryGaps.noteArrival(performance.now(), packetId, packetSequenceNumber)
3187
+ this.noteArrival('multicast', packetId, packetSequenceNumber)
3188
+ }
3189
+ /**
3190
+ * Record one MMTP packet arrival on a lossy path for that path's
3191
+ * delivery-gap measurement: the multicast leg (datagram delivery only; an
3192
+ * ordered relay settles by stream order) or an "mfu-datagram" leg, whose
3193
+ * datagrams are always a lossy path (#lossyDatagramPath).
3194
+ */
3195
+ noteArrival(path: DeliveryGapPath, packetId: number, packetSequenceNumber: number): void {
3196
+ if (!this.#lossyDatagramPath(path)) return
3197
+ this.#deliveryGaps[path].noteArrival(performance.now(), packetId, packetSequenceNumber)
3198
+ }
3199
+ /** The largest delivery gap any lossy path measured over its window. */
3200
+ #peakDeliveryGapMs(): number {
3201
+ const now = performance.now()
3202
+ return Math.max(...Object.values(this.#deliveryGaps).map((estimator) => estimator.peakGapMs(now)))
3003
3203
  }
3004
3204
  /**
3005
3205
  * Resolved per-track multicast late-symbol wait in milliseconds: the span
@@ -3013,16 +3213,18 @@ export class FECManager {
3013
3213
  * Largest multicast delivery gap measured over the current window (ms), and
3014
3214
  * that window (undefined: held since the last reset). Diagnostics.
3015
3215
  */
3016
- multicastDeliveryGap(): { peakGapMs: number; windowMs: number | undefined } {
3216
+ multicastDeliveryGap(path: DeliveryGapPath = 'multicast'): { peakGapMs: number; windowMs: number | undefined } {
3017
3217
  return {
3018
- peakGapMs: this.#deliveryGaps.peakGapMs(performance.now()),
3019
- windowMs: this.#deliveryGaps.windowMs,
3218
+ peakGapMs: this.#deliveryGaps[path].peakGapMs(performance.now()),
3219
+ windowMs: this.#deliveryGaps[path].windowMs,
3020
3220
  }
3021
3221
  }
3022
3222
  /**
3023
3223
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
3024
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
3025
- * Undefined for a block that is not open.
3224
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
3225
+ * repair-less span states its length, and RSB_length 0 when it is longer
3226
+ * than K, since no repair can reach it). Undefined for a block that is not
3227
+ * open.
3026
3228
  */
3027
3229
  blockSymbolCounts(
3028
3230
  sbn: number,
@@ -3105,8 +3307,9 @@ export class FECManager {
3105
3307
  return true
3106
3308
  }
3107
3309
  /**
3108
- * Drop a block's repair hold: its FETCH ended without delivering. The block
3109
- * falls back to its multicast wait, which may already have passed.
3310
+ * Drop a block's repair hold: its FETCH ended without delivering, or brought
3311
+ * back only a repair that cannot complete it. The block falls back to its
3312
+ * multicast wait, which may already have passed.
3110
3313
  */
3111
3314
  releaseRepairHold(sbn: number, packetId: number, catalogTrackName?: string): void {
3112
3315
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
@@ -3126,6 +3329,27 @@ export class FECManager {
3126
3329
  const config = this.#trackConfigs.get(packetId)
3127
3330
  return config === undefined ? undefined : this.#blockLifetimeMs(config)
3128
3331
  }
3332
+ /**
3333
+ * How long an "mfu-datagram" leg's duplicate ledgers must remember a packet
3334
+ * so a legal reorder never reads as a publisher restart: one block span,
3335
+ * the reorder tolerance (`timeoutMs` is span + tolerance) and one group,
3336
+ * since a datagram may trail the stream by a whole group behind a joining
3337
+ * FETCH (mmt-02 6.1 step 3). The group is the catalog group duration
3338
+ * (`groupDurationMs`), whatever the track kind; a video track configured
3339
+ * without one falls back to its keyframe interval (one GOP per group).
3340
+ * Undefined for an unconfigured packet id.
3341
+ */
3342
+ datagramLegLedgerRetentionMsForPacket(packetId: number): number | undefined {
3343
+ const config = this.#trackConfigs.get(packetId)
3344
+ if (config === undefined) return undefined
3345
+ const geometry = config.geometry
3346
+ const groupMs = config.groupDurationMs ?? (
3347
+ geometry?.trackKind === 'video' && geometry.mode === 'classifying'
3348
+ ? (geometry.keyframeInterval.ticks / geometry.keyframeInterval.timescale) * 1000
3349
+ : 0
3350
+ )
3351
+ return config.timeoutMs + (Number.isFinite(groupMs) ? groupMs : 0)
3352
+ }
3129
3353
  /**
3130
3354
  * How long a terminal (clean, recovered or failed) block stays authoritative,
3131
3355
  * for late symbols and for the in-order release gate. It is also the gate's
@@ -3156,7 +3380,7 @@ export class FECManager {
3156
3380
  }
3157
3381
  const trackConfig = this.#trackConfigs.get(packetId)
3158
3382
  if (trackConfig === undefined) return undefined
3159
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig))
3383
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)))
3160
3384
  }
3161
3385
 
3162
3386
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
@@ -3204,6 +3428,9 @@ export class FECManager {
3204
3428
  for (const key of [...this.#isoLocators.keys()]) {
3205
3429
  if (this.#belongsToPacket(key, packetId)) this.#isoLocators.delete(key)
3206
3430
  }
3431
+ for (const key of [...this.#runAnchors.keys()]) {
3432
+ if (this.#belongsToPacket(key, packetId)) this.#runAnchors.delete(key)
3433
+ }
3207
3434
  }
3208
3435
 
3209
3436
  /**
@@ -3267,8 +3494,9 @@ export class FECManager {
3267
3494
  ): boolean {
3268
3495
  const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
3269
3496
  const evictedBefore = locator.heldEvicted
3270
- const held = locator.hold(ssId, source)
3271
- if (held && source.source === 'multicast') this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName)
3497
+ const held = locator.hold(ssId, source.arrivedAtMs === undefined ? { ...source, arrivedAtMs: this.#receiptNow() } : source)
3498
+ this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
3499
+ if (held && source.source !== 'moq') this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName)
3272
3500
  const evicted = locator.heldEvicted - evictedBefore
3273
3501
  if (evicted > 0) {
3274
3502
  const before = this.#isoHeldEvictedCount
@@ -3296,17 +3524,26 @@ export class FECManager {
3296
3524
  ssStart: number,
3297
3525
  ssbLength: number,
3298
3526
  ): IsoRepairPlacement<IsoHeldSource> {
3299
- const placement = this.#growingIsoLocatorFor(packetId, catalogTrackName).placeRepair(ssStart, ssbLength)
3527
+ const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
3528
+ const placement = locator.placeRepair(ssStart, ssbLength)
3529
+ this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
3300
3530
  if (placement.status !== 'placed') {
3301
3531
  this.#isoRepairRefusedCount++
3302
3532
  if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
3303
3533
  console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`)
3304
3534
  }
3535
+ // The repair FETCH of a span's first group brought back a shorter block:
3536
+ // the span holds more than one, so that group cannot complete it, and
3537
+ // holding the span (and every frame behind it) for the FETCH buys
3538
+ // nothing. It falls back to its multicast wait.
3539
+ if (placement.ofSpan !== undefined) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName)
3305
3540
  return placement
3306
3541
  }
3542
+ // A repair states the block at its SS_Start: a span the locator kept
3543
+ // there is now that one block (IsoBlockLocator.placeRepair).
3544
+ this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName))
3307
3545
  if (placement.span !== undefined) this.#openIsoSpan(placement.span, packetId, catalogTrackName)
3308
3546
  if (placement.hole !== undefined) {
3309
- const locator = this.#isoLocatorFor(packetId, catalogTrackName)
3310
3547
  const hole = placement.hole.block
3311
3548
  const previous = locator.blockEndingAt(hole.start)
3312
3549
  const loss: UndelimitedIsoLoss = {
@@ -3328,18 +3565,38 @@ export class FECManager {
3328
3565
  * `handler`, instead of a repair-less span; null restores spans. Set by the
3329
3566
  * range repair scheduler; applies to every stream from its next gap. The
3330
3567
  * handler and the deferral are one setting, so no hole is ever created with
3331
- * nobody to close it.
3568
+ * nobody to close it. `onExpired` is told of each pending hole the stream
3569
+ * runs past the locator's horizon (BLO-52085): returning true, it closes
3570
+ * the hole (`closeIsoHoles`), so the span it leaves still fails and is
3571
+ * reported; otherwise the hole is discarded with its sources.
3332
3572
  */
3333
- setUndelimitedLossHandler(handler: ((loss: UndelimitedIsoLoss) => void) | null): void {
3573
+ setUndelimitedLossHandler(
3574
+ handler: ((loss: UndelimitedIsoLoss) => void) | null,
3575
+ onExpired: ((hole: ExpiredIsoHole) => boolean) | null = null,
3576
+ ): void {
3334
3577
  this.#onUndelimitedLoss = handler
3578
+ this.#onIsoHoleExpired = handler === null ? null : onExpired
3335
3579
  this.#deferIsoGaps = handler !== null
3336
3580
  for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps
3337
3581
  }
3338
3582
 
3583
+ /** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
3584
+ #settleExpiredIsoHoles(
3585
+ locator: IsoBlockLocator<IsoHeldSource>,
3586
+ packetId: number,
3587
+ catalogTrackName: string | undefined,
3588
+ ): void {
3589
+ for (const hole of locator.takeExpiredHoles()) {
3590
+ const expired: ExpiredIsoHole = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length }
3591
+ if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length)
3592
+ }
3593
+ }
3594
+
3339
3595
  /**
3340
- * The range repair for a hole ended: every hole still pending inside
3341
- * `[start, start + length)` becomes a repair-less span. Returns those spans
3342
- * with the held sources they placed, for the caller to feed (MmtpRouter).
3596
+ * The range repair for a hole ended: every hole inside `[start, start +
3597
+ * length)`, pending or expired, becomes a repair-less span. Returns those
3598
+ * spans with the held sources they placed, for the caller to feed
3599
+ * (MmtpRouter).
3343
3600
  */
3344
3601
  closeIsoHoles(
3345
3602
  packetId: number,
@@ -3361,6 +3618,17 @@ export class FECManager {
3361
3618
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
3362
3619
  * SS_ID of which vanished resolves through its deadline like any vanished
3363
3620
  * block.
3621
+ *
3622
+ * A span longer than K holds more than one block (SSB_length <= K), and the
3623
+ * locator states no block inside a span, only one exactly its range
3624
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
3625
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
3626
+ * Group of it (group-cannot-complete). Every span still keeps its whole
3627
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
3628
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
3629
+ * gate lets those frames go once only a late source can fill the gap
3630
+ * before them, as long after they arrived as the gap's decision allows
3631
+ * (isoRepairlessWaitMs).
3364
3632
  */
3365
3633
  #openIsoSpan(
3366
3634
  span: { readonly block: IsoBlockRange; readonly placed: readonly unknown[] },
@@ -3368,7 +3636,16 @@ export class FECManager {
3368
3636
  catalogTrackName: string | undefined,
3369
3637
  ): void {
3370
3638
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName)
3371
- if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length)
3639
+ // A span's key is always new here. An authored length is set only here or
3640
+ // from a repair stating that block (#noteAuthoredLength), and the locator
3641
+ // opens a span only where no repair stated a block, so none can precede
3642
+ // it. Were one to, the guard would skip the RSB_length 0 that keeps the
3643
+ // repair scheduler from FETCHing a long span's first Group.
3644
+ if (!this.#blockAuthoredLengths.has(key)) {
3645
+ this.#blockAuthoredLengths.set(key, span.block.length)
3646
+ this.#isoSpanKeys.add(key)
3647
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0)
3648
+ }
3372
3649
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true)
3373
3650
  }
3374
3651
 
@@ -3376,7 +3653,12 @@ export class FECManager {
3376
3653
  * Resolution of the SS_IDs strictly between two released frames' SS_IDs on
3377
3654
  * an iso-ssbg1-v1 stream, for in-order frame release: null while a block
3378
3655
  * that could hold them is pending or not yet stated by a repair, else the
3379
- * starts of the blocks that failed or vanished.
3656
+ * starts of the blocks that failed or vanished. SS_IDs no repair has
3657
+ * delimited yet that all arrived lost nothing and wait for no repair, only
3658
+ * the late-source allowance after the datagram of a lossy path that clocks
3659
+ * them arrived (#lossFreeRunReadyAtMs), and not even that when none of them
3660
+ * came as one; one missing makes a run that waits as one block
3661
+ * (isoRepairlessWaitMs).
3380
3662
  *
3381
3663
  * `untracked` reads as the release gate reads it (MmtpRouter
3382
3664
  * #createFecReleaseGate): a block holding either released frame's SS_ID
@@ -3394,7 +3676,19 @@ export class FECManager {
3394
3676
  ): readonly number[] | null {
3395
3677
  if (!serial32Precedes(fromSsId, toSsId) || serial32Distance(fromSsId, toSsId) <= 1) return []
3396
3678
  const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))
3397
- if (!locator || !locator.coversBetween(fromSsId, toSsId)) return null
3679
+ if (!locator) return null
3680
+ // SS_IDs past coverage that all arrived lost nothing, so no repair need
3681
+ // delimit them; a run of them the receiver lacks is one block, which
3682
+ // isoRepairlessWaitMs times.
3683
+ const run = locator.undelimitedBetween(fromSsId, toSsId)
3684
+ if (run?.missing !== undefined) return null
3685
+ if (run !== null) {
3686
+ const config = this.#trackConfigs.get(packetId)
3687
+ const readyAtMs = config === undefined ? undefined : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId)
3688
+ if (readyAtMs !== undefined && this.#receiptNow() < readyAtMs) return null
3689
+ }
3690
+ if (locator.coverageEnd === undefined) return []
3691
+ if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return null
3398
3692
  const highest = this.highestSbn(packetId, catalogTrackName)
3399
3693
  const lost: number[] = []
3400
3694
  for (const block of locator.blocksBetween(fromSsId, toSsId)) {
@@ -3416,6 +3710,220 @@ export class FECManager {
3416
3710
  return lost
3417
3711
  }
3418
3712
 
3713
+ /**
3714
+ * When undelimited SS_IDs from `runStart` up to `toSsId` that all arrived
3715
+ * stop holding its frame: the late-source allowance after the receipt of
3716
+ * a datagram of a lossy path (#lossyDatagramPath: a multicast datagram, or
3717
+ * one of an "mfu-datagram" leg). Until then a frame between them may still
3718
+ * complete from a packet with no SS_ID (an untagged FT=0/FT=1 reordered
3719
+ * behind the next frame), and a repair may delimit them. The receipt is
3720
+ * `toSsId`'s own when it is held from such a datagram. Otherwise (its
3721
+ * packet came only as an overlap copy or from a MoQ stream, or was evicted
3722
+ * or retired) it is the newest among those SS_IDs, every one of which is
3723
+ * held and states its path. So the time moves at most once, when the
3724
+ * head's own datagram copy arrives while its frame waits or its held
3725
+ * source is dropped, and never on a later ask.
3726
+ *
3727
+ * Undefined, so the range releases at once, when no SS_ID of it came as
3728
+ * such a datagram: a MoQ arrival, an ordered relay's and the frame's own
3729
+ * are no clock for datagram reordering (#lossyReceiptMs). Undefined too
3730
+ * on a track with no catalog span, which states no allowance: the local
3731
+ * timeout is a cleanup bound, and isoRepairlessWaitMs arms no wake there,
3732
+ * so a wait would hold the frame until the next packet. The cost, on
3733
+ * multicast and on the leg too: an untagged FT=0/FT=1 reordered behind
3734
+ * the next frame of such a track is dropped stale.
3735
+ */
3736
+ #lossFreeRunReadyAtMs(
3737
+ config: ResolvedFECTrackConfig,
3738
+ locator: IsoBlockLocator<IsoHeldSource>,
3739
+ runStart: number,
3740
+ toSsId: number,
3741
+ ): number | undefined {
3742
+ if (!FECManager.#hasCatalogTiming(config)) return undefined
3743
+ let clockMs = this.#lossyReceiptMs(locator.heldSource(toSsId))
3744
+ if (clockMs === undefined) {
3745
+ for (let ssId = runStart; ssId !== toSsId; ssId = (ssId + 1) >>> 0) {
3746
+ const atMs = this.#lossyReceiptMs(locator.heldSource(ssId))
3747
+ if (atMs !== undefined && (clockMs === undefined || atMs > clockMs)) clockMs = atMs
3748
+ }
3749
+ }
3750
+ if (clockMs === undefined) return undefined
3751
+ return clockMs + Math.max(0, this.#multicastWaitMs(config) - config.interleaveDepthMs)
3752
+ }
3753
+
3754
+ /**
3755
+ * Receipt time of a held source that came as a datagram of a lossy path
3756
+ * (#lossyDatagramPath), else undefined: a MoQ stream and an ordered relay
3757
+ * deliver in order, so their arrivals clock no reorder allowance and no
3758
+ * FEC deadline. The path is the one the feed stated (IsoHeldSource.source,
3759
+ * and MulticastSymbolDelivery for a multicast source), never a guess.
3760
+ */
3761
+ #lossyReceiptMs(held: IsoHeldSource | undefined): number | undefined {
3762
+ return held !== undefined && this.#lossyDatagramPath(held.source) ? held.arrivedAtMs : undefined
3763
+ }
3764
+
3765
+ /**
3766
+ * The one path predicate of the loss gates: whether a symbol fed as
3767
+ * `source` reached this manager as a datagram of its own, on a path that
3768
+ * loses and reorders (mmt-02 Section 2, a datagram leg). A multicast
3769
+ * symbol does unless its provider declared an ordered relay. An
3770
+ * "mfu-datagram" object always does (4.3.1): MulticastSymbolDelivery is
3771
+ * the multicast provider's statement and is never read for the leg. A MoQ
3772
+ * stream object never does, a stream copy of the leg included.
3773
+ */
3774
+ #lossyDatagramPath(source: FecSymbolSource): boolean {
3775
+ return source === 'moq-datagram' || (source === 'multicast' && this.#multicastSymbolDelivery === 'datagram')
3776
+ }
3777
+
3778
+ /**
3779
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
3780
+ * between two released frames' SS_IDs once only a late source can still
3781
+ * fill them, else undefined. That is when every one missing (neither
3782
+ * arrived nor held) lies in a repair-less span longer than K, which no
3783
+ * repair can state a block of (#openIsoSpan), or in a stated block its
3784
+ * own repair group cannot complete every SS_ID of which it misses lies
3785
+ * between them (so the gap's decision covers all it lost), and a source of
3786
+ * a lossy leg (multicast, or an "mfu-datagram" leg's datagram) at or past
3787
+ * `toSsId` arrived, so each is lost or reordered behind it (a MoQ source
3788
+ * shows nothing: MoQ streams overtake one another). The span or block
3789
+ * itself keeps its own wait.
3790
+ *
3791
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
3792
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
3793
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
3794
+ * Then the frame waits as a stated block its group cannot complete does
3795
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
3796
+ * overlay's span plus the larger of the allowance and its tolerance, or,
3797
+ * for an overlay that states no span, the span's whole wait (undefined).
3798
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
3799
+ * the gap holds a stated block's loss.
3800
+ *
3801
+ * A run of SS_IDs no repair has delimited yet, one of which never arrived,
3802
+ * is one block of its own instead (draft-ramadan-moq-fec-multicast-00,
3803
+ * Receiver Repair Policy; on an "mfu-datagram" leg fec-core-00 9.3 and
3804
+ * mmt-02 5.3.3): the frame then waits for that block's FEC deadline,
3805
+ * whatever the flags: ts plus the whole multicast wait (fec-core-00 9.3),
3806
+ * ts the receipt of the lowest held source above the run that came as a
3807
+ * datagram of a lossy path (#lossyDatagramPath), up to the newest
3808
+ * (fec-multicast-00, Deadline Anchoring; under reordering at or after the
3809
+ * draft's first signal, never before). The wait returned counts from
3810
+ * `arrivedAtMs`, the frame's arrival; without it, it is the whole wait.
3811
+ * With no such source held (never arrived, retired, or evicted, or every
3812
+ * one from a MoQ stream or an ordered relay) the frame keeps the hold
3813
+ * ceiling: a stream arrival is no clock for a datagram deadline.
3814
+ */
3815
+ isoRepairlessWaitMs(
3816
+ packetId: number,
3817
+ catalogTrackName: string | undefined,
3818
+ fromSsId: number,
3819
+ toSsId: number,
3820
+ rapMayHide = false,
3821
+ rapNext = false,
3822
+ arrivedAtMs?: number,
3823
+ ): number | undefined {
3824
+ const config = this.#trackConfigs.get(packetId)
3825
+ if (config === undefined || !FECManager.#hasCatalogTiming(config)) return undefined
3826
+ const streamKey = this.#streamKey(packetId, catalogTrackName)
3827
+ const locator = this.#isoLocators.get(streamKey)
3828
+ if (locator === undefined) return undefined
3829
+ const run = locator.undelimitedBetween(fromSsId, toSsId)
3830
+ const readyAtMs = run === null || run.missing !== undefined ? undefined : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId)
3831
+ if (readyAtMs !== undefined && this.#receiptNow() < readyAtMs) {
3832
+ return Math.max(0, readyAtMs - (arrivedAtMs ?? this.#receiptNow()))
3833
+ }
3834
+ const newestSource = locator.newestSource
3835
+ if (newestSource === undefined || serial32Precedes(newestSource, toSsId)) return undefined
3836
+ // A run past coverage the receiver lacks an SS_ID of is one block of the
3837
+ // instance. A repair may delimit it until its FEC deadline, so once the
3838
+ // delimited SS_IDs before it resolved the frame waits for that deadline,
3839
+ // longer than any overlay wait. Only a held datagram of a lossy path
3840
+ // anchors it (#lossyReceiptMs): an overlap copy is never held, and a MoQ
3841
+ // stream overtakes the others. A multicast source on an ordered relay is
3842
+ // none either, so the scan below finds no ts there and the frame keeps
3843
+ // the hold ceiling, as a pause there says nothing of loss. The delivery
3844
+ // mode is not read here on its own: it is the multicast provider's
3845
+ // statement, and would deny an "mfu-datagram" leg's run its deadline.
3846
+ // Settle a run by stream order (#withinOrderedHorizon) if a relay ever
3847
+ // runs without repair.
3848
+ if (run?.missing !== undefined) {
3849
+ if (this.isoSpanResolution(packetId, catalogTrackName, fromSsId, run.start) === null) return undefined
3850
+ // An anchor older than twice the hold ceiling is another run's: the
3851
+ // gate flushes a frame at the ceiling, so the same `from` SS_ID came
3852
+ // again (a publisher restart that reuses SS_IDs, or the 2^32 wrap).
3853
+ const kept = this.#runAnchors.get(streamKey)
3854
+ const anchor =
3855
+ kept?.fromSsId === fromSsId &&
3856
+ this.#receiptNow() - kept.tsMs <= 2 * (config.interleaveDepthMs + 2 * this.#blockLifetimeMs(config))
3857
+ ? kept
3858
+ : undefined
3859
+ let tsMs = anchor?.tsMs
3860
+ for (let ssId = (run.missing + 1) >>> 0; !serial32Precedes(newestSource, ssId); ssId = (ssId + 1) >>> 0) {
3861
+ const atMs = this.#lossyReceiptMs(locator.heldSource(ssId))
3862
+ if (atMs === undefined) continue
3863
+ if (tsMs === undefined || atMs < tsMs) tsMs = atMs
3864
+ break
3865
+ }
3866
+ if (tsMs === undefined) return undefined
3867
+ const waitMs = this.#multicastWaitMs(config)
3868
+ let counted = anchor?.counted === true
3869
+ if (!counted && tsMs + waitMs <= this.#receiptNow()) {
3870
+ counted = true
3871
+ this.onUndelimitedRunGap?.(packetId, catalogTrackName)
3872
+ }
3873
+ this.#runAnchors.set(streamKey, { fromSsId, tsMs, counted })
3874
+ return arrivedAtMs === undefined ? waitMs : Math.max(0, tsMs + waitMs - arrivedAtMs)
3875
+ }
3876
+ // SS_IDs past coverage that all arrived hold no loss, so they wait for no
3877
+ // repair to delimit them.
3878
+ if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return undefined
3879
+ let repairless = false
3880
+ let stated = false
3881
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
3882
+ const key = this.#blockKey(block.start, packetId, catalogTrackName)
3883
+ if (this.#completedBlocks.has(key)) continue
3884
+ if (block.span && block.length > locator.kMax) {
3885
+ repairless = true
3886
+ continue
3887
+ }
3888
+ const received = this.#blockSourceEsis.get(key)
3889
+ const rebuilt = this.#blockRebuiltEsis.get(key)
3890
+ let missesInGap = false
3891
+ let missesOutside = false
3892
+ // A rebuilt source is present outside the gap but missed inside it.
3893
+ // Outside, the question is what the block's decoder lacks beyond this
3894
+ // gap, and it holds a rebuilt source (#groupCannotComplete). Inside, it
3895
+ // is what the base path lost between the two frames. A base recovery
3896
+ // does not route a rebuilt packet again (MmtpRouter
3897
+ // #routeVerifiedFecSymbols), so only the overlay route delivers it, and
3898
+ // its frame may not have reached the gate yet (a head held for its FT=1,
3899
+ // BLO-53369). The two differ only when every SS_ID a block misses in the
3900
+ // gap was rebuilt: the later frame then waits for the gap's blocks to
3901
+ // resolve (undefined), which is conservative.
3902
+ for (let esi = 0; esi < block.length; esi++) {
3903
+ const ssId = serial32Add(block.start, esi)
3904
+ if (received?.has(esi) || locator.isHeld(ssId)) continue
3905
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true
3906
+ else if (!rebuilt?.has(esi)) missesOutside = true
3907
+ }
3908
+ if (!missesInGap) continue
3909
+ // A stated block its own group cannot complete (#lateSourceWaitMs) is
3910
+ // one too, when every SS_ID it misses lies in this gap: the gap's
3911
+ // decision then covers all it lost, so the overlay can rebuild none of
3912
+ // it unless `rapMayHide` or `rapNext`.
3913
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return undefined
3914
+ repairless = stated = true
3915
+ }
3916
+ if (!repairless) return undefined
3917
+ // A gap into the next MPU (`rapNext`) may hold that MPU's FT=0, an overlay
3918
+ // member; rebuilt, it is one more source of a stated block, which its group
3919
+ // may then complete. Such a block keeps #741's overlay wait; a span longer
3920
+ // than K has no group to complete and keeps #742's allowance.
3921
+ const waitMs = rapMayHide || (stated && rapNext)
3922
+ ? this.#overlayLateWaitMs(packetId, catalogTrackName, config)
3923
+ : this.#multicastWaitMs(config) - config.interleaveDepthMs
3924
+ return waitMs === undefined ? undefined : Math.max(0, waitMs)
3925
+ }
3926
+
3419
3927
  /**
3420
3928
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
3421
3929
  * the sources held now for a block no repair has stated yet, and the held
@@ -3489,11 +3997,43 @@ export class FECManager {
3489
3997
  * it does not. A stream with no classifier yet has shown nothing against it,
3490
3998
  * and neither has a stream without catalog timing until it releases two
3491
3999
  * RAPs inside one MPU.
4000
+ *
4001
+ * With catalog timing and a `gap` inside one MPU, between the authored
4002
+ * timing of the frames on either side, it also takes the catalog keyframe
4003
+ * interval to rule a keyframe out of the gap
4004
+ * (`BlockClassifier.keyframeFreeBetween`, fec-multicast-00 Block
4005
+ * Classification item 3), and no source held between the frames' SS_IDs
4006
+ * may carry the RAP flag or another MPU's number (item 1 read on the held
4007
+ * packets: a RAP the loss cut in two is never released, so the frames
4008
+ * alone cannot show it); anything unknown counts as a keyframe.
3492
4009
  */
3493
- mpuBoundsRapsFor(packetId: number, catalogTrackName?: string): boolean {
4010
+ mpuBoundsRapsFor(
4011
+ packetId: number,
4012
+ catalogTrackName?: string,
4013
+ gap?: {
4014
+ readonly mpu: number
4015
+ readonly from?: AuthoredTiming
4016
+ readonly to?: AuthoredTiming
4017
+ readonly fromSsId?: number
4018
+ readonly toSsId?: number
4019
+ },
4020
+ ): boolean {
3494
4021
  const streamKey = this.#streamKey(packetId, catalogTrackName)
3495
4022
  if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true
3496
- return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true
4023
+ const classifier = this.#classifiers.get(streamKey)
4024
+ if (gap === undefined) return classifier?.mpuBoundsRaps ?? true
4025
+ const { mpu, from, to, fromSsId, toSsId } = gap
4026
+ if (fromSsId !== undefined && toSsId !== undefined) {
4027
+ const run = this.#isoLocators.get(streamKey)?.undelimitedBetween(
4028
+ fromSsId,
4029
+ toSsId,
4030
+ ({ evidence }) => evidence.rap || (evidence.mpu !== undefined && evidence.mpu !== mpu),
4031
+ )
4032
+ if (run?.flagged) return false
4033
+ }
4034
+ return classifier !== undefined && from !== undefined && to !== undefined &&
4035
+ from.mediaTimescale === to.mediaTimescale &&
4036
+ classifier.keyframeFreeBetween(mpu, from.decodeTime, to.decodeTime, from.mediaTimescale)
3497
4037
  }
3498
4038
 
3499
4039
  /** A block's class now, or frozen at its resolution. */
@@ -3520,7 +4060,9 @@ export class FECManager {
3520
4060
 
3521
4061
  /**
3522
4062
  * Record a RAP frame released in order, for the classifier's RAP-spacing
3523
- * invariant (consecutive MPUs exactly one keyframe interval apart).
4063
+ * invariant (consecutive MPUs exactly one keyframe interval apart) and,
4064
+ * with its decode time, as the MPU start gap decisions measure the catalog
4065
+ * keyframe interval from (mpuBoundsRapsFor).
3524
4066
  */
3525
4067
  noteReleasedRap(
3526
4068
  packetId: number,
@@ -3528,6 +4070,7 @@ export class FECManager {
3528
4070
  mpu: number,
3529
4071
  presentationTime: bigint,
3530
4072
  mediaTimescale: number,
4073
+ decodeTime?: bigint,
3531
4074
  ): void {
3532
4075
  if (!this.#trackConfigs.has(packetId)) return
3533
4076
  if (!this.#hasCatalogTimingForPacket(packetId)) {
@@ -3545,6 +4088,7 @@ export class FECManager {
3545
4088
  mpu,
3546
4089
  presentationTime,
3547
4090
  mediaTimescale,
4091
+ decodeTime,
3548
4092
  ),
3549
4093
  )
3550
4094
  }
@@ -3847,13 +4391,27 @@ export class FECManager {
3847
4391
 
3848
4392
  client.onCleanupComplete((sbn: number) => {
3849
4393
  if (this.#releasedWorkerClients.has(client)) return
3850
- const cleanupKeys = [...this.#pendingWorkerCleanups].filter((key) => {
4394
+ const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client)
4395
+ const cleanupKeys = owed.filter((key) => {
3851
4396
  const block = this.#parseBlockKey(key)
3852
- return block.packetId === packetId &&
3853
- block.sbn === sbn &&
3854
- this.#pendingWorkerCleanupClients.get(key) === client
4397
+ return block.packetId === packetId && block.sbn === sbn
3855
4398
  })
3856
- for (const key of cleanupKeys) this.#settleOwedCleanup(key, 'cleanup-ack')
4399
+ // A cleanup is a queue-drain barrier: the Worker took every symbol fed
4400
+ // before it was asked for first, so every block already due by then
4401
+ // is settled by this acknowledgement too, not one barrier later. The
4402
+ // client sends one barrier at a time, and the blocks a repair walk
4403
+ // stated in one span are due together (BLO-52085). That holds only
4404
+ // while no block is fed a symbol after its dueAtMs, which is its
4405
+ // receipt-scoped deadline, not when feeding stopped: a symbol fed
4406
+ // between that deadline and the block's timer, after another block's
4407
+ // barrier was asked for, would find the block settled (failed) one
4408
+ // barrier early. Walks end before D-28 (walkDeadlineAt), so that window
4409
+ // is the timer's lateness alone; whatever feeds a block past its dueAtMs
4410
+ // must leave it to its own barrier.
4411
+ const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity))
4412
+ const due = owed.filter((key) =>
4413
+ !cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs)
4414
+ for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, 'cleanup-ack')
3857
4415
  })
3858
4416
 
3859
4417
  client.onError((msg: string, code?: FecWorkerErrorCode) => {
@@ -3935,9 +4493,11 @@ export class FECManager {
3935
4493
  * fail deadline already passed, so failing it is the decision that deadline
3936
4494
  * made. A late ack then finds nothing owed and is a no-op.
3937
4495
  */
3938
- #boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient): void {
4496
+ #boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient, dueAtMs: number): void {
3939
4497
  this.#clearOwedCleanupBound(key)
3940
4498
  const bound = {
4499
+ dueAtMs,
4500
+ askedAtMs: performance.now(),
3941
4501
  handle: setTimeout(() => {
3942
4502
  if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return
3943
4503
  this.#pendingWorkerCleanupBounds.delete(key)
@@ -4068,7 +4628,22 @@ export class FECManager {
4068
4628
  this.#isoSourceOversizeCount++
4069
4629
  return null
4070
4630
  }
4071
- const sbn = located.block.start
4631
+ return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start)
4632
+ }
4633
+
4634
+ /**
4635
+ * Hand one placed source symbol to the stream's decoder: its Worker, which
4636
+ * answers through onFrame (null here), or its synchronous decoder, whose
4637
+ * recovered block is returned. `sbn` is the SS_Start of the block a repair
4638
+ * stated for `ssId`.
4639
+ */
4640
+ #feedDecoderSource(
4641
+ packetId: number,
4642
+ ssId: number,
4643
+ symbolData: Uint8Array,
4644
+ catalogTrackName: string | undefined,
4645
+ sbn: number,
4646
+ ): Uint8Array | null {
4072
4647
  const blockKey = this.#blockKey(sbn, packetId, catalogTrackName)
4073
4648
  const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey)
4074
4649
 
@@ -4113,6 +4688,97 @@ export class FECManager {
4113
4688
  return recovered
4114
4689
  }
4115
4690
 
4691
+ /**
4692
+ * Feed a source symbol of this stream that another FEC instance over the
4693
+ * same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
4694
+ * caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
4695
+ * BLO-52085). It joins its block's decoder as a received source would, so
4696
+ * it reduces the erasures the block still has to solve, but it is not a
4697
+ * network arrival: no transport accounting, no classification evidence,
4698
+ * no deadline refresh, and it never makes a block clean.
4699
+ *
4700
+ * Only a block a repair stated takes one (a repair-less span has no
4701
+ * decoder block). A block that is terminal, or already holds that source,
4702
+ * does not. The symbol is the exact protected packet, unpadded, as
4703
+ * feedSourceSymbol takes it.
4704
+ *
4705
+ * `recovered` is the block the synchronous decoder completed with it; the
4706
+ * caller routes it and completes the block, as for any recovery. When
4707
+ * every source of the block is then present, received or rebuilt, and no
4708
+ * decoder returned it (a Worker answers asynchronously, and reports such a
4709
+ * block as clean on its own side), the block is completed here as
4710
+ * recovered, with nothing left to route.
4711
+ */
4712
+ feedRebuiltSourceSymbol(
4713
+ packetId: number,
4714
+ ssId: number,
4715
+ symbolData: Uint8Array,
4716
+ catalogTrackName?: string,
4717
+ ): RebuiltSourceFeed {
4718
+ if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN
4719
+ const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId)
4720
+ if (located === null || located.block.span) return NOT_TAKEN
4721
+ if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN
4722
+ const sbn = located.block.start
4723
+ const key = this.#blockKey(sbn, packetId, catalogTrackName)
4724
+ if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN
4725
+ let rebuilt = this.#blockRebuiltEsis.get(key)
4726
+ if (rebuilt?.has(located.esi)) return NOT_TAKEN
4727
+ if (rebuilt === undefined) {
4728
+ rebuilt = new Set()
4729
+ this.#blockRebuiltEsis.set(key, rebuilt)
4730
+ }
4731
+ const config = this.#trackConfigs.get(packetId)
4732
+ const wasShort = config !== undefined &&
4733
+ this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== undefined
4734
+ rebuilt.add(located.esi)
4735
+ const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn)
4736
+ if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
4737
+ // The late-source cut assumed only a late source could complete this
4738
+ // block; with this source its group can, so it gets a full multicast
4739
+ // wait again, counted from now.
4740
+ // ponytail: from now, not from its sources, so it can close up to one
4741
+ // multicast wait after its uncut deadline; at most once per block, since
4742
+ // a rebuilt source only adds to what the block holds and the cut cannot
4743
+ // apply to it again. Keep the uncut deadline and re-arm to it if a lab
4744
+ // run shows that wait.
4745
+ if (wasShort && this.#activeBlocks.has(key) &&
4746
+ this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config!) === undefined) {
4747
+ this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config!))
4748
+ }
4749
+ }
4750
+ return { taken: true, recovered }
4751
+ }
4752
+
4753
+ /**
4754
+ * A block that holds every one of its `length` sources, received or
4755
+ * rebuilt by another instance, with at least one rebuilt, is recovered:
4756
+ * every packet of it was delivered, by its own arrival or by the instance
4757
+ * that rebuilt it, so nothing is routed. Returns whether it completed it.
4758
+ */
4759
+ #completeWhenSourcesPresent(
4760
+ key: string,
4761
+ sbn: number,
4762
+ length: number,
4763
+ packetId: number,
4764
+ catalogTrackName: string | undefined,
4765
+ ): boolean {
4766
+ const rebuilt = this.#blockRebuiltEsis.get(key)
4767
+ if (rebuilt === undefined || this.#completedBlocks.has(key)) return false
4768
+ let present = rebuilt.size
4769
+ for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++
4770
+ if (present < length) return false
4771
+ this.#traceLifecycle('recovered', sbn, packetId, catalogTrackName)
4772
+ this.countRecovery(packetId, sbn, catalogTrackName)
4773
+ this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
4774
+ if (catalogTrackName === undefined) {
4775
+ this.onBlockComplete?.(sbn, packetId)
4776
+ } else {
4777
+ this.onBlockComplete?.(sbn, packetId, catalogTrackName)
4778
+ }
4779
+ return true
4780
+ }
4781
+
4116
4782
  /**
4117
4783
  * fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
4118
4784
  * exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
@@ -4193,7 +4859,10 @@ export class FECManager {
4193
4859
  this.#layerAnchorHorizon(packetId),
4194
4860
  this.#sourceFrontiers.get(streamKey)?.sbn,
4195
4861
  )
4196
- if (verdict === 'discard') return false
4862
+ if (verdict === 'discard') {
4863
+ this.#unlistedRepairTrackRefusals++
4864
+ return false
4865
+ }
4197
4866
  if (verdict !== undefined) {
4198
4867
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName)
4199
4868
  return false
@@ -4380,9 +5049,11 @@ export class FECManager {
4380
5049
  * its sources in send order, so one that moves the stream's newest source
4381
5050
  * position past a block leaves the sources that block still misses
4382
5051
  * reordered behind it at best: it shortens the wait of every block it
4383
- * passed that only a late source can complete. MoQ is left out: its streams
4384
- * can overtake one another, so a MoQ source shows nothing about the sources
4385
- * sent before it.
5052
+ * passed that only a late source can complete. Reliable MoQ is left out:
5053
+ * its streams can overtake one another, so a MoQ source shows nothing
5054
+ * about the sources sent before it. An "mfu-datagram" leg is in: its
5055
+ * datagrams leave the publisher in send order and reorder only within the
5056
+ * path's tolerance, as multicast does.
4386
5057
  */
4387
5058
  #noteMulticastSource(
4388
5059
  locator: IsoBlockLocator<IsoHeldSource>,
@@ -4395,7 +5066,7 @@ export class FECManager {
4395
5066
  // The blocks whose last SS_ID lies in [previous, ssId): this source
4396
5067
  // passed them and the previous newest one had not.
4397
5068
  for (const block of locator.blocksBetween((previous - 1) >>> 0, ssId)) {
4398
- if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
5069
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
4399
5070
  this.#shortenUnrecoverableWait(
4400
5071
  this.#blockKey(block.start, packetId, catalogTrackName),
4401
5072
  block.start,
@@ -4414,7 +5085,13 @@ export class FECManager {
4414
5085
  * covers repair symbols paced after its sources, buys it nothing: it waits
4415
5086
  * the late-symbol allowance alone, the multicast wait less the span (the
4416
5087
  * catalog tolerance or the measured delivery gap). Undefined for any other
4417
- * block.
5088
+ * block. While a keyframe overlay is installed, the block waits for its
5089
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
5090
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
5091
+ * resolution is what releases the frames behind it, and failing it early
5092
+ * released them past a keyframe the overlay was still rebuilding, which
5093
+ * then arrived stale. The release gate lets them go instead
5094
+ * (isoRepairlessWaitMs).
4418
5095
  */
4419
5096
  #lateSourceWaitMs(
4420
5097
  key: string,
@@ -4423,15 +5100,64 @@ export class FECManager {
4423
5100
  catalogTrackName: string | undefined,
4424
5101
  config: ResolvedFECTrackConfig,
4425
5102
  ): number | undefined {
4426
- const authoredLength = this.#blockAuthoredLengths.get(key)
4427
- const rsbLength = this.#blockRsbLengths.get(key)
4428
- if (authoredLength === undefined || rsbLength === undefined) return undefined
4429
- if ((this.#blockSourceCounts.get(key) ?? 0) + rsbLength >= authoredLength) return undefined
5103
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return undefined
5104
+ const authoredLength = this.#blockAuthoredLengths.get(key)!
4430
5105
  const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource
4431
5106
  if (newestSource === undefined || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
4432
5107
  return undefined
4433
5108
  }
4434
- return this.#multicastWaitMs(config) - config.interleaveDepthMs
5109
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config)
5110
+ }
5111
+
5112
+ /**
5113
+ * A repair stated the block, and its sources plus every symbol its repair
5114
+ * group carries (RSB_length) are short of its SSB_length.
5115
+ */
5116
+ #groupCannotComplete(key: string): boolean {
5117
+ const authoredLength = this.#blockAuthoredLengths.get(key)
5118
+ const rsbLength = this.#blockRsbLengths.get(key)
5119
+ if (authoredLength === undefined || rsbLength === undefined) return false
5120
+ // A source another instance rebuilt (feedRebuiltSourceSymbol) is one the
5121
+ // decoder holds: the group need only cover what neither delivered.
5122
+ let present = this.#blockSourceCounts.get(key) ?? 0
5123
+ const received = this.#blockSourceEsis.get(key)
5124
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++
5125
+ return present + rsbLength < authoredLength
5126
+ }
5127
+
5128
+ /**
5129
+ * How long a loss only a late source or an installed keyframe overlay can
5130
+ * still fill waits once a later source passed it: the late-symbol
5131
+ * allowance alone (the multicast wait less the span) while no overlay is
5132
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
5133
+ * RAP packet the loss took: a second FEC instance over the same packets
5134
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
5135
+ * span, unrelated to the base's. That packet can complete a stated block
5136
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
5137
+ * first lets the release gate pass the keyframe, whose rebuild then lands
5138
+ * stale. The overlay repair of a packet the loss took goes out within the
5139
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
5140
+ * sent after it, so the loss waits that span plus the larger of the
5141
+ * allowance and the overlay's own tolerance. An overlay that states no
5142
+ * span (its block may then span keyframes), or one whose wait is not
5143
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
5144
+ */
5145
+ #overlayLateWaitMs(
5146
+ packetId: number,
5147
+ catalogTrackName: string | undefined,
5148
+ config: ResolvedFECTrackConfig,
5149
+ ): number | undefined {
5150
+ const waitMs = this.#multicastWaitMs(config)
5151
+ const allowanceMs = waitMs - config.interleaveDepthMs
5152
+ // Read live. The late-source cut only ever shortens a block's deadline
5153
+ // (#shortenUnrecoverableWait), so a block it armed at the bare allowance
5154
+ // before an overlay was installed, or between a dispose and a reinstall,
5155
+ // keeps that deadline until a source of its own re-arms it.
5156
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName)
5157
+ if (overlay === undefined) return allowanceMs
5158
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0
5159
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0)
5160
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : undefined
4435
5161
  }
4436
5162
 
4437
5163
  /**
@@ -4598,7 +5324,8 @@ export class FECManager {
4598
5324
  * the inactivity deadline on each symbol, records the symbol's in-band
4599
5325
  * classification evidence, and marks the block clean when all of its
4600
5326
  * authored source symbols arrived: the SSB_length a repair symbol declared,
4601
- * otherwise K.
5327
+ * otherwise K. `held` marks a source held unplaced since it arrived and
5328
+ * placed only now (see #noteSbnSeen).
4602
5329
  *
4603
5330
  * Throws for a packetId that was never configured, so a classified block
4604
5331
  * never reads the manager-global K or timeout.
@@ -4609,6 +5336,7 @@ export class FECManager {
4609
5336
  catalogTrackName: string | undefined,
4610
5337
  esi: number,
4611
5338
  evidence: SourceSymbolEvidence,
5339
+ held = false,
4612
5340
  ): void {
4613
5341
  const trackConfig = this.#trackConfigs.get(packetId)
4614
5342
  if (trackConfig === undefined) {
@@ -4630,6 +5358,7 @@ export class FECManager {
4630
5358
  'source',
4631
5359
  evidence.packetSequenceNumber,
4632
5360
  Number.isInteger(esi) ? (sbn + esi) >>> 0 : sbn,
5361
+ held,
4633
5362
  )
4634
5363
 
4635
5364
  // A source ESI at or past the block's authored SSB_length contradicts it;
@@ -4674,6 +5403,20 @@ export class FECManager {
4674
5403
  this.#completeCleanBlock(key, sbn, packetId, catalogTrackName)
4675
5404
  return
4676
5405
  }
5406
+ // A late arrival can be the last source a block lacked besides those
5407
+ // another instance rebuilt (feedRebuiltSourceSymbol).
5408
+ if (
5409
+ this.#blockRebuiltEsis.has(key) &&
5410
+ this.#completeWhenSourcesPresent(
5411
+ key,
5412
+ sbn,
5413
+ this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
5414
+ packetId,
5415
+ catalogTrackName,
5416
+ )
5417
+ ) {
5418
+ return
5419
+ }
4677
5420
 
4678
5421
  this.noteBlockActivity(sbn, packetId, catalogTrackName, true)
4679
5422
 
@@ -4693,7 +5436,9 @@ export class FECManager {
4693
5436
  this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
4694
5437
  this.#blockSourceCounts.delete(key)
4695
5438
  this.#blockSourceEsis.delete(key)
5439
+ this.#blockRebuiltEsis.delete(key)
4696
5440
  this.#blockAuthoredLengths.delete(key)
5441
+ this.#isoSpanKeys.delete(key)
4697
5442
  this.#blockRepairRsIds.delete(key)
4698
5443
  this.#blockRsbLengths.delete(key)
4699
5444
  // BLO-3323 L15: track which SBNs reached K source-symbol arrivals so the
@@ -4735,6 +5480,20 @@ export class FECManager {
4735
5480
  return this.#receiptAtMs ?? performance.now()
4736
5481
  }
4737
5482
 
5483
+ /**
5484
+ * The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
5485
+ * scope: counted from the receipt time, as the timer of a symbol fed when
5486
+ * it was received was, less the whole ms since. So it fires on the tick
5487
+ * that timer would have, never later than a delay counted from now, and
5488
+ * its handler still re-arms a timer that fires before its deadline.
5489
+ * Counted from now, a deadline set from the receipt time is rounded up
5490
+ * from another fraction of a ms (BLO-52085).
5491
+ */
5492
+ #receiptTimerDelayMs(deadlineMs: number, minMs: number): number {
5493
+ const receivedAtMs = this.#receiptAtMs!
5494
+ return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs))
5495
+ }
5496
+
4738
5497
  /**
4739
5498
  * A held packet admitted late arms from its (earlier) receipt time; that
4740
5499
  * never pulls in a deadline later activity already armed. Outside a
@@ -4826,6 +5585,9 @@ export class FECManager {
4826
5585
  catalogTrackName?: string,
4827
5586
  ): void {
4828
5587
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
5588
+ const span: IsoSpanFailure | undefined = this.#isoSpanKeys.delete(key)
5589
+ ? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 }
5590
+ : undefined
4829
5591
  this.#traceLifecycle('failed', sbn, packetId, catalogTrackName)
4830
5592
  this.#clearRepairDeadline(key)
4831
5593
  this.#clearBlockTimer(key)
@@ -4835,6 +5597,7 @@ export class FECManager {
4835
5597
  }
4836
5598
  this.#blockSourceCounts.delete(key)
4837
5599
  this.#blockSourceEsis.delete(key)
5600
+ this.#blockRebuiltEsis.delete(key)
4838
5601
  this.#blockAuthoredLengths.delete(key)
4839
5602
  this.#blockRepairRsIds.delete(key)
4840
5603
  this.#blockRsbLengths.delete(key)
@@ -4844,7 +5607,8 @@ export class FECManager {
4844
5607
  this.#markPathBlockComplete(sbn, packetId, catalogTrackName)
4845
5608
  this.#fecStats.blocksFailed++
4846
5609
  this.#statsForPacket(packetId).blocksFailed++
4847
- this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
5610
+ if (span === undefined) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
5611
+ else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span)
4848
5612
  this.onBlockResolved?.(sbn, packetId, catalogTrackName)
4849
5613
  }
4850
5614
 
@@ -4874,7 +5638,9 @@ export class FECManager {
4874
5638
  this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName)
4875
5639
  this.#blockSourceCounts.delete(key)
4876
5640
  this.#blockSourceEsis.delete(key)
5641
+ this.#blockRebuiltEsis.delete(key)
4877
5642
  this.#blockAuthoredLengths.delete(key)
5643
+ this.#isoSpanKeys.delete(key)
4878
5644
  this.#blockRepairRsIds.delete(key)
4879
5645
  this.#blockRsbLengths.delete(key)
4880
5646
  this.#clearBlockTimer(key)
@@ -4932,7 +5698,7 @@ export class FECManager {
4932
5698
  ): MmtpDeliveryProvenance {
4933
5699
  const counts = this.blockPathCount(sbn, packetId, catalogTrackName)
4934
5700
  if (!counts) return 'unknown'
4935
- if (counts.moqSymbols > 0) return 'mixed'
5701
+ if (counts.moqSymbols > 0 || counts.datagramSymbols > 0) return 'mixed'
4936
5702
  if (counts.multicastSymbols > 0) return 'multicast'
4937
5703
  return 'unknown'
4938
5704
  }
@@ -4967,7 +5733,7 @@ export class FECManager {
4967
5733
  this.#activeBlockDeadlinesMs.clear()
4968
5734
  this.#blockWaitDeadlinesMs.clear()
4969
5735
  this.#repairHoldUntilMs.clear()
4970
- this.#deliveryGaps.reset()
5736
+ for (const estimator of Object.values(this.#deliveryGaps)) estimator.reset()
4971
5737
  this.#pendingWorkerCleanups.clear()
4972
5738
  this.#pendingWorkerCleanupClients.clear()
4973
5739
  for (const bound of this.#pendingWorkerCleanupBounds.values()) clearTimeout(bound.handle)
@@ -4982,7 +5748,9 @@ export class FECManager {
4982
5748
  this.#blockKeysBySbn.clear()
4983
5749
  this.#blockSourceCounts.clear()
4984
5750
  this.#blockSourceEsis.clear()
5751
+ this.#blockRebuiltEsis.clear()
4985
5752
  this.#blockAuthoredLengths.clear()
5753
+ this.#isoSpanKeys.clear()
4986
5754
  this.#blockRepairRsIds.clear()
4987
5755
  this.#blockRsbLengths.clear()
4988
5756
  this.#heldLayerStates.clear()
@@ -5016,6 +5784,7 @@ export class FECManager {
5016
5784
  this.#highestSbn.clear()
5017
5785
  this.#sourceFrontiers.clear()
5018
5786
  this.#isoLocators.clear()
5787
+ this.#runAnchors.clear()
5019
5788
  this.#sourceAnchors.clear()
5020
5789
  this.#trackConfigs.clear()
5021
5790
  this.#fecDecoders.clear()