@blockcast/mmt-container 0.4.0 → 0.4.1-main.47aa22331187

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 (210) hide show
  1. package/README.md +36 -20
  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 +1839 -692
  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 +8 -0
  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 +98 -234
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +121 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +421 -66
  33. package/dist/fec-manager.js.map +3 -3
  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/index.d.ts +5 -5
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +8 -8
  45. package/dist/index.js.map +2 -2
  46. package/dist/iso-block-locator.d.ts +39 -1
  47. package/dist/iso-block-locator.d.ts.map +1 -1
  48. package/dist/iso-block-locator.js +109 -17
  49. package/dist/iso-block-locator.js.map +3 -3
  50. package/dist/manifest-auth-plan.d.ts +26 -25
  51. package/dist/manifest-auth-plan.d.ts.map +1 -1
  52. package/dist/manifest-auth-plan.js +331 -1171
  53. package/dist/manifest-auth-plan.js.map +4 -4
  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 +1137 -317
  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 +159 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +531 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +39 -6
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +184 -27
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +86 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +347 -132
  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 +94 -5
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +877 -357
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +12 -2
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +108 -238
  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 +4 -1
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +1086 -301
  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 +81 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +156 -31
  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/source-auth.js +2710 -7
  114. package/dist/source-auth.js.map +4 -4
  115. package/dist/switching-set-alignment.d.ts +1 -1
  116. package/dist/switching-set-alignment.js.map +1 -1
  117. package/dist/timestamp-codec.js +21 -13
  118. package/dist/timestamp-codec.js.map +2 -2
  119. package/dist/wasm-mfu-reassembler.js.map +1 -1
  120. package/dist/wasm-mmtp-container-parser.js +93 -22
  121. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  122. package/package.json +6 -9
  123. package/schemas/catalog.schema.json +133 -38
  124. package/src/align.ts +52 -21
  125. package/src/carp-catalog.ts +188 -68
  126. package/src/catalog-fec-params.ts +28 -3
  127. package/src/catalog-network-source.ts +49 -7
  128. package/src/catalog-validator.ts +4 -11
  129. package/src/cmcd-producer.ts +17 -0
  130. package/src/fec-manager.ts +452 -63
  131. package/src/fec-state.ts +11 -4
  132. package/src/fec-worker-setup.ts +30 -2
  133. package/src/index.ts +27 -10
  134. package/src/iso-block-locator.ts +110 -7
  135. package/src/manifest-auth-plan.ts +39 -91
  136. package/src/mmtp-container-parser.ts +75 -7
  137. package/src/mmtp-fec-session.ts +533 -0
  138. package/src/mmtp-router.ts +166 -7
  139. package/src/multicast-auth-catalog.ts +131 -238
  140. package/src/multicast-input.ts +148 -124
  141. package/src/multicast-manager.ts +267 -21
  142. package/src/multicast-transport.ts +17 -3
  143. package/src/no-modules.ts +7 -1
  144. package/src/phase14-catalog-override.ts +3 -3
  145. package/src/repair-fetch.ts +283 -39
  146. package/src/repair-layers.ts +22 -2
  147. package/src/sample-combiner.ts +15 -2
  148. package/src/signaling.ts +2 -2
  149. package/src/switching-set-alignment.ts +1 -1
  150. package/test-vectors/align.json +108 -32
  151. package/test-vectors/bc-provenance-v2.json +1526 -0
  152. package/test-vectors/catalog/README.md +71 -4
  153. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  154. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  155. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  156. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  158. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  159. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  160. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  161. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  162. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  163. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  164. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  165. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  166. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  167. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  168. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  169. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  170. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  172. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  173. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  174. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  177. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  178. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  179. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  181. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  182. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  184. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  185. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  186. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  187. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  188. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  189. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  190. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  191. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  192. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  193. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  194. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  195. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  196. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  197. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  198. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  199. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  200. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  201. package/test-vectors/catalog/section-codes.json +31 -1
  202. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  203. package/test-vectors/catalog-validation.json +101 -5
  204. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  205. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  206. package/dist/fec-codec.d.ts +0 -32
  207. package/dist/fec-codec.d.ts.map +0 -1
  208. package/dist/fec-codec.js +0 -47
  209. package/dist/fec-codec.js.map +0 -7
  210. package/src/fec-codec.ts +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,8 +33,10 @@ 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";
