@blockcast/mmt-container 0.4.0-main.88b772ee21c8 → 0.4.0-main.94b7ef7dcd8d

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 (71) hide show
  1. package/README.md +16 -5
  2. package/dist/browser-runtime.js +84 -29
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/carp-catalog.d.ts +5 -0
  5. package/dist/carp-catalog.d.ts.map +1 -1
  6. package/dist/carp-catalog.js +4 -0
  7. package/dist/carp-catalog.js.map +2 -2
  8. package/dist/catalog-fec-params.d.ts.map +1 -1
  9. package/dist/catalog-fec-params.js +6 -3
  10. package/dist/catalog-fec-params.js.map +2 -2
  11. package/dist/catalog-network-source.js.map +1 -1
  12. package/dist/delivery-catalog.js +2 -10
  13. package/dist/delivery-catalog.js.map +4 -4
  14. package/dist/fec-manager.js.map +1 -1
  15. package/dist/fec-state.d.ts.map +1 -1
  16. package/dist/fec-state.js +14 -2
  17. package/dist/fec-state.js.map +3 -3
  18. package/dist/fec-worker-setup.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js.map +2 -2
  22. package/dist/iso-block-locator.js.map +1 -1
  23. package/dist/mfu-reassembler.js.map +2 -2
  24. package/dist/mmtp-container-parser.js.map +2 -2
  25. package/dist/mmtp-container-parser.no-modules.js +99 -21
  26. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  27. package/dist/mmtp-decode-pipeline.js.map +2 -2
  28. package/dist/mmtp-fec-session.d.ts +40 -4
  29. package/dist/mmtp-fec-session.d.ts.map +1 -1
  30. package/dist/mmtp-fec-session.js +58 -18
  31. package/dist/mmtp-fec-session.js.map +2 -2
  32. package/dist/mmtp-router.d.ts.map +1 -1
  33. package/dist/mmtp-router.js +17 -0
  34. package/dist/mmtp-router.js.map +2 -2
  35. package/dist/multicast-input.js.map +1 -1
  36. package/dist/multicast-manager.js +17 -8
  37. package/dist/multicast-manager.js.map +4 -4
  38. package/dist/multicast-transport.js +0 -8
  39. package/dist/multicast-transport.js.map +4 -4
  40. package/dist/multicast-unwrap.js.map +2 -2
  41. package/dist/no-modules.d.ts +1 -0
  42. package/dist/no-modules.d.ts.map +1 -1
  43. package/dist/no-modules.js +98 -20
  44. package/dist/no-modules.js.map +4 -4
  45. package/dist/repair-fetch.js.map +1 -1
  46. package/dist/repair-layers.js.map +1 -1
  47. package/dist/signaling.d.ts +2 -2
  48. package/dist/signaling.d.ts.map +1 -1
  49. package/dist/signaling.js +3 -3
  50. package/dist/signaling.js.map +2 -2
  51. package/dist/timestamp-codec.js.map +2 -2
  52. package/dist/wasm-mfu-reassembler.js.map +1 -1
  53. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  54. package/package.json +5 -5
  55. package/schemas/catalog.schema.json +7 -1
  56. package/src/carp-catalog.ts +18 -1
  57. package/src/catalog-fec-params.ts +4 -1
  58. package/src/fec-state.ts +3 -2
  59. package/src/index.ts +3 -0
  60. package/src/mmtp-fec-session.ts +99 -18
  61. package/src/mmtp-router.ts +25 -0
  62. package/src/no-modules.ts +1 -0
  63. package/src/signaling.ts +2 -2
  64. package/test-vectors/catalog/README.md +8 -0
  65. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  66. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  67. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  68. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  69. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  70. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  71. package/test-vectors/catalog/section-codes.json +6 -0
package/README.md CHANGED
@@ -121,7 +121,7 @@ function parseAlFecMessage(buf: Uint8Array): AlFecMessage | null // every FEC
121
121
  function parseMoqRepairFrame(buf: Uint8Array): MoqRepairFrame
