@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.c7ae84be5039

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 (152) hide show
  1. package/README.md +28 -14
  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 +778 -272
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +58 -26
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +270 -194
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +6 -13
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +1 -1
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js.map +1 -1
  19. package/dist/catalog-validator.d.ts +4 -3
  20. package/dist/catalog-validator.d.ts.map +1 -1
  21. package/dist/catalog-validator.js +0 -29
  22. package/dist/catalog-validator.js.map +3 -3
  23. package/dist/delivery-catalog.js +4 -12
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/fec-manager.js.map +1 -1
  26. package/dist/fec-state.d.ts.map +1 -1
  27. package/dist/fec-state.js +14 -2
  28. package/dist/fec-state.js.map +3 -3
  29. package/dist/fec-worker-setup.js.map +1 -1
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -0
  33. package/dist/index.js.map +2 -2
  34. package/dist/iso-block-locator.js.map +1 -1
  35. package/dist/manifest-auth-plan.d.ts +26 -25
  36. package/dist/manifest-auth-plan.d.ts.map +1 -1
  37. package/dist/manifest-auth-plan.js +315 -1163
  38. package/dist/manifest-auth-plan.js.map +4 -4
  39. package/dist/mfu-reassembler.js.map +2 -2
  40. package/dist/mmtp-container-parser.js.map +2 -2
  41. package/dist/mmtp-container-parser.no-modules.js +947 -278
  42. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  43. package/dist/mmtp-decode-pipeline.js.map +2 -2
  44. package/dist/mmtp-fec-session.d.ts +156 -0
  45. package/dist/mmtp-fec-session.d.ts.map +1 -0
  46. package/dist/mmtp-fec-session.js +522 -0
  47. package/dist/mmtp-fec-session.js.map +7 -0
  48. package/dist/mmtp-router.d.ts.map +1 -1
  49. package/dist/mmtp-router.js +17 -0
  50. package/dist/mmtp-router.js.map +2 -2
  51. package/dist/multicast-auth-catalog.d.ts +86 -92
  52. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  53. package/dist/multicast-auth-catalog.js +331 -124
  54. package/dist/multicast-auth-catalog.js.map +3 -3
  55. package/dist/multicast-input.d.ts +26 -4
  56. package/dist/multicast-input.d.ts.map +1 -1
  57. package/dist/multicast-input.js +283 -23
  58. package/dist/multicast-input.js.map +3 -3
  59. package/dist/multicast-manager.d.ts +23 -4
  60. package/dist/multicast-manager.d.ts.map +1 -1
  61. package/dist/multicast-manager.js +59 -29
  62. package/dist/multicast-manager.js.map +4 -4
  63. package/dist/multicast-transport.js +2 -10
  64. package/dist/multicast-transport.js.map +4 -4
  65. package/dist/multicast-unwrap.js.map +2 -2
  66. package/dist/no-modules.d.ts +2 -0
  67. package/dist/no-modules.d.ts.map +1 -1
  68. package/dist/no-modules.js +899 -267
  69. package/dist/no-modules.js.map +4 -4
  70. package/dist/phase14-catalog-override.d.ts +1 -1
  71. package/dist/phase14-catalog-override.d.ts.map +1 -1
  72. package/dist/phase14-catalog-override.js +2 -2
  73. package/dist/phase14-catalog-override.js.map +2 -2
  74. package/dist/repair-fetch.d.ts +23 -1
  75. package/dist/repair-fetch.d.ts.map +1 -1
  76. package/dist/repair-fetch.js +35 -10
  77. package/dist/repair-fetch.js.map +2 -2
  78. package/dist/repair-layers.js.map +1 -1
  79. package/dist/signaling.d.ts +2 -2
  80. package/dist/signaling.d.ts.map +1 -1
  81. package/dist/signaling.js +3 -3
  82. package/dist/signaling.js.map +2 -2
  83. package/dist/source-auth.js +22 -6
  84. package/dist/source-auth.js.map +2 -2
  85. package/dist/switching-set-alignment.d.ts +1 -1
  86. package/dist/switching-set-alignment.js.map +1 -1
  87. package/dist/timestamp-codec.js.map +2 -2
  88. package/dist/wasm-mfu-reassembler.js.map +1 -1
  89. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  90. package/package.json +5 -5
  91. package/schemas/catalog.schema.json +117 -34
  92. package/src/align.ts +52 -21
  93. package/src/carp-catalog.ts +120 -46
  94. package/src/catalog-fec-params.ts +5 -2
  95. package/src/catalog-network-source.ts +1 -1
  96. package/src/catalog-validator.ts +4 -11
  97. package/src/fec-state.ts +3 -2
  98. package/src/index.ts +18 -2
  99. package/src/manifest-auth-plan.ts +39 -91
  100. package/src/mmtp-fec-session.ts +514 -0
  101. package/src/mmtp-router.ts +25 -0
  102. package/src/multicast-auth-catalog.ts +131 -238
  103. package/src/multicast-input.ts +109 -54
  104. package/src/multicast-manager.ts +88 -14
  105. package/src/no-modules.ts +2 -0
  106. package/src/phase14-catalog-override.ts +3 -3
  107. package/src/repair-fetch.ts +79 -14
  108. package/src/signaling.ts +2 -2
  109. package/src/switching-set-alignment.ts +1 -1
  110. package/test-vectors/align.json +108 -32
  111. package/test-vectors/catalog/README.md +55 -3
  112. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  113. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  114. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  115. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  116. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  117. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  118. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  119. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  120. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  121. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  122. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  123. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  124. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  125. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  126. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  127. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  128. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  129. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-out-of-range.json +56 -0
  130. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  131. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  132. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  133. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  134. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  135. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  136. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  137. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  138. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  139. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  140. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  141. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  142. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  143. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  144. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  145. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  146. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  147. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  148. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  149. package/test-vectors/catalog/section-codes.json +27 -1
  150. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  151. package/test-vectors/catalog-validation.json +3 -2
  152. package/test-vectors/catalog-validator-public-api.mjs +14 -9
