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.
- package/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +440 -2
- package/dist/fluxkit.js +3963 -0
- package/dist/fluxkit.js.map +1 -0
- package/dist/fluxkit.umd.cjs +22 -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 +46 -0
- package/dist/types/demux/flv.d.ts +46 -0
- package/dist/types/demux/hls.d.ts +54 -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 +31 -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 +11 -0
- package/dist/types/player.d.ts +110 -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 +48 -0
- package/dist/types/render/mse.d.ts +49 -0
- package/dist/types/render/software.d.ts +77 -0
- package/dist/types/render/webcodecs.d.ts +69 -0
- package/dist/types/soft/h264bsd.d.ts +23 -0
- package/dist/types/soft/index.d.ts +9 -0
- package/dist/types/soft/libde265.d.ts +16 -0
- package/dist/types/soft/types.d.ts +37 -0
- package/dist/types/source/hls.d.ts +29 -0
- package/dist/types/source/stream.d.ts +22 -0
- package/dist/types/types.d.ts +246 -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/package.json +77 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** AAC / ADTS / AudioSpecificConfig helpers. */
|
|
2
|
+
export declare const AAC_SAMPLE_RATES: number[];
|
|
3
|
+
export interface AdtsHeader {
|
|
4
|
+
objectType: number;
|
|
5
|
+
sampleRate: number;
|
|
6
|
+
sampleRateIndex: number;
|
|
7
|
+
channels: number;
|
|
8
|
+
frameLength: number;
|
|
9
|
+
headerLength: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function parseAdts(data: Uint8Array, offset?: number): AdtsHeader | null;
|
|
12
|
+
export declare function buildAudioSpecificConfig(objectType: number, sampleRate: number, channels: number): Uint8Array;
|
|
13
|
+
export interface AudioSpecificConfig {
|
|
14
|
+
objectType: number;
|
|
15
|
+
sampleRate: number;
|
|
16
|
+
channels: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function parseAudioSpecificConfig(asc: Uint8Array): AudioSpecificConfig;
|
|
19
|
+
export declare function aacCodecString(asc?: Uint8Array): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Exp-Golomb bit reader used by H.264 / H.265 SPS parsers. */
|
|
2
|
+
export declare class BitReader {
|
|
3
|
+
private readonly data;
|
|
4
|
+
private bitPos;
|
|
5
|
+
constructor(data: Uint8Array, bitOffset?: number);
|
|
6
|
+
get bitsLeft(): number;
|
|
7
|
+
skip(bits: number): void;
|
|
8
|
+
u1(): number;
|
|
9
|
+
/** Read up to 32 bits, big-endian. */
|
|
10
|
+
u(bits: number): number;
|
|
11
|
+
ue(): number;
|
|
12
|
+
se(): number;
|
|
13
|
+
}
|
|
14
|
+
/** Strip H.264/H.265 emulation-prevention bytes (0x00 0x00 0x03 -> 0x00 0x00). */
|
|
15
|
+
export declare function unescapeRbsp(data: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AvcSpsInfo } from './h264';
|
|
2
|
+
import { type HevcSpsInfo } from './h265';
|
|
3
|
+
export interface AvcCConfig {
|
|
4
|
+
nalLengthSize: number;
|
|
5
|
+
sps: Uint8Array[];
|
|
6
|
+
pps: Uint8Array[];
|
|
7
|
+
info: AvcSpsInfo | null;
|
|
8
|
+
}
|
|
9
|
+
export interface HvcCConfig {
|
|
10
|
+
nalLengthSize: number;
|
|
11
|
+
vps: Uint8Array[];
|
|
12
|
+
sps: Uint8Array[];
|
|
13
|
+
pps: Uint8Array[];
|
|
14
|
+
info: HevcSpsInfo | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseAvcC(data: Uint8Array): AvcCConfig;
|
|
17
|
+
export declare function parseHvcC(data: Uint8Array): HvcCConfig;
|
|
18
|
+
/** Read a 24-bit signed composition time offset. */
|
|
19
|
+
export declare function readI24(data: Uint8Array, offset: number): number;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** G.711 A-law / μ-law codecs (used by IP cameras inside FLV). */
|
|
2
|
+
export type G711Law = 'alaw' | 'ulaw';
|
|
3
|
+
export declare function decodeG711(data: Uint8Array, law: G711Law): Int16Array;
|
|
4
|
+
export declare function decodeG711Float(data: Uint8Array, law: G711Law): Float32Array;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const AVC_NAL: {
|
|
2
|
+
readonly SLICE: 1;
|
|
3
|
+
readonly IDR: 5;
|
|
4
|
+
readonly SEI: 6;
|
|
5
|
+
readonly SPS: 7;
|
|
6
|
+
readonly PPS: 8;
|
|
7
|
+
readonly AUD: 9;
|
|
8
|
+
};
|
|
9
|
+
export declare function avcNalType(nal: Uint8Array): number;
|
|
10
|
+
/** Split an Annex-B byte stream into NAL units (start codes removed). */
|
|
11
|
+
export declare function splitAnnexB(data: Uint8Array): Uint8Array[];
|
|
12
|
+
/** Convert NAL units to length-prefixed (AVCC) form. */
|
|
13
|
+
export declare function nalsToAvcc(nals: Uint8Array[], lengthSize?: number): Uint8Array;
|
|
14
|
+
export interface AvcSpsInfo {
|
|
15
|
+
profile: number;
|
|
16
|
+
compat: number;
|
|
17
|
+
level: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
fps?: number;
|
|
21
|
+
chromaFormat: number;
|
|
22
|
+
bitDepthLuma: number;
|
|
23
|
+
bitDepthChroma: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function parseAvcSps(nal: Uint8Array): AvcSpsInfo;
|
|
26
|
+
/** Build an AVCDecoderConfigurationRecord (avcC). */
|
|
27
|
+
export declare function buildAvcC(spsList: Uint8Array[], ppsList: Uint8Array[], info: AvcSpsInfo, lengthSize?: number): Uint8Array;
|
|
28
|
+
export declare function avcCodecString(avcC: Uint8Array): string;
|
|
29
|
+
export declare function avcProfileLevel(avcC: Uint8Array): {
|
|
30
|
+
profile: number;
|
|
31
|
+
level: number;
|
|
32
|
+
compat: number;
|
|
33
|
+
};
|
|
34
|
+
/** Convert an AVCC access unit back to Annex-B (used by gateways / debugging). */
|
|
35
|
+
export declare function avccToAnnexB(data: Uint8Array, lengthSize?: number): Uint8Array;
|
|
36
|
+
/** True when the first NAL in an access unit is an IDR slice. */
|
|
37
|
+
export declare function isAvcKeyframe(data: Uint8Array, lengthSize?: number): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const HEVC_NAL: {
|
|
2
|
+
readonly VPS: 32;
|
|
3
|
+
readonly SPS: 33;
|
|
4
|
+
readonly PPS: 34;
|
|
5
|
+
readonly AUD: 35;
|
|
6
|
+
readonly PREFIX_SEI: 39;
|
|
7
|
+
readonly SUFFIX_SEI: 40;
|
|
8
|
+
};
|
|
9
|
+
export declare function hevcNalType(nal: Uint8Array): number;
|
|
10
|
+
export interface HevcSpsInfo {
|
|
11
|
+
profileSpace: number;
|
|
12
|
+
tier: number;
|
|
13
|
+
profileIdc: number;
|
|
14
|
+
compatFlags: number;
|
|
15
|
+
constraintFlags: Uint8Array;
|
|
16
|
+
levelIdc: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
chromaFormat: number;
|
|
20
|
+
bitDepthLuma: number;
|
|
21
|
+
bitDepthChroma: number;
|
|
22
|
+
maxSubLayers: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function parseHevcSps(nal: Uint8Array): HevcSpsInfo;
|
|
25
|
+
export declare function buildHvcC(info: HevcSpsInfo, vps: Uint8Array, sps: Uint8Array, pps: Uint8Array, lengthSize?: number): Uint8Array;
|
|
26
|
+
export declare function hevcCodecString(hvcC: Uint8Array): string;
|
|
27
|
+
export declare function isHevcKeyframe(data: Uint8Array, lengthSize?: number): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FluxKitOptions, LogLevel } from './types';
|
|
2
|
+
export interface ResolvedOptions extends Required<Omit<FluxKitOptions, 'logger' | 'hls' | 'webcodecs' | 'headers' | 'retry' | 'softDecode'>> {
|
|
3
|
+
logger?: FluxKitOptions['logger'];
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
retry: {
|
|
6
|
+
maxRetries: number;
|
|
7
|
+
delay: number;
|
|
8
|
+
maxDelay: number;
|
|
9
|
+
};
|
|
10
|
+
hls: {
|
|
11
|
+
mode: 'demux' | 'native';
|
|
12
|
+
maxBandwidth?: number;
|
|
13
|
+
liveReloadFactor: number;
|
|
14
|
+
};
|
|
15
|
+
webcodecs: {
|
|
16
|
+
fit: 'contain' | 'cover' | 'fill';
|
|
17
|
+
audioBuffer: number;
|
|
18
|
+
};
|
|
19
|
+
softDecode: {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
maxDecodeAhead: number;
|
|
22
|
+
dropLateFrames: boolean;
|
|
23
|
+
loaders?: {
|
|
24
|
+
avc?: () => Promise<unknown>;
|
|
25
|
+
hevc?: () => Promise<unknown>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare const DEFAULTS: {
|
|
30
|
+
decoder: "auto";
|
|
31
|
+
protocol: "native";
|
|
32
|
+
autoplay: boolean;
|
|
33
|
+
muted: boolean;
|
|
34
|
+
loop: boolean;
|
|
35
|
+
volume: number;
|
|
36
|
+
logLevel: LogLevel;
|
|
37
|
+
allowNativeFallback: boolean;
|
|
38
|
+
hardwareAcceleration: "prefer-hardware";
|
|
39
|
+
segmentDuration: number;
|
|
40
|
+
liveBufferTarget: number;
|
|
41
|
+
catchUp: boolean;
|
|
42
|
+
timeout: number;
|
|
43
|
+
};
|
|
44
|
+
export declare function resolveOptions(options?: FluxKitOptions): ResolvedOptions;
|
|
45
|
+
/** Map a URL to the container/transport we should use. */
|
|
46
|
+
export declare function detectProtocol(url: string): import('./types').Protocol;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FLV demuxer.
|
|
3
|
+
*
|
|
4
|
+
* Handles plain FLV, HTTP-FLV and WS-FLV.
|
|
5
|
+
* Supports AVC, HEVC (legacy codecId 12 and Enhanced-RTMP `hvc1` fourCC),
|
|
6
|
+
* AAC, MP3 and onMetaData.
|
|
7
|
+
*/
|
|
8
|
+
import type { Demuxer, DemuxerSink } from '../types';
|
|
9
|
+
export declare const FLV_TIMESCALE = 1000;
|
|
10
|
+
export type FlvTagHandler = (type: number, timestamp: number, data: Uint8Array) => void;
|
|
11
|
+
/** Splits a byte stream into FLV tags. */
|
|
12
|
+
export declare class FlvTagParser {
|
|
13
|
+
private readonly onTag;
|
|
14
|
+
private buf;
|
|
15
|
+
private headerParsed;
|
|
16
|
+
constructor(onTag: FlvTagHandler);
|
|
17
|
+
push(chunk: Uint8Array): void;
|
|
18
|
+
flush(): void;
|
|
19
|
+
reset(): void;
|
|
20
|
+
private parse;
|
|
21
|
+
}
|
|
22
|
+
export declare class FlvDemuxer implements Demuxer {
|
|
23
|
+
private readonly sink;
|
|
24
|
+
readonly format = "flv";
|
|
25
|
+
private readonly parser;
|
|
26
|
+
private videoTrack;
|
|
27
|
+
private audioTrack;
|
|
28
|
+
private meta;
|
|
29
|
+
private warnedUnsupported;
|
|
30
|
+
constructor(sink: DemuxerSink);
|
|
31
|
+
push(chunk: Uint8Array): void;
|
|
32
|
+
/** Feed an already-demuxed FLV tag (for custom transports). */
|
|
33
|
+
pushTag(type: number, timestamp: number, data: Uint8Array): void;
|
|
34
|
+
flush(): void;
|
|
35
|
+
reset(): void;
|
|
36
|
+
private tracks;
|
|
37
|
+
private handleTag;
|
|
38
|
+
private handleScript;
|
|
39
|
+
private applyMetaSize;
|
|
40
|
+
private handleVideo;
|
|
41
|
+
private configureAvc;
|
|
42
|
+
private configureHevc;
|
|
43
|
+
private handleAudio;
|
|
44
|
+
private configureAac;
|
|
45
|
+
private warnOnce;
|
|
46
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** HLS playlist (m3u8) parsing. */
|
|
2
|
+
export interface HlsVariant {
|
|
3
|
+
uri: string;
|
|
4
|
+
bandwidth: number;
|
|
5
|
+
resolution?: string;
|
|
6
|
+
codecs?: string;
|
|
7
|
+
frameRate?: number;
|
|
8
|
+
audioGroup?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HlsRendition {
|
|
11
|
+
type: string;
|
|
12
|
+
groupId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
uri?: string;
|
|
15
|
+
default: boolean;
|
|
16
|
+
autoselect: boolean;
|
|
17
|
+
language?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface HlsKey {
|
|
20
|
+
method: string;
|
|
21
|
+
uri?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface HlsByteRange {
|
|
24
|
+
offset: number;
|
|
25
|
+
length: number;
|
|
26
|
+
}
|
|
27
|
+
export interface HlsSegment {
|
|
28
|
+
uri: string;
|
|
29
|
+
duration: number;
|
|
30
|
+
sequence: number;
|
|
31
|
+
discontinuity: boolean;
|
|
32
|
+
byterange?: HlsByteRange;
|
|
33
|
+
map?: string;
|
|
34
|
+
mapByterange?: HlsByteRange;
|
|
35
|
+
key?: HlsKey;
|
|
36
|
+
}
|
|
37
|
+
export interface HlsMediaPlaylist {
|
|
38
|
+
targetDuration: number;
|
|
39
|
+
mediaSequence: number;
|
|
40
|
+
segments: HlsSegment[];
|
|
41
|
+
endList: boolean;
|
|
42
|
+
map?: string;
|
|
43
|
+
mapByterange?: HlsByteRange;
|
|
44
|
+
encrypted: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function resolveUrl(uri: string, base: string): string;
|
|
47
|
+
/** Parse `KEY=VALUE,KEY="a,b"` attribute lists. */
|
|
48
|
+
export declare function parseAttributes(input: string): Record<string, string>;
|
|
49
|
+
export declare function parseMasterPlaylist(text: string, baseUrl: string): HlsVariant[];
|
|
50
|
+
/** `#EXT-X-MEDIA` entries (alternate audio / subtitles). */
|
|
51
|
+
export declare function parseMediaRenditions(text: string, baseUrl: string): HlsRendition[];
|
|
52
|
+
export declare function parseMediaPlaylist(text: string, baseUrl: string): HlsMediaPlaylist;
|
|
53
|
+
/** Pick a variant under the bitrate cap, preferring the highest quality. */
|
|
54
|
+
export declare function selectVariant(variants: HlsVariant[], maxBandwidth?: number): HlsVariant | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MP4 / fMP4 demuxer.
|
|
3
|
+
*
|
|
4
|
+
* Streaming design: boxes are parsed as they arrive and mdat payloads are
|
|
5
|
+
* sliced into samples on the fly, so HTTP-FMP4 starts playing before the
|
|
6
|
+
* segment finishes downloading. Non-fragmented MP4 is supported when `moov`
|
|
7
|
+
* precedes `mdat` (faststart), which is what streaming services ship.
|
|
8
|
+
*/
|
|
9
|
+
import type { Demuxer, DemuxerSink } from '../types';
|
|
10
|
+
export declare class Mp4Demuxer implements Demuxer {
|
|
11
|
+
private readonly sink;
|
|
12
|
+
readonly format = "mp4";
|
|
13
|
+
private buf;
|
|
14
|
+
private bufStart;
|
|
15
|
+
private skipBytes;
|
|
16
|
+
private state;
|
|
17
|
+
private mdatEnd;
|
|
18
|
+
private pending;
|
|
19
|
+
private pendingIndex;
|
|
20
|
+
private moovDone;
|
|
21
|
+
private sawMdatFirst;
|
|
22
|
+
private mediaDuration;
|
|
23
|
+
private readonly tracks;
|
|
24
|
+
constructor(sink: DemuxerSink);
|
|
25
|
+
private sawMoof;
|
|
26
|
+
get fragmented(): boolean;
|
|
27
|
+
/** Movie duration in seconds from mvhd, when present. */
|
|
28
|
+
get duration(): number | undefined;
|
|
29
|
+
push(chunk: Uint8Array): void;
|
|
30
|
+
flush(): void;
|
|
31
|
+
reset(): void;
|
|
32
|
+
private consume;
|
|
33
|
+
/** Drop n bytes that we never need, buffering only what has arrived. */
|
|
34
|
+
private skipAhead;
|
|
35
|
+
private parse;
|
|
36
|
+
private pumpMdat;
|
|
37
|
+
private handleBox;
|
|
38
|
+
private parseMoov;
|
|
39
|
+
private parseTrak;
|
|
40
|
+
private hasSampleTable;
|
|
41
|
+
private buildSampleTable;
|
|
42
|
+
private parseVideoTrack;
|
|
43
|
+
private parseAudioTrack;
|
|
44
|
+
private parseMoof;
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MPEG-TS demuxer used for HLS.
|
|
3
|
+
*
|
|
4
|
+
* Reads PAT/PMT, reassembles PES packets, converts Annex-B NAL units into
|
|
5
|
+
* AVCC access units and ADTS AAC into raw frames. Produces 90 kHz timestamps.
|
|
6
|
+
*/
|
|
7
|
+
import type { Demuxer, DemuxerSink } from '../types';
|
|
8
|
+
export declare const TS_TIMESCALE = 90000;
|
|
9
|
+
export declare class TsDemuxer implements Demuxer {
|
|
10
|
+
private readonly sink;
|
|
11
|
+
readonly format = "ts";
|
|
12
|
+
private buf;
|
|
13
|
+
private packetSize;
|
|
14
|
+
private syncOffset;
|
|
15
|
+
private synced;
|
|
16
|
+
private pmtPid;
|
|
17
|
+
private readonly streams;
|
|
18
|
+
private readonly tracks;
|
|
19
|
+
private videoPid;
|
|
20
|
+
private audioPid;
|
|
21
|
+
private warned;
|
|
22
|
+
constructor(sink: DemuxerSink);
|
|
23
|
+
push(chunk: Uint8Array): void;
|
|
24
|
+
flush(): void;
|
|
25
|
+
reset(): void;
|
|
26
|
+
private parse;
|
|
27
|
+
private detectPacketSize;
|
|
28
|
+
private resync;
|
|
29
|
+
private consumePacket;
|
|
30
|
+
private handleSection;
|
|
31
|
+
private parsePmt;
|
|
32
|
+
private addStream;
|
|
33
|
+
private finishPes;
|
|
34
|
+
private unwrap;
|
|
35
|
+
private handleVideoPes;
|
|
36
|
+
private maybeBuildVideoTrack;
|
|
37
|
+
private flushAu;
|
|
38
|
+
private handleAudioPes;
|
|
39
|
+
private buildAudioTrack;
|
|
40
|
+
private warnOnce;
|
|
41
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FluxKit public entry point.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { FluxKit, VERSION } from './player';
|
|
7
|
+
export { FluxKit as default } from './player';
|
|
8
|
+
export * from './types';
|
|
9
|
+
export { resolveOptions, detectProtocol, DEFAULTS } from './config';
|
|
10
|
+
export { FlvDemuxer, FlvTagParser, FLV_TIMESCALE } from './demux/flv';
|
|
11
|
+
export { Mp4Demuxer } from './demux/mp4';
|
|
12
|
+
export { TsDemuxer, TS_TIMESCALE } from './demux/ts';
|
|
13
|
+
export { parseMasterPlaylist, parseMediaPlaylist, parseMediaRenditions, parseAttributes, selectVariant, resolveUrl, type HlsMediaPlaylist, type HlsSegment, type HlsVariant, } from './demux/hls';
|
|
14
|
+
export { StreamSource } from './source/stream';
|
|
15
|
+
export { HlsSource } from './source/hls';
|
|
16
|
+
export { MseRenderer } from './render/mse';
|
|
17
|
+
export { WebCodecsRenderer, isWebCodecsSupported } from './render/webcodecs';
|
|
18
|
+
export { SoftwareRenderer } from './render/software';
|
|
19
|
+
export { createSoftwareDecoder, type SoftFrame, type SoftVideoDecoder, type SoftLoaders } from './soft';
|
|
20
|
+
export { Libde265Decoder } from './soft/libde265';
|
|
21
|
+
export { H264BsdDecoder } from './soft/h264bsd';
|
|
22
|
+
export { buildInitSegment, Fmp4Muxer, mimeTypeFor, videoMimeType, audioMimeType, codecLabel, } from './remux/fmp4';
|
|
23
|
+
export { parseAvcSps, buildAvcC, avcCodecString, avccToAnnexB, splitAnnexB, nalsToAvcc, isAvcKeyframe, } from './codec/h264';
|
|
24
|
+
export { parseHevcSps, buildHvcC, hevcCodecString, isHevcKeyframe } from './codec/h265';
|
|
25
|
+
export { parseAudioSpecificConfig, buildAudioSpecificConfig, aacCodecString, parseAdts, } from './codec/aac';
|
|
26
|
+
export { parseAvcC, parseHvcC } from './codec/config';
|
|
27
|
+
export { HttpStream, fetchText, fetchBytes } from './io/http';
|
|
28
|
+
export { WsTransport, WsStream } from './io/websocket';
|
|
29
|
+
export { encodeAmf0, decodeAmf0, encodeAmf0Values, decodeAmf0All } from './protocol/amf0';
|
|
30
|
+
export { Timeline } from './pipeline/timeline';
|
|
31
|
+
export { Segmenter } from './pipeline/segmenter';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface StreamSink {
|
|
2
|
+
onData(chunk: Uint8Array): void;
|
|
3
|
+
onEnd(): void;
|
|
4
|
+
onError(err: Error): void;
|
|
5
|
+
onResponse?(meta: {
|
|
6
|
+
status: number;
|
|
7
|
+
contentType: string | null;
|
|
8
|
+
contentLength: number | null;
|
|
9
|
+
url: string;
|
|
10
|
+
}): void;
|
|
11
|
+
}
|
|
12
|
+
export interface HttpOptions {
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
retry?: {
|
|
16
|
+
maxRetries: number;
|
|
17
|
+
delay: number;
|
|
18
|
+
maxDelay: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class HttpStream {
|
|
22
|
+
private controller;
|
|
23
|
+
private paused;
|
|
24
|
+
private resumeWaiters;
|
|
25
|
+
pause(): void;
|
|
26
|
+
resume(): void;
|
|
27
|
+
private waitIfPaused;
|
|
28
|
+
start(url: string, sink: StreamSink, options?: HttpOptions): Promise<void>;
|
|
29
|
+
stop(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function fetchText(url: string, options?: HttpOptions): Promise<string>;
|
|
32
|
+
export declare function fetchBytes(url: string, options?: HttpOptions): Promise<Uint8Array>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** WebSocket transport for WS-FLV. */
|
|
2
|
+
export interface WsOptions {
|
|
3
|
+
timeout?: number;
|
|
4
|
+
protocols?: string | string[];
|
|
5
|
+
}
|
|
6
|
+
export declare class WsTransport {
|
|
7
|
+
private socket;
|
|
8
|
+
private closedByUs;
|
|
9
|
+
onData?: (data: Uint8Array) => void;
|
|
10
|
+
onText?: (text: string) => void;
|
|
11
|
+
onClose?: (clean: boolean) => void;
|
|
12
|
+
onError?: (err: Error) => void;
|
|
13
|
+
get readyState(): number;
|
|
14
|
+
connect(url: string, options?: WsOptions): Promise<void>;
|
|
15
|
+
send(data: Uint8Array | string): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
/** WS-FLV: raw FLV bytes pushed from a WebSocket. */
|
|
19
|
+
export declare class WsStream {
|
|
20
|
+
private transport;
|
|
21
|
+
start(url: string, sink: {
|
|
22
|
+
onData: (chunk: Uint8Array) => void;
|
|
23
|
+
onEnd: () => void;
|
|
24
|
+
onError: (err: Error) => void;
|
|
25
|
+
}, options?: WsOptions): Promise<void>;
|
|
26
|
+
stop(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Groups samples into MSE-friendly fragments, cutting on video keyframes. */
|
|
2
|
+
import type { Sample, Track } from '../types';
|
|
3
|
+
export interface SegmenterOptions {
|
|
4
|
+
durationMs: number;
|
|
5
|
+
onSegment: (track: Track, samples: Sample[]) => void;
|
|
6
|
+
getTrack: (id: number) => Track | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare class Segmenter {
|
|
9
|
+
private readonly options;
|
|
10
|
+
private readonly buffers;
|
|
11
|
+
private windowStart;
|
|
12
|
+
constructor(options: SegmenterOptions);
|
|
13
|
+
push(sample: Sample): void;
|
|
14
|
+
private hasSamples;
|
|
15
|
+
flush(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Timeline normalization: origin, 33-bit wrap tolerance and monotonic DTS. */
|
|
2
|
+
import type { Sample, Track } from '../types';
|
|
3
|
+
export declare class Timeline {
|
|
4
|
+
private readonly tracks;
|
|
5
|
+
private baseMs;
|
|
6
|
+
private startMs;
|
|
7
|
+
private readonly lastDts;
|
|
8
|
+
constructor(tracks: Map<number, Track>);
|
|
9
|
+
setStart(startMs: number): void;
|
|
10
|
+
normalize(sample: Sample): Sample;
|
|
11
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FluxKit player façade.
|
|
3
|
+
*
|
|
4
|
+
* const player = new FluxKit('#stage', { decoder: 'auto' });
|
|
5
|
+
* await player.load('https://example.com/live/stream.flv');
|
|
6
|
+
*
|
|
7
|
+
* The player wires a Source (container + transport) into a Timeline, a
|
|
8
|
+
* Segmenter, and a Renderer (MSE or WebCodecs), and exposes playback controls
|
|
9
|
+
* plus typed events.
|
|
10
|
+
*/
|
|
11
|
+
import type { FluxKitOptions, LoadOptions, PlayerEvents, PlayerStats, Protocol, Track } from './types';
|
|
12
|
+
export declare const VERSION = "0.1.0";
|
|
13
|
+
export declare class FluxKit {
|
|
14
|
+
static readonly version = "0.1.0";
|
|
15
|
+
static isSupported(): boolean;
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private readonly emitter;
|
|
19
|
+
private readonly stage;
|
|
20
|
+
private readonly video;
|
|
21
|
+
private readonly canvas;
|
|
22
|
+
private readonly tracks;
|
|
23
|
+
private readonly timeline;
|
|
24
|
+
private readonly segmenter;
|
|
25
|
+
private source;
|
|
26
|
+
private renderer;
|
|
27
|
+
private rendererPromise;
|
|
28
|
+
private lastRendererError;
|
|
29
|
+
private url;
|
|
30
|
+
private protocol;
|
|
31
|
+
private live;
|
|
32
|
+
private startMs;
|
|
33
|
+
private nativeMode;
|
|
34
|
+
private loadId;
|
|
35
|
+
private destroyed;
|
|
36
|
+
private preBuffer;
|
|
37
|
+
private readyDeferred;
|
|
38
|
+
private readonly switchAttempts;
|
|
39
|
+
private pendingSeek;
|
|
40
|
+
private statsTimer;
|
|
41
|
+
private lastStats;
|
|
42
|
+
private bytes;
|
|
43
|
+
private lastBytes;
|
|
44
|
+
private lastStatsAt;
|
|
45
|
+
private lastFrames;
|
|
46
|
+
private lastFpsAt;
|
|
47
|
+
private lastWidth;
|
|
48
|
+
private lastHeight;
|
|
49
|
+
private audioOnlyTimer;
|
|
50
|
+
private wcPaused;
|
|
51
|
+
private sourcePaused;
|
|
52
|
+
constructor(target: HTMLElement | string, options?: FluxKitOptions);
|
|
53
|
+
on<K extends keyof PlayerEvents>(type: K, listener: (event: PlayerEvents[K]) => void): () => void;
|
|
54
|
+
once<K extends keyof PlayerEvents>(type: K, listener: (event: PlayerEvents[K]) => void): () => void;
|
|
55
|
+
off<K extends keyof PlayerEvents>(type: K, listener: (event: PlayerEvents[K]) => void): void;
|
|
56
|
+
get videoElement(): HTMLVideoElement;
|
|
57
|
+
get canvasElement(): HTMLCanvasElement;
|
|
58
|
+
get currentProtocol(): Protocol;
|
|
59
|
+
/** Tracks discovered so far (video + audio). */
|
|
60
|
+
get mediaTracks(): Track[];
|
|
61
|
+
get isLive(): boolean;
|
|
62
|
+
get decoderMode(): string;
|
|
63
|
+
get stats(): PlayerStats;
|
|
64
|
+
/** Current playback position in milliseconds. */
|
|
65
|
+
get currentTime(): number;
|
|
66
|
+
/** Duration in milliseconds; Infinity for live streams. */
|
|
67
|
+
get duration(): number;
|
|
68
|
+
get paused(): boolean;
|
|
69
|
+
get volume(): number;
|
|
70
|
+
setVolume(volume: number): void;
|
|
71
|
+
setMuted(muted: boolean): void;
|
|
72
|
+
/** Applies to the next load(). */
|
|
73
|
+
setDecoderMode(mode: FluxKitOptions['decoder']): void;
|
|
74
|
+
/** Applies to the next load(). */
|
|
75
|
+
setNativeFallback(enabled: boolean): void;
|
|
76
|
+
/** Enable/disable the WASM software decoding fallback. */
|
|
77
|
+
setSoftDecode(enabled: boolean): void;
|
|
78
|
+
load(url: string, options?: LoadOptions): Promise<void>;
|
|
79
|
+
play(): Promise<void>;
|
|
80
|
+
pause(): void;
|
|
81
|
+
seek(ms: number): Promise<void>;
|
|
82
|
+
/** Tear down the current stream but keep the player reusable. */
|
|
83
|
+
stop(): void;
|
|
84
|
+
destroy(): void;
|
|
85
|
+
private shouldUseNative;
|
|
86
|
+
private createSource;
|
|
87
|
+
private onTracks;
|
|
88
|
+
private emitMetadata;
|
|
89
|
+
private startRenderer;
|
|
90
|
+
private createRenderer;
|
|
91
|
+
private onSample;
|
|
92
|
+
private onSourceEnd;
|
|
93
|
+
private onSourceError;
|
|
94
|
+
private tryNativeFallback;
|
|
95
|
+
private switchProtocol;
|
|
96
|
+
private restartAt;
|
|
97
|
+
private buildSourceContext;
|
|
98
|
+
private startNative;
|
|
99
|
+
private safeAutoplay;
|
|
100
|
+
private startStats;
|
|
101
|
+
private get bufferAhead();
|
|
102
|
+
private updateStats;
|
|
103
|
+
private findCodec;
|
|
104
|
+
private bindVideoEvents;
|
|
105
|
+
private showRenderer;
|
|
106
|
+
private clearAudioOnlyTimer;
|
|
107
|
+
private stopPipeline;
|
|
108
|
+
private stopInternal;
|
|
109
|
+
}
|
|
110
|
+
export default FluxKit;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type AmfValue = number | string | boolean | null | undefined | AmfObject | AmfValue[];
|
|
2
|
+
export interface AmfObject {
|
|
3
|
+
[key: string]: AmfValue;
|
|
4
|
+
}
|
|
5
|
+
export interface AmfDecodeResult {
|
|
6
|
+
value: AmfValue | undefined;
|
|
7
|
+
offset: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function decodeAmf0(data: Uint8Array, offset?: number): AmfDecodeResult;
|
|
10
|
+
export declare function decodeAmf0All(data: Uint8Array): AmfValue[];
|
|
11
|
+
export declare function encodeAmf0(value: AmfValue): Uint8Array;
|
|
12
|
+
export declare function encodeAmf0Values(...values: AmfValue[]): Uint8Array;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fragmented MP4 muxer.
|
|
3
|
+
*
|
|
4
|
+
* Turns demuxer output (AVCC samples + avcC/hvcC/AudioSpecificConfig) into
|
|
5
|
+
* standards-compliant fMP4 that MSE can append:
|
|
6
|
+
*
|
|
7
|
+
* init segment: ftyp + moov (one track, mvex/trex)
|
|
8
|
+
* media segment: moof (mfhd/traf/tfhd/tfdt/trun) + mdat
|
|
9
|
+
*
|
|
10
|
+
* One track per init segment keeps SourceBuffer ownership simple.
|
|
11
|
+
*/
|
|
12
|
+
import type { AudioTrack, Sample, Track, VideoTrack } from '../types';
|
|
13
|
+
export declare function buildInitSegment(track: Track): Uint8Array;
|
|
14
|
+
export declare function videoMimeType(track: VideoTrack): string;
|
|
15
|
+
export declare function audioMimeType(track: AudioTrack): string;
|
|
16
|
+
export declare function mimeTypeFor(track: Track): string;
|
|
17
|
+
export declare function codecLabel(track: Track): string;
|
|
18
|
+
/**
|
|
19
|
+
* Builds media segments for a single track.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Fmp4Muxer {
|
|
22
|
+
readonly track: Track;
|
|
23
|
+
private sequence;
|
|
24
|
+
private readonly fallbackDuration;
|
|
25
|
+
constructor(track: Track);
|
|
26
|
+
initSegment(): Uint8Array;
|
|
27
|
+
reset(): void;
|
|
28
|
+
/** Build one moof+mdat segment from samples sorted by dts. */
|
|
29
|
+
fragment(samples: Sample[]): Uint8Array;
|
|
30
|
+
/** Ensure dts strictly increases; a non-monotonic DTS makes MSE stall. */
|
|
31
|
+
private normalize;
|
|
32
|
+
}
|