@blockcast/mmt-container 2.2.0-main.e1bebe787bc9 → 2.2.0-main.ea9223dc11de

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 (124) hide show
  1. package/dist/block-policy.d.ts +33 -3
  2. package/dist/block-policy.d.ts.map +1 -1
  3. package/dist/block-policy.js +60 -24
  4. package/dist/block-policy.js.map +3 -3
  5. package/dist/browser-runtime.js +1034 -126
  6. package/dist/browser-runtime.js.map +4 -4
  7. package/dist/carp-catalog.d.ts +40 -1
  8. package/dist/carp-catalog.d.ts.map +1 -1
  9. package/dist/carp-catalog.js +163 -10
  10. package/dist/carp-catalog.js.map +4 -4
  11. package/dist/catalog-fec-params.js +34 -0
  12. package/dist/catalog-fec-params.js.map +3 -3
  13. package/dist/catalog-network-source.js +34 -0
  14. package/dist/catalog-network-source.js.map +3 -3
  15. package/dist/datagram-leg-deadline.d.ts +138 -0
  16. package/dist/datagram-leg-deadline.d.ts.map +1 -0
  17. package/dist/datagram-leg-deadline.js +229 -0
  18. package/dist/datagram-leg-deadline.js.map +7 -0
  19. package/dist/delivery-catalog.js +68 -0
  20. package/dist/delivery-catalog.js.map +4 -4
  21. package/dist/delta-fallback-config.js +34 -0
  22. package/dist/delta-fallback-config.js.map +3 -3
  23. package/dist/fec-manager.d.ts +117 -13
  24. package/dist/fec-manager.d.ts.map +1 -1
  25. package/dist/fec-manager.js +358 -42
  26. package/dist/fec-manager.js.map +4 -4
  27. package/dist/fec-state.d.ts +17 -5
  28. package/dist/fec-state.d.ts.map +1 -1
  29. package/dist/fec-state.js +36 -0
  30. package/dist/fec-state.js.map +3 -3
  31. package/dist/fec-worker-setup.js +34 -0
  32. package/dist/fec-worker-setup.js.map +3 -3
  33. package/dist/held-layer-admission.js +34 -0
  34. package/dist/held-layer-admission.js.map +3 -3
  35. package/dist/index.d.ts +6 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +14 -0
  38. package/dist/index.js.map +2 -2
  39. package/dist/iso-block-locator.d.ts +16 -0
  40. package/dist/iso-block-locator.d.ts.map +1 -1
  41. package/dist/iso-block-locator.js +62 -0
  42. package/dist/iso-block-locator.js.map +3 -3
  43. package/dist/mfu-reassembler.js +34 -0
  44. package/dist/mfu-reassembler.js.map +3 -3
  45. package/dist/mmtp-container-parser.d.ts +6 -3
  46. package/dist/mmtp-container-parser.d.ts.map +1 -1
  47. package/dist/mmtp-container-parser.js +34 -0
  48. package/dist/mmtp-container-parser.js.map +3 -3
  49. package/dist/mmtp-container-parser.no-modules.js +167 -13
  50. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  51. package/dist/mmtp-decode-pipeline.js +34 -0
  52. package/dist/mmtp-decode-pipeline.js.map +3 -3
  53. package/dist/mmtp-fec-session.js +34 -0
  54. package/dist/mmtp-fec-session.js.map +3 -3
  55. package/dist/mmtp-mode-selection.d.ts +48 -0
  56. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  57. package/dist/mmtp-mode-selection.js +79 -0
  58. package/dist/mmtp-mode-selection.js.map +7 -0
  59. package/dist/mmtp-router.d.ts +66 -10
  60. package/dist/mmtp-router.d.ts.map +1 -1
  61. package/dist/mmtp-router.js +204 -30
  62. package/dist/mmtp-router.js.map +4 -4
  63. package/dist/multicast-auth-catalog.js +42 -2
  64. package/dist/multicast-auth-catalog.js.map +3 -3
  65. package/dist/multicast-input.js +42 -2
  66. package/dist/multicast-input.js.map +3 -3
  67. package/dist/multicast-manager.d.ts +95 -1
  68. package/dist/multicast-manager.d.ts.map +1 -1
  69. package/dist/multicast-manager.js +613 -92
  70. package/dist/multicast-manager.js.map +4 -4
  71. package/dist/multicast-transport.js +68 -0
  72. package/dist/multicast-transport.js.map +4 -4
  73. package/dist/multicast-unwrap.js +34 -0
  74. package/dist/multicast-unwrap.js.map +3 -3
  75. package/dist/no-modules.js +167 -13
  76. package/dist/no-modules.js.map +4 -4
  77. package/dist/phase14-catalog-override.d.ts +2 -1
  78. package/dist/phase14-catalog-override.d.ts.map +1 -1
  79. package/dist/phase14-catalog-override.js +69 -2
  80. package/dist/phase14-catalog-override.js.map +3 -3
  81. package/dist/repair-fetch.d.ts.map +1 -1
  82. package/dist/repair-fetch.js +50 -0
  83. package/dist/repair-fetch.js.map +3 -3
  84. package/dist/repair-layer-subscriptions.js +34 -0
  85. package/dist/repair-layer-subscriptions.js.map +3 -3
  86. package/dist/signaling.js +34 -0
  87. package/dist/signaling.js.map +3 -3
  88. package/dist/timestamp-codec.js +34 -0
  89. package/dist/timestamp-codec.js.map +3 -3
  90. package/dist/wasm-mfu-reassembler.js +34 -0
  91. package/dist/wasm-mfu-reassembler.js.map +3 -3
  92. package/dist/wasm-mmtp-container-parser.js +34 -0
  93. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  94. package/package.json +5 -5
  95. package/schemas/catalog.schema.json +2 -2
  96. package/src/block-policy.ts +108 -31
  97. package/src/carp-catalog.ts +165 -5
  98. package/src/datagram-leg-deadline.ts +370 -0
  99. package/src/fec-manager.ts +345 -33
  100. package/src/fec-state.ts +21 -5
  101. package/src/index.ts +37 -0
  102. package/src/iso-block-locator.ts +34 -0
  103. package/src/mmtp-container-parser.ts +6 -4
  104. package/src/mmtp-mode-selection.ts +80 -0
  105. package/src/mmtp-router.ts +226 -45
  106. package/src/multicast-manager.ts +126 -0
  107. package/src/phase14-catalog-override.ts +14 -3
  108. package/src/repair-fetch.ts +23 -0
  109. package/test-vectors/catalog/README.md +36 -2
  110. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  111. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  112. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  113. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  114. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  115. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  116. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  117. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  118. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  119. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  120. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  121. package/test-vectors/catalog/section-codes.json +3 -3
  122. package/test-vectors/catalog-timing.json +742 -1
  123. package/test-vectors/catalog-validation.json +266 -7
  124. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -370,6 +370,40 @@ var RUNTIME_FEC_RECEIVER = Object.freeze({
370
370
  overlays: true
371
371
  });
