@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbd83cb48eff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/browser-runtime.js +532 -333
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +5 -3
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +18 -5
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +5 -2
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +100 -36
- package/dist/catalog-fec-params.js.map +4 -4
- package/dist/catalog-network-source.js +3 -0
- package/dist/catalog-network-source.js.map +3 -3
- package/dist/delivery-catalog.js +84 -220
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +15 -0
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +99 -39
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +3 -2
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +16 -9
- package/dist/fec-state.js.map +4 -4
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +13 -2
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.js +3 -0
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/mfu-reassembler.js +24 -13
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +96 -22
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +124 -36
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +96 -22
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- package/dist/mmtp-router.d.ts +14 -4
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +139 -22
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-input.js +3 -0
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +49 -0
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +437 -302
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +6 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +93 -224
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +24 -13
- package/dist/multicast-unwrap.js.map +3 -3
- package/dist/no-modules.js +123 -35
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.js +3 -0
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.js +3 -0
- package/dist/repair-layers.js.map +3 -3
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.js +3 -0
- package/dist/signaling.js.map +3 -3
- package/dist/timestamp-codec.js +24 -13
- package/dist/timestamp-codec.js.map +3 -3
- package/dist/wasm-mfu-reassembler.js +3 -0
- package/dist/wasm-mfu-reassembler.js.map +3 -3
- package/dist/wasm-mmtp-container-parser.js +96 -22
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/package.json +5 -5
- package/src/carp-catalog.ts +33 -10
- package/src/catalog-fec-params.ts +38 -17
- package/src/fec-manager.ts +111 -49
- package/src/fec-state.ts +4 -9
- package/src/fec-worker-setup.ts +16 -1
- package/src/index.ts +5 -0
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-router.ts +76 -5
- package/src/multicast-manager.ts +143 -7
- package/src/multicast-transport.ts +14 -3
- package/src/sample-combiner.ts +15 -2
- package/test-vectors/catalog/README.md +5 -1
- package/test-vectors/catalog-validation.json +95 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockcast/mmt-container",
|
|
3
|
-
"version": "0.4.0-main.
|
|
3
|
+
"version": "0.4.0-main.bbd83cb48eff",
|
|
4
4
|
"description": "MMTP/LOC container parsing for MMT over MoQ and SSM",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -178,10 +178,10 @@
|
|
|
178
178
|
},
|
|
179
179
|
"dependencies": {
|
|
180
180
|
"@noble/hashes": "^1.8.0",
|
|
181
|
-
"@blockcast/mmt-fec": "0.
|
|
182
|
-
"@blockcast/mmt-manifest-verify": "0.
|
|
183
|
-
"@blockcast/fec-worker": "0.
|
|
184
|
-
"@blockcast/mmt-base": "0.
|
|
181
|
+
"@blockcast/mmt-fec": "0.4.0-main.bbd83cb48eff",
|
|
182
|
+
"@blockcast/mmt-manifest-verify": "0.4.0-main.bbd83cb48eff",
|
|
183
|
+
"@blockcast/fec-worker": "0.4.0-main.bbd83cb48eff",
|
|
184
|
+
"@blockcast/mmt-base": "0.4.0-main.bbd83cb48eff",
|
|
185
185
|
"ajv": "^8.17.1",
|
|
186
186
|
"ajv-formats": "^3.0.1"
|
|
187
187
|
},
|
package/src/carp-catalog.ts
CHANGED
|
@@ -126,13 +126,15 @@ export function hasSwitchingSetRole(names: string[]): boolean {
|
|
|
126
126
|
* Validate that a set of track names forms a complete switching set.
|
|
127
127
|
*
|
|
128
128
|
* - Empty or single-track sets (all parsing to `"single"`) → `{ ok: true }`.
|
|
129
|
-
* - Multi-track sets (any name has a role suffix) MUST include
|
|
130
|
-
*
|
|
129
|
+
* - Multi-track sets (any name has a role suffix) MUST include `base` and
|
|
130
|
+
* `repair`. `delta` is optional (BLO-49199): base is the self-decodable leg,
|
|
131
|
+
* so a base-only set plays in base-only mode; a delta without base cannot.
|
|
132
|
+
* Missing roles are listed.
|
|
131
133
|
*
|
|
132
134
|
* Propagates throws from `parseTrackRole` (non-ASCII, unknown suffix, etc.).
|
|
133
135
|
*
|
|
134
136
|
* D-04: Legacy single-track streams pass without enforcement.
|
|
135
|
-
* D-04: Once any suffix appears, the set is multi-track and
|
|
137
|
+
* D-04: Once any suffix appears, the set is multi-track and needs base + repair.
|
|
136
138
|
*/
|
|
137
139
|
export function validateSwitchingSet(
|
|
138
140
|
trackNames: string[],
|
|
@@ -147,11 +149,11 @@ export function validateSwitchingSet(
|
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
// Multi-track: at least one name has a role suffix.
|
|
150
|
-
// The set MUST contain
|
|
152
|
+
// The set MUST contain base and repair; delta is optional (BLO-49199).
|
|
151
153
|
// Explicit Set<TrackRole> so the TrackRole-typed `required.filter`
|
|
152
154
|
// callback can call .has(r) without a narrow-mismatch complaint.
|
|
153
155
|
const presentRoles: Set<TrackRole> = new Set(roles.filter((r) => r !== "single"));
|
|
154
|
-
const required: TrackRole[] = ["base", "
|
|
156
|
+
const required: TrackRole[] = ["base", "repair"];
|
|
155
157
|
const missing = required.filter((r) => !presentRoles.has(r));
|
|
156
158
|
|
|
157
159
|
if (missing.length > 0) {
|
|
@@ -927,7 +929,14 @@ export function validateCmsfMmtpCatalog(value: unknown): CmsfCatalog {
|
|
|
927
929
|
);
|
|
928
930
|
}
|
|
929
931
|
|
|
930
|
-
|
|
932
|
+
// mmt-00 §4.4: alternates share group boundaries so a subscriber can switch
|
|
933
|
+
// at any of them. An intra-only member (one frame per group, e.g. the demo's
|
|
934
|
+
// forceIOnly `video/base`) has a boundary at every frame, so it switches
|
|
935
|
+
// cleanly with any GOP peer whose group duration is a whole number of its
|
|
936
|
+
// groups. Such a member is checked for divisibility against the first GOP
|
|
937
|
+
// member; every GOP member must still match that anchor exactly (BLO-49202).
|
|
938
|
+
type SwitchingMember = { index: number; name: string; ticks: bigint; timescale: bigint; intraOnly: boolean };
|
|
939
|
+
const switchingSets = new Map<number, SwitchingMember[]>();
|
|
931
940
|
for (let index = 0; index < trackRecords.length; index++) {
|
|
932
941
|
const track = trackRecords[index]!;
|
|
933
942
|
if (track["packaging"] !== "mmtp") continue;
|
|
@@ -938,11 +947,25 @@ export function validateCmsfMmtpCatalog(value: unknown): CmsfCatalog {
|
|
|
938
947
|
const ticks = durationTicks !== undefined
|
|
939
948
|
? BigInt(durationTicks as number)
|
|
940
949
|
: BigInt(track["groupDurationMs"] as number) * timescale / 1000n;
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
|
|
950
|
+
const framerate = track["framerate"];
|
|
951
|
+
// Group duration == one frame period. `framerate` is a float (29.97), so
|
|
952
|
+
// compare within 0.1%; a GOP track is off by a factor of >= 2.
|
|
953
|
+
const intraOnly = positiveNumber(framerate) &&
|
|
954
|
+
Math.abs(Number(ticks) * framerate - Number(timescale)) <= Number(timescale) * 1e-3;
|
|
955
|
+
const members = switchingSets.get(altGroup as number) ?? [];
|
|
956
|
+
members.push({ index, name: track["name"] as string, ticks, timescale, intraOnly });
|
|
957
|
+
switchingSets.set(altGroup as number, members);
|
|
958
|
+
}
|
|
959
|
+
for (const [altGroup, members] of switchingSets) {
|
|
960
|
+
const anchor = members.find((member) => !member.intraOnly) ?? members[0]!;
|
|
961
|
+
for (const member of members) {
|
|
962
|
+
if (member === anchor || member.ticks * anchor.timescale === anchor.ticks * member.timescale) continue;
|
|
963
|
+
const nests = member.intraOnly && !anchor.intraOnly &&
|
|
964
|
+
(anchor.ticks * member.timescale) % (member.ticks * anchor.timescale) === 0n;
|
|
965
|
+
if (!nests) {
|
|
966
|
+
catalogError("track_switching_set", `$.tracks[${member.index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
|
|
967
|
+
}
|
|
944
968
|
}
|
|
945
|
-
if (!anchor) switchingSets.set(altGroup as number, { name: track["name"] as string, ticks, timescale });
|
|
946
969
|
}
|
|
947
970
|
|
|
948
971
|
const multicast = catalog["multicast"];
|
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
// player-agnostic.
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
+
catalogFecAvailable,
|
|
11
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
10
12
|
FEC_BLOCK_PROFILES,
|
|
11
13
|
isFecBlockProfile,
|
|
14
|
+
locateCatalogFecSource,
|
|
12
15
|
parseFecBlockProfile,
|
|
16
|
+
type CatalogFecRole,
|
|
17
|
+
type CatalogFecSource,
|
|
13
18
|
type FecBlockProfile,
|
|
14
19
|
} from "@blockcast/mmt-base";
|
|
15
20
|
import { catalogFecInterleaveMs, type FecInterleaveCatalog } from "@blockcast/mmt-fec";
|
|
@@ -37,6 +42,15 @@ import type { RepairTarget } from "./repair-fetch.js";
|
|
|
37
42
|
|
|
38
43
|
export { catalogFecInterleaveMs, type FecInterleaveCatalog };
|
|
39
44
|
export { FEC_BLOCK_PROFILES, isFecBlockProfile, parseFecBlockProfile, type FecBlockProfile };
|
|
45
|
+
// The shared catalog FEC source rules (BLO-40851): one copy, in the leaf
|
|
46
|
+
// package transport and every player also read.
|
|
47
|
+
export {
|
|
48
|
+
catalogFecAvailable,
|
|
49
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
50
|
+
locateCatalogFecSource,
|
|
51
|
+
type CatalogFecRole,
|
|
52
|
+
type CatalogFecSource,
|
|
53
|
+
};
|
|
40
54
|
export {
|
|
41
55
|
assembleRepairLayers,
|
|
42
56
|
assertRepairTrackReachable,
|
|
@@ -416,8 +430,10 @@ export function resolveRepairLayers(
|
|
|
416
430
|
// beside a tracks[] switching-set index (the unified ABR ladder catalog),
|
|
417
431
|
// the rendition blocks are authoritative, exactly as they are for hang's own
|
|
418
432
|
// catalog decode. A typed ref resolves only within its own role.
|
|
433
|
+
// `locateCatalogFecSource` is that precedence rule, shared with transport's
|
|
434
|
+
// endpoint selection and the players' repair inventories.
|
|
419
435
|
const hang = catalog as CatalogWithRenditions;
|
|
420
|
-
const roles:
|
|
436
|
+
const roles: CatalogFecRole[] =
|
|
421
437
|
typeof source === "string"
|
|
422
438
|
? ["video", "audio"]
|
|
423
439
|
: source.type === "audio"
|
|
@@ -425,10 +441,10 @@ export function resolveRepairLayers(
|
|
|
425
441
|
: source.type === "video"
|
|
426
442
|
? ["video"]
|
|
427
443
|
: ["video", "audio"];
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
const renditionPath = `$.${role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
431
|
-
const rendition =
|
|
444
|
+
const located = locateCatalogFecSource(catalog, sourceName, roles);
|
|
445
|
+
if (located?.dialect === "hang") {
|
|
446
|
+
const renditionPath = `$.${located.role}.renditions[${JSON.stringify(sourceName)}]`;
|
|
447
|
+
const rendition = located.entry;
|
|
432
448
|
rejectRepairFieldsOnMediaTrack(renditionPath, rendition, throwRepairContractError);
|
|
433
449
|
const repairRenditions = recordOf(hang.repair?.renditions) ?? {};
|
|
434
450
|
const descriptors: RepairTrackDescriptor[] = Object.entries(repairRenditions).map(([name, entry]) => {
|
|
@@ -473,8 +489,8 @@ export function resolveRepairLayers(
|
|
|
473
489
|
}
|
|
474
490
|
|
|
475
491
|
const msf = msfTracks(catalog);
|
|
476
|
-
|
|
477
|
-
|
|
492
|
+
if (!msf || located?.dialect !== "msf") return undefined;
|
|
493
|
+
const msfIndex = located.index;
|
|
478
494
|
const track = msf.tracks[msfIndex]!;
|
|
479
495
|
const fec = recordOf(track["fec"]);
|
|
480
496
|
const packagingOf = (t: Record<string, unknown>): unknown => t["packaging"];
|
|
@@ -653,19 +669,26 @@ function isoSpanUnavailable(
|
|
|
653
669
|
* `iso-ssbg1-v1` instance, carries no usable block span. Returns undefined for
|
|
654
670
|
* a non-object and for every block whose FEC is available. It reads only the
|
|
655
671
|
* profile and the span: malformed geometry (`sourceSymbols`, `symbolSize`, ...)
|
|
656
|
-
* is the caller's to reject, and takes precedence. Never throws
|
|
672
|
+
* is the caller's to reject, and takes precedence. Never throws on catalog
|
|
673
|
+
* input: whether FEC is available is `catalogFecAvailable` (mmt-base), and a
|
|
674
|
+
* test pins that every unavailable block gets a reason here.
|
|
657
675
|
*
|
|
658
676
|
* @param fec the track's catalog `fec` value.
|
|
659
677
|
* @param fecPath JSON path of that `fec` block; the reason's `path` extends it.
|
|
660
678
|
*/
|
|
661
679
|
export function catalogFecUnavailable(fec: unknown, fecPath: string): TrackFecUnavailable | undefined {
|
|
662
|
-
|
|
663
|
-
|
|
680
|
+
// The decision is mmt-base's `catalogFecAvailable`, which transport reads
|
|
681
|
+
// too; this function only explains a negative one.
|
|
682
|
+
if (catalogFecAvailable(fec)) return undefined;
|
|
683
|
+
const block = recordOf(fec)!;
|
|
664
684
|
const declaresFecInstance = block["algorithm"] !== "none";
|
|
665
|
-
|
|
685
|
+
const reason =
|
|
666
686
|
blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ??
|
|
667
|
-
isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance)
|
|
668
|
-
)
|
|
687
|
+
isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
|
|
688
|
+
if (reason === undefined) {
|
|
689
|
+
throw new Error(`catalogFecUnavailable: ${fecPath} is unavailable but no reason applies (rule drift)`);
|
|
690
|
+
}
|
|
691
|
+
return reason;
|
|
669
692
|
}
|
|
670
693
|
|
|
671
694
|
/**
|
|
@@ -701,10 +724,8 @@ function fecParams(
|
|
|
701
724
|
// and T are positive integers, the algorithm is not `none`, and the block
|
|
702
725
|
// profile is known.
|
|
703
726
|
if (!catalogDeclaresFec(fec)) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
const tValid = Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0;
|
|
707
|
-
if (declaresFecInstance && !(kValid && tValid)) {
|
|
727
|
+
if (catalogFecDeclaresUnconfigurableInstance(fec)) {
|
|
728
|
+
const kValid = Number.isSafeInteger(fec.sourceSymbols) && (fec.sourceSymbols ?? 0) > 0;
|
|
708
729
|
// Any algorithm but `none` declares an FEC instance, so geometry a
|
|
709
730
|
// decoder cannot configure is a malformed catalog, not "no FEC".
|
|
710
731
|
// Returning NO_FEC would silently drop the track's repair
|
package/src/fec-manager.ts
CHANGED
|
@@ -572,9 +572,13 @@ export class FECManager {
|
|
|
572
572
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
573
573
|
// arithmetic and never throws at all.
|
|
574
574
|
#orderedHorizonWarnedFor = new Set<number>()
|
|
575
|
-
// Newest block start (SS_Start)
|
|
576
|
-
//
|
|
575
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
576
|
+
// frontier isoSpanResolution reads.
|
|
577
577
|
#highestSbn = new Map<string, { sbn: number; atMs: number }>()
|
|
578
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
579
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
580
|
+
// blocks ahead of the media they protect.
|
|
581
|
+
#sourceFrontiers = new Map<string, { sbn: number; atMs: number }>()
|
|
578
582
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
579
583
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
580
584
|
#isoLocators = new Map<string, IsoBlockLocator<IsoHeldSource>>()
|
|
@@ -592,9 +596,9 @@ export class FECManager {
|
|
|
592
596
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
593
597
|
#isoDecoderUnplacedRetireFailed = 0
|
|
594
598
|
// The latest source symbol per stream that carried its MMTP
|
|
595
|
-
// packet_sequence_number: the anchor that bounds how
|
|
596
|
-
// producer can have
|
|
597
|
-
#sourceAnchors = new Map<string, {
|
|
599
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
600
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
601
|
+
#sourceAnchors = new Map<string, { ssId: number; psn: number; atMs: number }>()
|
|
598
602
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
599
603
|
#packetEpochs = new Map<number, number>()
|
|
600
604
|
|
|
@@ -1509,8 +1513,8 @@ export class FECManager {
|
|
|
1509
1513
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
1510
1514
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
1511
1515
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
1512
|
-
// many blocks a stream can
|
|
1513
|
-
//
|
|
1516
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
1517
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
1514
1518
|
// The extra block of retention is slack for a block still being fed; a block
|
|
1515
1519
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
1516
1520
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -1521,23 +1525,28 @@ export class FECManager {
|
|
|
1521
1525
|
|
|
1522
1526
|
/**
|
|
1523
1527
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
1524
|
-
* advance the stream's
|
|
1528
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
1525
1529
|
*
|
|
1526
|
-
* A SOURCE symbol
|
|
1527
|
-
*
|
|
1528
|
-
*
|
|
1530
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
1531
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
1532
|
+
* block goes back further than the blocks this manager retains, or that
|
|
1533
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
1534
|
+
* further than the stream could have produced since its last symbol, is a
|
|
1535
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
1529
1536
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
1530
1537
|
* signals a discontinuity.
|
|
1531
1538
|
*
|
|
1532
1539
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
1533
1540
|
* source symbols filled it, so one interleave span can start several blocks
|
|
1534
|
-
* (every large keyframe does). What bounds a
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
* packet_sequence_number
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1541
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
1542
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
1543
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
1544
|
+
* packet of the packet_id, so with both source symbols'
|
|
1545
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
1546
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
1547
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
1548
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
1549
|
+
* known.
|
|
1541
1550
|
*
|
|
1542
1551
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
1543
1552
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
@@ -1549,10 +1558,11 @@ export class FECManager {
|
|
|
1549
1558
|
catalogTrackName: string | undefined,
|
|
1550
1559
|
symbol: 'source' | 'repair',
|
|
1551
1560
|
packetSequenceNumber?: number,
|
|
1561
|
+
ssId = sbn,
|
|
1552
1562
|
): void {
|
|
1553
1563
|
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
1554
1564
|
const now = performance.now()
|
|
1555
|
-
const previous = this.#highestSbn.get(streamKey)
|
|
1565
|
+
const previous = (symbol === 'source' ? this.#sourceFrontiers : this.#highestSbn).get(streamKey)
|
|
1556
1566
|
const anchor = this.#sourceAnchors.get(streamKey)
|
|
1557
1567
|
const psn = symbol === 'source' &&
|
|
1558
1568
|
packetSequenceNumber !== undefined &&
|
|
@@ -1562,29 +1572,46 @@ export class FECManager {
|
|
|
1562
1572
|
? packetSequenceNumber
|
|
1563
1573
|
: undefined
|
|
1564
1574
|
const anchorHere = (): void => {
|
|
1565
|
-
if (psn !== undefined && (anchor === undefined || !
|
|
1566
|
-
this.#sourceAnchors.set(streamKey, {
|
|
1575
|
+
if (psn !== undefined && (anchor === undefined || !serial32Precedes(ssId, anchor.ssId))) {
|
|
1576
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now })
|
|
1567
1577
|
}
|
|
1568
1578
|
}
|
|
1579
|
+
const advance = (): void => {
|
|
1580
|
+
const highest = this.#highestSbn.get(streamKey)
|
|
1581
|
+
if (highest === undefined || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
1582
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now })
|
|
1583
|
+
}
|
|
1584
|
+
if (symbol === 'source') this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
|
|
1585
|
+
anchorHere()
|
|
1586
|
+
}
|
|
1569
1587
|
const discontinuity = (): void => {
|
|
1570
1588
|
// The classifier compares authored order with SBN order only within
|
|
1571
1589
|
// one continuous SBN sequence.
|
|
1572
1590
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity()
|
|
1573
1591
|
this.#highestSbn.set(streamKey, { sbn, atMs: now })
|
|
1592
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
|
|
1574
1593
|
if (psn === undefined) this.#sourceAnchors.delete(streamKey)
|
|
1575
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
1594
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now })
|
|
1576
1595
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName)
|
|
1577
1596
|
}
|
|
1578
1597
|
if (previous === undefined) {
|
|
1579
|
-
|
|
1580
|
-
anchorHere()
|
|
1598
|
+
advance()
|
|
1581
1599
|
return
|
|
1582
1600
|
}
|
|
1583
1601
|
const config = this.#trackConfig(packetId)
|
|
1584
1602
|
const window = this.#liveWindowBlocks(config)
|
|
1603
|
+
// Packets sent from `from` to `to`, serial arithmetic (RFC 1982): more
|
|
1604
|
+
// than half the space means it went backwards.
|
|
1605
|
+
const sentInOrder = (from: { ssId: number; psn: number }, to: { ssId: number; psn: number }): boolean => {
|
|
1606
|
+
const sent = (to.psn - from.psn) >>> 0
|
|
1607
|
+
return sent <= 0x7fff_ffff && serial32Distance(from.ssId, to.ssId) <= sent + config.k
|
|
1608
|
+
}
|
|
1585
1609
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
1586
|
-
if (symbol === 'source' && window !== null &&
|
|
1587
|
-
|
|
1610
|
+
if (symbol === 'source' && window !== null && this.#blockPrecedes(sbn, previous.sbn) && (
|
|
1611
|
+
this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) ||
|
|
1612
|
+
(psn !== undefined && anchor !== undefined && serial32Precedes(ssId, anchor.ssId) &&
|
|
1613
|
+
psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))
|
|
1614
|
+
)) {
|
|
1588
1615
|
discontinuity()
|
|
1589
1616
|
return
|
|
1590
1617
|
}
|
|
@@ -1598,15 +1625,8 @@ export class FECManager {
|
|
|
1598
1625
|
// producer that does not maintain it); only then is the D-close rate
|
|
1599
1626
|
// the whole bound.
|
|
1600
1627
|
if (psn !== undefined && anchor !== undefined &&
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
// plus the anchor's own offset into its block (< K). Packets sent
|
|
1604
|
-
// from the anchor packet to this one, serial arithmetic (RFC 1982):
|
|
1605
|
-
// more than half the space means it went backwards.
|
|
1606
|
-
const sent = (psn - anchor.psn) >>> 0
|
|
1607
|
-
plausible =
|
|
1608
|
-
sent <= 0x7fff_ffff &&
|
|
1609
|
-
serial32Distance(anchor.sbn, sbn) <= sent + config.k
|
|
1628
|
+
serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
1629
|
+
plausible = sentInOrder(anchor, { ssId, psn })
|
|
1610
1630
|
} else {
|
|
1611
1631
|
plausible = missing <= window + Math.ceil((now - previous.atMs) / config.interleaveDepthMs)
|
|
1612
1632
|
}
|
|
@@ -1616,8 +1636,7 @@ export class FECManager {
|
|
|
1616
1636
|
discontinuity()
|
|
1617
1637
|
return
|
|
1618
1638
|
}
|
|
1619
|
-
|
|
1620
|
-
anchorHere()
|
|
1639
|
+
advance()
|
|
1621
1640
|
}
|
|
1622
1641
|
|
|
1623
1642
|
/*
|
|
@@ -2397,6 +2416,7 @@ export class FECManager {
|
|
|
2397
2416
|
resetSet(this.#materializedBlocks)
|
|
2398
2417
|
resetMap(this.#resolvedBlockClasses)
|
|
2399
2418
|
resetMap(this.#highestSbn)
|
|
2419
|
+
resetMap(this.#sourceFrontiers)
|
|
2400
2420
|
resetMap(this.#isoLocators)
|
|
2401
2421
|
resetMap(this.#sourceAnchors)
|
|
2402
2422
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName))
|
|
@@ -2510,6 +2530,7 @@ export class FECManager {
|
|
|
2510
2530
|
dropMap(this.#orderedPendingBlocks)
|
|
2511
2531
|
dropMap(this.#resolvedBlockClasses)
|
|
2512
2532
|
dropMap(this.#highestSbn)
|
|
2533
|
+
dropMap(this.#sourceFrontiers)
|
|
2513
2534
|
dropMap(this.#isoLocators)
|
|
2514
2535
|
dropMap(this.#sourceAnchors)
|
|
2515
2536
|
dropMap(this.#classifiers)
|
|
@@ -2642,7 +2663,11 @@ export class FECManager {
|
|
|
2642
2663
|
this.#startupPartialBlocks.delete(blockKey)
|
|
2643
2664
|
this.#startupAlignedPackets.add(streamKey)
|
|
2644
2665
|
} else if (
|
|
2645
|
-
|
|
2666
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
2667
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
2668
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
2669
|
+
// per join (BLO-48308).
|
|
2670
|
+
isStartupPartial ||
|
|
2646
2671
|
(!this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair)
|
|
2647
2672
|
) {
|
|
2648
2673
|
this.#markStartupPartial(blockKey)
|
|
@@ -3028,6 +3053,11 @@ export class FECManager {
|
|
|
3028
3053
|
return blocks
|
|
3029
3054
|
}
|
|
3030
3055
|
|
|
3056
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
3057
|
+
isoRetentionBlocksForPacket(packetId: number): number | undefined {
|
|
3058
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : undefined
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3031
3061
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
3032
3062
|
isoSourceFits(packetId: number, packetLength: number): boolean {
|
|
3033
3063
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize
|
|
@@ -3827,6 +3857,39 @@ export class FECManager {
|
|
|
3827
3857
|
* Caller is responsible for routing recovered data and updating
|
|
3828
3858
|
* block completion state via `markBlockCompleted()`.
|
|
3829
3859
|
*/
|
|
3860
|
+
/**
|
|
3861
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
3862
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
3863
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
3864
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
3865
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
3866
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
3867
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
3868
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
3869
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
3870
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
3871
|
+
*/
|
|
3872
|
+
admitRepairSymbolSize(
|
|
3873
|
+
packetId: number,
|
|
3874
|
+
ssStart: number,
|
|
3875
|
+
ssbLength: number,
|
|
3876
|
+
rsId: number,
|
|
3877
|
+
byteLength: number,
|
|
3878
|
+
): boolean {
|
|
3879
|
+
if (!this.#hasBlockProfile(packetId)) return false
|
|
3880
|
+
const symbolSize = this.#trackConfig(packetId).symbolSize
|
|
3881
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
3882
|
+
this.#repairSymbolSizeMismatchCount++
|
|
3883
|
+
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
3884
|
+
console.warn(
|
|
3885
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`,
|
|
3886
|
+
)
|
|
3887
|
+
}
|
|
3888
|
+
return false
|
|
3889
|
+
}
|
|
3890
|
+
return true
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3830
3893
|
feedRepairSymbol(
|
|
3831
3894
|
packetId: number,
|
|
3832
3895
|
ssStart: number,
|
|
@@ -3840,16 +3903,7 @@ export class FECManager {
|
|
|
3840
3903
|
// A packetId with no configured block profile has no block geometry: its
|
|
3841
3904
|
// repair names no block this manager can track or decode.
|
|
3842
3905
|
if (!this.#hasBlockProfile(packetId)) return null
|
|
3843
|
-
|
|
3844
|
-
if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
|
|
3845
|
-
this.#repairSymbolSizeMismatchCount++
|
|
3846
|
-
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
3847
|
-
console.warn(
|
|
3848
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`,
|
|
3849
|
-
)
|
|
3850
|
-
}
|
|
3851
|
-
return null
|
|
3852
|
-
}
|
|
3906
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null
|
|
3853
3907
|
const fecData = repairData
|
|
3854
3908
|
|
|
3855
3909
|
// ISO/IEC 23008-1 C.5.3: the block is [SS_Start, SS_Start + SSB_length),
|
|
@@ -4072,7 +4126,14 @@ export class FECManager {
|
|
|
4072
4126
|
// Skip blocks already recovered — late source symbols must not restart timeouts
|
|
4073
4127
|
if (this.#completedBlocks.has(key)) return
|
|
4074
4128
|
|
|
4075
|
-
this.#noteSbnSeen(
|
|
4129
|
+
this.#noteSbnSeen(
|
|
4130
|
+
sbn,
|
|
4131
|
+
packetId,
|
|
4132
|
+
catalogTrackName,
|
|
4133
|
+
'source',
|
|
4134
|
+
evidence.packetSequenceNumber,
|
|
4135
|
+
Number.isInteger(esi) ? (sbn + esi) >>> 0 : sbn,
|
|
4136
|
+
)
|
|
4076
4137
|
|
|
4077
4138
|
// A source ESI at or past the block's authored SSB_length contradicts it;
|
|
4078
4139
|
// its geometry can no longer be trusted, so fail it closed.
|
|
@@ -4410,6 +4471,7 @@ export class FECManager {
|
|
|
4410
4471
|
this.#repairedBlocks.clear()
|
|
4411
4472
|
this.#materializedBlocks.clear()
|
|
4412
4473
|
this.#highestSbn.clear()
|
|
4474
|
+
this.#sourceFrontiers.clear()
|
|
4413
4475
|
this.#isoLocators.clear()
|
|
4414
4476
|
this.#sourceAnchors.clear()
|
|
4415
4477
|
this.#trackConfigs.clear()
|
package/src/fec-state.ts
CHANGED
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
// timers or elapsed time. The rules live here so the three players cannot
|
|
14
14
|
// disagree about precedence.
|
|
15
15
|
|
|
16
|
-
import { isFecBlockProfile } from '@blockcast/mmt-base'
|
|
16
|
+
import { isFecBlockProfile, isoBlockSpanUsable } from '@blockcast/mmt-base'
|
|
17
|
+
|
|
18
|
+
/** The optional elapsed-span rule lives in mmt-base beside the other catalog FEC rules. */
|
|
19
|
+
export { isoBlockSpanUsable }
|
|
17
20
|
|
|
18
21
|
/** Smallest positive catalog elapsed span; zero/absence means no elapsed deadline. */
|
|
19
22
|
export const MIN_INTERLEAVE_DEPTH_MS = 1
|
|
@@ -147,14 +150,6 @@ export function catalogDeclaresFec(fec: unknown): boolean {
|
|
|
147
150
|
)
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
/** Validate the optional elapsed span without requiring one for in-band FEC. */
|
|
151
|
-
export function isoBlockSpanUsable(fec: unknown): boolean {
|
|
152
|
-
const block = recordOf(fec)
|
|
153
|
-
if (block === undefined || block['blockProfile'] !== 'iso-ssbg1-v1') return true
|
|
154
|
-
const ms = block['interleaveDepthMs']
|
|
155
|
-
return ms === undefined || (typeof ms === 'number' && Number.isSafeInteger(ms) && ms >= 0)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
153
|
function requireBoolean(value: unknown, field: string): boolean {
|
|
159
154
|
if (typeof value !== 'boolean') {
|
|
160
155
|
throw new TypeError(`resolveFecState: ${field} must be a boolean, got ${typeof value}`)
|
package/src/fec-worker-setup.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
deriveFecRetentionBlocks,
|
|
21
21
|
LOCAL_FEC_RETENTION_BLOCKS,
|
|
22
22
|
LOCAL_FEC_TIMEOUT_MS,
|
|
23
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
23
24
|
} from '@blockcast/mmt-fec'
|
|
24
25
|
import { computeFecDeliveryWindowMs } from './track-session.js'
|
|
25
26
|
|
|
@@ -252,7 +253,6 @@ export async function setupFecWorkerForTrack(
|
|
|
252
253
|
relayBlockSigEnabled: false,
|
|
253
254
|
} as unknown as FecTrackConfig
|
|
254
255
|
|
|
255
|
-
client.configure(fecTrackConfig, rqWasm)
|
|
256
256
|
try {
|
|
257
257
|
opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
|
|
258
258
|
blockProfile,
|
|
@@ -276,6 +276,21 @@ export async function setupFecWorkerForTrack(
|
|
|
276
276
|
}
|
|
277
277
|
throw e
|
|
278
278
|
}
|
|
279
|
+
// The Worker retires a block `interleaveDepth` blocks behind the newest
|
|
280
|
+
// SS_ID it has seen, repair SS_Starts included, by the metric the manager's
|
|
281
|
+
// locator uses for its own horizon. Repairs ride their own group and can run
|
|
282
|
+
// blocks ahead of their media, so a shorter Worker horizon fails a block whose
|
|
283
|
+
// late sources the manager still waits for.
|
|
284
|
+
// ponytail: read once here; a keyframe cadence configured later widens only
|
|
285
|
+
// the manager's horizon (reconfigure the Worker if a player ever does that).
|
|
286
|
+
fecTrackConfig.interleaveDepth = Math.min(
|
|
287
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
288
|
+
Math.max(
|
|
289
|
+
interleaveDepthBlocks,
|
|
290
|
+
opts.multicastManager.fecManager.isoRetentionBlocksForPacket(opts.packetId) ?? 0,
|
|
291
|
+
),
|
|
292
|
+
)
|
|
293
|
+
client.configure(fecTrackConfig, rqWasm)
|
|
279
294
|
|
|
280
295
|
let disposed = false
|
|
281
296
|
return {
|
package/src/index.ts
CHANGED
|
@@ -552,6 +552,11 @@ export {
|
|
|
552
552
|
type TrackFecParams,
|
|
553
553
|
type TrackFecUnavailable,
|
|
554
554
|
catalogFecUnavailable,
|
|
555
|
+
catalogFecAvailable,
|
|
556
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
557
|
+
locateCatalogFecSource,
|
|
558
|
+
type CatalogFecRole,
|
|
559
|
+
type CatalogFecSource,
|
|
555
560
|
catalogGroupDurationMs,
|
|
556
561
|
catalogKeyframeCadenceMs,
|
|
557
562
|
catalogFecMediaUnitsPerSecond,
|