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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +5 -2
  2. package/dist/block-policy.d.ts +88 -16
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +164 -56
  5. package/dist/block-policy.js.map +3 -3
  6. package/dist/browser-runtime.js +2163 -303
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +40 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +163 -10
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +48 -1
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.js +34 -0
  17. package/dist/catalog-network-source.js.map +3 -3
  18. package/dist/cmaf-block-assembler.js +92 -1
  19. package/dist/cmaf-block-assembler.js.map +2 -2
  20. package/dist/codec-utils.d.ts.map +1 -1
  21. package/dist/codec-utils.js +92 -1
  22. package/dist/codec-utils.js.map +2 -2
  23. package/dist/delivery-catalog.js +68 -0
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/delta-fallback-config.js +39 -1
  26. package/dist/delta-fallback-config.js.map +4 -4
  27. package/dist/fec-manager.d.ts +222 -21
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +875 -131
  30. package/dist/fec-manager.js.map +4 -4
  31. package/dist/fec-state.d.ts +17 -5
  32. package/dist/fec-state.d.ts.map +1 -1
  33. package/dist/fec-state.js +41 -1
  34. package/dist/fec-state.js.map +3 -3
  35. package/dist/fec-worker-setup.js +34 -0
  36. package/dist/fec-worker-setup.js.map +3 -3
  37. package/dist/held-layer-admission.js +34 -0
  38. package/dist/held-layer-admission.js.map +3 -3
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +9 -1
  42. package/dist/index.js.map +2 -2
  43. package/dist/iso-block-locator.d.ts +55 -13
  44. package/dist/iso-block-locator.d.ts.map +1 -1
  45. package/dist/iso-block-locator.js +142 -25
  46. package/dist/iso-block-locator.js.map +3 -3
  47. package/dist/media-router.js.map +1 -1
  48. package/dist/mfu-reassembler.js +34 -0
  49. package/dist/mfu-reassembler.js.map +3 -3
  50. package/dist/mmtp-container-parser.d.ts +72 -10
  51. package/dist/mmtp-container-parser.d.ts.map +1 -1
  52. package/dist/mmtp-container-parser.js +260 -18
  53. package/dist/mmtp-container-parser.js.map +3 -3
  54. package/dist/mmtp-container-parser.no-modules.js +411 -34
  55. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  56. package/dist/mmtp-decode-pipeline.js +260 -18
  57. package/dist/mmtp-decode-pipeline.js.map +3 -3
  58. package/dist/mmtp-fec-session.js +34 -0
  59. package/dist/mmtp-fec-session.js.map +3 -3
  60. package/dist/mmtp-mode-selection.d.ts +48 -0
  61. package/dist/mmtp-mode-selection.d.ts.map +1 -0
  62. package/dist/mmtp-mode-selection.js +79 -0
  63. package/dist/mmtp-mode-selection.js.map +7 -0
  64. package/dist/mmtp-router.d.ts +94 -16
  65. package/dist/mmtp-router.d.ts.map +1 -1
  66. package/dist/mmtp-router.js +754 -78
  67. package/dist/mmtp-router.js.map +4 -4
  68. package/dist/multicast-auth-catalog.js +42 -2
  69. package/dist/multicast-auth-catalog.js.map +3 -3
  70. package/dist/multicast-input.js +42 -2
  71. package/dist/multicast-input.js.map +3 -3
  72. package/dist/multicast-manager.d.ts +121 -4
  73. package/dist/multicast-manager.d.ts.map +1 -1
  74. package/dist/multicast-manager.js +1774 -248
  75. package/dist/multicast-manager.js.map +4 -4
  76. package/dist/multicast-transport.js +70 -2
  77. package/dist/multicast-transport.js.map +4 -4
  78. package/dist/multicast-unwrap.js +34 -0
  79. package/dist/multicast-unwrap.js.map +3 -3
  80. package/dist/no-modules.d.ts +1 -0
  81. package/dist/no-modules.d.ts.map +1 -1
  82. package/dist/no-modules.js +415 -35
  83. package/dist/no-modules.js.map +4 -4
  84. package/dist/phase14-catalog-override.d.ts +2 -1
  85. package/dist/phase14-catalog-override.d.ts.map +1 -1
  86. package/dist/phase14-catalog-override.js +69 -2
  87. package/dist/phase14-catalog-override.js.map +3 -3
  88. package/dist/repair-fetch.d.ts +38 -8
  89. package/dist/repair-fetch.d.ts.map +1 -1
  90. package/dist/repair-fetch.js +336 -27
  91. package/dist/repair-fetch.js.map +3 -3
  92. package/dist/repair-layer-subscriptions.js +34 -0
  93. package/dist/repair-layer-subscriptions.js.map +3 -3
  94. package/dist/signaling.js +34 -0
  95. package/dist/signaling.js.map +3 -3
  96. package/dist/timestamp-codec.js +34 -0
  97. package/dist/timestamp-codec.js.map +3 -3
  98. package/dist/track-session.d.ts.map +1 -1
  99. package/dist/track-session.js +1 -0
  100. package/dist/track-session.js.map +2 -2
  101. package/dist/wasm-mfu-reassembler.js +34 -0
  102. package/dist/wasm-mfu-reassembler.js.map +3 -3
  103. package/dist/wasm-mmtp-container-parser.js +260 -18
  104. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  105. package/package.json +5 -5
  106. package/schemas/catalog.schema.json +2 -2
  107. package/src/block-policy.ts +324 -83
  108. package/src/carp-catalog.ts +165 -5
  109. package/src/catalog-fec-params.ts +1 -0
  110. package/src/codec-utils.ts +121 -1
  111. package/src/fec-manager.ts +835 -66
  112. package/src/fec-state.ts +21 -5
  113. package/src/index.ts +25 -0
  114. package/src/iso-block-locator.ts +148 -31
  115. package/src/mmtp-container-parser.ts +259 -24
  116. package/src/mmtp-mode-selection.ts +80 -0
  117. package/src/mmtp-router.ts +774 -86
  118. package/src/multicast-manager.ts +262 -16
  119. package/src/no-modules.ts +3 -0
  120. package/src/phase14-catalog-override.ts +14 -3
  121. package/src/repair-fetch.ts +389 -50
  122. package/src/track-session.ts +3 -0
  123. package/test-vectors/catalog/README.md +36 -2
  124. package/test-vectors/catalog/mmtp-siblings/ambiguous-sibling.json +158 -0
  125. package/test-vectors/catalog/mmtp-siblings/ladder-bitrate-only.json +231 -0
  126. package/test-vectors/catalog/mmtp-siblings/ladder-four-rungs.json +405 -0
  127. package/test-vectors/catalog/mmtp-siblings/ladder-other-names.json +231 -0
  128. package/test-vectors/catalog/mmtp-siblings/mmtp-mode-unknown.json +143 -0
  129. package/test-vectors/catalog/mmtp-siblings/multicast-endpoint-lists-datagram-track.json +143 -0
  130. package/test-vectors/catalog/mmtp-siblings/no-sibling.json +79 -0
  131. package/test-vectors/catalog/mmtp-siblings/rendition-mismatch.json +143 -0
  132. package/test-vectors/catalog/mmtp-siblings/stream-delivery-mode.json +143 -0
  133. package/test-vectors/catalog/mmtp-siblings/timescale-mismatch.json +143 -0
  134. package/test-vectors/catalog/mmtp-siblings/valid-pair.json +142 -0
  135. package/test-vectors/catalog/section-codes.json +3 -3
  136. package/test-vectors/catalog-validation.json +266 -7
  137. package/test-vectors/moq/mmtp-mode-selection.json +259 -0
