@blockcast/mmt-container 2.1.0 → 2.2.0-main.02321582f1ca

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 (99) hide show
  1. package/README.md +29 -17
  2. package/dist/browser-runtime.js +1302 -249
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/carp-catalog.js.map +1 -1
  5. package/dist/catalog-fec-params.d.ts +17 -1
  6. package/dist/catalog-fec-params.d.ts.map +1 -1
  7. package/dist/catalog-fec-params.js +15 -0
  8. package/dist/catalog-fec-params.js.map +2 -2
  9. package/dist/catalog-network-source.js.map +1 -1
  10. package/dist/cmcd-producer.d.ts +65 -47
  11. package/dist/cmcd-producer.d.ts.map +1 -1
  12. package/dist/cmcd-producer.js +138 -109
  13. package/dist/cmcd-producer.js.map +2 -2
  14. package/dist/delivery-catalog.js +26 -16
  15. package/dist/delivery-catalog.js.map +2 -2
  16. package/dist/delta-fallback-config.js.map +1 -1
  17. package/dist/fec-manager.d.ts +33 -1
  18. package/dist/fec-manager.d.ts.map +1 -1
  19. package/dist/fec-manager.js +213 -6
  20. package/dist/fec-manager.js.map +2 -2
  21. package/dist/fec-state.js.map +1 -1
  22. package/dist/fec-worker-setup.d.ts +1 -1
  23. package/dist/fec-worker-setup.js +1 -1
  24. package/dist/fec-worker-setup.js.map +1 -1
  25. package/dist/held-layer-admission.js.map +1 -1
  26. package/dist/index.d.ts +5 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +9 -1
  29. package/dist/index.js.map +2 -2
  30. package/dist/iso-block-locator.d.ts +9 -0
  31. package/dist/iso-block-locator.d.ts.map +1 -1
  32. package/dist/iso-block-locator.js +17 -0
  33. package/dist/iso-block-locator.js.map +2 -2
  34. package/dist/iso-bmff-timing.d.ts +10 -1
  35. package/dist/iso-bmff-timing.d.ts.map +1 -1
  36. package/dist/iso-bmff-timing.js +36 -2
  37. package/dist/iso-bmff-timing.js.map +2 -2
  38. package/dist/media-router.js.map +1 -1
  39. package/dist/mfu-reassembler.js +12 -19
  40. package/dist/mfu-reassembler.js.map +2 -2
  41. package/dist/mmtp-container-parser.d.ts +37 -2
  42. package/dist/mmtp-container-parser.d.ts.map +1 -1
  43. package/dist/mmtp-container-parser.js +98 -28
  44. package/dist/mmtp-container-parser.js.map +2 -2
  45. package/dist/mmtp-container-parser.no-modules.js +222 -45
  46. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  47. package/dist/mmtp-decode-pipeline.js +97 -28
  48. package/dist/mmtp-decode-pipeline.js.map +2 -2
  49. package/dist/mmtp-fec-session.d.ts +41 -3
  50. package/dist/mmtp-fec-session.d.ts.map +1 -1
  51. package/dist/mmtp-fec-session.js +118 -13
  52. package/dist/mmtp-fec-session.js.map +3 -3
  53. package/dist/mmtp-router.d.ts +25 -2
  54. package/dist/mmtp-router.d.ts.map +1 -1
  55. package/dist/mmtp-router.js +1749 -56
  56. package/dist/mmtp-router.js.map +4 -4
  57. package/dist/multicast-auth-catalog.js.map +1 -1
  58. package/dist/multicast-input.js.map +1 -1
  59. package/dist/multicast-manager.d.ts +15 -2
  60. package/dist/multicast-manager.d.ts.map +1 -1
  61. package/dist/multicast-manager.js +15683 -14941
  62. package/dist/multicast-manager.js.map +4 -4
  63. package/dist/multicast-transport.d.ts +11 -3
  64. package/dist/multicast-transport.d.ts.map +1 -1
  65. package/dist/multicast-transport.js +281 -35
  66. package/dist/multicast-transport.js.map +4 -4
  67. package/dist/multicast-unwrap.js +12 -19
  68. package/dist/multicast-unwrap.js.map +2 -2
  69. package/dist/no-modules.js +215 -42
  70. package/dist/no-modules.js.map +3 -3
  71. package/dist/repair-fetch.js.map +1 -1
  72. package/dist/repair-layer-subscriptions.d.ts +82 -0
  73. package/dist/repair-layer-subscriptions.d.ts.map +1 -0
  74. package/dist/repair-layer-subscriptions.js +192 -0
  75. package/dist/repair-layer-subscriptions.js.map +7 -0
  76. package/dist/signaling.js.map +2 -2
  77. package/dist/timestamp-codec.js +12 -19
  78. package/dist/timestamp-codec.js.map +2 -2
  79. package/dist/track-session.d.ts +1 -1
  80. package/dist/track-session.js.map +1 -1
  81. package/dist/wasm-mfu-reassembler.js.map +1 -1
  82. package/dist/wasm-mmtp-container-parser.js +97 -28
  83. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  84. package/package.json +8 -5
  85. package/schemas/catalog.schema.json +4 -0
  86. package/src/catalog-fec-params.ts +36 -1
  87. package/src/cmcd-producer.ts +194 -179
  88. package/src/fec-manager.ts +256 -6
  89. package/src/fec-worker-setup.ts +2 -2
  90. package/src/index.ts +18 -2
  91. package/src/iso-block-locator.ts +19 -0
  92. package/src/iso-bmff-timing.ts +40 -1
  93. package/src/mmtp-container-parser.ts +96 -8
  94. package/src/mmtp-fec-session.ts +115 -15
  95. package/src/mmtp-router.ts +414 -29
  96. package/src/multicast-manager.ts +26 -5
  97. package/src/multicast-transport.ts +44 -20
  98. package/src/repair-layer-subscriptions.ts +261 -0
  99. package/src/track-session.ts +1 -1
