@pexip/media-processor 22.0.0 → 22.2.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 (108) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/api-docs/README.mdx +4 -1
  3. package/api-docs/functions/avg.mdx +1 -1
  4. package/api-docs/functions/createAnalyzerGraphNode.mdx +3 -1
  5. package/api-docs/functions/createAnalyzerSubscribableGraphNode.mdx +3 -1
  6. package/api-docs/functions/createAsyncCallbackLoop.mdx +6 -6
  7. package/api-docs/functions/createAudioDestinationGraphNode.mdx +1 -1
  8. package/api-docs/functions/createAudioSignalDetector.mdx +4 -4
  9. package/api-docs/functions/createAudioStats.mdx +1 -1
  10. package/api-docs/functions/createBenchmark.mdx +7 -6
  11. package/api-docs/functions/createChannelMergerGraphNode.mdx +1 -1
  12. package/api-docs/functions/createChannelSplitterGraphNode.mdx +1 -1
  13. package/api-docs/functions/createDelayGraphNode.mdx +1 -1
  14. package/api-docs/functions/createDenoiseWorkletGraphNode.mdx +2 -2
  15. package/api-docs/functions/createFrameCallbackRequest.mdx +3 -3
  16. package/api-docs/functions/createGainGraphNode.mdx +3 -1
  17. package/api-docs/functions/createMediaElementSourceGraphNode.mdx +1 -1
  18. package/api-docs/functions/createReadWritableStreamFallbackInputProcessAdaptor.mdx +1 -1
  19. package/api-docs/functions/createSegmenter.mdx +1 -1
  20. package/api-docs/functions/createStreamDestinationGraphNode.mdx +1 -1
  21. package/api-docs/functions/createStreamSourceGraphNode.mdx +1 -1
  22. package/api-docs/functions/createVADetector.mdx +3 -3
  23. package/api-docs/functions/createVoiceDetectorFromProbability.mdx +1 -1
  24. package/api-docs/functions/createVoiceDetectorFromTimeData.mdx +3 -1
  25. package/api-docs/functions/createWindowedStats.mdx +2 -2
  26. package/api-docs/functions/getBezierCurveControlPoints.mdx +3 -1
  27. package/api-docs/functions/labelComponents.mdx +3 -1
  28. package/api-docs/functions/loadScript.mdx +1 -1
  29. package/api-docs/functions/loadWasms.mdx +1 -1
  30. package/api-docs/functions/nearestPowerOfTwo.mdx +1 -1
  31. package/api-docs/functions/playVideo.mdx +6 -4
  32. package/api-docs/functions/processAverageVolume.mdx +1 -1
  33. package/api-docs/functions/rms.mdx +1 -1
  34. package/api-docs/functions/subscribeWorkletNode.mdx +1 -1
  35. package/api-docs/functions/sum.mdx +1 -1
  36. package/api-docs/interfaces/AnalyzerSubscribableOptions.mdx +5 -3
  37. package/api-docs/interfaces/AudioGraph.mdx +2 -2
  38. package/api-docs/interfaces/AudioNodeInit.mdx +10 -6
  39. package/api-docs/interfaces/AudioNodeProps.mdx +3 -3
  40. package/api-docs/interfaces/Benchmark.mdx +3 -3
  41. package/api-docs/interfaces/Clock.mdx +1 -1
  42. package/api-docs/interfaces/Denoise.mdx +2 -2
  43. package/api-docs/interfaces/InputProcessAdaptor.mdx +6 -2
  44. package/api-docs/interfaces/MPMask.mdx +1 -1
  45. package/api-docs/interfaces/Process.mdx +5 -5
  46. package/api-docs/interfaces/ProcessWorkerDebugMessage.mdx +1 -1
  47. package/api-docs/interfaces/ProcessWorkerEventClosed.mdx +5 -0
  48. package/api-docs/interfaces/ProcessorEvent.mdx +2 -1
  49. package/api-docs/interfaces/ProcessorProcessOptions.mdx +2 -2
  50. package/api-docs/interfaces/ProcessorUpdateOptions.mdx +3 -1
  51. package/api-docs/interfaces/ReadWritableStream.mdx +2 -2
  52. package/api-docs/interfaces/RenderEventHandlers.mdx +3 -3
  53. package/api-docs/interfaces/Renderer.mdx +3 -1
  54. package/api-docs/interfaces/RendererOptions.mdx +5 -5
  55. package/api-docs/interfaces/Runner.mdx +3 -3
  56. package/api-docs/interfaces/Segmentation.mdx +1 -1
  57. package/api-docs/interfaces/Segmenter.mdx +39 -19
  58. package/api-docs/interfaces/VideoFrameLike.mdx +1 -1
  59. package/api-docs/interfaces/VideoProcessor.mdx +7 -7
  60. package/api-docs/interfaces/WorkletMessagePortOptions.mdx +2 -2
  61. package/api-docs/type-aliases/AsyncCallback.mdx +1 -1
  62. package/api-docs/type-aliases/Callback.mdx +2 -2
  63. package/api-docs/type-aliases/ExtractMessageEventType.mdx +1 -1
  64. package/api-docs/type-aliases/IncludeMessageEventDataType.mdx +1 -1
  65. package/api-docs/type-aliases/Logger.mdx +12 -0
  66. package/api-docs/type-aliases/OptionalKeys.mdx +1 -1
  67. package/api-docs/type-aliases/ProcessWorkerEvents.mdx +1 -0
  68. package/api-docs/type-aliases/RunnerCreator.mdx +3 -3
  69. package/api-docs/type-aliases/TupleOf.mdx +1 -1
  70. package/api-docs/variables/RENDER_BACKEND.mdx +1 -0
  71. package/api-docs/variables/cloneImageRecord.mdx +3 -1
  72. package/api-docs/variables/createLazyProps.mdx +1 -1
  73. package/api-docs/variables/createObjectUpdater.mdx +2 -2
  74. package/api-docs/variables/createRemoteImageBitmap.mdx +5 -5
  75. package/api-docs/variables/getCanUseWebGL.mdx +7 -0
  76. package/api-docs/variables/handleWebGLContextLoss.mdx +1 -1
  77. package/api-docs/variables/urls.mdx +2 -2
  78. package/dist/common/backends/canvas2d/renderer.d.ts +2 -0
  79. package/dist/common/backends/canvas2d/renderer.js +36 -0
  80. package/dist/common/backends/webgl/blur.d.ts +1 -1
  81. package/dist/common/backends/webgl/blur.js +11 -25
  82. package/dist/common/backends/webgl/renderer.js +4 -4
  83. package/dist/common/backends/webgpu/dualFilterBlur.js +93 -114
  84. package/dist/common/canvasRenderUtils.d.ts +23 -4
  85. package/dist/common/canvasRenderUtils.js +48 -11
  86. package/dist/common/constants.d.ts +1 -0
  87. package/dist/common/constants.js +1 -0
  88. package/dist/common/inferencer.d.ts +18 -0
  89. package/dist/common/inferencer.js +60 -0
  90. package/dist/common/tsconfig.tsbuildinfo +1 -1
  91. package/dist/common/types/messageEvents.d.ts +4 -1
  92. package/dist/common/types/processor.d.ts +1 -0
  93. package/dist/common/utils.d.ts +1 -0
  94. package/dist/common/utils.js +13 -0
  95. package/dist/main/audio.js +20 -2
  96. package/dist/main/benchUtils.d.ts +28 -18
  97. package/dist/main/benchUtils.js +66 -56
  98. package/dist/main/tsconfig.tsbuildinfo +1 -1
  99. package/dist/main/utils.d.ts +9 -0
  100. package/dist/main/utils.js +12 -0
  101. package/dist/main/video/segmenter.d.ts +8 -1
  102. package/dist/main/video/segmenter.js +44 -29
  103. package/dist/main/video/types.d.ts +1 -1
  104. package/dist/main/video/video.d.ts +1 -1
  105. package/dist/main/video/video.js +25 -12
  106. package/dist/workers/mediaWorker.js +23 -23
  107. package/dist/workers/tsconfig.tsbuildinfo +1 -1
  108. package/package.json +6 -9
