@blockcast/mmt-container 2.2.0-main.f480a7ede8b1 → 2.2.0-main.fde7aee36726

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 (137) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +88 -16
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +164 -56
  5. package/dist/block-policy.js.map +3 -3
  6. package/dist/browser-runtime.js +2163 -303
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +40 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +163 -10
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +48 -1
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.js +34 -0
  17. package/dist/catalog-network-source.js.map +3 -3
  18. package/dist/cmaf-block-assembler.js +92 -1
  19. package/dist/cmaf-block-assembler.js.map +2 -2
  20. package/dist/codec-utils.d.ts.map +1 -1
  21. package/dist/codec-utils.js +92 -1
  22. package/dist/codec-utils.js.map +2 -2
  23. package/dist/delivery-catalog.js +68 -0
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/delta-fallback-config.js +39 -1
  26. package/dist/delta-fallback-config.js.map +4 -4
  27. package/dist/fec-manager.d.ts +222 -21
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +875 -131
  30. package/dist/fec-manager.js.map +4 -4
  31. package/dist/fec-state.d.ts +17 -5
  32. package/dist/fec-state.d.ts.map +1 -1
  33. package/dist/fec-state.js +41 -1
  34. package/dist/fec-state.js.map +3 -3
  35. package/dist/fec-worker-setup.js +34 -0
  36. package/dist/fec-worker-setup.js.map +3 -3
  37. package/dist/held-layer-admission.js +34 -0
  38. package/dist/held-layer-admission.js.map +3 -3
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +9 -1
  42. package/dist/index.js.map +2 -2
  43. package/dist/iso-block-locator.d.ts +55 -13
  44. package/dist/iso-block-locator.d.ts.map +1 -1
  45. package/dist/iso-block-locator.js +142 -25
  46. package/dist/iso-block-locator.js.map +3 -3
  47. package/dist/media-router.js.map +1 -1
  48. package/dist/mfu-reassembler.js +34 -0
  49. package/dist/mfu-reassembler.js.map +3 -3
  50. package/dist/mmtp-container-parser.d.ts +72 -10
  51. package/dist/mmtp-container-parser.d.ts.map +1 -1
  52. package/dist/mmtp-container-parser.js +260 -18
  53. package/dist/mmtp-container-parser.js.map +3 -3
  54. package/dist/mmtp-container-parser.no-modules.js +411 -34
  55. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  56. package/dist/mmtp-decode-pipeline.js +260 -18
  57. package/dist/mmtp-decode-pipeline.js.map +3 -3
  58. package/dist/mmtp-fec-session.js +34 -0
  59. package/dist/mmtp-fec-session.js.map +3 -3
  60. package/dist/mmtp-mode-selection.d.ts +48 -0
  61. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  62. package/dist/mmtp-mode-selection.js +79 -0
  63. package/dist/mmtp-mode-selection.js.map +7 -0
  64. package/dist/mmtp-router.d.ts +94 -16
  65. package/dist/mmtp-router.d.ts.map +1 -1
  66. package/dist/mmtp-router.js +754 -78
  67. package/dist/mmtp-router.js.map +4 -4
  68. package/dist/multicast-auth-catalog.js +42 -2
  69. package/dist/multicast-auth-catalog.js.map +3 -3
  70. package/dist/multicast-input.js +42 -2
  71. package/dist/multicast-input.js.map +3 -3
  72. package/dist/multicast-manager.d.ts +121 -4
  73. package/dist/multicast-manager.d.ts.map +1 -1
  74. package/dist/multicast-manager.js +1774 -248
  75. package/dist/multicast-manager.js.map +4 -4
  76. package/dist/multicast-transport.js +70 -2
  77. package/dist/multicast-transport.js.map +4 -4
  78. package/dist/multicast-unwrap.js +34 -0
  79. package/dist/multicast-unwrap.js.map +3 -3
  80. package/dist/no-modules.d.ts +1 -0
  81. package/dist/no-modules.d.ts.map +1 -1
  82. package/dist/no-modules.js +415 -35
  83. package/dist/no-modules.js.map +4 -4
  84. package/dist/phase14-catalog-override.d.ts +2 -1
  85. package/dist/phase14-catalog-override.d.ts.map +1 -1
  86. package/dist/phase14-catalog-override.js +69 -2
  87. package/dist/phase14-catalog-override.js.map +3 -3
  88. package/dist/repair-fetch.d.ts +38 -8
  89. package/dist/repair-fetch.d.ts.map +1 -1
  90. package/dist/repair-fetch.js +336 -27
  91. package/dist/repair-fetch.js.map +3 -3
  92. package/dist/repair-layer-subscriptions.js +34 -0
  93. package/dist/repair-layer-subscriptions.js.map +3 -3
  94. package/dist/signaling.js +34 -0
  95. package/dist/signaling.js.map +3 -3
  96. package/dist/timestamp-codec.js +34 -0
  97. package/dist/timestamp-codec.js.map +3 -3
  98. package/dist/track-session.d.ts.map +1 -1
  99. package/dist/track-session.js +1 -0
  100. package/dist/track-session.js.map +2 -2
  101. package/dist/wasm-mfu-reassembler.js +34 -0
  102. package/dist/wasm-mfu-reassembler.js.map +3 -3
  103. package/dist/wasm-mmtp-container-parser.js +260 -18
  104. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  105. package/package.json +5 -5
  106. package/schemas/catalog.schema.json +2 -2
  107. package/src/block-policy.ts +324 -83
  108. package/src/carp-catalog.ts +165 -5
  109. package/src/catalog-fec-params.ts +1 -0
  110. package/src/codec-utils.ts +121 -1
  111. package/src/fec-manager.ts +835 -66
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +25 -0
  114. package/src/iso-block-locator.ts +148 -31
  115. package/src/mmtp-container-parser.ts +259 -24
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +774 -86
  118. package/src/multicast-manager.ts +262 -16
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +389 -50
  122. package/src/track-session.ts +3 -0
  123. package/test-vectors/catalog/README.md +36 -2
  124. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  127. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  128. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  130. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  131. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  134. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  135. package/test-vectors/catalog/section-codes.json +3 -3
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -8,7 +8,7 @@
8
8
  * - MulticastTransport — SSM join/socket/watchdog
