@tradalab/mediakit 2.4.1 → 2.7.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 +315 -2
- package/dist/{chunk-YW75KJJO.js → chunk-4YCBTZRB.js} +15 -3
- package/dist/chunk-4YCBTZRB.js.map +1 -0
- package/dist/detect-worker.js +3718 -683
- package/dist/detect-worker.js.map +1 -1
- package/dist/face_cover.onnx +0 -0
- package/dist/index.d.ts +178 -8
- package/dist/index.js +1036 -116
- package/dist/index.js.map +1 -1
- package/dist/mediakit.wasm +0 -0
- package/dist/recipe.d.ts +10 -0
- package/dist/recipe.js +1 -1
- package/dist/worker.js +867 -102
- package/dist/worker.js.map +1 -1
- package/package.json +10 -3
- package/dist/chunk-YW75KJJO.js.map +0 -1
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,29 @@ export { DEBUG_VIEWS, EFFECTS_SCHEMA, FieldSpec, NO_EFFECTS, Rgb, TOUCH_UP, need
|
|
|
3
3
|
import { Color, SceneLayer, TransitionKind } from './layout.js';
|
|
4
4
|
export { BLEND_MODES, BlendMode, Rect, TRANSITIONS, hitTest, layouts, parseColor } from './layout.js';
|
|
5
5
|
|
|
6
|
+
/** When a lost WebGL context happened: building the core's shaders, linking a face colour shader, or later. */
|
|
7
|
+
type LossPhase = "init" | "link" | "run";
|
|
8
|
+
/** What this browser remembers about a GPU that lost its context under mediakit. */
|
|
9
|
+
interface GpuRecord {
|
|
10
|
+
/** Lost the context building the core's shaders: mediakit does not start on it. */
|
|
11
|
+
init: boolean;
|
|
12
|
+
/** Lost the context linking a face colour shader: makeup and teeth stay off on it. */
|
|
13
|
+
faceColor: boolean;
|
|
14
|
+
/** When the last loss was recorded, ms since the epoch. */
|
|
15
|
+
at: number;
|
|
16
|
+
}
|
|
17
|
+
/** The record for `gpu`, null when there is none, it expired, or this realm has no localStorage. */
|
|
18
|
+
declare function gpuRecord(gpu: string): GpuRecord | null;
|
|
19
|
+
/** Forget every GPU failure this browser remembers - for a "try again" after a driver update. */
|
|
20
|
+
declare function forgetGpuFailures(): void;
|
|
21
|
+
/** A WebGL context lost while mediakit was building or linking its shaders. */
|
|
22
|
+
declare class GpuLostError extends Error {
|
|
23
|
+
readonly phase: LossPhase;
|
|
24
|
+
readonly gpu: string;
|
|
25
|
+
readonly detail: string;
|
|
26
|
+
constructor(phase: LossPhase, gpu: string, detail?: string);
|
|
27
|
+
}
|
|
28
|
+
|
|
6
29
|
/**
|
|
7
30
|
* One mediakit pipeline: canvas plus WebGL2 plus the Go core plus the detectors, which is
|
|
8
31
|
* everything needed to turn a source frame into a processed one.
|
|
@@ -47,8 +70,14 @@ interface FrameStats {
|
|
|
47
70
|
faceAgeMs: number;
|
|
48
71
|
/** How old the segmentation mask behind this frame is; 0 without one. */
|
|
49
72
|
maskAgeMs: number;
|
|
73
|
+
/** Why makeup and teeth are off while the rest runs (their shader failed to link); "" when none. */
|
|
74
|
+
effectError: string;
|
|
50
75
|
}
|
|
51
76
|
type EngineCanvas = HTMLCanvasElement | OffscreenCanvas;
|
|
77
|
+
/** What the Engine skips on a GPU known to fail; a host on the main thread gets it from the GPU guard. */
|
|
78
|
+
interface EngineGuard {
|
|
79
|
+
noFaceColor?: boolean;
|
|
80
|
+
}
|
|
52
81
|
declare class Engine {
|
|
53
82
|
private canvas;
|
|
54
83
|
private gl;
|
|
@@ -75,6 +104,14 @@ declare class Engine {
|
|
|
75
104
|
private classLoading;
|
|
76
105
|
/** The segmenter whose result this frame borrowed, to give it back after process(). */
|
|
77
106
|
private used;
|
|
107
|
+
private programErr;
|
|
108
|
+
private loadErr;
|
|
109
|
+
private gpu;
|
|
110
|
+
private linkSeenAt;
|
|
111
|
+
private links;
|
|
112
|
+
private lostPhase;
|
|
113
|
+
private classFailed;
|
|
114
|
+
private readonly failed;
|
|
78
115
|
/**
|
|
79
116
|
* The landmark detector, also lazy and independent of the segmenter.
|
|
80
117
|
*
|
|
@@ -92,8 +129,9 @@ declare class Engine {
|
|
|
92
129
|
renderedTs: number;
|
|
93
130
|
private queue;
|
|
94
131
|
private spare;
|
|
95
|
-
private
|
|
96
|
-
private
|
|
132
|
+
private faceExtraUp;
|
|
133
|
+
private faceExtraTried;
|
|
134
|
+
private lerpBuf;
|
|
97
135
|
private gapUs;
|
|
98
136
|
private prevTs;
|
|
99
137
|
private readonly sent;
|
|
@@ -101,6 +139,35 @@ declare class Engine {
|
|
|
101
139
|
private faceLatencyMs;
|
|
102
140
|
private readonly maskLatencyMs;
|
|
103
141
|
private faceTs;
|
|
142
|
+
private faceResults;
|
|
143
|
+
private coverCanvas;
|
|
144
|
+
private coverCell;
|
|
145
|
+
private coverOn;
|
|
146
|
+
private faceMisses;
|
|
147
|
+
private coverHidden;
|
|
148
|
+
private srcW;
|
|
149
|
+
private srcH;
|
|
150
|
+
private coverLast;
|
|
151
|
+
private coverShown;
|
|
152
|
+
private coverImg;
|
|
153
|
+
private readonly faceAsked;
|
|
154
|
+
private readonly faceCrops;
|
|
155
|
+
private followBox;
|
|
156
|
+
private followTs;
|
|
157
|
+
private followCrop;
|
|
158
|
+
private followCanvas;
|
|
159
|
+
private followRetry;
|
|
160
|
+
private faceSeen;
|
|
161
|
+
private followFloats;
|
|
162
|
+
private followAll;
|
|
163
|
+
private followTurn;
|
|
164
|
+
private followMiss;
|
|
165
|
+
private followGrow;
|
|
166
|
+
private boxFloats;
|
|
167
|
+
private scanFrom;
|
|
168
|
+
private scanTurn;
|
|
169
|
+
private readonly probes;
|
|
170
|
+
private maskResults;
|
|
104
171
|
private maskUsedTs;
|
|
105
172
|
private lastHeld;
|
|
106
173
|
private swallowed;
|
|
@@ -112,10 +179,20 @@ declare class Engine {
|
|
|
112
179
|
private personMaskFresh;
|
|
113
180
|
private personMaskTs;
|
|
114
181
|
private personWorkerMs;
|
|
182
|
+
private personBytes;
|
|
183
|
+
private classBytes;
|
|
184
|
+
private mergedBytes;
|
|
185
|
+
private mergedTex;
|
|
186
|
+
private mergedFresh;
|
|
187
|
+
private mergedTs;
|
|
115
188
|
private detectCanvas;
|
|
116
189
|
private detectCanvasTs;
|
|
190
|
+
private thumbCanvas;
|
|
191
|
+
private readonly thumbs;
|
|
117
192
|
private readonly inThread;
|
|
118
193
|
private faceLoading;
|
|
194
|
+
private faceCount;
|
|
195
|
+
private caughtUpTs;
|
|
119
196
|
private maxFaces;
|
|
120
197
|
private lmBuf;
|
|
121
198
|
private filter;
|
|
@@ -125,15 +202,25 @@ declare class Engine {
|
|
|
125
202
|
last: FrameStats;
|
|
126
203
|
private constructor();
|
|
127
204
|
/** Main thread: makes its own canvas. A worker calls `on` with an OffscreenCanvas. */
|
|
128
|
-
static create(width: number, height: number, filter: BgFilter, effects?: Effects, alpha?: boolean, maxFaces?: number): Promise<Engine>;
|
|
205
|
+
static create(width: number, height: number, filter: BgFilter, effects?: Effects, alpha?: boolean, maxFaces?: number, guard?: EngineGuard): Promise<Engine>;
|
|
129
206
|
/**
|
|
130
207
|
* `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
|
|
131
208
|
* only a `cutout` background writes; it is fixed for the life of the context, so a host that
|
|
132
209
|
* may switch to `cutout` later has to ask for it here. `maxFaces` (1-3) is how many faces the
|
|
133
|
-
* landmarker looks for: below 3 it skips re-running its face detector on every call.
|
|
210
|
+
* landmarker looks for: below 3 it skips re-running its face detector on every call. Throws
|
|
211
|
+
* GpuLostError when the context is lost building the shaders, or this GPU is remembered for it.
|
|
134
212
|
*/
|
|
135
|
-
static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean, maxFaces?: number): Promise<Engine>;
|
|
213
|
+
static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean, maxFaces?: number, guard?: EngineGuard): Promise<Engine>;
|
|
214
|
+
/** The GPU the context reported at creation, "" when the browser hides it. */
|
|
215
|
+
get gpuName(): string;
|
|
136
216
|
get loading(): boolean;
|
|
217
|
+
/** The browser took the WebGL context away (GPU process reset or reclaimed); this Engine is done. */
|
|
218
|
+
get lost(): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* When the context was lost: "link" within 3 s of a face colour shader starting or still linking, else "run";
|
|
221
|
+
* null while it is not. The first read decides, and on the main thread it is remembered per GPU.
|
|
222
|
+
*/
|
|
223
|
+
get lostDuring(): LossPhase | null;
|
|
137
224
|
get outputCanvas(): EngineCanvas;
|
|
138
225
|
/** Draws an inner layer instead of the picture until set back to "off". */
|
|
139
226
|
setDebug(view: DebugView): void;
|
|
@@ -145,12 +232,18 @@ declare class Engine {
|
|
|
145
232
|
* cannot be decoded at all, and the main thread has to do it and transfer the bitmap.
|
|
146
233
|
*/
|
|
147
234
|
setRecipe(filter: BgFilter, effects?: Effects, background?: ImageBitmap): Promise<void>;
|
|
235
|
+
private noteLinking;
|
|
236
|
+
/** A worker, or the multiclass model, will bring the mask: no in-thread person model for it. */
|
|
237
|
+
private remoteMaskComing;
|
|
238
|
+
private gaveUp;
|
|
148
239
|
private ensureFace;
|
|
149
240
|
/** The detect worker for `kind`, made on first use; rejects when that kind must stay in-thread. */
|
|
150
241
|
private personRemoteWanted;
|
|
151
242
|
private ensurePersonRemote;
|
|
152
243
|
private remote;
|
|
153
244
|
private detectHandlers;
|
|
245
|
+
private noteThumb;
|
|
246
|
+
private merge;
|
|
154
247
|
private uploadClassMask;
|
|
155
248
|
private uploadMaskBytes;
|
|
156
249
|
/**
|
|
@@ -158,6 +251,14 @@ declare class Engine {
|
|
|
158
251
|
* detection drains Chrome's few capture buffers and throttles the camera itself.
|
|
159
252
|
*/
|
|
160
253
|
private requestRemote;
|
|
254
|
+
private followCopy;
|
|
255
|
+
private scanCopy;
|
|
256
|
+
private scanTile;
|
|
257
|
+
private uncrop;
|
|
258
|
+
private dedupe;
|
|
259
|
+
private follow;
|
|
260
|
+
private freeFaceWorker;
|
|
261
|
+
private ensureFaceExtra;
|
|
161
262
|
/** Face and mask asked on the same frame share one draw. */
|
|
162
263
|
private detectCopy;
|
|
163
264
|
private ensureClassSegmenter;
|
|
@@ -176,9 +277,17 @@ declare class Engine {
|
|
|
176
277
|
*/
|
|
177
278
|
render(source: TexImageSource, timestampUs: number): boolean;
|
|
178
279
|
private remoteMaskKind;
|
|
179
|
-
private
|
|
280
|
+
private spareFront;
|
|
281
|
+
private applyMask;
|
|
282
|
+
private masksFor;
|
|
283
|
+
private faceReady;
|
|
180
284
|
private dutyAllows;
|
|
181
285
|
private took;
|
|
286
|
+
private applyFace;
|
|
287
|
+
private faceFor;
|
|
288
|
+
private hideCover;
|
|
289
|
+
private showCover;
|
|
290
|
+
private sameFaces;
|
|
182
291
|
private releaseHeld;
|
|
183
292
|
dropped(): boolean;
|
|
184
293
|
passthrough(): VideoFrame | null;
|
|
@@ -243,6 +352,28 @@ interface PipelineOptions {
|
|
|
243
352
|
}) => void;
|
|
244
353
|
/** The pipeline replaced `processedTrack` mid-session. */
|
|
245
354
|
onTrackReplaced?: (track: MediaStreamTrack, previous: MediaStreamTrack | undefined) => void;
|
|
355
|
+
/** Something degraded while running; see {@link IssueCode}. Each code fires once until it clears. */
|
|
356
|
+
onIssue?: (issue: PipelineIssue) => void;
|
|
357
|
+
}
|
|
358
|
+
/** What degraded; each code and what the app should do is in the README, "Handling a weak or failing GPU". */
|
|
359
|
+
type IssueCode = "stall" | "slow" | "effect-off" | "worker-moved" | "gpu-lost";
|
|
360
|
+
interface PipelineIssue {
|
|
361
|
+
code: IssueCode;
|
|
362
|
+
message: string;
|
|
363
|
+
transport: Transport;
|
|
364
|
+
}
|
|
365
|
+
/** `gpu-blocked`: this GPU lost its WebGL context building mediakit's shaders in the last 3 days. */
|
|
366
|
+
type SupportReason = "no-window" | "no-wasm" | "no-webgl2" | "no-transport" | "gpu-blocked";
|
|
367
|
+
interface SupportReport {
|
|
368
|
+
supported: boolean;
|
|
369
|
+
/** Every reason it cannot run, empty when supported. */
|
|
370
|
+
reasons: SupportReason[];
|
|
371
|
+
/** WebGL2 only through a software rasteriser (SwiftShader, llvmpipe): it runs, but slowly. */
|
|
372
|
+
softwareRenderer: boolean;
|
|
373
|
+
/** The GPU the browser reports, "" when it hides it. */
|
|
374
|
+
gpu: string;
|
|
375
|
+
/** What this browser remembers about `gpu` failing under mediakit; see `forgetGpuFailures`. */
|
|
376
|
+
remembered: GpuRecord | null;
|
|
246
377
|
}
|
|
247
378
|
/** What `health` reports. */
|
|
248
379
|
interface PipelineHealth {
|
|
@@ -252,8 +383,12 @@ interface PipelineHealth {
|
|
|
252
383
|
/** Milliseconds since a frame last came out. */
|
|
253
384
|
sinceMs: number;
|
|
254
385
|
stalled: boolean;
|
|
386
|
+
/** Why some effects are off while the picture still runs (see `FrameStats.effectError`); "" when none. */
|
|
387
|
+
effectError: string;
|
|
255
388
|
}
|
|
256
|
-
/** Whether mediakit can run in this browser
|
|
389
|
+
/** Whether mediakit can run in this browser, and every reason it cannot. Creates and frees two WebGL contexts. */
|
|
390
|
+
declare function checkSupport(): SupportReport;
|
|
391
|
+
/** Whether mediakit can run in this browser at all; {@link checkSupport} says why not. */
|
|
257
392
|
declare function mediakitSupported(): boolean;
|
|
258
393
|
declare class VideoPipeline {
|
|
259
394
|
processedTrack?: MediaStreamTrack;
|
|
@@ -268,6 +403,15 @@ declare class VideoPipeline {
|
|
|
268
403
|
private stalled;
|
|
269
404
|
private watchdog;
|
|
270
405
|
private movedOff;
|
|
406
|
+
private raised;
|
|
407
|
+
private slowTicks;
|
|
408
|
+
private gpuRecoveries;
|
|
409
|
+
private gpu;
|
|
410
|
+
private faceColorLost;
|
|
411
|
+
private recovering;
|
|
412
|
+
private workerDialect;
|
|
413
|
+
private generator;
|
|
414
|
+
private piping;
|
|
271
415
|
/** What the worker last said about loading detectors. */
|
|
272
416
|
private workerLoading;
|
|
273
417
|
private frameSubs;
|
|
@@ -287,6 +431,11 @@ declare class VideoPipeline {
|
|
|
287
431
|
/** Every processed frame. */
|
|
288
432
|
subscribeFrames(cb: (frame: VideoFrame) => void): () => void;
|
|
289
433
|
private deliver;
|
|
434
|
+
private issue;
|
|
435
|
+
private watchQuality;
|
|
436
|
+
private noFaceColor;
|
|
437
|
+
/** A "link" loss rebuilds without face colour, a "run" loss as before; an "init" loss would only repeat. */
|
|
438
|
+
private recoverGpu;
|
|
290
439
|
private beat;
|
|
291
440
|
private startWatchdog;
|
|
292
441
|
private stopWatchdog;
|
|
@@ -297,6 +446,13 @@ declare class VideoPipeline {
|
|
|
297
446
|
/** Take over `source` and publish the result on {@link processedTrack}. */
|
|
298
447
|
start(source: MediaStreamTrack): Promise<void>;
|
|
299
448
|
private startMain;
|
|
449
|
+
/**
|
|
450
|
+
* Feed a different camera into the running pipeline, as Tencent's `resetCore(input)`. At the
|
|
451
|
+
* same resolution {@link processedTrack} stays the same track; otherwise the pipeline rebuilds
|
|
452
|
+
* and `onTrackReplaced` fires. The caller still owns both sources: neither is stopped here.
|
|
453
|
+
*/
|
|
454
|
+
replaceSource(next: MediaStreamTrack): Promise<MediaStreamTrack | undefined>;
|
|
455
|
+
private rebuild;
|
|
300
456
|
/** Swap the background in place - no pipeline rebuild, so the picture does not flash. */
|
|
301
457
|
switchTo(filter: BgFilter): Promise<void>;
|
|
302
458
|
/**
|
|
@@ -309,6 +465,7 @@ declare class VideoPipeline {
|
|
|
309
465
|
setEffects(effects: Effects): Promise<void>;
|
|
310
466
|
private pushRecipe;
|
|
311
467
|
stop(): Promise<void>;
|
|
468
|
+
private teardownTransports;
|
|
312
469
|
/**
|
|
313
470
|
* The image background decoded HERE, for the worker: it has no `Image`, so it cannot decode
|
|
314
471
|
* an SVG, which is every background meet bundles. Only when the path changed - the worker
|
|
@@ -350,9 +507,22 @@ declare class VideoPipeline {
|
|
|
350
507
|
/** Starts the worker and waits for its "ready". */
|
|
351
508
|
private attachWorker;
|
|
352
509
|
private startInsertable;
|
|
510
|
+
private pipeInsertable;
|
|
353
511
|
private startCanvas;
|
|
354
512
|
}
|
|
355
513
|
|
|
514
|
+
/** Which detectors {@link preloadDetectors} fetches; the MediaPipe runtime comes with any of them. */
|
|
515
|
+
interface PreloadParts {
|
|
516
|
+
person?: boolean;
|
|
517
|
+
classes?: boolean;
|
|
518
|
+
face?: boolean;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Warm the HTTP cache with the MediaPipe runtime and the chosen models, at low priority, so the
|
|
522
|
+
* first recipe that needs them builds without waiting on the network. Never rejects.
|
|
523
|
+
*/
|
|
524
|
+
declare function preloadDetectors(parts?: PreloadParts): Promise<void>;
|
|
525
|
+
|
|
356
526
|
/**
|
|
357
527
|
* Layers several sources onto one output, OBS style: cameras (each with its own mediakit
|
|
358
528
|
* recipe, `cutout` included), screen shares, video files, images, text and any canvas.
|
|
@@ -498,4 +668,4 @@ declare function renderText(text: string, style?: TextStyle): HTMLCanvasElement;
|
|
|
498
668
|
/** Where each of the face landmarker's first 468 landmarks lies on the canonical face texture. */
|
|
499
669
|
declare const FACE_UV: Float32Array<ArrayBuffer>;
|
|
500
670
|
|
|
501
|
-
export { BgFilter, Color, DebugView, Effects, Engine, type EngineCanvas, FACE_UV, type FrameStats, type PipelineHealth, type PipelineOptions, Scene, SceneLayer, type SceneOptions, type SceneSource, type SceneStats, type TextStyle, TransitionKind, type Transport, VideoPipeline, mediakitSupported, renderText };
|
|
671
|
+
export { BgFilter, Color, DebugView, Effects, Engine, type EngineCanvas, type EngineGuard, FACE_UV, type FrameStats, GpuLostError, type GpuRecord, type IssueCode, type LossPhase, type PipelineHealth, type PipelineIssue, type PipelineOptions, type PreloadParts, Scene, SceneLayer, type SceneOptions, type SceneSource, type SceneStats, type SupportReason, type SupportReport, type TextStyle, TransitionKind, type Transport, VideoPipeline, checkSupport, forgetGpuFailures, gpuRecord, mediakitSupported, preloadDetectors, renderText };
|