@blockcast/mmt-container 0.4.0 → 0.4.1-main.cbe342dbdd9c
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 +1839 -692
- 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 +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- 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 +421 -66
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +331 -1171
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +1137 -317
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +159 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +531 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +39 -6
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +184 -27
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +877 -357
- 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 +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1086 -301
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/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 +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +2710 -7
- package/dist/source-auth.js.map +4 -4
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +452 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +110 -7
- 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 +166 -7
- 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 +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +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
|
@@ -171,26 +171,30 @@ function isEmptyOrExactLegacyTrailer(payload, start, end) {
|
|
|
171
171
|
const authLength = view2.getUint16(2, false);
|
|
172
172
|
return start + LEGACY_TRAILER_HEADER_SIZE + authLength === end;
|
|
173
173
|
}
|
|
174
|
-
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options) {
|
|
174
|
+
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options, rapFlag = false) {
|
|
175
175
|
if (declaredEnd > payload.length)
|
|
176
176
|
return null;
|
|
177
177
|
if (options?.skipFecId) {
|
|
178
|
-
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false } : null;
|
|
178
|
+
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false, hasOverlayFecId: false } : null;
|
|
179
179
|
}
|
|
180
|
+
const overlay = options?.overlayDeclared === true && rapFlag;
|
|
180
181
|
if (fecType === 1) {
|
|
181
|
-
const fecStart = payload.length -
|
|
182
|
+
const fecStart = payload.length - sourceFecTrailerSize(overlay);
|
|
182
183
|
if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
|
|
183
184
|
return null;
|
|
184
185
|
}
|
|
185
|
-
return { hasFecId: true };
|
|
186
|
+
return { hasFecId: true, hasOverlayFecId: overlay };
|
|
186
187
|
}
|
|
187
|
-
if (fecType !== 0)
|
|
188
|
+
if (fecType !== 0 || overlay)
|
|
188
189
|
return null;
|
|
189
190
|
if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
|
|
190
|
-
return { hasFecId: false };
|
|
191
|
+
return { hasFecId: false, hasOverlayFecId: false };
|
|
191
192
|
}
|
|
192
193
|
return null;
|
|
193
194
|
}
|
|
195
|
+
function sourceFecTrailerSize(overlay) {
|
|
196
|
+
return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE;
|
|
197
|
+
}
|
|
194
198
|
function planMfuExtraction(mmtpPacket, options, parsedHeader) {
|
|
195
199
|
if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE) {
|
|
196
200
|
return {
|
|
@@ -243,15 +247,16 @@ function planMfuExtraction(mmtpPacket, options, parsedHeader) {
|
|
|
243
247
|
if ("rejection" in layoutResult)
|
|
244
248
|
return layoutResult;
|
|
245
249
|
const { layout } = layoutResult;
|
|
246
|
-
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options);
|
|
250
|
+
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options, header.rapFlag);
|
|
247
251
|
if (!trailerLayout) {
|
|
248
252
|
if (!options?.skipFecId && header.fecType === 1) {
|
|
249
253
|
const observed = payload.length - layout.dataEnd;
|
|
250
|
-
|
|
254
|
+
const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag);
|
|
255
|
+
if (observed !== expected) {
|
|
251
256
|
return {
|
|
252
257
|
rejection: {
|
|
253
258
|
gate: "source-fec-payload-id-width-mismatch",
|
|
254
|
-
detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${
|
|
259
|
+
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})`
|
|
255
260
|
}
|
|
256
261
|
};
|
|
257
262
|
}
|
|
@@ -278,10 +283,13 @@ function extractPlannedMfu(mmtpPacket, result) {
|
|
|
278
283
|
const mfuDuHeader = mfuDuHeaderPresent && mpu.timedFlag === 1 ? parseTimedMfuDuHeader(payload, MPU_HEADER_SIZE) : null;
|
|
279
284
|
const itemId = mfuDuHeaderPresent && mpu.timedFlag === 0 ? new DataView(payload.buffer, payload.byteOffset + MPU_HEADER_SIZE, 4).getUint32(0, false) : null;
|
|
280
285
|
const data = payload.subarray(mfuOffset, dataEnd);
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
const trailerStart = mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId);
|
|
287
|
+
const ssIdAt = (offset) => ({
|
|
288
|
+
ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false)
|
|
289
|
+
});
|
|
290
|
+
const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null;
|
|
291
|
+
const overlayFecPayloadId = trailerLayout.hasOverlayFecId ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE) : null;
|
|
292
|
+
return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId };
|
|
285
293
|
}
|
|
286
294
|
function sourceFecPayloadIdOf(mmtpPacket, header) {
|
|
287
295
|
if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE)
|
|
@@ -433,11 +441,16 @@ function catalogFecAvailable(fec) {
|
|
|
433
441
|
const block = recordOf(fec);
|
|
434
442
|
if (block === void 0)
|
|
435
443
|
return true;
|
|
444
|
+
if (fecAlgorithmUnimplemented(block["algorithm"]))
|
|
445
|
+
return false;
|
|
436
446
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
437
447
|
const profile = block["blockProfile"];
|
|
438
448
|
const profileOk = isFecBlockProfile(profile) || profile === void 0 && !declaresFecInstance;
|
|
439
449
|
return profileOk && (!declaresFecInstance || isoBlockSpanUsable(block));
|
|
440
450
|
}
|
|
451
|
+
function fecAlgorithmUnimplemented(algorithm) {
|
|
452
|
+
return typeof algorithm === "string" && algorithm !== "none" && algorithm !== "raptorq" && algorithm !== "reed-solomon";
|
|
453
|
+
}
|
|
441
454
|
|
|
442
455
|
// src/track-session.ts
|
|
443
456
|
import { fecBlockBudgetMs } from "@blockcast/mmt-fec";
|
|
@@ -556,16 +569,6 @@ import {
|
|
|
556
569
|
|
|
557
570
|
// src/iso-block-locator.ts
|
|
558
571
|
var IsoBlockLocator = class _IsoBlockLocator {
|
|
559
|
-
/** Known blocks and spans, in serial order of their start. */
|
|
560
|
-
#blocks = [];
|
|
561
|
-
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
562
|
-
#held = /* @__PURE__ */ new Map();
|
|
563
|
-
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
564
|
-
#coverageEnd;
|
|
565
|
-
#kMax;
|
|
566
|
-
#retentionBlocks;
|
|
567
|
-
#heldEvicted = 0;
|
|
568
|
-
#newest;
|
|
569
572
|
/**
|
|
570
573
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
571
574
|
* @param retentionBlocks how many blocks behind the newest position the
|
|
@@ -573,12 +576,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
573
576
|
* no locator exists without retention.
|
|
574
577
|
*/
|
|
575
578
|
constructor(kMax, retentionBlocks) {
|
|
579
|
+
/** Known blocks and spans, in serial order of their start. */
|
|
580
|
+
this.#blocks = [];
|
|
581
|
+
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
582
|
+
this.#held = /* @__PURE__ */ new Map();
|
|
583
|
+
this.#heldEvicted = 0;
|
|
584
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
585
|
+
this.#holes = [];
|
|
586
|
+
/**
|
|
587
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
588
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
589
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
590
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
591
|
+
*/
|
|
592
|
+
this.deferIncompleteGaps = false;
|
|
576
593
|
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
577
594
|
throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
|
|
578
595
|
}
|
|
579
596
|
this.#kMax = kMax;
|
|
580
597
|
this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
|
|
581
598
|
}
|
|
599
|
+
#blocks;
|
|
600
|
+
#held;
|
|
601
|
+
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
602
|
+
#coverageEnd;
|
|
603
|
+
#kMax;
|
|
604
|
+
#retentionBlocks;
|
|
605
|
+
#heldEvicted;
|
|
606
|
+
#newest;
|
|
607
|
+
#holes;
|
|
582
608
|
static #checkedRetention(retentionBlocks) {
|
|
583
609
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
584
610
|
throw new Error(
|
|
@@ -641,6 +667,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
641
667
|
}
|
|
642
668
|
return null;
|
|
643
669
|
}
|
|
670
|
+
/** Number of pending holes. */
|
|
671
|
+
get holeCount() {
|
|
672
|
+
return this.#holes.length;
|
|
673
|
+
}
|
|
674
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
675
|
+
blockEndingAt(end) {
|
|
676
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
|
|
677
|
+
}
|
|
644
678
|
/** The known block or span starting exactly at `start`. */
|
|
645
679
|
blockAt(start) {
|
|
646
680
|
return this.#blocks.find((block) => block.start === start);
|
|
@@ -663,6 +697,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
663
697
|
coversBetween(a, b) {
|
|
664
698
|
if (this.#coverageEnd === void 0) return false;
|
|
665
699
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
|
|
700
|
+
const first = a + 1 >>> 0;
|
|
701
|
+
const count = serial32Distance(a, b) - 1;
|
|
702
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
|
|
666
703
|
return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
|
|
667
704
|
}
|
|
668
705
|
/**
|
|
@@ -692,6 +729,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
692
729
|
* known block (a different length, or an overlap with another block or a
|
|
693
730
|
* span) fails closed: the repair symbol is dropped and no block changes.
|
|
694
731
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
732
|
+
* A block so far past `newest` that stating it would retire the position
|
|
733
|
+
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
734
|
+
* this is slightly conservative (retirement measures that block from its
|
|
735
|
+
* last SS_ID), dropping up to one block-length of repairs past the horizon
|
|
736
|
+
* until a source moves `newest`. Placing it would turn everything
|
|
737
|
+
* between into a repair-less span and leave every real repair behind it
|
|
738
|
+
* `stale`. Sources move `newest` (`hold`, `observe`), so after a real outage
|
|
739
|
+
* the first source back brings the next repair inside the horizon; until one
|
|
740
|
+
* arrives, a stream's repairs alone cannot pass it.
|
|
695
741
|
*/
|
|
696
742
|
placeRepair(start, length) {
|
|
697
743
|
if (!Number.isSafeInteger(length) || length <= 0 || length > this.#kMax) {
|
|
@@ -710,6 +756,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
710
756
|
}
|
|
711
757
|
return { status: "placed", block: known, placed: [] };
|
|
712
758
|
}
|
|
759
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
|
|
760
|
+
if (pending !== void 0) {
|
|
761
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
762
|
+
return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
|
|
763
|
+
}
|
|
764
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1);
|
|
765
|
+
const before = serial32Distance(pending.start, start);
|
|
766
|
+
const afterStart = isoBlockEnd(start, length);
|
|
767
|
+
const after = pending.length - before - length;
|
|
768
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
|
|
769
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
|
|
770
|
+
const block2 = { start, length, span: false };
|
|
771
|
+
const placed2 = this.#claim(block2);
|
|
772
|
+
this.#blocks.push(block2);
|
|
773
|
+
return { status: "placed", block: block2, placed: placed2 };
|
|
774
|
+
}
|
|
713
775
|
for (const block2 of this.#blocks) {
|
|
714
776
|
if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
|
|
715
777
|
return {
|
|
@@ -718,7 +780,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
718
780
|
};
|
|
719
781
|
}
|
|
720
782
|
}
|
|
783
|
+
if (this.#newest !== void 0 && isoBlocksBehindLowerBound(this.#newest, start, this.#kMax) > this.#retentionBlocks) {
|
|
784
|
+
return { status: "ahead", reason: `repair block ${start}+${length} is past the retention horizon ahead of ${this.#newest}` };
|
|
785
|
+
}
|
|
721
786
|
let span;
|
|
787
|
+
let hole;
|
|
722
788
|
if (this.#coverageEnd === void 0) {
|
|
723
789
|
for (const ssId of this.#held.keys()) {
|
|
724
790
|
if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
|
|
@@ -727,21 +793,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
727
793
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
728
794
|
return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
|
|
729
795
|
} else if (start !== this.#coverageEnd) {
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
span:
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
796
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
|
|
797
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
|
|
798
|
+
if (lostSsId !== void 0) {
|
|
799
|
+
const holeBlock = { ...gap, span: false };
|
|
800
|
+
this.#holes.push(holeBlock);
|
|
801
|
+
hole = { block: holeBlock, lostSsId };
|
|
802
|
+
} else {
|
|
803
|
+
const spanBlock = { ...gap, span: true };
|
|
804
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) };
|
|
805
|
+
this.#blocks.push(spanBlock);
|
|
806
|
+
}
|
|
737
807
|
}
|
|
738
808
|
const block = { start, length, span: false };
|
|
739
809
|
const placed = this.#claim(block);
|
|
740
810
|
this.#blocks.push(block);
|
|
741
811
|
this.#coverageEnd = isoBlockEnd(start, length);
|
|
742
812
|
this.retireBehind(start);
|
|
813
|
+
if (hole !== void 0) return { status: "placed", block, placed, hole };
|
|
743
814
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
744
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
818
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
819
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
820
|
+
*/
|
|
821
|
+
closeHolesWithin(start, length) {
|
|
822
|
+
const closed = [];
|
|
823
|
+
for (const hole of [...this.#holes]) {
|
|
824
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
825
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1);
|
|
826
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
827
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
828
|
+
this.#blocks.push(spanBlock);
|
|
829
|
+
}
|
|
830
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
831
|
+
}
|
|
832
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
833
|
+
#highestMissing(start, length) {
|
|
834
|
+
const steps = Math.min(length, this.#held.size + 1);
|
|
835
|
+
for (let i = 1; i <= steps; i++) {
|
|
836
|
+
const ssId = serial32Add(start, length - i);
|
|
837
|
+
if (!this.#held.has(ssId)) return ssId;
|
|
838
|
+
}
|
|
839
|
+
return void 0;
|
|
840
|
+
}
|
|
745
841
|
/**
|
|
746
842
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
747
843
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -760,6 +856,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
760
856
|
this.#blocks.splice(i, 1);
|
|
761
857
|
}
|
|
762
858
|
}
|
|
859
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
860
|
+
const hole = this.#holes[i];
|
|
861
|
+
const last = serial32Add(hole.start, hole.length - 1);
|
|
862
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
|
|
863
|
+
}
|
|
763
864
|
for (const ssId of [...this.#held.keys()]) {
|
|
764
865
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
|
|
765
866
|
}
|
|
@@ -768,6 +869,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
768
869
|
/** Forget everything (publisher restart, track reset). */
|
|
769
870
|
reset() {
|
|
770
871
|
this.#blocks.length = 0;
|
|
872
|
+
this.#holes.length = 0;
|
|
771
873
|
this.#held.clear();
|
|
772
874
|
this.#coverageEnd = void 0;
|
|
773
875
|
this.#newest = void 0;
|
|
@@ -783,6 +885,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
783
885
|
return placed;
|
|
784
886
|
}
|
|
785
887
|
};
|
|
888
|
+
function isoRangesOverlap(aStart, aLength, bStart, bLength) {
|
|
889
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
|
|
890
|
+
}
|
|
786
891
|
|
|
787
892
|
// src/fec-state.ts
|
|
788
893
|
var MIN_INTERLEAVE_DEPTH_MS = 1;
|
|
@@ -1257,6 +1362,7 @@ function decideGap(input) {
|
|
|
1257
1362
|
}
|
|
1258
1363
|
|
|
1259
1364
|
// src/fec-manager.ts
|
|
1365
|
+
var RS_MAX_BLOCK_SYMBOLS = 255;
|
|
1260
1366
|
var WORKER_ERROR_LOG_CAP = 5;
|
|
1261
1367
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
1262
1368
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
@@ -1371,6 +1477,11 @@ var FECManager = class _FECManager {
|
|
|
1371
1477
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
1372
1478
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
1373
1479
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
1480
|
+
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
1481
|
+
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
1482
|
+
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
1483
|
+
this.#fecFailClosed = /* @__PURE__ */ new Map();
|
|
1484
|
+
this.#onFecFailClosed = null;
|
|
1374
1485
|
// Blocks already recovered — prevents late source symbols from restarting timeouts.
|
|
1375
1486
|
// WASM removes blocks after recovery; late symbols create empty blocks returning null,
|
|
1376
1487
|
// which would falsely start new timeouts without this guard.
|
|
@@ -1491,12 +1602,17 @@ var FECManager = class _FECManager {
|
|
|
1491
1602
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
1492
1603
|
// arithmetic and never throws at all.
|
|
1493
1604
|
this.#orderedHorizonWarnedFor = /* @__PURE__ */ new Set();
|
|
1494
|
-
// Newest block start (SS_Start)
|
|
1495
|
-
//
|
|
1605
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
1606
|
+
// frontier isoSpanResolution reads.
|
|
1496
1607
|
this.#highestSbn = /* @__PURE__ */ new Map();
|
|
1608
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
1609
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
1610
|
+
// blocks ahead of the media they protect.
|
|
1611
|
+
this.#sourceFrontiers = /* @__PURE__ */ new Map();
|
|
1497
1612
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
1498
1613
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
1499
1614
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
1615
|
+
this.#deferIsoGaps = false;
|
|
1500
1616
|
this.#isoRepairRefusedCount = 0;
|
|
1501
1617
|
this.#isoSourceOversizeCount = 0;
|
|
1502
1618
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -1511,8 +1627,8 @@ var FECManager = class _FECManager {
|
|
|
1511
1627
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
1512
1628
|
this.#isoDecoderUnplacedRetireFailed = 0;
|
|
1513
1629
|
// The latest source symbol per stream that carried its MMTP
|
|
1514
|
-
// packet_sequence_number: the anchor that bounds how
|
|
1515
|
-
// producer can have
|
|
1630
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
1631
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
1516
1632
|
this.#sourceAnchors = /* @__PURE__ */ new Map();
|
|
1517
1633
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
1518
1634
|
this.#packetEpochs = /* @__PURE__ */ new Map();
|
|
@@ -1571,6 +1687,14 @@ var FECManager = class _FECManager {
|
|
|
1571
1687
|
this.onBlockReclassified = null;
|
|
1572
1688
|
/** A video stream's classifier mode was established or changed. */
|
|
1573
1689
|
this.onClassifierMode = null;
|
|
1690
|
+
/**
|
|
1691
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
1692
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
1693
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
1694
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
1695
|
+
* for it, which it must be.
|
|
1696
|
+
*/
|
|
1697
|
+
this.#onUndelimitedLoss = null;
|
|
1574
1698
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
1575
1699
|
this.onBlockVanished = null;
|
|
1576
1700
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
@@ -1612,6 +1736,9 @@ var FECManager = class _FECManager {
|
|
|
1612
1736
|
#ssbLengthConflictCount;
|
|
1613
1737
|
#blockRepairRsIds;
|
|
1614
1738
|
#blockRsbLengths;
|
|
1739
|
+
#heldLayerStates;
|
|
1740
|
+
#fecFailClosed;
|
|
1741
|
+
#onFecFailClosed;
|
|
1615
1742
|
#completedBlocks;
|
|
1616
1743
|
#terminalExpiryMs;
|
|
1617
1744
|
#terminalQueues;
|
|
@@ -1650,7 +1777,9 @@ var FECManager = class _FECManager {
|
|
|
1650
1777
|
#materializedBlocks;
|
|
1651
1778
|
#orderedHorizonWarnedFor;
|
|
1652
1779
|
#highestSbn;
|
|
1780
|
+
#sourceFrontiers;
|
|
1653
1781
|
#isoLocators;
|
|
1782
|
+
#deferIsoGaps;
|
|
1654
1783
|
#isoRepairRefusedCount;
|
|
1655
1784
|
#isoSourceOversizeCount;
|
|
1656
1785
|
#isoHeldEvictedCount;
|
|
@@ -1664,6 +1793,7 @@ var FECManager = class _FECManager {
|
|
|
1664
1793
|
#workerErrorCounts;
|
|
1665
1794
|
#decoderUnavailableEvents;
|
|
1666
1795
|
#repairSymbolSizeMismatchCount;
|
|
1796
|
+
#onUndelimitedLoss;
|
|
1667
1797
|
#encodeTrackName(catalogTrackName) {
|
|
1668
1798
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
1669
1799
|
if (encoded === void 0) {
|
|
@@ -2240,8 +2370,8 @@ var FECManager = class _FECManager {
|
|
|
2240
2370
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
2241
2371
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
2242
2372
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
2243
|
-
// many blocks a stream can
|
|
2244
|
-
//
|
|
2373
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
2374
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
2245
2375
|
// The extra block of retention is slack for a block still being fed; a block
|
|
2246
2376
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
2247
2377
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -2251,55 +2381,72 @@ var FECManager = class _FECManager {
|
|
|
2251
2381
|
}
|
|
2252
2382
|
/**
|
|
2253
2383
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
2254
|
-
* advance the stream's
|
|
2384
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
2255
2385
|
*
|
|
2256
|
-
* A SOURCE symbol
|
|
2257
|
-
*
|
|
2258
|
-
*
|
|
2386
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
2387
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
2388
|
+
* block goes back further than the blocks this manager retains, or that
|
|
2389
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
2390
|
+
* further than the stream could have produced since its last symbol, is a
|
|
2391
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
2259
2392
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
2260
2393
|
* signals a discontinuity.
|
|
2261
2394
|
*
|
|
2262
2395
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
2263
2396
|
* source symbols filled it, so one interleave span can start several blocks
|
|
2264
|
-
* (every large keyframe does). What bounds a
|
|
2265
|
-
*
|
|
2266
|
-
*
|
|
2267
|
-
*
|
|
2268
|
-
* packet_sequence_number
|
|
2269
|
-
*
|
|
2270
|
-
*
|
|
2397
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
2398
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
2399
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
2400
|
+
* packet of the packet_id, so with both source symbols'
|
|
2401
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
2402
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
2403
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
2404
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
2405
|
+
* known.
|
|
2271
2406
|
*
|
|
2272
2407
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
2273
2408
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
2274
2409
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
2275
2410
|
*/
|
|
2276
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber) {
|
|
2411
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
2277
2412
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
2278
2413
|
const now = performance.now();
|
|
2279
|
-
const previous = this.#highestSbn.get(streamKey);
|
|
2414
|
+
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
2280
2415
|
const anchor = this.#sourceAnchors.get(streamKey);
|
|
2281
2416
|
const psn = symbol === "source" && packetSequenceNumber !== void 0 && Number.isSafeInteger(packetSequenceNumber) && packetSequenceNumber >= 0 && packetSequenceNumber <= 4294967295 ? packetSequenceNumber : void 0;
|
|
2282
2417
|
const anchorHere = () => {
|
|
2283
|
-
if (psn !== void 0 && (anchor === void 0 || !
|
|
2284
|
-
this.#sourceAnchors.set(streamKey, {
|
|
2418
|
+
if (psn !== void 0 && (anchor === void 0 || !serial32Precedes(ssId, anchor.ssId))) {
|
|
2419
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
2285
2420
|
}
|
|
2286
2421
|
};
|
|
2422
|
+
const advance = () => {
|
|
2423
|
+
const highest = this.#highestSbn.get(streamKey);
|
|
2424
|
+
if (highest === void 0 || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
2425
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
2426
|
+
}
|
|
2427
|
+
if (symbol === "source") this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
2428
|
+
anchorHere();
|
|
2429
|
+
};
|
|
2287
2430
|
const discontinuity = () => {
|
|
2288
2431
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
2289
2432
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
2433
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
2290
2434
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
2291
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
2435
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
2292
2436
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName);
|
|
2293
2437
|
};
|
|
2294
2438
|
if (previous === void 0) {
|
|
2295
|
-
|
|
2296
|
-
anchorHere();
|
|
2439
|
+
advance();
|
|
2297
2440
|
return;
|
|
2298
2441
|
}
|
|
2299
2442
|
const config = this.#trackConfig(packetId);
|
|
2300
2443
|
const window2 = this.#liveWindowBlocks(config);
|
|
2444
|
+
const sentInOrder = (from, to) => {
|
|
2445
|
+
const sent = to.psn - from.psn >>> 0;
|
|
2446
|
+
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
2447
|
+
};
|
|
2301
2448
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
2302
|
-
if (symbol === "source" && window2 !== null && this.#blocksBehind(sbn, previous.sbn, packetId) >
|
|
2449
|
+
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))) {
|
|
2303
2450
|
discontinuity();
|
|
2304
2451
|
return;
|
|
2305
2452
|
}
|
|
@@ -2309,9 +2456,8 @@ var FECManager = class _FECManager {
|
|
|
2309
2456
|
const missing = this.#blocksBehind(previous.sbn, sbn, packetId) - 1;
|
|
2310
2457
|
let plausible = true;
|
|
2311
2458
|
if (window2 !== null) {
|
|
2312
|
-
if (psn !== void 0 && anchor !== void 0 &&
|
|
2313
|
-
|
|
2314
|
-
plausible = sent <= 2147483647 && serial32Distance(anchor.sbn, sbn) <= sent + config.k;
|
|
2459
|
+
if (psn !== void 0 && anchor !== void 0 && serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
2460
|
+
plausible = sentInOrder(anchor, { ssId, psn });
|
|
2315
2461
|
} else {
|
|
2316
2462
|
plausible = missing <= window2 + Math.ceil((now - previous.atMs) / config.interleaveDepthMs);
|
|
2317
2463
|
}
|
|
@@ -2321,8 +2467,7 @@ var FECManager = class _FECManager {
|
|
|
2321
2467
|
discontinuity();
|
|
2322
2468
|
return;
|
|
2323
2469
|
}
|
|
2324
|
-
|
|
2325
|
-
anchorHere();
|
|
2470
|
+
advance();
|
|
2326
2471
|
}
|
|
2327
2472
|
/*
|
|
2328
2473
|
* Block order for one stream (BLO-35597 iso:5). A block is keyed by its
|
|
@@ -2639,8 +2784,10 @@ var FECManager = class _FECManager {
|
|
|
2639
2784
|
);
|
|
2640
2785
|
}
|
|
2641
2786
|
const hasCatalogTiming = _FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs });
|
|
2787
|
+
const algorithm = config.algorithm ?? previous.algorithm;
|
|
2642
2788
|
const next = {
|
|
2643
2789
|
blockProfile,
|
|
2790
|
+
...algorithm === void 0 ? {} : { algorithm },
|
|
2644
2791
|
k,
|
|
2645
2792
|
symbolSize: config.symbolSize != null && config.symbolSize > 0 ? config.symbolSize : previousTrack?.symbolSize ?? 0,
|
|
2646
2793
|
interleaveDepthMs: ownInterleaveDepthMs,
|
|
@@ -2648,8 +2795,19 @@ var FECManager = class _FECManager {
|
|
|
2648
2795
|
timeoutMs: config.timeoutMs ?? (timingChanged ? 0 : previous.timeoutMs ?? 0),
|
|
2649
2796
|
...(config.trackKind ?? previous.trackKind) === void 0 ? {} : { trackKind: config.trackKind ?? previous.trackKind },
|
|
2650
2797
|
...(config.codec ?? previous.codec) === void 0 ? {} : { codec: config.codec ?? previous.codec },
|
|
2651
|
-
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry }
|
|
2798
|
+
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry },
|
|
2799
|
+
...(config.repairLayers ?? previous.repairLayers) === void 0 ? {} : { repairLayers: config.repairLayers ?? previous.repairLayers },
|
|
2800
|
+
...(config.heldLayers ?? previous.heldLayers) === void 0 ? {} : { heldLayers: config.heldLayers ?? previous.heldLayers }
|
|
2652
2801
|
};
|
|
2802
|
+
if (
|
|
2803
|
+
// By content: a catalog refresh rebuilds equal arrays, and forgetting
|
|
2804
|
+
// the anchors on one would fail open.
|
|
2805
|
+
JSON.stringify(next.repairLayers) !== JSON.stringify(previous.repairLayers) || JSON.stringify(next.heldLayers) !== JSON.stringify(previous.heldLayers)
|
|
2806
|
+
) {
|
|
2807
|
+
for (const key of [...this.#heldLayerStates.keys()]) {
|
|
2808
|
+
if (this.#belongsToPacket(key, packetId)) this.#heldLayerStates.delete(key);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2653
2811
|
if (!hasCatalogTiming) {
|
|
2654
2812
|
next.timeoutMs = config.timeoutMs !== void 0 && config.timeoutMs > 0 ? config.timeoutMs : previousTrack !== void 0 && previousTrack.interleaveDepthMs === 0 ? previousTrack.timeoutMs : LOCAL_FEC_TIMEOUT_MS;
|
|
2655
2813
|
} else {
|
|
@@ -2884,6 +3042,8 @@ var FECManager = class _FECManager {
|
|
|
2884
3042
|
resetMap(this.#blockAuthoredLengths);
|
|
2885
3043
|
resetMap(this.#blockRepairRsIds);
|
|
2886
3044
|
resetMap(this.#blockRsbLengths);
|
|
3045
|
+
resetMap(this.#heldLayerStates);
|
|
3046
|
+
resetMap(this.#fecFailClosed);
|
|
2887
3047
|
resetMap(this.#blockPathCounts);
|
|
2888
3048
|
resetMap(this.#blockAnchorsMs);
|
|
2889
3049
|
resetMap(this.#blockCatalogTrackNames);
|
|
@@ -2906,6 +3066,7 @@ var FECManager = class _FECManager {
|
|
|
2906
3066
|
resetSet(this.#materializedBlocks);
|
|
2907
3067
|
resetMap(this.#resolvedBlockClasses);
|
|
2908
3068
|
resetMap(this.#highestSbn);
|
|
3069
|
+
resetMap(this.#sourceFrontiers);
|
|
2909
3070
|
resetMap(this.#isoLocators);
|
|
2910
3071
|
resetMap(this.#sourceAnchors);
|
|
2911
3072
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -3011,6 +3172,7 @@ var FECManager = class _FECManager {
|
|
|
3011
3172
|
dropMap(this.#orderedPendingBlocks);
|
|
3012
3173
|
dropMap(this.#resolvedBlockClasses);
|
|
3013
3174
|
dropMap(this.#highestSbn);
|
|
3175
|
+
dropMap(this.#sourceFrontiers);
|
|
3014
3176
|
dropMap(this.#isoLocators);
|
|
3015
3177
|
dropMap(this.#sourceAnchors);
|
|
3016
3178
|
dropMap(this.#classifiers);
|
|
@@ -3103,7 +3265,13 @@ var FECManager = class _FECManager {
|
|
|
3103
3265
|
if (isSourceSymbol && esi === 0) {
|
|
3104
3266
|
this.#startupPartialBlocks.delete(blockKey);
|
|
3105
3267
|
this.#startupAlignedPackets.add(streamKey);
|
|
3106
|
-
} else if (
|
|
3268
|
+
} else if (
|
|
3269
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
3270
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
3271
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
3272
|
+
// per join (BLO-48308).
|
|
3273
|
+
isStartupPartial || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair
|
|
3274
|
+
) {
|
|
3107
3275
|
this.#markStartupPartial(blockKey);
|
|
3108
3276
|
return false;
|
|
3109
3277
|
}
|
|
@@ -3385,6 +3553,7 @@ var FECManager = class _FECManager {
|
|
|
3385
3553
|
let locator = this.#isoLocators.get(streamKey);
|
|
3386
3554
|
if (!locator) {
|
|
3387
3555
|
locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
|
|
3556
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
3388
3557
|
this.#isoLocators.set(streamKey, locator);
|
|
3389
3558
|
}
|
|
3390
3559
|
return locator;
|
|
@@ -3428,6 +3597,10 @@ var FECManager = class _FECManager {
|
|
|
3428
3597
|
}
|
|
3429
3598
|
return blocks;
|
|
3430
3599
|
}
|
|
3600
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
3601
|
+
isoRetentionBlocksForPacket(packetId) {
|
|
3602
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : void 0;
|
|
3603
|
+
}
|
|
3431
3604
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
3432
3605
|
isoSourceFits(packetId, packetLength) {
|
|
3433
3606
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize;
|
|
@@ -3477,15 +3650,61 @@ var FECManager = class _FECManager {
|
|
|
3477
3650
|
}
|
|
3478
3651
|
return placement;
|
|
3479
3652
|
}
|
|
3480
|
-
if (placement.span !== void 0)
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3653
|
+
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
3654
|
+
if (placement.hole !== void 0) {
|
|
3655
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
3656
|
+
const hole = placement.hole.block;
|
|
3657
|
+
const previous = locator.blockEndingAt(hole.start);
|
|
3658
|
+
const loss = {
|
|
3659
|
+
packetId,
|
|
3660
|
+
catalogTrackName,
|
|
3661
|
+
holeStart: hole.start,
|
|
3662
|
+
holeLength: hole.length,
|
|
3663
|
+
lostSsId: placement.hole.lostSsId,
|
|
3664
|
+
kMax: this.#trackConfig(packetId).k,
|
|
3665
|
+
...previous === void 0 ? {} : { previousBlockStart: previous.start }
|
|
3666
|
+
};
|
|
3667
|
+
this.#onUndelimitedLoss(loss);
|
|
3486
3668
|
}
|
|
3487
3669
|
return placement;
|
|
3488
3670
|
}
|
|
3671
|
+
/**
|
|
3672
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
3673
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
3674
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
3675
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
3676
|
+
* nobody to close it.
|
|
3677
|
+
*/
|
|
3678
|
+
setUndelimitedLossHandler(handler) {
|
|
3679
|
+
this.#onUndelimitedLoss = handler;
|
|
3680
|
+
this.#deferIsoGaps = handler !== null;
|
|
3681
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
3685
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
3686
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
3687
|
+
*/
|
|
3688
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
3689
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
3690
|
+
if (locator === void 0) return [];
|
|
3691
|
+
const spans = locator.closeHolesWithin(start, length);
|
|
3692
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
|
|
3693
|
+
return spans;
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
3697
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
3698
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
3699
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
3700
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
3701
|
+
* block.
|
|
3702
|
+
*/
|
|
3703
|
+
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
3704
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
3705
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
|
|
3706
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
3707
|
+
}
|
|
3489
3708
|
/**
|
|
3490
3709
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
3491
3710
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -4002,6 +4221,154 @@ var FECManager = class _FECManager {
|
|
|
4002
4221
|
}
|
|
4003
4222
|
return recovered;
|
|
4004
4223
|
}
|
|
4224
|
+
/**
|
|
4225
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
4226
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
4227
|
+
* block state unchanged. The router calls this before the repair places a
|
|
4228
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
4229
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
4230
|
+
*/
|
|
4231
|
+
admitRepairBlockLength(packetId, ssbLength, rsbLength, rsId) {
|
|
4232
|
+
if (rsId >= rsbLength) return false;
|
|
4233
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== "reed-solomon") return true;
|
|
4234
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS;
|
|
4235
|
+
}
|
|
4236
|
+
/**
|
|
4237
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
4238
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
4239
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
4240
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
4241
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
4242
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
4243
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
4244
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
4245
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
4246
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
4247
|
+
*/
|
|
4248
|
+
admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, byteLength) {
|
|
4249
|
+
if (!this.#hasBlockProfile(packetId)) return false;
|
|
4250
|
+
const symbolSize = this.#trackConfig(packetId).symbolSize;
|
|
4251
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
4252
|
+
this.#repairSymbolSizeMismatchCount++;
|
|
4253
|
+
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
4254
|
+
console.warn(
|
|
4255
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
4256
|
+
);
|
|
4257
|
+
}
|
|
4258
|
+
return false;
|
|
4259
|
+
}
|
|
4260
|
+
return true;
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* fec-01 6.3.9 receiver check, run on a repair packet after the 4.5 discard
|
|
4264
|
+
* and the size check, before it places a block. For each held layer i with
|
|
4265
|
+
* total B_i = O_i + P_i: the anchor is the earliest block, in SS_Start
|
|
4266
|
+
* serial order, whose repair carried RSB_length >= B_i. The source track
|
|
4267
|
+
* fails closed on (a) a packet on layer i's own repair track (i > 0) below
|
|
4268
|
+
* B_i, or (b) any packet of the instance at or after the anchor below B_i.
|
|
4269
|
+
* Blocks before the anchor (pre-append) stay valid at the previous total. A
|
|
4270
|
+
* packet on a repair track the catalog does not list is discarded and
|
|
4271
|
+
* anchors nothing. `repairTrackName` is the subscribed repair track, never
|
|
4272
|
+
* inferred from RS_ID; without it only (b) runs. Returns false when the
|
|
4273
|
+
* repair must be dropped, including every repair once the track failed.
|
|
4274
|
+
*/
|
|
4275
|
+
admitRepairLayerTotal(packetId, catalogTrackName, repairTrackName, ssStart, rsbLength) {
|
|
4276
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
4277
|
+
if (this.#fecFailClosed.has(streamKey)) return false;
|
|
4278
|
+
const config = this.#trackConfigs.get(packetId);
|
|
4279
|
+
const layers = config?.repairLayers;
|
|
4280
|
+
if (layers === void 0 || layers.length === 0) return true;
|
|
4281
|
+
if (repairTrackName !== void 0 && !layers.some((l) => l.repairTrackName === repairTrackName)) {
|
|
4282
|
+
return false;
|
|
4283
|
+
}
|
|
4284
|
+
let states = this.#heldLayerStates.get(streamKey);
|
|
4285
|
+
if (states === void 0) {
|
|
4286
|
+
const held = new Set(config.heldLayers ?? [0]);
|
|
4287
|
+
states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
|
|
4288
|
+
this.#heldLayerStates.set(streamKey, states);
|
|
4289
|
+
}
|
|
4290
|
+
const horizon = this.#layerAnchorHorizon(packetId);
|
|
4291
|
+
const frontier = this.#sourceFrontiers.get(streamKey)?.sbn;
|
|
4292
|
+
const farAhead = frontier !== void 0 && serial32Precedes(frontier, ssStart) && serial32Distance(frontier, ssStart) > horizon;
|
|
4293
|
+
for (const state of states) {
|
|
4294
|
+
let code;
|
|
4295
|
+
if (farAhead) {
|
|
4296
|
+
if (rsbLength < state.total) {
|
|
4297
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
4298
|
+
else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
|
|
4299
|
+
}
|
|
4300
|
+
} else {
|
|
4301
|
+
if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
|
|
4302
|
+
const stale = (s) => serial32Distance(s, state.newest) > horizon;
|
|
4303
|
+
if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
|
|
4304
|
+
delete state.latestBelow;
|
|
4305
|
+
delete state.latestBelowRsb;
|
|
4306
|
+
}
|
|
4307
|
+
if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
|
|
4308
|
+
if (rsbLength < state.total) {
|
|
4309
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
4310
|
+
else if (stale(ssStart)) continue;
|
|
4311
|
+
else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
|
|
4312
|
+
else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
|
|
4313
|
+
state.latestBelow = ssStart;
|
|
4314
|
+
state.latestBelowRsb = rsbLength;
|
|
4315
|
+
}
|
|
4316
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
4317
|
+
if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
|
|
4318
|
+
if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
4319
|
+
code = "below_anchored_total";
|
|
4320
|
+
ssStart = state.latestBelow;
|
|
4321
|
+
rsbLength = state.latestBelowRsb;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
if (code !== void 0) {
|
|
4326
|
+
const reason = {
|
|
4327
|
+
code,
|
|
4328
|
+
layer: state.layer,
|
|
4329
|
+
total: state.total,
|
|
4330
|
+
rsbLength,
|
|
4331
|
+
ssStart,
|
|
4332
|
+
...state.anchor === void 0 ? {} : { anchor: state.anchor }
|
|
4333
|
+
};
|
|
4334
|
+
this.#fecFailClosed.set(streamKey, reason);
|
|
4335
|
+
this.#onFecFailClosed?.({ ...reason, packetId, catalogTrackName });
|
|
4336
|
+
console.warn(
|
|
4337
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? "-"}: ${JSON.stringify(reason)}`
|
|
4338
|
+
);
|
|
4339
|
+
return false;
|
|
4340
|
+
}
|
|
4341
|
+
}
|
|
4342
|
+
return true;
|
|
4343
|
+
}
|
|
4344
|
+
/**
|
|
4345
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
4346
|
+
* below-total block can still matter: the iso locator's retention in blocks
|
|
4347
|
+
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
4348
|
+
*/
|
|
4349
|
+
#layerAnchorHorizon(packetId) {
|
|
4350
|
+
const cap = 1073741824;
|
|
4351
|
+
let blocks;
|
|
4352
|
+
try {
|
|
4353
|
+
blocks = this.isoRetentionBlocksForPacket(packetId);
|
|
4354
|
+
} catch {
|
|
4355
|
+
blocks = void 0;
|
|
4356
|
+
}
|
|
4357
|
+
const k = this.#trackConfigs.get(packetId)?.k ?? 0;
|
|
4358
|
+
return blocks === void 0 || k <= 0 ? cap : Math.min(cap, blocks * k);
|
|
4359
|
+
}
|
|
4360
|
+
/**
|
|
4361
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), once,
|
|
4362
|
+
* when it does; null stops reporting. The player wiring forwards it to
|
|
4363
|
+
* CmcdProducer.updateFecFailClosed.
|
|
4364
|
+
*/
|
|
4365
|
+
setFecFailClosedHandler(handler) {
|
|
4366
|
+
this.#onFecFailClosed = handler;
|
|
4367
|
+
}
|
|
4368
|
+
/** The runtime fail-closed reason of a stream's FEC (fec-01 6.3.9), if any. */
|
|
4369
|
+
fecFailClosedReason(packetId, catalogTrackName) {
|
|
4370
|
+
return this.#fecFailClosed.get(this.#streamKey(packetId, catalogTrackName));
|
|
4371
|
+
}
|
|
4005
4372
|
/**
|
|
4006
4373
|
* Feed a repair symbol to the WASM FEC decoder.
|
|
4007
4374
|
*
|
|
@@ -4013,16 +4380,7 @@ var FECManager = class _FECManager {
|
|
|
4013
4380
|
this.#fecStats.repairPackets++;
|
|
4014
4381
|
this.#statsForPacket(packetId).repairPackets++;
|
|
4015
4382
|
if (!this.#hasBlockProfile(packetId)) return null;
|
|
4016
|
-
|
|
4017
|
-
if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
|
|
4018
|
-
this.#repairSymbolSizeMismatchCount++;
|
|
4019
|
-
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
4020
|
-
console.warn(
|
|
4021
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
4022
|
-
);
|
|
4023
|
-
}
|
|
4024
|
-
return null;
|
|
4025
|
-
}
|
|
4383
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null;
|
|
4026
4384
|
const fecData = repairData;
|
|
4027
4385
|
const k = this.#trackConfig(packetId).k;
|
|
4028
4386
|
const block = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(ssStart);
|
|
@@ -4175,7 +4533,14 @@ var FECManager = class _FECManager {
|
|
|
4175
4533
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
4176
4534
|
const k = trackConfig.k;
|
|
4177
4535
|
if (this.#completedBlocks.has(key)) return;
|
|
4178
|
-
this.#noteSbnSeen(
|
|
4536
|
+
this.#noteSbnSeen(
|
|
4537
|
+
sbn,
|
|
4538
|
+
packetId,
|
|
4539
|
+
catalogTrackName,
|
|
4540
|
+
"source",
|
|
4541
|
+
evidence.packetSequenceNumber,
|
|
4542
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
4543
|
+
);
|
|
4179
4544
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
4180
4545
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
4181
4546
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -4402,6 +4767,8 @@ var FECManager = class _FECManager {
|
|
|
4402
4767
|
this.#blockAuthoredLengths.clear();
|
|
4403
4768
|
this.#blockRepairRsIds.clear();
|
|
4404
4769
|
this.#blockRsbLengths.clear();
|
|
4770
|
+
this.#heldLayerStates.clear();
|
|
4771
|
+
this.#fecFailClosed.clear();
|
|
4405
4772
|
this.#completedBlocks.clear();
|
|
4406
4773
|
this.#cleanlyCompletedBlocks.clear();
|
|
4407
4774
|
this.#repairRequestedBlocks.clear();
|
|
@@ -4426,6 +4793,7 @@ var FECManager = class _FECManager {
|
|
|
4426
4793
|
this.#repairedBlocks.clear();
|
|
4427
4794
|
this.#materializedBlocks.clear();
|
|
4428
4795
|
this.#highestSbn.clear();
|
|
4796
|
+
this.#sourceFrontiers.clear();
|
|
4429
4797
|
this.#isoLocators.clear();
|
|
4430
4798
|
this.#sourceAnchors.clear();
|
|
4431
4799
|
this.#trackConfigs.clear();
|
|
@@ -9325,8 +9693,14 @@ var SampleCombiner = class {
|
|
|
9325
9693
|
/**
|
|
9326
9694
|
* Add one reassembled data unit. Returns the combined sample once every
|
|
9327
9695
|
* constituent data unit has arrived and totals the authored size.
|
|
9696
|
+
*
|
|
9697
|
+
* `sampleSize` is the authored size the host resolves for the sample as the
|
|
9698
|
+
* data unit completes. It stands in only when no size was registered, which
|
|
9699
|
+
* happens when the data unit's FI=0/FI=1 reached the reassembler without the
|
|
9700
|
+
* host's own FT=2 parse: an FEC-recovered first fragment completed by source
|
|
9701
|
+
* fragments, or one decoded before its source copy arrived.
|
|
9328
9702
|
*/
|
|
9329
|
-
addMfu(mfu) {
|
|
9703
|
+
addMfu(mfu, sampleSize) {
|
|
9330
9704
|
if (mfu.movieFragmentSequenceNumber === void 0 || mfu.sampleNumber === void 0) {
|
|
9331
9705
|
this.#stats.passthroughSamples++;
|
|
9332
9706
|
return fromPassthrough(mfu);
|
|
@@ -9342,7 +9716,7 @@ var SampleCombiner = class {
|
|
|
9342
9716
|
return null;
|
|
9343
9717
|
}
|
|
9344
9718
|
const dataLen = mfu.data.byteLength;
|
|
9345
|
-
const authoredSize = this.#authoredSizes.get(key);
|
|
9719
|
+
const authoredSize = this.#authoredSizes.get(key) ?? sampleSize;
|
|
9346
9720
|
if (offset === 0 && !this.#pending.has(key)) {
|
|
9347
9721
|
const passesThrough = authoredSize === void 0 ? !this.#requireAuthoredSize : dataLen === authoredSize;
|
|
9348
9722
|
if (passesThrough) {
|
|
@@ -9636,6 +10010,12 @@ if (void 0) {
|
|
|
9636
10010
|
const out = c.addMfu(mfu(1, 9, 17, 5, [6, 7, 8, 9, 10], 1001n, false));
|
|
9637
10011
|
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
|
|
9638
10012
|
});
|
|
10013
|
+
test("a size handed with the data unit completes a sample no head registered", () => {
|
|
10014
|
+
const c = combiner({ requireAuthoredSize: true });
|
|
10015
|
+
const out = c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5);
|
|
10016
|
+
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
|
|
10017
|
+
expect(c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5)).toBeNull();
|
|
10018
|
+
});
|
|
9639
10019
|
test("duplicate offset is rejected", () => {
|
|
9640
10020
|
const c = combiner();
|
|
9641
10021
|
c.registerAuthoredSize(void 0, 1, 9, 17, 10);
|
|
@@ -10880,6 +11260,7 @@ function isFmp4Box(data) {
|
|
|
10880
11260
|
const type = String.fromCharCode(data[4], data[5], data[6], data[7]);
|
|
10881
11261
|
return FMPU_BOX_TYPES.has(type);
|
|
10882
11262
|
}
|
|
11263
|
+
var MAX_AWAITING_TIMING_HEADS = 8;
|
|
10883
11264
|
var MmtpContainerParser = class _MmtpContainerParser {
|
|
10884
11265
|
constructor(config) {
|
|
10885
11266
|
this.#tracks = /* @__PURE__ */ new Map();
|
|
@@ -10938,6 +11319,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
10938
11319
|
* reordering into the parser. */
|
|
10939
11320
|
this.#reliableMoqStartupGate = /* @__PURE__ */ new Map();
|
|
10940
11321
|
this.#disposed = false;
|
|
11322
|
+
this.#replayingAwaitingTiming = false;
|
|
10941
11323
|
this.#fedObjects = 0;
|
|
10942
11324
|
this.#reassemblerFragmentsFed = 0;
|
|
10943
11325
|
this.#reassemblerDataUnitsReturned = 0;
|
|
@@ -11030,6 +11412,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11030
11412
|
#reorderStats;
|
|
11031
11413
|
#reliableMoqStartupGate;
|
|
11032
11414
|
#disposed;
|
|
11415
|
+
#replayingAwaitingTiming;
|
|
11033
11416
|
#fedObjects;
|
|
11034
11417
|
#reassemblerFragmentsFed;
|
|
11035
11418
|
#reassemblerDataUnitsReturned;
|
|
@@ -11279,7 +11662,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11279
11662
|
* a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
|
|
11280
11663
|
*/
|
|
11281
11664
|
#drop(reason) {
|
|
11282
|
-
this.#
|
|
11665
|
+
if (this.#replayingAwaitingTiming) this.#countDeferredOutcome(reason);
|
|
11666
|
+
else this.#countOutcome(`drop:${reason}`);
|
|
11283
11667
|
return null;
|
|
11284
11668
|
}
|
|
11285
11669
|
get reorderDiagnostics() {
|
|
@@ -11302,6 +11686,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11302
11686
|
for (const combiner of this.#sampleCombiners.values()) {
|
|
11303
11687
|
combiner.cleanupTimeouts(timeoutMs);
|
|
11304
11688
|
}
|
|
11689
|
+
const now = Date.now();
|
|
11690
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
11691
|
+
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
11692
|
+
awaitingTiming.shift();
|
|
11693
|
+
}
|
|
11694
|
+
}
|
|
11305
11695
|
}
|
|
11306
11696
|
/**
|
|
11307
11697
|
* Phase 1 of two-phase parsing. Returns structured header info for FEC feeding.
|
|
@@ -11382,7 +11772,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11382
11772
|
byteLength: packet.byteLength
|
|
11383
11773
|
};
|
|
11384
11774
|
}
|
|
11385
|
-
if (info.fecPayloadId !== null && this.#sourceSymbolCb) {
|
|
11775
|
+
if (info.fecPayloadId !== null && this.#sourceSymbolCb && !this.#replayingAwaitingTiming) {
|
|
11386
11776
|
const rawSymbol = packet.subarray(0, packet.length - 4);
|
|
11387
11777
|
try {
|
|
11388
11778
|
this.#sourceSymbolCb(info.packetId, info.fecPayloadId.ssId, rawSymbol);
|
|
@@ -11430,6 +11820,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11430
11820
|
}
|
|
11431
11821
|
return this.#drop("fragment-timing-refused");
|
|
11432
11822
|
}
|
|
11823
|
+
this.#replayAwaitingTiming(streamKey, resolver2);
|
|
11433
11824
|
return {
|
|
11434
11825
|
kind: "fragment",
|
|
11435
11826
|
packet: info,
|
|
@@ -11453,7 +11844,18 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11453
11844
|
mfuDuHeader.movieFragmentSequenceNumber,
|
|
11454
11845
|
mfuDuHeader.sampleNumber
|
|
11455
11846
|
);
|
|
11456
|
-
if (!headTiming)
|
|
11847
|
+
if (!headTiming) {
|
|
11848
|
+
this.#awaitTiming(streamKey, {
|
|
11849
|
+
packet,
|
|
11850
|
+
options,
|
|
11851
|
+
parsed,
|
|
11852
|
+
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
11853
|
+
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
11854
|
+
sampleNumber: mfuDuHeader.sampleNumber,
|
|
11855
|
+
arrivedAt: Date.now()
|
|
11856
|
+
});
|
|
11857
|
+
return this.#drop("mfu-sample-timing-missing");
|
|
11858
|
+
}
|
|
11457
11859
|
const offset = mfuDuHeader.offset;
|
|
11458
11860
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset >= headTiming.size)
|
|
11459
11861
|
return this.#drop("mfu-offset-out-of-range");
|
|
@@ -11529,16 +11931,17 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11529
11931
|
const sampleNumber = assembled.sampleNumber;
|
|
11530
11932
|
if (movieFragmentSequenceNumber === void 0 || sampleNumber === void 0)
|
|
11531
11933
|
return this.#drop("assembled-identity-missing");
|
|
11532
|
-
|
|
11934
|
+
const assembledTiming = resolver.sampleTiming(
|
|
11533
11935
|
assembled.mpuSequenceNumber,
|
|
11534
11936
|
movieFragmentSequenceNumber,
|
|
11535
11937
|
sampleNumber
|
|
11536
|
-
)
|
|
11938
|
+
);
|
|
11939
|
+
if (!assembledTiming) return this.#drop("assembled-timing-missing");
|
|
11537
11940
|
if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
|
|
11538
11941
|
return this.#drop("assembled-mpu-mismatch");
|
|
11539
11942
|
let combined;
|
|
11540
11943
|
try {
|
|
11541
|
-
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled);
|
|
11944
|
+
combined = this.#sampleCombinerFor(streamKey).addMfu(assembled, assembledTiming.size);
|
|
11542
11945
|
} catch (error) {
|
|
11543
11946
|
if (!(error instanceof SampleCombineError)) throw error;
|
|
11544
11947
|
console.warn(
|
|
@@ -11847,9 +12250,37 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
11847
12250
|
if (existing) return existing.resolver;
|
|
11848
12251
|
if (!create) return null;
|
|
11849
12252
|
const resolver = new IsoBmffTimingResolver(this.#maxPendingTimingSamples);
|
|
11850
|
-
this.#timingStreams.set(streamKey, { packetId, resolver });
|
|
12253
|
+
this.#timingStreams.set(streamKey, { packetId, resolver, awaitingTiming: [] });
|
|
11851
12254
|
return resolver;
|
|
11852
12255
|
}
|
|
12256
|
+
#awaitTiming(streamKey, head) {
|
|
12257
|
+
const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming;
|
|
12258
|
+
if (!awaitingTiming) return;
|
|
12259
|
+
awaitingTiming.push(head);
|
|
12260
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
|
|
12261
|
+
}
|
|
12262
|
+
/**
|
|
12263
|
+
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
12264
|
+
* FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
|
|
12265
|
+
* FEC path routes a source symbol that already arrived a second time.
|
|
12266
|
+
*/
|
|
12267
|
+
#replayAwaitingTiming(streamKey, resolver) {
|
|
12268
|
+
const state = this.#timingStreams.get(streamKey);
|
|
12269
|
+
if (!state || state.awaitingTiming.length === 0) return;
|
|
12270
|
+
const ready = state.awaitingTiming.filter((head) => resolver.sampleTiming(
|
|
12271
|
+
head.mpuSequenceNumber,
|
|
12272
|
+
head.movieFragmentSequenceNumber,
|
|
12273
|
+
head.sampleNumber
|
|
12274
|
+
));
|
|
12275
|
+
if (ready.length === 0) return;
|
|
12276
|
+
state.awaitingTiming = state.awaitingTiming.filter((head) => !ready.includes(head));
|
|
12277
|
+
this.#replayingAwaitingTiming = true;
|
|
12278
|
+
try {
|
|
12279
|
+
for (const head of ready) this.#feed(head.packet, head.options, head.parsed);
|
|
12280
|
+
} finally {
|
|
12281
|
+
this.#replayingAwaitingTiming = false;
|
|
12282
|
+
}
|
|
12283
|
+
}
|
|
11853
12284
|
#dropTimingStream(streamKey) {
|
|
11854
12285
|
const state = this.#timingStreams.get(streamKey);
|
|
11855
12286
|
if (!state) return;
|
|
@@ -12453,6 +12884,18 @@ var MmtpRouter = class {
|
|
|
12453
12884
|
// MSE recovery routes through CmafBlockAssembler and can reorder by block; the
|
|
12454
12885
|
// direct callback path has to preserve decode order before frames leave libmmt.
|
|
12455
12886
|
#latestVideoSeqByStream = /* @__PURE__ */ new Map();
|
|
12887
|
+
/**
|
|
12888
|
+
* Per stream, SS_ID - packet_sequence_number (mod 2^32) of its latest
|
|
12889
|
+
* first-arrival FEC source packet. A recovered source symbol's wire
|
|
12890
|
+
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
12891
|
+
*/
|
|
12892
|
+
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
12893
|
+
/**
|
|
12894
|
+
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
12895
|
+
* not parsed, typically because its overlap copy was parsed first
|
|
12896
|
+
* (BLO-49179). The next video keyframe emitted on the stream consumes it.
|
|
12897
|
+
*/
|
|
12898
|
+
#multicastRapTwinByStream = /* @__PURE__ */ new Set();
|
|
12456
12899
|
#lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
|
|
12457
12900
|
#lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
|
|
12458
12901
|
#pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
|
|
@@ -12527,11 +12970,14 @@ var MmtpRouter = class {
|
|
|
12527
12970
|
*/
|
|
12528
12971
|
#onPublisherRestart;
|
|
12529
12972
|
#publisherRestarts = 0;
|
|
12973
|
+
#restampedRecoveredSeqs = 0;
|
|
12530
12974
|
/** Inits delivered with no onTrackInit handler for their packetId (MOQT-01). */
|
|
12531
12975
|
#unmappedInitDeliveries = 0;
|
|
12532
12976
|
// FEC Payload IDs left unread because their (owner) packetId had no
|
|
12533
12977
|
// configured fec.blockProfile (see #noteUnreadableFecPayloadId).
|
|
12534
12978
|
#fecPayloadIdsWithoutProfile = 0;
|
|
12979
|
+
// Repair packets discarded by the fec-01 4.5 block-length rule.
|
|
12980
|
+
#repairBlockLengthDiscards = 0;
|
|
12535
12981
|
/** The staged in-place stream switch, if any (stageStreamSwitch). */
|
|
12536
12982
|
#staged = null;
|
|
12537
12983
|
#disposed = false;
|
|
@@ -12585,6 +13031,12 @@ var MmtpRouter = class {
|
|
|
12585
13031
|
...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
|
|
12586
13032
|
};
|
|
12587
13033
|
if (meta.source) frameMeta.source = meta.source;
|
|
13034
|
+
if (isVideo && frameMeta.keyframe) {
|
|
13035
|
+
const twinSeen = this.#multicastRapTwinByStream.delete(
|
|
13036
|
+
this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
|
|
13037
|
+
);
|
|
13038
|
+
if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
|
|
13039
|
+
}
|
|
12588
13040
|
if (meta.deliveryProvenance !== void 0)
|
|
12589
13041
|
frameMeta.deliveryProvenance = meta.deliveryProvenance;
|
|
12590
13042
|
if (meta.recovered) frameMeta.recovered = true;
|
|
@@ -12747,6 +13199,14 @@ var MmtpRouter = class {
|
|
|
12747
13199
|
get publisherRestartCount() {
|
|
12748
13200
|
return this.#publisherRestarts;
|
|
12749
13201
|
}
|
|
13202
|
+
/**
|
|
13203
|
+
* FEC-recovered source symbols whose reconstructed header named a
|
|
13204
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to:
|
|
13205
|
+
* a hop re-stamped the sequence after the sender protected the packet.
|
|
13206
|
+
*/
|
|
13207
|
+
get restampedRecoveredSequenceCount() {
|
|
13208
|
+
return this.#restampedRecoveredSeqs;
|
|
13209
|
+
}
|
|
12750
13210
|
/**
|
|
12751
13211
|
* Packets whose Source or Repair FEC Payload ID was left unread because
|
|
12752
13212
|
* their (owner) packetId had no configured `fec.blockProfile`: FEC not
|
|
@@ -12758,6 +13218,14 @@ var MmtpRouter = class {
|
|
|
12758
13218
|
get fecPayloadIdsWithoutProfile() {
|
|
12759
13219
|
return this.#fecPayloadIdsWithoutProfile;
|
|
12760
13220
|
}
|
|
13221
|
+
/**
|
|
13222
|
+
* Repair packets discarded at admission by the fec-01 4.5 rule (RS_ID not
|
|
13223
|
+
* below RSB_length, or a reed-solomon SSB_length + RSB_length above 255),
|
|
13224
|
+
* before they touched any block state.
|
|
13225
|
+
*/
|
|
13226
|
+
get repairBlockLengthDiscards() {
|
|
13227
|
+
return this.#repairBlockLengthDiscards;
|
|
13228
|
+
}
|
|
12761
13229
|
get reassembler() {
|
|
12762
13230
|
return this.#parser.reassembler;
|
|
12763
13231
|
}
|
|
@@ -13136,13 +13604,13 @@ var MmtpRouter = class {
|
|
|
13136
13604
|
* Feed a repair packet from MoQ (reliable QUIC) — parses MMTP repair
|
|
13137
13605
|
* header and delegates to FECManager for FEC recovery.
|
|
13138
13606
|
*/
|
|
13139
|
-
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
13607
|
+
feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
13140
13608
|
if (this.#disposed) return;
|
|
13141
13609
|
this.#withDeferredFecPokes(() => {
|
|
13142
|
-
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName);
|
|
13610
|
+
this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
|
|
13143
13611
|
});
|
|
13144
13612
|
}
|
|
13145
|
-
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName) {
|
|
13613
|
+
#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
|
|
13146
13614
|
let header;
|
|
13147
13615
|
try {
|
|
13148
13616
|
header = parseMMTPHeader(packet);
|
|
@@ -13173,7 +13641,7 @@ var MmtpRouter = class {
|
|
|
13173
13641
|
this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
|
|
13174
13642
|
return;
|
|
13175
13643
|
}
|
|
13176
|
-
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq");
|
|
13644
|
+
this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
|
|
13177
13645
|
}
|
|
13178
13646
|
}
|
|
13179
13647
|
// ── Packet FEC geometry and block profile ───────────────────────
|
|
@@ -13255,13 +13723,25 @@ var MmtpRouter = class {
|
|
|
13255
13723
|
* the repair, the order they had on the wire, so a loss-free block completes
|
|
13256
13724
|
* clean on its repair. A repair contradicting a known block is dropped.
|
|
13257
13725
|
*/
|
|
13258
|
-
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source) {
|
|
13726
|
+
#handleIsoRepair(ownerPacketId, catalogTrackName, repair, source, repairTrackName) {
|
|
13259
13727
|
const fec = this.#fecManager;
|
|
13260
13728
|
if (!fec?.placeIsoRepair) {
|
|
13261
13729
|
throw new Error(
|
|
13262
13730
|
`[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`
|
|
13263
13731
|
);
|
|
13264
13732
|
}
|
|
13733
|
+
if (fec.admitRepairBlockLength && !fec.admitRepairBlockLength(ownerPacketId, repair.ssbLength, repair.rsbLength, repair.rsId)) {
|
|
13734
|
+
this.#repairBlockLengthDiscards++;
|
|
13735
|
+
return;
|
|
13736
|
+
}
|
|
13737
|
+
if (fec.admitRepairSymbolSize && !fec.admitRepairSymbolSize(
|
|
13738
|
+
ownerPacketId,
|
|
13739
|
+
repair.ssStart,
|
|
13740
|
+
repair.ssbLength,
|
|
13741
|
+
repair.rsId,
|
|
13742
|
+
repair.symbolData.byteLength
|
|
13743
|
+
)) return;
|
|
13744
|
+
if (fec.admitRepairLayerTotal && !fec.admitRepairLayerTotal(ownerPacketId, catalogTrackName, repairTrackName, repair.ssStart, repair.rsbLength)) return;
|
|
13265
13745
|
const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
|
|
13266
13746
|
if (placement.status !== "placed") return;
|
|
13267
13747
|
const blockStart = placement.block.start;
|
|
@@ -13296,6 +13776,17 @@ var MmtpRouter = class {
|
|
|
13296
13776
|
this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
|
|
13297
13777
|
}
|
|
13298
13778
|
}
|
|
13779
|
+
/**
|
|
13780
|
+
* The range repair FETCH for an undelimited hole ended (draft-ramadan-moq-fec
|
|
13781
|
+
* §7.5): what no repair stated becomes repair-less spans, whose held sources
|
|
13782
|
+
* are fed exactly as a span a repair closed.
|
|
13783
|
+
*/
|
|
13784
|
+
closeIsoHoles(ownerPacketId, catalogTrackName, start, length) {
|
|
13785
|
+
const spans = this.#fecManager?.closeIsoHoles?.(ownerPacketId, catalogTrackName, start, length) ?? [];
|
|
13786
|
+
for (const span of spans) {
|
|
13787
|
+
this.#replayIsoSources(ownerPacketId, catalogTrackName, span.block.start, span.placed);
|
|
13788
|
+
}
|
|
13789
|
+
}
|
|
13299
13790
|
/**
|
|
13300
13791
|
* Feed iso-ssbg1-v1 sources a repair just placed, in SS_ID order, exactly as
|
|
13301
13792
|
* a first-arrival source is fed once its block is known: transport
|
|
@@ -13391,6 +13882,8 @@ var MmtpRouter = class {
|
|
|
13391
13882
|
this.#trackSynced.delete(streamKey);
|
|
13392
13883
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
13393
13884
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
13885
|
+
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
13886
|
+
this.#multicastRapTwinByStream.delete(streamKey);
|
|
13394
13887
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
13395
13888
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
13396
13889
|
this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
|
|
@@ -14161,6 +14654,12 @@ var MmtpRouter = class {
|
|
|
14161
14654
|
} else if (fecUnreadable && info.fecPayloadId) {
|
|
14162
14655
|
parseSourceSymbol = !duplicates.parsedSymbols.has(info.fecPayloadId.ssId);
|
|
14163
14656
|
}
|
|
14657
|
+
if (fecPayloadId && !overlapCopy) {
|
|
14658
|
+
this.#ssIdSeqOffsetByStream.set(
|
|
14659
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName),
|
|
14660
|
+
fecPayloadId.ssId - info.sequenceNumber >>> 0
|
|
14661
|
+
);
|
|
14662
|
+
}
|
|
14164
14663
|
if (!this.#fecManager || !info.fecPayloadId || parseSourceSymbol) {
|
|
14165
14664
|
if (this.#fecManager && info.fecPayloadId) {
|
|
14166
14665
|
duplicates.parsedSymbols.add(info.fecPayloadId.ssId);
|
|
@@ -14183,6 +14682,10 @@ var MmtpRouter = class {
|
|
|
14183
14682
|
// An FEC source frame is anchored by its own SS_ID (C.5.2).
|
|
14184
14683
|
...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
|
|
14185
14684
|
}, parsed);
|
|
14685
|
+
} else if (source === "multicast" && info.rapFlag) {
|
|
14686
|
+
this.#multicastRapTwinByStream.add(
|
|
14687
|
+
this.#mediaStreamKey(info.packetId, catalogTrackName)
|
|
14688
|
+
);
|
|
14186
14689
|
}
|
|
14187
14690
|
if (this.#classifyPacketId(info.packetId) === null) return;
|
|
14188
14691
|
if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
|
|
@@ -14737,6 +15240,20 @@ var MmtpRouter = class {
|
|
|
14737
15240
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
|
|
14738
15241
|
if (ownerPacketId == null) return;
|
|
14739
15242
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
15243
|
+
const ssIdSeqOffset = this.#ssIdSeqOffsetByStream.get(
|
|
15244
|
+
this.#mediaStreamKey(ownerPacketId, catalogTrackName)
|
|
15245
|
+
);
|
|
15246
|
+
if (ssIdSeqOffset !== void 0) {
|
|
15247
|
+
result = {
|
|
15248
|
+
...result,
|
|
15249
|
+
symbols: result.symbols.map((sym) => {
|
|
15250
|
+
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
15251
|
+
if (wire === sym.packetSequenceNumber) return sym;
|
|
15252
|
+
this.#restampedRecoveredSeqs++;
|
|
15253
|
+
return { ...sym, packetSequenceNumber: wire };
|
|
15254
|
+
})
|
|
15255
|
+
};
|
|
15256
|
+
}
|
|
14740
15257
|
this.#stream(ownerPacketId, catalogTrackName).duplicates.advance(blockId);
|
|
14741
15258
|
const deliveryProvenance = this.#fecManager?.blockDeliveryProvenance?.(
|
|
14742
15259
|
blockId,
|
|
@@ -15222,189 +15739,6 @@ var MmtpRouter = class {
|
|
|
15222
15739
|
}
|
|
15223
15740
|
};
|
|
15224
15741
|
|
|
15225
|
-
// node_modules/@blockcast/mmt-transport/dist/types.js
|
|
15226
|
-
var MoqFecAlgorithm;
|
|
15227
|
-
(function(MoqFecAlgorithm2) {
|
|
15228
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["None"] = 0] = "None";
|
|
15229
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["Xor"] = 1] = "Xor";
|
|
15230
|
-
MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
|
|
15231
|
-
})(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
|
|
15232
|
-
|
|
15233
|
-
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
15234
|
-
var MPU_HEADER_SIZE2 = 8;
|
|
15235
|
-
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
15236
|
-
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
15237
|
-
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
15238
|
-
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
15239
|
-
|
|
15240
|
-
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
15241
|
-
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
15242
|
-
|
|
15243
|
-
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
15244
|
-
var NTP_SHORT_BITS2 = 32;
|
|
15245
|
-
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
15246
|
-
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
15247
|
-
function isNtpShort(value) {
|
|
15248
|
-
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
15249
|
-
}
|
|
15250
|
-
function compareNtpShort(a, b) {
|
|
15251
|
-
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
15252
|
-
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
15253
|
-
}
|
|
15254
|
-
if (a === b)
|
|
15255
|
-
return "equal";
|
|
15256
|
-
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
15257
|
-
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
15258
|
-
return "after";
|
|
15259
|
-
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
15260
|
-
return "before";
|
|
15261
|
-
return "unordered";
|
|
15262
|
-
}
|
|
15263
|
-
|
|
15264
|
-
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
15265
|
-
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
15266
|
-
"iso-ssbg1-v1"
|
|
15267
|
-
]);
|
|
15268
|
-
|
|
15269
|
-
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
15270
|
-
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
15271
|
-
|
|
15272
|
-
// node_modules/@blockcast/mmt-transport/dist/driad-discovery.js
|
|
15273
|
-
var DRIADDiscovery = class {
|
|
15274
|
-
cache = /* @__PURE__ */ new Map();
|
|
15275
|
-
cacheExpiry = 3e5;
|
|
15276
|
-
// 5 minutes
|
|
15277
|
-
/**
|
|
15278
|
-
* Discover AMT relays for a multicast source address (RFC 8777)
|
|
15279
|
-
*
|
|
15280
|
-
* @param source - The multicast source IP address (NOT the group!)
|
|
15281
|
-
* @returns Array of discovered AMT relays that can tunnel traffic from this source
|
|
15282
|
-
*/
|
|
15283
|
-
async discoverRelays(source) {
|
|
15284
|
-
const cached = this.cache.get(source);
|
|
15285
|
-
if (cached) {
|
|
15286
|
-
return cached;
|
|
15287
|
-
}
|
|
15288
|
-
try {
|
|
15289
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
15290
|
-
const queryDomain = `${reversedSource}.amt.in-addr.arpa`;
|
|
15291
|
-
console.log(`[DRIAD] Discovering relays for source ${source} via ${queryDomain}`);
|
|
15292
|
-
const relays = await this.queryDRIADProxy(source);
|
|
15293
|
-
if (relays.length > 0) {
|
|
15294
|
-
this.cache.set(source, relays);
|
|
15295
|
-
setTimeout(() => this.cache.delete(source), this.cacheExpiry);
|
|
15296
|
-
}
|
|
15297
|
-
return relays;
|
|
15298
|
-
} catch (error) {
|
|
15299
|
-
console.warn(`[DRIAD] Discovery failed for source ${source}:`, error);
|
|
15300
|
-
return [];
|
|
15301
|
-
}
|
|
15302
|
-
}
|
|
15303
|
-
/**
|
|
15304
|
-
* Query DRIAD proxy service (browser-compatible)
|
|
15305
|
-
*/
|
|
15306
|
-
async queryDRIADProxy(source) {
|
|
15307
|
-
const proxyEndpoints = [
|
|
15308
|
-
"https://driad.amt.net/api/v1/relays",
|
|
15309
|
-
"https://multicast-gateway.cloudflare.com/driad"
|
|
15310
|
-
];
|
|
15311
|
-
for (const endpoint of proxyEndpoints) {
|
|
15312
|
-
try {
|
|
15313
|
-
const response = await fetch(`${endpoint}?source=${encodeURIComponent(source)}`, {
|
|
15314
|
-
method: "GET",
|
|
15315
|
-
headers: { Accept: "application/json" },
|
|
15316
|
-
signal: AbortSignal.timeout(5e3)
|
|
15317
|
-
});
|
|
15318
|
-
if (response.ok) {
|
|
15319
|
-
const data = await response.json();
|
|
15320
|
-
return data.relays || [];
|
|
15321
|
-
}
|
|
15322
|
-
} catch {
|
|
15323
|
-
}
|
|
15324
|
-
}
|
|
15325
|
-
const dohRelay = await this.queryDNSOverHTTPS(source);
|
|
15326
|
-
if (dohRelay) {
|
|
15327
|
-
return [dohRelay];
|
|
15328
|
-
}
|
|
15329
|
-
return [];
|
|
15330
|
-
}
|
|
15331
|
-
/**
|
|
15332
|
-
* Query DNS-over-HTTPS for DRIAD relay based on source address (RFC 8777)
|
|
15333
|
-
*/
|
|
15334
|
-
async queryDNSOverHTTPS(source) {
|
|
15335
|
-
try {
|
|
15336
|
-
const reversedSource = source.split(".").reverse().join(".");
|
|
15337
|
-
const queryName = `${reversedSource}.amt.in-addr.arpa`;
|
|
15338
|
-
const dohUrl = `https://cloudflare-dns.com/dns-query?name=${queryName}&type=A`;
|
|
15339
|
-
const response = await fetch(dohUrl, {
|
|
15340
|
-
headers: { Accept: "application/dns-json" },
|
|
15341
|
-
signal: AbortSignal.timeout(3e3)
|
|
15342
|
-
});
|
|
15343
|
-
if (!response.ok) {
|
|
15344
|
-
return null;
|
|
15345
|
-
}
|
|
15346
|
-
const result = await response.json();
|
|
15347
|
-
if (result.Answer && result.Answer.length > 0) {
|
|
15348
|
-
return {
|
|
15349
|
-
host: result.Answer[0].data,
|
|
15350
|
-
port: DEFAULT_AMT_RELAY_PORT2,
|
|
15351
|
-
priority: 10,
|
|
15352
|
-
weight: 100,
|
|
15353
|
-
asn: 0
|
|
15354
|
-
};
|
|
15355
|
-
}
|
|
15356
|
-
return null;
|
|
15357
|
-
} catch (error) {
|
|
15358
|
-
console.warn("[DRIAD] DNS-over-HTTPS query failed:", error);
|
|
15359
|
-
return null;
|
|
15360
|
-
}
|
|
15361
|
-
}
|
|
15362
|
-
/**
|
|
15363
|
-
* Select best relay based on RTT measurements
|
|
15364
|
-
*/
|
|
15365
|
-
async selectBestRelay(relays) {
|
|
15366
|
-
if (relays.length === 0)
|
|
15367
|
-
return null;
|
|
15368
|
-
const measured = await Promise.all(relays.map(async (relay) => {
|
|
15369
|
-
const rtt = await this.measureRTT(relay.host, relay.port);
|
|
15370
|
-
return { ...relay, rtt };
|
|
15371
|
-
}));
|
|
15372
|
-
measured.sort((a, b) => {
|
|
15373
|
-
if (a.priority !== b.priority)
|
|
15374
|
-
return a.priority - b.priority;
|
|
15375
|
-
return (a.rtt || Infinity) - (b.rtt || Infinity);
|
|
15376
|
-
});
|
|
15377
|
-
console.log(`[DRIAD] Selected relay: ${measured[0].host} (RTT: ${measured[0].rtt}ms)`);
|
|
15378
|
-
return measured[0];
|
|
15379
|
-
}
|
|
15380
|
-
async measureRTT(host, _port) {
|
|
15381
|
-
const start = performance.now();
|
|
15382
|
-
try {
|
|
15383
|
-
await fetch(`https://${host}/health`, {
|
|
15384
|
-
method: "HEAD",
|
|
15385
|
-
signal: AbortSignal.timeout(2e3),
|
|
15386
|
-
mode: "no-cors"
|
|
15387
|
-
});
|
|
15388
|
-
return performance.now() - start;
|
|
15389
|
-
} catch {
|
|
15390
|
-
return Infinity;
|
|
15391
|
-
}
|
|
15392
|
-
}
|
|
15393
|
-
/**
|
|
15394
|
-
* Clear the relay cache
|
|
15395
|
-
*/
|
|
15396
|
-
clearCache() {
|
|
15397
|
-
this.cache.clear();
|
|
15398
|
-
}
|
|
15399
|
-
/**
|
|
15400
|
-
* Get cached relays for a source address
|
|
15401
|
-
*/
|
|
15402
|
-
getCached(source) {
|
|
15403
|
-
return this.cache.get(source);
|
|
15404
|
-
}
|
|
15405
|
-
};
|
|
15406
|
-
var driadDiscovery = new DRIADDiscovery();
|
|
15407
|
-
|
|
15408
15742
|
// node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
|
|
15409
15743
|
function endpointKey(endpoint) {
|
|
15410
15744
|
return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
|
|
@@ -15535,8 +15869,8 @@ var AdaptiveBitrateController = class {
|
|
|
15535
15869
|
/**
|
|
15536
15870
|
* Update FEC statistics for ABR decisions
|
|
15537
15871
|
*
|
|
15538
|
-
*
|
|
15539
|
-
*
|
|
15872
|
+
* ABR uses the effective loss rate (after FEC recovery) rather than the
|
|
15873
|
+
* raw transport loss rate.
|
|
15540
15874
|
*
|
|
15541
15875
|
* @param stats - FEC statistics from the FEC decoder
|
|
15542
15876
|
*/
|
|
@@ -15612,6 +15946,45 @@ var AdaptiveBitrateController = class {
|
|
|
15612
15946
|
}
|
|
15613
15947
|
};
|
|
15614
15948
|
|
|
15949
|
+
// node_modules/@blockcast/mmt-base/dist/mmtp.js
|
|
15950
|
+
var MPU_HEADER_SIZE2 = 8;
|
|
15951
|
+
var MPU_LENGTH_FIELD_SIZE2 = 2;
|
|
15952
|
+
var MPU_HEADER_REMAINDER_SIZE2 = MPU_HEADER_SIZE2 - MPU_LENGTH_FIELD_SIZE2;
|
|
15953
|
+
var MMTP_SIGNALING_PACKET_ID2 = 0;
|
|
15954
|
+
var MMTP_PACKET_ID_MAX2 = 65535;
|
|
15955
|
+
|
|
15956
|
+
// node_modules/@blockcast/mmt-base/dist/net-constants.js
|
|
15957
|
+
var DEFAULT_AMT_RELAY_PORT2 = 2268;
|
|
15958
|
+
|
|
15959
|
+
// node_modules/@blockcast/mmt-base/dist/ntp-short.js
|
|
15960
|
+
var NTP_SHORT_BITS2 = 32;
|
|
15961
|
+
var NTP_SHORT_MODULUS2 = 2 ** NTP_SHORT_BITS2;
|
|
15962
|
+
var NTP_SHORT_HALF_RANGE2 = 2 ** (NTP_SHORT_BITS2 - 1);
|
|
15963
|
+
function isNtpShort(value) {
|
|
15964
|
+
return Number.isInteger(value) && value >= 0 && value < NTP_SHORT_MODULUS2;
|
|
15965
|
+
}
|
|
15966
|
+
function compareNtpShort(a, b) {
|
|
15967
|
+
if (!isNtpShort(a) || !isNtpShort(b)) {
|
|
15968
|
+
throw new RangeError(`NTP-short values must be integers in [0, 2^${NTP_SHORT_BITS2}), got ${String(a)} and ${String(b)}`);
|
|
15969
|
+
}
|
|
15970
|
+
if (a === b)
|
|
15971
|
+
return "equal";
|
|
15972
|
+
const forward = (a - b + NTP_SHORT_MODULUS2) % NTP_SHORT_MODULUS2;
|
|
15973
|
+
if (forward < NTP_SHORT_HALF_RANGE2)
|
|
15974
|
+
return "after";
|
|
15975
|
+
if (forward > NTP_SHORT_HALF_RANGE2)
|
|
15976
|
+
return "before";
|
|
15977
|
+
return "unordered";
|
|
15978
|
+
}
|
|
15979
|
+
|
|
15980
|
+
// node_modules/@blockcast/mmt-base/dist/fec-block-profile.js
|
|
15981
|
+
var FEC_BLOCK_PROFILES2 = Object.freeze([
|
|
15982
|
+
"iso-ssbg1-v1"
|
|
15983
|
+
]);
|
|
15984
|
+
|
|
15985
|
+
// node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
|
|
15986
|
+
var ALL_ROLES2 = Object.freeze(["video", "audio"]);
|
|
15987
|
+
|
|
15615
15988
|
// node_modules/@blockcast/mmt-transport/dist/multicast-orchestrator.js
|
|
15616
15989
|
var DEFAULT_DWELL_MS = 3e3;
|
|
15617
15990
|
var DEFAULT_JOIN_DEADLINE_MS = 5e3;
|
|
@@ -15849,8 +16222,23 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
15849
16222
|
consume: "bytes",
|
|
15850
16223
|
...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
|
|
15851
16224
|
};
|
|
16225
|
+
if (input.atsc3) {
|
|
16226
|
+
const { frequency, plpId, serviceId } = input.atsc3;
|
|
16227
|
+
if (!Number.isInteger(frequency) || frequency < 1) {
|
|
16228
|
+
throw new TypeError(`ATSC3 tuning requires a positive integer frequency in kHz, got ${String(frequency)}`);
|
|
16229
|
+
}
|
|
16230
|
+
return {
|
|
16231
|
+
...base,
|
|
16232
|
+
origin: "tuner",
|
|
16233
|
+
standard: "atsc3",
|
|
16234
|
+
frequency,
|
|
16235
|
+
...plpId !== void 0 ? { plpId } : {},
|
|
16236
|
+
...serviceId !== void 0 ? { serviceId } : {}
|
|
16237
|
+
};
|
|
16238
|
+
}
|
|
15852
16239
|
const relay = input.amtRelay?.trim();
|
|
15853
|
-
const
|
|
16240
|
+
const driad = !relay && input.amtDiscovery === "driad";
|
|
16241
|
+
const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
|
|
15854
16242
|
if (!wantsAmt) {
|
|
15855
16243
|
const native = {
|
|
15856
16244
|
...base,
|
|
@@ -15860,6 +16248,20 @@ function toWindowMulticastSubscribeConfig(input) {
|
|
|
15860
16248
|
return native;
|
|
15861
16249
|
}
|
|
15862
16250
|
const relayPort = input.amtRelayPort;
|
|
16251
|
+
if (driad) {
|
|
16252
|
+
if (!base.source)
|
|
16253
|
+
throw new TypeError("AMT DRIAD discovery requires a source address");
|
|
16254
|
+
if (relayPort !== void 0 && !isPositivePort(relayPort)) {
|
|
16255
|
+
throw new TypeError("AMT DRIAD discovery requires a valid relay port when one is given");
|
|
16256
|
+
}
|
|
16257
|
+
return {
|
|
16258
|
+
...base,
|
|
16259
|
+
source: base.source,
|
|
16260
|
+
origin: "amt",
|
|
16261
|
+
discovery: "driad",
|
|
16262
|
+
...relayPort !== void 0 ? { relayPort } : {}
|
|
16263
|
+
};
|
|
16264
|
+
}
|
|
15863
16265
|
if (!relay || relayPort === void 0 || !isPositivePort(relayPort)) {
|
|
15864
16266
|
throw new TypeError("AMT requires a resolved relay and a valid relay port");
|
|
15865
16267
|
}
|
|
@@ -15903,7 +16305,8 @@ function normalizeMulticastEndpoint(endpoint) {
|
|
|
15903
16305
|
port: endpoint.port,
|
|
15904
16306
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
15905
16307
|
...amtRelay ? { amtRelay } : {},
|
|
15906
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
16308
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
16309
|
+
...endpoint.amtDiscovery === "driad" ? { amtDiscovery: "driad" } : {}
|
|
15907
16310
|
};
|
|
15908
16311
|
}
|
|
15909
16312
|
function multicastEndpointKey(endpoint) {
|
|
@@ -15916,7 +16319,9 @@ function multicastEndpointKey(endpoint) {
|
|
|
15916
16319
|
normalized.port,
|
|
15917
16320
|
normalized.mode ?? "auto",
|
|
15918
16321
|
normalized.amtRelay ?? "",
|
|
15919
|
-
normalized.amtRelayPort ?? ""
|
|
16322
|
+
normalized.amtRelayPort ?? "",
|
|
16323
|
+
// A DRIAD join is a different gateway subscription from a native one.
|
|
16324
|
+
...normalized.amtDiscovery ? [normalized.amtDiscovery] : []
|
|
15920
16325
|
]);
|
|
15921
16326
|
}
|
|
15922
16327
|
function isMulticastTrackPacketId(value) {
|
|
@@ -15956,7 +16361,8 @@ var MulticastSubscriptionPool = class {
|
|
|
15956
16361
|
port: config.port,
|
|
15957
16362
|
mode: config.mode,
|
|
15958
16363
|
amtRelay: config.amtRelay,
|
|
15959
|
-
amtRelayPort: config.amtRelayPort
|
|
16364
|
+
amtRelayPort: config.amtRelayPort,
|
|
16365
|
+
amtDiscovery: config.amtDiscovery
|
|
15960
16366
|
});
|
|
15961
16367
|
if (!endpoint)
|
|
15962
16368
|
throw new Error("Invalid multicast endpoint");
|
|
@@ -16022,7 +16428,8 @@ var MulticastSubscriptionPool = class {
|
|
|
16022
16428
|
port: endpoint.port,
|
|
16023
16429
|
...endpoint.mode ? { mode: endpoint.mode } : {},
|
|
16024
16430
|
...endpoint.amtRelay ? { amtRelay: endpoint.amtRelay } : {},
|
|
16025
|
-
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {}
|
|
16431
|
+
...endpoint.amtRelayPort ? { amtRelayPort: endpoint.amtRelayPort } : {},
|
|
16432
|
+
...endpoint.amtDiscovery ? { amtDiscovery: endpoint.amtDiscovery } : {}
|
|
16026
16433
|
}));
|
|
16027
16434
|
const consumers = /* @__PURE__ */ new Map();
|
|
16028
16435
|
let entry;
|
|
@@ -16102,7 +16509,6 @@ var TransportManager = class {
|
|
|
16102
16509
|
};
|
|
16103
16510
|
capabilities = null;
|
|
16104
16511
|
subscription = null;
|
|
16105
|
-
driad = new DRIADDiscovery();
|
|
16106
16512
|
/** Built by `connect()` from the caller's ladder; there is no built-in one. */
|
|
16107
16513
|
abr = null;
|
|
16108
16514
|
multicastOrchestrator = null;
|
|
@@ -16152,8 +16558,8 @@ var TransportManager = class {
|
|
|
16152
16558
|
nativeIGMP: hasGatewayBytes,
|
|
16153
16559
|
directSockets: typeof win?.UDPSocket !== "undefined",
|
|
16154
16560
|
amt: false,
|
|
16155
|
-
driad:
|
|
16156
|
-
//
|
|
16561
|
+
driad: hasGatewayBytes,
|
|
16562
|
+
// the gateway runs RFC 8777 discovery
|
|
16157
16563
|
fecDecode: false
|
|
16158
16564
|
};
|
|
16159
16565
|
console.log("[Transport] Capabilities:", this.capabilities);
|
|
@@ -16164,7 +16570,7 @@ var TransportManager = class {
|
|
|
16164
16570
|
*
|
|
16165
16571
|
* Promotion hierarchy:
|
|
16166
16572
|
* 1. window.multicast gateway bytes
|
|
16167
|
-
* 2. AMT
|
|
16573
|
+
* 2. AMT: a configured relay via the AMT proxy, else gateway DRIAD discovery
|
|
16168
16574
|
* 3. MOQ WebTransport (final fallback)
|
|
16169
16575
|
*
|
|
16170
16576
|
* The ABR ladder (`abrLadder`) and initial rendition (`initialQuality`)
|
|
@@ -16258,7 +16664,7 @@ var TransportManager = class {
|
|
|
16258
16664
|
/**
|
|
16259
16665
|
* Connect via the lowercase window.multicast bytes gateway.
|
|
16260
16666
|
*/
|
|
16261
|
-
async connectWindowMulticast(config, generation) {
|
|
16667
|
+
async connectWindowMulticast(config, generation, mode = "multicast") {
|
|
16262
16668
|
try {
|
|
16263
16669
|
const gateway = this.getWindowMulticastGateway();
|
|
16264
16670
|
if (typeof gateway?.subscribe !== "function")
|
|
@@ -16293,7 +16699,7 @@ var TransportManager = class {
|
|
|
16293
16699
|
}
|
|
16294
16700
|
};
|
|
16295
16701
|
this.state = {
|
|
16296
|
-
mode
|
|
16702
|
+
mode,
|
|
16297
16703
|
connected: true,
|
|
16298
16704
|
group: config.group,
|
|
16299
16705
|
source: config.source,
|
|
@@ -16311,29 +16717,19 @@ var TransportManager = class {
|
|
|
16311
16717
|
}
|
|
16312
16718
|
}
|
|
16313
16719
|
/**
|
|
16314
|
-
* Connect via AMT proxy
|
|
16720
|
+
* Connect via AMT: a configured relay goes through the AMT proxy; with no
|
|
16721
|
+
* relay, the window.multicast gateway discovers one per RFC 8777 (DRIAD).
|
|
16315
16722
|
*/
|
|
16316
16723
|
async connectAmt(config, generation) {
|
|
16317
16724
|
try {
|
|
16318
|
-
|
|
16319
|
-
|
|
16320
|
-
|
|
16321
|
-
const relays = await this.driad.discoverRelays(config.source);
|
|
16322
|
-
if (generation !== this.connectionGeneration)
|
|
16323
|
-
return false;
|
|
16324
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
16325
|
-
if (generation !== this.connectionGeneration)
|
|
16326
|
-
return false;
|
|
16327
|
-
if (bestRelay) {
|
|
16328
|
-
amtRelay = bestRelay.host;
|
|
16329
|
-
this.state.amtRelay = amtRelay;
|
|
16330
|
-
}
|
|
16331
|
-
}
|
|
16332
|
-
if (!amtRelay) {
|
|
16725
|
+
if (config.amtRelay)
|
|
16726
|
+
return await this.connectAmtProxy(config, config.amtRelay, generation);
|
|
16727
|
+
if (config.driadEnabled === false || !config.source || config.mode === "native") {
|
|
16333
16728
|
console.warn("[Transport] No AMT relay available (DRIAD requires source address for SSM)");
|
|
16334
16729
|
return false;
|
|
16335
16730
|
}
|
|
16336
|
-
|
|
16731
|
+
console.log(`[Transport] Asking the gateway for a DRIAD relay for source ${config.source}...`);
|
|
16732
|
+
return await this.connectWindowMulticast({ ...config, amtDiscovery: "driad" }, generation, "amt");
|
|
16337
16733
|
} catch (error) {
|
|
16338
16734
|
console.warn("[Transport] AMT connection failed:", error);
|
|
16339
16735
|
return false;
|
|
@@ -16564,7 +16960,6 @@ var AMTGatewayManager = class {
|
|
|
16564
16960
|
subscriptions = /* @__PURE__ */ new Map();
|
|
16565
16961
|
messageHandler;
|
|
16566
16962
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
16567
|
-
driad = new DRIADDiscovery();
|
|
16568
16963
|
constructor() {
|
|
16569
16964
|
this.messageHandler = (event) => {
|
|
16570
16965
|
const data = event.data;
|
|
@@ -16595,26 +16990,12 @@ var AMTGatewayManager = class {
|
|
|
16595
16990
|
return keyStr;
|
|
16596
16991
|
}
|
|
16597
16992
|
try {
|
|
16598
|
-
|
|
16599
|
-
let discoveryMethod;
|
|
16993
|
+
const relayAddress = config.relayAddress;
|
|
16600
16994
|
const relayPort = config.relayPort || DEFAULT_AMT_RELAY_PORT2;
|
|
16601
|
-
if (
|
|
16602
|
-
|
|
16603
|
-
discoveryMethod = "manual";
|
|
16604
|
-
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
16605
|
-
} else if (key.source) {
|
|
16606
|
-
console.log(`[AMT] No relay configured, discovering via DRIAD for source ${key.source}...`);
|
|
16607
|
-
const relays = await this.driad.discoverRelays(key.source);
|
|
16608
|
-
const bestRelay = await this.driad.selectBestRelay(relays);
|
|
16609
|
-
if (!bestRelay) {
|
|
16610
|
-
throw new Error(`AMT relay discovery failed for source ${key.source}. Please specify a relay address in the subscription configuration.`);
|
|
16611
|
-
}
|
|
16612
|
-
relayAddress = bestRelay.host;
|
|
16613
|
-
discoveryMethod = "driad";
|
|
16614
|
-
console.log(`[AMT] Discovered relay via DRIAD: ${relayAddress}:${relayPort}`);
|
|
16615
|
-
} else {
|
|
16616
|
-
throw new Error(`AMT relay discovery requires a source address for SSM (RFC 8777). Please specify either a relay address or source address.`);
|
|
16995
|
+
if (!relayAddress) {
|
|
16996
|
+
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".`);
|
|
16617
16997
|
}
|
|
16998
|
+
console.log(`[AMT] Using configured relay ${relayAddress}:${relayPort}`);
|
|
16618
16999
|
const subscriptionId = keyStr;
|
|
16619
17000
|
this.pendingPackets.set(subscriptionId, []);
|
|
16620
17001
|
const subscription = {
|
|
@@ -16625,7 +17006,7 @@ var AMTGatewayManager = class {
|
|
|
16625
17006
|
relay: {
|
|
16626
17007
|
address: relayAddress,
|
|
16627
17008
|
port: relayPort,
|
|
16628
|
-
discoveryMethod,
|
|
17009
|
+
discoveryMethod: "manual",
|
|
16629
17010
|
discoveredAt: Date.now()
|
|
16630
17011
|
}
|
|
16631
17012
|
};
|
|
@@ -16781,7 +17162,7 @@ function sameIds(a, b) {
|
|
|
16781
17162
|
for (const id of a) if (!b.has(id)) return false;
|
|
16782
17163
|
return true;
|
|
16783
17164
|
}
|
|
16784
|
-
var MulticastTransport = class
|
|
17165
|
+
var MulticastTransport = class {
|
|
16785
17166
|
#onPacket;
|
|
16786
17167
|
#subscription = null;
|
|
16787
17168
|
#packetListener = null;
|
|
@@ -16853,8 +17234,11 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
16853
17234
|
// droppedPacketIds.
|
|
16854
17235
|
#unadvertisedPacketIds = /* @__PURE__ */ new Set();
|
|
16855
17236
|
#joinGeneration = 0;
|
|
16856
|
-
|
|
17237
|
+
// The provider to subscribe through; window.multicast when unset.
|
|
17238
|
+
#gateway;
|
|
17239
|
+
constructor(onPacket, options = {}) {
|
|
16857
17240
|
this.#onPacket = onPacket;
|
|
17241
|
+
this.#gateway = options.gateway;
|
|
16858
17242
|
}
|
|
16859
17243
|
static isAvailable() {
|
|
16860
17244
|
return hasMulticastGateway();
|
|
@@ -16864,7 +17248,8 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
16864
17248
|
this.#releaseSubscription();
|
|
16865
17249
|
this.#dataPlaneLive = false;
|
|
16866
17250
|
if (this.#disposed) return this.#declined(generation, "disposed");
|
|
16867
|
-
|
|
17251
|
+
const gateway = this.#gateway ?? getMulticastGlobals().multicast;
|
|
17252
|
+
if (typeof gateway?.subscribe !== "function") {
|
|
16868
17253
|
console.warn("[MulticastTransport] Multicast API not available");
|
|
16869
17254
|
return this.#declined(generation, "unavailable");
|
|
16870
17255
|
}
|
|
@@ -16881,11 +17266,13 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
16881
17266
|
mode: config.mode,
|
|
16882
17267
|
amtRelay: config.amtRelay,
|
|
16883
17268
|
amtRelayPort: config.amtRelayPort,
|
|
17269
|
+
amtDiscovery: config.amtDiscovery,
|
|
16884
17270
|
packetIds: config.packetIds,
|
|
16885
|
-
tracks: config.tracks
|
|
17271
|
+
tracks: config.tracks,
|
|
17272
|
+
atsc3: config.atsc3
|
|
16886
17273
|
});
|
|
16887
17274
|
failure = "provider-rejected";
|
|
16888
|
-
const subscription = await
|
|
17275
|
+
const subscription = await gateway.subscribe(subscribeConfig);
|
|
16889
17276
|
failure = "invalid-subscription";
|
|
16890
17277
|
console.log(`[MulticastTransport] window.multicast.subscribe returned:`, !!subscription);
|
|
16891
17278
|
if (this.#disposed || generation !== this.#joinGeneration) {
|
|
@@ -17472,16 +17859,6 @@ var MulticastTransport = class _MulticastTransport {
|
|
|
17472
17859
|
// src/multicast-manager.ts
|
|
17473
17860
|
import { deriveFecInterleaveDepth as deriveFecInterleaveDepth3, FecBlockMapper as FecBlockMapper2 } from "@blockcast/mmt-fec";
|
|
17474
17861
|
|
|
17475
|
-
// src/multicast-auth-catalog.ts
|
|
17476
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
17477
|
-
var BASE64URL_DECODE_TABLE = (() => {
|
|
17478
|
-
const table = new Int8Array(128).fill(-1);
|
|
17479
|
-
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
17480
|
-
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
17481
|
-
}
|
|
17482
|
-
return table;
|
|
17483
|
-
})();
|
|
17484
|
-
|
|
17485
17862
|
// src/repair-layers.ts
|
|
17486
17863
|
var RepairContractError = class extends Error {
|
|
17487
17864
|
constructor(code, path, message) {
|
|
@@ -17555,7 +17932,7 @@ function isFecCatalogGeometry(obj) {
|
|
|
17555
17932
|
const o = obj;
|
|
17556
17933
|
const algorithm = o["algorithm"];
|
|
17557
17934
|
const symbolSize = o["symbolSize"];
|
|
17558
|
-
return typeof algorithm === "string" &&
|
|
17935
|
+
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;
|
|
17559
17936
|
}
|
|
17560
17937
|
function isFecCatalogConfig(obj) {
|
|
17561
17938
|
if (!isFecCatalogGeometry(obj)) return false;
|
|
@@ -17591,6 +17968,13 @@ function isoSpanUnavailable(fec, path, declaresFecInstance) {
|
|
|
17591
17968
|
function catalogFecUnavailable(fec, fecPath) {
|
|
17592
17969
|
if (catalogFecAvailable(fec)) return void 0;
|
|
17593
17970
|
const block = recordOf2(fec);
|
|
17971
|
+
if (fecAlgorithmUnimplemented(block["algorithm"])) {
|
|
17972
|
+
return Object.freeze({
|
|
17973
|
+
code: "track_fec_algorithm_unimplemented",
|
|
17974
|
+
path: `${fecPath}.algorithm`,
|
|
17975
|
+
message: `algorithm ${JSON.stringify(block["algorithm"])} is not implemented: the track plays without FEC`
|
|
17976
|
+
});
|
|
17977
|
+
}
|
|
17594
17978
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
17595
17979
|
const reason = blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
|
|
17596
17980
|
if (reason === void 0) {
|
|
@@ -17633,8 +18017,10 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
|
|
|
17633
18017
|
repairsSkippedRttUnmeasured: 0,
|
|
17634
18018
|
repairsSkippedRttExceedsBudget: 0,
|
|
17635
18019
|
repairsSkippedPresentationDelayUnavailable: 0,
|
|
18020
|
+
repairsSkippedRangeNoAnchor: 0,
|
|
17636
18021
|
lastRepairSkip: null,
|
|
17637
18022
|
keyframeRepairFetchesSent: 0,
|
|
18023
|
+
rangeRepairFetchesSent: 0,
|
|
17638
18024
|
keyframeBudgetHolds: 0,
|
|
17639
18025
|
keyframeBudgetHoldMs: 0,
|
|
17640
18026
|
deltaBlocksFailed: 0,
|
|
@@ -17713,6 +18099,12 @@ var REPAIR_PRIORITY_REASONS = /* @__PURE__ */ new Set([
|
|
|
17713
18099
|
"repair-priority-absent",
|
|
17714
18100
|
"repair-priority-invalid"
|
|
17715
18101
|
]);
|
|
18102
|
+
var REPAIR_SKIP_REASONS = /* @__PURE__ */ new Set([
|
|
18103
|
+
"rtt-unmeasured",
|
|
18104
|
+
"rtt-exceeds-budget",
|
|
18105
|
+
"presentation-delay-unavailable"
|
|
18106
|
+
]);
|
|
18107
|
+
var REPAIR_DEADLINE_BOUNDS = /* @__PURE__ */ new Set(["wait", "presentation", "keyframe", "retention"]);
|
|
17716
18108
|
var GAP_REASONS = {
|
|
17717
18109
|
"rap-lost": "stall",
|
|
17718
18110
|
"rap-unknown": "stall",
|
|
@@ -17735,6 +18127,9 @@ function isSymbolCounts(value) {
|
|
|
17735
18127
|
function isNullableNonNegative(value) {
|
|
17736
18128
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
17737
18129
|
}
|
|
18130
|
+
function isFiniteNumber(value) {
|
|
18131
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
18132
|
+
}
|
|
17738
18133
|
function isRepairLifecycleEvent(value) {
|
|
17739
18134
|
if (!isRecord(value) || value["version"] !== 2) return false;
|
|
17740
18135
|
const block = value["block"];
|
|
@@ -17752,6 +18147,20 @@ function isRepairLifecycleEvent(value) {
|
|
|
17752
18147
|
case "repair-preempted":
|
|
17753
18148
|
case "repair-deferred":
|
|
17754
18149
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
18150
|
+
case "repair-sent":
|
|
18151
|
+
return hasExactKeys(value, [
|
|
18152
|
+
"version",
|
|
18153
|
+
"type",
|
|
18154
|
+
"block",
|
|
18155
|
+
"priority",
|
|
18156
|
+
"rttMs",
|
|
18157
|
+
"budgetMs",
|
|
18158
|
+
"delayMs",
|
|
18159
|
+
"blockAgeMs",
|
|
18160
|
+
"bound"
|
|
18161
|
+
]) && 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"]);
|
|
18162
|
+
case "repair-skipped":
|
|
18163
|
+
return hasExactKeys(value, ["version", "type", "block", "reason", "rttMs", "budgetMs"]) && isRepairBlockIdentity(block) && REPAIR_SKIP_REASONS.has(value["reason"]) && isNullableNonNegative(value["rttMs"]) && isFiniteNumber(value["budgetMs"]);
|
|
17755
18164
|
case "repair-priority": {
|
|
17756
18165
|
const blockClass = value["blockClass"];
|
|
17757
18166
|
const action = value["action"];
|
|
@@ -17931,6 +18340,9 @@ var MulticastManager = class {
|
|
|
17931
18340
|
#router;
|
|
17932
18341
|
#hostMfuTimeoutMs;
|
|
17933
18342
|
#transport;
|
|
18343
|
+
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
18344
|
+
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
18345
|
+
#repairReleases = /* @__PURE__ */ new Map();
|
|
17934
18346
|
#reportedFecDiagnosticsFailure = false;
|
|
17935
18347
|
// ── Stream-global FEC timing reduction ──
|
|
17936
18348
|
//
|
|
@@ -18194,7 +18606,9 @@ var MulticastManager = class {
|
|
|
18194
18606
|
catalogTrackName
|
|
18195
18607
|
);
|
|
18196
18608
|
this.#configureTrackMapper(packetId, config);
|
|
18197
|
-
this.#router.
|
|
18609
|
+
if (this.#router.trackKindFor(packetId) !== trackType) {
|
|
18610
|
+
this.#router.setPacketIdType(packetId, trackType);
|
|
18611
|
+
}
|
|
18198
18612
|
}
|
|
18199
18613
|
/**
|
|
18200
18614
|
* Stop routing a stream's symbols to its Worker decoder. Returns false when
|
|
@@ -18275,6 +18689,14 @@ var MulticastManager = class {
|
|
|
18275
18689
|
);
|
|
18276
18690
|
}
|
|
18277
18691
|
}
|
|
18692
|
+
for (const [packetId, c] of this.#trackFecTiming) {
|
|
18693
|
+
if (c.deliveryWindowMs === void 0) continue;
|
|
18694
|
+
mfuTimeoutMs = Math.max(
|
|
18695
|
+
mfuTimeoutMs ?? 0,
|
|
18696
|
+
this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
|
|
18697
|
+
this.#hostMfuTimeoutMs ?? 0
|
|
18698
|
+
);
|
|
18699
|
+
}
|
|
18278
18700
|
const failbackWindowMs = deliveryWindowMs === void 0 ? minimumFailbackWindowMs : Math.max(deliveryWindowMs, minimumFailbackWindowMs ?? 0);
|
|
18279
18701
|
this.#transport.setFailbackWindowMs(failbackWindowMs ?? null);
|
|
18280
18702
|
this.#router.setMfuTimeoutMs(mfuTimeoutMs ?? this.#hostMfuTimeoutMs);
|
|
@@ -18458,6 +18880,7 @@ var MulticastManager = class {
|
|
|
18458
18880
|
setMfuTimeoutMs(ms) {
|
|
18459
18881
|
this.#router.setMfuTimeoutMs(ms);
|
|
18460
18882
|
this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
|
|
18883
|
+
if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
|
|
18461
18884
|
}
|
|
18462
18885
|
setTrackCodec(packetId, codec) {
|
|
18463
18886
|
this.#router.setTrackCodec(packetId, codec);
|
|
@@ -18578,11 +19001,80 @@ var MulticastManager = class {
|
|
|
18578
19001
|
// through whatever the relay looks like, since dropping it would be the
|
|
18579
19002
|
// worse behaviour.
|
|
18580
19003
|
amtRelayPort: config.amtRelayPort ?? config.relayPort ?? (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
19004
|
+
amtDiscovery: config.amtDiscovery,
|
|
18581
19005
|
packetIds: config.packetIds,
|
|
18582
19006
|
tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId }))
|
|
18583
19007
|
};
|
|
18584
19008
|
return ingress === void 0 ? this.#transport.join(transportConfig) : this.#transport.join(transportConfig, ingress);
|
|
18585
19009
|
}
|
|
19010
|
+
/**
|
|
19011
|
+
* Join the selected rung's dedicated repair groups beside the media join
|
|
19012
|
+
* (pim #3898): one subscription per endpoint, through `provider` when given
|
|
19013
|
+
* (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
|
|
19014
|
+
* new MulticastTransport on `window.multicast`. Returns the call that
|
|
19015
|
+
* releases every one of them; dispose() releases them too.
|
|
19016
|
+
*
|
|
19017
|
+
* Packets go straight to the router with the endpoint's ingress, never
|
|
19018
|
+
* through feedPacket(): repair arriving on its own group is not media
|
|
19019
|
+
* liveness, so it must not hold off the media leg's failback watchdog. The
|
|
19020
|
+
* repair roles and owners are registered here; in-band owners stay the
|
|
19021
|
+
* caller's. Joining is best effort: a group that fails to join is logged
|
|
19022
|
+
* and leaves the media join as it was.
|
|
19023
|
+
*/
|
|
19024
|
+
joinRepairEndpoints(endpoints, provider) {
|
|
19025
|
+
const releases = [];
|
|
19026
|
+
let released = false;
|
|
19027
|
+
const safely = (each) => {
|
|
19028
|
+
try {
|
|
19029
|
+
each();
|
|
19030
|
+
} catch (error) {
|
|
19031
|
+
console.warn("[MulticastManager] repair group release failed", error);
|
|
19032
|
+
}
|
|
19033
|
+
};
|
|
19034
|
+
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
|
|
19035
|
+
this.#applyRepairOwners(repairOwners);
|
|
19036
|
+
for (const endpoint of endpoints) {
|
|
19037
|
+
const ingress = {
|
|
19038
|
+
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId })))
|
|
19039
|
+
};
|
|
19040
|
+
const onPacket = (packet) => {
|
|
19041
|
+
if (!released) this.#router.feedPacket(packet, "multicast", void 0, ingress);
|
|
19042
|
+
};
|
|
19043
|
+
const fail = (error) => console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
|
|
19044
|
+
if (typeof provider === "function") {
|
|
19045
|
+
Promise.resolve().then(() => provider(endpoint, onPacket)).then((release2) => released ? safely(release2) : releases.push(release2), fail);
|
|
19046
|
+
continue;
|
|
19047
|
+
}
|
|
19048
|
+
const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
|
|
19049
|
+
releases.push(() => transport.dispose());
|
|
19050
|
+
void transport.join({
|
|
19051
|
+
sourceAddress: endpoint.source,
|
|
19052
|
+
groupAddress: endpoint.group,
|
|
19053
|
+
port: endpoint.port,
|
|
19054
|
+
mode: endpoint.mode,
|
|
19055
|
+
amtRelay: endpoint.amtRelay,
|
|
19056
|
+
amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
|
|
19057
|
+
packetIds: endpoint.packetIds,
|
|
19058
|
+
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId }))
|
|
19059
|
+
}).then((joined) => {
|
|
19060
|
+
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
19061
|
+
});
|
|
19062
|
+
}
|
|
19063
|
+
const release = () => {
|
|
19064
|
+
if (released) return;
|
|
19065
|
+
released = true;
|
|
19066
|
+
this.#repairReleases.delete(release);
|
|
19067
|
+
for (const each of releases.splice(0)) safely(each);
|
|
19068
|
+
};
|
|
19069
|
+
this.#repairReleases.set(release, repairOwners);
|
|
19070
|
+
return release;
|
|
19071
|
+
}
|
|
19072
|
+
#applyRepairOwners(owners) {
|
|
19073
|
+
for (const { packetId, ownerPacketId } of owners) {
|
|
19074
|
+
this.#router.setPacketIdRole(packetId, "repair");
|
|
19075
|
+
this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
|
|
19076
|
+
}
|
|
19077
|
+
}
|
|
18586
19078
|
// ---------------------------------------------------------------------------
|
|
18587
19079
|
// In-place rendition switch
|
|
18588
19080
|
// ---------------------------------------------------------------------------
|
|
@@ -18858,7 +19350,7 @@ var MulticastManager = class {
|
|
|
18858
19350
|
*
|
|
18859
19351
|
* D-04: Validates completeness via validateSwitchingSet — throws if incomplete.
|
|
18860
19352
|
* D-07: Applies per-track FEC configs (base+delta get decoders; repair does not).
|
|
18861
|
-
* D-17: Builds altGroup → track-name index for getSwitchingSet().
|
|
19353
|
+
* D-17: Builds altGroup → track-name index for getSwitchingSet() (repair legs excluded).
|
|
18862
19354
|
* D-26: Registers packetId → TrackRole on MmtpRouter for block-complete fanout.
|
|
18863
19355
|
*
|
|
18864
19356
|
* FEC availability is per track (draft-ramadan-moq-fec §5.1). A media track
|
|
@@ -18909,11 +19401,9 @@ var MulticastManager = class {
|
|
|
18909
19401
|
}
|
|
18910
19402
|
}
|
|
18911
19403
|
const repairOwnerGroup = /* @__PURE__ */ new Map();
|
|
18912
|
-
const repairOwnerAltGroup = /* @__PURE__ */ new Map();
|
|
18913
19404
|
for (const track of catalog.tracks) {
|
|
18914
19405
|
for (const repairName of repairNamesBySource.get(track.name) ?? []) {
|
|
18915
19406
|
repairOwnerGroup.set(repairName, altGroupKey(track));
|
|
18916
|
-
repairOwnerAltGroup.set(repairName, track.altGroup);
|
|
18917
19407
|
}
|
|
18918
19408
|
}
|
|
18919
19409
|
const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
|
|
@@ -18944,11 +19434,7 @@ var MulticastManager = class {
|
|
|
18944
19434
|
for (const [groupKey, roles] of resolvedRolesByGroup) {
|
|
18945
19435
|
if (!(hasSwitchingSetByGroup.get(groupKey) ?? false)) continue;
|
|
18946
19436
|
const presentRoles = new Set(roles.filter((r) => r !== "single"));
|
|
18947
|
-
const required = [
|
|
18948
|
-
"base",
|
|
18949
|
-
"delta",
|
|
18950
|
-
"repair"
|
|
18951
|
-
];
|
|
19437
|
+
const required = ["base", "repair"];
|
|
18952
19438
|
const missing = required.filter((r) => !presentRoles.has(r));
|
|
18953
19439
|
if (missing.length > 0) {
|
|
18954
19440
|
throw new Error(
|
|
@@ -18995,6 +19481,7 @@ var MulticastManager = class {
|
|
|
18995
19481
|
this.#switchingSets.clear();
|
|
18996
19482
|
this.#repairPacketIds.clear();
|
|
18997
19483
|
this.#router.clearRepairPacketIdOwners();
|
|
19484
|
+
for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
|
|
18998
19485
|
const fecPacketIds = new Set([...fecDecoders.keys()].map((i) => catalog.tracks[i].packetId));
|
|
18999
19486
|
for (const [packetId, catalogTrackName] of this.#multiTrackFecTracks) {
|
|
19000
19487
|
if (fecPacketIds.has(packetId)) continue;
|
|
@@ -19015,11 +19502,10 @@ var MulticastManager = class {
|
|
|
19015
19502
|
for (let i = 0; i < catalog.tracks.length; i++) {
|
|
19016
19503
|
const track = catalog.tracks[i];
|
|
19017
19504
|
const role = resolvedRoles[i];
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
const existing = this.#switchingSets.get(altGroup) ?? [];
|
|
19505
|
+
if (role !== "repair" && track.altGroup !== void 0) {
|
|
19506
|
+
const existing = this.#switchingSets.get(track.altGroup) ?? [];
|
|
19021
19507
|
existing.push(track.name);
|
|
19022
|
-
this.#switchingSets.set(altGroup, existing);
|
|
19508
|
+
this.#switchingSets.set(track.altGroup, existing);
|
|
19023
19509
|
}
|
|
19024
19510
|
if (track.packetId !== void 0) {
|
|
19025
19511
|
this.#router.setPacketIdRole(track.packetId, role);
|
|
@@ -19094,7 +19580,7 @@ var MulticastManager = class {
|
|
|
19094
19580
|
#multiTrackFecTracks = /* @__PURE__ */ new Map();
|
|
19095
19581
|
/**
|
|
19096
19582
|
* Return the track names belonging to the given altGroup switching set.
|
|
19097
|
-
* D-17:
|
|
19583
|
+
* D-17: tracks with equal altGroup form one switching set; repair legs are in none.
|
|
19098
19584
|
*
|
|
19099
19585
|
* @param altGroup - The altGroup number to look up.
|
|
19100
19586
|
* @returns Array of track names in that switching set (empty if none).
|
|
@@ -19122,6 +19608,26 @@ var MulticastManager = class {
|
|
|
19122
19608
|
this.requestRepairForBlock(sbn, packetId, catalogTrackName, blockClass);
|
|
19123
19609
|
};
|
|
19124
19610
|
}
|
|
19611
|
+
/**
|
|
19612
|
+
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
19613
|
+
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
19614
|
+
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
19615
|
+
* once its range FETCH ends (or none is sent).
|
|
19616
|
+
*/
|
|
19617
|
+
onUndelimitedLoss(cb) {
|
|
19618
|
+
this.#fec.setUndelimitedLossHandler(cb);
|
|
19619
|
+
}
|
|
19620
|
+
/**
|
|
19621
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
19622
|
+
* to CmcdProducer.updateFecFailClosed.
|
|
19623
|
+
*/
|
|
19624
|
+
onFecFailClosed(cb) {
|
|
19625
|
+
this.#fec.setFecFailClosedHandler(cb);
|
|
19626
|
+
}
|
|
19627
|
+
/** End a pending hole's range repair: feed what no repair stated as spans. */
|
|
19628
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
19629
|
+
this.#router.closeIsoHoles(packetId, catalogTrackName, start, length);
|
|
19630
|
+
}
|
|
19125
19631
|
/**
|
|
19126
19632
|
* Record a repair request whose SUBSCRIBER_PRIORITY the catalog could not
|
|
19127
19633
|
* supply (draft-ramadan-moq-fec §11.4.5): sent without the parameter, or
|
|
@@ -19143,6 +19649,7 @@ var MulticastManager = class {
|
|
|
19143
19649
|
stats.repairsSkipped++;
|
|
19144
19650
|
if (reason === "rtt-unmeasured") stats.repairsSkippedRttUnmeasured++;
|
|
19145
19651
|
else if (reason === "rtt-exceeds-budget") stats.repairsSkippedRttExceedsBudget++;
|
|
19652
|
+
else if (reason === "range-no-anchor") stats.repairsSkippedRangeNoAnchor++;
|
|
19146
19653
|
else stats.repairsSkippedPresentationDelayUnavailable++;
|
|
19147
19654
|
stats.lastRepairSkip = {
|
|
19148
19655
|
reason,
|
|
@@ -19174,8 +19681,20 @@ var MulticastManager = class {
|
|
|
19174
19681
|
stats.keyframeBudgetHoldMs += extensionMs;
|
|
19175
19682
|
}
|
|
19176
19683
|
/** Record a repair FETCH the scheduler admitted and sent. */
|
|
19177
|
-
noteRepairFetchSent(priority,
|
|
19684
|
+
noteRepairFetchSent(priority, sbn, packetId, catalogTrackName, measurement) {
|
|
19178
19685
|
if (priority === 0) this.#statsFor(packetId, catalogTrackName).keyframeRepairFetchesSent++;
|
|
19686
|
+
if (measurement.range) this.#statsFor(packetId, catalogTrackName).rangeRepairFetchesSent++;
|
|
19687
|
+
this.#emitRepairLifecycle({
|
|
19688
|
+
version: 2,
|
|
19689
|
+
type: "repair-sent",
|
|
19690
|
+
block: repairBlockIdentity(packetId, sbn, catalogTrackName),
|
|
19691
|
+
priority,
|
|
19692
|
+
rttMs: measurement.rttMs,
|
|
19693
|
+
budgetMs: measurement.budgetMs,
|
|
19694
|
+
delayMs: measurement.delayMs,
|
|
19695
|
+
blockAgeMs: measurement.blockAgeMs,
|
|
19696
|
+
bound: measurement.bound
|
|
19697
|
+
});
|
|
19179
19698
|
}
|
|
19180
19699
|
/**
|
|
19181
19700
|
* Record a repair-scheduler decision about a delta block: preempted for
|
|
@@ -19326,6 +19845,7 @@ var MulticastManager = class {
|
|
|
19326
19845
|
this.#trackResetObservers.clear();
|
|
19327
19846
|
this.#repairLifecycleObservers.clear();
|
|
19328
19847
|
this.#transport.dispose();
|
|
19848
|
+
for (const release of [...this.#repairReleases.keys()]) release();
|
|
19329
19849
|
this.#router.dispose();
|
|
19330
19850
|
this.#fec.dispose();
|
|
19331
19851
|
}
|