@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.d5ca55d82e33

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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/browser-runtime.js +224 -55
  3. package/dist/browser-runtime.js.map +4 -4
  4. package/dist/carp-catalog.js +3 -0
  5. package/dist/carp-catalog.js.map +3 -3
  6. package/dist/catalog-fec-params.d.ts +5 -2
  7. package/dist/catalog-fec-params.d.ts.map +1 -1
  8. package/dist/catalog-fec-params.js +100 -36
  9. package/dist/catalog-fec-params.js.map +4 -4
  10. package/dist/catalog-network-source.js +3 -0
  11. package/dist/catalog-network-source.js.map +3 -3
  12. package/dist/delivery-catalog.js +22 -1
  13. package/dist/delivery-catalog.js.map +4 -4
  14. package/dist/fec-manager.js +3 -0
  15. package/dist/fec-manager.js.map +3 -3
  16. package/dist/fec-state.d.ts +3 -2
  17. package/dist/fec-state.d.ts.map +1 -1
  18. package/dist/fec-state.js +16 -9
  19. package/dist/fec-state.js.map +4 -4
  20. package/dist/fec-worker-setup.js +3 -0
  21. package/dist/fec-worker-setup.js.map +3 -3
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -0
  25. package/dist/index.js.map +2 -2
  26. package/dist/iso-block-locator.js +3 -0
  27. package/dist/iso-block-locator.js.map +3 -3
  28. package/dist/mfu-reassembler.js +24 -13
  29. package/dist/mfu-reassembler.js.map +3 -3
  30. package/dist/mmtp-container-parser.js +24 -13
  31. package/dist/mmtp-container-parser.js.map +3 -3
  32. package/dist/mmtp-container-parser.no-modules.js +37 -22
  33. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  34. package/dist/mmtp-decode-pipeline.js +24 -13
  35. package/dist/mmtp-decode-pipeline.js.map +3 -3
  36. package/dist/mmtp-router.js +24 -13
  37. package/dist/mmtp-router.js.map +3 -3
  38. package/dist/multicast-input.js +3 -0
  39. package/dist/multicast-input.js.map +3 -3
  40. package/dist/multicast-manager.d.ts +49 -0
  41. package/dist/multicast-manager.d.ts.map +1 -1
  42. package/dist/multicast-manager.js +151 -29
  43. package/dist/multicast-manager.js.map +4 -4
  44. package/dist/multicast-transport.d.ts +6 -2
  45. package/dist/multicast-transport.d.ts.map +1 -1
  46. package/dist/multicast-transport.js +31 -5
  47. package/dist/multicast-transport.js.map +4 -4
  48. package/dist/multicast-unwrap.js +24 -13
  49. package/dist/multicast-unwrap.js.map +3 -3
  50. package/dist/no-modules.js +37 -22
  51. package/dist/no-modules.js.map +4 -4
  52. package/dist/repair-fetch.js +3 -0
  53. package/dist/repair-fetch.js.map +3 -3
  54. package/dist/repair-layers.js +3 -0
  55. package/dist/repair-layers.js.map +3 -3
  56. package/dist/signaling.js +3 -0
  57. package/dist/signaling.js.map +3 -3
  58. package/dist/timestamp-codec.js +24 -13
  59. package/dist/timestamp-codec.js.map +3 -3
  60. package/dist/wasm-mfu-reassembler.js +3 -0
  61. package/dist/wasm-mfu-reassembler.js.map +3 -3
  62. package/dist/wasm-mmtp-container-parser.js +24 -13
  63. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  64. package/package.json +5 -5
  65. package/src/catalog-fec-params.ts +38 -17
  66. package/src/fec-state.ts +4 -9
  67. package/src/index.ts +5 -0
  68. package/src/multicast-manager.ts +120 -1
  69. package/src/multicast-transport.ts +14 -3
package/README.md CHANGED
@@ -265,7 +265,7 @@ per-commit `0.1.0-main.<sha>` prerelease from `stamp-prerelease.mjs`), and a
265
265
  > Superseded by BLO-40665. Every package is now bumped in lockstep by a `v*`
266
266
  > tag and the sibling ranges move with it, so the objection above no longer
267
267
  > applies -- it was an argument against bumping *one* package. The set is at
