@blockcast/mmt-container 2.2.0-main.cc080e5a56f2 → 2.2.0-main.cc3fe0684403

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 +1485 -172
  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/datagram-leg-deadline.d.ts +118 -0
  24. package/dist/datagram-leg-deadline.d.ts.map +1 -0
  25. package/dist/datagram-leg-deadline.js +217 -0
  26. package/dist/datagram-leg-deadline.js.map +7 -0
  27. package/dist/delivery-catalog.js +68 -0
  28. package/dist/delivery-catalog.js.map +4 -4
  29. package/dist/delta-fallback-config.js +39 -1
  30. package/dist/delta-fallback-config.js.map +4 -4
  31. package/dist/fec-manager.d.ts +155 -10
  32. package/dist/fec-manager.d.ts.map +1 -1
  33. package/dist/fec-manager.js +596 -81
  34. package/dist/fec-manager.js.map +4 -4
  35. package/dist/fec-state.d.ts +17 -5
  36. package/dist/fec-state.d.ts.map +1 -1
  37. package/dist/fec-state.js +41 -1
  38. package/dist/fec-state.js.map +3 -3
  39. package/dist/fec-worker-setup.js +34 -0
  40. package/dist/fec-worker-setup.js.map +3 -3
  41. package/dist/held-layer-admission.js +34 -0
  42. package/dist/held-layer-admission.js.map +3 -3
  43. package/dist/index.d.ts +7 -5
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +15 -1
  46. package/dist/index.js.map +2 -2
  47. package/dist/iso-block-locator.d.ts +16 -0
  48. package/dist/iso-block-locator.d.ts.map +1 -1
  49. package/dist/iso-block-locator.js +62 -0
  50. package/dist/iso-block-locator.js.map +3 -3
  51. package/dist/mfu-reassembler.js +34 -0
  52. package/dist/mfu-reassembler.js.map +3 -3
  53. package/dist/mmtp-container-parser.d.ts +30 -2
  54. package/dist/mmtp-container-parser.d.ts.map +1 -1
  55. package/dist/mmtp-container-parser.js +140 -2
  56. package/dist/mmtp-container-parser.js.map +3 -3
  57. package/dist/mmtp-container-parser.no-modules.js +293 -18
  58. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  59. package/dist/mmtp-decode-pipeline.js +140 -2
  60. package/dist/mmtp-decode-pipeline.js.map +3 -3
  61. package/dist/mmtp-fec-session.js +34 -0
  62. package/dist/mmtp-fec-session.js.map +3 -3
  63. package/dist/mmtp-mode-selection.d.ts +48 -0
  64. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  65. package/dist/mmtp-mode-selection.js +79 -0
  66. package/dist/mmtp-mode-selection.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +66 -8
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +348 -27
  70. package/dist/mmtp-router.js.map +4 -4
  71. package/dist/multicast-auth-catalog.js +42 -2
  72. package/dist/multicast-auth-catalog.js.map +3 -3
  73. package/dist/multicast-input.js +42 -2
  74. package/dist/multicast-input.js.map +3 -3
  75. package/dist/multicast-manager.d.ts +108 -1
  76. package/dist/multicast-manager.d.ts.map +1 -1
  77. package/dist/multicast-manager.js +1067 -138
  78. package/dist/multicast-manager.js.map +4 -4
  79. package/dist/multicast-transport.js +68 -0
  80. package/dist/multicast-transport.js.map +4 -4
  81. package/dist/multicast-unwrap.js +34 -0
  82. package/dist/multicast-unwrap.js.map +3 -3
  83. package/dist/no-modules.d.ts +1 -0
  84. package/dist/no-modules.d.ts.map +1 -1
  85. package/dist/no-modules.js +295 -19
  86. package/dist/no-modules.js.map +4 -4
  87. package/dist/phase14-catalog-override.d.ts +2 -1
  88. package/dist/phase14-catalog-override.d.ts.map +1 -1
  89. package/dist/phase14-catalog-override.js +69 -2
  90. package/dist/phase14-catalog-override.js.map +3 -3
  91. package/dist/repair-fetch.d.ts.map +1 -1
  92. package/dist/repair-fetch.js +50 -0
  93. package/dist/repair-fetch.js.map +3 -3
  94. package/dist/repair-layer-subscriptions.js +34 -0
  95. package/dist/repair-layer-subscriptions.js.map +3 -3
  96. package/dist/signaling.js +34 -0
  97. package/dist/signaling.js.map +3 -3
  98. package/dist/timestamp-codec.js +34 -0
  99. package/dist/timestamp-codec.js.map +3 -3
  100. package/dist/wasm-mfu-reassembler.js +34 -0
  101. package/dist/wasm-mfu-reassembler.js.map +3 -3
  102. package/dist/wasm-mmtp-container-parser.js +140 -2
  103. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  104. package/package.json +5 -5
  105. package/schemas/catalog.schema.json +2 -2
  106. package/src/block-policy.ts +324 -83
  107. package/src/carp-catalog.ts +165 -5
  108. package/src/catalog-fec-params.ts +1 -0
  109. package/src/codec-utils.ts +121 -1
  110. package/src/datagram-leg-deadline.ts +342 -0
  111. package/src/fec-manager.ts +534 -41
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +38 -0
  114. package/src/iso-block-locator.ts +34 -0
  115. package/src/mmtp-container-parser.ts +57 -11
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +287 -42
  118. package/src/multicast-manager.ts +218 -10
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +23 -0
  122. package/test-vectors/catalog/README.md +36 -2
  123. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  124. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  127. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  128. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  130. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  131. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  134. package/test-vectors/catalog/section-codes.json +3 -3
  135. package/test-vectors/catalog-timing.json +559 -1
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -895,13 +895,25 @@ function fecCatalogTracks(catalog) {
895
895
  });