122
122
  ```
123
123
 
124
- Constants worth knowing: `MMTP_HEADER_SIZE = 12`, `MPU_HEADER_SIZE = 8`, `MFU_DU_HEADER_SIZE_TIMED = 14`, `PACKET_TYPE_MPU = 0x00`, `PACKET_TYPE_REPAIR = 0x03`, `ALFEC_MESSAGE_ID = 0x0203`, `FEC_CODE_RAPTORQ = 2`.
124
+ Constants worth knowing: `MMTP_HEADER_SIZE = 12`, `MPU_HEADER_SIZE = 8`, `MFU_DU_HEADER_SIZE_TIMED = 14`, `PACKET_TYPE_MPU = 0x00`, `PACKET_TYPE_REPAIR = 0x03`, `ALFEC_MESSAGE_ID = 0x0203`, `FEC_CODE_RAPTORQ = 3`, `FEC_CODE_REED_SOLOMON = 1`.
125
125
 
126
126
  ```ts
127
127
  import { parseMMTPHeader, extractMFUPayload } from "@blockcast/mmt-base"
@@ -248,7 +248,9 @@ non-DRIAD AMT entry, so the manual one carries the relay while the DRIAD one
248
248
  keeps the discovery request. An `atsc3` endpoint now
249
249
  requires a `{type: "atsc3", …}` entry and throws `atsc3_requires_tuning`
250
250
  without one: that entry carries the frequency, PLP, service id and SLS URI,
251
- which is the only tuning information an ATSC3 receiver has, and the schema
251
+ which is the only tuning information an ATSC3 receiver has (the SLS behind
252
+ `slsUri` describes the MMTP session, MP table included, per A/331:2026-04 7.2,
253
+ and nothing of this profile, so `manifestPort` and keys come from provisioning), and the schema
252
254
  cannot enforce it because `networkSource` is optional there (a native join has
253
255
  none). `version`, `validUntil` and `enabled` are still emitted and still
254
256
  outside `$defs/multicast` (the BLO-3323 freshness model, tracked separately).
@@ -446,7 +448,7 @@ All string values pass through `sanitize()` (T-06-01) — commas, `\r`, `\n` are
446
448
 
447
449
  ### Multicast transport (`./multicast-transport`)
448
450
 
449
- Thin wrapper around the lowercase `window.multicast` gateway. Calls `globalThis.multicast.subscribe({ group, source, port, consume: 'bytes' })`, listens for `"bytes"` events (`CustomEvent<ArrayBuffer>`) on the returned `EventTarget` subscription, pumps packets to a callback, runs a 5-second watchdog, and fires `onTakeover` once both video and audio are confirmed receiving.
451
+ Thin wrapper around the lowercase `window.multicast` gateway. Calls `globalThis.multicast.subscribe({ group, source, port, consume: 'bytes' })`, listens for `"bytes"` events (`CustomEvent<ArrayBuffer>`) on the returned `EventTarget` subscription, pumps packets to a callback, runs a silence watchdog over the catalog-derived failback window (`setFailbackWindowMs`), and fires `onTakeover` once both video and audio are confirmed receiving.
450
452
 
451
453
  ```ts
452
454
  class MulticastTransport {
@@ -457,12 +459,21 @@ class MulticastTransport {
457
459
  confirmVideo(): void
458
460
  confirmAudio(): void
459
461
  onTakeover(cb: () => void): void
460
- onFailback(cb: () => void): void
462
+ onFailback(cb: (reason: MulticastFailbackReason) => void): void
463
+ setFailbackWindowMs(windowMs: number | null): void
461
464
  dispose(): void
462
465
  readonly stats: { packetsReceived: number; bytesReceived: number }
463
466
  }
464
467
  ```
465
468
 
469
+ **Failover vocabulary.** draft-multicast-01 Section 6 "failover" (multicast to
470
+ unicast) is libmmt's *failback*: `onFailback`, `MulticastManager.onFailback`,
471
+ `failbackAll`, `MediaRouter.failbackToMoq`, `MulticastFailbackReason`, and CMCD
472
+ `x-bc-ct` `mc-to-uc`. libmmt's in-code *failover* (`track-session.ts`) is the
473
+ per-track hop along a track's transport chain. The return to multicast is the
474
+ draft's switch to multicast / join / switch back; CMCD `mc-start` is fired
475
+ host-side.
476
+
466
477
  Direct Sockets is Chrome-IWA-only. Outside an IWA context `isAvailable()` returns false and join() warns + returns false. AMT tunneling and unicast fallback are handled by `@blockcast/mmt-transport`, not by this transport class.
467
478
 
468
479
  ## Track-role convention summary (Phase 14)
