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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +55 -13
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +104 -32
  5. package/dist/block-policy.js.map +2 -2
  6. package/dist/browser-runtime.js +420 -55
  7. package/dist/browser-runtime.js.map +3 -3
  8. package/dist/carp-catalog.js.map +2 -2
  9. package/dist/catalog-fec-params.d.ts +1 -1
  10. package/dist/catalog-fec-params.d.ts.map +1 -1
  11. package/dist/catalog-fec-params.js +14 -1
  12. package/dist/catalog-fec-params.js.map +2 -2
  13. package/dist/catalog-network-source.js.map +2 -2
  14. package/dist/cmaf-block-assembler.js +92 -1
  15. package/dist/cmaf-block-assembler.js.map +2 -2
  16. package/dist/codec-utils.d.ts.map +1 -1
  17. package/dist/codec-utils.js +92 -1
  18. package/dist/codec-utils.js.map +2 -2
  19. package/dist/delivery-catalog.js.map +2 -2
  20. package/dist/delta-fallback-config.js +5 -1
  21. package/dist/delta-fallback-config.js.map +3 -3
  22. package/dist/fec-manager.d.ts +44 -3
  23. package/dist/fec-manager.d.ts.map +1 -1
  24. package/dist/fec-manager.js +245 -46
  25. package/dist/fec-manager.js.map +2 -2
  26. package/dist/fec-state.js +5 -1
  27. package/dist/fec-state.js.map +2 -2
  28. package/dist/fec-worker-setup.js.map +2 -2
  29. package/dist/held-layer-admission.js.map +2 -2
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +3 -1
  33. package/dist/index.js.map +2 -2
  34. package/dist/iso-block-locator.js.map +2 -2
  35. package/dist/mfu-reassembler.js.map +2 -2
  36. package/dist/mmtp-container-parser.d.ts +27 -2
  37. package/dist/mmtp-container-parser.d.ts.map +1 -1
  38. package/dist/mmtp-container-parser.js +106 -2
  39. package/dist/mmtp-container-parser.js.map +2 -2
  40. package/dist/mmtp-container-parser.no-modules.js +126 -5
  41. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  42. package/dist/mmtp-decode-pipeline.js +106 -2
  43. package/dist/mmtp-decode-pipeline.js.map +2 -2
  44. package/dist/mmtp-fec-session.js.map +2 -2
  45. package/dist/mmtp-router.d.ts +2 -0
  46. package/dist/mmtp-router.d.ts.map +1 -1
  47. package/dist/mmtp-router.js +150 -3
  48. package/dist/mmtp-router.js.map +3 -3
  49. package/dist/multicast-auth-catalog.js.map +2 -2
  50. package/dist/multicast-input.js.map +2 -2
  51. package/dist/multicast-manager.d.ts.map +1 -1
  52. package/dist/multicast-manager.js +409 -53
  53. package/dist/multicast-manager.js.map +3 -3
  54. package/dist/multicast-transport.js.map +2 -2
  55. package/dist/multicast-unwrap.js.map +2 -2
  56. package/dist/no-modules.d.ts +1 -0
  57. package/dist/no-modules.d.ts.map +1 -1
  58. package/dist/no-modules.js +128 -6
  59. package/dist/no-modules.js.map +4 -4
  60. package/dist/repair-fetch.d.ts +2 -0
  61. package/dist/repair-fetch.d.ts.map +1 -1
  62. package/dist/repair-fetch.js +2 -2
  63. package/dist/repair-fetch.js.map +2 -2
  64. package/dist/repair-layer-subscriptions.js.map +2 -2
  65. package/dist/signaling.js.map +2 -2
  66. package/dist/timestamp-codec.js.map +2 -2
  67. package/dist/wasm-mfu-reassembler.js.map +2 -2
  68. package/dist/wasm-mmtp-container-parser.js +106 -2
  69. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  70. package/package.json +5 -5
  71. package/src/block-policy.ts +216 -52
  72. package/src/catalog-fec-params.ts +1 -0
  73. package/src/codec-utils.ts +121 -1
  74. package/src/fec-manager.ts +195 -14
  75. package/src/index.ts +2 -0
  76. package/src/mmtp-container-parser.ts +55 -11
  77. package/src/mmtp-router.ts +70 -6
  78. package/src/multicast-manager.ts +19 -3
  79. package/src/no-modules.ts +3 -0
  80. package/src/repair-fetch.ts +4 -2
