@blockcast/mmt-container 0.4.1 → 0.5.0-main.2c1f81817995

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/browser-runtime.js +3458 -356
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/cmcd-producer.d.ts +5 -1
  5. package/dist/cmcd-producer.d.ts.map +1 -1
  6. package/dist/cmcd-producer.js.map +2 -2
  7. package/dist/delivery-catalog.js +18 -2
  8. package/dist/delivery-catalog.js.map +2 -2
  9. package/dist/fec-manager.d.ts +21 -16
  10. package/dist/fec-manager.d.ts.map +1 -1
  11. package/dist/fec-manager.js +177 -80
  12. package/dist/fec-manager.js.map +3 -3
  13. package/dist/held-layer-admission.d.ts +58 -0
  14. package/dist/held-layer-admission.d.ts.map +1 -0
  15. package/dist/held-layer-admission.js +105 -0
  16. package/dist/held-layer-admission.js.map +7 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +2 -2
  19. package/dist/mmtp-container-parser.no-modules.js +2682 -1023
  20. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  21. package/dist/mmtp-fec-session.d.ts +36 -3
  22. package/dist/mmtp-fec-session.d.ts.map +1 -1
  23. package/dist/mmtp-fec-session.js +114 -5
  24. package/dist/mmtp-fec-session.js.map +3 -3
  25. package/dist/mmtp-router.d.ts +72 -28
  26. package/dist/mmtp-router.d.ts.map +1 -1
  27. package/dist/mmtp-router.js +321 -203
  28. package/dist/mmtp-router.js.map +2 -2
  29. package/dist/multicast-auth-catalog.d.ts +10 -2
  30. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  31. package/dist/multicast-auth-catalog.js +422 -22
  32. package/dist/multicast-auth-catalog.js.map +4 -4
  33. package/dist/multicast-manager.d.ts +48 -9
  34. package/dist/multicast-manager.d.ts.map +1 -1
  35. package/dist/multicast-manager.js +3406 -340
  36. package/dist/multicast-manager.js.map +4 -4
  37. package/dist/multicast-transport.d.ts +4 -1
  38. package/dist/multicast-transport.d.ts.map +1 -1
  39. package/dist/multicast-transport.js +20 -3
  40. package/dist/multicast-transport.js.map +2 -2
  41. package/dist/no-modules.d.ts +1 -2
  42. package/dist/no-modules.d.ts.map +1 -1
  43. package/dist/no-modules.js +2668 -1007
  44. package/dist/no-modules.js.map +4 -4
  45. package/dist/repair-fetch.d.ts +10 -1
  46. package/dist/repair-fetch.d.ts.map +1 -1
  47. package/dist/repair-fetch.js +5 -2
  48. package/dist/repair-fetch.js.map +2 -2
  49. package/package.json +5 -14
  50. package/src/cmcd-producer.ts +6 -1
  51. package/src/fec-manager.ts +121 -131
  52. package/src/held-layer-admission.ts +161 -0
  53. package/src/index.ts +5 -9
  54. package/src/mmtp-fec-session.ts +76 -3
  55. package/src/mmtp-router.ts +390 -272
  56. package/src/multicast-auth-catalog.ts +81 -8
  57. package/src/multicast-manager.ts +189 -48
  58. package/src/multicast-transport.ts +6 -2
  59. package/src/no-modules.ts +1 -6
  60. package/src/repair-fetch.ts +24 -4
  61. package/dist/manifest-auth-plan.d.ts +0 -31
  62. package/dist/manifest-auth-plan.d.ts.map +0 -1
  63. package/dist/manifest-auth-plan.js +0 -426
  64. package/dist/manifest-auth-plan.js.map +0 -7
  65. package/dist/source-auth.d.ts +0 -2
  66. package/dist/source-auth.d.ts.map +0 -1
  67. package/dist/source-auth.js +0 -3912
  68. package/dist/source-auth.js.map +0 -7
  69. package/src/manifest-auth-plan.ts +0 -55
  70. package/src/source-auth.ts +0 -1
  71. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  72. package/test-vectors/source-auth-v1.json +0 -61
