@tradalab/mediakit 2.4.0 → 2.4.1

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,19 @@ 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.4.1
10
+
11
+ No API change: serve the new `worker.js` and `detect-worker.js`.
12
+
13
+ - On a machine too slow for the detectors to keep up with the camera (one detection outlasts a
14
+ frame), the detect workers are asked at most 60% of the time instead of back to back. Back to
15
+ back they took a whole core and starved the main thread, where frames are handed between
16
+ workers: a live studio with two channels, six overlays and a green screen on one core ran at
17
+ 18-19 fps with the camera stopping for up to 1.8 s; now 21-22 fps and 1.0 s. A machine that
18
+ keeps up is untouched.
19
+ - `web/example/studio-live.html` starts with the beauty filter off, like the live studio it
20
+ simulates.
21
+
9
22
  ### Upgrading to 2.4
10
23
 
11
24
  2.3.0 was committed but never published; everything below ships first in 2.4.0.
package/dist/index.d.ts CHANGED
@@ -97,6 +97,7 @@ declare class Engine {
97
97
  private gapUs;
98
98
  private prevTs;
99
99
  private readonly sent;
100
+ private readonly lastSentAt;
100
101
  private faceLatencyMs;
101
102
  private readonly maskLatencyMs;
102
103
  private faceTs;
@@ -176,6 +177,7 @@ declare class Engine {
176
177
  render(source: TexImageSource, timestampUs: number): boolean;
177
178
  private remoteMaskKind;
178
179
  private retuneDepth;
180
+ private dutyAllows;
179
181
  private took;
180
182
  private releaseHeld;
181
183
  dropped(): boolean;
package/dist/index.js CHANGED
@@ -307,6 +307,7 @@ var ZERO_STATS = {
307
307
  };
308
308
  var MAX_HOLD = 2;
309
309
  var DEPTH_VOTES = 15;
310
+ var DETECT_DUTY = 0.6;
310
311
  function sourceSize(source) {
311
312
  if (source instanceof VideoFrame) return [source.displayWidth, source.displayHeight];
312
313
  if (typeof HTMLVideoElement !== "undefined" && source instanceof HTMLVideoElement) return [source.videoWidth, source.videoHeight];
@@ -367,6 +368,7 @@ var Engine = class _Engine {
367
368
  gapUs = 33333;
368
369
  prevTs = -1;
369
370
  sent = /* @__PURE__ */ new Map();
371
+ lastSentAt = /* @__PURE__ */ new Map();
370
372
  faceLatencyMs = 0;
371
373
  maskLatencyMs = /* @__PURE__ */ new Map();
372
374
  faceTs = -1;
@@ -671,6 +673,7 @@ var Engine = class _Engine {
671
673
  requestRemote(kind, source, timestampUs) {
672
674
  const detect = this.detects.get(kind);
673
675
  if (!detect?.accepts(kind === "face" ? "face" : "mask")) return;
676
+ if (!this.dutyAllows(kind)) return;
674
677
  let frame = null;
675
678
  try {
676
679
  const copyable = source instanceof VideoFrame || source instanceof OffscreenCanvas;
@@ -680,7 +683,9 @@ var Engine = class _Engine {
680
683
  } catch {
681
684
  }
682
685
  if (frame && detect.request(kind === "face" ? "face" : "mask", frame, timestampUs)) {
683
- this.sent.set(kind, { ts: timestampUs, at: performance.now() });
686
+ const now2 = performance.now();
687
+ this.sent.set(kind, { ts: timestampUs, at: now2 });
688
+ this.lastSentAt.set(kind, now2);
684
689
  }
685
690
  }
686
691
  /** Face and mask asked on the same frame share one draw. */
@@ -795,6 +800,12 @@ var Engine = class _Engine {
795
800
  this.depthVotes = 0;
796
801
  }
797
802
  }
803
+ dutyAllows(kind) {
804
+ const took = kind === "face" ? this.faceLatencyMs : this.maskLatencyMs.get(kind) ?? 0;
805
+ if (took * 1e3 < this.gapUs) return true;
806
+ const last = this.lastSentAt.get(kind);
807
+ return last === void 0 || performance.now() - last >= took / DETECT_DUTY;
808
+ }
798
809
  took(kind, tsUs) {
799
810
  const s = this.sent.get(kind);
800
811
  if (s?.ts !== tsUs) return null;