@blockcast/mmt-container 0.4.0 → 0.4.1-main.2e0aa69d293d

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 (220) hide show
  1. package/README.md +37 -21
  2. package/dist/align.d.ts +24 -18
  3. package/dist/align.d.ts.map +1 -1
  4. package/dist/align.js +23 -4
  5. package/dist/align.js.map +2 -2
  6. package/dist/browser-runtime.js +5070 -908
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +76 -39
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +321 -205
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +12 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +40 -17
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +28 -7
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +21 -1
  19. package/dist/catalog-network-source.js.map +2 -2
  20. package/dist/catalog-validator.d.ts +4 -3
  21. package/dist/catalog-validator.d.ts.map +1 -1
  22. package/dist/catalog-validator.js +0 -29
  23. package/dist/catalog-validator.js.map +3 -3
  24. package/dist/cmcd-producer.d.ts +13 -1
  25. package/dist/cmcd-producer.d.ts.map +1 -1
  26. package/dist/cmcd-producer.js +14 -0
  27. package/dist/cmcd-producer.js.map +2 -2
  28. package/dist/delivery-catalog.js +115 -235
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +113 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +464 -66
  33. package/dist/fec-manager.js.map +4 -4
  34. package/dist/fec-state.d.ts +2 -1
  35. package/dist/fec-state.d.ts.map +1 -1
  36. package/dist/fec-state.js +18 -3
  37. package/dist/fec-state.js.map +3 -3
  38. package/dist/fec-worker-setup.d.ts +10 -0
  39. package/dist/fec-worker-setup.d.ts.map +1 -1
  40. package/dist/fec-worker-setup.js +15 -4
  41. package/dist/fec-worker-setup.js.map +2 -2
  42. package/dist/held-layer-admission.d.ts +58 -0
  43. package/dist/held-layer-admission.d.ts.map +1 -0
  44. package/dist/held-layer-admission.js +105 -0
  45. package/dist/held-layer-admission.js.map +7 -0
  46. package/dist/index.d.ts +5 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +8 -8
  49. package/dist/index.js.map +2 -2
  50. package/dist/iso-block-locator.d.ts +39 -1
  51. package/dist/iso-block-locator.d.ts.map +1 -1
  52. package/dist/iso-block-locator.js +109 -17
  53. package/dist/iso-block-locator.js.map +3 -3
  54. package/dist/mfu-reassembler.js +21 -13
  55. package/dist/mfu-reassembler.js.map +2 -2
  56. package/dist/mmtp-container-parser.d.ts.map +1 -1
  57. package/dist/mmtp-container-parser.js +93 -22
  58. package/dist/mmtp-container-parser.js.map +2 -2
  59. package/dist/mmtp-container-parser.no-modules.js +3692 -1213
  60. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  61. package/dist/mmtp-decode-pipeline.js +93 -22
  62. package/dist/mmtp-decode-pipeline.js.map +2 -2
  63. package/dist/mmtp-fec-session.d.ts +192 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +640 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +101 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +422 -189
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +94 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +746 -131
  74. package/dist/multicast-auth-catalog.js.map +4 -4
  75. package/dist/multicast-input.d.ts +31 -8
  76. package/dist/multicast-input.d.ts.map +1 -1
  77. package/dist/multicast-input.js +299 -35
  78. package/dist/multicast-input.js.map +3 -3
  79. package/dist/multicast-manager.d.ts +140 -12
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +4104 -605
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +16 -3
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +127 -240
  86. package/dist/multicast-transport.js.map +4 -4
  87. package/dist/multicast-unwrap.js +21 -13
  88. package/dist/multicast-unwrap.js.map +2 -2
  89. package/dist/no-modules.d.ts +5 -3
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +3643 -1197
  92. package/dist/no-modules.js.map +4 -4
  93. package/dist/phase14-catalog-override.d.ts +1 -1
  94. package/dist/phase14-catalog-override.d.ts.map +1 -1
  95. package/dist/phase14-catalog-override.js +2 -2
  96. package/dist/phase14-catalog-override.js.map +2 -2
  97. package/dist/repair-fetch.d.ts +90 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +160 -32
  100. package/dist/repair-fetch.js.map +3 -3
  101. package/dist/repair-layers.d.ts +2 -0
  102. package/dist/repair-layers.d.ts.map +1 -1
  103. package/dist/repair-layers.js +19 -2
  104. package/dist/repair-layers.js.map +2 -2
  105. package/dist/sample-combiner.d.ts +7 -1
  106. package/dist/sample-combiner.d.ts.map +1 -1
  107. package/dist/sample-combiner.js +14 -2
  108. package/dist/sample-combiner.js.map +2 -2
  109. package/dist/signaling.d.ts +2 -2
  110. package/dist/signaling.d.ts.map +1 -1
  111. package/dist/signaling.js +3 -3
  112. package/dist/signaling.js.map +2 -2
  113. package/dist/switching-set-alignment.d.ts +1 -1
  114. package/dist/switching-set-alignment.js.map +1 -1
  115. package/dist/timestamp-codec.js +21 -13
  116. package/dist/timestamp-codec.js.map +2 -2
  117. package/dist/wasm-mfu-reassembler.js.map +1 -1
  118. package/dist/wasm-mmtp-container-parser.js +93 -22
  119. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  120. package/package.json +6 -18
  121. package/schemas/catalog.schema.json +133 -38
  122. package/src/align.ts +52 -21
  123. package/src/carp-catalog.ts +188 -68
  124. package/src/catalog-fec-params.ts +28 -3
  125. package/src/catalog-network-source.ts +49 -7
  126. package/src/catalog-validator.ts +4 -11
  127. package/src/cmcd-producer.ts +23 -1
  128. package/src/fec-manager.ts +378 -63
  129. package/src/fec-state.ts +11 -4
  130. package/src/fec-worker-setup.ts +30 -2
  131. package/src/held-layer-admission.ts +161 -0
  132. package/src/index.ts +32 -19
  133. package/src/iso-block-locator.ts +110 -7
  134. package/src/mmtp-container-parser.ts +75 -7
  135. package/src/mmtp-fec-session.ts +606 -0
  136. package/src/mmtp-router.ts +453 -236
  137. package/src/multicast-auth-catalog.ts +196 -231
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +447 -53
  140. package/src/multicast-transport.ts +23 -5
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +306 -42
  144. package/src/repair-layers.ts +22 -2
  145. package/src/sample-combiner.ts +15 -2
  146. package/src/signaling.ts +2 -2
  147. package/src/switching-set-alignment.ts +1 -1
  148. package/test-vectors/align.json +108 -32
  149. package/test-vectors/bc-provenance-v2.json +1526 -0
  150. package/test-vectors/catalog/README.md +71 -4
  151. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  152. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  153. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  154. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  156. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  158. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  159. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  160. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  161. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  162. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  163. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  164. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  165. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  167. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  168. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  169. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  170. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  172. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  174. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  177. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  178. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  179. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  181. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  182. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  184. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  185. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  186. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  187. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  188. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  189. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  190. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  191. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  192. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  193. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  194. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  195. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  196. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  197. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  198. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  199. package/test-vectors/catalog/section-codes.json +31 -1
  200. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  201. package/test-vectors/catalog-validation.json +101 -5
  202. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  203. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  204. package/dist/fec-codec.d.ts +0 -32
  205. package/dist/fec-codec.d.ts.map +0 -1
  206. package/dist/fec-codec.js +0 -47
  207. package/dist/fec-codec.js.map +0 -7
  208. package/dist/manifest-auth-plan.d.ts +0 -30
  209. package/dist/manifest-auth-plan.d.ts.map +0 -1
  210. package/dist/manifest-auth-plan.js +0 -1266
  211. package/dist/manifest-auth-plan.js.map +0 -7
  212. package/dist/source-auth.d.ts +0 -2
  213. package/dist/source-auth.d.ts.map +0 -1
  214. package/dist/source-auth.js +0 -1209
  215. package/dist/source-auth.js.map +0 -7
  216. package/src/fec-codec.ts +0 -61
  217. package/src/manifest-auth-plan.ts +0 -107
  218. package/src/source-auth.ts +0 -1
  219. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  220. package/test-vectors/source-auth-v1.json +0 -61