@@ -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]);
@@ -6005,7 +6170,10 @@ var BlockcastMmt = (() => {
6005
6170
  function ssIdAfter(a, b) {
6006
6171
  return (a - b | 0) > 0;
6007
6172
  }
6008
- var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, release_fn;
6173
+ function holdsRebuilt(stream) {
6174
+ return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
6175
+ }
6176
+ var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, drainLoop_fn, unrepairableWaitOver_fn, cursorPassed_fn, release_fn;
6009
6177
  var FecReleaseSequencer = class {
6010
6178
  constructor(gate, emit, recordStat) {
6011
6179
  __privateAdd(this, _FecReleaseSequencer_instances);
@@ -6065,6 +6233,7 @@ var BlockcastMmt = (() => {
6065
6233
  stream.lastSbn = void 0;
6066
6234
  stream.discontinuity = false;
6067
6235
  stream.rapSsId = void 0;
6236
+ stream.sourced = false;
6068
6237
  }
6069
6238
  if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
6070
6239
  __privateGet(this, _recordStat2).call(this, "droppedStale");
@@ -6091,6 +6260,7 @@ var BlockcastMmt = (() => {
6091
6260
  if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
6092
6261
  else hi = mid;
6093
6262
  }
6263
+ if (stream.buf[lo]?.passed === true) frame.passed = true;
6094
6264
  stream.buf.splice(lo, 0, frame);
6095
6265
  __privateMethod(this, _FecReleaseSequencer_instances, drainUnlessDeferred_fn).call(this, stream);
6096
6266
  }
@@ -6126,6 +6296,41 @@ var BlockcastMmt = (() => {
6126
6296
  }
6127
6297
  return false;
6128
6298
  }
6299
+ /**
6300
+ * These streams' sink is being replaced by one that has seen no source
6301
+ * frame yet. First, from a stream that holds a frame the overlay rebuilt,
6302
+ * release to the sink being replaced the frames the unanchored path had
6303
+ * already released to it (#cursorPassed): there they waited in its queue,
6304
+ * which its replacement flushes. A stream that holds none is not drained:
6305
+ * it holds nothing the anchor kept back, and a drain would still force out
6306
+ * a frame held past the hold limit, which before the anchor waited for the
6307
+ * next push. Then treat the streams as unsourced until a source frame is
6308
+ * released.
6309
+ */
6310
+ unsource(packetId, catalogTrackName) {
6311
+ for (const stream of __privateGet(this, _streams2).values()) {
6312
+ if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
6313
+ if (stream.draining === 0 && holdsRebuilt(stream)) {
6314
+ if (__privateGet(this, _deferDepth) > 0) __privateGet(this, _deferredStreams).add(stream);
6315
+ else __privateMethod(this, _FecReleaseSequencer_instances, drain_fn).call(this, stream, true);
6316
+ }
6317
+ stream.sourced = false;
6318
+ }
6319
+ }
6320
+ }
6321
+ /**
6322
+ * Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
6323
+ * (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
6324
+ * packetId.
6325
+ */
6326
+ holdsRebuilt(packetId, catalogTrackName) {
6327
+ for (const stream of __privateGet(this, _streams2).values()) {
6328
+ if (stream.packetId !== packetId) continue;
6329
+ if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
6330
+ if (holdsRebuilt(stream)) return true;
6331
+ }
6332
+ return false;
6333
+ }
6129
6334
  /** Re-evaluate held gaps after FEC state changed. */
6130
6335
  poke(streamKey) {
6131
6336
  if (streamKey !== void 0) {
@@ -6229,16 +6434,32 @@ var BlockcastMmt = (() => {
6229
6434
  last: null,
6230
6435
  lastSbn: void 0,
6231
6436
  discontinuity: false,
6232
- rapSsId: void 0
6437
+ rapSsId: void 0,
6438
+ sourced: false,
6439
+ draining: 0
6233
6440
  };
6234
6441
  __privateGet(this, _streams2).set(streamKey, stream);
6235
6442
  }
6236
6443
  return stream;
6237
6444
  };
6238
- drain_fn = function(stream) {
6445
+ /** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
6446
+ drain_fn = function(stream, asUnanchored = false) {
6447
+ stream.draining++;
6448
+ try {
6449
+ __privateMethod(this, _FecReleaseSequencer_instances, drainLoop_fn).call(this, stream, asUnanchored);
6450
+ } finally {
6451
+ stream.draining--;
6452
+ }
6453
+ };
6454
+ drainLoop_fn = function(stream, asUnanchored) {
6239
6455
  while (stream.buf.length > 0 && stream.last !== null) {
6240
6456
  const head = stream.buf[0];
6241
6457
  const last = stream.last;
6458
+ if (compareFrameOrder(head, last) <= 0) {
6459
+ stream.buf.shift();
6460
+ __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, void 0);
6461
+ continue;
6462
+ }
6242
6463
  if (stream.discontinuity) {
6243
6464
  stream.discontinuity = false;
6244
6465
  stream.buf.shift();
@@ -6252,9 +6473,10 @@ var BlockcastMmt = (() => {
6252
6473
  }
6253
6474
  const headSbn = head.meta.fecSbn;
6254
6475
  const from = stream.lastSbn ?? headSbn;
6255
- const to = headSbn ?? stream.lastSbn;
6476
+ const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
6256
6477
  let lost = [];
6257
6478
  const unanchored = from === void 0 && to === void 0;
6479
+ let unresolved = false;
6258
6480
  if (from !== void 0 && to !== void 0) {
6259
6481
  const resolved = __privateGet(this, _gate).resolvedLoss(
6260
6482
  stream.packetId,
@@ -6263,7 +6485,8 @@ var BlockcastMmt = (() => {
6263
6485
  Math.max(from, to),
6264
6486
  from
6265
6487
  );
6266
- if (resolved === null) {
6488
+ unresolved = resolved === null;
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)) {
6267
6490
  const heldMs = performance.now() - head.arrivedAtMs;
6268
6491
  if (heldMs <= __privateGet(this, _gate).holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
6269
6492
  __privateGet(this, _recordStat2).call(this, "forcedWindowFlushes");
@@ -6271,18 +6494,65 @@ var BlockcastMmt = (() => {
6271
6494
  __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, __privateGet(this, _gate).decide(last, head, [], true));
6272
6495
  continue;
6273
6496
  }
6274
- lost = resolved;
6497
+ lost = resolved ?? [];
6275
6498
  }
6276
6499
  stream.buf.shift();
6277
- __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? __privateGet(this, _gate).decide(last, head, lost, false) : void 0);
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);
6278
6501
  }
6279
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
+ };
6516
+ /**
6517
+ * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
6518
+ * source cursor holds it unanchored, and neither does a later frame behind
6519
+ * it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
6520
+ * fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
6521
+ * like each frame that arrived in front of it since (stale there). The head
6522
+ * then goes, decided as it would be unanchored, once a frame the base path
6523
+ * delivered (a source frame, or one base FEC recovered) is buffered after a
6524
+ * marked one: the base path has passed that one, so a frame still missing
6525
+ * before it can only come from a repair. It also goes while no source frame
6526
+ * has been released, when the direct path shows a recovered frame at once.
6527
+ * And it goes at once while a staged switch decides on when frames arrive
6528
+ * (FecReleaseGate.releaseUnanchored), and when unsource releases into a
6529
+ * sink being replaced: unanchored, it had already reached the sink.
6530
+ * The scan also writes: the `passed` marks it sets stay on the frames,
6531
+ * and push marks a frame it inserts in front of a marked one from them.
6532
+ */
6533
+ cursorPassed_fn = function(stream, asUnanchored) {
6534
+ let at = -1;
6535
+ for (let i = 0; i < stream.buf.length; i++) {
6536
+ const frame = stream.buf[i];
6537
+ if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
6538
+ frame.passed = true;
6539
+ if (at < 0) at = i;
6540
+ } else if (frame.passed !== true) break;
6541
+ }
6542
+ if (at < 0) return false;
6543
+ return asUnanchored || !stream.sourced || __privateGet(this, _gate).releaseUnanchored?.(stream.packetId, stream.catalogTrackName) === true || stream.buf.some(({ meta }, i) => i > at && meta.fecSbnFirst === void 0 && (meta.recovered !== true || meta.fecSbn !== void 0));
6544
+ };
6280
6545
  release_fn = function(stream, frame, decision) {
6546
+ const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
6547
+ if (stale) __privateGet(this, _recordStat2).call(this, "droppedStale");
6281
6548
  if (decision) frame.meta.gapBefore = decision;
6282
6549
  stream.last = frame;
6283
- if (frame.meta.fecSbn !== void 0) stream.lastSbn = frame.meta.fecSbn;
6550
+ if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
6551
+ stream.lastSbn = frame.meta.fecSbn;
6552
+ }
6553
+ if (frame.meta.recovered !== true) stream.sourced = true;
6284
6554
  __privateGet(this, _gate).onReleased?.(frame.data, frame.meta);
6285
- __privateGet(this, _emit2).call(this, frame.data, frame.meta);
6555
+ if (!stale) __privateGet(this, _emit2).call(this, frame.data, frame.meta);
6286
6556
  };
6287
6557
  var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
6288
6558
  function isFmp4Box(data) {
@@ -6460,11 +6730,12 @@ var BlockcastMmt = (() => {
6460
6730
  /**
6461
6731
  * Typed view of the ISO-BMFF timing-sample budget.
6462
6732
  *
6463
- * This is the acceptance signal for the budget ratchet: `pending` walking
6464
- * to `capacity` while `rejectedMovieFragments` climbs is the stream wedging,
6465
- * and it is observable here rather than only as media silently stopping.
6466
- * Per repo policy this is a producer-owned counter -- never infer budget
6467
- * state by parsing logs.
6733
+ * Each stream admits timing against its own window of `capacity` slots
6734
+ * (BLO-52085). A stream at capacity displaces its own oldest timing to
6735
+ * admit the moof in hand, and `evicted` counts the slots so displaced:
6736
+ * timing a stream declared and never delivered shows up there. `pending`
6737
+ * sums every stream, so it can exceed `capacity`. Per repo policy this is
6738
+ * a producer-owned counter -- never infer budget state by parsing logs.
6468
6739
  */
6469
6740
  get timingBudgetStats() {
6470
6741
  return {
@@ -6524,6 +6795,14 @@ var BlockcastMmt = (() => {
6524
6795
  fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
6525
6796
  return __privateGet(this, _fecSequencer)?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
6526
6797
  }
6798
+ /** See FecReleaseSequencer.unsource. */
6799
+ unsourceFecRelease(packetId, catalogTrackName) {
6800
+ __privateGet(this, _fecSequencer)?.unsource(packetId, catalogTrackName);
6801
+ }
6802
+ /** See FecReleaseSequencer.holdsRebuilt. */
6803
+ fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
6804
+ return __privateGet(this, _fecSequencer)?.holdsRebuilt(packetId, catalogTrackName) ?? false;
6805
+ }
6527
6806
  /** Re-evaluate held gaps after FEC block state changed. */
6528
6807
  pokeFecRelease(packetId, catalogTrackName) {
6529
6808
  if (!__privateGet(this, _fecSequencer)) return;
@@ -7080,7 +7359,7 @@ var BlockcastMmt = (() => {
7080
7359
  if (!resolver2?.initialized) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "fragment-no-resolver");
7081
7360
  const pendingBefore = resolver2.pendingSampleCount;
7082
7361
  const evictedBefore = resolver2.evictedSampleCount;
7083
- const remaining = __privateGet(this, _maxPendingTimingSamples) - __privateGet(this, _pendingTimingSamples);
7362
+ const remaining = __privateGet(this, _maxPendingTimingSamples) - resolver2.pendingSampleCount;
7084
7363
  const admitted = resolver2.addMovieFragment(
7085
7364
  mpu.mpuSequenceNumber,
7086
7365
  data,
@@ -7148,7 +7427,7 @@ var BlockcastMmt = (() => {
7148
7427
  headTiming.size
7149
7428
  );
7150
7429
  if (readyOnRegister) {
7151
- const deferred = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, readyOnRegister, info, resolver, options?.recovered === true, options?.fecSbn);
7430
+ const deferred = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, readyOnRegister, info, resolver, options?.recovered === true, options?.fecSbn, options?.fecSbnFirst);
7152
7431
  if (deferred.record === void 0) __privateMethod(this, _MmtpContainerParser_instances, countDeferredOutcome_fn).call(this, deferred.reason);
7153
7432
  }
7154
7433
  }
@@ -7235,7 +7514,7 @@ var BlockcastMmt = (() => {
7235
7514
  fragmentCounter: mpu.fragmentCounter
7236
7515
  };
7237
7516
  }
7238
- const outcome = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, combined, info, resolver, options?.recovered === true, options?.fecSbn);
7517
+ const outcome = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, combined, info, resolver, options?.recovered === true, options?.fecSbn, options?.fecSbnFirst);
7239
7518
  if (outcome.record !== void 0) return outcome.record;
7240
7519
  return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, outcome.reason);
7241
7520
  };
@@ -7254,7 +7533,7 @@ var BlockcastMmt = (() => {
7254
7533
  * attribution exists to keep readable. Leaving the choice at the call site
7255
7534
  * is what keeps both true.
7256
7535
  */
7257
- emitCombinedSample_fn = function(combined, info, resolver, recovered, fecSbn) {
7536
+ emitCombinedSample_fn = function(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
7258
7537
  const timing = resolver.sampleTiming(
7259
7538
  combined.mpuSequenceNumber,
7260
7539
  combined.movieFragmentSequenceNumber,
@@ -7265,6 +7544,7 @@ var BlockcastMmt = (() => {
7265
7544
  const meta = __privateMethod(this, _MmtpContainerParser_instances, buildFrameMeta_fn).call(this, combined, info.packetId, info.sequenceNumber, timing, recovered);
7266
7545
  if (!meta) return { reason: "combined-meta-build-failed" };
7267
7546
  if (fecSbn !== void 0) meta.fecSbn = fecSbn;
7547
+ if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
7268
7548
  if (!resolver.consumeSample(
7269
7549
  combined.mpuSequenceNumber,
7270
7550
  combined.movieFragmentSequenceNumber,
@@ -8020,13 +8300,13 @@ var BlockcastMmt = (() => {
8020
8300
  }
8021
8301
  const timescale = track["timescale"];
8022
8302
  const groupDurationMs = track["groupDurationMs"];
8023
- const groupDurationTicks = track["groupDurationTicks"];
8303
+ const groupDurationTicks2 = track["groupDurationTicks"];
8024
8304
  const keyframeIntervalMs = track["keyframeIntervalMs"];
8025
8305
  const keyframeIntervalTicks = track["keyframeIntervalTicks"];
8026
8306
  if (groupDurationMs !== void 0 && !positiveInteger(groupDurationMs)) {
8027
8307
  catalogError("track_group_duration_ms", `${path}.groupDurationMs`, "must be a positive integer");
8028
8308
  }
8029
- if (groupDurationTicks !== void 0 && !positiveInteger(groupDurationTicks)) {
8309
+ if (groupDurationTicks2 !== void 0 && !positiveInteger(groupDurationTicks2)) {
8030
8310
  catalogError("track_group_duration_ticks", `${path}.groupDurationTicks`, "must be a positive integer");
8031
8311
  }
8032
8312
  if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger(keyframeIntervalTicks)) {
@@ -8041,20 +8321,17 @@ var BlockcastMmt = (() => {
8041
8321
  catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
8042
8322
  }
8043
8323
  if (packaging === "mmtp") {
8044
- if (track["mmtpMode"] !== "mfu") {
8045
- catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
8046
- }
8047
8324
  if (!positiveInteger(timescale)) {
8048
8325
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
8049
8326
  }
8050
- if (groupDurationMs === void 0 && groupDurationTicks === void 0) {
8327
+ if (groupDurationMs === void 0 && groupDurationTicks2 === void 0) {
8051
8328
  catalogError(
8052
8329
  "track_group_duration_ms",
8053
8330
  path,
8054
8331
  "groupDurationMs or groupDurationTicks must be a positive integer"
8055
8332
  );
8056
8333
  }
8057
- if (groupDurationTicks === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8334
+ if (groupDurationTicks2 === void 0 && BigInt(groupDurationMs) * BigInt(timescale) % 1000n !== 0n) {
8058
8335
  catalogError("track_group_duration_exact", `${path}.groupDurationMs`, "does not resolve to an exact integer tick count");
8059
8336
  }
8060
8337
  }
@@ -8136,8 +8413,103 @@ var BlockcastMmt = (() => {
8136
8413
  }
8137
8414
  }
8138
8415
  validateArchive(catalog);
8416
+ dropRejectedMmtpTracks(catalog);
8139
8417
  return catalog;
8140
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
+ }
8141
8513
 
8142
8514
  // ../fec/dist/oti.js
8143
8515
  function catalogFecInterleaveMs(fec) {
@@ -8216,6 +8588,7 @@ var BlockcastMmt = (() => {
8216
8588
  const catalogFec = requireBoolean(evidence.catalogFec, "catalogFec");
8217
8589
  const bridgeAvailable = requireBoolean(evidence.bridgeAvailable, "bridgeAvailable");
8218
8590
  const multicastLegJoined = requireBoolean(evidence.multicastLegJoined, "multicastLegJoined");
8591
+ const datagramLegJoined = evidence.datagramLegJoined === void 0 ? false : requireBoolean(evidence.datagramLegJoined, "datagramLegJoined");
8219
8592
  const { transportPolicy, stats } = evidence;
8220
8593
  if (typeof transportPolicy !== "string" || !TRANSPORT_POLICIES.has(transportPolicy)) {
8221
8594
  throw new TypeError(`resolveFecState: unsupported transportPolicy ${JSON.stringify(transportPolicy)}`);
@@ -8224,6 +8597,7 @@ var BlockcastMmt = (() => {
8224
8597
  throw new TypeError("resolveFecState: stats must be a plain object, null or undefined");
8225
8598
  }
8226
8599
  if (!catalogFec) return INACTIVE["no-catalog-fec"];
8600
+ if (datagramLegJoined) return { ...stats ?? {}, state: "active" };
8227
8601
  if (transportPolicy === "moq-only") return INACTIVE["reliable-moq"];
8228
8602
  if (!bridgeAvailable) return INACTIVE["no-multicast-bridge"];
8229
8603
  if (transportPolicy === "multicast-only" || multicastLegJoined) {
@@ -8232,6 +8606,9 @@ var BlockcastMmt = (() => {
8232
8606
  return INACTIVE["reliable-moq"];
8233
8607
  }
8234
8608
 
8609
+ // src/catalog-fec-params.ts
8610
+ var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
8611
+
8235
8612
  // src/held-layer-admission.ts
8236
8613
  var HORIZON_CAP = 1073741824;
8237
8614
  function heldLayerAnchorHorizon(retentionBlocks, k) {
@@ -10195,12 +10572,12 @@ var BlockcastMmt = (() => {
10195
10572
  return Number.isInteger(value) && value >= 0 && value <= 65535;
10196
10573
  }
10197
10574
  function parseIpv4(address) {
10198
- const fields = address.split(".");
10199
- 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))) {
10200
10577
  throw new Error(`invalid IPv4 address ${address}`);
10201
10578
  }
10202
- const values = fields.map(Number);
10203
- 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])) {
10204
10581
  throw new Error(`invalid IPv4 address ${address}`);
10205
10582
  }
10206
10583
  return Uint8Array.from(values);
@@ -10414,7 +10791,7 @@ var BlockcastMmt = (() => {
10414
10791
  return len;
10415
10792
  }
10416
10793
  var bitMask = (n) => (_1n << BigInt(n)) - _1n;
10417
- function _validateObject(object, fields, optFields = {}) {
10794
+ function _validateObject(object, fields2, optFields = {}) {
10418
10795
  if (!object || typeof object !== "object")
10419
10796
  throw new Error("expected valid options object");
10420
10797
  function checkField(fieldName, expectedType, isOpt) {
@@ -10425,7 +10802,7 @@ var BlockcastMmt = (() => {
10425
10802
  if (current !== expectedType || val === null)
10426
10803
  throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
10427
10804
  }
10428
- Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
10805
+ Object.entries(fields2).forEach(([k, v]) => checkField(k, v, false));
10429
10806
  Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
10430
10807
  }
10431
10808
  var notImplemented = () => {