@blockcast/mmt-container 2.2.0-main.efb4fa4521af → 2.2.0-main.f112316e5f40
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 +29 -17
- package/dist/browser-runtime.js +1685 -319
- package/dist/browser-runtime.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +17 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +15 -0
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmcd-producer.d.ts +60 -47
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +138 -109
- package/dist/cmcd-producer.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 +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js.map +1 -1
- package/dist/fec-manager.d.ts +114 -15
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +535 -63
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -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/mmtp-container-parser.d.ts +106 -12
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +312 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +319 -31
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +311 -27
- package/dist/mmtp-decode-pipeline.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 +703 -80
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-manager.d.ts +26 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1328 -162
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +28 -18
- package/dist/multicast-transport.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 +319 -30
- 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.d.ts +6 -2
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +6 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- 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-mmtp-container-parser.js +311 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/src/catalog-fec-params.ts +36 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +609 -37
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +9 -2
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +353 -32
- package/src/mmtp-router.ts +604 -38
- package/src/multicast-manager.ts +136 -16
- package/src/no-modules.ts +3 -0
- package/src/repair-fetch.ts +366 -50
- package/src/repair-layer-subscriptions.ts +13 -5
- package/src/track-session.ts +4 -1
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
|
}
|
|
@@ -6088,9 +6099,10 @@ function isH264IntraSlice(nal) {
|
|
|
6088
6099
|
const sliceType = readH264SliceType(nal);
|
|
6089
6100
|
return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
|
|
6090
6101
|
}
|
|
6102
|
+
var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
|
|
6091
6103
|
function readH264SliceType(nal) {
|
|
6092
6104
|
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
6093
|
-
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
6105
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
|
|
6094
6106
|
const state = { bitOffset: 0 };
|
|
6095
6107
|
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
6096
6108
|
return readUnsignedExpGolomb(rbsp, state);
|
|
@@ -6459,6 +6471,96 @@ if (void 0) {
|
|
|
6459
6471
|
]))).toBe(false);
|
|
6460
6472
|
});
|
|
6461
6473
|
});
|
|
6474
|
+
describe("readH264SliceType", () => {
|
|
6475
|
+
const wholeNalSliceType = (nal) => {
|
|
6476
|
+
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
6477
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
6478
|
+
const state = { bitOffset: 0 };
|
|
6479
|
+
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
6480
|
+
return readUnsignedExpGolomb(rbsp, state);
|
|
6481
|
+
};
|
|
6482
|
+
const hex3 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
|
|
6483
|
+
const ue = (value) => {
|
|
6484
|
+
const code = (value + 1).toString(2);
|
|
6485
|
+
return "0".repeat(code.length - 1) + code;
|
|
6486
|
+
};
|
|
6487
|
+
const sliceNal = (bits) => {
|
|
6488
|
+
const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
|
|
6489
|
+
const nal = [1];
|
|
6490
|
+
let zeros = 0;
|
|
6491
|
+
for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
|
|
6492
|
+
if (zeros >= 2 && byte <= 3) {
|
|
6493
|
+
nal.push(3);
|
|
6494
|
+
zeros = 0;
|
|
6495
|
+
}
|
|
6496
|
+
nal.push(byte);
|
|
6497
|
+
zeros = byte === 0 ? zeros + 1 : 0;
|
|
6498
|
+
}
|
|
6499
|
+
return Uint8Array.from(nal);
|
|
6500
|
+
};
|
|
6501
|
+
const x264Slices = [
|
|
6502
|
+
["64x48 P", hex3("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
|
|
6503
|
+
["64x48 B", hex3("419e414212fffeeade283707cb70f7"), 6, false],
|
|
6504
|
+
["64x48 non-IDR I", hex3(
|
|
6505
|
+
"4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
|
|
6506
|
+
), 7, true],
|
|
6507
|
+
["1280x720 B, escape at byte 10", hex3(
|
|
6508
|
+
"01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
|
|
6509
|
+
), 6, false],
|
|
6510
|
+
["1280x720 P, escape at byte 15", hex3(
|
|
6511
|
+
"41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
|
|
6512
|
+
), 5, false],
|
|
6513
|
+
["1280x720 B, escape at byte 22", hex3("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
|
|
6514
|
+
["7680x4320 IDR, first_mb_in_slice 97440", hex3(
|
|
6515
|
+
"650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
|
|
6516
|
+
), null, true],
|
|
6517
|
+
["7680x4320 P, first_mb_in_slice 32640", hex3(
|
|
6518
|
+
"410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
|
|
6519
|
+
), 5, false],
|
|
6520
|
+
["7680x4320 P, first_mb_in_slice 97440", hex3(
|
|
6521
|
+
"410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
|
|
6522
|
+
), 5, false]
|
|
6523
|
+
];
|
|
6524
|
+
const syntheticSlices = [
|
|
6525
|
+
["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
|
|
6526
|
+
["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
|
|
6527
|
+
["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
|
|
6528
|
+
["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
|
|
6529
|
+
["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
|
|
6530
|
+
["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
|
|
6531
|
+
["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
|
|
6532
|
+
["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
|
|
6533
|
+
];
|
|
6534
|
+
test("reads the slice_type of real and synthetic slices", () => {
|
|
6535
|
+
for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
|
|
6536
|
+
expect(readH264SliceType(nal), name).toBe(sliceType);
|
|
6537
|
+
}
|
|
6538
|
+
});
|
|
6539
|
+
test("matches the whole-NAL unescape at every truncation", () => {
|
|
6540
|
+
for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
|
|
6541
|
+
for (let end = 0; end <= nal.length; end++) {
|
|
6542
|
+
const cut = nal.subarray(0, end);
|
|
6543
|
+
expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
});
|
|
6547
|
+
test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
|
|
6548
|
+
const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
|
|
6549
|
+
let seed = 1;
|
|
6550
|
+
const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
|
|
6551
|
+
for (let i = 0; i < 5e3; i++) {
|
|
6552
|
+
const nal = new Uint8Array(2 + next() % 63);
|
|
6553
|
+
nal[0] = 65;
|
|
6554
|
+
for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
|
|
6555
|
+
expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
|
|
6556
|
+
}
|
|
6557
|
+
});
|
|
6558
|
+
test("classifies the x264 slices as keyframes or not", () => {
|
|
6559
|
+
for (const [name, nal, , keyframe] of x264Slices) {
|
|
6560
|
+
expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
|
|
6561
|
+
}
|
|
6562
|
+
});
|
|
6563
|
+
});
|
|
6462
6564
|
describe("avccToAnnexB", () => {
|
|
6463
6565
|
test("converts with SPS/PPS on keyframe", () => {
|
|
6464
6566
|
const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
|
|
@@ -7988,8 +8090,8 @@ var MulticastSubscriptionPool = class {
|
|
|
7988
8090
|
record.claims--;
|
|
7989
8091
|
return this.acquire(gateway, config, consumer);
|
|
7990
8092
|
}
|
|
7991
|
-
const
|
|
7992
|
-
entry.consumers.set(
|
|
8093
|
+
const token2 = Symbol(key);
|
|
8094
|
+
entry.consumers.set(token2, consumer);
|
|
7993
8095
|
let released = false;
|
|
7994
8096
|
return {
|
|
7995
8097
|
key,
|
|
@@ -7997,7 +8099,7 @@ var MulticastSubscriptionPool = class {
|
|
|
7997
8099
|
if (released)
|
|
7998
8100
|
return;
|
|
7999
8101
|
released = true;
|
|
8000
|
-
entry.consumers.delete(
|
|
8102
|
+
entry.consumers.delete(token2);
|
|
8001
8103
|
record.claims--;
|
|
8002
8104
|
if (record.claims > 0)
|
|
8003
8105
|
return;
|
|
@@ -8625,9 +8727,9 @@ async function openSubscription(rx, openedPromise, options, packetIds) {
|
|
|
8625
8727
|
} catch (error) {
|
|
8626
8728
|
throw new MulticastError("subscription-failed", "MulticastReceiver did not open", error);
|
|
8627
8729
|
}
|
|
8628
|
-
if (
|
|
8730
|
+
if (opened.integrityScheme !== INTEGRITY_SCHEME) {
|
|
8629
8731
|
await rx.close();
|
|
8630
|
-
throw unsupported(`integrity scheme ${String(
|
|
8732
|
+
throw unsupported(`integrity scheme ${String(opened.integrityScheme)} is not ${INTEGRITY_SCHEME}`);
|
|
8631
8733
|
}
|
|
8632
8734
|
const events = new EventTarget();
|
|
8633
8735
|
let state = "connected";
|
|
@@ -8746,14 +8848,15 @@ var MOQT_PUBLISHER_PRIORITY = Object.freeze({
|
|
|
8746
8848
|
});
|
|
8747
8849
|
|
|
8748
8850
|
// node_modules/@blockcast/mmt-transport/dist/amt-gateway.js
|
|
8851
|
+
var MAX_PENDING_PACKETS = 256;
|
|
8749
8852
|
var AMTGatewayManager = class {
|
|
8750
8853
|
subscriptions = /* @__PURE__ */ new Map();
|
|
8751
8854
|
messageHandler;
|
|
8855
|
+
messageListenerRegistered = false;
|
|
8752
8856
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
8753
8857
|
constructor() {
|
|
8754
8858
|
this.messageHandler = (event) => {
|
|
8755
8859
|
const data = event.data;
|
|
8756
|
-
console.log(`[AMT] SW message received:`, data.type);
|
|
8757
8860
|
if (data.type === "UDP_PACKET") {
|
|
8758
8861
|
this.handlePacket(data);
|
|
8759
8862
|
} else if (data.type === "SOCKET_ERROR") {
|
|
@@ -8762,12 +8865,22 @@ var AMTGatewayManager = class {
|
|
|
8762
8865
|
console.log(`[AMT SW Debug] ${data.message}`);
|
|
8763
8866
|
}
|
|
8764
8867
|
};
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8868
|
+
}
|
|
8869
|
+
ensureMessageListener() {
|
|
8870
|
+
if (this.messageListenerRegistered || typeof navigator === "undefined" || !navigator.serviceWorker || !this.messageHandler) {
|
|
8871
|
+
return;
|
|
8872
|
+
}
|
|
8873
|
+
navigator.serviceWorker.addEventListener("message", this.messageHandler);
|
|
8874
|
+
this.messageListenerRegistered = true;
|
|
8875
|
+
console.log("[AMT] Registered service worker message handler");
|
|
8876
|
+
}
|
|
8877
|
+
removeMessageListener() {
|
|
8878
|
+
if (!this.messageListenerRegistered)
|
|
8879
|
+
return;
|
|
8880
|
+
if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
|
|
8881
|
+
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
8770
8882
|
}
|
|
8883
|
+
this.messageListenerRegistered = false;
|
|
8771
8884
|
}
|
|
8772
8885
|
/**
|
|
8773
8886
|
* Subscribe via AMT tunnel
|
|
@@ -8777,6 +8890,7 @@ var AMTGatewayManager = class {
|
|
|
8777
8890
|
if (config.protected) {
|
|
8778
8891
|
throw new Error("AMTGatewayManager refuses a protected join: it reports no per-datagram sender (multicast-02 7.2.7)");
|
|
8779
8892
|
}
|
|
8893
|
+
this.ensureMessageListener();
|
|
8780
8894
|
const keyStr = this.getKeyString(key);
|
|
8781
8895
|
if (this.subscriptions.has(keyStr)) {
|
|
8782
8896
|
console.log(`[AMT] Reusing existing subscription to ${keyStr}`);
|
|
@@ -8812,6 +8926,8 @@ var AMTGatewayManager = class {
|
|
|
8812
8926
|
this.subscriptions.delete(keyStr);
|
|
8813
8927
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
8814
8928
|
}
|
|
8929
|
+
if (this.subscriptions.size === 0)
|
|
8930
|
+
this.removeMessageListener();
|
|
8815
8931
|
throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
|
|
8816
8932
|
}
|
|
8817
8933
|
}
|
|
@@ -8833,6 +8949,8 @@ var AMTGatewayManager = class {
|
|
|
8833
8949
|
} finally {
|
|
8834
8950
|
this.subscriptions.delete(handle);
|
|
8835
8951
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
8952
|
+
if (this.subscriptions.size === 0)
|
|
8953
|
+
this.removeMessageListener();
|
|
8836
8954
|
}
|
|
8837
8955
|
}
|
|
8838
8956
|
/**
|
|
@@ -8849,14 +8967,12 @@ var AMTGatewayManager = class {
|
|
|
8849
8967
|
if (!subscriptionId)
|
|
8850
8968
|
return;
|
|
8851
8969
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
8852
|
-
if (!subscription)
|
|
8853
|
-
console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
|
|
8970
|
+
if (!subscription)
|
|
8854
8971
|
return;
|
|
8855
|
-
}
|
|
8856
8972
|
if (!subscription.handshakeComplete) {
|
|
8857
8973
|
const queue = this.pendingPackets.get(subscriptionId);
|
|
8858
8974
|
const packetData2 = data;
|
|
8859
|
-
if (queue) {
|
|
8975
|
+
if (queue && queue.length < MAX_PENDING_PACKETS) {
|
|
8860
8976
|
queue.push({
|
|
8861
8977
|
data: packetData2.data,
|
|
8862
8978
|
remoteAddress: packetData2.remoteAddress,
|
|
@@ -8882,19 +8998,15 @@ var AMTGatewayManager = class {
|
|
|
8882
8998
|
if (!subscriptionId)
|
|
8883
8999
|
return;
|
|
8884
9000
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
8885
|
-
if (!subscription)
|
|
8886
|
-
console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
|
|
9001
|
+
if (!subscription)
|
|
8887
9002
|
return;
|
|
8888
|
-
}
|
|
8889
9003
|
subscription.config.onError(new Error(error || "Unknown error"));
|
|
8890
9004
|
}
|
|
8891
9005
|
/**
|
|
8892
9006
|
* Cleanup on destroy
|
|
8893
9007
|
*/
|
|
8894
9008
|
destroy() {
|
|
8895
|
-
|
|
8896
|
-
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
8897
|
-
}
|
|
9009
|
+
this.removeMessageListener();
|
|
8898
9010
|
const handles = Array.from(this.subscriptions.keys());
|
|
8899
9011
|
for (const handle of handles) {
|
|
8900
9012
|
this.unsubscribe(handle).catch((err) => {
|
|
@@ -12425,6 +12537,7 @@ var TrackSession = class {
|
|
|
12425
12537
|
this.#state = "idle";
|
|
12426
12538
|
this.#subscription = null;
|
|
12427
12539
|
this.#disarmFec();
|
|
12540
|
+
this.#unsuppress();
|
|
12428
12541
|
}
|
|
12429
12542
|
// -----------------------------------------------------------------------
|
|
12430
12543
|
// Internal
|
|
@@ -12918,6 +13031,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12918
13031
|
this.#heldEvicted = 0;
|
|
12919
13032
|
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
12920
13033
|
this.#holes = [];
|
|
13034
|
+
/** Holes the horizon passed while pending: sources held until closed. */
|
|
13035
|
+
this.#expired = [];
|
|
13036
|
+
/** Of `#expired`, those `takeExpiredHoles` has not handed out yet. */
|
|
13037
|
+
this.#newlyExpired = [];
|
|
13038
|
+
/**
|
|
13039
|
+
* Spans closed from expired holes: behind the horizon, so kept only for
|
|
13040
|
+
* `locate` while their sources are fed, until the next retirement.
|
|
13041
|
+
*/
|
|
13042
|
+
this.#closedBehind = [];
|
|
12921
13043
|
/**
|
|
12922
13044
|
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
12923
13045
|
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
@@ -12939,7 +13061,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12939
13061
|
#retentionBlocks;
|
|
12940
13062
|
#heldEvicted;
|
|
12941
13063
|
#newest;
|
|
13064
|
+
#newestSource;
|
|
12942
13065
|
#holes;
|
|
13066
|
+
#expired;
|
|
13067
|
+
#newlyExpired;
|
|
13068
|
+
#closedBehind;
|
|
12943
13069
|
static #checkedRetention(retentionBlocks) {
|
|
12944
13070
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
12945
13071
|
throw new Error(
|
|
@@ -12976,6 +13102,21 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12976
13102
|
observe(position) {
|
|
12977
13103
|
if (this.#newest === void 0 || serial32Precedes(this.#newest, position)) this.#newest = position;
|
|
12978
13104
|
}
|
|
13105
|
+
/**
|
|
13106
|
+
* The newest source SS_ID noted with `noteSource` (RFC 1982 order). Unlike
|
|
13107
|
+
* `newest`, a repair never moves it: a repair can run ahead of its sources,
|
|
13108
|
+
* a source cannot run ahead of the sources sent before it except by
|
|
13109
|
+
* reordering.
|
|
13110
|
+
*/
|
|
13111
|
+
get newestSource() {
|
|
13112
|
+
return this.#newestSource;
|
|
13113
|
+
}
|
|
13114
|
+
/** Note a received source's SS_ID; true when it is the newest one yet. */
|
|
13115
|
+
noteSource(ssId) {
|
|
13116
|
+
if (this.#newestSource !== void 0 && !serial32Precedes(this.#newestSource, ssId)) return false;
|
|
13117
|
+
this.#newestSource = ssId;
|
|
13118
|
+
return true;
|
|
13119
|
+
}
|
|
12979
13120
|
/** Held sources evicted by `heldCapacity` (never by the horizon itself). */
|
|
12980
13121
|
get heldEvicted() {
|
|
12981
13122
|
return this.#heldEvicted;
|
|
@@ -12994,17 +13135,29 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
12994
13135
|
}
|
|
12995
13136
|
/** The known block or span containing `ssId`, with its ESI. */
|
|
12996
13137
|
locate(ssId) {
|
|
12997
|
-
for (
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13138
|
+
for (const blocks of [this.#blocks, this.#closedBehind]) {
|
|
13139
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
13140
|
+
const block = blocks[i];
|
|
13141
|
+
if (isoBlockContains(block.start, block.length, ssId)) {
|
|
13142
|
+
return { block, esi: serial32Distance(block.start, ssId) };
|
|
13143
|
+
}
|
|
13001
13144
|
}
|
|
13002
13145
|
}
|
|
13003
13146
|
return null;
|
|
13004
13147
|
}
|
|
13005
|
-
/** Number of pending
|
|
13148
|
+
/** Number of holes not closed yet, pending or past the horizon. */
|
|
13006
13149
|
get holeCount() {
|
|
13007
|
-
return this.#holes.length;
|
|
13150
|
+
return this.#holes.length + this.#expired.length;
|
|
13151
|
+
}
|
|
13152
|
+
/**
|
|
13153
|
+
* The pending holes the horizon has passed since the last call, in the
|
|
13154
|
+
* order it passed them. Each is no longer pending: no repair states a block
|
|
13155
|
+
* in it (that repair is `stale`, as for a span the horizon retired) and the
|
|
13156
|
+
* release gate does not wait for it. Its owner must close it
|
|
13157
|
+
* (`closeHolesWithin`), which turns it into a span that is not kept here.
|
|
13158
|
+
*/
|
|
13159
|
+
takeExpiredHoles() {
|
|
13160
|
+
return this.#newlyExpired.splice(0);
|
|
13008
13161
|
}
|
|
13009
13162
|
/** The stated block (never a span) ending exactly at `end`. */
|
|
13010
13163
|
blockEndingAt(end) {
|
|
@@ -13060,9 +13213,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13060
13213
|
/**
|
|
13061
13214
|
* Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
|
|
13062
13215
|
* block states its range and places every held source in it; later repair
|
|
13063
|
-
* symbols of the same block change nothing. A range
|
|
13064
|
-
*
|
|
13065
|
-
*
|
|
13216
|
+
* symbols of the same block change nothing. A repair whose range is exactly
|
|
13217
|
+
* a repair-less span states that span's one block. A range that contradicts
|
|
13218
|
+
* a known block (a different length, or an overlap with another block or
|
|
13219
|
+
* with part of a span) fails closed: the repair symbol is dropped and no
|
|
13220
|
+
* block changes.
|
|
13066
13221
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
13067
13222
|
* A block so far past `newest` that stating it would retire the position
|
|
13068
13223
|
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
@@ -13081,7 +13236,16 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13081
13236
|
const known = this.blockAt(start);
|
|
13082
13237
|
if (known !== void 0) {
|
|
13083
13238
|
if (known.span) {
|
|
13084
|
-
|
|
13239
|
+
if (known.length === length) {
|
|
13240
|
+
const block2 = { start, length, span: false };
|
|
13241
|
+
this.#blocks[this.#blocks.indexOf(known)] = block2;
|
|
13242
|
+
return { status: "placed", block: block2, placed: [] };
|
|
13243
|
+
}
|
|
13244
|
+
return length < known.length ? {
|
|
13245
|
+
status: "overlap",
|
|
13246
|
+
reason: `repair block ${start}+${length} is only the first block of repair-less span ${known.start}+${known.length}`,
|
|
13247
|
+
ofSpan: known
|
|
13248
|
+
} : { status: "overlap", reason: `repair block ${start}+${length} runs past repair-less span ${known.start}+${known.length}` };
|
|
13085
13249
|
}
|
|
13086
13250
|
if (known.length !== length) {
|
|
13087
13251
|
return {
|
|
@@ -13149,18 +13313,28 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13149
13313
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
13150
13314
|
}
|
|
13151
13315
|
/**
|
|
13152
|
-
* Turn every
|
|
13153
|
-
*
|
|
13154
|
-
*
|
|
13316
|
+
* Turn every hole inside `[start, start + length)` into a repair-less span,
|
|
13317
|
+
* claiming its held sources: its range FETCH ended, so nothing more will
|
|
13318
|
+
* state its blocks. A hole the horizon passed (`takeExpiredHoles`) leaves a
|
|
13319
|
+
* span that is not kept among the blocks, as the horizon would retire it at
|
|
13320
|
+
* once; only `locate` finds it, until the next retirement, so its sources
|
|
13321
|
+
* can be fed. Returns the spans, in SS_ID order.
|
|
13155
13322
|
*/
|
|
13156
13323
|
closeHolesWithin(start, length) {
|
|
13157
13324
|
const closed = [];
|
|
13158
|
-
for (const
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13325
|
+
for (const holes of [this.#holes, this.#expired]) {
|
|
13326
|
+
for (const hole of [...holes]) {
|
|
13327
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
13328
|
+
holes.splice(holes.indexOf(hole), 1);
|
|
13329
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
13330
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
13331
|
+
if (holes === this.#holes) {
|
|
13332
|
+
this.#blocks.push(spanBlock);
|
|
13333
|
+
} else {
|
|
13334
|
+
this.#closedBehind.push(spanBlock);
|
|
13335
|
+
if (this.#newlyExpired.includes(hole)) this.#newlyExpired.splice(this.#newlyExpired.indexOf(hole), 1);
|
|
13336
|
+
}
|
|
13337
|
+
}
|
|
13164
13338
|
}
|
|
13165
13339
|
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
13166
13340
|
}
|
|
@@ -13174,15 +13348,17 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13174
13348
|
return void 0;
|
|
13175
13349
|
}
|
|
13176
13350
|
/**
|
|
13177
|
-
* Retire every block and span whose last SS_ID, and every held source
|
|
13178
|
-
* lies more than `retentionBlocks` blocks behind
|
|
13179
|
-
* lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
13180
|
-
* horizon uses
|
|
13351
|
+
* Retire every block and span whose last SS_ID, and every held source
|
|
13352
|
+
* outside a hole, lies more than `retentionBlocks` blocks behind
|
|
13353
|
+
* `position`, with the shared lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
13354
|
+
* every ISO interleave horizon uses; a pending hole so far behind expires
|
|
13355
|
+
* (`takeExpiredHoles`). Returns the retired block starts.
|
|
13181
13356
|
*/
|
|
13182
13357
|
retireBehind(position) {
|
|
13183
13358
|
this.observe(position);
|
|
13184
13359
|
const horizon = this.#retentionBlocks;
|
|
13185
13360
|
const retired = [];
|
|
13361
|
+
this.#closedBehind.length = 0;
|
|
13186
13362
|
for (let i = this.#blocks.length - 1; i >= 0; i--) {
|
|
13187
13363
|
const block = this.#blocks[i];
|
|
13188
13364
|
const last = serial32Add(block.start, block.length - 1);
|
|
@@ -13194,10 +13370,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13194
13370
|
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
13195
13371
|
const hole = this.#holes[i];
|
|
13196
13372
|
const last = serial32Add(hole.start, hole.length - 1);
|
|
13197
|
-
if (isoBlocksBehindLowerBound(last, position, this.#kMax)
|
|
13373
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) <= horizon) continue;
|
|
13374
|
+
this.#holes.splice(i, 1);
|
|
13375
|
+
this.#expired.push(hole);
|
|
13376
|
+
this.#newlyExpired.push(hole);
|
|
13198
13377
|
}
|
|
13199
13378
|
for (const ssId of [...this.#held.keys()]) {
|
|
13200
|
-
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#
|
|
13379
|
+
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))) {
|
|
13380
|
+
this.#held.delete(ssId);
|
|
13381
|
+
}
|
|
13201
13382
|
}
|
|
13202
13383
|
return retired;
|
|
13203
13384
|
}
|
|
@@ -13205,9 +13386,13 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
13205
13386
|
reset() {
|
|
13206
13387
|
this.#blocks.length = 0;
|
|
13207
13388
|
this.#holes.length = 0;
|
|
13389
|
+
this.#expired.length = 0;
|
|
13390
|
+
this.#newlyExpired.length = 0;
|
|
13391
|
+
this.#closedBehind.length = 0;
|
|
13208
13392
|
this.#held.clear();
|
|
13209
13393
|
this.#coverageEnd = void 0;
|
|
13210
13394
|
this.#newest = void 0;
|
|
13395
|
+
this.#newestSource = void 0;
|
|
13211
13396
|
}
|
|
13212
13397
|
#claim(block) {
|
|
13213
13398
|
const placed = [];
|
|
@@ -13827,6 +14012,7 @@ var WORKER_ERROR_LOG_CAP = 5;
|
|
|
13827
14012
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
13828
14013
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
13829
14014
|
var STARTUP_REPAIR_WAIT_SOURCE_BOUNDARIES = 2;
|
|
14015
|
+
var NOT_TAKEN = Object.freeze({ taken: false, recovered: null });
|
|
13830
14016
|
function isMulticastSymbolDelivery(value) {
|
|
13831
14017
|
return value === "datagram" || value === "ordered-relay";
|
|
13832
14018
|
}
|
|
@@ -13920,10 +14106,18 @@ var FECManager = class _FECManager {
|
|
|
13920
14106
|
// 'pending' forever, which would park every later frame of its stream in
|
|
13921
14107
|
// the in-order release gate. Each entry owns its handle; the callback
|
|
13922
14108
|
// checks it still owns the key, so a settled or reset key is never touched.
|
|
14109
|
+
/**
|
|
14110
|
+
* Per owed Worker cleanup: the bound on its acknowledgement, when its block
|
|
14111
|
+
* was due, and when its cleanup was asked for (see `onCleanupComplete`).
|
|
14112
|
+
*/
|
|
13923
14113
|
this.#pendingWorkerCleanupBounds = /* @__PURE__ */ new Map();
|
|
13924
14114
|
// Source symbol count per track-scoped block — marks complete when K symbols arrive.
|
|
13925
14115
|
this.#blockSourceCounts = /* @__PURE__ */ new Map();
|
|
13926
14116
|
this.#blockSourceEsis = /* @__PURE__ */ new Map();
|
|
14117
|
+
// Source ESIs per block that another FEC instance rebuilt and fed in
|
|
14118
|
+
// (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
|
|
14119
|
+
// not network arrivals and never make a block clean.
|
|
14120
|
+
this.#blockRebuiltEsis = /* @__PURE__ */ new Map();
|
|
13927
14121
|
// Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
|
|
13928
14122
|
// first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
|
|
13929
14123
|
// media units, usually before it holds K symbols; under iso-ssbg1-v1
|
|
@@ -13932,10 +14126,14 @@ var FECManager = class _FECManager {
|
|
|
13932
14126
|
// SSB_length source arrivals and recoverable from SSB_length received
|
|
13933
14127
|
// symbols; waiting for K fails every one of them.
|
|
13934
14128
|
this.#blockAuthoredLengths = /* @__PURE__ */ new Map();
|
|
14129
|
+
// Keys whose authored length is a repair-less span's (#openIsoSpan), until
|
|
14130
|
+
// a repair states the block there or the span resolves.
|
|
14131
|
+
this.#isoSpanKeys = /* @__PURE__ */ new Set();
|
|
13935
14132
|
this.#ssbLengthConflictCount = 0;
|
|
13936
14133
|
this.#blockRepairRsIds = /* @__PURE__ */ new Map();
|
|
13937
14134
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
13938
|
-
// symbols its repair group carries
|
|
14135
|
+
// symbols its repair group carries; 0 for a repair-less span no repair can
|
|
14136
|
+
// state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
|
|
13939
14137
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
13940
14138
|
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
13941
14139
|
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
@@ -14052,6 +14250,10 @@ var FECManager = class _FECManager {
|
|
|
14052
14250
|
// ── Keyframe-protected repair policy (block-policy.ts) ──
|
|
14053
14251
|
// One classifier per physical stream, built from that stream's geometry.
|
|
14054
14252
|
this.#classifiers = /* @__PURE__ */ new Map();
|
|
14253
|
+
// A stream without catalog timing has no classifier, so the last RAP it
|
|
14254
|
+
// released stands in for one: "an MPU boundary bounds its RAPs" holds until
|
|
14255
|
+
// a second RAP is released inside one MPU (BLO-52085).
|
|
14256
|
+
this.#noSpanRaps = /* @__PURE__ */ new Map();
|
|
14055
14257
|
// Geometry a stream-scoped configuration gave one stream (streamKey). ABR
|
|
14056
14258
|
// rungs can share a packetId with a different framerate or GOP, so the
|
|
14057
14259
|
// packet-level geometry is only the geometry of a packet whose streams
|
|
@@ -14119,13 +14321,17 @@ var FECManager = class _FECManager {
|
|
|
14119
14321
|
this.#workerErrorCounts = /* @__PURE__ */ new Map();
|
|
14120
14322
|
this.#decoderUnavailableEvents = 0;
|
|
14121
14323
|
this.#repairSymbolSizeMismatchCount = 0;
|
|
14324
|
+
this.#unlistedRepairTrackRefusals = 0;
|
|
14122
14325
|
// Event callbacks — block lifecycle notifications for MmtpRouter wiring.
|
|
14123
14326
|
// NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
|
|
14124
14327
|
// feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
|
|
14125
14328
|
// arrives via onBlockRecovered callback.
|
|
14126
14329
|
this.onBlockStarted = null;
|
|
14127
14330
|
this.onBlockComplete = null;
|
|
14128
|
-
/**
|
|
14331
|
+
/**
|
|
14332
|
+
* A block reached its fail bound. `blockClass` is its class at failure.
|
|
14333
|
+
* `span` is set when what failed is a repair-less span starting at `sbn`.
|
|
14334
|
+
*/
|
|
14129
14335
|
this.onBlockFailed = null;
|
|
14130
14336
|
/**
|
|
14131
14337
|
* Fired once per stream when its Worker decoder stops being routable.
|
|
@@ -14167,12 +14373,24 @@ var FECManager = class _FECManager {
|
|
|
14167
14373
|
* for it, which it must be.
|
|
14168
14374
|
*/
|
|
14169
14375
|
this.#onUndelimitedLoss = null;
|
|
14376
|
+
/** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
|
|
14377
|
+
this.#onIsoHoleExpired = null;
|
|
14170
14378
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
14171
14379
|
this.onBlockVanished = null;
|
|
14172
14380
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
14173
14381
|
this.onBlockResolved = null;
|
|
14174
14382
|
/** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
|
|
14175
14383
|
this.onSourceDiscontinuity = null;
|
|
14384
|
+
/**
|
|
14385
|
+
* The span and tolerance the catalog states for a keyframe overlay
|
|
14386
|
+
* installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
|
|
14387
|
+
* overlay instance's own interleaveDepthMs and reorderToleranceMs), or
|
|
14388
|
+
* undefined while none is installed. A stated block only a late source
|
|
14389
|
+
* can complete, and a frame whose gap may hide a RAP behind a span only a
|
|
14390
|
+
* late source can fill, also wait for that overlay's repair
|
|
14391
|
+
* (#overlayLateWaitMs).
|
|
14392
|
+
*/
|
|
14393
|
+
this.keyframeOverlayTiming = null;
|
|
14176
14394
|
// Worker-path callbacks — async recovery and stats from FecWorkerClient.
|
|
14177
14395
|
/**
|
|
14178
14396
|
* A recovered source symbol. Return false when admission refused the
|
|
@@ -14209,7 +14427,9 @@ var FECManager = class _FECManager {
|
|
|
14209
14427
|
#pendingWorkerCleanupBounds;
|
|
14210
14428
|
#blockSourceCounts;
|
|
14211
14429
|
#blockSourceEsis;
|
|
14430
|
+
#blockRebuiltEsis;
|
|
14212
14431
|
#blockAuthoredLengths;
|
|
14432
|
+
#isoSpanKeys;
|
|
14213
14433
|
#ssbLengthConflictCount;
|
|
14214
14434
|
#blockRepairRsIds;
|
|
14215
14435
|
#blockRsbLengths;
|
|
@@ -14251,6 +14471,7 @@ var FECManager = class _FECManager {
|
|
|
14251
14471
|
#orderedFrontiers;
|
|
14252
14472
|
#orderedPendingBlocks;
|
|
14253
14473
|
#classifiers;
|
|
14474
|
+
#noSpanRaps;
|
|
14254
14475
|
#streamGeometries;
|
|
14255
14476
|
#failedBlocks;
|
|
14256
14477
|
#resolvedBlockClasses;
|
|
@@ -14274,7 +14495,9 @@ var FECManager = class _FECManager {
|
|
|
14274
14495
|
#workerErrorCounts;
|
|
14275
14496
|
#decoderUnavailableEvents;
|
|
14276
14497
|
#repairSymbolSizeMismatchCount;
|
|
14498
|
+
#unlistedRepairTrackRefusals;
|
|
14277
14499
|
#onUndelimitedLoss;
|
|
14500
|
+
#onIsoHoleExpired;
|
|
14278
14501
|
#encodeTrackName(catalogTrackName) {
|
|
14279
14502
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
14280
14503
|
if (encoded === void 0) {
|
|
@@ -14746,7 +14969,10 @@ var FECManager = class _FECManager {
|
|
|
14746
14969
|
timer.handle = null;
|
|
14747
14970
|
this.#requestRepair(sbn, packetId, catalogTrackName);
|
|
14748
14971
|
};
|
|
14749
|
-
timer.handle = setTimeout(
|
|
14972
|
+
timer.handle = setTimeout(
|
|
14973
|
+
onFire,
|
|
14974
|
+
this.#receiptAtMs === void 0 ? Math.max(0, deadlineMs - performance.now()) : this.#receiptTimerDelayMs(deadlineMs, 0)
|
|
14975
|
+
);
|
|
14750
14976
|
this.#repairDeadlines.set(key, timer);
|
|
14751
14977
|
}
|
|
14752
14978
|
#requestRepair(sbn, packetId, catalogTrackName, settledByOrder = false) {
|
|
@@ -14890,8 +15116,14 @@ var FECManager = class _FECManager {
|
|
|
14890
15116
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
14891
15117
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
14892
15118
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
15119
|
+
*
|
|
15120
|
+
* A `held` source arrived before its block was known and is fed only now
|
|
15121
|
+
* that a repair, a span or a closed hole placed it: how far its block start
|
|
15122
|
+
* then lies behind the frontier measures how long the receiver held it, not
|
|
15123
|
+
* where the stream was, so only its SS_ID and packet_sequence_number judge
|
|
15124
|
+
* it (BLO-52085).
|
|
14893
15125
|
*/
|
|
14894
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
15126
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn, held = false) {
|
|
14895
15127
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
14896
15128
|
const now = performance.now();
|
|
14897
15129
|
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
@@ -14912,6 +15144,7 @@ var FECManager = class _FECManager {
|
|
|
14912
15144
|
};
|
|
14913
15145
|
const discontinuity = () => {
|
|
14914
15146
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
15147
|
+
this.#noSpanRaps.delete(streamKey);
|
|
14915
15148
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
14916
15149
|
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
14917
15150
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
@@ -14929,7 +15162,7 @@ var FECManager = class _FECManager {
|
|
|
14929
15162
|
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
14930
15163
|
};
|
|
14931
15164
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
14932
|
-
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))) {
|
|
15165
|
+
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))) {
|
|
14933
15166
|
discontinuity();
|
|
14934
15167
|
return;
|
|
14935
15168
|
}
|
|
@@ -15191,17 +15424,21 @@ var FECManager = class _FECManager {
|
|
|
15191
15424
|
this.#blockWaitDeadlinesMs.delete(key);
|
|
15192
15425
|
this.#repairHoldUntilMs.delete(key);
|
|
15193
15426
|
this.#traceLifecycle("timeout-queued", sbn, packetId, catalogTrackName);
|
|
15194
|
-
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName);
|
|
15427
|
+
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs);
|
|
15195
15428
|
};
|
|
15196
|
-
timer.handle = setTimeout(
|
|
15429
|
+
timer.handle = setTimeout(
|
|
15430
|
+
onFire,
|
|
15431
|
+
this.#receiptAtMs === void 0 ? Math.max(1, Math.ceil(deadlineMs - nowMs)) : this.#receiptTimerDelayMs(deadlineMs, 1)
|
|
15432
|
+
);
|
|
15197
15433
|
this.#activeBlocks.set(key, timer);
|
|
15198
15434
|
this.#indexBlockKey(key, sbn, packetId);
|
|
15199
15435
|
}
|
|
15200
15436
|
/**
|
|
15201
15437
|
* Hand a block whose delivery is over to its decoder for finalization: the
|
|
15202
|
-
* datagram deadline fired, or the ordered relay moved past it.
|
|
15438
|
+
* datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
|
|
15439
|
+
* is when it was due: its deadline, or now.
|
|
15203
15440
|
*/
|
|
15204
|
-
#finalizeExpiredBlock(sbn, packetId, catalogTrackName) {
|
|
15441
|
+
#finalizeExpiredBlock(sbn, packetId, catalogTrackName, dueAtMs = performance.now()) {
|
|
15205
15442
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
15206
15443
|
if (this.#materializedBlocks.has(key) && !this.#blockPathCounts.has(key)) {
|
|
15207
15444
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -15217,7 +15454,7 @@ var FECManager = class _FECManager {
|
|
|
15217
15454
|
if (workerClient) {
|
|
15218
15455
|
this.#pendingWorkerCleanups.add(key);
|
|
15219
15456
|
this.#pendingWorkerCleanupClients.set(key, workerClient);
|
|
15220
|
-
this.#boundOwedCleanup(key, packetId, workerClient);
|
|
15457
|
+
this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs);
|
|
15221
15458
|
workerClient.cleanup(sbn);
|
|
15222
15459
|
} else {
|
|
15223
15460
|
const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client;
|
|
@@ -15324,6 +15561,9 @@ var FECManager = class _FECManager {
|
|
|
15324
15561
|
}
|
|
15325
15562
|
if (policyChanged) {
|
|
15326
15563
|
this.#bumpEpoch(packetId);
|
|
15564
|
+
for (const key of [...this.#noSpanRaps.keys()]) {
|
|
15565
|
+
if (this.#belongsToPacket(key, packetId)) this.#noSpanRaps.delete(key);
|
|
15566
|
+
}
|
|
15327
15567
|
for (const [key, classifier] of [...this.#classifiers]) {
|
|
15328
15568
|
if (!this.#belongsToPacket(key, packetId)) continue;
|
|
15329
15569
|
const stream = this.#parseStreamKey(key);
|
|
@@ -15424,6 +15664,7 @@ var FECManager = class _FECManager {
|
|
|
15424
15664
|
packetId
|
|
15425
15665
|
})),
|
|
15426
15666
|
repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
|
|
15667
|
+
unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
|
|
15427
15668
|
repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
|
|
15428
15669
|
workerErrors: Object.fromEntries(this.#workerErrorCounts)
|
|
15429
15670
|
};
|
|
@@ -15526,7 +15767,9 @@ var FECManager = class _FECManager {
|
|
|
15526
15767
|
}
|
|
15527
15768
|
resetMap(this.#blockSourceCounts);
|
|
15528
15769
|
resetMap(this.#blockSourceEsis);
|
|
15770
|
+
resetMap(this.#blockRebuiltEsis);
|
|
15529
15771
|
resetMap(this.#blockAuthoredLengths);
|
|
15772
|
+
resetSet(this.#isoSpanKeys);
|
|
15530
15773
|
resetMap(this.#blockRepairRsIds);
|
|
15531
15774
|
resetMap(this.#blockRsbLengths);
|
|
15532
15775
|
resetMap(this.#heldLayerStates);
|
|
@@ -15559,6 +15802,7 @@ var FECManager = class _FECManager {
|
|
|
15559
15802
|
resetMap(this.#isoLocators);
|
|
15560
15803
|
resetMap(this.#sourceAnchors);
|
|
15561
15804
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
15805
|
+
this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName));
|
|
15562
15806
|
this.#bumpEpoch(packetId);
|
|
15563
15807
|
for (const [sbn, keys] of this.#blockKeysBySbn) {
|
|
15564
15808
|
for (const key of keys.keys()) {
|
|
@@ -15649,7 +15893,9 @@ var FECManager = class _FECManager {
|
|
|
15649
15893
|
dropMap(this.#pendingWorkerCleanupClients);
|
|
15650
15894
|
dropMap(this.#blockSourceCounts);
|
|
15651
15895
|
dropMap(this.#blockSourceEsis);
|
|
15896
|
+
dropMap(this.#blockRebuiltEsis);
|
|
15652
15897
|
dropMap(this.#blockAuthoredLengths);
|
|
15898
|
+
dropSet(this.#isoSpanKeys);
|
|
15653
15899
|
dropMap(this.#blockRepairRsIds);
|
|
15654
15900
|
dropMap(this.#blockRsbLengths);
|
|
15655
15901
|
dropMap(this.#blockPathCounts);
|
|
@@ -15665,6 +15911,7 @@ var FECManager = class _FECManager {
|
|
|
15665
15911
|
dropMap(this.#isoLocators);
|
|
15666
15912
|
dropMap(this.#sourceAnchors);
|
|
15667
15913
|
dropMap(this.#classifiers);
|
|
15914
|
+
dropMap(this.#noSpanRaps);
|
|
15668
15915
|
dropMap(this.#streamGeometries);
|
|
15669
15916
|
dropSet(this.#pendingWorkerCleanups);
|
|
15670
15917
|
dropSet(this.#completedBlocks);
|
|
@@ -15810,6 +16057,9 @@ var FECManager = class _FECManager {
|
|
|
15810
16057
|
this.#unindexBlockKey(key);
|
|
15811
16058
|
}
|
|
15812
16059
|
}
|
|
16060
|
+
if (isSourceSymbol && source === "multicast") {
|
|
16061
|
+
this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), sbn + esi >>> 0, packetId, catalogTrackName);
|
|
16062
|
+
}
|
|
15813
16063
|
return true;
|
|
15814
16064
|
}
|
|
15815
16065
|
#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName) {
|
|
@@ -15919,8 +16169,10 @@ var FECManager = class _FECManager {
|
|
|
15919
16169
|
}
|
|
15920
16170
|
/**
|
|
15921
16171
|
* An open block's accepted sources, distinct repair RS_IDs, authored K'
|
|
15922
|
-
* (SSB_length) and RSB_length (each undefined until a repair stated it
|
|
15923
|
-
*
|
|
16172
|
+
* (SSB_length) and RSB_length (each undefined until a repair stated it; a
|
|
16173
|
+
* repair-less span states its length, and RSB_length 0 when it is longer
|
|
16174
|
+
* than K, since no repair can reach it). Undefined for a block that is not
|
|
16175
|
+
* open.
|
|
15924
16176
|
*/
|
|
15925
16177
|
blockSymbolCounts(sbn, packetId, catalogTrackName) {
|
|
15926
16178
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -15988,8 +16240,9 @@ var FECManager = class _FECManager {
|
|
|
15988
16240
|
return true;
|
|
15989
16241
|
}
|
|
15990
16242
|
/**
|
|
15991
|
-
* Drop a block's repair hold: its FETCH ended without delivering
|
|
15992
|
-
*
|
|
16243
|
+
* Drop a block's repair hold: its FETCH ended without delivering, or brought
|
|
16244
|
+
* back only a repair that cannot complete it. The block falls back to its
|
|
16245
|
+
* multicast wait, which may already have passed.
|
|
15993
16246
|
*/
|
|
15994
16247
|
releaseRepairHold(sbn, packetId, catalogTrackName) {
|
|
15995
16248
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -16035,7 +16288,7 @@ var FECManager = class _FECManager {
|
|
|
16035
16288
|
}
|
|
16036
16289
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
16037
16290
|
if (trackConfig === void 0) return void 0;
|
|
16038
|
-
return Math.max(1, trackConfig
|
|
16291
|
+
return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
|
|
16039
16292
|
}
|
|
16040
16293
|
/** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
|
|
16041
16294
|
// -----------------------------------------------------------------------
|
|
@@ -16127,6 +16380,8 @@ var FECManager = class _FECManager {
|
|
|
16127
16380
|
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
16128
16381
|
const evictedBefore = locator.heldEvicted;
|
|
16129
16382
|
const held = locator.hold(ssId, source);
|
|
16383
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
16384
|
+
if (held && source.source === "multicast") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
|
|
16130
16385
|
const evicted = locator.heldEvicted - evictedBefore;
|
|
16131
16386
|
if (evicted > 0) {
|
|
16132
16387
|
const before = this.#isoHeldEvictedCount;
|
|
@@ -16147,17 +16402,20 @@ var FECManager = class _FECManager {
|
|
|
16147
16402
|
* contradicts a known block is refused (counted) and must be dropped.
|
|
16148
16403
|
*/
|
|
16149
16404
|
placeIsoRepair(packetId, catalogTrackName, ssStart, ssbLength) {
|
|
16150
|
-
const
|
|
16405
|
+
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
16406
|
+
const placement = locator.placeRepair(ssStart, ssbLength);
|
|
16407
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
16151
16408
|
if (placement.status !== "placed") {
|
|
16152
16409
|
this.#isoRepairRefusedCount++;
|
|
16153
16410
|
if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
|
|
16154
16411
|
console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`);
|
|
16155
16412
|
}
|
|
16413
|
+
if (placement.ofSpan !== void 0) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName);
|
|
16156
16414
|
return placement;
|
|
16157
16415
|
}
|
|
16416
|
+
this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName));
|
|
16158
16417
|
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
16159
16418
|
if (placement.hole !== void 0) {
|
|
16160
|
-
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
16161
16419
|
const hole = placement.hole.block;
|
|
16162
16420
|
const previous = locator.blockEndingAt(hole.start);
|
|
16163
16421
|
const loss = {
|
|
@@ -16178,17 +16436,29 @@ var FECManager = class _FECManager {
|
|
|
16178
16436
|
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
16179
16437
|
* range repair scheduler; applies to every stream from its next gap. The
|
|
16180
16438
|
* handler and the deferral are one setting, so no hole is ever created with
|
|
16181
|
-
* nobody to close it.
|
|
16439
|
+
* nobody to close it. `onExpired` is told of each pending hole the stream
|
|
16440
|
+
* runs past the locator's horizon (BLO-52085): returning true, it closes
|
|
16441
|
+
* the hole (`closeIsoHoles`), so the span it leaves still fails and is
|
|
16442
|
+
* reported; otherwise the hole is discarded with its sources.
|
|
16182
16443
|
*/
|
|
16183
|
-
setUndelimitedLossHandler(handler) {
|
|
16444
|
+
setUndelimitedLossHandler(handler, onExpired = null) {
|
|
16184
16445
|
this.#onUndelimitedLoss = handler;
|
|
16446
|
+
this.#onIsoHoleExpired = handler === null ? null : onExpired;
|
|
16185
16447
|
this.#deferIsoGaps = handler !== null;
|
|
16186
16448
|
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
16187
16449
|
}
|
|
16450
|
+
/** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
|
|
16451
|
+
#settleExpiredIsoHoles(locator, packetId, catalogTrackName) {
|
|
16452
|
+
for (const hole of locator.takeExpiredHoles()) {
|
|
16453
|
+
const expired = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length };
|
|
16454
|
+
if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length);
|
|
16455
|
+
}
|
|
16456
|
+
}
|
|
16188
16457
|
/**
|
|
16189
|
-
* The range repair for a hole ended: every hole
|
|
16190
|
-
*
|
|
16191
|
-
* with the held sources they placed, for the caller to feed
|
|
16458
|
+
* The range repair for a hole ended: every hole inside `[start, start +
|
|
16459
|
+
* length)`, pending or expired, becomes a repair-less span. Returns those
|
|
16460
|
+
* spans with the held sources they placed, for the caller to feed
|
|
16461
|
+
* (MmtpRouter).
|
|
16192
16462
|
*/
|
|
16193
16463
|
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
16194
16464
|
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -16204,10 +16474,25 @@ var FECManager = class _FECManager {
|
|
|
16204
16474
|
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
16205
16475
|
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
16206
16476
|
* block.
|
|
16477
|
+
*
|
|
16478
|
+
* A span longer than K holds more than one block (SSB_length <= K), and the
|
|
16479
|
+
* locator states no block inside a span, only one exactly its range
|
|
16480
|
+
* (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
|
|
16481
|
+
* reach it. Its repair group is empty, so the repair scheduler FETCHes no
|
|
16482
|
+
* Group of it (group-cannot-complete). Every span still keeps its whole
|
|
16483
|
+
* wait (#lateSourceWaitMs): failing it early released the frames behind it
|
|
16484
|
+
* past a keyframe the overlay was still rebuilding (BLO-52085). The release
|
|
16485
|
+
* gate lets those frames go once only a late source can fill the gap
|
|
16486
|
+
* before them, as long after they arrived as the gap's decision allows
|
|
16487
|
+
* (isoRepairlessWaitMs).
|
|
16207
16488
|
*/
|
|
16208
16489
|
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
16209
16490
|
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
16210
|
-
if (!this.#blockAuthoredLengths.has(key))
|
|
16491
|
+
if (!this.#blockAuthoredLengths.has(key)) {
|
|
16492
|
+
this.#blockAuthoredLengths.set(key, span.block.length);
|
|
16493
|
+
this.#isoSpanKeys.add(key);
|
|
16494
|
+
if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
|
|
16495
|
+
}
|
|
16211
16496
|
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
16212
16497
|
}
|
|
16213
16498
|
/**
|
|
@@ -16245,6 +16530,62 @@ var FECManager = class _FECManager {
|
|
|
16245
16530
|
}
|
|
16246
16531
|
return lost;
|
|
16247
16532
|
}
|
|
16533
|
+
/**
|
|
16534
|
+
* The release gate's wait, from a frame's arrival, for the SS_IDs strictly
|
|
16535
|
+
* between two released frames' SS_IDs once only a late source can still
|
|
16536
|
+
* fill them, else undefined. That is when every one missing (neither
|
|
16537
|
+
* arrived nor held) lies in a repair-less span longer than K, which no
|
|
16538
|
+
* repair can state a block of (#openIsoSpan), or in a stated block its
|
|
16539
|
+
* own repair group cannot complete every SS_ID of which it misses lies
|
|
16540
|
+
* between them (so the gap's decision covers all it lost), and a multicast
|
|
16541
|
+
* source at or past `toSsId` arrived, so each is lost or reordered behind
|
|
16542
|
+
* it (a MoQ source shows nothing: MoQ streams overtake one another). The
|
|
16543
|
+
* span or block itself keeps its own wait.
|
|
16544
|
+
*
|
|
16545
|
+
* The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
|
|
16546
|
+
* hold a RAP packet an installed keyframe overlay can still rebuild (its
|
|
16547
|
+
* decision stalls, or it ends at a RAP that may lie past a whole MPU).
|
|
16548
|
+
* Then the frame waits as a stated block its group cannot complete does
|
|
16549
|
+
* (#overlayLateWaitMs): the allowance alone with no overlay installed, the
|
|
16550
|
+
* overlay's span plus the larger of the allowance and its tolerance, or,
|
|
16551
|
+
* for an overlay that states no span, the span's whole wait (undefined).
|
|
16552
|
+
* So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
|
|
16553
|
+
* the gap holds a stated block's loss.
|
|
16554
|
+
*/
|
|
16555
|
+
isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false) {
|
|
16556
|
+
const config = this.#trackConfigs.get(packetId);
|
|
16557
|
+
if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
|
|
16558
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
16559
|
+
if (locator === void 0 || !locator.coversBetween(fromSsId, toSsId)) return void 0;
|
|
16560
|
+
const newestSource = locator.newestSource;
|
|
16561
|
+
if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
|
|
16562
|
+
let repairless = false;
|
|
16563
|
+
let stated = false;
|
|
16564
|
+
for (const block of locator.blocksBetween(fromSsId, toSsId)) {
|
|
16565
|
+
const key = this.#blockKey(block.start, packetId, catalogTrackName);
|
|
16566
|
+
if (this.#completedBlocks.has(key)) continue;
|
|
16567
|
+
if (block.span && block.length > locator.kMax) {
|
|
16568
|
+
repairless = true;
|
|
16569
|
+
continue;
|
|
16570
|
+
}
|
|
16571
|
+
const received = this.#blockSourceEsis.get(key);
|
|
16572
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
16573
|
+
let missesInGap = false;
|
|
16574
|
+
let missesOutside = false;
|
|
16575
|
+
for (let esi = 0; esi < block.length; esi++) {
|
|
16576
|
+
const ssId = serial32Add(block.start, esi);
|
|
16577
|
+
if (received?.has(esi) || locator.isHeld(ssId)) continue;
|
|
16578
|
+
if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
|
|
16579
|
+
else if (!rebuilt?.has(esi)) missesOutside = true;
|
|
16580
|
+
}
|
|
16581
|
+
if (!missesInGap) continue;
|
|
16582
|
+
if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
|
|
16583
|
+
repairless = stated = true;
|
|
16584
|
+
}
|
|
16585
|
+
if (!repairless) return void 0;
|
|
16586
|
+
const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
|
|
16587
|
+
return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
|
|
16588
|
+
}
|
|
16248
16589
|
/**
|
|
16249
16590
|
* iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
|
|
16250
16591
|
* the sources held now for a block no repair has stated yet, and the held
|
|
@@ -16295,11 +16636,14 @@ var FECManager = class _FECManager {
|
|
|
16295
16636
|
/**
|
|
16296
16637
|
* Whether an MPU boundary still bounds this stream's RAPs (see
|
|
16297
16638
|
* `BlockClassifier.mpuBoundsRaps`). Gap decisions drop MPU evidence once
|
|
16298
|
-
* it does not. A stream with no classifier yet has shown nothing against it
|
|
16639
|
+
* it does not. A stream with no classifier yet has shown nothing against it,
|
|
16640
|
+
* and neither has a stream without catalog timing until it releases two
|
|
16641
|
+
* RAPs inside one MPU.
|
|
16299
16642
|
*/
|
|
16300
16643
|
mpuBoundsRapsFor(packetId, catalogTrackName) {
|
|
16301
|
-
|
|
16302
|
-
return this.#
|
|
16644
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16645
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true;
|
|
16646
|
+
return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true;
|
|
16303
16647
|
}
|
|
16304
16648
|
/** A block's class now, or frozen at its resolution. */
|
|
16305
16649
|
blockClassFor(sbn, packetId, catalogTrackName) {
|
|
@@ -16325,7 +16669,14 @@ var FECManager = class _FECManager {
|
|
|
16325
16669
|
* invariant (consecutive MPUs exactly one keyframe interval apart).
|
|
16326
16670
|
*/
|
|
16327
16671
|
noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale) {
|
|
16328
|
-
if (!this.#trackConfigs.has(packetId)
|
|
16672
|
+
if (!this.#trackConfigs.has(packetId)) return;
|
|
16673
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) {
|
|
16674
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
16675
|
+
const last = this.#noSpanRaps.get(streamKey);
|
|
16676
|
+
const inside = last?.inside === true || last?.mpu === mpu && last.presentationTime !== presentationTime;
|
|
16677
|
+
this.#noSpanRaps.set(streamKey, { mpu, presentationTime, inside });
|
|
16678
|
+
return;
|
|
16679
|
+
}
|
|
16329
16680
|
this.#applyClassifierChanges(
|
|
16330
16681
|
packetId,
|
|
16331
16682
|
catalogTrackName,
|
|
@@ -16538,11 +16889,14 @@ var FECManager = class _FECManager {
|
|
|
16538
16889
|
});
|
|
16539
16890
|
client.onCleanupComplete((sbn) => {
|
|
16540
16891
|
if (this.#releasedWorkerClients.has(client)) return;
|
|
16541
|
-
const
|
|
16892
|
+
const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client);
|
|
16893
|
+
const cleanupKeys = owed.filter((key) => {
|
|
16542
16894
|
const block = this.#parseBlockKey(key);
|
|
16543
|
-
return block.packetId === packetId && block.sbn === sbn
|
|
16895
|
+
return block.packetId === packetId && block.sbn === sbn;
|
|
16544
16896
|
});
|
|
16545
|
-
|
|
16897
|
+
const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity));
|
|
16898
|
+
const due = owed.filter((key) => !cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs);
|
|
16899
|
+
for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, "cleanup-ack");
|
|
16546
16900
|
});
|
|
16547
16901
|
client.onError((msg, code) => {
|
|
16548
16902
|
const requestedKind = code ?? msg;
|
|
@@ -16612,9 +16966,11 @@ var FECManager = class _FECManager {
|
|
|
16612
16966
|
* fail deadline already passed, so failing it is the decision that deadline
|
|
16613
16967
|
* made. A late ack then finds nothing owed and is a no-op.
|
|
16614
16968
|
*/
|
|
16615
|
-
#boundOwedCleanup(key, packetId, client) {
|
|
16969
|
+
#boundOwedCleanup(key, packetId, client, dueAtMs) {
|
|
16616
16970
|
this.#clearOwedCleanupBound(key);
|
|
16617
16971
|
const bound = {
|
|
16972
|
+
dueAtMs,
|
|
16973
|
+
askedAtMs: performance.now(),
|
|
16618
16974
|
handle: setTimeout(() => {
|
|
16619
16975
|
if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return;
|
|
16620
16976
|
this.#pendingWorkerCleanupBounds.delete(key);
|
|
@@ -16712,7 +17068,15 @@ var FECManager = class _FECManager {
|
|
|
16712
17068
|
this.#isoSourceOversizeCount++;
|
|
16713
17069
|
return null;
|
|
16714
17070
|
}
|
|
16715
|
-
|
|
17071
|
+
return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start);
|
|
17072
|
+
}
|
|
17073
|
+
/**
|
|
17074
|
+
* Hand one placed source symbol to the stream's decoder: its Worker, which
|
|
17075
|
+
* answers through onFrame (null here), or its synchronous decoder, whose
|
|
17076
|
+
* recovered block is returned. `sbn` is the SS_Start of the block a repair
|
|
17077
|
+
* stated for `ssId`.
|
|
17078
|
+
*/
|
|
17079
|
+
#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn) {
|
|
16716
17080
|
const blockKey = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
16717
17081
|
const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey);
|
|
16718
17082
|
const workerClient = this.#routableWorkerForPacket(packetId, catalogTrackName);
|
|
@@ -16741,6 +17105,74 @@ var FECManager = class _FECManager {
|
|
|
16741
17105
|
}
|
|
16742
17106
|
return recovered;
|
|
16743
17107
|
}
|
|
17108
|
+
/**
|
|
17109
|
+
* Feed a source symbol of this stream that another FEC instance over the
|
|
17110
|
+
* same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
|
|
17111
|
+
* caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
|
|
17112
|
+
* BLO-52085). It joins its block's decoder as a received source would, so
|
|
17113
|
+
* it reduces the erasures the block still has to solve, but it is not a
|
|
17114
|
+
* network arrival: no transport accounting, no classification evidence,
|
|
17115
|
+
* no deadline refresh, and it never makes a block clean.
|
|
17116
|
+
*
|
|
17117
|
+
* Only a block a repair stated takes one (a repair-less span has no
|
|
17118
|
+
* decoder block). A block that is terminal, or already holds that source,
|
|
17119
|
+
* does not. The symbol is the exact protected packet, unpadded, as
|
|
17120
|
+
* feedSourceSymbol takes it.
|
|
17121
|
+
*
|
|
17122
|
+
* `recovered` is the block the synchronous decoder completed with it; the
|
|
17123
|
+
* caller routes it and completes the block, as for any recovery. When
|
|
17124
|
+
* every source of the block is then present, received or rebuilt, and no
|
|
17125
|
+
* decoder returned it (a Worker answers asynchronously, and reports such a
|
|
17126
|
+
* block as clean on its own side), the block is completed here as
|
|
17127
|
+
* recovered, with nothing left to route.
|
|
17128
|
+
*/
|
|
17129
|
+
feedRebuiltSourceSymbol(packetId, ssId, symbolData, catalogTrackName) {
|
|
17130
|
+
if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN;
|
|
17131
|
+
const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId);
|
|
17132
|
+
if (located === null || located.block.span) return NOT_TAKEN;
|
|
17133
|
+
if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN;
|
|
17134
|
+
const sbn = located.block.start;
|
|
17135
|
+
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
17136
|
+
if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN;
|
|
17137
|
+
let rebuilt = this.#blockRebuiltEsis.get(key);
|
|
17138
|
+
if (rebuilt?.has(located.esi)) return NOT_TAKEN;
|
|
17139
|
+
if (rebuilt === void 0) {
|
|
17140
|
+
rebuilt = /* @__PURE__ */ new Set();
|
|
17141
|
+
this.#blockRebuiltEsis.set(key, rebuilt);
|
|
17142
|
+
}
|
|
17143
|
+
const config = this.#trackConfigs.get(packetId);
|
|
17144
|
+
const wasShort = config !== void 0 && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== void 0;
|
|
17145
|
+
rebuilt.add(located.esi);
|
|
17146
|
+
const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn);
|
|
17147
|
+
if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
|
|
17148
|
+
if (wasShort && this.#activeBlocks.has(key) && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) === void 0) {
|
|
17149
|
+
this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config));
|
|
17150
|
+
}
|
|
17151
|
+
}
|
|
17152
|
+
return { taken: true, recovered };
|
|
17153
|
+
}
|
|
17154
|
+
/**
|
|
17155
|
+
* A block that holds every one of its `length` sources, received or
|
|
17156
|
+
* rebuilt by another instance, with at least one rebuilt, is recovered:
|
|
17157
|
+
* every packet of it was delivered, by its own arrival or by the instance
|
|
17158
|
+
* that rebuilt it, so nothing is routed. Returns whether it completed it.
|
|
17159
|
+
*/
|
|
17160
|
+
#completeWhenSourcesPresent(key, sbn, length, packetId, catalogTrackName) {
|
|
17161
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
17162
|
+
if (rebuilt === void 0 || this.#completedBlocks.has(key)) return false;
|
|
17163
|
+
let present = rebuilt.size;
|
|
17164
|
+
for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++;
|
|
17165
|
+
if (present < length) return false;
|
|
17166
|
+
this.#traceLifecycle("recovered", sbn, packetId, catalogTrackName);
|
|
17167
|
+
this.countRecovery(packetId, sbn, catalogTrackName);
|
|
17168
|
+
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
17169
|
+
if (catalogTrackName === void 0) {
|
|
17170
|
+
this.onBlockComplete?.(sbn, packetId);
|
|
17171
|
+
} else {
|
|
17172
|
+
this.onBlockComplete?.(sbn, packetId, catalogTrackName);
|
|
17173
|
+
}
|
|
17174
|
+
return true;
|
|
17175
|
+
}
|
|
16744
17176
|
/**
|
|
16745
17177
|
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
16746
17178
|
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
@@ -16802,7 +17234,10 @@ var FECManager = class _FECManager {
|
|
|
16802
17234
|
this.#layerAnchorHorizon(packetId),
|
|
16803
17235
|
this.#sourceFrontiers.get(streamKey)?.sbn
|
|
16804
17236
|
);
|
|
16805
|
-
if (verdict === "discard")
|
|
17237
|
+
if (verdict === "discard") {
|
|
17238
|
+
this.#unlistedRepairTrackRefusals++;
|
|
17239
|
+
return false;
|
|
17240
|
+
}
|
|
16806
17241
|
if (verdict !== void 0) {
|
|
16807
17242
|
this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
|
|
16808
17243
|
return false;
|
|
@@ -16943,8 +17378,115 @@ var FECManager = class _FECManager {
|
|
|
16943
17378
|
this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName);
|
|
16944
17379
|
return null;
|
|
16945
17380
|
}
|
|
17381
|
+
if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName);
|
|
16946
17382
|
return recovered;
|
|
16947
17383
|
}
|
|
17384
|
+
/**
|
|
17385
|
+
* A first-arrival multicast source, held or placed. A datagram flow keeps
|
|
17386
|
+
* its sources in send order, so one that moves the stream's newest source
|
|
17387
|
+
* position past a block leaves the sources that block still misses
|
|
17388
|
+
* reordered behind it at best: it shortens the wait of every block it
|
|
17389
|
+
* passed that only a late source can complete. MoQ is left out: its streams
|
|
17390
|
+
* can overtake one another, so a MoQ source shows nothing about the sources
|
|
17391
|
+
* sent before it.
|
|
17392
|
+
*/
|
|
17393
|
+
#noteMulticastSource(locator, ssId, packetId, catalogTrackName) {
|
|
17394
|
+
const previous = locator.newestSource;
|
|
17395
|
+
if (!locator.noteSource(ssId) || previous === void 0) return;
|
|
17396
|
+
for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
|
|
17397
|
+
if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
|
|
17398
|
+
this.#shortenUnrecoverableWait(
|
|
17399
|
+
this.#blockKey(block.start, packetId, catalogTrackName),
|
|
17400
|
+
block.start,
|
|
17401
|
+
packetId,
|
|
17402
|
+
catalogTrackName
|
|
17403
|
+
);
|
|
17404
|
+
}
|
|
17405
|
+
}
|
|
17406
|
+
/**
|
|
17407
|
+
* The wait of a block that only a late source can complete (BLO-52085): a
|
|
17408
|
+
* repair stated it, its received sources plus every symbol its repair group
|
|
17409
|
+
* carries (RSB_length) are short of K' (the repair scheduler's
|
|
17410
|
+
* group-cannot-complete), and a later source of the stream has arrived, so
|
|
17411
|
+
* a source it misses is lost or reordered behind that one. The span, which
|
|
17412
|
+
* covers repair symbols paced after its sources, buys it nothing: it waits
|
|
17413
|
+
* the late-symbol allowance alone, the multicast wait less the span (the
|
|
17414
|
+
* catalog tolerance or the measured delivery gap). Undefined for any other
|
|
17415
|
+
* block. While a keyframe overlay is installed, the block waits for its
|
|
17416
|
+
* repair too (#overlayLateWaitMs). A repair-less span keeps its whole
|
|
17417
|
+
* wait, even one longer than K whose group is empty (#openIsoSpan): its
|
|
17418
|
+
* resolution is what releases the frames behind it, and failing it early
|
|
17419
|
+
* released them past a keyframe the overlay was still rebuilding, which
|
|
17420
|
+
* then arrived stale. The release gate lets them go instead
|
|
17421
|
+
* (isoRepairlessWaitMs).
|
|
17422
|
+
*/
|
|
17423
|
+
#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
|
|
17424
|
+
if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
|
|
17425
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
17426
|
+
const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
|
|
17427
|
+
if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
|
|
17428
|
+
return void 0;
|
|
17429
|
+
}
|
|
17430
|
+
return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
|
|
17431
|
+
}
|
|
17432
|
+
/**
|
|
17433
|
+
* A repair stated the block, and its sources plus every symbol its repair
|
|
17434
|
+
* group carries (RSB_length) are short of its SSB_length.
|
|
17435
|
+
*/
|
|
17436
|
+
#groupCannotComplete(key) {
|
|
17437
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
17438
|
+
const rsbLength = this.#blockRsbLengths.get(key);
|
|
17439
|
+
if (authoredLength === void 0 || rsbLength === void 0) return false;
|
|
17440
|
+
let present = this.#blockSourceCounts.get(key) ?? 0;
|
|
17441
|
+
const received = this.#blockSourceEsis.get(key);
|
|
17442
|
+
for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
|
|
17443
|
+
return present + rsbLength < authoredLength;
|
|
17444
|
+
}
|
|
17445
|
+
/**
|
|
17446
|
+
* How long a loss only a late source or an installed keyframe overlay can
|
|
17447
|
+
* still fill waits once a later source passed it: the late-symbol
|
|
17448
|
+
* allowance alone (the multicast wait less the span) while no overlay is
|
|
17449
|
+
* installed. An installed one (keyframeOverlayTiming) may still rebuild a
|
|
17450
|
+
* RAP packet the loss took: a second FEC instance over the same packets
|
|
17451
|
+
* (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
|
|
17452
|
+
* span, unrelated to the base's. That packet can complete a stated block
|
|
17453
|
+
* (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
|
|
17454
|
+
* first lets the release gate pass the keyframe, whose rebuild then lands
|
|
17455
|
+
* stale. The overlay repair of a packet the loss took goes out within the
|
|
17456
|
+
* overlay's span of that packet (fec-core-00 9.3), and the later source was
|
|
17457
|
+
* sent after it, so the loss waits that span plus the larger of the
|
|
17458
|
+
* allowance and the overlay's own tolerance. An overlay that states no
|
|
17459
|
+
* span (its block may then span keyframes), or one whose wait is not
|
|
17460
|
+
* shorter than the whole multicast wait, leaves the whole wait: undefined.
|
|
17461
|
+
*/
|
|
17462
|
+
#overlayLateWaitMs(packetId, catalogTrackName, config) {
|
|
17463
|
+
const waitMs = this.#multicastWaitMs(config);
|
|
17464
|
+
const allowanceMs = waitMs - config.interleaveDepthMs;
|
|
17465
|
+
const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
|
|
17466
|
+
if (overlay === void 0) return allowanceMs;
|
|
17467
|
+
const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
|
|
17468
|
+
const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
|
|
17469
|
+
return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
|
|
17470
|
+
}
|
|
17471
|
+
/**
|
|
17472
|
+
* Bring an open block's wait in to its late-source wait, when it has one.
|
|
17473
|
+
* Never later than it is armed: only a source can complete such a block,
|
|
17474
|
+
* so a repair of its group (paced across the span) must not keep it open.
|
|
17475
|
+
*/
|
|
17476
|
+
#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName) {
|
|
17477
|
+
if (!this.#activeBlocks.has(key)) return;
|
|
17478
|
+
const config = this.#trackConfigs.get(packetId);
|
|
17479
|
+
if (config === void 0) return;
|
|
17480
|
+
const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config);
|
|
17481
|
+
if (waitMs === void 0) return;
|
|
17482
|
+
const armedAtMs = this.#blockWaitDeadlinesMs.get(key);
|
|
17483
|
+
this.#armBlockTimeout(
|
|
17484
|
+
sbn,
|
|
17485
|
+
packetId,
|
|
17486
|
+
catalogTrackName,
|
|
17487
|
+
armedAtMs === void 0 ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow())
|
|
17488
|
+
);
|
|
17489
|
+
}
|
|
16948
17490
|
/**
|
|
16949
17491
|
* Record a block's authored SSB_length from a repair symbol. Returns false,
|
|
16950
17492
|
* leaving the block unchanged, when the symbol contradicts the block: a
|
|
@@ -17042,12 +17584,13 @@ var FECManager = class _FECManager {
|
|
|
17042
17584
|
* the inactivity deadline on each symbol, records the symbol's in-band
|
|
17043
17585
|
* classification evidence, and marks the block clean when all of its
|
|
17044
17586
|
* authored source symbols arrived: the SSB_length a repair symbol declared,
|
|
17045
|
-
* otherwise K.
|
|
17587
|
+
* otherwise K. `held` marks a source held unplaced since it arrived and
|
|
17588
|
+
* placed only now (see #noteSbnSeen).
|
|
17046
17589
|
*
|
|
17047
17590
|
* Throws for a packetId that was never configured, so a classified block
|
|
17048
17591
|
* never reads the manager-global K or timeout.
|
|
17049
17592
|
*/
|
|
17050
|
-
trackBlock(sbn, packetId, catalogTrackName, esi, evidence) {
|
|
17593
|
+
trackBlock(sbn, packetId, catalogTrackName, esi, evidence, held = false) {
|
|
17051
17594
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
17052
17595
|
if (trackConfig === void 0) {
|
|
17053
17596
|
throw new Error(
|
|
@@ -17063,7 +17606,8 @@ var FECManager = class _FECManager {
|
|
|
17063
17606
|
catalogTrackName,
|
|
17064
17607
|
"source",
|
|
17065
17608
|
evidence.packetSequenceNumber,
|
|
17066
|
-
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
17609
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn,
|
|
17610
|
+
held
|
|
17067
17611
|
);
|
|
17068
17612
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
17069
17613
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
@@ -17099,6 +17643,15 @@ var FECManager = class _FECManager {
|
|
|
17099
17643
|
this.#completeCleanBlock(key, sbn, packetId, catalogTrackName);
|
|
17100
17644
|
return;
|
|
17101
17645
|
}
|
|
17646
|
+
if (this.#blockRebuiltEsis.has(key) && this.#completeWhenSourcesPresent(
|
|
17647
|
+
key,
|
|
17648
|
+
sbn,
|
|
17649
|
+
this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
|
|
17650
|
+
packetId,
|
|
17651
|
+
catalogTrackName
|
|
17652
|
+
)) {
|
|
17653
|
+
return;
|
|
17654
|
+
}
|
|
17102
17655
|
this.noteBlockActivity(sbn, packetId, catalogTrackName, true);
|
|
17103
17656
|
}
|
|
17104
17657
|
#completeCleanBlock(key, sbn, packetId, catalogTrackName) {
|
|
@@ -17107,7 +17660,9 @@ var FECManager = class _FECManager {
|
|
|
17107
17660
|
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
17108
17661
|
this.#blockSourceCounts.delete(key);
|
|
17109
17662
|
this.#blockSourceEsis.delete(key);
|
|
17663
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17110
17664
|
this.#blockAuthoredLengths.delete(key);
|
|
17665
|
+
this.#isoSpanKeys.delete(key);
|
|
17111
17666
|
this.#blockRepairRsIds.delete(key);
|
|
17112
17667
|
this.#blockRsbLengths.delete(key);
|
|
17113
17668
|
this.#markTerminal(key, sbn, packetId, true);
|
|
@@ -17138,6 +17693,19 @@ var FECManager = class _FECManager {
|
|
|
17138
17693
|
#receiptNow() {
|
|
17139
17694
|
return this.#receiptAtMs ?? performance.now();
|
|
17140
17695
|
}
|
|
17696
|
+
/**
|
|
17697
|
+
* The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
|
|
17698
|
+
* scope: counted from the receipt time, as the timer of a symbol fed when
|
|
17699
|
+
* it was received was, less the whole ms since. So it fires on the tick
|
|
17700
|
+
* that timer would have, never later than a delay counted from now, and
|
|
17701
|
+
* its handler still re-arms a timer that fires before its deadline.
|
|
17702
|
+
* Counted from now, a deadline set from the receipt time is rounded up
|
|
17703
|
+
* from another fraction of a ms (BLO-52085).
|
|
17704
|
+
*/
|
|
17705
|
+
#receiptTimerDelayMs(deadlineMs, minMs) {
|
|
17706
|
+
const receivedAtMs = this.#receiptAtMs;
|
|
17707
|
+
return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs));
|
|
17708
|
+
}
|
|
17141
17709
|
/**
|
|
17142
17710
|
* A held packet admitted late arms from its (earlier) receipt time; that
|
|
17143
17711
|
* never pulls in a deadline later activity already armed. Outside a
|
|
@@ -17173,10 +17741,20 @@ var FECManager = class _FECManager {
|
|
|
17173
17741
|
this.#repairDeadlineMs(trackConfig)
|
|
17174
17742
|
);
|
|
17175
17743
|
}
|
|
17176
|
-
this.#
|
|
17744
|
+
if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== void 0) {
|
|
17745
|
+
this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName);
|
|
17746
|
+
return;
|
|
17747
|
+
}
|
|
17748
|
+
this.#armBlockTimeout(
|
|
17749
|
+
sbn,
|
|
17750
|
+
packetId,
|
|
17751
|
+
catalogTrackName,
|
|
17752
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs
|
|
17753
|
+
);
|
|
17177
17754
|
}
|
|
17178
17755
|
#failBlock(sbn, packetId, catalogTrackName) {
|
|
17179
17756
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
17757
|
+
const span = this.#isoSpanKeys.delete(key) ? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 } : void 0;
|
|
17180
17758
|
this.#traceLifecycle("failed", sbn, packetId, catalogTrackName);
|
|
17181
17759
|
this.#clearRepairDeadline(key);
|
|
17182
17760
|
this.#clearBlockTimer(key);
|
|
@@ -17186,6 +17764,7 @@ var FECManager = class _FECManager {
|
|
|
17186
17764
|
}
|
|
17187
17765
|
this.#blockSourceCounts.delete(key);
|
|
17188
17766
|
this.#blockSourceEsis.delete(key);
|
|
17767
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17189
17768
|
this.#blockAuthoredLengths.delete(key);
|
|
17190
17769
|
this.#blockRepairRsIds.delete(key);
|
|
17191
17770
|
this.#blockRsbLengths.delete(key);
|
|
@@ -17195,7 +17774,8 @@ var FECManager = class _FECManager {
|
|
|
17195
17774
|
this.#markPathBlockComplete(sbn, packetId, catalogTrackName);
|
|
17196
17775
|
this.#fecStats.blocksFailed++;
|
|
17197
17776
|
this.#statsForPacket(packetId).blocksFailed++;
|
|
17198
|
-
this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
17777
|
+
if (span === void 0) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
17778
|
+
else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
17199
17779
|
this.onBlockResolved?.(sbn, packetId, catalogTrackName);
|
|
17200
17780
|
}
|
|
17201
17781
|
/**
|
|
@@ -17224,7 +17804,9 @@ var FECManager = class _FECManager {
|
|
|
17224
17804
|
this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName);
|
|
17225
17805
|
this.#blockSourceCounts.delete(key);
|
|
17226
17806
|
this.#blockSourceEsis.delete(key);
|
|
17807
|
+
this.#blockRebuiltEsis.delete(key);
|
|
17227
17808
|
this.#blockAuthoredLengths.delete(key);
|
|
17809
|
+
this.#isoSpanKeys.delete(key);
|
|
17228
17810
|
this.#blockRepairRsIds.delete(key);
|
|
17229
17811
|
this.#blockRsbLengths.delete(key);
|
|
17230
17812
|
this.#clearBlockTimer(key);
|
|
@@ -17315,7 +17897,9 @@ var FECManager = class _FECManager {
|
|
|
17315
17897
|
this.#blockKeysBySbn.clear();
|
|
17316
17898
|
this.#blockSourceCounts.clear();
|
|
17317
17899
|
this.#blockSourceEsis.clear();
|
|
17900
|
+
this.#blockRebuiltEsis.clear();
|
|
17318
17901
|
this.#blockAuthoredLengths.clear();
|
|
17902
|
+
this.#isoSpanKeys.clear();
|
|
17319
17903
|
this.#blockRepairRsIds.clear();
|
|
17320
17904
|
this.#blockRsbLengths.clear();
|
|
17321
17905
|
this.#heldLayerStates.clear();
|
|
@@ -17340,6 +17924,7 @@ var FECManager = class _FECManager {
|
|
|
17340
17924
|
this.#blockAnchorsMs.clear();
|
|
17341
17925
|
this.#blockCatalogTrackNames.clear();
|
|
17342
17926
|
this.#classifiers.clear();
|
|
17927
|
+
this.#noSpanRaps.clear();
|
|
17343
17928
|
this.#streamGeometries.clear();
|
|
17344
17929
|
this.#failedBlocks.clear();
|
|
17345
17930
|
this.#resolvedBlockClasses.clear();
|
|
@@ -17870,9 +18455,21 @@ var IsoBmffTimingResolver = class {
|
|
|
17870
18455
|
}
|
|
17871
18456
|
#track = null;
|
|
17872
18457
|
#fragments = /* @__PURE__ */ new Map();
|
|
18458
|
+
/** First sample of each pending fragment, kept in `#delivered` with its sample count. */
|
|
18459
|
+
#firstSamples = /* @__PURE__ */ new Map();
|
|
18460
|
+
/**
|
|
18461
|
+
* First sample and sample count of the newest fragments whose every slot was
|
|
18462
|
+
* cleared. Abandonment counts: `releaseSample` clears a slot too, which
|
|
18463
|
+
* matches the combiner, since it retires an abandoned sample as well.
|
|
18464
|
+
*/
|
|
18465
|
+
#delivered = /* @__PURE__ */ new Map();
|
|
17873
18466
|
#pendingSamples = 0;
|
|
17874
18467
|
#evictedSamples = 0;
|
|
17875
18468
|
#lastMovieFragmentRejection = null;
|
|
18469
|
+
/** True once an FT=0 has bound the track that FT=1 timing is read against. */
|
|
18470
|
+
get initialized() {
|
|
18471
|
+
return this.#track !== null;
|
|
18472
|
+
}
|
|
17876
18473
|
get pendingSampleCount() {
|
|
17877
18474
|
return this.#pendingSamples;
|
|
17878
18475
|
}
|
|
@@ -17896,7 +18493,14 @@ var IsoBmffTimingResolver = class {
|
|
|
17896
18493
|
this.#track = timing;
|
|
17897
18494
|
return true;
|
|
17898
18495
|
}
|
|
17899
|
-
|
|
18496
|
+
/**
|
|
18497
|
+
* `recovered` marks an FEC-recovered copy. A recovered block hands back
|
|
18498
|
+
* every FT=1 it holds, the received ones included, so a recovered copy of a
|
|
18499
|
+
* fragment whose samples are all done is a duplicate: admitting it again
|
|
18500
|
+
* would charge stale timing and could displace the live MPU's. A source
|
|
18501
|
+
* copy is still admitted again (a rendition switch re-arms timing that way).
|
|
18502
|
+
*/
|
|
18503
|
+
addMovieFragment(mpuSequenceNumber2, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
|
|
17900
18504
|
this.#lastMovieFragmentRejection = null;
|
|
17901
18505
|
if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
|
|
17902
18506
|
this.#lastMovieFragmentRejection = "invalid";
|
|
@@ -17922,6 +18526,8 @@ var IsoBmffTimingResolver = class {
|
|
|
17922
18526
|
(sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
|
|
17923
18527
|
);
|
|
17924
18528
|
}
|
|
18529
|
+
const delivered = recovered ? this.#delivered.get(key) : void 0;
|
|
18530
|
+
if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
|
|
17925
18531
|
let freed = 0;
|
|
17926
18532
|
while (this.#fragments.size > 0 && (this.#pendingSamples + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
|
|
17927
18533
|
freed += this.#evictOldestFragment();
|
|
@@ -17935,6 +18541,7 @@ var IsoBmffTimingResolver = class {
|
|
|
17935
18541
|
return false;
|
|
17936
18542
|
}
|
|
17937
18543
|
this.#fragments.set(key, [...parsed.samples]);
|
|
18544
|
+
this.#firstSamples.set(key, parsed.samples[0]);
|
|
17938
18545
|
this.#pendingSamples += parsed.samples.length;
|
|
17939
18546
|
return true;
|
|
17940
18547
|
}
|
|
@@ -17992,6 +18599,7 @@ var IsoBmffTimingResolver = class {
|
|
|
17992
18599
|
let live = 0;
|
|
17993
18600
|
for (const sample of samples) if (sample !== null) live++;
|
|
17994
18601
|
this.#fragments.delete(oldest);
|
|
18602
|
+
this.#firstSamples.delete(oldest);
|
|
17995
18603
|
this.#pendingSamples -= live;
|
|
17996
18604
|
this.#evictedSamples += live;
|
|
17997
18605
|
return live;
|
|
@@ -18007,12 +18615,23 @@ var IsoBmffTimingResolver = class {
|
|
|
18007
18615
|
if (!samples || !samples[index]) return false;
|
|
18008
18616
|
samples[index] = null;
|
|
18009
18617
|
this.#pendingSamples--;
|
|
18010
|
-
if (samples.every((value) => value === null))
|
|
18618
|
+
if (samples.every((value) => value === null)) {
|
|
18619
|
+
this.#fragments.delete(key);
|
|
18620
|
+
const first = this.#firstSamples.get(key);
|
|
18621
|
+
this.#firstSamples.delete(key);
|
|
18622
|
+
this.#delivered.delete(key);
|
|
18623
|
+
this.#delivered.set(key, { first, sampleCount: samples.length });
|
|
18624
|
+
if (this.#delivered.size > this.maxPendingSamples) {
|
|
18625
|
+
this.#delivered.delete(this.#delivered.keys().next().value);
|
|
18626
|
+
}
|
|
18627
|
+
}
|
|
18011
18628
|
return true;
|
|
18012
18629
|
}
|
|
18013
18630
|
reset() {
|
|
18014
18631
|
this.#track = null;
|
|
18015
18632
|
this.#fragments.clear();
|
|
18633
|
+
this.#firstSamples.clear();
|
|
18634
|
+
this.#delivered.clear();
|
|
18016
18635
|
this.#pendingSamples = 0;
|
|
18017
18636
|
}
|
|
18018
18637
|
};
|
|
@@ -18182,6 +18801,9 @@ function authoredGap(before, after) {
|
|
|
18182
18801
|
function ssIdAfter(a, b) {
|
|
18183
18802
|
return (a - b | 0) > 0;
|
|
18184
18803
|
}
|
|
18804
|
+
function holdsRebuilt(stream) {
|
|
18805
|
+
return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
|
|
18806
|
+
}
|
|
18185
18807
|
var FecReleaseSequencer = class {
|
|
18186
18808
|
#streams = /* @__PURE__ */ new Map();
|
|
18187
18809
|
#gate;
|
|
@@ -18244,6 +18866,7 @@ var FecReleaseSequencer = class {
|
|
|
18244
18866
|
stream.lastSbn = void 0;
|
|
18245
18867
|
stream.discontinuity = false;
|
|
18246
18868
|
stream.rapSsId = void 0;
|
|
18869
|
+
stream.sourced = false;
|
|
18247
18870
|
}
|
|
18248
18871
|
if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
|
|
18249
18872
|
this.#recordStat("droppedStale");
|
|
@@ -18270,6 +18893,7 @@ var FecReleaseSequencer = class {
|
|
|
18270
18893
|
if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
|
|
18271
18894
|
else hi = mid;
|
|
18272
18895
|
}
|
|
18896
|
+
if (stream.buf[lo]?.passed === true) frame.passed = true;
|
|
18273
18897
|
stream.buf.splice(lo, 0, frame);
|
|
18274
18898
|
this.#drainUnlessDeferred(stream);
|
|
18275
18899
|
}
|
|
@@ -18305,6 +18929,41 @@ var FecReleaseSequencer = class {
|
|
|
18305
18929
|
}
|
|
18306
18930
|
return false;
|
|
18307
18931
|
}
|
|
18932
|
+
/**
|
|
18933
|
+
* These streams' sink is being replaced by one that has seen no source
|
|
18934
|
+
* frame yet. First, from a stream that holds a frame the overlay rebuilt,
|
|
18935
|
+
* release to the sink being replaced the frames the unanchored path had
|
|
18936
|
+
* already released to it (#cursorPassed): there they waited in its queue,
|
|
18937
|
+
* which its replacement flushes. A stream that holds none is not drained:
|
|
18938
|
+
* it holds nothing the anchor kept back, and a drain would still force out
|
|
18939
|
+
* a frame held past the hold limit, which before the anchor waited for the
|
|
18940
|
+
* next push. Then treat the streams as unsourced until a source frame is
|
|
18941
|
+
* released.
|
|
18942
|
+
*/
|
|
18943
|
+
unsource(packetId, catalogTrackName) {
|
|
18944
|
+
for (const stream of this.#streams.values()) {
|
|
18945
|
+
if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
|
|
18946
|
+
if (stream.draining === 0 && holdsRebuilt(stream)) {
|
|
18947
|
+
if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
|
|
18948
|
+
else this.#drain(stream, true);
|
|
18949
|
+
}
|
|
18950
|
+
stream.sourced = false;
|
|
18951
|
+
}
|
|
18952
|
+
}
|
|
18953
|
+
}
|
|
18954
|
+
/**
|
|
18955
|
+
* Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
|
|
18956
|
+
* (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
|
|
18957
|
+
* packetId.
|
|
18958
|
+
*/
|
|
18959
|
+
holdsRebuilt(packetId, catalogTrackName) {
|
|
18960
|
+
for (const stream of this.#streams.values()) {
|
|
18961
|
+
if (stream.packetId !== packetId) continue;
|
|
18962
|
+
if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
|
|
18963
|
+
if (holdsRebuilt(stream)) return true;
|
|
18964
|
+
}
|
|
18965
|
+
return false;
|
|
18966
|
+
}
|
|
18308
18967
|
/** Re-evaluate held gaps after FEC state changed. */
|
|
18309
18968
|
poke(streamKey) {
|
|
18310
18969
|
if (streamKey !== void 0) {
|
|
@@ -18396,16 +19055,32 @@ var FecReleaseSequencer = class {
|
|
|
18396
19055
|
last: null,
|
|
18397
19056
|
lastSbn: void 0,
|
|
18398
19057
|
discontinuity: false,
|
|
18399
|
-
rapSsId: void 0
|
|
19058
|
+
rapSsId: void 0,
|
|
19059
|
+
sourced: false,
|
|
19060
|
+
draining: 0
|
|
18400
19061
|
};
|
|
18401
19062
|
this.#streams.set(streamKey, stream);
|
|
18402
19063
|
}
|
|
18403
19064
|
return stream;
|
|
18404
19065
|
}
|
|
18405
|
-
#
|
|
19066
|
+
/** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
|
|
19067
|
+
#drain(stream, asUnanchored = false) {
|
|
19068
|
+
stream.draining++;
|
|
19069
|
+
try {
|
|
19070
|
+
this.#drainLoop(stream, asUnanchored);
|
|
19071
|
+
} finally {
|
|
19072
|
+
stream.draining--;
|
|
19073
|
+
}
|
|
19074
|
+
}
|
|
19075
|
+
#drainLoop(stream, asUnanchored) {
|
|
18406
19076
|
while (stream.buf.length > 0 && stream.last !== null) {
|
|
18407
19077
|
const head = stream.buf[0];
|
|
18408
19078
|
const last = stream.last;
|
|
19079
|
+
if (compareFrameOrder(head, last) <= 0) {
|
|
19080
|
+
stream.buf.shift();
|
|
19081
|
+
this.#release(stream, head, void 0);
|
|
19082
|
+
continue;
|
|
19083
|
+
}
|
|
18409
19084
|
if (stream.discontinuity) {
|
|
18410
19085
|
stream.discontinuity = false;
|
|
18411
19086
|
stream.buf.shift();
|
|
@@ -18419,9 +19094,10 @@ var FecReleaseSequencer = class {
|
|
|
18419
19094
|
}
|
|
18420
19095
|
const headSbn = head.meta.fecSbn;
|
|
18421
19096
|
const from = stream.lastSbn ?? headSbn;
|
|
18422
|
-
const to = headSbn ?? stream.lastSbn;
|
|
19097
|
+
const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
|
|
18423
19098
|
let lost = [];
|
|
18424
19099
|
const unanchored = from === void 0 && to === void 0;
|
|
19100
|
+
let unresolved = false;
|
|
18425
19101
|
if (from !== void 0 && to !== void 0) {
|
|
18426
19102
|
const resolved = this.#gate.resolvedLoss(
|
|
18427
19103
|
stream.packetId,
|
|
@@ -18430,7 +19106,8 @@ var FecReleaseSequencer = class {
|
|
|
18430
19106
|
Math.max(from, to),
|
|
18431
19107
|
from
|
|
18432
19108
|
);
|
|
18433
|
-
|
|
19109
|
+
unresolved = resolved === null;
|
|
19110
|
+
if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
|
|
18434
19111
|
const heldMs = performance.now() - head.arrivedAtMs;
|
|
18435
19112
|
if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
|
|
18436
19113
|
this.#recordStat("forcedWindowFlushes");
|
|
@@ -18438,22 +19115,69 @@ var FecReleaseSequencer = class {
|
|
|
18438
19115
|
this.#release(stream, head, this.#gate.decide(last, head, [], true));
|
|
18439
19116
|
continue;
|
|
18440
19117
|
}
|
|
18441
|
-
lost = resolved;
|
|
19118
|
+
lost = resolved ?? [];
|
|
18442
19119
|
}
|
|
18443
19120
|
stream.buf.shift();
|
|
18444
19121
|
this.#release(
|
|
18445
19122
|
stream,
|
|
18446
19123
|
head,
|
|
18447
|
-
lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
19124
|
+
lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
18448
19125
|
);
|
|
18449
19126
|
}
|
|
18450
19127
|
}
|
|
19128
|
+
/**
|
|
19129
|
+
* The head has waited out a gap only a late source can still fill
|
|
19130
|
+
* (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
|
|
19131
|
+
* the stream when it has (`wakeAt`), since no packet may come by then.
|
|
19132
|
+
*/
|
|
19133
|
+
#unrepairableWaitOver(stream, last, head, from, to) {
|
|
19134
|
+
const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
|
|
19135
|
+
if (waitMs === void 0) return false;
|
|
19136
|
+
const atMs = head.arrivedAtMs + waitMs;
|
|
19137
|
+
if (performance.now() >= atMs) return true;
|
|
19138
|
+
this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
|
|
19139
|
+
return false;
|
|
19140
|
+
}
|
|
19141
|
+
/**
|
|
19142
|
+
* An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
|
|
19143
|
+
* source cursor holds it unanchored, and neither does a later frame behind
|
|
19144
|
+
* it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
|
|
19145
|
+
* fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
|
|
19146
|
+
* like each frame that arrived in front of it since (stale there). The head
|
|
19147
|
+
* then goes, decided as it would be unanchored, once a frame the base path
|
|
19148
|
+
* delivered (a source frame, or one base FEC recovered) is buffered after a
|
|
19149
|
+
* marked one: the base path has passed that one, so a frame still missing
|
|
19150
|
+
* before it can only come from a repair. It also goes while no source frame
|
|
19151
|
+
* has been released, when the direct path shows a recovered frame at once.
|
|
19152
|
+
* And it goes at once while a staged switch decides on when frames arrive
|
|
19153
|
+
* (FecReleaseGate.releaseUnanchored), and when unsource releases into a
|
|
19154
|
+
* sink being replaced: unanchored, it had already reached the sink.
|
|
19155
|
+
* The scan also writes: the `passed` marks it sets stay on the frames,
|
|
19156
|
+
* and push marks a frame it inserts in front of a marked one from them.
|
|
19157
|
+
*/
|
|
19158
|
+
#cursorPassed(stream, asUnanchored) {
|
|
19159
|
+
let at2 = -1;
|
|
19160
|
+
for (let i = 0; i < stream.buf.length; i++) {
|
|
19161
|
+
const frame = stream.buf[i];
|
|
19162
|
+
if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
|
|
19163
|
+
frame.passed = true;
|
|
19164
|
+
if (at2 < 0) at2 = i;
|
|
19165
|
+
} else if (frame.passed !== true) break;
|
|
19166
|
+
}
|
|
19167
|
+
if (at2 < 0) return false;
|
|
19168
|
+
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));
|
|
19169
|
+
}
|
|
18451
19170
|
#release(stream, frame, decision) {
|
|
19171
|
+
const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
|
|
19172
|
+
if (stale) this.#recordStat("droppedStale");
|
|
18452
19173
|
if (decision) frame.meta.gapBefore = decision;
|
|
18453
19174
|
stream.last = frame;
|
|
18454
|
-
if (frame.meta.fecSbn !== void 0
|
|
19175
|
+
if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
|
|
19176
|
+
stream.lastSbn = frame.meta.fecSbn;
|
|
19177
|
+
}
|
|
19178
|
+
if (frame.meta.recovered !== true) stream.sourced = true;
|
|
18455
19179
|
this.#gate.onReleased?.(frame.data, frame.meta);
|
|
18456
|
-
this.#emit(frame.data, frame.meta);
|
|
19180
|
+
if (!stale) this.#emit(frame.data, frame.meta);
|
|
18457
19181
|
}
|
|
18458
19182
|
};
|
|
18459
19183
|
var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
|
|
@@ -18494,6 +19218,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18494
19218
|
this.#reclaimedTimingSamples = 0;
|
|
18495
19219
|
this.#evictedTimingSamples = 0;
|
|
18496
19220
|
this.#rejectedMovieFragments = 0;
|
|
19221
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
19222
|
+
held: 0,
|
|
19223
|
+
expired: 0,
|
|
19224
|
+
discarded: 0,
|
|
19225
|
+
superseded: 0
|
|
19226
|
+
};
|
|
18497
19227
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
18498
19228
|
this.#fecGate = null;
|
|
18499
19229
|
this.#fecSequencer = null;
|
|
@@ -18602,6 +19332,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18602
19332
|
#reclaimedTimingSamples;
|
|
18603
19333
|
#evictedTimingSamples;
|
|
18604
19334
|
#rejectedMovieFragments;
|
|
19335
|
+
#recoveredHeadsAwaitingTiming;
|
|
18605
19336
|
#sequencers;
|
|
18606
19337
|
#fecGate;
|
|
18607
19338
|
#fecSequencer;
|
|
@@ -18707,11 +19438,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18707
19438
|
/**
|
|
18708
19439
|
* Typed view of the ISO-BMFF timing-sample budget.
|
|
18709
19440
|
*
|
|
18710
|
-
*
|
|
18711
|
-
*
|
|
18712
|
-
*
|
|
18713
|
-
*
|
|
18714
|
-
*
|
|
19441
|
+
* Each stream admits timing against its own window of `capacity` slots
|
|
19442
|
+
* (BLO-52085). A stream at capacity displaces its own oldest timing to
|
|
19443
|
+
* admit the moof in hand, and `evicted` counts the slots so displaced:
|
|
19444
|
+
* timing a stream declared and never delivered shows up there. `pending`
|
|
19445
|
+
* sums every stream, so it can exceed `capacity`. Per repo policy this is
|
|
19446
|
+
* a producer-owned counter -- never infer budget state by parsing logs.
|
|
18715
19447
|
*/
|
|
18716
19448
|
get timingBudgetStats() {
|
|
18717
19449
|
return {
|
|
@@ -18722,6 +19454,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18722
19454
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
18723
19455
|
};
|
|
18724
19456
|
}
|
|
19457
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
19458
|
+
get recoveredHeadsAwaitingTiming() {
|
|
19459
|
+
let pending = 0;
|
|
19460
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
19461
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
19462
|
+
}
|
|
19463
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
19464
|
+
}
|
|
18725
19465
|
get reorderStats() {
|
|
18726
19466
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
18727
19467
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -18763,6 +19503,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18763
19503
|
fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
|
|
18764
19504
|
return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
|
|
18765
19505
|
}
|
|
19506
|
+
/** See FecReleaseSequencer.unsource. */
|
|
19507
|
+
unsourceFecRelease(packetId, catalogTrackName) {
|
|
19508
|
+
this.#fecSequencer?.unsource(packetId, catalogTrackName);
|
|
19509
|
+
}
|
|
19510
|
+
/** See FecReleaseSequencer.holdsRebuilt. */
|
|
19511
|
+
fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
|
|
19512
|
+
return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
|
|
19513
|
+
}
|
|
18766
19514
|
/** Re-evaluate held gaps after FEC block state changed. */
|
|
18767
19515
|
pokeFecRelease(packetId, catalogTrackName) {
|
|
18768
19516
|
if (!this.#fecSequencer) return;
|
|
@@ -18850,10 +19598,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18850
19598
|
get reassemblerDataUnitsReturned() {
|
|
18851
19599
|
return this.#reassemblerDataUnitsReturned;
|
|
18852
19600
|
}
|
|
18853
|
-
#countOutcome(
|
|
18854
|
-
const count = (this.#feedOutcomes.get(
|
|
18855
|
-
this.#feedOutcomes.set(
|
|
18856
|
-
this.#lastOutcome =
|
|
19601
|
+
#countOutcome(token2) {
|
|
19602
|
+
const count = (this.#feedOutcomes.get(token2) ?? 0) + 1;
|
|
19603
|
+
this.#feedOutcomes.set(token2, count);
|
|
19604
|
+
this.#lastOutcome = token2;
|
|
18857
19605
|
this.#lastOutcomeCount = count;
|
|
18858
19606
|
}
|
|
18859
19607
|
#countDeferredOutcome(reason) {
|
|
@@ -18895,7 +19643,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
18895
19643
|
const now = Date.now();
|
|
18896
19644
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
18897
19645
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
18898
|
-
awaitingTiming.shift();
|
|
19646
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
18899
19647
|
}
|
|
18900
19648
|
}
|
|
18901
19649
|
}
|
|
@@ -19013,11 +19761,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19013
19761
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
19014
19762
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
19015
19763
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
19016
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
19764
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
19017
19765
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
19018
19766
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
19019
|
-
const remaining = this.#maxPendingTimingSamples -
|
|
19020
|
-
const admitted = resolver2.addMovieFragment(
|
|
19767
|
+
const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
|
|
19768
|
+
const admitted = resolver2.addMovieFragment(
|
|
19769
|
+
mpu.mpuSequenceNumber,
|
|
19770
|
+
data,
|
|
19771
|
+
remaining,
|
|
19772
|
+
options?.recovered === true
|
|
19773
|
+
);
|
|
19021
19774
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
19022
19775
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
19023
19776
|
if (!admitted) {
|
|
@@ -19037,7 +19790,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19037
19790
|
};
|
|
19038
19791
|
}
|
|
19039
19792
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
19040
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
19793
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
19041
19794
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
19042
19795
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
19043
19796
|
return this.#drop("mfu-empty-payload");
|
|
@@ -19058,6 +19811,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19058
19811
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
19059
19812
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
19060
19813
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
19814
|
+
sequenceNumber: info.sequenceNumber,
|
|
19061
19815
|
arrivedAt: Date.now()
|
|
19062
19816
|
});
|
|
19063
19817
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -19083,7 +19837,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19083
19837
|
info,
|
|
19084
19838
|
resolver,
|
|
19085
19839
|
options?.recovered === true,
|
|
19086
|
-
options?.fecSbn
|
|
19840
|
+
options?.fecSbn,
|
|
19841
|
+
options?.fecSbnFirst
|
|
19087
19842
|
);
|
|
19088
19843
|
if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
|
|
19089
19844
|
}
|
|
@@ -19176,7 +19931,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19176
19931
|
info,
|
|
19177
19932
|
resolver,
|
|
19178
19933
|
options?.recovered === true,
|
|
19179
|
-
options?.fecSbn
|
|
19934
|
+
options?.fecSbn,
|
|
19935
|
+
options?.fecSbnFirst
|
|
19180
19936
|
);
|
|
19181
19937
|
if (outcome.record !== void 0) return outcome.record;
|
|
19182
19938
|
return this.#drop(outcome.reason);
|
|
@@ -19196,7 +19952,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19196
19952
|
* attribution exists to keep readable. Leaving the choice at the call site
|
|
19197
19953
|
* is what keeps both true.
|
|
19198
19954
|
*/
|
|
19199
|
-
#emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
|
|
19955
|
+
#emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
|
|
19200
19956
|
const timing = resolver.sampleTiming(
|
|
19201
19957
|
combined.mpuSequenceNumber,
|
|
19202
19958
|
combined.movieFragmentSequenceNumber,
|
|
@@ -19213,6 +19969,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19213
19969
|
);
|
|
19214
19970
|
if (!meta) return { reason: "combined-meta-build-failed" };
|
|
19215
19971
|
if (fecSbn !== void 0) meta.fecSbn = fecSbn;
|
|
19972
|
+
if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
|
|
19216
19973
|
if (!resolver.consumeSample(
|
|
19217
19974
|
combined.mpuSequenceNumber,
|
|
19218
19975
|
combined.movieFragmentSequenceNumber,
|
|
@@ -19381,6 +20138,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19381
20138
|
}
|
|
19382
20139
|
this.#emitFrame(data, meta);
|
|
19383
20140
|
}
|
|
20141
|
+
/** Whether FT=1 metadata already names this sample, without claiming it. */
|
|
20142
|
+
hasAuthoredTimingFor(packetId, mpuSequenceNumber2, movieFragmentSequenceNumber, sampleNumber, catalogTrackName) {
|
|
20143
|
+
return this.#timingResolver(this.#streamKey(packetId, catalogTrackName), packetId, false)?.sampleTiming(mpuSequenceNumber2, movieFragmentSequenceNumber, sampleNumber) != null;
|
|
20144
|
+
}
|
|
19384
20145
|
/**
|
|
19385
20146
|
* Claim and return the authored timing for a recovered sample. Recovery does
|
|
19386
20147
|
* not pass through the ordinary `feed()` completion path, so it must retire
|
|
@@ -19442,6 +20203,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19442
20203
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
19443
20204
|
this.#sequencers.clear();
|
|
19444
20205
|
this.#fecSequencer?.discard();
|
|
20206
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
20207
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
20208
|
+
}
|
|
19445
20209
|
this.#timingStreams.clear();
|
|
19446
20210
|
this.#pendingTimingSamples = 0;
|
|
19447
20211
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -19460,10 +20224,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19460
20224
|
return resolver;
|
|
19461
20225
|
}
|
|
19462
20226
|
#awaitTiming(streamKey, head) {
|
|
19463
|
-
const
|
|
19464
|
-
if (!
|
|
20227
|
+
const state = this.#timingStreams.get(streamKey);
|
|
20228
|
+
if (!state) return;
|
|
20229
|
+
if (!head.options?.recovered) {
|
|
20230
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
20231
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
20232
|
+
state.awaitingTiming = kept;
|
|
20233
|
+
}
|
|
20234
|
+
const awaitingTiming = state.awaitingTiming;
|
|
19465
20235
|
awaitingTiming.push(head);
|
|
19466
|
-
if (
|
|
20236
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
20237
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
20238
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
20239
|
+
}
|
|
20240
|
+
}
|
|
20241
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
20242
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
20243
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
19467
20244
|
}
|
|
19468
20245
|
/**
|
|
19469
20246
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -19491,6 +20268,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
19491
20268
|
const state = this.#timingStreams.get(streamKey);
|
|
19492
20269
|
if (!state) return;
|
|
19493
20270
|
this.#timingStreams.delete(streamKey);
|
|
20271
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
19494
20272
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
19495
20273
|
if (this.#pendingTimingSamples < 0) {
|
|
19496
20274
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|
|
@@ -22697,7 +23475,18 @@ function keyframeOverlaySsId(header) {
|
|
|
22697
23475
|
if (ext?.type !== KEYFRAME_OVERLAY_EXTENSION_TYPE || ext.data.length !== 4) return void 0;
|
|
22698
23476
|
return new DataView(ext.data.buffer, ext.data.byteOffset, 4).getUint32(0);
|
|
22699
23477
|
}
|
|
23478
|
+
function overlayBaseSsId(anchor, overlaySsId, restoredPsn, headerPsn) {
|
|
23479
|
+
if (anchor.baseSsId === void 0 || headerPsn !== restoredPsn) return void 0;
|
|
23480
|
+
return serial32Add(anchor.baseSsId, overlaySsId - anchor.overlaySsId | 0);
|
|
23481
|
+
}
|
|
23482
|
+
function unstampedBaseSsId(offset, unstampedOffset, headerPsn) {
|
|
23483
|
+
if (offset === void 0 || offset !== unstampedOffset) return void 0;
|
|
23484
|
+
return headerPsn + offset >>> 0;
|
|
23485
|
+
}
|
|
23486
|
+
var OVERLAY_ROUTED_LIMIT = 1024;
|
|
23487
|
+
var OVERLAY_PENDING_LIMIT = 256;
|
|
22700
23488
|
var OVERLAY_OFFSET_MPUS = 16;
|
|
23489
|
+
var OVERLAY_REBUILT_LIMIT = 256;
|
|
22701
23490
|
var OVERLAY_MOQ_HORIZON_BLOCKS = 64;
|
|
22702
23491
|
function assertStreamIdentity(role, stream) {
|
|
22703
23492
|
if (stream === void 0 || !Number.isInteger(stream.packetId) || stream.packetId <= MMTP_SIGNALING_PACKET_ID || typeof stream.catalogTrackName !== "string" || stream.catalogTrackName.length === 0) {
|
|
@@ -22808,6 +23597,7 @@ var MmtpRouter = class {
|
|
|
22808
23597
|
#provenance = /* @__PURE__ */ new Map();
|
|
22809
23598
|
#onFlowProtected = null;
|
|
22810
23599
|
#unadmittedListedDrops = 0;
|
|
23600
|
+
#admittedSourceDatagrams = 0;
|
|
22811
23601
|
#unlistedRepairSetAside = 0;
|
|
22812
23602
|
#assistBlocks = /* @__PURE__ */ new Map();
|
|
22813
23603
|
#assistFailures = /* @__PURE__ */ new Map();
|
|
@@ -22864,6 +23654,26 @@ var MmtpRouter = class {
|
|
|
22864
23654
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
22865
23655
|
*/
|
|
22866
23656
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
23657
|
+
/**
|
|
23658
|
+
* Per stream, the SS_ID offset at which a base recovery last showed the
|
|
23659
|
+
* sender's own packet_sequence_number: a recovered packet's header psn
|
|
23660
|
+
* equal to its SS_ID minus that offset. While it equals the stream's
|
|
23661
|
+
* current offset, no hop re-stamps the stream, and a packet's protected psn
|
|
23662
|
+
* names its base SS_ID within unstampedBaseSsId's limits (joint decoding of
|
|
23663
|
+
* an MPU no member of which arrived).
|
|
23664
|
+
*/
|
|
23665
|
+
#unstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
23666
|
+
/**
|
|
23667
|
+
* The same, shown by the overlay alone, before any base recovery did: a
|
|
23668
|
+
* packet it rebuilt whose base copy carries its protected psn
|
|
23669
|
+
* (#feedOverlaySource), or whose protected psn passes overlayBaseSsId's
|
|
23670
|
+
* test at that offset (#routeOverlayRecovered). A base SS_ID placed by it
|
|
23671
|
+
* anchors the release gate only (BLO-52085 D3): fed to the base, it would
|
|
23672
|
+
* make the base drop a late base copy of a keyframe the overlay never
|
|
23673
|
+
* finished, and lift a block's late-source cut, which nothing before
|
|
23674
|
+
* this offset did.
|
|
23675
|
+
*/
|
|
23676
|
+
#overlayUnstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
22867
23677
|
/**
|
|
22868
23678
|
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
22869
23679
|
* not parsed, typically because its overlap copy was parsed first
|
|
@@ -22909,6 +23719,8 @@ var MmtpRouter = class {
|
|
|
22909
23719
|
// end: a synchronous recovery completes its block BEFORE routing the
|
|
22910
23720
|
// recovered frames, and releasing a held gap in between would strand them.
|
|
22911
23721
|
#fecPokeDepth = 0;
|
|
23722
|
+
/** FecReleaseGate.wakeAt timers, by media stream key. */
|
|
23723
|
+
#fecWakes = /* @__PURE__ */ new Map();
|
|
22912
23724
|
#pendingFecPokes = /* @__PURE__ */ new Map();
|
|
22913
23725
|
// ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
|
|
22914
23726
|
/** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
|
|
@@ -22933,7 +23745,9 @@ var MmtpRouter = class {
|
|
|
22933
23745
|
recovered: 0,
|
|
22934
23746
|
restarts: 0,
|
|
22935
23747
|
unsequencedDropped: 0,
|
|
22936
|
-
protectedDropped: 0
|
|
23748
|
+
protectedDropped: 0,
|
|
23749
|
+
baseFed: 0,
|
|
23750
|
+
baseUndetermined: 0
|
|
22937
23751
|
};
|
|
22938
23752
|
/** Callback fired when a delta-track FEC block completes or fails. */
|
|
22939
23753
|
#onDeltaBlockCompleteCb = null;
|
|
@@ -23106,7 +23920,7 @@ var MmtpRouter = class {
|
|
|
23106
23920
|
const cb = this.#getFrameCallback(packetId);
|
|
23107
23921
|
if (isVideo && !assembler) {
|
|
23108
23922
|
if (frameMeta.recovered) {
|
|
23109
|
-
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb);
|
|
23923
|
+
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb, meta.fecSbn);
|
|
23110
23924
|
} else {
|
|
23111
23925
|
this.#routeDirectSourceVideo(packetId, data, frameMeta, cb);
|
|
23112
23926
|
}
|
|
@@ -23139,13 +23953,18 @@ var MmtpRouter = class {
|
|
|
23139
23953
|
this.#onDeltaBlockCompleteCb?.(packetId, false);
|
|
23140
23954
|
}
|
|
23141
23955
|
};
|
|
23142
|
-
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass) => {
|
|
23956
|
+
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
23143
23957
|
this.#mseAssemblerFor(packetId, catalogTrackName)?.failBlock(sbn);
|
|
23144
23958
|
if (this.#isCatalogTrackUnambiguous(packetId, catalogTrackName) && this.#packetIdRoles.get(packetId) === "delta") {
|
|
23145
23959
|
this.#onDeltaBlockCompleteCb?.(packetId, true);
|
|
23146
23960
|
}
|
|
23147
|
-
|
|
23148
|
-
|
|
23961
|
+
if (span === void 0) {
|
|
23962
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
23963
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
23964
|
+
} else {
|
|
23965
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
23966
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
23967
|
+
}
|
|
23149
23968
|
};
|
|
23150
23969
|
}
|
|
23151
23970
|
}
|
|
@@ -23190,8 +24009,9 @@ var MmtpRouter = class {
|
|
|
23190
24009
|
}
|
|
23191
24010
|
/**
|
|
23192
24011
|
* FEC-recovered source symbols whose reconstructed header named a
|
|
23193
|
-
* packet_sequence_number other than the wire sequence their SS_ID maps to
|
|
23194
|
-
*
|
|
24012
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to,
|
|
24013
|
+
* or, rebuilt by the overlay, than their base copy carries: a hop
|
|
24014
|
+
* re-stamped the sequence after the sender protected the packet.
|
|
23195
24015
|
*/
|
|
23196
24016
|
get restampedRecoveredSequenceCount() {
|
|
23197
24017
|
return this.#restampedRecoveredSeqs;
|
|
@@ -23370,6 +24190,7 @@ var MmtpRouter = class {
|
|
|
23370
24190
|
enableMseAssembler(packetId, config, catalogTrackName) {
|
|
23371
24191
|
const assemblerKey = this.#mseAssemblerKey(packetId, catalogTrackName);
|
|
23372
24192
|
const previous = this.#mseAssemblers.get(assemblerKey);
|
|
24193
|
+
this.#parser.unsourceFecRelease(packetId, catalogTrackName);
|
|
23373
24194
|
if (previous) {
|
|
23374
24195
|
previous.flush();
|
|
23375
24196
|
previous.dispose();
|
|
@@ -23496,6 +24317,10 @@ var MmtpRouter = class {
|
|
|
23496
24317
|
get keyframeOverlayStats() {
|
|
23497
24318
|
return { ...this.#overlayStats };
|
|
23498
24319
|
}
|
|
24320
|
+
/** Recovered FT=2 heads held for their FT=1, and how each left the wait (BLO-53369). */
|
|
24321
|
+
get recoveredHeadsAwaitingTiming() {
|
|
24322
|
+
return this.#parser.recoveredHeadsAwaitingTiming;
|
|
24323
|
+
}
|
|
23499
24324
|
#isOverlayRepair(repairPacketId, repairTrackName) {
|
|
23500
24325
|
return this.#overlayLegs.has(repairPacketId) || repairTrackName !== void 0 && this.#overlayRepairNames.has(repairTrackName);
|
|
23501
24326
|
}
|
|
@@ -23516,7 +24341,8 @@ var MmtpRouter = class {
|
|
|
23516
24341
|
fec,
|
|
23517
24342
|
k,
|
|
23518
24343
|
offsets: /* @__PURE__ */ new Map(),
|
|
23519
|
-
moqBlocks: /* @__PURE__ */ new Set()
|
|
24344
|
+
moqBlocks: /* @__PURE__ */ new Set(),
|
|
24345
|
+
rebuilt: /* @__PURE__ */ new Map()
|
|
23520
24346
|
};
|
|
23521
24347
|
this.#overlays.set(repairPacketId, inst);
|
|
23522
24348
|
return () => {
|
|
@@ -23546,12 +24372,18 @@ var MmtpRouter = class {
|
|
|
23546
24372
|
*/
|
|
23547
24373
|
resetKeyframeOverlays(sourcePacketId, catalogTrackName) {
|
|
23548
24374
|
for (const inst of this.#overlaysForSource(sourcePacketId, catalogTrackName)) this.#resetOverlay(inst);
|
|
24375
|
+
for (const [name, stream] of this.#streams.get(sourcePacketId) ?? []) {
|
|
24376
|
+
if (catalogTrackName !== void 0 && name !== catalogTrackName) continue;
|
|
24377
|
+
stream.overlayToBase.routed.clear();
|
|
24378
|
+
stream.overlayToBase.pending.clear();
|
|
24379
|
+
}
|
|
23549
24380
|
}
|
|
23550
24381
|
#resetOverlay(inst) {
|
|
23551
24382
|
inst.fec.resetTrack(inst.repairPacketId, inst.streamName);
|
|
23552
24383
|
inst.last = void 0;
|
|
23553
24384
|
inst.offsets.clear();
|
|
23554
24385
|
inst.moqBlocks.clear();
|
|
24386
|
+
inst.rebuilt.clear();
|
|
23555
24387
|
}
|
|
23556
24388
|
#overlaysForSource(sourcePacketId, catalogTrackName) {
|
|
23557
24389
|
return [...this.#overlays.values()].filter(({ leg }) => leg.sourcePacketId === sourcePacketId && (catalogTrackName === void 0 || leg.sourceCatalogTrackName === void 0 || leg.sourceCatalogTrackName === catalogTrackName));
|
|
@@ -23602,18 +24434,33 @@ var MmtpRouter = class {
|
|
|
23602
24434
|
* A source packet that carries a 0x8B01 overlay SS_ID is also a symbol of
|
|
23603
24435
|
* every overlay installed for its source, at that SS_ID, with the bytes the
|
|
23604
24436
|
* base protects: the packet minus its 4-byte SS_ID trailer, extension
|
|
23605
|
-
* included (7.1, 7.4.3).
|
|
23606
|
-
|
|
23607
|
-
|
|
24437
|
+
* included (7.1, 7.4.3). `baseSsId` is that trailer's SS_ID, when the base
|
|
24438
|
+
* FEC reads it.
|
|
24439
|
+
*
|
|
24440
|
+
* The base copy of a packet an overlay rebuilt with no base SS_ID shows
|
|
24441
|
+
* what a base recovery of it would (#routeProcessedFecSymbols, BLO-52085):
|
|
24442
|
+
* its wire packet_sequence_number equal to the protected one rebuilt shows
|
|
24443
|
+
* the stream unstamped at the SS_ID offset it states, for the release gate
|
|
24444
|
+
* (#overlayUnstampedSsIdSeqOffsetByStream); any other shows a hop that
|
|
24445
|
+
* re-stamps it, which is counted (restampedRecoveredSequenceCount).
|
|
24446
|
+
*/
|
|
24447
|
+
#feedOverlaySource(packetId, catalogTrackName, packet, header, sequenceNumber, rapFlag, source, baseSsId) {
|
|
23608
24448
|
if (this.#overlays.size === 0) return;
|
|
23609
24449
|
const ssId = keyframeOverlaySsId(header);
|
|
23610
24450
|
if (ssId === void 0) return;
|
|
24451
|
+
let rebuiltPsn;
|
|
23611
24452
|
for (const inst of this.#overlaysForSource(packetId, catalogTrackName)) {
|
|
23612
24453
|
this.#noteOverlaySsId(inst, ssId, sequenceNumber);
|
|
24454
|
+
rebuiltPsn ??= inst.rebuilt.get(ssId);
|
|
24455
|
+
inst.rebuilt.delete(ssId);
|
|
23613
24456
|
const identity = MmtpContainerParser.sourcePacketIdentity(packet, header);
|
|
23614
24457
|
if (identity !== null) {
|
|
23615
24458
|
inst.offsets.delete(identity.mpuSequenceNumber);
|
|
23616
|
-
inst.offsets.set(identity.mpuSequenceNumber,
|
|
24459
|
+
inst.offsets.set(identity.mpuSequenceNumber, {
|
|
24460
|
+
psnOffset: ssId - sequenceNumber >>> 0,
|
|
24461
|
+
overlaySsId: ssId,
|
|
24462
|
+
...baseSsId === void 0 ? {} : { baseSsId }
|
|
24463
|
+
});
|
|
23617
24464
|
if (inst.offsets.size > OVERLAY_OFFSET_MPUS) inst.offsets.delete(inst.offsets.keys().next().value);
|
|
23618
24465
|
}
|
|
23619
24466
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -23635,6 +24482,14 @@ var MmtpRouter = class {
|
|
|
23635
24482
|
const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
|
|
23636
24483
|
if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, coords.sbn, recovered);
|
|
23637
24484
|
}
|
|
24485
|
+
if (rebuiltPsn === void 0 || this.#classifyPacketId(packetId) === null) return;
|
|
24486
|
+
const streamKey = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
24487
|
+
if (rebuiltPsn !== sequenceNumber) {
|
|
24488
|
+
this.#restampedRecoveredSeqs++;
|
|
24489
|
+
} else if (baseSsId !== void 0) {
|
|
24490
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24491
|
+
if (offset === baseSsId - sequenceNumber >>> 0) this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
24492
|
+
}
|
|
23638
24493
|
}
|
|
23639
24494
|
#noteOverlayMoqBlock(inst, blockStart) {
|
|
23640
24495
|
inst.moqBlocks.add(blockStart);
|
|
@@ -23668,11 +24523,16 @@ var MmtpRouter = class {
|
|
|
23668
24523
|
}
|
|
23669
24524
|
/**
|
|
23670
24525
|
* Route an overlay-recovered block's packets as source media of the
|
|
23671
|
-
* overlay's source (7.2: an overlay coordinate yields no base SS_ID).
|
|
23672
|
-
*
|
|
23673
|
-
*
|
|
23674
|
-
*
|
|
23675
|
-
*
|
|
24526
|
+
* overlay's source (7.2: an overlay coordinate yields no base SS_ID). A
|
|
24527
|
+
* packet whose base SS_ID is determined independently (overlayBaseSsId,
|
|
24528
|
+
* unstampedBaseSsId) enters the release gate at that SS_ID, as a packet
|
|
24529
|
+
* base FEC recovered does, so it waits behind base frames still in flight,
|
|
24530
|
+
* though not for its own MPU's packets (FrameMeta.fecSbnFirst) and no
|
|
24531
|
+
* longer than unanchored; one whose base SS_ID is undetermined has no
|
|
24532
|
+
* release-gate anchor. No parse ledger, no base re-stamp, no block
|
|
24533
|
+
* advance. Each packet's wire sequence is restored from its keyframe's own
|
|
24534
|
+
* offset; without one, a stream the base never re-stamped keeps the
|
|
24535
|
+
* header's sequence and any other drops the packet.
|
|
23676
24536
|
*/
|
|
23677
24537
|
#routeOverlayRecovered(inst, blockStart, recovered) {
|
|
23678
24538
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -23692,22 +24552,139 @@ var MmtpRouter = class {
|
|
|
23692
24552
|
const streamKey = this.#mediaStreamKey(sourcePacketId, sourceName);
|
|
23693
24553
|
const restamped = this.#restampedStreams.has(streamKey);
|
|
23694
24554
|
const restored = /* @__PURE__ */ new Set();
|
|
24555
|
+
const baseSsIds = /* @__PURE__ */ new Map();
|
|
24556
|
+
const gateOnly = /* @__PURE__ */ new Set();
|
|
23695
24557
|
const symbols = result.symbols.flatMap((sym) => {
|
|
23696
|
-
const
|
|
23697
|
-
|
|
23698
|
-
|
|
24558
|
+
const overlaySsId = serial32Add(blockStart, sym.index);
|
|
24559
|
+
const anchor = inst.offsets.get(sym.fragment.mpuSequenceNumber);
|
|
24560
|
+
if (anchor !== void 0) {
|
|
24561
|
+
const packetSequenceNumber = overlaySsId - anchor.psnOffset >>> 0;
|
|
23699
24562
|
restored.add(packetSequenceNumber);
|
|
23700
|
-
|
|
24563
|
+
const out = { ...sym, packetSequenceNumber };
|
|
24564
|
+
const baseSsId = overlayBaseSsId(anchor, overlaySsId, packetSequenceNumber, sym.packetSequenceNumber);
|
|
24565
|
+
if (baseSsId !== void 0) {
|
|
24566
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
24567
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24568
|
+
if (!this.#sourceSeqReceived(sourcePacketId, packetSequenceNumber, sourceName) && offset === baseSsId - packetSequenceNumber >>> 0) {
|
|
24569
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
24570
|
+
}
|
|
24571
|
+
}
|
|
24572
|
+
return [out];
|
|
24573
|
+
}
|
|
24574
|
+
if (!restamped) {
|
|
24575
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
24576
|
+
const fedSsId = unstampedBaseSsId(offset, this.#unstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
24577
|
+
const baseSsId = fedSsId ?? unstampedBaseSsId(offset, this.#overlayUnstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
24578
|
+
if (baseSsId !== void 0) {
|
|
24579
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
24580
|
+
if (fedSsId === void 0) gateOnly.add(sym.index);
|
|
24581
|
+
} else {
|
|
24582
|
+
inst.rebuilt.set(overlaySsId, sym.packetSequenceNumber);
|
|
24583
|
+
if (inst.rebuilt.size > OVERLAY_REBUILT_LIMIT) inst.rebuilt.delete(inst.rebuilt.keys().next().value);
|
|
24584
|
+
}
|
|
24585
|
+
return [sym];
|
|
23701
24586
|
}
|
|
23702
|
-
if (!restamped) return [sym];
|
|
23703
24587
|
this.#overlayStats.unsequencedDropped++;
|
|
23704
24588
|
return [];
|
|
23705
24589
|
});
|
|
23706
24590
|
this.#overlayStats.recovered++;
|
|
24591
|
+
const mpuFirst = /* @__PURE__ */ new Map();
|
|
24592
|
+
for (const sym of symbols) {
|
|
24593
|
+
const ssId = baseSsIds.get(sym.index);
|
|
24594
|
+
const mpu = sym.fragment.mpuSequenceNumber;
|
|
24595
|
+
const first = mpuFirst.get(mpu);
|
|
24596
|
+
if (ssId !== void 0 && (first === void 0 || serial32Precedes(ssId, first))) mpuFirst.set(mpu, ssId);
|
|
24597
|
+
}
|
|
24598
|
+
const firstSsIds = /* @__PURE__ */ new Map();
|
|
24599
|
+
for (const sym of symbols) {
|
|
24600
|
+
if (baseSsIds.has(sym.index)) firstSsIds.set(sym.index, mpuFirst.get(sym.fragment.mpuSequenceNumber));
|
|
24601
|
+
}
|
|
23707
24602
|
this.#routeProcessedFecSymbols(blockStart, { ...result, symbols }, sourcePacketId, sourceName, {
|
|
23708
|
-
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast"
|
|
24603
|
+
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast",
|
|
24604
|
+
baseSsIds,
|
|
24605
|
+
firstSsIds
|
|
23709
24606
|
});
|
|
23710
24607
|
this.#noteOverlayRecoveredRaps(sourcePacketId, sourceName, streamKey, symbols.filter((sym) => restored.has(sym.packetSequenceNumber)));
|
|
24608
|
+
this.#feedOverlayRecoveredToBase(inst, blockStart, symbols, gateOnly.size === 0 ? baseSsIds : new Map([...baseSsIds].filter(([index]) => !gateOnly.has(index))));
|
|
24609
|
+
}
|
|
24610
|
+
/**
|
|
24611
|
+
* Joint decoding (BLO-52085). A packet the overlay rebuilt is a source of
|
|
24612
|
+
* its base block too, once its base SS_ID is determined (overlayBaseSsId,
|
|
24613
|
+
* from a received member of its MPU, else unstampedBaseSsId at an offset a
|
|
24614
|
+
* base recovery showed; `baseSsIds` holds no other),
|
|
24615
|
+
* so it is fed to the base decoder as a rebuilt source
|
|
24616
|
+
* (FECManager.feedRebuiltSourceSymbol): the base block has one erasure
|
|
24617
|
+
* fewer to solve, and its repair can recover the block's other packets.
|
|
24618
|
+
* A base block no repair has stated yet takes it when one does
|
|
24619
|
+
* (#feedPendingRebuilt).
|
|
24620
|
+
*
|
|
24621
|
+
* The overlay route already handled each packet fed (delivered it, or
|
|
24622
|
+
* held an untimed head for its FT=1), so a base recovery routes none of
|
|
24623
|
+
* them again (#routeVerifiedFecSymbols): a second recovered copy of a
|
|
24624
|
+
* held head would wait in the parser for timing its first copy consumed.
|
|
24625
|
+
* Only an overlay block decoded from multicast symbols alone is fed: with
|
|
24626
|
+
* a MoQ symbol in it, the base block's recovery would depend on bytes
|
|
24627
|
+
* that crossed no multicast socket, which the provenance counted from the
|
|
24628
|
+
* block's own arrivals cannot show.
|
|
24629
|
+
*/
|
|
24630
|
+
#feedOverlayRecoveredToBase(inst, blockStart, symbols, baseSsIds) {
|
|
24631
|
+
const fec = this.#fecManager;
|
|
24632
|
+
const owner = inst.leg.sourcePacketId;
|
|
24633
|
+
const name = inst.leg.sourceCatalogTrackName;
|
|
24634
|
+
if (!fec?.feedRebuiltSourceSymbol || inst.moqBlocks.has(blockStart)) return;
|
|
24635
|
+
if (this.#classifyPacketId(owner) === null || fec.isTrackConfigured?.(owner) === false) return;
|
|
24636
|
+
const { duplicates, overlayToBase: { routed } } = this.#stream(owner, name);
|
|
24637
|
+
const feeds = [];
|
|
24638
|
+
for (const sym of symbols) {
|
|
24639
|
+
if (duplicates.sourceSeqs.has(sym.packetSequenceNumber)) continue;
|
|
24640
|
+
const ssId = baseSsIds.get(sym.index);
|
|
24641
|
+
if (ssId === void 0) {
|
|
24642
|
+
this.#overlayStats.baseUndetermined++;
|
|
24643
|
+
continue;
|
|
24644
|
+
}
|
|
24645
|
+
routed.delete(ssId);
|
|
24646
|
+
routed.add(ssId);
|
|
24647
|
+
if (routed.size > OVERLAY_ROUTED_LIMIT) routed.delete(routed.values().next().value);
|
|
24648
|
+
feeds.push([ssId, sym.rawSymbol]);
|
|
24649
|
+
}
|
|
24650
|
+
for (const [ssId, symbolData] of feeds) {
|
|
24651
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24652
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24653
|
+
}
|
|
24654
|
+
}
|
|
24655
|
+
/** Feed one rebuilt source to its base block, or keep it until a repair states that block. */
|
|
24656
|
+
#feedRebuiltToBase(owner, name, ssId, symbolData) {
|
|
24657
|
+
const fec = this.#fecManager;
|
|
24658
|
+
if (!fec?.feedRebuiltSourceSymbol) return;
|
|
24659
|
+
const coords = fec.locateIsoSource?.(owner, name, ssId);
|
|
24660
|
+
if (coords == null) {
|
|
24661
|
+
const pending = this.#stream(owner, name).overlayToBase.pending;
|
|
24662
|
+
pending.delete(ssId);
|
|
24663
|
+
pending.set(ssId, symbolData.slice());
|
|
24664
|
+
if (pending.size > OVERLAY_PENDING_LIMIT) pending.delete(pending.keys().next().value);
|
|
24665
|
+
return;
|
|
24666
|
+
}
|
|
24667
|
+
const fed = fec.feedRebuiltSourceSymbol(owner, ssId, symbolData, name);
|
|
24668
|
+
if (!fed.taken) return;
|
|
24669
|
+
this.#overlayStats.baseFed++;
|
|
24670
|
+
if (fed.recovered === null) return;
|
|
24671
|
+
const sbn = coords.sbn;
|
|
24672
|
+
this.#routeRecoveredBlock(sbn, fed.recovered, owner, name, () => {
|
|
24673
|
+
fec.cancelBlockTimeout(sbn, owner, name);
|
|
24674
|
+
fec.countRecovery(owner, sbn, name);
|
|
24675
|
+
fec.markBlockCompleted(sbn, owner, name);
|
|
24676
|
+
});
|
|
24677
|
+
}
|
|
24678
|
+
/** A repair stated `block`: the rebuilt sources that waited for it join it now. */
|
|
24679
|
+
#feedPendingRebuilt(owner, name, block) {
|
|
24680
|
+
const pending = this.#streams.get(owner)?.get(name)?.overlayToBase.pending;
|
|
24681
|
+
if (pending === void 0 || pending.size === 0) return;
|
|
24682
|
+
for (const [ssId, symbolData] of [...pending]) {
|
|
24683
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
24684
|
+
if (serial32Distance(block.start, ssId) >= block.length) continue;
|
|
24685
|
+
pending.delete(ssId);
|
|
24686
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
24687
|
+
}
|
|
23711
24688
|
}
|
|
23712
24689
|
/** fec-multicast-00 §6.6: report each base block whose RAP MFU fragments
|
|
23713
24690
|
* the overlay restored, when the keyframe's FT=0 and FT=1 are held too. A
|
|
@@ -23847,6 +24824,10 @@ var MmtpRouter = class {
|
|
|
23847
24824
|
get unadmittedListedDropCount() {
|
|
23848
24825
|
return this.#unadmittedListedDrops;
|
|
23849
24826
|
}
|
|
24827
|
+
/** 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. */
|
|
24828
|
+
get admittedSourceDatagramCount() {
|
|
24829
|
+
return this.#admittedSourceDatagrams;
|
|
24830
|
+
}
|
|
23850
24831
|
/** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
|
|
23851
24832
|
get unlistedRepairSetAsideCount() {
|
|
23852
24833
|
return this.#unlistedRepairSetAside;
|
|
@@ -24333,6 +25314,8 @@ var MmtpRouter = class {
|
|
|
24333
25314
|
)) return;
|
|
24334
25315
|
fec.noteBlockActivity?.(blockStart, ownerPacketId, catalogTrackName);
|
|
24335
25316
|
fec.noteRepairGroupLength?.(blockStart, ownerPacketId, repair.rsbLength, catalogTrackName);
|
|
25317
|
+
this.#feedPendingRebuilt(ownerPacketId, catalogTrackName, placement.block);
|
|
25318
|
+
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
24336
25319
|
const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
|
|
24337
25320
|
const recovered = fec.feedRepairSymbol(
|
|
24338
25321
|
ownerPacketId,
|
|
@@ -24383,7 +25366,7 @@ var MmtpRouter = class {
|
|
|
24383
25366
|
catalogTrackName
|
|
24384
25367
|
)) continue;
|
|
24385
25368
|
if (fec.isTrackConfigured?.(ownerPacketId) !== false) {
|
|
24386
|
-
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence);
|
|
25369
|
+
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence, true);
|
|
24387
25370
|
this.#requestFecPoke(ownerPacketId, catalogTrackName);
|
|
24388
25371
|
}
|
|
24389
25372
|
if (payload.oversized) continue;
|
|
@@ -24470,6 +25453,8 @@ var MmtpRouter = class {
|
|
|
24470
25453
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
24471
25454
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
24472
25455
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
25456
|
+
this.#unstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
25457
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
24473
25458
|
this.#multicastRapTwinByStream.delete(streamKey);
|
|
24474
25459
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
24475
25460
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
@@ -24596,6 +25581,12 @@ var MmtpRouter = class {
|
|
|
24596
25581
|
* the outgoing stream stops. The hold is bounded by the incoming stream's
|
|
24597
25582
|
* own RAP cadence, so no timer is involved.
|
|
24598
25583
|
*
|
|
25584
|
+
* While the switch is staged, the FEC release gate lets a keyframe the
|
|
25585
|
+
* overlay rebuilt reach it, on either side, when the keyframe did before
|
|
25586
|
+
* the gate anchored it (FecReleaseGate.releaseUnanchored): the switch
|
|
25587
|
+
* decides on what each side delivered, and the commit discards the gate's
|
|
25588
|
+
* frames of the outgoing stream.
|
|
25589
|
+
*
|
|
24599
25590
|
* The commit is one synchronous transition inside the frame path: the
|
|
24600
25591
|
* outgoing stream's already-admitted frames are released (its queued FEC
|
|
24601
25592
|
* gap fills only up to the RAP, since recovery can queue a frame ahead of
|
|
@@ -24646,6 +25637,9 @@ var MmtpRouter = class {
|
|
|
24646
25637
|
droppedIncomingFrames: 0
|
|
24647
25638
|
};
|
|
24648
25639
|
this.#staged = state;
|
|
25640
|
+
if (this.#parser.fecReleaseHoldsRebuilt(from.packetId, from.catalogTrackName)) {
|
|
25641
|
+
this.#requestFecPoke(from.packetId, from.catalogTrackName);
|
|
25642
|
+
}
|
|
24649
25643
|
return {
|
|
24650
25644
|
cancel: () => {
|
|
24651
25645
|
if (this.#staged !== state) return false;
|
|
@@ -24728,7 +25722,17 @@ var MmtpRouter = class {
|
|
|
24728
25722
|
*/
|
|
24729
25723
|
#routeParsedFrame(data, meta) {
|
|
24730
25724
|
if (this.#classifyPacketId(meta.packetId) === null) return;
|
|
24731
|
-
if (this.#staged !== null
|
|
25725
|
+
if (this.#staged !== null) {
|
|
25726
|
+
let consumed = false;
|
|
25727
|
+
this.#fecPokeDepth++;
|
|
25728
|
+
try {
|
|
25729
|
+
consumed = this.#interceptSwitchFrame(data, meta);
|
|
25730
|
+
} finally {
|
|
25731
|
+
this.#fecPokeDepth--;
|
|
25732
|
+
this.#flushPendingFecPokes();
|
|
25733
|
+
}
|
|
25734
|
+
if (consumed) return;
|
|
25735
|
+
}
|
|
24732
25736
|
this.#deliverParsedFrame(data, meta);
|
|
24733
25737
|
}
|
|
24734
25738
|
#commitStreamSwitch(state, rap, reason) {
|
|
@@ -24777,6 +25781,8 @@ var MmtpRouter = class {
|
|
|
24777
25781
|
this.#disposed = true;
|
|
24778
25782
|
this.#staged = null;
|
|
24779
25783
|
this.cancelKeyframeLostTimer();
|
|
25784
|
+
for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
|
|
25785
|
+
this.#fecWakes.clear();
|
|
24780
25786
|
this.#parser.dispose();
|
|
24781
25787
|
this.#streams.clear();
|
|
24782
25788
|
this.#trackPacketCallbacks.clear();
|
|
@@ -24880,12 +25886,16 @@ var MmtpRouter = class {
|
|
|
24880
25886
|
this.#parser.deferFecRelease(work);
|
|
24881
25887
|
} finally {
|
|
24882
25888
|
this.#fecPokeDepth--;
|
|
24883
|
-
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
24887
|
-
|
|
24888
|
-
|
|
25889
|
+
this.#flushPendingFecPokes();
|
|
25890
|
+
}
|
|
25891
|
+
}
|
|
25892
|
+
/** Run the pokes requested while #fecPokeDepth was raised, once it is 0. */
|
|
25893
|
+
#flushPendingFecPokes() {
|
|
25894
|
+
if (this.#fecPokeDepth === 0 && this.#pendingFecPokes.size > 0 && !this.#disposed) {
|
|
25895
|
+
const pokes = [...this.#pendingFecPokes.values()];
|
|
25896
|
+
this.#pendingFecPokes.clear();
|
|
25897
|
+
for (const poke of pokes) {
|
|
25898
|
+
this.#parser.pokeFecRelease(poke.packetId, poke.catalogTrackName);
|
|
24889
25899
|
}
|
|
24890
25900
|
}
|
|
24891
25901
|
}
|
|
@@ -24954,6 +25964,31 @@ var MmtpRouter = class {
|
|
|
24954
25964
|
if (!fec?.terminalRetentionMsForPacket) return Infinity;
|
|
24955
25965
|
return fec.terminalRetentionMsForPacket(packetId) ?? 0;
|
|
24956
25966
|
},
|
|
25967
|
+
// Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
|
|
25968
|
+
// late source can), its frame waits the late-symbol allowance when the
|
|
25969
|
+
// gap holds no RAP an installed keyframe overlay could still rebuild:
|
|
25970
|
+
// lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
|
|
25971
|
+
// that opens the next one while MPU boundaries bound RAPs (rap-next,
|
|
25972
|
+
// unless the gap holds a stated block's loss: the overlay may rebuild
|
|
25973
|
+
// that MPU's FT=0, and the block's group then complete it), or
|
|
25974
|
+
// an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
|
|
25975
|
+
// other rap-next, whose gap may hold a whole MPU and the keyframe the
|
|
25976
|
+
// overlay protects) waits for that overlay's repair too (BLO-52085
|
|
25977
|
+
// D4). The FEC check comes first: most held gaps are not behind such a
|
|
25978
|
+
// span, and deciding one scans both frames' bitstreams.
|
|
25979
|
+
unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
|
|
25980
|
+
const fec = this.#fecManager;
|
|
25981
|
+
const { packetId, catalogTrackName } = after.meta;
|
|
25982
|
+
const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
|
|
25983
|
+
if (!fec || allowanceMs === void 0) return void 0;
|
|
25984
|
+
const decision = this.#decideGap(before, after, [], false);
|
|
25985
|
+
const mpu = before.meta.mpuSequenceNumber;
|
|
25986
|
+
const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
|
|
25987
|
+
if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
|
|
25988
|
+
return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
|
|
25989
|
+
}
|
|
25990
|
+
return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
|
|
25991
|
+
},
|
|
24957
25992
|
decide: (before, after, lostBlocks, discontinuity) => {
|
|
24958
25993
|
const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
|
|
24959
25994
|
this.#onFrameGap?.(decision);
|
|
@@ -24963,6 +25998,28 @@ var MmtpRouter = class {
|
|
|
24963
25998
|
onRap: (packetId, catalogTrackName, ssId) => {
|
|
24964
25999
|
for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
|
|
24965
26000
|
},
|
|
26001
|
+
// One timer per stream, at the earliest wake asked: its drain re-arms
|
|
26002
|
+
// for the next frame still waiting.
|
|
26003
|
+
wakeAt: (packetId, catalogTrackName, atMs) => {
|
|
26004
|
+
if (this.#disposed) return;
|
|
26005
|
+
const key = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
26006
|
+
const armed = this.#fecWakes.get(key);
|
|
26007
|
+
if (armed !== void 0 && armed.atMs <= atMs) return;
|
|
26008
|
+
if (armed !== void 0) clearTimeout(armed.timer);
|
|
26009
|
+
const timer = setTimeout(() => {
|
|
26010
|
+
this.#fecWakes.delete(key);
|
|
26011
|
+
this.#requestFecPoke(packetId, catalogTrackName);
|
|
26012
|
+
}, Math.max(0, Math.ceil(atMs - performance.now())));
|
|
26013
|
+
this.#fecWakes.set(key, { atMs, timer });
|
|
26014
|
+
},
|
|
26015
|
+
// A staged switch commits on when each side's frames reach it
|
|
26016
|
+
// (#interceptSwitchFrame): both sides' overlay keyframes reach it when
|
|
26017
|
+
// they did unanchored.
|
|
26018
|
+
releaseUnanchored: (packetId, catalogTrackName) => {
|
|
26019
|
+
const staged = this.#staged;
|
|
26020
|
+
const stream = { packetId, ...catalogTrackName === void 0 ? {} : { catalogTrackName } };
|
|
26021
|
+
return staged !== null && (isStream(stream, staged.from) || isStream(stream, staged.to));
|
|
26022
|
+
},
|
|
24966
26023
|
onReleased: (data, meta) => {
|
|
24967
26024
|
if (meta.trackType !== "video" || meta.mpuSequenceNumber === void 0) return;
|
|
24968
26025
|
const timing = meta.authoredTiming;
|
|
@@ -25104,6 +26161,7 @@ var MmtpRouter = class {
|
|
|
25104
26161
|
const parsed = this.#parser.parsePacket(packet);
|
|
25105
26162
|
if (!parsed) return;
|
|
25106
26163
|
const info = parsed.info;
|
|
26164
|
+
if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
|
|
25107
26165
|
if (source === "multicast" && !manifestAdmitted) {
|
|
25108
26166
|
this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
|
|
25109
26167
|
}
|
|
@@ -25385,7 +26443,8 @@ var MmtpRouter = class {
|
|
|
25385
26443
|
parsed.header,
|
|
25386
26444
|
info.sequenceNumber,
|
|
25387
26445
|
info.rapFlag,
|
|
25388
|
-
source
|
|
26446
|
+
source,
|
|
26447
|
+
fecPayloadId?.ssId
|
|
25389
26448
|
);
|
|
25390
26449
|
}
|
|
25391
26450
|
}
|
|
@@ -25411,7 +26470,8 @@ var MmtpRouter = class {
|
|
|
25411
26470
|
source: parserOptions?.source,
|
|
25412
26471
|
deliveryProvenance: parserOptions?.deliveryProvenance,
|
|
25413
26472
|
catalogTrackName: parserOptions?.catalogTrackName,
|
|
25414
|
-
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn }
|
|
26473
|
+
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn },
|
|
26474
|
+
...parserOptions?.fecSbnFirst === void 0 ? {} : { fecSbnFirst: parserOptions.fecSbnFirst }
|
|
25415
26475
|
};
|
|
25416
26476
|
if (parsed) this.#parser.feedParsed(packet, parsed, feedOptions);
|
|
25417
26477
|
else this.#parser.feed(packet, feedOptions);
|
|
@@ -25535,7 +26595,8 @@ var MmtpRouter = class {
|
|
|
25535
26595
|
if (stream === void 0) {
|
|
25536
26596
|
stream = {
|
|
25537
26597
|
key: JSON.stringify([packetId, catalogTrackName ?? null]),
|
|
25538
|
-
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId))
|
|
26598
|
+
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId)),
|
|
26599
|
+
overlayToBase: { routed: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Map() }
|
|
25539
26600
|
};
|
|
25540
26601
|
byName.set(catalogTrackName, stream);
|
|
25541
26602
|
}
|
|
@@ -25650,8 +26711,16 @@ var MmtpRouter = class {
|
|
|
25650
26711
|
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
25651
26712
|
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
25652
26713
|
}
|
|
25653
|
-
#routeDirectRecoveredVideo(packetId, data, meta, cb) {
|
|
26714
|
+
#routeDirectRecoveredVideo(packetId, data, meta, cb, fecSbn) {
|
|
25654
26715
|
const streamKey = this.#mediaStreamKey(packetId, meta.catalogTrackName);
|
|
26716
|
+
if (this.#isFecTrack(packetId)) {
|
|
26717
|
+
const high = this.#deliveredVideoHighWaterByStream.get(streamKey);
|
|
26718
|
+
if (fecSbn !== void 0 || high !== void 0 && authoredAdjacent(high, meta)) {
|
|
26719
|
+
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
26720
|
+
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
26721
|
+
return;
|
|
26722
|
+
}
|
|
26723
|
+
}
|
|
25655
26724
|
this.#enqueueDirectRecoveredVideo(packetId, data, meta);
|
|
25656
26725
|
const lastSourceTs = this.#lastDirectSourceVideoTsByStream.get(streamKey);
|
|
25657
26726
|
this.#drainDirectRecoveredVideo(
|
|
@@ -25805,6 +26874,13 @@ var MmtpRouter = class {
|
|
|
25805
26874
|
* frames by epoch only if pre-protection input ever matters.
|
|
25806
26875
|
*/
|
|
25807
26876
|
#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete, assisted = false) {
|
|
26877
|
+
const overlayRouted = ownerPacketId == null ? void 0 : this.#streams.get(ownerPacketId)?.get(catalogTrackName)?.overlayToBase.routed;
|
|
26878
|
+
if (overlayRouted !== void 0 && overlayRouted.size > 0) {
|
|
26879
|
+
result = {
|
|
26880
|
+
...result,
|
|
26881
|
+
symbols: result.symbols.filter((sym) => !overlayRouted.has(this.#fecAnchorForRecovered(blockId, sym.index)))
|
|
26882
|
+
};
|
|
26883
|
+
}
|
|
25808
26884
|
const entry = ownerPacketId == null ? void 0 : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
25809
26885
|
const receiver = entry === void 0 || entry === "ambiguous" ? entry : entry.receiver;
|
|
25810
26886
|
const userAgent = !assisted && entry !== void 0 && entry !== "ambiguous" && entry.protected === true && entry.userAgent === true;
|
|
@@ -25861,7 +26937,12 @@ var MmtpRouter = class {
|
|
|
25861
26937
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, overlay) {
|
|
25862
26938
|
if (ownerPacketId == null) return;
|
|
25863
26939
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
25864
|
-
const fecSbnOf = (index) =>
|
|
26940
|
+
const fecSbnOf = (index) => {
|
|
26941
|
+
if (!overlay) return { fecSbn: this.#fecAnchorForRecovered(blockId, index) };
|
|
26942
|
+
const fecSbn = overlay.baseSsIds.get(index);
|
|
26943
|
+
const fecSbnFirst = overlay.firstSsIds.get(index);
|
|
26944
|
+
return fecSbn === void 0 || fecSbnFirst === void 0 ? {} : { fecSbn, fecSbnFirst };
|
|
26945
|
+
};
|
|
25865
26946
|
const streamKey = this.#mediaStreamKey(ownerPacketId, catalogTrackName);
|
|
25866
26947
|
const ssIdSeqOffset = overlay ? void 0 : this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
25867
26948
|
if (ssIdSeqOffset !== void 0) {
|
|
@@ -25869,7 +26950,10 @@ var MmtpRouter = class {
|
|
|
25869
26950
|
...result,
|
|
25870
26951
|
symbols: result.symbols.map((sym) => {
|
|
25871
26952
|
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
25872
|
-
if (wire === sym.packetSequenceNumber)
|
|
26953
|
+
if (wire === sym.packetSequenceNumber) {
|
|
26954
|
+
this.#unstampedSsIdSeqOffsetByStream.set(streamKey, ssIdSeqOffset);
|
|
26955
|
+
return sym;
|
|
26956
|
+
}
|
|
25873
26957
|
this.#restampedRecoveredSeqs++;
|
|
25874
26958
|
this.#restampedStreams.add(streamKey);
|
|
25875
26959
|
return { ...sym, packetSequenceNumber: wire };
|
|
@@ -25905,6 +26989,29 @@ var MmtpRouter = class {
|
|
|
25905
26989
|
}
|
|
25906
26990
|
);
|
|
25907
26991
|
}
|
|
26992
|
+
const untimedHead = (sym) => sym.fragmentType === 2 && sym.fragment.fragmentationIndicator === 1 && sym.fragment.movieFragmentSequenceNumber !== void 0 && sym.fragment.sampleNumber !== void 0 && !this.#parser.hasAuthoredTimingFor(
|
|
26993
|
+
ownerPacketId,
|
|
26994
|
+
sym.fragment.mpuSequenceNumber,
|
|
26995
|
+
sym.fragment.movieFragmentSequenceNumber,
|
|
26996
|
+
sym.fragment.sampleNumber,
|
|
26997
|
+
catalogTrackName
|
|
26998
|
+
);
|
|
26999
|
+
for (const sym of result.symbols) {
|
|
27000
|
+
if (!untimedHead(sym) || this.#sourceSeqReceived(ownerPacketId, sym.packetSequenceNumber, catalogTrackName)) continue;
|
|
27001
|
+
this.#feedViaParser(
|
|
27002
|
+
sym.rawSymbol,
|
|
27003
|
+
{ packetId: ownerPacketId, sequenceNumber: sym.packetSequenceNumber },
|
|
27004
|
+
void 0,
|
|
27005
|
+
{
|
|
27006
|
+
skipFecPayloadId: true,
|
|
27007
|
+
recovered: true,
|
|
27008
|
+
deliveryProvenance,
|
|
27009
|
+
...fecSbnOf(sym.index),
|
|
27010
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
27011
|
+
}
|
|
27012
|
+
);
|
|
27013
|
+
}
|
|
27014
|
+
result = { ...result, symbols: result.symbols.filter((sym) => !untimedHead(sym)) };
|
|
25908
27015
|
const gated = this.#isFecTrack(ownerPacketId);
|
|
25909
27016
|
const assembler = this.#mseAssemblerFor(ownerPacketId, catalogTrackName);
|
|
25910
27017
|
if (assembler) {
|
|
@@ -27631,6 +28738,12 @@ function isNonNegativeSafeInteger(value) {
|
|
|
27631
28738
|
function isSymbolCounts(value) {
|
|
27632
28739
|
return isRecord(value) && hasExactKeys(value, ["multicast", "moq"]) && isNonNegativeSafeInteger(value["multicast"]) && isNonNegativeSafeInteger(value["moq"]);
|
|
27633
28740
|
}
|
|
28741
|
+
function isSpanFailure(value) {
|
|
28742
|
+
if (!isRecord(value) || !hasExactKeys(value, ["length", "sources"])) return false;
|
|
28743
|
+
const length = value["length"];
|
|
28744
|
+
const sources = value["sources"];
|
|
28745
|
+
return Number.isSafeInteger(length) && length > 0 && isNonNegativeSafeInteger(sources) && sources < length;
|
|
28746
|
+
}
|
|
27634
28747
|
function isNullableNonNegative(value) {
|
|
27635
28748
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
27636
28749
|
}
|
|
@@ -27650,7 +28763,10 @@ function isRepairLifecycleEvent(value) {
|
|
|
27650
28763
|
case "recovered":
|
|
27651
28764
|
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"]);
|
|
27652
28765
|
case "failed":
|
|
27653
|
-
return hasExactKeys(
|
|
28766
|
+
return hasExactKeys(
|
|
28767
|
+
value,
|
|
28768
|
+
"span" in value ? ["version", "type", "block", "blockClass", "symbols", "span"] : ["version", "type", "block", "blockClass", "symbols"]
|
|
28769
|
+
) && isRepairBlockIdentity(block) && BLOCK_CLASSES.has(value["blockClass"]) && isSymbolCounts(value["symbols"]) && (!("span" in value) || isSpanFailure(value["span"]));
|
|
27654
28770
|
case "repair-preempted":
|
|
27655
28771
|
case "repair-deferred":
|
|
27656
28772
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
@@ -27859,6 +28975,8 @@ var MulticastManager = class {
|
|
|
27859
28975
|
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
27860
28976
|
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
27861
28977
|
#repairReleases = /* @__PURE__ */ new Map();
|
|
28978
|
+
/** Protected repair flows owned by each live repair-endpoint release. */
|
|
28979
|
+
#repairProvenanceFlows = /* @__PURE__ */ new Map();
|
|
27862
28980
|
/** Each source's catalog keyframe overlay, from its `ok` binding. */
|
|
27863
28981
|
#overlayBindings = /* @__PURE__ */ new Map();
|
|
27864
28982
|
/** Installed overlay decoders (`setKeyframeOverlayDecoder`), by source. */
|
|
@@ -27916,7 +29034,7 @@ var MulticastManager = class {
|
|
|
27916
29034
|
onPublisherRestart: (packetId, catalogTrackName) => {
|
|
27917
29035
|
this.#resetStreamOutsideRouter(packetId, catalogTrackName);
|
|
27918
29036
|
},
|
|
27919
|
-
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass) => {
|
|
29037
|
+
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
27920
29038
|
const pathCount = this.#fec.blockPathCount(
|
|
27921
29039
|
sbn,
|
|
27922
29040
|
packetId,
|
|
@@ -27934,7 +29052,8 @@ var MulticastManager = class {
|
|
|
27934
29052
|
symbols: {
|
|
27935
29053
|
multicast: pathCount?.multicastSymbols ?? 0,
|
|
27936
29054
|
moq: pathCount?.moqSymbols ?? 0
|
|
27937
|
-
}
|
|
29055
|
+
},
|
|
29056
|
+
...span === void 0 ? {} : { span }
|
|
27938
29057
|
});
|
|
27939
29058
|
},
|
|
27940
29059
|
onFrameGap: (decision) => {
|
|
@@ -28022,6 +29141,11 @@ var MulticastManager = class {
|
|
|
28022
29141
|
this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
|
|
28023
29142
|
this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
|
|
28024
29143
|
};
|
|
29144
|
+
this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
|
|
29145
|
+
const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
|
|
29146
|
+
if (binding === void 0) return void 0;
|
|
29147
|
+
return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
|
|
29148
|
+
};
|
|
28025
29149
|
this.#fec.onDecoderUnavailable = (event) => {
|
|
28026
29150
|
this.#emitRepairLifecycle({
|
|
28027
29151
|
version: 2,
|
|
@@ -28524,6 +29648,9 @@ var MulticastManager = class {
|
|
|
28524
29648
|
this.#transport.onFailback((reason) => {
|
|
28525
29649
|
const joined = this.#provenanceJoin;
|
|
28526
29650
|
if (joined !== null) this.#router.unprotectProvenanceFlow(joined.flow);
|
|
29651
|
+
for (const flows of this.#repairProvenanceFlows.values()) {
|
|
29652
|
+
for (const flow of flows) this.#router.unprotectProvenanceFlow(flow);
|
|
29653
|
+
}
|
|
28527
29654
|
this.#onFailback?.(reason);
|
|
28528
29655
|
});
|
|
28529
29656
|
}
|
|
@@ -28558,6 +29685,12 @@ var MulticastManager = class {
|
|
|
28558
29685
|
"[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port"
|
|
28559
29686
|
);
|
|
28560
29687
|
}
|
|
29688
|
+
if (provenanceFlow !== void 0) {
|
|
29689
|
+
const flow = multicastProvenanceFlowKey(provenanceFlow);
|
|
29690
|
+
if ([...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
29691
|
+
throw new TypeError(`[MulticastManager] join: provenance flow already registered by a repair endpoint: ${flow}`);
|
|
29692
|
+
}
|
|
29693
|
+
}
|
|
28561
29694
|
const staged = this.#renditionSwitch;
|
|
28562
29695
|
if (staged !== null) this.#endRenditionSwitch(staged, { reason: "superseded" }, false);
|
|
28563
29696
|
this.configureFec(config);
|
|
@@ -28565,8 +29698,8 @@ var MulticastManager = class {
|
|
|
28565
29698
|
const selectedPacketIds = config.packetIds?.length ? new Set(config.packetIds) : null;
|
|
28566
29699
|
const catalogTracks = config.tracks?.filter(({ packetId }) => selectedPacketIds === null || selectedPacketIds.has(packetId));
|
|
28567
29700
|
const ingressTracks = catalogTracks ? catalogTracks : selectedPacketIds === null ? void 0 : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
|
|
28568
|
-
this.#releaseProvenanceJoin();
|
|
28569
29701
|
const provenance = config.provenance;
|
|
29702
|
+
this.#releaseProvenanceJoin();
|
|
28570
29703
|
const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
|
|
28571
29704
|
const ingress = protectedTracks === void 0 ? void 0 : {
|
|
28572
29705
|
tracks: Object.freeze(
|
|
@@ -28619,8 +29752,13 @@ var MulticastManager = class {
|
|
|
28619
29752
|
* feeds the flow's receiver; media datagrams are held until one admits them.
|
|
28620
29753
|
*/
|
|
28621
29754
|
#joinProvenance(provenance, ingress) {
|
|
29755
|
+
this.#router.registerProvenanceFlow(ingress, this.#provenanceReceiver(provenance));
|
|
29756
|
+
this.#hookFailback();
|
|
29757
|
+
this.#provenanceJoin = { flow: ingress.flow };
|
|
29758
|
+
}
|
|
29759
|
+
#provenanceReceiver(provenance) {
|
|
28622
29760
|
const { flow, auth } = provenance;
|
|
28623
|
-
|
|
29761
|
+
return new BcProvenanceV2Receiver({
|
|
28624
29762
|
...provenance.receiver,
|
|
28625
29763
|
// The caller's ctx when it passes one, else the catalog's: an explicit
|
|
28626
29764
|
// `catalogCtx: undefined` must not switch off the 7.2.4 ctx check.
|
|
@@ -28637,9 +29775,6 @@ var MulticastManager = class {
|
|
|
28637
29775
|
maxAuthDelayMs: flow.maxAuthDelayMs,
|
|
28638
29776
|
manifestTimerMs: flow.manifestTimerMs
|
|
28639
29777
|
});
|
|
28640
|
-
this.#router.registerProvenanceFlow(ingress, receiver);
|
|
28641
|
-
this.#hookFailback();
|
|
28642
|
-
this.#provenanceJoin = { flow: ingress.flow };
|
|
28643
29778
|
}
|
|
28644
29779
|
/** Un-protect: drop the flow's hold queues (no expiry counted). */
|
|
28645
29780
|
#releaseProvenanceJoin() {
|
|
@@ -28670,8 +29805,25 @@ var MulticastManager = class {
|
|
|
28670
29805
|
* callback delivers must come from a subscription opened on
|
|
28671
29806
|
* `options.gateway`. A callback that also merges another source (a MoQ or
|
|
28672
29807
|
* WebSocket repair feed) must not name a native provider here.
|
|
29808
|
+
*
|
|
29809
|
+
* An endpoint's `provenance` makes its group a protected flow of its own
|
|
29810
|
+
* (multicast-02 7.2.7), registered here and released with the group; its
|
|
29811
|
+
* records ride in band on the group's port. On the user-agent path a
|
|
29812
|
+
* flow-less repair group of a protected track is set aside, never read, so
|
|
29813
|
+
* a player joining a protected catalog's repair groups passes it.
|
|
28673
29814
|
*/
|
|
28674
29815
|
joinRepairEndpoints(endpoints, provider, options) {
|
|
29816
|
+
for (const { provenance, flow, source, group, port: port2 } of endpoints) {
|
|
29817
|
+
if (provenance === void 0) continue;
|
|
29818
|
+
if (flow !== void 0) {
|
|
29819
|
+
throw new TypeError("[MulticastManager] joinRepairEndpoints: an endpoint names provenance or flow, never both");
|
|
29820
|
+
}
|
|
29821
|
+
if (!sameIpAddress(source, provenance.flow.source) || !sameIpAddress(group, provenance.flow.groupAddress) || port2 !== provenance.flow.port) {
|
|
29822
|
+
throw new RangeError(
|
|
29823
|
+
"[MulticastManager] joinRepairEndpoints: provenance flow (S, G, port) must match the endpoint's source, group and port"
|
|
29824
|
+
);
|
|
29825
|
+
}
|
|
29826
|
+
}
|
|
28675
29827
|
const releases = [];
|
|
28676
29828
|
let released = false;
|
|
28677
29829
|
const safely = (each) => {
|
|
@@ -28681,17 +29833,36 @@ var MulticastManager = class {
|
|
|
28681
29833
|
console.warn("[MulticastManager] repair group release failed", error);
|
|
28682
29834
|
}
|
|
28683
29835
|
};
|
|
29836
|
+
const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
|
|
29837
|
+
const preparedProvenance = endpoints.map((endpoint) => {
|
|
29838
|
+
if (endpoint.provenance === void 0) return void 0;
|
|
29839
|
+
const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
29840
|
+
if (usedFlows.has(flow) || this.#provenanceJoin?.flow === flow || [...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
29841
|
+
throw new TypeError(`[MulticastManager] joinRepairEndpoints: provenance flow already registered: ${flow}`);
|
|
29842
|
+
}
|
|
29843
|
+
usedFlows.add(flow);
|
|
29844
|
+
return { flow, receiver: this.#provenanceReceiver(endpoint.provenance) };
|
|
29845
|
+
});
|
|
29846
|
+
const provenanceFlows = [];
|
|
28684
29847
|
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners.map((owner) => owner.instance !== "keyframe" ? owner : {
|
|
28685
29848
|
...owner,
|
|
28686
29849
|
ownerTrackName: endpoint.tracks.find((t) => t.packetId === owner.ownerPacketId)?.name,
|
|
28687
29850
|
repairTrackName: endpoint.tracks.find((t) => t.packetId === owner.packetId)?.name
|
|
28688
29851
|
}));
|
|
28689
29852
|
this.#applyRepairOwners(repairOwners);
|
|
28690
|
-
for (const endpoint of endpoints) {
|
|
29853
|
+
for (const [index, endpoint] of endpoints.entries()) {
|
|
29854
|
+
const flow = endpoint.provenance === void 0 ? endpoint.flow : multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
28691
29855
|
const ingress = {
|
|
28692
29856
|
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
|
|
28693
|
-
...
|
|
29857
|
+
...flow === void 0 ? {} : { flow }
|
|
28694
29858
|
};
|
|
29859
|
+
if (endpoint.provenance !== void 0) {
|
|
29860
|
+
const prepared = preparedProvenance[index];
|
|
29861
|
+
if (prepared === void 0) throw new Error("[MulticastManager] repair provenance preparation missing");
|
|
29862
|
+
this.#router.registerProvenanceFlow(ingress, prepared.receiver);
|
|
29863
|
+
provenanceFlows.push(prepared.flow);
|
|
29864
|
+
releases.push(() => this.#router.releaseProvenanceFlow(flow));
|
|
29865
|
+
}
|
|
28695
29866
|
let sender;
|
|
28696
29867
|
const feed = (packet, sourceAddress, ingressToFeed) => {
|
|
28697
29868
|
if (released) return;
|
|
@@ -28721,7 +29892,7 @@ var MulticastManager = class {
|
|
|
28721
29892
|
packetIds: endpoint.packetIds,
|
|
28722
29893
|
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
|
|
28723
29894
|
// A protected repair group's records ride in band on its port (7.2.3).
|
|
28724
|
-
...
|
|
29895
|
+
...flow === void 0 ? {} : { protected: true }
|
|
28725
29896
|
}, ingress).then((joined) => {
|
|
28726
29897
|
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
28727
29898
|
});
|
|
@@ -28730,9 +29901,12 @@ var MulticastManager = class {
|
|
|
28730
29901
|
if (released) return;
|
|
28731
29902
|
released = true;
|
|
28732
29903
|
this.#repairReleases.delete(release);
|
|
29904
|
+
this.#repairProvenanceFlows.delete(release);
|
|
28733
29905
|
for (const each of releases.splice(0)) safely(each);
|
|
28734
29906
|
};
|
|
28735
29907
|
this.#repairReleases.set(release, repairOwners);
|
|
29908
|
+
this.#repairProvenanceFlows.set(release, provenanceFlows);
|
|
29909
|
+
if (provenanceFlows.length) this.#hookFailback();
|
|
28736
29910
|
return release;
|
|
28737
29911
|
}
|
|
28738
29912
|
#applyRepairOwners(owners) {
|
|
@@ -29218,7 +30392,8 @@ var MulticastManager = class {
|
|
|
29218
30392
|
blockProfile: parseFecBlockProfile(
|
|
29219
30393
|
geometry2.blockProfile,
|
|
29220
30394
|
`tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
|
|
29221
|
-
)
|
|
30395
|
+
),
|
|
30396
|
+
geometry: geometry2
|
|
29222
30397
|
});
|
|
29223
30398
|
}
|
|
29224
30399
|
}
|
|
@@ -29257,7 +30432,7 @@ var MulticastManager = class {
|
|
|
29257
30432
|
for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
|
|
29258
30433
|
const before = this.#overlayBindings.get(sourcePacketId);
|
|
29259
30434
|
const after = overlayBindings.get(sourcePacketId);
|
|
29260
|
-
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
|
|
30435
|
+
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
|
|
29261
30436
|
if (!same) install.dispose();
|
|
29262
30437
|
else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
|
|
29263
30438
|
else install.reattach();
|
|
@@ -29314,10 +30489,12 @@ var MulticastManager = class {
|
|
|
29314
30489
|
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
29315
30490
|
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
29316
30491
|
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
29317
|
-
* once its range FETCH ends (or none is sent).
|
|
30492
|
+
* once its range FETCH ends (or none is sent). `onExpired` is told of a
|
|
30493
|
+
* pending hole the stream runs past the locator's horizon: returning true,
|
|
30494
|
+
* the caller closes it (`closeIsoHoles`); otherwise it is discarded.
|
|
29318
30495
|
*/
|
|
29319
|
-
onUndelimitedLoss(cb) {
|
|
29320
|
-
this.#fec.setUndelimitedLossHandler(cb);
|
|
30496
|
+
onUndelimitedLoss(cb, onExpired) {
|
|
30497
|
+
this.#fec.setUndelimitedLossHandler(cb, onExpired ?? null);
|
|
29321
30498
|
}
|
|
29322
30499
|
/**
|
|
29323
30500
|
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
@@ -29553,7 +30730,8 @@ var MulticastManager = class {
|
|
|
29553
30730
|
"stream" in event ? { ...event, stream: Object.freeze({ ...event.stream }) } : {
|
|
29554
30731
|
...event,
|
|
29555
30732
|
block: Object.freeze({ ...event.block }),
|
|
29556
|
-
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {}
|
|
30733
|
+
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {},
|
|
30734
|
+
..."span" in event && event.span !== void 0 ? { span: Object.freeze({ ...event.span }) } : {}
|
|
29557
30735
|
}
|
|
29558
30736
|
);
|
|
29559
30737
|
if (this.#logRepairLifecycle) {
|
|
@@ -29666,7 +30844,7 @@ async function setupFecWorkerForTrack(opts) {
|
|
|
29666
30844
|
blockProfile,
|
|
29667
30845
|
k: opts.fecK,
|
|
29668
30846
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
29669
|
-
// and CMCD `
|
|
30847
|
+
// and CMCD `com.blockcast-fp` are read from this. Identity on a single layer.
|
|
29670
30848
|
repairCount: opts.joinedRepairCount ?? opts.fecRepairCount,
|
|
29671
30849
|
symbolSize: opts.fecSymbolSize,
|
|
29672
30850
|
interleaveDepth: interleaveDepthBlocks,
|
|
@@ -30208,24 +31386,24 @@ var MediaRouter = class {
|
|
|
30208
31386
|
if (!this.#multicastVideoKeyed) return;
|
|
30209
31387
|
if (this.#requireAudio && !this.#multicastAudioReceived) return;
|
|
30210
31388
|
if (this.#requireAudio && !this.#moqAudioWarmed) return;
|
|
30211
|
-
const
|
|
31389
|
+
const token2 = ++this.#sourceSwitchToken;
|
|
30212
31390
|
const maybeReady = this.#onSourceSwitch?.("multicast");
|
|
30213
31391
|
if (!maybeReady || typeof maybeReady.then !== "function") {
|
|
30214
|
-
this.#commitMulticastActivation(
|
|
31392
|
+
this.#commitMulticastActivation(token2);
|
|
30215
31393
|
return;
|
|
30216
31394
|
}
|
|
30217
31395
|
const ready = Promise.resolve(maybeReady);
|
|
30218
|
-
this.#pendingMulticastToken =
|
|
31396
|
+
this.#pendingMulticastToken = token2;
|
|
30219
31397
|
this.#sourceSwitchReady = ready;
|
|
30220
31398
|
void ready.then(
|
|
30221
|
-
() => this.#commitMulticastActivation(
|
|
30222
|
-
(err) => this.#rejectMulticastActivation(
|
|
31399
|
+
() => this.#commitMulticastActivation(token2),
|
|
31400
|
+
(err) => this.#rejectMulticastActivation(token2, err)
|
|
30223
31401
|
).finally(() => {
|
|
30224
31402
|
if (this.#sourceSwitchReady === ready) this.#sourceSwitchReady = null;
|
|
30225
31403
|
});
|
|
30226
31404
|
}
|
|
30227
|
-
#commitMulticastActivation(
|
|
30228
|
-
if (
|
|
31405
|
+
#commitMulticastActivation(token2) {
|
|
31406
|
+
if (token2 !== this.#sourceSwitchToken) return;
|
|
30229
31407
|
this.#active = "multicast";
|
|
30230
31408
|
this.#suppressed = true;
|
|
30231
31409
|
this.#pendingMulticastToken = null;
|
|
@@ -30236,9 +31414,9 @@ var MediaRouter = class {
|
|
|
30236
31414
|
if (video) this.#onVideoFrame?.(video.data, video.meta);
|
|
30237
31415
|
if (audio) this.#onAudioFrame?.(audio.data, audio.meta);
|
|
30238
31416
|
}
|
|
30239
|
-
#rejectMulticastActivation(
|
|
30240
|
-
if (
|
|
30241
|
-
if (this.#pendingMulticastToken ===
|
|
31417
|
+
#rejectMulticastActivation(token2, err) {
|
|
31418
|
+
if (token2 !== this.#sourceSwitchToken) return;
|
|
31419
|
+
if (this.#pendingMulticastToken === token2) this.#pendingMulticastToken = null;
|
|
30242
31420
|
this.#pendingMulticastVideo = null;
|
|
30243
31421
|
this.#pendingMulticastAudio = null;
|
|
30244
31422
|
console.warn("[MediaRouter] onSourceSwitch(multicast) failed", err);
|
|
@@ -31207,63 +32385,65 @@ var FecStarvationDetector = class {
|
|
|
31207
32385
|
|
|
31208
32386
|
// src/cmcd-producer.ts
|
|
31209
32387
|
var PLAY_MODES = ["full", "base-only", "single-track"];
|
|
31210
|
-
|
|
31211
|
-
|
|
31212
|
-
|
|
31213
|
-
|
|
31214
|
-
|
|
31215
|
-
|
|
31216
|
-
|
|
31217
|
-
|
|
31218
|
-
|
|
31219
|
-
|
|
31220
|
-
|
|
31221
|
-
|
|
31222
|
-
|
|
31223
|
-
|
|
31224
|
-
|
|
31225
|
-
|
|
31226
|
-
|
|
31227
|
-
|
|
31228
|
-
}
|
|
31229
|
-
if (snap.multicastSource != null) {
|
|
31230
|
-
params["x-bc-multicast-source"] = snap.multicastSource;
|
|
31231
|
-
}
|
|
31232
|
-
if (snap.amtRelay != null) {
|
|
31233
|
-
params["x-bc-amt-relay"] = snap.amtRelay;
|
|
31234
|
-
}
|
|
31235
|
-
return params;
|
|
31236
|
-
}
|
|
31237
|
-
function formatQueryString(params) {
|
|
31238
|
-
return Object.keys(params).sort().map((key) => {
|
|
31239
|
-
const v = params[key];
|
|
31240
|
-
if (typeof v === "string") return `${key}=${sanitize(v)}`;
|
|
31241
|
-
return `${key}=${v}`;
|
|
32388
|
+
var DEFAULT_INTERVAL_MS = 3e4;
|
|
32389
|
+
var CUSTOM_PREFIX = "com.blockcast-";
|
|
32390
|
+
var MAX_CUSTOM_VALUE = 64;
|
|
32391
|
+
var TRANSPORT_TOKEN = {
|
|
32392
|
+
native: "ssm",
|
|
32393
|
+
amt: "amt",
|
|
32394
|
+
moq: "moq"
|
|
32395
|
+
};
|
|
32396
|
+
function sfString(value) {
|
|
32397
|
+
return `"${value.replace(/[^\x20-\x7e]/g, "").replace(/[\\"]/g, "\\$&")}"`;
|
|
32398
|
+
}
|
|
32399
|
+
function encodeCmcdRecord(record) {
|
|
32400
|
+
return Object.keys(record).sort().map((key) => {
|
|
32401
|
+
const value = record[key];
|
|
32402
|
+
if (typeof value === "number") return `${key}=${value}`;
|
|
32403
|
+
if (typeof value === "string") return `${key}=${sfString(value)}`;
|
|
32404
|
+
if (Array.isArray(value)) return `${key}=(${value.map(sfString).join(" ")})`;
|
|
32405
|
+
return `${key}=${value.token}`;
|
|
31242
32406
|
}).join(",");
|
|
31243
32407
|
}
|
|
32408
|
+
var token = (value) => ({ token: value });
|
|
32409
|
+
function putCustom(record, name, value) {
|
|
32410
|
+
if (value === void 0) return;
|
|
32411
|
+
if (typeof value === "number") value = String(value);
|
|
32412
|
+
if (typeof value === "string" && value.length > MAX_CUSTOM_VALUE) return;
|
|
32413
|
+
record[CUSTOM_PREFIX + name] = value;
|
|
32414
|
+
}
|
|
31244
32415
|
var CmcdProducer = class {
|
|
31245
|
-
#onCmcdParams;
|
|
31246
32416
|
#onCmcdPost;
|
|
32417
|
+
#intervalMs;
|
|
32418
|
+
#sessionId;
|
|
32419
|
+
#now;
|
|
32420
|
+
#sn = 0;
|
|
32421
|
+
#lastHeartbeat = null;
|
|
31247
32422
|
#transport;
|
|
31248
32423
|
#lastStats;
|
|
31249
|
-
// Phase 14 state — Plan 03 Task 2 (D-12, D-15).
|
|
31250
32424
|
#playMode = null;
|
|
31251
32425
|
#deltaFailRate = null;
|
|
31252
32426
|
#switchMiscount = 0;
|
|
31253
32427
|
#manifestStats = null;
|
|
31254
32428
|
#fecFailClosed = null;
|
|
32429
|
+
/** Video-block resolutions from the repair lifecycle; null until the player feeds one. */
|
|
32430
|
+
#lifecycle = null;
|
|
31255
32431
|
constructor(options) {
|
|
31256
|
-
this.#onCmcdParams = options.onCmcdParams;
|
|
31257
32432
|
this.#onCmcdPost = options.onCmcdPost;
|
|
32433
|
+
this.#intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
32434
|
+
if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {
|
|
32435
|
+
throw new Error(`[CmcdProducer] invalid intervalMs "${String(options.intervalMs)}"; expected a positive number`);
|
|
32436
|
+
}
|
|
32437
|
+
this.#sessionId = options.sessionId ?? globalThis.crypto.randomUUID();
|
|
32438
|
+
this.#now = options.now ?? Date.now;
|
|
31258
32439
|
}
|
|
31259
32440
|
/** Update the stored transport state. Called by player wiring layer. */
|
|
31260
32441
|
updateTransport(snapshot) {
|
|
31261
32442
|
this.#transport = snapshot;
|
|
31262
32443
|
}
|
|
31263
32444
|
/**
|
|
31264
|
-
* Set the current play-mode
|
|
31265
|
-
*
|
|
31266
|
-
* (CLAUDE.md: error on bad init).
|
|
32445
|
+
* Set the current play-mode, reported as `com.blockcast-pm`. Throws on any
|
|
32446
|
+
* value outside {'full','base-only','single-track'} (CLAUDE.md: error on bad init).
|
|
31267
32447
|
*/
|
|
31268
32448
|
updatePlayMode(mode) {
|
|
31269
32449
|
if (typeof mode !== "string" || !PLAY_MODES.includes(mode)) {
|
|
@@ -31274,9 +32454,8 @@ var CmcdProducer = class {
|
|
|
31274
32454
|
this.#playMode = mode;
|
|
31275
32455
|
}
|
|
31276
32456
|
/**
|
|
31277
|
-
* Set the delta-track FEC block-failure rate (0..1 inclusive)
|
|
31278
|
-
* `
|
|
31279
|
-
* Omitted on single-track streams.
|
|
32457
|
+
* Set the delta-track FEC block-failure rate (0..1 inclusive), reported as
|
|
32458
|
+
* `com.blockcast-dfr` when play-mode is 'full' or 'base-only'.
|
|
31280
32459
|
*/
|
|
31281
32460
|
updateDeltaFailRate(rate) {
|
|
31282
32461
|
if (typeof rate !== "number" || !Number.isFinite(rate) || rate < 0 || rate > 1) {
|
|
@@ -31286,112 +32465,139 @@ var CmcdProducer = class {
|
|
|
31286
32465
|
}
|
|
31287
32466
|
this.#deltaFailRate = rate;
|
|
31288
32467
|
}
|
|
31289
|
-
/**
|
|
31290
|
-
* Bump the cumulative switching-set misalignment counter. Emitted as
|
|
31291
|
-
* `x-bc-switch-miscount` on snapshots when the counter is > 0.
|
|
31292
|
-
*/
|
|
32468
|
+
/** Bump the cumulative switching-set misalignment counter (`com.blockcast-sm`). */
|
|
31293
32469
|
incrementSwitchMiscount() {
|
|
31294
32470
|
this.#switchMiscount += 1;
|
|
31295
32471
|
}
|
|
31296
32472
|
/**
|
|
31297
|
-
* Record that FEC failed closed at runtime (fec-01 6.3.9).
|
|
31298
|
-
*
|
|
31299
|
-
* `
|
|
31300
|
-
* stream playing without FEC is told apart from one
|
|
32473
|
+
* Record that FEC failed closed at runtime (fec-01 6.3.9). Reported at once
|
|
32474
|
+
* as `e=e` with the reason code in `ec`, and on every later counter report
|
|
32475
|
+
* as `com.blockcast-ffc` / `com.blockcast-ffl` (the held layer whose total
|
|
32476
|
+
* B_i was undercut), so a stream playing without FEC is told apart from one
|
|
32477
|
+
* with no loss.
|
|
31301
32478
|
*/
|
|
31302
32479
|
updateFecFailClosed(reason) {
|
|
32480
|
+
const changed = this.#fecFailClosed?.code !== reason.code || this.#fecFailClosed?.layer !== reason.layer;
|
|
31303
32481
|
this.#fecFailClosed = reason;
|
|
32482
|
+
if (changed) this.#post([{ ...this.#base("e"), ec: [reason.code] }]);
|
|
31304
32483
|
}
|
|
31305
32484
|
updateManifestVerification(stats) {
|
|
31306
32485
|
this.#manifestStats = stats;
|
|
31307
32486
|
}
|
|
31308
32487
|
/**
|
|
31309
|
-
*
|
|
31310
|
-
*
|
|
31311
|
-
*
|
|
31312
|
-
*
|
|
32488
|
+
* Count a video block's resolution from the repair lifecycle: recovered in
|
|
32489
|
+
* band (`com.blockcast-fbr`), recovered by repair FETCH (`-fbq`), or failed
|
|
32490
|
+
* as a keyframe-class block (`-fbfk`). Audio blocks are not counted, matching
|
|
32491
|
+
* the video-track `-fbf`. Until the player feeds this, the three are absent.
|
|
31313
32492
|
*/
|
|
32493
|
+
onRepairLifecycle(event) {
|
|
32494
|
+
this.#lifecycle ??= { inband: 0, fetch: 0, failedKeyframe: 0 };
|
|
32495
|
+
if (event.type === "recovered" && event.blockClass !== "audio") {
|
|
32496
|
+
if (event.via === "inband") this.#lifecycle.inband++;
|
|
32497
|
+
else this.#lifecycle.fetch++;
|
|
32498
|
+
} else if (event.type === "failed" && event.blockClass === "keyframe") {
|
|
32499
|
+
this.#lifecycle.failedKeyframe++;
|
|
32500
|
+
}
|
|
32501
|
+
}
|
|
32502
|
+
/** One-shot custom event `com.blockcast-switch-drift` for a single misalignment. */
|
|
31314
32503
|
emitSwitchDrift(driftUs) {
|
|
31315
32504
|
if (typeof driftUs !== "number" || !Number.isFinite(driftUs) || driftUs < 0) {
|
|
31316
32505
|
throw new Error(
|
|
31317
32506
|
`[CmcdProducer] invalid drift-us "${String(driftUs)}"; expected a non-negative finite number`
|
|
31318
32507
|
);
|
|
31319
32508
|
}
|
|
31320
|
-
const
|
|
31321
|
-
|
|
31322
|
-
|
|
31323
|
-
if (this.#switchMiscount > 0) params["x-bc-switch-miscount"] = this.#switchMiscount;
|
|
31324
|
-
params["x-bc-switch-drift-us"] = driftUs;
|
|
31325
|
-
this.#emit(params);
|
|
32509
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "switch-drift" };
|
|
32510
|
+
putCustom(record, "sdu", Math.round(driftUs));
|
|
32511
|
+
this.#post([record]);
|
|
31326
32512
|
}
|
|
31327
|
-
/**
|
|
31328
|
-
* Process a FecTrackStats snapshot. Finds the video track, builds
|
|
31329
|
-
* x-bc-* vendor keys, and fires both delivery callbacks.
|
|
31330
|
-
*/
|
|
32513
|
+
/** Take a FecTrackStats snapshot (first video track) and send the heartbeat when due. */
|
|
31331
32514
|
onSnapshot(data) {
|
|
31332
32515
|
const videoTrack = data.tracks.find((t) => t.config.trackType === "video");
|
|
31333
32516
|
if (!videoTrack) return;
|
|
31334
32517
|
this.#lastStats = videoTrack;
|
|
31335
|
-
|
|
31336
|
-
...buildFecParams(videoTrack),
|
|
31337
|
-
...buildTransportParams(this.#transport)
|
|
31338
|
-
};
|
|
31339
|
-
if (this.#playMode !== null) {
|
|
31340
|
-
params["x-bc-play-mode"] = this.#playMode;
|
|
31341
|
-
}
|
|
31342
|
-
if (this.#fecFailClosed) {
|
|
31343
|
-
params["x-bc-fec-fail-closed"] = this.#fecFailClosed.code;
|
|
31344
|
-
params["x-bc-fec-fail-layer"] = this.#fecFailClosed.layer;
|
|
31345
|
-
}
|
|
31346
|
-
if (this.#playMode !== null && this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
31347
|
-
params["x-bc-delta-fail-rate"] = parseFloat(this.#deltaFailRate.toFixed(4));
|
|
31348
|
-
}
|
|
31349
|
-
if (this.#switchMiscount > 0) {
|
|
31350
|
-
params["x-bc-switch-miscount"] = this.#switchMiscount;
|
|
31351
|
-
}
|
|
31352
|
-
if (this.#manifestStats) {
|
|
31353
|
-
params["x-bc-manifest-verified"] = this.#manifestStats.verified > 0;
|
|
31354
|
-
params["x-bc-manifest-failures"] = Object.values(this.#manifestStats.failures).reduce((total, count) => total + count, 0);
|
|
31355
|
-
}
|
|
31356
|
-
this.#emit(params);
|
|
32518
|
+
this.#heartbeat();
|
|
31357
32519
|
}
|
|
31358
32520
|
/**
|
|
31359
|
-
*
|
|
31360
|
-
*
|
|
32521
|
+
* Take transport state for receivers that do not own FEC stats, and send the
|
|
32522
|
+
* heartbeat when due.
|
|
31361
32523
|
*/
|
|
31362
32524
|
onTransportSnapshot(data) {
|
|
31363
32525
|
if (!Number.isFinite(data.timestampMs) || data.timestampMs < 0) {
|
|
31364
32526
|
throw new Error("[CmcdProducer] transport snapshot timestamp must be a non-negative finite number");
|
|
31365
32527
|
}
|
|
31366
32528
|
if (data.playMode !== void 0) this.updatePlayMode(data.playMode);
|
|
31367
|
-
if (data.switchMiscount !== void 0
|
|
31368
|
-
|
|
32529
|
+
if (data.switchMiscount !== void 0) {
|
|
32530
|
+
if (!Number.isSafeInteger(data.switchMiscount) || data.switchMiscount < 0) {
|
|
32531
|
+
throw new Error("[CmcdProducer] transport snapshot switch-miscount must be a non-negative safe integer");
|
|
32532
|
+
}
|
|
32533
|
+
this.#switchMiscount = data.switchMiscount;
|
|
31369
32534
|
}
|
|
31370
32535
|
this.#transport = data.transport;
|
|
31371
|
-
|
|
31372
|
-
if (this.#playMode !== null) params["x-bc-play-mode"] = this.#playMode;
|
|
31373
|
-
const switchMiscount = data.switchMiscount ?? this.#switchMiscount;
|
|
31374
|
-
if (switchMiscount > 0) params["x-bc-switch-miscount"] = switchMiscount;
|
|
31375
|
-
this.#emit(params);
|
|
32536
|
+
this.#heartbeat();
|
|
31376
32537
|
}
|
|
31377
|
-
/**
|
|
31378
|
-
* Signal a transport transition event. Fires an immediate out-of-band
|
|
31379
|
-
* emit with x-bc-ct set. The subsequent onSnapshot() will NOT include
|
|
31380
|
-
* x-bc-ct (one-shot).
|
|
31381
|
-
*/
|
|
32538
|
+
/** Report a transport transition at once, as custom event `com.blockcast-ct`. */
|
|
31382
32539
|
onTransition(event) {
|
|
31383
|
-
const
|
|
31384
|
-
|
|
31385
|
-
|
|
32540
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "ct" };
|
|
32541
|
+
putCustom(record, "ct", token(event));
|
|
32542
|
+
this.#putTransport(record);
|
|
32543
|
+
this.#post([record]);
|
|
32544
|
+
}
|
|
32545
|
+
#base(event) {
|
|
32546
|
+
return { e: token(event), sid: this.#sessionId, sn: this.#sn++, ts: Math.floor(this.#now()), v: 2 };
|
|
32547
|
+
}
|
|
32548
|
+
#heartbeat() {
|
|
32549
|
+
const now = this.#now();
|
|
32550
|
+
if (this.#lastHeartbeat !== null && now - this.#lastHeartbeat < this.#intervalMs) return;
|
|
32551
|
+
this.#lastHeartbeat = now;
|
|
32552
|
+
this.#post([this.#base("t"), this.#counters()]);
|
|
32553
|
+
}
|
|
32554
|
+
#putTransport(record) {
|
|
32555
|
+
const snap = this.#transport;
|
|
32556
|
+
if (!snap) return;
|
|
32557
|
+
putCustom(record, "tr", token(TRANSPORT_TOKEN[snap.transport]));
|
|
32558
|
+
if (snap.multicastGroup != null && snap.multicastSource != null) {
|
|
32559
|
+
putCustom(record, "sg", `${snap.multicastGroup}@${snap.multicastSource}`);
|
|
32560
|
+
}
|
|
32561
|
+
putCustom(record, "ar", snap.amtRelay);
|
|
32562
|
+
}
|
|
32563
|
+
/** The `e=ce` counter report. */
|
|
32564
|
+
#counters() {
|
|
32565
|
+
const record = { ...this.#base("ce"), cen: CUSTOM_PREFIX + "fec" };
|
|
32566
|
+
const stats = this.#lastStats;
|
|
32567
|
+
if (stats) {
|
|
32568
|
+
putCustom(record, "fa", stats.config.algorithm);
|
|
32569
|
+
putCustom(record, "fk", stats.config.k);
|
|
32570
|
+
putCustom(record, "fp", stats.config.repairCount);
|
|
32571
|
+
putCustom(record, "pr", stats.sourceSymbols);
|
|
32572
|
+
putCustom(record, "pl", stats.sourcePacketsMissing);
|
|
32573
|
+
putCustom(record, "pu", stats.sourcePacketsUnrecovered);
|
|
32574
|
+
putCustom(record, "fbf", stats.blocksFailed);
|
|
32575
|
+
}
|
|
32576
|
+
if (this.#lifecycle) {
|
|
32577
|
+
putCustom(record, "fbr", this.#lifecycle.inband);
|
|
32578
|
+
putCustom(record, "fbq", this.#lifecycle.fetch);
|
|
32579
|
+
putCustom(record, "fbfk", this.#lifecycle.failedKeyframe);
|
|
32580
|
+
}
|
|
32581
|
+
this.#putTransport(record);
|
|
32582
|
+
if (this.#playMode !== null) {
|
|
32583
|
+
putCustom(record, "pm", token(this.#playMode));
|
|
32584
|
+
if (this.#playMode !== "single-track" && this.#deltaFailRate !== null) {
|
|
32585
|
+
putCustom(record, "dfr", this.#deltaFailRate.toFixed(3));
|
|
32586
|
+
}
|
|
31386
32587
|
}
|
|
31387
|
-
|
|
31388
|
-
|
|
31389
|
-
|
|
32588
|
+
if (this.#fecFailClosed) {
|
|
32589
|
+
putCustom(record, "ffc", token(this.#fecFailClosed.code));
|
|
32590
|
+
putCustom(record, "ffl", this.#fecFailClosed.layer);
|
|
32591
|
+
}
|
|
32592
|
+
if (this.#switchMiscount > 0) putCustom(record, "sm", this.#switchMiscount);
|
|
32593
|
+
if (this.#manifestStats) {
|
|
32594
|
+
putCustom(record, "mv", this.#manifestStats.verified);
|
|
32595
|
+
putCustom(record, "mf", Object.values(this.#manifestStats.failures).reduce((a, b) => a + b, 0));
|
|
32596
|
+
}
|
|
32597
|
+
return record;
|
|
31390
32598
|
}
|
|
31391
|
-
|
|
31392
|
-
|
|
31393
|
-
this.#onCmcdParams?.(params);
|
|
31394
|
-
this.#onCmcdPost?.(formatQueryString(params));
|
|
32599
|
+
#post(records) {
|
|
32600
|
+
this.#onCmcdPost?.(records.map(encodeCmcdRecord).join("\n"));
|
|
31395
32601
|
}
|
|
31396
32602
|
};
|
|
31397
32603
|
|
|
@@ -31487,6 +32693,19 @@ function resolveRepairLayers(catalog, source) {
|
|
|
31487
32693
|
totalBaseRepairSymbols: binding.totalBaseRepairSymbols
|
|
31488
32694
|
};
|
|
31489
32695
|
}
|
|
32696
|
+
function valueAt(catalog, pointer) {
|
|
32697
|
+
let node = catalog;
|
|
32698
|
+
for (const segment of pointer.split("/").slice(1)) {
|
|
32699
|
+
if (typeof node !== "object" || node === null) return void 0;
|
|
32700
|
+
node = node[segment.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
32701
|
+
}
|
|
32702
|
+
return node;
|
|
32703
|
+
}
|
|
32704
|
+
function catalogTrackDeliveryMode(catalog, source) {
|
|
32705
|
+
const binding = bindingOf(catalog, source);
|
|
32706
|
+
const entry = binding ? valueAt(catalog, binding.pointer) : void 0;
|
|
32707
|
+
return entry?.deliveryMode === "stream" ? "stream" : "datagram";
|
|
32708
|
+
}
|
|
31490
32709
|
function moqtPriority2(value) {
|
|
31491
32710
|
return Number.isSafeInteger(value) && value >= 0 && value <= 255 ? value : null;
|
|
31492
32711
|
}
|
|
@@ -31530,6 +32749,7 @@ function fecParams(catalog, track, fps, sampleRate) {
|
|
|
31530
32749
|
repairTrackName: base.repairTrack,
|
|
31531
32750
|
repairLayers: repair.baseLayers,
|
|
31532
32751
|
repairOverlays: repair.overlays,
|
|
32752
|
+
deliveryMode: catalogTrackDeliveryMode(catalog, track),
|
|
31533
32753
|
...mediaRate
|
|
31534
32754
|
};
|
|
31535
32755
|
}
|
|
@@ -32054,7 +33274,7 @@ var RepairLayerSubscriptions = class {
|
|
|
32054
33274
|
* or interleaved sequences read as loss.
|
|
32055
33275
|
*/
|
|
32056
33276
|
noteSourceSequence(seq) {
|
|
32057
|
-
if (this.#disposed || this.#
|
|
33277
|
+
if (this.#disposed || this.#delivery() === "stream") return;
|
|
32058
33278
|
seq >>>= 0;
|
|
32059
33279
|
if (this.#lastSeq === void 0) {
|
|
32060
33280
|
this.#lastSeq = seq;
|
|
@@ -32087,12 +33307,12 @@ var RepairLayerSubscriptions = class {
|
|
|
32087
33307
|
this.#expected = 0;
|
|
32088
33308
|
this.#lost = 0;
|
|
32089
33309
|
this.#wantFewer = 0;
|
|
32090
|
-
this.#layerCount = Math.min(this.#layerCount, this.#layers().length);
|
|
33310
|
+
this.#layerCount = this.#delivery() === "stream" ? 0 : Math.min(this.#layerCount, this.#layers().length);
|
|
32091
33311
|
this.#reconcile();
|
|
32092
33312
|
}
|
|
32093
33313
|
snapshot() {
|
|
32094
33314
|
return {
|
|
32095
|
-
delivery: this.#
|
|
33315
|
+
delivery: this.#delivery(),
|
|
32096
33316
|
layerCount: this.#layerCount,
|
|
32097
33317
|
subscribedTracks: [...this.#subs.keys()],
|
|
32098
33318
|
repairPackets: this.#repairPackets,
|
|
@@ -32106,6 +33326,9 @@ var RepairLayerSubscriptions = class {
|
|
|
32106
33326
|
this.#closeAll();
|
|
32107
33327
|
this.#disposed = true;
|
|
32108
33328
|
}
|
|
33329
|
+
#delivery() {
|
|
33330
|
+
return this.#source.deliveryMode === "stream" ? "stream" : "datagram";
|
|
33331
|
+
}
|
|
32109
33332
|
#layers() {
|
|
32110
33333
|
return this.#source.repairLayers ?? [];
|
|
32111
33334
|
}
|
|
@@ -32180,6 +33403,7 @@ var RepairLayerSubscriptions = class {
|
|
|
32180
33403
|
|
|
32181
33404
|
// src/repair-fetch.ts
|
|
32182
33405
|
var MOQT_PRIORITY_MAX = 255;
|
|
33406
|
+
var WALK_LEAD_MS = 3;
|
|
32183
33407
|
var SOURCE_MEDIA_PRIORITY_MAX = REPAIR_PRIORITY_MIN - 1;
|
|
32184
33408
|
function isMoqtPriority(value) {
|
|
32185
33409
|
return Number.isSafeInteger(value) && value >= 0 && value <= MOQT_PRIORITY_MAX;
|
|
@@ -32230,8 +33454,17 @@ function wireRepairFetch(mc, opts) {
|
|
|
32230
33454
|
mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
32231
33455
|
};
|
|
32232
33456
|
const clearEntry = (entry) => {
|
|
32233
|
-
|
|
32234
|
-
|
|
33457
|
+
const { range } = entry;
|
|
33458
|
+
if (range) {
|
|
33459
|
+
atReport(range, () => mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, range.holeLength));
|
|
33460
|
+
} else {
|
|
33461
|
+
clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
33462
|
+
}
|
|
33463
|
+
};
|
|
33464
|
+
const atReport = (range, work) => {
|
|
33465
|
+
const fec = mc.fecManager;
|
|
33466
|
+
if (range.groups !== null || fec.withReceiptTime === void 0) work();
|
|
33467
|
+
else fec.withReceiptTime(range.reportedAt, work);
|
|
32235
33468
|
};
|
|
32236
33469
|
const releaseHold = (entry) => {
|
|
32237
33470
|
if (entry.range) return;
|
|
@@ -32243,7 +33476,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32243
33476
|
if (!run) return;
|
|
32244
33477
|
entry.running = null;
|
|
32245
33478
|
run.stopped = reason;
|
|
32246
|
-
run.controller.abort();
|
|
33479
|
+
run.controller.abort(reason);
|
|
32247
33480
|
if (reason === "preempted") releaseHold(entry);
|
|
32248
33481
|
mc.noteRepairStopped?.(reason, entry.sbn, entry.packetId, entry.catalogTrackName);
|
|
32249
33482
|
};
|
|
@@ -32298,21 +33531,42 @@ function wireRepairFetch(mc, opts) {
|
|
|
32298
33531
|
const admit = (entry, now) => {
|
|
32299
33532
|
const budgetMs = entry.deadlineAt - now;
|
|
32300
33533
|
const rttMs = readRtt();
|
|
32301
|
-
const reason =
|
|
33534
|
+
const reason = refusal(entry, now, rttMs);
|
|
32302
33535
|
if (reason === null) return rttMs;
|
|
32303
33536
|
skip(entry, reason, rttMs, budgetMs);
|
|
32304
33537
|
return null;
|
|
32305
33538
|
};
|
|
33539
|
+
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";
|
|
32306
33540
|
const retire = (entry) => {
|
|
32307
33541
|
if (entries.get(entry.key) === entry) entries.delete(entry.key);
|
|
32308
33542
|
if (entry.expiry !== void 0) clearTimeout(entry.expiry);
|
|
32309
33543
|
};
|
|
32310
|
-
const
|
|
33544
|
+
const holdsBack = (entry, priority, videoWalks = true) => {
|
|
33545
|
+
if (entry.priority >= priority) return false;
|
|
33546
|
+
const { walk } = entry;
|
|
33547
|
+
if (walk === void 0) return true;
|
|
33548
|
+
if (entry.priority !== 0 || !videoWalks) return false;
|
|
33549
|
+
return entry.running === null || walk.group !== null && !walk.group.controller.signal.aborted;
|
|
33550
|
+
};
|
|
33551
|
+
const outstandingBelow = (priority, videoWalks = true) => {
|
|
32311
33552
|
for (const entry of entries.values()) {
|
|
32312
|
-
if (entry
|
|
33553
|
+
if (holdsBack(entry, priority, videoWalks)) return true;
|
|
32313
33554
|
}
|
|
32314
33555
|
return false;
|
|
32315
33556
|
};
|
|
33557
|
+
const yieldVideoWalks = (queued) => {
|
|
33558
|
+
const now = performance.now();
|
|
33559
|
+
const rttMs = readRtt();
|
|
33560
|
+
const due = queued.some((entry) => entry.priority !== 0 && entry.walk === void 0 && !outstandingBelow(entry.priority, false) && refusal(entry, now, rttMs) === null);
|
|
33561
|
+
if (!due) return;
|
|
33562
|
+
for (const entry of entries.values()) {
|
|
33563
|
+
const walk = entry.walk;
|
|
33564
|
+
if (entry.priority !== 0 || walk === void 0 || walk.group === null) continue;
|
|
33565
|
+
if (walk.group.controller.signal.aborted) continue;
|
|
33566
|
+
walk.yielded = true;
|
|
33567
|
+
walk.group.controller.abort();
|
|
33568
|
+
}
|
|
33569
|
+
};
|
|
32316
33570
|
const preemptBestEffort = () => {
|
|
32317
33571
|
for (const entry of entries.values()) {
|
|
32318
33572
|
if (entry.priority === 0 || !entry.running) continue;
|
|
@@ -32341,7 +33595,8 @@ function wireRepairFetch(mc, opts) {
|
|
|
32341
33595
|
}
|
|
32342
33596
|
const rttMs = admit(entry, now);
|
|
32343
33597
|
if (rttMs === null) return;
|
|
32344
|
-
if (entry.priority === 0) preemptBestEffort();
|
|
33598
|
+
if (entry.priority === 0 && entry.walk === void 0) preemptBestEffort();
|
|
33599
|
+
if (entry.range === void 0) leaveWalkedGroup(entry);
|
|
32345
33600
|
if (counted) entry.attempts++;
|
|
32346
33601
|
mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
|
|
32347
33602
|
rttMs,
|
|
@@ -32363,6 +33618,14 @@ function wireRepairFetch(mc, opts) {
|
|
|
32363
33618
|
}
|
|
32364
33619
|
void execute(entry, run);
|
|
32365
33620
|
};
|
|
33621
|
+
const leaveWalkedGroup = (block) => {
|
|
33622
|
+
for (const entry of entries.values()) {
|
|
33623
|
+
const group = entry.walk?.group;
|
|
33624
|
+
if (group?.sbn === block.sbn && entry.packetId === block.packetId && entry.catalogTrackName === block.catalogTrackName) {
|
|
33625
|
+
group.controller.abort();
|
|
33626
|
+
}
|
|
33627
|
+
}
|
|
33628
|
+
};
|
|
32366
33629
|
const dispatch = () => {
|
|
32367
33630
|
if (disposed) return;
|
|
32368
33631
|
const now = performance.now();
|
|
@@ -32387,6 +33650,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32387
33650
|
for (const entry of queued) {
|
|
32388
33651
|
if (entry.priority === 0) start(entry);
|
|
32389
33652
|
}
|
|
33653
|
+
yieldVideoWalks(queued);
|
|
32390
33654
|
if (outstandingBelow(1)) return;
|
|
32391
33655
|
for (const entry of queued) {
|
|
32392
33656
|
if (entry.priority === 1) start(entry);
|
|
@@ -32413,6 +33677,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
32413
33677
|
}
|
|
32414
33678
|
return counts.sources + counts.repairGroupLength >= counts.authoredLength;
|
|
32415
33679
|
};
|
|
33680
|
+
const groupServed = (sbn, packetId, catalogTrackName) => {
|
|
33681
|
+
if (mc.fecManager.blockSymbolCounts === void 0) return false;
|
|
33682
|
+
const counts = symbolCounts(sbn, packetId, catalogTrackName);
|
|
33683
|
+
if (counts === void 0 || counts.authoredLength === void 0) return true;
|
|
33684
|
+
return counts.sources + counts.repairs >= counts.authoredLength || !groupCanComplete(sbn, packetId, catalogTrackName);
|
|
33685
|
+
};
|
|
33686
|
+
const statedEnd = (sbn, packetId, catalogTrackName) => {
|
|
33687
|
+
const length = symbolCounts(sbn, packetId, catalogTrackName)?.authoredLength;
|
|
33688
|
+
return length === void 0 ? void 0 : serial32Add(sbn, length);
|
|
33689
|
+
};
|
|
32416
33690
|
const finish = (entry, run, fed, error) => {
|
|
32417
33691
|
if (run.stopped !== null || entry.running !== run || entries.get(entry.key) !== entry) {
|
|
32418
33692
|
return;
|
|
@@ -32457,27 +33731,81 @@ function wireRepairFetch(mc, opts) {
|
|
|
32457
33731
|
signal: run.controller.signal,
|
|
32458
33732
|
subscriberPriority: entry.subscriberPriority
|
|
32459
33733
|
};
|
|
33734
|
+
const { range } = entry;
|
|
33735
|
+
const feed = (packet) => {
|
|
33736
|
+
if (entry.catalogTrackName === void 0) {
|
|
33737
|
+
mc.processRepairFromMoQ(packet, entry.packetId);
|
|
33738
|
+
} else {
|
|
33739
|
+
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
33740
|
+
}
|
|
33741
|
+
};
|
|
32460
33742
|
try {
|
|
32461
|
-
const packets = entry.
|
|
33743
|
+
const packets = range === void 0 ? opts.transport({ ...common, sbn: entry.sbn }) : entry.walk !== void 0 ? walkHole(entry, entry.walk, range, common) : opts.rangeTransport({
|
|
32462
33744
|
...common,
|
|
32463
|
-
startGroup:
|
|
32464
|
-
endGroup:
|
|
32465
|
-
lostSsId:
|
|
32466
|
-
})
|
|
33745
|
+
startGroup: range.groups.startGroup,
|
|
33746
|
+
endGroup: range.groups.endGroup,
|
|
33747
|
+
lostSsId: range.lostSsId
|
|
33748
|
+
});
|
|
32467
33749
|
for await (const packet of packets) {
|
|
32468
33750
|
if (run.stopped !== null || entry.running !== run) break;
|
|
32469
33751
|
fed++;
|
|
32470
|
-
if (
|
|
32471
|
-
|
|
32472
|
-
} else {
|
|
32473
|
-
mc.processRepairFromMoQ(packet, entry.packetId, entry.catalogTrackName);
|
|
32474
|
-
}
|
|
33752
|
+
if (range === void 0) feed(packet);
|
|
33753
|
+
else atReport(range, () => feed(packet));
|
|
32475
33754
|
}
|
|
32476
33755
|
finish(entry, run, fed, void 0);
|
|
32477
33756
|
} catch (error) {
|
|
32478
33757
|
finish(entry, run, fed, error ?? new Error("repair transport rejected"));
|
|
32479
33758
|
}
|
|
32480
33759
|
};
|
|
33760
|
+
async function* walkHole(entry, walk, hole, common) {
|
|
33761
|
+
const lostAt = serial32Distance(entry.sbn, hole.lostSsId);
|
|
33762
|
+
for (let first = true; !common.signal.aborted; first = false) {
|
|
33763
|
+
if (!first && entry.priority !== 0 && outstandingBelow(1)) {
|
|
33764
|
+
stop(entry, "preempted");
|
|
33765
|
+
note("repair-preempted", entry);
|
|
33766
|
+
return;
|
|
33767
|
+
}
|
|
33768
|
+
if (!first && entry.priority === 0) {
|
|
33769
|
+
dispatch();
|
|
33770
|
+
if (common.signal.aborted) return;
|
|
33771
|
+
}
|
|
33772
|
+
const sbn = walk.next;
|
|
33773
|
+
let next;
|
|
33774
|
+
if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
|
|
33775
|
+
const rsIds = /* @__PURE__ */ new Set();
|
|
33776
|
+
const group = new AbortController();
|
|
33777
|
+
const cancel = () => group.abort(common.signal.reason);
|
|
33778
|
+
common.signal.addEventListener("abort", cancel, { once: true });
|
|
33779
|
+
walk.group = { sbn, controller: group };
|
|
33780
|
+
try {
|
|
33781
|
+
for await (const packet of opts.transport({ ...common, sbn, signal: group.signal })) {
|
|
33782
|
+
yield packet;
|
|
33783
|
+
const id = extractRepairFecPayloadId(packet);
|
|
33784
|
+
if (id === null || id.ssStart !== sbn || id.ssbLength === 0) continue;
|
|
33785
|
+
next ??= serial32Add(sbn, id.ssbLength);
|
|
33786
|
+
rsIds.add(id.rsId);
|
|
33787
|
+
if (rsIds.size >= id.rsbLength || groupServed(sbn, entry.packetId, entry.catalogTrackName)) {
|
|
33788
|
+
group.abort();
|
|
33789
|
+
break;
|
|
33790
|
+
}
|
|
33791
|
+
}
|
|
33792
|
+
} catch (error) {
|
|
33793
|
+
if (!group.signal.aborted || common.signal.aborted) throw error;
|
|
33794
|
+
} finally {
|
|
33795
|
+
common.signal.removeEventListener("abort", cancel);
|
|
33796
|
+
walk.group = null;
|
|
33797
|
+
}
|
|
33798
|
+
if (walk.yielded) {
|
|
33799
|
+
walk.yielded = false;
|
|
33800
|
+
continue;
|
|
33801
|
+
}
|
|
33802
|
+
}
|
|
33803
|
+
next ??= statedEnd(sbn, entry.packetId, entry.catalogTrackName);
|
|
33804
|
+
if (next === void 0) return;
|
|
33805
|
+
if (serial32Distance(entry.sbn, next) > lostAt) return;
|
|
33806
|
+
walk.next = next;
|
|
33807
|
+
}
|
|
33808
|
+
}
|
|
32481
33809
|
const removeResetObserver = mc.addTrackResetObserver((packetId, catalogTrackName) => {
|
|
32482
33810
|
for (const entry of [...entries.values()]) {
|
|
32483
33811
|
if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
|
|
@@ -32673,7 +34001,37 @@ function wireRepairFetch(mc, opts) {
|
|
|
32673
34001
|
throw error;
|
|
32674
34002
|
}
|
|
32675
34003
|
};
|
|
32676
|
-
|
|
34004
|
+
const trackKind = (packetId) => {
|
|
34005
|
+
try {
|
|
34006
|
+
return mc.fecManager.trackKindFor?.(packetId);
|
|
34007
|
+
} catch {
|
|
34008
|
+
return void 0;
|
|
34009
|
+
}
|
|
34010
|
+
};
|
|
34011
|
+
const walkDeadlineAt = (packetId, now, deadlineAt) => {
|
|
34012
|
+
let repairDeadlineMs;
|
|
34013
|
+
try {
|
|
34014
|
+
repairDeadlineMs = mc.fecManager.repairDeadlineMsForPacket?.(packetId);
|
|
34015
|
+
} catch {
|
|
34016
|
+
repairDeadlineMs = void 0;
|
|
34017
|
+
}
|
|
34018
|
+
if (repairDeadlineMs === void 0 || !Number.isFinite(repairDeadlineMs)) return deadlineAt;
|
|
34019
|
+
return Math.min(deadlineAt, now + repairDeadlineMs - WALK_LEAD_MS);
|
|
34020
|
+
};
|
|
34021
|
+
const onHoleExpired = (hole) => {
|
|
34022
|
+
if (disposed) return false;
|
|
34023
|
+
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);
|
|
34024
|
+
if (entry === void 0) return false;
|
|
34025
|
+
queueMicrotask(() => {
|
|
34026
|
+
if (entries.get(entry.key) !== entry) return;
|
|
34027
|
+
retire(entry);
|
|
34028
|
+
stop(entry, "expired");
|
|
34029
|
+
clearEntry(entry);
|
|
34030
|
+
dispatch();
|
|
34031
|
+
});
|
|
34032
|
+
return true;
|
|
34033
|
+
};
|
|
34034
|
+
if (mc.onUndelimitedLoss !== void 0 && mc.closeIsoHoles !== void 0) {
|
|
32677
34035
|
mc.onUndelimitedLoss((loss) => {
|
|
32678
34036
|
const { packetId, catalogTrackName, holeStart, holeLength } = loss;
|
|
32679
34037
|
const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
|
|
@@ -32681,9 +34039,11 @@ function wireRepairFetch(mc, opts) {
|
|
|
32681
34039
|
const blockProfile = blockProfileOf(packetId);
|
|
32682
34040
|
const target = opts.resolveTarget(packetId, catalogTrackName);
|
|
32683
34041
|
if (!target) return close();
|
|
32684
|
-
const
|
|
32685
|
-
const
|
|
32686
|
-
|
|
34042
|
+
const walked = opts.rangeTransport === void 0;
|
|
34043
|
+
const holeClass = walked && trackKind(packetId) === "audio" ? "audio" : "unknown";
|
|
34044
|
+
const priority = repairPriorityForClass(holeClass);
|
|
34045
|
+
const groups = walked ? null : rangeFor(loss, target.repairTrack);
|
|
34046
|
+
if (!walked && groups === null) {
|
|
32687
34047
|
close();
|
|
32688
34048
|
mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
|
|
32689
34049
|
return;
|
|
@@ -32694,8 +34054,10 @@ function wireRepairFetch(mc, opts) {
|
|
|
32694
34054
|
packetId,
|
|
32695
34055
|
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
32696
34056
|
};
|
|
32697
|
-
const wire = wirePriority(identity,
|
|
32698
|
-
|
|
34057
|
+
const wire = wirePriority(identity, holeClass);
|
|
34058
|
+
if (wire === null) return close();
|
|
34059
|
+
const now = performance.now();
|
|
34060
|
+
const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, now, holeClass);
|
|
32699
34061
|
if (deadline === null) {
|
|
32700
34062
|
close();
|
|
32701
34063
|
mc.noteRepairSkipped(
|
|
@@ -32707,6 +34069,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32707
34069
|
);
|
|
32708
34070
|
return;
|
|
32709
34071
|
}
|
|
34072
|
+
const deadlineAt = walked ? walkDeadlineAt(packetId, now, deadline.deadlineAt) : deadline.deadlineAt;
|
|
32710
34073
|
const entry = {
|
|
32711
34074
|
key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
|
|
32712
34075
|
...identity,
|
|
@@ -32714,15 +34077,16 @@ function wireRepairFetch(mc, opts) {
|
|
|
32714
34077
|
blockProfile,
|
|
32715
34078
|
priority,
|
|
32716
34079
|
subscriberPriority: wire.subscriberPriority,
|
|
32717
|
-
deadlineAt
|
|
32718
|
-
playoutDeadlineAt:
|
|
34080
|
+
deadlineAt,
|
|
34081
|
+
playoutDeadlineAt: deadlineAt - deadline.extensionMs,
|
|
32719
34082
|
anchorAt: deadline.anchorAt,
|
|
32720
34083
|
delayMs: deadline.delayMs,
|
|
32721
34084
|
bound: deadline.bound,
|
|
32722
34085
|
order: enqueueOrder++,
|
|
32723
34086
|
attempts: 0,
|
|
32724
34087
|
running: null,
|
|
32725
|
-
range: {
|
|
34088
|
+
range: { lostSsId: loss.lostSsId, holeLength, groups, reportedAt: now },
|
|
34089
|
+
...walked ? { walk: { next: holeStart, group: null, yielded: false } } : {}
|
|
32726
34090
|
};
|
|
32727
34091
|
const previous = entries.get(entry.key);
|
|
32728
34092
|
if (previous) {
|
|
@@ -32732,7 +34096,7 @@ function wireRepairFetch(mc, opts) {
|
|
|
32732
34096
|
entries.set(entry.key, entry);
|
|
32733
34097
|
entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
|
|
32734
34098
|
dispatch();
|
|
32735
|
-
});
|
|
34099
|
+
}, onHoleExpired);
|
|
32736
34100
|
}
|
|
32737
34101
|
const removeRapObserver = mc.addRapCompleteObserver?.((packetId) => {
|
|
32738
34102
|
queueMicrotask(() => {
|
|
@@ -32848,6 +34212,7 @@ export {
|
|
|
32848
34212
|
catalogGroupDurationMs,
|
|
32849
34213
|
catalogKeyframeCadenceMs,
|
|
32850
34214
|
catalogRepairTarget,
|
|
34215
|
+
catalogTrackDeliveryMode,
|
|
32851
34216
|
catalogTrackFecUnavailable,
|
|
32852
34217
|
classifyH264Keyframe,
|
|
32853
34218
|
classifyHevcKeyframe,
|
|
@@ -32868,6 +34233,7 @@ export {
|
|
|
32868
34233
|
detectH264Keyframe,
|
|
32869
34234
|
detectHevcKeyframe,
|
|
32870
34235
|
driftCheck,
|
|
34236
|
+
encodeCmcdRecord,
|
|
32871
34237
|
encodeDataSegment,
|
|
32872
34238
|
encodeFecSourceInfo,
|
|
32873
34239
|
encodeLocTimestamp,
|