@blockcast/mmt-container 0.4.0-main.94b7ef7dcd8d → 0.4.0-main.9d97fa55ba69

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 (157) hide show
  1. package/README.md +15 -11
  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 +704 -302
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +57 -29
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +266 -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.js +0 -10
  14. package/dist/catalog-fec-params.js.map +3 -3
  15. package/dist/catalog-network-source.d.ts +24 -2
  16. package/dist/catalog-network-source.d.ts.map +1 -1
  17. package/dist/catalog-network-source.js +21 -1
  18. package/dist/catalog-network-source.js.map +2 -2
  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 +16 -2
  24. package/dist/delivery-catalog.js.map +2 -2
  25. package/dist/fec-manager.d.ts +36 -1
  26. package/dist/fec-manager.d.ts.map +1 -1
  27. package/dist/fec-manager.js +161 -23
  28. package/dist/fec-manager.js.map +3 -3
  29. package/dist/fec-state.js.map +1 -1
  30. package/dist/fec-worker-setup.js.map +1 -1
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -0
  34. package/dist/index.js.map +2 -2
  35. package/dist/iso-block-locator.d.ts +29 -0
  36. package/dist/iso-block-locator.d.ts.map +1 -1
  37. package/dist/iso-block-locator.js +97 -17
  38. package/dist/iso-block-locator.js.map +3 -3
  39. package/dist/manifest-auth-plan.d.ts +26 -25
  40. package/dist/manifest-auth-plan.d.ts.map +1 -1
  41. package/dist/manifest-auth-plan.js +331 -1171
  42. package/dist/manifest-auth-plan.js.map +4 -4
  43. package/dist/mfu-reassembler.js.map +1 -1
  44. package/dist/mmtp-container-parser.js.map +1 -1
  45. package/dist/mmtp-container-parser.no-modules.js +457 -266
  46. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  47. package/dist/mmtp-decode-pipeline.js.map +1 -1
  48. package/dist/mmtp-fec-session.d.ts.map +1 -1
  49. package/dist/mmtp-fec-session.js +3 -1
  50. package/dist/mmtp-fec-session.js.map +2 -2
  51. package/dist/mmtp-router.d.ts +14 -1
  52. package/dist/mmtp-router.d.ts.map +1 -1
  53. package/dist/mmtp-router.js +11 -0
  54. package/dist/mmtp-router.js.map +2 -2
  55. package/dist/multicast-auth-catalog.d.ts +86 -92
  56. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  57. package/dist/multicast-auth-catalog.js +347 -132
  58. package/dist/multicast-auth-catalog.js.map +4 -4
  59. package/dist/multicast-input.d.ts +28 -6
  60. package/dist/multicast-input.d.ts.map +1 -1
  61. package/dist/multicast-input.js +290 -28
  62. package/dist/multicast-input.js.map +3 -3
  63. package/dist/multicast-manager.d.ts +19 -3
  64. package/dist/multicast-manager.d.ts.map +1 -1
  65. package/dist/multicast-manager.js +212 -44
  66. package/dist/multicast-manager.js.map +4 -4
  67. package/dist/multicast-transport.d.ts +6 -0
  68. package/dist/multicast-transport.d.ts.map +1 -1
  69. package/dist/multicast-transport.js +18 -3
  70. package/dist/multicast-transport.js.map +2 -2
  71. package/dist/multicast-unwrap.js.map +1 -1
  72. package/dist/no-modules.d.ts +1 -1
  73. package/dist/no-modules.d.ts.map +1 -1
  74. package/dist/no-modules.js +457 -266
  75. package/dist/no-modules.js.map +4 -4
  76. package/dist/phase14-catalog-override.d.ts +1 -1
  77. package/dist/phase14-catalog-override.d.ts.map +1 -1
  78. package/dist/phase14-catalog-override.js +2 -2
  79. package/dist/phase14-catalog-override.js.map +2 -2
  80. package/dist/repair-fetch.d.ts +58 -5
  81. package/dist/repair-fetch.d.ts.map +1 -1
  82. package/dist/repair-fetch.js +122 -22
  83. package/dist/repair-fetch.js.map +3 -3
  84. package/dist/repair-layers.js.map +1 -1
  85. package/dist/signaling.js.map +1 -1
  86. package/dist/source-auth.js +2710 -7
  87. package/dist/source-auth.js.map +4 -4
  88. package/dist/switching-set-alignment.d.ts +1 -1
  89. package/dist/switching-set-alignment.js.map +1 -1
  90. package/dist/timestamp-codec.js.map +1 -1
  91. package/dist/wasm-mfu-reassembler.js.map +1 -1
  92. package/dist/wasm-mmtp-container-parser.js.map +1 -1
  93. package/package.json +6 -5
  94. package/schemas/catalog.schema.json +113 -36
  95. package/src/align.ts +52 -21
  96. package/src/carp-catalog.ts +106 -48
  97. package/src/catalog-fec-params.ts +1 -1
  98. package/src/catalog-network-source.ts +45 -2
  99. package/src/catalog-validator.ts +4 -11
  100. package/src/fec-manager.ts +99 -14
  101. package/src/index.ts +7 -2
  102. package/src/iso-block-locator.ts +97 -6
  103. package/src/manifest-auth-plan.ts +39 -91
  104. package/src/mmtp-fec-session.ts +7 -1
  105. package/src/mmtp-router.ts +24 -0
  106. package/src/multicast-auth-catalog.ts +131 -238
  107. package/src/multicast-input.ts +119 -61
  108. package/src/multicast-manager.ts +35 -12
  109. package/src/multicast-transport.ts +3 -0
  110. package/src/no-modules.ts +1 -1
  111. package/src/phase14-catalog-override.ts +3 -3
  112. package/src/repair-fetch.ts +204 -25
  113. package/src/switching-set-alignment.ts +1 -1
  114. package/test-vectors/align.json +108 -32
  115. package/test-vectors/bc-provenance-v2.json +1526 -0
  116. package/test-vectors/catalog/README.md +47 -3
  117. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  118. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  119. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  120. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  121. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  122. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  123. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  124. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  125. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  126. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  127. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  128. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  129. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  130. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  131. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-out-of-range.json +56 -0
  132. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  133. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  134. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  135. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  136. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  137. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  138. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  139. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  140. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  141. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  142. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  143. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  144. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  145. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  146. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  147. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  148. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  149. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  150. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  151. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  152. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  153. package/test-vectors/catalog/section-codes.json +21 -1
  154. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  155. package/test-vectors/catalog-validation.json +3 -2
  156. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  157. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
@@ -1025,6 +1025,254 @@ function catalogFecDeclaresUnconfigurableInstance(fec) {
1025
1025
  return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
1026
1026
  }
1027
1027
 
