@blockcast/mmt-container 2.2.0-main.cc080e5a56f2 → 2.2.0-main.cc3fe0684403

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 +1485 -172
  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/datagram-leg-deadline.d.ts +118 -0
  24. package/dist/datagram-leg-deadline.d.ts.map +1 -0
  25. package/dist/datagram-leg-deadline.js +217 -0
  26. package/dist/datagram-leg-deadline.js.map +7 -0
  27. package/dist/delivery-catalog.js +68 -0
  28. package/dist/delivery-catalog.js.map +4 -4
  29. package/dist/delta-fallback-config.js +39 -1
  30. package/dist/delta-fallback-config.js.map +4 -4
  31. package/dist/fec-manager.d.ts +155 -10
  32. package/dist/fec-manager.d.ts.map +1 -1
  33. package/dist/fec-manager.js +596 -81
  34. package/dist/fec-manager.js.map +4 -4
  35. package/dist/fec-state.d.ts +17 -5
  36. package/dist/fec-state.d.ts.map +1 -1
  37. package/dist/fec-state.js +41 -1
  38. package/dist/fec-state.js.map +3 -3
  39. package/dist/fec-worker-setup.js +34 -0
  40. package/dist/fec-worker-setup.js.map +3 -3
  41. package/dist/held-layer-admission.js +34 -0
  42. package/dist/held-layer-admission.js.map +3 -3
  43. package/dist/index.d.ts +7 -5
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +15 -1
  46. package/dist/index.js.map +2 -2
  47. package/dist/iso-block-locator.d.ts +16 -0
  48. package/dist/iso-block-locator.d.ts.map +1 -1
  49. package/dist/iso-block-locator.js +62 -0
  50. package/dist/iso-block-locator.js.map +3 -3
  51. package/dist/mfu-reassembler.js +34 -0
  52. package/dist/mfu-reassembler.js.map +3 -3
  53. package/dist/mmtp-container-parser.d.ts +30 -2
  54. package/dist/mmtp-container-parser.d.ts.map +1 -1
  55. package/dist/mmtp-container-parser.js +140 -2
  56. package/dist/mmtp-container-parser.js.map +3 -3
  57. package/dist/mmtp-container-parser.no-modules.js +293 -18
  58. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  59. package/dist/mmtp-decode-pipeline.js +140 -2
  60. package/dist/mmtp-decode-pipeline.js.map +3 -3
  61. package/dist/mmtp-fec-session.js +34 -0
  62. package/dist/mmtp-fec-session.js.map +3 -3
  63. package/dist/mmtp-mode-selection.d.ts +48 -0
  64. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  65. package/dist/mmtp-mode-selection.js +79 -0
  66. package/dist/mmtp-mode-selection.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +66 -8
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +348 -27
  70. package/dist/mmtp-router.js.map +4 -4
  71. package/dist/multicast-auth-catalog.js +42 -2
  72. package/dist/multicast-auth-catalog.js.map +3 -3
  73. package/dist/multicast-input.js +42 -2
  74. package/dist/multicast-input.js.map +3 -3
  75. package/dist/multicast-manager.d.ts +108 -1
  76. package/dist/multicast-manager.d.ts.map +1 -1
  77. package/dist/multicast-manager.js +1067 -138
  78. package/dist/multicast-manager.js.map +4 -4
  79. package/dist/multicast-transport.js +68 -0
  80. package/dist/multicast-transport.js.map +4 -4
  81. package/dist/multicast-unwrap.js +34 -0
  82. package/dist/multicast-unwrap.js.map +3 -3
  83. package/dist/no-modules.d.ts +1 -0
  84. package/dist/no-modules.d.ts.map +1 -1
  85. package/dist/no-modules.js +295 -19
  86. package/dist/no-modules.js.map +4 -4
  87. package/dist/phase14-catalog-override.d.ts +2 -1
  88. package/dist/phase14-catalog-override.d.ts.map +1 -1
  89. package/dist/phase14-catalog-override.js +69 -2
  90. package/dist/phase14-catalog-override.js.map +3 -3
  91. package/dist/repair-fetch.d.ts.map +1 -1
  92. package/dist/repair-fetch.js +50 -0
  93. package/dist/repair-fetch.js.map +3 -3
  94. package/dist/repair-layer-subscriptions.js +34 -0
  95. package/dist/repair-layer-subscriptions.js.map +3 -3
  96. package/dist/signaling.js +34 -0
  97. package/dist/signaling.js.map +3 -3
  98. package/dist/timestamp-codec.js +34 -0
  99. package/dist/timestamp-codec.js.map +3 -3
  100. package/dist/wasm-mfu-reassembler.js +34 -0
  101. package/dist/wasm-mfu-reassembler.js.map +3 -3
  102. package/dist/wasm-mmtp-container-parser.js +140 -2
  103. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  104. package/package.json +5 -5
  105. package/schemas/catalog.schema.json +2 -2
  106. package/src/block-policy.ts +324 -83
  107. package/src/carp-catalog.ts +165 -5
  108. package/src/catalog-fec-params.ts +1 -0
  109. package/src/codec-utils.ts +121 -1
  110. package/src/datagram-leg-deadline.ts +342 -0
  111. package/src/fec-manager.ts +534 -41
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +38 -0
  114. package/src/iso-block-locator.ts +34 -0
  115. package/src/mmtp-container-parser.ts +57 -11
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +287 -42
  118. package/src/multicast-manager.ts +218 -10
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +23 -0
  122. package/test-vectors/catalog/README.md +36 -2
  123. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  124. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  127. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  128. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  130. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  131. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  134. package/test-vectors/catalog/section-codes.json +3 -3
  135. package/test-vectors/catalog-timing.json +559 -1
  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,6 +261,10 @@ 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,