896
896
  return { tracks, pointers };
897
897
  }
898
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
898
+ function runtimeView(catalog, receiver) {
899
899
  const { tracks, pointers } = fecCatalogTracks(catalog);
900
900
  const report = validateFecCatalog({ tracks }, receiver);
901
901
  const at = (path) => {
902
902
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
903
903
  return m ? pointers[Number(m[1])] + m[2] : path;
904
904
  };
905
+ return { tracks, pointers, report, at };
906
+ }
907
+ function runtimeFecCatalogReport(catalog, receiver = RUNTIME_FEC_RECEIVER) {
908
+ const { report, at } = runtimeView(catalog, receiver);
909
+ const issue = (i) => Object.freeze({ code: i.code, path: at(i.path) });
910
+ return Object.freeze({
911
+ instances: Object.freeze(report.instances.map((i) => Object.freeze({ ...i, path: at(i.path), issues: Object.freeze(i.issues.map(issue)) }))),
912
+ issues: Object.freeze(report.issues.map(issue))
913
+ });
914
+ }
915
+ function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
916
+ const { tracks, pointers, report, at } = runtimeView(catalog, receiver);
905
917
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
906
918
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
907
919
  const why = (i) => Object.freeze({
@@ -999,6 +1011,66 @@ function geometry(o, instanceId, symbolTrack) {
999
1011
  });
1000
1012
  }
1001
1013
 
