@blockcast/mmt-container 2.2.0-main.75b39a2cdddf → 2.2.0-main.7e8a9d13c01c

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 (52) hide show
  1. package/dist/browser-runtime.js +634 -129
  2. package/dist/browser-runtime.js.map +3 -3
  3. package/dist/delta-fallback-config.js.map +1 -1
  4. package/dist/fec-manager.d.ts +37 -11
  5. package/dist/fec-manager.d.ts.map +1 -1
  6. package/dist/fec-manager.js +181 -52
  7. package/dist/fec-manager.js.map +2 -2
  8. package/dist/fec-worker-setup.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +2 -2
  12. package/dist/iso-block-locator.d.ts +39 -13
  13. package/dist/iso-block-locator.d.ts.map +1 -1
  14. package/dist/iso-block-locator.js +80 -25
  15. package/dist/iso-block-locator.js.map +2 -2
  16. package/dist/media-router.js.map +1 -1
  17. package/dist/mmtp-container-parser.d.ts +21 -0
  18. package/dist/mmtp-container-parser.d.ts.map +1 -1
  19. package/dist/mmtp-container-parser.js +114 -11
  20. package/dist/mmtp-container-parser.js.map +2 -2
  21. package/dist/mmtp-container-parser.no-modules.js +113 -12
  22. package/dist/mmtp-container-parser.no-modules.js.map +2 -2
  23. package/dist/mmtp-decode-pipeline.js +114 -11
  24. package/dist/mmtp-decode-pipeline.js.map +2 -2
  25. package/dist/mmtp-router.d.ts +18 -9
  26. package/dist/mmtp-router.d.ts.map +1 -1
  27. package/dist/mmtp-router.js +254 -44
  28. package/dist/mmtp-router.js.map +2 -2
  29. package/dist/multicast-manager.d.ts +13 -3
  30. package/dist/multicast-manager.d.ts.map +1 -1
  31. package/dist/multicast-manager.js +455 -103
  32. package/dist/multicast-manager.js.map +2 -2
  33. package/dist/no-modules.js +114 -11
  34. package/dist/no-modules.js.map +2 -2
  35. package/dist/repair-fetch.d.ts +36 -8
  36. package/dist/repair-fetch.d.ts.map +1 -1
  37. package/dist/repair-fetch.js +285 -26
  38. package/dist/repair-fetch.js.map +3 -3
  39. package/dist/track-session.d.ts.map +1 -1
  40. package/dist/track-session.js +1 -0
  41. package/dist/track-session.js.map +2 -2
  42. package/dist/wasm-mmtp-container-parser.js +114 -11
  43. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  44. package/package.json +5 -5
  45. package/src/fec-manager.ts +156 -26
  46. package/src/index.ts +2 -0
  47. package/src/iso-block-locator.ts +114 -31
  48. package/src/mmtp-container-parser.ts +181 -10
  49. package/src/mmtp-router.ts +231 -58
  50. package/src/multicast-manager.ts +44 -6
  51. package/src/repair-fetch.ts +363 -49
  52. package/src/track-session.ts +3 -0
@@ -5197,6 +5197,9 @@ function authoredGap(before, after) {
5197
5197
  function ssIdAfter(a, b) {
5198
5198
  return (a - b | 0) > 0;
5199
5199
  }
5200
+ function holdsRebuilt(stream) {
5201
+ return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
5202
+ }
5200
5203
  var FecReleaseSequencer = class {
5201
5204
  #streams = /* @__PURE__ */ new Map();
5202
5205
  #gate;
@@ -5259,6 +5262,7 @@ var FecReleaseSequencer = class {
5259
5262
  stream.lastSbn = void 0;
5260
5263
  stream.discontinuity = false;
5261
5264
  stream.rapSsId = void 0;
5265
+ stream.sourced = false;
5262
5266
  }
5263
5267
  if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
5264
5268
  this.#recordStat("droppedStale");
@@ -5285,6 +5289,7 @@ var FecReleaseSequencer = class {
5285
5289
  if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
5286
5290
  else hi = mid;
5287
5291
  }
5292
+ if (stream.buf[lo]?.passed === true) frame.passed = true;
5288
5293
  stream.buf.splice(lo, 0, frame);
5289
5294
  this.#drainUnlessDeferred(stream);
5290
5295
  }
@@ -5320,6 +5325,41 @@ var FecReleaseSequencer = class {
5320
5325
  }
5321
5326
  return false;
5322
5327
  }
