import type { DepthMap } from "supervision-js-core"; import type { DepthPreviewDecodeOptions, DepthPreviewDecodeRun, DepthPreviewLumaFrame } from "#media/depth-preview-track"; import { type RenderPreparationArtifactDiagnostics, type ResolvedRenderPreparationGateThresholds } from "#types/render-preparation"; /** One pass over a frame source, from where it was started forward. */ export interface DepthFrameRun { /** The next frame, or null once the source has ended or the run was cancelled. */ next(): Promise; cancel(): void; } /** * A video track decodes from a key frame forward; a source with * `randomAccess` starts a run at any frame and skips the frames `keep` * turns away at no cost, so one run serves every frame ahead of it. */ export interface DepthFrameSource { readonly frameCount: number; readonly randomAccess?: boolean; keyIndexAtOrBefore(index: number): number; decode(fromIndex: number, options: DepthPreviewDecodeOptions): DepthFrameRun | DepthPreviewDecodeRun; } export interface DepthWindowEntry { readonly index: number; readonly map: DepthMap; readonly bytes: number; } export interface DepthFrameWindowOptions { readonly frames: DepthFrameSource; /** Start of frame `index` on the media timeline, in seconds. */ readonly timeAt: (index: number) => number; /** End of frame `index` on the media timeline, in seconds. */ readonly endAt: (index: number) => number; readonly createMap: (frame: Frame) => DepthMap; /** * Bytes one decoded frame is expected to hold; sets how many frames fit in * `maxBytes`. */ readonly frameBytes: number; /** * For frames that differ in size. Defaults to the frame's `luma` length, * then `frameBytes`. */ readonly bytesOf?: (frame: Frame) => number; /** Names the frames in errors and warnings. Defaults to "preview". */ readonly precision?: "exact" | "preview"; /** What playback draws once the window stops, for its stop message. */ readonly stillDrawn: () => string; /** Budget for decoded frames, in bytes. */ readonly maxBytes: number; /** * How far ahead of the playhead to decode while playing, in seconds of * media; a drag spends the same span both ways. */ readonly prefetchSeconds: number; /** How much behind the playhead to keep, in seconds of media. */ readonly retainSeconds: number; /** * Frames a resting playhead keeps decoded ahead, its own included, so a * step forward lands on a decoded frame. */ readonly pausedFrameCount: number; readonly loop?: boolean; /** A frame was decoded and kept. */ readonly onFrame?: (index: number) => void; /** What the window holds or waits for changed. */ readonly onChange?: () => void; } export interface DepthFrameWindow { getEntry(index: number): DepthWindowEntry | null; /** * The playhead moved to `index`: decoding follows it, and its moves give * the heading and, while playing, how many frames each present moves. */ setPlayhead(index: number): void; /** * Whether playback runs or a drag moves the playhead. A resting playhead * keeps only a small margin decoded ahead of it. */ setPlaybackActive(active: boolean): void; /** * Whether a drag holds the playhead. A slow drag forward moves it the way * playback does; this is what tells the two apart. */ setScrubbing(scrubbing: boolean): void; setLoop(loop: boolean): void; /** A hidden page decodes nothing and starts no run until it is shown. */ setHidden(hidden: boolean): void; /** Which way the playhead travels: 1, -1, or 0 without enough to say. */ heading(): -1 | 0 | 1; /** * Seconds of decoded frames from the start of `index` onward that the * next presents land on, without a gap; Infinity once that run reaches * the last frame of a clip that does not loop. */ leadSeconds(index: number): number; needsPlaybackGateWait(index: number, thresholds: ResolvedRenderPreparationGateThresholds): boolean; waitForReady(index: number, thresholds: ResolvedRenderPreparationGateThresholds, signal?: AbortSignal): Promise; /** Frames decoded and kept, counted up across the window's life. */ getPreparationProgress(): number; /** * Decoded entries for `count` frames in a row from `skip` frames after * `index`, nearest first, stopping at the first one not decoded. */ upcoming(index: number, count: number, skip?: number): DepthWindowEntry[]; getDiagnostics(): RenderPreparationArtifactDiagnostics; /** * The most lead the window decodes ahead of `index` while playing, in * seconds of media; Infinity where that reaches the end of a clip that * does not loop. */ wantedLeadSeconds(index: number): number; /** The decoder failed; the window stops waiting and decoding. */ readonly failure: unknown; /** Why the window stopped and what playback draws now, or null. */ readonly stopMessage: string | null; destroy(): void; } /** * Decoded depth frames around the playhead, by frame index. * * One decode run is active at a time; it starts at the frame it is for, or * at the key frame before it on a source without random access. What the * window wants decoded follows how the playhead moves: * * - Playing, it leads the playhead by `prefetchSeconds` times how many frames * presents move, wrapping at the last frame when the clip loops. Once every * recent present has moved the same number of frames, it keeps only the * frames presents land on. * - Dragged, it spends `prefetchSeconds` both ways, most of it the way the * playhead heads. Dragged backwards, a run from a key frame keeps every * frame up to the playhead, so the frames the hand reaches next are there. * - Resting, it keeps a small margin ahead; stepping backwards fills behind. * * A frame the playback gate waits on is decoded before anything else. When * the budget is short, frames the window no longer wants go first, then the * ones farthest the other way from where the playhead heads. The frame at the * playhead and the ones the gate waits on or just let through stay, over the * budget if they must. */ export declare function createDepthFrameWindow(options: DepthFrameWindowOptions): DepthFrameWindow; //# sourceMappingURL=frame-window.d.ts.map