@blockcast/mmt-container 2.2.0-main.88a4d1b4803a → 2.2.0-main.8cff791d86f5

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 (64) hide show
  1. package/dist/browser-runtime.js +94 -25
  2. package/dist/browser-runtime.js.map +2 -2
  3. package/dist/carp-catalog.js.map +2 -2
  4. package/dist/catalog-fec-params.d.ts +1 -1
  5. package/dist/catalog-fec-params.d.ts.map +1 -1
  6. package/dist/catalog-fec-params.js +14 -1
  7. package/dist/catalog-fec-params.js.map +2 -2
  8. package/dist/catalog-network-source.js.map +2 -2
  9. package/dist/delivery-catalog.js.map +2 -2
  10. package/dist/delta-fallback-config.js +5 -1
  11. package/dist/delta-fallback-config.js.map +3 -3
  12. package/dist/fec-manager.d.ts +15 -5
  13. package/dist/fec-manager.d.ts.map +1 -1
  14. package/dist/fec-manager.js +42 -17
  15. package/dist/fec-manager.js.map +2 -2
  16. package/dist/fec-state.js +5 -1
  17. package/dist/fec-state.js.map +2 -2
  18. package/dist/fec-worker-setup.js.map +2 -2
  19. package/dist/held-layer-admission.js.map +2 -2
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +3 -1
  23. package/dist/index.js.map +2 -2
  24. package/dist/iso-block-locator.js.map +2 -2
  25. package/dist/mfu-reassembler.js.map +2 -2
  26. package/dist/mmtp-container-parser.d.ts +6 -0
  27. package/dist/mmtp-container-parser.d.ts.map +1 -1
  28. package/dist/mmtp-container-parser.js +12 -4
  29. package/dist/mmtp-container-parser.js.map +2 -2
  30. package/dist/mmtp-container-parser.no-modules.js +31 -6
  31. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  32. package/dist/mmtp-decode-pipeline.js +12 -4
  33. package/dist/mmtp-decode-pipeline.js.map +2 -2
  34. package/dist/mmtp-fec-session.js.map +2 -2
  35. package/dist/mmtp-router.d.ts +1 -1
  36. package/dist/mmtp-router.d.ts.map +1 -1
  37. package/dist/mmtp-router.js +37 -6
  38. package/dist/mmtp-router.js.map +2 -2
  39. package/dist/multicast-auth-catalog.js.map +2 -2
  40. package/dist/multicast-input.js.map +2 -2
  41. package/dist/multicast-manager.d.ts.map +1 -1
  42. package/dist/multicast-manager.js +85 -25
  43. package/dist/multicast-manager.js.map +2 -2
  44. package/dist/multicast-transport.js.map +2 -2
  45. package/dist/multicast-unwrap.js.map +2 -2
  46. package/dist/no-modules.d.ts +1 -0
  47. package/dist/no-modules.d.ts.map +1 -1
  48. package/dist/no-modules.js +34 -8
  49. package/dist/no-modules.js.map +4 -4
  50. package/dist/repair-fetch.js.map +2 -2
  51. package/dist/repair-layer-subscriptions.js.map +2 -2
  52. package/dist/signaling.js.map +2 -2
  53. package/dist/timestamp-codec.js.map +2 -2
  54. package/dist/wasm-mfu-reassembler.js.map +2 -2
  55. package/dist/wasm-mmtp-container-parser.js +12 -4
  56. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  57. package/package.json +5 -5
  58. package/src/catalog-fec-params.ts +1 -0
  59. package/src/fec-manager.ts +57 -17
  60. package/src/index.ts +2 -0
  61. package/src/mmtp-container-parser.ts +23 -7
  62. package/src/mmtp-router.ts +27 -3
  63. package/src/multicast-manager.ts +3 -1
  64. package/src/no-modules.ts +3 -0
@@ -1797,13 +1797,25 @@ function fecCatalogTracks(catalog) {
1797
1797
  });
1798
1798
  return { tracks, pointers };
1799
1799
  }
