@blockcast/mmt-container 0.4.1 → 0.5.0-main.2c1f81817995

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.
Files changed (72) hide show
  1. package/README.md +2 -2
  2. package/dist/browser-runtime.js +3458 -356
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/cmcd-producer.d.ts +5 -1
  5. package/dist/cmcd-producer.d.ts.map +1 -1
  6. package/dist/cmcd-producer.js.map +2 -2
  7. package/dist/delivery-catalog.js +18 -2
  8. package/dist/delivery-catalog.js.map +2 -2
  9. package/dist/fec-manager.d.ts +21 -16
  10. package/dist/fec-manager.d.ts.map +1 -1
  11. package/dist/fec-manager.js +177 -80
  12. package/dist/fec-manager.js.map +3 -3
  13. package/dist/held-layer-admission.d.ts +58 -0
  14. package/dist/held-layer-admission.d.ts.map +1 -0
  15. package/dist/held-layer-admission.js +105 -0
  16. package/dist/held-layer-admission.js.map +7 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +2 -2
  19. package/dist/mmtp-container-parser.no-modules.js +2682 -1023
  20. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  21. package/dist/mmtp-fec-session.d.ts +36 -3
  22. package/dist/mmtp-fec-session.d.ts.map +1 -1
  23. package/dist/mmtp-fec-session.js +114 -5
  24. package/dist/mmtp-fec-session.js.map +3 -3
  25. package/dist/mmtp-router.d.ts +72 -28
  26. package/dist/mmtp-router.d.ts.map +1 -1
  27. package/dist/mmtp-router.js +321 -203
  28. package/dist/mmtp-router.js.map +2 -2
  29. package/dist/multicast-auth-catalog.d.ts +10 -2
  30. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  31. package/dist/multicast-auth-catalog.js +422 -22
  32. package/dist/multicast-auth-catalog.js.map +4 -4
  33. package/dist/multicast-manager.d.ts +48 -9
  34. package/dist/multicast-manager.d.ts.map +1 -1
  35. package/dist/multicast-manager.js +3406 -340
  36. package/dist/multicast-manager.js.map +4 -4
  37. package/dist/multicast-transport.d.ts +4 -1
  38. package/dist/multicast-transport.d.ts.map +1 -1
  39. package/dist/multicast-transport.js +20 -3
  40. package/dist/multicast-transport.js.map +2 -2
  41. package/dist/no-modules.d.ts +1 -2
  42. package/dist/no-modules.d.ts.map +1 -1
  43. package/dist/no-modules.js +2668 -1007
  44. package/dist/no-modules.js.map +4 -4
  45. package/dist/repair-fetch.d.ts +10 -1
  46. package/dist/repair-fetch.d.ts.map +1 -1
  47. package/dist/repair-fetch.js +5 -2
  48. package/dist/repair-fetch.js.map +2 -2
  49. package/package.json +5 -14
  50. package/src/cmcd-producer.ts +6 -1
  51. package/src/fec-manager.ts +121 -131
  52. package/src/held-layer-admission.ts +161 -0
  53. package/src/index.ts +5 -9
  54. package/src/mmtp-fec-session.ts +76 -3
  55. package/src/mmtp-router.ts +390 -272
  56. package/src/multicast-auth-catalog.ts +81 -8
  57. package/src/multicast-manager.ts +189 -48
  58. package/src/multicast-transport.ts +6 -2
  59. package/src/no-modules.ts +1 -6
  60. package/src/repair-fetch.ts +24 -4
  61. package/dist/manifest-auth-plan.d.ts +0 -31
  62. package/dist/manifest-auth-plan.d.ts.map +0 -1
  63. package/dist/manifest-auth-plan.js +0 -426
  64. package/dist/manifest-auth-plan.js.map +0 -7
  65. package/dist/source-auth.d.ts +0 -2
  66. package/dist/source-auth.d.ts.map +0 -1
  67. package/dist/source-auth.js +0 -3912
  68. package/dist/source-auth.js.map +0 -7
  69. package/src/manifest-auth-plan.ts +0 -55
  70. package/src/source-auth.ts +0 -1
  71. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  72. package/test-vectors/source-auth-v1.json +0 -61
