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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +37 -21
  2. package/dist/align.d.ts +24 -18
  3. package/dist/align.d.ts.map +1 -1
  4. package/dist/align.js +23 -4
  5. package/dist/align.js.map +2 -2
  6. package/dist/browser-runtime.js +5070 -908
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +76 -39
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +321 -205
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +12 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +40 -17
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +28 -7
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +21 -1
  19. package/dist/catalog-network-source.js.map +2 -2
  20. package/dist/catalog-validator.d.ts +4 -3
  21. package/dist/catalog-validator.d.ts.map +1 -1
  22. package/dist/catalog-validator.js +0 -29
  23. package/dist/catalog-validator.js.map +3 -3
  24. package/dist/cmcd-producer.d.ts +13 -1
  25. package/dist/cmcd-producer.d.ts.map +1 -1
  26. package/dist/cmcd-producer.js +14 -0
  27. package/dist/cmcd-producer.js.map +2 -2
  28. package/dist/delivery-catalog.js +115 -235
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +113 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +464 -66
  33. package/dist/fec-manager.js.map +4 -4
  34. package/dist/fec-state.d.ts +2 -1
  35. package/dist/fec-state.d.ts.map +1 -1
  36. package/dist/fec-state.js +18 -3
  37. package/dist/fec-state.js.map +3 -3
  38. package/dist/fec-worker-setup.d.ts +10 -0
  39. package/dist/fec-worker-setup.d.ts.map +1 -1
  40. package/dist/fec-worker-setup.js +15 -4
  41. package/dist/fec-worker-setup.js.map +2 -2
  42. package/dist/held-layer-admission.d.ts +58 -0
  43. package/dist/held-layer-admission.d.ts.map +1 -0
  44. package/dist/held-layer-admission.js +105 -0
  45. package/dist/held-layer-admission.js.map +7 -0
  46. package/dist/index.d.ts +5 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +8 -8
  49. package/dist/index.js.map +2 -2
  50. package/dist/iso-block-locator.d.ts +39 -1
  51. package/dist/iso-block-locator.d.ts.map +1 -1
  52. package/dist/iso-block-locator.js +109 -17
  53. package/dist/iso-block-locator.js.map +3 -3
  54. package/dist/mfu-reassembler.js +21 -13
  55. package/dist/mfu-reassembler.js.map +2 -2
  56. package/dist/mmtp-container-parser.d.ts.map +1 -1
  57. package/dist/mmtp-container-parser.js +93 -22
  58. package/dist/mmtp-container-parser.js.map +2 -2
  59. package/dist/mmtp-container-parser.no-modules.js +3692 -1213
  60. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  61. package/dist/mmtp-decode-pipeline.js +93 -22
  62. package/dist/mmtp-decode-pipeline.js.map +2 -2
  63. package/dist/mmtp-fec-session.d.ts +192 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +640 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +101 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +422 -189
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +94 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +746 -131
  74. package/dist/multicast-auth-catalog.js.map +4 -4
  75. package/dist/multicast-input.d.ts +31 -8
  76. package/dist/multicast-input.d.ts.map +1 -1
  77. package/dist/multicast-input.js +299 -35
  78. package/dist/multicast-input.js.map +3 -3
  79. package/dist/multicast-manager.d.ts +140 -12
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +4104 -605
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +16 -3
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +127 -240
  86. package/dist/multicast-transport.js.map +4 -4
  87. package/dist/multicast-unwrap.js +21 -13
  88. package/dist/multicast-unwrap.js.map +2 -2
  89. package/dist/no-modules.d.ts +5 -3
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +3643 -1197
  92. package/dist/no-modules.js.map +4 -4
  93. package/dist/phase14-catalog-override.d.ts +1 -1
  94. package/dist/phase14-catalog-override.d.ts.map +1 -1
  95. package/dist/phase14-catalog-override.js +2 -2
  96. package/dist/phase14-catalog-override.js.map +2 -2
  97. package/dist/repair-fetch.d.ts +90 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +160 -32
  100. package/dist/repair-fetch.js.map +3 -3
  101. package/dist/repair-layers.d.ts +2 -0
  102. package/dist/repair-layers.d.ts.map +1 -1
  103. package/dist/repair-layers.js +19 -2
  104. package/dist/repair-layers.js.map +2 -2
  105. package/dist/sample-combiner.d.ts +7 -1
  106. package/dist/sample-combiner.d.ts.map +1 -1
  107. package/dist/sample-combiner.js +14 -2
  108. package/dist/sample-combiner.js.map +2 -2
  109. package/dist/signaling.d.ts +2 -2
  110. package/dist/signaling.d.ts.map +1 -1
  111. package/dist/signaling.js +3 -3
  112. package/dist/signaling.js.map +2 -2
  113. package/dist/switching-set-alignment.d.ts +1 -1
  114. package/dist/switching-set-alignment.js.map +1 -1
  115. package/dist/timestamp-codec.js +21 -13
  116. package/dist/timestamp-codec.js.map +2 -2
  117. package/dist/wasm-mfu-reassembler.js.map +1 -1
  118. package/dist/wasm-mmtp-container-parser.js +93 -22
  119. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  120. package/package.json +6 -18
  121. package/schemas/catalog.schema.json +133 -38
  122. package/src/align.ts +52 -21
  123. package/src/carp-catalog.ts +188 -68
  124. package/src/catalog-fec-params.ts +28 -3
  125. package/src/catalog-network-source.ts +49 -7
  126. package/src/catalog-validator.ts +4 -11
  127. package/src/cmcd-producer.ts +23 -1
  128. package/src/fec-manager.ts +378 -63
  129. package/src/fec-state.ts +11 -4
  130. package/src/fec-worker-setup.ts +30 -2
  131. package/src/held-layer-admission.ts +161 -0
  132. package/src/index.ts +32 -19
  133. package/src/iso-block-locator.ts +110 -7
  134. package/src/mmtp-container-parser.ts +75 -7
  135. package/src/mmtp-fec-session.ts +606 -0
  136. package/src/mmtp-router.ts +453 -236
  137. package/src/multicast-auth-catalog.ts +196 -231
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +447 -53
  140. package/src/multicast-transport.ts +23 -5
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +306 -42
  144. package/src/repair-layers.ts +22 -2
  145. package/src/sample-combiner.ts +15 -2
  146. package/src/signaling.ts +2 -2
  147. package/src/switching-set-alignment.ts +1 -1
  148. package/test-vectors/align.json +108 -32
  149. package/test-vectors/bc-provenance-v2.json +1526 -0
  150. package/test-vectors/catalog/README.md +71 -4
  151. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  152. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  153. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  154. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  156. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  158. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  159. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  160. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  161. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  162. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  163. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  164. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  165. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  167. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  168. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  169. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  170. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  172. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  174. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  177. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  178. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  179. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  181. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  182. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  184. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  185. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  186. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  187. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  188. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  189. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  190. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  191. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  192. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  193. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  194. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  195. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  196. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  197. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  198. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  199. package/test-vectors/catalog/section-codes.json +31 -1
  200. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  201. package/test-vectors/catalog-validation.json +101 -5
  202. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  203. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  204. package/dist/fec-codec.d.ts +0 -32
  205. package/dist/fec-codec.d.ts.map +0 -1
  206. package/dist/fec-codec.js +0 -47
  207. package/dist/fec-codec.js.map +0 -7
  208. package/dist/manifest-auth-plan.d.ts +0 -30
  209. package/dist/manifest-auth-plan.d.ts.map +0 -1
  210. package/dist/manifest-auth-plan.js +0 -1266
  211. package/dist/manifest-auth-plan.js.map +0 -7
  212. package/dist/source-auth.d.ts +0 -2
  213. package/dist/source-auth.d.ts.map +0 -1
  214. package/dist/source-auth.js +0 -1209
  215. package/dist/source-auth.js.map +0 -7
  216. package/src/fec-codec.ts +0 -61
  217. package/src/manifest-auth-plan.ts +0 -107
  218. package/src/source-auth.ts +0 -1
  219. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  220. package/test-vectors/source-auth-v1.json +0 -61
