@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
@@ -298,6 +298,40 @@ var RUNTIME_FEC_RECEIVER = Object.freeze({
298
298
  overlays: true
299
299
  });
300
300
 
301
+ // ../mmt-base/dist/mmtp-siblings.js
302
+ var MMTP_MODES = Object.freeze(["mfu", "mfu-datagram"]);
303
+ var MMTP_SIBLING_HARD_FIELDS = Object.freeze([
304
+ "namespace",
305
+ "timescale",
306
+ "presentationAnchorTicks",
307
+ "groupDuration"
308
+ ]);
309
+ var MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
310
+ "codec",
311
+ "width",
312
+ "height",
313
+ "framerate",
314
+ "bitrate",
315
+ "samplerate",
316
+ "channelConfig",
317
+ "lang"
318
+ ]);
319
+ var MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
320
+ "initRef",
321
+ "keyframeIntervalMs",
322
+ "keyframeIntervalTicks",
323
+ "isLive",
324
+ "altGroup"
325
+ ]);
326
+
327
+ // ../mmt-base/dist/datagram-leg-size.js
328
+ var DATAGRAM_LEG_UDP_FLOOR = 1200;
329
+ var DATAGRAM_LEG_QUIC_WT_FRAMING = 48;
330
+ var DATAGRAM_LEG_OBJECT_HEADER = 13;
331
+ var DATAGRAM_LEG_RELAY_ROOM = 16;
332
+ var DATAGRAM_LEG_DATAGRAM_MAX = DATAGRAM_LEG_UDP_FLOOR - DATAGRAM_LEG_QUIC_WT_FRAMING;
333
+ var DATAGRAM_LEG_BODY_MAX = DATAGRAM_LEG_DATAGRAM_MAX - DATAGRAM_LEG_OBJECT_HEADER - DATAGRAM_LEG_RELAY_ROOM;
334
+
301
335
  // src/mfu-reassembler.ts
302
336
  function fragmentProvenance(fragment) {
303
337
  if (fragment.deliveryProvenance !== void 0) return fragment.deliveryProvenance;
@@ -3875,9 +3909,10 @@ function isH264IntraSlice(nal) {
3875
3909
  const sliceType = readH264SliceType(nal);
3876
3910
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
3877
3911
  }
3912
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
3878
3913
  function readH264SliceType(nal) {
3879
3914
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
3880
- const rbsp = removeEmulationPrevention(nal.subarray(1));
3915
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
3881
3916
  const state = { bitOffset: 0 };
3882
3917
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
3883
3918
  return readUnsignedExpGolomb(rbsp, state);
@@ -4024,6 +4059,96 @@ if (void 0) {
4024
4059
  ]))).toBe(false);
4025
4060
  });
4026
4061
  });
