UNPKG

z-web-audio-stream

Version:

iOS Safari-safe Web Audio streaming with separated download/storage optimization, instant playback, and memory management

107 lines 3.14 kB
import { DownloadChunk } from './DownloadManager.js'; export interface AssemblyChunk { id: string; storageIndex: number; downloadChunks: DownloadChunk[]; totalSize: number; data: ArrayBuffer; assemblyTime: number; canStartPlayback: boolean; } export interface StreamingAssemblerOptions { storageChunkSize: number; playbackChunkSize: number; onChunkAssembled?: (chunk: AssemblyChunk) => void; onPlaybackReady?: (firstChunk: AssemblyChunk) => void; onProgress?: (assembled: number, total: number) => void; } /** * Streaming assembler that converts network-optimized download chunks * into storage-optimized chunks and playback-ready buffers * * Key features: * - Assembles small download chunks (64KB-512KB) into larger storage chunks (1-3MB) * - Creates optimal first chunk for instant playback (256-384KB) * - Streams assembly - doesn't wait for all downloads to complete * - Memory efficient - releases download chunks after assembly * - iOS Safari optimized chunk sizes */ export declare class StreamingAssembler { private options; private downloadChunks; private assembledChunks; private totalExpectedSize; private isPlaybackReady; private nextStorageIndex; private currentAssemblyBuffer; private currentAssemblySize; private currentDownloadChunks; constructor(options: StreamingAssemblerOptions); /** * Initialize assembly for a specific total file size */ initialize(totalSize: number): void; /** * Add a downloaded chunk for assembly */ addDownloadChunk(chunk: DownloadChunk): void; /** * Process all available sequential chunks */ private processAvailableChunks; /** * Get the next sequential download chunk index we're waiting for */ private getNextSequentialIndex; /** * Process a single download chunk into the assembly buffer */ private processDownloadChunk; /** * Check if current assembly should be completed */ private checkForAssemblyCompletion; /** * Determine if current assembly should be completed */ private shouldCompleteCurrentAssembly; /** * Check if this is the last assembly chunk */ private isLastAssemblyChunk; /** * Complete the current assembly and create an AssemblyChunk */ private completeCurrentAssembly; /** * Report assembly progress */ private reportProgress; /** * Force completion of any pending assembly */ finalize(): void; /** * Get all assembled chunks in order */ getAssembledChunks(): AssemblyChunk[]; /** * Get first chunk for immediate playback */ getFirstChunk(): AssemblyChunk | null; /** * Get assembly statistics */ getStats(): { assembledChunks: number; totalAssembledSize: number; pendingDownloadChunks: number; isPlaybackReady: boolean; assemblyProgress: number; }; /** * Clear all data to free memory */ cleanup(): void; } //# sourceMappingURL=StreamingAssembler.d.ts.map