@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 CHANGED
@@ -6,6 +6,43 @@ face retouching.
6
6
 
7
7
  The examples named below live in the repository under `web/example/`; `make example` serves them.
8
8
 
9
+ ### Upgrading to 2.9.0
10
+
11
+ No change for an app that does not read the new fields; serve the new `worker.js`,
12
+ `detect-worker.js` and `mediakit.wasm`.
13
+
14
+ **New: what each detector is doing, in `health.parts` and `FrameStats.parts`.** One state per
15
+ part - `person`, `classes`, `face` and `cover` (the face cover behind `occluders`) - each `"off"`
16
+ (the recipe does not need it), `"loading"`, `"ready"` or `"failed"`, and `partErrors` with the
17
+ reason for each failed part ("" for the others). An app can show "filter ready" before going live,
18
+ or "getting the filter ready" while a part loads, without guessing from which effects show. On a
19
+ fake camera with lipstick, smoothing and `occluders`: all four `"off"` before the first frame,
20
+ `person`, `face` and `cover` `"loading"` at 0.5 s and `"ready"` at 1 s. `cover` follows `face`:
21
+ `"loading"` while landmarks load, `"failed"` when they fail, with their reason.
22
+
23
+ **Fix: a detector that failed was told to nobody unless it timed out.** Only a load over 60 s
24
+ reached `effectError`; a 404 on a model, a wasm error, or a face cover that did not load turned
25
+ the effects off with nothing but a console line - for the cover, makeup on hands for the whole
26
+ session. Now the part turns `"failed"`, `partErrors` says why (`mediakit: face detection did not
27
+ load: Failed to fetch model: /mediakit/face_landmarker.task (404); face effects stay off`,
28
+ `mediakit: the face cover model did not load: ...; occluders stays off`) and `onIssue` fires the
29
+ new code `part-off` once per reason, unless `effect-off` already said the same. Without the detect
30
+ worker the cover is `"failed"` too: it runs only there. The cover model now also gives up after
31
+ 60 s, as the MediaPipe models do. With `syncFaces`, `cover` is the state of the first face worker;
32
+ the second one's cover does not change it.
33
+
34
+ **New: `preloadDetectors(parts, onProgress)`** reports the download as it goes:
35
+ `{ loaded, total, done, files }` - bytes so far, the sum of the files' sizes, and files finished out
36
+ of files asked for. `total` is 0 until every file's headers are in, and stays 0 when one of them
37
+ gives no usable size (no `Content-Length`, or a compressed response, whose `Content-Length` is
38
+ not the size the browser hands over); show `done`/`files` then. `loaded` never passes a known
39
+ `total`. It is called at the start, at most every 100 ms while bytes arrive, and once per finished
40
+ file, the last call with `done === files`. A file that fails, or answers with an error status,
41
+ counts as done and adds no bytes. A callback that throws is not called again. The MediaPipe
42
+ runtime and onnxruntime load in workers that report nothing, so this is the only progress there
43
+ is: an app that wants a progress line calls `preloadDetectors` when the camera screen opens and
44
+ shows it, and the detectors then load from the HTTP cache.
45
+
9
46
  ### Upgrading to 2.8.0
10
47
 
11
48
  No change at runtime for a recipe that already works: serve the new `worker.js`,
@@ -305,6 +342,7 @@ Taken from what Tencent Beauty AR Web, BytePlus's web beauty extension and GPUPi
305
342
  | `stall` | no frame out for 2 s with the camera live (also `onStall`) | fall back to the raw camera after a grace period |