1014
+ // ../mmt-base/dist/mmtp-siblings.js
1015
+ var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
1016
+ function isMmtpMode(value) {
1017
+ return typeof value === "string" && MMTP_MODES.includes(value);
1018
+ }
1019
+ var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
1020
+ "namespace",
1021
+ "timescale",
1022
+ "presentationAnchorTicks",
1023
+ "groupDuration"
1024
+ ]);
1025
+ var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
1026
+ "codec",
1027
+ "width",
1028
+ "height",
1029
+ "framerate",
1030
+ "bitrate",
1031
+ "samplerate",
1032
+ "channelConfig",
1033
+ "lang"
1034
+ ]);
1035
+ var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
1036
+ "initRef",
1037
+ "keyframeIntervalMs",
1038
+ "keyframeIntervalTicks",
1039
+ "isLive",
1040
+ "altGroup"
1041
+ ]);
1042
+ function fields(track) {
1043
+ return track;
1044
+ }
1045
+ function groupDurationTicks(track) {
1046
+ const ticks = track["groupDurationTicks"];
1047
+ if (Number.isSafeInteger(ticks))
1048
+ return BigInt(ticks);
1049
+ const ms = track["groupDurationMs"];
1050
+ const timescale = track["timescale"];
1051
+ if (!Number.isSafeInteger(ms) || !Number.isSafeInteger(timescale))
1052
+ return void 0;
1053
+ return BigInt(ms) * BigInt(timescale) / 1000n;
1054
+ }
1055
+ function identityEqual(a, b) {
1056
+ return a["namespace"] === b["namespace"] && a["timescale"] === b["timescale"] && a["presentationAnchorTicks"] === b["presentationAnchorTicks"] && groupDurationTicks(a) === groupDurationTicks(b) && MMTP_SIBLING_RENDITION_FIELDS.every((field) => a[field] === b[field]);
1057
+ }
1058
+ function isMmtpTrack(track, mode) {
1059
+ return typeof track === "object" && track !== null && !Array.isArray(track) && fields(track)["packaging"] === "mmtp" && fields(track)["mmtpMode"] === mode;
1060
+ }
1061
+ function mmtpSiblingCandidates(tracks, datagram) {
1062
+ const own = fields(datagram);
1063
+ return tracks.filter((track) => isMmtpTrack(track, "mfu") && identityEqual(fields(track), own));
1064
+ }
1065
+
1066
+ // ../mmt-base/dist/datagram-leg-size.js
1067
+ var DATAGRAM_LEG_UDP_FLOOR = 1200;
1068
+ var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
1069
+ var DATAGRAM_LEG_OBJECT_HEADER = 13;
1070
+ var DATAGRAM_LEG_RELAY_ROOM = 16;
1071
+ var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
1072
+ var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
1073
+
1002
1074
  // src/mfu-reassembler.ts
1003
1075
  function fragmentProvenance(fragment) {
1004
1076
  if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
@@ -4576,9 +4648,10 @@ function isH264IntraSlice(nal) {
4576
4648
  const sliceType = readH264SliceType(nal);
4577
4649
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
4578
4650
  }
4651
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
4579
4652
  function readH264SliceType(nal) {
4580
4653
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4581
- const rbsp = removeEmulationPrevention(nal.subarray(1));
4654
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
4582
4655
  const state = { bitOffset: 0 };
4583
4656
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4584
4657
  return readUnsignedExpGolomb(rbsp, state);
@@ -4725,6 +4798,96 @@ if (void 0) {
4725
4798
  ]))).toBe(false);
4726
4799
  });
4727
4800
  });
