@voltkit-rtc/client 0.8.0 → 0.9.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/CHANGELOG.md +38 -0
- package/README.md +102 -0
- package/dist/cjs/diagnostics.d.ts +1 -1
- package/dist/cjs/diagnostics.js +1 -1
- package/dist/cjs/effects-core.d.ts +95 -0
- package/dist/cjs/effects-core.d.ts.map +1 -0
- package/dist/cjs/effects-core.js +154 -0
- package/dist/cjs/effects-core.js.map +1 -0
- package/dist/cjs/effects-gl.d.ts +79 -0
- package/dist/cjs/effects-gl.d.ts.map +1 -0
- package/dist/cjs/effects-gl.js +351 -0
- package/dist/cjs/effects-gl.js.map +1 -0
- package/dist/cjs/index.d.ts +57 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +278 -64
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/noise-suppression.d.ts +44 -0
- package/dist/cjs/noise-suppression.d.ts.map +1 -0
- package/dist/cjs/noise-suppression.js +103 -0
- package/dist/cjs/noise-suppression.js.map +1 -0
- package/dist/cjs/processors.d.ts +34 -0
- package/dist/cjs/processors.d.ts.map +1 -0
- package/dist/cjs/processors.js +10 -0
- package/dist/cjs/processors.js.map +1 -0
- package/dist/cjs/quality.d.ts +7 -1
- package/dist/cjs/quality.d.ts.map +1 -1
- package/dist/cjs/quality.js +2 -1
- package/dist/cjs/quality.js.map +1 -1
- package/dist/cjs/video-effects.d.ts +93 -0
- package/dist/cjs/video-effects.d.ts.map +1 -0
- package/dist/cjs/video-effects.js +493 -0
- package/dist/cjs/video-effects.js.map +1 -0
- package/dist/esm/diagnostics.d.ts +1 -1
- package/dist/esm/diagnostics.js +1 -1
- package/dist/esm/effects-core.d.ts +95 -0
- package/dist/esm/effects-core.d.ts.map +1 -0
- package/dist/esm/effects-core.js +142 -0
- package/dist/esm/effects-core.js.map +1 -0
- package/dist/esm/effects-gl.d.ts +79 -0
- package/dist/esm/effects-gl.d.ts.map +1 -0
- package/dist/esm/effects-gl.js +347 -0
- package/dist/esm/effects-gl.js.map +1 -0
- package/dist/esm/index.d.ts +57 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +278 -64
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/noise-suppression.d.ts +44 -0
- package/dist/esm/noise-suppression.d.ts.map +1 -0
- package/dist/esm/noise-suppression.js +99 -0
- package/dist/esm/noise-suppression.js.map +1 -0
- package/dist/esm/processors.d.ts +34 -0
- package/dist/esm/processors.d.ts.map +1 -0
- package/dist/esm/processors.js +9 -0
- package/dist/esm/processors.js.map +1 -0
- package/dist/esm/quality.d.ts +7 -1
- package/dist/esm/quality.d.ts.map +1 -1
- package/dist/esm/quality.js +2 -1
- package/dist/esm/quality.js.map +1 -1
- package/dist/esm/video-effects.d.ts +93 -0
- package/dist/esm/video-effects.d.ts.map +1 -0
- package/dist/esm/video-effects.js +488 -0
- package/dist/esm/video-effects.js.map +1 -0
- package/package.json +31 -1
- package/src/diagnostics.ts +1 -1
- package/src/effects-core.ts +177 -0
- package/src/effects-gl.ts +384 -0
- package/src/index.ts +276 -63
- package/src/noise-suppression.ts +135 -0
- package/src/processors.ts +35 -0
- package/src/quality.ts +9 -2
- package/src/video-effects.ts +552 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_LANDSCAPE_MODEL = exports.DEFAULT_SEGMENTER_MODEL = exports.MEDIAPIPE_VERSION = void 0;
|
|
4
|
+
exports.isVideoEffectsSupported = isVideoEffectsSupported;
|
|
5
|
+
exports.createVideoEffects = createVideoEffects;
|
|
6
|
+
/**
|
|
7
|
+
* Virtual background and beauty for the camera (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-5): a blurred or
|
|
8
|
+
* replaced background and skin smoothing, as LiveKit's track processors, Agora's and ZEGOCLOUD's virtual background and
|
|
9
|
+
* beauty extensions, and Tencent TRTC's video effect plugin do -- in the browser, on the GPU.
|
|
10
|
+
*
|
|
11
|
+
* Imported on its own (`@voltkit-rtc/client/video-effects`), so an app that does not use it never ships it:
|
|
12
|
+
*
|
|
13
|
+
* import { createVideoEffects } from '@voltkit-rtc/client/video-effects';
|
|
14
|
+
* const effects = createVideoEffects({ background: 'blur', beauty: true });
|
|
15
|
+
* await client.setVideoProcessor(effects);
|
|
16
|
+
* await effects.update({ background: { image: '/office.jpg' } }); // live, no pause for viewers
|
|
17
|
+
*
|
|
18
|
+
* Finding the person takes Google's MediaPipe selfie segmenter: install `@mediapipe/tasks-vision@0.10.35` next to the
|
|
19
|
+
* SDK (an optional peer dependency, 0.10.35 exactly -- later versions report usage to Google). Its wasm (3 MB
|
|
20
|
+
* compressed) and the model (250 kB) load the first time a background effect is used: the wasm from jsDelivr at that
|
|
21
|
+
* version and the model from Google, unless you serve them yourself (`wasmPath`, `modelUrl`). Beauty alone needs none
|
|
22
|
+
* of it.
|
|
23
|
+
*
|
|
24
|
+
* Chrome and Edge process each camera frame as it arrives (insertable streams: smooth, and it keeps going in a
|
|
25
|
+
* background tab). Firefox and Safari draw from a hidden video on a worker's timer into a captured canvas -- what
|
|
26
|
+
* LiveKit, Twilio and Amazon Chime fall back to -- which a background tab can slow down.
|
|
27
|
+
*/
|
|
28
|
+
const effects_core_js_1 = require("./effects-core.js");
|
|
29
|
+
const effects_gl_js_1 = require("./effects-gl.js");
|
|
30
|
+
/** The `@mediapipe/tasks-vision` version this SDK was tested with; the default wasm URL points at it. */
|
|
31
|
+
exports.MEDIAPIPE_VERSION = '0.10.35';
|
|
32
|
+
const MEDIAPIPE_WASM = `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${exports.MEDIAPIPE_VERSION}/wasm`;
|
|
33
|
+
/** Google's selfie segmenter for portrait and square pictures (phones), at a fixed version. */
|
|
34
|
+
exports.DEFAULT_SEGMENTER_MODEL = 'https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/1/selfie_segmenter.tflite';
|
|
35
|
+
/**
|
|
36
|
+
* Its landscape version, for wide pictures (webcams): fed a 16:9 frame, the square model leaves patches of the room
|
|
37
|
+
* beside the head, the landscape one traces it cleanly (as LiveKit, Twilio, Chime and TRTC use for webcams).
|
|
38
|
+
*/
|
|
39
|
+
exports.DEFAULT_LANDSCAPE_MODEL = 'https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter_landscape/float16/1/selfie_segmenter_landscape.tflite';
|
|
40
|
+
/** Whether this browser can run the effects (WebGL2, and a way to take and give back frames). */
|
|
41
|
+
function isVideoEffectsSupported() {
|
|
42
|
+
if (typeof document === 'undefined' || typeof WebGL2RenderingContext === 'undefined')
|
|
43
|
+
return false;
|
|
44
|
+
if (pumpKind() === null)
|
|
45
|
+
return false;
|
|
46
|
+
try {
|
|
47
|
+
const gl = document.createElement('canvas').getContext('webgl2');
|
|
48
|
+
if (!gl)
|
|
49
|
+
return false;
|
|
50
|
+
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function pumpKind() {
|
|
58
|
+
const g = globalThis;
|
|
59
|
+
if (typeof g.MediaStreamTrackProcessor === 'function' && typeof g.MediaStreamTrackGenerator === 'function' && typeof VideoFrame === 'function')
|
|
60
|
+
return 'insertable';
|
|
61
|
+
if (typeof HTMLCanvasElement !== 'undefined' && typeof HTMLCanvasElement.prototype.captureStream === 'function')
|
|
62
|
+
return 'canvas';
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** MediaPipe's selfie segmenter, on the GPU where it starts, else the CPU. */
|
|
66
|
+
async function loadMediaPipe(wasmPath, modelUrl) {
|
|
67
|
+
const vision = await Promise.resolve().then(() => require('@mediapipe/tasks-vision'));
|
|
68
|
+
const fileset = await vision.FilesetResolver.forVisionTasks(wasmPath);
|
|
69
|
+
const make = (delegate) => vision.ImageSegmenter.createFromOptions(fileset, {
|
|
70
|
+
baseOptions: { modelAssetPath: modelUrl, delegate },
|
|
71
|
+
runningMode: 'VIDEO',
|
|
72
|
+
outputConfidenceMasks: true,
|
|
73
|
+
outputCategoryMask: false,
|
|
74
|
+
});
|
|
75
|
+
let segmenter;
|
|
76
|
+
try {
|
|
77
|
+
segmenter = await make('GPU');
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
segmenter = await make('CPU');
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
segment(input, timestampMs, use) {
|
|
84
|
+
segmenter.segmentForVideo(input, timestampMs, (result) => {
|
|
85
|
+
// The selfie segmenter's one mask: how sure it is that each pixel is the person. Only valid in here.
|
|
86
|
+
const mask = result.confidenceMasks?.[0];
|
|
87
|
+
if (mask)
|
|
88
|
+
use(mask.getAsFloat32Array());
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
close() {
|
|
92
|
+
segmenter.close();
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const browserDeps = { loadSegmenter: loadMediaPipe };
|
|
97
|
+
/** The largest side a background picture is kept at, to spare the GPU's memory. */
|
|
98
|
+
const PICTURE_MAX = 1920;
|
|
99
|
+
async function loadPicture(source) {
|
|
100
|
+
let input;
|
|
101
|
+
if (typeof source === 'string') {
|
|
102
|
+
const img = new Image();
|
|
103
|
+
img.crossOrigin = 'anonymous';
|
|
104
|
+
img.decoding = 'async';
|
|
105
|
+
img.src = source;
|
|
106
|
+
await img.decode();
|
|
107
|
+
input = img;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
input = source;
|
|
111
|
+
}
|
|
112
|
+
let bitmap = await createImageBitmap(input);
|
|
113
|
+
const longest = Math.max(bitmap.width, bitmap.height);
|
|
114
|
+
if (longest > PICTURE_MAX) {
|
|
115
|
+
const scale = PICTURE_MAX / longest;
|
|
116
|
+
const smaller = await createImageBitmap(bitmap, { resizeWidth: Math.round(bitmap.width * scale), resizeHeight: Math.round(bitmap.height * scale), resizeQuality: 'high' });
|
|
117
|
+
bitmap.close();
|
|
118
|
+
bitmap = smaller;
|
|
119
|
+
}
|
|
120
|
+
const b = bitmap;
|
|
121
|
+
return { image: b, width: b.width, height: b.height, close: () => b.close() };
|
|
122
|
+
}
|
|
123
|
+
/** Chrome and Edge: every camera frame as it arrives, out through a generator track; no timer, no page rendering. */
|
|
124
|
+
function insertablePump(source, draw, canvas, frameIntervalMs, minGapUs) {
|
|
125
|
+
const g = globalThis;
|
|
126
|
+
const reader = new g.MediaStreamTrackProcessor({ track: source }).readable.getReader();
|
|
127
|
+
const generator = new g.MediaStreamTrackGenerator({ kind: 'video' });
|
|
128
|
+
const writer = generator.writable.getWriter();
|
|
129
|
+
let stopped = false;
|
|
130
|
+
let lastOut = Number.NEGATIVE_INFINITY;
|
|
131
|
+
let failures = 0;
|
|
132
|
+
const stop = () => {
|
|
133
|
+
if (stopped)
|
|
134
|
+
return;
|
|
135
|
+
stopped = true;
|
|
136
|
+
void reader.cancel().catch(() => undefined);
|
|
137
|
+
void writer.close().catch(() => undefined);
|
|
138
|
+
generator.stop();
|
|
139
|
+
};
|
|
140
|
+
void (async () => {
|
|
141
|
+
try {
|
|
142
|
+
for (;;) {
|
|
143
|
+
const { value: frame, done } = await reader.read();
|
|
144
|
+
if (done || !frame)
|
|
145
|
+
return;
|
|
146
|
+
if (stopped || generator.readyState === 'ended') {
|
|
147
|
+
frame.close();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// Paused (the camera is off), or sooner than maxFrameRate allows: nothing to do for this one.
|
|
151
|
+
if (!generator.enabled || frame.timestamp - lastOut < minGapUs) {
|
|
152
|
+
frame.close();
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
let out = null;
|
|
156
|
+
try {
|
|
157
|
+
draw(frame, frame.displayWidth, frame.displayHeight, frameIntervalMs);
|
|
158
|
+
out = new VideoFrame(canvas, { timestamp: frame.timestamp });
|
|
159
|
+
lastOut = frame.timestamp;
|
|
160
|
+
failures = 0;
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
// A frame that cannot be drawn is dropped, never sent as it is: the background may be what is hidden.
|
|
164
|
+
if ((failures += 1) === 1)
|
|
165
|
+
console.warn('video effects: a frame could not be processed', err);
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
frame.close();
|
|
169
|
+
}
|
|
170
|
+
if (out)
|
|
171
|
+
await writer.write(out);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
// The output was stopped, or the camera went.
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
stop();
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
return { output: generator, stop };
|
|
182
|
+
}
|
|
183
|
+
/** A timer that keeps time in a background tab: a worker's (LiveKit's FrameTicker), the page's if a CSP refuses it. */
|
|
184
|
+
function startTicker(ms, tick) {
|
|
185
|
+
let interval = null;
|
|
186
|
+
const onPage = () => {
|
|
187
|
+
if (interval === null)
|
|
188
|
+
interval = setInterval(tick, ms);
|
|
189
|
+
};
|
|
190
|
+
let worker = null;
|
|
191
|
+
let url = null;
|
|
192
|
+
try {
|
|
193
|
+
url = URL.createObjectURL(new Blob(['let t=null;onmessage=(e)=>{clearInterval(t);t=e.data>0?setInterval(()=>postMessage(0),e.data):null;};'], { type: 'text/javascript' }));
|
|
194
|
+
worker = new Worker(url);
|
|
195
|
+
worker.onmessage = () => tick();
|
|
196
|
+
worker.onerror = () => {
|
|
197
|
+
worker?.terminate();
|
|
198
|
+
worker = null;
|
|
199
|
+
onPage();
|
|
200
|
+
};
|
|
201
|
+
worker.postMessage(ms);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
worker = null;
|
|
205
|
+
onPage();
|
|
206
|
+
}
|
|
207
|
+
return () => {
|
|
208
|
+
worker?.terminate();
|
|
209
|
+
worker = null;
|
|
210
|
+
if (interval !== null)
|
|
211
|
+
clearInterval(interval);
|
|
212
|
+
interval = null;
|
|
213
|
+
if (url)
|
|
214
|
+
URL.revokeObjectURL(url);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** Firefox and Safari: a hidden video drawn on a worker's timer, the canvas captured as the output. */
|
|
218
|
+
function canvasPump(source, draw, canvas, frameIntervalMs) {
|
|
219
|
+
const video = document.createElement('video');
|
|
220
|
+
video.muted = true;
|
|
221
|
+
video.playsInline = true;
|
|
222
|
+
video.autoplay = true;
|
|
223
|
+
video.srcObject = new MediaStream([source]);
|
|
224
|
+
const play = () => { void video.play().catch(() => undefined); };
|
|
225
|
+
play();
|
|
226
|
+
const output = canvas.captureStream().getVideoTracks()[0];
|
|
227
|
+
if (!output)
|
|
228
|
+
throw new Error('video effects: this browser gives no track from a canvas');
|
|
229
|
+
let stopped = false;
|
|
230
|
+
let lastTime = -1;
|
|
231
|
+
let failures = 0;
|
|
232
|
+
const stop = () => {
|
|
233
|
+
if (stopped)
|
|
234
|
+
return;
|
|
235
|
+
stopped = true;
|
|
236
|
+
stopTicker();
|
|
237
|
+
video.pause();
|
|
238
|
+
video.srcObject = null;
|
|
239
|
+
output.stop();
|
|
240
|
+
};
|
|
241
|
+
const stopTicker = startTicker(frameIntervalMs, () => {
|
|
242
|
+
if (stopped)
|
|
243
|
+
return;
|
|
244
|
+
if (output.readyState === 'ended' || source.readyState === 'ended') {
|
|
245
|
+
stop();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// WebKit can refuse play() until later: keep asking.
|
|
249
|
+
if (video.paused)
|
|
250
|
+
play();
|
|
251
|
+
if (!output.enabled || video.readyState < 2 || video.videoWidth === 0)
|
|
252
|
+
return;
|
|
253
|
+
if (video.currentTime === lastTime)
|
|
254
|
+
return;
|
|
255
|
+
lastTime = video.currentTime;
|
|
256
|
+
try {
|
|
257
|
+
draw(video, video.videoWidth, video.videoHeight, frameIntervalMs);
|
|
258
|
+
failures = 0;
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
if ((failures += 1) === 1)
|
|
262
|
+
console.warn('video effects: a frame could not be processed', err);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return { output, stop };
|
|
266
|
+
}
|
|
267
|
+
/** Virtual background and beauty, for `client.setVideoProcessor()`. */
|
|
268
|
+
function createVideoEffects(options = {}, stand = {}) {
|
|
269
|
+
const deps = { ...browserDeps, ...stand };
|
|
270
|
+
const wasmPath = options.wasmPath ?? MEDIAPIPE_WASM;
|
|
271
|
+
const modelFor = (width, height) => options.modelUrl ?? (width > height ? exports.DEFAULT_LANDSCAPE_MODEL : exports.DEFAULT_SEGMENTER_MODEL);
|
|
272
|
+
const maxFrameRate = typeof options.maxFrameRate === 'number' && options.maxFrameRate > 0 ? options.maxFrameRate : null;
|
|
273
|
+
const state = {
|
|
274
|
+
mode: 'none',
|
|
275
|
+
blur: (0, effects_core_js_1.blurLevel)(options.blur),
|
|
276
|
+
beauty: (0, effects_core_js_1.beautySettings)(options.beauty),
|
|
277
|
+
};
|
|
278
|
+
let picture = null;
|
|
279
|
+
// By model: one for wide pictures, one for tall ones, each loaded when first needed.
|
|
280
|
+
const segmenters = new Map();
|
|
281
|
+
const loading = new Map();
|
|
282
|
+
// The camera's shape, for the model to load before it is seen; a webcam's until a camera is given.
|
|
283
|
+
let shape = { width: 1280, height: 720 };
|
|
284
|
+
let renderer = null;
|
|
285
|
+
let pipeline = null;
|
|
286
|
+
let destroyed = false;
|
|
287
|
+
let overloaded = false;
|
|
288
|
+
const pacer = new effects_core_js_1.SegmentationPacer();
|
|
289
|
+
const clock = new effects_core_js_1.MonotonicClock();
|
|
290
|
+
// Per camera: the mask and how far along it is.
|
|
291
|
+
let maskReady = false;
|
|
292
|
+
let steady = null;
|
|
293
|
+
let maskBytes = new Uint8Array(0);
|
|
294
|
+
let frameIndex = 0;
|
|
295
|
+
let segCanvas = null;
|
|
296
|
+
let segContext = null;
|
|
297
|
+
let pictureUploaded = null;
|
|
298
|
+
const ensureSegmenter = (model) => {
|
|
299
|
+
const ready = segmenters.get(model);
|
|
300
|
+
if (ready)
|
|
301
|
+
return Promise.resolve(ready);
|
|
302
|
+
let pending = loading.get(model);
|
|
303
|
+
if (!pending) {
|
|
304
|
+
pending = deps.loadSegmenter(wasmPath, model).then((s) => {
|
|
305
|
+
loading.delete(model);
|
|
306
|
+
if (destroyed) {
|
|
307
|
+
s.close();
|
|
308
|
+
throw new Error('video effects: destroyed');
|
|
309
|
+
}
|
|
310
|
+
segmenters.set(model, s);
|
|
311
|
+
return s;
|
|
312
|
+
}, (err) => {
|
|
313
|
+
loading.delete(model); // tried again next time (a network blip)
|
|
314
|
+
throw err;
|
|
315
|
+
});
|
|
316
|
+
loading.set(model, pending);
|
|
317
|
+
}
|
|
318
|
+
return pending;
|
|
319
|
+
};
|
|
320
|
+
/** A fresh start for the mask: nothing behind the person shows until the next one is found. */
|
|
321
|
+
const restartMask = () => {
|
|
322
|
+
maskReady = false;
|
|
323
|
+
steady = null;
|
|
324
|
+
frameIndex = 0;
|
|
325
|
+
};
|
|
326
|
+
const segmentInto = (input, width, height, frameIntervalMs) => {
|
|
327
|
+
const model = modelFor(width, height);
|
|
328
|
+
let seg = segmenters.get(model);
|
|
329
|
+
if (!seg) {
|
|
330
|
+
// The camera turned (a phone rotated): the other model loads meanwhile, and the one there is goes on.
|
|
331
|
+
void ensureSegmenter(model).catch(() => undefined);
|
|
332
|
+
seg = segmenters.values().next().value;
|
|
333
|
+
}
|
|
334
|
+
if (!seg || !renderer)
|
|
335
|
+
return;
|
|
336
|
+
const size = (0, effects_core_js_1.segmentationSize)(width, height);
|
|
337
|
+
if (!segCanvas || segCanvas.width !== size.width || segCanvas.height !== size.height) {
|
|
338
|
+
segCanvas = typeof OffscreenCanvas === 'function' ? new OffscreenCanvas(size.width, size.height) : Object.assign(document.createElement('canvas'), size);
|
|
339
|
+
segContext = segCanvas.getContext('2d');
|
|
340
|
+
maskBytes = new Uint8Array(size.width * size.height);
|
|
341
|
+
steady = null;
|
|
342
|
+
}
|
|
343
|
+
if (!segContext)
|
|
344
|
+
return;
|
|
345
|
+
segContext.drawImage(input, 0, 0, size.width, size.height);
|
|
346
|
+
const started = performance.now();
|
|
347
|
+
seg.segment(segCanvas, clock.next(started), (confidence) => {
|
|
348
|
+
if (confidence.length !== size.width * size.height || !renderer)
|
|
349
|
+
return;
|
|
350
|
+
steady = (0, effects_core_js_1.smoothMask)(confidence, steady, maskBytes);
|
|
351
|
+
renderer.uploadMask(maskBytes, size.width, size.height);
|
|
352
|
+
maskReady = true;
|
|
353
|
+
});
|
|
354
|
+
const now = performance.now();
|
|
355
|
+
pacer.report(now - started, frameIntervalMs, now);
|
|
356
|
+
const over = pacer.overloaded(frameIntervalMs);
|
|
357
|
+
if (over !== overloaded) {
|
|
358
|
+
overloaded = over;
|
|
359
|
+
try {
|
|
360
|
+
options.onOverload?.(over);
|
|
361
|
+
}
|
|
362
|
+
catch { /* the app's */ }
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const draw = (input, width, height, frameIntervalMs) => {
|
|
366
|
+
const r = renderer;
|
|
367
|
+
if (!r || r.lost || !(width > 0 && height > 0))
|
|
368
|
+
return;
|
|
369
|
+
r.setSize(width, height);
|
|
370
|
+
r.uploadFrame(input);
|
|
371
|
+
const mode = state.mode;
|
|
372
|
+
if (mode !== 'none') {
|
|
373
|
+
if (pacer.shouldSegment(frameIndex))
|
|
374
|
+
segmentInto(input, width, height, frameIntervalMs);
|
|
375
|
+
frameIndex += 1;
|
|
376
|
+
}
|
|
377
|
+
if (mode === 'image' && picture && pictureUploaded !== picture) {
|
|
378
|
+
r.setPicture(picture.image, picture.width, picture.height);
|
|
379
|
+
pictureUploaded = picture;
|
|
380
|
+
}
|
|
381
|
+
else if (mode !== 'image' && pictureUploaded) {
|
|
382
|
+
r.setPicture(null);
|
|
383
|
+
pictureUploaded = null;
|
|
384
|
+
}
|
|
385
|
+
r.render({
|
|
386
|
+
mode,
|
|
387
|
+
blurSigma: (0, effects_core_js_1.blurSigma)(state.blur, r.size.blurHeight),
|
|
388
|
+
beauty: state.beauty,
|
|
389
|
+
maskReady,
|
|
390
|
+
cover: picture ? (0, effects_core_js_1.coverFit)(picture.width, picture.height, width, height) : { sx: 1, sy: 1, ox: 0, oy: 0 },
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
const apply = async (changes) => {
|
|
394
|
+
if (destroyed)
|
|
395
|
+
throw new Error('video effects: destroyed');
|
|
396
|
+
let mode = state.mode;
|
|
397
|
+
let nextPicture;
|
|
398
|
+
if ('background' in changes) {
|
|
399
|
+
mode = (0, effects_core_js_1.backgroundMode)(changes.background);
|
|
400
|
+
// Loaded before anything changes: one that fails leaves the effects as they were.
|
|
401
|
+
if (mode === 'image')
|
|
402
|
+
nextPicture = await loadPicture(changes.background.image);
|
|
403
|
+
if (mode !== 'none') {
|
|
404
|
+
try {
|
|
405
|
+
await ensureSegmenter(modelFor(shape.width, shape.height));
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
nextPicture?.close();
|
|
409
|
+
throw err;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (destroyed) {
|
|
414
|
+
nextPicture?.close();
|
|
415
|
+
throw new Error('video effects: destroyed');
|
|
416
|
+
}
|
|
417
|
+
if ('blur' in changes)
|
|
418
|
+
state.blur = (0, effects_core_js_1.blurLevel)(changes.blur);
|
|
419
|
+
if ('beauty' in changes)
|
|
420
|
+
state.beauty = (0, effects_core_js_1.beautySettings)(changes.beauty);
|
|
421
|
+
if (mode !== state.mode)
|
|
422
|
+
restartMask();
|
|
423
|
+
if (nextPicture !== undefined || mode !== 'image') {
|
|
424
|
+
const old = picture;
|
|
425
|
+
picture = nextPicture ?? null;
|
|
426
|
+
if (old && old !== picture)
|
|
427
|
+
old.close();
|
|
428
|
+
}
|
|
429
|
+
state.mode = mode;
|
|
430
|
+
};
|
|
431
|
+
// The background asked for at creation starts loading now, so it is likely ready by the time the camera is.
|
|
432
|
+
let queue = apply({ background: options.background ?? 'none' });
|
|
433
|
+
queue.catch(() => undefined);
|
|
434
|
+
const pumpChoice = deps.pump ?? pumpKind();
|
|
435
|
+
return {
|
|
436
|
+
name: 'video-effects',
|
|
437
|
+
async process(track) {
|
|
438
|
+
if (destroyed)
|
|
439
|
+
throw new Error('video effects: destroyed');
|
|
440
|
+
if (!pumpChoice)
|
|
441
|
+
throw new Error('video effects are not supported in this browser');
|
|
442
|
+
await queue; // the background asked for at creation: a failure is the SDK's to report
|
|
443
|
+
const settings = track.getSettings();
|
|
444
|
+
if (typeof settings.width === 'number' && typeof settings.height === 'number' && settings.width > 0 && settings.height > 0) {
|
|
445
|
+
shape = { width: settings.width, height: settings.height };
|
|
446
|
+
}
|
|
447
|
+
// The model for this camera's shape, before its first frame: a background shows nothing behind the person meanwhile.
|
|
448
|
+
if (state.mode !== 'none')
|
|
449
|
+
await ensureSegmenter(modelFor(shape.width, shape.height));
|
|
450
|
+
pipeline?.stop();
|
|
451
|
+
pipeline = null;
|
|
452
|
+
if (!renderer) {
|
|
453
|
+
const canvas = pumpChoice === 'insertable' && typeof OffscreenCanvas === 'function' ? new OffscreenCanvas(2, 2) : document.createElement('canvas');
|
|
454
|
+
renderer = new effects_gl_js_1.EffectsRenderer(canvas);
|
|
455
|
+
}
|
|
456
|
+
restartMask();
|
|
457
|
+
const cameraRate = typeof settings.frameRate === 'number' && settings.frameRate > 0 ? settings.frameRate : 30;
|
|
458
|
+
const rate = maxFrameRate ? Math.min(maxFrameRate, cameraRate) : cameraRate;
|
|
459
|
+
const frameIntervalMs = 1000 / rate;
|
|
460
|
+
pipeline = pumpChoice === 'insertable'
|
|
461
|
+
? insertablePump(track, draw, renderer.canvas, frameIntervalMs, maxFrameRate ? (1e6 / maxFrameRate) * 0.8 : 0)
|
|
462
|
+
: canvasPump(track, draw, renderer.canvas, frameIntervalMs);
|
|
463
|
+
return pipeline.output;
|
|
464
|
+
},
|
|
465
|
+
update(changes) {
|
|
466
|
+
// One change at a time, in the order asked.
|
|
467
|
+
const next = queue.catch(() => undefined).then(() => apply(changes));
|
|
468
|
+
queue = next.catch(() => undefined);
|
|
469
|
+
return next;
|
|
470
|
+
},
|
|
471
|
+
get settings() {
|
|
472
|
+
return { background: state.mode, blur: state.blur, beauty: state.beauty ? { ...state.beauty } : null };
|
|
473
|
+
},
|
|
474
|
+
get stats() {
|
|
475
|
+
return { segmentEvery: pacer.interval, segmentMs: Math.round(pacer.segmentMs * 10) / 10, overloaded };
|
|
476
|
+
},
|
|
477
|
+
destroy() {
|
|
478
|
+
if (destroyed)
|
|
479
|
+
return;
|
|
480
|
+
destroyed = true;
|
|
481
|
+
pipeline?.stop();
|
|
482
|
+
pipeline = null;
|
|
483
|
+
for (const s of segmenters.values())
|
|
484
|
+
s.close();
|
|
485
|
+
segmenters.clear();
|
|
486
|
+
renderer?.dispose();
|
|
487
|
+
renderer = null;
|
|
488
|
+
picture?.close();
|
|
489
|
+
picture = null;
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
//# sourceMappingURL=video-effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-effects.js","sourceRoot":"","sources":["../../src/video-effects.ts"],"names":[],"mappings":";;;AAyGA,0DAWC;AAyND,gDA0NC;AAviBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,uDAc2B;AAC3B,mDAAkD;AAKlD,yGAAyG;AAC5F,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAC3C,MAAM,cAAc,GAAG,wDAAwD,yBAAiB,OAAO,CAAC;AACxG,+FAA+F;AAClF,QAAA,uBAAuB,GAAG,oHAAoH,CAAC;AAC5J;;;GAGG;AACU,QAAA,uBAAuB,GAAG,wIAAwI,CAAC;AAqDhL,iGAAiG;AACjG,SAAgB,uBAAuB;IACrC,IAAI,OAAO,QAAQ,KAAK,WAAW,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IAAI,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* attach to a support ticket: the SDK's recent events (a ring buffer) and its state now.
|
|
7
7
|
*/
|
|
8
8
|
/** This package's version; kept equal to package.json by a test. */
|
|
9
|
-
export declare const SDK_VERSION = "0.
|
|
9
|
+
export declare const SDK_VERSION = "0.9.1";
|
|
10
10
|
/** How many recent events the log keeps. */
|
|
11
11
|
export declare const DIAGNOSTICS_LOG_SIZE = 200;
|
|
12
12
|
export interface DiagnosticsEntry {
|
package/dist/esm/diagnostics.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* attach to a support ticket: the SDK's recent events (a ring buffer) and its state now.
|
|
7
7
|
*/
|
|
8
8
|
/** This package's version; kept equal to package.json by a test. */
|
|
9
|
-
export const SDK_VERSION = '0.
|
|
9
|
+
export const SDK_VERSION = '0.9.1';
|
|
10
10
|
/** How many recent events the log keeps. */
|
|
11
11
|
export const DIAGNOSTICS_LOG_SIZE = 200;
|
|
12
12
|
/** The events worth keeping for support, and how to summarise each. */
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video effects, the parts that need no browser (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-5): settings,
|
|
3
|
+
* fitting a background image, the size segmentation runs at, and pacing it on a slow device. Kept apart from the
|
|
4
|
+
* WebGL and MediaPipe code so they are tested in Node.
|
|
5
|
+
*/
|
|
6
|
+
/** A background picture: a URL, or anything the browser can draw. */
|
|
7
|
+
export type BackgroundImageSource = string | Blob | ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas;
|
|
8
|
+
/** What happens behind the person: nothing, a blur, or a picture. */
|
|
9
|
+
export type BackgroundSetting = 'none' | 'blur' | {
|
|
10
|
+
image: BackgroundImageSource;
|
|
11
|
+
};
|
|
12
|
+
/** Beauty, each 0-1 (Agora's beauty effect has the same four). */
|
|
13
|
+
export interface BeautyOptions {
|
|
14
|
+
/** Skin smoothing. Default 0.5. */
|
|
15
|
+
smooth?: number;
|
|
16
|
+
/** Brightening. Default 0.3. */
|
|
17
|
+
brighten?: number;
|
|
18
|
+
/** A rosier skin. Default 0.1. */
|
|
19
|
+
redness?: number;
|
|
20
|
+
/** Sharper eyes, hair and edges (not skin). Default 0.3. */
|
|
21
|
+
sharpen?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface BeautySettings {
|
|
24
|
+
smooth: number;
|
|
25
|
+
brighten: number;
|
|
26
|
+
redness: number;
|
|
27
|
+
sharpen: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const DEFAULT_BEAUTY: Readonly<BeautySettings>;
|
|
30
|
+
/** The blur behind the person, 1 (light) to 10 (strong). */
|
|
31
|
+
export declare const DEFAULT_BLUR = 5;
|
|
32
|
+
/** Beauty settings from what the app passed: `true` is the defaults, `false`/`null` is off. */
|
|
33
|
+
export declare function beautySettings(options: BeautyOptions | boolean | null | undefined): BeautySettings | null;
|
|
34
|
+
/** A blur level from what the app passed: 1-10, rounded; anything else is the default. */
|
|
35
|
+
export declare function blurLevel(value: unknown): number;
|
|
36
|
+
/**
|
|
37
|
+
* The blur's Gaussian sigma, in texels of the quarter-size picture it is computed on: a share of the picture's height,
|
|
38
|
+
* so a level looks the same at 480p and 1080p.
|
|
39
|
+
*/
|
|
40
|
+
export declare function blurSigma(level: number, blurHeight: number): number;
|
|
41
|
+
/** What the background setting asks of the pipeline. */
|
|
42
|
+
export declare function backgroundMode(setting: BackgroundSetting | undefined | null): 'none' | 'blur' | 'image';
|
|
43
|
+
/**
|
|
44
|
+
* Fit a background picture to the frame the way CSS `object-fit: cover` does: it fills the frame, cropped evenly on
|
|
45
|
+
* the long side, never stretched. Returns the texture transform `imageUv = frameUv * scale + offset`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function coverFit(imageWidth: number, imageHeight: number, frameWidth: number, frameHeight: number): {
|
|
48
|
+
sx: number;
|
|
49
|
+
sy: number;
|
|
50
|
+
ox: number;
|
|
51
|
+
oy: number;
|
|
52
|
+
};
|
|
53
|
+
/** The size the person is found at: the frame scaled so its longer side is `longSide` (the model's input). */
|
|
54
|
+
export declare function segmentationSize(width: number, height: number, longSide?: number): {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
/** How fast the mask follows a new one: lower is steadier between frames, higher follows movement sooner. */
|
|
59
|
+
export declare const MASK_FOLLOW = 0.65;
|
|
60
|
+
/**
|
|
61
|
+
* Smooth the person mask between frames (Stream's temporal smoothing), against flicker at the edges, and write it as
|
|
62
|
+
* bytes for the GPU. `steady` keeps the running mask; a new size starts it over.
|
|
63
|
+
*/
|
|
64
|
+
export declare function smoothMask(confidence: Float32Array, steady: Float32Array | null, out: Uint8Array, follow?: number): Float32Array;
|
|
65
|
+
/** The most frames a mask is reused for before the device is called overloaded. */
|
|
66
|
+
export declare const MAX_SEGMENT_EVERY = 6;
|
|
67
|
+
/**
|
|
68
|
+
* Amazon Chime's adaptive background filter: finding the person is the expensive part, so when it takes too much of
|
|
69
|
+
* each frame's time it runs only every Nth frame and the last mask is reused -- the picture still runs at the camera's
|
|
70
|
+
* rate. N comes back down once it is cheap again. `overloaded` is the point where even that is not enough.
|
|
71
|
+
*/
|
|
72
|
+
export declare class SegmentationPacer {
|
|
73
|
+
private readonly maxEvery;
|
|
74
|
+
private average;
|
|
75
|
+
private changedAt;
|
|
76
|
+
private every;
|
|
77
|
+
constructor(maxEvery?: number);
|
|
78
|
+
/** Run segmentation on every this-many frames. */
|
|
79
|
+
get interval(): number;
|
|
80
|
+
/** Average milliseconds one segmentation takes. */
|
|
81
|
+
get segmentMs(): number;
|
|
82
|
+
shouldSegment(frameIndex: number): boolean;
|
|
83
|
+
/** The share of the frame time segmentation takes now, given how often it runs. */
|
|
84
|
+
load(frameIntervalMs: number): number;
|
|
85
|
+
/** Whether segmenting even this rarely still takes too long. */
|
|
86
|
+
overloaded(frameIntervalMs: number): boolean;
|
|
87
|
+
/** One segmentation took `ms`, at a frame interval of `frameIntervalMs`. */
|
|
88
|
+
report(ms: number, frameIntervalMs: number, now: number): void;
|
|
89
|
+
}
|
|
90
|
+
/** Timestamps MediaPipe's video mode accepts: in milliseconds and always increasing. */
|
|
91
|
+
export declare class MonotonicClock {
|
|
92
|
+
private last;
|
|
93
|
+
next(now: number): number;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=effects-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects-core.d.ts","sourceRoot":"","sources":["../../src/effects-core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qEAAqE;AACrE,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEzH,qEAAqE;AACrE,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAEnF,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,cAAc,CAA6E,CAAC;AAElI,4DAA4D;AAC5D,eAAO,MAAM,YAAY,IAAI,CAAC;AAK9B,+FAA+F;AAC/F,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,GAA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