@@ -8,7 +8,8 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
8
8
  /**
9
9
  * Multicast catalog input contract — validator + builder.
10
10
  *
11
- * Per draft-ramadan-moq-multicast-00 §3 + §4.1, the publisher (FFmpeg,
11
+ * Per draft-ramadan-moq-multicast-01 §3 + §4.1 + §7.2.6
12
+ * (Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4), the publisher (FFmpeg,
12
13
  * cast bridge, GStreamer, OBS-bridge) populates `multicast.endpoints[]`
13
14
  * in the catalog when its output includes a UDP multicast destination.
14
15
  *
@@ -22,17 +23,23 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
22
23
  * perform.
23
24
  *
24
25
  * Validation invariants (per codex review of BLO-3323 v2):
25
- * - protocol === 'ssm' → sourceAddress REQUIRED
26
- * - protocol === 'amt' → a catalog-level `multicast.networkSource` entry of
27
- * type "amt" REQUIRED; its `relay` is required only for
28
- * `discovery: "manual"` ("driad" resolves the relay at runtime).
29
- * A per-endpoint `relayAddress` input is LIFTED into that entry and is
30
- * never emitted onto the endpoint.
31
- * - protocol === 'atsc3' → a catalog-level `multicast.networkSource` entry of
32
- * type "atsc3" REQUIRED; it carries the frequency, PLP, service id and SLS
33
- * URI, which is the only tuning information an ATSC3 receiver has.
34
- * - protocol === 'ssm' | 'asm' → no `networkSource` entry required: a native
35
- * join describes no alternate bearer (BLO-37926).
26
+ * - The emitted mode is the one `sourceAddress` selects (present: SSM,
27
+ * absent: ASM), restated as `protocol`. Input `protocol` "ssm" requires
28
+ * `sourceAddress`, "asm" forbids it.
29
+ * - Input `protocol` "amt" / "atsc3" names a bearer, which draft -01
30
+ * carries as a `networkSource` entry, not a protocol: the `networkSource`
31
+ * entries of that type MOVE onto each endpoint that named it (so they
32
+ * no longer apply to native endpoints) and the protocol is never emitted.
33
+ * An entry of that type is REQUIRED: an AMT one's `relay` only for
34
+ * `discovery: "manual"` ("driad" resolves it at runtime), an ATSC3 one
35
+ * carries the only tuning information an ATSC3 receiver has. A
36
+ * per-endpoint `relayAddress` input is LIFTED into the AMT entry.
37
+ * - Native "ssm" | "asm" requires no `networkSource` entry: a native join
38
+ * describes no alternate bearer (BLO-37926).
39
+ * - `auth` (catalog) and endpoint `auth` follow draft -01 7.2.6 through the
40
+ * shared `multicastCatalogIssues` of `@blockcast/mmt-base`: all or
41
+ * nothing, `senderAddress` on ASM only, bandwidth required, and
42
+ * `(S, G, manifestPort)` clear of every port of its `(S, G)`.
36
43
  * - groupAddress is a valid IPv4 multicast group (224.0.0.0/4)
37
44
  * or IPv6 multicast group (ff00::/8)
38
45
  * - SSM groupAddress MUST be in 232.0.0.0/8 (IPv4) or ff3x::/32 (IPv6),
@@ -46,23 +53,31 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
46
53
  * `signaling_packet_id`. The kind string matches cast's
47
54
  * `multicast_input.rs` so the two ports report the same reason.
48
55
  * - packetIds unique within an endpoint
49
- * - (sourceAddress, groupAddress, port) tuple unique across endpoints
56
+ * - (S, groupAddress, port) tuple unique across endpoints, S being
57
+ * sourceAddress (SSM), auth.senderAddress (protected ASM) or absent
50
58
  * - bandwidth (if present) > 0
51
59
  * - validUntil (if present) is a positive unix-ms timestamp
52
60
  *
53
- * @see draft-ramadan-moq-multicast-00 §4.1
61
+ * @see draft-ramadan-moq-multicast-01 §4.1, §7.2.6
54
62
  * @see .planning/drafts/blo-3323-multicast-catalog-source-of-truth.md
55
63
  */