@@ -8479,11 +8479,22 @@ var MmtpRouter = class {
8479
8479
  #fecManager;
8480
8480
  #defaultFecMapper;
8481
8481
  #fecMappersByPacketId = /* @__PURE__ */ new Map();
8482
- #manifestVerifier;
8483
- #ownsManifestVerifier;
8484
- #resolveManifestIdentity;
8485
- #resolveManifestIdentityForRoute;
8486
- #manifestRecoveryQueues = /* @__PURE__ */ new Map();
8482
+ /** Protected flows: one 7.2.7 receiver each, and the ingress its datagrams arrive with. */
8483
+ #provenance = /* @__PURE__ */ new Map();
8484
+ #onFlowProtected = null;
8485
+ #unadmittedListedDrops = 0;
8486
+ #unlistedRepairSetAside = 0;
8487
+ /** The ingress a held datagram arrived with; the receiver returns the same bytes on release. */
8488
+ #heldIngress = /* @__PURE__ */ new WeakMap();
8489
+ #unicastRepair = false;
8490
+ /** How to route a held unicast (MoQ) datagram once a record admits it. */
8491
+ #heldReplay = /* @__PURE__ */ new WeakMap();
8492
+ /** When a held datagram was received: admitted later, it keeps that receipt time (fec-01 9). */
8493
+ #heldAt = /* @__PURE__ */ new WeakMap();
8494
+ /** The flow whose receiver admitted a stream's source datagrams, by packetId then catalog track name: recovered packets answer to it. */
8495
+ #provenanceStreamFlow = /* @__PURE__ */ new Map();
8496
+ #unregisteredFlowDrops = 0;
8497
+ #ambiguousRecoveredDrops = 0;
8487
8498
  // Temp state set by #processMMTP before calling parser.feed(),
8488
8499
  // read by the parser's onFrame callback for CMAF assembly + dedup.
8489
8500
  #currentFecInfo;
@@ -8620,10 +8631,6 @@ var MmtpRouter = class {
8620
8631
  this.#fecManager = config?.fecManager ?? null;
8621
8632
  this.#onFrameGap = config?.onFrameGap ?? null;
8622
8633
  this.#defaultFecMapper = config?.fecMapper ?? null;
8623
- this.#manifestVerifier = config?.manifestVerifier ?? null;
8624
- this.#ownsManifestVerifier = config?.manifestVerifierOwnership !== "caller";
8625
- this.#resolveManifestIdentity = config?.resolveManifestIdentity ?? null;
8626
- this.#resolveManifestIdentityForRoute = config?.resolveManifestIdentityForRoute ?? null;
8627
8634
  this.#parser = new MmtpContainerParser({
8628
8635
  mfuTimeoutMs: config?.mfuTimeoutMs,
8629
8636
  reassemblyPolicy: config?.reassemblyPolicy,
@@ -9155,29 +9162,189 @@ var MmtpRouter = class {
9155
9162
  }
9156
9163
  });
9157
9164
  }
