@blockcast/mmt-container 2.2.0-main.979b946cb020 → 2.2.0-main.9c3e22d1cd4d

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.
@@ -14380,6 +14380,16 @@ var FECManager = class _FECManager {
14380
14380
  this.onBlockResolved = null;
14381
14381
  /** A stream's SBN went backwards (or jumped implausibly): the source restarted. */
14382
14382
  this.onSourceDiscontinuity = null;
14383
+ /**
14384
+ * The span and tolerance the catalog states for a keyframe overlay
14385
+ * installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
14386
+ * overlay instance's own interleaveDepthMs and reorderToleranceMs), or
14387
+ * undefined while none is installed. A stated block only a late source
14388
+ * can complete, and a frame whose gap may hide a RAP behind a span only a
14389
+ * late source can fill, also wait for that overlay's repair
14390
+ * (#overlayLateWaitMs).
14391
+ */
14392
+ this.keyframeOverlayTiming = null;
14383
14393
  // Worker-path callbacks — async recovery and stats from FecWorkerClient.
14384
14394
  /**
14385
14395
  * A recovered source symbol. Return false when admission refused the
@@ -16465,10 +16475,13 @@ var FECManager = class _FECManager {
16465
16475
  * A span longer than K holds more than one block (SSB_length <= K), and the
16466
16476
  * locator states no block inside a span, only one exactly its range
16467
16477
  * (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
16468
- * reach it. Its repair group is empty, so only its own late sources can
16469
- * complete it, and it waits as a stated block its group cannot complete
16470
- * does (#lateSourceWaitMs; BLO-52085 D4). A span of K or less may be one
16471
- * block whose repair is still to come, and keeps the whole wait.
16478
+ * reach it. Its repair group is empty, so the repair scheduler FETCHes no
16479
+ * Group of it (group-cannot-complete). Every span still keeps its whole
16480
+ * wait (#lateSourceWaitMs): failing it early released the frames behind it
16481
+ * past a keyframe the overlay was still rebuilding (BLO-52085). The release
16482
+ * gate lets those frames go once only a late source can fill the gap
16483
+ * before them, as long after they arrived as the gap's decision allows
16484
+ * (isoRepairlessWaitMs).
16472
16485
  */
16473
16486
  #openIsoSpan(span, packetId, catalogTrackName) {
16474
16487
  const key = this.#blockKey(span.block.start, packetId, catalogTrackName);
@@ -16514,6 +16527,50 @@ var FECManager = class _FECManager {
16514
16527
  }
16515
16528
  return lost;
16516
16529
  }