@@ -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,
@@ -137,6 +138,12 @@ export interface FecStats {
137
138
  workers: Array<FecTrackStats & { packetId: number }>
138
139
  /** Main-thread repair symbols rejected before dispatch because their size did not match T. */
139
140
  repairSymbolSizeMismatches: number
141
+ /**
142
+ * Repair packets discarded because they arrived on a repair track the
143
+ * catalog does not list for their instance (fec-01 6.3.9): they delimit no
144
+ * block and anchor nothing.
145
+ */
146
+ unlistedRepairTrackRefusals: number
140
147
  /**
141
148
  * Repair objects discarded on admission (draft-ramadan-moq-fec-core-00 7.5,
142
149
  * draft-ramadan-moq-mmt-02 7.3), per FEC instance and reason. The instance
@@ -570,7 +577,8 @@ export class FECManager {
570
577
  #ssbLengthConflictCount = 0
571
578
  #blockRepairRsIds = new Map<string, Set<number>>()
572
579
  // RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
573
- // symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
580
+ // symbols its repair group carries; 0 for a repair-less span no repair can
581
+ // state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
574
582
  #blockRsbLengths = new Map<string, number>()
575
583
  /** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
576
584
  #heldLayerStates = new Map<string, HeldLayerAdmission>()
@@ -763,6 +771,7 @@ export class FECManager {
763
771
  #workerErrorCounts = new Map<string, number>()
764
772
  #decoderUnavailableEvents = 0
765
773
  #repairSymbolSizeMismatchCount = 0
774
+ #unlistedRepairTrackRefusals = 0
766
775
 
767
776
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
768
777
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
@@ -882,6 +891,21 @@ export class FECManager {
882
891
  onSourceDiscontinuity:
883
892
  | ((packetId: number, catalogTrackName: string | undefined) => void)
884
893
  | null = null
894
+ /**
895
+ * The span and tolerance the catalog states for a keyframe overlay
896
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
897
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
898
+ * undefined while none is installed. A stated block only a late source
899
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
900
+ * late source can fill, also wait for that overlay's repair
901
+ * (#overlayLateWaitMs).
902
+ */
903
+ keyframeOverlayTiming:
904
+ | ((
905
+ packetId: number,
906
+ catalogTrackName: string | undefined,
907
+ ) => Pick<FecInstanceGeometry, 'interleaveDepthMs' | 'reorderToleranceMs'> | undefined)
908
+ | null = null
885
909
 
886
910
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
887
911
  /**
@@ -2491,6 +2515,7 @@ export class FECManager {
2491
2515
  packetId,
2492
2516
  })),
2493
2517
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
2518
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
2494
2519
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
2495
2520
  workerErrors: Object.fromEntries(this.#workerErrorCounts),
2496
2521
  }
@@ -3094,8 +3119,10 @@ export class FECManager {
3094
3119
  }
3095
3120
  /**
3096
3121
  * An open block's accepted sources, distinct repair RS_IDs, authored K'
3097
- * (SSB_length) and RSB_length (each undefined until a repair stated it).
3098
- * Undefined for a block that is not open.
3122
+ * (SSB_length) and RSB_length (each undefined until a repair stated it; a
3123
+ * repair-less span states its length, and RSB_length 0 when it is longer
3124
+ * than K, since no repair can reach it). Undefined for a block that is not
3125
+ * open.
3099
3126
  */
3100
3127
  blockSymbolCounts(
3101
3128
  sbn: number,
@@ -3230,7 +3257,7 @@ export class FECManager {
3230
3257
  }
3231
3258
  const trackConfig = this.#trackConfigs.get(packetId)
3232
3259
  if (trackConfig === undefined) return undefined
3233
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig))
3260
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)))
3234
3261
  }
3235
3262
 
3236
3263
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
@@ -3465,6 +3492,17 @@ export class FECManager {
3465
3492
  * its placed sources exactly as on the wire (feedRepairSymbol). A span every
3466
3493
  * SS_ID of which vanished resolves through its deadline like any vanished
3467
3494
  * block.
3495
+ *
3496
+ * A span longer than K holds more than one block (SSB_length <= K), and the
3497
+ * locator states no block inside a span, only one exactly its range
3498
+ * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
3499
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
3500
+ * Group of it (group-cannot-complete). Every span still keeps its whole
3501
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
3502
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
3503
+ * gate lets those frames go once only a late source can fill the gap
3504
+ * before them, as long after they arrived as the gap's decision allows
3505
+ * (isoRepairlessWaitMs).
3468
3506
  */
3469
3507
  #openIsoSpan(
3470
3508
  span: { readonly block: IsoBlockRange; readonly placed: readonly unknown[] },
@@ -3472,9 +3510,15 @@ export class FECManager {
3472
3510
  catalogTrackName: string | undefined,
3473
3511
  ): void {
3474
3512
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName)
3513
+ // A span's key is always new here. An authored length is set only here or
3514
+ // from a repair stating that block (#noteAuthoredLength), and the locator
3515
+ // opens a span only where no repair stated a block, so none can precede
3516
+ // it. Were one to, the guard would skip the RSB_length 0 that keeps the
3517
+ // repair scheduler from FETCHing a long span's first Group.
3475
3518
  if (!this.#blockAuthoredLengths.has(key)) {
3476
3519
  this.#blockAuthoredLengths.set(key, span.block.length)
3477
3520
  this.#isoSpanKeys.add(key)
3521
+ if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0)
3478
3522
  }