9
9
  */
10
10
 
11
- import { canonicalIpAddress, parseFecBlockProfile, resolveFecBindings, sameIpAddress, type FecBlockProfile, type FecSourceBinding } from "@blockcast/mmt-base";
11
+ import { canonicalIpAddress, parseFecBlockProfile, resolveFecBindings, sameIpAddress, type FecBlockProfile, type FecInstanceGeometry, type FecSourceBinding } from "@blockcast/mmt-base";
12
12
  import {
13
13
  FECManager,
14
14
  MIN_INTERLEAVE_DEPTH_MS,
@@ -18,8 +18,10 @@ import {
18
18
  type FecFallbackDecoder,
19
19
  type MulticastSymbolDelivery,
20
20
  type RepairVia,
21
+ type ExpiredIsoHole,
21
22
  type UndelimitedIsoLoss,
22
23
  type FecFailClosedEvent,
24
+ type IsoSpanFailure,
23
25
  } from "./fec-manager.js";
24
26
  import {
25
27
  deriveBlockClassifierGeometry,
@@ -108,6 +110,13 @@ export interface MulticastRepairEndpoint {
108
110
  tracks: MmtpIngressContext["tracks"];
109
111
  /** The protected flow (`MmtpRouter.registerProvenanceFlow`) this group's datagrams belong to. */
110
112
  flow?: string;
113
+ /**
114
+ * The group's own protected flow, which joinRepairEndpoints registers and
115
+ * releases itself, as join() does for the media flow. Its (S, G, port) must
116
+ * be the endpoint's. Never beside `flow`, which names a flow the caller
117
+ * registered.
118
+ */
119
+ provenance?: MulticastProvenanceJoin;
111
120
  }
112
121
 
113
122
  /**
@@ -206,6 +215,13 @@ export interface MulticastEndpointConfig {
206
215
  keyframeIntervalTicks?: number;
207
216
  /** Raw catalog `keyframeIntervalMs` (never a resolved cadence). */
208
217
  keyframeIntervalMs?: number;
218
+ /**
219
+ * The track's catalog group duration in ms (`catalogGroupDurationMs`). An
220
+ * "mfu-datagram" leg's duplicate ledgers remember a packet for the block
221
+ * span, the reorder tolerance and one group; pass it for every leg track,
222
+ * audio included, which has no keyframe interval to stand in for it.
223
+ */
224
+ groupDurationMs?: number;
209
225
  /** Catalog-derived lower bound for packet-silence failback (for example, keyframe repair cadence). */
210
226
  minimumFailbackWindowMs?: number;
211
227
  }
@@ -407,6 +423,14 @@ export type RepairLifecycleEvent =
407
423
  readonly block: RepairBlockIdentity;
408
424
  readonly blockClass: BlockClass;
409
425
  readonly symbols: RepairSymbolCounts;
426
+ /**
427
+ * Set when what failed is an iso-ssbg1-v1 repair-less span starting at
428
+ * `block.sbn`: `length` SS_IDs between two stated blocks, `sources` of
429
+ * them received. No repair stated the blocks inside it, so the receiver
430
+ * cannot tell which of them lost a source; it is not the failure of the
431
+ * block at `block.sbn` alone.
432
+ */
433
+ readonly span?: IsoSpanFailure;
410
434
  }
