@blockcast/mmt-container 2.2.0-main.5da4e39e7fb8 → 2.2.0-main.5e3e277b4606

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 (48) hide show
  1. package/dist/__tests__/test-utils.d.ts +1 -0
  2. package/dist/__tests__/test-utils.d.ts.map +1 -1
  3. package/dist/block-policy.d.ts +12 -4
  4. package/dist/block-policy.d.ts.map +1 -1
  5. package/dist/block-policy.js +148 -19
  6. package/dist/block-policy.js.map +2 -2
  7. package/dist/browser-runtime.js +202 -45
  8. package/dist/browser-runtime.js.map +3 -3
  9. package/dist/carp-catalog.js.map +1 -1
  10. package/dist/catalog-network-source.d.ts +1 -17
  11. package/dist/catalog-network-source.d.ts.map +1 -1
  12. package/dist/catalog-network-source.js +25 -19
  13. package/dist/catalog-network-source.js.map +3 -3
  14. package/dist/fec-manager.js +148 -19
  15. package/dist/fec-manager.js.map +2 -2
  16. package/dist/mmtp-container-parser.d.ts +2 -0
  17. package/dist/mmtp-container-parser.d.ts.map +1 -1
  18. package/dist/mmtp-container-parser.js +1 -0
  19. package/dist/mmtp-container-parser.js.map +2 -2
  20. package/dist/mmtp-container-parser.no-modules.js +26 -19
  21. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  22. package/dist/mmtp-decode-pipeline.js +1 -0
  23. package/dist/mmtp-decode-pipeline.js.map +2 -2
  24. package/dist/mmtp-router.d.ts.map +1 -1
  25. package/dist/mmtp-router.js +3 -1
  26. package/dist/mmtp-router.js.map +2 -2
  27. package/dist/multicast-auth-catalog.js.map +1 -1
  28. package/dist/multicast-input.js.map +1 -1
  29. package/dist/multicast-manager.d.ts +9 -1
  30. package/dist/multicast-manager.d.ts.map +1 -1
  31. package/dist/multicast-manager.js +154 -21
  32. package/dist/multicast-manager.js.map +2 -2
  33. package/dist/no-modules.js +26 -19
  34. package/dist/no-modules.js.map +4 -4
  35. package/dist/repair-fetch.d.ts +3 -1
  36. package/dist/repair-fetch.d.ts.map +1 -1
  37. package/dist/repair-fetch.js +31 -5
  38. package/dist/repair-fetch.js.map +2 -2
  39. package/dist/wasm-mmtp-container-parser.js +1 -0
  40. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  41. package/package.json +5 -5
  42. package/src/block-policy.ts +206 -29
  43. package/src/catalog-network-source.ts +3 -37
  44. package/src/mmtp-container-parser.ts +3 -0
  45. package/src/mmtp-router.ts +1 -0
  46. package/src/multicast-manager.ts +10 -0
  47. package/src/repair-fetch.ts +46 -6
  48. package/test-vectors/repair-policy-v1.json +36 -3
@@ -1374,6 +1374,23 @@ function multicastCatalogIssues(catalog, options = {}) {
1374
1374
  }
1375
1375
  return issues;
1376
1376
  }
1377
+ function catalogAtsc3NetworkSource(networkSource) {
1378
+ const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
1379
+ for (const ns of entries) {
1380
+ if (!isObject(ns))
1381
+ continue;
1382
+ if (ns.type !== "atsc3" || !isIntegerIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER))
1383
+ continue;
1384
+ const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
1385
+ return {
1386
+ frequency: ns.frequency,
1387
+ ...isIntegerIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
1388
+ ...isIntegerIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
1389
+ ...slsUri ? { slsUri } : {}
1390
+ };
1391
+ }
1392
+ return void 0;
1393
+ }
1377
1394
 
1378
1395
  // ../mmt-base/dist/fec-catalog.js
1379
1396
  var DEFAULT_SCHEMES = ["reed-solomon", "raptorq"];