@@ -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
@@ -138,8 +168,8 @@ export type MulticastInputErrorKind =
138
168
  | "amt_requires_relay"
139
169
  /**
140
170
  * An `atsc3` endpoint with no `networkSource` entry of type `"atsc3"`. The
141
- * ATSC3 entry carries the frequency, PLP, service id and SLS URI — the only
142
- * tuning information there is — so without it the endpoint names a broadcast
171
+ * ATSC3 entry carries the frequency (kHz; PLP, service id and SLS URI are
172
+ * optional) — the only tuning information there is — so without it the endpoint names a broadcast
143
173
  * nobody can tune to. The AMT mirror of this is `amt_requires_relay`; native
144
174
  * joins ("ssm", "asm") describe no bearer and are exempt (BLO-37926).
145
175
  */
@@ -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);
@@ -256,22 +285,15 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
256
285
  // `networkSource` is catalog-level, so a per-endpoint relay that differs from
257
286
  // it (another endpoint's, `amtFallback.relayDns`, or an explicit entry) would
258
287
  // otherwise be dropped silently and that endpoint joins the wrong relay.
259
- //
260
- // A DRIAD entry does not count: both readers skip it, so its `relay` is a
261
- // discovery hint, not a relay the catalog carries. Without this the derived
262
- // path merges `amtFallback: {discovery: "driad"}` with an endpoint's
263
- // `relayAddress` into a driad entry holding that relay, the check passes, and
264
- // the join silently falls through to DRIAD -- where the explicit form of the
265
- // same input already fails closed here.
288
+ // A DRIAD entry carries no relay (`validateNetworkSourceEntry`).
266
289
  const amtRelays = new Set(
267
290
  networkSource
268
- .flatMap((s) => (s.type === "amt" && s.discovery !== "driad" && s.relay?.trim() ? [s.relay.trim()] : []))
291
+ .flatMap((s) => (s.type === "amt" && s.relay?.trim() ? [s.relay.trim()] : []))
269
292
  // Only the first, because it is the only one either reader can
270
293
  // deliver: `catalogAmtNetworkSource` returns on it and `findAmtRelay`
271
294
  // uses `.find`. Collecting every entry accepts an endpoint naming a
272
295
  // second manual entry, which then joins the first -- the same silent
273
- // wrong-relay join this guard exists to prevent, through the one
274
- // shape the DRIAD filter does not cover. It also keeps the `(...)`
296
+ // wrong-relay join this guard exists to prevent. It also keeps the `(...)`
275
297
  // listing below honest. Sliced rather than `.find`ed so the `amt`
276
298
  // narrowing stays inside the callback.
277
299
  .slice(0, 1),
@@ -279,48 +301,21 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
279
301
  input.endpoints.forEach((ep, idx) => {
280
302
  const relay = ep.relayAddress?.trim();
281
303
  if (!relay || amtRelays.has(relay)) return;
282
- // Two different causes reach this throw and they need different fixes.
283
- // If a DRIAD entry carries this exact relay, the catalog is not missing
284
- // it -- the entry is present and demoted, so reporting the set as
285
- // "(none)" sends the operator looking for an entry they already wrote.
286
- // Name the demotion and the two-entry shape that escapes it; both
287
- // readers take the first non-DRIAD AMT entry
288
- // (`catalog-network-source.ts` `catalogAmtNetworkSource`,
289
- // `multicast-catalog-policy.ts` `findAmtRelay`) and
290
- // `validateNetworkSourceEntry` has no duplicate-type rule, so a manual
291
- // entry beside the DRIAD one is joined while the DRIAD one is kept.
292
- const demoted = networkSource.some(
293
- (s) => s.type === "amt" && s.discovery === "driad" && s.relay?.trim() === relay,
294
- );
295
- // Same "written down but undeliverable" family as `demoted`, different
296
- // reason and so a different fix: there the entry is skipped for its
297
- // discovery, here for its position. Reachable only on the explicit
304
+ // The entry is written down but undeliverable for its position: both
305
+ // readers join the first AMT entry. Reachable only on the explicit
298
306
  // path -- `resolveNetworkSource` emits at most one entry -- so there is
299
307
  // no provenance clause to add, and saying "is not the relay of any AMT
300
308
  // entry" here would be plainly false: the operator can see the entry.
301
309
  // `amtRelays` holds only the first joinable relay, so reaching this
302
310
  // throw at all already means this one is not it.
303
311
  const shadowed = networkSource.some(
304
- (s) => s.type === "amt" && s.discovery !== "driad" && s.relay?.trim() === relay,
312
+ (s) => s.type === "amt" && s.relay?.trim() === relay,
305
313
  );
306
314
  // The derived and env paths never wrote `networkSource` at all -- it was
307
- // synthesised below in `resolveNetworkSource` -- so naming only that key
308
- // would name the one field the operator did not set. This applies to
309
- // EVERY cause that reaches this throw, not just the demoted one: the
310
- // clause belongs in the shared prefix, or the arm that omits it
311
- // reproduces the misdiagnosis the other arm was written to fix.
312
- //
313
- // The two arms are about different values, so they name different
314
- // 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.
317
- // The set clause is about the *relay*, which `resolveNetworkSource`
318
- // takes from `amtFallback.relayDns` or from the endpoint
319
- // `relayAddress` values -- and saying "amtFallback" to an operator who
320
- // never wrote one is the same defect one level down. Read that source
321
- // from `relayFrom` rather than re-inferring it: three review rounds
322
- // found a local re-inference here drifting from the rule above it.
323
- const derived = input.networkSource === undefined;
315
+ // synthesised in `resolveNetworkSource` -- so name the input that
316
+ // supplied the relay. Read that source from `relayFrom` rather than
317
+ // re-inferring it: three review rounds found a local re-inference here
318
+ // drifting from the rule above it.
324
319
  const fromAmtFallback = ", derived from amtFallback/MOQCAST_MULTICAST_AMT_*";
325
320
  const fromRelay =
326
321
  relayFrom === "amtFallback.relayDns"
@@ -332,31 +327,23 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
332
327
  // the derived path the set can be non-empty and still not hold this
333
328
  // relay. Blaming per-endpoint representation there is wrong twice over:
334
329
  // there may be only one endpoint, and the field that actually won is
335
- // `relayDns`, which is the one the operator can act on. Asking
336
- // `amtRelays` instead would miss the case where the winning entry is
337
- // `discovery: "driad"` and so filtered out of that set entirely.
330
+ // `relayDns`, which is the one the operator can act on.
338
331
  const relayDns = input.amtFallback?.relayDns?.trim();
339
332
  const outranked = relayFrom === "amtFallback.relayDns" && relayDns !== relay;
340
333
  throw new MulticastInputError(
341
334
  "conflicting_amt_relay",
342
335
  idx,
343
336
  `endpoint[${idx}] relayAddress ${JSON.stringify(relay)} ` +
344
- (demoted
345
- ? `is carried only by a multicast.networkSource AMT entry with discovery="driad"` +
346
- `${derived ? fromAmtFallback : ""}, ` +
347
- "whose relay is a DRIAD discovery hint that both readers skip, so the catalog names " +
348
- "no relay to join; to join it, add a manual entry beside the driad one: " +
349
- `[{type:"amt",discovery:"manual",relay:${JSON.stringify(relay)}},{type:"amt",discovery:"driad"}]`
350
- : shadowed
351
- ? `is carried by a multicast.networkSource AMT entry that is not the first one: ` +
352
- `both readers join the first AMT entry (${[...amtRelays].join(", ")}) and ignore ` +
353
- "the rest, so this relay is never joined; keep a single AMT entry, or put this one first"
354
- : `is not the relay of any multicast.networkSource AMT entry ` +
355
- `(${[...amtRelays].join(", ") || "none"})${fromRelay}; ` +
356
- (outranked
357
- ? `amtFallback.relayDns/MOQCAST_MULTICAST_AMT_RELAY_DNS (${relayDns}) outranks an ` +
358
- "endpoint relay when networkSource is derived -- drop one, or make them agree"
359
- : "networkSource is catalog-level and cannot represent per-endpoint relays")),
337
+ (shadowed
338
+ ? `is carried by a multicast.networkSource AMT entry that is not the first one: ` +
339
+ `both readers join the first AMT entry (${[...amtRelays].join(", ")}) and ignore ` +
340
+ "the rest, so this relay is never joined; keep a single AMT entry, or put this one first"
341
+ : `is not the relay of any multicast.networkSource AMT entry ` +
342
+ `(${[...amtRelays].join(", ") || "none"})${fromRelay}; ` +
343
+ (outranked
344
+ ? `amtFallback.relayDns/MOQCAST_MULTICAST_AMT_RELAY_DNS (${relayDns}) outranks an ` +
345
+ "endpoint relay when networkSource is derived -- drop one, or make them agree"
346
+ : "networkSource is catalog-level and cannot represent per-endpoint relays")),
360
347
  );
361
348
  });
362
349
 
@@ -375,11 +362,35 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
375
362
  `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of ` +
376
363
  `type "${ep.protocol}"` +
377
364
  (ep.protocol === "atsc3"
378
- ? " carrying frequency, plpId, serviceId and slsUri — an ATSC3 endpoint is not tunable without them"
365
+ ? " carrying at least its frequency (kHz) — an ATSC3 endpoint is not tunable without it"
379
366
  : ""),
380
367
  );
