@blockcast/mmt-container 0.4.0 → 0.4.1-main.30f0611c24e8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -20
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +1904 -692
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +108 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +452 -66
- package/dist/fec-manager.js.map +4 -4
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/held-layer-admission.d.ts +58 -0
- package/dist/held-layer-admission.d.ts.map +1 -0
- package/dist/held-layer-admission.js +105 -0
- package/dist/held-layer-admission.js.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +331 -1171
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +1250 -317
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +192 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +640 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +39 -6
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +184 -27
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +908 -357
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1195 -301
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +2710 -7
- package/dist/source-auth.js.map +4 -4
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +366 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/held-layer-admission.ts +161 -0
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +110 -7
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +606 -0
- package/src/mmtp-router.ts +166 -7
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +267 -21
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +7 -1
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/sample-combiner.ts +15 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
// ../mmt-base/dist/mmtp.js
|
|
2
|
+
var MMTP_HEADER_SIZE = 12;
|
|
3
|
+
var MPU_HEADER_SIZE = 8;
|
|
4
|
+
var MPU_LENGTH_FIELD_SIZE = 2;
|
|
5
|
+
var MPU_HEADER_REMAINDER_SIZE = MPU_HEADER_SIZE - MPU_LENGTH_FIELD_SIZE;
|
|
6
|
+
var PACKET_TYPE_REPAIR = 3;
|
|
7
|
+
function parseMMTPHeader(buffer) {
|
|
8
|
+
if (buffer.length < MMTP_HEADER_SIZE) {
|
|
9
|
+
throw new Error(`MMTP packet too small: ${buffer.length} bytes`);
|
|
10
|
+
}
|
|
11
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
12
|
+
const version = buffer[0] >> 6 & 3;
|
|
13
|
+
if (version !== 0) {
|
|
14
|
+
throw new Error(`Unsupported MMTP version: ${version}`);
|
|
15
|
+
}
|
|
16
|
+
const fecType = buffer[0] >> 3 & 3;
|
|
17
|
+
const packetCounterFlag = (buffer[0] & 32) !== 0;
|
|
18
|
+
const extensionFlag = (buffer[0] & 2) !== 0;
|
|
19
|
+
const rapFlag = (buffer[0] & 1) === 1;
|
|
20
|
+
const packetType = buffer[1] & 63;
|
|
21
|
+
let offset = 2;
|
|
22
|
+
const packetId = view.getUint16(offset, false);
|
|
23
|
+
offset += 2;
|
|
24
|
+
const timestamp = BigInt(view.getUint32(offset, false));
|
|
25
|
+
offset += 4;
|
|
26
|
+
const sequenceNumber = view.getUint32(offset, false);
|
|
27
|
+
offset += 4;
|
|
28
|
+
let packetCounter;
|
|
29
|
+
if (packetCounterFlag) {
|
|
30
|
+
if (offset + 4 > buffer.length)
|
|
31
|
+
throw new Error("MMTP packet truncated in packet_counter");
|
|
32
|
+
packetCounter = view.getUint32(offset, false);
|
|
33
|
+
offset += 4;
|
|
34
|
+
}
|
|
35
|
+
let extension;
|
|
36
|
+
if (extensionFlag) {
|
|
37
|
+
if (offset + 4 > buffer.length)
|
|
38
|
+
throw new Error("MMTP packet truncated in header extension");
|
|
39
|
+
const type = view.getUint16(offset, false);
|
|
40
|
+
const length = view.getUint16(offset + 2, false);
|
|
41
|
+
offset += 4;
|
|
42
|
+
if (offset + length > buffer.length)
|
|
43
|
+
throw new Error("MMTP packet truncated in header extension value");
|
|
44
|
+
extension = { type, data: buffer.subarray(offset, offset + length) };
|
|
45
|
+
offset += length;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
version,
|
|
49
|
+
packetType,
|
|
50
|
+
packetId,
|
|
51
|
+
timestamp,
|
|
52
|
+
sequenceNumber,
|
|
53
|
+
payloadLength: buffer.length - offset,
|
|
54
|
+
fecType,
|
|
55
|
+
packetCounterFlag,
|
|
56
|
+
packetCounter,
|
|
57
|
+
extensionFlag,
|
|
58
|
+
extension,
|
|
59
|
+
headerLength: offset,
|
|
60
|
+
rapFlag
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
64
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
65
|
+
let header;
|
|
66
|
+
if (parsedHeader) {
|
|
67
|
+
header = parsedHeader;
|
|
68
|
+
} else {
|
|
69
|
+
try {
|
|
70
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
76
|
+
return null;
|
|
77
|
+
const off = header.headerLength;
|
|
78
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
79
|
+
return null;
|
|
80
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
81
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
82
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
83
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
84
|
+
return {
|
|
85
|
+
packetId: header.packetId,
|
|
86
|
+
ssStart,
|
|
87
|
+
rsbLength,
|
|
88
|
+
rsId,
|
|
89
|
+
ssbLength,
|
|
90
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function parseMoqRepairFrameWithHeader(frame, header) {
|
|
94
|
+
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
|
|
95
|
+
}
|
|
96
|
+
function moqRepairFrameFrom(frame, repairId) {
|
|
97
|
+
if (!repairId)
|
|
98
|
+
return null;
|
|
99
|
+
const symbolData = frame.subarray(repairId.dataOffset);
|
|
100
|
+
if (repairId.rsbLength === 0 || repairId.ssbLength === 0 || repairId.rsId >= repairId.rsbLength || symbolData.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
packetId: repairId.packetId,
|
|
104
|
+
ssStart: repairId.ssStart,
|
|
105
|
+
rsbLength: repairId.rsbLength,
|
|
106
|
+
rsId: repairId.rsId,
|
|
107
|
+
ssbLength: repairId.ssbLength,
|
|
108
|
+
symbolData
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ../mmt-base/dist/ntp-short.js
|
|
113
|
+
var NTP_SHORT_BITS = 32;
|
|
114
|
+
var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
|
|
115
|
+
var NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
|
|
116
|
+
|
|
117
|
+
// ../mmt-base/dist/serial-number.js
|
|
118
|
+
var SERIAL32_SPAN = 4294967296;
|
|
119
|
+
var SERIAL32_HALF = 2147483648;
|
|
120
|
+
function assertUint32(value, name) {
|
|
121
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
122
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function serial32Add(s, n) {
|
|
126
|
+
assertUint32(s, "s");
|
|
127
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
128
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
129
|
+
}
|
|
130
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
131
|
+
}
|
|
132
|
+
function serial32Distance(from, to) {
|
|
133
|
+
return to - from >>> 0;
|
|
134
|
+
}
|
|
135
|
+
function serial32Precedes(a, b) {
|
|
136
|
+
const distance = serial32Distance(a, b);
|
|
137
|
+
return distance !== 0 && distance < SERIAL32_HALF;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ../mmt-base/dist/fec-block-profile.js
|
|
141
|
+
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
142
|
+
"iso-ssbg1-v1"
|
|
143
|
+
]);
|
|
144
|
+
function isFecBlockProfile(value) {
|
|
145
|
+
return value === "iso-ssbg1-v1";
|
|
146
|
+
}
|
|
147
|
+
function parseFecBlockProfile(value, where) {
|
|
148
|
+
if (isFecBlockProfile(value))
|
|
149
|
+
return value;
|
|
150
|
+
if (value === void 0) {
|
|
151
|
+
throw new Error(`${where} is required: name the FEC block profile ("iso-ssbg1-v1")`);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
|
|
154
|
+
}
|
|
155
|
+
var SSBG1_LENGTH_FIELD_BYTES = 2;
|
|
156
|
+
function ssbg1MaxPacketLength(symbolSize) {
|
|
157
|
+
return symbolSize - SSBG1_LENGTH_FIELD_BYTES;
|
|
158
|
+
}
|
|
159
|
+
function ssbg1FitsSymbol(packetLength, symbolSize) {
|
|
160
|
+
return Number.isSafeInteger(packetLength) && packetLength >= 0 && packetLength <= ssbg1MaxPacketLength(symbolSize) && packetLength <= 65535;
|
|
161
|
+
}
|
|
162
|
+
function trimSsbg1SourceSymbol(symbol) {
|
|
163
|
+
if (symbol.byteLength < SSBG1_LENGTH_FIELD_BYTES)
|
|
164
|
+
return null;
|
|
165
|
+
const length = symbol[0] << 8 | symbol[1];
|
|
166
|
+
const end = SSBG1_LENGTH_FIELD_BYTES + length;
|
|
167
|
+
if (end > symbol.byteLength)
|
|
168
|
+
return null;
|
|
169
|
+
for (let i = end; i < symbol.byteLength; i++) {
|
|
170
|
+
if (symbol[i] !== 0)
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return symbol.subarray(SSBG1_LENGTH_FIELD_BYTES, end);
|
|
174
|
+
}
|
|
175
|
+
function isoBlockContains(ssStart, ssbLength, ssId) {
|
|
176
|
+
return serial32Distance(ssStart, ssId) < ssbLength;
|
|
177
|
+
}
|
|
178
|
+
function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
179
|
+
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
180
|
+
throw new Error(`iso-ssbg1-v1 block horizon needs a positive maximum K (got ${kMax})`);
|
|
181
|
+
}
|
|
182
|
+
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ../mmt-base/dist/catalog-fec-source.js
|
|
186
|
+
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
187
|
+
|
|
188
|
+
// src/mmtp-fec-session.ts
|
|
189
|
+
import { deriveFecRetentionBlocks, fecBlockBudgetMs } from "@blockcast/mmt-fec";
|
|
190
|
+
|
|
191
|
+
// src/held-layer-admission.ts
|
|
192
|
+
var HORIZON_CAP = 1073741824;
|
|
193
|
+
function heldLayerAnchorHorizon(retentionBlocks, k) {
|
|
194
|
+
return retentionBlocks === void 0 || k <= 0 ? HORIZON_CAP : Math.min(HORIZON_CAP, retentionBlocks * k);
|
|
195
|
+
}
|
|
196
|
+
var HeldLayerAdmission = class {
|
|
197
|
+
#layerNames;
|
|
198
|
+
#states;
|
|
199
|
+
constructor(layers, heldLayers = [0]) {
|
|
200
|
+
const held = new Set(heldLayers);
|
|
201
|
+
this.#layerNames = new Set(layers.map((l) => l.repairTrackName));
|
|
202
|
+
this.#states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Judges one repair packet, after the 4.5 discards and the size check and
|
|
206
|
+
* before it places a block. `repairTrackName` is the subscribed repair
|
|
207
|
+
* track, never inferred from RS_ID; without it only (b) runs. A packet on a
|
|
208
|
+
* repair track the catalog does not list is `'discard'` and anchors nothing.
|
|
209
|
+
* `sourceFrontier` is the newest source SS_ID, if any: a repair more than
|
|
210
|
+
* `horizon` past it is judged without moving the anchored state.
|
|
211
|
+
*
|
|
212
|
+
* @returns undefined to admit, `'discard'`, or the fail-closed reason.
|
|
213
|
+
*/
|
|
214
|
+
admit(repairTrackName, ssStart, rsbLength, horizon, sourceFrontier) {
|
|
215
|
+
if (repairTrackName !== void 0 && !this.#layerNames.has(repairTrackName)) return "discard";
|
|
216
|
+
const farAhead = sourceFrontier !== void 0 && serial32Precedes(sourceFrontier, ssStart) && serial32Distance(sourceFrontier, ssStart) > horizon;
|
|
217
|
+
for (const state of this.#states) {
|
|
218
|
+
let code;
|
|
219
|
+
if (farAhead) {
|
|
220
|
+
if (rsbLength < state.total) {
|
|
221
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
222
|
+
else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
|
|
226
|
+
const stale = (s) => serial32Distance(s, state.newest) > horizon;
|
|
227
|
+
if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
|
|
228
|
+
delete state.latestBelow;
|
|
229
|
+
delete state.latestBelowRsb;
|
|
230
|
+
}
|
|
231
|
+
if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
|
|
232
|
+
if (rsbLength < state.total) {
|
|
233
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
234
|
+
else if (stale(ssStart)) continue;
|
|
235
|
+
else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
|
|
236
|
+
else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
|
|
237
|
+
state.latestBelow = ssStart;
|
|
238
|
+
state.latestBelowRsb = rsbLength;
|
|
239
|
+
}
|
|
240
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
241
|
+
if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
|
|
242
|
+
if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
243
|
+
code = "below_anchored_total";
|
|
244
|
+
ssStart = state.latestBelow;
|
|
245
|
+
rsbLength = state.latestBelowRsb;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (code !== void 0) {
|
|
250
|
+
return {
|
|
251
|
+
code,
|
|
252
|
+
layer: state.layer,
|
|
253
|
+
total: state.total,
|
|
254
|
+
rsbLength,
|
|
255
|
+
ssStart,
|
|
256
|
+
...state.anchor === void 0 ? {} : { anchor: state.anchor }
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/mmtp-fec-session.ts
|
|
265
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
266
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
267
|
+
var MmtpFecSession = class {
|
|
268
|
+
#decoder;
|
|
269
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
270
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
271
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
272
|
+
#settled = /* @__PURE__ */ new Set();
|
|
273
|
+
/**
|
|
274
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
275
|
+
* received on, or 0 for one the session recovered.
|
|
276
|
+
*/
|
|
277
|
+
#have = /* @__PURE__ */ new Map();
|
|
278
|
+
#newest;
|
|
279
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
280
|
+
#prunedAt;
|
|
281
|
+
#repairPacketId;
|
|
282
|
+
#newestSource;
|
|
283
|
+
#heldLayers;
|
|
284
|
+
#anchorHorizon;
|
|
285
|
+
#stats = {
|
|
286
|
+
sourceSymbols: 0,
|
|
287
|
+
repairSymbols: 0,
|
|
288
|
+
blocksClean: 0,
|
|
289
|
+
blocksRecovered: 0,
|
|
290
|
+
blocksFailed: 0,
|
|
291
|
+
blocksReleased: 0,
|
|
292
|
+
packetsRecovered: 0,
|
|
293
|
+
packetsLost: 0,
|
|
294
|
+
dropped: {},
|
|
295
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
296
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
297
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 },
|
|
298
|
+
failClosed: null
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
302
|
+
* needs: the block profile, K, P_0 (`repairSymbols`), T, `interleaveDepthMs` or
|
|
303
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
304
|
+
*/
|
|
305
|
+
constructor(config) {
|
|
306
|
+
const fec = config?.fec;
|
|
307
|
+
if (!fec || typeof fec !== "object") {
|
|
308
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
309
|
+
}
|
|
310
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
311
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
312
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
313
|
+
}
|
|
314
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
315
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
316
|
+
this.repairSymbols = requirePositiveInteger(fec.repairSymbols, "fec.repairSymbols");
|
|
317
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
318
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
319
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
320
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
321
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
322
|
+
interleaveDepthMs
|
|
323
|
+
);
|
|
324
|
+
this.#heldLayers = new HeldLayerAdmission(
|
|
325
|
+
config.repairLayers ?? [
|
|
326
|
+
{
|
|
327
|
+
layer: 0,
|
|
328
|
+
repairTrackName: typeof fec.repairTrack === "string" ? fec.repairTrack : "",
|
|
329
|
+
rsIdOffset: 0,
|
|
330
|
+
repairSymbols: this.repairSymbols
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
config.heldLayers
|
|
334
|
+
);
|
|
335
|
+
this.#anchorHorizon = heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols);
|
|
336
|
+
if (typeof config.Decoder !== "function") {
|
|
337
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
338
|
+
}
|
|
339
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
340
|
+
try {
|
|
341
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
decoder.free();
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
this.#decoder = decoder;
|
|
347
|
+
}
|
|
348
|
+
/** True once release() ran. */
|
|
349
|
+
get released() {
|
|
350
|
+
return this.#decoder === null;
|
|
351
|
+
}
|
|
352
|
+
get stats() {
|
|
353
|
+
return {
|
|
354
|
+
...this.#stats,
|
|
355
|
+
dropped: { ...this.#stats.dropped },
|
|
356
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
357
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
358
|
+
mixedPath: { ...this.#stats.mixedPath },
|
|
359
|
+
failClosed: this.#stats.failClosed && { ...this.#stats.failClosed }
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
364
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
365
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
366
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
367
|
+
*
|
|
368
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
369
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
370
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
371
|
+
*/
|
|
372
|
+
addSource(ssId, packet, path = "moq") {
|
|
373
|
+
const decoder = this.#decoder;
|
|
374
|
+
if (!decoder) return this.#drop("source:released");
|
|
375
|
+
const pathBit = PATH_BITS[path];
|
|
376
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
377
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
378
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
379
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
380
|
+
this.#have.set(ssId, pathBit);
|
|
381
|
+
this.#stats.sourceSymbols++;
|
|
382
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
383
|
+
this.#noteNewest(ssId);
|
|
384
|
+
if (this.#newestSource === void 0 || serial32Precedes(this.#newestSource, ssId)) this.#newestSource = ssId;
|
|
385
|
+
const start = this.#blockStartOf(ssId);
|
|
386
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
387
|
+
if (block) {
|
|
388
|
+
block.received++;
|
|
389
|
+
block.paths |= pathBit;
|
|
390
|
+
}
|
|
391
|
+
let output;
|
|
392
|
+
try {
|
|
393
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
394
|
+
} catch {
|
|
395
|
+
this.#drop("source:decoder-refused");
|
|
396
|
+
output = void 0;
|
|
397
|
+
}
|
|
398
|
+
const recovered = [];
|
|
399
|
+
if (start !== void 0 && block) {
|
|
400
|
+
if (output) {
|
|
401
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
402
|
+
} else if (block.received >= block.ssbLength) {
|
|
403
|
+
this.#settleClean(start);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
this.#retireBehindHorizon();
|
|
407
|
+
return recovered;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
411
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
412
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
413
|
+
* `path` is where it was received, as for addSource(). `repairTrackName`
|
|
414
|
+
* is the repair track it was received on, for the 6.3.9 own-track rule; a
|
|
415
|
+
* track the layers do not list is refused as `repair:unlisted-track`.
|
|
416
|
+
*
|
|
417
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
418
|
+
* addSource().
|
|
419
|
+
*/
|
|
420
|
+
addRepair(packet, path = "moq", repairTrackName) {
|
|
421
|
+
const decoder = this.#decoder;
|
|
422
|
+
if (!decoder) return this.#drop("repair:released");
|
|
423
|
+
if (this.#stats.failClosed) return this.#drop("repair:fail-closed");
|
|
424
|
+
const pathBit = PATH_BITS[path];
|
|
425
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
426
|
+
let header;
|
|
427
|
+
try {
|
|
428
|
+
header = parseMMTPHeader(packet);
|
|
429
|
+
} catch {
|
|
430
|
+
return this.#drop("repair:malformed");
|
|
431
|
+
}
|
|
432
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
433
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
434
|
+
if (this.#repairPacketId === void 0) {
|
|
435
|
+
this.#repairPacketId = frame.packetId;
|
|
436
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
437
|
+
return this.#drop("repair:foreign-packet-id");
|
|
438
|
+
}
|
|
439
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
440
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
441
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
442
|
+
return this.#drop("repair:rs-block-length");
|
|
443
|
+
}
|
|
444
|
+
const verdict = this.#heldLayers.admit(
|
|
445
|
+
repairTrackName,
|
|
446
|
+
frame.ssStart,
|
|
447
|
+
frame.rsbLength,
|
|
448
|
+
this.#anchorHorizon,
|
|
449
|
+
this.#newestSource
|
|
450
|
+
);
|
|
451
|
+
if (verdict === "discard") return this.#drop("repair:unlisted-track");
|
|
452
|
+
if (verdict !== void 0) {
|
|
453
|
+
this.#stats.failClosed = verdict;
|
|
454
|
+
return this.#drop("repair:fail-closed");
|
|
455
|
+
}
|
|
456
|
+
const start = frame.ssStart;
|
|
457
|
+
let block = this.#blocks.get(start);
|
|
458
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
459
|
+
if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
|
|
460
|
+
if (!block) {
|
|
461
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
462
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
463
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
464
|
+
this.#countHeld(start, block);
|
|
465
|
+
this.#blocks.set(start, block);
|
|
466
|
+
}
|
|
467
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
468
|
+
if (block.received >= block.ssbLength) {
|
|
469
|
+
this.#settleClean(start);
|
|
470
|
+
this.#retireBehindHorizon();
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
let output;
|
|
474
|
+
try {
|
|
475
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
476
|
+
} catch {
|
|
477
|
+
return this.#drop("repair:decoder-refused");
|
|
478
|
+
}
|
|
479
|
+
block.rsIds.add(frame.rsId);
|
|
480
|
+
this.#stats.repairSymbols++;
|
|
481
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
482
|
+
block.paths |= pathBit;
|
|
483
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
484
|
+
this.#retireBehindHorizon();
|
|
485
|
+
return recovered;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
489
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
490
|
+
* returns whether this call released anything.
|
|
491
|
+
*/
|
|
492
|
+
release() {
|
|
493
|
+
const decoder = this.#decoder;
|
|
494
|
+
if (!decoder) return false;
|
|
495
|
+
this.#decoder = null;
|
|
496
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
497
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
498
|
+
this.#blocks.clear();
|
|
499
|
+
this.#settled.clear();
|
|
500
|
+
this.#have.clear();
|
|
501
|
+
decoder.free();
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
#drop(reason) {
|
|
505
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
506
|
+
return [];
|
|
507
|
+
}
|
|
508
|
+
#noteNewest(ssId) {
|
|
509
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
510
|
+
}
|
|
511
|
+
#blockStartOf(ssId) {
|
|
512
|
+
for (const [start, block] of this.#blocks) {
|
|
513
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
514
|
+
}
|
|
515
|
+
return void 0;
|
|
516
|
+
}
|
|
517
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
518
|
+
#countHeld(start, block) {
|
|
519
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
520
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
521
|
+
if (pathBit === void 0) continue;
|
|
522
|
+
block.received++;
|
|
523
|
+
block.paths |= pathBit;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
#noteMixed(block, outcome) {
|
|
527
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
528
|
+
}
|
|
529
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
530
|
+
#behindHorizon(start) {
|
|
531
|
+
const newest = this.#newest;
|
|
532
|
+
if (newest === void 0) return false;
|
|
533
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
534
|
+
}
|
|
535
|
+
#settle(start) {
|
|
536
|
+
this.#blocks.delete(start);
|
|
537
|
+
this.#settled.add(start);
|
|
538
|
+
}
|
|
539
|
+
#settleClean(start) {
|
|
540
|
+
const block = this.#blocks.get(start);
|
|
541
|
+
if (!block) return;
|
|
542
|
+
this.#settle(start);
|
|
543
|
+
this.#stats.blocksClean++;
|
|
544
|
+
this.#noteMixed(block, "clean");
|
|
545
|
+
try {
|
|
546
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
552
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
553
|
+
* back the packets the parser does not have yet.
|
|
554
|
+
*/
|
|
555
|
+
#settleDecoded(start, block, output) {
|
|
556
|
+
this.#settle(start);
|
|
557
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
558
|
+
this.#stats.blocksFailed++;
|
|
559
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
560
|
+
this.#noteMixed(block, "failed");
|
|
561
|
+
this.#drop("block:decoded-length");
|
|
562
|
+
return [];
|
|
563
|
+
}
|
|
564
|
+
const recovered = [];
|
|
565
|
+
let refused = 0;
|
|
566
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
567
|
+
const ssId = serial32Add(start, i);
|
|
568
|
+
if (this.#have.has(ssId)) continue;
|
|
569
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
570
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
571
|
+
if (!packet) {
|
|
572
|
+
refused++;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
this.#have.set(ssId, 0);
|
|
576
|
+
recovered.push(packet.slice());
|
|
577
|
+
}
|
|
578
|
+
if (refused > 0) {
|
|
579
|
+
this.#stats.blocksFailed++;
|
|
580
|
+
this.#stats.packetsLost += refused;
|
|
581
|
+
this.#noteMixed(block, "failed");
|
|
582
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
583
|
+
} else if (recovered.length === 0) {
|
|
584
|
+
this.#stats.blocksClean++;
|
|
585
|
+
this.#noteMixed(block, "clean");
|
|
586
|
+
} else {
|
|
587
|
+
this.#stats.blocksRecovered++;
|
|
588
|
+
this.#noteMixed(block, "recovered");
|
|
589
|
+
}
|
|
590
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
591
|
+
return recovered;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
595
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
596
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
597
|
+
* restore, or its repair never arrived.
|
|
598
|
+
*/
|
|
599
|
+
#retireBehindHorizon() {
|
|
600
|
+
const decoder = this.#decoder;
|
|
601
|
+
const newest = this.#newest;
|
|
602
|
+
if (!decoder || newest === void 0) return;
|
|
603
|
+
try {
|
|
604
|
+
decoder.cleanup_by_ss_start(newest);
|
|
605
|
+
} catch {
|
|
606
|
+
}
|
|
607
|
+
for (const [start, block] of this.#blocks) {
|
|
608
|
+
if (!this.#behindHorizon(start)) continue;
|
|
609
|
+
this.#settle(start);
|
|
610
|
+
this.#stats.blocksFailed++;
|
|
611
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
612
|
+
this.#noteMixed(block, "failed");
|
|
613
|
+
}
|
|
614
|
+
const prunedAt = this.#prunedAt;
|
|
615
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
616
|
+
this.#prunedAt = newest;
|
|
617
|
+
for (const ssId of this.#have.keys()) {
|
|
618
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
619
|
+
}
|
|
620
|
+
for (const start of this.#settled) {
|
|
621
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
function requirePositiveInteger(value, path) {
|
|
626
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
627
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
628
|
+
}
|
|
629
|
+
return value;
|
|
630
|
+
}
|
|
631
|
+
function requireNumber(value, path) {
|
|
632
|
+
if (typeof value !== "number") {
|
|
633
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
634
|
+
}
|
|
635
|
+
return value;
|
|
636
|
+
}
|
|
637
|
+
export {
|
|
638
|
+
MmtpFecSession
|
|
639
|
+
};
|
|
640
|
+
//# sourceMappingURL=mmtp-fec-session.js.map
|