@@ -4,7 +4,7 @@ Wrapper for a mask produced by a Segmentation Task.
4
4
 
5
5
  | Property | Modifier | Type | Description |
6
6
  | ------ | ------ | ------ | ------ |
7
- | <a id="canvas"></a> `canvas` | `readonly` | `OffscreenCanvas` \| `undefined` | Returns the canvas element that the mask is bound to. |
7
+ | <a id="canvas"></a> `canvas` | `readonly` | `OffscreenCanvas \| undefined` | Returns the canvas element that the mask is bound to. |
8
8
  | <a id="width"></a> `width` | `readonly` | `number` | Returns the width of the mask. |
9
9
  | <a id="height"></a> `height` | `readonly` | `number` | Returns the height of the mask. |
10
10
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  | Property | Type |
14
14
  | ------ | ------ |
15
- | <a id="status"></a> `status` | \| `"closed"` \| `"closing"` \| `"Error"` \| `"destroyed"` \| `"destroying"` \| `"idle"` \| `"new"` \| `"opened"` \| `"opening"` \| `"processing"` \| `"updated"` \| `"updating"` |
15
+ | <a id="status"></a> `status` | `\| "closed" \| "closing" \| "Error" \| "destroyed" \| "destroying" \| "idle" \| "new" \| "opened" \| "opening" \| "processing" \| "updated" \| "updating"` |
16
16
 
17
17
  ## Methods
18
18
 
@@ -24,19 +24,19 @@ open(): Promise<T>;
24
24
 
25
25
  #### Returns
26
26
 
27
- `Promise`\<`T`\>
27
+ `Promise<T>`
28
28
 
29
29
  ***
30
30
 
31
31
  ### close()
32
32
 
33
33
  ```ts
34
- close(): void;
34
+ close(): Promise<void>;
35
35
  ```
36
36
 
37
37
  #### Returns
38
38
 
39
- `void`
39
+ `Promise<void>`
40
40
 
41
41
  ***
42
42
 