@@ -18,6 +18,8 @@ import {
18
18
  type FecFallbackDecoder,
19
19
  type MulticastSymbolDelivery,
20
20
  type RepairVia,
21
+ type UndelimitedIsoLoss,
22
+ type FecFailClosedEvent,
21
23
  } from "./fec-manager.js";
22
24
  import {
23
25
  deriveBlockClassifierGeometry,
@@ -31,29 +33,33 @@ import {
31
33
  type TrackKind,
32
34
  } from "./block-policy.js";
33
35
  import type {
36
+ RepairDeadlineBound,
34
37
  RepairFetchHost,
35
38
  RepairPriorityReason,
39
+ RepairSendMeasurement,
36
40
  RepairSkipReason,
37
41
  RepairSubscribeCallback,
38
42
  } from "./repair-fetch.js";
39
43
  import {
40
44
  MmtpRouter,
41
45
  type FrameCallback,
42
- type ManifestIdentityResolver,
43
46
  type MmtpIngressContext,
44
47
  type MmtpStreamIdentity,
45
48
  type StagedStreamSwitch,
46
49
  type StreamSwitchCommit,
47
50
  type TrackPacketCallback,
48
51
  } from "./mmtp-router.js";
49
- import { isMulticastTrackPacketId } from "@blockcast/mmt-transport";
52
+ import { isMulticastTrackPacketId, type WindowMulticastGateway } from "@blockcast/mmt-transport";
50
53
  import {
51
54
  MulticastTransport,
52
55
  type MulticastFailbackReason,
53
56
  type MulticastJoinOutcome,
54
57
  type MulticastJoinStats,
58
+ type MulticastTransportConfig,
55
59
  } from "./multicast-transport.js";
56
60
  import { computeFecDeliveryWindowMs } from "./track-session.js";
61
+ import { BcProvenanceV2Receiver, type BcpV2ReceiverConfig } from "@blockcast/mmt-manifest-verify";
62
+ import type { ResolvedMulticastAuthConfig, ResolvedMulticastAuthFlow } from "./multicast-auth-catalog.js";
57
63
  import { DEFAULT_AMT_RELAY_PORT } from "./catalog-network-source.js";
58
64
  import { deriveFecInterleaveDepth, FecBlockMapper } from "@blockcast/mmt-fec";
59
65
  import type {
@@ -64,10 +70,6 @@ import type {
64
70
  } from "@blockcast/fec-worker";
65
71
  import type { MfuReassemblerBackend } from "./mfu-reassembler.js";
66
72
  import type { MfuReassemblyPolicy } from "./mfu-reassembly-policy.js";
67
- import type {
68
- ManifestObjectIdentity,
69
- ManifestVerifier,
70
- } from "@blockcast/mmt-manifest-verify";
71
73
  import type {
72
74
  BlockAssemblerConfig,
73
75
  CmafBlockSample,
@@ -83,8 +85,63 @@ import {
83
85
  } from "./carp-catalog.js";
84
86
  import { catalogFecUnavailable, type TrackFecUnavailable } from "./catalog-fec-params.js";
85
87
 
88
+ /**
89
+ * One dedicated repair group to join beside the media join: the shape
90
+ * `selectRepairEndpointsForTracks` (`@blockcast/mmt-transport`) returns.
91
+ */
92
+ export interface MulticastRepairEndpoint {
93
+ group: string;
94
+ source: string;
95
+ port: number;
96
+ mode?: string;
97
+ amtRelay?: string;
98
+ amtRelayPort?: number;
99
+ /** The repair packet IDs this group carries. */
100
+ packetIds: number[];
101
+ /** Each repair packet ID bound to the media packet ID it repairs. */
102
+ repairOwners: ReadonlyArray<{ packetId: number; ownerPacketId: number }>;
103
+ /** Ingress tracks: the owners' source tracks and the repair tracks. */
104
+ tracks: MmtpIngressContext["tracks"];
105
+ /** The protected flow (`MmtpRouter.registerProvenanceFlow`) this group's datagrams belong to. */
106
+ flow?: string;
107
+ }
108
+
109
+ /**
110
+ * Opens one repair-group subscription through the caller's own provider (a
111
+ * hang bridge, for one): delivers each packet to `onPacket` and returns (or
112
+ * resolves to) the call that releases it.
113
+ */
114
+ export type MulticastRepairSubscribe = (
115
+ endpoint: MulticastRepairEndpoint,
116
+ onPacket: (packet: Uint8Array) => void,
117
+ ) => (() => void) | Promise<() => void>;
118
+
119
+ /**
120
+ * A protected endpoint's join (draft -01 7.2.7): the keys and flow
121
+ * `resolveMulticastAuthCatalog` resolved for it. The join registers the flow
122
+ * with the router and subscribes `manifestPort` on the same `(S, G)` beside
123
+ * the media, so every media datagram is admitted by a record before it is read.
124
+ */
125
+ export interface MulticastProvenanceJoin {
126
+ auth: Pick<ResolvedMulticastAuthConfig, "keys" | "minEpoch">;
127
+ flow: ResolvedMulticastAuthFlow;
128
+ /** Receiver options beyond the catalog's (ctx, clock, freshness, W, lead). */
129
+ receiver?: Omit<Partial<BcpV2ReceiverConfig>, "endpoint" | "keys" | "minEpoch" | "bandwidth" | "maxAuthDelayMs" | "manifestTimerMs">;
130
+ }
131
+
86
132
  export interface MulticastEndpointConfig {
87
- sourceAddress: string;
133
+ /** SSM source; omitted on ASM. */
134
+ sourceAddress?: string;
135
+ /** ASM sender filter: `auth.senderAddress` of a protected ASM endpoint. Never beside `sourceAddress`. */
136
+ senderAddress?: string;
137
+ /**
138
+ * Present on a protected endpoint: the join admits through bc-provenance v2.
139
+ * From its first admission (`onProtected`) MoQ copies of the listed tracks
140
+ * are dropped until the media transport fails back (silence or a
141
+ * subscription error); the manager un-protects then whether or not a player
142
+ * registered `onFailback`.
143
+ */
144
+ provenance?: MulticastProvenanceJoin;
88
145
  groupAddress: string;
89
146
  port: number;
90
147
  /** Explicit gateway transport policy. Omitted means gateway-selected auto mode. */
@@ -95,6 +152,12 @@ export interface MulticastEndpointConfig {
95
152
  amtRelay?: string;
96
153
  /** AMT relay port from player/UI overrides. Wins over `relayPort`. */
97
154
  amtRelayPort?: number;
155
+ /**
156
+ * `'driad'`: no relay is pinned; the window.multicast gateway runs RFC 8777
157
+ * DRIAD on `sourceAddress` and fails over across the relays it offers.
158
+ * Ignored when `amtRelay` is set.
159
+ */
160
+ amtDiscovery?: 'driad';
98
161
  /** MMTP packet IDs to forward before data enters the page transport queue. */
99
162
  packetIds?: number[];
100
163
  /** Exact catalog tracks carried by this physical multicast endpoint. */
@@ -151,15 +214,6 @@ export interface MulticastManagerOptions {
151
214
  reassemblyPolicy?: MfuReassemblyPolicy;
152
215
  reassembler?: MfuReassemblerBackend;
153
216
  maxBufferedMfus?: number;
154
- manifestVerifier?: ManifestVerifier;
155
- manifestVerifierOwnership?: "caller" | "router";
156
- resolveManifestIdentity?: (
157
- packetId: number,
158
- sbn: number,
159
- esi: number,
160
- catalogTrackName?: string,
161
- ) => ManifestObjectIdentity | null;
162
- resolveManifestIdentityForRoute?: ManifestIdentityResolver;
163
217
  /**
164
218
  * Also write every repair lifecycle event to the console as one
165
219
  * `REPAIR_LIFECYCLE_LOG_PREFIX` JSON line. Off unless asked for: the lines
@@ -257,11 +311,13 @@ interface ActiveRenditionSwitch {
257
311
  state: RenditionSwitchState;
258
312
  }
259
313
 
260
- function freezeIngress(tracks: Iterable<Readonly<{ name: string; packetId: number }>>): MmtpIngressContext {
314
+ /** `flow` is the live join's protected flow: every ingress a switch installs keeps it, or the router reads media unauthenticated. */
315
+ function freezeIngress(tracks: Iterable<Readonly<{ name: string; packetId: number }>>, flow: string | undefined): MmtpIngressContext {
261
316
  return Object.freeze({
262
317
  tracks: Object.freeze(
263
318
  [...tracks].map(({ name, packetId }) => Object.freeze({ name, packetId })),
264
319
  ),
320
+ ...(flow === undefined ? {} : { flow }),
265
321
  });
266
322
  }
267
323
 
@@ -297,6 +353,9 @@ interface RepairSymbolCounts {
297
353
  * class.
298
354
  * - `recovered` / `failed`: every block that could not complete from its
299
355
  * first-arrival source symbols resolves with exactly one of these.
356
+ * - `repair-sent`: the scheduler admitted and sent a repair FETCH; carries
357
+ * the admission inputs (RTT, time left to the deadline, which term set
358
+ * the deadline) so a harness reads the budget instead of inferring it.
300
359
  * - `repair-preempted` / `repair-deferred`: the scheduler aborted a delta
301
360
  * repair for keyframe work, or never ran it before its block resolved.
302
361
  * - `repair-priority`: the catalog could not supply the SUBSCRIBER_PRIORITY a
@@ -344,6 +403,23 @@ export type RepairLifecycleEvent =
344
403
  readonly type: "repair-preempted" | "repair-deferred";
345
404
  readonly block: RepairBlockIdentity;
346
405
  }
406
+ | {
407
+ readonly version: 2;
408
+ /**
409
+ * The scheduler sent a FETCH (BLO-33597): every attempt, a retry or a
410
+ * reprioritised restart included. `budgetMs` is the time left to the
411
+ * deadline at send, `bound` which term set that deadline; `delayMs` and
412
+ * `blockAgeMs` are null for a block with no anchor.
413
+ */
414
+ readonly type: "repair-sent";
415
+ readonly block: RepairBlockIdentity;
416
+ readonly priority: RepairPriority;
417
+ readonly rttMs: number;
418
+ readonly budgetMs: number;
419
+ readonly delayMs: number | null;
420
+ readonly blockAgeMs: number | null;
421
+ readonly bound: RepairDeadlineBound;
422
+ }
347
423
  | {
348
424
  readonly version: 2;
349
425
  /**
@@ -424,6 +500,16 @@ export interface BlockPolicyStats {
424
500
  repairsSkippedRttExceedsBudget: number;
425
501
  /** `repairsSkipped` by reason: the player gave no presentation delay. */
426
502
  repairsSkippedPresentationDelayUnavailable: number;
503
+ /**
504
+ * `repairsSkipped` by reason: a lost SS_ID in an undelimited span had no
505
+ * §7.5 anchor (no epoch reference, or none it could be extended from).
506
+ */
507
+ repairsSkippedRangeNoAnchor: number;
508
+ /**
509
+ * `repairsSkipped` by reason: the block's repair group could not complete
510
+ * it (sources + RSB_length < K'), so no FETCH was sent.
511
+ */
512
+ repairsSkippedGroupCannotComplete: number;
427
513
  /**
428
514
  * The most recent skip: its reason, the measured RTT (null when
429
515
  * unmeasured), the time that was left to the deadline, and the request's
@@ -438,6 +524,8 @@ export interface BlockPolicyStats {
438
524
  } | null;
439
525
  /** Repair FETCHes sent for keyframe/unknown (P0) blocks, every attempt counted. */
440
526
  keyframeRepairFetchesSent: number;
527
+ /** Range repair FETCHes (draft-ramadan-moq-fec §7.5 lost SS_ID) sent, every attempt counted. */
528
+ rangeRepairFetchesSent: number;
441
529
  /**
442
530
  * Requests the keyframe late-repair budget extended past the presentation
443
531
  * deadline (each one can hold the stream behind its block that long).
@@ -482,8 +570,11 @@ function newBlockPolicyStats(
482
570
  repairsSkippedRttUnmeasured: 0,
483
571
  repairsSkippedRttExceedsBudget: 0,
484
572
  repairsSkippedPresentationDelayUnavailable: 0,
573
+ repairsSkippedRangeNoAnchor: 0,
574
+ repairsSkippedGroupCannotComplete: 0,
485
575
  lastRepairSkip: null,
486
576
  keyframeRepairFetchesSent: 0,
577
+ rangeRepairFetchesSent: 0,
487
578
  keyframeBudgetHolds: 0,
488
579
  keyframeBudgetHoldMs: 0,
489
580
  deltaBlocksFailed: 0,
@@ -629,6 +720,14 @@ const REPAIR_PRIORITY_REASONS: ReadonlySet<unknown> = new Set([
629
720
  "repair-priority-absent",
630
721
  "repair-priority-invalid",
631
722
  ]);
723
+ const REPAIR_SKIP_REASONS: ReadonlySet<unknown> = new Set([
724
+ "rtt-unmeasured",
725
+ "rtt-exceeds-budget",
726
+ "presentation-delay-unavailable",
727
+ "range-no-anchor",
728
+ "group-cannot-complete",
729
+ ]);
730
+ const REPAIR_DEADLINE_BOUNDS: ReadonlySet<unknown> = new Set(["wait", "presentation", "keyframe", "retention"]);
632
731
  const GAP_REASONS: Readonly<Record<string, "stall" | "conceal">> = {
633
732
  "rap-lost": "stall",
634
733
  "rap-unknown": "stall",
@@ -661,6 +760,10 @@ function isNullableNonNegative(value: unknown): boolean {
661
760
  return value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
662
761
  }
663
762
 
763
+ function isFiniteNumber(value: unknown): boolean {
764
+ return typeof value === "number" && Number.isFinite(value);
765
+ }
766
+
664
767
  /** Runtime guard for observer, DOM-event, and cross-realm consumers. */
665
768
  export function isRepairLifecycleEvent(
666
769
  value: unknown,
@@ -703,6 +806,40 @@ export function isRepairLifecycleEvent(
703
806
  case "repair-preempted":
704
807
  case "repair-deferred":
705
808
  return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
809
+ case "repair-sent":
810
+ // Admission sends only when 0 < rttMs < budgetMs.
811
+ return (
812
+ hasExactKeys(value, [
813
+ "version",
814
+ "type",
815
+ "block",
816
+ "priority",
817
+ "rttMs",
818
+ "budgetMs",
819
+ "delayMs",
820
+ "blockAgeMs",
821
+ "bound",
822
+ ]) &&
823
+ isRepairBlockIdentity(block) &&
824
+ (value["priority"] === 0 || value["priority"] === 1 || value["priority"] === 2) &&
825
+ isFiniteNumber(value["rttMs"]) &&
826
+ (value["rttMs"] as number) > 0 &&
827
+ isFiniteNumber(value["budgetMs"]) &&
828
+ (value["budgetMs"] as number) > (value["rttMs"] as number) &&
829
+ isNullableNonNegative(value["delayMs"]) &&
830
+ isNullableNonNegative(value["blockAgeMs"]) &&
831
+ (value["delayMs"] === null) === (value["blockAgeMs"] === null) &&
832
+ REPAIR_DEADLINE_BOUNDS.has(value["bound"])
833
+ );
834
+ case "repair-skipped":
835
+ // budgetMs may be negative: the deadline can already have passed.
836
+ return (
837
+ hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) &&
838
+ isRepairBlockIdentity(block) &&
839
+ REPAIR_SKIP_REASONS.has(value["reason"]) &&
840
+ isNullableNonNegative(value["rttMs"]) &&
841
+ isFiniteNumber(value["budgetMs"])
842
+ );
706
843
  case "repair-priority": {
707
844
  const blockClass = value["blockClass"];
708
845
  const action = value["action"];
@@ -1099,6 +1236,13 @@ export class MulticastManager {
1099
1236
  readonly #router: MmtpRouter;
1100
1237
  #hostMfuTimeoutMs: number | null;
1101
1238
  readonly #transport: MulticastTransport<MmtpIngressContext>;
1239
+ /** The protected flow of the current join and its manifestPort subscription. */
1240
+ #provenanceJoin: { flow: string; manifest: MulticastTransport } | null = null;
1241
+ #onFailback: ((reason: MulticastFailbackReason) => void) | null = null;
1242
+ #failbackHooked = false;
1243
+ /** Live joinRepairEndpoints() releases → the repair owners they registered,
1244
+ * re-applied after configureMultiTrack() clears catalog-derived owners. */
1245
+ readonly #repairReleases = new Map<() => void, MulticastRepairEndpoint["repairOwners"]>();
1102
1246
  #reportedFecDiagnosticsFailure = false;
1103
1247
 
1104
1248
  // ── Stream-global FEC timing reduction ──
@@ -1161,10 +1305,6 @@ export class MulticastManager {
1161
1305
  reassemblyPolicy: options?.reassemblyPolicy,
1162
1306
  reassembler: options?.reassembler,
1163
1307
  maxBufferedMfus: options?.maxBufferedMfus,
1164
- manifestVerifier: options?.manifestVerifier,
1165
- manifestVerifierOwnership: options?.manifestVerifierOwnership,
1166
- resolveManifestIdentity: options?.resolveManifestIdentity,
1167
- resolveManifestIdentityForRoute: options?.resolveManifestIdentityForRoute,
1168
1308
  // The router has reset its own state for the stream; reset the rest.
1169
1309
  onPublisherRestart: (packetId, catalogTrackName) => {
1170
1310
  this.#resetStreamOutsideRouter(packetId, catalogTrackName);
@@ -1211,7 +1351,7 @@ export class MulticastManager {
1211
1351
  });
1212
1352
  this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
1213
1353
  this.#transport = new MulticastTransport<MmtpIngressContext>((packet, ingress) => {
1214
- this.#router.feedPacket(packet, "multicast", undefined, ingress);
1354
+ this.#router.feedPacket(packet, "multicast", ingress);
1215
1355
  });
1216
1356
  // Each joined subscription declares how it delivers packets. An ordered
1217
1357
  // relay decides FEC block fate by stream order instead of the datagram
@@ -1323,6 +1463,11 @@ export class MulticastManager {
1323
1463
  get router(): MmtpRouter {
1324
1464
  return this.#router;
1325
1465
  }
1466
+ /** Repair FETCH wiring (wireRepairFetch): this manager can request unicast repair. */
1467
+ setUnicastRepair(enabled: boolean): void {
1468
+ this.#router.setUnicastRepair(enabled);
1469
+ }
1470
+
1326
1471
  get transport(): MulticastTransport<MmtpIngressContext> {
1327
1472
  return this.#transport;
1328
1473
  }
@@ -1416,7 +1561,12 @@ export class MulticastManager {
1416
1561
  catalogTrackName,
1417
1562
  );
1418
1563
  this.#configureTrackMapper(packetId, config);
1419
- this.#router.setPacketIdType(packetId, trackType);
1564
+ // A Worker for an already registered track swaps the decoder mid-stream.
1565
+ // Re-registering the track would reset the parser's MPU timing and drop
1566
+ // the rest of the GOP in flight.
1567
+ if (this.#router.trackKindFor(packetId) !== trackType) {
1568
+ this.#router.setPacketIdType(packetId, trackType);
1569
+ }
1420
1570
  }
1421
1571
 
1422
1572
  /**
@@ -1510,6 +1660,18 @@ export class MulticastManager {
1510
1660
  }
1511
1661
  }
1512
1662
 
1663
+ // A data unit must outlive every FEC block that can still complete it: the
1664
+ // release gate waits for them up to terminal retention, and a fragment
1665
+ // recovered after its data unit was evicted is lost.
1666
+ for (const [packetId, c] of this.#trackFecTiming) {
1667
+ if (c.deliveryWindowMs === undefined) continue;
1668
+ mfuTimeoutMs = Math.max(
1669
+ mfuTimeoutMs ?? 0,
1670
+ this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
1671
+ this.#hostMfuTimeoutMs ?? 0,
1672
+ );
1673
+ }
1674
+
1513
1675
  const failbackWindowMs =
1514
1676
  deliveryWindowMs === undefined
1515
1677
  ? minimumFailbackWindowMs
@@ -1810,6 +1972,8 @@ export class MulticastManager {
1810
1972
  setMfuTimeoutMs(ms: number): void {
1811
1973
  this.#router.setMfuTimeoutMs(ms);
1812
1974
  this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
1975
+ // A FEC track's data units must still outlive its terminal retention.
1976
+ if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
1813
1977
  }
1814
1978
 
1815
1979
  setTrackCodec(packetId: number, codec: string) {
@@ -1894,8 +2058,36 @@ export class MulticastManager {
1894
2058
  onTakeover(cb: () => void) {
1895
2059
  this.#transport.onTakeover(cb);
1896
2060
  }
2061
+ /** Failback un-protects the join's flow (7.2.7 failover), so the fallback's MoQ packets are read. */
1897
2062
  onFailback(cb: (reason: MulticastFailbackReason) => void) {
1898
- this.#transport.onFailback(cb);
2063
+ this.#onFailback = cb;
2064
+ this.#hookFailback();
2065
+ }
2066
+
2067
+ /**
2068
+ * Install the manager's own failback listener on the media transport, which
2069
+ * arms its silence watchdog: a protected join un-protects on failover even
2070
+ * when no player listens, else its tracks' MoQ copies stay dropped.
2071
+ */
2072
+ #hookFailback(): void {
2073
+ if (this.#failbackHooked) return;
2074
+ this.#failbackHooked = true;
2075
+ this.#transport.onFailback((reason) => {
2076
+ const joined = this.#provenanceJoin;
2077
+ if (joined !== null) this.#router.unprotectProvenanceFlow(joined.flow);
2078
+ this.#onFailback?.(reason);
2079
+ });
2080
+ }
2081
+ /**
2082
+ * A protected join's handoff (draft -01 7.2.7), before `onTakeover`: its
2083
+ * first admitted datagram. MoQ copies of the flow's tracks the router still
2084
+ * held unadmitted are discarded, and later ones are dropped. Fires again
2085
+ * after a failback once multicast resumes.
2086
+ */
2087
+ onProtected(cb: (() => void) | null) {
2088
+ this.#router.onProvenanceFlowProtected(cb && ((flow) => {
2089
+ if (this.#provenanceJoin?.flow === flow) cb();
2090
+ }));
1899
2091
  }
1900
2092
  /** See MulticastTransport.onDataPlaneLive: the join's first accepted packet. */
1901
2093
  onDataPlaneLive(cb: () => void) {
@@ -1913,6 +2105,17 @@ export class MulticastManager {
1913
2105
  }
1914
2106
 
1915
2107
  async join(config: MulticastEndpointConfig): Promise<boolean> {
2108
+ const provenanceFlow = config.provenance?.flow;
2109
+ if (
2110
+ provenanceFlow !== undefined &&
2111
+ ((config.sourceAddress ?? config.senderAddress) !== provenanceFlow.source ||
2112
+ config.groupAddress !== provenanceFlow.groupAddress ||
2113
+ config.port !== provenanceFlow.port)
2114
+ ) {
2115
+ throw new RangeError(
2116
+ "[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port",
2117
+ );
2118
+ }
1916
2119
  // A join replaces the admission a staged switch was built on. The new
1917
2120
  // join's config decides what is admitted, so nothing is restored or
1918
2121
  // retired here: the switch just ends.
@@ -1937,22 +2140,27 @@ export class MulticastManager {
1937
2140
  : selectedPacketIds === null
1938
2141
  ? undefined
1939
2142
  : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
1940
- const ingress = ingressTracks === undefined
2143
+ this.#releaseProvenanceJoin();
2144
+ const provenance = config.provenance;
2145
+ const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
2146
+ const ingress: MmtpIngressContext | undefined = protectedTracks === undefined
1941
2147
  ? undefined
1942
2148
  : {
1943
2149
  tracks: Object.freeze(
1944
- ingressTracks.map(({ name, packetId }) =>
2150
+ protectedTracks.map(({ name, packetId }) =>
1945
2151
  Object.freeze({ name, packetId }),
1946
2152
  ),
1947
2153
  ),
2154
+ ...(provenance === undefined ? {} : { flow: multicastProvenanceFlowKey(provenance.flow) }),
1948
2155
  };
1949
2156
  // The single relay inlet: the player/UI override, or the catalog's
1950
2157
  // `multicast.networkSource[{type:"amt"}]` relay, which
1951
2158
  // `endpointToMulticastConfig` (packages/transport
1952
2159
  // multicast-catalog-policy.ts) resolves into `amtRelay` via `findAmtRelay`.
1953
2160
  const amtRelay = config.amtRelay;
1954
- const transportConfig = {
2161
+ const transportConfig: MulticastTransportConfig = {
1955
2162
  sourceAddress: config.sourceAddress,
2163
+ senderAddress: config.senderAddress,
1956
2164
  groupAddress: config.groupAddress,
1957
2165
  port: config.port,
1958
2166
  mode: config.mode,
@@ -1978,12 +2186,150 @@ export class MulticastManager {
1978
2186
  config.amtRelayPort ??
1979
2187
  config.relayPort ??
1980
2188
  (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : undefined),
2189
+ amtDiscovery: config.amtDiscovery,
1981
2190
  packetIds: config.packetIds,
1982
2191
  tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId })),
1983
2192
  };
1984
- return ingress === undefined
2193
+ if (provenance !== undefined) this.#joinProvenance(provenance, ingress as MmtpIngressContext & { flow: string }, transportConfig);
2194
+ const protectedJoin = this.#provenanceJoin;
2195
+ const joined = await (ingress === undefined
1985
2196
  ? this.#transport.join(transportConfig)
1986
- : this.#transport.join(transportConfig, ingress);
2197
+ : this.#transport.join(transportConfig, ingress));
2198
+ // No media: leave the manifest subscription and release the flow now, not at the next join.
2199
+ if (!joined && protectedJoin !== null && this.#provenanceJoin === protectedJoin) this.#releaseProvenanceJoin();
2200
+ return joined;
2201
+ }
2202
+
2203
+ /**
2204
+ * Register the protected flow and subscribe its `manifestPort` on the same
2205
+ * `(S, G)` with its own listener (draft -01 7.2.7), so records reach the
2206
+ * flow's receiver and media datagrams are held until one admits them. A
2207
+ * manifest subscription that fails to join admits nothing: the media is
2208
+ * held and expires, never read unauthenticated.
2209
+ */
2210
+ #joinProvenance(
2211
+ provenance: MulticastProvenanceJoin,
2212
+ ingress: MmtpIngressContext & { flow: string },
2213
+ media: MulticastTransportConfig,
2214
+ ): void {
2215
+ const { flow, auth } = provenance;
2216
+ const receiver = new BcProvenanceV2Receiver({
2217
+ // The catalog's ctx unless the caller passes its own (or none).
2218
+ ...(flow.ctx === undefined ? {} : { catalogCtx: flow.ctx }),
2219
+ ...provenance.receiver,
2220
+ endpoint: {
2221
+ sourceAddress: flow.source,
2222
+ groupAddress: flow.groupAddress,
2223
+ port: flow.port,
2224
+ manifestPort: flow.manifestPort,
2225
+ streamId: flow.streamId,
2226
+ },
2227
+ keys: auth.keys,
2228
+ minEpoch: auth.minEpoch,
2229
+ bandwidth: flow.bandwidth,
2230
+ maxAuthDelayMs: flow.maxAuthDelayMs,
2231
+ manifestTimerMs: flow.manifestTimerMs,
2232
+ });
2233
+ this.#router.registerProvenanceFlow(ingress, receiver);
2234
+ this.#hookFailback();
2235
+ const manifest = new MulticastTransport((record) => {
2236
+ if (this.#provenanceJoin?.manifest === manifest) {
2237
+ this.#router.feedProvenanceRecord(ingress.flow, record, "multicast");
2238
+ }
2239
+ });
2240
+ this.#provenanceJoin = { flow: ingress.flow, manifest };
2241
+ const { packetIds: _packetIds, tracks: _tracks, ...path } = media;
2242
+ void manifest.join({ ...path, port: flow.manifestPort }).then((joined) => {
2243
+ if (!joined && this.#provenanceJoin?.manifest === manifest) {
2244
+ console.warn(`[MulticastManager] manifestPort ${flow.groupAddress}:${flow.manifestPort} not joined`, manifest.lastJoinOutcome);
2245
+ }
2246
+ });
2247
+ }
2248
+
2249
+ /** Un-protect: drop the flow's hold queues (no expiry counted) and leave its manifestPort. */
2250
+ #releaseProvenanceJoin(): void {
2251
+ const joined = this.#provenanceJoin;
2252
+ if (joined === null) return;
2253
+ this.#provenanceJoin = null;
2254
+ joined.manifest.dispose();
2255
+ this.#router.releaseProvenanceFlow(joined.flow);
2256
+ }
2257
+
2258
+ /**
2259
+ * Join the selected rung's dedicated repair groups beside the media join
2260
+ * (pim #3898): one subscription per endpoint, through `provider` when given
2261
+ * (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
2262
+ * new MulticastTransport on `window.multicast`. Returns the call that
2263
+ * releases every one of them; dispose() releases them too.
2264
+ *
2265
+ * Packets go straight to the router with the endpoint's ingress, never
2266
+ * through feedPacket(): repair arriving on its own group is not media
2267
+ * liveness, so it must not hold off the media leg's failback watchdog. The
2268
+ * repair roles and owners are registered here; in-band owners stay the
2269
+ * caller's. Joining is best effort: a group that fails to join is logged
2270
+ * and leaves the media join as it was.
2271
+ */
2272
+ joinRepairEndpoints(
2273
+ endpoints: readonly MulticastRepairEndpoint[],
2274
+ provider?: WindowMulticastGateway | MulticastRepairSubscribe,
2275
+ ): () => void {
2276
+ const releases: Array<() => void> = [];
2277
+ let released = false;
2278
+ const safely = (each: () => void) => {
2279
+ try {
2280
+ each();
2281
+ } catch (error) {
2282
+ console.warn("[MulticastManager] repair group release failed", error);
2283
+ }
2284
+ };
2285
+ const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
2286
+ this.#applyRepairOwners(repairOwners);
2287
+ for (const endpoint of endpoints) {
2288
+ const ingress: MmtpIngressContext = {
2289
+ tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
2290
+ ...(endpoint.flow === undefined ? {} : { flow: endpoint.flow }),
2291
+ };
2292
+ const onPacket = (packet: Uint8Array) => {
2293
+ if (!released) this.#router.feedPacket(packet, "multicast", ingress);
2294
+ };
2295
+ const fail = (error: unknown) =>
2296
+ console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
2297
+ if (typeof provider === "function") {
2298
+ Promise.resolve()
2299
+ .then(() => provider(endpoint, onPacket))
2300
+ .then((release) => (released ? safely(release) : releases.push(release)), fail);
2301
+ continue;
2302
+ }
2303
+ const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
2304
+ releases.push(() => transport.dispose());
2305
+ void transport.join({
2306
+ sourceAddress: endpoint.source,
2307
+ groupAddress: endpoint.group,
2308
+ port: endpoint.port,
2309
+ mode: endpoint.mode as MulticastEndpointConfig["mode"],
2310
+ amtRelay: endpoint.amtRelay,
2311
+ amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : undefined),
2312
+ packetIds: endpoint.packetIds,
2313
+ tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
2314
+ }).then((joined) => {
2315
+ if (!joined && !released) fail(transport.lastJoinOutcome);
2316
+ });
2317
+ }
2318
+ const release = () => {
2319
+ if (released) return;
2320
+ released = true;
2321
+ this.#repairReleases.delete(release);
2322
+ for (const each of releases.splice(0)) safely(each);
2323
+ };
2324
+ this.#repairReleases.set(release, repairOwners);
2325
+ return release;
2326
+ }
2327
+
2328
+ #applyRepairOwners(owners: MulticastRepairEndpoint["repairOwners"]): void {
2329
+ for (const { packetId, ownerPacketId } of owners) {
2330
+ this.#router.setPacketIdRole(packetId, "repair");
2331
+ this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
2332
+ }
1987
2333
  }
1988
2334
 
1989
2335
  // ---------------------------------------------------------------------------
@@ -2112,7 +2458,7 @@ export class MulticastManager {
2112
2458
  for (const track of [...live.tracks, ...request.tracks]) {
2113
2459
  stagedTracks.set(`${track.packetId}\0${track.name}`, track);
2114
2460
  }
2115
- const stagedIngress = freezeIngress(stagedTracks.values());
2461
+ const stagedIngress = freezeIngress(stagedTracks.values(), live.flow);
2116
2462
  const stagedPacketIds =
2117
2463
  committedPacketIds === undefined || livePacketIds === null
2118
2464
  ? null
@@ -2127,7 +2473,7 @@ export class MulticastManager {
2127
2473
  liveIngress: live,
2128
2474
  livePacketIds,
2129
2475
  widened,
2130
- committedIngress: freezeIngress(request.tracks),
2476
+ committedIngress: freezeIngress(request.tracks, live.flow),
2131
2477
  committedPacketIds,
2132
2478
  router: null,
2133
2479
  state: "staged",
@@ -2141,7 +2487,7 @@ export class MulticastManager {
2141
2487
  let widening: Promise<void> | undefined;
2142
2488
  try {
2143
2489
  if (widened) widening = this.#transport.setPacketIds([...stagedPacketIds!]);
2144
- this.#transport.setContext(stagedIngress);
2490
+ this.#setSwitchIngress(stagedIngress);
2145
2491
  } catch (error) {
2146
2492
  active.router.cancel();
2147
2493
  throw error;
@@ -2163,6 +2509,12 @@ export class MulticastManager {
2163
2509
  };
2164
2510
  }
2165
2511
 
2512
+ /** Route a switch's ingress and keep a protected flow's registration in step (7.2.7). */
2513
+ #setSwitchIngress(ingress: MmtpIngressContext): void {
2514
+ this.#transport.setContext(ingress);
2515
+ if (ingress.flow !== undefined) this.#router.updateProvenanceFlowIngress({ ...ingress, flow: ingress.flow });
2516
+ }
2517
+
2166
2518
  /** The router committed the staged switch (it already retired `from`). */
2167
2519
  #commitRenditionSwitch(active: ActiveRenditionSwitch, commit: StreamSwitchCommit): void {
2168
2520
  if (this.#renditionSwitch !== active) return;
@@ -2170,7 +2522,7 @@ export class MulticastManager {
2170
2522
  active.state = "committed";
2171
2523
  active.router = null;
2172
2524
  if (this.#transport.joined) {
2173
- this.#transport.setContext(active.committedIngress);
2525
+ this.#setSwitchIngress(active.committedIngress);
2174
2526
  if (active.committedPacketIds !== undefined) {
2175
2527
  // The page-side filter narrows now; the provider may keep delivering
2176
2528
  // the retired IDs until it applies the narrower list, and the page
@@ -2218,7 +2570,7 @@ export class MulticastManager {
2218
2570
  active.router = null;
2219
2571
  if (restore) {
2220
2572
  if (this.#transport.joined) {
2221
- this.#transport.setContext(active.liveIngress);
2573
+ this.#setSwitchIngress(active.liveIngress);
2222
2574
  if (active.widened && active.livePacketIds !== null) {
2223
2575
  this.#transport.setPacketIds([...active.livePacketIds]).catch((error: unknown) => {
2224
2576
  console.warn(
@@ -2331,7 +2683,7 @@ export class MulticastManager {
2331
2683
  *
2332
2684
  * D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
2333
2685
  * D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
2334
- * D-17: Builds altGroup → track-name index for getSwitchingSet().
2686
+ * D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
2335
2687
  * D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
2336
2688
  *
2337
2689
  * FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
@@ -2411,11 +2763,9 @@ export class MulticastManager {
2411
2763
  }
2412
2764
  }
2413
2765
  const repairOwnerGroup = new Map<string, string>();
2414
- const repairOwnerAltGroup = new Map<string, number | undefined>();
2415
2766
  for (const track of catalog.tracks) {
2416
2767
  for (const repairName of repairNamesBySource.get(track.name) ?? []) {
2417
2768
  repairOwnerGroup.set(repairName, altGroupKey(track));
2418
- repairOwnerAltGroup.set(repairName, track.altGroup);
2419
2769
  }
2420
2770
  }
2421
2771
  const groupKeyFor = (track: MultiTrackCatalogTrack): string =>
@@ -2458,11 +2808,9 @@ export class MulticastManager {
2458
2808
  if (!(hasSwitchingSetByGroup.get(groupKey) ?? false)) continue;
2459
2809
 
2460
2810
  const presentRoles = new Set(roles.filter((r) => r !== "single"));
2461
- const required: Array<"base" | "delta" | "repair"> = [
2462
- "base",
2463
- "delta",
2464
- "repair",
2465
- ];
2811
+ // Delta is optional (BLO-49199): base is the self-decodable leg and a
2812
+ // base-only group plays in base-only mode; delta without base cannot.
2813
+ const required: Array<"base" | "repair"> = ["base", "repair"];
2466
2814
  const missing = required.filter((r) => !presentRoles.has(r));
2467
2815
  if (missing.length > 0) {
2468
2816
  throw new Error(
@@ -2517,6 +2865,9 @@ export class MulticastManager {
2517
2865
  this.#switchingSets.clear();
2518
2866
  this.#repairPacketIds.clear();
2519
2867
  this.#router.clearRepairPacketIdOwners();
2868
+ // Dedicated repair groups joined beside the media join outlive a catalog
2869
+ // refresh; their owners are not this catalog's to drop.
2870
+ for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
2520
2871
  // FEC a previous call configured that this one does not (the source is
2521
2872
  // gone, lost its `fec`, or its FEC is now unavailable) must not stay
2522
2873
  // installed: its symbols would still be read as block coordinates and
@@ -2547,15 +2898,13 @@ export class MulticastManager {
2547
2898
  const track = catalog.tracks[i]!;
2548
2899
  const role = resolvedRoles[i]!;
2549
2900
 
2550
- // D-17: Build altGroup → track-name index. A repair leg belongs to the
2551
- // switching set of the owner that points at it.
2552
- const altGroup = repairOwnerAltGroup.has(track.name)
2553
- ? repairOwnerAltGroup.get(track.name)
2554
- : track.altGroup;
2555
- if (altGroup !== undefined) {
2556
- const existing = this.#switchingSets.get(altGroup) ?? [];
2901
+ // D-17: Build altGroup → track-name index. Members are the tracks that
2902
+ // carry equal altGroup; a repair leg is in no switching set, whatever it
2903
+ // declares (draft-ramadan-moq-mmt-01 Switching Sets).
2904
+ if (role !== "repair" && track.altGroup !== undefined) {
2905
+ const existing = this.#switchingSets.get(track.altGroup) ?? [];
2557
2906
  existing.push(track.name);
2558
- this.#switchingSets.set(altGroup, existing);
2907
+ this.#switchingSets.set(track.altGroup, existing);
2559
2908
  }
2560
2909
 
2561
2910
  // D-26: Register packetId → role on MmtpRouter (if packetId provided at ingest time).
@@ -2649,7 +2998,7 @@ export class MulticastManager {
2649
2998
 
2650
2999
  /**
2651
3000
  * Return the track names belonging to the given altGroup switching set.
2652
- * D-17: altGroup groups base+delta+repair into one switching set.
3001
+ * D-17: tracks with equal altGroup form one switching set; repair legs are in none.
2653
3002
  *
2654
3003
  * @param altGroup - The altGroup number to look up.
2655
3004
  * @returns Array of track names in that switching set (empty if none).
@@ -2679,6 +3028,29 @@ export class MulticastManager {
2679
3028
  };
2680
3029
  }
2681
3030
 
3031
+ /**
3032
+ * Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
3033
+ * on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
3034
+ * pending hole and reported here, and `closeIsoHoles` must be called for it
3035
+ * once its range FETCH ends (or none is sent).
3036
+ */
3037
+ onUndelimitedLoss(cb: (loss: UndelimitedIsoLoss) => void): void {
3038
+ this.#fec.setUndelimitedLossHandler(cb);
3039
+ }
3040
+
3041
+ /**
3042
+ * Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
3043
+ * to CmcdProducer.updateFecFailClosed.
3044
+ */
3045
+ onFecFailClosed(cb: (event: FecFailClosedEvent) => void): void {
3046
+ this.#fec.setFecFailClosedHandler(cb);
3047
+ }
3048
+
3049
+ /** End a pending hole's range repair: feed what no repair stated as spans. */
3050
+ closeIsoHoles(packetId: number, catalogTrackName: string | undefined, start: number, length: number): void {
3051
+ this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
3052
+ }
3053
+
2682
3054
  /**
2683
3055
  * Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
2684
3056
  * supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
@@ -2714,6 +3086,8 @@ export class MulticastManager {
2714
3086
  stats.repairsSkipped++;
2715
3087
  if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
2716
3088
  else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
3089
+ else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
3090
+ else if (reason === "group-cannot-complete") stats.repairsSkippedGroupCannotComplete++;
2717
3091
  else stats.repairsSkippedPresentationDelayUnavailable++;
2718
3092
  stats.lastRepairSkip = {
2719
3093
  reason,
@@ -2755,11 +3129,24 @@ export class MulticastManager {
2755
3129
  /** Record a repair FETCH the scheduler admitted and sent. */
2756
3130
  noteRepairFetchSent(
2757
3131
  priority: RepairPriority,
2758
- _sbn: number,
3132
+ sbn: number,
2759
3133
  packetId: number,
2760
- catalogTrackName?: string,
3134
+ catalogTrackName: string | undefined,
3135
+ measurement: RepairSendMeasurement,
2761
3136
  ): void {
2762
3137
  if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
3138
+ if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
3139
+ this.#emitRepairLifecycle({
3140
+ version: 2,
3141
+ type: "repair-sent",
3142
+ block: repairBlockIdentity(packetId, sbn, catalogTrackName),
3143
+ priority,
3144
+ rttMs: measurement.rttMs,
3145
+ budgetMs: measurement.budgetMs,
3146
+ delayMs: measurement.delayMs,
3147
+ blockAgeMs: measurement.blockAgeMs,
3148
+ bound: measurement.bound,
3149
+ });
2763
3150
  }
2764
3151
 
2765
3152
  /**
@@ -2951,6 +3338,8 @@ export class MulticastManager {
2951
3338
  this.#trackResetObservers.clear();
2952
3339
  this.#repairLifecycleObservers.clear();
2953
3340
  this.#transport.dispose();
3341
+ this.#releaseProvenanceJoin();
3342
+ for (const release of [...this.#repairReleases.keys()]) release();
2954
3343
  this.#router.dispose();
2955
3344
  this.#fec.dispose();
2956
3345
  }
@@ -2960,3 +3349,8 @@ export class MulticastManager {
2960
3349
  // (wireRepairFetch) drives.
2961
3350
  const repairFetchHost = (manager: MulticastManager): RepairFetchHost => manager;
2962
3351
  void repairFetchHost;
3352
+
3353
+ /** The router's key of a protected flow: its `(S, G, port)`. */
3354
+ export function multicastProvenanceFlowKey(flow: Pick<ResolvedMulticastAuthFlow, "source" | "groupAddress" | "port">): string {
3355
+ return JSON.stringify([flow.source, flow.groupAddress, flow.port]);
3356
+ }