411
435
  | {
412
436
  readonly version: 2;
@@ -563,6 +587,11 @@ export interface BlockPolicyStats {
563
587
  stalls: number;
564
588
  concealedBlocks: number;
565
589
  concealedGaps: number;
590
+ /**
591
+ * Gaps the FEC deadline of a run no repair delimited released (counted in
592
+ * `concealedGaps` or `stalls` too; their decisions name no block).
593
+ */
594
+ undelimitedRunGaps: number;
566
595
  concealedFrames: number;
567
596
  concealedAudioMs: number;
568
597
  vanishedBlocks: number;
@@ -609,6 +638,7 @@ function newBlockPolicyStats(
609
638
  stalls: 0,
610
639
  concealedBlocks: 0,
611
640
  concealedGaps: 0,
641
+ undelimitedRunGaps: 0,
612
642
  concealedFrames: 0,
613
643
  concealedAudioMs: 0,
614
644
  vanishedBlocks: 0,
@@ -791,6 +821,19 @@ function isSymbolCounts(value: unknown): boolean {
791
821
  );
792
822
  }
793
823
 
824
+ /** A failed repair-less span: `sources` of its `length` SS_IDs arrived, never all. */
825
+ function isSpanFailure(value: unknown): boolean {
826
+ if (!isRecord(value) || !hasExactKeys(value, ["length", "sources"])) return false;
827
+ const length = value["length"];
828
+ const sources = value["sources"];
829
+ return (
830
+ Number.isSafeInteger(length) &&
831
+ (length as number) > 0 &&
832
+ isNonNegativeSafeInteger(sources) &&
833
+ (sources as number) < (length as number)
834
+ );
835
+ }
836
+
794
837
  function isNullableNonNegative(value: unknown): boolean {
795
838
  return value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
796
839
  }
@@ -833,10 +876,16 @@ export function isRepairLifecycleEvent(
833
876
  );
834
877
  case "failed":
835
878
  return (
836
- hasExactKeys(value, ["version", "type", "block", "blockClass", "symbols"]) &&
879
+ hasExactKeys(
880
+ value,
881
+ "span" in value
882
+ ? ["version", "type", "block", "blockClass", "symbols", "span"]
883
+ : ["version", "type", "block", "blockClass", "symbols"],
884
+ ) &&
837
885
  isRepairBlockIdentity(block) &&
838
886
  BLOCK_CLASSES.has(value["blockClass"]) &&
839
- isSymbolCounts(value["symbols"])
887
+ isSymbolCounts(value["symbols"]) &&
888
+ (!("span" in value) || isSpanFailure(value["span"]))
840
889
  );
841
890
  case "repair-preempted":
842
891
  case "repair-deferred":
@@ -1088,6 +1137,35 @@ function fecReorderWindowFrames(
1088
1137
  }
1089
1138
 
1090
1139
  /** Catalog track descriptor for configureMultiTrack(). */
1140
+ /**
1141
+ * The counters of an "mfu-datagram" leg, under the names every player
1142
+ * publishes: both spread `MulticastManager.datagramLegDiagnostics(...)` into
1143
+ * the FEC stats object they expose (hang `getFecStats()`, moqtail
1144
+ * `__MOQTAIL_STATS__.fecStats`), so a lane reads one shape from either. A
1145
+ * player that started no leg publishes none of these keys: an absent counter
1146
+ * is not a zero.
1147
+ */
1148
+ export interface DatagramLegDiagnostics {
1149
+ /** SUBSCRIBE_OK received on the datagram track and not ended (`FecStateEvidence.datagramLegJoined`). */
1150
+ readonly datagramLegJoined: boolean
1151
+ /** Leg packets dropped because their packet id is not the leg's (`MmtpRouter.datagramLegIngressDropCount`). */
1152
+ readonly datagramLegIngressDrops: number
1153
+ /** Repair datagrams that overflowed the player's ring before the first source packet named the owner packet id. */
1154
+ readonly datagramLegRepairBeforePacketId: number
1155
+ /** Datagrams the MoQ session dropped after SUBSCRIBE_OK because their track alias was unknown. */
1156
+ readonly datagramUnknownAlias: number
1157
+ /** `WebTransport.datagrams.maxDatagramSize` of the session the leg rides; null when the browser states none. */
1158
+ readonly transport: { readonly maxDatagramSize: number | null }
1159
+ }
1160
+
1161
+ /** What only the player can count for `DatagramLegDiagnostics`; libmmt adds its own counter. */
1162
+ export interface DatagramLegPlayerCounters {
1163
+ readonly joined: boolean
1164
+ readonly repairBeforePacketId: number
1165
+ readonly unknownAlias: number
1166
+ readonly maxDatagramSize?: number | null
1167
+ }
1168
+
1091
1169
  export interface MultiTrackCatalogTrack {
1092
1170
  name: string;
1093
1171
  altGroup?: number;
@@ -1277,6 +1355,10 @@ interface OverlayBinding {
1277
1355
  k: number;
1278
1356
  symbolSize: number;
1279
1357
  blockProfile: FecBlockProfile;
1358
+ /** The overlay instance's catalog geometry, read for its span and
1359
+ * tolerance (FECManager.keyframeOverlayTiming). No part of its decoder: a
1360
+ * reconfigure that changes it keeps an install. */
1361
+ geometry: FecInstanceGeometry;
1280
1362
  }
1281
1363
 
1282
1364
  type RepairOwnerEntry = MulticastRepairEndpoint["repairOwners"][number] & {
@@ -1296,6 +1378,8 @@ export class MulticastManager {
1296
1378
  /** Live joinRepairEndpoints() releases → the repair owners they registered,
1297
1379
  * re-applied after configureMultiTrack() clears catalog-derived owners. */
1298
1380
  readonly #repairReleases = new Map<() => void, RepairOwnerEntry[]>();
1381
+ /** Protected repair flows owned by each live repair-endpoint release. */
1382
+ readonly #repairProvenanceFlows = new Map<() => void, string[]>();
1299
1383
  /** Each source's catalog keyframe overlay, from its `ok` binding. */
1300
1384
  readonly #overlayBindings = new Map<number, OverlayBinding>();
1301
1385
  /** Installed overlay decoders (`setKeyframeOverlayDecoder`), by source. */
@@ -1366,7 +1450,7 @@ export class MulticastManager {
1366
1450
  onPublisherRestart: (packetId, catalogTrackName) => {
1367
1451
  this.#resetStreamOutsideRouter(packetId, catalogTrackName);
1368
1452
  },
1369
- onBlockFailed: (sbn, packetId, catalogTrackName, blockClass) => {
1453
+ onBlockFailed: (sbn, packetId, catalogTrackName, blockClass, span) => {
1370
1454
  const pathCount = this.#fec.blockPathCount(
1371
1455
  sbn,
1372
1456
  packetId,
@@ -1385,6 +1469,7 @@ export class MulticastManager {
1385
1469
  multicast: pathCount?.multicastSymbols ?? 0,
1386
1470
  moq: pathCount?.moqSymbols ?? 0,
1387
1471
  },
1472
+ ...(span === undefined ? {} : { span }),
1388
1473
  });
1389
1474
  },
1390
1475
  onFrameGap: (decision) => {
@@ -1488,9 +1573,21 @@ export class MulticastManager {
1488
1573
  reason,
1489
1574
  });
1490
1575
  };
1576
+ this.#fec.onUndelimitedRunGap = (packetId, catalogTrackName) => {
1577
+ this.#statsFor(packetId, catalogTrackName).undelimitedRunGaps++;
1578
+ };
1491
1579
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
1492
1580
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
1493
1581
  };
1582
+ // An installed keyframe overlay may still rebuild a RAP packet a base
1583
+ // block lost; a block only a late source can complete waits for it.
1584
+ this.#fec.keyframeOverlayTiming = (packetId, catalogTrackName) => {
1585
+ const binding = this.#overlayInstalls.has(packetId) ? this.#overlayBindings.get(packetId) : undefined;
1586
+ if (binding === undefined) return undefined;
1587
+ return catalogTrackName === undefined || catalogTrackName === binding.sourceCatalogTrackName
1588
+ ? binding.geometry
1589
+ : undefined;
1590
+ };
1494
1591
  this.#fec.onDecoderUnavailable = (event) => {
1495
1592
  this.#emitRepairLifecycle({
1496
1593
  version: 2,
@@ -1828,6 +1925,7 @@ export class MulticastManager {
1828
1925
  | "timescale"
1829
1926
  | "keyframeIntervalTicks"
1830
1927
  | "keyframeIntervalMs"
1928
+ | "groupDurationMs"
1831
1929
  >,
1832
1930
  catalogTrackName?: string,
1833
1931
  ): void {
@@ -1862,6 +1960,7 @@ export class MulticastManager {
1862
1960
  assertPositiveGeometry("timescale", config.timescale);
1863
1961
  assertPositiveGeometry("keyframeIntervalTicks", config.keyframeIntervalTicks);
1864
1962
  assertPositiveGeometry("keyframeIntervalMs", config.keyframeIntervalMs);
1963
+ assertPositiveGeometry("groupDurationMs", config.groupDurationMs);
1865
1964
  assertNonNegativeGeometry("fecRepairSymbols", config.fecRepairSymbols);
1866
1965
  // A tolerance is the network path's allowance, added to the encoder's
1867
1966
  // span. These are public entry points: the catalog parser validates what it
@@ -1917,6 +2016,7 @@ export class MulticastManager {
1917
2016
  ...(trackKind === undefined ? {} : { trackKind }),
1918
2017
  ...(config.codec === undefined ? {} : { codec: config.codec }),
1919
2018
  ...(geometry === undefined ? {} : { geometry }),
2019
+ ...(config.groupDurationMs === undefined ? {} : { groupDurationMs: config.groupDurationMs }),
1920
2020
  };
1921
2021
  this.#fec.configureTrack(packetId, fecConfig, catalogTrackName);
1922
2022
  this.#configureTrackMapper(packetId, fecConfig);
@@ -2179,6 +2279,9 @@ export class MulticastManager {
2179
2279
  this.#transport.onFailback((reason) => {
2180
2280
  const joined = this.#provenanceJoin;
2181
2281
  if (joined !== null) this.#router.unprotectProvenanceFlow(joined.flow);
2282
+ for (const flows of this.#repairProvenanceFlows.values()) {
2283
+ for (const flow of flows) this.#router.unprotectProvenanceFlow(flow);
2284
+ }
2182
2285
  this.#onFailback?.(reason);
2183
2286
  });
2184
2287
  }
@@ -2221,6 +2324,12 @@ export class MulticastManager {
2221
2324
  "[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port",
2222
2325
  );
2223
2326
  }