56
64
 
57
- import { MMTP_PACKET_ID_MAX, MMTP_SIGNALING_PACKET_ID } from "@blockcast/mmt-base";
65
+ import { MMTP_PACKET_ID_MAX, MMTP_SIGNALING_PACKET_ID, multicastCatalogIssues } from "@blockcast/mmt-base";
58
66
  import {
59
67
  type AmtDiscovery,
60
68
  type MulticastCatalogConfig,
61
69
  type MulticastEndpoint,
62
- type MulticastProtocol,
63
70
  type MulticastTrackObject,
64
71
  type NetworkSource,
65
72
  } from "./carp-catalog.js";
73
+ import type { EndpointAuthConfig, MulticastAuthConfig } from "./multicast-auth-catalog.js";
74
+
75
+ /**
76
+ * Publisher input protocol. "ssm" / "asm" restate the mode `sourceAddress`
77
+ * selects; "amt" / "atsc3" (draft -00) name a bearer and are mapped onto an
78
+ * endpoint-level `networkSource`, never emitted.
79
+ */
80
+ export type MulticastInputProtocol = "ssm" | "asm" | "amt" | "atsc3";
66
81
 
67
82
  /**
68
83
  * Strict typed input for one multicast endpoint. The publisher provides
@@ -70,7 +85,7 @@ import {
70
85
  * lifts it into a `MulticastEndpoint` ready to embed in the catalog.
71
86
  */
72
87
  export interface MulticastEndpointInput {
73
- readonly protocol: MulticastProtocol;
88
+ readonly protocol: MulticastInputProtocol;
74
89
  readonly sourceAddress?: string;
75
90
  readonly groupAddress: string;
76
91
  readonly port: number;
@@ -88,8 +103,10 @@ export interface MulticastEndpointInput {
88
103
  * Prefer declaring `MulticastInput.networkSource` directly.
89
104
  */
90
105
  readonly relayAddress?: string;
91
- /** Aggregate bandwidth in bits per second. RECOMMENDED per draft §4.1. */
106
+ /** Aggregate bandwidth in bits per second. RECOMMENDED per draft §4.1; REQUIRED with `auth`. */
92
107
  readonly bandwidth?: number;
108
+ /** Protected-flow parameters (draft -01 7.2.6); REQUIRED exactly when `MulticastInput.auth` is set. */
109
+ readonly auth?: EndpointAuthConfig;
93
110
  }
94
111
 
95
112
  /**
@@ -112,7 +129,9 @@ export interface MulticastInput {
112
129
  */
113
130
  readonly networkSource?: ReadonlyArray<NetworkSource>;
114
131
  /** @deprecated Lifted into `networkSource`; no longer emitted. */
115
- readonly amtFallback?: { readonly discovery: AmtDiscovery; readonly relayDns?: string };
132
+ readonly amtFallback?: { readonly discovery?: AmtDiscovery; readonly relayDns?: string };
133
+ /** bc-provenance version 2 profile and keys (draft -01 7.2.6). */
134
+ readonly auth?: MulticastAuthConfig;
116
135
  readonly version?: number;
117
136
  readonly validUntil?: number;
118
137
  }