9158
- registerManifestTrack(context) {
9159
- if (!this.#manifestVerifier) throw new Error("manifest verifier is not configured");
9160
- this.#manifestVerifier.registerTrack(context);
9161
- }
9162
- feedManifestFrame(trackName, frame) {
9163
- this.#manifestVerifier?.ingestManifestFrame(trackName, frame);
9164
- }
9165
- setManifestAuthMode(mode) {
9166
- this.#manifestVerifier?.setMode(mode);
9167
- if (mode !== "enforce") {
9168
- for (const queue of this.#manifestRecoveryQueues.values()) {
9169
- for (const item of queue) {
9170
- this.#routeProcessedFecSymbols(
9171
- item.blockId,
9172
- item.result,
9173
- item.ownerPacketId,
9174
- item.catalogTrackName
9175
- );
9165
+ /**
9166
+ * Protect a flow (draft-ramadan-moq-multicast-01 7.2.7): every multicast
9167
+ * datagram whose ingress names `ingress.flow`, source and repair alike, is
9168
+ * admitted by `receiver` before anything reads it, and an unadmitted one is
9169
+ * held or dropped. The caller owns the receiver's configuration; the router
9170
+ * releases it on `releaseProvenanceFlow` and on dispose.
9171
+ */
9172
+ registerProvenanceFlow(ingress, receiver) {
9173
+ this.#provenance.get(ingress.flow)?.receiver.release();
9174
+ this.#provenance.set(ingress.flow, { receiver, ingress });
9175
+ receiver.keepPendingAgeMs = () => this.#oldestOpenBlockAgeMs(ingress.flow);
9176
+ }
9177
+ /**
9178
+ * Declare that this receiver can request unicast repair (a repair FETCH
9179
+ * scheduler is wired): a protected flow then keeps the pending entries of
9180
+ * its open blocks for the repair to consume (7.2.7 step 2).
9181
+ */
9182
+ setUnicastRepair(enabled) {
9183
+ this.#unicastRepair = enabled;
9184
+ }
9185
+ #oldestOpenBlockAgeMs(flow) {
9186
+ const entry = this.#provenance.get(flow);
9187
+ if (!this.#unicastRepair || !entry) return void 0;
9188
+ let age;
9189
+ for (const { name, packetId } of entry.ingress.tracks) {
9190
+ const a = name ? this.#fecManager?.oldestOpenBlockAgeMs?.(packetId, name) : void 0;
9191
+ if (a !== void 0 && (age === void 0 || a > age)) age = a;
9192
+ }
9193
+ return age;
9194
+ }
9195
+ /**
9196
+ * Replace a registered flow's ingress (a rendition switch staged, committed
9197
+ * or cancelled) while keeping its receiver; a no-op for an unregistered flow.
9198
+ */
9199
+ updateProvenanceFlowIngress(ingress) {
9200
+ const entry = this.#provenance.get(ingress.flow);
9201
+ if (!entry) return;
9202
+ this.#provenance.set(ingress.flow, { ...entry, ingress });
9203
+ if (entry.protected) {
9204
+ for (const { name, packetId } of ingress.tracks) {
9205
+ if (name && !entry.ingress.tracks.some((t) => t.name === name && t.packetId === packetId)) {
9206
+ this.#fecManager?.resetTrack?.(packetId, name);
9176
9207
  }
9177
9208
  }
9178
- this.#manifestRecoveryQueues.clear();
9179
9209
  }
9180
9210
  }
9211
+ /**
9212
+ * Called once per protection of a flow: at the admission that makes this
9213
+ * router's consumers protected under it (7.2.7), after their unadmitted
9214
+ * holdings of its listed tracks are discarded. Again after an unprotect.
9215
+ */
9216
+ onProvenanceFlowProtected(cb) {
9217
+ this.#onFlowProtected = cb;
9218
+ }
9219
+ /**
9220
+ * The receiver ceased to hold the flow's endpoint on failover (7.2.7): drop
9221
+ * its state and hold queues (no expiry counted) and un-protect its tracks,
9222
+ * which then take MoQ again. The registration stays, so multicast resuming
9223
+ * protects the flow anew at its next admission.
9224
+ */
9225
+ unprotectProvenanceFlow(flow) {
9226
+ const entry = this.#provenance.get(flow);
9227
+ if (!entry) return;
9228
+ entry.receiver.release();
9229
+ entry.protected = false;
9230
+ }
9231
+ /** MoQ packets of a track a protected flow lists, dropped on its unicast path: duplicate, overflow, or listed by more than one flow. */
9232
+ get unadmittedListedDropCount() {
9233
+ return this.#unadmittedListedDrops;
9234
+ }
9235
+ /** MoQ repair symbols of an unlisted track kept out of a governed FEC instance (7.2.7 step 2). */
9236
+ get unlistedRepairSetAsideCount() {
9237
+ return this.#unlistedRepairSetAside;
9238
+ }
9239
+ /**
9240
+ * A MoQ repair symbol no protected flow lists, owned by a source track one
9241
+ * does: its FEC instance is governed (7.2.7 step 2) and takes only admitted
9242
+ * symbols, so the symbol is set aside. Un-listing needs no hook: an
9243
+ * unprotected or released flow lists nothing.
9244
+ * ponytail: set aside = dropped. 7.2.7 lets it enter a decode (MAY), only
9245
+ * for a shortfall; the unlisted-symbol pool (BLO-49773 item 2) adds that.
9246
+ */
9247
+ #setAsideUnlistedRepair(ownerPacketId) {
9248
+ for (const entry of this.#provenance.values()) {
9249
+ if (entry.protected && ingressHasPacketId(entry.ingress, ownerPacketId)) {
9250
+ this.#unlistedRepairSetAside++;
9251
+ return true;
9252
+ }
9253
+ }
9254
+ return false;
9255
+ }
9256
+ /**
9257
+ * The admission that makes this router protected under `flow` (7.2.7):
9258
+ * its FEC instances discard what they hold of the flow's listed tracks so
9259
+ * no unadmitted symbol stands for an admitted one, then notify. Before it
9260
+ * nothing of the flow was admitted, so every such symbol is unadmitted.
9261
+ * The playback parse ledger is kept: it records MoQ copies already played,
9262
+ * not holdings, and clearing it re-emits that media (audio twice).
9263
+ * The FEC reset is the whole 7.2.7 discard here: no keyframe-overlay
9264
+ * instance exists to hold anything (repair-layers.ts is the catalog
9265
+ * contract only, no decoder), and packet_id 0 is never a listed track
9266
+ * (`ingressHasPacketId`), so nothing of it is held for the flow.
9267
+ */
9268
+ #noteFlowAdmitted(flow) {
9269
+ const entry = this.#provenance.get(flow);
9270
+ if (!entry || entry.protected) return;
9271
+ entry.protected = true;
9272
+ for (const { name, packetId } of entry.ingress.tracks) {
9273
+ if (name) this.#fecManager?.resetTrack?.(packetId, name);
9274
+ }
9275
+ this.#onFlowProtected?.(flow);
9276
+ }
9277
+ /**
9278
+ * Admit a MoQ datagram of `packetId` on the unicast path of the protected
9279
+ * flow that lists it (7.2.7). `unlisted`: no protected flow lists it, so it
9280
+ * is read as before. A held datagram is routed by `replay` when a record
9281
+ * admits it; one more than one protected flow lists is dropped. So is an
9282
+ * overlap copy: it never enters FEC accounting, so admitting it would leave
9283
+ * its multicast twin a duplicate and the block one symbol short.
9284
+ */
9285
+ #admitUnicast(packetId, packet, replay, overlapCopy = false) {
9286
+ let receiver;
9287
+ for (const entry of this.#provenance.values()) {
9288
+ if (!entry.protected || !ingressHasPacketId(entry.ingress, packetId)) continue;
9289
+ if (receiver || overlapCopy) {
9290
+ this.#unadmittedListedDrops++;
9291
+ return "dropped";
9292
+ }
9293
+ receiver = entry.receiver;
9294
+ }
9295
+ if (!receiver) return "unlisted";
9296
+ const { verdict } = receiver.onDatagram(packet, "unicast");
9297
+ if (verdict === "admitted") return "admitted";
9298
+ if (verdict === "held") {
9299
+ this.#heldReplay.set(packet, replay);
9300
+ this.#heldAt.set(packet, performance.now());
9301
+ return "held";
9302
+ }
9303
+ this.#unadmittedListedDrops++;
9304
+ return "dropped";
9305
+ }
9306
+ /**
9307
+ * Feed one bc-provenance record of `flow`: a datagram from `manifestPort`
9308
+ * (`multicast`) or an object of the manifest track (`mirror`). Held
9309
+ * datagrams the record admits are routed before this returns.
9310
+ */
9311
+ feedProvenanceRecord(flow, record, path) {
9312
+ const entry = this.#provenance.get(flow);
9313
+ if (!entry || this.#disposed) return "unregistered";
9314
+ const result = entry.receiver.onRecord(record, path);
9315
+ if (result.admitted.length > 0) {
9316
+ this.#noteFlowAdmitted(flow);
9317
+ this.#withDeferredFecPokes(() => {
9318
+ for (const datagram of result.admitted) {
9319
+ const route = () => {
9320
+ const replay = this.#heldReplay.get(datagram);
9321
+ if (replay) replay();
9322
+ else this.#processMMTP(datagram, "multicast", true, this.#heldIngress.get(datagram) ?? entry.ingress, false, true);
9323
+ };
9324
+ const heldAt = this.#heldAt.get(datagram);
9325
+ if (heldAt !== void 0 && this.#fecManager?.withReceiptTime) this.#fecManager.withReceiptTime(heldAt, route);
9326
+ else route();
9327
+ }
9328
+ });
9329
+ }
9330
+ return result.verdict;
9331
+ }
9332
+ /** The receiver ceased to hold the flow: its hold queues are dropped, not expired. */
9333
+ releaseProvenanceFlow(flow) {
9334
+ this.#provenance.get(flow)?.receiver.release();
9335
+ this.#provenance.delete(flow);
9336
+ for (const byName of this.#provenanceStreamFlow.values()) {
9337
+ for (const [name, bound] of byName) if (bound === flow) byName.delete(name);
9338
+ }
9339
+ }
9340
+ /** Multicast datagrams dropped because their ingress names a flow with no registered receiver. */
9341
+ get unregisteredFlowDropCount() {
9342
+ return this.#unregisteredFlowDrops;
9343
+ }
9344
+ /** Recovered packets dropped because more than one protected flow could own their stream. */
9345
+ get ambiguousRecoveredDropCount() {
9346
+ return this.#ambiguousRecoveredDrops;
9347
+ }
9181
9348
  /**
9182
9349
  * Main entry point: feed a raw MMTP packet for processing.
9183
9350
  *
@@ -9192,10 +9359,10 @@ var MmtpRouter = class {
9192
9359
  * they may never have crossed — and that attribution is what the physical-
9193
9360
  * delivery evidence path is built on. Absence is not multicast; say which.
9194
9361
  */
9195
- feedPacket(packet, source, manifestIdentity, ingress) {
9362
+ feedPacket(packet, source, ingress) {
9196
9363
  if (this.#disposed) return;
9197
9364
  this.#withDeferredFecPokes(() => {
9198
- this.#processMMTP(packet, source, manifestIdentity, false, ingress);
9365
+ this.#processMMTP(packet, source, false, ingress);
9199
9366
  });
9200
9367
  }
9201
9368
  /**
@@ -9230,7 +9397,7 @@ var MmtpRouter = class {
9230
9397
  feedOverlapCopy(packet, ingress) {
9231
9398
  if (this.#disposed) return;
9232
9399
  this.#withDeferredFecPokes(() => {
9233
- this.#processMMTP(packet, "moq", void 0, false, ingress, true);
9400
+ this.#processMMTP(packet, "moq", false, ingress, true);
9234
9401
  });
9235
9402
  }
9236
9403
  /**
@@ -9243,7 +9410,7 @@ var MmtpRouter = class {
9243
9410
  this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
9244
9411
  });
9245
9412
  }
9246
- #feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName) {
9413
+ #feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, admitted = false) {
9247
9414
  let header;
9248
9415
  try {
9249
9416
  header = parseMMTPHeader(packet);
@@ -9260,6 +9427,11 @@ var MmtpRouter = class {
9260
9427
  `[MmtpRouter] Dropping MoQ repair packet pid=${repairPacketId}: owner hint is required`
9261
9428
  );
9262
9429
  }
9430
+ if (ownerPacketId != null && !admitted) {
9431
+ const admit = this.#admitUnicast(repairPacketId, packet, () => this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, true));
9432
+ if (admit === "held" || admit === "dropped") return;
9433
+ if (admit === "unlisted" && this.#setAsideUnlistedRepair(ownerPacketId)) return;
9434
+ }
9263
9435
  if (ownerPacketId != null && this.#fecManager) {
9264
9436
  this.#moqRepairPidCounts[repairPacketId] = (this.#moqRepairPidCounts[repairPacketId] || 0) + 1;
9265
9437
  this.#moqRepairOwnerCounts[ownerPacketId] = (this.#moqRepairOwnerCounts[ownerPacketId] || 0) + 1;
@@ -9403,10 +9575,11 @@ var MmtpRouter = class {
9403
9575
  catalogTrackName
9404
9576
  );
9405
9577
  if (recovered && !alreadyCompleted) {
9406
- fec.cancelBlockTimeout(blockStart, ownerPacketId, catalogTrackName);
9407
- fec.countRecovery(ownerPacketId, blockStart, catalogTrackName);
9408
- fec.markBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
9409
- this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
9578
+ this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName, () => {
9579
+ fec.cancelBlockTimeout(blockStart, ownerPacketId, catalogTrackName);
9580
+ fec.countRecovery(ownerPacketId, blockStart, catalogTrackName);
9581
+ fec.markBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
9582
+ });
9410
9583
  }
9411
9584
  }
9412
9585
  /**
@@ -9447,10 +9620,11 @@ var MmtpRouter = class {
9447
9620
  const alreadyCompleted = fec.isBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
9448
9621
  const recovered = fec.feedSourceSymbol(ownerPacketId, ssId, payload.symbolData, catalogTrackName);
9449
9622
  if (!recovered || alreadyCompleted) continue;
9450
- fec.cancelBlockTimeout(blockStart, ownerPacketId, catalogTrackName);
9451
- fec.countRecovery(ownerPacketId, blockStart, catalogTrackName);
9452
- fec.markBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
9453
- this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName);
9623
+ this.#routeRecoveredBlock(blockStart, recovered, ownerPacketId, catalogTrackName, () => {
9624
+ fec.cancelBlockTimeout(blockStart, ownerPacketId, catalogTrackName);
9625
+ fec.countRecovery(ownerPacketId, blockStart, catalogTrackName);
9626
+ fec.markBlockCompleted(blockStart, ownerPacketId, catalogTrackName);
9627
+ });
9454
9628
  }
9455
9629
  }
9456
9630
  #resolveRepairOwnerPacketId(packetId, ingress) {
@@ -9473,14 +9647,18 @@ var MmtpRouter = class {
9473
9647
  * Sync WASM decoders return the block's K' = SSB_length fixed-width
9474
9648
  * ssbg_mode1 source symbols concatenated. */
9475
9649
  routeRecoveredBlock(blockId, data, packetId, catalogTrackName) {
9476
- this.#withDeferredFecPokes(() => this.#routeRecoveredBlock(blockId, data, packetId, catalogTrackName));
9650
+ let recovered = false;
9651
+ this.#withDeferredFecPokes(() => {
9652
+ recovered = this.#routeRecoveredBlock(blockId, data, packetId, catalogTrackName);
9653
+ });
9654
+ return recovered;
9477
9655
  }
