@blockcast/mmt-container 2.2.0-main.bdefba2a99c2 → 2.2.0-main.c1482ff09fa3

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 (67) hide show
  1. package/dist/browser-runtime.js +1304 -170
  2. package/dist/browser-runtime.js.map +3 -3
  3. package/dist/cmaf-block-assembler.js +92 -1
  4. package/dist/cmaf-block-assembler.js.map +2 -2
  5. package/dist/codec-utils.d.ts.map +1 -1
  6. package/dist/codec-utils.js +92 -1
  7. package/dist/codec-utils.js.map +2 -2
  8. package/dist/delivery-catalog.js +2 -1
  9. package/dist/delivery-catalog.js.map +2 -2
  10. package/dist/delta-fallback-config.js.map +1 -1
  11. package/dist/fec-manager.d.ts +74 -14
  12. package/dist/fec-manager.d.ts.map +1 -1
  13. package/dist/fec-manager.js +419 -61
  14. package/dist/fec-manager.js.map +2 -2
  15. package/dist/fec-worker-setup.js.map +1 -1
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +2 -2
  19. package/dist/iso-block-locator.d.ts +48 -13
  20. package/dist/iso-block-locator.d.ts.map +1 -1
  21. package/dist/iso-block-locator.js +97 -25
  22. package/dist/iso-block-locator.js.map +2 -2
  23. package/dist/iso-bmff-timing.d.ts +10 -1
  24. package/dist/iso-bmff-timing.d.ts.map +1 -1
  25. package/dist/iso-bmff-timing.js +36 -2
  26. package/dist/iso-bmff-timing.js.map +2 -2
  27. package/dist/media-router.js.map +1 -1
  28. package/dist/mmtp-container-parser.d.ts +79 -10
  29. package/dist/mmtp-container-parser.d.ts.map +1 -1
  30. package/dist/mmtp-container-parser.js +299 -27
  31. package/dist/mmtp-container-parser.js.map +2 -2
  32. package/dist/mmtp-container-parser.no-modules.js +301 -30
  33. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  34. package/dist/mmtp-decode-pipeline.js +298 -27
  35. package/dist/mmtp-decode-pipeline.js.map +2 -2
  36. package/dist/mmtp-router.d.ts +34 -8
  37. package/dist/mmtp-router.d.ts.map +1 -1
  38. package/dist/mmtp-router.js +623 -65
  39. package/dist/mmtp-router.js.map +3 -3
  40. package/dist/multicast-manager.d.ts +26 -3
  41. package/dist/multicast-manager.d.ts.map +1 -1
  42. package/dist/multicast-manager.js +1124 -143
  43. package/dist/multicast-manager.js.map +3 -3
  44. package/dist/multicast-transport.js +4 -3
  45. package/dist/multicast-transport.js.map +2 -2
  46. package/dist/no-modules.js +298 -27
  47. package/dist/no-modules.js.map +3 -3
  48. package/dist/repair-fetch.d.ts +38 -8
  49. package/dist/repair-fetch.d.ts.map +1 -1
  50. package/dist/repair-fetch.js +286 -27
  51. package/dist/repair-fetch.js.map +3 -3
  52. package/dist/track-session.d.ts.map +1 -1
  53. package/dist/track-session.js +1 -0
  54. package/dist/track-session.js.map +2 -2
  55. package/dist/wasm-mmtp-container-parser.js +298 -27
  56. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  57. package/package.json +5 -5
  58. package/src/codec-utils.ts +121 -1
  59. package/src/fec-manager.ts +454 -35
  60. package/src/index.ts +3 -0
  61. package/src/iso-block-locator.ts +133 -31
  62. package/src/iso-bmff-timing.ts +40 -1
  63. package/src/mmtp-container-parser.ts +306 -29
  64. package/src/mmtp-router.ts +548 -38
  65. package/src/multicast-manager.ts +118 -14
  66. package/src/repair-fetch.ts +366 -50
  67. package/src/track-session.ts +3 -0