@@ -507,7 +518,7 @@ Roles are required by:
507
518
  - **draft-ramadan-moq-fec** — AL-FEC over MoQ (§5.3 FEC Source Info object extension 0x11: SS_ID(32), fixed 4 bytes)
508
519
  - **RFC 6330** — RaptorQ Forward Error Correction (strict OTI codec in `@blockcast/mmt-fec`)
509
520
  - **RFC 9559** — CMCD (used by `CmcdProducer`)
510
- - **ATSC A/331** — Signaling, Delivery, Synchronization, Error Protection
521
+ - **ATSC A/331:2026-02 (informative for draft-fec-01 / draft-mmt-01; 7.2 SLS/MP table, 8.1.2.1 MMTP session, 8.1.2.5 AL-FEC) and A/331:2026-04 (normative for draft-multicast-01)** — Signaling, Delivery, Synchronization, Error Protection
511
522
 
512
523
  ## Related packages
513
524
 
@@ -1015,11 +1015,14 @@ function catalogFecAvailable(fec) {
1015
1015
  function isPositiveSafeInteger(value) {
1016
1016
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
1017
1017
  }
1018
+ var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
1018
1019
  function catalogFecDeclaresUnconfigurableInstance(fec) {
1019
1020
  const block = recordOf(fec);
1020
1021
  if (block === void 0 || block["algorithm"] === "none")
1021
1022
  return false;
1022
- return !(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"]));
1023
+ if (!(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"])))
1024
+ return true;
1025
+ return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
1023
1026
  }
1024
1027
 
1025
1028
  // src/mfu-reassembler.ts
@@ -6811,6 +6814,9 @@ function validateCmsfMmtpCatalog(value) {
6811
6814
  }
6812
6815
  }
6813
6816
  readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
6817
+ if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
6818
+ catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
6819
+ }
6814
6820
  }
6815
6821
  }