@@ -46,7 +50,7 @@ import {
46
50
  type StreamSwitchCommit,
47
51
  type TrackPacketCallback,
48
52
  } from "./mmtp-router.js";
49
- import { isMulticastTrackPacketId } from "@blockcast/mmt-transport";
53
+ import { isMulticastTrackPacketId, type WindowMulticastGateway } from "@blockcast/mmt-transport";
50
54
  import {
51
55
  MulticastTransport,
52
56
  type MulticastFailbackReason,
@@ -83,6 +87,35 @@ import {
83
87
  } from "./carp-catalog.js";
84
88
  import { catalogFecUnavailable, type TrackFecUnavailable } from "./catalog-fec-params.js";
85
89
 
90
+ /**
91
+ * One dedicated repair group to join beside the media join: the shape
92
+ * `selectRepairEndpointsForTracks` (`@blockcast/mmt-transport`) returns.
93
+ */
94
+ export interface MulticastRepairEndpoint {
95
+ group: string;
96
+ source: string;
97
+ port: number;
98
+ mode?: string;
99
+ amtRelay?: string;
100
+ amtRelayPort?: number;
101
+ /** The repair packet IDs this group carries. */
102
+ packetIds: number[];
103
+ /** Each repair packet ID bound to the media packet ID it repairs. */
104
+ repairOwners: ReadonlyArray<{ packetId: number; ownerPacketId: number }>;
105
+ /** Ingress tracks: the owners' source tracks and the repair tracks. */
106
+ tracks: MmtpIngressContext["tracks"];
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
+
86
119
  export interface MulticastEndpointConfig {
87
120
  sourceAddress: string;
88
121
  groupAddress: string;
@@ -95,6 +128,12 @@ export interface MulticastEndpointConfig {
95
128
  amtRelay?: string;
96
129
  /** AMT relay port from player/UI overrides. Wins over `relayPort`. */
97
130
  amtRelayPort?: number;
131
+ /**
132
+ * `'driad'`: no relay is pinned; the window.multicast gateway runs RFC 8777
133
+ * DRIAD on `sourceAddress` and fails over across the relays it offers.
134
+ * Ignored when `amtRelay` is set.
135
+ */
136
+ amtDiscovery?: 'driad';
98
137
  /** MMTP packet IDs to forward before data enters the page transport queue. */
99
138
  packetIds?: number[];
100
139
  /** Exact catalog tracks carried by this physical multicast endpoint. */
@@ -297,6 +336,9 @@ interface RepairSymbolCounts {
297
336
  * class.
298
337
  * - `recovered` / `failed`: every block that could not complete from its
299
338
  * first-arrival source symbols resolves with exactly one of these.
339
+ * - `repair-sent`: the scheduler admitted and sent a repair FETCH; carries
340
+ * the admission inputs (RTT, time left to the deadline, which term set
341
+ * the deadline) so a harness reads the budget instead of inferring it.
300
342
  * - `repair-preempted` / `repair-deferred`: the scheduler aborted a delta
301
343
  * repair for keyframe work, or never ran it before its block resolved.
302
344
  * - `repair-priority`: the catalog could not supply the SUBSCRIBER_PRIORITY a
@@ -344,6 +386,23 @@ export type RepairLifecycleEvent =
344
386
  readonly type: "repair-preempted" | "repair-deferred";
345
387
  readonly block: RepairBlockIdentity;
346
388
  }
389
+ | {
390
+ readonly version: 2;
391
+ /**
392
+ * The scheduler sent a FETCH (BLO-33597): every attempt, a retry or a
393
+ * reprioritised restart included. `budgetMs` is the time left to the
394
+ * deadline at send, `bound` which term set that deadline; `delayMs` and
395
+ * `blockAgeMs` are null for a block with no anchor.
396
+ */
397
+ readonly type: "repair-sent";
398
+ readonly block: RepairBlockIdentity;
399
+ readonly priority: RepairPriority;
400
+ readonly rttMs: number;
401
+ readonly budgetMs: number;
402
+ readonly delayMs: number | null;
403
+ readonly blockAgeMs: number | null;
404
+ readonly bound: RepairDeadlineBound;
405
+ }
347
406
  | {
348
407
  readonly version: 2;
349
408
  /**
@@ -424,6 +483,11 @@ export interface BlockPolicyStats {
424
483
  repairsSkippedRttExceedsBudget: number;
425
484
  /** `repairsSkipped` by reason: the player gave no presentation delay. */
426
485
  repairsSkippedPresentationDelayUnavailable: number;
486
+ /**
487
+ * `repairsSkipped` by reason: a lost SS_ID in an undelimited span had no
488
+ * §7.5 anchor (no epoch reference, or none it could be extended from).
489
+ */
490
+ repairsSkippedRangeNoAnchor: number;
427
491
  /**
428
492
  * The most recent skip: its reason, the measured RTT (null when
429
493
  * unmeasured), the time that was left to the deadline, and the request's
@@ -438,6 +502,8 @@ export interface BlockPolicyStats {
438
502
  } | null;
439
503
  /** Repair FETCHes sent for keyframe/unknown (P0) blocks, every attempt counted. */
440
504
  keyframeRepairFetchesSent: number;
505
+ /** Range repair FETCHes (draft-ramadan-moq-fec §7.5 lost SS_ID) sent, every attempt counted. */
506
+ rangeRepairFetchesSent: number;
441
507
  /**
442
508
  * Requests the keyframe late-repair budget extended past the presentation
443
509
  * deadline (each one can hold the stream behind its block that long).
@@ -482,8 +548,10 @@ function newBlockPolicyStats(
482
548
  repairsSkippedRttUnmeasured: 0,
483
549
  repairsSkippedRttExceedsBudget: 0,
484
550
  repairsSkippedPresentationDelayUnavailable: 0,
551
+ repairsSkippedRangeNoAnchor: 0,
485
552
  lastRepairSkip: null,
486
553
  keyframeRepairFetchesSent: 0,
554
+ rangeRepairFetchesSent: 0,
487
555
  keyframeBudgetHolds: 0,
488
556
  keyframeBudgetHoldMs: 0,
489
557
  deltaBlocksFailed: 0,
@@ -629,6 +697,12 @@ const REPAIR_PRIORITY_REASONS: ReadonlySet<unknown> = new Set([
629
697
  "repair-priority-absent",
630
698
  "repair-priority-invalid",
631
699
  ]);
700
+ const REPAIR_SKIP_REASONS: ReadonlySet<unknown> = new Set([
701
+ "rtt-unmeasured",
702
+ "rtt-exceeds-budget",
703
+ "presentation-delay-unavailable",
704
+ ]);
705
+ const REPAIR_DEADLINE_BOUNDS: ReadonlySet<unknown> = new Set(["wait", "presentation", "keyframe", "retention"]);
632
706
  const GAP_REASONS: Readonly<Record<string, "stall" | "conceal">> = {
633
707
  "rap-lost": "stall",
634
708
  "rap-unknown": "stall",
@@ -661,6 +735,10 @@ function isNullableNonNegative(value: unknown): boolean {
661
735
  return value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
662
736
  }
663
737
 
738
+ function isFiniteNumber(value: unknown): boolean {
739
+ return typeof value === "number" && Number.isFinite(value);
740
+ }
741
+
664
742
  /** Runtime guard for observer, DOM-event, and cross-realm consumers. */
665
743
  export function isRepairLifecycleEvent(
666
744
  value: unknown,
@@ -703,6 +781,40 @@ export function isRepairLifecycleEvent(
703
781
  case "repair-preempted":
704
782
  case "repair-deferred":
705
783
  return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
784
+ case "repair-sent":
785
+ // Admission sends only when 0 < rttMs < budgetMs.
786
+ return (
787
+ hasExactKeys(value, [
788
+ "version",
789
+ "type",
790
+ "block",
791
+ "priority",
792
+ "rttMs",
793
+ "budgetMs",
794
+ "delayMs",
795
+ "blockAgeMs",
796
+ "bound",
797
+ ]) &&
798
+ isRepairBlockIdentity(block) &&
799
+ (value["priority"] === 0 || value["priority"] === 1 || value["priority"] === 2) &&
800
+ isFiniteNumber(value["rttMs"]) &&
801
+ (value["rttMs"] as number) > 0 &&
802
+ isFiniteNumber(value["budgetMs"]) &&
803
+ (value["budgetMs"] as number) > (value["rttMs"] as number) &&
804
+ isNullableNonNegative(value["delayMs"]) &&
805
+ isNullableNonNegative(value["blockAgeMs"]) &&
806
+ (value["delayMs"] === null) === (value["blockAgeMs"] === null) &&
807
+ REPAIR_DEADLINE_BOUNDS.has(value["bound"])
808
+ );
809
+ case "repair-skipped":
810
+ // budgetMs may be negative: the deadline can already have passed.
811
+ return (
812
+ hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) &&
813
+ isRepairBlockIdentity(block) &&
814
+ REPAIR_SKIP_REASONS.has(value["reason"]) &&
815
+ isNullableNonNegative(value["rttMs"]) &&
816
+ isFiniteNumber(value["budgetMs"])
817
+ );
706
818
  case "repair-priority": {
707
819
  const blockClass = value["blockClass"];
708
820
  const action = value["action"];
@@ -1099,6 +1211,9 @@ export class MulticastManager {
1099
1211
  readonly #router: MmtpRouter;
1100
1212
  #hostMfuTimeoutMs: number | null;
1101
1213
  readonly #transport: MulticastTransport<MmtpIngressContext>;
1214
+ /** Live joinRepairEndpoints() releases → the repair owners they registered,
1215
+ * re-applied after configureMultiTrack() clears catalog-derived owners. */
1216
+ readonly #repairReleases = new Map<() => void, MulticastRepairEndpoint["repairOwners"]>();
1102
1217
  #reportedFecDiagnosticsFailure = false;
1103
1218
 
1104
1219
  // ── Stream-global FEC timing reduction ──
@@ -1416,7 +1531,12 @@ export class MulticastManager {
1416
1531
  catalogTrackName,
1417
1532
  );
1418
1533
  this.#configureTrackMapper(packetId, config);
1419
- this.#router.setPacketIdType(packetId, trackType);
1534
+ // A Worker for an already registered track swaps the decoder mid-stream.
1535
+ // Re-registering the track would reset the parser's MPU timing and drop
1536
+ // the rest of the GOP in flight.
1537
+ if (this.#router.trackKindFor(packetId) !== trackType) {
1538
+ this.#router.setPacketIdType(packetId, trackType);
1539
+ }
1420
1540
  }
1421
1541
 
1422
1542
  /**
@@ -1510,6 +1630,18 @@ export class MulticastManager {
1510
1630
  }
1511
1631
  }
1512
1632
 
1633
+ // A data unit must outlive every FEC block that can still complete it: the
1634
+ // release gate waits for them up to terminal retention, and a fragment
1635
+ // recovered after its data unit was evicted is lost.
1636
+ for (const [packetId, c] of this.#trackFecTiming) {
1637
+ if (c.deliveryWindowMs === undefined) continue;
1638
+ mfuTimeoutMs = Math.max(
1639
+ mfuTimeoutMs ?? 0,
1640
+ this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
1641
+ this.#hostMfuTimeoutMs ?? 0,
1642
+ );
1643
+ }
1644
+
1513
1645
  const failbackWindowMs =
1514
1646
  deliveryWindowMs === undefined
1515
1647
  ? minimumFailbackWindowMs
@@ -1810,6 +1942,8 @@ export class MulticastManager {
1810
1942
  setMfuTimeoutMs(ms: number): void {
1811
1943
  this.#router.setMfuTimeoutMs(ms);
1812
1944
  this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
1945
+ // A FEC track's data units must still outlive its terminal retention.
1946
+ if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
1813
1947
  }
1814
1948
 
1815
1949
  setTrackCodec(packetId: number, codec: string) {
@@ -1978,6 +2112,7 @@ export class MulticastManager {
1978
2112
  config.amtRelayPort ??
1979
2113
  config.relayPort ??
1980
2114
  (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : undefined),
2115
+ amtDiscovery: config.amtDiscovery,
1981
2116
  packetIds: config.packetIds,
1982
2117
  tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId })),
1983
2118
  };
@@ -1986,6 +2121,82 @@ export class MulticastManager {
1986
2121
  : this.#transport.join(transportConfig, ingress);
1987
2122
  }
1988
2123
 
2124
+ /**
2125
+ * Join the selected rung's dedicated repair groups beside the media join
2126
+ * (pim #3898): one subscription per endpoint, through `provider` when given
2127
+ * (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
2128
+ * new MulticastTransport on `window.multicast`. Returns the call that
2129
+ * releases every one of them; dispose() releases them too.
2130
+ *
2131
+ * Packets go straight to the router with the endpoint's ingress, never
2132
+ * through feedPacket(): repair arriving on its own group is not media
2133
+ * liveness, so it must not hold off the media leg's failback watchdog. The
2134
+ * repair roles and owners are registered here; in-band owners stay the
2135
+ * caller's. Joining is best effort: a group that fails to join is logged
2136
+ * and leaves the media join as it was.
2137
+ */
2138
+ joinRepairEndpoints(
2139
+ endpoints: readonly MulticastRepairEndpoint[],
2140
+ provider?: WindowMulticastGateway | MulticastRepairSubscribe,
2141
+ ): () => void {
2142
+ const releases: Array<() => void> = [];
2143
+ let released = false;
2144
+ const safely = (each: () => void) => {
2145
+ try {
2146
+ each();
2147
+ } catch (error) {
2148
+ console.warn("[MulticastManager] repair group release failed", error);
2149
+ }
2150
+ };
2151
+ const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
2152
+ this.#applyRepairOwners(repairOwners);
2153
+ for (const endpoint of endpoints) {
2154
+ const ingress: MmtpIngressContext = {
2155
+ tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
2156
+ };
2157
+ const onPacket = (packet: Uint8Array) => {
2158
+ if (!released) this.#router.feedPacket(packet, "multicast", undefined, ingress);
2159
+ };
2160
+ const fail = (error: unknown) =>
2161
+ console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
2162
+ if (typeof provider === "function") {
2163
+ Promise.resolve()
2164
+ .then(() => provider(endpoint, onPacket))
2165
+ .then((release) => (released ? safely(release) : releases.push(release)), fail);
2166
+ continue;
2167
+ }
2168
+ const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
2169
+ releases.push(() => transport.dispose());
2170
+ void transport.join({
2171
+ sourceAddress: endpoint.source,
2172
+ groupAddress: endpoint.group,
2173
+ port: endpoint.port,
2174
+ mode: endpoint.mode as MulticastEndpointConfig["mode"],
2175
+ amtRelay: endpoint.amtRelay,
2176
+ amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : undefined),
2177
+ packetIds: endpoint.packetIds,
2178
+ tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
2179
+ }).then((joined) => {
2180
+ if (!joined && !released) fail(transport.lastJoinOutcome);
2181
+ });
2182
+ }
2183
+ const release = () => {
2184
+ if (released) return;
2185
+ released = true;
2186
+ this.#repairReleases.delete(release);
2187
+ for (const each of releases.splice(0)) safely(each);
2188
+ };
2189
+ this.#repairReleases.set(release, repairOwners);
2190
+ return release;
2191
+ }
2192
+
2193
+ #applyRepairOwners(owners: MulticastRepairEndpoint["repairOwners"]): void {
2194
+ for (const { packetId, ownerPacketId } of owners) {
2195
+ this.#router.setPacketIdRole(packetId, "repair");
2196
+ this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
2197
+ }
2198
+ }
2199
+
1989
2200
  // ---------------------------------------------------------------------------
1990
2201
  // In-place rendition switch
1991
2202
  // ---------------------------------------------------------------------------
@@ -2331,7 +2542,7 @@ export class MulticastManager {
2331
2542
  *
2332
2543
  * D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
2333
2544
  * D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
2334
- * D-17: Builds altGroup → track-name index for getSwitchingSet().
2545
+ * D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
2335
2546
  * D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
2336
2547
  *
2337
2548
  * FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
@@ -2411,11 +2622,9 @@ export class MulticastManager {
2411
2622
  }
2412
2623
  }
2413
2624
  const repairOwnerGroup = new Map<string, string>();
2414
- const repairOwnerAltGroup = new Map<string, number | undefined>();
2415
2625
  for (const track of catalog.tracks) {
2416
2626
  for (const repairName of repairNamesBySource.get(track.name) ?? []) {
2417
2627
  repairOwnerGroup.set(repairName, altGroupKey(track));
2418
- repairOwnerAltGroup.set(repairName, track.altGroup);
2419
2628
  }
2420
2629
  }
2421
2630
  const groupKeyFor = (track: MultiTrackCatalogTrack): string =>
@@ -2458,11 +2667,9 @@ export class MulticastManager {
2458
2667
  if (!(hasSwitchingSetByGroup.get(groupKey) ?? false)) continue;
2459
2668
 
2460
2669
  const presentRoles = new Set(roles.filter((r) => r !== "single"));
2461
- const required: Array<"base" | "delta" | "repair"> = [
2462
- "base",
2463
- "delta",
2464
- "repair",
2465
- ];
2670
+ // Delta is optional (BLO-49199): base is the self-decodable leg and a
2671
+ // base-only group plays in base-only mode; delta without base cannot.
2672
+ const required: Array<"base" | "repair"> = ["base", "repair"];
2466
2673
  const missing = required.filter((r) => !presentRoles.has(r));
2467
2674
  if (missing.length > 0) {
2468
2675
  throw new Error(
@@ -2517,6 +2724,9 @@ export class MulticastManager {
2517
2724
  this.#switchingSets.clear();
2518
2725
  this.#repairPacketIds.clear();
2519
2726
  this.#router.clearRepairPacketIdOwners();
2727
+ // Dedicated repair groups joined beside the media join outlive a catalog
2728
+ // refresh; their owners are not this catalog's to drop.
2729
+ for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
2520
2730
  // FEC a previous call configured that this one does not (the source is
2521
2731
  // gone, lost its `fec`, or its FEC is now unavailable) must not stay
2522
2732
  // installed: its symbols would still be read as block coordinates and
@@ -2547,15 +2757,13 @@ export class MulticastManager {
2547
2757
  const track = catalog.tracks[i]!;
2548
2758
  const role = resolvedRoles[i]!;
2549
2759
 
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) ?? [];
2760
+ // D-17: Build altGroup → track-name index. Members are the tracks that
2761
+ // carry equal altGroup; a repair leg is in no switching set, whatever it
2762
+ // declares (draft-ramadan-moq-mmt-01 Switching Sets).
2763
+ if (role !== "repair" && track.altGroup !== undefined) {
2764
+ const existing = this.#switchingSets.get(track.altGroup) ?? [];
2557
2765
  existing.push(track.name);
2558
- this.#switchingSets.set(altGroup, existing);
2766
+ this.#switchingSets.set(track.altGroup, existing);
2559
2767
  }
2560
2768
 
2561
2769
  // D-26: Register packetId → role on MmtpRouter (if packetId provided at ingest time).
@@ -2649,7 +2857,7 @@ export class MulticastManager {
2649
2857
 
2650
2858
  /**
2651
2859
  * Return the track names belonging to the given altGroup switching set.
2652
- * D-17: altGroup groups base+delta+repair into one switching set.
2860
+ * D-17: tracks with equal altGroup form one switching set; repair legs are in none.
2653
2861
  *
2654
2862
  * @param altGroup - The altGroup number to look up.
2655
2863
  * @returns Array of track names in that switching set (empty if none).
@@ -2679,6 +2887,29 @@ export class MulticastManager {
2679
2887
  };
2680
2888
  }
2681
2889
 
2890
+ /**
2891
+ * Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
2892
+ * on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
2893
+ * pending hole and reported here, and `closeIsoHoles` must be called for it
2894
+ * once its range FETCH ends (or none is sent).
2895
+ */
2896
+ onUndelimitedLoss(cb: (loss: UndelimitedIsoLoss) => void): void {
2897
+ this.#fec.setUndelimitedLossHandler(cb);
2898
+ }
2899
+
2900
+ /**
2901
+ * Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
2902
+ * to CmcdProducer.updateFecFailClosed.
2903
+ */
2904
+ onFecFailClosed(cb: (event: FecFailClosedEvent) => void): void {
2905
+ this.#fec.setFecFailClosedHandler(cb);
2906
+ }
2907
+
2908
+ /** End a pending hole's range repair: feed what no repair stated as spans. */
2909
+ closeIsoHoles(packetId: number, catalogTrackName: string | undefined, start: number, length: number): void {
2910
+ this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
2911
+ }
2912
+
2682
2913
  /**
2683
2914
  * Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
2684
2915
  * supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
@@ -2714,6 +2945,7 @@ export class MulticastManager {
2714
2945
  stats.repairsSkipped++;
2715
2946
  if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
2716
2947
  else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
2948
+ else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
2717
2949
  else stats.repairsSkippedPresentationDelayUnavailable++;
2718
2950
  stats.lastRepairSkip = {
2719
2951
  reason,
@@ -2755,11 +2987,24 @@ export class MulticastManager {
2755
2987
  /** Record a repair FETCH the scheduler admitted and sent. */
2756
2988
  noteRepairFetchSent(
2757
2989
  priority: RepairPriority,
2758
- _sbn: number,
2990
+ sbn: number,
2759
2991
  packetId: number,
2760
- catalogTrackName?: string,
2992
+ catalogTrackName: string | undefined,
2993
+ measurement: RepairSendMeasurement,
2761
2994
  ): void {
2762
2995
  if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
2996
+ if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
2997
+ this.#emitRepairLifecycle({
2998
+ version: 2,
2999
+ type: "repair-sent",
3000
+ block: repairBlockIdentity(packetId, sbn, catalogTrackName),
3001
+ priority,
3002
+ rttMs: measurement.rttMs,
3003
+ budgetMs: measurement.budgetMs,
3004
+ delayMs: measurement.delayMs,
3005
+ blockAgeMs: measurement.blockAgeMs,
3006
+ bound: measurement.bound,
3007
+ });
2763
3008
  }
2764
3009
 
2765
3010
  /**
@@ -2951,6 +3196,7 @@ export class MulticastManager {
2951
3196
  this.#trackResetObservers.clear();
2952
3197
  this.#repairLifecycleObservers.clear();
2953
3198
  this.#transport.dispose();
3199
+ for (const release of [...this.#repairReleases.keys()]) release();
2954
3200
  this.#router.dispose();
2955
3201
  this.#fec.dispose();
2956
3202
  }
@@ -25,8 +25,12 @@ export interface MulticastTransportConfig {
25
25
  mode?: 'auto' | 'native' | 'tunnel'
26
26
  amtRelay?: string
27
27
  amtRelayPort?: number
28
+ /** `'driad'`: with no relay, the gateway discovers one per RFC 8777. */
29
+ amtDiscovery?: 'driad'
28
30
  packetIds?: number[]
29
31
  tracks?: { name: string; packetId: number }[]
32
+ /** ATSC 3.0 tuning (`catalogAtsc3NetworkSource`); when set the join is the tuner. */
33
+ atsc3?: { frequency: number; plpId?: number; serviceId?: number }
30
34
  }
31
35
 
32
36
  export type ResolvedMulticastTransport = 'native' | 'amt'
@@ -330,8 +334,15 @@ export class MulticastTransport<TPacketContext = never> {
330
334
  readonly #unadvertisedPacketIds = new Set<number>()
331
335
  #joinGeneration = 0
332
336
 
333
- constructor(onPacket: (packet: Uint8Array, context?: TPacketContext) => void) {
337
+ // The provider to subscribe through; window.multicast when unset.
338
+ readonly #gateway: WindowMulticastGateway | undefined
339
+
340
+ constructor(
341
+ onPacket: (packet: Uint8Array, context?: TPacketContext) => void,
342
+ options: { gateway?: WindowMulticastGateway } = {},
343
+ ) {
334
344
  this.#onPacket = onPacket
345
+ this.#gateway = options.gateway
335
346
  }
336
347
 
337
348
  static isAvailable(): boolean {
@@ -344,7 +355,8 @@ export class MulticastTransport<TPacketContext = never> {
344
355
  this.#dataPlaneLive = false
345
356
 
346
357
  if (this.#disposed) return this.#declined(generation, 'disposed')
347
- if (!MulticastTransport.isAvailable()) {
358
+ const gateway = this.#gateway ?? getMulticastGlobals().multicast
359
+ if (typeof gateway?.subscribe !== 'function') {
348
360
  console.warn('[MulticastTransport] Multicast API not available')
349
361
  return this.#declined(generation, 'unavailable')
350
362
  }
@@ -365,11 +377,13 @@ export class MulticastTransport<TPacketContext = never> {
365
377
  mode: config.mode,
366
378
  amtRelay: config.amtRelay,
367
379
  amtRelayPort: config.amtRelayPort,
380
+ amtDiscovery: config.amtDiscovery,
368
381
  packetIds: config.packetIds,
369
382
  tracks: config.tracks,
383
+ atsc3: config.atsc3,
370
384
  })
371
385
  failure = 'provider-rejected'
372
- const subscription = await getMulticastGlobals().multicast!.subscribe!(subscribeConfig)
386
+ const subscription = await gateway.subscribe(subscribeConfig)
373
387
  failure = 'invalid-subscription'
374
388
  console.log(`[MulticastTransport] window.multicast.subscribe returned:`, !!subscription)
375
389
 
package/src/no-modules.ts CHANGED
@@ -10,9 +10,15 @@ export {
10
10
  CmsfCatalogValidationError,
11
11
  resolveGroupDurationMs,
12
12
  } from './carp-catalog.js'
13
- export { catalogFecInterleaveMs, computeFecTimeout } from '@blockcast/mmt-fec'
13
+ export { catalogFecInterleaveMs, fecBlockBudgetMs, fecBlockDeadlineMs } from '@blockcast/mmt-fec'
14
14
  export { FEC_INACTIVE_REASONS, catalogDeclaresFec, resolveFecState } from './fec-state.js'
15
+ export { MmtpFecSession } from './mmtp-fec-session.js'
16
+ export { catalogAmtNetworkSource, catalogAtsc3NetworkSource } from './catalog-network-source.js'
15
17
  export { MmtpToCmaf } from './mmtp-to-cmaf.js'
18
+ // Catalog initData contract check (mmt-01 4.5). Shaka's Closure build can
19
+ // reach only this classic-script surface, so it has to be exported here as
20
+ // well as from the barrel (BLO-49943).
21
+ export { isFmp4InitSegment } from './codec-utils.js'
16
22
  export { createManifestAuthPlan } from './manifest-auth-plan.js'
17
23
  export {
18
24
  ManifestVerifier,
@@ -50,7 +50,7 @@ export interface Phase14OverrideTrack {
50
50
  * derives it from the override's top-level `streamingFormat`. */
51
51
  packaging?: "mmtp" | "cmaf" | "loc" | "timeline";
52
52
  /** Required when packaging is `mmtp`; the current publisher emits MFU mode. */
53
- mmtpMode?: "mpu" | "mfu";
53
+ mmtpMode?: "mfu";
54
54
  /** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */
55
55
  timescale?: number;
56
56
  /** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */
@@ -262,7 +262,7 @@ export function mergeOverrideIntoCmsfTracks(
262
262
  if (ot.role !== undefined && existing.role === undefined) existing.role = ot.role;
263
263
  if (existing.packaging === "mmtp") {
264
264
  const mode = existing.mmtpMode ?? ot.mmtpMode;
265
- if (mode !== "mpu" && mode !== "mfu") {
265
+ if (mode !== "mfu") {
266
266
  throw new Error(
267
267
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`,
268
268
  );
@@ -302,7 +302,7 @@ export function mergeOverrideIntoCmsfTracks(
302
302
  );
303
303
  }
304
304
  const mmtpMode = ot.mmtpMode;
305
- if (packaging === "mmtp" && mmtpMode !== "mpu" && mmtpMode !== "mfu") {
305
+ if (packaging === "mmtp" && mmtpMode !== "mfu") {
306
306
  throw new Error(
307
307
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`,
308
308
  );