306
343
  | `slow` | frames or face detection over 150 ms for 3 s (Tencent's 50005) | suggest a lower resolution or fewer effects |
307
344
  | `effect-off` | some effects are off, the rest runs (`health.effectError`) | say which ones and why |
345
+ | `part-off` | a detector failed and `effect-off` has not said so, once per reason (`health.parts`, `health.partErrors`) | say what is off; for `cover`, that makeup may land on a hand |
308
346
  | `worker-moved` | the worker failed, the pipeline moved to the main thread | install the track from `onTrackReplaced` |
309
347
  | `gpu-lost` | the WebGL context was lost | nothing: the pipeline rebuilds itself (up to twice; once without makeup after a makeup link loss, never after a loss building the shaders) and fires `onTrackReplaced` |
310
348
 
@@ -327,6 +365,7 @@ Taken from what Tencent Beauty AR Web, BytePlus's web beauty extension and GPUPi
327
365
  | Software renderer (SwiftShader, llvmpipe) | runs, slowly; `checkSupport().softwareRenderer` | warn |
328
366
  | Makeup shader slow or failing to link, or losing the context linking | makeup off, rest runs, `effect-off`; remembered per GPU after a loss | show that makeup is off, keep the camera on |
329
367
  | A detector does not load within 60 s | its effects off, rest runs, `effect-off` | say the network is slow; `preloadDetectors()` earlier helps the next time |
368
+ | The face cover model or its runtime does not load, or face detection runs without the detect worker | `occluders` off, rest runs, `part-off`, `health.parts.cover` `"failed"` | say that makeup may land on a hand or a cup; offer to turn makeup off |
330
369
  | Overloaded machine | `slow`, then `stall` | lower the load, then fall back to the raw camera |
331
370
  | GPU context lost while running | rebuilds, `gpu-lost`, `onTrackReplaced` | install the new track |
332
371
  | `start()` throws `GpuLostError` | lost the context building the shaders; remembered | use the raw camera; do not retry, mediakit would refuse anyway |
@@ -701,7 +740,7 @@ const pipeline = new VideoPipeline(filter, effects, {
701
740
  onTrackReplaced: (track) => sender.replaceTrack(track),
702
741
  })
703
742
  const stop = pipeline.subscribeFrames((frame) => { draw(frame); frame.close() })
704
- pipeline.health // { transport, frames, sinceMs, stalled }
743
+ pipeline.health // { transport, frames, sinceMs, stalled, effectError, parts, partErrors }
705
744
  ```
706
745
 
707
746
  - No frame for two seconds fires `onStall` (a machine too slow for the recipe, or a hang). A worker
@@ -7520,6 +7520,7 @@
7520
7520
  classes: assetUrl("selfie_multiclass_256x256.tflite"),
7521
7521
  face: assetUrl("face_landmarker.task")
7522
7522
  };
7523
+ var LOAD_MS = 6e4;
7523
7524
  var fileset = null;
7524
7525
  function visionFileset() {
7525
7526
  fileset ??= uh.forVisionTasks(MP_DIR).catch((e2) => {
@@ -7528,6 +7529,37 @@
7528
7529
  });
7529
7530
  return fileset;
7530
7531
  }
7532
+ var LoadTimeout = class extends Error {
7533
+ constructor(what, ms2) {
7534
+ super(`mediakit: ${what} did not load within ${Math.round(ms2 / 1e3)} s`);
7535
+ this.name = "LoadTimeout";
7536
+ }
7537
+ };
7538
+ function withTimeout(p2, ms2, what, late) {
7539
+ return new Promise((resolve, reject) => {
7540
+ let done = false;
7541
+ const timer = setTimeout(() => {
7542
+ done = true;
7543
+ reject(new LoadTimeout(what, ms2));
7544
+ }, ms2);
7545
+ p2.then(
7546
+ (v2) => {
7547
+ if (done) late(v2);
7548
+ else {
7549
+ done = true;
7550
+ clearTimeout(timer);
7551
+ resolve(v2);
7552
+ }
7553
+ },
7554
+ (e2) => {
7555
+ if (done) return;
7556
+ done = true;
7557
+ clearTimeout(timer);
7558
+ reject(e2);
7559
+ }
7560
+ );
7561
+ });
7562
+ }
7531
7563
 
7532
7564
  // src/face.ts
7533
7565
  var FACE_FLOATS = 478 * 3;
@@ -7795,11 +7827,15 @@
7795
7827
  let seen = null;
7796
7828
  if (m2.cover && !coverAsked) {
7797
7829
  coverAsked = true;
7798
- createFaceCover().then(
7830
+ withTimeout(createFaceCover(), LOAD_MS, "the face cover model", (c2) => c2.close()).then(
7799
7831
  (c2) => {
7800
7832
  cover = c2;
7833
+ post({ t: "cover", ok: true, message: "" });
7801
7834
  },
7802
- (err) => console.warn("mediakit: the face cover model did not load, occluders has no effect:", message(err))
7835
+ (err) => {
7836
+ console.warn("mediakit: the face cover model did not load, occluders has no effect:", message(err));
7837
+ post({ t: "cover", ok: false, message: `the face cover model did not load: ${message(err)}` });
7838
+ }
7803
7839
  );
7804
7840
  }
7805
7841
  try {
@@ -7812,6 +7848,7 @@
7812
7848
  seen = await cover.read(frame, lm, n2);
7813
7849
  } catch (err) {
7814
7850
  console.warn("mediakit: the face cover failed, occluders is off from here:", message(err));
7851
+ post({ t: "cover", ok: false, message: `the face cover failed: ${message(err)}` });
7815
7852
  cover.close();
7816
7853
  cover = null;
7817
7854
  }