@@ -48,4 +48,4 @@ destroy(): Promise<void>;
48
48
 
49
49
  #### Returns
50
50
 
51
- `Promise`\<`void`\>
51
+ `Promise<void>`
@@ -2,5 +2,5 @@
2
2
 
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
- | <a id="context"></a> `context?` | `Record`\<`string`, `unknown`\> |
5
+ | <a id="context"></a> `context?` | `Record<string, unknown>` |
6
6
  | <a id="message"></a> `message` | `string` |
@@ -0,0 +1,5 @@
1
+ ## Properties
2
+
3
+ | Property | Type |
4
+ | ------ | ------ |
5
+ | <a id="type"></a> `type` | `"closed"` |
@@ -2,6 +2,7 @@
2
2
 
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
- | <a id="type"></a> `type` | \| `"Error"` \| `"ContextCreationError"` \| `"ContextLost"` \| `"ContextRestored"` \| `"ProcessorRestarted"` \| `"SamplingError"` |
5
+ | <a id="type"></a> `type` | `\| "Error" \| "ContextCreationError" \| "ContextLost" \| "ContextRestored" \| "ProcessorRestarted" \| "SamplingError"` |
6
+ | <a id="error"></a> `error?` | `Error` |
6
7
  | <a id="message"></a> `message?` | `string` |
7
8
  | <a id="track"></a> `track?` | `MediaStreamTrack` |
@@ -3,6 +3,6 @@
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
5
  | <a id="track"></a> `track?` | `MediaStreamTrack` |
6
- | <a id="readable"></a> `readable?` | `ReadableStream`\<`VideoFrame`\> |
7
- | <a id="writable"></a> `writable?` | `WritableStream`\<`VideoFrame`\> |
6
+ | <a id="readable"></a> `readable?` | `ReadableStream<VideoFrame>` |
7
+ | <a id="writable"></a> `writable?` | `WritableStream<VideoFrame>` |
8
8
  | <a id="renderoptions"></a> `renderOptions?` | [`RendererOptions`](RendererOptions.mdx) |
@@ -1,6 +1,8 @@
1
1
  ## Extends
2
2
 
3
- - `Omit`\<[`ProcessorOptions`](ProcessorOptions.mdx), `"renderOptions"`\>
3
+ ```ts
4
+ - Omit<ProcessorOptions, "renderOptions">
5
+ ```
4
6
 
5
7
  ## Properties
6
8
 
@@ -8,5 +8,5 @@
8
8
 
9
9
  | Property | Type |
10
10
  | ------ | ------ |
11
- | <a id="readable"></a> `readable` | `ReadableStream`\<`T`\> |
12
- | <a id="writable"></a> `writable` | `WritableStream`\<`T`\> |
11
+ | <a id="readable"></a> `readable` | `ReadableStream<T>` |
12
+ | <a id="writable"></a> `writable` | `WritableStream<T>` |
@@ -2,6 +2,6 @@
2
2
 
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
- | <a id="contextlost"></a> `contextLost` | (`message`) => `void` |
6
- | <a id="contextrestored"></a> `contextRestored` | (`message`) => `void` |
7
- | <a id="contextcreationerror"></a> `contextCreationError` | (`message`) => `void` |
5
+ | <a id="contextlost"></a> `contextLost` | `(message) => void` |
6
+ | <a id="contextrestored"></a> `contextRestored` | `(message) => void` |
7
+ | <a id="contextcreationerror"></a> `contextCreationError` | `(message) => void` |
@@ -14,7 +14,9 @@ init(options?): void | Promise<void>;
14
14
 
15
15
  #### Returns
16
16
 
17
- `void` \| `Promise`\<`void`\>
17
+ ```ts
18
+ void | Promise<void>
19
+ ```
18
20
 
19
21
  ***
20
22
 
@@ -8,16 +8,16 @@ All values are stable per-frame and can be safely updated in real-time.
8
8
  | <a id="backgroundimageurl"></a> `backgroundImageUrl` | `string` | URL or Data URI for the virtual background image (used in "overlay" effect). |
9
9
  | <a id="backgroundbluramount"></a> `backgroundBlurAmount` | `number` | Amount of background blur (radius in px): [0,9]. Recommend: 3–6 for portraits. Higher may be slow and over-blurred. **Default** `3` |
10
10
  | <a id="edgebluramount"></a> `edgeBlurAmount` | `number` | Edge blur for mask boundary antialiasing (radius in px): [0,9]. Small values (1–5) smooth mask stair-steps; large values soften edges more visibly. **Default** `4` |