381
368
  });
382
369
 
370
+ // Draft -01 4.2: a bearer is a networkSource entry. An endpoint that named
371
+ // one as its protocol gets that type's entries as its own networkSource.
372
+ // They are copied, not moved: the catalog-level array already applied to
373
+ // every endpoint under -00 readers, and still does under -01.
374
+ input.endpoints.forEach((ep, idx) => {
375
+ if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
376
+ endpoints[idx]!.networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
377
+ });
378
+
379
+ if (input.auth !== undefined) out.auth = input.auth;
380
+ const [issue] = multicastCatalogIssues({ multicast: out });
381
+ if (issue) {
382
+ const kind: MulticastInputErrorKind =
383
+ issue.code === "multicast_auth"
384
+ ? "invalid_multicast_auth"
385
+ : issue.code === "multicast_endpoint_auth"
386
+ ? "invalid_endpoint_auth"
387
+ : issue.path.endsWith(".port")
388
+ ? "duplicate_endpoint_tuple"
389
+ : "protocol_source_mismatch";
390
+ const where = issue.endpointIndex === undefined ? "" : `endpoint[${issue.endpointIndex}] `;
391
+ throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
392
+ }
393
+
383
394
  if (input.enabled !== undefined) out.enabled = input.enabled;
384
395
  if (input.version !== undefined) out.version = input.version;
