@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
@@ -333,6 +333,18 @@ const OVERLAY_REBUILT_LIMIT = 256;
333
333
  * longer recover and be admitted as multicast-only. */
334
334
  const OVERLAY_MOQ_HORIZON_BLOCKS = 64;
335
335
 
336
+ /**
337
+ * Where a packet entered this router. `'multicast'` and `'moq'` are the
338
+ * transport attribution every frame carries (`MmtpSourcePath`);
339
+ * `'moq-datagram'` is an "mfu-datagram" subscription (mmt-02 4.3.1): a lossy
340
+ * unicast leg, so it takes every loss rule a multicast datagram takes (FEC
341
+ * holds, deadlines, startup partial blocks, the publisher-restart epoch,
342
+ * 7.2.7 unicast admission) and none of the multicast socket's (ingress
343
+ * flows, the ordered-relay frontier). Frames it yields are attributed
344
+ * `'moq'` and their provenance `'mixed'`: the bytes crossed QUIC.
345
+ */
346
+ export type MmtpIngestSource = MmtpSourcePath | "moq-datagram";
347
+
336
348
  export interface MmtpIngressContext {
337
349
  tracks: readonly Readonly<{ name: string; packetId: number }>[];
338
350
  /**
@@ -781,6 +793,8 @@ export interface FECManagerLike {
781
793
  /** fec-01 4.5: refuse a repair header whose block length the track's scheme
782
794
  * forbids, before it touches block state (optional). */
783
795
  admitRepairBlockLength?(packetId: number, ssbLength: number, rsbLength: number, rsId: number): boolean;
796
+ /** Count a repair packet dropped because its owning track could not be named (optional). */
797
+ countUnresolvedRepairOwner?(reason: "unregistered" | "ownerAbsent" | "ownerAmbiguous"): void;
784
798
  /** core-00 7.5 / mmt-02 7.3 admission of one repair object of the named
785
799
  * instance; counts a discard per instance (optional). */
786
800
  admitRepairObject?(
@@ -822,13 +836,16 @@ export interface FECManagerLike {
822
836
  /** Delivery-gap sample for one multicast packet (FECManager.noteMulticastArrival). */
823
837
  noteMulticastArrival?(packetId: number, packetSequenceNumber: number): void;
824
838
 
839
+ /** Delivery-gap sample for one packet of a lossy path, keyed by path (FECManager.noteArrival). */
840
+ noteArrival?(path: "multicast" | "moq-datagram", packetId: number, packetSequenceNumber: number): void;
841
+
825
842
  /** Record a transport symbol for first-arrival-wins dedup and path counters. */
826
843
  feedSymbolFromSource(
827
844
  packetId: number,
828
845
  sbn: number,
829
846
  esi: number,
830
847
  data: Uint8Array,
831
- source: "multicast" | "moq",
848
+ source: MmtpIngestSource,
832
849
  catalogTrackName?: string,
833
850
  ): boolean;
834
851
 
@@ -889,16 +906,32 @@ export interface FECManagerLike {
889
906
  catalogTrackName?: string,
890
907
  ): { mode: ClassifierMode; reason: ClassifierReason | null };
891
908
 
892
- /** Whether an MPU boundary still bounds the stream's RAPs. */
893
- mpuBoundsRapsFor?(packetId: number, catalogTrackName?: string): boolean;
909
+ /**
910
+ * Whether an MPU boundary still bounds the stream's RAPs; given a gap
911
+ * inside one MPU, whether the catalog keyframe interval also rules a
912
+ * keyframe out of it and no source held in the gap carries part of a RAP
913
+ * (FECManager.mpuBoundsRapsFor).
914
+ */
915
+ mpuBoundsRapsFor?(
916
+ packetId: number,
917
+ catalogTrackName?: string,
918
+ gap?: {
919
+ readonly mpu: number;
920
+ readonly from?: AuthoredTiming;
921
+ readonly to?: AuthoredTiming;
922
+ readonly fromSsId?: number;
923
+ readonly toSsId?: number;
924
+ },
925
+ ): boolean;
894
926
 
895
- /** Record a RAP released in order (RAP-spacing invariant). */
927
+ /** Record a RAP released in order (RAP-spacing invariant; its decode time anchors the MPU's keyframe instants). */
896
928
  noteReleasedRap?(
897
929
  packetId: number,
898
930
  catalogTrackName: string | undefined,
899
931
  mpu: number,
900
932
  presentationTime: bigint,
901
933
  mediaTimescale: number,
934
+ decodeTime?: bigint,
902
935
  ): void;
903
936
 
904
937
  /** Refresh the block inactivity deadline after accepted repair progress. */
@@ -966,7 +999,7 @@ export interface FECManagerLike {
966
999
  fromSsId: number,
967
1000
  toSsId: number,
968
1001
  ): readonly number[] | null;
969
- /** iso-ssbg1-v1: how long a frame waits once only a late source can fill the SS_IDs before it, longer when they may hold a RAP an installed keyframe overlay can still rebuild (FECManager.isoRepairlessWaitMs). */
1002
+ /** iso-ssbg1-v1: how long a frame that arrived at `arrivedAtMs` waits once only a late source can fill the SS_IDs before it, longer when they may hold a RAP an installed keyframe overlay can still rebuild, or behind a run no repair has delimited until its FEC deadline (FECManager.isoRepairlessWaitMs). */
970
1003
  isoRepairlessWaitMs?(
971
1004
  packetId: number,
972
1005
  catalogTrackName: string | undefined,
@@ -974,6 +1007,7 @@ export interface FECManagerLike {
974
1007
  toSsId: number,
975
1008
  rapMayHide?: boolean,
976
1009
  rapNext?: boolean,
1010
+ arrivedAtMs?: number,
977
1011
  ): number | undefined;
978
1012
 
979
1013
 
@@ -983,6 +1017,8 @@ export interface FECManagerLike {
983
1017
  * how long the router keeps a stream's duplicate ledgers.
984
1018
  */
985
1019
  blockLifetimeMsForPacket?(packetId: number): number | undefined;
1020
+ /** Duplicate-ledger retention an "mfu-datagram" leg needs (FECManager.datagramLegLedgerRetentionMsForPacket). */
1021
+ datagramLegLedgerRetentionMsForPacket?(packetId: number): number | undefined;
986
1022
 
987
1023
  /** FEC symbol size T in bytes (0 = unknown / no FEC). */
988
1024
  readonly symbolSize: number;
@@ -1116,6 +1152,20 @@ export class MmtpRouter {
1116
1152
  /** The flow whose receiver admitted a stream's source datagrams, by packetId then catalog track name: recovered packets answer to it. */
1117
1153
  readonly #provenanceStreamFlow = new Map<number, Map<string | undefined, string>>();
1118
1154
  #unregisteredFlowDrops = 0;
1155
+ /** "mfu-datagram" leg packets of a packet id the ingress does not name (never the signaling flow). */
1156
+ #datagramLegIngressDrops = 0;
1157
+ /** "mfu-datagram" leg packets of the signaling flow (packet id 0): expected, one per group. */
1158
+ #datagramLegSignalingPackets = 0;
1159
+ /**
1160
+ * The streams a live "mfu-datagram" leg has fed, catalog track names by
1161
+ * packet id: their ledgers and release gate take the leg's bounds. A stream
1162
+ * leaves when its leg does: `endDatagramLeg`, `resetTrack`, `dispose`, or
1163
+ * the first multicast packet of its packet id (the ordered switch retires
1164
+ * the leg first). The "mfu" sibling shares the packet id, never the name.
1165
+ */
1166
+ readonly #datagramLegStreams = new Map<number, Set<string | undefined>>();
1167
+ /** The leg's presentation budget (setDatagramLegPresentationBudget), or null: no presentation bound. */
1168
+ #datagramLegPresentationBudgetMs: ((packetId: number, catalogTrackName?: string) => number) | null = null;
1119
1169
  #ambiguousRecoveredDrops = 0;
1120
1170
 
1121
1171
  // Temp state set by #processMMTP before calling parser.feed(),
@@ -1668,10 +1718,14 @@ export class MmtpRouter {
1668
1718
  if (blockSpanMs === undefined || blockLifetimeMs === undefined) return NO_FEC_GEOMETRY_HORIZON;
1669
1719
  // FECManager reports 0 for a stream the catalog gave no block span.
1670
1720
  if (blockSpanMs === 0) return NO_BLOCK_SPAN_HORIZON;
1671
- return {
1672
- kind: "fec-horizon",
1673
- retentionMs: duplicateRetentionMs({ blockSpanMs, blockLifetimeMs }),
1674
- };
1721
+ let retentionMs = duplicateRetentionMs({ blockSpanMs, blockLifetimeMs });
1722
+ // An "mfu-datagram" leg's datagrams may trail a joining FETCH by a whole
1723
+ // group: remember at least span + tolerance + group, or the lag reads as
1724
+ // a publisher restart (mmt-02 4.3.1, 6.1 step 3).
1725
+ if (this.#datagramLegStreams.has(packetId)) {
1726
+ retentionMs = Math.max(retentionMs, fec.datagramLegLedgerRetentionMsForPacket?.(packetId) ?? 0);
1727
+ }
1728
+ return { kind: "fec-horizon", retentionMs };
1675
1729
  }
1676
1730
 
1677
1731
  /**
@@ -2177,7 +2231,7 @@ export class MmtpRouter {
2177
2231
  repairPacketId: number,
2178
2232
  packet: Uint8Array,
2179
2233
  header: MMTPHeader,
2180
- source: "multicast" | "moq",
2234
+ source: MmtpIngestSource,
2181
2235
  ): void {
2182
2236
  const repair = inst ? parseMoqRepairFrameWithHeader(packet, header) : null;
2183
2237
  if (!inst || !repair) {
@@ -2193,7 +2247,7 @@ export class MmtpRouter {
2193
2247
  const blockStart = placement.block.start;
2194
2248
  if (placement.span !== undefined) this.#replayOverlaySources(inst, placement.span.block.start, placement.span.placed);
2195
2249
  this.#replayOverlaySources(inst, blockStart, placement.placed);
2196
- if (source === "moq") this.#noteOverlayMoqBlock(inst, blockStart);
2250
+ if (source !== "multicast") this.#noteOverlayMoqBlock(inst, blockStart);
2197
2251
  const alreadyCompleted = fec.isBlockCompleted(blockStart, pid, name);
2198
2252
  const recovered = fec.feedRepairSymbol(pid, repair.ssStart, repair.ssbLength, repair.rsId, repair.symbolData, name);
2199
2253
  if (recovered && !alreadyCompleted) this.#routeOverlayRecovered(inst, blockStart, recovered);
@@ -2206,7 +2260,7 @@ export class MmtpRouter {
2206
2260
  ): void {
2207
2261
  const { fec, repairPacketId: pid, streamName: name } = inst;
2208
2262
  for (const { ssId, payload } of placed) {
2209
- if (payload.source === "moq") this.#noteOverlayMoqBlock(inst, blockStart);
2263
+ if (payload.source !== "multicast") this.#noteOverlayMoqBlock(inst, blockStart);
2210
2264
  if (payload.oversized) continue;
2211
2265
  const alreadyCompleted = fec.isBlockCompleted(blockStart, pid, name);
2212
2266
  const recovered = fec.feedSourceSymbol(pid, ssId, payload.symbolData, name);
@@ -2235,7 +2289,7 @@ export class MmtpRouter {
2235
2289
  header: MMTPHeader,
2236
2290
  sequenceNumber: number,
2237
2291
  rapFlag: boolean,
2238
- source: MmtpSourcePath,
2292
+ source: MmtpIngestSource,
2239
2293
  baseSsId: number | undefined,
2240
2294
  ): void {
2241
2295
  if (this.#overlays.size === 0) return;
@@ -2278,7 +2332,7 @@ export class MmtpRouter {
2278
2332
  });
2279
2333
  continue;
2280
2334
  }
2281
- if (source === "moq") this.#noteOverlayMoqBlock(inst, coords.sbn);
2335
+ if (source !== "multicast") this.#noteOverlayMoqBlock(inst, coords.sbn);
2282
2336
  if (oversized) continue;
2283
2337
  const alreadyCompleted = fec.isBlockCompleted(coords.sbn, pid, name);
2284
2338
  const recovered = fec.feedSourceSymbol(pid, ssId, symbolData, name);
@@ -3027,6 +3081,51 @@ export class MmtpRouter {
3027
3081
  return this.#unregisteredFlowDrops;
3028
3082
  }
3029
3083
 
3084
+ /** "mfu-datagram" leg packets dropped because the leg's ingress does not name their packet id (packet id 0 apart). */
3085
+ get datagramLegIngressDropCount(): number {
3086
+ return this.#datagramLegIngressDrops;
3087
+ }
3088
+
3089
+ /** "mfu-datagram" leg packets of the MMTP signaling flow (packet id 0), which no track owns. */
3090
+ get datagramLegSignalingPacketCount(): number {
3091
+ return this.#datagramLegSignalingPackets;
3092
+ }
3093
+
3094
+ /**
3095
+ * The "mfu-datagram" leg's presentation bound (mmt-02 6.1 step 6): how
3096
+ * long after a frame arrives it must leave the release gate when the gap
3097
+ * before it holds no RAP, FT=0 or FT=1 data (the player's presentation
3098
+ * delay less its decode lead). The gap is then decided at the earlier of
3099
+ * the FEC block deadline and this bound; a gap that may hold a RAP keeps
3100
+ * the block deadline. Null, or a value that is not finite and positive:
3101
+ * the block deadline alone, as on multicast.
3102
+ */
3103
+ setDatagramLegPresentationBudget(budgetMs: ((packetId: number, catalogTrackName?: string) => number) | null): void {
3104
+ this.#datagramLegPresentationBudgetMs = budgetMs;
3105
+ }
3106
+
3107
+ /**
3108
+ * The "mfu-datagram" leg is over (unsubscribed, or switched to another
3109
+ * path): no stream keeps its presentation bound or its ledger retention.
3110
+ * Parser, FEC and ledger state stay, so the packet ids continue on the
3111
+ * next path without an epoch. A later leg datagram starts a leg again.
3112
+ */
3113
+ endDatagramLeg(): void {
3114
+ this.#datagramLegStreams.clear();
3115
+ this.#datagramLegPresentationBudgetMs = null;
3116
+ }
3117
+
3118
+ #datagramLegPresentationWaitMs(packetId: number, catalogTrackName: string | undefined): number | undefined {
3119
+ if (this.#datagramLegPresentationBudgetMs === null || this.#datagramLegStreams.get(packetId)?.has(catalogTrackName) !== true) return undefined;
3120
+ let budgetMs: number;
3121
+ try {
3122
+ budgetMs = this.#datagramLegPresentationBudgetMs(packetId, catalogTrackName);
3123
+ } catch {
3124
+ return undefined;
3125
+ }
3126
+ return Number.isFinite(budgetMs) && budgetMs > 0 ? budgetMs : undefined;
3127
+ }
3128
+
3030
3129
  /** Recovered packets dropped because more than one protected flow could own their stream. */
3031
3130
  get ambiguousRecoveredDropCount(): number {
3032
3131
  return this.#ambiguousRecoveredDrops;
@@ -3045,10 +3144,14 @@ export class MmtpRouter {
3045
3144
  * caller that forgot it silently attributed its bytes to a multicast socket
3046
3145
  * they may never have crossed — and that attribution is what the physical-
3047
3146
  * delivery evidence path is built on. Absence is not multicast; say which.
3147
+ * `"moq-datagram"` is an "mfu-datagram" subscription (MmtpIngestSource):
3148
+ * `ingress.tracks` MUST name the datagram catalog track for its packet id,
3149
+ * and a packet of a packet id it does not name is dropped and counted
3150
+ * (`datagramLegIngressDropCount`; the signaling flow, packet id 0, apart).
3048
3151
  */
3049
3152
  feedPacket(
3050
3153
  packet: Uint8Array,
3051
- source: "multicast" | "moq",
3154
+ source: MmtpIngestSource,
3052
3155
  ingress?: MmtpIngressContext,
3053
3156
  ): void {
3054
3157
  if (this.#disposed) return;
@@ -3105,17 +3208,21 @@ export class MmtpRouter {
3105
3208
 
3106
3209
  /**
3107
3210
  * Feed a repair packet from MoQ (reliable QUIC) — parses MMTP repair
3108
- * header and delegates to FECManager for FEC recovery.
3211
+ * header and delegates to FECManager for FEC recovery. `source` is
3212
+ * `"moq-datagram"` for a repair object of an "mfu-datagram" track's repair
3213
+ * track, which arrives as a datagram and so counts as an in-band symbol of
3214
+ * the leg; a FETCHed repair stays `"moq"` (RepairVia `quic`).
3109
3215
  */
3110
3216
  feedRepairPacket(
3111
3217
  packet: Uint8Array,
3112
3218
  ownerPacketIdHint?: number,
3113
3219
  catalogTrackName?: string,
3114
3220
  repairTrackName?: string,
3221
+ source: "moq" | "moq-datagram" = "moq",
3115
3222
  ): void {
3116
3223
  if (this.#disposed) return;
3117
3224
  this.#withDeferredFecPokes(() => {
3118
- this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName);
3225
+ this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source);
3119
3226
  });
3120
3227
  }
3121
3228
 
@@ -3124,6 +3231,7 @@ export class MmtpRouter {
3124
3231
  ownerPacketIdHint: number | undefined,
3125
3232
  catalogTrackName: string | undefined,
3126
3233
  repairTrackName: string | undefined,
3234
+ source: "moq" | "moq-datagram",
3127
3235
  admitted = false,
3128
3236
  ): void {
3129
3237
  // One header parse per packet, as on the multicast repair branch: mmt-fec's
@@ -3139,7 +3247,7 @@ export class MmtpRouter {
3139
3247
  const repairPacketId = header.packetId;
3140
3248
  const overlay = this.#overlayRepairTarget(repairPacketId, repairTrackName);
3141
3249
  if (overlay !== undefined) {
3142
- this.#routeOverlayRepair(overlay, repairPacketId, packet, header, "moq");
3250
+ this.#routeOverlayRepair(overlay, repairPacketId, packet, header, source);
3143
3251
  return;
3144
3252
  }
3145
3253
 
@@ -3167,7 +3275,7 @@ export class MmtpRouter {
3167
3275
  let unlisted = false;
3168
3276
  if (ownerPacketId != null && !admitted) {
3169
3277
  const admit = this.#admitUnicast(repairPacketId, packet, () =>
3170
- this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, true));
3278
+ this.#feedRepairPacket(packet, ownerPacketIdHint, catalogTrackName, repairTrackName, source, true));
3171
3279
  if (admit === "held" || admit === "dropped") return;
3172
3280
  unlisted = admit === "unlisted";
3173
3281
  }
@@ -3191,7 +3299,7 @@ export class MmtpRouter {
3191
3299
  this.#noteUnreadableFecPayloadId(ownerPacketId, "repair");
3192
3300
  return;
3193
3301
  }
3194
- this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, "moq", repairTrackName);
3302
+ this.#handleIsoRepair(ownerPacketId, catalogTrackName, parsed, source, repairTrackName);
3195
3303
  }
3196
3304
  }
3197
3305
 
@@ -3315,7 +3423,7 @@ export class MmtpRouter {
3315
3423
  ownerPacketId: number,
3316
3424
  catalogTrackName: string | undefined,
3317
3425
  repair: { ssStart: number; ssbLength: number; rsbLength: number; rsId: number; symbolData: Uint8Array },
3318
- source: "multicast" | "moq",
3426
+ source: MmtpIngestSource,
3319
3427
  repairTrackName?: string,
3320
3428
  ): void {
3321
3429
  const fec = this.#fecManager;
@@ -3463,6 +3571,7 @@ export class MmtpRouter {
3463
3571
  debugRouter(
3464
3572
  `[MmtpRouter] Dropping repair packet pid=${packetId}: physical PID is unregistered`,
3465
3573
  );
3574
+ this.#fecManager?.countUnresolvedRepairOwner?.("unregistered");
3466
3575
  return null;
3467
3576
  }
3468
3577
 
@@ -3476,6 +3585,7 @@ export class MmtpRouter {
3476
3585
  debugRouter(
3477
3586
  `[MmtpRouter] Dropping repair packet pid=${packetId}: catalog owner is ${owners.length === 0 ? "absent" : "ambiguous"}`,
3478
3587
  );
3588
+ this.#fecManager?.countUnresolvedRepairOwner?.(owners.length === 0 ? "ownerAbsent" : "ownerAmbiguous");
3479
3589
  return null;
3480
3590
  }
3481
3591
 
@@ -3546,6 +3656,9 @@ export class MmtpRouter {
3546
3656
  }
3547
3657
  this.#parser.resetTrack(packetId, catalogTrackName);
3548
3658
  this.resetKeyframeOverlays(packetId, catalogTrackName);
3659
+ // A new epoch is no leg stream until a leg datagram says so again.
3660
+ const legNames = this.#datagramLegStreams.get(packetId);
3661
+ if (legNames?.delete(catalogTrackName) && legNames.size === 0) this.#datagramLegStreams.delete(packetId);
3549
3662
  this.#restampedStreams.delete(this.#mediaStreamKey(packetId, catalogTrackName));
3550
3663
  const assistPrefix = assistKey(packetId, catalogTrackName, 0).slice(0, -1);
3551
3664
  for (const key of this.#assistBlocks.keys()) if (key.startsWith(assistPrefix)) this.#assistBlocks.delete(key);
@@ -3938,6 +4051,7 @@ export class MmtpRouter {
3938
4051
  this.#fecWakes.clear();
3939
4052
  this.#parser.dispose();
3940
4053
  this.#streams.clear();
4054
+ this.endDatagramLeg();
3941
4055
  this.#trackPacketCallbacks.clear();
3942
4056
  this.#latestVideoSeqByStream.clear();
3943
4057
  this.#lastDirectSourceVideoTsByStream.clear();
@@ -4162,24 +4276,41 @@ export class MmtpRouter {
4162
4276
  // an audio gap. A gap that may hold one (rap-lost, rap-unknown, or any
4163
4277
  // other rap-next, whose gap may hold a whole MPU and the keyframe the
4164
4278
  // overlay protects) waits for that overlay's repair too (BLO-52085
4165
- // D4). The FEC check comes first: most held gaps are not behind such a
4166
- // span, and deciding one scans both frames' bitstreams.
4279
+ // D4). A run no repair has delimited instead waits for its FEC
4280
+ // deadline, whatever the decision (FECManager.isoRepairlessWaitMs). The
4281
+ // FEC check comes first: most held gaps are not behind such a span, and
4282
+ // deciding one scans both frames' bitstreams.
4167
4283
  unrepairableWaitMs: (before, after, fromSbn, toSbn) => {
4168
4284
  const fec = this.#fecManager;
4169
4285
  const { packetId, catalogTrackName } = after.meta;
4170
- const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn);
4171
- if (!fec || allowanceMs === undefined) return undefined;
4286
+ const arrivedAtMs = after.arrivedAtMs;
4287
+ const allowanceMs = fec?.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, false, arrivedAtMs);
4288
+ // On an "mfu-datagram" leg a gap of delta data alone also goes at the
4289
+ // held frame's presentation time (mmt-02 6.1 step 6), repair pending
4290
+ // or not; a gap that may hold a RAP keeps the block deadline.
4291
+ const presentationMs = this.#datagramLegPresentationWaitMs(packetId, catalogTrackName);
4292
+ if (!fec || (allowanceMs === undefined && presentationMs === undefined)) return undefined;
4172
4293
  const decision = this.#decideGap(before, after, [], false);
4173
4294
  const mpu = before.meta.mpuSequenceNumber;
4174
4295
  const intoNextMpu = decision.reason === "rap-next" && mpu !== undefined &&
4175
4296
  after.meta.mpuSequenceNumber === ((mpu + 1) >>> 0) &&
4176
4297
  fec.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
4177
4298
  if (decision.action === "stall" || (decision.reason === "rap-next" && !intoNextMpu)) {
4178
- return fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true);
4299
+ return allowanceMs === undefined
4300
+ ? undefined
4301
+ : fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, true, false, arrivedAtMs);
4179
4302
  }
4180
- return decision.reason === "rap-next"
4181
- ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true)
4182
- : allowanceMs;
4303
+ const waitMs = allowanceMs === undefined
4304
+ ? undefined
4305
+ : decision.reason === "rap-next"
4306
+ ? fec.isoRepairlessWaitMs?.(packetId, catalogTrackName, fromSbn, toSbn, false, true, arrivedAtMs)
4307
+ : allowanceMs;
4308
+ // A track with no catalog span has no classifier, so nothing ruled a
4309
+ // keyframe out of a gap inside one MPU (FECManager.mpuBoundsRapsFor):
4310
+ // its delta-lost is unproven and never takes the presentation bound.
4311
+ if (decision.reason === "delta-lost" && !((fec.interleaveDepthMsForPacket?.(packetId) ?? 0) > 0)) return waitMs;
4312
+ if (presentationMs === undefined) return waitMs;
4313
+ return waitMs === undefined ? presentationMs : Math.min(waitMs, presentationMs);
4183
4314
  },
4184
4315
  decide: (before, after, lostBlocks, discontinuity) => {
4185
4316
  const decision = this.#decideGap(before, after, lostBlocks, discontinuity);
@@ -4222,6 +4353,7 @@ export class MmtpRouter {
4222
4353
  meta.mpuSequenceNumber,
4223
4354
  timing.presentationTime,
4224
4355
  timing.mediaTimescale,
4356
+ timing.decodeTime,
4225
4357
  );
4226
4358
  },
4227
4359
  };
@@ -4262,9 +4394,25 @@ export class MmtpRouter {
4262
4394
  // boundary bounds the stream's RAPs. Once a RAP was seen inside an MPU
4263
4395
  // (or an MPU outran its GOP), a lost RAP can hide inside one MPU, so the
4264
4396
  // MPU is withheld and a non-RAP after the gap stalls as rap-unknown. A
4265
- // manager that cannot answer is treated as unable to prove it.
4266
- const mpuTrusted =
4267
- this.#fecManager?.mpuBoundsRapsFor?.(packetId, catalogTrackName) === true;
4397
+ // manager that cannot answer is treated as unable to prove it. Inside
4398
+ // one video MPU the catalog keyframe interval must also rule a keyframe
4399
+ // out of the gap (fec-multicast-00 Block Classification item 3), and no
4400
+ // packet held in it may carry part of a RAP.
4401
+ const mpu = before.meta.mpuSequenceNumber;
4402
+ const sameMpu = trackKind === "video" && mpu !== undefined && after.meta.mpuSequenceNumber === mpu;
4403
+ const mpuTrusted = this.#fecManager?.mpuBoundsRapsFor?.(
4404
+ packetId,
4405
+ catalogTrackName,
4406
+ sameMpu
4407
+ ? {
4408
+ mpu,
4409
+ from: before.meta.authoredTiming,
4410
+ to: after.meta.authoredTiming,
4411
+ fromSsId: before.meta.fecSbn,
4412
+ toSsId: after.meta.fecSbnFirst ?? after.meta.fecSbn,
4413
+ }
4414
+ : undefined,
4415
+ ) === true;
4268
4416
  const evidence = (frame: { data: Uint8Array; meta: ParserFrameMeta }): GapFrameEvidence => {
4269
4417
  const timing = frame.meta.authoredTiming;
4270
4418
  const sampleNumber = frame.meta.sampleNumber;
@@ -4403,7 +4551,7 @@ export class MmtpRouter {
4403
4551
  */
4404
4552
  #processMMTP(
4405
4553
  packet: Uint8Array,
4406
- source: "multicast" | "moq",
4554
+ source: MmtpIngestSource,
4407
4555
  manifestAdmitted = false,
4408
4556
  ingress?: MmtpIngressContext,
4409
4557
  overlapCopy = false,
@@ -4422,22 +4570,47 @@ export class MmtpRouter {
4422
4570
  // admission is the same arrival, not a new one.
4423
4571
  if (source === "multicast" && !manifestAdmitted) {
4424
4572
  this.#fecManager?.noteMulticastArrival?.(info.packetId, info.sequenceNumber);
4425
- }
4426
- if (source === "multicast" && !ingressHasPacketId(ingress, info.packetId)) {
4573
+ } else if (source === "moq-datagram" && !manifestAdmitted) {
4574
+ // The leg's own estimator: its stalls never widen the multicast wait.
4575
+ this.#fecManager?.noteArrival?.("moq-datagram", info.packetId, info.sequenceNumber);
4576
+ }
4577
+ if (source !== "moq" && !ingressHasPacketId(ingress, info.packetId)) {
4578
+ if (source === "moq-datagram") {
4579
+ // The signaling object (packet id 0, Object 0 of every group) is no
4580
+ // track's packet and carries no FEC Source Info: counted apart, so
4581
+ // the ingress-drop counter stays a misconfiguration signal.
4582
+ if (info.packetId === MMTP_SIGNALING_PACKET_ID) this.#datagramLegSignalingPackets++;
4583
+ else this.#datagramLegIngressDrops++;
4584
+ }
4427
4585
  debugRouter(
4428
- `[MmtpRouter] Dropping multicast packet pid=${info.packetId}: absent from ingress tracks`,
4586
+ `[MmtpRouter] Dropping ${source} packet pid=${info.packetId}: absent from ingress tracks`,
4429
4587
  );
4430
4588
  return;
4431
4589
  }
4590
+ if (source === "moq-datagram") {
4591
+ if (!info.isRepair) {
4592
+ let names = this.#datagramLegStreams.get(info.packetId);
4593
+ if (!names) this.#datagramLegStreams.set(info.packetId, (names = new Set()));
4594
+ names.add(catalogTrackNameForPacket(ingress, info.packetId));
4595
+ }
4596
+ } else if (source === "multicast") {
4597
+ // The ordered switch retires the leg before the first multicast packet
4598
+ // of its packet id: from here the stream is a multicast one, and the
4599
+ // leg's presentation bound and ledger retention no longer apply.
4600
+ this.#datagramLegStreams.delete(info.packetId);
4601
+ }
4432
4602
  const packetRole = this.#packetIdRoles.get(info.packetId);
4433
4603
  if (
4434
- source === "multicast" &&
4604
+ source !== "moq" &&
4435
4605
  this.#classifyPacketId(info.packetId) === null &&
4436
4606
  (!info.isRepair || packetRole !== "repair")
4437
4607
  ) {
4438
4608
  debugRouter(
4439
- `[MmtpRouter] Dropping multicast packet pid=${info.packetId}: physical PID is unregistered`,
4609
+ `[MmtpRouter] Dropping ${source} packet pid=${info.packetId}: physical PID is unregistered`,
4440
4610
  );
4611
+ // #resolveRepairOwnerPacketId's "unregistered" drop for every leg that is
4612
+ // not a MoQ stream: a multicast leg and a "moq-datagram" leg both count here.
4613
+ if (info.isRepair) this.#fecManager?.countUnresolvedRepairOwner?.("unregistered");
4441
4614
  return;
4442
4615
  }
4443
4616
  if (!info.isRepair && hasAmbiguousCatalogTrackName(ingress, info.packetId)) {
@@ -4495,7 +4668,8 @@ export class MmtpRouter {
4495
4668
 
4496
4669
  // A MoQ packet of a track a protected flow lists is a datagram of that
4497
4670
  // flow on its unicast path (7.2.7): admitted before it is read, or held.
4498
- if (source === "moq" && !manifestAdmitted) {
4671
+ // An "mfu-datagram" object is one too: it crossed QUIC, not the flow.
4672
+ if (source !== "multicast" && !manifestAdmitted) {
4499
4673
  const admit = this.#admitUnicast(info.packetId, packet, () =>
4500
4674
  this.#processMMTP(packet, source, true, ingress, overlapCopy, true), overlapCopy);
4501
4675
  if (admit !== "unlisted") {
@@ -4539,7 +4713,7 @@ export class MmtpRouter {
4539
4713
  // An unadmitted MoQ symbol reaching here is unlisted (#admitUnicast);
4540
4714
  // a flow-less multicast one is unverified.
4541
4715
  if (
4542
- ((flowless && this.#userAgentGoverns(ownerPacketId)) || (source === "moq" && !manifestAdmitted)) &&
4716
+ ((flowless && this.#userAgentGoverns(ownerPacketId)) || (source !== "multicast" && !manifestAdmitted)) &&
4543
4717
  this.#setAsideUnlistedRepair(ownerPacketId, catalogTrackNameForPacket(ingress, ownerPacketId), repair)
4544
4718
  ) return;
4545
4719
  this.#repairPidCounts[info.packetId] = (this.#repairPidCounts[info.packetId] || 0) + 1;
@@ -4620,9 +4794,10 @@ export class MmtpRouter {
4620
4794
  // checked; an overlap copy is MoQ bytes and says nothing about the
4621
4795
  // multicast publisher, and neither does a packet a provenance hold queue
4622
4796
  // released: it predates the horizon because it waited, not because the
4623
- // publisher restarted.
4797
+ // publisher restarted. An "mfu-datagram" leg is the publisher's own
4798
+ // datagrams, so it shows a restart as multicast does.
4624
4799
  if (
4625
- source === "multicast" &&
4800
+ source !== "moq" &&
4626
4801
  !overlapCopy &&
4627
4802
  !releasedFromQuarantine &&
4628
4803
  catalogTrackName !== undefined &&
@@ -4735,6 +4910,10 @@ export class MmtpRouter {
4735
4910
  evidence: sourceSymbolEvidence(packet, parsed.header, info.rapFlag, info.sequenceNumber),
4736
4911
  oversized: !(this.#fecManager.isoSourceFits?.(info.packetId, rawSymbol.length) ?? false),
4737
4912
  }) ?? false;
4913
+ // A held source can complete the SS_IDs a waiting frame's gap asks
4914
+ // for, or anchor its run, as a located one can complete a block:
4915
+ // ask the gate again, or the frame waits for the next packet.
4916
+ if (held) this.#requestFecPoke(info.packetId, catalogTrackName);
4738
4917
  parseSourceSymbol = held && !duplicates.parsedSymbols.has(ssId);
4739
4918
  }
4740
4919
  } else if (fecUnreadable && info.fecPayloadId) {
@@ -4900,7 +5079,7 @@ export class MmtpRouter {
4900
5079
  parserOptions?: {
4901
5080
  skipFecPayloadId?: boolean;
4902
5081
  recovered?: boolean;
4903
- source?: MmtpSourcePath;
5082
+ source?: MmtpIngestSource;
4904
5083
  deliveryProvenance?: MmtpDeliveryProvenance;
4905
5084
  catalogTrackName?: string;
4906
5085
  fecSbn?: number;
@@ -4924,7 +5103,9 @@ export class MmtpRouter {
4924
5103
  const feedOptions = {
4925
5104
  skipFecPayloadId: parserOptions?.skipFecPayloadId,
4926
5105
  recovered: parserOptions?.recovered,
4927
- source: parserOptions?.source,
5106
+ // Frame attribution is the transport path: an "mfu-datagram" object
5107
+ // crossed QUIC, so its frames are 'moq' (provenance 'mixed').
5108
+ source: parserOptions?.source === "moq-datagram" ? "moq" : parserOptions?.source,
4928
5109
  deliveryProvenance: parserOptions?.deliveryProvenance,
4929
5110
  catalogTrackName: parserOptions?.catalogTrackName,
4930
5111
  ...(parserOptions?.fecSbn === undefined ? {} : { fecSbn: parserOptions.fecSbn }),
@@ -4948,7 +5129,7 @@ export class MmtpRouter {
4948
5129
  sbn: number,
4949
5130
  esi: number,
4950
5131
  data: Uint8Array,
4951
- source: MmtpSourcePath,
5132
+ source: MmtpIngestSource,
4952
5133
  catalogTrackName?: string,
4953
5134
  ): boolean {
4954
5135
  const fecManager = this.#fecManager;