16530
+ /**
16531
+ * The release gate's wait, from a frame's arrival, for the SS_IDs strictly
16532
+ * between two released frames' SS_IDs once only a late source can still
16533
+ * fill them, else undefined. That is when every one missing (neither
16534
+ * 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.
16539
+ *
16540
+ * The wait is the late-symbol allowance, unless `rapMayHide`: the gap may
16541
+ * hold a RAP packet an installed keyframe overlay can still rebuild (its
16542
+ * decision stalls, or it ends at a RAP that may lie past a whole MPU).
16543
+ * Then the frame waits as a stated block its group cannot complete does
16544
+ * (#overlayLateWaitMs): the allowance alone with no overlay installed, the
16545
+ * overlay's span plus the larger of the allowance and its tolerance, or,
16546
+ * for an overlay that states no span, the span's whole wait (undefined).
16547
+ */
16548
+ isoRepairlessWaitMs(packetId, catalogTrackName, fromSsId, toSsId, rapMayHide = false) {
16549
+ const config = this.#trackConfigs.get(packetId);
16550
+ if (config === void 0 || !_FECManager.#hasCatalogTiming(config)) return void 0;
16551
+ const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName));
16552
+ if (locator === void 0 || !locator.coversBetween(fromSsId, toSsId)) return void 0;
16553
+ const newestSource = locator.newestSource;
16554
+ if (newestSource === void 0 || serial32Precedes(newestSource, toSsId)) return void 0;
16555
+ let repairless = false;
16556
+ for (const block of locator.blocksBetween(fromSsId, toSsId)) {
16557
+ const key = this.#blockKey(block.start, packetId, catalogTrackName);
16558
+ if (this.#completedBlocks.has(key)) continue;
16559
+ if (block.span && block.length > locator.kMax) {
16560
+ repairless = true;
16561
+ continue;
16562
+ }
16563
+ const received = this.#blockSourceEsis.get(key);
16564
+ for (let esi = 0; esi < block.length; esi++) {
16565
+ 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;
16568
+ }
16569
+ }
16570
+ if (!repairless) return void 0;
16571
+ const waitMs = rapMayHide ? this.#overlayLateWaitMs(packetId, catalogTrackName, config) : this.#multicastWaitMs(config) - config.interleaveDepthMs;
16572
+ return waitMs === void 0 ? void 0 : Math.max(0, waitMs);
16573
+ }
16517
16574
  /**
16518
16575
  * iso-ssbg1-v1 block location: repair symbols it refused, oversize sources,
16519
16576
  * the sources held now for a block no repair has stated yet, and the held
@@ -17330,17 +17387,23 @@ var FECManager = class _FECManager {
17330
17387
  }
17331
17388
  /**
17332
17389
  * The wait of a block that only a late source can complete (BLO-52085): a
17333
- * repair stated it, or it is a repair-less span longer than K (whose group
17334
- * is empty, #openIsoSpan), its received sources plus every symbol its
17335
- * repair group carries (RSB_length) are short of K' (the repair scheduler's
17390
+ * repair stated it, its received sources plus every symbol its repair group
17391
+ * carries (RSB_length) are short of K' (the repair scheduler's
17336
17392
  * group-cannot-complete), and a later source of the stream has arrived, so
17337
17393
  * a source it misses is lost or reordered behind that one. The span, which
17338
17394
  * covers repair symbols paced after its sources, buys it nothing: it waits
17339
17395
  * the late-symbol allowance alone, the multicast wait less the span (the
17340
17396
  * catalog tolerance or the measured delivery gap). Undefined for any other
17341
- * block.
17397
+ * block. While a keyframe overlay is installed, the block waits for its
17398
+ * repair too (#overlayLateWaitMs). A repair-less span keeps its whole
17399
+ * wait, even one longer than K whose group is empty (#openIsoSpan): its
17400
+ * resolution is what releases the frames behind it, and failing it early
17401
+ * released them past a keyframe the overlay was still rebuilding, which
17402
+ * then arrived stale. The release gate lets them go instead
17403
+ * (isoRepairlessWaitMs).
17342
17404
  */
17343
17405
  #lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) {
17406
+ if (this.#isoSpanKeys.has(key)) return void 0;
17344
17407
  const authoredLength = this.#blockAuthoredLengths.get(key);
17345
17408
  const rsbLength = this.#blockRsbLengths.get(key);
17346
17409
  if (authoredLength === void 0 || rsbLength === void 0) return void 0;
@@ -17352,7 +17415,33 @@ var FECManager = class _FECManager {
17352
17415
  if (newestSource === void 0 || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
17353
17416
  return void 0;
17354
17417
  }
17355
- return this.#multicastWaitMs(config) - config.interleaveDepthMs;
17418
+ return this.#overlayLateWaitMs(packetId, catalogTrackName, config);
17419
+ }
17420
+ /**
17421
+ * How long a loss only a late source or an installed keyframe overlay can
17422
+ * still fill waits once a later source passed it: the late-symbol
17423
+ * allowance alone (the multicast wait less the span) while no overlay is
17424
+ * installed. An installed one (keyframeOverlayTiming) may still rebuild a
17425
+ * RAP packet the loss took: a second FEC instance over the same packets
17426
+ * (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
17427
+ * span, unrelated to the base's. That packet can complete a stated block
17428
+ * (feedRebuiltSourceSymbol), or play behind a span; giving the loss up
17429
+ * first lets the release gate pass the keyframe, whose rebuild then lands
17430
+ * stale. The overlay repair of a packet the loss took goes out within the
17431
+ * overlay's span of that packet (fec-core-00 9.3), and the later source was
17432
+ * sent after it, so the loss waits that span plus the larger of the
17433
+ * allowance and the overlay's own tolerance. An overlay that states no
17434
+ * span (its block may then span keyframes), or one whose wait is not
17435
+ * shorter than the whole multicast wait, leaves the whole wait: undefined.
17436
+ */
17437
+ #overlayLateWaitMs(packetId, catalogTrackName, config) {
17438
+ const waitMs = this.#multicastWaitMs(config);
17439
+ const allowanceMs = waitMs - config.interleaveDepthMs;
17440
+ const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName);
17441
+ if (overlay === void 0) return allowanceMs;
17442
+ const overlaySpanMs = overlay.interleaveDepthMs ?? 0;
17443
+ const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0);
17444
+ return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : void 0;
17356
17445
  }