6816
6822
  const repairDescriptors = trackRecords.flatMap(
@@ -6977,14 +6983,6 @@ function validateSwitchingSetTiming(tracks) {
6977
6983
  return { ok: false, expectedTicks, mismatches };
6978
6984
  }
6979
6985
 
6980
- // node_modules/@blockcast/mmt-transport/dist/types.js
6981
- var MoqFecAlgorithm;
6982
- (function(MoqFecAlgorithm2) {
6983
- MoqFecAlgorithm2[MoqFecAlgorithm2["None"] = 0] = "None";
6984
- MoqFecAlgorithm2[MoqFecAlgorithm2["Xor"] = 1] = "Xor";
6985
- MoqFecAlgorithm2[MoqFecAlgorithm2["RaptorQ"] = 2] = "RaptorQ";
6986
- })(MoqFecAlgorithm || (MoqFecAlgorithm = {}));
6987
-
6988
6986
  // node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
6989
6987
  function endpointKey(endpoint) {
6990
6988
  return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
@@ -12544,7 +12542,7 @@ function isPositiveSafeInteger2(value) {
12544
12542
  function catalogDeclaresFec(fec) {
12545
12543
  const block = recordOf2(fec);
12546
12544
  if (block === void 0 || block["algorithm"] === "none") return false;
12547
- return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block);
12545
+ return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
12548
12546
  }
12549
12547
  function requireBoolean(value, field) {
12550
12548
  if (typeof value !== "boolean") {
@@ -18977,6 +18975,12 @@ var MmtpRouter = class {
18977
18975
  * sequence is its SS_ID minus this; see #routeProcessedFecSymbols.
18978
18976
  */
18979
18977
  #ssIdSeqOffsetByStream = /* @__PURE__ */ new Map();
18978
+ /**
18979
+ * Streams whose multicast leg delivered a RAP-flagged source packet that was
18980
+ * not parsed, typically because its overlap copy was parsed first
18981
+ * (BLO-49179). The next video keyframe emitted on the stream consumes it.
18982
+ */
18983
+ #multicastRapTwinByStream = /* @__PURE__ */ new Set();
18980
18984
  #lastDirectSourceVideoTsByStream = /* @__PURE__ */ new Map();
18981
18985
  #lastDirectEmittedVideoTsByStream = /* @__PURE__ */ new Map();
18982
18986
  #pendingDirectRecoveredVideoByStream = /* @__PURE__ */ new Map();
@@ -19110,6 +19114,12 @@ var MmtpRouter = class {
19110
19114
  ...meta.catalogTrackName === void 0 ? {} : { catalogTrackName: meta.catalogTrackName }
19111
19115
  };
19112
19116
  if (meta.source) frameMeta.source = meta.source;
19117
+ if (isVideo && frameMeta.keyframe) {
19118
+ const twinSeen = this.#multicastRapTwinByStream.delete(
19119
+ this.#mediaStreamKey(packetId, frameMeta.catalogTrackName)
19120
+ );
19121
+ if (twinSeen && frameMeta.source === "moq") frameMeta.source = "multicast";
19122
+ }
19113
19123
  if (meta.deliveryProvenance !== void 0)
19114
19124
  frameMeta.deliveryProvenance = meta.deliveryProvenance;
19115
19125
  if (meta.recovered) frameMeta.recovered = true;
@@ -19932,6 +19942,7 @@ var MmtpRouter = class {
19932
19942
  this.#droppedPreSyncVideo.delete(streamKey);
19933
19943
  this.#latestVideoSeqByStream.delete(streamKey);
19934
19944
  this.#ssIdSeqOffsetByStream.delete(streamKey);
19945
+ this.#multicastRapTwinByStream.delete(streamKey);
19935
19946
  this.#lastDirectSourceVideoTsByStream.delete(streamKey);
19936
19947
  this.#lastDirectEmittedVideoTsByStream.delete(streamKey);
19937
19948
  this.#pendingDirectRecoveredVideoByStream.delete(streamKey);
@@ -20730,6 +20741,10 @@ var MmtpRouter = class {
20730
20741
  // An FEC source frame is anchored by its own SS_ID (C.5.2).
20731
20742
  ...fecSource && fecPayloadId ? { fecSbn: fecPayloadId.ssId } : {}
20732
20743
  }, parsed);
20744
+ } else if (source === "multicast" && info.rapFlag) {
20745
+ this.#multicastRapTwinByStream.add(
20746
+ this.#mediaStreamKey(info.packetId, catalogTrackName)
20747
+ );
20733
20748
  }
20734
20749
  if (this.#classifyPacketId(info.packetId) === null) return;
20735
20750
  if (this.#fecManager && fecPayloadId && coords && sourceSymbolAccepted && sourceSymbolTrackable) {
@@ -23068,7 +23083,7 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
23068
23083
  throwRepairContractError(
23069
23084
  "track_fec",
23070
23085
  `${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
23071
- "must be a positive integer"
23086
+ kValid && Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0 ? `iso-ssbg1-v1 symbolSize must be at least ${ISO_SSBG1_MIN_SYMBOL_SIZE}` : "must be a positive integer"
23072
23087
  );
23073
23088
  }
23074
23089
  const fecUnavailable = catalogFecUnavailable(fec, fecPath);
@@ -26743,14 +26758,19 @@ var CmcdProducer = class {
26743
26758
  };
26744
26759
 
26745
26760
  // src/mmtp-fec-session.ts
26761
+ var PATH_BITS = { moq: 1, multicast: 2 };
26762
+ var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
26746
26763
  var MmtpFecSession = class {
26747
26764
  #decoder;
26748
26765
  /** Blocks a repair has defined and that are not settled yet, by SS_Start. */
26749
26766
  #blocks = /* @__PURE__ */ new Map();
26750
26767
  /** SS_Starts of settled blocks, so a later repair for one is refused. */
26751
26768
  #settled = /* @__PURE__ */ new Set();
26752
- /** SS_IDs whose packet the parser has: received, or recovered by the session. */
26753
- #have = /* @__PURE__ */ new Set();
26769
+ /**
26770
+ * SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
26771
+ * received on, or 0 for one the session recovered.
26772
+ */
26773
+ #have = /* @__PURE__ */ new Map();
26754
26774
  #newest;
26755
26775
  /** The newest SS_ID when the remembered SS_IDs were last pruned. */
26756
26776
  #prunedAt;
@@ -26764,7 +26784,10 @@ var MmtpFecSession = class {
26764
26784
  blocksReleased: 0,
26765
26785
  packetsRecovered: 0,
26766
26786
  packetsLost: 0,
26767
- dropped: {}
26787
+ dropped: {},
26788
+ sourceSymbolsByPath: { moq: 0, multicast: 0 },
26789
+ repairSymbolsByPath: { moq: 0, multicast: 0 },
26790
+ mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
26768
26791
  };
26769
26792
  /**
26770
26793
  * @throws when the catalog block lacks or misstates a field the session
@@ -26802,29 +26825,42 @@ var MmtpFecSession = class {
26802
26825
  return this.#decoder === null;
26803
26826
  }
26804
26827
  get stats() {
26805
- return { ...this.#stats, dropped: { ...this.#stats.dropped } };
26828
+ return {
26829
+ ...this.#stats,
26830
+ dropped: { ...this.#stats.dropped },
26831
+ sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
26832
+ repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
26833
+ mixedPath: { ...this.#stats.mixedPath }
26834
+ };
26806
26835
  }
26807
26836
  /**
26808
26837
  * Feeds one received source packet: the MMTP packet without its four-byte
26809
26838
  * Source FEC Payload ID, under the SS_ID that ID stated. This is what
26810
- * MmtpContainerParser's onSourceSymbol() hands over.
26839
+ * MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
26840
+ * was received; a caller that only subscribes over MoQT can leave it out.
26811
26841
  *
26812
26842
  * @returns the protected packets of this packet's block that it recovered,
26813
26843
  * in SS_ID order, for the caller to feed to its parser with
26814
26844
  * `{skipFecPayloadId: true, recovered: true}`. Usually empty.
26815
26845
  */
26816
- addSource(ssId, packet) {
26846
+ addSource(ssId, packet, path = "moq") {
26817
26847
  const decoder = this.#decoder;
26818
26848
  if (!decoder) return this.#drop("source:released");
26849
+ const pathBit = PATH_BITS[path];
26850
+ if (!pathBit) return this.#drop("source:unknown-path");
26819
26851
  if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
26820
26852
  if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
26821
26853
  if (this.#have.has(ssId)) return this.#drop("source:duplicate");
26822
- this.#have.add(ssId);
26854
+ this.#have.set(ssId, pathBit);
26823
26855
  this.#stats.sourceSymbols++;
26856
+ this.#stats.sourceSymbolsByPath[path]++;
26824
26857
  this.#noteNewest(ssId);
26825
26858
  const start = this.#blockStartOf(ssId);
26826
26859
  const block = start === void 0 ? void 0 : this.#blocks.get(start);
26827
- if (block) block.received++;
26860
+ if (block) {
26861
+ block.received++;
26862
+ block.paths |= pathBit;
26863
+ }
26828
26864
  let output;
26829
26865
  try {
26830
26866
  output = decoder.add_source(ssId, packet, 0);
@@ -26847,13 +26883,16 @@ var MmtpFecSession = class {
26847
26883
  * Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
26848
26884
  * 23008-1 C.5.3). A repair track carries one repair flow, so the first
26849
26885
  * repair packet fixes its packet ID and a packet of any other is refused.
26886
+ * `path` is where it was received, as for addSource().
26850
26887
  *
26851
26888
  * @returns the protected packets this repair symbol recovered, as for
26852
26889
  * addSource().
26853
26890
  */
26854
- addRepair(packet) {
26891
+ addRepair(packet, path = "moq") {
26855
26892
  const decoder = this.#decoder;
26856
26893
  if (!decoder) return this.#drop("repair:released");
26894
+ const pathBit = PATH_BITS[path];
26895
+ if (!pathBit) return this.#drop("repair:unknown-path");
26857
26896
  let header;
26858
26897
  try {
26859
26898
  header = parseMMTPHeader(packet);
@@ -26875,7 +26914,8 @@ var MmtpFecSession = class {
26875
26914
  if (!block) {
26876
26915
  if (this.#settled.has(start)) return this.#drop("repair:block-settled");
26877
26916
  if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
26878
- block = { ssbLength: frame.ssbLength, received: this.#countHeld(start, frame.ssbLength) };
26917
+ block = { ssbLength: frame.ssbLength, received: 0, paths: 0 };
26918
+ this.#countHeld(start, block);
26879
26919
  this.#blocks.set(start, block);
26880
26920
  }
26881
26921
  this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
@@ -26891,6 +26931,8 @@ var MmtpFecSession = class {
26891
26931
  return this.#drop("repair:decoder-refused");
26892
26932
  }
26893
26933
  this.#stats.repairSymbols++;
26934
+ this.#stats.repairSymbolsByPath[path]++;
26935
+ block.paths |= pathBit;
26894
26936
  const recovered = output ? this.#settleDecoded(start, block, output) : [];
26895
26937
  this.#retireBehindHorizon();
26896
26938
  return recovered;
@@ -26905,6 +26947,7 @@ var MmtpFecSession = class {
26905
26947
  if (!decoder) return false;
26906
26948
  this.#decoder = null;
26907
26949
  this.#stats.blocksReleased += this.#blocks.size;
26950
+ for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
26908
26951
  this.#blocks.clear();
26909
26952
  this.#settled.clear();
26910
26953
  this.#have.clear();
@@ -26924,12 +26967,17 @@ var MmtpFecSession = class {
26924
26967
  }
26925
26968
  return void 0;
26926
26969
  }
26927
- #countHeld(start, ssbLength) {
26928
- let held = 0;
26929
- for (let i = 0; i < ssbLength; i++) {
26930
- if (this.#have.has(serial32Add(start, i))) held++;
26970
+ /** Counts the sources of a new block the parser already has, and their paths. */
26971
+ #countHeld(start, block) {
26972
+ for (let i = 0; i < block.ssbLength; i++) {
26973
+ const pathBit = this.#have.get(serial32Add(start, i));
26974
+ if (pathBit === void 0) continue;
26975
+ block.received++;
26976
+ block.paths |= pathBit;
26931
26977
  }
26932
- return held;
26978
+ }
26979
+ #noteMixed(block, outcome) {
26980
+ if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
26933
26981
  }
26934
26982
  /** The decoder's own rule: more than its retention behind, counted from below. */
26935
26983
  #behindHorizon(start) {
@@ -26942,9 +26990,11 @@ var MmtpFecSession = class {
26942
26990
  this.#settled.add(start);
26943
26991
  }
26944
26992
  #settleClean(start) {
26945
- if (!this.#blocks.has(start)) return;
26993
+ const block = this.#blocks.get(start);
26994
+ if (!block) return;
26946
26995
  this.#settle(start);
26947
26996
  this.#stats.blocksClean++;
26997
+ this.#noteMixed(block, "clean");
26948
26998
  try {
26949
26999
  this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
26950
27000
  } catch {
@@ -26960,6 +27010,7 @@ var MmtpFecSession = class {
26960
27010
  if (output.byteLength !== block.ssbLength * this.symbolSize) {
26961
27011
  this.#stats.blocksFailed++;
26962
27012
  this.#stats.packetsLost += block.ssbLength - block.received;
27013
+ this.#noteMixed(block, "failed");
26963
27014
  this.#drop("block:decoded-length");
26964
27015
  return [];
26965
27016
  }
@@ -26974,17 +27025,20 @@ var MmtpFecSession = class {
26974
27025
  refused++;
26975
27026
  continue;
26976
27027
  }
26977
- this.#have.add(ssId);
27028
+ this.#have.set(ssId, 0);
26978
27029
  recovered.push(packet.slice());
26979
27030
  }
26980
27031
  if (refused > 0) {
26981
27032
  this.#stats.blocksFailed++;
26982
27033
  this.#stats.packetsLost += refused;
27034
+ this.#noteMixed(block, "failed");
26983
27035
  this.#drop("block:bad-ssbg1-symbol");
26984
27036
  } else if (recovered.length === 0) {
26985
27037
  this.#stats.blocksClean++;
27038
+ this.#noteMixed(block, "clean");
26986
27039
  } else {
26987
27040
  this.#stats.blocksRecovered++;
27041
+ this.#noteMixed(block, "recovered");
26988
27042
  }
26989
27043
  this.#stats.packetsRecovered += recovered.length;
26990
27044
  return recovered;
@@ -27008,11 +27062,12 @@ var MmtpFecSession = class {
27008
27062
  this.#settle(start);
27009
27063
  this.#stats.blocksFailed++;
27010
27064
  this.#stats.packetsLost += block.ssbLength - block.received;
27065
+ this.#noteMixed(block, "failed");
27011
27066
  }
27012
27067
  const prunedAt = this.#prunedAt;
27013
27068
  if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
27014
27069
  this.#prunedAt = newest;
27015
- for (const ssId of this.#have) {
27070
+ for (const ssId of this.#have.keys()) {
27016
27071
  if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
27017
27072
  }
27018
27073
  for (const start of this.#settled) {