@tradalab/mediakit 2.1.0 → 2.1.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/dist/worker.js CHANGED
@@ -5141,6 +5141,7 @@
5141
5141
  classMaskFresh = false;
5142
5142
  maskWorkerMs = 0;
5143
5143
  detect = null;
5144
+ detectCanvas = null;
5144
5145
  // A kind whose worker failed once stays in-thread.
5145
5146
  inThread = /* @__PURE__ */ new Set();
5146
5147
  faceLoading = null;
@@ -5374,15 +5375,28 @@
5374
5375
  gl.bindTexture(gl.TEXTURE_2D, null);
5375
5376
  this.classMaskFresh = true;
5376
5377
  }
5377
- /** Hands a copy of this frame to the detect worker; the caller's frame stays its own. */
5378
+ /**
5379
+ * Sends the detect worker a downscaled copy, never a clone: a camera frame held through a slow
5380
+ * detection drains Chrome's few capture buffers and throttles the camera itself.
5381
+ */
5378
5382
  requestRemote(kind, source, timestampUs) {
5379
5383
  let frame = null;
5380
5384
  try {
5381
- frame = source instanceof VideoFrame ? source.clone() : new VideoFrame(source, { timestamp: timestampUs });
5385
+ frame = new VideoFrame(source instanceof VideoFrame ? this.detectCopy(source) : source, {
5386
+ timestamp: timestampUs
5387
+ });
5382
5388
  } catch {
5383
5389
  }
5384
5390
  if (frame) this.detect?.request(kind, frame, timestampUs);
5385
5391
  }
5392
+ detectCopy(source) {
5393
+ const s2 = Math.min(1, 512 / Math.max(source.displayWidth, source.displayHeight));
5394
+ const w2 = Math.max(1, Math.round(source.displayWidth * s2));
5395
+ const h2 = Math.max(1, Math.round(source.displayHeight * s2));
5396
+ if (!this.detectCanvas || this.detectCanvas.width !== w2 || this.detectCanvas.height !== h2) this.detectCanvas = new OffscreenCanvas(w2, h2);
5397
+ this.detectCanvas.getContext("2d").drawImage(source, 0, 0, w2, h2);
5398
+ return this.detectCanvas;
5399
+ }
5386
5400
  ensureClassSegmenter() {
5387
5401
  if (this.classSegmenter || this.classRemote || this.closed) return Promise.resolve();
5388
5402
  if (this.classLoading) return this.classLoading;