@vonage/ml-transformers 4.3.0 → 4.3.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.
@@ -1,6 +1,8 @@
1
1
  import { EventDataMap, MediaProcessorConnector } from "@vonage/media-processor";
2
2
  import Emittery from "emittery";
3
3
  import { BackgroundOptions, MediaProcessorConfig } from "../../main";
4
+ import { ResolvedWebglQuery } from "../webgl/webgl-profiler";
5
+ import { WebglProfilerReporter } from "../webgl/webgl-profiler-reporter";
4
6
  /**
5
7
  * Class wrapping features provided by ml-transformers.
6
8
  */
@@ -50,6 +52,9 @@ export declare class VonageMediaProcessor extends Emittery<EventDataMap> {
50
52
  * @returns - `MediaProcessorConnectorInterface` feed this return value to any vonage SDK that supports this API
51
53
  */
52
54
  getConnector(): MediaProcessorConnector;
55
+ profile(duration: number): Promise<ResolvedWebglQuery[]>;
56
+ static profile(duration: number): Promise<WebglProfilerReporter>;
57
+ private static instances;
53
58
  /**
54
59
  * Asynchronous constructor of VonageMediaProcessor
55
60
  * @param config Initial MediaProcessorConfig to use
@@ -1,4 +1,5 @@
1
1
  import { BackgroundOptions } from "../../main";
2
+ import { ResolvedWebglQuery } from "../webgl/webgl-profiler";
2
3
  import { FlickeringOptions } from "../webgl/pipelines/improve-segmentation-mask";
3
4
  export interface BackgroundFilterConfig {
4
5
  maskWidth: number;
@@ -7,21 +8,24 @@ export interface BackgroundFilterConfig {
7
8
  foregroundHeight: number;
8
9
  }
9
10
  export declare class BackgroundFilter {
11
+ private id;
10
12
  private improveMaskSegmentation;
11
13
  private backgroundResizer;
12
14
  private backgroundImage;
13
15
  private backgroundVideo;
16
+ private profiler?;
14
17
  private activePipeline?;
15
18
  canvas: OffscreenCanvas;
16
19
  private options?;
17
- readonly context: WebGLRenderingContext;
20
+ readonly context: WebGL2RenderingContext;
18
21
  private virtualBGImage?;
19
- constructor(config: BackgroundFilterConfig);
22
+ constructor(id: string, config: BackgroundFilterConfig);
20
23
  setBackgroundOptions(options: BackgroundOptions): void;
21
24
  setFlickeringOptions(options: FlickeringOptions): void;
22
25
  setVideoBGReadable(videoBGReadable: ReadableStream): void;
23
26
  setVirtualBGImage(image: ImageBitmap): Promise<void>;
24
27
  process(foreground: ImageBitmap, mask?: ImageBitmap): Promise<void>;
25
28
  resizeForeground(width: number, height: number): Promise<void>;
29
+ profile(duration: number): Promise<ResolvedWebglQuery[]>;
26
30
  private getBlurSize;
27
31
  }
@@ -2,6 +2,7 @@ import { EventDataMap, MediaProcessorInterface } from "@vonage/media-processor";
2
2
  import Emittery from "emittery";
3
3
  import { BackgroundOptions, MediaProcessorConfig } from "../../main";
4
4
  import { FlickeringOptions } from "../webgl/pipelines/improve-segmentation-mask";
5
+ import { ResolvedWebglQuery } from "../webgl/webgl-profiler";
5
6
  export declare enum WorkerOperations {
6
7
  init = "init",
7
8
  transform = "transform",
@@ -22,11 +23,13 @@ export interface InnerEventDataMap {
22
23
  export declare class ProcessorMain extends Emittery<EventDataMap> implements MediaProcessorInterface {
23
24
  private rate;
24
25
  private worker?;
26
+ private static initCount;
25
27
  init(config: MediaProcessorConfig): Promise<void>;
26
28
  setTrackExpectedRate(rate: number): Promise<void>;
27
29
  setBackgroundOptions(options: BackgroundOptions): Promise<void>;
28
30
  transform(readable: ReadableStream<any>, writable: WritableStream<any>): Promise<void>;
29
31
  destroy(): Promise<void>;
30
32
  setFlickeringOptions(options: FlickeringOptions): Promise<void>;
33
+ profile(duration: number): Promise<ResolvedWebglQuery[]>;
31
34
  private listenWorker;
32
35
  }
@@ -11,7 +11,7 @@ export declare class ProcessorWorker {
11
11
  private rate;
12
12
  private resolveOnMediaProcessor?;
13
13
  private eventsQueue;
14
- init(config: MediaProcessorConfig): Promise<void>;
14
+ init(id: string, config: MediaProcessorConfig): Promise<void>;
15
15
  onMediaProcessorEvent(): Promise<MediaProcessorEvent>;
16
16
  setTrackExpectedRate(rate: number): Promise<void>;
17
17
  transform(readable: ReadableStream<any>, writable: WritableStream<any>): Promise<void>;
@@ -21,4 +21,5 @@ export declare class ProcessorWorker {
21
21
  terminate(): Promise<void>;
22
22
  setFlickeringOptions(options: FlickeringOptions): void;
23
23
  setVonageMetadata(metadata: VonageMetadata): void;
24
+ profile(duration: number): Promise<string>;
24
25
  }
@@ -1,14 +1,16 @@
1
1
  /// <reference types="dom-webcodecs" />
2
2
  import { BackgroundOptions, MediaProcessorConfig } from "../../main";
3
3
  import { FlickeringOptions } from "../webgl/pipelines/improve-segmentation-mask";
4
+ import { ResolvedWebglQuery } from "../webgl/webgl-profiler";
4
5
  export declare class BackgroundTransformer {
5
6
  private selfieSegmentation;
6
7
  private backgroundFilter?;
7
- init(config: MediaProcessorConfig): Promise<void>;
8
+ init(id: string, config: MediaProcessorConfig): Promise<void>;
8
9
  private previousDimensions;
9
10
  transform?(frame: VideoFrame, controller: TransformStreamDefaultController): Promise<void>;
10
11
  setBackgroundOptions(options: BackgroundOptions): Promise<void>;
11
12
  setVideoBGReadable(stream: ReadableStream): Promise<void>;
12
13
  setVirtualBGImage(image: ImageBitmap): Promise<void>;
13
14
  setFlickeringOptions(options: FlickeringOptions): void;
15
+ profile(duration: number): Promise<ResolvedWebglQuery[]>;
14
16
  }
@@ -0,0 +1 @@
1
+ export declare function wait(ms: number): Promise<void>;
@@ -15,7 +15,7 @@ export declare function frameToCanvas(frame: VideoFrame, context: OffscreenCanva
15
15
  * @param source Source used to fill the texture
16
16
  * @returns Created texture, or source if it's a WebGLTexture
17
17
  */
18
- export declare function texture(context: WebGLRenderingContext, source?: TextureSource | WebGLTexture): WebGLTexture;
18
+ export declare function texture(context: WebGLRenderingContext, source?: TextureSource | WebGLTexture): () => WebGLTexture;
19
19
  /**
20
20
  * Create a webgl texture and fill it with a color
21
21
  * @param context Webgl context to create the texture on
@@ -24,4 +24,8 @@ export declare function texture(context: WebGLRenderingContext, source?: Texture
24
24
  * @param color Color to fill the texture with
25
25
  * @returns Created texture
26
26
  */
27
- export declare function textureWithColor(context: WebGLRenderingContext, width: number, height: number, color: vec4): WebGLTexture;
27
+ export declare function textureWithColor(context: WebGLRenderingContext, width: number, height: number, color: vec4): () => WebGLTexture;
28
+ /**
29
+ * Minimum size for a webgl texture
30
+ */
31
+ export declare const WEBGL_MINIMUM_TEXTURE_SIZE: number;
@@ -4,6 +4,8 @@ export declare class BackgroundBlur extends WebglTransformerPipeline {
4
4
  private readonly context;
5
5
  inputImage?: ImageBitmap | TextureSource | WebGLTexture;
6
6
  inputMask?: ImageBitmap | TextureSource | WebGLTexture;
7
+ private blur;
7
8
  constructor(context: WebGLRenderingContext, radius: number);
8
9
  setData(image?: ImageBitmap | TextureSource | WebGLTexture, mask?: ImageBitmap | TextureSource | WebGLTexture): void;
10
+ resizeOutput(width: number, height: number): void;
9
11
  }
@@ -1,5 +1,8 @@
1
1
  import { TextureSource } from "../../types";
2
2
  import { WebglPipeline } from "../webgl-pipeline";
3
+ /**
4
+ * @internal
5
+ */
3
6
  export interface FlickeringOptions {
4
7
  currentThresholdMinimum: number;
5
8
  currentThresholdMaximum: number;
@@ -1,6 +1,7 @@
1
1
  import * as twgl from "twgl.js";
2
2
  import { FramebufferInfo } from "twgl.js";
3
3
  import { UniformDataMap } from "../types";
4
+ import { WebglProfiler } from "./webgl-profiler";
4
5
  export interface WebglPipelineProgramOptions {
5
6
  context: WebGLRenderingContext;
6
7
  width: number;
@@ -15,6 +16,7 @@ export interface WebglPipelineProgramOptions {
15
16
  * - vec2 canvas: canvas dimension, in px
16
17
  */
17
18
  export declare abstract class WebglPipelineProgram<O extends WebglPipelineProgramOptions = WebglPipelineProgramOptions> {
19
+ id: string;
18
20
  /**
19
21
  * Webgl context used by the program
20
22
  */
@@ -39,6 +41,7 @@ export declare abstract class WebglPipelineProgram<O extends WebglPipelineProgra
39
41
  * Buffers infos used by the program
40
42
  */
41
43
  private bufferInfo;
44
+ private profiler?;
42
45
  constructor(options: O);
43
46
  resizeOutput(width: number, height: number): void;
44
47
  /**
@@ -79,4 +82,5 @@ export declare abstract class WebglPipelineProgram<O extends WebglPipelineProgra
79
82
  * @param uniforms Data to used for the uniforms
80
83
  */
81
84
  run(uniforms: UniformDataMap): void;
85
+ setProfiler(profiler?: WebglProfiler): void;
82
86
  }
@@ -1,4 +1,5 @@
1
1
  import { UniformDataMap } from "../types";
2
+ import { WebglProfiler } from "./webgl-profiler";
2
3
  import { WebglPipelineProgram } from "./webgl-pipeline-program";
3
4
  /**
4
5
  * Program pipeline run infos
@@ -13,6 +14,10 @@ export interface WebglPipelineStep {
13
14
  * @returns Object containing for each uniform a pair key/value name/value
14
15
  */
15
16
  getUniforms: () => UniformDataMap;
17
+ /**
18
+ * If set to true, the step won't be rescale if the output is resized
19
+ */
20
+ preventResize?: boolean;
16
21
  }
17
22
  /**
18
23
  * Webgl pipeline. Run pipeline program one after one
@@ -32,4 +37,7 @@ export declare class WebglPipeline {
32
37
  */
33
38
  run(): Promise<void>;
34
39
  resizeOutput(width: number, height: number): void;
40
+ private profiler?;
41
+ setProfiler(profiler?: WebglProfiler): void;
42
+ setId(id: string): void;
35
43
  }
@@ -0,0 +1,11 @@
1
+ import { ResolvedWebglQuery } from "./webgl-profiler";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class WebglProfilerReporter {
6
+ private queries;
7
+ constructor(queries: ResolvedWebglQuery[][]);
8
+ downloadSpeedscope(): Promise<void>;
9
+ private download;
10
+ private convertToSpeedscope;
11
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare enum WebglQueryAction {
5
+ PUSH = "PUSH",
6
+ POP = "POP"
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export interface WebglQuery {
12
+ name: string;
13
+ action: WebglQueryAction;
14
+ query: WebGLQuery;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ export interface ResolvedWebglQuery extends WebglQuery {
20
+ duration: number;
21
+ timestamp: number;
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ export declare class WebglProfiler {
27
+ private context;
28
+ private extension;
29
+ private queries;
30
+ private activeQuery?;
31
+ constructor(context: WebGL2RenderingContext);
32
+ start(): void;
33
+ stop(): void;
34
+ pushContext(name: string): void;
35
+ popContext(name: string): void;
36
+ private createQuery;
37
+ getResolvedQueries(): Promise<ResolvedWebglQuery[]>;
38
+ private resolveQuery;
39
+ private awaitQueryAvailable;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonage/ml-transformers",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "author": "Guy Mininberg <guy.mininberg@vonage.com>",
5
5
  "contributors": [
6
6
  "Guy Mininberg <guy.mininberg@vonage.com>",
@@ -26,7 +26,7 @@
26
26
  "build": "npm-run-all build:js build:static doc",
27
27
  "build:js": "tsc && vite build && tsc --declaration --emitDeclarationOnly --outDir dist/types",
28
28
  "build:static": "node ./scripts/build-static.js && minify ./dist/ml-transformers.static.js > ./dist/ml-transformers.min.js ",
29
- "doc": "typedoc --excludePrivate --excludeProtected --disableSources --out dist/docs lib/main.ts",
29
+ "doc": "typedoc --excludePrivate --excludeInternal --excludeProtected --disableSources --out dist/docs lib/main.ts",
30
30
  "dev": "vite",
31
31
  "preview": "vite preview",
32
32
  "e2e:app": "vite ./tests/e2e/apps/vite",