1028
+ // ../mmt-base/dist/multicast-catalog.js
1029
+ var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
1030
+ var UINT32_MAX = 4294967295;
1031
+ var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
1032
+ var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
1033
+ var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
1034
+ "manifestPort",
1035
+ "streamId",
1036
+ "senderAddress",
1037
+ "maxAuthDelayMs",
1038
+ "manifestTimerMs",
1039
+ "manifestTrack"
1040
+ ]);
1041
+ function isObject(value) {
1042
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1043
+ }
1044
+ function isNonEmptyString(value) {
1045
+ return typeof value === "string" && value.trim().length > 0;
1046
+ }
1047
+ function isIntegerIn(value, min, max) {
1048
+ return Number.isSafeInteger(value) && value >= min && value <= max;
1049
+ }
1050
+ function multicastEndpointSource(endpoint) {
1051
+ if (!isObject(endpoint))
1052
+ return void 0;
1053
+ const sourceAddress = endpoint["sourceAddress"];
1054
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
1055
+ return void 0;
1056
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
1057
+ const protocol = endpoint["protocol"];
1058
+ if (protocol !== void 0 && protocol !== mode)
1059
+ return void 0;
1060
+ const auth = endpoint["auth"];
1061
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
1062
+ if (mode === "ssm")
1063
+ return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
1064
+ if (auth === void 0)
1065
+ return { mode };
1066
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
1067
+ }
1068
+ function authIssues(auth) {
1069
+ const base = "$.multicast.auth";
1070
+ const issue = (path, message) => [
1071
+ { code: "multicast_auth", path: `${base}${path}`, message }
1072
+ ];
1073
+ if (!isObject(auth))
1074
+ return issue("", "auth must be an object");
1075
+ const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
1076
+ if (unknown.length > 0) {
1077
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
1078
+ }
1079
+ if (auth["scheme"] !== "bc-provenance")
1080
+ return issue(".scheme", 'scheme must be "bc-provenance"');
1081
+ if (auth["version"] !== 2)
1082
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
1083
+ if (auth["sig"] !== "ed25519")
1084
+ return issue(".sig", 'sig must be "ed25519"');
1085
+ const keys = auth["keys"];
1086
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
1087
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
1088
+ }
1089
+ const kids = /* @__PURE__ */ new Set();
1090
+ const firstEpochs = /* @__PURE__ */ new Set();
1091
+ for (let index = 0; index < keys.length; index++) {
1092
+ const key = keys[index];
1093
+ const at = `.keys[${index}]`;
1094
+ if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
1095
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
1096
+ }
1097
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
1098
+ return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
1099
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
1100
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
1101
+ }
1102
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
1103
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
1104
+ }
1105
+ if (kids.has(key["kid"]))
1106
+ return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
1107
+ if (firstEpochs.has(key["firstEpoch"])) {
1108
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
1109
+ }
1110
+ kids.add(key["kid"]);
1111
+ firstEpochs.add(key["firstEpoch"]);
1112
+ }
1113
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
1114
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
1115
+ }
1116
+ return [];
1117
+ }
1118
+ function endpointAuthIssue(endpoint, mode, at) {
1119
+ const auth = endpoint["auth"];
1120
+ if (!isObject(auth))
1121
+ return { path: `${at}.auth`, message: "auth must be an object" };
1122
+ const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
1123
+ if (unknown.length > 0)
1124
+ return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
1125
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
1126
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
1127
+ }
1128
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
1129
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
1130
+ }
1131
+ if (mode === "ssm" && auth["senderAddress"] !== void 0) {
1132
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
1133
+ }
1134
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
1135
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
1136
+ }
1137
+ if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
1138
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
1139
+ }
1140
+ if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
1141
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
1142
+ }
1143
+ if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
1144
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
1145
+ }
1146
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
1147
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
1148
+ }
1149
+ return void 0;
1150
+ }
1151
+ var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
1152
+ function multicastCatalogIssues(catalog, options = {}) {
1153
+ if (!isObject(catalog))
1154
+ return [];
1155
+ const issues = [];
1156
+ if ("multicast.auth" in catalog) {
1157
+ issues.push({
1158
+ code: "multicast_auth",
1159
+ path: '$["multicast.auth"]',
1160
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
1161
+ });
1162
+ }
1163
+ const multicast = catalog["multicast"];
1164
+ if (!isObject(multicast))
1165
+ return issues;
1166
+ const protectedCatalog = multicast["auth"] !== void 0;
1167
+ if (protectedCatalog)
1168
+ issues.push(...authIssues(multicast["auth"]));
1169
+ const endpoints = multicast["endpoints"];
1170
+ if (!Array.isArray(endpoints))
1171
+ return issues;
1172
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
1173
+ const namespaceOf = /* @__PURE__ */ new Map();
1174
+ for (const track of tracks) {
1175
+ if (isObject(track) && typeof track["name"] === "string")
1176
+ namespaceOf.set(track["name"], track["namespace"]);
1177
+ }
1178
+ const tagged = catalog[CATALOG_NAMESPACE];
1179
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
1180
+ const sources = [];
1181
+ for (let index = 0; index < endpoints.length; index++) {
1182
+ const endpoint = endpoints[index];
1183
+ const at = `$.multicast.endpoints[${index}]`;
1184
+ const fail = (code, path, message) => {
1185
+ issues.push({ code, path, message, endpointIndex: index });
1186
+ };
1187
+ sources.push(void 0);
1188
+ if (!isObject(endpoint)) {
1189
+ fail("multicast_endpoint", at, "endpoint must be an object");
1190
+ continue;
1191
+ }
1192
+ const protocol = endpoint["protocol"];
1193
+ if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
1194
+ fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -01 4.2)`);
1195
+ continue;
1196
+ }
1197
+ const hasAuth = endpoint["auth"] !== void 0;
1198
+ if (protectedCatalog !== hasAuth) {
1199
+ fail("multicast_endpoint_auth", `${at}.auth`, protectedCatalog ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint" : "auth names no key without multicast.auth; a receiver ignores this endpoint");
1200
+ continue;
1201
+ }
1202
+ const sourceAddress = endpoint["sourceAddress"];
1203
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
1204
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
1205
+ continue;
1206
+ }
1207
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
1208
+ if (protocol !== void 0 && protocol !== mode) {
1209
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
1210
+ continue;
1211
+ }
1212
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
1213
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
1214
+ continue;
1215
+ }
1216
+ if (hasAuth) {
1217
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
1218
+ if (authIssue) {
1219
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
1220
+ continue;
1221
+ }
1222
+ }
1223
+ sources[index] = multicastEndpointSource(endpoint);
1224
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
1225
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
1226
+ const ref = refs[refIndex];
1227
+ const name = isObject(ref) ? ref["name"] : ref;
1228
+ if (typeof name !== "string")
1229
+ continue;
1230
+ const namespace = namespaceOf.get(name);
1231
+ if (typeof namespace !== "string")
1232
+ continue;
1233
+ referenceNamespace ??= namespace;
1234
+ if (namespace !== referenceNamespace) {
1235
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
1236
+ }
1237
+ }
1238
+ }
1239
+ const tupleOf = (index) => {
1240
+ const endpoint = endpoints[index];
1241
+ const auth = endpoint["auth"];
1242
+ return {
1243
+ sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
1244
+ port: endpoint["port"],
1245
+ manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
1246
+ };
1247
+ };
1248
+ for (let index = 0; index < endpoints.length; index++) {
1249
+ if (!sources[index])
1250
+ continue;
1251
+ const own = tupleOf(index);
1252
+ const at = `$.multicast.endpoints[${index}]`;
1253
+ if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
1254
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
1255
+ continue;
1256
+ }
1257
+ for (let other = 0; other < endpoints.length; other++) {
1258
+ if (other === index || !sources[other])
1259
+ continue;
1260
+ const peer = tupleOf(other);
1261
+ if (peer.sg !== own.sg)
1262
+ continue;
1263
+ if (peer.port === own.port) {
1264
+ issues.push({ code: "multicast_endpoint", path: `${at}.port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
1265
+ break;
1266
+ }
1267
+ if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
1268
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: `manifestPort is a port or manifestPort of endpoint ${other} on the same (S, G)`, endpointIndex: index });
1269
+ break;
1270
+ }
1271
+ }
1272
+ }
1273
+ return issues;
1274
+ }
1275
+
1028
1276
  // src/mfu-reassembler.ts
1029
1277
  function fragmentProvenance(fragment) {
1030
1278
  if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
@@ -6026,197 +6274,6 @@ if (void 0) {
6026
6274
  });
6027
6275
  }
6028
6276
 
