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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +88 -16
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +164 -56
  5. package/dist/block-policy.js.map +3 -3
  6. package/dist/browser-runtime.js +2163 -303
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +40 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +163 -10
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +48 -1
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.js +34 -0
  17. package/dist/catalog-network-source.js.map +3 -3
  18. package/dist/cmaf-block-assembler.js +92 -1
  19. package/dist/cmaf-block-assembler.js.map +2 -2
  20. package/dist/codec-utils.d.ts.map +1 -1
  21. package/dist/codec-utils.js +92 -1
  22. package/dist/codec-utils.js.map +2 -2
  23. package/dist/delivery-catalog.js +68 -0
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/delta-fallback-config.js +39 -1
  26. package/dist/delta-fallback-config.js.map +4 -4
  27. package/dist/fec-manager.d.ts +222 -21
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +875 -131
  30. package/dist/fec-manager.js.map +4 -4
  31. package/dist/fec-state.d.ts +17 -5
  32. package/dist/fec-state.d.ts.map +1 -1
  33. package/dist/fec-state.js +41 -1
  34. package/dist/fec-state.js.map +3 -3
  35. package/dist/fec-worker-setup.js +34 -0
  36. package/dist/fec-worker-setup.js.map +3 -3
  37. package/dist/held-layer-admission.js +34 -0
  38. package/dist/held-layer-admission.js.map +3 -3
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +9 -1
  42. package/dist/index.js.map +2 -2
  43. package/dist/iso-block-locator.d.ts +55 -13
  44. package/dist/iso-block-locator.d.ts.map +1 -1
  45. package/dist/iso-block-locator.js +142 -25
  46. package/dist/iso-block-locator.js.map +3 -3
  47. package/dist/media-router.js.map +1 -1
  48. package/dist/mfu-reassembler.js +34 -0
  49. package/dist/mfu-reassembler.js.map +3 -3
  50. package/dist/mmtp-container-parser.d.ts +72 -10
  51. package/dist/mmtp-container-parser.d.ts.map +1 -1
  52. package/dist/mmtp-container-parser.js +260 -18
  53. package/dist/mmtp-container-parser.js.map +3 -3
  54. package/dist/mmtp-container-parser.no-modules.js +411 -34
  55. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  56. package/dist/mmtp-decode-pipeline.js +260 -18
  57. package/dist/mmtp-decode-pipeline.js.map +3 -3
  58. package/dist/mmtp-fec-session.js +34 -0
  59. package/dist/mmtp-fec-session.js.map +3 -3
  60. package/dist/mmtp-mode-selection.d.ts +48 -0
  61. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  62. package/dist/mmtp-mode-selection.js +79 -0
  63. package/dist/mmtp-mode-selection.js.map +7 -0
  64. package/dist/mmtp-router.d.ts +94 -16
  65. package/dist/mmtp-router.d.ts.map +1 -1
  66. package/dist/mmtp-router.js +754 -78
  67. package/dist/mmtp-router.js.map +4 -4
  68. package/dist/multicast-auth-catalog.js +42 -2
  69. package/dist/multicast-auth-catalog.js.map +3 -3
  70. package/dist/multicast-input.js +42 -2
  71. package/dist/multicast-input.js.map +3 -3
  72. package/dist/multicast-manager.d.ts +121 -4
  73. package/dist/multicast-manager.d.ts.map +1 -1
  74. package/dist/multicast-manager.js +1774 -248
  75. package/dist/multicast-manager.js.map +4 -4
  76. package/dist/multicast-transport.js +70 -2
  77. package/dist/multicast-transport.js.map +4 -4
  78. package/dist/multicast-unwrap.js +34 -0
  79. package/dist/multicast-unwrap.js.map +3 -3
  80. package/dist/no-modules.d.ts +1 -0
  81. package/dist/no-modules.d.ts.map +1 -1
  82. package/dist/no-modules.js +415 -35
  83. package/dist/no-modules.js.map +4 -4
  84. package/dist/phase14-catalog-override.d.ts +2 -1
  85. package/dist/phase14-catalog-override.d.ts.map +1 -1
  86. package/dist/phase14-catalog-override.js +69 -2
  87. package/dist/phase14-catalog-override.js.map +3 -3
  88. package/dist/repair-fetch.d.ts +38 -8
  89. package/dist/repair-fetch.d.ts.map +1 -1
  90. package/dist/repair-fetch.js +336 -27
  91. package/dist/repair-fetch.js.map +3 -3
  92. package/dist/repair-layer-subscriptions.js +34 -0
  93. package/dist/repair-layer-subscriptions.js.map +3 -3
  94. package/dist/signaling.js +34 -0
  95. package/dist/signaling.js.map +3 -3
  96. package/dist/timestamp-codec.js +34 -0
  97. package/dist/timestamp-codec.js.map +3 -3
  98. package/dist/track-session.d.ts.map +1 -1
  99. package/dist/track-session.js +1 -0
  100. package/dist/track-session.js.map +2 -2
  101. package/dist/wasm-mfu-reassembler.js +34 -0
  102. package/dist/wasm-mfu-reassembler.js.map +3 -3
  103. package/dist/wasm-mmtp-container-parser.js +260 -18
  104. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  105. package/package.json +5 -5
  106. package/schemas/catalog.schema.json +2 -2
  107. package/src/block-policy.ts +324 -83
  108. package/src/carp-catalog.ts +165 -5
  109. package/src/catalog-fec-params.ts +1 -0
  110. package/src/codec-utils.ts +121 -1
  111. package/src/fec-manager.ts +835 -66
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +25 -0
  114. package/src/iso-block-locator.ts +148 -31
  115. package/src/mmtp-container-parser.ts +259 -24
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +774 -86
  118. package/src/multicast-manager.ts +262 -16
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +389 -50
  122. package/src/track-session.ts +3 -0
  123. package/test-vectors/catalog/README.md +36 -2
  124. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  127. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  128. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  130. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  131. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  134. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  135. package/test-vectors/catalog/section-codes.json +3 -3
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
package/src/fec-state.ts CHANGED
@@ -18,7 +18,11 @@ import { resolveFecBindings } from '@blockcast/mmt-base'
18
18
  /** Smallest positive catalog elapsed span; zero/absence means no elapsed deadline. */
