@blockcast/mmt-container 2.2.0-main.e75bbd7576a6 → 2.2.0-main.ef09fa701ea8

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 (60) hide show
  1. package/dist/browser-runtime.js +994 -162
  2. package/dist/browser-runtime.js.map +3 -3
  3. package/dist/cmaf-block-assembler.js +92 -1
  4. package/dist/cmaf-block-assembler.js.map +2 -2
  5. package/dist/codec-utils.d.ts.map +1 -1
  6. package/dist/codec-utils.js +92 -1
  7. package/dist/codec-utils.js.map +2 -2
  8. package/dist/delta-fallback-config.js.map +1 -1
  9. package/dist/fec-manager.d.ts +75 -14
  10. package/dist/fec-manager.d.ts.map +1 -1
  11. package/dist/fec-manager.js +315 -65
  12. package/dist/fec-manager.js.map +2 -2
  13. package/dist/fec-worker-setup.js.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js.map +2 -2
  17. package/dist/iso-block-locator.d.ts +39 -13
  18. package/dist/iso-block-locator.d.ts.map +1 -1
  19. package/dist/iso-block-locator.js +80 -25
  20. package/dist/iso-block-locator.js.map +2 -2
  21. package/dist/media-router.js.map +1 -1
  22. package/dist/mmtp-container-parser.d.ts +69 -10
  23. package/dist/mmtp-container-parser.d.ts.map +1 -1
  24. package/dist/mmtp-container-parser.js +226 -18
  25. package/dist/mmtp-container-parser.js.map +2 -2
  26. package/dist/mmtp-container-parser.no-modules.js +225 -19
  27. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  28. package/dist/mmtp-decode-pipeline.js +226 -18
  29. package/dist/mmtp-decode-pipeline.js.map +2 -2
  30. package/dist/mmtp-router.d.ts +20 -9
  31. package/dist/mmtp-router.d.ts.map +1 -1
  32. package/dist/mmtp-router.js +409 -51
  33. package/dist/mmtp-router.js.map +3 -3
  34. package/dist/multicast-manager.d.ts +26 -3
  35. package/dist/multicast-manager.d.ts.map +1 -1
  36. package/dist/multicast-manager.js +814 -135
  37. package/dist/multicast-manager.js.map +3 -3
  38. package/dist/multicast-transport.js +2 -2
  39. package/dist/multicast-transport.js.map +2 -2
  40. package/dist/no-modules.js +226 -18
  41. package/dist/no-modules.js.map +3 -3
  42. package/dist/repair-fetch.d.ts +38 -8
  43. package/dist/repair-fetch.d.ts.map +1 -1
  44. package/dist/repair-fetch.js +286 -27
  45. package/dist/repair-fetch.js.map +3 -3
  46. package/dist/track-session.d.ts.map +1 -1
  47. package/dist/track-session.js +1 -0
  48. package/dist/track-session.js.map +2 -2
  49. package/dist/wasm-mmtp-container-parser.js +226 -18
  50. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  51. package/package.json +5 -5
  52. package/src/codec-utils.ts +121 -1
  53. package/src/fec-manager.ts +329 -39
  54. package/src/index.ts +2 -0
  55. package/src/iso-block-locator.ts +114 -31
  56. package/src/mmtp-container-parser.ts +257 -24
  57. package/src/mmtp-router.ts +287 -58
  58. package/src/multicast-manager.ts +136 -16
  59. package/src/repair-fetch.ts +366 -50
  60. package/src/track-session.ts +3 -0
@@ -3875,9 +3875,10 @@ function isH264IntraSlice(nal) {
3875
3875
  const sliceType = readH264SliceType(nal);
3876
3876
  return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
3877
3877
  }
3878
+ var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
3878
3879
  function readH264SliceType(nal) {
3879
3880
  if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
3880
- const rbsp = removeEmulationPrevention(nal.subarray(1));
3881
+ const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
3881
3882
  const state = { bitOffset: 0 };
3882
3883
  if (readUnsignedExpGolomb(rbsp, state) === null) return null;
3883
3884
  return readUnsignedExpGolomb(rbsp, state);
@@ -4024,6 +4025,96 @@ if (void 0) {
4024
4025
  ]))).toBe(false);
