@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
@@ -58,7 +58,9 @@ var BlockcastMmt = (() => {
58
58
  reliableMoqMfuReassembly: () => reliableMoqMfuReassembly,
59
59
  resolveFecState: () => resolveFecState,
60
60
  resolveGroupDurationMs: () => resolveGroupDurationMs,
61
- validateCmsfMmtpCatalog: () => validateCmsfMmtpCatalog
61
+ runtimeFecCatalogReport: () => runtimeFecCatalogReport,
62
+ validateCmsfMmtpCatalog: () => validateCmsfMmtpCatalog,
63
+ validateFecCatalog: () => validateFecCatalog
62
64
  });
63
65
 
64
66
  // ../mmt-base/dist/mmtp.js
@@ -958,13 +960,25 @@ var BlockcastMmt = (() => {
958
960
  });
959
961
  return { tracks, pointers };
960
962
  }
961
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
963
+ function runtimeView(catalog, receiver) {
962
964
  const { tracks, pointers } = fecCatalogTracks(catalog);
963
965
  const report = validateFecCatalog({ tracks }, receiver);
964
966
  const at = (path) => {
965
967
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
966
968
  return m ? pointers[Number(m[1])] + m[2] : path;
967
969
  };
970
+ return { tracks, pointers, report, at };
971
+ }
972
+ function runtimeFecCatalogReport(catalog, receiver = RUNTIME_FEC_RECEIVER) {
973
+ const { report, at } = runtimeView(catalog, receiver);
974
+ const issue = (i) => Object.freeze({ code: i.code, path: at(i.path) });
975
+ return Object.freeze({
976
+ instances: Object.freeze(report.instances.map((i) => Object.freeze({ ...i, path: at(i.path), issues: Object.freeze(i.issues.map(issue)) }))),
977
+ issues: Object.freeze(report.issues.map(issue))
978
+ });
979
+ }
980
+ function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
981
+ const { tracks, pointers, report, at } = runtimeView(catalog, receiver);
968
982
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
969
983
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
970
984
  const why = (i) => Object.freeze({
@@ -1062,6 +1076,66 @@ var BlockcastMmt = (() => {
1062
1076
  });
1063
1077
  }
1064
1078
 
1079
+ // ../mmt-base/dist/mmtp-siblings.js
1080
+ var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
1081
+ function isMmtpMode(value) {
1082
+ return typeof value === "string" && MMTP_MODES.includes(value);
1083
+ }
1084
+ var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
1085
+ "namespace",
1086
+ "timescale",
1087
+ "presentationAnchorTicks",
1088
+ "groupDuration"
1089
+ ]);
1090
+ var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
1091
+ "codec",
1092
+ "width",
1093
+ "height",
1094
+ "framerate",
1095
+ "bitrate",
1096
+ "samplerate",
1097
+ "channelConfig",
1098
+ "lang"
1099
+ ]);
1100
+ var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
1101
+ "initRef",
1102
+ "keyframeIntervalMs",
1103
+ "keyframeIntervalTicks",
1104
+ "isLive",
1105
+ "altGroup"
1106
+ ]);
1107
+ function fields(track) {
1108
+ return track;
1109
+ }
1110
+ function groupDurationTicks(track) {
1111
+ const ticks = track["groupDurationTicks"];
1112
+ if (Number.isSafeInteger(ticks))
1113
+ return BigInt(ticks);
1114
+ const ms = track["groupDurationMs"];
1115
+ const timescale = track["timescale"];
1116
+ if (!Number.isSafeInteger(ms) || !Number.isSafeInteger(timescale))
1117
+ return void 0;
1118
+ return BigInt(ms) * BigInt(timescale) / 1000n;
1119
+ }
1120
+ function identityEqual(a, b) {
1121
+ 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]);
1122
+ }
1123
+ function isMmtpTrack(track, mode) {
1124
+ return typeof track === "object" && track !== null && !Array.isArray(track) && fields(track)["packaging"] === "mmtp" && fields(track)["mmtpMode"] === mode;
1125
+ }
1126
+ function mmtpSiblingCandidates(tracks, datagram) {
1127
+ const own = fields(datagram);
1128
+ return tracks.filter((track) => isMmtpTrack(track, "mfu") && identityEqual(fields(track), own));
1129
+ }
1130
+
1131
+ // ../mmt-base/dist/datagram-leg-size.js
1132
+ var DATAGRAM_LEG_UDP_FLOOR = 1200;
1133
+ var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
1134
+ var DATAGRAM_LEG_OBJECT_HEADER = 13;
1135
+ var DATAGRAM_LEG_RELAY_ROOM = 16;
1136
+ var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
1137
+ var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
1138
+
1065
1139
  // src/mfu-reassembler.ts