17357
17446
  /**
17358
17447
  * Bring an open block's wait in to its late-source wait, when it has one.
@@ -18993,7 +19082,7 @@ var FecReleaseSequencer = class {
18993
19082
  from
18994
19083
  );
18995
19084
  unresolved = resolved === null;
18996
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
19085
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(last, head, from, to)) {
18997
19086
  const heldMs = performance.now() - head.arrivedAtMs;
18998
19087
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
18999
19088
  this.#recordStat("forcedWindowFlushes");
@@ -19011,6 +19100,11 @@ var FecReleaseSequencer = class {
19011
19100
  );
19012
19101
  }
19013
19102
  }
19103
+ /** The head has waited out a gap only a late source can still fill (FecReleaseGate.unrepairableWaitMs). */
19104
+ #unrepairableWaitOver(last, head, from, to) {
19105
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
19106
+ return waitMs !== void 0 && performance.now() - head.arrivedAtMs >= waitMs;
19107
+ }
19014
19108
  /**
19015
19109
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
19016
19110
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -25833,6 +25927,26 @@ var MmtpRouter = class {
25833
25927
  if (!fec?.terminalRetentionMsForPacket) return Infinity;
25834
25928
  return fec.terminalRetentionMsForPacket(packetId) ?? 0;
25835
25929
  },
25930
+ // Once no repair can fill a gap (FECManager.isoRepairlessWaitMs: only a
25931
+ // late source can), its frame waits the late-symbol allowance when the
25932
+ // gap holds no RAP an installed keyframe overlay could still rebuild:
25933
+ // 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
25935
+ // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
25936
+ // other rap-next, whose gap may hold a whole MPU and the keyframe the
25937
+ // overlay protects) waits for that overlay's repair too (BLO-52085
25938
+ // D4). The FEC check comes first: most held gaps are not behind such a
25939
+ // span, and deciding one scans both frames' bitstreams.
25940
+ unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
25941
+ const fec = this.#fecManager;
25942
+ const { packetId, catalogTrackName } = after.meta;
25943
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
25944
+ if (!fec || allowanceMs === void 0) return void 0;
25945
+ const decision = this.#decideGap(before, after, [], false);
25946
+ const mpu = before.meta.mpuSequenceNumber;
25947
+ 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;
25949
+ },
25836
25950
  decide: (before, after, lostBlocks, discontinuity) => {
25837
25951
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
25838
25952
  this.#onFrameGap?.(decision);
@@ -28971,6 +29085,11 @@ var MulticastManager = class {
28971
29085
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
28972
29086
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
28973
29087
  };
29088
+ this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
29089
+ const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : void 0;
29090
+ if (binding === void 0) return void 0;
29091
+ return catalogTrackName === void 0 || catalogTrackName === binding.sourceCatalogTrackName ? binding.geometry : void 0;
29092
+ };
28974
29093
  this.#fec.onDecoderUnavailable = (event) => {
28975
29094
  this.#emitRepairLifecycle({
28976
29095
  version: 2,
@@ -30217,7 +30336,8 @@ var MulticastManager = class {
30217
30336
  blockProfile: parseFecBlockProfile(
30218
30337
  geometry2.blockProfile,
30219
30338
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`
30220
- )
30339
+ ),
30340
+ geometry: geometry2
30221
30341
  });
30222
30342
  }
30223
30343
  }
@@ -30256,7 +30376,7 @@ var MulticastManager = class {
30256
30376
  for (const [sourcePacketId, install] of [...this.#overlayInstalls]) {
30257
30377
  const before = this.#overlayBindings.get(sourcePacketId);
30258
30378
  const after = overlayBindings.get(sourcePacketId);
30259
- const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => after[key] === before[key]);
30379
+ const same = before !== void 0 && after !== void 0 && Object.keys(after).every((key) => key === "geometry" || after[key] === before[key]);
30260
30380
  if (!same) install.dispose();
30261
30381
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
30262
30382
  else install.reattach();