@blockcast/mmt-container 2.2.0-main.a88c3a0aa4f3 → 2.2.0-main.aee8d33d2cc8

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 (118) hide show
  1. package/README.md +34 -19
  2. package/dist/block-policy.d.ts +55 -13
  3. package/dist/block-policy.d.ts.map +1 -1
  4. package/dist/block-policy.js +104 -32
  5. package/dist/block-policy.js.map +2 -2
  6. package/dist/browser-runtime.js +2094 -385
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.js.map +2 -2
  9. package/dist/catalog-fec-params.d.ts +18 -2
  10. package/dist/catalog-fec-params.d.ts.map +1 -1
  11. package/dist/catalog-fec-params.js +29 -1
  12. package/dist/catalog-fec-params.js.map +2 -2
  13. package/dist/catalog-network-source.js.map +2 -2
  14. package/dist/cmaf-block-assembler.js +92 -1
  15. package/dist/cmaf-block-assembler.js.map +2 -2
  16. package/dist/cmcd-producer.d.ts +60 -47
  17. package/dist/cmcd-producer.d.ts.map +1 -1
  18. package/dist/cmcd-producer.js +138 -109
  19. package/dist/cmcd-producer.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 +26 -16
  24. package/dist/delivery-catalog.js.map +2 -2
  25. package/dist/delta-fallback-config.js +5 -1
  26. package/dist/delta-fallback-config.js.map +3 -3
  27. package/dist/fec-manager.d.ts +114 -15
  28. package/dist/fec-manager.d.ts.map +1 -1
  29. package/dist/fec-manager.js +639 -95
  30. package/dist/fec-manager.js.map +2 -2
  31. package/dist/fec-state.js +5 -1
  32. package/dist/fec-state.js.map +2 -2
  33. package/dist/fec-worker-setup.d.ts +1 -1
  34. package/dist/fec-worker-setup.js +1 -1
  35. package/dist/fec-worker-setup.js.map +2 -2
  36. package/dist/held-layer-admission.js.map +2 -2
  37. package/dist/index.d.ts +6 -5
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +12 -2
  40. package/dist/index.js.map +2 -2
  41. package/dist/iso-block-locator.d.ts +48 -13
  42. package/dist/iso-block-locator.d.ts.map +1 -1
  43. package/dist/iso-block-locator.js +97 -25
  44. package/dist/iso-block-locator.js.map +2 -2
  45. package/dist/iso-bmff-timing.d.ts +10 -1
  46. package/dist/iso-bmff-timing.d.ts.map +1 -1
  47. package/dist/iso-bmff-timing.js +36 -2
  48. package/dist/iso-bmff-timing.js.map +2 -2
  49. package/dist/media-router.js.map +1 -1
  50. package/dist/mfu-reassembler.js +12 -19
  51. package/dist/mfu-reassembler.js.map +2 -2
  52. package/dist/mmtp-container-parser.d.ts +106 -12
  53. package/dist/mmtp-container-parser.d.ts.map +1 -1
  54. package/dist/mmtp-container-parser.js +324 -46
  55. package/dist/mmtp-container-parser.js.map +2 -2
  56. package/dist/mmtp-container-parser.no-modules.js +466 -66
  57. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  58. package/dist/mmtp-decode-pipeline.js +323 -46
  59. package/dist/mmtp-decode-pipeline.js.map +2 -2
  60. package/dist/mmtp-fec-session.d.ts +41 -3
  61. package/dist/mmtp-fec-session.d.ts.map +1 -1
  62. package/dist/mmtp-fec-session.js +118 -13
  63. package/dist/mmtp-fec-session.js.map +3 -3
  64. package/dist/mmtp-router.d.ts +36 -8
  65. package/dist/mmtp-router.d.ts.map +1 -1
  66. package/dist/mmtp-router.js +716 -100
  67. package/dist/mmtp-router.js.map +3 -3
  68. package/dist/multicast-auth-catalog.js.map +2 -2
  69. package/dist/multicast-input.js.map +2 -2
  70. package/dist/multicast-manager.d.ts +28 -3
  71. package/dist/multicast-manager.d.ts.map +1 -1
  72. package/dist/multicast-manager.js +1451 -215
  73. package/dist/multicast-manager.js.map +3 -3
  74. package/dist/multicast-transport.js +28 -18
  75. package/dist/multicast-transport.js.map +2 -2
  76. package/dist/multicast-unwrap.js +12 -19
  77. package/dist/multicast-unwrap.js.map +2 -2
  78. package/dist/no-modules.d.ts +1 -0
  79. package/dist/no-modules.d.ts.map +1 -1
  80. package/dist/no-modules.js +463 -64
  81. package/dist/no-modules.js.map +4 -4
  82. package/dist/repair-fetch.d.ts +38 -8
  83. package/dist/repair-fetch.d.ts.map +1 -1
  84. package/dist/repair-fetch.js +286 -27
  85. package/dist/repair-fetch.js.map +3 -3
  86. package/dist/repair-layer-subscriptions.d.ts +82 -0
  87. package/dist/repair-layer-subscriptions.d.ts.map +1 -0
  88. package/dist/repair-layer-subscriptions.js +192 -0
  89. package/dist/repair-layer-subscriptions.js.map +7 -0
  90. package/dist/signaling.js.map +2 -2
  91. package/dist/timestamp-codec.js +12 -19
  92. package/dist/timestamp-codec.js.map +2 -2
  93. package/dist/track-session.d.ts +1 -1
  94. package/dist/track-session.d.ts.map +1 -1
  95. package/dist/track-session.js +1 -0
  96. package/dist/track-session.js.map +2 -2
  97. package/dist/wasm-mfu-reassembler.js.map +2 -2
  98. package/dist/wasm-mmtp-container-parser.js +323 -46
  99. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  100. package/package.json +8 -5
  101. package/schemas/catalog.schema.json +4 -0
  102. package/src/block-policy.ts +216 -52
  103. package/src/catalog-fec-params.ts +37 -1
  104. package/src/cmcd-producer.ts +189 -179
  105. package/src/codec-utils.ts +121 -1
  106. package/src/fec-manager.ts +619 -37
  107. package/src/fec-worker-setup.ts +2 -2
  108. package/src/index.ts +22 -2
  109. package/src/iso-block-locator.ts +133 -31
  110. package/src/iso-bmff-timing.ts +40 -1
  111. package/src/mmtp-container-parser.ts +353 -32
  112. package/src/mmtp-fec-session.ts +115 -15
  113. package/src/mmtp-router.ts +618 -44
  114. package/src/multicast-manager.ts +139 -16
  115. package/src/no-modules.ts +3 -0
  116. package/src/repair-fetch.ts +366 -50
  117. package/src/repair-layer-subscriptions.ts +261 -0
  118. package/src/track-session.ts +4 -1