@@ -365,10 +365,19 @@ export type MmtpFeedDropReason =
365
365
  /** No timing resolver, or it refused the initialization segment. */
366
366
  | 'init-timing-refused'
367
367
  | 'fragment-unexpected-fragmentation'
368
+ /** FT=1 before an FT=0 has bound the stream's timing track. */
368
369
  | 'fragment-no-resolver'
369
370
  /** addMovieFragment refused — includes the pending-timing-sample budget. */
370
371
  | 'fragment-timing-refused'
371
372
  | 'unknown-fragment-type'
373
+ /** Stable code, no longer produced: an FT=2 with no timing (before the
374
+ * stream's first FT=0, or after setTrack dropped it) now waits for its
375
+ * timing like one whose FT=1 has not arrived. A head counts as
376
+ * `drop:mfu-sample-timing-missing` (parked) and a FI=2/FI=3 continuation
377
+ * as the `pending` record. A continuation that completes a head the
378
+ * reassembler buffered before the timing was dropped counts as
379
+ * `drop:assembled-timing-missing`. A panel keyed on this code reads zero:
380
+ * a re-attribution, not lost coverage. Re-key on both drop codes. */
372
381
  | 'mfu-no-resolver'
373
382
  | 'mfu-empty-payload'
374
383
  | 'mfu-du-header-missing'
