@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/index.d.ts CHANGED
@@ -83,6 +83,7 @@ declare class Engine {
83
83
  private classMaskFresh;
84
84
  private maskWorkerMs;
85
85
  private detect;
86
+ private detectCanvas;
86
87
  private readonly inThread;
87
88
  private faceLoading;
88
89
  private maxFaces;
@@ -116,8 +117,12 @@ declare class Engine {
116
117
  /** The detect worker for `kind`, made on first use; rejects when that kind must stay in-thread. */
117
118
  private remote;
118
119
  private uploadClassMask;
119
- /** Hands a copy of this frame to the detect worker; the caller's frame stays its own. */
120
+ /**
121
+ * Sends the detect worker a downscaled copy, never a clone: a camera frame held through a slow
122
+ * detection drains Chrome's few capture buffers and throttles the camera itself.
123
+ */
120
124
  private requestRemote;
125
+ private detectCopy;
121
126
  private ensureClassSegmenter;
122
127
  private ensureSegmenter;
123
128
  /**
package/dist/index.js CHANGED
@@ -343,6 +343,7 @@ var Engine = class _Engine {
343
343
  classMaskFresh = false;
344
344
  maskWorkerMs = 0;
345
345
  detect = null;
346
+ detectCanvas = null;
346
347
  // A kind whose worker failed once stays in-thread.
347
348
  inThread = /* @__PURE__ */ new Set();
348
349
  faceLoading = null;
@@ -576,15 +577,28 @@ var Engine = class _Engine {
576
577
  gl.bindTexture(gl.TEXTURE_2D, null);
577
578
  this.classMaskFresh = true;
578
579
  }
579
- /** Hands a copy of this frame to the detect worker; the caller's frame stays its own. */
580
+ /**
581
+ * Sends the detect worker a downscaled copy, never a clone: a camera frame held through a slow
582
+ * detection drains Chrome's few capture buffers and throttles the camera itself.
583
+ */
580
584
  requestRemote(kind, source, timestampUs) {
581
585
  let frame = null;
582
586
  try {
583
- frame = source instanceof VideoFrame ? source.clone() : new VideoFrame(source, { timestamp: timestampUs });
587
+ frame = new VideoFrame(source instanceof VideoFrame ? this.detectCopy(source) : source, {
588
+ timestamp: timestampUs
589
+ });
584
590
  } catch {
585
591
  }
586
592
  if (frame) this.detect?.request(kind, frame, timestampUs);
587
593
  }
594
+ detectCopy(source) {
595
+ const s = Math.min(1, 512 / Math.max(source.displayWidth, source.displayHeight));
596
+ const w = Math.max(1, Math.round(source.displayWidth * s));
597
+ const h = Math.max(1, Math.round(source.displayHeight * s));
598
+ if (!this.detectCanvas || this.detectCanvas.width !== w || this.detectCanvas.height !== h) this.detectCanvas = new OffscreenCanvas(w, h);
599
+ this.detectCanvas.getContext("2d").drawImage(source, 0, 0, w, h);
600
+ return this.detectCanvas;
601
+ }
588
602
  ensureClassSegmenter() {
589
603
  if (this.classSegmenter || this.classRemote || this.closed) return Promise.resolve();
590
604
  if (this.classLoading) return this.classLoading;