@@ -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
@@ -73,6 +75,8 @@ var BlockcastMmt = (() => {
73
75
  var PACKET_TYPE_REPAIR = 3;
74
76
  var MMTP_SIGNALING_PACKET_ID = 0;
75
77
  var MMTP_PACKET_ID_MAX = 65535;
78
+ var FEC_CODE_REED_SOLOMON = 1;
79
+ var FEC_CODE_RAPTORQ = 3;
76
80
  function parseMMTPHeader(buffer) {
77
81
  if (buffer.length < MMTP_HEADER_SIZE) {
78
82
  throw new Error(`MMTP packet too small: ${buffer.length} bytes`);
@@ -213,30 +217,26 @@ var BlockcastMmt = (() => {
213
217
  const authLength = view2.getUint16(2, false);
214
218
  return start + LEGACY_TRAILER_HEADER_SIZE + authLength === end;
215
219
  }
216
- function resolveDeclaredTrailers(payload, declaredEnd, fecType, options, rapFlag = false) {
220
+ function resolveDeclaredTrailers(payload, declaredEnd, fecType, options) {
217
221
  if (declaredEnd > payload.length)
218
222
  return null;
219
223
  if (options?.skipFecId) {
220
- return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false, hasOverlayFecId: false } : null;
224
+ return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false } : null;
221
225
  }
222
- const overlay = options?.overlayDeclared === true && rapFlag;
223
226
  if (fecType === 1) {
224
- const fecStart = payload.length - sourceFecTrailerSize(overlay);
227
+ const fecStart = payload.length - SOURCE_FEC_PAYLOAD_ID_SIZE;
225
228
  if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
226
229
  return null;
227
230
  }
228
- return { hasFecId: true, hasOverlayFecId: overlay };
231
+ return { hasFecId: true };
229
232
  }
230
- if (fecType !== 0 || overlay)
233
+ if (fecType !== 0)
231
234
  return null;
232
235
  if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
233
- return { hasFecId: false, hasOverlayFecId: false };
236
+ return { hasFecId: false };
234
237
  }
235
238
  return null;
236
239
  }
237
- function sourceFecTrailerSize(overlay) {
238
- return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE;
239
- }
240
240
  function planMfuExtraction(mmtpPacket, options, parsedHeader) {
241
241
  if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE) {
242
242
  return {
@@ -289,11 +289,11 @@ var BlockcastMmt = (() => {
289
289
  if ("rejection" in layoutResult)
290
290
  return layoutResult;
291
291
  const { layout } = layoutResult;
292
- const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options, header.rapFlag);
292
+ const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options);
293
293
  if (!trailerLayout) {
294
294
  if (!options?.skipFecId && header.fecType === 1) {
295
295
  const observed = payload.length - layout.dataEnd;
296
- const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag);
296
+ const expected = SOURCE_FEC_PAYLOAD_ID_SIZE;
297
297
  if (observed !== expected) {
298
298
  return {
299
299
  rejection: {
@@ -325,13 +325,10 @@ var BlockcastMmt = (() => {
325
325
  const mfuDuHeader = mfuDuHeaderPresent && mpu.timedFlag === 1 ? parseTimedMfuDuHeader(payload, MPU_HEADER_SIZE) : null;
326
326
  const itemId = mfuDuHeaderPresent && mpu.timedFlag === 0 ? new DataView(payload.buffer, payload.byteOffset + MPU_HEADER_SIZE, 4).getUint32(0, false) : null;
327
327
  const data = payload.subarray(mfuOffset, dataEnd);
328
- const trailerStart = mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId);
329
- const ssIdAt = (offset) => ({
330
- ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false)
331
- });
332
- const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null;
333
- const overlayFecPayloadId = trailerLayout.hasOverlayFecId ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE) : null;
334
- return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId };
328
+ const fecPayloadId = trailerLayout.hasFecId ? {
329
+ ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + mmtpPacket.length - SOURCE_FEC_PAYLOAD_ID_SIZE, 4).getUint32(0, false)
330
+ } : null;
331
+ return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId };
335
332
  }
336
333
  function sourceFecPayloadIdOf(mmtpPacket, header) {
337
334
  if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE)
@@ -423,6 +420,50 @@ var BlockcastMmt = (() => {
423
420
  var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
424
421
  var NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
425
422
 
423
+ // ../mmt-base/dist/signalling.js
424
+ var FEC_CODING_STRUCTURE_ONE_STAGE = 1;
425
+ var SSBG_MODE_1 = 1;
426
+ var RAPTORQ_MAX_SOURCE_SYMBOLS = 56403;
427
+ var REPAIR_SYMBOL_ID_MAX = 16777215;
428
+ var MIN_REPAIR_SYMBOL_SIZE = 14;
429
+ var REED_SOLOMON_MAX_BLOCK = 255;
430
+ function alFecRaptorQFlowConfig(flow) {
431
+ if (flow.fecCodingStructure !== FEC_CODING_STRUCTURE_ONE_STAGE || flow.repairFlows.length !== 1)
432
+ return null;
433
+ if (flow.ssbgMode !== SSBG_MODE_1 || flow.ffsrptsFlag !== 0 || flow.fecPayloadIdMode !== 0)
434
+ return null;
435
+ if (flow.packetIds.length !== 1)
436
+ return null;
437
+ const repair = flow.repairFlows[0];
438
+ const { fecCodeId, maximumK: k, maximumP: p } = repair;
439
+ const t = flow.repairSymbolSize;
440
+ if (t < MIN_REPAIR_SYMBOL_SIZE || k < 1 || p < 1 || k + p - 1 > REPAIR_SYMBOL_ID_MAX)
441
+ return null;
442
+ if (fecCodeId === FEC_CODE_RAPTORQ) {
443
+ if (t % 8 !== 0 || k > RAPTORQ_MAX_SOURCE_SYMBOLS)
444
+ return null;
445
+ } else if (fecCodeId === FEC_CODE_REED_SOLOMON) {
446
+ if (k + p > REED_SOLOMON_MAX_BLOCK)
447
+ return null;
448
+ } else {
449
+ return null;
450
+ }
451
+ if (repair.repairFlowId === MMTP_SIGNALING_PACKET_ID || repair.repairFlowId === flow.packetIds[0])
452
+ return null;
453
+ return {
454
+ sourcePacketIds: [...flow.packetIds],
455
+ repairFlowId: repair.repairFlowId,
456
+ fecCodeId,
457
+ ssbgMode: flow.ssbgMode,
458
+ fecPayloadIdMode: flow.fecPayloadIdMode,
459
+ repairSymbolSize: t,
460
+ maximumK: k,
461
+ maximumP: p,
462
+ protectionWindowTime: repair.protectionWindowTime,
463
+ protectionWindowSize: repair.protectionWindowSize
464
+ };
465
+ }
466
+
426
467
  // ../mmt-base/dist/serial-number.js
427
468
  var SERIAL32_SPAN = 4294967296;
428
469
  var SERIAL32_HALF = 2147483648;
@@ -919,13 +960,25 @@ var BlockcastMmt = (() => {
919
960
  });
920
961
  return { tracks, pointers };
921
962
  }
922
- function resolveFecBindings(catalog, receiver = RUNTIME_FEC_RECEIVER) {
963
+ function runtimeView(catalog, receiver) {
923
964
  const { tracks, pointers } = fecCatalogTracks(catalog);
924
965
  const report = validateFecCatalog({ tracks }, receiver);
925
966
  const at = (path) => {
926
967
  const m = /^\/tracks\/(\d+)(.*)$/.exec(path);
927
968
  return m ? pointers[Number(m[1])] + m[2] : path;
928
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);
929
982
  const trackAt = (i) => recordOf(tracks[i]) ?? {};
930
983
  const nameAt = (i) => i === null ? void 0 : trackAt(i)["name"];
931
984
  const why = (i) => Object.freeze({
@@ -4611,9 +4664,10 @@ var BlockcastMmt = (() => {
4611
4664
  const sliceType = readH264SliceType(nal);
4612
4665
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
4613
4666
  }
4667
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
4614
4668
  function readH264SliceType(nal) {
4615
4669
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4616
- const rbsp = removeEmulationPrevention(nal.subarray(1));
4670
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
4617
4671
  const state = { bitOffset: 0 };
4618
4672
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4619
4673
  return readUnsignedExpGolomb(rbsp, state);
@@ -4760,6 +4814,96 @@ var BlockcastMmt = (() => {
4760
4814
  ]))).toBe(false);
4761
4815
  });
4762
4816
  });
4817
+ describe("readH264SliceType", () => {
4818
+ const wholeNalSliceType = (nal) => {
4819
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4820
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
4821
+ const state = { bitOffset: 0 };
4822
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4823
+ return readUnsignedExpGolomb(rbsp, state);
4824
+ };
4825
+ const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
4826
+ const ue = (value) => {
4827
+ const code = (value + 1).toString(2);
4828
+ return "0".repeat(code.length - 1) + code;
4829
+ };
4830
+ const sliceNal = (bits) => {
4831
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
4832
+ const nal = [1];
4833
+ let zeros = 0;
4834
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
4835
+ if (zeros >= 2 && byte <= 3) {
4836
+ nal.push(3);
4837
+ zeros = 0;
4838
+ }
4839
+ nal.push(byte);
4840
+ zeros = byte === 0 ? zeros + 1 : 0;
4841
+ }
4842
+ return Uint8Array.from(nal);
4843
+ };
4844
+ const x264Slices = [
4845
+ ["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
4846
+ ["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
4847
+ ["64x48 non-IDR I", hex2(
4848
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
4849
+ ), 7, true],
4850
+ ["1280x720 B, escape at byte 10", hex2(
4851
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
4852
+ ), 6, false],
4853
+ ["1280x720 P, escape at byte 15", hex2(
4854
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
4855
+ ), 5, false],
4856
+ ["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
4857
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex2(
4858
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
4859
+ ), null, true],
4860
+ ["7680x4320 P, first_mb_in_slice 32640", hex2(
4861
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
4862
+ ), 5, false],
4863
+ ["7680x4320 P, first_mb_in_slice 97440", hex2(
4864
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
4865
+ ), 5, false]
4866
+ ];
4867
+ const syntheticSlices = [
4868
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
4869
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
4870
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
4871
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
4872
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
4873
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
4874
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
4875
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
4876
+ ];
4877
+ test("reads the slice_type of real and synthetic slices", () => {
4878
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
4879
+ expect(readH264SliceType(nal), name).toBe(sliceType);
4880
+ }
4881
+ });
4882
+ test("matches the whole-NAL unescape at every truncation", () => {
4883
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
4884
+ for (let end = 0; end <= nal.length; end++) {
4885
+ const cut = nal.subarray(0, end);
4886
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
4887
+ }
4888
+ }
4889
+ });
4890
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
4891
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
4892
+ let seed = 1;
4893
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
4894
+ for (let i = 0; i < 5e3; i++) {
4895
+ const nal = new Uint8Array(2 + next() % 63);
4896
+ nal[0] = 65;
4897
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
4898
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
4899
+ }
4900
+ });
4901
+ test("classifies the x264 slices as keyframes or not", () => {
4902
+ for (const [name, nal, , keyframe] of x264Slices) {
4903
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
4904
+ }
4905
+ });
4906
+ });
4763
4907
  describe("avccToAnnexB", () => {
4764
4908
  test("converts with SPS/PPS on keyframe", () => {
4765
4909
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -5594,13 +5738,21 @@ var BlockcastMmt = (() => {
5594
5738
  function sameSample(a, b) {
5595
5739
  return a.decodeTime === b.decodeTime && a.presentationTime === b.presentationTime && a.duration === b.duration && a.timescale === b.timescale && a.size === b.size && a.bytePosition === b.bytePosition;
5596
5740
  }
5597
- var _track, _fragments, _pendingSamples, _evictedSamples, _lastMovieFragmentRejection, _IsoBmffTimingResolver_instances, evictOldestFragment_fn, clearSlot_fn;
5741
+ var _track, _fragments, _firstSamples, _delivered, _pendingSamples, _evictedSamples, _lastMovieFragmentRejection, _IsoBmffTimingResolver_instances, evictOldestFragment_fn, clearSlot_fn;
5598
5742
  var IsoBmffTimingResolver = class {
5599
5743
  constructor(maxPendingSamples) {
5600
5744
  this.maxPendingSamples = maxPendingSamples;
5601
5745
  __privateAdd(this, _IsoBmffTimingResolver_instances);
5602
5746
  __privateAdd(this, _track, null);
5603
5747
  __privateAdd(this, _fragments, /* @__PURE__ */ new Map());
5748
+ /** First sample of each pending fragment, kept in `#delivered` with its sample count. */
5749
+ __privateAdd(this, _firstSamples, /* @__PURE__ */ new Map());
5750
+ /**
5751
+ * First sample and sample count of the newest fragments whose every slot was
5752
+ * cleared. Abandonment counts: `releaseSample` clears a slot too, which
5753
+ * matches the combiner, since it retires an abandoned sample as well.
5754
+ */
5755
+ __privateAdd(this, _delivered, /* @__PURE__ */ new Map());
5604
5756
  __privateAdd(this, _pendingSamples, 0);
5605
5757
  __privateAdd(this, _evictedSamples, 0);
5606
5758
  __privateAdd(this, _lastMovieFragmentRejection, null);
@@ -5608,6 +5760,10 @@ var BlockcastMmt = (() => {
5608
5760
  throw new Error("[IsoBmffTimingResolver] maxPendingSamples must be a positive integer");
5609
5761
  }
5610
5762
  }
5763
+ /** True once an FT=0 has bound the track that FT=1 timing is read against. */
5764
+ get initialized() {
5765
+ return __privateGet(this, _track) !== null;
5766
+ }
5611
5767
  get pendingSampleCount() {
5612
5768
  return __privateGet(this, _pendingSamples);
5613
5769
  }
@@ -5631,7 +5787,14 @@ var BlockcastMmt = (() => {
5631
5787
  __privateSet(this, _track, timing);
5632
5788
  return true;
5633
5789
  }
5634
- addMovieFragment(mpuSequenceNumber, data, additionalSampleLimit = this.maxPendingSamples) {
5790
+ /**
5791
+ * `recovered` marks an FEC-recovered copy. A recovered block hands back
5792
+ * every FT=1 it holds, the received ones included, so a recovered copy of a
5793
+ * fragment whose samples are all done is a duplicate: admitting it again
5794
+ * would charge stale timing and could displace the live MPU's. A source
5795
+ * copy is still admitted again (a rendition switch re-arms timing that way).
5796
+ */
5797
+ addMovieFragment(mpuSequenceNumber, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
5635
5798
  __privateSet(this, _lastMovieFragmentRejection, null);
5636
5799
  if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
5637
5800
  __privateSet(this, _lastMovieFragmentRejection, "invalid");
@@ -5657,6 +5820,8 @@ var BlockcastMmt = (() => {
5657
5820
  (sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
5658
5821
  );
5659
5822
  }
5823
+ const delivered = recovered ? __privateGet(this, _delivered).get(key) : void 0;
5824
+ if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
5660
5825
  let freed = 0;
5661
5826
  while (__privateGet(this, _fragments).size > 0 && (__privateGet(this, _pendingSamples) + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
5662
5827
  freed += __privateMethod(this, _IsoBmffTimingResolver_instances, evictOldestFragment_fn).call(this);
@@ -5670,6 +5835,7 @@ var BlockcastMmt = (() => {
5670
5835
  return false;
5671
5836
  }
5672
5837
  __privateGet(this, _fragments).set(key, [...parsed.samples]);
5838
+ __privateGet(this, _firstSamples).set(key, parsed.samples[0]);
5673
5839
  __privateSet(this, _pendingSamples, __privateGet(this, _pendingSamples) + parsed.samples.length);
5674
5840
  return true;
5675
5841
  }
@@ -5716,11 +5882,15 @@ var BlockcastMmt = (() => {
5716
5882
  reset() {
5717
5883
  __privateSet(this, _track, null);
5718
5884
  __privateGet(this, _fragments).clear();
5885
+ __privateGet(this, _firstSamples).clear();
5886
+ __privateGet(this, _delivered).clear();
5719
5887
  __privateSet(this, _pendingSamples, 0);
5720
5888
  }
5721
5889
  };
5722
5890
  _track = new WeakMap();
5723
5891
  _fragments = new WeakMap();
5892
+ _firstSamples = new WeakMap();
5893
+ _delivered = new WeakMap();
5724
5894
  _pendingSamples = new WeakMap();
5725
5895
  _evictedSamples = new WeakMap();
5726
5896
  _lastMovieFragmentRejection = new WeakMap();
@@ -5739,6 +5909,7 @@ var BlockcastMmt = (() => {
5739
5909
  let live = 0;
5740
5910
  for (const sample of samples) if (sample !== null) live++;
5741
5911
  __privateGet(this, _fragments).delete(oldest);
5912
+ __privateGet(this, _firstSamples).delete(oldest);
5742
5913
  __privateSet(this, _pendingSamples, __privateGet(this, _pendingSamples) - live);
5743
5914
  __privateSet(this, _evictedSamples, __privateGet(this, _evictedSamples) + live);
5744
5915
  return live;
@@ -5754,7 +5925,16 @@ var BlockcastMmt = (() => {
5754
5925
  if (!samples || !samples[index]) return false;
5755
5926
  samples[index] = null;
5756
5927
  __privateWrapper(this, _pendingSamples)._--;
5757
- if (samples.every((value) => value === null)) __privateGet(this, _fragments).delete(key);
5928
+ if (samples.every((value) => value === null)) {
5929
+ __privateGet(this, _fragments).delete(key);
5930
+ const first = __privateGet(this, _firstSamples).get(key);
5931
+ __privateGet(this, _firstSamples).delete(key);
5932
+ __privateGet(this, _delivered).delete(key);
5933
+ __privateGet(this, _delivered).set(key, { first, sampleCount: samples.length });
5934
+ if (__privateGet(this, _delivered).size > this.maxPendingSamples) {
5935
+ __privateGet(this, _delivered).delete(__privateGet(this, _delivered).keys().next().value);
5936
+ }
5937
+ }
5758
5938
  return true;
5759
5939
  };
5760
5940
  function fragmentKey(mpuSequenceNumber, movieFragmentSequenceNumber) {
@@ -5930,7 +6110,10 @@ var BlockcastMmt = (() => {
5930
6110
  function ssIdAfter(a, b) {
5931
6111
  return (a - b | 0) > 0;
5932
6112
  }
5933
- var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, release_fn;
6113
+ function holdsRebuilt(stream) {
6114
+ return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
6115
+ }
6116
+ var _streams2, _gate, _emit2, _recordStat2, _deferDepth, _deferredStreams, _FecReleaseSequencer_instances, drainUnlessDeferred_fn, streamFor_fn2, drain_fn, drainLoop_fn, unrepairableWaitOver_fn, cursorPassed_fn, release_fn;
5934
6117
  var FecReleaseSequencer = class {
5935
6118
  constructor(gate, emit, recordStat) {
5936
6119
  __privateAdd(this, _FecReleaseSequencer_instances);
@@ -5990,6 +6173,7 @@ var BlockcastMmt = (() => {
5990
6173
  stream.lastSbn = void 0;
5991
6174
  stream.discontinuity = false;
5992
6175
  stream.rapSsId = void 0;
6176
+ stream.sourced = false;
5993
6177
  }
5994
6178
  if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
5995
6179
  __privateGet(this, _recordStat2).call(this, "droppedStale");
@@ -6016,6 +6200,7 @@ var BlockcastMmt = (() => {
6016
6200
  if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
6017
6201
  else hi = mid;
6018
6202
  }
6203
+ if (stream.buf[lo]?.passed === true) frame.passed = true;
6019
6204
  stream.buf.splice(lo, 0, frame);
6020
6205
  __privateMethod(this, _FecReleaseSequencer_instances, drainUnlessDeferred_fn).call(this, stream);
6021
6206
  }
@@ -6051,6 +6236,41 @@ var BlockcastMmt = (() => {
6051
6236
  }
6052
6237
  return false;
6053
6238
  }
6239
+ /**
6240
+ * These streams' sink is being replaced by one that has seen no source
6241
+ * frame yet. First, from a stream that holds a frame the overlay rebuilt,
6242
+ * release to the sink being replaced the frames the unanchored path had
6243
+ * already released to it (#cursorPassed): there they waited in its queue,
6244
+ * which its replacement flushes. A stream that holds none is not drained:
6245
+ * it holds nothing the anchor kept back, and a drain would still force out
6246
+ * a frame held past the hold limit, which before the anchor waited for the
6247
+ * next push. Then treat the streams as unsourced until a source frame is
6248
+ * released.
6249
+ */
6250
+ unsource(packetId, catalogTrackName) {
6251
+ for (const stream of __privateGet(this, _streams2).values()) {
6252
+ if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
6253
+ if (stream.draining === 0 && holdsRebuilt(stream)) {
6254
+ if (__privateGet(this, _deferDepth) > 0) __privateGet(this, _deferredStreams).add(stream);
6255
+ else __privateMethod(this, _FecReleaseSequencer_instances, drain_fn).call(this, stream, true);
6256
+ }
6257
+ stream.sourced = false;
6258
+ }
6259
+ }
6260
+ }
6261
+ /**
6262
+ * Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
6263
+ * (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
6264
+ * packetId.
6265
+ */
6266
+ holdsRebuilt(packetId, catalogTrackName) {
6267
+ for (const stream of __privateGet(this, _streams2).values()) {
6268
+ if (stream.packetId !== packetId) continue;
6269
+ if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
6270
+ if (holdsRebuilt(stream)) return true;
6271
+ }
6272
+ return false;
6273
+ }
6054
6274
  /** Re-evaluate held gaps after FEC state changed. */
6055
6275
  poke(streamKey) {
6056
6276
  if (streamKey !== void 0) {
@@ -6154,16 +6374,32 @@ var BlockcastMmt = (() => {
6154
6374
  last: null,
6155
6375
  lastSbn: void 0,
6156
6376
  discontinuity: false,
6157
- rapSsId: void 0
6377
+ rapSsId: void 0,
6378
+ sourced: false,
6379
+ draining: 0
6158
6380
  };
6159
6381
  __privateGet(this, _streams2).set(streamKey, stream);
6160
6382
  }
6161
6383
  return stream;
6162
6384
  };
6163
- drain_fn = function(stream) {
6385
+ /** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
6386
+ drain_fn = function(stream, asUnanchored = false) {
6387
+ stream.draining++;
6388
+ try {
6389
+ __privateMethod(this, _FecReleaseSequencer_instances, drainLoop_fn).call(this, stream, asUnanchored);
6390
+ } finally {
6391
+ stream.draining--;
6392
+ }
6393
+ };
6394
+ drainLoop_fn = function(stream, asUnanchored) {
6164
6395
  while (stream.buf.length > 0 && stream.last !== null) {
6165
6396
  const head = stream.buf[0];
6166
6397
  const last = stream.last;
6398
+ if (compareFrameOrder(head, last) <= 0) {
6399
+ stream.buf.shift();
6400
+ __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, void 0);
6401
+ continue;
6402
+ }
6167
6403
  if (stream.discontinuity) {
6168
6404
  stream.discontinuity = false;
6169
6405
  stream.buf.shift();
@@ -6177,9 +6413,10 @@ var BlockcastMmt = (() => {
6177
6413
  }
6178
6414
  const headSbn = head.meta.fecSbn;
6179
6415
  const from = stream.lastSbn ?? headSbn;
6180
- const to = headSbn ?? stream.lastSbn;
6416
+ const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
6181
6417
  let lost = [];
6182
6418
  const unanchored = from === void 0 && to === void 0;
6419
+ let unresolved = false;
6183
6420
  if (from !== void 0 && to !== void 0) {
6184
6421
  const resolved = __privateGet(this, _gate).resolvedLoss(
6185
6422
  stream.packetId,
@@ -6188,7 +6425,8 @@ var BlockcastMmt = (() => {
6188
6425
  Math.max(from, to),
6189
6426
  from
6190
6427
  );
6191
- if (resolved === null) {
6428
+ unresolved = resolved === null;
6429
+ 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)) {
6192
6430
  const heldMs = performance.now() - head.arrivedAtMs;
6193
6431
  if (heldMs <= __privateGet(this, _gate).holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
6194
6432
  __privateGet(this, _recordStat2).call(this, "forcedWindowFlushes");
@@ -6196,18 +6434,65 @@ var BlockcastMmt = (() => {
6196
6434
  __privateMethod(this, _FecReleaseSequencer_instances, release_fn).call(this, stream, head, __privateGet(this, _gate).decide(last, head, [], true));
6197
6435
  continue;
6198
6436
  }
6199
- lost = resolved;
6437
+ lost = resolved ?? [];
6200
6438
  }
6201
6439
  stream.buf.shift();
6202
- __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);
6440
+ __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);
6203
6441
  }
6204
6442
  };
6443
+ /**
6444
+ * The head has waited out a gap only a late source can still fill
6445
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
6446
+ * the stream when it has (`wakeAt`), since no packet may come by then.
6447
+ */
6448
+ unrepairableWaitOver_fn = function(stream, last, head, from, to) {
6449
+ const waitMs = __privateGet(this, _gate).unrepairableWaitMs?.(last, head, from, to);
6450
+ if (waitMs === void 0) return false;
6451
+ const atMs = head.arrivedAtMs + waitMs;
6452
+ if (performance.now() >= atMs) return true;
6453
+ __privateGet(this, _gate).wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
6454
+ return false;
6455
+ };
6456
+ /**
6457
+ * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
6458
+ * source cursor holds it unanchored, and neither does a later frame behind
6459
+ * it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
6460
+ * fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
6461
+ * like each frame that arrived in front of it since (stale there). The head
6462
+ * then goes, decided as it would be unanchored, once a frame the base path
6463
+ * delivered (a source frame, or one base FEC recovered) is buffered after a
6464
+ * marked one: the base path has passed that one, so a frame still missing
6465
+ * before it can only come from a repair. It also goes while no source frame
6466
+ * has been released, when the direct path shows a recovered frame at once.
6467
+ * And it goes at once while a staged switch decides on when frames arrive
6468
+ * (FecReleaseGate.releaseUnanchored), and when unsource releases into a
6469
+ * sink being replaced: unanchored, it had already reached the sink.
6470
+ * The scan also writes: the `passed` marks it sets stay on the frames,
6471
+ * and push marks a frame it inserts in front of a marked one from them.
6472
+ */
6473
+ cursorPassed_fn = function(stream, asUnanchored) {
6474
+ let at = -1;
6475
+ for (let i = 0; i < stream.buf.length; i++) {
6476
+ const frame = stream.buf[i];
6477
+ if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
6478
+ frame.passed = true;
6479
+ if (at < 0) at = i;
6480
+ } else if (frame.passed !== true) break;
6481
+ }
6482
+ if (at < 0) return false;
6483
+ 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));
6484
+ };
6205
6485
  release_fn = function(stream, frame, decision) {
6486
+ const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
6487
+ if (stale) __privateGet(this, _recordStat2).call(this, "droppedStale");
6206
6488
  if (decision) frame.meta.gapBefore = decision;
6207
6489
  stream.last = frame;
6208
- if (frame.meta.fecSbn !== void 0) stream.lastSbn = frame.meta.fecSbn;
6490
+ if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
6491
+ stream.lastSbn = frame.meta.fecSbn;
6492
+ }
6493
+ if (frame.meta.recovered !== true) stream.sourced = true;
6209
6494
  __privateGet(this, _gate).onReleased?.(frame.data, frame.meta);
6210
- __privateGet(this, _emit2).call(this, frame.data, frame.meta);
6495
+ if (!stale) __privateGet(this, _emit2).call(this, frame.data, frame.meta);
6211
6496
  };
6212
6497
  var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
6213
6498
  function isFmp4Box(data) {
@@ -6216,7 +6501,7 @@ var BlockcastMmt = (() => {
6216
6501
  return FMPU_BOX_TYPES.has(type);
6217
6502
  }
6218
6503
  var MAX_AWAITING_TIMING_HEADS = 8;
6219
- var _tracks, _defaultTrack, _reassembler, _sampleCombiners, _sampleCombinerOptions, _retiredSampleCombinerStats, _timingStreams, _maxPendingTimingSamples, _pendingTimingSamples, _reclaimedTimingSamples, _evictedTimingSamples, _rejectedMovieFragments, _sequencers, _fecGate, _fecSequencer, _reorderWindow, _reassemblyPolicy, _frameCb, _initCb, _sourceSymbolCb, _trackFrameCbs, _reorderStats, _reliableMoqStartupGate, _disposed, _replayingAwaitingTiming, _fedObjects, _reassemblerFragmentsFed, _reassemblerDataUnitsReturned, _feedOutcomes, _deferredFeedOutcomes, _lastOutcome, _lastOutcomeCount, _MmtpContainerParser_instances, streamKey_fn, sampleCombinerFor_fn, releaseTimingSlot_fn, dropSampleCombiner_fn, countOutcome_fn, countDeferredOutcome_fn, drop_fn, feedCounted_fn, feed_fn, emitCombinedSample_fn, passReliableMoqStartupGate_fn, timingResolver_fn, awaitTiming_fn, replayAwaitingTiming_fn, dropTimingStream_fn, validateReassemblyPolicy_fn, buildFrameMeta_fn, sequencerFor_fn, flushSequencers_fn, emitFrame_fn2, _MmtpContainerParser_static, scanForKeyframe_fn, scanLengthPrefixedHevcForKeyframe_fn, scanAnnexBForKeyframe_fn;
6504
+ var _tracks, _defaultTrack, _reassembler, _sampleCombiners, _sampleCombinerOptions, _retiredSampleCombinerStats, _timingStreams, _maxPendingTimingSamples, _pendingTimingSamples, _reclaimedTimingSamples, _evictedTimingSamples, _rejectedMovieFragments, _recoveredHeadsAwaitingTiming, _sequencers, _fecGate, _fecSequencer, _reorderWindow, _reassemblyPolicy, _frameCb, _initCb, _sourceSymbolCb, _trackFrameCbs, _reorderStats, _reliableMoqStartupGate, _disposed, _replayingAwaitingTiming, _fedObjects, _reassemblerFragmentsFed, _reassemblerDataUnitsReturned, _feedOutcomes, _deferredFeedOutcomes, _lastOutcome, _lastOutcomeCount, _MmtpContainerParser_instances, streamKey_fn, sampleCombinerFor_fn, releaseTimingSlot_fn, dropSampleCombiner_fn, countOutcome_fn, countDeferredOutcome_fn, drop_fn, feedCounted_fn, feed_fn, emitCombinedSample_fn, passReliableMoqStartupGate_fn, timingResolver_fn, awaitTiming_fn, leaveAwaitingTiming_fn, replayAwaitingTiming_fn, dropTimingStream_fn, validateReassemblyPolicy_fn, buildFrameMeta_fn, sequencerFor_fn, flushSequencers_fn, emitFrame_fn2, _MmtpContainerParser_static, scanForKeyframe_fn, scanLengthPrefixedHevcForKeyframe_fn, scanAnnexBForKeyframe_fn;
6220
6505
  var _MmtpContainerParser = class _MmtpContainerParser {
6221
6506
  constructor(config) {
6222
6507
  __privateAdd(this, _MmtpContainerParser_instances);
@@ -6252,6 +6537,12 @@ var BlockcastMmt = (() => {
6252
6537
  __privateAdd(this, _reclaimedTimingSamples, 0);
6253
6538
  __privateAdd(this, _evictedTimingSamples, 0);
6254
6539
  __privateAdd(this, _rejectedMovieFragments, 0);
6540
+ __privateAdd(this, _recoveredHeadsAwaitingTiming, {
6541
+ held: 0,
6542
+ expired: 0,
6543
+ discarded: 0,
6544
+ superseded: 0
6545
+ });
6255
6546
  __privateAdd(this, _sequencers, /* @__PURE__ */ new Map());
6256
6547
  __privateAdd(this, _fecGate, null);
6257
6548
  __privateAdd(this, _fecSequencer, null);
@@ -6379,11 +6670,12 @@ var BlockcastMmt = (() => {
6379
6670
  /**
6380
6671
  * Typed view of the ISO-BMFF timing-sample budget.
6381
6672
  *
6382
- * This is the acceptance signal for the budget ratchet: `pending` walking
6383
- * to `capacity` while `rejectedMovieFragments` climbs is the stream wedging,
6384
- * and it is observable here rather than only as media silently stopping.
6385
- * Per repo policy this is a producer-owned counter -- never infer budget
6386
- * state by parsing logs.
6673
+ * Each stream admits timing against its own window of `capacity` slots
6674
+ * (BLO-52085). A stream at capacity displaces its own oldest timing to
6675
+ * admit the moof in hand, and `evicted` counts the slots so displaced:
6676
+ * timing a stream declared and never delivered shows up there. `pending`
6677
+ * sums every stream, so it can exceed `capacity`. Per repo policy this is
6678
+ * a producer-owned counter -- never infer budget state by parsing logs.
6387
6679
  */
6388
6680
  get timingBudgetStats() {
6389
6681
  return {
@@ -6394,6 +6686,14 @@ var BlockcastMmt = (() => {
6394
6686
  rejectedMovieFragments: __privateGet(this, _rejectedMovieFragments)
6395
6687
  };
6396
6688
  }
6689
+ /** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
6690
+ get recoveredHeadsAwaitingTiming() {
6691
+ let pending = 0;
6692
+ for (const { awaitingTiming } of __privateGet(this, _timingStreams).values()) {
6693
+ for (const head of awaitingTiming) if (head.options?.recovered) pending++;
6694
+ }
6695
+ return { ...__privateGet(this, _recoveredHeadsAwaitingTiming), pending };
6696
+ }
6397
6697
  get reorderStats() {
6398
6698
  let bufferedFrames = __privateGet(this, _fecSequencer)?.buffered ?? 0;
6399
6699
  for (const { sequencer } of __privateGet(this, _sequencers).values()) bufferedFrames += sequencer.buffered;
@@ -6435,6 +6735,14 @@ var BlockcastMmt = (() => {
6435
6735
  fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
6436
6736
  return __privateGet(this, _fecSequencer)?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
6437
6737
  }
6738
+ /** See FecReleaseSequencer.unsource. */
6739
+ unsourceFecRelease(packetId, catalogTrackName) {
6740
+ __privateGet(this, _fecSequencer)?.unsource(packetId, catalogTrackName);
6741
+ }
6742
+ /** See FecReleaseSequencer.holdsRebuilt. */
6743
+ fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
6744
+ return __privateGet(this, _fecSequencer)?.holdsRebuilt(packetId, catalogTrackName) ?? false;
6745
+ }
6438
6746
  /** Re-evaluate held gaps after FEC block state changed. */
6439
6747
  pokeFecRelease(packetId, catalogTrackName) {
6440
6748
  if (!__privateGet(this, _fecSequencer)) return;
@@ -6545,7 +6853,7 @@ var BlockcastMmt = (() => {
6545
6853
  const now = Date.now();
6546
6854
  for (const { awaitingTiming } of __privateGet(this, _timingStreams).values()) {
6547
6855
  while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
6548
- awaitingTiming.shift();
6856
+ __privateMethod(this, _MmtpContainerParser_instances, leaveAwaitingTiming_fn).call(this, awaitingTiming.shift(), "expired");
6549
6857
  }
6550
6858
  }
6551
6859
  }
@@ -6750,6 +7058,10 @@ var BlockcastMmt = (() => {
6750
7058
  }
6751
7059
  __privateMethod(this, _MmtpContainerParser_instances, emitFrame_fn2).call(this, data, meta);
6752
7060
  }
7061
+ /** Whether FT=1 metadata already names this sample, without claiming it. */
7062
+ hasAuthoredTimingFor(packetId, mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber, catalogTrackName) {
7063
+ return __privateMethod(this, _MmtpContainerParser_instances, timingResolver_fn).call(this, __privateMethod(this, _MmtpContainerParser_instances, streamKey_fn).call(this, packetId, catalogTrackName), packetId, false)?.sampleTiming(mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber) != null;
7064
+ }
6753
7065
  /**
6754
7066
  * Claim and return the authored timing for a recovered sample. Recovery does
6755
7067
  * not pass through the ordinary `feed()` completion path, so it must retire
@@ -6794,6 +7106,9 @@ var BlockcastMmt = (() => {
6794
7106
  for (const { sequencer } of __privateGet(this, _sequencers).values()) sequencer.discard();
6795
7107
  __privateGet(this, _sequencers).clear();
6796
7108
  __privateGet(this, _fecSequencer)?.discard();
7109
+ for (const { awaitingTiming } of __privateGet(this, _timingStreams).values()) {
7110
+ for (const head of awaitingTiming) __privateMethod(this, _MmtpContainerParser_instances, leaveAwaitingTiming_fn).call(this, head, "discarded");
7111
+ }
6797
7112
  __privateGet(this, _timingStreams).clear();
6798
7113
  __privateSet(this, _pendingTimingSamples, 0);
6799
7114
  __privateGet(this, _reliableMoqStartupGate).clear();
@@ -6822,6 +7137,7 @@ var BlockcastMmt = (() => {
6822
7137
  _reclaimedTimingSamples = new WeakMap();
6823
7138
  _evictedTimingSamples = new WeakMap();
6824
7139
  _rejectedMovieFragments = new WeakMap();
7140
+ _recoveredHeadsAwaitingTiming = new WeakMap();
6825
7141
  _sequencers = new WeakMap();
6826
7142
  _fecGate = new WeakMap();
6827
7143
  _fecSequencer = new WeakMap();
@@ -6980,11 +7296,16 @@ var BlockcastMmt = (() => {
6980
7296
  if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
6981
7297
  return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "fragment-unexpected-fragmentation");
6982
7298
  const resolver2 = __privateMethod(this, _MmtpContainerParser_instances, timingResolver_fn).call(this, streamKey, info.packetId, false);
6983
- if (!resolver2) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "fragment-no-resolver");
7299
+ if (!resolver2?.initialized) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "fragment-no-resolver");
6984
7300
  const pendingBefore = resolver2.pendingSampleCount;
6985
7301
  const evictedBefore = resolver2.evictedSampleCount;
6986
- const remaining = __privateGet(this, _maxPendingTimingSamples) - __privateGet(this, _pendingTimingSamples);
6987
- const admitted = resolver2.addMovieFragment(mpu.mpuSequenceNumber, data, remaining);
7302
+ const remaining = __privateGet(this, _maxPendingTimingSamples) - resolver2.pendingSampleCount;
7303
+ const admitted = resolver2.addMovieFragment(
7304
+ mpu.mpuSequenceNumber,
7305
+ data,
7306
+ remaining,
7307
+ options?.recovered === true
7308
+ );
6988
7309
  __privateSet(this, _pendingTimingSamples, __privateGet(this, _pendingTimingSamples) + (resolver2.pendingSampleCount - pendingBefore));
6989
7310
  __privateSet(this, _evictedTimingSamples, __privateGet(this, _evictedTimingSamples) + (resolver2.evictedSampleCount - evictedBefore));
6990
7311
  if (!admitted) {
@@ -7004,7 +7325,7 @@ var BlockcastMmt = (() => {
7004
7325
  };
7005
7326
  }
7006
7327
  if (fragmentType !== 2) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "unknown-fragment-type");
7007
- const resolver = __privateMethod(this, _MmtpContainerParser_instances, timingResolver_fn).call(this, streamKey, info.packetId, false);
7328
+ const resolver = __privateMethod(this, _MmtpContainerParser_instances, timingResolver_fn).call(this, streamKey, info.packetId, true);
7008
7329
  if (!resolver) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "mfu-no-resolver");
7009
7330
  if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
7010
7331
  return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "mfu-empty-payload");
@@ -7025,6 +7346,7 @@ var BlockcastMmt = (() => {
7025
7346
  mpuSequenceNumber: mpu.mpuSequenceNumber,
7026
7347
  movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
7027
7348
  sampleNumber: mfuDuHeader.sampleNumber,
7349
+ sequenceNumber: info.sequenceNumber,
7028
7350
  arrivedAt: Date.now()
7029
7351
  });
7030
7352
  return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "mfu-sample-timing-missing");
@@ -7045,7 +7367,7 @@ var BlockcastMmt = (() => {
7045
7367
  headTiming.size
7046
7368
  );
7047
7369
  if (readyOnRegister) {
7048
- const deferred = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, readyOnRegister, info, resolver, options?.recovered === true, options?.fecSbn);
7370
+ const deferred = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, readyOnRegister, info, resolver, options?.recovered === true, options?.fecSbn, options?.fecSbnFirst);
7049
7371
  if (deferred.record === void 0) __privateMethod(this, _MmtpContainerParser_instances, countDeferredOutcome_fn).call(this, deferred.reason);
7050
7372
  }
7051
7373
  }
@@ -7132,7 +7454,7 @@ var BlockcastMmt = (() => {
7132
7454
  fragmentCounter: mpu.fragmentCounter
7133
7455
  };
7134
7456
  }
7135
- const outcome = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, combined, info, resolver, options?.recovered === true, options?.fecSbn);
7457
+ const outcome = __privateMethod(this, _MmtpContainerParser_instances, emitCombinedSample_fn).call(this, combined, info, resolver, options?.recovered === true, options?.fecSbn, options?.fecSbnFirst);
7136
7458
  if (outcome.record !== void 0) return outcome.record;
7137
7459
  return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, outcome.reason);
7138
7460
  };
@@ -7151,7 +7473,7 @@ var BlockcastMmt = (() => {
7151
7473
  * attribution exists to keep readable. Leaving the choice at the call site
7152
7474
  * is what keeps both true.
7153
7475
  */
7154
- emitCombinedSample_fn = function(combined, info, resolver, recovered, fecSbn) {
7476
+ emitCombinedSample_fn = function(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
7155
7477
  const timing = resolver.sampleTiming(
7156
7478
  combined.mpuSequenceNumber,
7157
7479
  combined.movieFragmentSequenceNumber,
@@ -7162,6 +7484,7 @@ var BlockcastMmt = (() => {
7162
7484
  const meta = __privateMethod(this, _MmtpContainerParser_instances, buildFrameMeta_fn).call(this, combined, info.packetId, info.sequenceNumber, timing, recovered);
7163
7485
  if (!meta) return { reason: "combined-meta-build-failed" };
7164
7486
  if (fecSbn !== void 0) meta.fecSbn = fecSbn;
7487
+ if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
7165
7488
  if (!resolver.consumeSample(
7166
7489
  combined.mpuSequenceNumber,
7167
7490
  combined.movieFragmentSequenceNumber,
@@ -7206,10 +7529,23 @@ var BlockcastMmt = (() => {
7206
7529
  return resolver;
7207
7530
  };
7208
7531
  awaitTiming_fn = function(streamKey, head) {
7209
- const awaitingTiming = __privateGet(this, _timingStreams).get(streamKey)?.awaitingTiming;
7210
- if (!awaitingTiming) return;
7532
+ const state = __privateGet(this, _timingStreams).get(streamKey);
7533
+ if (!state) return;
7534
+ if (!head.options?.recovered) {
7535
+ const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
7536
+ __privateGet(this, _recoveredHeadsAwaitingTiming).superseded += state.awaitingTiming.length - kept.length;
7537
+ state.awaitingTiming = kept;
7538
+ }
7539
+ const awaitingTiming = state.awaitingTiming;
7211
7540
  awaitingTiming.push(head);
7212
- if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
7541
+ if (head.options?.recovered) __privateGet(this, _recoveredHeadsAwaitingTiming).held++;
7542
+ if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
7543
+ __privateMethod(this, _MmtpContainerParser_instances, leaveAwaitingTiming_fn).call(this, awaitingTiming.shift(), "expired");
7544
+ }
7545
+ };
7546
+ /** Count a recovered head leaving the queue other than by replay or its source copy. */
7547
+ leaveAwaitingTiming_fn = function(head, outcome) {
7548
+ if (head.options?.recovered) __privateGet(this, _recoveredHeadsAwaitingTiming)[outcome]++;
7213
7549
  };
7214
7550
  /**
7215
7551
  * Feed again the heads whose timing the FT=1 just admitted declares. That
@@ -7237,6 +7573,7 @@ var BlockcastMmt = (() => {
7237
7573
  const state = __privateGet(this, _timingStreams).get(streamKey);
7238
7574
  if (!state) return;
7239
7575
  __privateGet(this, _timingStreams).delete(streamKey);
7576
+ for (const head of state.awaitingTiming) __privateMethod(this, _MmtpContainerParser_instances, leaveAwaitingTiming_fn).call(this, head, "discarded");
7240
7577
  __privateSet(this, _pendingTimingSamples, __privateGet(this, _pendingTimingSamples) - state.resolver.pendingSampleCount);
7241
7578
  if (__privateGet(this, _pendingTimingSamples) < 0) {
7242
7579
  throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
@@ -8115,6 +8452,9 @@ var BlockcastMmt = (() => {
8115
8452
  return INACTIVE["reliable-moq"];
8116
8453
  }
8117
8454
 
8455
+ // src/catalog-fec-params.ts
8456
+ var MAX_SAFE_TICKS_PER_HZ = Number.MAX_SAFE_INTEGER / 1e3;
8457
+
8118
8458
  // src/held-layer-admission.ts
8119
8459
  var HORIZON_CAP = 1073741824;
8120
8460
  function heldLayerAnchorHorizon(retentionBlocks, k) {
@@ -8217,7 +8557,7 @@ var BlockcastMmt = (() => {
8217
8557
  // src/mmtp-fec-session.ts
8218
8558
  var PATH_BITS = { moq: 1, multicast: 2 };
8219
8559
  var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
8220
- var _decoder, _blocks, _settled, _have, _newest, _prunedAt, _repairPacketId, _newestSource, _heldLayers, _anchorHorizon, _stats3, _MmtpFecSession_instances, drop_fn2, noteNewest_fn, blockStartOf_fn, countHeld_fn, noteMixed_fn, behindHorizon_fn, settle_fn, settleClean_fn, settleDecoded_fn, retireBehindHorizon_fn;
8560
+ var _decoder, _repairSymbols, _message, _blocks, _settled, _have, _newest, _prunedAt, _repairPacketId, _newestSource, _heldLayers, _anchorHorizon, _stats3, _MmtpFecSession_instances, trackFor_fn, drop_fn2, noteNewest_fn, blockStartOf_fn, countHeld_fn, noteMixed_fn, behindHorizon_fn, settle_fn, settleClean_fn, settleDecoded_fn, retireBehindHorizon_fn;
8221
8561
  var MmtpFecSession = class {
8222
8562
  /**
8223
8563
  * @throws when the instance lacks or misstates a field the session needs:
@@ -8227,6 +8567,9 @@ var BlockcastMmt = (() => {
8227
8567
  constructor(config) {
8228
8568
  __privateAdd(this, _MmtpFecSession_instances);
8229
8569
  __privateAdd(this, _decoder);
8570
+ __privateAdd(this, _repairSymbols);
8571
+ /** The message entry a catalog-less session was built from; undefined under a catalog. */
8572
+ __privateAdd(this, _message);
8230
8573
  /** Blocks a repair has defined and that are not settled yet, by SS_Start. */
8231
8574
  __privateAdd(this, _blocks, /* @__PURE__ */ new Map());
8232
8575
  /** SS_Starts of settled blocks, so a later repair for one is refused. */
@@ -8258,6 +8601,24 @@ var BlockcastMmt = (() => {
8258
8601
  mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 },
8259
8602
  failClosed: null
8260
8603
  });
8604
+ if (config && "alFecFlow" in config) {
8605
+ const message = alFecRaptorQFlowConfig(config.alFecFlow);
8606
+ if (!message) {
8607
+ throw new Error("MmtpFecSession: the AL-FEC entry is outside draft-ramadan-moq-mmt-02 8.3 (iso-ssbg1-v1)");
8608
+ }
8609
+ __privateSet(this, _message, message);
8610
+ this.blockProfile = parseFecBlockProfile("iso-ssbg1-v1", "alFecFlow");
8611
+ this.algorithm = message.fecCodeId === FEC_CODE_RAPTORQ ? "raptorq" : "reed-solomon";
8612
+ this.sourceSymbols = message.maximumK;
8613
+ __privateSet(this, _repairSymbols, message.maximumP);
8614
+ this.symbolSize = message.repairSymbolSize;
8615
+ this.retentionBlocks = requirePositiveInteger(config.retentionBlocks, "retentionBlocks");
8616
+ __privateSet(this, _repairPacketId, message.repairFlowId);
8617
+ __privateSet(this, _heldLayers, layerZero(message.maximumP));
8618
+ __privateSet(this, _anchorHorizon, heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols));
8619
+ __privateSet(this, _decoder, buildDecoder(config.Decoder, this));
8620
+ return;
8621
+ }
8261
8622
  const fec = config?.fec;
8262
8623
  if (!fec || typeof fec !== "object") {
8263
8624
  throw new Error("MmtpFecSession: the catalog fec instance is required");
@@ -8268,7 +8629,7 @@ var BlockcastMmt = (() => {
8268
8629
  }
8269
8630
  this.algorithm = fec.scheme;
8270
8631
  this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
8271
- this.repairSymbols = requirePositiveInteger(fec.repairSymbols, "fec.repairSymbols");
8632
+ __privateSet(this, _repairSymbols, requirePositiveInteger(fec.repairSymbols, "fec.repairSymbols"));
8272
8633
  this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
8273
8634
  const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
8274
8635
  const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
@@ -8288,17 +8649,34 @@ var BlockcastMmt = (() => {
8288
8649
  config.heldLayers
8289
8650
  ));
8290
8651
  __privateSet(this, _anchorHorizon, heldLayerAnchorHorizon(this.retentionBlocks, this.sourceSymbols));
8291
- if (typeof config.Decoder !== "function") {
8292
- throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
8293
- }
8294
- const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
8295
- try {
8296
- decoder.configure_params(this.sourceSymbols, this.symbolSize);
8297
- } catch (error) {
8298
- decoder.free();
8299
- throw error;
8300
- }
8301
- __privateSet(this, _decoder, decoder);
8652
+ __privateSet(this, _decoder, buildDecoder(config.Decoder, this));
8653
+ }
8654
+ /** P_0 = B_0, the held total every repair packet is checked against. */
8655
+ get repairSymbols() {
8656
+ return __privateGet(this, _repairSymbols);
8657
+ }
8658
+ /**
8659
+ * A later version of the AL-FEC message, catalog-less sessions only. A
8660
+ * maximum_p_for_repair_flow above the held total raises it (`raised`): the
8661
+ * anchored check restarts at the new total, so a block generated under the
8662
+ * previous one stays valid before the first block carrying the new total
8663
+ * (fec-core-00 7.3.2, mmt-02 8.3). A field at or below it changes nothing
8664
+ * (`unchanged`): no publisher lowers it, and the check catches a wire that
8665
+ * does. An entry with another asset, repair flow, code point, K or T, or
8666
+ * one outside 8.3, is `refused`: that is a new source encoding, which needs
8667
+ * a new session. A latched fail-closed stays latched either way.
8668
+ */
8669
+ updateAlFecFlow(flow) {
8670
+ const held = __privateGet(this, _message);
8671
+ if (!held) throw new Error("MmtpFecSession: updateAlFecFlow() needs a session built from an AL-FEC entry");
8672
+ const next = alFecRaptorQFlowConfig(flow);
8673
+ if (!next || next.sourcePacketIds[0] !== held.sourcePacketIds[0] || next.repairFlowId !== held.repairFlowId || next.fecCodeId !== held.fecCodeId || next.maximumK !== held.maximumK || next.repairSymbolSize !== held.repairSymbolSize) {
8674
+ return "refused";
8675
+ }
8676
+ if (next.maximumP <= __privateGet(this, _repairSymbols)) return "unchanged";
8677
+ __privateSet(this, _repairSymbols, next.maximumP);
8678
+ __privateSet(this, _heldLayers, layerZero(next.maximumP));
8679
+ return "raised";
8302
8680
  }
8303
8681
  /** True once release() ran. */
8304
8682
  get released() {
@@ -8393,7 +8771,7 @@ var BlockcastMmt = (() => {
8393
8771
  }
8394
8772
  if (admission.reject) {
8395
8773
  const verdict2 = __privateGet(this, _heldLayers).failsClosed(
8396
- repairTrackName,
8774
+ __privateMethod(this, _MmtpFecSession_instances, trackFor_fn).call(this, repairTrackName),
8397
8775
  frame.ssStart,
8398
8776
  frame.rsbLength,
8399
8777
  __privateGet(this, _anchorHorizon),
@@ -8408,7 +8786,7 @@ var BlockcastMmt = (() => {
8408
8786
  __privateGet(this, _repairPacketId) ?? __privateSet(this, _repairPacketId, frame.packetId);
8409
8787
  if (frame.ssbLength > this.sourceSymbols) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:ssb-length");
8410
8788
  const verdict = __privateGet(this, _heldLayers).admit(
8411
- repairTrackName,
8789
+ __privateMethod(this, _MmtpFecSession_instances, trackFor_fn).call(this, repairTrackName),
8412
8790
  frame.ssStart,
8413
8791
  frame.rsbLength,
8414
8792
  __privateGet(this, _anchorHorizon),
@@ -8469,6 +8847,8 @@ var BlockcastMmt = (() => {
8469
8847
  }
8470
8848
  };
8471
8849
  _decoder = new WeakMap();
8850
+ _repairSymbols = new WeakMap();
8851
+ _message = new WeakMap();
8472
8852
  _blocks = new WeakMap();
8473
8853
  _settled = new WeakMap();
8474
8854
  _have = new WeakMap();
@@ -8480,6 +8860,10 @@ var BlockcastMmt = (() => {
8480
8860
  _anchorHorizon = new WeakMap();
8481
8861
  _stats3 = new WeakMap();
8482
8862
  _MmtpFecSession_instances = new WeakSet();
8863
+ /** Catalog-less: layer 0 has no own-track clause (mmt-02 8.3), so no track name is judged. */
8864
+ trackFor_fn = function(repairTrackName) {
8865
+ return __privateGet(this, _message) ? void 0 : repairTrackName;
8866
+ };
8483
8867
  drop_fn2 = function(reason) {
8484
8868
  __privateGet(this, _stats3).dropped[reason] = (__privateGet(this, _stats3).dropped[reason] ?? 0) + 1;
8485
8869
  return [];
@@ -8600,6 +8984,22 @@ var BlockcastMmt = (() => {
8600
8984
  if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) __privateGet(this, _settled).delete(start);
8601
8985
  }
8602
8986
  };
8987
+ function layerZero(total) {
8988
+ return new HeldLayerAdmission([{ layer: 0, repairTrackName: "", rsIdOffset: 0, repairSymbols: total }]);
8989
+ }
8990
+ function buildDecoder(Decoder, session) {
8991
+ if (typeof Decoder !== "function") {
8992
+ throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
8993
+ }
8994
+ const decoder = new Decoder(session.retentionBlocks, session.blockProfile, session.algorithm);
8995
+ try {
8996
+ decoder.configure_params(session.sourceSymbols, session.symbolSize);
8997
+ } catch (error) {
8998
+ decoder.free();
8999
+ throw error;
9000
+ }
9001
+ return decoder;
9002
+ }
8603
9003
  function requirePositiveInteger(value, path) {
8604
9004
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
8605
9005
  throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);