@@ -127,6 +146,17 @@ export type MulticastInputErrorKind =
127
146
  */
128
147
  | "invalid_endpoints"
129
148
  | "ssm_requires_source"
149
+ /** Input `protocol` "asm" with a `sourceAddress`, which selects SSM. */
150
+ | "protocol_source_mismatch"
151
+ /** `MulticastInput.auth` fails draft -01 7.2.6 (version, keys, a repeated kid or firstEpoch). */
152
+ | "invalid_multicast_auth"
153
+ /**
154
+ * An endpoint's `auth` fails draft -01 7.2.6: present without
155
+ * `MulticastInput.auth` or absent with it, `senderAddress` on SSM or
156
+ * missing on ASM, a timer out of range, no `bandwidth`, or a
157
+ * `manifestPort` that is a port or manifestPort of its `(S, G)`.
158
+ */
159
+ | "invalid_endpoint_auth"
130
160
  /**
131
161
  * Deliberately overloaded, unlike its one-site mirror
132
162
  * `atsc3_requires_tuning`: an AMT relay can be missing at two layers, and
@@ -242,8 +272,7 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
242
272
  }
243
273
  }
244
274
 
245
- const seenTuples = new Set<string>();
246
- const endpoints: MulticastEndpoint[] = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx, seenTuples));
275
+ const endpoints: MulticastEndpoint[] = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx));
247
276
 
248
277
  const out: MulticastCatalogConfig = { endpoints };
249
278
  const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
@@ -312,8 +341,8 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
312
341
  //
313
342
  // The two arms are about different values, so they name different
314
343
  // fields. The demoted arm is about `discovery`: a derived entry is only
315
- // `"driad"` when `amtFallback.discovery` said so (the default is
316
- // `"manual"`), so `amtFallback` is always the actionable field there.
344
+ // `"driad"` when `amtFallback.discovery` said so (there is no default),
345
+ // so `amtFallback` is always the actionable field there.
317
346
  // The set clause is about the *relay*, which `resolveNetworkSource`
318
347
  // takes from `amtFallback.relayDns` or from the endpoint
319
348
  // `relayAddress` values -- and saying "amtFallback" to an operator who
@@ -380,6 +409,30 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
380
409
  );
381
410
  });
382
411
 
412
+ // Draft -01 4.2: a bearer is a networkSource entry. An endpoint that named
413
+ // one as its protocol gets that type's entries as its own networkSource.
414
+ // They are copied, not moved: the catalog-level array already applied to
415
+ // every endpoint under -00 readers, and still does under -01.
416
+ input.endpoints.forEach((ep, idx) => {
417
+ if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
418
+ endpoints[idx]!.networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
419
+ });
420
+
421
+ if (input.auth !== undefined) out.auth = input.auth;
422
+ const [issue] = multicastCatalogIssues({ multicast: out });
423
+ if (issue) {
424
+ const kind: MulticastInputErrorKind =
425
+ issue.code === "multicast_auth"
426
+ ? "invalid_multicast_auth"
427
+ : issue.code === "multicast_endpoint_auth"
428
+ ? "invalid_endpoint_auth"
429
+ : issue.path.endsWith(".port")
430
+ ? "duplicate_endpoint_tuple"
431
+ : "protocol_source_mismatch";
432
+ const where = issue.endpointIndex === undefined ? "" : `endpoint[${issue.endpointIndex}] `;
433
+ throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
434
+ }
435
+
383
436
  if (input.enabled !== undefined) out.enabled = input.enabled;
384
437
  if (input.version !== undefined) out.version = input.version;
385
438
  if (input.validUntil !== undefined) out.validUntil = input.validUntil;
@@ -391,9 +444,10 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
391
444
  *
392
445
  * An explicit `input.networkSource` is authoritative and used as given.
393
446
  * Otherwise one AMT entry is derived from the deprecated inputs it replaces:
394
- * `amtFallback.discovery`/`relayDns` and any endpoint `relayAddress`;
395
- * `discovery` defaults to `"manual"` because a relay named in the catalog is,
396
- * by definition, not discovered. Endpoint relays that disagree with the result
447
+ * `amtFallback.discovery`/`relayDns` and any endpoint `relayAddress`.
448
+ * `discovery` is copied only when given: draft-ramadan-moq-multicast-01 4.2.1
449
+ * reads an omitted `discovery` with a hostname `relay` as `"dns"`, so no
450
+ * default is written. Endpoint relays that disagree with the result
397
451
  * are rejected by `multicastFromConfig`, not resolved here.
398
452
  *
399
453
  * `relayFrom` reports which deprecated input supplied the derived relay, so
@@ -411,10 +465,10 @@ function resolveNetworkSource(input: MulticastInput): {
411
465
 
412
466
  const relayDns = input.amtFallback?.relayDns?.trim();
413
467
  const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
414
- const discovery = input.amtFallback?.discovery ?? (relay ? "manual" : undefined);
415
- if (discovery === undefined) return { entries: [], relayFrom: null };
468
+ const discovery = input.amtFallback?.discovery;
469
+ if (discovery === undefined && !relay) return { entries: [], relayFrom: null };
416
470
  return {
417
- entries: [{ type: "amt", discovery, ...(relay ? { relay } : {}) }],
471
+ entries: [{ type: "amt", ...(discovery ? { discovery } : {}), ...(relay ? { relay } : {}) }],
418
472
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress",
419
473
  };
420
474
  }
@@ -425,7 +479,7 @@ const ATSC3_SOURCE_KEYS = new Set(["type", "frequency", "plpId", "serviceId", "s
425
479
  /**
426
480
  * One `networkSource[]` entry against `catalog.schema.json` `$defs/networkSource`
427
481
  * (and moq-rs `NetworkSource`), plus the one semantic rule the schema leaves
428
- * out: `discovery: "manual"` names its relay. These helpers are consumed
482
+ * out: `discovery: "dns"` and `"manual"` name their relay. These helpers are consumed
429
483
  * out-of-tree from plain JS, so the `NetworkSource` type is no guarantee.
430
484
  */
