@blockcast/mmt-container 2.2.0-main.fb5c7dfbe2de → 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 (132) 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 +1284 -174
  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 +155 -10
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +596 -81
  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 +16 -0
  44. package/dist/iso-block-locator.d.ts.map +1 -1
  45. package/dist/iso-block-locator.js +62 -0
  46. package/dist/iso-block-locator.js.map +3 -3
  47. package/dist/mfu-reassembler.js +34 -0
  48. package/dist/mfu-reassembler.js.map +3 -3
  49. package/dist/mmtp-container-parser.d.ts +30 -2
  50. package/dist/mmtp-container-parser.d.ts.map +1 -1
  51. package/dist/mmtp-container-parser.js +140 -2
  52. package/dist/mmtp-container-parser.js.map +3 -3
  53. package/dist/mmtp-container-parser.no-modules.js +293 -18
  54. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  55. package/dist/mmtp-decode-pipeline.js +140 -2
  56. package/dist/mmtp-decode-pipeline.js.map +3 -3
  57. package/dist/mmtp-fec-session.js +34 -0
  58. package/dist/mmtp-fec-session.js.map +3 -3
  59. package/dist/mmtp-mode-selection.d.ts +48 -0
  60. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  61. package/dist/mmtp-mode-selection.js +79 -0
  62. package/dist/mmtp-mode-selection.js.map +7 -0
  63. package/dist/mmtp-router.d.ts +66 -8
  64. package/dist/mmtp-router.d.ts.map +1 -1
  65. package/dist/mmtp-router.js +348 -27
  66. package/dist/mmtp-router.js.map +4 -4
  67. package/dist/multicast-auth-catalog.js +42 -2
  68. package/dist/multicast-auth-catalog.js.map +3 -3
  69. package/dist/multicast-input.js +42 -2
  70. package/dist/multicast-input.js.map +3 -3
  71. package/dist/multicast-manager.d.ts +108 -1
  72. package/dist/multicast-manager.d.ts.map +1 -1
  73. package/dist/multicast-manager.js +1067 -138
  74. package/dist/multicast-manager.js.map +4 -4
  75. package/dist/multicast-transport.js +68 -0
  76. package/dist/multicast-transport.js.map +4 -4
  77. package/dist/multicast-unwrap.js +34 -0
  78. package/dist/multicast-unwrap.js.map +3 -3
  79. package/dist/no-modules.d.ts +1 -0
  80. package/dist/no-modules.d.ts.map +1 -1
  81. package/dist/no-modules.js +295 -19
  82. package/dist/no-modules.js.map +4 -4
  83. package/dist/phase14-catalog-override.d.ts +2 -1
  84. package/dist/phase14-catalog-override.d.ts.map +1 -1
  85. package/dist/phase14-catalog-override.js +69 -2
  86. package/dist/phase14-catalog-override.js.map +3 -3
  87. package/dist/repair-fetch.d.ts +2 -0
  88. package/dist/repair-fetch.d.ts.map +1 -1
  89. package/dist/repair-fetch.js +52 -2
  90. package/dist/repair-fetch.js.map +3 -3
  91. package/dist/repair-layer-subscriptions.js +34 -0
  92. package/dist/repair-layer-subscriptions.js.map +3 -3
  93. package/dist/signaling.js +34 -0
  94. package/dist/signaling.js.map +3 -3
  95. package/dist/timestamp-codec.js +34 -0
  96. package/dist/timestamp-codec.js.map +3 -3
  97. package/dist/wasm-mfu-reassembler.js +34 -0
  98. package/dist/wasm-mfu-reassembler.js.map +3 -3
  99. package/dist/wasm-mmtp-container-parser.js +140 -2
  100. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  101. package/package.json +5 -5
  102. package/schemas/catalog.schema.json +2 -2
  103. package/src/block-policy.ts +324 -83
  104. package/src/carp-catalog.ts +165 -5
  105. package/src/catalog-fec-params.ts +1 -0
  106. package/src/codec-utils.ts +121 -1
  107. package/src/fec-manager.ts +534 -41
  108. package/src/fec-state.ts +21 -5
  109. package/src/index.ts +23 -0
  110. package/src/iso-block-locator.ts +34 -0
  111. package/src/mmtp-container-parser.ts +57 -11
  112. package/src/mmtp-mode-selection.ts +80 -0
  113. package/src/mmtp-router.ts +287 -42
  114. package/src/multicast-manager.ts +218 -10
  115. package/src/no-modules.ts +3 -0
  116. package/src/phase14-catalog-override.ts +14 -3
  117. package/src/repair-fetch.ts +27 -2
  118. package/test-vectors/catalog/README.md +36 -2
  119. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  120. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  121. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  122. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  123. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  124. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  125. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  126. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  127. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  128. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  130. package/test-vectors/catalog/section-codes.json +3 -3
  131. package/test-vectors/catalog-validation.json +266 -7
  132. 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,