1800
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1800
+ function runtimeView(catalog, receiver) {
1801
1801
  const { tracks, pointers } = fecCatalogTracks(catalog);
1802
1802
  const report = validateFecCatalog({ tracks }, receiver);
1803
1803
  const at2 = (path) => {
1804
1804
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
1805
1805
  return m ? pointers[Number(m[1])] + m[2] : path;
1806
1806
  };
1807
+ return { tracks, pointers, report, at: at2 };
1808
+ }
1809
+ function runtimeFecCatalogReport(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1810
+ const { report, at: at2 } = runtimeView(catalog, receiver);
1811
+ const issue = (i) => Object.freeze({ code: i.code, path: at2(i.path) });
1812
+ return Object.freeze({
1813
+ instances: Object.freeze(report.instances.map((i) => Object.freeze({ ...i, path: at2(i.path), issues: Object.freeze(i.issues.map(issue)) }))),
1814
+ issues: Object.freeze(report.issues.map(issue))
1815
+ });
1816
+ }
1817
+ function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
1818
+ const { tracks, pointers, report, at: at2 } = runtimeView(catalog, receiver);
1807
1819
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
1808
1820
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
1809
1821
  const why = (i) => Object.freeze({
@@ -14321,6 +14333,7 @@ var FECManager = class _FECManager {
14321
14333
  this.#workerErrorCounts = /* @__PURE__ */ new Map();
14322
14334
  this.#decoderUnavailableEvents = 0;
14323
14335
  this.#repairSymbolSizeMismatchCount = 0;
14336
+ this.#unlistedRepairTrackRefusals = 0;
14324
14337
  // Event callbacks — block lifecycle notifications for MmtpRouter wiring.
14325
14338
  // NOTE: For sync WASM path, recovery routing is handled by MmtpRouter from
14326
14339
  // feedSourceSymbol/feedRepairSymbol return values. For Worker path, recovery
@@ -14494,6 +14507,7 @@ var FECManager = class _FECManager {
14494
14507
  #workerErrorCounts;
14495
14508
  #decoderUnavailableEvents;
14496
14509
  #repairSymbolSizeMismatchCount;
14510
+ #unlistedRepairTrackRefusals;
14497
14511
  #onUndelimitedLoss;
14498
14512
  #onIsoHoleExpired;
14499
14513
  #encodeTrackName(catalogTrackName) {
@@ -15662,6 +15676,7 @@ var FECManager = class _FECManager {
15662
15676
  packetId
15663
15677
  })),
15664
15678
  repairSymbolSizeMismatches: this.#repairSymbolSizeMismatchCount,
15679
+ unlistedRepairTrackRefusals: this.#unlistedRepairTrackRefusals,
15665
15680
  repairObjectRejects: [...this.#repairObjectRejects.values()].map((r) => ({ ...r })),
15666
15681
  workerErrors: Object.fromEntries(this.#workerErrorCounts)
15667
15682
  };
@@ -16285,7 +16300,7 @@ var FECManager = class _FECManager {
16285
16300
  }
16286
16301
  const trackConfig = this.#trackConfigs.get(packetId);
16287
16302
  if (trackConfig === void 0) return void 0;
16288
- return Math.max(1, trackConfig.timeoutMs - this.#repairDeadlineMs(trackConfig));
16303
+ return Math.max(1, this.#repairGraceMs(trackConfig, this.#multicastWaitMs(trackConfig)));
16289
16304
  }
16290
16305
  /** True once configureTrack/setFecDecoder/setFecWorker configured this packetId. */
16291
16306
  // -----------------------------------------------------------------------
@@ -16532,10 +16547,12 @@ var FECManager = class _FECManager {
16532
16547
  * between two released frames' SS_IDs once only a late source can still
16533
16548
  * fill them, else undefined. That is when every one missing (neither
16534
16549
  * arrived nor held) lies in a repair-less span longer than K, which no
16535
- * repair can state a block of (#openIsoSpan), and a multicast source at or
16536
- * past `toSsId` arrived, so each is lost or reordered behind it (a MoQ
16537
- * source shows nothing: MoQ streams overtake one another). The span itself
16538
- * keeps its whole wait.
16550
+ * repair can state a block of (#openIsoSpan), or in a stated block its
16551
+ * own repair group cannot complete every SS_ID of which it misses lies
16552
+ * between them (so the gap's decision covers all it lost), and a multicast
16553
+ * source at or past `toSsId` arrived, so each is lost or reordered behind
16554
+ * it (a MoQ source shows nothing: MoQ streams overtake one another). The
16555
+ * span or block itself keeps its own wait.
16539
16556
  *
16540
16557
  * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
16541
16558
  * hold a RAP packet an installed keyframe overlay can still rebuild (its
@@ -16544,8 +16561,10 @@ var FECManager = class _FECManager {
16544
16561
  * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
16545
16562
  * overlay's span plus the larger of the allowance and its tolerance, or,
16546
16563
  * for an overlay that states no span, the span's whole wait (undefined).
16564
+ * So does `rapNext` (the gap ends at the RAP that opens the next MPU) when
16565
+ * the gap holds a stated block's loss.
16547
16566
  */
16548
- isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false) {
16567
+ isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false, rapNext = false) {
16549
16568
  const config = this.#trackConfigs.get(packetId);
16550
16569
  if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
16551
16570
  const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
@@ -16553,6 +16572,7 @@ var FECManager = class _FECManager {
16553
16572
  const newestSource = locator.newestSource;
16554
16573
  if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
16555
16574
  let repairless = false;
16575
+ let stated = false;
16556
16576
  for (const block of locator.blocksBetween(fromSsId, toSsId)) {
16557
16577
  const key = this.#blockKey(block.start, packetId, catalogTrackName);
16558
16578
  if (this.#completedBlocks.has(key)) continue;
@@ -16561,14 +16581,21 @@ var FECManager = class _FECManager {
16561
16581
  continue;
16562
16582
  }
16563
16583
  const received = this.#blockSourceEsis.get(key);
16584
+ const rebuilt = this.#blockRebuiltEsis.get(key);
16585
+ let missesInGap = false;
16586
+ let missesOutside = false;
16564
16587
  for (let esi = 0; esi < block.length; esi++) {
16565
16588
  const ssId = serial32Add(block.start, esi);
16566
- if (!serial32Precedes(fromSsId, ssId) || !serial32Precedes(ssId, toSsId)) continue;
16567
- if (!received?.has(esi) && !locator.isHeld(ssId)) return void 0;
16589
+ if (received?.has(esi) || locator.isHeld(ssId)) continue;
16590
+ if (serial32Precedes(fromSsId, ssId) && serial32Precedes(ssId, toSsId)) missesInGap = true;
16591
+ else if (!rebuilt?.has(esi)) missesOutside = true;
16568
16592
  }
16593
+ if (!missesInGap) continue;
16594
+ if (missesOutside || block.span || !this.#groupCannotComplete(key)) return void 0;
16595
+ repairless = stated = true;
16569
16596
  }
16570
16597
  if (!repairless) return void 0;
16571
- const waitMs = rapMayHide ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
16598
+ const waitMs = rapMayHide || stated && rapNext ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
16572
16599
  return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
16573
16600
  }
16574
16601
  /**
@@ -17219,7 +17246,10 @@ var FECManager = class _FECManager {
17219
17246
  this.#layerAnchorHorizon(packetId),
17220
17247
  this.#sourceFrontiers.get(streamKey)?.sbn
17221
17248
  );
17222
- if (verdict === "discard") return false;
17249
+ if (verdict === "discard") {
17250
+ this.#unlistedRepairTrackRefusals++;
17251
+ return false;
17252
+ }
17223
17253
  if (verdict !== void 0) {
17224
17254
  this.#failClosed(streamKey, verdict, packetId, catalogTrackName);
17225
17255
  return false;
@@ -17403,20 +17433,27 @@ var FECManager = class _FECManager {
17403
17433
  * (isoRepairlessWaitMs).
17404
17434
  */
17405
17435
  #lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
17406
- if (this.#isoSpanKeys.has(key)) return void 0;
17436
+ if (this.#isoSpanKeys.has(key) || !this.#groupCannotComplete(key)) return void 0;
17407
17437
  const authoredLength = this.#blockAuthoredLengths.get(key);
17408
- const rsbLength = this.#blockRsbLengths.get(key);
17409
- if (authoredLength === void 0 || rsbLength === void 0) return void 0;
17410
- let present = this.#blockSourceCounts.get(key) ?? 0;
17411
- const received = this.#blockSourceEsis.get(key);
17412
- for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
17413
- if (present + rsbLength >= authoredLength) return void 0;
17414
17438
  const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource;
17415
17439
  if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
17416
17440
  return void 0;
17417
17441
  }
17418
17442
  return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
17419
17443
  }
17444
+ /**
17445
+ * A repair stated the block, and its sources plus every symbol its repair
17446
+ * group carries (RSB_length) are short of its SSB_length.
17447
+ */
17448
+ #groupCannotComplete(key) {
17449
+ const authoredLength = this.#blockAuthoredLengths.get(key);
17450
+ const rsbLength = this.#blockRsbLengths.get(key);
17451
+ if (authoredLength === void 0 || rsbLength === void 0) return false;
17452
+ let present = this.#blockSourceCounts.get(key) ?? 0;
17453
+ const received = this.#blockSourceEsis.get(key);
17454
+ for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++;
17455
+ return present + rsbLength < authoredLength;
17456
+ }
17420
17457
  /**
17421
17458
  * How long a loss only a late source or an installed keyframe overlay can
17422
17459
  * still fill waits once a later source passed it: the late-symbol
@@ -19082,7 +19119,7 @@ var FecReleaseSequencer = class {
19082
19119
  from
19083
19120
  );
19084
19121
  unresolved = resolved === null;
19085
- if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(last, head, from, to)) {
19122
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
19086
19123
  const heldMs = performance.now() - head.arrivedAtMs;
19087
19124
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
19088
19125
  this.#recordStat("forcedWindowFlushes");
@@ -19100,10 +19137,18 @@ var FecReleaseSequencer = class {
19100
19137
  );
19101
19138
  }
19102
19139
  }
19103
- /** The head has waited out a gap only a late source can still fill (FecReleaseGate.unrepairableWaitMs). */
19104
- #unrepairableWaitOver(last, head, from, to) {
19140
+ /**
19141
+ * The head has waited out a gap only a late source can still fill
19142
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
19143
+ * the stream when it has (`wakeAt`), since no packet may come by then.
19144
+ */
19145
+ #unrepairableWaitOver(stream, last, head, from, to) {
19105
19146
  const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
19106
- return waitMs !== void 0 && performance.now() - head.arrivedAtMs >= waitMs;
19147
+ if (waitMs === void 0) return false;
19148
+ const atMs = head.arrivedAtMs + waitMs;
19149
+ if (performance.now() >= atMs) return true;
19150
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
19151
+ return false;
19107
19152
  }
19108
19153
  /**
19109
19154
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
@@ -23686,6 +23731,8 @@ var MmtpRouter = class {
23686
23731
  // end: a synchronous recovery completes its block BEFORE routing the
23687
23732
  // recovered frames, and releasing a held gap in between would strand them.
23688
23733
  #fecPokeDepth = 0;
23734
+ /** FecReleaseGate.wakeAt timers, by media stream key. */
23735
+ #fecWakes = /* @__PURE__ */ new Map();
23689
23736
  #pendingFecPokes = /* @__PURE__ */ new Map();
23690
23737
  // ── Phase 14: per-role packetId dispatch (D-26, D-27, D-28) ───────
23691
23738
  /** Maps packetId → TrackRole. Default: 'single' when absent (legacy path). */
@@ -25746,6 +25793,8 @@ var MmtpRouter = class {
25746
25793
  this.#disposed = true;
25747
25794
  this.#staged = null;
25748
25795
  this.cancelKeyframeLostTimer();
25796
+ for (const { timer } of this.#fecWakes.values()) clearTimeout(timer);
25797
+ this.#fecWakes.clear();
25749
25798
  this.#parser.dispose();
25750
25799
  this.#streams.clear();
25751
25800
  this.#trackPacketCallbacks.clear();
@@ -25931,7 +25980,9 @@ var MmtpRouter = class {
25931
25980
  // late source can), its frame waits the late-symbol allowance when the
25932
25981
  // gap holds no RAP an installed keyframe overlay could still rebuild:
25933
25982
  // lost deltas of one MPU (delta-lost), the tail of the MPU before a RAP
25934
- // that opens the next one while MPU boundaries bound RAPs (rap-next), or
25983
+ // that opens the next one while MPU boundaries bound RAPs (rap-next,
25984
+ // unless the gap holds a stated block's loss: the overlay may rebuild
25985
+ // that MPU's FT=0, and the block's group then complete it), or
25935
25986
  // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
25936
25987
  // other rap-next, whose gap may hold a whole MPU and the keyframe the
25937
25988
  // overlay protects) waits for that overlay's repair too (BLO-52085
@@ -25945,7 +25996,10 @@ var MmtpRouter = class {
25945
25996
  const decision = this.#decideGap(before, after, [], false);
25946
25997
  const mpu = before.meta.mpuSequenceNumber;
25947
25998
  const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
25948
- return decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true) : allowanceMs;
25999
+ if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
26000
+ return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
26001
+ }
26002
+ return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
25949
26003
  },
25950
26004
  decide: (before, after, lostBlocks, discontinuity) => {
25951
26005
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
@@ -25956,6 +26010,20 @@ var MmtpRouter = class {
25956
26010
  onRap: (packetId, catalogTrackName, ssId) => {
25957
26011
  for (const observer of this.#fecRapObservers) observer(packetId, catalogTrackName, ssId);
25958
26012
  },
26013
+ // One timer per stream, at the earliest wake asked: its drain re-arms
26014
+ // for the next frame still waiting.
26015
+ wakeAt: (packetId, catalogTrackName, atMs) => {
26016
+ if (this.#disposed) return;
26017
+ const key = this.#mediaStreamKey(packetId, catalogTrackName);
26018
+ const armed = this.#fecWakes.get(key);
26019
+ if (armed !== void 0 && armed.atMs <= atMs) return;
26020
+ if (armed !== void 0) clearTimeout(armed.timer);
26021
+ const timer = setTimeout(() => {
26022
+ this.#fecWakes.delete(key);
26023
+ this.#requestFecPoke(packetId, catalogTrackName);
26024
+ }, Math.max(0, Math.ceil(atMs - performance.now())));
26025
+ this.#fecWakes.set(key, { atMs, timer });
26026
+ },
25959
26027
  // A staged switch commits on when each side's frames reach it
25960
26028
  // (#interceptSwitchFrame): both sides' overlay keyframes reach it when
25961
26029
  // they did unanchored.
@@ -29777,7 +29845,7 @@ var MulticastManager = class {
29777
29845
  console.warn("[MulticastManager] repair group release failed", error);
29778
29846
  }
29779
29847
  };
29780
- const usedFlows = /* @__PURE__ */ new Set();
29848
+ const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === void 0 ? [] : [flow]));
29781
29849
  const preparedProvenance = endpoints.map((endpoint) => {
29782
29850
  if (endpoint.provenance === void 0) return void 0;
29783
29851
  const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
@@ -34254,6 +34322,7 @@ export {
34254
34322
  resolveGroupDurationMs,
34255
34323
  resolveGroupDurationTicks,
34256
34324
  resolveRepairLayers,
34325
+ runtimeFecCatalogReport,
34257
34326
  secondsFromTicks,
34258
34327
  setupFecWorkerForTrack,
34259
34328
  setupTrackPipeline,