9478
9656
  /** Route a single recovered source symbol through the parser + dedup pipeline.
9479
9657
  * Worker-backed decoders emit one padded source symbol per frame event. */
9480
9658
  routeRecoveredSymbol(blockId, data, packetId, esi = 0, catalogTrackName) {
9481
9659
  const blockProfile = this.#blockProfileFor(packetId);
9482
9660
  const result = processFecSymbol(data, { ownerPacketId: packetId, index: esi, blockProfile });
9483
- this.#routeVerifiedFecSymbols(blockId, result, packetId, catalogTrackName);
9661
+ return this.#routeVerifiedFecSymbols(blockId, result, packetId, catalogTrackName);
9484
9662
  }
9485
9663
  // ── Keyframe timer cancellation ─────────────────────────────────
9486
9664
  /** Cancel the active keyframe loss timer.
@@ -9523,7 +9701,6 @@ var MmtpRouter = class {
9523
9701
  this.#lastDirectSourceAudioCursorByStream.delete(streamKey);
9524
9702
  this.#lastDirectEmittedAudioCursorByStream.delete(streamKey);
9525
9703
  this.#pendingDirectRecoveredAudioByStream.delete(streamKey);
9526
- this.#manifestRecoveryQueues.delete(streamKey);
9527
9704
  this.#deliveredVideoHighWaterByStream.delete(streamKey);
9528
9705
  this.#stream(packetId, catalogTrackName).duplicates.clear();
9529
9706
  const assemblersToReset = /* @__PURE__ */ new Set();
