@tradalab/mediakit 2.4.0 → 2.6.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 +116 -0
- package/dist/{chunk-YW75KJJO.js → chunk-RWUGOTNJ.js} +12 -3
- package/dist/chunk-RWUGOTNJ.js.map +1 -0
- package/dist/detect-worker.js +22 -13
- package/dist/detect-worker.js.map +1 -1
- package/dist/index.d.ts +119 -5
- package/dist/index.js +471 -64
- package/dist/index.js.map +1 -1
- package/dist/mediakit.wasm +0 -0
- package/dist/recipe.d.ts +8 -0
- package/dist/recipe.js +1 -1
- package/dist/worker.js +299 -49
- package/dist/worker.js.map +1 -1
- package/package.json +11 -9
- package/dist/chunk-YW75KJJO.js.map +0 -1
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
|
*
|
|
@@ -97,6 +134,7 @@ declare class Engine {
|
|
|
97
134
|
private gapUs;
|
|
98
135
|
private prevTs;
|
|
99
136
|
private readonly sent;
|
|
137
|
+
private readonly lastSentAt;
|
|
100
138
|
private faceLatencyMs;
|
|
101
139
|
private readonly maskLatencyMs;
|
|
102
140
|
private faceTs;
|
|
@@ -124,15 +162,25 @@ declare class Engine {
|
|
|
124
162
|
last: FrameStats;
|
|
125
163
|
private constructor();
|
|
126
164
|
/** Main thread: makes its own canvas. A worker calls `on` with an OffscreenCanvas. */
|
|
127
|
-
static create(width: number, height: number, filter: BgFilter, effects?: Effects, alpha?: boolean, maxFaces?: number): Promise<Engine>;
|
|
165
|
+
static create(width: number, height: number, filter: BgFilter, effects?: Effects, alpha?: boolean, maxFaces?: number, guard?: EngineGuard): Promise<Engine>;
|
|
128
166
|
/**
|
|
129
167
|
* `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
|
|
130
168
|
* only a `cutout` background writes; it is fixed for the life of the context, so a host that
|
|
131
169
|
* may switch to `cutout` later has to ask for it here. `maxFaces` (1-3) is how many faces the
|
|
132
|
-
* landmarker looks for: below 3 it skips re-running its face detector on every call.
|
|
170
|
+
* landmarker looks for: below 3 it skips re-running its face detector on every call. Throws
|
|
171
|
+
* GpuLostError when the context is lost building the shaders, or this GPU is remembered for it.
|
|
133
172
|
*/
|
|
134
|
-
static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean, maxFaces?: number): Promise<Engine>;
|
|
173
|
+
static on(canvas: EngineCanvas, filter: BgFilter, effects?: Effects, background?: ImageBitmap, alpha?: boolean, maxFaces?: number, guard?: EngineGuard): Promise<Engine>;
|
|
174
|
+
/** The GPU the context reported at creation, "" when the browser hides it. */
|
|
175
|
+
get gpuName(): string;
|
|
135
176
|
get loading(): boolean;
|
|
177
|
+
/** The browser took the WebGL context away (GPU process reset or reclaimed); this Engine is done. */
|
|
178
|
+
get lost(): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* When the context was lost: "link" within 3 s of a face colour shader starting or still linking, else "run";
|
|
181
|
+
* null while it is not. The first read decides, and on the main thread it is remembered per GPU.
|
|
182
|
+
*/
|
|
183
|
+
get lostDuring(): LossPhase | null;
|
|
136
184
|
get outputCanvas(): EngineCanvas;
|
|
137
185
|
/** Draws an inner layer instead of the picture until set back to "off". */
|
|
138
186
|
setDebug(view: DebugView): void;
|
|
@@ -144,6 +192,10 @@ declare class Engine {
|
|
|
144
192
|
* cannot be decoded at all, and the main thread has to do it and transfer the bitmap.
|
|
145
193
|
*/
|
|
146
194
|
setRecipe(filter: BgFilter, effects?: Effects, background?: ImageBitmap): Promise<void>;
|
|
195
|
+
private noteLinking;
|
|
196
|
+
/** A worker, or the multiclass model, will bring the mask: no in-thread person model for it. */
|
|
197
|
+
private remoteMaskComing;
|
|
198
|
+
private gaveUp;
|
|
147
199
|
private ensureFace;
|
|
148
200
|
/** The detect worker for `kind`, made on first use; rejects when that kind must stay in-thread. */
|
|
149
201
|
private personRemoteWanted;
|
|
@@ -176,6 +228,7 @@ declare class Engine {
|
|
|
176
228
|
render(source: TexImageSource, timestampUs: number): boolean;
|
|
177
229
|
private remoteMaskKind;
|
|
178
230
|
private retuneDepth;
|
|
231
|
+
private dutyAllows;
|
|
179
232
|
private took;
|
|
180
233
|
private releaseHeld;
|
|
181
234
|
dropped(): boolean;
|
|
@@ -241,6 +294,28 @@ interface PipelineOptions {
|
|
|
241
294
|
}) => void;
|
|
242
295
|
/** The pipeline replaced `processedTrack` mid-session. */
|
|
243
296
|
onTrackReplaced?: (track: MediaStreamTrack, previous: MediaStreamTrack | undefined) => void;
|
|
297
|
+
/** Something degraded while running; see {@link IssueCode}. Each code fires once until it clears. */
|
|
298
|
+
onIssue?: (issue: PipelineIssue) => void;
|
|
299
|
+
}
|
|
300
|
+
/** What degraded; each code and what the app should do is in the README, "Handling a weak or failing GPU". */
|
|
301
|
+
type IssueCode = "stall" | "slow" | "effect-off" | "worker-moved" | "gpu-lost";
|
|
302
|
+
interface PipelineIssue {
|
|
303
|
+
code: IssueCode;
|
|
304
|
+
message: string;
|
|
305
|
+
transport: Transport;
|
|
306
|
+
}
|
|
307
|
+
/** `gpu-blocked`: this GPU lost its WebGL context building mediakit's shaders in the last 3 days. */
|
|
308
|
+
type SupportReason = "no-window" | "no-wasm" | "no-webgl2" | "no-transport" | "gpu-blocked";
|
|
309
|
+
interface SupportReport {
|
|
310
|
+
supported: boolean;
|
|
311
|
+
/** Every reason it cannot run, empty when supported. */
|
|
312
|
+
reasons: SupportReason[];
|
|
313
|
+
/** WebGL2 only through a software rasteriser (SwiftShader, llvmpipe): it runs, but slowly. */
|
|
314
|
+
softwareRenderer: boolean;
|
|
315
|
+
/** The GPU the browser reports, "" when it hides it. */
|
|
316
|
+
gpu: string;
|
|
317
|
+
/** What this browser remembers about `gpu` failing under mediakit; see `forgetGpuFailures`. */
|
|
318
|
+
remembered: GpuRecord | null;
|
|
244
319
|
}
|
|
245
320
|
/** What `health` reports. */
|
|
246
321
|
interface PipelineHealth {
|
|
@@ -250,8 +325,12 @@ interface PipelineHealth {
|
|
|
250
325
|
/** Milliseconds since a frame last came out. */
|
|
251
326
|
sinceMs: number;
|
|
252
327
|
stalled: boolean;
|
|
328
|
+
/** Why some effects are off while the picture still runs (see `FrameStats.effectError`); "" when none. */
|
|
329
|
+
effectError: string;
|
|
253
330
|
}
|
|
254
|
-
/** Whether mediakit can run in this browser
|
|
331
|
+
/** Whether mediakit can run in this browser, and every reason it cannot. Creates and frees two WebGL contexts. */
|
|
332
|
+
declare function checkSupport(): SupportReport;
|
|
333
|
+
/** Whether mediakit can run in this browser at all; {@link checkSupport} says why not. */
|
|
255
334
|
declare function mediakitSupported(): boolean;
|
|
256
335
|
declare class VideoPipeline {
|
|
257
336
|
processedTrack?: MediaStreamTrack;
|
|
@@ -266,6 +345,15 @@ declare class VideoPipeline {
|
|
|
266
345
|
private stalled;
|
|
267
346
|
private watchdog;
|
|
268
347
|
private movedOff;
|
|
348
|
+
private raised;
|
|
349
|
+
private slowTicks;
|
|
350
|
+
private gpuRecoveries;
|
|
351
|
+
private gpu;
|
|
352
|
+
private faceColorLost;
|
|
353
|
+
private recovering;
|
|
354
|
+
private workerDialect;
|
|
355
|
+
private generator;
|
|
356
|
+
private piping;
|
|
269
357
|
/** What the worker last said about loading detectors. */
|
|
270
358
|
private workerLoading;
|
|
271
359
|
private frameSubs;
|
|
@@ -285,6 +373,11 @@ declare class VideoPipeline {
|
|
|
285
373
|
/** Every processed frame. */
|
|
286
374
|
subscribeFrames(cb: (frame: VideoFrame) => void): () => void;
|
|
287
375
|
private deliver;
|
|
376
|
+
private issue;
|
|
377
|
+
private watchQuality;
|
|
378
|
+
private noFaceColor;
|
|
379
|
+
/** A "link" loss rebuilds without face colour, a "run" loss as before; an "init" loss would only repeat. */
|
|
380
|
+
private recoverGpu;
|
|
288
381
|
private beat;
|
|
289
382
|
private startWatchdog;
|
|
290
383
|
private stopWatchdog;
|
|
@@ -295,6 +388,13 @@ declare class VideoPipeline {
|
|
|
295
388
|
/** Take over `source` and publish the result on {@link processedTrack}. */
|
|
296
389
|
start(source: MediaStreamTrack): Promise<void>;
|
|
297
390
|
private startMain;
|
|
391
|
+
/**
|
|
392
|
+
* Feed a different camera into the running pipeline, as Tencent's `resetCore(input)`. At the
|
|
393
|
+
* same resolution {@link processedTrack} stays the same track; otherwise the pipeline rebuilds
|
|
394
|
+
* and `onTrackReplaced` fires. The caller still owns both sources: neither is stopped here.
|
|
395
|
+
*/
|
|
396
|
+
replaceSource(next: MediaStreamTrack): Promise<MediaStreamTrack | undefined>;
|
|
397
|
+
private rebuild;
|
|
298
398
|
/** Swap the background in place - no pipeline rebuild, so the picture does not flash. */
|
|
299
399
|
switchTo(filter: BgFilter): Promise<void>;
|
|
300
400
|
/**
|
|
@@ -307,6 +407,7 @@ declare class VideoPipeline {
|
|
|
307
407
|
setEffects(effects: Effects): Promise<void>;
|
|
308
408
|
private pushRecipe;
|
|
309
409
|
stop(): Promise<void>;
|
|
410
|
+
private teardownTransports;
|
|
310
411
|
/**
|
|
311
412
|
* The image background decoded HERE, for the worker: it has no `Image`, so it cannot decode
|
|
312
413
|
* an SVG, which is every background meet bundles. Only when the path changed - the worker
|
|
@@ -348,9 +449,22 @@ declare class VideoPipeline {
|
|
|
348
449
|
/** Starts the worker and waits for its "ready". */
|
|
349
450
|
private attachWorker;
|
|
350
451
|
private startInsertable;
|
|
452
|
+
private pipeInsertable;
|
|
351
453
|
private startCanvas;
|
|
352
454
|
}
|
|
353
455
|
|
|
456
|
+
/** Which detectors {@link preloadDetectors} fetches; the MediaPipe runtime comes with any of them. */
|
|
457
|
+
interface PreloadParts {
|
|
458
|
+
person?: boolean;
|
|
459
|
+
classes?: boolean;
|
|
460
|
+
face?: boolean;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Warm the HTTP cache with the MediaPipe runtime and the chosen models, at low priority, so the
|
|
464
|
+
* first recipe that needs them builds without waiting on the network. Never rejects.
|
|
465
|
+
*/
|
|
466
|
+
declare function preloadDetectors(parts?: PreloadParts): Promise<void>;
|
|
467
|
+
|
|
354
468
|
/**
|
|
355
469
|
* Layers several sources onto one output, OBS style: cameras (each with its own mediakit
|
|
356
470
|
* recipe, `cutout` included), screen shares, video files, images, text and any canvas.
|
|
@@ -496,4 +610,4 @@ declare function renderText(text: string, style?: TextStyle): HTMLCanvasElement;
|
|
|
496
610
|
/** Where each of the face landmarker's first 468 landmarks lies on the canonical face texture. */
|
|
497
611
|
declare const FACE_UV: Float32Array<ArrayBuffer>;
|
|
498
612
|
|
|
499
|
-
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 };
|
|
613
|
+
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 };
|