fluxkit-player 0.1.0 → 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 +88 -9
- package/README.en.md +224 -0
- package/README.md +207 -98
- package/THIRD-PARTY-NOTICES.md +30 -0
- package/dist/fluxkit.js +2052 -479
- package/dist/fluxkit.js.map +1 -1
- package/dist/fluxkit.umd.cjs +75 -3
- package/dist/fluxkit.umd.cjs.map +1 -1
- package/dist/types/config.d.ts +21 -1
- package/dist/types/crypto/hls-aes.d.ts +13 -0
- package/dist/types/demux/flv.d.ts +2 -0
- package/dist/types/demux/hls.d.ts +25 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/pipeline/timeline.d.ts +4 -0
- package/dist/types/player.d.ts +60 -1
- package/dist/types/render/audio.d.ts +13 -0
- package/dist/types/render/backlog.d.ts +27 -0
- package/dist/types/render/mse.d.ts +7 -0
- package/dist/types/render/software.d.ts +34 -1
- package/dist/types/render/subtitles.d.ts +36 -0
- package/dist/types/render/webcodecs.d.ts +4 -0
- package/dist/types/soft/index.d.ts +5 -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 +2 -2
- 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 +39 -2
- package/dist/types/source/stream.d.ts +2 -1
- package/dist/types/types.d.ts +108 -0
- package/dist/types/ui/controls.d.ts +68 -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 +22 -3
package/dist/types/config.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { FluxKitOptions, LogLevel } from './types';
|
|
2
|
-
export interface ResolvedOptions extends Required<Omit<FluxKitOptions, 'logger' | 'hls' | 'webcodecs' | 'headers' | 'retry' | 'softDecode'>> {
|
|
2
|
+
export interface ResolvedOptions extends Required<Omit<FluxKitOptions, 'logger' | 'hls' | 'webcodecs' | 'headers' | 'retry' | 'softDecode' | 'controls' | 'live'>> {
|
|
3
|
+
/** undefined = auto-detect from Content-Length / HLS ENDLIST. */
|
|
4
|
+
live?: boolean;
|
|
5
|
+
controls: {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
autoHide: number;
|
|
8
|
+
screenshot: boolean;
|
|
9
|
+
record: boolean;
|
|
10
|
+
fullscreen: boolean;
|
|
11
|
+
downloadName: string;
|
|
12
|
+
};
|
|
3
13
|
logger?: FluxKitOptions['logger'];
|
|
4
14
|
headers: Record<string, string>;
|
|
5
15
|
retry: {
|
|
@@ -11,6 +21,9 @@ export interface ResolvedOptions extends Required<Omit<FluxKitOptions, 'logger'
|
|
|
11
21
|
mode: 'demux' | 'native';
|
|
12
22
|
maxBandwidth?: number;
|
|
13
23
|
liveReloadFactor: number;
|
|
24
|
+
abr: boolean;
|
|
25
|
+
abrLowBuffer: number;
|
|
26
|
+
abrHighBuffer: number;
|
|
14
27
|
};
|
|
15
28
|
webcodecs: {
|
|
16
29
|
fit: 'contain' | 'cover' | 'fill';
|
|
@@ -22,8 +35,15 @@ export interface ResolvedOptions extends Required<Omit<FluxKitOptions, 'logger'
|
|
|
22
35
|
dropLateFrames: boolean;
|
|
23
36
|
loaders?: {
|
|
24
37
|
avc?: () => Promise<unknown>;
|
|
38
|
+
openh264?: () => Promise<unknown>;
|
|
25
39
|
hevc?: () => Promise<unknown>;
|
|
26
40
|
};
|
|
41
|
+
worker?: string | (() => Worker);
|
|
42
|
+
modules?: {
|
|
43
|
+
avc?: string;
|
|
44
|
+
openh264?: string;
|
|
45
|
+
hevc?: string;
|
|
46
|
+
};
|
|
27
47
|
};
|
|
28
48
|
}
|
|
29
49
|
export declare const DEFAULTS: {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Big-endian media sequence number padded to 128 bits (RFC 8216 §5.2). */
|
|
2
|
+
export declare function sequenceIv(sequence: number): Uint8Array;
|
|
3
|
+
/** Parse `IV=0x...`; returns null for malformed values. */
|
|
4
|
+
export declare function parseIv(value: string | undefined): Uint8Array | null;
|
|
5
|
+
export declare function ivForSegment(ivHex: string | undefined, sequence: number): Uint8Array;
|
|
6
|
+
export declare function importAes128Key(raw: Uint8Array): Promise<CryptoKey>;
|
|
7
|
+
export declare function importAes256GcmKey(raw: Uint8Array): Promise<CryptoKey>;
|
|
8
|
+
/**
|
|
9
|
+
* HLS AES-256-GCM segments are `IV(16) || ciphertext || tag(16)`; WebCrypto
|
|
10
|
+
* expects the tag appended to the ciphertext and the IV passed separately.
|
|
11
|
+
*/
|
|
12
|
+
export declare function decryptAes256Gcm(key: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
|
|
13
|
+
export declare function decryptAes128(key: CryptoKey, iv: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
|
|
@@ -31,6 +31,8 @@ export declare class FlvDemuxer implements Demuxer {
|
|
|
31
31
|
push(chunk: Uint8Array): void;
|
|
32
32
|
/** Feed an already-demuxed FLV tag (for custom transports). */
|
|
33
33
|
pushTag(type: number, timestamp: number, data: Uint8Array): void;
|
|
34
|
+
/** Duration in seconds from onMetaData, when the stream is a VOD file. */
|
|
35
|
+
get duration(): number | undefined;
|
|
34
36
|
flush(): void;
|
|
35
37
|
reset(): void;
|
|
36
38
|
private tracks;
|
|
@@ -6,6 +6,7 @@ export interface HlsVariant {
|
|
|
6
6
|
codecs?: string;
|
|
7
7
|
frameRate?: number;
|
|
8
8
|
audioGroup?: string;
|
|
9
|
+
subtitleGroup?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface HlsRendition {
|
|
11
12
|
type: string;
|
|
@@ -19,16 +20,32 @@ export interface HlsRendition {
|
|
|
19
20
|
export interface HlsKey {
|
|
20
21
|
method: string;
|
|
21
22
|
uri?: string;
|
|
23
|
+
/** Explicit `IV=0x...` (128-bit hex). */
|
|
24
|
+
iv?: string;
|
|
25
|
+
/** `KEYFORMAT`, defaulting to `identity` when omitted. */
|
|
26
|
+
keyformat?: string;
|
|
22
27
|
}
|
|
23
28
|
export interface HlsByteRange {
|
|
24
29
|
offset: number;
|
|
25
30
|
length: number;
|
|
26
31
|
}
|
|
32
|
+
/** LL-HLS partial segment (`EXT-X-PART`). */
|
|
33
|
+
export interface HlsPart {
|
|
34
|
+
uri: string;
|
|
35
|
+
duration: number;
|
|
36
|
+
independent: boolean;
|
|
37
|
+
gap: boolean;
|
|
38
|
+
byterange?: HlsByteRange;
|
|
39
|
+
}
|
|
27
40
|
export interface HlsSegment {
|
|
28
41
|
uri: string;
|
|
29
42
|
duration: number;
|
|
30
43
|
sequence: number;
|
|
31
44
|
discontinuity: boolean;
|
|
45
|
+
/** True once the full segment URI is available. */
|
|
46
|
+
complete: boolean;
|
|
47
|
+
/** LL-HLS parts listed for this segment (possibly still growing). */
|
|
48
|
+
parts: HlsPart[];
|
|
32
49
|
byterange?: HlsByteRange;
|
|
33
50
|
map?: string;
|
|
34
51
|
mapByterange?: HlsByteRange;
|
|
@@ -37,6 +54,14 @@ export interface HlsSegment {
|
|
|
37
54
|
export interface HlsMediaPlaylist {
|
|
38
55
|
targetDuration: number;
|
|
39
56
|
mediaSequence: number;
|
|
57
|
+
/** Monotonic count of discontinuities before this playlist window. */
|
|
58
|
+
discontinuitySequence: number;
|
|
59
|
+
/** LL-HLS `PART-TARGET` in seconds. */
|
|
60
|
+
partTarget: number;
|
|
61
|
+
/** LL-HLS blocking playlist reload. */
|
|
62
|
+
canBlockReload: boolean;
|
|
63
|
+
/** LL-HLS `PART-HOLD-BACK` in seconds. */
|
|
64
|
+
partHoldBack?: number;
|
|
40
65
|
segments: HlsSegment[];
|
|
41
66
|
endList: boolean;
|
|
42
67
|
map?: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,14 +16,15 @@ export { HlsSource } from './source/hls';
|
|
|
16
16
|
export { MseRenderer } from './render/mse';
|
|
17
17
|
export { WebCodecsRenderer, isWebCodecsSupported } from './render/webcodecs';
|
|
18
18
|
export { SoftwareRenderer } from './render/software';
|
|
19
|
-
export { createSoftwareDecoder, type SoftFrame, type SoftVideoDecoder, type SoftLoaders } from './soft';
|
|
19
|
+
export { createSoftwareDecoder, installSoftWorker, type SoftFrame, type SoftVideoDecoder, type SoftLoaders, type SoftWorkerResponse, type SoftWorkerScope, } from './soft';
|
|
20
20
|
export { Libde265Decoder } from './soft/libde265';
|
|
21
21
|
export { H264BsdDecoder } from './soft/h264bsd';
|
|
22
22
|
export { buildInitSegment, Fmp4Muxer, mimeTypeFor, videoMimeType, audioMimeType, codecLabel, } from './remux/fmp4';
|
|
23
23
|
export { parseAvcSps, buildAvcC, avcCodecString, avccToAnnexB, splitAnnexB, nalsToAvcc, isAvcKeyframe, } from './codec/h264';
|
|
24
24
|
export { parseHevcSps, buildHvcC, hevcCodecString, isHevcKeyframe } from './codec/h265';
|
|
25
|
-
export { parseAudioSpecificConfig, buildAudioSpecificConfig, aacCodecString, parseAdts
|
|
25
|
+
export { parseAudioSpecificConfig, buildAudioSpecificConfig, aacCodecString, parseAdts } from './codec/aac';
|
|
26
26
|
export { parseAvcC, parseHvcC } from './codec/config';
|
|
27
|
+
export { decodeG711, decodeG711Float, type G711Law } from './codec/g711';
|
|
27
28
|
export { HttpStream, fetchText, fetchBytes } from './io/http';
|
|
28
29
|
export { WsTransport, WsStream } from './io/websocket';
|
|
29
30
|
export { encodeAmf0, decodeAmf0, encodeAmf0Values, decodeAmf0All } from './protocol/amf0';
|
|
@@ -5,7 +5,11 @@ export declare class Timeline {
|
|
|
5
5
|
private baseMs;
|
|
6
6
|
private startMs;
|
|
7
7
|
private readonly lastDts;
|
|
8
|
+
private readonly offsets;
|
|
9
|
+
private readonly pendingDiscontinuity;
|
|
8
10
|
constructor(tracks: Map<number, Track>);
|
|
9
11
|
setStart(startMs: number): void;
|
|
12
|
+
/** Rebase every known track at its next sample (HLS discontinuity / ad break). */
|
|
13
|
+
markDiscontinuity(): void;
|
|
10
14
|
normalize(sample: Sample): Sample;
|
|
11
15
|
}
|
package/dist/types/player.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Segmenter, and a Renderer (MSE or WebCodecs), and exposes playback controls
|
|
9
9
|
* plus typed events.
|
|
10
10
|
*/
|
|
11
|
-
import type { FluxKitOptions, LoadOptions, PlayerEvents, PlayerStats, Protocol, Track } from './types';
|
|
11
|
+
import type { AudioTrackInfo, FluxKitOptions, LoadOptions, PlayerEvents, PlayerStats, Protocol, SubtitleTrackInfo, Track } from './types';
|
|
12
12
|
export declare const VERSION = "0.1.0";
|
|
13
13
|
export declare class FluxKit {
|
|
14
14
|
static readonly version = "0.1.0";
|
|
@@ -49,6 +49,25 @@ export declare class FluxKit {
|
|
|
49
49
|
private audioOnlyTimer;
|
|
50
50
|
private wcPaused;
|
|
51
51
|
private sourcePaused;
|
|
52
|
+
private controlsUI;
|
|
53
|
+
private stopped;
|
|
54
|
+
private lastUrl;
|
|
55
|
+
private lastDuration;
|
|
56
|
+
private loading;
|
|
57
|
+
private playbackRateValue;
|
|
58
|
+
private hasStarted;
|
|
59
|
+
private preferredAudioId?;
|
|
60
|
+
private preferredBandwidth;
|
|
61
|
+
private activeSubtitleId;
|
|
62
|
+
private subtitleRenderer;
|
|
63
|
+
private pipVideo;
|
|
64
|
+
private pipStream;
|
|
65
|
+
private reconnectAttempts;
|
|
66
|
+
private reconnectTimer;
|
|
67
|
+
private reconnectResetTimer;
|
|
68
|
+
private recorder;
|
|
69
|
+
private recordedChunks;
|
|
70
|
+
private recordingDone;
|
|
52
71
|
constructor(target: HTMLElement | string, options?: FluxKitOptions);
|
|
53
72
|
on<K extends keyof PlayerEvents>(type: K, listener: (event: PlayerEvents[K]) => void): () => void;
|
|
54
73
|
once<K extends keyof PlayerEvents>(type: K, listener: (event: PlayerEvents[K]) => void): () => void;
|
|
@@ -67,6 +86,11 @@ export declare class FluxKit {
|
|
|
67
86
|
get duration(): number;
|
|
68
87
|
get paused(): boolean;
|
|
69
88
|
get volume(): number;
|
|
89
|
+
get muted(): boolean;
|
|
90
|
+
get isRecording(): boolean;
|
|
91
|
+
get isStopped(): boolean;
|
|
92
|
+
get isLoading(): boolean;
|
|
93
|
+
get playbackRate(): number;
|
|
70
94
|
setVolume(volume: number): void;
|
|
71
95
|
setMuted(muted: boolean): void;
|
|
72
96
|
/** Applies to the next load(). */
|
|
@@ -78,6 +102,36 @@ export declare class FluxKit {
|
|
|
78
102
|
load(url: string, options?: LoadOptions): Promise<void>;
|
|
79
103
|
play(): Promise<void>;
|
|
80
104
|
pause(): void;
|
|
105
|
+
/** Capture the current frame as an image Blob. */
|
|
106
|
+
snapshot(type?: string, quality?: number): Promise<Blob>;
|
|
107
|
+
/** Start recording the current stream to WebM (video + audio when available). */
|
|
108
|
+
startRecording(options?: {
|
|
109
|
+
mimeType?: string;
|
|
110
|
+
videoBitsPerSecond?: number;
|
|
111
|
+
}): void;
|
|
112
|
+
stopRecording(): Promise<Blob | null>;
|
|
113
|
+
private buildRecordingStream;
|
|
114
|
+
/** Jump back to the live edge (MSE buffer or a fresh live load). */
|
|
115
|
+
seekToLive(): Promise<void>;
|
|
116
|
+
/** Playback rate for native/MSE and canvas (WebCodecs / software) renderers. */
|
|
117
|
+
setPlaybackRate(rate: number): void;
|
|
118
|
+
/** Available HLS alternate audio tracks. */
|
|
119
|
+
get audioTracks(): AudioTrackInfo[];
|
|
120
|
+
/** Available HLS subtitle renditions. */
|
|
121
|
+
get subtitleTracks(): SubtitleTrackInfo[];
|
|
122
|
+
/** Switch to another HLS alternate audio track (restarts at the current time). */
|
|
123
|
+
selectAudioTrack(id: string): Promise<void>;
|
|
124
|
+
/** Enable a WebVTT subtitle rendition, or disable subtitles with null. */
|
|
125
|
+
selectSubtitleTrack(id: string | null): void;
|
|
126
|
+
/**
|
|
127
|
+
* Select an HLS variant by bandwidth (bits/second), or 'auto' to resume ABR.
|
|
128
|
+
* The switch happens on a segment boundary for HLS; other protocols are a no-op.
|
|
129
|
+
*/
|
|
130
|
+
setQuality(bandwidth: number | 'auto'): void;
|
|
131
|
+
togglePictureInPicture(): Promise<void>;
|
|
132
|
+
private cleanupPip;
|
|
133
|
+
private setLoading;
|
|
134
|
+
toggleFullscreen(): Promise<void>;
|
|
81
135
|
seek(ms: number): Promise<void>;
|
|
82
136
|
/** Tear down the current stream but keep the player reusable. */
|
|
83
137
|
stop(): void;
|
|
@@ -91,6 +145,11 @@ export declare class FluxKit {
|
|
|
91
145
|
private onSample;
|
|
92
146
|
private onSourceEnd;
|
|
93
147
|
private onSourceError;
|
|
148
|
+
private shouldReconnect;
|
|
149
|
+
private scheduleReconnect;
|
|
150
|
+
private onReconnected;
|
|
151
|
+
private clearReconnectTimer;
|
|
152
|
+
private cancelReconnect;
|
|
94
153
|
private tryNativeFallback;
|
|
95
154
|
private switchProtocol;
|
|
96
155
|
private restartAt;
|
|
@@ -22,21 +22,34 @@ export declare class AudioOutput {
|
|
|
22
22
|
private manualLaw;
|
|
23
23
|
private ctx;
|
|
24
24
|
private gain;
|
|
25
|
+
private destination;
|
|
25
26
|
private anchorMedia;
|
|
26
27
|
private anchorCtx;
|
|
27
28
|
private anchored;
|
|
28
29
|
private volume;
|
|
29
30
|
private destroyed;
|
|
30
31
|
private clockSource;
|
|
32
|
+
private rate;
|
|
31
33
|
decodedFrames: number;
|
|
34
|
+
private peakValue;
|
|
35
|
+
private peakAt;
|
|
32
36
|
constructor(options: AudioOutputOptions);
|
|
33
37
|
get configured(): boolean;
|
|
38
|
+
/** Peak absolute sample over the last second, 0..1. */
|
|
39
|
+
get peak(): number;
|
|
40
|
+
get state(): string;
|
|
41
|
+
get volumeLevel(): number;
|
|
42
|
+
/** Audio-only MediaStream for MediaRecorder (post-gain). */
|
|
43
|
+
captureStream(): MediaStream | null;
|
|
34
44
|
configure(track: AudioTrack): void;
|
|
35
45
|
write(samples: Sample[]): void;
|
|
36
46
|
private writeManual;
|
|
47
|
+
private updatePeak;
|
|
37
48
|
/** Media time in seconds from the active clock, or null before playback. */
|
|
38
49
|
get clock(): number | null;
|
|
39
50
|
setClockSource(source: (() => number | null) | null): void;
|
|
51
|
+
/** Changes the presentation rate; already-scheduled buffers finish at 1x. */
|
|
52
|
+
setRate(rate: number): void;
|
|
40
53
|
private ensureAudioContext;
|
|
41
54
|
private onData;
|
|
42
55
|
private schedule;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live backlog resynchronisation for the software renderer.
|
|
3
|
+
*
|
|
4
|
+
* A software decoder that cannot keep up falls further and further behind the
|
|
5
|
+
* live edge. Decoding every stale frame only makes it worse, so the player
|
|
6
|
+
* periodically resumes at the next keyframe instead. Frame-level skipping is
|
|
7
|
+
* not possible in H.264/H.265: inter-frame prediction requires the whole GOP.
|
|
8
|
+
*/
|
|
9
|
+
/** One decodable access unit with a presentation timestamp. */
|
|
10
|
+
export interface TimedAccessUnit {
|
|
11
|
+
ptsUs: number;
|
|
12
|
+
keyframe: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface LiveResyncPlan {
|
|
15
|
+
/** Number of leading access units to discard. */
|
|
16
|
+
cut: number;
|
|
17
|
+
/** No usable keyframe is buffered; drop non-keyframes until the next one. */
|
|
18
|
+
awaitingKeyframe: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Choose where to resume after falling behind.
|
|
22
|
+
*
|
|
23
|
+
* Keyframes up to `tolerance` seconds before `now` are kept so they can be
|
|
24
|
+
* presented immediately; older GOPs are dropped. When no keyframe is available
|
|
25
|
+
* the caller should discard everything and wait for the next keyframe.
|
|
26
|
+
*/
|
|
27
|
+
export declare function planLiveResync<T extends TimedAccessUnit>(items: readonly T[], nowSeconds: number, tolerance?: number): LiveResyncPlan;
|
|
@@ -18,15 +18,19 @@ export declare class MseRenderer implements Renderer {
|
|
|
18
18
|
private readonly buffers;
|
|
19
19
|
private readonly queues;
|
|
20
20
|
private readonly muxers;
|
|
21
|
+
private readonly mimeTypes;
|
|
21
22
|
private readonly attached;
|
|
22
23
|
private readonly trackList;
|
|
23
24
|
private readonly fallbackTracks;
|
|
24
25
|
private fallbackAudio;
|
|
26
|
+
private hasMseAudio;
|
|
25
27
|
private endPending;
|
|
26
28
|
private destroyed;
|
|
27
29
|
constructor(video: HTMLVideoElement, options: MseOptions);
|
|
28
30
|
get stats(): RendererStats;
|
|
29
31
|
attach(tracks: Track[]): Promise<void>;
|
|
32
|
+
/** Swap the muxer/init segment for an existing SourceBuffer (HLS ABR). */
|
|
33
|
+
private reconfigure;
|
|
30
34
|
private ensureFallbackAudio;
|
|
31
35
|
private initMediaSource;
|
|
32
36
|
private addTrack;
|
|
@@ -43,7 +47,10 @@ export declare class MseRenderer implements Renderer {
|
|
|
43
47
|
setVolume(volume: number): void;
|
|
44
48
|
resumeAudio(): Promise<void> | void;
|
|
45
49
|
setPaused(paused: boolean): void;
|
|
50
|
+
setPlaybackRate(rate: number): void;
|
|
46
51
|
destroy(): void;
|
|
47
52
|
/** Seconds buffered ahead of the playhead. */
|
|
53
|
+
captureStream(): MediaStream | null;
|
|
54
|
+
captureAudioStream(): MediaStream | null;
|
|
48
55
|
get bufferAhead(): number;
|
|
49
56
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WASM software renderer.
|
|
3
3
|
*
|
|
4
|
-
* Decodes H.265 (libde265) or
|
|
4
|
+
* Decodes H.265 (libde265) or H.264 (h264bsd/OpenH264) on the CPU, converts
|
|
5
5
|
* YUV420 to RGB on the GPU (WebGL) and presents frames against the audio clock.
|
|
6
6
|
* This is the last-resort path for browsers without a platform HEVC decoder.
|
|
7
7
|
*/
|
|
@@ -10,10 +10,18 @@ import { FluxKitError } from '../types';
|
|
|
10
10
|
import type { SoftLoaders } from '../soft';
|
|
11
11
|
export interface SoftwareOptions {
|
|
12
12
|
fit: 'contain' | 'cover' | 'fill';
|
|
13
|
+
live: boolean;
|
|
13
14
|
volume: number;
|
|
14
15
|
maxDecodeAhead: number;
|
|
15
16
|
dropLateFrames: boolean;
|
|
16
17
|
loaders?: SoftLoaders;
|
|
18
|
+
/** Worker URL or factory for off-main-thread decode. */
|
|
19
|
+
worker?: string | (() => Worker);
|
|
20
|
+
modules?: {
|
|
21
|
+
avc?: string;
|
|
22
|
+
openh264?: string;
|
|
23
|
+
hevc?: string;
|
|
24
|
+
};
|
|
17
25
|
onError?: (err: Error) => void;
|
|
18
26
|
onFirstFrame?: (width: number, height: number) => void;
|
|
19
27
|
}
|
|
@@ -32,6 +40,7 @@ export declare class SoftwareRenderer implements Renderer {
|
|
|
32
40
|
private paused;
|
|
33
41
|
private anchored;
|
|
34
42
|
private anchorMedia;
|
|
43
|
+
private rate;
|
|
35
44
|
private anchorWall;
|
|
36
45
|
private decoded;
|
|
37
46
|
private dropped;
|
|
@@ -45,21 +54,44 @@ export declare class SoftwareRenderer implements Renderer {
|
|
|
45
54
|
private tmpCtx;
|
|
46
55
|
private imageData;
|
|
47
56
|
private resizeObserver;
|
|
57
|
+
private worker;
|
|
58
|
+
private workerReady;
|
|
59
|
+
private workerName;
|
|
60
|
+
private workerInFlight;
|
|
61
|
+
private workerMaxInFlight;
|
|
62
|
+
private workerId;
|
|
63
|
+
private workerFlushPending;
|
|
64
|
+
private workerFlushId;
|
|
65
|
+
private lastDecodedPtsUs;
|
|
66
|
+
private dropBeforeUs;
|
|
67
|
+
private awaitingKeyframe;
|
|
48
68
|
constructor(options: SoftwareOptions, canvas: HTMLCanvasElement);
|
|
49
69
|
get stats(): RendererStats;
|
|
50
70
|
get currentTime(): number;
|
|
51
71
|
get framesPending(): number;
|
|
72
|
+
get usingWorker(): boolean;
|
|
52
73
|
get backlogSeconds(): number;
|
|
53
74
|
get decoderName(): string;
|
|
75
|
+
captureStream(): MediaStream | null;
|
|
76
|
+
captureAudioStream(): MediaStream | null;
|
|
54
77
|
attach(tracks: Track[]): Promise<void>;
|
|
78
|
+
private initWorker;
|
|
79
|
+
private onWorkerMessage;
|
|
80
|
+
private pumpWorker;
|
|
55
81
|
write(track: Track, samples: Sample[]): void;
|
|
56
82
|
private scheduleDecode;
|
|
57
83
|
private decodeStep;
|
|
84
|
+
/**
|
|
85
|
+
* Resync a live stream that has fallen behind. Only whole GOPs are dropped:
|
|
86
|
+
* the software decoder cannot resume in the middle of an inter-frame chain.
|
|
87
|
+
*/
|
|
88
|
+
private maybeResync;
|
|
58
89
|
private mediaTime;
|
|
59
90
|
private startRaf;
|
|
60
91
|
private tick;
|
|
61
92
|
private resize;
|
|
62
93
|
private observeResize;
|
|
94
|
+
private renderBitmap;
|
|
63
95
|
private render;
|
|
64
96
|
private initGl;
|
|
65
97
|
private uploadPlane;
|
|
@@ -68,6 +100,7 @@ export declare class SoftwareRenderer implements Renderer {
|
|
|
68
100
|
setPaused(paused: boolean): void;
|
|
69
101
|
resumeAudio(): Promise<void> | void;
|
|
70
102
|
setVolume(volume: number): void;
|
|
103
|
+
setPlaybackRate(rate: number): void;
|
|
71
104
|
flush(): void;
|
|
72
105
|
endOfStream(): void;
|
|
73
106
|
reset(): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface SubtitleCue {
|
|
2
|
+
startMs: number;
|
|
3
|
+
endMs: number;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Parse a WebVTT file. HLS subtitle segments may carry an X-TIMESTAMP-MAP
|
|
8
|
+
* header mapping local cue time to the 90 kHz media timeline.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseWebVtt(text: string, baseOffsetMs?: number): SubtitleCue[];
|
|
11
|
+
export interface SubtitleRendererOptions {
|
|
12
|
+
getTime: () => number;
|
|
13
|
+
live?: boolean;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
onError?: (err: Error) => void;
|
|
16
|
+
}
|
|
17
|
+
/** One active subtitle rendition. Rendering is a simple DOM overlay. */
|
|
18
|
+
export declare class SubtitleRenderer {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly host;
|
|
21
|
+
private readonly label;
|
|
22
|
+
private cues;
|
|
23
|
+
private seen;
|
|
24
|
+
private timer;
|
|
25
|
+
private generation;
|
|
26
|
+
private destroyed;
|
|
27
|
+
private current;
|
|
28
|
+
private lastPrune;
|
|
29
|
+
constructor(container: HTMLElement, options: SubtitleRendererOptions);
|
|
30
|
+
get activeText(): string;
|
|
31
|
+
load(playlistUrl: string, headers?: Record<string, string>): Promise<void>;
|
|
32
|
+
private fetchWithRetry;
|
|
33
|
+
private loadSegments;
|
|
34
|
+
private tick;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
@@ -30,6 +30,7 @@ export declare class WebCodecsRenderer implements Renderer {
|
|
|
30
30
|
private anchored;
|
|
31
31
|
private anchorWall;
|
|
32
32
|
private anchorMedia;
|
|
33
|
+
private rate;
|
|
33
34
|
private decodedVideo;
|
|
34
35
|
private droppedVideo;
|
|
35
36
|
private hardware;
|
|
@@ -42,6 +43,8 @@ export declare class WebCodecsRenderer implements Renderer {
|
|
|
42
43
|
get framesPending(): number;
|
|
43
44
|
get acceleration(): 'preferred' | 'software' | 'unknown';
|
|
44
45
|
get element(): HTMLCanvasElement;
|
|
46
|
+
captureStream(): MediaStream | null;
|
|
47
|
+
captureAudioStream(): MediaStream | null;
|
|
45
48
|
attach(tracks: Track[]): Promise<void>;
|
|
46
49
|
private configureVideo;
|
|
47
50
|
write(track: Track, samples: Sample[]): void;
|
|
@@ -62,6 +65,7 @@ export declare class WebCodecsRenderer implements Renderer {
|
|
|
62
65
|
setPaused(paused: boolean): void;
|
|
63
66
|
resumeAudio(): Promise<void> | void;
|
|
64
67
|
setVolume(volume: number): void;
|
|
68
|
+
setPlaybackRate(rate: number): void;
|
|
65
69
|
flush(): void;
|
|
66
70
|
endOfStream(): void;
|
|
67
71
|
reset(): void;
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
import type { VideoTrack } from '../types';
|
|
3
3
|
import type { SoftModuleLoader, SoftVideoDecoder } from './types';
|
|
4
4
|
export interface SoftLoaders {
|
|
5
|
+
/** Baseline H.264 (h264bsd). */
|
|
5
6
|
avc?: SoftModuleLoader;
|
|
7
|
+
/** Main/High H.264 (OpenH264). */
|
|
8
|
+
openh264?: SoftModuleLoader;
|
|
6
9
|
hevc?: SoftModuleLoader;
|
|
7
10
|
}
|
|
8
11
|
export declare function createSoftwareDecoder(track: VideoTrack, loaders?: SoftLoaders): Promise<SoftVideoDecoder>;
|
|
9
12
|
export type { SoftFrame, SoftPlane, SoftVideoDecoder } from './types';
|
|
13
|
+
export { installSoftWorker } from './soft-worker';
|
|
14
|
+
export type { SoftWorkerRequest, SoftWorkerResponse, SoftWorkerScope } from './worker-protocol';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* H.264 Main/High software decoding through OpenH264 (WASM).
|
|
3
|
+
*
|
|
4
|
+
* h264bsd only handles Baseline; this backend covers Main/High. The KMP glue
|
|
5
|
+
* exposes a synchronous decoder whose output is a packed I420 blob with a
|
|
6
|
+
* 64-byte header.
|
|
7
|
+
*/
|
|
8
|
+
import type { VideoTrack } from '../types';
|
|
9
|
+
import type { SoftFrame, SoftVideoDecoder } from './types';
|
|
10
|
+
export declare class OpenH264Decoder implements SoftVideoDecoder {
|
|
11
|
+
readonly name = "OpenH264";
|
|
12
|
+
private shim;
|
|
13
|
+
private handle;
|
|
14
|
+
private parameterSets;
|
|
15
|
+
configure(track: VideoTrack): Promise<void>;
|
|
16
|
+
init(loader: () => Promise<unknown>): Promise<void>;
|
|
17
|
+
decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[];
|
|
18
|
+
flush(): SoftFrame[];
|
|
19
|
+
private takeFrame;
|
|
20
|
+
close(): void;
|
|
21
|
+
}
|
|
@@ -30,8 +30,8 @@ export interface SoftVideoDecoder {
|
|
|
30
30
|
/** Load the WebAssembly module and create the decoder instance. */
|
|
31
31
|
init(loader: SoftModuleLoader): Promise<void>;
|
|
32
32
|
/** `annexB` is one complete access unit (start codes included). */
|
|
33
|
-
decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[]
|
|
34
|
-
flush(): SoftFrame[]
|
|
33
|
+
decode(annexB: Uint8Array, ptsUs: number, keyframe: boolean): SoftFrame[] | Promise<SoftFrame[]>;
|
|
34
|
+
flush(): SoftFrame[] | Promise<SoftFrame[]>;
|
|
35
35
|
close(): void;
|
|
36
36
|
}
|
|
37
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;
|