@blockcast/mmt-container 0.5.0 → 1.0.0-main.215b8665a0eb

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockcast/mmt-container",
3
- "version": "0.5.0",
3
+ "version": "1.0.0-main.215b8665a0eb",
4
4
  "description": "MMTP/LOC container parsing for MMT over MoQ and SSM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,6 +26,10 @@
26
26
  "import": "./dist/codec-utils.js",
27
27
  "types": "./dist/codec-utils.d.ts"
28
28
  },
29
+ "./fec-catalog": {
30
+ "import": "./dist/fec-catalog.js",
31
+ "types": "./dist/fec-catalog.d.ts"
32
+ },
29
33
  "./fec-manager": {
30
34
  "import": "./dist/fec-manager.js",
31
35
  "types": "./dist/fec-manager.d.ts"
@@ -165,10 +169,10 @@
165
169
  "test:watch": "vitest"
166
170
  },
167
171
  "dependencies": {
168
- "@blockcast/fec-worker": "^0.5.0",
169
- "@blockcast/mmt-base": "^0.5.0",
170
- "@blockcast/mmt-fec": "^0.5.0",
171
- "@blockcast/mmt-manifest-verify": "^0.5.0",
172
+ "@blockcast/fec-worker": "1.0.0-main.215b8665a0eb",
173
+ "@blockcast/mmt-base": "1.0.0-main.215b8665a0eb",
174
+ "@blockcast/mmt-fec": "1.0.0-main.215b8665a0eb",
175
+ "@blockcast/mmt-manifest-verify": "1.0.0-main.215b8665a0eb",
172
176
  "@noble/curves": "^1.9.7",
173
177
  "@noble/hashes": "^1.8.0",
174
178
  "ajv": "^8.17.1",
@@ -0,0 +1,428 @@
1
+ // FEC catalog binding validator (draft-ramadan-moq-fec-catalog-00, as posted
2
+ // 2026-11-02, moqcast-draft 5f49172).
3
+ //
4
+ // The catalog-00 shape only: a track's `fec` is an array of instance objects,
5
+ // and a repair or symbol track binds to its instance by `source` + `instanceId`
6
+ // (or by being named in `repairTrack` / `symbolTrack`). The draft-01 object
7
+ // shape (`fec: {...}`, `depends`) is not accepted: an object `fec` is a type
8
+ // violation, and a repair track that only `depends` on its source is an orphan.
9
+ //
10
+ // Validation fails closed per instance (fec-core-00 10.3): a violation stops
11
+ // FEC for that instance and no other. Three outcomes, each reported with the
12
+ // catalog path that caused it:
13
+ // ok - FEC may start for the instance.
14
+ // unavailable - the receiver forgoes FEC for it (fec-core-00 10.3 rule 1,
15
+ // 4.5); not a validation failure.
16
+ // violation - the configuration is invalid for this receiver.
17
+ // An orphan repair or symbol track (fec-catalog-00 5 rule 6) is reported and
18
+ // stops nothing. `enhancementRepair` anywhere rejects the catalog (rule 4).
19
+ //
20
+ // The Rust twin is `mmt_fec::fec_catalog`; both run vectors/fec-catalog-00/.
21
+
22
+ export type FecCatalogOutcome = "ok" | "unavailable" | "violation";
23
+
24
+ export type FecCatalogCode =
25
+ // Unavailable (fec-core-00 10.3 rule 1; fec-catalog-00 3.1).
26
+ | "fec_scheme_absent"
27
+ | "fec_scheme_unimplemented"
28
+ | "fec_block_profile_absent"
29
+ | "fec_block_profile_unimplemented"
30
+ | "fec_block_profile_packaging"
31
+ // Violations.
32
+ | "fec_member" // fec-catalog-00 5 rule 1; fec-core-00 10.3 rule 11
33
+ | "fec_naming" // fec-catalog-00 5 rule 2
34
+ | "fec_resolution" // fec-catalog-00 5 rule 3
35
+ | "fec_enhancement_repair" // fec-catalog-00 5 rule 4, 3.4
36
+ | "fec_orphan" // fec-catalog-00 5 rule 6 (report only)
37
+ | "fec_layers" // fec-core-00 10.3 rule 3
38
+ | "fec_layer0" // fec-core-00 10.3 rule 4
39
+ | "fec_bounds" // fec-core-00 10.3 rule 5; block-codes-00 7; mmt-02 7.1
40
+ | "fec_instance_id" // fec-core-00 10.3 rule 7
41
+ | "fec_symbol_tracks" // fec-core-00 10.3 rule 7
42
+ | "fec_track_geometry" // fec-core-00 10.3 rule 8
43
+ | "fec_priority" // fec-core-00 10.3 rule 10
44
+ | "fec_overlay" // mmt-02 7.4.1
45
+ | "fec_overlay_unsupported"; // mmt-02 7.4.4
46
+
47
+ export interface FecCatalogIssue {
48
+ readonly code: FecCatalogCode;
49
+ /** JSON Pointer into the catalog. */
50
+ readonly path: string;
51
+ }
52
+
53
+ export interface FecCatalogInstance {
54
+ /** JSON Pointer of the instance object, `/tracks/<i>/fec/<j>`. */
55
+ readonly path: string;
56
+ readonly track: string | null;
57
+ /** Resolved Instance ID; null when `instanceId` is malformed. */
58
+ readonly instanceId: number | null;
59
+ readonly outcome: FecCatalogOutcome;
60
+ readonly issues: readonly FecCatalogIssue[];
61
+ }
62
+
63
+ export interface FecCatalogReport {
64
+ readonly instances: readonly FecCatalogInstance[];
65
+ /** Every report, instance-attributed or not, in discovery order. */
66
+ readonly issues: readonly FecCatalogIssue[];
67
+ }
68
+
69
+ export interface FecCatalogReceiver {
70
+ /** Schemes the receiver implements. Default: reed-solomon, raptorq. */
71
+ readonly schemes?: readonly string[];
72
+ /** Block profiles the receiver implements. Default: moq-object-v1, iso-ssbg1-v1. */
73
+ readonly blockProfiles?: readonly string[];
74
+ /** Whether the receiver implements the mmt-02 7.4 keyframe overlay. Default true. */
75
+ readonly overlays?: boolean;
76
+ }
77
+
78
+ const DEFAULT_SCHEMES = ["reed-solomon", "raptorq"];
79
+ const DEFAULT_PROFILES = ["moq-object-v1", "iso-ssbg1-v1"];
80
+ const RS_MAX_BLOCK = 255; // block-codes-00 7
81
+ const RAPTORQ_MAX_K = 56403; // block-codes-00 7
82
+ const MAX_24 = 0xffffff; // fec-core-00 10.3 rule 5
83
+ const ISO_MIN_T = 14; // mmt-02 7.1
84
+ const GEOMETRY_KEYS = [
85
+ "scheme",
86
+ "blockProfile",
87
+ "mmtpMode",
88
+ "timescale",
89
+ "symbolSize",
90
+ "interleaveDepthMs",
91
+ "reorderToleranceMs",
92
+ "sourceSymbols",
93
+ "fec",
94
+ ];
95
+
96
+ type Json = unknown;
97
+ type Known =
98
+ | "tracks" | "fec" | "name" | "namespace" | "packaging" | "source" | "instanceId"
99
+ | "repairLayer" | "repairSymbols" | "priority" | "scheme" | "blockProfile"
100
+ | "sourceSymbols" | "symbolSize" | "repairTrack" | "symbolTrack"
101
+ | "interleaveDepthMs" | "reorderToleranceMs" | "label" | "scope";
102
+ type Obj = Record<string, Json> & Partial<Record<Known, Json>>;
103
+
104
+ const isObj = (v: Json): v is Obj => typeof v === "object" && v !== null && !Array.isArray(v);
105
+ const has = (o: Obj, k: string) => Object.prototype.hasOwnProperty.call(o, k);
106
+ const isInt = (v: Json): v is number => typeof v === "number" && Number.isInteger(v);
107
+ const intIn = (v: Json, lo: number, hi = Number.MAX_SAFE_INTEGER): v is number =>
108
+ isInt(v) && v >= lo && v <= hi;
109
+
110
+ // moq-object-v1 admits any packaging whose objects carry media as whole
111
+ // objects (fec-core-00 15.3); iso-ssbg1-v1 admits mmtp (mmt-02 7.1).
112
+ const profileAdmits = (profile: string, packaging: Json) => profile !== "iso-ssbg1-v1" || packaging === "mmtp";
113
+
114
+ interface Inst {
115
+ path: string;
116
+ ti: number;
117
+ track: Obj;
118
+ obj: Obj | null;
119
+ id: number | null;
120
+ unavailable: boolean;
121
+ overlay: boolean;
122
+ issues: FecCatalogIssue[];
123
+ layer0: number | null; // track index of the resolved repairTrack
124
+ symbolNamed: number | null;
125
+ attached: number[]; // unnamed fec-repair/fec-source tracks bound by source
126
+ }
127
+
128
+ export function validateFecCatalog(catalog: Json, receiver: FecCatalogReceiver = {}): FecCatalogReport {
129
+ const schemes = receiver.schemes ?? DEFAULT_SCHEMES;
130
+ const profiles = receiver.blockProfiles ?? DEFAULT_PROFILES;
131
+ const overlays = receiver.overlays ?? true;
132
+ const all: FecCatalogIssue[] = [];
133
+ const report = (code: FecCatalogCode, path: string, inst?: Inst) => {
134
+ const issue = { code, path };
135
+ all.push(issue);
136
+ inst?.issues.push(issue);
137
+ };
138
+
139
+ const tracks: Json[] = isObj(catalog) && Array.isArray(catalog.tracks) ? catalog.tracks : [];
140
+ if (!isObj(catalog) || !Array.isArray(catalog.tracks)) report("fec_member", "/tracks");
141
+
142
+ // Rule 4: enhancementRepair at track level or inside an instance object.
143
+ let rejectAll = false;
144
+ tracks.forEach((t, ti) => {
145
+ if (!isObj(t)) return;
146
+ if (has(t, "enhancementRepair")) {
147
+ rejectAll = true;
148
+ report("fec_enhancement_repair", `/tracks/${ti}/enhancementRepair`);
149
+ }
150
+ if (Array.isArray(t.fec))
151
+ t.fec.forEach((o, ii) => {
152
+ if (isObj(o) && has(o, "enhancementRepair")) {
153
+ rejectAll = true;
154
+ report("fec_enhancement_repair", `/tracks/${ti}/fec/${ii}/enhancementRepair`);
155
+ }
156
+ });
157
+ });
158
+
159
+ // Track lookup by (namespace, name): a name resolves in the source track's namespace.
160
+ const key = (ns: Json, name: string) => JSON.stringify([ns ?? null, name]);
161
+ const byName = new Map<string, number>();
162
+ tracks.forEach((t, ti) => {
163
+ if (isObj(t) && typeof t.name === "string") {
164
+ const k = key(t.namespace, t.name);
165
+ if (!byName.has(k)) byName.set(k, ti);
166
+ }
167
+ });
168
+ const trackAt = (ti: number) => tracks[ti] as Obj;
169
+
170
+ // Collect instances.
171
+ const insts: Inst[] = [];
172
+ tracks.forEach((t, ti) => {
173
+ // A repair or symbol track's own `fec` is geometry (core rule 8), not instances.
174
+ if (!isObj(t) || !has(t, "fec") || t.packaging === "fec-repair" || t.packaging === "fec-source") return;
175
+ if (!Array.isArray(t.fec)) {
176
+ report("fec_member", `/tracks/${ti}/fec`);
177
+ return;
178
+ }
179
+ t.fec.forEach((o, ii) => {
180
+ const path = `/tracks/${ti}/fec/${ii}`;
181
+ const inst: Inst = {
182
+ path,
183
+ ti,
184
+ track: t,
185
+ obj: isObj(o) ? o : null,
186
+ id: null,
187
+ unavailable: false,
188
+ overlay: false,
189
+ issues: [],
190
+ layer0: null,
191
+ symbolNamed: null,
192
+ attached: [],
193
+ };
194
+ insts.push(inst);
195
+ if (!inst.obj) return report("fec_member", path, inst);
196
+ const o2 = inst.obj;
197
+ if (!has(o2, "instanceId")) inst.id = 0;
198
+ else if (intIn(o2.instanceId, 0, 255)) inst.id = o2.instanceId;
199
+ else report("fec_member", `${path}/instanceId`, inst);
200
+ inst.overlay = has(o2, "scope");
201
+ });
202
+ });
203
+ const declaresFec = insts.length > 0;
204
+
205
+ // Availability (fec-core-00 10.3 rule 1). Scheme first, then profile.
206
+ for (const inst of insts) {
207
+ const o = inst.obj;
208
+ if (!o) continue;
209
+ const avail = (field: "scheme" | "blockProfile", impl: readonly string[]) => {
210
+ const p = `${inst.path}/${field}`;
211
+ const absent = field === "scheme" ? "fec_scheme_absent" : "fec_block_profile_absent";
212
+ const unimpl = field === "scheme" ? "fec_scheme_unimplemented" : "fec_block_profile_unimplemented";
213
+ if (!has(o, field)) return report(absent, p, inst), false;
214
+ if (typeof o[field] !== "string") return report("fec_member", p, inst), true;
215
+ if (!impl.includes(o[field] as string)) return report(unimpl, p, inst), false;
216
+ return true;
217
+ };
218
+ if (!avail("scheme", schemes) || !avail("blockProfile", profiles)) inst.unavailable = true;
219
+ else if (typeof o.blockProfile === "string" && !profileAdmits(o.blockProfile, inst.track.packaging)) {
220
+ report("fec_block_profile_packaging", `${inst.path}/blockProfile`, inst);
221
+ inst.unavailable = true;
222
+ }
223
+ }
224
+ const live = (i: Inst) => !i.unavailable;
225
+
226
+ // Rule 1 on instance members, and core rule 11.
227
+ for (const inst of insts.filter(live)) {
228
+ const o = inst.obj;
229
+ if (!o) continue;
230
+ const p = inst.path;
231
+ for (const m of ["sourceSymbols", "repairSymbols", "symbolSize"])
232
+ if (!intIn(o[m], 1)) report("fec_member", `${p}/${m}`, inst);
233
+ if (typeof o.repairTrack !== "string") report("fec_member", `${p}/repairTrack`, inst);
234
+ if (has(o, "symbolTrack") && typeof o.symbolTrack !== "string") report("fec_member", `${p}/symbolTrack`, inst);
235
+ if (has(o, "interleaveDepthMs")) {
236
+ const d = o.interleaveDepthMs;
237
+ if (!intIn(d, 0) || (d === 0 && o.blockProfile !== "iso-ssbg1-v1"))
238
+ report("fec_member", `${p}/interleaveDepthMs`, inst);
239
+ }
240
+ if (has(o, "reorderToleranceMs")) {
241
+ const r = o.reorderToleranceMs;
242
+ if (typeof r !== "number" || !Number.isFinite(r) || r < 0) report("fec_member", `${p}/reorderToleranceMs`, inst);
243
+ }
244
+ if (has(o, "label") && typeof o.label !== "string") report("fec_member", `${p}/label`, inst);
245
+ if (inst.overlay && o.scope !== "keyframe") report("fec_member", `${p}/scope`, inst);
246
+ }
247
+
248
+ // Core rule 7: unique Instance IDs within a track.
249
+ const idGroups = new Map<string, Inst[]>();
250
+ for (const inst of insts)
251
+ if (inst.id !== null) {
252
+ const k = `${inst.ti}:${inst.id}`;
253
+ idGroups.set(k, [...(idGroups.get(k) ?? []), inst]);
254
+ }
255
+ for (const group of idGroups.values())
256
+ if (group.length > 1)
257
+ for (const inst of group.filter(live))
258
+ report("fec_instance_id", inst.obj && has(inst.obj, "instanceId") ? `${inst.path}/instanceId` : inst.path, inst);
259
+
260
+ // Rule 2: repairTrack / symbolTrack name a track of the right packaging, once
261
+ // per catalog. A name used twice binds no layer 0 or symbol track for either
262
+ // namer; the track is still claimed by the first, so it is not re-attached.
263
+ const nameUses = new Map<string, { inst: Inst; field: "repairTrack" | "symbolTrack" }[]>();
264
+ for (const inst of insts)
265
+ for (const field of ["repairTrack", "symbolTrack"] as const)
266
+ if (inst.obj && typeof inst.obj[field] === "string") {
267
+ const k = key(inst.track.namespace, inst.obj[field] as string);
268
+ nameUses.set(k, [...(nameUses.get(k) ?? []), { inst, field }]);
269
+ }
270
+ const namedBy = new Map<number, Inst>();
271
+ for (const [k, uses] of nameUses) {
272
+ const tj = byName.get(k);
273
+ for (const { inst, field } of uses) {
274
+ const path = `${inst.path}/${field}`;
275
+ if (tj === undefined || trackAt(tj).packaging !== (field === "repairTrack" ? "fec-repair" : "fec-source")) {
276
+ if (live(inst)) report("fec_naming", path, inst);
277
+ } else if (uses.length > 1) {
278
+ if (live(inst)) report("fec_naming", path, inst);
279
+ if (!namedBy.has(tj)) namedBy.set(tj, inst);
280
+ } else {
281
+ namedBy.set(tj, inst);
282
+ if (field === "repairTrack") inst.layer0 = tj;
283
+ else inst.symbolNamed = tj;
284
+ }
285
+ }
286
+ }
287
+
288
+ // Repair and symbol tracks: resolve each to its instance.
289
+ const owner = new Map<number, Inst>();
290
+ if (declaresFec)
291
+ tracks.forEach((t, tj) => {
292
+ if (!isObj(t) || (t.packaging !== "fec-repair" && t.packaging !== "fec-source")) return;
293
+ const tp = `/tracks/${tj}`;
294
+ const named = namedBy.get(tj);
295
+ if (named) {
296
+ owner.set(tj, named);
297
+ if (!live(named)) return;
298
+ // Rule 3: a named track's source / instanceId agree with its namer.
299
+ if (has(t, "source") && t.source !== named.track.name) report("fec_resolution", `${tp}/source`, named);
300
+ if (has(t, "instanceId") && t.instanceId !== named.id) report("fec_resolution", `${tp}/instanceId`, named);
301
+ return;
302
+ }
303
+ if (!has(t, "source")) return report("fec_orphan", tp); // rule 6, stops nothing
304
+ const id = has(t, "instanceId") ? t.instanceId : 0;
305
+ const src = typeof t.source === "string" ? byName.get(key(t.namespace, t.source)) : undefined;
306
+ const target = src === undefined ? undefined : insts.find((i) => i.ti === src && i.id === id);
307
+ if (!target) return report("fec_naming", has(t, "instanceId") && src !== undefined ? `${tp}/instanceId` : `${tp}/source`);
308
+ owner.set(tj, target);
309
+ target.attached.push(tj);
310
+ });
311
+
312
+ // Track fields (rule 1) and no geometry (core rule 8), charged to the owner.
313
+ for (const [tj, inst] of owner) {
314
+ if (!live(inst)) continue;
315
+ const t = trackAt(tj);
316
+ const tp = `/tracks/${tj}`;
317
+ const symbol = t.packaging === "fec-source";
318
+ if (has(t, "source") && typeof t.source !== "string") report("fec_member", `${tp}/source`, inst);
319
+ if (has(t, "instanceId") && !intIn(t.instanceId, 0, 255)) report("fec_member", `${tp}/instanceId`, inst);
320
+ for (const m of ["repairLayer", "repairSymbols"]) {
321
+ if (!has(t, m)) continue;
322
+ if (symbol || !intIn(t[m], m === "repairLayer" ? 0 : 1)) report("fec_member", `${tp}/${m}`, inst);
323
+ }
324
+ if (has(t, "priority") && !intIn(t.priority, symbol ? 0 : 192, 255)) report("fec_member", `${tp}/priority`, inst);
325
+ for (const k of Object.keys(t))
326
+ if (GEOMETRY_KEYS.includes(k) || k.startsWith("groupDuration")) report("fec_track_geometry", `${tp}/${k}`, inst);
327
+ }
328
+
329
+ // Per instance: layers, symbol tracks, priorities, scheme bounds.
330
+ for (const inst of insts.filter(live)) {
331
+ const o = inst.obj;
332
+ if (!o) continue;
333
+ const repairs = inst.attached.filter((tj) => trackAt(tj).packaging === "fec-repair");
334
+ const symbols = inst.attached.filter((tj) => trackAt(tj).packaging === "fec-source");
335
+ if (symbols.length + (inst.symbolNamed !== null ? 1 : 0) > 1)
336
+ for (const tj of symbols) report("fec_symbol_tracks", `/tracks/${tj}`, inst);
337
+
338
+ const l0 = inst.layer0 === null ? null : trackAt(inst.layer0);
339
+ const l0p = `/tracks/${inst.layer0}`;
340
+ if (inst.overlay) {
341
+ // mmt-02 7.4.1: an overlay has one repair track and no repairLayer.
342
+ if (l0 && has(l0, "repairLayer")) report("fec_overlay", `${l0p}/repairLayer`, inst);
343
+ for (const tj of repairs)
344
+ report("fec_overlay", has(trackAt(tj), "repairLayer") ? `/tracks/${tj}/repairLayer` : `/tracks/${tj}`, inst);
345
+ } else {
346
+ if (l0 && has(l0, "repairLayer") && l0.repairLayer !== 0) report("fec_layers", `${l0p}/repairLayer`, inst);
347
+ if (l0 && has(l0, "repairSymbols") && intIn(o.repairSymbols, 1) && l0.repairSymbols !== o.repairSymbols)
348
+ report("fec_layer0", `${l0p}/repairSymbols`, inst);
349
+ const layers: { tj: number; layer: number }[] = [];
350
+ for (const tj of repairs) {
351
+ const t = trackAt(tj);
352
+ if (!has(t, "repairLayer")) report("fec_member", `/tracks/${tj}/repairLayer`, inst);
353
+ else if (t.repairLayer === 0) report("fec_layers", `/tracks/${tj}/repairLayer`, inst);
354
+ else if (intIn(t.repairLayer, 1)) layers.push({ tj, layer: t.repairLayer });
355
+ if (!has(t, "repairSymbols")) report("fec_member", `/tracks/${tj}/repairSymbols`, inst);
356
+ }
357
+ // Core rule 3: layers 1..n contiguous, no duplicates.
358
+ const counts = new Map<number, number>();
359
+ for (const { layer } of layers) counts.set(layer, (counts.get(layer) ?? 0) + 1);
360
+ let missing = 1;
361
+ while (counts.has(missing)) missing++;
362
+ for (const { tj, layer } of layers)
363
+ if (counts.get(layer)! > 1 || layer > missing) report("fec_layers", `/tracks/${tj}/repairLayer`, inst);
364
+ // Core rule 10: priority non-decreasing with layer; layer 0 defaults to 240.
365
+ const chain = [
366
+ { layer: 0, tj: inst.layer0, pri: l0 && intIn(l0.priority, 192, 255) ? l0.priority : l0 && has(l0, "priority") ? null : 240 },
367
+ ...layers.map(({ tj, layer }) => {
368
+ const pr = trackAt(tj).priority;
369
+ return { layer, tj, pri: intIn(pr, 192, 255) ? pr : null };
370
+ }),
371
+ ].sort((a, b) => a.layer - b.layer);
372
+ let prev: number | null = null;
373
+ for (const c of chain) {
374
+ if (c.pri === null) continue;
375
+ if (prev !== null && c.pri < prev) report("fec_priority", `/tracks/${c.tj}/priority`, inst);
376
+ prev = Math.max(prev ?? c.pri, c.pri);
377
+ }
378
+ }
379
+
380
+ // Core rule 5 and the scheme / profile bounds.
381
+ const K = o.sourceSymbols;
382
+ const T = o.symbolSize;
383
+ const P0 = o.repairSymbols;
384
+ if (intIn(K, 1) && intIn(P0, 1)) {
385
+ let P = P0;
386
+ if (!inst.overlay)
387
+ for (const tj of repairs) {
388
+ const t = trackAt(tj);
389
+ if (intIn(t.repairLayer, 1) && intIn(t.repairSymbols, 1)) P += t.repairSymbols;
390
+ }
391
+ if (P > MAX_24 || K + P - 1 > MAX_24) report("fec_bounds", inst.path, inst);
392
+ else if (o.scheme === "reed-solomon" && K + P > RS_MAX_BLOCK) report("fec_bounds", inst.path, inst);
393
+ }
394
+ if (o.scheme === "raptorq" && intIn(K, 1) && K > RAPTORQ_MAX_K) report("fec_bounds", `${inst.path}/sourceSymbols`, inst);
395
+ if (intIn(T, 1)) {
396
+ if (o.scheme === "raptorq" && T % 8 !== 0) report("fec_bounds", `${inst.path}/symbolSize`, inst);
397
+ else if (o.blockProfile === "iso-ssbg1-v1" && T < ISO_MIN_T) report("fec_bounds", `${inst.path}/symbolSize`, inst);
398
+ }
399
+ }
400
+
401
+ // mmt-02 7.4.1 / 7.4.4: overlays, per source track.
402
+ const overlayTracks = new Set(insts.filter((i) => live(i) && i.overlay).map((i) => i.ti));
403
+ for (const ti of overlayTracks) {
404
+ const ofTrack = insts.filter((i) => i.ti === ti && live(i));
405
+ const ovs = ofTrack.filter((i) => i.overlay);
406
+ if (!overlays) {
407
+ for (const ov of ovs) report("fec_overlay_unsupported", `${ov.path}/scope`, ov);
408
+ for (const i of ofTrack) i.issues.length === 0 && i.issues.push({ code: "fec_overlay_unsupported", path: `${ovs[0].path}/scope` });
409
+ continue;
410
+ }
411
+ if (ovs.length > 1) for (const ov of ovs) report("fec_overlay", `${ov.path}/scope`, ov);
412
+ for (const ov of ovs)
413
+ if (ov.obj?.blockProfile !== "iso-ssbg1-v1") report("fec_overlay", `${ov.path}/blockProfile`, ov);
414
+ const cause = ovs.flatMap((ov) => ov.issues).find((x) => x.code === "fec_overlay");
415
+ if (cause) for (const ov of ovs) if (ov.issues.length === 0) ov.issues.push(cause);
416
+ }
417
+
418
+ return {
419
+ instances: insts.map((i) => ({
420
+ path: i.path,
421
+ track: typeof i.track.name === "string" ? i.track.name : null,
422
+ instanceId: i.id,
423
+ outcome: rejectAll || (!i.unavailable && i.issues.length > 0) ? "violation" : i.unavailable ? "unavailable" : "ok",
424
+ issues: i.issues,
425
+ })),
426
+ issues: all,
427
+ };
428
+ }
package/src/index.ts CHANGED
@@ -146,6 +146,17 @@ export {
146
146
  archiveOrigin,
147
147
  } from './carp-catalog.js'
148
148
 
149
+ // FEC catalog binding, draft-ramadan-moq-fec-catalog-00 array shape (BLO-50171).
150
+ export {
151
+ validateFecCatalog,
152
+ type FecCatalogCode,
153
+ type FecCatalogInstance,
154
+ type FecCatalogIssue,
155
+ type FecCatalogOutcome,
156
+ type FecCatalogReceiver,
157
+ type FecCatalogReport,
158
+ } from './fec-catalog.js'
159
+
149
160
  // Strict v2 multicast delivery catalog (DASH/HLS/MMTP routes), moved from
150
161
  // moqtail-private so players share one contract (BLO-47003).
151
162
  export {
@@ -989,9 +989,6 @@ export class MmtpRouter {
989
989
  #onVideoFrame: FrameCallback | null = null;
990
990
  #onAudioFrame: FrameCallback | null = null;
991
991
 
992
- // Init segment (ftyp+moov) from MMTP MPU metadata — needed for MSE SourceBuffer
993
- #onInitSegment: ((data: Uint8Array) => void) | null = null;
994
-
995
992
  // Per-track init segment callbacks keyed by packetId
996
993
  #trackInitCallbacks = new Map<number, (data: Uint8Array) => void>();
997
994
  // Track whether init has been delivered per physical stream — prevent duplicates
@@ -1418,11 +1415,10 @@ export class MmtpRouter {
1418
1415
  }
1419
1416
 
1420
1417
  /**
1421
- * Init segments delivered for a packetId with no `onTrackInit` handler
1422
- * since construction, whether the deprecated aggregate `onInitSegment`
1423
- * callback then received them or nothing did. A supported deployment reads
1424
- * 0 here; a non-zero value is the evidence that blocks removing the
1425
- * aggregate callback (MOQT-01, BLO-21181).
1418
+ * Init segments rejected since construction because their packetId had no
1419
+ * `onTrackInit` handler. A rejected init is delivered nowhere; there is no
1420
+ * aggregate fallback (removed in 1.0.0, MOQT-01 / BLO-21181). A supported
1421
+ * deployment reads 0 here.
1426
1422
  */
1427
1423
  get unmappedInitDeliveryCount(): number {
1428
1424
  return this.#unmappedInitDeliveries;
@@ -1640,21 +1636,10 @@ export class MmtpRouter {
1640
1636
  this.#trackPacketCallbacks.set(packetId, cb);
1641
1637
  }
1642
1638
 
1643
- /**
1644
- * Register an init segment callback (ftyp+moov from MMTP MPU metadata).
1645
- * Receives an init only for a packetId with no `onTrackInit` handler.
1646
- *
1647
- * @deprecated Use onTrackInit(packetId, cb). Still delivered as a fallback;
1648
- * removed in the 1.0.0 major, no earlier than one minor release after this
1649
- * deprecation reaches the `latest` dist-tag (BLO-21181). Count fallback
1650
- * deliveries with `unmappedInitDeliveryCount`.
1651
- */
1652
- onInitSegment(cb: (data: Uint8Array) => void): void {
1653
- this.#onInitSegment = cb;
1654
- }
1655
-
1656
1639
  /** Register an init segment callback for a specific MMTP packetId.
1657
- * Called when FT=0 init arrives via direct source or FEC recovery. */
1640
+ * Called when FT=0 init arrives via direct source or FEC recovery. An init
1641
+ * for a packetId with no handler is rejected and counted by
1642
+ * `unmappedInitDeliveryCount`. */
1658
1643
  onTrackInit(packetId: number, cb: (data: Uint8Array) => void): void {
1659
1644
  this.#trackInitCallbacks.set(packetId, cb);
1660
1645
  }
@@ -3404,16 +3389,16 @@ export class MmtpRouter {
3404
3389
  if (this.#trackInitDelivered.has(streamKey)) return;
3405
3390
  if (data.byteLength <= 8) return;
3406
3391
  this.#trackInitDelivered.add(streamKey);
3392
+ const track = `packetId=${packetId}${catalogTrackName === undefined ? "" : ` track=${catalogTrackName}`}`;
3407
3393
  const cb = this.#trackInitCallbacks.get(packetId);
3408
- if (cb) {
3409
- cb(data);
3410
- } else {
3394
+ if (!cb) {
3395
+ // No aggregate fallback (MOQT-01): an init nobody mapped is rejected.
3411
3396
  this.#unmappedInitDeliveries++;
3412
- this.#onInitSegment?.(data);
3397
+ console.log(`[MmtpRouter] Init rejected for ${track}: no onTrackInit handler`);
3398
+ return;
3413
3399
  }
3414
- console.log(
3415
- `[MmtpRouter] Init delivered for packetId=${packetId}${catalogTrackName === undefined ? "" : ` track=${catalogTrackName}`} (${data.byteLength}B)`,
3416
- );
3400
+ cb(data);
3401
+ console.log(`[MmtpRouter] Init delivered for ${track} (${data.byteLength}B)`);
3417
3402
  }
3418
3403
 
3419
3404
  /**
@@ -110,11 +110,13 @@ export interface MulticastRepairEndpoint {
110
110
  /**
111
111
  * Opens one repair-group subscription through the caller's own provider (a
112
112
  * hang bridge, for one): delivers each packet to `onPacket` and returns (or
113
- * resolves to) the call that releases it.
113
+ * resolves to) the call that releases it. Pass each datagram's sender as
114
+ * `sourceAddress` when known: the group then admits only its first sender,
115
+ * as MulticastTransport does (`packetsDroppedForeignSender`).
114
116
  */
115
117
  export type MulticastRepairSubscribe = (
116
118
  endpoint: MulticastRepairEndpoint,
117
- onPacket: (packet: Uint8Array) => void,
119
+ onPacket: (packet: Uint8Array, sourceAddress?: string) => void,
118
120
  ) => (() => void) | Promise<() => void>;
119
121
 
120
122
  /**
@@ -2032,10 +2034,6 @@ export class MulticastManager {
2032
2034
  onTrackPacket(packetId: number, cb: TrackPacketCallback) {
2033
2035
  this.#router.onTrackPacket(packetId, cb);
2034
2036
  }
2035
- /** @deprecated Use onTrackInit(packetId, cb); see MmtpRouter.onInitSegment. */
2036
- onInitSegment(cb: (data: Uint8Array) => void) {
2037
- this.#router.onInitSegment(cb);
2038
- }
2039
2037
  onTrackInit(packetId: number, cb: (data: Uint8Array) => void) {
2040
2038
  this.#router.onTrackInit(packetId, cb);
2041
2039
  }
@@ -2321,8 +2319,13 @@ export class MulticastManager {
2321
2319
  tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
2322
2320
  ...(endpoint.flow === undefined ? {} : { flow: endpoint.flow }),
2323
2321
  };
2324
- const onPacket = (packet: Uint8Array) => {
2325
- if (!released) this.#router.feedPacket(packet, "multicast", ingress);
2322
+ let sender: string | undefined;
2323
+ const onPacket = (packet: Uint8Array, sourceAddress?: string) => {
2324
+ if (released) return;
2325
+ // The media join's sender owns the repair too; this group's own first
2326
+ // sender stands in only until the media join has one.
2327
+ if (sourceAddress !== undefined && sourceAddress !== (this.#transport.sender ?? (sender ??= sourceAddress))) return;
2328
+ this.#router.feedPacket(packet, "multicast", ingress);
2326
2329
  };
2327
2330
  const fail = (error: unknown) =>
2328
2331
  console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
@@ -2332,7 +2335,10 @@ export class MulticastManager {
2332
2335
  .then((release) => (released ? safely(release) : releases.push(release)), fail);
2333
2336
  continue;
2334
2337
  }
2335
- const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
2338
+ const transport = new MulticastTransport((packet) => onPacket(packet), {
2339
+ gateway: provider,
2340
+ lockedTo: () => this.#transport.sender,
2341
+ });
2336
2342
  releases.push(() => transport.dispose());
2337
2343
  void transport.join({
2338
2344
  sourceAddress: endpoint.source,
@@ -2663,8 +2669,8 @@ export class MulticastManager {
2663
2669
  * transport attribution in FEC path counters.
2664
2670
  * The `router` accessor above is already public.
2665
2671
  */
2666
- feedPacket(data: ArrayBuffer | Uint8Array, ingress?: MmtpIngressContext) {
2667
- this.#transport.feedPacket(data, ingress);
2672
+ feedPacket(data: ArrayBuffer | Uint8Array, ingress?: MmtpIngressContext, sourceAddress?: string) {
2673
+ this.#transport.feedPacket(data, ingress, sourceAddress);
2668
2674
  }
2669
2675
 
2670
2676
  /**