@webex/ladon-ts 4.5.1 → 5.0.2

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 (49) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/module/config.json.js +26 -0
  3. package/build/module/config.json.js.map +1 -0
  4. package/build/module/index.d.ts +3 -0
  5. package/build/module/index.js +41 -8
  6. package/build/module/index.js.map +1 -0
  7. package/build/module/lib/config-builder.d.ts +180 -0
  8. package/build/module/lib/config-builder.js +336 -0
  9. package/build/module/lib/config-builder.js.map +1 -0
  10. package/build/module/lib/config-types.d.ts +98 -0
  11. package/build/module/lib/config-types.js +6 -0
  12. package/build/module/lib/config-types.js.map +1 -0
  13. package/build/module/lib/config.d.ts +30 -105
  14. package/build/module/lib/config.js +22 -151
  15. package/build/module/lib/config.js.map +1 -0
  16. package/build/module/lib/generator.d.ts +2 -1
  17. package/build/module/lib/generator.js +212 -273
  18. package/build/module/lib/generator.js.map +1 -0
  19. package/build/module/lib/pipeline.d.ts +3 -2
  20. package/build/module/lib/pipeline.js +158 -218
  21. package/build/module/lib/pipeline.js.map +1 -0
  22. package/build/module/lib/preload.d.ts +9 -0
  23. package/build/module/lib/preload.js +8 -0
  24. package/build/module/lib/preload.js.map +1 -0
  25. package/build/module/lib/renderer/blur-renderer.d.ts +5 -4
  26. package/build/module/lib/renderer/blur-renderer.js +102 -126
  27. package/build/module/lib/renderer/blur-renderer.js.map +1 -0
  28. package/build/module/lib/renderer/ladon-renderer.d.ts +2 -1
  29. package/build/module/lib/renderer/passthrough-renderer.d.ts +5 -4
  30. package/build/module/lib/renderer/passthrough-renderer.js +25 -44
  31. package/build/module/lib/renderer/passthrough-renderer.js.map +1 -0
  32. package/build/module/lib/renderer/replacement-renderer.d.ts +8 -5
  33. package/build/module/lib/renderer/replacement-renderer.js +84 -99
  34. package/build/module/lib/renderer/replacement-renderer.js.map +1 -0
  35. package/build/module/lib/renderer/webgl-renderer.d.ts +11 -3
  36. package/build/module/lib/renderer/webgl-renderer.js +168 -115
  37. package/build/module/lib/renderer/webgl-renderer.js.map +1 -0
  38. package/build/module/lib/shared-resource-manager.d.ts +40 -31
  39. package/build/module/lib/shared-resource-manager.js +151 -189
  40. package/build/module/lib/shared-resource-manager.js.map +1 -0
  41. package/build/module/lib/util.d.ts +10 -0
  42. package/build/module/lib/util.js +92 -179
  43. package/build/module/lib/util.js.map +1 -0
  44. package/build/module/lib/version.d.ts +1 -1
  45. package/build/module/lib/version.js +5 -2
  46. package/build/module/lib/version.js.map +1 -0
  47. package/package.json +21 -5
  48. package/build/module/lib/renderer/ladon-renderer.js +0 -2
  49. package/build/module/lib/renderer.js +0 -6