@@ -13778,6 +13795,16 @@ function keyframeInstantBetween(start, interval, from, to) {
13778
13795
  function compareDataUnitStarts(a, b) {
13779
13796
  return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
13780
13797
  }
13798
+ function firstStartAtOrAfter(starts, sbn) {
13799
+ let lo = 0;
13800
+ let hi = starts.length;
13801
+ while (lo < hi) {
13802
+ const mid = lo + hi >>> 1;
13803
+ if (starts[mid].sbn < sbn) lo = mid + 1;
13804
+ else hi = mid;
13805
+ }
13806
+ return lo;
13807
+ }
13781
13808
  var LATE_RAP_MAX_MPUS_BACK = 64;
13782
13809
  var UNPLACED = { rapNotMpuStart: false };
13783
13810
  var BlockClassifier = class {
@@ -13802,6 +13829,15 @@ var BlockClassifier = class {
13802
13829
  #mpuSbnSpans = /* @__PURE__ */ new Map();
13803
13830
  #dataUnitStarts = /* @__PURE__ */ new Map();
13804
13831
  #highestMpu = null;
13832
+ /**
13833
+ * The DU headers held, per MPU in authored order, for the run rule. Kept in
13834
+ * every mode (the rule needs no catalog cadence) for the same horizon and
13835
+ * the same continuous SBN sequence as the P1 ledger.
13836
+ */
13837
+ #runStarts = /* @__PURE__ */ new Map();
13838
+ #runHighestMpu = null;
13839
+ /** Two DU headers of this sequence lay in blocks against their authored order: no run is read. */
13840
+ #runOrderRefuted = false;
13805
13841
  /**
13806
13842
  * P3 layout, kept for the MPUs within the classification horizon and valid
13807
13843
  * within one continuous SBN sequence (`noteSourceDiscontinuity`).
@@ -13909,6 +13945,7 @@ var BlockClassifier = class {
13909
13945
  if (this.#geometry.trackKind === "audio") return [];
13910
13946
  const changes = [];
13911
13947
  const block = this.#blockFor(sbn);
13948
+ const fragmentsCountedSamples = !this.#multiSampleFragment;
13912
13949
  const placement = this.#place(evidence);
13913
13950
  if (evidence.rap) block.rapSeen = true;
13914
13951
  if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
@@ -13920,19 +13957,31 @@ var BlockClassifier = class {
13920
13957
  if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
13921
13958
  const violation = this.#checkInvariants(sbn, block, evidence, placement);
13922
13959
  if (violation !== null) changes.push(...this.#disable(violation));
13923
- const next = this.#classify(block);
13924
- if (next !== block.cls && this.#allowed(block.cls, next)) {
13925
- changes.push({
13926
- kind: "reclassified",
13927
- sbn,
13928
- from: block.cls,
13929
- to: next,
13930
- evidence: this.#evidenceFor(block, next)
13931
- });
13932
- block.cls = next;
13960
+ const orderHeld = !this.#runOrderRefuted;
13961
+ const bounded = this.#noteRunStart(sbn, evidence, position);
13962
+ if (orderHeld && this.#runOrderRefuted || fragmentsCountedSamples && this.#multiSampleFragment) {
13963
+ for (const [other, classed] of this.#blocks) {
13964
+ if (classed.cls !== "delta") continue;
13965
+ classed.cls = "unknown";
13966
+ changes.push({ kind: "reclassified", sbn: other, from: "delta", to: "unknown", evidence: "classifier-disabled" });
13967
+ }
13933
13968
  }
13969
+ this.#reclassify(sbn, block, changes);
13970
+ for (const other of bounded) this.#reclassify(other, this.#blocks.get(other), changes);
13934
13971
  return changes;
13935
13972
  }
13973
+ #reclassify(sbn, block, changes) {
13974
+ const next = this.#classify(block, sbn);
13975
+ if (next === block.cls || !this.#allowed(block.cls, next)) return;
13976
+ changes.push({
13977
+ kind: "reclassified",
13978
+ sbn,
13979
+ from: block.cls,
13980
+ to: next,
13981
+ evidence: this.#evidenceFor(block, next)
13982
+ });
13983
+ block.cls = next;
13984
+ }
13936
13985
  /**
13937
13986
  * Record a RAP frame released in order. Released MPU-start RAPs of MPUs m
13938
13987
  * and m+n must be exactly n keyframe intervals apart in the media
@@ -14091,6 +14140,9 @@ var BlockClassifier = class {
14091
14140
  this.#mpuSbnSpans.clear();
14092
14141
  this.#dataUnitStarts.clear();
14093
14142
  this.#highestMpu = null;
14143
+ this.#runStarts.clear();
14144
+ this.#runHighestMpu = null;
14145
+ this.#runOrderRefuted = false;
14094
14146
  }
14095
14147
  /**
14096
14148
  * P1 check for one source packet of MPU `mpu` in block `sbn`, then record
@@ -14181,18 +14233,112 @@ var BlockClassifier = class {
14181
14233
  }
14182
14234
  return changes;
14183
14235
  }
14184
- #classify(block) {
14236
+ #classify(block, sbn) {
14185
14237
  if (block.rapSeen || block.mpus.size >= 2) return "keyframe";
14186
- if (this.#mode === "all-protected") return "unknown";
14238
+ if (block.cls === "delta") return "delta";
14239
+ if (this.#windowHolds(block) || this.#runHolds(block, sbn)) return "delta";
14240
+ return "unknown";
14241
+ }
14242
+ #windowHolds(block) {
14243
+ if (this.#mode === "all-protected") return false;
14187
14244
  const geometry2 = this.#geometry;
14188
- if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return "unknown";
14189
- if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
14190
- const span = geometry2.interleaveUnits - 1;
14191
- if (block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1) {
14192
- return "delta";
14193
- }
14245
+ if (geometry2.trackKind !== "video" || geometry2.mode !== "classifying") return false;
14246
+ if (block.mpus.size !== 1 || block.positionMin === void 0 || block.positionMax === void 0) {
14247
+ return false;
14194
14248
  }
14195
- return "unknown";
14249
+ const span = geometry2.interleaveUnits - 1;
14250
+ return block.positionMax - span >= 1 && block.positionMin + span <= geometry2.gopFrames - 1;
14251
+ }
14252
+ /**
14253
+ * Record a DU header for the run rule. Returns the other blocks it now
14254
+ * bounds: those between it and the DU headers next to it in authored order.
14255
+ */
14256
+ #noteRunStart(sbn, evidence, position) {
14257
+ const { mpu, idx, movieFragment } = evidence;
14258
+ if (this.#geometry.trackKind !== "video" || mpu === void 0 || idx === void 0 || movieFragment === void 0) {
14259
+ return [];
14260
+ }
14261
+ const start = {
14262
+ movieFragment,
14263
+ idx,
14264
+ offset: evidence.offset ?? 0,
14265
+ sbn,
14266
+ rap: evidence.rap,
14267
+ dep: evidence.depCounter ?? 0,
14268
+ ...position === void 0 ? {} : { position }
14269
+ };
14270
+ let starts = this.#runStarts.get(mpu);
14271
+ if (starts === void 0) {
14272
+ starts = [];
14273
+ this.#runStarts.set(mpu, starts);
14274
+ }
14275
+ let at2 = 0;
14276
+ let end = starts.length;
14277
+ while (at2 < end) {
14278
+ const mid = at2 + end >>> 1;
14279
+ if (compareDataUnitStarts(starts[mid], start) < 0) at2 = mid + 1;
14280
+ else end = mid;
14281
+ }
14282
+ if (at2 < starts.length && compareDataUnitStarts(starts[at2], start) === 0) return [];
14283
+ starts.splice(at2, 0, start);
14284
+ if (this.#runHighestMpu === null || mpu > this.#runHighestMpu) {
14285
+ this.#runHighestMpu = mpu;
14286
+ for (const other of [...this.#runStarts.keys()]) {
14287
+ if (other + 1 < mpu) this.#runStarts.delete(other);
14288
+ }
14289
+ }
14290
+ const before = starts[at2 - 1]?.sbn;
14291
+ const after = starts[at2 + 1]?.sbn;
14292
+ if (before !== void 0 && before > sbn || after !== void 0 && after < sbn) {
14293
+ this.#runOrderRefuted = true;
14294
+ return [];
14295
+ }
14296
+ const bounded = [];
14297
+ for (const other of this.#blocks.keys()) {
14298
+ if (before !== void 0 && other > before && other < sbn || after !== void 0 && other > sbn && other < after) {
14299
+ bounded.push(other);
14300
+ }
14301
+ }
14302
+ return bounded;
14303
+ }
14304
+ /**
14305
+ * The run rule of fec-multicast-01 6.1: the DU header held last before the
14306
+ * block and the one held first after it are in one MPU, the lower one is a
14307
+ * non-RAP sample start, and its dependent run reaches the upper one's
14308
+ * sample. No sample the block can carry is then a RAP.
14309
+ */
14310
+ #runHolds(block, sbn) {
14311
+ if (this.#runOrderRefuted) return false;
14312
+ let lower;
14313
+ let upper;
14314
+ let lowerMpu = 0;
14315
+ let upperMpu = 0;
14316
+ for (const [mpu, starts] of this.#runStarts) {
14317
+ const before = firstStartAtOrAfter(starts, sbn);
14318
+ const after = firstStartAtOrAfter(starts, sbn + 1);
14319
+ if (before > 0 && (lower === void 0 || mpu >= lowerMpu)) {
14320
+ lower = starts[before - 1];
14321
+ lowerMpu = mpu;
14322
+ }
14323
+ if (after < starts.length && (upper === void 0 || mpu < upperMpu)) {
14324
+ upper = starts[after];
14325
+ upperMpu = mpu;
14326
+ }
14327
+ }
14328
+ if (lower === void 0 || upper === void 0 || lowerMpu !== upperMpu) return false;
14329
+ if (block.mpus.size === 1 && !block.mpus.has(lowerMpu)) return false;
14330
+ if (lower.offset !== 0 || lower.rap || lower.dep < 1) return false;
14331
+ let samples;
14332
+ if (lower.movieFragment === upper.movieFragment) samples = upper.idx - lower.idx;
14333
+ else if (!this.#multiSampleFragment) {
14334
+ samples = upper.movieFragment - lower.movieFragment >>> 0;
14335
+ } else return false;
14336
+ if (samples < 0 || samples > lower.dep) return false;
14337
+ const geometry2 = this.#geometry;
14338
+ if (geometry2.trackKind === "video" && geometry2.mode === "classifying" && lower.position !== void 0 && upper.position !== void 0 && Math.floor(upper.position / geometry2.gopFrames) > Math.floor(lower.position / geometry2.gopFrames)) {
14339
+ return false;
14340
+ }
14341
+ return true;
14196
14342
  }
14197
14343
  #allowed(from, to) {
14198
14344
  if (from === "keyframe") return false;
@@ -14201,7 +14347,7 @@ var BlockClassifier = class {
14201
14347
  return false;
14202
14348
  }
14203
14349
  #evidenceFor(block, to) {
14204
- if (to === "delta") return "window";
14350
+ if (to === "delta") return this.#windowHolds(block) ? "window" : "dependent-run";
14205
14351
  return block.rapSeen ? "rap" : "mpu-span";
14206
14352
  }
14207
14353
  };
@@ -20116,6 +20262,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
20116
20262
  identity.sampleNumber = extraction.mfuDuHeader.sampleNumber;
20117
20263
  identity.movieFragmentSequenceNumber = extraction.mfuDuHeader.movieFragmentSequenceNumber;
20118
20264
  identity.offset = extraction.mfuDuHeader.offset;
20265
+ identity.dependencyCounter = extraction.mfuDuHeader.dependencyCounter;
20119
20266
  }
