/** * Byte residency for a URL source: the bytes this process holds, the fetch that * serves them to the demuxer, and a background walk that fills the rest in. * * The browser HTTP cache does not do this job for media. A 200 response is * stored whole and read back in about a millisecond, but the demuxer never * issues one: it opens the file with `Range: bytes=N-` and abandons the * response once it has what it wanted, so every read is stored as sparse data * against a single cache entry. Sparse data is evicted long before a hundred * megabytes of it accumulates, and a whole-file fetch issued after the demuxer * has already touched the URL lands in that same sparse entry and is discarded * with it. Bytes held here are held for as long as this session wants them, * whatever the cache does. */ /** A held run of the source file, `end` exclusive. */ export interface ResidentRange { readonly start: number; readonly end: number; } export interface ResidencySnapshot { /** Held runs, ascending, never touching or overlapping. */ readonly ranges: readonly ResidentRange[]; readonly residentBytes: number; /** Source length once a response has disclosed it, else null. */ readonly totalBytes: number | null; /** Bytes the background walk has pulled, excluding what playback pulled. */ readonly prefetchedBytes: number; readonly warming: boolean; } export interface SourceResidencyOptions { readonly url: string; /** Ceiling on held bytes. Runs furthest from the focus offset are dropped first. */ readonly budgetBytes: number; /** Largest single background request. */ readonly chunkBytes?: number; readonly requestInit?: RequestInit; readonly fetchImpl?: typeof fetch; } export interface SourceResidency { /** Hand to mediabunny's `UrlSource` as its `fetchFn`. */ readonly fetchFn: typeof fetch; snapshot(): ResidencySnapshot; /** * Offset the background walk works outward from, so the bytes nearest the * playhead arrive first and a viewer who seeks nearby stops waiting soonest. */ focusAt(offset: number): void; startWarming(): void; stopWarming(): void; dispose(): void; } /** Granularity at which a streaming read is banked. Mediabunny never asks * the network for less than half a mebibyte, so every read it makes banks * at least one block. */ export declare const READ_BLOCK_BYTES: number; /** How long a delivered chunk may sit unclaimed before the walk stops deferring * to the read that produced it. It measures the gap between a chunk and the * consumer's next pull, not the wait for the server, so a slow link reads as * a live read while a reader that walked away frees the link. */ export declare const FOREGROUND_STALL_MS = 250; /** * Bytes held in one buffer per contiguous run, so a lookup is a single scan and * a served range is a subarray with nothing copied. Insert is where copying * happens: a run keeps spare capacity so an append that extends it writes into * that room, and only a backward or overlapping insert re-materializes the run. */ export declare class ByteStore { #private; get residentBytes(): number; /** Bytes retained by backing arrays, including append headroom. */ get allocatedBytes(): number; ranges(): ResidentRange[]; /** The held run from `offset` to the end of its run, or null. */ runAt(offset: number): Uint8Array | null; /** Where the gap containing `offset` ends, or null when nothing is held past it. */ nextHeldStart(offset: number): number | null; insert(start: number, bytes: Uint8Array): void; /** * Brings held bytes under the budget: whole runs go first, furthest from * `focus`, and a lone run that has outgrown the budget is narrowed to a * `budgetBytes` window at `focus`. */ evictTo(budgetBytes: number, focus: number): void; clear(): void; } /** * Outstanding claims on the link, for this module's own tests: they drive every * way a read can end and assert the count comes back to zero. */ export declare function outstandingForegroundHolds(residency: SourceResidency): number; export declare function createSourceResidency(options: SourceResidencyOptions): SourceResidency;