4062
+ describe("readH264SliceType", () => {
4063
+ const wholeNalSliceType = (nal) => {
4064
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4065
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
4066
+ const state = { bitOffset: 0 };
4067
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4068
+ return readUnsignedExpGolomb(rbsp, state);
4069
+ };
4070
+ const hex = (text) => Uint8Array.from(text.match(/../g), (byte) => parseInt(byte, 16));
4071
+ const ue = (value) => {
4072
+ const code = (value + 1).toString(2);
4073
+ return "0".repeat(code.length - 1) + code;
4074
+ };
4075
+ const sliceNal = (bits) => {
4076
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
4077
+ const nal = [1];
4078
+ let zeros = 0;
4079
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
4080
+ if (zeros >= 2 && byte <= 3) {
4081
+ nal.push(3);
4082
+ zeros = 0;
4083
+ }
4084
+ nal.push(byte);
4085
+ zeros = byte === 0 ? zeros + 1 : 0;
4086
+ }
4087
+ return Uint8Array.from(nal);
4088
+ };
4089
+ const x264Slices = [
4090
+ ["64x48 P", hex("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
4091
+ ["64x48 B", hex("419e414212fffeeade283707cb70f7"), 6, false],
4092
+ ["64x48 non-IDR I", hex(
4093
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
4094
+ ), 7, true],
4095
+ ["1280x720 B, escape at byte 10", hex(
4096
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
4097
+ ), 6, false],
4098
+ ["1280x720 P, escape at byte 15", hex(
4099
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
4100
+ ), 5, false],
4101
+ ["1280x720 B, escape at byte 22", hex("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
4102
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex(
4103
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
4104
+ ), null, true],
4105
+ ["7680x4320 P, first_mb_in_slice 32640", hex(
4106
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
4107
+ ), 5, false],
4108
+ ["7680x4320 P, first_mb_in_slice 97440", hex(
4109
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
4110
+ ), 5, false]
4111
+ ];
4112
+ const syntheticSlices = [
4113
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
4114
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
4115
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
4116
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
4117
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
4118
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
4119
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
4120
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
4121
+ ];
4122
+ test("reads the slice_type of real and synthetic slices", () => {
4123
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
4124
+ expect(readH264SliceType(nal), name).toBe(sliceType);
4125
+ }
4126
+ });
4127
+ test("matches the whole-NAL unescape at every truncation", () => {
4128
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
4129
+ for (let end = 0; end <= nal.length; end++) {
4130
+ const cut = nal.subarray(0, end);
4131
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
4132
+ }
4133
+ }
4134
+ });
4135
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
4136
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
4137
+ let seed = 1;
4138
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
4139
+ for (let i = 0; i < 5e3; i++) {
4140
+ const nal = new Uint8Array(2 + next() % 63);
4141
+ nal[0] = 65;
4142
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
4143
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
4144
+ }
4145
+ });
4146
+ test("classifies the x264 slices as keyframes or not", () => {
4147
+ for (const [name, nal, , keyframe] of x264Slices) {
4148
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
4149
+ }
4150
+ });
4151
+ });
4027
4152
  describe("avccToAnnexB", () => {
4028
4153
  test("converts with SPS/PPS on keyframe", () => {
4029
4154
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -5197,6 +5322,9 @@ function authoredGap(before, after) {
5197
5322
  function ssIdAfter(a, b) {
5198
5323
  return (a - b | 0) > 0;
5199
5324
  }
5325
+ function holdsRebuilt(stream) {
5326
+ return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
5327
+ }
5200
5328
  var FecReleaseSequencer = class {
5201
5329
  #streams = /* @__PURE__ */ new Map();
5202
5330
  #gate;
@@ -5259,6 +5387,7 @@ var FecReleaseSequencer = class {
5259
5387
  stream.lastSbn = void 0;
5260
5388
  stream.discontinuity = false;
5261
5389
  stream.rapSsId = void 0;
5390
+ stream.sourced = false;
5262
5391
  }
5263
5392
  if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
5264
5393
  this.#recordStat("droppedStale");
@@ -5285,6 +5414,7 @@ var FecReleaseSequencer = class {
5285
5414
  if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
5286
5415
  else hi = mid;
5287
5416
  }
5417
+ if (stream.buf[lo]?.passed === true) frame.passed = true;
5288
5418
  stream.buf.splice(lo, 0, frame);
5289
5419
  this.#drainUnlessDeferred(stream);
5290
5420
  }
@@ -5320,6 +5450,41 @@ var FecReleaseSequencer = class {
5320
5450
  }
5321
5451
  return false;
5322
5452
  }
5453
+ /**
5454
+ * These streams' sink is being replaced by one that has seen no source
5455
+ * frame yet. First, from a stream that holds a frame the overlay rebuilt,
5456
+ * release to the sink being replaced the frames the unanchored path had
5457
+ * already released to it (#cursorPassed): there they waited in its queue,
5458
+ * which its replacement flushes. A stream that holds none is not drained:
5459
+ * it holds nothing the anchor kept back, and a drain would still force out
5460
+ * a frame held past the hold limit, which before the anchor waited for the
5461
+ * next push. Then treat the streams as unsourced until a source frame is
5462
+ * released.
5463
+ */
5464
+ unsource(packetId, catalogTrackName) {
5465
+ for (const stream of this.#streams.values()) {
5466
+ if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
5467
+ if (stream.draining === 0 && holdsRebuilt(stream)) {
5468
+ if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
5469
+ else this.#drain(stream, true);
5470
+ }
5471
+ stream.sourced = false;
5472
+ }
5473
+ }
5474
+ }
5475
+ /**
5476
+ * Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
5477
+ * (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
5478
+ * packetId.
5479
+ */
5480
+ holdsRebuilt(packetId, catalogTrackName) {
5481
+ for (const stream of this.#streams.values()) {
5482
+ if (stream.packetId !== packetId) continue;
5483
+ if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
5484
+ if (holdsRebuilt(stream)) return true;
5485
+ }
5486
+ return false;
5487
+ }
5323
5488
  /** Re-evaluate held gaps after FEC state changed. */
5324
5489
  poke(streamKey) {
5325
5490
  if (streamKey !== void 0) {
@@ -5411,16 +5576,32 @@ var FecReleaseSequencer = class {
5411
5576
  last: null,
5412
5577
  lastSbn: void 0,
5413
5578
  discontinuity: false,
5414
- rapSsId: void 0
5579
+ rapSsId: void 0,
5580
+ sourced: false,
5581
+ draining: 0
5415
5582
  };
5416
5583
  this.#streams.set(streamKey, stream);
5417
5584
  }
5418
5585
  return stream;
5419
5586
  }
5420
- #drain(stream) {
5587
+ /** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
5588
+ #drain(stream, asUnanchored = false) {
5589
+ stream.draining++;
5590
+ try {
5591
+ this.#drainLoop(stream, asUnanchored);
5592
+ } finally {
5593
+ stream.draining--;
5594
+ }
5595
+ }
5596
+ #drainLoop(stream, asUnanchored) {
5421
5597
  while (stream.buf.length > 0 && stream.last !== null) {
5422
5598
  const head = stream.buf[0];
5423
5599
  const last = stream.last;
5600
+ if (compareFrameOrder(head, last) <= 0) {
5601
+ stream.buf.shift();
5602
+ this.#release(stream, head, void 0);
5603
+ continue;
5604
+ }
5424
5605
  if (stream.discontinuity) {
5425
5606
  stream.discontinuity = false;
5426
5607
  stream.buf.shift();
@@ -5434,9 +5615,10 @@ var FecReleaseSequencer = class {
5434
5615
  }
5435
5616
  const headSbn = head.meta.fecSbn;
5436
5617
  const from = stream.lastSbn ?? headSbn;
5437
- const to = headSbn ?? stream.lastSbn;
5618
+ const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
5438
5619
  let lost = [];
5439
5620
  const unanchored = from === void 0 && to === void 0;
5621
+ let unresolved = false;
5440
5622
  if (from !== void 0 && to !== void 0) {
5441
5623
  const resolved = this.#gate.resolvedLoss(
5442
5624
  stream.packetId,
@@ -5445,7 +5627,8 @@ var FecReleaseSequencer = class {
5445
5627
  Math.max(from, to),
5446
5628
  from
5447
5629
  );
5448
- if (resolved === null) {
5630
+ unresolved = resolved === null;
5631
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
5449
5632
  const heldMs = performance.now() - head.arrivedAtMs;
5450
5633
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
5451
5634
  this.#recordStat("forcedWindowFlushes");
@@ -5453,22 +5636,69 @@ var FecReleaseSequencer = class {
5453
5636
  this.#release(stream, head, this.#gate.decide(last, head, [], true));
5454
5637
  continue;
5455
5638
  }
5456
- lost = resolved;
5639
+ lost = resolved ?? [];
5457
5640
  }
5458
5641
  stream.buf.shift();
5459
5642
  this.#release(
5460
5643
  stream,
5461
5644
  head,
5462
- lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5645
+ lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5463
5646
  );
5464
5647
  }
5465
5648
  }
5649
+ /**
5650
+ * The head has waited out a gap only a late source can still fill
5651
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
5652
+ * the stream when it has (`wakeAt`), since no packet may come by then.
5653
+ */
5654
+ #unrepairableWaitOver(stream, last, head, from, to) {
5655
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
5656
+ if (waitMs === void 0) return false;
5657
+ const atMs = head.arrivedAtMs + waitMs;
5658
+ if (performance.now() >= atMs) return true;
5659
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
5660
+ return false;
5661
+ }
5662
+ /**
5663
+ * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
5664
+ * source cursor holds it unanchored, and neither does a later frame behind
5665
+ * it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
5666
+ * fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
5667
+ * like each frame that arrived in front of it since (stale there). The head
5668
+ * then goes, decided as it would be unanchored, once a frame the base path
5669
+ * delivered (a source frame, or one base FEC recovered) is buffered after a
5670
+ * marked one: the base path has passed that one, so a frame still missing
5671
+ * before it can only come from a repair. It also goes while no source frame
5672
+ * has been released, when the direct path shows a recovered frame at once.
5673
+ * And it goes at once while a staged switch decides on when frames arrive
5674
+ * (FecReleaseGate.releaseUnanchored), and when unsource releases into a
5675
+ * sink being replaced: unanchored, it had already reached the sink.
5676
+ * The scan also writes: the `passed` marks it sets stay on the frames,
5677
+ * and push marks a frame it inserts in front of a marked one from them.
5678
+ */
5679
+ #cursorPassed(stream, asUnanchored) {
5680
+ let at = -1;
5681
+ for (let i = 0; i < stream.buf.length; i++) {
5682
+ const frame = stream.buf[i];
5683
+ if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
5684
+ frame.passed = true;
5685
+ if (at < 0) at = i;
5686
+ } else if (frame.passed !== true) break;
5687
+ }
5688
+ if (at < 0) return false;
5689
+ return asUnanchored || !stream.sourced || 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));
5690
+ }
5466
5691
  #release(stream, frame, decision) {