@@ -22,6 +22,7 @@ import {
22
22
  isoBlockContains,
23
23
  isoBlocksBehindLowerBound,
24
24
  parseFecBlockProfile,
25
+ serial32Add,
25
26
  serial32Distance,
26
27
  serial32Precedes,
27
28
  ssbg1FitsSymbol,
@@ -169,6 +170,17 @@ export interface FecPacketStats {
169
170
 
170
171
  export type FecSymbolSource = 'multicast' | 'moq'
171
172
 
173
+ /**
174
+ * What feedRebuiltSourceSymbol did with a rebuilt source: whether its block
175
+ * took it, and the block the synchronous decoder recovered with it, if any.
176
+ */
177
+ export interface RebuiltSourceFeed {
178
+ readonly taken: boolean
179
+ readonly recovered: Uint8Array | null
180
+ }
181
+
182
+ const NOT_TAKEN: RebuiltSourceFeed = Object.freeze({ taken: false, recovered: null })
183
+
172
184
  /**
173
185
  * One iso-ssbg1-v1 first-arrival source symbol MmtpRouter holds until a repair
174
186
  * symbol states its block: the exact protected packet (no SS_ID, unpadded),
@@ -201,6 +213,25 @@ export interface UndelimitedIsoLoss {
201
213
  readonly previousBlockStart?: number
202
214
  }
203
215
 
216
+ /**
217
+ * A pending hole the stream ran more than the locator's horizon past before
218
+ * its range repair ended (BLO-52085): no repair can state its blocks any
219
+ * more, and the release gate no longer waits for it.
220
+ */
221
+ export type ExpiredIsoHole = Pick<UndelimitedIsoLoss, 'packetId' | 'catalogTrackName' | 'holeStart' | 'holeLength'>
222
+
223
+ /**
224
+ * What a failed iso-ssbg1-v1 repair-less span was: the `length` SS_IDs from
225
+ * its start, between two stated blocks, of which `sources` arrived. No repair
226
+ * stated the blocks inside it, so the receiver cannot tell its complete
227
+ * blocks from the ones that lost a source: the span failed, not the block
228
+ * that starts it.
229
+ */
230
+ export interface IsoSpanFailure {
231
+ readonly length: number
232
+ readonly sources: number
233
+ }
234
+
204
235
  /**
205
236
  * How the multicast leg hands its symbols to this manager.
206
237
  *
@@ -510,10 +541,21 @@ export class FECManager {
510
541
  // 'pending' forever, which would park every later frame of its stream in
511
542
  // the in-order release gate. Each entry owns its handle; the callback
512
543
  // checks it still owns the key, so a settled or reset key is never touched.
513
- #pendingWorkerCleanupBounds = new Map<string, { handle: ReturnType<typeof setTimeout> }>()
544
+ /**
545
+ * Per owed Worker cleanup: the bound on its acknowledgement, when its block
546
+ * was due, and when its cleanup was asked for (see `onCleanupComplete`).
547
+ */
548
+ #pendingWorkerCleanupBounds = new Map<
549
+ string,
550
+ { handle: ReturnType<typeof setTimeout>; dueAtMs: number; askedAtMs: number }
551
+ >()
514
552
  // Source symbol count per track-scoped block — marks complete when K symbols arrive.
515
553
  #blockSourceCounts = new Map<string, number>()
516
554
  #blockSourceEsis = new Map<string, Set<number>>()
555
+ // Source ESIs per block that another FEC instance rebuilt and fed in
556
+ // (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
557
+ // not network arrivals and never make a block clean.
558
+ #blockRebuiltEsis = new Map<string, Set<number>>()
517
559
  // Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
518
560
  // first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
519
561
  // media units, usually before it holds K symbols; under iso-ssbg1-v1
@@ -522,10 +564,14 @@ export class FECManager {
522
564
  // SSB_length source arrivals and recoverable from SSB_length received
523
565
  // symbols; waiting for K fails every one of them.
524
566
  #blockAuthoredLengths = new Map<string, number>()
567
+ // Keys whose authored length is a repair-less span's (#openIsoSpan), until
568
+ // a repair states the block there or the span resolves.
569
+ #isoSpanKeys = new Set<string>()
525
570
  #ssbLengthConflictCount = 0
526
571
  #blockRepairRsIds = new Map<string, Set<number>>()
527
572
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
528
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
573
+ // symbols its repair group carries; 0 for a repair-less span no repair can
574
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
529
575
  #blockRsbLengths = new Map<string, number>()
530
576
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
531
577
  #heldLayerStates = new Map<string, HeldLayerAdmission>()
@@ -644,6 +690,10 @@ export class FECManager {
644
690
  // ── Keyframe-protected repair policy (block-policy.ts) ──
645
691
  // One classifier per physical stream, built from that stream's geometry.
646
692
  #classifiers = new Map<string, BlockClassifier>()
693
+ // A stream without catalog timing has no classifier, so the last RAP it
694
+ // released stands in for one: "an MPU boundary bounds its RAPs" holds until
695
+ // a second RAP is released inside one MPU (BLO-52085).
696
+ #noSpanRaps = new Map<string, { mpu: number; presentationTime: bigint; inside: boolean }>()
647
697
  // Geometry a stream-scoped configuration gave one stream (streamKey). ABR
648
698
  // rungs can share a packetId with a different framerate or GOP, so the
649
699
  // packet-level geometry is only the geometry of a packet whose streams
@@ -725,13 +775,17 @@ export class FECManager {
725
775
  onBlockComplete:
726
776
  | ((sbn: number, packetId: number, catalogTrackName?: string) => void)
727
777
  | null = null
728
- /** A block reached its fail bound. `blockClass` is its class at failure. */
778
+ /**
779
+ * A block reached its fail bound. `blockClass` is its class at failure.
780
+ * `span` is set when what failed is a repair-less span starting at `sbn`.
781
+ */
729
782
  onBlockFailed:
730
783
  | ((
731
784
  sbn: number,
732
785
  packetId: number,
733
786
  catalogTrackName: string | undefined,
734
787
  blockClass: BlockClass,
788
+ span?: IsoSpanFailure,
735
789
  ) => void)
736
790
  | null = null
737
791
  /**
@@ -815,6 +869,8 @@ export class FECManager {
815
869
  * for it, which it must be.
816
870
  */
817
871
  #onUndelimitedLoss: ((loss: UndelimitedIsoLoss) => void) | null = null
872
+ /** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
873
+ #onIsoHoleExpired: ((hole: ExpiredIsoHole) => boolean) | null = null
818
874
  /** A block every symbol of which vanished was created by SBN evidence. */
819
875
  onBlockVanished:
820
876
  | ((sbn: number, packetId: number, catalogTrackName: string | undefined) => void)
@@ -1469,7 +1525,12 @@ export class FECManager {
1469
1525
  timer.handle = null
1470
1526
  this.#requestRepair(sbn, packetId, catalogTrackName)
1471
1527
  }
1472
- timer.handle = setTimeout(onFire, Math.max(0, deadlineMs - performance.now()))
1528
+ timer.handle = setTimeout(
1529
+ onFire,
1530
+ this.#receiptAtMs === undefined
1531
+ ? Math.max(0, deadlineMs - performance.now())
1532
+ : this.#receiptTimerDelayMs(deadlineMs, 0),
1533
+ )
1473
1534
  this.#repairDeadlines.set(key, timer)
1474
1535
  }
1475
1536
 
@@ -1663,6 +1724,12 @@ export class FECManager {
1663
1724
  * Vanished blocks are not enumerated here: their starts are unknown until a
1664
1725
  * repair states them. The SS_IDs between two stated blocks become one
1665
1726
  * repair-less span when the later block's repair arrives (placeIsoRepair).
1727
+ *
1728
+ * A `held` source arrived before its block was known and is fed only now
1729
+ * that a repair, a span or a closed hole placed it: how far its block start
1730
+ * then lies behind the frontier measures how long the receiver held it, not
1731
+ * where the stream was, so only its SS_ID and packet_sequence_number judge
1732
+ * it (BLO-52085).
1666
1733
  */
1667
1734
  #noteSbnSeen(
1668
1735
  sbn: number,
@@ -1671,6 +1738,7 @@ export class FECManager {
1671
1738
  symbol: 'source' | 'repair',
1672
1739
  packetSequenceNumber?: number,
1673
1740
  ssId = sbn,
1741
+ held = false,
1674
1742
  ): void {
1675
1743
  const streamKey = this.#streamKey(packetId, catalogTrackName)
1676
1744
  // Arrival at FEC, not receipt (withReceiptTime): this bounds how far SS_ID
@@ -1706,6 +1774,7 @@ export class FECManager {
1706
1774
  // The classifier compares authored order with SBN order only within
1707
1775
  // one continuous SBN sequence.
1708
1776
  this.#classifiers.get(streamKey)?.noteSourceDiscontinuity()
1777
+ this.#noSpanRaps.delete(streamKey)
1709
1778
  this.#highestSbn.set(streamKey, { sbn, atMs: now })
1710
1779
  this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
1711
1780
  if (psn === undefined) this.#sourceAnchors.delete(streamKey)
@@ -1726,7 +1795,7 @@ export class FECManager {
1726
1795
  }
1727
1796
  if (!this.#blockPrecedes(previous.sbn, sbn)) {
1728
1797
  if (symbol === 'source' && window !== null && this.#blockPrecedes(sbn, previous.sbn) && (
1729
- this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) ||
1798
+ (!held && this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId)) ||
1730
1799
  (psn !== undefined && anchor !== undefined && serial32Precedes(ssId, anchor.ssId) &&
1731
1800
  psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))
1732
1801
  )) {
@@ -2080,21 +2149,28 @@ export class FECManager {
2080
2149
  this.#blockWaitDeadlinesMs.delete(key)
2081
2150
  this.#repairHoldUntilMs.delete(key)
2082
2151
  this.#traceLifecycle('timeout-queued', sbn, packetId, catalogTrackName)
2083
- this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName)
2152
+ this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs)
2084
2153
  }
2085
- timer.handle = setTimeout(onFire, Math.max(1, Math.ceil(deadlineMs - nowMs)))
2154
+ timer.handle = setTimeout(
2155
+ onFire,
2156
+ this.#receiptAtMs === undefined
2157
+ ? Math.max(1, Math.ceil(deadlineMs - nowMs))
2158
+ : this.#receiptTimerDelayMs(deadlineMs, 1),
2159
+ )
2086
2160
  this.#activeBlocks.set(key, timer)
2087
2161
  this.#indexBlockKey(key, sbn, packetId)
2088
2162
  }
2089
2163
 
2090
2164
  /**
2091
2165
  * Hand a block whose delivery is over to its decoder for finalization: the
2092
- * datagram deadline fired, or the ordered relay moved past it.
2166
+ * datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
2167
+ * is when it was due: its deadline, or now.
2093
2168
  */
2094
2169
  #finalizeExpiredBlock(
2095
2170
  sbn: number,
2096
2171
  packetId: number,
2097
2172
  catalogTrackName: string | undefined,
2173
+ dueAtMs = performance.now(),
2098
2174
  ): void {
2099
2175
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
2100
2176
  // A vanished block that never received a symbol holds no decoder state
@@ -2118,7 +2194,7 @@ export class FECManager {
2118
2194
  if (workerClient) {
2119
2195
  this.#pendingWorkerCleanups.add(key)
2120
2196
  this.#pendingWorkerCleanupClients.set(key, workerClient)
2121
- this.#boundOwedCleanup(key, packetId, workerClient)
2197
+ this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs)
2122
2198
  workerClient.cleanup(sbn)
2123
2199
  } else {
2124
2200
  const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client
@@ -2289,6 +2365,9 @@ export class FECManager {
2289
2365
  // sibling's change, but the first stream-scoped geometry on a packet
2290
2366
  // does change the siblings that have none (stream-geometry-absent).
2291
2367
  this.#bumpEpoch(packetId)
2368
+ for (const key of [...this.#noSpanRaps.keys()]) {
2369
+ if (this.#belongsToPacket(key, packetId)) this.#noSpanRaps.delete(key)
2370
+ }
2292
2371
  for (const [key, classifier] of [...this.#classifiers]) {
2293
2372
  if (!this.#belongsToPacket(key, packetId)) continue
2294
2373
  const stream = this.#parseStreamKey(key)
@@ -2532,7 +2611,9 @@ export class FECManager {
2532
2611
  }
2533
2612
  resetMap(this.#blockSourceCounts)
2534
2613
  resetMap(this.#blockSourceEsis)
2614
+ resetMap(this.#blockRebuiltEsis)
2535
2615
  resetMap(this.#blockAuthoredLengths)
2616
+ resetSet(this.#isoSpanKeys)
2536
2617
  resetMap(this.#blockRepairRsIds)
2537
2618
  resetMap(this.#blockRsbLengths)
2538
2619
  resetMap(this.#heldLayerStates)
@@ -2565,6 +2646,7 @@ export class FECManager {
2565
2646
  resetMap(this.#isoLocators)
2566
2647
  resetMap(this.#sourceAnchors)
2567
2648
  this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName))
2649
+ this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName))
2568
2650
  this.#bumpEpoch(packetId)
2569
2651
  for (const [sbn, keys] of this.#blockKeysBySbn) {
2570
2652
  for (const key of keys.keys()) {
@@ -2663,7 +2745,9 @@ export class FECManager {
2663
2745
  dropMap(this.#pendingWorkerCleanupClients)
2664
2746
  dropMap(this.#blockSourceCounts)
2665
2747
  dropMap(this.#blockSourceEsis)
2748
+ dropMap(this.#blockRebuiltEsis)
2666
2749
  dropMap(this.#blockAuthoredLengths)
2750
+ dropSet(this.#isoSpanKeys)
2667
2751
  dropMap(this.#blockRepairRsIds)
2668
2752
  dropMap(this.#blockRsbLengths)
2669
2753
  dropMap(this.#blockPathCounts)
@@ -2679,6 +2763,7 @@ export class FECManager {
2679
2763
  dropMap(this.#isoLocators)
2680
2764
  dropMap(this.#sourceAnchors)
2681
2765
  dropMap(this.#classifiers)
2766
+ dropMap(this.#noSpanRaps)
2682
2767
  dropMap(this.#streamGeometries)
2683
2768
  dropSet(this.#pendingWorkerCleanups)
2684
2769
  dropSet(this.#completedBlocks)
@@ -2881,6 +2966,10 @@ export class FECManager {
2881
2966
  }
2882
2967
  }
2883
2968
 
2969
+ if (isSourceSymbol && source === 'multicast') {
2970
+ this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), (sbn + esi) >>> 0, packetId, catalogTrackName)
2971
+ }
2972
+
2884
2973
  return true
2885
2974
  }
2886
2975
 
@@ -3006,8 +3095,10 @@ export class FECManager {
3006
3095
  }
3007
3096
  /**
3008
3097
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
3009
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
3010
- * Undefined for a block that is not open.
3098
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
3099
+ * repair-less span states its length, and RSB_length 0 when it is longer
3100
+ * than K, since no repair can reach it). Undefined for a block that is not
3101
+ * open.
3011
3102
  */
3012
3103
  blockSymbolCounts(
3013
3104
  sbn: number,
@@ -3090,8 +3181,9 @@ export class FECManager {
3090
3181
  return true
3091
3182
  }
3092
3183
  /**
3093
- * Drop a block's repair hold: its FETCH ended without delivering. The block
3094
- * falls back to its multicast wait, which may already have passed.
3184
+ * Drop a block's repair hold: its FETCH ended without delivering, or brought
3185
+ * back only a repair that cannot complete it. The block falls back to its
3186
+ * multicast wait, which may already have passed.
3095
3187
  */
3096
3188
  releaseRepairHold(sbn: number, packetId: number, catalogTrackName?: string): void {
3097
3189
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
@@ -3253,6 +3345,8 @@ export class FECManager {
3253
3345
  const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
3254
3346
  const evictedBefore = locator.heldEvicted
3255
3347
  const held = locator.hold(ssId, source)
3348
+ this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
3349
+ if (held && source.source === 'multicast') this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName)
3256
3350
  const evicted = locator.heldEvicted - evictedBefore
3257
3351
  if (evicted > 0) {
3258
3352
  const before = this.#isoHeldEvictedCount
@@ -3280,17 +3374,26 @@ export class FECManager {
3280
3374
  ssStart: number,
3281
3375
  ssbLength: number,
3282
3376
  ): IsoRepairPlacement<IsoHeldSource> {
3283
- const placement = this.#growingIsoLocatorFor(packetId, catalogTrackName).placeRepair(ssStart, ssbLength)
3377
+ const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
3378
+ const placement = locator.placeRepair(ssStart, ssbLength)
3379
+ this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
3284
3380
  if (placement.status !== 'placed') {
3285
3381
  this.#isoRepairRefusedCount++
3286
3382
  if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
3287
3383
  console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`)
3288
3384
  }
3385
+ // The repair FETCH of a span's first group brought back a shorter block:
3386
+ // the span holds more than one, so that group cannot complete it, and
3387
+ // holding the span (and every frame behind it) for the FETCH buys
3388
+ // nothing. It falls back to its multicast wait.
3389
+ if (placement.ofSpan !== undefined) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName)
3289
3390
  return placement
3290
3391
  }
3392
+ // A repair states the block at its SS_Start: a span the locator kept
3393
+ // there is now that one block (IsoBlockLocator.placeRepair).
3394
+ this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName))
3291
3395
  if (placement.span !== undefined) this.#openIsoSpan(placement.span, packetId, catalogTrackName)
3292
3396
  if (placement.hole !== undefined) {
3293
- const locator = this.#isoLocatorFor(packetId, catalogTrackName)
3294
3397
  const hole = placement.hole.block
3295
3398
  const previous = locator.blockEndingAt(hole.start)
3296
3399
  const loss: UndelimitedIsoLoss = {
@@ -3312,18 +3415,38 @@ export class FECManager {
3312
3415
  * `handler`, instead of a repair-less span; null restores spans. Set by the
3313
3416
  * range repair scheduler; applies to every stream from its next gap. The
3314
3417
  * handler and the deferral are one setting, so no hole is ever created with
3315
- * nobody to close it.
3418
+ * nobody to close it. `onExpired` is told of each pending hole the stream
3419
+ * runs past the locator's horizon (BLO-52085): returning true, it closes
3420
+ * the hole (`closeIsoHoles`), so the span it leaves still fails and is
3421
+ * reported; otherwise the hole is discarded with its sources.
3316
3422
  */
3317
- setUndelimitedLossHandler(handler: ((loss: UndelimitedIsoLoss) => void) | null): void {
3423
+ setUndelimitedLossHandler(
3424
+ handler: ((loss: UndelimitedIsoLoss) => void) | null,
3425
+ onExpired: ((hole: ExpiredIsoHole) => boolean) | null = null,
3426
+ ): void {
3318
3427
  this.#onUndelimitedLoss = handler
3428
+ this.#onIsoHoleExpired = handler === null ? null : onExpired
3319
3429
  this.#deferIsoGaps = handler !== null
3320
3430
  for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps
3321
3431
  }
3322
3432
 
3433
+ /** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
3434
+ #settleExpiredIsoHoles(
3435
+ locator: IsoBlockLocator<IsoHeldSource>,
3436
+ packetId: number,
3437
+ catalogTrackName: string | undefined,
3438
+ ): void {
3439
+ for (const hole of locator.takeExpiredHoles()) {
3440
+ const expired: ExpiredIsoHole = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length }
3441
+ if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length)
3442
+ }
3443
+ }
3444
+
3323
3445
  /**
3324
- * The range repair for a hole ended: every hole still pending inside
3325
- * `[start, start + length)` becomes a repair-less span. Returns those spans
3326
- * with the held sources they placed, for the caller to feed (MmtpRouter).
3446
+ * The range repair for a hole ended: every hole inside `[start, start +
3447
+ * length)`, pending or expired, becomes a repair-less span. Returns those
3448
+ * spans with the held sources they placed, for the caller to feed
3449
+ * (MmtpRouter).
3327
3450
  */
3328
3451
  closeIsoHoles(
3329
3452
  packetId: number,
@@ -3345,6 +3468,14 @@ export class FECManager {
3345
3468
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
3346
3469
  * SS_ID of which vanished resolves through its deadline like any vanished
3347
3470
  * block.
3471
+ *
3472
+ * A span longer than K holds more than one block (SSB_length <= K), and the
3473
+ * locator states no block inside a span, only one exactly its range
3474
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
3475
+ * reach it. Its repair group is empty, so only its own late sources can
3476
+ * complete it, and it waits as a stated block its group cannot complete
3477
+ * does (#lateSourceWaitMs; BLO-52085 D4). A span of K or less may be one
3478
+ * block whose repair is still to come, and keeps the whole wait.
3348
3479
  */
3349
3480
  #openIsoSpan(
3350
3481
  span: { readonly block: IsoBlockRange; readonly placed: readonly unknown[] },
@@ -3352,7 +3483,16 @@ export class FECManager {
3352
3483
  catalogTrackName: string | undefined,
3353
3484
  ): void {
3354
3485
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName)
3355
- if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length)
3486
+ // A span's key is always new here. An authored length is set only here or
3487
+ // from a repair stating that block (#noteAuthoredLength), and the locator
3488
+ // opens a span only where no repair stated a block, so none can precede
3489
+ // it. Were one to, the span would keep the whole wait (no RSB_length),
3490
+ // never fail early.
3491
+ if (!this.#blockAuthoredLengths.has(key)) {
3492
+ this.#blockAuthoredLengths.set(key, span.block.length)
3493
+ this.#isoSpanKeys.add(key)
3494
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0)
3495
+ }
3356
3496
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true)
3357
3497
  }
3358
3498
 
@@ -3470,11 +3610,14 @@ export class FECManager {
3470
3610
  /**
3471
3611
  * Whether an MPU boundary still bounds this stream's RAPs (see
3472
3612
  * `BlockClassifier.mpuBoundsRaps`). Gap decisions drop MPU evidence once
3473
- * it does not. A stream with no classifier yet has shown nothing against it.
3613
+ * it does not. A stream with no classifier yet has shown nothing against it,
3614
+ * and neither has a stream without catalog timing until it releases two
3615
+ * RAPs inside one MPU.
3474
3616
  */
3475
3617
  mpuBoundsRapsFor(packetId: number, catalogTrackName?: string): boolean {
3476
- if (!this.#hasCatalogTimingForPacket(packetId)) return false
3477
- return this.#classifiers.get(this.#streamKey(packetId, catalogTrackName))?.mpuBoundsRaps ?? true
3618
+ const streamKey = this.#streamKey(packetId, catalogTrackName)
3619
+ if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true
3620
+ return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true
3478
3621
  }
3479
3622
 
3480
3623
  /** A block's class now, or frozen at its resolution. */
@@ -3510,7 +3653,15 @@ export class FECManager {
3510
3653
  presentationTime: bigint,
3511
3654
  mediaTimescale: number,
3512
3655
  ): void {
3513
- if (!this.#trackConfigs.has(packetId) || !this.#hasCatalogTimingForPacket(packetId)) return
3656
+ if (!this.#trackConfigs.has(packetId)) return
3657
+ if (!this.#hasCatalogTimingForPacket(packetId)) {
3658
+ const streamKey = this.#streamKey(packetId, catalogTrackName)
3659
+ const last = this.#noSpanRaps.get(streamKey)
3660
+ const inside = last?.inside === true ||
3661
+ (last?.mpu === mpu && last.presentationTime !== presentationTime)
3662
+ this.#noSpanRaps.set(streamKey, { mpu, presentationTime, inside })
3663
+ return
3664
+ }
3514
3665
  this.#applyClassifierChanges(
3515
3666
  packetId,
3516
3667
  catalogTrackName,
@@ -3820,13 +3971,27 @@ export class FECManager {
3820
3971
 
3821
3972
  client.onCleanupComplete((sbn: number) => {
3822
3973
  if (this.#releasedWorkerClients.has(client)) return
3823
- const cleanupKeys = [...this.#pendingWorkerCleanups].filter((key) => {
3974
+ const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client)
3975
+ const cleanupKeys = owed.filter((key) => {
3824
3976
  const block = this.#parseBlockKey(key)
3825
- return block.packetId === packetId &&
3826
- block.sbn === sbn &&
3827
- this.#pendingWorkerCleanupClients.get(key) === client
3977
+ return block.packetId === packetId && block.sbn === sbn
3828
3978
  })
3829
- for (const key of cleanupKeys) this.#settleOwedCleanup(key, 'cleanup-ack')
3979
+ // A cleanup is a queue-drain barrier: the Worker took every symbol fed
3980
+ // before it was asked for first, so every block already due by then
3981
+ // is settled by this acknowledgement too, not one barrier later. The
3982
+ // client sends one barrier at a time, and the blocks a repair walk
3983
+ // stated in one span are due together (BLO-52085). That holds only
3984
+ // while no block is fed a symbol after its dueAtMs, which is its
3985
+ // receipt-scoped deadline, not when feeding stopped: a symbol fed
3986
+ // between that deadline and the block's timer, after another block's
3987
+ // barrier was asked for, would find the block settled (failed) one
3988
+ // barrier early. Walks end before D-28 (walkDeadlineAt), so that window
3989
+ // is the timer's lateness alone; whatever feeds a block past its dueAtMs
3990
+ // must leave it to its own barrier.
3991
+ const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity))
3992
+ const due = owed.filter((key) =>
3993
+ !cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs)
3994
+ for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, 'cleanup-ack')
3830
3995
  })
3831
3996
 
3832
3997
  client.onError((msg: string, code?: FecWorkerErrorCode) => {
@@ -3908,9 +4073,11 @@ export class FECManager {
3908
4073
  * fail deadline already passed, so failing it is the decision that deadline
3909
4074
  * made. A late ack then finds nothing owed and is a no-op.
3910
4075
  */
3911
- #boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient): void {
4076
+ #boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient, dueAtMs: number): void {
3912
4077
  this.#clearOwedCleanupBound(key)
3913
4078
  const bound = {
4079
+ dueAtMs,
4080
+ askedAtMs: performance.now(),
3914
4081
  handle: setTimeout(() => {
3915
4082
  if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return
3916
4083
  this.#pendingWorkerCleanupBounds.delete(key)
@@ -4041,7 +4208,22 @@ export class FECManager {
4041
4208
  this.#isoSourceOversizeCount++
4042
4209
  return null
4043
4210
  }
4044
- const sbn = located.block.start
4211
+ return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start)
4212
+ }
4213
+
4214
+ /**
4215
+ * Hand one placed source symbol to the stream's decoder: its Worker, which
4216
+ * answers through onFrame (null here), or its synchronous decoder, whose
4217
+ * recovered block is returned. `sbn` is the SS_Start of the block a repair
4218
+ * stated for `ssId`.
4219
+ */
4220
+ #feedDecoderSource(
4221
+ packetId: number,
4222
+ ssId: number,
4223
+ symbolData: Uint8Array,
4224
+ catalogTrackName: string | undefined,
4225
+ sbn: number,
4226
+ ): Uint8Array | null {
4045
4227
  const blockKey = this.#blockKey(sbn, packetId, catalogTrackName)
4046
4228
  const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey)
4047
4229
 
@@ -4086,6 +4268,97 @@ export class FECManager {
4086
4268
  return recovered
4087
4269
  }
4088
4270
 
4271
+ /**
4272
+ * Feed a source symbol of this stream that another FEC instance over the
4273
+ * same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
4274
+ * caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
4275
+ * BLO-52085). It joins its block's decoder as a received source would, so
4276
+ * it reduces the erasures the block still has to solve, but it is not a
4277
+ * network arrival: no transport accounting, no classification evidence,
4278
+ * no deadline refresh, and it never makes a block clean.
4279
+ *
4280
+ * Only a block a repair stated takes one (a repair-less span has no
4281
+ * decoder block). A block that is terminal, or already holds that source,
4282
+ * does not. The symbol is the exact protected packet, unpadded, as
4283
+ * feedSourceSymbol takes it.
4284
+ *
4285
+ * `recovered` is the block the synchronous decoder completed with it; the
4286
+ * caller routes it and completes the block, as for any recovery. When
4287
+ * every source of the block is then present, received or rebuilt, and no
4288
+ * decoder returned it (a Worker answers asynchronously, and reports such a
4289
+ * block as clean on its own side), the block is completed here as
4290
+ * recovered, with nothing left to route.
4291
+ */
4292
+ feedRebuiltSourceSymbol(
4293
+ packetId: number,
4294
+ ssId: number,
4295
+ symbolData: Uint8Array,
4296
+ catalogTrackName?: string,
4297
+ ): RebuiltSourceFeed {
4298
+ if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN
4299
+ const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId)
4300
+ if (located === null || located.block.span) return NOT_TAKEN
4301
+ if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN
4302
+ const sbn = located.block.start
4303
+ const key = this.#blockKey(sbn, packetId, catalogTrackName)
4304
+ if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN
4305
+ let rebuilt = this.#blockRebuiltEsis.get(key)
4306
+ if (rebuilt?.has(located.esi)) return NOT_TAKEN
4307
+ if (rebuilt === undefined) {
4308
+ rebuilt = new Set()
4309
+ this.#blockRebuiltEsis.set(key, rebuilt)
4310
+ }
4311
+ const config = this.#trackConfigs.get(packetId)
4312
+ const wasShort = config !== undefined &&
4313
+ this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== undefined
4314
+ rebuilt.add(located.esi)
4315
+ const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn)
4316
+ if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
4317
+ // The late-source cut assumed only a late source could complete this
4318
+ // block; with this source its group can, so it gets a full multicast
4319
+ // wait again, counted from now.
4320
+ // ponytail: from now, not from its sources, so it can close up to one
4321
+ // multicast wait after its uncut deadline; at most once per block, since
4322
+ // a rebuilt source only adds to what the block holds and the cut cannot
4323
+ // apply to it again. Keep the uncut deadline and re-arm to it if a lab
4324
+ // run shows that wait.
4325
+ if (wasShort && this.#activeBlocks.has(key) &&
4326
+ this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config!) === undefined) {
4327
+ this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config!))
4328
+ }
4329
+ }
4330
+ return { taken: true, recovered }
4331
+ }
4332
+
4333
+ /**
4334
+ * A block that holds every one of its `length` sources, received or
4335
+ * rebuilt by another instance, with at least one rebuilt, is recovered:
4336
+ * every packet of it was delivered, by its own arrival or by the instance
4337
+ * that rebuilt it, so nothing is routed. Returns whether it completed it.
4338
+ */
4339
+ #completeWhenSourcesPresent(
4340
+ key: string,
4341
+ sbn: number,
4342
+ length: number,
4343
+ packetId: number,
4344
+ catalogTrackName: string | undefined,
4345
+ ): boolean {
4346
+ const rebuilt = this.#blockRebuiltEsis.get(key)
4347
+ if (rebuilt === undefined || this.#completedBlocks.has(key)) return false
4348
+ let present = rebuilt.size
4349
+ for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++
4350
+ if (present < length) return false
4351
+ this.#traceLifecycle('recovered', sbn, packetId, catalogTrackName)
4352
+ this.countRecovery(packetId, sbn, catalogTrackName)
4353
+ this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
4354
+ if (catalogTrackName === undefined) {
4355
+ this.onBlockComplete?.(sbn, packetId)
4356
+ } else {
4357
+ this.onBlockComplete?.(sbn, packetId, catalogTrackName)
4358
+ }
4359
+ return true
4360
+ }
4361
+
4089
4362
  /**
4090
4363
  * fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
4091
4364
  * exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
@@ -4343,9 +4616,101 @@ export class FECManager {
4343
4616
  this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName)
4344
4617
  return null
4345
4618
  }
4619
+ // Its K' is known now: a block this repair shows short of it waits less.
4620
+ if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName)
4346
4621
  return recovered
4347
4622
  }
4348
4623
 
4624
+ /**
4625
+ * A first-arrival multicast source, held or placed. A datagram flow keeps
4626
+ * its sources in send order, so one that moves the stream's newest source
4627
+ * position past a block leaves the sources that block still misses
4628
+ * reordered behind it at best: it shortens the wait of every block it
4629
+ * passed that only a late source can complete. MoQ is left out: its streams
4630
+ * can overtake one another, so a MoQ source shows nothing about the sources
4631
+ * sent before it.
4632
+ */
4633
+ #noteMulticastSource(
4634
+ locator: IsoBlockLocator<IsoHeldSource>,
4635
+ ssId: number,
4636
+ packetId: number,
4637
+ catalogTrackName: string | undefined,
4638
+ ): void {
4639
+ const previous = locator.newestSource
4640
+ if (!locator.noteSource(ssId) || previous === undefined) return
4641
+ // The blocks whose last SS_ID lies in [previous, ssId): this source
4642
+ // passed them and the previous newest one had not.
4643
+ for (const block of locator.blocksBetween((previous - 1) >>> 0, ssId)) {
4644
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
4645
+ this.#shortenUnrecoverableWait(
4646
+ this.#blockKey(block.start, packetId, catalogTrackName),
4647
+ block.start,
4648
+ packetId,
4649
+ catalogTrackName,
4650
+ )
4651
+ }
4652
+ }
4653
+
4654
+ /**
4655
+ * The wait of a block that only a late source can complete (BLO-52085): a
4656
+ * repair stated it, or it is a repair-less span longer than K (whose group
4657
+ * is empty, #openIsoSpan), its received sources plus every symbol its
4658
+ * repair group carries (RSB_length) are short of K' (the repair scheduler's
4659
+ * group-cannot-complete), and a later source of the stream has arrived, so
4660
+ * a source it misses is lost or reordered behind that one. The span, which
4661
+ * covers repair symbols paced after its sources, buys it nothing: it waits
4662
+ * the late-symbol allowance alone, the multicast wait less the span (the
4663
+ * catalog tolerance or the measured delivery gap). Undefined for any other
4664
+ * block.
4665
+ */
4666
+ #lateSourceWaitMs(
4667
+ key: string,
4668
+ sbn: number,
4669
+ packetId: number,
4670
+ catalogTrackName: string | undefined,
4671
+ config: ResolvedFECTrackConfig,
4672
+ ): number | undefined {
4673
+ const authoredLength = this.#blockAuthoredLengths.get(key)
4674
+ const rsbLength = this.#blockRsbLengths.get(key)
4675
+ if (authoredLength === undefined || rsbLength === undefined) return undefined
4676
+ // A source another instance rebuilt (feedRebuiltSourceSymbol) is one the
4677
+ // decoder holds: the group need only cover what neither delivered.
4678
+ let present = this.#blockSourceCounts.get(key) ?? 0
4679
+ const received = this.#blockSourceEsis.get(key)
4680
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++
4681
+ if (present + rsbLength >= authoredLength) return undefined
4682
+ const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource
4683
+ if (newestSource === undefined || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
4684
+ return undefined
4685
+ }
4686
+ return this.#multicastWaitMs(config) - config.interleaveDepthMs
4687
+ }
4688
+
4689
+ /**
4690
+ * Bring an open block's wait in to its late-source wait, when it has one.
4691
+ * Never later than it is armed: only a source can complete such a block,
4692
+ * so a repair of its group (paced across the span) must not keep it open.
4693
+ */
4694
+ #shortenUnrecoverableWait(
4695
+ key: string,
4696
+ sbn: number,
4697
+ packetId: number,
4698
+ catalogTrackName: string | undefined,
4699
+ ): void {
4700
+ if (!this.#activeBlocks.has(key)) return
4701
+ const config = this.#trackConfigs.get(packetId)
4702
+ if (config === undefined) return
4703
+ const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config)
4704
+ if (waitMs === undefined) return
4705
+ const armedAtMs = this.#blockWaitDeadlinesMs.get(key)
4706
+ this.#armBlockTimeout(
4707
+ sbn,
4708
+ packetId,
4709
+ catalogTrackName,
4710
+ armedAtMs === undefined ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow()),
4711
+ )
4712
+ }
4713
+
4349
4714
  /**
4350
4715
  * Record a block's authored SSB_length from a repair symbol. Returns false,
4351
4716
  * leaving the block unchanged, when the symbol contradicts the block: a
@@ -4485,7 +4850,8 @@ export class FECManager {
4485
4850
  * the inactivity deadline on each symbol, records the symbol's in-band
4486
4851
  * classification evidence, and marks the block clean when all of its
4487
4852
  * authored source symbols arrived: the SSB_length a repair symbol declared,
4488
- * otherwise K.
4853
+ * otherwise K. `held` marks a source held unplaced since it arrived and
4854
+ * placed only now (see #noteSbnSeen).
4489
4855
  *
4490
4856
  * Throws for a packetId that was never configured, so a classified block
4491
4857
  * never reads the manager-global K or timeout.
@@ -4496,6 +4862,7 @@ export class FECManager {
4496
4862
  catalogTrackName: string | undefined,
4497
4863
  esi: number,
4498
4864
  evidence: SourceSymbolEvidence,
4865
+ held = false,
4499
4866
  ): void {
4500
4867
  const trackConfig = this.#trackConfigs.get(packetId)
4501
4868
  if (trackConfig === undefined) {
@@ -4517,6 +4884,7 @@ export class FECManager {
4517
4884
  'source',
4518
4885
  evidence.packetSequenceNumber,
4519
4886
  Number.isInteger(esi) ? (sbn + esi) >>> 0 : sbn,
4887
+ held,
4520
4888
  )
4521
4889
 
4522
4890
  // A source ESI at or past the block's authored SSB_length contradicts it;
@@ -4561,6 +4929,20 @@ export class FECManager {
4561
4929
  this.#completeCleanBlock(key, sbn, packetId, catalogTrackName)
4562
4930
  return
4563
4931
  }
4932
+ // A late arrival can be the last source a block lacked besides those
4933
+ // another instance rebuilt (feedRebuiltSourceSymbol).
4934
+ if (
4935
+ this.#blockRebuiltEsis.has(key) &&
4936
+ this.#completeWhenSourcesPresent(
4937
+ key,
4938
+ sbn,
4939
+ this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
4940
+ packetId,
4941
+ catalogTrackName,
4942
+ )
4943
+ ) {
4944
+ return
4945
+ }
4564
4946
 
4565
4947
  this.noteBlockActivity(sbn, packetId, catalogTrackName, true)
4566
4948
 
@@ -4580,7 +4962,9 @@ export class FECManager {
4580
4962
  this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
4581
4963
  this.#blockSourceCounts.delete(key)
4582
4964
  this.#blockSourceEsis.delete(key)
4965
+ this.#blockRebuiltEsis.delete(key)
4583
4966
  this.#blockAuthoredLengths.delete(key)
4967
+ this.#isoSpanKeys.delete(key)
4584
4968
  this.#blockRepairRsIds.delete(key)
4585
4969
  this.#blockRsbLengths.delete(key)
4586
4970
  // BLO-3323 L15: track which SBNs reached K source-symbol arrivals so the
@@ -4622,6 +5006,20 @@ export class FECManager {
4622
5006
  return this.#receiptAtMs ?? performance.now()
4623
5007
  }
4624
5008
 
5009
+ /**
5010
+ * The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
5011
+ * scope: counted from the receipt time, as the timer of a symbol fed when
5012
+ * it was received was, less the whole ms since. So it fires on the tick
5013
+ * that timer would have, never later than a delay counted from now, and
5014
+ * its handler still re-arms a timer that fires before its deadline.
5015
+ * Counted from now, a deadline set from the receipt time is rounded up
5016
+ * from another fraction of a ms (BLO-52085).
5017
+ */
5018
+ #receiptTimerDelayMs(deadlineMs: number, minMs: number): number {
5019
+ const receivedAtMs = this.#receiptAtMs!
5020
+ return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs))
5021
+ }
5022
+
4625
5023
  /**
4626
5024
  * A held packet admitted late arms from its (earlier) receipt time; that
4627
5025
  * never pulls in a deadline later activity already armed. Outside a
@@ -4693,7 +5091,18 @@ export class FECManager {
4693
5091
  )
4694
5092
  }
4695
5093
 
4696
- this.#armBlockTimeout(sbn, packetId, catalogTrackName, timeoutMs)
5094
+ // A block only a late source can complete waits the late-symbol
5095
+ // allowance from its own sources' activity; nothing else moves it later.
5096
+ if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== undefined) {
5097
+ this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName)
5098
+ return
5099
+ }
5100
+ this.#armBlockTimeout(
5101
+ sbn,
5102
+ packetId,
5103
+ catalogTrackName,
5104
+ this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs,
5105
+ )
4697
5106
  }
4698
5107
 
4699
5108
  #failBlock(
@@ -4702,6 +5111,9 @@ export class FECManager {
4702
5111
  catalogTrackName?: string,
4703
5112
  ): void {
4704
5113
  const key = this.#blockKey(sbn, packetId, catalogTrackName)
5114
+ const span: IsoSpanFailure | undefined = this.#isoSpanKeys.delete(key)
5115
+ ? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 }
5116
+ : undefined
4705
5117
  this.#traceLifecycle('failed', sbn, packetId, catalogTrackName)
4706
5118
  this.#clearRepairDeadline(key)
4707
5119
  this.#clearBlockTimer(key)
@@ -4711,6 +5123,7 @@ export class FECManager {
4711
5123
  }
4712
5124
  this.#blockSourceCounts.delete(key)
4713
5125
  this.#blockSourceEsis.delete(key)
5126
+ this.#blockRebuiltEsis.delete(key)
4714
5127
  this.#blockAuthoredLengths.delete(key)
4715
5128
  this.#blockRepairRsIds.delete(key)
4716
5129
  this.#blockRsbLengths.delete(key)
@@ -4720,7 +5133,8 @@ export class FECManager {
4720
5133
  this.#markPathBlockComplete(sbn, packetId, catalogTrackName)
4721
5134
  this.#fecStats.blocksFailed++
4722
5135
  this.#statsForPacket(packetId).blocksFailed++
4723
- this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
5136
+ if (span === undefined) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
5137
+ else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span)
4724
5138
  this.onBlockResolved?.(sbn, packetId, catalogTrackName)
4725
5139
  }
4726
5140
 
@@ -4750,7 +5164,9 @@ export class FECManager {
4750
5164
  this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName)
4751
5165
  this.#blockSourceCounts.delete(key)
4752
5166
  this.#blockSourceEsis.delete(key)
5167
+ this.#blockRebuiltEsis.delete(key)
4753
5168
  this.#blockAuthoredLengths.delete(key)
5169
+ this.#isoSpanKeys.delete(key)
4754
5170
  this.#blockRepairRsIds.delete(key)
4755
5171
  this.#blockRsbLengths.delete(key)
4756
5172
  this.#clearBlockTimer(key)
@@ -4858,7 +5274,9 @@ export class FECManager {
4858
5274
  this.#blockKeysBySbn.clear()
4859
5275
  this.#blockSourceCounts.clear()
4860
5276
  this.#blockSourceEsis.clear()
5277
+ this.#blockRebuiltEsis.clear()
4861
5278
  this.#blockAuthoredLengths.clear()
5279
+ this.#isoSpanKeys.clear()
4862
5280
  this.#blockRepairRsIds.clear()
4863
5281
  this.#blockRsbLengths.clear()
4864
5282
  this.#heldLayerStates.clear()
@@ -4883,6 +5301,7 @@ export class FECManager {
4883
5301
  this.#blockAnchorsMs.clear()
4884
5302
  this.#blockCatalogTrackNames.clear()
4885
5303
  this.#classifiers.clear()
5304
+ this.#noSpanRaps.clear()
4886
5305
  this.#streamGeometries.clear()
4887
5306
  this.#failedBlocks.clear()
4888
5307
  this.#resolvedBlockClasses.clear()