6029
- // src/multicast-auth-catalog.ts
6030
- var RAW_ED25519_KEY_LENGTH = 32;
6031
- var SOURCE_AUTH_SCOPE_LENGTH = 32;
6032
- var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
6033
- function encodeBase64Url(bytes) {
6034
- let output = "";
6035
- for (let i = 0; i < bytes.length; i += 3) {
6036
- const b0 = bytes[i];
6037
- const b1 = bytes[i + 1];
6038
- const b2 = bytes[i + 2];
6039
- output += BASE64URL_ALPHABET[b0 >> 2];
6040
- output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
6041
- if (b1 === void 0) break;
6042
- output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
6043
- if (b2 === void 0) break;
6044
- output += BASE64URL_ALPHABET[b2 & 63];
6045
- }
6046
- return output;
6047
- }
6048
- var BASE64URL_DECODE_TABLE = (() => {
6049
- const table = new Int8Array(128).fill(-1);
6050
- for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
6051
- table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
6052
- }
6053
- return table;
6054
- })();
6055
- function decodeBase64Url(text) {
6056
- if (text.length % 4 === 1) {
6057
- throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
6058
- }
6059
- const bytes = [];
6060
- let buffer = 0;
6061
- let bits = 0;
6062
- for (let i = 0; i < text.length; i++) {
6063
- const code = text.charCodeAt(i);
6064
- const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
6065
- if (value === void 0 || value < 0) {
6066
- throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
6067
- }
6068
- buffer = buffer << 6 | value;
6069
- bits += 6;
6070
- if (bits >= 8) {
6071
- bits -= 8;
6072
- bytes.push(buffer >> bits & 255);
6073
- }
6074
- }
6075
- const decoded = Uint8Array.from(bytes);
6076
- if (encodeBase64Url(decoded) !== text) {
6077
- throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
6078
- }
6079
- return decoded;
6080
- }
6081
- function decodeAuthScope(authScope) {
6082
- const bytes = decodeBase64Url(authScope);
6083
- if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
6084
- throw new Error(
6085
- `[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
6086
- );
6087
- }
6088
- return bytes;
6089
- }
6090
- function decodeEd25519PublicKey(publicKey) {
6091
- const bytes = decodeBase64Url(publicKey);
6092
- if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
6093
- throw new Error(
6094
- `[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
6095
- );
6096
- }
6097
- return bytes;
6098
- }
6099
- function isNonEmptyString(value) {
6100
- return typeof value === "string" && value.length > 0;
6101
- }
6102
- function isValidAuthScopeField(value) {
6103
- if (!isNonEmptyString(value)) return false;
6104
- try {
6105
- decodeAuthScope(value);
6106
- return true;
6107
- } catch {
6108
- return false;
6109
- }
6110
- }
6111
- function isValidPublicKeyField(value) {
6112
- if (!isNonEmptyString(value)) return false;
6113
- try {
6114
- decodeEd25519PublicKey(value);
6115
- return true;
6116
- } catch {
6117
- return false;
6118
- }
6119
- }
6120
- function hasOnlyKeys(object2, allowed) {
6121
- const allowedKeys = new Set(allowed);
6122
- return Object.keys(object2).every((key) => allowedKeys.has(key));
6123
- }
6124
- function isMulticastAuthTrackConfig(obj) {
6125
- if (typeof obj !== "object" || obj === null) return false;
6126
- const o = obj;
6127
- return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
6128
- }
6129
- var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
6130
- var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
6131
- function hasUniqueMulticastAuthTrackBindings(tracks) {
6132
- const bindings = tracks.flatMap((track) => {
6133
- if (typeof track !== "object" || track === null) return [];
6134
- const value = track;
6135
- if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
6136
- return [];
6137
- }
6138
- return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
6139
- });
6140
- return new Set(bindings).size === bindings.length;
6141
- }
6142
- function isMulticastAuthConfig(obj) {
6143
- if (typeof obj !== "object" || obj === null) return false;
6144
- const o = obj;
6145
- if (o["scheme"] !== "bc-provenance") return false;
6146
- if (o["hash"] !== "blake3") return false;
6147
- if (o["sig"] !== "ed25519") return false;
6148
- if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
6149
- if (!isValidPublicKeyField(o["publicKey"])) return false;
6150
- if (!isNonEmptyString(o["keyId"])) return false;
6151
- if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
6152
- if (o["previousKey"] === o["publicKey"]) return false;
6153
- if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
6154
- if (o["enforcement"] !== void 0) {
6155
- if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
6156
- }
6157
- if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
6158
- const tracks = o["tracks"];
6159
- if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
6160
- const typedTracks = tracks;
6161
- const scopes = typedTracks.map((t) => t.authScope);
6162
- if (new Set(scopes).size !== scopes.length) return false;
6163
- if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
6164
- const manifestTracks = typedTracks.map((t) => t.manifestTrack);
6165
- if (new Set(manifestTracks).size !== manifestTracks.length) return false;
6166
- return true;
6167
- }
6168
- function resolveMulticastAuthMode(playerMode, auth) {
6169
- if (playerMode !== void 0) return playerMode;
6170
- if (auth === void 0) return "off";
6171
- return auth.enforcement ?? "shadow";
6172
- }
6173
- function resolveMulticastAuthCatalog(catalog, playerMode) {
6174
- if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
6175
- throw new Error("[multicast-auth-catalog] catalog must be an object");
6176
- }
6177
- const root = catalog;
6178
- const rawAuth = root["multicast.auth"];
6179
- if (rawAuth === void 0) {
6180
- if (playerMode === "enforce") {
6181
- throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
6182
- }
6183
- return void 0;
6184
- }
6185
- if (!isMulticastAuthConfig(rawAuth)) {
6186
- throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
6187
- }
6188
- const rawTracks = root["tracks"];
6189
- if (!Array.isArray(rawTracks)) {
6190
- throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
6191
- }
6192
- const catalogTrackNames = new Set(
6193
- rawTracks.flatMap(
6194
- (track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
6195
- )
6196
- );
6197
- for (const track of rawAuth.tracks) {
6198
- if (!catalogTrackNames.has(track.mediaTrack)) {
6199
- throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
6200
- }
6201
- if (!catalogTrackNames.has(track.manifestTrack)) {
6202
- throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
6203
- }
6204
- }
6205
- return {
6206
- keyId: rawAuth.keyId,
6207
- acceptedPublicKeys: [
6208
- decodeEd25519PublicKey(rawAuth.publicKey),
6209
- ...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
6210
- ],
6211
- mode: resolveMulticastAuthMode(playerMode, rawAuth),
6212
- compaction: rawAuth.compaction,
6213
- tracks: rawAuth.tracks.map((track) => ({
6214
- ...track,
6215
- authScope: decodeAuthScope(track.authScope)
6216
- }))
6217
- };
6218
- }
6219
-
6220
6277
  // src/repair-layers.ts
6221
6278
  var REPAIR_PRIORITY_MIN = 192;
6222
6279
  var REPAIR_PRIORITY_MAX = 255;
@@ -6575,8 +6632,7 @@ function isMulticastTrackObject(obj) {
6575
6632
  function isMulticastEndpoint(obj) {
6576
6633
  if (typeof obj !== "object" || obj === null) return false;
6577
6634
  const o = obj;
6578
- const protocol = o["protocol"] ?? (typeof o["sourceAddress"] === "string" && o["sourceAddress"].length > 0 ? "ssm" : void 0);
6579
- return typeof protocol === "string" && (protocol === "ssm" || protocol === "asm" || protocol === "amt" || protocol === "atsc3") && typeof o["groupAddress"] === "string" && o["groupAddress"].length > 0 && typeof o["port"] === "number" && o["port"] > 0 && o["port"] <= 65535 && Array.isArray(o["tracks"]) && o["tracks"].every((t) => typeof t === "string" || isMulticastTrackObject(t));
6635
+ return multicastEndpointSource(o) !== void 0 && typeof o["groupAddress"] === "string" && o["groupAddress"].length > 0 && typeof o["port"] === "number" && o["port"] > 0 && o["port"] <= 65535 && Array.isArray(o["tracks"]) && o["tracks"].every((t) => typeof t === "string" || isMulticastTrackObject(t));
6580
6636
  }
6581
6637
  function isMulticastCatalogConfig(obj) {
6582
6638
  if (typeof obj !== "object" || obj === null) return false;
@@ -6680,7 +6736,7 @@ var CmsfCatalogValidationError = class extends Error {
6680
6736
  function catalogError(code, path, message) {
6681
6737
  throw new CmsfCatalogValidationError(code, path, message);
6682
6738
  }
6683
- function validateCmsfMmtpCatalog(value) {
6739
+ function validateCmsfMmtpCatalog(value, options = {}) {
6684
6740
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
6685
6741
  catalogError("catalog_object", "$", "catalog must be an object");
6686
6742
  }
@@ -6701,6 +6757,22 @@ function validateCmsfMmtpCatalog(value) {
6701
6757
  "commonTrackFields is retired; every track carries its own fields"
6702
6758
  );
6703
6759
  }
6760
+ const initDataList = catalog["initDataList"];
6761
+ if (initDataList !== void 0) {
6762
+ if (!Array.isArray(initDataList)) {
6763
+ catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
6764
+ }
6765
+ initDataList.forEach((entry, i) => {
6766
+ const e = entry;
6767
+ const entryPath = `$.initDataList[${i}]`;
6768
+ if (typeof e !== "object" || e === null || Array.isArray(e) || typeof e["id"] !== "string" || e["id"].length === 0 || typeof e["type"] !== "string" || e["type"].length === 0) {
6769
+ catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
6770
+ }
6771
+ if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
6772
+ catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
6773
+ }
6774
+ });
6775
+ }
6704
6776
  const tracks = catalog["tracks"];
6705
6777
  const trackRecords = [];
6706
6778
  const positiveInteger3 = (input) => Number.isSafeInteger(input) && input > 0;
@@ -6752,6 +6824,14 @@ function validateCmsfMmtpCatalog(value) {
6752
6824
  if (keyframeIntervalMs !== void 0 && !positiveNumber2(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger3(keyframeIntervalTicks)) {
6753
6825
  catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
6754
6826
  }
6827
+ const anchor = track["presentationAnchorTicks"];
6828
+ if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
6829
+ catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
6830
+ }
6831
+ const initRef = track["initRef"];
6832
+ if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
6833
+ catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
6834
+ }
6755
6835
  if (packaging === "fec-repair") {
6756
6836
  rejectRepairTrackGeometry(path, track, catalogError);
6757
6837
  validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
@@ -6759,9 +6839,8 @@ function validateCmsfMmtpCatalog(value) {
6759
6839
  rejectRepairFieldsOnMediaTrack(path, track, catalogError);
6760
6840
  }
6761
6841
  if (packaging === "mmtp") {
6762
- const mmtpMode = track["mmtpMode"];
6763
- if (mmtpMode !== "mpu" && mmtpMode !== "mfu") {
6764
- catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
6842
+ if (track["mmtpMode"] !== "mfu") {
6843
+ catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
6765
6844
  }
6766
6845
  if (!positiveInteger3(timescale)) {
6767
6846
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
@@ -6928,15 +7007,8 @@ function validateCmsfMmtpCatalog(value) {
6928
7007
  }
6929
7008
  }
6930
7009
  }
6931
- try {
6932
- resolveMulticastAuthCatalog(catalog);
6933
- } catch (error) {
6934
- catalogError(
6935
- "multicast_auth",
6936
- "$.multicast.auth",
6937
- error instanceof Error ? error.message : "invalid multicast.auth v2 block"
6938
- );
6939
- }
7010
+ const [multicastIssue] = multicastCatalogIssues(catalog, options);
7011
+ if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
6940
7012
  validateArchive(catalog);
6941
7013
  return catalog;
6942
7014
  }
@@ -6962,7 +7034,7 @@ function resolveGroupDurationTicks(timing, timescale) {
6962
7034
  const product = timing.groupDurationMs * timescale;
6963
7035
  if (product % 1e3 !== 0) {
6964
7036
  throw new Error(
6965
- `[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-00 \xA74.4.4)`
7037
+ `[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-01 \xA74.4.2)`
6966
7038
  );
6967
7039
  }
6968
7040
  return product / 1e3;
@@ -7113,8 +7185,8 @@ var AdaptiveBitrateController = class {
7113
7185
  /**
7114
7186
  * Update FEC statistics for ABR decisions
7115
7187
  *
7116
- * Per draft-ramadan-moq-fec-00, ABR should use the effective loss rate
7117
- * (after FEC recovery) rather than raw transport loss rate.
7188
+ * ABR uses the effective loss rate (after FEC recovery) rather than the
7189
+ * raw transport loss rate.
7118
7190
  *
7119
7191
  * @param stats - FEC statistics from the FEC decoder
7120
7192
  */
@@ -7466,6 +7538,20 @@ function toWindowMulticastSubscribeConfig(input) {
7466
7538
  consume: "bytes",
7467
7539
  ...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
7468
7540
  };
7541
+ if (input.atsc3) {
7542
+ const { frequency, plpId, serviceId } = input.atsc3;
7543
+ if (!Number.isInteger(frequency) || frequency < 1) {
7544
+ throw new TypeError(`ATSC3 tuning requires a positive integer frequency in kHz, got ${String(frequency)}`);
7545
+ }
7546
+ return {
7547
+ ...base,
7548
+ origin: "tuner",
7549
+ standard: "atsc3",
7550
+ frequency,
7551
+ ...plpId !== void 0 ? { plpId } : {},
7552
+ ...serviceId !== void 0 ? { serviceId } : {}
7553
+ };
7554
+ }
7469
7555
  const relay = input.amtRelay?.trim();
7470
7556
  const driad = !relay && input.amtDiscovery === "driad";
7471
7557
  const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
@@ -8711,8 +8797,7 @@ function multicastFromConfig(input) {
8711
8797
  );
8712
8798
  }
8713
8799
  }
8714
- const seenTuples = /* @__PURE__ */ new Set();
8715
- const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx, seenTuples));
8800
+ const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx));
8716
8801
  const out = { endpoints };