11
- | <a id="effects"></a> `effects` | `"blur"` \| `"none"` \| `"overlay"` | Effects to apply: "none", "blur", or "overlay". "blur" = background blur. "overlay" = replace BG with backgroundImageUrl. |
12
- | <a id="backend"></a> `backend` | `"webgl"` \| `"webgpu"` | Backend to render background effects |
13
- | <a id="foregroundthreshold"></a> `foregroundThreshold` | `number` | [0,1] Upper mask confidence: all mask pixels >= this are considered definite foreground. Adjust to make mask edges tighter or more permissive for foreground inclusion. Example: 0.8 ("mask > 0.8 = sure foreground"). Must always be >= backgroundThreshold. **Default** `0.85` |
14
- | <a id="backgroundthreshold"></a> `backgroundThreshold` | `number` | [0,1] Lower mask confidence: all mask pixels <= this are considered definite background. Adjust to make mask edges tighter or more permissive for background inclusion. Example: 0.3 ("mask < 0.3 = sure background"). **Default** `0.35` |
11
+ | <a id="effects"></a> `effects` | `"blur" \| "none" \| "overlay"` | Effects to apply: "none", "blur", or "overlay". "blur" = background blur. "overlay" = replace BG with backgroundImageUrl. |
12
+ | <a id="backend"></a> `backend` | `"webgl" \| "webgpu" \| "canvas2d"` | Backend to render background effects |
13
+ | <a id="foregroundthreshold"></a> `foregroundThreshold` | `number` | [0,1] Upper mask confidence: all mask pixels \>= this are considered definite foreground. Adjust to make mask edges tighter or more permissive for foreground inclusion. Example: 0.8 ("mask \> 0.8 = sure foreground"). Must always be \>= backgroundThreshold. **Default** `0.85` |
14
+ | <a id="backgroundthreshold"></a> `backgroundThreshold` | `number` | [0,1] Lower mask confidence: all mask pixels \<= this are considered definite background. Adjust to make mask edges tighter or more permissive for background inclusion. Example: 0.3 ("mask \< 0.3 = sure background"). **Default** `0.35` |
15
15
  | <a id="sigmaspace"></a> `sigmaSpace` | `number` | Bilateral filter: sigma in pixel space for mask edge snapping. Controls the neighborhood/pixel distance—higher is larger window (5–10 typical). **Default** `5` |
16
16
  | <a id="sigmarangelo"></a> `sigmaRangeLo` | `number` | Bilateral filter: minimum sigma in color/luma (for mask interiors), [0,1]. Controls how little color difference is needed to cross-mask regions away from edge. Lower = sharper edge preservation in mask interiors. Example: 0.2 **Default** `0.2` |
17
17
  | <a id="sigmarangehi"></a> `sigmaRangeHi` | `number` | Bilateral filter: maximum sigma in color/luma (for mask uncertain zones), [0,1]. Controls how much color similarity is required at uncertain/edge mask locations. Higher = more mask smoothing at edges. Example: 0.8 **Default** `0.8` |
18
18
  | <a id="maskcombineratio"></a> `maskCombineRatio` | `number` | Ratio for mask smoothing (how much uncertainty enables temporal blend), [0,1]. Higher = more frame-to-frame blending, more stability but more trailing ghosts. Typical: 0.6–0.85. **Default** `0.8` |
19
19
  | <a id="excludebystanders"></a> `excludeBystanders` | `boolean` | **`Experimental`** Whether to exclude bystanders/connected people from the output mask. The main person instance (closest to personCenter OR largest blob) is kept in the output mask. All other bystanders/connected people are suppressed (bystander removal). **Default** `false (no bystander removal, all detected people are included in the mask). @experimental This feature is experimental and only works in WebGL backend.` |
20
- | <a id="personcenter"></a> `personCenter` | \[`number`, `number`\] | **`Experimental`** Person center: normalized (x, y) in [0,1] image coordinates for main subject selection. Used by the CCL/bias filter to select the main person blob. **Default** `[0.5, 0.42] (= center, slightly above vertical midpoint). @experimental This feature is experimental and only works in WebGL backend.` |
20
+ | <a id="personcenter"></a> `personCenter` | `[number, number]` | **`Experimental`** Person center: normalized (x, y) in [0,1] image coordinates for main subject selection. Used by the CCL/bias filter to select the main person blob. **Default** `[0.5, 0.42] (= center, slightly above vertical midpoint). @experimental This feature is experimental and only works in WebGL backend.` |
21
21
  | <a id="morpheroderadiuspx"></a> `morphErodeRadiusPx` | `number` | **`Experimental`** Morphological erosion: radius in pixels [1,12]. Sets kernel size for bridge-breaking. Larger values break thicker bridges but may erode fine details. **Default** `5 @experimental This feature is experimental and only works in WebGL backend.` |
22
22
  | <a id="morphpass"></a> `morphPass` | `number` | **`Experimental`** Morphological pass: number of separable passes [1,10]. More passes increase the effective span. **Default** `4 @experimental This feature is experimental and only works in WebGL backend.` |
23
23
  | <a id="morphdilateradiuspx"></a> `morphDilateRadiusPx` | `number` | **`Experimental`** Geodesic dilation: radius in pixels [1,12]. Must match erosion for good reconstruction. **Default** `6 @experimental This feature is experimental and only works in WebGL backend.` |
@@ -2,7 +2,7 @@
2
2
 
3
3
  | Type Parameter |
4
4
  | ------ |
5
- | `P` *extends* `unknown`[] |
5
+ | `P extends unknown[]` |
6
6
 
7
7
  ## Properties
8
8
 
@@ -22,11 +22,11 @@ start(...params): Promise<void>;
22
22
 