1066
1140
  function fragmentProvenance(fragment) {
1067
1141
  if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
@@ -4650,9 +4724,10 @@ var BlockcastMmt = (() => {
4650
4724
  const sliceType = readH264SliceType(nal);
4651
4725
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
4652
4726
  }
4727
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
4653
4728
  function readH264SliceType(nal) {
4654
4729
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4655
- const rbsp = removeEmulationPrevention(nal.subarray(1));
4730
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
4656
4731
  const state = { bitOffset: 0 };
4657
4732
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4658
4733
  return readUnsignedExpGolomb(rbsp, state);
@@ -4799,6 +4874,96 @@ var BlockcastMmt = (() => {
4799
4874
  ]))).toBe(false);
4800
4875
  });
4801
4876
  });
4877
+ describe("readH264SliceType", () => {
4878
+ const wholeNalSliceType = (nal) => {
4879
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4880
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
4881
+ const state = { bitOffset: 0 };
4882
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4883
+ return readUnsignedExpGolomb(rbsp, state);
4884
+ };
4885
+ const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
4886
+ const ue = (value) => {
4887
+ const code = (value + 1).toString(2);
4888
+ return "0".repeat(code.length - 1) + code;
4889
+ };
4890
+ const sliceNal = (bits) => {
4891
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
4892
+ const nal = [1];
4893
+ let zeros = 0;
4894
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
4895
+ if (zeros >= 2 && byte <= 3) {
4896
+ nal.push(3);
4897
+ zeros = 0;
4898
+ }
4899
+ nal.push(byte);
4900
+ zeros = byte === 0 ? zeros + 1 : 0;
4901
+ }
4902
+ return Uint8Array.from(nal);
4903
+ };
4904
+ const x264Slices = [
4905
+ ["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
4906
+ ["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
4907
+ ["64x48 non-IDR I", hex2(
4908
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
4909
+ ), 7, true],
4910
+ ["1280x720 B, escape at byte 10", hex2(
4911
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
4912
+ ), 6, false],
4913
+ ["1280x720 P, escape at byte 15", hex2(
4914
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
4915
+ ), 5, false],
4916
+ ["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
4917
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex2(
4918
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
4919
+ ), null, true],
4920
+ ["7680x4320 P, first_mb_in_slice 32640", hex2(
4921
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
4922
+ ), 5, false],
4923
+ ["7680x4320 P, first_mb_in_slice 97440", hex2(
4924
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
4925
+ ), 5, false]
4926
+ ];
4927
+ const syntheticSlices = [
4928
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
4929
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
4930
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
4931
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
4932
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
4933
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
4934
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
4935
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
4936
+ ];
4937
+ test("reads the slice_type of real and synthetic slices", () => {
4938
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
4939
+ expect(readH264SliceType(nal), name).toBe(sliceType);
4940
+ }
4941
+ });
4942
+ test("matches the whole-NAL unescape at every truncation", () => {
4943
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
4944
+ for (let end = 0; end <= nal.length; end++) {
4945
+ const cut = nal.subarray(0, end);
4946
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
4947
+ }
4948
+ }
4949
+ });
4950
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
4951
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
4952
+ let seed = 1;
4953
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
4954
+ for (let i = 0; i < 5e3; i++) {
4955
+ const nal = new Uint8Array(2 + next() % 63);
4956
+ nal[0] = 65;
4957
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
4958
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
4959
+ }
4960
+ });
4961
+ test("classifies the x264 slices as keyframes or not", () => {
4962
+ for (const [name, nal, , keyframe] of x264Slices) {
4963
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
4964
+ }
4965
+ });
4966
+ });
4802
4967
  describe("avccToAnnexB", () => {
4803
4968
  test("converts with SPS/PPS on keyframe", () => {
4804
4969
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -6008,7 +6173,7 @@ var BlockcastMmt = (() => {
6008
6173
  function holdsRebuilt(stream) {
6009
6174
  return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
6010
6175
  }
6011
- var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, drainLoop_fn, cursorPassed_fn, release_fn;
6176
+ var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, drainLoop_fn, unrepairableWaitOver_fn, cursorPassed_fn, release_fn;
6012
6177
  var FecReleaseSequencer = class {
6013
6178
  constructor(gate, emit, recordStat) {
6014
6179
  __privateAdd(this, _FecReleaseSequencer_instances);
@@ -6321,7 +6486,7 @@ var BlockcastMmt = (() => {
6321
6486
  from
6322
6487
  );
6323
6488
  unresolved = resolved === null;
6324
- if (unresolved && !__privateMethod(this, _FecReleaseSequencer_instances, cursorPassed_fn).call(this, stream, asUnanchored)) {
6489
+ if (unresolved && !__privateMethod(this, _FecReleaseSequencer_instances, cursorPassed_fn).call(this, stream, asUnanchored) && !__privateMethod(this, _FecReleaseSequencer_instances, unrepairableWaitOver_fn).call(this, stream, last, head, from, to)) {
6325
6490
  const heldMs = performance.now() - head.arrivedAtMs;
6326
6491
  if (heldMs <= __privateGet(this, _gate).holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
6327
6492
  __privateGet(this, _recordStat2).call(this, "forcedWindowFlushes");
@@ -6335,6 +6500,19 @@ var BlockcastMmt = (() => {
6335
6500
  __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? __privateGet(this, _gate).decide(last, head, lost, false) : void 0);
6336
6501
  }
6337
6502
  };
6503
+ /**
6504
+ * The head has waited out a gap only a late source can still fill
6505
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
6506
+ * the stream when it has (`wakeAt`), since no packet may come by then.
6507
+ */
6508
+ unrepairableWaitOver_fn = function(stream, last, head, from, to) {
6509
+ const waitMs = __privateGet(this, _gate).unrepairableWaitMs?.(last, head, from, to);
6510
+ if (waitMs === void 0) return false;
6511
+ const atMs = head.arrivedAtMs + waitMs;
6512
+ if (performance.now() >= atMs) return true;
6513
+ __privateGet(this, _gate).wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
6514
+ return false;
6515
+ };
6338
6516
  /**
6339
6517
  * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
6340
6518
  * source cursor holds it unanchored, and neither does a later frame behind
@@ -8122,13 +8300,13 @@ var BlockcastMmt = (() => {
8122
8300
  }
8123
8301
  const timescale = track["timescale"];
8124
8302
  const groupDurationMs = track["groupDurationMs"];
8125
- const groupDurationTicks = track["groupDurationTicks"];
8303
+ const groupDurationTicks2 = track["groupDurationTicks"];
8126
8304
  const keyframeIntervalMs = track["keyframeIntervalMs"];
8127
8305
  const keyframeIntervalTicks = track["keyframeIntervalTicks"];
8128
8306
  if (groupDurationMs !== void 0 && !positiveInteger(groupDurationMs)) {
8129
8307
  catalogError("track_group_duration_ms", `${path}.groupDurationMs`, "must be a positive integer");
8130
8308
  }
8131
- if (groupDurationTicks !== void 0 && !positiveInteger(groupDurationTicks)) {
8309
+ if (groupDurationTicks2 !== void 0 && !positiveInteger(groupDurationTicks2)) {
8132
8310
  catalogError("track_group_duration_ticks", `${path}.groupDurationTicks`, "must be a positive integer");
8133
8311
  }
8134
8312
  if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger(keyframeIntervalTicks)) {
@@ -8143,20 +8321,17 @@ var BlockcastMmt = (() => {
8143
8321
  catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
8144
8322
  }
8145
8323
  if (packaging === "mmtp") {
8146
- if (track["mmtpMode"] !== "mfu") {
8147
- catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
8148
- }
8149
8324
  if (!positiveInteger(timescale)) {
8150
8325
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
8151
8326
  }
8152
- if (groupDurationMs === void 0 && groupDurationTicks === void 0) {
8327
+ if (groupDurationMs === void 0 && groupDurationTicks2 === void 0) {
8153
8328
  catalogError(
8154
8329
  "track_group_duration_ms",
8155
8330
  path,
8156
8331
  "groupDurationMs or groupDurationTicks must be a positive integer"
8157
8332
  );
8158
8333
  }
8159
- if (groupDurationTicks === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8334
+ if (groupDurationTicks2 === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8160
8335
  catalogError("track_group_duration_exact", `${path}.groupDurationMs`, "does not resolve to an exact integer tick count");
8161
8336
  }
8162
8337
  }
@@ -8238,8 +8413,103 @@ var BlockcastMmt = (() => {
8238
8413
  }
8239
8414
  }
8240
8415
  validateArchive(catalog);
8416
+ dropRejectedMmtpTracks(catalog);
8241
8417
  return catalog;
8242
8418
  }
8419
+ function dropRejectedMmtpTracks(catalog) {
8420
+ const rejected = mmtpTrackIssues(catalog);
8421
+ if (rejected.length === 0) return;
8422
+ const tracks = catalog["tracks"];
8423
+ const rejectedIndexes = new Set(rejected.map((issue) => issue.index));
8424
+ const nameOf = (track) => track?.["name"];
8425
+ const mediaNames = new Set(tracks.filter((_, index) => !rejectedIndexes.has(index)).map(nameOf));
8426
+ const kept = tracks.filter((track, index) => {
8427
+ if (rejectedIndexes.has(index)) return false;
8428
+ const t = track;
8429
+ return !(t?.["packaging"] === "fec-repair" && typeof t["source"] === "string" && !mediaNames.has(t["source"]) && rejected.some((issue) => issue.name === t["source"]));
8430
+ });
8431
+ catalog["tracks"] = kept;
8432
+ const keptNames = new Set(kept.map(nameOf));
8433
+ const endpoints = catalog["multicast"]?.["endpoints"];
8434
+ if (Array.isArray(endpoints)) {
8435
+ for (const endpoint of endpoints) {
8436
+ const refs = endpoint?.["tracks"];
8437
+ if (!endpoint || !Array.isArray(refs)) continue;
8438
+ endpoint["tracks"] = refs.filter((ref) => keptNames.has(typeof ref === "object" ? nameOf(ref) : ref));
8439
+ }
8440
+ }
8441
+ Object.defineProperty(catalog, "rejectedTracks", { value: rejected, enumerable: false, configurable: true, writable: true });
8442
+ }
8443
+ function mmtpTrackIssues(catalog) {
8444
+ if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) return [];
8445
+ const tracks = catalog["tracks"];
8446
+ if (!Array.isArray(tracks)) return [];
8447
+ const records = tracks.filter(
8448
+ (track) => typeof track === "object" && track !== null && !Array.isArray(track)
8449
+ );
8450
+ const issues = [];
8451
+ const streamPaths = (track) => {
8452
+ const name = typeof track["name"] === "string" ? track["name"] : "";
8453
+ return [track, ...records.filter((repair) => repair["packaging"] === "fec-repair" && repair["source"] === name)].filter((declaring) => declaring["deliveryMode"] === "stream").map((declaring) => `$.tracks[${tracks.indexOf(declaring)}]`);
8454
+ };
8455
+ const candidatesOf = /* @__PURE__ */ new Map();
8456
+ const mirrorsOf = /* @__PURE__ */ new Map();
8457
+ for (const track of records) {
8458
+ if (track["packaging"] !== "mmtp" || track["mmtpMode"] !== "mfu-datagram") continue;
8459
+ const candidates = mmtpSiblingCandidates(records, track);
8460
+ candidatesOf.set(track, candidates);
8461
+ if (candidates.length === 1 && streamPaths(track).length === 0) {
8462
+ mirrorsOf.set(candidates[0], [...mirrorsOf.get(candidates[0]) ?? [], track]);
8463
+ }
8464
+ }
8465
+ for (const track of records) {
8466
+ const index = tracks.indexOf(track);
8467
+ const path = `$.tracks[${index}]`;
8468
+ const name = typeof track["name"] === "string" ? track["name"] : "";
8469
+ if (track["packaging"] !== "mmtp") continue;
8470
+ const mode = track["mmtpMode"];
8471
+ if (!isMmtpMode(mode)) {
8472
+ issues.push({
8473
+ code: "track_mmtp_mode",
8474
+ path: `${path}.mmtpMode`,
8475
+ message: `mmtpMode must be "mfu" or "mfu-datagram", got ${JSON.stringify(mode)}; a subscriber rejects the track (draft-ramadan-moq-mmt-02 13.1)`,
8476
+ name,
8477
+ index
8478
+ });
8479
+ continue;
8480
+ }
8481
+ if (mode !== "mfu-datagram") continue;
8482
+ const conflict = (at) => issues.push({
8483
+ code: "track_delivery_mode_conflict",
8484
+ path: `${at}.deliveryMode`,
8485
+ 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)`,
8486
+ name,
8487
+ index
8488
+ });
8489
+ const streams = streamPaths(track);
8490
+ for (const at of streams) conflict(at);
8491
+ const candidates = candidatesOf.get(track) ?? [];
8492
+ const rivals = candidates.length === 1 && streams.length === 0 ? (mirrorsOf.get(candidates[0]) ?? []).filter((other) => other !== track) : [];
8493
+ if (rivals.length > 0) {
8494
+ issues.push({
8495
+ code: "track_mmtp_sibling",
8496
+ path,
8497
+ 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)`,
8498
+ name,
8499
+ index
8500
+ });
8501
+ } else if (candidates.length !== 1) {
8502
+ issues.push({
8503
+ code: "track_mmtp_sibling",
8504
+ path,
8505
+ 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`,
8506
+ name,
8507
+ index
8508
+ });
8509
+ }
8510
+ }
8511
+ return issues;
8512
+ }
8243
8513
 
8244
8514
  // ../fec/dist/oti.js
8245
8515
  function catalogFecInterleaveMs(fec) {
@@ -8318,6 +8588,7 @@ var BlockcastMmt = (() => {
8318
8588
  const catalogFec = requireBoolean(evidence.catalogFec, "catalogFec");
8319
8589
  const bridgeAvailable = requireBoolean(evidence.bridgeAvailable, "bridgeAvailable");
8320
8590
  const multicastLegJoined = requireBoolean(evidence.multicastLegJoined, "multicastLegJoined");
8591
+ const datagramLegJoined = evidence.datagramLegJoined === void 0 ? false : requireBoolean(evidence.datagramLegJoined, "datagramLegJoined");
8321
8592
  const { transportPolicy, stats } = evidence;
8322
8593
  if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
8323
8594
  throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
@@ -8326,6 +8597,7 @@ var BlockcastMmt = (() => {
8326
8597
  throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
8327
8598
  }
8328
8599
  if (!catalogFec) return INACTIVE["no-catalog-fec"];
8600
+ if (datagramLegJoined) return { ...stats ?? {}, state: "active" };
8329
8601
  if (transportPolicy === "moq-only") return INACTIVE["reliable-moq"];
8330
8602
  if (!bridgeAvailable) return INACTIVE["no-multicast-bridge"];
8331
8603
  if (transportPolicy === "multicast-only" || multicastLegJoined) {
@@ -8334,6 +8606,9 @@ var BlockcastMmt = (() => {
8334
8606
  return INACTIVE["reliable-moq"];
8335
8607
  }
8336
8608
 
8609
+ // src/catalog-fec-params.ts
8610
+ var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
8611
+
8337
8612
  // src/held-layer-admission.ts
8338
8613
  var HORIZON_CAP = 1073741824;
8339
8614
  function heldLayerAnchorHorizon(retentionBlocks, k) {
@@ -10297,12 +10572,12 @@ var BlockcastMmt = (() => {
10297
10572
  return Number.isInteger(value) && value >= 0 && value <= 65535;
10298
10573
  }
10299
10574
  function parseIpv4(address) {
10300
- const fields = address.split(".");
10301
- if (fields.length !== 4 || fields.some((field) => !/^\d+$/.test(field))) {
10575
+ const fields2 = address.split(".");
10576
+ if (fields2.length !== 4 || fields2.some((field) => !/^\d+$/.test(field))) {
10302
10577
  throw new Error(`invalid IPv4 address ${address}`);
10303
10578
  }
10304
- const values = fields.map(Number);
10305
- if (values.some((value, index) => value > 255 || String(value) !== fields[index])) {
10579
+ const values = fields2.map(Number);
10580
+ if (values.some((value, index) => value > 255 || String(value) !== fields2[index])) {
10306
10581
  throw new Error(`invalid IPv4 address ${address}`);
10307
10582
  }
10308
10583
  return Uint8Array.from(values);
@@ -10516,7 +10791,7 @@ var BlockcastMmt = (() => {
10516
10791
  return len;
10517
10792
  }
10518
10793
  var bitMask = (n) => (_1n << BigInt(n)) - _1n;
10519
- function _validateObject(object, fields, optFields = {}) {
10794
+ function _validateObject(object, fields2, optFields = {}) {
10520
10795
  if (!object || typeof object !== "object")
10521
10796
  throw new Error("expected valid options object");
10522
10797
  function checkField(fieldName, expectedType, isOpt) {
@@ -10527,7 +10802,7 @@ var BlockcastMmt = (() => {
10527
10802
  if (current !== expectedType || val === null)
10528
10803
  throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
10529
10804
  }
10530
- Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
10805
+ Object.entries(fields2).forEach(([k, v]) => checkField(k, v, false));
10531
10806
  Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
10532
10807
  }
10533
10808
  var notImplemented = () => {