@@ -18,11 +18,18 @@
18
18
  * The retention is derived from the catalog's `fecBlockBudgetMs`, and a
19
19
  * catalog missing either input throws rather than defaulting.
20
20
  *
21
+ * Every repair packet runs the fec-01 6.3.9 held-layer check (layer 0, B_0 =
22
+ * catalog `fec.repairSymbols`) through the same HeldLayerAdmission FECManager
23
+ * uses. A packet below B_0 at or after the anchor fails the session closed:
24
+ * `stats.failClosed` reports why, and every later repair is refused.
25
+ *
21
26
  * Every repair packet that cannot be used is counted under the reason it was
22
27
  * refused, and every block ends under exactly one outcome, so a stream whose
23
28
  * FEC is doing nothing can be told apart from one with nothing to repair.
24
29
  */
25
30
  import { type FecBlockProfile } from '@blockcast/mmt-base';
31
+ import { type FecFailClosedReason, type HeldLayerInput } from './held-layer-admission.js';
32
+ export type { FecFailClosedReason, HeldLayerInput } from './held-layer-admission.js';
26
33
  /** The mmt-wasm `MmtFecDecoder` members the session drives. */
27
34
  export interface MmtpFecSessionDecoder {
28
35
  configure_params(k: number, symbolSize: number): void;
@@ -40,6 +47,10 @@ export interface MmtpFecSessionCatalogFec {
40
47
  algorithm?: unknown;
41
48
  blockProfile?: unknown;
42
49
  sourceSymbols?: unknown;
50
+ /** P_0: layer 0's repair symbols per block, the fec-01 6.3.9 total B_0. */
51
+ repairSymbols?: unknown;
52
+ /** Layer 0's repair track; names it for addRepair()'s `repairTrackName`. */
53
+ repairTrack?: unknown;
43
54
  symbolSize?: unknown;
44
55
  interleaveDepthMs?: unknown;
45
56
  reorderToleranceMs?: unknown;
@@ -49,6 +60,14 @@ export interface MmtpFecSessionConfig {
49
60
  fec: MmtpFecSessionCatalogFec;
50
61
  /** Builds the RaptorQ decoder, normally `wasm_bindgen.MmtFecDecoder`. */
51
62
  Decoder: MmtpFecSessionDecoderConstructor;
63
+ /**
64
+ * The source's repair layers as the catalog resolves them
65
+ * (`TrackFecParams.repairLayers`), for a caller that subscribes more than
66
+ * layer 0. Absent: layer 0 alone, B_0 = `fec.repairSymbols`.
67
+ */
68
+ repairLayers?: readonly HeldLayerInput[];
69
+ /** The layers the caller holds (fec-01 6.3.9). Absent: [0]. */
70
+ heldLayers?: readonly number[];
52
71
  }
53
72
  /**
54
73
  * The path a symbol arrived on: its MoQT subscription, or the multicast
@@ -107,6 +126,16 @@ export interface MmtpFecSessionStats {
107
126
  * contributed nothing to its block and do not make it mixed.
108
127
  */
109
128
  mixedPath: MmtpFecSessionMixedPathStats;
129
+ /**
130
+ * fec-01 6.3.9: null until a repair packet at or after the anchor (the
131
+ * earliest block, in SS_Start serial order, whose repair carried
132
+ * RSB_length >= B_0) states an RSB_length below B_0; then why. Terminal:
133
+ * every later repair is refused under `repair:fail-closed` (the packet that
134
+ * failed it is counted there too), and block state stays as it was. Sources
135
+ * are still taken and can still complete a block from repair admitted
136
+ * before the failure.
137
+ */
138
+ failClosed: FecFailClosedReason | null;
110
139
  }
111
140
  /**
112
141
  * One asset's in-band FEC state. See the file comment.
@@ -116,12 +145,14 @@ export declare class MmtpFecSession {
116
145
  readonly blockProfile: FecBlockProfile;
117
146
  readonly algorithm: 'raptorq' | 'reed-solomon';
118
147
  readonly sourceSymbols: number;
148
+ /** P_0 = B_0, the held total every repair packet is checked against. */
149
+ readonly repairSymbols: number;
119
150
  readonly symbolSize: number;
120
151
  /** The decoder's retention, in blocks, derived from the catalog budget. */
121
152
  readonly retentionBlocks: number;
122
153
  /**
123
154
  * @throws when the catalog block lacks or misstates a field the session
124
- * needs: the block profile, K, T, `interleaveDepthMs` or
155
+ * needs: the block profile, K, P_0 (`repairSymbols`), T, `interleaveDepthMs` or
125
156
  * `reorderToleranceMs`. None is defaulted.
126
157
  */
127
158
  constructor(config: MmtpFecSessionConfig);
@@ -143,12 +174,14 @@ export declare class MmtpFecSession {
143
174
  * Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
144
175
  * 23008-1 C.5.3). A repair track carries one repair flow, so the first
145
176
  * repair packet fixes its packet ID and a packet of any other is refused.
146
- * `path` is where it was received, as for addSource().
177
+ * `path` is where it was received, as for addSource(). `repairTrackName`
178
+ * is the repair track it was received on, for the 6.3.9 own-track rule; a
179
+ * track the layers do not list is refused as `repair:unlisted-track`.
147
180
  *
148
181
  * @returns the protected packets this repair symbol recovered, as for
149
182
  * addSource().
150
183
  */
151
- addRepair(packet: Uint8Array, path?: MmtpFecSessionPath): Uint8Array[];
184
+ addRepair(packet: Uint8Array, path?: MmtpFecSessionPath, repairTrackName?: string): Uint8Array[];
152
185
  /**
153
186
  * Frees the decoder and every block. Blocks still unsettled are counted as
154
187
  * released, not failed: nothing proved them unrecoverable. Idempotent;
@@ -1 +1 @@
1
- {"version":3,"file":"mmtp-fec-session.d.ts","sourceRoot":"","sources":["../src/mmtp-fec-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAWL,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAA;AAG5B,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACrD,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,CAAA;IAC5F,UAAU,CACR,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,GAChB,UAAU,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAAA;IACjD,uBAAuB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAA;IACvD,IAAI,IAAI,IAAI,CAAA;CACb;AAED,wEAAwE;AACxE,MAAM,MAAM,gCAAgC,GAAG,KAC7C,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,KACf,qBAAqB,CAAA;AAE1B,kDAAkD;AAClD,MAAM,WAAW,wBAAwB;IACvC,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,U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MAAM,CAAA;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAmChC;;;;OAIG;gBACS,MAAM,EAAE,oBAAoB;IA4CxC,+BAA+B;IAC/B,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,KAAK,IAAI,mBAAmB,CAS/B;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,kBAA0B,GAAG,UAAU,EAAE;IAyC3F;;;;;;;;;;OAUG;IACH,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,kBAA0B,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IA4EvG;;;;OAIG;IACH,OAAO,IAAI,OAAO;CAmJnB"}
@@ -187,6 +187,81 @@ var ALL_ROLES = Object.freeze(["video", "audio"]);
187
187
 
188
188
  // src/mmtp-fec-session.ts
189
189
  import { deriveFecRetentionBlocks, fecBlockBudgetMs } from "@blockcast/mmt-fec";
190
+
191
+ // src/held-layer-admission.ts
192
+ var HORIZON_CAP = 1073741824;
193
+ function heldLayerAnchorHorizon(retentionBlocks, k) {
194
+ return retentionBlocks === void 0 || k <= 0 ? HORIZON_CAP : Math.min(HORIZON_CAP, retentionBlocks * k);
195
+ }
196
+ var HeldLayerAdmission = class {
197
+ #layerNames;
198
+ #states;
199
+ constructor(layers, heldLayers = [0]) {
200
+ const held = new Set(heldLayers);
201
+ this.#layerNames = new Set(layers.map((l) => l.repairTrackName));
202
+ this.#states = layers.filter((l) => held.has(l.layer)).map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }));
203
+ }
204
+ /**
205
+ * Judges one repair packet, after the 4.5 discards and the size check and
206
+ * before it places a block. `repairTrackName` is the subscribed repair
207
+ * track, never inferred from RS_ID; without it only (b) runs. A packet on a
208
+ * repair track the catalog does not list is `'discard'` and anchors nothing.
209
+ * `sourceFrontier` is the newest source SS_ID, if any: a repair more than
210
+ * `horizon` past it is judged without moving the anchored state.
211
+ *
212
+ * @returns undefined to admit, `'discard'`, or the fail-closed reason.
213
+ */
214
+ admit(repairTrackName, ssStart, rsbLength, horizon, sourceFrontier) {
215
+ if (repairTrackName !== void 0 && !this.#layerNames.has(repairTrackName)) return "discard";
216
+ const farAhead = sourceFrontier !== void 0 && serial32Precedes(sourceFrontier, ssStart) && serial32Distance(sourceFrontier, ssStart) > horizon;
217
+ for (const state of this.#states) {
218
+ let code;
219
+ if (farAhead) {
220
+ if (rsbLength < state.total) {
221
+ if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
222
+ else if (state.anchor !== void 0 || state.settled) code = "below_anchored_total";
223
+ }
224
+ } else {
225
+ if (state.newest === void 0 || serial32Precedes(state.newest, ssStart)) state.newest = ssStart;
226
+ const stale = (s) => serial32Distance(s, state.newest) > horizon;
227
+ if (state.latestBelow !== void 0 && stale(state.latestBelow)) {
228
+ delete state.latestBelow;
229
+ delete state.latestBelowRsb;
230
+ }
231
+ if (state.anchor !== void 0 && stale(state.anchor)) state.settled = true;
232
+ if (rsbLength < state.total) {
233
+ if (state.layer > 0 && repairTrackName === state.repairTrackName) code = "below_own_track_total";
234
+ else if (stale(ssStart)) continue;
235
+ else if (state.settled || state.anchor !== void 0 && !serial32Precedes(ssStart, state.anchor)) code = "below_anchored_total";
236
+ else if (state.latestBelow === void 0 || serial32Precedes(state.latestBelow, ssStart)) {
237
+ state.latestBelow = ssStart;
238
+ state.latestBelowRsb = rsbLength;
239
+ }
240
+ } else if (!state.settled && !stale(ssStart)) {
241
+ if (state.anchor === void 0 || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart;
242
+ if (state.latestBelow !== void 0 && !serial32Precedes(state.latestBelow, state.anchor)) {
243
+ code = "below_anchored_total";
244
+ ssStart = state.latestBelow;
245
+ rsbLength = state.latestBelowRsb;
246
+ }
247
+ }
248
+ }
249
+ if (code !== void 0) {
250
+ return {
251
+ code,
252
+ layer: state.layer,
253
+ total: state.total,
254
+ rsbLength,
255
+ ssStart,
256
+ ...state.anchor === void 0 ? {} : { anchor: state.anchor }
257
+ };
258
+ }
259
+ }
260
+ return void 0;
261
+ }
262
+ };
263
+
264
+ // src/mmtp-fec-session.ts
190
265
  var PATH_BITS = { moq: 1, multicast: 2 };
191
266
  var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
192
267
  var MmtpFecSession = class {
@@ -204,6 +279,9 @@ var MmtpFecSession = class {
204
279
  /** The newest SS_ID when the remembered SS_IDs were last pruned. */
205
280
  #prunedAt;
206
281
  #repairPacketId;
282
+ #newestSource;
283
+ #heldLayers;
284
+ #anchorHorizon;
207
285
  #stats = {
208
286
  sourceSymbols: 0,
209
287
  repairSymbols: 0,
@@ -216,11 +294,12 @@ var MmtpFecSession = class {
216
294
  dropped: {},
217
295
  sourceSymbolsByPath: { moq: 0, multicast: 0 },
218
296
  repairSymbolsByPath: { moq: 0, multicast: 0 },
219
- mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
297
+ mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 },
298
+ failClosed: null
220
299
  };
221
300
  /**
222
301
  * @throws when the catalog block lacks or misstates a field the session
223
- * needs: the block profile, K, T, `interleaveDepthMs` or
302
+ * needs: the block profile, K, P_0 (`repairSymbols`), T, `interleaveDepthMs` or
224
303
  * `reorderToleranceMs`. None is defaulted.
225
304
  */
226
305
  constructor(config) {
@@ -234,6 +313,7 @@ var MmtpFecSession = class {
234
313
  }
235
314
  this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
236
315
  this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
316
+ this.repairSymbols = requirePositiveInteger(fec.repairSymbols, "fec.repairSymbols");
237
317
  this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
238
318
  const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
239
319
  const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
@@ -241,6 +321,18 @@ var MmtpFecSession = class {
241
321
  fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
242
322
  interleaveDepthMs
243
323
  );
324
+ this.#heldLayers = new HeldLayerAdmission(
325
+ config.repairLayers ?? [
326
+ {
327
+ layer: 0,
328
+ repairTrackName: typeof fec.repairTrack === "string" ? fec.repairTrack : "",
329
+ rsIdOffset: 0,
330
+ repairSymbols: this.repairSymbols
331
+ }
332
+ ],
333
+ config.heldLayers
334
+ );
335
+ this.#anchorHorizon = heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols);
244
336
  if (typeof config.Decoder !== "function") {
245
337
  throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
246
338
  }
@@ -263,7 +355,8 @@ var MmtpFecSession = class {
263
355
  dropped: { ...this.#stats.dropped },
264
356
  sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
265
357
  repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
266
- mixedPath: { ...this.#stats.mixedPath }
358
+ mixedPath: { ...this.#stats.mixedPath },
359
+ failClosed: this.#stats.failClosed && { ...this.#stats.failClosed }
267
360
  };
268
361
  }
269
362
  /**
@@ -288,6 +381,7 @@ var MmtpFecSession = class {
288
381
  this.#stats.sourceSymbols++;
289
382
  this.#stats.sourceSymbolsByPath[path]++;
290
383
  this.#noteNewest(ssId);
384
+ if (this.#newestSource === void 0 || serial32Precedes(this.#newestSource, ssId)) this.#newestSource = ssId;
291
385
  const start = this.#blockStartOf(ssId);
292
386
  const block = start === void 0 ? void 0 : this.#blocks.get(start);
293
387
  if (block) {
@@ -316,14 +410,17 @@ var MmtpFecSession = class {
316
410
  * Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
317
411
  * 23008-1 C.5.3). A repair track carries one repair flow, so the first
318
412
  * repair packet fixes its packet ID and a packet of any other is refused.
319
- * `path` is where it was received, as for addSource().
413
+ * `path` is where it was received, as for addSource(). `repairTrackName`
414
+ * is the repair track it was received on, for the 6.3.9 own-track rule; a
415
+ * track the layers do not list is refused as `repair:unlisted-track`.
320
416
  *
321
417
  * @returns the protected packets this repair symbol recovered, as for
322
418
  * addSource().
323
419
  */
324
- addRepair(packet, path = "moq") {
420
+ addRepair(packet, path = "moq", repairTrackName) {
325
421
  const decoder = this.#decoder;
326
422
  if (!decoder) return this.#drop("repair:released");
423
+ if (this.#stats.failClosed) return this.#drop("repair:fail-closed");
327
424
  const pathBit = PATH_BITS[path];
328
425
  if (!pathBit) return this.#drop("repair:unknown-path");
329
426
  let header;
@@ -344,6 +441,18 @@ var MmtpFecSession = class {
344
441
  if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
345
442
  return this.#drop("repair:rs-block-length");
346
443
  }
444
+ const verdict = this.#heldLayers.admit(
445
+ repairTrackName,
446
+ frame.ssStart,
447
+ frame.rsbLength,
448
+ this.#anchorHorizon,
449
+ this.#newestSource
450
+ );
451
+ if (verdict === "discard") return this.#drop("repair:unlisted-track");
452
+ if (verdict !== void 0) {
453
+ this.#stats.failClosed = verdict;
454
+ return this.#drop("repair:fail-closed");
455
+ }
347
456
  const start = frame.ssStart;
348
457
  let block = this.#blocks.get(start);
349
458
  if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");