23
23
  | Parameter | Type |
24
24
  | ------ | ------ |
25
- | ...`params` | `P` |
25
+ | `...params` | `P` |
26
26
 
27
27
  #### Returns
28
28
 
29
- `Promise`\<`void`\>
29
+ `Promise<void>`
30
30
 
31
31
  ***
32
32
 
@@ -2,4 +2,4 @@
2
2
 
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
- | <a id="canvas"></a> `canvas` | `OffscreenCanvas` \| `undefined` |
5
+ | <a id="canvas"></a> `canvas` | `OffscreenCanvas \| undefined` |
@@ -1,12 +1,14 @@
1
1
  ## Extends
2
2
 
3
- - [`Process`](Process.mdx)\<`Partial`\<[`RendererOptions`](RendererOptions.mdx)\>\>
3
+ ```ts
4
+ - Process<Partial<RendererOptions>>
5
+ ```
4
6
 
5
7
  ## Properties
6
8
 
7
9
  | Property | Type | Inherited from |
8
10
  | ------ | ------ | ------ |
9
- | <a id="status"></a> `status` | \| `"closed"` \| `"closing"` \| `"Error"` \| `"destroyed"` \| `"destroying"` \| `"idle"` \| `"new"` \| `"opened"` \| `"opening"` \| `"processing"` \| `"updated"` \| `"updating"` | [`Process`](Process.mdx).[`status`](Process.mdx#status) |
11
+ | <a id="status"></a> `status` | `\| "closed" \| "closing" \| "Error" \| "destroyed" \| "destroying" \| "idle" \| "new" \| "opened" \| "opening" \| "processing" \| "updated" \| "updating"` | [`Process`](Process.mdx).[`status`](Process.mdx#status) |
10
12
  | <a id="modelasset"></a> `modelAsset` | [`SegmentationModelAsset`](SegmentationModelAsset.mdx) | - |
11
13
  | <a id="backgroundimage"></a> `backgroundImage?` | [`BackgroundImage`](BackgroundImage.mdx) | - |
12
14
 
@@ -15,12 +17,12 @@
15
17
  ### close()
16
18
 
17
19
  ```ts
18
- close(): void;
20
+ close(): Promise<void>;
19
21
  ```
20
22
 
21
23
  #### Returns
22
24
 
23
- `void`
25
+ `Promise<void>`
24
26
 
25
27
  #### Inherited from
26
28
 
@@ -36,7 +38,7 @@ destroy(): Promise<void>;
36
38
 
37
39
  #### Returns
38
40
 
39
- `Promise`\<`void`\>
41
+ `Promise<void>`
40
42
 
41
43
  #### Inherited from
42
44
 
@@ -61,7 +63,9 @@ It is expected to be called once.
61
63
 
62
64
  #### Returns
63
65
 
64
- `Promise`\<`Partial`\<[`RendererOptions`](RendererOptions.mdx)\>\>
66
+ ```ts
67
+ Promise<Partial<RendererOptions>>
68
+ ```
65
69
 
66
70
  #### Overrides
67
71
 
@@ -85,7 +89,9 @@ Update the processor options
85
89
 
86
90
  #### Returns
87
91
 
88
- `Promise`\<`Partial`\<[`RendererOptions`](RendererOptions.mdx)\>\>
92
+ ```ts
93
+ Promise<Partial<RendererOptions>>
94
+ ```
89
95
 
90
96
  ***
91
97
 
@@ -128,7 +134,7 @@ Process provided input
128
134
 
129
135
  ##### Returns
130
136
 
131
- `Promise`\<`MediaStreamTrack`\>
137
+ `Promise<MediaStreamTrack>`
132
138
 
133
139
  #### Call Signature
134
140
 
@@ -142,14 +148,20 @@ process(input, options?): Promise<
142
148
 
143
149
  | Parameter | Type |
144
150
  | ------ | ------ |
145
- | `input` | [`ReadWritableStream`](ReadWritableStream.mdx)\<`VideoFrame`\> |
151
+ | `input` | [`ReadWritableStream<VideoFrame>`](ReadWritableStream.mdx) |
146
152
  | `options?` | [`RendererOptions`](RendererOptions.mdx) |
147
153
 
148
154
  ##### Returns
149
155
 
150
- `Promise`\<
151
- \| [`ReadWritableStream`](ReadWritableStream.mdx)\<`VideoFrame`\>
152
- \| `undefined`\>
156
+ ```ts
157
+ Promise<
158
+ ```
159
+ ```ts
160
+ | ReadWritableStream<VideoFrame>
161
+ ```
162
+ ```ts
163
+ | undefined>
164
+ ```
153
165
 
154
166
  #### Call Signature
155
167
 
@@ -164,15 +176,23 @@ process(input, options?): Promise<
164
176
 
165
177
  | Parameter | Type |
166
178
  | ------ | ------ |
167
- | `input` | \| `MediaStreamTrack` \| [`ReadWritableStream`](ReadWritableStream.mdx)\<`VideoFrame`\> |
179
+ | `input` | \| `MediaStreamTrack` \| [`ReadWritableStream<VideoFrame>`](ReadWritableStream.mdx) |
168
180
  | `options?` | [`RendererOptions`](RendererOptions.mdx) |
169
181
 
170
182
  ##### Returns
171
183
 
172
- `Promise`\<
173
- \| `MediaStreamTrack`
174
- \| [`ReadWritableStream`](ReadWritableStream.mdx)\<`VideoFrame`\>
175
- \| `undefined`\>
184
+ ```ts
185
+ Promise<
186
+ ```
187
+ ```ts
188
+ | MediaStreamTrack
189
+ ```
190
+ ```ts
191
+ | ReadWritableStream<VideoFrame>
192
+ ```
193
+ ```ts
194
+ | undefined>
195
+ ```
176
196
 
177
197
  ***
178
198
 
@@ -188,8 +208,8 @@ Subscribe rendering events,
188
208
 
189
209
  | Parameter | Type |
190
210
  | ------ | ------ |
191
- | `event` | \| `"Error"` \| `"ContextCreationError"` \| `"ContextLost"` \| `"ContextRestored"` \| `"ProcessorRestarted"` \| `"SamplingError"` |
192
- | `callback` | `Callback`\<`void`\> |
211
+ | `event` | `\| "Error" \| "ContextCreationError" \| "ContextLost" \| "ContextRestored" \| "ProcessorRestarted" \| "SamplingError"` |
212
+ | `callback` | `Callback<void>` |
193
213
 
194
214
  #### Returns
195
215
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  | Property | Type |
4
4
  | ------ | ------ |
5
- | <a id="frame"></a> `frame` | `ImageBitmap` \| `VideoFrame` |
5
+ | <a id="frame"></a> `frame` | `ImageBitmap \| VideoFrame` |
6
6
  | <a id="timestamp"></a> `timestamp` | `number` |
7
7
  | <a id="width"></a> `width` | `number` |
8
8
  | <a id="height"></a> `height` | `number` |
@@ -2,9 +2,9 @@
2
2
 
3
3
  | Property | Modifier | Type | Description |
4
4
  | ------ | ------ | ------ | ------ |
5
- | <a id="status"></a> `status` | `readonly` | \| `"closed"` \| `"closing"` \| `"Error"` \| `"destroyed"` \| `"destroying"` \| `"idle"` \| `"new"` \| `"opened"` \| `"opening"` \| `"processing"` \| `"updated"` \| `"updating"` | - |
6
- | <a id="process"></a> `process` | `public` | (`source`) => `Promise`\<`MediaStreamTrack`\> | Process the video and return a MediaStream |
7
- | <a id="destroy"></a> `destroy` | `public` | () => `Promise`\<`void`\> | Destroy the segmentation wasm instance |
5
+ | <a id="status"></a> `status` | `readonly` | `\| "closed" \| "closing" \| "Error" \| "destroyed" \| "destroying" \| "idle" \| "new" \| "opened" \| "opening" \| "processing" \| "updated" \| "updating"` | - |
6
+ | <a id="process"></a> `process` | `public` | `(source) => Promise<MediaStreamTrack>` | Process the video and return a MediaStream |
7
+ | <a id="destroy"></a> `destroy` | `public` | `() => Promise<void>` | Destroy the segmentation wasm instance |
8
8
  | <a id="renderoptions"></a> `renderOptions` | `readonly` | [`RendererOptions`](RendererOptions.mdx) | Current renderer options |
9
9
  | <a id="processingwidth"></a> `processingWidth` | `readonly` | `number` | Current processing width |
10
10
  | <a id="processingheight"></a> `processingHeight` | `readonly` | `number` | Current processing height |
@@ -27,7 +27,7 @@ Initialize the video processor and related
27
27
 
28
28
  #### Returns
29
29
 
30
- `Promise`\<`void`\>
30
+ `Promise<void>`
31
31
 
32
32
  ***
33
33
 
@@ -47,7 +47,7 @@ Update the video processor with provided options
47
47
 
48
48
  #### Returns
49
49
 
50
- `Promise`\<`void`\>
50
+ `Promise<void>`
51
51
 
52
52
  ***
53
53
 
@@ -72,11 +72,11 @@ mute(muted): void;
72
72
  ### close()
73
73
 
74
74
  ```ts
75
- close(): void;
75
+ close(): Promise<void>;
76
76
  ```
77
77
 
78
78
  Stop the process of video segmentation
79
79
 
80
80
  #### Returns
81
81
 
82
- `void`
82
+ `Promise<void>`
@@ -12,5 +12,5 @@
12
12
 
13
13
  | Property | Type |
14
14
  | ------ | ------ |
15
- | <a id="messagehandler"></a> `messageHandler` | (`message`) => `void` |
16
- | <a id="errorhandler"></a> `errorHandler?` | (`event`) => `void` |
15
+ | <a id="messagehandler"></a> `messageHandler` | `(message) => void` |
16
+ | <a id="errorhandler"></a> `errorHandler?` | `(event) => void` |
@@ -4,4 +4,4 @@ type AsyncCallback = () => Promise<void>;
4
4
 
5
5
  ## Returns
6
6
 
7
- `Promise`\<`void`\>
7
+ `Promise<void>`
@@ -7,13 +7,13 @@ type Callback<R, T> = (...params) => R;
7
7
  | Type Parameter |
8
8
  | ------ |
9
9
  | `R` |
10
- | `T` *extends* `unknown`[] |
10
+ | `T extends unknown[]` |
11
11
 
12
12
  ## Parameters
13
13
 
14
14
  | Parameter | Type |
15
15
  | ------ | ------ |
16
- | ...`params` | `T` |
16
+ | `...params` | `T` |
17
17
 
18
18
  ## Returns
19
19
 
@@ -6,4 +6,4 @@ type ExtractMessageEventType<T> = T extends object ? O : never;
6
6
 
7
7
  | Type Parameter |
8
8
  | ------ |
9
- | `T` *extends* `object` |
9
+ | `T extends object` |
@@ -6,5 +6,5 @@ type IncludeMessageEventDataType<E, I> = E extends object ? A extends I ? D : ne
6
6
 
7
7
  | Type Parameter |
8
8
  | ------ |
9
- | `E` *extends* `object` |
9
+ | `E extends object` |
10
10
  | `I` |
@@ -0,0 +1,12 @@
1
+ ```ts
2
+ type Logger = object;
3
+ ```
4
+
5
+ ## Properties
6
+
7
+ | Property | Type |
8
+ | ------ | ------ |
9
+ | <a id="debug"></a> `debug` | `LogMethod` |
10
+ | <a id="info"></a> `info` | `LogMethod` |
11
+ | <a id="warn"></a> `warn` | `LogMethod` |
12
+ | <a id="error"></a> `error` | `LogMethod` |
@@ -7,4 +7,4 @@ type OptionalKeys<T, K> = Omit<T, K> & Partial<Pick<T, K>>;
7
7
  | Type Parameter |
8
8
  | ------ |
9
9
  | `T` |
10
- | `K` *extends* keyof `T` |
10
+ | `K extends keyof T` |
@@ -3,6 +3,7 @@ type ProcessWorkerEvents<T, E, D, U> =
3
3
  | ProcessWorkerEventProcessed<T>
4
4
  | ProcessWorkerEventOpened<U>
5
5
  | ProcessWorkerEventUpdated<U>
6
+ | ProcessWorkerEventClosed
6
7
  | ProcessWorkerEvent<E>
7
8
  | ProcessWorkerEventDebug<D>
8
9
  | ProcessWorkerEventStats;
@@ -6,16 +6,16 @@ type RunnerCreator<P, R> = (callback, frameRate) => Runner<P>;
6
6
 
7
7
  | Type Parameter |
8
8
  | ------ |
9
- | `P` *extends* `unknown`[] |
9
+ | `P extends unknown[]` |
10
10
  | `R` |
11
11
 
12
12
  ## Parameters
13
13
 
14
14
  | Parameter | Type |
15
15
  | ------ | ------ |
16
- | `callback` | [`Callback`](Callback.mdx)\<`R`, `P`\> |
16
+ | `callback` | [`Callback<R, P>`](Callback.mdx) |
17
17
  | `frameRate` | `number` |
18
18
 
19
19
  ## Returns
20
20
 
21
- [`Runner`](../interfaces/Runner.mdx)\<`P`\>
21
+ [`Runner<P>`](../interfaces/Runner.mdx)
@@ -9,4 +9,4 @@ From https://github.com/Microsoft/TypeScript/issues/26223#issuecomment-674500430
9
9
  | Type Parameter |
10
10
  | ------ |
11
11
  | `T` |
12
- | `N` *extends* `number` |
12
+ | `N extends number` |
@@ -8,3 +8,4 @@ const RENDER_BACKEND: object;
8
8
  | ------ | ------ |
9
9
  | <a id="webgl"></a> `WebGL` | `"webgl"` |
10
10
  | <a id="webgpu"></a> `WebGPU` | `"webgpu"` |
11
+ | <a id="canvas2d"></a> `Canvas2D` | `"canvas2d"` |
@@ -13,7 +13,9 @@ const cloneImageRecord: (image) => Promise<{
13
13
 
14
14
  ## Returns
15
15
 
16
- `Promise`\<\{
16
+ ```ts
17
+ Promise<{
18
+ ```
17
19
  `image`: `ImageBitmap`;
18
20
  `key`: `string`;
19
21
  \}\>
@@ -6,7 +6,7 @@ const createLazyProps: <T>(stateBuilder) => T;
6
6
 
7
7
  | Type Parameter |
8
8
  | ------ |
9
- | `T` *extends* `Record`\<`string`, `unknown`\> |
9
+ | `T extends Record<string, unknown>` |
10
10
 
11
11
  ## Parameters
12
12
 
@@ -6,7 +6,7 @@ const createObjectUpdater: <T>(original) => (another) => void;
6
6
 
7
7
  | Type Parameter |
8
8
  | ------ |
9
- | `T` *extends* `{ [K in keyof T]: unknown }` |
9
+ | `T extends { [K in keyof T]: unknown }` |
10
10
 
11
11
  ## Parameters
12
12
 
@@ -24,7 +24,7 @@ const createObjectUpdater: <T>(original) => (another) => void;
24
24
 
25
25
  | Parameter | Type |
26
26
  | ------ | ------ |
27
- | `another` | `Partial`\<`T`\> |
27
+ | `another` | `Partial<T>` |
28
28
 
29
29
  ### Returns
30
30
 
@@ -14,8 +14,8 @@ const createRemoteImageBitmap: (map?) => object;
14
14
 
15
15
  | Name | Type |
16
16
  | ------ | ------ |
17
- | `tryFetchingImage()` | (`uri`, `abortSignal`) => `Promise`\<`ImageBitmap` \| `null` \| `undefined`\> |
18
- | `setImage()` | (`uri`, `image`) => `void` |
19
- | `getImage()` | (`uri`) => `ImageBitmap` \| `null` |
20
- | `removeImage()` | (`uri`) => `boolean` |
21
- | `clear()` | () => `void` |
17
+ | `tryFetchingImage()` | `(uri, abortSignal) => Promise<ImageBitmap` | null | undefined\>` |
18
+ | `setImage()` | `(uri, image) => void` |
19
+ | `getImage()` | `(uri) => ImageBitmap \| null` |
20
+ | `removeImage()` | `(uri) => boolean` |
21
+ | `clear()` | `() => void` |
@@ -0,0 +1,7 @@
1
+ ```ts
2
+ const getCanUseWebGL: () => boolean;
3
+ ```
4
+
5
+ ## Returns
6
+
7
+ `boolean`
@@ -8,7 +8,7 @@ const handleWebGLContextLoss: (canvas, eventHandlers, contextLostCb?) => () => v
8
8
  | ------ | ------ |
9
9
  | `canvas` | `OffscreenCanvas` |
10
10
  | `eventHandlers` | [`RenderEventHandlers`](../interfaces/RenderEventHandlers.mdx) |
11
- | `contextLostCb?` | () => `void` |
11
+ | `contextLostCb?` | `() => void` |
12
12
 
13
13
  ## Returns
14
14
 
@@ -6,5 +6,5 @@ const urls: object;
6
6
 
7
7
  | Name | Type |
8
8
  | ------ | ------ |
9
- | <a id="denoise"></a> `denoise()` | () => `URL` |
10
- | <a id="mediaworker"></a> `mediaWorker()` | () => `URL` |
9
+ | <a id="denoise"></a> `denoise()` | `() => URL` |
10
+ | <a id="mediaworker"></a> `mediaWorker()` | `() => URL` |
@@ -0,0 +1,2 @@
1
+ import type { Renderer, RenderEventHandlers } from '../../types/render';
2
+ export declare const createRenderer: (renderEventHandlers: RenderEventHandlers, canvas?: OffscreenCanvas) => Renderer;
@@ -0,0 +1,36 @@
1
+ import { PROCESSING_HEIGHT, PROCESSING_WIDTH } from '../../constants';
2
+ import { createCanvasRenderUtils } from '../../canvasRenderUtils';
3
+ export const createRenderer = (renderEventHandlers, canvas = new OffscreenCanvas(PROCESSING_WIDTH, PROCESSING_HEIGHT)) => {
4
+ const utils = createCanvasRenderUtils(canvas.width, canvas.height);
5
+ let ctx = null;
6
+ const init = () => {
7
+ ctx = canvas.getContext('2d');
8
+ if (!ctx) {
9
+ renderEventHandlers.contextCreationError('Failed to create 2D rendering context');
10
+ }
11
+ };
12
+ const render = (mask, frame, options) => {
13
+ if (!ctx) {
14
+ return;
15
+ }
16
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
17
+ const inputImage = utils.evaluateInput(frame);
18
+ if (options.effects === 'blur' && options.backgroundBlurAmount) {
19
+ utils.drawBlurEffect(canvas, inputImage, mask, options.foregroundThreshold, options.backgroundBlurAmount, options.edgeBlurAmount);
20
+ }
21
+ else if (options?.effects === 'overlay' && options.backgroundImage) {
22
+ utils.drawOverlayEffect(canvas, inputImage, options.backgroundImage, mask, options.foregroundThreshold, 0, options.edgeBlurAmount);
23
+ }
24
+ };
25
+ const cleanup = () => {
26
+ utils.reset();
27
+ ctx = null;
28
+ };
29
+ const release = () => {
30
+ cleanup();
31
+ };
32
+ const isContextLost = () => {
33
+ return !ctx || ctx.isContextLost();
34
+ };
35
+ return { init, render, release, isContextLost };
36
+ };
@@ -2,7 +2,7 @@ import type { TextureInfo } from './types';
2
2
  /**
3
3
  * Blur provided frame
4
4
  */
5
- export declare const createBlurRenderer: (processor: OffscreenCanvas, pass: number, redOnly?: boolean) => {
5
+ export declare const createBlurRenderer: (processor: OffscreenCanvas, redOnly?: boolean) => {
6
6
  render: (frame: TextureInfo, pass: number) => TextureInfo;
7
7
  release: () => void;
8
8
  };