@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbdfdbf39ded
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 +36 -20
- 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 +1721 -705
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +72 -34
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +309 -204
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +15 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +137 -50
- package/dist/catalog-fec-params.js.map +4 -4
- package/dist/catalog-network-source.d.ts +24 -2
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +24 -1
- package/dist/catalog-network-source.js.map +3 -3
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/delivery-catalog.js +100 -230
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +64 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +275 -62
- package/dist/fec-manager.js.map +4 -4
- package/dist/fec-state.d.ts +5 -3
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +34 -12
- package/dist/fec-state.js.map +4 -4
- package/dist/fec-worker-setup.d.ts +2 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -3
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +29 -0
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +100 -17
- package/dist/iso-block-locator.js.map +4 -4
- 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 +24 -13
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +96 -22
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +1138 -325
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +96 -22
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- 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 +31 -5
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +168 -22
- package/dist/mmtp-router.js.map +3 -3
- 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 +28 -6
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +293 -28
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +89 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +730 -356
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +111 -235
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +24 -13
- package/dist/multicast-unwrap.js.map +3 -3
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1087 -309
- 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 +159 -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 +22 -2
- package/dist/repair-layers.js.map +3 -3
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +6 -3
- package/dist/signaling.js.map +3 -3
- 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 +24 -13
- package/dist/timestamp-codec.js.map +3 -3
- package/dist/wasm-mfu-reassembler.js +3 -0
- package/dist/wasm-mfu-reassembler.js.map +3 -3
- package/dist/wasm-mmtp-container-parser.js +96 -22
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/package.json +6 -9
- package/schemas/catalog.schema.json +124 -37
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +163 -61
- package/src/catalog-fec-params.ts +66 -20
- package/src/catalog-network-source.ts +45 -2
- package/src/catalog-validator.ts +4 -11
- package/src/fec-manager.ts +239 -63
- package/src/fec-state.ts +14 -12
- package/src/fec-worker-setup.ts +20 -2
- package/src/index.ts +29 -10
- package/src/iso-block-locator.ts +97 -6
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +533 -0
- package/src/mmtp-router.ts +133 -5
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +119 -61
- package/src/multicast-manager.ts +258 -21
- package/src/multicast-transport.ts +17 -3
- 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/sample-combiner.ts +15 -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 +65 -4
- 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-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 +2 -2
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +30 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -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
|
@@ -655,26 +655,30 @@ function isEmptyOrExactLegacyTrailer(payload, start, end) {
|
|
|
655
655
|
const authLength = view2.getUint16(2, false);
|
|
656
656
|
return start + LEGACY_TRAILER_HEADER_SIZE + authLength === end;
|
|
657
657
|
}
|
|
658
|
-
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options) {
|
|
658
|
+
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options, rapFlag = false) {
|
|
659
659
|
if (declaredEnd > payload.length)
|
|
660
660
|
return null;
|
|
661
661
|
if (options?.skipFecId) {
|
|
662
|
-
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false } : null;
|
|
662
|
+
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false, hasOverlayFecId: false } : null;
|
|
663
663
|
}
|
|
664
|
+
const overlay = options?.overlayDeclared === true && rapFlag;
|
|
664
665
|
if (fecType === 1) {
|
|
665
|
-
const fecStart = payload.length -
|
|
666
|
+
const fecStart = payload.length - sourceFecTrailerSize(overlay);
|
|
666
667
|
if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
|
|
667
668
|
return null;
|
|
668
669
|
}
|
|
669
|
-
return { hasFecId: true };
|
|
670
|
+
return { hasFecId: true, hasOverlayFecId: overlay };
|
|
670
671
|
}
|
|
671
|
-
if (fecType !== 0)
|
|
672
|
+
if (fecType !== 0 || overlay)
|
|
672
673
|
return null;
|
|
673
674
|
if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
|
|
674
|
-
return { hasFecId: false };
|
|
675
|
+
return { hasFecId: false, hasOverlayFecId: false };
|
|
675
676
|
}
|
|
676
677
|
return null;
|
|
677
678
|
}
|
|
679
|
+
function sourceFecTrailerSize(overlay) {
|
|
680
|
+
return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE;
|
|
681
|
+
}
|
|
678
682
|
function extractNALUnit(mmtpPacket) {
|
|
679
683
|
const extraction = extractMFUPayload(mmtpPacket);
|
|
680
684
|
if (!extraction)
|
|
@@ -733,15 +737,16 @@ function planMfuExtraction(mmtpPacket, options, parsedHeader) {
|
|
|
733
737
|
if ("rejection" in layoutResult)
|
|
734
738
|
return layoutResult;
|
|
735
739
|
const { layout } = layoutResult;
|
|
736
|
-
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options);
|
|
740
|
+
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options, header.rapFlag);
|
|
737
741
|
if (!trailerLayout) {
|
|
738
742
|
if (!options?.skipFecId && header.fecType === 1) {
|
|
739
743
|
const observed = payload.length - layout.dataEnd;
|
|
740
|
-
|
|
744
|
+
const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag);
|
|
745
|
+
if (observed !== expected) {
|
|
741
746
|
return {
|
|
742
747
|
rejection: {
|
|
743
748
|
gate: "source-fec-payload-id-width-mismatch",
|
|
744
|
-
detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${
|
|
749
|
+
detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${expected} (payload=${payload.length}, declaredEnd=${layout.dataEnd})`
|
|
745
750
|
}
|
|
746
751
|
};
|
|
747
752
|
}
|
|
@@ -771,10 +776,13 @@ function extractPlannedMfu(mmtpPacket, result) {
|
|
|
771
776
|
const mfuDuHeader = mfuDuHeaderPresent && mpu.timedFlag === 1 ? parseTimedMfuDuHeader(payload, MPU_HEADER_SIZE) : null;
|
|
772
777
|
const itemId = mfuDuHeaderPresent && mpu.timedFlag === 0 ? new DataView(payload.buffer, payload.byteOffset + MPU_HEADER_SIZE, 4).getUint32(0, false) : null;
|
|
773
778
|
const data = payload.subarray(mfuOffset, dataEnd);
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
779
|
+
const trailerStart = mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId);
|
|
780
|
+
const ssIdAt = (offset) => ({
|
|
781
|
+
ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false)
|
|
782
|
+
});
|
|
783
|
+
const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null;
|
|
784
|
+
const overlayFecPayloadId = trailerLayout.hasOverlayFecId ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE) : null;
|
|
785
|
+
return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId };
|
|
778
786
|
}
|
|
779
787
|
function extractTimestamp(mmtpPacket) {
|
|
780
788
|
const { header } = unwrapMMTP(mmtpPacket);
|
|
@@ -949,6 +957,327 @@ function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
|
949
957
|
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
950
958
|
}
|
|
951
959
|
|
|
960
|
+
// ../mmt-base/dist/catalog-fec-source.js
|
|
961
|
+
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
962
|
+
function recordOf(value) {
|
|
963
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
964
|
+
}
|
|
965
|
+
function locateCatalogFecSource(catalog, source, roles = ALL_ROLES) {
|
|
966
|
+
const root = recordOf(catalog);
|
|
967
|
+
if (root === void 0)
|
|
968
|
+
return void 0;
|
|
969
|
+
for (const role of roles) {
|
|
970
|
+
const renditions = recordOf(recordOf(root[role])?.["renditions"]);
|
|
971
|
+
if (renditions === void 0 || !Object.hasOwn(renditions, source))
|
|
972
|
+
continue;
|
|
973
|
+
const entry2 = recordOf(renditions[source]);
|
|
974
|
+
if (entry2 === void 0)
|
|
975
|
+
continue;
|
|
976
|
+
return Object.freeze({
|
|
977
|
+
dialect: "hang",
|
|
978
|
+
role,
|
|
979
|
+
entry: entry2,
|
|
980
|
+
fec: entry2["fec"],
|
|
981
|
+
fecPath: `$.${role}.renditions[${JSON.stringify(source)}].fec`
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
const tracks = root["tracks"];
|
|
985
|
+
if (!Array.isArray(tracks))
|
|
986
|
+
return void 0;
|
|
987
|
+
const index = tracks.findIndex((track) => recordOf(track)?.["name"] === source);
|
|
988
|
+
if (index < 0)
|
|
989
|
+
return void 0;
|
|
990
|
+
const entry = recordOf(tracks[index]) ?? {};
|
|
991
|
+
return Object.freeze({
|
|
992
|
+
dialect: "msf",
|
|
993
|
+
index,
|
|
994
|
+
entry,
|
|
995
|
+
fec: entry["fec"],
|
|
996
|
+
fecPath: `$.tracks[${index}].fec`
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
function isoBlockSpanUsable(fec) {
|
|
1000
|
+
const block = recordOf(fec);
|
|
1001
|
+
if (block === void 0 || block["blockProfile"] !== "iso-ssbg1-v1")
|
|
1002
|
+
return true;
|
|
1003
|
+
const ms = block["interleaveDepthMs"];
|
|
1004
|
+
return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
|
|
1005
|
+
}
|
|
1006
|
+
function catalogFecAvailable(fec) {
|
|
1007
|
+
const block = recordOf(fec);
|
|
1008
|
+
if (block === void 0)
|
|
1009
|
+
return true;
|
|
1010
|
+
if (fecAlgorithmUnimplemented(block["algorithm"]))
|
|
1011
|
+
return false;
|
|
1012
|
+
const declaresFecInstance = block["algorithm"] !== "none";
|
|
1013
|
+
const profile = block["blockProfile"];
|
|
1014
|
+
const profileOk = isFecBlockProfile(profile) || profile === void 0 && !declaresFecInstance;
|
|
1015
|
+
return profileOk && (!declaresFecInstance || isoBlockSpanUsable(block));
|
|
1016
|
+
}
|
|
1017
|
+
function fecAlgorithmUnimplemented(algorithm) {
|
|
1018
|
+
return typeof algorithm === "string" && algorithm !== "none" && algorithm !== "raptorq" && algorithm !== "reed-solomon";
|
|
1019
|
+
}
|
|
1020
|
+
function isPositiveSafeInteger(value) {
|
|
1021
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
1022
|
+
}
|
|
1023
|
+
var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
|
|
1024
|
+
function catalogFecDeclaresUnconfigurableInstance(fec) {
|
|
1025
|
+
const block = recordOf(fec);
|
|
1026
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"]))
|
|
1027
|
+
return false;
|
|
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;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
952
1281
|
// src/mfu-reassembler.ts
|
|
953
1282
|
function fragmentProvenance(fragment) {
|
|
954
1283
|
if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
|
|
@@ -3821,8 +4150,14 @@ var SampleCombiner = class {
|
|
|
3821
4150
|
/**
|
|
3822
4151
|
* Add one reassembled data unit. Returns the combined sample once every
|
|
3823
4152
|
* constituent data unit has arrived and totals the authored size.
|
|
4153
|
+
*
|
|
4154
|
+
* `sampleSize` is the authored size the host resolves for the sample as the
|
|
4155
|
+
* data unit completes. It stands in only when no size was registered, which
|
|
4156
|
+
* happens when the data unit's FI=0/FI=1 reached the reassembler without the
|
|
4157
|
+
* host's own FT=2 parse: an FEC-recovered first fragment completed by source
|
|
4158
|
+
* fragments, or one decoded before its source copy arrived.
|
|
3824
4159
|
*/
|
|
3825
|
-
addMfu(mfu) {
|
|
4160
|
+
addMfu(mfu, sampleSize) {
|
|
3826
4161
|
if (mfu.movieFragmentSequenceNumber === void 0 || mfu.sampleNumber === void 0) {
|
|
3827
4162
|
this.#stats.passthroughSamples++;
|
|
3828
4163
|
return fromPassthrough(mfu);
|
|
@@ -3838,7 +4173,7 @@ var SampleCombiner = class {
|
|
|
3838
4173
|
return null;
|
|
3839
4174
|
}
|
|
3840
4175
|
const dataLen = mfu.data.byteLength;
|
|
3841
|
-
const authoredSize = this.#authoredSizes.get(key);
|
|
4176
|
+
const authoredSize = this.#authoredSizes.get(key) ?? sampleSize;
|
|
3842
4177
|
if (offset === 0 && !this.#pending.has(key)) {
|
|
3843
4178
|
const passesThrough = authoredSize === void 0 ? !this.#requireAuthoredSize : dataLen === authoredSize;
|
|
3844
4179
|
if (passesThrough) {
|
|
@@ -4132,6 +4467,12 @@ if (void 0) {
|
|
|
4132
4467
|
const out = c.addMfu(mfu(1, 9, 17, 5, [6, 7, 8, 9, 10], 1001n, false));
|
|
4133
4468
|
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
|
|
4134
4469
|
});
|
|
4470
|
+
test("a size handed with the data unit completes a sample no head registered", () => {
|
|
4471
|
+
const c = combiner({ requireAuthoredSize: true });
|
|
4472
|
+
const out = c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5);
|
|
4473
|
+
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
|
|
4474
|
+
expect(c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5)).toBeNull();
|
|
4475
|
+
});
|
|
4135
4476
|
test("duplicate offset is rejected", () => {
|
|
4136
4477
|
const c = combiner();
|
|
4137
4478
|
c.registerAuthoredSize(void 0, 1, 9, 17, 10);
|
|
@@ -5938,197 +6279,6 @@ if (void 0) {
|
|
|
5938
6279
|
});
|
|
5939
6280
|
}
|
|
5940
6281
|
|
|
5941
|
-
// src/multicast-auth-catalog.ts
|
|
5942
|
-
var RAW_ED25519_KEY_LENGTH = 32;
|
|
5943
|
-
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
5944
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
5945
|
-
function encodeBase64Url(bytes) {
|
|
5946
|
-
let output = "";
|
|
5947
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
5948
|
-
const b0 = bytes[i];
|
|
5949
|
-
const b1 = bytes[i + 1];
|
|
5950
|
-
const b2 = bytes[i + 2];
|
|
5951
|
-
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
5952
|
-
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
5953
|
-
if (b1 === void 0) break;
|
|
5954
|
-
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
5955
|
-
if (b2 === void 0) break;
|
|
5956
|
-
output += BASE64URL_ALPHABET[b2 & 63];
|
|
5957
|
-
}
|
|
5958
|
-
return output;
|
|
5959
|
-
}
|
|
5960
|
-
var BASE64URL_DECODE_TABLE = (() => {
|
|
5961
|
-
const table = new Int8Array(128).fill(-1);
|
|
5962
|
-
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
5963
|
-
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
5964
|
-
}
|
|
5965
|
-
return table;
|
|
5966
|
-
})();
|
|
5967
|
-
function decodeBase64Url(text) {
|
|
5968
|
-
if (text.length % 4 === 1) {
|
|
5969
|
-
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
|
|
5970
|
-
}
|
|
5971
|
-
const bytes = [];
|
|
5972
|
-
let buffer = 0;
|
|
5973
|
-
let bits = 0;
|
|
5974
|
-
for (let i = 0; i < text.length; i++) {
|
|
5975
|
-
const code = text.charCodeAt(i);
|
|
5976
|
-
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
5977
|
-
if (value === void 0 || value < 0) {
|
|
5978
|
-
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
|
|
5979
|
-
}
|
|
5980
|
-
buffer = buffer << 6 | value;
|
|
5981
|
-
bits += 6;
|
|
5982
|
-
if (bits >= 8) {
|
|
5983
|
-
bits -= 8;
|
|
5984
|
-
bytes.push(buffer >> bits & 255);
|
|
5985
|
-
}
|
|
5986
|
-
}
|
|
5987
|
-
const decoded = Uint8Array.from(bytes);
|
|
5988
|
-
if (encodeBase64Url(decoded) !== text) {
|
|
5989
|
-
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
|
|
5990
|
-
}
|
|
5991
|
-
return decoded;
|
|
5992
|
-
}
|
|
5993
|
-
function decodeAuthScope(authScope) {
|
|
5994
|
-
const bytes = decodeBase64Url(authScope);
|
|
5995
|
-
if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
|
|
5996
|
-
throw new Error(
|
|
5997
|
-
`[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
5998
|
-
);
|
|
5999
|
-
}
|
|
6000
|
-
return bytes;
|
|
6001
|
-
}
|
|
6002
|
-
function decodeEd25519PublicKey(publicKey) {
|
|
6003
|
-
const bytes = decodeBase64Url(publicKey);
|
|
6004
|
-
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
6005
|
-
throw new Error(
|
|
6006
|
-
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
6007
|
-
);
|
|
6008
|
-
}
|
|
6009
|
-
return bytes;
|
|
6010
|
-
}
|
|
6011
|
-
function isNonEmptyString(value) {
|
|
6012
|
-
return typeof value === "string" && value.length > 0;
|
|
6013
|
-
}
|
|
6014
|
-
function isValidAuthScopeField(value) {
|
|
6015
|
-
if (!isNonEmptyString(value)) return false;
|
|
6016
|
-
try {
|
|
6017
|
-
decodeAuthScope(value);
|
|
6018
|
-
return true;
|
|
6019
|
-
} catch {
|
|
6020
|
-
return false;
|
|
6021
|
-
}
|
|
6022
|
-
}
|
|
6023
|
-
function isValidPublicKeyField(value) {
|
|
6024
|
-
if (!isNonEmptyString(value)) return false;
|
|
6025
|
-
try {
|
|
6026
|
-
decodeEd25519PublicKey(value);
|
|
6027
|
-
return true;
|
|
6028
|
-
} catch {
|
|
6029
|
-
return false;
|
|
6030
|
-
}
|
|
6031
|
-
}
|
|
6032
|
-
function hasOnlyKeys(object2, allowed) {
|
|
6033
|
-
const allowedKeys = new Set(allowed);
|
|
6034
|
-
return Object.keys(object2).every((key) => allowedKeys.has(key));
|
|
6035
|
-
}
|
|
6036
|
-
function isMulticastAuthTrackConfig(obj) {
|
|
6037
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
6038
|
-
const o = obj;
|
|
6039
|
-
return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
|
|
6040
|
-
}
|
|
6041
|
-
var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
|
|
6042
|
-
var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
|
|
6043
|
-
function hasUniqueMulticastAuthTrackBindings(tracks) {
|
|
6044
|
-
const bindings = tracks.flatMap((track) => {
|
|
6045
|
-
if (typeof track !== "object" || track === null) return [];
|
|
6046
|
-
const value = track;
|
|
6047
|
-
if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
|
|
6048
|
-
return [];
|
|
6049
|
-
}
|
|
6050
|
-
return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
|
|
6051
|
-
});
|
|
6052
|
-
return new Set(bindings).size === bindings.length;
|
|
6053
|
-
}
|
|
6054
|
-
function isMulticastAuthConfig(obj) {
|
|
6055
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
6056
|
-
const o = obj;
|
|
6057
|
-
if (o["scheme"] !== "bc-provenance") return false;
|
|
6058
|
-
if (o["hash"] !== "blake3") return false;
|
|
6059
|
-
if (o["sig"] !== "ed25519") return false;
|
|
6060
|
-
if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
|
|
6061
|
-
if (!isValidPublicKeyField(o["publicKey"])) return false;
|
|
6062
|
-
if (!isNonEmptyString(o["keyId"])) return false;
|
|
6063
|
-
if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
|
|
6064
|
-
if (o["previousKey"] === o["publicKey"]) return false;
|
|
6065
|
-
if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
|
|
6066
|
-
if (o["enforcement"] !== void 0) {
|
|
6067
|
-
if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
|
|
6068
|
-
}
|
|
6069
|
-
if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
|
|
6070
|
-
const tracks = o["tracks"];
|
|
6071
|
-
if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
|
|
6072
|
-
const typedTracks = tracks;
|
|
6073
|
-
const scopes = typedTracks.map((t) => t.authScope);
|
|
6074
|
-
if (new Set(scopes).size !== scopes.length) return false;
|
|
6075
|
-
if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
|
|
6076
|
-
const manifestTracks = typedTracks.map((t) => t.manifestTrack);
|
|
6077
|
-
if (new Set(manifestTracks).size !== manifestTracks.length) return false;
|
|
6078
|
-
return true;
|
|
6079
|
-
}
|
|
6080
|
-
function resolveMulticastAuthMode(playerMode, auth) {
|
|
6081
|
-
if (playerMode !== void 0) return playerMode;
|
|
6082
|
-
if (auth === void 0) return "off";
|
|
6083
|
-
return auth.enforcement ?? "shadow";
|
|
6084
|
-
}
|
|
6085
|
-
function resolveMulticastAuthCatalog(catalog, playerMode) {
|
|
6086
|
-
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
6087
|
-
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
6088
|
-
}
|
|
6089
|
-
const root = catalog;
|
|
6090
|
-
const rawAuth = root["multicast.auth"];
|
|
6091
|
-
if (rawAuth === void 0) {
|
|
6092
|
-
if (playerMode === "enforce") {
|
|
6093
|
-
throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
|
|
6094
|
-
}
|
|
6095
|
-
return void 0;
|
|
6096
|
-
}
|
|
6097
|
-
if (!isMulticastAuthConfig(rawAuth)) {
|
|
6098
|
-
throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
|
|
6099
|
-
}
|
|
6100
|
-
const rawTracks = root["tracks"];
|
|
6101
|
-
if (!Array.isArray(rawTracks)) {
|
|
6102
|
-
throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
|
|
6103
|
-
}
|
|
6104
|
-
const catalogTrackNames = new Set(
|
|
6105
|
-
rawTracks.flatMap(
|
|
6106
|
-
(track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
|
|
6107
|
-
)
|
|
6108
|
-
);
|
|
6109
|
-
for (const track of rawAuth.tracks) {
|
|
6110
|
-
if (!catalogTrackNames.has(track.mediaTrack)) {
|
|
6111
|
-
throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
|
|
6112
|
-
}
|
|
6113
|
-
if (!catalogTrackNames.has(track.manifestTrack)) {
|
|
6114
|
-
throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
|
|
6115
|
-
}
|
|
6116
|
-
}
|
|
6117
|
-
return {
|
|
6118
|
-
keyId: rawAuth.keyId,
|
|
6119
|
-
acceptedPublicKeys: [
|
|
6120
|
-
decodeEd25519PublicKey(rawAuth.publicKey),
|
|
6121
|
-
...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
|
|
6122
|
-
],
|
|
6123
|
-
mode: resolveMulticastAuthMode(playerMode, rawAuth),
|
|
6124
|
-
compaction: rawAuth.compaction,
|
|
6125
|
-
tracks: rawAuth.tracks.map((track) => ({
|
|
6126
|
-
...track,
|
|
6127
|
-
authScope: decodeAuthScope(track.authScope)
|
|
6128
|
-
}))
|
|
6129
|
-
};
|
|
6130
|
-
}
|
|
6131
|
-
|
|
6132
6282
|
// src/repair-layers.ts
|
|
6133
6283
|
var REPAIR_PRIORITY_MIN = 192;
|
|
6134
6284
|
var REPAIR_PRIORITY_MAX = 255;
|
|
@@ -6136,6 +6286,7 @@ var DEFAULT_REPAIR_PRIORITY = 240;
|
|
|
6136
6286
|
var MAX_RAPTORQ_SOURCE_SYMBOLS = 56403;
|
|
6137
6287
|
var MAX_REPAIR_SYMBOLS = 16777215;
|
|
6138
6288
|
var MAX_ENCODING_SYMBOL_ID = 16777215;
|
|
6289
|
+
var MAX_REED_SOLOMON_BLOCK_SYMBOLS = 255;
|
|
6139
6290
|
var RepairContractError = class extends Error {
|
|
6140
6291
|
constructor(code, path, message) {
|
|
6141
6292
|
super(`[repair-layers:${code}] ${path}: ${message}`);
|
|
@@ -6318,11 +6469,12 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6318
6469
|
if (layered && !positiveInteger(source.sourceSymbols)) {
|
|
6319
6470
|
fail("track_fec", `${source.path}.sourceSymbols`, "layered or overlay repair needs a positive integer sourceSymbols on the source");
|
|
6320
6471
|
}
|
|
6321
|
-
|
|
6472
|
+
const reedSolomon = source.algorithm === "reed-solomon";
|
|
6473
|
+
if (layered && source.algorithm !== "raptorq" && !reedSolomon) {
|
|
6322
6474
|
fail(
|
|
6323
6475
|
"track_fec",
|
|
6324
6476
|
`${source.path}.algorithm`,
|
|
6325
|
-
"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)"
|
|
6326
6478
|
);
|
|
6327
6479
|
}
|
|
6328
6480
|
let layerZeroPriority = DEFAULT_REPAIR_PRIORITY;
|
|
@@ -6381,6 +6533,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6381
6533
|
`overlay sourceSymbols + repairSymbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
6382
6534
|
);
|
|
6383
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
|
+
}
|
|
6384
6543
|
overlays.push({ repairTrackName: d.name, scope: "keyframe", sourceSymbols, repairSymbols, priority: d.priority });
|
|
6385
6544
|
}
|
|
6386
6545
|
let offset = layerZeroSymbols;
|
|
@@ -6425,6 +6584,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
|
|
|
6425
6584
|
`sourceSymbols + total base repair symbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
6426
6585
|
);
|
|
6427
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
|
+
}
|
|
6428
6594
|
return { sourceTrackName: source.name, baseLayers, overlays, totalBaseRepairSymbols };
|
|
6429
6595
|
}
|
|
6430
6596
|
|
|
@@ -6472,7 +6638,7 @@ function isFecCatalogGeometry(obj) {
|
|
|
6472
6638
|
const o = obj;
|
|
6473
6639
|
const algorithm = o["algorithm"];
|
|
6474
6640
|
const symbolSize = o["symbolSize"];
|
|
6475
|
-
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;
|
|
6476
6642
|
}
|
|
6477
6643
|
function isFecCatalogConfig(obj) {
|
|
6478
6644
|
if (!isFecCatalogGeometry(obj)) return false;
|
|
@@ -6487,8 +6653,7 @@ function isMulticastTrackObject(obj) {
|
|
|
6487
6653
|
function isMulticastEndpoint(obj) {
|
|
6488
6654
|
if (typeof obj !== "object" || obj === null) return false;
|
|
6489
6655
|
const o = obj;
|
|
6490
|
-
|
|
6491
|
-
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));
|
|
6492
6657
|
}
|
|
6493
6658
|
function isMulticastCatalogConfig(obj) {
|
|
6494
6659
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -6592,7 +6757,7 @@ var CmsfCatalogValidationError = class extends Error {
|
|
|
6592
6757
|
function catalogError(code, path, message) {
|
|
6593
6758
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
6594
6759
|
}
|
|
6595
|
-
function validateCmsfMmtpCatalog(value) {
|
|
6760
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
6596
6761
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
6597
6762
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
6598
6763
|
}
|
|
@@ -6613,6 +6778,22 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6613
6778
|
"commonTrackFields is retired; every track carries its own fields"
|
|
6614
6779
|
);
|
|
6615
6780
|
}
|
|
6781
|
+
const initDataList = catalog["initDataList"];
|
|
6782
|
+
if (initDataList !== void 0) {
|
|
6783
|
+
if (!Array.isArray(initDataList)) {
|
|
6784
|
+
catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
|
|
6785
|
+
}
|
|
6786
|
+
initDataList.forEach((entry, i) => {
|
|
6787
|
+
const e = entry;
|
|
6788
|
+
const entryPath = `$.initDataList[${i}]`;
|
|
6789
|
+
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) {
|
|
6790
|
+
catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
|
|
6791
|
+
}
|
|
6792
|
+
if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
|
|
6793
|
+
catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
|
|
6794
|
+
}
|
|
6795
|
+
});
|
|
6796
|
+
}
|
|
6616
6797
|
const tracks = catalog["tracks"];
|
|
6617
6798
|
const trackRecords = [];
|
|
6618
6799
|
const positiveInteger3 = (input) => Number.isSafeInteger(input) && input > 0;
|
|
@@ -6664,6 +6845,14 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6664
6845
|
if (keyframeIntervalMs !== void 0 && !positiveNumber2(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger3(keyframeIntervalTicks)) {
|
|
6665
6846
|
catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
|
|
6666
6847
|
}
|
|
6848
|
+
const anchor = track["presentationAnchorTicks"];
|
|
6849
|
+
if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
|
|
6850
|
+
catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
|
|
6851
|
+
}
|
|
6852
|
+
const initRef = track["initRef"];
|
|
6853
|
+
if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
|
|
6854
|
+
catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
|
|
6855
|
+
}
|
|
6667
6856
|
if (packaging === "fec-repair") {
|
|
6668
6857
|
rejectRepairTrackGeometry(path, track, catalogError);
|
|
6669
6858
|
validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
|
|
@@ -6671,9 +6860,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6671
6860
|
rejectRepairFieldsOnMediaTrack(path, track, catalogError);
|
|
6672
6861
|
}
|
|
6673
6862
|
if (packaging === "mmtp") {
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
|
|
6863
|
+
if (track["mmtpMode"] !== "mfu") {
|
|
6864
|
+
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
|
|
6677
6865
|
}
|
|
6678
6866
|
if (!positiveInteger3(timescale)) {
|
|
6679
6867
|
catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
|
|
@@ -6696,8 +6884,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6696
6884
|
}
|
|
6697
6885
|
const config = fec;
|
|
6698
6886
|
const algorithm = config["algorithm"];
|
|
6699
|
-
if (
|
|
6700
|
-
catalogError("track_fec", `${path}.fec.algorithm`, "
|
|
6887
|
+
if (typeof algorithm !== "string" || algorithm.length === 0) {
|
|
6888
|
+
catalogError("track_fec", `${path}.fec.algorithm`, "must be a non-empty string");
|
|
6701
6889
|
}
|
|
6702
6890
|
if ("interleaveDepth" in config || "interleaveMs" in config) {
|
|
6703
6891
|
catalogError("track_fec", `${path}.fec`, "interleaveDepthMs is the only supported interleave field");
|
|
@@ -6726,6 +6914,9 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6726
6914
|
}
|
|
6727
6915
|
}
|
|
6728
6916
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
6917
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
6918
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
6919
|
+
}
|
|
6729
6920
|
}
|
|
6730
6921
|
}
|
|
6731
6922
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -6775,11 +6966,21 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6775
6966
|
const timescale = BigInt(track["timescale"]);
|
|
6776
6967
|
const durationTicks = track["groupDurationTicks"];
|
|
6777
6968
|
const ticks = durationTicks !== void 0 ? BigInt(durationTicks) : BigInt(track["groupDurationMs"]) * timescale / 1000n;
|
|
6778
|
-
const
|
|
6779
|
-
|
|
6780
|
-
|
|
6969
|
+
const framerate = track["framerate"];
|
|
6970
|
+
const intraOnly = positiveNumber2(framerate) && Math.abs(Number(ticks) * framerate - Number(timescale)) <= Number(timescale) * 1e-3;
|
|
6971
|
+
const members = switchingSets.get(altGroup) ?? [];
|
|
6972
|
+
members.push({ index, name: track["name"], ticks, timescale, intraOnly });
|
|
6973
|
+
switchingSets.set(altGroup, members);
|
|
6974
|
+
}
|
|
6975
|
+
for (const [altGroup, members] of switchingSets) {
|
|
6976
|
+
const anchor = members.find((member) => !member.intraOnly) ?? members[0];
|
|
6977
|
+
for (const member of members) {
|
|
6978
|
+
if (member === anchor || member.ticks * anchor.timescale === anchor.ticks * member.timescale) continue;
|
|
6979
|
+
const nests = member.intraOnly && !anchor.intraOnly && anchor.ticks * member.timescale % (member.ticks * anchor.timescale) === 0n;
|
|
6980
|
+
if (!nests) {
|
|
6981
|
+
catalogError("track_switching_set", `$.tracks[${member.index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
|
|
6982
|
+
}
|
|
6781
6983
|
}
|
|
6782
|
-
if (!anchor) switchingSets.set(altGroup, { name: track["name"], ticks, timescale });
|
|
6783
6984
|
}
|
|
6784
6985
|
const multicast = catalog["multicast"];
|
|
6785
6986
|
if (typeof multicast === "object" && multicast !== null && !Array.isArray(multicast)) {
|
|
@@ -6827,15 +7028,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6827
7028
|
}
|
|
6828
7029
|
}
|
|
6829
7030
|
}
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
} catch (error) {
|
|
6833
|
-
catalogError(
|
|
6834
|
-
"multicast_auth",
|
|
6835
|
-
"$.multicast.auth",
|
|
6836
|
-
error instanceof Error ? error.message : "invalid multicast.auth v2 block"
|
|
6837
|
-
);
|
|
6838
|
-
}
|
|
7031
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
7032
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
6839
7033
|
validateArchive(catalog);
|
|
6840
7034
|
return catalog;
|
|
6841
7035
|
}
|
|
@@ -6861,7 +7055,7 @@ function resolveGroupDurationTicks(timing, timescale) {
|
|
|
6861
7055
|
const product = timing.groupDurationMs * timescale;
|
|
6862
7056
|
if (product % 1e3 !== 0) {
|
|
6863
7057
|
throw new Error(
|
|
6864
|
-
`[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-
|
|
7058
|
+
`[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)`
|
|
6865
7059
|
);
|
|
6866
7060
|
}
|
|
6867
7061
|
return product / 1e3;
|
|
@@ -6882,186 +7076,6 @@ function validateSwitchingSetTiming(tracks) {
|
|
|
6882
7076
|
return { ok: false, expectedTicks, mismatches };
|
|
6883
7077
|
}
|
|
6884
7078
|
|
|
6885
|
-
// node_modules/@blockcast/mmt-transport/dist/types.js
|
|
6886
|
-
var MoqFecAlgorithm;
|
|
6887
|
-
(function(MoqFecAlgorithm2) {
|
|
6888
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["None"] = 0] = "None";
|
|
6889
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["Xor"] = 1] = "Xor";
|
|
6890
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
|
|
6891
|
-
})(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
|
|
6892
|
-
|
|
6893
|
-
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
6894
|
-
var MPU_HEADER_SIZE2 = 8;
|
|
6895
|
-
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
6896
|
-
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
6897
|
-
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
6898
|
-
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
6899
|
-
|
|
6900
|
-
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
6901
|
-
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
6902
|
-
|
|
6903
|
-
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
6904
|
-
var NTP_SHORT_BITS2 = 32;
|
|
6905
|
-
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
6906
|
-
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
6907
|
-
function isNtpShort(value) {
|
|
6908
|
-
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
6909
|
-
}
|
|
6910
|
-
function compareNtpShort(a, b) {
|
|
6911
|
-
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
6912
|
-
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
6913
|
-
}
|
|
6914
|
-
if (a === b)
|
|
6915
|
-
return "equal";
|
|
6916
|
-
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
6917
|
-
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
6918
|
-
return "after";
|
|
6919
|
-
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
6920
|
-
return "before";
|
|
6921
|
-
return "unordered";
|
|
6922
|
-
}
|
|
6923
|
-
|
|
6924
|
-
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
6925
|
-
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
6926
|
-
"iso-ssbg1-v1"
|
|
6927
|
-
]);
|
|
6928
|
-
|
|
6929
|
-
// node_modules/@blockcast/mmt-transport/dist/driad-discovery.js
|
|
6930
|
-
var DRIADDiscovery = class {
|
|
6931
|
-
cache = /* @__PURE__ */ new Map();
|
|
6932
|
-
cacheExpiry = 3e5;
|
|
6933
|
-
// 5 minutes
|
|
6934
|
-
/**
|
|
6935
|
-
* Discover AMT relays for a multicast source address (RFC 8777)
|
|
6936
|
-
*
|
|
6937
|
-
* @param source - The multicast source IP address (NOT the group!)
|
|
6938
|
-
* @returns Array of discovered AMT relays that can tunnel traffic from this source
|
|
6939
|
-
*/
|
|
6940
|
-
async discoverRelays(source) {
|
|
6941
|
-
const cached = this.cache.get(source);
|
|
6942
|
-
if (cached) {
|
|
6943
|
-
return cached;
|
|
6944
|
-
}
|
|
6945
|
-
try {
|
|
6946
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
6947
|
-
const queryDomain = `${reversedSource}.amt.in-addr.arpa`;
|
|
6948
|
-
console.log(`[DRIAD] Discovering relays for source ${source} via ${queryDomain}`);
|
|
6949
|
-
const relays = await this.queryDRIADProxy(source);
|
|
6950
|
-
if (relays.length > 0) {
|
|
6951
|
-
this.cache.set(source, relays);
|
|
6952
|
-
setTimeout(() => this.cache.delete(source), this.cacheExpiry);
|
|
6953
|
-
}
|
|
6954
|
-
return relays;
|
|
6955
|
-
} catch (error) {
|
|
6956
|
-
console.warn(`[DRIAD] Discovery failed for source ${source}:`, error);
|
|
6957
|
-
return [];
|
|
6958
|
-
}
|
|
6959
|
-
}
|
|
6960
|
-
/**
|
|
6961
|
-
* Query DRIAD proxy service (browser-compatible)
|
|
6962
|
-
*/
|
|
6963
|
-
async queryDRIADProxy(source) {
|
|
6964
|
-
const proxyEndpoints = [
|
|
6965
|
-
"https://driad.amt.net/api/v1/relays",
|
|
6966
|
-
"https://multicast-gateway.cloudflare.com/driad"
|
|
6967
|
-
];
|
|
6968
|
-
for (const endpoint of proxyEndpoints) {
|
|
6969
|
-
try {
|
|
6970
|
-
const response = await fetch(`${endpoint}?source=${encodeURIComponent(source)}`, {
|
|
6971
|
-
method: "GET",
|
|
6972
|
-
headers: { Accept: "application/json" },
|
|
6973
|
-
signal: AbortSignal.timeout(5e3)
|
|
6974
|
-
});
|
|
6975
|
-
if (response.ok) {
|
|
6976
|
-
const data = await response.json();
|
|
6977
|
-
return data.relays || [];
|
|
6978
|
-
}
|
|
6979
|
-
} catch {
|
|
6980
|
-
}
|
|
6981
|
-
}
|
|
6982
|
-
const dohRelay = await this.queryDNSOverHTTPS(source);
|
|
6983
|
-
if (dohRelay) {
|
|
6984
|
-
return [dohRelay];
|
|
6985
|
-
}
|
|
6986
|
-
return [];
|
|
6987
|
-
}
|
|
6988
|
-
/**
|
|
6989
|
-
* Query DNS-over-HTTPS for DRIAD relay based on source address (RFC 8777)
|
|
6990
|
-
*/
|
|
6991
|
-
async queryDNSOverHTTPS(source) {
|
|
6992
|
-
try {
|
|
6993
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
6994
|
-
const queryName = `${reversedSource}.amt.in-addr.arpa`;
|
|
6995
|
-
const dohUrl = `https://cloudflare-dns.com/dns-query?name=${queryName}&type=A`;
|
|
6996
|
-
const response = await fetch(dohUrl, {
|
|
6997
|
-
headers: { Accept: "application/dns-json" },
|
|
6998
|
-
signal: AbortSignal.timeout(3e3)
|
|
6999
|
-
});
|
|
7000
|
-
if (!response.ok) {
|
|
7001
|
-
return null;
|
|
7002
|
-
}
|
|
7003
|
-
const result = await response.json();
|
|
7004
|
-
if (result.Answer && result.Answer.length > 0) {
|
|
7005
|
-
return {
|
|
7006
|
-
host: result.Answer[0].data,
|
|
7007
|
-
port: DEFAULT_AMT_RELAY_PORT2,
|
|
7008
|
-
priority: 10,
|
|
7009
|
-
weight: 100,
|
|
7010
|
-
asn: 0
|
|
7011
|
-
};
|
|
7012
|
-
}
|
|
7013
|
-
return null;
|
|
7014
|
-
} catch (error) {
|
|
7015
|
-
console.warn("[DRIAD] DNS-over-HTTPS query failed:", error);
|
|
7016
|
-
return null;
|
|
7017
|
-
}
|
|
7018
|
-
}
|
|
7019
|
-
/**
|
|
7020
|
-
* Select best relay based on RTT measurements
|
|
7021
|
-
*/
|
|
7022
|
-
async selectBestRelay(relays) {
|
|
7023
|
-
if (relays.length === 0)
|
|
7024
|
-
return null;
|
|
7025
|
-
const measured = await Promise.all(relays.map(async (relay) => {
|
|
7026
|
-
const rtt = await this.measureRTT(relay.host, relay.port);
|
|
7027
|
-
return { ...relay, rtt };
|
|
7028
|
-
}));
|
|
7029
|
-
measured.sort((a, b) => {
|
|
7030
|
-
if (a.priority !== b.priority)
|
|
7031
|
-
return a.priority - b.priority;
|
|
7032
|
-
return (a.rtt || Infinity) - (b.rtt || Infinity);
|
|
7033
|
-
});
|
|
7034
|
-
console.log(`[DRIAD] Selected relay: ${measured[0].host} (RTT: ${measured[0].rtt}ms)`);
|
|
7035
|
-
return measured[0];
|
|
7036
|
-
}
|
|
7037
|
-
async measureRTT(host, _port) {
|
|
7038
|
-
const start = performance.now();
|
|
7039
|
-
try {
|
|
7040
|
-
await fetch(`https://${host}/health`, {
|
|
7041
|
-
method: "HEAD",
|
|
7042
|
-
signal: AbortSignal.timeout(2e3),
|
|
7043
|
-
mode: "no-cors"
|
|
7044
|
-
});
|
|
7045
|
-
return performance.now() - start;
|
|
7046
|
-
} catch {
|
|
7047
|
-
return Infinity;
|
|
7048
|
-
}
|
|
7049
|
-
}
|
|
7050
|
-
/**
|
|
7051
|
-
* Clear the relay cache
|
|
7052
|
-
*/
|
|
7053
|
-
clearCache() {
|
|
7054
|
-
this.cache.clear();
|
|
7055
|
-
}
|
|
7056
|
-
/**
|
|
7057
|
-
* Get cached relays for a source address
|
|
7058
|
-
*/
|
|
7059
|
-
getCached(source) {
|
|
7060
|
-
return this.cache.get(source);
|
|
7061
|
-
}
|
|
7062
|
-
};
|
|
7063
|
-
var driadDiscovery = new DRIADDiscovery();
|
|
7064
|
-
|
|
7065
7079
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
7066
7080
|
function endpointKey(endpoint) {
|
|
7067
7081
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -7192,8 +7206,8 @@ var AdaptiveBitrateController = class {
|
|
|
7192
7206
|
/**
|
|
7193
7207
|
* Update FEC statistics for ABR decisions
|
|
7194
7208
|
*
|
|
7195
|
-
*
|
|
7196
|
-
*
|
|
7209
|
+
* ABR uses the effective loss rate (after FEC recovery) rather than the
|
|
7210
|
+
* raw transport loss rate.
|
|
7197
7211
|
*
|
|
7198
7212
|
* @param stats - FEC statistics from the FEC decoder
|
|
7199
7213
|
*/
|
|
@@ -7269,6 +7283,45 @@ var AdaptiveBitrateController = class {
|
|
|
7269
7283
|
}
|
|
7270
7284
|
};
|
|
7271
7285
|
|
|
7286
|
+
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
7287
|
+
var MPU_HEADER_SIZE2 = 8;
|
|
7288
|
+
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
7289
|
+
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
7290
|
+
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
7291
|
+
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
7292
|
+
|
|
7293
|
+
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
7294
|
+
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
7295
|
+
|
|
7296
|
+
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
7297
|
+
var NTP_SHORT_BITS2 = 32;
|
|
7298
|
+
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
7299
|
+
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
7300
|
+
function isNtpShort(value) {
|
|
7301
|
+
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
7302
|
+
}
|
|
7303
|
+
function compareNtpShort(a, b) {
|
|
7304
|
+
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
7305
|
+
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
7306
|
+
}
|
|
7307
|
+
if (a === b)
|
|
7308
|
+
return "equal";
|
|
7309
|
+
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
7310
|
+
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
7311
|
+
return "after";
|
|
7312
|
+
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
7313
|
+
return "before";
|
|
7314
|
+
return "unordered";
|
|
7315
|
+
}
|
|
7316
|
+
|
|
7317
|
+
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
7318
|
+
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
7319
|
+
"iso-ssbg1-v1"
|
|
7320
|
+
]);
|
|
7321
|
+
|
|
7322
|
+
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
7323
|
+
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
7324
|
+
|
|
7272
7325
|
// node_modules/@blockcast/mmt-transport/dist/multicast-orchestrator.js
|
|
7273
7326
|
var DEFAULT_DWELL_MS = 3e3;
|
|
7274
7327
|
var DEFAULT_JOIN_DEADLINE_MS = 5e3;
|
|
@@ -7506,8 +7559,23 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
7506
7559
|
consume: "bytes",
|
|
7507
7560
|
...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
|
|
7508
7561
|
};
|
|
7562
|
+
if (input.atsc3) {
|
|
7563
|
+
const { frequency, plpId, serviceId } = input.atsc3;
|
|
7564
|
+
if (!Number.isInteger(frequency) || frequency < 1) {
|
|
7565
|
+
throw new TypeError(`ATSC3 tuning requires a positive integer frequency in kHz, got ${String(frequency)}`);
|
|
7566
|
+
}
|
|
7567
|
+
return {
|
|
7568
|
+
...base,
|
|
7569
|
+
origin: "tuner",
|
|
7570
|
+
standard: "atsc3",
|
|
7571
|
+
frequency,
|
|
7572
|
+
...plpId !== void 0 ? { plpId } : {},
|
|
7573
|
+
...serviceId !== void 0 ? { serviceId } : {}
|
|
7574
|
+
};
|
|
7575
|
+
}
|
|
7509
7576
|
const relay = input.amtRelay?.trim();
|
|
7510
|
-
const
|
|
7577
|
+
const driad = !relay && input.amtDiscovery === "driad";
|
|
7578
|
+
const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
|
|
7511
7579
|
if (!wantsAmt) {
|
|
7512
7580
|
const native = {
|
|
7513
7581
|
...base,
|
|
@@ -7517,6 +7585,20 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
7517
7585
|
return native;
|
|
7518
7586
|
}
|
|
7519
7587
|
const relayPort = input.amtRelayPort;
|
|
7588
|
+
if (driad) {
|
|
7589
|
+
if (!base.source)
|
|
7590
|
+
throw new TypeError("AMT DRIAD discovery requires a source address");
|
|
7591
|
+
if (relayPort !== void 0 && !isPositivePort(relayPort)) {
|
|
7592
|
+
throw new TypeError("AMT DRIAD discovery requires a valid relay port when one is given");
|
|
7593
|
+
}
|
|
7594
|
+
return {
|
|
7595
|
+
...base,
|
|
7596
|
+
source: base.source,
|
|
7597
|
+
origin: "amt",
|
|
7598
|
+
discovery: "driad",
|
|
7599
|
+
...relayPort !== void 0 ? { relayPort } : {}
|
|
7600
|
+
};
|
|
7601
|
+
}
|
|
7520
7602
|
if (!relay || relayPort === void 0 || !isPositivePort(relayPort)) {
|
|
7521
7603
|
throw new TypeError("AMT requires a resolved relay and a valid relay port");
|
|
7522
7604
|
}
|
|
@@ -7560,7 +7642,8 @@ function normalizeMulticastEndpoint(endpoint) {
|
|
|
7560
7642
|
port: endpoint.port,
|
|
7561
7643
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7562
7644
|
...amtRelay ? { amtRelay } : {},
|
|
7563
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7645
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7646
|
+
...endpoint.amtDiscovery === "driad" ? { amtDiscovery: "driad" } : {}
|
|
7564
7647
|
};
|
|
7565
7648
|
}
|
|
7566
7649
|
function multicastEndpointKey(endpoint) {
|
|
@@ -7573,7 +7656,9 @@ function multicastEndpointKey(endpoint) {
|
|
|
7573
7656
|
normalized.port,
|
|
7574
7657
|
normalized.mode ?? "auto",
|
|
7575
7658
|
normalized.amtRelay ?? "",
|
|
7576
|
-
normalized.amtRelayPort ?? ""
|
|
7659
|
+
normalized.amtRelayPort ?? "",
|
|
7660
|
+
// A DRIAD join is a different gateway subscription from a native one.
|
|
7661
|
+
...normalized.amtDiscovery ? [normalized.amtDiscovery] : []
|
|
7577
7662
|
]);
|
|
7578
7663
|
}
|
|
7579
7664
|
function isMulticastTrackPacketId(value) {
|
|
@@ -7613,7 +7698,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7613
7698
|
port: config.port,
|
|
7614
7699
|
mode: config.mode,
|
|
7615
7700
|
amtRelay: config.amtRelay,
|
|
7616
|
-
amtRelayPort: config.amtRelayPort
|
|
7701
|
+
amtRelayPort: config.amtRelayPort,
|
|
7702
|
+
amtDiscovery: config.amtDiscovery
|
|
7617
7703
|
});
|
|
7618
7704
|
if (!endpoint)
|
|
7619
7705
|
throw new Error("Invalid multicast endpoint");
|
|
@@ -7679,7 +7765,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7679
7765
|
port: endpoint.port,
|
|
7680
7766
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7681
7767
|
...endpoint.amtRelay ? { amtRelay: endpoint.amtRelay } : {},
|
|
7682
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7768
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7769
|
+
...endpoint.amtDiscovery ? { amtDiscovery: endpoint.amtDiscovery } : {}
|
|
7683
7770
|
}));
|
|
7684
7771
|
const consumers = /* @__PURE__ */ new Map();
|
|
7685
7772
|
let entry;
|
|
@@ -7759,7 +7846,6 @@ var TransportManager = class {
|
|
|
7759
7846
|
};
|
|
7760
7847
|
capabilities = null;
|
|
7761
7848
|
subscription = null;
|
|
7762
|
-
driad = new DRIADDiscovery();
|
|
7763
7849
|
/** Built by `connect()` from the caller's ladder; there is no built-in one. */
|
|
7764
7850
|
abr = null;
|
|
7765
7851
|
multicastOrchestrator = null;
|
|
@@ -7809,8 +7895,8 @@ var TransportManager = class {
|
|
|
7809
7895
|
nativeIGMP: hasGatewayBytes,
|
|
7810
7896
|
directSockets: typeof win?.UDPSocket !== "undefined",
|
|
7811
7897
|
amt: false,
|
|
7812
|
-
driad:
|
|
7813
|
-
//
|
|
7898
|
+
driad: hasGatewayBytes,
|
|
7899
|
+
// the gateway runs RFC 8777 discovery
|
|
7814
7900
|
fecDecode: false
|
|
7815
7901
|
};
|
|
7816
7902
|
console.log("[Transport] Capabilities:", this.capabilities);
|
|
@@ -7821,7 +7907,7 @@ var TransportManager = class {
|
|
|
7821
7907
|
*
|
|
7822
7908
|
* Promotion hierarchy:
|
|
7823
7909
|
* 1. window.multicast gateway bytes
|
|
7824
|
-
* 2. AMT
|
|
7910
|
+
* 2. AMT: a configured relay via the AMT proxy, else gateway DRIAD discovery
|
|
7825
7911
|
* 3. MOQ WebTransport (final fallback)
|
|
7826
7912
|
*
|
|
7827
7913
|
* The ABR ladder (`abrLadder`) and initial rendition (`initialQuality`)
|
|
@@ -7915,7 +8001,7 @@ var TransportManager = class {
|
|
|
7915
8001
|
/**
|
|
7916
8002
|
* Connect via the lowercase window.multicast bytes gateway.
|
|
7917
8003
|
*/
|
|
7918
|
-
async connectWindowMulticast(config, generation) {
|
|
8004
|
+
async connectWindowMulticast(config, generation, mode = "multicast") {
|
|
7919
8005
|
try {
|
|
7920
8006
|
const gateway = this.getWindowMulticastGateway();
|
|
7921
8007
|
if (typeof gateway?.subscribe !== "function")
|
|
@@ -7950,7 +8036,7 @@ var TransportManager = class {
|
|
|
7950
8036
|
}
|
|
7951
8037
|
};
|
|
7952
8038
|
this.state = {
|
|
7953
|
-
mode
|
|
8039
|
+
mode,
|
|
7954
8040
|
connected: true,
|
|
7955
8041
|
group: config.group,
|
|
7956
8042
|
source: config.source,
|
|
@@ -7968,29 +8054,19 @@ var TransportManager = class {
|
|
|
7968
8054
|
}
|
|
7969
8055
|
}
|
|
7970
8056
|
/**
|
|
7971
|
-
* Connect via AMT proxy
|
|
8057
|
+
* Connect via AMT: a configured relay goes through the AMT proxy; with no
|
|
8058
|
+
* relay, the window.multicast gateway discovers one per RFC 8777 (DRIAD).
|
|
7972
8059
|
*/
|
|
7973
8060
|
async connectAmt(config, generation) {
|
|
7974
8061
|
try {
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
const relays = await this.driad.discoverRelays(config.source);
|
|
7979
|
-
if (generation !== this.connectionGeneration)
|
|
7980
|
-
return false;
|
|
7981
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
7982
|
-
if (generation !== this.connectionGeneration)
|
|
7983
|
-
return false;
|
|
7984
|
-
if (bestRelay) {
|
|
7985
|
-
amtRelay = bestRelay.host;
|
|
7986
|
-
this.state.amtRelay = amtRelay;
|
|
7987
|
-
}
|
|
7988
|
-
}
|
|
7989
|
-
if (!amtRelay) {
|
|
8062
|
+
if (config.amtRelay)
|
|
8063
|
+
return await this.connectAmtProxy(config, config.amtRelay, generation);
|
|
8064
|
+
if (config.driadEnabled === false || !config.source || config.mode === "native") {
|
|
7990
8065
|
console.warn("[Transport] No AMT relay available (DRIAD requires source address for SSM)");
|
|
7991
8066
|
return false;
|
|
7992
8067
|
}
|
|
7993
|
-
|
|
8068
|
+
console.log(`[Transport] Asking the gateway for a DRIAD relay for source ${config.source}...`);
|
|
8069
|
+
return await this.connectWindowMulticast({ ...config, amtDiscovery: "driad" }, generation, "amt");
|
|
7994
8070
|
} catch (error) {
|
|
7995
8071
|
console.warn("[Transport] AMT connection failed:", error);
|
|
7996
8072
|
return false;
|
|
@@ -8221,7 +8297,6 @@ var AMTGatewayManager = class {
|
|
|
8221
8297
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8222
8298
|
messageHandler;
|
|
8223
8299
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
8224
|
-
driad = new DRIADDiscovery();
|
|
8225
8300
|
constructor() {
|
|
8226
8301
|
this.messageHandler = (event) => {
|
|
8227
8302
|
const data = event.data;
|
|
@@ -8252,26 +8327,12 @@ var AMTGatewayManager = class {
|
|
|
8252
8327
|
return keyStr;
|
|
8253
8328
|
}
|
|
8254
8329
|
try {
|
|
8255
|
-
|
|
8256
|
-
let discoveryMethod;
|
|
8330
|
+
const relayAddress = config.relayAddress;
|
|
8257
8331
|
const relayPort = config.relayPort || DEFAULT_AMT_RELAY_PORT2;
|
|
8258
|
-
if (
|
|
8259
|
-
|
|
8260
|
-
discoveryMethod = "manual";
|
|
8261
|
-
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8262
|
-
} else if (key.source) {
|
|
8263
|
-
console.log(`[AMT] No relay configured, discovering via DRIAD for source ${key.source}...`);
|
|
8264
|
-
const relays = await this.driad.discoverRelays(key.source);
|
|
8265
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
8266
|
-
if (!bestRelay) {
|
|
8267
|
-
throw new Error(`AMT relay discovery failed for source ${key.source}. Please specify a relay address in the subscription configuration.`);
|
|
8268
|
-
}
|
|
8269
|
-
relayAddress = bestRelay.host;
|
|
8270
|
-
discoveryMethod = "driad";
|
|
8271
|
-
console.log(`[AMT] Discovered relay via DRIAD: ${relayAddress}:${relayPort}`);
|
|
8272
|
-
} else {
|
|
8273
|
-
throw new Error(`AMT relay discovery requires a source address for SSM (RFC 8777). Please specify either a relay address or source address.`);
|
|
8332
|
+
if (!relayAddress) {
|
|
8333
|
+
throw new Error(`AMT relay address required: this manager does no relay discovery. For RFC 8777 DRIAD discovery, join through window.multicast with amtDiscovery: "driad".`);
|
|
8274
8334
|
}
|
|
8335
|
+
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8275
8336
|
const subscriptionId = keyStr;
|
|
8276
8337
|
this.pendingPackets.set(subscriptionId, []);
|
|
8277
8338
|
const subscription = {
|
|
@@ -8282,7 +8343,7 @@ var AMTGatewayManager = class {
|
|
|
8282
8343
|
relay: {
|
|
8283
8344
|
address: relayAddress,
|
|
8284
8345
|
port: relayPort,
|
|
8285
|
-
discoveryMethod,
|
|
8346
|
+
discoveryMethod: "manual",
|
|
8286
8347
|
discoveredAt: Date.now()
|
|
8287
8348
|
}
|
|
8288
8349
|
};
|
|
@@ -8757,8 +8818,7 @@ function multicastFromConfig(input) {
|
|
|
8757
8818
|
);
|
|
8758
8819
|
}
|
|
8759
8820
|
}
|
|
8760
|
-
const
|
|
8761
|
-
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx, seenTuples));
|
|
8821
|
+
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx));
|
|
8762
8822
|
const out = { endpoints };
|
|
8763
8823
|
const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
|
|
8764
8824
|
networkSource.forEach(validateNetworkSourceEntry);
|
|
@@ -8792,9 +8852,20 @@ function multicastFromConfig(input) {
|
|
|
8792
8852
|
throw new MulticastInputError(
|
|
8793
8853
|
ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
|
|
8794
8854
|
idx,
|
|
8795
|
-
`endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying
|
|
8855
|
+
`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" : "")
|
|
8796
8856
|
);
|
|
8797
8857
|
});
|
|
8858
|
+
input.endpoints.forEach((ep, idx) => {
|
|
8859
|
+
if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
|
|
8860
|
+
endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
|
|
8861
|
+
});
|
|
8862
|
+
if (input.auth !== void 0) out.auth = input.auth;
|
|
8863
|
+
const [issue] = multicastCatalogIssues({ multicast: out });
|
|
8864
|
+
if (issue) {
|
|
8865
|
+
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";
|
|
8866
|
+
const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
|
|
8867
|
+
throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
|
|
8868
|
+
}
|
|
8798
8869
|
if (input.enabled !== void 0) out.enabled = input.enabled;
|
|
8799
8870
|
if (input.version !== void 0) out.version = input.version;
|
|
8800
8871
|
if (input.validUntil !== void 0) out.validUntil = input.validUntil;
|
|
@@ -8806,10 +8877,10 @@ function resolveNetworkSource(input) {
|
|
|
8806
8877
|
}
|
|
8807
8878
|
const relayDns = input.amtFallback?.relayDns?.trim();
|
|
8808
8879
|
const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
|
|
8809
|
-
const discovery = input.amtFallback?.discovery
|
|
8810
|
-
if (discovery === void 0) return { entries: [], relayFrom: null };
|
|
8880
|
+
const discovery = input.amtFallback?.discovery;
|
|
8881
|
+
if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
|
|
8811
8882
|
return {
|
|
8812
|
-
entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
|
|
8883
|
+
entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
|
|
8813
8884
|
relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
|
|
8814
8885
|
};
|
|
8815
8886
|
}
|
|
@@ -8822,8 +8893,11 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8822
8893
|
const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
|
|
8823
8894
|
if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
|
|
8824
8895
|
if (s.type === "amt") {
|
|
8825
|
-
if (s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8826
|
-
throw err(
|
|
8896
|
+
if (s.discovery !== void 0 && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8897
|
+
throw err(
|
|
8898
|
+
"invalid_amt_discovery",
|
|
8899
|
+
`discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`
|
|
8900
|
+
);
|
|
8827
8901
|
}
|
|
8828
8902
|
if (s.relay !== void 0) {
|
|
8829
8903
|
const relay = typeof s.relay === "string" ? s.relay.trim() : "";
|
|
@@ -8832,8 +8906,8 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8832
8906
|
}
|
|
8833
8907
|
s.relay = relay;
|
|
8834
8908
|
}
|
|
8835
|
-
if (s.discovery === "manual" && s.relay === void 0) {
|
|
8836
|
-
throw err("amt_requires_relay", `discovery="
|
|
8909
|
+
if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === void 0) {
|
|
8910
|
+
throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
|
|
8837
8911
|
}
|
|
8838
8912
|
if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
|
|
8839
8913
|
throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
|
|
@@ -8842,13 +8916,15 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8842
8916
|
}
|
|
8843
8917
|
const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
|
|
8844
8918
|
if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
|
|
8845
|
-
throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
|
|
8919
|
+
throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
|
|
8920
|
+
}
|
|
8921
|
+
if (s.plpId !== void 0 && !inRange(s.plpId, 0, 63)) {
|
|
8922
|
+
throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
|
|
8846
8923
|
}
|
|
8847
|
-
if (!inRange(s.
|
|
8848
|
-
if (!inRange(s.serviceId, 0, 65535)) {
|
|
8924
|
+
if (s.serviceId !== void 0 && !inRange(s.serviceId, 0, 65535)) {
|
|
8849
8925
|
throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
|
|
8850
8926
|
}
|
|
8851
|
-
if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
|
|
8927
|
+
if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
|
|
8852
8928
|
throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
|
|
8853
8929
|
}
|
|
8854
8930
|
}
|
|
@@ -8860,7 +8936,7 @@ function isAbsoluteUri(value) {
|
|
|
8860
8936
|
return false;
|
|
8861
8937
|
}
|
|
8862
8938
|
}
|
|
8863
|
-
function validateEndpoint2(ep, idx
|
|
8939
|
+
function validateEndpoint2(ep, idx) {
|
|
8864
8940
|
if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
|
|
8865
8941
|
throw new MulticastInputError(
|
|
8866
8942
|
"ssm_requires_source",
|
|
@@ -8868,6 +8944,13 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8868
8944
|
`endpoint[${idx}] protocol=ssm requires sourceAddress`
|
|
8869
8945
|
);
|
|
8870
8946
|
}
|
|
8947
|
+
if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
|
|
8948
|
+
throw new MulticastInputError(
|
|
8949
|
+
"protocol_source_mismatch",
|
|
8950
|
+
idx,
|
|
8951
|
+
`endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
|
|
8952
|
+
);
|
|
8953
|
+
}
|
|
8871
8954
|
if (!isMulticastGroupAddress(ep.groupAddress)) {
|
|
8872
8955
|
throw new MulticastInputError(
|
|
8873
8956
|
"invalid_group_address",
|
|
@@ -8927,23 +9010,15 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8927
9010
|
`endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
|
|
8928
9011
|
);
|
|
8929
9012
|
}
|
|
8930
|
-
const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
|
|
8931
|
-
if (seenTuples.has(tupleKey)) {
|
|
8932
|
-
throw new MulticastInputError(
|
|
8933
|
-
"duplicate_endpoint_tuple",
|
|
8934
|
-
idx,
|
|
8935
|
-
`endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
|
|
8936
|
-
);
|
|
8937
|
-
}
|
|
8938
|
-
seenTuples.add(tupleKey);
|
|
8939
9013
|
const out = {
|
|
8940
|
-
protocol: ep.
|
|
9014
|
+
protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
|
|
8941
9015
|
groupAddress: ep.groupAddress,
|
|
8942
9016
|
port: ep.port,
|
|
8943
9017
|
tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
|
|
8944
9018
|
};
|
|
8945
9019
|
if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
|
|
8946
9020
|
if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
|
|
9021
|
+
if (ep.auth !== void 0) out.auth = { ...ep.auth };
|
|
8947
9022
|
return out;
|
|
8948
9023
|
}
|
|
8949
9024
|
function isMulticastGroupAddress(addr) {
|
|
@@ -8986,9 +9061,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
|
|
|
8986
9061
|
endpoints,
|
|
8987
9062
|
...hasCatalogAmt ? {
|
|
8988
9063
|
amtFallback: {
|
|
8989
|
-
//
|
|
8990
|
-
//
|
|
8991
|
-
discovery: amtDiscovery
|
|
9064
|
+
// No default: an omitted discovery with a relay hostname is
|
|
9065
|
+
// "dns" (draft-ramadan-moq-multicast-01 4.2.1).
|
|
9066
|
+
...amtDiscovery ? { discovery: amtDiscovery } : {},
|
|
8992
9067
|
...amtRelayDns ? { relayDns: amtRelayDns } : {}
|
|
8993
9068
|
}
|
|
8994
9069
|
} : {}
|
|
@@ -9156,7 +9231,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9156
9231
|
if (ot.role !== void 0 && existing.role === void 0) existing.role = ot.role;
|
|
9157
9232
|
if (existing.packaging === "mmtp") {
|
|
9158
9233
|
const mode = existing.mmtpMode ?? ot.mmtpMode;
|
|
9159
|
-
if (mode !== "
|
|
9234
|
+
if (mode !== "mfu") {
|
|
9160
9235
|
throw new Error(
|
|
9161
9236
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9162
9237
|
);
|
|
@@ -9193,7 +9268,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9193
9268
|
);
|
|
9194
9269
|
}
|
|
9195
9270
|
const mmtpMode = ot.mmtpMode;
|
|
9196
|
-
if (packaging === "mmtp" && mmtpMode !== "
|
|
9271
|
+
if (packaging === "mmtp" && mmtpMode !== "mfu") {
|
|
9197
9272
|
throw new Error(
|
|
9198
9273
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9199
9274
|
);
|
|
@@ -9494,8 +9569,8 @@ function u32(v) {
|
|
|
9494
9569
|
}
|
|
9495
9570
|
var KEYFRAME_FLAGS = 33554432;
|
|
9496
9571
|
var DELTA_FLAGS = 16842752;
|
|
9497
|
-
var
|
|
9498
|
-
var MAX_TRACK_ID =
|
|
9572
|
+
var UINT32_MAX2 = 4294967295;
|
|
9573
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
9499
9574
|
var INT32_MIN = -2147483648;
|
|
9500
9575
|
var INT32_MAX = 2147483647;
|
|
9501
9576
|
function assertTrackId(trackId, label) {
|
|
@@ -9504,8 +9579,8 @@ function assertTrackId(trackId, label) {
|
|
|
9504
9579
|
}
|
|
9505
9580
|
}
|
|
9506
9581
|
function assertTimescale(timescale, label) {
|
|
9507
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
9508
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
9582
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
9583
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
9509
9584
|
}
|
|
9510
9585
|
}
|
|
9511
9586
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -12338,16 +12413,6 @@ var DeliveryGapEstimator = class {
|
|
|
12338
12413
|
|
|
12339
12414
|
// src/iso-block-locator.ts
|
|
12340
12415
|
var IsoBlockLocator = class _IsoBlockLocator {
|
|
12341
|
-
/** Known blocks and spans, in serial order of their start. */
|
|
12342
|
-
#blocks = [];
|
|
12343
|
-
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12344
|
-
#held = /* @__PURE__ */ new Map();
|
|
12345
|
-
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12346
|
-
#coverageEnd;
|
|
12347
|
-
#kMax;
|
|
12348
|
-
#retentionBlocks;
|
|
12349
|
-
#heldEvicted = 0;
|
|
12350
|
-
#newest;
|
|
12351
12416
|
/**
|
|
12352
12417
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
12353
12418
|
* @param retentionBlocks how many blocks behind the newest position the
|
|
@@ -12355,12 +12420,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12355
12420
|
* no locator exists without retention.
|
|
12356
12421
|
*/
|
|
12357
12422
|
constructor(kMax, retentionBlocks) {
|
|
12423
|
+
/** Known blocks and spans, in serial order of their start. */
|
|
12424
|
+
this.#blocks = [];
|
|
12425
|
+
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12426
|
+
this.#held = /* @__PURE__ */ new Map();
|
|
12427
|
+
this.#heldEvicted = 0;
|
|
12428
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
12429
|
+
this.#holes = [];
|
|
12430
|
+
/**
|
|
12431
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
12432
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
12433
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
12434
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
12435
|
+
*/
|
|
12436
|
+
this.deferIncompleteGaps = false;
|
|
12358
12437
|
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
12359
12438
|
throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
|
|
12360
12439
|
}
|
|
12361
12440
|
this.#kMax = kMax;
|
|
12362
12441
|
this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
|
|
12363
12442
|
}
|
|
12443
|
+
#blocks;
|
|
12444
|
+
#held;
|
|
12445
|
+
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12446
|
+
#coverageEnd;
|
|
12447
|
+
#kMax;
|
|
12448
|
+
#retentionBlocks;
|
|
12449
|
+
#heldEvicted;
|
|
12450
|
+
#newest;
|
|
12451
|
+
#holes;
|
|
12364
12452
|
static #checkedRetention(retentionBlocks) {
|
|
12365
12453
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
12366
12454
|
throw new Error(
|
|
@@ -12423,6 +12511,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12423
12511
|
}
|
|
12424
12512
|
return null;
|
|
12425
12513
|
}
|
|
12514
|
+
/** Number of pending holes. */
|
|
12515
|
+
get holeCount() {
|
|
12516
|
+
return this.#holes.length;
|
|
12517
|
+
}
|
|
12518
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
12519
|
+
blockEndingAt(end) {
|
|
12520
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
|
|
12521
|
+
}
|
|
12426
12522
|
/** The known block or span starting exactly at `start`. */
|
|
12427
12523
|
blockAt(start) {
|
|
12428
12524
|
return this.#blocks.find((block) => block.start === start);
|
|
@@ -12445,6 +12541,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12445
12541
|
coversBetween(a, b) {
|
|
12446
12542
|
if (this.#coverageEnd === void 0) return false;
|
|
12447
12543
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
|
|
12544
|
+
const first = a + 1 >>> 0;
|
|
12545
|
+
const count = serial32Distance(a, b) - 1;
|
|
12546
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
|
|
12448
12547
|
return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
|
|
12449
12548
|
}
|
|
12450
12549
|
/**
|
|
@@ -12492,6 +12591,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12492
12591
|
}
|
|
12493
12592
|
return { status: "placed", block: known, placed: [] };
|
|
12494
12593
|
}
|
|
12594
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
|
|
12595
|
+
if (pending !== void 0) {
|
|
12596
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
12597
|
+
return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
|
|
12598
|
+
}
|
|
12599
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1);
|
|
12600
|
+
const before = serial32Distance(pending.start, start);
|
|
12601
|
+
const afterStart = isoBlockEnd(start, length);
|
|
12602
|
+
const after = pending.length - before - length;
|
|
12603
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
|
|
12604
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
|
|
12605
|
+
const block2 = { start, length, span: false };
|
|
12606
|
+
const placed2 = this.#claim(block2);
|
|
12607
|
+
this.#blocks.push(block2);
|
|
12608
|
+
return { status: "placed", block: block2, placed: placed2 };
|
|
12609
|
+
}
|
|
12495
12610
|
for (const block2 of this.#blocks) {
|
|
12496
12611
|
if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
|
|
12497
12612
|
return {
|
|
@@ -12501,6 +12616,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12501
12616
|
}
|
|
12502
12617
|
}
|
|
12503
12618
|
let span;
|
|
12619
|
+
let hole;
|
|
12504
12620
|
if (this.#coverageEnd === void 0) {
|
|
12505
12621
|
for (const ssId of this.#held.keys()) {
|
|
12506
12622
|
if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
|
|
@@ -12509,21 +12625,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12509
12625
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
12510
12626
|
return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
|
|
12511
12627
|
} else if (start !== this.#coverageEnd) {
|
|
12512
|
-
const
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
span:
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12628
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
|
|
12629
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
|
|
12630
|
+
if (lostSsId !== void 0) {
|
|
12631
|
+
const holeBlock = { ...gap, span: false };
|
|
12632
|
+
this.#holes.push(holeBlock);
|
|
12633
|
+
hole = { block: holeBlock, lostSsId };
|
|
12634
|
+
} else {
|
|
12635
|
+
const spanBlock = { ...gap, span: true };
|
|
12636
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) };
|
|
12637
|
+
this.#blocks.push(spanBlock);
|
|
12638
|
+
}
|
|
12519
12639
|
}
|
|
12520
12640
|
const block = { start, length, span: false };
|
|
12521
12641
|
const placed = this.#claim(block);
|
|
12522
12642
|
this.#blocks.push(block);
|
|
12523
12643
|
this.#coverageEnd = isoBlockEnd(start, length);
|
|
12524
12644
|
this.retireBehind(start);
|
|
12645
|
+
if (hole !== void 0) return { status: "placed", block, placed, hole };
|
|
12525
12646
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
12526
12647
|
}
|
|
12648
|
+
/**
|
|
12649
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
12650
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
12651
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
12652
|
+
*/
|
|
12653
|
+
closeHolesWithin(start, length) {
|
|
12654
|
+
const closed = [];
|
|
12655
|
+
for (const hole of [...this.#holes]) {
|
|
12656
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
12657
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1);
|
|
12658
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
12659
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
12660
|
+
this.#blocks.push(spanBlock);
|
|
12661
|
+
}
|
|
12662
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
12663
|
+
}
|
|
12664
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
12665
|
+
#highestMissing(start, length) {
|
|
12666
|
+
const steps = Math.min(length, this.#held.size + 1);
|
|
12667
|
+
for (let i = 1; i <= steps; i++) {
|
|
12668
|
+
const ssId = serial32Add(start, length - i);
|
|
12669
|
+
if (!this.#held.has(ssId)) return ssId;
|
|
12670
|
+
}
|
|
12671
|
+
return void 0;
|
|
12672
|
+
}
|
|
12527
12673
|
/**
|
|
12528
12674
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
12529
12675
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -12542,6 +12688,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12542
12688
|
this.#blocks.splice(i, 1);
|
|
12543
12689
|
}
|
|
12544
12690
|
}
|
|
12691
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
12692
|
+
const hole = this.#holes[i];
|
|
12693
|
+
const last = serial32Add(hole.start, hole.length - 1);
|
|
12694
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
|
|
12695
|
+
}
|
|
12545
12696
|
for (const ssId of [...this.#held.keys()]) {
|
|
12546
12697
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
|
|
12547
12698
|
}
|
|
@@ -12550,6 +12701,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12550
12701
|
/** Forget everything (publisher restart, track reset). */
|
|
12551
12702
|
reset() {
|
|
12552
12703
|
this.#blocks.length = 0;
|
|
12704
|
+
this.#holes.length = 0;
|
|
12553
12705
|
this.#held.clear();
|
|
12554
12706
|
this.#coverageEnd = void 0;
|
|
12555
12707
|
this.#newest = void 0;
|
|
@@ -12565,6 +12717,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12565
12717
|
return placed;
|
|
12566
12718
|
}
|
|
12567
12719
|
};
|
|
12720
|
+
function isoRangesOverlap(aStart, aLength, bStart, bLength) {
|
|
12721
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
|
|
12722
|
+
}
|
|
12568
12723
|
|
|
12569
12724
|
// src/fec-state.ts
|
|
12570
12725
|
var MIN_INTERLEAVE_DEPTH_MS = 1;
|
|
@@ -12579,22 +12734,16 @@ var INACTIVE = Object.freeze({
|
|
|
12579
12734
|
"reliable-moq": Object.freeze({ state: "inactive", reason: "reliable-moq" }),
|
|
12580
12735
|
"no-multicast-bridge": Object.freeze({ state: "inactive", reason: "no-multicast-bridge" })
|
|
12581
12736
|
});
|
|
12582
|
-
function
|
|
12737
|
+
function recordOf2(value) {
|
|
12583
12738
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
12584
12739
|
}
|
|
12585
|
-
function
|
|
12740
|
+
function isPositiveSafeInteger2(value) {
|
|
12586
12741
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
12587
12742
|
}
|
|
12588
12743
|
function catalogDeclaresFec(fec) {
|
|
12589
|
-
const block =
|
|
12590
|
-
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
12591
|
-
return
|
|
12592
|
-
}
|
|
12593
|
-
function isoBlockSpanUsable(fec) {
|
|
12594
|
-
const block = recordOf(fec);
|
|
12595
|
-
if (block === void 0 || block["blockProfile"] !== "iso-ssbg1-v1") return true;
|
|
12596
|
-
const ms = block["interleaveDepthMs"];
|
|
12597
|
-
return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
|
|
12744
|
+
const block = recordOf2(fec);
|
|
12745
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"])) return false;
|
|
12746
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
12598
12747
|
}
|
|
12599
12748
|
function requireBoolean(value, field) {
|
|
12600
12749
|
if (typeof value !== "boolean") {
|
|
@@ -12610,7 +12759,7 @@ function resolveFecState(evidence) {
|
|
|
12610
12759
|
if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
|
|
12611
12760
|
throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
|
|
12612
12761
|
}
|
|
12613
|
-
if (stats !== null && stats !== void 0 &&
|
|
12762
|
+
if (stats !== null && stats !== void 0 && recordOf2(stats) === void 0) {
|
|
12614
12763
|
throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
|
|
12615
12764
|
}
|
|
12616
12765
|
if (!catalogFec) return INACTIVE["no-catalog-fec"];
|
|
@@ -13081,6 +13230,7 @@ function decideGap(input) {
|
|
|
13081
13230
|
}
|
|
13082
13231
|
|
|
13083
13232
|
// src/fec-manager.ts
|
|
13233
|
+
var RS_MAX_BLOCK_SYMBOLS = 255;
|
|
13084
13234
|
var WORKER_ERROR_LOG_CAP = 5;
|
|
13085
13235
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13086
13236
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
@@ -13315,12 +13465,17 @@ var FECManager = class _FECManager {
|
|
|
13315
13465
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
13316
13466
|
// arithmetic and never throws at all.
|
|
13317
13467
|
this.#orderedHorizonWarnedFor = /* @__PURE__ */ new Set();
|
|
13318
|
-
// Newest block start (SS_Start)
|
|
13319
|
-
//
|
|
13468
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
13469
|
+
// frontier isoSpanResolution reads.
|
|
13320
13470
|
this.#highestSbn = /* @__PURE__ */ new Map();
|
|
13471
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
13472
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
13473
|
+
// blocks ahead of the media they protect.
|
|
13474
|
+
this.#sourceFrontiers = /* @__PURE__ */ new Map();
|
|
13321
13475
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
13322
13476
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
13323
13477
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
13478
|
+
this.#deferIsoGaps = false;
|
|
13324
13479
|
this.#isoRepairRefusedCount = 0;
|
|
13325
13480
|
this.#isoSourceOversizeCount = 0;
|
|
13326
13481
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -13335,8 +13490,8 @@ var FECManager = class _FECManager {
|
|
|
13335
13490
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
13336
13491
|
this.#isoDecoderUnplacedRetireFailed = 0;
|
|
13337
13492
|
// The latest source symbol per stream that carried its MMTP
|
|
13338
|
-
// packet_sequence_number: the anchor that bounds how
|
|
13339
|
-
// producer can have
|
|
13493
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
13494
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
13340
13495
|
this.#sourceAnchors = /* @__PURE__ */ new Map();
|
|
13341
13496
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
13342
13497
|
this.#packetEpochs = /* @__PURE__ */ new Map();
|
|
@@ -13395,6 +13550,14 @@ var FECManager = class _FECManager {
|
|
|
13395
13550
|
this.onBlockReclassified = null;
|
|
13396
13551
|
/** A video stream's classifier mode was established or changed. */
|
|
13397
13552
|
this.onClassifierMode = null;
|
|
13553
|
+
/**
|
|
13554
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
13555
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
13556
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
13557
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
13558
|
+
* for it, which it must be.
|
|
13559
|
+
*/
|
|
13560
|
+
this.#onUndelimitedLoss = null;
|
|
13398
13561
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
13399
13562
|
this.onBlockVanished = null;
|
|
13400
13563
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
@@ -13474,7 +13637,9 @@ var FECManager = class _FECManager {
|
|
|
13474
13637
|
#materializedBlocks;
|
|
13475
13638
|
#orderedHorizonWarnedFor;
|
|
13476
13639
|
#highestSbn;
|
|
13640
|
+
#sourceFrontiers;
|
|
13477
13641
|
#isoLocators;
|
|
13642
|
+
#deferIsoGaps;
|
|
13478
13643
|
#isoRepairRefusedCount;
|
|
13479
13644
|
#isoSourceOversizeCount;
|
|
13480
13645
|
#isoHeldEvictedCount;
|
|
@@ -13488,6 +13653,7 @@ var FECManager = class _FECManager {
|
|
|
13488
13653
|
#workerErrorCounts;
|
|
13489
13654
|
#decoderUnavailableEvents;
|
|
13490
13655
|
#repairSymbolSizeMismatchCount;
|
|
13656
|
+
#onUndelimitedLoss;
|
|
13491
13657
|
#encodeTrackName(catalogTrackName) {
|
|
13492
13658
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
13493
13659
|
if (encoded === void 0) {
|
|
@@ -14064,8 +14230,8 @@ var FECManager = class _FECManager {
|
|
|
14064
14230
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
14065
14231
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
14066
14232
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
14067
|
-
// many blocks a stream can
|
|
14068
|
-
//
|
|
14233
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
14234
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
14069
14235
|
// The extra block of retention is slack for a block still being fed; a block
|
|
14070
14236
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
14071
14237
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -14075,55 +14241,72 @@ var FECManager = class _FECManager {
|
|
|
14075
14241
|
}
|
|
14076
14242
|
/**
|
|
14077
14243
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
14078
|
-
* advance the stream's
|
|
14244
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
14079
14245
|
*
|
|
14080
|
-
* A SOURCE symbol
|
|
14081
|
-
*
|
|
14082
|
-
*
|
|
14246
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
14247
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
14248
|
+
* block goes back further than the blocks this manager retains, or that
|
|
14249
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
14250
|
+
* further than the stream could have produced since its last symbol, is a
|
|
14251
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
14083
14252
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
14084
14253
|
* signals a discontinuity.
|
|
14085
14254
|
*
|
|
14086
14255
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
14087
14256
|
* source symbols filled it, so one interleave span can start several blocks
|
|
14088
|
-
* (every large keyframe does). What bounds a
|
|
14089
|
-
*
|
|
14090
|
-
*
|
|
14091
|
-
*
|
|
14092
|
-
* packet_sequence_number
|
|
14093
|
-
*
|
|
14094
|
-
*
|
|
14257
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
14258
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
14259
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
14260
|
+
* packet of the packet_id, so with both source symbols'
|
|
14261
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
14262
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
14263
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
14264
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
14265
|
+
* known.
|
|
14095
14266
|
*
|
|
14096
14267
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
14097
14268
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
14098
14269
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
14099
14270
|
*/
|
|
14100
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber) {
|
|
14271
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
14101
14272
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
14102
14273
|
const now = performance.now();
|
|
14103
|
-
const previous = this.#highestSbn.get(streamKey);
|
|
14274
|
+
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
14104
14275
|
const anchor = this.#sourceAnchors.get(streamKey);
|
|
14105
14276
|
const psn = symbol === "source" && packetSequenceNumber !== void 0 && Number.isSafeInteger(packetSequenceNumber) && packetSequenceNumber >= 0 && packetSequenceNumber <= 4294967295 ? packetSequenceNumber : void 0;
|
|
14106
14277
|
const anchorHere = () => {
|
|
14107
|
-
if (psn !== void 0 && (anchor === void 0 || !
|
|
14108
|
-
this.#sourceAnchors.set(streamKey, {
|
|
14278
|
+
if (psn !== void 0 && (anchor === void 0 || !serial32Precedes(ssId, anchor.ssId))) {
|
|
14279
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
14280
|
+
}
|
|
14281
|
+
};
|
|
14282
|
+
const advance = () => {
|
|
14283
|
+
const highest = this.#highestSbn.get(streamKey);
|
|
14284
|
+
if (highest === void 0 || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
14285
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14109
14286
|
}
|
|
14287
|
+
if (symbol === "source") this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14288
|
+
anchorHere();
|
|
14110
14289
|
};
|
|
14111
14290
|
const discontinuity = () => {
|
|
14112
14291
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
14113
14292
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14293
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14114
14294
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
14115
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
14295
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
14116
14296
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName);
|
|
14117
14297
|
};
|
|
14118
14298
|
if (previous === void 0) {
|
|
14119
|
-
|
|
14120
|
-
anchorHere();
|
|
14299
|
+
advance();
|
|
14121
14300
|
return;
|
|
14122
14301
|
}
|
|
14123
14302
|
const config = this.#trackConfig(packetId);
|
|
14124
14303
|
const window2 = this.#liveWindowBlocks(config);
|
|
14304
|
+
const sentInOrder = (from, to) => {
|
|
14305
|
+
const sent = to.psn - from.psn >>> 0;
|
|
14306
|
+
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
14307
|
+
};
|
|
14125
14308
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
14126
|
-
if (symbol === "source" && window2 !== null && this.#blocksBehind(sbn, previous.sbn, packetId) >
|
|
14309
|
+
if (symbol === "source" && window2 !== null && this.#blockPrecedes(sbn, previous.sbn) && (this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) || psn !== void 0 && anchor !== void 0 && serial32Precedes(ssId, anchor.ssId) && psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))) {
|
|
14127
14310
|
discontinuity();
|
|
14128
14311
|
return;
|
|
14129
14312
|
}
|
|
@@ -14133,9 +14316,8 @@ var FECManager = class _FECManager {
|
|
|
14133
14316
|
const missing = this.#blocksBehind(previous.sbn, sbn, packetId) - 1;
|
|
14134
14317
|
let plausible = true;
|
|
14135
14318
|
if (window2 !== null) {
|
|
14136
|
-
if (psn !== void 0 && anchor !== void 0 &&
|
|
14137
|
-
|
|
14138
|
-
plausible = sent <= 2147483647 && serial32Distance(anchor.sbn, sbn) <= sent + config.k;
|
|
14319
|
+
if (psn !== void 0 && anchor !== void 0 && serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
14320
|
+
plausible = sentInOrder(anchor, { ssId, psn });
|
|
14139
14321
|
} else {
|
|
14140
14322
|
plausible = missing <= window2 + Math.ceil((now - previous.atMs) / config.interleaveDepthMs);
|
|
14141
14323
|
}
|
|
@@ -14145,8 +14327,7 @@ var FECManager = class _FECManager {
|
|
|
14145
14327
|
discontinuity();
|
|
14146
14328
|
return;
|
|
14147
14329
|
}
|
|
14148
|
-
|
|
14149
|
-
anchorHere();
|
|
14330
|
+
advance();
|
|
14150
14331
|
}
|
|
14151
14332
|
/*
|
|
14152
14333
|
* Block order for one stream (BLO-35597 iso:5). A block is keyed by its
|
|
@@ -14463,8 +14644,10 @@ var FECManager = class _FECManager {
|
|
|
14463
14644
|
);
|
|
14464
14645
|
}
|
|
14465
14646
|
const hasCatalogTiming = _FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs });
|
|
14647
|
+
const algorithm = config.algorithm ?? previous.algorithm;
|
|
14466
14648
|
const next = {
|
|
14467
14649
|
blockProfile,
|
|
14650
|
+
...algorithm === void 0 ? {} : { algorithm },
|
|
14468
14651
|
k,
|
|
14469
14652
|
symbolSize: config.symbolSize != null && config.symbolSize > 0 ? config.symbolSize : previousTrack?.symbolSize ?? 0,
|
|
14470
14653
|
interleaveDepthMs: ownInterleaveDepthMs,
|
|
@@ -14730,6 +14913,7 @@ var FECManager = class _FECManager {
|
|
|
14730
14913
|
resetSet(this.#materializedBlocks);
|
|
14731
14914
|
resetMap(this.#resolvedBlockClasses);
|
|
14732
14915
|
resetMap(this.#highestSbn);
|
|
14916
|
+
resetMap(this.#sourceFrontiers);
|
|
14733
14917
|
resetMap(this.#isoLocators);
|
|
14734
14918
|
resetMap(this.#sourceAnchors);
|
|
14735
14919
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -14835,6 +15019,7 @@ var FECManager = class _FECManager {
|
|
|
14835
15019
|
dropMap(this.#orderedPendingBlocks);
|
|
14836
15020
|
dropMap(this.#resolvedBlockClasses);
|
|
14837
15021
|
dropMap(this.#highestSbn);
|
|
15022
|
+
dropMap(this.#sourceFrontiers);
|
|
14838
15023
|
dropMap(this.#isoLocators);
|
|
14839
15024
|
dropMap(this.#sourceAnchors);
|
|
14840
15025
|
dropMap(this.#classifiers);
|
|
@@ -14927,7 +15112,13 @@ var FECManager = class _FECManager {
|
|
|
14927
15112
|
if (isSourceSymbol && esi === 0) {
|
|
14928
15113
|
this.#startupPartialBlocks.delete(blockKey);
|
|
14929
15114
|
this.#startupAlignedPackets.add(streamKey);
|
|
14930
|
-
} else if (
|
|
15115
|
+
} else if (
|
|
15116
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
15117
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
15118
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
15119
|
+
// per join (BLO-48308).
|
|
15120
|
+
isStartupPartial || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair
|
|
15121
|
+
) {
|
|
14931
15122
|
this.#markStartupPartial(blockKey);
|
|
14932
15123
|
return false;
|
|
14933
15124
|
}
|
|
@@ -15209,6 +15400,7 @@ var FECManager = class _FECManager {
|
|
|
15209
15400
|
let locator = this.#isoLocators.get(streamKey);
|
|
15210
15401
|
if (!locator) {
|
|
15211
15402
|
locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
|
|
15403
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15212
15404
|
this.#isoLocators.set(streamKey, locator);
|
|
15213
15405
|
}
|
|
15214
15406
|
return locator;
|
|
@@ -15252,6 +15444,10 @@ var FECManager = class _FECManager {
|
|
|
15252
15444
|
}
|
|
15253
15445
|
return blocks;
|
|
15254
15446
|
}
|
|
15447
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
15448
|
+
isoRetentionBlocksForPacket(packetId) {
|
|
15449
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : void 0;
|
|
15450
|
+
}
|
|
15255
15451
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
15256
15452
|
isoSourceFits(packetId, packetLength) {
|
|
15257
15453
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize;
|
|
@@ -15301,15 +15497,61 @@ var FECManager = class _FECManager {
|
|
|
15301
15497
|
}
|
|
15302
15498
|
return placement;
|
|
15303
15499
|
}
|
|
15304
|
-
if (placement.span !== void 0)
|
|
15305
|
-
|
|
15306
|
-
|
|
15307
|
-
|
|
15308
|
-
|
|
15309
|
-
|
|
15500
|
+
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
15501
|
+
if (placement.hole !== void 0) {
|
|
15502
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
15503
|
+
const hole = placement.hole.block;
|
|
15504
|
+
const previous = locator.blockEndingAt(hole.start);
|
|
15505
|
+
const loss = {
|
|
15506
|
+
packetId,
|
|
15507
|
+
catalogTrackName,
|
|
15508
|
+
holeStart: hole.start,
|
|
15509
|
+
holeLength: hole.length,
|
|
15510
|
+
lostSsId: placement.hole.lostSsId,
|
|
15511
|
+
kMax: this.#trackConfig(packetId).k,
|
|
15512
|
+
...previous === void 0 ? {} : { previousBlockStart: previous.start }
|
|
15513
|
+
};
|
|
15514
|
+
this.#onUndelimitedLoss(loss);
|
|
15310
15515
|
}
|
|
15311
15516
|
return placement;
|
|
15312
15517
|
}
|
|
15518
|
+
/**
|
|
15519
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
15520
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
15521
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
15522
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
15523
|
+
* nobody to close it.
|
|
15524
|
+
*/
|
|
15525
|
+
setUndelimitedLossHandler(handler) {
|
|
15526
|
+
this.#onUndelimitedLoss = handler;
|
|
15527
|
+
this.#deferIsoGaps = handler !== null;
|
|
15528
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15529
|
+
}
|
|
15530
|
+
/**
|
|
15531
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
15532
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
15533
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
15534
|
+
*/
|
|
15535
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
15536
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
15537
|
+
if (locator === void 0) return [];
|
|
15538
|
+
const spans = locator.closeHolesWithin(start, length);
|
|
15539
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
|
|
15540
|
+
return spans;
|
|
15541
|
+
}
|
|
15542
|
+
/**
|
|
15543
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
15544
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
15545
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
15546
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
15547
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
15548
|
+
* block.
|
|
15549
|
+
*/
|
|
15550
|
+
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
15551
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
15552
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
|
|
15553
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
15554
|
+
}
|
|
15313
15555
|
/**
|
|
15314
15556
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
15315
15557
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -15833,20 +16075,49 @@ var FECManager = class _FECManager {
|
|
|
15833
16075
|
* Caller is responsible for routing recovered data and updating
|
|
15834
16076
|
* block completion state via `markBlockCompleted()`.
|
|
15835
16077
|
*/
|
|
15836
|
-
|
|
15837
|
-
|
|
15838
|
-
|
|
15839
|
-
|
|
16078
|
+
/**
|
|
16079
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
16080
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
16081
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
16082
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
16083
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
16084
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
16085
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
16086
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
16087
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
16088
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
16089
|
+
*/
|
|
16090
|
+
/**
|
|
16091
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16092
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
16093
|
+
* block state unchanged. The router calls this before the repair places a
|
|
16094
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
16095
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
16096
|
+
*/
|
|
16097
|
+
admitRepairBlockLength(packetId, ssbLength, rsbLength, rsId) {
|
|
16098
|
+
if (rsId >= rsbLength) return false;
|
|
16099
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== "reed-solomon") return true;
|
|
16100
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS;
|
|
16101
|
+
}
|
|
16102
|
+
admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, byteLength) {
|
|
16103
|
+
if (!this.#hasBlockProfile(packetId)) return false;
|
|
15840
16104
|
const symbolSize = this.#trackConfig(packetId).symbolSize;
|
|
15841
|
-
if (symbolSize > 0 &&
|
|
16105
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
15842
16106
|
this.#repairSymbolSizeMismatchCount++;
|
|
15843
16107
|
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
15844
16108
|
console.warn(
|
|
15845
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${
|
|
16109
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
15846
16110
|
);
|
|
15847
16111
|
}
|
|
15848
|
-
return
|
|
16112
|
+
return false;
|
|
15849
16113
|
}
|
|
16114
|
+
return true;
|
|
16115
|
+
}
|
|
16116
|
+
feedRepairSymbol(packetId, ssStart, ssbLength, rsId, repairData, catalogTrackName) {
|
|
16117
|
+
this.#fecStats.repairPackets++;
|
|
16118
|
+
this.#statsForPacket(packetId).repairPackets++;
|
|
16119
|
+
if (!this.#hasBlockProfile(packetId)) return null;
|
|
16120
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null;
|
|
15850
16121
|
const fecData = repairData;
|
|
15851
16122
|
const k = this.#trackConfig(packetId).k;
|
|
15852
16123
|
const block = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(ssStart);
|
|
@@ -15999,7 +16270,14 @@ var FECManager = class _FECManager {
|
|
|
15999
16270
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
16000
16271
|
const k = trackConfig.k;
|
|
16001
16272
|
if (this.#completedBlocks.has(key)) return;
|
|
16002
|
-
this.#noteSbnSeen(
|
|
16273
|
+
this.#noteSbnSeen(
|
|
16274
|
+
sbn,
|
|
16275
|
+
packetId,
|
|
16276
|
+
catalogTrackName,
|
|
16277
|
+
"source",
|
|
16278
|
+
evidence.packetSequenceNumber,
|
|
16279
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
16280
|
+
);
|
|
16003
16281
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
16004
16282
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
16005
16283
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -16250,6 +16528,7 @@ var FECManager = class _FECManager {
|
|
|
16250
16528
|
this.#repairedBlocks.clear();
|
|
16251
16529
|
this.#materializedBlocks.clear();
|
|
16252
16530
|
this.#highestSbn.clear();
|
|
16531
|
+
this.#sourceFrontiers.clear();
|
|
16253
16532
|
this.#isoLocators.clear();
|
|
16254
16533
|
this.#sourceAnchors.clear();
|
|
16255
16534
|
this.#trackConfigs.clear();
|
|
@@ -17339,6 +17618,7 @@ function isFmp4Box(data) {
|
|
|
17339
17618
|
const type = String.fromCharCode(data[4], data[5], data[6], data[7]);
|
|
17340
17619
|
return FMPU_BOX_TYPES.has(type);
|
|
17341
17620
|
}
|
|
17621
|
+
var MAX_AWAITING_TIMING_HEADS = 8;
|
|
17342
17622
|
var MmtpContainerParser = class _MmtpContainerParser {
|
|
17343
17623
|
constructor(config) {
|
|
17344
17624
|
this.#tracks = /* @__PURE__ */ new Map();
|
|
@@ -17397,6 +17677,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17397
17677
|
* reordering into the parser. */
|
|
17398
17678
|
this.#reliableMoqStartupGate = /* @__PURE__ */ new Map();
|
|
17399
17679
|
this.#disposed = false;
|
|
17680
|
+
this.#replayingAwaitingTiming = false;
|
|
17400
17681
|
this.#fedObjects = 0;
|
|
17401
17682
|
this.#reassemblerFragmentsFed = 0;
|
|
17402
17683
|
this.#reassemblerDataUnitsReturned = 0;
|
|
@@ -17489,6 +17770,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17489
17770
|
#reorderStats;
|
|
17490
17771
|
#reliableMoqStartupGate;
|
|
17491
17772
|
#disposed;
|
|
17773
|
+
#replayingAwaitingTiming;
|
|
17492
17774
|
#fedObjects;
|
|
17493
17775
|
#reassemblerFragmentsFed;
|
|
17494
17776
|
#reassemblerDataUnitsReturned;
|
|
@@ -17738,7 +18020,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17738
18020
|
* a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
|
|
17739
18021
|
*/
|
|
17740
18022
|
#drop(reason) {
|
|
17741
|
-
this.#
|
|
18023
|
+
if (this.#replayingAwaitingTiming) this.#countDeferredOutcome(reason);
|
|
18024
|
+
else this.#countOutcome(`drop:${reason}`);
|
|
17742
18025
|
return null;
|
|
17743
18026
|
}
|
|
17744
18027
|
get reorderDiagnostics() {
|
|
@@ -17761,6 +18044,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17761
18044
|
for (const combiner of this.#sampleCombiners.values()) {
|
|
17762
18045
|
combiner.cleanupTimeouts(timeoutMs);
|
|
17763
18046
|
}
|
|
18047
|
+
const now = Date.now();
|
|
18048
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18049
|
+
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
18050
|
+
awaitingTiming.shift();
|
|
18051
|
+
}
|
|
18052
|
+
}
|
|
17764
18053
|
}
|
|
17765
18054
|
/**
|
|
17766
18055
|
* Phase 1 of two-phase parsing. Returns structured header info for FEC feeding.
|
|
@@ -17841,7 +18130,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17841
18130
|
byteLength: packet.byteLength
|
|
17842
18131
|
};
|
|
17843
18132
|
}
|
|
17844
|
-
if (info.fecPayloadId !== null && this.#sourceSymbolCb) {
|
|
18133
|
+
if (info.fecPayloadId !== null && this.#sourceSymbolCb && !this.#replayingAwaitingTiming) {
|
|
17845
18134
|
const rawSymbol = packet.subarray(0, packet.length - 4);
|
|
17846
18135
|
try {
|
|
17847
18136
|
this.#sourceSymbolCb(info.packetId, info.fecPayloadId.ssId, rawSymbol);
|
|
@@ -17889,6 +18178,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17889
18178
|
}
|
|
17890
18179
|
return this.#drop("fragment-timing-refused");
|
|
17891
18180
|
}
|
|
18181
|
+
this.#replayAwaitingTiming(streamKey, resolver2);
|
|
17892
18182
|
return {
|
|
17893
18183
|
kind: "fragment",
|
|
17894
18184
|
packet: info,
|
|
@@ -17912,7 +18202,18 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17912
18202
|
mfuDuHeader.movieFragmentSequenceNumber,
|
|
17913
18203
|
mfuDuHeader.sampleNumber
|
|
17914
18204
|
);
|
|
17915
|
-
if (!headTiming)
|
|
18205
|
+
if (!headTiming) {
|
|
18206
|
+
this.#awaitTiming(streamKey, {
|
|
18207
|
+
packet,
|
|
18208
|
+
options,
|
|
18209
|
+
parsed,
|
|
18210
|
+
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
18211
|
+
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
18212
|
+
sampleNumber: mfuDuHeader.sampleNumber,
|
|
18213
|
+
arrivedAt: Date.now()
|
|
18214
|
+
});
|
|
18215
|
+
return this.#drop("mfu-sample-timing-missing");
|
|
18216
|
+
}
|
|
17916
18217
|
const offset = mfuDuHeader.offset;
|
|
17917
18218
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset >= headTiming.size)
|
|
17918
18219
|
return this.#drop("mfu-offset-out-of-range");
|
|
@@ -17988,16 +18289,17 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17988
18289
|
const sampleNumber = assembled.sampleNumber;
|
|
17989
18290
|
if (movieFragmentSequenceNumber === void 0 || sampleNumber === void 0)
|
|
17990
18291
|
return this.#drop("assembled-identity-missing");
|
|
17991
|
-
|
|
18292
|
+
const assembledTiming = resolver.sampleTiming(
|
|
17992
18293
|
assembled.mpuSequenceNumber,
|
|
17993
18294
|
movieFragmentSequenceNumber,
|
|
17994
18295
|
sampleNumber
|
|
17995
|
-
)
|
|
18296
|
+
);
|
|
18297
|
+
if (!assembledTiming) return this.#drop("assembled-timing-missing");
|
|
17996
18298
|
if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
|
|
17997
18299
|
return this.#drop("assembled-mpu-mismatch");
|
|
17998
18300
|
let combined;
|
|
17999
18301
|
try {
|
|
18000
|
-
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled);
|
|
18302
|
+
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled, assembledTiming.size);
|
|
18001
18303
|
} catch (error) {
|
|
18002
18304
|
if (!(error instanceof SampleCombineError)) throw error;
|
|
18003
18305
|
console.warn(
|
|
@@ -18306,9 +18608,37 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18306
18608
|
if (existing) return existing.resolver;
|
|
18307
18609
|
if (!create) return null;
|
|
18308
18610
|
const resolver = new IsoBmffTimingResolver(this.#maxPendingTimingSamples);
|
|
18309
|
-
this.#timingStreams.set(streamKey, { packetId, resolver });
|
|
18611
|
+
this.#timingStreams.set(streamKey, { packetId, resolver, awaitingTiming: [] });
|
|
18310
18612
|
return resolver;
|
|
18311
18613
|
}
|
|
18614
|
+
#awaitTiming(streamKey, head) {
|
|
18615
|
+
const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming;
|
|
18616
|
+
if (!awaitingTiming) return;
|
|
18617
|
+
awaitingTiming.push(head);
|
|
18618
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
|
|
18619
|
+
}
|
|
18620
|
+
/**
|
|
18621
|
+
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
18622
|
+
* FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
|
|
18623
|
+
* FEC path routes a source symbol that already arrived a second time.
|
|
18624
|
+
*/
|
|
18625
|
+
#replayAwaitingTiming(streamKey, resolver) {
|
|
18626
|
+
const state = this.#timingStreams.get(streamKey);
|
|
18627
|
+
if (!state || state.awaitingTiming.length === 0) return;
|
|
18628
|
+
const ready = state.awaitingTiming.filter((head) => resolver.sampleTiming(
|
|
18629
|
+
head.mpuSequenceNumber,
|
|
18630
|
+
head.movieFragmentSequenceNumber,
|
|
18631
|
+
head.sampleNumber
|
|
18632
|
+
));
|
|
18633
|
+
if (ready.length === 0) return;
|
|
18634
|
+
state.awaitingTiming = state.awaitingTiming.filter((head) => !ready.includes(head));
|
|
18635
|
+
this.#replayingAwaitingTiming = true;
|
|
18636
|
+
try {
|
|
18637
|
+
for (const head of ready) this.#feed(head.packet, head.options, head.parsed);
|
|
18638
|
+
} finally {
|
|
18639
|
+
this.#replayingAwaitingTiming = false;
|
|
18640
|
+
}
|
|
18641
|
+
}
|
|
18312
18642
|
#dropTimingStream(streamKey) {
|
|
18313
18643
|
const state = this.#timingStreams.get(streamKey);
|
|
18314
18644
|
if (!state) return;
|
|
@@ -18913,6 +19243,18 @@ var MmtpRouter = class {
|
|
|
18913
19243
|
// MSE recovery routes through CmafBlockAssembler and can reorder by block; the
|
|
18914
19244
|
// direct callback path has to preserve decode order before frames leave libmmt.
|
|
18915
19245
|
#latestVideoSeqByStream = /* @__PURE__ */ new Map();
|
|
19246
|
+
/**
|
|
19247
|
+
* Per stream, SS_ID - packet_sequence_number (mod 2^32) of its latest
|
|
19248
|
+
* first-arrival FEC source packet. A recovered source symbol's wire
|
|
19249
|
+
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
19250
|
+
*/
|
|
19251
|
+
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19252
|
+
/**
|
|
19253
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
19254
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
19255
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
19256
|
+
*/
|
|
19257
|
+
#multicastRapTwinByStream = /* @__PURE__ */ new Set();
|
|
18916
19258
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18917
19259
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18918
19260
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -18987,6 +19329,7 @@ var MmtpRouter = class {
|
|
|
18987
19329
|
*/
|
|
18988
19330
|
#onPublisherRestart;
|
|
18989
19331
|
#publisherRestarts = 0;
|
|
19332
|
+
#restampedRecoveredSeqs = 0;
|
|
18990
19333
|
/** Inits delivered with no onTrackInit handler for their packetId (MOQT-01). */
|
|
18991
19334
|
#unmappedInitDeliveries = 0;
|
|
18992
19335
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
@@ -19045,6 +19388,12 @@ var MmtpRouter = class {
|
|
|
19045
19388
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
|
|
19046
19389
|
};
|
|
19047
19390
|
if (meta.source) frameMeta.source = meta.source;
|
|
19391
|
+
if (isVideo && frameMeta.keyframe) {
|
|
19392
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
19393
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
|
|
19394
|
+
);
|
|
19395
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
19396
|
+
}
|
|
19048
19397
|
if (meta.deliveryProvenance !== void 0)
|
|
19049
19398
|
frameMeta.deliveryProvenance = meta.deliveryProvenance;
|
|
19050
19399
|
if (meta.recovered) frameMeta.recovered = true;
|
|
@@ -19207,6 +19556,14 @@ var MmtpRouter = class {
|
|
|
19207
19556
|
get publisherRestartCount() {
|
|
19208
19557
|
return this.#publisherRestarts;
|
|
19209
19558
|
}
|
|
19559
|
+
/**
|
|
19560
|
+
* FEC-recovered source symbols whose reconstructed header named a
|
|
19561
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to:
|
|
19562
|
+
* a hop re-stamped the sequence after the sender protected the packet.
|
|
19563
|
+
*/
|
|
19564
|
+
get restampedRecoveredSequenceCount() {
|
|
19565
|
+
return this.#restampedRecoveredSeqs;
|
|
19566
|
+
}
|
|
19210
19567
|
/**
|
|
19211
19568
|
* Packets whose Source or Repair FEC Payload ID was left unread because
|
|
19212
19569
|
* their (owner) packetId had no configured `fec.blockProfile`: FEC not
|
|
@@ -19722,6 +20079,14 @@ var MmtpRouter = class {
|
|
|
19722
20079
|
`[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`
|
|
19723
20080
|
);
|
|
19724
20081
|
}
|
|
20082
|
+
if (fec.admitRepairBlockLength && !fec.admitRepairBlockLength(ownerPacketId, repair.ssbLength, repair.rsbLength, repair.rsId)) return;
|
|
20083
|
+
if (fec.admitRepairSymbolSize && !fec.admitRepairSymbolSize(
|
|
20084
|
+
ownerPacketId,
|
|
20085
|
+
repair.ssStart,
|
|
20086
|
+
repair.ssbLength,
|
|
20087
|
+
repair.rsId,
|
|
20088
|
+
repair.symbolData.byteLength
|
|
20089
|
+
)) return;
|
|
19725
20090
|
const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
|
|
19726
20091
|
if (placement.status !== "placed") return;
|
|
19727
20092
|
const blockStart = placement.block.start;
|
|
@@ -19756,6 +20121,17 @@ var MmtpRouter = class {
|
|
|
19756
20121
|
this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
|
|
19757
20122
|
}
|
|
19758
20123
|
}
|
|
20124
|
+
/**
|
|
20125
|
+
* The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
|
|
20126
|
+
* §7.5): what no repair stated becomes repair-less spans, whose held sources
|
|
20127
|
+
* are fed exactly as a span a repair closed.
|
|
20128
|
+
*/
|
|
20129
|
+
closeIsoHoles(ownerPacketId, catalogTrackName, start, length) {
|
|
20130
|
+
const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
|
|
20131
|
+
for (const span of spans) {
|
|
20132
|
+
this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
|
|
20133
|
+
}
|
|
20134
|
+
}
|
|
19759
20135
|
/**
|
|
19760
20136
|
* Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
|
|
19761
20137
|
* a first-arrival source is fed once its block is known: transport
|
|
@@ -19851,6 +20227,8 @@ var MmtpRouter = class {
|
|
|
19851
20227
|
this.#trackSynced.delete(streamKey);
|
|
19852
20228
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19853
20229
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
20230
|
+
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
20231
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
19854
20232
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19855
20233
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
19856
20234
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -20621,6 +20999,12 @@ var MmtpRouter = class {
|
|
|
20621
20999
|
} else if (fecUnreadable && info.fecPayloadId) {
|
|
20622
21000
|
parseSourceSymbol = !duplicates.parsedSymbols.has(info.fecPayloadId.ssId);
|
|
20623
21001
|
}
|
|
21002
|
+
if (fecPayloadId && !overlapCopy) {
|
|
21003
|
+
this.#ssIdSeqOffsetByStream.set(
|
|
21004
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
21005
|
+
fecPayloadId.ssId - info.sequenceNumber >>> 0
|
|
21006
|
+
);
|
|
21007
|
+
}
|
|
20624
21008
|
if (!this.#fecManager || !info.fecPayloadId || parseSourceSymbol) {
|
|
20625
21009
|
if (this.#fecManager && info.fecPayloadId) {
|
|
20626
21010
|
duplicates.parsedSymbols.add(info.fecPayloadId.ssId);
|
|
@@ -20643,6 +21027,10 @@ var MmtpRouter = class {
|
|
|
20643
21027
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
20644
21028
|
...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
|
|
20645
21029
|
}, parsed);
|
|
21030
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
21031
|
+
this.#multicastRapTwinByStream.add(
|
|
21032
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName)
|
|
21033
|
+
);
|
|
20646
21034
|
}
|
|
20647
21035
|
if (this.#classifyPacketId(info.packetId) === null) return;
|
|
20648
21036
|
if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
|
|
@@ -21197,6 +21585,20 @@ var MmtpRouter = class {
|
|
|
21197
21585
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
|
|
21198
21586
|
if (ownerPacketId == null) return;
|
|
21199
21587
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
21588
|
+
const ssIdSeqOffset = this.#ssIdSeqOffsetByStream.get(
|
|
21589
|
+
this.#mediaStreamKey(ownerPacketId, catalogTrackName)
|
|
21590
|
+
);
|
|
21591
|
+
if (ssIdSeqOffset !== void 0) {
|
|
21592
|
+
result = {
|
|
21593
|
+
...result,
|
|
21594
|
+
symbols: result.symbols.map((sym) => {
|
|
21595
|
+
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
21596
|
+
if (wire === sym.packetSequenceNumber) return sym;
|
|
21597
|
+
this.#restampedRecoveredSeqs++;
|
|
21598
|
+
return { ...sym, packetSequenceNumber: wire };
|
|
21599
|
+
})
|
|
21600
|
+
};
|
|
21601
|
+
}
|
|
21200
21602
|
this.#stream(ownerPacketId, catalogTrackName).duplicates.advance(blockId);
|
|
21201
21603
|
const deliveryProvenance = this.#fecManager?.blockDeliveryProvenance?.(
|
|
21202
21604
|
blockId,
|
|
@@ -21937,48 +22339,6 @@ function createWasmMmtpContainerParser(config) {
|
|
|
21937
22339
|
});
|
|
21938
22340
|
}
|
|
21939
22341
|
|
|
21940
|
-
// src/fec-codec.ts
|
|
21941
|
-
var NoneCodec = class {
|
|
21942
|
-
constructor() {
|
|
21943
|
-
this.algorithm = "none";
|
|
21944
|
-
}
|
|
21945
|
-
addSymbol(_blockId, _symbolId, data, _isRepair) {
|
|
21946
|
-
return data;
|
|
21947
|
-
}
|
|
21948
|
-
configure(_params) {
|
|
21949
|
-
}
|
|
21950
|
-
cleanup(_now) {
|
|
21951
|
-
return new Uint8Array(0);
|
|
21952
|
-
}
|
|
21953
|
-
};
|
|
21954
|
-
function createFecCodec(algorithm) {
|
|
21955
|
-
switch (algorithm) {
|
|
21956
|
-
case "none":
|
|
21957
|
-
return new NoneCodec();
|
|
21958
|
-
case "reed-solomon":
|
|
21959
|
-
return new ReedSolomonCodec();
|
|
21960
|
-
case "raptorq":
|
|
21961
|
-
console.warn("[FEC] RaptorQ requested via createFecCodec \u2014 use FECManager.setFecDecoder() for WASM RaptorQ. Falling back to NoneCodec.");
|
|
21962
|
-
return new NoneCodec();
|
|
21963
|
-
default:
|
|
21964
|
-
console.warn(`[FEC] Unknown algorithm "${algorithm}", falling back to NoneCodec`);
|
|
21965
|
-
return new NoneCodec();
|
|
21966
|
-
}
|
|
21967
|
-
}
|
|
21968
|
-
var ReedSolomonCodec = class {
|
|
21969
|
-
constructor() {
|
|
21970
|
-
this.algorithm = "reed-solomon";
|
|
21971
|
-
}
|
|
21972
|
-
addSymbol(_blockId, _symbolId, _data, _isRepair) {
|
|
21973
|
-
return null;
|
|
21974
|
-
}
|
|
21975
|
-
configure(_params) {
|
|
21976
|
-
}
|
|
21977
|
-
cleanup(_now) {
|
|
21978
|
-
return new Uint8Array(0);
|
|
21979
|
-
}
|
|
21980
|
-
};
|
|
21981
|
-
|
|
21982
22342
|
// src/multicast-transport.ts
|
|
21983
22343
|
var JOIN_SUCCEEDED = Object.freeze({ ok: true });
|
|
21984
22344
|
function providerErrorOf(error) {
|
|
@@ -22022,7 +22382,7 @@ function sameIds(a, b) {
|
|
|
22022
22382
|
for (const id of a) if (!b.has(id)) return false;
|
|
22023
22383
|
return true;
|
|
22024
22384
|
}
|
|
22025
|
-
var MulticastTransport = class
|
|
22385
|
+
var MulticastTransport = class {
|
|
22026
22386
|
#onPacket;
|
|
22027
22387
|
#subscription = null;
|
|
22028
22388
|
#packetListener = null;
|
|
@@ -22094,8 +22454,11 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22094
22454
|
// droppedPacketIds.
|
|
22095
22455
|
#unadvertisedPacketIds = /* @__PURE__ */ new Set();
|
|
22096
22456
|
#joinGeneration = 0;
|
|
22097
|
-
|
|
22457
|
+
// The provider to subscribe through; window.multicast when unset.
|
|
22458
|
+
#gateway;
|
|
22459
|
+
constructor(onPacket, options = {}) {
|
|
22098
22460
|
this.#onPacket = onPacket;
|
|
22461
|
+
this.#gateway = options.gateway;
|
|
22099
22462
|
}
|
|
22100
22463
|
static isAvailable() {
|
|
22101
22464
|
return hasMulticastGateway();
|
|
@@ -22105,7 +22468,8 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22105
22468
|
this.#releaseSubscription();
|
|
22106
22469
|
this.#dataPlaneLive = false;
|
|
22107
22470
|
if (this.#disposed) return this.#declined(generation, "disposed");
|
|
22108
|
-
|
|
22471
|
+
const gateway = this.#gateway ?? getMulticastGlobals().multicast;
|
|
22472
|
+
if (typeof gateway?.subscribe !== "function") {
|
|
22109
22473
|
console.warn("[MulticastTransport] Multicast API not available");
|
|
22110
22474
|
return this.#declined(generation, "unavailable");
|
|
22111
22475
|
}
|
|
@@ -22122,11 +22486,13 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22122
22486
|
mode: config.mode,
|
|
22123
22487
|
amtRelay: config.amtRelay,
|
|
22124
22488
|
amtRelayPort: config.amtRelayPort,
|
|
22489
|
+
amtDiscovery: config.amtDiscovery,
|
|
22125
22490
|
packetIds: config.packetIds,
|
|
22126
|
-
tracks: config.tracks
|
|
22491
|
+
tracks: config.tracks,
|
|
22492
|
+
atsc3: config.atsc3
|
|
22127
22493
|
});
|
|
22128
22494
|
failure = "provider-rejected";
|
|
22129
|
-
const subscription = await
|
|
22495
|
+
const subscription = await gateway.subscribe(subscribeConfig);
|
|
22130
22496
|
failure = "invalid-subscription";
|
|
22131
22497
|
console.log(`[MulticastTransport] window.multicast.subscribe returned:`, !!subscription);
|
|
22132
22498
|
if (this.#disposed || generation !== this.#joinGeneration) {
|
|
@@ -22728,6 +23094,25 @@ function catalogAmtNetworkSource(networkSource) {
|
|
|
22728
23094
|
}
|
|
22729
23095
|
return void 0;
|
|
22730
23096
|
}
|
|
23097
|
+
function intIn(value, min, max) {
|
|
23098
|
+
return Number.isInteger(value) && value >= min && value <= max;
|
|
23099
|
+
}
|
|
23100
|
+
function catalogAtsc3NetworkSource(networkSource) {
|
|
23101
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
23102
|
+
for (const raw of entries) {
|
|
23103
|
+
if (!raw || typeof raw !== "object") continue;
|
|
23104
|
+
const ns = raw;
|
|
23105
|
+
if (ns.type !== "atsc3" || !intIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
|
|
23106
|
+
const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
|
|
23107
|
+
return {
|
|
23108
|
+
frequency: ns.frequency,
|
|
23109
|
+
...intIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
|
|
23110
|
+
...intIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
|
|
23111
|
+
...slsUri ? { slsUri } : {}
|
|
23112
|
+
};
|
|
23113
|
+
}
|
|
23114
|
+
return void 0;
|
|
23115
|
+
}
|
|
22731
23116
|
|
|
22732
23117
|
// src/catalog-fec-params.ts
|
|
22733
23118
|
var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
|
|
@@ -22782,28 +23167,28 @@ function joinedRepairSymbolCount(params, joinedRepairTrackNames) {
|
|
|
22782
23167
|
}
|
|
22783
23168
|
return total;
|
|
22784
23169
|
}
|
|
22785
|
-
function
|
|
23170
|
+
function recordOf3(value) {
|
|
22786
23171
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
22787
23172
|
}
|
|
22788
23173
|
function msfTracks(catalog) {
|
|
22789
23174
|
const raw = catalog.tracks;
|
|
22790
23175
|
if (!Array.isArray(raw)) return void 0;
|
|
22791
|
-
return { tracks: raw.map((t) =>
|
|
23176
|
+
return { tracks: raw.map((t) => recordOf3(t) ?? {}) };
|
|
22792
23177
|
}
|
|
22793
23178
|
function resolveRepairLayers(catalog, source) {
|
|
22794
23179
|
if (!catalog) return void 0;
|
|
22795
23180
|
const sourceName = typeof source === "string" ? source : source.name;
|
|
22796
23181
|
const hang = catalog;
|
|
22797
23182
|
const roles = typeof source === "string" ? ["video", "audio"] : source.type === "audio" ? ["audio"] : source.type === "video" ? ["video"] : ["video", "audio"];
|
|
22798
|
-
const
|
|
22799
|
-
if (
|
|
22800
|
-
const renditionPath = `$.${role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
22801
|
-
const rendition =
|
|
23183
|
+
const located = locateCatalogFecSource(catalog, sourceName, roles);
|
|
23184
|
+
if (located?.dialect === "hang") {
|
|
23185
|
+
const renditionPath = `$.${located.role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
23186
|
+
const rendition = located.entry;
|
|
22802
23187
|
rejectRepairFieldsOnMediaTrack(renditionPath, rendition, throwRepairContractError);
|
|
22803
|
-
const repairRenditions =
|
|
23188
|
+
const repairRenditions = recordOf3(hang.repair?.renditions) ?? {};
|
|
22804
23189
|
const descriptors2 = Object.entries(repairRenditions).map(([name, entry]) => {
|
|
22805
23190
|
const path = `$.repair.renditions[${JSON.stringify(name)}]`;
|
|
22806
|
-
const fields =
|
|
23191
|
+
const fields = recordOf3(entry);
|
|
22807
23192
|
if (fields === void 0) {
|
|
22808
23193
|
throwRepairContractError("track_repair_layer", path, "a repair rendition must be an object");
|
|
22809
23194
|
}
|
|
@@ -22811,14 +23196,14 @@ function resolveRepairLayers(catalog, source) {
|
|
|
22811
23196
|
return describeRepairTrack(name, path, fields);
|
|
22812
23197
|
});
|
|
22813
23198
|
const fecOfRendition = (entry) => {
|
|
22814
|
-
const fec2 =
|
|
23199
|
+
const fec2 = recordOf3(recordOf3(entry)?.["fec"]);
|
|
22815
23200
|
return fec2 !== void 0 && fec2["algorithm"] !== "none" ? fec2 : void 0;
|
|
22816
23201
|
};
|
|
22817
23202
|
const mediaRenditions = [
|
|
22818
|
-
...Object.values(
|
|
22819
|
-
...Object.values(
|
|
23203
|
+
...Object.values(recordOf3(hang.video?.renditions) ?? {}),
|
|
23204
|
+
...Object.values(recordOf3(hang.audio?.renditions) ?? {})
|
|
22820
23205
|
];
|
|
22821
|
-
const reachability2 = repairReachability(mediaRenditions.map((entry) =>
|
|
23206
|
+
const reachability2 = repairReachability(mediaRenditions.map((entry) => recordOf3(entry)?.["fec"]));
|
|
22822
23207
|
for (const d of descriptors2) {
|
|
22823
23208
|
validateRepairTrackFields(d, throwRepairContractError);
|
|
22824
23209
|
assertRepairTrackReachable(d, reachability2, throwRepairContractError);
|
|
@@ -22834,20 +23219,20 @@ function resolveRepairLayers(catalog, source) {
|
|
|
22834
23219
|
}
|
|
22835
23220
|
}
|
|
22836
23221
|
const layers2 = assembleRepairLayers(
|
|
22837
|
-
geometryOf(sourceName, `${renditionPath}.fec`,
|
|
23222
|
+
geometryOf(sourceName, `${renditionPath}.fec`, recordOf3(rendition["fec"])),
|
|
22838
23223
|
descriptors2,
|
|
22839
23224
|
throwRepairContractError
|
|
22840
23225
|
);
|
|
22841
23226
|
return catalogFecUnavailable(rendition["fec"], `${renditionPath}.fec`) === void 0 ? layers2 : void 0;
|
|
22842
23227
|
}
|
|
22843
23228
|
const msf = msfTracks(catalog);
|
|
22844
|
-
|
|
22845
|
-
|
|
23229
|
+
if (!msf || located?.dialect !== "msf") return void 0;
|
|
23230
|
+
const msfIndex = located.index;
|
|
22846
23231
|
const track = msf.tracks[msfIndex];
|
|
22847
|
-
const fec =
|
|
23232
|
+
const fec = recordOf3(track["fec"]);
|
|
22848
23233
|
const packagingOf = (t) => t["packaging"];
|
|
22849
23234
|
const fecOfTrack = (t) => {
|
|
22850
|
-
const trackFec =
|
|
23235
|
+
const trackFec = recordOf3(t?.["fec"]);
|
|
22851
23236
|
return trackFec !== void 0 && trackFec["algorithm"] !== "none" ? trackFec : void 0;
|
|
22852
23237
|
};
|
|
22853
23238
|
const descriptors = [];
|
|
@@ -22897,8 +23282,8 @@ function catalogRepairTarget(catalog, source) {
|
|
|
22897
23282
|
const entry = msf?.tracks.find((t) => t["name"] === sourceName);
|
|
22898
23283
|
const hang = catalog;
|
|
22899
23284
|
const roles = typeof source === "string" ? ["video", "audio"] : source.type === "video" ? ["video"] : source.type === "audio" ? ["audio"] : ["video", "audio"];
|
|
22900
|
-
const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) =>
|
|
22901
|
-
const fec = rendition === void 0 ?
|
|
23285
|
+
const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) => recordOf3(r) !== void 0);
|
|
23286
|
+
const fec = rendition === void 0 ? recordOf3(entry?.["fec"]) : recordOf3(rendition.fec);
|
|
22902
23287
|
if (!fec || !(catalogFecInterleaveMs(fec) ?? 0)) return null;
|
|
22903
23288
|
const sourcePriority = entry === void 0 ? null : moqtPriority2(entry["priority"]);
|
|
22904
23289
|
return { repairTrack: layerZero.repairTrackName, sourcePriority, repairPriority: layerZero.priority };
|
|
@@ -22941,10 +23326,21 @@ function isoSpanUnavailable(fec, path, declaresFecInstance) {
|
|
|
22941
23326
|
});
|
|
22942
23327
|
}
|
|
22943
23328
|
function catalogFecUnavailable(fec, fecPath) {
|
|
22944
|
-
|
|
22945
|
-
|
|
23329
|
+
if (catalogFecAvailable(fec)) return void 0;
|
|
23330
|
+
const block = recordOf3(fec);
|
|
23331
|
+
if (fecAlgorithmUnimplemented(block["algorithm"])) {
|
|
23332
|
+
return Object.freeze({
|
|
23333
|
+
code: "track_fec_algorithm_unimplemented",
|
|
23334
|
+
path: `${fecPath}.algorithm`,
|
|
23335
|
+
message: `algorithm ${JSON.stringify(block["algorithm"])} is not implemented: the track plays without FEC`
|
|
23336
|
+
});
|
|
23337
|
+
}
|
|
22946
23338
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
22947
|
-
|
|
23339
|
+
const reason = blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
|
|
23340
|
+
if (reason === void 0) {
|
|
23341
|
+
throw new Error(`catalogFecUnavailable: ${fecPath} is unavailable but no reason applies (rule drift)`);
|
|
23342
|
+
}
|
|
23343
|
+
return reason;
|
|
22948
23344
|
}
|
|
22949
23345
|
function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
22950
23346
|
const mediaRate = sampleRate === void 0 ? { fps } : { fps, sampleRate };
|
|
@@ -22953,14 +23349,12 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
22953
23349
|
const repair = resolveRepairLayers(catalog, track);
|
|
22954
23350
|
const fecPath = `$.${track.type}.renditions[${JSON.stringify(track.name)}].fec`;
|
|
22955
23351
|
if (!catalogDeclaresFec(fec)) {
|
|
22956
|
-
|
|
22957
|
-
|
|
22958
|
-
const tValid = Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0;
|
|
22959
|
-
if (declaresFecInstance && !(kValid && tValid)) {
|
|
23352
|
+
if (catalogFecDeclaresUnconfigurableInstance(fec)) {
|
|
23353
|
+
const kValid = Number.isSafeInteger(fec.sourceSymbols) && (fec.sourceSymbols ?? 0) > 0;
|
|
22960
23354
|
throwRepairContractError(
|
|
22961
23355
|
"track_fec",
|
|
22962
23356
|
`${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
|
|
22963
|
-
"must be a positive integer"
|
|
23357
|
+
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"
|
|
22964
23358
|
);
|
|
22965
23359
|
}
|
|
22966
23360
|
const fecUnavailable = catalogFecUnavailable(fec, fecPath);
|
|
@@ -22969,6 +23363,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
22969
23363
|
const fecBlockProfile = readFecBlockProfile(fec.blockProfile, `${fecPath}.blockProfile`, true, throwRepairContractError);
|
|
22970
23364
|
return {
|
|
22971
23365
|
fecK: fec.sourceSymbols ?? 0,
|
|
23366
|
+
fecAlgorithm: fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq",
|
|
22972
23367
|
fecBlockProfile,
|
|
22973
23368
|
fecRepairCount: fec.repairSymbols ?? 0,
|
|
22974
23369
|
// The wire RSB_length: every base layer's packets carry the base total (§7.1).
|
|
@@ -23065,8 +23460,10 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
|
|
|
23065
23460
|
repairsSkippedRttUnmeasured: 0,
|
|
23066
23461
|
repairsSkippedRttExceedsBudget: 0,
|
|
23067
23462
|
repairsSkippedPresentationDelayUnavailable: 0,
|
|
23463
|
+
repairsSkippedRangeNoAnchor: 0,
|
|
23068
23464
|
lastRepairSkip: null,
|
|
23069
23465
|
keyframeRepairFetchesSent: 0,
|
|
23466
|
+
rangeRepairFetchesSent: 0,
|
|
23070
23467
|
keyframeBudgetHolds: 0,
|
|
23071
23468
|
keyframeBudgetHoldMs: 0,
|
|
23072
23469
|
deltaBlocksFailed: 0,
|
|
@@ -23145,6 +23542,12 @@ var REPAIR_PRIORITY_REASONS = /* @__PURE__ */ new Set([
|
|
|
23145
23542
|
"repair-priority-absent",
|
|
23146
23543
|
"repair-priority-invalid"
|
|
23147
23544
|
]);
|
|
23545
|
+
var REPAIR_SKIP_REASONS = /* @__PURE__ */ new Set([
|
|
23546
|
+
"rtt-unmeasured",
|
|
23547
|
+
"rtt-exceeds-budget",
|
|
23548
|
+
"presentation-delay-unavailable"
|
|
23549
|
+
]);
|
|
23550
|
+
var REPAIR_DEADLINE_BOUNDS = /* @__PURE__ */ new Set(["wait", "presentation", "keyframe", "retention"]);
|
|
23148
23551
|
var GAP_REASONS = {
|
|
23149
23552
|
"rap-lost": "stall",
|
|
23150
23553
|
"rap-unknown": "stall",
|
|
@@ -23167,6 +23570,9 @@ function isSymbolCounts(value) {
|
|
|
23167
23570
|
function isNullableNonNegative(value) {
|
|
23168
23571
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
23169
23572
|
}
|
|
23573
|
+
function isFiniteNumber(value) {
|
|
23574
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
23575
|
+
}
|
|
23170
23576
|
function isRepairLifecycleEvent(value) {
|
|
23171
23577
|
if (!isRecord(value) || value["version"] !== 2) return false;
|
|
23172
23578
|
const block = value["block"];
|
|
@@ -23184,6 +23590,20 @@ function isRepairLifecycleEvent(value) {
|
|
|
23184
23590
|
case "repair-preempted":
|
|
23185
23591
|
case "repair-deferred":
|
|
23186
23592
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
23593
|
+
case "repair-sent":
|
|
23594
|
+
return hasExactKeys(value, [
|
|
23595
|
+
"version",
|
|
23596
|
+
"type",
|
|
23597
|
+
"block",
|
|
23598
|
+
"priority",
|
|
23599
|
+
"rttMs",
|
|
23600
|
+
"budgetMs",
|
|
23601
|
+
"delayMs",
|
|
23602
|
+
"blockAgeMs",
|
|
23603
|
+
"bound"
|
|
23604
|
+
]) && 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"]);
|
|
23605
|
+
case "repair-skipped":
|
|
23606
|
+
return hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) && isRepairBlockIdentity(block) && REPAIR_SKIP_REASONS.has(value["reason"]) && isNullableNonNegative(value["rttMs"]) && isFiniteNumber(value["budgetMs"]);
|
|
23187
23607
|
case "repair-priority": {
|
|
23188
23608
|
const blockClass = value["blockClass"];
|
|
23189
23609
|
const action = value["action"];
|
|
@@ -23363,6 +23783,9 @@ var MulticastManager = class {
|
|
|
23363
23783
|
#router;
|
|
23364
23784
|
#hostMfuTimeoutMs;
|
|
23365
23785
|
#transport;
|
|
23786
|
+
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
23787
|
+
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
23788
|
+
#repairReleases = /* @__PURE__ */ new Map();
|
|
23366
23789
|
#reportedFecDiagnosticsFailure = false;
|
|
23367
23790
|
// ── Stream-global FEC timing reduction ──
|
|
23368
23791
|
//
|
|
@@ -23626,7 +24049,9 @@ var MulticastManager = class {
|
|
|
23626
24049
|
catalogTrackName
|
|
23627
24050
|
);
|
|
23628
24051
|
this.#configureTrackMapper(packetId, config);
|
|
23629
|
-
this.#router.
|
|
24052
|
+
if (this.#router.trackKindFor(packetId) !== trackType) {
|
|
24053
|
+
this.#router.setPacketIdType(packetId, trackType);
|
|
24054
|
+
}
|
|
23630
24055
|
}
|
|
23631
24056
|
/**
|
|
23632
24057
|
* Stop routing a stream's symbols to its Worker decoder. Returns false when
|
|
@@ -23707,6 +24132,14 @@ var MulticastManager = class {
|
|
|
23707
24132
|
);
|
|
23708
24133
|
}
|
|
23709
24134
|
}
|
|
24135
|
+
for (const [packetId, c] of this.#trackFecTiming) {
|
|
24136
|
+
if (c.deliveryWindowMs === void 0) continue;
|
|
24137
|
+
mfuTimeoutMs = Math.max(
|
|
24138
|
+
mfuTimeoutMs ?? 0,
|
|
24139
|
+
this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
|
|
24140
|
+
this.#hostMfuTimeoutMs ?? 0
|
|
24141
|
+
);
|
|
24142
|
+
}
|
|
23710
24143
|
const failbackWindowMs = deliveryWindowMs === void 0 ? minimumFailbackWindowMs : Math.max(deliveryWindowMs, minimumFailbackWindowMs ?? 0);
|
|
23711
24144
|
this.#transport.setFailbackWindowMs(failbackWindowMs ?? null);
|
|
23712
24145
|
this.#router.setMfuTimeoutMs(mfuTimeoutMs ?? this.#hostMfuTimeoutMs);
|
|
@@ -23890,6 +24323,7 @@ var MulticastManager = class {
|
|
|
23890
24323
|
setMfuTimeoutMs(ms) {
|
|
23891
24324
|
this.#router.setMfuTimeoutMs(ms);
|
|
23892
24325
|
this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
|
|
24326
|
+
if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
|
|
23893
24327
|
}
|
|
23894
24328
|
setTrackCodec(packetId, codec) {
|
|
23895
24329
|
this.#router.setTrackCodec(packetId, codec);
|
|
@@ -24010,11 +24444,80 @@ var MulticastManager = class {
|
|
|
24010
24444
|
// through whatever the relay looks like, since dropping it would be the
|
|
24011
24445
|
// worse behaviour.
|
|
24012
24446
|
amtRelayPort: config.amtRelayPort ?? config.relayPort ?? (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
24447
|
+
amtDiscovery: config.amtDiscovery,
|
|
24013
24448
|
packetIds: config.packetIds,
|
|
24014
24449
|
tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId }))
|
|
24015
24450
|
};
|
|
24016
24451
|
return ingress === void 0 ? this.#transport.join(transportConfig) : this.#transport.join(transportConfig, ingress);
|
|
24017
24452
|
}
|
|
24453
|
+
/**
|
|
24454
|
+
* Join the selected rung's dedicated repair groups beside the media join
|
|
24455
|
+
* (pim #3898): one subscription per endpoint, through `provider` when given
|
|
24456
|
+
* (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
|
|
24457
|
+
* new MulticastTransport on `window.multicast`. Returns the call that
|
|
24458
|
+
* releases every one of them; dispose() releases them too.
|
|
24459
|
+
*
|
|
24460
|
+
* Packets go straight to the router with the endpoint's ingress, never
|
|
24461
|
+
* through feedPacket(): repair arriving on its own group is not media
|
|
24462
|
+
* liveness, so it must not hold off the media leg's failback watchdog. The
|
|
24463
|
+
* repair roles and owners are registered here; in-band owners stay the
|
|
24464
|
+
* caller's. Joining is best effort: a group that fails to join is logged
|
|
24465
|
+
* and leaves the media join as it was.
|
|
24466
|
+
*/
|
|
24467
|
+
joinRepairEndpoints(endpoints, provider) {
|
|
24468
|
+
const releases = [];
|
|
24469
|
+
let released = false;
|
|
24470
|
+
const safely = (each) => {
|
|
24471
|
+
try {
|
|
24472
|
+
each();
|
|
24473
|
+
} catch (error) {
|
|
24474
|
+
console.warn("[MulticastManager] repair group release failed", error);
|
|
24475
|
+
}
|
|
24476
|
+
};
|
|
24477
|
+
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
|
|
24478
|
+
this.#applyRepairOwners(repairOwners);
|
|
24479
|
+
for (const endpoint of endpoints) {
|
|
24480
|
+
const ingress = {
|
|
24481
|
+
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId })))
|
|
24482
|
+
};
|
|
24483
|
+
const onPacket = (packet) => {
|
|
24484
|
+
if (!released) this.#router.feedPacket(packet, "multicast", void 0, ingress);
|
|
24485
|
+
};
|
|
24486
|
+
const fail = (error) => console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
|
|
24487
|
+
if (typeof provider === "function") {
|
|
24488
|
+
Promise.resolve().then(() => provider(endpoint, onPacket)).then((release2) => released ? safely(release2) : releases.push(release2), fail);
|
|
24489
|
+
continue;
|
|
24490
|
+
}
|
|
24491
|
+
const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
|
|
24492
|
+
releases.push(() => transport.dispose());
|
|
24493
|
+
void transport.join({
|
|
24494
|
+
sourceAddress: endpoint.source,
|
|
24495
|
+
groupAddress: endpoint.group,
|
|
24496
|
+
port: endpoint.port,
|
|
24497
|
+
mode: endpoint.mode,
|
|
24498
|
+
amtRelay: endpoint.amtRelay,
|
|
24499
|
+
amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
24500
|
+
packetIds: endpoint.packetIds,
|
|
24501
|
+
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId }))
|
|
24502
|
+
}).then((joined) => {
|
|
24503
|
+
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
24504
|
+
});
|
|
24505
|
+
}
|
|
24506
|
+
const release = () => {
|
|
24507
|
+
if (released) return;
|
|
24508
|
+
released = true;
|
|
24509
|
+
this.#repairReleases.delete(release);
|
|
24510
|
+
for (const each of releases.splice(0)) safely(each);
|
|
24511
|
+
};
|
|
24512
|
+
this.#repairReleases.set(release, repairOwners);
|
|
24513
|
+
return release;
|
|
24514
|
+
}
|
|
24515
|
+
#applyRepairOwners(owners) {
|
|
24516
|
+
for (const { packetId, ownerPacketId } of owners) {
|
|
24517
|
+
this.#router.setPacketIdRole(packetId, "repair");
|
|
24518
|
+
this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
|
|
24519
|
+
}
|
|
24520
|
+
}
|
|
24018
24521
|
// ---------------------------------------------------------------------------
|
|
24019
24522
|
// In-place rendition switch
|
|
24020
24523
|
// ---------------------------------------------------------------------------
|
|
@@ -24290,7 +24793,7 @@ var MulticastManager = class {
|
|
|
24290
24793
|
*
|
|
24291
24794
|
* D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
|
|
24292
24795
|
* D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
|
|
24293
|
-
* D-17: Builds altGroup → track-name index for getSwitchingSet().
|
|
24796
|
+
* D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
|
|
24294
24797
|
* D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
|
|
24295
24798
|
*
|
|
24296
24799
|
* FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
|
|
@@ -24341,11 +24844,9 @@ var MulticastManager = class {
|
|
|
24341
24844
|
}
|
|
24342
24845
|
}
|
|
24343
24846
|
const repairOwnerGroup = /* @__PURE__ */ new Map();
|
|
24344
|
-
const repairOwnerAltGroup = /* @__PURE__ */ new Map();
|
|
24345
24847
|
for (const track of catalog.tracks) {
|
|
24346
24848
|
for (const repairName of repairNamesBySource.get(track.name) ?? []) {
|
|
24347
24849
|
repairOwnerGroup.set(repairName, altGroupKey(track));
|
|
24348
|
-
repairOwnerAltGroup.set(repairName, track.altGroup);
|
|
24349
24850
|
}
|
|
24350
24851
|
}
|
|
24351
24852
|
const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
|
|
@@ -24376,11 +24877,7 @@ var MulticastManager = class {
|
|
|
24376
24877
|
for (const [groupKey, roles] of resolvedRolesByGroup) {
|
|
24377
24878
|
if (!(hasSwitchingSetByGroup.get(groupKey) ?? false)) continue;
|
|
24378
24879
|
const presentRoles = new Set(roles.filter((r) => r !== "single"));
|
|
24379
|
-
const required = [
|
|
24380
|
-
"base",
|
|
24381
|
-
"delta",
|
|
24382
|
-
"repair"
|
|
24383
|
-
];
|
|
24880
|
+
const required = ["base", "repair"];
|
|
24384
24881
|
const missing = required.filter((r) => !presentRoles.has(r));
|
|
24385
24882
|
if (missing.length > 0) {
|
|
24386
24883
|
throw new Error(
|
|
@@ -24427,6 +24924,7 @@ var MulticastManager = class {
|
|
|
24427
24924
|
this.#switchingSets.clear();
|
|
24428
24925
|
this.#repairPacketIds.clear();
|
|
24429
24926
|
this.#router.clearRepairPacketIdOwners();
|
|
24927
|
+
for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
|
|
24430
24928
|
const fecPacketIds = new Set([...fecDecoders.keys()].map((i) => catalog.tracks[i].packetId));
|
|
24431
24929
|
for (const [packetId, catalogTrackName] of this.#multiTrackFecTracks) {
|
|
24432
24930
|
if (fecPacketIds.has(packetId)) continue;
|
|
@@ -24447,11 +24945,10 @@ var MulticastManager = class {
|
|
|
24447
24945
|
for (let i = 0; i < catalog.tracks.length; i++) {
|
|
24448
24946
|
const track = catalog.tracks[i];
|
|
24449
24947
|
const role = resolvedRoles[i];
|
|
24450
|
-
|
|
24451
|
-
|
|
24452
|
-
const existing = this.#switchingSets.get(altGroup) ?? [];
|
|
24948
|
+
if (role !== "repair" && track.altGroup !== void 0) {
|
|
24949
|
+
const existing = this.#switchingSets.get(track.altGroup) ?? [];
|
|
24453
24950
|
existing.push(track.name);
|
|
24454
|
-
this.#switchingSets.set(altGroup, existing);
|
|
24951
|
+
this.#switchingSets.set(track.altGroup, existing);
|
|
24455
24952
|
}
|
|
24456
24953
|
if (track.packetId !== void 0) {
|
|
24457
24954
|
this.#router.setPacketIdRole(track.packetId, role);
|
|
@@ -24526,7 +25023,7 @@ var MulticastManager = class {
|
|
|
24526
25023
|
#multiTrackFecTracks = /* @__PURE__ */ new Map();
|
|
24527
25024
|
/**
|
|
24528
25025
|
* Return the track names belonging to the given altGroup switching set.
|
|
24529
|
-
* D-17:
|
|
25026
|
+
* D-17: tracks with equal altGroup form one switching set; repair legs are in none.
|
|
24530
25027
|
*
|
|
24531
25028
|
* @param altGroup - The altGroup number to look up.
|
|
24532
25029
|
* @returns Array of track names in that switching set (empty if none).
|
|
@@ -24554,6 +25051,19 @@ var MulticastManager = class {
|
|
|
24554
25051
|
this.requestRepairForBlock(sbn, packetId, catalogTrackName, blockClass);
|
|
24555
25052
|
};
|
|
24556
25053
|
}
|
|
25054
|
+
/**
|
|
25055
|
+
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
25056
|
+
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
25057
|
+
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
25058
|
+
* once its range FETCH ends (or none is sent).
|
|
25059
|
+
*/
|
|
25060
|
+
onUndelimitedLoss(cb) {
|
|
25061
|
+
this.#fec.setUndelimitedLossHandler(cb);
|
|
25062
|
+
}
|
|
25063
|
+
/** End a pending hole's range repair: feed what no repair stated as spans. */
|
|
25064
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
25065
|
+
this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
|
|
25066
|
+
}
|
|
24557
25067
|
/**
|
|
24558
25068
|
* Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
|
|
24559
25069
|
* supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
|
|
@@ -24575,6 +25085,7 @@ var MulticastManager = class {
|
|
|
24575
25085
|
stats.repairsSkipped++;
|
|
24576
25086
|
if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
|
|
24577
25087
|
else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
|
|
25088
|
+
else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
|
|
24578
25089
|
else stats.repairsSkippedPresentationDelayUnavailable++;
|
|
24579
25090
|
stats.lastRepairSkip = {
|
|
24580
25091
|
reason,
|
|
@@ -24606,8 +25117,20 @@ var MulticastManager = class {
|
|
|
24606
25117
|
stats.keyframeBudgetHoldMs += extensionMs;
|
|
24607
25118
|
}
|
|
24608
25119
|
/** Record a repair FETCH the scheduler admitted and sent. */
|
|
24609
|
-
noteRepairFetchSent(priority,
|
|
25120
|
+
noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
|
|
24610
25121
|
if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
|
|
25122
|
+
if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
|
|
25123
|
+
this.#emitRepairLifecycle({
|
|
25124
|
+
version: 2,
|
|
25125
|
+
type: "repair-sent",
|
|
25126
|
+
block: repairBlockIdentity(packetId, sbn, catalogTrackName),
|
|
25127
|
+
priority,
|
|
25128
|
+
rttMs: measurement.rttMs,
|
|
25129
|
+
budgetMs: measurement.budgetMs,
|
|
25130
|
+
delayMs: measurement.delayMs,
|
|
25131
|
+
blockAgeMs: measurement.blockAgeMs,
|
|
25132
|
+
bound: measurement.bound
|
|
25133
|
+
});
|
|
24611
25134
|
}
|
|
24612
25135
|
/**
|
|
24613
25136
|
* Record a repair-scheduler decision about a delta block: preempted for
|
|
@@ -24758,6 +25281,7 @@ var MulticastManager = class {
|
|
|
24758
25281
|
this.#trackResetObservers.clear();
|
|
24759
25282
|
this.#repairLifecycleObservers.clear();
|
|
24760
25283
|
this.#transport.dispose();
|
|
25284
|
+
for (const release of [...this.#repairReleases.keys()]) release();
|
|
24761
25285
|
this.#router.dispose();
|
|
24762
25286
|
this.#fec.dispose();
|
|
24763
25287
|
}
|
|
@@ -24833,7 +25357,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24833
25357
|
trackType: opts.trackType,
|
|
24834
25358
|
framerate: opts.framerate,
|
|
24835
25359
|
sampleRate: opts.sampleRate,
|
|
24836
|
-
algorithm: "
|
|
25360
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
24837
25361
|
blockProfile,
|
|
24838
25362
|
k: opts.fecK,
|
|
24839
25363
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
@@ -24847,10 +25371,10 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24847
25371
|
repairTrack: opts.repairTrackName,
|
|
24848
25372
|
relayBlockSigEnabled: false
|
|
24849
25373
|
};
|
|
24850
|
-
client.configure(fecTrackConfig, rqWasm);
|
|
24851
25374
|
try {
|
|
24852
25375
|
opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
|
|
24853
25376
|
blockProfile,
|
|
25377
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
24854
25378
|
k: opts.fecK,
|
|
24855
25379
|
symbolSize: opts.fecSymbolSize,
|
|
24856
25380
|
interleaveDepthMs: opts.fecInterleaveMs,
|
|
@@ -24867,6 +25391,14 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24867
25391
|
}
|
|
24868
25392
|
throw e;
|
|
24869
25393
|
}
|
|
25394
|
+
fecTrackConfig.interleaveDepth = Math.min(
|
|
25395
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
25396
|
+
Math.max(
|
|
25397
|
+
interleaveDepthBlocks,
|
|
25398
|
+
opts.multicastManager.fecManager.isoRetentionBlocksForPacket(opts.packetId) ?? 0
|
|
25399
|
+
)
|
|
25400
|
+
);
|
|
25401
|
+
client.configure(fecTrackConfig, rqWasm);
|
|
24870
25402
|
let disposed = false;
|
|
24871
25403
|
return {
|
|
24872
25404
|
client,
|
|
@@ -25516,7 +26048,7 @@ function asSeconds(n) {
|
|
|
25516
26048
|
}
|
|
25517
26049
|
return n;
|
|
25518
26050
|
}
|
|
25519
|
-
function groupIdForTicks(ticks, groupDurationTicks) {
|
|
26051
|
+
function groupIdForTicks(ticks, groupDurationTicks, presentationAnchorTicks = 0) {
|
|
25520
26052
|
if (!Number.isInteger(ticks)) {
|
|
25521
26053
|
throw new Error(
|
|
25522
26054
|
`[align] groupIdForTicks: ticks must be an integer, got ${ticks}`
|
|
@@ -25527,8 +26059,23 @@ function groupIdForTicks(ticks, groupDurationTicks) {
|
|
|
25527
26059
|
`[align] groupIdForTicks: groupDurationTicks must be a positive integer, got ${groupDurationTicks}`
|
|
25528
26060
|
);
|
|
25529
26061
|
}
|
|
25530
|
-
if (
|
|
25531
|
-
|
|
26062
|
+
if (!Number.isInteger(presentationAnchorTicks)) {
|
|
26063
|
+
throw new Error(
|
|
26064
|
+
`[align] groupIdForTicks: presentationAnchorTicks must be an integer, got ${presentationAnchorTicks}`
|
|
26065
|
+
);
|
|
26066
|
+
}
|
|
26067
|
+
const relativeTicks = ticks - presentationAnchorTicks;
|
|
26068
|
+
if (!Number.isSafeInteger(relativeTicks)) {
|
|
26069
|
+
throw new Error(
|
|
26070
|
+
`[align] groupIdForTicks: ticks - presentationAnchorTicks = ${relativeTicks} is not a safe integer`
|
|
26071
|
+
);
|
|
26072
|
+
}
|
|
26073
|
+
if (relativeTicks < 0) {
|
|
26074
|
+
throw new Error(
|
|
26075
|
+
`[align] groupIdForTicks: ticks ${ticks} precede presentationAnchorTicks ${presentationAnchorTicks}; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26076
|
+
);
|
|
26077
|
+
}
|
|
26078
|
+
return Math.floor(relativeTicks / groupDurationTicks);
|
|
25532
26079
|
}
|
|
25533
26080
|
function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
25534
26081
|
if (!Number.isFinite(mediaTimeSec)) {
|
|
@@ -25541,7 +26088,11 @@ function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
|
25541
26088
|
`[align] groupIdFor: groupDurationSec must be a positive finite number, got ${groupDurationSec}`
|
|
25542
26089
|
);
|
|
25543
26090
|
}
|
|
25544
|
-
if (mediaTimeSec < 0)
|
|
26091
|
+
if (mediaTimeSec < 0) {
|
|
26092
|
+
throw new Error(
|
|
26093
|
+
`[align] groupIdFor: mediaTimeSec ${mediaTimeSec} precedes presentationAnchorTicks 0; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26094
|
+
);
|
|
26095
|
+
}
|
|
25545
26096
|
const TS = 1e9;
|
|
25546
26097
|
const ticks = Math.round(mediaTimeSec * TS);
|
|
25547
26098
|
const durTicks = Math.round(groupDurationSec * TS);
|
|
@@ -26512,6 +27063,346 @@ var CmcdProducer = class {
|
|
|
26512
27063
|
}
|
|
26513
27064
|
};
|
|
26514
27065
|
|
|
27066
|
+
// src/mmtp-fec-session.ts
|
|
27067
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
27068
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
27069
|
+
var MmtpFecSession = class {
|
|
27070
|
+
#decoder;
|
|
27071
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
27072
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
27073
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
27074
|
+
#settled = /* @__PURE__ */ new Set();
|
|
27075
|
+
/**
|
|
27076
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
27077
|
+
* received on, or 0 for one the session recovered.
|
|
27078
|
+
*/
|
|
27079
|
+
#have = /* @__PURE__ */ new Map();
|
|
27080
|
+
#newest;
|
|
27081
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
27082
|
+
#prunedAt;
|
|
27083
|
+
#repairPacketId;
|
|
27084
|
+
#stats = {
|
|
27085
|
+
sourceSymbols: 0,
|
|
27086
|
+
repairSymbols: 0,
|
|
27087
|
+
blocksClean: 0,
|
|
27088
|
+
blocksRecovered: 0,
|
|
27089
|
+
blocksFailed: 0,
|
|
27090
|
+
blocksReleased: 0,
|
|
27091
|
+
packetsRecovered: 0,
|
|
27092
|
+
packetsLost: 0,
|
|
27093
|
+
dropped: {},
|
|
27094
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27095
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27096
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
27097
|
+
};
|
|
27098
|
+
/**
|
|
27099
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
27100
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
27101
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
27102
|
+
*/
|
|
27103
|
+
constructor(config) {
|
|
27104
|
+
const fec = config?.fec;
|
|
27105
|
+
if (!fec || typeof fec !== "object") {
|
|
27106
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
27107
|
+
}
|
|
27108
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
27109
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
27110
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
27111
|
+
}
|
|
27112
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
27113
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
27114
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
27115
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
27116
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
27117
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
27118
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
27119
|
+
interleaveDepthMs
|
|
27120
|
+
);
|
|
27121
|
+
if (typeof config.Decoder !== "function") {
|
|
27122
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
27123
|
+
}
|
|
27124
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
27125
|
+
try {
|
|
27126
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
27127
|
+
} catch (error) {
|
|
27128
|
+
decoder.free();
|
|
27129
|
+
throw error;
|
|
27130
|
+
}
|
|
27131
|
+
this.#decoder = decoder;
|
|
27132
|
+
}
|
|
27133
|
+
/** True once release() ran. */
|
|
27134
|
+
get released() {
|
|
27135
|
+
return this.#decoder === null;
|
|
27136
|
+
}
|
|
27137
|
+
get stats() {
|
|
27138
|
+
return {
|
|
27139
|
+
...this.#stats,
|
|
27140
|
+
dropped: { ...this.#stats.dropped },
|
|
27141
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
27142
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
27143
|
+
mixedPath: { ...this.#stats.mixedPath }
|
|
27144
|
+
};
|
|
27145
|
+
}
|
|
27146
|
+
/**
|
|
27147
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
27148
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
27149
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
27150
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
27151
|
+
*
|
|
27152
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
27153
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
27154
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
27155
|
+
*/
|
|
27156
|
+
addSource(ssId, packet, path = "moq") {
|
|
27157
|
+
const decoder = this.#decoder;
|
|
27158
|
+
if (!decoder) return this.#drop("source:released");
|
|
27159
|
+
const pathBit = PATH_BITS[path];
|
|
27160
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
27161
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
27162
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
27163
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
27164
|
+
this.#have.set(ssId, pathBit);
|
|
27165
|
+
this.#stats.sourceSymbols++;
|
|
27166
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
27167
|
+
this.#noteNewest(ssId);
|
|
27168
|
+
const start = this.#blockStartOf(ssId);
|
|
27169
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
27170
|
+
if (block) {
|
|
27171
|
+
block.received++;
|
|
27172
|
+
block.paths |= pathBit;
|
|
27173
|
+
}
|
|
27174
|
+
let output;
|
|
27175
|
+
try {
|
|
27176
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
27177
|
+
} catch {
|
|
27178
|
+
this.#drop("source:decoder-refused");
|
|
27179
|
+
output = void 0;
|
|
27180
|
+
}
|
|
27181
|
+
const recovered = [];
|
|
27182
|
+
if (start !== void 0 && block) {
|
|
27183
|
+
if (output) {
|
|
27184
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
27185
|
+
} else if (block.received >= block.ssbLength) {
|
|
27186
|
+
this.#settleClean(start);
|
|
27187
|
+
}
|
|
27188
|
+
}
|
|
27189
|
+
this.#retireBehindHorizon();
|
|
27190
|
+
return recovered;
|
|
27191
|
+
}
|
|
27192
|
+
/**
|
|
27193
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
27194
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
27195
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
27196
|
+
* `path` is where it was received, as for addSource().
|
|
27197
|
+
*
|
|
27198
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
27199
|
+
* addSource().
|
|
27200
|
+
*/
|
|
27201
|
+
addRepair(packet, path = "moq") {
|
|
27202
|
+
const decoder = this.#decoder;
|
|
27203
|
+
if (!decoder) return this.#drop("repair:released");
|
|
27204
|
+
const pathBit = PATH_BITS[path];
|
|
27205
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
27206
|
+
let header;
|
|
27207
|
+
try {
|
|
27208
|
+
header = parseMMTPHeader(packet);
|
|
27209
|
+
} catch {
|
|
27210
|
+
return this.#drop("repair:malformed");
|
|
27211
|
+
}
|
|
27212
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
27213
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
27214
|
+
if (this.#repairPacketId === void 0) {
|
|
27215
|
+
this.#repairPacketId = frame.packetId;
|
|
27216
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
27217
|
+
return this.#drop("repair:foreign-packet-id");
|
|
27218
|
+
}
|
|
27219
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
27220
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
27221
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
27222
|
+
return this.#drop("repair:rs-block-length");
|
|
27223
|
+
}
|
|
27224
|
+
const start = frame.ssStart;
|
|
27225
|
+
let block = this.#blocks.get(start);
|
|
27226
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
27227
|
+
if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
|
|
27228
|
+
if (!block) {
|
|
27229
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
27230
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
27231
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
27232
|
+
this.#countHeld(start, block);
|
|
27233
|
+
this.#blocks.set(start, block);
|
|
27234
|
+
}
|
|
27235
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
27236
|
+
if (block.received >= block.ssbLength) {
|
|
27237
|
+
this.#settleClean(start);
|
|
27238
|
+
this.#retireBehindHorizon();
|
|
27239
|
+
return [];
|
|
27240
|
+
}
|
|
27241
|
+
let output;
|
|
27242
|
+
try {
|
|
27243
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
27244
|
+
} catch {
|
|
27245
|
+
return this.#drop("repair:decoder-refused");
|
|
27246
|
+
}
|
|
27247
|
+
block.rsIds.add(frame.rsId);
|
|
27248
|
+
this.#stats.repairSymbols++;
|
|
27249
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
27250
|
+
block.paths |= pathBit;
|
|
27251
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
27252
|
+
this.#retireBehindHorizon();
|
|
27253
|
+
return recovered;
|
|
27254
|
+
}
|
|
27255
|
+
/**
|
|
27256
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
27257
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
27258
|
+
* returns whether this call released anything.
|
|
27259
|
+
*/
|
|
27260
|
+
release() {
|
|
27261
|
+
const decoder = this.#decoder;
|
|
27262
|
+
if (!decoder) return false;
|
|
27263
|
+
this.#decoder = null;
|
|
27264
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
27265
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
27266
|
+
this.#blocks.clear();
|
|
27267
|
+
this.#settled.clear();
|
|
27268
|
+
this.#have.clear();
|
|
27269
|
+
decoder.free();
|
|
27270
|
+
return true;
|
|
27271
|
+
}
|
|
27272
|
+
#drop(reason) {
|
|
27273
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
27274
|
+
return [];
|
|
27275
|
+
}
|
|
27276
|
+
#noteNewest(ssId) {
|
|
27277
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
27278
|
+
}
|
|
27279
|
+
#blockStartOf(ssId) {
|
|
27280
|
+
for (const [start, block] of this.#blocks) {
|
|
27281
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
27282
|
+
}
|
|
27283
|
+
return void 0;
|
|
27284
|
+
}
|
|
27285
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
27286
|
+
#countHeld(start, block) {
|
|
27287
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27288
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
27289
|
+
if (pathBit === void 0) continue;
|
|
27290
|
+
block.received++;
|
|
27291
|
+
block.paths |= pathBit;
|
|
27292
|
+
}
|
|
27293
|
+
}
|
|
27294
|
+
#noteMixed(block, outcome) {
|
|
27295
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
27296
|
+
}
|
|
27297
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
27298
|
+
#behindHorizon(start) {
|
|
27299
|
+
const newest = this.#newest;
|
|
27300
|
+
if (newest === void 0) return false;
|
|
27301
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
27302
|
+
}
|
|
27303
|
+
#settle(start) {
|
|
27304
|
+
this.#blocks.delete(start);
|
|
27305
|
+
this.#settled.add(start);
|
|
27306
|
+
}
|
|
27307
|
+
#settleClean(start) {
|
|
27308
|
+
const block = this.#blocks.get(start);
|
|
27309
|
+
if (!block) return;
|
|
27310
|
+
this.#settle(start);
|
|
27311
|
+
this.#stats.blocksClean++;
|
|
27312
|
+
this.#noteMixed(block, "clean");
|
|
27313
|
+
try {
|
|
27314
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
27315
|
+
} catch {
|
|
27316
|
+
}
|
|
27317
|
+
}
|
|
27318
|
+
/**
|
|
27319
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
27320
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
27321
|
+
* back the packets the parser does not have yet.
|
|
27322
|
+
*/
|
|
27323
|
+
#settleDecoded(start, block, output) {
|
|
27324
|
+
this.#settle(start);
|
|
27325
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
27326
|
+
this.#stats.blocksFailed++;
|
|
27327
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27328
|
+
this.#noteMixed(block, "failed");
|
|
27329
|
+
this.#drop("block:decoded-length");
|
|
27330
|
+
return [];
|
|
27331
|
+
}
|
|
27332
|
+
const recovered = [];
|
|
27333
|
+
let refused = 0;
|
|
27334
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27335
|
+
const ssId = serial32Add(start, i);
|
|
27336
|
+
if (this.#have.has(ssId)) continue;
|
|
27337
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
27338
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
27339
|
+
if (!packet) {
|
|
27340
|
+
refused++;
|
|
27341
|
+
continue;
|
|
27342
|
+
}
|
|
27343
|
+
this.#have.set(ssId, 0);
|
|
27344
|
+
recovered.push(packet.slice());
|
|
27345
|
+
}
|
|
27346
|
+
if (refused > 0) {
|
|
27347
|
+
this.#stats.blocksFailed++;
|
|
27348
|
+
this.#stats.packetsLost += refused;
|
|
27349
|
+
this.#noteMixed(block, "failed");
|
|
27350
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
27351
|
+
} else if (recovered.length === 0) {
|
|
27352
|
+
this.#stats.blocksClean++;
|
|
27353
|
+
this.#noteMixed(block, "clean");
|
|
27354
|
+
} else {
|
|
27355
|
+
this.#stats.blocksRecovered++;
|
|
27356
|
+
this.#noteMixed(block, "recovered");
|
|
27357
|
+
}
|
|
27358
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
27359
|
+
return recovered;
|
|
27360
|
+
}
|
|
27361
|
+
/**
|
|
27362
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
27363
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
27364
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
27365
|
+
* restore, or its repair never arrived.
|
|
27366
|
+
*/
|
|
27367
|
+
#retireBehindHorizon() {
|
|
27368
|
+
const decoder = this.#decoder;
|
|
27369
|
+
const newest = this.#newest;
|
|
27370
|
+
if (!decoder || newest === void 0) return;
|
|
27371
|
+
try {
|
|
27372
|
+
decoder.cleanup_by_ss_start(newest);
|
|
27373
|
+
} catch {
|
|
27374
|
+
}
|
|
27375
|
+
for (const [start, block] of this.#blocks) {
|
|
27376
|
+
if (!this.#behindHorizon(start)) continue;
|
|
27377
|
+
this.#settle(start);
|
|
27378
|
+
this.#stats.blocksFailed++;
|
|
27379
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27380
|
+
this.#noteMixed(block, "failed");
|
|
27381
|
+
}
|
|
27382
|
+
const prunedAt = this.#prunedAt;
|
|
27383
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
27384
|
+
this.#prunedAt = newest;
|
|
27385
|
+
for (const ssId of this.#have.keys()) {
|
|
27386
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
27387
|
+
}
|
|
27388
|
+
for (const start of this.#settled) {
|
|
27389
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
27390
|
+
}
|
|
27391
|
+
}
|
|
27392
|
+
};
|
|
27393
|
+
function requirePositiveInteger(value, path) {
|
|
27394
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
27395
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
27396
|
+
}
|
|
27397
|
+
return value;
|
|
27398
|
+
}
|
|
27399
|
+
function requireNumber(value, path) {
|
|
27400
|
+
if (typeof value !== "number") {
|
|
27401
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
27402
|
+
}
|
|
27403
|
+
return value;
|
|
27404
|
+
}
|
|
27405
|
+
|
|
26515
27406
|
// src/repair-fetch.ts
|
|
26516
27407
|
var MOQT_PRIORITY_MAX = 255;
|
|
26517
27408
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
@@ -26546,6 +27437,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26546
27437
|
if (typeof opts.presentationDelayMs !== "function") {
|
|
26547
27438
|
throw new Error("[RepairFetch] presentationDelayMs is required: a repair FETCH is due by the block's presentation deadline");
|
|
26548
27439
|
}
|
|
27440
|
+
if (opts.rangeTransport !== void 0 && (typeof opts.repairEpochReference !== "function" || !mc.onUndelimitedLoss || !mc.closeIsoHoles)) {
|
|
27441
|
+
throw new Error("[RepairFetch] rangeTransport needs repairEpochReference and a host that reports undelimited losses");
|
|
27442
|
+
}
|
|
26549
27443
|
const entries = /* @__PURE__ */ new Map();
|
|
26550
27444
|
const warnedNoTarget = /* @__PURE__ */ new Set();
|
|
26551
27445
|
let disposed = false;
|
|
@@ -26559,7 +27453,12 @@ function wireRepairFetch(mc, opts) {
|
|
|
26559
27453
|
const note = (type, entry) => {
|
|
26560
27454
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26561
27455
|
};
|
|
27456
|
+
const clearEntry = (entry) => {
|
|
27457
|
+
if (entry.range) mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength);
|
|
27458
|
+
else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
27459
|
+
};
|
|
26562
27460
|
const releaseHold = (entry) => {
|
|
27461
|
+
if (entry.range) return;
|
|
26563
27462
|
if (entry.catalogTrackName === void 0) mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId);
|
|
26564
27463
|
else mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26565
27464
|
};
|
|
@@ -26592,10 +27491,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
26592
27491
|
const admit = (entry, now) => {
|
|
26593
27492
|
const budgetMs = entry.deadlineAt - now;
|
|
26594
27493
|
const rttMs = readRtt();
|
|
26595
|
-
if (rttMs !== null && rttMs < budgetMs) return
|
|
27494
|
+
if (rttMs !== null && rttMs < budgetMs) return rttMs;
|
|
26596
27495
|
retire(entry);
|
|
26597
27496
|
releaseHold(entry);
|
|
26598
|
-
|
|
27497
|
+
clearEntry(entry);
|
|
26599
27498
|
mc.noteRepairSkipped(
|
|
26600
27499
|
rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
|
|
26601
27500
|
{ rttMs, budgetMs, priority: entry.priority },
|
|
@@ -26603,10 +27502,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
26603
27502
|
entry.packetId,
|
|
26604
27503
|
entry.catalogTrackName
|
|
26605
27504
|
);
|
|
26606
|
-
return
|
|
27505
|
+
return null;
|
|
26607
27506
|
};
|
|
26608
27507
|
const retire = (entry) => {
|
|
26609
27508
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
27509
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
26610
27510
|
};
|
|
26611
27511
|
const urgentOutstanding = () => {
|
|
26612
27512
|
for (const entry of entries.values()) {
|
|
@@ -26635,17 +27535,28 @@ function wireRepairFetch(mc, opts) {
|
|
|
26635
27535
|
return derived.kind === "omit" ? { subscriberPriority: void 0 } : null;
|
|
26636
27536
|
};
|
|
26637
27537
|
const start = (entry, counted = true) => {
|
|
26638
|
-
|
|
27538
|
+
const now = performance.now();
|
|
27539
|
+
const rttMs = admit(entry, now);
|
|
27540
|
+
if (rttMs === null) return;
|
|
26639
27541
|
if (counted) entry.attempts++;
|
|
26640
|
-
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName
|
|
27542
|
+
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
27543
|
+
rttMs,
|
|
27544
|
+
budgetMs: entry.deadlineAt - now,
|
|
27545
|
+
delayMs: entry.delayMs,
|
|
27546
|
+
blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
|
|
27547
|
+
bound: entry.bound,
|
|
27548
|
+
...entry.range ? { range: true } : {}
|
|
27549
|
+
});
|
|
26641
27550
|
const run = { controller: new AbortController(), stopped: null };
|
|
26642
27551
|
entry.running = run;
|
|
26643
|
-
|
|
26644
|
-
|
|
26645
|
-
|
|
26646
|
-
|
|
26647
|
-
|
|
26648
|
-
|
|
27552
|
+
if (!entry.range) {
|
|
27553
|
+
mc.fecManager.holdBlockForRepair(
|
|
27554
|
+
entry.sbn,
|
|
27555
|
+
entry.packetId,
|
|
27556
|
+
entry.catalogTrackName,
|
|
27557
|
+
entry.deadlineAt
|
|
27558
|
+
);
|
|
27559
|
+
}
|
|
26649
27560
|
void execute(entry, run);
|
|
26650
27561
|
};
|
|
26651
27562
|
const dispatch = () => {
|
|
@@ -26657,14 +27568,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
26657
27568
|
if (entry.deadlineAt <= now) {
|
|
26658
27569
|
stop(entry, "expired");
|
|
26659
27570
|
retire(entry);
|
|
26660
|
-
|
|
27571
|
+
clearEntry(entry);
|
|
26661
27572
|
}
|
|
26662
27573
|
continue;
|
|
26663
27574
|
}
|
|
26664
27575
|
if (entry.deadlineAt <= now) {
|
|
26665
27576
|
retire(entry);
|
|
26666
27577
|
if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
|
|
26667
|
-
|
|
27578
|
+
clearEntry(entry);
|
|
26668
27579
|
continue;
|
|
26669
27580
|
}
|
|
26670
27581
|
queued.push(entry);
|
|
@@ -26701,9 +27612,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26701
27612
|
entry.running = null;
|
|
26702
27613
|
if (error === void 0) {
|
|
26703
27614
|
retire(entry);
|
|
26704
|
-
if (fed === 0 || !decodable(entry)) {
|
|
27615
|
+
if (entry.range || fed === 0 || !decodable(entry)) {
|
|
26705
27616
|
releaseHold(entry);
|
|
26706
|
-
|
|
27617
|
+
clearEntry(entry);
|
|
26707
27618
|
}
|
|
26708
27619
|
dispatch();
|
|
26709
27620
|
return;
|
|
@@ -26715,7 +27626,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26715
27626
|
}
|
|
26716
27627
|
retire(entry);
|
|
26717
27628
|
if (fed === 0) releaseHold(entry);
|
|
26718
|
-
|
|
27629
|
+
clearEntry(entry);
|
|
26719
27630
|
console.warn(
|
|
26720
27631
|
`[RepairFetch] fetch failed pid=${entry.packetId} sbn=${entry.sbn} track=${entry.repairTrack}:`,
|
|
26721
27632
|
error
|
|
@@ -26731,15 +27642,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
26731
27642
|
};
|
|
26732
27643
|
const execute = async (entry, run) => {
|
|
26733
27644
|
let fed = 0;
|
|
27645
|
+
const common = {
|
|
27646
|
+
repairTrack: entry.repairTrack,
|
|
27647
|
+
blockProfile: entry.blockProfile,
|
|
27648
|
+
packetId: entry.packetId,
|
|
27649
|
+
signal: run.controller.signal,
|
|
27650
|
+
subscriberPriority: entry.subscriberPriority
|
|
27651
|
+
};
|
|
26734
27652
|
try {
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
26741
|
-
|
|
26742
|
-
})) {
|
|
27653
|
+
const packets = entry.range ? opts.rangeTransport({
|
|
27654
|
+
...common,
|
|
27655
|
+
startGroup: entry.range.startGroup,
|
|
27656
|
+
endGroup: entry.range.endGroup,
|
|
27657
|
+
lostSsId: entry.range.lostSsId
|
|
27658
|
+
}) : opts.transport({ ...common, sbn: entry.sbn });
|
|
27659
|
+
for await (const packet of packets) {
|
|
26743
27660
|
if (run.stopped !== null || entry.running !== run) break;
|
|
26744
27661
|
fed++;
|
|
26745
27662
|
if (entry.catalogTrackName === void 0) {
|
|
@@ -26758,6 +27675,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26758
27675
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
26759
27676
|
retire(entry);
|
|
26760
27677
|
stop(entry, "reset");
|
|
27678
|
+
if (entry.range) clearEntry(entry);
|
|
26761
27679
|
}
|
|
26762
27680
|
warnedNoTarget.delete(noTargetKey(packetId, catalogTrackName));
|
|
26763
27681
|
dispatch();
|
|
@@ -26784,6 +27702,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26784
27702
|
);
|
|
26785
27703
|
if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
|
|
26786
27704
|
entry2.deadlineAt = promotedDeadline.deadlineAt;
|
|
27705
|
+
entry2.anchorAt = promotedDeadline.anchorAt;
|
|
27706
|
+
entry2.delayMs = promotedDeadline.delayMs;
|
|
27707
|
+
entry2.bound = promotedDeadline.bound;
|
|
26787
27708
|
noteBudget(entry2, promotedDeadline.extensionMs);
|
|
26788
27709
|
}
|
|
26789
27710
|
if (entry2.running) {
|
|
@@ -26809,7 +27730,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26809
27730
|
if (waitMs === void 0) return null;
|
|
26810
27731
|
const waitDeadlineAt = now + waitMs;
|
|
26811
27732
|
const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
|
|
26812
|
-
if (anchor === void 0)
|
|
27733
|
+
if (anchor === void 0) {
|
|
27734
|
+
return { deadlineAt: waitDeadlineAt, extensionMs: 0, anchorAt: null, delayMs: null, bound: "wait" };
|
|
27735
|
+
}
|
|
26813
27736
|
let delayMs;
|
|
26814
27737
|
try {
|
|
26815
27738
|
delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
|
|
@@ -26820,12 +27743,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
26820
27743
|
const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
|
|
26821
27744
|
if (retentionMs === void 0) return null;
|
|
26822
27745
|
const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
|
|
26823
|
-
const
|
|
26824
|
-
|
|
27746
|
+
const at = (delay, delayBound) => {
|
|
27747
|
+
const presentAt = Math.min(anchor + delay, ceilingAt);
|
|
27748
|
+
if (waitDeadlineAt >= presentAt) return { deadlineAt: waitDeadlineAt, bound: "wait" };
|
|
27749
|
+
return { deadlineAt: presentAt, bound: anchor + delay <= ceilingAt ? delayBound : "retention" };
|
|
27750
|
+
};
|
|
27751
|
+
const base = at(delayMs, "presentation");
|
|
26825
27752
|
const budgetMs = keyframeBudgetEligible(blockClass, classifierMode(packetId, catalogTrackName)) && groupCanComplete(sbn, packetId, catalogTrackName) ? readKeyframeBudget(packetId, catalogTrackName) : null;
|
|
26826
|
-
if (budgetMs === null || budgetMs <= delayMs) return {
|
|
26827
|
-
const extended =
|
|
26828
|
-
return {
|
|
27753
|
+
if (budgetMs === null || budgetMs <= delayMs) return { ...base, extensionMs: 0, anchorAt: anchor, delayMs };
|
|
27754
|
+
const extended = at(budgetMs, "keyframe");
|
|
27755
|
+
return {
|
|
27756
|
+
...extended,
|
|
27757
|
+
extensionMs: extended.deadlineAt - base.deadlineAt,
|
|
27758
|
+
anchorAt: anchor,
|
|
27759
|
+
delayMs: budgetMs
|
|
27760
|
+
};
|
|
26829
27761
|
};
|
|
26830
27762
|
const earliestGatedFrameAt = (packetId, catalogTrackName) => {
|
|
26831
27763
|
try {
|
|
@@ -26902,6 +27834,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26902
27834
|
priority,
|
|
26903
27835
|
subscriberPriority: wire.subscriberPriority,
|
|
26904
27836
|
deadlineAt: deadline.deadlineAt,
|
|
27837
|
+
anchorAt: deadline.anchorAt,
|
|
27838
|
+
delayMs: deadline.delayMs,
|
|
27839
|
+
bound: deadline.bound,
|
|
26905
27840
|
order: enqueueOrder++,
|
|
26906
27841
|
attempts: 0,
|
|
26907
27842
|
running: null
|
|
@@ -26911,14 +27846,92 @@ function wireRepairFetch(mc, opts) {
|
|
|
26911
27846
|
if (entry.priority < 2) preemptDeltas();
|
|
26912
27847
|
dispatch();
|
|
26913
27848
|
});
|
|
27849
|
+
const rangeFor = (loss, repairTrack) => {
|
|
27850
|
+
let reference;
|
|
27851
|
+
try {
|
|
27852
|
+
reference = opts.repairEpochReference(repairTrack);
|
|
27853
|
+
} catch {
|
|
27854
|
+
return null;
|
|
27855
|
+
}
|
|
27856
|
+
if (reference === void 0) return null;
|
|
27857
|
+
try {
|
|
27858
|
+
const anchor = loss.previousBlockStart === void 0 ? { reference } : { previousBlockStart: extendSsId(reference, loss.previousBlockStart) };
|
|
27859
|
+
return repairFetchRange(loss.lostSsId, loss.kMax, anchor);
|
|
27860
|
+
} catch (error) {
|
|
27861
|
+
if (error instanceof RangeError) return null;
|
|
27862
|
+
throw error;
|
|
27863
|
+
}
|
|
27864
|
+
};
|
|
27865
|
+
if (opts.rangeTransport !== void 0) {
|
|
27866
|
+
mc.onUndelimitedLoss((loss) => {
|
|
27867
|
+
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
27868
|
+
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
27869
|
+
if (disposed) return close();
|
|
27870
|
+
const blockProfile = blockProfileOf(packetId);
|
|
27871
|
+
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
27872
|
+
if (!target) return close();
|
|
27873
|
+
const priority = repairPriorityForClass("unknown");
|
|
27874
|
+
const range = rangeFor(loss, target.repairTrack);
|
|
27875
|
+
if (range === null) {
|
|
27876
|
+
close();
|
|
27877
|
+
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
27878
|
+
return;
|
|
27879
|
+
}
|
|
27880
|
+
const identity = {
|
|
27881
|
+
target,
|
|
27882
|
+
sbn: holeStart,
|
|
27883
|
+
packetId,
|
|
27884
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
27885
|
+
};
|
|
27886
|
+
const wire = wirePriority(identity, "unknown");
|
|
27887
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), "unknown");
|
|
27888
|
+
if (deadline === null) {
|
|
27889
|
+
close();
|
|
27890
|
+
mc.noteRepairSkipped(
|
|
27891
|
+
"presentation-delay-unavailable",
|
|
27892
|
+
{ rttMs: readRtt(), budgetMs: 0, priority },
|
|
27893
|
+
holeStart,
|
|
27894
|
+
packetId,
|
|
27895
|
+
catalogTrackName
|
|
27896
|
+
);
|
|
27897
|
+
return;
|
|
27898
|
+
}
|
|
27899
|
+
const entry = {
|
|
27900
|
+
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
27901
|
+
...identity,
|
|
27902
|
+
repairTrack: target.repairTrack,
|
|
27903
|
+
blockProfile,
|
|
27904
|
+
priority,
|
|
27905
|
+
subscriberPriority: wire.subscriberPriority,
|
|
27906
|
+
deadlineAt: deadline.deadlineAt,
|
|
27907
|
+
anchorAt: deadline.anchorAt,
|
|
27908
|
+
delayMs: deadline.delayMs,
|
|
27909
|
+
bound: deadline.bound,
|
|
27910
|
+
order: enqueueOrder++,
|
|
27911
|
+
attempts: 0,
|
|
27912
|
+
running: null,
|
|
27913
|
+
range: { ...range, lostSsId: loss.lostSsId, holeLength }
|
|
27914
|
+
};
|
|
27915
|
+
const previous = entries.get(entry.key);
|
|
27916
|
+
if (previous) {
|
|
27917
|
+
retire(previous);
|
|
27918
|
+
stop(previous, "reset");
|
|
27919
|
+
}
|
|
27920
|
+
entries.set(entry.key, entry);
|
|
27921
|
+
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
27922
|
+
preemptDeltas();
|
|
27923
|
+
dispatch();
|
|
27924
|
+
});
|
|
27925
|
+
}
|
|
26914
27926
|
return () => {
|
|
26915
27927
|
disposed = true;
|
|
26916
27928
|
removeResetObserver();
|
|
26917
27929
|
removeLifecycleObserver();
|
|
26918
27930
|
for (const entry of [...entries.values()]) {
|
|
26919
|
-
|
|
27931
|
+
clearEntry(entry);
|
|
26920
27932
|
if (entry.running) releaseHold(entry);
|
|
26921
27933
|
stop(entry, "disposed");
|
|
27934
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
26922
27935
|
}
|
|
26923
27936
|
entries.clear();
|
|
26924
27937
|
};
|
|
@@ -26957,20 +27970,19 @@ export {
|
|
|
26957
27970
|
MfuReassemblyError,
|
|
26958
27971
|
MmtpContainerParser,
|
|
26959
27972
|
MmtpDecodePipeline,
|
|
27973
|
+
MmtpFecSession,
|
|
26960
27974
|
MmtpRouter,
|
|
26961
27975
|
MmtpToCmaf,
|
|
26962
27976
|
MulticastContainerContractError,
|
|
26963
27977
|
MulticastInputError,
|
|
26964
27978
|
MulticastManager,
|
|
26965
27979
|
MulticastTransport,
|
|
26966
|
-
NoneCodec,
|
|
26967
27980
|
REPAIR_LIFECYCLE_EVENT_TYPE,
|
|
26968
27981
|
REPAIR_LIFECYCLE_LOG_PREFIX,
|
|
26969
27982
|
REPAIR_PRIORITY_MAX,
|
|
26970
27983
|
REPAIR_PRIORITY_MIN,
|
|
26971
27984
|
REPAIR_TRACK_GEOMETRY_KEYS,
|
|
26972
27985
|
REPAIR_TRACK_ONLY_KEYS,
|
|
26973
|
-
ReedSolomonCodec,
|
|
26974
27986
|
RepairContractError,
|
|
26975
27987
|
SOURCE_MEDIA_PRIORITY_MAX,
|
|
26976
27988
|
SampleCombineError,
|
|
@@ -26991,7 +28003,10 @@ export {
|
|
|
26991
28003
|
buildHevcVideoInitSegment,
|
|
26992
28004
|
buildVideoInitSegment,
|
|
26993
28005
|
catalogAmtNetworkSource,
|
|
28006
|
+
catalogAtsc3NetworkSource,
|
|
26994
28007
|
catalogDeclaresFec,
|
|
28008
|
+
catalogFecAvailable,
|
|
28009
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
26995
28010
|
catalogFecInterleaveMs,
|
|
26996
28011
|
catalogFecMediaUnitsPerSecond,
|
|
26997
28012
|
catalogFecUnavailable,
|
|
@@ -27005,7 +28020,6 @@ export {
|
|
|
27005
28020
|
computeFecDeliveryWindowMediaUnits,
|
|
27006
28021
|
computeFecDeliveryWindowMs,
|
|
27007
28022
|
computeFecLossWindowMs,
|
|
27008
|
-
createFecCodec,
|
|
27009
28023
|
createFragment,
|
|
27010
28024
|
createWasmMmtpContainerParser,
|
|
27011
28025
|
datagramMfuReassembly,
|
|
@@ -27033,6 +28047,7 @@ export {
|
|
|
27033
28047
|
extractHevcCodecDescription,
|
|
27034
28048
|
extractHevcParameterSets,
|
|
27035
28049
|
extractSpsPpsFromAvcC,
|
|
28050
|
+
fecAlgorithmUnimplemented,
|
|
27036
28051
|
findAnnexBStartCode,
|
|
27037
28052
|
forwardRepairLifecycleEvents,
|
|
27038
28053
|
frameSamplesFromInit,
|
|
@@ -27066,6 +28081,7 @@ export {
|
|
|
27066
28081
|
isTrackTimingConfig,
|
|
27067
28082
|
joinedRepairSymbolCount,
|
|
27068
28083
|
keyframeIntervalMediaTicks,
|
|
28084
|
+
locateCatalogFecSource,
|
|
27069
28085
|
mergeOverrideIntoCmsfTracks,
|
|
27070
28086
|
mergeOverrideIntoHangRenditions,
|
|
27071
28087
|
mfuReassemblyTimeoutMs,
|