@blockcast/mmt-container 0.4.0-main.d60c84364d2a → 0.4.0-main.ec774a581e1a

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.
@@ -13255,9 +13255,13 @@ var FECManager = class _FECManager {
13255
13255
  // per stream. Not only throws: the ordinary out-of-range case is detected by
13256
13256
  // arithmetic and never throws at all.
13257
13257
  this.#orderedHorizonWarnedFor = /* @__PURE__ */ new Set();
13258
- // Newest block start (SS_Start) seen per stream and when: the frontier for
13259
- // source-discontinuity detection and isoSpanResolution.
13258
+ // Newest block start (SS_Start) any symbol carried per stream and when: the
13259
+ // frontier isoSpanResolution reads.
13260
13260
  this.#highestSbn = /* @__PURE__ */ new Map();
13261
+ // The same from source symbols alone: the frontier a source is judged
13262
+ // against for a discontinuity. Repairs ride their own group, which can run
13263
+ // blocks ahead of the media they protect.
13264
+ this.#sourceFrontiers = /* @__PURE__ */ new Map();
13261
13265
  // iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
13262
13266
  // block only once a repair symbol stated the block's (SS_Start, SSB_length).
13263
13267
  this.#isoLocators = /* @__PURE__ */ new Map();
@@ -13275,8 +13279,8 @@ var FECManager = class _FECManager {
13275
13279
  // rate-limited like the other per-symbol warns here. Cumulative.
13276
13280
  this.#isoDecoderUnplacedRetireFailed = 0;
13277
13281
  // The latest source symbol per stream that carried its MMTP
13278
- // packet_sequence_number: the anchor that bounds how many blocks the
13279
- // producer can have started before a later source symbol.
13282
+ // packet_sequence_number, by its own SS_ID: the anchor that bounds how far
13283
+ // the producer's SS_IDs can have moved before or after another source symbol.
13280
13284
  this.#sourceAnchors = /* @__PURE__ */ new Map();
13281
13285
  // Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
13282
13286
  this.#packetEpochs = /* @__PURE__ */ new Map();
@@ -13414,6 +13418,7 @@ var FECManager = class _FECManager {
13414
13418
  #materializedBlocks;
13415
13419
  #orderedHorizonWarnedFor;
13416
13420
  #highestSbn;
13421
+ #sourceFrontiers;
13417
13422
  #isoLocators;
13418
13423
  #isoRepairRefusedCount;
13419
13424
  #isoSourceOversizeCount;
@@ -14004,8 +14009,8 @@ var FECManager = class _FECManager {
14004
14009
  // Deliberately one block tighter than deriveFecRetentionBlocks over the same
14005
14010
  // inputs (that function's `+ 1`). Different question: the retention horizon
14006
14011
  // asks how long the decoder still ACCEPTS symbols for a block, this asks how
14007
- // many blocks a stream can live behind (or ahead of) its frontier before a
14008
- // source symbol there is a discontinuity rather than loss (see #noteSbnSeen).
14012
+ // many blocks a stream can jump ahead of its frontier before a source symbol
14013
+ // there is a discontinuity rather than loss (see #noteSbnSeen).
14009
14014
  // The extra block of retention is slack for a block still being fed; a block
14010
14015
  // nothing has been heard from does not get it. Not the units defect — but it
14011
14016
  // is the next place the two can drift, so change both or neither.
@@ -14015,55 +14020,72 @@ var FECManager = class _FECManager {
14015
14020
  }
14016
14021
  /**
14017
14022
  * Record that a symbol for block `sbn` (the block's SS_Start) arrived and
14018
- * advance the stream's frontier, the newest block start seen.
14023
+ * advance the stream's frontiers, the newest block start seen.
14019
14024
  *
14020
- * A SOURCE symbol whose block goes back further than one live window, or
14021
- * jumps further than the stream could have produced since its last symbol,
14022
- * is a source discontinuity, not loss. A repair symbol can only advance the
14025
+ * A SOURCE symbol is judged against the newest source block alone: repairs
14026
+ * ride their own group, which can run blocks ahead of the media. One whose
14027
+ * block goes back further than the blocks this manager retains, or that
14028
+ * cannot have been sent before the source it lies behind, or that jumps
14029
+ * further than the stream could have produced since its last symbol, is a
14030
+ * source discontinuity, not loss. A repair symbol can only advance the
14023
14031
  * frontier: a D-28 fetch legitimately answers for an old block, so it never
14024
14032
  * signals a discontinuity.
14025
14033
  *
14026
14034
  * The producer closes a block at its Dth media-unit boundary OR when K
14027
14035
  * source symbols filled it, so one interleave span can start several blocks
14028
- * (every large keyframe does). What bounds a forward jump is therefore
14029
- * packet evidence, not a block rate: SS_ID advances by one per FEC source
14030
- * packet (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one
14031
- * per packet of the packet_id, so with both source symbols'
14032
- * packet_sequence_number a block start can move at most the packets sent
14033
- * between them plus the anchor's own offset into its block (< K). Without
14034
- * it, only the D-close rate is known.
14036
+ * (every large keyframe does). What bounds a jump is therefore packet
14037
+ * evidence, not a block rate: SS_ID advances by one per FEC source packet
14038
+ * (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
14039
+ * packet of the packet_id, so with both source symbols'
14040
+ * packet_sequence_number their SS_IDs (`ssId`, not their block starts,
14041
+ * which a repair-less span can put far behind) can move at most the packets
14042
+ * sent between them, in either direction, plus K of slack for sources lost
14043
+ * before a hop that renumbers packets. Without it, only the D-close rate is
14044
+ * known.
14035
14045
  *
14036
14046
  * Vanished blocks are not enumerated here: their starts are unknown until a
14037
14047
  * repair states them. The SS_IDs between two stated blocks become one
14038
14048
  * repair-less span when the later block's repair arrives (placeIsoRepair).
14039
14049
  */
14040
- #noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber) {
14050
+ #noteSbnSeen(sbn, packetId, catalogTrackName, symbol, packetSequenceNumber, ssId = sbn) {
14041
14051
  const streamKey = this.#streamKey(packetId, catalogTrackName);
14042
14052
  const now = performance.now();
14043
- const previous = this.#highestSbn.get(streamKey);
14053
+ const previous = (symbol === "source" ? this.#sourceFrontiers : this.#highestSbn).get(streamKey);
14044
14054
  const anchor = this.#sourceAnchors.get(streamKey);
14045
14055
  const psn = symbol === "source" && packetSequenceNumber !== void 0 && Number.isSafeInteger(packetSequenceNumber) && packetSequenceNumber >= 0 && packetSequenceNumber <= 4294967295 ? packetSequenceNumber : void 0;
14046
14056
  const anchorHere = () => {
14047
- if (psn !== void 0 && (anchor === void 0 || !this.#blockPrecedes(sbn, anchor.sbn))) {
14048
- this.#sourceAnchors.set(streamKey, { sbn, psn, atMs: now });
14057
+ if (psn !== void 0 && (anchor === void 0 || !serial32Precedes(ssId, anchor.ssId))) {
14058
+ this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
14049
14059
  }
14050
14060
  };
14061
+ const advance = () => {
14062
+ const highest = this.#highestSbn.get(streamKey);
14063
+ if (highest === void 0 || this.#blockPrecedes(highest.sbn, sbn)) {
14064
+ this.#highestSbn.set(streamKey, { sbn, atMs: now });
14065
+ }
14066
+ if (symbol === "source") this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
14067
+ anchorHere();
14068
+ };
14051
14069
  const discontinuity = () => {
14052
14070
  this.#classifiers.get(streamKey)?.noteSourceDiscontinuity();
14053
14071
  this.#highestSbn.set(streamKey, { sbn, atMs: now });
14072
+ this.#sourceFrontiers.set(streamKey, { sbn, atMs: now });
14054
14073
  if (psn === void 0) this.#sourceAnchors.delete(streamKey);
14055
- else this.#sourceAnchors.set(streamKey, { sbn, psn, atMs: now });
14074
+ else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now });
14056
14075
  this.onSourceDiscontinuity?.(packetId, catalogTrackName);
14057
14076
  };
14058
14077
  if (previous === void 0) {
14059
- this.#highestSbn.set(streamKey, { sbn, atMs: now });
14060
- anchorHere();
14078
+ advance();
14061
14079
  return;
14062
14080
  }
14063
14081
  const config = this.#trackConfig(packetId);
14064
14082
  const window2 = this.#liveWindowBlocks(config);
14083
+ const sentInOrder = (from, to) => {
14084
+ const sent = to.psn - from.psn >>> 0;
14085
+ return sent <= 2147483647 && serial32Distance(from.ssId, to.ssId) <= sent + config.k;
14086
+ };
14065
14087
  if (!this.#blockPrecedes(previous.sbn, sbn)) {
14066
- if (symbol === "source" && window2 !== null && this.#blocksBehind(sbn, previous.sbn, packetId) > window2) {
14088
+ if (symbol === "source" && window2 !== null && this.#blockPrecedes(sbn, previous.sbn) && (this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) || psn !== void 0 && anchor !== void 0 && serial32Precedes(ssId, anchor.ssId) && psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))) {
14067
14089
  discontinuity();
14068
14090
  return;
14069
14091
  }
@@ -14073,9 +14095,8 @@ var FECManager = class _FECManager {
14073
14095
  const missing = this.#blocksBehind(previous.sbn, sbn, packetId) - 1;
14074
14096
  let plausible = true;
14075
14097
  if (window2 !== null) {
14076
- if (psn !== void 0 && anchor !== void 0 && this.#blockPrecedes(anchor.sbn, sbn) && psn !== anchor.psn) {
14077
- const sent = psn - anchor.psn >>> 0;
14078
- plausible = sent <= 2147483647 && serial32Distance(anchor.sbn, sbn) <= sent + config.k;
14098
+ if (psn !== void 0 && anchor !== void 0 && serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
14099
+ plausible = sentInOrder(anchor, { ssId, psn });
14079
14100
  } else {
14080
14101
  plausible = missing <= window2 + Math.ceil((now - previous.atMs) / config.interleaveDepthMs);
14081
14102
  }
@@ -14085,8 +14106,7 @@ var FECManager = class _FECManager {
14085
14106
  discontinuity();
14086
14107
  return;
14087
14108
  }
14088
- this.#highestSbn.set(streamKey, { sbn, atMs: now });
14089
- anchorHere();
14109
+ advance();
14090
14110
  }
14091
14111
  /*
14092
14112
  * Block order for one stream (BLO-35597 iso:5). A block is keyed by its
@@ -14670,6 +14690,7 @@ var FECManager = class _FECManager {
14670
14690
  resetSet(this.#materializedBlocks);
14671
14691
  resetMap(this.#resolvedBlockClasses);
14672
14692
  resetMap(this.#highestSbn);
14693
+ resetMap(this.#sourceFrontiers);
14673
14694
  resetMap(this.#isoLocators);
14674
14695
  resetMap(this.#sourceAnchors);
14675
14696
  this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName));
@@ -14775,6 +14796,7 @@ var FECManager = class _FECManager {
14775
14796
  dropMap(this.#orderedPendingBlocks);
14776
14797
  dropMap(this.#resolvedBlockClasses);
14777
14798
  dropMap(this.#highestSbn);
14799
+ dropMap(this.#sourceFrontiers);
14778
14800
  dropMap(this.#isoLocators);
14779
14801
  dropMap(this.#sourceAnchors);
14780
14802
  dropMap(this.#classifiers);
@@ -14867,7 +14889,13 @@ var FECManager = class _FECManager {
14867
14889
  if (isSourceSymbol && esi === 0) {
14868
14890
  this.#startupPartialBlocks.delete(blockKey);
14869
14891
  this.#startupAlignedPackets.add(streamKey);
14870
- } else if (isStartupPartial && !isReadyMulticastRepair || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair) {
14892
+ } else if (
14893
+ // A ready multicast repair opens a block the join has not seen yet, never
14894
+ // a join partial: its sources were refused, so its repairs alone open a
14895
+ // block that cannot decode and fails at its deadline, once per packet ID
14896
+ // per join (BLO-48308).
14897
+ isStartupPartial || !this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair
14898
+ ) {
14871
14899
  this.#markStartupPartial(blockKey);
14872
14900
  return false;
14873
14901
  }
@@ -15192,6 +15220,10 @@ var FECManager = class _FECManager {
15192
15220
  }
15193
15221
  return blocks;
15194
15222
  }
15223
+ /** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
15224
+ isoRetentionBlocksForPacket(packetId) {
15225
+ return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : void 0;
15226
+ }
15195
15227
  /** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
15196
15228
  isoSourceFits(packetId, packetLength) {
15197
15229
  const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize;
@@ -15773,20 +15805,37 @@ var FECManager = class _FECManager {
15773
15805
  * Caller is responsible for routing recovered data and updating
15774
15806
  * block completion state via `markBlockCompleted()`.
15775
15807
  */
15776
- feedRepairSymbol(packetId, ssStart, ssbLength, rsId, repairData, catalogTrackName) {
15777
- this.#fecStats.repairPackets++;
15778
- this.#statsForPacket(packetId).repairPackets++;
15779
- if (!this.#hasBlockProfile(packetId)) return null;
15808
+ /**
15809
+ * Whether a repair symbol of `byteLength` bytes is a valid member of a
15810
+ * `packetId` block: every repair symbol is exactly the track's T. A symbol of
15811
+ * any other size is counted on `repairSymbolSizeMismatches`, warned (rate
15812
+ * limited) and refused. The router calls this before the symbol takes any
15813
+ * other part in block state (placement, first-arrival dedup, completed-block
15814
+ * accounting), so a malformed repair is counted whatever its arrival order:
15815
+ * judged after dedup, one landing on an already-complete block, or behind a
15816
+ * valid copy from the other transport, was swallowed as a duplicate and never
15817
+ * counted (BLO-48306). A packetId with no configured block profile admits
15818
+ * nothing here; its repair is dropped upstream as unreadable.
15819
+ */
15820
+ admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, byteLength) {
15821
+ if (!this.#hasBlockProfile(packetId)) return false;
15780
15822
  const symbolSize = this.#trackConfig(packetId).symbolSize;
15781
- if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
15823
+ if (symbolSize > 0 && byteLength !== symbolSize) {
15782
15824
  this.#repairSymbolSizeMismatchCount++;
15783
15825
  if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
15784
15826
  console.warn(
15785
- `[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
15827
+ `[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`
15786
15828
  );
15787
15829
  }
15788
- return null;
15830
+ return false;
15789
15831
  }
15832
+ return true;
15833
+ }
15834
+ feedRepairSymbol(packetId, ssStart, ssbLength, rsId, repairData, catalogTrackName) {
15835
+ this.#fecStats.repairPackets++;
15836
+ this.#statsForPacket(packetId).repairPackets++;
15837
+ if (!this.#hasBlockProfile(packetId)) return null;
15838
+ if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null;
15790
15839
  const fecData = repairData;
15791
15840
  const k = this.#trackConfig(packetId).k;
15792
15841
  const block = this.#isoLocatorFor(packetId, catalogTrackName).blockAt(ssStart);
@@ -15939,7 +15988,14 @@ var FECManager = class _FECManager {
15939
15988
  const key = this.#blockKey(sbn, packetId, catalogTrackName);
15940
15989
  const k = trackConfig.k;
15941
15990
  if (this.#completedBlocks.has(key)) return;
15942
- this.#noteSbnSeen(sbn, packetId, catalogTrackName, "source", evidence.packetSequenceNumber);
15991
+ this.#noteSbnSeen(
15992
+ sbn,
15993
+ packetId,
15994
+ catalogTrackName,
15995
+ "source",
15996
+ evidence.packetSequenceNumber,
15997
+ Number.isInteger(esi) ? sbn + esi >>> 0 : sbn
15998
+ );
15943
15999
  const authoredLength = this.#blockAuthoredLengths.get(key) ?? k;
15944
16000
  if (Number.isInteger(esi) && esi >= authoredLength) {
15945
16001
  this.#failBlock(sbn, packetId, catalogTrackName);
@@ -16190,6 +16246,7 @@ var FECManager = class _FECManager {
16190
16246
  this.#repairedBlocks.clear();
16191
16247
  this.#materializedBlocks.clear();
16192
16248
  this.#highestSbn.clear();
16249
+ this.#sourceFrontiers.clear();
16193
16250
  this.#isoLocators.clear();
16194
16251
  this.#sourceAnchors.clear();
16195
16252
  this.#trackConfigs.clear();
@@ -19728,6 +19785,13 @@ var MmtpRouter = class {
19728
19785
  `[MmtpRouter] packetId=${ownerPacketId} is iso-ssbg1-v1 but its FEC manager cannot place ISO blocks`
19729
19786
  );
19730
19787
  }
19788
+ if (fec.admitRepairSymbolSize && !fec.admitRepairSymbolSize(
19789
+ ownerPacketId,
19790
+ repair.ssStart,
19791
+ repair.ssbLength,
19792
+ repair.rsId,
19793
+ repair.symbolData.byteLength
19794
+ )) return;
19731
19795
  const placement = fec.placeIsoRepair(ownerPacketId, catalogTrackName, repair.ssStart, repair.ssbLength);
19732
19796
  if (placement.status !== "placed") return;
19733
19797
  const blockStart = placement.block.start;
@@ -23663,7 +23727,9 @@ var MulticastManager = class {
23663
23727
  catalogTrackName
23664
23728
  );
23665
23729
  this.#configureTrackMapper(packetId, config);
23666
- this.#router.setPacketIdType(packetId, trackType);
23730
+ if (this.#router.trackKindFor(packetId) !== trackType) {
23731
+ this.#router.setPacketIdType(packetId, trackType);
23732
+ }
23667
23733
  }
23668
23734
  /**
23669
23735
  * Stop routing a stream's symbols to its Worker decoder. Returns false when
@@ -23744,6 +23810,14 @@ var MulticastManager = class {
23744
23810
  );
23745
23811
  }
23746
23812
  }
23813
+ for (const [packetId, c] of this.#trackFecTiming) {
23814
+ if (c.deliveryWindowMs === void 0) continue;
23815
+ mfuTimeoutMs = Math.max(
23816
+ mfuTimeoutMs ?? 0,
23817
+ this.#fec.terminalRetentionMsForPacket(packetId) ?? 0,
23818
+ this.#hostMfuTimeoutMs ?? 0
23819
+ );
23820
+ }
23747
23821
  const failbackWindowMs = deliveryWindowMs === void 0 ? minimumFailbackWindowMs : Math.max(deliveryWindowMs, minimumFailbackWindowMs ?? 0);
23748
23822
  this.#transport.setFailbackWindowMs(failbackWindowMs ?? null);
23749
23823
  this.#router.setMfuTimeoutMs(mfuTimeoutMs ?? this.#hostMfuTimeoutMs);
@@ -23927,6 +24001,7 @@ var MulticastManager = class {
23927
24001
  setMfuTimeoutMs(ms) {
23928
24002
  this.#router.setMfuTimeoutMs(ms);
23929
24003
  this.#hostMfuTimeoutMs = this.#router.reassembler.timeoutMs;
24004
+ if (this.#trackFecTiming.size > 0) this.#applyStreamGlobalFecTiming();
23930
24005
  }
23931
24006
  setTrackCodec(packetId, codec) {
23932
24007
  this.#router.setTrackCodec(packetId, codec);
@@ -24955,7 +25030,6 @@ async function setupFecWorkerForTrack(opts) {
24955
25030
  repairTrack: opts.repairTrackName,
24956
25031
  relayBlockSigEnabled: false
24957
25032
  };
24958
- client.configure(fecTrackConfig, rqWasm);
24959
25033
  try {
24960
25034
  opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
24961
25035
  blockProfile,
@@ -24975,6 +25049,14 @@ async function setupFecWorkerForTrack(opts) {
24975
25049
  }
24976
25050
  throw e;
24977
25051
  }
25052
+ fecTrackConfig.interleaveDepth = Math.min(
25053
+ MAX_FEC_RETENTION_BLOCKS,
25054
+ Math.max(
25055
+ interleaveDepthBlocks,
25056
+ opts.multicastManager.fecManager.isoRetentionBlocksForPacket(opts.packetId) ?? 0
25057
+ )
25058
+ );
25059
+ client.configure(fecTrackConfig, rqWasm);
24978
25060
  let disposed = false;
24979
25061
  return {
24980
25062
  client,