@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
@@ -799,6 +799,16 @@ function keyframeInstantBetween(start, interval, from, to) {
799
799
  function compareDataUnitStarts(a, b) {
800
800
  return a.movieFragment - b.movieFragment | 0 || a.idx - b.idx || a.offset - b.offset;
801
801
  }
802
+ function firstStartAtOrAfter(starts, sbn) {
803
+ let lo = 0;
804
+ let hi = starts.length;
805
+ while (lo < hi) {
806
+ const mid = lo + hi >>> 1;
807
+ if (starts[mid].sbn < sbn) lo = mid + 1;
808
+ else hi = mid;
809
+ }
810
+ return lo;
811
+ }
802
812
  var LATE_RAP_MAX_MPUS_BACK = 64;
803
813
  var UNPLACED = { rapNotMpuStart: false };
804
814
  var BlockClassifier = class {
@@ -823,6 +833,15 @@ var BlockClassifier = class {
823
833
  #mpuSbnSpans = /* @__PURE__ */ new Map();
824
834
  #dataUnitStarts = /* @__PURE__ */ new Map();
825
835
  #highestMpu = null;
836
+ /**
837
+ * The DU headers held, per MPU in authored order, for the run rule. Kept in
838
+ * every mode (the rule needs no catalog cadence) for the same horizon and
839
+ * the same continuous SBN sequence as the P1 ledger.
840
+ */
841
+ #runStarts = /* @__PURE__ */ new Map();
842
+ #runHighestMpu = null;
843
+ /** Two DU headers of this sequence lay in blocks against their authored order: no run is read. */
844
+ #runOrderRefuted = false;
826
845
  /**
827
846
  * P3 layout, kept for the MPUs within the classification horizon and valid
828
847
  * within one continuous SBN sequence (`noteSourceDiscontinuity`).
@@ -930,6 +949,7 @@ var BlockClassifier = class {
930
949
  if (this.#geometry.trackKind === "audio") return [];
931
950
  const changes = [];
932
951
  const block = this.#blockFor(sbn);
952
+ const fragmentsCountedSamples = !this.#multiSampleFragment;
933
953
  const placement = this.#place(evidence);
934
954
  if (evidence.rap) block.rapSeen = true;
935
955
  if (evidence.mpu !== void 0) block.mpus.add(evidence.mpu);
@@ -941,19 +961,31 @@ var BlockClassifier = class {
941
961
  if (placement.rapNotMpuStart) this.#mpuBoundsRaps = false;
942
962
  const violation = this.#checkInvariants(sbn, block, evidence, placement);
943
963
  if (violation !== null) changes.push(...this.#disable(violation));
944
- const next = this.#classify(block);
945
- if (next !== block.cls && this.#allowed(block.cls, next)) {
946
- changes.push({
947
- kind: "reclassified",
948
- sbn,
949
- from: block.cls,
950
- to: next,
951
- evidence: this.#evidenceFor(block, next)
952
- });
953
- block.cls = next;
964
+ const orderHeld = !this.#runOrderRefuted;
965
+ const bounded = this.#noteRunStart(sbn, evidence, position);
966
+ if (orderHeld && this.#runOrderRefuted || fragmentsCountedSamples && this.#multiSampleFragment) {
967
+ for (const [other, classed] of this.#blocks) {
968
+ if (classed.cls !== "delta") continue;
969
+ classed.cls = "unknown";
970
+ changes.push({ kind: "reclassified", sbn: other, from: "delta", to: "unknown", evidence: "classifier-disabled" });
971
+ }
954
972
  }
973
+ this.#reclassify(sbn, block, changes);
974
+ for (const other of bounded) this.#reclassify(other, this.#blocks.get(other), changes);
955
975
  return changes;
956
976
  }
977
+ #reclassify(sbn, block, changes) {
978
+ const next = this.#classify(block, sbn);
979
+ if (next === block.cls || !this.#allowed(block.cls, next)) return;
980
+ changes.push({
981
+ kind: "reclassified",
982
+ sbn,
983
+ from: block.cls,
984
+ to: next,
985
+ evidence: this.#evidenceFor(block, next)
986
+ });
987
+ block.cls = next;
988
+ }
957
989
  /**
958
990
  * Record a RAP frame released in order. Released MPU-start RAPs of MPUs m
959
991
  * and m+n must be exactly n keyframe intervals apart in the media
@@ -1112,6 +1144,9 @@ var BlockClassifier = class {
1112
1144
  this.#mpuSbnSpans.clear();
1113
1145
  this.#dataUnitStarts.clear();
1114
1146
  this.#highestMpu = null;
1147
+ this.#runStarts.clear();
1148
+ this.#runHighestMpu = null;
1149
+ this.#runOrderRefuted = false;
1115
1150
  }
1116
1151
  /**
1117
1152
  * P1 check for one source packet of MPU `mpu` in block `sbn`, then record
@@ -1202,18 +1237,112 @@ var BlockClassifier = class {
1202
1237
  }
1203
1238
  return changes;
1204
1239
  }
1205
- #classify(block) {
1240
+ #classify(block, sbn) {
1206
1241
  if (block.rapSeen || block.mpus.size >= 2) return "keyframe";
1207
- if (this.#mode === "all-protected") return "unknown";
1242
+ if (block.cls === "delta") return "delta";
1243
+ if (this.#windowHolds(block) || this.#runHolds(block, sbn)) return "delta";
1244
+ return "unknown";
1245
+ }
1246
+ #windowHolds(block) {
1247
+ if (this.#mode === "all-protected") return false;
1208
1248
  const geometry = this.#geometry;
1209
- if (geometry.trackKind !== "video" || geometry.mode !== "classifying") return "unknown";
1210
- if (block.mpus.size === 1 && block.positionMin !== void 0 && block.positionMax !== void 0) {
1211
- const span = geometry.interleaveUnits - 1;
1212
- if (block.positionMax - span >= 1 && block.positionMin + span <= geometry.gopFrames - 1) {
1213
- return "delta";
1249
+ if (geometry.trackKind !== "video" || geometry.mode !== "classifying") return false;
1250
+ if (block.mpus.size !== 1 || block.positionMin === void 0 || block.positionMax === void 0) {
1251
+ return false;
1252
+ }
1253
+ const span = geometry.interleaveUnits - 1;
1254
+ return block.positionMax - span >= 1 && block.positionMin + span <= geometry.gopFrames - 1;
1255
+ }
1256
+ /**
1257
+ * Record a DU header for the run rule. Returns the other blocks it now
1258
+ * bounds: those between it and the DU headers next to it in authored order.
1259
+ */
1260
+ #noteRunStart(sbn, evidence, position) {
1261
+ const { mpu, idx, movieFragment } = evidence;
1262
+ if (this.#geometry.trackKind !== "video" || mpu === void 0 || idx === void 0 || movieFragment === void 0) {
1263
+ return [];
1264
+ }
1265
+ const start = {
1266
+ movieFragment,
1267
+ idx,
1268
+ offset: evidence.offset ?? 0,
1269
+ sbn,
1270
+ rap: evidence.rap,
1271
+ dep: evidence.depCounter ?? 0,
1272
+ ...position === void 0 ? {} : { position }
1273
+ };
1274
+ let starts = this.#runStarts.get(mpu);
1275
+ if (starts === void 0) {
1276
+ starts = [];
1277
+ this.#runStarts.set(mpu, starts);
1278
+ }
1279
+ let at = 0;
1280
+ let end = starts.length;
1281
+ while (at < end) {
1282
+ const mid = at + end >>> 1;
1283
+ if (compareDataUnitStarts(starts[mid], start) < 0) at = mid + 1;
1284
+ else end = mid;
1285
+ }
1286
+ if (at < starts.length && compareDataUnitStarts(starts[at], start) === 0) return [];
1287
+ starts.splice(at, 0, start);
1288
+ if (this.#runHighestMpu === null || mpu > this.#runHighestMpu) {
1289
+ this.#runHighestMpu = mpu;
1290
+ for (const other of [...this.#runStarts.keys()]) {
1291
+ if (other + 1 < mpu) this.#runStarts.delete(other);
1214
1292
  }
1215
1293
  }
1216
- return "unknown";
1294
+ const before = starts[at - 1]?.sbn;
1295
+ const after = starts[at + 1]?.sbn;
1296
+ if (before !== void 0 && before > sbn || after !== void 0 && after < sbn) {
1297
+ this.#runOrderRefuted = true;
1298
+ return [];
1299
+ }
1300
+ const bounded = [];
1301
+ for (const other of this.#blocks.keys()) {
1302
+ if (before !== void 0 && other > before && other < sbn || after !== void 0 && other > sbn && other < after) {
1303
+ bounded.push(other);
1304
+ }
1305
+ }
1306
+ return bounded;
1307
+ }
1308
+ /**
1309
+ * The run rule of fec-multicast-01 6.1: the DU header held last before the
1310
+ * block and the one held first after it are in one MPU, the lower one is a
1311
+ * non-RAP sample start, and its dependent run reaches the upper one's
1312
+ * sample. No sample the block can carry is then a RAP.
1313
+ */
1314
+ #runHolds(block, sbn) {
1315
+ if (this.#runOrderRefuted) return false;
1316
+ let lower;
1317
+ let upper;
1318
+ let lowerMpu = 0;
1319
+ let upperMpu = 0;
1320
+ for (const [mpu, starts] of this.#runStarts) {
1321
+ const before = firstStartAtOrAfter(starts, sbn);
1322
+ const after = firstStartAtOrAfter(starts, sbn + 1);
1323
+ if (before > 0 && (lower === void 0 || mpu >= lowerMpu)) {
1324
+ lower = starts[before - 1];
1325
+ lowerMpu = mpu;
1326
+ }
1327
+ if (after < starts.length && (upper === void 0 || mpu < upperMpu)) {
1328
+ upper = starts[after];
1329
+ upperMpu = mpu;
1330
+ }
1331
+ }
1332
+ if (lower === void 0 || upper === void 0 || lowerMpu !== upperMpu) return false;
1333
+ if (block.mpus.size === 1 && !block.mpus.has(lowerMpu)) return false;
1334
+ if (lower.offset !== 0 || lower.rap || lower.dep < 1) return false;
1335
+ let samples;
1336
+ if (lower.movieFragment === upper.movieFragment) samples = upper.idx - lower.idx;
1337
+ else if (!this.#multiSampleFragment) {
1338
+ samples = upper.movieFragment - lower.movieFragment >>> 0;
1339
+ } else return false;
1340
+ if (samples < 0 || samples > lower.dep) return false;
1341
+ const geometry = this.#geometry;
1342
+ if (geometry.trackKind === "video" && geometry.mode === "classifying" && lower.position !== void 0 && upper.position !== void 0 && Math.floor(upper.position / geometry.gopFrames) > Math.floor(lower.position / geometry.gopFrames)) {
1343
+ return false;
1344
+ }
1345
+ return true;
1217
1346
  }
1218
1347
  #allowed(from, to) {
1219
1348
  if (from === "keyframe") return false;
@@ -1222,7 +1351,7 @@ var BlockClassifier = class {
1222
1351
  return false;
1223
1352
  }
1224
1353
  #evidenceFor(block, to) {
1225
- if (to === "delta") return "window";
1354
+ if (to === "delta") return this.#windowHolds(block) ? "window" : "dependent-run";
1226
1355
  return block.rapSeen ? "rap" : "mpu-span";
1227
1356
  }
1228
1357
  };