@@ -1,218 +1,158 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { LocalGenerator, NullGenerator, WorkerGenerator, } from './generator';
11
- import { BlurRenderer, PassthroughRenderer, ReplacementRenderer } from './renderer';
12
- import { resizeImage } from './util';
13
- export class Pipeline {
14
- constructor(inputCanvas, outputCanvas, config, videoElement) {
15
- this.inputCanvas = inputCanvas;
16
- this.outputCanvas = outputCanvas;
17
- this.config = config;
18
- this.videoElement = videoElement;
19
- this.loaded = false;
20
- this.frameQueue = [];
21
- this.maskQueue = [];
22
- const inputCanvasCtx = this.inputCanvas.getContext('2d', {
23
- alpha: false,
24
- willReadFrequently: true,
25
- });
26
- if (!inputCanvasCtx) {
27
- throw new Error('[ladon-ts] - error getting input context 2d');
28
- }
29
- this.inputCanvasCtx = inputCanvasCtx;
30
- }
31
- /**
32
- * Processes a single frame and returns the inference result.
33
- *
34
- * @param timestamp - The timestamp of the frame.
35
- * @param [performInference=true] - Flag to perform mask inference.
36
- * @returns The result of the frame processing.
37
- * @throws If the pipeline (generator or renderer) is not loaded.
38
- */
39
- onFrame(timestamp, performInference = true) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- if (!this.generator || !this.renderer) {
42
- throw new Error('[ladon-ts] - pipeline is not loaded.');
43
- }
44
- // Get the current frame (raw image data or video element)
45
- const frameData = this.getInputFrameData(performInference);
46
- // Add the frame to the queue with its timestamp
47
- this.frameQueue.push({ timestamp, frameData });
48
- if (performInference || !this.lastMaskResult) {
49
- // Perform inference and add the new mask to the mask queue
50
- const rawImageData = frameData;
51
- const maskImageData = this.getMaskImageData(rawImageData);
52
- const maskResult = yield this.generator.getLadonOutput(maskImageData, timestamp);
53
- // Add the mask to the queue and use the mask timestamp to sync frames and masks.
54
- this.maskQueue.push({ timestamp: maskResult.timestamp, maskResult });
55
- this.lastMaskResult = maskResult;
56
- // Sync frames and masks to render together
57
- yield this.renderSyncedFrameAndMask();
58
- // Post-process the mask after rendering
59
- yield this.generator.postRender(maskImageData, timestamp);
60
- }
61
- else {
62
- // Skipping inference. Update the last mask result's timestamp to match the current frame.
63
- this.maskQueue.push({ timestamp, maskResult: this.lastMaskResult });
64
- // Sync frames and masks to render together
65
- yield this.renderSyncedFrameAndMask();
66
- }
67
- // Return the inference result
68
- return this.createInferenceResult(timestamp, performInference);
69
- });
70
- }
71
- /**
72
- * Synchronizes frames and masks to ensure they are rendered together.
73
- */
74
- renderSyncedFrameAndMask() {
75
- var _a;
76
- return __awaiter(this, void 0, void 0, function* () {
77
- while (this.frameQueue.length > 0 && this.maskQueue.length > 0) {
78
- const frame = this.frameQueue[0];
79
- const maskEntry = this.maskQueue[0];
80
- if (frame.timestamp === maskEntry.timestamp) {
81
- // Render the frame and mask together
82
- yield ((_a = this.renderer) === null || _a === void 0 ? void 0 : _a.render(frame.frameData, maskEntry.maskResult));
83
- this.frameQueue.shift();
84
- this.maskQueue.shift();
85
- }
86
- else if (frame.timestamp < maskEntry.timestamp) {
87
- // Discard the older frame
88
- this.frameQueue.shift();
89
- }
90
- else {
91
- // Discard the older mask
92
- this.maskQueue.shift();
93
- }
94
- }
95
- });
96
- }
97
- /**
98
- * Gets the raw image data from the input canvas context.
99
- *
100
- * @param needFreshImageData - Flag to indicate if fresh image data is needed.
101
- *
102
- * @returns The raw image data.
103
- */
104
- getInputFrameData(needFreshImageData) {
105
- if (needFreshImageData || !this.videoElement) {
106
- return this.inputCanvasCtx.getImageData(0, 0, this.config.input.width, this.config.input.height).data;
107
- }
108
- return this.videoElement;
109
- }
110
- /**
111
- * Resizes the image data if the model expects a fixed size input.
112
- *
113
- * @param {Uint8ClampedArray} rawImageData - The raw image data.
114
- * @returns {Uint8ClampedArray} - The processed mask image data.
115
- */
116
- getMaskImageData(rawImageData) {
117
- // Check if resizing is needed based on configuration.
118
- if (this.config.mask.input_size.width === this.config.input.width) {
119
- return rawImageData;
120
- }
121
- // Resize the image data.
122
- return resizeImage(rawImageData, this.config.input.width, this.config.input.height, this.config.mask.input_size.width, this.config.mask.input_size.height);
123
- }
124
- /**
125
- * Creates the inference result object.
126
- *
127
- * @param {number} timestamp - The timestamp of the frame.
128
- * @param {boolean} performedInference - Indicates if the inference was performed.
129
- * @returns {IFrameInferenceResult} - The result object containing inference details.
130
- */
131
- createInferenceResult(timestamp, performedInference) {
132
- if (!this.lastMaskResult) {
133
- return {
134
- facesAndLandmarks: { data: new Float32Array(0), dims: [] },
135
- gesture: new Float32Array(0),
136
- motion: 0,
137
- skipped: true,
138
- timestamp,
139
- };
140
- }
141
- return {
142
- facesAndLandmarks: this.lastMaskResult.facesAndLandmarks,
143
- gesture: this.lastMaskResult.gesture,
144
- motion: this.lastMaskResult.motion,
145
- skipped: !performedInference,
146
- timestamp,
147
- };
148
- }
149
- /**
150
- * Checks if the pipeline is loaded.
151
- *
152
- * @returns True if the pipeline is loaded, false otherwise.
153
- */
154
- isLoaded() {
155
- return this.loaded;
156
- }
157
- /**
158
- * Loads the pipeline components such as the generator and renderer.
159
- */
160
- load() {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- switch (this.config.render.type) {
163
- case 'blur':
164
- this.renderer = new BlurRenderer(this.outputCanvas, this.config);
165
- break;
166
- case 'passthrough':
167
- this.renderer = new PassthroughRenderer(this.outputCanvas, this.config);
168
- break;
169
- case 'replacement':
170
- this.renderer = new ReplacementRenderer(this.outputCanvas, this.config);
171
- break;
172
- default:
173
- throw new Error('[ladon-ts] - renderer not implemented.');
174
- }
175
- yield this.renderer.load();
176
- if (this.config.render.type === 'passthrough') {
177
- // automatically disable model evaluation when the renderer is set to passthrough
178
- // Note: this may change when gestures are detected (model eval will be a dependency for more than rendering)
179
- this.generator = new NullGenerator(this.config);
180
- }
181
- else {
182
- switch (this.config.mask.generator) {
183
- case 'local':
184
- this.generator = new LocalGenerator(this.config);
185
- break;
186
- case 'worker':
187
- this.generator = new WorkerGenerator(this.config);
188
- break;
189
- default:
190
- throw new Error('[ladon-ts] - generator not implemented.');
191
- }
192
- }
193
- yield this.generator.load();
194
- this.loaded = true;
195
- });
196
- }
197
- /**
198
- * Resets the frame and mask queues.
199
- */
200
- resetQueues() {
201
- this.frameQueue = [];
202
- this.maskQueue = [];
203
- }
204
- reset() {
205
- this.resetQueues();
206
- this.lastMaskResult = undefined;
207
- }
208
- /**
209
- * Destroys the pipeline and cleans up resources.
210
- */
211
- destroy() {
212
- var _a, _b;
213
- this.reset();
214
- (_a = this.generator) === null || _a === void 0 ? void 0 : _a.destroy();
215
- (_b = this.renderer) === null || _b === void 0 ? void 0 : _b.destroy();
216
- }
217
- }
218
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGlwZWxpbmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3BpcGVsaW5lLnRzIl0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5QyxDQUFDLENBQUM7aUJBQ2xFO2FBQ0o7WUFFRCxNQUFNLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxFQUFFLENBQUM7WUFFNUIsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUM7UUFDdkIsQ0FBQztLQUFBO0lBRUQ7O09BRUc7SUFDSyxXQUFXO1FBQ2YsSUFBSSxDQUFDLFVBQVUsR0FBRyxFQUFFLENBQUM7UUFDckIsSUFBSSxDQUFDLFNBQVMsR0FBRyxFQUFFLENBQUM7SUFDeEIsQ0FBQztJQUVNLEtBQUs7UUFDUixJQUFJLENBQUMsV0FBVyxFQUFFLENBQUM7UUFDbkIsSUFBSSxDQUFDLGNBQWMsR0FBRyxTQUFTLENBQUM7SUFDcEMsQ0FBQztJQUVEOztPQUVHO0lBQ0ksT0FBTzs7UUFDVixJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDYixNQUFBLElBQUksQ0FBQyxTQUFTLDBDQUFFLE9BQU8sRUFBRSxDQUFDO1FBQzFCLE1BQUEsSUFBSSxDQUFDLFFBQVEsMENBQUUsT0FBTyxFQUFFLENBQUM7SUFDN0IsQ0FBQztDQUNKIn0=
1
+ import { NullGenerator as n, WorkerGenerator as h, LocalGenerator as o } from "./generator.js";
2
+ import { BlurRenderer as u } from "./renderer/blur-renderer.js";
3
+ import { PassthroughRenderer as d } from "./renderer/passthrough-renderer.js";
4
+ import { ReplacementRenderer as l } from "./renderer/replacement-renderer.js";
5
+ import { resizeImage as m } from "./util.js";
6
+ class R {
7
+ constructor(e, t, s, i) {
8
+ this.inputCanvas = e, this.outputCanvas = t, this.config = s, this.videoElement = i, this.loaded = !1, this.frameQueue = [], this.maskQueue = [];
9
+ const a = this.inputCanvas.getContext("2d", {
10
+ alpha: !1,
11
+ willReadFrequently: !0
12
+ });
13
+ if (!a)
14
+ throw new Error("[ladon-ts] - error getting input context 2d");
15
+ this.inputCanvasCtx = a;
16
+ }
17
+ /**
18
+ * Processes a single frame and returns the inference result.
19
+ *
20
+ * @param timestamp - The timestamp of the frame.
21
+ * @param [performInference=true] - Flag to perform mask inference.
22
+ * @returns The result of the frame processing.
23
+ * @throws If the pipeline (generator or renderer) is not loaded.
24
+ */
25
+ async onFrame(e, t = !0) {
26
+ if (!this.generator || !this.renderer)
27
+ throw new Error("[ladon-ts] - pipeline is not loaded.");
28
+ const s = this.getInputFrameData(t);
29
+ if (this.frameQueue.push({ timestamp: e, frameData: s }), t || !this.lastMaskResult) {
30
+ const i = s, a = this.getMaskImageData(i), r = await this.generator.getLadonOutput(a, e);
31
+ this.maskQueue.push({ timestamp: r.timestamp, maskResult: r }), this.lastMaskResult = r, await this.renderSyncedFrameAndMask(), await this.generator.postRender(a, e);
32
+ } else
33
+ this.maskQueue.push({ timestamp: e, maskResult: this.lastMaskResult }), await this.renderSyncedFrameAndMask();
34
+ return this.createInferenceResult(e, t);
35
+ }
36
+ /**
37
+ * Synchronizes frames and masks to ensure they are rendered together.
38
+ */
39
+ async renderSyncedFrameAndMask() {
40
+ var e;
41
+ for (; this.frameQueue.length > 0 && this.maskQueue.length > 0; ) {
42
+ const t = this.frameQueue[0], s = this.maskQueue[0];
43
+ t.timestamp === s.timestamp ? (await ((e = this.renderer) == null ? void 0 : e.render(t.frameData, s.maskResult)), this.frameQueue.shift(), this.maskQueue.shift()) : t.timestamp < s.timestamp ? this.frameQueue.shift() : this.maskQueue.shift();
44
+ }
45
+ }
46
+ /**
47
+ * Gets the raw image data from the input canvas context.
48
+ *
49
+ * @param needFreshImageData - Flag to indicate if fresh image data is needed.
50
+ *
51
+ * @returns The raw image data.
52
+ */
53
+ getInputFrameData(e) {
54
+ return e || !this.videoElement ? this.inputCanvasCtx.getImageData(
55
+ 0,
56
+ 0,
57
+ this.config.input.width,
58
+ this.config.input.height
59
+ ).data : this.videoElement;
60
+ }
61
+ /**
62
+ * Resizes the image data if the model expects a fixed size input.
63
+ *
64
+ * @param {Uint8ClampedArray} rawImageData - The raw image data.
65
+ * @returns {Uint8ClampedArray} - The processed mask image data.
66
+ */
67
+ getMaskImageData(e) {
68
+ return this.config.mask.inputSize.width === this.config.input.width ? e : m(
69
+ e,
70
+ this.config.input.width,
71
+ this.config.input.height,
72
+ this.config.mask.inputSize.width,
73
+ this.config.mask.inputSize.height
74
+ );
75
+ }
76
+ /**
77
+ * Creates the inference result object.
78
+ *
79
+ * @param {number} timestamp - The timestamp of the frame.
80
+ * @param {boolean} performedInference - Indicates if the inference was performed.
81
+ * @returns {IFrameInferenceResult} - The result object containing inference details.
82
+ */
83
+ createInferenceResult(e, t) {
84
+ return this.lastMaskResult ? {
85
+ facesAndLandmarks: this.lastMaskResult.facesAndLandmarks,
86
+ gesture: this.lastMaskResult.gesture,
87
+ motion: this.lastMaskResult.motion,
88
+ skipped: !t,
89
+ timestamp: e
90
+ } : {
91
+ facesAndLandmarks: { data: new Float32Array(0), dims: [] },
92
+ gesture: new Float32Array(0),
93
+ motion: 0,
94
+ skipped: !0,
95
+ timestamp: e
96
+ };
97
+ }
98
+ /**
99
+ * Checks if the pipeline is loaded.
100
+ *
101
+ * @returns True if the pipeline is loaded, false otherwise.
102
+ */
103
+ isLoaded() {
104
+ return this.loaded;
105
+ }
106
+ /**
107
+ * Loads the pipeline components such as the generator and renderer.
108
+ */
109
+ async load() {
110
+ switch (this.config.render.type) {
111
+ case "blur":
112
+ this.renderer = new u(this.outputCanvas, this.config);
113
+ break;
114
+ case "passthrough":
115
+ this.renderer = new d(this.outputCanvas, this.config);
116
+ break;
117
+ case "replacement":
118
+ this.renderer = new l(this.outputCanvas, this.config);
119
+ break;
120
+ default:
121
+ throw new Error("[ladon-ts] - renderer not implemented.");
122
+ }
123
+ if (await this.renderer.load(), this.config.render.type === "passthrough")
124
+ this.generator = new n(this.config);
125
+ else
126
+ switch (this.config.mask.generator) {
127
+ case "local":
128
+ this.generator = new o(this.config);
129
+ break;
130
+ case "worker":
131
+ this.generator = new h(this.config);
132
+ break;
133
+ default:
134
+ throw new Error("[ladon-ts] - generator not implemented.");
135
+ }
136
+ await this.generator.load(), this.loaded = !0;
137
+ }
138
+ /**
139
+ * Resets the frame and mask queues.
140
+ */
141
+ resetQueues() {
142
+ this.frameQueue = [], this.maskQueue = [];
143
+ }
144
+ reset() {
145
+ this.resetQueues(), this.lastMaskResult = void 0;
146
+ }
147
+ /**
148
+ * Destroys the pipeline and cleans up resources.
149
+ */
150
+ destroy() {
151
+ var e, t;
152
+ this.reset(), (e = this.generator) == null || e.destroy(), (t = this.renderer) == null || t.destroy();
153
+ }
154
+ }
155
+ export {
156
+ R as Pipeline
157
+ };
158
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sources":["../../../src/lib/pipeline.ts"],"sourcesContent":["import { PipelineConfig } from './config-types';\nimport {\n FacesAndLandmarks,\n FrameData,\n LadonOutput,\n LocalGenerator,\n MaskGenerator,\n NullGenerator,\n WorkerGenerator,\n} from './generator';\nimport { BlurRenderer, LadonRenderer, PassthroughRenderer, ReplacementRenderer } from './renderer';\nimport { resizeImage } from './util';\n\nexport interface IFrameInferenceResult {\n facesAndLandmarks: FacesAndLandmarks;\n gesture: Float32Array;\n motion: number;\n skipped: boolean;\n timestamp: number;\n}\n\nexport interface IPipeline {\n onFrame(\n timestamp: number,\n maskNeeded?: boolean,\n videoElement?: HTMLVideoElement\n ): Promise<IFrameInferenceResult>;\n isLoaded(): boolean;\n load(): Promise<void>;\n destroy(): void;\n}\n\nexport class Pipeline implements IPipeline {\n private generator?: MaskGenerator;\n private renderer?: LadonRenderer;\n private loaded = false;\n\n private inputCanvasCtx: CanvasRenderingContext2D;\n private lastMaskResult?: LadonOutput;\n\n private frameQueue: Array<{ timestamp: number; frameData: FrameData }> = [];\n private maskQueue: Array<{ timestamp: number; maskResult: LadonOutput }> = [];\n\n constructor(\n private inputCanvas: HTMLCanvasElement,\n private outputCanvas: HTMLCanvasElement,\n public readonly config: PipelineConfig,\n private readonly videoElement?: HTMLVideoElement\n ) {\n const inputCanvasCtx = this.inputCanvas.getContext('2d', {\n alpha: false,\n willReadFrequently: true,\n });\n\n if (!inputCanvasCtx) {\n throw new Error('[ladon-ts] - error getting input context 2d');\n }\n this.inputCanvasCtx = inputCanvasCtx;\n }\n\n /**\n * Processes a single frame and returns the inference result.\n *\n * @param timestamp - The timestamp of the frame.\n * @param [performInference=true] - Flag to perform mask inference.\n * @returns The result of the frame processing.\n * @throws If the pipeline (generator or renderer) is not loaded.\n */\n public async onFrame(\n timestamp: number,\n performInference = true\n ): Promise<IFrameInferenceResult> {\n if (!this.generator || !this.renderer) {\n throw new Error('[ladon-ts] - pipeline is not loaded.');\n }\n\n // Get the current frame (raw image data or video element)\n const frameData = this.getInputFrameData(performInference);\n\n // Add the frame to the queue with its timestamp\n this.frameQueue.push({ timestamp, frameData });\n\n if (performInference || !this.lastMaskResult) {\n // Perform inference and add the new mask to the mask queue\n const rawImageData = frameData as Uint8ClampedArray;\n const maskImageData = this.getMaskImageData(rawImageData);\n const maskResult = await this.generator.getLadonOutput(maskImageData, timestamp);\n // Add the mask to the queue and use the mask timestamp to sync frames and masks.\n this.maskQueue.push({ timestamp: maskResult.timestamp, maskResult });\n this.lastMaskResult = maskResult;\n\n // Sync frames and masks to render together\n await this.renderSyncedFrameAndMask();\n\n // Post-process the mask after rendering\n await this.generator.postRender(maskImageData, timestamp);\n } else {\n // Skipping inference. Update the last mask result's timestamp to match the current frame.\n this.maskQueue.push({ timestamp, maskResult: this.lastMaskResult });\n // Sync frames and masks to render together\n await this.renderSyncedFrameAndMask();\n }\n\n // Return the inference result\n return this.createInferenceResult(timestamp, performInference);\n }\n\n /**\n * Synchronizes frames and masks to ensure they are rendered together.\n */\n private async renderSyncedFrameAndMask(): Promise<void> {\n while (this.frameQueue.length > 0 && this.maskQueue.length > 0) {\n const frame = this.frameQueue[0];\n const maskEntry = this.maskQueue[0];\n\n if (frame.timestamp === maskEntry.timestamp) {\n // Render the frame and mask together\n await this.renderer?.render(frame.frameData, maskEntry.maskResult);\n this.frameQueue.shift();\n this.maskQueue.shift();\n } else if (frame.timestamp < maskEntry.timestamp) {\n // Discard the older frame\n this.frameQueue.shift();\n } else {\n // Discard the older mask\n this.maskQueue.shift();\n }\n }\n }\n\n /**\n * Gets the raw image data from the input canvas context.\n *\n * @param needFreshImageData - Flag to indicate if fresh image data is needed.\n *\n * @returns The raw image data.\n */\n private getInputFrameData(needFreshImageData: boolean): FrameData {\n if (needFreshImageData || !this.videoElement) {\n return this.inputCanvasCtx.getImageData(\n 0,\n 0,\n this.config.input.width,\n this.config.input.height\n ).data;\n }\n\n return this.videoElement;\n }\n\n /**\n * Resizes the image data if the model expects a fixed size input.\n *\n * @param {Uint8ClampedArray} rawImageData - The raw image data.\n * @returns {Uint8ClampedArray} - The processed mask image data.\n */\n private getMaskImageData(rawImageData: Uint8ClampedArray): Uint8ClampedArray {\n // Check if resizing is needed based on configuration.\n if (this.config.mask.inputSize.width === this.config.input.width) {\n return rawImageData;\n }\n\n // Resize the image data.\n return resizeImage(\n rawImageData,\n this.config.input.width,\n this.config.input.height,\n this.config.mask.inputSize.width,\n this.config.mask.inputSize.height\n );\n }\n\n /**\n * Creates the inference result object.\n *\n * @param {number} timestamp - The timestamp of the frame.\n * @param {boolean} performedInference - Indicates if the inference was performed.\n * @returns {IFrameInferenceResult} - The result object containing inference details.\n */\n private createInferenceResult(\n timestamp: number,\n performedInference: boolean\n ): IFrameInferenceResult {\n if (!this.lastMaskResult) {\n return {\n facesAndLandmarks: { data: new Float32Array(0), dims: [] },\n gesture: new Float32Array(0),\n motion: 0,\n skipped: true,\n timestamp,\n };\n }\n\n return {\n facesAndLandmarks: this.lastMaskResult.facesAndLandmarks,\n gesture: this.lastMaskResult.gesture,\n motion: this.lastMaskResult.motion,\n skipped: !performedInference,\n timestamp,\n };\n }\n\n /**\n * Checks if the pipeline is loaded.\n *\n * @returns True if the pipeline is loaded, false otherwise.\n */\n public isLoaded(): boolean {\n return this.loaded;\n }\n\n /**\n * Loads the pipeline components such as the generator and renderer.\n */\n public async load(): Promise<void> {\n switch (this.config.render.type) {\n case 'blur':\n this.renderer = new BlurRenderer(this.outputCanvas, this.config);\n break;\n case 'passthrough':\n this.renderer = new PassthroughRenderer(this.outputCanvas, this.config);\n break;\n case 'replacement':\n this.renderer = new ReplacementRenderer(this.outputCanvas, this.config);\n break;\n default:\n throw new Error('[ladon-ts] - renderer not implemented.');\n }\n\n await this.renderer.load();\n\n if (this.config.render.type === 'passthrough') {\n // automatically disable model evaluation when the renderer is set to passthrough\n // Note: this may change when gestures are detected (model eval will be a dependency for more than rendering)\n this.generator = new NullGenerator(this.config);\n } else {\n switch (this.config.mask.generator) {\n case 'local':\n this.generator = new LocalGenerator(this.config);\n break;\n case 'worker':\n this.generator = new WorkerGenerator(this.config);\n break;\n default:\n throw new Error('[ladon-ts] - generator not implemented.');\n }\n }\n\n await this.generator.load();\n\n this.loaded = true;\n }\n\n /**\n * Resets the frame and mask queues.\n */\n private resetQueues(): void {\n this.frameQueue = [];\n this.maskQueue = [];\n }\n\n public reset(): void {\n this.resetQueues();\n this.lastMaskResult = undefined;\n }\n\n /**\n * Destroys the pipeline and cleans up resources.\n */\n public destroy(): void {\n this.reset();\n this.generator?.destroy();\n this.renderer?.destroy();\n }\n}\n"],"names":["Pipeline","inputCanvas","outputCanvas","config","videoElement","inputCanvasCtx","timestamp","performInference","frameData","rawImageData","maskImageData","maskResult","frame","maskEntry","_a","needFreshImageData","resizeImage","performedInference","BlurRenderer","PassthroughRenderer","ReplacementRenderer","NullGenerator","LocalGenerator","WorkerGenerator","_b"],"mappings":";;;;;AAgCO,MAAMA,EAA8B;AAAA,EAWvC,YACYC,GACAC,GACQC,GACCC,GACnB;AAJU,SAAA,cAAAH,GACA,KAAA,eAAAC,GACQ,KAAA,SAAAC,GACC,KAAA,eAAAC,GAZrB,KAAQ,SAAS,IAKjB,KAAQ,aAAiE,CAAC,GAC1E,KAAQ,YAAmE,CAAC;AAQxE,UAAMC,IAAi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AAK,OAAO,OAAO,MAAM;AAAA,MAC7B,KAAK;AACD,aAAK,WAAW,IAAIY,EAAa,KAAK,cAAc,KAAK,MAAM;AAC/D;AAAA,MACJ,KAAK;AACD,aAAK,WAAW,IAAIC,EAAoB,KAAK,cAAc,KAAK,MAAM;AACtE;AAAA,MACJ,KAAK;AACD,aAAK,WAAW,IAAIC,EAAoB,KAAK,cAAc,KAAK,MAAM;AACtE;AAAA,MACJ;AACU,cAAA,IAAI,MAAM,wCAAwC;AAAA,IAAA;AAKhE,QAFM,MAAA,KAAK,SAAS,KAAK,GAErB,KAAK,OAAO,OAAO,SAAS;AAG5B,WAAK,YAAY,IAAIC,EAAc,KAAK,MAAM;AAAA;AAEtC,cAAA,KAAK,OAAO,KAAK,WAAW;AAAA,QAChC,KAAK;AACD,eAAK,YAAY,IAAIC,EAAe,KAAK,MAAM;AAC/C;AAAA,QACJ,KAAK;AACD,eAAK,YAAY,IAAIC,EAAgB,KAAK,MAAM;AAChD;AAAA,QACJ;AACU,gBAAA,IAAI,MAAM,yCAAyC;AAAA,MAAA;AAI/D,UAAA,KAAK,UAAU,KAAK,GAE1B,KAAK,SAAS;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMV,cAAoB;AACxB,SAAK,aAAa,CAAC,GACnB,KAAK,YAAY,CAAC;AAAA,EAAA;AAAA,EAGf,QAAc;AACjB,SAAK,YAAY,GACjB,KAAK,iBAAiB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,UAAgB;;AACnB,SAAK,MAAM,IACXT,IAAA,KAAK,cAAL,QAAAA,EAAgB,YAChBU,IAAA,KAAK,aAAL,QAAAA,EAAe;AAAA,EAAQ;AAE/B;"}
@@ -0,0 +1,9 @@
1
+ import { PreloadConfig } from './config-types';
2
+
3
+ /**
4
+ * Preload the resources using the provided configuration. This function is used to preload the model
5
+ * and the worker before creating the pipeline.
6
+ *
7
+ * @param config - The configuration object.
8
+ */
9
+ export declare const preload: (config: PreloadConfig) => Promise<void>;
@@ -0,0 +1,8 @@
1
+ import { sharedResourceManager as r } from "./shared-resource-manager.js";
2
+ const o = async (e) => {
3
+ e.mask.generator === "worker" ? await r.preloadWorker(e) : await r.loadModel(e);
4
+ };
5
+ export {
6
+ o as preload
7
+ };
8
+ //# sourceMappingURL=preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.js","sources":["../../../src/lib/preload.ts"],"sourcesContent":["import { PreloadConfig } from './config-types';\nimport { sharedResourceManager } from './shared-resource-manager';\n\n/**\n * Preload the resources using the provided configuration. This function is used to preload the model\n * and the worker before creating the pipeline.\n *\n * @param config - The configuration object.\n */\nexport const preload = async (config: PreloadConfig) => {\n if (config.mask.generator === 'worker') {\n await sharedResourceManager.preloadWorker(config);\n } else {\n await sharedResourceManager.loadModel(config);\n }\n};\n"],"names":["preload","config","sharedResourceManager"],"mappings":";AASa,MAAAA,IAAU,OAAOC,MAA0B;AAChD,EAAAA,EAAO,KAAK,cAAc,WACpB,MAAAC,EAAsB,cAAcD,CAAM,IAE1C,MAAAC,EAAsB,UAAUD,CAAM;AAEpD;"}
@@ -1,7 +1,8 @@
1
- import { PipelineConfig } from '../config';
2
- import { FrameData, LadonOutput } from '../generator';
3
- import { LadonRenderer } from './ladon-renderer';
4
- import { WebGLRenderer } from './webgl-renderer';
1
+ import { PipelineConfig } from '../config-types';
2
+ import { FrameData, LadonOutput } from '../generator';
3
+ import { LadonRenderer } from './ladon-renderer';
4
+ import { WebGLRenderer } from './webgl-renderer';
5
+
5
6
  export declare class BlurRenderer extends WebGLRenderer implements LadonRenderer {
6
7
  output_canvas: HTMLCanvasElement;
7
8
  readonly config: PipelineConfig;