3479
3523
  if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true)
3480
3524
  }
@@ -3523,6 +3567,90 @@ export class FECManager {
3523
3567
  return lost
3524
3568
  }
3525
3569
 
3570
+ /**
3571
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
3572
+ * between two released frames' SS_IDs once only a late source can still
3573
+ * fill them, else undefined. That is when every one missing (neither
3574
+ * arrived nor held) lies in a repair-less span longer than K, which no
3575
+ * repair can state a block of (#openIsoSpan), or in a stated block its
3576
+ * own repair group cannot complete every SS_ID of which it misses lies
3577
+ * between them (so the gap's decision covers all it lost), and a multicast
3578
+ * source at or past `toSsId` arrived, so each is lost or reordered behind
3579
+ * it (a MoQ source shows nothing: MoQ streams overtake one another). The
3580
+ * span or block itself keeps its own wait.
3581
+ *
3582
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
3583
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
3584
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
3585
+ * Then the frame waits as a stated block its group cannot complete does
3586
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
3587
+ * overlay's span plus the larger of the allowance and its tolerance, or,
3588
+ * for an overlay that states no span, the span's whole wait (undefined).
3589
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
3590
+ * the gap holds a stated block's loss.
3591
+ */
3592
+ isoRepairlessWaitMs(
3593
+ packetId: number,
3594
+ catalogTrackName: string | undefined,
3595
+ fromSsId: number,
3596
+ toSsId: number,
3597
+ rapMayHide = false,
3598
+ rapNext = false,
3599
+ ): number | undefined {
3600
+ const config = this.#trackConfigs.get(packetId)
3601
+ if (config === undefined || !FECManager.#hasCatalogTiming(config)) return undefined
3602
+ const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))
3603
+ if (locator === undefined || !locator.coversBetween(fromSsId, toSsId)) return undefined
3604
+ const newestSource = locator.newestSource
3605
+ if (newestSource === undefined || serial32Precedes(newestSource, toSsId)) return undefined
3606
+ let repairless = false
3607
+ let stated = false
3608
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
3609
+ const key = this.#blockKey(block.start, packetId, catalogTrackName)
3610
+ if (this.#completedBlocks.has(key)) continue
3611
+ if (block.span && block.length > locator.kMax) {
3612
+ repairless = true
3613
+ continue
3614
+ }
3615
+ const received = this.#blockSourceEsis.get(key)
3616
+ const rebuilt = this.#blockRebuiltEsis.get(key)
3617
+ let missesInGap = false
3618
+ let missesOutside = false
3619
+ // A rebuilt source is present outside the gap but missed inside it.
3620
+ // Outside, the question is what the block's decoder lacks beyond this
3621
+ // gap, and it holds a rebuilt source (#groupCannotComplete). Inside, it
3622
+ // is what the base path lost between the two frames. A base recovery
3623
+ // does not route a rebuilt packet again (MmtpRouter
3624
+ // #routeVerifiedFecSymbols), so only the overlay route delivers it, and
3625
+ // its frame may not have reached the gate yet (a head held for its FT=1,
3626
+ // BLO-53369). The two differ only when every SS_ID a block misses in the
3627
+ // gap was rebuilt: the later frame then waits for the gap's blocks to
3628
+ // resolve (undefined), which is conservative.
3629
+ for (let esi = 0; esi < block.length; esi++) {
3630
+ const ssId = serial32Add(block.start, esi)
3631
+ if (received?.has(esi) || locator.isHeld(ssId)) continue
3632
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true
3633
+ else if (!rebuilt?.has(esi)) missesOutside = true
3634
+ }
3635
+ if (!missesInGap) continue
3636
+ // A stated block its own group cannot complete (#lateSourceWaitMs) is
3637
+ // one too, when every SS_ID it misses lies in this gap: the gap's
3638
+ // decision then covers all it lost, so the overlay can rebuild none of
3639
+ // it unless `rapMayHide` or `rapNext`.
3640
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return undefined
3641
+ repairless = stated = true
3642
+ }
3643
+ if (!repairless) return undefined
3644
+ // A gap into the next MPU (`rapNext`) may hold that MPU's FT=0, an overlay
3645
+ // member; rebuilt, it is one more source of a stated block, which its group
3646
+ // may then complete. Such a block keeps #741's overlay wait; a span longer
3647
+ // than K has no group to complete and keeps #742's allowance.
3648
+ const waitMs = rapMayHide || (stated && rapNext)
3649
+ ? this.#overlayLateWaitMs(packetId, catalogTrackName, config)
3650
+ : this.#multicastWaitMs(config) - config.interleaveDepthMs
3651
+ return waitMs === undefined ? undefined : Math.max(0, waitMs)
3652
+ }
3653
+
3526
3654
  /**
3527
3655
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
3528
3656
  * the sources held now for a block no repair has stated yet, and the held
@@ -4422,7 +4550,10 @@ export class FECManager {
4422
4550
  this.#layerAnchorHorizon(packetId),
4423
4551
  this.#sourceFrontiers.get(streamKey)?.sbn,
4424
4552
  )
4425
- if (verdict === 'discard') return false
4553
+ if (verdict === 'discard') {
4554
+ this.#unlistedRepairTrackRefusals++
4555
+ return false
4556
+ }
4426
4557
  if (verdict !== undefined) {
4427
4558
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName)
4428
4559
  return false
@@ -4624,7 +4755,7 @@ export class FECManager {
4624
4755
  // The blocks whose last SS_ID lies in [previous, ssId): this source
4625
4756
  // passed them and the previous newest one had not.
4626
4757
  for (const block of locator.blocksBetween((previous - 1) >>> 0, ssId)) {
4627
- if (block.span || !serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
4758
+ if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
4628
4759
  this.#shortenUnrecoverableWait(
4629
4760
  this.#blockKey(block.start, packetId, catalogTrackName),
4630
4761
  block.start,
@@ -4643,7 +4774,13 @@ export class FECManager {
4643
4774
  * covers repair symbols paced after its sources, buys it nothing: it waits
4644
4775
  * the late-symbol allowance alone, the multicast wait less the span (the
4645
4776
  * catalog tolerance or the measured delivery gap). Undefined for any other
4646
- * block.
4777
+ * block. While a keyframe overlay is installed, the block waits for its
4778
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
4779
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
4780
+ * resolution is what releases the frames behind it, and failing it early
4781
+ * released them past a keyframe the overlay was still rebuilding, which
4782
+ * then arrived stale. The release gate lets them go instead
4783
+ * (isoRepairlessWaitMs).
4647
4784
  */
