@webex/web-media-effects-types 2.20.8 → 2.21.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.
Files changed (2) hide show
  1. package/index.d.ts +329 -54
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import TypedEmitter from 'typed-emitter';
2
+ import { IFrameInferenceResult, Generator, Quality, BlurStrength, Pipeline } from '@webex/ladon-ts';
3
+ export { BlurStrength, Generator, Quality } from '@webex/ladon-ts';
2
4
  import * as js_logger from 'js-logger';
3
5
  export { default as Logger } from 'js-logger';
4
- import { Generator, Quality, BlurStrength, Pipeline } from '@webex/ladon-ts';
5
- export { BlurStrength, Generator, Quality } from '@webex/ladon-ts';
6
6
 
7
7
  declare const EventEmitter_base: new <TT>() => TypedEmitter<TT>;
8
8
  declare class EventEmitter<T> extends EventEmitter_base<T> {
@@ -26,6 +26,14 @@ declare enum EffectEnv {
26
26
  Prod = "prod",
27
27
  Int = "int"
28
28
  }
29
+ declare enum EffectState {
30
+ Idle = "idle",
31
+ Init = "init",
32
+ Disabled = "disabled",
33
+ Enabled = "enabled",
34
+ Disposed = "disposed",
35
+ Error = "error"
36
+ }
29
37
  declare enum EffectEvent {
30
38
  TrackUpdated = "track-updated",
31
39
  Enabled = "enabled",
@@ -42,6 +50,7 @@ interface EffectOptions {
42
50
  [key: string]: unknown;
43
51
  }
44
52
  declare abstract class BaseEffect extends EventEmitter<EffectEventCallback> implements TrackEffect {
53
+ protected state: EffectState;
45
54
  protected effectTrack?: MediaStreamTrack;
46
55
  protected outputTrack?: MediaStreamTrack;
47
56
  protected inputStream?: MediaStream;
@@ -150,63 +159,106 @@ declare class NoiseReductionEffect extends BaseMicrophoneEffect {
150
159
  }
151
160
  declare const createNoiseReductionEffect: (options?: NoiseReductionEffectOptions, preloadAssets?: boolean) => Promise<NoiseReductionEffect>;
152
161
 
153
- declare const logger: js_logger.ILogger;
154
- //# sourceMappingURL=logger.d.ts.map
155
-
156
- interface RateEstimatorOptions {
157
- hysteresisMargin: number;
158
- lowDuration: number;
159
- lowThreshold: number;
160
- minSamples: number;
161
- maxSamples: number;
162
+ declare enum BeRightBackAction {
163
+ TurnOn = "turn-on",
164
+ TurnOff = "turn-off"
162
165
  }
163
- declare enum RateEstimatorEvent {
164
- RateOk = "rate-ok",
165
- RateLow = "rate-low",
166
- RateLagging = "rate-lagging"
166
+ declare enum BeRightBackState {
167
+ Idle = "idle",
168
+ Off = "off",
169
+ On = "on"
167
170
  }
168
- interface RateEstimatorEventCallback {
169
- [RateEstimatorEvent.RateLow]: (rate: number) => void;
170
- [RateEstimatorEvent.RateOk]: (rate: number) => void;
171
- [RateEstimatorEvent.RateLagging]: (rate: number) => void;
171
+ interface BeRightBackOptions {
172
+ motionIouThreshold: number;
173
+ onHysteresisMaxMs: number;
174
+ offHysteresisMaxMs: number;
172
175
  }
173
- declare enum RateEstimatorStatus {
174
- Idle = "idle",
175
- Init = "init",
176
- Lagging = "lagging",
177
- Low = "low",
178
- Ok = "ok"
176
+ interface BeRightBackDebugInfo {
177
+ action: BeRightBackAction;
178
+ isMoving: boolean;
179
+ offHysteresisDurationMs: number;
180
+ onHysteresisDurationMs: number;
181
+ numFaces: number;
182
+ state: BeRightBackState;
183
+ timeDiffMs: number;
179
184
  }
180
- interface RateEstimatedValues {
181
- rate?: number;
182
- status: RateEstimatorStatus;
183
- threshold: number;
185
+ declare enum BeRightBackEvent {
186
+ On = "on",
187
+ Off = "off",
188
+ StateChange = "state-change"
184
189
  }
185
- declare class RateEstimator extends EventEmitter<RateEstimatorEventCallback> {
186
- private timestamps;
187
- private targetRate?;
188
- private estimatedRate?;
189
- private lowRateStartTime?;
190
+ interface BeRightBackEventCallback {
191
+ [BeRightBackEvent.StateChange]: (newState: BeRightBackState, oldState: BeRightBackState) => void;
192
+ [BeRightBackEvent.On]: () => void;
193
+ [BeRightBackEvent.Off]: () => void;
194
+ }
195
+ declare enum BeRightBackPluginMode {
196
+ Off = "off",
197
+ Conservative = "conservative",
198
+ Aggressive = "aggressive"
199
+ }
200
+ interface BeRightBackPluginOptions {
201
+ mode: BeRightBackPluginMode;
202
+ debug?: boolean;
203
+ coreOptions?: Partial<BeRightBackOptions>;
204
+ }
205
+
206
+ declare class BeRightBack extends EventEmitter<BeRightBackEventCallback> {
207
+ private debugBuffer;
208
+ private state;
190
209
  private options;
191
- status: RateEstimatorStatus;
192
- constructor(targetRate: number, options?: Partial<RateEstimatorOptions>);
193
- getEstimatedValues(): RateEstimatedValues;
194
- getOptions(): Readonly<RateEstimatorOptions>;
195
- getTimestamps(): Readonly<number[]>;
196
- addTimestamp(timestamp: DOMHighResTimeStamp): void;
197
- private calculateAndUpdateRate;
198
- private evaluateRate;
199
- private isRateLow;
200
- private handleLowRate;
201
- private handleReturnToNormalRate;
202
- reset(): void;
203
- updateOptions(newOptions: Partial<RateEstimatorOptions>): void;
210
+ private onHysteresisDurationMs;
211
+ private offHysteresisDurationMs;
212
+ private lastTimestampMs;
213
+ private isEnabled;
214
+ private isFirstFrame;
215
+ constructor(options?: Partial<BeRightBackOptions>);
216
+ destroy(): void;
217
+ getDebugInfo(): BeRightBackDebugInfo[];
218
+ getLatestDebugInfo(): BeRightBackDebugInfo;
219
+ getState(): BeRightBackState;
220
+ setEnable(enable: boolean): void;
221
+ updateOptions(newOptions: Partial<BeRightBackOptions>): void;
222
+ processFrame(faces: Float32Array, shape: readonly number[], motion: number, timestampMs: number): BeRightBackState;
223
+ private initializeFirstFrameState;
224
+ private determineActionFromInferenceResult;
225
+ private handleHysteresisAndStateChange;
226
+ private accumulateHysteresisAndAttemptTurnOn;
227
+ private accumulateHysteresisAndAttemptTurnOff;
228
+ private changeState;
229
+ private resetHysteresis;
230
+ }
231
+
232
+ interface Plugin {
233
+ isInitialized: boolean;
234
+ initialize(effect: VirtualBackgroundEffect): void;
235
+ dispose(effect: VirtualBackgroundEffect): void;
236
+ }
237
+ type BeforeInferenceResult = {
238
+ shouldInfer: boolean;
239
+ modifiedCanvas?: HTMLCanvasElement;
240
+ };
241
+ type BeforeInferenceCallback = (timestamp: number, lastResult: IFrameInferenceResult, inputCanvas?: HTMLCanvasElement) => Promise<BeforeInferenceResult>;
242
+ type AfterInferenceCallback = (timestamp: number, result?: IFrameInferenceResult) => Promise<void>;
243
+ interface BeforeInferencePlugin extends Plugin {
244
+ onBeforeInference: BeforeInferenceCallback;
245
+ }
246
+ interface AfterInferencePlugin extends Plugin {
247
+ onAfterInference: AfterInferenceCallback;
248
+ }
249
+ type PluginType = BeforeInferencePlugin | AfterInferencePlugin;
250
+ declare class PluginManager {
251
+ private plugins;
252
+ private effect;
253
+ register(name: string, plugin: PluginType): void;
254
+ initialize(effect: VirtualBackgroundEffect): void;
255
+ dispose(): void;
256
+ getPlugin<T extends PluginType>(name: string): T | undefined;
257
+ getPlugins(): Map<string, Plugin>;
204
258
  }
205
259
 
206
260
  declare function debounce<F extends (...args: Parameters<F>) => ReturnType<F>>(func: F, delay: number): (...args: Parameters<F>) => void;
207
261
 
208
- declare const DEFAULT_FRAME_RATE = 24;
209
-
210
262
  declare enum VirtualBackgroundMode {
211
263
  Blur = "BLUR",
212
264
  Image = "IMAGE",
@@ -224,8 +276,12 @@ interface VirtualBackgroundEffectOptions extends EffectOptions {
224
276
  mirror: boolean;
225
277
  env?: EffectEnv;
226
278
  preventBackgroundThrottling?: boolean;
227
- }
228
- declare const defaultOptions: VirtualBackgroundEffectOptions;
279
+ useLocalSegmentationWorker?: boolean;
280
+ canvasResolutionScaling?: number;
281
+ }
282
+
283
+ declare const DEFAULT_FRAME_RATE = 24;
284
+
229
285
  declare class VirtualBackgroundEffect extends BaseCameraEffect {
230
286
  static readonly kind = "virtual-background-effect";
231
287
  static readonly BlurStrength: typeof BlurStrength;
@@ -244,11 +300,16 @@ declare class VirtualBackgroundEffect extends BaseCameraEffect {
244
300
  private preloadFuture?;
245
301
  private loadFuture?;
246
302
  private disposeFuture?;
247
- private onFrameProcessedCallback?;
248
303
  private lastFrameTime;
249
304
  private frameInterval;
250
305
  private restoreEffectOnTrackEnable;
251
306
  private timerId?;
307
+ private lastFrame?;
308
+ private pluginManager;
309
+ private beforeInferenceCallbacks;
310
+ private afterInferenceCallbacks;
311
+ private offscreenCanvas?;
312
+ private inputCanvasContext?;
252
313
  get isReady(): boolean;
253
314
  get isLoaded(): boolean;
254
315
  get frameRate(): number;
@@ -266,6 +327,9 @@ declare class VirtualBackgroundEffect extends BaseCameraEffect {
266
327
  private loadModel;
267
328
  private handleFrame;
268
329
  private manageEffectRestoration;
330
+ private prepareInputCanvas;
331
+ private executeBeforeInferenceCallbacks;
332
+ private executeAfterInferenceCallbacks;
269
333
  private setupDom;
270
334
  private detectQuirks;
271
335
  private handleOrientationChange;
@@ -275,10 +339,221 @@ declare class VirtualBackgroundEffect extends BaseCameraEffect {
275
339
  enable(): Promise<boolean>;
276
340
  disable(): Promise<boolean>;
277
341
  dispose(): Promise<void>;
278
- setOnFrameProcessedCallback(callback: (timestamp: number) => void): void;
342
+ addBeforeInferenceCallback(callback: BeforeInferenceCallback): void;
343
+ addAfterInferenceCallback(callback: AfterInferenceCallback): void;
344
+ removeBeforeInferenceCallback(callback: BeforeInferenceCallback): void;
345
+ removeAfterInferenceCallback(callback: AfterInferenceCallback): void;
346
+ setOnFrameProcessedCallback(callback: AfterInferenceCallback): void;
279
347
  updateOptions(options: Partial<VirtualBackgroundEffectOptions>): Promise<void>;
280
348
  updateSize(width: number, height: number): Promise<void>;
349
+ registerPlugin: (name: string, plugin: PluginType) => void;
350
+ initializePlugins: () => void;
351
+ getPlugin: <T extends PluginType>(name: string) => T | undefined;
352
+ getPluginManager: () => PluginManager;
281
353
  }
282
354
  declare const createVirtualBackgroundEffect: (options?: VirtualBackgroundEffectOptions, preloadAssets?: boolean) => Promise<VirtualBackgroundEffect>;
283
355
 
284
- export { BaseCameraEffect, BaseEffect, BaseMicrophoneEffect, DEFAULT_FRAME_RATE, EffectEnv, EffectEvent, EffectEventCallback, EffectOptions, GainEffect, MediaStreamOrTrack, NoiseReductionEffect, NoiseReductionEffectOptions, NoiseReductionMode, RateEstimatedValues, RateEstimator, RateEstimatorEvent, RateEstimatorEventCallback, RateEstimatorOptions, RateEstimatorStatus, TrackEffect, VirtualBackgroundEffect, VirtualBackgroundEffectOptions, VirtualBackgroundMode, createEffect, createNoiseReductionEffect, createVirtualBackgroundEffect, defaultOptions, logger };
356
+ declare abstract class BaseInferencePlugin<T, O> {
357
+ protected core: T;
358
+ protected options: O;
359
+ protected isEffectEnabled: boolean;
360
+ protected isInitialized: boolean;
361
+ constructor(options?: Partial<O>);
362
+ initialize(effect: VirtualBackgroundEffect): void;
363
+ dispose(): void;
364
+ updateOptions(newOptions: Partial<O>): void;
365
+ protected getDefaultOptions(options?: Partial<O>): O;
366
+ protected createCore(): T;
367
+ protected onCoreCreated(): void;
368
+ protected onEffectEnabled(): void;
369
+ protected onEffectDisabled(): void;
370
+ protected cleanup(): void;
371
+ protected onOptionsUpdated(): void;
372
+ protected abstract destroyCore(): void;
373
+ }
374
+
375
+ declare abstract class BaseEventEmitterPlugin<T extends EventEmitter<unknown>, O> extends BaseInferencePlugin<T, O> {
376
+ on?: T['on'];
377
+ off?: T['off'];
378
+ once?: T['once'];
379
+ constructor(options?: Partial<O>);
380
+ destroyCore(): void;
381
+ }
382
+
383
+ declare abstract class BaseAfterInferencePlugin<T extends EventEmitter<unknown> = EventEmitter<unknown>, O extends object = Record<string, never>> extends BaseEventEmitterPlugin<T, O> {
384
+ constructor(options?: Partial<O>);
385
+ initialize(effect: VirtualBackgroundEffect): void;
386
+ dispose(): void;
387
+ abstract onAfterInference(timestamp: number, result?: IFrameInferenceResult): Promise<void>;
388
+ }
389
+
390
+ declare class BeRightBackPlugin extends BaseAfterInferencePlugin<BeRightBack, BeRightBackPluginOptions> {
391
+ protected getDefaultOptions(): BeRightBackPluginOptions;
392
+ protected createCore(): BeRightBack;
393
+ onAfterInference(timestamp: number, result?: IFrameInferenceResult): Promise<void>;
394
+ onOptionsUpdated(): void;
395
+ getDebugInfo(): BeRightBackDebugInfo[];
396
+ getLatestDebugInfo(): BeRightBackDebugInfo;
397
+ }
398
+
399
+ declare function getOptionsByMode(mode: BeRightBackPluginMode): BeRightBackOptions;
400
+ declare function makeBeRightBackOptions(mode: BeRightBackPluginMode, coreOptions?: Partial<BeRightBackOptions>): BeRightBackOptions;
401
+
402
+ interface FrameSkipperOptions {
403
+ baseMinSkipTime: number;
404
+ baseMaxSkipTime: number;
405
+ historySize: number;
406
+ skipTimeIncrement: number;
407
+ forcedInferenceInterval: number;
408
+ highMotionThreshold: number;
409
+ smoothingFactor: number;
410
+ }
411
+ declare enum FrameSkipperInferenceReason {
412
+ Initial = "initial",
413
+ HighMotion = "high-motion",
414
+ TimeForced = "time-forced",
415
+ SkipIntervalElapsed = "skip-interval-elapsed"
416
+ }
417
+ interface FrameSkipperDebugInfo {
418
+ averageMotion: number;
419
+ currentTime: number;
420
+ currentSkipTime: number;
421
+ isHighMotion: boolean;
422
+ isSkipIntervalElapsed: boolean;
423
+ isTimeForced: boolean;
424
+ lastInferenceReason: FrameSkipperInferenceReason;
425
+ lastInferenceTime: number;
426
+ motionValue: number;
427
+ shouldInfer: boolean;
428
+ smoothedMotion: number;
429
+ timeSinceLastInference: number;
430
+ }
431
+ declare enum FrameSkipperPluginMode {
432
+ Off = "off",
433
+ Conservative = "conservative",
434
+ Aggressive = "aggressive"
435
+ }
436
+ interface FrameSkipperPluginOptions {
437
+ mode: FrameSkipperPluginMode;
438
+ debug?: boolean;
439
+ coreOptions?: Partial<FrameSkipperOptions>;
440
+ }
441
+
442
+ declare class AdaptiveFrameSkipper extends EventEmitter<unknown> {
443
+ private options;
444
+ private debugBuffer;
445
+ private motionData;
446
+ private lastInferenceTime;
447
+ private currentSkipTime;
448
+ private lastSmoothedMotion;
449
+ constructor(options?: FrameSkipperOptions);
450
+ destroy(): void;
451
+ getDebugInfo(): FrameSkipperDebugInfo[];
452
+ getLatestDebugInfo(): FrameSkipperDebugInfo;
453
+ shouldPerformInference(motionValue: number, motionTimestamp: number): boolean;
454
+ updateOptions(newOptions: FrameSkipperOptions): void;
455
+ private updateMotionData;
456
+ private adjustSkipTime;
457
+ private calculateSmoothedMotion;
458
+ private calculateAverageMotion;
459
+ }
460
+
461
+ declare abstract class BaseBeforeInferencePlugin<T extends EventEmitter<unknown> = EventEmitter<unknown>, O extends object = Record<string, never>> extends BaseEventEmitterPlugin<T, O> {
462
+ constructor(options: O);
463
+ initialize(effect: VirtualBackgroundEffect): void;
464
+ abstract onBeforeInference(timestamp: number, lastResult: IFrameInferenceResult, inputCanvas?: HTMLCanvasElement): Promise<BeforeInferenceResult>;
465
+ }
466
+
467
+ declare class FrameSkipperPlugin extends BaseBeforeInferencePlugin<AdaptiveFrameSkipper, FrameSkipperPluginOptions> {
468
+ protected getDefaultOptions(): FrameSkipperPluginOptions;
469
+ protected createCore(): AdaptiveFrameSkipper;
470
+ destroyCore(): void;
471
+ onBeforeInference(timestamp: number, lastResult: IFrameInferenceResult): Promise<BeforeInferenceResult>;
472
+ onOptionsUpdated(): void;
473
+ getDebugInfo(): FrameSkipperDebugInfo[];
474
+ getLatestDebugInfo(): FrameSkipperDebugInfo;
475
+ }
476
+
477
+ declare function makeFrameSkipperOptions(mode: FrameSkipperPluginMode, coreOptions?: Partial<FrameSkipperOptions>): FrameSkipperOptions;
478
+
479
+ declare enum RateEstimatorStatus {
480
+ Idle = "idle",
481
+ Init = "init",
482
+ Lagging = "lagging",
483
+ Low = "low",
484
+ Ok = "ok"
485
+ }
486
+ interface RateEstimatedValues {
487
+ rate?: number;
488
+ status: RateEstimatorStatus;
489
+ threshold: number;
490
+ }
491
+ interface RateEstimatorOptions {
492
+ hysteresisMargin: number;
493
+ lowDuration: number;
494
+ lowThreshold: number;
495
+ minSamples: number;
496
+ maxSamples: number;
497
+ }
498
+ declare enum RateEstimatorEvent {
499
+ RateOk = "rate-ok",
500
+ RateLow = "rate-low",
501
+ RateLagging = "rate-lagging"
502
+ }
503
+ interface RateEstimatorEventCallback {
504
+ [RateEstimatorEvent.RateLow]: (rate: number) => void;
505
+ [RateEstimatorEvent.RateOk]: (rate: number) => void;
506
+ [RateEstimatorEvent.RateLagging]: (rate: number) => void;
507
+ }
508
+ interface RateEstimationPluginOptions {
509
+ targetRate: number;
510
+ debug?: boolean;
511
+ coreOptions?: Partial<RateEstimatorOptions>;
512
+ }
513
+
514
+ declare class RateEstimator extends EventEmitter<RateEstimatorEventCallback> {
515
+ private timestamps;
516
+ private estimatedRate?;
517
+ private lowRateStartTime?;
518
+ private options;
519
+ status: RateEstimatorStatus;
520
+ constructor(targetRate: number, options?: Partial<RateEstimatorOptions>);
521
+ dispose(): void;
522
+ getEstimatedValues(): RateEstimatedValues;
523
+ getOptions(): Readonly<RateEstimatorOptions>;
524
+ getTimestamps(): Readonly<number[]>;
525
+ addTimestamp(timestamp: DOMHighResTimeStamp): void;
526
+ private calculateAndUpdateRate;
527
+ private evaluateRate;
528
+ private isRateLow;
529
+ private handleLowRate;
530
+ private handleReturnToNormalRate;
531
+ reset(): void;
532
+ updateOptions(newOptions: Partial<RateEstimatorOptions>): void;
533
+ }
534
+
535
+ declare class RateEstimationPlugin extends BaseAfterInferencePlugin<RateEstimator, RateEstimationPluginOptions> {
536
+ protected createCore(): RateEstimator;
537
+ onCoreCreated(): void;
538
+ onEffectDisabled(): void;
539
+ onEffectEnabled(): void;
540
+ destroyCore(): void;
541
+ onAfterInference(timestamp: number): Promise<void>;
542
+ getRate(): number | undefined;
543
+ getThreshold(): number | undefined;
544
+ getStatus(): RateEstimatorStatus | undefined;
545
+ }
546
+
547
+ declare class SkippedFrameRatePlugin extends BaseAfterInferencePlugin {
548
+ private frameHistory;
549
+ private readonly frameWindowSize;
550
+ onAfterInference(timestamp: number, result?: IFrameInferenceResult): Promise<void>;
551
+ getSkippedPercentage(): number;
552
+ getSkippedFrameCount(): number;
553
+ getTotalFrameCount(): number;
554
+ }
555
+
556
+ declare const logger: js_logger.ILogger;
557
+ //# sourceMappingURL=logger.d.ts.map
558
+
559
+ export { AdaptiveFrameSkipper, BaseCameraEffect, BaseEffect, BaseMicrophoneEffect, BeRightBack, BeRightBackAction, BeRightBackDebugInfo, BeRightBackEvent, BeRightBackEventCallback, BeRightBackOptions, BeRightBackPlugin, BeRightBackPluginMode, BeRightBackPluginOptions, BeRightBackState, DEFAULT_FRAME_RATE, EffectEnv, EffectEvent, EffectEventCallback, EffectOptions, EffectState, FrameSkipperDebugInfo, FrameSkipperInferenceReason, FrameSkipperOptions, FrameSkipperPlugin, FrameSkipperPluginMode, FrameSkipperPluginOptions, GainEffect, MediaStreamOrTrack, NoiseReductionEffect, NoiseReductionEffectOptions, NoiseReductionMode, RateEstimatedValues, RateEstimationPlugin, RateEstimationPluginOptions, RateEstimator, RateEstimatorEvent, RateEstimatorEventCallback, RateEstimatorOptions, RateEstimatorStatus, SkippedFrameRatePlugin, TrackEffect, VirtualBackgroundEffect, createEffect, createNoiseReductionEffect, createVirtualBackgroundEffect, getOptionsByMode, logger, makeBeRightBackOptions, makeFrameSkipperOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/web-media-effects-types",
3
- "version": "2.20.8",
3
+ "version": "2.21.0",
4
4
  "description": "TypeScript definitions for @webex/web-media-effects",
5
5
  "main": "",
6
6
  "types": "index.d.ts",