5328
+ /**
5329
+ * These streams' sink is being replaced by one that has seen no source
5330
+ * frame yet. First, from a stream that holds a frame the overlay rebuilt,
5331
+ * release to the sink being replaced the frames the unanchored path had
5332
+ * already released to it (#cursorPassed): there they waited in its queue,
5333
+ * which its replacement flushes. A stream that holds none is not drained:
5334
+ * it holds nothing the anchor kept back, and a drain would still force out
5335
+ * a frame held past the hold limit, which before the anchor waited for the
5336
+ * next push. Then treat the streams as unsourced until a source frame is
5337
+ * released.
5338
+ */
5339
+ unsource(packetId, catalogTrackName) {
5340
+ for (const stream of this.#streams.values()) {
5341
+ if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
5342
+ if (stream.draining === 0 && holdsRebuilt(stream)) {
5343
+ if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
5344
+ else this.#drain(stream, true);
5345
+ }
5346
+ stream.sourced = false;
5347
+ }
5348
+ }
5349
+ }
5350
+ /**
5351
+ * Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
5352
+ * (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
5353
+ * packetId.
5354
+ */
5355
+ holdsRebuilt(packetId, catalogTrackName) {
5356
+ for (const stream of this.#streams.values()) {
5357
+ if (stream.packetId !== packetId) continue;
5358
+ if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
5359
+ if (holdsRebuilt(stream)) return true;
5360
+ }
5361
+ return false;
5362
+ }
5323
5363
  /** Re-evaluate held gaps after FEC state changed. */
5324
5364
  poke(streamKey) {
5325
5365
  if (streamKey !== void 0) {
@@ -5411,16 +5451,32 @@ var FecReleaseSequencer = class {
5411
5451
  last: null,
5412
5452
  lastSbn: void 0,
5413
5453
  discontinuity: false,
5414
- rapSsId: void 0
5454
+ rapSsId: void 0,
5455
+ sourced: false,
5456
+ draining: 0
5415
5457
  };
5416
5458
  this.#streams.set(streamKey, stream);
5417
5459
  }
5418
5460
  return stream;
5419
5461
  }
5420
- #drain(stream) {
5462
+ /** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
5463
+ #drain(stream, asUnanchored = false) {
5464
+ stream.draining++;
5465
+ try {
5466
+ this.#drainLoop(stream, asUnanchored);
5467
+ } finally {
5468
+ stream.draining--;
5469
+ }
5470
+ }
5471
+ #drainLoop(stream, asUnanchored) {
5421
5472
  while (stream.buf.length > 0 && stream.last !== null) {
5422
5473
  const head = stream.buf[0];
5423
5474
  const last = stream.last;
5475
+ if (compareFrameOrder(head, last) <= 0) {
5476
+ stream.buf.shift();
5477
+ this.#release(stream, head, void 0);
5478
+ continue;
5479
+ }
5424
5480
  if (stream.discontinuity) {
5425
5481
  stream.discontinuity = false;
5426
5482
  stream.buf.shift();
@@ -5434,9 +5490,10 @@ var FecReleaseSequencer = class {
5434
5490
  }
5435
5491
  const headSbn = head.meta.fecSbn;
5436
5492
  const from = stream.lastSbn ?? headSbn;
5437
- const to = headSbn ?? stream.lastSbn;
5493
+ const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
5438
5494
  let lost = [];
5439
5495
  const unanchored = from === void 0 && to === void 0;
5496
+ let unresolved = false;
5440
5497
  if (from !== void 0 && to !== void 0) {
5441
5498
  const resolved = this.#gate.resolvedLoss(
5442
5499
  stream.packetId,
@@ -5445,7 +5502,8 @@ var FecReleaseSequencer = class {
5445
5502
  Math.max(from, to),
5446
5503
  from
5447
5504
  );
5448
- if (resolved === null) {
5505
+ unresolved = resolved === null;
5506
+ if (unresolved && !this.#cursorPassed(stream, asUnanchored)) {
5449
5507
  const heldMs = performance.now() - head.arrivedAtMs;
5450
5508
  if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
5451
5509
  this.#recordStat("forcedWindowFlushes");
@@ -5453,22 +5511,56 @@ var FecReleaseSequencer = class {
5453
5511
  this.#release(stream, head, this.#gate.decide(last, head, [], true));
5454
5512
  continue;
5455
5513
  }
5456
- lost = resolved;
5514
+ lost = resolved ?? [];
5457
5515
  }
5458
5516
  stream.buf.shift();
5459
5517
  this.#release(
5460
5518
  stream,
5461
5519
  head,
5462
- lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5520
+ lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
5463
5521
  );
5464
5522
  }
5465
5523
  }
5524
+ /**
5525
+ * An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
5526
+ * source cursor holds it unanchored, and neither does a later frame behind
5527
+ * it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
5528
+ * fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
5529
+ * like each frame that arrived in front of it since (stale there). The head
5530
+ * then goes, decided as it would be unanchored, once a frame the base path
5531
+ * delivered (a source frame, or one base FEC recovered) is buffered after a
5532
+ * marked one: the base path has passed that one, so a frame still missing
5533
+ * before it can only come from a repair. It also goes while no source frame
5534
+ * has been released, when the direct path shows a recovered frame at once.
5535
+ * And it goes at once while a staged switch decides on when frames arrive
5536
+ * (FecReleaseGate.releaseUnanchored), and when unsource releases into a
5537
+ * sink being replaced: unanchored, it had already reached the sink.
5538
+ * The scan also writes: the `passed` marks it sets stay on the frames,
5539
+ * and push marks a frame it inserts in front of a marked one from them.
5540
+ */
5541
+ #cursorPassed(stream, asUnanchored) {
5542
+ let at = -1;
5543
+ for (let i = 0; i < stream.buf.length; i++) {
5544
+ const frame = stream.buf[i];
5545
+ if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
5546
+ frame.passed = true;
5547
+ if (at < 0) at = i;
5548
+ } else if (frame.passed !== true) break;
5549
+ }
5550
+ if (at < 0) return false;
5551
+ 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));
5552
+ }
5466
5553
  #release(stream, frame, decision) {