4648
4785
  #lateSourceWaitMs(
4649
4786
  key: string,
@@ -4652,20 +4789,64 @@ export class FECManager {
4652
4789
  catalogTrackName: string | undefined,
4653
4790
  config: ResolvedFECTrackConfig,
4654
4791
  ): number | undefined {
4792
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return undefined
4793
+ const authoredLength = this.#blockAuthoredLengths.get(key)!
4794
+ const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource
4795
+ if (newestSource === undefined || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
4796
+ return undefined
4797
+ }
4798
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config)
4799
+ }
4800
+
4801
+ /**
4802
+ * A repair stated the block, and its sources plus every symbol its repair
4803
+ * group carries (RSB_length) are short of its SSB_length.
4804
+ */
4805
+ #groupCannotComplete(key: string): boolean {
4655
4806
  const authoredLength = this.#blockAuthoredLengths.get(key)
4656
4807
  const rsbLength = this.#blockRsbLengths.get(key)
4657
- if (authoredLength === undefined || rsbLength === undefined) return undefined
4808
+ if (authoredLength === undefined || rsbLength === undefined) return false
4658
4809
  // A source another instance rebuilt (feedRebuiltSourceSymbol) is one the
4659
4810
  // decoder holds: the group need only cover what neither delivered.
4660
4811
  let present = this.#blockSourceCounts.get(key) ?? 0
4661
4812
  const received = this.#blockSourceEsis.get(key)
4662
4813
  for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++
4663
- if (present + rsbLength >= authoredLength) return undefined
4664
- const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource
4665
- if (newestSource === undefined || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
4666
- return undefined
4667
- }
4668
- return this.#multicastWaitMs(config) - config.interleaveDepthMs
4814
+ return present + rsbLength < authoredLength
4815
+ }
4816
+
4817
+ /**
4818
+ * How long a loss only a late source or an installed keyframe overlay can
4819
+ * still fill waits once a later source passed it: the late-symbol
4820
+ * allowance alone (the multicast wait less the span) while no overlay is
4821
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
4822
+ * RAP packet the loss took: a second FEC instance over the same packets
4823
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
4824
+ * span, unrelated to the base's. That packet can complete a stated block
4825
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
4826
+ * first lets the release gate pass the keyframe, whose rebuild then lands
4827
+ * stale. The overlay repair of a packet the loss took goes out within the
4828
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
4829
+ * sent after it, so the loss waits that span plus the larger of the
4830
+ * allowance and the overlay's own tolerance. An overlay that states no
4831
+ * span (its block may then span keyframes), or one whose wait is not
4832
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
4833
+ */
4834
+ #overlayLateWaitMs(
4835
+ packetId: number,
4836
+ catalogTrackName: string | undefined,
4837
+ config: ResolvedFECTrackConfig,
4838
+ ): number | undefined {
4839
+ const waitMs = this.#multicastWaitMs(config)
4840
+ const allowanceMs = waitMs - config.interleaveDepthMs
4841
+ // Read live. The late-source cut only ever shortens a block's deadline
4842
+ // (#shortenUnrecoverableWait), so a block it armed at the bare allowance
4843
+ // before an overlay was installed, or between a dispose and a reinstall,
4844
+ // keeps that deadline until a source of its own re-arms it.
4845
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName)
4846
+ if (overlay === undefined) return allowanceMs
4847
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0
4848
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0)
4849
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : undefined
4669
4850
  }
