fluxkit-player 0.0.0-stage → 0.1.1
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.
- package/CHANGELOG.md +120 -0
- package/LICENSE +21 -0
- package/README.en.md +224 -0
- package/README.md +549 -2
- package/THIRD-PARTY-NOTICES.md +30 -0
- package/dist/fluxkit.js +5536 -0
- package/dist/fluxkit.js.map +1 -0
- package/dist/fluxkit.umd.cjs +94 -0
- package/dist/fluxkit.umd.cjs.map +1 -0
- package/dist/types/codec/aac.d.ts +19 -0
- package/dist/types/codec/bit.d.ts +15 -0
- package/dist/types/codec/config.d.ts +19 -0
- package/dist/types/codec/g711.d.ts +4 -0
- package/dist/types/codec/h264.d.ts +37 -0
- package/dist/types/codec/h265.d.ts +27 -0
- package/dist/types/config.d.ts +66 -0
- package/dist/types/crypto/hls-aes.d.ts +13 -0
- package/dist/types/demux/flv.d.ts +48 -0
- package/dist/types/demux/hls.d.ts +79 -0
- package/dist/types/demux/mp4.d.ts +45 -0
- package/dist/types/demux/ts.d.ts +41 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/io/http.d.ts +32 -0
- package/dist/types/io/websocket.d.ts +27 -0
- package/dist/types/pipeline/segmenter.d.ts +16 -0
- package/dist/types/pipeline/timeline.d.ts +15 -0
- package/dist/types/player.d.ts +169 -0
- package/dist/types/protocol/amf0.d.ts +12 -0
- package/dist/types/remux/fmp4.d.ts +32 -0
- package/dist/types/render/audio.d.ts +61 -0
- package/dist/types/render/backlog.d.ts +27 -0
- package/dist/types/render/mse.d.ts +56 -0
- package/dist/types/render/software.d.ts +110 -0
- package/dist/types/render/subtitles.d.ts +36 -0
- package/dist/types/render/webcodecs.d.ts +73 -0
- package/dist/types/soft/h264bsd.d.ts +23 -0
- package/dist/types/soft/index.d.ts +14 -0
- package/dist/types/soft/libde265.d.ts +16 -0
- package/dist/types/soft/openh264.d.ts +21 -0
- package/dist/types/soft/soft-worker.d.ts +2 -0
- package/dist/types/soft/types.d.ts +37 -0
- package/dist/types/soft/worker-protocol.d.ts +52 -0
- package/dist/types/source/abr.d.ts +22 -0
- package/dist/types/source/hls.d.ts +66 -0
- package/dist/types/source/stream.d.ts +23 -0
- package/dist/types/types.d.ts +354 -0
- package/dist/types/ui/controls.d.ts +68 -0
- package/dist/types/utils/async.d.ts +12 -0
- package/dist/types/utils/buffer.d.ts +17 -0
- package/dist/types/utils/bytes.d.ts +62 -0
- package/dist/types/utils/events.d.ts +10 -0
- package/dist/types/utils/log.d.ts +14 -0
- package/docs/PUBLISHING.md +142 -0
- package/docs/README.md +42 -0
- package/docs/TEST-REPORT.md +370 -0
- package/docs/USAGE.md +513 -0
- package/docs/architecture.md +213 -0
- package/docs/test-logs/build.txt +19 -0
- package/docs/test-logs/coverage.txt +64 -0
- package/docs/test-logs/e2e-firefox.txt +1667 -0
- package/docs/test-logs/e2e.txt +1667 -0
- package/docs/test-logs/environment.json +62 -0
- package/docs/test-logs/typecheck.txt +1 -0
- package/docs/test-logs/unit.txt +81 -0
- package/examples/README.md +53 -0
- package/examples/minimal.html +49 -0
- package/examples/react/FluxPlayer.tsx +48 -0
- package/examples/soft-worker.js +6 -0
- package/examples/vue/FluxPlayer.vue +47 -0
- package/package.json +96 -4
|
@@ -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[] | Promise<SoftFrame[]>;
|
|
34
|
+
flush(): SoftFrame[] | Promise<SoftFrame[]>;
|
|
35
|
+
close(): void;
|
|
36
|
+
}
|
|
37
|
+
export type SoftModuleLoader = () => Promise<unknown>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Message protocol between the player and the optional software-decode worker. */
|
|
2
|
+
import type { Track } from '../types';
|
|
3
|
+
export interface SoftWorkerInit {
|
|
4
|
+
type: 'init';
|
|
5
|
+
track: Track;
|
|
6
|
+
/** URLs for the optional WASM modules (module workers cannot receive functions). */
|
|
7
|
+
modules?: {
|
|
8
|
+
avc?: string;
|
|
9
|
+
openh264?: string;
|
|
10
|
+
hevc?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface SoftWorkerDecode {
|
|
14
|
+
type: 'decode';
|
|
15
|
+
id: number;
|
|
16
|
+
data: Uint8Array;
|
|
17
|
+
ptsUs: number;
|
|
18
|
+
keyframe: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SoftWorkerFlush {
|
|
21
|
+
type: 'flush';
|
|
22
|
+
id: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SoftWorkerClose {
|
|
25
|
+
type: 'close';
|
|
26
|
+
}
|
|
27
|
+
export type SoftWorkerRequest = SoftWorkerInit | SoftWorkerDecode | SoftWorkerFlush | SoftWorkerClose;
|
|
28
|
+
export interface SoftWorkerReady {
|
|
29
|
+
type: 'ready';
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SoftWorkerFrame {
|
|
33
|
+
ptsUs: number;
|
|
34
|
+
bitmap: ImageBitmap;
|
|
35
|
+
}
|
|
36
|
+
export interface SoftWorkerFrames {
|
|
37
|
+
type: 'frames';
|
|
38
|
+
id: number;
|
|
39
|
+
frames: SoftWorkerFrame[];
|
|
40
|
+
}
|
|
41
|
+
export interface SoftWorkerError {
|
|
42
|
+
type: 'error';
|
|
43
|
+
id?: number;
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
export type SoftWorkerResponse = SoftWorkerReady | SoftWorkerFrames | SoftWorkerError;
|
|
47
|
+
/** The subset of DedicatedWorkerGlobalScope used by installSoftWorker. */
|
|
48
|
+
export interface SoftWorkerScope {
|
|
49
|
+
onmessage: ((event: MessageEvent) => void) | null;
|
|
50
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Pure HLS ABR decision, kept separate from network/state for testability. */
|
|
2
|
+
import type { HlsVariant } from '../demux/hls';
|
|
3
|
+
export interface AbrDecisionInput {
|
|
4
|
+
/** Variants sorted by ascending bandwidth. */
|
|
5
|
+
variants: readonly HlsVariant[];
|
|
6
|
+
currentUri?: string;
|
|
7
|
+
/** Seconds of media buffered ahead of the playhead. */
|
|
8
|
+
buffer: number;
|
|
9
|
+
/** Estimated download throughput in bits/second. */
|
|
10
|
+
throughput: number;
|
|
11
|
+
live: boolean;
|
|
12
|
+
liveBufferTarget: number;
|
|
13
|
+
lowBuffer: number;
|
|
14
|
+
highBuffer: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Choose the next variant, or null to stay. Moves at most one step per call so
|
|
18
|
+
* a transient buffer spike cannot jump across the whole ladder.
|
|
19
|
+
*/
|
|
20
|
+
export declare function chooseAbrVariant(input: AbrDecisionInput): HlsVariant | null;
|
|
21
|
+
/** Normalize an HLS CODECS attribute to a switchable video codec family. */
|
|
22
|
+
export declare function videoCodecFamily(codecs?: string): string | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** HLS source: playlist parsing, segment loading, TS/fMP4 demuxing. */
|
|
2
|
+
import type { AudioTrackInfo, MediaSourceLike, SourceContext, SubtitleTrackInfo } 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
|
+
private readonly preferredBandwidth?;
|
|
10
|
+
readonly protocol: "hls";
|
|
11
|
+
private tracks;
|
|
12
|
+
private stopped;
|
|
13
|
+
private _live;
|
|
14
|
+
private mediaDuration;
|
|
15
|
+
private audioOnly;
|
|
16
|
+
private audioRenditions;
|
|
17
|
+
private subtitleRenditions;
|
|
18
|
+
private activeAudioId;
|
|
19
|
+
private readonly preferredAudioId?;
|
|
20
|
+
private variants;
|
|
21
|
+
private manualBandwidth;
|
|
22
|
+
private switchTarget;
|
|
23
|
+
private lastSwitchAt;
|
|
24
|
+
private throughputBps;
|
|
25
|
+
private readonly keyCache;
|
|
26
|
+
constructor(url: string, options: ResolvedOptions, ctx: SourceContext, startMs?: number, preferredAudioId?: string, preferredBandwidth?: number | undefined);
|
|
27
|
+
get duration(): number;
|
|
28
|
+
get live(): boolean;
|
|
29
|
+
get variantBandwidth(): number;
|
|
30
|
+
get audioTracks(): AudioTrackInfo[];
|
|
31
|
+
get subtitleTracks(): SubtitleTrackInfo[];
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
private createSink;
|
|
34
|
+
private createDemuxer;
|
|
35
|
+
private pushInit;
|
|
36
|
+
private createTrack;
|
|
37
|
+
private runLoop;
|
|
38
|
+
/** Fetch a new `EXT-X-MAP` init segment when it changes (fMP4 HLS). */
|
|
39
|
+
/** Keep only a small window of played segments so long live streams do not grow forever. */
|
|
40
|
+
private prunePlaylist;
|
|
41
|
+
private refreshMap;
|
|
42
|
+
/** Select a variant manually, or resume automatic switching. */
|
|
43
|
+
setQuality(bandwidth: number | 'auto'): void;
|
|
44
|
+
private abrPool;
|
|
45
|
+
private recordDownload;
|
|
46
|
+
/** Automatic bitrate adaptation at segment boundaries. */
|
|
47
|
+
private maybeAdapt;
|
|
48
|
+
/** Replace the main track's demuxer/playlist at the next media sequence. */
|
|
49
|
+
private switchVariant;
|
|
50
|
+
private assertKeySupported;
|
|
51
|
+
private decrypt;
|
|
52
|
+
private getKey;
|
|
53
|
+
private fetchSegment;
|
|
54
|
+
private fetchPart;
|
|
55
|
+
private fetchUri;
|
|
56
|
+
private reload;
|
|
57
|
+
private blockingUrl;
|
|
58
|
+
/** Merge a fresh playlist into the live window, updating in-progress parts. */
|
|
59
|
+
private mergePlaylist;
|
|
60
|
+
/** VOD: don't read the whole file into memory ahead of playback. */
|
|
61
|
+
private waitForDemand;
|
|
62
|
+
private paceLive;
|
|
63
|
+
/** True when the chosen variant carries no video (audio-only radio stream). */
|
|
64
|
+
get isAudioOnly(): boolean;
|
|
65
|
+
stop(): void;
|
|
66
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 _live;
|
|
13
|
+
private readonly liveOverride?;
|
|
14
|
+
constructor(protocol: Protocol, url: string, options: ResolvedOptions, ctx: SourceContext, live?: boolean);
|
|
15
|
+
get live(): boolean;
|
|
16
|
+
get duration(): number | undefined;
|
|
17
|
+
start(): Promise<void>;
|
|
18
|
+
/** Content-Type can contradict the file extension; fix it before parsing. */
|
|
19
|
+
private sniff;
|
|
20
|
+
pause(): void;
|
|
21
|
+
resume(): void;
|
|
22
|
+
stop(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
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
|
+
/** The source discovered that the stream is live or VOD. */
|
|
69
|
+
onLive?(live: boolean): void;
|
|
70
|
+
/** Timestamps jump here (HLS `EXT-X-DISCONTINUITY`); rebase the timeline. */
|
|
71
|
+
onDiscontinuity?(): void;
|
|
72
|
+
/** Active renderer mode, used to decide whether in-place ABR is safe. */
|
|
73
|
+
getRendererMode?(): string;
|
|
74
|
+
/** The source switched variants; useful for UI/diagnostics. */
|
|
75
|
+
onVariantChange?(bandwidth: number): void;
|
|
76
|
+
/** Seconds of media already buffered ahead of the playhead (used to pace HLS). */
|
|
77
|
+
getBufferAhead?: () => number;
|
|
78
|
+
getCurrentTime?: () => number;
|
|
79
|
+
/** Bytes received, for the stats overlay. */
|
|
80
|
+
onBytes?: (bytes: number) => void;
|
|
81
|
+
}
|
|
82
|
+
export interface MediaSourceLike {
|
|
83
|
+
readonly protocol: Protocol;
|
|
84
|
+
start(): Promise<void>;
|
|
85
|
+
stop(): void;
|
|
86
|
+
seek?(ms: number): Promise<void>;
|
|
87
|
+
/** Stop reading from the network (backpressure); optional. */
|
|
88
|
+
pause?(): void;
|
|
89
|
+
resume?(): void;
|
|
90
|
+
/** Select a variant by bandwidth, or 'auto' to re-enable ABR. */
|
|
91
|
+
setQuality?(bandwidth: number | 'auto'): void;
|
|
92
|
+
/** Active variant bandwidth, when the source exposes one. */
|
|
93
|
+
readonly variantBandwidth?: number;
|
|
94
|
+
readonly live: boolean;
|
|
95
|
+
readonly duration?: number;
|
|
96
|
+
}
|
|
97
|
+
export interface RendererStats {
|
|
98
|
+
decodedVideoFrames: number;
|
|
99
|
+
droppedVideoFrames: number;
|
|
100
|
+
decodedAudioFrames: number;
|
|
101
|
+
/** Peak absolute sample of the last ~1s, 0..1 (Web Audio paths only). */
|
|
102
|
+
audioPeak: number;
|
|
103
|
+
/** AudioContext state: 'running' | 'suspended' | 'closed' | 'none'. */
|
|
104
|
+
audioState: string;
|
|
105
|
+
/** Effective Web Audio gain, 0..1. */
|
|
106
|
+
audioVolume: number;
|
|
107
|
+
/** Where audio is decoded: MSE SourceBuffer, Web Audio, or none. */
|
|
108
|
+
audioPath: 'mse' | 'webaudio' | 'none';
|
|
109
|
+
}
|
|
110
|
+
export interface Renderer {
|
|
111
|
+
readonly mode: 'mse' | 'webcodecs' | 'software' | 'native';
|
|
112
|
+
attach(tracks: Track[]): Promise<void>;
|
|
113
|
+
/** `samples` are sorted by dts and share a timeline. */
|
|
114
|
+
write(track: Track, samples: Sample[]): void;
|
|
115
|
+
flush(): void;
|
|
116
|
+
reset(): void;
|
|
117
|
+
destroy(): void;
|
|
118
|
+
endOfStream?(): void;
|
|
119
|
+
resumeAudio?(): Promise<void> | void;
|
|
120
|
+
setVolume?(volume: number): void;
|
|
121
|
+
setPaused?(paused: boolean): void;
|
|
122
|
+
setPlaybackRate?(rate: number): void;
|
|
123
|
+
/** Video stream for MediaRecorder (canvas or <video>). */
|
|
124
|
+
captureStream?(): MediaStream | null;
|
|
125
|
+
/** Separate Web Audio stream (G.711 side channel / WebCodecs). */
|
|
126
|
+
captureAudioStream?(): MediaStream | null;
|
|
127
|
+
readonly stats: RendererStats;
|
|
128
|
+
}
|
|
129
|
+
export interface PlayerStats {
|
|
130
|
+
/** Bytes received from the network since load(). */
|
|
131
|
+
bytesReceived: number;
|
|
132
|
+
/** Instantaneous bitrate in bits/second (1s window). */
|
|
133
|
+
kbps: number;
|
|
134
|
+
/** Protocol in use. */
|
|
135
|
+
protocol: Protocol;
|
|
136
|
+
/** 'mse' | 'webcodecs' | 'native'. */
|
|
137
|
+
decoder: string;
|
|
138
|
+
/** Whether the active video decoder prefers hardware acceleration. */
|
|
139
|
+
hardwareAcceleration: 'preferred' | 'software' | 'unknown';
|
|
140
|
+
videoCodec?: string;
|
|
141
|
+
audioCodec?: string;
|
|
142
|
+
width?: number;
|
|
143
|
+
height?: number;
|
|
144
|
+
/** Frames per second currently being rendered. */
|
|
145
|
+
fps: number;
|
|
146
|
+
decodedVideoFrames: number;
|
|
147
|
+
droppedVideoFrames: number;
|
|
148
|
+
decodedAudioFrames: number;
|
|
149
|
+
/** Peak audio sample in the last second (0..1). 0 = silence. */
|
|
150
|
+
audioPeak: number;
|
|
151
|
+
audioState: string;
|
|
152
|
+
audioVolume: number;
|
|
153
|
+
audioPath: 'mse' | 'webaudio' | 'none';
|
|
154
|
+
/** Software decode is running in a Worker. */
|
|
155
|
+
decodeWorker: boolean;
|
|
156
|
+
/** Seconds of media buffered ahead of the playhead. */
|
|
157
|
+
bufferAhead: number;
|
|
158
|
+
/** Live latency estimate in seconds (buffer end - currentTime). */
|
|
159
|
+
latency: number;
|
|
160
|
+
/** Active HLS variant bandwidth in bits/second (0 when not applicable). */
|
|
161
|
+
variantBandwidth: number;
|
|
162
|
+
live: boolean;
|
|
163
|
+
droppedAudioFrames: number;
|
|
164
|
+
}
|
|
165
|
+
export declare class FluxKitError extends Error {
|
|
166
|
+
readonly code: string;
|
|
167
|
+
readonly detail?: unknown;
|
|
168
|
+
constructor(code: string, message: string, detail?: unknown);
|
|
169
|
+
}
|
|
170
|
+
export interface AudioTrackInfo {
|
|
171
|
+
id: string;
|
|
172
|
+
label: string;
|
|
173
|
+
language?: string;
|
|
174
|
+
default: boolean;
|
|
175
|
+
active: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface SubtitleTrackInfo {
|
|
178
|
+
id: string;
|
|
179
|
+
label: string;
|
|
180
|
+
language?: string;
|
|
181
|
+
default: boolean;
|
|
182
|
+
active: boolean;
|
|
183
|
+
/** Resolved media playlist URI (present for HLS subtitle renditions). */
|
|
184
|
+
uri?: string;
|
|
185
|
+
}
|
|
186
|
+
export interface PlayerEvents {
|
|
187
|
+
/** Tracks discovered and renderer attached. Playback can start. */
|
|
188
|
+
ready: {
|
|
189
|
+
tracks: Track[];
|
|
190
|
+
protocol: Protocol;
|
|
191
|
+
decoder: string;
|
|
192
|
+
};
|
|
193
|
+
/** A load/seek/reconnect is in progress. */
|
|
194
|
+
loading: {
|
|
195
|
+
loading: boolean;
|
|
196
|
+
url?: string;
|
|
197
|
+
};
|
|
198
|
+
/** First frames rendered. */
|
|
199
|
+
loaded: {
|
|
200
|
+
width: number;
|
|
201
|
+
height: number;
|
|
202
|
+
};
|
|
203
|
+
metadata: {
|
|
204
|
+
width: number;
|
|
205
|
+
height: number;
|
|
206
|
+
duration?: number;
|
|
207
|
+
live: boolean;
|
|
208
|
+
};
|
|
209
|
+
stats: PlayerStats;
|
|
210
|
+
/** A live stream dropped and a reconnect is scheduled. */
|
|
211
|
+
reconnecting: {
|
|
212
|
+
attempt: number;
|
|
213
|
+
max: number;
|
|
214
|
+
delay: number;
|
|
215
|
+
};
|
|
216
|
+
/** The stream is back after a reconnect. */
|
|
217
|
+
reconnected: void;
|
|
218
|
+
/** HLS ABR / manual quality switch finished. */
|
|
219
|
+
qualitychange: {
|
|
220
|
+
bandwidth: number;
|
|
221
|
+
};
|
|
222
|
+
audiochange: {
|
|
223
|
+
id: string | null;
|
|
224
|
+
};
|
|
225
|
+
subtitlechange: {
|
|
226
|
+
id: string | null;
|
|
227
|
+
};
|
|
228
|
+
error: FluxKitError | Error;
|
|
229
|
+
ended: void;
|
|
230
|
+
seeked: {
|
|
231
|
+
time: number;
|
|
232
|
+
};
|
|
233
|
+
play: void;
|
|
234
|
+
pause: void;
|
|
235
|
+
log: {
|
|
236
|
+
level: string;
|
|
237
|
+
message: string;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export interface LoggerLike {
|
|
241
|
+
(level: 'error' | 'warn' | 'info' | 'debug', message: string, ...args: unknown[]): void;
|
|
242
|
+
}
|
|
243
|
+
export interface RetryOptions {
|
|
244
|
+
/** Max reconnect attempts, 0 disables reconnecting. */
|
|
245
|
+
maxRetries: number;
|
|
246
|
+
/** Base delay in ms, doubled on each attempt. */
|
|
247
|
+
delay: number;
|
|
248
|
+
maxDelay: number;
|
|
249
|
+
}
|
|
250
|
+
export interface FluxKitOptions {
|
|
251
|
+
/** Force a decoder. Default 'auto'. */
|
|
252
|
+
decoder?: DecoderMode;
|
|
253
|
+
/** Force a protocol instead of sniffing the URL. */
|
|
254
|
+
protocol?: Protocol | 'auto';
|
|
255
|
+
/**
|
|
256
|
+
* Built-in overlay control bar (play/pause, stop, progress, volume,
|
|
257
|
+
* screenshot, recording, fullscreen). Default false.
|
|
258
|
+
*/
|
|
259
|
+
controls?: boolean | {
|
|
260
|
+
/** Auto-hide delay in ms. Default 2500. */
|
|
261
|
+
autoHide?: number;
|
|
262
|
+
screenshot?: boolean;
|
|
263
|
+
record?: boolean;
|
|
264
|
+
fullscreen?: boolean;
|
|
265
|
+
/** Prefix for downloaded files. Default 'fluxkit'. */
|
|
266
|
+
downloadName?: string;
|
|
267
|
+
};
|
|
268
|
+
/** Automatically reconnect live streams after a mid-stream drop. Default true. */
|
|
269
|
+
autoReconnect?: boolean;
|
|
270
|
+
/** Force live/VOD semantics. Default: auto (HTTP Content-Length / HLS ENDLIST). */
|
|
271
|
+
live?: boolean;
|
|
272
|
+
/** Autoplay after the first frames arrive. */
|
|
273
|
+
autoplay?: boolean;
|
|
274
|
+
/** Start muted (required for most autoplay policies). */
|
|
275
|
+
muted?: boolean;
|
|
276
|
+
loop?: boolean;
|
|
277
|
+
volume?: number;
|
|
278
|
+
/** 'auto' lets FluxKit pick. */
|
|
279
|
+
logLevel?: LogLevel;
|
|
280
|
+
logger?: LoggerLike;
|
|
281
|
+
/** Allow falling back to the browser's native player for MP4/HLS. */
|
|
282
|
+
allowNativeFallback?: boolean;
|
|
283
|
+
/** Prefer hardware decoding in WebCodecs. */
|
|
284
|
+
hardwareAcceleration?: 'no-preference' | 'prefer-hardware' | 'prefer-software';
|
|
285
|
+
/** Target fragment size handed to MSE, ms. Lower = lower latency. */
|
|
286
|
+
segmentDuration?: number;
|
|
287
|
+
/** Keep at most this many seconds buffered in MSE for live streams. */
|
|
288
|
+
liveBufferTarget?: number;
|
|
289
|
+
/** Speed up playback slightly when far behind a live edge. */
|
|
290
|
+
catchUp?: boolean;
|
|
291
|
+
/** Reconnect policy for network streams. */
|
|
292
|
+
retry?: Partial<RetryOptions>;
|
|
293
|
+
/** Timeout for connect/handshake, ms. */
|
|
294
|
+
timeout?: number;
|
|
295
|
+
/** Extra headers for HTTP requests (may be rejected by CORS preflight). */
|
|
296
|
+
headers?: Record<string, string>;
|
|
297
|
+
/** HLS specifics. */
|
|
298
|
+
hls?: {
|
|
299
|
+
/** 'demux' (default) builds fMP4 for MSE; 'native' uses <video src>. */
|
|
300
|
+
mode?: 'demux' | 'native';
|
|
301
|
+
/** Cap variant bitrate when the master playlist is used. */
|
|
302
|
+
maxBandwidth?: number;
|
|
303
|
+
/** Reload interval for live playlists, in target durations. */
|
|
304
|
+
liveReloadFactor?: number;
|
|
305
|
+
/** Automatic variant switching for multi-variant master playlists. */
|
|
306
|
+
abr?: boolean;
|
|
307
|
+
/** Switch down when fewer than this many seconds are buffered. Default 2. */
|
|
308
|
+
abrLowBuffer?: number;
|
|
309
|
+
/** Switch up when more than this many seconds are buffered. Default 8. */
|
|
310
|
+
abrHighBuffer?: number;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* WASM software decoding, used when MSE and WebCodecs cannot decode the
|
|
314
|
+
* stream (typically H.265 on browsers without a platform decoder).
|
|
315
|
+
*/
|
|
316
|
+
softDecode?: {
|
|
317
|
+
/** Default true; software is only tried after MSE and WebCodecs fail. */
|
|
318
|
+
enabled?: boolean;
|
|
319
|
+
/** Custom module loaders for the bundled WASM backends. */
|
|
320
|
+
loaders?: {
|
|
321
|
+
avc?: () => Promise<unknown>;
|
|
322
|
+
openh264?: () => Promise<unknown>;
|
|
323
|
+
hevc?: () => Promise<unknown>;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Run decode + YUV→RGBA in a module Worker. Pass a worker URL or a factory
|
|
327
|
+
* returning a Worker. The worker must call `installSoftWorker(self)`.
|
|
328
|
+
*/
|
|
329
|
+
worker?: string | (() => Worker);
|
|
330
|
+
/** WASM module URLs passed to the worker (module workers cannot get functions). */
|
|
331
|
+
modules?: {
|
|
332
|
+
avc?: string;
|
|
333
|
+
openh264?: string;
|
|
334
|
+
hevc?: string;
|
|
335
|
+
};
|
|
336
|
+
/** Decoded frames kept ahead of the presentation clock. Default 4. */
|
|
337
|
+
maxDecodeAhead?: number;
|
|
338
|
+
/** Drop late frames when decoding cannot keep up. Default true. */
|
|
339
|
+
dropLateFrames?: boolean;
|
|
340
|
+
};
|
|
341
|
+
/** WebCodecs specifics. */
|
|
342
|
+
webcodecs?: {
|
|
343
|
+
/** Canvas fit style. */
|
|
344
|
+
fit?: 'contain' | 'cover' | 'fill';
|
|
345
|
+
/** Audio jitter buffer in seconds. */
|
|
346
|
+
audioBuffer?: number;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
export interface LoadOptions {
|
|
350
|
+
/** Start position for VOD, ms. */
|
|
351
|
+
startTime?: number;
|
|
352
|
+
/** Do not autoplay this load. */
|
|
353
|
+
autoplay?: boolean;
|
|
354
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in overlay control bar.
|
|
3
|
+
*
|
|
4
|
+
* Enabled with `new FluxKit(el, { controls: true })`. Framework-free: it only
|
|
5
|
+
* touches the container it is given and the public player API.
|
|
6
|
+
*/
|
|
7
|
+
import type { FluxKit } from '../player';
|
|
8
|
+
export interface ControlBarOptions {
|
|
9
|
+
autoHide: number;
|
|
10
|
+
screenshot: boolean;
|
|
11
|
+
record: boolean;
|
|
12
|
+
fullscreen: boolean;
|
|
13
|
+
downloadName: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class ControlBar {
|
|
16
|
+
private readonly player;
|
|
17
|
+
private readonly container;
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly root;
|
|
20
|
+
private readonly progress;
|
|
21
|
+
private readonly bufferBar;
|
|
22
|
+
private readonly playedBar;
|
|
23
|
+
private readonly thumb;
|
|
24
|
+
private readonly playButton;
|
|
25
|
+
private readonly stopButton;
|
|
26
|
+
private readonly muteButton;
|
|
27
|
+
private readonly volumeInput;
|
|
28
|
+
private readonly timeLabel;
|
|
29
|
+
private readonly recTime;
|
|
30
|
+
private readonly shotButton;
|
|
31
|
+
private readonly recordButton;
|
|
32
|
+
private readonly fullscreenButton;
|
|
33
|
+
private readonly pipButton;
|
|
34
|
+
private readonly rateSelect;
|
|
35
|
+
private readonly spinner;
|
|
36
|
+
private readonly toast;
|
|
37
|
+
private toastTimer;
|
|
38
|
+
private readonly cleanups;
|
|
39
|
+
private timer;
|
|
40
|
+
private hideTimer;
|
|
41
|
+
private dragging;
|
|
42
|
+
private recordStartedAt;
|
|
43
|
+
private destroyed;
|
|
44
|
+
constructor(player: FluxKit, container: HTMLElement, options: ControlBarOptions);
|
|
45
|
+
private query;
|
|
46
|
+
private bind;
|
|
47
|
+
private onKeyDown;
|
|
48
|
+
private togglePlay;
|
|
49
|
+
private updatePlayButton;
|
|
50
|
+
private updateVolume;
|
|
51
|
+
private onPointerDown;
|
|
52
|
+
private onPointerMove;
|
|
53
|
+
private onPointerUp;
|
|
54
|
+
private seekToPointer;
|
|
55
|
+
private bufferedEndMs;
|
|
56
|
+
private updateProgress;
|
|
57
|
+
private takeSnapshot;
|
|
58
|
+
private toggleRecording;
|
|
59
|
+
private updateRecordButton;
|
|
60
|
+
private updateRecordTimer;
|
|
61
|
+
private updateRateVisibility;
|
|
62
|
+
private updatePipButton;
|
|
63
|
+
private showToast;
|
|
64
|
+
private updateFullscreenButton;
|
|
65
|
+
private show;
|
|
66
|
+
private scheduleHide;
|
|
67
|
+
destroy(): void;
|
|
68
|
+
}
|
|
@@ -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
|
+
}
|