4025
4026
  });
4026
4027
  });
4028
+ describe("readH264SliceType", () => {
4029
+ const wholeNalSliceType = (nal) => {
4030
+ if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
4031
+ const rbsp = removeEmulationPrevention(nal.subarray(1));
4032
+ const state = { bitOffset: 0 };
4033
+ if (readUnsignedExpGolomb(rbsp, state) === null) return null;
4034
+ return readUnsignedExpGolomb(rbsp, state);
4035
+ };
4036
+ const hex = (text) => Uint8Array.from(text.match(/../g), (byte) => parseInt(byte, 16));
4037
+ const ue = (value) => {
4038
+ const code = (value + 1).toString(2);
4039
+ return "0".repeat(code.length - 1) + code;
4040
+ };
4041
+ const sliceNal = (bits) => {
4042
+ const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
4043
+ const nal = [1];
4044
+ let zeros = 0;
4045
+ for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
4046
+ if (zeros >= 2 && byte <= 3) {
4047
+ nal.push(3);
4048
+ zeros = 0;
4049
+ }
4050
+ nal.push(byte);
4051
+ zeros = byte === 0 ? zeros + 1 : 0;
4052
+ }
4053
+ return Uint8Array.from(nal);
4054
+ };
4055
+ const x264Slices = [
4056
+ ["64x48 P", hex("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
4057
+ ["64x48 B", hex("419e414212fffeeade283707cb70f7"), 6, false],
4058
+ ["64x48 non-IDR I", hex(
4059
+ "4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
4060
+ ), 7, true],
4061
+ ["1280x720 B, escape at byte 10", hex(
4062
+ "01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
4063
+ ), 6, false],
4064
+ ["1280x720 P, escape at byte 15", hex(
4065
+ "41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
4066
+ ), 5, false],
4067
+ ["1280x720 B, escape at byte 22", hex("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
4068
+ ["7680x4320 IDR, first_mb_in_slice 97440", hex(
4069
+ "650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
4070
+ ), null, true],
4071
+ ["7680x4320 P, first_mb_in_slice 32640", hex(
4072
+ "410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
4073
+ ), 5, false],
4074
+ ["7680x4320 P, first_mb_in_slice 97440", hex(
4075
+ "410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
4076
+ ), 5, false]
4077
+ ];
4078
+ const syntheticSlices = [
4079
+ ["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
4080
+ ["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
4081
+ ["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
4082
+ ["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
4083
+ ["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
4084
+ ["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
4085
+ ["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
4086
+ ["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
4087
+ ];
4088
+ test("reads the slice_type of real and synthetic slices", () => {
4089
+ for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
4090
+ expect(readH264SliceType(nal), name).toBe(sliceType);
4091
+ }
4092
+ });
4093
+ test("matches the whole-NAL unescape at every truncation", () => {
4094
+ for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
4095
+ for (let end = 0; end <= nal.length; end++) {
4096
+ const cut = nal.subarray(0, end);
4097
+ expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
4098
+ }
4099
+ }
4100
+ });
4101
+ test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
4102
+ const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
4103
+ let seed = 1;
4104
+ const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
4105
+ for (let i = 0; i < 5e3; i++) {
4106
+ const nal = new Uint8Array(2 + next() % 63);
4107
+ nal[0] = 65;
4108
+ for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
4109
+ expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
4110
+ }
4111
+ });
4112
+ test("classifies the x264 slices as keyframes or not", () => {
4113
+ for (const [name, nal, , keyframe] of x264Slices) {
4114
+ expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
4115
+ }
4116
+ });
4117
+ });
4027
4118
  describe("avccToAnnexB", () => {
4028
4119
  test("converts with SPS/PPS on keyframe", () => {
4029
4120
  const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
@@ -5197,6 +5288,9 @@ function authoredGap(before, after) {
5197
5288
  function ssIdAfter(a, b) {
5198
5289
  return (a - b | 0) > 0;
5199
5290
  }
5291
+ function holdsRebuilt(stream) {
5292
+ return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
5293
+ }
5200
5294
  var FecReleaseSequencer = class {
5201
5295
  #streams = /* @__PURE__ */ new Map();
5202
5296
  #gate;
@@ -5259,6 +5353,7 @@ var FecReleaseSequencer = class {
5259
5353
  stream.lastSbn = void 0;
5260
5354
  stream.discontinuity = false;
5261
5355
  stream.rapSsId = void 0;
5356
+ stream.sourced = false;
5262
5357
  }
5263
5358
  if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
5264
5359
  this.#recordStat("droppedStale");
@@ -5285,6 +5380,7 @@ var FecReleaseSequencer = class {
5285
5380
  if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
5286
5381
  else hi = mid;
5287
5382
  }
5383
+ if (stream.buf[lo]?.passed === true) frame.passed = true;
5288
5384
  stream.buf.splice(lo, 0, frame);
5289
5385
  this.#drainUnlessDeferred(stream);
5290
5386
  }
@@ -5320,6 +5416,41 @@ var FecReleaseSequencer = class {
5320
5416
  }
5321
5417
  return false;
5322
5418
  }
5419
+ /**
5420
+ * These streams' sink is being replaced by one that has seen no source
5421
+ * frame yet. First, from a stream that holds a frame the overlay rebuilt,
5422
+ * release to the sink being replaced the frames the unanchored path had
5423
+ * already released to it (#cursorPassed): there they waited in its queue,
5424
+ * which its replacement flushes. A stream that holds none is not drained:
5425
+ * it holds nothing the anchor kept back, and a drain would still force out
5426
+ * a frame held past the hold limit, which before the anchor waited for the
5427
+ * next push. Then treat the streams as unsourced until a source frame is
5428
+ * released.
5429
+ */
5430
+ unsource(packetId, catalogTrackName) {
5431
+ for (const stream of this.#streams.values()) {
5432
+ if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
5433
+ if (stream.draining === 0 && holdsRebuilt(stream)) {
5434
+ if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
5435
+ else this.#drain(stream, true);
5436
+ }
5437
+ stream.sourced = false;
5438
+ }
5439
+ }
5440
+ }
5441
+ /**
5442
+ * Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
5443
+ * (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
5444
+ * packetId.
5445
+ */
5446
+ holdsRebuilt(packetId, catalogTrackName) {
5447
+ for (const stream of this.#streams.values()) {
5448
+ if (stream.packetId !== packetId) continue;
5449
+ if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
5450
+ if (holdsRebuilt(stream)) return true;
5451
+ }
5452
+ return false;
5453
+ }
5323
5454
  /** Re-evaluate held gaps after FEC state changed. */
5324
5455
  poke(streamKey) {
5325
5456
  if (streamKey !== void 0) {
@@ -5411,16 +5542,32 @@ var FecReleaseSequencer = class {
5411
5542
  last: null,
5412
5543
  lastSbn: void 0,
5413
5544
  discontinuity: false,
5414
- rapSsId: void 0
5545
+ rapSsId: void 0,
5546
+ sourced: false,
5547
+ draining: 0
5415
5548
  };
5416
5549
  this.#streams.set(streamKey, stream);
5417
5550
  }
5418
5551
  return stream;
5419
5552
  }
5420
- #drain(stream) {
5553
+ /** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
5554
+ #drain(stream, asUnanchored = false) {
5555
+ stream.draining++;
5556
+ try {
5557
+ this.#drainLoop(stream, asUnanchored);
5558
+ } finally {
5559
+ stream.draining--;
5560
+ }
5561
+ }
5562
+ #drainLoop(stream, asUnanchored) {
5421
5563
  while (stream.buf.length > 0 && stream.last !== null) {
5422
5564
  const head = stream.buf[0];
5423
5565
  const last = stream.last;
5566
+ if (compareFrameOrder(head, last) <= 0) {
5567
+ stream.buf.shift();
5568
+ this.#release(stream, head, void 0);
5569
+ continue;
5570
+ }
5424
5571
  if (stream.discontinuity) {
5425
5572
  stream.discontinuity = false;
5426
5573
  stream.buf.shift();
@@ -5434,9 +5581,10 @@ var FecReleaseSequencer = class {
5434
5581
  }
5435
5582
  const headSbn = head.meta.fecSbn;
5436
5583
  const from = stream.lastSbn ?? headSbn;
5437
- const to = headSbn ?? stream.lastSbn;
5584
+ const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
5438
5585
  let lost = [];
5439
5586
  const unanchored = from === void 0 && to === void 0;
5587
+ let unresolved = false;
5440
5588
  if (from !== void 0 && to !== void 0) {
5441
5589
  const resolved = this.#gate.resolvedLoss(
5442
5590
  stream.packetId,
@@ -5445,7 +5593,8 @@ var FecReleaseSequencer = class {
5445
5593
  Math.max(from, to),
5446
5594
  from
5447
5595
  );
5448
- if (resolved === null) {
5596
+ unresolved = resolved === null;
5597
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
5449
5598
  const heldMs = performance.now() - head.arrivedAtMs;
5450
5599
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
5451
5600
  this.#recordStat("forcedWindowFlushes");
@@ -5453,22 +5602,69 @@ var FecReleaseSequencer = class {
5453
5602
  this.#release(stream, head, this.#gate.decide(last, head, [], true));
5454
5603
  continue;
5455
5604
  }
5456
- lost = resolved;
5605
+ lost = resolved ?? [];
5457
5606
  }
5458
5607
  stream.buf.shift();
5459
5608
  this.#release(
5460
5609
  stream,
5461
5610
  head,
5462
- lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5611
+ lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5463
5612
  );
5464
5613
  }
5465
5614
  }
5615
+ /**
5616
+ * The head has waited out a gap only a late source can still fill
5617
+ * (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
5618
+ * the stream when it has (`wakeAt`), since no packet may come by then.
5619
+ */
5620
+ #unrepairableWaitOver(stream, last, head, from, to) {
5621
+ const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
5622
+ if (waitMs === void 0) return false;
5623
+ const atMs = head.arrivedAtMs + waitMs;
5624
+ if (performance.now() >= atMs) return true;
5625
+ this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
5626
+ return false;
5627
+ }
5628
+ /**
5629
+ * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
5630
+ * source cursor holds it unanchored, and neither does a later frame behind
5631
+ * it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
5632
+ * fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
5633
+ * like each frame that arrived in front of it since (stale there). The head
5634
+ * then goes, decided as it would be unanchored, once a frame the base path
5635
+ * delivered (a source frame, or one base FEC recovered) is buffered after a
5636
+ * marked one: the base path has passed that one, so a frame still missing
5637
+ * before it can only come from a repair. It also goes while no source frame
5638
+ * has been released, when the direct path shows a recovered frame at once.
5639
+ * And it goes at once while a staged switch decides on when frames arrive
5640
+ * (FecReleaseGate.releaseUnanchored), and when unsource releases into a
5641
+ * sink being replaced: unanchored, it had already reached the sink.
5642
+ * The scan also writes: the `passed` marks it sets stay on the frames,
5643
+ * and push marks a frame it inserts in front of a marked one from them.
5644
+ */
5645
+ #cursorPassed(stream, asUnanchored) {
5646
+ let at = -1;
5647
+ for (let i = 0; i < stream.buf.length; i++) {
5648
+ const frame = stream.buf[i];
5649
+ if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
5650
+ frame.passed = true;
5651
+ if (at < 0) at = i;
5652
+ } else if (frame.passed !== true) break;
5653
+ }
5654
+ if (at < 0) return false;
5655
+ 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));
5656
+ }
5466
5657
  #release(stream, frame, decision) {
5658
+ const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
5659
+ if (stale) this.#recordStat("droppedStale");
5467
5660
  if (decision) frame.meta.gapBefore = decision;
5468
5661
  stream.last = frame;
5469
- if (frame.meta.fecSbn !== void 0) stream.lastSbn = frame.meta.fecSbn;
5662
+ if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
5663
+ stream.lastSbn = frame.meta.fecSbn;
5664
+ }
5665
+ if (frame.meta.recovered !== true) stream.sourced = true;
5470
5666
  this.#gate.onReleased?.(frame.data, frame.meta);
5471
- this.#emit(frame.data, frame.meta);
5667
+ if (!stale) this.#emit(frame.data, frame.meta);
5472
5668
  }
5473
5669
  };
5474
5670
  var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
@@ -5729,11 +5925,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
5729
5925
  /**
5730
5926
  * Typed view of the ISO-BMFF timing-sample budget.
5731
5927
  *
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.
5928
+ * Each stream admits timing against its own window of `capacity` slots
5929
+ * (BLO-52085). A stream at capacity displaces its own oldest timing to
5930
+ * admit the moof in hand, and `evicted` counts the slots so displaced:
5931
+ * timing a stream declared and never delivered shows up there. `pending`
5932
+ * sums every stream, so it can exceed `capacity`. Per repo policy this is
5933
+ * a producer-owned counter -- never infer budget state by parsing logs.
5737
5934
  */
5738
5935
  get timingBudgetStats() {
5739
5936
  return {
@@ -5793,6 +5990,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
5793
5990
  fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
5794
5991
  return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
5795
5992
  }
5993
+ /** See FecReleaseSequencer.unsource. */
5994
+ unsourceFecRelease(packetId, catalogTrackName) {
5995
+ this.#fecSequencer?.unsource(packetId, catalogTrackName);
5996
+ }
5997
+ /** See FecReleaseSequencer.holdsRebuilt. */
5998
+ fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
5999
+ return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
6000
+ }
5796
6001
  /** Re-evaluate held gaps after FEC block state changed. */
5797
6002
  pokeFecRelease(packetId, catalogTrackName) {
5798
6003
  if (!this.#fecSequencer) return;
@@ -6046,7 +6251,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6046
6251
  if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
6047
6252
  const pendingBefore = resolver2.pendingSampleCount;
6048
6253
  const evictedBefore = resolver2.evictedSampleCount;
6049
- const remaining = this.#maxPendingTimingSamples - this.#pendingTimingSamples;
6254
+ const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
6050
6255
  const admitted = resolver2.addMovieFragment(
6051
6256
  mpu.mpuSequenceNumber,
6052
6257
  data,
@@ -6119,7 +6324,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6119
6324
  info,
6120
6325
  resolver,
6121
6326
  options?.recovered === true,
6122
- options?.fecSbn
6327
+ options?.fecSbn,
6328
+ options?.fecSbnFirst
6123
6329
  );
6124
6330
  if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
6125
6331
  }
@@ -6212,7 +6418,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6212
6418
  info,
6213
6419
  resolver,
6214
6420
  options?.recovered === true,
6215
- options?.fecSbn
6421
+ options?.fecSbn,
6422
+ options?.fecSbnFirst
6216
6423
  );
6217
6424
  if (outcome.record !== void 0) return outcome.record;
6218
6425
  return this.#drop(outcome.reason);
@@ -6232,7 +6439,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6232
6439
  * attribution exists to keep readable. Leaving the choice at the call site
6233
6440
  * is what keeps both true.
6234
6441
  */
6235
- #emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
6442
+ #emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
6236
6443
  const timing = resolver.sampleTiming(
6237
6444
  combined.mpuSequenceNumber,
6238
6445
  combined.movieFragmentSequenceNumber,
@@ -6249,6 +6456,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6249
6456
  );
6250
6457
  if (!meta) return { reason: "combined-meta-build-failed" };
6251
6458
  if (fecSbn !== void 0) meta.fecSbn = fecSbn;
6459
+ if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
6252
6460
  if (!resolver.consumeSample(
6253
6461
  combined.mpuSequenceNumber,
6254
6462
  combined.movieFragmentSequenceNumber,