268
- > `0.3.0`; see `RELEASES.md`.
268
+ > `0.4.0`; see `RELEASES.md`.
269
269
 
270
270
  #### Track-role convention (Phase 14)
271
271
 
@@ -655,26 +655,30 @@ function isEmptyOrExactLegacyTrailer(payload, start, end) {
655
655
  const authLength = view2.getUint16(2, false);
656
656
  return start + LEGACY_TRAILER_HEADER_SIZE + authLength === end;
657
657
  }
658
- function resolveDeclaredTrailers(payload, declaredEnd, fecType, options) {
658
+ function resolveDeclaredTrailers(payload, declaredEnd, fecType, options, rapFlag = false) {
659
659
  if (declaredEnd > payload.length)
660
660
  return null;
661
661
  if (options?.skipFecId) {
662
- return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false } : null;
662
+ return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false, hasOverlayFecId: false } : null;
663
663
  }
664
+ const overlay = options?.overlayDeclared === true && rapFlag;
664
665
  if (fecType === 1) {
665
- const fecStart = payload.length - SOURCE_FEC_PAYLOAD_ID_SIZE;
666
+ const fecStart = payload.length - sourceFecTrailerSize(overlay);
666
667
  if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
667
668
  return null;
668
669
  }
669
- return { hasFecId: true };
670
+ return { hasFecId: true, hasOverlayFecId: overlay };
670
671
  }
671
- if (fecType !== 0)
672
+ if (fecType !== 0 || overlay)
672
673
  return null;
673
674
  if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
674
- return { hasFecId: false };
675
+ return { hasFecId: false, hasOverlayFecId: false };
675
676
  }
676
677
  return null;
677
678
  }
679
+ function sourceFecTrailerSize(overlay) {
680
+ return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE;
681
+ }
678
682
  function extractNALUnit(mmtpPacket) {
679
683
  const extraction = extractMFUPayload(mmtpPacket);
680
684
  if (!extraction)
@@ -733,15 +737,16 @@ function planMfuExtraction(mmtpPacket, options, parsedHeader) {
733
737
  if ("rejection" in layoutResult)
734
738
  return layoutResult;
735
739
  const { layout } = layoutResult;
736
- const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options);
740
+ const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options, header.rapFlag);
737
741
  if (!trailerLayout) {
738
742
  if (!options?.skipFecId && header.fecType === 1) {
739
743
  const observed = payload.length - layout.dataEnd;
740
- if (observed !== SOURCE_FEC_PAYLOAD_ID_SIZE) {
744
+ const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag);
745
+ if (observed !== expected) {
741
746
  return {
742
747
  rejection: {
743
748
  gate: "source-fec-payload-id-width-mismatch",
744
- detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${SOURCE_FEC_PAYLOAD_ID_SIZE} (payload=${payload.length}, declaredEnd=${layout.dataEnd})`
749
+ detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${expected} (payload=${payload.length}, declaredEnd=${layout.dataEnd})`
745
750
  }
746
751
  };
747
752
  }
@@ -771,10 +776,13 @@ function extractPlannedMfu(mmtpPacket, result) {
771
776
  const mfuDuHeader = mfuDuHeaderPresent && mpu.timedFlag === 1 ? parseTimedMfuDuHeader(payload, MPU_HEADER_SIZE) : null;
772
777
  const itemId = mfuDuHeaderPresent && mpu.timedFlag === 0 ? new DataView(payload.buffer, payload.byteOffset + MPU_HEADER_SIZE, 4).getUint32(0, false) : null;
773
778
  const data = payload.subarray(mfuOffset, dataEnd);
774
- const fecPayloadId = trailerLayout.hasFecId ? {
775
- ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + mmtpPacket.length - SOURCE_FEC_PAYLOAD_ID_SIZE, SOURCE_FEC_PAYLOAD_ID_SIZE).getUint32(0, false)
776
- } : null;
777
- return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId };
779
+ const trailerStart = mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId);
780
+ const ssIdAt = (offset) => ({
781
+ ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false)
782
+ });
783
+ const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null;
784
+ const overlayFecPayloadId = trailerLayout.hasOverlayFecId ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE) : null;
785
+ return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId };
778
786
  }
