fluxkit-player 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +21 -0
  3. package/README.md +440 -2
  4. package/dist/fluxkit.js +3963 -0
  5. package/dist/fluxkit.js.map +1 -0
  6. package/dist/fluxkit.umd.cjs +22 -0
  7. package/dist/fluxkit.umd.cjs.map +1 -0
  8. package/dist/types/codec/aac.d.ts +19 -0
  9. package/dist/types/codec/bit.d.ts +15 -0
  10. package/dist/types/codec/config.d.ts +19 -0
  11. package/dist/types/codec/g711.d.ts +4 -0
  12. package/dist/types/codec/h264.d.ts +37 -0
  13. package/dist/types/codec/h265.d.ts +27 -0
  14. package/dist/types/config.d.ts +46 -0
  15. package/dist/types/demux/flv.d.ts +46 -0
  16. package/dist/types/demux/hls.d.ts +54 -0
  17. package/dist/types/demux/mp4.d.ts +45 -0
  18. package/dist/types/demux/ts.d.ts +41 -0
  19. package/dist/types/index.d.ts +31 -0
  20. package/dist/types/io/http.d.ts +32 -0
  21. package/dist/types/io/websocket.d.ts +27 -0
  22. package/dist/types/pipeline/segmenter.d.ts +16 -0
  23. package/dist/types/pipeline/timeline.d.ts +11 -0
  24. package/dist/types/player.d.ts +110 -0
  25. package/dist/types/protocol/amf0.d.ts +12 -0
  26. package/dist/types/remux/fmp4.d.ts +32 -0
  27. package/dist/types/render/audio.d.ts +48 -0
  28. package/dist/types/render/mse.d.ts +49 -0
  29. package/dist/types/render/software.d.ts +77 -0
  30. package/dist/types/render/webcodecs.d.ts +69 -0
  31. package/dist/types/soft/h264bsd.d.ts +23 -0
  32. package/dist/types/soft/index.d.ts +9 -0
  33. package/dist/types/soft/libde265.d.ts +16 -0
  34. package/dist/types/soft/types.d.ts +37 -0
  35. package/dist/types/source/hls.d.ts +29 -0
  36. package/dist/types/source/stream.d.ts +22 -0
  37. package/dist/types/types.d.ts +246 -0
  38. package/dist/types/utils/async.d.ts +12 -0
  39. package/dist/types/utils/buffer.d.ts +17 -0
  40. package/dist/types/utils/bytes.d.ts +62 -0
  41. package/dist/types/utils/events.d.ts +10 -0
  42. package/dist/types/utils/log.d.ts +14 -0
  43. package/package.json +77 -4
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Shared audio output.
3
+ *
4
+ * AAC goes through WebCodecs `AudioDecoder`; G.711 (A-law/μ-law) is decoded in
5
+ * JS because MSE cannot mux it and browser support for the WebCodecs G.711
6
+ * codecs is inconsistent. Both paths are scheduled through Web Audio.
7
+ *
8
+ * Two clock modes:
9
+ * - internal (default): audio is the master clock (used by WebCodecs/soft video)
10
+ * - external: schedule against another clock (the MSE <video>), so a G.711
11
+ * audio side channel stays in sync with an MSE video track
12
+ */
13
+ import type { AudioTrack, Sample } from '../types';
14
+ export interface AudioOutputOptions {
15
+ volume: number;
16
+ onError?: (err: Error) => void;
17
+ }
18
+ export declare class AudioOutput {
19
+ private readonly options;
20
+ private decoder;
21
+ private track;
22
+ private manualLaw;
23
+ private ctx;
24
+ private gain;
25
+ private anchorMedia;
26
+ private anchorCtx;
27
+ private anchored;
28
+ private volume;
29
+ private destroyed;
30
+ private clockSource;
31
+ decodedFrames: number;
32
+ constructor(options: AudioOutputOptions);
33
+ get configured(): boolean;
34
+ configure(track: AudioTrack): void;
35
+ write(samples: Sample[]): void;
36
+ private writeManual;
37
+ /** Media time in seconds from the active clock, or null before playback. */
38
+ get clock(): number | null;
39
+ setClockSource(source: (() => number | null) | null): void;
40
+ private ensureAudioContext;
41
+ private onData;
42
+ private schedule;
43
+ resume(): Promise<void> | void;
44
+ setPaused(paused: boolean): void;
45
+ setVolume(volume: number): void;
46
+ reset(): void;
47
+ destroy(): void;
48
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * MSE renderer: builds fMP4 fragments and appends them to SourceBuffers.
3
+ * The browser's media pipeline performs hardware decoding.
4
+ */
5
+ import type { Renderer, RendererStats, Sample, Track } from '../types';
6
+ export interface MseOptions {
7
+ live: boolean;
8
+ liveBufferTarget: number;
9
+ onError?: (err: Error) => void;
10
+ }
11
+ export declare class MseRenderer implements Renderer {
12
+ private readonly video;
13
+ private readonly options;
14
+ readonly mode: "mse";
15
+ private mediaSource;
16
+ private objectUrl;
17
+ private sourceOpen;
18
+ private readonly buffers;
19
+ private readonly queues;
20
+ private readonly muxers;
21
+ private readonly attached;
22
+ private readonly trackList;
23
+ private readonly fallbackTracks;
24
+ private fallbackAudio;
25
+ private endPending;
26
+ private destroyed;
27
+ constructor(video: HTMLVideoElement, options: MseOptions);
28
+ get stats(): RendererStats;
29
+ attach(tracks: Track[]): Promise<void>;
30
+ private ensureFallbackAudio;
31
+ private initMediaSource;
32
+ private addTrack;
33
+ write(track: Track, samples: Sample[]): void;
34
+ private enqueue;
35
+ private pump;
36
+ private nothingBuffering;
37
+ /** Drop media far behind the playhead so long VODs don't hit the quota. */
38
+ trimOld(keepBehindSeconds?: number): void;
39
+ private trimBuffer;
40
+ endOfStream(): void;
41
+ flush(): void;
42
+ reset(): void;
43
+ setVolume(volume: number): void;
44
+ resumeAudio(): Promise<void> | void;
45
+ setPaused(paused: boolean): void;
46
+ destroy(): void;
47
+ /** Seconds buffered ahead of the playhead. */
48
+ get bufferAhead(): number;
49
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * WASM software renderer.
3
+ *
4
+ * Decodes H.265 (libde265) or Baseline H.264 (h264bsd) on the CPU, converts
5
+ * YUV420 to RGB on the GPU (WebGL) and presents frames against the audio clock.
6
+ * This is the last-resort path for browsers without a platform HEVC decoder.
7
+ */
8
+ import type { Renderer, RendererStats, Sample, Track } from '../types';
9
+ import { FluxKitError } from '../types';
10
+ import type { SoftLoaders } from '../soft';
11
+ export interface SoftwareOptions {
12
+ fit: 'contain' | 'cover' | 'fill';
13
+ volume: number;
14
+ maxDecodeAhead: number;
15
+ dropLateFrames: boolean;
16
+ loaders?: SoftLoaders;
17
+ onError?: (err: Error) => void;
18
+ onFirstFrame?: (width: number, height: number) => void;
19
+ }
20
+ export declare class SoftwareRenderer implements Renderer {
21
+ private readonly options;
22
+ readonly mode: "software";
23
+ private decoder;
24
+ private videoTrack;
25
+ private readonly audio;
26
+ private readonly canvas;
27
+ private backlog;
28
+ private present;
29
+ private decoding;
30
+ private rafId;
31
+ private timer;
32
+ private paused;
33
+ private anchored;
34
+ private anchorMedia;
35
+ private anchorWall;
36
+ private decoded;
37
+ private dropped;
38
+ private firstFrameReported;
39
+ private destroyed;
40
+ private ended;
41
+ private gl;
42
+ private glFailed;
43
+ private ctx2d;
44
+ private tmpCanvas;
45
+ private tmpCtx;
46
+ private imageData;
47
+ private resizeObserver;
48
+ constructor(options: SoftwareOptions, canvas: HTMLCanvasElement);
49
+ get stats(): RendererStats;
50
+ get currentTime(): number;
51
+ get framesPending(): number;
52
+ get backlogSeconds(): number;
53
+ get decoderName(): string;
54
+ attach(tracks: Track[]): Promise<void>;
55
+ write(track: Track, samples: Sample[]): void;
56
+ private scheduleDecode;
57
+ private decodeStep;
58
+ private mediaTime;
59
+ private startRaf;
60
+ private tick;
61
+ private resize;
62
+ private observeResize;
63
+ private render;
64
+ private initGl;
65
+ private uploadPlane;
66
+ private renderGl;
67
+ private render2d;
68
+ setPaused(paused: boolean): void;
69
+ resumeAudio(): Promise<void> | void;
70
+ setVolume(volume: number): void;
71
+ flush(): void;
72
+ endOfStream(): void;
73
+ reset(): void;
74
+ destroy(): void;
75
+ }
76
+ /** For callers that want to distinguish "no decoder" from a runtime error. */
77
+ export declare function softwareDecoderError(err: unknown): FluxKitError;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * WebCodecs renderer.
3
+ *
4
+ * Decodes H.264 / H.265 with `VideoDecoder` (hardware accelerated when the
5
+ * browser agrees) and AAC with `AudioDecoder`, presenting video to a canvas
6
+ * and audio through Web Audio. This path exists because MSE does not expose
7
+ * HEVC everywhere (notably Chrome on Linux/Windows without the codec pack),
8
+ * while WebCodecs often can still use the platform decoder.
9
+ */
10
+ import type { Renderer, RendererStats, Sample, Track } from '../types';
11
+ export interface WebCodecsOptions {
12
+ hardwareAcceleration: 'no-preference' | 'prefer-hardware' | 'prefer-software';
13
+ fit: 'contain' | 'cover' | 'fill';
14
+ volume: number;
15
+ onError?: (err: Error) => void;
16
+ onFirstFrame?: (width: number, height: number) => void;
17
+ }
18
+ export declare function isWebCodecsSupported(): boolean;
19
+ export declare class WebCodecsRenderer implements Renderer {
20
+ private readonly options;
21
+ readonly mode: "webcodecs";
22
+ private videoDecoder;
23
+ private readonly audio;
24
+ private canvas;
25
+ private ctx;
26
+ private frames;
27
+ private videoBacklog;
28
+ private rafId;
29
+ private paused;
30
+ private anchored;
31
+ private anchorWall;
32
+ private anchorMedia;
33
+ private decodedVideo;
34
+ private droppedVideo;
35
+ private hardware;
36
+ private firstFrameReported;
37
+ private destroyed;
38
+ constructor(options: WebCodecsOptions, canvas?: HTMLCanvasElement);
39
+ get stats(): RendererStats;
40
+ /** Presentation time in seconds (0 until the first frame is anchored). */
41
+ get currentTime(): number;
42
+ get framesPending(): number;
43
+ get acceleration(): 'preferred' | 'software' | 'unknown';
44
+ get element(): HTMLCanvasElement;
45
+ attach(tracks: Track[]): Promise<void>;
46
+ private configureVideo;
47
+ write(track: Track, samples: Sample[]): void;
48
+ private writeVideo;
49
+ /**
50
+ * Feed the decoder only a few frames ahead of the presentation clock.
51
+ * Without this a fast VOD downloads minutes of frames into the queue and
52
+ * either explodes memory or drops half a GOP (which breaks references).
53
+ */
54
+ private pumpVideo;
55
+ /** Seconds of compressed video queued ahead of the playhead. */
56
+ get backlogSeconds(): number;
57
+ private onFrame;
58
+ private mediaTime;
59
+ private startRaf;
60
+ private tick;
61
+ private render;
62
+ setPaused(paused: boolean): void;
63
+ resumeAudio(): Promise<void> | void;
64
+ setVolume(volume: number): void;
65
+ flush(): void;
66
+ endOfStream(): void;
67
+ reset(): void;
68
+ destroy(): void;
69
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * H.264 software decoding through h264bsd compiled to WebAssembly.
3
+ *
4
+ * h264bsd is a Baseline-profile decoder only; High/Main streams are rejected
5
+ * with a clear error so the player can fall back to native playback instead of
6
+ * showing corrupted frames.
7
+ */
8
+ import type { VideoTrack } from '../types';
9
+ import type { SoftFrame, SoftVideoDecoder } from './types';
10
+ export declare class H264BsdDecoder implements SoftVideoDecoder {
11
+ readonly name = "h264bsd";
12
+ private module;
13
+ private decoder;
14
+ private parameterSets;
15
+ private picId;
16
+ private readonly ptsById;
17
+ configure(track: VideoTrack): Promise<void>;
18
+ init(loader: () => Promise<unknown>): Promise<void>;
19
+ decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[];
20
+ flush(): SoftFrame[];
21
+ private toFrame;
22
+ close(): void;
23
+ }
@@ -0,0 +1,9 @@
1
+ /** WASM software decoder factory (H.265 via libde265, H.264 via h264bsd). */
2
+ import type { VideoTrack } from '../types';
3
+ import type { SoftModuleLoader, SoftVideoDecoder } from './types';
4
+ export interface SoftLoaders {
5
+ avc?: SoftModuleLoader;
6
+ hevc?: SoftModuleLoader;
7
+ }
8
+ export declare function createSoftwareDecoder(track: VideoTrack, loaders?: SoftLoaders): Promise<SoftVideoDecoder>;
9
+ export type { SoftFrame, SoftPlane, SoftVideoDecoder } from './types';
@@ -0,0 +1,16 @@
1
+ /** H.265 software decoding through libde265 compiled to WebAssembly. */
2
+ import type { VideoTrack } from '../types';
3
+ import type { SoftFrame, SoftVideoDecoder } from './types';
4
+ export declare class Libde265Decoder implements SoftVideoDecoder {
5
+ readonly name = "libde265";
6
+ private module;
7
+ private decoder;
8
+ private parameterSets;
9
+ configure(track: VideoTrack): Promise<void>;
10
+ /** Must be called once the module factory is available. */
11
+ init(loader: () => Promise<unknown>): Promise<void>;
12
+ decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[];
13
+ flush(): SoftFrame[];
14
+ private drain;
15
+ close(): void;
16
+ }
@@ -0,0 +1,37 @@
1
+ /** Shared types for the WASM software decoding backends. */
2
+ import type { VideoTrack } from '../types';
3
+ export interface SoftPlane {
4
+ bytes: Uint8Array;
5
+ width: number;
6
+ height: number;
7
+ stride: number;
8
+ }
9
+ export interface SoftFrame {
10
+ /** Presentation timestamp in microseconds. */
11
+ ptsUs: number;
12
+ /** Luma plane size (the texture coordinate space). */
13
+ width: number;
14
+ height: number;
15
+ /** Visible area inside the luma plane. */
16
+ crop: {
17
+ left: number;
18
+ top: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+ y: SoftPlane;
23
+ u: SoftPlane;
24
+ v: SoftPlane;
25
+ }
26
+ export interface SoftVideoDecoder {
27
+ readonly name: string;
28
+ /** Read stream configuration (SPS/PPS/VPS) from the track. */
29
+ configure(track: VideoTrack): Promise<void>;
30
+ /** Load the WebAssembly module and create the decoder instance. */
31
+ init(loader: SoftModuleLoader): Promise<void>;
32
+ /** `annexB` is one complete access unit (start codes included). */
33
+ decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[];
34
+ flush(): SoftFrame[];
35
+ close(): void;
36
+ }
37
+ export type SoftModuleLoader = () => Promise<unknown>;
@@ -0,0 +1,29 @@
1
+ /** HLS source: playlist parsing, segment loading, TS/fMP4 demuxing. */
2
+ import type { MediaSourceLike, SourceContext } from '../types';
3
+ import type { ResolvedOptions } from '../config';
4
+ export declare class HlsSource implements MediaSourceLike {
5
+ private readonly url;
6
+ private readonly options;
7
+ private readonly ctx;
8
+ private readonly startMs;
9
+ readonly protocol: "hls";
10
+ private tracks;
11
+ private stopped;
12
+ private _live;
13
+ private mediaDuration;
14
+ private audioOnly;
15
+ constructor(url: string, options: ResolvedOptions, ctx: SourceContext, startMs?: number);
16
+ get duration(): number;
17
+ get live(): boolean;
18
+ start(): Promise<void>;
19
+ private createTrack;
20
+ private runLoop;
21
+ private fetchSegment;
22
+ private reload;
23
+ /** VOD: don't read the whole file into memory ahead of playback. */
24
+ private waitForDemand;
25
+ private paceLive;
26
+ /** True when the chosen variant carries no video (audio-only radio stream). */
27
+ get isAudioOnly(): boolean;
28
+ stop(): void;
29
+ }
@@ -0,0 +1,22 @@
1
+ /** Plain container-over-HTTP/WS source: FLV, WS-FLV, MP4, HTTP-FMP4. */
2
+ import type { MediaSourceLike, Protocol, SourceContext } from '../types';
3
+ import type { ResolvedOptions } from '../config';
4
+ export declare class StreamSource implements MediaSourceLike {
5
+ private readonly url;
6
+ private readonly options;
7
+ private readonly ctx;
8
+ readonly protocol: Protocol;
9
+ private readonly demuxer;
10
+ private readonly http;
11
+ private ws;
12
+ private readonly _live;
13
+ constructor(protocol: Protocol, url: string, options: ResolvedOptions, ctx: SourceContext, live?: boolean);
14
+ get live(): boolean;
15
+ get duration(): number | undefined;
16
+ start(): Promise<void>;
17
+ /** Content-Type can contradict the file extension; fix it before parsing. */
18
+ private sniff;
19
+ pause(): void;
20
+ resume(): void;
21
+ stop(): void;
22
+ }
@@ -0,0 +1,246 @@
1
+ /**
2
+ * FluxKit — public types.
3
+ */
4
+ /** Container / transport that FluxKit knows how to read. */
5
+ export type Protocol = 'flv' | 'ws-flv' | 'mp4' | 'fmp4' | 'hls' | 'native';
6
+ /** How compressed frames are turned into pictures. */
7
+ export type DecoderMode = 'auto' | 'mse' | 'webcodecs' | 'software' | 'native';
8
+ export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
9
+ export interface VideoTrack {
10
+ kind: 'video';
11
+ /** MP4 track id (1-based). */
12
+ id: number;
13
+ codec: 'avc' | 'hevc';
14
+ /** Ticks per second for this track's dts/pts. */
15
+ timescale: number;
16
+ width: number;
17
+ height: number;
18
+ fps?: number;
19
+ /** avcC / hvcC decoder configuration record. */
20
+ codecPrivate: Uint8Array;
21
+ profile?: number;
22
+ level?: number;
23
+ }
24
+ export interface AudioTrack {
25
+ kind: 'audio';
26
+ id: number;
27
+ codec: 'aac' | 'mp3' | 'opus' | 'g711a' | 'g711u';
28
+ timescale: number;
29
+ sampleRate: number;
30
+ channels: number;
31
+ /** AudioSpecificConfig for AAC. */
32
+ codecPrivate?: Uint8Array;
33
+ }
34
+ export type Track = VideoTrack | AudioTrack;
35
+ /**
36
+ * One coded access unit.
37
+ *
38
+ * Video `data` is always in AVCC form (4-byte big-endian NAL length prefixes),
39
+ * regardless of the container it came from.
40
+ */
41
+ export interface Sample {
42
+ trackId: number;
43
+ kind: 'video' | 'audio';
44
+ dts: number;
45
+ pts: number;
46
+ duration: number;
47
+ keyframe: boolean;
48
+ data: Uint8Array;
49
+ }
50
+ export interface DemuxerSink {
51
+ onTracks(tracks: Track[]): void;
52
+ onSample(sample: Sample): void;
53
+ onError?(err: Error): void;
54
+ }
55
+ export interface Demuxer {
56
+ readonly format: string;
57
+ /** Feed bytes. `position` is the absolute byte offset of `chunk[0]` when known. */
58
+ push(chunk: Uint8Array, position?: number): void;
59
+ /** Signal end of input; flush any buffered access units. */
60
+ flush(): void;
61
+ reset(): void;
62
+ }
63
+ export interface SourceContext {
64
+ onTracks(tracks: Track[]): void;
65
+ onSample(sample: Sample): void;
66
+ onEnd(): void;
67
+ onError(err: Error): void;
68
+ /** Seconds of media already buffered ahead of the playhead (used to pace HLS). */
69
+ getBufferAhead?: () => number;
70
+ getCurrentTime?: () => number;
71
+ /** Bytes received, for the stats overlay. */
72
+ onBytes?: (bytes: number) => void;
73
+ }
74
+ export interface MediaSourceLike {
75
+ readonly protocol: Protocol;
76
+ start(): Promise<void>;
77
+ stop(): void;
78
+ seek?(ms: number): Promise<void>;
79
+ /** Stop reading from the network (backpressure); optional. */
80
+ pause?(): void;
81
+ resume?(): void;
82
+ readonly live: boolean;
83
+ readonly duration?: number;
84
+ }
85
+ export interface RendererStats {
86
+ decodedVideoFrames: number;
87
+ droppedVideoFrames: number;
88
+ decodedAudioFrames: number;
89
+ }
90
+ export interface Renderer {
91
+ readonly mode: 'mse' | 'webcodecs' | 'software' | 'native';
92
+ attach(tracks: Track[]): Promise<void>;
93
+ /** `samples` are sorted by dts and share a timeline. */
94
+ write(track: Track, samples: Sample[]): void;
95
+ flush(): void;
96
+ reset(): void;
97
+ destroy(): void;
98
+ endOfStream?(): void;
99
+ resumeAudio?(): Promise<void> | void;
100
+ setVolume?(volume: number): void;
101
+ setPaused?(paused: boolean): void;
102
+ readonly stats: RendererStats;
103
+ }
104
+ export interface PlayerStats {
105
+ /** Bytes received from the network since load(). */
106
+ bytesReceived: number;
107
+ /** Instantaneous bitrate in bits/second (1s window). */
108
+ kbps: number;
109
+ /** Protocol in use. */
110
+ protocol: Protocol;
111
+ /** 'mse' | 'webcodecs' | 'native'. */
112
+ decoder: string;
113
+ /** Whether the active video decoder prefers hardware acceleration. */
114
+ hardwareAcceleration: 'preferred' | 'software' | 'unknown';
115
+ videoCodec?: string;
116
+ audioCodec?: string;
117
+ width?: number;
118
+ height?: number;
119
+ /** Frames per second currently being rendered. */
120
+ fps: number;
121
+ decodedVideoFrames: number;
122
+ droppedVideoFrames: number;
123
+ decodedAudioFrames: number;
124
+ /** Seconds of media buffered ahead of the playhead. */
125
+ bufferAhead: number;
126
+ /** Live latency estimate in seconds (buffer end - currentTime). */
127
+ latency: number;
128
+ live: boolean;
129
+ droppedAudioFrames: number;
130
+ }
131
+ export declare class FluxKitError extends Error {
132
+ readonly code: string;
133
+ readonly detail?: unknown;
134
+ constructor(code: string, message: string, detail?: unknown);
135
+ }
136
+ export interface PlayerEvents {
137
+ /** Tracks discovered and renderer attached. Playback can start. */
138
+ ready: {
139
+ tracks: Track[];
140
+ protocol: Protocol;
141
+ decoder: string;
142
+ };
143
+ /** First frames rendered. */
144
+ loaded: {
145
+ width: number;
146
+ height: number;
147
+ };
148
+ metadata: {
149
+ width: number;
150
+ height: number;
151
+ duration?: number;
152
+ live: boolean;
153
+ };
154
+ stats: PlayerStats;
155
+ error: FluxKitError | Error;
156
+ ended: void;
157
+ seeked: {
158
+ time: number;
159
+ };
160
+ play: void;
161
+ pause: void;
162
+ log: {
163
+ level: string;
164
+ message: string;
165
+ };
166
+ }
167
+ export interface LoggerLike {
168
+ (level: 'error' | 'warn' | 'info' | 'debug', message: string, ...args: unknown[]): void;
169
+ }
170
+ export interface RetryOptions {
171
+ /** Max reconnect attempts, 0 disables reconnecting. */
172
+ maxRetries: number;
173
+ /** Base delay in ms, doubled on each attempt. */
174
+ delay: number;
175
+ maxDelay: number;
176
+ }
177
+ export interface FluxKitOptions {
178
+ /** Force a decoder. Default 'auto'. */
179
+ decoder?: DecoderMode;
180
+ /** Force a protocol instead of sniffing the URL. */
181
+ protocol?: Protocol | 'auto';
182
+ /** Autoplay after the first frames arrive. */
183
+ autoplay?: boolean;
184
+ /** Start muted (required for most autoplay policies). */
185
+ muted?: boolean;
186
+ loop?: boolean;
187
+ volume?: number;
188
+ /** 'auto' lets FluxKit pick. */
189
+ logLevel?: LogLevel;
190
+ logger?: LoggerLike;
191
+ /** Allow falling back to the browser's native player for MP4/HLS. */
192
+ allowNativeFallback?: boolean;
193
+ /** Prefer hardware decoding in WebCodecs. */
194
+ hardwareAcceleration?: 'no-preference' | 'prefer-hardware' | 'prefer-software';
195
+ /** Target fragment size handed to MSE, ms. Lower = lower latency. */
196
+ segmentDuration?: number;
197
+ /** Keep at most this many seconds buffered in MSE for live streams. */
198
+ liveBufferTarget?: number;
199
+ /** Speed up playback slightly when far behind a live edge. */
200
+ catchUp?: boolean;
201
+ /** Reconnect policy for network streams. */
202
+ retry?: Partial<RetryOptions>;
203
+ /** Timeout for connect/handshake, ms. */
204
+ timeout?: number;
205
+ /** Extra headers for HTTP requests (may be rejected by CORS preflight). */
206
+ headers?: Record<string, string>;
207
+ /** HLS specifics. */
208
+ hls?: {
209
+ /** 'demux' (default) builds fMP4 for MSE; 'native' uses <video src>. */
210
+ mode?: 'demux' | 'native';
211
+ /** Cap variant bitrate when the master playlist is used. */
212
+ maxBandwidth?: number;
213
+ /** Reload interval for live playlists, in target durations. */
214
+ liveReloadFactor?: number;
215
+ };
216
+ /**
217
+ * WASM software decoding, used when MSE and WebCodecs cannot decode the
218
+ * stream (typically H.265 on browsers without a platform decoder).
219
+ */
220
+ softDecode?: {
221
+ /** Default true; software is only tried after MSE and WebCodecs fail. */
222
+ enabled?: boolean;
223
+ /** Custom module loaders for the bundled WASM backends. */
224
+ loaders?: {
225
+ avc?: () => Promise<unknown>;
226
+ hevc?: () => Promise<unknown>;
227
+ };
228
+ /** Decoded frames kept ahead of the presentation clock. Default 4. */
229
+ maxDecodeAhead?: number;
230
+ /** Drop late frames when decoding cannot keep up. Default true. */
231
+ dropLateFrames?: boolean;
232
+ };
233
+ /** WebCodecs specifics. */
234
+ webcodecs?: {
235
+ /** Canvas fit style. */
236
+ fit?: 'contain' | 'cover' | 'fill';
237
+ /** Audio jitter buffer in seconds. */
238
+ audioBuffer?: number;
239
+ };
240
+ }
241
+ export interface LoadOptions {
242
+ /** Start position for VOD, ms. */
243
+ startTime?: number;
244
+ /** Do not autoplay this load. */
245
+ autoplay?: boolean;
246
+ }
@@ -0,0 +1,12 @@
1
+ /** Promise/time helpers used across the library. */
2
+ export interface Deferred<T> {
3
+ promise: Promise<T>;
4
+ resolve: (value: T) => void;
5
+ reject: (err: unknown) => void;
6
+ readonly settled: boolean;
7
+ }
8
+ export declare function deferred<T = void>(): Deferred<T>;
9
+ export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
10
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T>;
11
+ export declare function noop(): void;
12
+ export declare function now(): number;
@@ -0,0 +1,17 @@
1
+ /** Growable byte queue with cheap append / peek / consume. */
2
+ export declare class ByteBuffer {
3
+ private buf;
4
+ private start;
5
+ private end;
6
+ constructor(size?: number);
7
+ get length(): number;
8
+ append(data: Uint8Array): void;
9
+ private ensure;
10
+ /** Zero-copy view of the next n bytes, or null when not enough data. */
11
+ peek(n: number): Uint8Array | null;
12
+ peekByte(offset?: number): number;
13
+ /** Copy out n bytes and advance. */
14
+ consume(n: number): Uint8Array;
15
+ skip(n: number): void;
16
+ clear(): void;
17
+ }