@blockcast/mmt-container 2.2.0-main.da2e7cd1dd5d → 2.2.0-main.e1bebe787bc9
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 +5 -2
- package/dist/block-policy.d.ts +55 -13
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +104 -32
- package/dist/block-policy.js.map +2 -2
- package/dist/browser-runtime.js +1573 -214
- package/dist/browser-runtime.js.map +3 -3
- package/dist/carp-catalog.js.map +2 -2
- package/dist/catalog-fec-params.d.ts +1 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +14 -1
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +2 -1
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js +5 -1
- package/dist/delta-fallback-config.js.map +3 -3
- package/dist/fec-manager.d.ts +111 -14
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +613 -91
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-state.js +5 -1
- package/dist/fec-state.js.map +2 -2
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/held-layer-admission.js.map +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +48 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +97 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts +104 -12
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +308 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +329 -32
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +307 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.js.map +2 -2
- package/dist/mmtp-router.d.ts +36 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +676 -76
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.js.map +2 -2
- package/dist/multicast-input.js.map +2 -2
- package/dist/multicast-manager.d.ts +26 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1384 -187
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +4 -3
- package/dist/multicast-transport.js.map +2 -2
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +1 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +329 -31
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/signaling.js.map +2 -2
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +307 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +5 -5
- package/src/block-policy.ts +216 -52
- package/src/catalog-fec-params.ts +1 -0
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +593 -33
- package/src/index.ts +5 -0
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +341 -32
- package/src/mmtp-router.ts +614 -61
- package/src/multicast-manager.ts +136 -16
- package/src/no-modules.ts +3 -0
- package/src/repair-fetch.ts +366 -50
- package/src/track-session.ts +3 -0
package/dist/browser-runtime.js
CHANGED
|
@@ -851,6 +851,17 @@ function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
|
851
851
|
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
852
852
|
};
|
|
853
853
|
}
|
|
854
|
+
function extractRepairFecPayloadId(mmtpPacket) {
|
|
855
|
+
const fields = readRepairFecPayloadIdFields(mmtpPacket);
|
|
856
|
+
if (!fields)
|
|
857
|
+
return null;
|
|
858
|
+
return {
|
|
859
|
+
ssStart: fields.ssStart,
|
|
860
|
+
rsbLength: fields.rsbLength,
|
|
861
|
+
rsId: fields.rsId,
|
|
862
|
+
ssbLength: fields.ssbLength
|
|
863
|
+
};
|
|
864
|
+
}
|
|
854
865
|
function parseMoqRepairFrame(frame) {
|
|
855
866
|
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame));
|
|
856
867
|
}
|
|
@@ -1786,13 +1797,25 @@ function fecCatalogTracks(catalog) {
|
|
|
1786
1797
|
});
|
|
1787
1798
|
return { tracks, pointers };
|
|
1788
1799
|
}
|
|
1789
|
-
function
|
|
1800
|
+
function runtimeView(catalog, receiver) {
|
|
1790
1801
|
const { tracks, pointers } = fecCatalogTracks(catalog);
|
|
1791
1802
|
const report = validateFecCatalog({ tracks }, receiver);
|
|
1792
1803
|
const at2 = (path) => {
|
|
1793
1804
|
const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
|
|
1794
1805
|
return m ? pointers[Number(m[1])] + m[2] : path;
|
|
1795
1806
|
};
|
|
1807
|
+
return { tracks, pointers, report, at: at2 };
|
|
1808
|
+
}
|
|
1809
|
+
function runtimeFecCatalogReport(catalog, receiver = RUNTIME_FEC_RECEIVER) {
|
|
1810
|
+
const { report, at: at2 } = runtimeView(catalog, receiver);
|
|
1811
|
+
const issue = (i) => Object.freeze({ code: i.code, path: at2(i.path) });
|
|
1812
|
+
return Object.freeze({
|
|
1813
|
+
instances: Object.freeze(report.instances.map((i) => Object.freeze({ ...i, path: at2(i.path), issues: Object.freeze(i.issues.map(issue)) }))),
|
|
1814
|
+
issues: Object.freeze(report.issues.map(issue))
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
|
|
1818
|
+
const { tracks, pointers, report, at: at2 } = runtimeView(catalog, receiver);
|
|
1796
1819
|
const trackAt = (i) => recordOf(tracks[i]) ?? {};
|
|
1797
1820
|
const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
|
|
1798
1821
|
const why = (i) => Object.freeze({
|
|
@@ -6088,9 +6111,10 @@ function isH264IntraSlice(nal) {
|
|
|
6088
6111
|
const sliceType = readH264SliceType(nal);
|
|
6089
6112
|
return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
|
|
6090
6113
|
}
|
|
6114
|
+
var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
|
|
6091
6115
|
function readH264SliceType(nal) {
|
|
6092
6116
|
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
6093
|
-
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
6117
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
|
|
6094
6118
|
const state = { bitOffset: 0 };
|
|
6095
6119
|
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
6096
6120
|
return readUnsignedExpGolomb(rbsp, state);
|
|
@@ -6459,6 +6483,96 @@ if (void 0) {
|
|
|
6459
6483
|
]))).toBe(false);
|
|
6460
6484
|
});
|
|
6461
6485
|
});
|
|
6486
|
+
describe("readH264SliceType", () => {
|
|
6487
|
+
const wholeNalSliceType = (nal) => {
|
|
6488
|
+
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
6489
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
6490
|
+
const state = { bitOffset: 0 };
|
|
6491
|
+
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
6492
|
+
return readUnsignedExpGolomb(rbsp, state);
|
|
6493
|
+
};
|
|
6494
|
+
const hex3 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
|
|
6495
|
+
const ue = (value) => {
|
|
6496
|
+
const code = (value + 1).toString(2);
|
|
6497
|
+
return "0".repeat(code.length - 1) + code;
|
|
6498
|
+
};
|
|
6499
|
+
const sliceNal = (bits) => {
|
|
6500
|
+
const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
|
|
6501
|
+
const nal = [1];
|
|
6502
|
+
let zeros = 0;
|
|
6503
|
+
for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
|
|
6504
|
+
if (zeros >= 2 && byte <= 3) {
|
|
6505
|
+
nal.push(3);
|
|
6506
|
+
zeros = 0;
|
|
6507
|
+
}
|
|
6508
|
+
nal.push(byte);
|
|
6509
|
+
zeros = byte === 0 ? zeros + 1 : 0;
|
|
6510
|
+
}
|
|
6511
|
+
return Uint8Array.from(nal);
|
|
6512
|
+
};
|
|
6513
|
+
const x264Slices = [
|
|
6514
|
+
["64x48 P", hex3("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
|
|
6515
|
+
["64x48 B", hex3("419e414212fffeeade283707cb70f7"), 6, false],
|
|
6516
|
+
["64x48 non-IDR I", hex3(
|
|
6517
|
+
"4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
|
|
6518
|
+
), 7, true],
|
|
6519
|
+
["1280x720 B, escape at byte 10", hex3(
|
|
6520
|
+
"01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
|
|
6521
|
+
), 6, false],
|
|
6522
|
+
["1280x720 P, escape at byte 15", hex3(
|
|
6523
|
+
"41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
|
|
6524
|
+
), 5, false],
|
|
6525
|
+
["1280x720 B, escape at byte 22", hex3("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
|
|
6526
|
+
["7680x4320 IDR, first_mb_in_slice 97440", hex3(
|
|
6527
|
+
"650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
|
|
6528
|
+
), null, true],
|
|
6529
|
+
["7680x4320 P, first_mb_in_slice 32640", hex3(
|
|
6530
|
+
"410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
|
|
6531
|
+
), 5, false],
|
|
6532
|
+
["7680x4320 P, first_mb_in_slice 97440", hex3(
|
|
6533
|
+
"410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
|
|
6534
|
+
), 5, false]
|
|
6535
|
+
];
|
|
6536
|
+
const syntheticSlices = [
|
|
6537
|
+
["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
|
|
6538
|
+
["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
|
|
6539
|
+
["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
|
|
6540
|
+
["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
|
|
6541
|
+
["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
|
|
6542
|
+
["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
|
|
6543
|
+
["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
|
|
6544
|
+
["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
|
|
6545
|
+
];
|
|
6546
|
+
test("reads the slice_type of real and synthetic slices", () => {
|
|
6547
|
+
for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
|
|
6548
|
+
expect(readH264SliceType(nal), name).toBe(sliceType);
|
|
6549
|
+
}
|
|
6550
|
+
});
|
|
6551
|
+
test("matches the whole-NAL unescape at every truncation", () => {
|
|
6552
|
+
for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
|
|
6553
|
+
for (let end = 0; end <= nal.length; end++) {
|
|
6554
|
+
const cut = nal.subarray(0, end);
|
|
6555
|
+
expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
|
|
6556
|
+
}
|
|
6557
|
+
}
|
|
6558
|
+
});
|
|
6559
|
+
test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
|
|
6560
|
+
const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
|
|
6561
|
+
let seed = 1;
|
|
6562
|
+
const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
|
|
6563
|
+
for (let i = 0; i < 5e3; i++) {
|
|
6564
|
+
const nal = new Uint8Array(2 + next() % 63);
|
|
6565
|
+
nal[0] = 65;
|
|
6566
|
+
for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
|
|
6567
|
+
expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
|
|
6568
|
+
}
|
|
6569
|
+
});
|
|
6570
|
+
test("classifies the x264 slices as keyframes or not", () => {
|
|
6571
|
+
for (const [name, nal, , keyframe] of x264Slices) {
|
|
6572
|
+
expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
|
|
6573
|
+
}
|
|
6574
|
+
});
|
|
6575
|
+
});
|
|
6462
6576
|
describe("avccToAnnexB", () => {
|
|
6463
6577
|
test("converts with SPS/PPS on keyframe", () => {
|
|
6464
6578
|
const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
|
|
@@ -8625,9 +8739,9 @@ async function openSubscription(rx, openedPromise, options, packetIds) {
|
|
|
8625
8739
|
} catch (error) {
|
|
8626
8740
|
throw new MulticastError("subscription-failed", "MulticastReceiver did not open", error);
|
|
8627
8741
|
}
|
|
8628
|
-
if (
|
|
8742
|
+
if (opened.integrityScheme !== INTEGRITY_SCHEME) {
|
|
8629
8743
|
await rx.close();
|
|
8630
|
-
throw unsupported(`integrity scheme ${String(
|
|
8744
|
+
throw unsupported(`integrity scheme ${String(opened.integrityScheme)} is not ${INTEGRITY_SCHEME}`);
|
|
8631
8745
|
}
|
|
8632
8746
|
const events = new EventTarget();
|
|
8633
8747
|
let state = "connected";
|
|
@@ -8746,6 +8860,7 @@ var MOQT_PUBLISHER_PRIORITY = Object.freeze({
|
|
|
8746
8860
|
});
|
|
8747
8861
|
|
|
8748
8862
|
// node_modules/@blockcast/mmt-transport/dist/amt-gateway.js
|
|
8863
|
+
var MAX_PENDING_PACKETS = 256;
|
|
8749
8864
|
var AMTGatewayManager = class {
|
|
8750
8865
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8751
8866
|
messageHandler;
|
|
@@ -8869,7 +8984,7 @@ var AMTGatewayManager = class {
|
|
|
8869
8984
|
if (!subscription.handshakeComplete) {
|
|
8870
8985
|
const queue = this.pendingPackets.get(subscriptionId);
|
|
8871
8986
|
const packetData2 = data;
|
|
8872
|
-
if (queue) {
|
|
8987
|
+
if (queue && queue.length < MAX_PENDING_PACKETS) {
|
|
8873
8988
|
queue.push({
|
|
8874
8989
|
data: packetData2.data,
|
|
8875
8990
|
remoteAddress: packetData2.remoteAddress,
|
|
@@ -12434,6 +12549,7 @@ var TrackSession = class {
|
|
|
12434
12549
|
this.#state = "idle";
|
|
12435
12550
|
this.#subscription = null;
|
|
12436
12551
|
this.#disarmFec();
|
|
12552
|
+
this.#unsuppress();
|
|
12437
12553
|
}
|
|
12438
12554
|
// -----------------------------------------------------------------------
|
|
12439
12555
|
// Internal
|
|
@@ -12927,6 +13043,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12927
13043
|
this.#heldEvicted = 0;
|
|
12928
13044
|
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
12929
13045
|
this.#holes = [];
|
|
13046
|
+
/** Holes the horizon passed while pending: sources held until closed. */
|
|
13047
|
+
this.#expired = [];
|
|
13048
|
+
/** Of `#expired`, those `takeExpiredHoles` has not handed out yet. */
|
|
13049
|
+
this.#newlyExpired = [];
|
|
13050
|
+
/**
|
|
13051
|
+
* Spans closed from expired holes: behind the horizon, so kept only for
|
|
13052
|
+
* `locate` while their sources are fed, until the next retirement.
|
|
13053
|
+
*/
|
|
13054
|
+
this.#closedBehind = [];
|
|
12930
13055
|
/**
|
|
12931
13056
|
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
12932
13057
|
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
@@ -12948,7 +13073,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12948
13073
|
#retentionBlocks;
|
|
12949
13074
|
#heldEvicted;
|
|
12950
13075
|
#newest;
|
|
13076
|
+
#newestSource;
|
|
12951
13077
|
#holes;
|
|
13078
|
+
#expired;
|
|
13079
|
+
#newlyExpired;
|
|
13080
|
+
#closedBehind;
|
|
12952
13081
|
static #checkedRetention(retentionBlocks) {
|
|
12953
13082
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
12954
13083
|
throw new Error(
|
|
@@ -12985,6 +13114,21 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12985
13114
|
observe(position) {
|
|
12986
13115
|
if (this.#newest === void 0 || serial32Precedes(this.#newest, position)) this.#newest = position;
|
|
12987
13116
|
}
|
|
13117
|
+
/**
|
|
13118
|
+
* The newest source SS_ID noted with `noteSource` (RFC 1982 order). Unlike
|
|
13119
|
+
* `newest`, a repair never moves it: a repair can run ahead of its sources,
|
|
13120
|
+
* a source cannot run ahead of the sources sent before it except by
|
|
13121
|
+
* reordering.
|
|
13122
|
+
*/
|
|
13123
|
+
get newestSource() {
|
|
13124
|
+
return this.#newestSource;
|
|
13125
|
+
}
|
|
13126
|
+
/** Note a received source's SS_ID; true when it is the newest one yet. */
|
|
13127
|
+
noteSource(ssId) {
|
|
13128
|
+
if (this.#newestSource !== void 0 && !serial32Precedes(this.#newestSource, ssId)) return false;
|
|
13129
|
+
this.#newestSource = ssId;
|
|
13130
|
+
return true;
|
|
13131
|
+
}
|
|
12988
13132
|
/** Held sources evicted by `heldCapacity` (never by the horizon itself). */
|
|
12989
13133
|
get heldEvicted() {
|
|
12990
13134
|
return this.#heldEvicted;
|
|
@@ -13003,17 +13147,29 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13003
13147
|
}
|
|
13004
13148
|
/** The known block or span containing `ssId`, with its ESI. */
|
|
13005
13149
|
locate(ssId) {
|
|
13006
|
-
for (
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13150
|
+
for (const blocks of [this.#blocks, this.#closedBehind]) {
|
|
13151
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
13152
|
+
const block = blocks[i];
|
|
13153
|
+
if (isoBlockContains(block.start, block.length, ssId)) {
|
|
13154
|
+
return { block, esi: serial32Distance(block.start, ssId) };
|
|
13155
|
+
}
|
|
13010
13156
|
}
|
|
13011
13157
|
}
|
|
13012
13158
|
return null;
|
|
13013
13159
|
}
|
|
13014
|
-
/** Number of pending
|
|
13160
|
+
/** Number of holes not closed yet, pending or past the horizon. */
|
|
13015
13161
|
get holeCount() {
|
|
13016
|
-
return this.#holes.length;
|
|
13162
|
+
return this.#holes.length + this.#expired.length;
|
|
13163
|
+
}
|
|
13164
|
+
/**
|
|
13165
|
+
* The pending holes the horizon has passed since the last call, in the
|
|
13166
|
+
* order it passed them. Each is no longer pending: no repair states a block
|
|
13167
|
+
* in it (that repair is `stale`, as for a span the horizon retired) and the
|
|
13168
|
+
* release gate does not wait for it. Its owner must close it
|
|
13169
|
+
* (`closeHolesWithin`), which turns it into a span that is not kept here.
|
|
13170
|
+
*/
|
|
13171
|
+
takeExpiredHoles() {
|
|
13172
|
+
return this.#newlyExpired.splice(0);
|
|
13017
13173
|
}
|
|
13018
13174
|
/** The stated block (never a span) ending exactly at `end`. */
|
|
13019
13175
|
blockEndingAt(end) {
|
|
@@ -13069,9 +13225,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13069
13225
|
/**
|
|
13070
13226
|
* Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
|
|
13071
13227
|
* block states its range and places every held source in it; later repair
|
|
13072
|
-
* symbols of the same block change nothing. A range
|
|
13073
|
-
*
|
|
13074
|
-
*
|
|
13228
|
+
* symbols of the same block change nothing. A repair whose range is exactly
|
|
13229
|
+
* a repair-less span states that span's one block. A range that contradicts
|
|
13230
|
+
* a known block (a different length, or an overlap with another block or
|
|
13231
|
+
* with part of a span) fails closed: the repair symbol is dropped and no
|
|
13232
|
+
* block changes.
|
|
13075
13233
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
13076
13234
|
* A block so far past `newest` that stating it would retire the position
|
|
13077
13235
|
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
@@ -13090,7 +13248,16 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13090
13248
|
const known = this.blockAt(start);
|
|
13091
13249
|
if (known !== void 0) {
|
|
13092
13250
|
if (known.span) {
|
|
13093
|
-
|
|
13251
|
+
if (known.length === length) {
|
|
13252
|
+
const block2 = { start, length, span: false };
|
|
13253
|
+
this.#blocks[this.#blocks.indexOf(known)] = block2;
|
|
13254
|
+
return { status: "placed", block: block2, placed: [] };
|
|
13255
|
+
}
|
|
13256
|
+
return length < known.length ? {
|
|
13257
|
+
status: "overlap",
|
|
13258
|
+
reason: `repair block ${start}+${length} is only the first block of repair-less span ${known.start}+${known.length}`,
|
|
13259
|
+
ofSpan: known
|
|
13260
|
+
} : { status: "overlap", reason: `repair block ${start}+${length} runs past repair-less span ${known.start}+${known.length}` };
|
|
13094
13261
|
}
|
|
13095
13262
|
if (known.length !== length) {
|
|
13096
13263
|
return {
|
|
@@ -13158,18 +13325,28 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13158
13325
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
13159
13326
|
}
|
|
13160
13327
|
/**
|
|
13161
|
-
* Turn every
|
|
13162
|
-
*
|
|
13163
|
-
*
|
|
13328
|
+
* Turn every hole inside `[start, start + length)` into a repair-less span,
|
|
13329
|
+
* claiming its held sources: its range FETCH ended, so nothing more will
|
|
13330
|
+
* state its blocks. A hole the horizon passed (`takeExpiredHoles`) leaves a
|
|
13331
|
+
* span that is not kept among the blocks, as the horizon would retire it at
|
|
13332
|
+
* once; only `locate` finds it, until the next retirement, so its sources
|
|
13333
|
+
* can be fed. Returns the spans, in SS_ID order.
|
|
13164
13334
|
*/
|
|
13165
13335
|
closeHolesWithin(start, length) {
|
|
13166
13336
|
const closed = [];
|
|
13167
|
-
for (const
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13337
|
+
for (const holes of [this.#holes, this.#expired]) {
|
|
13338
|
+
for (const hole of [...holes]) {
|
|
13339
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
13340
|
+
holes.splice(holes.indexOf(hole), 1);
|
|
13341
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
13342
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
13343
|
+
if (holes === this.#holes) {
|
|
13344
|
+
this.#blocks.push(spanBlock);
|
|
13345
|
+
} else {
|
|
13346
|
+
this.#closedBehind.push(spanBlock);
|
|
13347
|
+
if (this.#newlyExpired.includes(hole)) this.#newlyExpired.splice(this.#newlyExpired.indexOf(hole), 1);
|
|
13348
|
+
}
|
|
13349
|
+
}
|
|
13173
13350
|
}
|
|
13174
13351
|
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
13175
13352
|
}
|
|
@@ -13183,15 +13360,17 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13183
13360
|
return void 0;
|
|
13184
13361
|
}
|
|
13185
13362
|
/**
|
|
13186
|
-
* Retire every block and span whose last SS_ID, and every held source
|
|
13187
|
-
* lies more than `retentionBlocks` blocks behind
|
|
13188
|
-
* lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
13189
|
-
* horizon uses
|
|
13363
|
+
* Retire every block and span whose last SS_ID, and every held source
|
|
13364
|
+
* outside a hole, lies more than `retentionBlocks` blocks behind
|
|
13365
|
+
* `position`, with the shared lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
13366
|
+
* every ISO interleave horizon uses; a pending hole so far behind expires
|
|
13367
|
+
* (`takeExpiredHoles`). Returns the retired block starts.
|
|
13190
13368
|
*/
|
|
13191
13369
|
retireBehind(position) {
|
|
13192
13370
|
this.observe(position);
|
|
13193
13371
|
const horizon = this.#retentionBlocks;
|
|
13194
13372
|
const retired = [];
|
|
13373
|
+
this.#closedBehind.length = 0;
|
|
13195
13374
|
for (let i = this.#blocks.length - 1; i >= 0; i--) {
|
|
13196
13375
|
const block = this.#blocks[i];
|
|
13197
13376
|
const last = serial32Add(block.start, block.length - 1);
|
|
@@ -13203,10 +13382,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13203
13382
|
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
13204
13383
|
const hole = this.#holes[i];
|
|
13205
13384
|
const last = serial32Add(hole.start, hole.length - 1);
|
|
13206
|
-
if (isoBlocksBehindLowerBound(last, position, this.#kMax)
|
|
13385
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) <= horizon) continue;
|
|
13386
|
+
this.#holes.splice(i, 1);
|
|
13387
|
+
this.#expired.push(hole);
|
|
13388
|
+
this.#newlyExpired.push(hole);
|
|
13207
13389
|
}
|
|
13208
13390
|
for (const ssId of [...this.#held.keys()]) {
|
|
13209
|
-
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#
|
|
13391
|
+
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon && !this.#holes.some((hole) => isoBlockContains(hole.start, hole.length, ssId)) && !this.#expired.some((hole) => isoBlockContains(hole.start, hole.length, ssId))) {
|
|
13392
|
+
this.#held.delete(ssId);
|
|
13393
|
+
}
|
|
13210
13394
|
}
|
|
13211
13395
|
return retired;
|
|
13212
13396
|
}
|
|
@@ -13214,9 +13398,13 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13214
13398
|
reset() {
|
|
13215
13399
|
this.#blocks.length = 0;
|
|
13216
13400
|
this.#holes.length = 0;
|
|
13401
|
+
this.#expired.length = 0;
|
|
13402
|
+
this.#newlyExpired.length = 0;
|
|
13403
|
+
this.#closedBehind.length = 0;
|
|
13217
13404
|
this.#held.clear();
|
|
13218
13405
|
this.#coverageEnd = void 0;
|
|
13219
13406
|
this.#newest = void 0;
|
|
13407
|
+
this.#newestSource = void 0;
|
|
13220
13408
|
}
|
|
13221
13409
|
#claim(block) {
|
|
13222
13410
|
const placed = [];
|
|
@@ -13355,8 +13543,9 @@ function keyframeIntervalMediaTicks(geometry2, mediaTimescale) {
|
|
|
13355
13543
|
return scaled / divisor;
|
|
13356
13544
|
}
|
|
13357
13545
|
function compareDataUnitStarts(a, b) {
|
|
13358
|
-
return a.movieFragment - b.movieFragment || a.idx - b.idx || a.offset - b.offset;
|
|
13546
|
+
return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
|
|
13359
13547
|
}
|
|
13548
|
+
var UNPLACED = { rapNotMpuStart: false };
|
|
13360
13549
|
var BlockClassifier = class {
|
|
13361
13550
|
#geometry;
|
|
13362
13551
|
#mode;
|
|
@@ -13379,8 +13568,23 @@ var BlockClassifier = class {
|
|
|
13379
13568
|
#mpuSbnSpans = /* @__PURE__ */ new Map();
|
|
13380
13569
|
#dataUnitStarts = /* @__PURE__ */ new Map();
|
|
13381
13570
|
#highestMpu = null;
|
|
13382
|
-
/**
|
|
13383
|
-
|
|
13571
|
+
/**
|
|
13572
|
+
* P3 layout, kept for the MPUs within the classification horizon and valid
|
|
13573
|
+
* within one continuous SBN sequence (`noteSourceDiscontinuity`).
|
|
13574
|
+
*/
|
|
13575
|
+
#mpus = /* @__PURE__ */ new Map();
|
|
13576
|
+
/** An MPU of this sequence showed two movie fragments: each frame is one. */
|
|
13577
|
+
#fragmentPerFrame = false;
|
|
13578
|
+
/** A DU header of this sequence stated sample_number above 1. */
|
|
13579
|
+
#multiSampleFragment = false;
|
|
13580
|
+
/**
|
|
13581
|
+
* The anchor received last, whether or not its MPU is still in the
|
|
13582
|
+
* horizon. Each new anchor, and the anchor of every DU header's MPU, is
|
|
13583
|
+
* checked against it.
|
|
13584
|
+
*/
|
|
13585
|
+
#lastAnchor = null;
|
|
13586
|
+
/** Two anchors were exactly G fragments per MPU apart. */
|
|
13587
|
+
#fragmentsProven = false;
|
|
13384
13588
|
#lastRap = null;
|
|
13385
13589
|
constructor(geometry2) {
|
|
13386
13590
|
this.#geometry = geometry2;
|
|
@@ -13410,7 +13614,7 @@ var BlockClassifier = class {
|
|
|
13410
13614
|
this.#geometry = geometry2;
|
|
13411
13615
|
this.#blocks.clear();
|
|
13412
13616
|
this.#clearContiguityLedger();
|
|
13413
|
-
this.#
|
|
13617
|
+
this.#clearMpuLayout();
|
|
13414
13618
|
this.#lastRap = null;
|
|
13415
13619
|
this.#mpuBoundsRaps = true;
|
|
13416
13620
|
if (geometry2.trackKind === "video" && geometry2.mode === "all-protected") {
|
|
@@ -13444,11 +13648,13 @@ var BlockClassifier = class {
|
|
|
13444
13648
|
/**
|
|
13445
13649
|
* The stream's SBN sequence restarted (FECManager source discontinuity:
|
|
13446
13650
|
* a publisher restart, or the SS_ID space wrapped). Authored order and SBN
|
|
13447
|
-
* order are comparable only within one continuous sequence,
|
|
13448
|
-
*
|
|
13651
|
+
* order are comparable only within one continuous sequence, and a
|
|
13652
|
+
* restarted publisher numbers MPUs and movie fragments again, so the P1
|
|
13653
|
+
* ledger and the P3 layout start again.
|
|
13449
13654
|
*/
|
|
13450
13655
|
noteSourceDiscontinuity() {
|
|
13451
13656
|
this.#clearContiguityLedger();
|
|
13657
|
+
this.#clearMpuLayout();
|
|
13452
13658
|
}
|
|
13453
13659
|
/** Register a block that exists without evidence (a vanished block). */
|
|
13454
13660
|
touch(sbn) {
|
|
@@ -13467,16 +13673,16 @@ var BlockClassifier = class {
|
|
|
13467
13673
|
if (this.#geometry.trackKind === "audio") return [];
|
|
13468
13674
|
const changes = [];
|
|
13469
13675
|
const block = this.#blockFor(sbn);
|
|
13676
|
+
const placement = this.#place(evidence);
|
|
13470
13677
|
if (evidence.rap) block.rapSeen = true;
|
|
13471
13678
|
if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
block.
|
|
13679
|
+
const { position } = placement;
|
|
13680
|
+
if (position !== void 0) {
|
|
13681
|
+
block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
|
|
13682
|
+
block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
|
|
13475
13683
|
}
|
|
13476
|
-
if (
|
|
13477
|
-
|
|
13478
|
-
}
|
|
13479
|
-
const violation = this.#checkInvariants(sbn, block, evidence);
|
|
13684
|
+
if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
|
|
13685
|
+
const violation = this.#checkInvariants(sbn, block, evidence, placement);
|
|
13480
13686
|
if (violation !== null) changes.push(...this.#disable(violation));
|
|
13481
13687
|
const next = this.#classify(block);
|
|
13482
13688
|
if (next !== block.cls && this.#allowed(block.cls, next)) {
|
|
@@ -13529,35 +13735,89 @@ var BlockClassifier = class {
|
|
|
13529
13735
|
}
|
|
13530
13736
|
return block;
|
|
13531
13737
|
}
|
|
13532
|
-
#checkInvariants(sbn, block, evidence) {
|
|
13738
|
+
#checkInvariants(sbn, block, evidence, placement) {
|
|
13533
13739
|
if (this.#mode === "all-protected" || this.#geometry.trackKind !== "video") return null;
|
|
13534
13740
|
const geometry2 = this.#geometry;
|
|
13535
13741
|
if (geometry2.mode !== "classifying") return null;
|
|
13536
|
-
if (
|
|
13537
|
-
|
|
13538
|
-
}
|
|
13539
|
-
if (evidence.idx !== void 0 && evidence.idx >= geometry2.gopFrames) {
|
|
13742
|
+
if (placement.rapNotMpuStart) return "rap-not-mpu-start";
|
|
13743
|
+
if (placement.position !== void 0 && placement.position >= geometry2.gopFrames) {
|
|
13540
13744
|
return "mpu-longer-than-gop";
|
|
13541
13745
|
}
|
|
13542
|
-
if (block.mpus.size === 1 && block.
|
|
13746
|
+
if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0 && block.positionMax - block.positionMin >= geometry2.interleaveUnits) {
|
|
13543
13747
|
return "block-wider-than-interleave";
|
|
13544
13748
|
}
|
|
13545
|
-
if (
|
|
13546
|
-
const fragment = this.#mpuFragments.get(evidence.mpu);
|
|
13547
|
-
if (fragment === void 0) {
|
|
13548
|
-
this.#mpuFragments.set(evidence.mpu, evidence.movieFragment);
|
|
13549
|
-
for (const mpu of this.#mpuFragments.keys()) {
|
|
13550
|
-
if (mpu + 1 < evidence.mpu) this.#mpuFragments.delete(mpu);
|
|
13551
|
-
}
|
|
13552
|
-
} else if (fragment !== evidence.movieFragment) {
|
|
13553
|
-
return "mpu-multiple-fragments";
|
|
13554
|
-
}
|
|
13555
|
-
}
|
|
13749
|
+
if (placement.violation !== void 0) return placement.violation;
|
|
13556
13750
|
if (evidence.mpu !== void 0 && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {
|
|
13557
13751
|
return "block-not-contiguous";
|
|
13558
13752
|
}
|
|
13559
13753
|
return null;
|
|
13560
13754
|
}
|
|
13755
|
+
/**
|
|
13756
|
+
* The MPU position a source symbol's DU header proves (P3), and what it
|
|
13757
|
+
* refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.
|
|
13758
|
+
*/
|
|
13759
|
+
#place(evidence) {
|
|
13760
|
+
const { mpu, idx, movieFragment: fragment } = evidence;
|
|
13761
|
+
if (idx === void 0) return UNPLACED;
|
|
13762
|
+
const bySample = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 };
|
|
13763
|
+
if (mpu === void 0 || fragment === void 0) {
|
|
13764
|
+
return this.#fragmentPerFrame && !this.#multiSampleFragment ? { rapNotMpuStart: bySample.rapNotMpuStart } : bySample;
|
|
13765
|
+
}
|
|
13766
|
+
let layout = this.#mpus.get(mpu);
|
|
13767
|
+
if (layout === void 0) {
|
|
13768
|
+
layout = { low: fragment };
|
|
13769
|
+
this.#mpus.set(mpu, layout);
|
|
13770
|
+
for (const other of this.#mpus.keys()) {
|
|
13771
|
+
if (other + 1 < mpu) this.#mpus.delete(other);
|
|
13772
|
+
}
|
|
13773
|
+
} else if (fragment !== layout.low) {
|
|
13774
|
+
this.#fragmentPerFrame = true;
|
|
13775
|
+
if ((fragment - layout.low | 0) < 0) layout.low = fragment;
|
|
13776
|
+
}
|
|
13777
|
+
if (idx !== 0) this.#multiSampleFragment = true;
|
|
13778
|
+
let arrival;
|
|
13779
|
+
if (evidence.rap && layout.anchor === void 0) {
|
|
13780
|
+
layout.anchor = fragment;
|
|
13781
|
+
arrival = this.#anchorDrift(mpu, fragment);
|
|
13782
|
+
if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true;
|
|
13783
|
+
this.#lastAnchor = { mpu, fragment };
|
|
13784
|
+
}
|
|
13785
|
+
if (!this.#fragmentPerFrame) return bySample;
|
|
13786
|
+
if (this.#multiSampleFragment) return { ...bySample, violation: "mpu-multiple-fragments" };
|
|
13787
|
+
const { anchor } = layout;
|
|
13788
|
+
if (anchor === void 0) return UNPLACED;
|
|
13789
|
+
const drift = arrival ?? this.#anchorDrift(mpu, anchor);
|
|
13790
|
+
const offset = fragment - anchor | 0;
|
|
13791
|
+
return {
|
|
13792
|
+
...offset === 0 || offset > 0 && this.#fragmentsProven ? { position: offset } : {},
|
|
13793
|
+
rapNotMpuStart: evidence.rap && offset !== 0 || (layout.low - anchor | 0) < 0 || // Fragments count frames: an anchor arriving past the spacing is a
|
|
13794
|
+
// RAP inside its MPU, or an earlier MPU outran G.
|
|
13795
|
+
arrival !== void 0 && arrival > 0 && this.#fragmentsProven,
|
|
13796
|
+
...drift === void 0 || drift === 0 ? {} : { violation: "rap-spacing-mismatch" }
|
|
13797
|
+
};
|
|
13798
|
+
}
|
|
13799
|
+
/**
|
|
13800
|
+
* How many fragments MPU m's anchor `fragment` lies past the start that
|
|
13801
|
+
* the anchor received last predicts for MPU m: one frame per fragment and
|
|
13802
|
+
* G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')
|
|
13803
|
+
* fragments apart, modulo 2^32. Undefined without a last anchor, a
|
|
13804
|
+
* cadence, or this layout.
|
|
13805
|
+
*/
|
|
13806
|
+
#anchorDrift(mpu, fragment) {
|
|
13807
|
+
const geometry2 = this.#geometry;
|
|
13808
|
+
const last = this.#lastAnchor;
|
|
13809
|
+
if (last === null || !this.#fragmentPerFrame || this.#multiSampleFragment || geometry2.trackKind !== "video" || geometry2.mode !== "classifying") {
|
|
13810
|
+
return void 0;
|
|
13811
|
+
}
|
|
13812
|
+
return fragment - last.fragment - geometry2.gopFrames * (mpu - last.mpu) | 0;
|
|
13813
|
+
}
|
|
13814
|
+
#clearMpuLayout() {
|
|
13815
|
+
this.#mpus.clear();
|
|
13816
|
+
this.#fragmentPerFrame = false;
|
|
13817
|
+
this.#multiSampleFragment = false;
|
|
13818
|
+
this.#lastAnchor = null;
|
|
13819
|
+
this.#fragmentsProven = false;
|
|
13820
|
+
}
|
|
13561
13821
|
#clearContiguityLedger() {
|
|
13562
13822
|
this.#mpuSbnSpans.clear();
|
|
13563
13823
|
this.#dataUnitStarts.clear();
|
|
@@ -13657,9 +13917,9 @@ var BlockClassifier = class {
|
|
|
13657
13917
|
if (this.#mode === "all-protected") return "unknown";
|
|
13658
13918
|
const geometry2 = this.#geometry;
|
|
13659
13919
|
if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return "unknown";
|
|
13660
|
-
if (block.mpus.size === 1 && block.
|
|
13920
|
+
if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
|
|
13661
13921
|
const span = geometry2.interleaveUnits - 1;
|
|
13662
|
-
if (block.
|
|
13922
|
+
if (block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1) {
|
|
13663
13923
|
return "delta";
|
|
13664
13924
|
}
|
|
13665
13925
|
}
|
|
@@ -13836,6 +14096,7 @@ var WORKER_ERROR_LOG_CAP = 5;
|
|
|
13836
14096
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13837
14097
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
13838
14098
|
var STARTUP_REPAIR_WAIT_SOURCE_BOUNDARIES = 2;
|
|
14099
|
+
var NOT_TAKEN = Object.freeze({ taken: false, recovered: null });
|
|
13839
14100
|
function isMulticastSymbolDelivery(value) {
|
|
13840
14101
|
return value === "datagram" || value === "ordered-relay";
|
|
13841
14102
|
}
|
|
@@ -13929,10 +14190,18 @@ var FECManager = class _FECManager {
|
|
|
13929
14190
|
// 'pending' forever, which would park every later frame of its stream in
|
|
13930
14191
|
// the in-order release gate. Each entry owns its handle; the callback
|
|
13931
14192
|
// checks it still owns the key, so a settled or reset key is never touched.
|
|
14193
|
+
/**
|
|
14194
|
+
* Per owed Worker cleanup: the bound on its acknowledgement, when its block
|
|
14195
|
+
* was due, and when its cleanup was asked for (see `onCleanupComplete`).
|
|
14196
|
+
*/
|
|
13932
14197
|
this.#pendingWorkerCleanupBounds = /* @__PURE__ */ new Map();
|
|
13933
14198
|
// Source symbol count per track-scoped block — marks complete when K symbols arrive.
|
|
13934
14199
|
this.#blockSourceCounts = /* @__PURE__ */ new Map();
|
|
13935
14200
|
this.#blockSourceEsis = /* @__PURE__ */ new Map();
|
|
14201
|
+
// Source ESIs per block that another FEC instance rebuilt and fed in
|
|
14202
|
+
// (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
|
|
14203
|
+
// not network arrivals and never make a block clean.
|
|
14204
|
+
this.#blockRebuiltEsis = /* @__PURE__ */ new Map();
|
|
13936
14205
|
// Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
|
|
13937
14206
|
// first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
|
|
13938
14207
|
// media units, usually before it holds K symbols; under iso-ssbg1-v1
|
|
@@ -13941,10 +14210,14 @@ var FECManager = class _FECManager {
|
|
|
13941
14210
|
// SSB_length source arrivals and recoverable from SSB_length received
|
|
13942
14211
|
// symbols; waiting for K fails every one of them.
|
|
13943
14212
|
this.#blockAuthoredLengths = /* @__PURE__ */ new Map();
|
|
14213
|
+
// Keys whose authored length is a repair-less span's (#openIsoSpan), until
|
|
14214
|
+
// a repair states the block there or the span resolves.
|
|
14215
|
+
this.#isoSpanKeys = /* @__PURE__ */ new Set();
|
|
13944
14216
|
this.#ssbLengthConflictCount = 0;
|
|
13945
14217
|
this.#blockRepairRsIds = /* @__PURE__ */ new Map();
|
|
13946
14218
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
13947
|
-
// symbols its repair group carries
|
|
14219
|
+
// symbols its repair group carries; 0 for a repair-less span no repair can
|
|
14220
|
+
// state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
|
|
13948
14221
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
13949
14222
|
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
13950
14223
|
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
@@ -14132,13 +14405,17 @@ var FECManager = class _FECManager {
|
|
|
14132
14405
|
this.#workerErrorCounts = /* @__PURE__ */ new Map();
|
|
14133
14406
|
this.#decoderUnavailableEvents = 0;
|
|
14134
14407
|
this.#repairSymbolSizeMismatchCount = 0;
|
|
14408
|
+
this.#unlistedRepairTrackRefusals = 0;
|
|
14135
14409
|
// Event callbacks — block lifecycle notifications for MmtpRouter wiring.
|
|
14136
14410
|
// NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
|
|
14137
14411
|
// feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
|
|
14138
14412
|
// arrives via onBlockRecovered callback.
|
|
14139
14413
|
this.onBlockStarted = null;
|
|
14140
14414
|
this.onBlockComplete = null;
|
|
14141
|
-
/**
|
|
14415
|
+
/**
|
|
14416
|
+
* A block reached its fail bound. `blockClass` is its class at failure.
|
|
14417
|
+
* `span` is set when what failed is a repair-less span starting at `sbn`.
|
|
14418
|
+
*/
|
|
14142
14419
|
this.onBlockFailed = null;
|
|
14143
14420
|
/**
|
|
14144
14421
|
* Fired once per stream when its Worker decoder stops being routable.
|
|
@@ -14180,12 +14457,24 @@ var FECManager = class _FECManager {
|
|
|
14180
14457
|
* for it, which it must be.
|
|
14181
14458
|
*/
|
|
14182
14459
|
this.#onUndelimitedLoss = null;
|
|
14460
|
+
/** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
|
|
14461
|
+
this.#onIsoHoleExpired = null;
|
|
14183
14462
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
14184
14463
|
this.onBlockVanished = null;
|
|
14185
14464
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
14186
14465
|
this.onBlockResolved = null;
|
|
14187
14466
|
/** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
|
|
14188
14467
|
this.onSourceDiscontinuity = null;
|
|
14468
|
+
/**
|
|
14469
|
+
* The span and tolerance the catalog states for a keyframe overlay
|
|
14470
|
+
* installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
|
|
14471
|
+
* overlay instance's own interleaveDepthMs and reorderToleranceMs), or
|
|
14472
|
+
* undefined while none is installed. A stated block only a late source
|
|
14473
|
+
* can complete, and a frame whose gap may hide a RAP behind a span only a
|
|
14474
|
+
* late source can fill, also wait for that overlay's repair
|
|
14475
|
+
* (#overlayLateWaitMs).
|
|
14476
|
+
*/
|
|
14477
|
+
this.keyframeOverlayTiming = null;
|
|
14189
14478
|
// Worker-path callbacks — async recovery and stats from FecWorkerClient.
|
|
14190
14479
|
/**
|
|
14191
14480
|
* A recovered source symbol. Return false when admission refused the
|
|
@@ -14222,7 +14511,9 @@ var FECManager = class _FECManager {
|
|
|
14222
14511
|
#pendingWorkerCleanupBounds;
|
|
14223
14512
|
#blockSourceCounts;
|
|
14224
14513
|
#blockSourceEsis;
|
|
14514
|
+
#blockRebuiltEsis;
|
|
14225
14515
|
#blockAuthoredLengths;
|
|
14516
|
+
#isoSpanKeys;
|
|
14226
14517
|
#ssbLengthConflictCount;
|
|
14227
14518
|
#blockRepairRsIds;
|
|
14228
14519
|
#blockRsbLengths;
|
|
@@ -14288,7 +14579,9 @@ var FECManager = class _FECManager {
|
|
|
14288
14579
|
#workerErrorCounts;
|
|
14289
14580
|
#decoderUnavailableEvents;
|
|
14290
14581
|
#repairSymbolSizeMismatchCount;
|
|
14582
|
+
#unlistedRepairTrackRefusals;
|
|
14291
14583
|
#onUndelimitedLoss;
|
|
14584
|
+
#onIsoHoleExpired;
|
|
14292
14585
|
#encodeTrackName(catalogTrackName) {
|
|
14293
14586
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
14294
14587
|
if (encoded === void 0) {
|
|
@@ -14760,7 +15053,10 @@ var FECManager = class _FECManager {
|
|
|
14760
15053
|
timer.handle = null;
|
|
14761
15054
|
this.#requestRepair(sbn, packetId, catalogTrackName);
|
|
14762
15055
|
};
|
|
14763
|
-
timer.handle = setTimeout(
|
|
15056
|
+
timer.handle = setTimeout(
|
|
15057
|
+
onFire,
|
|
15058
|
+
this.#receiptAtMs === void 0 ? Math.max(0, deadlineMs - performance.now()) : this.#receiptTimerDelayMs(deadlineMs, 0)
|
|
15059
|
+
);
|
|
14764
15060
|
this.#repairDeadlines.set(key, timer);
|
|
14765
15061
|
}
|
|
14766
15062
|
#requestRepair(sbn, packetId, catalogTrackName, settledByOrder = false) {
|
|
@@ -14904,8 +15200,14 @@ var FECManager = class _FECManager {
|
|
|
14904
15200
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
14905
15201
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
14906
15202
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
15203
|
+
*
|
|
15204
|
+
* A `held` source arrived before its block was known and is fed only now
|
|
15205
|
+
* that a repair, a span or a closed hole placed it: how far its block start
|
|
15206
|
+
* then lies behind the frontier measures how long the receiver held it, not
|
|
15207
|
+
* where the stream was, so only its SS_ID and packet_sequence_number judge
|
|
15208
|
+
* it (BLO-52085).
|
|
14907
15209
|
*/
|
|
14908
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
15210
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn, held = false) {
|
|
14909
15211
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
14910
15212
|
const now = performance.now();
|
|
14911
15213
|
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
@@ -14944,7 +15246,7 @@ var FECManager = class _FECManager {
|
|
|
14944
15246
|
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
14945
15247
|
};
|
|
14946
15248
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
14947
|
-
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))) {
|
|
15249
|
+
if (symbol === "source" && window2 !== null && this.#blockPrecedes(sbn, previous.sbn) && (!held && 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))) {
|
|
14948
15250
|
discontinuity();
|
|
14949
15251
|
return;
|
|
14950
15252
|
}
|
|
@@ -15206,17 +15508,21 @@ var FECManager = class _FECManager {
|
|
|
15206
15508
|
this.#blockWaitDeadlinesMs.delete(key);
|
|
15207
15509
|
this.#repairHoldUntilMs.delete(key);
|
|
15208
15510
|
this.#traceLifecycle("timeout-queued", sbn, packetId, catalogTrackName);
|
|
15209
|
-
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName);
|
|
15511
|
+
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs);
|
|
15210
15512
|
};
|
|
15211
|
-
timer.handle = setTimeout(
|
|
15513
|
+
timer.handle = setTimeout(
|
|
15514
|
+
onFire,
|
|
15515
|
+
this.#receiptAtMs === void 0 ? Math.max(1, Math.ceil(deadlineMs - nowMs)) : this.#receiptTimerDelayMs(deadlineMs, 1)
|
|
15516
|
+
);
|
|
15212
15517
|
this.#activeBlocks.set(key, timer);
|
|
15213
15518
|
this.#indexBlockKey(key, sbn, packetId);
|
|
15214
15519
|
}
|
|
15215
15520
|
/**
|
|
15216
15521
|
* Hand a block whose delivery is over to its decoder for finalization: the
|
|
15217
|
-
* datagram deadline fired, or the ordered relay moved past it.
|
|
15522
|
+
* datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
|
|
15523
|
+
* is when it was due: its deadline, or now.
|
|
15218
15524
|
*/
|
|
15219
|
-
#finalizeExpiredBlock(sbn, packetId, catalogTrackName) {
|
|
15525
|
+
#finalizeExpiredBlock(sbn, packetId, catalogTrackName, dueAtMs = performance.now()) {
|
|
15220
15526
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
15221
15527
|
if (this.#materializedBlocks.has(key) && !this.#blockPathCounts.has(key)) {
|
|
15222
15528
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -15232,7 +15538,7 @@ var FECManager = class _FECManager {
|
|
|
15232
15538
|
if (workerClient) {
|
|
15233
15539
|
this.#pendingWorkerCleanups.add(key);
|
|
15234
15540
|
this.#pendingWorkerCleanupClients.set(key, workerClient);
|
|
15235
|
-
this.#boundOwedCleanup(key, packetId, workerClient);
|
|
15541
|
+
this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs);
|
|
15236
15542
|
workerClient.cleanup(sbn);
|
|
15237
15543
|
} else {
|
|
15238
15544
|
const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client;
|
|
@@ -15442,6 +15748,7 @@ var FECManager = class _FECManager {
|
|
|
15442
15748
|
packetId
|
|
15443
15749
|
})),
|
|
15444
15750
|
repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
|
|
15751
|
+
unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
|
|
15445
15752
|
repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
|
|
15446
15753
|
workerErrors: Object.fromEntries(this.#workerErrorCounts)
|
|
15447
15754
|
};
|
|
@@ -15544,7 +15851,9 @@ var FECManager = class _FECManager {
|
|
|
15544
15851
|
}
|
|
15545
15852
|
resetMap(this.#blockSourceCounts);
|
|
15546
15853
|
resetMap(this.#blockSourceEsis);
|
|
15854
|
+
resetMap(this.#blockRebuiltEsis);
|
|
15547
15855
|
resetMap(this.#blockAuthoredLengths);
|
|
15856
|
+
resetSet(this.#isoSpanKeys);
|
|
15548
15857
|
resetMap(this.#blockRepairRsIds);
|
|
15549
15858
|
resetMap(this.#blockRsbLengths);
|
|
15550
15859
|
resetMap(this.#heldLayerStates);
|
|
@@ -15668,7 +15977,9 @@ var FECManager = class _FECManager {
|
|
|
15668
15977
|
dropMap(this.#pendingWorkerCleanupClients);
|
|
15669
15978
|
dropMap(this.#blockSourceCounts);
|
|
15670
15979
|
dropMap(this.#blockSourceEsis);
|
|
15980
|
+
dropMap(this.#blockRebuiltEsis);
|
|
15671
15981
|
dropMap(this.#blockAuthoredLengths);
|
|
15982
|
+
dropSet(this.#isoSpanKeys);
|
|
15672
15983
|
dropMap(this.#blockRepairRsIds);
|
|
15673
15984
|
dropMap(this.#blockRsbLengths);
|
|
15674
15985
|
dropMap(this.#blockPathCounts);
|
|
@@ -15830,6 +16141,9 @@ var FECManager = class _FECManager {
|
|
|
15830
16141
|
this.#unindexBlockKey(key);
|
|
15831
16142
|
}
|
|
15832
16143
|
}
|
|
16144
|
+
if (isSourceSymbol && source === "multicast") {
|
|
16145
|
+
this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), sbn + esi >>> 0, packetId, catalogTrackName);
|
|
16146
|
+
}
|
|
15833
16147
|
return true;
|
|
15834
16148
|
}
|
|
15835
16149
|
#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName) {
|
|
@@ -15939,8 +16253,10 @@ var FECManager = class _FECManager {
|
|
|
15939
16253
|
}
|
|
15940
16254
|
/**
|
|
15941
16255
|
* An open block's accepted sources, distinct repair RS_IDs, authored K'
|
|
15942
|
-
* (SSB_length) and RSB_length (each undefined until a repair stated it
|
|
15943
|
-
*
|
|
16256
|
+
* (SSB_length) and RSB_length (each undefined until a repair stated it; a
|
|
16257
|
+
* repair-less span states its length, and RSB_length 0 when it is longer
|
|
16258
|
+
* than K, since no repair can reach it). Undefined for a block that is not
|
|
16259
|
+
* open.
|
|
15944
16260
|
*/
|
|
15945
16261
|
blockSymbolCounts(sbn, packetId, catalogTrackName) {
|
|
15946
16262
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -16008,8 +16324,9 @@ var FECManager = class _FECManager {
|
|
|
16008
16324
|
return true;
|
|
16009
16325
|
}
|
|
16010
16326
|
/**
|
|
16011
|
-
* Drop a block's repair hold: its FETCH ended without delivering
|
|
16012
|
-
*
|
|
16327
|
+
* Drop a block's repair hold: its FETCH ended without delivering, or brought
|
|
16328
|
+
* back only a repair that cannot complete it. The block falls back to its
|
|
16329
|
+
* multicast wait, which may already have passed.
|
|
16013
16330
|
*/
|
|
16014
16331
|
releaseRepairHold(sbn, packetId, catalogTrackName) {
|
|
16015
16332
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -16055,7 +16372,7 @@ var FECManager = class _FECManager {
|
|
|
16055
16372
|
}
|
|
16056
16373
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
16057
16374
|
if (trackConfig === void 0) return void 0;
|
|
16058
|
-
return Math.max(1, trackConfig
|
|
16375
|
+
return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
|
|
16059
16376
|
}
|
|
16060
16377
|
/** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
|
|
16061
16378
|
// -----------------------------------------------------------------------
|
|
@@ -16147,6 +16464,8 @@ var FECManager = class _FECManager {
|
|
|
16147
16464
|
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
16148
16465
|
const evictedBefore = locator.heldEvicted;
|
|
16149
16466
|
const held = locator.hold(ssId, source);
|
|
16467
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
16468
|
+
if (held && source.source === "multicast") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
|
|
16150
16469
|
const evicted = locator.heldEvicted - evictedBefore;
|
|
16151
16470
|
if (evicted > 0) {
|
|
16152
16471
|
const before = this.#isoHeldEvictedCount;
|
|
@@ -16167,17 +16486,20 @@ var FECManager = class _FECManager {
|
|
|
16167
16486
|
* contradicts a known block is refused (counted) and must be dropped.
|
|
16168
16487
|
*/
|
|
16169
16488
|
placeIsoRepair(packetId, catalogTrackName, ssStart, ssbLength) {
|
|
16170
|
-
const
|
|
16489
|
+
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
16490
|
+
const placement = locator.placeRepair(ssStart, ssbLength);
|
|
16491
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
16171
16492
|
if (placement.status !== "placed") {
|
|
16172
16493
|
this.#isoRepairRefusedCount++;
|
|
16173
16494
|
if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
|
|
16174
16495
|
console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`);
|
|
16175
16496
|
}
|
|
16497
|
+
if (placement.ofSpan !== void 0) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName);
|
|
16176
16498
|
return placement;
|
|
16177
16499
|
}
|
|
16500
|
+
this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName));
|
|
16178
16501
|
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
16179
16502
|
if (placement.hole !== void 0) {
|
|
16180
|
-
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
16181
16503
|
const hole = placement.hole.block;
|
|
16182
16504
|
const previous = locator.blockEndingAt(hole.start);
|
|
16183
16505
|
const loss = {
|
|
@@ -16198,17 +16520,29 @@ var FECManager = class _FECManager {
|
|
|
16198
16520
|
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
16199
16521
|
* range repair scheduler; applies to every stream from its next gap. The
|
|
16200
16522
|
* handler and the deferral are one setting, so no hole is ever created with
|
|
16201
|
-
* nobody to close it.
|
|
16523
|
+
* nobody to close it. `onExpired` is told of each pending hole the stream
|
|
16524
|
+
* runs past the locator's horizon (BLO-52085): returning true, it closes
|
|
16525
|
+
* the hole (`closeIsoHoles`), so the span it leaves still fails and is
|
|
16526
|
+
* reported; otherwise the hole is discarded with its sources.
|
|
16202
16527
|
*/
|
|
16203
|
-
setUndelimitedLossHandler(handler) {
|
|
16528
|
+
setUndelimitedLossHandler(handler, onExpired = null) {
|
|
16204
16529
|
this.#onUndelimitedLoss = handler;
|
|
16530
|
+
this.#onIsoHoleExpired = handler === null ? null : onExpired;
|
|
16205
16531
|
this.#deferIsoGaps = handler !== null;
|
|
16206
16532
|
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
16207
16533
|
}
|
|
16534
|
+
/** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
|
|
16535
|
+
#settleExpiredIsoHoles(locator, packetId, catalogTrackName) {
|
|
16536
|
+
for (const hole of locator.takeExpiredHoles()) {
|
|
16537
|
+
const expired = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length };
|
|
16538
|
+
if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length);
|
|
16539
|
+
}
|
|
16540
|
+
}
|
|
16208
16541
|
/**
|
|
16209
|
-
* The range repair for a hole ended: every hole
|
|
16210
|
-
*
|
|
16211
|
-
* with the held sources they placed, for the caller to feed
|
|
16542
|
+
* The range repair for a hole ended: every hole inside `[start, start +
|
|
16543
|
+
* length)`, pending or expired, becomes a repair-less span. Returns those
|
|
16544
|
+
* spans with the held sources they placed, for the caller to feed
|
|
16545
|
+
* (MmtpRouter).
|
|
16212
16546
|
*/
|
|
16213
16547
|
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
16214
16548
|
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -16224,10 +16558,25 @@ var FECManager = class _FECManager {
|
|
|
16224
16558
|
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
16225
16559
|
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
16226
16560
|
* block.
|
|
16561
|
+
*
|
|
16562
|
+
* A span longer than K holds more than one block (SSB_length <= K), and the
|
|
16563
|
+
* locator states no block inside a span, only one exactly its range
|
|
16564
|
+
* (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
|
|
16565
|
+
* reach it. Its repair group is empty, so the repair scheduler FETCHes no
|
|
16566
|
+
* Group of it (group-cannot-complete). Every span still keeps its whole
|
|
16567
|
+
* wait (#lateSourceWaitMs): failing it early released the frames behind it
|
|
16568
|
+
* past a keyframe the overlay was still rebuilding (BLO-52085). The release
|
|
16569
|
+
* gate lets those frames go once only a late source can fill the gap
|
|
16570
|
+
* before them, as long after they arrived as the gap's decision allows
|
|
16571
|
+
* (isoRepairlessWaitMs).
|
|
16227
16572
|
*/
|
|
16228
16573
|
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
16229
16574
|
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
16230
|
-
if (!this.#blockAuthoredLengths.has(key))
|
|
16575
|
+
if (!this.#blockAuthoredLengths.has(key)) {
|
|
16576
|
+
this.#blockAuthoredLengths.set(key, span.block.length);
|
|
16577
|
+
this.#isoSpanKeys.add(key);
|
|
16578
|
+
if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
|
|
16579
|
+
}
|
|
16231
16580
|
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
16232
16581
|
}
|
|
16233
16582
|
/**
|
|
@@ -16265,6 +16614,62 @@ var FECManager = class _FECManager {
|
|
|
16265
16614
|
}
|
|
16266
16615
|
return lost;
|
|
16267
16616
|
}
|
|
16617
|
+
/**
|
|
16618
|
+
* The release gate's wait, from a frame's arrival, for the SS_IDs strictly
|
|
16619
|
+
* between two released frames' SS_IDs once only a late source can still
|
|
16620
|
+
* fill them, else undefined. That is when every one missing (neither
|
|
16621
|
+
* arrived nor held) lies in a repair-less span longer than K, which no
|
|
16622
|
+
* repair can state a block of (#openIsoSpan), or in a stated block its
|
|
16623
|
+
* own repair group cannot complete every SS_ID of which it misses lies
|
|
16624
|
+
* between them (so the gap's decision covers all it lost), and a multicast
|
|
16625
|
+
* source at or past `toSsId` arrived, so each is lost or reordered behind
|
|
16626
|
+
* it (a MoQ source shows nothing: MoQ streams overtake one another). The
|
|
16627
|
+
* span or block itself keeps its own wait.
|
|
16628
|
+
*
|
|
16629
|
+
* The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
|
|
16630
|
+
* hold a RAP packet an installed keyframe overlay can still rebuild (its
|
|
16631
|
+
* decision stalls, or it ends at a RAP that may lie past a whole MPU).
|
|
16632
|
+
* Then the frame waits as a stated block its group cannot complete does
|
|
16633
|
+
* (#overlayLateWaitMs): the allowance alone with no overlay installed, the
|
|
16634
|
+
* overlay's span plus the larger of the allowance and its tolerance, or,
|
|
16635
|
+
* for an overlay that states no span, the span's whole wait (undefined).
|
|
16636
|
+
* So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
|
|
16637
|
+
* the gap holds a stated block's loss.
|
|
16638
|
+
*/
|
|
16639
|
+
isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false) {
|
|
16640
|
+
const config = this.#trackConfigs.get(packetId);
|
|
16641
|
+
if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
|
|
16642
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
16643
|
+
if (locator === void 0 || !locator.coversBetween(fromSsId, toSsId)) return void 0;
|
|
16644
|
+
const newestSource = locator.newestSource;
|
|
16645
|
+
if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
|
|
16646
|
+
let repairless = false;
|
|
16647
|
+
let stated = false;
|
|
16648
|
+
for (const block of locator.blocksBetween(fromSsId, toSsId)) {
|
|
16649
|
+
const key = this.#blockKey(block.start, packetId, catalogTrackName);
|
|
16650
|
+
if (this.#completedBlocks.has(key)) continue;
|
|
16651
|
+
if (block.span && block.length > locator.kMax) {
|
|
16652
|
+
repairless = true;
|
|
16653
|
+
continue;
|
|
16654
|
+
}
|
|
16655
|
+
const received = this.#blockSourceEsis.get(key);
|
|
16656
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
16657
|
+
let missesInGap = false;
|
|
16658
|
+
let missesOutside = false;
|
|
16659
|
+
for (let esi = 0; esi < block.length; esi++) {
|
|
16660
|
+
const ssId = serial32Add(block.start, esi);
|
|
16661
|
+
if (received?.has(esi) || locator.isHeld(ssId)) continue;
|
|
16662
|
+
if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
|
|
16663
|
+
else if (!rebuilt?.has(esi)) missesOutside = true;
|
|
16664
|
+
}
|
|
16665
|
+
if (!missesInGap) continue;
|
|
16666
|
+
if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
|
|
16667
|
+
repairless = stated = true;
|
|
16668
|
+
}
|
|
16669
|
+
if (!repairless) return void 0;
|
|
16670
|
+
const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
|
|
16671
|
+
return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
|
|
16672
|
+
}
|
|
16268
16673
|
/**
|
|
16269
16674
|
* iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
|
|
16270
16675
|
* the sources held now for a block no repair has stated yet, and the held
|
|
@@ -16568,11 +16973,14 @@ var FECManager = class _FECManager {
|
|
|
16568
16973
|
});
|
|
16569
16974
|
client.onCleanupComplete((sbn) => {
|
|
16570
16975
|
if (this.#releasedWorkerClients.has(client)) return;
|
|
16571
|
-
const
|
|
16976
|
+
const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client);
|
|
16977
|
+
const cleanupKeys = owed.filter((key) => {
|
|
16572
16978
|
const block = this.#parseBlockKey(key);
|
|
16573
|
-
return block.packetId === packetId && block.sbn === sbn
|
|
16979
|
+
return block.packetId === packetId && block.sbn === sbn;
|
|
16574
16980
|
});
|
|
16575
|
-
|
|
16981
|
+
const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity));
|
|
16982
|
+
const due = owed.filter((key) => !cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs);
|
|
16983
|
+
for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, "cleanup-ack");
|
|
16576
16984
|
});
|
|
16577
16985
|
client.onError((msg, code) => {
|
|
16578
16986
|
const requestedKind = code ?? msg;
|
|
@@ -16642,9 +17050,11 @@ var FECManager = class _FECManager {
|
|
|
16642
17050
|
* fail deadline already passed, so failing it is the decision that deadline
|
|
16643
17051
|
* made. A late ack then finds nothing owed and is a no-op.
|
|
16644
17052
|
*/
|
|
16645
|
-
#boundOwedCleanup(key, packetId, client) {
|
|
17053
|
+
#boundOwedCleanup(key, packetId, client, dueAtMs) {
|
|
16646
17054
|
this.#clearOwedCleanupBound(key);
|
|
16647
17055
|
const bound = {
|
|
17056
|
+
dueAtMs,
|
|
17057
|
+
askedAtMs: performance.now(),
|
|
16648
17058
|
handle: setTimeout(() => {
|
|
16649
17059
|
if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return;
|
|
16650
17060
|
this.#pendingWorkerCleanupBounds.delete(key);
|
|
@@ -16742,7 +17152,15 @@ var FECManager = class _FECManager {
|
|
|
16742
17152
|
this.#isoSourceOversizeCount++;
|
|
16743
17153
|
return null;
|
|
16744
17154
|
}
|
|
16745
|
-
|
|
17155
|
+
return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start);
|
|
17156
|
+
}
|
|
17157
|
+
/**
|
|
17158
|
+
* Hand one placed source symbol to the stream's decoder: its Worker, which
|
|
17159
|
+
* answers through onFrame (null here), or its synchronous decoder, whose
|
|
17160
|
+
* recovered block is returned. `sbn` is the SS_Start of the block a repair
|
|
17161
|
+
* stated for `ssId`.
|
|
17162
|
+
*/
|
|
17163
|
+
#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn) {
|
|
16746
17164
|
const blockKey = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
16747
17165
|
const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey);
|
|
16748
17166
|
const workerClient = this.#routableWorkerForPacket(packetId, catalogTrackName);
|
|
@@ -16771,6 +17189,74 @@ var FECManager = class _FECManager {
|
|
|
16771
17189
|
}
|
|
16772
17190
|
return recovered;
|
|
16773
17191
|
}
|
|
17192
|
+
/**
|
|
17193
|
+
* Feed a source symbol of this stream that another FEC instance over the
|
|
17194
|
+
* same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
|
|
17195
|
+
* caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
|
|
17196
|
+
* BLO-52085). It joins its block's decoder as a received source would, so
|
|
17197
|
+
* it reduces the erasures the block still has to solve, but it is not a
|
|
17198
|
+
* network arrival: no transport accounting, no classification evidence,
|
|
17199
|
+
* no deadline refresh, and it never makes a block clean.
|
|
17200
|
+
*
|
|
17201
|
+
* Only a block a repair stated takes one (a repair-less span has no
|
|
17202
|
+
* decoder block). A block that is terminal, or already holds that source,
|
|
17203
|
+
* does not. The symbol is the exact protected packet, unpadded, as
|
|
17204
|
+
* feedSourceSymbol takes it.
|
|
17205
|
+
*
|
|
17206
|
+
* `recovered` is the block the synchronous decoder completed with it; the
|
|
17207
|
+
* caller routes it and completes the block, as for any recovery. When
|
|
17208
|
+
* every source of the block is then present, received or rebuilt, and no
|
|
17209
|
+
* decoder returned it (a Worker answers asynchronously, and reports such a
|
|
17210
|
+
* block as clean on its own side), the block is completed here as
|
|
17211
|
+
* recovered, with nothing left to route.
|
|
17212
|
+
*/
|
|
17213
|
+
feedRebuiltSourceSymbol(packetId, ssId, symbolData, catalogTrackName) {
|
|
17214
|
+
if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN;
|
|
17215
|
+
const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId);
|
|
17216
|
+
if (located === null || located.block.span) return NOT_TAKEN;
|
|
17217
|
+
if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN;
|
|
17218
|
+
const sbn = located.block.start;
|
|
17219
|
+
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
17220
|
+
if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN;
|
|
17221
|
+
let rebuilt = this.#blockRebuiltEsis.get(key);
|
|
17222
|
+
if (rebuilt?.has(located.esi)) return NOT_TAKEN;
|
|
17223
|
+
if (rebuilt === void 0) {
|
|
17224
|
+
rebuilt = /* @__PURE__ */ new Set();
|
|
17225
|
+
this.#blockRebuiltEsis.set(key, rebuilt);
|
|
17226
|
+
}
|
|
17227
|
+
const config = this.#trackConfigs.get(packetId);
|
|
17228
|
+
const wasShort = config !== void 0 && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== void 0;
|
|
17229
|
+
rebuilt.add(located.esi);
|
|
17230
|
+
const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn);
|
|
17231
|
+
if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
|
|
17232
|
+
if (wasShort && this.#activeBlocks.has(key) && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) === void 0) {
|
|
17233
|
+
this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config));
|
|
17234
|
+
}
|
|
17235
|
+
}
|
|
17236
|
+
return { taken: true, recovered };
|
|
17237
|
+
}
|
|
17238
|
+
/**
|
|
17239
|
+
* A block that holds every one of its `length` sources, received or
|
|
17240
|
+
* rebuilt by another instance, with at least one rebuilt, is recovered:
|
|
17241
|
+
* every packet of it was delivered, by its own arrival or by the instance
|
|
17242
|
+
* that rebuilt it, so nothing is routed. Returns whether it completed it.
|
|
17243
|
+
*/
|
|
17244
|
+
#completeWhenSourcesPresent(key, sbn, length, packetId, catalogTrackName) {
|
|
17245
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
17246
|
+
if (rebuilt === void 0 || this.#completedBlocks.has(key)) return false;
|
|
17247
|
+
let present = rebuilt.size;
|
|
17248
|
+
for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++;
|
|
17249
|
+
if (present < length) return false;
|
|
17250
|
+
this.#traceLifecycle("recovered", sbn, packetId, catalogTrackName);
|
|
17251
|
+
this.countRecovery(packetId, sbn, catalogTrackName);
|
|
17252
|
+
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
17253
|
+
if (catalogTrackName === void 0) {
|
|
17254
|
+
this.onBlockComplete?.(sbn, packetId);
|
|
17255
|
+
} else {
|
|
17256
|
+
this.onBlockComplete?.(sbn, packetId, catalogTrackName);
|
|
17257
|
+
}
|
|
17258
|
+
return true;
|
|
17259
|
+
}
|
|
16774
17260
|
/**
|
|
16775
17261
|
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16776
17262
|
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
@@ -16832,7 +17318,10 @@ var FECManager = class _FECManager {
|
|
|
16832
17318
|
this.#layerAnchorHorizon(packetId),
|
|
16833
17319
|
this.#sourceFrontiers.get(streamKey)?.sbn
|
|
16834
17320
|
);
|
|
16835
|
-
if (verdict === "discard")
|
|
17321
|
+
if (verdict === "discard") {
|
|
17322
|
+
this.#unlistedRepairTrackRefusals++;
|
|
17323
|
+
return false;
|
|
17324
|
+
}
|
|
16836
17325
|
if (verdict !== void 0) {
|
|
16837
17326
|
this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
|
|
16838
17327
|
return false;
|
|
@@ -16973,8 +17462,115 @@ var FECManager = class _FECManager {
|
|
|
16973
17462
|
this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName);
|
|
16974
17463
|
return null;
|
|
16975
17464
|
}
|
|
17465
|
+
if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName);
|
|
16976
17466
|
return recovered;
|
|
16977
17467
|
}
|
|
17468
|
+
/**
|
|
17469
|
+
* A first-arrival multicast source, held or placed. A datagram flow keeps
|
|
17470
|
+
* its sources in send order, so one that moves the stream's newest source
|
|
17471
|
+
* position past a block leaves the sources that block still misses
|
|
17472
|
+
* reordered behind it at best: it shortens the wait of every block it
|
|
17473
|
+
* passed that only a late source can complete. MoQ is left out: its streams
|
|
17474
|
+
* can overtake one another, so a MoQ source shows nothing about the sources
|
|
17475
|
+
* sent before it.
|
|
17476
|
+
*/
|
|
17477
|
+
#noteMulticastSource(locator, ssId, packetId, catalogTrackName) {
|
|
17478
|
+
const previous = locator.newestSource;
|
|
17479
|
+
if (!locator.noteSource(ssId) || previous === void 0) return;
|
|
17480
|
+
for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
|
|
17481
|
+
if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
|
|
17482
|
+
this.#shortenUnrecoverableWait(
|
|
17483
|
+
this.#blockKey(block.start, packetId, catalogTrackName),
|
|
17484
|
+
block.start,
|
|
17485
|
+
packetId,
|
|
17486
|
+
catalogTrackName
|
|
17487
|
+
);
|
|
17488
|
+
}
|
|
17489
|
+
}
|
|
17490
|
+
/**
|
|
17491
|
+
* The wait of a block that only a late source can complete (BLO-52085): a
|
|
17492
|
+
* repair stated it, its received sources plus every symbol its repair group
|
|
17493
|
+
* carries (RSB_length) are short of K' (the repair scheduler's
|
|
17494
|
+
* group-cannot-complete), and a later source of the stream has arrived, so
|
|
17495
|
+
* a source it misses is lost or reordered behind that one. The span, which
|
|
17496
|
+
* covers repair symbols paced after its sources, buys it nothing: it waits
|
|
17497
|
+
* the late-symbol allowance alone, the multicast wait less the span (the
|
|
17498
|
+
* catalog tolerance or the measured delivery gap). Undefined for any other
|
|
17499
|
+
* block. While a keyframe overlay is installed, the block waits for its
|
|
17500
|
+
* repair too (#overlayLateWaitMs). A repair-less span keeps its whole
|
|
17501
|
+
* wait, even one longer than K whose group is empty (#openIsoSpan): its
|
|
17502
|
+
* resolution is what releases the frames behind it, and failing it early
|
|
17503
|
+
* released them past a keyframe the overlay was still rebuilding, which
|
|
17504
|
+
* then arrived stale. The release gate lets them go instead
|
|
17505
|
+
* (isoRepairlessWaitMs).
|
|
17506
|
+
*/
|
|
17507
|
+
#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
|
|
17508
|
+
if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
|
|
17509
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
17510
|
+
const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
|
|
17511
|
+
if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
|
|
17512
|
+
return void 0;
|
|
17513
|
+
}
|
|
17514
|
+
return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
|
|
17515
|
+
}
|
|
17516
|
+
/**
|
|
17517
|
+
* A repair stated the block, and its sources plus every symbol its repair
|
|
17518
|
+
* group carries (RSB_length) are short of its SSB_length.
|
|
17519
|
+
*/
|
|
17520
|
+
#groupCannotComplete(key) {
|
|
17521
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
17522
|
+
const rsbLength = this.#blockRsbLengths.get(key);
|
|
17523
|
+
if (authoredLength === void 0 || rsbLength === void 0) return false;
|
|
17524
|
+
let present = this.#blockSourceCounts.get(key) ?? 0;
|
|
17525
|
+
const received = this.#blockSourceEsis.get(key);
|
|
17526
|
+
for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
|
|
17527
|
+
return present + rsbLength < authoredLength;
|
|
17528
|
+
}
|
|
17529
|
+
/**
|
|
17530
|
+
* How long a loss only a late source or an installed keyframe overlay can
|
|
17531
|
+
* still fill waits once a later source passed it: the late-symbol
|
|
17532
|
+
* allowance alone (the multicast wait less the span) while no overlay is
|
|
17533
|
+
* installed. An installed one (keyframeOverlayTiming) may still rebuild a
|
|
17534
|
+
* RAP packet the loss took: a second FEC instance over the same packets
|
|
17535
|
+
* (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
|
|
17536
|
+
* span, unrelated to the base's. That packet can complete a stated block
|
|
17537
|
+
* (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
|
|
17538
|
+
* first lets the release gate pass the keyframe, whose rebuild then lands
|
|
17539
|
+
* stale. The overlay repair of a packet the loss took goes out within the
|
|
17540
|
+
* overlay's span of that packet (fec-core-00 9.3), and the later source was
|
|
17541
|
+
* sent after it, so the loss waits that span plus the larger of the
|
|
17542
|
+
* allowance and the overlay's own tolerance. An overlay that states no
|
|
17543
|
+
* span (its block may then span keyframes), or one whose wait is not
|
|
17544
|
+
* shorter than the whole multicast wait, leaves the whole wait: undefined.
|
|
17545
|
+
*/
|
|
17546
|
+
#overlayLateWaitMs(packetId, catalogTrackName, config) {
|
|
17547
|
+
const waitMs = this.#multicastWaitMs(config);
|
|
17548
|
+
const allowanceMs = waitMs - config.interleaveDepthMs;
|
|
17549
|
+
const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
|
|
17550
|
+
if (overlay === void 0) return allowanceMs;
|
|
17551
|
+
const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
|
|
17552
|
+
const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
|
|
17553
|
+
return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
|
|
17554
|
+
}
|
|
17555
|
+
/**
|
|
17556
|
+
* Bring an open block's wait in to its late-source wait, when it has one.
|
|
17557
|
+
* Never later than it is armed: only a source can complete such a block,
|
|
17558
|
+
* so a repair of its group (paced across the span) must not keep it open.
|
|
17559
|
+
*/
|
|
17560
|
+
#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName) {
|
|
17561
|
+
if (!this.#activeBlocks.has(key)) return;
|
|
17562
|
+
const config = this.#trackConfigs.get(packetId);
|
|
17563
|
+
if (config === void 0) return;
|
|
17564
|
+
const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config);
|
|
17565
|
+
if (waitMs === void 0) return;
|
|
17566
|
+
const armedAtMs = this.#blockWaitDeadlinesMs.get(key);
|
|
17567
|
+
this.#armBlockTimeout(
|
|
17568
|
+
sbn,
|
|
17569
|
+
packetId,
|
|
17570
|
+
catalogTrackName,
|
|
17571
|
+
armedAtMs === void 0 ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow())
|
|
17572
|
+
);
|
|
17573
|
+
}
|
|
16978
17574
|
/**
|
|
16979
17575
|
* Record a block's authored SSB_length from a repair symbol. Returns false,
|
|
16980
17576
|
* leaving the block unchanged, when the symbol contradicts the block: a
|
|
@@ -17072,12 +17668,13 @@ var FECManager = class _FECManager {
|
|
|
17072
17668
|
* the inactivity deadline on each symbol, records the symbol's in-band
|
|
17073
17669
|
* classification evidence, and marks the block clean when all of its
|
|
17074
17670
|
* authored source symbols arrived: the SSB_length a repair symbol declared,
|
|
17075
|
-
* otherwise K.
|
|
17671
|
+
* otherwise K. `held` marks a source held unplaced since it arrived and
|
|
17672
|
+
* placed only now (see #noteSbnSeen).
|
|
17076
17673
|
*
|
|
17077
17674
|
* Throws for a packetId that was never configured, so a classified block
|
|
17078
17675
|
* never reads the manager-global K or timeout.
|
|
17079
17676
|
*/
|
|
17080
|
-
trackBlock(sbn, packetId, catalogTrackName, esi, evidence) {
|
|
17677
|
+
trackBlock(sbn, packetId, catalogTrackName, esi, evidence, held = false) {
|
|
17081
17678
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
17082
17679
|
if (trackConfig === void 0) {
|
|
17083
17680
|
throw new Error(
|
|
@@ -17093,7 +17690,8 @@ var FECManager = class _FECManager {
|
|
|
17093
17690
|
catalogTrackName,
|
|
17094
17691
|
"source",
|
|
17095
17692
|
evidence.packetSequenceNumber,
|
|
17096
|
-
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
17693
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn,
|
|
17694
|
+
held
|
|
17097
17695
|
);
|
|
17098
17696
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
17099
17697
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
@@ -17129,6 +17727,15 @@ var FECManager = class _FECManager {
|
|
|
17129
17727
|
this.#completeCleanBlock(key, sbn, packetId, catalogTrackName);
|
|
17130
17728
|
return;
|
|
17131
17729
|
}
|
|
17730
|
+
if (this.#blockRebuiltEsis.has(key) && this.#completeWhenSourcesPresent(
|
|
17731
|
+
key,
|
|
17732
|
+
sbn,
|
|
17733
|
+
this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
|
|
17734
|
+
packetId,
|
|
17735
|
+
catalogTrackName
|
|
17736
|
+
)) {
|
|
17737
|
+
return;
|
|
17738
|
+
}
|
|
17132
17739
|
this.noteBlockActivity(sbn, packetId, catalogTrackName, true);
|
|
17133
17740
|
}
|
|
17134
17741
|
#completeCleanBlock(key, sbn, packetId, catalogTrackName) {
|
|
@@ -17137,7 +17744,9 @@ var FECManager = class _FECManager {
|
|
|
17137
17744
|
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
17138
17745
|
this.#blockSourceCounts.delete(key);
|
|
17139
17746
|
this.#blockSourceEsis.delete(key);
|
|
17747
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17140
17748
|
this.#blockAuthoredLengths.delete(key);
|
|
17749
|
+
this.#isoSpanKeys.delete(key);
|
|
17141
17750
|
this.#blockRepairRsIds.delete(key);
|
|
17142
17751
|
this.#blockRsbLengths.delete(key);
|
|
17143
17752
|
this.#markTerminal(key, sbn, packetId, true);
|
|
@@ -17168,6 +17777,19 @@ var FECManager = class _FECManager {
|
|
|
17168
17777
|
#receiptNow() {
|
|
17169
17778
|
return this.#receiptAtMs ?? performance.now();
|
|
17170
17779
|
}
|
|
17780
|
+
/**
|
|
17781
|
+
* The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
|
|
17782
|
+
* scope: counted from the receipt time, as the timer of a symbol fed when
|
|
17783
|
+
* it was received was, less the whole ms since. So it fires on the tick
|
|
17784
|
+
* that timer would have, never later than a delay counted from now, and
|
|
17785
|
+
* its handler still re-arms a timer that fires before its deadline.
|
|
17786
|
+
* Counted from now, a deadline set from the receipt time is rounded up
|
|
17787
|
+
* from another fraction of a ms (BLO-52085).
|
|
17788
|
+
*/
|
|
17789
|
+
#receiptTimerDelayMs(deadlineMs, minMs) {
|
|
17790
|
+
const receivedAtMs = this.#receiptAtMs;
|
|
17791
|
+
return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs));
|
|
17792
|
+
}
|
|
17171
17793
|
/**
|
|
17172
17794
|
* A held packet admitted late arms from its (earlier) receipt time; that
|
|
17173
17795
|
* never pulls in a deadline later activity already armed. Outside a
|
|
@@ -17203,10 +17825,20 @@ var FECManager = class _FECManager {
|
|
|
17203
17825
|
this.#repairDeadlineMs(trackConfig)
|
|
17204
17826
|
);
|
|
17205
17827
|
}
|
|
17206
|
-
this.#
|
|
17828
|
+
if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== void 0) {
|
|
17829
|
+
this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName);
|
|
17830
|
+
return;
|
|
17831
|
+
}
|
|
17832
|
+
this.#armBlockTimeout(
|
|
17833
|
+
sbn,
|
|
17834
|
+
packetId,
|
|
17835
|
+
catalogTrackName,
|
|
17836
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs
|
|
17837
|
+
);
|
|
17207
17838
|
}
|
|
17208
17839
|
#failBlock(sbn, packetId, catalogTrackName) {
|
|
17209
17840
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
17841
|
+
const span = this.#isoSpanKeys.delete(key) ? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 } : void 0;
|
|
17210
17842
|
this.#traceLifecycle("failed", sbn, packetId, catalogTrackName);
|
|
17211
17843
|
this.#clearRepairDeadline(key);
|
|
17212
17844
|
this.#clearBlockTimer(key);
|
|
@@ -17216,6 +17848,7 @@ var FECManager = class _FECManager {
|
|
|
17216
17848
|
}
|
|
17217
17849
|
this.#blockSourceCounts.delete(key);
|
|
17218
17850
|
this.#blockSourceEsis.delete(key);
|
|
17851
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17219
17852
|
this.#blockAuthoredLengths.delete(key);
|
|
17220
17853
|
this.#blockRepairRsIds.delete(key);
|
|
17221
17854
|
this.#blockRsbLengths.delete(key);
|
|
@@ -17225,7 +17858,8 @@ var FECManager = class _FECManager {
|
|
|
17225
17858
|
this.#markPathBlockComplete(sbn, packetId, catalogTrackName);
|
|
17226
17859
|
this.#fecStats.blocksFailed++;
|
|
17227
17860
|
this.#statsForPacket(packetId).blocksFailed++;
|
|
17228
|
-
this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
17861
|
+
if (span === void 0) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
17862
|
+
else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
17229
17863
|
this.onBlockResolved?.(sbn, packetId, catalogTrackName);
|
|
17230
17864
|
}
|
|
17231
17865
|
/**
|
|
@@ -17254,7 +17888,9 @@ var FECManager = class _FECManager {
|
|
|
17254
17888
|
this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName);
|
|
17255
17889
|
this.#blockSourceCounts.delete(key);
|
|
17256
17890
|
this.#blockSourceEsis.delete(key);
|
|
17891
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17257
17892
|
this.#blockAuthoredLengths.delete(key);
|
|
17893
|
+
this.#isoSpanKeys.delete(key);
|
|
17258
17894
|
this.#blockRepairRsIds.delete(key);
|
|
17259
17895
|
this.#blockRsbLengths.delete(key);
|
|
17260
17896
|
this.#clearBlockTimer(key);
|
|
@@ -17345,7 +17981,9 @@ var FECManager = class _FECManager {
|
|
|
17345
17981
|
this.#blockKeysBySbn.clear();
|
|
17346
17982
|
this.#blockSourceCounts.clear();
|
|
17347
17983
|
this.#blockSourceEsis.clear();
|
|
17984
|
+
this.#blockRebuiltEsis.clear();
|
|
17348
17985
|
this.#blockAuthoredLengths.clear();
|
|
17986
|
+
this.#isoSpanKeys.clear();
|
|
17349
17987
|
this.#blockRepairRsIds.clear();
|
|
17350
17988
|
this.#blockRsbLengths.clear();
|
|
17351
17989
|
this.#heldLayerStates.clear();
|
|
@@ -17901,9 +18539,21 @@ var IsoBmffTimingResolver = class {
|
|
|
17901
18539
|
}
|
|
17902
18540
|
#track = null;
|
|
17903
18541
|
#fragments = /* @__PURE__ */ new Map();
|
|
18542
|
+
/** First sample of each pending fragment, kept in `#delivered` with its sample count. */
|
|
18543
|
+
#firstSamples = /* @__PURE__ */ new Map();
|
|
18544
|
+
/**
|
|
18545
|
+
* First sample and sample count of the newest fragments whose every slot was
|
|
18546
|
+
* cleared. Abandonment counts: `releaseSample` clears a slot too, which
|
|
18547
|
+
* matches the combiner, since it retires an abandoned sample as well.
|
|
18548
|
+
*/
|
|
18549
|
+
#delivered = /* @__PURE__ */ new Map();
|
|
17904
18550
|
#pendingSamples = 0;
|
|
17905
18551
|
#evictedSamples = 0;
|
|
17906
18552
|
#lastMovieFragmentRejection = null;
|
|
18553
|
+
/** True once an FT=0 has bound the track that FT=1 timing is read against. */
|
|
18554
|
+
get initialized() {
|
|
18555
|
+
return this.#track !== null;
|
|
18556
|
+
}
|
|
17907
18557
|
get pendingSampleCount() {
|
|
17908
18558
|
return this.#pendingSamples;
|
|
17909
18559
|
}
|
|
@@ -17927,7 +18577,14 @@ var IsoBmffTimingResolver = class {
|
|
|
17927
18577
|
this.#track = timing;
|
|
17928
18578
|
return true;
|
|
17929
18579
|
}
|
|
17930
|
-
|
|
18580
|
+
/**
|
|
18581
|
+
* `recovered` marks an FEC-recovered copy. A recovered block hands back
|
|
18582
|
+
* every FT=1 it holds, the received ones included, so a recovered copy of a
|
|
18583
|
+
* fragment whose samples are all done is a duplicate: admitting it again
|
|
18584
|
+
* would charge stale timing and could displace the live MPU's. A source
|
|
18585
|
+
* copy is still admitted again (a rendition switch re-arms timing that way).
|
|
18586
|
+
*/
|
|
18587
|
+
addMovieFragment(mpuSequenceNumber2, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
|
|
17931
18588
|
this.#lastMovieFragmentRejection = null;
|
|
17932
18589
|
if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
|
|
17933
18590
|
this.#lastMovieFragmentRejection = "invalid";
|
|
@@ -17953,6 +18610,8 @@ var IsoBmffTimingResolver = class {
|
|
|
17953
18610
|
(sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
|
|
17954
18611
|
);
|
|
17955
18612
|
}
|
|
18613
|
+
const delivered = recovered ? this.#delivered.get(key) : void 0;
|
|
18614
|
+
if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
|
|
17956
18615
|
let freed = 0;
|
|
17957
18616
|
while (this.#fragments.size > 0 && (this.#pendingSamples + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
|
|
17958
18617
|
freed += this.#evictOldestFragment();
|
|
@@ -17966,6 +18625,7 @@ var IsoBmffTimingResolver = class {
|
|
|
17966
18625
|
return false;
|
|
17967
18626
|
}
|
|
17968
18627
|
this.#fragments.set(key, [...parsed.samples]);
|
|
18628
|
+
this.#firstSamples.set(key, parsed.samples[0]);
|
|
17969
18629
|
this.#pendingSamples += parsed.samples.length;
|
|
17970
18630
|
return true;
|
|
17971
18631
|
}
|
|
@@ -18023,6 +18683,7 @@ var IsoBmffTimingResolver = class {
|
|
|
18023
18683
|
let live = 0;
|
|
18024
18684
|
for (const sample of samples) if (sample !== null) live++;
|
|
18025
18685
|
this.#fragments.delete(oldest);
|
|
18686
|
+
this.#firstSamples.delete(oldest);
|
|
18026
18687
|
this.#pendingSamples -= live;
|
|
18027
18688
|
this.#evictedSamples += live;
|
|
18028
18689
|
return live;
|
|
@@ -18038,12 +18699,23 @@ var IsoBmffTimingResolver = class {
|
|
|
18038
18699
|
if (!samples || !samples[index]) return false;
|
|
18039
18700
|
samples[index] = null;
|
|
18040
18701
|
this.#pendingSamples--;
|
|
18041
|
-
if (samples.every((value) => value === null))
|
|
18702
|
+
if (samples.every((value) => value === null)) {
|
|
18703
|
+
this.#fragments.delete(key);
|
|
18704
|
+
const first = this.#firstSamples.get(key);
|
|
18705
|
+
this.#firstSamples.delete(key);
|
|
18706
|
+
this.#delivered.delete(key);
|
|
18707
|
+
this.#delivered.set(key, { first, sampleCount: samples.length });
|
|
18708
|
+
if (this.#delivered.size > this.maxPendingSamples) {
|
|
18709
|
+
this.#delivered.delete(this.#delivered.keys().next().value);
|
|
18710
|
+
}
|
|
18711
|
+
}
|
|
18042
18712
|
return true;
|
|
18043
18713
|
}
|
|
18044
18714
|
reset() {
|
|
18045
18715
|
this.#track = null;
|
|
18046
18716
|
this.#fragments.clear();
|
|
18717
|
+
this.#firstSamples.clear();
|
|
18718
|
+
this.#delivered.clear();
|
|
18047
18719
|
this.#pendingSamples = 0;
|
|
18048
18720
|
}
|
|
18049
18721
|
};
|
|
@@ -18213,6 +18885,9 @@ function authoredGap(before, after) {
|
|
|
18213
18885
|
function ssIdAfter(a, b) {
|
|
18214
18886
|
return (a - b | 0) > 0;
|
|
18215
18887
|
}
|
|
18888
|
+
function holdsRebuilt(stream) {
|
|
18889
|
+
return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
|
|
18890
|
+
}
|
|
18216
18891
|
var FecReleaseSequencer = class {
|
|
18217
18892
|
#streams = /* @__PURE__ */ new Map();
|
|
18218
18893
|
#gate;
|
|
@@ -18275,6 +18950,7 @@ var FecReleaseSequencer = class {
|
|
|
18275
18950
|
stream.lastSbn = void 0;
|
|
18276
18951
|
stream.discontinuity = false;
|
|
18277
18952
|
stream.rapSsId = void 0;
|
|
18953
|
+
stream.sourced = false;
|
|
18278
18954
|
}
|
|
18279
18955
|
if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
|
|
18280
18956
|
this.#recordStat("droppedStale");
|
|
@@ -18301,6 +18977,7 @@ var FecReleaseSequencer = class {
|
|
|
18301
18977
|
if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
|
|
18302
18978
|
else hi = mid;
|
|
18303
18979
|
}
|
|
18980
|
+
if (stream.buf[lo]?.passed === true) frame.passed = true;
|
|
18304
18981
|
stream.buf.splice(lo, 0, frame);
|
|
18305
18982
|
this.#drainUnlessDeferred(stream);
|
|
18306
18983
|
}
|
|
@@ -18336,6 +19013,41 @@ var FecReleaseSequencer = class {
|
|
|
18336
19013
|
}
|
|
18337
19014
|
return false;
|
|
18338
19015
|
}
|
|
19016
|
+
/**
|
|
19017
|
+
* These streams' sink is being replaced by one that has seen no source
|
|
19018
|
+
* frame yet. First, from a stream that holds a frame the overlay rebuilt,
|
|
19019
|
+
* release to the sink being replaced the frames the unanchored path had
|
|
19020
|
+
* already released to it (#cursorPassed): there they waited in its queue,
|
|
19021
|
+
* which its replacement flushes. A stream that holds none is not drained:
|
|
19022
|
+
* it holds nothing the anchor kept back, and a drain would still force out
|
|
19023
|
+
* a frame held past the hold limit, which before the anchor waited for the
|
|
19024
|
+
* next push. Then treat the streams as unsourced until a source frame is
|
|
19025
|
+
* released.
|
|
19026
|
+
*/
|
|
19027
|
+
unsource(packetId, catalogTrackName) {
|
|
19028
|
+
for (const stream of this.#streams.values()) {
|
|
19029
|
+
if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
|
|
19030
|
+
if (stream.draining === 0 && holdsRebuilt(stream)) {
|
|
19031
|
+
if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
|
|
19032
|
+
else this.#drain(stream, true);
|
|
19033
|
+
}
|
|
19034
|
+
stream.sourced = false;
|
|
19035
|
+
}
|
|
19036
|
+
}
|
|
19037
|
+
}
|
|
19038
|
+
/**
|
|
19039
|
+
* Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
|
|
19040
|
+
* (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
|
|
19041
|
+
* packetId.
|
|
19042
|
+
*/
|
|
19043
|
+
holdsRebuilt(packetId, catalogTrackName) {
|
|
19044
|
+
for (const stream of this.#streams.values()) {
|
|
19045
|
+
if (stream.packetId !== packetId) continue;
|
|
19046
|
+
if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
|
|
19047
|
+
if (holdsRebuilt(stream)) return true;
|
|
19048
|
+
}
|
|
19049
|
+
return false;
|
|
19050
|
+
}
|
|
18339
19051
|
/** Re-evaluate held gaps after FEC state changed. */
|
|
18340
19052
|
poke(streamKey) {
|
|
18341
19053
|
if (streamKey !== void 0) {
|
|
@@ -18427,16 +19139,32 @@ var FecReleaseSequencer = class {
|
|
|
18427
19139
|
last: null,
|
|
18428
19140
|
lastSbn: void 0,
|
|
18429
19141
|
discontinuity: false,
|
|
18430
|
-
rapSsId: void 0
|
|
19142
|
+
rapSsId: void 0,
|
|
19143
|
+
sourced: false,
|
|
19144
|
+
draining: 0
|
|
18431
19145
|
};
|
|
18432
19146
|
this.#streams.set(streamKey, stream);
|
|
18433
19147
|
}
|
|
18434
19148
|
return stream;
|
|
18435
19149
|
}
|
|
18436
|
-
#
|
|
19150
|
+
/** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
|
|
19151
|
+
#drain(stream, asUnanchored = false) {
|
|
19152
|
+
stream.draining++;
|
|
19153
|
+
try {
|
|
19154
|
+
this.#drainLoop(stream, asUnanchored);
|
|
19155
|
+
} finally {
|
|
19156
|
+
stream.draining--;
|
|
19157
|
+
}
|
|
19158
|
+
}
|
|
19159
|
+
#drainLoop(stream, asUnanchored) {
|
|
18437
19160
|
while (stream.buf.length > 0 && stream.last !== null) {
|
|
18438
19161
|
const head = stream.buf[0];
|
|
18439
19162
|
const last = stream.last;
|
|
19163
|
+
if (compareFrameOrder(head, last) <= 0) {
|
|
19164
|
+
stream.buf.shift();
|
|
19165
|
+
this.#release(stream, head, void 0);
|
|
19166
|
+
continue;
|
|
19167
|
+
}
|
|
18440
19168
|
if (stream.discontinuity) {
|
|
18441
19169
|
stream.discontinuity = false;
|
|
18442
19170
|
stream.buf.shift();
|
|
@@ -18450,9 +19178,10 @@ var FecReleaseSequencer = class {
|
|
|
18450
19178
|
}
|
|
18451
19179
|
const headSbn = head.meta.fecSbn;
|
|
18452
19180
|
const from = stream.lastSbn ?? headSbn;
|
|
18453
|
-
const to = headSbn ?? stream.lastSbn;
|
|
19181
|
+
const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
|
|
18454
19182
|
let lost = [];
|
|
18455
19183
|
const unanchored = from === void 0 && to === void 0;
|
|
19184
|
+
let unresolved = false;
|
|
18456
19185
|
if (from !== void 0 && to !== void 0) {
|
|
18457
19186
|
const resolved = this.#gate.resolvedLoss(
|
|
18458
19187
|
stream.packetId,
|
|
@@ -18461,7 +19190,8 @@ var FecReleaseSequencer = class {
|
|
|
18461
19190
|
Math.max(from, to),
|
|
18462
19191
|
from
|
|
18463
19192
|
);
|
|
18464
|
-
|
|
19193
|
+
unresolved = resolved === null;
|
|
19194
|
+
if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
|
|
18465
19195
|
const heldMs = performance.now() - head.arrivedAtMs;
|
|
18466
19196
|
if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
|
|
18467
19197
|
this.#recordStat("forcedWindowFlushes");
|
|
@@ -18469,22 +19199,69 @@ var FecReleaseSequencer = class {
|
|
|
18469
19199
|
this.#release(stream, head, this.#gate.decide(last, head, [], true));
|
|
18470
19200
|
continue;
|
|
18471
19201
|
}
|
|
18472
|
-
lost = resolved;
|
|
19202
|
+
lost = resolved ?? [];
|
|
18473
19203
|
}
|
|
18474
19204
|
stream.buf.shift();
|
|
18475
19205
|
this.#release(
|
|
18476
19206
|
stream,
|
|
18477
19207
|
head,
|
|
18478
|
-
lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
19208
|
+
lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
18479
19209
|
);
|
|
18480
19210
|
}
|
|
18481
19211
|
}
|
|
19212
|
+
/**
|
|
19213
|
+
* The head has waited out a gap only a late source can still fill
|
|
19214
|
+
* (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
|
|
19215
|
+
* the stream when it has (`wakeAt`), since no packet may come by then.
|
|
19216
|
+
*/
|
|
19217
|
+
#unrepairableWaitOver(stream, last, head, from, to) {
|
|
19218
|
+
const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
|
|
19219
|
+
if (waitMs === void 0) return false;
|
|
19220
|
+
const atMs = head.arrivedAtMs + waitMs;
|
|
19221
|
+
if (performance.now() >= atMs) return true;
|
|
19222
|
+
this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
|
|
19223
|
+
return false;
|
|
19224
|
+
}
|
|
19225
|
+
/**
|
|
19226
|
+
* An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
|
|
19227
|
+
* source cursor holds it unanchored, and neither does a later frame behind
|
|
19228
|
+
* it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
|
|
19229
|
+
* fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
|
|
19230
|
+
* like each frame that arrived in front of it since (stale there). The head
|
|
19231
|
+
* then goes, decided as it would be unanchored, once a frame the base path
|
|
19232
|
+
* delivered (a source frame, or one base FEC recovered) is buffered after a
|
|
19233
|
+
* marked one: the base path has passed that one, so a frame still missing
|
|
19234
|
+
* before it can only come from a repair. It also goes while no source frame
|
|
19235
|
+
* has been released, when the direct path shows a recovered frame at once.
|
|
19236
|
+
* And it goes at once while a staged switch decides on when frames arrive
|
|
19237
|
+
* (FecReleaseGate.releaseUnanchored), and when unsource releases into a
|
|
19238
|
+
* sink being replaced: unanchored, it had already reached the sink.
|
|
19239
|
+
* The scan also writes: the `passed` marks it sets stay on the frames,
|
|
19240
|
+
* and push marks a frame it inserts in front of a marked one from them.
|
|
19241
|
+
*/
|
|
19242
|
+
#cursorPassed(stream, asUnanchored) {
|
|
19243
|
+
let at2 = -1;
|
|
19244
|
+
for (let i = 0; i < stream.buf.length; i++) {
|
|
19245
|
+
const frame = stream.buf[i];
|
|
19246
|
+
if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
|
|
19247
|
+
frame.passed = true;
|
|
19248
|
+
if (at2 < 0) at2 = i;
|
|
19249
|
+
} else if (frame.passed !== true) break;
|
|
19250
|
+
}
|
|
19251
|
+
if (at2 < 0) return false;
|
|
19252
|
+
return asUnanchored || !stream.sourced || this.#gate.releaseUnanchored?.(stream.packetId, stream.catalogTrackName) === true || stream.buf.some(({ meta }, i) => i > at2 && meta.fecSbnFirst === void 0 && (meta.recovered !== true || meta.fecSbn !== void 0));
|
|
19253
|
+
}
|
|
18482
19254
|
#release(stream, frame, decision) {
|
|
19255
|
+
const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
|
|
19256
|
+
if (stale) this.#recordStat("droppedStale");
|
|
18483
19257
|
if (decision) frame.meta.gapBefore = decision;
|
|
18484
19258
|
stream.last = frame;
|
|
18485
|
-
if (frame.meta.fecSbn !== void 0
|
|
19259
|
+
if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
|
|
19260
|
+
stream.lastSbn = frame.meta.fecSbn;
|
|
19261
|
+
}
|
|
19262
|
+
if (frame.meta.recovered !== true) stream.sourced = true;
|
|
18486
19263
|
this.#gate.onReleased?.(frame.data, frame.meta);
|
|
18487
|
-
this.#emit(frame.data, frame.meta);
|
|
19264
|
+
if (!stale) this.#emit(frame.data, frame.meta);
|
|
18488
19265
|
}
|
|
18489
19266
|
};
|
|
18490
19267
|
var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
|
|
@@ -18525,6 +19302,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18525
19302
|
this.#reclaimedTimingSamples = 0;
|
|
18526
19303
|
this.#evictedTimingSamples = 0;
|
|
18527
19304
|
this.#rejectedMovieFragments = 0;
|
|
19305
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
19306
|
+
held: 0,
|
|
19307
|
+
expired: 0,
|
|
19308
|
+
discarded: 0,
|
|
19309
|
+
superseded: 0
|
|
19310
|
+
};
|
|
18528
19311
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
18529
19312
|
this.#fecGate = null;
|
|
18530
19313
|
this.#fecSequencer = null;
|
|
@@ -18633,6 +19416,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18633
19416
|
#reclaimedTimingSamples;
|
|
18634
19417
|
#evictedTimingSamples;
|
|
18635
19418
|
#rejectedMovieFragments;
|
|
19419
|
+
#recoveredHeadsAwaitingTiming;
|
|
18636
19420
|
#sequencers;
|
|
18637
19421
|
#fecGate;
|
|
18638
19422
|
#fecSequencer;
|
|
@@ -18738,11 +19522,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18738
19522
|
/**
|
|
18739
19523
|
* Typed view of the ISO-BMFF timing-sample budget.
|
|
18740
19524
|
*
|
|
18741
|
-
*
|
|
18742
|
-
*
|
|
18743
|
-
*
|
|
18744
|
-
*
|
|
18745
|
-
*
|
|
19525
|
+
* Each stream admits timing against its own window of `capacity` slots
|
|
19526
|
+
* (BLO-52085). A stream at capacity displaces its own oldest timing to
|
|
19527
|
+
* admit the moof in hand, and `evicted` counts the slots so displaced:
|
|
19528
|
+
* timing a stream declared and never delivered shows up there. `pending`
|
|
19529
|
+
* sums every stream, so it can exceed `capacity`. Per repo policy this is
|
|
19530
|
+
* a producer-owned counter -- never infer budget state by parsing logs.
|
|
18746
19531
|
*/
|
|
18747
19532
|
get timingBudgetStats() {
|
|
18748
19533
|
return {
|
|
@@ -18753,6 +19538,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18753
19538
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
18754
19539
|
};
|
|
18755
19540
|
}
|
|
19541
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
19542
|
+
get recoveredHeadsAwaitingTiming() {
|
|
19543
|
+
let pending = 0;
|
|
19544
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
19545
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
19546
|
+
}
|
|
19547
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
19548
|
+
}
|
|
18756
19549
|
get reorderStats() {
|
|
18757
19550
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
18758
19551
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -18794,6 +19587,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18794
19587
|
fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
|
|
18795
19588
|
return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
|
|
18796
19589
|
}
|
|
19590
|
+
/** See FecReleaseSequencer.unsource. */
|
|
19591
|
+
unsourceFecRelease(packetId, catalogTrackName) {
|
|
19592
|
+
this.#fecSequencer?.unsource(packetId, catalogTrackName);
|
|
19593
|
+
}
|
|
19594
|
+
/** See FecReleaseSequencer.holdsRebuilt. */
|
|
19595
|
+
fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
|
|
19596
|
+
return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
|
|
19597
|
+
}
|
|
18797
19598
|
/** Re-evaluate held gaps after FEC block state changed. */
|
|
18798
19599
|
pokeFecRelease(packetId, catalogTrackName) {
|
|
18799
19600
|
if (!this.#fecSequencer) return;
|
|
@@ -18926,7 +19727,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18926
19727
|
const now = Date.now();
|
|
18927
19728
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18928
19729
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
18929
|
-
awaitingTiming.shift();
|
|
19730
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
18930
19731
|
}
|
|
18931
19732
|
}
|
|
18932
19733
|
}
|
|
@@ -19044,11 +19845,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19044
19845
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
19045
19846
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
19046
19847
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
19047
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
19848
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
19048
19849
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
19049
19850
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
19050
|
-
const remaining = this.#maxPendingTimingSamples -
|
|
19051
|
-
const admitted = resolver2.addMovieFragment(
|
|
19851
|
+
const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
|
|
19852
|
+
const admitted = resolver2.addMovieFragment(
|
|
19853
|
+
mpu.mpuSequenceNumber,
|
|
19854
|
+
data,
|
|
19855
|
+
remaining,
|
|
19856
|
+
options?.recovered === true
|
|
19857
|
+
);
|
|
19052
19858
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
19053
19859
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
19054
19860
|
if (!admitted) {
|
|
@@ -19068,7 +19874,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19068
19874
|
};
|
|
19069
19875
|
}
|
|
19070
19876
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
19071
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
19877
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
19072
19878
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
19073
19879
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
19074
19880
|
return this.#drop("mfu-empty-payload");
|
|
@@ -19089,6 +19895,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19089
19895
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
19090
19896
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
19091
19897
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
19898
|
+
sequenceNumber: info.sequenceNumber,
|
|
19092
19899
|
arrivedAt: Date.now()
|
|
19093
19900
|
});
|
|
19094
19901
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -19114,7 +19921,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19114
19921
|
info,
|
|
19115
19922
|
resolver,
|
|
19116
19923
|
options?.recovered === true,
|
|
19117
|
-
options?.fecSbn
|
|
19924
|
+
options?.fecSbn,
|
|
19925
|
+
options?.fecSbnFirst
|
|
19118
19926
|
);
|
|
19119
19927
|
if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
|
|
19120
19928
|
}
|
|
@@ -19207,7 +20015,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19207
20015
|
info,
|
|
19208
20016
|
resolver,
|
|
19209
20017
|
options?.recovered === true,
|
|
19210
|
-
options?.fecSbn
|
|
20018
|
+
options?.fecSbn,
|
|
20019
|
+
options?.fecSbnFirst
|
|
19211
20020
|
);
|
|
19212
20021
|
if (outcome.record !== void 0) return outcome.record;
|
|
19213
20022
|
return this.#drop(outcome.reason);
|
|
@@ -19227,7 +20036,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19227
20036
|
* attribution exists to keep readable. Leaving the choice at the call site
|
|
19228
20037
|
* is what keeps both true.
|
|
19229
20038
|
*/
|
|
19230
|
-
#emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
|
|
20039
|
+
#emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
|
|
19231
20040
|
const timing = resolver.sampleTiming(
|
|
19232
20041
|
combined.mpuSequenceNumber,
|
|
19233
20042
|
combined.movieFragmentSequenceNumber,
|
|
@@ -19244,6 +20053,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19244
20053
|
);
|
|
19245
20054
|
if (!meta) return { reason: "combined-meta-build-failed" };
|
|
19246
20055
|
if (fecSbn !== void 0) meta.fecSbn = fecSbn;
|
|
20056
|
+
if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
|
|
19247
20057
|
if (!resolver.consumeSample(
|
|
19248
20058
|
combined.mpuSequenceNumber,
|
|
19249
20059
|
combined.movieFragmentSequenceNumber,
|
|
@@ -19477,6 +20287,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19477
20287
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
19478
20288
|
this.#sequencers.clear();
|
|
19479
20289
|
this.#fecSequencer?.discard();
|
|
20290
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
20291
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
20292
|
+
}
|
|
19480
20293
|
this.#timingStreams.clear();
|
|
19481
20294
|
this.#pendingTimingSamples = 0;
|
|
19482
20295
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -19495,10 +20308,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19495
20308
|
return resolver;
|
|
19496
20309
|
}
|
|
19497
20310
|
#awaitTiming(streamKey, head) {
|
|
19498
|
-
const
|
|
19499
|
-
if (!
|
|
20311
|
+
const state = this.#timingStreams.get(streamKey);
|
|
20312
|
+
if (!state) return;
|
|
20313
|
+
if (!head.options?.recovered) {
|
|
20314
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
20315
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
20316
|
+
state.awaitingTiming = kept;
|
|
20317
|
+
}
|
|
20318
|
+
const awaitingTiming = state.awaitingTiming;
|
|
19500
20319
|
awaitingTiming.push(head);
|
|
19501
|
-
if (
|
|
20320
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
20321
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
20322
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
20323
|
+
}
|
|
20324
|
+
}
|
|
20325
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
20326
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
20327
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
19502
20328
|
}
|
|
19503
20329
|
/**
|
|
19504
20330
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -19526,6 +20352,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19526
20352
|
const state = this.#timingStreams.get(streamKey);
|
|
19527
20353
|
if (!state) return;
|
|
19528
20354
|
this.#timingStreams.delete(streamKey);
|
|
20355
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
19529
20356
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
19530
20357
|
if (this.#pendingTimingSamples < 0) {
|
|
19531
20358
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|
|
@@ -22732,7 +23559,18 @@ function keyframeOverlaySsId(header) {
|
|
|
22732
23559
|
if (ext?.type !== KEYFRAME_OVERLAY_EXTENSION_TYPE || ext.data.length !== 4) return void 0;
|
|
22733
23560
|
return new DataView(ext.data.buffer, ext.data.byteOffset, 4).getUint32(0);
|
|
22734
23561
|
}
|
|
23562
|
+
function overlayBaseSsId(anchor, overlaySsId, restoredPsn, headerPsn) {
|
|
23563
|
+
if (anchor.baseSsId === void 0 || headerPsn !== restoredPsn) return void 0;
|
|
23564
|
+
return serial32Add(anchor.baseSsId, overlaySsId - anchor.overlaySsId | 0);
|
|
23565
|
+
}
|
|
23566
|
+
function unstampedBaseSsId(offset, unstampedOffset, headerPsn) {
|
|
23567
|
+
if (offset === void 0 || offset !== unstampedOffset) return void 0;
|
|
23568
|
+
return headerPsn + offset >>> 0;
|
|
23569
|
+
}
|
|
23570
|
+
var OVERLAY_ROUTED_LIMIT = 1024;
|
|
23571
|
+
var OVERLAY_PENDING_LIMIT = 256;
|
|
22735
23572
|
var OVERLAY_OFFSET_MPUS = 16;
|
|
23573
|
+
var OVERLAY_REBUILT_LIMIT = 256;
|
|
22736
23574
|
var OVERLAY_MOQ_HORIZON_BLOCKS = 64;
|
|
22737
23575
|
function assertStreamIdentity(role, stream) {
|
|
22738
23576
|
if (stream === void 0 || !Number.isInteger(stream.packetId) || stream.packetId <= MMTP_SIGNALING_PACKET_ID || typeof stream.catalogTrackName !== "string" || stream.catalogTrackName.length === 0) {
|
|
@@ -22843,6 +23681,7 @@ var MmtpRouter = class {
|
|
|
22843
23681
|
#provenance = /* @__PURE__ */ new Map();
|
|
22844
23682
|
#onFlowProtected = null;
|
|
22845
23683
|
#unadmittedListedDrops = 0;
|
|
23684
|
+
#admittedSourceDatagrams = 0;
|
|
22846
23685
|
#unlistedRepairSetAside = 0;
|
|
22847
23686
|
#assistBlocks = /* @__PURE__ */ new Map();
|
|
22848
23687
|
#assistFailures = /* @__PURE__ */ new Map();
|
|
@@ -22899,6 +23738,26 @@ var MmtpRouter = class {
|
|
|
22899
23738
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
22900
23739
|
*/
|
|
22901
23740
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
23741
|
+
/**
|
|
23742
|
+
* Per stream, the SS_ID offset at which a base recovery last showed the
|
|
23743
|
+
* sender's own packet_sequence_number: a recovered packet's header psn
|
|
23744
|
+
* equal to its SS_ID minus that offset. While it equals the stream's
|
|
23745
|
+
* current offset, no hop re-stamps the stream, and a packet's protected psn
|
|
23746
|
+
* names its base SS_ID within unstampedBaseSsId's limits (joint decoding of
|
|
23747
|
+
* an MPU no member of which arrived).
|
|
23748
|
+
*/
|
|
23749
|
+
#unstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
23750
|
+
/**
|
|
23751
|
+
* The same, shown by the overlay alone, before any base recovery did: a
|
|
23752
|
+
* packet it rebuilt whose base copy carries its protected psn
|
|
23753
|
+
* (#feedOverlaySource), or whose protected psn passes overlayBaseSsId's
|
|
23754
|
+
* test at that offset (#routeOverlayRecovered). A base SS_ID placed by it
|
|
23755
|
+
* anchors the release gate only (BLO-52085 D3): fed to the base, it would
|
|
23756
|
+
* make the base drop a late base copy of a keyframe the overlay never
|
|
23757
|
+
* finished, and lift a block's late-source cut, which nothing before
|
|
23758
|
+
* this offset did.
|
|
23759
|
+
*/
|
|
23760
|
+
#overlayUnstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
22902
23761
|
/**
|
|
22903
23762
|
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
22904
23763
|
* not parsed, typically because its overlap copy was parsed first
|
|
@@ -22944,6 +23803,8 @@ var MmtpRouter = class {
|
|
|
22944
23803
|
// end: a synchronous recovery completes its block BEFORE routing the
|
|
22945
23804
|
// recovered frames, and releasing a held gap in between would strand them.
|
|
22946
23805
|
#fecPokeDepth = 0;
|
|
23806
|
+
/** FecReleaseGate.wakeAt timers, by media stream key. */
|
|
23807
|
+
#fecWakes = /* @__PURE__ */ new Map();
|
|
22947
23808
|
#pendingFecPokes = /* @__PURE__ */ new Map();
|
|
22948
23809
|
// ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
|
|
22949
23810
|
/** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
|
|
@@ -22968,7 +23829,9 @@ var MmtpRouter = class {
|
|
|
22968
23829
|
recovered: 0,
|
|
22969
23830
|
restarts: 0,
|
|
22970
23831
|
unsequencedDropped: 0,
|
|
22971
|
-
protectedDropped: 0
|
|
23832
|
+
protectedDropped: 0,
|
|
23833
|
+
baseFed: 0,
|
|
23834
|
+
baseUndetermined: 0
|
|
22972
23835
|
};
|
|
22973
23836
|
/** Callback fired when a delta-track FEC block completes or fails. */
|
|
22974
23837
|
#onDeltaBlockCompleteCb = null;
|
|
@@ -23141,7 +24004,7 @@ var MmtpRouter = class {
|
|
|
23141
24004
|
const cb = this.#getFrameCallback(packetId);
|
|
23142
24005
|
if (isVideo && !assembler) {
|
|
23143
24006
|
if (frameMeta.recovered) {
|
|
23144
|
-
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb);
|
|
24007
|
+
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb, meta.fecSbn);
|
|
23145
24008
|
} else {
|
|
23146
24009
|
this.#routeDirectSourceVideo(packetId, data, frameMeta, cb);
|
|
23147
24010
|
}
|
|
@@ -23174,13 +24037,18 @@ var MmtpRouter = class {
|
|
|
23174
24037
|
this.#onDeltaBlockCompleteCb?.(packetId, false);
|
|
23175
24038
|
}
|
|
23176
24039
|
};
|
|
23177
|
-
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass) => {
|
|
24040
|
+
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
23178
24041
|
this.#mseAssemblerFor(packetId, catalogTrackName)?.failBlock(sbn);
|
|
23179
24042
|
if (this.#isCatalogTrackUnambiguous(packetId, catalogTrackName) && this.#packetIdRoles.get(packetId) === "delta") {
|
|
23180
24043
|
this.#onDeltaBlockCompleteCb?.(packetId, true);
|
|
23181
24044
|
}
|
|
23182
|
-
|
|
23183
|
-
|
|
24045
|
+
if (span === void 0) {
|
|
24046
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
24047
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
24048
|
+
} else {
|
|
24049
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
24050
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
24051
|
+
}
|
|
23184
24052
|
};
|
|
23185
24053
|
}
|
|
23186
24054
|
}
|
|
@@ -23225,8 +24093,9 @@ var MmtpRouter = class {
|
|
|
23225
24093
|
}
|
|
23226
24094
|
/**
|
|
23227
24095
|
* FEC-recovered source symbols whose reconstructed header named a
|
|
23228
|
-
* packet_sequence_number other than the wire sequence their SS_ID maps to
|
|
23229
|
-
*
|
|
24096
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to,
|
|
24097
|
+
* or, rebuilt by the overlay, than their base copy carries: a hop
|
|
24098
|
+
* re-stamped the sequence after the sender protected the packet.
|
|
23230
24099
|
*/
|
|
23231
24100
|
get restampedRecoveredSequenceCount() {
|
|
23232
24101
|
return this.#restampedRecoveredSeqs;
|
|
@@ -23405,6 +24274,7 @@ var MmtpRouter = class {
|
|
|
23405
24274
|
enableMseAssembler(packetId, config, catalogTrackName) {
|
|
23406
24275
|
const assemblerKey = this.#mseAssemblerKey(packetId, catalogTrackName);
|
|
23407
24276
|
const previous = this.#mseAssemblers.get(assemblerKey);
|
|
24277
|
+
this.#parser.unsourceFecRelease(packetId, catalogTrackName);
|
|
23408
24278
|
if (previous) {
|
|
23409
24279
|
previous.flush();
|
|
23410
24280
|
previous.dispose();
|
|
@@ -23531,6 +24401,10 @@ var MmtpRouter = class {
|
|
|
23531
24401
|
get keyframeOverlayStats() {
|
|
23532
24402
|
return { ...this.#overlayStats };
|
|
23533
24403
|
}
|
|
24404
|
+
/** Recovered FT=2 heads held for their FT=1, and how each left the wait (BLO-53369). */
|
|
24405
|
+
get recoveredHeadsAwaitingTiming() {
|
|
24406
|
+
return this.#parser.recoveredHeadsAwaitingTiming;
|
|
24407
|
+
}
|
|
23534
24408
|
#isOverlayRepair(repairPacketId, repairTrackName) {
|
|
23535
24409
|
return this.#overlayLegs.has(repairPacketId) || repairTrackName !== void 0 && this.#overlayRepairNames.has(repairTrackName);
|
|
23536
24410
|
}
|
|
@@ -23551,7 +24425,8 @@ var MmtpRouter = class {
|
|
|
23551
24425
|
fec,
|
|
23552
24426
|
k,
|
|
23553
24427
|
offsets: /* @__PURE__ */ new Map(),
|
|
23554
|
-
moqBlocks: /* @__PURE__ */ new Set()
|
|
24428
|
+
moqBlocks: /* @__PURE__ */ new Set(),
|
|
24429
|
+
rebuilt: /* @__PURE__ */ new Map()
|
|
23555
24430
|
};
|
|
23556
24431
|
this.#overlays.set(repairPacketId, inst);
|
|
23557
24432
|
return () => {
|
|
@@ -23581,12 +24456,18 @@ var MmtpRouter = class {
|
|
|
23581
24456
|
*/
|
|
23582
24457
|
resetKeyframeOverlays(sourcePacketId, catalogTrackName) {
|
|
23583
24458
|
for (const inst of this.#overlaysForSource(sourcePacketId, catalogTrackName)) this.#resetOverlay(inst);
|
|
24459
|
+
for (const [name, stream] of this.#streams.get(sourcePacketId) ?? []) {
|
|
24460
|
+
if (catalogTrackName !== void 0 && name !== catalogTrackName) continue;
|
|
24461
|
+
stream.overlayToBase.routed.clear();
|
|
24462
|
+
stream.overlayToBase.pending.clear();
|
|
24463
|
+
}
|
|
23584
24464
|
}
|
|
23585
24465
|
#resetOverlay(inst) {
|
|
23586
24466
|
inst.fec.resetTrack(inst.repairPacketId, inst.streamName);
|
|
23587
24467
|
inst.last = void 0;
|
|
23588
24468
|
inst.offsets.clear();
|
|
23589
24469
|
inst.moqBlocks.clear();
|
|
24470
|
+
inst.rebuilt.clear();
|
|
23590
24471
|
}
|
|
23591
24472
|
#overlaysForSource(sourcePacketId, catalogTrackName) {
|
|
23592
24473
|
return [...this.#overlays.values()].filter(({ leg }) => leg.sourcePacketId === sourcePacketId && (catalogTrackName === void 0 || leg.sourceCatalogTrackName === void 0 || leg.sourceCatalogTrackName === catalogTrackName));
|
|
@@ -23637,18 +24518,33 @@ var MmtpRouter = class {
|
|
|
23637
24518
|
* A source packet that carries a 0x8B01 overlay SS_ID is also a symbol of
|
|
23638
24519
|
* every overlay installed for its source, at that SS_ID, with the bytes the
|
|
23639
24520
|
* base protects: the packet minus its 4-byte SS_ID trailer, extension
|
|
23640
|
-
* included (7.1, 7.4.3).
|
|
23641
|
-
|
|
23642
|
-
|
|
24521
|
+
* included (7.1, 7.4.3). `baseSsId` is that trailer's SS_ID, when the base
|
|
24522
|
+
* FEC reads it.
|
|
24523
|
+
*
|
|
24524
|
+
* The base copy of a packet an overlay rebuilt with no base SS_ID shows
|
|
24525
|
+
* what a base recovery of it would (#routeProcessedFecSymbols, BLO-52085):
|
|
24526
|
+
* its wire packet_sequence_number equal to the protected one rebuilt shows
|
|
24527
|
+
* the stream unstamped at the SS_ID offset it states, for the release gate
|
|
24528
|
+
* (#overlayUnstampedSsIdSeqOffsetByStream); any other shows a hop that
|
|
24529
|
+
* re-stamps it, which is counted (restampedRecoveredSequenceCount).
|
|
24530
|
+
*/
|
|
24531
|
+
#feedOverlaySource(packetId, catalogTrackName, packet, header, sequenceNumber, rapFlag, source, baseSsId) {
|
|
23643
24532
|
if (this.#overlays.size === 0) return;
|
|
23644
24533
|
const ssId = keyframeOverlaySsId(header);
|
|
23645
24534
|
if (ssId === void 0) return;
|
|
24535
|
+
let rebuiltPsn;
|
|
23646
24536
|
for (const inst of this.#overlaysForSource(packetId, catalogTrackName)) {
|
|
23647
24537
|
this.#noteOverlaySsId(inst, ssId, sequenceNumber);
|
|
24538
|
+
rebuiltPsn ??= inst.rebuilt.get(ssId);
|
|
24539
|
+
inst.rebuilt.delete(ssId);
|
|
23648
24540
|
const identity = MmtpContainerParser.sourcePacketIdentity(packet, header);
|
|
23649
24541
|
if (identity !== null) {
|
|
23650
24542
|
inst.offsets.delete(identity.mpuSequenceNumber);
|
|
23651
|
-
inst.offsets.set(identity.mpuSequenceNumber,
|
|
24543
|
+
inst.offsets.set(identity.mpuSequenceNumber, {
|
|
24544
|
+
psnOffset: ssId - sequenceNumber >>> 0,
|
|
24545
|
+
overlaySsId: ssId,
|
|
24546
|
+
...baseSsId === void 0 ? {} : { baseSsId }
|
|
24547
|
+
});
|
|
23652
24548
|
if (inst.offsets.size > OVERLAY_OFFSET_MPUS) inst.offsets.delete(inst.offsets.keys().next().value);
|
|
23653
24549
|
}
|
|
23654
24550
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -23670,6 +24566,14 @@ var MmtpRouter = class {
|
|
|
23670
24566
|
const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
|
|
23671
24567
|
if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, coords.sbn, recovered);
|
|
23672
24568
|
}
|
|
24569
|
+
if (rebuiltPsn === void 0 || this.#classifyPacketId(packetId) === null) return;
|
|
24570
|
+
const streamKey = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
24571
|
+
if (rebuiltPsn !== sequenceNumber) {
|
|
24572
|
+
this.#restampedRecoveredSeqs++;
|
|
24573
|
+
} else if (baseSsId !== void 0) {
|
|
24574
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24575
|
+
if (offset === baseSsId - sequenceNumber >>> 0) this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
24576
|
+
}
|
|
23673
24577
|
}
|
|
23674
24578
|
#noteOverlayMoqBlock(inst, blockStart) {
|
|
23675
24579
|
inst.moqBlocks.add(blockStart);
|
|
@@ -23703,11 +24607,16 @@ var MmtpRouter = class {
|
|
|
23703
24607
|
}
|
|
23704
24608
|
/**
|
|
23705
24609
|
* Route an overlay-recovered block's packets as source media of the
|
|
23706
|
-
* overlay's source (7.2: an overlay coordinate yields no base SS_ID).
|
|
23707
|
-
*
|
|
23708
|
-
*
|
|
23709
|
-
*
|
|
23710
|
-
*
|
|
24610
|
+
* overlay's source (7.2: an overlay coordinate yields no base SS_ID). A
|
|
24611
|
+
* packet whose base SS_ID is determined independently (overlayBaseSsId,
|
|
24612
|
+
* unstampedBaseSsId) enters the release gate at that SS_ID, as a packet
|
|
24613
|
+
* base FEC recovered does, so it waits behind base frames still in flight,
|
|
24614
|
+
* though not for its own MPU's packets (FrameMeta.fecSbnFirst) and no
|
|
24615
|
+
* longer than unanchored; one whose base SS_ID is undetermined has no
|
|
24616
|
+
* release-gate anchor. No parse ledger, no base re-stamp, no block
|
|
24617
|
+
* advance. Each packet's wire sequence is restored from its keyframe's own
|
|
24618
|
+
* offset; without one, a stream the base never re-stamped keeps the
|
|
24619
|
+
* header's sequence and any other drops the packet.
|
|
23711
24620
|
*/
|
|
23712
24621
|
#routeOverlayRecovered(inst, blockStart, recovered) {
|
|
23713
24622
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -23727,22 +24636,139 @@ var MmtpRouter = class {
|
|
|
23727
24636
|
const streamKey = this.#mediaStreamKey(sourcePacketId, sourceName);
|
|
23728
24637
|
const restamped = this.#restampedStreams.has(streamKey);
|
|
23729
24638
|
const restored = /* @__PURE__ */ new Set();
|
|
24639
|
+
const baseSsIds = /* @__PURE__ */ new Map();
|
|
24640
|
+
const gateOnly = /* @__PURE__ */ new Set();
|
|
23730
24641
|
const symbols = result.symbols.flatMap((sym) => {
|
|
23731
|
-
const
|
|
23732
|
-
|
|
23733
|
-
|
|
24642
|
+
const overlaySsId = serial32Add(blockStart, sym.index);
|
|
24643
|
+
const anchor = inst.offsets.get(sym.fragment.mpuSequenceNumber);
|
|
24644
|
+
if (anchor !== void 0) {
|
|
24645
|
+
const packetSequenceNumber = overlaySsId - anchor.psnOffset >>> 0;
|
|
23734
24646
|
restored.add(packetSequenceNumber);
|
|
23735
|
-
|
|
24647
|
+
const out = { ...sym, packetSequenceNumber };
|
|
24648
|
+
const baseSsId = overlayBaseSsId(anchor, overlaySsId, packetSequenceNumber, sym.packetSequenceNumber);
|
|
24649
|
+
if (baseSsId !== void 0) {
|
|
24650
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
24651
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24652
|
+
if (!this.#sourceSeqReceived(sourcePacketId, packetSequenceNumber, sourceName) && offset === baseSsId - packetSequenceNumber >>> 0) {
|
|
24653
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
24654
|
+
}
|
|
24655
|
+
}
|
|
24656
|
+
return [out];
|
|
24657
|
+
}
|
|
24658
|
+
if (!restamped) {
|
|
24659
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24660
|
+
const fedSsId = unstampedBaseSsId(offset, this.#unstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
24661
|
+
const baseSsId = fedSsId ?? unstampedBaseSsId(offset, this.#overlayUnstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
24662
|
+
if (baseSsId !== void 0) {
|
|
24663
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
24664
|
+
if (fedSsId === void 0) gateOnly.add(sym.index);
|
|
24665
|
+
} else {
|
|
24666
|
+
inst.rebuilt.set(overlaySsId, sym.packetSequenceNumber);
|
|
24667
|
+
if (inst.rebuilt.size > OVERLAY_REBUILT_LIMIT) inst.rebuilt.delete(inst.rebuilt.keys().next().value);
|
|
24668
|
+
}
|
|
24669
|
+
return [sym];
|
|
23736
24670
|
}
|
|
23737
|
-
if (!restamped) return [sym];
|
|
23738
24671
|
this.#overlayStats.unsequencedDropped++;
|
|
23739
24672
|
return [];
|
|
23740
24673
|
});
|
|
23741
24674
|
this.#overlayStats.recovered++;
|
|
24675
|
+
const mpuFirst = /* @__PURE__ */ new Map();
|
|
24676
|
+
for (const sym of symbols) {
|
|
24677
|
+
const ssId = baseSsIds.get(sym.index);
|
|
24678
|
+
const mpu = sym.fragment.mpuSequenceNumber;
|
|
24679
|
+
const first = mpuFirst.get(mpu);
|
|
24680
|
+
if (ssId !== void 0 && (first === void 0 || serial32Precedes(ssId, first))) mpuFirst.set(mpu, ssId);
|
|
24681
|
+
}
|
|
24682
|
+
const firstSsIds = /* @__PURE__ */ new Map();
|
|
24683
|
+
for (const sym of symbols) {
|
|
24684
|
+
if (baseSsIds.has(sym.index)) firstSsIds.set(sym.index, mpuFirst.get(sym.fragment.mpuSequenceNumber));
|
|
24685
|
+
}
|
|
23742
24686
|
this.#routeProcessedFecSymbols(blockStart, { ...result, symbols }, sourcePacketId, sourceName, {
|
|
23743
|
-
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast"
|
|
24687
|
+
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast",
|
|
24688
|
+
baseSsIds,
|
|
24689
|
+
firstSsIds
|
|
23744
24690
|
});
|
|
23745
24691
|
this.#noteOverlayRecoveredRaps(sourcePacketId, sourceName, streamKey, symbols.filter((sym) => restored.has(sym.packetSequenceNumber)));
|
|
24692
|
+
this.#feedOverlayRecoveredToBase(inst, blockStart, symbols, gateOnly.size === 0 ? baseSsIds : new Map([...baseSsIds].filter(([index]) => !gateOnly.has(index))));
|
|
24693
|
+
}
|
|
24694
|
+
/**
|
|
24695
|
+
* Joint decoding (BLO-52085). A packet the overlay rebuilt is a source of
|
|
24696
|
+
* its base block too, once its base SS_ID is determined (overlayBaseSsId,
|
|
24697
|
+
* from a received member of its MPU, else unstampedBaseSsId at an offset a
|
|
24698
|
+
* base recovery showed; `baseSsIds` holds no other),
|
|
24699
|
+
* so it is fed to the base decoder as a rebuilt source
|
|
24700
|
+
* (FECManager.feedRebuiltSourceSymbol): the base block has one erasure
|
|
24701
|
+
* fewer to solve, and its repair can recover the block's other packets.
|
|
24702
|
+
* A base block no repair has stated yet takes it when one does
|
|
24703
|
+
* (#feedPendingRebuilt).
|
|
24704
|
+
*
|
|
24705
|
+
* The overlay route already handled each packet fed (delivered it, or
|
|
24706
|
+
* held an untimed head for its FT=1), so a base recovery routes none of
|
|
24707
|
+
* them again (#routeVerifiedFecSymbols): a second recovered copy of a
|
|
24708
|
+
* held head would wait in the parser for timing its first copy consumed.
|
|
24709
|
+
* Only an overlay block decoded from multicast symbols alone is fed: with
|
|
24710
|
+
* a MoQ symbol in it, the base block's recovery would depend on bytes
|
|
24711
|
+
* that crossed no multicast socket, which the provenance counted from the
|
|
24712
|
+
* block's own arrivals cannot show.
|
|
24713
|
+
*/
|
|
24714
|
+
#feedOverlayRecoveredToBase(inst, blockStart, symbols, baseSsIds) {
|
|
24715
|
+
const fec = this.#fecManager;
|
|
24716
|
+
const owner = inst.leg.sourcePacketId;
|
|
24717
|
+
const name = inst.leg.sourceCatalogTrackName;
|
|
24718
|
+
if (!fec?.feedRebuiltSourceSymbol || inst.moqBlocks.has(blockStart)) return;
|
|
24719
|
+
if (this.#classifyPacketId(owner) === null || fec.isTrackConfigured?.(owner) === false) return;
|
|
24720
|
+
const { duplicates, overlayToBase: { routed } } = this.#stream(owner, name);
|
|
24721
|
+
const feeds = [];
|
|
24722
|
+
for (const sym of symbols) {
|
|
24723
|
+
if (duplicates.sourceSeqs.has(sym.packetSequenceNumber)) continue;
|
|
24724
|
+
const ssId = baseSsIds.get(sym.index);
|
|
24725
|
+
if (ssId === void 0) {
|
|
24726
|
+
this.#overlayStats.baseUndetermined++;
|
|
24727
|
+
continue;
|
|
24728
|
+
}
|
|
24729
|
+
routed.delete(ssId);
|
|
24730
|
+
routed.add(ssId);
|
|
24731
|
+
if (routed.size > OVERLAY_ROUTED_LIMIT) routed.delete(routed.values().next().value);
|
|
24732
|
+
feeds.push([ssId, sym.rawSymbol]);
|
|
24733
|
+
}
|
|
24734
|
+
for (const [ssId, symbolData] of feeds) {
|
|
24735
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24736
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24737
|
+
}
|
|
24738
|
+
}
|
|
24739
|
+
/** Feed one rebuilt source to its base block, or keep it until a repair states that block. */
|
|
24740
|
+
#feedRebuiltToBase(owner, name, ssId, symbolData) {
|
|
24741
|
+
const fec = this.#fecManager;
|
|
24742
|
+
if (!fec?.feedRebuiltSourceSymbol) return;
|
|
24743
|
+
const coords = fec.locateIsoSource?.(owner, name, ssId);
|
|
24744
|
+
if (coords == null) {
|
|
24745
|
+
const pending = this.#stream(owner, name).overlayToBase.pending;
|
|
24746
|
+
pending.delete(ssId);
|
|
24747
|
+
pending.set(ssId, symbolData.slice());
|
|
24748
|
+
if (pending.size > OVERLAY_PENDING_LIMIT) pending.delete(pending.keys().next().value);
|
|
24749
|
+
return;
|
|
24750
|
+
}
|
|
24751
|
+
const fed = fec.feedRebuiltSourceSymbol(owner, ssId, symbolData, name);
|
|
24752
|
+
if (!fed.taken) return;
|
|
24753
|
+
this.#overlayStats.baseFed++;
|
|
24754
|
+
if (fed.recovered === null) return;
|
|
24755
|
+
const sbn = coords.sbn;
|
|
24756
|
+
this.#routeRecoveredBlock(sbn, fed.recovered, owner, name, () => {
|
|
24757
|
+
fec.cancelBlockTimeout(sbn, owner, name);
|
|
24758
|
+
fec.countRecovery(owner, sbn, name);
|
|
24759
|
+
fec.markBlockCompleted(sbn, owner, name);
|
|
24760
|
+
});
|
|
24761
|
+
}
|
|
24762
|
+
/** A repair stated `block`: the rebuilt sources that waited for it join it now. */
|
|
24763
|
+
#feedPendingRebuilt(owner, name, block) {
|
|
24764
|
+
const pending = this.#streams.get(owner)?.get(name)?.overlayToBase.pending;
|
|
24765
|
+
if (pending === void 0 || pending.size === 0) return;
|
|
24766
|
+
for (const [ssId, symbolData] of [...pending]) {
|
|
24767
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24768
|
+
if (serial32Distance(block.start, ssId) >= block.length) continue;
|
|
24769
|
+
pending.delete(ssId);
|
|
24770
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24771
|
+
}
|
|
23746
24772
|
}
|
|
23747
24773
|
/** fec-multicast-00 §6.6: report each base block whose RAP MFU fragments
|
|
23748
24774
|
* the overlay restored, when the keyframe's FT=0 and FT=1 are held too. A
|
|
@@ -23882,6 +24908,10 @@ var MmtpRouter = class {
|
|
|
23882
24908
|
get unadmittedListedDropCount() {
|
|
23883
24909
|
return this.#unadmittedListedDrops;
|
|
23884
24910
|
}
|
|
24911
|
+
/** Source datagrams (multicast or MoQ) a protected flow's bc-provenance v2 receiver released: admitted at once or held, then admitted by a record. Repair symbols and user-agent-admitted datagrams are not counted. Counted at release, before this router's own track checks: a released datagram those drop, which only a track change between hold and release can cause, still counts, so this is not a count of routed media. */
|
|
24912
|
+
get admittedSourceDatagramCount() {
|
|
24913
|
+
return this.#admittedSourceDatagrams;
|
|
24914
|
+
}
|
|
23885
24915
|
/** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
|
|
23886
24916
|
get unlistedRepairSetAsideCount() {
|
|
23887
24917
|
return this.#unlistedRepairSetAside;
|
|
@@ -24368,6 +25398,8 @@ var MmtpRouter = class {
|
|
|
24368
25398
|
)) return;
|
|
24369
25399
|
fec.noteBlockActivity?.(blockStart, ownerPacketId, catalogTrackName);
|
|
24370
25400
|
fec.noteRepairGroupLength?.(blockStart, ownerPacketId, repair.rsbLength, catalogTrackName);
|
|
25401
|
+
this.#feedPendingRebuilt(ownerPacketId, catalogTrackName, placement.block);
|
|
25402
|
+
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
24371
25403
|
const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
|
|
24372
25404
|
const recovered = fec.feedRepairSymbol(
|
|
24373
25405
|
ownerPacketId,
|
|
@@ -24418,7 +25450,7 @@ var MmtpRouter = class {
|
|
|
24418
25450
|
catalogTrackName
|
|
24419
25451
|
)) continue;
|
|
24420
25452
|
if (fec.isTrackConfigured?.(ownerPacketId) !== false) {
|
|
24421
|
-
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence);
|
|
25453
|
+
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence, true);
|
|
24422
25454
|
this.#requestFecPoke(ownerPacketId, catalogTrackName);
|
|
24423
25455
|
}
|
|
24424
25456
|
if (payload.oversized) continue;
|
|
@@ -24505,6 +25537,8 @@ var MmtpRouter = class {
|
|
|
24505
25537
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
24506
25538
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
24507
25539
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
25540
|
+
this.#unstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
25541
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
24508
25542
|
this.#multicastRapTwinByStream.delete(streamKey);
|
|
24509
25543
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
24510
25544
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
@@ -24631,6 +25665,12 @@ var MmtpRouter = class {
|
|
|
24631
25665
|
* the outgoing stream stops. The hold is bounded by the incoming stream's
|
|
24632
25666
|
* own RAP cadence, so no timer is involved.
|
|
24633
25667
|
*
|
|
25668
|
+
* While the switch is staged, the FEC release gate lets a keyframe the
|
|
25669
|
+
* overlay rebuilt reach it, on either side, when the keyframe did before
|
|
25670
|
+
* the gate anchored it (FecReleaseGate.releaseUnanchored): the switch
|
|
25671
|
+
* decides on what each side delivered, and the commit discards the gate's
|
|
25672
|
+
* frames of the outgoing stream.
|
|
25673
|
+
*
|
|
24634
25674
|
* The commit is one synchronous transition inside the frame path: the
|
|
24635
25675
|
* outgoing stream's already-admitted frames are released (its queued FEC
|
|
24636
25676
|
* gap fills only up to the RAP, since recovery can queue a frame ahead of
|
|
@@ -24681,6 +25721,9 @@ var MmtpRouter = class {
|
|
|
24681
25721
|
droppedIncomingFrames: 0
|
|
24682
25722
|
};
|
|
24683
25723
|
this.#staged = state;
|
|
25724
|
+
if (this.#parser.fecReleaseHoldsRebuilt(from.packetId, from.catalogTrackName)) {
|
|
25725
|
+
this.#requestFecPoke(from.packetId, from.catalogTrackName);
|
|
25726
|
+
}
|
|
24684
25727
|
return {
|
|
24685
25728
|
cancel: () => {
|
|
24686
25729
|
if (this.#staged !== state) return false;
|
|
@@ -24763,7 +25806,17 @@ var MmtpRouter = class {
|
|
|
24763
25806
|
*/
|
|
24764
25807
|
#routeParsedFrame(data, meta) {
|
|
24765
25808
|
if (this.#classifyPacketId(meta.packetId) === null) return;
|
|
24766
|
-
if (this.#staged !== null
|
|
25809
|
+
if (this.#staged !== null) {
|
|
25810
|
+
let consumed = false;
|
|
25811
|
+
this.#fecPokeDepth++;
|
|
25812
|
+
try {
|
|
25813
|
+
consumed = this.#interceptSwitchFrame(data, meta);
|
|
25814
|
+
} finally {
|
|
25815
|
+
this.#fecPokeDepth--;
|
|
25816
|
+
this.#flushPendingFecPokes();
|
|
25817
|
+
}
|
|
25818
|
+
if (consumed) return;
|
|
25819
|
+
}
|
|
24767
25820
|
this.#deliverParsedFrame(data, meta);
|
|
24768
25821
|
}
|
|
24769
25822
|
#commitStreamSwitch(state, rap, reason) {
|
|
@@ -24812,6 +25865,8 @@ var MmtpRouter = class {
|
|
|
24812
25865
|
this.#disposed = true;
|
|
24813
25866
|
this.#staged = null;
|
|
24814
25867
|
this.cancelKeyframeLostTimer();
|
|
25868
|
+
for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
|
|
25869
|
+
this.#fecWakes.clear();
|
|
24815
25870
|
this.#parser.dispose();
|
|
24816
25871
|
this.#streams.clear();
|
|
24817
25872
|
this.#trackPacketCallbacks.clear();
|
|
@@ -24915,12 +25970,16 @@ var MmtpRouter = class {
|
|
|
24915
25970
|
this.#parser.deferFecRelease(work);
|
|
24916
25971
|
} finally {
|
|
24917
25972
|
this.#fecPokeDepth--;
|
|
24918
|
-
|
|
24919
|
-
|
|
24920
|
-
|
|
24921
|
-
|
|
24922
|
-
|
|
24923
|
-
|
|
25973
|
+
this.#flushPendingFecPokes();
|
|
25974
|
+
}
|
|
25975
|
+
}
|
|
25976
|
+
/** Run the pokes requested while #fecPokeDepth was raised, once it is 0. */
|
|
25977
|
+
#flushPendingFecPokes() {
|
|
25978
|
+
if (this.#fecPokeDepth === 0 && this.#pendingFecPokes.size > 0 && !this.#disposed) {
|
|
25979
|
+
const pokes = [...this.#pendingFecPokes.values()];
|
|
25980
|
+
this.#pendingFecPokes.clear();
|
|
25981
|
+
for (const poke of pokes) {
|
|
25982
|
+
this.#parser.pokeFecRelease(poke.packetId, poke.catalogTrackName);
|
|
24924
25983
|
}
|
|
24925
25984
|
}
|
|
24926
25985
|
}
|
|
@@ -24989,6 +26048,31 @@ var MmtpRouter = class {
|
|
|
24989
26048
|
if (!fec?.terminalRetentionMsForPacket) return Infinity;
|
|
24990
26049
|
return fec.terminalRetentionMsForPacket(packetId) ?? 0;
|
|
24991
26050
|
},
|
|
26051
|
+
// Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
|
|
26052
|
+
// late source can), its frame waits the late-symbol allowance when the
|
|
26053
|
+
// gap holds no RAP an installed keyframe overlay could still rebuild:
|
|
26054
|
+
// lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
|
|
26055
|
+
// that opens the next one while MPU boundaries bound RAPs (rap-next,
|
|
26056
|
+
// unless the gap holds a stated block's loss: the overlay may rebuild
|
|
26057
|
+
// that MPU's FT=0, and the block's group then complete it), or
|
|
26058
|
+
// an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
|
|
26059
|
+
// other rap-next, whose gap may hold a whole MPU and the keyframe the
|
|
26060
|
+
// overlay protects) waits for that overlay's repair too (BLO-52085
|
|
26061
|
+
// D4). The FEC check comes first: most held gaps are not behind such a
|
|
26062
|
+
// span, and deciding one scans both frames' bitstreams.
|
|
26063
|
+
unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
|
|
26064
|
+
const fec = this.#fecManager;
|
|
26065
|
+
const { packetId, catalogTrackName } = after.meta;
|
|
26066
|
+
const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
|
|
26067
|
+
if (!fec || allowanceMs === void 0) return void 0;
|
|
26068
|
+
const decision = this.#decideGap(before, after, [], false);
|
|
26069
|
+
const mpu = before.meta.mpuSequenceNumber;
|
|
26070
|
+
const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
|
|
26071
|
+
if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
|
|
26072
|
+
return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
|
|
26073
|
+
}
|
|
26074
|
+
return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
|
|
26075
|
+
},
|
|
24992
26076
|
decide: (before, after, lostBlocks, discontinuity) => {
|
|
24993
26077
|
const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
|
|
24994
26078
|
this.#onFrameGap?.(decision);
|
|
@@ -24998,6 +26082,28 @@ var MmtpRouter = class {
|
|
|
24998
26082
|
onRap: (packetId, catalogTrackName, ssId) => {
|
|
24999
26083
|
for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
|
|
25000
26084
|
},
|
|
26085
|
+
// One timer per stream, at the earliest wake asked: its drain re-arms
|
|
26086
|
+
// for the next frame still waiting.
|
|
26087
|
+
wakeAt: (packetId, catalogTrackName, atMs) => {
|
|
26088
|
+
if (this.#disposed) return;
|
|
26089
|
+
const key = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
26090
|
+
const armed = this.#fecWakes.get(key);
|
|
26091
|
+
if (armed !== void 0 && armed.atMs <= atMs) return;
|
|
26092
|
+
if (armed !== void 0) clearTimeout(armed.timer);
|
|
26093
|
+
const timer = setTimeout(() => {
|
|
26094
|
+
this.#fecWakes.delete(key);
|
|
26095
|
+
this.#requestFecPoke(packetId, catalogTrackName);
|
|
26096
|
+
}, Math.max(0, Math.ceil(atMs - performance.now())));
|
|
26097
|
+
this.#fecWakes.set(key, { atMs, timer });
|
|
26098
|
+
},
|
|
26099
|
+
// A staged switch commits on when each side's frames reach it
|
|
26100
|
+
// (#interceptSwitchFrame): both sides' overlay keyframes reach it when
|
|
26101
|
+
// they did unanchored.
|
|
26102
|
+
releaseUnanchored: (packetId, catalogTrackName) => {
|
|
26103
|
+
const staged = this.#staged;
|
|
26104
|
+
const stream = { packetId, ...catalogTrackName === void 0 ? {} : { catalogTrackName } };
|
|
26105
|
+
return staged !== null && (isStream(stream, staged.from) || isStream(stream, staged.to));
|
|
26106
|
+
},
|
|
25001
26107
|
onReleased: (data, meta) => {
|
|
25002
26108
|
if (meta.trackType !== "video" || meta.mpuSequenceNumber === void 0) return;
|
|
25003
26109
|
const timing = meta.authoredTiming;
|
|
@@ -25025,7 +26131,7 @@ var MmtpRouter = class {
|
|
|
25025
26131
|
#decideGap(before, after, lostBlocks, discontinuity) {
|
|
25026
26132
|
const { packetId, catalogTrackName } = after.meta;
|
|
25027
26133
|
const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
|
|
25028
|
-
const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying";
|
|
26134
|
+
const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" && before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
|
|
25029
26135
|
const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
|
|
25030
26136
|
const evidence = (frame) => {
|
|
25031
26137
|
const timing = frame.meta.authoredTiming;
|
|
@@ -25139,6 +26245,7 @@ var MmtpRouter = class {
|
|
|
25139
26245
|
const parsed = this.#parser.parsePacket(packet);
|
|
25140
26246
|
if (!parsed) return;
|
|
25141
26247
|
const info = parsed.info;
|
|
26248
|
+
if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
|
|
25142
26249
|
if (source === "multicast" && !manifestAdmitted) {
|
|
25143
26250
|
this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
|
|
25144
26251
|
}
|
|
@@ -25420,7 +26527,8 @@ var MmtpRouter = class {
|
|
|
25420
26527
|
parsed.header,
|
|
25421
26528
|
info.sequenceNumber,
|
|
25422
26529
|
info.rapFlag,
|
|
25423
|
-
source
|
|
26530
|
+
source,
|
|
26531
|
+
fecPayloadId?.ssId
|
|
25424
26532
|
);
|
|
25425
26533
|
}
|
|
25426
26534
|
}
|
|
@@ -25446,7 +26554,8 @@ var MmtpRouter = class {
|
|
|
25446
26554
|
source: parserOptions?.source,
|
|
25447
26555
|
deliveryProvenance: parserOptions?.deliveryProvenance,
|
|
25448
26556
|
catalogTrackName: parserOptions?.catalogTrackName,
|
|
25449
|
-
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn }
|
|
26557
|
+
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn },
|
|
26558
|
+
...parserOptions?.fecSbnFirst === void 0 ? {} : { fecSbnFirst: parserOptions.fecSbnFirst }
|
|
25450
26559
|
};
|
|
25451
26560
|
if (parsed) this.#parser.feedParsed(packet, parsed, feedOptions);
|
|
25452
26561
|
else this.#parser.feed(packet, feedOptions);
|
|
@@ -25570,7 +26679,8 @@ var MmtpRouter = class {
|
|
|
25570
26679
|
if (stream === void 0) {
|
|
25571
26680
|
stream = {
|
|
25572
26681
|
key: JSON.stringify([packetId, catalogTrackName ?? null]),
|
|
25573
|
-
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId))
|
|
26682
|
+
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId)),
|
|
26683
|
+
overlayToBase: { routed: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Map() }
|
|
25574
26684
|
};
|
|
25575
26685
|
byName.set(catalogTrackName, stream);
|
|
25576
26686
|
}
|
|
@@ -25685,8 +26795,16 @@ var MmtpRouter = class {
|
|
|
25685
26795
|
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
25686
26796
|
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
25687
26797
|
}
|
|
25688
|
-
#routeDirectRecoveredVideo(packetId, data, meta, cb) {
|
|
26798
|
+
#routeDirectRecoveredVideo(packetId, data, meta, cb, fecSbn) {
|
|
25689
26799
|
const streamKey = this.#mediaStreamKey(packetId, meta.catalogTrackName);
|
|
26800
|
+
if (this.#isFecTrack(packetId)) {
|
|
26801
|
+
const high = this.#deliveredVideoHighWaterByStream.get(streamKey);
|
|
26802
|
+
if (fecSbn !== void 0 || high !== void 0 && authoredAdjacent(high, meta)) {
|
|
26803
|
+
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
26804
|
+
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
26805
|
+
return;
|
|
26806
|
+
}
|
|
26807
|
+
}
|
|
25690
26808
|
this.#enqueueDirectRecoveredVideo(packetId, data, meta);
|
|
25691
26809
|
const lastSourceTs = this.#lastDirectSourceVideoTsByStream.get(streamKey);
|
|
25692
26810
|
this.#drainDirectRecoveredVideo(
|
|
@@ -25840,6 +26958,13 @@ var MmtpRouter = class {
|
|
|
25840
26958
|
* frames by epoch only if pre-protection input ever matters.
|
|
25841
26959
|
*/
|
|
25842
26960
|
#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete, assisted = false) {
|
|
26961
|
+
const overlayRouted = ownerPacketId == null ? void 0 : this.#streams.get(ownerPacketId)?.get(catalogTrackName)?.overlayToBase.routed;
|
|
26962
|
+
if (overlayRouted !== void 0 && overlayRouted.size > 0) {
|
|
26963
|
+
result = {
|
|
26964
|
+
...result,
|
|
26965
|
+
symbols: result.symbols.filter((sym) => !overlayRouted.has(this.#fecAnchorForRecovered(blockId, sym.index)))
|
|
26966
|
+
};
|
|
26967
|
+
}
|
|
25843
26968
|
const entry = ownerPacketId == null ? void 0 : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
25844
26969
|
const receiver = entry === void 0 || entry === "ambiguous" ? entry : entry.receiver;
|
|
25845
26970
|
const userAgent = !assisted && entry !== void 0 && entry !== "ambiguous" && entry.protected === true && entry.userAgent === true;
|
|
@@ -25896,7 +27021,12 @@ var MmtpRouter = class {
|
|
|
25896
27021
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, overlay) {
|
|
25897
27022
|
if (ownerPacketId == null) return;
|
|
25898
27023
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
25899
|
-
const fecSbnOf = (index) =>
|
|
27024
|
+
const fecSbnOf = (index) => {
|
|
27025
|
+
if (!overlay) return { fecSbn: this.#fecAnchorForRecovered(blockId, index) };
|
|
27026
|
+
const fecSbn = overlay.baseSsIds.get(index);
|
|
27027
|
+
const fecSbnFirst = overlay.firstSsIds.get(index);
|
|
27028
|
+
return fecSbn === void 0 || fecSbnFirst === void 0 ? {} : { fecSbn, fecSbnFirst };
|
|
27029
|
+
};
|
|
25900
27030
|
const streamKey = this.#mediaStreamKey(ownerPacketId, catalogTrackName);
|
|
25901
27031
|
const ssIdSeqOffset = overlay ? void 0 : this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
25902
27032
|
if (ssIdSeqOffset !== void 0) {
|
|
@@ -25904,7 +27034,10 @@ var MmtpRouter = class {
|
|
|
25904
27034
|
...result,
|
|
25905
27035
|
symbols: result.symbols.map((sym) => {
|
|
25906
27036
|
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
25907
|
-
if (wire === sym.packetSequenceNumber)
|
|
27037
|
+
if (wire === sym.packetSequenceNumber) {
|
|
27038
|
+
this.#unstampedSsIdSeqOffsetByStream.set(streamKey, ssIdSeqOffset);
|
|
27039
|
+
return sym;
|
|
27040
|
+
}
|
|
25908
27041
|
this.#restampedRecoveredSeqs++;
|
|
25909
27042
|
this.#restampedStreams.add(streamKey);
|
|
25910
27043
|
return { ...sym, packetSequenceNumber: wire };
|
|
@@ -25940,16 +27073,29 @@ var MmtpRouter = class {
|
|
|
25940
27073
|
}
|
|
25941
27074
|
);
|
|
25942
27075
|
}
|
|
25943
|
-
|
|
25944
|
-
|
|
25945
|
-
|
|
25946
|
-
|
|
25947
|
-
|
|
25948
|
-
|
|
25949
|
-
|
|
25950
|
-
|
|
25951
|
-
))
|
|
25952
|
-
|
|
27076
|
+
const untimedHead = (sym) => sym.fragmentType === 2 && sym.fragment.fragmentationIndicator === 1 && sym.fragment.movieFragmentSequenceNumber !== void 0 && sym.fragment.sampleNumber !== void 0 && !this.#parser.hasAuthoredTimingFor(
|
|
27077
|
+
ownerPacketId,
|
|
27078
|
+
sym.fragment.mpuSequenceNumber,
|
|
27079
|
+
sym.fragment.movieFragmentSequenceNumber,
|
|
27080
|
+
sym.fragment.sampleNumber,
|
|
27081
|
+
catalogTrackName
|
|
27082
|
+
);
|
|
27083
|
+
for (const sym of result.symbols) {
|
|
27084
|
+
if (!untimedHead(sym) || this.#sourceSeqReceived(ownerPacketId, sym.packetSequenceNumber, catalogTrackName)) continue;
|
|
27085
|
+
this.#feedViaParser(
|
|
27086
|
+
sym.rawSymbol,
|
|
27087
|
+
{ packetId: ownerPacketId, sequenceNumber: sym.packetSequenceNumber },
|
|
27088
|
+
void 0,
|
|
27089
|
+
{
|
|
27090
|
+
skipFecPayloadId: true,
|
|
27091
|
+
recovered: true,
|
|
27092
|
+
deliveryProvenance,
|
|
27093
|
+
...fecSbnOf(sym.index),
|
|
27094
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
27095
|
+
}
|
|
27096
|
+
);
|
|
27097
|
+
}
|
|
27098
|
+
result = { ...result, symbols: result.symbols.filter((sym) => !untimedHead(sym)) };
|
|
25953
27099
|
const gated = this.#isFecTrack(ownerPacketId);
|
|
25954
27100
|
const assembler = this.#mseAssemblerFor(ownerPacketId, catalogTrackName);
|
|
25955
27101
|
if (assembler) {
|
|
@@ -27676,6 +28822,12 @@ function isNonNegativeSafeInteger(value) {
|
|
|
27676
28822
|
function isSymbolCounts(value) {
|
|
27677
28823
|
return isRecord(value) && hasExactKeys(value, ["multicast", "moq"]) && isNonNegativeSafeInteger(value["multicast"]) && isNonNegativeSafeInteger(value["moq"]);
|
|
27678
28824
|
}
|
|
28825
|
+
function isSpanFailure(value) {
|
|
28826
|
+
if (!isRecord(value) || !hasExactKeys(value, ["length", "sources"])) return false;
|
|
28827
|
+
const length = value["length"];
|
|
28828
|
+
const sources = value["sources"];
|
|
28829
|
+
return Number.isSafeInteger(length) && length > 0 && isNonNegativeSafeInteger(sources) && sources < length;
|
|
28830
|
+
}
|
|
27679
28831
|
function isNullableNonNegative(value) {
|
|
27680
28832
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
27681
28833
|
}
|
|
@@ -27695,7 +28847,10 @@ function isRepairLifecycleEvent(value) {
|
|
|
27695
28847
|
case "recovered":
|
|
27696
28848
|
return hasExactKeys(value, ["version", "type", "block", "blockClass", "via", "symbols"]) && isRepairBlockIdentity(block) && BLOCK_CLASSES.has(value["blockClass"]) && (value["via"] === "inband" || value["via"] === "quic") && isSymbolCounts(value["symbols"]);
|
|
27697
28849
|
case "failed":
|
|
27698
|
-
return hasExactKeys(
|
|
28850
|
+
return hasExactKeys(
|
|
28851
|
+
value,
|
|
28852
|
+
"span" in value ? ["version", "type", "block", "blockClass", "symbols", "span"] : ["version", "type", "block", "blockClass", "symbols"]
|
|
28853
|
+
) && isRepairBlockIdentity(block) && BLOCK_CLASSES.has(value["blockClass"]) && isSymbolCounts(value["symbols"]) && (!("span" in value) || isSpanFailure(value["span"]));
|
|
27699
28854
|
case "repair-preempted":
|
|
27700
28855
|
case "repair-deferred":
|
|
27701
28856
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
@@ -27904,6 +29059,8 @@ var MulticastManager = class {
|
|
|
27904
29059
|
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
27905
29060
|
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
27906
29061
|
#repairReleases = /* @__PURE__ */ new Map();
|
|
29062
|
+
/** Protected repair flows owned by each live repair-endpoint release. */
|
|
29063
|
+
#repairProvenanceFlows = /* @__PURE__ */ new Map();
|
|
27907
29064
|
/** Each source's catalog keyframe overlay, from its `ok` binding. */
|
|
27908
29065
|
#overlayBindings = /* @__PURE__ */ new Map();
|
|
27909
29066
|
/** Installed overlay decoders (`setKeyframeOverlayDecoder`), by source. */
|
|
@@ -27961,7 +29118,7 @@ var MulticastManager = class {
|
|
|
27961
29118
|
onPublisherRestart: (packetId, catalogTrackName) => {
|
|
27962
29119
|
this.#resetStreamOutsideRouter(packetId, catalogTrackName);
|
|
27963
29120
|
},
|
|
27964
|
-
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass) => {
|
|
29121
|
+
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
27965
29122
|
const pathCount = this.#fec.blockPathCount(
|
|
27966
29123
|
sbn,
|
|
27967
29124
|
packetId,
|
|
@@ -27979,7 +29136,8 @@ var MulticastManager = class {
|
|
|
27979
29136
|
symbols: {
|
|
27980
29137
|
multicast: pathCount?.multicastSymbols ?? 0,
|
|
27981
29138
|
moq: pathCount?.moqSymbols ?? 0
|
|
27982
|
-
}
|
|
29139
|
+
},
|
|
29140
|
+
...span === void 0 ? {} : { span }
|
|
27983
29141
|
});
|
|
27984
29142
|
},
|
|
27985
29143
|
onFrameGap: (decision) => {
|
|
@@ -28067,6 +29225,11 @@ var MulticastManager = class {
|
|
|
28067
29225
|
this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
|
|
28068
29226
|
this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
|
|
28069
29227
|
};
|
|
29228
|
+
this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
|
|
29229
|
+
const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
|
|
29230
|
+
if (binding === void 0) return void 0;
|
|
29231
|
+
return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
|
|
29232
|
+
};
|
|
28070
29233
|
this.#fec.onDecoderUnavailable = (event) => {
|
|
28071
29234
|
this.#emitRepairLifecycle({
|
|
28072
29235
|
version: 2,
|
|
@@ -28569,6 +29732,9 @@ var MulticastManager = class {
|
|
|
28569
29732
|
this.#transport.onFailback((reason) => {
|
|
28570
29733
|
const joined = this.#provenanceJoin;
|
|
28571
29734
|
if (joined !== null) this.#router.unprotectProvenanceFlow(joined.flow);
|
|
29735
|
+
for (const flows of this.#repairProvenanceFlows.values()) {
|
|
29736
|
+
for (const flow of flows) this.#router.unprotectProvenanceFlow(flow);
|
|
29737
|
+
}
|
|
28572
29738
|
this.#onFailback?.(reason);
|
|
28573
29739
|
});
|
|
28574
29740
|
}
|
|
@@ -28603,6 +29769,12 @@ var MulticastManager = class {
|
|
|
28603
29769
|
"[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port"
|
|
28604
29770
|
);
|
|
28605
29771
|
}
|
|
29772
|
+
if (provenanceFlow !== void 0) {
|
|
29773
|
+
const flow = multicastProvenanceFlowKey(provenanceFlow);
|
|
29774
|
+
if ([...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
29775
|
+
throw new TypeError(`[MulticastManager] join: provenance flow already registered by a repair endpoint: ${flow}`);
|
|
29776
|
+
}
|
|
29777
|
+
}
|
|
28606
29778
|
const staged = this.#renditionSwitch;
|
|
28607
29779
|
if (staged !== null) this.#endRenditionSwitch(staged, { reason: "superseded" }, false);
|
|
28608
29780
|
this.configureFec(config);
|
|
@@ -28610,8 +29782,8 @@ var MulticastManager = class {
|
|
|
28610
29782
|
const selectedPacketIds = config.packetIds?.length ? new Set(config.packetIds) : null;
|
|
28611
29783
|
const catalogTracks = config.tracks?.filter(({ packetId }) => selectedPacketIds === null || selectedPacketIds.has(packetId));
|
|
28612
29784
|
const ingressTracks = catalogTracks ? catalogTracks : selectedPacketIds === null ? void 0 : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
|
|
28613
|
-
this.#releaseProvenanceJoin();
|
|
28614
29785
|
const provenance = config.provenance;
|
|
29786
|
+
this.#releaseProvenanceJoin();
|
|
28615
29787
|
const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
|
|
28616
29788
|
const ingress = protectedTracks === void 0 ? void 0 : {
|
|
28617
29789
|
tracks: Object.freeze(
|
|
@@ -28664,8 +29836,13 @@ var MulticastManager = class {
|
|
|
28664
29836
|
* feeds the flow's receiver; media datagrams are held until one admits them.
|
|
28665
29837
|
*/
|
|
28666
29838
|
#joinProvenance(provenance, ingress) {
|
|
29839
|
+
this.#router.registerProvenanceFlow(ingress, this.#provenanceReceiver(provenance));
|
|
29840
|
+
this.#hookFailback();
|
|
29841
|
+
this.#provenanceJoin = { flow: ingress.flow };
|
|
29842
|
+
}
|
|
29843
|
+
#provenanceReceiver(provenance) {
|
|
28667
29844
|
const { flow, auth } = provenance;
|
|
28668
|
-
|
|
29845
|
+
return new BcProvenanceV2Receiver({
|
|
28669
29846
|
...provenance.receiver,
|
|
28670
29847
|
// The caller's ctx when it passes one, else the catalog's: an explicit
|
|
28671
29848
|
// `catalogCtx: undefined` must not switch off the 7.2.4 ctx check.
|
|
@@ -28682,9 +29859,6 @@ var MulticastManager = class {
|
|
|
28682
29859
|
maxAuthDelayMs: flow.maxAuthDelayMs,
|
|
28683
29860
|
manifestTimerMs: flow.manifestTimerMs
|
|
28684
29861
|
});
|
|
28685
|
-
this.#router.registerProvenanceFlow(ingress, receiver);
|
|
28686
|
-
this.#hookFailback();
|
|
28687
|
-
this.#provenanceJoin = { flow: ingress.flow };
|
|
28688
29862
|
}
|
|
28689
29863
|
/** Un-protect: drop the flow's hold queues (no expiry counted). */
|
|
28690
29864
|
#releaseProvenanceJoin() {
|
|
@@ -28715,8 +29889,25 @@ var MulticastManager = class {
|
|
|
28715
29889
|
* callback delivers must come from a subscription opened on
|
|
28716
29890
|
* `options.gateway`. A callback that also merges another source (a MoQ or
|
|
28717
29891
|
* WebSocket repair feed) must not name a native provider here.
|
|
29892
|
+
*
|
|
29893
|
+
* An endpoint's `provenance` makes its group a protected flow of its own
|
|
29894
|
+
* (multicast-02 7.2.7), registered here and released with the group; its
|
|
29895
|
+
* records ride in band on the group's port. On the user-agent path a
|
|
29896
|
+
* flow-less repair group of a protected track is set aside, never read, so
|
|
29897
|
+
* a player joining a protected catalog's repair groups passes it.
|
|
28718
29898
|
*/
|
|
28719
29899
|
joinRepairEndpoints(endpoints, provider, options) {
|
|
29900
|
+
for (const { provenance, flow, source, group, port: port2 } of endpoints) {
|
|
29901
|
+
if (provenance === void 0) continue;
|
|
29902
|
+
if (flow !== void 0) {
|
|
29903
|
+
throw new TypeError("[MulticastManager] joinRepairEndpoints: an endpoint names provenance or flow, never both");
|
|
29904
|
+
}
|
|
29905
|
+
if (!sameIpAddress(source, provenance.flow.source) || !sameIpAddress(group, provenance.flow.groupAddress) || port2 !== provenance.flow.port) {
|
|
29906
|
+
throw new RangeError(
|
|
29907
|
+
"[MulticastManager] joinRepairEndpoints: provenance flow (S, G, port) must match the endpoint's source, group and port"
|
|
29908
|
+
);
|
|
29909
|
+
}
|
|
29910
|
+
}
|
|
28720
29911
|
const releases = [];
|
|
28721
29912
|
let released = false;
|
|
28722
29913
|
const safely = (each) => {
|
|
@@ -28726,17 +29917,36 @@ var MulticastManager = class {
|
|
|
28726
29917
|
console.warn("[MulticastManager] repair group release failed", error);
|
|
28727
29918
|
}
|
|
28728
29919
|
};
|
|
29920
|
+
const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
|
|
29921
|
+
const preparedProvenance = endpoints.map((endpoint) => {
|
|
29922
|
+
if (endpoint.provenance === void 0) return void 0;
|
|
29923
|
+
const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
29924
|
+
if (usedFlows.has(flow) || this.#provenanceJoin?.flow === flow || [...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
29925
|
+
throw new TypeError(`[MulticastManager] joinRepairEndpoints: provenance flow already registered: ${flow}`);
|
|
29926
|
+
}
|
|
29927
|
+
usedFlows.add(flow);
|
|
29928
|
+
return { flow, receiver: this.#provenanceReceiver(endpoint.provenance) };
|
|
29929
|
+
});
|
|
29930
|
+
const provenanceFlows = [];
|
|
28729
29931
|
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners.map((owner) => owner.instance !== "keyframe" ? owner : {
|
|
28730
29932
|
...owner,
|
|
28731
29933
|
ownerTrackName: endpoint.tracks.find((t) => t.packetId === owner.ownerPacketId)?.name,
|
|
28732
29934
|
repairTrackName: endpoint.tracks.find((t) => t.packetId === owner.packetId)?.name
|
|
28733
29935
|
}));
|
|
28734
29936
|
this.#applyRepairOwners(repairOwners);
|
|
28735
|
-
for (const endpoint of endpoints) {
|
|
29937
|
+
for (const [index, endpoint] of endpoints.entries()) {
|
|
29938
|
+
const flow = endpoint.provenance === void 0 ? endpoint.flow : multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
28736
29939
|
const ingress = {
|
|
28737
29940
|
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
|
|
28738
|
-
...
|
|
29941
|
+
...flow === void 0 ? {} : { flow }
|
|
28739
29942
|
};
|
|
29943
|
+
if (endpoint.provenance !== void 0) {
|
|
29944
|
+
const prepared = preparedProvenance[index];
|
|
29945
|
+
if (prepared === void 0) throw new Error("[MulticastManager] repair provenance preparation missing");
|
|
29946
|
+
this.#router.registerProvenanceFlow(ingress, prepared.receiver);
|
|
29947
|
+
provenanceFlows.push(prepared.flow);
|
|
29948
|
+
releases.push(() => this.#router.releaseProvenanceFlow(flow));
|
|
29949
|
+
}
|
|
28740
29950
|
let sender;
|
|
28741
29951
|
const feed = (packet, sourceAddress, ingressToFeed) => {
|
|
28742
29952
|
if (released) return;
|
|
@@ -28766,7 +29976,7 @@ var MulticastManager = class {
|
|
|
28766
29976
|
packetIds: endpoint.packetIds,
|
|
28767
29977
|
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
|
|
28768
29978
|
// A protected repair group's records ride in band on its port (7.2.3).
|
|
28769
|
-
...
|
|
29979
|
+
...flow === void 0 ? {} : { protected: true }
|
|
28770
29980
|
}, ingress).then((joined) => {
|
|
28771
29981
|
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
28772
29982
|
});
|
|
@@ -28775,9 +29985,12 @@ var MulticastManager = class {
|
|
|
28775
29985
|
if (released) return;
|
|
28776
29986
|
released = true;
|
|
28777
29987
|
this.#repairReleases.delete(release);
|
|
29988
|
+
this.#repairProvenanceFlows.delete(release);
|
|
28778
29989
|
for (const each of releases.splice(0)) safely(each);
|
|
28779
29990
|
};
|
|
28780
29991
|
this.#repairReleases.set(release, repairOwners);
|
|
29992
|
+
this.#repairProvenanceFlows.set(release, provenanceFlows);
|
|
29993
|
+
if (provenanceFlows.length) this.#hookFailback();
|
|
28781
29994
|
return release;
|
|
28782
29995
|
}
|
|
28783
29996
|
#applyRepairOwners(owners) {
|
|
@@ -29263,7 +30476,8 @@ var MulticastManager = class {
|
|
|
29263
30476
|
blockProfile: parseFecBlockProfile(
|
|
29264
30477
|
geometry2.blockProfile,
|
|
29265
30478
|
`tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
|
|
29266
|
-
)
|
|
30479
|
+
),
|
|
30480
|
+
geometry: geometry2
|
|
29267
30481
|
});
|
|
29268
30482
|
}
|
|
29269
30483
|
}
|
|
@@ -29302,7 +30516,7 @@ var MulticastManager = class {
|
|
|
29302
30516
|
for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
|
|
29303
30517
|
const before = this.#overlayBindings.get(sourcePacketId);
|
|
29304
30518
|
const after = overlayBindings.get(sourcePacketId);
|
|
29305
|
-
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
|
|
30519
|
+
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
|
|
29306
30520
|
if (!same) install.dispose();
|
|
29307
30521
|
else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
|
|
29308
30522
|
else install.reattach();
|
|
@@ -29359,10 +30573,12 @@ var MulticastManager = class {
|
|
|
29359
30573
|
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
29360
30574
|
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
29361
30575
|
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
29362
|
-
* once its range FETCH ends (or none is sent).
|
|
30576
|
+
* once its range FETCH ends (or none is sent). `onExpired` is told of a
|
|
30577
|
+
* pending hole the stream runs past the locator's horizon: returning true,
|
|
30578
|
+
* the caller closes it (`closeIsoHoles`); otherwise it is discarded.
|
|
29363
30579
|
*/
|
|
29364
|
-
onUndelimitedLoss(cb) {
|
|
29365
|
-
this.#fec.setUndelimitedLossHandler(cb);
|
|
30580
|
+
onUndelimitedLoss(cb, onExpired) {
|
|
30581
|
+
this.#fec.setUndelimitedLossHandler(cb, onExpired ?? null);
|
|
29366
30582
|
}
|
|
29367
30583
|
/**
|
|
29368
30584
|
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
@@ -29598,7 +30814,8 @@ var MulticastManager = class {
|
|
|
29598
30814
|
"stream" in event ? { ...event, stream: Object.freeze({ ...event.stream }) } : {
|
|
29599
30815
|
...event,
|
|
29600
30816
|
block: Object.freeze({ ...event.block }),
|
|
29601
|
-
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {}
|
|
30817
|
+
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {},
|
|
30818
|
+
..."span" in event && event.span !== void 0 ? { span: Object.freeze({ ...event.span }) } : {}
|
|
29602
30819
|
}
|
|
29603
30820
|
);
|
|
29604
30821
|
if (this.#logRepairLifecycle) {
|
|
@@ -32270,6 +33487,7 @@ var RepairLayerSubscriptions = class {
|
|
|
32270
33487
|
|
|
32271
33488
|
// src/repair-fetch.ts
|
|
32272
33489
|
var MOQT_PRIORITY_MAX = 255;
|
|
33490
|
+
var WALK_LEAD_MS = 3;
|
|
32273
33491
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
32274
33492
|
function isMoqtPriority(value) {
|
|
32275
33493
|
return Number.isSafeInteger(value) && value >= 0 && value <= MOQT_PRIORITY_MAX;
|
|
@@ -32320,8 +33538,17 @@ function wireRepairFetch(mc, opts) {
|
|
|
32320
33538
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
32321
33539
|
};
|
|
32322
33540
|
const clearEntry = (entry) => {
|
|
32323
|
-
|
|
32324
|
-
|
|
33541
|
+
const { range } = entry;
|
|
33542
|
+
if (range) {
|
|
33543
|
+
atReport(range, () => mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, range.holeLength));
|
|
33544
|
+
} else {
|
|
33545
|
+
clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
33546
|
+
}
|
|
33547
|
+
};
|
|
33548
|
+
const atReport = (range, work) => {
|
|
33549
|
+
const fec = mc.fecManager;
|
|
33550
|
+
if (range.groups !== null || fec.withReceiptTime === void 0) work();
|
|
33551
|
+
else fec.withReceiptTime(range.reportedAt, work);
|
|
32325
33552
|
};
|
|
32326
33553
|
const releaseHold = (entry) => {
|
|
32327
33554
|
if (entry.range) return;
|
|
@@ -32333,7 +33560,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32333
33560
|
if (!run) return;
|
|
32334
33561
|
entry.running = null;
|
|
32335
33562
|
run.stopped = reason;
|
|
32336
|
-
run.controller.abort();
|
|
33563
|
+
run.controller.abort(reason);
|
|
32337
33564
|
if (reason === "preempted") releaseHold(entry);
|
|
32338
33565
|
mc.noteRepairStopped?.(reason, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
32339
33566
|
};
|
|
@@ -32388,21 +33615,42 @@ function wireRepairFetch(mc, opts) {
|
|
|
32388
33615
|
const admit = (entry, now) => {
|
|
32389
33616
|
const budgetMs = entry.deadlineAt - now;
|
|
32390
33617
|
const rttMs = readRtt();
|
|
32391
|
-
const reason =
|
|
33618
|
+
const reason = refusal(entry, now, rttMs);
|
|
32392
33619
|
if (reason === null) return rttMs;
|
|
32393
33620
|
skip(entry, reason, rttMs, budgetMs);
|
|
32394
33621
|
return null;
|
|
32395
33622
|
};
|
|
33623
|
+
const refusal = (entry, now, rttMs) => !entry.range && !groupCanComplete(entry.sbn, entry.packetId, entry.catalogTrackName) ? "group-cannot-complete" : rttMs === null ? "rtt-unmeasured" : rttMs < entry.deadlineAt - now ? null : "rtt-exceeds-budget";
|
|
32396
33624
|
const retire = (entry) => {
|
|
32397
33625
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
32398
33626
|
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
32399
33627
|
};
|
|
32400
|
-
const
|
|
33628
|
+
const holdsBack = (entry, priority, videoWalks = true) => {
|
|
33629
|
+
if (entry.priority >= priority) return false;
|
|
33630
|
+
const { walk } = entry;
|
|
33631
|
+
if (walk === void 0) return true;
|
|
33632
|
+
if (entry.priority !== 0 || !videoWalks) return false;
|
|
33633
|
+
return entry.running === null || walk.group !== null && !walk.group.controller.signal.aborted;
|
|
33634
|
+
};
|
|
33635
|
+
const outstandingBelow = (priority, videoWalks = true) => {
|
|
32401
33636
|
for (const entry of entries.values()) {
|
|
32402
|
-
if (entry
|
|
33637
|
+
if (holdsBack(entry, priority, videoWalks)) return true;
|
|
32403
33638
|
}
|
|
32404
33639
|
return false;
|
|
32405
33640
|
};
|
|
33641
|
+
const yieldVideoWalks = (queued) => {
|
|
33642
|
+
const now = performance.now();
|
|
33643
|
+
const rttMs = readRtt();
|
|
33644
|
+
const due = queued.some((entry) => entry.priority !== 0 && entry.walk === void 0 && !outstandingBelow(entry.priority, false) && refusal(entry, now, rttMs) === null);
|
|
33645
|
+
if (!due) return;
|
|
33646
|
+
for (const entry of entries.values()) {
|
|
33647
|
+
const walk = entry.walk;
|
|
33648
|
+
if (entry.priority !== 0 || walk === void 0 || walk.group === null) continue;
|
|
33649
|
+
if (walk.group.controller.signal.aborted) continue;
|
|
33650
|
+
walk.yielded = true;
|
|
33651
|
+
walk.group.controller.abort();
|
|
33652
|
+
}
|
|
33653
|
+
};
|
|
32406
33654
|
const preemptBestEffort = () => {
|
|
32407
33655
|
for (const entry of entries.values()) {
|
|
32408
33656
|
if (entry.priority === 0 || !entry.running) continue;
|
|
@@ -32431,7 +33679,8 @@ function wireRepairFetch(mc, opts) {
|
|
|
32431
33679
|
}
|
|
32432
33680
|
const rttMs = admit(entry, now);
|
|
32433
33681
|
if (rttMs === null) return;
|
|
32434
|
-
if (entry.priority === 0) preemptBestEffort();
|
|
33682
|
+
if (entry.priority === 0 && entry.walk === void 0) preemptBestEffort();
|
|
33683
|
+
if (entry.range === void 0) leaveWalkedGroup(entry);
|
|
32435
33684
|
if (counted) entry.attempts++;
|
|
32436
33685
|
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
32437
33686
|
rttMs,
|
|
@@ -32453,6 +33702,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
32453
33702
|
}
|
|
32454
33703
|
void execute(entry, run);
|
|
32455
33704
|
};
|
|
33705
|
+
const leaveWalkedGroup = (block) => {
|
|
33706
|
+
for (const entry of entries.values()) {
|
|
33707
|
+
const group = entry.walk?.group;
|
|
33708
|
+
if (group?.sbn === block.sbn && entry.packetId === block.packetId && entry.catalogTrackName === block.catalogTrackName) {
|
|
33709
|
+
group.controller.abort();
|
|
33710
|
+
}
|
|
33711
|
+
}
|
|
33712
|
+
};
|
|
32456
33713
|
const dispatch = () => {
|
|
32457
33714
|
if (disposed) return;
|
|
32458
33715
|
const now = performance.now();
|
|
@@ -32477,6 +33734,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32477
33734
|
for (const entry of queued) {
|
|
32478
33735
|
if (entry.priority === 0) start(entry);
|
|
32479
33736
|
}
|
|
33737
|
+
yieldVideoWalks(queued);
|
|
32480
33738
|
if (outstandingBelow(1)) return;
|
|
32481
33739
|
for (const entry of queued) {
|
|
32482
33740
|
if (entry.priority === 1) start(entry);
|
|
@@ -32503,6 +33761,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
32503
33761
|
}
|
|
32504
33762
|
return counts.sources + counts.repairGroupLength >= counts.authoredLength;
|
|
32505
33763
|
};
|
|
33764
|
+
const groupServed = (sbn, packetId, catalogTrackName) => {
|
|
33765
|
+
if (mc.fecManager.blockSymbolCounts === void 0) return false;
|
|
33766
|
+
const counts = symbolCounts(sbn, packetId, catalogTrackName);
|
|
33767
|
+
if (counts === void 0 || counts.authoredLength === void 0) return true;
|
|
33768
|
+
return counts.sources + counts.repairs >= counts.authoredLength || !groupCanComplete(sbn, packetId, catalogTrackName);
|
|
33769
|
+
};
|
|
33770
|
+
const statedEnd = (sbn, packetId, catalogTrackName) => {
|
|
33771
|
+
const length = symbolCounts(sbn, packetId, catalogTrackName)?.authoredLength;
|
|
33772
|
+
return length === void 0 ? void 0 : serial32Add(sbn, length);
|
|
33773
|
+
};
|
|
32506
33774
|
const finish = (entry, run, fed, error) => {
|
|
32507
33775
|
if (run.stopped !== null || entry.running !== run || entries.get(entry.key) !== entry) {
|
|
32508
33776
|
return;
|
|
@@ -32547,27 +33815,81 @@ function wireRepairFetch(mc, opts) {
|
|
|
32547
33815
|
signal: run.controller.signal,
|
|
32548
33816
|
subscriberPriority: entry.subscriberPriority
|
|
32549
33817
|
};
|
|
33818
|
+
const { range } = entry;
|
|
33819
|
+
const feed = (packet) => {
|
|
33820
|
+
if (entry.catalogTrackName === void 0) {
|
|
33821
|
+
mc.processRepairFromMoQ(packet, entry.packetId);
|
|
33822
|
+
} else {
|
|
33823
|
+
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
33824
|
+
}
|
|
33825
|
+
};
|
|
32550
33826
|
try {
|
|
32551
|
-
const packets = entry.
|
|
33827
|
+
const packets = range === void 0 ? opts.transport({ ...common, sbn: entry.sbn }) : entry.walk !== void 0 ? walkHole(entry, entry.walk, range, common) : opts.rangeTransport({
|
|
32552
33828
|
...common,
|
|
32553
|
-
startGroup:
|
|
32554
|
-
endGroup:
|
|
32555
|
-
lostSsId:
|
|
32556
|
-
})
|
|
33829
|
+
startGroup: range.groups.startGroup,
|
|
33830
|
+
endGroup: range.groups.endGroup,
|
|
33831
|
+
lostSsId: range.lostSsId
|
|
33832
|
+
});
|
|
32557
33833
|
for await (const packet of packets) {
|
|
32558
33834
|
if (run.stopped !== null || entry.running !== run) break;
|
|
32559
33835
|
fed++;
|
|
32560
|
-
if (
|
|
32561
|
-
|
|
32562
|
-
} else {
|
|
32563
|
-
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
32564
|
-
}
|
|
33836
|
+
if (range === void 0) feed(packet);
|
|
33837
|
+
else atReport(range, () => feed(packet));
|
|
32565
33838
|
}
|
|
32566
33839
|
finish(entry, run, fed, void 0);
|
|
32567
33840
|
} catch (error) {
|
|
32568
33841
|
finish(entry, run, fed, error ?? new Error("repair transport rejected"));
|
|
32569
33842
|
}
|
|
32570
33843
|
};
|
|
33844
|
+
async function* walkHole(entry, walk, hole, common) {
|
|
33845
|
+
const lostAt = serial32Distance(entry.sbn, hole.lostSsId);
|
|
33846
|
+
for (let first = true; !common.signal.aborted; first = false) {
|
|
33847
|
+
if (!first && entry.priority !== 0 && outstandingBelow(1)) {
|
|
33848
|
+
stop(entry, "preempted");
|
|
33849
|
+
note("repair-preempted", entry);
|
|
33850
|
+
return;
|
|
33851
|
+
}
|
|
33852
|
+
if (!first && entry.priority === 0) {
|
|
33853
|
+
dispatch();
|
|
33854
|
+
if (common.signal.aborted) return;
|
|
33855
|
+
}
|
|
33856
|
+
const sbn = walk.next;
|
|
33857
|
+
let next;
|
|
33858
|
+
if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
|
|
33859
|
+
const rsIds = /* @__PURE__ */ new Set();
|
|
33860
|
+
const group = new AbortController();
|
|
33861
|
+
const cancel = () => group.abort(common.signal.reason);
|
|
33862
|
+
common.signal.addEventListener("abort", cancel, { once: true });
|
|
33863
|
+
walk.group = { sbn, controller: group };
|
|
33864
|
+
try {
|
|
33865
|
+
for await (const packet of opts.transport({ ...common, sbn, signal: group.signal })) {
|
|
33866
|
+
yield packet;
|
|
33867
|
+
const id = extractRepairFecPayloadId(packet);
|
|
33868
|
+
if (id === null || id.ssStart !== sbn || id.ssbLength === 0) continue;
|
|
33869
|
+
next ??= serial32Add(sbn, id.ssbLength);
|
|
33870
|
+
rsIds.add(id.rsId);
|
|
33871
|
+
if (rsIds.size >= id.rsbLength || groupServed(sbn, entry.packetId, entry.catalogTrackName)) {
|
|
33872
|
+
group.abort();
|
|
33873
|
+
break;
|
|
33874
|
+
}
|
|
33875
|
+
}
|
|
33876
|
+
} catch (error) {
|
|
33877
|
+
if (!group.signal.aborted || common.signal.aborted) throw error;
|
|
33878
|
+
} finally {
|
|
33879
|
+
common.signal.removeEventListener("abort", cancel);
|
|
33880
|
+
walk.group = null;
|
|
33881
|
+
}
|
|
33882
|
+
if (walk.yielded) {
|
|
33883
|
+
walk.yielded = false;
|
|
33884
|
+
continue;
|
|
33885
|
+
}
|
|
33886
|
+
}
|
|
33887
|
+
next ??= statedEnd(sbn, entry.packetId, entry.catalogTrackName);
|
|
33888
|
+
if (next === void 0) return;
|
|
33889
|
+
if (serial32Distance(entry.sbn, next) > lostAt) return;
|
|
33890
|
+
walk.next = next;
|
|
33891
|
+
}
|
|
33892
|
+
}
|
|
32571
33893
|
const removeResetObserver = mc.addTrackResetObserver((packetId, catalogTrackName) => {
|
|
32572
33894
|
for (const entry of [...entries.values()]) {
|
|
32573
33895
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
@@ -32763,7 +34085,37 @@ function wireRepairFetch(mc, opts) {
|
|
|
32763
34085
|
throw error;
|
|
32764
34086
|
}
|
|
32765
34087
|
};
|
|
32766
|
-
|
|
34088
|
+
const trackKind = (packetId) => {
|
|
34089
|
+
try {
|
|
34090
|
+
return mc.fecManager.trackKindFor?.(packetId);
|
|
34091
|
+
} catch {
|
|
34092
|
+
return void 0;
|
|
34093
|
+
}
|
|
34094
|
+
};
|
|
34095
|
+
const walkDeadlineAt = (packetId, now, deadlineAt) => {
|
|
34096
|
+
let repairDeadlineMs;
|
|
34097
|
+
try {
|
|
34098
|
+
repairDeadlineMs = mc.fecManager.repairDeadlineMsForPacket?.(packetId);
|
|
34099
|
+
} catch {
|
|
34100
|
+
repairDeadlineMs = void 0;
|
|
34101
|
+
}
|
|
34102
|
+
if (repairDeadlineMs === void 0 || !Number.isFinite(repairDeadlineMs)) return deadlineAt;
|
|
34103
|
+
return Math.min(deadlineAt, now + repairDeadlineMs - WALK_LEAD_MS);
|
|
34104
|
+
};
|
|
34105
|
+
const onHoleExpired = (hole) => {
|
|
34106
|
+
if (disposed) return false;
|
|
34107
|
+
const entry = [...entries.values()].find((candidate) => candidate.walk !== void 0 && candidate.packetId === hole.packetId && candidate.catalogTrackName === hole.catalogTrackName && serial32Distance(candidate.sbn, hole.holeStart) < candidate.range.holeLength);
|
|
34108
|
+
if (entry === void 0) return false;
|
|
34109
|
+
queueMicrotask(() => {
|
|
34110
|
+
if (entries.get(entry.key) !== entry) return;
|
|
34111
|
+
retire(entry);
|
|
34112
|
+
stop(entry, "expired");
|
|
34113
|
+
clearEntry(entry);
|
|
34114
|
+
dispatch();
|
|
34115
|
+
});
|
|
34116
|
+
return true;
|
|
34117
|
+
};
|
|
34118
|
+
if (mc.onUndelimitedLoss !== void 0 && mc.closeIsoHoles !== void 0) {
|
|
32767
34119
|
mc.onUndelimitedLoss((loss) => {
|
|
32768
34120
|
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
32769
34121
|
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
@@ -32771,9 +34123,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
32771
34123
|
const blockProfile = blockProfileOf(packetId);
|
|
32772
34124
|
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
32773
34125
|
if (!target) return close();
|
|
32774
|
-
const
|
|
32775
|
-
const
|
|
32776
|
-
|
|
34126
|
+
const walked = opts.rangeTransport === void 0;
|
|
34127
|
+
const holeClass = walked && trackKind(packetId) === "audio" ? "audio" : "unknown";
|
|
34128
|
+
const priority = repairPriorityForClass(holeClass);
|
|
34129
|
+
const groups = walked ? null : rangeFor(loss, target.repairTrack);
|
|
34130
|
+
if (!walked && groups === null) {
|
|
32777
34131
|
close();
|
|
32778
34132
|
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
32779
34133
|
return;
|
|
@@ -32784,8 +34138,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
32784
34138
|
packetId,
|
|
32785
34139
|
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
32786
34140
|
};
|
|
32787
|
-
const wire = wirePriority(identity,
|
|
32788
|
-
|
|
34141
|
+
const wire = wirePriority(identity, holeClass);
|
|
34142
|
+
if (wire === null) return close();
|
|
34143
|
+
const now = performance.now();
|
|
34144
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, now, holeClass);
|
|
32789
34145
|
if (deadline === null) {
|
|
32790
34146
|
close();
|
|
32791
34147
|
mc.noteRepairSkipped(
|
|
@@ -32797,6 +34153,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32797
34153
|
);
|
|
32798
34154
|
return;
|
|
32799
34155
|
}
|
|
34156
|
+
const deadlineAt = walked ? walkDeadlineAt(packetId, now, deadline.deadlineAt) : deadline.deadlineAt;
|
|
32800
34157
|
const entry = {
|
|
32801
34158
|
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
32802
34159
|
...identity,
|
|
@@ -32804,15 +34161,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
32804
34161
|
blockProfile,
|
|
32805
34162
|
priority,
|
|
32806
34163
|
subscriberPriority: wire.subscriberPriority,
|
|
32807
|
-
deadlineAt
|
|
32808
|
-
playoutDeadlineAt:
|
|
34164
|
+
deadlineAt,
|
|
34165
|
+
playoutDeadlineAt: deadlineAt - deadline.extensionMs,
|
|
32809
34166
|
anchorAt: deadline.anchorAt,
|
|
32810
34167
|
delayMs: deadline.delayMs,
|
|
32811
34168
|
bound: deadline.bound,
|
|
32812
34169
|
order: enqueueOrder++,
|
|
32813
34170
|
attempts: 0,
|
|
32814
34171
|
running: null,
|
|
32815
|
-
range: {
|
|
34172
|
+
range: { lostSsId: loss.lostSsId, holeLength, groups, reportedAt: now },
|
|
34173
|
+
...walked ? { walk: { next: holeStart, group: null, yielded: false } } : {}
|
|
32816
34174
|
};
|
|
32817
34175
|
const previous = entries.get(entry.key);
|
|
32818
34176
|
if (previous) {
|
|
@@ -32822,7 +34180,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32822
34180
|
entries.set(entry.key, entry);
|
|
32823
34181
|
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
32824
34182
|
dispatch();
|
|
32825
|
-
});
|
|
34183
|
+
}, onHoleExpired);
|
|
32826
34184
|
}
|
|
32827
34185
|
const removeRapObserver = mc.addRapCompleteObserver?.((packetId) => {
|
|
32828
34186
|
queueMicrotask(() => {
|
|
@@ -33036,6 +34394,7 @@ export {
|
|
|
33036
34394
|
resolveGroupDurationMs,
|
|
33037
34395
|
resolveGroupDurationTicks,
|
|
33038
34396
|
resolveRepairLayers,
|
|
34397
|
+
runtimeFecCatalogReport,
|
|
33039
34398
|
secondsFromTicks,
|
|
33040
34399
|
setupFecWorkerForTrack,
|
|
33041
34400
|
setupTrackPipeline,
|