385
396
  if (input.validUntil !== undefined) out.validUntil = input.validUntil;
@@ -391,9 +402,10 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
391
402
  *
392
403
  * An explicit `input.networkSource` is authoritative and used as given.
393
404
  * 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
405
+ * `amtFallback.discovery`/`relayDns` and any endpoint `relayAddress`.
406
+ * `discovery` is copied only when given: draft-ramadan-moq-multicast-01 4.2.1
407
+ * reads an omitted `discovery` with a hostname `relay` as `"dns"`, so no
408
+ * default is written. Endpoint relays that disagree with the result
397
409
  * are rejected by `multicastFromConfig`, not resolved here.
398
410
  *
399
411
  * `relayFrom` reports which deprecated input supplied the derived relay, so
@@ -411,10 +423,10 @@ function resolveNetworkSource(input: MulticastInput): {
411
423
 
412
424
  const relayDns = input.amtFallback?.relayDns?.trim();
413
425
  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 };
426
+ const discovery = input.amtFallback?.discovery;
427
+ if (discovery === undefined && !relay) return { entries: [], relayFrom: null };
416
428
  return {
417
- entries: [{ type: "amt", discovery, ...(relay ? { relay } : {}) }],
429
+ entries: [{ type: "amt", ...(discovery ? { discovery } : {}), ...(relay ? { relay } : {}) }],
418
430
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress",
419
431
  };
