import { PipelineConfig } from '../config-types'; import { FrameData, LadonOutput } from '../generator'; import { LadonRenderer } from './ladon-renderer'; import { WebGLRenderer } from './webgl-renderer'; /** * WebGL renderer implementation for virtual background replacement effects. * Handles rendering of video backgrounds with proper frame rate throttling. */ export declare class ReplacementRenderer extends WebGLRenderer implements LadonRenderer { outputCanvas: HTMLCanvasElement; readonly config: PipelineConfig; /** The compiled WebGL shader program used for rendering. */ private program; /** Timestamp of the last video frame update in milliseconds. */ private lastVideoFrameTime; /** Interval between video frame updates in milliseconds. */ private videoFrameInterval; /** WebGL texture containing the background image or video frame. */ protected backgroundTexture: WebGLTexture; /** Fragment shader source code for the replacement effect. */ protected fragmentShader: string; /** * Create a new replacement renderer instance. * * @param outputCanvas - The canvas element where the rendered output will be displayed. * @param config - Pipeline configuration containing render settings and background source. */ constructor(outputCanvas: HTMLCanvasElement, config: PipelineConfig); /** * Build the fragment shader source code for the replacement effect. * Creates a shader that blends the background with the input video based on the mask. * * @returns The complete fragment shader source code. */ protected buildFragmentShader(): string; /** * Set up the WebGL texture for the background image or video. * Creates and configures the texture that will be used as the replacement background. */ protected setupBackgroundTexture(): void; /** * Render a frame with the replacement background effect. * Combines the input video stream with the background based on the provided mask. * Includes frame rate throttling for video backgrounds to prevent stuttering. * Canvas backgrounds are updated every frame to support dynamic content. * * @param input - The input frame data (video element or image data). * @param mask - Optional mask data for determining foreground/background blend. * @returns Promise that resolves when rendering is complete. */ render(input: FrameData, mask?: LadonOutput): Promise; /** * Throttle video background updates and upload texture only when needed. * This prevents stuttering and unnecessary GPU uploads when inference is skipped. * * @param backgroundSource - The video element to potentially upload. * @returns Promise that resolves after appropriate throttling and upload. */ private updateVideoBackgroundTexture; /** * Attempt to determine the frame rate of a video element. * Tries to extract frame rate from video track settings if available. * * @param video - The video element to analyze. * @returns The video's frame rate in frames per second, or undefined if not determinable. */ private getVideoFrameRate; /** * Load and initialize the renderer. * Currently a no-op for this renderer implementation. * * @returns Promise that resolves when loading is complete. */ load(): Promise; /** * Clean up resources and destroy the renderer. * Currently a no-op for this renderer implementation. */ destroy(): void; }