8717
8802
  const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
8718
8803
  networkSource.forEach(validateNetworkSourceEntry);
@@ -8746,9 +8831,20 @@ function multicastFromConfig(input) {
8746
8831
  throw new MulticastInputError(
8747
8832
  ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
8748
8833
  idx,
8749
- `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying frequency, plpId, serviceId and slsUri \u2014 an ATSC3 endpoint is not tunable without them" : "")
8834
+ `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying at least its frequency (kHz) \u2014 an ATSC3 endpoint is not tunable without it" : "")
8750
8835
  );
8751
8836
  });
8837
+ input.endpoints.forEach((ep, idx) => {
8838
+ if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
8839
+ endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
8840
+ });
8841
+ if (input.auth !== void 0) out.auth = input.auth;
8842
+ const [issue] = multicastCatalogIssues({ multicast: out });
8843
+ if (issue) {
8844
+ const kind = issue.code === "multicast_auth" ? "invalid_multicast_auth" : issue.code === "multicast_endpoint_auth" ? "invalid_endpoint_auth" : issue.path.endsWith(".port") ? "duplicate_endpoint_tuple" : "protocol_source_mismatch";
8845
+ const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
8846
+ throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
8847
+ }
8752
8848
  if (input.enabled !== void 0) out.enabled = input.enabled;
8753
8849
  if (input.version !== void 0) out.version = input.version;
8754
8850
  if (input.validUntil !== void 0) out.validUntil = input.validUntil;
@@ -8760,10 +8856,10 @@ function resolveNetworkSource(input) {
8760
8856
  }
8761
8857
  const relayDns = input.amtFallback?.relayDns?.trim();
8762
8858
  const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
8763
- const discovery = input.amtFallback?.discovery ?? (relay ? "manual" : void 0);
8764
- if (discovery === void 0) return { entries: [], relayFrom: null };
8859
+ const discovery = input.amtFallback?.discovery;
8860
+ if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
8765
8861
  return {
8766
- entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
8862
+ entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
8767
8863
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
8768
8864
  };
8769
8865
  }
@@ -8776,8 +8872,11 @@ function validateNetworkSourceEntry(s, i) {
8776
8872
  const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
8777
8873
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
8778
8874
  if (s.type === "amt") {
8779
- if (s.discovery !== "driad" && s.discovery !== "manual") {
8780
- throw err("invalid_amt_discovery", `discovery must be "driad" or "manual"; got ${JSON.stringify(s.discovery)}`);
8875
+ if (s.discovery !== void 0 && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
8876
+ throw err(
8877
+ "invalid_amt_discovery",
8878
+ `discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`
8879
+ );
8781
8880
  }
8782
8881
  if (s.relay !== void 0) {
8783
8882
  const relay = typeof s.relay === "string" ? s.relay.trim() : "";
@@ -8786,8 +8885,8 @@ function validateNetworkSourceEntry(s, i) {
8786
8885
  }
8787
8886
  s.relay = relay;
8788
8887
  }
8789
- if (s.discovery === "manual" && s.relay === void 0) {
8790
- throw err("amt_requires_relay", `discovery="manual" requires a relay ("driad" resolves it at runtime)`);
8888
+ if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === void 0) {
8889
+ throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
8791
8890
  }
8792
8891
  if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
8793
8892
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -8796,13 +8895,15 @@ function validateNetworkSourceEntry(s, i) {
8796
8895
  }
8797
8896
  const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
8798
8897
  if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
8799
- throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
8898
+ throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
8899
+ }
8900
+ if (s.plpId !== void 0 && !inRange(s.plpId, 0, 63)) {
8901
+ throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
8800
8902
  }
8801
- if (!inRange(s.plpId, 0, 63)) throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
8802
- if (!inRange(s.serviceId, 0, 65535)) {
8903
+ if (s.serviceId !== void 0 && !inRange(s.serviceId, 0, 65535)) {
8803
8904
  throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
8804
8905
  }
8805
- if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
8906
+ if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
8806
8907
  throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
8807
8908
  }
8808
8909
  }
@@ -8814,7 +8915,7 @@ function isAbsoluteUri(value) {
8814
8915
  return false;
8815
8916
  }
8816
8917
  }
8817
- function validateEndpoint2(ep, idx, seenTuples) {
8918
+ function validateEndpoint2(ep, idx) {
8818
8919
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
8819
8920
  throw new MulticastInputError(
8820
8921
  "ssm_requires_source",
@@ -8822,6 +8923,13 @@ function validateEndpoint2(ep, idx, seenTuples) {
8822
8923
  `endpoint[${idx}] protocol=ssm requires sourceAddress`
8823
8924
  );
8824
8925
  }
8926
+ if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
8927
+ throw new MulticastInputError(
8928
+ "protocol_source_mismatch",
8929
+ idx,
8930
+ `endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
8931
+ );
8932
+ }
8825
8933
  if (!isMulticastGroupAddress(ep.groupAddress)) {
8826
8934
  throw new MulticastInputError(
8827
8935
  "invalid_group_address",
@@ -8881,23 +8989,15 @@ function validateEndpoint2(ep, idx, seenTuples) {
8881
8989
  `endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
8882
8990
  );
8883
8991
  }
8884
- const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
8885
- if (seenTuples.has(tupleKey)) {
8886
- throw new MulticastInputError(
8887
- "duplicate_endpoint_tuple",
8888
- idx,
8889
- `endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
8890
- );
8891
- }
8892
- seenTuples.add(tupleKey);
8893
8992
  const out = {
8894
- protocol: ep.protocol,
8993
+ protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
8895
8994
  groupAddress: ep.groupAddress,
8896
8995
  port: ep.port,
8897
8996
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
8898
8997
  };
8899
8998
  if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
8900
8999
  if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
9000
+ if (ep.auth !== void 0) out.auth = { ...ep.auth };
8901
9001
  return out;
8902
9002
  }
8903
9003
  function isMulticastGroupAddress(addr) {
@@ -8940,9 +9040,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
8940
9040
  endpoints,
8941
9041
  ...hasCatalogAmt ? {
8942
9042
  amtFallback: {
8943
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
8944
- // the catalog is, by definition, not discovered.
8945
- discovery: amtDiscovery ?? "manual",
9043
+ // No default: an omitted discovery with a relay hostname is
9044
+ // "dns" (draft-ramadan-moq-multicast-01 4.2.1).
9045
+ ...amtDiscovery ? { discovery: amtDiscovery } : {},
8946
9046
  ...amtRelayDns ? { relayDns: amtRelayDns } : {}
8947
9047
  }
8948
9048
  } : {}
@@ -9110,7 +9210,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
9110
9210
  if (ot.role !== void 0 && existing.role === void 0) existing.role = ot.role;
9111
9211
  if (existing.packaging === "mmtp") {
9112
9212
  const mode = existing.mmtpMode ?? ot.mmtpMode;
9113
- if (mode !== "mpu" && mode !== "mfu") {
9213
+ if (mode !== "mfu") {
9114
9214
  throw new Error(
9115
9215
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
9116
9216
  );
@@ -9147,7 +9247,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
9147
9247
  );
9148
9248
  }
9149
9249
  const mmtpMode = ot.mmtpMode;
9150
- if (packaging === "mmtp" && mmtpMode !== "mpu" && mmtpMode !== "mfu") {
9250
+ if (packaging === "mmtp" && mmtpMode !== "mfu") {
9151
9251
  throw new Error(
9152
9252
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
9153
9253
  );
@@ -9448,8 +9548,8 @@ function u32(v) {
9448
9548
  }
9449
9549
  var KEYFRAME_FLAGS = 33554432;
9450
9550
  var DELTA_FLAGS = 16842752;
9451
- var UINT32_MAX = 4294967295;
9452
- var MAX_TRACK_ID = UINT32_MAX - 1;
9551
+ var UINT32_MAX2 = 4294967295;
9552
+ var MAX_TRACK_ID = UINT32_MAX2 - 1;
9453
9553
  var INT32_MIN = -2147483648;
9454
9554
  var INT32_MAX = 2147483647;
9455
9555
  function assertTrackId(trackId, label) {
@@ -9458,8 +9558,8 @@ function assertTrackId(trackId, label) {
9458
9558
  }
9459
9559
  }
9460
9560
  function assertTimescale(timescale, label) {
9461
- if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX) {
9462
- throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX}, got ${timescale}`);
9561
+ if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
9562
+ throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
9463
9563
  }
9464
9564
  }