420
432
  }
@@ -425,7 +437,7 @@ const ATSC3_SOURCE_KEYS = new Set(["type", "frequency", "plpId", "serviceId", "s
425
437
  /**
426
438
  * One `networkSource[]` entry against `catalog.schema.json` `$defs/networkSource`
427
439
  * (and moq-rs `NetworkSource`), plus the one semantic rule the schema leaves
428
- * out: `discovery: "manual"` names its relay. These helpers are consumed
440
+ * out: `discovery: "dns"` and `"manual"` name their relay. These helpers are consumed
429
441
  * out-of-tree from plain JS, so the `NetworkSource` type is no guarantee.
430
442
  */
431
443
  function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
@@ -443,8 +455,11 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
443
455
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
444
456
 
445
457
  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)}`);
458
+ if (s.discovery !== undefined && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
459
+ throw err(
460
+ "invalid_amt_discovery",
461
+ `discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`,
462
+ );
448
463
  }
449
464
  if (s.relay !== undefined) {
450
465
  // Canonicalize, don't just check: the conflict guard in
@@ -459,8 +474,15 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
459
474
  }
460
475
  s.relay = relay;
461
476
  }
462
- if (s.discovery === "manual" && s.relay === undefined) {
463
- throw err("amt_requires_relay", `discovery="manual" requires a relay ("driad" resolves it at runtime)`);
477
+ if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === undefined) {
478
+ throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
479
+ }
480
+ if (s.discovery === "driad" && s.relay !== undefined) {
481
+ throw err(
482
+ "invalid_network_source",
483
+ `discovery="driad" must omit relay: DRIAD supplies the relay candidates (draft -01 4.2.1); ` +
484
+ `drop the relay (amtFallback.relayDns / endpoint relayAddress on the derived path), or use "dns" or "manual"`,
485
+ );
464
486
  }
465
487
  if (s.port !== undefined && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
466
488
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -469,13 +491,16 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
469
491
  }
470
492
  const inRange = (v: number, min: number, max: number) => Number.isInteger(v) && v >= min && v <= max;
471
493
  if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
472
- throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
494
+ throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
495
+ }
496
+ // Draft -01 4.2.2: only frequency (kHz) is REQUIRED; the rest are checked when set.
497
+ if (s.plpId !== undefined && !inRange(s.plpId, 0, 63)) {
498
+ throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
473
499
  }
474
- if (!inRange(s.plpId, 0, 63)) throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
475
- if (!inRange(s.serviceId, 0, 65535)) {
500
+ if (s.serviceId !== undefined && !inRange(s.serviceId, 0, 65535)) {
476
501
  throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
477
502
  }
478
- if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
503
+ if (s.slsUri !== undefined && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
479
504
  throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
480
505
  }
481
506
  }
@@ -489,11 +514,7 @@ function isAbsoluteUri(value: string): boolean {
489
514
  }
490
515
  }
491
516
 
492
- function validateEndpoint(
493
- ep: MulticastEndpointInput,
494
- idx: number,
495
- seenTuples: Set<string>,
496
- ): MulticastEndpoint {
517
+ function validateEndpoint(ep: MulticastEndpointInput, idx: number): MulticastEndpoint {
497
518
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
498
519
  throw new MulticastInputError(
499
520
  "ssm_requires_source",
@@ -501,6 +522,13 @@ function validateEndpoint(
501
522
  `endpoint[${idx}] protocol=ssm requires sourceAddress`,
502
523
  );
503
524
  }
525
+ if (ep.protocol === "asm" && ep.sourceAddress !== undefined) {
526
+ throw new MulticastInputError(
527
+ "protocol_source_mismatch",
528
+ idx,
529
+ `endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`,
530
+ );
531
+ }
504
532
  // NOTE: `protocol: "amt"` no longer requires a per-endpoint relay here. The
505
533
  // relay is catalog-level (`multicast.networkSource`), which this function
506
534
  // cannot see; `multicastFromConfig` enforces it once both halves are in hand.
@@ -570,18 +598,12 @@ function validateEndpoint(
570
598
  );
571
599
  }
572
600
 
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
-
601
+ // Tuple uniqueness is keyed on S, which needs `auth`; `multicastFromConfig`
602
+ // checks it with the rest of draft -01 4.1 once the catalog is composed.
603
+ // The emitted protocol restates the mode `sourceAddress` selects; a bearer
604
+ // input protocol is never emitted.
583
605
  const out: MulticastEndpoint = {
584
- protocol: ep.protocol,
606
+ protocol: ep.sourceAddress === undefined ? "asm" : "ssm",
585
607
  groupAddress: ep.groupAddress,
586
608
  port: ep.port,
587
609
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId })),
@@ -590,6 +612,7 @@ function validateEndpoint(
590
612
  // `relayAddress` is deliberately NOT copied: the relay is lifted to
591
613
  // catalog-level `multicast.networkSource` by `multicastFromConfig`.
592
614
  if (ep.bandwidth !== undefined) out.bandwidth = ep.bandwidth;
615
+ if (ep.auth !== undefined) out.auth = { ...ep.auth };
593
616
  return out;
594
617
  }
595
618
 
@@ -640,8 +663,9 @@ function isSsmGroupAddress(addr: string): boolean {
640
663
  * MOQCAST_MULTICAST[_<idx>]_TRACKS=video:1,audio:3
641
664
  * MOQCAST_MULTICAST[_<idx>]_BANDWIDTH=8000000 (optional, bps)
642
665
  *
643
- * MOQCAST_MULTICAST_AMT_DISCOVERY=driad (catalog-level)
644
- * MOQCAST_MULTICAST_AMT_RELAY_DNS=relay.example.com (catalog-level)
666
+ * MOQCAST_MULTICAST_AMT_DISCOVERY=dns (catalog-level)
667
+ * MOQCAST_MULTICAST_AMT_RELAY_DNS=relay.example.com (catalog-level;
668
+ * must be unset with discovery=driad)
645
669
  *
646
670
  * The unindexed form (`MOQCAST_MULTICAST_GROUP`) is exactly index 0;
647
671
  * mixing it with explicit `_0_` keys is rejected as ambiguous. Indices
@@ -689,9 +713,9 @@ export function multicastFromEnv(
689
713
  ...(hasCatalogAmt
690
714
  ? {
691
715
  amtFallback: {
692
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
693
- // the catalog is, by definition, not discovered.
694
- discovery: (amtDiscovery ?? "manual") as AmtDiscovery,
716
+ // No default: an omitted discovery with a relay hostname is
717
+ // "dns" (draft-ramadan-moq-multicast-01 4.2.1).
718
+ ...(amtDiscovery ? { discovery: amtDiscovery as AmtDiscovery } : {}),
695
719
  ...(amtRelayDns ? { relayDns: amtRelayDns } : {}),
696
720
  },
697
721
  }
@@ -757,7 +781,7 @@ function readEndpointAt(env: Record<string, string | undefined>, idx: number): M
757
781
  const relay = lookup("RELAY");
758
782
 
759
783
  return {
760
- protocol: lookup("PROTOCOL") as MulticastProtocol,
784
+ protocol: lookup("PROTOCOL") as MulticastInputProtocol,
761
785
  groupAddress: lookup("GROUP") ?? "",
762
786
  port,
763
787
  tracks,