431
485
  function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
@@ -443,8 +497,11 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
443
497
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
444
498
 
445
499
  if (s.type === "amt") {
446
- if (s.discovery !== "driad" && s.discovery !== "manual") {
447
- throw err("invalid_amt_discovery", `discovery must be "driad" or "manual"; got ${JSON.stringify(s.discovery)}`);
500
+ if (s.discovery !== undefined && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
501
+ throw err(
502
+ "invalid_amt_discovery",
503
+ `discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`,
504
+ );
448
505
  }
449
506
  if (s.relay !== undefined) {
450
507
  // Canonicalize, don't just check: the conflict guard in
@@ -459,8 +516,8 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
459
516
  }
460
517
  s.relay = relay;
461
518
  }
462
- if (s.discovery === "manual" && s.relay === undefined) {
463
- throw err("amt_requires_relay", `discovery="manual" requires a relay ("driad" resolves it at runtime)`);
519
+ if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === undefined) {
520
+ throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
464
521
  }
465
522
  if (s.port !== undefined && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
466
523
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -489,11 +546,7 @@ function isAbsoluteUri(value: string): boolean {
489
546
  }
490
547
  }
491
548
 
492
- function validateEndpoint(
493
- ep: MulticastEndpointInput,
494
- idx: number,
495
- seenTuples: Set<string>,
496
- ): MulticastEndpoint {
549
+ function validateEndpoint(ep: MulticastEndpointInput, idx: number): MulticastEndpoint {
497
550
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
498
551
  throw new MulticastInputError(
499
552
  "ssm_requires_source",
@@ -501,6 +554,13 @@ function validateEndpoint(
501
554
  `endpoint[${idx}] protocol=ssm requires sourceAddress`,
502
555
  );
503
556
  }
557
+ if (ep.protocol === "asm" && ep.sourceAddress !== undefined) {
558
+ throw new MulticastInputError(
559
+ "protocol_source_mismatch",
560
+ idx,
561
+ `endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`,
562
+ );
563
+ }
504
564
  // NOTE: `protocol: "amt"` no longer requires a per-endpoint relay here. The
505
565
  // relay is catalog-level (`multicast.networkSource`), which this function
506
566
  // cannot see; `multicastFromConfig` enforces it once both halves are in hand.
@@ -570,18 +630,12 @@ function validateEndpoint(
570
630
  );
571
631
  }
572
632
 
573
- const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
574
- if (seenTuples.has(tupleKey)) {
575
- throw new MulticastInputError(
576
- "duplicate_endpoint_tuple",
577
- idx,
578
- `endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`,
579
- );
580
- }
581
- seenTuples.add(tupleKey);
582
-
633
+ // Tuple uniqueness is keyed on S, which needs `auth`; `multicastFromConfig`
634
+ // checks it with the rest of draft -01 4.1 once the catalog is composed.
635
+ // The emitted protocol restates the mode `sourceAddress` selects; a bearer
636
+ // input protocol is never emitted.
583
637
  const out: MulticastEndpoint = {
584
- protocol: ep.protocol,
638
+ protocol: ep.sourceAddress === undefined ? "asm" : "ssm",
585
639
  groupAddress: ep.groupAddress,
586
640
  port: ep.port,
587
641
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId })),
@@ -590,6 +644,7 @@ function validateEndpoint(
590
644
  // `relayAddress` is deliberately NOT copied: the relay is lifted to
591
645
  // catalog-level `multicast.networkSource` by `multicastFromConfig`.
592
646
  if (ep.bandwidth !== undefined) out.bandwidth = ep.bandwidth;
647
+ if (ep.auth !== undefined) out.auth = { ...ep.auth };
593
648
  return out;
594
649
  }