4801
+ describe("readH264SliceType", () => {
4802
+ const wholeNalSliceType = (nal) => {
4803
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4804
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
4805
+ const state = { bitOffset: 0 };
4806
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4807
+ return readUnsignedExpGolomb(rbsp, state);
4808
+ };
4809
+ const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
4810
+ const ue = (value) => {
4811
+ const code = (value + 1).toString(2);
4812
+ return "0".repeat(code.length - 1) + code;
4813
+ };
4814
+ const sliceNal = (bits) => {
4815
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
4816
+ const nal = [1];
4817
+ let zeros = 0;
4818
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
4819
+ if (zeros >= 2 && byte <= 3) {
4820
+ nal.push(3);
4821
+ zeros = 0;
4822
+ }
4823
+ nal.push(byte);
4824
+ zeros = byte === 0 ? zeros + 1 : 0;
4825
+ }
4826
+ return Uint8Array.from(nal);
4827
+ };
4828
+ const x264Slices = [
4829
+ ["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
4830
+ ["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
4831
+ ["64x48 non-IDR I", hex2(
4832
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
4833
+ ), 7, true],
4834
+ ["1280x720 B, escape at byte 10", hex2(
4835
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
4836
+ ), 6, false],
4837
+ ["1280x720 P, escape at byte 15", hex2(
4838
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
4839
+ ), 5, false],
4840
+ ["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
4841
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex2(
4842
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
4843
+ ), null, true],
4844
+ ["7680x4320 P, first_mb_in_slice 32640", hex2(
4845
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
4846
+ ), 5, false],
4847
+ ["7680x4320 P, first_mb_in_slice 97440", hex2(
4848
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
4849
+ ), 5, false]
4850
+ ];
4851
+ const syntheticSlices = [
4852
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
4853
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
4854
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
4855
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
4856
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
4857
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
4858
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
4859
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
4860
+ ];
4861
+ test("reads the slice_type of real and synthetic slices", () => {
4862
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
4863
+ expect(readH264SliceType(nal), name).toBe(sliceType);
4864
+ }
4865
+ });
4866
+ test("matches the whole-NAL unescape at every truncation", () => {
4867
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
4868
+ for (let end = 0; end <= nal.length; end++) {
4869
+ const cut = nal.subarray(0, end);
4870
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
4871
+ }
4872
+ }
4873
+ });
4874
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
4875
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
4876
+ let seed = 1;
4877
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
4878
+ for (let i = 0; i < 5e3; i++) {
4879
+ const nal = new Uint8Array(2 + next() % 63);
4880
+ nal[0] = 65;
4881
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
4882
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
4883
+ }
4884
+ });
4885
+ test("classifies the x264 slices as keyframes or not", () => {
4886
+ for (const [name, nal, , keyframe] of x264Slices) {
4887
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
4888
+ }
4889
+ });
4890
+ });
4728
4891
  describe("avccToAnnexB", () => {
4729
4892
  test("converts with SPS/PPS on keyframe", () => {
4730
4893
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -6220,7 +6383,7 @@ var FecReleaseSequencer = class {
6220
6383
  from
6221
6384
  );
6222
6385
  unresolved = resolved === null;
6223
- if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
6386
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
6224
6387
  const heldMs = performance.now() - head.arrivedAtMs;
6225
6388
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
6226
6389
  this.#recordStat("forcedWindowFlushes");
@@ -6238,6 +6401,19 @@ var FecReleaseSequencer = class {
6238
6401
  );
6239
6402
  }
6240
6403
  }
6404
+ /**
6405
+ * The head has waited out a gap only a late source can still fill
6406
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
6407
+ * the stream when it has (`wakeAt`), since no packet may come by then.
6408
+ */
6409
+ #unrepairableWaitOver(stream, last, head, from, to) {
6410
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
6411
+ if (waitMs === void 0) return false;
6412
+ const atMs = head.arrivedAtMs + waitMs;
6413
+ if (performance.now() >= atMs) return true;
6414
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
6415
+ return false;
6416
+ }
6241
6417
  /**
6242
6418
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
6243
6419
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -8023,13 +8199,13 @@ function validateCmsfMmtpCatalog(value, _options = {}) {
8023
8199
  }
8024
8200
  const timescale = track["timescale"];
8025
8201
  const groupDurationMs = track["groupDurationMs"];
8026
- const groupDurationTicks = track["groupDurationTicks"];
8202
+ const groupDurationTicks2 = track["groupDurationTicks"];
8027
8203
  const keyframeIntervalMs = track["keyframeIntervalMs"];
8028
8204
  const keyframeIntervalTicks = track["keyframeIntervalTicks"];
8029
8205
  if (groupDurationMs !== void 0 && !positiveInteger(groupDurationMs)) {
8030
8206
  catalogError("track_group_duration_ms", `${path}.groupDurationMs`, "must be a positive integer");
8031
8207
  }
8032
- if (groupDurationTicks !== void 0 && !positiveInteger(groupDurationTicks)) {
8208
+ if (groupDurationTicks2 !== void 0 && !positiveInteger(groupDurationTicks2)) {
8033
8209
  catalogError("track_group_duration_ticks", `${path}.groupDurationTicks`, "must be a positive integer");
8034
8210
  }
8035
8211
  if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger(keyframeIntervalTicks)) {
@@ -8044,20 +8220,17 @@ function validateCmsfMmtpCatalog(value, _options = {}) {
8044
8220
  catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
8045
8221
  }
8046
8222
  if (packaging === "mmtp") {
8047
- if (track["mmtpMode"] !== "mfu") {
8048
- catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
8049
- }
8050
8223
  if (!positiveInteger(timescale)) {
8051
8224
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
8052
8225
  }
8053
- if (groupDurationMs === void 0 && groupDurationTicks === void 0) {
8226
+ if (groupDurationMs === void 0 && groupDurationTicks2 === void 0) {
8054
8227
  catalogError(
8055
8228
  "track_group_duration_ms",
8056
8229
  path,
8057
8230
  "groupDurationMs or groupDurationTicks must be a positive integer"
8058
8231
  );
8059
8232
  }
8060
- if (groupDurationTicks === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8233
+ if (groupDurationTicks2 === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8061
8234
  catalogError("track_group_duration_exact", `${path}.groupDurationMs`, "does not resolve to an exact integer tick count");
8062
8235
  }
8063
8236
  }
@@ -8139,11 +8312,106 @@ function validateCmsfMmtpCatalog(value, _options = {}) {
8139
8312
  }
8140
8313
  }
8141
8314
  validateArchive(catalog);
8315
+ dropRejectedMmtpTracks(catalog);
8142
8316
  return catalog;
8143
8317
  }
8318
+ function dropRejectedMmtpTracks(catalog) {
8319
+ const rejected = mmtpTrackIssues(catalog);
8320
+ if (rejected.length === 0) return;
8321
+ const tracks = catalog["tracks"];
8322
+ const rejectedIndexes = new Set(rejected.map((issue) => issue.index));
8323
+ const nameOf = (track) => track?.["name"];
8324
+ const mediaNames = new Set(tracks.filter((_, index) => !rejectedIndexes.has(index)).map(nameOf));
8325
+ const kept = tracks.filter((track, index) => {
8326
+ if (rejectedIndexes.has(index)) return false;
8327
+ const t = track;
8328
+ return !(t?.["packaging"] === "fec-repair" && typeof t["source"] === "string" && !mediaNames.has(t["source"]) && rejected.some((issue) => issue.name === t["source"]));
8329
+ });
8330
+ catalog["tracks"] = kept;
8331
+ const keptNames = new Set(kept.map(nameOf));
8332
+ const endpoints = catalog["multicast"]?.["endpoints"];
8333
+ if (Array.isArray(endpoints)) {
8334
+ for (const endpoint of endpoints) {
8335
+ const refs = endpoint?.["tracks"];
8336
+ if (!endpoint || !Array.isArray(refs)) continue;
8337
+ endpoint["tracks"] = refs.filter((ref) => keptNames.has(typeof ref === "object" ? nameOf(ref) : ref));
8338
+ }
8339
+ }
8340
+ Object.defineProperty(catalog, "rejectedTracks", { value: rejected, enumerable: false, configurable: true, writable: true });
8341
+ }
8342
+ function mmtpTrackIssues(catalog) {
8343
+ if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) return [];
8344
+ const tracks = catalog["tracks"];
8345
+ if (!Array.isArray(tracks)) return [];
8346
+ const records = tracks.filter(
8347
+ (track) => typeof track === "object" && track !== null && !Array.isArray(track)
8348
+ );
8349
+ const issues = [];
8350
+ const streamPaths = (track) => {
8351
+ const name = typeof track["name"] === "string" ? track["name"] : "";
8352
+ return [track, ...records.filter((repair) => repair["packaging"] === "fec-repair" && repair["source"] === name)].filter((declaring) => declaring["deliveryMode"] === "stream").map((declaring) => `$.tracks[${tracks.indexOf(declaring)}]`);
8353
+ };
8354
+ const candidatesOf = /* @__PURE__ */ new Map();
8355
+ const mirrorsOf = /* @__PURE__ */ new Map();
8356
+ for (const track of records) {
8357
+ if (track["packaging"] !== "mmtp" || track["mmtpMode"] !== "mfu-datagram") continue;
8358
+ const candidates = mmtpSiblingCandidates(records, track);
8359
+ candidatesOf.set(track, candidates);
8360
+ if (candidates.length === 1 && streamPaths(track).length === 0) {
8361
+ mirrorsOf.set(candidates[0], [...mirrorsOf.get(candidates[0]) ?? [], track]);
8362
+ }
8363
+ }
8364
+ for (const track of records) {
8365
+ const index = tracks.indexOf(track);
8366
+ const path = `$.tracks[${index}]`;
8367
+ const name = typeof track["name"] === "string" ? track["name"] : "";
8368
+ if (track["packaging"] !== "mmtp") continue;
8369
+ const mode = track["mmtpMode"];
8370
+ if (!isMmtpMode(mode)) {
8371
+ issues.push({
8372
+ code: "track_mmtp_mode",
8373
+ path: `${path}.mmtpMode`,
8374
+ message: `mmtpMode must be "mfu" or "mfu-datagram", got ${JSON.stringify(mode)}; a subscriber rejects the track (draft-ramadan-moq-mmt-02 13.1)`,
8375
+ name,
8376
+ index
8377
+ });
8378
+ continue;
8379
+ }
8380
+ if (mode !== "mfu-datagram") continue;
8381
+ const conflict = (at) => issues.push({
8382
+ code: "track_delivery_mode_conflict",
8383
+ path: `${at}.deliveryMode`,
8384
+ message: `"mfu-datagram" track ${JSON.stringify(name)} and its repair tracks are sent as datagrams; deliveryMode "stream" would subscribe no repair (draft-ramadan-moq-mmt-02 4.3.1)`,
8385
+ name,
8386
+ index
8387
+ });
8388
+ const streams = streamPaths(track);
8389
+ for (const at of streams) conflict(at);
8390
+ const candidates = candidatesOf.get(track) ?? [];
8391
+ const rivals = candidates.length === 1 && streams.length === 0 ? (mirrorsOf.get(candidates[0]) ?? []).filter((other) => other !== track) : [];
8392
+ if (rivals.length > 0) {
8393
+ issues.push({
8394
+ code: "track_mmtp_sibling",
8395
+ path,
8396
+ message: `"mfu-datagram" track ${JSON.stringify(name)} mirrors "mfu" track ${JSON.stringify(candidates[0]["name"])}, and so ${rivals.length === 1 ? "does" : "do"} ${rivals.map((rival) => JSON.stringify(rival["name"])).join(", ")}; the catalog does not say which one mirrors it, so a subscriber pairs none (draft-ramadan-moq-mmt-02 4.3.1)`,
8397
+ name,
8398
+ index
8399
+ });
8400
+ } else if (candidates.length !== 1) {
8401
+ issues.push({
8402
+ code: "track_mmtp_sibling",
8403
+ path,
8404
+ message: candidates.length === 0 ? `"mfu-datagram" track ${JSON.stringify(name)} mirrors no "mfu" track of its namespace with the same timescale, presentationAnchorTicks, group duration and rendition fields (${MMTP_SIBLING_RENDITION_FIELDS.join(", ")}), each equal or absent on both (draft-ramadan-moq-mmt-02 4.3.1, 13.1)` : `"mfu-datagram" track ${JSON.stringify(name)} could mirror ${candidates.length} "mfu" tracks (${candidates.map((c) => JSON.stringify(c["name"])).join(", ")}) that carry one description; the pair is ambiguous`,
8405
+ name,
8406
+ index
8407
+ });
8408
+ }
8409
+ }
8410
+ return issues;
8411
+ }
8144
8412
 