2327
+ if (provenanceFlow !== undefined) {
2328
+ const flow = multicastProvenanceFlowKey(provenanceFlow);
2329
+ if ([...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
2330
+ throw new TypeError(`[MulticastManager] join: provenance flow already registered by a repair endpoint: ${flow}`);
2331
+ }
2332
+ }
2224
2333
  // A join replaces the admission a staged switch was built on. The new
2225
2334
  // join's config decides what is admitted, so nothing is restored or
2226
2335
  // retired here: the switch just ends.
@@ -2245,8 +2354,8 @@ export class MulticastManager {
2245
2354
  : selectedPacketIds === null
2246
2355
  ? undefined
2247
2356
  : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
2248
- this.#releaseProvenanceJoin();
2249
2357
  const provenance = config.provenance;
2358
+ this.#releaseProvenanceJoin();
2250
2359
  const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
2251
2360
  const ingress: MmtpIngressContext | undefined = protectedTracks === undefined
2252
2361
  ? undefined
@@ -2315,8 +2424,14 @@ export class MulticastManager {
2315
2424
  provenance: MulticastProvenanceJoin,
2316
2425
  ingress: MmtpIngressContext & { flow: string },
2317
2426
  ): void {
2427
+ this.#router.registerProvenanceFlow(ingress, this.#provenanceReceiver(provenance));
2428
+ this.#hookFailback();
2429
+ this.#provenanceJoin = { flow: ingress.flow };
2430
+ }
2431
+
2432
+ #provenanceReceiver(provenance: MulticastProvenanceJoin): BcProvenanceV2Receiver {
2318
2433
  const { flow, auth } = provenance;
2319
- const receiver = new BcProvenanceV2Receiver({
2434
+ return new BcProvenanceV2Receiver({
2320
2435
  ...provenance.receiver,
2321
2436
  // The caller's ctx when it passes one, else the catalog's: an explicit
2322
2437
  // `catalogCtx: undefined` must not switch off the 7.2.4 ctx check.
@@ -2333,9 +2448,6 @@ export class MulticastManager {
2333
2448
  maxAuthDelayMs: flow.maxAuthDelayMs,
2334
2449
  manifestTimerMs: flow.manifestTimerMs,
2335
2450
  });
2336
- this.#router.registerProvenanceFlow(ingress, receiver);
2337
- this.#hookFailback();
2338
- this.#provenanceJoin = { flow: ingress.flow };
2339
2451
  }
2340
2452
 
2341
2453
  /** Un-protect: drop the flow's hold queues (no expiry counted). */
@@ -2368,12 +2480,33 @@ export class MulticastManager {
2368
2480
  * callback delivers must come from a subscription opened on
2369
2481
  * `options.gateway`. A callback that also merges another source (a MoQ or
2370
2482
  * WebSocket repair feed) must not name a native provider here.
2483
+ *
2484
+ * An endpoint's `provenance` makes its group a protected flow of its own
2485
+ * (multicast-02 7.2.7), registered here and released with the group; its
2486
+ * records ride in band on the group's port. On the user-agent path a
2487
+ * flow-less repair group of a protected track is set aside, never read, so
2488
+ * a player joining a protected catalog's repair groups passes it.
2371
2489
  */
2372
2490
  joinRepairEndpoints(
2373
2491
  endpoints: readonly MulticastRepairEndpoint[],
2374
2492
  provider?: WindowMulticastGateway | MulticastRepairSubscribe,
2375
2493
  options?: { gateway?: WindowMulticastGateway },
2376
2494
  ): () => void {
2495
+ for (const { provenance, flow, source, group, port } of endpoints) {
2496
+ if (provenance === undefined) continue;
2497
+ if (flow !== undefined) {
2498
+ throw new TypeError("[MulticastManager] joinRepairEndpoints: an endpoint names provenance or flow, never both");
2499
+ }
2500
+ if (
2501
+ !sameIpAddress(source, provenance.flow.source) ||
2502
+ !sameIpAddress(group, provenance.flow.groupAddress) ||
2503
+ port !== provenance.flow.port
2504
+ ) {
2505
+ throw new RangeError(
2506
+ "[MulticastManager] joinRepairEndpoints: provenance flow (S, G, port) must match the endpoint's source, group and port",
2507
+ );
2508
+ }
2509
+ }
2377
2510
  const releases: Array<() => void> = [];
2378
2511
  let released = false;
2379
2512
  const safely = (each: () => void) => {
@@ -2383,6 +2516,21 @@ export class MulticastManager {
2383
2516
  console.warn("[MulticastManager] repair group release failed", error);
2384
2517
  }
2385
2518
  };
2519
+ // Caller-owned flows reserve their keys even though this method does not
2520
+ // own their release; a protected endpoint must not replace one silently.
2521
+ const usedFlows = new Set(endpoints.flatMap(({ flow }) => flow === undefined ? [] : [flow]));
2522
+ const preparedProvenance = endpoints.map((endpoint) => {
2523
+ if (endpoint.provenance === undefined) return undefined;
2524
+ const flow = multicastProvenanceFlowKey(endpoint.provenance.flow);
2525
+ if (usedFlows.has(flow) || this.#provenanceJoin?.flow === flow ||
2526
+ [...this.#repairProvenanceFlows.values()].some((flows) => flows.includes(flow))) {
2527
+ throw new TypeError(`[MulticastManager] joinRepairEndpoints: provenance flow already registered: ${flow}`);
2528
+ }
2529
+ usedFlows.add(flow);
2530
+ // Construct every receiver before registering or joining any endpoint.
2531
+ return { flow, receiver: this.#provenanceReceiver(endpoint.provenance) };
2532
+ });
2533
+ const provenanceFlows: string[] = [];
2386
2534
  // An overlay leg's source and repair track names come from the
2387
2535
  // endpoint's ingress tracks.
2388
2536
  const repairOwners: RepairOwnerEntry[] = endpoints.flatMap((endpoint) =>
@@ -2392,11 +2540,19 @@ export class MulticastManager {
2392
2540
  repairTrackName: endpoint.tracks.find((t) => t.packetId === owner.packetId)?.name,
2393
2541
  }));
2394
2542
  this.#applyRepairOwners(repairOwners);
2395
- for (const endpoint of endpoints) {
2543
+ for (const [index, endpoint] of endpoints.entries()) {
2544
+ const flow = endpoint.provenance === undefined ? endpoint.flow : multicastProvenanceFlowKey(endpoint.provenance.flow);
2396
2545
  const ingress: MmtpIngressContext = {
2397
2546
  tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
2398
- ...(endpoint.flow === undefined ? {} : { flow: endpoint.flow }),
2547
+ ...(flow === undefined ? {} : { flow }),
2399
2548
  };
2549
+ if (endpoint.provenance !== undefined) {
2550
+ const prepared = preparedProvenance[index];
2551
+ if (prepared === undefined) throw new Error("[MulticastManager] repair provenance preparation missing");
2552
+ this.#router.registerProvenanceFlow(ingress as MmtpIngressContext & { flow: string }, prepared.receiver);
2553
+ provenanceFlows.push(prepared.flow);
2554
+ releases.push(() => this.#router.releaseProvenanceFlow(flow!));
2555
+ }
2400
2556
  let sender: string | undefined;
2401
2557
  const feed = (packet: Uint8Array, sourceAddress: string | undefined, ingressToFeed: MmtpIngressContext) => {
2402
2558
  if (released) return;
@@ -2433,7 +2589,7 @@ export class MulticastManager {
2433
2589
  packetIds: endpoint.packetIds,
2434
2590
  tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
2435
2591
  // A protected repair group's records ride in band on its port (7.2.3).
2436
- ...(endpoint.flow === undefined ? {} : { protected: true }),
2592
+ ...(flow === undefined ? {} : { protected: true }),
2437
2593
  }, ingress).then((joined) => {
2438
2594
  if (!joined && !released) fail(transport.lastJoinOutcome);
2439
2595
  });
@@ -2442,9 +2598,12 @@ export class MulticastManager {
2442
2598
  if (released) return;
2443
2599
  released = true;
2444
2600
  this.#repairReleases.delete(release);
2601
+ this.#repairProvenanceFlows.delete(release);
2445
2602
  for (const each of releases.splice(0)) safely(each);
2446
2603
  };
2447
2604
  this.#repairReleases.set(release, repairOwners);
2605
+ this.#repairProvenanceFlows.set(release, provenanceFlows);
2606
+ if (provenanceFlows.length) this.#hookFailback();
2448
2607
  return release;
2449
2608
  }
2450
2609
 
@@ -2766,6 +2925,84 @@ export class MulticastManager {
2766
2925
  this.#transport.feedPacket(data, ingress, sourceAddress);
2767
2926
  }
2768
2927
 
2928
+ /**
2929
+ * Start an "mfu-datagram" leg (draft-ramadan-moq-mmt-02 4.3.1): a
2930
+ * subscription whose objects arrive as datagrams, a lossy unicast path.
2931
+ * Arms the join-boundary rules exactly as a multicast join does (the leg
2932
+ * starts at an arbitrary datagram), keeping configured tracks, decoders
2933
+ * and diagnostics. No MulticastTransport is involved: no takeover, no
2934
+ * failback watchdog, no bridge. While the leg is up the player publishes
2935
+ * `datagramLegDiagnostics(...)` in its FEC stats (`DatagramLegDiagnostics`:
2936
+ * `datagramLegJoined`, `datagramLegIngressDrops`,
2937
+ * `datagramLegRepairBeforePacketId`, `datagramUnknownAlias`,
2938
+ * `transport.maxDatagramSize`), the same keys in every player.
2939
+ */
2940
+ startDatagramLeg(options: {
2941
+ /**
2942
+ * How long after a frame arrives it must leave the release gate when the
2943
+ * gap before it holds delta data alone (the presentation delay less the
2944
+ * decode lead; mmt-02 6.1 step 6): the gap is decided at the earlier of
2945
+ * this and the FEC block deadline. Absent: the block deadline alone.
2946
+ */
2947
+ presentationBudgetMs?: (packetId: number, catalogTrackName?: string) => number;
2948
+ } = {}): void {
2949
+ this.#router.setDatagramLegPresentationBudget(options.presentationBudgetMs ?? null);
2950
+ this.#fec.beginLegJoin();
2951
+ }
2952
+
2953
+ /**
2954
+ * Feed one object of an "mfu-datagram" subscription (one MMTP packet) in
2955
+ * arrival order. `ingress.tracks` names the datagram catalog track for the
2956
+ * packet id; the router restores serial order, holds FEC sources until a
2957
+ * repair states their block, and declares loss at the block deadline
2958
+ * (mmt-02 5.3.3). Bypasses MulticastTransport, unlike `feedPacket`.
2959
+ */
2960
+ feedDatagramLegPacket(packet: Uint8Array, ingress?: MmtpIngressContext): void {
2961
+ this.#router.feedPacket(packet, "moq-datagram", ingress);
2962
+ }
2963
+
2964
+ /**
2965
+ * Feed one repair object of an "mfu-datagram" track's repair track (sent
2966
+ * as datagrams, mmt-02 4.3.1): the repair track's own packet id names no
2967
+ * owner, so the subscription supplies it, as `router.feedRepairPacket`
2968
+ * does for a MoQ repair; the symbol counts as in-band (`RepairVia`
2969
+ * `inband`), unlike a FETCHed repair.
2970
+ */
2971
+ feedDatagramLegRepair(packet: Uint8Array, ownerPacketId: number, catalogTrackName: string, repairTrackName?: string): void {
2972
+ this.#router.feedRepairPacket(packet, ownerPacketId, catalogTrackName, repairTrackName, "moq-datagram");
2973
+ }
2974
+
2975
+ /**
2976
+ * End the "mfu-datagram" leg: call it when the subscription is dropped and
2977
+ * before the first packet of the path that replaces it (the ordered switch
2978
+ * to multicast, a fallback to the "mfu" track). The leg's presentation
2979
+ * bound and ledger retention stop applying; tracks, decoders, FEC state
2980
+ * and diagnostics stay, so the next path continues without a new epoch.
2981
+ */
2982
+ stopDatagramLeg(): void {
2983
+ this.#router.endDatagramLeg();
2984
+ }
2985
+
2986
+ /** "mfu-datagram" leg packets dropped because their packet id is not the leg's (`MmtpRouter.datagramLegIngressDropCount`). */
2987
+ get datagramLegIngressDropCount(): number {
2988
+ return this.#router.datagramLegIngressDropCount;
2989
+ }
2990
+
2991
+ /**
2992
+ * The leg's diagnostics as one object with the shared names
2993
+ * (`DatagramLegDiagnostics`): the player supplies what it alone counts and
2994
+ * spreads the result into its published FEC stats while a leg is up.
2995
+ */
2996
+ datagramLegDiagnostics(player: DatagramLegPlayerCounters): DatagramLegDiagnostics {
2997
+ return {
2998
+ datagramLegJoined: player.joined,
2999
+ datagramLegIngressDrops: this.#router.datagramLegIngressDropCount,
3000
+ datagramLegRepairBeforePacketId: player.repairBeforePacketId,
3001
+ datagramUnknownAlias: player.unknownAlias,
3002
+ transport: { maxDatagramSize: player.maxDatagramSize ?? null },
3003
+ };
3004
+ }
3005
+
2769
3006
  /**
2770
3007
  * Declare how packets given to feedPacket() reach this manager. A consumer
2771
3008
  * that owns the multicast socket itself declares its own leg; join()
@@ -3084,6 +3321,7 @@ export class MulticastManager {
3084
3321
  geometry.blockProfile,
3085
3322
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`,
3086
3323
  ),
3324
+ geometry,
3087
3325
  });
3088
3326
  }
3089
3327
  }
@@ -3129,7 +3367,7 @@ export class MulticastManager {
3129
3367
  const before = this.#overlayBindings.get(sourcePacketId);
3130
3368
  const after = overlayBindings.get(sourcePacketId);
3131
3369
  const same = before !== undefined && after !== undefined &&
3132
- (Object.keys(after) as Array<keyof OverlayBinding>).every((key) => after[key] === before[key]);
3370
+ (Object.keys(after) as Array<keyof OverlayBinding>).every((key) => key === "geometry" || after[key] === before[key]);
3133
3371
  if (!same) install.dispose();
3134
3372
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
3135
3373
  // A retired packet ID took the router's instance with it.
@@ -3193,10 +3431,15 @@ export class MulticastManager {
3193
3431
  * Register the range repair scheduler (draft-ramadan-moq-fec §7.5): from now
3194
3432
  * on an iso-ssbg1-v1 gap missing a source and every repair is kept as a
3195
3433
  * pending hole and reported here, and `closeIsoHoles` must be called for it
3196
- * once its range FETCH ends (or none is sent).
3434
+ * once its range FETCH ends (or none is sent). `onExpired` is told of a
3435
+ * pending hole the stream runs past the locator's horizon: returning true,
3436
+ * the caller closes it (`closeIsoHoles`); otherwise it is discarded.
3197
3437
  */
3198
- onUndelimitedLoss(cb: (loss: UndelimitedIsoLoss) => void): void {
3199
- this.#fec.setUndelimitedLossHandler(cb);
3438
+ onUndelimitedLoss(
3439
+ cb: (loss: UndelimitedIsoLoss) => void,
3440
+ onExpired?: (hole: ExpiredIsoHole) => boolean,
3441
+ ): void {
3442
+ this.#fec.setUndelimitedLossHandler(cb, onExpired ?? null);
3200
3443
  }
3201
3444
 
3202
3445
  /**
@@ -3515,6 +3758,9 @@ export class MulticastManager {
3515
3758
  ...("symbols" in event
3516
3759
  ? { symbols: Object.freeze({ ...event.symbols }) }
3517
3760
  : {}),
3761
+ ...("span" in event && event.span !== undefined
3762
+ ? { span: Object.freeze({ ...event.span }) }
3763
+ : {}),
3518
3764
  },
3519
3765
  ) as RepairLifecycleEvent);
3520
3766
  // Serialize before invoking observers so a re-entrant observer cannot log
package/src/no-modules.ts CHANGED
@@ -12,6 +12,9 @@ export {
12
12
  } from './carp-catalog.js'
13
13
  export { catalogFecInterleaveMs, fecBlockBudgetMs, fecBlockDeadlineMs } from '@blockcast/mmt-fec'
14
14
  export { FEC_INACTIVE_REASONS, catalogDeclaresFec, resolveFecState } from './fec-state.js'
15
+ // The per-instance report a receiver acts on, for classic-script pages that
16
+ // must publish it (BLO-55242).
17
+ export { runtimeFecCatalogReport, validateFecCatalog } from './catalog-fec-params.js'
15
18
  export { MmtpFecSession } from './mmtp-fec-session.js'
16
19
  export { catalogAmtNetworkSource, catalogAtsc3NetworkSource } from './catalog-network-source.js'
17
20
  export { MmtpToCmaf } from './mmtp-to-cmaf.js'
@@ -34,6 +34,7 @@
34
34
  * runtime unless the test harness opts in.
35
35
  */
36
36
 
37
+ import { isMmtpMode, type MmtpMode } from "@blockcast/mmt-base";
37
38
  import type { FecCatalogConfig } from "./carp-catalog.js";
38
39
 
39
40
  // ---------------------------------------------------------------------------
@@ -57,7 +58,7 @@ export interface Phase14OverrideTrack {
57
58
  source?: string;
58
59
  instanceId?: number;
59
60
  /** Required when packaging is `mmtp`; the current publisher emits MFU mode. */
60
- mmtpMode?: "mfu";
61
+ mmtpMode?: MmtpMode;
61
62
  /** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */
62
63
  timescale?: number;
63
64
  /** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */
@@ -308,11 +309,17 @@ export function mergeOverrideIntoCmsfTracks(
308
309
  if (ot.role !== undefined && existing.role === undefined) existing.role = ot.role;
309
310
  if (existing.packaging === "mmtp") {
310
311
  const mode = existing.mmtpMode ?? ot.mmtpMode;
311
- if (mode !== "mfu") {
312
+ if (mode === undefined) {
312
313
  throw new Error(
313
314
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`,
314
315
  );
315
316
  }
317
+ // mmt-02 13.1: an unknown mode rejects the track, never the
318
+ // catalog (`mmtpTrackIssues`); the override leaves it alone.
319
+ if (!isMmtpMode(mode)) {
320
+ console.warn(`[phase14-catalog-override] track "${ot.name}" has unknown mmtpMode ${JSON.stringify(mode)}; skipping the override`);
321
+ continue;
322
+ }
316
323
  existing.mmtpMode = mode;
317
324
  if (existing.timescale === undefined && ot.timescale !== undefined) existing.timescale = ot.timescale;
318
325
  if (existing.groupDurationMs === undefined && ot.groupDurationMs !== undefined) {
@@ -353,11 +360,15 @@ export function mergeOverrideIntoCmsfTracks(
353
360
  );
354
361
  }
355
362
  const mmtpMode = ot.mmtpMode;
356
- if (packaging === "mmtp" && mmtpMode !== "mfu") {
363
+ if (packaging === "mmtp" && mmtpMode === undefined) {
357
364
  throw new Error(
358
365
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`,
359
366
  );
360
367
  }
368
+ if (packaging === "mmtp" && !isMmtpMode(mmtpMode)) {
369
+ console.warn(`[phase14-catalog-override] track "${ot.name}" has unknown mmtpMode ${JSON.stringify(mmtpMode)}; skipping the track`);
370
+ continue;
371
+ }
361
372
  if (packaging === "mmtp" && !isPositiveInteger(ot.timescale)) {
362
373
  throw new Error(
363
374
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid timescale`,