@tradalab/mediakit 2.8.0 → 2.9.0
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.
- package/README.md +40 -1
- package/dist/detect-worker.js +39 -2
- package/dist/detect-worker.js.map +1 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +114 -10
- package/dist/index.js.map +1 -1
- package/dist/worker.js +53 -2
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -4910,6 +4910,9 @@
|
|
|
4910
4910
|
this.busy.delete("face");
|
|
4911
4911
|
if (this.up.has("face")) this.on.face(m2.tsUs, m2.n, m2.lm, m2.ms, m2.cover, m2.rects);
|
|
4912
4912
|
break;
|
|
4913
|
+
case "cover":
|
|
4914
|
+
this.on.cover(m2.ok, m2.message);
|
|
4915
|
+
break;
|
|
4913
4916
|
case "mask":
|
|
4914
4917
|
this.busy.delete("mask");
|
|
4915
4918
|
if (this.up.has("mask") && m2.width > 0) this.on.mask(m2.tsUs, m2.width, m2.height, m2.data, m2.ms);
|
|
@@ -5301,6 +5304,9 @@
|
|
|
5301
5304
|
}
|
|
5302
5305
|
|
|
5303
5306
|
// src/engine.ts
|
|
5307
|
+
var NO_PARTS = Object.freeze({ person: "off", classes: "off", face: "off", cover: "off" });
|
|
5308
|
+
var NO_PART_ERRORS = Object.freeze({ person: "", classes: "", face: "", cover: "" });
|
|
5309
|
+
var COVER_IN_THREAD = "mediakit: the face cover runs only in the detect worker, and face detection runs in this thread; occluders stays off";
|
|
5304
5310
|
var ZERO_STATS = {
|
|
5305
5311
|
totalMs: 0,
|
|
5306
5312
|
segMs: 0,
|
|
@@ -5321,7 +5327,9 @@
|
|
|
5321
5327
|
heldFrames: 0,
|
|
5322
5328
|
faceAgeMs: 0,
|
|
5323
5329
|
maskAgeMs: 0,
|
|
5324
|
-
effectError: ""
|
|
5330
|
+
effectError: "",
|
|
5331
|
+
parts: { ...NO_PARTS },
|
|
5332
|
+
partErrors: { ...NO_PART_ERRORS }
|
|
5325
5333
|
};
|
|
5326
5334
|
var MAX_HOLD = 3;
|
|
5327
5335
|
var COVER_FRAME_W = 256;
|
|
@@ -5443,6 +5451,8 @@
|
|
|
5443
5451
|
coverCanvas = null;
|
|
5444
5452
|
coverCell = null;
|
|
5445
5453
|
coverOn = false;
|
|
5454
|
+
coverState = "loading";
|
|
5455
|
+
partErr = /* @__PURE__ */ new Map();
|
|
5446
5456
|
faceMisses = 0;
|
|
5447
5457
|
coverHidden = false;
|
|
5448
5458
|
srcW = 0;
|
|
@@ -5720,6 +5730,7 @@
|
|
|
5720
5730
|
});
|
|
5721
5731
|
}).catch((e2) => {
|
|
5722
5732
|
this.failed.add("face");
|
|
5733
|
+
this.partFailed("face", "face detection", "face effects", e2);
|
|
5723
5734
|
this.gaveUp("face effects", e2);
|
|
5724
5735
|
if (!(e2 instanceof LoadTimeout)) console.error("mediakit: face detector failed to load", e2);
|
|
5725
5736
|
}).finally(() => {
|
|
@@ -5738,6 +5749,7 @@
|
|
|
5738
5749
|
}).catch((e2) => {
|
|
5739
5750
|
if (!(e2 instanceof LoadTimeout)) return;
|
|
5740
5751
|
this.failed.add("person");
|
|
5752
|
+
this.partFailed("person", "person segmentation", "background effects", e2);
|
|
5741
5753
|
this.gaveUp("background effects", e2);
|
|
5742
5754
|
}).finally(() => {
|
|
5743
5755
|
this.personLoading = null;
|
|
@@ -5795,6 +5807,11 @@
|
|
|
5795
5807
|
this.maskResults.push(r2);
|
|
5796
5808
|
if (this.maskResults.length > MASK_RESULTS_KEPT) this.maskResults.shift();
|
|
5797
5809
|
},
|
|
5810
|
+
cover: (ok, message) => {
|
|
5811
|
+
if (key !== "face" || this.coverState === "failed") return;
|
|
5812
|
+
this.coverState = ok ? "ready" : "failed";
|
|
5813
|
+
if (!ok) this.partErr.set("cover", `mediakit: ${message}; occluders stays off`);
|
|
5814
|
+
},
|
|
5798
5815
|
failed: (k2, reason) => {
|
|
5799
5816
|
if (key === "faceExtra") {
|
|
5800
5817
|
this.faceExtraUp = false;
|
|
@@ -6077,6 +6094,7 @@
|
|
|
6077
6094
|
});
|
|
6078
6095
|
}).catch((e2) => {
|
|
6079
6096
|
this.classFailed = true;
|
|
6097
|
+
this.partFailed("classes", "skin segmentation", "skin, hair and product effects use the person model", e2);
|
|
6080
6098
|
if (!(e2 instanceof LoadTimeout)) console.error("mediakit: multiclass segmenter failed to load", e2);
|
|
6081
6099
|
else console.warn(`${e2.message}; the person model stands in`);
|
|
6082
6100
|
if (needsSegmentation(this.filter, this.effects)) void this.ensureSegmenter();
|
|
@@ -6096,6 +6114,7 @@
|
|
|
6096
6114
|
this.segmenter = s2;
|
|
6097
6115
|
}).catch((e2) => {
|
|
6098
6116
|
this.failed.add("segmenter");
|
|
6117
|
+
this.partFailed("person", "person segmentation", "background and skin effects", e2);
|
|
6099
6118
|
this.gaveUp("background and skin effects", e2);
|
|
6100
6119
|
if (!(e2 instanceof LoadTimeout)) console.error("mediakit: segmenter failed to load", e2);
|
|
6101
6120
|
}).finally(() => {
|
|
@@ -6432,6 +6451,7 @@
|
|
|
6432
6451
|
this.prevSegMs = segMs;
|
|
6433
6452
|
this.prevTotalMs = performance.now() - t0;
|
|
6434
6453
|
const s2 = this.core.stats();
|
|
6454
|
+
const parts = this.parts();
|
|
6435
6455
|
this.last = {
|
|
6436
6456
|
totalMs: this.prevTotalMs,
|
|
6437
6457
|
segMs,
|
|
@@ -6452,10 +6472,41 @@
|
|
|
6452
6472
|
heldFrames: faceDone ? this.queue.length : 0,
|
|
6453
6473
|
faceAgeMs: s2 && s2[10] > 0.5 && this.faceTs >= 0 ? (timestampUs - this.faceTs) / 1e3 : 0,
|
|
6454
6474
|
maskAgeMs: (needSeg || remoteMask !== null) && this.maskUsedTs >= 0 ? (timestampUs - this.maskUsedTs) / 1e3 : 0,
|
|
6455
|
-
effectError: this.programErr || this.loadErr
|
|
6475
|
+
effectError: this.programErr || this.loadErr,
|
|
6476
|
+
parts,
|
|
6477
|
+
partErrors: this.partErrors(parts)
|
|
6456
6478
|
};
|
|
6457
6479
|
return glCalls > 0;
|
|
6458
6480
|
}
|
|
6481
|
+
partFailed(part, what, off, e2) {
|
|
6482
|
+
if (this.partErr.has(part)) return;
|
|
6483
|
+
const why = e2 instanceof LoadTimeout ? e2.message : `mediakit: ${what} did not load: ${String(e2?.message ?? e2)}`;
|
|
6484
|
+
this.partErr.set(part, `${why}; ${off} stay off`);
|
|
6485
|
+
}
|
|
6486
|
+
parts() {
|
|
6487
|
+
const f2 = this.filter;
|
|
6488
|
+
const e2 = this.effects;
|
|
6489
|
+
const face = !needsFace(e2) ? "off" : this.failed.has("face") ? "failed" : this.face || this.faceRemote ? "ready" : "loading";
|
|
6490
|
+
const classes = !needsSkinClasses(f2, e2) ? "off" : this.classFailed ? "failed" : this.classSegmenter || this.classRemote ? "ready" : "loading";
|
|
6491
|
+
let person = "off";
|
|
6492
|
+
if (needsSegmentation(f2, e2)) {
|
|
6493
|
+
if (this.segmenter || this.personRemote && this.personRemoteWanted(f2, e2)) person = "ready";
|
|
6494
|
+
else if (this.segmenterLoading || this.personLoading) person = "loading";
|
|
6495
|
+
else if (this.failed.has("segmenter") || this.failed.has("person")) person = classes === "ready" ? "ready" : "failed";
|
|
6496
|
+
else person = classes === "off" ? "loading" : classes;
|
|
6497
|
+
}
|
|
6498
|
+
let cover = "off";
|
|
6499
|
+
if (face !== "off" && (e2.occluders ?? false)) {
|
|
6500
|
+
cover = face === "loading" ? "loading" : face === "failed" || this.inThread.has("face") ? "failed" : this.coverState;
|
|
6501
|
+
}
|
|
6502
|
+
return { person, classes, face, cover };
|
|
6503
|
+
}
|
|
6504
|
+
partErrors(p2) {
|
|
6505
|
+
const why = (part) => p2[part] === "failed" ? this.partErr.get(part) ?? "" : "";
|
|
6506
|
+
let cover = why("cover");
|
|
6507
|
+
if (p2.cover === "failed" && !cover) cover = p2.face === "failed" ? why("face") : COVER_IN_THREAD;
|
|
6508
|
+
return { person: why("person"), classes: why("classes"), face: why("face"), cover };
|
|
6509
|
+
}
|
|
6459
6510
|
/**
|
|
6460
6511
|
* Wrap the output canvas as a new VideoFrame.
|
|
6461
6512
|
*
|