@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.
File without changes
package/dist/worker.js CHANGED
@@ -5107,6 +5107,7 @@
5107
5107
  };
5108
5108
  var MAX_HOLD = 2;
5109
5109
  var DEPTH_VOTES = 15;
5110
+ var DETECT_DUTY = 0.6;
5110
5111
  function sourceSize(source) {
5111
5112
  if (source instanceof VideoFrame) return [source.displayWidth, source.displayHeight];
5112
5113
  if (typeof HTMLVideoElement !== "undefined" && source instanceof HTMLVideoElement) return [source.videoWidth, source.videoHeight];
@@ -5167,6 +5168,7 @@
5167
5168
  gapUs = 33333;
5168
5169
  prevTs = -1;
5169
5170
  sent = /* @__PURE__ */ new Map();
5171
+ lastSentAt = /* @__PURE__ */ new Map();
5170
5172
  faceLatencyMs = 0;
5171
5173
  maskLatencyMs = /* @__PURE__ */ new Map();
5172
5174
  faceTs = -1;
@@ -5471,6 +5473,7 @@
5471
5473
  requestRemote(kind, source, timestampUs) {
5472
5474
  const detect = this.detects.get(kind);
5473
5475
  if (!detect?.accepts(kind === "face" ? "face" : "mask")) return;
5476
+ if (!this.dutyAllows(kind)) return;
5474
5477
  let frame = null;
5475
5478
  try {
5476
5479
  const copyable = source instanceof VideoFrame || source instanceof OffscreenCanvas;
@@ -5480,7 +5483,9 @@
5480
5483
  } catch {
5481
5484
  }
5482
5485
  if (frame && detect.request(kind === "face" ? "face" : "mask", frame, timestampUs)) {
5483
- this.sent.set(kind, { ts: timestampUs, at: performance.now() });
5486
+ const now = performance.now();
5487
+ this.sent.set(kind, { ts: timestampUs, at: now });
5488
+ this.lastSentAt.set(kind, now);
5484
5489
  }
5485
5490
  }
5486
5491
  /** Face and mask asked on the same frame share one draw. */
@@ -5595,6 +5600,12 @@
5595
5600
  this.depthVotes = 0;
5596
5601
  }
5597
5602
  }
5603
+ dutyAllows(kind) {
5604
+ const took = kind === "face" ? this.faceLatencyMs : this.maskLatencyMs.get(kind) ?? 0;
5605
+ if (took * 1e3 < this.gapUs) return true;
5606
+ const last = this.lastSentAt.get(kind);
5607
+ return last === void 0 || performance.now() - last >= took / DETECT_DUTY;
5608
+ }
5598
5609
  took(kind, tsUs) {
5599
5610
  const s2 = this.sent.get(kind);
5600
5611
  if (s2?.ts !== tsUs) return null;