@@ -110,6 +110,13 @@ export interface MulticastRepairEndpoint {
110
110
  tracks: MmtpIngressContext["tracks"];
111
111
  /** The protected flow (`MmtpRouter.registerProvenanceFlow`) this group's datagrams belong to. */
112
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;
113
120
  }
114
121
 
115
122
  /**
@@ -208,6 +215,13 @@ export interface MulticastEndpointConfig {
208
215
  keyframeIntervalTicks?: number;
209
216
  /** Raw catalog `keyframeIntervalMs` (never a resolved cadence). */
210
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;
211
225
  /** Catalog-derived lower bound for packet-silence failback (for example, keyframe repair cadence). */
212
226
  minimumFailbackWindowMs?: number;
213
227
  }
@@ -573,6 +587,11 @@ export interface BlockPolicyStats {
573
587
  stalls: number;
574
588
  concealedBlocks: number;
575
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;
576
595
  concealedFrames: number;
577
596
  concealedAudioMs: number;
578
597
  vanishedBlocks: number;
@@ -619,6 +638,7 @@ function newBlockPolicyStats(
619
638
  stalls: 0,
620
639
  concealedBlocks: 0,
621
640
  concealedGaps: 0,
641
+ undelimitedRunGaps: 0,
622
642
  concealedFrames: 0,
623
643
  concealedAudioMs: 0,
624
644
  vanishedBlocks: 0,
@@ -1117,6 +1137,35 @@ function fecReorderWindowFrames(
1117
1137
  }
1118
1138
 
1119
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
+
1120
1169
  export interface MultiTrackCatalogTrack {
1121
1170
  name: string;
1122
1171
  altGroup?: number;
@@ -1306,6 +1355,10 @@ interface OverlayBinding {
1306
1355
  k: number;
1307
1356
  symbolSize: number;
1308
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;
1309
1362
  }
1310
1363
 
1311
1364
  type RepairOwnerEntry = MulticastRepairEndpoint["repairOwners"][number] & {
@@ -1325,6 +1378,8 @@ export class MulticastManager {
1325
1378
  /** Live joinRepairEndpoints() releases → the repair owners they registered,
1326
1379
  * re-applied after configureMultiTrack() clears catalog-derived owners. */
1327
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[]>();
1328
1383
  /** Each source's catalog keyframe overlay, from its `ok` binding. */
1329
1384
  readonly #overlayBindings = new Map<number, OverlayBinding>();
1330
1385
  /** Installed overlay decoders (`setKeyframeOverlayDecoder`), by source. */
@@ -1518,9 +1573,21 @@ export class MulticastManager {
1518
1573
  reason,
1519
1574
  });
1520
1575
  };
1576
+ this.#fec.onUndelimitedRunGap = (packetId, catalogTrackName) => {
1577
+ this.#statsFor(packetId, catalogTrackName).undelimitedRunGaps++;
1578
+ };
1521
1579
  this.#fec.onBlockVanished = (_sbn, packetId, catalogTrackName) => {
1522
1580
  this.#statsFor(packetId, catalogTrackName).vanishedBlocks++;
1523
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
+ };
1524
1591
  this.#fec.onDecoderUnavailable = (event) => {
1525
1592
  this.#emitRepairLifecycle({
1526
1593
  version: 2,
@@ -1858,6 +1925,7 @@ export class MulticastManager {
1858
1925
  | "timescale"
1859
1926
  | "keyframeIntervalTicks"
1860
1927
  | "keyframeIntervalMs"
1928
+ | "groupDurationMs"
1861
1929
  >,
1862
1930
  catalogTrackName?: string,
1863
1931
  ): void {
@@ -1892,6 +1960,7 @@ export class MulticastManager {
1892
1960
  assertPositiveGeometry("timescale", config.timescale);
1893
1961
  assertPositiveGeometry("keyframeIntervalTicks", config.keyframeIntervalTicks);
1894
1962
  assertPositiveGeometry("keyframeIntervalMs", config.keyframeIntervalMs);
1963
+ assertPositiveGeometry("groupDurationMs", config.groupDurationMs);
1895
1964
  assertNonNegativeGeometry("fecRepairSymbols", config.fecRepairSymbols);
1896
1965
  // A tolerance is the network path's allowance, added to the encoder's
1897
1966
  // span. These are public entry points: the catalog parser validates what it
@@ -1947,6 +2016,7 @@ export class MulticastManager {
1947
2016
  ...(trackKind === undefined ? {} : { trackKind }),
1948
2017
  ...(config.codec === undefined ? {} : { codec: config.codec }),
1949
2018
  ...(geometry === undefined ? {} : { geometry }),
2019
+ ...(config.groupDurationMs === undefined ? {} : { groupDurationMs: config.groupDurationMs }),
1950
2020
  };
1951
2021
  this.#fec.configureTrack(packetId, fecConfig, catalogTrackName);
1952
2022
  this.#configureTrackMapper(packetId, fecConfig);
@@ -2209,6 +2279,9 @@ export class MulticastManager {
2209
2279
  this.#transport.onFailback((reason) => {
2210
2280
  const joined = this.#provenanceJoin;
2211
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
+ }
2212
2285
  this.#onFailback?.(reason);
2213
2286
  });
2214
2287
  }