19
19
  export const MIN_INTERLEAVE_DEPTH_MS = 1
20
20
 
21
- /** Why FEC is not protecting this session. */
21
+ /**
22
+ * Why FEC is not protecting this session. An "mfu-datagram" subscription
23
+ * (draft-ramadan-moq-mmt-02 4.3.1) is a lossy unicast leg: once joined, FEC
24
+ * is active whatever the transport policy or bridge says.
25
+ */
22
26
  export type FecInactiveReason = 'no-catalog-fec' | 'reliable-moq' | 'no-multicast-bridge'
23
27
 
24
28
  /** Every inactive reason, in resolution order. */
@@ -78,6 +82,12 @@ export interface FecStateEvidence<S extends object> {
78
82
  * it and it has not been closed. A requested leg is not a joined one.
79
83
  */
80
84
  readonly multicastLegJoined: boolean
85
+ /**
86
+ * Whether an "mfu-datagram" subscription is live (SUBSCRIBE_OK received,
87
+ * not ended): a lossy unicast leg that needs no bridge and runs under
88
+ * `moq-only`. Never counted as `multicastLegJoined`. Absent reads false.
89
+ */
90
+ readonly datagramLegJoined?: boolean
81
91
  }
82
92
 
83
93
  const INACTIVE: Readonly<Record<FecInactiveReason, FecInactiveState>> = Object.freeze({
@@ -115,16 +125,18 @@ function requireBoolean(value: unknown, field: string): boolean {
115
125
  * 1. The catalog declares no FEC for a selected track: `no-catalog-fec`. FEC
116
126
  * geometry comes only from the catalog, so there is nothing to configure on
117
127
  * any path.
118
- * 2. The policy is `moq-only`: `reliable-moq`. Media travels only over QUIC,
128
+ * 2. An "mfu-datagram" leg is joined: active. Its datagrams are lossy
129
+ * unicast, whatever the policy or the bridge (mmt-02 4.3.1).
130
+ * 3. The policy is `moq-only`: `reliable-moq`. Media travels only over QUIC,
119
131
  * which is reliable, so FEC has no loss to repair, bridge or not.
120
- * 3. No multicast bridge: `no-multicast-bridge`. No lossy leg can exist, and on
132
+ * 4. No multicast bridge: `no-multicast-bridge`. No lossy leg can exist, and on
121
133
  * `auto` this is the reason the session is on reliable MoQ.
122
- * 4. The policy is `multicast-only`, or a lossy subscription is live: active.
134
+ * 5. The policy is `multicast-only`, or a lossy subscription is live: active.
123
135
  * `multicast-only` commits the session to the lossy leg, so FEC is in force
124
136
  * before the join completes; whether the join succeeded is the physical
125
137
  * attestation's question, not this one. The counters may be absent until
126
138
  * the decoder reports.
127
- * 5. Otherwise (`auto`, a bridge, no live subscription): `reliable-moq`.
139
+ * 6. Otherwise (`auto`, a bridge, no live subscription): `reliable-moq`.
128
140
  *
129
141
  * Throws on malformed evidence rather than picking a reason for it.
130
142
  */
@@ -134,6 +146,9 @@ export function resolveFecState<S extends object>(evidence: FecStateEvidence<S>)
134
146
  const catalogFec = requireBoolean(evidence.catalogFec, 'catalogFec')
135
147
  const bridgeAvailable = requireBoolean(evidence.bridgeAvailable, 'bridgeAvailable')
136
148
  const multicastLegJoined = requireBoolean(evidence.multicastLegJoined, 'multicastLegJoined')
149
+ const datagramLegJoined = evidence.datagramLegJoined === undefined
150
+ ? false
151
+ : requireBoolean(evidence.datagramLegJoined, 'datagramLegJoined')
137
152
  const { transportPolicy, stats } = evidence
138
153
  if (typeof transportPolicy !== 'string' || !TRANSPORT_POLICIES.has(transportPolicy)) {
139
154
  throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`)
@@ -143,6 +158,7 @@ export function resolveFecState<S extends object>(evidence: FecStateEvidence<S>)
143
158
  }
144
159
 
145
160
  if (!catalogFec) return INACTIVE['no-catalog-fec']
161
+ if (datagramLegJoined) return { ...(stats ?? {}), state: 'active' } as FecActiveState<S | NoFecCounters>
146
162
  if (transportPolicy === 'moq-only') return INACTIVE['reliable-moq']
147
163
  if (!bridgeAvailable) return INACTIVE['no-multicast-bridge']
148
164
  if (transportPolicy === 'multicast-only' || multicastLegJoined) {
package/src/index.ts CHANGED
@@ -140,6 +140,9 @@ export {
140
140
  type CmsfCatalogErrorCode,
141
141
  CmsfCatalogValidationError,
142
142
  validateCmsfMmtpCatalog,
143
+ type MmtpTrackIssue,
144
+ type MmtpTrackIssueCode,
145
+ mmtpTrackIssues,
143
146
  type ArchiveConfig,
144
147
  archiveOrigin,
145
148
  } from './carp-catalog.js'
@@ -258,8 +261,14 @@ export {
258
261
  type FecFallbackDecoder,
259
262
  type WasmFecDecoder,
260
263
  type FecStats,
264
+ type FecSymbolSource,
265
+ type DeliveryGapPath,
266
+ type UnresolvedRepairOwnerDrops,
267
+ type UnresolvedRepairOwnerReason,
261
268
  type MulticastSymbolDelivery,
262
269
  type UndelimitedIsoLoss,
270
+ type ExpiredIsoHole,
271
+ type IsoSpanFailure,
263
272
  type FecBlockResolution,
264
273
  type RepairVia,
265
274
  type FecRepairLayer,
@@ -273,6 +282,7 @@ export {
273
282
  KEYFRAME_LOST_TIMEOUT_SLACK,
274
283
  type FrameCallback,
275
284
  type FECManagerLike,
285
+ type MmtpIngestSource,
276
286
  type MmtpIngressContext,
277
287
  type KeyframeOverlayLeg,
278
288
  type KeyframeOverlayFec,
@@ -349,6 +359,8 @@ export {
349
359
  REPAIR_LIFECYCLE_EVENT_TYPE,
350
360
  REPAIR_LIFECYCLE_LOG_PREFIX,
351
361
  type MulticastEndpointConfig,
362
+ type DatagramLegDiagnostics,
363
+ type DatagramLegPlayerCounters,
352
364
  type MultiTrackCatalog,
353
365
  type MultiTrackCatalogTrack,
354
366
  type WasmFecDecoderFactory,
@@ -575,6 +587,8 @@ export {
575
587
  type RepairOverlayParams,
576
588
  // FEC catalog binding, draft-ramadan-moq-fec-catalog-00 array shape (BLO-50171).
577
589
  validateFecCatalog,
590
+ // The report the runtime acts on, for hosts that publish it (BLO-55242).
591
+ runtimeFecCatalogReport,
578
592
  type FecCatalogCode,
579
593
  type FecCatalogInstance,
580
594
  type FecCatalogIssue,
@@ -599,6 +613,17 @@ export {
599
613
  type NoFecCounters,
600
614
  } from "./fec-state.js";
601
615
 
616
+ // Which mmtp sibling to subscribe (mmt-02 4.3.1), one implementation for every
617
+ // player; vectors in test-vectors/moq/mmtp-mode-selection.json.
618
+ export {
619
+ selectMmtpMode,
620
+ type MmtpModeChoice,
621
+ type MmtpModeOverride,
622
+ type MmtpModeReason,
623
+ type MmtpModeSelection,
624
+ type MmtpModeSelectionInput,
625
+ } from "./mmtp-mode-selection.js";
626
+
602
627
  // In-band AL-FEC for one MMTP asset over a MoQT subscription, for a player
603
628
  // that owns its own parser (the Shaka MSF MMTP packaging).
604
629
  export {
@@ -14,9 +14,10 @@
14
14
  * between are one or more blocks whose every repair symbol was lost: they are
15
15
  * kept as one repair-less span, which completes clean once all of its SS_IDs
16
16
  * arrived (C.5.2 makes a gap in consecutive SS_IDs directly visible) and
17
- * otherwise resolves through its catalog-derived deadline. That is the only
18
- * way a block without repair completes: on the next block's SS_Start, never on
19
- * a count of K source symbols.
17
+ * otherwise resolves through its catalog-derived deadline. A block without
18
+ * repair completes that way, on the next block's SS_Start, never on a count of
19
+ * K source symbols, unless a repair that arrives later (a FETCH of the span's
20
+ * first group) states exactly the span's range: the span was that one block.
20
21
  */
21
22
  import {
22
23
  isoBlockContains,
@@ -58,14 +59,29 @@ export type IsoRepairPlacement<T> =
58
59
  */
59
60
  readonly hole?: { readonly block: IsoBlockRange; readonly lostSsId: number }
60
61
  }
61
- /** Not a block this stream can use; the repair symbol is dropped. */
62
- | { readonly status: 'conflict' | 'overlap' | 'stale' | 'ahead'; readonly reason: string }
62
+ /**
63
+ * Not a block this stream can use; the repair symbol is dropped. `ofSpan` is
64
+ * set when the repair stated only the first block of that repair-less span:
65
+ * the span holds more than one block, so no single repair group completes it.
66
+ */
67
+ | {
68
+ readonly status: 'conflict' | 'overlap' | 'stale' | 'ahead'
69
+ readonly reason: string
70
+ readonly ofSpan?: IsoBlockRange
71
+ }
63
72
 
64
73
  /**
65
74
  * Retention: the locator is never without one. Every call that can grow it
66
75
  * (`hold`, `placeRepair`) retires, behind the position it just saw, every
67
76
  * block, span and held source more than `retentionBlocks` blocks back, by the
68
- * one ISO horizon metric (`isoBlocksBehindLowerBound`). A block is measured
77
+ * one ISO horizon metric (`isoBlocksBehindLowerBound`). A held source stays
78
+ * while a pending hole holding it does: the hole's repair FETCH may still
79
+ * state its block, and closing the hole places it, so the span it leaves
80
+ * counts every source it received (BLO-52085). A pending hole the horizon
81
+ * passes stops being pending (its blocks can no longer be stated, and the
82
+ * release gate no longer waits for it), but keeps its sources until its
83
+ * owner closes it (`takeExpiredHoles`), so it still fails as the span it
84
+ * is. A block is measured
69
85
  * from its last SS_ID, so it stays while any SS_ID of it is inside the
70
86
  * horizon: a repair-less span has no length bound, and one measured from its
71
87
  * start could be retired the moment it is created, before the sources it
@@ -88,6 +104,15 @@ export class IsoBlockLocator<T> {
88
104
  #newestSource: number | undefined
89
105
  /** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
90
106
  readonly #holes: IsoBlockRange[] = []
107
+ /** Holes the horizon passed while pending: sources held until closed. */
108
+ readonly #expired: IsoBlockRange[] = []
109
+ /** Of `#expired`, those `takeExpiredHoles` has not handed out yet. */
110
+ readonly #newlyExpired: IsoBlockRange[] = []
111
+ /**
112
+ * Spans closed from expired holes: behind the horizon, so kept only for
113
+ * `locate` while their sources are fed, until the next retirement.
114
+ */
115
+ readonly #closedBehind: IsoBlockRange[] = []
91
116
  /**
92
117
  * Keep a gap that is missing a source as a pending hole rather than a span,
93
118
  * so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
@@ -192,18 +217,31 @@ export class IsoBlockLocator<T> {
192
217
 
193
218
  /** The known block or span containing `ssId`, with its ESI. */
194
219
  locate(ssId: number): { block: IsoBlockRange; esi: number } | null {
195
- for (let i = this.#blocks.length - 1; i >= 0; i--) {
196
- const block = this.#blocks[i]!
197
- if (isoBlockContains(block.start, block.length, ssId)) {
198
- return { block, esi: serial32Distance(block.start, ssId) }
220
+ for (const blocks of [this.#blocks, this.#closedBehind]) {
221
+ for (let i = blocks.length - 1; i >= 0; i--) {
222
+ const block = blocks[i]!
223
+ if (isoBlockContains(block.start, block.length, ssId)) {
224
+ return { block, esi: serial32Distance(block.start, ssId) }
225
+ }
199
226
  }
200
227
  }
201
228
  return null
202
229
  }
203
230
 
204
- /** Number of pending holes. */
231
+ /** Number of holes not closed yet, pending or past the horizon. */
205
232
  get holeCount(): number {
206
- return this.#holes.length
233
+ return this.#holes.length + this.#expired.length
234
+ }
235
+
236
+ /**
237
+ * The pending holes the horizon has passed since the last call, in the
238
+ * order it passed them. Each is no longer pending: no repair states a block
239
+ * in it (that repair is `stale`, as for a span the horizon retired) and the
240
+ * release gate does not wait for it. Its owner must close it
241
+ * (`closeHolesWithin`), which turns it into a span that is not kept here.
242
+ */
243
+ takeExpiredHoles(): IsoBlockRange[] {
244
+ return this.#newlyExpired.splice(0)
207
245
  }
208
246
 
209
247
  /** The stated block (never a span) ending exactly at `end`. */
@@ -265,12 +303,48 @@ export class IsoBlockLocator<T> {
265
303
  return this.#held.has(ssId)
266
304
  }
267
305
 
306
+ /** The payload held unplaced for `ssId`, if any. */
307
+ heldSource(ssId: number): T | undefined {
308
+ return this.#held.get(ssId)
309
+ }
310
+
311
+ /**
312
+ * The SS_IDs strictly between `a` and `b` that no repair has delimited a
313
+ * block of yet: those from the coverage end on, or all of them before the
314
+ * first repair. `missing` is the highest of them no source is held for;
315
+ * absent, every one of them arrived (C.5.2: SS_IDs are consecutive). Null
316
+ * when none lies past coverage. `flagged` is whether a source held among
317
+ * them satisfies `flag` (a RAP fragment, say): the held packets read as
318
+ * fec-multicast-00 Block Classification item 1 reads bounding packets.
319
+ */
320
+ undelimitedBetween(
321
+ a: number,
322
+ b: number,
323
+ flag?: (payload: T) => boolean,
324
+ ): { start: number; missing?: number; flagged: boolean } | null {
325
+ if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return null
326
+ const first = (a + 1) >>> 0
327
+ const end = this.#coverageEnd
328
+ const start = end !== undefined && serial32Precedes(first, end) ? end : first
329
+ if (!serial32Precedes(start, b)) return null
330
+ const length = serial32Distance(start, b)
331
+ const missing = this.#highestMissing(start, length)
332
+ let flagged = false
333
+ for (let i = 0; flag !== undefined && !flagged && i < length; i++) {
334
+ const payload = this.#held.get(serial32Add(start, i))
335
+ flagged = payload !== undefined && flag(payload)
336
+ }
337
+ return missing === undefined ? { start, flagged } : { start, missing, flagged }
338
+ }
339
+
268
340
  /**
269
341
  * Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
270
342
  * block states its range and places every held source in it; later repair
271
- * symbols of the same block change nothing. A range that contradicts a
272
- * known block (a different length, or an overlap with another block or a
273
- * span) fails closed: the repair symbol is dropped and no block changes.
343
+ * symbols of the same block change nothing. A repair whose range is exactly
344
+ * a repair-less span states that span's one block. A range that contradicts
345
+ * a known block (a different length, or an overlap with another block or
346
+ * with part of a span) fails closed: the repair symbol is dropped and no
347
+ * block changes.
274
348
  * A newly stated block retires behind its SS_Start (see the class note).
275
349
  * A block so far past `newest` that stating it would retire the position
276
350
  * `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
@@ -289,7 +363,25 @@ export class IsoBlockLocator<T> {
289
363
  const known = this.blockAt(start)
290
364
  if (known !== undefined) {
291
365
  if (known.span) {
292
- return { status: 'overlap', reason: `repair block ${start}+${length} falls inside a repair-less span` }
366
+ // A span is no accepted block: it is the whole blocks between two
367
+ // stated ones whose repair never came (blocks are consecutive), so a
368
+ // repair whose range is exactly the span states its one block and
369
+ // contradicts nothing (draft-ramadan-moq-fec-core-00 5.4). Its sources
370
+ // were placed at these same ESIs when the span closed. A FETCH of the
371
+ // span's Group ext(SS_Start) returns just this when one block lost
372
+ // every multicast repair (a join).
373
+ if (known.length === length) {
374
+ const block: IsoBlockRange = { start, length, span: false }
375
+ this.#blocks[this.#blocks.indexOf(known)] = block
376
+ return { status: 'placed', block, placed: [] }
377
+ }
378
+ return length < known.length
379
+ ? {
380
+ status: 'overlap',
381
+ reason: `repair block ${start}+${length} is only the first block of repair-less span ${known.start}+${known.length}`,
382
+ ofSpan: known,
383
+ }
384
+ : { status: 'overlap', reason: `repair block ${start}+${length} runs past repair-less span ${known.start}+${known.length}` }
293
385
  }
294
386
  if (known.length !== length) {
295
387
  return {
@@ -367,18 +459,28 @@ export class IsoBlockLocator<T> {
367
459
  }
368
460
 
369
461
  /**
370
- * Turn every pending hole inside `[start, start + length)` into a
371
- * repair-less span, claiming its held sources: its range FETCH ended, so
372
- * nothing more will state its blocks. Returns the spans, in SS_ID order.
462
+ * Turn every hole inside `[start, start + length)` into a repair-less span,
463
+ * claiming its held sources: its range FETCH ended, so nothing more will
464
+ * state its blocks. A hole the horizon passed (`takeExpiredHoles`) leaves a
465
+ * span that is not kept among the blocks, as the horizon would retire it at
466
+ * once; only `locate` finds it, until the next retirement, so its sources
467
+ * can be fed. Returns the spans, in SS_ID order.
373
468
  */
374
469
  closeHolesWithin(start: number, length: number): { block: IsoBlockRange; placed: IsoPlacedSource<T>[] }[] {
375
470
  const closed: { block: IsoBlockRange; placed: IsoPlacedSource<T>[] }[] = []
376
- for (const hole of [...this.#holes]) {
377
- if (!isoBlockContains(start, length, hole.start)) continue
378
- this.#holes.splice(this.#holes.indexOf(hole), 1)
379
- const spanBlock: IsoBlockRange = { start: hole.start, length: hole.length, span: true }
380
- closed.push({ block: spanBlock, placed: this.#claim(spanBlock) })
381
- this.#blocks.push(spanBlock)
471
+ for (const holes of [this.#holes, this.#expired]) {
472
+ for (const hole of [...holes]) {
473
+ if (!isoBlockContains(start, length, hole.start)) continue
474
+ holes.splice(holes.indexOf(hole), 1)
475
+ const spanBlock: IsoBlockRange = { start: hole.start, length: hole.length, span: true }
476
+ closed.push({ block: spanBlock, placed: this.#claim(spanBlock) })
477
+ if (holes === this.#holes) {
478
+ this.#blocks.push(spanBlock)
479
+ } else {
480
+ this.#closedBehind.push(spanBlock)
481
+ if (this.#newlyExpired.includes(hole)) this.#newlyExpired.splice(this.#newlyExpired.indexOf(hole), 1)
482
+ }
483
+ }
382
484
  }
383
485
  return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start))
384
486
  }
@@ -395,15 +497,17 @@ export class IsoBlockLocator<T> {
395
497
  }
396
498
 
397
499
  /**
398
- * Retire every block and span whose last SS_ID, and every held source,
399
- * lies more than `retentionBlocks` blocks behind `position`, with the shared
400
- * lower-bound metric (`isoBlocksBehindLowerBound`) every ISO interleave
401
- * horizon uses. Returns the retired block starts.
500
+ * Retire every block and span whose last SS_ID, and every held source
501
+ * outside a hole, lies more than `retentionBlocks` blocks behind
502
+ * `position`, with the shared lower-bound metric (`isoBlocksBehindLowerBound`)
503
+ * every ISO interleave horizon uses; a pending hole so far behind expires
504
+ * (`takeExpiredHoles`). Returns the retired block starts.
402
505
  */
403
506
  retireBehind(position: number): number[] {
404
507
  this.observe(position)
405
508
  const horizon = this.#retentionBlocks
406
509
  const retired: number[] = []
510
+ this.#closedBehind.length = 0
407
511
  for (let i = this.#blocks.length - 1; i >= 0; i--) {
408
512
  const block = this.#blocks[i]!
409
513
  const last = serial32Add(block.start, block.length - 1)
@@ -415,10 +519,20 @@ export class IsoBlockLocator<T> {
415
519
  for (let i = this.#holes.length - 1; i >= 0; i--) {
416
520
  const hole = this.#holes[i]!
417
521
  const last = serial32Add(hole.start, hole.length - 1)
418
- if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1)
522
+ if (isoBlocksBehindLowerBound(last, position, this.#kMax) <= horizon) continue
523
+ this.#holes.splice(i, 1)
524
+ this.#expired.push(hole)
525
+ this.#newlyExpired.push(hole)
419
526
  }
527
+ // A held source stays while a hole holding it does (class note).
420
528
  for (const ssId of [...this.#held.keys()]) {
421
- if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId)
529
+ if (
530
+ isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon &&
531
+ !this.#holes.some((hole) => isoBlockContains(hole.start, hole.length, ssId)) &&
532
+ !this.#expired.some((hole) => isoBlockContains(hole.start, hole.length, ssId))
533
+ ) {
534
+ this.#held.delete(ssId)
535
+ }
422
536
  }
423
537
  return retired
424
538
  }
@@ -427,6 +541,9 @@ export class IsoBlockLocator<T> {
427
541
  reset(): void {
428
542
  this.#blocks.length = 0
429
543
  this.#holes.length = 0
544
+ this.#expired.length = 0
545
+ this.#newlyExpired.length = 0
546
+ this.#closedBehind.length = 0
430
547
  this.#held.clear()
431
548
  this.#coverageEnd = undefined
432
549
  this.#newest = undefined