@blockcast/mmt-container 0.4.0-main.1cd3cdea89da → 0.4.0-main.1d3ea1cc8ff2
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 +1938 -723
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +327 -205
- 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 +28 -7
- 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/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +104 -230
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +121 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +412 -66
- 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 +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +18 -4
- 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 +1156 -326
- 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 +53 -2
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +193 -27
- 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 +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +302 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +903 -365
- 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 +115 -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 +1105 -310
- 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 +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +193 -68
- package/src/catalog-fec-params.ts +66 -20
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +450 -63
- package/src/fec-state.ts +14 -12
- package/src/fec-worker-setup.ts +30 -2
- package/src/index.ts +32 -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 +187 -3
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +267 -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 +78 -5
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/negative/raptorq-unaligned-symbol.json +1 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +63 -0
- 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,13 +6757,22 @@ var CmsfCatalogValidationError = class extends Error {
|
|
|
6592
6757
|
function catalogError(code, path, message) {
|
|
6593
6758
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
6594
6759
|
}
|
|
6595
|
-
function
|
|
6760
|
+
function validateNetworkSourceRelays(sources, path) {
|
|
6761
|
+
if (!Array.isArray(sources)) return;
|
|
6762
|
+
sources.forEach((source, i) => {
|
|
6763
|
+
const s = source;
|
|
6764
|
+
if (s?.["type"] === "amt" && s["discovery"] === "driad" && s["relay"] !== void 0) {
|
|
6765
|
+
catalogError("multicast_network_source", `${path}[${i}].relay`, 'relay must be omitted with discovery "driad"');
|
|
6766
|
+
}
|
|
6767
|
+
});
|
|
6768
|
+
}
|
|
6769
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
6596
6770
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
6597
6771
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
6598
6772
|
}
|
|
6599
6773
|
const catalog = value;
|
|
6600
6774
|
const rawVersion = catalog["version"];
|
|
6601
|
-
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") ? 1 : NaN : rawVersion;
|
|
6775
|
+
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") || rawVersion === "draft-01" ? 1 : NaN : rawVersion;
|
|
6602
6776
|
if (!Number.isInteger(normalizedVersion) || normalizedVersion <= 0) {
|
|
6603
6777
|
catalogError("catalog_version", "$.version", "version must be a positive integer or a recognized format tag");
|
|
6604
6778
|
}
|
|
@@ -6613,6 +6787,22 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6613
6787
|
"commonTrackFields is retired; every track carries its own fields"
|
|
6614
6788
|
);
|
|
6615
6789
|
}
|
|
6790
|
+
const initDataList = catalog["initDataList"];
|
|
6791
|
+
if (initDataList !== void 0) {
|
|
6792
|
+
if (!Array.isArray(initDataList)) {
|
|
6793
|
+
catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
|
|
6794
|
+
}
|
|
6795
|
+
initDataList.forEach((entry, i) => {
|
|
6796
|
+
const e = entry;
|
|
6797
|
+
const entryPath = `$.initDataList[${i}]`;
|
|
6798
|
+
if (typeof e !== "object" || e === null || Array.isArray(e) || typeof e["id"] !== "string" || e["id"].length === 0 || typeof e["type"] !== "string" || e["type"].length === 0) {
|
|
6799
|
+
catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
|
|
6800
|
+
}
|
|
6801
|
+
if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
|
|
6802
|
+
catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
|
|
6803
|
+
}
|
|
6804
|
+
});
|
|
6805
|
+
}
|
|
6616
6806
|
const tracks = catalog["tracks"];
|
|
6617
6807
|
const trackRecords = [];
|
|
6618
6808
|
const positiveInteger3 = (input) => Number.isSafeInteger(input) && input > 0;
|
|
@@ -6664,6 +6854,14 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6664
6854
|
if (keyframeIntervalMs !== void 0 && !positiveNumber2(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger3(keyframeIntervalTicks)) {
|
|
6665
6855
|
catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
|
|
6666
6856
|
}
|
|
6857
|
+
const anchor = track["presentationAnchorTicks"];
|
|
6858
|
+
if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
|
|
6859
|
+
catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
|
|
6860
|
+
}
|
|
6861
|
+
const initRef = track["initRef"];
|
|
6862
|
+
if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
|
|
6863
|
+
catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
|
|
6864
|
+
}
|
|
6667
6865
|
if (packaging === "fec-repair") {
|
|
6668
6866
|
rejectRepairTrackGeometry(path, track, catalogError);
|
|
6669
6867
|
validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
|
|
@@ -6671,9 +6869,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6671
6869
|
rejectRepairFieldsOnMediaTrack(path, track, catalogError);
|
|
6672
6870
|
}
|
|
6673
6871
|
if (packaging === "mmtp") {
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
|
|
6872
|
+
if (track["mmtpMode"] !== "mfu") {
|
|
6873
|
+
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
|
|
6677
6874
|
}
|
|
6678
6875
|
if (!positiveInteger3(timescale)) {
|
|
6679
6876
|
catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
|
|
@@ -6696,8 +6893,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6696
6893
|
}
|
|
6697
6894
|
const config = fec;
|
|
6698
6895
|
const algorithm = config["algorithm"];
|
|
6699
|
-
if (
|
|
6700
|
-
catalogError("track_fec", `${path}.fec.algorithm`, "
|
|
6896
|
+
if (typeof algorithm !== "string" || algorithm.length === 0) {
|
|
6897
|
+
catalogError("track_fec", `${path}.fec.algorithm`, "must be a non-empty string");
|
|
6701
6898
|
}
|
|
6702
6899
|
if ("interleaveDepth" in config || "interleaveMs" in config) {
|
|
6703
6900
|
catalogError("track_fec", `${path}.fec`, "interleaveDepthMs is the only supported interleave field");
|
|
@@ -6718,11 +6915,17 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6718
6915
|
catalogError("track_fec", `${path}.fec.${field}`, "must be a positive integer");
|
|
6719
6916
|
}
|
|
6720
6917
|
}
|
|
6918
|
+
if (algorithm === "raptorq" && config["symbolSize"] % 8 !== 0) {
|
|
6919
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "RaptorQ symbolSize must be a multiple of 8");
|
|
6920
|
+
}
|
|
6721
6921
|
if (typeof config["repairTrack"] !== "string" || config["repairTrack"].length === 0) {
|
|
6722
6922
|
catalogError("track_fec", `${path}.fec.repairTrack`, "must be a non-empty string");
|
|
6723
6923
|
}
|
|
6724
6924
|
}
|
|
6725
6925
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
6926
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
6927
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
6928
|
+
}
|
|
6726
6929
|
}
|
|
6727
6930
|
}
|
|
6728
6931
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -6772,19 +6975,34 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6772
6975
|
const timescale = BigInt(track["timescale"]);
|
|
6773
6976
|
const durationTicks = track["groupDurationTicks"];
|
|
6774
6977
|
const ticks = durationTicks !== void 0 ? BigInt(durationTicks) : BigInt(track["groupDurationMs"]) * timescale / 1000n;
|
|
6775
|
-
const
|
|
6776
|
-
|
|
6777
|
-
|
|
6978
|
+
const framerate = track["framerate"];
|
|
6979
|
+
const intraOnly = positiveNumber2(framerate) && Math.abs(Number(ticks) * framerate - Number(timescale)) <= Number(timescale) * 1e-3;
|
|
6980
|
+
const members = switchingSets.get(altGroup) ?? [];
|
|
6981
|
+
members.push({ index, name: track["name"], ticks, timescale, intraOnly });
|
|
6982
|
+
switchingSets.set(altGroup, members);
|
|
6983
|
+
}
|
|
6984
|
+
for (const [altGroup, members] of switchingSets) {
|
|
6985
|
+
const anchor = members.find((member) => !member.intraOnly) ?? members[0];
|
|
6986
|
+
for (const member of members) {
|
|
6987
|
+
if (member === anchor || member.ticks * anchor.timescale === anchor.ticks * member.timescale) continue;
|
|
6988
|
+
const nests = member.intraOnly && !anchor.intraOnly && anchor.ticks * member.timescale % (member.ticks * anchor.timescale) === 0n;
|
|
6989
|
+
if (!nests) {
|
|
6990
|
+
catalogError("track_switching_set", `$.tracks[${member.index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
|
|
6991
|
+
}
|
|
6778
6992
|
}
|
|
6779
|
-
if (!anchor) switchingSets.set(altGroup, { name: track["name"], ticks, timescale });
|
|
6780
6993
|
}
|
|
6781
6994
|
const multicast = catalog["multicast"];
|
|
6782
6995
|
if (typeof multicast === "object" && multicast !== null && !Array.isArray(multicast)) {
|
|
6996
|
+
validateNetworkSourceRelays(multicast["networkSource"], "$.multicast.networkSource");
|
|
6783
6997
|
const endpoints = multicast["endpoints"];
|
|
6784
6998
|
if (Array.isArray(endpoints)) {
|
|
6785
6999
|
for (let endpointIndex = 0; endpointIndex < endpoints.length; endpointIndex++) {
|
|
6786
7000
|
const endpoint = endpoints[endpointIndex];
|
|
6787
7001
|
if (typeof endpoint !== "object" || endpoint === null || Array.isArray(endpoint)) continue;
|
|
7002
|
+
validateNetworkSourceRelays(
|
|
7003
|
+
endpoint["networkSource"],
|
|
7004
|
+
`$.multicast.endpoints[${endpointIndex}].networkSource`
|
|
7005
|
+
);
|
|
6788
7006
|
if ("relayAddress" in endpoint) {
|
|
6789
7007
|
catalogError(
|
|
6790
7008
|
"multicast_relay_address",
|
|
@@ -6824,15 +7042,8 @@ function validateCmsfMmtpCatalog(value) {
|
|
|
6824
7042
|
}
|
|
6825
7043
|
}
|
|
6826
7044
|
}
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
} catch (error) {
|
|
6830
|
-
catalogError(
|
|
6831
|
-
"multicast_auth",
|
|
6832
|
-
"$.multicast.auth",
|
|
6833
|
-
error instanceof Error ? error.message : "invalid multicast.auth v2 block"
|
|
6834
|
-
);
|
|
6835
|
-
}
|
|
7045
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
7046
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
6836
7047
|
validateArchive(catalog);
|
|
6837
7048
|
return catalog;
|
|
6838
7049
|
}
|
|
@@ -6858,7 +7069,7 @@ function resolveGroupDurationTicks(timing, timescale) {
|
|
|
6858
7069
|
const product = timing.groupDurationMs * timescale;
|
|
6859
7070
|
if (product % 1e3 !== 0) {
|
|
6860
7071
|
throw new Error(
|
|
6861
|
-
`[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-
|
|
7072
|
+
`[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-01 \xA74.4.2)`
|
|
6862
7073
|
);
|
|
6863
7074
|
}
|
|
6864
7075
|
return product / 1e3;
|
|
@@ -6879,186 +7090,6 @@ function validateSwitchingSetTiming(tracks) {
|
|
|
6879
7090
|
return { ok: false, expectedTicks, mismatches };
|
|
6880
7091
|
}
|
|
6881
7092
|
|
|
6882
|
-
// node_modules/@blockcast/mmt-transport/dist/types.js
|
|
6883
|
-
var MoqFecAlgorithm;
|
|
6884
|
-
(function(MoqFecAlgorithm2) {
|
|
6885
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["None"] = 0] = "None";
|
|
6886
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["Xor"] = 1] = "Xor";
|
|
6887
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
|
|
6888
|
-
})(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
|
|
6889
|
-
|
|
6890
|
-
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
6891
|
-
var MPU_HEADER_SIZE2 = 8;
|
|
6892
|
-
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
6893
|
-
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
6894
|
-
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
6895
|
-
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
6896
|
-
|
|
6897
|
-
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
6898
|
-
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
6899
|
-
|
|
6900
|
-
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
6901
|
-
var NTP_SHORT_BITS2 = 32;
|
|
6902
|
-
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
6903
|
-
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
6904
|
-
function isNtpShort(value) {
|
|
6905
|
-
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
6906
|
-
}
|
|
6907
|
-
function compareNtpShort(a, b) {
|
|
6908
|
-
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
6909
|
-
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
6910
|
-
}
|
|
6911
|
-
if (a === b)
|
|
6912
|
-
return "equal";
|
|
6913
|
-
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
6914
|
-
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
6915
|
-
return "after";
|
|
6916
|
-
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
6917
|
-
return "before";
|
|
6918
|
-
return "unordered";
|
|
6919
|
-
}
|
|
6920
|
-
|
|
6921
|
-
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
6922
|
-
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
6923
|
-
"iso-ssbg1-v1"
|
|
6924
|
-
]);
|
|
6925
|
-
|
|
6926
|
-
// node_modules/@blockcast/mmt-transport/dist/driad-discovery.js
|
|
6927
|
-
var DRIADDiscovery = class {
|
|
6928
|
-
cache = /* @__PURE__ */ new Map();
|
|
6929
|
-
cacheExpiry = 3e5;
|
|
6930
|
-
// 5 minutes
|
|
6931
|
-
/**
|
|
6932
|
-
* Discover AMT relays for a multicast source address (RFC 8777)
|
|
6933
|
-
*
|
|
6934
|
-
* @param source - The multicast source IP address (NOT the group!)
|
|
6935
|
-
* @returns Array of discovered AMT relays that can tunnel traffic from this source
|
|
6936
|
-
*/
|
|
6937
|
-
async discoverRelays(source) {
|
|
6938
|
-
const cached = this.cache.get(source);
|
|
6939
|
-
if (cached) {
|
|
6940
|
-
return cached;
|
|
6941
|
-
}
|
|
6942
|
-
try {
|
|
6943
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
6944
|
-
const queryDomain = `${reversedSource}.amt.in-addr.arpa`;
|
|
6945
|
-
console.log(`[DRIAD] Discovering relays for source ${source} via ${queryDomain}`);
|
|
6946
|
-
const relays = await this.queryDRIADProxy(source);
|
|
6947
|
-
if (relays.length > 0) {
|
|
6948
|
-
this.cache.set(source, relays);
|
|
6949
|
-
setTimeout(() => this.cache.delete(source), this.cacheExpiry);
|
|
6950
|
-
}
|
|
6951
|
-
return relays;
|
|
6952
|
-
} catch (error) {
|
|
6953
|
-
console.warn(`[DRIAD] Discovery failed for source ${source}:`, error);
|
|
6954
|
-
return [];
|
|
6955
|
-
}
|
|
6956
|
-
}
|
|
6957
|
-
/**
|
|
6958
|
-
* Query DRIAD proxy service (browser-compatible)
|
|
6959
|
-
*/
|
|
6960
|
-
async queryDRIADProxy(source) {
|
|
6961
|
-
const proxyEndpoints = [
|
|
6962
|
-
"https://driad.amt.net/api/v1/relays",
|
|
6963
|
-
"https://multicast-gateway.cloudflare.com/driad"
|
|
6964
|
-
];
|
|
6965
|
-
for (const endpoint of proxyEndpoints) {
|
|
6966
|
-
try {
|
|
6967
|
-
const response = await fetch(`${endpoint}?source=${encodeURIComponent(source)}`, {
|
|
6968
|
-
method: "GET",
|
|
6969
|
-
headers: { Accept: "application/json" },
|
|
6970
|
-
signal: AbortSignal.timeout(5e3)
|
|
6971
|
-
});
|
|
6972
|
-
if (response.ok) {
|
|
6973
|
-
const data = await response.json();
|
|
6974
|
-
return data.relays || [];
|
|
6975
|
-
}
|
|
6976
|
-
} catch {
|
|
6977
|
-
}
|
|
6978
|
-
}
|
|
6979
|
-
const dohRelay = await this.queryDNSOverHTTPS(source);
|
|
6980
|
-
if (dohRelay) {
|
|
6981
|
-
return [dohRelay];
|
|
6982
|
-
}
|
|
6983
|
-
return [];
|
|
6984
|
-
}
|
|
6985
|
-
/**
|
|
6986
|
-
* Query DNS-over-HTTPS for DRIAD relay based on source address (RFC 8777)
|
|
6987
|
-
*/
|
|
6988
|
-
async queryDNSOverHTTPS(source) {
|
|
6989
|
-
try {
|
|
6990
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
6991
|
-
const queryName = `${reversedSource}.amt.in-addr.arpa`;
|
|
6992
|
-
const dohUrl = `https://cloudflare-dns.com/dns-query?name=${queryName}&type=A`;
|
|
6993
|
-
const response = await fetch(dohUrl, {
|
|
6994
|
-
headers: { Accept: "application/dns-json" },
|
|
6995
|
-
signal: AbortSignal.timeout(3e3)
|
|
6996
|
-
});
|
|
6997
|
-
if (!response.ok) {
|
|
6998
|
-
return null;
|
|
6999
|
-
}
|
|
7000
|
-
const result = await response.json();
|
|
7001
|
-
if (result.Answer && result.Answer.length > 0) {
|
|
7002
|
-
return {
|
|
7003
|
-
host: result.Answer[0].data,
|
|
7004
|
-
port: DEFAULT_AMT_RELAY_PORT2,
|
|
7005
|
-
priority: 10,
|
|
7006
|
-
weight: 100,
|
|
7007
|
-
asn: 0
|
|
7008
|
-
};
|
|
7009
|
-
}
|
|
7010
|
-
return null;
|
|
7011
|
-
} catch (error) {
|
|
7012
|
-
console.warn("[DRIAD] DNS-over-HTTPS query failed:", error);
|
|
7013
|
-
return null;
|
|
7014
|
-
}
|
|
7015
|
-
}
|
|
7016
|
-
/**
|
|
7017
|
-
* Select best relay based on RTT measurements
|
|
7018
|
-
*/
|
|
7019
|
-
async selectBestRelay(relays) {
|
|
7020
|
-
if (relays.length === 0)
|
|
7021
|
-
return null;
|
|
7022
|
-
const measured = await Promise.all(relays.map(async (relay) => {
|
|
7023
|
-
const rtt = await this.measureRTT(relay.host, relay.port);
|
|
7024
|
-
return { ...relay, rtt };
|
|
7025
|
-
}));
|
|
7026
|
-
measured.sort((a, b) => {
|
|
7027
|
-
if (a.priority !== b.priority)
|
|
7028
|
-
return a.priority - b.priority;
|
|
7029
|
-
return (a.rtt || Infinity) - (b.rtt || Infinity);
|
|
7030
|
-
});
|
|
7031
|
-
console.log(`[DRIAD] Selected relay: ${measured[0].host} (RTT: ${measured[0].rtt}ms)`);
|
|
7032
|
-
return measured[0];
|
|
7033
|
-
}
|
|
7034
|
-
async measureRTT(host, _port) {
|
|
7035
|
-
const start = performance.now();
|
|
7036
|
-
try {
|
|
7037
|
-
await fetch(`https://${host}/health`, {
|
|
7038
|
-
method: "HEAD",
|
|
7039
|
-
signal: AbortSignal.timeout(2e3),
|
|
7040
|
-
mode: "no-cors"
|
|
7041
|
-
});
|
|
7042
|
-
return performance.now() - start;
|
|
7043
|
-
} catch {
|
|
7044
|
-
return Infinity;
|
|
7045
|
-
}
|
|
7046
|
-
}
|
|
7047
|
-
/**
|
|
7048
|
-
* Clear the relay cache
|
|
7049
|
-
*/
|
|
7050
|
-
clearCache() {
|
|
7051
|
-
this.cache.clear();
|
|
7052
|
-
}
|
|
7053
|
-
/**
|
|
7054
|
-
* Get cached relays for a source address
|
|
7055
|
-
*/
|
|
7056
|
-
getCached(source) {
|
|
7057
|
-
return this.cache.get(source);
|
|
7058
|
-
}
|
|
7059
|
-
};
|
|
7060
|
-
var driadDiscovery = new DRIADDiscovery();
|
|
7061
|
-
|
|
7062
7093
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
7063
7094
|
function endpointKey(endpoint) {
|
|
7064
7095
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -7189,8 +7220,8 @@ var AdaptiveBitrateController = class {
|
|
|
7189
7220
|
/**
|
|
7190
7221
|
* Update FEC statistics for ABR decisions
|
|
7191
7222
|
*
|
|
7192
|
-
*
|
|
7193
|
-
*
|
|
7223
|
+
* ABR uses the effective loss rate (after FEC recovery) rather than the
|
|
7224
|
+
* raw transport loss rate.
|
|
7194
7225
|
*
|
|
7195
7226
|
* @param stats - FEC statistics from the FEC decoder
|
|
7196
7227
|
*/
|
|
@@ -7266,6 +7297,45 @@ var AdaptiveBitrateController = class {
|
|
|
7266
7297
|
}
|
|
7267
7298
|
};
|
|
7268
7299
|
|
|
7300
|
+
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
7301
|
+
var MPU_HEADER_SIZE2 = 8;
|
|
7302
|
+
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
7303
|
+
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
7304
|
+
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
7305
|
+
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
7306
|
+
|
|
7307
|
+
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
7308
|
+
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
7309
|
+
|
|
7310
|
+
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
7311
|
+
var NTP_SHORT_BITS2 = 32;
|
|
7312
|
+
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
7313
|
+
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
7314
|
+
function isNtpShort(value) {
|
|
7315
|
+
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
7316
|
+
}
|
|
7317
|
+
function compareNtpShort(a, b) {
|
|
7318
|
+
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
7319
|
+
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
7320
|
+
}
|
|
7321
|
+
if (a === b)
|
|
7322
|
+
return "equal";
|
|
7323
|
+
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
7324
|
+
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
7325
|
+
return "after";
|
|
7326
|
+
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
7327
|
+
return "before";
|
|
7328
|
+
return "unordered";
|
|
7329
|
+
}
|
|
7330
|
+
|
|
7331
|
+
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
7332
|
+
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
7333
|
+
"iso-ssbg1-v1"
|
|
7334
|
+
]);
|
|
7335
|
+
|
|
7336
|
+
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
7337
|
+
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
7338
|
+
|
|
7269
7339
|
// node_modules/@blockcast/mmt-transport/dist/multicast-orchestrator.js
|
|
7270
7340
|
var DEFAULT_DWELL_MS = 3e3;
|
|
7271
7341
|
var DEFAULT_JOIN_DEADLINE_MS = 5e3;
|
|
@@ -7503,8 +7573,23 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
7503
7573
|
consume: "bytes",
|
|
7504
7574
|
...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
|
|
7505
7575
|
};
|
|
7576
|
+
if (input.atsc3) {
|
|
7577
|
+
const { frequency, plpId, serviceId } = input.atsc3;
|
|
7578
|
+
if (!Number.isInteger(frequency) || frequency < 1) {
|
|
7579
|
+
throw new TypeError(`ATSC3 tuning requires a positive integer frequency in kHz, got ${String(frequency)}`);
|
|
7580
|
+
}
|
|
7581
|
+
return {
|
|
7582
|
+
...base,
|
|
7583
|
+
origin: "tuner",
|
|
7584
|
+
standard: "atsc3",
|
|
7585
|
+
frequency,
|
|
7586
|
+
...plpId !== void 0 ? { plpId } : {},
|
|
7587
|
+
...serviceId !== void 0 ? { serviceId } : {}
|
|
7588
|
+
};
|
|
7589
|
+
}
|
|
7506
7590
|
const relay = input.amtRelay?.trim();
|
|
7507
|
-
const
|
|
7591
|
+
const driad = !relay && input.amtDiscovery === "driad";
|
|
7592
|
+
const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
|
|
7508
7593
|
if (!wantsAmt) {
|
|
7509
7594
|
const native = {
|
|
7510
7595
|
...base,
|
|
@@ -7514,6 +7599,20 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
7514
7599
|
return native;
|
|
7515
7600
|
}
|
|
7516
7601
|
const relayPort = input.amtRelayPort;
|
|
7602
|
+
if (driad) {
|
|
7603
|
+
if (!base.source)
|
|
7604
|
+
throw new TypeError("AMT DRIAD discovery requires a source address");
|
|
7605
|
+
if (relayPort !== void 0 && !isPositivePort(relayPort)) {
|
|
7606
|
+
throw new TypeError("AMT DRIAD discovery requires a valid relay port when one is given");
|
|
7607
|
+
}
|
|
7608
|
+
return {
|
|
7609
|
+
...base,
|
|
7610
|
+
source: base.source,
|
|
7611
|
+
origin: "amt",
|
|
7612
|
+
discovery: "driad",
|
|
7613
|
+
...relayPort !== void 0 ? { relayPort } : {}
|
|
7614
|
+
};
|
|
7615
|
+
}
|
|
7517
7616
|
if (!relay || relayPort === void 0 || !isPositivePort(relayPort)) {
|
|
7518
7617
|
throw new TypeError("AMT requires a resolved relay and a valid relay port");
|
|
7519
7618
|
}
|
|
@@ -7557,7 +7656,8 @@ function normalizeMulticastEndpoint(endpoint) {
|
|
|
7557
7656
|
port: endpoint.port,
|
|
7558
7657
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7559
7658
|
...amtRelay ? { amtRelay } : {},
|
|
7560
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7659
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7660
|
+
...endpoint.amtDiscovery === "driad" ? { amtDiscovery: "driad" } : {}
|
|
7561
7661
|
};
|
|
7562
7662
|
}
|
|
7563
7663
|
function multicastEndpointKey(endpoint) {
|
|
@@ -7570,7 +7670,9 @@ function multicastEndpointKey(endpoint) {
|
|
|
7570
7670
|
normalized.port,
|
|
7571
7671
|
normalized.mode ?? "auto",
|
|
7572
7672
|
normalized.amtRelay ?? "",
|
|
7573
|
-
normalized.amtRelayPort ?? ""
|
|
7673
|
+
normalized.amtRelayPort ?? "",
|
|
7674
|
+
// A DRIAD join is a different gateway subscription from a native one.
|
|
7675
|
+
...normalized.amtDiscovery ? [normalized.amtDiscovery] : []
|
|
7574
7676
|
]);
|
|
7575
7677
|
}
|
|
7576
7678
|
function isMulticastTrackPacketId(value) {
|
|
@@ -7610,7 +7712,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7610
7712
|
port: config.port,
|
|
7611
7713
|
mode: config.mode,
|
|
7612
7714
|
amtRelay: config.amtRelay,
|
|
7613
|
-
amtRelayPort: config.amtRelayPort
|
|
7715
|
+
amtRelayPort: config.amtRelayPort,
|
|
7716
|
+
amtDiscovery: config.amtDiscovery
|
|
7614
7717
|
});
|
|
7615
7718
|
if (!endpoint)
|
|
7616
7719
|
throw new Error("Invalid multicast endpoint");
|
|
@@ -7676,7 +7779,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7676
7779
|
port: endpoint.port,
|
|
7677
7780
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
7678
7781
|
...endpoint.amtRelay ? { amtRelay: endpoint.amtRelay } : {},
|
|
7679
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
7782
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
7783
|
+
...endpoint.amtDiscovery ? { amtDiscovery: endpoint.amtDiscovery } : {}
|
|
7680
7784
|
}));
|
|
7681
7785
|
const consumers = /* @__PURE__ */ new Map();
|
|
7682
7786
|
let entry;
|
|
@@ -7756,7 +7860,6 @@ var TransportManager = class {
|
|
|
7756
7860
|
};
|
|
7757
7861
|
capabilities = null;
|
|
7758
7862
|
subscription = null;
|
|
7759
|
-
driad = new DRIADDiscovery();
|
|
7760
7863
|
/** Built by `connect()` from the caller's ladder; there is no built-in one. */
|
|
7761
7864
|
abr = null;
|
|
7762
7865
|
multicastOrchestrator = null;
|
|
@@ -7806,8 +7909,8 @@ var TransportManager = class {
|
|
|
7806
7909
|
nativeIGMP: hasGatewayBytes,
|
|
7807
7910
|
directSockets: typeof win?.UDPSocket !== "undefined",
|
|
7808
7911
|
amt: false,
|
|
7809
|
-
driad:
|
|
7810
|
-
//
|
|
7912
|
+
driad: hasGatewayBytes,
|
|
7913
|
+
// the gateway runs RFC 8777 discovery
|
|
7811
7914
|
fecDecode: false
|
|
7812
7915
|
};
|
|
7813
7916
|
console.log("[Transport] Capabilities:", this.capabilities);
|
|
@@ -7818,7 +7921,7 @@ var TransportManager = class {
|
|
|
7818
7921
|
*
|
|
7819
7922
|
* Promotion hierarchy:
|
|
7820
7923
|
* 1. window.multicast gateway bytes
|
|
7821
|
-
* 2. AMT
|
|
7924
|
+
* 2. AMT: a configured relay via the AMT proxy, else gateway DRIAD discovery
|
|
7822
7925
|
* 3. MOQ WebTransport (final fallback)
|
|
7823
7926
|
*
|
|
7824
7927
|
* The ABR ladder (`abrLadder`) and initial rendition (`initialQuality`)
|
|
@@ -7912,7 +8015,7 @@ var TransportManager = class {
|
|
|
7912
8015
|
/**
|
|
7913
8016
|
* Connect via the lowercase window.multicast bytes gateway.
|
|
7914
8017
|
*/
|
|
7915
|
-
async connectWindowMulticast(config, generation) {
|
|
8018
|
+
async connectWindowMulticast(config, generation, mode = "multicast") {
|
|
7916
8019
|
try {
|
|
7917
8020
|
const gateway = this.getWindowMulticastGateway();
|
|
7918
8021
|
if (typeof gateway?.subscribe !== "function")
|
|
@@ -7947,7 +8050,7 @@ var TransportManager = class {
|
|
|
7947
8050
|
}
|
|
7948
8051
|
};
|
|
7949
8052
|
this.state = {
|
|
7950
|
-
mode
|
|
8053
|
+
mode,
|
|
7951
8054
|
connected: true,
|
|
7952
8055
|
group: config.group,
|
|
7953
8056
|
source: config.source,
|
|
@@ -7965,29 +8068,19 @@ var TransportManager = class {
|
|
|
7965
8068
|
}
|
|
7966
8069
|
}
|
|
7967
8070
|
/**
|
|
7968
|
-
* Connect via AMT proxy
|
|
8071
|
+
* Connect via AMT: a configured relay goes through the AMT proxy; with no
|
|
8072
|
+
* relay, the window.multicast gateway discovers one per RFC 8777 (DRIAD).
|
|
7969
8073
|
*/
|
|
7970
8074
|
async connectAmt(config, generation) {
|
|
7971
8075
|
try {
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
const relays = await this.driad.discoverRelays(config.source);
|
|
7976
|
-
if (generation !== this.connectionGeneration)
|
|
7977
|
-
return false;
|
|
7978
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
7979
|
-
if (generation !== this.connectionGeneration)
|
|
7980
|
-
return false;
|
|
7981
|
-
if (bestRelay) {
|
|
7982
|
-
amtRelay = bestRelay.host;
|
|
7983
|
-
this.state.amtRelay = amtRelay;
|
|
7984
|
-
}
|
|
7985
|
-
}
|
|
7986
|
-
if (!amtRelay) {
|
|
8076
|
+
if (config.amtRelay)
|
|
8077
|
+
return await this.connectAmtProxy(config, config.amtRelay, generation);
|
|
8078
|
+
if (config.driadEnabled === false || !config.source || config.mode === "native") {
|
|
7987
8079
|
console.warn("[Transport] No AMT relay available (DRIAD requires source address for SSM)");
|
|
7988
8080
|
return false;
|
|
7989
8081
|
}
|
|
7990
|
-
|
|
8082
|
+
console.log(`[Transport] Asking the gateway for a DRIAD relay for source ${config.source}...`);
|
|
8083
|
+
return await this.connectWindowMulticast({ ...config, amtDiscovery: "driad" }, generation, "amt");
|
|
7991
8084
|
} catch (error) {
|
|
7992
8085
|
console.warn("[Transport] AMT connection failed:", error);
|
|
7993
8086
|
return false;
|
|
@@ -8125,6 +8218,10 @@ var TransportManager = class {
|
|
|
8125
8218
|
pollMulticastTierSwitch() {
|
|
8126
8219
|
return this.dispatchOrchestratorCommand(this.multicastOrchestrator?.poll());
|
|
8127
8220
|
}
|
|
8221
|
+
/** Abandon the in-flight tier join, e.g. because the host could not join the target. */
|
|
8222
|
+
cancelMulticastTierJoin() {
|
|
8223
|
+
return this.dispatchOrchestratorCommand(this.multicastOrchestrator?.cancel());
|
|
8224
|
+
}
|
|
8128
8225
|
/**
|
|
8129
8226
|
* Set packet callback
|
|
8130
8227
|
*/
|
|
@@ -8214,7 +8311,6 @@ var AMTGatewayManager = class {
|
|
|
8214
8311
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8215
8312
|
messageHandler;
|
|
8216
8313
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
8217
|
-
driad = new DRIADDiscovery();
|
|
8218
8314
|
constructor() {
|
|
8219
8315
|
this.messageHandler = (event) => {
|
|
8220
8316
|
const data = event.data;
|
|
@@ -8245,26 +8341,12 @@ var AMTGatewayManager = class {
|
|
|
8245
8341
|
return keyStr;
|
|
8246
8342
|
}
|
|
8247
8343
|
try {
|
|
8248
|
-
|
|
8249
|
-
let discoveryMethod;
|
|
8344
|
+
const relayAddress = config.relayAddress;
|
|
8250
8345
|
const relayPort = config.relayPort || DEFAULT_AMT_RELAY_PORT2;
|
|
8251
|
-
if (
|
|
8252
|
-
|
|
8253
|
-
discoveryMethod = "manual";
|
|
8254
|
-
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8255
|
-
} else if (key.source) {
|
|
8256
|
-
console.log(`[AMT] No relay configured, discovering via DRIAD for source ${key.source}...`);
|
|
8257
|
-
const relays = await this.driad.discoverRelays(key.source);
|
|
8258
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
8259
|
-
if (!bestRelay) {
|
|
8260
|
-
throw new Error(`AMT relay discovery failed for source ${key.source}. Please specify a relay address in the subscription configuration.`);
|
|
8261
|
-
}
|
|
8262
|
-
relayAddress = bestRelay.host;
|
|
8263
|
-
discoveryMethod = "driad";
|
|
8264
|
-
console.log(`[AMT] Discovered relay via DRIAD: ${relayAddress}:${relayPort}`);
|
|
8265
|
-
} else {
|
|
8266
|
-
throw new Error(`AMT relay discovery requires a source address for SSM (RFC 8777). Please specify either a relay address or source address.`);
|
|
8346
|
+
if (!relayAddress) {
|
|
8347
|
+
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".`);
|
|
8267
8348
|
}
|
|
8349
|
+
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
8268
8350
|
const subscriptionId = keyStr;
|
|
8269
8351
|
this.pendingPackets.set(subscriptionId, []);
|
|
8270
8352
|
const subscription = {
|
|
@@ -8275,7 +8357,7 @@ var AMTGatewayManager = class {
|
|
|
8275
8357
|
relay: {
|
|
8276
8358
|
address: relayAddress,
|
|
8277
8359
|
port: relayPort,
|
|
8278
|
-
discoveryMethod,
|
|
8360
|
+
discoveryMethod: "manual",
|
|
8279
8361
|
discoveredAt: Date.now()
|
|
8280
8362
|
}
|
|
8281
8363
|
};
|
|
@@ -8750,25 +8832,20 @@ function multicastFromConfig(input) {
|
|
|
8750
8832
|
);
|
|
8751
8833
|
}
|
|
8752
8834
|
}
|
|
8753
|
-
const
|
|
8754
|
-
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx, seenTuples));
|
|
8835
|
+
const endpoints = input.endpoints.map((ep, idx) => validateEndpoint2(ep, idx));
|
|
8755
8836
|
const out = { endpoints };
|
|
8756
8837
|
const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
|
|
8757
8838
|
networkSource.forEach(validateNetworkSourceEntry);
|
|
8758
8839
|
if (networkSource.length > 0) out.networkSource = networkSource;
|
|
8759
8840
|
const amtRelays = new Set(
|
|
8760
|
-
networkSource.flatMap((s) => s.type === "amt" && s.
|
|
8841
|
+
networkSource.flatMap((s) => s.type === "amt" && s.relay?.trim() ? [s.relay.trim()] : []).slice(0, 1)
|
|
8761
8842
|
);
|
|
8762
8843
|
input.endpoints.forEach((ep, idx) => {
|
|
8763
8844
|
const relay = ep.relayAddress?.trim();
|
|
8764
8845
|
if (!relay || amtRelays.has(relay)) return;
|
|
8765
|
-
const demoted = networkSource.some(
|
|
8766
|
-
(s) => s.type === "amt" && s.discovery === "driad" && s.relay?.trim() === relay
|
|
8767
|
-
);
|
|
8768
8846
|
const shadowed = networkSource.some(
|
|
8769
|
-
(s) => s.type === "amt" && s.
|
|
8847
|
+
(s) => s.type === "amt" && s.relay?.trim() === relay
|
|
8770
8848
|
);
|
|
8771
|
-
const derived = input.networkSource === void 0;
|
|
8772
8849
|
const fromAmtFallback = ", derived from amtFallback/MOQCAST_MULTICAST_AMT_*";
|
|
8773
8850
|
const fromRelay = relayFrom === "amtFallback.relayDns" ? fromAmtFallback : relayFrom === "endpoint.relayAddress" ? ", derived from the endpoint relayAddress values" : "";
|
|
8774
8851
|
const relayDns = input.amtFallback?.relayDns?.trim();
|
|
@@ -8776,7 +8853,7 @@ function multicastFromConfig(input) {
|
|
|
8776
8853
|
throw new MulticastInputError(
|
|
8777
8854
|
"conflicting_amt_relay",
|
|
8778
8855
|
idx,
|
|
8779
|
-
`endpoint[${idx}] relayAddress ${JSON.stringify(relay)} ` + (
|
|
8856
|
+
`endpoint[${idx}] relayAddress ${JSON.stringify(relay)} ` + (shadowed ? `is carried by a multicast.networkSource AMT entry that is not the first one: both readers join the first AMT entry (${[...amtRelays].join(", ")}) and ignore the rest, so this relay is never joined; keep a single AMT entry, or put this one first` : `is not the relay of any multicast.networkSource AMT entry (${[...amtRelays].join(", ") || "none"})${fromRelay}; ` + (outranked ? `amtFallback.relayDns/MOQCAST_MULTICAST_AMT_RELAY_DNS (${relayDns}) outranks an endpoint relay when networkSource is derived -- drop one, or make them agree` : "networkSource is catalog-level and cannot represent per-endpoint relays"))
|
|
8780
8857
|
);
|
|
8781
8858
|
});
|
|
8782
8859
|
input.endpoints.forEach((ep, idx) => {
|
|
@@ -8785,9 +8862,20 @@ function multicastFromConfig(input) {
|
|
|
8785
8862
|
throw new MulticastInputError(
|
|
8786
8863
|
ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
|
|
8787
8864
|
idx,
|
|
8788
|
-
`endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying
|
|
8865
|
+
`endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying at least its frequency (kHz) \u2014 an ATSC3 endpoint is not tunable without it" : "")
|
|
8789
8866
|
);
|
|
8790
8867
|
});
|
|
8868
|
+
input.endpoints.forEach((ep, idx) => {
|
|
8869
|
+
if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
|
|
8870
|
+
endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
|
|
8871
|
+
});
|
|
8872
|
+
if (input.auth !== void 0) out.auth = input.auth;
|
|
8873
|
+
const [issue] = multicastCatalogIssues({ multicast: out });
|
|
8874
|
+
if (issue) {
|
|
8875
|
+
const kind = issue.code === "multicast_auth" ? "invalid_multicast_auth" : issue.code === "multicast_endpoint_auth" ? "invalid_endpoint_auth" : issue.path.endsWith(".port") ? "duplicate_endpoint_tuple" : "protocol_source_mismatch";
|
|
8876
|
+
const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
|
|
8877
|
+
throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
|
|
8878
|
+
}
|
|
8791
8879
|
if (input.enabled !== void 0) out.enabled = input.enabled;
|
|
8792
8880
|
if (input.version !== void 0) out.version = input.version;
|
|
8793
8881
|
if (input.validUntil !== void 0) out.validUntil = input.validUntil;
|
|
@@ -8799,10 +8887,10 @@ function resolveNetworkSource(input) {
|
|
|
8799
8887
|
}
|
|
8800
8888
|
const relayDns = input.amtFallback?.relayDns?.trim();
|
|
8801
8889
|
const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
|
|
8802
|
-
const discovery = input.amtFallback?.discovery
|
|
8803
|
-
if (discovery === void 0) return { entries: [], relayFrom: null };
|
|
8890
|
+
const discovery = input.amtFallback?.discovery;
|
|
8891
|
+
if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
|
|
8804
8892
|
return {
|
|
8805
|
-
entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
|
|
8893
|
+
entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
|
|
8806
8894
|
relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
|
|
8807
8895
|
};
|
|
8808
8896
|
}
|
|
@@ -8815,8 +8903,11 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8815
8903
|
const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
|
|
8816
8904
|
if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
|
|
8817
8905
|
if (s.type === "amt") {
|
|
8818
|
-
if (s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8819
|
-
throw err(
|
|
8906
|
+
if (s.discovery !== void 0 && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
|
|
8907
|
+
throw err(
|
|
8908
|
+
"invalid_amt_discovery",
|
|
8909
|
+
`discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`
|
|
8910
|
+
);
|
|
8820
8911
|
}
|
|
8821
8912
|
if (s.relay !== void 0) {
|
|
8822
8913
|
const relay = typeof s.relay === "string" ? s.relay.trim() : "";
|
|
@@ -8825,8 +8916,14 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8825
8916
|
}
|
|
8826
8917
|
s.relay = relay;
|
|
8827
8918
|
}
|
|
8828
|
-
if (s.discovery === "manual" && s.relay === void 0) {
|
|
8829
|
-
throw err("amt_requires_relay", `discovery="
|
|
8919
|
+
if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === void 0) {
|
|
8920
|
+
throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
|
|
8921
|
+
}
|
|
8922
|
+
if (s.discovery === "driad" && s.relay !== void 0) {
|
|
8923
|
+
throw err(
|
|
8924
|
+
"invalid_network_source",
|
|
8925
|
+
`discovery="driad" must omit relay: DRIAD supplies the relay candidates (draft -01 4.2.1); drop the relay (amtFallback.relayDns / endpoint relayAddress on the derived path), or use "dns" or "manual"`
|
|
8926
|
+
);
|
|
8830
8927
|
}
|
|
8831
8928
|
if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
|
|
8832
8929
|
throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
|
|
@@ -8835,13 +8932,15 @@ function validateNetworkSourceEntry(s, i) {
|
|
|
8835
8932
|
}
|
|
8836
8933
|
const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
|
|
8837
8934
|
if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
|
|
8838
|
-
throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
|
|
8935
|
+
throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
|
|
8936
|
+
}
|
|
8937
|
+
if (s.plpId !== void 0 && !inRange(s.plpId, 0, 63)) {
|
|
8938
|
+
throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
|
|
8839
8939
|
}
|
|
8840
|
-
if (!inRange(s.
|
|
8841
|
-
if (!inRange(s.serviceId, 0, 65535)) {
|
|
8940
|
+
if (s.serviceId !== void 0 && !inRange(s.serviceId, 0, 65535)) {
|
|
8842
8941
|
throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
|
|
8843
8942
|
}
|
|
8844
|
-
if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
|
|
8943
|
+
if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
|
|
8845
8944
|
throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
|
|
8846
8945
|
}
|
|
8847
8946
|
}
|
|
@@ -8853,7 +8952,7 @@ function isAbsoluteUri(value) {
|
|
|
8853
8952
|
return false;
|
|
8854
8953
|
}
|
|
8855
8954
|
}
|
|
8856
|
-
function validateEndpoint2(ep, idx
|
|
8955
|
+
function validateEndpoint2(ep, idx) {
|
|
8857
8956
|
if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
|
|
8858
8957
|
throw new MulticastInputError(
|
|
8859
8958
|
"ssm_requires_source",
|
|
@@ -8861,6 +8960,13 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8861
8960
|
`endpoint[${idx}] protocol=ssm requires sourceAddress`
|
|
8862
8961
|
);
|
|
8863
8962
|
}
|
|
8963
|
+
if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
|
|
8964
|
+
throw new MulticastInputError(
|
|
8965
|
+
"protocol_source_mismatch",
|
|
8966
|
+
idx,
|
|
8967
|
+
`endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
|
|
8968
|
+
);
|
|
8969
|
+
}
|
|
8864
8970
|
if (!isMulticastGroupAddress(ep.groupAddress)) {
|
|
8865
8971
|
throw new MulticastInputError(
|
|
8866
8972
|
"invalid_group_address",
|
|
@@ -8920,23 +9026,15 @@ function validateEndpoint2(ep, idx, seenTuples) {
|
|
|
8920
9026
|
`endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
|
|
8921
9027
|
);
|
|
8922
9028
|
}
|
|
8923
|
-
const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
|
|
8924
|
-
if (seenTuples.has(tupleKey)) {
|
|
8925
|
-
throw new MulticastInputError(
|
|
8926
|
-
"duplicate_endpoint_tuple",
|
|
8927
|
-
idx,
|
|
8928
|
-
`endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
|
|
8929
|
-
);
|
|
8930
|
-
}
|
|
8931
|
-
seenTuples.add(tupleKey);
|
|
8932
9029
|
const out = {
|
|
8933
|
-
protocol: ep.
|
|
9030
|
+
protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
|
|
8934
9031
|
groupAddress: ep.groupAddress,
|
|
8935
9032
|
port: ep.port,
|
|
8936
9033
|
tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
|
|
8937
9034
|
};
|
|
8938
9035
|
if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
|
|
8939
9036
|
if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
|
|
9037
|
+
if (ep.auth !== void 0) out.auth = { ...ep.auth };
|
|
8940
9038
|
return out;
|
|
8941
9039
|
}
|
|
8942
9040
|
function isMulticastGroupAddress(addr) {
|
|
@@ -8979,9 +9077,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
|
|
|
8979
9077
|
endpoints,
|
|
8980
9078
|
...hasCatalogAmt ? {
|
|
8981
9079
|
amtFallback: {
|
|
8982
|
-
//
|
|
8983
|
-
//
|
|
8984
|
-
discovery: amtDiscovery
|
|
9080
|
+
// No default: an omitted discovery with a relay hostname is
|
|
9081
|
+
// "dns" (draft-ramadan-moq-multicast-01 4.2.1).
|
|
9082
|
+
...amtDiscovery ? { discovery: amtDiscovery } : {},
|
|
8985
9083
|
...amtRelayDns ? { relayDns: amtRelayDns } : {}
|
|
8986
9084
|
}
|
|
8987
9085
|
} : {}
|
|
@@ -9149,7 +9247,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9149
9247
|
if (ot.role !== void 0 && existing.role === void 0) existing.role = ot.role;
|
|
9150
9248
|
if (existing.packaging === "mmtp") {
|
|
9151
9249
|
const mode = existing.mmtpMode ?? ot.mmtpMode;
|
|
9152
|
-
if (mode !== "
|
|
9250
|
+
if (mode !== "mfu") {
|
|
9153
9251
|
throw new Error(
|
|
9154
9252
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9155
9253
|
);
|
|
@@ -9186,7 +9284,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
|
|
|
9186
9284
|
);
|
|
9187
9285
|
}
|
|
9188
9286
|
const mmtpMode = ot.mmtpMode;
|
|
9189
|
-
if (packaging === "mmtp" && mmtpMode !== "
|
|
9287
|
+
if (packaging === "mmtp" && mmtpMode !== "mfu") {
|
|
9190
9288
|
throw new Error(
|
|
9191
9289
|
`[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
|
|
9192
9290
|
);
|
|
@@ -9487,8 +9585,8 @@ function u32(v) {
|
|
|
9487
9585
|
}
|
|
9488
9586
|
var KEYFRAME_FLAGS = 33554432;
|
|
9489
9587
|
var DELTA_FLAGS = 16842752;
|
|
9490
|
-
var
|
|
9491
|
-
var MAX_TRACK_ID =
|
|
9588
|
+
var UINT32_MAX2 = 4294967295;
|
|
9589
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
9492
9590
|
var INT32_MIN = -2147483648;
|
|
9493
9591
|
var INT32_MAX = 2147483647;
|
|
9494
9592
|
function assertTrackId(trackId, label) {
|
|
@@ -9497,8 +9595,8 @@ function assertTrackId(trackId, label) {
|
|
|
9497
9595
|
}
|
|
9498
9596
|
}
|
|
9499
9597
|
function assertTimescale(timescale, label) {
|
|
9500
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
9501
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
9598
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
9599
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
9502
9600
|
}
|
|
9503
9601
|
}
|
|
9504
9602
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -12331,16 +12429,6 @@ var DeliveryGapEstimator = class {
|
|
|
12331
12429
|
|
|
12332
12430
|
// src/iso-block-locator.ts
|
|
12333
12431
|
var IsoBlockLocator = class _IsoBlockLocator {
|
|
12334
|
-
/** Known blocks and spans, in serial order of their start. */
|
|
12335
|
-
#blocks = [];
|
|
12336
|
-
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12337
|
-
#held = /* @__PURE__ */ new Map();
|
|
12338
|
-
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12339
|
-
#coverageEnd;
|
|
12340
|
-
#kMax;
|
|
12341
|
-
#retentionBlocks;
|
|
12342
|
-
#heldEvicted = 0;
|
|
12343
|
-
#newest;
|
|
12344
12432
|
/**
|
|
12345
12433
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
12346
12434
|
* @param retentionBlocks how many blocks behind the newest position the
|
|
@@ -12348,12 +12436,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12348
12436
|
* no locator exists without retention.
|
|
12349
12437
|
*/
|
|
12350
12438
|
constructor(kMax, retentionBlocks) {
|
|
12439
|
+
/** Known blocks and spans, in serial order of their start. */
|
|
12440
|
+
this.#blocks = [];
|
|
12441
|
+
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
12442
|
+
this.#held = /* @__PURE__ */ new Map();
|
|
12443
|
+
this.#heldEvicted = 0;
|
|
12444
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
12445
|
+
this.#holes = [];
|
|
12446
|
+
/**
|
|
12447
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
12448
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
12449
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
12450
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
12451
|
+
*/
|
|
12452
|
+
this.deferIncompleteGaps = false;
|
|
12351
12453
|
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
12352
12454
|
throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
|
|
12353
12455
|
}
|
|
12354
12456
|
this.#kMax = kMax;
|
|
12355
12457
|
this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
|
|
12356
12458
|
}
|
|
12459
|
+
#blocks;
|
|
12460
|
+
#held;
|
|
12461
|
+
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
12462
|
+
#coverageEnd;
|
|
12463
|
+
#kMax;
|
|
12464
|
+
#retentionBlocks;
|
|
12465
|
+
#heldEvicted;
|
|
12466
|
+
#newest;
|
|
12467
|
+
#holes;
|
|
12357
12468
|
static #checkedRetention(retentionBlocks) {
|
|
12358
12469
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
12359
12470
|
throw new Error(
|
|
@@ -12416,6 +12527,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12416
12527
|
}
|
|
12417
12528
|
return null;
|
|
12418
12529
|
}
|
|
12530
|
+
/** Number of pending holes. */
|
|
12531
|
+
get holeCount() {
|
|
12532
|
+
return this.#holes.length;
|
|
12533
|
+
}
|
|
12534
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
12535
|
+
blockEndingAt(end) {
|
|
12536
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
|
|
12537
|
+
}
|
|
12419
12538
|
/** The known block or span starting exactly at `start`. */
|
|
12420
12539
|
blockAt(start) {
|
|
12421
12540
|
return this.#blocks.find((block) => block.start === start);
|
|
@@ -12438,6 +12557,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12438
12557
|
coversBetween(a, b) {
|
|
12439
12558
|
if (this.#coverageEnd === void 0) return false;
|
|
12440
12559
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
|
|
12560
|
+
const first = a + 1 >>> 0;
|
|
12561
|
+
const count = serial32Distance(a, b) - 1;
|
|
12562
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
|
|
12441
12563
|
return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
|
|
12442
12564
|
}
|
|
12443
12565
|
/**
|
|
@@ -12485,6 +12607,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12485
12607
|
}
|
|
12486
12608
|
return { status: "placed", block: known, placed: [] };
|
|
12487
12609
|
}
|
|
12610
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
|
|
12611
|
+
if (pending !== void 0) {
|
|
12612
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
12613
|
+
return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
|
|
12614
|
+
}
|
|
12615
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1);
|
|
12616
|
+
const before = serial32Distance(pending.start, start);
|
|
12617
|
+
const afterStart = isoBlockEnd(start, length);
|
|
12618
|
+
const after = pending.length - before - length;
|
|
12619
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
|
|
12620
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
|
|
12621
|
+
const block2 = { start, length, span: false };
|
|
12622
|
+
const placed2 = this.#claim(block2);
|
|
12623
|
+
this.#blocks.push(block2);
|
|
12624
|
+
return { status: "placed", block: block2, placed: placed2 };
|
|
12625
|
+
}
|
|
12488
12626
|
for (const block2 of this.#blocks) {
|
|
12489
12627
|
if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
|
|
12490
12628
|
return {
|
|
@@ -12494,6 +12632,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12494
12632
|
}
|
|
12495
12633
|
}
|
|
12496
12634
|
let span;
|
|
12635
|
+
let hole;
|
|
12497
12636
|
if (this.#coverageEnd === void 0) {
|
|
12498
12637
|
for (const ssId of this.#held.keys()) {
|
|
12499
12638
|
if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
|
|
@@ -12502,21 +12641,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12502
12641
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
12503
12642
|
return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
|
|
12504
12643
|
} else if (start !== this.#coverageEnd) {
|
|
12505
|
-
const
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
span:
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12644
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
|
|
12645
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
|
|
12646
|
+
if (lostSsId !== void 0) {
|
|
12647
|
+
const holeBlock = { ...gap, span: false };
|
|
12648
|
+
this.#holes.push(holeBlock);
|
|
12649
|
+
hole = { block: holeBlock, lostSsId };
|
|
12650
|
+
} else {
|
|
12651
|
+
const spanBlock = { ...gap, span: true };
|
|
12652
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) };
|
|
12653
|
+
this.#blocks.push(spanBlock);
|
|
12654
|
+
}
|
|
12512
12655
|
}
|
|
12513
12656
|
const block = { start, length, span: false };
|
|
12514
12657
|
const placed = this.#claim(block);
|
|
12515
12658
|
this.#blocks.push(block);
|
|
12516
12659
|
this.#coverageEnd = isoBlockEnd(start, length);
|
|
12517
12660
|
this.retireBehind(start);
|
|
12661
|
+
if (hole !== void 0) return { status: "placed", block, placed, hole };
|
|
12518
12662
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
12519
12663
|
}
|
|
12664
|
+
/**
|
|
12665
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
12666
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
12667
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
12668
|
+
*/
|
|
12669
|
+
closeHolesWithin(start, length) {
|
|
12670
|
+
const closed = [];
|
|
12671
|
+
for (const hole of [...this.#holes]) {
|
|
12672
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
12673
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1);
|
|
12674
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
12675
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
12676
|
+
this.#blocks.push(spanBlock);
|
|
12677
|
+
}
|
|
12678
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
12679
|
+
}
|
|
12680
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
12681
|
+
#highestMissing(start, length) {
|
|
12682
|
+
const steps = Math.min(length, this.#held.size + 1);
|
|
12683
|
+
for (let i = 1; i <= steps; i++) {
|
|
12684
|
+
const ssId = serial32Add(start, length - i);
|
|
12685
|
+
if (!this.#held.has(ssId)) return ssId;
|
|
12686
|
+
}
|
|
12687
|
+
return void 0;
|
|
12688
|
+
}
|
|
12520
12689
|
/**
|
|
12521
12690
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
12522
12691
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -12535,6 +12704,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12535
12704
|
this.#blocks.splice(i, 1);
|
|
12536
12705
|
}
|
|
12537
12706
|
}
|
|
12707
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
12708
|
+
const hole = this.#holes[i];
|
|
12709
|
+
const last = serial32Add(hole.start, hole.length - 1);
|
|
12710
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
|
|
12711
|
+
}
|
|
12538
12712
|
for (const ssId of [...this.#held.keys()]) {
|
|
12539
12713
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
|
|
12540
12714
|
}
|
|
@@ -12543,6 +12717,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12543
12717
|
/** Forget everything (publisher restart, track reset). */
|
|
12544
12718
|
reset() {
|
|
12545
12719
|
this.#blocks.length = 0;
|
|
12720
|
+
this.#holes.length = 0;
|
|
12546
12721
|
this.#held.clear();
|
|
12547
12722
|
this.#coverageEnd = void 0;
|
|
12548
12723
|
this.#newest = void 0;
|
|
@@ -12558,6 +12733,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12558
12733
|
return placed;
|
|
12559
12734
|
}
|
|
12560
12735
|
};
|
|
12736
|
+
function isoRangesOverlap(aStart, aLength, bStart, bLength) {
|
|
12737
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
|
|
12738
|
+
}
|
|
12561
12739
|
|
|
12562
12740
|
// src/fec-state.ts
|
|
12563
12741
|
var MIN_INTERLEAVE_DEPTH_MS = 1;
|
|
@@ -12572,22 +12750,16 @@ var INACTIVE = Object.freeze({
|
|
|
12572
12750
|
"reliable-moq": Object.freeze({ state: "inactive", reason: "reliable-moq" }),
|
|
12573
12751
|
"no-multicast-bridge": Object.freeze({ state: "inactive", reason: "no-multicast-bridge" })
|
|
12574
12752
|
});
|
|
12575
|
-
function
|
|
12753
|
+
function recordOf2(value) {
|
|
12576
12754
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
12577
12755
|
}
|
|
12578
|
-
function
|
|
12756
|
+
function isPositiveSafeInteger2(value) {
|
|
12579
12757
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
12580
12758
|
}
|
|
12581
12759
|
function catalogDeclaresFec(fec) {
|
|
12582
|
-
const block =
|
|
12583
|
-
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
12584
|
-
return
|
|
12585
|
-
}
|
|
12586
|
-
function isoBlockSpanUsable(fec) {
|
|
12587
|
-
const block = recordOf(fec);
|
|
12588
|
-
if (block === void 0 || block["blockProfile"] !== "iso-ssbg1-v1") return true;
|
|
12589
|
-
const ms = block["interleaveDepthMs"];
|
|
12590
|
-
return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
|
|
12760
|
+
const block = recordOf2(fec);
|
|
12761
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"])) return false;
|
|
12762
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
12591
12763
|
}
|
|
12592
12764
|
function requireBoolean(value, field) {
|
|
12593
12765
|
if (typeof value !== "boolean") {
|
|
@@ -12603,7 +12775,7 @@ function resolveFecState(evidence) {
|
|
|
12603
12775
|
if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
|
|
12604
12776
|
throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
|
|
12605
12777
|
}
|
|
12606
|
-
if (stats !== null && stats !== void 0 &&
|
|
12778
|
+
if (stats !== null && stats !== void 0 && recordOf2(stats) === void 0) {
|
|
12607
12779
|
throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
|
|
12608
12780
|
}
|
|
12609
12781
|
if (!catalogFec) return INACTIVE["no-catalog-fec"];
|
|
@@ -13074,6 +13246,7 @@ function decideGap(input) {
|
|
|
13074
13246
|
}
|
|
13075
13247
|
|
|
13076
13248
|
// src/fec-manager.ts
|
|
13249
|
+
var RS_MAX_BLOCK_SYMBOLS = 255;
|
|
13077
13250
|
var WORKER_ERROR_LOG_CAP = 5;
|
|
13078
13251
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13079
13252
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
@@ -13188,6 +13361,11 @@ var FECManager = class _FECManager {
|
|
|
13188
13361
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
13189
13362
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
13190
13363
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
13364
|
+
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
13365
|
+
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
13366
|
+
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
13367
|
+
this.#fecFailClosed = /* @__PURE__ */ new Map();
|
|
13368
|
+
this.#onFecFailClosed = null;
|
|
13191
13369
|
// Blocks already recovered — prevents late source symbols from restarting timeouts.
|
|
13192
13370
|
// WASM removes blocks after recovery; late symbols create empty blocks returning null,
|
|
13193
13371
|
// which would falsely start new timeouts without this guard.
|
|
@@ -13308,12 +13486,17 @@ var FECManager = class _FECManager {
|
|
|
13308
13486
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
13309
13487
|
// arithmetic and never throws at all.
|
|
13310
13488
|
this.#orderedHorizonWarnedFor = /* @__PURE__ */ new Set();
|
|
13311
|
-
// Newest block start (SS_Start)
|
|
13312
|
-
//
|
|
13489
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
13490
|
+
// frontier isoSpanResolution reads.
|
|
13313
13491
|
this.#highestSbn = /* @__PURE__ */ new Map();
|
|
13492
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
13493
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
13494
|
+
// blocks ahead of the media they protect.
|
|
13495
|
+
this.#sourceFrontiers = /* @__PURE__ */ new Map();
|
|
13314
13496
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
13315
13497
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
13316
13498
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
13499
|
+
this.#deferIsoGaps = false;
|
|
13317
13500
|
this.#isoRepairRefusedCount = 0;
|
|
13318
13501
|
this.#isoSourceOversizeCount = 0;
|
|
13319
13502
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -13328,8 +13511,8 @@ var FECManager = class _FECManager {
|
|
|
13328
13511
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
13329
13512
|
this.#isoDecoderUnplacedRetireFailed = 0;
|
|
13330
13513
|
// The latest source symbol per stream that carried its MMTP
|
|
13331
|
-
// packet_sequence_number: the anchor that bounds how
|
|
13332
|
-
// producer can have
|
|
13514
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
13515
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
13333
13516
|
this.#sourceAnchors = /* @__PURE__ */ new Map();
|
|
13334
13517
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
13335
13518
|
this.#packetEpochs = /* @__PURE__ */ new Map();
|
|
@@ -13388,6 +13571,14 @@ var FECManager = class _FECManager {
|
|
|
13388
13571
|
this.onBlockReclassified = null;
|
|
13389
13572
|
/** A video stream's classifier mode was established or changed. */
|
|
13390
13573
|
this.onClassifierMode = null;
|
|
13574
|
+
/**
|
|
13575
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
13576
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
13577
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
13578
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
13579
|
+
* for it, which it must be.
|
|
13580
|
+
*/
|
|
13581
|
+
this.#onUndelimitedLoss = null;
|
|
13391
13582
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
13392
13583
|
this.onBlockVanished = null;
|
|
13393
13584
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
@@ -13429,6 +13620,9 @@ var FECManager = class _FECManager {
|
|
|
13429
13620
|
#ssbLengthConflictCount;
|
|
13430
13621
|
#blockRepairRsIds;
|
|
13431
13622
|
#blockRsbLengths;
|
|
13623
|
+
#heldLayerStates;
|
|
13624
|
+
#fecFailClosed;
|
|
13625
|
+
#onFecFailClosed;
|
|
13432
13626
|
#completedBlocks;
|
|
13433
13627
|
#terminalExpiryMs;
|
|
13434
13628
|
#terminalQueues;
|
|
@@ -13467,7 +13661,9 @@ var FECManager = class _FECManager {
|
|
|
13467
13661
|
#materializedBlocks;
|
|
13468
13662
|
#orderedHorizonWarnedFor;
|
|
13469
13663
|
#highestSbn;
|
|
13664
|
+
#sourceFrontiers;
|
|
13470
13665
|
#isoLocators;
|
|
13666
|
+
#deferIsoGaps;
|
|
13471
13667
|
#isoRepairRefusedCount;
|
|
13472
13668
|
#isoSourceOversizeCount;
|
|
13473
13669
|
#isoHeldEvictedCount;
|
|
@@ -13481,6 +13677,7 @@ var FECManager = class _FECManager {
|
|
|
13481
13677
|
#workerErrorCounts;
|
|
13482
13678
|
#decoderUnavailableEvents;
|
|
13483
13679
|
#repairSymbolSizeMismatchCount;
|
|
13680
|
+
#onUndelimitedLoss;
|
|
13484
13681
|
#encodeTrackName(catalogTrackName) {
|
|
13485
13682
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
13486
13683
|
if (encoded === void 0) {
|
|
@@ -14057,8 +14254,8 @@ var FECManager = class _FECManager {
|
|
|
14057
14254
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
14058
14255
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
14059
14256
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
14060
|
-
// many blocks a stream can
|
|
14061
|
-
//
|
|
14257
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
14258
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
14062
14259
|
// The extra block of retention is slack for a block still being fed; a block
|
|
14063
14260
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
14064
14261
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -14068,55 +14265,72 @@ var FECManager = class _FECManager {
|
|
|
14068
14265
|
}
|
|
14069
14266
|
/**
|
|
14070
14267
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
14071
|
-
* advance the stream's
|
|
14268
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
14072
14269
|
*
|
|
14073
|
-
* A SOURCE symbol
|
|
14074
|
-
*
|
|
14075
|
-
*
|
|
14270
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
14271
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
14272
|
+
* block goes back further than the blocks this manager retains, or that
|
|
14273
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
14274
|
+
* further than the stream could have produced since its last symbol, is a
|
|
14275
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
14076
14276
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
14077
14277
|
* signals a discontinuity.
|
|
14078
14278
|
*
|
|
14079
14279
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
14080
14280
|
* source symbols filled it, so one interleave span can start several blocks
|
|
14081
|
-
* (every large keyframe does). What bounds a
|
|
14082
|
-
*
|
|
14083
|
-
*
|
|
14084
|
-
*
|
|
14085
|
-
* packet_sequence_number
|
|
14086
|
-
*
|
|
14087
|
-
*
|
|
14281
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
14282
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
14283
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
14284
|
+
* packet of the packet_id, so with both source symbols'
|
|
14285
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
14286
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
14287
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
14288
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
14289
|
+
* known.
|
|
14088
14290
|
*
|
|
14089
14291
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
14090
14292
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
14091
14293
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
14092
14294
|
*/
|
|
14093
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber) {
|
|
14295
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
14094
14296
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
14095
14297
|
const now = performance.now();
|
|
14096
|
-
const previous = this.#highestSbn.get(streamKey);
|
|
14298
|
+
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
14097
14299
|
const anchor = this.#sourceAnchors.get(streamKey);
|
|
14098
14300
|
const psn = symbol === "source" && packetSequenceNumber !== void 0 && Number.isSafeInteger(packetSequenceNumber) && packetSequenceNumber >= 0 && packetSequenceNumber <= 4294967295 ? packetSequenceNumber : void 0;
|
|
14099
14301
|
const anchorHere = () => {
|
|
14100
|
-
if (psn !== void 0 && (anchor === void 0 || !
|
|
14101
|
-
this.#sourceAnchors.set(streamKey, {
|
|
14302
|
+
if (psn !== void 0 && (anchor === void 0 || !serial32Precedes(ssId, anchor.ssId))) {
|
|
14303
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
14304
|
+
}
|
|
14305
|
+
};
|
|
14306
|
+
const advance = () => {
|
|
14307
|
+
const highest = this.#highestSbn.get(streamKey);
|
|
14308
|
+
if (highest === void 0 || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
14309
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14102
14310
|
}
|
|
14311
|
+
if (symbol === "source") this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14312
|
+
anchorHere();
|
|
14103
14313
|
};
|
|
14104
14314
|
const discontinuity = () => {
|
|
14105
14315
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
14106
14316
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14317
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14107
14318
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
14108
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
14319
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
14109
14320
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName);
|
|
14110
14321
|
};
|
|
14111
14322
|
if (previous === void 0) {
|
|
14112
|
-
|
|
14113
|
-
anchorHere();
|
|
14323
|
+
advance();
|
|
14114
14324
|
return;
|
|
14115
14325
|
}
|
|
14116
14326
|
const config = this.#trackConfig(packetId);
|
|
14117
14327
|
const window2 = this.#liveWindowBlocks(config);
|
|
14328
|
+
const sentInOrder = (from, to) => {
|
|
14329
|
+
const sent = to.psn - from.psn >>> 0;
|
|
14330
|
+
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
14331
|
+
};
|
|
14118
14332
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
14119
|
-
if (symbol === "source" && window2 !== null && this.#blocksBehind(sbn, previous.sbn, packetId) >
|
|
14333
|
+
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))) {
|
|
14120
14334
|
discontinuity();
|
|
14121
14335
|
return;
|
|
14122
14336
|
}
|
|
@@ -14126,9 +14340,8 @@ var FECManager = class _FECManager {
|
|
|
14126
14340
|
const missing = this.#blocksBehind(previous.sbn, sbn, packetId) - 1;
|
|
14127
14341
|
let plausible = true;
|
|
14128
14342
|
if (window2 !== null) {
|
|
14129
|
-
if (psn !== void 0 && anchor !== void 0 &&
|
|
14130
|
-
|
|
14131
|
-
plausible = sent <= 2147483647 && serial32Distance(anchor.sbn, sbn) <= sent + config.k;
|
|
14343
|
+
if (psn !== void 0 && anchor !== void 0 && serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
14344
|
+
plausible = sentInOrder(anchor, { ssId, psn });
|
|
14132
14345
|
} else {
|
|
14133
14346
|
plausible = missing <= window2 + Math.ceil((now - previous.atMs) / config.interleaveDepthMs);
|
|
14134
14347
|
}
|
|
@@ -14138,8 +14351,7 @@ var FECManager = class _FECManager {
|
|
|
14138
14351
|
discontinuity();
|
|
14139
14352
|
return;
|
|
14140
14353
|
}
|
|
14141
|
-
|
|
14142
|
-
anchorHere();
|
|
14354
|
+
advance();
|
|
14143
14355
|
}
|
|
14144
14356
|
/*
|
|
14145
14357
|
* Block order for one stream (BLO-35597 iso:5). A block is keyed by its
|
|
@@ -14456,8 +14668,10 @@ var FECManager = class _FECManager {
|
|
|
14456
14668
|
);
|
|
14457
14669
|
}
|
|
14458
14670
|
const hasCatalogTiming = _FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs });
|
|
14671
|
+
const algorithm = config.algorithm ?? previous.algorithm;
|
|
14459
14672
|
const next = {
|
|
14460
14673
|
blockProfile,
|
|
14674
|
+
...algorithm === void 0 ? {} : { algorithm },
|
|
14461
14675
|
k,
|
|
14462
14676
|
symbolSize: config.symbolSize != null && config.symbolSize > 0 ? config.symbolSize : previousTrack?.symbolSize ?? 0,
|
|
14463
14677
|
interleaveDepthMs: ownInterleaveDepthMs,
|
|
@@ -14465,8 +14679,19 @@ var FECManager = class _FECManager {
|
|
|
14465
14679
|
timeoutMs: config.timeoutMs ?? (timingChanged ? 0 : previous.timeoutMs ?? 0),
|
|
14466
14680
|
...(config.trackKind ?? previous.trackKind) === void 0 ? {} : { trackKind: config.trackKind ?? previous.trackKind },
|
|
14467
14681
|
...(config.codec ?? previous.codec) === void 0 ? {} : { codec: config.codec ?? previous.codec },
|
|
14468
|
-
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry }
|
|
14682
|
+
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry },
|
|
14683
|
+
...(config.repairLayers ?? previous.repairLayers) === void 0 ? {} : { repairLayers: config.repairLayers ?? previous.repairLayers },
|
|
14684
|
+
...(config.heldLayers ?? previous.heldLayers) === void 0 ? {} : { heldLayers: config.heldLayers ?? previous.heldLayers }
|
|
14469
14685
|
};
|
|
14686
|
+
if (
|
|
14687
|
+
// By content: a catalog refresh rebuilds equal arrays, and forgetting
|
|
14688
|
+
// the anchors on one would fail open.
|
|
14689
|
+
JSON.stringify(next.repairLayers) !== JSON.stringify(previous.repairLayers) || JSON.stringify(next.heldLayers) !== JSON.stringify(previous.heldLayers)
|
|
14690
|
+
) {
|
|
14691
|
+
for (const key of [...this.#heldLayerStates.keys()]) {
|
|
14692
|
+
if (this.#belongsToPacket(key, packetId)) this.#heldLayerStates.delete(key);
|
|
14693
|
+
}
|
|
14694
|
+
}
|
|
14470
14695
|
if (!hasCatalogTiming) {
|
|
14471
14696
|
next.timeoutMs = config.timeoutMs !== void 0 && config.timeoutMs > 0 ? config.timeoutMs : previousTrack !== void 0 && previousTrack.interleaveDepthMs === 0 ? previousTrack.timeoutMs : LOCAL_FEC_TIMEOUT_MS;
|
|
14472
14697
|
} else {
|
|
@@ -14701,6 +14926,8 @@ var FECManager = class _FECManager {
|
|
|
14701
14926
|
resetMap(this.#blockAuthoredLengths);
|
|
14702
14927
|
resetMap(this.#blockRepairRsIds);
|
|
14703
14928
|
resetMap(this.#blockRsbLengths);
|
|
14929
|
+
resetMap(this.#heldLayerStates);
|
|
14930
|
+
resetMap(this.#fecFailClosed);
|
|
14704
14931
|
resetMap(this.#blockPathCounts);
|
|
14705
14932
|
resetMap(this.#blockAnchorsMs);
|
|
14706
14933
|
resetMap(this.#blockCatalogTrackNames);
|
|
@@ -14723,6 +14950,7 @@ var FECManager = class _FECManager {
|
|
|
14723
14950
|
resetSet(this.#materializedBlocks);
|
|
14724
14951
|
resetMap(this.#resolvedBlockClasses);
|
|
14725
14952
|
resetMap(this.#highestSbn);
|
|
14953
|
+
resetMap(this.#sourceFrontiers);
|
|
14726
14954
|
resetMap(this.#isoLocators);
|
|
14727
14955
|
resetMap(this.#sourceAnchors);
|
|
14728
14956
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -14828,6 +15056,7 @@ var FECManager = class _FECManager {
|
|
|
14828
15056
|
dropMap(this.#orderedPendingBlocks);
|
|
14829
15057
|
dropMap(this.#resolvedBlockClasses);
|
|
14830
15058
|
dropMap(this.#highestSbn);
|
|
15059
|
+
dropMap(this.#sourceFrontiers);
|
|
14831
15060
|
dropMap(this.#isoLocators);
|
|
14832
15061
|
dropMap(this.#sourceAnchors);
|
|
14833
15062
|
dropMap(this.#classifiers);
|
|
@@ -14920,7 +15149,13 @@ var FECManager = class _FECManager {
|
|
|
14920
15149
|
if (isSourceSymbol && esi === 0) {
|
|
14921
15150
|
this.#startupPartialBlocks.delete(blockKey);
|
|
14922
15151
|
this.#startupAlignedPackets.add(streamKey);
|
|
14923
|
-
} else if (
|
|
15152
|
+
} else if (
|
|
15153
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
15154
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
15155
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
15156
|
+
// per join (BLO-48308).
|
|
15157
|
+
isStartupPartial || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair
|
|
15158
|
+
) {
|
|
14924
15159
|
this.#markStartupPartial(blockKey);
|
|
14925
15160
|
return false;
|
|
14926
15161
|
}
|
|
@@ -15202,6 +15437,7 @@ var FECManager = class _FECManager {
|
|
|
15202
15437
|
let locator = this.#isoLocators.get(streamKey);
|
|
15203
15438
|
if (!locator) {
|
|
15204
15439
|
locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
|
|
15440
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15205
15441
|
this.#isoLocators.set(streamKey, locator);
|
|
15206
15442
|
}
|
|
15207
15443
|
return locator;
|
|
@@ -15245,6 +15481,10 @@ var FECManager = class _FECManager {
|
|
|
15245
15481
|
}
|
|
15246
15482
|
return blocks;
|
|
15247
15483
|
}
|
|
15484
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
15485
|
+
isoRetentionBlocksForPacket(packetId) {
|
|
15486
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : void 0;
|
|
15487
|
+
}
|
|
15248
15488
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
15249
15489
|
isoSourceFits(packetId, packetLength) {
|
|
15250
15490
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize;
|
|
@@ -15294,15 +15534,61 @@ var FECManager = class _FECManager {
|
|
|
15294
15534
|
}
|
|
15295
15535
|
return placement;
|
|
15296
15536
|
}
|
|
15297
|
-
if (placement.span !== void 0)
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15537
|
+
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
15538
|
+
if (placement.hole !== void 0) {
|
|
15539
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
15540
|
+
const hole = placement.hole.block;
|
|
15541
|
+
const previous = locator.blockEndingAt(hole.start);
|
|
15542
|
+
const loss = {
|
|
15543
|
+
packetId,
|
|
15544
|
+
catalogTrackName,
|
|
15545
|
+
holeStart: hole.start,
|
|
15546
|
+
holeLength: hole.length,
|
|
15547
|
+
lostSsId: placement.hole.lostSsId,
|
|
15548
|
+
kMax: this.#trackConfig(packetId).k,
|
|
15549
|
+
...previous === void 0 ? {} : { previousBlockStart: previous.start }
|
|
15550
|
+
};
|
|
15551
|
+
this.#onUndelimitedLoss(loss);
|
|
15303
15552
|
}
|
|
15304
15553
|
return placement;
|
|
15305
15554
|
}
|
|
15555
|
+
/**
|
|
15556
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
15557
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
15558
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
15559
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
15560
|
+
* nobody to close it.
|
|
15561
|
+
*/
|
|
15562
|
+
setUndelimitedLossHandler(handler) {
|
|
15563
|
+
this.#onUndelimitedLoss = handler;
|
|
15564
|
+
this.#deferIsoGaps = handler !== null;
|
|
15565
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
15566
|
+
}
|
|
15567
|
+
/**
|
|
15568
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
15569
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
15570
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
15571
|
+
*/
|
|
15572
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
15573
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
15574
|
+
if (locator === void 0) return [];
|
|
15575
|
+
const spans = locator.closeHolesWithin(start, length);
|
|
15576
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
|
|
15577
|
+
return spans;
|
|
15578
|
+
}
|
|
15579
|
+
/**
|
|
15580
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
15581
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
15582
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
15583
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
15584
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
15585
|
+
* block.
|
|
15586
|
+
*/
|
|
15587
|
+
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
15588
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
15589
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
|
|
15590
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
15591
|
+
}
|
|
15306
15592
|
/**
|
|
15307
15593
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
15308
15594
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -15819,6 +16105,154 @@ var FECManager = class _FECManager {
|
|
|
15819
16105
|
}
|
|
15820
16106
|
return recovered;
|
|
15821
16107
|
}
|
|
16108
|
+
/**
|
|
16109
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16110
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
16111
|
+
* block state unchanged. The router calls this before the repair places a
|
|
16112
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
16113
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
16114
|
+
*/
|
|
16115
|
+
admitRepairBlockLength(packetId, ssbLength, rsbLength, rsId) {
|
|
16116
|
+
if (rsId >= rsbLength) return false;
|
|
16117
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== "reed-solomon") return true;
|
|
16118
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS;
|
|
16119
|
+
}
|
|
16120
|
+
/**
|
|
16121
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
16122
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
16123
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
16124
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
16125
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
16126
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
16127
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
16128
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
16129
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
16130
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
16131
|
+
*/
|
|
16132
|
+
admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, byteLength) {
|
|
16133
|
+
if (!this.#hasBlockProfile(packetId)) return false;
|
|
16134
|
+
const symbolSize = this.#trackConfig(packetId).symbolSize;
|
|
16135
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
16136
|
+
this.#repairSymbolSizeMismatchCount++;
|
|
16137
|
+
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
16138
|
+
console.warn(
|
|
16139
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
16140
|
+
);
|
|
16141
|
+
}
|
|
16142
|
+
return false;
|
|
16143
|
+
}
|
|
16144
|
+
return true;
|
|
16145
|
+
}
|
|
16146
|
+
/**
|
|
16147
|
+
* fec-01 6.3.9 receiver check, run on a repair packet after the 4.5 discard
|
|
16148
|
+
* and the size check, before it places a block. For each held layer i with
|
|
16149
|
+
* total B_i = O_i + P_i: the anchor is the earliest block, in SS_Start
|
|
16150
|
+
* serial order, whose repair carried RSB_length >= B_i. The source track
|
|
16151
|
+
* fails closed on (a) a packet on layer i's own repair track (i > 0) below
|
|
16152
|
+
* B_i, or (b) any packet of the instance at or after the anchor below B_i.
|
|
16153
|
+
* Blocks before the anchor (pre-append) stay valid at the previous total. A
|
|
16154
|
+
* packet on a repair track the catalog does not list is discarded and
|
|
16155
|
+
* anchors nothing. `repairTrackName` is the subscribed repair track, never
|
|
16156
|
+
* inferred from RS_ID; without it only (b) runs. Returns false when the
|
|
16157
|
+
* repair must be dropped, including every repair once the track failed.
|
|
16158
|
+
*/
|
|
16159
|
+
admitRepairLayerTotal(packetId, catalogTrackName, repairTrackName, ssStart, rsbLength) {
|
|
16160
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16161
|
+
if (this.#fecFailClosed.has(streamKey)) return false;
|
|
16162
|
+
const config = this.#trackConfigs.get(packetId);
|
|
16163
|
+
const layers = config?.repairLayers;
|
|
16164
|
+
if (layers === void 0 || layers.length === 0) return true;
|
|
16165
|
+
if (repairTrackName !== void 0 && !layers.some((l) => l.repairTrackName === repairTrackName)) {
|
|
16166
|
+
return false;
|
|
16167
|
+
}
|
|
16168
|
+
let states = this.#heldLayerStates.get(streamKey);
|
|
16169
|
+
if (states === void 0) {
|
|
16170
|
+
const held = new Set(config.heldLayers ?? [0]);
|
|
16171
|
+
states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
|
|
16172
|
+
this.#heldLayerStates.set(streamKey, states);
|
|
16173
|
+
}
|
|
16174
|
+
const horizon = this.#layerAnchorHorizon(packetId);
|
|
16175
|
+
const frontier = this.#sourceFrontiers.get(streamKey)?.sbn;
|
|
16176
|
+
const farAhead = frontier !== void 0 && serial32Precedes(frontier, ssStart) && serial32Distance(frontier, ssStart) > horizon;
|
|
16177
|
+
for (const state of states) {
|
|
16178
|
+
let code;
|
|
16179
|
+
if (farAhead) {
|
|
16180
|
+
if (rsbLength < state.total) {
|
|
16181
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
16182
|
+
else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
|
|
16183
|
+
}
|
|
16184
|
+
} else {
|
|
16185
|
+
if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
|
|
16186
|
+
const stale = (s) => serial32Distance(s, state.newest) > horizon;
|
|
16187
|
+
if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
|
|
16188
|
+
delete state.latestBelow;
|
|
16189
|
+
delete state.latestBelowRsb;
|
|
16190
|
+
}
|
|
16191
|
+
if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
|
|
16192
|
+
if (rsbLength < state.total) {
|
|
16193
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
16194
|
+
else if (stale(ssStart)) continue;
|
|
16195
|
+
else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
|
|
16196
|
+
else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
|
|
16197
|
+
state.latestBelow = ssStart;
|
|
16198
|
+
state.latestBelowRsb = rsbLength;
|
|
16199
|
+
}
|
|
16200
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
16201
|
+
if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
|
|
16202
|
+
if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
16203
|
+
code = "below_anchored_total";
|
|
16204
|
+
ssStart = state.latestBelow;
|
|
16205
|
+
rsbLength = state.latestBelowRsb;
|
|
16206
|
+
}
|
|
16207
|
+
}
|
|
16208
|
+
}
|
|
16209
|
+
if (code !== void 0) {
|
|
16210
|
+
const reason = {
|
|
16211
|
+
code,
|
|
16212
|
+
layer: state.layer,
|
|
16213
|
+
total: state.total,
|
|
16214
|
+
rsbLength,
|
|
16215
|
+
ssStart,
|
|
16216
|
+
...state.anchor === void 0 ? {} : { anchor: state.anchor }
|
|
16217
|
+
};
|
|
16218
|
+
this.#fecFailClosed.set(streamKey, reason);
|
|
16219
|
+
this.#onFecFailClosed?.({ ...reason, packetId, catalogTrackName });
|
|
16220
|
+
console.warn(
|
|
16221
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? "-"}: ${JSON.stringify(reason)}`
|
|
16222
|
+
);
|
|
16223
|
+
return false;
|
|
16224
|
+
}
|
|
16225
|
+
}
|
|
16226
|
+
return true;
|
|
16227
|
+
}
|
|
16228
|
+
/**
|
|
16229
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
16230
|
+
* below-total block can still matter: the iso locator's retention in blocks
|
|
16231
|
+
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
16232
|
+
*/
|
|
16233
|
+
#layerAnchorHorizon(packetId) {
|
|
16234
|
+
const cap = 1073741824;
|
|
16235
|
+
let blocks;
|
|
16236
|
+
try {
|
|
16237
|
+
blocks = this.isoRetentionBlocksForPacket(packetId);
|
|
16238
|
+
} catch {
|
|
16239
|
+
blocks = void 0;
|
|
16240
|
+
}
|
|
16241
|
+
const k = this.#trackConfigs.get(packetId)?.k ?? 0;
|
|
16242
|
+
return blocks === void 0 || k <= 0 ? cap : Math.min(cap, blocks * k);
|
|
16243
|
+
}
|
|
16244
|
+
/**
|
|
16245
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), once,
|
|
16246
|
+
* when it does; null stops reporting. The player wiring forwards it to
|
|
16247
|
+
* CmcdProducer.updateFecFailClosed.
|
|
16248
|
+
*/
|
|
16249
|
+
setFecFailClosedHandler(handler) {
|
|
16250
|
+
this.#onFecFailClosed = handler;
|
|
16251
|
+
}
|
|
16252
|
+
/** The runtime fail-closed reason of a stream's FEC (fec-01 6.3.9), if any. */
|
|
16253
|
+
fecFailClosedReason(packetId, catalogTrackName) {
|
|
16254
|
+
return this.#fecFailClosed.get(this.#streamKey(packetId, catalogTrackName));
|
|
16255
|
+
}
|
|
15822
16256
|
/**
|
|
15823
16257
|
* Feed a repair symbol to the WASM FEC decoder.
|
|
15824
16258
|
*
|
|
@@ -15830,16 +16264,7 @@ var FECManager = class _FECManager {
|
|
|
15830
16264
|
this.#fecStats.repairPackets++;
|
|
15831
16265
|
this.#statsForPacket(packetId).repairPackets++;
|
|
15832
16266
|
if (!this.#hasBlockProfile(packetId)) return null;
|
|
15833
|
-
|
|
15834
|
-
if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
|
|
15835
|
-
this.#repairSymbolSizeMismatchCount++;
|
|
15836
|
-
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
15837
|
-
console.warn(
|
|
15838
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
15839
|
-
);
|
|
15840
|
-
}
|
|
15841
|
-
return null;
|
|
15842
|
-
}
|
|
16267
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null;
|
|
15843
16268
|
const fecData = repairData;
|
|
15844
16269
|
const k = this.#trackConfig(packetId).k;
|
|
15845
16270
|
const block = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(ssStart);
|
|
@@ -15992,7 +16417,14 @@ var FECManager = class _FECManager {
|
|
|
15992
16417
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
15993
16418
|
const k = trackConfig.k;
|
|
15994
16419
|
if (this.#completedBlocks.has(key)) return;
|
|
15995
|
-
this.#noteSbnSeen(
|
|
16420
|
+
this.#noteSbnSeen(
|
|
16421
|
+
sbn,
|
|
16422
|
+
packetId,
|
|
16423
|
+
catalogTrackName,
|
|
16424
|
+
"source",
|
|
16425
|
+
evidence.packetSequenceNumber,
|
|
16426
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
16427
|
+
);
|
|
15996
16428
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
15997
16429
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
15998
16430
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -16219,6 +16651,8 @@ var FECManager = class _FECManager {
|
|
|
16219
16651
|
this.#blockAuthoredLengths.clear();
|
|
16220
16652
|
this.#blockRepairRsIds.clear();
|
|
16221
16653
|
this.#blockRsbLengths.clear();
|
|
16654
|
+
this.#heldLayerStates.clear();
|
|
16655
|
+
this.#fecFailClosed.clear();
|
|
16222
16656
|
this.#completedBlocks.clear();
|
|
16223
16657
|
this.#cleanlyCompletedBlocks.clear();
|
|
16224
16658
|
this.#repairRequestedBlocks.clear();
|
|
@@ -16243,6 +16677,7 @@ var FECManager = class _FECManager {
|
|
|
16243
16677
|
this.#repairedBlocks.clear();
|
|
16244
16678
|
this.#materializedBlocks.clear();
|
|
16245
16679
|
this.#highestSbn.clear();
|
|
16680
|
+
this.#sourceFrontiers.clear();
|
|
16246
16681
|
this.#isoLocators.clear();
|
|
16247
16682
|
this.#sourceAnchors.clear();
|
|
16248
16683
|
this.#trackConfigs.clear();
|
|
@@ -17332,6 +17767,7 @@ function isFmp4Box(data) {
|
|
|
17332
17767
|
const type = String.fromCharCode(data[4], data[5], data[6], data[7]);
|
|
17333
17768
|
return FMPU_BOX_TYPES.has(type);
|
|
17334
17769
|
}
|
|
17770
|
+
var MAX_AWAITING_TIMING_HEADS = 8;
|
|
17335
17771
|
var MmtpContainerParser = class _MmtpContainerParser {
|
|
17336
17772
|
constructor(config) {
|
|
17337
17773
|
this.#tracks = /* @__PURE__ */ new Map();
|
|
@@ -17390,6 +17826,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17390
17826
|
* reordering into the parser. */
|
|
17391
17827
|
this.#reliableMoqStartupGate = /* @__PURE__ */ new Map();
|
|
17392
17828
|
this.#disposed = false;
|
|
17829
|
+
this.#replayingAwaitingTiming = false;
|
|
17393
17830
|
this.#fedObjects = 0;
|
|
17394
17831
|
this.#reassemblerFragmentsFed = 0;
|
|
17395
17832
|
this.#reassemblerDataUnitsReturned = 0;
|
|
@@ -17482,6 +17919,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17482
17919
|
#reorderStats;
|
|
17483
17920
|
#reliableMoqStartupGate;
|
|
17484
17921
|
#disposed;
|
|
17922
|
+
#replayingAwaitingTiming;
|
|
17485
17923
|
#fedObjects;
|
|
17486
17924
|
#reassemblerFragmentsFed;
|
|
17487
17925
|
#reassemblerDataUnitsReturned;
|
|
@@ -17731,7 +18169,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17731
18169
|
* a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
|
|
17732
18170
|
*/
|
|
17733
18171
|
#drop(reason) {
|
|
17734
|
-
this.#
|
|
18172
|
+
if (this.#replayingAwaitingTiming) this.#countDeferredOutcome(reason);
|
|
18173
|
+
else this.#countOutcome(`drop:${reason}`);
|
|
17735
18174
|
return null;
|
|
17736
18175
|
}
|
|
17737
18176
|
get reorderDiagnostics() {
|
|
@@ -17754,6 +18193,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17754
18193
|
for (const combiner of this.#sampleCombiners.values()) {
|
|
17755
18194
|
combiner.cleanupTimeouts(timeoutMs);
|
|
17756
18195
|
}
|
|
18196
|
+
const now = Date.now();
|
|
18197
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18198
|
+
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
18199
|
+
awaitingTiming.shift();
|
|
18200
|
+
}
|
|
18201
|
+
}
|
|
17757
18202
|
}
|
|
17758
18203
|
/**
|
|
17759
18204
|
* Phase 1 of two-phase parsing. Returns structured header info for FEC feeding.
|
|
@@ -17834,7 +18279,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17834
18279
|
byteLength: packet.byteLength
|
|
17835
18280
|
};
|
|
17836
18281
|
}
|
|
17837
|
-
if (info.fecPayloadId !== null && this.#sourceSymbolCb) {
|
|
18282
|
+
if (info.fecPayloadId !== null && this.#sourceSymbolCb && !this.#replayingAwaitingTiming) {
|
|
17838
18283
|
const rawSymbol = packet.subarray(0, packet.length - 4);
|
|
17839
18284
|
try {
|
|
17840
18285
|
this.#sourceSymbolCb(info.packetId, info.fecPayloadId.ssId, rawSymbol);
|
|
@@ -17882,6 +18327,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17882
18327
|
}
|
|
17883
18328
|
return this.#drop("fragment-timing-refused");
|
|
17884
18329
|
}
|
|
18330
|
+
this.#replayAwaitingTiming(streamKey, resolver2);
|
|
17885
18331
|
return {
|
|
17886
18332
|
kind: "fragment",
|
|
17887
18333
|
packet: info,
|
|
@@ -17905,7 +18351,18 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17905
18351
|
mfuDuHeader.movieFragmentSequenceNumber,
|
|
17906
18352
|
mfuDuHeader.sampleNumber
|
|
17907
18353
|
);
|
|
17908
|
-
if (!headTiming)
|
|
18354
|
+
if (!headTiming) {
|
|
18355
|
+
this.#awaitTiming(streamKey, {
|
|
18356
|
+
packet,
|
|
18357
|
+
options,
|
|
18358
|
+
parsed,
|
|
18359
|
+
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
18360
|
+
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
18361
|
+
sampleNumber: mfuDuHeader.sampleNumber,
|
|
18362
|
+
arrivedAt: Date.now()
|
|
18363
|
+
});
|
|
18364
|
+
return this.#drop("mfu-sample-timing-missing");
|
|
18365
|
+
}
|
|
17909
18366
|
const offset = mfuDuHeader.offset;
|
|
17910
18367
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset >= headTiming.size)
|
|
17911
18368
|
return this.#drop("mfu-offset-out-of-range");
|
|
@@ -17981,16 +18438,17 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
17981
18438
|
const sampleNumber = assembled.sampleNumber;
|
|
17982
18439
|
if (movieFragmentSequenceNumber === void 0 || sampleNumber === void 0)
|
|
17983
18440
|
return this.#drop("assembled-identity-missing");
|
|
17984
|
-
|
|
18441
|
+
const assembledTiming = resolver.sampleTiming(
|
|
17985
18442
|
assembled.mpuSequenceNumber,
|
|
17986
18443
|
movieFragmentSequenceNumber,
|
|
17987
18444
|
sampleNumber
|
|
17988
|
-
)
|
|
18445
|
+
);
|
|
18446
|
+
if (!assembledTiming) return this.#drop("assembled-timing-missing");
|
|
17989
18447
|
if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
|
|
17990
18448
|
return this.#drop("assembled-mpu-mismatch");
|
|
17991
18449
|
let combined;
|
|
17992
18450
|
try {
|
|
17993
|
-
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled);
|
|
18451
|
+
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled, assembledTiming.size);
|
|
17994
18452
|
} catch (error) {
|
|
17995
18453
|
if (!(error instanceof SampleCombineError)) throw error;
|
|
17996
18454
|
console.warn(
|
|
@@ -18299,9 +18757,37 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18299
18757
|
if (existing) return existing.resolver;
|
|
18300
18758
|
if (!create) return null;
|
|
18301
18759
|
const resolver = new IsoBmffTimingResolver(this.#maxPendingTimingSamples);
|
|
18302
|
-
this.#timingStreams.set(streamKey, { packetId, resolver });
|
|
18760
|
+
this.#timingStreams.set(streamKey, { packetId, resolver, awaitingTiming: [] });
|
|
18303
18761
|
return resolver;
|
|
18304
18762
|
}
|
|
18763
|
+
#awaitTiming(streamKey, head) {
|
|
18764
|
+
const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming;
|
|
18765
|
+
if (!awaitingTiming) return;
|
|
18766
|
+
awaitingTiming.push(head);
|
|
18767
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
|
|
18768
|
+
}
|
|
18769
|
+
/**
|
|
18770
|
+
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
18771
|
+
* FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
|
|
18772
|
+
* FEC path routes a source symbol that already arrived a second time.
|
|
18773
|
+
*/
|
|
18774
|
+
#replayAwaitingTiming(streamKey, resolver) {
|
|
18775
|
+
const state = this.#timingStreams.get(streamKey);
|
|
18776
|
+
if (!state || state.awaitingTiming.length === 0) return;
|
|
18777
|
+
const ready = state.awaitingTiming.filter((head) => resolver.sampleTiming(
|
|
18778
|
+
head.mpuSequenceNumber,
|
|
18779
|
+
head.movieFragmentSequenceNumber,
|
|
18780
|
+
head.sampleNumber
|
|
18781
|
+
));
|
|
18782
|
+
if (ready.length === 0) return;
|
|
18783
|
+
state.awaitingTiming = state.awaitingTiming.filter((head) => !ready.includes(head));
|
|
18784
|
+
this.#replayingAwaitingTiming = true;
|
|
18785
|
+
try {
|
|
18786
|
+
for (const head of ready) this.#feed(head.packet, head.options, head.parsed);
|
|
18787
|
+
} finally {
|
|
18788
|
+
this.#replayingAwaitingTiming = false;
|
|
18789
|
+
}
|
|
18790
|
+
}
|
|
18305
18791
|
#dropTimingStream(streamKey) {
|
|
18306
18792
|
const state = this.#timingStreams.get(streamKey);
|
|
18307
18793
|
if (!state) return;
|
|
@@ -18906,6 +19392,18 @@ var MmtpRouter = class {
|
|
|
18906
19392
|
// MSE recovery routes through CmafBlockAssembler and can reorder by block; the
|
|
18907
19393
|
// direct callback path has to preserve decode order before frames leave libmmt.
|
|
18908
19394
|
#latestVideoSeqByStream = /* @__PURE__ */ new Map();
|
|
19395
|
+
/**
|
|
19396
|
+
* Per stream, SS_ID - packet_sequence_number (mod 2^32) of its latest
|
|
19397
|
+
* first-arrival FEC source packet. A recovered source symbol's wire
|
|
19398
|
+
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
19399
|
+
*/
|
|
19400
|
+
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19401
|
+
/**
|
|
19402
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
19403
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
19404
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
19405
|
+
*/
|
|
19406
|
+
#multicastRapTwinByStream = /* @__PURE__ */ new Set();
|
|
18909
19407
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18910
19408
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
18911
19409
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -18980,11 +19478,14 @@ var MmtpRouter = class {
|
|
|
18980
19478
|
*/
|
|
18981
19479
|
#onPublisherRestart;
|
|
18982
19480
|
#publisherRestarts = 0;
|
|
19481
|
+
#restampedRecoveredSeqs = 0;
|
|
18983
19482
|
/** Inits delivered with no onTrackInit handler for their packetId (MOQT-01). */
|
|
18984
19483
|
#unmappedInitDeliveries = 0;
|
|
18985
19484
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
18986
19485
|
// configured fec.blockProfile (see #noteUnreadableFecPayloadId).
|
|
18987
19486
|
#fecPayloadIdsWithoutProfile = 0;
|
|
19487
|
+
// Repair packets discarded by the fec-01 4.5 block-length rule.
|
|
19488
|
+
#repairBlockLengthDiscards = 0;
|
|
18988
19489
|
/** The staged in-place stream switch, if any (stageStreamSwitch). */
|
|
18989
19490
|
#staged = null;
|
|
18990
19491
|
#disposed = false;
|
|
@@ -19038,6 +19539,12 @@ var MmtpRouter = class {
|
|
|
19038
19539
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
|
|
19039
19540
|
};
|
|
19040
19541
|
if (meta.source) frameMeta.source = meta.source;
|
|
19542
|
+
if (isVideo && frameMeta.keyframe) {
|
|
19543
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
19544
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
|
|
19545
|
+
);
|
|
19546
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
19547
|
+
}
|
|
19041
19548
|
if (meta.deliveryProvenance !== void 0)
|
|
19042
19549
|
frameMeta.deliveryProvenance = meta.deliveryProvenance;
|
|
19043
19550
|
if (meta.recovered) frameMeta.recovered = true;
|
|
@@ -19200,6 +19707,14 @@ var MmtpRouter = class {
|
|
|
19200
19707
|
get publisherRestartCount() {
|
|
19201
19708
|
return this.#publisherRestarts;
|
|
19202
19709
|
}
|
|
19710
|
+
/**
|
|
19711
|
+
* FEC-recovered source symbols whose reconstructed header named a
|
|
19712
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to:
|
|
19713
|
+
* a hop re-stamped the sequence after the sender protected the packet.
|
|
19714
|
+
*/
|
|
19715
|
+
get restampedRecoveredSequenceCount() {
|
|
19716
|
+
return this.#restampedRecoveredSeqs;
|
|
19717
|
+
}
|
|
19203
19718
|
/**
|
|
19204
19719
|
* Packets whose Source or Repair FEC Payload ID was left unread because
|
|
19205
19720
|
* their (owner) packetId had no configured `fec.blockProfile`: FEC not
|
|
@@ -19211,6 +19726,14 @@ var MmtpRouter = class {
|
|
|
19211
19726
|
get fecPayloadIdsWithoutProfile() {
|
|
19212
19727
|
return this.#fecPayloadIdsWithoutProfile;
|
|
19213
19728
|
}
|
|
19729
|
+
/**
|
|
19730
|
+
* Repair packets discarded at admission by the fec-01 4.5 rule (RS_ID not
|
|
19731
|
+
* below RSB_length, or a reed-solomon SSB_length + RSB_length above 255),
|
|
19732
|
+
* before they touched any block state.
|
|
19733
|
+
*/
|
|
19734
|
+
get repairBlockLengthDiscards() {
|
|
19735
|
+
return this.#repairBlockLengthDiscards;
|
|
19736
|
+
}
|
|
19214
19737
|
get reassembler() {
|
|
19215
19738
|
return this.#parser.reassembler;
|
|
19216
19739
|
}
|
|
@@ -19589,13 +20112,13 @@ var MmtpRouter = class {
|
|
|
19589
20112
|
* Feed a repair packet from MoQ (reliable QUIC) — parses MMTP repair
|
|
19590
20113
|
* header and delegates to FECManager for FEC recovery.
|
|
19591
20114
|
*/
|
|
19592
|
-
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
20115
|
+
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
19593
20116
|
if (this.#disposed) return;
|
|
19594
20117
|
this.#withDeferredFecPokes(() => {
|
|
19595
|
-
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName);
|
|
20118
|
+
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
|
|
19596
20119
|
});
|
|
19597
20120
|
}
|
|
19598
|
-
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
20121
|
+
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
19599
20122
|
let header;
|
|
19600
20123
|
try {
|
|
19601
20124
|
header = parseMMTPHeader(packet);
|
|
@@ -19626,7 +20149,7 @@ var MmtpRouter = class {
|
|
|
19626
20149
|
this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
|
|
19627
20150
|
return;
|
|
19628
20151
|
}
|
|
19629
|
-
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq");
|
|
20152
|
+
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
|
|
19630
20153
|
}
|
|
19631
20154
|
}
|
|
19632
20155
|
// ── Packet FEC geometry and block profile ───────────────────────
|
|
@@ -19708,13 +20231,25 @@ var MmtpRouter = class {
|
|
|
19708
20231
|
* the repair, the order they had on the wire, so a loss-free block completes
|
|
19709
20232
|
* clean on its repair. A repair contradicting a known block is dropped.
|
|
19710
20233
|
*/
|
|
19711
|
-
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source) {
|
|
20234
|
+
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source, repairTrackName) {
|
|
19712
20235
|
const fec = this.#fecManager;
|
|
19713
20236
|
if (!fec?.placeIsoRepair) {
|
|
19714
20237
|
throw new Error(
|
|
19715
20238
|
`[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`
|
|
19716
20239
|
);
|
|
19717
20240
|
}
|
|
20241
|
+
if (fec.admitRepairBlockLength && !fec.admitRepairBlockLength(ownerPacketId, repair.ssbLength, repair.rsbLength, repair.rsId)) {
|
|
20242
|
+
this.#repairBlockLengthDiscards++;
|
|
20243
|
+
return;
|
|
20244
|
+
}
|
|
20245
|
+
if (fec.admitRepairSymbolSize && !fec.admitRepairSymbolSize(
|
|
20246
|
+
ownerPacketId,
|
|
20247
|
+
repair.ssStart,
|
|
20248
|
+
repair.ssbLength,
|
|
20249
|
+
repair.rsId,
|
|
20250
|
+
repair.symbolData.byteLength
|
|
20251
|
+
)) return;
|
|
20252
|
+
if (fec.admitRepairLayerTotal && !fec.admitRepairLayerTotal(ownerPacketId, catalogTrackName, repairTrackName, repair.ssStart, repair.rsbLength)) return;
|
|
19718
20253
|
const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
|
|
19719
20254
|
if (placement.status !== "placed") return;
|
|
19720
20255
|
const blockStart = placement.block.start;
|
|
@@ -19749,6 +20284,17 @@ var MmtpRouter = class {
|
|
|
19749
20284
|
this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
|
|
19750
20285
|
}
|
|
19751
20286
|
}
|
|
20287
|
+
/**
|
|
20288
|
+
* The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
|
|
20289
|
+
* §7.5): what no repair stated becomes repair-less spans, whose held sources
|
|
20290
|
+
* are fed exactly as a span a repair closed.
|
|
20291
|
+
*/
|
|
20292
|
+
closeIsoHoles(ownerPacketId, catalogTrackName, start, length) {
|
|
20293
|
+
const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
|
|
20294
|
+
for (const span of spans) {
|
|
20295
|
+
this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
|
|
20296
|
+
}
|
|
20297
|
+
}
|
|
19752
20298
|
/**
|
|
19753
20299
|
* Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
|
|
19754
20300
|
* a first-arrival source is fed once its block is known: transport
|
|
@@ -19844,6 +20390,8 @@ var MmtpRouter = class {
|
|
|
19844
20390
|
this.#trackSynced.delete(streamKey);
|
|
19845
20391
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19846
20392
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
20393
|
+
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
20394
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
19847
20395
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19848
20396
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
19849
20397
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -20614,6 +21162,12 @@ var MmtpRouter = class {
|
|
|
20614
21162
|
} else if (fecUnreadable && info.fecPayloadId) {
|
|
20615
21163
|
parseSourceSymbol = !duplicates.parsedSymbols.has(info.fecPayloadId.ssId);
|
|
20616
21164
|
}
|
|
21165
|
+
if (fecPayloadId && !overlapCopy) {
|
|
21166
|
+
this.#ssIdSeqOffsetByStream.set(
|
|
21167
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
21168
|
+
fecPayloadId.ssId - info.sequenceNumber >>> 0
|
|
21169
|
+
);
|
|
21170
|
+
}
|
|
20617
21171
|
if (!this.#fecManager || !info.fecPayloadId || parseSourceSymbol) {
|
|
20618
21172
|
if (this.#fecManager && info.fecPayloadId) {
|
|
20619
21173
|
duplicates.parsedSymbols.add(info.fecPayloadId.ssId);
|
|
@@ -20624,6 +21178,8 @@ var MmtpRouter = class {
|
|
|
20624
21178
|
catalogTrackName
|
|
20625
21179
|
);
|
|
20626
21180
|
this.#routeTrackPacket(packet, info.packetId, info.sequenceNumber, {
|
|
21181
|
+
mmtpTimestamp: parsed.header.timestamp,
|
|
21182
|
+
rap: info.rapFlag,
|
|
20627
21183
|
recovered: false,
|
|
20628
21184
|
skipFecPayloadId: false,
|
|
20629
21185
|
catalogTrackName
|
|
@@ -20634,6 +21190,10 @@ var MmtpRouter = class {
|
|
|
20634
21190
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
20635
21191
|
...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
|
|
20636
21192
|
}, parsed);
|
|
21193
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
21194
|
+
this.#multicastRapTwinByStream.add(
|
|
21195
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName)
|
|
21196
|
+
);
|
|
20637
21197
|
}
|
|
20638
21198
|
if (this.#classifyPacketId(info.packetId) === null) return;
|
|
20639
21199
|
if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
|
|
@@ -20811,6 +21371,8 @@ var MmtpRouter = class {
|
|
|
20811
21371
|
callback(packet, {
|
|
20812
21372
|
packetId,
|
|
20813
21373
|
packetSequenceNumber,
|
|
21374
|
+
mmtpTimestamp: meta.mmtpTimestamp,
|
|
21375
|
+
rap: meta.rap,
|
|
20814
21376
|
recovered: meta.recovered,
|
|
20815
21377
|
skipFecPayloadId: meta.skipFecPayloadId,
|
|
20816
21378
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName },
|
|
@@ -21186,6 +21748,20 @@ var MmtpRouter = class {
|
|
|
21186
21748
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
|
|
21187
21749
|
if (ownerPacketId == null) return;
|
|
21188
21750
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
21751
|
+
const ssIdSeqOffset = this.#ssIdSeqOffsetByStream.get(
|
|
21752
|
+
this.#mediaStreamKey(ownerPacketId, catalogTrackName)
|
|
21753
|
+
);
|
|
21754
|
+
if (ssIdSeqOffset !== void 0) {
|
|
21755
|
+
result = {
|
|
21756
|
+
...result,
|
|
21757
|
+
symbols: result.symbols.map((sym) => {
|
|
21758
|
+
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
21759
|
+
if (wire === sym.packetSequenceNumber) return sym;
|
|
21760
|
+
this.#restampedRecoveredSeqs++;
|
|
21761
|
+
return { ...sym, packetSequenceNumber: wire };
|
|
21762
|
+
})
|
|
21763
|
+
};
|
|
21764
|
+
}
|
|
21189
21765
|
this.#stream(ownerPacketId, catalogTrackName).duplicates.advance(blockId);
|
|
21190
21766
|
const deliveryProvenance = this.#fecManager?.blockDeliveryProvenance?.(
|
|
21191
21767
|
blockId,
|
|
@@ -21194,6 +21770,8 @@ var MmtpRouter = class {
|
|
|
21194
21770
|
) ?? "unknown";
|
|
21195
21771
|
for (const sym of result.symbols) {
|
|
21196
21772
|
this.#routeTrackPacket(sym.rawSymbol, ownerPacketId, sym.packetSequenceNumber, {
|
|
21773
|
+
mmtpTimestamp: sym.fragment.timestamp,
|
|
21774
|
+
rap: sym.fragment.rapFlag,
|
|
21197
21775
|
recovered: true,
|
|
21198
21776
|
skipFecPayloadId: true,
|
|
21199
21777
|
catalogTrackName,
|
|
@@ -21924,48 +22502,6 @@ function createWasmMmtpContainerParser(config) {
|
|
|
21924
22502
|
});
|
|
21925
22503
|
}
|
|
21926
22504
|
|
|
21927
|
-
// src/fec-codec.ts
|
|
21928
|
-
var NoneCodec = class {
|
|
21929
|
-
constructor() {
|
|
21930
|
-
this.algorithm = "none";
|
|
21931
|
-
}
|
|
21932
|
-
addSymbol(_blockId, _symbolId, data, _isRepair) {
|
|
21933
|
-
return data;
|
|
21934
|
-
}
|
|
21935
|
-
configure(_params) {
|
|
21936
|
-
}
|
|
21937
|
-
cleanup(_now) {
|
|
21938
|
-
return new Uint8Array(0);
|
|
21939
|
-
}
|
|
21940
|
-
};
|
|
21941
|
-
function createFecCodec(algorithm) {
|
|
21942
|
-
switch (algorithm) {
|
|
21943
|
-
case "none":
|
|
21944
|
-
return new NoneCodec();
|
|
21945
|
-
case "reed-solomon":
|
|
21946
|
-
return new ReedSolomonCodec();
|
|
21947
|
-
case "raptorq":
|
|
21948
|
-
console.warn("[FEC] RaptorQ requested via createFecCodec \u2014 use FECManager.setFecDecoder() for WASM RaptorQ. Falling back to NoneCodec.");
|
|
21949
|
-
return new NoneCodec();
|
|
21950
|
-
default:
|
|
21951
|
-
console.warn(`[FEC] Unknown algorithm "${algorithm}", falling back to NoneCodec`);
|
|
21952
|
-
return new NoneCodec();
|
|
21953
|
-
}
|
|
21954
|
-
}
|
|
21955
|
-
var ReedSolomonCodec = class {
|
|
21956
|
-
constructor() {
|
|
21957
|
-
this.algorithm = "reed-solomon";
|
|
21958
|
-
}
|
|
21959
|
-
addSymbol(_blockId, _symbolId, _data, _isRepair) {
|
|
21960
|
-
return null;
|
|
21961
|
-
}
|
|
21962
|
-
configure(_params) {
|
|
21963
|
-
}
|
|
21964
|
-
cleanup(_now) {
|
|
21965
|
-
return new Uint8Array(0);
|
|
21966
|
-
}
|
|
21967
|
-
};
|
|
21968
|
-
|
|
21969
22505
|
// src/multicast-transport.ts
|
|
21970
22506
|
var JOIN_SUCCEEDED = Object.freeze({ ok: true });
|
|
21971
22507
|
function providerErrorOf(error) {
|
|
@@ -22009,7 +22545,7 @@ function sameIds(a, b) {
|
|
|
22009
22545
|
for (const id of a) if (!b.has(id)) return false;
|
|
22010
22546
|
return true;
|
|
22011
22547
|
}
|
|
22012
|
-
var MulticastTransport = class
|
|
22548
|
+
var MulticastTransport = class {
|
|
22013
22549
|
#onPacket;
|
|
22014
22550
|
#subscription = null;
|
|
22015
22551
|
#packetListener = null;
|
|
@@ -22081,8 +22617,11 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22081
22617
|
// droppedPacketIds.
|
|
22082
22618
|
#unadvertisedPacketIds = /* @__PURE__ */ new Set();
|
|
22083
22619
|
#joinGeneration = 0;
|
|
22084
|
-
|
|
22620
|
+
// The provider to subscribe through; window.multicast when unset.
|
|
22621
|
+
#gateway;
|
|
22622
|
+
constructor(onPacket, options = {}) {
|
|
22085
22623
|
this.#onPacket = onPacket;
|
|
22624
|
+
this.#gateway = options.gateway;
|
|
22086
22625
|
}
|
|
22087
22626
|
static isAvailable() {
|
|
22088
22627
|
return hasMulticastGateway();
|
|
@@ -22092,7 +22631,8 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22092
22631
|
this.#releaseSubscription();
|
|
22093
22632
|
this.#dataPlaneLive = false;
|
|
22094
22633
|
if (this.#disposed) return this.#declined(generation, "disposed");
|
|
22095
|
-
|
|
22634
|
+
const gateway = this.#gateway ?? getMulticastGlobals().multicast;
|
|
22635
|
+
if (typeof gateway?.subscribe !== "function") {
|
|
22096
22636
|
console.warn("[MulticastTransport] Multicast API not available");
|
|
22097
22637
|
return this.#declined(generation, "unavailable");
|
|
22098
22638
|
}
|
|
@@ -22109,11 +22649,13 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
22109
22649
|
mode: config.mode,
|
|
22110
22650
|
amtRelay: config.amtRelay,
|
|
22111
22651
|
amtRelayPort: config.amtRelayPort,
|
|
22652
|
+
amtDiscovery: config.amtDiscovery,
|
|
22112
22653
|
packetIds: config.packetIds,
|
|
22113
|
-
tracks: config.tracks
|
|
22654
|
+
tracks: config.tracks,
|
|
22655
|
+
atsc3: config.atsc3
|
|
22114
22656
|
});
|
|
22115
22657
|
failure = "provider-rejected";
|
|
22116
|
-
const subscription = await
|
|
22658
|
+
const subscription = await gateway.subscribe(subscribeConfig);
|
|
22117
22659
|
failure = "invalid-subscription";
|
|
22118
22660
|
console.log(`[MulticastTransport] window.multicast.subscribe returned:`, !!subscription);
|
|
22119
22661
|
if (this.#disposed || generation !== this.#joinGeneration) {
|
|
@@ -22715,6 +23257,25 @@ function catalogAmtNetworkSource(networkSource) {
|
|
|
22715
23257
|
}
|
|
22716
23258
|
return void 0;
|
|
22717
23259
|
}
|
|
23260
|
+
function intIn(value, min, max) {
|
|
23261
|
+
return Number.isInteger(value) && value >= min && value <= max;
|
|
23262
|
+
}
|
|
23263
|
+
function catalogAtsc3NetworkSource(networkSource) {
|
|
23264
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
23265
|
+
for (const raw of entries) {
|
|
23266
|
+
if (!raw || typeof raw !== "object") continue;
|
|
23267
|
+
const ns = raw;
|
|
23268
|
+
if (ns.type !== "atsc3" || !intIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
|
|
23269
|
+
const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
|
|
23270
|
+
return {
|
|
23271
|
+
frequency: ns.frequency,
|
|
23272
|
+
...intIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
|
|
23273
|
+
...intIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
|
|
23274
|
+
...slsUri ? { slsUri } : {}
|
|
23275
|
+
};
|
|
23276
|
+
}
|
|
23277
|
+
return void 0;
|
|
23278
|
+
}
|
|
22718
23279
|
|
|
22719
23280
|
// src/catalog-fec-params.ts
|
|
22720
23281
|
var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
|
|
@@ -22769,28 +23330,28 @@ function joinedRepairSymbolCount(params, joinedRepairTrackNames) {
|
|
|
22769
23330
|
}
|
|
22770
23331
|
return total;
|
|
22771
23332
|
}
|
|
22772
|
-
function
|
|
23333
|
+
function recordOf3(value) {
|
|
22773
23334
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
22774
23335
|
}
|
|
22775
23336
|
function msfTracks(catalog) {
|
|
22776
23337
|
const raw = catalog.tracks;
|
|
22777
23338
|
if (!Array.isArray(raw)) return void 0;
|
|
22778
|
-
return { tracks: raw.map((t) =>
|
|
23339
|
+
return { tracks: raw.map((t) => recordOf3(t) ?? {}) };
|
|
22779
23340
|
}
|
|
22780
23341
|
function resolveRepairLayers(catalog, source) {
|
|
22781
23342
|
if (!catalog) return void 0;
|
|
22782
23343
|
const sourceName = typeof source === "string" ? source : source.name;
|
|
22783
23344
|
const hang = catalog;
|
|
22784
23345
|
const roles = typeof source === "string" ? ["video", "audio"] : source.type === "audio" ? ["audio"] : source.type === "video" ? ["video"] : ["video", "audio"];
|
|
22785
|
-
const
|
|
22786
|
-
if (
|
|
22787
|
-
const renditionPath = `$.${role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
22788
|
-
const rendition =
|
|
23346
|
+
const located = locateCatalogFecSource(catalog, sourceName, roles);
|
|
23347
|
+
if (located?.dialect === "hang") {
|
|
23348
|
+
const renditionPath = `$.${located.role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
23349
|
+
const rendition = located.entry;
|
|
22789
23350
|
rejectRepairFieldsOnMediaTrack(renditionPath, rendition, throwRepairContractError);
|
|
22790
|
-
const repairRenditions =
|
|
23351
|
+
const repairRenditions = recordOf3(hang.repair?.renditions) ?? {};
|
|
22791
23352
|
const descriptors2 = Object.entries(repairRenditions).map(([name, entry]) => {
|
|
22792
23353
|
const path = `$.repair.renditions[${JSON.stringify(name)}]`;
|
|
22793
|
-
const fields =
|
|
23354
|
+
const fields = recordOf3(entry);
|
|
22794
23355
|
if (fields === void 0) {
|
|
22795
23356
|
throwRepairContractError("track_repair_layer", path, "a repair rendition must be an object");
|
|
22796
23357
|
}
|
|
@@ -22798,14 +23359,14 @@ function resolveRepairLayers(catalog, source) {
|
|
|
22798
23359
|
return describeRepairTrack(name, path, fields);
|
|
22799
23360
|
});
|
|
22800
23361
|
const fecOfRendition = (entry) => {
|
|
22801
|
-
const fec2 =
|
|
23362
|
+
const fec2 = recordOf3(recordOf3(entry)?.["fec"]);
|
|
22802
23363
|
return fec2 !== void 0 && fec2["algorithm"] !== "none" ? fec2 : void 0;
|
|
22803
23364
|
};
|
|
22804
23365
|
const mediaRenditions = [
|
|
22805
|
-
...Object.values(
|
|
22806
|
-
...Object.values(
|
|
23366
|
+
...Object.values(recordOf3(hang.video?.renditions) ?? {}),
|
|
23367
|
+
...Object.values(recordOf3(hang.audio?.renditions) ?? {})
|
|
22807
23368
|
];
|
|
22808
|
-
const reachability2 = repairReachability(mediaRenditions.map((entry) =>
|
|
23369
|
+
const reachability2 = repairReachability(mediaRenditions.map((entry) => recordOf3(entry)?.["fec"]));
|
|
22809
23370
|
for (const d of descriptors2) {
|
|
22810
23371
|
validateRepairTrackFields(d, throwRepairContractError);
|
|
22811
23372
|
assertRepairTrackReachable(d, reachability2, throwRepairContractError);
|
|
@@ -22821,20 +23382,20 @@ function resolveRepairLayers(catalog, source) {
|
|
|
22821
23382
|
}
|
|
22822
23383
|
}
|
|
22823
23384
|
const layers2 = assembleRepairLayers(
|
|
22824
|
-
geometryOf(sourceName, `${renditionPath}.fec`,
|
|
23385
|
+
geometryOf(sourceName, `${renditionPath}.fec`, recordOf3(rendition["fec"])),
|
|
22825
23386
|
descriptors2,
|
|
22826
23387
|
throwRepairContractError
|
|
22827
23388
|
);
|
|
22828
23389
|
return catalogFecUnavailable(rendition["fec"], `${renditionPath}.fec`) === void 0 ? layers2 : void 0;
|
|
22829
23390
|
}
|
|
22830
23391
|
const msf = msfTracks(catalog);
|
|
22831
|
-
|
|
22832
|
-
|
|
23392
|
+
if (!msf || located?.dialect !== "msf") return void 0;
|
|
23393
|
+
const msfIndex = located.index;
|
|
22833
23394
|
const track = msf.tracks[msfIndex];
|
|
22834
|
-
const fec =
|
|
23395
|
+
const fec = recordOf3(track["fec"]);
|
|
22835
23396
|
const packagingOf = (t) => t["packaging"];
|
|
22836
23397
|
const fecOfTrack = (t) => {
|
|
22837
|
-
const trackFec =
|
|
23398
|
+
const trackFec = recordOf3(t?.["fec"]);
|
|
22838
23399
|
return trackFec !== void 0 && trackFec["algorithm"] !== "none" ? trackFec : void 0;
|
|
22839
23400
|
};
|
|
22840
23401
|
const descriptors = [];
|
|
@@ -22884,8 +23445,8 @@ function catalogRepairTarget(catalog, source) {
|
|
|
22884
23445
|
const entry = msf?.tracks.find((t) => t["name"] === sourceName);
|
|
22885
23446
|
const hang = catalog;
|
|
22886
23447
|
const roles = typeof source === "string" ? ["video", "audio"] : source.type === "video" ? ["video"] : source.type === "audio" ? ["audio"] : ["video", "audio"];
|
|
22887
|
-
const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) =>
|
|
22888
|
-
const fec = rendition === void 0 ?
|
|
23448
|
+
const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) => recordOf3(r) !== void 0);
|
|
23449
|
+
const fec = rendition === void 0 ? recordOf3(entry?.["fec"]) : recordOf3(rendition.fec);
|
|
22889
23450
|
if (!fec || !(catalogFecInterleaveMs(fec) ?? 0)) return null;
|
|
22890
23451
|
const sourcePriority = entry === void 0 ? null : moqtPriority2(entry["priority"]);
|
|
22891
23452
|
return { repairTrack: layerZero.repairTrackName, sourcePriority, repairPriority: layerZero.priority };
|
|
@@ -22928,10 +23489,21 @@ function isoSpanUnavailable(fec, path, declaresFecInstance) {
|
|
|
22928
23489
|
});
|
|
22929
23490
|
}
|
|
22930
23491
|
function catalogFecUnavailable(fec, fecPath) {
|
|
22931
|
-
|
|
22932
|
-
|
|
23492
|
+
if (catalogFecAvailable(fec)) return void 0;
|
|
23493
|
+
const block = recordOf3(fec);
|
|
23494
|
+
if (fecAlgorithmUnimplemented(block["algorithm"])) {
|
|
23495
|
+
return Object.freeze({
|
|
23496
|
+
code: "track_fec_algorithm_unimplemented",
|
|
23497
|
+
path: `${fecPath}.algorithm`,
|
|
23498
|
+
message: `algorithm ${JSON.stringify(block["algorithm"])} is not implemented: the track plays without FEC`
|
|
23499
|
+
});
|
|
23500
|
+
}
|
|
22933
23501
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
22934
|
-
|
|
23502
|
+
const reason = blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
|
|
23503
|
+
if (reason === void 0) {
|
|
23504
|
+
throw new Error(`catalogFecUnavailable: ${fecPath} is unavailable but no reason applies (rule drift)`);
|
|
23505
|
+
}
|
|
23506
|
+
return reason;
|
|
22935
23507
|
}
|
|
22936
23508
|
function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
22937
23509
|
const mediaRate = sampleRate === void 0 ? { fps } : { fps, sampleRate };
|
|
@@ -22940,14 +23512,12 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
22940
23512
|
const repair = resolveRepairLayers(catalog, track);
|
|
22941
23513
|
const fecPath = `$.${track.type}.renditions[${JSON.stringify(track.name)}].fec`;
|
|
22942
23514
|
if (!catalogDeclaresFec(fec)) {
|
|
22943
|
-
|
|
22944
|
-
|
|
22945
|
-
const tValid = Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0;
|
|
22946
|
-
if (declaresFecInstance && !(kValid && tValid)) {
|
|
23515
|
+
if (catalogFecDeclaresUnconfigurableInstance(fec)) {
|
|
23516
|
+
const kValid = Number.isSafeInteger(fec.sourceSymbols) && (fec.sourceSymbols ?? 0) > 0;
|
|
22947
23517
|
throwRepairContractError(
|
|
22948
23518
|
"track_fec",
|
|
22949
23519
|
`${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
|
|
22950
|
-
"must be a positive integer"
|
|
23520
|
+
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"
|
|
22951
23521
|
);
|
|
22952
23522
|
}
|
|
22953
23523
|
const fecUnavailable = catalogFecUnavailable(fec, fecPath);
|
|
@@ -22956,6 +23526,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
|
|
|
22956
23526
|
const fecBlockProfile = readFecBlockProfile(fec.blockProfile, `${fecPath}.blockProfile`, true, throwRepairContractError);
|
|
22957
23527
|
return {
|
|
22958
23528
|
fecK: fec.sourceSymbols ?? 0,
|
|
23529
|
+
fecAlgorithm: fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq",
|
|
22959
23530
|
fecBlockProfile,
|
|
22960
23531
|
fecRepairCount: fec.repairSymbols ?? 0,
|
|
22961
23532
|
// The wire RSB_length: every base layer's packets carry the base total (§7.1).
|
|
@@ -23052,8 +23623,10 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
|
|
|
23052
23623
|
repairsSkippedRttUnmeasured: 0,
|
|
23053
23624
|
repairsSkippedRttExceedsBudget: 0,
|
|
23054
23625
|
repairsSkippedPresentationDelayUnavailable: 0,
|
|
23626
|
+
repairsSkippedRangeNoAnchor: 0,
|
|
23055
23627
|
lastRepairSkip: null,
|
|
23056
23628
|
keyframeRepairFetchesSent: 0,
|
|
23629
|
+
rangeRepairFetchesSent: 0,
|
|
23057
23630
|
keyframeBudgetHolds: 0,
|
|
23058
23631
|
keyframeBudgetHoldMs: 0,
|
|
23059
23632
|
deltaBlocksFailed: 0,
|
|
@@ -23132,6 +23705,12 @@ var REPAIR_PRIORITY_REASONS = /* @__PURE__ */ new Set([
|
|
|
23132
23705
|
"repair-priority-absent",
|
|
23133
23706
|
"repair-priority-invalid"
|
|
23134
23707
|
]);
|
|
23708
|
+
var REPAIR_SKIP_REASONS = /* @__PURE__ */ new Set([
|
|
23709
|
+
"rtt-unmeasured",
|
|
23710
|
+
"rtt-exceeds-budget",
|
|
23711
|
+
"presentation-delay-unavailable"
|
|
23712
|
+
]);
|
|
23713
|
+
var REPAIR_DEADLINE_BOUNDS = /* @__PURE__ */ new Set(["wait", "presentation", "keyframe", "retention"]);
|
|
23135
23714
|
var GAP_REASONS = {
|
|
23136
23715
|
"rap-lost": "stall",
|
|
23137
23716
|
"rap-unknown": "stall",
|
|
@@ -23154,6 +23733,9 @@ function isSymbolCounts(value) {
|
|
|
23154
23733
|
function isNullableNonNegative(value) {
|
|
23155
23734
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
23156
23735
|
}
|
|
23736
|
+
function isFiniteNumber(value) {
|
|
23737
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
23738
|
+
}
|
|
23157
23739
|
function isRepairLifecycleEvent(value) {
|
|
23158
23740
|
if (!isRecord(value) || value["version"] !== 2) return false;
|
|
23159
23741
|
const block = value["block"];
|
|
@@ -23171,6 +23753,20 @@ function isRepairLifecycleEvent(value) {
|
|
|
23171
23753
|
case "repair-preempted":
|
|
23172
23754
|
case "repair-deferred":
|
|
23173
23755
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
23756
|
+
case "repair-sent":
|
|
23757
|
+
return hasExactKeys(value, [
|
|
23758
|
+
"version",
|
|
23759
|
+
"type",
|
|
23760
|
+
"block",
|
|
23761
|
+
"priority",
|
|
23762
|
+
"rttMs",
|
|
23763
|
+
"budgetMs",
|
|
23764
|
+
"delayMs",
|
|
23765
|
+
"blockAgeMs",
|
|
23766
|
+
"bound"
|
|
23767
|
+
]) && 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"]);
|
|
23768
|
+
case "repair-skipped":
|
|
23769
|
+
return hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) && isRepairBlockIdentity(block) && REPAIR_SKIP_REASONS.has(value["reason"]) && isNullableNonNegative(value["rttMs"]) && isFiniteNumber(value["budgetMs"]);
|
|
23174
23770
|
case "repair-priority": {
|
|
23175
23771
|
const blockClass = value["blockClass"];
|
|
23176
23772
|
const action = value["action"];
|
|
@@ -23350,6 +23946,9 @@ var MulticastManager = class {
|
|
|
23350
23946
|
#router;
|
|
23351
23947
|
#hostMfuTimeoutMs;
|
|
23352
23948
|
#transport;
|
|
23949
|
+
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
23950
|
+
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
23951
|
+
#repairReleases = /* @__PURE__ */ new Map();
|
|
23353
23952
|
#reportedFecDiagnosticsFailure = false;
|
|
23354
23953
|
// ── Stream-global FEC timing reduction ──
|
|
23355
23954
|
//
|
|
@@ -23613,7 +24212,9 @@ var MulticastManager = class {
|
|
|
23613
24212
|
catalogTrackName
|
|
23614
24213
|
);
|
|
23615
24214
|
this.#configureTrackMapper(packetId, config);
|
|
23616
|
-
this.#router.
|
|
24215
|
+
if (this.#router.trackKindFor(packetId) !== trackType) {
|
|
24216
|
+
this.#router.setPacketIdType(packetId, trackType);
|
|
24217
|
+
}
|
|
23617
24218
|
}
|
|
23618
24219
|
/**
|
|
23619
24220
|
* Stop routing a stream's symbols to its Worker decoder. Returns false when
|
|
@@ -23694,6 +24295,14 @@ var MulticastManager = class {
|
|
|
23694
24295
|
);
|
|
23695
24296
|
}
|
|
23696
24297
|
}
|
|
24298
|
+
for (const [packetId, c] of this.#trackFecTiming) {
|
|
24299
|
+
if (c.deliveryWindowMs === void 0) continue;
|
|
24300
|
+
mfuTimeoutMs = Math.max(
|
|
24301
|
+
mfuTimeoutMs ?? 0,
|
|
24302
|
+
this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
|
|
24303
|
+
this.#hostMfuTimeoutMs ?? 0
|
|
24304
|
+
);
|
|
24305
|
+
}
|
|
23697
24306
|
const failbackWindowMs = deliveryWindowMs === void 0 ? minimumFailbackWindowMs : Math.max(deliveryWindowMs, minimumFailbackWindowMs ?? 0);
|
|
23698
24307
|
this.#transport.setFailbackWindowMs(failbackWindowMs ?? null);
|
|
23699
24308
|
this.#router.setMfuTimeoutMs(mfuTimeoutMs ?? this.#hostMfuTimeoutMs);
|
|
@@ -23877,6 +24486,7 @@ var MulticastManager = class {
|
|
|
23877
24486
|
setMfuTimeoutMs(ms) {
|
|
23878
24487
|
this.#router.setMfuTimeoutMs(ms);
|
|
23879
24488
|
this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
|
|
24489
|
+
if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
|
|
23880
24490
|
}
|
|
23881
24491
|
setTrackCodec(packetId, codec) {
|
|
23882
24492
|
this.#router.setTrackCodec(packetId, codec);
|
|
@@ -23997,11 +24607,80 @@ var MulticastManager = class {
|
|
|
23997
24607
|
// through whatever the relay looks like, since dropping it would be the
|
|
23998
24608
|
// worse behaviour.
|
|
23999
24609
|
amtRelayPort: config.amtRelayPort ?? config.relayPort ?? (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
24610
|
+
amtDiscovery: config.amtDiscovery,
|
|
24000
24611
|
packetIds: config.packetIds,
|
|
24001
24612
|
tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId }))
|
|
24002
24613
|
};
|
|
24003
24614
|
return ingress === void 0 ? this.#transport.join(transportConfig) : this.#transport.join(transportConfig, ingress);
|
|
24004
24615
|
}
|
|
24616
|
+
/**
|
|
24617
|
+
* Join the selected rung's dedicated repair groups beside the media join
|
|
24618
|
+
* (pim #3898): one subscription per endpoint, through `provider` when given
|
|
24619
|
+
* (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
|
|
24620
|
+
* new MulticastTransport on `window.multicast`. Returns the call that
|
|
24621
|
+
* releases every one of them; dispose() releases them too.
|
|
24622
|
+
*
|
|
24623
|
+
* Packets go straight to the router with the endpoint's ingress, never
|
|
24624
|
+
* through feedPacket(): repair arriving on its own group is not media
|
|
24625
|
+
* liveness, so it must not hold off the media leg's failback watchdog. The
|
|
24626
|
+
* repair roles and owners are registered here; in-band owners stay the
|
|
24627
|
+
* caller's. Joining is best effort: a group that fails to join is logged
|
|
24628
|
+
* and leaves the media join as it was.
|
|
24629
|
+
*/
|
|
24630
|
+
joinRepairEndpoints(endpoints, provider) {
|
|
24631
|
+
const releases = [];
|
|
24632
|
+
let released = false;
|
|
24633
|
+
const safely = (each) => {
|
|
24634
|
+
try {
|
|
24635
|
+
each();
|
|
24636
|
+
} catch (error) {
|
|
24637
|
+
console.warn("[MulticastManager] repair group release failed", error);
|
|
24638
|
+
}
|
|
24639
|
+
};
|
|
24640
|
+
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
|
|
24641
|
+
this.#applyRepairOwners(repairOwners);
|
|
24642
|
+
for (const endpoint of endpoints) {
|
|
24643
|
+
const ingress = {
|
|
24644
|
+
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId })))
|
|
24645
|
+
};
|
|
24646
|
+
const onPacket = (packet) => {
|
|
24647
|
+
if (!released) this.#router.feedPacket(packet, "multicast", void 0, ingress);
|
|
24648
|
+
};
|
|
24649
|
+
const fail = (error) => console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
|
|
24650
|
+
if (typeof provider === "function") {
|
|
24651
|
+
Promise.resolve().then(() => provider(endpoint, onPacket)).then((release2) => released ? safely(release2) : releases.push(release2), fail);
|
|
24652
|
+
continue;
|
|
24653
|
+
}
|
|
24654
|
+
const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
|
|
24655
|
+
releases.push(() => transport.dispose());
|
|
24656
|
+
void transport.join({
|
|
24657
|
+
sourceAddress: endpoint.source,
|
|
24658
|
+
groupAddress: endpoint.group,
|
|
24659
|
+
port: endpoint.port,
|
|
24660
|
+
mode: endpoint.mode,
|
|
24661
|
+
amtRelay: endpoint.amtRelay,
|
|
24662
|
+
amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
24663
|
+
packetIds: endpoint.packetIds,
|
|
24664
|
+
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId }))
|
|
24665
|
+
}).then((joined) => {
|
|
24666
|
+
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
24667
|
+
});
|
|
24668
|
+
}
|
|
24669
|
+
const release = () => {
|
|
24670
|
+
if (released) return;
|
|
24671
|
+
released = true;
|
|
24672
|
+
this.#repairReleases.delete(release);
|
|
24673
|
+
for (const each of releases.splice(0)) safely(each);
|
|
24674
|
+
};
|
|
24675
|
+
this.#repairReleases.set(release, repairOwners);
|
|
24676
|
+
return release;
|
|
24677
|
+
}
|
|
24678
|
+
#applyRepairOwners(owners) {
|
|
24679
|
+
for (const { packetId, ownerPacketId } of owners) {
|
|
24680
|
+
this.#router.setPacketIdRole(packetId, "repair");
|
|
24681
|
+
this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
|
|
24682
|
+
}
|
|
24683
|
+
}
|
|
24005
24684
|
// ---------------------------------------------------------------------------
|
|
24006
24685
|
// In-place rendition switch
|
|
24007
24686
|
// ---------------------------------------------------------------------------
|
|
@@ -24277,7 +24956,7 @@ var MulticastManager = class {
|
|
|
24277
24956
|
*
|
|
24278
24957
|
* D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
|
|
24279
24958
|
* D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
|
|
24280
|
-
* D-17: Builds altGroup → track-name index for getSwitchingSet().
|
|
24959
|
+
* D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
|
|
24281
24960
|
* D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
|
|
24282
24961
|
*
|
|
24283
24962
|
* FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
|
|
@@ -24328,11 +25007,9 @@ var MulticastManager = class {
|
|
|
24328
25007
|
}
|
|
24329
25008
|
}
|
|
24330
25009
|
const repairOwnerGroup = /* @__PURE__ */ new Map();
|
|
24331
|
-
const repairOwnerAltGroup = /* @__PURE__ */ new Map();
|
|
24332
25010
|
for (const track of catalog.tracks) {
|
|
24333
25011
|
for (const repairName of repairNamesBySource.get(track.name) ?? []) {
|
|
24334
25012
|
repairOwnerGroup.set(repairName, altGroupKey(track));
|
|
24335
|
-
repairOwnerAltGroup.set(repairName, track.altGroup);
|
|
24336
25013
|
}
|
|
24337
25014
|
}
|
|
24338
25015
|
const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
|
|
@@ -24363,11 +25040,7 @@ var MulticastManager = class {
|
|
|
24363
25040
|
for (const [groupKey, roles] of resolvedRolesByGroup) {
|
|
24364
25041
|
if (!(hasSwitchingSetByGroup.get(groupKey) ?? false)) continue;
|
|
24365
25042
|
const presentRoles = new Set(roles.filter((r) => r !== "single"));
|
|
24366
|
-
const required = [
|
|
24367
|
-
"base",
|
|
24368
|
-
"delta",
|
|
24369
|
-
"repair"
|
|
24370
|
-
];
|
|
25043
|
+
const required = ["base", "repair"];
|
|
24371
25044
|
const missing = required.filter((r) => !presentRoles.has(r));
|
|
24372
25045
|
if (missing.length > 0) {
|
|
24373
25046
|
throw new Error(
|
|
@@ -24414,6 +25087,7 @@ var MulticastManager = class {
|
|
|
24414
25087
|
this.#switchingSets.clear();
|
|
24415
25088
|
this.#repairPacketIds.clear();
|
|
24416
25089
|
this.#router.clearRepairPacketIdOwners();
|
|
25090
|
+
for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
|
|
24417
25091
|
const fecPacketIds = new Set([...fecDecoders.keys()].map((i) => catalog.tracks[i].packetId));
|
|
24418
25092
|
for (const [packetId, catalogTrackName] of this.#multiTrackFecTracks) {
|
|
24419
25093
|
if (fecPacketIds.has(packetId)) continue;
|
|
@@ -24434,11 +25108,10 @@ var MulticastManager = class {
|
|
|
24434
25108
|
for (let i = 0; i < catalog.tracks.length; i++) {
|
|
24435
25109
|
const track = catalog.tracks[i];
|
|
24436
25110
|
const role = resolvedRoles[i];
|
|
24437
|
-
|
|
24438
|
-
|
|
24439
|
-
const existing = this.#switchingSets.get(altGroup) ?? [];
|
|
25111
|
+
if (role !== "repair" && track.altGroup !== void 0) {
|
|
25112
|
+
const existing = this.#switchingSets.get(track.altGroup) ?? [];
|
|
24440
25113
|
existing.push(track.name);
|
|
24441
|
-
this.#switchingSets.set(altGroup, existing);
|
|
25114
|
+
this.#switchingSets.set(track.altGroup, existing);
|
|
24442
25115
|
}
|
|
24443
25116
|
if (track.packetId !== void 0) {
|
|
24444
25117
|
this.#router.setPacketIdRole(track.packetId, role);
|
|
@@ -24513,7 +25186,7 @@ var MulticastManager = class {
|
|
|
24513
25186
|
#multiTrackFecTracks = /* @__PURE__ */ new Map();
|
|
24514
25187
|
/**
|
|
24515
25188
|
* Return the track names belonging to the given altGroup switching set.
|
|
24516
|
-
* D-17:
|
|
25189
|
+
* D-17: tracks with equal altGroup form one switching set; repair legs are in none.
|
|
24517
25190
|
*
|
|
24518
25191
|
* @param altGroup - The altGroup number to look up.
|
|
24519
25192
|
* @returns Array of track names in that switching set (empty if none).
|
|
@@ -24541,6 +25214,26 @@ var MulticastManager = class {
|
|
|
24541
25214
|
this.requestRepairForBlock(sbn, packetId, catalogTrackName, blockClass);
|
|
24542
25215
|
};
|
|
24543
25216
|
}
|
|
25217
|
+
/**
|
|
25218
|
+
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
25219
|
+
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
25220
|
+
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
25221
|
+
* once its range FETCH ends (or none is sent).
|
|
25222
|
+
*/
|
|
25223
|
+
onUndelimitedLoss(cb) {
|
|
25224
|
+
this.#fec.setUndelimitedLossHandler(cb);
|
|
25225
|
+
}
|
|
25226
|
+
/**
|
|
25227
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
25228
|
+
* to CmcdProducer.updateFecFailClosed.
|
|
25229
|
+
*/
|
|
25230
|
+
onFecFailClosed(cb) {
|
|
25231
|
+
this.#fec.setFecFailClosedHandler(cb);
|
|
25232
|
+
}
|
|
25233
|
+
/** End a pending hole's range repair: feed what no repair stated as spans. */
|
|
25234
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
25235
|
+
this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
|
|
25236
|
+
}
|
|
24544
25237
|
/**
|
|
24545
25238
|
* Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
|
|
24546
25239
|
* supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
|
|
@@ -24562,6 +25255,7 @@ var MulticastManager = class {
|
|
|
24562
25255
|
stats.repairsSkipped++;
|
|
24563
25256
|
if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
|
|
24564
25257
|
else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
|
|
25258
|
+
else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
|
|
24565
25259
|
else stats.repairsSkippedPresentationDelayUnavailable++;
|
|
24566
25260
|
stats.lastRepairSkip = {
|
|
24567
25261
|
reason,
|
|
@@ -24593,8 +25287,20 @@ var MulticastManager = class {
|
|
|
24593
25287
|
stats.keyframeBudgetHoldMs += extensionMs;
|
|
24594
25288
|
}
|
|
24595
25289
|
/** Record a repair FETCH the scheduler admitted and sent. */
|
|
24596
|
-
noteRepairFetchSent(priority,
|
|
25290
|
+
noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
|
|
24597
25291
|
if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
|
|
25292
|
+
if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
|
|
25293
|
+
this.#emitRepairLifecycle({
|
|
25294
|
+
version: 2,
|
|
25295
|
+
type: "repair-sent",
|
|
25296
|
+
block: repairBlockIdentity(packetId, sbn, catalogTrackName),
|
|
25297
|
+
priority,
|
|
25298
|
+
rttMs: measurement.rttMs,
|
|
25299
|
+
budgetMs: measurement.budgetMs,
|
|
25300
|
+
delayMs: measurement.delayMs,
|
|
25301
|
+
blockAgeMs: measurement.blockAgeMs,
|
|
25302
|
+
bound: measurement.bound
|
|
25303
|
+
});
|
|
24598
25304
|
}
|
|
24599
25305
|
/**
|
|
24600
25306
|
* Record a repair-scheduler decision about a delta block: preempted for
|
|
@@ -24745,6 +25451,7 @@ var MulticastManager = class {
|
|
|
24745
25451
|
this.#trackResetObservers.clear();
|
|
24746
25452
|
this.#repairLifecycleObservers.clear();
|
|
24747
25453
|
this.#transport.dispose();
|
|
25454
|
+
for (const release of [...this.#repairReleases.keys()]) release();
|
|
24748
25455
|
this.#router.dispose();
|
|
24749
25456
|
this.#fec.dispose();
|
|
24750
25457
|
}
|
|
@@ -24820,7 +25527,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24820
25527
|
trackType: opts.trackType,
|
|
24821
25528
|
framerate: opts.framerate,
|
|
24822
25529
|
sampleRate: opts.sampleRate,
|
|
24823
|
-
algorithm: "
|
|
25530
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
24824
25531
|
blockProfile,
|
|
24825
25532
|
k: opts.fecK,
|
|
24826
25533
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
@@ -24834,10 +25541,10 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24834
25541
|
repairTrack: opts.repairTrackName,
|
|
24835
25542
|
relayBlockSigEnabled: false
|
|
24836
25543
|
};
|
|
24837
|
-
client.configure(fecTrackConfig, rqWasm);
|
|
24838
25544
|
try {
|
|
24839
25545
|
opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
|
|
24840
25546
|
blockProfile,
|
|
25547
|
+
algorithm: opts.fecAlgorithm ?? "raptorq",
|
|
24841
25548
|
k: opts.fecK,
|
|
24842
25549
|
symbolSize: opts.fecSymbolSize,
|
|
24843
25550
|
interleaveDepthMs: opts.fecInterleaveMs,
|
|
@@ -24845,7 +25552,9 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24845
25552
|
// the local cleanup budget, but it must not use a guessed fps for timing
|
|
24846
25553
|
// or classification.
|
|
24847
25554
|
...hasCatalogTiming ? { fps: 1e3 / opts.mediaUnitDurationMs } : {},
|
|
24848
|
-
timeoutMs: deliveryWindowMs
|
|
25555
|
+
timeoutMs: deliveryWindowMs,
|
|
25556
|
+
...opts.fecRepairLayers ? { repairLayers: opts.fecRepairLayers } : {},
|
|
25557
|
+
...opts.heldRepairLayers ? { heldLayers: opts.heldRepairLayers } : {}
|
|
24849
25558
|
}, opts.trackName);
|
|
24850
25559
|
} catch (e) {
|
|
24851
25560
|
try {
|
|
@@ -24854,6 +25563,14 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
24854
25563
|
}
|
|
24855
25564
|
throw e;
|
|
24856
25565
|
}
|
|
25566
|
+
fecTrackConfig.interleaveDepth = Math.min(
|
|
25567
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
25568
|
+
Math.max(
|
|
25569
|
+
interleaveDepthBlocks,
|
|
25570
|
+
opts.multicastManager.fecManager.isoRetentionBlocksForPacket(opts.packetId) ?? 0
|
|
25571
|
+
)
|
|
25572
|
+
);
|
|
25573
|
+
client.configure(fecTrackConfig, rqWasm);
|
|
24857
25574
|
let disposed = false;
|
|
24858
25575
|
return {
|
|
24859
25576
|
client,
|
|
@@ -25503,7 +26220,7 @@ function asSeconds(n) {
|
|
|
25503
26220
|
}
|
|
25504
26221
|
return n;
|
|
25505
26222
|
}
|
|
25506
|
-
function groupIdForTicks(ticks, groupDurationTicks) {
|
|
26223
|
+
function groupIdForTicks(ticks, groupDurationTicks, presentationAnchorTicks = 0) {
|
|
25507
26224
|
if (!Number.isInteger(ticks)) {
|
|
25508
26225
|
throw new Error(
|
|
25509
26226
|
`[align] groupIdForTicks: ticks must be an integer, got ${ticks}`
|
|
@@ -25514,8 +26231,23 @@ function groupIdForTicks(ticks, groupDurationTicks) {
|
|
|
25514
26231
|
`[align] groupIdForTicks: groupDurationTicks must be a positive integer, got ${groupDurationTicks}`
|
|
25515
26232
|
);
|
|
25516
26233
|
}
|
|
25517
|
-
if (
|
|
25518
|
-
|
|
26234
|
+
if (!Number.isInteger(presentationAnchorTicks)) {
|
|
26235
|
+
throw new Error(
|
|
26236
|
+
`[align] groupIdForTicks: presentationAnchorTicks must be an integer, got ${presentationAnchorTicks}`
|
|
26237
|
+
);
|
|
26238
|
+
}
|
|
26239
|
+
const relativeTicks = ticks - presentationAnchorTicks;
|
|
26240
|
+
if (!Number.isSafeInteger(relativeTicks)) {
|
|
26241
|
+
throw new Error(
|
|
26242
|
+
`[align] groupIdForTicks: ticks - presentationAnchorTicks = ${relativeTicks} is not a safe integer`
|
|
26243
|
+
);
|
|
26244
|
+
}
|
|
26245
|
+
if (relativeTicks < 0) {
|
|
26246
|
+
throw new Error(
|
|
26247
|
+
`[align] groupIdForTicks: ticks ${ticks} precede presentationAnchorTicks ${presentationAnchorTicks}; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26248
|
+
);
|
|
26249
|
+
}
|
|
26250
|
+
return Math.floor(relativeTicks / groupDurationTicks);
|
|
25519
26251
|
}
|
|
25520
26252
|
function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
25521
26253
|
if (!Number.isFinite(mediaTimeSec)) {
|
|
@@ -25528,7 +26260,11 @@ function groupIdFor(mediaTimeSec, groupDurationSec) {
|
|
|
25528
26260
|
`[align] groupIdFor: groupDurationSec must be a positive finite number, got ${groupDurationSec}`
|
|
25529
26261
|
);
|
|
25530
26262
|
}
|
|
25531
|
-
if (mediaTimeSec < 0)
|
|
26263
|
+
if (mediaTimeSec < 0) {
|
|
26264
|
+
throw new Error(
|
|
26265
|
+
`[align] groupIdFor: mediaTimeSec ${mediaTimeSec} precedes presentationAnchorTicks 0; the publisher must reject this MPU (moq-mmt-01 4.4.1)`
|
|
26266
|
+
);
|
|
26267
|
+
}
|
|
25532
26268
|
const TS = 1e9;
|
|
25533
26269
|
const ticks = Math.round(mediaTimeSec * TS);
|
|
25534
26270
|
const durTicks = Math.round(groupDurationSec * TS);
|
|
@@ -26369,6 +27105,7 @@ var CmcdProducer = class {
|
|
|
26369
27105
|
#deltaFailRate = null;
|
|
26370
27106
|
#switchMiscount = 0;
|
|
26371
27107
|
#manifestStats = null;
|
|
27108
|
+
#fecFailClosed = null;
|
|
26372
27109
|
constructor(options) {
|
|
26373
27110
|
this.#onCmcdParams = options.onCmcdParams;
|
|
26374
27111
|
this.#onCmcdPost = options.onCmcdPost;
|
|
@@ -26410,6 +27147,15 @@ var CmcdProducer = class {
|
|
|
26410
27147
|
incrementSwitchMiscount() {
|
|
26411
27148
|
this.#switchMiscount += 1;
|
|
26412
27149
|
}
|
|
27150
|
+
/**
|
|
27151
|
+
* Record that FEC failed closed at runtime (fec-01 6.3.9). Every later
|
|
27152
|
+
* snapshot carries `x-bc-fec-fail-closed` (the reason code) and
|
|
27153
|
+
* `x-bc-fec-fail-layer` (the held layer i whose total B_i was undercut), so a
|
|
27154
|
+
* stream playing without FEC is told apart from one with no loss.
|
|
27155
|
+
*/
|
|
27156
|
+
updateFecFailClosed(reason) {
|
|
27157
|
+
this.#fecFailClosed = reason;
|
|
27158
|
+
}
|
|
26413
27159
|
updateManifestVerification(stats) {
|
|
26414
27160
|
this.#manifestStats = stats;
|
|
26415
27161
|
}
|
|
@@ -26447,6 +27193,10 @@ var CmcdProducer = class {
|
|
|
26447
27193
|
if (this.#playMode !== null) {
|
|
26448
27194
|
params["x-bc-play-mode"] = this.#playMode;
|
|
26449
27195
|
}
|
|
27196
|
+
if (this.#fecFailClosed) {
|
|
27197
|
+
params["x-bc-fec-fail-closed"] = this.#fecFailClosed.code;
|
|
27198
|
+
params["x-bc-fec-fail-layer"] = this.#fecFailClosed.layer;
|
|
27199
|
+
}
|
|
26450
27200
|
if (this.#playMode !== null && this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
26451
27201
|
params["x-bc-delta-fail-rate"] = parseFloat(this.#deltaFailRate.toFixed(4));
|
|
26452
27202
|
}
|
|
@@ -26499,6 +27249,346 @@ var CmcdProducer = class {
|
|
|
26499
27249
|
}
|
|
26500
27250
|
};
|
|
26501
27251
|
|
|
27252
|
+
// src/mmtp-fec-session.ts
|
|
27253
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
27254
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
27255
|
+
var MmtpFecSession = class {
|
|
27256
|
+
#decoder;
|
|
27257
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
27258
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
27259
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
27260
|
+
#settled = /* @__PURE__ */ new Set();
|
|
27261
|
+
/**
|
|
27262
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
27263
|
+
* received on, or 0 for one the session recovered.
|
|
27264
|
+
*/
|
|
27265
|
+
#have = /* @__PURE__ */ new Map();
|
|
27266
|
+
#newest;
|
|
27267
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
27268
|
+
#prunedAt;
|
|
27269
|
+
#repairPacketId;
|
|
27270
|
+
#stats = {
|
|
27271
|
+
sourceSymbols: 0,
|
|
27272
|
+
repairSymbols: 0,
|
|
27273
|
+
blocksClean: 0,
|
|
27274
|
+
blocksRecovered: 0,
|
|
27275
|
+
blocksFailed: 0,
|
|
27276
|
+
blocksReleased: 0,
|
|
27277
|
+
packetsRecovered: 0,
|
|
27278
|
+
packetsLost: 0,
|
|
27279
|
+
dropped: {},
|
|
27280
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27281
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
27282
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
27283
|
+
};
|
|
27284
|
+
/**
|
|
27285
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
27286
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
27287
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
27288
|
+
*/
|
|
27289
|
+
constructor(config) {
|
|
27290
|
+
const fec = config?.fec;
|
|
27291
|
+
if (!fec || typeof fec !== "object") {
|
|
27292
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
27293
|
+
}
|
|
27294
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
27295
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
27296
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
27297
|
+
}
|
|
27298
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
27299
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
27300
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
27301
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
27302
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
27303
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
27304
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
27305
|
+
interleaveDepthMs
|
|
27306
|
+
);
|
|
27307
|
+
if (typeof config.Decoder !== "function") {
|
|
27308
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
27309
|
+
}
|
|
27310
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
27311
|
+
try {
|
|
27312
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
27313
|
+
} catch (error) {
|
|
27314
|
+
decoder.free();
|
|
27315
|
+
throw error;
|
|
27316
|
+
}
|
|
27317
|
+
this.#decoder = decoder;
|
|
27318
|
+
}
|
|
27319
|
+
/** True once release() ran. */
|
|
27320
|
+
get released() {
|
|
27321
|
+
return this.#decoder === null;
|
|
27322
|
+
}
|
|
27323
|
+
get stats() {
|
|
27324
|
+
return {
|
|
27325
|
+
...this.#stats,
|
|
27326
|
+
dropped: { ...this.#stats.dropped },
|
|
27327
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
27328
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
27329
|
+
mixedPath: { ...this.#stats.mixedPath }
|
|
27330
|
+
};
|
|
27331
|
+
}
|
|
27332
|
+
/**
|
|
27333
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
27334
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
27335
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
27336
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
27337
|
+
*
|
|
27338
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
27339
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
27340
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
27341
|
+
*/
|
|
27342
|
+
addSource(ssId, packet, path = "moq") {
|
|
27343
|
+
const decoder = this.#decoder;
|
|
27344
|
+
if (!decoder) return this.#drop("source:released");
|
|
27345
|
+
const pathBit = PATH_BITS[path];
|
|
27346
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
27347
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
27348
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
27349
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
27350
|
+
this.#have.set(ssId, pathBit);
|
|
27351
|
+
this.#stats.sourceSymbols++;
|
|
27352
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
27353
|
+
this.#noteNewest(ssId);
|
|
27354
|
+
const start = this.#blockStartOf(ssId);
|
|
27355
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
27356
|
+
if (block) {
|
|
27357
|
+
block.received++;
|
|
27358
|
+
block.paths |= pathBit;
|
|
27359
|
+
}
|
|
27360
|
+
let output;
|
|
27361
|
+
try {
|
|
27362
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
27363
|
+
} catch {
|
|
27364
|
+
this.#drop("source:decoder-refused");
|
|
27365
|
+
output = void 0;
|
|
27366
|
+
}
|
|
27367
|
+
const recovered = [];
|
|
27368
|
+
if (start !== void 0 && block) {
|
|
27369
|
+
if (output) {
|
|
27370
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
27371
|
+
} else if (block.received >= block.ssbLength) {
|
|
27372
|
+
this.#settleClean(start);
|
|
27373
|
+
}
|
|
27374
|
+
}
|
|
27375
|
+
this.#retireBehindHorizon();
|
|
27376
|
+
return recovered;
|
|
27377
|
+
}
|
|
27378
|
+
/**
|
|
27379
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
27380
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
27381
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
27382
|
+
* `path` is where it was received, as for addSource().
|
|
27383
|
+
*
|
|
27384
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
27385
|
+
* addSource().
|
|
27386
|
+
*/
|
|
27387
|
+
addRepair(packet, path = "moq") {
|
|
27388
|
+
const decoder = this.#decoder;
|
|
27389
|
+
if (!decoder) return this.#drop("repair:released");
|
|
27390
|
+
const pathBit = PATH_BITS[path];
|
|
27391
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
27392
|
+
let header;
|
|
27393
|
+
try {
|
|
27394
|
+
header = parseMMTPHeader(packet);
|
|
27395
|
+
} catch {
|
|
27396
|
+
return this.#drop("repair:malformed");
|
|
27397
|
+
}
|
|
27398
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
27399
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
27400
|
+
if (this.#repairPacketId === void 0) {
|
|
27401
|
+
this.#repairPacketId = frame.packetId;
|
|
27402
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
27403
|
+
return this.#drop("repair:foreign-packet-id");
|
|
27404
|
+
}
|
|
27405
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
27406
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
27407
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
27408
|
+
return this.#drop("repair:rs-block-length");
|
|
27409
|
+
}
|
|
27410
|
+
const start = frame.ssStart;
|
|
27411
|
+
let block = this.#blocks.get(start);
|
|
27412
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
27413
|
+
if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
|
|
27414
|
+
if (!block) {
|
|
27415
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
27416
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
27417
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
27418
|
+
this.#countHeld(start, block);
|
|
27419
|
+
this.#blocks.set(start, block);
|
|
27420
|
+
}
|
|
27421
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
27422
|
+
if (block.received >= block.ssbLength) {
|
|
27423
|
+
this.#settleClean(start);
|
|
27424
|
+
this.#retireBehindHorizon();
|
|
27425
|
+
return [];
|
|
27426
|
+
}
|
|
27427
|
+
let output;
|
|
27428
|
+
try {
|
|
27429
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
27430
|
+
} catch {
|
|
27431
|
+
return this.#drop("repair:decoder-refused");
|
|
27432
|
+
}
|
|
27433
|
+
block.rsIds.add(frame.rsId);
|
|
27434
|
+
this.#stats.repairSymbols++;
|
|
27435
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
27436
|
+
block.paths |= pathBit;
|
|
27437
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
27438
|
+
this.#retireBehindHorizon();
|
|
27439
|
+
return recovered;
|
|
27440
|
+
}
|
|
27441
|
+
/**
|
|
27442
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
27443
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
27444
|
+
* returns whether this call released anything.
|
|
27445
|
+
*/
|
|
27446
|
+
release() {
|
|
27447
|
+
const decoder = this.#decoder;
|
|
27448
|
+
if (!decoder) return false;
|
|
27449
|
+
this.#decoder = null;
|
|
27450
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
27451
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
27452
|
+
this.#blocks.clear();
|
|
27453
|
+
this.#settled.clear();
|
|
27454
|
+
this.#have.clear();
|
|
27455
|
+
decoder.free();
|
|
27456
|
+
return true;
|
|
27457
|
+
}
|
|
27458
|
+
#drop(reason) {
|
|
27459
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
27460
|
+
return [];
|
|
27461
|
+
}
|
|
27462
|
+
#noteNewest(ssId) {
|
|
27463
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
27464
|
+
}
|
|
27465
|
+
#blockStartOf(ssId) {
|
|
27466
|
+
for (const [start, block] of this.#blocks) {
|
|
27467
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
27468
|
+
}
|
|
27469
|
+
return void 0;
|
|
27470
|
+
}
|
|
27471
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
27472
|
+
#countHeld(start, block) {
|
|
27473
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27474
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
27475
|
+
if (pathBit === void 0) continue;
|
|
27476
|
+
block.received++;
|
|
27477
|
+
block.paths |= pathBit;
|
|
27478
|
+
}
|
|
27479
|
+
}
|
|
27480
|
+
#noteMixed(block, outcome) {
|
|
27481
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
27482
|
+
}
|
|
27483
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
27484
|
+
#behindHorizon(start) {
|
|
27485
|
+
const newest = this.#newest;
|
|
27486
|
+
if (newest === void 0) return false;
|
|
27487
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
27488
|
+
}
|
|
27489
|
+
#settle(start) {
|
|
27490
|
+
this.#blocks.delete(start);
|
|
27491
|
+
this.#settled.add(start);
|
|
27492
|
+
}
|
|
27493
|
+
#settleClean(start) {
|
|
27494
|
+
const block = this.#blocks.get(start);
|
|
27495
|
+
if (!block) return;
|
|
27496
|
+
this.#settle(start);
|
|
27497
|
+
this.#stats.blocksClean++;
|
|
27498
|
+
this.#noteMixed(block, "clean");
|
|
27499
|
+
try {
|
|
27500
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
27501
|
+
} catch {
|
|
27502
|
+
}
|
|
27503
|
+
}
|
|
27504
|
+
/**
|
|
27505
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
27506
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
27507
|
+
* back the packets the parser does not have yet.
|
|
27508
|
+
*/
|
|
27509
|
+
#settleDecoded(start, block, output) {
|
|
27510
|
+
this.#settle(start);
|
|
27511
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
27512
|
+
this.#stats.blocksFailed++;
|
|
27513
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27514
|
+
this.#noteMixed(block, "failed");
|
|
27515
|
+
this.#drop("block:decoded-length");
|
|
27516
|
+
return [];
|
|
27517
|
+
}
|
|
27518
|
+
const recovered = [];
|
|
27519
|
+
let refused = 0;
|
|
27520
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
27521
|
+
const ssId = serial32Add(start, i);
|
|
27522
|
+
if (this.#have.has(ssId)) continue;
|
|
27523
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
27524
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
27525
|
+
if (!packet) {
|
|
27526
|
+
refused++;
|
|
27527
|
+
continue;
|
|
27528
|
+
}
|
|
27529
|
+
this.#have.set(ssId, 0);
|
|
27530
|
+
recovered.push(packet.slice());
|
|
27531
|
+
}
|
|
27532
|
+
if (refused > 0) {
|
|
27533
|
+
this.#stats.blocksFailed++;
|
|
27534
|
+
this.#stats.packetsLost += refused;
|
|
27535
|
+
this.#noteMixed(block, "failed");
|
|
27536
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
27537
|
+
} else if (recovered.length === 0) {
|
|
27538
|
+
this.#stats.blocksClean++;
|
|
27539
|
+
this.#noteMixed(block, "clean");
|
|
27540
|
+
} else {
|
|
27541
|
+
this.#stats.blocksRecovered++;
|
|
27542
|
+
this.#noteMixed(block, "recovered");
|
|
27543
|
+
}
|
|
27544
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
27545
|
+
return recovered;
|
|
27546
|
+
}
|
|
27547
|
+
/**
|
|
27548
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
27549
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
27550
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
27551
|
+
* restore, or its repair never arrived.
|
|
27552
|
+
*/
|
|
27553
|
+
#retireBehindHorizon() {
|
|
27554
|
+
const decoder = this.#decoder;
|
|
27555
|
+
const newest = this.#newest;
|
|
27556
|
+
if (!decoder || newest === void 0) return;
|
|
27557
|
+
try {
|
|
27558
|
+
decoder.cleanup_by_ss_start(newest);
|
|
27559
|
+
} catch {
|
|
27560
|
+
}
|
|
27561
|
+
for (const [start, block] of this.#blocks) {
|
|
27562
|
+
if (!this.#behindHorizon(start)) continue;
|
|
27563
|
+
this.#settle(start);
|
|
27564
|
+
this.#stats.blocksFailed++;
|
|
27565
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
27566
|
+
this.#noteMixed(block, "failed");
|
|
27567
|
+
}
|
|
27568
|
+
const prunedAt = this.#prunedAt;
|
|
27569
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
27570
|
+
this.#prunedAt = newest;
|
|
27571
|
+
for (const ssId of this.#have.keys()) {
|
|
27572
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
27573
|
+
}
|
|
27574
|
+
for (const start of this.#settled) {
|
|
27575
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
27576
|
+
}
|
|
27577
|
+
}
|
|
27578
|
+
};
|
|
27579
|
+
function requirePositiveInteger(value, path) {
|
|
27580
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
27581
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
27582
|
+
}
|
|
27583
|
+
return value;
|
|
27584
|
+
}
|
|
27585
|
+
function requireNumber(value, path) {
|
|
27586
|
+
if (typeof value !== "number") {
|
|
27587
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
27588
|
+
}
|
|
27589
|
+
return value;
|
|
27590
|
+
}
|
|
27591
|
+
|
|
26502
27592
|
// src/repair-fetch.ts
|
|
26503
27593
|
var MOQT_PRIORITY_MAX = 255;
|
|
26504
27594
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
@@ -26533,6 +27623,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26533
27623
|
if (typeof opts.presentationDelayMs !== "function") {
|
|
26534
27624
|
throw new Error("[RepairFetch] presentationDelayMs is required: a repair FETCH is due by the block's presentation deadline");
|
|
26535
27625
|
}
|
|
27626
|
+
if (opts.rangeTransport !== void 0 && (typeof opts.repairEpochReference !== "function" || !mc.onUndelimitedLoss || !mc.closeIsoHoles)) {
|
|
27627
|
+
throw new Error("[RepairFetch] rangeTransport needs repairEpochReference and a host that reports undelimited losses");
|
|
27628
|
+
}
|
|
26536
27629
|
const entries = /* @__PURE__ */ new Map();
|
|
26537
27630
|
const warnedNoTarget = /* @__PURE__ */ new Set();
|
|
26538
27631
|
let disposed = false;
|
|
@@ -26546,7 +27639,12 @@ function wireRepairFetch(mc, opts) {
|
|
|
26546
27639
|
const note = (type, entry) => {
|
|
26547
27640
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26548
27641
|
};
|
|
27642
|
+
const clearEntry = (entry) => {
|
|
27643
|
+
if (entry.range) mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength);
|
|
27644
|
+
else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
27645
|
+
};
|
|
26549
27646
|
const releaseHold = (entry) => {
|
|
27647
|
+
if (entry.range) return;
|
|
26550
27648
|
if (entry.catalogTrackName === void 0) mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId);
|
|
26551
27649
|
else mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
26552
27650
|
};
|
|
@@ -26579,10 +27677,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
26579
27677
|
const admit = (entry, now) => {
|
|
26580
27678
|
const budgetMs = entry.deadlineAt - now;
|
|
26581
27679
|
const rttMs = readRtt();
|
|
26582
|
-
if (rttMs !== null && rttMs < budgetMs) return
|
|
27680
|
+
if (rttMs !== null && rttMs < budgetMs) return rttMs;
|
|
26583
27681
|
retire(entry);
|
|
26584
27682
|
releaseHold(entry);
|
|
26585
|
-
|
|
27683
|
+
clearEntry(entry);
|
|
26586
27684
|
mc.noteRepairSkipped(
|
|
26587
27685
|
rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
|
|
26588
27686
|
{ rttMs, budgetMs, priority: entry.priority },
|
|
@@ -26590,10 +27688,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
26590
27688
|
entry.packetId,
|
|
26591
27689
|
entry.catalogTrackName
|
|
26592
27690
|
);
|
|
26593
|
-
return
|
|
27691
|
+
return null;
|
|
26594
27692
|
};
|
|
26595
27693
|
const retire = (entry) => {
|
|
26596
27694
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
27695
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
26597
27696
|
};
|
|
26598
27697
|
const urgentOutstanding = () => {
|
|
26599
27698
|
for (const entry of entries.values()) {
|
|
@@ -26622,17 +27721,28 @@ function wireRepairFetch(mc, opts) {
|
|
|
26622
27721
|
return derived.kind === "omit" ? { subscriberPriority: void 0 } : null;
|
|
26623
27722
|
};
|
|
26624
27723
|
const start = (entry, counted = true) => {
|
|
26625
|
-
|
|
27724
|
+
const now = performance.now();
|
|
27725
|
+
const rttMs = admit(entry, now);
|
|
27726
|
+
if (rttMs === null) return;
|
|
26626
27727
|
if (counted) entry.attempts++;
|
|
26627
|
-
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName
|
|
27728
|
+
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
27729
|
+
rttMs,
|
|
27730
|
+
budgetMs: entry.deadlineAt - now,
|
|
27731
|
+
delayMs: entry.delayMs,
|
|
27732
|
+
blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
|
|
27733
|
+
bound: entry.bound,
|
|
27734
|
+
...entry.range ? { range: true } : {}
|
|
27735
|
+
});
|
|
26628
27736
|
const run = { controller: new AbortController(), stopped: null };
|
|
26629
27737
|
entry.running = run;
|
|
26630
|
-
|
|
26631
|
-
|
|
26632
|
-
|
|
26633
|
-
|
|
26634
|
-
|
|
26635
|
-
|
|
27738
|
+
if (!entry.range) {
|
|
27739
|
+
mc.fecManager.holdBlockForRepair(
|
|
27740
|
+
entry.sbn,
|
|
27741
|
+
entry.packetId,
|
|
27742
|
+
entry.catalogTrackName,
|
|
27743
|
+
entry.deadlineAt
|
|
27744
|
+
);
|
|
27745
|
+
}
|
|
26636
27746
|
void execute(entry, run);
|
|
26637
27747
|
};
|
|
26638
27748
|
const dispatch = () => {
|
|
@@ -26644,14 +27754,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
26644
27754
|
if (entry.deadlineAt <= now) {
|
|
26645
27755
|
stop(entry, "expired");
|
|
26646
27756
|
retire(entry);
|
|
26647
|
-
|
|
27757
|
+
clearEntry(entry);
|
|
26648
27758
|
}
|
|
26649
27759
|
continue;
|
|
26650
27760
|
}
|
|
26651
27761
|
if (entry.deadlineAt <= now) {
|
|
26652
27762
|
retire(entry);
|
|
26653
27763
|
if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
|
|
26654
|
-
|
|
27764
|
+
clearEntry(entry);
|
|
26655
27765
|
continue;
|
|
26656
27766
|
}
|
|
26657
27767
|
queued.push(entry);
|
|
@@ -26688,9 +27798,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26688
27798
|
entry.running = null;
|
|
26689
27799
|
if (error === void 0) {
|
|
26690
27800
|
retire(entry);
|
|
26691
|
-
if (fed === 0 || !decodable(entry)) {
|
|
27801
|
+
if (entry.range || fed === 0 || !decodable(entry)) {
|
|
26692
27802
|
releaseHold(entry);
|
|
26693
|
-
|
|
27803
|
+
clearEntry(entry);
|
|
26694
27804
|
}
|
|
26695
27805
|
dispatch();
|
|
26696
27806
|
return;
|
|
@@ -26702,7 +27812,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26702
27812
|
}
|
|
26703
27813
|
retire(entry);
|
|
26704
27814
|
if (fed === 0) releaseHold(entry);
|
|
26705
|
-
|
|
27815
|
+
clearEntry(entry);
|
|
26706
27816
|
console.warn(
|
|
26707
27817
|
`[RepairFetch] fetch failed pid=${entry.packetId} sbn=${entry.sbn} track=${entry.repairTrack}:`,
|
|
26708
27818
|
error
|
|
@@ -26718,15 +27828,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
26718
27828
|
};
|
|
26719
27829
|
const execute = async (entry, run) => {
|
|
26720
27830
|
let fed = 0;
|
|
27831
|
+
const common = {
|
|
27832
|
+
repairTrack: entry.repairTrack,
|
|
27833
|
+
blockProfile: entry.blockProfile,
|
|
27834
|
+
packetId: entry.packetId,
|
|
27835
|
+
signal: run.controller.signal,
|
|
27836
|
+
subscriberPriority: entry.subscriberPriority
|
|
27837
|
+
};
|
|
26721
27838
|
try {
|
|
26722
|
-
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
|
|
26728
|
-
|
|
26729
|
-
})) {
|
|
27839
|
+
const packets = entry.range ? opts.rangeTransport({
|
|
27840
|
+
...common,
|
|
27841
|
+
startGroup: entry.range.startGroup,
|
|
27842
|
+
endGroup: entry.range.endGroup,
|
|
27843
|
+
lostSsId: entry.range.lostSsId
|
|
27844
|
+
}) : opts.transport({ ...common, sbn: entry.sbn });
|
|
27845
|
+
for await (const packet of packets) {
|
|
26730
27846
|
if (run.stopped !== null || entry.running !== run) break;
|
|
26731
27847
|
fed++;
|
|
26732
27848
|
if (entry.catalogTrackName === void 0) {
|
|
@@ -26745,6 +27861,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
26745
27861
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
26746
27862
|
retire(entry);
|
|
26747
27863
|
stop(entry, "reset");
|
|
27864
|
+
if (entry.range) clearEntry(entry);
|
|
26748
27865
|
}
|
|
26749
27866
|
warnedNoTarget.delete(noTargetKey(packetId, catalogTrackName));
|
|
26750
27867
|
dispatch();
|
|
@@ -26771,6 +27888,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26771
27888
|
);
|
|
26772
27889
|
if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
|
|
26773
27890
|
entry2.deadlineAt = promotedDeadline.deadlineAt;
|
|
27891
|
+
entry2.anchorAt = promotedDeadline.anchorAt;
|
|
27892
|
+
entry2.delayMs = promotedDeadline.delayMs;
|
|
27893
|
+
entry2.bound = promotedDeadline.bound;
|
|
26774
27894
|
noteBudget(entry2, promotedDeadline.extensionMs);
|
|
26775
27895
|
}
|
|
26776
27896
|
if (entry2.running) {
|
|
@@ -26796,7 +27916,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26796
27916
|
if (waitMs === void 0) return null;
|
|
26797
27917
|
const waitDeadlineAt = now + waitMs;
|
|
26798
27918
|
const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
|
|
26799
|
-
if (anchor === void 0)
|
|
27919
|
+
if (anchor === void 0) {
|
|
27920
|
+
return { deadlineAt: waitDeadlineAt, extensionMs: 0, anchorAt: null, delayMs: null, bound: "wait" };
|
|
27921
|
+
}
|
|
26800
27922
|
let delayMs;
|
|
26801
27923
|
try {
|
|
26802
27924
|
delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
|
|
@@ -26807,12 +27929,21 @@ function wireRepairFetch(mc, opts) {
|
|
|
26807
27929
|
const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
|
|
26808
27930
|
if (retentionMs === void 0) return null;
|
|
26809
27931
|
const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
|
|
26810
|
-
const
|
|
26811
|
-
|
|
27932
|
+
const at = (delay, delayBound) => {
|
|
27933
|
+
const presentAt = Math.min(anchor + delay, ceilingAt);
|
|
27934
|
+
if (waitDeadlineAt >= presentAt) return { deadlineAt: waitDeadlineAt, bound: "wait" };
|
|
27935
|
+
return { deadlineAt: presentAt, bound: anchor + delay <= ceilingAt ? delayBound : "retention" };
|
|
27936
|
+
};
|
|
27937
|
+
const base = at(delayMs, "presentation");
|
|
26812
27938
|
const budgetMs = keyframeBudgetEligible(blockClass, classifierMode(packetId, catalogTrackName)) && groupCanComplete(sbn, packetId, catalogTrackName) ? readKeyframeBudget(packetId, catalogTrackName) : null;
|
|
26813
|
-
if (budgetMs === null || budgetMs <= delayMs) return {
|
|
26814
|
-
const extended =
|
|
26815
|
-
return {
|
|
27939
|
+
if (budgetMs === null || budgetMs <= delayMs) return { ...base, extensionMs: 0, anchorAt: anchor, delayMs };
|
|
27940
|
+
const extended = at(budgetMs, "keyframe");
|
|
27941
|
+
return {
|
|
27942
|
+
...extended,
|
|
27943
|
+
extensionMs: extended.deadlineAt - base.deadlineAt,
|
|
27944
|
+
anchorAt: anchor,
|
|
27945
|
+
delayMs: budgetMs
|
|
27946
|
+
};
|
|
26816
27947
|
};
|
|
26817
27948
|
const earliestGatedFrameAt = (packetId, catalogTrackName) => {
|
|
26818
27949
|
try {
|
|
@@ -26889,6 +28020,9 @@ function wireRepairFetch(mc, opts) {
|
|
|
26889
28020
|
priority,
|
|
26890
28021
|
subscriberPriority: wire.subscriberPriority,
|
|
26891
28022
|
deadlineAt: deadline.deadlineAt,
|
|
28023
|
+
anchorAt: deadline.anchorAt,
|
|
28024
|
+
delayMs: deadline.delayMs,
|
|
28025
|
+
bound: deadline.bound,
|
|
26892
28026
|
order: enqueueOrder++,
|
|
26893
28027
|
attempts: 0,
|
|
26894
28028
|
running: null
|
|
@@ -26898,14 +28032,92 @@ function wireRepairFetch(mc, opts) {
|
|
|
26898
28032
|
if (entry.priority < 2) preemptDeltas();
|
|
26899
28033
|
dispatch();
|
|
26900
28034
|
});
|
|
28035
|
+
const rangeFor = (loss, repairTrack) => {
|
|
28036
|
+
let reference;
|
|
28037
|
+
try {
|
|
28038
|
+
reference = opts.repairEpochReference(repairTrack);
|
|
28039
|
+
} catch {
|
|
28040
|
+
return null;
|
|
28041
|
+
}
|
|
28042
|
+
if (reference === void 0) return null;
|
|
28043
|
+
try {
|
|
28044
|
+
const anchor = loss.previousBlockStart === void 0 ? { reference } : { previousBlockStart: extendSsId(reference, loss.previousBlockStart) };
|
|
28045
|
+
return repairFetchRange(loss.lostSsId, loss.kMax, anchor);
|
|
28046
|
+
} catch (error) {
|
|
28047
|
+
if (error instanceof RangeError) return null;
|
|
28048
|
+
throw error;
|
|
28049
|
+
}
|
|
28050
|
+
};
|
|
28051
|
+
if (opts.rangeTransport !== void 0) {
|
|
28052
|
+
mc.onUndelimitedLoss((loss) => {
|
|
28053
|
+
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
28054
|
+
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
28055
|
+
if (disposed) return close();
|
|
28056
|
+
const blockProfile = blockProfileOf(packetId);
|
|
28057
|
+
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
28058
|
+
if (!target) return close();
|
|
28059
|
+
const priority = repairPriorityForClass("unknown");
|
|
28060
|
+
const range = rangeFor(loss, target.repairTrack);
|
|
28061
|
+
if (range === null) {
|
|
28062
|
+
close();
|
|
28063
|
+
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
28064
|
+
return;
|
|
28065
|
+
}
|
|
28066
|
+
const identity = {
|
|
28067
|
+
target,
|
|
28068
|
+
sbn: holeStart,
|
|
28069
|
+
packetId,
|
|
28070
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
28071
|
+
};
|
|
28072
|
+
const wire = wirePriority(identity, "unknown");
|
|
28073
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), "unknown");
|
|
28074
|
+
if (deadline === null) {
|
|
28075
|
+
close();
|
|
28076
|
+
mc.noteRepairSkipped(
|
|
28077
|
+
"presentation-delay-unavailable",
|
|
28078
|
+
{ rttMs: readRtt(), budgetMs: 0, priority },
|
|
28079
|
+
holeStart,
|
|
28080
|
+
packetId,
|
|
28081
|
+
catalogTrackName
|
|
28082
|
+
);
|
|
28083
|
+
return;
|
|
28084
|
+
}
|
|
28085
|
+
const entry = {
|
|
28086
|
+
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
28087
|
+
...identity,
|
|
28088
|
+
repairTrack: target.repairTrack,
|
|
28089
|
+
blockProfile,
|
|
28090
|
+
priority,
|
|
28091
|
+
subscriberPriority: wire.subscriberPriority,
|
|
28092
|
+
deadlineAt: deadline.deadlineAt,
|
|
28093
|
+
anchorAt: deadline.anchorAt,
|
|
28094
|
+
delayMs: deadline.delayMs,
|
|
28095
|
+
bound: deadline.bound,
|
|
28096
|
+
order: enqueueOrder++,
|
|
28097
|
+
attempts: 0,
|
|
28098
|
+
running: null,
|
|
28099
|
+
range: { ...range, lostSsId: loss.lostSsId, holeLength }
|
|
28100
|
+
};
|
|
28101
|
+
const previous = entries.get(entry.key);
|
|
28102
|
+
if (previous) {
|
|
28103
|
+
retire(previous);
|
|
28104
|
+
stop(previous, "reset");
|
|
28105
|
+
}
|
|
28106
|
+
entries.set(entry.key, entry);
|
|
28107
|
+
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
28108
|
+
preemptDeltas();
|
|
28109
|
+
dispatch();
|
|
28110
|
+
});
|
|
28111
|
+
}
|
|
26901
28112
|
return () => {
|
|
26902
28113
|
disposed = true;
|
|
26903
28114
|
removeResetObserver();
|
|
26904
28115
|
removeLifecycleObserver();
|
|
26905
28116
|
for (const entry of [...entries.values()]) {
|
|
26906
|
-
|
|
28117
|
+
clearEntry(entry);
|
|
26907
28118
|
if (entry.running) releaseHold(entry);
|
|
26908
28119
|
stop(entry, "disposed");
|
|
28120
|
+
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
26909
28121
|
}
|
|
26910
28122
|
entries.clear();
|
|
26911
28123
|
};
|
|
@@ -26944,20 +28156,19 @@ export {
|
|
|
26944
28156
|
MfuReassemblyError,
|
|
26945
28157
|
MmtpContainerParser,
|
|
26946
28158
|
MmtpDecodePipeline,
|
|
28159
|
+
MmtpFecSession,
|
|
26947
28160
|
MmtpRouter,
|
|
26948
28161
|
MmtpToCmaf,
|
|
26949
28162
|
MulticastContainerContractError,
|
|
26950
28163
|
MulticastInputError,
|
|
26951
28164
|
MulticastManager,
|
|
26952
28165
|
MulticastTransport,
|
|
26953
|
-
NoneCodec,
|
|
26954
28166
|
REPAIR_LIFECYCLE_EVENT_TYPE,
|
|
26955
28167
|
REPAIR_LIFECYCLE_LOG_PREFIX,
|
|
26956
28168
|
REPAIR_PRIORITY_MAX,
|
|
26957
28169
|
REPAIR_PRIORITY_MIN,
|
|
26958
28170
|
REPAIR_TRACK_GEOMETRY_KEYS,
|
|
26959
28171
|
REPAIR_TRACK_ONLY_KEYS,
|
|
26960
|
-
ReedSolomonCodec,
|
|
26961
28172
|
RepairContractError,
|
|
26962
28173
|
SOURCE_MEDIA_PRIORITY_MAX,
|
|
26963
28174
|
SampleCombineError,
|
|
@@ -26978,7 +28189,10 @@ export {
|
|
|
26978
28189
|
buildHevcVideoInitSegment,
|
|
26979
28190
|
buildVideoInitSegment,
|
|
26980
28191
|
catalogAmtNetworkSource,
|
|
28192
|
+
catalogAtsc3NetworkSource,
|
|
26981
28193
|
catalogDeclaresFec,
|
|
28194
|
+
catalogFecAvailable,
|
|
28195
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
26982
28196
|
catalogFecInterleaveMs,
|
|
26983
28197
|
catalogFecMediaUnitsPerSecond,
|
|
26984
28198
|
catalogFecUnavailable,
|
|
@@ -26992,7 +28206,6 @@ export {
|
|
|
26992
28206
|
computeFecDeliveryWindowMediaUnits,
|
|
26993
28207
|
computeFecDeliveryWindowMs,
|
|
26994
28208
|
computeFecLossWindowMs,
|
|
26995
|
-
createFecCodec,
|
|
26996
28209
|
createFragment,
|
|
26997
28210
|
createWasmMmtpContainerParser,
|
|
26998
28211
|
datagramMfuReassembly,
|
|
@@ -27020,6 +28233,7 @@ export {
|
|
|
27020
28233
|
extractHevcCodecDescription,
|
|
27021
28234
|
extractHevcParameterSets,
|
|
27022
28235
|
extractSpsPpsFromAvcC,
|
|
28236
|
+
fecAlgorithmUnimplemented,
|
|
27023
28237
|
findAnnexBStartCode,
|
|
27024
28238
|
forwardRepairLifecycleEvents,
|
|
27025
28239
|
frameSamplesFromInit,
|
|
@@ -27053,6 +28267,7 @@ export {
|
|
|
27053
28267
|
isTrackTimingConfig,
|
|
27054
28268
|
joinedRepairSymbolCount,
|
|
27055
28269
|
keyframeIntervalMediaTicks,
|
|
28270
|
+
locateCatalogFecSource,
|
|
27056
28271
|
mergeOverrideIntoCmsfTracks,
|
|
27057
28272
|
mergeOverrideIntoHangRenditions,
|
|
27058
28273
|
mfuReassemblyTimeoutMs,
|