import { PipelineConfig, PreloadConfig, WorkerConfig } from './config-types'; import { WorkerGeneratedResult } from './generator-types'; /** * Worker manager class to handle the initialization and termination of the segmenation * web worker. This class is responsible for loading the worker script, resolving the * configuration, and managing the worker lifecycle. It also provides methods to * preload the worker and terminate it when no longer needed. */ export declare class WorkerManager { private worker?; private workerUrl?; private destroyPromise; private onInitializedCallbacks; private onGeneratedCallbacks; private onDroppedCallbacks; private onLogCallbacks; /** * Get the current worker instance. * * @returns The current worker instance or undefined if not initialized. */ getWorker(): Worker | undefined; /** * Initialize the worker using the provided configuration. * * @param config - The configuration object. * @returns A promise that resolves when the worker is initialized. */ initializeWorker(config: WorkerConfig): Promise; /** * Destroys the worker gracefully by sending a destroy message and waiting for confirmation. * * @returns A promise that resolves when the worker is destroyed. * If no worker is available, it resolves immediately. */ destroyWorker(): Promise; /** * Terminate the worker. */ terminateWorker(): void; /** * Preload the worker using the provided configuration. * * @param config - The configuration object. * @returns A promise that resolves when the worker is preloaded. */ preloadWorker(config: PreloadConfig): Promise; /** * Prepare the worker configuration by resolving the final URLs and paths to send to the * worker. This is necessary because we can't send functions to the worker. We also need to * remove the assetUrlResolver function from the configuration. * * @param config - The preload configuration. * @returns The worker configuration. */ prepareWorkerConfig(config: PreloadConfig): Promise; /** * Register a callback for when the worker is initialized. */ onInitialized(callback: () => void): void; /** * Register a callback for when the worker generates output. * * @param callback - The callback function to be called with the generated data. * @param data - The generated data from the worker. * @param data.mask - The generated mask. * @param data.facesAndLandmarks - The detected faces and landmarks. * @param data.gesture - The detected gesture. * @param data.motion - The detected motion. */ onGenerated(callback: (data: WorkerGeneratedResult) => void): void; /** * Register a callback for when the worker drops a frame. * This is useful for handling cases where the worker cannot keep up with the input frame rate. * The callback will be called with the timestamp of the dropped frame. * * @param callback - The callback function to be called with the timestamp of the dropped frame. */ onDropped(callback: (timestamp: number) => void): void; /** * Register a callback for log messages from the worker. * * @param callback - The callback function to be called with the log message and severity. * @param severity - The severity of the log message (e.g., 'info', 'warn', 'error'). */ onLog(callback: (message: string, severity: string) => void): void; /** * Send an init message to the worker. * * @param config - The configuration object to initialize the worker. * @param config.baseUrl - The base URL for loading assets. * @param config.input - The input configuration for the worker. * @param config.mask - The mask configuration for the worker. * @param config.wasmUri - The URI for the WebAssembly module. * @param config.workerUri - The URI for the worker script. * @param config.assetUrlResolver - The function to resolve asset URLs. */ sendInit(config: PipelineConfig): void; /** * Send a generate message to the worker. * * @param input - The input image data as a Uint8ClampedArray. * @param timestamp - The timestamp of the input image. */ sendGenerate(input: Uint8ClampedArray, timestamp: number): void; } export declare const workerManager: WorkerManager;