9465
9565
  function assertCompositionTimeOffsets(samples) {
@@ -12292,16 +12392,6 @@ var DeliveryGapEstimator = class {
12292
12392
 
12293
12393
  // src/iso-block-locator.ts
12294
12394
  var IsoBlockLocator = class _IsoBlockLocator {
12295
- /** Known blocks and spans, in serial order of their start. */
12296
- #blocks = [];
12297
- /** Held first-arrival sources whose block no repair has stated yet. */
12298
- #held = /* @__PURE__ */ new Map();
12299
- /** End of contiguous coverage: the SS_ID the next unknown block starts at. */
12300
- #coverageEnd;
12301
- #kMax;
12302
- #retentionBlocks;
12303
- #heldEvicted = 0;
12304
- #newest;
12305
12395
  /**
12306
12396
  * @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
12307
12397
  * @param retentionBlocks how many blocks behind the newest position the
@@ -12309,12 +12399,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
12309
12399
  * no locator exists without retention.
12310
12400
  */
12311
12401
  constructor(kMax, retentionBlocks) {
12402
+ /** Known blocks and spans, in serial order of their start. */
12403
+ this.#blocks = [];
12404
+ /** Held first-arrival sources whose block no repair has stated yet. */
12405
+ this.#held = /* @__PURE__ */ new Map();
12406
+ this.#heldEvicted = 0;
12407
+ /** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
12408
+ this.#holes = [];
12409
+ /**
12410
+ * Keep a gap that is missing a source as a pending hole rather than a span,
12411
+ * so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
12412
+ * its blocks. Set only while a range repair scheduler is wired; its owner
12413
+ * must close every hole it is told about (`closeHolesWithin`).
12414
+ */
12415
+ this.deferIncompleteGaps = false;
12312
12416
  if (!Number.isSafeInteger(kMax) || kMax <= 0) {
12313
12417
  throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
12314
12418
  }
12315
12419
  this.#kMax = kMax;
12316
12420
  this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
12317
12421
  }
12422
+ #blocks;
12423
+ #held;
12424
+ /** End of contiguous coverage: the SS_ID the next unknown block starts at. */
12425
+ #coverageEnd;
12426
+ #kMax;
12427
+ #retentionBlocks;
12428
+ #heldEvicted;
12429
+ #newest;
12430
+ #holes;
12318
12431
  static #checkedRetention(retentionBlocks) {
12319
12432
  if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
12320
12433
  throw new Error(
@@ -12377,6 +12490,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
12377
12490
  }
12378
12491
  return null;
12379
12492
  }
12493
+ /** Number of pending holes. */
12494
+ get holeCount() {
12495
+ return this.#holes.length;
12496
+ }
12497
+ /** The stated block (never a span) ending exactly at `end`. */
12498
+ blockEndingAt(end) {
12499
+ return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
12500
+ }
12380
12501
  /** The known block or span starting exactly at `start`. */
12381
12502
  blockAt(start) {
12382
12503
  return this.#blocks.find((block) => block.start === start);
@@ -12399,6 +12520,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
12399
12520
  coversBetween(a, b) {
12400
12521
  if (this.#coverageEnd === void 0) return false;
12401
12522
  if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
12523
+ const first = a + 1 >>> 0;
12524
+ const count = serial32Distance(a, b) - 1;
12525
+ if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
12402
12526
  return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
12403
12527
  }
12404
12528
  /**
@@ -12446,6 +12570,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
12446
12570
  }
12447
12571
  return { status: "placed", block: known, placed: [] };
12448
12572
  }
12573
+ const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
12574
+ if (pending !== void 0) {
12575
+ if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
12576
+ return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
12577
+ }
12578
+ this.#holes.splice(this.#holes.indexOf(pending), 1);
12579
+ const before = serial32Distance(pending.start, start);
12580
+ const afterStart = isoBlockEnd(start, length);
12581
+ const after = pending.length - before - length;
12582
+ if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
12583
+ if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
12584
+ const block2 = { start, length, span: false };
12585
+ const placed2 = this.#claim(block2);
12586
+ this.#blocks.push(block2);
12587
+ return { status: "placed", block: block2, placed: placed2 };
12588
+ }
12449
12589
  for (const block2 of this.#blocks) {
12450
12590
  if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
12451
12591
  return {
@@ -12455,6 +12595,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
12455
12595
  }
12456
12596
  }
12457
12597
  let span;
12598
+ let hole;
12458
12599
  if (this.#coverageEnd === void 0) {
12459
12600
  for (const ssId of this.#held.keys()) {
12460
12601
  if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
@@ -12463,21 +12604,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
12463
12604
  } else if (serial32Precedes(start, this.#coverageEnd)) {
12464
12605
  return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
12465
12606
  } else if (start !== this.#coverageEnd) {
12466
- const spanBlock = {
12467
- start: this.#coverageEnd,
12468
- length: serial32Distance(this.#coverageEnd, start),
12469
- span: true
12470
- };
12471
- span = { block: spanBlock, placed: this.#claim(spanBlock) };
12472
- this.#blocks.push(spanBlock);
12607
+ const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
12608
+ const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
12609
+ if (lostSsId !== void 0) {
12610
+ const holeBlock = { ...gap, span: false };
12611
+ this.#holes.push(holeBlock);
12612
+ hole = { block: holeBlock, lostSsId };
12613
+ } else {
12614
+ const spanBlock = { ...gap, span: true };
12615
+ span = { block: spanBlock, placed: this.#claim(spanBlock) };
12616
+ this.#blocks.push(spanBlock);
12617
+ }
12473
12618
  }
12474
12619
  const block = { start, length, span: false };
12475
12620
  const placed = this.#claim(block);
12476
12621
  this.#blocks.push(block);
12477
12622
  this.#coverageEnd = isoBlockEnd(start, length);
12478
12623
  this.retireBehind(start);
12624
+ if (hole !== void 0) return { status: "placed", block, placed, hole };
12479
12625
  return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
12480
12626
  }
12627
+ /**
12628
+ * Turn every pending hole inside `[start, start + length)` into a
12629
+ * repair-less span, claiming its held sources: its range FETCH ended, so
12630
+ * nothing more will state its blocks. Returns the spans, in SS_ID order.
12631
+ */
12632
+ closeHolesWithin(start, length) {
12633
+ const closed = [];
12634
+ for (const hole of [...this.#holes]) {
12635
+ if (!isoBlockContains(start, length, hole.start)) continue;
12636
+ this.#holes.splice(this.#holes.indexOf(hole), 1);
12637
+ const spanBlock = { start: hole.start, length: hole.length, span: true };
12638
+ closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
12639
+ this.#blocks.push(spanBlock);
12640
+ }
12641
+ return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
12642
+ }
12643
+ /** The highest SS_ID in the range no source is held for, or undefined when all are. */
12644
+ #highestMissing(start, length) {
12645
+ const steps = Math.min(length, this.#held.size + 1);
12646
+ for (let i = 1; i <= steps; i++) {
12647
+ const ssId = serial32Add(start, length - i);
12648
+ if (!this.#held.has(ssId)) return ssId;
12649
+ }
12650
+ return void 0;
12651
+ }
12481
12652
  /**
12482
12653
  * Retire every block and span whose last SS_ID, and every held source,
12483
12654
  * lies more than `retentionBlocks` blocks behind `position`, with the shared
@@ -12496,6 +12667,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
12496
12667
  this.#blocks.splice(i, 1);
12497
12668
  }
12498
12669
  }
12670
+ for (let i = this.#holes.length - 1; i >= 0; i--) {
12671
+ const hole = this.#holes[i];
12672
+ const last = serial32Add(hole.start, hole.length - 1);
12673
+ if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
12674
+ }
12499
12675
  for (const ssId of [...this.#held.keys()]) {
12500
12676
  if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
12501
12677
  }
@@ -12504,6 +12680,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
12504
12680
  /** Forget everything (publisher restart, track reset). */
12505
12681
  reset() {
12506
12682
  this.#blocks.length = 0;
12683
+ this.#holes.length = 0;
12507
12684
  this.#held.clear();
12508
12685
  this.#coverageEnd = void 0;
12509
12686
  this.#newest = void 0;
@@ -12519,6 +12696,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
12519
12696
  return placed;
12520
12697
  }
12521
12698
  };
12699
+ function isoRangesOverlap(aStart, aLength, bStart, bLength) {
12700
+ return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
12701
+ }
12522
12702
 
12523
12703
  // src/fec-state.ts
12524
12704
  var MIN_INTERLEAVE_DEPTH_MS = 1;
@@ -13273,6 +13453,7 @@ var FECManager = class _FECManager {
13273
13453
  // iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
13274
13454
  // block only once a repair symbol stated the block's (SS_Start, SSB_length).
13275
13455
  this.#isoLocators = /* @__PURE__ */ new Map();
13456
+ this.#deferIsoGaps = false;
13276
13457
  this.#isoRepairRefusedCount = 0;
13277
13458
  this.#isoSourceOversizeCount = 0;
13278
13459
  // Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
@@ -13347,6 +13528,14 @@ var FECManager = class _FECManager {
13347
13528
  this.onBlockReclassified = null;
13348
13529
  /** A video stream's classifier mode was established or changed. */
13349
13530
  this.onClassifierMode = null;
13531
+ /**
13532
+ * A repair stated a block past a gap that is missing a source and whose
13533
+ * every repair was lost: a lost SS_ID in an undelimited span
13534
+ * (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
13535
+ * receiver keeps the gap as a pending hole until `closeIsoHoles` is called
13536
+ * for it, which it must be.
13537
+ */
13538
+ this.#onUndelimitedLoss = null;
13350
13539
  /** A block every symbol of which vanished was created by SBN evidence. */
13351
13540
  this.onBlockVanished = null;
13352
13541
  /** A block reached a terminal state (completed, recovered, or failed). */
@@ -13428,6 +13617,7 @@ var FECManager = class _FECManager {
13428
13617
  #highestSbn;
13429
13618
  #sourceFrontiers;
13430
13619
  #isoLocators;
13620
+ #deferIsoGaps;
13431
13621
  #isoRepairRefusedCount;
13432
13622
  #isoSourceOversizeCount;
13433
13623
  #isoHeldEvictedCount;
@@ -13441,6 +13631,7 @@ var FECManager = class _FECManager {
13441
13631
  #workerErrorCounts;
13442
13632
  #decoderUnavailableEvents;
13443
13633
  #repairSymbolSizeMismatchCount;
13634
+ #onUndelimitedLoss;
13444
13635
  #encodeTrackName(catalogTrackName) {
13445
13636
  let encoded = this.#encodedTrackNames.get(catalogTrackName);
13446
13637
  if (encoded === void 0) {
@@ -15185,6 +15376,7 @@ var FECManager = class _FECManager {
15185
15376
  let locator = this.#isoLocators.get(streamKey);
15186
15377
  if (!locator) {
15187
15378
  locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
15379
+ locator.deferIncompleteGaps = this.#deferIsoGaps;
15188
15380
  this.#isoLocators.set(streamKey, locator);
15189
15381
  }
15190
15382
  return locator;
@@ -15281,15 +15473,61 @@ var FECManager = class _FECManager {
15281
15473
  }
15282
15474
  return placement;
15283
15475
  }
15284
- if (placement.span !== void 0) {
15285
- const key = this.#blockKey(placement.span.block.start, packetId, catalogTrackName);
15286
- if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, placement.span.block.length);
15287
- }
15288
- if (placement.span !== void 0 && placement.span.placed.length === 0) {
15289
- this.#materializeBlock(placement.span.block.start, packetId, catalogTrackName, true);
15476
+ if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
15477
+ if (placement.hole !== void 0) {
15478
+ const locator = this.#isoLocatorFor(packetId, catalogTrackName);
15479
+ const hole = placement.hole.block;
15480
+ const previous = locator.blockEndingAt(hole.start);
15481
+ const loss = {
15482
+ packetId,
15483
+ catalogTrackName,
15484
+ holeStart: hole.start,
15485
+ holeLength: hole.length,
15486
+ lostSsId: placement.hole.lostSsId,
15487
+ kMax: this.#trackConfig(packetId).k,
15488
+ ...previous === void 0 ? {} : { previousBlockStart: previous.start }
15489
+ };
15490
+ this.#onUndelimitedLoss(loss);
15290
15491
  }
15291
15492
  return placement;
15292
15493
  }
15494
+ /**
15495
+ * Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
15496
+ * `handler`, instead of a repair-less span; null restores spans. Set by the
15497
+ * range repair scheduler; applies to every stream from its next gap. The
15498
+ * handler and the deferral are one setting, so no hole is ever created with
15499
+ * nobody to close it.
15500
+ */
15501
+ setUndelimitedLossHandler(handler) {
15502
+ this.#onUndelimitedLoss = handler;
15503
+ this.#deferIsoGaps = handler !== null;
15504
+ for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
15505
+ }
15506
+ /**
15507
+ * The range repair for a hole ended: every hole still pending inside
15508
+ * `[start, start + length)` becomes a repair-less span. Returns those spans
15509
+ * with the held sources they placed, for the caller to feed (MmtpRouter).
15510
+ */
15511
+ closeIsoHoles(packetId, catalogTrackName, start, length) {
15512
+ const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
15513
+ if (locator === void 0) return [];
15514
+ const spans = locator.closeHolesWithin(start, length);
15515
+ for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
15516
+ return spans;
15517
+ }
15518
+ /**
15519
+ * A repair-less span has no repair to state its length, so it is known
15520
+ * here: its sources make it clean exactly when all of them arrived. A
15521
+ * stated block learns its SSB_length from its own repair symbol, fed after
15522
+ * its placed sources exactly as on the wire (feedRepairSymbol). A span every
15523
+ * SS_ID of which vanished resolves through its deadline like any vanished
15524
+ * block.
15525
+ */
15526
+ #openIsoSpan(span, packetId, catalogTrackName) {
15527
+ const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
15528
+ if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
15529
+ if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
15530
+ }
15293
15531
  /**
15294
15532
  * Resolution of the SS_IDs strictly between two released frames' SS_IDs on
15295
15533
  * an iso-ssbg1-v1 stream, for in-order frame release: null while a block
@@ -19846,6 +20084,17 @@ var MmtpRouter = class {
19846
20084
  this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
19847
20085
  }
19848
20086
  }
20087
+ /**
20088
+ * The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
20089
+ * §7.5): what no repair stated becomes repair-less spans, whose held sources
20090
+ * are fed exactly as a span a repair closed.
20091
+ */
20092
+ closeIsoHoles(ownerPacketId, catalogTrackName, start, length) {
20093
+ const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
20094
+ for (const span of spans) {
20095
+ this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
20096
+ }
20097
+ }
19849
20098
  /**
19850
20099
  * Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
19851
20100
  * a first-arrival source is fed once its block is known: transport
@@ -22244,7 +22493,8 @@ var MulticastTransport = class {
22244
22493
  amtRelayPort: config.amtRelayPort,
22245
22494
  amtDiscovery: config.amtDiscovery,
22246
22495
  packetIds: config.packetIds,
22247
- tracks: config.tracks
22496
+ tracks: config.tracks,
22497
+ atsc3: config.atsc3
22248
22498
  });
22249
22499
  failure = "provider-rejected";
22250
22500
  const subscription = await gateway.subscribe(subscribeConfig);
@@ -22849,6 +23099,25 @@ function catalogAmtNetworkSource(networkSource) {
22849
23099
  }
22850
23100
  return void 0;
22851
23101
  }
23102
+ function intIn(value, min, max) {
23103
+ return Number.isInteger(value) && value >= min && value <= max;
23104
+ }
23105
+ function catalogAtsc3NetworkSource(networkSource) {
23106
+ const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
23107
+ for (const raw of entries) {
23108
+ if (!raw || typeof raw !== "object") continue;
23109
+ const ns = raw;
23110
+ if (ns.type !== "atsc3" || !intIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
23111
+ const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
23112
+ return {
23113
+ frequency: ns.frequency,
23114
+ ...intIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
23115
+ ...intIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
23116
+ ...slsUri ? { slsUri } : {}
23117
+ };
23118
+ }
23119
+ return void 0;
23120
+ }
22852
23121
 
22853
23122
  // src/catalog-fec-params.ts
22854
23123
  var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
@@ -23188,8 +23457,10 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
23188
23457
  repairsSkippedRttUnmeasured: 0,
23189
23458
  repairsSkippedRttExceedsBudget: 0,
23190
23459
  repairsSkippedPresentationDelayUnavailable: 0,
23460
+ repairsSkippedRangeNoAnchor: 0,
23191
23461
  lastRepairSkip: null,
23192
23462
  keyframeRepairFetchesSent: 0,
23463
+ rangeRepairFetchesSent: 0,
23193
23464
  keyframeBudgetHolds: 0,
23194
23465
  keyframeBudgetHoldMs: 0,
23195
23466
  deltaBlocksFailed: 0,
@@ -24519,7 +24790,7 @@ var MulticastManager = class {
24519
24790
  *
24520
24791
  * D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
24521
24792
  * D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
24522
- * D-17: Builds altGroup → track-name index for getSwitchingSet().
24793
+ * D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
24523
24794
  * D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
24524
24795
  *
24525
24796
  * FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
@@ -24570,11 +24841,9 @@ var MulticastManager = class {
24570
24841
  }
24571
24842
  }
24572
24843
  const repairOwnerGroup = /* @__PURE__ */ new Map();
24573
- const repairOwnerAltGroup = /* @__PURE__ */ new Map();
24574
24844
  for (const track of catalog.tracks) {
24575
24845
  for (const repairName of repairNamesBySource.get(track.name) ?? []) {
24576
24846
  repairOwnerGroup.set(repairName, altGroupKey(track));
24577
- repairOwnerAltGroup.set(repairName, track.altGroup);
24578
24847
  }
24579
24848
  }
24580
24849
  const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
@@ -24673,11 +24942,10 @@ var MulticastManager = class {
24673
24942
  for (let i = 0; i < catalog.tracks.length; i++) {
24674
24943
  const track = catalog.tracks[i];
24675
24944
  const role = resolvedRoles[i];
24676
- const altGroup = repairOwnerAltGroup.has(track.name) ? repairOwnerAltGroup.get(track.name) : track.altGroup;
24677
- if (altGroup !== void 0) {
24678
- const existing = this.#switchingSets.get(altGroup) ?? [];
24945
+ if (role !== "repair" && track.altGroup !== void 0) {
24946
+ const existing = this.#switchingSets.get(track.altGroup) ?? [];
24679
24947
  existing.push(track.name);
24680
- this.#switchingSets.set(altGroup, existing);
24948
+ this.#switchingSets.set(track.altGroup, existing);
24681
24949
  }
24682
24950
  if (track.packetId !== void 0) {
24683
24951
  this.#router.setPacketIdRole(track.packetId, role);
@@ -24752,7 +25020,7 @@ var MulticastManager = class {
24752
25020
  #multiTrackFecTracks = /* @__PURE__ */ new Map();
24753
25021
  /**
24754
25022
  * Return the track names belonging to the given altGroup switching set.
24755
- * D-17: altGroup groups base+delta+repair into one switching set.
25023
+ * D-17: tracks with equal altGroup form one switching set; repair legs are in none.
24756
25024
  *
24757
25025
  * @param altGroup - The altGroup number to look up.
24758
25026
  * @returns Array of track names in that switching set (empty if none).
@@ -24780,6 +25048,19 @@ var MulticastManager = class {
24780
25048
  this.requestRepairForBlock(sbn, packetId, catalogTrackName, blockClass);
24781
25049
  };
24782
25050
  }
25051
+ /**
25052
+ * Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
25053
+ * on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
25054
+ * pending hole and reported here, and `closeIsoHoles` must be called for it
25055
+ * once its range FETCH ends (or none is sent).
25056
+ */
25057
+ onUndelimitedLoss(cb) {
25058
+ this.#fec.setUndelimitedLossHandler(cb);
25059
+ }
25060
+ /** End a pending hole's range repair: feed what no repair stated as spans. */
25061
+ closeIsoHoles(packetId, catalogTrackName, start, length) {
25062
+ this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
25063
+ }
24783
25064
  /**
24784
25065
  * Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
24785
25066
  * supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
@@ -24801,6 +25082,7 @@ var MulticastManager = class {
24801
25082
  stats.repairsSkipped++;
24802
25083
  if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
24803
25084
  else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
25085
+ else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
24804
25086
  else stats.repairsSkippedPresentationDelayUnavailable++;
24805
25087
  stats.lastRepairSkip = {
24806
25088
  reason,
@@ -24834,6 +25116,7 @@ var MulticastManager = class {
24834
25116
  /** Record a repair FETCH the scheduler admitted and sent. */
24835
25117
  noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
24836
25118
  if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
25119
+ if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
24837
25120
  this.#emitRepairLifecycle({
24838
25121
  version: 2,
24839
25122
  type: "repair-sent",
@@ -25761,7 +26044,7 @@ function asSeconds(n) {
25761
26044
  }
25762
26045
  return n;
25763
26046
  }
25764
- function groupIdForTicks(ticks, groupDurationTicks) {
26047
+ function groupIdForTicks(ticks, groupDurationTicks, presentationAnchorTicks = 0) {
25765
26048
  if (!Number.isInteger(ticks)) {
25766
26049
  throw new Error(
25767
26050
  `[align] groupIdForTicks: ticks must be an integer, got ${ticks}`
@@ -25772,8 +26055,23 @@ function groupIdForTicks(ticks, groupDurationTicks) {
25772
26055
  `[align] groupIdForTicks: groupDurationTicks must be a positive integer, got ${groupDurationTicks}`
25773
26056
  );
25774
26057
  }
25775
- if (ticks < 0) return 0;
25776
- return Math.floor(ticks / groupDurationTicks);
26058
+ if (!Number.isInteger(presentationAnchorTicks)) {
26059
+ throw new Error(
26060
+ `[align] groupIdForTicks: presentationAnchorTicks must be an integer, got ${presentationAnchorTicks}`
26061
+ );
26062
+ }
26063
+ const relativeTicks = ticks - presentationAnchorTicks;
26064
+ if (!Number.isSafeInteger(relativeTicks)) {
26065
+ throw new Error(
26066
+ `[align] groupIdForTicks: ticks - presentationAnchorTicks = ${relativeTicks} is not a safe integer`
26067
+ );
26068
+ }
26069
+ if (relativeTicks < 0) {
26070
+ throw new Error(
26071
+ `[align] groupIdForTicks: ticks ${ticks} precede presentationAnchorTicks ${presentationAnchorTicks}; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
26072
+ );
26073
+ }
26074
+ return Math.floor(relativeTicks / groupDurationTicks);
25777
26075
  }
25778
26076
  function groupIdFor(mediaTimeSec, groupDurationSec) {
25779
26077
  if (!Number.isFinite(mediaTimeSec)) {
@@ -25786,7 +26084,11 @@ function groupIdFor(mediaTimeSec, groupDurationSec) {
25786
26084
  `[align] groupIdFor: groupDurationSec must be a positive finite number, got ${groupDurationSec}`
25787
26085
  );
25788
26086
  }
25789
- if (mediaTimeSec < 0) return 0;
26087
+ if (mediaTimeSec < 0) {
26088
+ throw new Error(
26089
+ `[align] groupIdFor: mediaTimeSec ${mediaTimeSec} precedes presentationAnchorTicks 0; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
26090
+ );
26091
+ }
25790
26092
  const TS = 1e9;
25791
26093
  const ticks = Math.round(mediaTimeSec * TS);
25792
26094
  const durTicks = Math.round(groupDurationSec * TS);
@@ -26911,10 +27213,11 @@ var MmtpFecSession = class {
26911
27213
  const start = frame.ssStart;
26912
27214
  let block = this.#blocks.get(start);
26913
27215
  if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
27216
+ if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
26914
27217
  if (!block) {
26915
27218
  if (this.#settled.has(start)) return this.#drop("repair:block-settled");
26916
27219
  if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
26917
- block = { ssbLength: frame.ssbLength, received: 0, paths: 0 };
27220
+ block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
26918
27221
  this.#countHeld(start, block);
26919
27222
  this.#blocks.set(start, block);
26920
27223
  }
@@ -26930,6 +27233,7 @@ var MmtpFecSession = class {
26930
27233
  } catch {
26931
27234
  return this.#drop("repair:decoder-refused");
26932
27235
  }
27236
+ block.rsIds.add(frame.rsId);
26933
27237
  this.#stats.repairSymbols++;
26934
27238
  this.#stats.repairSymbolsByPath[path]++;
26935
27239
  block.paths |= pathBit;
@@ -27122,6 +27426,9 @@ function wireRepairFetch(mc, opts) {
27122
27426
  if (typeof opts.presentationDelayMs !== "function") {
27123
27427
  throw new Error("[RepairFetch] presentationDelayMs is required: a repair FETCH is due by the block's presentation deadline");
27124
27428
  }
27429
+ if (opts.rangeTransport !== void 0 && (typeof opts.repairEpochReference !== "function" || !mc.onUndelimitedLoss || !mc.closeIsoHoles)) {
27430
+ throw new Error("[RepairFetch] rangeTransport needs repairEpochReference and a host that reports undelimited losses");
27431
+ }
27125
27432
  const entries = /* @__PURE__ */ new Map();
27126
27433
  const warnedNoTarget = /* @__PURE__ */ new Set();
27127
27434
  let disposed = false;
@@ -27135,7 +27442,12 @@ function wireRepairFetch(mc, opts) {
27135
27442
  const note = (type, entry) => {
27136
27443
  mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
27137
27444
  };
27445
+ const clearEntry = (entry) => {
27446
+ if (entry.range) mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength);
27447
+ else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27448
+ };
27138
27449
  const releaseHold = (entry) => {
27450
+ if (entry.range) return;
27139
27451
  if (entry.catalogTrackName === void 0) mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId);
27140
27452
  else mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId, entry.catalogTrackName);
27141
27453
  };
@@ -27171,7 +27483,7 @@ function wireRepairFetch(mc, opts) {
27171
27483
  if (rttMs !== null && rttMs < budgetMs) return rttMs;
27172
27484
  retire(entry);
27173
27485
  releaseHold(entry);
27174
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27486
+ clearEntry(entry);
27175
27487
  mc.noteRepairSkipped(
27176
27488
  rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
27177
27489
  { rttMs, budgetMs, priority: entry.priority },
@@ -27183,6 +27495,7 @@ function wireRepairFetch(mc, opts) {
27183
27495
  };
27184
27496
  const retire = (entry) => {
27185
27497
  if (entries.get(entry.key) === entry) entries.delete(entry.key);
27498
+ if (entry.expiry !== void 0) clearTimeout(entry.expiry);
27186
27499
  };
27187
27500
  const urgentOutstanding = () => {
27188
27501
  for (const entry of entries.values()) {
@@ -27220,16 +27533,19 @@ function wireRepairFetch(mc, opts) {
27220
27533
  budgetMs: entry.deadlineAt - now,
27221
27534
  delayMs: entry.delayMs,
27222
27535
  blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
27223
- bound: entry.bound
27536
+ bound: entry.bound,
27537
+ ...entry.range ? { range: true } : {}
27224
27538
  });
27225
27539
  const run = { controller: new AbortController(), stopped: null };
27226
27540
  entry.running = run;
27227
- mc.fecManager.holdBlockForRepair(
27228
- entry.sbn,
27229
- entry.packetId,
27230
- entry.catalogTrackName,
27231
- entry.deadlineAt
27232
- );
27541
+ if (!entry.range) {
27542
+ mc.fecManager.holdBlockForRepair(
27543
+ entry.sbn,
27544
+ entry.packetId,
27545
+ entry.catalogTrackName,
27546
+ entry.deadlineAt
27547
+ );
27548
+ }
27233
27549
  void execute(entry, run);
27234
27550
  };
27235
27551
  const dispatch = () => {
@@ -27241,14 +27557,14 @@ function wireRepairFetch(mc, opts) {
27241
27557
  if (entry.deadlineAt <= now) {
27242
27558
  stop(entry, "expired");
27243
27559
  retire(entry);
27244
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27560
+ clearEntry(entry);
27245
27561
  }
27246
27562
  continue;
27247
27563
  }
27248
27564
  if (entry.deadlineAt <= now) {
27249
27565
  retire(entry);
27250
27566
  if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
27251
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27567
+ clearEntry(entry);
27252
27568
  continue;
27253
27569
  }
27254
27570
  queued.push(entry);
@@ -27285,9 +27601,9 @@ function wireRepairFetch(mc, opts) {
27285
27601
  entry.running = null;
27286
27602
  if (error === void 0) {
27287
27603
  retire(entry);
27288
- if (fed === 0 || !decodable(entry)) {
27604
+ if (entry.range || fed === 0 || !decodable(entry)) {
27289
27605
  releaseHold(entry);
27290
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27606
+ clearEntry(entry);
27291
27607
  }
27292
27608
  dispatch();
27293
27609
  return;
@@ -27299,7 +27615,7 @@ function wireRepairFetch(mc, opts) {
27299
27615
  }
27300
27616
  retire(entry);
27301
27617
  if (fed === 0) releaseHold(entry);
27302
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27618
+ clearEntry(entry);
27303
27619
  console.warn(
27304
27620
  `[RepairFetch] fetch failed pid=${entry.packetId} sbn=${entry.sbn} track=${entry.repairTrack}:`,
27305
27621
  error
@@ -27315,15 +27631,21 @@ function wireRepairFetch(mc, opts) {
27315
27631
  };
27316
27632
  const execute = async (entry, run) => {
27317
27633
  let fed = 0;
27634
+ const common = {
27635
+ repairTrack: entry.repairTrack,
27636
+ blockProfile: entry.blockProfile,
27637
+ packetId: entry.packetId,
27638
+ signal: run.controller.signal,
27639
+ subscriberPriority: entry.subscriberPriority
27640
+ };
27318
27641
  try {
27319
- for await (const packet of opts.transport({
27320
- repairTrack: entry.repairTrack,
27321
- sbn: entry.sbn,
27322
- blockProfile: entry.blockProfile,
27323
- packetId: entry.packetId,
27324
- signal: run.controller.signal,
27325
- subscriberPriority: entry.subscriberPriority
27326
- })) {
27642
+ const packets = entry.range ? opts.rangeTransport({
27643
+ ...common,
27644
+ startGroup: entry.range.startGroup,
27645
+ endGroup: entry.range.endGroup,
27646
+ lostSsId: entry.range.lostSsId
27647
+ }) : opts.transport({ ...common, sbn: entry.sbn });
27648
+ for await (const packet of packets) {
27327
27649
  if (run.stopped !== null || entry.running !== run) break;
27328
27650
  fed++;
27329
27651
  if (entry.catalogTrackName === void 0) {
@@ -27342,6 +27664,7 @@ function wireRepairFetch(mc, opts) {
27342
27664
  if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
27343
27665
  retire(entry);
27344
27666
  stop(entry, "reset");
27667
+ if (entry.range) clearEntry(entry);
27345
27668
  }
27346
27669
  warnedNoTarget.delete(noTargetKey(packetId, catalogTrackName));
27347
27670
  dispatch();
@@ -27512,14 +27835,92 @@ function wireRepairFetch(mc, opts) {
27512
27835
  if (entry.priority < 2) preemptDeltas();
27513
27836
  dispatch();
27514
27837
  });
27838
+ const rangeFor = (loss, repairTrack) => {
27839
+ let reference;
27840
+ try {
27841
+ reference = opts.repairEpochReference(repairTrack);
27842
+ } catch {
27843
+ return null;
27844
+ }
27845
+ if (reference === void 0) return null;
27846
+ try {
27847
+ const anchor = loss.previousBlockStart === void 0 ? { reference } : { previousBlockStart: extendSsId(reference, loss.previousBlockStart) };
27848
+ return repairFetchRange(loss.lostSsId, loss.kMax, anchor);
27849
+ } catch (error) {
27850
+ if (error instanceof RangeError) return null;
27851
+ throw error;
27852
+ }
27853
+ };
27854
+ if (opts.rangeTransport !== void 0) {
27855
+ mc.onUndelimitedLoss((loss) => {
27856
+ const { packetId, catalogTrackName, holeStart, holeLength } = loss;
27857
+ const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
27858
+ if (disposed) return close();
27859
+ const blockProfile = blockProfileOf(packetId);
27860
+ const target = opts.resolveTarget(packetId, catalogTrackName);
27861
+ if (!target) return close();
27862
+ const priority = repairPriorityForClass("unknown");
27863
+ const range = rangeFor(loss, target.repairTrack);
27864
+ if (range === null) {
27865
+ close();
27866
+ mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
27867
+ return;
27868
+ }
27869
+ const identity = {
27870
+ target,
27871
+ sbn: holeStart,
27872
+ packetId,
27873
+ ...catalogTrackName === void 0 ? {} : { catalogTrackName }
27874
+ };
27875
+ const wire = wirePriority(identity, "unknown");
27876
+ const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), "unknown");
27877
+ if (deadline === null) {
27878
+ close();
27879
+ mc.noteRepairSkipped(
27880
+ "presentation-delay-unavailable",
27881
+ { rttMs: readRtt(), budgetMs: 0, priority },
27882
+ holeStart,
27883
+ packetId,
27884
+ catalogTrackName
27885
+ );
27886
+ return;
27887
+ }
27888
+ const entry = {
27889
+ key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
27890
+ ...identity,
27891
+ repairTrack: target.repairTrack,
27892
+ blockProfile,
27893
+ priority,
27894
+ subscriberPriority: wire.subscriberPriority,
27895
+ deadlineAt: deadline.deadlineAt,
27896
+ anchorAt: deadline.anchorAt,
27897
+ delayMs: deadline.delayMs,
27898
+ bound: deadline.bound,
27899
+ order: enqueueOrder++,
27900
+ attempts: 0,
27901
+ running: null,
27902
+ range: { ...range, lostSsId: loss.lostSsId, holeLength }
27903
+ };
27904
+ const previous = entries.get(entry.key);
27905
+ if (previous) {
27906
+ retire(previous);
27907
+ stop(previous, "reset");
27908
+ }
27909
+ entries.set(entry.key, entry);
27910
+ entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
27911
+ preemptDeltas();
27912
+ dispatch();
27913
+ });
27914
+ }
27515
27915
  return () => {
27516
27916
  disposed = true;
27517
27917
  removeResetObserver();
27518
27918
  removeLifecycleObserver();
27519
27919
  for (const entry of [...entries.values()]) {
27520
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
27920
+ clearEntry(entry);
27521
27921
  if (entry.running) releaseHold(entry);
27522
27922
  stop(entry, "disposed");
27923
+ if (entry.expiry !== void 0) clearTimeout(entry.expiry);
27523
27924
  }
27524
27925
  entries.clear();
27525
27926
  };
@@ -27593,6 +27994,7 @@ export {
27593
27994
  buildHevcVideoInitSegment,
27594
27995
  buildVideoInitSegment,
27595
27996
  catalogAmtNetworkSource,
27997
+ catalogAtsc3NetworkSource,
27596
27998
  catalogDeclaresFec,
27597
27999
  catalogFecAvailable,
27598
28000
  catalogFecDeclaresUnconfigurableInstance,