263
270
  type ExpiredIsoHole,
@@ -275,6 +282,7 @@ export {
275
282
  KEYFRAME_LOST_TIMEOUT_SLACK,
276
283
  type FrameCallback,
277
284
  type FECManagerLike,
285
+ type MmtpIngestSource,
278
286
  type MmtpIngressContext,
279
287
  type KeyframeOverlayLeg,
280
288
  type KeyframeOverlayFec,
@@ -351,6 +359,8 @@ export {
351
359
  REPAIR_LIFECYCLE_EVENT_TYPE,
352
360
  REPAIR_LIFECYCLE_LOG_PREFIX,
353
361
  type MulticastEndpointConfig,
362
+ type DatagramLegDiagnostics,
363
+ type DatagramLegPlayerCounters,
354
364
  type MultiTrackCatalog,
355
365
  type MultiTrackCatalogTrack,
356
366
  type WasmFecDecoderFactory,
@@ -577,6 +587,8 @@ export {
577
587
  type RepairOverlayParams,
578
588
  // FEC catalog binding, draft-ramadan-moq-fec-catalog-00 array shape (BLO-50171).
579
589
  validateFecCatalog,
590
+ // The report the runtime acts on, for hosts that publish it (BLO-55242).
591
+ runtimeFecCatalogReport,
580
592
  type FecCatalogCode,
581
593
  type FecCatalogInstance,
582
594
  type FecCatalogIssue,
@@ -601,6 +613,32 @@ export {
601
613
  type NoFecCounters,
602
614
  } from "./fec-state.js";
603
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
+
627
+ // When an "mfu-datagram" leg is taken and when it is handed back (mmt-02
628
+ // 4.3.1): the delay target and the catalog FEC window, no constant. One
629
+ // implementation for every player; vectors in test-vectors/catalog-timing.json.
630
+ export {
631
+ computeDatagramLegDeadlines,
632
+ DatagramLegWatch,
633
+ type DatagramLegDeadlineInput,
634
+ type DatagramLegDeadlineReason,
635
+ type DatagramLegDeadlines,
636
+ type DatagramLegFecInstance,
637
+ type DatagramLegLimits,
638
+ type DatagramLegVerdict,
639
+ type DatagramLegWatchOptions,
640
+ } from "./datagram-leg-deadline.js";
641
+
604
642
  // In-band AL-FEC for one MMTP asset over a MoQT subscription, for a player
605
643
  // that owns its own parser (the Shaka MSF MMTP packaging).
606
644
  export {
@@ -303,6 +303,40 @@ export class IsoBlockLocator<T> {
303
303
  return this.#held.has(ssId)
304
304
  }
305
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
+
306
340
  /**
307
341
  * Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
308
342
  * block states its range and places every held source in it; later repair
@@ -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,24 @@ 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. Behind a run no repair has delimited, until the
246
+ * run's FEC deadline, since a repair may delimit it until then.
247
+ * `fromSbn` is the anchor of the frame released before the gap, `toSbn`
248
+ * this frame's, `after.arrivedAtMs` its arrival (performance.now()). Past
249
+ * the wait the frame goes, decided, as it would once those blocks failed.
250
+ */
251
+ unrepairableWaitMs?(
252
+ before: { data: Uint8Array; meta: FrameMeta },
253
+ after: { data: Uint8Array; meta: FrameMeta; arrivedAtMs?: number },
254
+ fromSbn: number,
255
+ toSbn: number,
256
+ ): number | undefined
237
257
  /** Decide stall/conceal for the first frame released after a gap. */
238
258
  decide(
239
259
  before: { data: Uint8Array; meta: FrameMeta },
@@ -257,6 +277,12 @@ export interface FecReleaseGate {
257
277
  * frame when it did unanchored (#cursorPassed).
258
278
  */
259
279
  releaseUnanchored?(packetId: number, catalogTrackName: string | undefined): boolean
280
+ /**
281
+ * A frame held only for its `unrepairableWaitMs` may go at `atMs`
282
+ * (performance.now()): poke the stream (pokeFecRelease) then. Absent, it
283
+ * goes at the next push or poke after that.
284
+ */
285
+ wakeAt?(packetId: number, catalogTrackName: string | undefined, atMs: number): void
260
286
  }
261
287
 
262
288
  /** Typed ISO-BMFF timing-sample budget counters. See `timingBudgetStats`. */
@@ -786,18 +812,24 @@ interface GatedStream {
786
812
  * to the last released frame is released immediately. A frame after a gap
787
813
  * waits until every block between the last released frame's block and its
788
814
  * 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`.
815
+ * still fill the gap. Once only a late source or the keyframe overlay could
816
+ * fill it, the frame waits only the gate's `unrepairableWaitMs` from its
817
+ * arrival: the late-symbol allowance, or longer when the gap may hold a RAP
818
+ * the overlay could still rebuild. A frame the keyframe overlay rebuilt
819
+ * waits only for the blocks before its MPU (FrameMeta.fecSbnFirst), and no
820
+ * longer than the source cursor would hold it unanchored
821
+ * (#cursorPassed). When the resolved blocks lost media, or authored decode
822
+ * time shows a missing sample, the release carries the gate's stall/conceal
823
+ * decision as `gapBefore`.
794
824
  *
795
825
  * The wait is bounded here, not by the blocks: a frame held longer than the
796
826
  * gate's `holdLimitMs` since it arrived is released with the gate's
797
827
  * 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.
828
+ * grow the buffer without limit. That ceiling has no timer: the check runs
829
+ * on the next push or poke, so after a total outage held frames are released
830
+ * by the first packet that arrives, not at the ceiling itself. Only the
831
+ * `unrepairableWaitMs` wait is timed: the gate is asked to poke the stream
832
+ * when it ends (`wakeAt`), since a burst may be the last traffic for a while.
801
833
  */
802
834
  class FecReleaseSequencer {
803
835
  #streams = new Map<string, GatedStream>()
@@ -1160,7 +1192,7 @@ class FecReleaseSequencer {
1160
1192
  from,
1161
1193
  )
1162
1194
  unresolved = resolved === null
1163
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
1195
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
1164
1196
  const heldMs = performance.now() - head.arrivedAtMs
1165
1197
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return
1166
1198
  // Past the point where these blocks must have resolved: nothing
@@ -1188,6 +1220,20 @@ class FecReleaseSequencer {
1188
1220
  }
1189
1221
  }
1190
1222
 
1223
+ /**
1224
+ * The head has waited out a gap only a late source can still fill
1225
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
1226
+ * the stream when it has (`wakeAt`), since no packet may come by then.
1227
+ */
1228
+ #unrepairableWaitOver(stream: GatedStream, last: PendingFrame, head: GatedFrame, from: number, to: number): boolean {
1229
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to)
1230
+ if (waitMs === undefined) return false
1231
+ const atMs = head.arrivedAtMs + waitMs
1232
+ if (performance.now() >= atMs) return true
1233
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs)
1234
+ return false
1235
+ }
1236
+
1191
1237
  /**
1192
1238
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
1193
1239
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -0,0 +1,80 @@
1
+ // Which mmtp sibling a player subscribes (draft-ramadan-moq-mmt-02 4.3.1):
2
+ // the "mfu" track on a reliable path, the "mfu-datagram" track on an
3
+ // unreliable session that can carry its repair objects. One implementation
4
+ // for every player, with shared vectors in
5
+ // test-vectors/moq/mmtp-mode-selection.json, so the A/B knob and the
6
+ // fallback rules cannot drift between them.
7
+
8
+ import { datagramLegObjectMax } from '@blockcast/mmt-base'
9
+ import type { FecTransportPolicy } from './fec-state.js'
10
+
11
+ export type MmtpModeChoice = 'mfu' | 'mfu-datagram'
12
+
13
+ /** The player override: moqtail URL `mmtpMode=`, hang attribute `mmtp-mode`. */
14
+ export type MmtpModeOverride = 'auto' | MmtpModeChoice
15
+
16
+ export type MmtpModeReason =
17
+ /** `multicast-only` subscribes no unicast media; "mfu" for the record. */
18
+ | 'multicast-only'
19
+ /** The override named the mode. */
20
+ | 'override'
21
+ /** The override asked for "mfu-datagram" on a reliable session (HTTP/2 WebTransport, WebSocket): refused, "mfu". */
22
+ | 'override-refused-reliable'
23
+ /** The datagram track binds no FEC instance the player decodes: its leg would lose and never recover. */
24
+ | 'datagram-fec-undecodable'
25
+ /** The catalog pairs no "mfu-datagram" track with the selected rendition: "mfu", the `mfu-datagram` override included. */
26
+ | 'no-datagram-sibling'
27
+ /** The session is reliable: datagrams would be streams, and a lost one blocks everything. */
28
+ | 'reliable-session'
29
+ /** The session's maximum datagram size cannot carry the track's repair objects. */
30
+ | 'repair-object-too-large'
31
+ /** An unreliable session with room: the datagram leg. */
32
+ | 'datagram'
33
+
34
+ export interface MmtpModeSelectionInput {
35
+ /** The catalog pairs an "mfu-datagram" track with the selected "mfu" track (`pairMmtpSiblings`). */
36
+ readonly datagramSibling: boolean
37
+ /** `WebTransport.reliability === 'supports-unreliable'`; false on HTTP/2, WebSocket, or when unknown (fail closed). */
38
+ readonly unreliable: boolean
39
+ /** `WebTransport.datagrams.maxDatagramSize` of the live session, when known. */
40
+ readonly maxDatagramSize?: number
41
+ /** The datagram track's `fec.symbolSize` T, when known: its repair object is the leg's largest. */
42
+ readonly symbolSize?: number
43
+ /**
44
+ * Whether the datagram track's `fec` binds an instance the player decodes,
45
+ * by the player's own resolver (a bound base instance under a block profile
46
+ * it implements). `false` takes "mfu", the override included: FEC and the
47
+ * release gate are the leg's only loss handling (4.3.1), so without them it
48
+ * drops what the "mfu" track delivers. Absent: not stated, never read.
49
+ */
50
+ readonly datagramFecDecodable?: boolean
51
+ readonly transportPolicy: FecTransportPolicy
52
+ readonly override: MmtpModeOverride
53
+ }
54
+
55
+ export interface MmtpModeSelection {
56
+ readonly mode: MmtpModeChoice
57
+ readonly reason: MmtpModeReason
58
+ }
59
+
60
+ /** First rule that applies wins; pure, never throws. */
61
+ export function selectMmtpMode(input: MmtpModeSelectionInput): MmtpModeSelection {
62
+ if (input.transportPolicy === 'multicast-only') return { mode: 'mfu', reason: 'multicast-only' }
63
+ if (input.override === 'mfu') return { mode: 'mfu', reason: 'override' }
64
+ // Before the override: it cannot name a track the catalog does not pair.
65
+ if (!input.datagramSibling) return { mode: 'mfu', reason: 'no-datagram-sibling' }
66
+ if (input.datagramFecDecodable === false) return { mode: 'mfu', reason: 'datagram-fec-undecodable' }
67
+ if (input.override === 'mfu-datagram') {
68
+ return input.unreliable
69
+ ? { mode: 'mfu-datagram', reason: 'override' }
70
+ : { mode: 'mfu', reason: 'override-refused-reliable' }
71
+ }
72
+ if (!input.unreliable) return { mode: 'mfu', reason: 'reliable-session' }
73
+ if (
74
+ input.maxDatagramSize !== undefined && input.symbolSize !== undefined &&
75
+ input.maxDatagramSize < datagramLegObjectMax(input.symbolSize)
76
+ ) {
77
+ return { mode: 'mfu', reason: 'repair-object-too-large' }
78
+ }
79
+ return { mode: 'mfu-datagram', reason: 'datagram' }
80
+ }