20120
20267
  return identity;
20121
20268
  } catch {
@@ -24149,7 +24296,8 @@ function sourceSymbolEvidence(packet, header, rapFlag, packetSequenceNumber) {
24149
24296
  ...identity === null ? {} : { mpu: identity.mpuSequenceNumber },
24150
24297
  ...identity?.sampleNumber !== void 0 && identity.sampleNumber >= 1 ? { idx: identity.sampleNumber - 1 } : {},
24151
24298
  ...identity?.movieFragmentSequenceNumber !== void 0 ? { movieFragment: identity.movieFragmentSequenceNumber } : {},
24152
- ...identity?.offset !== void 0 ? { offset: identity.offset } : {}
24299
+ ...identity?.offset !== void 0 ? { offset: identity.offset } : {},
24300
+ ...identity?.dependencyCounter ? { depCounter: identity.dependencyCounter } : {}
24153
24301
  };
24154
24302
  }
24155
24303
  var MmtpRouter = class {
@@ -29234,25 +29382,6 @@ function catalogAmtNetworkSource(networkSource) {
29234
29382
  }
29235
29383
  return void 0;
29236
29384
  }
29237
- function intIn2(value, min, max) {
29238
- return Number.isInteger(value) && value >= min && value <= max;
29239
- }
29240
- function catalogAtsc3NetworkSource(networkSource) {
29241
- const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
29242
- for (const raw of entries) {
29243
- if (!raw || typeof raw !== "object") continue;
29244
- const ns = raw;
29245
- if (ns.type !== "atsc3" || !intIn2(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
29246
- const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
29247
- return {
29248
- frequency: ns.frequency,
29249
- ...intIn2(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
29250
- ...intIn2(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
29251
- ...slsUri ? { slsUri } : {}
29252
- };
29253
- }
29254
- return void 0;
29255
- }
29256
29385
 
29257
29386
  // src/multicast-manager.ts
29258
29387
  function freezeIngress(tracks, flow) {
@@ -30415,6 +30544,7 @@ var MulticastManager = class {
30415
30544
  // worse behaviour.
30416
30545
  amtRelayPort: config.amtRelayPort ?? config.relayPort ?? (amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
30417
30546
  amtDiscovery: config.amtDiscovery,
30547
+ atsc3: config.atsc3,
30418
30548
  packetIds: config.packetIds,
30419
30549
  tracks: catalogTracks?.map(({ name, packetId }) => ({ name, packetId })),
30420
30550
  ...provenance === void 0 ? {} : { protected: true }
@@ -30568,6 +30698,7 @@ var MulticastManager = class {
30568
30698
  amtRelay: endpoint.amtRelay,
30569
30699
  amtRelayPort: endpoint.amtRelayPort ?? (endpoint.amtRelay?.trim() ? DEFAULT_AMT_RELAY_PORT : void 0),
30570
30700
  amtDiscovery: endpoint.amtDiscovery,
30701
+ atsc3: endpoint.atsc3,
30571
30702
  packetIds: endpoint.packetIds,
30572
30703
  tracks: endpoint.tracks.map(({ name, packetId }) => ({ name, packetId })),
30573
30704
  // A protected repair group's records ride in band on its port (7.2.3).
@@ -34446,6 +34577,7 @@ function wireRepairFetch(mc, opts) {
34446
34577
  const run = entry.running;
34447
34578
  if (!run) return;
34448
34579
  entry.running = null;
34580
+ if (run.mootTimer !== void 0) clearTimeout(run.mootTimer);
34449
34581
  run.stopped = reason;
34450
34582
  run.controller.abort(reason);
34451
34583
  if (reason === "preempted") releaseHold(entry);
@@ -34470,6 +34602,31 @@ function wireRepairFetch(mc, opts) {
34470
34602
  return false;
34471
34603
  }
34472
34604
  };
34605
+ const dropMoot = (entry) => {
34606
+ stop(entry, "moot");
34607
+ retire(entry);
34608
+ releaseHold(entry);
34609
+ clearEntry(entry);
34610
+ };
34611
+ const mootAtPlayout = (entry) => {
34612
+ const run = entry.running;
34613
+ if (run === null || run.mootTimer !== void 0 || entry.priority !== 0) return;
34614
+ const last = lastSsId(entry);
34615
+ if (last === void 0) return;
34616
+ try {
34617
+ if (mc.rapCompleteAbove?.(entry.packetId, entry.catalogTrackName, last) !== true) return;
34618
+ } catch {
34619
+ return;
34620
+ }
34621
+ run.mootTimer = setTimeout(() => {
34622
+ run.mootTimer = void 0;
34623
+ if (disposed || entry.running !== run) return;
34624
+ if (performance.now() < entry.playoutDeadlineAt) return mootAtPlayout(entry);
34625
+ if (!moot(entry)) return;
34626
+ dropMoot(entry);
34627
+ dispatch();
34628
+ }, Math.max(0, entry.playoutDeadlineAt - performance.now()));
34629
+ };
34473
34630
  const skip = (entry, reason, rttMs, budgetMs) => {
34474
34631
  retire(entry);
34475
34632
  releaseHold(entry);
@@ -34580,6 +34737,7 @@ function wireRepairFetch(mc, opts) {
34580
34737
  });
34581
34738
  const run = { controller: new AbortController(), sentAt: now, stopped: null };
34582
34739
  entry.running = run;
34740
+ mootAtPlayout(entry);
34583
34741
  if (!entry.range) {
34584
34742
  mc.fecManager.holdBlockForRepair(
34585
34743
  entry.sbn,
@@ -34664,6 +34822,7 @@ function wireRepairFetch(mc, opts) {
34664
34822
  return;
34665
34823
  }
34666
34824
  entry.running = null;
34825
+ if (run.mootTimer !== void 0) clearTimeout(run.mootTimer);
34667
34826
  if (error === void 0) {
34668
34827
  retire(entry);
34669
34828
  if (entry.range || fed === 0 || !decodable(entry)) {
@@ -35090,11 +35249,9 @@ function wireRepairFetch(mc, opts) {
35090
35249
  queueMicrotask(() => {
35091
35250
  if (disposed) return;
35092
35251
  for (const entry of [...entries.values()]) {
35093
- if (entry.packetId !== packetId || !entry.running || !moot(entry)) continue;
35094
- stop(entry, "moot");
35095
- retire(entry);
35096
- releaseHold(entry);
35097
- clearEntry(entry);
35252
+ if (entry.packetId !== packetId || !entry.running) continue;
35253
+ if (moot(entry)) dropMoot(entry);
35254
+ else mootAtPlayout(entry);
35098
35255
  }
35099
35256
  dispatch();
35100
35257
  });