import { PipelineConfig } from './config-types'; import { FrameData } from './generator'; import { IFrameInferenceResult, IPipeline } from './pipeline-types'; /** * Core pipeline implementation for processing video frames with ML inference and rendering. * Handles frame processing, mask generation, and output rendering with proper timing controls. */ export declare class Pipeline implements IPipeline { private inputCanvas; private outputCanvas; readonly config: PipelineConfig; private readonly inputVideoElement; /** The mask generator responsible for ML inference. */ private generator?; /** The renderer responsible for compositing the final output. */ private renderer?; /** Flag indicating whether the pipeline has been fully loaded and initialized. */ private loaded; /** 2D rendering context for the input canvas used for frame processing. */ private inputCanvasContext; /** The most recent mask result from ML inference, used when skipping inference. */ private lastMaskResult?; /** Flag indicating whether a frame is currently being processed. */ private isProcessingFrame; /** Promise for the currently pending frame processing operation. */ private pendingFramePromise; /** Buffer for frame data copies to ensure they are not modified or garbage collected. */ private frameDataBuffer?; /** * Create a new pipeline instance. * * @param inputCanvas - Canvas element for input frame processing. * @param outputCanvas - Canvas element where the final rendered output will be displayed. * @param config - Pipeline configuration containing processing and rendering settings. * @param inputVideoElement - Video element serving as the input source. * @throws Error if the input canvas 2D context cannot be obtained. */ constructor(inputCanvas: HTMLCanvasElement, outputCanvas: HTMLCanvasElement, config: PipelineConfig, inputVideoElement: HTMLVideoElement); /** * Process a single frame and return the inference result. * This method handles frame data, performs inference if needed, and renders the output. * Includes frame processing serialization to prevent overlapping operations. * * @param timestamp - The timestamp of the frame in milliseconds. * @param performInference - Whether to perform mask inference or reuse the last result. * @param frameData - Optional frame data to process instead of capturing from input. * @returns Promise resolving to the frame processing result with timing statistics. * @throws Error if the pipeline (generator or renderer) is not loaded. */ onFrame(timestamp: number, performInference?: boolean, frameData?: FrameData): Promise; /** * Internal frame processing implementation. * Handles the actual frame processing logic including timing measurements. * * @param timestamp - The timestamp of the frame in milliseconds. * @param performInference - Whether to perform mask inference or reuse the last result. * @param frameData - Optional frame data to process instead of capturing from input. * @returns Promise resolving to the frame processing result with timing statistics. * @throws Error if the pipeline (generator or renderer) is not loaded. */ private processFrameInternal; /** * Get the raw image data from the input canvas context. * * @returns The frame data as a Uint8ClampedArray. */ private getInputFrameData; /** * Create a copy of frame data to prevent modifications during async operations. */ private createFrameDataCopy; /** * Resize the image data if the model expects a different input size. * Handles scaling between input dimensions and model requirements. * * @param rawImageData - The raw image data to potentially resize. * @returns The processed mask image data, resized if necessary. */ private getMaskImageData; /** * Create the inference result object with appropriate data. * Handles both successful inference results and fallback cases. * * @param timestamp - The timestamp of the frame in milliseconds. * @param performedInference - Whether inference was actually performed for this frame. * @returns The inference result object containing mask data and metadata. */ private createInferenceResult; /** * Check if the pipeline is fully loaded and ready for processing. * * @returns True if the pipeline is loaded and ready, false otherwise. */ isLoaded(): boolean; /** * Load and initialize the pipeline components. * Creates the appropriate renderer and generator based on configuration. * * @returns Promise that resolves when all components are loaded and ready. * @throws Error if an unsupported renderer type is specified in the configuration. */ load(): Promise; /** * Reset the pipeline state by clearing cached mask results. * Useful when switching between different processing modes or sources. */ reset(): void; /** * Destroy the pipeline and clean up all resources. * Properly disposes of the renderer and generator to prevent memory leaks. * * @returns Promise that resolves when cleanup is complete. */ destroy(): Promise; }