595
650
 
@@ -689,9 +744,9 @@ export function multicastFromEnv(
689
744
  ...(hasCatalogAmt
690
745
  ? {
691
746
  amtFallback: {
692
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
693
- // the catalog is, by definition, not discovered.
694
- discovery: (amtDiscovery ?? "manual") as AmtDiscovery,
747
+ // No default: an omitted discovery with a relay hostname is
748
+ // "dns" (draft-ramadan-moq-multicast-01 4.2.1).
749
+ ...(amtDiscovery ? { discovery: amtDiscovery as AmtDiscovery } : {}),
695
750
  ...(amtRelayDns ? { relayDns: amtRelayDns } : {}),
696
751
  },
697
752
  }
@@ -757,7 +812,7 @@ function readEndpointAt(env: Record<string, string | undefined>, idx: number): M
757
812
  const relay = lookup("RELAY");
758
813
 
759
814
  return {
760
- protocol: lookup("PROTOCOL") as MulticastProtocol,
815
+ protocol: lookup("PROTOCOL") as MulticastInputProtocol,
761
816
  groupAddress: lookup("GROUP") ?? "",
762
817
  port,
763
818
  tracks,
@@ -31,8 +31,10 @@ import {
31
31
  type TrackKind,
32
32
  } from "./block-policy.js";
33
33
  import type {
34
+ RepairDeadlineBound,
34
35
  RepairFetchHost,
35
36
  RepairPriorityReason,
37
+ RepairSendMeasurement,
36
38
  RepairSkipReason,
37
39
  RepairSubscribeCallback,
38
40
  } from "./repair-fetch.js";
@@ -332,6 +334,9 @@ interface RepairSymbolCounts {
332
334
  * class.
333
335
  * - `recovered` / `failed`: every block that could not complete from its
334
336
  * first-arrival source symbols resolves with exactly one of these.
337
+ * - `repair-sent`: the scheduler admitted and sent a repair FETCH; carries
338
+ * the admission inputs (RTT, time left to the deadline, which term set
339
+ * the deadline) so a harness reads the budget instead of inferring it.
335
340
  * - `repair-preempted` / `repair-deferred`: the scheduler aborted a delta
336
341
  * repair for keyframe work, or never ran it before its block resolved.
337
342
  * - `repair-priority`: the catalog could not supply the SUBSCRIBER_PRIORITY a
@@ -379,6 +384,23 @@ export type RepairLifecycleEvent =
379
384
  readonly type: "repair-preempted" | "repair-deferred";
380
385
  readonly block: RepairBlockIdentity;
381
386
  }
387
+ | {
388
+ readonly version: 2;
389
+ /**
390
+ * The scheduler sent a FETCH (BLO-33597): every attempt, a retry or a
391
+ * reprioritised restart included. `budgetMs` is the time left to the
392
+ * deadline at send, `bound` which term set that deadline; `delayMs` and
393
+ * `blockAgeMs` are null for a block with no anchor.
394
+ */
395
+ readonly type: "repair-sent";
396
+ readonly block: RepairBlockIdentity;
397
+ readonly priority: RepairPriority;
398
+ readonly rttMs: number;
399
+ readonly budgetMs: number;
400
+ readonly delayMs: number | null;
401
+ readonly blockAgeMs: number | null;
402
+ readonly bound: RepairDeadlineBound;
403
+ }
382
404
  | {
383
405
  readonly version: 2;
384
406
  /**
@@ -664,6 +686,12 @@ const REPAIR_PRIORITY_REASONS: ReadonlySet<unknown> = new Set([
664
686
  "repair-priority-absent",
665
687
  "repair-priority-invalid",
666
688
  ]);
689
+ const REPAIR_SKIP_REASONS: ReadonlySet<unknown> = new Set([
690
+ "rtt-unmeasured",
691
+ "rtt-exceeds-budget",
692
+ "presentation-delay-unavailable",
693
+ ]);
694
+ const REPAIR_DEADLINE_BOUNDS: ReadonlySet<unknown> = new Set(["wait", "presentation", "keyframe", "retention"]);
667
695
  const GAP_REASONS: Readonly<Record<string, "stall" | "conceal">> = {
668
696
  "rap-lost": "stall",
669
697
  "rap-unknown": "stall",
@@ -696,6 +724,10 @@ function isNullableNonNegative(value: unknown): boolean {
696
724
  return value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
697
725
  }
698
726
 
727
+ function isFiniteNumber(value: unknown): boolean {
728
+ return typeof value === "number" && Number.isFinite(value);
729
+ }
730
+
699
731
  /** Runtime guard for observer, DOM-event, and cross-realm consumers. */
700
732
  export function isRepairLifecycleEvent(
701
733
  value: unknown,
@@ -738,6 +770,40 @@ export function isRepairLifecycleEvent(
738
770
  case "repair-preempted":
739
771
  case "repair-deferred":
740
772
  return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
773
+ case "repair-sent":
774
+ // Admission sends only when 0 < rttMs < budgetMs.
775
+ return (
776
+ hasExactKeys(value, [
777
+ "version",
778
+ "type",
779
+ "block",
780
+ "priority",
781
+ "rttMs",
782
+ "budgetMs",
783
+ "delayMs",
784
+ "blockAgeMs",
785
+ "bound",
786
+ ]) &&
787
+ isRepairBlockIdentity(block) &&
788
+ (value["priority"] === 0 || value["priority"] === 1 || value["priority"] === 2) &&
789
+ isFiniteNumber(value["rttMs"]) &&
790
+ (value["rttMs"] as number) > 0 &&
791
+ isFiniteNumber(value["budgetMs"]) &&
792
+ (value["budgetMs"] as number) > (value["rttMs"] as number) &&
793
+ isNullableNonNegative(value["delayMs"]) &&
794
+ isNullableNonNegative(value["blockAgeMs"]) &&
795
+ (value["delayMs"] === null) === (value["blockAgeMs"] === null) &&
796
+ REPAIR_DEADLINE_BOUNDS.has(value["bound"])
797
+ );
798
+ case "repair-skipped":
799
+ // budgetMs may be negative: the deadline can already have passed.
800
+ return (
801
+ hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) &&
802
+ isRepairBlockIdentity(block) &&
803
+ REPAIR_SKIP_REASONS.has(value["reason"]) &&
804
+ isNullableNonNegative(value["rttMs"]) &&
805
+ isFiniteNumber(value["budgetMs"])
806
+ );
741
807
  case "repair-priority": {
742
808
  const blockClass = value["blockClass"];
743
809
  const action = value["action"];
@@ -2465,7 +2531,7 @@ export class MulticastManager {
2465
2531
  *
2466
2532
  * D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
2467
2533
  * D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
2468
- * D-17: Builds altGroup → track-name index for getSwitchingSet().
2534
+ * D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
2469
2535
  * D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
2470
2536
  *
2471
2537
  * FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
@@ -2545,11 +2611,9 @@ export class MulticastManager {
2545
2611
  }
2546
2612
  }
2547
2613
  const repairOwnerGroup = new Map<string, string>();
2548
- const repairOwnerAltGroup = new Map<string, number | undefined>();
2549
2614
  for (const track of catalog.tracks) {
2550
2615
  for (const repairName of repairNamesBySource.get(track.name) ?? []) {
2551
2616
  repairOwnerGroup.set(repairName, altGroupKey(track));
2552
- repairOwnerAltGroup.set(repairName, track.altGroup);
2553
2617
  }
2554
2618
  }
2555
2619
  const groupKeyFor = (track: MultiTrackCatalogTrack): string =>
@@ -2682,15 +2746,13 @@ export class MulticastManager {
2682
2746
  const track = catalog.tracks[i]!;
2683
2747
  const role = resolvedRoles[i]!;
2684
2748
 
2685
- // D-17: Build altGroup → track-name index. A repair leg belongs to the
2686
- // switching set of the owner that points at it.
2687
- const altGroup = repairOwnerAltGroup.has(track.name)
2688
- ? repairOwnerAltGroup.get(track.name)
2689
- : track.altGroup;
2690
- if (altGroup !== undefined) {
2691
- const existing = this.#switchingSets.get(altGroup) ?? [];
2749
+ // D-17: Build altGroup → track-name index. Members are the tracks that
2750
+ // carry equal altGroup; a repair leg is in no switching set, whatever it
2751
+ // declares (draft-ramadan-moq-mmt-01 Switching Sets).
2752
+ if (role !== "repair" && track.altGroup !== undefined) {
2753
+ const existing = this.#switchingSets.get(track.altGroup) ?? [];
2692
2754
  existing.push(track.name);
2693
- this.#switchingSets.set(altGroup, existing);
2755
+ this.#switchingSets.set(track.altGroup, existing);
2694
2756
  }
2695
2757
 
2696
2758
  // D-26: Register packetId → role on MmtpRouter (if packetId provided at ingest time).
@@ -2784,7 +2846,7 @@ export class MulticastManager {
2784
2846
 
2785
2847
  /**
2786
2848
  * Return the track names belonging to the given altGroup switching set.
2787
- * D-17: altGroup groups base+delta+repair into one switching set.
2849
+ * D-17: tracks with equal altGroup form one switching set; repair legs are in none.
2788
2850
  *
2789
2851
  * @param altGroup - The altGroup number to look up.
2790
2852
  * @returns Array of track names in that switching set (empty if none).
@@ -2890,11 +2952,23 @@ export class MulticastManager {
2890
2952
  /** Record a repair FETCH the scheduler admitted and sent. */
2891
2953
  noteRepairFetchSent(
2892
2954
  priority: RepairPriority,
2893
- _sbn: number,
2955
+ sbn: number,
2894
2956
  packetId: number,
2895
- catalogTrackName?: string,
2957
+ catalogTrackName: string | undefined,
2958
+ measurement: RepairSendMeasurement,
2896
2959
  ): void {
2897
2960
  if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
2961
+ this.#emitRepairLifecycle({
2962
+ version: 2,
2963
+ type: "repair-sent",
2964
+ block: repairBlockIdentity(packetId, sbn, catalogTrackName),
2965
+ priority,
2966
+ rttMs: measurement.rttMs,
2967
+ budgetMs: measurement.budgetMs,
2968
+ delayMs: measurement.delayMs,
2969
+ blockAgeMs: measurement.blockAgeMs,
2970
+ bound: measurement.bound,
2971
+ });
2898
2972
  }
2899
2973
 
2900
2974
  /**
package/src/no-modules.ts CHANGED
@@ -12,6 +12,8 @@ export {
12
12
  } from './carp-catalog.js'
13
13
  export { catalogFecInterleaveMs, computeFecTimeout } 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 } from './catalog-network-source.js'
15
17
  export { MmtpToCmaf } from './mmtp-to-cmaf.js'
16
18
  export { createManifestAuthPlan } from './manifest-auth-plan.js'
17
19
  export {
@@ -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
  );