4670
4851
 
4671
4852
  /**
package/src/index.ts CHANGED
@@ -577,6 +577,8 @@ export {
577
577
  type RepairOverlayParams,
578
578
  // FEC catalog binding, draft-ramadan-moq-fec-catalog-00 array shape (BLO-50171).
579
579
  validateFecCatalog,
580
+ // The report the runtime acts on, for hosts that publish it (BLO-55242).
581
+ runtimeFecCatalogReport,
580
582
  type FecCatalogCode,
581
583
  type FecCatalogInstance,
582
584
  type FecCatalogIssue,
@@ -206,8 +206,10 @@ export interface SourcePacketIdentity {
206
206
  /**
207
207
  * In-order release policy for FEC-protected streams. For such a stream a
208
208
  * frame after a gap is released only once every FEC block that could hold
209
- * the missing frames has resolved (completed or failed); the frame-count
210
- * reorder window applies only to streams without FEC.
209
+ * the missing frames has resolved (completed or failed), or only a late
210
+ * source or the keyframe overlay could still fill the gap and the frame has
211
+ * waited for them (`unrepairableWaitMs`); the frame-count reorder window
212
+ * applies only to streams without FEC.
211
213
  */
212
214
  export interface FecReleaseGate {
213
215
  /** True when this physical stream's frames are FEC-gated. */
@@ -234,6 +236,22 @@ export interface FecReleaseGate {
234
236
  * It must not exceed how long a resolved block stays readable as resolved.
235
237
  */
236
238
  holdLimitMs(packetId: number, catalogTrackName?: string): number
239
+ /**
240
+ * How long a frame held behind unresolved blocks waits, from its arrival,
241
+ * once no repair but the keyframe overlay can still fill the gap before
242
+ * it: the late-symbol allowance when the gap holds no RAP that overlay
243
+ * could rebuild, else as long as its repair may still come. Undefined
244
+ * while another repair may still fill the gap, or the overlay's repair
245
+ * may come at any time. `fromSbn` is the anchor of the frame released
246
+ * before the gap, `toSbn` this frame's. Past the wait the frame goes,
247
+ * decided, as it would once those blocks failed.
248
+ */
249
+ unrepairableWaitMs?(
250
+ before: { data: Uint8Array; meta: FrameMeta },
251
+ after: { data: Uint8Array; meta: FrameMeta },
252
+ fromSbn: number,
253
+ toSbn: number,
254
+ ): number | undefined
237
255
  /** Decide stall/conceal for the first frame released after a gap. */
238
256
  decide(
239
257
  before: { data: Uint8Array; meta: FrameMeta },
@@ -257,6 +275,12 @@ export interface FecReleaseGate {
257
275
  * frame when it did unanchored (#cursorPassed).
258
276
  */
259
277
  releaseUnanchored?(packetId: number, catalogTrackName: string | undefined): boolean
278
+ /**
279
+ * A frame held only for its `unrepairableWaitMs` may go at `atMs`
280
+ * (performance.now()): poke the stream (pokeFecRelease) then. Absent, it
281
+ * goes at the next push or poke after that.
282
+ */
283
+ wakeAt?(packetId: number, catalogTrackName: string | undefined, atMs: number): void
260
284
  }
261
285
 
262
286
  /** Typed ISO-BMFF timing-sample budget counters. See `timingBudgetStats`. */
@@ -786,18 +810,24 @@ interface GatedStream {
786
810
  * to the last released frame is released immediately. A frame after a gap
787
811
  * waits until every block between the last released frame's block and its
788
812
  * own has resolved; a D-28 repair or a late in-band recovery can therefore
789
- * still fill the gap. A frame the keyframe overlay rebuilt waits only for the
790
- * blocks before its MPU (FrameMeta.fecSbnFirst), and no longer than the
791
- * source cursor would hold it unanchored (#cursorPassed). When the resolved
792
- * blocks lost media, or authored decode time shows a missing sample, the
793
- * release carries the gate's stall/conceal decision as `gapBefore`.
813
+ * still fill the gap. Once only a late source or the keyframe overlay could
814
+ * fill it, the frame waits only the gate's `unrepairableWaitMs` from its
815
+ * arrival: the late-symbol allowance, or longer when the gap may hold a RAP
816
+ * the overlay could still rebuild. A frame the keyframe overlay rebuilt
817
+ * waits only for the blocks before its MPU (FrameMeta.fecSbnFirst), and no
818
+ * longer than the source cursor would hold it unanchored
819
+ * (#cursorPassed). When the resolved blocks lost media, or authored decode
820
+ * time shows a missing sample, the release carries the gate's stall/conceal
821
+ * decision as `gapBefore`.
794
822
  *
795
823
  * The wait is bounded here, not by the blocks: a frame held longer than the
796
824
  * gate's `holdLimitMs` since it arrived is released with the gate's
797
825
  * discontinuity decision (a stall), so a block that never resolves cannot
798
- * grow the buffer without limit. There is no timer: the check runs on the
799
- * next push or poke, so after a total outage held frames are released by the
800
- * first packet that arrives, not at the ceiling itself.
826
+ * grow the buffer without limit. That ceiling has no timer: the check runs
827
+ * on the next push or poke, so after a total outage held frames are released
828
+ * by the first packet that arrives, not at the ceiling itself. Only the
829
+ * `unrepairableWaitMs` wait is timed: the gate is asked to poke the stream
830
+ * when it ends (`wakeAt`), since a burst may be the last traffic for a while.
801
831
  */
802
832
  class FecReleaseSequencer {
803
833
  #streams = new Map<string, GatedStream>()
@@ -1160,7 +1190,7 @@ class FecReleaseSequencer {
1160
1190
  from,
1161
1191
  )
1162
1192
  unresolved = resolved === null
1163
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
1193
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
1164
1194
  const heldMs = performance.now() - head.arrivedAtMs
1165
1195
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return
1166
1196
  // Past the point where these blocks must have resolved: nothing
@@ -1188,6 +1218,20 @@ class FecReleaseSequencer {
1188
1218
  }
1189
1219
  }
1190
1220
 
1221
+ /**
1222
+ * The head has waited out a gap only a late source can still fill
1223
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
1224
+ * the stream when it has (`wakeAt`), since no packet may come by then.
1225
+ */
1226
+ #unrepairableWaitOver(stream: GatedStream, last: PendingFrame, head: GatedFrame, from: number, to: number): boolean {
1227
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to)
1228
+ if (waitMs === undefined) return false
1229
+ const atMs = head.arrivedAtMs + waitMs
1230
+ if (performance.now() >= atMs) return true
1231
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs)
1232
+ return false
1233
+ }
1234
+
1191
1235
  /**
1192
1236
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
1193
1237
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -966,6 +966,15 @@ export interface FECManagerLike {
966
966
  fromSsId: number,
967
967
  toSsId: number,
968
968
  ): readonly number[] | null;
969
+ /** iso-ssbg1-v1: how long a frame waits once only a late source can fill the SS_IDs before it, longer when they may hold a RAP an installed keyframe overlay can still rebuild (FECManager.isoRepairlessWaitMs). */
970
+ isoRepairlessWaitMs?(
971
+ packetId: number,
972
+ catalogTrackName: string | undefined,
973
+ fromSsId: number,
974
+ toSsId: number,
975
+ rapMayHide?: boolean,
976
+ rapNext?: boolean,
977
+ ): number | undefined;
969
978
 
970
979
 
971
980
  /**
@@ -1043,9 +1052,10 @@ export interface FECManagerLike {
1043
1052
  /**
1044
1053
  * Classification evidence carried by one first-arrival network source
1045
1054
  * packet: the MMTP header R bit and the MPU / data-unit identity it states
1046
- * (movie fragment, sample, DU offset). `idx` is the 0-based sample position
1047
- * (`sample_number` is 1-based). The packet_sequence_number rides along for
1048
- * FECManager's forward-jump bound.
1055
+ * (movie fragment, sample, DU offset). `idx` is the sample's 0-based
1056
+ * position within its movie fragment (`sample_number` is 1-based);
1057
+ * BlockClassifier turns it and the fragment into an MPU position. The
1058
+ * packet_sequence_number rides along for FECManager's forward-jump bound.
1049
1059
  */
1050
1060
  function sourceSymbolEvidence(
1051
1061
  packet: Uint8Array,
@@ -1236,6 +1246,8 @@ export class MmtpRouter {
1236
1246
  // end: a synchronous recovery completes its block BEFORE routing the
1237
1247
  // recovered frames, and releasing a held gap in between would strand them.
1238
1248
  #fecPokeDepth = 0;
1249
+ /** FecReleaseGate.wakeAt timers, by media stream key. */
1250
+ readonly #fecWakes = new Map<string, { atMs: number; timer: ReturnType<typeof setTimeout> }>();
1239
1251
  #pendingFecPokes = new Map<string, { packetId: number; catalogTrackName?: string }>();
1240
1252
  // ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
1241
1253
  /** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
@@ -3922,6 +3934,8 @@ export class MmtpRouter {
3922
3934
  this.#disposed = true;
3923
3935
  this.#staged = null;
3924
3936
  this.cancelKeyframeLostTimer();
3937
+ for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
3938
+ this.#fecWakes.clear();
3925
3939
  this.#parser.dispose();
3926
3940
  this.#streams.clear();
3927
3941
  this.#trackPacketCallbacks.clear();
@@ -4138,6 +4152,35 @@ export class MmtpRouter {
4138
4152
  if (!fec?.terminalRetentionMsForPacket) return Infinity;
4139
4153
  return fec.terminalRetentionMsForPacket(packetId) ?? 0;
4140
4154
  },
4155
+ // Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
4156
+ // late source can), its frame waits the late-symbol allowance when the
4157
+ // gap holds no RAP an installed keyframe overlay could still rebuild:
4158
+ // lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
4159
+ // that opens the next one while MPU boundaries bound RAPs (rap-next,
4160
+ // unless the gap holds a stated block's loss: the overlay may rebuild
4161
+ // that MPU's FT=0, and the block's group then complete it), or
4162
+ // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
4163
+ // other rap-next, whose gap may hold a whole MPU and the keyframe the
4164
+ // overlay protects) waits for that overlay's repair too (BLO-52085
4165
+ // D4). The FEC check comes first: most held gaps are not behind such a
4166
+ // span, and deciding one scans both frames' bitstreams.
4167
+ unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
4168
+ const fec = this.#fecManager;
4169
+ const { packetId, catalogTrackName } = after.meta;
4170
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
4171
+ if (!fec || allowanceMs === undefined) return undefined;
4172
+ const decision = this.#decideGap(before, after, [], false);
4173
+ const mpu = before.meta.mpuSequenceNumber;
4174
+ const intoNextMpu = decision.reason === "rap-next" && mpu !== undefined &&
4175
+ after.meta.mpuSequenceNumber === ((mpu + 1) >>> 0) &&
4176
+ fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
4177
+ if (decision.action === "stall" || (decision.reason === "rap-next" && !intoNextMpu)) {
4178
+ return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
4179
+ }
4180
+ return decision.reason === "rap-next"
4181
+ ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true)
4182
+ : allowanceMs;
4183
+ },
4141
4184
  decide: (before, after, lostBlocks, discontinuity) => {
4142
4185
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
4143
4186
  this.#onFrameGap?.(decision);
@@ -4147,6 +4190,20 @@ export class MmtpRouter {
4147
4190
  onRap: (packetId, catalogTrackName, ssId) => {
4148
4191
  for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
4149
4192
  },
4193
+ // One timer per stream, at the earliest wake asked: its drain re-arms
4194
+ // for the next frame still waiting.
4195
+ wakeAt: (packetId, catalogTrackName, atMs) => {
4196
+ if (this.#disposed) return;
4197
+ const key = this.#mediaStreamKey(packetId, catalogTrackName);
4198
+ const armed = this.#fecWakes.get(key);
4199
+ if (armed !== undefined && armed.atMs <= atMs) return;
4200
+ if (armed !== undefined) clearTimeout(armed.timer);
4201
+ const timer = setTimeout(() => {
4202
+ this.#fecWakes.delete(key);
4203
+ this.#requestFecPoke(packetId, catalogTrackName);
4204
+ }, Math.max(0, Math.ceil(atMs - performance.now())));
4205
+ this.#fecWakes.set(key, { atMs, timer });
4206
+ },
4150
4207
  // A staged switch commits on when each side's frames reach it
4151
4208
  // (#interceptSwitchFrame): both sides' overlay keyframes reach it when
4152
4209
  // they did unanchored.
@@ -4190,10 +4247,17 @@ export class MmtpRouter {
4190
4247
  ): FrameGapDecision {
4191
4248
  const { packetId, catalogTrackName } = after.meta;
4192
4249
  const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
4193
- // Sample positions are MPU positions only while the classifier verified
4194
- // the geometry (one movie fragment per MPU, RAP at index 0).
4250
+ // decideGap counts the frames a delta-lost gap missed as the difference
4251
+ // of the two sides' sample_number. That is exact only within one movie
4252
+ // fragment, which numbers its samples consecutively, and is stated only
4253
+ // while the classifier verifies the geometry. Two fragments state no
4254
+ // count: an MPU of several multi-sample fragments still classifies while
4255
+ // the classifier received only one of them first-hand (BLO-55339).
4256
+ // ponytail: cross-fragment gaps report missingFrames null; count them from
4257
+ // BlockClassifier MPU positions when concealedFrames must cover them.
4195
4258
  const positionsTrusted =
4196
- this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying";
4259
+ this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" &&
4260
+ before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
4197
4261
  // "Same MPU on both sides" proves a delta-only gap only while an MPU
4198
4262
  // boundary bounds the stream's RAPs. Once a RAP was seen inside an MPU
4199
4263
  // (or an MPU outran its GOP), a lost RAP can hide inside one MPU, so the
@@ -8,7 +8,7 @@
8
8
  * - MulticastTransport — SSM join/socket/watchdog
9
9
  */
10
10
 
11
- import { canonicalIpAddress, parseFecBlockProfile, resolveFecBindings, sameIpAddress, type FecBlockProfile, type FecSourceBinding } from "@blockcast/mmt-base";
11
+ import { canonicalIpAddress, parseFecBlockProfile, resolveFecBindings, sameIpAddress, type FecBlockProfile, type FecInstanceGeometry, type FecSourceBinding } from "@blockcast/mmt-base";
12
12
  import {
13
13
  FECManager,
14
14
  MIN_INTERLEAVE_DEPTH_MS,
@@ -1313,6 +1313,10 @@ interface OverlayBinding {
1313
1313
  k: number;
1314
1314
  symbolSize: number;
1315
1315
  blockProfile: FecBlockProfile;
1316
+ /** The overlay instance's catalog geometry, read for its span and
1317
+ * tolerance (FECManager.keyframeOverlayTiming). No part of its decoder: a
1318
+ * reconfigure that changes it keeps an install. */
1319
+ geometry: FecInstanceGeometry;
1316
1320
  }
1317
1321
 
1318
1322
  type RepairOwnerEntry = MulticastRepairEndpoint["repairOwners"][number] & {
@@ -1530,6 +1534,15 @@ export class MulticastManager {
1530
1534
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
1531
1535
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
1532
1536
  };
1537
+ // An installed keyframe overlay may still rebuild a RAP packet a base
1538
+ // block lost; a block only a late source can complete waits for it.
1539
+ this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
1540
+ const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : undefined;
1541
+ if (binding === undefined) return undefined;
1542
+ return catalogTrackName === undefined || catalogTrackName === binding.sourceCatalogTrackName
1543
+ ? binding.geometry
1544
+ : undefined;
1545
+ };
1533
1546
  this.#fec.onDecoderUnavailable = (event) => {
1534
1547
  this.#emitRepairLifecycle({
1535
1548
  version: 2,
@@ -2455,7 +2468,9 @@ export class MulticastManager {
2455
2468
  console.warn("[MulticastManager] repair group release failed", error);
2456
2469
  }
2457
2470
  };
2458
- const usedFlows = new Set<string>();
2471
+ // Caller-owned flows reserve their keys even though this method does not
2472
+ // own their release; a protected endpoint must not replace one silently.
2473
+ const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === undefined ? [] : [flow]));
2459
2474
  const preparedProvenance = endpoints.map((endpoint) => {
2460
2475
  if (endpoint.provenance === undefined) return undefined;
2461
2476
  const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
@@ -3180,6 +3195,7 @@ export class MulticastManager {
3180
3195
  geometry.blockProfile,
3181
3196
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`,
3182
3197
  ),
3198
+ geometry,
3183
3199
  });
3184
3200
  }
3185
3201
  }
@@ -3225,7 +3241,7 @@ export class MulticastManager {
3225
3241
  const before = this.#overlayBindings.get(sourcePacketId);
3226
3242
  const after = overlayBindings.get(sourcePacketId);
3227
3243
  const same = before !== undefined && after !== undefined &&
3228
- (Object.keys(after) as Array<keyof OverlayBinding>).every((key) => after[key] === before[key]);
3244
+ (Object.keys(after) as Array<keyof OverlayBinding>).every((key) => key === "geometry" || after[key] === before[key]);
3229
3245
  if (!same) install.dispose();
3230
3246
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
3231
3247
  // A retired packet ID took the router's instance with it.
package/src/no-modules.ts CHANGED
@@ -12,6 +12,9 @@ export {
12
12
  } from './carp-catalog.js'
13
13
  export { catalogFecInterleaveMs, fecBlockBudgetMs, fecBlockDeadlineMs } from '@blockcast/mmt-fec'
14
14
  export { FEC_INACTIVE_REASONS, catalogDeclaresFec, resolveFecState } from './fec-state.js'
15
+ // The per-instance report a receiver acts on, for classic-script pages that
16
+ // must publish it (BLO-55242).
17
+ export { runtimeFecCatalogReport, validateFecCatalog } from './catalog-fec-params.js'
15
18
  export { MmtpFecSession } from './mmtp-fec-session.js'
16
19
  export { catalogAmtNetworkSource, catalogAtsc3NetworkSource } from './catalog-network-source.js'
17
20
  export { MmtpToCmaf } from './mmtp-to-cmaf.js'