@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.c9b538a2feb5
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.
- package/README.md +25 -12
- package/dist/browser-runtime.js +710 -253
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +51 -22
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +240 -191
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +1 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +6 -13
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.js.map +1 -1
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/delivery-catalog.js +4 -12
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.js.map +1 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +14 -2
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.js.map +1 -1
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +311 -1163
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +917 -275
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +156 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +522 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +17 -0
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +327 -124
- package/dist/multicast-auth-catalog.js.map +3 -3
- package/dist/multicast-input.d.ts +25 -3
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +266 -13
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +23 -4
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +59 -29
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.js +2 -10
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +2 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +869 -264
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +23 -1
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +35 -10
- package/dist/repair-fetch.js.map +2 -2
- package/dist/repair-layers.js.map +1 -1
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +22 -6
- package/dist/source-auth.js.map +2 -2
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +5 -5
- package/schemas/catalog.schema.json +81 -28
- package/src/carp-catalog.ts +77 -39
- package/src/catalog-fec-params.ts +5 -2
- package/src/catalog-validator.ts +4 -11
- package/src/fec-state.ts +3 -2
- package/src/index.ts +18 -2
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-fec-session.ts +514 -0
- package/src/mmtp-router.ts +25 -0
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +88 -37
- package/src/multicast-manager.ts +88 -14
- package/src/no-modules.ts +2 -0
- package/src/repair-fetch.ts +79 -14
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/catalog/README.md +38 -3
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/section-codes.json +23 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +3 -2
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
package/dist/browser-runtime.js
CHANGED
|
@@ -1015,11 +1015,258 @@ function catalogFecAvailable(fec) {
|
|
|
1015
1015
|
function isPositiveSafeInteger(value) {
|
|
1016
1016
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
1017
1017
|
}
|
|
1018
|
+
var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
|
|
1018
1019
|
function catalogFecDeclaresUnconfigurableInstance(fec) {
|
|
1019
1020
|
const block = recordOf(fec);
|
|
1020
1021
|
if (block === void 0 || block["algorithm"] === "none")
|
|
1021
1022
|
return false;
|
|
1022
|
-
|
|
1023
|
+
if (!(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"])))
|
|
1024
|
+
return true;
|
|
1025
|
+
return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
|
|
1026
|
+
}
|
|
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 (hasAuth) {
|
|
1213
|
+
const authIssue = endpointAuthIssue(endpoint, mode, at);
|
|
1214
|
+
if (authIssue) {
|
|
1215
|
+
fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
sources[index] = multicastEndpointSource(endpoint);
|
|
1220
|
+
const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
|
|
1221
|
+
for (let refIndex = 0; refIndex < refs.length; refIndex++) {
|
|
1222
|
+
const ref = refs[refIndex];
|
|
1223
|
+
const name = isObject(ref) ? ref["name"] : ref;
|
|
1224
|
+
if (typeof name !== "string")
|
|
1225
|
+
continue;
|
|
1226
|
+
const namespace = namespaceOf.get(name);
|
|
1227
|
+
if (typeof namespace !== "string")
|
|
1228
|
+
continue;
|
|
1229
|
+
referenceNamespace ??= namespace;
|
|
1230
|
+
if (namespace !== referenceNamespace) {
|
|
1231
|
+
fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const tupleOf = (index) => {
|
|
1236
|
+
const endpoint = endpoints[index];
|
|
1237
|
+
const auth = endpoint["auth"];
|
|
1238
|
+
return {
|
|
1239
|
+
sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
|
|
1240
|
+
port: endpoint["port"],
|
|
1241
|
+
manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
|
|
1242
|
+
};
|
|
1243
|
+
};
|
|
1244
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
1245
|
+
if (!sources[index])
|
|
1246
|
+
continue;
|
|
1247
|
+
const own = tupleOf(index);
|
|
1248
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
1249
|
+
if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
|
|
1250
|
+
issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
for (let other = 0; other < endpoints.length; other++) {
|
|
1254
|
+
if (other === index || !sources[other])
|
|
1255
|
+
continue;
|
|
1256
|
+
const peer = tupleOf(other);
|
|
1257
|
+
if (peer.sg !== own.sg)
|
|
1258
|
+
continue;
|
|
1259
|
+
if (peer.port === own.port) {
|
|
1260
|
+
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 });
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
|
|
1264
|
+
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 });
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return issues;
|
|
1023
1270
|
}
|
|
1024
1271
|
|
|
1025
1272
|
// src/mfu-reassembler.ts
|
|
@@ -6023,197 +6270,6 @@ if (void 0) {
|
|
|
6023
6270
|
});
|
|
6024
6271
|
}
|
|
6025
6272
|
|
|
6026
|
-
// src/multicast-auth-catalog.ts
|
|
6027
|
-
var RAW_ED25519_KEY_LENGTH = 32;
|
|
6028
|
-
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
6029
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
6030
|
-
function encodeBase64Url(bytes) {
|
|
6031
|
-
let output = "";
|
|
6032
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
6033
|
-
const b0 = bytes[i];
|
|
6034
|
-
const b1 = bytes[i + 1];
|
|
6035
|
-
const b2 = bytes[i + 2];
|
|
6036
|
-
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
6037
|
-
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
6038
|
-
if (b1 === void 0) break;
|
|
6039
|
-
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
6040
|
-
if (b2 === void 0) break;
|
|
6041
|
-
output += BASE64URL_ALPHABET[b2 & 63];
|
|
6042
|
-
}
|
|
6043
|
-
return output;
|
|
6044
|
-
}
|
|
6045
|
-
var BASE64URL_DECODE_TABLE = (() => {
|
|
6046
|
-
const table = new Int8Array(128).fill(-1);
|
|
6047
|
-
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
6048
|
-
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
6049
|
-
}
|
|
6050
|
-
return table;
|
|
6051
|
-
})();
|
|
6052
|
-
function decodeBase64Url(text) {
|
|
6053
|
-
if (text.length % 4 === 1) {
|
|
6054
|
-
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
|
|
6055
|
-
}
|
|
6056
|
-
const bytes = [];
|
|
6057
|
-
let buffer = 0;
|
|
6058
|
-
let bits = 0;
|
|
6059
|
-
for (let i = 0; i < text.length; i++) {
|
|
6060
|
-
const code = text.charCodeAt(i);
|
|
6061
|
-
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
6062
|
-
if (value === void 0 || value < 0) {
|
|
6063
|
-
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
|
|
6064
|
-
}
|
|
6065
|
-
buffer = buffer << 6 | value;
|
|
6066
|
-
bits += 6;
|
|
6067
|
-
if (bits >= 8) {
|
|
6068
|
-
bits -= 8;
|
|
6069
|
-
bytes.push(buffer >> bits & 255);
|
|
6070
|
-
}
|
|
6071
|
-
}
|
|
6072
|
-
const decoded = Uint8Array.from(bytes);
|
|
6073
|
-
if (encodeBase64Url(decoded) !== text) {
|
|
6074
|
-
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
|
|
6075
|
-
}
|
|
6076
|
-
return decoded;
|
|
6077
|
-
}
|
|
6078
|
-
function decodeAuthScope(authScope) {
|
|
6079
|
-
const bytes = decodeBase64Url(authScope);
|
|
6080
|
-
if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
|
|
6081
|
-
throw new Error(
|
|
6082
|
-
`[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
6083
|
-
);
|
|
6084
|
-
}
|
|
6085
|
-
return bytes;
|
|
6086
|
-
}
|
|
6087
|
-
function decodeEd25519PublicKey(publicKey) {
|
|
6088
|
-
const bytes = decodeBase64Url(publicKey);
|
|
6089
|
-
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
6090
|
-
throw new Error(
|
|
6091
|
-
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
6092
|
-
);
|
|
6093
|
-
}
|
|
6094
|
-
return bytes;
|
|
6095
|
-
}
|
|
6096
|
-
function isNonEmptyString(value) {
|
|
6097
|
-
return typeof value === "string" && value.length > 0;
|
|
6098
|
-
}
|
|
6099
|
-
function isValidAuthScopeField(value) {
|
|
6100
|
-
if (!isNonEmptyString(value)) return false;
|
|
6101
|
-
try {
|
|
6102
|
-
decodeAuthScope(value);
|
|
6103
|
-
return true;
|
|
6104
|
-
} catch {
|
|
6105
|
-
return false;
|
|
6106
|
-
}
|
|
6107
|
-
}
|
|
6108
|
-
function isValidPublicKeyField(value) {
|
|
6109
|
-
if (!isNonEmptyString(value)) return false;
|
|
6110
|
-
try {
|
|
6111
|
-
decodeEd25519PublicKey(value);
|
|
6112
|
-
return true;
|
|
6113
|
-
} catch {
|
|
6114
|
-
return false;
|
|
6115
|
-
}
|
|
6116
|
-
}
|
|
6117
|
-
function hasOnlyKeys(object2, allowed) {
|
|
6118
|
-
const allowedKeys = new Set(allowed);
|
|
6119
|
-
return Object.keys(object2).every((key) => allowedKeys.has(key));
|
|
6120
|
-
}
|
|
6121
|
-
function isMulticastAuthTrackConfig(obj) {
|
|
6122
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
6123
|
-
const o = obj;
|
|
6124
|
-
return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
|
|
6125
|
-
}
|
|
6126
|
-
var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
|
|
6127
|
-
var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
|
|
6128
|
-
function hasUniqueMulticastAuthTrackBindings(tracks) {
|
|
6129
|
-
const bindings = tracks.flatMap((track) => {
|
|
6130
|
-
if (typeof track !== "object" || track === null) return [];
|
|
6131
|
-
const value = track;
|
|
6132
|
-
if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
|
|
6133
|
-
return [];
|
|
6134
|
-
}
|
|
6135
|
-
return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
|
|
6136
|
-
});
|
|
6137
|
-
return new Set(bindings).size === bindings.length;
|
|
6138
|
-
}
|
|
6139
|
-
function isMulticastAuthConfig(obj) {
|
|
6140
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
6141
|
-
const o = obj;
|
|
6142
|
-
if (o["scheme"] !== "bc-provenance") return false;
|
|
6143
|
-
if (o["hash"] !== "blake3") return false;
|
|
6144
|
-
if (o["sig"] !== "ed25519") return false;
|
|
6145
|
-
if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
|
|
6146
|
-
if (!isValidPublicKeyField(o["publicKey"])) return false;
|
|
6147
|
-
if (!isNonEmptyString(o["keyId"])) return false;
|
|
6148
|
-
if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
|
|
6149
|
-
if (o["previousKey"] === o["publicKey"]) return false;
|
|
6150
|
-
if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
|
|
6151
|
-
if (o["enforcement"] !== void 0) {
|
|
6152
|
-
if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
|
|
6153
|
-
}
|
|
6154
|
-
if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
|
|
6155
|
-
const tracks = o["tracks"];
|
|
6156
|
-
if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
|
|
6157
|
-
const typedTracks = tracks;
|
|
6158
|
-
const scopes = typedTracks.map((t) => t.authScope);
|
|
6159
|
-
if (new Set(scopes).size !== scopes.length) return false;
|
|
6160
|
-
if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
|
|
6161
|
-
const manifestTracks = typedTracks.map((t) => t.manifestTrack);
|
|
6162
|
-
if (new Set(manifestTracks).size !== manifestTracks.length) return false;
|
|
6163
|
-
return true;
|
|
6164
|
-
}
|
|
6165
|
-
function resolveMulticastAuthMode(playerMode, auth) {
|
|
6166
|
-
if (playerMode !== void 0) return playerMode;
|
|
6167
|
-
if (auth === void 0) return "off";
|
|
6168
|
-
return auth.enforcement ?? "shadow";
|
|
6169
|
-
}
|
|
6170
|
-
function resolveMulticastAuthCatalog(catalog, playerMode) {
|
|
6171
|
-
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
6172
|
-
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
6173
|
-
}
|
|
6174
|
-
const root = catalog;
|
|
6175
|
-
const rawAuth = root["multicast.auth"];
|
|
6176
|
-
if (rawAuth === void 0) {
|
|
6177
|
-
if (playerMode === "enforce") {
|
|
6178
|
-
throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
|
|
6179
|
-
}
|
|
6180
|
-
return void 0;
|
|
6181
|
-
}
|
|
6182
|
-
if (!isMulticastAuthConfig(rawAuth)) {
|
|
6183
|
-
throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
|
|
6184
|
-
}
|
|
6185
|
-
const rawTracks = root["tracks"];
|
|
6186
|
-
if (!Array.isArray(rawTracks)) {
|
|
6187
|
-
throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
|
|
6188
|
-
}
|
|
6189
|
-
const catalogTrackNames = new Set(
|
|
6190
|
-
rawTracks.flatMap(
|
|
6191
|
-
(track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
|
|
6192
|
-
)
|
|
6193
|
-
);
|
|
6194
|
-
for (const track of rawAuth.tracks) {
|
|
6195
|
-
if (!catalogTrackNames.has(track.mediaTrack)) {
|
|
6196
|
-
throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
|
|
6197
|
-
}
|
|
6198
|
-
if (!catalogTrackNames.has(track.manifestTrack)) {
|
|
6199
|
-
throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
|
|
6200
|
-
}
|
|
6201
|
-
}
|
|
6202
|
-
return {
|
|
6203
|
-
keyId: rawAuth.keyId,
|
|
6204
|
-
acceptedPublicKeys: [
|
|
6205
|
-
decodeEd25519PublicKey(rawAuth.publicKey),
|
|
6206
|
-
...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
|
|
6207
|
-
],
|
|
6208
|
-
mode: resolveMulticastAuthMode(playerMode, rawAuth),
|
|
6209
|
-
compaction: rawAuth.compaction,
|
|
6210
|
-
tracks: rawAuth.tracks.map((track) => ({
|
|
6211
|
-
...track,
|
|
6212
|
-
authScope: decodeAuthScope(track.authScope)
|
|
6213
|
-
}))
|
|
6214
|
-
};
|
|
6215
|
-
}
|
|
6216
|
-
|
|
6217
6273
|
// src/repair-layers.ts
|
|
6218
6274
|
var REPAIR_PRIORITY_MIN = 192;
|
|
6219
6275
|
var REPAIR_PRIORITY_MAX = 255;
|
|
@@ -6572,8 +6628,7 @@ function isMulticastTrackObject(obj) {
|
|
|
6572
6628
|
function isMulticastEndpoint(obj) {
|
|
6573
6629
|
if (typeof obj !== "object" || obj === null) return false;
|
|
6574
6630
|
const o = obj;
|
|
6575
|
-
|
|
6576
|
-
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));
|
|
6631
|
+
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));
|
|
6577
6632
|
}
|
|
6578
6633
|
function isMulticastCatalogConfig(obj) {
|
|
6579
6634
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -6677,7 +6732,7 @@ var CmsfCatalogValidationError = class extends Error {
|
|
|
6677
6732
|
function catalogError(code, path, message) {
|
|
6678
6733
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
6679
6734
|
}
|
|
6680
|
-
function validateCmsfMmtpCatalog(value) {
|
|
6735
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
6681
6736
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
6682
6737
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
6683
6738
|
}
|
|
@@ -6811,6 +6866,9 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6811
6866
|
}
|
|
6812
6867
|
}
|
|
6813
6868
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
6869
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
6870
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
6871
|
+
}
|
|
6814
6872
|
}
|
|
6815
6873
|
}
|
|
6816
6874
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -6922,15 +6980,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6922
6980
|
}
|
|
6923
6981
|
}
|
|
6924
6982
|
}
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
} catch (error) {
|
|
6928
|
-
catalogError(
|
|
6929
|
-
"multicast_auth",
|
|
6930
|
-
"$.multicast.auth",
|
|
6931
|
-
error instanceof Error ? error.message : "invalid multicast.auth v2 block"
|
|
6932
|
-
);
|
|
6933
|
-
}
|
|
6983
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
6984
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
6934
6985
|
validateArchive(catalog);
|
|
6935
6986
|
return catalog;
|
|
6936
6987
|
}
|
|
@@ -6956,7 +7007,7 @@ function resolveGroupDurationTicks(timing, timescale) {
|
|
|
6956
7007
|
const product = timing.groupDurationMs * timescale;
|
|
6957
7008
|
if (product % 1e3 !== 0) {
|
|
6958
7009
|
throw new Error(
|
|
6959
|
-
`[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-
|
|
7010
|
+
`[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)`
|
|
6960
7011
|
);
|
|
6961
7012
|
}
|
|
6962
7013
|
return product / 1e3;
|
|
@@ -6977,14 +7028,6 @@ function validateSwitchingSetTiming(tracks) {
|
|
|
6977
7028
|
return { ok: false, expectedTicks, mismatches };
|
|
6978
7029
|
}
|
|
6979
7030
|
|
|
6980
|
-
// node_modules/@blockcast/mmt-transport/dist/types.js
|
|
6981
|
-
var MoqFecAlgorithm;
|
|
6982
|
-
(function(MoqFecAlgorithm2) {
|
|
6983
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["None"] = 0] = "None";
|
|
6984
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["Xor"] = 1] = "Xor";
|
|
6985
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
|
|
6986
|
-
})(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
|
|
6987
|
-
|
|
6988
7031
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
6989
7032
|
function endpointKey(endpoint) {
|
|
6990
7033
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -7115,8 +7158,8 @@ var AdaptiveBitrateController = class {
|
|
|
7115
7158
|
/**
|
|
7116
7159
|
* Update FEC statistics for ABR decisions
|
|
7117
7160
|
*
|
|
7118
|
-
*
|
|
7119
|
-
*
|
|
7161
|
+
* ABR uses the effective loss rate (after FEC recovery) rather than the
|
|
7162
|
+
* raw transport loss rate.
|
|
7120
7163
|
*
|
|
7121
7164
|
* @param stats - FEC statistics from the FEC decoder
|
|
7122
7165
|
*/
|
|
@@ -8713,8 +8756,7 @@ function multicastFromConfig(input) {
|
|
|
8713
8756
|
);
|
|
8714
8757
|
}
|
|
8715
8758
|
}
|
|
8716
|
-
const
|
|
8717
|
-
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx, seenTuples));
|
|
8759
|
+
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx));
|
|
8718
8760
|
const out = { endpoints };
|
|
8719
8761
|
const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
|
|
8720
8762
|
networkSource.forEach(validateNetworkSourceEntry);
|
|
@@ -8751,6 +8793,17 @@ function multicastFromConfig(input) {
|
|
|
8751
8793
|
`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" : "")
|
|
8752
8794
|
);
|
|
8753
8795
|
});
|
|
8796
|
+
input.endpoints.forEach((ep, idx) => {
|
|
8797
|
+
if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
|
|
8798
|
+
endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
|
|
8799
|
+
});
|
|
8800
|
+
if (input.auth !== void 0) out.auth = input.auth;
|
|
8801
|
+
const [issue] = multicastCatalogIssues({ multicast: out });
|
|
8802
|
+
if (issue) {
|
|
8803
|
+
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";
|
|
8804
|
+
const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
|
|
8805
|
+
throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
|
|
8806
|
+
}
|
|
8754
8807
|
if (input.enabled !== void 0) out.enabled = input.enabled;
|
|
8755
8808
|
if (input.version !== void 0) out.version = input.version;
|
|
8756
8809
|
if (input.validUntil !== void 0) out.validUntil = input.validUntil;
|
|
@@ -8816,7 +8869,7 @@ function isAbsoluteUri(value) {
|
|
|
8816
8869
|
return false;
|
|
8817
8870
|
}
|
|
8818
8871
|
}
|
|
8819
|
-
function validateEndpoint2(ep, idx
|
|
8872
|
+
function validateEndpoint2(ep, idx) {
|
|
8820
8873
|
if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
|
|
8821
8874
|
throw new MulticastInputError(
|
|
8822
8875
|
"ssm_requires_source",
|
|
@@ -8824,6 +8877,13 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8824
8877
|
`endpoint[${idx}] protocol=ssm requires sourceAddress`
|
|
8825
8878
|
);
|
|
8826
8879
|
}
|
|
8880
|
+
if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
|
|
8881
|
+
throw new MulticastInputError(
|
|
8882
|
+
"protocol_source_mismatch",
|
|
8883
|
+
idx,
|
|
8884
|
+
`endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
|
|
8885
|
+
);
|
|
8886
|
+
}
|
|
8827
8887
|
if (!isMulticastGroupAddress(ep.groupAddress)) {
|
|
8828
8888
|
throw new MulticastInputError(
|
|
8829
8889
|
"invalid_group_address",
|
|
@@ -8883,23 +8943,15 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8883
8943
|
`endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
|
|
8884
8944
|
);
|
|
8885
8945
|
}
|
|
8886
|
-
const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
|
|
8887
|
-
if (seenTuples.has(tupleKey)) {
|
|
8888
|
-
throw new MulticastInputError(
|
|
8889
|
-
"duplicate_endpoint_tuple",
|
|
8890
|
-
idx,
|
|
8891
|
-
`endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
|
|
8892
|
-
);
|
|
8893
|
-
}
|
|
8894
|
-
seenTuples.add(tupleKey);
|
|
8895
8946
|
const out = {
|
|
8896
|
-
protocol: ep.
|
|
8947
|
+
protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
|
|
8897
8948
|
groupAddress: ep.groupAddress,
|
|
8898
8949
|
port: ep.port,
|
|
8899
8950
|
tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
|
|
8900
8951
|
};
|
|
8901
8952
|
if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
|
|
8902
8953
|
if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
|
|
8954
|
+
if (ep.auth !== void 0) out.auth = { ...ep.auth };
|
|
8903
8955
|
return out;
|
|
8904
8956
|
}
|
|
8905
8957
|
function isMulticastGroupAddress(addr) {
|
|
@@ -9450,8 +9502,8 @@ function u32(v) {
|
|
|
9450
9502
|
}
|
|
9451
9503
|
var KEYFRAME_FLAGS = 33554432;
|
|
9452
9504
|
var DELTA_FLAGS = 16842752;
|
|
9453
|
-
var
|
|
9454
|
-
var MAX_TRACK_ID =
|
|
9505
|
+
var UINT32_MAX2 = 4294967295;
|
|
9506
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
9455
9507
|
var INT32_MIN = -2147483648;
|
|
9456
9508
|
var INT32_MAX = 2147483647;
|
|
9457
9509
|
function assertTrackId(trackId, label) {
|
|
@@ -9460,8 +9512,8 @@ function assertTrackId(trackId, label) {
|
|
|
9460
9512
|
}
|
|
9461
9513
|
}
|
|
9462
9514
|
function assertTimescale(timescale, label) {
|
|
9463
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
9464
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
9515
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
9516
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
9465
9517
|
}
|
|
9466
9518
|
}
|
|
9467
9519
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -12544,7 +12596,7 @@ function isPositiveSafeInteger2(value) {
|
|
|
12544
12596
|
function catalogDeclaresFec(fec) {
|
|
12545
12597
|
const block = recordOf2(fec);
|
|
12546
12598
|
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
12547
|
-
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block);
|
|
12599
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
12548
12600
|
}
|
|
12549
12601
|
function requireBoolean(value, field) {
|
|
12550
12602
|
if (typeof value !== "boolean") {
|
|
@@ -18977,6 +19029,12 @@ var MmtpRouter = class {
|
|
|
18977
19029
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
18978
19030
|
*/
|
|
18979
19031
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19032
|
+
/**
|
|
19033
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
19034
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
19035
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
19036
|
+
*/
|
|
19037
|
+
#multicastRapTwinByStream = /* @__PURE__ */ new Set();
|
|
18980
19038
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18981
19039
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18982
19040
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -19110,6 +19168,12 @@ var MmtpRouter = class {
|
|
|
19110
19168
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
|
|
19111
19169
|
};
|
|
19112
19170
|
if (meta.source) frameMeta.source = meta.source;
|
|
19171
|
+
if (isVideo && frameMeta.keyframe) {
|
|
19172
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
19173
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
|
|
19174
|
+
);
|
|
19175
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
19176
|
+
}
|
|
19113
19177
|
if (meta.deliveryProvenance !== void 0)
|
|
19114
19178
|
frameMeta.deliveryProvenance = meta.deliveryProvenance;
|
|
19115
19179
|
if (meta.recovered) frameMeta.recovered = true;
|
|
@@ -19932,6 +19996,7 @@ var MmtpRouter = class {
|
|
|
19932
19996
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19933
19997
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
19934
19998
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
19999
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
19935
20000
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19936
20001
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
19937
20002
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -20730,6 +20795,10 @@ var MmtpRouter = class {
|
|
|
20730
20795
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
20731
20796
|
...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
|
|
20732
20797
|
}, parsed);
|
|
20798
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
20799
|
+
this.#multicastRapTwinByStream.add(
|
|
20800
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName)
|
|
20801
|
+
);
|
|
20733
20802
|
}
|
|
20734
20803
|
if (this.#classifyPacketId(info.packetId) === null) return;
|
|
20735
20804
|
if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
|
|
@@ -23068,7 +23137,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
23068
23137
|
throwRepairContractError(
|
|
23069
23138
|
"track_fec",
|
|
23070
23139
|
`${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
|
|
23071
|
-
"must be a positive integer"
|
|
23140
|
+
kValid && Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0 ? `iso-ssbg1-v1 symbolSize must be at least ${ISO_SSBG1_MIN_SYMBOL_SIZE}` : "must be a positive integer"
|
|
23072
23141
|
);
|
|
23073
23142
|
}
|
|
23074
23143
|
const fecUnavailable = catalogFecUnavailable(fec, fecPath);
|
|
@@ -23253,6 +23322,12 @@ var REPAIR_PRIORITY_REASONS = /* @__PURE__ */ new Set([
|
|
|
23253
23322
|
"repair-priority-absent",
|
|
23254
23323
|
"repair-priority-invalid"
|
|
23255
23324
|
]);
|
|
23325
|
+
var REPAIR_SKIP_REASONS = /* @__PURE__ */ new Set([
|
|
23326
|
+
"rtt-unmeasured",
|
|
23327
|
+
"rtt-exceeds-budget",
|
|
23328
|
+
"presentation-delay-unavailable"
|
|
23329
|
+
]);
|
|
23330
|
+
var REPAIR_DEADLINE_BOUNDS = /* @__PURE__ */ new Set(["wait", "presentation", "keyframe", "retention"]);
|
|
23256
23331
|
var GAP_REASONS = {
|
|
23257
23332
|
"rap-lost": "stall",
|
|
23258
23333
|
"rap-unknown": "stall",
|
|
@@ -23275,6 +23350,9 @@ function isSymbolCounts(value) {
|
|
|
23275
23350
|
function isNullableNonNegative(value) {
|
|
23276
23351
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
23277
23352
|
}
|
|
23353
|
+
function isFiniteNumber(value) {
|
|
23354
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
23355
|
+
}
|
|
23278
23356
|
function isRepairLifecycleEvent(value) {
|
|
23279
23357
|
if (!isRecord(value) || value["version"] !== 2) return false;
|
|
23280
23358
|
const block = value["block"];
|
|
@@ -23292,6 +23370,20 @@ function isRepairLifecycleEvent(value) {
|
|
|
23292
23370
|
case "repair-preempted":
|
|
23293
23371
|
case "repair-deferred":
|
|
23294
23372
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
23373
|
+
case "repair-sent":
|
|
23374
|
+
return hasExactKeys(value, [
|
|
23375
|
+
"version",
|
|
23376
|
+
"type",
|
|
23377
|
+
"block",
|
|
23378
|
+
"priority",
|
|
23379
|
+
"rttMs",
|
|
23380
|
+
"budgetMs",
|
|
23381
|
+
"delayMs",
|
|
23382
|
+
"blockAgeMs",
|
|
23383
|
+
"bound"
|
|
23384
|
+
]) && isRepairBlockIdentity(block) && (value["priority"] === 0 || value["priority"] === 1 || value["priority"] === 2) && isFiniteNumber(value["rttMs"]) && value["rttMs"] > 0 && isFiniteNumber(value["budgetMs"]) && value["budgetMs"] > value["rttMs"] && isNullableNonNegative(value["delayMs"]) && isNullableNonNegative(value["blockAgeMs"]) && value["delayMs"] === null === (value["blockAgeMs"] === null) && REPAIR_DEADLINE_BOUNDS.has(value["bound"]);
|
|
23385
|
+
case "repair-skipped":
|
|
23386
|
+
return hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) && isRepairBlockIdentity(block) && REPAIR_SKIP_REASONS.has(value["reason"]) && isNullableNonNegative(value["rttMs"]) && isFiniteNumber(value["budgetMs"]);
|
|
23295
23387
|
case "repair-priority": {
|
|
23296
23388
|
const blockClass = value["blockClass"];
|
|
23297
23389
|
const action = value["action"];
|
|
@@ -24481,7 +24573,7 @@ var MulticastManager = class {
|
|
|
24481
24573
|
*
|
|
24482
24574
|
* D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
|
|
24483
24575
|
* D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
|
|
24484
|
-
* D-17: Builds altGroup → track-name index for getSwitchingSet().
|
|
24576
|
+
* D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
|
|
24485
24577
|
* D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
|
|
24486
24578
|
*
|
|
24487
24579
|
* FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
|
|
@@ -24532,11 +24624,9 @@ var MulticastManager = class {
|
|
|
24532
24624
|
}
|
|
24533
24625
|
}
|
|
24534
24626
|
const repairOwnerGroup = /* @__PURE__ */ new Map();
|
|
24535
|
-
const repairOwnerAltGroup = /* @__PURE__ */ new Map();
|
|
24536
24627
|
for (const track of catalog.tracks) {
|
|
24537
24628
|
for (const repairName of repairNamesBySource.get(track.name) ?? []) {
|
|
24538
24629
|
repairOwnerGroup.set(repairName, altGroupKey(track));
|
|
24539
|
-
repairOwnerAltGroup.set(repairName, track.altGroup);
|
|
24540
24630
|
}
|
|
24541
24631
|
}
|
|
24542
24632
|
const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
|
|
@@ -24635,11 +24725,10 @@ var MulticastManager = class {
|
|
|
24635
24725
|
for (let i = 0; i < catalog.tracks.length; i++) {
|
|
24636
24726
|
const track = catalog.tracks[i];
|
|
24637
24727
|
const role = resolvedRoles[i];
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
const existing = this.#switchingSets.get(altGroup) ?? [];
|
|
24728
|
+
if (role !== "repair" && track.altGroup !== void 0) {
|
|
24729
|
+
const existing = this.#switchingSets.get(track.altGroup) ?? [];
|
|
24641
24730
|
existing.push(track.name);
|
|
24642
|
-
this.#switchingSets.set(altGroup, existing);
|
|
24731
|
+
this.#switchingSets.set(track.altGroup, existing);
|
|
24643
24732
|
}
|
|
24644
24733
|
if (track.packetId !== void 0) {
|
|
24645
24734
|
this.#router.setPacketIdRole(track.packetId, role);
|
|
@@ -24714,7 +24803,7 @@ var MulticastManager = class {
|
|
|
24714
24803
|
#multiTrackFecTracks = /* @__PURE__ */ new Map();
|
|
24715
24804
|
/**
|
|
24716
24805
|
* Return the track names belonging to the given altGroup switching set.
|
|
24717
|
-
* D-17:
|
|
24806
|
+
* D-17: tracks with equal altGroup form one switching set; repair legs are in none.
|
|
24718
24807
|
*
|
|
24719
24808
|
* @param altGroup - The altGroup number to look up.
|
|
24720
24809
|
* @returns Array of track names in that switching set (empty if none).
|
|
@@ -24794,8 +24883,19 @@ var MulticastManager = class {
|
|
|
24794
24883
|
stats.keyframeBudgetHoldMs += extensionMs;
|
|
24795
24884
|
}
|
|
24796
24885
|
/** Record a repair FETCH the scheduler admitted and sent. */
|
|
24797
|
-
noteRepairFetchSent(priority,
|
|
24886
|
+
noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
|
|
24798
24887
|
if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
|
|
24888
|
+
this.#emitRepairLifecycle({
|
|
24889
|
+
version: 2,
|
|
24890
|
+
type: "repair-sent",
|
|
24891
|
+
block: repairBlockIdentity(packetId, sbn, catalogTrackName),
|
|
24892
|
+
priority,
|
|
24893
|
+
rttMs: measurement.rttMs,
|
|
24894
|
+
budgetMs: measurement.budgetMs,
|
|
24895
|
+
delayMs: measurement.delayMs,
|
|
24896
|
+
blockAgeMs: measurement.blockAgeMs,
|
|
24897
|
+
bound: measurement.bound
|
|
24898
|
+
});
|
|
24799
24899
|
}
|
|
24800
24900
|
/**
|
|
24801
24901
|
* Record a repair-scheduler decision about a delta block: preempted for
|
|
@@ -26708,6 +26808,337 @@ var CmcdProducer = class {
|
|
|
26708
26808
|
}
|
|
26709
26809
|
};
|
|
26710
26810
|
|
|
26811
|
+
// src/mmtp-fec-session.ts
|
|
26812
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
26813
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
26814
|
+
var MmtpFecSession = class {
|
|
26815
|
+
#decoder;
|
|
26816
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
26817
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
26818
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
26819
|
+
#settled = /* @__PURE__ */ new Set();
|
|
26820
|
+
/**
|
|
26821
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
26822
|
+
* received on, or 0 for one the session recovered.
|
|
26823
|
+
*/
|
|
26824
|
+
#have = /* @__PURE__ */ new Map();
|
|
26825
|
+
#newest;
|
|
26826
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
26827
|
+
#prunedAt;
|
|
26828
|
+
#repairPacketId;
|
|
26829
|
+
#stats = {
|
|
26830
|
+
sourceSymbols: 0,
|
|
26831
|
+
repairSymbols: 0,
|
|
26832
|
+
blocksClean: 0,
|
|
26833
|
+
blocksRecovered: 0,
|
|
26834
|
+
blocksFailed: 0,
|
|
26835
|
+
blocksReleased: 0,
|
|
26836
|
+
packetsRecovered: 0,
|
|
26837
|
+
packetsLost: 0,
|
|
26838
|
+
dropped: {},
|
|
26839
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
26840
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
26841
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
26842
|
+
};
|
|
26843
|
+
/**
|
|
26844
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
26845
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
26846
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
26847
|
+
*/
|
|
26848
|
+
constructor(config) {
|
|
26849
|
+
const fec = config?.fec;
|
|
26850
|
+
if (!fec || typeof fec !== "object") {
|
|
26851
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
26852
|
+
}
|
|
26853
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
26854
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
26855
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
26856
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
26857
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
26858
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
26859
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
26860
|
+
interleaveDepthMs
|
|
26861
|
+
);
|
|
26862
|
+
if (typeof config.Decoder !== "function") {
|
|
26863
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
26864
|
+
}
|
|
26865
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile);
|
|
26866
|
+
try {
|
|
26867
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
26868
|
+
} catch (error) {
|
|
26869
|
+
decoder.free();
|
|
26870
|
+
throw error;
|
|
26871
|
+
}
|
|
26872
|
+
this.#decoder = decoder;
|
|
26873
|
+
}
|
|
26874
|
+
/** True once release() ran. */
|
|
26875
|
+
get released() {
|
|
26876
|
+
return this.#decoder === null;
|
|
26877
|
+
}
|
|
26878
|
+
get stats() {
|
|
26879
|
+
return {
|
|
26880
|
+
...this.#stats,
|
|
26881
|
+
dropped: { ...this.#stats.dropped },
|
|
26882
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
26883
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
26884
|
+
mixedPath: { ...this.#stats.mixedPath }
|
|
26885
|
+
};
|
|
26886
|
+
}
|
|
26887
|
+
/**
|
|
26888
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
26889
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
26890
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
26891
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
26892
|
+
*
|
|
26893
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
26894
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
26895
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
26896
|
+
*/
|
|
26897
|
+
addSource(ssId, packet, path = "moq") {
|
|
26898
|
+
const decoder = this.#decoder;
|
|
26899
|
+
if (!decoder) return this.#drop("source:released");
|
|
26900
|
+
const pathBit = PATH_BITS[path];
|
|
26901
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
26902
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
26903
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
26904
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
26905
|
+
this.#have.set(ssId, pathBit);
|
|
26906
|
+
this.#stats.sourceSymbols++;
|
|
26907
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
26908
|
+
this.#noteNewest(ssId);
|
|
26909
|
+
const start = this.#blockStartOf(ssId);
|
|
26910
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
26911
|
+
if (block) {
|
|
26912
|
+
block.received++;
|
|
26913
|
+
block.paths |= pathBit;
|
|
26914
|
+
}
|
|
26915
|
+
let output;
|
|
26916
|
+
try {
|
|
26917
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
26918
|
+
} catch {
|
|
26919
|
+
this.#drop("source:decoder-refused");
|
|
26920
|
+
output = void 0;
|
|
26921
|
+
}
|
|
26922
|
+
const recovered = [];
|
|
26923
|
+
if (start !== void 0 && block) {
|
|
26924
|
+
if (output) {
|
|
26925
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
26926
|
+
} else if (block.received >= block.ssbLength) {
|
|
26927
|
+
this.#settleClean(start);
|
|
26928
|
+
}
|
|
26929
|
+
}
|
|
26930
|
+
this.#retireBehindHorizon();
|
|
26931
|
+
return recovered;
|
|
26932
|
+
}
|
|
26933
|
+
/**
|
|
26934
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
26935
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
26936
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
26937
|
+
* `path` is where it was received, as for addSource().
|
|
26938
|
+
*
|
|
26939
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
26940
|
+
* addSource().
|
|
26941
|
+
*/
|
|
26942
|
+
addRepair(packet, path = "moq") {
|
|
26943
|
+
const decoder = this.#decoder;
|
|
26944
|
+
if (!decoder) return this.#drop("repair:released");
|
|
26945
|
+
const pathBit = PATH_BITS[path];
|
|
26946
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
26947
|
+
let header;
|
|
26948
|
+
try {
|
|
26949
|
+
header = parseMMTPHeader(packet);
|
|
26950
|
+
} catch {
|
|
26951
|
+
return this.#drop("repair:malformed");
|
|
26952
|
+
}
|
|
26953
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
26954
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
26955
|
+
if (this.#repairPacketId === void 0) {
|
|
26956
|
+
this.#repairPacketId = frame.packetId;
|
|
26957
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
26958
|
+
return this.#drop("repair:foreign-packet-id");
|
|
26959
|
+
}
|
|
26960
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
26961
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
26962
|
+
const start = frame.ssStart;
|
|
26963
|
+
let block = this.#blocks.get(start);
|
|
26964
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
26965
|
+
if (!block) {
|
|
26966
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
26967
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
26968
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0 };
|
|
26969
|
+
this.#countHeld(start, block);
|
|
26970
|
+
this.#blocks.set(start, block);
|
|
26971
|
+
}
|
|
26972
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
26973
|
+
if (block.received >= block.ssbLength) {
|
|
26974
|
+
this.#settleClean(start);
|
|
26975
|
+
this.#retireBehindHorizon();
|
|
26976
|
+
return [];
|
|
26977
|
+
}
|
|
26978
|
+
let output;
|
|
26979
|
+
try {
|
|
26980
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
26981
|
+
} catch {
|
|
26982
|
+
return this.#drop("repair:decoder-refused");
|
|
26983
|
+
}
|
|
26984
|
+
this.#stats.repairSymbols++;
|
|
26985
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
26986
|
+
block.paths |= pathBit;
|
|
26987
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
26988
|
+
this.#retireBehindHorizon();
|
|
26989
|
+
return recovered;
|
|
26990
|
+
}
|
|
26991
|
+
/**
|
|
26992
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
26993
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
26994
|
+
* returns whether this call released anything.
|
|
26995
|
+
*/
|
|
26996
|
+
release() {
|
|
26997
|
+
const decoder = this.#decoder;
|
|
26998
|
+
if (!decoder) return false;
|
|
26999
|
+
this.#decoder = null;
|
|
27000
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
27001
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
27002
|
+
this.#blocks.clear();
|
|
27003
|
+
this.#settled.clear();
|
|
27004
|
+
this.#have.clear();
|
|
27005
|
+
decoder.free();
|
|
27006
|
+
return true;
|
|
27007
|
+
}
|
|
27008
|
+
#drop(reason) {
|
|
27009
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
27010
|
+
return [];
|
|
27011
|
+
}
|
|
27012
|
+
#noteNewest(ssId) {
|
|
27013
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
27014
|
+
}
|
|
27015
|
+
#blockStartOf(ssId) {
|
|
27016
|
+
for (const [start, block] of this.#blocks) {
|
|
27017
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
27018
|
+
}
|
|
27019
|
+
return void 0;
|
|
27020
|
+
}
|
|
27021
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
27022
|
+
#countHeld(start, block) {
|
|
27023
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27024
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
27025
|
+
if (pathBit === void 0) continue;
|
|
27026
|
+
block.received++;
|
|
27027
|
+
block.paths |= pathBit;
|
|
27028
|
+
}
|
|
27029
|
+
}
|
|
27030
|
+
#noteMixed(block, outcome) {
|
|
27031
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
27032
|
+
}
|
|
27033
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
27034
|
+
#behindHorizon(start) {
|
|
27035
|
+
const newest = this.#newest;
|
|
27036
|
+
if (newest === void 0) return false;
|
|
27037
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
27038
|
+
}
|
|
27039
|
+
#settle(start) {
|
|
27040
|
+
this.#blocks.delete(start);
|
|
27041
|
+
this.#settled.add(start);
|
|
27042
|
+
}
|
|
27043
|
+
#settleClean(start) {
|
|
27044
|
+
const block = this.#blocks.get(start);
|
|
27045
|
+
if (!block) return;
|
|
27046
|
+
this.#settle(start);
|
|
27047
|
+
this.#stats.blocksClean++;
|
|
27048
|
+
this.#noteMixed(block, "clean");
|
|
27049
|
+
try {
|
|
27050
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
27051
|
+
} catch {
|
|
27052
|
+
}
|
|
27053
|
+
}
|
|
27054
|
+
/**
|
|
27055
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
27056
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
27057
|
+
* back the packets the parser does not have yet.
|
|
27058
|
+
*/
|
|
27059
|
+
#settleDecoded(start, block, output) {
|
|
27060
|
+
this.#settle(start);
|
|
27061
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
27062
|
+
this.#stats.blocksFailed++;
|
|
27063
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27064
|
+
this.#noteMixed(block, "failed");
|
|
27065
|
+
this.#drop("block:decoded-length");
|
|
27066
|
+
return [];
|
|
27067
|
+
}
|
|
27068
|
+
const recovered = [];
|
|
27069
|
+
let refused = 0;
|
|
27070
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27071
|
+
const ssId = serial32Add(start, i);
|
|
27072
|
+
if (this.#have.has(ssId)) continue;
|
|
27073
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
27074
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
27075
|
+
if (!packet) {
|
|
27076
|
+
refused++;
|
|
27077
|
+
continue;
|
|
27078
|
+
}
|
|
27079
|
+
this.#have.set(ssId, 0);
|
|
27080
|
+
recovered.push(packet.slice());
|
|
27081
|
+
}
|
|
27082
|
+
if (refused > 0) {
|
|
27083
|
+
this.#stats.blocksFailed++;
|
|
27084
|
+
this.#stats.packetsLost += refused;
|
|
27085
|
+
this.#noteMixed(block, "failed");
|
|
27086
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
27087
|
+
} else if (recovered.length === 0) {
|
|
27088
|
+
this.#stats.blocksClean++;
|
|
27089
|
+
this.#noteMixed(block, "clean");
|
|
27090
|
+
} else {
|
|
27091
|
+
this.#stats.blocksRecovered++;
|
|
27092
|
+
this.#noteMixed(block, "recovered");
|
|
27093
|
+
}
|
|
27094
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
27095
|
+
return recovered;
|
|
27096
|
+
}
|
|
27097
|
+
/**
|
|
27098
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
27099
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
27100
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
27101
|
+
* restore, or its repair never arrived.
|
|
27102
|
+
*/
|
|
27103
|
+
#retireBehindHorizon() {
|
|
27104
|
+
const decoder = this.#decoder;
|
|
27105
|
+
const newest = this.#newest;
|
|
27106
|
+
if (!decoder || newest === void 0) return;
|
|
27107
|
+
try {
|
|
27108
|
+
decoder.cleanup_by_ss_start(newest);
|
|
27109
|
+
} catch {
|
|
27110
|
+
}
|
|
27111
|
+
for (const [start, block] of this.#blocks) {
|
|
27112
|
+
if (!this.#behindHorizon(start)) continue;
|
|
27113
|
+
this.#settle(start);
|
|
27114
|
+
this.#stats.blocksFailed++;
|
|
27115
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27116
|
+
this.#noteMixed(block, "failed");
|
|
27117
|
+
}
|
|
27118
|
+
const prunedAt = this.#prunedAt;
|
|
27119
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
27120
|
+
this.#prunedAt = newest;
|
|
27121
|
+
for (const ssId of this.#have.keys()) {
|
|
27122
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
27123
|
+
}
|
|
27124
|
+
for (const start of this.#settled) {
|
|
27125
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
27126
|
+
}
|
|
27127
|
+
}
|
|
27128
|
+
};
|
|
27129
|
+
function requirePositiveInteger(value, path) {
|
|
27130
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
27131
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
27132
|
+
}
|
|
27133
|
+
return value;
|
|
27134
|
+
}
|
|
27135
|
+
function requireNumber(value, path) {
|
|
27136
|
+
if (typeof value !== "number") {
|
|
27137
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
27138
|
+
}
|
|
27139
|
+
return value;
|
|
27140
|
+
}
|
|
27141
|
+
|
|
26711
27142
|
// src/repair-fetch.ts
|
|
26712
27143
|
var MOQT_PRIORITY_MAX = 255;
|
|
26713
27144
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
@@ -26788,7 +27219,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26788
27219
|
const admit = (entry, now) => {
|
|
26789
27220
|
const budgetMs = entry.deadlineAt - now;
|
|
26790
27221
|
const rttMs = readRtt();
|
|
26791
|
-
if (rttMs !== null && rttMs < budgetMs) return
|
|
27222
|
+
if (rttMs !== null && rttMs < budgetMs) return rttMs;
|
|
26792
27223
|
retire(entry);
|
|
26793
27224
|
releaseHold(entry);
|
|
26794
27225
|
clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
@@ -26799,7 +27230,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26799
27230
|
entry.packetId,
|
|
26800
27231
|
entry.catalogTrackName
|
|
26801
27232
|
);
|
|
26802
|
-
return
|
|
27233
|
+
return null;
|
|
26803
27234
|
};
|
|
26804
27235
|
const retire = (entry) => {
|
|
26805
27236
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
@@ -26831,9 +27262,17 @@ function wireRepairFetch(mc, opts) {
|
|
|
26831
27262
|
return derived.kind === "omit" ? { subscriberPriority: void 0 } : null;
|
|
26832
27263
|
};
|
|
26833
27264
|
const start = (entry, counted = true) => {
|
|
26834
|
-
|
|
27265
|
+
const now = performance.now();
|
|
27266
|
+
const rttMs = admit(entry, now);
|
|
27267
|
+
if (rttMs === null) return;
|
|
26835
27268
|
if (counted) entry.attempts++;
|
|
26836
|
-
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName
|
|
27269
|
+
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
27270
|
+
rttMs,
|
|
27271
|
+
budgetMs: entry.deadlineAt - now,
|
|
27272
|
+
delayMs: entry.delayMs,
|
|
27273
|
+
blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
|
|
27274
|
+
bound: entry.bound
|
|
27275
|
+
});
|
|
26837
27276
|
const run = { controller: new AbortController(), stopped: null };
|
|
26838
27277
|
entry.running = run;
|
|
26839
27278
|
mc.fecManager.holdBlockForRepair(
|
|
@@ -26980,6 +27419,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26980
27419
|
);
|
|
26981
27420
|
if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
|
|
26982
27421
|
entry2.deadlineAt = promotedDeadline.deadlineAt;
|
|
27422
|
+
entry2.anchorAt = promotedDeadline.anchorAt;
|
|
27423
|
+
entry2.delayMs = promotedDeadline.delayMs;
|
|
27424
|
+
entry2.bound = promotedDeadline.bound;
|
|
26983
27425
|
noteBudget(entry2, promotedDeadline.extensionMs);
|
|
26984
27426
|
}
|
|
26985
27427
|
if (entry2.running) {
|
|
@@ -27005,7 +27447,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
27005
27447
|
if (waitMs === void 0) return null;
|
|
27006
27448
|
const waitDeadlineAt = now + waitMs;
|
|
27007
27449
|
const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
|
|
27008
|
-
if (anchor === void 0)
|
|
27450
|
+
if (anchor === void 0) {
|
|
27451
|
+
return { deadlineAt: waitDeadlineAt, extensionMs: 0, anchorAt: null, delayMs: null, bound: "wait" };
|
|
27452
|
+
}
|
|
27009
27453
|
let delayMs;
|
|
27010
27454
|
try {
|
|
27011
27455
|
delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
|
|
@@ -27016,12 +27460,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
27016
27460
|
const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
|
|
27017
27461
|
if (retentionMs === void 0) return null;
|
|
27018
27462
|
const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
|
|
27019
|
-
const
|
|
27020
|
-
|
|
27463
|
+
const at = (delay, delayBound) => {
|
|
27464
|
+
const presentAt = Math.min(anchor + delay, ceilingAt);
|
|
27465
|
+
if (waitDeadlineAt >= presentAt) return { deadlineAt: waitDeadlineAt, bound: "wait" };
|
|
27466
|
+
return { deadlineAt: presentAt, bound: anchor + delay <= ceilingAt ? delayBound : "retention" };
|
|
27467
|
+
};
|
|
27468
|
+
const base = at(delayMs, "presentation");
|
|
27021
27469
|
const budgetMs = keyframeBudgetEligible(blockClass, classifierMode(packetId, catalogTrackName)) && groupCanComplete(sbn, packetId, catalogTrackName) ? readKeyframeBudget(packetId, catalogTrackName) : null;
|
|
27022
|
-
if (budgetMs === null || budgetMs <= delayMs) return {
|
|
27023
|
-
const extended =
|
|
27024
|
-
return {
|
|
27470
|
+
if (budgetMs === null || budgetMs <= delayMs) return { ...base, extensionMs: 0, anchorAt: anchor, delayMs };
|
|
27471
|
+
const extended = at(budgetMs, "keyframe");
|
|
27472
|
+
return {
|
|
27473
|
+
...extended,
|
|
27474
|
+
extensionMs: extended.deadlineAt - base.deadlineAt,
|
|
27475
|
+
anchorAt: anchor,
|
|
27476
|
+
delayMs: budgetMs
|
|
27477
|
+
};
|
|
27025
27478
|
};
|
|
27026
27479
|
const earliestGatedFrameAt = (packetId, catalogTrackName) => {
|
|
27027
27480
|
try {
|
|
@@ -27098,6 +27551,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
27098
27551
|
priority,
|
|
27099
27552
|
subscriberPriority: wire.subscriberPriority,
|
|
27100
27553
|
deadlineAt: deadline.deadlineAt,
|
|
27554
|
+
anchorAt: deadline.anchorAt,
|
|
27555
|
+
delayMs: deadline.delayMs,
|
|
27556
|
+
bound: deadline.bound,
|
|
27101
27557
|
order: enqueueOrder++,
|
|
27102
27558
|
attempts: 0,
|
|
27103
27559
|
running: null
|
|
@@ -27153,6 +27609,7 @@ export {
|
|
|
27153
27609
|
MfuReassemblyError,
|
|
27154
27610
|
MmtpContainerParser,
|
|
27155
27611
|
MmtpDecodePipeline,
|
|
27612
|
+
MmtpFecSession,
|
|
27156
27613
|
MmtpRouter,
|
|
27157
27614
|
MmtpToCmaf,
|
|
27158
27615
|
MulticastContainerContractError,
|