@@ -679,7 +688,10 @@ class FrameSequencer {
679
688
  // ── FecReleaseSequencer ─────────────────────────────────────────────
680
689
 
681
690
  /** Authored decode-time adjacency: the next frame starts where this one ends. */
682
- function authoredAdjacent(before: FrameMeta, after: FrameMeta): boolean {
691
+ export function authoredAdjacent(
692
+ before: Pick<FrameMeta, 'authoredTiming'>,
693
+ after: Pick<FrameMeta, 'authoredTiming'>,
694
+ ): boolean {
683
695
  const a = before.authoredTiming
684
696
  const b = after.authoredTiming
685
697
  if (!a || !b || a.mediaTimescale !== b.mediaTimescale) return false
@@ -1089,9 +1101,30 @@ interface AwaitingTimingHead {
1089
1101
  mpuSequenceNumber: number
1090
1102
  movieFragmentSequenceNumber: number
1091
1103
  sampleNumber: number
1104
+ /** MMTP packet sequence number; a recovered copy carries its source's. */
1105
+ sequenceNumber: number
1092
1106
  arrivedAt: number
1093
1107
  }
1094
1108
 
1109
+ /** FEC-recovered heads that went through the awaiting-timing queue. Every
1110
+ * count but `pending` is cumulative. A held head is pending or has left the
1111
+ * queue exactly once, so `held - expired - discarded - superseded - pending`
1112
+ * is the number fed again once their FT=1 landed. That feed can still refuse
1113
+ * one (size, offset, dispose from a frame callback); the refusal is counted in
1114
+ * `feedStats.deferredOutcomes`, not here. */
1115
+ export interface MmtpRecoveredHeadTimingStats {
1116
+ /** Held because their sample's FT=1 had not arrived yet. */
1117
+ held: number
1118
+ /** Left without timing: the reassembler-timeout deadline, or pushed out by the queue's capacity. */
1119
+ expired: number
1120
+ /** Dropped with their stream (track reconfigure, reset or retire) or by dispose(). */
1121
+ discarded: number
1122
+ /** Gave way to their arriving source copy, which takes their place in the queue. */
1123
+ superseded: number
1124
+ /** In the queue now; current occupancy, not cumulative. */
1125
+ pending: number
1126
+ }
1127
+
1095
1128
  const MAX_AWAITING_TIMING_HEADS = 8
1096
1129
 
1097
1130
  // ── MmtpContainerParser ─────────────────────────────────────────────
@@ -1129,6 +1162,9 @@ export class MmtpContainerParser {
1129
1162
  #reclaimedTimingSamples = 0
1130
1163
  #evictedTimingSamples = 0
1131
1164
  #rejectedMovieFragments = 0
1165
+ #recoveredHeadsAwaitingTiming: Omit<MmtpRecoveredHeadTimingStats, 'pending'> = {
1166
+ held: 0, expired: 0, discarded: 0, superseded: 0,
1167
+ }
1132
1168
  #sequencers = new Map<string, { packetId: number; sequencer: FrameSequencer }>()
1133
1169
  #fecGate: FecReleaseGate | null = null
1134
1170
  #fecSequencer: FecReleaseSequencer | null = null
@@ -1346,6 +1382,15 @@ export class MmtpContainerParser {
1346
1382
  }
1347
1383
  }
1348
1384
 
1385
+ /** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
1386
+ get recoveredHeadsAwaitingTiming(): Readonly<MmtpRecoveredHeadTimingStats> {
1387
+ let pending = 0
1388
+ for (const { awaitingTiming } of this.#timingStreams.values()) {
1389
+ for (const head of awaitingTiming) if (head.options?.recovered) pending++
1390
+ }
1391
+ return { ...this.#recoveredHeadsAwaitingTiming, pending }
1392
+ }
1393
+
1349
1394
  get reorderStats(): Readonly<MmtpReorderStats> {
1350
1395
  let bufferedFrames = this.#fecSequencer?.buffered ?? 0
1351
1396
  for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered
@@ -1541,7 +1586,7 @@ export class MmtpContainerParser {
1541
1586
  const now = Date.now()
1542
1587
  for (const { awaitingTiming } of this.#timingStreams.values()) {
1543
1588
  while (awaitingTiming.length > 0 && now - awaitingTiming[0]!.arrivedAt > timeoutMs) {
1544
- awaitingTiming.shift()
1589
+ this.#leaveAwaitingTiming(awaitingTiming.shift()!, 'expired')
1545
1590
  }
1546
1591
  }
1547
1592
  }
@@ -1711,11 +1756,16 @@ export class MmtpContainerParser {
1711
1756
  if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
1712
1757
  return this.#drop('fragment-unexpected-fragmentation')
1713
1758
  const resolver = this.#timingResolver(streamKey, info.packetId, false)
1714
- if (!resolver) return this.#drop('fragment-no-resolver')
1759
+ if (!resolver?.initialized) return this.#drop('fragment-no-resolver')
1715
1760
  const pendingBefore = resolver.pendingSampleCount
1716
1761
  const evictedBefore = resolver.evictedSampleCount
1717
1762
  const remaining = this.#maxPendingTimingSamples - this.#pendingTimingSamples
1718
- const admitted = resolver.addMovieFragment(mpu.mpuSequenceNumber, data, remaining)
1763
+ const admitted = resolver.addMovieFragment(
1764
+ mpu.mpuSequenceNumber,
1765
+ data,
1766
+ remaining,
1767
+ options?.recovered === true,
1768
+ )
1719
1769
  // Sync on BOTH paths: the resolver can displace stale timing and still
1720
1770
  // refuse the fragment in hand, and a global count that missed those
1721
1771
  // freed slots would keep refusing on a budget that is no longer full.
@@ -1739,7 +1789,11 @@ export class MmtpContainerParser {
1739
1789
  }
1740
1790
  if (fragmentType !== 2) return this.#drop('unknown-fragment-type')
1741
1791
 
1742
- const resolver = this.#timingResolver(streamKey, info.packetId, false)
1792
+ // An FT=2 before the stream's first FT=0 (a join, a track reset) is taken
1793
+ // like one whose FT=1 has not arrived: a head waits for its timing, a
1794
+ // continuation parks in the reassembler, and a later or FEC-recovered
1795
+ // FT=0/FT=1 can still time them.
1796
+ const resolver = this.#timingResolver(streamKey, info.packetId, true)
1743
1797
  if (!resolver) return this.#drop('mfu-no-resolver')
1744
1798
  if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
1745
1799
  return this.#drop('mfu-empty-payload')
@@ -1761,6 +1815,7 @@ export class MmtpContainerParser {
1761
1815
  mpuSequenceNumber: mpu.mpuSequenceNumber,
1762
1816
  movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
1763
1817
  sampleNumber: mfuDuHeader.sampleNumber,
1818
+ sequenceNumber: info.sequenceNumber,
1764
1819
  arrivedAt: Date.now(),
1765
1820
  })
1766
1821
  return this.#drop('mfu-sample-timing-missing')
@@ -2146,6 +2201,18 @@ export class MmtpContainerParser {
2146
2201
  this.#emitFrame(data, meta)
2147
2202
  }
2148
2203
 
2204
+ /** Whether FT=1 metadata already names this sample, without claiming it. */
2205
+ hasAuthoredTimingFor(
2206
+ packetId: number,
2207
+ mpuSequenceNumber: number,
2208
+ movieFragmentSequenceNumber: number,
2209
+ sampleNumber: number,
2210
+ catalogTrackName?: string,
2211
+ ): boolean {
2212
+ return this.#timingResolver(this.#streamKey(packetId, catalogTrackName), packetId, false)
2213
+ ?.sampleTiming(mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber) != null
2214
+ }
2215
+
2149
2216
  /**
2150
2217
  * Claim and return the authored timing for a recovered sample. Recovery does
2151
2218
  * not pass through the ordinary `feed()` completion path, so it must retire
@@ -2216,6 +2283,9 @@ export class MmtpContainerParser {
2216
2283
  for (const { sequencer } of this.#sequencers.values()) sequencer.discard()
2217
2284
  this.#sequencers.clear()
2218
2285
  this.#fecSequencer?.discard()
2286
+ for (const { awaitingTiming } of this.#timingStreams.values()) {
2287
+ for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, 'discarded')
2288
+ }
2219
2289
  this.#timingStreams.clear()
2220
2290
  this.#pendingTimingSamples = 0
2221
2291
  this.#reliableMoqStartupGate.clear()
@@ -2241,10 +2311,27 @@ export class MmtpContainerParser {
2241
2311
  }
2242
2312
 
2243
2313
  #awaitTiming(streamKey: string, head: AwaitingTimingHead): void {
2244
- const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming
2245
- if (!awaitingTiming) return
2314
+ const state = this.#timingStreams.get(streamKey)
2315
+ if (!state) return
2316
+ // The source copy of a held recovered head takes its place, so the frame
2317
+ // is delivered with source provenance once FT=1 lands.
2318
+ if (!head.options?.recovered) {
2319
+ const kept = state.awaitingTiming.filter(queued =>
2320
+ !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber)
2321
+ this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length
2322
+ state.awaitingTiming = kept
2323
+ }
2324
+ const awaitingTiming = state.awaitingTiming
2246
2325
  awaitingTiming.push(head)
2247
- if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift()
2326
+ if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++
2327
+ if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
2328
+ this.#leaveAwaitingTiming(awaitingTiming.shift()!, 'expired')
2329
+ }
2330
+ }
2331
+
2332
+ /** Count a recovered head leaving the queue other than by replay or its source copy. */
2333
+ #leaveAwaitingTiming(head: AwaitingTimingHead, outcome: 'expired' | 'discarded'): void {
2334
+ if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++
2248
2335
  }
2249
2336
 
2250
2337
  /**
@@ -2274,6 +2361,7 @@ export class MmtpContainerParser {
2274
2361
  const state = this.#timingStreams.get(streamKey)
2275
2362
  if (!state) return
2276
2363
  this.#timingStreams.delete(streamKey)
2364
+ for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, 'discarded')
2277
2365
  this.#pendingTimingSamples -= state.resolver.pendingSampleCount
2278
2366
  if (this.#pendingTimingSamples < 0) {
2279
2367
  throw new Error('[MmtpContainerParser] pending timing sample accounting underflow')
@@ -23,6 +23,15 @@
23
23
  * uses. A packet below B_0 at or after the anchor fails the session closed:
24
24
  * `stats.failClosed` reports why, and every later repair is refused.
25
25
  *
26
+ * Catalog-less (draft-ramadan-moq-mmt-02 8.3, 13.2): a receiver holding
27
+ * layer 0 under the AL-FEC message alone builds the session from the message's
28
+ * fec_flow entry (`alFecFlow`) instead. K, T, the code point and the repair
29
+ * packet_id come from that entry, and layer 0 is held at
30
+ * maximum_p_for_repair_flow, standing for O_0 + P_0, by the anchored clause of
31
+ * draft-ramadan-moq-fec-core-00 7.3.2 alone. A later version that raises the
32
+ * field raises the held total (updateAlFecFlow()); the message carries no
33
+ * millisecond budget, so the caller states the retention (fec-core-00 9.4).
34
+ *
26
35
  * Every repair packet that cannot be used is counted under the reason it was
27
36
  * refused, and every block ends under exactly one outcome, so a stream whose
28
37
  * FEC is doing nothing can be told apart from one with nothing to repair.
@@ -30,6 +39,8 @@
30
39
 
31
40
  import {
32
41
  admitMmtpRepairObject,
42
+ alFecRaptorQFlowConfig,
43
+ FEC_CODE_RAPTORQ,
33
44
  isoBlockContains,
34
45
  isoBlocksBehindLowerBound,
35
46
  parseFecBlockProfile,
@@ -39,6 +50,8 @@ import {
39
50
  serial32Precedes,
40
51
  ssbg1FitsSymbol,
41
52
  trimSsbg1SourceSymbol,
53
+ type AlFecFlow,
54
+ type AlFecRaptorQFlowConfig,
42
55
  type FecBlockProfile,
43
56
  } from '@blockcast/mmt-base'
44
57
  import { deriveFecRetentionBlocks, fecBlockBudgetMs } from '@blockcast/mmt-fec'
@@ -105,6 +118,25 @@ export interface MmtpFecSessionConfig {
105
118
  heldLayers?: readonly number[]
106
119
  }
107
120
 
121
+ /**
122
+ * A catalog-less session: one fec_flow entry of the AL-FEC message
123
+ * (`parseAlFecMessage(...).flows[i]`), draft-ramadan-moq-mmt-02 8.3.
124
+ */
125
+ export interface MmtpFecSessionMessageConfig {
126
+ /** The source track's entry; it must pass `alFecRaptorQFlowConfig`. */
127
+ alFecFlow: AlFecFlow
128
+ /**
129
+ * The decoder retention in blocks. The message carries no elapsed-time
130
+ * budget (mmt-02 7.5), so open-block state is bounded by local policy
131
+ * (fec-core-00 9.4); required, never defaulted.
132
+ */
133
+ retentionBlocks: number
134
+ Decoder: MmtpFecSessionDecoderConstructor
135
+ }
136
+
137
+ /** What updateAlFecFlow() did with a later version of the message. */
138
+ export type MmtpFecSessionMessageUpdate = 'raised' | 'unchanged' | 'refused'
139
+
108
140
  /**
109
141
  * The path a symbol arrived on: its MoQT subscription, or the multicast
110
142
  * group (native SSM or AMT) carrying the same asset. The caller states it;
@@ -197,12 +229,17 @@ export class MmtpFecSession {
197
229
  readonly algorithm: 'raptorq' | 'reed-solomon'
198
230
  readonly sourceSymbols: number
199
231
  /** P_0 = B_0, the held total every repair packet is checked against. */
200
- readonly repairSymbols: number
232
+ get repairSymbols(): number {
233
+ return this.#repairSymbols
234
+ }
201
235
  readonly symbolSize: number
202
236
  /** The decoder's retention, in blocks, derived from the catalog budget. */
203
237
  readonly retentionBlocks: number
204
238
 
205
239
  #decoder: MmtpFecSessionDecoder | null
240
+ #repairSymbols: number
241
+ /** The message entry a catalog-less session was built from; undefined under a catalog. */
242
+ #message: AlFecRaptorQFlowConfig | undefined
206
243
  /** Blocks a repair has defined and that are not settled yet, by SS_Start. */
207
244
  #blocks = new Map<number, BlockState>()
208
245
  /** SS_Starts of settled blocks, so a later repair for one is refused. */
@@ -240,7 +277,26 @@ export class MmtpFecSession {
240
277
  * the scheme, the block profile, K, P_0 (`repairSymbols`), T,
241
278
  * `interleaveDepthMs` or `reorderToleranceMs`. None is defaulted.
242
279
  */
243
- constructor(config: MmtpFecSessionConfig) {
280
+ constructor(config: MmtpFecSessionConfig | MmtpFecSessionMessageConfig) {
281
+ if (config && 'alFecFlow' in config) {
282
+ const message = alFecRaptorQFlowConfig(config.alFecFlow)
283
+ if (!message) {
284
+ throw new Error('MmtpFecSession: the AL-FEC entry is outside draft-ramadan-moq-mmt-02 8.3 (iso-ssbg1-v1)')
285
+ }
286
+ this.#message = message
287
+ // Coding byte 0x14 is the iso-ssbg1-v1 profile (mmt-02 8.3).
288
+ this.blockProfile = parseFecBlockProfile('iso-ssbg1-v1', 'alFecFlow')
289
+ this.algorithm = message.fecCodeId === FEC_CODE_RAPTORQ ? 'raptorq' : 'reed-solomon'
290
+ this.sourceSymbols = message.maximumK
291
+ this.#repairSymbols = message.maximumP
292
+ this.symbolSize = message.repairSymbolSize
293
+ this.retentionBlocks = requirePositiveInteger(config.retentionBlocks, 'retentionBlocks')
294
+ this.#repairPacketId = message.repairFlowId
295
+ this.#heldLayers = layerZero(message.maximumP)
296
+ this.#anchorHorizon = heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols)
297
+ this.#decoder = buildDecoder(config.Decoder, this)
298
+ return
299
+ }
244
300
  const fec = config?.fec
245
301
  if (!fec || typeof fec !== 'object') {
246
302
  throw new Error('MmtpFecSession: the catalog fec instance is required')
@@ -251,7 +307,7 @@ export class MmtpFecSession {
251
307
  }
252
308
  this.algorithm = fec.scheme
253
309
  this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, 'fec.sourceSymbols')
254
- this.repairSymbols = requirePositiveInteger(fec.repairSymbols, 'fec.repairSymbols')
310
+ this.#repairSymbols = requirePositiveInteger(fec.repairSymbols, 'fec.repairSymbols')
255
311
  this.symbolSize = requirePositiveInteger(fec.symbolSize, 'fec.symbolSize')
256
312
  const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, 'fec.interleaveDepthMs')
257
313
  const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, 'fec.reorderToleranceMs')
@@ -271,17 +327,38 @@ export class MmtpFecSession {
271
327
  config.heldLayers,
272
328
  )
273
329
  this.#anchorHorizon = heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols)
274
- if (typeof config.Decoder !== 'function') {
275
- throw new Error('MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required')
276
- }
277
- const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm)
278
- try {
279
- decoder.configure_params(this.sourceSymbols, this.symbolSize)
280
- } catch (error) {
281
- decoder.free()
282
- throw error
330
+ this.#decoder = buildDecoder(config.Decoder, this)
331
+ }
332
+
333
+ /**
334
+ * A later version of the AL-FEC message, catalog-less sessions only. A
335
+ * maximum_p_for_repair_flow above the held total raises it (`raised`): the
336
+ * anchored check restarts at the new total, so a block generated under the
337
+ * previous one stays valid before the first block carrying the new total
338
+ * (fec-core-00 7.3.2, mmt-02 8.3). A field at or below it changes nothing
339
+ * (`unchanged`): no publisher lowers it, and the check catches a wire that
340
+ * does. An entry with another asset, repair flow, code point, K or T, or
341
+ * one outside 8.3, is `refused`: that is a new source encoding, which needs
342
+ * a new session. A latched fail-closed stays latched either way.
343
+ */
344
+ updateAlFecFlow(flow: AlFecFlow): MmtpFecSessionMessageUpdate {
345
+ const held = this.#message
346
+ if (!held) throw new Error('MmtpFecSession: updateAlFecFlow() needs a session built from an AL-FEC entry')
347
+ const next = alFecRaptorQFlowConfig(flow)
348
+ if (
349
+ !next ||
350
+ next.sourcePacketIds[0] !== held.sourcePacketIds[0] ||
351
+ next.repairFlowId !== held.repairFlowId ||
352
+ next.fecCodeId !== held.fecCodeId ||
353
+ next.maximumK !== held.maximumK ||
354
+ next.repairSymbolSize !== held.repairSymbolSize
355
+ ) {
356
+ return 'refused'
283
357
  }
284
- this.#decoder = decoder
358
+ if (next.maximumP <= this.#repairSymbols) return 'unchanged'
359
+ this.#repairSymbols = next.maximumP
360
+ this.#heldLayers = layerZero(next.maximumP)
361
+ return 'raised'
285
362
  }
286
363
 
287
364
  /** True once release() ran. */
@@ -386,7 +463,7 @@ export class MmtpFecSession {
386
463
  // An RSB_length below a held layer's total goes to the 7.3.2 stop, not
387
464
  // to the discard; the block state is unchanged either way.
388
465
  const verdict = this.#heldLayers.failsClosed(
389
- repairTrackName, frame.ssStart, frame.rsbLength, this.#anchorHorizon, this.#newestSource,
466
+ this.#trackFor(repairTrackName), frame.ssStart, frame.rsbLength, this.#anchorHorizon, this.#newestSource,
390
467
  )
391
468
  if (verdict) {
392
469
  this.#stats.failClosed = verdict
@@ -399,7 +476,7 @@ export class MmtpFecSession {
399
476
  // fec-01 6.3.9, after the 4.5 discards and the size check, before a block
400
477
  // is placed. Without a track name only the anchored rule (b) applies.
401
478
  const verdict = this.#heldLayers.admit(
402
- repairTrackName,
479
+ this.#trackFor(repairTrackName),
403
480
  frame.ssStart,
404
481
  frame.rsbLength,
405
482
  this.#anchorHorizon,
@@ -464,6 +541,11 @@ export class MmtpFecSession {
464
541
  return true
465
542
  }
466
543
 
544
+ /** Catalog-less: layer 0 has no own-track clause (mmt-02 8.3), so no track name is judged. */
545
+ #trackFor(repairTrackName: string | undefined): string | undefined {
546
+ return this.#message ? undefined : repairTrackName
547
+ }
548
+
467
549
  #drop(reason: string): Uint8Array[] {
468
550
  this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1
469
551
  return []
@@ -600,6 +682,24 @@ export class MmtpFecSession {
600
682
  }
601
683
  }
602
684
 
685
+ function layerZero(total: number): HeldLayerAdmission {
686
+ return new HeldLayerAdmission([{ layer: 0, repairTrackName: '', rsIdOffset: 0, repairSymbols: total }])
687
+ }
688
+
689
+ function buildDecoder(Decoder: MmtpFecSessionDecoderConstructor, session: MmtpFecSession): MmtpFecSessionDecoder {
690
+ if (typeof Decoder !== 'function') {
691
+ throw new Error('MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required')
692
+ }
693
+ const decoder = new Decoder(session.retentionBlocks, session.blockProfile, session.algorithm)
694
+ try {
695
+ decoder.configure_params(session.sourceSymbols, session.symbolSize)
696
+ } catch (error) {
697
+ decoder.free()
698
+ throw error
699
+ }
700
+ return decoder
701
+ }
702
+
603
703
  function requirePositiveInteger(value: unknown, path: string): number {
604
704
  if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
605
705
  throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`)