@blockcast/mmt-container 2.2.0-main.c4fa878f4ff4 → 2.2.0-main.caa271d80062
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 +34 -19
- package/dist/block-policy.d.ts +88 -16
- package/dist/block-policy.d.ts.map +1 -1
- package/dist/block-policy.js +164 -56
- package/dist/block-policy.js.map +3 -3
- package/dist/browser-runtime.js +2064 -388
- package/dist/browser-runtime.js.map +3 -3
- package/dist/carp-catalog.js.map +2 -2
- package/dist/catalog-fec-params.d.ts +18 -2
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +29 -1
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmcd-producer.d.ts +60 -47
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +138 -109
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js +5 -1
- package/dist/delta-fallback-config.js.map +3 -3
- package/dist/fec-manager.d.ts +163 -20
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +863 -110
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.js +5 -1
- package/dist/fec-state.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/held-layer-admission.js.map +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +64 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +125 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts +109 -12
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +312 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +333 -32
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +311 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.js.map +2 -2
- package/dist/mmtp-router.d.ts +51 -12
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +723 -83
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.js.map +2 -2
- package/dist/multicast-input.js.map +2 -2
- package/dist/multicast-manager.d.ts +31 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1698 -231
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +28 -18
- package/dist/multicast-transport.js.map +2 -2
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +1 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +333 -31
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.d.ts +6 -2
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +6 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/signaling.js.map +2 -2
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +311 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/schemas/catalog.schema.json +4 -0
- package/src/block-policy.ts +324 -83
- package/src/catalog-fec-params.ts +37 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +818 -42
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +11 -2
- package/src/iso-block-locator.ts +167 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +355 -32
- package/src/mmtp-router.ts +665 -50
- package/src/multicast-manager.ts +145 -16
- package/src/no-modules.ts +3 -0
- package/src/repair-fetch.ts +366 -50
- package/src/repair-layer-subscriptions.ts +13 -5
- package/src/track-session.ts +4 -1
|
@@ -954,13 +954,17 @@ function fecCatalogTracks(catalog) {
|
|
|
954
954
|
});
|
|
955
955
|
return { tracks, pointers };
|
|
956
956
|
}
|
|
957
|
-
function
|
|
957
|
+
function runtimeView(catalog, receiver) {
|
|
958
958
|
const { tracks, pointers } = fecCatalogTracks(catalog);
|
|
959
959
|
const report = validateFecCatalog({ tracks }, receiver);
|
|
960
960
|
const at = (path) => {
|
|
961
961
|
const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
|
|
962
962
|
return m ? pointers[Number(m[1])] + m[2] : path;
|
|
963
963
|
};
|
|
964
|
+
return { tracks, pointers, report, at };
|
|
965
|
+
}
|
|
966
|
+
function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
|
|
967
|
+
const { tracks, pointers, report, at } = runtimeView(catalog, receiver);
|
|
964
968
|
const trackAt = (i) => recordOf(tracks[i]) ?? {};
|
|
965
969
|
const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
|
|
966
970
|
const why = (i) => Object.freeze({
|
|
@@ -1189,6 +1193,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1189
1193
|
this.#heldEvicted = 0;
|
|
1190
1194
|
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
1191
1195
|
this.#holes = [];
|
|
1196
|
+
/** Holes the horizon passed while pending: sources held until closed. */
|
|
1197
|
+
this.#expired = [];
|
|
1198
|
+
/** Of `#expired`, those `takeExpiredHoles` has not handed out yet. */
|
|
1199
|
+
this.#newlyExpired = [];
|
|
1200
|
+
/**
|
|
1201
|
+
* Spans closed from expired holes: behind the horizon, so kept only for
|
|
1202
|
+
* `locate` while their sources are fed, until the next retirement.
|
|
1203
|
+
*/
|
|
1204
|
+
this.#closedBehind = [];
|
|
1192
1205
|
/**
|
|
1193
1206
|
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
1194
1207
|
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
@@ -1210,7 +1223,11 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1210
1223
|
#retentionBlocks;
|
|
1211
1224
|
#heldEvicted;
|
|
1212
1225
|
#newest;
|
|
1226
|
+
#newestSource;
|
|
1213
1227
|
#holes;
|
|
1228
|
+
#expired;
|
|
1229
|
+
#newlyExpired;
|
|
1230
|
+
#closedBehind;
|
|
1214
1231
|
static #checkedRetention(retentionBlocks) {
|
|
1215
1232
|
if (!Number.isSafeInteger(retentionBlocks) || retentionBlocks <= 0) {
|
|
1216
1233
|
throw new Error(
|
|
@@ -1247,6 +1264,21 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1247
1264
|
observe(position) {
|
|
1248
1265
|
if (this.#newest === void 0 || serial32Precedes(this.#newest, position)) this.#newest = position;
|
|
1249
1266
|
}
|
|
1267
|
+
/**
|
|
1268
|
+
* The newest source SS_ID noted with `noteSource` (RFC 1982 order). Unlike
|
|
1269
|
+
* `newest`, a repair never moves it: a repair can run ahead of its sources,
|
|
1270
|
+
* a source cannot run ahead of the sources sent before it except by
|
|
1271
|
+
* reordering.
|
|
1272
|
+
*/
|
|
1273
|
+
get newestSource() {
|
|
1274
|
+
return this.#newestSource;
|
|
1275
|
+
}
|
|
1276
|
+
/** Note a received source's SS_ID; true when it is the newest one yet. */
|
|
1277
|
+
noteSource(ssId) {
|
|
1278
|
+
if (this.#newestSource !== void 0 && !serial32Precedes(this.#newestSource, ssId)) return false;
|
|
1279
|
+
this.#newestSource = ssId;
|
|
1280
|
+
return true;
|
|
1281
|
+
}
|
|
1250
1282
|
/** Held sources evicted by `heldCapacity` (never by the horizon itself). */
|
|
1251
1283
|
get heldEvicted() {
|
|
1252
1284
|
return this.#heldEvicted;
|
|
@@ -1265,17 +1297,29 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1265
1297
|
}
|
|
1266
1298
|
/** The known block or span containing `ssId`, with its ESI. */
|
|
1267
1299
|
locate(ssId) {
|
|
1268
|
-
for (
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1300
|
+
for (const blocks of [this.#blocks, this.#closedBehind]) {
|
|
1301
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
1302
|
+
const block = blocks[i];
|
|
1303
|
+
if (isoBlockContains(block.start, block.length, ssId)) {
|
|
1304
|
+
return { block, esi: serial32Distance(block.start, ssId) };
|
|
1305
|
+
}
|
|
1272
1306
|
}
|
|
1273
1307
|
}
|
|
1274
1308
|
return null;
|
|
1275
1309
|
}
|
|
1276
|
-
/** Number of pending
|
|
1310
|
+
/** Number of holes not closed yet, pending or past the horizon. */
|
|
1277
1311
|
get holeCount() {
|
|
1278
|
-
return this.#holes.length;
|
|
1312
|
+
return this.#holes.length + this.#expired.length;
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* The pending holes the horizon has passed since the last call, in the
|
|
1316
|
+
* order it passed them. Each is no longer pending: no repair states a block
|
|
1317
|
+
* in it (that repair is `stale`, as for a span the horizon retired) and the
|
|
1318
|
+
* release gate does not wait for it. Its owner must close it
|
|
1319
|
+
* (`closeHolesWithin`), which turns it into a span that is not kept here.
|
|
1320
|
+
*/
|
|
1321
|
+
takeExpiredHoles() {
|
|
1322
|
+
return this.#newlyExpired.splice(0);
|
|
1279
1323
|
}
|
|
1280
1324
|
/** The stated block (never a span) ending exactly at `end`. */
|
|
1281
1325
|
blockEndingAt(end) {
|
|
@@ -1328,12 +1372,42 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1328
1372
|
isHeld(ssId) {
|
|
1329
1373
|
return this.#held.has(ssId);
|
|
1330
1374
|
}
|
|
1375
|
+
/** The payload held unplaced for `ssId`, if any. */
|
|
1376
|
+
heldSource(ssId) {
|
|
1377
|
+
return this.#held.get(ssId);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* The SS_IDs strictly between `a` and `b` that no repair has delimited a
|
|
1381
|
+
* block of yet: those from the coverage end on, or all of them before the
|
|
1382
|
+
* first repair. `missing` is the highest of them no source is held for;
|
|
1383
|
+
* absent, every one of them arrived (C.5.2: SS_IDs are consecutive). Null
|
|
1384
|
+
* when none lies past coverage. `flagged` is whether a source held among
|
|
1385
|
+
* them satisfies `flag` (a RAP fragment, say): the held packets read as
|
|
1386
|
+
* fec-multicast-00 Block Classification item 1 reads bounding packets.
|
|
1387
|
+
*/
|
|
1388
|
+
undelimitedBetween(a, b, flag) {
|
|
1389
|
+
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return null;
|
|
1390
|
+
const first = a + 1 >>> 0;
|
|
1391
|
+
const end = this.#coverageEnd;
|
|
1392
|
+
const start = end !== void 0 && serial32Precedes(first, end) ? end : first;
|
|
1393
|
+
if (!serial32Precedes(start, b)) return null;
|
|
1394
|
+
const length = serial32Distance(start, b);
|
|
1395
|
+
const missing = this.#highestMissing(start, length);
|
|
1396
|
+
let flagged = false;
|
|
1397
|
+
for (let i = 0; flag !== void 0 && !flagged && i < length; i++) {
|
|
1398
|
+
const payload = this.#held.get(serial32Add(start, i));
|
|
1399
|
+
flagged = payload !== void 0 && flag(payload);
|
|
1400
|
+
}
|
|
1401
|
+
return missing === void 0 ? { start, flagged } : { start, missing, flagged };
|
|
1402
|
+
}
|
|
1331
1403
|
/**
|
|
1332
1404
|
* Apply one repair symbol's `(SS_Start, SSB_length)`. The first repair of a
|
|
1333
1405
|
* block states its range and places every held source in it; later repair
|
|
1334
|
-
* symbols of the same block change nothing. A range
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1406
|
+
* symbols of the same block change nothing. A repair whose range is exactly
|
|
1407
|
+
* a repair-less span states that span's one block. A range that contradicts
|
|
1408
|
+
* a known block (a different length, or an overlap with another block or
|
|
1409
|
+
* with part of a span) fails closed: the repair symbol is dropped and no
|
|
1410
|
+
* block changes.
|
|
1337
1411
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
1338
1412
|
* A block so far past `newest` that stating it would retire the position
|
|
1339
1413
|
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
@@ -1352,7 +1426,16 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1352
1426
|
const known = this.blockAt(start);
|
|
1353
1427
|
if (known !== void 0) {
|
|
1354
1428
|
if (known.span) {
|
|
1355
|
-
|
|
1429
|
+
if (known.length === length) {
|
|
1430
|
+
const block2 = { start, length, span: false };
|
|
1431
|
+
this.#blocks[this.#blocks.indexOf(known)] = block2;
|
|
1432
|
+
return { status: "placed", block: block2, placed: [] };
|
|
1433
|
+
}
|
|
1434
|
+
return length < known.length ? {
|
|
1435
|
+
status: "overlap",
|
|
1436
|
+
reason: `repair block ${start}+${length} is only the first block of repair-less span ${known.start}+${known.length}`,
|
|
1437
|
+
ofSpan: known
|
|
1438
|
+
} : { status: "overlap", reason: `repair block ${start}+${length} runs past repair-less span ${known.start}+${known.length}` };
|
|
1356
1439
|
}
|
|
1357
1440
|
if (known.length !== length) {
|
|
1358
1441
|
return {
|
|
@@ -1420,18 +1503,28 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1420
1503
|
return span === void 0 ? { status: "placed", block, placed } : { status: "placed", block, placed, span };
|
|
1421
1504
|
}
|
|
1422
1505
|
/**
|
|
1423
|
-
* Turn every
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1506
|
+
* Turn every hole inside `[start, start + length)` into a repair-less span,
|
|
1507
|
+
* claiming its held sources: its range FETCH ended, so nothing more will
|
|
1508
|
+
* state its blocks. A hole the horizon passed (`takeExpiredHoles`) leaves a
|
|
1509
|
+
* span that is not kept among the blocks, as the horizon would retire it at
|
|
1510
|
+
* once; only `locate` finds it, until the next retirement, so its sources
|
|
1511
|
+
* can be fed. Returns the spans, in SS_ID order.
|
|
1426
1512
|
*/
|
|
1427
1513
|
closeHolesWithin(start, length) {
|
|
1428
1514
|
const closed = [];
|
|
1429
|
-
for (const
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1515
|
+
for (const holes of [this.#holes, this.#expired]) {
|
|
1516
|
+
for (const hole of [...holes]) {
|
|
1517
|
+
if (!isoBlockContains(start, length, hole.start)) continue;
|
|
1518
|
+
holes.splice(holes.indexOf(hole), 1);
|
|
1519
|
+
const spanBlock = { start: hole.start, length: hole.length, span: true };
|
|
1520
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) });
|
|
1521
|
+
if (holes === this.#holes) {
|
|
1522
|
+
this.#blocks.push(spanBlock);
|
|
1523
|
+
} else {
|
|
1524
|
+
this.#closedBehind.push(spanBlock);
|
|
1525
|
+
if (this.#newlyExpired.includes(hole)) this.#newlyExpired.splice(this.#newlyExpired.indexOf(hole), 1);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1435
1528
|
}
|
|
1436
1529
|
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start));
|
|
1437
1530
|
}
|
|
@@ -1445,15 +1538,17 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1445
1538
|
return void 0;
|
|
1446
1539
|
}
|
|
1447
1540
|
/**
|
|
1448
|
-
* Retire every block and span whose last SS_ID, and every held source
|
|
1449
|
-
* lies more than `retentionBlocks` blocks behind
|
|
1450
|
-
* lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
1451
|
-
* horizon uses
|
|
1541
|
+
* Retire every block and span whose last SS_ID, and every held source
|
|
1542
|
+
* outside a hole, lies more than `retentionBlocks` blocks behind
|
|
1543
|
+
* `position`, with the shared lower-bound metric (`isoBlocksBehindLowerBound`)
|
|
1544
|
+
* every ISO interleave horizon uses; a pending hole so far behind expires
|
|
1545
|
+
* (`takeExpiredHoles`). Returns the retired block starts.
|
|
1452
1546
|
*/
|
|
1453
1547
|
retireBehind(position) {
|
|
1454
1548
|
this.observe(position);
|
|
1455
1549
|
const horizon = this.#retentionBlocks;
|
|
1456
1550
|
const retired = [];
|
|
1551
|
+
this.#closedBehind.length = 0;
|
|
1457
1552
|
for (let i = this.#blocks.length - 1; i >= 0; i--) {
|
|
1458
1553
|
const block = this.#blocks[i];
|
|
1459
1554
|
const last = serial32Add(block.start, block.length - 1);
|
|
@@ -1465,10 +1560,15 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1465
1560
|
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
1466
1561
|
const hole = this.#holes[i];
|
|
1467
1562
|
const last = serial32Add(hole.start, hole.length - 1);
|
|
1468
|
-
if (isoBlocksBehindLowerBound(last, position, this.#kMax)
|
|
1563
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) <= horizon) continue;
|
|
1564
|
+
this.#holes.splice(i, 1);
|
|
1565
|
+
this.#expired.push(hole);
|
|
1566
|
+
this.#newlyExpired.push(hole);
|
|
1469
1567
|
}
|
|
1470
1568
|
for (const ssId of [...this.#held.keys()]) {
|
|
1471
|
-
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#
|
|
1569
|
+
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon && !this.#holes.some((hole) => isoBlockContains(hole.start, hole.length, ssId)) && !this.#expired.some((hole) => isoBlockContains(hole.start, hole.length, ssId))) {
|
|
1570
|
+
this.#held.delete(ssId);
|
|
1571
|
+
}
|
|
1472
1572
|
}
|
|
1473
1573
|
return retired;
|
|
1474
1574
|
}
|
|
@@ -1476,9 +1576,13 @@ var IsoBlockLocator = class _IsoBlockLocator {
|
|
|
1476
1576
|
reset() {
|
|
1477
1577
|
this.#blocks.length = 0;
|
|
1478
1578
|
this.#holes.length = 0;
|
|
1579
|
+
this.#expired.length = 0;
|
|
1580
|
+
this.#newlyExpired.length = 0;
|
|
1581
|
+
this.#closedBehind.length = 0;
|
|
1479
1582
|
this.#held.clear();
|
|
1480
1583
|
this.#coverageEnd = void 0;
|
|
1481
1584
|
this.#newest = void 0;
|
|
1585
|
+
this.#newestSource = void 0;
|
|
1482
1586
|
}
|
|
1483
1587
|
#claim(block) {
|
|
1484
1588
|
const placed = [];
|
|
@@ -1541,31 +1645,26 @@ function deriveBlockClassifierGeometry(input) {
|
|
|
1541
1645
|
);
|
|
1542
1646
|
}
|
|
1543
1647
|
if (input.trackKind === "audio") return { trackKind: "audio" };
|
|
1544
|
-
if (!isPositiveFinite(input.framerate)) {
|
|
1545
|
-
return { trackKind: "video", mode: "all-protected", reason: "framerate-absent" };
|
|
1546
|
-
}
|
|
1547
|
-
const framerate = input.framerate;
|
|
1548
1648
|
let keyframeInterval;
|
|
1549
1649
|
if (isPositiveFinite(input.keyframeIntervalTicks) && isPositiveFinite(input.timescale)) {
|
|
1550
1650
|
keyframeInterval = { ticks: input.keyframeIntervalTicks, timescale: input.timescale };
|
|
1551
1651
|
} else if (isPositiveFinite(input.keyframeIntervalMs)) {
|
|
1552
1652
|
keyframeInterval = { ticks: input.keyframeIntervalMs, timescale: 1e3 };
|
|
1553
|
-
} else {
|
|
1554
|
-
return { trackKind: "video", mode: "all-protected", reason: "keyframe-cadence-absent" };
|
|
1555
1653
|
}
|
|
1654
|
+
const protect = (reason) => ({
|
|
1655
|
+
trackKind: "video",
|
|
1656
|
+
mode: "all-protected",
|
|
1657
|
+
reason,
|
|
1658
|
+
...keyframeInterval === void 0 ? {} : { keyframeInterval }
|
|
1659
|
+
});
|
|
1660
|
+
if (!isPositiveFinite(input.framerate)) return protect("framerate-absent");
|
|
1661
|
+
const framerate = input.framerate;
|
|
1662
|
+
if (keyframeInterval === void 0) return protect("keyframe-cadence-absent");
|
|
1556
1663
|
const gopFrames = exactInteger(keyframeInterval.ticks * framerate, keyframeInterval.timescale);
|
|
1557
|
-
if (gopFrames === null)
|
|
1558
|
-
return {
|
|
1559
|
-
trackKind: "video",
|
|
1560
|
-
mode: "all-protected",
|
|
1561
|
-
reason: "keyframe-interval-not-integral"
|
|
1562
|
-
};
|
|
1563
|
-
}
|
|
1664
|
+
if (gopFrames === null) return protect("keyframe-interval-not-integral");
|
|
1564
1665
|
const frameDurationMs = 1e3 / framerate;
|
|
1565
1666
|
const interleaveUnits = deriveFecInterleaveDepth(input.interleaveDepthMs, frameDurationMs);
|
|
1566
|
-
if (interleaveUnits >= gopFrames)
|
|
1567
|
-
return { trackKind: "video", mode: "all-protected", reason: "block-spans-gop" };
|
|
1568
|
-
}
|
|
1667
|
+
if (interleaveUnits >= gopFrames) return protect("block-spans-gop");
|
|
1569
1668
|
return {
|
|
1570
1669
|
trackKind: "video",
|
|
1571
1670
|
mode: "classifying",
|
|
@@ -1576,7 +1675,7 @@ function deriveBlockClassifierGeometry(input) {
|
|
|
1576
1675
|
};
|
|
1577
1676
|
}
|
|
1578
1677
|
function keyframeIntervalMediaTicks(geometry2, mediaTimescale) {
|
|
1579
|
-
if (geometry2.trackKind !== "video" || geometry2.
|
|
1678
|
+
if (geometry2.trackKind !== "video" || geometry2.keyframeInterval === void 0) return null;
|
|
1580
1679
|
if (!Number.isSafeInteger(mediaTimescale) || mediaTimescale <= 0) return null;
|
|
1581
1680
|
const { ticks, timescale } = geometry2.keyframeInterval;
|
|
1582
1681
|
if (!Number.isSafeInteger(ticks) || !Number.isSafeInteger(timescale)) return null;
|
|
@@ -1585,9 +1684,15 @@ function keyframeIntervalMediaTicks(geometry2, mediaTimescale) {
|
|
|
1585
1684
|
if (scaled % divisor !== 0n) return null;
|
|
1586
1685
|
return scaled / divisor;
|
|
1587
1686
|
}
|
|
1687
|
+
function keyframeInstantBetween(start, interval, from, to) {
|
|
1688
|
+
const k = from >= start ? (from - start) / interval + 1n : 1n;
|
|
1689
|
+
return start + k * interval <= to;
|
|
1690
|
+
}
|
|
1588
1691
|
function compareDataUnitStarts(a, b) {
|
|
1589
|
-
return a.movieFragment - b.movieFragment || a.idx - b.idx || a.offset - b.offset;
|
|
1692
|
+
return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
|
|
1590
1693
|
}
|
|
1694
|
+
var LATE_RAP_MAX_MPUS_BACK = 64;
|
|
1695
|
+
var UNPLACED = { rapNotMpuStart: false };
|
|
1591
1696
|
var BlockClassifier = class {
|
|
1592
1697
|
#geometry;
|
|
1593
1698
|
#mode;
|
|
@@ -1610,8 +1715,24 @@ var BlockClassifier = class {
|
|
|
1610
1715
|
#mpuSbnSpans = /* @__PURE__ */ new Map();
|
|
1611
1716
|
#dataUnitStarts = /* @__PURE__ */ new Map();
|
|
1612
1717
|
#highestMpu = null;
|
|
1613
|
-
/**
|
|
1614
|
-
|
|
1718
|
+
/**
|
|
1719
|
+
* P3 layout, kept for the MPUs within the classification horizon and valid
|
|
1720
|
+
* within one continuous SBN sequence (`noteSourceDiscontinuity`).
|
|
1721
|
+
*/
|
|
1722
|
+
#mpus = /* @__PURE__ */ new Map();
|
|
1723
|
+
/** An MPU of this sequence showed two movie fragments: each frame is one. */
|
|
1724
|
+
#fragmentPerFrame = false;
|
|
1725
|
+
/** A DU header of this sequence stated sample_number above 1. */
|
|
1726
|
+
#multiSampleFragment = false;
|
|
1727
|
+
/**
|
|
1728
|
+
* The anchor received last, whether or not its MPU is still in the
|
|
1729
|
+
* horizon. Each new anchor, and the anchor of every DU header's MPU, is
|
|
1730
|
+
* checked against it.
|
|
1731
|
+
*/
|
|
1732
|
+
#lastAnchor = null;
|
|
1733
|
+
/** Two anchors were exactly G fragments per MPU apart. */
|
|
1734
|
+
#fragmentsProven = false;
|
|
1735
|
+
/** The first RAP released of the latest MPU a RAP was released in, recorded in every mode. */
|
|
1615
1736
|
#lastRap = null;
|
|
1616
1737
|
constructor(geometry2) {
|
|
1617
1738
|
this.#geometry = geometry2;
|
|
@@ -1641,7 +1762,7 @@ var BlockClassifier = class {
|
|
|
1641
1762
|
this.#geometry = geometry2;
|
|
1642
1763
|
this.#blocks.clear();
|
|
1643
1764
|
this.#clearContiguityLedger();
|
|
1644
|
-
this.#
|
|
1765
|
+
this.#clearMpuLayout();
|
|
1645
1766
|
this.#lastRap = null;
|
|
1646
1767
|
this.#mpuBoundsRaps = true;
|
|
1647
1768
|
if (geometry2.trackKind === "video" && geometry2.mode === "all-protected") {
|
|
@@ -1675,11 +1796,14 @@ var BlockClassifier = class {
|
|
|
1675
1796
|
/**
|
|
1676
1797
|
* The stream's SBN sequence restarted (FECManager source discontinuity:
|
|
1677
1798
|
* a publisher restart, or the SS_ID space wrapped). Authored order and SBN
|
|
1678
|
-
* order are comparable only within one continuous sequence,
|
|
1679
|
-
*
|
|
1799
|
+
* order are comparable only within one continuous sequence, and a
|
|
1800
|
+
* restarted publisher numbers MPUs and movie fragments again, so the P1
|
|
1801
|
+
* ledger and the P3 layout start again.
|
|
1680
1802
|
*/
|
|
1681
1803
|
noteSourceDiscontinuity() {
|
|
1682
1804
|
this.#clearContiguityLedger();
|
|
1805
|
+
this.#clearMpuLayout();
|
|
1806
|
+
this.#lastRap = null;
|
|
1683
1807
|
}
|
|
1684
1808
|
/** Register a block that exists without evidence (a vanished block). */
|
|
1685
1809
|
touch(sbn) {
|
|
@@ -1698,16 +1822,16 @@ var BlockClassifier = class {
|
|
|
1698
1822
|
if (this.#geometry.trackKind === "audio") return [];
|
|
1699
1823
|
const changes = [];
|
|
1700
1824
|
const block = this.#blockFor(sbn);
|
|
1825
|
+
const placement = this.#place(evidence);
|
|
1701
1826
|
if (evidence.rap) block.rapSeen = true;
|
|
1702
1827
|
if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
block.
|
|
1706
|
-
|
|
1707
|
-
if (evidence.rap && evidence.idx !== void 0 && evidence.idx !== 0) {
|
|
1708
|
-
this.#mpuBoundsRaps = false;
|
|
1828
|
+
const { position } = placement;
|
|
1829
|
+
if (position !== void 0) {
|
|
1830
|
+
block.positionMin = block.positionMin === void 0 ? position : Math.min(block.positionMin, position);
|
|
1831
|
+
block.positionMax = block.positionMax === void 0 ? position : Math.max(block.positionMax, position);
|
|
1709
1832
|
}
|
|
1710
|
-
|
|
1833
|
+
if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
|
|
1834
|
+
const violation = this.#checkInvariants(sbn, block, evidence, placement);
|
|
1711
1835
|
if (violation !== null) changes.push(...this.#disable(violation));
|
|
1712
1836
|
const next = this.#classify(block);
|
|
1713
1837
|
if (next !== block.cls && this.#allowed(block.cls, next)) {
|
|
@@ -1732,18 +1856,35 @@ var BlockClassifier = class {
|
|
|
1732
1856
|
* RAP-bearing block is the one a wrong G calls delta), because the next
|
|
1733
1857
|
* released RAP then belongs to m+2. Every MPU is one interval long, so the
|
|
1734
1858
|
* span to any later released RAP proves or refutes all MPUs in between.
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1859
|
+
*
|
|
1860
|
+
* In every mode it keeps each MPU's first released RAP, with its decode
|
|
1861
|
+
* time, as the start keyframeFreeBetween measures the catalog interval
|
|
1862
|
+
* from, and a second RAP released inside one MPU refutes `mpuBoundsRaps`
|
|
1863
|
+
* when it lies off the catalog lattice (not a whole number of intervals
|
|
1864
|
+
* after the first; draft-ramadan-moq-mmt-02 4.4.3 binds every keyframe to
|
|
1865
|
+
* it): with no repair, released RAPs are the only evidence of where they
|
|
1866
|
+
* lie. Without a usable interval, or a decode time on either, any second
|
|
1867
|
+
* RAP with another presentation time refutes.
|
|
1868
|
+
*/
|
|
1869
|
+
noteReleasedRap(mpu, presentationTime, mediaTimescale, decodeTime) {
|
|
1870
|
+
if (this.#geometry.trackKind === "audio") return [];
|
|
1742
1871
|
const previous = this.#lastRap;
|
|
1743
1872
|
if (previous !== null && previous.mpu === mpu && previous.mediaTimescale === mediaTimescale) {
|
|
1873
|
+
if (presentationTime === previous.presentationTime) return [];
|
|
1874
|
+
const interval2 = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
|
|
1875
|
+
if (interval2 === null || decodeTime === void 0 || previous.decodeTime === void 0 || (decodeTime - previous.decodeTime) % interval2 !== 0n) {
|
|
1876
|
+
this.#mpuBoundsRaps = false;
|
|
1877
|
+
}
|
|
1744
1878
|
return [];
|
|
1745
1879
|
}
|
|
1746
|
-
|
|
1880
|
+
if (previous !== null && previous.mediaTimescale === mediaTimescale) {
|
|
1881
|
+
const back = previous.mpu - mpu >>> 0;
|
|
1882
|
+
if (back !== 0 && back <= LATE_RAP_MAX_MPUS_BACK && presentationTime < previous.presentationTime) return [];
|
|
1883
|
+
}
|
|
1884
|
+
this.#lastRap = { mpu, presentationTime, mediaTimescale, ...decodeTime === void 0 ? {} : { decodeTime } };
|
|
1885
|
+
if (this.#mode === "all-protected") return [];
|
|
1886
|
+
const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
|
|
1887
|
+
if (interval === null) return this.#disable("keyframe-interval-not-media-integral");
|
|
1747
1888
|
if (previous === null || mpu < previous.mpu || previous.mediaTimescale !== mediaTimescale) {
|
|
1748
1889
|
return [];
|
|
1749
1890
|
}
|
|
@@ -1752,6 +1893,22 @@ var BlockClassifier = class {
|
|
|
1752
1893
|
}
|
|
1753
1894
|
return this.#disable("rap-spacing-mismatch");
|
|
1754
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Whether a gap inside MPU `mpu`, between the decode times `from` and `to`
|
|
1898
|
+
* of the frames on either side, holds no keyframe: MPU boundaries still
|
|
1899
|
+
* bound RAPs, the catalog states an interval exact in this timescale, and
|
|
1900
|
+
* none of its instants after the MPU's first released RAP lies in
|
|
1901
|
+
* `(from, to]` (fec-multicast-00 Block Classification item 3). Anything
|
|
1902
|
+
* unknown counts as a keyframe.
|
|
1903
|
+
*/
|
|
1904
|
+
keyframeFreeBetween(mpu, from, to, mediaTimescale) {
|
|
1905
|
+
const rap = this.#lastRap;
|
|
1906
|
+
if (!this.#mpuBoundsRaps || rap?.mpu !== mpu || rap.mediaTimescale !== mediaTimescale || rap.decodeTime === void 0) {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
const interval = keyframeIntervalMediaTicks(this.#geometry, mediaTimescale);
|
|
1910
|
+
return interval !== null && !keyframeInstantBetween(rap.decodeTime, interval, from, to);
|
|
1911
|
+
}
|
|
1755
1912
|
#blockFor(sbn) {
|
|
1756
1913
|
let block = this.#blocks.get(sbn);
|
|
1757
1914
|
if (!block) {
|
|
@@ -1760,35 +1917,89 @@ var BlockClassifier = class {
|
|
|
1760
1917
|
}
|
|
1761
1918
|
return block;
|
|
1762
1919
|
}
|
|
1763
|
-
#checkInvariants(sbn, block, evidence) {
|
|
1920
|
+
#checkInvariants(sbn, block, evidence, placement) {
|
|
1764
1921
|
if (this.#mode === "all-protected" || this.#geometry.trackKind !== "video") return null;
|
|
1765
1922
|
const geometry2 = this.#geometry;
|
|
1766
1923
|
if (geometry2.mode !== "classifying") return null;
|
|
1767
|
-
if (
|
|
1768
|
-
|
|
1769
|
-
}
|
|
1770
|
-
if (evidence.idx !== void 0 && evidence.idx >= geometry2.gopFrames) {
|
|
1924
|
+
if (placement.rapNotMpuStart) return "rap-not-mpu-start";
|
|
1925
|
+
if (placement.position !== void 0 && placement.position >= geometry2.gopFrames) {
|
|
1771
1926
|
return "mpu-longer-than-gop";
|
|
1772
1927
|
}
|
|
1773
|
-
if (block.mpus.size === 1 && block.
|
|
1928
|
+
if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0 && block.positionMax - block.positionMin >= geometry2.interleaveUnits) {
|
|
1774
1929
|
return "block-wider-than-interleave";
|
|
1775
1930
|
}
|
|
1776
|
-
if (
|
|
1777
|
-
const fragment = this.#mpuFragments.get(evidence.mpu);
|
|
1778
|
-
if (fragment === void 0) {
|
|
1779
|
-
this.#mpuFragments.set(evidence.mpu, evidence.movieFragment);
|
|
1780
|
-
for (const mpu of this.#mpuFragments.keys()) {
|
|
1781
|
-
if (mpu + 1 < evidence.mpu) this.#mpuFragments.delete(mpu);
|
|
1782
|
-
}
|
|
1783
|
-
} else if (fragment !== evidence.movieFragment) {
|
|
1784
|
-
return "mpu-multiple-fragments";
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1931
|
+
if (placement.violation !== void 0) return placement.violation;
|
|
1787
1932
|
if (evidence.mpu !== void 0 && this.#contradictsAuthoredOrder(sbn, evidence.mpu, evidence)) {
|
|
1788
1933
|
return "block-not-contiguous";
|
|
1789
1934
|
}
|
|
1790
1935
|
return null;
|
|
1791
1936
|
}
|
|
1937
|
+
/**
|
|
1938
|
+
* The MPU position a source symbol's DU header proves (P3), and what it
|
|
1939
|
+
* refutes. Runs in every mode: mpuBoundsRaps needs its RAP verdict.
|
|
1940
|
+
*/
|
|
1941
|
+
#place(evidence) {
|
|
1942
|
+
const { mpu, idx, movieFragment: fragment } = evidence;
|
|
1943
|
+
if (idx === void 0) return UNPLACED;
|
|
1944
|
+
const bySample = { position: idx, rapNotMpuStart: evidence.rap && idx !== 0 };
|
|
1945
|
+
if (mpu === void 0 || fragment === void 0) {
|
|
1946
|
+
return this.#fragmentPerFrame && !this.#multiSampleFragment ? { rapNotMpuStart: bySample.rapNotMpuStart } : bySample;
|
|
1947
|
+
}
|
|
1948
|
+
let layout = this.#mpus.get(mpu);
|
|
1949
|
+
if (layout === void 0) {
|
|
1950
|
+
layout = { low: fragment };
|
|
1951
|
+
this.#mpus.set(mpu, layout);
|
|
1952
|
+
for (const other of this.#mpus.keys()) {
|
|
1953
|
+
if (other + 1 < mpu) this.#mpus.delete(other);
|
|
1954
|
+
}
|
|
1955
|
+
} else if (fragment !== layout.low) {
|
|
1956
|
+
this.#fragmentPerFrame = true;
|
|
1957
|
+
if ((fragment - layout.low | 0) < 0) layout.low = fragment;
|
|
1958
|
+
}
|
|
1959
|
+
if (idx !== 0) this.#multiSampleFragment = true;
|
|
1960
|
+
let arrival;
|
|
1961
|
+
if (evidence.rap && layout.anchor === void 0) {
|
|
1962
|
+
layout.anchor = fragment;
|
|
1963
|
+
arrival = this.#anchorDrift(mpu, fragment);
|
|
1964
|
+
if (arrival === 0 && this.#lastAnchor?.mpu !== mpu) this.#fragmentsProven = true;
|
|
1965
|
+
this.#lastAnchor = { mpu, fragment };
|
|
1966
|
+
}
|
|
1967
|
+
if (!this.#fragmentPerFrame) return bySample;
|
|
1968
|
+
if (this.#multiSampleFragment) return { ...bySample, violation: "mpu-multiple-fragments" };
|
|
1969
|
+
const { anchor } = layout;
|
|
1970
|
+
if (anchor === void 0) return UNPLACED;
|
|
1971
|
+
const drift = arrival ?? this.#anchorDrift(mpu, anchor);
|
|
1972
|
+
const offset = fragment - anchor | 0;
|
|
1973
|
+
return {
|
|
1974
|
+
...offset === 0 || offset > 0 && this.#fragmentsProven ? { position: offset } : {},
|
|
1975
|
+
rapNotMpuStart: evidence.rap && offset !== 0 || (layout.low - anchor | 0) < 0 || // Fragments count frames: an anchor arriving past the spacing is a
|
|
1976
|
+
// RAP inside its MPU, or an earlier MPU outran G.
|
|
1977
|
+
arrival !== void 0 && arrival > 0 && this.#fragmentsProven,
|
|
1978
|
+
...drift === void 0 || drift === 0 ? {} : { violation: "rap-spacing-mismatch" }
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
/**
|
|
1982
|
+
* How many fragments MPU m's anchor `fragment` lies past the start that
|
|
1983
|
+
* the anchor received last predicts for MPU m: one frame per fragment and
|
|
1984
|
+
* G frames per MPU put the anchors of MPUs m and m' exactly G * (m - m')
|
|
1985
|
+
* fragments apart, modulo 2^32. Undefined without a last anchor, a
|
|
1986
|
+
* cadence, or this layout.
|
|
1987
|
+
*/
|
|
1988
|
+
#anchorDrift(mpu, fragment) {
|
|
1989
|
+
const geometry2 = this.#geometry;
|
|
1990
|
+
const last = this.#lastAnchor;
|
|
1991
|
+
if (last === null || !this.#fragmentPerFrame || this.#multiSampleFragment || geometry2.trackKind !== "video" || geometry2.mode !== "classifying") {
|
|
1992
|
+
return void 0;
|
|
1993
|
+
}
|
|
1994
|
+
return fragment - last.fragment - geometry2.gopFrames * (mpu - last.mpu) | 0;
|
|
1995
|
+
}
|
|
1996
|
+
#clearMpuLayout() {
|
|
1997
|
+
this.#mpus.clear();
|
|
1998
|
+
this.#fragmentPerFrame = false;
|
|
1999
|
+
this.#multiSampleFragment = false;
|
|
2000
|
+
this.#lastAnchor = null;
|
|
2001
|
+
this.#fragmentsProven = false;
|
|
2002
|
+
}
|
|
1792
2003
|
#clearContiguityLedger() {
|
|
1793
2004
|
this.#mpuSbnSpans.clear();
|
|
1794
2005
|
this.#dataUnitStarts.clear();
|
|
@@ -1888,9 +2099,9 @@ var BlockClassifier = class {
|
|
|
1888
2099
|
if (this.#mode === "all-protected") return "unknown";
|
|
1889
2100
|
const geometry2 = this.#geometry;
|
|
1890
2101
|
if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return "unknown";
|
|
1891
|
-
if (block.mpus.size === 1 && block.
|
|
2102
|
+
if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
|
|
1892
2103
|
const span = geometry2.interleaveUnits - 1;
|
|
1893
|
-
if (block.
|
|
2104
|
+
if (block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1) {
|
|
1894
2105
|
return "delta";
|
|
1895
2106
|
}
|
|
1896
2107
|
}
|
|
@@ -2067,6 +2278,7 @@ var WORKER_ERROR_LOG_CAP = 5;
|
|
|
2067
2278
|
var WORKER_ERROR_KIND_CAP = 32;
|
|
2068
2279
|
var WORKER_ERROR_OVERFLOW_KIND = "other";
|
|
2069
2280
|
var STARTUP_REPAIR_WAIT_SOURCE_BOUNDARIES = 2;
|
|
2281
|
+
var NOT_TAKEN = Object.freeze({ taken: false, recovered: null });
|
|
2070
2282
|
function isMulticastSymbolDelivery(value) {
|
|
2071
2283
|
return value === "datagram" || value === "ordered-relay";
|
|
2072
2284
|
}
|
|
@@ -2160,10 +2372,18 @@ var FECManager = class _FECManager {
|
|
|
2160
2372
|
// 'pending' forever, which would park every later frame of its stream in
|
|
2161
2373
|
// the in-order release gate. Each entry owns its handle; the callback
|
|
2162
2374
|
// checks it still owns the key, so a settled or reset key is never touched.
|
|
2375
|
+
/**
|
|
2376
|
+
* Per owed Worker cleanup: the bound on its acknowledgement, when its block
|
|
2377
|
+
* was due, and when its cleanup was asked for (see `onCleanupComplete`).
|
|
2378
|
+
*/
|
|
2163
2379
|
this.#pendingWorkerCleanupBounds = /* @__PURE__ */ new Map();
|
|
2164
2380
|
// Source symbol count per track-scoped block — marks complete when K symbols arrive.
|
|
2165
2381
|
this.#blockSourceCounts = /* @__PURE__ */ new Map();
|
|
2166
2382
|
this.#blockSourceEsis = /* @__PURE__ */ new Map();
|
|
2383
|
+
// Source ESIs per block that another FEC instance rebuilt and fed in
|
|
2384
|
+
// (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
|
|
2385
|
+
// not network arrivals and never make a block clean.
|
|
2386
|
+
this.#blockRebuiltEsis = /* @__PURE__ */ new Map();
|
|
2167
2387
|
// Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
|
|
2168
2388
|
// first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
|
|
2169
2389
|
// media units, usually before it holds K symbols; under iso-ssbg1-v1
|
|
@@ -2172,10 +2392,14 @@ var FECManager = class _FECManager {
|
|
|
2172
2392
|
// SSB_length source arrivals and recoverable from SSB_length received
|
|
2173
2393
|
// symbols; waiting for K fails every one of them.
|
|
2174
2394
|
this.#blockAuthoredLengths = /* @__PURE__ */ new Map();
|
|
2395
|
+
// Keys whose authored length is a repair-less span's (#openIsoSpan), until
|
|
2396
|
+
// a repair states the block there or the span resolves.
|
|
2397
|
+
this.#isoSpanKeys = /* @__PURE__ */ new Set();
|
|
2175
2398
|
this.#ssbLengthConflictCount = 0;
|
|
2176
2399
|
this.#blockRepairRsIds = /* @__PURE__ */ new Map();
|
|
2177
2400
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
2178
|
-
// symbols its repair group carries
|
|
2401
|
+
// symbols its repair group carries; 0 for a repair-less span no repair can
|
|
2402
|
+
// state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
|
|
2179
2403
|
this.#blockRsbLengths = /* @__PURE__ */ new Map();
|
|
2180
2404
|
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
2181
2405
|
this.#heldLayerStates = /* @__PURE__ */ new Map();
|
|
@@ -2292,6 +2516,10 @@ var FECManager = class _FECManager {
|
|
|
2292
2516
|
// ── Keyframe-protected repair policy (block-policy.ts) ──
|
|
2293
2517
|
// One classifier per physical stream, built from that stream's geometry.
|
|
2294
2518
|
this.#classifiers = /* @__PURE__ */ new Map();
|
|
2519
|
+
// A stream without catalog timing has no classifier, so the last RAP it
|
|
2520
|
+
// released stands in for one: "an MPU boundary bounds its RAPs" holds until
|
|
2521
|
+
// a second RAP is released inside one MPU (BLO-52085).
|
|
2522
|
+
this.#noSpanRaps = /* @__PURE__ */ new Map();
|
|
2295
2523
|
// Geometry a stream-scoped configuration gave one stream (streamKey). ABR
|
|
2296
2524
|
// rungs can share a packetId with a different framerate or GOP, so the
|
|
2297
2525
|
// packet-level geometry is only the geometry of a packet whose streams
|
|
@@ -2324,6 +2552,14 @@ var FECManager = class _FECManager {
|
|
|
2324
2552
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
2325
2553
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
2326
2554
|
this.#isoLocators = /* @__PURE__ */ new Map();
|
|
2555
|
+
// The ts of the run behind the gap the release gate last asked about, per
|
|
2556
|
+
// stream (isoRepairlessWaitMs), keyed on the frame before the gap: kept, as
|
|
2557
|
+
// the source it came from may retire before the run's deadline, and the
|
|
2558
|
+
// earliest found wins, so a late frame that becomes the head restarts
|
|
2559
|
+
// nothing. It stays until the next run gap: a source discontinuity drops
|
|
2560
|
+
// it, and one older than twice the hold ceiling is not this gap's.
|
|
2561
|
+
// `counted` once the deadline passed (onUndelimitedRunGap).
|
|
2562
|
+
this.#runAnchors = /* @__PURE__ */ new Map();
|
|
2327
2563
|
this.#deferIsoGaps = false;
|
|
2328
2564
|
this.#isoRepairRefusedCount = 0;
|
|
2329
2565
|
this.#isoSourceOversizeCount = 0;
|
|
@@ -2359,13 +2595,17 @@ var FECManager = class _FECManager {
|
|
|
2359
2595
|
this.#workerErrorCounts = /* @__PURE__ */ new Map();
|
|
2360
2596
|
this.#decoderUnavailableEvents = 0;
|
|
2361
2597
|
this.#repairSymbolSizeMismatchCount = 0;
|
|
2598
|
+
this.#unlistedRepairTrackRefusals = 0;
|
|
2362
2599
|
// Event callbacks — block lifecycle notifications for MmtpRouter wiring.
|
|
2363
2600
|
// NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
|
|
2364
2601
|
// feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
|
|
2365
2602
|
// arrives via onBlockRecovered callback.
|
|
2366
2603
|
this.onBlockStarted = null;
|
|
2367
2604
|
this.onBlockComplete = null;
|
|
2368
|
-
/**
|
|
2605
|
+
/**
|
|
2606
|
+
* A block reached its fail bound. `blockClass` is its class at failure.
|
|
2607
|
+
* `span` is set when what failed is a repair-less span starting at `sbn`.
|
|
2608
|
+
*/
|
|
2369
2609
|
this.onBlockFailed = null;
|
|
2370
2610
|
/**
|
|
2371
2611
|
* Fired once per stream when its Worker decoder stops being routable.
|
|
@@ -2407,12 +2647,26 @@ var FECManager = class _FECManager {
|
|
|
2407
2647
|
* for it, which it must be.
|
|
2408
2648
|
*/
|
|
2409
2649
|
this.#onUndelimitedLoss = null;
|
|
2650
|
+
/** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
|
|
2651
|
+
this.#onIsoHoleExpired = null;
|
|
2410
2652
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
2411
2653
|
this.onBlockVanished = null;
|
|
2412
2654
|
/** A block reached a terminal state (completed, recovered, or failed). */
|
|
2413
2655
|
this.onBlockResolved = null;
|
|
2414
2656
|
/** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
|
|
2415
2657
|
this.onSourceDiscontinuity = null;
|
|
2658
|
+
/** The FEC deadline of a run no repair delimited passed, releasing the gap behind it (once per gap). */
|
|
2659
|
+
this.onUndelimitedRunGap = null;
|
|
2660
|
+
/**
|
|
2661
|
+
* The span and tolerance the catalog states for a keyframe overlay
|
|
2662
|
+
* installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
|
|
2663
|
+
* overlay instance's own interleaveDepthMs and reorderToleranceMs), or
|
|
2664
|
+
* undefined while none is installed. A stated block only a late source
|
|
2665
|
+
* can complete, and a frame whose gap may hide a RAP behind a span only a
|
|
2666
|
+
* late source can fill, also wait for that overlay's repair
|
|
2667
|
+
* (#overlayLateWaitMs).
|
|
2668
|
+
*/
|
|
2669
|
+
this.keyframeOverlayTiming = null;
|
|
2416
2670
|
// Worker-path callbacks — async recovery and stats from FecWorkerClient.
|
|
2417
2671
|
/**
|
|
2418
2672
|
* A recovered source symbol. Return false when admission refused the
|
|
@@ -2449,7 +2703,9 @@ var FECManager = class _FECManager {
|
|
|
2449
2703
|
#pendingWorkerCleanupBounds;
|
|
2450
2704
|
#blockSourceCounts;
|
|
2451
2705
|
#blockSourceEsis;
|
|
2706
|
+
#blockRebuiltEsis;
|
|
2452
2707
|
#blockAuthoredLengths;
|
|
2708
|
+
#isoSpanKeys;
|
|
2453
2709
|
#ssbLengthConflictCount;
|
|
2454
2710
|
#blockRepairRsIds;
|
|
2455
2711
|
#blockRsbLengths;
|
|
@@ -2491,6 +2747,7 @@ var FECManager = class _FECManager {
|
|
|
2491
2747
|
#orderedFrontiers;
|
|
2492
2748
|
#orderedPendingBlocks;
|
|
2493
2749
|
#classifiers;
|
|
2750
|
+
#noSpanRaps;
|
|
2494
2751
|
#streamGeometries;
|
|
2495
2752
|
#failedBlocks;
|
|
2496
2753
|
#resolvedBlockClasses;
|
|
@@ -2500,6 +2757,7 @@ var FECManager = class _FECManager {
|
|
|
2500
2757
|
#highestSbn;
|
|
2501
2758
|
#sourceFrontiers;
|
|
2502
2759
|
#isoLocators;
|
|
2760
|
+
#runAnchors;
|
|
2503
2761
|
#deferIsoGaps;
|
|
2504
2762
|
#isoRepairRefusedCount;
|
|
2505
2763
|
#isoSourceOversizeCount;
|
|
@@ -2514,7 +2772,9 @@ var FECManager = class _FECManager {
|
|
|
2514
2772
|
#workerErrorCounts;
|
|
2515
2773
|
#decoderUnavailableEvents;
|
|
2516
2774
|
#repairSymbolSizeMismatchCount;
|
|
2775
|
+
#unlistedRepairTrackRefusals;
|
|
2517
2776
|
#onUndelimitedLoss;
|
|
2777
|
+
#onIsoHoleExpired;
|
|
2518
2778
|
#encodeTrackName(catalogTrackName) {
|
|
2519
2779
|
let encoded = this.#encodedTrackNames.get(catalogTrackName);
|
|
2520
2780
|
if (encoded === void 0) {
|
|
@@ -2986,7 +3246,10 @@ var FECManager = class _FECManager {
|
|
|
2986
3246
|
timer.handle = null;
|
|
2987
3247
|
this.#requestRepair(sbn, packetId, catalogTrackName);
|
|
2988
3248
|
};
|
|
2989
|
-
timer.handle = setTimeout(
|
|
3249
|
+
timer.handle = setTimeout(
|
|
3250
|
+
onFire,
|
|
3251
|
+
this.#receiptAtMs === void 0 ? Math.max(0, deadlineMs - performance.now()) : this.#receiptTimerDelayMs(deadlineMs, 0)
|
|
3252
|
+
);
|
|
2990
3253
|
this.#repairDeadlines.set(key, timer);
|
|
2991
3254
|
}
|
|
2992
3255
|
#requestRepair(sbn, packetId, catalogTrackName, settledByOrder = false) {
|
|
@@ -3130,8 +3393,14 @@ var FECManager = class _FECManager {
|
|
|
3130
3393
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
3131
3394
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
3132
3395
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
3396
|
+
*
|
|
3397
|
+
* A `held` source arrived before its block was known and is fed only now
|
|
3398
|
+
* that a repair, a span or a closed hole placed it: how far its block start
|
|
3399
|
+
* then lies behind the frontier measures how long the receiver held it, not
|
|
3400
|
+
* where the stream was, so only its SS_ID and packet_sequence_number judge
|
|
3401
|
+
* it (BLO-52085).
|
|
3133
3402
|
*/
|
|
3134
|
-
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
|
|
3403
|
+
#noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn, held = false) {
|
|
3135
3404
|
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
3136
3405
|
const now = performance.now();
|
|
3137
3406
|
const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
|
|
@@ -3152,6 +3421,8 @@ var FECManager = class _FECManager {
|
|
|
3152
3421
|
};
|
|
3153
3422
|
const discontinuity = () => {
|
|
3154
3423
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
|
|
3424
|
+
this.#noSpanRaps.delete(streamKey);
|
|
3425
|
+
this.#runAnchors.delete(streamKey);
|
|
3155
3426
|
this.#highestSbn.set(streamKey, { sbn, atMs: now });
|
|
3156
3427
|
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
|
|
3157
3428
|
if (psn === void 0) this.#sourceAnchors.delete(streamKey);
|
|
@@ -3169,7 +3440,7 @@ var FECManager = class _FECManager {
|
|
|
3169
3440
|
return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
|
|
3170
3441
|
};
|
|
3171
3442
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
3172
|
-
if (symbol === "source" && window2 !== null && this.#blockPrecedes(sbn, previous.sbn) && (this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) || psn !== void 0 && anchor !== void 0 && serial32Precedes(ssId, anchor.ssId) && psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))) {
|
|
3443
|
+
if (symbol === "source" && window2 !== null && this.#blockPrecedes(sbn, previous.sbn) && (!held && this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) || psn !== void 0 && anchor !== void 0 && serial32Precedes(ssId, anchor.ssId) && psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))) {
|
|
3173
3444
|
discontinuity();
|
|
3174
3445
|
return;
|
|
3175
3446
|
}
|
|
@@ -3431,17 +3702,21 @@ var FECManager = class _FECManager {
|
|
|
3431
3702
|
this.#blockWaitDeadlinesMs.delete(key);
|
|
3432
3703
|
this.#repairHoldUntilMs.delete(key);
|
|
3433
3704
|
this.#traceLifecycle("timeout-queued", sbn, packetId, catalogTrackName);
|
|
3434
|
-
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName);
|
|
3705
|
+
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs);
|
|
3435
3706
|
};
|
|
3436
|
-
timer.handle = setTimeout(
|
|
3707
|
+
timer.handle = setTimeout(
|
|
3708
|
+
onFire,
|
|
3709
|
+
this.#receiptAtMs === void 0 ? Math.max(1, Math.ceil(deadlineMs - nowMs)) : this.#receiptTimerDelayMs(deadlineMs, 1)
|
|
3710
|
+
);
|
|
3437
3711
|
this.#activeBlocks.set(key, timer);
|
|
3438
3712
|
this.#indexBlockKey(key, sbn, packetId);
|
|
3439
3713
|
}
|
|
3440
3714
|
/**
|
|
3441
3715
|
* Hand a block whose delivery is over to its decoder for finalization: the
|
|
3442
|
-
* datagram deadline fired, or the ordered relay moved past it.
|
|
3716
|
+
* datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
|
|
3717
|
+
* is when it was due: its deadline, or now.
|
|
3443
3718
|
*/
|
|
3444
|
-
#finalizeExpiredBlock(sbn, packetId, catalogTrackName) {
|
|
3719
|
+
#finalizeExpiredBlock(sbn, packetId, catalogTrackName, dueAtMs = performance.now()) {
|
|
3445
3720
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
3446
3721
|
if (this.#materializedBlocks.has(key) && !this.#blockPathCounts.has(key)) {
|
|
3447
3722
|
this.#failBlock(sbn, packetId, catalogTrackName);
|
|
@@ -3457,7 +3732,7 @@ var FECManager = class _FECManager {
|
|
|
3457
3732
|
if (workerClient) {
|
|
3458
3733
|
this.#pendingWorkerCleanups.add(key);
|
|
3459
3734
|
this.#pendingWorkerCleanupClients.set(key, workerClient);
|
|
3460
|
-
this.#boundOwedCleanup(key, packetId, workerClient);
|
|
3735
|
+
this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs);
|
|
3461
3736
|
workerClient.cleanup(sbn);
|
|
3462
3737
|
} else {
|
|
3463
3738
|
const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client;
|
|
@@ -3564,6 +3839,9 @@ var FECManager = class _FECManager {
|
|
|
3564
3839
|
}
|
|
3565
3840
|
if (policyChanged) {
|
|
3566
3841
|
this.#bumpEpoch(packetId);
|
|
3842
|
+
for (const key of [...this.#noSpanRaps.keys()]) {
|
|
3843
|
+
if (this.#belongsToPacket(key, packetId)) this.#noSpanRaps.delete(key);
|
|
3844
|
+
}
|
|
3567
3845
|
for (const [key, classifier] of [...this.#classifiers]) {
|
|
3568
3846
|
if (!this.#belongsToPacket(key, packetId)) continue;
|
|
3569
3847
|
const stream = this.#parseStreamKey(key);
|
|
@@ -3664,6 +3942,7 @@ var FECManager = class _FECManager {
|
|
|
3664
3942
|
packetId
|
|
3665
3943
|
})),
|
|
3666
3944
|
repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
|
|
3945
|
+
unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
|
|
3667
3946
|
repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
|
|
3668
3947
|
workerErrors: Object.fromEntries(this.#workerErrorCounts)
|
|
3669
3948
|
};
|
|
@@ -3766,7 +4045,9 @@ var FECManager = class _FECManager {
|
|
|
3766
4045
|
}
|
|
3767
4046
|
resetMap(this.#blockSourceCounts);
|
|
3768
4047
|
resetMap(this.#blockSourceEsis);
|
|
4048
|
+
resetMap(this.#blockRebuiltEsis);
|
|
3769
4049
|
resetMap(this.#blockAuthoredLengths);
|
|
4050
|
+
resetSet(this.#isoSpanKeys);
|
|
3770
4051
|
resetMap(this.#blockRepairRsIds);
|
|
3771
4052
|
resetMap(this.#blockRsbLengths);
|
|
3772
4053
|
resetMap(this.#heldLayerStates);
|
|
@@ -3797,8 +4078,10 @@ var FECManager = class _FECManager {
|
|
|
3797
4078
|
resetMap(this.#highestSbn);
|
|
3798
4079
|
resetMap(this.#sourceFrontiers);
|
|
3799
4080
|
resetMap(this.#isoLocators);
|
|
4081
|
+
resetMap(this.#runAnchors);
|
|
3800
4082
|
resetMap(this.#sourceAnchors);
|
|
3801
4083
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
|
|
4084
|
+
this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName));
|
|
3802
4085
|
this.#bumpEpoch(packetId);
|
|
3803
4086
|
for (const [sbn, keys] of this.#blockKeysBySbn) {
|
|
3804
4087
|
for (const key of keys.keys()) {
|
|
@@ -3889,7 +4172,9 @@ var FECManager = class _FECManager {
|
|
|
3889
4172
|
dropMap(this.#pendingWorkerCleanupClients);
|
|
3890
4173
|
dropMap(this.#blockSourceCounts);
|
|
3891
4174
|
dropMap(this.#blockSourceEsis);
|
|
4175
|
+
dropMap(this.#blockRebuiltEsis);
|
|
3892
4176
|
dropMap(this.#blockAuthoredLengths);
|
|
4177
|
+
dropSet(this.#isoSpanKeys);
|
|
3893
4178
|
dropMap(this.#blockRepairRsIds);
|
|
3894
4179
|
dropMap(this.#blockRsbLengths);
|
|
3895
4180
|
dropMap(this.#blockPathCounts);
|
|
@@ -3903,8 +4188,10 @@ var FECManager = class _FECManager {
|
|
|
3903
4188
|
dropMap(this.#highestSbn);
|
|
3904
4189
|
dropMap(this.#sourceFrontiers);
|
|
3905
4190
|
dropMap(this.#isoLocators);
|
|
4191
|
+
dropMap(this.#runAnchors);
|
|
3906
4192
|
dropMap(this.#sourceAnchors);
|
|
3907
4193
|
dropMap(this.#classifiers);
|
|
4194
|
+
dropMap(this.#noSpanRaps);
|
|
3908
4195
|
dropMap(this.#streamGeometries);
|
|
3909
4196
|
dropSet(this.#pendingWorkerCleanups);
|
|
3910
4197
|
dropSet(this.#completedBlocks);
|
|
@@ -4050,6 +4337,9 @@ var FECManager = class _FECManager {
|
|
|
4050
4337
|
this.#unindexBlockKey(key);
|
|
4051
4338
|
}
|
|
4052
4339
|
}
|
|
4340
|
+
if (isSourceSymbol && source === "multicast") {
|
|
4341
|
+
this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), sbn + esi >>> 0, packetId, catalogTrackName);
|
|
4342
|
+
}
|
|
4053
4343
|
return true;
|
|
4054
4344
|
}
|
|
4055
4345
|
#observeBlockCatalogTrackName(blockKey, sbn, packetId, catalogTrackName) {
|
|
@@ -4159,8 +4449,10 @@ var FECManager = class _FECManager {
|
|
|
4159
4449
|
}
|
|
4160
4450
|
/**
|
|
4161
4451
|
* An open block's accepted sources, distinct repair RS_IDs, authored K'
|
|
4162
|
-
* (SSB_length) and RSB_length (each undefined until a repair stated it
|
|
4163
|
-
*
|
|
4452
|
+
* (SSB_length) and RSB_length (each undefined until a repair stated it; a
|
|
4453
|
+
* repair-less span states its length, and RSB_length 0 when it is longer
|
|
4454
|
+
* than K, since no repair can reach it). Undefined for a block that is not
|
|
4455
|
+
* open.
|
|
4164
4456
|
*/
|
|
4165
4457
|
blockSymbolCounts(sbn, packetId, catalogTrackName) {
|
|
4166
4458
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -4228,8 +4520,9 @@ var FECManager = class _FECManager {
|
|
|
4228
4520
|
return true;
|
|
4229
4521
|
}
|
|
4230
4522
|
/**
|
|
4231
|
-
* Drop a block's repair hold: its FETCH ended without delivering
|
|
4232
|
-
*
|
|
4523
|
+
* Drop a block's repair hold: its FETCH ended without delivering, or brought
|
|
4524
|
+
* back only a repair that cannot complete it. The block falls back to its
|
|
4525
|
+
* multicast wait, which may already have passed.
|
|
4233
4526
|
*/
|
|
4234
4527
|
releaseRepairHold(sbn, packetId, catalogTrackName) {
|
|
4235
4528
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
@@ -4275,7 +4568,7 @@ var FECManager = class _FECManager {
|
|
|
4275
4568
|
}
|
|
4276
4569
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
4277
4570
|
if (trackConfig === void 0) return void 0;
|
|
4278
|
-
return Math.max(1, trackConfig
|
|
4571
|
+
return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
|
|
4279
4572
|
}
|
|
4280
4573
|
/** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
|
|
4281
4574
|
// -----------------------------------------------------------------------
|
|
@@ -4317,6 +4610,9 @@ var FECManager = class _FECManager {
|
|
|
4317
4610
|
for (const key of [...this.#isoLocators.keys()]) {
|
|
4318
4611
|
if (this.#belongsToPacket(key, packetId)) this.#isoLocators.delete(key);
|
|
4319
4612
|
}
|
|
4613
|
+
for (const key of [...this.#runAnchors.keys()]) {
|
|
4614
|
+
if (this.#belongsToPacket(key, packetId)) this.#runAnchors.delete(key);
|
|
4615
|
+
}
|
|
4320
4616
|
}
|
|
4321
4617
|
/**
|
|
4322
4618
|
* The iso-ssbg1-v1 locator horizon in blocks: every block the manager can
|
|
@@ -4366,7 +4662,9 @@ var FECManager = class _FECManager {
|
|
|
4366
4662
|
holdIsoSource(packetId, catalogTrackName, ssId, source) {
|
|
4367
4663
|
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
4368
4664
|
const evictedBefore = locator.heldEvicted;
|
|
4369
|
-
const held = locator.hold(ssId, source);
|
|
4665
|
+
const held = locator.hold(ssId, source.arrivedAtMs === void 0 ? { ...source, arrivedAtMs: this.#receiptNow() } : source);
|
|
4666
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
4667
|
+
if (held && source.source === "multicast") this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName);
|
|
4370
4668
|
const evicted = locator.heldEvicted - evictedBefore;
|
|
4371
4669
|
if (evicted > 0) {
|
|
4372
4670
|
const before = this.#isoHeldEvictedCount;
|
|
@@ -4387,17 +4685,20 @@ var FECManager = class _FECManager {
|
|
|
4387
4685
|
* contradicts a known block is refused (counted) and must be dropped.
|
|
4388
4686
|
*/
|
|
4389
4687
|
placeIsoRepair(packetId, catalogTrackName, ssStart, ssbLength) {
|
|
4390
|
-
const
|
|
4688
|
+
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName);
|
|
4689
|
+
const placement = locator.placeRepair(ssStart, ssbLength);
|
|
4690
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName);
|
|
4391
4691
|
if (placement.status !== "placed") {
|
|
4392
4692
|
this.#isoRepairRefusedCount++;
|
|
4393
4693
|
if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
|
|
4394
4694
|
console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`);
|
|
4395
4695
|
}
|
|
4696
|
+
if (placement.ofSpan !== void 0) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName);
|
|
4396
4697
|
return placement;
|
|
4397
4698
|
}
|
|
4699
|
+
this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName));
|
|
4398
4700
|
if (placement.span !== void 0) this.#openIsoSpan(placement.span, packetId, catalogTrackName);
|
|
4399
4701
|
if (placement.hole !== void 0) {
|
|
4400
|
-
const locator = this.#isoLocatorFor(packetId, catalogTrackName);
|
|
4401
4702
|
const hole = placement.hole.block;
|
|
4402
4703
|
const previous = locator.blockEndingAt(hole.start);
|
|
4403
4704
|
const loss = {
|
|
@@ -4418,17 +4719,29 @@ var FECManager = class _FECManager {
|
|
|
4418
4719
|
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
4419
4720
|
* range repair scheduler; applies to every stream from its next gap. The
|
|
4420
4721
|
* handler and the deferral are one setting, so no hole is ever created with
|
|
4421
|
-
* nobody to close it.
|
|
4722
|
+
* nobody to close it. `onExpired` is told of each pending hole the stream
|
|
4723
|
+
* runs past the locator's horizon (BLO-52085): returning true, it closes
|
|
4724
|
+
* the hole (`closeIsoHoles`), so the span it leaves still fails and is
|
|
4725
|
+
* reported; otherwise the hole is discarded with its sources.
|
|
4422
4726
|
*/
|
|
4423
|
-
setUndelimitedLossHandler(handler) {
|
|
4727
|
+
setUndelimitedLossHandler(handler, onExpired = null) {
|
|
4424
4728
|
this.#onUndelimitedLoss = handler;
|
|
4729
|
+
this.#onIsoHoleExpired = handler === null ? null : onExpired;
|
|
4425
4730
|
this.#deferIsoGaps = handler !== null;
|
|
4426
4731
|
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps;
|
|
4427
4732
|
}
|
|
4733
|
+
/** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
|
|
4734
|
+
#settleExpiredIsoHoles(locator, packetId, catalogTrackName) {
|
|
4735
|
+
for (const hole of locator.takeExpiredHoles()) {
|
|
4736
|
+
const expired = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length };
|
|
4737
|
+
if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length);
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4428
4740
|
/**
|
|
4429
|
-
* The range repair for a hole ended: every hole
|
|
4430
|
-
*
|
|
4431
|
-
* with the held sources they placed, for the caller to feed
|
|
4741
|
+
* The range repair for a hole ended: every hole inside `[start, start +
|
|
4742
|
+
* length)`, pending or expired, becomes a repair-less span. Returns those
|
|
4743
|
+
* spans with the held sources they placed, for the caller to feed
|
|
4744
|
+
* (MmtpRouter).
|
|
4432
4745
|
*/
|
|
4433
4746
|
closeIsoHoles(packetId, catalogTrackName, start, length) {
|
|
4434
4747
|
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
@@ -4444,17 +4757,37 @@ var FECManager = class _FECManager {
|
|
|
4444
4757
|
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
4445
4758
|
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
4446
4759
|
* block.
|
|
4760
|
+
*
|
|
4761
|
+
* A span longer than K holds more than one block (SSB_length <= K), and the
|
|
4762
|
+
* locator states no block inside a span, only one exactly its range
|
|
4763
|
+
* (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
|
|
4764
|
+
* reach it. Its repair group is empty, so the repair scheduler FETCHes no
|
|
4765
|
+
* Group of it (group-cannot-complete). Every span still keeps its whole
|
|
4766
|
+
* wait (#lateSourceWaitMs): failing it early released the frames behind it
|
|
4767
|
+
* past a keyframe the overlay was still rebuilding (BLO-52085). The release
|
|
4768
|
+
* gate lets those frames go once only a late source can fill the gap
|
|
4769
|
+
* before them, as long after they arrived as the gap's decision allows
|
|
4770
|
+
* (isoRepairlessWaitMs).
|
|
4447
4771
|
*/
|
|
4448
4772
|
#openIsoSpan(span, packetId, catalogTrackName) {
|
|
4449
4773
|
const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
|
|
4450
|
-
if (!this.#blockAuthoredLengths.has(key))
|
|
4774
|
+
if (!this.#blockAuthoredLengths.has(key)) {
|
|
4775
|
+
this.#blockAuthoredLengths.set(key, span.block.length);
|
|
4776
|
+
this.#isoSpanKeys.add(key);
|
|
4777
|
+
if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0);
|
|
4778
|
+
}
|
|
4451
4779
|
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true);
|
|
4452
4780
|
}
|
|
4453
4781
|
/**
|
|
4454
4782
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
4455
4783
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
4456
4784
|
* that could hold them is pending or not yet stated by a repair, else the
|
|
4457
|
-
* starts of the blocks that failed or vanished.
|
|
4785
|
+
* starts of the blocks that failed or vanished. SS_IDs no repair has
|
|
4786
|
+
* delimited yet that all arrived lost nothing and wait for no repair, only
|
|
4787
|
+
* the late-source allowance after the multicast datagram that clocks them
|
|
4788
|
+
* arrived (#lossFreeRunReadyAtMs), and not even that when none of them came
|
|
4789
|
+
* as one; one missing makes a run that waits as one block
|
|
4790
|
+
* (isoRepairlessWaitMs).
|
|
4458
4791
|
*
|
|
4459
4792
|
* `untracked` reads as the release gate reads it (MmtpRouter
|
|
4460
4793
|
* #createFecReleaseGate): a block holding either released frame's SS_ID
|
|
@@ -4467,7 +4800,16 @@ var FECManager = class _FECManager {
|
|
|
4467
4800
|
isoSpanResolution(packetId, catalogTrackName, fromSsId, toSsId) {
|
|
4468
4801
|
if (!serial32Precedes(fromSsId, toSsId) || serial32Distance(fromSsId, toSsId) <= 1) return [];
|
|
4469
4802
|
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
|
|
4470
|
-
if (!locator
|
|
4803
|
+
if (!locator) return null;
|
|
4804
|
+
const run = locator.undelimitedBetween(fromSsId, toSsId);
|
|
4805
|
+
if (run?.missing !== void 0) return null;
|
|
4806
|
+
if (run !== null) {
|
|
4807
|
+
const config = this.#trackConfigs.get(packetId);
|
|
4808
|
+
const readyAtMs = config === void 0 ? void 0 : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId);
|
|
4809
|
+
if (readyAtMs !== void 0 && this.#receiptNow() < readyAtMs) return null;
|
|
4810
|
+
}
|
|
4811
|
+
if (locator.coverageEnd === void 0) return [];
|
|
4812
|
+
if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return null;
|
|
4471
4813
|
const highest = this.highestSbn(packetId, catalogTrackName);
|
|
4472
4814
|
const lost = [];
|
|
4473
4815
|
for (const block of locator.blocksBetween(fromSsId, toSsId)) {
|
|
@@ -4485,6 +4827,148 @@ var FECManager = class _FECManager {
|
|
|
4485
4827
|
}
|
|
4486
4828
|
return lost;
|
|
4487
4829
|
}
|
|
4830
|
+
/**
|
|
4831
|
+
* When undelimited SS_IDs from `runStart` up to `toSsId` that all arrived
|
|
4832
|
+
* stop holding its frame: the late-source allowance after a multicast
|
|
4833
|
+
* datagram receipt. Until then a frame between them may still complete
|
|
4834
|
+
* from a packet with no SS_ID (an untagged FT=0/FT=1 reordered behind the
|
|
4835
|
+
* next frame), and a repair may delimit them. The receipt is `toSsId`'s
|
|
4836
|
+
* own when it is held from a multicast datagram. Otherwise (its packet
|
|
4837
|
+
* came only as an overlap copy or from a MoQ stream, or was evicted or
|
|
4838
|
+
* retired) it is the newest among those SS_IDs, every one of which is
|
|
4839
|
+
* held and states its path. So the time moves at most once, when the
|
|
4840
|
+
* head's own multicast copy arrives while its frame waits or its held
|
|
4841
|
+
* source is dropped, and never on a later ask.
|
|
4842
|
+
*
|
|
4843
|
+
* Undefined, so the range releases at once, when no SS_ID of it came as a
|
|
4844
|
+
* multicast datagram: a MoQ arrival, an ordered relay's and the frame's
|
|
4845
|
+
* own are no clock for multicast reordering (#lossyReceiptMs). Undefined
|
|
4846
|
+
* too on a track with no catalog span, which states no allowance: the
|
|
4847
|
+
* local timeout is a cleanup bound, and isoRepairlessWaitMs arms no wake
|
|
4848
|
+
* there, so a wait would hold the frame until the next packet. The cost,
|
|
4849
|
+
* on multicast too: an untagged FT=0/FT=1 reordered behind the next frame
|
|
4850
|
+
* of such a track is dropped stale.
|
|
4851
|
+
*/
|
|
4852
|
+
#lossFreeRunReadyAtMs(config, locator, runStart, toSsId) {
|
|
4853
|
+
if (!_FECManager.#hasCatalogTiming(config)) return void 0;
|
|
4854
|
+
let clockMs = this.#lossyReceiptMs(locator.heldSource(toSsId));
|
|
4855
|
+
if (clockMs === void 0) {
|
|
4856
|
+
for (let ssId = runStart; ssId !== toSsId; ssId = ssId + 1 >>> 0) {
|
|
4857
|
+
const atMs = this.#lossyReceiptMs(locator.heldSource(ssId));
|
|
4858
|
+
if (atMs !== void 0 && (clockMs === void 0 || atMs > clockMs)) clockMs = atMs;
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
if (clockMs === void 0) return void 0;
|
|
4862
|
+
return clockMs + Math.max(0, this.#multicastWaitMs(config) - config.interleaveDepthMs);
|
|
4863
|
+
}
|
|
4864
|
+
/**
|
|
4865
|
+
* Receipt time of a held source that came as a multicast datagram, the
|
|
4866
|
+
* one path that loses and reorders packets, else undefined: a MoQ stream
|
|
4867
|
+
* and an ordered relay deliver in order, so their arrivals clock no
|
|
4868
|
+
* reorder allowance and no FEC deadline. The path is the one the feed
|
|
4869
|
+
* stated (IsoHeldSource.source, MulticastSymbolDelivery), never a guess.
|
|
4870
|
+
*/
|
|
4871
|
+
#lossyReceiptMs(held) {
|
|
4872
|
+
return held?.source === "multicast" && this.#multicastSymbolDelivery === "datagram" ? held.arrivedAtMs : void 0;
|
|
4873
|
+
}
|
|
4874
|
+
/**
|
|
4875
|
+
* The release gate's wait, from a frame's arrival, for the SS_IDs strictly
|
|
4876
|
+
* between two released frames' SS_IDs once only a late source can still
|
|
4877
|
+
* fill them, else undefined. That is when every one missing (neither
|
|
4878
|
+
* arrived nor held) lies in a repair-less span longer than K, which no
|
|
4879
|
+
* repair can state a block of (#openIsoSpan), or in a stated block its
|
|
4880
|
+
* own repair group cannot complete every SS_ID of which it misses lies
|
|
4881
|
+
* between them (so the gap's decision covers all it lost), and a multicast
|
|
4882
|
+
* source at or past `toSsId` arrived, so each is lost or reordered behind
|
|
4883
|
+
* it (a MoQ source shows nothing: MoQ streams overtake one another). The
|
|
4884
|
+
* span or block itself keeps its own wait.
|
|
4885
|
+
*
|
|
4886
|
+
* The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
|
|
4887
|
+
* hold a RAP packet an installed keyframe overlay can still rebuild (its
|
|
4888
|
+
* decision stalls, or it ends at a RAP that may lie past a whole MPU).
|
|
4889
|
+
* Then the frame waits as a stated block its group cannot complete does
|
|
4890
|
+
* (#overlayLateWaitMs): the allowance alone with no overlay installed, the
|
|
4891
|
+
* overlay's span plus the larger of the allowance and its tolerance, or,
|
|
4892
|
+
* for an overlay that states no span, the span's whole wait (undefined).
|
|
4893
|
+
* So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
|
|
4894
|
+
* the gap holds a stated block's loss.
|
|
4895
|
+
*
|
|
4896
|
+
* A run of SS_IDs no repair has delimited yet, one of which never arrived,
|
|
4897
|
+
* is one block of its own instead (draft-ramadan-moq-fec-multicast-00,
|
|
4898
|
+
* Receiver Repair Policy): on datagram delivery the frame then waits for
|
|
4899
|
+
* that block's FEC deadline, whatever the flags: ts plus the whole
|
|
4900
|
+
* multicast wait (fec-core-00 9.3), ts the arrival of the lowest held
|
|
4901
|
+
* multicast source above the run, up to the newest (fec-multicast-00,
|
|
4902
|
+
* Deadline Anchoring; under reordering at or after the draft's first
|
|
4903
|
+
* signal, never before). The wait returned counts from `arrivedAtMs`, the
|
|
4904
|
+
* frame's arrival; without it, it is the whole wait. With no such source
|
|
4905
|
+
* held (never arrived, retired, or evicted) the frame keeps the hold
|
|
4906
|
+
* ceiling: a MoQ arrival is no clock for a multicast deadline.
|
|
4907
|
+
*/
|
|
4908
|
+
isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false, arrivedAtMs) {
|
|
4909
|
+
const config = this.#trackConfigs.get(packetId);
|
|
4910
|
+
if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
|
|
4911
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
4912
|
+
const locator = this.#isoLocators.get(streamKey);
|
|
4913
|
+
if (locator === void 0) return void 0;
|
|
4914
|
+
const run = locator.undelimitedBetween(fromSsId, toSsId);
|
|
4915
|
+
const readyAtMs = run === null || run.missing !== void 0 ? void 0 : this.#lossFreeRunReadyAtMs(config, locator, run.start, toSsId);
|
|
4916
|
+
if (readyAtMs !== void 0 && this.#receiptNow() < readyAtMs) {
|
|
4917
|
+
return Math.max(0, readyAtMs - (arrivedAtMs ?? this.#receiptNow()));
|
|
4918
|
+
}
|
|
4919
|
+
const newestSource = locator.newestSource;
|
|
4920
|
+
if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
|
|
4921
|
+
if (run?.missing !== void 0) {
|
|
4922
|
+
if (this.#multicastSymbolDelivery === "ordered-relay" || this.isoSpanResolution(packetId, catalogTrackName, fromSsId, run.start) === null) {
|
|
4923
|
+
return void 0;
|
|
4924
|
+
}
|
|
4925
|
+
const kept = this.#runAnchors.get(streamKey);
|
|
4926
|
+
const anchor = kept?.fromSsId === fromSsId && this.#receiptNow() - kept.tsMs <= 2 * (config.interleaveDepthMs + 2 * this.#blockLifetimeMs(config)) ? kept : void 0;
|
|
4927
|
+
let tsMs = anchor?.tsMs;
|
|
4928
|
+
for (let ssId = run.missing + 1 >>> 0; !serial32Precedes(newestSource, ssId); ssId = ssId + 1 >>> 0) {
|
|
4929
|
+
const atMs = this.#lossyReceiptMs(locator.heldSource(ssId));
|
|
4930
|
+
if (atMs === void 0) continue;
|
|
4931
|
+
if (tsMs === void 0 || atMs < tsMs) tsMs = atMs;
|
|
4932
|
+
break;
|
|
4933
|
+
}
|
|
4934
|
+
if (tsMs === void 0) return void 0;
|
|
4935
|
+
const waitMs2 = this.#multicastWaitMs(config);
|
|
4936
|
+
let counted = anchor?.counted === true;
|
|
4937
|
+
if (!counted && tsMs + waitMs2 <= this.#receiptNow()) {
|
|
4938
|
+
counted = true;
|
|
4939
|
+
this.onUndelimitedRunGap?.(packetId, catalogTrackName);
|
|
4940
|
+
}
|
|
4941
|
+
this.#runAnchors.set(streamKey, { fromSsId, tsMs, counted });
|
|
4942
|
+
return arrivedAtMs === void 0 ? waitMs2 : Math.max(0, tsMs + waitMs2 - arrivedAtMs);
|
|
4943
|
+
}
|
|
4944
|
+
if (!locator.coversBetween(fromSsId, run?.start ?? toSsId)) return void 0;
|
|
4945
|
+
let repairless = false;
|
|
4946
|
+
let stated = false;
|
|
4947
|
+
for (const block of locator.blocksBetween(fromSsId, toSsId)) {
|
|
4948
|
+
const key = this.#blockKey(block.start, packetId, catalogTrackName);
|
|
4949
|
+
if (this.#completedBlocks.has(key)) continue;
|
|
4950
|
+
if (block.span && block.length > locator.kMax) {
|
|
4951
|
+
repairless = true;
|
|
4952
|
+
continue;
|
|
4953
|
+
}
|
|
4954
|
+
const received = this.#blockSourceEsis.get(key);
|
|
4955
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
4956
|
+
let missesInGap = false;
|
|
4957
|
+
let missesOutside = false;
|
|
4958
|
+
for (let esi = 0; esi < block.length; esi++) {
|
|
4959
|
+
const ssId = serial32Add(block.start, esi);
|
|
4960
|
+
if (received?.has(esi) || locator.isHeld(ssId)) continue;
|
|
4961
|
+
if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
|
|
4962
|
+
else if (!rebuilt?.has(esi)) missesOutside = true;
|
|
4963
|
+
}
|
|
4964
|
+
if (!missesInGap) continue;
|
|
4965
|
+
if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
|
|
4966
|
+
repairless = stated = true;
|
|
4967
|
+
}
|
|
4968
|
+
if (!repairless) return void 0;
|
|
4969
|
+
const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
|
|
4970
|
+
return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
|
|
4971
|
+
}
|
|
4488
4972
|
/**
|
|
4489
4973
|
* iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
|
|
4490
4974
|
* the sources held now for a block no repair has stated yet, and the held
|
|
@@ -4535,11 +5019,34 @@ var FECManager = class _FECManager {
|
|
|
4535
5019
|
/**
|
|
4536
5020
|
* Whether an MPU boundary still bounds this stream's RAPs (see
|
|
4537
5021
|
* `BlockClassifier.mpuBoundsRaps`). Gap decisions drop MPU evidence once
|
|
4538
|
-
* it does not. A stream with no classifier yet has shown nothing against it
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
5022
|
+
* it does not. A stream with no classifier yet has shown nothing against it,
|
|
5023
|
+
* and neither has a stream without catalog timing until it releases two
|
|
5024
|
+
* RAPs inside one MPU.
|
|
5025
|
+
*
|
|
5026
|
+
* With catalog timing and a `gap` inside one MPU, between the authored
|
|
5027
|
+
* timing of the frames on either side, it also takes the catalog keyframe
|
|
5028
|
+
* interval to rule a keyframe out of the gap
|
|
5029
|
+
* (`BlockClassifier.keyframeFreeBetween`, fec-multicast-00 Block
|
|
5030
|
+
* Classification item 3), and no source held between the frames' SS_IDs
|
|
5031
|
+
* may carry the RAP flag or another MPU's number (item 1 read on the held
|
|
5032
|
+
* packets: a RAP the loss cut in two is never released, so the frames
|
|
5033
|
+
* alone cannot show it); anything unknown counts as a keyframe.
|
|
5034
|
+
*/
|
|
5035
|
+
mpuBoundsRapsFor(packetId, catalogTrackName, gap) {
|
|
5036
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
5037
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true;
|
|
5038
|
+
const classifier = this.#classifiers.get(streamKey);
|
|
5039
|
+
if (gap === void 0) return classifier?.mpuBoundsRaps ?? true;
|
|
5040
|
+
const { mpu, from, to, fromSsId, toSsId } = gap;
|
|
5041
|
+
if (fromSsId !== void 0 && toSsId !== void 0) {
|
|
5042
|
+
const run = this.#isoLocators.get(streamKey)?.undelimitedBetween(
|
|
5043
|
+
fromSsId,
|
|
5044
|
+
toSsId,
|
|
5045
|
+
({ evidence }) => evidence.rap || evidence.mpu !== void 0 && evidence.mpu !== mpu
|
|
5046
|
+
);
|
|
5047
|
+
if (run?.flagged) return false;
|
|
5048
|
+
}
|
|
5049
|
+
return classifier !== void 0 && from !== void 0 && to !== void 0 && from.mediaTimescale === to.mediaTimescale && classifier.keyframeFreeBetween(mpu, from.decodeTime, to.decodeTime, from.mediaTimescale);
|
|
4543
5050
|
}
|
|
4544
5051
|
/** A block's class now, or frozen at its resolution. */
|
|
4545
5052
|
blockClassFor(sbn, packetId, catalogTrackName) {
|
|
@@ -4562,17 +5069,27 @@ var FECManager = class _FECManager {
|
|
|
4562
5069
|
}
|
|
4563
5070
|
/**
|
|
4564
5071
|
* Record a RAP frame released in order, for the classifier's RAP-spacing
|
|
4565
|
-
* invariant (consecutive MPUs exactly one keyframe interval apart)
|
|
5072
|
+
* invariant (consecutive MPUs exactly one keyframe interval apart) and,
|
|
5073
|
+
* with its decode time, as the MPU start gap decisions measure the catalog
|
|
5074
|
+
* keyframe interval from (mpuBoundsRapsFor).
|
|
4566
5075
|
*/
|
|
4567
|
-
noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale) {
|
|
4568
|
-
if (!this.#trackConfigs.has(packetId)
|
|
5076
|
+
noteReleasedRap(packetId, catalogTrackName, mpu, presentationTime, mediaTimescale, decodeTime) {
|
|
5077
|
+
if (!this.#trackConfigs.has(packetId)) return;
|
|
5078
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) {
|
|
5079
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName);
|
|
5080
|
+
const last = this.#noSpanRaps.get(streamKey);
|
|
5081
|
+
const inside = last?.inside === true || last?.mpu === mpu && last.presentationTime !== presentationTime;
|
|
5082
|
+
this.#noSpanRaps.set(streamKey, { mpu, presentationTime, inside });
|
|
5083
|
+
return;
|
|
5084
|
+
}
|
|
4569
5085
|
this.#applyClassifierChanges(
|
|
4570
5086
|
packetId,
|
|
4571
5087
|
catalogTrackName,
|
|
4572
5088
|
this.#classifierFor(packetId, catalogTrackName).noteReleasedRap(
|
|
4573
5089
|
mpu,
|
|
4574
5090
|
presentationTime,
|
|
4575
|
-
mediaTimescale
|
|
5091
|
+
mediaTimescale,
|
|
5092
|
+
decodeTime
|
|
4576
5093
|
)
|
|
4577
5094
|
);
|
|
4578
5095
|
}
|
|
@@ -4778,11 +5295,14 @@ var FECManager = class _FECManager {
|
|
|
4778
5295
|
});
|
|
4779
5296
|
client.onCleanupComplete((sbn) => {
|
|
4780
5297
|
if (this.#releasedWorkerClients.has(client)) return;
|
|
4781
|
-
const
|
|
5298
|
+
const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client);
|
|
5299
|
+
const cleanupKeys = owed.filter((key) => {
|
|
4782
5300
|
const block = this.#parseBlockKey(key);
|
|
4783
|
-
return block.packetId === packetId && block.sbn === sbn
|
|
5301
|
+
return block.packetId === packetId && block.sbn === sbn;
|
|
4784
5302
|
});
|
|
4785
|
-
|
|
5303
|
+
const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity));
|
|
5304
|
+
const due = owed.filter((key) => !cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs);
|
|
5305
|
+
for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, "cleanup-ack");
|
|
4786
5306
|
});
|
|
4787
5307
|
client.onError((msg, code) => {
|
|
4788
5308
|
const requestedKind = code ?? msg;
|
|
@@ -4852,9 +5372,11 @@ var FECManager = class _FECManager {
|
|
|
4852
5372
|
* fail deadline already passed, so failing it is the decision that deadline
|
|
4853
5373
|
* made. A late ack then finds nothing owed and is a no-op.
|
|
4854
5374
|
*/
|
|
4855
|
-
#boundOwedCleanup(key, packetId, client) {
|
|
5375
|
+
#boundOwedCleanup(key, packetId, client, dueAtMs) {
|
|
4856
5376
|
this.#clearOwedCleanupBound(key);
|
|
4857
5377
|
const bound = {
|
|
5378
|
+
dueAtMs,
|
|
5379
|
+
askedAtMs: performance.now(),
|
|
4858
5380
|
handle: setTimeout(() => {
|
|
4859
5381
|
if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return;
|
|
4860
5382
|
this.#pendingWorkerCleanupBounds.delete(key);
|
|
@@ -4952,7 +5474,15 @@ var FECManager = class _FECManager {
|
|
|
4952
5474
|
this.#isoSourceOversizeCount++;
|
|
4953
5475
|
return null;
|
|
4954
5476
|
}
|
|
4955
|
-
|
|
5477
|
+
return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start);
|
|
5478
|
+
}
|
|
5479
|
+
/**
|
|
5480
|
+
* Hand one placed source symbol to the stream's decoder: its Worker, which
|
|
5481
|
+
* answers through onFrame (null here), or its synchronous decoder, whose
|
|
5482
|
+
* recovered block is returned. `sbn` is the SS_Start of the block a repair
|
|
5483
|
+
* stated for `ssId`.
|
|
5484
|
+
*/
|
|
5485
|
+
#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn) {
|
|
4956
5486
|
const blockKey = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
4957
5487
|
const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey);
|
|
4958
5488
|
const workerClient = this.#routableWorkerForPacket(packetId, catalogTrackName);
|
|
@@ -4981,6 +5511,74 @@ var FECManager = class _FECManager {
|
|
|
4981
5511
|
}
|
|
4982
5512
|
return recovered;
|
|
4983
5513
|
}
|
|
5514
|
+
/**
|
|
5515
|
+
* Feed a source symbol of this stream that another FEC instance over the
|
|
5516
|
+
* same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
|
|
5517
|
+
* caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
|
|
5518
|
+
* BLO-52085). It joins its block's decoder as a received source would, so
|
|
5519
|
+
* it reduces the erasures the block still has to solve, but it is not a
|
|
5520
|
+
* network arrival: no transport accounting, no classification evidence,
|
|
5521
|
+
* no deadline refresh, and it never makes a block clean.
|
|
5522
|
+
*
|
|
5523
|
+
* Only a block a repair stated takes one (a repair-less span has no
|
|
5524
|
+
* decoder block). A block that is terminal, or already holds that source,
|
|
5525
|
+
* does not. The symbol is the exact protected packet, unpadded, as
|
|
5526
|
+
* feedSourceSymbol takes it.
|
|
5527
|
+
*
|
|
5528
|
+
* `recovered` is the block the synchronous decoder completed with it; the
|
|
5529
|
+
* caller routes it and completes the block, as for any recovery. When
|
|
5530
|
+
* every source of the block is then present, received or rebuilt, and no
|
|
5531
|
+
* decoder returned it (a Worker answers asynchronously, and reports such a
|
|
5532
|
+
* block as clean on its own side), the block is completed here as
|
|
5533
|
+
* recovered, with nothing left to route.
|
|
5534
|
+
*/
|
|
5535
|
+
feedRebuiltSourceSymbol(packetId, ssId, symbolData, catalogTrackName) {
|
|
5536
|
+
if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN;
|
|
5537
|
+
const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId);
|
|
5538
|
+
if (located === null || located.block.span) return NOT_TAKEN;
|
|
5539
|
+
if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN;
|
|
5540
|
+
const sbn = located.block.start;
|
|
5541
|
+
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
5542
|
+
if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN;
|
|
5543
|
+
let rebuilt = this.#blockRebuiltEsis.get(key);
|
|
5544
|
+
if (rebuilt?.has(located.esi)) return NOT_TAKEN;
|
|
5545
|
+
if (rebuilt === void 0) {
|
|
5546
|
+
rebuilt = /* @__PURE__ */ new Set();
|
|
5547
|
+
this.#blockRebuiltEsis.set(key, rebuilt);
|
|
5548
|
+
}
|
|
5549
|
+
const config = this.#trackConfigs.get(packetId);
|
|
5550
|
+
const wasShort = config !== void 0 && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== void 0;
|
|
5551
|
+
rebuilt.add(located.esi);
|
|
5552
|
+
const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn);
|
|
5553
|
+
if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
|
|
5554
|
+
if (wasShort && this.#activeBlocks.has(key) && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) === void 0) {
|
|
5555
|
+
this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config));
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
return { taken: true, recovered };
|
|
5559
|
+
}
|
|
5560
|
+
/**
|
|
5561
|
+
* A block that holds every one of its `length` sources, received or
|
|
5562
|
+
* rebuilt by another instance, with at least one rebuilt, is recovered:
|
|
5563
|
+
* every packet of it was delivered, by its own arrival or by the instance
|
|
5564
|
+
* that rebuilt it, so nothing is routed. Returns whether it completed it.
|
|
5565
|
+
*/
|
|
5566
|
+
#completeWhenSourcesPresent(key, sbn, length, packetId, catalogTrackName) {
|
|
5567
|
+
const rebuilt = this.#blockRebuiltEsis.get(key);
|
|
5568
|
+
if (rebuilt === void 0 || this.#completedBlocks.has(key)) return false;
|
|
5569
|
+
let present = rebuilt.size;
|
|
5570
|
+
for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++;
|
|
5571
|
+
if (present < length) return false;
|
|
5572
|
+
this.#traceLifecycle("recovered", sbn, packetId, catalogTrackName);
|
|
5573
|
+
this.countRecovery(packetId, sbn, catalogTrackName);
|
|
5574
|
+
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
5575
|
+
if (catalogTrackName === void 0) {
|
|
5576
|
+
this.onBlockComplete?.(sbn, packetId);
|
|
5577
|
+
} else {
|
|
5578
|
+
this.onBlockComplete?.(sbn, packetId, catalogTrackName);
|
|
5579
|
+
}
|
|
5580
|
+
return true;
|
|
5581
|
+
}
|
|
4984
5582
|
/**
|
|
4985
5583
|
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
4986
5584
|
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
@@ -5042,7 +5640,10 @@ var FECManager = class _FECManager {
|
|
|
5042
5640
|
this.#layerAnchorHorizon(packetId),
|
|
5043
5641
|
this.#sourceFrontiers.get(streamKey)?.sbn
|
|
5044
5642
|
);
|
|
5045
|
-
if (verdict === "discard")
|
|
5643
|
+
if (verdict === "discard") {
|
|
5644
|
+
this.#unlistedRepairTrackRefusals++;
|
|
5645
|
+
return false;
|
|
5646
|
+
}
|
|
5046
5647
|
if (verdict !== void 0) {
|
|
5047
5648
|
this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
|
|
5048
5649
|
return false;
|
|
@@ -5183,8 +5784,115 @@ var FECManager = class _FECManager {
|
|
|
5183
5784
|
this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName);
|
|
5184
5785
|
return null;
|
|
5185
5786
|
}
|
|
5787
|
+
if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName);
|
|
5186
5788
|
return recovered;
|
|
5187
5789
|
}
|
|
5790
|
+
/**
|
|
5791
|
+
* A first-arrival multicast source, held or placed. A datagram flow keeps
|
|
5792
|
+
* its sources in send order, so one that moves the stream's newest source
|
|
5793
|
+
* position past a block leaves the sources that block still misses
|
|
5794
|
+
* reordered behind it at best: it shortens the wait of every block it
|
|
5795
|
+
* passed that only a late source can complete. MoQ is left out: its streams
|
|
5796
|
+
* can overtake one another, so a MoQ source shows nothing about the sources
|
|
5797
|
+
* sent before it.
|
|
5798
|
+
*/
|
|
5799
|
+
#noteMulticastSource(locator, ssId, packetId, catalogTrackName) {
|
|
5800
|
+
const previous = locator.newestSource;
|
|
5801
|
+
if (!locator.noteSource(ssId) || previous === void 0) return;
|
|
5802
|
+
for (const block of locator.blocksBetween(previous - 1 >>> 0, ssId)) {
|
|
5803
|
+
if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue;
|
|
5804
|
+
this.#shortenUnrecoverableWait(
|
|
5805
|
+
this.#blockKey(block.start, packetId, catalogTrackName),
|
|
5806
|
+
block.start,
|
|
5807
|
+
packetId,
|
|
5808
|
+
catalogTrackName
|
|
5809
|
+
);
|
|
5810
|
+
}
|
|
5811
|
+
}
|
|
5812
|
+
/**
|
|
5813
|
+
* The wait of a block that only a late source can complete (BLO-52085): a
|
|
5814
|
+
* repair stated it, its received sources plus every symbol its repair group
|
|
5815
|
+
* carries (RSB_length) are short of K' (the repair scheduler's
|
|
5816
|
+
* group-cannot-complete), and a later source of the stream has arrived, so
|
|
5817
|
+
* a source it misses is lost or reordered behind that one. The span, which
|
|
5818
|
+
* covers repair symbols paced after its sources, buys it nothing: it waits
|
|
5819
|
+
* the late-symbol allowance alone, the multicast wait less the span (the
|
|
5820
|
+
* catalog tolerance or the measured delivery gap). Undefined for any other
|
|
5821
|
+
* block. While a keyframe overlay is installed, the block waits for its
|
|
5822
|
+
* repair too (#overlayLateWaitMs). A repair-less span keeps its whole
|
|
5823
|
+
* wait, even one longer than K whose group is empty (#openIsoSpan): its
|
|
5824
|
+
* resolution is what releases the frames behind it, and failing it early
|
|
5825
|
+
* released them past a keyframe the overlay was still rebuilding, which
|
|
5826
|
+
* then arrived stale. The release gate lets them go instead
|
|
5827
|
+
* (isoRepairlessWaitMs).
|
|
5828
|
+
*/
|
|
5829
|
+
#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
|
|
5830
|
+
if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
|
|
5831
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
5832
|
+
const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
|
|
5833
|
+
if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
|
|
5834
|
+
return void 0;
|
|
5835
|
+
}
|
|
5836
|
+
return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
|
|
5837
|
+
}
|
|
5838
|
+
/**
|
|
5839
|
+
* A repair stated the block, and its sources plus every symbol its repair
|
|
5840
|
+
* group carries (RSB_length) are short of its SSB_length.
|
|
5841
|
+
*/
|
|
5842
|
+
#groupCannotComplete(key) {
|
|
5843
|
+
const authoredLength = this.#blockAuthoredLengths.get(key);
|
|
5844
|
+
const rsbLength = this.#blockRsbLengths.get(key);
|
|
5845
|
+
if (authoredLength === void 0 || rsbLength === void 0) return false;
|
|
5846
|
+
let present = this.#blockSourceCounts.get(key) ?? 0;
|
|
5847
|
+
const received = this.#blockSourceEsis.get(key);
|
|
5848
|
+
for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
|
|
5849
|
+
return present + rsbLength < authoredLength;
|
|
5850
|
+
}
|
|
5851
|
+
/**
|
|
5852
|
+
* How long a loss only a late source or an installed keyframe overlay can
|
|
5853
|
+
* still fill waits once a later source passed it: the late-symbol
|
|
5854
|
+
* allowance alone (the multicast wait less the span) while no overlay is
|
|
5855
|
+
* installed. An installed one (keyframeOverlayTiming) may still rebuild a
|
|
5856
|
+
* RAP packet the loss took: a second FEC instance over the same packets
|
|
5857
|
+
* (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
|
|
5858
|
+
* span, unrelated to the base's. That packet can complete a stated block
|
|
5859
|
+
* (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
|
|
5860
|
+
* first lets the release gate pass the keyframe, whose rebuild then lands
|
|
5861
|
+
* stale. The overlay repair of a packet the loss took goes out within the
|
|
5862
|
+
* overlay's span of that packet (fec-core-00 9.3), and the later source was
|
|
5863
|
+
* sent after it, so the loss waits that span plus the larger of the
|
|
5864
|
+
* allowance and the overlay's own tolerance. An overlay that states no
|
|
5865
|
+
* span (its block may then span keyframes), or one whose wait is not
|
|
5866
|
+
* shorter than the whole multicast wait, leaves the whole wait: undefined.
|
|
5867
|
+
*/
|
|
5868
|
+
#overlayLateWaitMs(packetId, catalogTrackName, config) {
|
|
5869
|
+
const waitMs = this.#multicastWaitMs(config);
|
|
5870
|
+
const allowanceMs = waitMs - config.interleaveDepthMs;
|
|
5871
|
+
const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
|
|
5872
|
+
if (overlay === void 0) return allowanceMs;
|
|
5873
|
+
const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
|
|
5874
|
+
const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
|
|
5875
|
+
return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
|
|
5876
|
+
}
|
|
5877
|
+
/**
|
|
5878
|
+
* Bring an open block's wait in to its late-source wait, when it has one.
|
|
5879
|
+
* Never later than it is armed: only a source can complete such a block,
|
|
5880
|
+
* so a repair of its group (paced across the span) must not keep it open.
|
|
5881
|
+
*/
|
|
5882
|
+
#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName) {
|
|
5883
|
+
if (!this.#activeBlocks.has(key)) return;
|
|
5884
|
+
const config = this.#trackConfigs.get(packetId);
|
|
5885
|
+
if (config === void 0) return;
|
|
5886
|
+
const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config);
|
|
5887
|
+
if (waitMs === void 0) return;
|
|
5888
|
+
const armedAtMs = this.#blockWaitDeadlinesMs.get(key);
|
|
5889
|
+
this.#armBlockTimeout(
|
|
5890
|
+
sbn,
|
|
5891
|
+
packetId,
|
|
5892
|
+
catalogTrackName,
|
|
5893
|
+
armedAtMs === void 0 ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow())
|
|
5894
|
+
);
|
|
5895
|
+
}
|
|
5188
5896
|
/**
|
|
5189
5897
|
* Record a block's authored SSB_length from a repair symbol. Returns false,
|
|
5190
5898
|
* leaving the block unchanged, when the symbol contradicts the block: a
|
|
@@ -5282,12 +5990,13 @@ var FECManager = class _FECManager {
|
|
|
5282
5990
|
* the inactivity deadline on each symbol, records the symbol's in-band
|
|
5283
5991
|
* classification evidence, and marks the block clean when all of its
|
|
5284
5992
|
* authored source symbols arrived: the SSB_length a repair symbol declared,
|
|
5285
|
-
* otherwise K.
|
|
5993
|
+
* otherwise K. `held` marks a source held unplaced since it arrived and
|
|
5994
|
+
* placed only now (see #noteSbnSeen).
|
|
5286
5995
|
*
|
|
5287
5996
|
* Throws for a packetId that was never configured, so a classified block
|
|
5288
5997
|
* never reads the manager-global K or timeout.
|
|
5289
5998
|
*/
|
|
5290
|
-
trackBlock(sbn, packetId, catalogTrackName, esi, evidence) {
|
|
5999
|
+
trackBlock(sbn, packetId, catalogTrackName, esi, evidence, held = false) {
|
|
5291
6000
|
const trackConfig = this.#trackConfigs.get(packetId);
|
|
5292
6001
|
if (trackConfig === void 0) {
|
|
5293
6002
|
throw new Error(
|
|
@@ -5303,7 +6012,8 @@ var FECManager = class _FECManager {
|
|
|
5303
6012
|
catalogTrackName,
|
|
5304
6013
|
"source",
|
|
5305
6014
|
evidence.packetSequenceNumber,
|
|
5306
|
-
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
|
|
6015
|
+
Number.isInteger(esi) ? sbn + esi >>> 0 : sbn,
|
|
6016
|
+
held
|
|
5307
6017
|
);
|
|
5308
6018
|
const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
|
|
5309
6019
|
if (Number.isInteger(esi) && esi >= authoredLength) {
|
|
@@ -5339,6 +6049,15 @@ var FECManager = class _FECManager {
|
|
|
5339
6049
|
this.#completeCleanBlock(key, sbn, packetId, catalogTrackName);
|
|
5340
6050
|
return;
|
|
5341
6051
|
}
|
|
6052
|
+
if (this.#blockRebuiltEsis.has(key) && this.#completeWhenSourcesPresent(
|
|
6053
|
+
key,
|
|
6054
|
+
sbn,
|
|
6055
|
+
this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
|
|
6056
|
+
packetId,
|
|
6057
|
+
catalogTrackName
|
|
6058
|
+
)) {
|
|
6059
|
+
return;
|
|
6060
|
+
}
|
|
5342
6061
|
this.noteBlockActivity(sbn, packetId, catalogTrackName, true);
|
|
5343
6062
|
}
|
|
5344
6063
|
#completeCleanBlock(key, sbn, packetId, catalogTrackName) {
|
|
@@ -5347,7 +6066,9 @@ var FECManager = class _FECManager {
|
|
|
5347
6066
|
this.cancelBlockTimeout(sbn, packetId, catalogTrackName);
|
|
5348
6067
|
this.#blockSourceCounts.delete(key);
|
|
5349
6068
|
this.#blockSourceEsis.delete(key);
|
|
6069
|
+
this.#blockRebuiltEsis.delete(key);
|
|
5350
6070
|
this.#blockAuthoredLengths.delete(key);
|
|
6071
|
+
this.#isoSpanKeys.delete(key);
|
|
5351
6072
|
this.#blockRepairRsIds.delete(key);
|
|
5352
6073
|
this.#blockRsbLengths.delete(key);
|
|
5353
6074
|
this.#markTerminal(key, sbn, packetId, true);
|
|
@@ -5378,6 +6099,19 @@ var FECManager = class _FECManager {
|
|
|
5378
6099
|
#receiptNow() {
|
|
5379
6100
|
return this.#receiptAtMs ?? performance.now();
|
|
5380
6101
|
}
|
|
6102
|
+
/**
|
|
6103
|
+
* The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
|
|
6104
|
+
* scope: counted from the receipt time, as the timer of a symbol fed when
|
|
6105
|
+
* it was received was, less the whole ms since. So it fires on the tick
|
|
6106
|
+
* that timer would have, never later than a delay counted from now, and
|
|
6107
|
+
* its handler still re-arms a timer that fires before its deadline.
|
|
6108
|
+
* Counted from now, a deadline set from the receipt time is rounded up
|
|
6109
|
+
* from another fraction of a ms (BLO-52085).
|
|
6110
|
+
*/
|
|
6111
|
+
#receiptTimerDelayMs(deadlineMs, minMs) {
|
|
6112
|
+
const receivedAtMs = this.#receiptAtMs;
|
|
6113
|
+
return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs));
|
|
6114
|
+
}
|
|
5381
6115
|
/**
|
|
5382
6116
|
* A held packet admitted late arms from its (earlier) receipt time; that
|
|
5383
6117
|
* never pulls in a deadline later activity already armed. Outside a
|
|
@@ -5413,10 +6147,20 @@ var FECManager = class _FECManager {
|
|
|
5413
6147
|
this.#repairDeadlineMs(trackConfig)
|
|
5414
6148
|
);
|
|
5415
6149
|
}
|
|
5416
|
-
this.#
|
|
6150
|
+
if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== void 0) {
|
|
6151
|
+
this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName);
|
|
6152
|
+
return;
|
|
6153
|
+
}
|
|
6154
|
+
this.#armBlockTimeout(
|
|
6155
|
+
sbn,
|
|
6156
|
+
packetId,
|
|
6157
|
+
catalogTrackName,
|
|
6158
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs
|
|
6159
|
+
);
|
|
5417
6160
|
}
|
|
5418
6161
|
#failBlock(sbn, packetId, catalogTrackName) {
|
|
5419
6162
|
const key = this.#blockKey(sbn, packetId, catalogTrackName);
|
|
6163
|
+
const span = this.#isoSpanKeys.delete(key) ? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 } : void 0;
|
|
5420
6164
|
this.#traceLifecycle("failed", sbn, packetId, catalogTrackName);
|
|
5421
6165
|
this.#clearRepairDeadline(key);
|
|
5422
6166
|
this.#clearBlockTimer(key);
|
|
@@ -5426,6 +6170,7 @@ var FECManager = class _FECManager {
|
|
|
5426
6170
|
}
|
|
5427
6171
|
this.#blockSourceCounts.delete(key);
|
|
5428
6172
|
this.#blockSourceEsis.delete(key);
|
|
6173
|
+
this.#blockRebuiltEsis.delete(key);
|
|
5429
6174
|
this.#blockAuthoredLengths.delete(key);
|
|
5430
6175
|
this.#blockRepairRsIds.delete(key);
|
|
5431
6176
|
this.#blockRsbLengths.delete(key);
|
|
@@ -5435,7 +6180,8 @@ var FECManager = class _FECManager {
|
|
|
5435
6180
|
this.#markPathBlockComplete(sbn, packetId, catalogTrackName);
|
|
5436
6181
|
this.#fecStats.blocksFailed++;
|
|
5437
6182
|
this.#statsForPacket(packetId).blocksFailed++;
|
|
5438
|
-
this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
6183
|
+
if (span === void 0) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
6184
|
+
else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
5439
6185
|
this.onBlockResolved?.(sbn, packetId, catalogTrackName);
|
|
5440
6186
|
}
|
|
5441
6187
|
/**
|
|
@@ -5464,7 +6210,9 @@ var FECManager = class _FECManager {
|
|
|
5464
6210
|
this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName);
|
|
5465
6211
|
this.#blockSourceCounts.delete(key);
|
|
5466
6212
|
this.#blockSourceEsis.delete(key);
|
|
6213
|
+
this.#blockRebuiltEsis.delete(key);
|
|
5467
6214
|
this.#blockAuthoredLengths.delete(key);
|
|
6215
|
+
this.#isoSpanKeys.delete(key);
|
|
5468
6216
|
this.#blockRepairRsIds.delete(key);
|
|
5469
6217
|
this.#blockRsbLengths.delete(key);
|
|
5470
6218
|
this.#clearBlockTimer(key);
|
|
@@ -5555,7 +6303,9 @@ var FECManager = class _FECManager {
|
|
|
5555
6303
|
this.#blockKeysBySbn.clear();
|
|
5556
6304
|
this.#blockSourceCounts.clear();
|
|
5557
6305
|
this.#blockSourceEsis.clear();
|
|
6306
|
+
this.#blockRebuiltEsis.clear();
|
|
5558
6307
|
this.#blockAuthoredLengths.clear();
|
|
6308
|
+
this.#isoSpanKeys.clear();
|
|
5559
6309
|
this.#blockRepairRsIds.clear();
|
|
5560
6310
|
this.#blockRsbLengths.clear();
|
|
5561
6311
|
this.#heldLayerStates.clear();
|
|
@@ -5580,6 +6330,7 @@ var FECManager = class _FECManager {
|
|
|
5580
6330
|
this.#blockAnchorsMs.clear();
|
|
5581
6331
|
this.#blockCatalogTrackNames.clear();
|
|
5582
6332
|
this.#classifiers.clear();
|
|
6333
|
+
this.#noSpanRaps.clear();
|
|
5583
6334
|
this.#streamGeometries.clear();
|
|
5584
6335
|
this.#failedBlocks.clear();
|
|
5585
6336
|
this.#resolvedBlockClasses.clear();
|
|
@@ -5588,6 +6339,7 @@ var FECManager = class _FECManager {
|
|
|
5588
6339
|
this.#highestSbn.clear();
|
|
5589
6340
|
this.#sourceFrontiers.clear();
|
|
5590
6341
|
this.#isoLocators.clear();
|
|
6342
|
+
this.#runAnchors.clear();
|
|
5591
6343
|
this.#sourceAnchors.clear();
|
|
5592
6344
|
this.#trackConfigs.clear();
|
|
5593
6345
|
this.#fecDecoders.clear();
|
|
@@ -6933,9 +7685,9 @@ async function openSubscription(rx, openedPromise, options, packetIds) {
|
|
|
6933
7685
|
} catch (error) {
|
|
6934
7686
|
throw new MulticastError("subscription-failed", "MulticastReceiver did not open", error);
|
|
6935
7687
|
}
|
|
6936
|
-
if (
|
|
7688
|
+
if (opened.integrityScheme !== INTEGRITY_SCHEME) {
|
|
6937
7689
|
await rx.close();
|
|
6938
|
-
throw unsupported(`integrity scheme ${String(
|
|
7690
|
+
throw unsupported(`integrity scheme ${String(opened.integrityScheme)} is not ${INTEGRITY_SCHEME}`);
|
|
6939
7691
|
}
|
|
6940
7692
|
const events = new EventTarget();
|
|
6941
7693
|
let state = "connected";
|
|
@@ -7054,14 +7806,15 @@ var MOQT_PUBLISHER_PRIORITY = Object.freeze({
|
|
|
7054
7806
|
});
|
|
7055
7807
|
|
|
7056
7808
|
// node_modules/@blockcast/mmt-transport/dist/amt-gateway.js
|
|
7809
|
+
var MAX_PENDING_PACKETS = 256;
|
|
7057
7810
|
var AMTGatewayManager = class {
|
|
7058
7811
|
subscriptions = /* @__PURE__ */ new Map();
|
|
7059
7812
|
messageHandler;
|
|
7813
|
+
messageListenerRegistered = false;
|
|
7060
7814
|
pendingPackets = /* @__PURE__ */ new Map();
|
|
7061
7815
|
constructor() {
|
|
7062
7816
|
this.messageHandler = (event) => {
|
|
7063
7817
|
const data = event.data;
|
|
7064
|
-
console.log(`[AMT] SW message received:`, data.type);
|
|
7065
7818
|
if (data.type === "UDP_PACKET") {
|
|
7066
7819
|
this.handlePacket(data);
|
|
7067
7820
|
} else if (data.type === "SOCKET_ERROR") {
|
|
@@ -7070,12 +7823,22 @@ var AMTGatewayManager = class {
|
|
|
7070
7823
|
console.log(`[AMT SW Debug] ${data.message}`);
|
|
7071
7824
|
}
|
|
7072
7825
|
};
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7826
|
+
}
|
|
7827
|
+
ensureMessageListener() {
|
|
7828
|
+
if (this.messageListenerRegistered || typeof navigator === "undefined" || !navigator.serviceWorker || !this.messageHandler) {
|
|
7829
|
+
return;
|
|
7830
|
+
}
|
|
7831
|
+
navigator.serviceWorker.addEventListener("message", this.messageHandler);
|
|
7832
|
+
this.messageListenerRegistered = true;
|
|
7833
|
+
console.log("[AMT] Registered service worker message handler");
|
|
7834
|
+
}
|
|
7835
|
+
removeMessageListener() {
|
|
7836
|
+
if (!this.messageListenerRegistered)
|
|
7837
|
+
return;
|
|
7838
|
+
if (this.messageHandler && typeof navigator !== "undefined" && navigator.serviceWorker) {
|
|
7839
|
+
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
7078
7840
|
}
|
|
7841
|
+
this.messageListenerRegistered = false;
|
|
7079
7842
|
}
|
|
7080
7843
|
/**
|
|
7081
7844
|
* Subscribe via AMT tunnel
|
|
@@ -7085,6 +7848,7 @@ var AMTGatewayManager = class {
|
|
|
7085
7848
|
if (config.protected) {
|
|
7086
7849
|
throw new Error("AMTGatewayManager refuses a protected join: it reports no per-datagram sender (multicast-02 7.2.7)");
|
|
7087
7850
|
}
|
|
7851
|
+
this.ensureMessageListener();
|
|
7088
7852
|
const keyStr = this.getKeyString(key);
|
|
7089
7853
|
if (this.subscriptions.has(keyStr)) {
|
|
7090
7854
|
console.log(`[AMT] Reusing existing subscription to ${keyStr}`);
|
|
@@ -7120,6 +7884,8 @@ var AMTGatewayManager = class {
|
|
|
7120
7884
|
this.subscriptions.delete(keyStr);
|
|
7121
7885
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
7122
7886
|
}
|
|
7887
|
+
if (this.subscriptions.size === 0)
|
|
7888
|
+
this.removeMessageListener();
|
|
7123
7889
|
throw new Error(`Failed to subscribe via AMT: ${error instanceof Error ? error.message : String(error)}`);
|
|
7124
7890
|
}
|
|
7125
7891
|
}
|
|
@@ -7141,6 +7907,8 @@ var AMTGatewayManager = class {
|
|
|
7141
7907
|
} finally {
|
|
7142
7908
|
this.subscriptions.delete(handle);
|
|
7143
7909
|
this.pendingPackets.delete(subscription.subscriptionId);
|
|
7910
|
+
if (this.subscriptions.size === 0)
|
|
7911
|
+
this.removeMessageListener();
|
|
7144
7912
|
}
|
|
7145
7913
|
}
|
|
7146
7914
|
/**
|
|
@@ -7157,14 +7925,12 @@ var AMTGatewayManager = class {
|
|
|
7157
7925
|
if (!subscriptionId)
|
|
7158
7926
|
return;
|
|
7159
7927
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
7160
|
-
if (!subscription)
|
|
7161
|
-
console.warn(`[AMT] Received packet for unknown subscription: ${subscriptionId}`);
|
|
7928
|
+
if (!subscription)
|
|
7162
7929
|
return;
|
|
7163
|
-
}
|
|
7164
7930
|
if (!subscription.handshakeComplete) {
|
|
7165
7931
|
const queue = this.pendingPackets.get(subscriptionId);
|
|
7166
7932
|
const packetData2 = data;
|
|
7167
|
-
if (queue) {
|
|
7933
|
+
if (queue && queue.length < MAX_PENDING_PACKETS) {
|
|
7168
7934
|
queue.push({
|
|
7169
7935
|
data: packetData2.data,
|
|
7170
7936
|
remoteAddress: packetData2.remoteAddress,
|
|
@@ -7190,19 +7956,15 @@ var AMTGatewayManager = class {
|
|
|
7190
7956
|
if (!subscriptionId)
|
|
7191
7957
|
return;
|
|
7192
7958
|
const subscription = this.subscriptions.get(subscriptionId);
|
|
7193
|
-
if (!subscription)
|
|
7194
|
-
console.warn(`[AMT] Received error for unknown subscription: ${subscriptionId}`);
|
|
7959
|
+
if (!subscription)
|
|
7195
7960
|
return;
|
|
7196
|
-
}
|
|
7197
7961
|
subscription.config.onError(new Error(error || "Unknown error"));
|
|
7198
7962
|
}
|
|
7199
7963
|
/**
|
|
7200
7964
|
* Cleanup on destroy
|
|
7201
7965
|
*/
|
|
7202
7966
|
destroy() {
|
|
7203
|
-
|
|
7204
|
-
navigator.serviceWorker.removeEventListener("message", this.messageHandler);
|
|
7205
|
-
}
|
|
7967
|
+
this.removeMessageListener();
|
|
7206
7968
|
const handles = Array.from(this.subscriptions.keys());
|
|
7207
7969
|
for (const handle of handles) {
|
|
7208
7970
|
this.unsubscribe(handle).catch((err) => {
|
|
@@ -10261,9 +11023,10 @@ function isH264IntraSlice(nal) {
|
|
|
10261
11023
|
const sliceType = readH264SliceType(nal);
|
|
10262
11024
|
return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
|
|
10263
11025
|
}
|
|
11026
|
+
var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
|
|
10264
11027
|
function readH264SliceType(nal) {
|
|
10265
11028
|
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
10266
|
-
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
11029
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
|
|
10267
11030
|
const state = { bitOffset: 0 };
|
|
10268
11031
|
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
10269
11032
|
return readUnsignedExpGolomb(rbsp, state);
|
|
@@ -10410,6 +11173,96 @@ if (void 0) {
|
|
|
10410
11173
|
]))).toBe(false);
|
|
10411
11174
|
});
|
|
10412
11175
|
});
|
|
11176
|
+
describe("readH264SliceType", () => {
|
|
11177
|
+
const wholeNalSliceType = (nal) => {
|
|
11178
|
+
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
11179
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
11180
|
+
const state = { bitOffset: 0 };
|
|
11181
|
+
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
11182
|
+
return readUnsignedExpGolomb(rbsp, state);
|
|
11183
|
+
};
|
|
11184
|
+
const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
|
|
11185
|
+
const ue = (value) => {
|
|
11186
|
+
const code = (value + 1).toString(2);
|
|
11187
|
+
return "0".repeat(code.length - 1) + code;
|
|
11188
|
+
};
|
|
11189
|
+
const sliceNal = (bits) => {
|
|
11190
|
+
const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
|
|
11191
|
+
const nal = [1];
|
|
11192
|
+
let zeros = 0;
|
|
11193
|
+
for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
|
|
11194
|
+
if (zeros >= 2 && byte <= 3) {
|
|
11195
|
+
nal.push(3);
|
|
11196
|
+
zeros = 0;
|
|
11197
|
+
}
|
|
11198
|
+
nal.push(byte);
|
|
11199
|
+
zeros = byte === 0 ? zeros + 1 : 0;
|
|
11200
|
+
}
|
|
11201
|
+
return Uint8Array.from(nal);
|
|
11202
|
+
};
|
|
11203
|
+
const x264Slices = [
|
|
11204
|
+
["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
|
|
11205
|
+
["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
|
|
11206
|
+
["64x48 non-IDR I", hex2(
|
|
11207
|
+
"4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
|
|
11208
|
+
), 7, true],
|
|
11209
|
+
["1280x720 B, escape at byte 10", hex2(
|
|
11210
|
+
"01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
|
|
11211
|
+
), 6, false],
|
|
11212
|
+
["1280x720 P, escape at byte 15", hex2(
|
|
11213
|
+
"41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
|
|
11214
|
+
), 5, false],
|
|
11215
|
+
["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
|
|
11216
|
+
["7680x4320 IDR, first_mb_in_slice 97440", hex2(
|
|
11217
|
+
"650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
|
|
11218
|
+
), null, true],
|
|
11219
|
+
["7680x4320 P, first_mb_in_slice 32640", hex2(
|
|
11220
|
+
"410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
|
|
11221
|
+
), 5, false],
|
|
11222
|
+
["7680x4320 P, first_mb_in_slice 97440", hex2(
|
|
11223
|
+
"410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
|
|
11224
|
+
), 5, false]
|
|
11225
|
+
];
|
|
11226
|
+
const syntheticSlices = [
|
|
11227
|
+
["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
|
|
11228
|
+
["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
|
|
11229
|
+
["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
|
|
11230
|
+
["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
|
|
11231
|
+
["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
|
|
11232
|
+
["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
|
|
11233
|
+
["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
|
|
11234
|
+
["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
|
|
11235
|
+
];
|
|
11236
|
+
test("reads the slice_type of real and synthetic slices", () => {
|
|
11237
|
+
for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
|
|
11238
|
+
expect(readH264SliceType(nal), name).toBe(sliceType);
|
|
11239
|
+
}
|
|
11240
|
+
});
|
|
11241
|
+
test("matches the whole-NAL unescape at every truncation", () => {
|
|
11242
|
+
for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
|
|
11243
|
+
for (let end = 0; end <= nal.length; end++) {
|
|
11244
|
+
const cut = nal.subarray(0, end);
|
|
11245
|
+
expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
|
|
11246
|
+
}
|
|
11247
|
+
}
|
|
11248
|
+
});
|
|
11249
|
+
test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
|
|
11250
|
+
const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
|
|
11251
|
+
let seed = 1;
|
|
11252
|
+
const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
|
|
11253
|
+
for (let i = 0; i < 5e3; i++) {
|
|
11254
|
+
const nal = new Uint8Array(2 + next() % 63);
|
|
11255
|
+
nal[0] = 65;
|
|
11256
|
+
for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
|
|
11257
|
+
expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
|
|
11258
|
+
}
|
|
11259
|
+
});
|
|
11260
|
+
test("classifies the x264 slices as keyframes or not", () => {
|
|
11261
|
+
for (const [name, nal, , keyframe] of x264Slices) {
|
|
11262
|
+
expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
|
|
11263
|
+
}
|
|
11264
|
+
});
|
|
11265
|
+
});
|
|
10413
11266
|
describe("avccToAnnexB", () => {
|
|
10414
11267
|
test("converts with SPS/PPS on keyframe", () => {
|
|
10415
11268
|
const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
|
|
@@ -13111,9 +13964,21 @@ var IsoBmffTimingResolver = class {
|
|
|
13111
13964
|
}
|
|
13112
13965
|
#track = null;
|
|
13113
13966
|
#fragments = /* @__PURE__ */ new Map();
|
|
13967
|
+
/** First sample of each pending fragment, kept in `#delivered` with its sample count. */
|
|
13968
|
+
#firstSamples = /* @__PURE__ */ new Map();
|
|
13969
|
+
/**
|
|
13970
|
+
* First sample and sample count of the newest fragments whose every slot was
|
|
13971
|
+
* cleared. Abandonment counts: `releaseSample` clears a slot too, which
|
|
13972
|
+
* matches the combiner, since it retires an abandoned sample as well.
|
|
13973
|
+
*/
|
|
13974
|
+
#delivered = /* @__PURE__ */ new Map();
|
|
13114
13975
|
#pendingSamples = 0;
|
|
13115
13976
|
#evictedSamples = 0;
|
|
13116
13977
|
#lastMovieFragmentRejection = null;
|
|
13978
|
+
/** True once an FT=0 has bound the track that FT=1 timing is read against. */
|
|
13979
|
+
get initialized() {
|
|
13980
|
+
return this.#track !== null;
|
|
13981
|
+
}
|
|
13117
13982
|
get pendingSampleCount() {
|
|
13118
13983
|
return this.#pendingSamples;
|
|
13119
13984
|
}
|
|
@@ -13137,7 +14002,14 @@ var IsoBmffTimingResolver = class {
|
|
|
13137
14002
|
this.#track = timing;
|
|
13138
14003
|
return true;
|
|
13139
14004
|
}
|
|
13140
|
-
|
|
14005
|
+
/**
|
|
14006
|
+
* `recovered` marks an FEC-recovered copy. A recovered block hands back
|
|
14007
|
+
* every FT=1 it holds, the received ones included, so a recovered copy of a
|
|
14008
|
+
* fragment whose samples are all done is a duplicate: admitting it again
|
|
14009
|
+
* would charge stale timing and could displace the live MPU's. A source
|
|
14010
|
+
* copy is still admitted again (a rendition switch re-arms timing that way).
|
|
14011
|
+
*/
|
|
14012
|
+
addMovieFragment(mpuSequenceNumber, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
|
|
13141
14013
|
this.#lastMovieFragmentRejection = null;
|
|
13142
14014
|
if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
|
|
13143
14015
|
this.#lastMovieFragmentRejection = "invalid";
|
|
@@ -13163,6 +14035,8 @@ var IsoBmffTimingResolver = class {
|
|
|
13163
14035
|
(sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
|
|
13164
14036
|
);
|
|
13165
14037
|
}
|
|
14038
|
+
const delivered = recovered ? this.#delivered.get(key) : void 0;
|
|
14039
|
+
if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
|
|
13166
14040
|
let freed = 0;
|
|
13167
14041
|
while (this.#fragments.size > 0 && (this.#pendingSamples + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
|
|
13168
14042
|
freed += this.#evictOldestFragment();
|
|
@@ -13176,6 +14050,7 @@ var IsoBmffTimingResolver = class {
|
|
|
13176
14050
|
return false;
|
|
13177
14051
|
}
|
|
13178
14052
|
this.#fragments.set(key, [...parsed.samples]);
|
|
14053
|
+
this.#firstSamples.set(key, parsed.samples[0]);
|
|
13179
14054
|
this.#pendingSamples += parsed.samples.length;
|
|
13180
14055
|
return true;
|
|
13181
14056
|
}
|
|
@@ -13233,6 +14108,7 @@ var IsoBmffTimingResolver = class {
|
|
|
13233
14108
|
let live = 0;
|
|
13234
14109
|
for (const sample of samples) if (sample !== null) live++;
|
|
13235
14110
|
this.#fragments.delete(oldest);
|
|
14111
|
+
this.#firstSamples.delete(oldest);
|
|
13236
14112
|
this.#pendingSamples -= live;
|
|
13237
14113
|
this.#evictedSamples += live;
|
|
13238
14114
|
return live;
|
|
@@ -13248,12 +14124,23 @@ var IsoBmffTimingResolver = class {
|
|
|
13248
14124
|
if (!samples || !samples[index]) return false;
|
|
13249
14125
|
samples[index] = null;
|
|
13250
14126
|
this.#pendingSamples--;
|
|
13251
|
-
if (samples.every((value) => value === null))
|
|
14127
|
+
if (samples.every((value) => value === null)) {
|
|
14128
|
+
this.#fragments.delete(key);
|
|
14129
|
+
const first = this.#firstSamples.get(key);
|
|
14130
|
+
this.#firstSamples.delete(key);
|
|
14131
|
+
this.#delivered.delete(key);
|
|
14132
|
+
this.#delivered.set(key, { first, sampleCount: samples.length });
|
|
14133
|
+
if (this.#delivered.size > this.maxPendingSamples) {
|
|
14134
|
+
this.#delivered.delete(this.#delivered.keys().next().value);
|
|
14135
|
+
}
|
|
14136
|
+
}
|
|
13252
14137
|
return true;
|
|
13253
14138
|
}
|
|
13254
14139
|
reset() {
|
|
13255
14140
|
this.#track = null;
|
|
13256
14141
|
this.#fragments.clear();
|
|
14142
|
+
this.#firstSamples.clear();
|
|
14143
|
+
this.#delivered.clear();
|
|
13257
14144
|
this.#pendingSamples = 0;
|
|
13258
14145
|
}
|
|
13259
14146
|
};
|
|
@@ -13423,6 +14310,9 @@ function authoredGap(before, after) {
|
|
|
13423
14310
|
function ssIdAfter(a, b) {
|
|
13424
14311
|
return (a - b | 0) > 0;
|
|
13425
14312
|
}
|
|
14313
|
+
function holdsRebuilt(stream) {
|
|
14314
|
+
return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
|
|
14315
|
+
}
|
|
13426
14316
|
var FecReleaseSequencer = class {
|
|
13427
14317
|
#streams = /* @__PURE__ */ new Map();
|
|
13428
14318
|
#gate;
|
|
@@ -13485,6 +14375,7 @@ var FecReleaseSequencer = class {
|
|
|
13485
14375
|
stream.lastSbn = void 0;
|
|
13486
14376
|
stream.discontinuity = false;
|
|
13487
14377
|
stream.rapSsId = void 0;
|
|
14378
|
+
stream.sourced = false;
|
|
13488
14379
|
}
|
|
13489
14380
|
if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
|
|
13490
14381
|
this.#recordStat("droppedStale");
|
|
@@ -13511,6 +14402,7 @@ var FecReleaseSequencer = class {
|
|
|
13511
14402
|
if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
|
|
13512
14403
|
else hi = mid;
|
|
13513
14404
|
}
|
|
14405
|
+
if (stream.buf[lo]?.passed === true) frame.passed = true;
|
|
13514
14406
|
stream.buf.splice(lo, 0, frame);
|
|
13515
14407
|
this.#drainUnlessDeferred(stream);
|
|
13516
14408
|
}
|
|
@@ -13546,6 +14438,41 @@ var FecReleaseSequencer = class {
|
|
|
13546
14438
|
}
|
|
13547
14439
|
return false;
|
|
13548
14440
|
}
|
|
14441
|
+
/**
|
|
14442
|
+
* These streams' sink is being replaced by one that has seen no source
|
|
14443
|
+
* frame yet. First, from a stream that holds a frame the overlay rebuilt,
|
|
14444
|
+
* release to the sink being replaced the frames the unanchored path had
|
|
14445
|
+
* already released to it (#cursorPassed): there they waited in its queue,
|
|
14446
|
+
* which its replacement flushes. A stream that holds none is not drained:
|
|
14447
|
+
* it holds nothing the anchor kept back, and a drain would still force out
|
|
14448
|
+
* a frame held past the hold limit, which before the anchor waited for the
|
|
14449
|
+
* next push. Then treat the streams as unsourced until a source frame is
|
|
14450
|
+
* released.
|
|
14451
|
+
*/
|
|
14452
|
+
unsource(packetId, catalogTrackName) {
|
|
14453
|
+
for (const stream of this.#streams.values()) {
|
|
14454
|
+
if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
|
|
14455
|
+
if (stream.draining === 0 && holdsRebuilt(stream)) {
|
|
14456
|
+
if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
|
|
14457
|
+
else this.#drain(stream, true);
|
|
14458
|
+
}
|
|
14459
|
+
stream.sourced = false;
|
|
14460
|
+
}
|
|
14461
|
+
}
|
|
14462
|
+
}
|
|
14463
|
+
/**
|
|
14464
|
+
* Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
|
|
14465
|
+
* (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
|
|
14466
|
+
* packetId.
|
|
14467
|
+
*/
|
|
14468
|
+
holdsRebuilt(packetId, catalogTrackName) {
|
|
14469
|
+
for (const stream of this.#streams.values()) {
|
|
14470
|
+
if (stream.packetId !== packetId) continue;
|
|
14471
|
+
if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
|
|
14472
|
+
if (holdsRebuilt(stream)) return true;
|
|
14473
|
+
}
|
|
14474
|
+
return false;
|
|
14475
|
+
}
|
|
13549
14476
|
/** Re-evaluate held gaps after FEC state changed. */
|
|
13550
14477
|
poke(streamKey) {
|
|
13551
14478
|
if (streamKey !== void 0) {
|
|
@@ -13637,16 +14564,32 @@ var FecReleaseSequencer = class {
|
|
|
13637
14564
|
last: null,
|
|
13638
14565
|
lastSbn: void 0,
|
|
13639
14566
|
discontinuity: false,
|
|
13640
|
-
rapSsId: void 0
|
|
14567
|
+
rapSsId: void 0,
|
|
14568
|
+
sourced: false,
|
|
14569
|
+
draining: 0
|
|
13641
14570
|
};
|
|
13642
14571
|
this.#streams.set(streamKey, stream);
|
|
13643
14572
|
}
|
|
13644
14573
|
return stream;
|
|
13645
14574
|
}
|
|
13646
|
-
#
|
|
14575
|
+
/** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
|
|
14576
|
+
#drain(stream, asUnanchored = false) {
|
|
14577
|
+
stream.draining++;
|
|
14578
|
+
try {
|
|
14579
|
+
this.#drainLoop(stream, asUnanchored);
|
|
14580
|
+
} finally {
|
|
14581
|
+
stream.draining--;
|
|
14582
|
+
}
|
|
14583
|
+
}
|
|
14584
|
+
#drainLoop(stream, asUnanchored) {
|
|
13647
14585
|
while (stream.buf.length > 0 && stream.last !== null) {
|
|
13648
14586
|
const head = stream.buf[0];
|
|
13649
14587
|
const last = stream.last;
|
|
14588
|
+
if (compareFrameOrder(head, last) <= 0) {
|
|
14589
|
+
stream.buf.shift();
|
|
14590
|
+
this.#release(stream, head, void 0);
|
|
14591
|
+
continue;
|
|
14592
|
+
}
|
|
13650
14593
|
if (stream.discontinuity) {
|
|
13651
14594
|
stream.discontinuity = false;
|
|
13652
14595
|
stream.buf.shift();
|
|
@@ -13660,9 +14603,10 @@ var FecReleaseSequencer = class {
|
|
|
13660
14603
|
}
|
|
13661
14604
|
const headSbn = head.meta.fecSbn;
|
|
13662
14605
|
const from = stream.lastSbn ?? headSbn;
|
|
13663
|
-
const to = headSbn ?? stream.lastSbn;
|
|
14606
|
+
const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
|
|
13664
14607
|
let lost = [];
|
|
13665
14608
|
const unanchored = from === void 0 && to === void 0;
|
|
14609
|
+
let unresolved = false;
|
|
13666
14610
|
if (from !== void 0 && to !== void 0) {
|
|
13667
14611
|
const resolved = this.#gate.resolvedLoss(
|
|
13668
14612
|
stream.packetId,
|
|
@@ -13671,7 +14615,8 @@ var FecReleaseSequencer = class {
|
|
|
13671
14615
|
Math.max(from, to),
|
|
13672
14616
|
from
|
|
13673
14617
|
);
|
|
13674
|
-
|
|
14618
|
+
unresolved = resolved === null;
|
|
14619
|
+
if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
|
|
13675
14620
|
const heldMs = performance.now() - head.arrivedAtMs;
|
|
13676
14621
|
if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
|
|
13677
14622
|
this.#recordStat("forcedWindowFlushes");
|
|
@@ -13679,22 +14624,69 @@ var FecReleaseSequencer = class {
|
|
|
13679
14624
|
this.#release(stream, head, this.#gate.decide(last, head, [], true));
|
|
13680
14625
|
continue;
|
|
13681
14626
|
}
|
|
13682
|
-
lost = resolved;
|
|
14627
|
+
lost = resolved ?? [];
|
|
13683
14628
|
}
|
|
13684
14629
|
stream.buf.shift();
|
|
13685
14630
|
this.#release(
|
|
13686
14631
|
stream,
|
|
13687
14632
|
head,
|
|
13688
|
-
lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
14633
|
+
lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
13689
14634
|
);
|
|
13690
14635
|
}
|
|
13691
14636
|
}
|
|
14637
|
+
/**
|
|
14638
|
+
* The head has waited out a gap only a late source can still fill
|
|
14639
|
+
* (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
|
|
14640
|
+
* the stream when it has (`wakeAt`), since no packet may come by then.
|
|
14641
|
+
*/
|
|
14642
|
+
#unrepairableWaitOver(stream, last, head, from, to) {
|
|
14643
|
+
const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
|
|
14644
|
+
if (waitMs === void 0) return false;
|
|
14645
|
+
const atMs = head.arrivedAtMs + waitMs;
|
|
14646
|
+
if (performance.now() >= atMs) return true;
|
|
14647
|
+
this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
|
|
14648
|
+
return false;
|
|
14649
|
+
}
|
|
14650
|
+
/**
|
|
14651
|
+
* An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
|
|
14652
|
+
* source cursor holds it unanchored, and neither does a later frame behind
|
|
14653
|
+
* it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
|
|
14654
|
+
* fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
|
|
14655
|
+
* like each frame that arrived in front of it since (stale there). The head
|
|
14656
|
+
* then goes, decided as it would be unanchored, once a frame the base path
|
|
14657
|
+
* delivered (a source frame, or one base FEC recovered) is buffered after a
|
|
14658
|
+
* marked one: the base path has passed that one, so a frame still missing
|
|
14659
|
+
* before it can only come from a repair. It also goes while no source frame
|
|
14660
|
+
* has been released, when the direct path shows a recovered frame at once.
|
|
14661
|
+
* And it goes at once while a staged switch decides on when frames arrive
|
|
14662
|
+
* (FecReleaseGate.releaseUnanchored), and when unsource releases into a
|
|
14663
|
+
* sink being replaced: unanchored, it had already reached the sink.
|
|
14664
|
+
* The scan also writes: the `passed` marks it sets stay on the frames,
|
|
14665
|
+
* and push marks a frame it inserts in front of a marked one from them.
|
|
14666
|
+
*/
|
|
14667
|
+
#cursorPassed(stream, asUnanchored) {
|
|
14668
|
+
let at = -1;
|
|
14669
|
+
for (let i = 0; i < stream.buf.length; i++) {
|
|
14670
|
+
const frame = stream.buf[i];
|
|
14671
|
+
if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
|
|
14672
|
+
frame.passed = true;
|
|
14673
|
+
if (at < 0) at = i;
|
|
14674
|
+
} else if (frame.passed !== true) break;
|
|
14675
|
+
}
|
|
14676
|
+
if (at < 0) return false;
|
|
14677
|
+
return asUnanchored || !stream.sourced || this.#gate.releaseUnanchored?.(stream.packetId, stream.catalogTrackName) === true || stream.buf.some(({ meta }, i) => i > at && meta.fecSbnFirst === void 0 && (meta.recovered !== true || meta.fecSbn !== void 0));
|
|
14678
|
+
}
|
|
13692
14679
|
#release(stream, frame, decision) {
|
|
14680
|
+
const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
|
|
14681
|
+
if (stale) this.#recordStat("droppedStale");
|
|
13693
14682
|
if (decision) frame.meta.gapBefore = decision;
|
|
13694
14683
|
stream.last = frame;
|
|
13695
|
-
if (frame.meta.fecSbn !== void 0
|
|
14684
|
+
if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
|
|
14685
|
+
stream.lastSbn = frame.meta.fecSbn;
|
|
14686
|
+
}
|
|
14687
|
+
if (frame.meta.recovered !== true) stream.sourced = true;
|
|
13696
14688
|
this.#gate.onReleased?.(frame.data, frame.meta);
|
|
13697
|
-
this.#emit(frame.data, frame.meta);
|
|
14689
|
+
if (!stale) this.#emit(frame.data, frame.meta);
|
|
13698
14690
|
}
|
|
13699
14691
|
};
|
|
13700
14692
|
var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
|
|
@@ -13735,6 +14727,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
13735
14727
|
this.#reclaimedTimingSamples = 0;
|
|
13736
14728
|
this.#evictedTimingSamples = 0;
|
|
13737
14729
|
this.#rejectedMovieFragments = 0;
|
|
14730
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
14731
|
+
held: 0,
|
|
14732
|
+
expired: 0,
|
|
14733
|
+
discarded: 0,
|
|
14734
|
+
superseded: 0
|
|
14735
|
+
};
|
|
13738
14736
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
13739
14737
|
this.#fecGate = null;
|
|
13740
14738
|
this.#fecSequencer = null;
|
|
@@ -13843,6 +14841,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
13843
14841
|
#reclaimedTimingSamples;
|
|
13844
14842
|
#evictedTimingSamples;
|
|
13845
14843
|
#rejectedMovieFragments;
|
|
14844
|
+
#recoveredHeadsAwaitingTiming;
|
|
13846
14845
|
#sequencers;
|
|
13847
14846
|
#fecGate;
|
|
13848
14847
|
#fecSequencer;
|
|
@@ -13948,11 +14947,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
13948
14947
|
/**
|
|
13949
14948
|
* Typed view of the ISO-BMFF timing-sample budget.
|
|
13950
14949
|
*
|
|
13951
|
-
*
|
|
13952
|
-
*
|
|
13953
|
-
*
|
|
13954
|
-
*
|
|
13955
|
-
*
|
|
14950
|
+
* Each stream admits timing against its own window of `capacity` slots
|
|
14951
|
+
* (BLO-52085). A stream at capacity displaces its own oldest timing to
|
|
14952
|
+
* admit the moof in hand, and `evicted` counts the slots so displaced:
|
|
14953
|
+
* timing a stream declared and never delivered shows up there. `pending`
|
|
14954
|
+
* sums every stream, so it can exceed `capacity`. Per repo policy this is
|
|
14955
|
+
* a producer-owned counter -- never infer budget state by parsing logs.
|
|
13956
14956
|
*/
|
|
13957
14957
|
get timingBudgetStats() {
|
|
13958
14958
|
return {
|
|
@@ -13963,6 +14963,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
13963
14963
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
13964
14964
|
};
|
|
13965
14965
|
}
|
|
14966
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
14967
|
+
get recoveredHeadsAwaitingTiming() {
|
|
14968
|
+
let pending = 0;
|
|
14969
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
14970
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
14971
|
+
}
|
|
14972
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
14973
|
+
}
|
|
13966
14974
|
get reorderStats() {
|
|
13967
14975
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
13968
14976
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -14004,6 +15012,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14004
15012
|
fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
|
|
14005
15013
|
return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
|
|
14006
15014
|
}
|
|
15015
|
+
/** See FecReleaseSequencer.unsource. */
|
|
15016
|
+
unsourceFecRelease(packetId, catalogTrackName) {
|
|
15017
|
+
this.#fecSequencer?.unsource(packetId, catalogTrackName);
|
|
15018
|
+
}
|
|
15019
|
+
/** See FecReleaseSequencer.holdsRebuilt. */
|
|
15020
|
+
fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
|
|
15021
|
+
return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
|
|
15022
|
+
}
|
|
14007
15023
|
/** Re-evaluate held gaps after FEC block state changed. */
|
|
14008
15024
|
pokeFecRelease(packetId, catalogTrackName) {
|
|
14009
15025
|
if (!this.#fecSequencer) return;
|
|
@@ -14136,7 +15152,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14136
15152
|
const now = Date.now();
|
|
14137
15153
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
14138
15154
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
14139
|
-
awaitingTiming.shift();
|
|
15155
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
14140
15156
|
}
|
|
14141
15157
|
}
|
|
14142
15158
|
}
|
|
@@ -14254,11 +15270,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14254
15270
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
14255
15271
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
14256
15272
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
14257
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
15273
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
14258
15274
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
14259
15275
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
14260
|
-
const remaining = this.#maxPendingTimingSamples -
|
|
14261
|
-
const admitted = resolver2.addMovieFragment(
|
|
15276
|
+
const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
|
|
15277
|
+
const admitted = resolver2.addMovieFragment(
|
|
15278
|
+
mpu.mpuSequenceNumber,
|
|
15279
|
+
data,
|
|
15280
|
+
remaining,
|
|
15281
|
+
options?.recovered === true
|
|
15282
|
+
);
|
|
14262
15283
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
14263
15284
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
14264
15285
|
if (!admitted) {
|
|
@@ -14278,7 +15299,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14278
15299
|
};
|
|
14279
15300
|
}
|
|
14280
15301
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
14281
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
15302
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
14282
15303
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
14283
15304
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
14284
15305
|
return this.#drop("mfu-empty-payload");
|
|
@@ -14299,6 +15320,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14299
15320
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
14300
15321
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
14301
15322
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
15323
|
+
sequenceNumber: info.sequenceNumber,
|
|
14302
15324
|
arrivedAt: Date.now()
|
|
14303
15325
|
});
|
|
14304
15326
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -14324,7 +15346,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14324
15346
|
info,
|
|
14325
15347
|
resolver,
|
|
14326
15348
|
options?.recovered === true,
|
|
14327
|
-
options?.fecSbn
|
|
15349
|
+
options?.fecSbn,
|
|
15350
|
+
options?.fecSbnFirst
|
|
14328
15351
|
);
|
|
14329
15352
|
if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
|
|
14330
15353
|
}
|
|
@@ -14417,7 +15440,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14417
15440
|
info,
|
|
14418
15441
|
resolver,
|
|
14419
15442
|
options?.recovered === true,
|
|
14420
|
-
options?.fecSbn
|
|
15443
|
+
options?.fecSbn,
|
|
15444
|
+
options?.fecSbnFirst
|
|
14421
15445
|
);
|
|
14422
15446
|
if (outcome.record !== void 0) return outcome.record;
|
|
14423
15447
|
return this.#drop(outcome.reason);
|
|
@@ -14437,7 +15461,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14437
15461
|
* attribution exists to keep readable. Leaving the choice at the call site
|
|
14438
15462
|
* is what keeps both true.
|
|
14439
15463
|
*/
|
|
14440
|
-
#emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
|
|
15464
|
+
#emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
|
|
14441
15465
|
const timing = resolver.sampleTiming(
|
|
14442
15466
|
combined.mpuSequenceNumber,
|
|
14443
15467
|
combined.movieFragmentSequenceNumber,
|
|
@@ -14454,6 +15478,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14454
15478
|
);
|
|
14455
15479
|
if (!meta) return { reason: "combined-meta-build-failed" };
|
|
14456
15480
|
if (fecSbn !== void 0) meta.fecSbn = fecSbn;
|
|
15481
|
+
if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
|
|
14457
15482
|
if (!resolver.consumeSample(
|
|
14458
15483
|
combined.mpuSequenceNumber,
|
|
14459
15484
|
combined.movieFragmentSequenceNumber,
|
|
@@ -14622,6 +15647,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14622
15647
|
}
|
|
14623
15648
|
this.#emitFrame(data, meta);
|
|
14624
15649
|
}
|
|
15650
|
+
/** Whether FT=1 metadata already names this sample, without claiming it. */
|
|
15651
|
+
hasAuthoredTimingFor(packetId, mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber, catalogTrackName) {
|
|
15652
|
+
return this.#timingResolver(this.#streamKey(packetId, catalogTrackName), packetId, false)?.sampleTiming(mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber) != null;
|
|
15653
|
+
}
|
|
14625
15654
|
/**
|
|
14626
15655
|
* Claim and return the authored timing for a recovered sample. Recovery does
|
|
14627
15656
|
* not pass through the ordinary `feed()` completion path, so it must retire
|
|
@@ -14683,6 +15712,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14683
15712
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
14684
15713
|
this.#sequencers.clear();
|
|
14685
15714
|
this.#fecSequencer?.discard();
|
|
15715
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
15716
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
15717
|
+
}
|
|
14686
15718
|
this.#timingStreams.clear();
|
|
14687
15719
|
this.#pendingTimingSamples = 0;
|
|
14688
15720
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -14701,10 +15733,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14701
15733
|
return resolver;
|
|
14702
15734
|
}
|
|
14703
15735
|
#awaitTiming(streamKey, head) {
|
|
14704
|
-
const
|
|
14705
|
-
if (!
|
|
15736
|
+
const state = this.#timingStreams.get(streamKey);
|
|
15737
|
+
if (!state) return;
|
|
15738
|
+
if (!head.options?.recovered) {
|
|
15739
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
15740
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
15741
|
+
state.awaitingTiming = kept;
|
|
15742
|
+
}
|
|
15743
|
+
const awaitingTiming = state.awaitingTiming;
|
|
14706
15744
|
awaitingTiming.push(head);
|
|
14707
|
-
if (
|
|
15745
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
15746
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
15747
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
15748
|
+
}
|
|
15749
|
+
}
|
|
15750
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
15751
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
15752
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
14708
15753
|
}
|
|
14709
15754
|
/**
|
|
14710
15755
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -14732,6 +15777,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
14732
15777
|
const state = this.#timingStreams.get(streamKey);
|
|
14733
15778
|
if (!state) return;
|
|
14734
15779
|
this.#timingStreams.delete(streamKey);
|
|
15780
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
14735
15781
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
14736
15782
|
if (this.#pendingTimingSamples < 0) {
|
|
14737
15783
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|
|
@@ -17937,7 +18983,18 @@ function keyframeOverlaySsId(header) {
|
|
|
17937
18983
|
if (ext?.type !== KEYFRAME_OVERLAY_EXTENSION_TYPE || ext.data.length !== 4) return void 0;
|
|
17938
18984
|
return new DataView(ext.data.buffer, ext.data.byteOffset, 4).getUint32(0);
|
|
17939
18985
|
}
|
|
18986
|
+
function overlayBaseSsId(anchor, overlaySsId, restoredPsn, headerPsn) {
|
|
18987
|
+
if (anchor.baseSsId === void 0 || headerPsn !== restoredPsn) return void 0;
|
|
18988
|
+
return serial32Add(anchor.baseSsId, overlaySsId - anchor.overlaySsId | 0);
|
|
18989
|
+
}
|
|
18990
|
+
function unstampedBaseSsId(offset, unstampedOffset, headerPsn) {
|
|
18991
|
+
if (offset === void 0 || offset !== unstampedOffset) return void 0;
|
|
18992
|
+
return headerPsn + offset >>> 0;
|
|
18993
|
+
}
|
|
18994
|
+
var OVERLAY_ROUTED_LIMIT = 1024;
|
|
18995
|
+
var OVERLAY_PENDING_LIMIT = 256;
|
|
17940
18996
|
var OVERLAY_OFFSET_MPUS = 16;
|
|
18997
|
+
var OVERLAY_REBUILT_LIMIT = 256;
|
|
17941
18998
|
var OVERLAY_MOQ_HORIZON_BLOCKS = 64;
|
|
17942
18999
|
function assertStreamIdentity(role, stream) {
|
|
17943
19000
|
if (stream === void 0 || !Number.isInteger(stream.packetId) || stream.packetId <= MMTP_SIGNALING_PACKET_ID || typeof stream.catalogTrackName !== "string" || stream.catalogTrackName.length === 0) {
|
|
@@ -18048,6 +19105,7 @@ var MmtpRouter = class {
|
|
|
18048
19105
|
#provenance = /* @__PURE__ */ new Map();
|
|
18049
19106
|
#onFlowProtected = null;
|
|
18050
19107
|
#unadmittedListedDrops = 0;
|
|
19108
|
+
#admittedSourceDatagrams = 0;
|
|
18051
19109
|
#unlistedRepairSetAside = 0;
|
|
18052
19110
|
#assistBlocks = /* @__PURE__ */ new Map();
|
|
18053
19111
|
#assistFailures = /* @__PURE__ */ new Map();
|
|
@@ -18104,6 +19162,26 @@ var MmtpRouter = class {
|
|
|
18104
19162
|
* sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
|
|
18105
19163
|
*/
|
|
18106
19164
|
#ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19165
|
+
/**
|
|
19166
|
+
* Per stream, the SS_ID offset at which a base recovery last showed the
|
|
19167
|
+
* sender's own packet_sequence_number: a recovered packet's header psn
|
|
19168
|
+
* equal to its SS_ID minus that offset. While it equals the stream's
|
|
19169
|
+
* current offset, no hop re-stamps the stream, and a packet's protected psn
|
|
19170
|
+
* names its base SS_ID within unstampedBaseSsId's limits (joint decoding of
|
|
19171
|
+
* an MPU no member of which arrived).
|
|
19172
|
+
*/
|
|
19173
|
+
#unstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
19174
|
+
/**
|
|
19175
|
+
* The same, shown by the overlay alone, before any base recovery did: a
|
|
19176
|
+
* packet it rebuilt whose base copy carries its protected psn
|
|
19177
|
+
* (#feedOverlaySource), or whose protected psn passes overlayBaseSsId's
|
|
19178
|
+
* test at that offset (#routeOverlayRecovered). A base SS_ID placed by it
|
|
19179
|
+
* anchors the release gate only (BLO-52085 D3): fed to the base, it would
|
|
19180
|
+
* make the base drop a late base copy of a keyframe the overlay never
|
|
19181
|
+
* finished, and lift a block's late-source cut, which nothing before
|
|
19182
|
+
* this offset did.
|
|
19183
|
+
*/
|
|
19184
|
+
#overlayUnstampedSsIdSeqOffsetByStream = /* @__PURE__ */ new Map();
|
|
18107
19185
|
/**
|
|
18108
19186
|
* Streams whose multicast leg delivered a RAP-flagged source packet that was
|
|
18109
19187
|
* not parsed, typically because its overlap copy was parsed first
|
|
@@ -18149,6 +19227,8 @@ var MmtpRouter = class {
|
|
|
18149
19227
|
// end: a synchronous recovery completes its block BEFORE routing the
|
|
18150
19228
|
// recovered frames, and releasing a held gap in between would strand them.
|
|
18151
19229
|
#fecPokeDepth = 0;
|
|
19230
|
+
/** FecReleaseGate.wakeAt timers, by media stream key. */
|
|
19231
|
+
#fecWakes = /* @__PURE__ */ new Map();
|
|
18152
19232
|
#pendingFecPokes = /* @__PURE__ */ new Map();
|
|
18153
19233
|
// ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
|
|
18154
19234
|
/** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
|
|
@@ -18173,7 +19253,9 @@ var MmtpRouter = class {
|
|
|
18173
19253
|
recovered: 0,
|
|
18174
19254
|
restarts: 0,
|
|
18175
19255
|
unsequencedDropped: 0,
|
|
18176
|
-
protectedDropped: 0
|
|
19256
|
+
protectedDropped: 0,
|
|
19257
|
+
baseFed: 0,
|
|
19258
|
+
baseUndetermined: 0
|
|
18177
19259
|
};
|
|
18178
19260
|
/** Callback fired when a delta-track FEC block completes or fails. */
|
|
18179
19261
|
#onDeltaBlockCompleteCb = null;
|
|
@@ -18346,7 +19428,7 @@ var MmtpRouter = class {
|
|
|
18346
19428
|
const cb = this.#getFrameCallback(packetId);
|
|
18347
19429
|
if (isVideo && !assembler) {
|
|
18348
19430
|
if (frameMeta.recovered) {
|
|
18349
|
-
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb);
|
|
19431
|
+
this.#routeDirectRecoveredVideo(packetId, data, frameMeta, cb, meta.fecSbn);
|
|
18350
19432
|
} else {
|
|
18351
19433
|
this.#routeDirectSourceVideo(packetId, data, frameMeta, cb);
|
|
18352
19434
|
}
|
|
@@ -18379,13 +19461,18 @@ var MmtpRouter = class {
|
|
|
18379
19461
|
this.#onDeltaBlockCompleteCb?.(packetId, false);
|
|
18380
19462
|
}
|
|
18381
19463
|
};
|
|
18382
|
-
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass) => {
|
|
19464
|
+
this.#fecManager.onBlockFailed = (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
18383
19465
|
this.#mseAssemblerFor(packetId, catalogTrackName)?.failBlock(sbn);
|
|
18384
19466
|
if (this.#isCatalogTrackUnambiguous(packetId, catalogTrackName) && this.#packetIdRoles.get(packetId) === "delta") {
|
|
18385
19467
|
this.#onDeltaBlockCompleteCb?.(packetId, true);
|
|
18386
19468
|
}
|
|
18387
|
-
|
|
18388
|
-
|
|
19469
|
+
if (span === void 0) {
|
|
19470
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
19471
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass);
|
|
19472
|
+
} else {
|
|
19473
|
+
onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
19474
|
+
this.#onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span);
|
|
19475
|
+
}
|
|
18389
19476
|
};
|
|
18390
19477
|
}
|
|
18391
19478
|
}
|
|
@@ -18430,8 +19517,9 @@ var MmtpRouter = class {
|
|
|
18430
19517
|
}
|
|
18431
19518
|
/**
|
|
18432
19519
|
* FEC-recovered source symbols whose reconstructed header named a
|
|
18433
|
-
* packet_sequence_number other than the wire sequence their SS_ID maps to
|
|
18434
|
-
*
|
|
19520
|
+
* packet_sequence_number other than the wire sequence their SS_ID maps to,
|
|
19521
|
+
* or, rebuilt by the overlay, than their base copy carries: a hop
|
|
19522
|
+
* re-stamped the sequence after the sender protected the packet.
|
|
18435
19523
|
*/
|
|
18436
19524
|
get restampedRecoveredSequenceCount() {
|
|
18437
19525
|
return this.#restampedRecoveredSeqs;
|
|
@@ -18610,6 +19698,7 @@ var MmtpRouter = class {
|
|
|
18610
19698
|
enableMseAssembler(packetId, config, catalogTrackName) {
|
|
18611
19699
|
const assemblerKey = this.#mseAssemblerKey(packetId, catalogTrackName);
|
|
18612
19700
|
const previous = this.#mseAssemblers.get(assemblerKey);
|
|
19701
|
+
this.#parser.unsourceFecRelease(packetId, catalogTrackName);
|
|
18613
19702
|
if (previous) {
|
|
18614
19703
|
previous.flush();
|
|
18615
19704
|
previous.dispose();
|
|
@@ -18736,6 +19825,10 @@ var MmtpRouter = class {
|
|
|
18736
19825
|
get keyframeOverlayStats() {
|
|
18737
19826
|
return { ...this.#overlayStats };
|
|
18738
19827
|
}
|
|
19828
|
+
/** Recovered FT=2 heads held for their FT=1, and how each left the wait (BLO-53369). */
|
|
19829
|
+
get recoveredHeadsAwaitingTiming() {
|
|
19830
|
+
return this.#parser.recoveredHeadsAwaitingTiming;
|
|
19831
|
+
}
|
|
18739
19832
|
#isOverlayRepair(repairPacketId, repairTrackName) {
|
|
18740
19833
|
return this.#overlayLegs.has(repairPacketId) || repairTrackName !== void 0 && this.#overlayRepairNames.has(repairTrackName);
|
|
18741
19834
|
}
|
|
@@ -18756,7 +19849,8 @@ var MmtpRouter = class {
|
|
|
18756
19849
|
fec,
|
|
18757
19850
|
k,
|
|
18758
19851
|
offsets: /* @__PURE__ */ new Map(),
|
|
18759
|
-
moqBlocks: /* @__PURE__ */ new Set()
|
|
19852
|
+
moqBlocks: /* @__PURE__ */ new Set(),
|
|
19853
|
+
rebuilt: /* @__PURE__ */ new Map()
|
|
18760
19854
|
};
|
|
18761
19855
|
this.#overlays.set(repairPacketId, inst);
|
|
18762
19856
|
return () => {
|
|
@@ -18786,12 +19880,18 @@ var MmtpRouter = class {
|
|
|
18786
19880
|
*/
|
|
18787
19881
|
resetKeyframeOverlays(sourcePacketId, catalogTrackName) {
|
|
18788
19882
|
for (const inst of this.#overlaysForSource(sourcePacketId, catalogTrackName)) this.#resetOverlay(inst);
|
|
19883
|
+
for (const [name, stream] of this.#streams.get(sourcePacketId) ?? []) {
|
|
19884
|
+
if (catalogTrackName !== void 0 && name !== catalogTrackName) continue;
|
|
19885
|
+
stream.overlayToBase.routed.clear();
|
|
19886
|
+
stream.overlayToBase.pending.clear();
|
|
19887
|
+
}
|
|
18789
19888
|
}
|
|
18790
19889
|
#resetOverlay(inst) {
|
|
18791
19890
|
inst.fec.resetTrack(inst.repairPacketId, inst.streamName);
|
|
18792
19891
|
inst.last = void 0;
|
|
18793
19892
|
inst.offsets.clear();
|
|
18794
19893
|
inst.moqBlocks.clear();
|
|
19894
|
+
inst.rebuilt.clear();
|
|
18795
19895
|
}
|
|
18796
19896
|
#overlaysForSource(sourcePacketId, catalogTrackName) {
|
|
18797
19897
|
return [...this.#overlays.values()].filter(({ leg }) => leg.sourcePacketId === sourcePacketId && (catalogTrackName === void 0 || leg.sourceCatalogTrackName === void 0 || leg.sourceCatalogTrackName === catalogTrackName));
|
|
@@ -18842,18 +19942,33 @@ var MmtpRouter = class {
|
|
|
18842
19942
|
* A source packet that carries a 0x8B01 overlay SS_ID is also a symbol of
|
|
18843
19943
|
* every overlay installed for its source, at that SS_ID, with the bytes the
|
|
18844
19944
|
* base protects: the packet minus its 4-byte SS_ID trailer, extension
|
|
18845
|
-
* included (7.1, 7.4.3).
|
|
18846
|
-
|
|
18847
|
-
|
|
19945
|
+
* included (7.1, 7.4.3). `baseSsId` is that trailer's SS_ID, when the base
|
|
19946
|
+
* FEC reads it.
|
|
19947
|
+
*
|
|
19948
|
+
* The base copy of a packet an overlay rebuilt with no base SS_ID shows
|
|
19949
|
+
* what a base recovery of it would (#routeProcessedFecSymbols, BLO-52085):
|
|
19950
|
+
* its wire packet_sequence_number equal to the protected one rebuilt shows
|
|
19951
|
+
* the stream unstamped at the SS_ID offset it states, for the release gate
|
|
19952
|
+
* (#overlayUnstampedSsIdSeqOffsetByStream); any other shows a hop that
|
|
19953
|
+
* re-stamps it, which is counted (restampedRecoveredSequenceCount).
|
|
19954
|
+
*/
|
|
19955
|
+
#feedOverlaySource(packetId, catalogTrackName, packet, header, sequenceNumber, rapFlag, source, baseSsId) {
|
|
18848
19956
|
if (this.#overlays.size === 0) return;
|
|
18849
19957
|
const ssId = keyframeOverlaySsId(header);
|
|
18850
19958
|
if (ssId === void 0) return;
|
|
19959
|
+
let rebuiltPsn;
|
|
18851
19960
|
for (const inst of this.#overlaysForSource(packetId, catalogTrackName)) {
|
|
18852
19961
|
this.#noteOverlaySsId(inst, ssId, sequenceNumber);
|
|
19962
|
+
rebuiltPsn ??= inst.rebuilt.get(ssId);
|
|
19963
|
+
inst.rebuilt.delete(ssId);
|
|
18853
19964
|
const identity = MmtpContainerParser.sourcePacketIdentity(packet, header);
|
|
18854
19965
|
if (identity !== null) {
|
|
18855
19966
|
inst.offsets.delete(identity.mpuSequenceNumber);
|
|
18856
|
-
inst.offsets.set(identity.mpuSequenceNumber,
|
|
19967
|
+
inst.offsets.set(identity.mpuSequenceNumber, {
|
|
19968
|
+
psnOffset: ssId - sequenceNumber >>> 0,
|
|
19969
|
+
overlaySsId: ssId,
|
|
19970
|
+
...baseSsId === void 0 ? {} : { baseSsId }
|
|
19971
|
+
});
|
|
18857
19972
|
if (inst.offsets.size > OVERLAY_OFFSET_MPUS) inst.offsets.delete(inst.offsets.keys().next().value);
|
|
18858
19973
|
}
|
|
18859
19974
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -18875,6 +19990,14 @@ var MmtpRouter = class {
|
|
|
18875
19990
|
const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
|
|
18876
19991
|
if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, coords.sbn, recovered);
|
|
18877
19992
|
}
|
|
19993
|
+
if (rebuiltPsn === void 0 || this.#classifyPacketId(packetId) === null) return;
|
|
19994
|
+
const streamKey = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
19995
|
+
if (rebuiltPsn !== sequenceNumber) {
|
|
19996
|
+
this.#restampedRecoveredSeqs++;
|
|
19997
|
+
} else if (baseSsId !== void 0) {
|
|
19998
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
19999
|
+
if (offset === baseSsId - sequenceNumber >>> 0) this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
20000
|
+
}
|
|
18878
20001
|
}
|
|
18879
20002
|
#noteOverlayMoqBlock(inst, blockStart) {
|
|
18880
20003
|
inst.moqBlocks.add(blockStart);
|
|
@@ -18908,11 +20031,16 @@ var MmtpRouter = class {
|
|
|
18908
20031
|
}
|
|
18909
20032
|
/**
|
|
18910
20033
|
* Route an overlay-recovered block's packets as source media of the
|
|
18911
|
-
* overlay's source (7.2: an overlay coordinate yields no base SS_ID).
|
|
18912
|
-
*
|
|
18913
|
-
*
|
|
18914
|
-
*
|
|
18915
|
-
*
|
|
20034
|
+
* overlay's source (7.2: an overlay coordinate yields no base SS_ID). A
|
|
20035
|
+
* packet whose base SS_ID is determined independently (overlayBaseSsId,
|
|
20036
|
+
* unstampedBaseSsId) enters the release gate at that SS_ID, as a packet
|
|
20037
|
+
* base FEC recovered does, so it waits behind base frames still in flight,
|
|
20038
|
+
* though not for its own MPU's packets (FrameMeta.fecSbnFirst) and no
|
|
20039
|
+
* longer than unanchored; one whose base SS_ID is undetermined has no
|
|
20040
|
+
* release-gate anchor. No parse ledger, no base re-stamp, no block
|
|
20041
|
+
* advance. Each packet's wire sequence is restored from its keyframe's own
|
|
20042
|
+
* offset; without one, a stream the base never re-stamped keeps the
|
|
20043
|
+
* header's sequence and any other drops the packet.
|
|
18916
20044
|
*/
|
|
18917
20045
|
#routeOverlayRecovered(inst, blockStart, recovered) {
|
|
18918
20046
|
const { fec, repairPacketId: pid, streamName: name } = inst;
|
|
@@ -18932,22 +20060,139 @@ var MmtpRouter = class {
|
|
|
18932
20060
|
const streamKey = this.#mediaStreamKey(sourcePacketId, sourceName);
|
|
18933
20061
|
const restamped = this.#restampedStreams.has(streamKey);
|
|
18934
20062
|
const restored = /* @__PURE__ */ new Set();
|
|
20063
|
+
const baseSsIds = /* @__PURE__ */ new Map();
|
|
20064
|
+
const gateOnly = /* @__PURE__ */ new Set();
|
|
18935
20065
|
const symbols = result.symbols.flatMap((sym) => {
|
|
18936
|
-
const
|
|
18937
|
-
|
|
18938
|
-
|
|
20066
|
+
const overlaySsId = serial32Add(blockStart, sym.index);
|
|
20067
|
+
const anchor = inst.offsets.get(sym.fragment.mpuSequenceNumber);
|
|
20068
|
+
if (anchor !== void 0) {
|
|
20069
|
+
const packetSequenceNumber = overlaySsId - anchor.psnOffset >>> 0;
|
|
18939
20070
|
restored.add(packetSequenceNumber);
|
|
18940
|
-
|
|
20071
|
+
const out = { ...sym, packetSequenceNumber };
|
|
20072
|
+
const baseSsId = overlayBaseSsId(anchor, overlaySsId, packetSequenceNumber, sym.packetSequenceNumber);
|
|
20073
|
+
if (baseSsId !== void 0) {
|
|
20074
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
20075
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
20076
|
+
if (!this.#sourceSeqReceived(sourcePacketId, packetSequenceNumber, sourceName) && offset === baseSsId - packetSequenceNumber >>> 0) {
|
|
20077
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.set(streamKey, offset);
|
|
20078
|
+
}
|
|
20079
|
+
}
|
|
20080
|
+
return [out];
|
|
20081
|
+
}
|
|
20082
|
+
if (!restamped) {
|
|
20083
|
+
const offset = this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
20084
|
+
const fedSsId = unstampedBaseSsId(offset, this.#unstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
20085
|
+
const baseSsId = fedSsId ?? unstampedBaseSsId(offset, this.#overlayUnstampedSsIdSeqOffsetByStream.get(streamKey), sym.packetSequenceNumber);
|
|
20086
|
+
if (baseSsId !== void 0) {
|
|
20087
|
+
baseSsIds.set(sym.index, baseSsId);
|
|
20088
|
+
if (fedSsId === void 0) gateOnly.add(sym.index);
|
|
20089
|
+
} else {
|
|
20090
|
+
inst.rebuilt.set(overlaySsId, sym.packetSequenceNumber);
|
|
20091
|
+
if (inst.rebuilt.size > OVERLAY_REBUILT_LIMIT) inst.rebuilt.delete(inst.rebuilt.keys().next().value);
|
|
20092
|
+
}
|
|
20093
|
+
return [sym];
|
|
18941
20094
|
}
|
|
18942
|
-
if (!restamped) return [sym];
|
|
18943
20095
|
this.#overlayStats.unsequencedDropped++;
|
|
18944
20096
|
return [];
|
|
18945
20097
|
});
|
|
18946
20098
|
this.#overlayStats.recovered++;
|
|
20099
|
+
const mpuFirst = /* @__PURE__ */ new Map();
|
|
20100
|
+
for (const sym of symbols) {
|
|
20101
|
+
const ssId = baseSsIds.get(sym.index);
|
|
20102
|
+
const mpu = sym.fragment.mpuSequenceNumber;
|
|
20103
|
+
const first = mpuFirst.get(mpu);
|
|
20104
|
+
if (ssId !== void 0 && (first === void 0 || serial32Precedes(ssId, first))) mpuFirst.set(mpu, ssId);
|
|
20105
|
+
}
|
|
20106
|
+
const firstSsIds = /* @__PURE__ */ new Map();
|
|
20107
|
+
for (const sym of symbols) {
|
|
20108
|
+
if (baseSsIds.has(sym.index)) firstSsIds.set(sym.index, mpuFirst.get(sym.fragment.mpuSequenceNumber));
|
|
20109
|
+
}
|
|
18947
20110
|
this.#routeProcessedFecSymbols(blockStart, { ...result, symbols }, sourcePacketId, sourceName, {
|
|
18948
|
-
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast"
|
|
20111
|
+
deliveryProvenance: inst.moqBlocks.has(blockStart) ? "mixed" : "multicast",
|
|
20112
|
+
baseSsIds,
|
|
20113
|
+
firstSsIds
|
|
18949
20114
|
});
|
|
18950
20115
|
this.#noteOverlayRecoveredRaps(sourcePacketId, sourceName, streamKey, symbols.filter((sym) => restored.has(sym.packetSequenceNumber)));
|
|
20116
|
+
this.#feedOverlayRecoveredToBase(inst, blockStart, symbols, gateOnly.size === 0 ? baseSsIds : new Map([...baseSsIds].filter(([index]) => !gateOnly.has(index))));
|
|
20117
|
+
}
|
|
20118
|
+
/**
|
|
20119
|
+
* Joint decoding (BLO-52085). A packet the overlay rebuilt is a source of
|
|
20120
|
+
* its base block too, once its base SS_ID is determined (overlayBaseSsId,
|
|
20121
|
+
* from a received member of its MPU, else unstampedBaseSsId at an offset a
|
|
20122
|
+
* base recovery showed; `baseSsIds` holds no other),
|
|
20123
|
+
* so it is fed to the base decoder as a rebuilt source
|
|
20124
|
+
* (FECManager.feedRebuiltSourceSymbol): the base block has one erasure
|
|
20125
|
+
* fewer to solve, and its repair can recover the block's other packets.
|
|
20126
|
+
* A base block no repair has stated yet takes it when one does
|
|
20127
|
+
* (#feedPendingRebuilt).
|
|
20128
|
+
*
|
|
20129
|
+
* The overlay route already handled each packet fed (delivered it, or
|
|
20130
|
+
* held an untimed head for its FT=1), so a base recovery routes none of
|
|
20131
|
+
* them again (#routeVerifiedFecSymbols): a second recovered copy of a
|
|
20132
|
+
* held head would wait in the parser for timing its first copy consumed.
|
|
20133
|
+
* Only an overlay block decoded from multicast symbols alone is fed: with
|
|
20134
|
+
* a MoQ symbol in it, the base block's recovery would depend on bytes
|
|
20135
|
+
* that crossed no multicast socket, which the provenance counted from the
|
|
20136
|
+
* block's own arrivals cannot show.
|
|
20137
|
+
*/
|
|
20138
|
+
#feedOverlayRecoveredToBase(inst, blockStart, symbols, baseSsIds) {
|
|
20139
|
+
const fec = this.#fecManager;
|
|
20140
|
+
const owner = inst.leg.sourcePacketId;
|
|
20141
|
+
const name = inst.leg.sourceCatalogTrackName;
|
|
20142
|
+
if (!fec?.feedRebuiltSourceSymbol || inst.moqBlocks.has(blockStart)) return;
|
|
20143
|
+
if (this.#classifyPacketId(owner) === null || fec.isTrackConfigured?.(owner) === false) return;
|
|
20144
|
+
const { duplicates, overlayToBase: { routed } } = this.#stream(owner, name);
|
|
20145
|
+
const feeds = [];
|
|
20146
|
+
for (const sym of symbols) {
|
|
20147
|
+
if (duplicates.sourceSeqs.has(sym.packetSequenceNumber)) continue;
|
|
20148
|
+
const ssId = baseSsIds.get(sym.index);
|
|
20149
|
+
if (ssId === void 0) {
|
|
20150
|
+
this.#overlayStats.baseUndetermined++;
|
|
20151
|
+
continue;
|
|
20152
|
+
}
|
|
20153
|
+
routed.delete(ssId);
|
|
20154
|
+
routed.add(ssId);
|
|
20155
|
+
if (routed.size > OVERLAY_ROUTED_LIMIT) routed.delete(routed.values().next().value);
|
|
20156
|
+
feeds.push([ssId, sym.rawSymbol]);
|
|
20157
|
+
}
|
|
20158
|
+
for (const [ssId, symbolData] of feeds) {
|
|
20159
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
20160
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
20161
|
+
}
|
|
20162
|
+
}
|
|
20163
|
+
/** Feed one rebuilt source to its base block, or keep it until a repair states that block. */
|
|
20164
|
+
#feedRebuiltToBase(owner, name, ssId, symbolData) {
|
|
20165
|
+
const fec = this.#fecManager;
|
|
20166
|
+
if (!fec?.feedRebuiltSourceSymbol) return;
|
|
20167
|
+
const coords = fec.locateIsoSource?.(owner, name, ssId);
|
|
20168
|
+
if (coords == null) {
|
|
20169
|
+
const pending = this.#stream(owner, name).overlayToBase.pending;
|
|
20170
|
+
pending.delete(ssId);
|
|
20171
|
+
pending.set(ssId, symbolData.slice());
|
|
20172
|
+
if (pending.size > OVERLAY_PENDING_LIMIT) pending.delete(pending.keys().next().value);
|
|
20173
|
+
return;
|
|
20174
|
+
}
|
|
20175
|
+
const fed = fec.feedRebuiltSourceSymbol(owner, ssId, symbolData, name);
|
|
20176
|
+
if (!fed.taken) return;
|
|
20177
|
+
this.#overlayStats.baseFed++;
|
|
20178
|
+
if (fed.recovered === null) return;
|
|
20179
|
+
const sbn = coords.sbn;
|
|
20180
|
+
this.#routeRecoveredBlock(sbn, fed.recovered, owner, name, () => {
|
|
20181
|
+
fec.cancelBlockTimeout(sbn, owner, name);
|
|
20182
|
+
fec.countRecovery(owner, sbn, name);
|
|
20183
|
+
fec.markBlockCompleted(sbn, owner, name);
|
|
20184
|
+
});
|
|
20185
|
+
}
|
|
20186
|
+
/** A repair stated `block`: the rebuilt sources that waited for it join it now. */
|
|
20187
|
+
#feedPendingRebuilt(owner, name, block) {
|
|
20188
|
+
const pending = this.#streams.get(owner)?.get(name)?.overlayToBase.pending;
|
|
20189
|
+
if (pending === void 0 || pending.size === 0) return;
|
|
20190
|
+
for (const [ssId, symbolData] of [...pending]) {
|
|
20191
|
+
if (this.#classifyPacketId(owner) === null) return;
|
|
20192
|
+
if (serial32Distance(block.start, ssId) >= block.length) continue;
|
|
20193
|
+
pending.delete(ssId);
|
|
20194
|
+
this.#feedRebuiltToBase(owner, name, ssId, symbolData);
|
|
20195
|
+
}
|
|
18951
20196
|
}
|
|
18952
20197
|
/** fec-multicast-00 §6.6: report each base block whose RAP MFU fragments
|
|
18953
20198
|
* the overlay restored, when the keyframe's FT=0 and FT=1 are held too. A
|
|
@@ -19087,6 +20332,10 @@ var MmtpRouter = class {
|
|
|
19087
20332
|
get unadmittedListedDropCount() {
|
|
19088
20333
|
return this.#unadmittedListedDrops;
|
|
19089
20334
|
}
|
|
20335
|
+
/** Source datagrams (multicast or MoQ) a protected flow's bc-provenance v2 receiver released: admitted at once or held, then admitted by a record. Repair symbols and user-agent-admitted datagrams are not counted. Counted at release, before this router's own track checks: a released datagram those drop, which only a track change between hold and release can cause, still counts, so this is not a count of routed media. */
|
|
20336
|
+
get admittedSourceDatagramCount() {
|
|
20337
|
+
return this.#admittedSourceDatagrams;
|
|
20338
|
+
}
|
|
19090
20339
|
/** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
|
|
19091
20340
|
get unlistedRepairSetAsideCount() {
|
|
19092
20341
|
return this.#unlistedRepairSetAside;
|
|
@@ -19573,6 +20822,8 @@ var MmtpRouter = class {
|
|
|
19573
20822
|
)) return;
|
|
19574
20823
|
fec.noteBlockActivity?.(blockStart, ownerPacketId, catalogTrackName);
|
|
19575
20824
|
fec.noteRepairGroupLength?.(blockStart, ownerPacketId, repair.rsbLength, catalogTrackName);
|
|
20825
|
+
this.#feedPendingRebuilt(ownerPacketId, catalogTrackName, placement.block);
|
|
20826
|
+
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
19576
20827
|
const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
|
|
19577
20828
|
const recovered = fec.feedRepairSymbol(
|
|
19578
20829
|
ownerPacketId,
|
|
@@ -19623,7 +20874,7 @@ var MmtpRouter = class {
|
|
|
19623
20874
|
catalogTrackName
|
|
19624
20875
|
)) continue;
|
|
19625
20876
|
if (fec.isTrackConfigured?.(ownerPacketId) !== false) {
|
|
19626
|
-
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence);
|
|
20877
|
+
fec.trackBlock(blockStart, ownerPacketId, catalogTrackName, esi, payload.evidence, true);
|
|
19627
20878
|
this.#requestFecPoke(ownerPacketId, catalogTrackName);
|
|
19628
20879
|
}
|
|
19629
20880
|
if (payload.oversized) continue;
|
|
@@ -19710,6 +20961,8 @@ var MmtpRouter = class {
|
|
|
19710
20961
|
this.#droppedPreSyncVideo.delete(streamKey);
|
|
19711
20962
|
this.#latestVideoSeqByStream.delete(streamKey);
|
|
19712
20963
|
this.#ssIdSeqOffsetByStream.delete(streamKey);
|
|
20964
|
+
this.#unstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
20965
|
+
this.#overlayUnstampedSsIdSeqOffsetByStream.delete(streamKey);
|
|
19713
20966
|
this.#multicastRapTwinByStream.delete(streamKey);
|
|
19714
20967
|
this.#lastDirectSourceVideoTsByStream.delete(streamKey);
|
|
19715
20968
|
this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
|
|
@@ -19836,6 +21089,12 @@ var MmtpRouter = class {
|
|
|
19836
21089
|
* the outgoing stream stops. The hold is bounded by the incoming stream's
|
|
19837
21090
|
* own RAP cadence, so no timer is involved.
|
|
19838
21091
|
*
|
|
21092
|
+
* While the switch is staged, the FEC release gate lets a keyframe the
|
|
21093
|
+
* overlay rebuilt reach it, on either side, when the keyframe did before
|
|
21094
|
+
* the gate anchored it (FecReleaseGate.releaseUnanchored): the switch
|
|
21095
|
+
* decides on what each side delivered, and the commit discards the gate's
|
|
21096
|
+
* frames of the outgoing stream.
|
|
21097
|
+
*
|
|
19839
21098
|
* The commit is one synchronous transition inside the frame path: the
|
|
19840
21099
|
* outgoing stream's already-admitted frames are released (its queued FEC
|
|
19841
21100
|
* gap fills only up to the RAP, since recovery can queue a frame ahead of
|
|
@@ -19886,6 +21145,9 @@ var MmtpRouter = class {
|
|
|
19886
21145
|
droppedIncomingFrames: 0
|
|
19887
21146
|
};
|
|
19888
21147
|
this.#staged = state;
|
|
21148
|
+
if (this.#parser.fecReleaseHoldsRebuilt(from.packetId, from.catalogTrackName)) {
|
|
21149
|
+
this.#requestFecPoke(from.packetId, from.catalogTrackName);
|
|
21150
|
+
}
|
|
19889
21151
|
return {
|
|
19890
21152
|
cancel: () => {
|
|
19891
21153
|
if (this.#staged !== state) return false;
|
|
@@ -19968,7 +21230,17 @@ var MmtpRouter = class {
|
|
|
19968
21230
|
*/
|
|
19969
21231
|
#routeParsedFrame(data, meta) {
|
|
19970
21232
|
if (this.#classifyPacketId(meta.packetId) === null) return;
|
|
19971
|
-
if (this.#staged !== null
|
|
21233
|
+
if (this.#staged !== null) {
|
|
21234
|
+
let consumed = false;
|
|
21235
|
+
this.#fecPokeDepth++;
|
|
21236
|
+
try {
|
|
21237
|
+
consumed = this.#interceptSwitchFrame(data, meta);
|
|
21238
|
+
} finally {
|
|
21239
|
+
this.#fecPokeDepth--;
|
|
21240
|
+
this.#flushPendingFecPokes();
|
|
21241
|
+
}
|
|
21242
|
+
if (consumed) return;
|
|
21243
|
+
}
|
|
19972
21244
|
this.#deliverParsedFrame(data, meta);
|
|
19973
21245
|
}
|
|
19974
21246
|
#commitStreamSwitch(state, rap, reason) {
|
|
@@ -20017,6 +21289,8 @@ var MmtpRouter = class {
|
|
|
20017
21289
|
this.#disposed = true;
|
|
20018
21290
|
this.#staged = null;
|
|
20019
21291
|
this.cancelKeyframeLostTimer();
|
|
21292
|
+
for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
|
|
21293
|
+
this.#fecWakes.clear();
|
|
20020
21294
|
this.#parser.dispose();
|
|
20021
21295
|
this.#streams.clear();
|
|
20022
21296
|
this.#trackPacketCallbacks.clear();
|
|
@@ -20120,12 +21394,16 @@ var MmtpRouter = class {
|
|
|
20120
21394
|
this.#parser.deferFecRelease(work);
|
|
20121
21395
|
} finally {
|
|
20122
21396
|
this.#fecPokeDepth--;
|
|
20123
|
-
|
|
20124
|
-
|
|
20125
|
-
|
|
20126
|
-
|
|
20127
|
-
|
|
20128
|
-
|
|
21397
|
+
this.#flushPendingFecPokes();
|
|
21398
|
+
}
|
|
21399
|
+
}
|
|
21400
|
+
/** Run the pokes requested while #fecPokeDepth was raised, once it is 0. */
|
|
21401
|
+
#flushPendingFecPokes() {
|
|
21402
|
+
if (this.#fecPokeDepth === 0 && this.#pendingFecPokes.size > 0 && !this.#disposed) {
|
|
21403
|
+
const pokes = [...this.#pendingFecPokes.values()];
|
|
21404
|
+
this.#pendingFecPokes.clear();
|
|
21405
|
+
for (const poke of pokes) {
|
|
21406
|
+
this.#parser.pokeFecRelease(poke.packetId, poke.catalogTrackName);
|
|
20129
21407
|
}
|
|
20130
21408
|
}
|
|
20131
21409
|
}
|
|
@@ -20194,6 +21472,34 @@ var MmtpRouter = class {
|
|
|
20194
21472
|
if (!fec?.terminalRetentionMsForPacket) return Infinity;
|
|
20195
21473
|
return fec.terminalRetentionMsForPacket(packetId) ?? 0;
|
|
20196
21474
|
},
|
|
21475
|
+
// Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
|
|
21476
|
+
// late source can), its frame waits the late-symbol allowance when the
|
|
21477
|
+
// gap holds no RAP an installed keyframe overlay could still rebuild:
|
|
21478
|
+
// lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
|
|
21479
|
+
// that opens the next one while MPU boundaries bound RAPs (rap-next,
|
|
21480
|
+
// unless the gap holds a stated block's loss: the overlay may rebuild
|
|
21481
|
+
// that MPU's FT=0, and the block's group then complete it), or
|
|
21482
|
+
// an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
|
|
21483
|
+
// other rap-next, whose gap may hold a whole MPU and the keyframe the
|
|
21484
|
+
// overlay protects) waits for that overlay's repair too (BLO-52085
|
|
21485
|
+
// D4). A run no repair has delimited instead waits for its FEC
|
|
21486
|
+
// deadline, whatever the decision (FECManager.isoRepairlessWaitMs). The
|
|
21487
|
+
// FEC check comes first: most held gaps are not behind such a span, and
|
|
21488
|
+
// deciding one scans both frames' bitstreams.
|
|
21489
|
+
unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
|
|
21490
|
+
const fec = this.#fecManager;
|
|
21491
|
+
const { packetId, catalogTrackName } = after.meta;
|
|
21492
|
+
const arrivedAtMs = after.arrivedAtMs;
|
|
21493
|
+
const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, false, arrivedAtMs);
|
|
21494
|
+
if (!fec || allowanceMs === void 0) return void 0;
|
|
21495
|
+
const decision = this.#decideGap(before, after, [], false);
|
|
21496
|
+
const mpu = before.meta.mpuSequenceNumber;
|
|
21497
|
+
const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
|
|
21498
|
+
if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
|
|
21499
|
+
return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true, false, arrivedAtMs);
|
|
21500
|
+
}
|
|
21501
|
+
return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true, arrivedAtMs) : allowanceMs;
|
|
21502
|
+
},
|
|
20197
21503
|
decide: (before, after, lostBlocks, discontinuity) => {
|
|
20198
21504
|
const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
|
|
20199
21505
|
this.#onFrameGap?.(decision);
|
|
@@ -20203,6 +21509,28 @@ var MmtpRouter = class {
|
|
|
20203
21509
|
onRap: (packetId, catalogTrackName, ssId) => {
|
|
20204
21510
|
for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
|
|
20205
21511
|
},
|
|
21512
|
+
// One timer per stream, at the earliest wake asked: its drain re-arms
|
|
21513
|
+
// for the next frame still waiting.
|
|
21514
|
+
wakeAt: (packetId, catalogTrackName, atMs) => {
|
|
21515
|
+
if (this.#disposed) return;
|
|
21516
|
+
const key = this.#mediaStreamKey(packetId, catalogTrackName);
|
|
21517
|
+
const armed = this.#fecWakes.get(key);
|
|
21518
|
+
if (armed !== void 0 && armed.atMs <= atMs) return;
|
|
21519
|
+
if (armed !== void 0) clearTimeout(armed.timer);
|
|
21520
|
+
const timer = setTimeout(() => {
|
|
21521
|
+
this.#fecWakes.delete(key);
|
|
21522
|
+
this.#requestFecPoke(packetId, catalogTrackName);
|
|
21523
|
+
}, Math.max(0, Math.ceil(atMs - performance.now())));
|
|
21524
|
+
this.#fecWakes.set(key, { atMs, timer });
|
|
21525
|
+
},
|
|
21526
|
+
// A staged switch commits on when each side's frames reach it
|
|
21527
|
+
// (#interceptSwitchFrame): both sides' overlay keyframes reach it when
|
|
21528
|
+
// they did unanchored.
|
|
21529
|
+
releaseUnanchored: (packetId, catalogTrackName) => {
|
|
21530
|
+
const staged = this.#staged;
|
|
21531
|
+
const stream = { packetId, ...catalogTrackName === void 0 ? {} : { catalogTrackName } };
|
|
21532
|
+
return staged !== null && (isStream(stream, staged.from) || isStream(stream, staged.to));
|
|
21533
|
+
},
|
|
20206
21534
|
onReleased: (data, meta) => {
|
|
20207
21535
|
if (meta.trackType !== "video" || meta.mpuSequenceNumber === void 0) return;
|
|
20208
21536
|
const timing = meta.authoredTiming;
|
|
@@ -20212,7 +21540,8 @@ var MmtpRouter = class {
|
|
|
20212
21540
|
meta.catalogTrackName,
|
|
20213
21541
|
meta.mpuSequenceNumber,
|
|
20214
21542
|
timing.presentationTime,
|
|
20215
|
-
timing.mediaTimescale
|
|
21543
|
+
timing.mediaTimescale,
|
|
21544
|
+
timing.decodeTime
|
|
20216
21545
|
);
|
|
20217
21546
|
}
|
|
20218
21547
|
};
|
|
@@ -20230,8 +21559,20 @@ var MmtpRouter = class {
|
|
|
20230
21559
|
#decideGap(before, after, lostBlocks, discontinuity) {
|
|
20231
21560
|
const { packetId, catalogTrackName } = after.meta;
|
|
20232
21561
|
const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
|
|
20233
|
-
const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying";
|
|
20234
|
-
const
|
|
21562
|
+
const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" && before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
|
|
21563
|
+
const mpu = before.meta.mpuSequenceNumber;
|
|
21564
|
+
const sameMpu = trackKind === "video" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu;
|
|
21565
|
+
const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(
|
|
21566
|
+
packetId,
|
|
21567
|
+
catalogTrackName,
|
|
21568
|
+
sameMpu ? {
|
|
21569
|
+
mpu,
|
|
21570
|
+
from: before.meta.authoredTiming,
|
|
21571
|
+
to: after.meta.authoredTiming,
|
|
21572
|
+
fromSsId: before.meta.fecSbn,
|
|
21573
|
+
toSsId: after.meta.fecSbnFirst ?? after.meta.fecSbn
|
|
21574
|
+
} : void 0
|
|
21575
|
+
) === true;
|
|
20235
21576
|
const evidence = (frame) => {
|
|
20236
21577
|
const timing = frame.meta.authoredTiming;
|
|
20237
21578
|
const sampleNumber = frame.meta.sampleNumber;
|
|
@@ -20344,6 +21685,7 @@ var MmtpRouter = class {
|
|
|
20344
21685
|
const parsed = this.#parser.parsePacket(packet);
|
|
20345
21686
|
if (!parsed) return;
|
|
20346
21687
|
const info = parsed.info;
|
|
21688
|
+
if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
|
|
20347
21689
|
if (source === "multicast" && !manifestAdmitted) {
|
|
20348
21690
|
this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
|
|
20349
21691
|
}
|
|
@@ -20522,6 +21864,7 @@ var MmtpRouter = class {
|
|
|
20522
21864
|
evidence: sourceSymbolEvidence(packet, parsed.header, info.rapFlag, info.sequenceNumber),
|
|
20523
21865
|
oversized: !(this.#fecManager.isoSourceFits?.(info.packetId, rawSymbol.length) ?? false)
|
|
20524
21866
|
}) ?? false;
|
|
21867
|
+
if (held) this.#requestFecPoke(info.packetId, catalogTrackName);
|
|
20525
21868
|
parseSourceSymbol = held && !duplicates.parsedSymbols.has(ssId);
|
|
20526
21869
|
}
|
|
20527
21870
|
} else if (fecUnreadable && info.fecPayloadId) {
|
|
@@ -20625,7 +21968,8 @@ var MmtpRouter = class {
|
|
|
20625
21968
|
parsed.header,
|
|
20626
21969
|
info.sequenceNumber,
|
|
20627
21970
|
info.rapFlag,
|
|
20628
|
-
source
|
|
21971
|
+
source,
|
|
21972
|
+
fecPayloadId?.ssId
|
|
20629
21973
|
);
|
|
20630
21974
|
}
|
|
20631
21975
|
}
|
|
@@ -20651,7 +21995,8 @@ var MmtpRouter = class {
|
|
|
20651
21995
|
source: parserOptions?.source,
|
|
20652
21996
|
deliveryProvenance: parserOptions?.deliveryProvenance,
|
|
20653
21997
|
catalogTrackName: parserOptions?.catalogTrackName,
|
|
20654
|
-
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn }
|
|
21998
|
+
...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn },
|
|
21999
|
+
...parserOptions?.fecSbnFirst === void 0 ? {} : { fecSbnFirst: parserOptions.fecSbnFirst }
|
|
20655
22000
|
};
|
|
20656
22001
|
if (parsed) this.#parser.feedParsed(packet, parsed, feedOptions);
|
|
20657
22002
|
else this.#parser.feed(packet, feedOptions);
|
|
@@ -20775,7 +22120,8 @@ var MmtpRouter = class {
|
|
|
20775
22120
|
if (stream === void 0) {
|
|
20776
22121
|
stream = {
|
|
20777
22122
|
key: JSON.stringify([packetId, catalogTrackName ?? null]),
|
|
20778
|
-
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId))
|
|
22123
|
+
duplicates: new StreamDuplicateLedgers(() => this.duplicateHorizonFor(packetId)),
|
|
22124
|
+
overlayToBase: { routed: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Map() }
|
|
20779
22125
|
};
|
|
20780
22126
|
byName.set(catalogTrackName, stream);
|
|
20781
22127
|
}
|
|
@@ -20890,8 +22236,16 @@ var MmtpRouter = class {
|
|
|
20890
22236
|
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
20891
22237
|
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
20892
22238
|
}
|
|
20893
|
-
#routeDirectRecoveredVideo(packetId, data, meta, cb) {
|
|
22239
|
+
#routeDirectRecoveredVideo(packetId, data, meta, cb, fecSbn) {
|
|
20894
22240
|
const streamKey = this.#mediaStreamKey(packetId, meta.catalogTrackName);
|
|
22241
|
+
if (this.#isFecTrack(packetId)) {
|
|
22242
|
+
const high = this.#deliveredVideoHighWaterByStream.get(streamKey);
|
|
22243
|
+
if (fecSbn !== void 0 || high !== void 0 && authoredAdjacent(high, meta)) {
|
|
22244
|
+
this.#drainDirectRecoveredVideo(streamKey, packetId, (frame) => frame.timestamp <= meta.timestamp, cb);
|
|
22245
|
+
this.#emitDirectVideo(packetId, data, meta, cb);
|
|
22246
|
+
return;
|
|
22247
|
+
}
|
|
22248
|
+
}
|
|
20895
22249
|
this.#enqueueDirectRecoveredVideo(packetId, data, meta);
|
|
20896
22250
|
const lastSourceTs = this.#lastDirectSourceVideoTsByStream.get(streamKey);
|
|
20897
22251
|
this.#drainDirectRecoveredVideo(
|
|
@@ -21045,6 +22399,13 @@ var MmtpRouter = class {
|
|
|
21045
22399
|
* frames by epoch only if pre-protection input ever matters.
|
|
21046
22400
|
*/
|
|
21047
22401
|
#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete, assisted = false) {
|
|
22402
|
+
const overlayRouted = ownerPacketId == null ? void 0 : this.#streams.get(ownerPacketId)?.get(catalogTrackName)?.overlayToBase.routed;
|
|
22403
|
+
if (overlayRouted !== void 0 && overlayRouted.size > 0) {
|
|
22404
|
+
result = {
|
|
22405
|
+
...result,
|
|
22406
|
+
symbols: result.symbols.filter((sym) => !overlayRouted.has(this.#fecAnchorForRecovered(blockId, sym.index)))
|
|
22407
|
+
};
|
|
22408
|
+
}
|
|
21048
22409
|
const entry = ownerPacketId == null ? void 0 : this.#provenanceFor(ownerPacketId, catalogTrackName);
|
|
21049
22410
|
const receiver = entry === void 0 || entry === "ambiguous" ? entry : entry.receiver;
|
|
21050
22411
|
const userAgent = !assisted && entry !== void 0 && entry !== "ambiguous" && entry.protected === true && entry.userAgent === true;
|
|
@@ -21101,7 +22462,12 @@ var MmtpRouter = class {
|
|
|
21101
22462
|
#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, overlay) {
|
|
21102
22463
|
if (ownerPacketId == null) return;
|
|
21103
22464
|
if (this.#classifyPacketId(ownerPacketId) === null) return;
|
|
21104
|
-
const fecSbnOf = (index) =>
|
|
22465
|
+
const fecSbnOf = (index) => {
|
|
22466
|
+
if (!overlay) return { fecSbn: this.#fecAnchorForRecovered(blockId, index) };
|
|
22467
|
+
const fecSbn = overlay.baseSsIds.get(index);
|
|
22468
|
+
const fecSbnFirst = overlay.firstSsIds.get(index);
|
|
22469
|
+
return fecSbn === void 0 || fecSbnFirst === void 0 ? {} : { fecSbn, fecSbnFirst };
|
|
22470
|
+
};
|
|
21105
22471
|
const streamKey = this.#mediaStreamKey(ownerPacketId, catalogTrackName);
|
|
21106
22472
|
const ssIdSeqOffset = overlay ? void 0 : this.#ssIdSeqOffsetByStream.get(streamKey);
|
|
21107
22473
|
if (ssIdSeqOffset !== void 0) {
|
|
@@ -21109,7 +22475,10 @@ var MmtpRouter = class {
|
|
|
21109
22475
|
...result,
|
|
21110
22476
|
symbols: result.symbols.map((sym) => {
|
|
21111
22477
|
const wire = this.#fecAnchorForRecovered(blockId, sym.index) - ssIdSeqOffset >>> 0;
|
|
21112
|
-
if (wire === sym.packetSequenceNumber)
|
|
22478
|
+
if (wire === sym.packetSequenceNumber) {
|
|
22479
|
+
this.#unstampedSsIdSeqOffsetByStream.set(streamKey, ssIdSeqOffset);
|
|
22480
|
+
return sym;
|
|
22481
|
+
}
|
|
21113
22482
|
this.#restampedRecoveredSeqs++;
|
|
21114
22483
|
this.#restampedStreams.add(streamKey);
|
|
21115
22484
|
return { ...sym, packetSequenceNumber: wire };
|
|
@@ -21145,6 +22514,29 @@ var MmtpRouter = class {
|
|
|
21145
22514
|
}
|
|
21146
22515
|
);
|
|
21147
22516
|
}
|
|
22517
|
+
const untimedHead = (sym) => sym.fragmentType === 2 && sym.fragment.fragmentationIndicator === 1 && sym.fragment.movieFragmentSequenceNumber !== void 0 && sym.fragment.sampleNumber !== void 0 && !this.#parser.hasAuthoredTimingFor(
|
|
22518
|
+
ownerPacketId,
|
|
22519
|
+
sym.fragment.mpuSequenceNumber,
|
|
22520
|
+
sym.fragment.movieFragmentSequenceNumber,
|
|
22521
|
+
sym.fragment.sampleNumber,
|
|
22522
|
+
catalogTrackName
|
|
22523
|
+
);
|
|
22524
|
+
for (const sym of result.symbols) {
|
|
22525
|
+
if (!untimedHead(sym) || this.#sourceSeqReceived(ownerPacketId, sym.packetSequenceNumber, catalogTrackName)) continue;
|
|
22526
|
+
this.#feedViaParser(
|
|
22527
|
+
sym.rawSymbol,
|
|
22528
|
+
{ packetId: ownerPacketId, sequenceNumber: sym.packetSequenceNumber },
|
|
22529
|
+
void 0,
|
|
22530
|
+
{
|
|
22531
|
+
skipFecPayloadId: true,
|
|
22532
|
+
recovered: true,
|
|
22533
|
+
deliveryProvenance,
|
|
22534
|
+
...fecSbnOf(sym.index),
|
|
22535
|
+
...catalogTrackName === void 0 ? {} : { catalogTrackName }
|
|
22536
|
+
}
|
|
22537
|
+
);
|
|
22538
|
+
}
|
|
22539
|
+
result = { ...result, symbols: result.symbols.filter((sym) => !untimedHead(sym)) };
|
|
21148
22540
|
const gated = this.#isFecTrack(ownerPacketId);
|
|
21149
22541
|
const assembler = this.#mseAssemblerFor(ownerPacketId, catalogTrackName);
|
|
21150
22542
|
if (assembler) {
|
|
@@ -22515,6 +23907,7 @@ function newBlockPolicyStats(packetId, catalogTrackName, epoch) {
|
|
|
22515
23907
|
stalls: 0,
|
|
22516
23908
|
concealedBlocks: 0,
|
|
22517
23909
|
concealedGaps: 0,
|
|
23910
|
+
undelimitedRunGaps: 0,
|
|
22518
23911
|
concealedFrames: 0,
|
|
22519
23912
|
concealedAudioMs: 0,
|
|
22520
23913
|
vanishedBlocks: 0
|
|
@@ -22621,6 +24014,12 @@ function isNonNegativeSafeInteger(value) {
|
|
|
22621
24014
|
function isSymbolCounts(value) {
|
|
22622
24015
|
return isRecord(value) && hasExactKeys(value, ["multicast", "moq"]) && isNonNegativeSafeInteger(value["multicast"]) && isNonNegativeSafeInteger(value["moq"]);
|
|
22623
24016
|
}
|
|
24017
|
+
function isSpanFailure(value) {
|
|
24018
|
+
if (!isRecord(value) || !hasExactKeys(value, ["length", "sources"])) return false;
|
|
24019
|
+
const length = value["length"];
|
|
24020
|
+
const sources = value["sources"];
|
|
24021
|
+
return Number.isSafeInteger(length) && length > 0 && isNonNegativeSafeInteger(sources) && sources < length;
|
|
24022
|
+
}
|
|
22624
24023
|
function isNullableNonNegative(value) {
|
|
22625
24024
|
return value === null || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
22626
24025
|
}
|
|
@@ -22640,7 +24039,10 @@ function isRepairLifecycleEvent(value) {
|
|
|
22640
24039
|
case "recovered":
|
|
22641
24040
|
return hasExactKeys(value, ["version", "type", "block", "blockClass", "via", "symbols"]) && isRepairBlockIdentity(block) && BLOCK_CLASSES.has(value["blockClass"]) && (value["via"] === "inband" || value["via"] === "quic") && isSymbolCounts(value["symbols"]);
|
|
22642
24041
|
case "failed":
|
|
22643
|
-
return hasExactKeys(
|
|
24042
|
+
return hasExactKeys(
|
|
24043
|
+
value,
|
|
24044
|
+
"span" in value ? ["version", "type", "block", "blockClass", "symbols", "span"] : ["version", "type", "block", "blockClass", "symbols"]
|
|
24045
|
+
) && isRepairBlockIdentity(block) && BLOCK_CLASSES.has(value["blockClass"]) && isSymbolCounts(value["symbols"]) && (!("span" in value) || isSpanFailure(value["span"]));
|
|
22644
24046
|
case "repair-preempted":
|
|
22645
24047
|
case "repair-deferred":
|
|
22646
24048
|
return hasExactKeys(value, ["version", "type", "block"]) && isRepairBlockIdentity(block);
|
|
@@ -22849,6 +24251,8 @@ var MulticastManager = class {
|
|
|
22849
24251
|
/** Live joinRepairEndpoints() releases → the repair owners they registered,
|
|
22850
24252
|
* re-applied after configureMultiTrack() clears catalog-derived owners. */
|
|
22851
24253
|
#repairReleases = /* @__PURE__ */ new Map();
|
|
24254
|
+
/** Protected repair flows owned by each live repair-endpoint release. */
|
|
24255
|
+
#repairProvenanceFlows = /* @__PURE__ */ new Map();
|
|
22852
24256
|
/** Each source's catalog keyframe overlay, from its `ok` binding. */
|
|
22853
24257
|
#overlayBindings = /* @__PURE__ */ new Map();
|
|
22854
24258
|
/** Installed overlay decoders (`setKeyframeOverlayDecoder`), by source. */
|
|
@@ -22906,7 +24310,7 @@ var MulticastManager = class {
|
|
|
22906
24310
|
onPublisherRestart: (packetId, catalogTrackName) => {
|
|
22907
24311
|
this.#resetStreamOutsideRouter(packetId, catalogTrackName);
|
|
22908
24312
|
},
|
|
22909
|
-
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass) => {
|
|
24313
|
+
onBlockFailed: (sbn, packetId, catalogTrackName, blockClass, span) => {
|
|
22910
24314
|
const pathCount = this.#fec.blockPathCount(
|
|
22911
24315
|
sbn,
|
|
22912
24316
|
packetId,
|
|
@@ -22924,7 +24328,8 @@ var MulticastManager = class {
|
|
|
22924
24328
|
symbols: {
|
|
22925
24329
|
multicast: pathCount?.multicastSymbols ?? 0,
|
|
22926
24330
|
moq: pathCount?.moqSymbols ?? 0
|
|
22927
|
-
}
|
|
24331
|
+
},
|
|
24332
|
+
...span === void 0 ? {} : { span }
|
|
22928
24333
|
});
|
|
22929
24334
|
},
|
|
22930
24335
|
onFrameGap: (decision) => {
|
|
@@ -23009,9 +24414,17 @@ var MulticastManager = class {
|
|
|
23009
24414
|
reason
|
|
23010
24415
|
});
|
|
23011
24416
|
};
|
|
24417
|
+
this.#fec.onUndelimitedRunGap = (packetId, catalogTrackName) => {
|
|
24418
|
+
this.#statsFor(packetId, catalogTrackName).undelimitedRunGaps++;
|
|
24419
|
+
};
|
|
23012
24420
|
this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
|
|
23013
24421
|
this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
|
|
23014
24422
|
};
|
|
24423
|
+
this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
|
|
24424
|
+
const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
|
|
24425
|
+
if (binding === void 0) return void 0;
|
|
24426
|
+
return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
|
|
24427
|
+
};
|
|
23015
24428
|
this.#fec.onDecoderUnavailable = (event) => {
|
|
23016
24429
|
this.#emitRepairLifecycle({
|
|
23017
24430
|
version: 2,
|
|
@@ -23514,6 +24927,9 @@ var MulticastManager = class {
|
|
|
23514
24927
|
this.#transport.onFailback((reason) => {
|
|
23515
24928
|
const joined = this.#provenanceJoin;
|
|
23516
24929
|
if (joined !== null) this.#router.unprotectProvenanceFlow(joined.flow);
|
|
24930
|
+
for (const flows of this.#repairProvenanceFlows.values()) {
|
|
24931
|
+
for (const flow of flows) this.#router.unprotectProvenanceFlow(flow);
|
|
24932
|
+
}
|
|
23517
24933
|
this.#onFailback?.(reason);
|
|
23518
24934
|
});
|
|
23519
24935
|
}
|
|
@@ -23548,6 +24964,12 @@ var MulticastManager = class {
|
|
|
23548
24964
|
"[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port"
|
|
23549
24965
|
);
|
|
23550
24966
|
}
|
|
24967
|
+
if (provenanceFlow !== void 0) {
|
|
24968
|
+
const flow = multicastProvenanceFlowKey(provenanceFlow);
|
|
24969
|
+
if ([...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
24970
|
+
throw new TypeError(`[MulticastManager] join: provenance flow already registered by a repair endpoint: ${flow}`);
|
|
24971
|
+
}
|
|
24972
|
+
}
|
|
23551
24973
|
const staged = this.#renditionSwitch;
|
|
23552
24974
|
if (staged !== null) this.#endRenditionSwitch(staged, { reason: "superseded" }, false);
|
|
23553
24975
|
this.configureFec(config);
|
|
@@ -23555,8 +24977,8 @@ var MulticastManager = class {
|
|
|
23555
24977
|
const selectedPacketIds = config.packetIds?.length ? new Set(config.packetIds) : null;
|
|
23556
24978
|
const catalogTracks = config.tracks?.filter(({ packetId }) => selectedPacketIds === null || selectedPacketIds.has(packetId));
|
|
23557
24979
|
const ingressTracks = catalogTracks ? catalogTracks : selectedPacketIds === null ? void 0 : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
|
|
23558
|
-
this.#releaseProvenanceJoin();
|
|
23559
24980
|
const provenance = config.provenance;
|
|
24981
|
+
this.#releaseProvenanceJoin();
|
|
23560
24982
|
const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
|
|
23561
24983
|
const ingress = protectedTracks === void 0 ? void 0 : {
|
|
23562
24984
|
tracks: Object.freeze(
|
|
@@ -23609,8 +25031,13 @@ var MulticastManager = class {
|
|
|
23609
25031
|
* feeds the flow's receiver; media datagrams are held until one admits them.
|
|
23610
25032
|
*/
|
|
23611
25033
|
#joinProvenance(provenance, ingress) {
|
|
25034
|
+
this.#router.registerProvenanceFlow(ingress, this.#provenanceReceiver(provenance));
|
|
25035
|
+
this.#hookFailback();
|
|
25036
|
+
this.#provenanceJoin = { flow: ingress.flow };
|
|
25037
|
+
}
|
|
25038
|
+
#provenanceReceiver(provenance) {
|
|
23612
25039
|
const { flow, auth } = provenance;
|
|
23613
|
-
|
|
25040
|
+
return new BcProvenanceV2Receiver({
|
|
23614
25041
|
...provenance.receiver,
|
|
23615
25042
|
// The caller's ctx when it passes one, else the catalog's: an explicit
|
|
23616
25043
|
// `catalogCtx: undefined` must not switch off the 7.2.4 ctx check.
|
|
@@ -23627,9 +25054,6 @@ var MulticastManager = class {
|
|
|
23627
25054
|
maxAuthDelayMs: flow.maxAuthDelayMs,
|
|
23628
25055
|
manifestTimerMs: flow.manifestTimerMs
|
|
23629
25056
|
});
|
|
23630
|
-
this.#router.registerProvenanceFlow(ingress, receiver);
|
|
23631
|
-
this.#hookFailback();
|
|
23632
|
-
this.#provenanceJoin = { flow: ingress.flow };
|
|
23633
25057
|
}
|
|
23634
25058
|
/** Un-protect: drop the flow's hold queues (no expiry counted). */
|
|
23635
25059
|
#releaseProvenanceJoin() {
|
|
@@ -23660,8 +25084,25 @@ var MulticastManager = class {
|
|
|
23660
25084
|
* callback delivers must come from a subscription opened on
|
|
23661
25085
|
* `options.gateway`. A callback that also merges another source (a MoQ or
|
|
23662
25086
|
* WebSocket repair feed) must not name a native provider here.
|
|
25087
|
+
*
|
|
25088
|
+
* An endpoint's `provenance` makes its group a protected flow of its own
|
|
25089
|
+
* (multicast-02 7.2.7), registered here and released with the group; its
|
|
25090
|
+
* records ride in band on the group's port. On the user-agent path a
|
|
25091
|
+
* flow-less repair group of a protected track is set aside, never read, so
|
|
25092
|
+
* a player joining a protected catalog's repair groups passes it.
|
|
23663
25093
|
*/
|
|
23664
25094
|
joinRepairEndpoints(endpoints, provider, options) {
|
|
25095
|
+
for (const { provenance, flow, source, group, port } of endpoints) {
|
|
25096
|
+
if (provenance === void 0) continue;
|
|
25097
|
+
if (flow !== void 0) {
|
|
25098
|
+
throw new TypeError("[MulticastManager] joinRepairEndpoints: an endpoint names provenance or flow, never both");
|
|
25099
|
+
}
|
|
25100
|
+
if (!sameIpAddress(source, provenance.flow.source) || !sameIpAddress(group, provenance.flow.groupAddress) || port !== provenance.flow.port) {
|
|
25101
|
+
throw new RangeError(
|
|
25102
|
+
"[MulticastManager] joinRepairEndpoints: provenance flow (S, G, port) must match the endpoint's source, group and port"
|
|
25103
|
+
);
|
|
25104
|
+
}
|
|
25105
|
+
}
|
|
23665
25106
|
const releases = [];
|
|
23666
25107
|
let released = false;
|
|
23667
25108
|
const safely = (each) => {
|
|
@@ -23671,17 +25112,36 @@ var MulticastManager = class {
|
|
|
23671
25112
|
console.warn("[MulticastManager] repair group release failed", error);
|
|
23672
25113
|
}
|
|
23673
25114
|
};
|
|
25115
|
+
const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
|
|
25116
|
+
const preparedProvenance = endpoints.map((endpoint) => {
|
|
25117
|
+
if (endpoint.provenance === void 0) return void 0;
|
|
25118
|
+
const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
25119
|
+
if (usedFlows.has(flow) || this.#provenanceJoin?.flow === flow || [...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
|
|
25120
|
+
throw new TypeError(`[MulticastManager] joinRepairEndpoints: provenance flow already registered: ${flow}`);
|
|
25121
|
+
}
|
|
25122
|
+
usedFlows.add(flow);
|
|
25123
|
+
return { flow, receiver: this.#provenanceReceiver(endpoint.provenance) };
|
|
25124
|
+
});
|
|
25125
|
+
const provenanceFlows = [];
|
|
23674
25126
|
const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners.map((owner) => owner.instance !== "keyframe" ? owner : {
|
|
23675
25127
|
...owner,
|
|
23676
25128
|
ownerTrackName: endpoint.tracks.find((t) => t.packetId === owner.ownerPacketId)?.name,
|
|
23677
25129
|
repairTrackName: endpoint.tracks.find((t) => t.packetId === owner.packetId)?.name
|
|
23678
25130
|
}));
|
|
23679
25131
|
this.#applyRepairOwners(repairOwners);
|
|
23680
|
-
for (const endpoint of endpoints) {
|
|
25132
|
+
for (const [index, endpoint] of endpoints.entries()) {
|
|
25133
|
+
const flow = endpoint.provenance === void 0 ? endpoint.flow : multicastProvenanceFlowKey(endpoint.provenance.flow);
|
|
23681
25134
|
const ingress = {
|
|
23682
25135
|
tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
|
|
23683
|
-
...
|
|
25136
|
+
...flow === void 0 ? {} : { flow }
|
|
23684
25137
|
};
|
|
25138
|
+
if (endpoint.provenance !== void 0) {
|
|
25139
|
+
const prepared = preparedProvenance[index];
|
|
25140
|
+
if (prepared === void 0) throw new Error("[MulticastManager] repair provenance preparation missing");
|
|
25141
|
+
this.#router.registerProvenanceFlow(ingress, prepared.receiver);
|
|
25142
|
+
provenanceFlows.push(prepared.flow);
|
|
25143
|
+
releases.push(() => this.#router.releaseProvenanceFlow(flow));
|
|
25144
|
+
}
|
|
23685
25145
|
let sender;
|
|
23686
25146
|
const feed = (packet, sourceAddress, ingressToFeed) => {
|
|
23687
25147
|
if (released) return;
|
|
@@ -23711,7 +25171,7 @@ var MulticastManager = class {
|
|
|
23711
25171
|
packetIds: endpoint.packetIds,
|
|
23712
25172
|
tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
|
|
23713
25173
|
// A protected repair group's records ride in band on its port (7.2.3).
|
|
23714
|
-
...
|
|
25174
|
+
...flow === void 0 ? {} : { protected: true }
|
|
23715
25175
|
}, ingress).then((joined) => {
|
|
23716
25176
|
if (!joined && !released) fail(transport.lastJoinOutcome);
|
|
23717
25177
|
});
|
|
@@ -23720,9 +25180,12 @@ var MulticastManager = class {
|
|
|
23720
25180
|
if (released) return;
|
|
23721
25181
|
released = true;
|
|
23722
25182
|
this.#repairReleases.delete(release);
|
|
25183
|
+
this.#repairProvenanceFlows.delete(release);
|
|
23723
25184
|
for (const each of releases.splice(0)) safely(each);
|
|
23724
25185
|
};
|
|
23725
25186
|
this.#repairReleases.set(release, repairOwners);
|
|
25187
|
+
this.#repairProvenanceFlows.set(release, provenanceFlows);
|
|
25188
|
+
if (provenanceFlows.length) this.#hookFailback();
|
|
23726
25189
|
return release;
|
|
23727
25190
|
}
|
|
23728
25191
|
#applyRepairOwners(owners) {
|
|
@@ -24208,7 +25671,8 @@ var MulticastManager = class {
|
|
|
24208
25671
|
blockProfile: parseFecBlockProfile(
|
|
24209
25672
|
geometry2.blockProfile,
|
|
24210
25673
|
`tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
|
|
24211
|
-
)
|
|
25674
|
+
),
|
|
25675
|
+
geometry: geometry2
|
|
24212
25676
|
});
|
|
24213
25677
|
}
|
|
24214
25678
|
}
|
|
@@ -24247,7 +25711,7 @@ var MulticastManager = class {
|
|
|
24247
25711
|
for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
|
|
24248
25712
|
const before = this.#overlayBindings.get(sourcePacketId);
|
|
24249
25713
|
const after = overlayBindings.get(sourcePacketId);
|
|
24250
|
-
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
|
|
25714
|
+
const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
|
|
24251
25715
|
if (!same) install.dispose();
|
|
24252
25716
|
else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
|
|
24253
25717
|
else install.reattach();
|
|
@@ -24304,10 +25768,12 @@ var MulticastManager = class {
|
|
|
24304
25768
|
* Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
|
|
24305
25769
|
* on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
|
|
24306
25770
|
* pending hole and reported here, and `closeIsoHoles` must be called for it
|
|
24307
|
-
* once its range FETCH ends (or none is sent).
|
|
25771
|
+
* once its range FETCH ends (or none is sent). `onExpired` is told of a
|
|
25772
|
+
* pending hole the stream runs past the locator's horizon: returning true,
|
|
25773
|
+
* the caller closes it (`closeIsoHoles`); otherwise it is discarded.
|
|
24308
25774
|
*/
|
|
24309
|
-
onUndelimitedLoss(cb) {
|
|
24310
|
-
this.#fec.setUndelimitedLossHandler(cb);
|
|
25775
|
+
onUndelimitedLoss(cb, onExpired) {
|
|
25776
|
+
this.#fec.setUndelimitedLossHandler(cb, onExpired ?? null);
|
|
24311
25777
|
}
|
|
24312
25778
|
/**
|
|
24313
25779
|
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), e.g.
|
|
@@ -24543,7 +26009,8 @@ var MulticastManager = class {
|
|
|
24543
26009
|
"stream" in event ? { ...event, stream: Object.freeze({ ...event.stream }) } : {
|
|
24544
26010
|
...event,
|
|
24545
26011
|
block: Object.freeze({ ...event.block }),
|
|
24546
|
-
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {}
|
|
26012
|
+
..."symbols" in event ? { symbols: Object.freeze({ ...event.symbols }) } : {},
|
|
26013
|
+
..."span" in event && event.span !== void 0 ? { span: Object.freeze({ ...event.span }) } : {}
|
|
24547
26014
|
}
|
|
24548
26015
|
);
|
|
24549
26016
|
if (this.#logRepairLifecycle) {
|