372
372
 
373
+ // ../mmt-base/dist/mmtp-siblings.js
374
+ var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
375
+ var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
376
+ "namespace",
377
+ "timescale",
378
+ "presentationAnchorTicks",
379
+ "groupDuration"
380
+ ]);
381
+ var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
382
+ "codec",
383
+ "width",
384
+ "height",
385
+ "framerate",
386
+ "bitrate",
387
+ "samplerate",
388
+ "channelConfig",
389
+ "lang"
390
+ ]);
391
+ var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
392
+ "initRef",
393
+ "keyframeIntervalMs",
394
+ "keyframeIntervalTicks",
395
+ "isLive",
396
+ "altGroup"
397
+ ]);
398
+
399
+ // ../mmt-base/dist/datagram-leg-size.js
400
+ var DATAGRAM_LEG_UDP_FLOOR = 1200;
401
+ var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
402
+ var DATAGRAM_LEG_OBJECT_HEADER = 13;
403
+ var DATAGRAM_LEG_RELAY_ROOM = 16;
404
+ var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
405
+ var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
406
+
373
407
  // node_modules/@blockcast/mmt-transport/dist/multicast-tier.js
374
408
  function endpointKey(endpoint) {
375
409
  return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
@@ -620,6 +654,40 @@ var RUNTIME_FEC_RECEIVER2 = Object.freeze({
620
654
  overlays: true
621
655
  });
622
656
 
657
+ // node_modules/@blockcast/mmt-base/dist/mmtp-siblings.js
658
+ var MMTP_MODES2 = Object.freeze(["mfu", "mfu-datagram"]);
659
+ var MMTP_SIBLING_HARD_FIELDS2 = Object.freeze([
660
+ "namespace",
661
+ "timescale",
662
+ "presentationAnchorTicks",
663
+ "groupDuration"
664
+ ]);
665
+ var MMTP_SIBLING_RENDITION_FIELDS2 = Object.freeze([
666
+ "codec",
667
+ "width",
668
+ "height",
669
+ "framerate",
670
+ "bitrate",
671
+ "samplerate",
672
+ "channelConfig",
673
+ "lang"
674
+ ]);
675
+ var MMTP_SIBLING_SOFT_FIELDS2 = Object.freeze([
676
+ "initRef",
677
+ "keyframeIntervalMs",
678
+ "keyframeIntervalTicks",
679
+ "isLive",
680
+ "altGroup"
681
+ ]);
682
+
683
+ // node_modules/@blockcast/mmt-base/dist/datagram-leg-size.js
684
+ var DATAGRAM_LEG_UDP_FLOOR2 = 1200;
685
+ var DATAGRAM_LEG_QUIC_WT_FRAMING2 = 48;
686
+ var DATAGRAM_LEG_OBJECT_HEADER2 = 13;
687
+ var DATAGRAM_LEG_RELAY_ROOM2 = 16;
688
+ var DATAGRAM_LEG_DATAGRAM_MAX2 = DATAGRAM_LEG_UDP_FLOOR2 - DATAGRAM_LEG_QUIC_WT_FRAMING2;
689
+ var DATAGRAM_LEG_BODY_MAX2 = DATAGRAM_LEG_DATAGRAM_MAX2 - DATAGRAM_LEG_OBJECT_HEADER2 - DATAGRAM_LEG_RELAY_ROOM2;
690
+
623
691
  // node_modules/@blockcast/mmt-transport/dist/multicast-orchestrator.js
624
692
  var DEFAULT_DWELL_MS = 3e3;
625
693
  var DEFAULT_JOIN_DEADLINE_MS = 5e3;
@@ -10261,6 +10329,20 @@ var MmtpRouter = class {
10261
10329
  /** The flow whose receiver admitted a stream's source datagrams, by packetId then catalog track name: recovered packets answer to it. */
10262
10330
  #provenanceStreamFlow = /* @__PURE__ */ new Map();
10263
10331
  #unregisteredFlowDrops = 0;
10332
+ /** "mfu-datagram" leg packets of a packet id the ingress does not name (never the signaling flow). */
10333
+ #datagramLegIngressDrops = 0;
10334
+ /** "mfu-datagram" leg packets of the signaling flow (packet id 0): expected, one per group. */
10335
+ #datagramLegSignalingPackets = 0;
10336
+ /**
10337
+ * The streams a live "mfu-datagram" leg has fed, catalog track names by
10338
+ * packet id: their ledgers and release gate take the leg's bounds. A stream
10339
+ * leaves when its leg does: `endDatagramLeg`, `resetTrack`, `dispose`, or
10340
+ * the first multicast packet of its packet id (the ordered switch retires
10341
+ * the leg first). The "mfu" sibling shares the packet id, never the name.
10342
+ */
10343
+ #datagramLegStreams = /* @__PURE__ */ new Map();
10344
+ /** The leg's presentation budget (setDatagramLegPresentationBudget), or null: no presentation bound. */
10345
+ #datagramLegPresentationBudgetMs = null;
10264
10346
  #ambiguousRecoveredDrops = 0;
10265
10347
  // Temp state set by #processMMTP before calling parser.feed(),
10266
10348
  // read by the parser's onFrame callback for CMAF assembly + dedup.
@@ -10636,10 +10718,11 @@ var MmtpRouter = class {
10636
10718
  const blockLifetimeMs = fec.blockLifetimeMsForPacket(packetId);
10637
10719
  if (blockSpanMs === void 0 || blockLifetimeMs === void 0) return NO_FEC_GEOMETRY_HORIZON;
10638
10720
  if (blockSpanMs === 0) return NO_BLOCK_SPAN_HORIZON;
10639
- return {
10640
- kind: "fec-horizon",
10641
- retentionMs: duplicateRetentionMs({ blockSpanMs, blockLifetimeMs })
10642
- };
10721
+ let retentionMs = duplicateRetentionMs({ blockSpanMs, blockLifetimeMs });
10722
+ if (this.#datagramLegStreams.has(packetId)) {
10723
+ retentionMs = Math.max(retentionMs, fec.datagramLegLedgerRetentionMsForPacket?.(packetId) ?? 0);
10724
+ }
10725
+ return { kind: "fec-horizon", retentionMs };
10643
10726
  }
10644
10727
  /**
10645
10728
  * Init segments rejected since construction because their packetId had no
@@ -11062,7 +11145,7 @@ var MmtpRouter = class {
11062
11145
  const blockStart = placement.block.start;
11063
11146
  if (placement.span !== void 0) this.#replayOverlaySources(inst, placement.span.block.start, placement.span.placed);
11064
11147
  this.#replayOverlaySources(inst, blockStart, placement.placed);
11065
- if (source === "moq") this.#noteOverlayMoqBlock(inst, blockStart);
11148
+ if (source !== "multicast") this.#noteOverlayMoqBlock(inst, blockStart);
11066
11149
  const alreadyCompleted = fec.isBlockCompleted(blockStart, pid, name);
11067
11150
  const recovered = fec.feedRepairSymbol(pid, repair.ssStart, repair.ssbLength, repair.rsId, repair.symbolData, name);
11068
11151
  if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, blockStart, recovered);
@@ -11070,7 +11153,7 @@ var MmtpRouter = class {
11070
11153
  #replayOverlaySources(inst, blockStart, placed) {
11071
11154
  const { fec, repairPacketId: pid, streamName: name } = inst;
11072
11155
  for (const { ssId, payload } of placed) {
11073
- if (payload.source === "moq") this.#noteOverlayMoqBlock(inst, blockStart);
11156
+ if (payload.source !== "multicast") this.#noteOverlayMoqBlock(inst, blockStart);
11074
11157
  if (payload.oversized) continue;
11075
11158
  const alreadyCompleted = fec.isBlockCompleted(blockStart, pid, name);
11076
11159
  const recovered = fec.feedSourceSymbol(pid, ssId, payload.symbolData, name);
@@ -11123,7 +11206,7 @@ var MmtpRouter = class {
11123
11206
  });
11124
11207
  continue;
11125
11208
  }
11126
- if (source === "moq") this.#noteOverlayMoqBlock(inst, coords.sbn);
11209
+ if (source !== "multicast") this.#noteOverlayMoqBlock(inst, coords.sbn);
11127
11210
  if (oversized) continue;
11128
11211
  const alreadyCompleted = fec.isBlockCompleted(coords.sbn, pid, name);
11129
11212
  const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
@@ -11712,6 +11795,46 @@ var MmtpRouter = class {
11712
11795
  get unregisteredFlowDropCount() {
11713
11796
  return this.#unregisteredFlowDrops;
11714
11797
  }
11798
+ /** "mfu-datagram" leg packets dropped because the leg's ingress does not name their packet id (packet id 0 apart). */
11799
+ get datagramLegIngressDropCount() {
11800
+ return this.#datagramLegIngressDrops;
11801
+ }
11802
+ /** "mfu-datagram" leg packets of the MMTP signaling flow (packet id 0), which no track owns. */
11803
+ get datagramLegSignalingPacketCount() {
11804
+ return this.#datagramLegSignalingPackets;
11805
+ }
11806
+ /**
11807
+ * The "mfu-datagram" leg's presentation bound (mmt-02 6.1 step 6): how
11808
+ * long after a frame arrives it must leave the release gate when the gap
11809
+ * before it holds no RAP, FT=0 or FT=1 data (the player's presentation
11810
+ * delay less its decode lead). The gap is then decided at the earlier of
11811
+ * the FEC block deadline and this bound; a gap that may hold a RAP keeps
11812
+ * the block deadline. Null, or a value that is not finite and positive:
11813
+ * the block deadline alone, as on multicast.
11814
+ */
11815
+ setDatagramLegPresentationBudget(budgetMs) {
11816
+ this.#datagramLegPresentationBudgetMs = budgetMs;
11817
+ }
11818
+ /**
11819
+ * The "mfu-datagram" leg is over (unsubscribed, or switched to another
11820
+ * path): no stream keeps its presentation bound or its ledger retention.
11821
+ * Parser, FEC and ledger state stay, so the packet ids continue on the
11822
+ * next path without an epoch. A later leg datagram starts a leg again.
11823
+ */
11824
+ endDatagramLeg() {
11825
+ this.#datagramLegStreams.clear();
11826
+ this.#datagramLegPresentationBudgetMs = null;
11827
+ }
11828
+ #datagramLegPresentationWaitMs(packetId, catalogTrackName) {
11829
+ if (this.#datagramLegPresentationBudgetMs === null || this.#datagramLegStreams.get(packetId)?.has(catalogTrackName) !== true) return void 0;
11830
+ let budgetMs;
11831
+ try {
11832
+ budgetMs = this.#datagramLegPresentationBudgetMs(packetId, catalogTrackName);
11833
+ } catch {
11834
+ return void 0;
11835
+ }
11836
+ return Number.isFinite(budgetMs) && budgetMs > 0 ? budgetMs : void 0;
11837
+ }
11715
11838
  /** Recovered packets dropped because more than one protected flow could own their stream. */
11716
11839
  get ambiguousRecoveredDropCount() {
11717
11840
  return this.#ambiguousRecoveredDrops;
@@ -11729,6 +11852,10 @@ var MmtpRouter = class {
11729
11852
  * caller that forgot it silently attributed its bytes to a multicast socket
11730
11853
  * they may never have crossed — and that attribution is what the physical-
11731
11854
  * delivery evidence path is built on. Absence is not multicast; say which.
11855
+ * `"moq-datagram"` is an "mfu-datagram" subscription (MmtpIngestSource):
11856
+ * `ingress.tracks` MUST name the datagram catalog track for its packet id,
11857
+ * and a packet of a packet id it does not name is dropped and counted
11858
+ * (`datagramLegIngressDropCount`; the signaling flow, packet id 0, apart).
11732
11859
  */
11733
11860
  feedPacket(packet, source, ingress) {
11734
11861
  if (this.#disposed) return;
@@ -11778,15 +11905,18 @@ var MmtpRouter = class {
11778
11905
  }
11779
11906
  /**
11780
11907
  * Feed a repair packet from MoQ (reliable QUIC) — parses MMTP repair
11781
- * header and delegates to FECManager for FEC recovery.
11908
+ * header and delegates to FECManager for FEC recovery. `source` is
11909
+ * `"moq-datagram"` for a repair object of an "mfu-datagram" track's repair
11910
+ * track, which arrives as a datagram and so counts as an in-band symbol of
11911
+ * the leg; a FETCHed repair stays `"moq"` (RepairVia `quic`).
11782
11912
  */
11783
- feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
11913
+ feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source = "moq") {
11784
11914
  if (this.#disposed) return;
11785
11915
  this.#withDeferredFecPokes(() => {
11786
- this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
11916
+ this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source);
11787
11917
  });
11788
11918
  }
11789
- #feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, admitted = false) {
11919
+ #feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source, admitted = false) {
11790
11920
  let header;
11791
11921
  try {
11792
11922
  header = parseMMTPHeader(packet);
@@ -11796,7 +11926,7 @@ var MmtpRouter = class {
11796
11926
  const repairPacketId = header.packetId;
11797
11927
  const overlay = this.#overlayRepairTarget(repairPacketId, repairTrackName);
11798
11928
  if (overlay !== void 0) {
11799
- this.#routeOverlayRepair(overlay, repairPacketId, packet, header, "moq");
11929
+ this.#routeOverlayRepair(overlay, repairPacketId, packet, header, source);
11800
11930
  return;
11801
11931
  }
11802
11932
  const hintedOwner = ownerPacketIdHint != null && this.#classifyPacketId(ownerPacketIdHint) !== null ? ownerPacketIdHint : null;
@@ -11808,7 +11938,7 @@ var MmtpRouter = class {
11808
11938
  }
11809
11939
  let unlisted = false;
11810
11940
  if (ownerPacketId != null && !admitted) {
11811
- const admit = this.#admitUnicast(repairPacketId, packet, () => this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, true));
11941
+ const admit = this.#admitUnicast(repairPacketId, packet, () => this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source, true));
11812
11942
  if (admit === "held" || admit === "dropped") return;
11813
11943
  unlisted = admit === "unlisted";
11814
11944
  }
@@ -11829,7 +11959,7 @@ var MmtpRouter = class {
11829
11959
  this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
11830
11960
  return;
11831
11961
  }
11832
- this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
11962
+ this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, source, repairTrackName);
11833
11963
  }
11834
11964
  }
11835
11965
  // ── Packet FEC geometry and block profile ───────────────────────
@@ -12034,6 +12164,7 @@ var MmtpRouter = class {
12034
12164
  debugRouter(
12035
12165
  `[MmtpRouter] Dropping repair packet pid=${packetId}: physical PID is unregistered`
12036
12166
  );
12167
+ this.#fecManager?.countUnresolvedRepairOwner?.("unregistered");
12037
12168
  return null;
12038
12169
  }
12039
12170
  const registeredOwners = this.#repairOwnersByPacketId.get(packetId) ?? /* @__PURE__ */ new Set();
@@ -12042,6 +12173,7 @@ var MmtpRouter = class {
12042
12173
  debugRouter(
12043
12174
  `[MmtpRouter] Dropping repair packet pid=${packetId}: catalog owner is ${owners.length === 0 ? "absent" : "ambiguous"}`
12044
12175
  );
12176
+ this.#fecManager?.countUnresolvedRepairOwner?.(owners.length === 0 ? "ownerAbsent" : "ownerAmbiguous");
12045
12177
  return null;
12046
12178
  }
12047
12179
  /** Route a recovered FEC block through the parser + dedup pipeline.
@@ -12091,6 +12223,8 @@ var MmtpRouter = class {
12091
12223
  }
12092
12224
  this.#parser.resetTrack(packetId, catalogTrackName);
12093
12225
  this.resetKeyframeOverlays(packetId, catalogTrackName);
12226
+ const legNames = this.#datagramLegStreams.get(packetId);
12227
+ if (legNames?.delete(catalogTrackName) && legNames.size === 0) this.#datagramLegStreams.delete(packetId);
12094
12228
  this.#restampedStreams.delete(this.#mediaStreamKey(packetId, catalogTrackName));
12095
12229
  const assistPrefix = assistKey(packetId, catalogTrackName, 0).slice(0, -1);
12096
12230
  for (const key of this.#assistBlocks.keys()) if (key.startsWith(assistPrefix)) this.#assistBlocks.delete(key);
@@ -12432,6 +12566,7 @@ var MmtpRouter = class {
12432
12566
  this.#fecWakes.clear();
12433
12567
  this.#parser.dispose();
12434
12568
  this.#streams.clear();
12569
+ this.endDatagramLeg();
12435
12570
  this.#trackPacketCallbacks.clear();
12436
12571
  this.#latestVideoSeqByStream.clear();
12437
12572
  this.#lastDirectSourceVideoTsByStream.clear();
@@ -12621,20 +12756,27 @@ var MmtpRouter = class {
12621
12756
  // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
12622
12757
  // other rap-next, whose gap may hold a whole MPU and the keyframe the
12623
12758
  // overlay protects) waits for that overlay's repair too (BLO-52085
12624
- // D4). The FEC check comes first: most held gaps are not behind such a
12625
- // span, and deciding one scans both frames' bitstreams.
12759
+ // D4). A run no repair has delimited instead waits for its FEC
12760
+ // deadline, whatever the decision (FECManager.isoRepairlessWaitMs). The
12761
+ // FEC check comes first: most held gaps are not behind such a span, and
12762
+ // deciding one scans both frames' bitstreams.
12626
12763
  unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
12627
12764
  const fec = this.#fecManager;
12628
12765
  const { packetId, catalogTrackName } = after.meta;
12629
- const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
12630
- if (!fec || allowanceMs === void 0) return void 0;
12766
+ const arrivedAtMs = after.arrivedAtMs;
12767
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, false, arrivedAtMs);
12768
+ const presentationMs = this.#datagramLegPresentationWaitMs(packetId, catalogTrackName);
12769
+ if (!fec || allowanceMs === void 0 && presentationMs === void 0) return void 0;
12631
12770
  const decision = this.#decideGap(before, after, [], false);
12632
12771
  const mpu = before.meta.mpuSequenceNumber;
12633
12772
  const intoNextMpu = decision.reason === "rap-next" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu + 1 >>> 0 && fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
12634
12773
  if (decision.action === "stall" || decision.reason === "rap-next" && !intoNextMpu) {
12635
- return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
12774
+ return allowanceMs === void 0 ? void 0 : fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true, false, arrivedAtMs);
12636
12775
  }
12637
- return decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true) : allowanceMs;
12776
+ const waitMs = allowanceMs === void 0 ? void 0 : decision.reason === "rap-next" ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true, arrivedAtMs) : allowanceMs;
12777
+ if (decision.reason === "delta-lost" && !((fec.interleaveDepthMsForPacket?.(packetId) ?? 0) > 0)) return waitMs;
12778
+ if (presentationMs === void 0) return waitMs;
12779
+ return waitMs === void 0 ? presentationMs : Math.min(waitMs, presentationMs);
12638
12780
  },
12639
12781
  decide: (before, after, lostBlocks, discontinuity) => {
12640
12782
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
@@ -12676,7 +12818,8 @@ var MmtpRouter = class {
12676
12818
  meta.catalogTrackName,
12677
12819
  meta.mpuSequenceNumber,
12678
12820
  timing.presentationTime,
12679
- timing.mediaTimescale
12821
+ timing.mediaTimescale,
12822
+ timing.decodeTime
12680
12823
  );
12681
12824
  }
12682
12825
  };
@@ -12695,7 +12838,19 @@ var MmtpRouter = class {
12695
12838
  const { packetId, catalogTrackName } = after.meta;
12696
12839
  const trackKind = this.#classifyPacketId(packetId) === false ? "audio" : "video";
12697
12840
  const positionsTrusted = this.#fecManager?.classifierModeFor?.(packetId, catalogTrackName).mode === "classifying" && before.meta.movieFragmentSequenceNumber === after.meta.movieFragmentSequenceNumber;
12698
- const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
12841
+ const mpu = before.meta.mpuSequenceNumber;
12842
+ const sameMpu = trackKind === "video" && mpu !== void 0 && after.meta.mpuSequenceNumber === mpu;
12843
+ const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(
12844
+ packetId,
12845
+ catalogTrackName,
12846
+ sameMpu ? {
12847
+ mpu,
12848
+ from: before.meta.authoredTiming,
12849
+ to: after.meta.authoredTiming,
12850
+ fromSsId: before.meta.fecSbn,
12851
+ toSsId: after.meta.fecSbnFirst ?? after.meta.fecSbn
12852
+ } : void 0
12853
+ ) === true;
12699
12854
  const evidence = (frame) => {
12700
12855
  const timing = frame.meta.authoredTiming;
12701
12856
  const sampleNumber = frame.meta.sampleNumber;
@@ -12811,18 +12966,34 @@ var MmtpRouter = class {
12811
12966
  if (manifestAdmitted && !info.isRepair && ingress?.admittedBy !== USER_AGENT_VERIFIED) this.#admittedSourceDatagrams++;
12812
12967
  if (source === "multicast" && !manifestAdmitted) {
12813
12968
  this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
12969
+ } else if (source === "moq-datagram" && !manifestAdmitted) {
12970
+ this.#fecManager?.noteArrival?.("moq-datagram", info.packetId, info.sequenceNumber);
12814
12971
  }
12815
- if (source === "multicast" && !ingressHasPacketId(ingress, info.packetId)) {
12972
+ if (source !== "moq" && !ingressHasPacketId(ingress, info.packetId)) {
12973
+ if (source === "moq-datagram") {
12974
+ if (info.packetId === MMTP_SIGNALING_PACKET_ID) this.#datagramLegSignalingPackets++;
12975
+ else this.#datagramLegIngressDrops++;
12976
+ }
12816
12977
  debugRouter(
12817
- `[MmtpRouter] Dropping multicast packet pid=${info.packetId}: absent from ingress tracks`
12978
+ `[MmtpRouter] Dropping ${source} packet pid=${info.packetId}: absent from ingress tracks`
12818
12979
  );
12819
12980
  return;
12820
12981
  }
12982
+ if (source === "moq-datagram") {
12983
+ if (!info.isRepair) {
12984
+ let names = this.#datagramLegStreams.get(info.packetId);
12985
+ if (!names) this.#datagramLegStreams.set(info.packetId, names = /* @__PURE__ */ new Set());
12986
+ names.add(catalogTrackNameForPacket(ingress, info.packetId));
12987
+ }
12988
+ } else if (source === "multicast") {
12989
+ this.#datagramLegStreams.delete(info.packetId);
12990
+ }
12821
12991
  const packetRole = this.#packetIdRoles.get(info.packetId);