@@ -9573,7 +9750,6 @@ var MmtpRouter = class {
9573
9750
  this.#lastDirectSourceAudioCursorByStream.delete(key);
9574
9751
  this.#lastDirectEmittedAudioCursorByStream.delete(key);
9575
9752
  this.#pendingDirectRecoveredAudioByStream.delete(key);
9576
- this.#manifestRecoveryQueues.delete(key);
9577
9753
  this.#trackInitDelivered.delete(key);
9578
9754
  this.#parserDiagnostics.delete(key);
9579
9755
  this.#pendingFecPokes.delete(key);
@@ -9834,8 +10010,9 @@ var MmtpRouter = class {
9834
10010
  this.#parserDiagnostics.clear();
9835
10011
  this.#catalogTrackNamesByPacketId.clear();
9836
10012
  this.#repairOwnersByPacketId.clear();
9837
- if (this.#ownsManifestVerifier) this.#manifestVerifier?.dispose();
9838
- this.#manifestRecoveryQueues.clear();
10013
+ for (const { receiver } of this.#provenance.values()) receiver.release();
10014
+ this.#provenance.clear();
10015
+ this.#provenanceStreamFlow.clear();
9839
10016
  for (const assembler of this.#mseAssemblers.values()) assembler.dispose();
9840
10017
  this.#mseAssemblers.clear();
9841
10018
  }
@@ -10112,7 +10289,7 @@ var MmtpRouter = class {
10112
10289
  * 1. parseHeader() → extract packetId + fecPayloadId for FEC feeding
10113
10290
  * 2. feed() → MFU extraction, reassembly, keyframe detection, emit via callbacks
10114
10291
  */
10115
- #processMMTP(packet, source, manifestIdentity, manifestAdmitted = false, ingress, overlapCopy = false, releasedFromQuarantine = false) {
10292
+ #processMMTP(packet, source, manifestAdmitted = false, ingress, overlapCopy = false, releasedFromQuarantine = false) {
10116
10293
  const parsed = this.#parser.parsePacket(packet);
10117
10294
  if (!parsed) return;
10118
10295
  const info = parsed.info;
@@ -10137,43 +10314,32 @@ var MmtpRouter = class {
10137
10314
  }
10138
10315
  const fecUnreadable = !info.isRepair && info.fecPayloadId != null && this.#fecManager !== null && this.#classifyPacketId(info.packetId) !== null && this.#configuredBlockProfile(info.packetId) === void 0;
10139
10316
  if (fecUnreadable && !manifestAdmitted) this.#noteUnreadableFecPayloadId(info.packetId, "source");
10140
- if (!info.isRepair && this.#manifestVerifier && !manifestAdmitted) {
10141
- let identity = manifestIdentity;
10142
- if (!identity && info.fecPayloadId && !fecUnreadable && (this.#resolveManifestIdentityForRoute || this.#resolveManifestIdentity)) {
10143
- const catalogTrackName = catalogTrackNameForPacket(ingress, info.packetId);
10144
- const coordinates = this.#locateFecSource(info.packetId, catalogTrackName, info.fecPayloadId.ssId);
10145
- identity = coordinates === null ? void 0 : (this.#resolveManifestIdentityForRoute ? this.#resolveManifestIdentityForRoute({
10146
- packetId: info.packetId,
10147
- sbn: coordinates.sbn,
10148
- esi: coordinates.esi,
10149
- ...catalogTrackName === void 0 ? {} : { catalogTrackName },
10150
- recovered: false,
10151
- sourceSymbolFormat: "full-mmtp-packet"
10152
- }) : this.#resolveManifestIdentity(
10153
- info.packetId,
10154
- coordinates.sbn,
10155
- coordinates.esi,
10156
- catalogTrackName
10157
- )) ?? void 0;
10158
- }
10159
- if (identity) {
10160
- identity = {
10161
- ...identity,
10162
- packetId: info.packetId,
10163
- ...info.fecPayloadId ? { ssId: info.fecPayloadId.ssId } : {}
10164
- };
10165
- const authenticated = info.fecPayloadId ? packet.subarray(0, packet.length - 4) : packet;
10166
- let quarantined = false;
10167
- const admission = this.#manifestVerifier.admitObject(identity, authenticated, () => {
10168
- if (!this.#disposed) {
10169
- this.#processMMTP(packet, source, identity, true, ingress, overlapCopy, quarantined);
10170
- }
10171
- });
10172
- quarantined = admission.action === "stall";
10317
+ if (source === "multicast" && manifestAdmitted && !info.isRepair && ingress?.flow !== void 0) {
10318
+ let byName = this.#provenanceStreamFlow.get(info.packetId);
10319
+ if (!byName) this.#provenanceStreamFlow.set(info.packetId, byName = /* @__PURE__ */ new Map());
10320
+ byName.set(catalogTrackNameForPacket(ingress, info.packetId), ingress.flow);
10321
+ }
10322
+ if (source === "multicast" && !manifestAdmitted && ingress?.flow !== void 0) {
10323
+ const protectedFlow = this.#provenance.get(ingress.flow);
10324
+ if (!protectedFlow) {
10325
+ this.#unregisteredFlowDrops++;
10326
+ debugRouter(`[MmtpRouter] Dropping multicast packet pid=${info.packetId}: flow ${ingress.flow} has no receiver`);
10173
10327
  return;
10174
10328
  }
10175
- if (this.#manifestVerifier.config.mode === "enforce" && this.#manifestVerifier.config.onMissingManifest === "stall") {
10176
- console.warn(`[MmtpRouter] manifest identity absent; stalling packetId=${info.packetId}`);
10329
+ const { verdict } = protectedFlow.receiver.onDatagram(packet, "multicast");
10330
+ if (verdict === "admitted") {
10331
+ this.#noteFlowAdmitted(ingress.flow);
10332
+ this.#processMMTP(packet, source, true, ingress, overlapCopy);
10333
+ } else if (verdict === "held") {
10334
+ this.#heldIngress.set(packet, ingress);
10335
+ this.#heldAt.set(packet, performance.now());
10336
+ }
10337
+ return;
10338
+ }
10339
+ if (source === "moq" && !manifestAdmitted) {
10340
+ const admit = this.#admitUnicast(info.packetId, packet, () => this.#processMMTP(packet, source, true, ingress, overlapCopy, true), overlapCopy);
10341
+ if (admit !== "unlisted") {
10342
+ if (admit === "admitted") this.#processMMTP(packet, source, true, ingress, overlapCopy);
10177
10343
  return;
10178
10344
  }
10179
10345
  }
@@ -10183,6 +10349,7 @@ var MmtpRouter = class {
10183
10349
  const ownerPacketId = this.#resolveRepairOwnerPacketId(info.packetId, ingress);
10184
10350
  if (ownerPacketId != null && this.#fecManager) {
10185
10351
  if (hasAmbiguousCatalogTrackName(ingress, ownerPacketId)) return;
10352
+ if (source === "moq" && !manifestAdmitted && this.#setAsideUnlistedRepair(ownerPacketId)) return;
10186
10353
  this.#repairPidCounts[info.packetId] = (this.#repairPidCounts[info.packetId] || 0) + 1;
10187
10354
  const count = this.#repairPidCounts[info.packetId];
10188
10355
  if (count <= 2 || count % 500 === 0) {
@@ -10350,36 +10517,22 @@ var MmtpRouter = class {
10350
10517
  sourceFec.symbolData,
10351
10518
  catalogTrackName
10352
10519
  );
10353
- if (recovered) {
10354
- if (!alreadyCompleted && this.#classifyPacketId(info.packetId) !== null) {
10520
+ if (recovered && !alreadyCompleted) {
10521
+ const fec = this.#fecManager;
10522
+ const sbn = sourceFec.sbn;
10523
+ const packetId = info.packetId;
10524
+ const tracked = this.#classifyPacketId(packetId) !== null;
10525
+ this.#routeRecoveredBlock(sbn, recovered, packetId, catalogTrackName, () => {
10355
10526
  if (catalogTrackName === void 0) {
10356
- this.#fecManager.cancelBlockTimeout(sourceFec.sbn, info.packetId);
10527
+ if (tracked) fec.cancelBlockTimeout(sbn, packetId);
10528
+ fec.countRecovery(packetId, sbn, catalogTrackName);
10529
+ fec.markBlockCompleted(sbn, packetId);
10357
10530
  } else {
10358
- this.#fecManager.cancelBlockTimeout(
10359
- sourceFec.sbn,
10360
- info.packetId,
10361
- catalogTrackName
10362
- );
10531
+ if (tracked) fec.cancelBlockTimeout(sbn, packetId, catalogTrackName);
10532
+ fec.countRecovery(packetId, sbn, catalogTrackName);
10533
+ fec.markBlockCompleted(sbn, packetId, catalogTrackName);
10363
10534
  }
10364
- }
10365
- if (!alreadyCompleted) {
10366
- this.#fecManager.countRecovery(info.packetId, sourceFec.sbn, catalogTrackName);
10367
- if (catalogTrackName === void 0) {
10368
- this.#fecManager.markBlockCompleted(sourceFec.sbn, info.packetId);
10369
- } else {
10370
- this.#fecManager.markBlockCompleted(
10371
- sourceFec.sbn,
10372
- info.packetId,
10373
- catalogTrackName
10374
- );
10375
- }
10376
- this.#routeRecoveredBlock(
10377
- sourceFec.sbn,
10378
- recovered,
10379
- info.packetId,
10380
- catalogTrackName
10381
- );
10382
- }
10535
+ });
10383
10536
  }
10384
10537
  }
10385
10538
  }
@@ -10755,7 +10908,7 @@ var MmtpRouter = class {
10755
10908
  }
10756
10909
  // ── Private: FEC recovery routing ───────────────────────────────
10757
10910
  /** Route WASM-recovered block through appropriate path based on container kind. */
10758
- #routeRecoveredBlock(blockId, recovered, ownerPacketId, catalogTrackName) {
10911
+ #routeRecoveredBlock(blockId, recovered, ownerPacketId, catalogTrackName, complete) {
10759
10912
  const packetSymbolSize = this.#symbolSizeForPacket(ownerPacketId);
10760
10913
  if (ownerPacketId === void 0) {
10761
10914
  throw new Error("[MmtpRouter] a recovered FEC block needs its owner packetId to read its fec.blockProfile");
@@ -10772,103 +10925,68 @@ var MmtpRouter = class {
10772
10925
  ownerPacketId,
10773
10926
  blockProfile
10774
10927
  });
10775
- this.#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
10928
+ return this.#routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete);
10776
10929
  }
10777
- #routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
10778
- if (!this.#manifestVerifier || ownerPacketId == null) {
10779
- this.#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
10780
- return;
10781
- }
10782
- if (!this.#resolveManifestIdentity && !this.#resolveManifestIdentityForRoute) {
10783
- console.warn(`[MmtpRouter] manifest identity resolver unavailable; recovered media is fail-open for packetId=${ownerPacketId} block=${blockId}`);
10784
- this.#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
10785
- return;
10930
+ /**
10931
+ * A recovered source packet of a protected flow is admitted on its own
10932
+ * digest: its bytes with the SS_ID it was sent with (SS_Start + ESI)
10933
+ * appended are the datagram the record listed (7.2.7). One that no record
10934
+ * lists is dropped; holding it would let it out later as a multicast arrival.
10935
+ * Returns whether the decode recovered the block: every packet it yields
10936
+ * that this router has not parsed already is admitted. A block one of whose
10937
+ * recovered packets is refused is unrecovered (7.2.7): its caller leaves it
10938
+ * open, so it reaches its FEC deadline and fails by class. Always true
10939
+ * outside a protected flow.
10940
+ */
10941
+ #routeVerifiedFecSymbols(blockId, result, ownerPacketId, catalogTrackName, complete) {
10942
+ const receiver = ownerPacketId == null ? void 0 : this.#provenanceFor(ownerPacketId, catalogTrackName);
10943
+ let recovered = true;
10944
+ if (receiver) {
10945
+ const parsed = this.#stream(ownerPacketId, catalogTrackName).duplicates.parsedSymbols;
10946
+ result = {
10947
+ ...result,
10948
+ symbols: result.symbols.filter((sym) => {
10949
+ const ssId = this.#fecAnchorForRecovered(blockId, sym.index);
10950
+ if (parsed.has(ssId)) return false;
10951
+ let admitted = false;
10952
+ if (receiver === "ambiguous") {
10953
+ this.#ambiguousRecoveredDrops++;
10954
+ } else {
10955
+ const wire = new Uint8Array(sym.rawSymbol.byteLength + 4);
10956
+ wire.set(sym.rawSymbol);
10957
+ new DataView(wire.buffer).setUint32(sym.rawSymbol.byteLength, ssId);
10958
+ admitted = receiver.admitRecovered(wire);
10959
+ }
10960
+ if (!admitted) recovered = false;
10961
+ return admitted;
10962
+ })
10963
+ };
10786
10964
  }
10787
- const queueKey = this.#mediaStreamKey(ownerPacketId, catalogTrackName);
10788
- const queue = this.#manifestRecoveryQueues.get(queueKey) ?? [];
10789
- queue.push({ blockId, result, ownerPacketId, catalogTrackName });
10790
- this.#manifestRecoveryQueues.set(queueKey, queue);
10791
- if (queue.length > 1) return;
10792
- const drain = () => {
10793
- const next = queue[0];
10794
- if (!next) {
10795
- this.#manifestRecoveryQueues.delete(queueKey);
10796
- return;
10965
+ if (recovered) complete?.();
10966
+ this.#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
10967
+ return recovered;
10968
+ }
10969
+ /**
10970
+ * The receiver a recovered packet of `packetId` answers to: the flow that
10971
+ * admitted the stream's source datagrams. Before any was admitted, the one
10972
+ * flow whose registration lists the stream; more than one (a repair flow
10973
+ * also lists its owners' source tracks) cannot be told apart, so none.
10974
+ */
10975
+ #provenanceFor(packetId, catalogTrackName) {
10976
+ const byName = this.#provenanceStreamFlow.get(packetId);
10977
+ const flows = new Set(
10978
+ catalogTrackName === void 0 || !byName ? byName?.values() : byName.has(catalogTrackName) ? [byName.get(catalogTrackName)] : []
10979
+ );
10980
+ if (flows.size > 1) return "ambiguous";
10981
+ for (const bound of flows) return this.#provenance.get(bound)?.receiver ?? "ambiguous";
10982
+ let match;
10983
+ for (const { receiver, ingress } of this.#provenance.values()) {
10984
+ if (ingress.tracks.some((t) => t.packetId === packetId && (catalogTrackName === void 0 || t.name === catalogTrackName))) {
10985
+ if (match) return "ambiguous";
10986
+ match = receiver;
10797
10987
  }
10798
- this.#admitRecoveredResult(
10799
- next.blockId,
10800
- next.result,
10801
- next.ownerPacketId,
10802
- next.catalogTrackName,
10803
- () => {
10804
- queue.shift();
10805
- drain();
10806
- }
10807
- );
10808
- };
10809
- drain();
10810
- }
10811
- #admitRecoveredResult(blockId, result, ownerPacketId, catalogTrackName, done) {
10812
- const verifier = this.#manifestVerifier;
10813
- const resolveIdentity = this.#resolveManifestIdentity;
10814
- const resolveIdentityForRoute = this.#resolveManifestIdentityForRoute;
10815
- if (!verifier) {
10816
- this.#routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName);
10817
- done();
10818
- return;
10819
10988
  }
10820
- if (!resolveIdentity && !resolveIdentityForRoute) throw new Error("manifest identity resolver disappeared during admission");
10821
- const symbols = result.symbols;
10822
- const admitNext = (index) => {
10823
- const symbol = symbols[index];
10824
- if (!symbol) {
10825
- done();
10826
- return;
10827
- }
10828
- const identity = resolveIdentityForRoute ? resolveIdentityForRoute({
10829
- packetId: ownerPacketId,
10830
- sbn: blockId,
10831
- esi: symbol.index,
10832
- ...catalogTrackName === void 0 ? {} : { catalogTrackName },
10833
- recovered: true,
10834
- sourceSymbolFormat: "fec-padded-recovery"
10835
- }) : resolveIdentity(ownerPacketId, blockId, symbol.index, catalogTrackName);
10836
- if (!identity) {
10837
- console.warn(`[MmtpRouter] manifest identity unresolved; recovered symbol is fail-open for packetId=${ownerPacketId} block=${blockId} esi=${symbol.index}`);
10838
- this.#routeProcessedFecSymbols(
10839
- blockId,
10840
- { ...result, symbols: [symbol] },
10841
- ownerPacketId,
10842
- catalogTrackName
10843
- );
10844
- admitNext(index + 1);
10845
- return;
10846
- }
10847
- const admission = verifier.admitObject(
10848
- {
10849
- ...identity,
10850
- packetId: ownerPacketId
10851
- },
10852
- symbol.rawSymbol,
10853
- () => {
10854
- if (!this.#disposed) {
10855
- this.#routeProcessedFecSymbols(
10856
- blockId,
10857
- { ...result, symbols: [symbol] },
10858
- ownerPacketId,
10859
- catalogTrackName
10860
- );
10861
- }
10862
- admitNext(index + 1);
10863
- },
10864
- // A stalled symbol that is later discarded instead of played must still
10865
- // advance this loop; enforce mode never calls the release callback for
10866
- // it (BLO-30095).
10867
- () => admitNext(index + 1)
10868
- );
10869
- if (admission.action === "drop") admitNext(index + 1);
10870
- };
10871
- admitNext(0);
10989
+ return match;
10872
10990
  }
10873
10991
  #routeProcessedFecSymbols(blockId, result, ownerPacketId, catalogTrackName) {
10874
10992
  if (ownerPacketId == null) return;