@blockcast/mmt-container 0.4.0 → 0.4.1-main.cbe342dbdd9c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -20
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +1839 -692
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +121 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +421 -66
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +331 -1171
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +1137 -317
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +159 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +531 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +39 -6
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +184 -27
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +877 -357
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1086 -301
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +2710 -7
- package/dist/source-auth.js.map +4 -4
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +452 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +110 -7
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +533 -0
- package/src/mmtp-router.ts +166 -7
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +267 -21
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +7 -1
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/sample-combiner.ts +15 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
package/dist/fec-manager.js
CHANGED
|
@@ -186,16 +186,6 @@ var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
|
186
186
|
|
|
187
187
|
// src/iso-block-locator.ts
|
|
188
188
|
var IsoBlockLocator = class _IsoBlockLocator {
|
|
189
|
-
/** Known blocks and spans, in serial order of their start. */
|
|
190
|
-
#blocks = [];
|
|
191
|
-
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
192
|
-
#held = /* @__PURE__ */ new Map();
|
|
193
|
-
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
194
|
-
#coverageEnd;
|
|
195
|
-
#kMax;
|
|
196
|
-
#retentionBlocks;
|
|
197
|
-
#heldEvicted = 0;
|
|
198
|
-
#newest;
|
|
199
189
|
/**
|
|
200
190
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
201
191
|
* @param retentionBlocks how many blocks behind the newest position the
|
|
@@ -203,12 +193,35 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
203
193
|
* no locator exists without retention.
|
|
204
194
|
*/
|
|
205
195
|
constructor(kMax, retentionBlocks) {
|
|
196
|
+
/** Known blocks and spans, in serial order of their start. */
|
|
197
|
+
this.#blocks = [];
|
|
198
|
+
/** Held first-arrival sources whose block no repair has stated yet. */
|
|
199
|
+
this.#held = /* @__PURE__ */ new Map();
|
|
200
|
+
this.#heldEvicted = 0;
|
|
201
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
202
|
+
this.#holes = [];
|
|
203
|
+
/**
|
|
204
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
205
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
206
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
207
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
208
|
+
*/
|
|
209
|
+
this.deferIncompleteGaps = false;
|
|
206
210
|
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
207
211
|
throw new Error(`[IsoBlockLocator] maximum K must be a positive integer (got ${kMax})`);
|
|
208
212
|
}
|
|
209
213
|
this.#kMax = kMax;
|
|
210
214
|
this.#retentionBlocks = _IsoBlockLocator.#checkedRetention(retentionBlocks);
|
|
211
215
|
}
|
|
216
|
+
#blocks;
|
|
217
|
+
#held;
|
|
218
|
+
/** End of contiguous coverage: the SS_ID the next unknown block starts at. */
|
|
219
|
+
#coverageEnd;
|
|
220
|
+
#kMax;
|
|
221
|
+
#retentionBlocks;
|
|
222
|
+
#heldEvicted;
|
|
223
|
+
#newest;
|
|
224
|
+
#holes;
|
|
212
225
|
static #checkedRetention(retentionBlocks) {
|
|
213
226
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
214
227
|
throw new Error(
|
|
@@ -271,6 +284,14 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
271
284
|
}
|
|
272
285
|
return null;
|
|
273
286
|
}
|
|
287
|
+
/** Number of pending holes. */
|
|
288
|
+
get holeCount() {
|
|
289
|
+
return this.#holes.length;
|
|
290
|
+
}
|
|
291
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
292
|
+
blockEndingAt(end) {
|
|
293
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end);
|
|
294
|
+
}
|
|
274
295
|
/** The known block or span starting exactly at `start`. */
|
|
275
296
|
blockAt(start) {
|
|
276
297
|
return this.#blocks.find((block) => block.start === start);
|
|
@@ -293,6 +314,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
293
314
|
coversBetween(a, b) {
|
|
294
315
|
if (this.#coverageEnd === void 0) return false;
|
|
295
316
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true;
|
|
317
|
+
const first = a + 1 >>> 0;
|
|
318
|
+
const count = serial32Distance(a, b) - 1;
|
|
319
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false;
|
|
296
320
|
return serial32Precedes(b - 1 >>> 0, this.#coverageEnd);
|
|
297
321
|
}
|
|
298
322
|
/**
|
|
@@ -322,6 +346,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
322
346
|
* known block (a different length, or an overlap with another block or a
|
|
323
347
|
* span) fails closed: the repair symbol is dropped and no block changes.
|
|
324
348
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
349
|
+
* A block so far past `newest` that stating it would retire the position
|
|
350
|
+
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
351
|
+
* this is slightly conservative (retirement measures that block from its
|
|
352
|
+
* last SS_ID), dropping up to one block-length of repairs past the horizon
|
|
353
|
+
* until a source moves `newest`. Placing it would turn everything
|
|
354
|
+
* between into a repair-less span and leave every real repair behind it
|
|
355
|
+
* `stale`. Sources move `newest` (`hold`, `observe`), so after a real outage
|
|
356
|
+
* the first source back brings the next repair inside the horizon; until one
|
|
357
|
+
* arrives, a stream's repairs alone cannot pass it.
|
|
325
358
|
*/
|
|
326
359
|
placeRepair(start, length) {
|
|
327
360
|
if (!Number.isSafeInteger(length) || length <= 0 || length > this.#kMax) {
|
|
@@ -340,6 +373,22 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
340
373
|
}
|
|
341
374
|
return { status: "placed", block: known, placed: [] };
|
|
342
375
|
}
|
|
376
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start));
|
|
377
|
+
if (pending !== void 0) {
|
|
378
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
379
|
+
return { status: "overlap", reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` };
|
|
380
|
+
}
|
|
381
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1);
|
|
382
|
+
const before = serial32Distance(pending.start, start);
|
|
383
|
+
const afterStart = isoBlockEnd(start, length);
|
|
384
|
+
const after = pending.length - before - length;
|
|
385
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false });
|
|
386
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false });
|
|
387
|
+
const block2 = { start, length, span: false };
|
|
388
|
+
const placed2 = this.#claim(block2);
|
|
389
|
+
this.#blocks.push(block2);
|
|
390
|
+
return { status: "placed", block: block2, placed: placed2 };
|
|
391
|
+
}
|
|
343
392
|
for (const block2 of this.#blocks) {
|
|
344
393
|
if (isoBlockContains(block2.start, block2.length, start) || isoBlockContains(start, length, block2.start)) {
|
|
345
394
|
return {
|
|
@@ -348,7 +397,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
348
397
|
};
|
|
349
398
|
}
|
|
350
399
|
}
|
|
400
|
+
if (this.#newest !== void 0 && isoBlocksBehindLowerBound(this.#newest, start, this.#kMax) > this.#retentionBlocks) {
|
|
401
|
+
return { status: "ahead", reason: `repair block ${start}+${length} is past the retention horizon ahead of ${this.#newest}` };
|
|
402
|
+
}
|
|
351
403
|
let span;
|
|
404
|
+
let hole;
|
|
352
405
|
if (this.#coverageEnd === void 0) {
|
|
353
406
|
for (const ssId of this.#held.keys()) {
|
|
354
407
|
if (serial32Precedes(ssId, start)) this.#held.delete(ssId);
|
|
@@ -357,21 +410,51 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
357
410
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
358
411
|
return { status: "stale", reason: `repair block ${start}+${length} precedes known coverage` };
|
|
359
412
|
} else if (start !== this.#coverageEnd) {
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
span:
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
413
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) };
|
|
414
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : void 0;
|
|
415
|
+
if (lostSsId !== void 0) {
|
|
416
|
+
const holeBlock = { ...gap, span: false };
|
|
417
|
+
this.#holes.push(holeBlock);
|
|
418
|
+
hole = { block: holeBlock, lostSsId };
|
|
419
|
+
} else {
|
|
420
|
+
const spanBlock = { ...gap, span: true };
|
|
421
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) };
|
|
422
|
+
this.#blocks.push(spanBlock);
|
|
423
|
+
}
|
|
367
424
|
}
|
|
368
425
|
const block = { start, length, span: false };
|
|
369
426
|
const placed = this.#claim(block);
|
|
370
427
|
this.#blocks.push(block);
|
|
371
428
|
this.#coverageEnd = isoBlockEnd(start, length);
|
|
372
429
|
this.retireBehind(start);
|
|
430
|
+
if (hole !== void 0) return { status: "placed", block, placed, hole };
|
|
373
431
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
374
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
435
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
436
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
437
|
+
*/
|
|
438
|
+
closeHolesWithin(start, length) {
|
|
439
|
+
const closed = [];
|
|
440
|
+
for (const hole of [...this.#holes]) {
|
|
441
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
442
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1);
|
|
443
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
444
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
445
|
+
this.#blocks.push(spanBlock);
|
|
446
|
+
}
|
|
447
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
448
|
+
}
|
|
449
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
450
|
+
#highestMissing(start, length) {
|
|
451
|
+
const steps = Math.min(length, this.#held.size + 1);
|
|
452
|
+
for (let i = 1; i <= steps; i++) {
|
|
453
|
+
const ssId = serial32Add(start, length - i);
|
|
454
|
+
if (!this.#held.has(ssId)) return ssId;
|
|
455
|
+
}
|
|
456
|
+
return void 0;
|
|
457
|
+
}
|
|
375
458
|
/**
|
|
376
459
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
377
460
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -390,6 +473,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
390
473
|
this.#blocks.splice(i, 1);
|
|
391
474
|
}
|
|
392
475
|
}
|
|
476
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
477
|
+
const hole = this.#holes[i];
|
|
478
|
+
const last = serial32Add(hole.start, hole.length - 1);
|
|
479
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1);
|
|
480
|
+
}
|
|
393
481
|
for (const ssId of [...this.#held.keys()]) {
|
|
394
482
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId);
|
|
395
483
|
}
|
|
@@ -398,6 +486,7 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
398
486
|
/** Forget everything (publisher restart, track reset). */
|
|
399
487
|
reset() {
|
|
400
488
|
this.#blocks.length = 0;
|
|
489
|
+
this.#holes.length = 0;
|
|
401
490
|
this.#held.clear();
|
|
402
491
|
this.#coverageEnd = void 0;
|
|
403
492
|
this.#newest = void 0;
|
|
@@ -413,6 +502,9 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
413
502
|
return placed;
|
|
414
503
|
}
|
|
415
504
|
};
|
|
505
|
+
function isoRangesOverlap(aStart, aLength, bStart, bLength) {
|
|
506
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength;
|
|
507
|
+
}
|
|
416
508
|
|
|
417
509
|
// src/fec-state.ts
|
|
418
510
|
var MIN_INTERLEAVE_DEPTH_MS = 1;
|
|
@@ -763,6 +855,7 @@ var BlockClassifier = class {
|
|
|
763
855
|
};
|
|
764
856
|
|
|
765
857
|
// src/fec-manager.ts
|
|
858
|
+
var RS_MAX_BLOCK_SYMBOLS = 255;
|
|
766
859
|
var WORKER_ERROR_LOG_CAP = 5;
|
|
767
860
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
768
861
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
@@ -877,6 +970,11 @@ var FECManager = class _FECManager {
|
|
|
877
970
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
878
971
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
879
972
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
973
|
+
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
974
|
+
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
975
|
+
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
976
|
+
this.#fecFailClosed = /* @__PURE__ */ new Map();
|
|
977
|
+
this.#onFecFailClosed = null;
|
|
880
978
|
// Blocks already recovered — prevents late source symbols from restarting timeouts.
|
|
881
979
|
// WASM removes blocks after recovery; late symbols create empty blocks returning null,
|
|
882
980
|
// which would falsely start new timeouts without this guard.
|
|
@@ -997,12 +1095,17 @@ var FECManager = class _FECManager {
|
|
|
997
1095
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
998
1096
|
// arithmetic and never throws at all.
|
|
999
1097
|
this.#orderedHorizonWarnedFor = /* @__PURE__ */ new Set();
|
|
1000
|
-
// Newest block start (SS_Start)
|
|
1001
|
-
//
|
|
1098
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
1099
|
+
// frontier isoSpanResolution reads.
|
|
1002
1100
|
this.#highestSbn = /* @__PURE__ */ new Map();
|
|
1101
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
1102
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
1103
|
+
// blocks ahead of the media they protect.
|
|
1104
|
+
this.#sourceFrontiers = /* @__PURE__ */ new Map();
|
|
1003
1105
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
1004
1106
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
1005
1107
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
1108
|
+
this.#deferIsoGaps = false;
|
|
1006
1109
|
this.#isoRepairRefusedCount = 0;
|
|
1007
1110
|
this.#isoSourceOversizeCount = 0;
|
|
1008
1111
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -1017,8 +1120,8 @@ var FECManager = class _FECManager {
|
|
|
1017
1120
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
1018
1121
|
this.#isoDecoderUnplacedRetireFailed = 0;
|
|
1019
1122
|
// The latest source symbol per stream that carried its MMTP
|
|
1020
|
-
// packet_sequence_number: the anchor that bounds how
|
|
1021
|
-
// producer can have
|
|
1123
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
1124
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
1022
1125
|
this.#sourceAnchors = /* @__PURE__ */ new Map();
|
|
1023
1126
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
1024
1127
|
this.#packetEpochs = /* @__PURE__ */ new Map();
|
|
@@ -1077,6 +1180,14 @@ var FECManager = class _FECManager {
|
|
|
1077
1180
|
this.onBlockReclassified = null;
|
|
1078
1181
|
/** A video stream's classifier mode was established or changed. */
|
|
1079
1182
|
this.onClassifierMode = null;
|
|
1183
|
+
/**
|
|
1184
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
1185
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
1186
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
1187
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
1188
|
+
* for it, which it must be.
|
|
1189
|
+
*/
|
|
1190
|
+
this.#onUndelimitedLoss = null;
|
|
1080
1191
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
1081
1192
|
this.onBlockVanished = null;
|
|
1082
1193
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
@@ -1118,6 +1229,9 @@ var FECManager = class _FECManager {
|
|
|
1118
1229
|
#ssbLengthConflictCount;
|
|
1119
1230
|
#blockRepairRsIds;
|
|
1120
1231
|
#blockRsbLengths;
|
|
1232
|
+
#heldLayerStates;
|
|
1233
|
+
#fecFailClosed;
|
|
1234
|
+
#onFecFailClosed;
|
|
1121
1235
|
#completedBlocks;
|
|
1122
1236
|
#terminalExpiryMs;
|
|
1123
1237
|
#terminalQueues;
|
|
@@ -1156,7 +1270,9 @@ var FECManager = class _FECManager {
|
|
|
1156
1270
|
#materializedBlocks;
|
|
1157
1271
|
#orderedHorizonWarnedFor;
|
|
1158
1272
|
#highestSbn;
|
|
1273
|
+
#sourceFrontiers;
|
|
1159
1274
|
#isoLocators;
|
|
1275
|
+
#deferIsoGaps;
|
|
1160
1276
|
#isoRepairRefusedCount;
|
|
1161
1277
|
#isoSourceOversizeCount;
|
|
1162
1278
|
#isoHeldEvictedCount;
|
|
@@ -1170,6 +1286,7 @@ var FECManager = class _FECManager {
|
|
|
1170
1286
|
#workerErrorCounts;
|
|
1171
1287
|
#decoderUnavailableEvents;
|
|
1172
1288
|
#repairSymbolSizeMismatchCount;
|
|
1289
|
+
#onUndelimitedLoss;
|
|
1173
1290
|
#encodeTrackName(catalogTrackName) {
|
|
1174
1291
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
1175
1292
|
if (encoded === void 0) {
|
|
@@ -1746,8 +1863,8 @@ var FECManager = class _FECManager {
|
|
|
1746
1863
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
1747
1864
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
1748
1865
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
1749
|
-
// many blocks a stream can
|
|
1750
|
-
//
|
|
1866
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
1867
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
1751
1868
|
// The extra block of retention is slack for a block still being fed; a block
|
|
1752
1869
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
1753
1870
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -1757,55 +1874,72 @@ var FECManager = class _FECManager {
|
|
|
1757
1874
|
}
|
|
1758
1875
|
/**
|
|
1759
1876
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
1760
|
-
* advance the stream's
|
|
1877
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
1761
1878
|
*
|
|
1762
|
-
* A SOURCE symbol
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1879
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
1880
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
1881
|
+
* block goes back further than the blocks this manager retains, or that
|
|
1882
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
1883
|
+
* further than the stream could have produced since its last symbol, is a
|
|
1884
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
1765
1885
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
1766
1886
|
* signals a discontinuity.
|
|
1767
1887
|
*
|
|
1768
1888
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
1769
1889
|
* source symbols filled it, so one interleave span can start several blocks
|
|
1770
|
-
* (every large keyframe does). What bounds a
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1774
|
-
* packet_sequence_number
|
|
1775
|
-
*
|
|
1776
|
-
*
|
|
1890
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
1891
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
1892
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
1893
|
+
* packet of the packet_id, so with both source symbols'
|
|
1894
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
1895
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
1896
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
1897
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
1898
|
+
* known.
|
|
1777
1899
|
*
|
|
1778
1900
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
1779
1901
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
1780
1902
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
1781
1903
|
*/
|
|
1782
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber) {
|
|
1904
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
1783
1905
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
1784
1906
|
const now = performance.now();
|
|
1785
|
-
const previous = this.#highestSbn.get(streamKey);
|
|
1907
|
+
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
1786
1908
|
const anchor = this.#sourceAnchors.get(streamKey);
|
|
1787
1909
|
const psn = symbol === "source" && packetSequenceNumber !== void 0 && Number.isSafeInteger(packetSequenceNumber) && packetSequenceNumber >= 0 && packetSequenceNumber <= 4294967295 ? packetSequenceNumber : void 0;
|
|
1788
1910
|
const anchorHere = () => {
|
|
1789
|
-
if (psn !== void 0 && (anchor === void 0 || !
|
|
1790
|
-
this.#sourceAnchors.set(streamKey, {
|
|
1911
|
+
if (psn !== void 0 && (anchor === void 0 || !serial32Precedes(ssId, anchor.ssId))) {
|
|
1912
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
const advance = () => {
|
|
1916
|
+
const highest = this.#highestSbn.get(streamKey);
|
|
1917
|
+
if (highest === void 0 || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
1918
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
1791
1919
|
}
|
|
1920
|
+
if (symbol === "source") this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
1921
|
+
anchorHere();
|
|
1792
1922
|
};
|
|
1793
1923
|
const discontinuity = () => {
|
|
1794
1924
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
1795
1925
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
1926
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
1796
1927
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
1797
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
1928
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
|
|
1798
1929
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName);
|
|
1799
1930
|
};
|
|
1800
1931
|
if (previous === void 0) {
|
|
1801
|
-
|
|
1802
|
-
anchorHere();
|
|
1932
|
+
advance();
|
|
1803
1933
|
return;
|
|
1804
1934
|
}
|
|
1805
1935
|
const config = this.#trackConfig(packetId);
|
|
1806
1936
|
const window = this.#liveWindowBlocks(config);
|
|
1937
|
+
const sentInOrder = (from, to) => {
|
|
1938
|
+
const sent = to.psn - from.psn >>> 0;
|
|
1939
|
+
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
1940
|
+
};
|
|
1807
1941
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
1808
|
-
if (symbol === "source" && window !== null && this.#blocksBehind(sbn, previous.sbn, packetId) >
|
|
1942
|
+
if (symbol === "source" && window !== 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))) {
|
|
1809
1943
|
discontinuity();
|
|
1810
1944
|
return;
|
|
1811
1945
|
}
|
|
@@ -1815,9 +1949,8 @@ var FECManager = class _FECManager {
|
|
|
1815
1949
|
const missing = this.#blocksBehind(previous.sbn, sbn, packetId) - 1;
|
|
1816
1950
|
let plausible = true;
|
|
1817
1951
|
if (window !== null) {
|
|
1818
|
-
if (psn !== void 0 && anchor !== void 0 &&
|
|
1819
|
-
|
|
1820
|
-
plausible = sent <= 2147483647 && serial32Distance(anchor.sbn, sbn) <= sent + config.k;
|
|
1952
|
+
if (psn !== void 0 && anchor !== void 0 && serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
1953
|
+
plausible = sentInOrder(anchor, { ssId, psn });
|
|
1821
1954
|
} else {
|
|
1822
1955
|
plausible = missing <= window + Math.ceil((now - previous.atMs) / config.interleaveDepthMs);
|
|
1823
1956
|
}
|
|
@@ -1827,8 +1960,7 @@ var FECManager = class _FECManager {
|
|
|
1827
1960
|
discontinuity();
|
|
1828
1961
|
return;
|
|
1829
1962
|
}
|
|
1830
|
-
|
|
1831
|
-
anchorHere();
|
|
1963
|
+
advance();
|
|
1832
1964
|
}
|
|
1833
1965
|
/*
|
|
1834
1966
|
* Block order for one stream (BLO-35597 iso:5). A block is keyed by its
|
|
@@ -2145,8 +2277,10 @@ var FECManager = class _FECManager {
|
|
|
2145
2277
|
);
|
|
2146
2278
|
}
|
|
2147
2279
|
const hasCatalogTiming = _FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs });
|
|
2280
|
+
const algorithm = config.algorithm ?? previous.algorithm;
|
|
2148
2281
|
const next = {
|
|
2149
2282
|
blockProfile,
|
|
2283
|
+
...algorithm === void 0 ? {} : { algorithm },
|
|
2150
2284
|
k,
|
|
2151
2285
|
symbolSize: config.symbolSize != null && config.symbolSize > 0 ? config.symbolSize : previousTrack?.symbolSize ?? 0,
|
|
2152
2286
|
interleaveDepthMs: ownInterleaveDepthMs,
|
|
@@ -2154,8 +2288,19 @@ var FECManager = class _FECManager {
|
|
|
2154
2288
|
timeoutMs: config.timeoutMs ?? (timingChanged ? 0 : previous.timeoutMs ?? 0),
|
|
2155
2289
|
...(config.trackKind ?? previous.trackKind) === void 0 ? {} : { trackKind: config.trackKind ?? previous.trackKind },
|
|
2156
2290
|
...(config.codec ?? previous.codec) === void 0 ? {} : { codec: config.codec ?? previous.codec },
|
|
2157
|
-
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry }
|
|
2291
|
+
...(config.geometry ?? previous.geometry) === void 0 ? {} : { geometry: config.geometry ?? previous.geometry },
|
|
2292
|
+
...(config.repairLayers ?? previous.repairLayers) === void 0 ? {} : { repairLayers: config.repairLayers ?? previous.repairLayers },
|
|
2293
|
+
...(config.heldLayers ?? previous.heldLayers) === void 0 ? {} : { heldLayers: config.heldLayers ?? previous.heldLayers }
|
|
2158
2294
|
};
|
|
2295
|
+
if (
|
|
2296
|
+
// By content: a catalog refresh rebuilds equal arrays, and forgetting
|
|
2297
|
+
// the anchors on one would fail open.
|
|
2298
|
+
JSON.stringify(next.repairLayers) !== JSON.stringify(previous.repairLayers) || JSON.stringify(next.heldLayers) !== JSON.stringify(previous.heldLayers)
|
|
2299
|
+
) {
|
|
2300
|
+
for (const key of [...this.#heldLayerStates.keys()]) {
|
|
2301
|
+
if (this.#belongsToPacket(key, packetId)) this.#heldLayerStates.delete(key);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2159
2304
|
if (!hasCatalogTiming) {
|
|
2160
2305
|
next.timeoutMs = config.timeoutMs !== void 0 && config.timeoutMs > 0 ? config.timeoutMs : previousTrack !== void 0 && previousTrack.interleaveDepthMs === 0 ? previousTrack.timeoutMs : LOCAL_FEC_TIMEOUT_MS;
|
|
2161
2306
|
} else {
|
|
@@ -2390,6 +2535,8 @@ var FECManager = class _FECManager {
|
|
|
2390
2535
|
resetMap(this.#blockAuthoredLengths);
|
|
2391
2536
|
resetMap(this.#blockRepairRsIds);
|
|
2392
2537
|
resetMap(this.#blockRsbLengths);
|
|
2538
|
+
resetMap(this.#heldLayerStates);
|
|
2539
|
+
resetMap(this.#fecFailClosed);
|
|
2393
2540
|
resetMap(this.#blockPathCounts);
|
|
2394
2541
|
resetMap(this.#blockAnchorsMs);
|
|
2395
2542
|
resetMap(this.#blockCatalogTrackNames);
|
|
@@ -2412,6 +2559,7 @@ var FECManager = class _FECManager {
|
|
|
2412
2559
|
resetSet(this.#materializedBlocks);
|
|
2413
2560
|
resetMap(this.#resolvedBlockClasses);
|
|
2414
2561
|
resetMap(this.#highestSbn);
|
|
2562
|
+
resetMap(this.#sourceFrontiers);
|
|
2415
2563
|
resetMap(this.#isoLocators);
|
|
2416
2564
|
resetMap(this.#sourceAnchors);
|
|
2417
2565
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -2517,6 +2665,7 @@ var FECManager = class _FECManager {
|
|
|
2517
2665
|
dropMap(this.#orderedPendingBlocks);
|
|
2518
2666
|
dropMap(this.#resolvedBlockClasses);
|
|
2519
2667
|
dropMap(this.#highestSbn);
|
|
2668
|
+
dropMap(this.#sourceFrontiers);
|
|
2520
2669
|
dropMap(this.#isoLocators);
|
|
2521
2670
|
dropMap(this.#sourceAnchors);
|
|
2522
2671
|
dropMap(this.#classifiers);
|
|
@@ -2609,7 +2758,13 @@ var FECManager = class _FECManager {
|
|
|
2609
2758
|
if (isSourceSymbol && esi === 0) {
|
|
2610
2759
|
this.#startupPartialBlocks.delete(blockKey);
|
|
2611
2760
|
this.#startupAlignedPackets.add(streamKey);
|
|
2612
|
-
} else if (
|
|
2761
|
+
} else if (
|
|
2762
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
2763
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
2764
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
2765
|
+
// per join (BLO-48308).
|
|
2766
|
+
isStartupPartial || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair
|
|
2767
|
+
) {
|
|
2613
2768
|
this.#markStartupPartial(blockKey);
|
|
2614
2769
|
return false;
|
|
2615
2770
|
}
|
|
@@ -2891,6 +3046,7 @@ var FECManager = class _FECManager {
|
|
|
2891
3046
|
let locator = this.#isoLocators.get(streamKey);
|
|
2892
3047
|
if (!locator) {
|
|
2893
3048
|
locator = new IsoBlockLocator(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId));
|
|
3049
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
2894
3050
|
this.#isoLocators.set(streamKey, locator);
|
|
2895
3051
|
}
|
|
2896
3052
|
return locator;
|
|
@@ -2934,6 +3090,10 @@ var FECManager = class _FECManager {
|
|
|
2934
3090
|
}
|
|
2935
3091
|
return blocks;
|
|
2936
3092
|
}
|
|
3093
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
3094
|
+
isoRetentionBlocksForPacket(packetId) {
|
|
3095
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : void 0;
|
|
3096
|
+
}
|
|
2937
3097
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
2938
3098
|
isoSourceFits(packetId, packetLength) {
|
|
2939
3099
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize;
|
|
@@ -2983,15 +3143,61 @@ var FECManager = class _FECManager {
|
|
|
2983
3143
|
}
|
|
2984
3144
|
return placement;
|
|
2985
3145
|
}
|
|
2986
|
-
if (placement.span !== void 0)
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
3146
|
+
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
3147
|
+
if (placement.hole !== void 0) {
|
|
3148
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
3149
|
+
const hole = placement.hole.block;
|
|
3150
|
+
const previous = locator.blockEndingAt(hole.start);
|
|
3151
|
+
const loss = {
|
|
3152
|
+
packetId,
|
|
3153
|
+
catalogTrackName,
|
|
3154
|
+
holeStart: hole.start,
|
|
3155
|
+
holeLength: hole.length,
|
|
3156
|
+
lostSsId: placement.hole.lostSsId,
|
|
3157
|
+
kMax: this.#trackConfig(packetId).k,
|
|
3158
|
+
...previous === void 0 ? {} : { previousBlockStart: previous.start }
|
|
3159
|
+
};
|
|
3160
|
+
this.#onUndelimitedLoss(loss);
|
|
2992
3161
|
}
|
|
2993
3162
|
return placement;
|
|
2994
3163
|
}
|
|
3164
|
+
/**
|
|
3165
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
3166
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
3167
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
3168
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
3169
|
+
* nobody to close it.
|
|
3170
|
+
*/
|
|
3171
|
+
setUndelimitedLossHandler(handler) {
|
|
3172
|
+
this.#onUndelimitedLoss = handler;
|
|
3173
|
+
this.#deferIsoGaps = handler !== null;
|
|
3174
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
3175
|
+
}
|
|
3176
|
+
/**
|
|
3177
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
3178
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
3179
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
3180
|
+
*/
|
|
3181
|
+
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
3182
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
3183
|
+
if (locator === void 0) return [];
|
|
3184
|
+
const spans = locator.closeHolesWithin(start, length);
|
|
3185
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName);
|
|
3186
|
+
return spans;
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
3190
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
3191
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
3192
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
3193
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
3194
|
+
* block.
|
|
3195
|
+
*/
|
|
3196
|
+
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
3197
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
3198
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length);
|
|
3199
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
3200
|
+
}
|
|
2995
3201
|
/**
|
|
2996
3202
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
2997
3203
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -3508,6 +3714,154 @@ var FECManager = class _FECManager {
|
|
|
3508
3714
|
}
|
|
3509
3715
|
return recovered;
|
|
3510
3716
|
}
|
|
3717
|
+
/**
|
|
3718
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
3719
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
3720
|
+
* block state unchanged. The router calls this before the repair places a
|
|
3721
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
3722
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
3723
|
+
*/
|
|
3724
|
+
admitRepairBlockLength(packetId, ssbLength, rsbLength, rsId) {
|
|
3725
|
+
if (rsId >= rsbLength) return false;
|
|
3726
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== "reed-solomon") return true;
|
|
3727
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS;
|
|
3728
|
+
}
|
|
3729
|
+
/**
|
|
3730
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
3731
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
3732
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
3733
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
3734
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
3735
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
3736
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
3737
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
3738
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
3739
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
3740
|
+
*/
|
|
3741
|
+
admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, byteLength) {
|
|
3742
|
+
if (!this.#hasBlockProfile(packetId)) return false;
|
|
3743
|
+
const symbolSize = this.#trackConfig(packetId).symbolSize;
|
|
3744
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
3745
|
+
this.#repairSymbolSizeMismatchCount++;
|
|
3746
|
+
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
3747
|
+
console.warn(
|
|
3748
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
3749
|
+
);
|
|
3750
|
+
}
|
|
3751
|
+
return false;
|
|
3752
|
+
}
|
|
3753
|
+
return true;
|
|
3754
|
+
}
|
|
3755
|
+
/**
|
|
3756
|
+
* fec-01 6.3.9 receiver check, run on a repair packet after the 4.5 discard
|
|
3757
|
+
* and the size check, before it places a block. For each held layer i with
|
|
3758
|
+
* total B_i = O_i + P_i: the anchor is the earliest block, in SS_Start
|
|
3759
|
+
* serial order, whose repair carried RSB_length >= B_i. The source track
|
|
3760
|
+
* fails closed on (a) a packet on layer i's own repair track (i > 0) below
|
|
3761
|
+
* B_i, or (b) any packet of the instance at or after the anchor below B_i.
|
|
3762
|
+
* Blocks before the anchor (pre-append) stay valid at the previous total. A
|
|
3763
|
+
* packet on a repair track the catalog does not list is discarded and
|
|
3764
|
+
* anchors nothing. `repairTrackName` is the subscribed repair track, never
|
|
3765
|
+
* inferred from RS_ID; without it only (b) runs. Returns false when the
|
|
3766
|
+
* repair must be dropped, including every repair once the track failed.
|
|
3767
|
+
*/
|
|
3768
|
+
admitRepairLayerTotal(packetId, catalogTrackName, repairTrackName, ssStart, rsbLength) {
|
|
3769
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
3770
|
+
if (this.#fecFailClosed.has(streamKey)) return false;
|
|
3771
|
+
const config = this.#trackConfigs.get(packetId);
|
|
3772
|
+
const layers = config?.repairLayers;
|
|
3773
|
+
if (layers === void 0 || layers.length === 0) return true;
|
|
3774
|
+
if (repairTrackName !== void 0 && !layers.some((l) => l.repairTrackName === repairTrackName)) {
|
|
3775
|
+
return false;
|
|
3776
|
+
}
|
|
3777
|
+
let states = this.#heldLayerStates.get(streamKey);
|
|
3778
|
+
if (states === void 0) {
|
|
3779
|
+
const held = new Set(config.heldLayers ?? [0]);
|
|
3780
|
+
states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
|
|
3781
|
+
this.#heldLayerStates.set(streamKey, states);
|
|
3782
|
+
}
|
|
3783
|
+
const horizon = this.#layerAnchorHorizon(packetId);
|
|
3784
|
+
const frontier = this.#sourceFrontiers.get(streamKey)?.sbn;
|
|
3785
|
+
const farAhead = frontier !== void 0 && serial32Precedes(frontier, ssStart) && serial32Distance(frontier, ssStart) > horizon;
|
|
3786
|
+
for (const state of states) {
|
|
3787
|
+
let code;
|
|
3788
|
+
if (farAhead) {
|
|
3789
|
+
if (rsbLength < state.total) {
|
|
3790
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
3791
|
+
else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
|
|
3792
|
+
}
|
|
3793
|
+
} else {
|
|
3794
|
+
if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
|
|
3795
|
+
const stale = (s) => serial32Distance(s, state.newest) > horizon;
|
|
3796
|
+
if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
|
|
3797
|
+
delete state.latestBelow;
|
|
3798
|
+
delete state.latestBelowRsb;
|
|
3799
|
+
}
|
|
3800
|
+
if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
|
|
3801
|
+
if (rsbLength < state.total) {
|
|
3802
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
|
|
3803
|
+
else if (stale(ssStart)) continue;
|
|
3804
|
+
else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
|
|
3805
|
+
else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
|
|
3806
|
+
state.latestBelow = ssStart;
|
|
3807
|
+
state.latestBelowRsb = rsbLength;
|
|
3808
|
+
}
|
|
3809
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
3810
|
+
if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
|
|
3811
|
+
if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
3812
|
+
code = "below_anchored_total";
|
|
3813
|
+
ssStart = state.latestBelow;
|
|
3814
|
+
rsbLength = state.latestBelowRsb;
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
if (code !== void 0) {
|
|
3819
|
+
const reason = {
|
|
3820
|
+
code,
|
|
3821
|
+
layer: state.layer,
|
|
3822
|
+
total: state.total,
|
|
3823
|
+
rsbLength,
|
|
3824
|
+
ssStart,
|
|
3825
|
+
...state.anchor === void 0 ? {} : { anchor: state.anchor }
|
|
3826
|
+
};
|
|
3827
|
+
this.#fecFailClosed.set(streamKey, reason);
|
|
3828
|
+
this.#onFecFailClosed?.({ ...reason, packetId, catalogTrackName });
|
|
3829
|
+
console.warn(
|
|
3830
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? "-"}: ${JSON.stringify(reason)}`
|
|
3831
|
+
);
|
|
3832
|
+
return false;
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
return true;
|
|
3836
|
+
}
|
|
3837
|
+
/**
|
|
3838
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
3839
|
+
* below-total block can still matter: the iso locator's retention in blocks
|
|
3840
|
+
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
3841
|
+
*/
|
|
3842
|
+
#layerAnchorHorizon(packetId) {
|
|
3843
|
+
const cap = 1073741824;
|
|
3844
|
+
let blocks;
|
|
3845
|
+
try {
|
|
3846
|
+
blocks = this.isoRetentionBlocksForPacket(packetId);
|
|
3847
|
+
} catch {
|
|
3848
|
+
blocks = void 0;
|
|
3849
|
+
}
|
|
3850
|
+
const k = this.#trackConfigs.get(packetId)?.k ?? 0;
|
|
3851
|
+
return blocks === void 0 || k <= 0 ? cap : Math.min(cap, blocks * k);
|
|
3852
|
+
}
|
|
3853
|
+
/**
|
|
3854
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), once,
|
|
3855
|
+
* when it does; null stops reporting. The player wiring forwards it to
|
|
3856
|
+
* CmcdProducer.updateFecFailClosed.
|
|
3857
|
+
*/
|
|
3858
|
+
setFecFailClosedHandler(handler) {
|
|
3859
|
+
this.#onFecFailClosed = handler;
|
|
3860
|
+
}
|
|
3861
|
+
/** The runtime fail-closed reason of a stream's FEC (fec-01 6.3.9), if any. */
|
|
3862
|
+
fecFailClosedReason(packetId, catalogTrackName) {
|
|
3863
|
+
return this.#fecFailClosed.get(this.#streamKey(packetId, catalogTrackName));
|
|
3864
|
+
}
|
|
3511
3865
|
/**
|
|
3512
3866
|
* Feed a repair symbol to the WASM FEC decoder.
|
|
3513
3867
|
*
|
|
@@ -3519,16 +3873,7 @@ var FECManager = class _FECManager {
|
|
|
3519
3873
|
this.#fecStats.repairPackets++;
|
|
3520
3874
|
this.#statsForPacket(packetId).repairPackets++;
|
|
3521
3875
|
if (!this.#hasBlockProfile(packetId)) return null;
|
|
3522
|
-
|
|
3523
|
-
if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
|
|
3524
|
-
this.#repairSymbolSizeMismatchCount++;
|
|
3525
|
-
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
3526
|
-
console.warn(
|
|
3527
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
|
|
3528
|
-
);
|
|
3529
|
-
}
|
|
3530
|
-
return null;
|
|
3531
|
-
}
|
|
3876
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null;
|
|
3532
3877
|
const fecData = repairData;
|
|
3533
3878
|
const k = this.#trackConfig(packetId).k;
|
|
3534
3879
|
const block = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(ssStart);
|
|
@@ -3681,7 +4026,14 @@ var FECManager = class _FECManager {
|
|
|
3681
4026
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
3682
4027
|
const k = trackConfig.k;
|
|
3683
4028
|
if (this.#completedBlocks.has(key)) return;
|
|
3684
|
-
this.#noteSbnSeen(
|
|
4029
|
+
this.#noteSbnSeen(
|
|
4030
|
+
sbn,
|
|
4031
|
+
packetId,
|
|
4032
|
+
catalogTrackName,
|
|
4033
|
+
"source",
|
|
4034
|
+
evidence.packetSequenceNumber,
|
|
4035
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
4036
|
+
);
|
|
3685
4037
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
3686
4038
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
3687
4039
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -3908,6 +4260,8 @@ var FECManager = class _FECManager {
|
|
|
3908
4260
|
this.#blockAuthoredLengths.clear();
|
|
3909
4261
|
this.#blockRepairRsIds.clear();
|
|
3910
4262
|
this.#blockRsbLengths.clear();
|
|
4263
|
+
this.#heldLayerStates.clear();
|
|
4264
|
+
this.#fecFailClosed.clear();
|
|
3911
4265
|
this.#completedBlocks.clear();
|
|
3912
4266
|
this.#cleanlyCompletedBlocks.clear();
|
|
3913
4267
|
this.#repairRequestedBlocks.clear();
|
|
@@ -3932,6 +4286,7 @@ var FECManager = class _FECManager {
|
|
|
3932
4286
|
this.#repairedBlocks.clear();
|
|
3933
4287
|
this.#materializedBlocks.clear();
|
|
3934
4288
|
this.#highestSbn.clear();
|
|
4289
|
+
this.#sourceFrontiers.clear();
|
|
3935
4290
|
this.#isoLocators.clear();
|
|
3936
4291
|
this.#sourceAnchors.clear();
|
|
3937
4292
|
this.#trackConfigs.clear();
|