12822
- if (source === "multicast" && this.#classifyPacketId(info.packetId) === null && (!info.isRepair || packetRole !== "repair")) {
12992
+ if (source !== "moq" && this.#classifyPacketId(info.packetId) === null && (!info.isRepair || packetRole !== "repair")) {
12823
12993
  debugRouter(
12824
- `[MmtpRouter] Dropping multicast packet pid=${info.packetId}: physical PID is unregistered`
12994
+ `[MmtpRouter] Dropping ${source} packet pid=${info.packetId}: physical PID is unregistered`
12825
12995
  );
12996
+ if (info.isRepair) this.#fecManager?.countUnresolvedRepairOwner?.("unregistered");
12826
12997
  return;
12827
12998
  }
12828
12999
  if (!info.isRepair && hasAmbiguousCatalogTrackName(ingress, info.packetId)) {
@@ -12858,7 +13029,7 @@ var MmtpRouter = class {
12858
13029
  }
12859
13030
  return;
12860
13031
  }
12861
- if (source === "moq" && !manifestAdmitted) {
13032
+ if (source !== "multicast" && !manifestAdmitted) {
12862
13033
  const admit = this.#admitUnicast(info.packetId, packet, () => this.#processMMTP(packet, source, true, ingress, overlapCopy, true), overlapCopy);
12863
13034
  if (admit !== "unlisted") {
12864
13035
  if (admit === "admitted") this.#processMMTP(packet, source, true, ingress, overlapCopy);
@@ -12887,7 +13058,7 @@ var MmtpRouter = class {
12887
13058
  );
12888
13059
  if (!repair) return;
12889
13060
  if (ownerPacketId != null && this.#fecManager) {
12890
- if ((flowless && this.#userAgentGoverns(ownerPacketId) || source === "moq" && !manifestAdmitted) && this.#setAsideUnlistedRepair(ownerPacketId, catalogTrackNameForPacket(ingress, ownerPacketId), repair)) return;
13061
+ if ((flowless && this.#userAgentGoverns(ownerPacketId) || source !== "multicast" && !manifestAdmitted) && this.#setAsideUnlistedRepair(ownerPacketId, catalogTrackNameForPacket(ingress, ownerPacketId), repair)) return;
12891
13062
  this.#repairPidCounts[info.packetId] = (this.#repairPidCounts[info.packetId] || 0) + 1;
12892
13063
  const count = this.#repairPidCounts[info.packetId];
12893
13064
  if (count <= 2 || count % 500 === 0) {
@@ -12926,7 +13097,7 @@ var MmtpRouter = class {
12926
13097
  const fecSource = this.#fecManager !== null && fecPayloadId != null;
12927
13098
  const coords = fecSource && fecPayloadId ? this.#locateFecSource(info.packetId, catalogTrackName, fecPayloadId.ssId) ?? void 0 : void 0;
12928
13099
  duplicates.advance(coords?.sbn);
12929
- if (source === "multicast" && !overlapCopy && !releasedFromQuarantine && catalogTrackName !== void 0 && duplicates.predatesHorizon(info.sequenceNumber, fecPayloadId?.ssId)) {
13100
+ if (source !== "moq" && !overlapCopy && !releasedFromQuarantine && catalogTrackName !== void 0 && duplicates.predatesHorizon(info.sequenceNumber, fecPayloadId?.ssId)) {
12930
13101
  this.#publisherRestarts++;
12931
13102
  console.warn(
12932
13103
  `[MmtpRouter] publisher restart on pid=${info.packetId} track=${catalogTrackName}: packet_sequence_number=${info.sequenceNumber} predates the stream's FEC horizon; starting a new epoch`
@@ -12987,6 +13158,7 @@ var MmtpRouter = class {
12987
13158
  evidence: sourceSymbolEvidence(packet, parsed.header, info.rapFlag, info.sequenceNumber),
12988
13159
  oversized: !(this.#fecManager.isoSourceFits?.(info.packetId, rawSymbol.length) ?? false)
12989
13160
  }) ?? false;
13161
+ if (held) this.#requestFecPoke(info.packetId, catalogTrackName);
12990
13162
  parseSourceSymbol = held && !duplicates.parsedSymbols.has(ssId);
12991
13163
  }
12992
13164
  } else if (fecUnreadable && info.fecPayloadId) {
@@ -13114,7 +13286,9 @@ var MmtpRouter = class {
13114
13286
  const feedOptions = {
13115
13287
  skipFecPayloadId: parserOptions?.skipFecPayloadId,
13116
13288
  recovered: parserOptions?.recovered,
13117
- source: parserOptions?.source,
13289
+ // Frame attribution is the transport path: an "mfu-datagram" object
13290
+ // crossed QUIC, so its frames are 'moq' (provenance 'mixed').
13291
+ source: parserOptions?.source === "moq-datagram" ? "moq" : parserOptions?.source,
13118
13292
  deliveryProvenance: parserOptions?.deliveryProvenance,
13119
13293
  catalogTrackName: parserOptions?.catalogTrackName,
13120
13294
  ...parserOptions?.fecSbn === void 0 ? {} : { fecSbn: parserOptions.fecSbn },