779
787
  function extractTimestamp(mmtpPacket) {
780
788
  const { header } = unwrapMMTP(mmtpPacket);
@@ -949,6 +957,71 @@ function isoBlocksBehindLowerBound(a, b, kMax) {
949
957
  return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
950
958
  }
951
959
 
960
+ // ../mmt-base/dist/catalog-fec-source.js
961
+ var ALL_ROLES = Object.freeze(["video", "audio"]);
962
+ function recordOf(value) {
963
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
964
+ }
965
+ function locateCatalogFecSource(catalog, source, roles = ALL_ROLES) {
966
+ const root = recordOf(catalog);
967
+ if (root === void 0)
968
+ return void 0;
969
+ for (const role of roles) {
970
+ const renditions = recordOf(recordOf(root[role])?.["renditions"]);
971
+ if (renditions === void 0 || !Object.hasOwn(renditions, source))
972
+ continue;
973
+ const entry2 = recordOf(renditions[source]);
974
+ if (entry2 === void 0)
975
+ continue;
976
+ return Object.freeze({
977
+ dialect: "hang",
978
+ role,
979
+ entry: entry2,
980
+ fec: entry2["fec"],
981
+ fecPath: `$.${role}.renditions[${JSON.stringify(source)}].fec`
982
+ });
983
+ }
984
+ const tracks = root["tracks"];
985
+ if (!Array.isArray(tracks))
986
+ return void 0;
987
+ const index = tracks.findIndex((track) => recordOf(track)?.["name"] === source);
988
+ if (index < 0)
989
+ return void 0;
990
+ const entry = recordOf(tracks[index]) ?? {};
991
+ return Object.freeze({
992
+ dialect: "msf",
993
+ index,
994
+ entry,
995
+ fec: entry["fec"],
996
+ fecPath: `$.tracks[${index}].fec`
997
+ });
998
+ }
999
+ function isoBlockSpanUsable(fec) {
1000
+ const block = recordOf(fec);
1001
+ if (block === void 0 || block["blockProfile"] !== "iso-ssbg1-v1")
1002
+ return true;
1003
+ const ms = block["interleaveDepthMs"];
1004
+ return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
1005
+ }
1006
+ function catalogFecAvailable(fec) {
1007
+ const block = recordOf(fec);
1008
+ if (block === void 0)
1009
+ return true;
1010
+ const declaresFecInstance = block["algorithm"] !== "none";
1011
+ const profile = block["blockProfile"];
1012
+ const profileOk = isFecBlockProfile(profile) || profile === void 0 && !declaresFecInstance;
1013
+ return profileOk && (!declaresFecInstance || isoBlockSpanUsable(block));
1014
+ }
1015
+ function isPositiveSafeInteger(value) {
1016
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
1017
+ }
1018
+ function catalogFecDeclaresUnconfigurableInstance(fec) {
1019
+ const block = recordOf(fec);
1020
+ if (block === void 0 || block["algorithm"] === "none")
1021
+ return false;
1022
+ return !(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"]));
1023
+ }
1024
+
952
1025
  // src/mfu-reassembler.ts
953
1026
  function fragmentProvenance(fragment) {
954
1027
  if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
@@ -6926,6 +6999,9 @@ var FEC_BLOCK_PROFILES2 = Object.freeze([
6926
6999
  "iso-ssbg1-v1"
6927
7000
  ]);
6928
7001
 
7002
+ // node_modules/@blockcast/mmt-base/dist/catalog-fec-source.js
7003
+ var ALL_ROLES2 = Object.freeze(["video", "audio"]);
7004
+
6929
7005
  // node_modules/@blockcast/mmt-transport/dist/driad-discovery.js
6930
7006
  var DRIADDiscovery = class {
6931
7007
  cache = /* @__PURE__ */ new Map();
@@ -7507,7 +7583,8 @@ function toWindowMulticastSubscribeConfig(input) {
7507
7583
  ...input.packetIds?.length ? { packetIds: [...input.packetIds] } : {}
7508
7584
  };
7509
7585
  const relay = input.amtRelay?.trim();
7510
- const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && relay !== void 0 && relay !== "";
7586
+ const driad = !relay && input.amtDiscovery === "driad";
7587
+ const wantsAmt = input.mode === "tunnel" || input.mode !== "native" && (relay !== void 0 && relay !== "" || driad);
7511
7588
  if (!wantsAmt) {
7512
7589
  const native = {
7513
7590
  ...base,
@@ -7517,6 +7594,20 @@ function toWindowMulticastSubscribeConfig(input) {
7517
7594
  return native;
7518
7595
  }
7519
7596
  const relayPort = input.amtRelayPort;
7597
+ if (driad) {
7598
+ if (!base.source)
7599
+ throw new TypeError("AMT DRIAD discovery requires a source address");
7600
+ if (relayPort !== void 0 && !isPositivePort(relayPort)) {
7601
+ throw new TypeError("AMT DRIAD discovery requires a valid relay port when one is given");
7602
+ }
7603
+ return {
7604
+ ...base,
7605
+ source: base.source,
7606
+ origin: "amt",
7607
+ discovery: "driad",
7608
+ ...relayPort !== void 0 ? { relayPort } : {}
7609
+ };
7610
+ }
7520
7611
  if (!relay || relayPort === void 0 || !isPositivePort(relayPort)) {
7521
7612
  throw new TypeError("AMT requires a resolved relay and a valid relay port");
7522
7613
  }
@@ -12579,22 +12670,16 @@ var INACTIVE = Object.freeze({
12579
12670
  "reliable-moq": Object.freeze({ state: "inactive", reason: "reliable-moq" }),
12580
12671
  "no-multicast-bridge": Object.freeze({ state: "inactive", reason: "no-multicast-bridge" })
12581
12672
  });
12582
- function recordOf(value) {
12673
+ function recordOf2(value) {
12583
12674
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
12584
12675
  }
12585
- function isPositiveSafeInteger(value) {
12676
+ function isPositiveSafeInteger2(value) {
12586
12677
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
12587
12678
  }
12588
12679
  function catalogDeclaresFec(fec) {
12589
- const block = recordOf(fec);
12680
+ const block = recordOf2(fec);
12590
12681
  if (block === void 0 || block["algorithm"] === "none") return false;
12591
- return isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block);
12592
- }
12593
- function isoBlockSpanUsable(fec) {
12594
- const block = recordOf(fec);
12595
- if (block === void 0 || block["blockProfile"] !== "iso-ssbg1-v1") return true;
12596
- const ms = block["interleaveDepthMs"];
12597
- return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
12682
+ return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block);
12598
12683
  }
12599
12684
  function requireBoolean(value, field) {
12600
12685
  if (typeof value !== "boolean") {
@@ -12610,7 +12695,7 @@ function resolveFecState(evidence) {
12610
12695
  if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
12611
12696
  throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
12612
12697
  }
12613
- if (stats !== null && stats !== void 0 && recordOf(stats) === void 0) {
12698
+ if (stats !== null && stats !== void 0 && recordOf2(stats) === void 0) {
12614
12699
  throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
12615
12700
  }
12616
12701
  if (!catalogFec) return INACTIVE["no-catalog-fec"];
@@ -22022,7 +22107,7 @@ function sameIds(a, b) {
22022
22107
  for (const id of a) if (!b.has(id)) return false;
22023
22108
  return true;
22024
22109
  }
22025
- var MulticastTransport = class _MulticastTransport {
22110
+ var MulticastTransport = class {
22026
22111
  #onPacket;
22027
22112
  #subscription = null;
22028
22113
  #packetListener = null;
@@ -22094,8 +22179,11 @@ var MulticastTransport = class _MulticastTransport {
22094
22179
  // droppedPacketIds.
22095
22180
  #unadvertisedPacketIds = /* @__PURE__ */ new Set();
22096
22181
  #joinGeneration = 0;
22097
- constructor(onPacket) {
22182
+ // The provider to subscribe through; window.multicast when unset.
22183
+ #gateway;
22184
+ constructor(onPacket, options = {}) {
22098
22185
  this.#onPacket = onPacket;
22186
+ this.#gateway = options.gateway;
22099
22187
  }
22100
22188
  static isAvailable() {
22101
22189
  return hasMulticastGateway();
@@ -22105,7 +22193,8 @@ var MulticastTransport = class _MulticastTransport {
22105
22193
  this.#releaseSubscription();
22106
22194
  this.#dataPlaneLive = false;
22107
22195
  if (this.#disposed) return this.#declined(generation, "disposed");
22108
- if (!_MulticastTransport.isAvailable()) {
22196
+ const gateway = this.#gateway ?? getMulticastGlobals().multicast;
22197
+ if (typeof gateway?.subscribe !== "function") {
22109
22198
  console.warn("[MulticastTransport] Multicast API not available");
22110
22199
  return this.#declined(generation, "unavailable");
22111
22200
  }
@@ -22122,11 +22211,12 @@ var MulticastTransport = class _MulticastTransport {
22122
22211
  mode: config.mode,
22123
22212
  amtRelay: config.amtRelay,
22124
22213
  amtRelayPort: config.amtRelayPort,
22214
+ amtDiscovery: config.amtDiscovery,
22125
22215
  packetIds: config.packetIds,
22126
22216
  tracks: config.tracks
22127
22217
  });
22128
22218
  failure = "provider-rejected";
22129
- const subscription = await getMulticastGlobals().multicast.subscribe(subscribeConfig);
22219
+ const subscription = await gateway.subscribe(subscribeConfig);
22130
22220
  failure = "invalid-subscription";
22131
22221
  console.log(`[MulticastTransport] window.multicast.subscribe returned:`, !!subscription);
22132
22222
  if (this.#disposed || generation !== this.#joinGeneration) {
@@ -22782,28 +22872,28 @@ function joinedRepairSymbolCount(params, joinedRepairTrackNames) {
22782
22872
  }
22783
22873
  return total;
22784
22874
  }
22785
- function recordOf2(value) {
22875
+ function recordOf3(value) {
22786
22876
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
22787
22877
  }
22788
22878
  function msfTracks(catalog) {
22789
22879
  const raw = catalog.tracks;
22790
22880
  if (!Array.isArray(raw)) return void 0;
22791
- return { tracks: raw.map((t) => recordOf2(t) ?? {}) };
22881
+ return { tracks: raw.map((t) => recordOf3(t) ?? {}) };
22792
22882
  }
22793
22883
  function resolveRepairLayers(catalog, source) {
22794
22884
  if (!catalog) return void 0;
22795
22885
  const sourceName = typeof source === "string" ? source : source.name;
22796
22886
  const hang = catalog;
22797
22887
  const roles = typeof source === "string" ? ["video", "audio"] : source.type === "audio" ? ["audio"] : source.type === "video" ? ["video"] : ["video", "audio"];
22798
- const role = roles.find((r) => recordOf2(hang[r]?.renditions?.[sourceName]) !== void 0);
22799
- if (role !== void 0) {
22800
- const renditionPath = `$.${role}.renditions[${JSON.stringify(sourceName)}]`;
22801
- const rendition = recordOf2(hang[role].renditions[sourceName]);
22888
+ const located = locateCatalogFecSource(catalog, sourceName, roles);
22889
+ if (located?.dialect === "hang") {
22890
+ const renditionPath = `$.${located.role}.renditions[${JSON.stringify(sourceName)}]`;
22891
+ const rendition = located.entry;
22802
22892
  rejectRepairFieldsOnMediaTrack(renditionPath, rendition, throwRepairContractError);
22803
- const repairRenditions = recordOf2(hang.repair?.renditions) ?? {};
22893
+ const repairRenditions = recordOf3(hang.repair?.renditions) ?? {};
22804
22894
  const descriptors2 = Object.entries(repairRenditions).map(([name, entry]) => {
22805
22895
  const path = `$.repair.renditions[${JSON.stringify(name)}]`;
22806
- const fields = recordOf2(entry);
22896
+ const fields = recordOf3(entry);
22807
22897
  if (fields === void 0) {
22808
22898
  throwRepairContractError("track_repair_layer", path, "a repair rendition must be an object");
22809
22899
  }
@@ -22811,14 +22901,14 @@ function resolveRepairLayers(catalog, source) {
22811
22901
  return describeRepairTrack(name, path, fields);
22812
22902
  });
22813
22903
  const fecOfRendition = (entry) => {
22814
- const fec2 = recordOf2(recordOf2(entry)?.["fec"]);
22904
+ const fec2 = recordOf3(recordOf3(entry)?.["fec"]);
22815
22905
  return fec2 !== void 0 && fec2["algorithm"] !== "none" ? fec2 : void 0;
22816
22906
  };
22817
22907
  const mediaRenditions = [
22818
- ...Object.values(recordOf2(hang.video?.renditions) ?? {}),
22819
- ...Object.values(recordOf2(hang.audio?.renditions) ?? {})
22908
+ ...Object.values(recordOf3(hang.video?.renditions) ?? {}),
22909
+ ...Object.values(recordOf3(hang.audio?.renditions) ?? {})
22820
22910
  ];
22821
- const reachability2 = repairReachability(mediaRenditions.map((entry) => recordOf2(entry)?.["fec"]));
22911
+ const reachability2 = repairReachability(mediaRenditions.map((entry) => recordOf3(entry)?.["fec"]));
22822
22912
  for (const d of descriptors2) {
22823
22913
  validateRepairTrackFields(d, throwRepairContractError);
22824
22914
  assertRepairTrackReachable(d, reachability2, throwRepairContractError);
@@ -22834,20 +22924,20 @@ function resolveRepairLayers(catalog, source) {
22834
22924
  }
22835
22925
  }
22836
22926
  const layers2 = assembleRepairLayers(
22837
- geometryOf(sourceName, `${renditionPath}.fec`, recordOf2(rendition["fec"])),
22927
+ geometryOf(sourceName, `${renditionPath}.fec`, recordOf3(rendition["fec"])),
22838
22928
  descriptors2,
22839
22929
  throwRepairContractError
22840
22930
  );
22841
22931
  return catalogFecUnavailable(rendition["fec"], `${renditionPath}.fec`) === void 0 ? layers2 : void 0;
22842
22932
  }
22843
22933
  const msf = msfTracks(catalog);
22844
- const msfIndex = msf ? msf.tracks.findIndex((t) => t["name"] === sourceName) : -1;
22845
- if (!msf || msfIndex < 0) return void 0;
22934
+ if (!msf || located?.dialect !== "msf") return void 0;
22935
+ const msfIndex = located.index;
22846
22936
  const track = msf.tracks[msfIndex];
22847
- const fec = recordOf2(track["fec"]);
22937
+ const fec = recordOf3(track["fec"]);
22848
22938
  const packagingOf = (t) => t["packaging"];
22849
22939
  const fecOfTrack = (t) => {
22850
- const trackFec = recordOf2(t?.["fec"]);
22940
+ const trackFec = recordOf3(t?.["fec"]);
22851
22941
  return trackFec !== void 0 && trackFec["algorithm"] !== "none" ? trackFec : void 0;
22852
22942
  };
22853
22943
  const descriptors = [];
@@ -22897,8 +22987,8 @@ function catalogRepairTarget(catalog, source) {
22897
22987
  const entry = msf?.tracks.find((t) => t["name"] === sourceName);
22898
22988
  const hang = catalog;
22899
22989
  const roles = typeof source === "string" ? ["video", "audio"] : source.type === "video" ? ["video"] : source.type === "audio" ? ["audio"] : ["video", "audio"];
22900
- const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) => recordOf2(r) !== void 0);
22901
- const fec = rendition === void 0 ? recordOf2(entry?.["fec"]) : recordOf2(rendition.fec);
22990
+ const rendition = roles.map((role) => hang[role]?.renditions?.[sourceName]).find((r) => recordOf3(r) !== void 0);
22991
+ const fec = rendition === void 0 ? recordOf3(entry?.["fec"]) : recordOf3(rendition.fec);
22902
22992
  if (!fec || !(catalogFecInterleaveMs(fec) ?? 0)) return null;
22903
22993
  const sourcePriority = entry === void 0 ? null : moqtPriority2(entry["priority"]);
22904
22994
  return { repairTrack: layerZero.repairTrackName, sourcePriority, repairPriority: layerZero.priority };
@@ -22941,10 +23031,14 @@ function isoSpanUnavailable(fec, path, declaresFecInstance) {
22941
23031
  });
22942
23032
  }
22943
23033
  function catalogFecUnavailable(fec, fecPath) {
22944
- const block = recordOf2(fec);
22945
- if (block === void 0) return void 0;
23034
+ if (catalogFecAvailable(fec)) return void 0;
23035
+ const block = recordOf3(fec);
22946
23036
  const declaresFecInstance = block["algorithm"] !== "none";
22947
- return blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
23037
+ const reason = blockProfileUnavailable(block["blockProfile"], `${fecPath}.blockProfile`, declaresFecInstance) ?? isoSpanUnavailable(block, `${fecPath}.interleaveDepthMs`, declaresFecInstance);
23038
+ if (reason === void 0) {
23039
+ throw new Error(`catalogFecUnavailable: ${fecPath} is unavailable but no reason applies (rule drift)`);
23040
+ }
23041
+ return reason;
22948
23042
  }
22949
23043
  function fecParams(catalog, track, rendition, fps, sampleRate) {
22950
23044
  const mediaRate = sampleRate === void 0 ? { fps } : { fps, sampleRate };
@@ -22953,10 +23047,8 @@ function fecParams(catalog, track, rendition, fps, sampleRate) {
22953
23047
  const repair = resolveRepairLayers(catalog, track);
22954
23048
  const fecPath = `$.${track.type}.renditions[${JSON.stringify(track.name)}].fec`;
22955
23049
  if (!catalogDeclaresFec(fec)) {
22956
- const declaresFecInstance = fec.algorithm !== "none";
22957
- const kValid = Number.isSafeInteger(fec.sourceSymbols) && (fec.sourceSymbols ?? 0) > 0;
22958
- const tValid = Number.isSafeInteger(fec.symbolSize) && (fec.symbolSize ?? 0) > 0;
22959
- if (declaresFecInstance && !(kValid && tValid)) {
23050
+ if (catalogFecDeclaresUnconfigurableInstance(fec)) {
23051
+ const kValid = Number.isSafeInteger(fec.sourceSymbols) && (fec.sourceSymbols ?? 0) > 0;
22960
23052
  throwRepairContractError(
22961
23053
  "track_fec",
22962
23054
  `${fecPath}.${kValid ? "symbolSize" : "sourceSymbols"}`,
@@ -23363,6 +23455,9 @@ var MulticastManager = class {
23363
23455
  #router;
23364
23456
  #hostMfuTimeoutMs;
23365
23457
  #transport;
23458
+ /** Live joinRepairEndpoints() releases → the repair owners they registered,
23459
+ * re-applied after configureMultiTrack() clears catalog-derived owners. */
23460
+ #repairReleases = /* @__PURE__ */ new Map();
23366
23461
  #reportedFecDiagnosticsFailure = false;
23367
23462
  // ── Stream-global FEC timing reduction ──
23368
23463
  //
@@ -24010,11 +24105,80 @@ var MulticastManager = class {
24010
24105
  // through whatever the relay looks like, since dropping it would be the
24011
24106
  // worse behaviour.
24012
24107
  amtRelayPort: config.amtRelayPort ?? config.relayPort ?? (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
24108
+ amtDiscovery: config.amtDiscovery,
24013
24109
  packetIds: config.packetIds,
24014
24110
  tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId }))
24015
24111
  };
24016
24112
  return ingress === void 0 ? this.#transport.join(transportConfig) : this.#transport.join(transportConfig, ingress);
24017
24113
  }
24114
+ /**
24115
+ * Join the selected rung's dedicated repair groups beside the media join
24116
+ * (pim #3898): one subscription per endpoint, through `provider` when given
24117
+ * (a `window.multicast`-shaped gateway or a subscribe callback), otherwise a
24118
+ * new MulticastTransport on `window.multicast`. Returns the call that
24119
+ * releases every one of them; dispose() releases them too.
24120
+ *
24121
+ * Packets go straight to the router with the endpoint's ingress, never
24122
+ * through feedPacket(): repair arriving on its own group is not media
24123
+ * liveness, so it must not hold off the media leg's failback watchdog. The
24124
+ * repair roles and owners are registered here; in-band owners stay the
24125
+ * caller's. Joining is best effort: a group that fails to join is logged
24126
+ * and leaves the media join as it was.
24127
+ */
24128
+ joinRepairEndpoints(endpoints, provider) {
24129
+ const releases = [];
24130
+ let released = false;
24131
+ const safely = (each) => {
24132
+ try {
24133
+ each();
24134
+ } catch (error) {
24135
+ console.warn("[MulticastManager] repair group release failed", error);
24136
+ }
24137
+ };
24138
+ const repairOwners = endpoints.flatMap((endpoint) => endpoint.repairOwners);
24139
+ this.#applyRepairOwners(repairOwners);
24140
+ for (const endpoint of endpoints) {
24141
+ const ingress = {
24142
+ tracks: Object.freeze(endpoint.tracks.map(({ name, packetId }) => Object.freeze({ name, packetId })))
24143
+ };
24144
+ const onPacket = (packet) => {
24145
+ if (!released) this.#router.feedPacket(packet, "multicast", void 0, ingress);
24146
+ };
24147
+ const fail = (error) => console.warn(`[MulticastManager] repair group ${endpoint.group}:${endpoint.port} not joined`, error);
24148
+ if (typeof provider === "function") {
24149
+ Promise.resolve().then(() => provider(endpoint, onPacket)).then((release2) => released ? safely(release2) : releases.push(release2), fail);
24150
+ continue;
24151
+ }
24152
+ const transport = new MulticastTransport((packet) => onPacket(packet), { gateway: provider });
24153
+ releases.push(() => transport.dispose());
24154
+ void transport.join({
24155
+ sourceAddress: endpoint.source,
24156
+ groupAddress: endpoint.group,
24157
+ port: endpoint.port,
24158
+ mode: endpoint.mode,
24159
+ amtRelay: endpoint.amtRelay,
24160
+ amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
24161
+ packetIds: endpoint.packetIds,
24162
+ tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId }))
24163
+ }).then((joined) => {
24164
+ if (!joined && !released) fail(transport.lastJoinOutcome);
24165
+ });
24166
+ }
24167
+ const release = () => {
24168
+ if (released) return;
24169
+ released = true;
24170
+ this.#repairReleases.delete(release);
24171
+ for (const each of releases.splice(0)) safely(each);
24172
+ };
24173
+ this.#repairReleases.set(release, repairOwners);
24174
+ return release;
24175
+ }
24176
+ #applyRepairOwners(owners) {
24177
+ for (const { packetId, ownerPacketId } of owners) {
24178
+ this.#router.setPacketIdRole(packetId, "repair");
24179
+ this.#router.setRepairPacketIdOwner(packetId, ownerPacketId);
24180
+ }
24181
+ }
24018
24182
  // ---------------------------------------------------------------------------
24019
24183
  // In-place rendition switch
24020
24184
  // ---------------------------------------------------------------------------
@@ -24427,6 +24591,7 @@ var MulticastManager = class {
24427
24591
  this.#switchingSets.clear();
24428
24592
  this.#repairPacketIds.clear();
24429
24593
  this.#router.clearRepairPacketIdOwners();
24594
+ for (const owners of this.#repairReleases.values()) this.#applyRepairOwners(owners);
24430
24595
  const fecPacketIds = new Set([...fecDecoders.keys()].map((i) => catalog.tracks[i].packetId));
24431
24596
  for (const [packetId, catalogTrackName] of this.#multiTrackFecTracks) {
24432
24597
  if (fecPacketIds.has(packetId)) continue;
@@ -24758,6 +24923,7 @@ var MulticastManager = class {
24758
24923
  this.#trackResetObservers.clear();
24759
24924
  this.#repairLifecycleObservers.clear();
24760
24925
  this.#transport.dispose();
24926
+ for (const release of [...this.#repairReleases.keys()]) release();
24761
24927
  this.#router.dispose();
24762
24928
  this.#fec.dispose();
24763
24929
  }
@@ -26992,6 +27158,8 @@ export {
26992
27158
  buildVideoInitSegment,
26993
27159
  catalogAmtNetworkSource,
26994
27160
  catalogDeclaresFec,
27161
+ catalogFecAvailable,
27162
+ catalogFecDeclaresUnconfigurableInstance,
26995
27163
  catalogFecInterleaveMs,
26996
27164
  catalogFecMediaUnitsPerSecond,
26997
27165
  catalogFecUnavailable,
@@ -27066,6 +27234,7 @@ export {
27066
27234
  isTrackTimingConfig,
27067
27235
  joinedRepairSymbolCount,
27068
27236
  keyframeIntervalMediaTicks,
27237
+ locateCatalogFecSource,
27069
27238
  mergeOverrideIntoCmsfTracks,
27070
27239
  mergeOverrideIntoHangRenditions,
27071
27240
  mfuReassemblyTimeoutMs,