5692
+ const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
5693
+ if (stale) this.#recordStat("droppedStale");
5467
5694
  if (decision) frame.meta.gapBefore = decision;
5468
5695
  stream.last = frame;
5469
- if (frame.meta.fecSbn !== void 0) stream.lastSbn = frame.meta.fecSbn;
5696
+ if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
5697
+ stream.lastSbn = frame.meta.fecSbn;
5698
+ }
5699
+ if (frame.meta.recovered !== true) stream.sourced = true;
5470
5700
  this.#gate.onReleased?.(frame.data, frame.meta);
5471
- this.#emit(frame.data, frame.meta);
5701
+ if (!stale) this.#emit(frame.data, frame.meta);
5472
5702
  }
5473
5703
  };
5474
5704
  var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
@@ -5729,11 +5959,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
5729
5959
  /**
5730
5960
  * Typed view of the ISO-BMFF timing-sample budget.
5731
5961
  *
5732
- * This is the acceptance signal for the budget ratchet: `pending` walking
5733
- * to `capacity` while `rejectedMovieFragments` climbs is the stream wedging,
5734
- * and it is observable here rather than only as media silently stopping.
5735
- * Per repo policy this is a producer-owned counter -- never infer budget
5736
- * state by parsing logs.
5962
+ * Each stream admits timing against its own window of `capacity` slots
5963
+ * (BLO-52085). A stream at capacity displaces its own oldest timing to
5964
+ * admit the moof in hand, and `evicted` counts the slots so displaced:
5965
+ * timing a stream declared and never delivered shows up there. `pending`
5966
+ * sums every stream, so it can exceed `capacity`. Per repo policy this is
5967
+ * a producer-owned counter -- never infer budget state by parsing logs.
5737
5968
  */