@@ -2251,6 +2324,12 @@ export class MulticastManager {
2251
2324
  "[MulticastManager] join: provenance flow (S, G, port) must match sourceAddress ?? senderAddress, groupAddress and port",
2252
2325
  );
2253
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
+ }
2254
2333
  // A join replaces the admission a staged switch was built on. The new
2255
2334
  // join's config decides what is admitted, so nothing is restored or
2256
2335
  // retired here: the switch just ends.
@@ -2275,8 +2354,8 @@ export class MulticastManager {
2275
2354
  : selectedPacketIds === null
2276
2355
  ? undefined
2277
2356
  : [...selectedPacketIds].map((packetId) => ({ name: "", packetId }));
2278
- this.#releaseProvenanceJoin();
2279
2357
  const provenance = config.provenance;
2358
+ this.#releaseProvenanceJoin();
2280
2359
  const protectedTracks = ingressTracks ?? provenance?.flow.tracks;
2281
2360
  const ingress: MmtpIngressContext | undefined = protectedTracks === undefined
2282
2361
  ? undefined
@@ -2345,8 +2424,14 @@ export class MulticastManager {
2345
2424
  provenance: MulticastProvenanceJoin,
2346
2425
  ingress: MmtpIngressContext & { flow: string },
2347
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 {
2348
2433
  const { flow, auth } = provenance;
2349
- const receiver = new BcProvenanceV2Receiver({
2434
+ return new BcProvenanceV2Receiver({
2350
2435
  ...provenance.receiver,
2351
2436
  // The caller's ctx when it passes one, else the catalog's: an explicit
2352
2437
  // `catalogCtx: undefined` must not switch off the 7.2.4 ctx check.
@@ -2363,9 +2448,6 @@ export class MulticastManager {
2363
2448
  maxAuthDelayMs: flow.maxAuthDelayMs,
2364
2449
  manifestTimerMs: flow.manifestTimerMs,
2365
2450
  });
2366
- this.#router.registerProvenanceFlow(ingress, receiver);
2367
- this.#hookFailback();
2368
- this.#provenanceJoin = { flow: ingress.flow };
2369
2451
  }
2370
2452
 
2371
2453
  /** Un-protect: drop the flow's hold queues (no expiry counted). */
@@ -2398,12 +2480,33 @@ export class MulticastManager {
2398
2480
  * callback delivers must come from a subscription opened on
2399
2481
  * `options.gateway`. A callback that also merges another source (a MoQ or
2400
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.
2401
2489
  */
2402
2490
  joinRepairEndpoints(
2403
2491
  endpoints: readonly MulticastRepairEndpoint[],
2404
2492
  provider?: WindowMulticastGateway | MulticastRepairSubscribe,
2405
2493
  options?: { gateway?: WindowMulticastGateway },
2406
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
+ }
2407
2510
  const releases: Array<() => void> = [];
2408
2511
  let released = false;
2409
2512
  const safely = (each: () => void) => {
@@ -2413,6 +2516,21 @@ export class MulticastManager {
2413
2516
  console.warn("[MulticastManager] repair group release failed", error);
2414
2517
  }
2415
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[] = [];
2416
2534
  // An overlay leg's source and repair track names come from the
2417
2535
  // endpoint's ingress tracks.
2418
2536
  const repairOwners: RepairOwnerEntry[] = endpoints.flatMap((endpoint) =>
@@ -2422,11 +2540,19 @@ export class MulticastManager {
2422
2540
  repairTrackName: endpoint.tracks.find((t) => t.packetId === owner.packetId)?.name,
2423
2541
  }));
2424
2542
  this.#applyRepairOwners(repairOwners);
2425
- 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);
2426
2545
  const ingress: MmtpIngressContext = {
2427
2546
  tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId }))),
2428
- ...(endpoint.flow === undefined ? {} : { flow: endpoint.flow }),
2547
+ ...(flow === undefined ? {} : { flow }),
2429
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
+ }
2430
2556
  let sender: string | undefined;
2431
2557
  const feed = (packet: Uint8Array, sourceAddress: string | undefined, ingressToFeed: MmtpIngressContext) => {
2432
2558
  if (released) return;
@@ -2463,7 +2589,7 @@ export class MulticastManager {
2463
2589
  packetIds: endpoint.packetIds,
2464
2590
  tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
2465
2591
  // A protected repair group's records ride in band on its port (7.2.3).
2466
- ...(endpoint.flow === undefined ? {} : { protected: true }),
2592
+ ...(flow === undefined ? {} : { protected: true }),
2467
2593
  }, ingress).then((joined) => {
2468
2594
  if (!joined && !released) fail(transport.lastJoinOutcome);
2469
2595
  });
@@ -2472,9 +2598,12 @@ export class MulticastManager {
2472
2598
  if (released) return;
2473
2599
  released = true;
2474
2600
  this.#repairReleases.delete(release);
2601
+ this.#repairProvenanceFlows.delete(release);
2475
2602
  for (const each of releases.splice(0)) safely(each);
2476
2603
  };
2477
2604
  this.#repairReleases.set(release, repairOwners);
2605
+ this.#repairProvenanceFlows.set(release, provenanceFlows);
2606
+ if (provenanceFlows.length) this.#hookFailback();
2478
2607
  return release;
2479
2608
  }
2480
2609
 
@@ -2796,6 +2925,84 @@ export class MulticastManager {
2796
2925
  this.#transport.feedPacket(data, ingress, sourceAddress);
2797
2926
  }
2798
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
+
2799
3006
  /**
2800
3007
  * Declare how packets given to feedPacket() reach this manager. A consumer
2801
3008
  * that owns the multicast socket itself declares its own leg; join()
@@ -3114,6 +3321,7 @@ export class MulticastManager {
3114
3321
  geometry.blockProfile,
3115
3322
  `tracks[${JSON.stringify(track.name)}].fec keyframe overlay blockProfile`,
3116
3323
  ),
3324
+ geometry,
3117
3325
  });
3118
3326
  }
3119
3327
  }
@@ -3159,7 +3367,7 @@ export class MulticastManager {
3159
3367
  const before = this.#overlayBindings.get(sourcePacketId);
3160
3368
  const after = overlayBindings.get(sourcePacketId);
3161
3369
  const same = before !== undefined && after !== undefined &&
3162
- (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]);
3163
3371
  if (!same) install.dispose();
3164
3372
  else if (this.#router.hasKeyframeOverlay(after.repairPacketId)) this.#router.resetKeyframeOverlays(sourcePacketId);
3165
3373
  // A retired packet ID took the router's instance with it.
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`,
@@ -211,6 +211,8 @@ export interface RepairFetchRequest {
211
211
  /**
212
212
  * Aborts when the scheduler no longer wants the group: preemption by
213
213
  * keyframe work, reprioritisation, block resolution, track reset, dispose.
214
+ * When the scheduler stops a running request, `signal.reason` is its
215
+ * `RepairStopReason`, the one `noteRepairStopped` reports.
214
216
  */
215
217
  readonly signal: AbortSignal
216
218
  /**
@@ -782,7 +784,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
782
784
  if (!run) return
783
785
  entry.running = null
784
786
  run.stopped = reason
785
- run.controller.abort()
787
+ run.controller.abort(reason)
786
788
  // A preempted request returns to the queue; until it runs again nothing is
787
789
  // in flight that could land, so the block goes back to its multicast wait.
788
790
  if (reason === 'preempted') releaseHold(entry)
@@ -1257,7 +1259,7 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1257
1259
  if (entries.get(requestKey(sbn, entry.packetId, entry.catalogTrackName))?.running == null) {
1258
1260
  const rsIds = new Set<number>()
1259
1261
  const group = new AbortController()
1260
- const cancel = (): void => group.abort()
1262
+ const cancel = (): void => group.abort(common.signal.reason)
1261
1263
  common.signal.addEventListener('abort', cancel, { once: true })
1262
1264
  walk.group = { sbn, controller: group }
1263
1265
  try {
@@ -1351,6 +1353,29 @@ export function wireRepairFetch(mc: RepairFetchHost, opts: WireRepairFetchOption
1351
1353
  dispatch()
1352
1354
  return
1353
1355
  }
1356
+ if (event.type === 'gap') {
1357
+ // mmt-02 5.3.3: a receiver cancels a repair it stops waiting for. A
1358
+ // frame the release gate forces out at its hold ceiling (a
1359
+ // discontinuity stall over blocks that never resolved) declares the
1360
+ // loss behind it, so every FETCH of that stream past its deadline is
1361
+ // cancelled here, inside the decision, before the frame leaves the
1362
+ // gate (MulticastManager emits the decision as a lifecycle event
1363
+ // synchronously from the gate's `decide`).
1364
+ if (event.action !== 'stall' || event.reason !== 'discontinuity') return
1365
+ const now = performance.now()
1366
+ let expired = false
1367
+ for (const entry of [...entries.values()]) {
1368
+ if (entry.packetId !== event.stream.packetId) continue
1369
+ if (entry.catalogTrackName !== (event.stream.catalogTrackName ?? undefined)) continue
1370
+ if (!entry.running || entry.deadlineAt > now) continue
1371
+ stop(entry, 'expired')
1372
+ retire(entry)
1373
+ clearEntry(entry)
1374
+ expired = true
1375
+ }
1376
+ if (expired) dispatch()
1377
+ return
1378
+ }
1354
1379
  if (event.type !== 'recovered' && event.type !== 'failed') return
1355
1380
  const entry = entries.get(
1356
1381
  requestKey(event.block.sbn, event.block.packetId, event.block.catalogTrackName ?? undefined),
@@ -26,7 +26,9 @@ runtime resolver still reads live in `fec-01-runtime/`.
26
26
  The negatives:
27
27
 
28
28
  - `legacy-selection-params.json`: rendition fields must be flat.
29
- - `missing-mmtp-fields.json`: MMTP tracks require mode, timescale, and duration.
29
+ - `missing-mmtp-fields.json`: MMTP tracks require a timescale and a duration
30
+ (the section's `track_timescale`); the missing `mmtpMode` is the track
31
+ admission rule below, which rejects the track, not the catalog.
30
32
  - `multicast-packet-id-signaling.json`: an endpoint track's `packetId` is
31
33
  1..65535; `packetId` 0 is the MMTP signaling flow and is never a track's.
32
34
  - `network-source-object.json`: `networkSource` is always an array.
@@ -176,7 +178,39 @@ Draft -01 track and root fields (BLO-15076, Blockcast/moqcast-draft@fd962fd):
176
178
  - `multicast-amt-dns-relay.json`, `multicast-amt-discovery-omitted.json`:
177
179
  multicast-01 4.2.1 `discovery: "dns"`, and an omitted `discovery` with a
178
180
  hostname relay (read as `"dns"`).
179
- - `mmtp-mode-mpu.json`: mmt-01 12.1, `mmtpMode` MUST be `"mfu"`.
181
+ - `mmtp-mode-mpu.json`: mmt-02 13.1, `mmtpMode` is `"mfu"` or `"mfu-datagram"`.
182
+ The schema accepts any non-empty string (a value set there would reject the
183
+ whole catalog); a subscriber rejects the track, never the catalog:
184
+ `validateCmsfMmtpCatalog` removes it from the catalog it returns
185
+ (`rejectedTracks`, `track_mmtp_mode`), and the Rust section names it with
186
+ `rejected_tracks` (`trackRejected` in `section-codes.json`).
187
+ - `mmtp-siblings/`: the shared vector set of the mmt-02 4.3.1 `"mfu-datagram"`
188
+ track, asserted by every implementation of the rules (this validator,
189
+ `mmt_fec::catalog::rejected_tracks` for the mode rule, and the vendored
190
+ copies in hang-mmt-fec, moqtail-ts and pim). Each file is
191
+ `{ generator, sha256, description, catalog, expected }`, with `sha256` that of
192
+ `JSON.stringify({ catalog, expected })` so a vendored copy is checked by
193
+ hash. `expected.tracks` gives every track a verdict: `accepted`, `rejected`
194
+ (with the `code` and JSON `path`), or `dropped` (a `fec-repair` track whose
195
+ `source` was rejected). `expected.pairs` maps each `"mfu"` track to its
196
+ datagram sibling over the accepted tracks; `expected.endpointIssues` is what
197
+ `multicastCatalogIssues` names. Every catalog of the set is valid and passes
198
+ the schema. Two entries are siblings when their whole identity set is equal,
199
+ field by field or absent on both: namespace, `timescale`,
200
+ `presentationAnchorTicks`, group duration (as ticks) and the mmt-02 13.1
201
+ rendition fields `codec`, `width`, `height`, `framerate`, `bitrate`,
202
+ `samplerate`, `channelConfig`, `lang`. A datagram track with exactly one
203
+ sibling pairs; zero or more than one rejects it. Never by name.
204
+ `valid-pair.json`; `ladder-four-rungs.json` and `ladder-bitrate-only.json`
205
+ (rungs share everything but the rendition fields, every rung pairs);
206
+ `ladder-other-names.json` (names unrelated to the rung: a name-based
207
+ implementation fails it); `no-sibling.json`, `timescale-mismatch.json`,
208
+ `rendition-mismatch.json` (another codec on the only candidate: a tie-break
209
+ implementation fails it) and `ambiguous-sibling.json` (two `"mfu"` tracks
210
+ with one description) are `track_mmtp_sibling`; `stream-delivery-mode.json`
211
+ (`track_delivery_mode_conflict`), `mmtp-mode-unknown.json`
212
+ (`track_mmtp_mode`), `multicast-endpoint-lists-datagram-track.json`
213
+ (`multicast_track`: the receiver ignores that endpoint).
180
214
  - `presentation-anchor-unsafe.json`: the anchor is a safe (signed) integer.
181
215
  - `init-data-inline-without-data.json`: an `"inline"` `initDataList` entry
182
216
  carries `data`.