@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.bd9f80b4a95e
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 +31 -17
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +1409 -395
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +71 -36
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +306 -200
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- 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/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +18 -12
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +111 -6
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +326 -29
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +5 -2
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +38 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +108 -17
- package/dist/iso-block-locator.js.map +3 -3
- 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 +331 -1171
- 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 +1029 -290
- 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 +159 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +531 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +25 -2
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +48 -5
- 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 +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +45 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +469 -65
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +6 -0
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +18 -11
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +979 -275
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- 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 +2710 -7
- package/dist/source-auth.js.map +4 -4
- 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 +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +156 -59
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +346 -19
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +14 -1
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +109 -7
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-fec-session.ts +533 -0
- package/src/mmtp-router.ts +90 -2
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +124 -14
- package/src/multicast-transport.ts +3 -0
- package/src/no-modules.ts +7 -1
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +66 -3
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- 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-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -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/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -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-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.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/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- 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/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +6 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
package/dist/browser-runtime.js
CHANGED
|
@@ -1007,19 +1007,275 @@ function catalogFecAvailable(fec) {
|
|
|
1007
1007
|
const block = recordOf(fec);
|
|
1008
1008
|
if (block === void 0)
|
|
1009
1009
|
return true;
|
|
1010
|
+
if (fecAlgorithmUnimplemented(block["algorithm"]))
|
|
1011
|
+
return false;
|
|
1010
1012
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
1011
1013
|
const profile = block["blockProfile"];
|
|
1012
1014
|
const profileOk = isFecBlockProfile(profile) || profile === void 0 && !declaresFecInstance;
|
|
1013
1015
|
return profileOk && (!declaresFecInstance || isoBlockSpanUsable(block));
|
|
1014
1016
|
}
|
|
1017
|
+
function fecAlgorithmUnimplemented(algorithm) {
|
|
1018
|
+
return typeof algorithm === "string" && algorithm !== "none" && algorithm !== "raptorq" && algorithm !== "reed-solomon";
|
|
1019
|
+
}
|
|
1015
1020
|
function isPositiveSafeInteger(value) {
|
|
1016
1021
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
1017
1022
|
}
|
|
1023
|
+
var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
|
|
1018
1024
|
function catalogFecDeclaresUnconfigurableInstance(fec) {
|
|
1019
1025
|
const block = recordOf(fec);
|
|
1020
|
-
if (block === void 0 || block["algorithm"] === "none")
|
|
1026
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"]))
|
|
1021
1027
|
return false;
|
|
1022
|
-
|
|
1028
|
+
if (!(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"])))
|
|
1029
|
+
return true;
|
|
1030
|
+
return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// ../mmt-base/dist/multicast-catalog.js
|
|
1034
|
+
var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
1035
|
+
var UINT32_MAX = 4294967295;
|
|
1036
|
+
var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
|
|
1037
|
+
var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
|
|
1038
|
+
var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
|
|
1039
|
+
"manifestPort",
|
|
1040
|
+
"streamId",
|
|
1041
|
+
"senderAddress",
|
|
1042
|
+
"maxAuthDelayMs",
|
|
1043
|
+
"manifestTimerMs",
|
|
1044
|
+
"manifestTrack"
|
|
1045
|
+
]);
|
|
1046
|
+
function isObject(value) {
|
|
1047
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1048
|
+
}
|
|
1049
|
+
function isNonEmptyString(value) {
|
|
1050
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
1051
|
+
}
|
|
1052
|
+
function isIntegerIn(value, min, max) {
|
|
1053
|
+
return Number.isSafeInteger(value) && value >= min && value <= max;
|
|
1054
|
+
}
|
|
1055
|
+
function multicastEndpointSource(endpoint) {
|
|
1056
|
+
if (!isObject(endpoint))
|
|
1057
|
+
return void 0;
|
|
1058
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
1059
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
|
|
1060
|
+
return void 0;
|
|
1061
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
1062
|
+
const protocol = endpoint["protocol"];
|
|
1063
|
+
if (protocol !== void 0 && protocol !== mode)
|
|
1064
|
+
return void 0;
|
|
1065
|
+
const auth = endpoint["auth"];
|
|
1066
|
+
const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
|
|
1067
|
+
if (mode === "ssm")
|
|
1068
|
+
return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
|
|
1069
|
+
if (auth === void 0)
|
|
1070
|
+
return { mode };
|
|
1071
|
+
return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
|
|
1072
|
+
}
|
|
1073
|
+
function authIssues(auth) {
|
|
1074
|
+
const base = "$.multicast.auth";
|
|
1075
|
+
const issue = (path, message) => [
|
|
1076
|
+
{ code: "multicast_auth", path: `${base}${path}`, message }
|
|
1077
|
+
];
|
|
1078
|
+
if (!isObject(auth))
|
|
1079
|
+
return issue("", "auth must be an object");
|
|
1080
|
+
const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
|
|
1081
|
+
if (unknown.length > 0) {
|
|
1082
|
+
return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
|
|
1083
|
+
}
|
|
1084
|
+
if (auth["scheme"] !== "bc-provenance")
|
|
1085
|
+
return issue(".scheme", 'scheme must be "bc-provenance"');
|
|
1086
|
+
if (auth["version"] !== 2)
|
|
1087
|
+
return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
|
|
1088
|
+
if (auth["sig"] !== "ed25519")
|
|
1089
|
+
return issue(".sig", 'sig must be "ed25519"');
|
|
1090
|
+
const keys = auth["keys"];
|
|
1091
|
+
if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
|
|
1092
|
+
return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
|
|
1093
|
+
}
|
|
1094
|
+
const kids = /* @__PURE__ */ new Set();
|
|
1095
|
+
const firstEpochs = /* @__PURE__ */ new Set();
|
|
1096
|
+
for (let index = 0; index < keys.length; index++) {
|
|
1097
|
+
const key = keys[index];
|
|
1098
|
+
const at = `.keys[${index}]`;
|
|
1099
|
+
if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
|
|
1100
|
+
return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
|
|
1101
|
+
}
|
|
1102
|
+
if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
|
|
1103
|
+
return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
|
|
1104
|
+
if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
|
|
1105
|
+
return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
|
|
1106
|
+
}
|
|
1107
|
+
if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
|
|
1108
|
+
return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
|
|
1109
|
+
}
|
|
1110
|
+
if (kids.has(key["kid"]))
|
|
1111
|
+
return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
|
|
1112
|
+
if (firstEpochs.has(key["firstEpoch"])) {
|
|
1113
|
+
return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
|
|
1114
|
+
}
|
|
1115
|
+
kids.add(key["kid"]);
|
|
1116
|
+
firstEpochs.add(key["firstEpoch"]);
|
|
1117
|
+
}
|
|
1118
|
+
if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
|
|
1119
|
+
return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
|
|
1120
|
+
}
|
|
1121
|
+
return [];
|
|
1122
|
+
}
|
|
1123
|
+
function endpointAuthIssue(endpoint, mode, at) {
|
|
1124
|
+
const auth = endpoint["auth"];
|
|
1125
|
+
if (!isObject(auth))
|
|
1126
|
+
return { path: `${at}.auth`, message: "auth must be an object" };
|
|
1127
|
+
const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
|
|
1128
|
+
if (unknown.length > 0)
|
|
1129
|
+
return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
|
|
1130
|
+
if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
|
|
1131
|
+
return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
|
|
1132
|
+
}
|
|
1133
|
+
if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
|
|
1134
|
+
return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
|
|
1135
|
+
}
|
|
1136
|
+
if (mode === "ssm" && auth["senderAddress"] !== void 0) {
|
|
1137
|
+
return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
|
|
1138
|
+
}
|
|
1139
|
+
if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
|
|
1140
|
+
return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
|
|
1141
|
+
}
|
|
1142
|
+
if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
|
|
1143
|
+
return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
|
|
1144
|
+
}
|
|
1145
|
+
if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
1146
|
+
return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
|
|
1147
|
+
}
|
|
1148
|
+
if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
|
|
1149
|
+
return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
|
|
1150
|
+
}
|
|
1151
|
+
if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
1152
|
+
return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
|
|
1153
|
+
}
|
|
1154
|
+
return void 0;
|
|
1155
|
+
}
|
|
1156
|
+
var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
|
|
1157
|
+
function multicastCatalogIssues(catalog, options = {}) {
|
|
1158
|
+
if (!isObject(catalog))
|
|
1159
|
+
return [];
|
|
1160
|
+
const issues = [];
|
|
1161
|
+
if ("multicast.auth" in catalog) {
|
|
1162
|
+
issues.push({
|
|
1163
|
+
code: "multicast_auth",
|
|
1164
|
+
path: '$["multicast.auth"]',
|
|
1165
|
+
message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
const multicast = catalog["multicast"];
|
|
1169
|
+
if (!isObject(multicast))
|
|
1170
|
+
return issues;
|
|
1171
|
+
const protectedCatalog = multicast["auth"] !== void 0;
|
|
1172
|
+
if (protectedCatalog)
|
|
1173
|
+
issues.push(...authIssues(multicast["auth"]));
|
|
1174
|
+
const endpoints = multicast["endpoints"];
|
|
1175
|
+
if (!Array.isArray(endpoints))
|
|
1176
|
+
return issues;
|
|
1177
|
+
const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
|
|
1178
|
+
const namespaceOf = /* @__PURE__ */ new Map();
|
|
1179
|
+
for (const track of tracks) {
|
|
1180
|
+
if (isObject(track) && typeof track["name"] === "string")
|
|
1181
|
+
namespaceOf.set(track["name"], track["namespace"]);
|
|
1182
|
+
}
|
|
1183
|
+
const tagged = catalog[CATALOG_NAMESPACE];
|
|
1184
|
+
let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
|
|
1185
|
+
const sources = [];
|
|
1186
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
1187
|
+
const endpoint = endpoints[index];
|
|
1188
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
1189
|
+
const fail = (code, path, message) => {
|
|
1190
|
+
issues.push({ code, path, message, endpointIndex: index });
|
|
1191
|
+
};
|
|
1192
|
+
sources.push(void 0);
|
|
1193
|
+
if (!isObject(endpoint)) {
|
|
1194
|
+
fail("multicast_endpoint", at, "endpoint must be an object");
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
const protocol = endpoint["protocol"];
|
|
1198
|
+
if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
|
|
1199
|
+
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)`);
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1202
|
+
const hasAuth = endpoint["auth"] !== void 0;
|
|
1203
|
+
if (protectedCatalog !== hasAuth) {
|
|
1204
|
+
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");
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
1208
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
|
|
1209
|
+
fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
1213
|
+
if (protocol !== void 0 && protocol !== mode) {
|
|
1214
|
+
fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
if (!isIntegerIn(endpoint["port"], 1, 65535)) {
|
|
1218
|
+
fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
if (hasAuth) {
|
|
1222
|
+
const authIssue = endpointAuthIssue(endpoint, mode, at);
|
|
1223
|
+
if (authIssue) {
|
|
1224
|
+
fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
sources[index] = multicastEndpointSource(endpoint);
|
|
1229
|
+
const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
|
|
1230
|
+
for (let refIndex = 0; refIndex < refs.length; refIndex++) {
|
|
1231
|
+
const ref = refs[refIndex];
|
|
1232
|
+
const name = isObject(ref) ? ref["name"] : ref;
|
|
1233
|
+
if (typeof name !== "string")
|
|
1234
|
+
continue;
|
|
1235
|
+
const namespace = namespaceOf.get(name);
|
|
1236
|
+
if (typeof namespace !== "string")
|
|
1237
|
+
continue;
|
|
1238
|
+
referenceNamespace ??= namespace;
|
|
1239
|
+
if (namespace !== referenceNamespace) {
|
|
1240
|
+
fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
const tupleOf = (index) => {
|
|
1245
|
+
const endpoint = endpoints[index];
|
|
1246
|
+
const auth = endpoint["auth"];
|
|
1247
|
+
return {
|
|
1248
|
+
sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
|
|
1249
|
+
port: endpoint["port"],
|
|
1250
|
+
manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
|
|
1251
|
+
};
|
|
1252
|
+
};
|
|
1253
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
1254
|
+
if (!sources[index])
|
|
1255
|
+
continue;
|
|
1256
|
+
const own = tupleOf(index);
|
|
1257
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
1258
|
+
if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
|
|
1259
|
+
issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
for (let other = 0; other < endpoints.length; other++) {
|
|
1263
|
+
if (other === index || !sources[other])
|
|
1264
|
+
continue;
|
|
1265
|
+
const peer = tupleOf(other);
|
|
1266
|
+
if (peer.sg !== own.sg)
|
|
1267
|
+
continue;
|
|
1268
|
+
if (peer.port === own.port) {
|
|
1269
|
+
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 });
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1272
|
+
if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
|
|
1273
|
+
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 });
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return issues;
|
|
1023
1279
|
}
|
|
1024
1280
|
|
|
1025
1281
|
// src/mfu-reassembler.ts
|
|
@@ -6023,197 +6279,6 @@ if (void 0) {
|
|
|
6023
6279
|
});
|
|
6024
6280
|
}
|
|
6025
6281
|
|
|
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
6282
|
// src/repair-layers.ts
|
|
6218
6283
|
var REPAIR_PRIORITY_MIN = 192;
|
|
6219
6284
|
var REPAIR_PRIORITY_MAX = 255;
|
|
@@ -6221,6 +6286,7 @@ var DEFAULT_REPAIR_PRIORITY = 240;
|
|
|
6221
6286
|
var MAX_RAPTORQ_SOURCE_SYMBOLS = 56403;
|
|
6222
6287
|
var MAX_REPAIR_SYMBOLS = 16777215;
|
|
6223
6288
|
var MAX_ENCODING_SYMBOL_ID = 16777215;
|
|
6289
|
+
var MAX_REED_SOLOMON_BLOCK_SYMBOLS = 255;
|
|
6224
6290
|
var RepairContractError = class extends Error {
|
|
6225
6291
|
constructor(code, path, message) {
|
|
6226
6292
|
super(`[repair-layers:${code}] ${path}: ${message}`);
|
|
@@ -6403,11 +6469,12 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6403
6469
|
if (layered && !positiveInteger(source.sourceSymbols)) {
|
|
6404
6470
|
fail("track_fec", `${source.path}.sourceSymbols`, "layered or overlay repair needs a positive integer sourceSymbols on the source");
|
|
6405
6471
|
}
|
|
6406
|
-
|
|
6472
|
+
const reedSolomon = source.algorithm === "reed-solomon";
|
|
6473
|
+
if (layered && source.algorithm !== "raptorq" && !reedSolomon) {
|
|
6407
6474
|
fail(
|
|
6408
6475
|
"track_fec",
|
|
6409
6476
|
`${source.path}.algorithm`,
|
|
6410
|
-
"repair layers and overlays are defined only for raptorq
|
|
6477
|
+
"repair layers and overlays are defined only for raptorq and reed-solomon (draft-ramadan-moq-fec-01 6.3.4 rule 7)"
|
|
6411
6478
|
);
|
|
6412
6479
|
}
|
|
6413
6480
|
let layerZeroPriority = DEFAULT_REPAIR_PRIORITY;
|
|
@@ -6466,6 +6533,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6466
6533
|
`overlay sourceSymbols + repairSymbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
6467
6534
|
);
|
|
6468
6535
|
}
|
|
6536
|
+
if (reedSolomon && sourceSymbols + repairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
|
|
6537
|
+
fail(
|
|
6538
|
+
"track_fec_bounds",
|
|
6539
|
+
`${d.path}.repairSymbols`,
|
|
6540
|
+
`reed-solomon overlay sourceSymbols + repairSymbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
|
|
6541
|
+
);
|
|
6542
|
+
}
|
|
6469
6543
|
overlays.push({ repairTrackName: d.name, scope: "keyframe", sourceSymbols, repairSymbols, priority: d.priority });
|
|
6470
6544
|
}
|
|
6471
6545
|
let offset = layerZeroSymbols;
|
|
@@ -6510,6 +6584,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6510
6584
|
`sourceSymbols + total base repair symbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
6511
6585
|
);
|
|
6512
6586
|
}
|
|
6587
|
+
if (reedSolomon && k + totalBaseRepairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
|
|
6588
|
+
fail(
|
|
6589
|
+
"track_fec_bounds",
|
|
6590
|
+
`${source.path}.sourceSymbols`,
|
|
6591
|
+
`reed-solomon sourceSymbols + total base repair symbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
|
|
6592
|
+
);
|
|
6593
|
+
}
|
|
6513
6594
|
return { sourceTrackName: source.name, baseLayers, overlays, totalBaseRepairSymbols };
|
|
6514
6595
|
}
|
|
6515
6596
|
|
|
@@ -6557,7 +6638,7 @@ function isFecCatalogGeometry(obj) {
|
|
|
6557
6638
|
const o = obj;
|
|
6558
6639
|
const algorithm = o["algorithm"];
|
|
6559
6640
|
const symbolSize = o["symbolSize"];
|
|
6560
|
-
return typeof algorithm === "string" &&
|
|
6641
|
+
return typeof algorithm === "string" && algorithm.length > 0 && typeof o["sourceSymbols"] === "number" && o["sourceSymbols"] >= 1 && typeof o["repairSymbols"] === "number" && o["repairSymbols"] >= 1 && typeof symbolSize === "number" && symbolSize >= 1 && (algorithm !== "raptorq" || symbolSize % 8 === 0) && typeof o["repairTrack"] === "string" && o["repairTrack"].length > 0;
|
|
6561
6642
|
}
|
|
6562
6643
|
function isFecCatalogConfig(obj) {
|
|
6563
6644
|
if (!isFecCatalogGeometry(obj)) return false;
|
|
@@ -6572,8 +6653,7 @@ function isMulticastTrackObject(obj) {
|
|
|
6572
6653
|
function isMulticastEndpoint(obj) {
|
|
6573
6654
|
if (typeof obj !== "object" || obj === null) return false;
|
|
6574
6655
|
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));
|
|
6656
|
+
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
6657
|
}
|
|
6578
6658
|
function isMulticastCatalogConfig(obj) {
|
|
6579
6659
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -6677,13 +6757,22 @@ var CmsfCatalogValidationError = class extends Error {
|
|
|
6677
6757
|
function catalogError(code, path, message) {
|
|
6678
6758
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
6679
6759
|
}
|
|
6680
|
-
function
|
|
6760
|
+
function validateNetworkSourceRelays(sources, path) {
|
|
6761
|
+
if (!Array.isArray(sources)) return;
|
|
6762
|
+
sources.forEach((source, i) => {
|
|
6763
|
+
const s = source;
|
|
6764
|
+
if (s?.["type"] === "amt" && s["discovery"] === "driad" && s["relay"] !== void 0) {
|
|
6765
|
+
catalogError("multicast_network_source", `${path}[${i}].relay`, 'relay must be omitted with discovery "driad"');
|
|
6766
|
+
}
|
|
6767
|
+
});
|
|
6768
|
+
}
|
|
6769
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
6681
6770
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
6682
6771
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
6683
6772
|
}
|
|
6684
6773
|
const catalog = value;
|
|
6685
6774
|
const rawVersion = catalog["version"];
|
|
6686
|
-
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") ? 1 : NaN : rawVersion;
|
|
6775
|
+
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") || rawVersion === "draft-01" ? 1 : NaN : rawVersion;
|
|
6687
6776
|
if (!Number.isInteger(normalizedVersion) || normalizedVersion <= 0) {
|
|
6688
6777
|
catalogError("catalog_version", "$.version", "version must be a positive integer or a recognized format tag");
|
|
6689
6778
|
}
|
|
@@ -6698,6 +6787,22 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6698
6787
|
"commonTrackFields is retired; every track carries its own fields"
|
|
6699
6788
|
);
|
|
6700
6789
|
}
|
|
6790
|
+
const initDataList = catalog["initDataList"];
|
|
6791
|
+
if (initDataList !== void 0) {
|
|
6792
|
+
if (!Array.isArray(initDataList)) {
|
|
6793
|
+
catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
|
|
6794
|
+
}
|
|
6795
|
+
initDataList.forEach((entry, i) => {
|
|
6796
|
+
const e = entry;
|
|
6797
|
+
const entryPath = `$.initDataList[${i}]`;
|
|
6798
|
+
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) {
|
|
6799
|
+
catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
|
|
6800
|
+
}
|
|
6801
|
+
if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
|
|
6802
|
+
catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
|
|
6803
|
+
}
|
|
6804
|
+
});
|
|
6805
|
+
}
|
|
6701
6806
|
const tracks = catalog["tracks"];
|
|
6702
6807
|
const trackRecords = [];
|
|
6703
6808
|
const positiveInteger3 = (input) => Number.isSafeInteger(input) && input > 0;
|
|
@@ -6749,6 +6854,14 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6749
6854
|
if (keyframeIntervalMs !== void 0 && !positiveNumber2(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger3(keyframeIntervalTicks)) {
|
|
6750
6855
|
catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
|
|
6751
6856
|
}
|
|
6857
|
+
const anchor = track["presentationAnchorTicks"];
|
|
6858
|
+
if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
|
|
6859
|
+
catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
|
|
6860
|
+
}
|
|
6861
|
+
const initRef = track["initRef"];
|
|
6862
|
+
if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
|
|
6863
|
+
catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
|
|
6864
|
+
}
|
|
6752
6865
|
if (packaging === "fec-repair") {
|
|
6753
6866
|
rejectRepairTrackGeometry(path, track, catalogError);
|
|
6754
6867
|
validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
|
|
@@ -6756,9 +6869,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6756
6869
|
rejectRepairFieldsOnMediaTrack(path, track, catalogError);
|
|
6757
6870
|
}
|
|
6758
6871
|
if (packaging === "mmtp") {
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
|
|
6872
|
+
if (track["mmtpMode"] !== "mfu") {
|
|
6873
|
+
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
|
|
6762
6874
|
}
|
|
6763
6875
|
if (!positiveInteger3(timescale)) {
|
|
6764
6876
|
catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
|
|
@@ -6781,8 +6893,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6781
6893
|
}
|
|
6782
6894
|
const config = fec;
|
|
6783
6895
|
const algorithm = config["algorithm"];
|
|
6784
|
-
if (
|
|
6785
|
-
catalogError("track_fec", `${path}.fec.algorithm`, "
|
|
6896
|
+
if (typeof algorithm !== "string" || algorithm.length === 0) {
|
|
6897
|
+
catalogError("track_fec", `${path}.fec.algorithm`, "must be a non-empty string");
|
|
6786
6898
|
}
|
|
6787
6899
|
if ("interleaveDepth" in config || "interleaveMs" in config) {
|
|
6788
6900
|
catalogError("track_fec", `${path}.fec`, "interleaveDepthMs is the only supported interleave field");
|
|
@@ -6811,6 +6923,9 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6811
6923
|
}
|
|
6812
6924
|
}
|
|
6813
6925
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
6926
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
6927
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
6928
|
+
}
|
|
6814
6929
|
}
|
|
6815
6930
|
}
|
|
6816
6931
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -6878,11 +6993,16 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6878
6993
|
}
|
|
6879
6994
|
const multicast = catalog["multicast"];
|
|
6880
6995
|
if (typeof multicast === "object" && multicast !== null && !Array.isArray(multicast)) {
|
|
6996
|
+
validateNetworkSourceRelays(multicast["networkSource"], "$.multicast.networkSource");
|
|
6881
6997
|
const endpoints = multicast["endpoints"];
|
|
6882
6998
|
if (Array.isArray(endpoints)) {
|
|
6883
6999
|
for (let endpointIndex = 0; endpointIndex < endpoints.length; endpointIndex++) {
|
|
6884
7000
|
const endpoint = endpoints[endpointIndex];
|
|
6885
7001
|
if (typeof endpoint !== "object" || endpoint === null || Array.isArray(endpoint)) continue;
|
|
7002
|
+
validateNetworkSourceRelays(
|
|
7003
|
+
endpoint["networkSource"],
|
|
7004
|
+
`$.multicast.endpoints[${endpointIndex}].networkSource`
|
|
7005
|
+
);
|
|
6886
7006
|
if ("relayAddress" in endpoint) {
|
|
6887
7007
|
catalogError(
|
|
6888
7008
|
"multicast_relay_address",
|
|
@@ -6922,15 +7042,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6922
7042
|
}
|
|
6923
7043
|
}
|
|
6924
7044
|
}
|
|
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
|
-
}
|
|
7045
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
7046
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
6934
7047
|
validateArchive(catalog);
|
|
6935
7048
|
return catalog;
|
|
6936
7049
|
}
|
|
@@ -6956,7 +7069,7 @@ function resolveGroupDurationTicks(timing, timescale) {
|
|
|
6956
7069
|
const product = timing.groupDurationMs * timescale;
|
|
6957
7070
|
if (product % 1e3 !== 0) {
|
|
6958
7071
|
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-
|
|
7072
|
+
`[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
7073
|
);
|
|
6961
7074
|
}
|
|
6962
7075
|
return product / 1e3;
|
|
@@ -6977,14 +7090,6 @@ function validateSwitchingSetTiming(tracks) {
|
|
|
6977
7090
|
return { ok: false, expectedTicks, mismatches };
|
|
6978
7091
|
}
|
|
6979
7092
|
|
|
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
7093
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
6989
7094
|
function endpointKey(endpoint) {
|
|
6990
7095
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -7115,8 +7220,8 @@ var AdaptiveBitrateController = class {
|
|
|
7115
7220
|
/**
|
|
7116
7221
|
* Update FEC statistics for ABR decisions
|
|
7117
7222
|
*
|
|
7118
|
-
*
|
|
7119
|
-
*
|
|
7223
|
+
* ABR uses the effective loss rate (after FEC recovery) rather than the
|
|
7224
|
+
* raw transport loss rate.
|
|
7120
7225
|
*
|
|
7121
7226
|
* @param stats - FEC statistics from the FEC decoder
|
|
7122
7227
|
*/
|
|
@@ -7468,6 +7573,20 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
7468
7573
|
consume: "bytes",
|
|
7469
7574
|
...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
|
|
7470
7575
|
};
|
|
7576
|
+
if (input.atsc3) {
|
|
7577
|
+
const { frequency, plpId, serviceId } = input.atsc3;
|
|
7578
|
+
if (!Number.isInteger(frequency) || frequency < 1) {
|
|
7579
|
+
throw new TypeError(`ATSC3 tuning requires a positive integer frequency in kHz, got ${String(frequency)}`);
|
|
7580
|
+
}
|
|
7581
|
+
return {
|
|
7582
|
+
...base,
|
|
7583
|
+
origin: "tuner",
|
|
7584
|
+
standard: "atsc3",
|
|
7585
|
+
frequency,
|
|
7586
|
+
...plpId !== void 0 ? { plpId } : {},
|
|
7587
|
+
...serviceId !== void 0 ? { serviceId } : {}
|
|
7588
|
+
};
|
|
7589
|
+
}
|
|
7471
7590
|
const relay = input.amtRelay?.trim();
|
|
7472
7591
|
const driad = !relay && input.amtDiscovery === "driad";
|
|
7473
7592
|
const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
|
|
@@ -8713,25 +8832,20 @@ function multicastFromConfig(input) {
|
|
|
8713
8832
|
);
|
|
8714
8833
|
}
|
|
8715
8834
|
}
|
|
8716
|
-
const
|
|
8717
|
-
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx, seenTuples));
|
|
8835
|
+
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx));
|
|
8718
8836
|
const out = { endpoints };
|
|
8719
8837
|
const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
|
|
8720
8838
|
networkSource.forEach(validateNetworkSourceEntry);
|
|
8721
8839
|
if (networkSource.length > 0) out.networkSource = networkSource;
|
|
8722
8840
|
const amtRelays = new Set(
|
|
8723
|
-
networkSource.flatMap((s) => s.type === "amt" && s.
|
|
8841
|
+
networkSource.flatMap((s) => s.type === "amt" && s.relay?.trim() ? [s.relay.trim()] : []).slice(0, 1)
|
|
8724
8842
|
);
|
|
8725
8843
|
input.endpoints.forEach((ep, idx) => {
|
|
8726
8844
|
const relay = ep.relayAddress?.trim();
|
|
8727
8845
|
if (!relay || amtRelays.has(relay)) return;
|
|
8728
|
-
const demoted = networkSource.some(
|
|
8729
|
-
(s) => s.type === "amt" && s.discovery === "driad" && s.relay?.trim() === relay
|
|
8730
|
-
);
|
|
8731
8846
|
const shadowed = networkSource.some(
|
|
8732
|
-
(s) => s.type === "amt" && s.
|
|
8847
|
+
(s) => s.type === "amt" && s.relay?.trim() === relay
|
|
8733
8848
|
);
|
|
8734
|
-
const derived = input.networkSource === void 0;
|
|
8735
8849
|
const fromAmtFallback = ", derived from amtFallback/MOQCAST_MULTICAST_AMT_*";
|
|
8736
8850
|
const fromRelay = relayFrom === "amtFallback.relayDns" ? fromAmtFallback : relayFrom === "endpoint.relayAddress" ? ", derived from the endpoint relayAddress values" : "";
|
|
8737
8851
|
const relayDns = input.amtFallback?.relayDns?.trim();
|
|
@@ -8739,7 +8853,7 @@ function multicastFromConfig(input) {
|
|
|
8739
8853
|
throw new MulticastInputError(
|
|
8740
8854
|
"conflicting_amt_relay",
|
|
8741
8855
|
idx,
|
|
8742
|
-
`endpoint[${idx}] relayAddress ${JSON.stringify(relay)} ` + (
|
|
8856
|
+
`endpoint[${idx}] relayAddress ${JSON.stringify(relay)} ` + (shadowed ? `is carried by a multicast.networkSource AMT entry that is not the first one: both readers join the first AMT entry (${[...amtRelays].join(", ")}) and ignore the rest, so this relay is never joined; keep a single AMT entry, or put this one first` : `is not the relay of any multicast.networkSource AMT entry (${[...amtRelays].join(", ") || "none"})${fromRelay}; ` + (outranked ? `amtFallback.relayDns/MOQCAST_MULTICAST_AMT_RELAY_DNS (${relayDns}) outranks an endpoint relay when networkSource is derived -- drop one, or make them agree` : "networkSource is catalog-level and cannot represent per-endpoint relays"))
|
|
8743
8857
|
);
|
|
8744
8858
|
});
|
|
8745
8859
|
input.endpoints.forEach((ep, idx) => {
|
|
@@ -8748,9 +8862,20 @@ function multicastFromConfig(input) {
|
|
|
8748
8862
|
throw new MulticastInputError(
|
|
8749
8863
|
ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
|
|
8750
8864
|
idx,
|
|
8751
|
-
`endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying
|
|
8865
|
+
`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" : "")
|
|
8752
8866
|
);
|
|
8753
8867
|
});
|
|
8868
|
+
input.endpoints.forEach((ep, idx) => {
|
|
8869
|
+
if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
|
|
8870
|
+
endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
|
|
8871
|
+
});
|
|
8872
|
+
if (input.auth !== void 0) out.auth = input.auth;
|
|
8873
|
+
const [issue] = multicastCatalogIssues({ multicast: out });
|
|
8874
|
+
if (issue) {
|
|
8875
|
+
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";
|
|
8876
|
+
const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
|
|
8877
|
+
throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
|
|
8878
|
+
}
|
|
8754
8879
|
if (input.enabled !== void 0) out.enabled = input.enabled;
|
|
8755
8880
|
if (input.version !== void 0) out.version = input.version;
|
|
8756
8881
|
if (input.validUntil !== void 0) out.validUntil = input.validUntil;
|
|
@@ -8762,10 +8887,10 @@ function resolveNetworkSource(input) {
|
|
|
8762
8887
|
}
|
|
8763
8888
|
const relayDns = input.amtFallback?.relayDns?.trim();
|
|
8764
8889
|
const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
|
|
8765
|
-
const discovery = input.amtFallback?.discovery
|
|
8766
|
-
if (discovery === void 0) return { entries: [], relayFrom: null };
|
|
8890
|
+
const discovery = input.amtFallback?.discovery;
|
|
8891
|
+
if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
|
|
8767
8892
|
return {
|
|
8768
|
-
entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
|
|
8893
|
+
entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
|
|
8769
8894
|
relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
|
|
8770
8895
|
};
|
|
8771
8896
|
}
|
|
@@ -8778,8 +8903,11 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8778
8903
|
const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
|
|
8779
8904
|
if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
|
|
8780
8905
|
if (s.type === "amt") {
|
|
8781
|
-
if (s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8782
|
-
throw err(
|
|
8906
|
+
if (s.discovery !== void 0 && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8907
|
+
throw err(
|
|
8908
|
+
"invalid_amt_discovery",
|
|
8909
|
+
`discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`
|
|
8910
|
+
);
|
|
8783
8911
|
}
|
|
8784
8912
|
if (s.relay !== void 0) {
|
|
8785
8913
|
const relay = typeof s.relay === "string" ? s.relay.trim() : "";
|
|
@@ -8788,8 +8916,14 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8788
8916
|
}
|
|
8789
8917
|
s.relay = relay;
|
|
8790
8918
|
}
|
|
8791
|
-
if (s.discovery === "manual" && s.relay === void 0) {
|
|
8792
|
-
throw err("amt_requires_relay", `discovery="
|
|
8919
|
+
if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === void 0) {
|
|
8920
|
+
throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
|
|
8921
|
+
}
|
|
8922
|
+
if (s.discovery === "driad" && s.relay !== void 0) {
|
|
8923
|
+
throw err(
|
|
8924
|
+
"invalid_network_source",
|
|
8925
|
+
`discovery="driad" must omit relay: DRIAD supplies the relay candidates (draft -01 4.2.1); drop the relay (amtFallback.relayDns / endpoint relayAddress on the derived path), or use "dns" or "manual"`
|
|
8926
|
+
);
|
|
8793
8927
|
}
|
|
8794
8928
|
if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
|
|
8795
8929
|
throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
|
|
@@ -8798,13 +8932,15 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8798
8932
|
}
|
|
8799
8933
|
const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
|
|
8800
8934
|
if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
|
|
8801
|
-
throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
|
|
8935
|
+
throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
|
|
8802
8936
|
}
|
|
8803
|
-
if (!inRange(s.plpId, 0, 63))
|
|
8804
|
-
|
|
8937
|
+
if (s.plpId !== void 0 && !inRange(s.plpId, 0, 63)) {
|
|
8938
|
+
throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
|
|
8939
|
+
}
|
|
8940
|
+
if (s.serviceId !== void 0 && !inRange(s.serviceId, 0, 65535)) {
|
|
8805
8941
|
throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
|
|
8806
8942
|
}
|
|
8807
|
-
if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
|
|
8943
|
+
if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
|
|
8808
8944
|
throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
|
|
8809
8945
|
}
|
|
8810
8946
|
}
|
|
@@ -8816,7 +8952,7 @@ function isAbsoluteUri(value) {
|
|
|
8816
8952
|
return false;
|
|
8817
8953
|
}
|
|
8818
8954
|
}
|
|
8819
|
-
function validateEndpoint2(ep, idx
|
|
8955
|
+
function validateEndpoint2(ep, idx) {
|
|
8820
8956
|
if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
|
|
8821
8957
|
throw new MulticastInputError(
|
|
8822
8958
|
"ssm_requires_source",
|
|
@@ -8824,6 +8960,13 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8824
8960
|
`endpoint[${idx}] protocol=ssm requires sourceAddress`
|
|
8825
8961
|
);
|
|
8826
8962
|
}
|
|
8963
|
+
if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
|
|
8964
|
+
throw new MulticastInputError(
|
|
8965
|
+
"protocol_source_mismatch",
|
|
8966
|
+
idx,
|
|
8967
|
+
`endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
|
|
8968
|
+
);
|
|
8969
|
+
}
|
|
8827
8970
|
if (!isMulticastGroupAddress(ep.groupAddress)) {
|
|
8828
8971
|
throw new MulticastInputError(
|
|
8829
8972
|
"invalid_group_address",
|
|
@@ -8883,23 +9026,15 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8883
9026
|
`endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
|
|
8884
9027
|
);
|
|
8885
9028
|
}
|
|
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
9029
|
const out = {
|
|
8896
|
-
protocol: ep.
|
|
9030
|
+
protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
|
|
8897
9031
|
groupAddress: ep.groupAddress,
|
|
8898
9032
|
port: ep.port,
|
|
8899
9033
|
tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
|
|
8900
9034
|
};
|
|
8901
9035
|
if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
|
|
8902
9036
|
if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
|
|
9037
|
+
if (ep.auth !== void 0) out.auth = { ...ep.auth };
|
|
8903
9038
|
return out;
|
|
8904
9039
|
}
|
|
8905
9040
|
function isMulticastGroupAddress(addr) {
|
|
@@ -8942,9 +9077,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
|
|
|
8942
9077
|
endpoints,
|
|
8943
9078
|
...hasCatalogAmt ? {
|
|
8944
9079
|
amtFallback: {
|
|
8945
|
-
//
|
|
8946
|
-
//
|
|
8947
|
-
discovery: amtDiscovery
|
|
9080
|
+
// No default: an omitted discovery with a relay hostname is
|
|
9081
|
+
// "dns" (draft-ramadan-moq-multicast-01 4.2.1).
|
|
9082
|
+
...amtDiscovery ? { discovery: amtDiscovery } : {},
|
|
8948
9083
|
...amtRelayDns ? { relayDns: amtRelayDns } : {}
|
|
8949
9084
|
}
|
|
8950
9085
|
} : {}
|
|
@@ -9112,7 +9247,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9112
9247
|
if (ot.role !== void 0 && existing.role === void 0) existing.role = ot.role;
|
|
9113
9248
|
if (existing.packaging === "mmtp") {
|
|
9114
9249
|
const mode = existing.mmtpMode ?? ot.mmtpMode;
|
|
9115
|
-
if (mode !== "
|
|
9250
|
+
if (mode !== "mfu") {
|
|
9116
9251
|
throw new Error(
|
|
9117
9252
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9118
9253
|
);
|
|
@@ -9149,7 +9284,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9149
9284
|
);
|
|
9150
9285
|
}
|
|
9151
9286
|
const mmtpMode = ot.mmtpMode;
|
|
9152
|
-
if (packaging === "mmtp" && mmtpMode !== "
|
|
9287
|
+
if (packaging === "mmtp" && mmtpMode !== "mfu") {
|
|
9153
9288
|
throw new Error(
|
|
9154
9289
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9155
9290
|
);
|
|
@@ -9450,8 +9585,8 @@ function u32(v) {
|
|
|
9450
9585
|
}
|
|
9451
9586
|
var KEYFRAME_FLAGS = 33554432;
|
|
9452
9587
|
var DELTA_FLAGS = 16842752;
|
|
9453
|
-
var
|
|
9454
|
-
var MAX_TRACK_ID =
|
|
9588
|
+
var UINT32_MAX2 = 4294967295;
|
|
9589
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
9455
9590
|
var INT32_MIN = -2147483648;
|
|
9456
9591
|
var INT32_MAX = 2147483647;
|
|
9457
9592
|
function assertTrackId(trackId, label) {
|
|
@@ -9460,8 +9595,8 @@ function assertTrackId(trackId, label) {
|
|
|
9460
9595
|
}
|
|
9461
9596
|
}
|
|
9462
9597
|
function assertTimescale(timescale, label) {
|
|
9463
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
9464
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
9598
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
9599
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
9465
9600
|
}
|
|
9466
9601
|
}
|
|
9467
9602
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -12294,16 +12429,6 @@ var DeliveryGapEstimator = class {
|
|
|
12294
12429
|
|
|
12295
12430
|
// src/iso-block-locator.ts
|
|
12296
12431
|
var IsoBlockLocator = class _IsoBlockLocator {
|
|
12297
|
-
/** Known blocks and spans, in serial order of their start. */
|
|
12298
|
-
#blocks = [];
|
|
12299
|
-
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12300
|
-
#held = /* @__PURE__ */ new Map();
|
|
12301
|
-
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12302
|
-
#coverageEnd;
|
|
12303
|
-
#kMax;
|
|
12304
|
-
#retentionBlocks;
|
|
12305
|
-
#heldEvicted = 0;
|
|
12306
|
-
#newest;
|
|
12307
12432
|
/**
|
|
12308
12433
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
12309
12434
|
* @param retentionBlocks how many blocks behind the newest position the
|
|
@@ -12311,12 +12436,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12311
12436
|
* no locator exists without retention.
|
|
12312
12437
|
*/
|
|
12313
12438
|
constructor(kMax, retentionBlocks) {
|
|
12439
|
+
/** Known blocks and spans, in serial order of their start. */
|
|
12440
|
+
this.#blocks = [];
|
|
12441
|
+
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12442
|
+
this.#held = /* @__PURE__ */ new Map();
|
|
12443
|
+
this.#heldEvicted = 0;
|
|
12444
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
12445
|
+
this.#holes = [];
|
|
12446
|
+
/**
|
|
12447
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
12448
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
12449
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
12450
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
12451
|
+
*/
|
|
12452
|
+
this.deferIncompleteGaps = false;
|
|
12314
12453
|
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
12315
12454
|
throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
|
|
12316
12455
|
}
|
|
12317
12456
|
this.#kMax = kMax;
|
|
12318
12457
|
this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
|
|
12319
12458
|
}
|
|
12459
|
+
#blocks;
|
|
12460
|
+
#held;
|
|
12461
|
+
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12462
|
+
#coverageEnd;
|
|
12463
|
+
#kMax;
|
|
12464
|
+
#retentionBlocks;
|
|
12465
|
+
#heldEvicted;
|
|
12466
|
+
#newest;
|
|
12467
|
+
#holes;
|
|
12320
12468
|
static #checkedRetention(retentionBlocks) {
|
|
12321
12469
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
12322
12470
|
throw new Error(
|
|
@@ -12379,6 +12527,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12379
12527
|
}
|
|
12380
12528
|
return null;
|
|
12381
12529
|
}
|
|
12530
|
+
/** Number of pending holes. */
|
|
12531
|
+
get holeCount() {
|
|
12532
|
+
return this.#holes.length;
|
|
12533
|
+
}
|
|
12534
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
12535
|
+
blockEndingAt(end) {
|
|
12536
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
|
|
12537
|
+
}
|
|
12382
12538
|
/** The known block or span starting exactly at `start`. */
|
|
12383
12539
|
blockAt(start) {
|
|
12384
12540
|
return this.#blocks.find((block) => block.start === start);
|
|
@@ -12401,6 +12557,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12401
12557
|
coversBetween(a, b) {
|
|
12402
12558
|
if (this.#coverageEnd === void 0) return false;
|
|
12403
12559
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
|
|
12560
|
+
const first = a + 1 >>> 0;
|
|
12561
|
+
const count = serial32Distance(a, b) - 1;
|
|
12562
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
|
|
12404
12563
|
return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
|
|
12405
12564
|
}
|
|
12406
12565
|
/**
|
|
@@ -12430,6 +12589,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12430
12589
|
* known block (a different length, or an overlap with another block or a
|
|
12431
12590
|
* span) fails closed: the repair symbol is dropped and no block changes.
|
|
12432
12591
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
12592
|
+
* A block so far past `newest` that stating it would retire the position
|
|
12593
|
+
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
12594
|
+
* this is slightly conservative (retirement measures that block from its
|
|
12595
|
+
* last SS_ID), costing one dropped repair. Placing it would turn everything
|
|
12596
|
+
* between into a repair-less span and leave every real repair behind it
|
|
12597
|
+
* `stale`. Sources move `newest` (`hold`, `observe`), so after a real outage
|
|
12598
|
+
* the first source back brings the next repair inside the horizon; until one
|
|
12599
|
+
* arrives, a stream's repairs alone cannot pass it.
|
|
12433
12600
|
*/
|
|
12434
12601
|
placeRepair(start, length) {
|
|
12435
12602
|
if (!Number.isSafeInteger(length) || length <= 0 || length > this.#kMax) {
|
|
@@ -12448,6 +12615,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12448
12615
|
}
|
|
12449
12616
|
return { status: "placed", block: known, placed: [] };
|
|
12450
12617
|
}
|
|
12618
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
|
|
12619
|
+
if (pending !== void 0) {
|
|
12620
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
12621
|
+
return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
|
|
12622
|
+
}
|
|
12623
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1);
|
|
12624
|
+
const before = serial32Distance(pending.start, start);
|
|
12625
|
+
const afterStart = isoBlockEnd(start, length);
|
|
12626
|
+
const after = pending.length - before - length;
|
|
12627
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
|
|
12628
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
|
|
12629
|
+
const block2 = { start, length, span: false };
|
|
12630
|
+
const placed2 = this.#claim(block2);
|
|
12631
|
+
this.#blocks.push(block2);
|
|
12632
|
+
return { status: "placed", block: block2, placed: placed2 };
|
|
12633
|
+
}
|
|
12451
12634
|
for (const block2 of this.#blocks) {
|
|
12452
12635
|
if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
|
|
12453
12636
|
return {
|
|
@@ -12456,7 +12639,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12456
12639
|
};
|
|
12457
12640
|
}
|
|
12458
12641
|
}
|
|
12642
|
+
if (this.#newest !== void 0 && isoBlocksBehindLowerBound(this.#newest, start, this.#kMax) > this.#retentionBlocks) {
|
|
12643
|
+
return { status: "ahead", reason: `repair block ${start}+${length} is past the retention horizon ahead of ${this.#newest}` };
|
|
12644
|
+
}
|
|
12459
12645
|
let span;
|
|
12646
|
+
let hole;
|
|
12460
12647
|
if (this.#coverageEnd === void 0) {
|
|
12461
12648
|
for (const ssId of this.#held.keys()) {
|
|
12462
12649
|
if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
|
|
@@ -12465,21 +12652,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12465
12652
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
12466
12653
|
return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
|
|
12467
12654
|
} else if (start !== this.#coverageEnd) {
|
|
12468
|
-
const
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
span:
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12655
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
|
|
12656
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
|
|
12657
|
+
if (lostSsId !== void 0) {
|
|
12658
|
+
const holeBlock = { ...gap, span: false };
|
|
12659
|
+
this.#holes.push(holeBlock);
|
|
12660
|
+
hole = { block: holeBlock, lostSsId };
|
|
12661
|
+
} else {
|
|
12662
|
+
const spanBlock = { ...gap, span: true };
|
|
12663
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) };
|
|
12664
|
+
this.#blocks.push(spanBlock);
|
|
12665
|
+
}
|
|
12475
12666
|
}
|
|
12476
12667
|
const block = { start, length, span: false };
|
|
12477
12668
|
const placed = this.#claim(block);
|
|
12478
12669
|
this.#blocks.push(block);
|
|
12479
12670
|
this.#coverageEnd = isoBlockEnd(start, length);
|
|
12480
12671
|
this.retireBehind(start);
|
|
12672
|
+
if (hole !== void 0) return { status: "placed", block, placed, hole };
|
|
12481
12673
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
12482
12674
|
}
|
|
12675
|
+
/**
|
|
12676
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
12677
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
12678
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
12679
|
+
*/
|
|
12680
|
+
closeHolesWithin(start, length) {
|
|
12681
|
+
const closed = [];
|
|
12682
|
+
for (const hole of [...this.#holes]) {
|
|
12683
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
12684
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1);
|
|
12685
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
12686
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
12687
|
+
this.#blocks.push(spanBlock);
|
|
12688
|
+
}
|
|
12689
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
12690
|
+
}
|
|
12691
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
12692
|
+
#highestMissing(start, length) {
|
|
12693
|
+
const steps = Math.min(length, this.#held.size + 1);
|
|
12694
|
+
for (let i = 1; i <= steps; i++) {
|
|
12695
|
+
const ssId = serial32Add(start, length - i);
|
|
12696
|
+
if (!this.#held.has(ssId)) return ssId;
|
|
12697
|
+
}
|
|
12698
|
+
return void 0;
|
|
12699
|
+
}
|
|
12483
12700
|
/**
|
|
12484
12701
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
12485
12702
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -12498,6 +12715,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12498
12715
|
this.#blocks.splice(i, 1);
|
|
12499
12716
|
}
|
|
12500
12717
|
}
|
|
12718
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
12719
|
+
const hole = this.#holes[i];
|
|
12720
|
+
const last = serial32Add(hole.start, hole.length - 1);
|
|
12721
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
|
|
12722
|
+
}
|
|
12501
12723
|
for (const ssId of [...this.#held.keys()]) {
|
|
12502
12724
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
|
|
12503
12725
|
}
|
|
@@ -12506,6 +12728,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12506
12728
|
/** Forget everything (publisher restart, track reset). */
|
|
12507
12729
|
reset() {
|
|
12508
12730
|
this.#blocks.length = 0;
|
|
12731
|
+
this.#holes.length = 0;
|
|
12509
12732
|
this.#held.clear();
|
|
12510
12733
|
this.#coverageEnd = void 0;
|
|
12511
12734
|
this.#newest = void 0;
|
|
@@ -12521,6 +12744,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12521
12744
|
return placed;
|
|
12522
12745
|
}
|
|
12523
12746
|
};
|
|
12747
|
+
function isoRangesOverlap(aStart, aLength, bStart, bLength) {
|
|
12748
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
|
|
12749
|
+
}
|
|
12524
12750
|
|
|
12525
12751
|
// src/fec-state.ts
|
|
12526
12752
|
var MIN_INTERLEAVE_DEPTH_MS = 1;
|
|
@@ -12543,8 +12769,8 @@ function isPositiveSafeInteger2(value) {
|
|
|
12543
12769
|
}
|
|
12544
12770
|
function catalogDeclaresFec(fec) {
|
|
12545
12771
|
const block = recordOf2(fec);
|
|
12546
|
-
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
12547
|
-
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block);
|
|
12772
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"])) return false;
|
|
12773
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
12548
12774
|
}
|
|
12549
12775
|
function requireBoolean(value, field) {
|
|
12550
12776
|
if (typeof value !== "boolean") {
|
|
@@ -13031,6 +13257,7 @@ function decideGap(input) {
|
|
|
13031
13257
|
}
|
|
13032
13258
|
|
|
13033
13259
|
// src/fec-manager.ts
|
|
13260
|
+
var RS_MAX_BLOCK_SYMBOLS = 255;
|
|
13034
13261
|
var WORKER_ERROR_LOG_CAP = 5;
|
|
13035
13262
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13036
13263
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
@@ -13145,6 +13372,11 @@ var FECManager = class _FECManager {
|
|
|
13145
13372
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
13146
13373
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
13147
13374
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
13375
|
+
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
13376
|
+
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
13377
|
+
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
13378
|
+
this.#fecFailClosed = /* @__PURE__ */ new Map();
|
|
13379
|
+
this.#onFecFailClosed = null;
|
|
13148
13380
|
// Blocks already recovered — prevents late source symbols from restarting timeouts.
|
|
13149
13381
|
// WASM removes blocks after recovery; late symbols create empty blocks returning null,
|
|
13150
13382
|
// which would falsely start new timeouts without this guard.
|
|
@@ -13275,6 +13507,7 @@ var FECManager = class _FECManager {
|
|
|
13275
13507
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
13276
13508
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
13277
13509
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
13510
|
+
this.#deferIsoGaps = false;
|
|
13278
13511
|
this.#isoRepairRefusedCount = 0;
|
|
13279
13512
|
this.#isoSourceOversizeCount = 0;
|
|
13280
13513
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -13349,6 +13582,14 @@ var FECManager = class _FECManager {
|
|
|
13349
13582
|
this.onBlockReclassified = null;
|
|
13350
13583
|
/** A video stream's classifier mode was established or changed. */
|
|
13351
13584
|
this.onClassifierMode = null;
|
|
13585
|
+
/**
|
|
13586
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
13587
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
13588
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
13589
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
13590
|
+
* for it, which it must be.
|
|
13591
|
+
*/
|
|
13592
|
+
this.#onUndelimitedLoss = null;
|
|
13352
13593
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
13353
13594
|
this.onBlockVanished = null;
|
|
13354
13595
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
@@ -13390,6 +13631,9 @@ var FECManager = class _FECManager {
|
|
|
13390
13631
|
#ssbLengthConflictCount;
|
|
13391
13632
|
#blockRepairRsIds;
|
|
13392
13633
|
#blockRsbLengths;
|
|
13634
|
+
#heldLayerStates;
|
|
13635
|
+
#fecFailClosed;
|
|
13636
|
+
#onFecFailClosed;
|
|
13393
13637
|
#completedBlocks;
|
|
13394
13638
|
#terminalExpiryMs;
|
|
13395
13639
|
#terminalQueues;
|
|
@@ -13430,6 +13674,7 @@ var FECManager = class _FECManager {
|
|
|
13430
13674
|
#highestSbn;
|
|
13431
13675
|
#sourceFrontiers;
|
|
13432
13676
|
#isoLocators;
|
|
13677
|
+
#deferIsoGaps;
|
|
13433
13678
|
#isoRepairRefusedCount;
|
|
13434
13679
|
#isoSourceOversizeCount;
|
|
13435
13680
|
#isoHeldEvictedCount;
|
|
@@ -13443,6 +13688,7 @@ var FECManager = class _FECManager {
|
|
|
13443
13688
|
#workerErrorCounts;
|
|
13444
13689
|
#decoderUnavailableEvents;
|
|
13445
13690
|
#repairSymbolSizeMismatchCount;
|
|
13691
|
+
#onUndelimitedLoss;
|
|
13446
13692
|
#encodeTrackName(catalogTrackName) {
|
|
13447
13693
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
13448
13694
|
if (encoded === void 0) {
|
|
@@ -14433,8 +14679,10 @@ var FECManager = class _FECManager {
|
|
|
14433
14679
|
);
|
|
14434
14680
|
}
|
|
14435
14681
|
const hasCatalogTiming = _FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs });
|
|
14682
|
+
const algorithm = config.algorithm ?? previous.algorithm;
|
|
14436
14683
|
const next = {
|
|
14437
14684
|
blockProfile,
|
|
14685
|
+
...algorithm === void 0 ? {} : { algorithm },
|
|
14438
14686
|
k,
|
|
14439
14687
|
symbolSize: config.symbolSize != null && config.symbolSize > 0 ? config.symbolSize : previousTrack?.symbolSize ?? 0,
|
|
14440
14688
|
interleaveDepthMs: ownInterleaveDepthMs,
|
|
@@ -14442,8 +14690,19 @@ var FECManager = class _FECManager {
|
|
|
14442
14690
|
timeoutMs: config.timeoutMs ?? (timingChanged ? 0 : previous.timeoutMs ?? 0),
|
|
14443
14691
|
...(config.trackKind ?? previous.trackKind) === void 0 ? {} : { trackKind: config.trackKind ?? previous.trackKind },
|
|
14444
14692
|
...(config.codec ?? previous.codec) === void 0 ? {} : { codec: config.codec ?? previous.codec },
|
|
14445
|
-
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry }
|
|
14693
|
+
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry },
|
|
14694
|
+
...(config.repairLayers ?? previous.repairLayers) === void 0 ? {} : { repairLayers: config.repairLayers ?? previous.repairLayers },
|
|
14695
|
+
...(config.heldLayers ?? previous.heldLayers) === void 0 ? {} : { heldLayers: config.heldLayers ?? previous.heldLayers }
|
|
14446
14696
|
};
|
|
14697
|
+
if (
|
|
14698
|
+
// By content: a catalog refresh rebuilds equal arrays, and forgetting
|
|
14699
|
+
// the anchors on one would fail open.
|
|
14700
|
+
JSON.stringify(next.repairLayers) !== JSON.stringify(previous.repairLayers) || JSON.stringify(next.heldLayers) !== JSON.stringify(previous.heldLayers)
|
|
14701
|
+
) {
|
|
14702
|
+
for (const key of [...this.#heldLayerStates.keys()]) {
|
|
14703
|
+
if (this.#belongsToPacket(key, packetId)) this.#heldLayerStates.delete(key);
|
|
14704
|
+
}
|
|
14705
|
+
}
|
|
14447
14706
|
if (!hasCatalogTiming) {
|
|
14448
14707
|
next.timeoutMs = config.timeoutMs !== void 0 && config.timeoutMs > 0 ? config.timeoutMs : previousTrack !== void 0 && previousTrack.interleaveDepthMs === 0 ? previousTrack.timeoutMs : LOCAL_FEC_TIMEOUT_MS;
|
|
14449
14708
|
} else {
|
|
@@ -14678,6 +14937,8 @@ var FECManager = class _FECManager {
|
|
|
14678
14937
|
resetMap(this.#blockAuthoredLengths);
|
|
14679
14938
|
resetMap(this.#blockRepairRsIds);
|
|
14680
14939
|
resetMap(this.#blockRsbLengths);
|
|
14940
|
+
resetMap(this.#heldLayerStates);
|
|
14941
|
+
resetMap(this.#fecFailClosed);
|
|
14681
14942
|
resetMap(this.#blockPathCounts);
|
|
14682
14943
|
resetMap(this.#blockAnchorsMs);
|
|
14683
14944
|
resetMap(this.#blockCatalogTrackNames);
|
|
@@ -15187,6 +15448,7 @@ var FECManager = class _FECManager {
|
|
|
15187
15448
|
let locator = this.#isoLocators.get(streamKey);
|
|
15188
15449
|
if (!locator) {
|
|
15189
15450
|
locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
|
|
15451
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15190
15452
|
this.#isoLocators.set(streamKey, locator);
|
|
15191
15453
|
}
|
|
15192
15454
|
return locator;
|
|
@@ -15283,15 +15545,61 @@ var FECManager = class _FECManager {
|
|
|
15283
15545
|
}
|
|
15284
15546
|
return placement;
|
|
15285
15547
|
}
|
|
15286
|
-
if (placement.span !== void 0)
|
|
15287
|
-
|
|
15288
|
-
|
|
15289
|
-
|
|
15290
|
-
|
|
15291
|
-
|
|
15548
|
+
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
15549
|
+
if (placement.hole !== void 0) {
|
|
15550
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
15551
|
+
const hole = placement.hole.block;
|
|
15552
|
+
const previous = locator.blockEndingAt(hole.start);
|
|
15553
|
+
const loss = {
|
|
15554
|
+
packetId,
|
|
15555
|
+
catalogTrackName,
|
|
15556
|
+
holeStart: hole.start,
|
|
15557
|
+
holeLength: hole.length,
|
|
15558
|
+
lostSsId: placement.hole.lostSsId,
|
|
15559
|
+
kMax: this.#trackConfig(packetId).k,
|
|
15560
|
+
...previous === void 0 ? {} : { previousBlockStart: previous.start }
|
|
15561
|
+
};
|
|
15562
|
+
this.#onUndelimitedLoss(loss);
|
|
15292
15563
|
}
|
|
15293
15564
|
return placement;
|
|
15294
15565
|
}
|
|
15566
|
+
/**
|
|
15567
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
15568
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
15569
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
15570
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
15571
|
+
* nobody to close it.
|
|
15572
|
+
*/
|
|
15573
|
+
setUndelimitedLossHandler(handler) {
|
|
15574
|
+
this.#onUndelimitedLoss = handler;
|
|
15575
|
+
this.#deferIsoGaps = handler !== null;
|
|
15576
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15577
|
+
}
|
|
15578
|
+
/**
|
|
15579
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
15580
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
15581
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
15582
|
+
*/
|
|
15583
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
15584
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
15585
|
+
if (locator === void 0) return [];
|
|
15586
|
+
const spans = locator.closeHolesWithin(start, length);
|
|
15587
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
|
|
15588
|
+
return spans;
|
|
15589
|
+
}
|
|
15590
|
+
/**
|
|
15591
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
15592
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
15593
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
15594
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
15595
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
15596
|
+
* block.
|
|
15597
|
+
*/
|
|
15598
|
+
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
15599
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
15600
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
|
|
15601
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
15602
|
+
}
|
|
15295
15603
|
/**
|
|
15296
15604
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
15297
15605
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -15809,12 +16117,17 @@ var FECManager = class _FECManager {
|
|
|
15809
16117
|
return recovered;
|
|
15810
16118
|
}
|
|
15811
16119
|
/**
|
|
15812
|
-
*
|
|
15813
|
-
*
|
|
15814
|
-
*
|
|
15815
|
-
*
|
|
15816
|
-
*
|
|
16120
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16121
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
16122
|
+
* block state unchanged. The router calls this before the repair places a
|
|
16123
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
16124
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
15817
16125
|
*/
|
|
16126
|
+
admitRepairBlockLength(packetId, ssbLength, rsbLength, rsId) {
|
|
16127
|
+
if (rsId >= rsbLength) return false;
|
|
16128
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== "reed-solomon") return true;
|
|
16129
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS;
|
|
16130
|
+
}
|
|
15818
16131
|
/**
|
|
15819
16132
|
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
15820
16133
|
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
@@ -15841,6 +16154,123 @@ var FECManager = class _FECManager {
|
|
|
15841
16154
|
}
|
|
15842
16155
|
return true;
|
|
15843
16156
|
}
|
|
16157
|
+
/**
|
|
16158
|
+
* fec-01 6.3.9 receiver check, run on a repair packet after the 4.5 discard
|
|
16159
|
+
* and the size check, before it places a block. For each held layer i with
|
|
16160
|
+
* total B_i = O_i + P_i: the anchor is the earliest block, in SS_Start
|
|
16161
|
+
* serial order, whose repair carried RSB_length >= B_i. The source track
|
|
16162
|
+
* fails closed on (a) a packet on layer i's own repair track (i > 0) below
|
|
16163
|
+
* B_i, or (b) any packet of the instance at or after the anchor below B_i.
|
|
16164
|
+
* Blocks before the anchor (pre-append) stay valid at the previous total. A
|
|
16165
|
+
* packet on a repair track the catalog does not list is discarded and
|
|
16166
|
+
* anchors nothing. `repairTrackName` is the subscribed repair track, never
|
|
16167
|
+
* inferred from RS_ID; without it only (b) runs. Returns false when the
|
|
16168
|
+
* repair must be dropped, including every repair once the track failed.
|
|
16169
|
+
*/
|
|
16170
|
+
admitRepairLayerTotal(packetId, catalogTrackName, repairTrackName, ssStart, rsbLength) {
|
|
16171
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16172
|
+
if (this.#fecFailClosed.has(streamKey)) return false;
|
|
16173
|
+
const config = this.#trackConfigs.get(packetId);
|
|
16174
|
+
const layers = config?.repairLayers;
|
|
16175
|
+
if (layers === void 0 || layers.length === 0) return true;
|
|
16176
|
+
if (repairTrackName !== void 0 && !layers.some((l) => l.repairTrackName === repairTrackName)) {
|
|
16177
|
+
return false;
|
|
16178
|
+
}
|
|
16179
|
+
let states = this.#heldLayerStates.get(streamKey);
|
|
16180
|
+
if (states === void 0) {
|
|
16181
|
+
const held = new Set(config.heldLayers ?? [0]);
|
|
16182
|
+
states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
|
|
16183
|
+
this.#heldLayerStates.set(streamKey, states);
|
|
16184
|
+
}
|
|
16185
|
+
const horizon = this.#layerAnchorHorizon(packetId);
|
|
16186
|
+
const frontier = this.#sourceFrontiers.get(streamKey)?.sbn;
|
|
16187
|
+
const farAhead = frontier !== void 0 && serial32Precedes(frontier, ssStart) && serial32Distance(frontier, ssStart) > horizon;
|
|
16188
|
+
for (const state of states) {
|
|
16189
|
+
let code;
|
|
16190
|
+
if (farAhead) {
|
|
16191
|
+
if (rsbLength < state.total) {
|
|
16192
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
16193
|
+
else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
|
|
16194
|
+
}
|
|
16195
|
+
} else {
|
|
16196
|
+
if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
|
|
16197
|
+
const stale = (s) => serial32Distance(s, state.newest) > horizon;
|
|
16198
|
+
if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
|
|
16199
|
+
delete state.latestBelow;
|
|
16200
|
+
delete state.latestBelowRsb;
|
|
16201
|
+
}
|
|
16202
|
+
if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
|
|
16203
|
+
if (rsbLength < state.total) {
|
|
16204
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
16205
|
+
else if (stale(ssStart)) continue;
|
|
16206
|
+
else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
|
|
16207
|
+
else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
|
|
16208
|
+
state.latestBelow = ssStart;
|
|
16209
|
+
state.latestBelowRsb = rsbLength;
|
|
16210
|
+
}
|
|
16211
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
16212
|
+
if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
|
|
16213
|
+
if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
16214
|
+
code = "below_anchored_total";
|
|
16215
|
+
ssStart = state.latestBelow;
|
|
16216
|
+
rsbLength = state.latestBelowRsb;
|
|
16217
|
+
}
|
|
16218
|
+
}
|
|
16219
|
+
}
|
|
16220
|
+
if (code !== void 0) {
|
|
16221
|
+
const reason = {
|
|
16222
|
+
code,
|
|
16223
|
+
layer: state.layer,
|
|
16224
|
+
total: state.total,
|
|
16225
|
+
rsbLength,
|
|
16226
|
+
ssStart,
|
|
16227
|
+
...state.anchor === void 0 ? {} : { anchor: state.anchor }
|
|
16228
|
+
};
|
|
16229
|
+
this.#fecFailClosed.set(streamKey, reason);
|
|
16230
|
+
this.#onFecFailClosed?.({ ...reason, packetId, catalogTrackName });
|
|
16231
|
+
console.warn(
|
|
16232
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? "-"}: ${JSON.stringify(reason)}`
|
|
16233
|
+
);
|
|
16234
|
+
return false;
|
|
16235
|
+
}
|
|
16236
|
+
}
|
|
16237
|
+
return true;
|
|
16238
|
+
}
|
|
16239
|
+
/**
|
|
16240
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
16241
|
+
* below-total block can still matter: the iso locator's retention in blocks
|
|
16242
|
+
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
16243
|
+
*/
|
|
16244
|
+
#layerAnchorHorizon(packetId) {
|
|
16245
|
+
const cap = 1073741824;
|
|
16246
|
+
let blocks;
|
|
16247
|
+
try {
|
|
16248
|
+
blocks = this.isoRetentionBlocksForPacket(packetId);
|
|
16249
|
+
} catch {
|
|
16250
|
+
blocks = void 0;
|
|
16251
|
+
}
|
|
16252
|
+
const k = this.#trackConfigs.get(packetId)?.k ?? 0;
|
|
16253
|
+
return blocks === void 0 || k <= 0 ? cap : Math.min(cap, blocks * k);
|
|
16254
|
+
}
|
|
16255
|
+
/**
|
|
16256
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), once,
|
|
16257
|
+
* when it does; null stops reporting. The player wiring forwards it to
|
|
16258
|
+
* CmcdProducer.updateFecFailClosed.
|
|
16259
|
+
*/
|
|
16260
|
+
setFecFailClosedHandler(handler) {
|
|
16261
|
+
this.#onFecFailClosed = handler;
|
|
16262
|
+
}
|
|
16263
|
+
/** The runtime fail-closed reason of a stream's FEC (fec-01 6.3.9), if any. */
|
|
16264
|
+
fecFailClosedReason(packetId, catalogTrackName) {
|
|
16265
|
+
return this.#fecFailClosed.get(this.#streamKey(packetId, catalogTrackName));
|
|
16266
|
+
}
|
|
16267
|
+
/**
|
|
16268
|
+
* Feed a repair symbol to the WASM FEC decoder.
|
|
16269
|
+
*
|
|
16270
|
+
* @returns Recovered block data if repair completed the block, else null.
|
|
16271
|
+
* Caller is responsible for routing recovered data and updating
|
|
16272
|
+
* block completion state via `markBlockCompleted()`.
|
|
16273
|
+
*/
|
|
15844
16274
|
feedRepairSymbol(packetId, ssStart, ssbLength, rsId, repairData, catalogTrackName) {
|
|
15845
16275
|
this.#fecStats.repairPackets++;
|
|
15846
16276
|
this.#statsForPacket(packetId).repairPackets++;
|
|
@@ -16232,6 +16662,8 @@ var FECManager = class _FECManager {
|
|
|
16232
16662
|
this.#blockAuthoredLengths.clear();
|
|
16233
16663
|
this.#blockRepairRsIds.clear();
|
|
16234
16664
|
this.#blockRsbLengths.clear();
|
|
16665
|
+
this.#heldLayerStates.clear();
|
|
16666
|
+
this.#fecFailClosed.clear();
|
|
16235
16667
|
this.#completedBlocks.clear();
|
|
16236
16668
|
this.#cleanlyCompletedBlocks.clear();
|
|
16237
16669
|
this.#repairRequestedBlocks.clear();
|
|
@@ -18977,6 +19409,12 @@ var MmtpRouter = class {
|
|
|
18977
19409
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
18978
19410
|
*/
|
|
18979
19411
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19412
|
+
/**
|
|
19413
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
19414
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
19415
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
19416
|
+
*/
|
|
19417
|
+
#multicastRapTwinByStream = /* @__PURE__ */ new Set();
|
|
18980
19418
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18981
19419
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18982
19420
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -19057,6 +19495,8 @@ var MmtpRouter = class {
|
|
|
19057
19495
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
19058
19496
|
// configured fec.blockProfile (see #noteUnreadableFecPayloadId).
|
|
19059
19497
|
#fecPayloadIdsWithoutProfile = 0;
|
|
19498
|
+
// Repair packets discarded by the fec-01 4.5 block-length rule.
|
|
19499
|
+
#repairBlockLengthDiscards = 0;
|
|
19060
19500
|
/** The staged in-place stream switch, if any (stageStreamSwitch). */
|
|
19061
19501
|
#staged = null;
|
|
19062
19502
|
#disposed = false;
|
|
@@ -19110,6 +19550,12 @@ var MmtpRouter = class {
|
|
|
19110
19550
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
|
|
19111
19551
|
};
|
|
19112
19552
|
if (meta.source) frameMeta.source = meta.source;
|
|
19553
|
+
if (isVideo && frameMeta.keyframe) {
|
|
19554
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
19555
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
|
|
19556
|
+
);
|
|
19557
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
19558
|
+
}
|
|
19113
19559
|
if (meta.deliveryProvenance !== void 0)
|
|
19114
19560
|
frameMeta.deliveryProvenance = meta.deliveryProvenance;
|
|
19115
19561
|
if (meta.recovered) frameMeta.recovered = true;
|
|
@@ -19291,6 +19737,14 @@ var MmtpRouter = class {
|
|
|
19291
19737
|
get fecPayloadIdsWithoutProfile() {
|
|
19292
19738
|
return this.#fecPayloadIdsWithoutProfile;
|
|
19293
19739
|
}
|
|
19740
|
+
/**
|
|
19741
|
+
* Repair packets discarded at admission by the fec-01 4.5 rule (RS_ID not
|
|
19742
|
+
* below RSB_length, or a reed-solomon SSB_length + RSB_length above 255),
|
|
19743
|
+
* before they touched any block state.
|
|
19744
|
+
*/
|
|
19745
|
+
get repairBlockLengthDiscards() {
|
|
19746
|
+
return this.#repairBlockLengthDiscards;
|
|
19747
|
+
}
|
|
19294
19748
|
get reassembler() {
|
|
19295
19749
|
return this.#parser.reassembler;
|
|
19296
19750
|
}
|
|
@@ -19669,13 +20123,13 @@ var MmtpRouter = class {
|
|
|
19669
20123
|
* Feed a repair packet from MoQ (reliable QUIC) — parses MMTP repair
|
|
19670
20124
|
* header and delegates to FECManager for FEC recovery.
|
|
19671
20125
|
*/
|
|
19672
|
-
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
20126
|
+
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
19673
20127
|
if (this.#disposed) return;
|
|
19674
20128
|
this.#withDeferredFecPokes(() => {
|
|
19675
|
-
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName);
|
|
20129
|
+
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
|
|
19676
20130
|
});
|
|
19677
20131
|
}
|
|
19678
|
-
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
20132
|
+
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
19679
20133
|
let header;
|
|
19680
20134
|
try {
|
|
19681
20135
|
header = parseMMTPHeader(packet);
|
|
@@ -19706,7 +20160,7 @@ var MmtpRouter = class {
|
|
|
19706
20160
|
this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
|
|
19707
20161
|
return;
|
|
19708
20162
|
}
|
|
19709
|
-
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq");
|
|
20163
|
+
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
|
|
19710
20164
|
}
|
|
19711
20165
|
}
|
|
19712
20166
|
// ── Packet FEC geometry and block profile ───────────────────────
|
|
@@ -19788,13 +20242,17 @@ var MmtpRouter = class {
|
|
|
19788
20242
|
* the repair, the order they had on the wire, so a loss-free block completes
|
|
19789
20243
|
* clean on its repair. A repair contradicting a known block is dropped.
|
|
19790
20244
|
*/
|
|
19791
|
-
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source) {
|
|
20245
|
+
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source, repairTrackName) {
|
|
19792
20246
|
const fec = this.#fecManager;
|
|
19793
20247
|
if (!fec?.placeIsoRepair) {
|
|
19794
20248
|
throw new Error(
|
|
19795
20249
|
`[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`
|
|
19796
20250
|
);
|
|
19797
20251
|
}
|
|
20252
|
+
if (fec.admitRepairBlockLength && !fec.admitRepairBlockLength(ownerPacketId, repair.ssbLength, repair.rsbLength, repair.rsId)) {
|
|
20253
|
+
this.#repairBlockLengthDiscards++;
|
|
20254
|
+
return;
|
|
20255
|
+
}
|
|
19798
20256
|
if (fec.admitRepairSymbolSize && !fec.admitRepairSymbolSize(
|
|
19799
20257
|
ownerPacketId,
|
|
19800
20258
|
repair.ssStart,
|
|
@@ -19802,6 +20260,7 @@ var MmtpRouter = class {
|
|
|
19802
20260
|
repair.rsId,
|
|
19803
20261
|
repair.symbolData.byteLength
|
|
19804
20262
|
)) return;
|
|
20263
|
+
if (fec.admitRepairLayerTotal && !fec.admitRepairLayerTotal(ownerPacketId, catalogTrackName, repairTrackName, repair.ssStart, repair.rsbLength)) return;
|
|
19805
20264
|
const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
|
|
19806
20265
|
if (placement.status !== "placed") return;
|
|
19807
20266
|
const blockStart = placement.block.start;
|
|
@@ -19836,6 +20295,17 @@ var MmtpRouter = class {
|
|
|
19836
20295
|
this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
|
|
19837
20296
|
}
|
|
19838
20297
|
}
|
|
20298
|
+
/**
|
|
20299
|
+
* The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
|
|
20300
|
+
* §7.5): what no repair stated becomes repair-less spans, whose held sources
|
|
20301
|
+
* are fed exactly as a span a repair closed.
|
|
20302
|
+
*/
|
|
20303
|
+
closeIsoHoles(ownerPacketId, catalogTrackName, start, length) {
|
|
20304
|
+
const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
|
|
20305
|
+
for (const span of spans) {
|
|
20306
|
+
this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
|
|
20307
|
+
}
|
|
20308
|
+
}
|
|
19839
20309
|
/**
|
|
19840
20310
|
* Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
|
|
19841
20311
|
* a first-arrival source is fed once its block is known: transport
|
|
@@ -19932,6 +20402,7 @@ var MmtpRouter = class {
|
|
|
19932
20402
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19933
20403
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
19934
20404
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
20405
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
19935
20406
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19936
20407
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
19937
20408
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -20730,6 +21201,10 @@ var MmtpRouter = class {
|
|
|
20730
21201
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
20731
21202
|
...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
|
|
20732
21203
|
}, parsed);
|
|
21204
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
21205
|
+
this.#multicastRapTwinByStream.add(
|
|
21206
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName)
|
|
21207
|
+
);
|
|
20733
21208
|
}
|
|
20734
21209
|
if (this.#classifyPacketId(info.packetId) === null) return;
|
|
20735
21210
|
if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
|
|
@@ -22038,48 +22513,6 @@ function createWasmMmtpContainerParser(config) {
|
|
|
22038
22513
|
});
|
|
22039
22514
|
}
|
|
22040
22515
|
|
|
22041
|
-
// src/fec-codec.ts
|
|
22042
|
-
var NoneCodec = class {
|
|
22043
|
-
constructor() {
|
|
22044
|
-
this.algorithm = "none";
|
|
22045
|
-
}
|
|
22046
|
-
addSymbol(_blockId, _symbolId, data, _isRepair) {
|
|
22047
|
-
return data;
|
|
22048
|
-
}
|
|
22049
|
-
configure(_params) {
|
|
22050
|
-
}
|
|
22051
|
-
cleanup(_now) {
|
|
22052
|
-
return new Uint8Array(0);
|
|
22053
|
-
}
|
|
22054
|
-
};
|
|
22055
|
-
function createFecCodec(algorithm) {
|
|
22056
|
-
switch (algorithm) {
|
|
22057
|
-
case "none":
|
|
22058
|
-
return new NoneCodec();
|
|
22059
|
-
case "reed-solomon":
|
|
22060
|
-
return new ReedSolomonCodec();
|
|
22061
|
-
case "raptorq":
|
|
22062
|
-
console.warn("[FEC] RaptorQ requested via createFecCodec \u2014 use FECManager.setFecDecoder() for WASM RaptorQ. Falling back to NoneCodec.");
|
|
22063
|
-
return new NoneCodec();
|
|
22064
|
-
default:
|
|
22065
|
-
console.warn(`[FEC] Unknown algorithm "${algorithm}", falling back to NoneCodec`);
|
|
22066
|
-
return new NoneCodec();
|
|
22067
|
-
}
|
|
22068
|
-
}
|
|
22069
|
-
var ReedSolomonCodec = class {
|
|
22070
|
-
constructor() {
|
|
22071
|
-
this.algorithm = "reed-solomon";
|
|
22072
|
-
}
|
|
22073
|
-
addSymbol(_blockId, _symbolId, _data, _isRepair) {
|
|
22074
|
-
return null;
|
|
22075
|
-
}
|
|
22076
|
-
configure(_params) {
|
|
22077
|
-
}
|
|
22078
|
-
cleanup(_now) {
|
|
22079
|
-
return new Uint8Array(0);
|
|
22080
|
-
}
|
|
22081
|
-
};
|
|
22082
|
-
|
|
22083
22516
|
// src/multicast-transport.ts
|
|
22084
22517
|
var JOIN_SUCCEEDED = Object.freeze({ ok: true });
|
|
22085
22518
|
function providerErrorOf(error) {
|
|
@@ -22229,7 +22662,8 @@ var MulticastTransport = class {
|
|
|
22229
22662
|
amtRelayPort: config.amtRelayPort,
|
|
22230
22663
|
amtDiscovery: config.amtDiscovery,
|
|
22231
22664
|
packetIds: config.packetIds,
|
|
22232
|
-
tracks: config.tracks
|
|
22665
|
+
tracks: config.tracks,
|
|
22666
|
+
atsc3: config.atsc3
|
|
22233
22667
|
});
|
|
22234
22668
|
failure = "provider-rejected";
|
|
22235
22669
|
const subscription = await gateway.subscribe(subscribeConfig);
|
|
@@ -22834,6 +23268,25 @@ function catalogAmtNetworkSource(networkSource) {
|
|
|
22834
23268
|
}
|
|
22835
23269
|
return void 0;
|
|
22836
23270
|
}
|
|
23271
|
+
function intIn(value, min, max) {
|
|
23272
|
+
return Number.isInteger(value) && value >= min && value <= max;
|
|
23273
|
+
}
|
|
23274
|
+
function catalogAtsc3NetworkSource(networkSource) {
|
|
23275
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
23276
|
+
for (const raw of entries) {
|
|
23277
|
+
if (!raw || typeof raw !== "object") continue;
|
|
23278
|
+
const ns = raw;
|
|
23279
|
+
if (ns.type !== "atsc3" || !intIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
|
|
23280
|
+
const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
|
|
23281
|
+
return {
|
|
23282
|
+
frequency: ns.frequency,
|
|
23283
|
+
...intIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
|
|
23284
|
+
...intIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
|
|
23285
|
+
...slsUri ? { slsUri } : {}
|
|
23286
|
+
};
|
|
23287
|
+
}
|
|
23288
|
+
return void 0;
|
|
23289
|
+
}
|
|
22837
23290
|
|
|
22838
23291
|
// src/catalog-fec-params.ts
|
|
22839
23292
|
var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
|
|
@@ -23049,6 +23502,13 @@ function isoSpanUnavailable(fec, path, declaresFecInstance) {
|
|
|
23049
23502
|
function catalogFecUnavailable(fec, fecPath) {
|
|
23050
23503
|
if (catalogFecAvailable(fec)) return void 0;
|
|
23051
23504
|
const block = recordOf3(fec);
|
|
23505
|
+
if (fecAlgorithmUnimplemented(block["algorithm"])) {
|
|
23506
|
+
return Object.freeze({
|
|
23507
|
+
code: "track_fec_algorithm_unimplemented",
|
|
23508
|
+
path: `${fecPath}.algorithm`,
|
|
23509
|
+
message: `algorithm ${JSON.stringify(block["algorithm"])} is not implemented: the track plays without FEC`
|
|
23510
|
+
});
|
|
23511
|
+
}
|
|
23052
23512
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
23053
23513
|
const reason = blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
|
|
23054
23514
|
if (reason === void 0) {
|
|
@@ -23068,7 +23528,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
23068
23528
|
throwRepairContractError(
|
|
23069
23529
|
"track_fec",
|
|
23070
23530
|
`${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
|
|
23071
|
-
"must be a positive integer"
|
|
23531
|
+
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
23532
|
);
|
|
23073
23533
|
}
|
|
23074
23534
|
const fecUnavailable = catalogFecUnavailable(fec, fecPath);
|
|
@@ -23077,6 +23537,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
23077
23537
|
const fecBlockProfile = readFecBlockProfile(fec.blockProfile, `${fecPath}.blockProfile`, true, throwRepairContractError);
|
|
23078
23538
|
return {
|
|
23079
23539
|
fecK: fec.sourceSymbols ?? 0,
|
|
23540
|
+
fecAlgorithm: fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq",
|
|
23080
23541
|
fecBlockProfile,
|
|
23081
23542
|
fecRepairCount: fec.repairSymbols ?? 0,
|
|
23082
23543
|
// The wire RSB_length: every base layer's packets carry the base total (§7.1).
|
|
@@ -23173,8 +23634,10 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
|
|
|
23173
23634
|
repairsSkippedRttUnmeasured: 0,
|
|
23174
23635
|
repairsSkippedRttExceedsBudget: 0,
|
|
23175
23636
|
repairsSkippedPresentationDelayUnavailable: 0,
|
|
23637
|
+
repairsSkippedRangeNoAnchor: 0,
|
|
23176
23638
|
lastRepairSkip: null,
|
|
23177
23639
|
keyframeRepairFetchesSent: 0,
|
|
23640
|
+
rangeRepairFetchesSent: 0,
|
|
23178
23641
|
keyframeBudgetHolds: 0,
|
|
23179
23642
|
keyframeBudgetHoldMs: 0,
|
|
23180
23643
|
deltaBlocksFailed: 0,
|
|
@@ -23253,6 +23716,12 @@ var REPAIR_PRIORITY_REASONS = /* @__PURE__ */ new Set([
|
|
|
23253
23716
|
"repair-priority-absent",
|
|
23254
23717
|
"repair-priority-invalid"
|
|
23255
23718
|
]);
|
|
23719
|
+
var REPAIR_SKIP_REASONS = /* @__PURE__ */ new Set([
|
|
23720
|
+
"rtt-unmeasured",
|
|
23721
|
+
"rtt-exceeds-budget",
|
|
23722
|
+
"presentation-delay-unavailable"
|
|
23723
|
+
]);
|
|
23724
|
+
var REPAIR_DEADLINE_BOUNDS = /* @__PURE__ */ new Set(["wait", "presentation", "keyframe", "retention"]);
|
|
23256
23725
|
var GAP_REASONS = {
|
|
23257
23726
|
"rap-lost": "stall",
|
|
23258
23727
|
"rap-unknown": "stall",
|
|
@@ -23275,6 +23744,9 @@ function isSymbolCounts(value) {
|
|
|
23275
23744
|
function isNullableNonNegative(value) {
|
|
23276
23745
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
23277
23746
|
}
|
|
23747
|
+
function isFiniteNumber(value) {
|
|
23748
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
23749
|
+
}
|
|
23278
23750
|
function isRepairLifecycleEvent(value) {
|
|
23279
23751
|
if (!isRecord(value) || value["version"] !== 2) return false;
|
|
23280
23752
|
const block = value["block"];
|
|
@@ -23292,6 +23764,20 @@ function isRepairLifecycleEvent(value) {
|
|
|
23292
23764
|
case "repair-preempted":
|
|
23293
23765
|
case "repair-deferred":
|
|
23294
23766
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
23767
|
+
case "repair-sent":
|
|
23768
|
+
return hasExactKeys(value, [
|
|
23769
|
+
"version",
|
|
23770
|
+
"type",
|
|
23771
|
+
"block",
|
|
23772
|
+
"priority",
|
|
23773
|
+
"rttMs",
|
|
23774
|
+
"budgetMs",
|
|
23775
|
+
"delayMs",
|
|
23776
|
+
"blockAgeMs",
|
|
23777
|
+
"bound"
|
|
23778
|
+
]) && 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"]);
|
|
23779
|
+
case "repair-skipped":
|
|
23780
|
+
return hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) && isRepairBlockIdentity(block) && REPAIR_SKIP_REASONS.has(value["reason"]) && isNullableNonNegative(value["rttMs"]) && isFiniteNumber(value["budgetMs"]);
|
|
23295
23781
|
case "repair-priority": {
|
|
23296
23782
|
const blockClass = value["blockClass"];
|
|
23297
23783
|
const action = value["action"];
|
|
@@ -24481,7 +24967,7 @@ var MulticastManager = class {
|
|
|
24481
24967
|
*
|
|
24482
24968
|
* D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
|
|
24483
24969
|
* D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
|
|
24484
|
-
* D-17: Builds altGroup → track-name index for getSwitchingSet().
|
|
24970
|
+
* D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
|
|
24485
24971
|
* D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
|
|
24486
24972
|
*
|
|
24487
24973
|
* FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
|
|
@@ -24532,11 +25018,9 @@ var MulticastManager = class {
|
|
|
24532
25018
|
}
|
|
24533
25019
|
}
|
|
24534
25020
|
const repairOwnerGroup = /* @__PURE__ */ new Map();
|
|
24535
|
-
const repairOwnerAltGroup = /* @__PURE__ */ new Map();
|
|
24536
25021
|
for (const track of catalog.tracks) {
|
|
24537
25022
|
for (const repairName of repairNamesBySource.get(track.name) ?? []) {
|
|
24538
25023
|
repairOwnerGroup.set(repairName, altGroupKey(track));
|
|
24539
|
-
repairOwnerAltGroup.set(repairName, track.altGroup);
|
|
24540
25024
|
}
|
|
24541
25025
|
}
|
|
24542
25026
|
const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
|
|
@@ -24635,11 +25119,10 @@ var MulticastManager = class {
|
|
|
24635
25119
|
for (let i = 0; i < catalog.tracks.length; i++) {
|
|
24636
25120
|
const track = catalog.tracks[i];
|
|
24637
25121
|
const role = resolvedRoles[i];
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
const existing = this.#switchingSets.get(altGroup) ?? [];
|
|
25122
|
+
if (role !== "repair" && track.altGroup !== void 0) {
|
|
25123
|
+
const existing = this.#switchingSets.get(track.altGroup) ?? [];
|
|
24641
25124
|
existing.push(track.name);
|
|
24642
|
-
this.#switchingSets.set(altGroup, existing);
|
|
25125
|
+
this.#switchingSets.set(track.altGroup, existing);
|
|
24643
25126
|
}
|
|
24644
25127
|
if (track.packetId !== void 0) {
|
|
24645
25128
|
this.#router.setPacketIdRole(track.packetId, role);
|
|
@@ -24714,7 +25197,7 @@ var MulticastManager = class {
|
|
|
24714
25197
|
#multiTrackFecTracks = /* @__PURE__ */ new Map();
|
|
24715
25198
|
/**
|
|
24716
25199
|
* Return the track names belonging to the given altGroup switching set.
|
|
24717
|
-
* D-17:
|
|
25200
|
+
* D-17: tracks with equal altGroup form one switching set; repair legs are in none.
|
|
24718
25201
|
*
|
|
24719
25202
|
* @param altGroup - The altGroup number to look up.
|
|
24720
25203
|
* @returns Array of track names in that switching set (empty if none).
|
|
@@ -24742,6 +25225,26 @@ var MulticastManager = class {
|
|
|
24742
25225
|
this.requestRepairForBlock(sbn, packetId, catalogTrackName, blockClass);
|
|
24743
25226
|
};
|
|
24744
25227
|
}
|
|
25228
|
+
/**
|
|
25229
|
+
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
25230
|
+
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
25231
|
+
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
25232
|
+
* once its range FETCH ends (or none is sent).
|
|
25233
|
+
*/
|
|
25234
|
+
onUndelimitedLoss(cb) {
|
|
25235
|
+
this.#fec.setUndelimitedLossHandler(cb);
|
|
25236
|
+
}
|
|
25237
|
+
/**
|
|
25238
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
25239
|
+
* to CmcdProducer.updateFecFailClosed.
|
|
25240
|
+
*/
|
|
25241
|
+
onFecFailClosed(cb) {
|
|
25242
|
+
this.#fec.setFecFailClosedHandler(cb);
|
|
25243
|
+
}
|
|
25244
|
+
/** End a pending hole's range repair: feed what no repair stated as spans. */
|
|
25245
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
25246
|
+
this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
|
|
25247
|
+
}
|
|
24745
25248
|
/**
|
|
24746
25249
|
* Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
|
|
24747
25250
|
* supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
|
|
@@ -24763,6 +25266,7 @@ var MulticastManager = class {
|
|
|
24763
25266
|
stats.repairsSkipped++;
|
|
24764
25267
|
if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
|
|
24765
25268
|
else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
|
|
25269
|
+
else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
|
|
24766
25270
|
else stats.repairsSkippedPresentationDelayUnavailable++;
|
|
24767
25271
|
stats.lastRepairSkip = {
|
|
24768
25272
|
reason,
|
|
@@ -24794,8 +25298,20 @@ var MulticastManager = class {
|
|
|
24794
25298
|
stats.keyframeBudgetHoldMs += extensionMs;
|
|
24795
25299
|
}
|
|
24796
25300
|
/** Record a repair FETCH the scheduler admitted and sent. */
|
|
24797
|
-
noteRepairFetchSent(priority,
|
|
25301
|
+
noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
|
|
24798
25302
|
if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
|
|
25303
|
+
if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
|
|
25304
|
+
this.#emitRepairLifecycle({
|
|
25305
|
+
version: 2,
|
|
25306
|
+
type: "repair-sent",
|
|
25307
|
+
block: repairBlockIdentity(packetId, sbn, catalogTrackName),
|
|
25308
|
+
priority,
|
|
25309
|
+
rttMs: measurement.rttMs,
|
|
25310
|
+
budgetMs: measurement.budgetMs,
|
|
25311
|
+
delayMs: measurement.delayMs,
|
|
25312
|
+
blockAgeMs: measurement.blockAgeMs,
|
|
25313
|
+
bound: measurement.bound
|
|
25314
|
+
});
|
|
24799
25315
|
}
|
|
24800
25316
|
/**
|
|
24801
25317
|
* Record a repair-scheduler decision about a delta block: preempted for
|
|
@@ -25022,7 +25538,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
25022
25538
|
trackType: opts.trackType,
|
|
25023
25539
|
framerate: opts.framerate,
|
|
25024
25540
|
sampleRate: opts.sampleRate,
|
|
25025
|
-
algorithm: "
|
|
25541
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
25026
25542
|
blockProfile,
|
|
25027
25543
|
k: opts.fecK,
|
|
25028
25544
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
@@ -25039,6 +25555,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
25039
25555
|
try {
|
|
25040
25556
|
opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
|
|
25041
25557
|
blockProfile,
|
|
25558
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
25042
25559
|
k: opts.fecK,
|
|
25043
25560
|
symbolSize: opts.fecSymbolSize,
|
|
25044
25561
|
interleaveDepthMs: opts.fecInterleaveMs,
|
|
@@ -25046,7 +25563,9 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
25046
25563
|
// the local cleanup budget, but it must not use a guessed fps for timing
|
|
25047
25564
|
// or classification.
|
|
25048
25565
|
...hasCatalogTiming ? { fps: 1e3 / opts.mediaUnitDurationMs } : {},
|
|
25049
|
-
timeoutMs: deliveryWindowMs
|
|
25566
|
+
timeoutMs: deliveryWindowMs,
|
|
25567
|
+
...opts.fecRepairLayers ? { repairLayers: opts.fecRepairLayers } : {},
|
|
25568
|
+
...opts.heldRepairLayers ? { heldLayers: opts.heldRepairLayers } : {}
|
|
25050
25569
|
}, opts.trackName);
|
|
25051
25570
|
} catch (e) {
|
|
25052
25571
|
try {
|
|
@@ -25712,7 +26231,7 @@ function asSeconds(n) {
|
|
|
25712
26231
|
}
|
|
25713
26232
|
return n;
|
|
25714
26233
|
}
|
|
25715
|
-
function groupIdForTicks(ticks, groupDurationTicks) {
|
|
26234
|
+
function groupIdForTicks(ticks, groupDurationTicks, presentationAnchorTicks = 0) {
|
|
25716
26235
|
if (!Number.isInteger(ticks)) {
|
|
25717
26236
|
throw new Error(
|
|
25718
26237
|
`[align] groupIdForTicks: ticks must be an integer, got ${ticks}`
|
|
@@ -25723,8 +26242,23 @@ function groupIdForTicks(ticks, groupDurationTicks) {
|
|
|
25723
26242
|
`[align] groupIdForTicks: groupDurationTicks must be a positive integer, got ${groupDurationTicks}`
|
|
25724
26243
|
);
|
|
25725
26244
|
}
|
|
25726
|
-
if (
|
|
25727
|
-
|
|
26245
|
+
if (!Number.isInteger(presentationAnchorTicks)) {
|
|
26246
|
+
throw new Error(
|
|
26247
|
+
`[align] groupIdForTicks: presentationAnchorTicks must be an integer, got ${presentationAnchorTicks}`
|
|
26248
|
+
);
|
|
26249
|
+
}
|
|
26250
|
+
const relativeTicks = ticks - presentationAnchorTicks;
|
|
26251
|
+
if (!Number.isSafeInteger(relativeTicks)) {
|
|
26252
|
+
throw new Error(
|
|
26253
|
+
`[align] groupIdForTicks: ticks - presentationAnchorTicks = ${relativeTicks} is not a safe integer`
|
|
26254
|
+
);
|
|
26255
|
+
}
|
|
26256
|
+
if (relativeTicks < 0) {
|
|
26257
|
+
throw new Error(
|
|
26258
|
+
`[align] groupIdForTicks: ticks ${ticks} precede presentationAnchorTicks ${presentationAnchorTicks}; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26259
|
+
);
|
|
26260
|
+
}
|
|
26261
|
+
return Math.floor(relativeTicks / groupDurationTicks);
|
|
25728
26262
|
}
|
|
25729
26263
|
function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
25730
26264
|
if (!Number.isFinite(mediaTimeSec)) {
|
|
@@ -25737,7 +26271,11 @@ function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
|
25737
26271
|
`[align] groupIdFor: groupDurationSec must be a positive finite number, got ${groupDurationSec}`
|
|
25738
26272
|
);
|
|
25739
26273
|
}
|
|
25740
|
-
if (mediaTimeSec < 0)
|
|
26274
|
+
if (mediaTimeSec < 0) {
|
|
26275
|
+
throw new Error(
|
|
26276
|
+
`[align] groupIdFor: mediaTimeSec ${mediaTimeSec} precedes presentationAnchorTicks 0; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26277
|
+
);
|
|
26278
|
+
}
|
|
25741
26279
|
const TS = 1e9;
|
|
25742
26280
|
const ticks = Math.round(mediaTimeSec * TS);
|
|
25743
26281
|
const durTicks = Math.round(groupDurationSec * TS);
|
|
@@ -26578,6 +27116,7 @@ var CmcdProducer = class {
|
|
|
26578
27116
|
#deltaFailRate = null;
|
|
26579
27117
|
#switchMiscount = 0;
|
|
26580
27118
|
#manifestStats = null;
|
|
27119
|
+
#fecFailClosed = null;
|
|
26581
27120
|
constructor(options) {
|
|
26582
27121
|
this.#onCmcdParams = options.onCmcdParams;
|
|
26583
27122
|
this.#onCmcdPost = options.onCmcdPost;
|
|
@@ -26619,6 +27158,15 @@ var CmcdProducer = class {
|
|
|
26619
27158
|
incrementSwitchMiscount() {
|
|
26620
27159
|
this.#switchMiscount += 1;
|
|
26621
27160
|
}
|
|
27161
|
+
/**
|
|
27162
|
+
* Record that FEC failed closed at runtime (fec-01 6.3.9). Every later
|
|
27163
|
+
* snapshot carries `x-bc-fec-fail-closed` (the reason code) and
|
|
27164
|
+
* `x-bc-fec-fail-layer` (the held layer i whose total B_i was undercut), so a
|
|
27165
|
+
* stream playing without FEC is told apart from one with no loss.
|
|
27166
|
+
*/
|
|
27167
|
+
updateFecFailClosed(reason) {
|
|
27168
|
+
this.#fecFailClosed = reason;
|
|
27169
|
+
}
|
|
26622
27170
|
updateManifestVerification(stats) {
|
|
26623
27171
|
this.#manifestStats = stats;
|
|
26624
27172
|
}
|
|
@@ -26656,6 +27204,10 @@ var CmcdProducer = class {
|
|
|
26656
27204
|
if (this.#playMode !== null) {
|
|
26657
27205
|
params["x-bc-play-mode"] = this.#playMode;
|
|
26658
27206
|
}
|
|
27207
|
+
if (this.#fecFailClosed) {
|
|
27208
|
+
params["x-bc-fec-fail-closed"] = this.#fecFailClosed.code;
|
|
27209
|
+
params["x-bc-fec-fail-layer"] = this.#fecFailClosed.layer;
|
|
27210
|
+
}
|
|
26659
27211
|
if (this.#playMode !== null && this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
26660
27212
|
params["x-bc-delta-fail-rate"] = parseFloat(this.#deltaFailRate.toFixed(4));
|
|
26661
27213
|
}
|
|
@@ -26708,6 +27260,346 @@ var CmcdProducer = class {
|
|
|
26708
27260
|
}
|
|
26709
27261
|
};
|
|
26710
27262
|
|
|
27263
|
+
// src/mmtp-fec-session.ts
|
|
27264
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
27265
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
27266
|
+
var MmtpFecSession = class {
|
|
27267
|
+
#decoder;
|
|
27268
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
27269
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
27270
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
27271
|
+
#settled = /* @__PURE__ */ new Set();
|
|
27272
|
+
/**
|
|
27273
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
27274
|
+
* received on, or 0 for one the session recovered.
|
|
27275
|
+
*/
|
|
27276
|
+
#have = /* @__PURE__ */ new Map();
|
|
27277
|
+
#newest;
|
|
27278
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
27279
|
+
#prunedAt;
|
|
27280
|
+
#repairPacketId;
|
|
27281
|
+
#stats = {
|
|
27282
|
+
sourceSymbols: 0,
|
|
27283
|
+
repairSymbols: 0,
|
|
27284
|
+
blocksClean: 0,
|
|
27285
|
+
blocksRecovered: 0,
|
|
27286
|
+
blocksFailed: 0,
|
|
27287
|
+
blocksReleased: 0,
|
|
27288
|
+
packetsRecovered: 0,
|
|
27289
|
+
packetsLost: 0,
|
|
27290
|
+
dropped: {},
|
|
27291
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27292
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27293
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
27294
|
+
};
|
|
27295
|
+
/**
|
|
27296
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
27297
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
27298
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
27299
|
+
*/
|
|
27300
|
+
constructor(config) {
|
|
27301
|
+
const fec = config?.fec;
|
|
27302
|
+
if (!fec || typeof fec !== "object") {
|
|
27303
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
27304
|
+
}
|
|
27305
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
27306
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
27307
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
27308
|
+
}
|
|
27309
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
27310
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
27311
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
27312
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
27313
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
27314
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
27315
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
27316
|
+
interleaveDepthMs
|
|
27317
|
+
);
|
|
27318
|
+
if (typeof config.Decoder !== "function") {
|
|
27319
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
27320
|
+
}
|
|
27321
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
27322
|
+
try {
|
|
27323
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
27324
|
+
} catch (error) {
|
|
27325
|
+
decoder.free();
|
|
27326
|
+
throw error;
|
|
27327
|
+
}
|
|
27328
|
+
this.#decoder = decoder;
|
|
27329
|
+
}
|
|
27330
|
+
/** True once release() ran. */
|
|
27331
|
+
get released() {
|
|
27332
|
+
return this.#decoder === null;
|
|
27333
|
+
}
|
|
27334
|
+
get stats() {
|
|
27335
|
+
return {
|
|
27336
|
+
...this.#stats,
|
|
27337
|
+
dropped: { ...this.#stats.dropped },
|
|
27338
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
27339
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
27340
|
+
mixedPath: { ...this.#stats.mixedPath }
|
|
27341
|
+
};
|
|
27342
|
+
}
|
|
27343
|
+
/**
|
|
27344
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
27345
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
27346
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
27347
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
27348
|
+
*
|
|
27349
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
27350
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
27351
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
27352
|
+
*/
|
|
27353
|
+
addSource(ssId, packet, path = "moq") {
|
|
27354
|
+
const decoder = this.#decoder;
|
|
27355
|
+
if (!decoder) return this.#drop("source:released");
|
|
27356
|
+
const pathBit = PATH_BITS[path];
|
|
27357
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
27358
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
27359
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
27360
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
27361
|
+
this.#have.set(ssId, pathBit);
|
|
27362
|
+
this.#stats.sourceSymbols++;
|
|
27363
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
27364
|
+
this.#noteNewest(ssId);
|
|
27365
|
+
const start = this.#blockStartOf(ssId);
|
|
27366
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
27367
|
+
if (block) {
|
|
27368
|
+
block.received++;
|
|
27369
|
+
block.paths |= pathBit;
|
|
27370
|
+
}
|
|
27371
|
+
let output;
|
|
27372
|
+
try {
|
|
27373
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
27374
|
+
} catch {
|
|
27375
|
+
this.#drop("source:decoder-refused");
|
|
27376
|
+
output = void 0;
|
|
27377
|
+
}
|
|
27378
|
+
const recovered = [];
|
|
27379
|
+
if (start !== void 0 && block) {
|
|
27380
|
+
if (output) {
|
|
27381
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
27382
|
+
} else if (block.received >= block.ssbLength) {
|
|
27383
|
+
this.#settleClean(start);
|
|
27384
|
+
}
|
|
27385
|
+
}
|
|
27386
|
+
this.#retireBehindHorizon();
|
|
27387
|
+
return recovered;
|
|
27388
|
+
}
|
|
27389
|
+
/**
|
|
27390
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
27391
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
27392
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
27393
|
+
* `path` is where it was received, as for addSource().
|
|
27394
|
+
*
|
|
27395
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
27396
|
+
* addSource().
|
|
27397
|
+
*/
|
|
27398
|
+
addRepair(packet, path = "moq") {
|
|
27399
|
+
const decoder = this.#decoder;
|
|
27400
|
+
if (!decoder) return this.#drop("repair:released");
|
|
27401
|
+
const pathBit = PATH_BITS[path];
|
|
27402
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
27403
|
+
let header;
|
|
27404
|
+
try {
|
|
27405
|
+
header = parseMMTPHeader(packet);
|
|
27406
|
+
} catch {
|
|
27407
|
+
return this.#drop("repair:malformed");
|
|
27408
|
+
}
|
|
27409
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
27410
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
27411
|
+
if (this.#repairPacketId === void 0) {
|
|
27412
|
+
this.#repairPacketId = frame.packetId;
|
|
27413
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
27414
|
+
return this.#drop("repair:foreign-packet-id");
|
|
27415
|
+
}
|
|
27416
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
27417
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
27418
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
27419
|
+
return this.#drop("repair:rs-block-length");
|
|
27420
|
+
}
|
|
27421
|
+
const start = frame.ssStart;
|
|
27422
|
+
let block = this.#blocks.get(start);
|
|
27423
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
27424
|
+
if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
|
|
27425
|
+
if (!block) {
|
|
27426
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
27427
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
27428
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
27429
|
+
this.#countHeld(start, block);
|
|
27430
|
+
this.#blocks.set(start, block);
|
|
27431
|
+
}
|
|
27432
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
27433
|
+
if (block.received >= block.ssbLength) {
|
|
27434
|
+
this.#settleClean(start);
|
|
27435
|
+
this.#retireBehindHorizon();
|
|
27436
|
+
return [];
|
|
27437
|
+
}
|
|
27438
|
+
let output;
|
|
27439
|
+
try {
|
|
27440
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
27441
|
+
} catch {
|
|
27442
|
+
return this.#drop("repair:decoder-refused");
|
|
27443
|
+
}
|
|
27444
|
+
block.rsIds.add(frame.rsId);
|
|
27445
|
+
this.#stats.repairSymbols++;
|
|
27446
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
27447
|
+
block.paths |= pathBit;
|
|
27448
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
27449
|
+
this.#retireBehindHorizon();
|
|
27450
|
+
return recovered;
|
|
27451
|
+
}
|
|
27452
|
+
/**
|
|
27453
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
27454
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
27455
|
+
* returns whether this call released anything.
|
|
27456
|
+
*/
|
|
27457
|
+
release() {
|
|
27458
|
+
const decoder = this.#decoder;
|
|
27459
|
+
if (!decoder) return false;
|
|
27460
|
+
this.#decoder = null;
|
|
27461
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
27462
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
27463
|
+
this.#blocks.clear();
|
|
27464
|
+
this.#settled.clear();
|
|
27465
|
+
this.#have.clear();
|
|
27466
|
+
decoder.free();
|
|
27467
|
+
return true;
|
|
27468
|
+
}
|
|
27469
|
+
#drop(reason) {
|
|
27470
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
27471
|
+
return [];
|
|
27472
|
+
}
|
|
27473
|
+
#noteNewest(ssId) {
|
|
27474
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
27475
|
+
}
|
|
27476
|
+
#blockStartOf(ssId) {
|
|
27477
|
+
for (const [start, block] of this.#blocks) {
|
|
27478
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
27479
|
+
}
|
|
27480
|
+
return void 0;
|
|
27481
|
+
}
|
|
27482
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
27483
|
+
#countHeld(start, block) {
|
|
27484
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27485
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
27486
|
+
if (pathBit === void 0) continue;
|
|
27487
|
+
block.received++;
|
|
27488
|
+
block.paths |= pathBit;
|
|
27489
|
+
}
|
|
27490
|
+
}
|
|
27491
|
+
#noteMixed(block, outcome) {
|
|
27492
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
27493
|
+
}
|
|
27494
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
27495
|
+
#behindHorizon(start) {
|
|
27496
|
+
const newest = this.#newest;
|
|
27497
|
+
if (newest === void 0) return false;
|
|
27498
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
27499
|
+
}
|
|
27500
|
+
#settle(start) {
|
|
27501
|
+
this.#blocks.delete(start);
|
|
27502
|
+
this.#settled.add(start);
|
|
27503
|
+
}
|
|
27504
|
+
#settleClean(start) {
|
|
27505
|
+
const block = this.#blocks.get(start);
|
|
27506
|
+
if (!block) return;
|
|
27507
|
+
this.#settle(start);
|
|
27508
|
+
this.#stats.blocksClean++;
|
|
27509
|
+
this.#noteMixed(block, "clean");
|
|
27510
|
+
try {
|
|
27511
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
27512
|
+
} catch {
|
|
27513
|
+
}
|
|
27514
|
+
}
|
|
27515
|
+
/**
|
|
27516
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
27517
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
27518
|
+
* back the packets the parser does not have yet.
|
|
27519
|
+
*/
|
|
27520
|
+
#settleDecoded(start, block, output) {
|
|
27521
|
+
this.#settle(start);
|
|
27522
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
27523
|
+
this.#stats.blocksFailed++;
|
|
27524
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27525
|
+
this.#noteMixed(block, "failed");
|
|
27526
|
+
this.#drop("block:decoded-length");
|
|
27527
|
+
return [];
|
|
27528
|
+
}
|
|
27529
|
+
const recovered = [];
|
|
27530
|
+
let refused = 0;
|
|
27531
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27532
|
+
const ssId = serial32Add(start, i);
|
|
27533
|
+
if (this.#have.has(ssId)) continue;
|
|
27534
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
27535
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
27536
|
+
if (!packet) {
|
|
27537
|
+
refused++;
|
|
27538
|
+
continue;
|
|
27539
|
+
}
|
|
27540
|
+
this.#have.set(ssId, 0);
|
|
27541
|
+
recovered.push(packet.slice());
|
|
27542
|
+
}
|
|
27543
|
+
if (refused > 0) {
|
|
27544
|
+
this.#stats.blocksFailed++;
|
|
27545
|
+
this.#stats.packetsLost += refused;
|
|
27546
|
+
this.#noteMixed(block, "failed");
|
|
27547
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
27548
|
+
} else if (recovered.length === 0) {
|
|
27549
|
+
this.#stats.blocksClean++;
|
|
27550
|
+
this.#noteMixed(block, "clean");
|
|
27551
|
+
} else {
|
|
27552
|
+
this.#stats.blocksRecovered++;
|
|
27553
|
+
this.#noteMixed(block, "recovered");
|
|
27554
|
+
}
|
|
27555
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
27556
|
+
return recovered;
|
|
27557
|
+
}
|
|
27558
|
+
/**
|
|
27559
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
27560
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
27561
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
27562
|
+
* restore, or its repair never arrived.
|
|
27563
|
+
*/
|
|
27564
|
+
#retireBehindHorizon() {
|
|
27565
|
+
const decoder = this.#decoder;
|
|
27566
|
+
const newest = this.#newest;
|
|
27567
|
+
if (!decoder || newest === void 0) return;
|
|
27568
|
+
try {
|
|
27569
|
+
decoder.cleanup_by_ss_start(newest);
|
|
27570
|
+
} catch {
|
|
27571
|
+
}
|
|
27572
|
+
for (const [start, block] of this.#blocks) {
|
|
27573
|
+
if (!this.#behindHorizon(start)) continue;
|
|
27574
|
+
this.#settle(start);
|
|
27575
|
+
this.#stats.blocksFailed++;
|
|
27576
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27577
|
+
this.#noteMixed(block, "failed");
|
|
27578
|
+
}
|
|
27579
|
+
const prunedAt = this.#prunedAt;
|
|
27580
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
27581
|
+
this.#prunedAt = newest;
|
|
27582
|
+
for (const ssId of this.#have.keys()) {
|
|
27583
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
27584
|
+
}
|
|
27585
|
+
for (const start of this.#settled) {
|
|
27586
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
27587
|
+
}
|
|
27588
|
+
}
|
|
27589
|
+
};
|
|
27590
|
+
function requirePositiveInteger(value, path) {
|
|
27591
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
27592
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
27593
|
+
}
|
|
27594
|
+
return value;
|
|
27595
|
+
}
|
|
27596
|
+
function requireNumber(value, path) {
|
|
27597
|
+
if (typeof value !== "number") {
|
|
27598
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
27599
|
+
}
|
|
27600
|
+
return value;
|
|
27601
|
+
}
|
|
27602
|
+
|
|
26711
27603
|
// src/repair-fetch.ts
|
|
26712
27604
|
var MOQT_PRIORITY_MAX = 255;
|
|
26713
27605
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
@@ -26742,6 +27634,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26742
27634
|
if (typeof opts.presentationDelayMs !== "function") {
|
|
26743
27635
|
throw new Error("[RepairFetch] presentationDelayMs is required: a repair FETCH is due by the block's presentation deadline");
|
|
26744
27636
|
}
|
|
27637
|
+
if (opts.rangeTransport !== void 0 && (typeof opts.repairEpochReference !== "function" || !mc.onUndelimitedLoss || !mc.closeIsoHoles)) {
|
|
27638
|
+
throw new Error("[RepairFetch] rangeTransport needs repairEpochReference and a host that reports undelimited losses");
|
|
27639
|
+
}
|
|
26745
27640
|
const entries = /* @__PURE__ */ new Map();
|
|
26746
27641
|
const warnedNoTarget = /* @__PURE__ */ new Set();
|
|
26747
27642
|
let disposed = false;
|
|
@@ -26755,7 +27650,12 @@ function wireRepairFetch(mc, opts) {
|
|
|
26755
27650
|
const note = (type, entry) => {
|
|
26756
27651
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26757
27652
|
};
|
|
27653
|
+
const clearEntry = (entry) => {
|
|
27654
|
+
if (entry.range) mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength);
|
|
27655
|
+
else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
27656
|
+
};
|
|
26758
27657
|
const releaseHold = (entry) => {
|
|
27658
|
+
if (entry.range) return;
|
|
26759
27659
|
if (entry.catalogTrackName === void 0) mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId);
|
|
26760
27660
|
else mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26761
27661
|
};
|
|
@@ -26788,10 +27688,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
26788
27688
|
const admit = (entry, now) => {
|
|
26789
27689
|
const budgetMs = entry.deadlineAt - now;
|
|
26790
27690
|
const rttMs = readRtt();
|
|
26791
|
-
if (rttMs !== null && rttMs < budgetMs) return
|
|
27691
|
+
if (rttMs !== null && rttMs < budgetMs) return rttMs;
|
|
26792
27692
|
retire(entry);
|
|
26793
27693
|
releaseHold(entry);
|
|
26794
|
-
|
|
27694
|
+
clearEntry(entry);
|
|
26795
27695
|
mc.noteRepairSkipped(
|
|
26796
27696
|
rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
|
|
26797
27697
|
{ rttMs, budgetMs, priority: entry.priority },
|
|
@@ -26799,10 +27699,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
26799
27699
|
entry.packetId,
|
|
26800
27700
|
entry.catalogTrackName
|
|
26801
27701
|
);
|
|
26802
|
-
return
|
|
27702
|
+
return null;
|
|
26803
27703
|
};
|
|
26804
27704
|
const retire = (entry) => {
|
|
26805
27705
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
27706
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
26806
27707
|
};
|
|
26807
27708
|
const urgentOutstanding = () => {
|
|
26808
27709
|
for (const entry of entries.values()) {
|
|
@@ -26831,17 +27732,28 @@ function wireRepairFetch(mc, opts) {
|
|
|
26831
27732
|
return derived.kind === "omit" ? { subscriberPriority: void 0 } : null;
|
|
26832
27733
|
};
|
|
26833
27734
|
const start = (entry, counted = true) => {
|
|
26834
|
-
|
|
27735
|
+
const now = performance.now();
|
|
27736
|
+
const rttMs = admit(entry, now);
|
|
27737
|
+
if (rttMs === null) return;
|
|
26835
27738
|
if (counted) entry.attempts++;
|
|
26836
|
-
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName
|
|
27739
|
+
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
27740
|
+
rttMs,
|
|
27741
|
+
budgetMs: entry.deadlineAt - now,
|
|
27742
|
+
delayMs: entry.delayMs,
|
|
27743
|
+
blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
|
|
27744
|
+
bound: entry.bound,
|
|
27745
|
+
...entry.range ? { range: true } : {}
|
|
27746
|
+
});
|
|
26837
27747
|
const run = { controller: new AbortController(), stopped: null };
|
|
26838
27748
|
entry.running = run;
|
|
26839
|
-
|
|
26840
|
-
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
27749
|
+
if (!entry.range) {
|
|
27750
|
+
mc.fecManager.holdBlockForRepair(
|
|
27751
|
+
entry.sbn,
|
|
27752
|
+
entry.packetId,
|
|
27753
|
+
entry.catalogTrackName,
|
|
27754
|
+
entry.deadlineAt
|
|
27755
|
+
);
|
|
27756
|
+
}
|
|
26845
27757
|
void execute(entry, run);
|
|
26846
27758
|
};
|
|
26847
27759
|
const dispatch = () => {
|
|
@@ -26853,14 +27765,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
26853
27765
|
if (entry.deadlineAt <= now) {
|
|
26854
27766
|
stop(entry, "expired");
|
|
26855
27767
|
retire(entry);
|
|
26856
|
-
|
|
27768
|
+
clearEntry(entry);
|
|
26857
27769
|
}
|
|
26858
27770
|
continue;
|
|
26859
27771
|
}
|
|
26860
27772
|
if (entry.deadlineAt <= now) {
|
|
26861
27773
|
retire(entry);
|
|
26862
27774
|
if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
|
|
26863
|
-
|
|
27775
|
+
clearEntry(entry);
|
|
26864
27776
|
continue;
|
|
26865
27777
|
}
|
|
26866
27778
|
queued.push(entry);
|
|
@@ -26897,9 +27809,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26897
27809
|
entry.running = null;
|
|
26898
27810
|
if (error === void 0) {
|
|
26899
27811
|
retire(entry);
|
|
26900
|
-
if (fed === 0 || !decodable(entry)) {
|
|
27812
|
+
if (entry.range || fed === 0 || !decodable(entry)) {
|
|
26901
27813
|
releaseHold(entry);
|
|
26902
|
-
|
|
27814
|
+
clearEntry(entry);
|
|
26903
27815
|
}
|
|
26904
27816
|
dispatch();
|
|
26905
27817
|
return;
|
|
@@ -26911,7 +27823,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26911
27823
|
}
|
|
26912
27824
|
retire(entry);
|
|
26913
27825
|
if (fed === 0) releaseHold(entry);
|
|
26914
|
-
|
|
27826
|
+
clearEntry(entry);
|
|
26915
27827
|
console.warn(
|
|
26916
27828
|
`[RepairFetch] fetch failed pid=${entry.packetId} sbn=${entry.sbn} track=${entry.repairTrack}:`,
|
|
26917
27829
|
error
|
|
@@ -26927,15 +27839,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
26927
27839
|
};
|
|
26928
27840
|
const execute = async (entry, run) => {
|
|
26929
27841
|
let fed = 0;
|
|
27842
|
+
const common = {
|
|
27843
|
+
repairTrack: entry.repairTrack,
|
|
27844
|
+
blockProfile: entry.blockProfile,
|
|
27845
|
+
packetId: entry.packetId,
|
|
27846
|
+
signal: run.controller.signal,
|
|
27847
|
+
subscriberPriority: entry.subscriberPriority
|
|
27848
|
+
};
|
|
26930
27849
|
try {
|
|
26931
|
-
|
|
26932
|
-
|
|
26933
|
-
|
|
26934
|
-
|
|
26935
|
-
|
|
26936
|
-
|
|
26937
|
-
|
|
26938
|
-
})) {
|
|
27850
|
+
const packets = entry.range ? opts.rangeTransport({
|
|
27851
|
+
...common,
|
|
27852
|
+
startGroup: entry.range.startGroup,
|
|
27853
|
+
endGroup: entry.range.endGroup,
|
|
27854
|
+
lostSsId: entry.range.lostSsId
|
|
27855
|
+
}) : opts.transport({ ...common, sbn: entry.sbn });
|
|
27856
|
+
for await (const packet of packets) {
|
|
26939
27857
|
if (run.stopped !== null || entry.running !== run) break;
|
|
26940
27858
|
fed++;
|
|
26941
27859
|
if (entry.catalogTrackName === void 0) {
|
|
@@ -26954,6 +27872,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26954
27872
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
26955
27873
|
retire(entry);
|
|
26956
27874
|
stop(entry, "reset");
|
|
27875
|
+
if (entry.range) clearEntry(entry);
|
|
26957
27876
|
}
|
|
26958
27877
|
warnedNoTarget.delete(noTargetKey(packetId, catalogTrackName));
|
|
26959
27878
|
dispatch();
|
|
@@ -26980,6 +27899,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26980
27899
|
);
|
|
26981
27900
|
if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
|
|
26982
27901
|
entry2.deadlineAt = promotedDeadline.deadlineAt;
|
|
27902
|
+
entry2.anchorAt = promotedDeadline.anchorAt;
|
|
27903
|
+
entry2.delayMs = promotedDeadline.delayMs;
|
|
27904
|
+
entry2.bound = promotedDeadline.bound;
|
|
26983
27905
|
noteBudget(entry2, promotedDeadline.extensionMs);
|
|
26984
27906
|
}
|
|
26985
27907
|
if (entry2.running) {
|
|
@@ -27005,7 +27927,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
27005
27927
|
if (waitMs === void 0) return null;
|
|
27006
27928
|
const waitDeadlineAt = now + waitMs;
|
|
27007
27929
|
const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
|
|
27008
|
-
if (anchor === void 0)
|
|
27930
|
+
if (anchor === void 0) {
|
|
27931
|
+
return { deadlineAt: waitDeadlineAt, extensionMs: 0, anchorAt: null, delayMs: null, bound: "wait" };
|
|
27932
|
+
}
|
|
27009
27933
|
let delayMs;
|
|
27010
27934
|
try {
|
|
27011
27935
|
delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
|
|
@@ -27016,12 +27940,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
27016
27940
|
const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
|
|
27017
27941
|
if (retentionMs === void 0) return null;
|
|
27018
27942
|
const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
|
|
27019
|
-
const
|
|
27020
|
-
|
|
27943
|
+
const at = (delay, delayBound) => {
|
|
27944
|
+
const presentAt = Math.min(anchor + delay, ceilingAt);
|
|
27945
|
+
if (waitDeadlineAt >= presentAt) return { deadlineAt: waitDeadlineAt, bound: "wait" };
|
|
27946
|
+
return { deadlineAt: presentAt, bound: anchor + delay <= ceilingAt ? delayBound : "retention" };
|
|
27947
|
+
};
|
|
27948
|
+
const base = at(delayMs, "presentation");
|
|
27021
27949
|
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 {
|
|
27950
|
+
if (budgetMs === null || budgetMs <= delayMs) return { ...base, extensionMs: 0, anchorAt: anchor, delayMs };
|
|
27951
|
+
const extended = at(budgetMs, "keyframe");
|
|
27952
|
+
return {
|
|
27953
|
+
...extended,
|
|
27954
|
+
extensionMs: extended.deadlineAt - base.deadlineAt,
|
|
27955
|
+
anchorAt: anchor,
|
|
27956
|
+
delayMs: budgetMs
|
|
27957
|
+
};
|
|
27025
27958
|
};
|
|
27026
27959
|
const earliestGatedFrameAt = (packetId, catalogTrackName) => {
|
|
27027
27960
|
try {
|
|
@@ -27098,6 +28031,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
27098
28031
|
priority,
|
|
27099
28032
|
subscriberPriority: wire.subscriberPriority,
|
|
27100
28033
|
deadlineAt: deadline.deadlineAt,
|
|
28034
|
+
anchorAt: deadline.anchorAt,
|
|
28035
|
+
delayMs: deadline.delayMs,
|
|
28036
|
+
bound: deadline.bound,
|
|
27101
28037
|
order: enqueueOrder++,
|
|
27102
28038
|
attempts: 0,
|
|
27103
28039
|
running: null
|
|
@@ -27107,14 +28043,92 @@ function wireRepairFetch(mc, opts) {
|
|
|
27107
28043
|
if (entry.priority < 2) preemptDeltas();
|
|
27108
28044
|
dispatch();
|
|
27109
28045
|
});
|
|
28046
|
+
const rangeFor = (loss, repairTrack) => {
|
|
28047
|
+
let reference;
|
|
28048
|
+
try {
|
|
28049
|
+
reference = opts.repairEpochReference(repairTrack);
|
|
28050
|
+
} catch {
|
|
28051
|
+
return null;
|
|
28052
|
+
}
|
|
28053
|
+
if (reference === void 0) return null;
|
|
28054
|
+
try {
|
|
28055
|
+
const anchor = loss.previousBlockStart === void 0 ? { reference } : { previousBlockStart: extendSsId(reference, loss.previousBlockStart) };
|
|
28056
|
+
return repairFetchRange(loss.lostSsId, loss.kMax, anchor);
|
|
28057
|
+
} catch (error) {
|
|
28058
|
+
if (error instanceof RangeError) return null;
|
|
28059
|
+
throw error;
|
|
28060
|
+
}
|
|
28061
|
+
};
|
|
28062
|
+
if (opts.rangeTransport !== void 0) {
|
|
28063
|
+
mc.onUndelimitedLoss((loss) => {
|
|
28064
|
+
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
28065
|
+
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
28066
|
+
if (disposed) return close();
|
|
28067
|
+
const blockProfile = blockProfileOf(packetId);
|
|
28068
|
+
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
28069
|
+
if (!target) return close();
|
|
28070
|
+
const priority = repairPriorityForClass("unknown");
|
|
28071
|
+
const range = rangeFor(loss, target.repairTrack);
|
|
28072
|
+
if (range === null) {
|
|
28073
|
+
close();
|
|
28074
|
+
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
28075
|
+
return;
|
|
28076
|
+
}
|
|
28077
|
+
const identity = {
|
|
28078
|
+
target,
|
|
28079
|
+
sbn: holeStart,
|
|
28080
|
+
packetId,
|
|
28081
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
28082
|
+
};
|
|
28083
|
+
const wire = wirePriority(identity, "unknown");
|
|
28084
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), "unknown");
|
|
28085
|
+
if (deadline === null) {
|
|
28086
|
+
close();
|
|
28087
|
+
mc.noteRepairSkipped(
|
|
28088
|
+
"presentation-delay-unavailable",
|
|
28089
|
+
{ rttMs: readRtt(), budgetMs: 0, priority },
|
|
28090
|
+
holeStart,
|
|
28091
|
+
packetId,
|
|
28092
|
+
catalogTrackName
|
|
28093
|
+
);
|
|
28094
|
+
return;
|
|
28095
|
+
}
|
|
28096
|
+
const entry = {
|
|
28097
|
+
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
28098
|
+
...identity,
|
|
28099
|
+
repairTrack: target.repairTrack,
|
|
28100
|
+
blockProfile,
|
|
28101
|
+
priority,
|
|
28102
|
+
subscriberPriority: wire.subscriberPriority,
|
|
28103
|
+
deadlineAt: deadline.deadlineAt,
|
|
28104
|
+
anchorAt: deadline.anchorAt,
|
|
28105
|
+
delayMs: deadline.delayMs,
|
|
28106
|
+
bound: deadline.bound,
|
|
28107
|
+
order: enqueueOrder++,
|
|
28108
|
+
attempts: 0,
|
|
28109
|
+
running: null,
|
|
28110
|
+
range: { ...range, lostSsId: loss.lostSsId, holeLength }
|
|
28111
|
+
};
|
|
28112
|
+
const previous = entries.get(entry.key);
|
|
28113
|
+
if (previous) {
|
|
28114
|
+
retire(previous);
|
|
28115
|
+
stop(previous, "reset");
|
|
28116
|
+
}
|
|
28117
|
+
entries.set(entry.key, entry);
|
|
28118
|
+
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
28119
|
+
preemptDeltas();
|
|
28120
|
+
dispatch();
|
|
28121
|
+
});
|
|
28122
|
+
}
|
|
27110
28123
|
return () => {
|
|
27111
28124
|
disposed = true;
|
|
27112
28125
|
removeResetObserver();
|
|
27113
28126
|
removeLifecycleObserver();
|
|
27114
28127
|
for (const entry of [...entries.values()]) {
|
|
27115
|
-
|
|
28128
|
+
clearEntry(entry);
|
|
27116
28129
|
if (entry.running) releaseHold(entry);
|
|
27117
28130
|
stop(entry, "disposed");
|
|
28131
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
27118
28132
|
}
|
|
27119
28133
|
entries.clear();
|
|
27120
28134
|
};
|
|
@@ -27153,20 +28167,19 @@ export {
|
|
|
27153
28167
|
MfuReassemblyError,
|
|
27154
28168
|
MmtpContainerParser,
|
|
27155
28169
|
MmtpDecodePipeline,
|
|
28170
|
+
MmtpFecSession,
|
|
27156
28171
|
MmtpRouter,
|
|
27157
28172
|
MmtpToCmaf,
|
|
27158
28173
|
MulticastContainerContractError,
|
|
27159
28174
|
MulticastInputError,
|
|
27160
28175
|
MulticastManager,
|
|
27161
28176
|
MulticastTransport,
|
|
27162
|
-
NoneCodec,
|
|
27163
28177
|
REPAIR_LIFECYCLE_EVENT_TYPE,
|
|
27164
28178
|
REPAIR_LIFECYCLE_LOG_PREFIX,
|
|
27165
28179
|
REPAIR_PRIORITY_MAX,
|
|
27166
28180
|
REPAIR_PRIORITY_MIN,
|
|
27167
28181
|
REPAIR_TRACK_GEOMETRY_KEYS,
|
|
27168
28182
|
REPAIR_TRACK_ONLY_KEYS,
|
|
27169
|
-
ReedSolomonCodec,
|
|
27170
28183
|
RepairContractError,
|
|
27171
28184
|
SOURCE_MEDIA_PRIORITY_MAX,
|
|
27172
28185
|
SampleCombineError,
|
|
@@ -27187,6 +28200,7 @@ export {
|
|
|
27187
28200
|
buildHevcVideoInitSegment,
|
|
27188
28201
|
buildVideoInitSegment,
|
|
27189
28202
|
catalogAmtNetworkSource,
|
|
28203
|
+
catalogAtsc3NetworkSource,
|
|
27190
28204
|
catalogDeclaresFec,
|
|
27191
28205
|
catalogFecAvailable,
|
|
27192
28206
|
catalogFecDeclaresUnconfigurableInstance,
|
|
@@ -27203,7 +28217,6 @@ export {
|
|
|
27203
28217
|
computeFecDeliveryWindowMediaUnits,
|
|
27204
28218
|
computeFecDeliveryWindowMs,
|
|
27205
28219
|
computeFecLossWindowMs,
|
|
27206
|
-
createFecCodec,
|
|
27207
28220
|
createFragment,
|
|
27208
28221
|
createWasmMmtpContainerParser,
|
|
27209
28222
|
datagramMfuReassembly,
|
|
@@ -27231,6 +28244,7 @@ export {
|
|
|
27231
28244
|
extractHevcCodecDescription,
|
|
27232
28245
|
extractHevcParameterSets,
|
|
27233
28246
|
extractSpsPpsFromAvcC,
|
|
28247
|
+
fecAlgorithmUnimplemented,
|
|
27234
28248
|
findAnnexBStartCode,
|
|
27235
28249
|
forwardRepairLifecycleEvents,
|
|
27236
28250
|
frameSamplesFromInit,
|