5738
5969
  get timingBudgetStats() {
5739
5970
  return {
@@ -5793,6 +6024,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
5793
6024
  fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
5794
6025
  return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
5795
6026
  }
6027
+ /** See FecReleaseSequencer.unsource. */
6028
+ unsourceFecRelease(packetId, catalogTrackName) {
6029
+ this.#fecSequencer?.unsource(packetId, catalogTrackName);
6030
+ }
6031
+ /** See FecReleaseSequencer.holdsRebuilt. */
6032
+ fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
6033
+ return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
6034
+ }
5796
6035
  /** Re-evaluate held gaps after FEC block state changed. */
5797
6036
  pokeFecRelease(packetId, catalogTrackName) {
5798
6037
  if (!this.#fecSequencer) return;
@@ -6046,7 +6285,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6046
6285
  if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
6047
6286
  const pendingBefore = resolver2.pendingSampleCount;
6048
6287
  const evictedBefore = resolver2.evictedSampleCount;
6049
- const remaining = this.#maxPendingTimingSamples - this.#pendingTimingSamples;
6288
+ const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
6050
6289
  const admitted = resolver2.addMovieFragment(
6051
6290
  mpu.mpuSequenceNumber,
6052
6291
  data,
@@ -6119,7 +6358,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6119
6358
  info,
6120
6359
  resolver,
6121
6360
  options?.recovered === true,
6122
- options?.fecSbn
6361
+ options?.fecSbn,
6362
+ options?.fecSbnFirst
6123
6363
  );
6124
6364
  if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
6125
6365
  }
@@ -6212,7 +6452,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6212
6452
  info,
6213
6453
  resolver,
6214
6454
  options?.recovered === true,
6215
- options?.fecSbn
6455
+ options?.fecSbn,
6456
+ options?.fecSbnFirst
6216
6457
  );
6217
6458
  if (outcome.record !== void 0) return outcome.record;
6218
6459
  return this.#drop(outcome.reason);
@@ -6232,7 +6473,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6232
6473
  * attribution exists to keep readable. Leaving the choice at the call site
6233
6474
  * is what keeps both true.
6234
6475
  */
6235
- #emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
6476
+ #emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
6236
6477
  const timing = resolver.sampleTiming(
6237
6478
  combined.mpuSequenceNumber,
6238
6479
  combined.movieFragmentSequenceNumber,
@@ -6249,6 +6490,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6249
6490
  );
6250
6491
  if (!meta) return { reason: "combined-meta-build-failed" };
6251
6492
  if (fecSbn !== void 0) meta.fecSbn = fecSbn;
6493
+ if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
6252
6494
  if (!resolver.consumeSample(
6253
6495
  combined.mpuSequenceNumber,
6254
6496
  combined.movieFragmentSequenceNumber,