5554
+ const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
5555
+ if (stale) this.#recordStat("droppedStale");
5467
5556
  if (decision) frame.meta.gapBefore = decision;
5468
5557
  stream.last = frame;
5469
- if (frame.meta.fecSbn !== void 0) stream.lastSbn = frame.meta.fecSbn;
5558
+ if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
5559
+ stream.lastSbn = frame.meta.fecSbn;
5560
+ }
5561
+ if (frame.meta.recovered !== true) stream.sourced = true;
5470
5562
  this.#gate.onReleased?.(frame.data, frame.meta);
5471
- this.#emit(frame.data, frame.meta);
5563
+ if (!stale) this.#emit(frame.data, frame.meta);
5472
5564
  }
5473
5565
  };
5474
5566
  var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
@@ -5794,6 +5886,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
5794
5886
  fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
5795
5887
  return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
5796
5888
  }
5889
+ /** See FecReleaseSequencer.unsource. */
5890
+ unsourceFecRelease(packetId, catalogTrackName) {
5891
+ this.#fecSequencer?.unsource(packetId, catalogTrackName);
5892
+ }
5893
+ /** See FecReleaseSequencer.holdsRebuilt. */
5894
+ fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
5895
+ return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
5896
+ }
5797
5897
  /** Re-evaluate held gaps after FEC block state changed. */
5798
5898
  pokeFecRelease(packetId, catalogTrackName) {
5799
5899
  if (!this.#fecSequencer) return;
@@ -6120,7 +6220,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6120
6220
  info,
6121
6221
  resolver,
6122
6222
  options?.recovered === true,
6123
- options?.fecSbn
6223
+ options?.fecSbn,
6224
+ options?.fecSbnFirst
6124
6225
  );
6125
6226
  if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
6126
6227
  }
@@ -6213,7 +6314,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
6213
6314
  info,
6214
6315
  resolver,
6215
6316
  options?.recovered === true,
6216
- options?.fecSbn
6317
+ options?.fecSbn,
6318
+ options?.fecSbnFirst
6217
6319
  );
6218
6320
  if (outcome.record !== void 0) return outcome.record;
6219
6321
  return this.#drop(outcome.reason);
@@ -6233,7 +6335,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6233
6335
  * attribution exists to keep readable. Leaving the choice at the call site
6234
6336
  * is what keeps both true.
6235
6337
  */
6236
- #emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
6338
+ #emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
6237
6339
  const timing = resolver.sampleTiming(
6238
6340
  combined.mpuSequenceNumber,
6239
6341
  combined.movieFragmentSequenceNumber,
@@ -6250,6 +6352,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
6250
6352
  );
6251
6353
  if (!meta) return { reason: "combined-meta-build-failed" };
6252
6354
  if (fecSbn !== void 0) meta.fecSbn = fecSbn;
6355
+ if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
6253
6356
  if (!resolver.consumeSample(
6254
6357
  combined.mpuSequenceNumber,
6255
6358
  combined.movieFragmentSequenceNumber,