8145
8413
  // src/no-modules.ts
8146
- import { catalogFecInterleaveMs, fecBlockBudgetMs as fecBlockBudgetMs2, fecBlockDeadlineMs } from "@blockcast/mmt-fec";
8414
+ import { catalogFecInterleaveMs as catalogFecInterleaveMs2, fecBlockBudgetMs as fecBlockBudgetMs2, fecBlockDeadlineMs } from "@blockcast/mmt-fec";
8147
8415
 
8148
8416
  // src/fec-state.ts
8149
8417
  var FEC_INACTIVE_REASONS = Object.freeze([
@@ -8173,6 +8441,7 @@ function resolveFecState(evidence) {
8173
8441
  const catalogFec = requireBoolean(evidence.catalogFec, "catalogFec");
8174
8442
  const bridgeAvailable = requireBoolean(evidence.bridgeAvailable, "bridgeAvailable");
8175
8443
  const multicastLegJoined = requireBoolean(evidence.multicastLegJoined, "multicastLegJoined");
8444
+ const datagramLegJoined = evidence.datagramLegJoined === void 0 ? false : requireBoolean(evidence.datagramLegJoined, "datagramLegJoined");
8176
8445
  const { transportPolicy, stats } = evidence;
8177
8446
  if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
8178
8447
  throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
@@ -8181,6 +8450,7 @@ function resolveFecState(evidence) {
8181
8450
  throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
8182
8451
  }
8183
8452
  if (!catalogFec) return INACTIVE["no-catalog-fec"];
8453
+ if (datagramLegJoined) return { ...stats ?? {}, state: "active" };
8184
8454
  if (transportPolicy === "moq-only") return INACTIVE["reliable-moq"];
8185
8455
  if (!bridgeAvailable) return INACTIVE["no-multicast-bridge"];
8186
8456
  if (transportPolicy === "multicast-only" || multicastLegJoined) {
@@ -8189,6 +8459,10 @@ function resolveFecState(evidence) {
8189
8459
  return INACTIVE["reliable-moq"];
8190
8460
  }
8191
8461
 
8462
+ // src/catalog-fec-params.ts
8463
+ import { catalogFecInterleaveMs } from "@blockcast/mmt-fec";
8464
+ var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
8465
+
8192
8466
  // src/mmtp-fec-session.ts
8193
8467
  import { deriveFecRetentionBlocks, fecBlockBudgetMs } from "@blockcast/mmt-fec";
8194
8468
 
@@ -10116,12 +10390,12 @@ function validPort(value) {
10116
10390
  return Number.isInteger(value) && value >= 0 && value <= 65535;
10117
10391
  }
10118
10392
  function parseIpv4(address) {
10119
- const fields = address.split(".");
10120
- if (fields.length !== 4 || fields.some((field) => !/^\d+$/.test(field))) {
10393
+ const fields2 = address.split(".");
10394
+ if (fields2.length !== 4 || fields2.some((field) => !/^\d+$/.test(field))) {
10121
10395
  throw new Error(`invalid IPv4 address ${address}`);
10122
10396
  }
10123
- const values = fields.map(Number);
10124
- if (values.some((value, index) => value > 255 || String(value) !== fields[index])) {
10397
+ const values = fields2.map(Number);
10398
+ if (values.some((value, index) => value > 255 || String(value) !== fields2[index])) {
10125
10399
  throw new Error(`invalid IPv4 address ${address}`);
10126
10400
  }
10127
10401
  return Uint8Array.from(values);
@@ -10335,7 +10609,7 @@ function bitLen(n) {
10335
10609
  return len;
10336
10610
  }
10337
10611
  var bitMask = (n) => (_1n << BigInt(n)) - _1n;
10338
- function _validateObject(object, fields, optFields = {}) {
10612
+ function _validateObject(object, fields2, optFields = {}) {
10339
10613
  if (!object || typeof object !== "object")
10340
10614
  throw new Error("expected valid options object");
10341
10615
  function checkField(fieldName, expectedType, isOpt) {
@@ -10346,7 +10620,7 @@ function _validateObject(object, fields, optFields = {}) {
10346
10620
  if (current !== expectedType || val === null)
10347
10621
  throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
10348
10622
  }
10349
- Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
10623
+ Object.entries(fields2).forEach(([k, v]) => checkField(k, v, false));
10350
10624
  Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
10351
10625
  }
10352
10626
  var notImplemented = () => {
@@ -12179,7 +12453,7 @@ export {
12179
12453
  catalogAmtNetworkSource,
12180
12454
  catalogAtsc3NetworkSource,
12181
12455
  catalogDeclaresFec,
12182
- catalogFecInterleaveMs,
12456
+ catalogFecInterleaveMs2 as catalogFecInterleaveMs,
12183
12457
  createWasmMmtpContainerParser,
12184
12458
  datagramMfuReassembly,
12185
12459
  fecBlockBudgetMs2 as fecBlockBudgetMs,
@@ -12189,7 +12463,9 @@ export {
12189
12463
  reliableMoqMfuReassembly,
12190
12464
  resolveFecState,
12191
12465
  resolveGroupDurationMs,
12192
- validateCmsfMmtpCatalog
12466
+ runtimeFecCatalogReport,
12467
+ validateCmsfMmtpCatalog,
12468
+ validateFecCatalog
12193
12469
  };
12194
12470
  /*! Bundled license information:
12195
12471