@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbdfdbf39ded

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