node-av-light 0.0.0 → 7.1.0-beta.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/LICENSE.md +22 -0
- package/README.md +711 -0
- package/dist/api/audio-frame-buffer.d.ts +636 -0
- package/dist/api/audio-frame-buffer.js +1027 -0
- package/dist/api/audio-frame-buffer.js.map +1 -0
- package/dist/api/bitstream-filter.d.ts +938 -0
- package/dist/api/bitstream-filter.js +1427 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/constants.d.ts +44 -0
- package/dist/api/constants.js +45 -0
- package/dist/api/constants.js.map +1 -0
- package/dist/api/data/test_av1.ivf +0 -0
- package/dist/api/data/test_h264.h264 +0 -0
- package/dist/api/data/test_hevc.h265 +0 -0
- package/dist/api/data/test_mjpeg.mjpeg +0 -0
- package/dist/api/data/test_vp8.ivf +0 -0
- package/dist/api/data/test_vp9.ivf +0 -0
- package/dist/api/decoder.d.ts +1413 -0
- package/dist/api/decoder.js +2367 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/demuxer.d.ts +1295 -0
- package/dist/api/demuxer.js +2344 -0
- package/dist/api/demuxer.js.map +1 -0
- package/dist/api/device.d.ts +589 -0
- package/dist/api/device.js +964 -0
- package/dist/api/device.js.map +1 -0
- package/dist/api/encoder-pool.d.ts +262 -0
- package/dist/api/encoder-pool.js +397 -0
- package/dist/api/encoder-pool.js.map +1 -0
- package/dist/api/encoder.d.ts +1509 -0
- package/dist/api/encoder.js +2619 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter-complex.d.ts +828 -0
- package/dist/api/filter-complex.js +1661 -0
- package/dist/api/filter-complex.js.map +1 -0
- package/dist/api/filter-presets.d.ts +800 -0
- package/dist/api/filter-presets.js +1554 -0
- package/dist/api/filter-presets.js.map +1 -0
- package/dist/api/filter.d.ts +1339 -0
- package/dist/api/filter.js +2075 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/fmp4-stream.d.ts +797 -0
- package/dist/api/fmp4-stream.js +1428 -0
- package/dist/api/fmp4-stream.js.map +1 -0
- package/dist/api/hardware.d.ts +677 -0
- package/dist/api/hardware.js +1300 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +21 -0
- package/dist/api/index.js +38 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +308 -0
- package/dist/api/io-stream.js +358 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/muxer.d.ts +1311 -0
- package/dist/api/muxer.js +2672 -0
- package/dist/api/muxer.js.map +1 -0
- package/dist/api/pipeline.d.ts +801 -0
- package/dist/api/pipeline.js +1344 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/probe.d.ts +128 -0
- package/dist/api/probe.js +227 -0
- package/dist/api/probe.js.map +1 -0
- package/dist/api/rtp-stream.d.ts +497 -0
- package/dist/api/rtp-stream.js +1131 -0
- package/dist/api/rtp-stream.js.map +1 -0
- package/dist/api/scaler.d.ts +561 -0
- package/dist/api/scaler.js +918 -0
- package/dist/api/scaler.js.map +1 -0
- package/dist/api/types.d.ts +17 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/async-queue.d.ts +149 -0
- package/dist/api/utilities/async-queue.js +254 -0
- package/dist/api/utilities/async-queue.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +117 -0
- package/dist/api/utilities/audio-sample.js +112 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/audio-transcode.d.ts +20 -0
- package/dist/api/utilities/audio-transcode.js +27 -0
- package/dist/api/utilities/audio-transcode.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +76 -0
- package/dist/api/utilities/channel-layout.js +80 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/codec-format.d.ts +87 -0
- package/dist/api/utilities/codec-format.js +117 -0
- package/dist/api/utilities/codec-format.js.map +1 -0
- package/dist/api/utilities/context-options.d.ts +25 -0
- package/dist/api/utilities/context-options.js +23 -0
- package/dist/api/utilities/context-options.js.map +1 -0
- package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
- package/dist/api/utilities/electron-shared-texture.js +540 -0
- package/dist/api/utilities/electron-shared-texture.js.map +1 -0
- package/dist/api/utilities/image.d.ts +207 -0
- package/dist/api/utilities/image.js +213 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +14 -0
- package/dist/api/utilities/index.js +27 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/live-decoding.d.ts +15 -0
- package/dist/api/utilities/live-decoding.js +32 -0
- package/dist/api/utilities/live-decoding.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +49 -0
- package/dist/api/utilities/media-type.js +53 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
- package/dist/api/utilities/packet-age-watchdog.js +594 -0
- package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +89 -0
- package/dist/api/utilities/pixel-format.js +97 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +129 -0
- package/dist/api/utilities/sample-format.js +141 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/scale-size.d.ts +51 -0
- package/dist/api/utilities/scale-size.js +55 -0
- package/dist/api/utilities/scale-size.js.map +1 -0
- package/dist/api/utilities/scheduler.d.ts +138 -0
- package/dist/api/utilities/scheduler.js +98 -0
- package/dist/api/utilities/scheduler.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +186 -0
- package/dist/api/utilities/streaming.js +309 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +193 -0
- package/dist/api/utilities/timestamp.js +206 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utilities/video-transcode.d.ts +218 -0
- package/dist/api/utilities/video-transcode.js +624 -0
- package/dist/api/utilities/video-transcode.js.map +1 -0
- package/dist/api/utilities/whisper-model.d.ts +330 -0
- package/dist/api/utilities/whisper-model.js +587 -0
- package/dist/api/utilities/whisper-model.js.map +1 -0
- package/dist/api/utils.d.ts +19 -0
- package/dist/api/utils.js +39 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/api/webrtc-stream.d.ts +294 -0
- package/dist/api/webrtc-stream.js +546 -0
- package/dist/api/webrtc-stream.js.map +1 -0
- package/dist/api/whisper.d.ts +326 -0
- package/dist/api/whisper.js +402 -0
- package/dist/api/whisper.js.map +1 -0
- package/dist/constants/bsf-options.d.ts +364 -0
- package/dist/constants/bsf-options.js +7 -0
- package/dist/constants/bsf-options.js.map +1 -0
- package/dist/constants/channel-layouts.d.ts +53 -0
- package/dist/constants/channel-layouts.js +57 -0
- package/dist/constants/channel-layouts.js.map +1 -0
- package/dist/constants/constants.d.ts +2435 -0
- package/dist/constants/constants.js +1989 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/decoders.d.ts +651 -0
- package/dist/constants/decoders.js +641 -0
- package/dist/constants/decoders.js.map +1 -0
- package/dist/constants/encoders.d.ts +314 -0
- package/dist/constants/encoders.js +309 -0
- package/dist/constants/encoders.js.map +1 -0
- package/dist/constants/filter-options.d.ts +12099 -0
- package/dist/constants/filter-options.js +7 -0
- package/dist/constants/filter-options.js.map +1 -0
- package/dist/constants/format-options.d.ts +4319 -0
- package/dist/constants/format-options.js +7 -0
- package/dist/constants/format-options.js.map +1 -0
- package/dist/constants/formats.d.ts +18 -0
- package/dist/constants/formats.js +7 -0
- package/dist/constants/formats.js.map +1 -0
- package/dist/constants/hardware.d.ts +26 -0
- package/dist/constants/hardware.js +27 -0
- package/dist/constants/hardware.js.map +1 -0
- package/dist/constants/index.d.ts +10 -0
- package/dist/constants/index.js +6 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/options.d.ts +6217 -0
- package/dist/constants/options.js +7 -0
- package/dist/constants/options.js.map +1 -0
- package/dist/ffmpeg/index.d.ts +101 -0
- package/dist/ffmpeg/index.js +161 -0
- package/dist/ffmpeg/index.js.map +1 -0
- package/dist/ffmpeg/version.d.ts +6 -0
- package/dist/ffmpeg/version.js +7 -0
- package/dist/ffmpeg/version.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +399 -0
- package/dist/lib/audio-fifo.js +431 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +242 -0
- package/dist/lib/binding.js +102 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +381 -0
- package/dist/lib/bitstream-filter-context.js +443 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +140 -0
- package/dist/lib/bitstream-filter.js +154 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/codec-context.d.ts +1069 -0
- package/dist/lib/codec-context.js +1336 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +664 -0
- package/dist/lib/codec-parameters.js +813 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +201 -0
- package/dist/lib/codec-parser.js +213 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +617 -0
- package/dist/lib/codec.js +746 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/device.d.ts +294 -0
- package/dist/lib/device.js +326 -0
- package/dist/lib/device.js.map +1 -0
- package/dist/lib/dictionary.d.ts +333 -0
- package/dist/lib/dictionary.js +372 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +311 -0
- package/dist/lib/error.js +395 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/fifo.d.ts +416 -0
- package/dist/lib/fifo.js +453 -0
- package/dist/lib/fifo.js.map +1 -0
- package/dist/lib/filter-context.d.ts +714 -0
- package/dist/lib/filter-context.js +783 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph-segment.d.ts +161 -0
- package/dist/lib/filter-graph-segment.js +172 -0
- package/dist/lib/filter-graph-segment.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +641 -0
- package/dist/lib/filter-graph.js +704 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +202 -0
- package/dist/lib/filter-inout.js +261 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +243 -0
- package/dist/lib/filter.js +272 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +1335 -0
- package/dist/lib/format-context.js +1455 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame-utils.d.ts +116 -0
- package/dist/lib/frame-utils.js +98 -0
- package/dist/lib/frame-utils.js.map +1 -0
- package/dist/lib/frame.d.ts +1315 -0
- package/dist/lib/frame.js +1535 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +362 -0
- package/dist/lib/hardware-device-context.js +383 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +418 -0
- package/dist/lib/hardware-frames-context.js +471 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +35 -0
- package/dist/lib/index.js +60 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +249 -0
- package/dist/lib/input-format.js +306 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +698 -0
- package/dist/lib/io-context.js +771 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +174 -0
- package/dist/lib/log.js +184 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +1024 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +953 -0
- package/dist/lib/option.js +1607 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +222 -0
- package/dist/lib/output-format.js +259 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +521 -0
- package/dist/lib/packet.js +613 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +251 -0
- package/dist/lib/rational.js +278 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +552 -0
- package/dist/lib/software-resample-context.js +592 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +344 -0
- package/dist/lib/software-scale-context.js +366 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +383 -0
- package/dist/lib/stream.js +524 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/sync-queue.d.ts +179 -0
- package/dist/lib/sync-queue.js +197 -0
- package/dist/lib/sync-queue.js.map +1 -0
- package/dist/lib/types.d.ts +34 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +1198 -0
- package/dist/lib/utilities.js +1302 -0
- package/dist/lib/utilities.js.map +1 -0
- package/dist/utils/electron.d.ts +49 -0
- package/dist/utils/electron.js +63 -0
- package/dist/utils/electron.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/libc.d.ts +11 -0
- package/dist/utils/libc.js +35 -0
- package/dist/utils/libc.js.map +1 -0
- package/dist/utils/variant.d.ts +26 -0
- package/dist/utils/variant.js +31 -0
- package/dist/utils/variant.js.map +1 -0
- package/dist/webrtc/index.d.ts +4 -0
- package/dist/webrtc/index.js +7 -0
- package/dist/webrtc/index.js.map +1 -0
- package/install/check.js +124 -0
- package/install/ffmpeg.js +66 -0
- package/package.json +165 -3
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { RtpPacket } from 'werift';
|
|
2
|
+
import { Demuxer } from './demuxer.js';
|
|
3
|
+
import type { AVCodecID, AVHWDeviceType, AVSampleFormat, FFAudioEncoder, FFHWDeviceType, FFVideoEncoder } from '../constants/index.js';
|
|
4
|
+
import type { DemuxerOptions } from './demuxer.js';
|
|
5
|
+
import type { EncoderOptions } from './encoder.js';
|
|
6
|
+
import type { MediaFrameSource } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Options for configuring RTP streaming.
|
|
9
|
+
*/
|
|
10
|
+
export interface RTPStreamOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Callback invoked for each video RTP packet.
|
|
13
|
+
* Use this to send packets to your RTP implementation.
|
|
14
|
+
*
|
|
15
|
+
* @param packet - Serialized RTP packet ready for transmission
|
|
16
|
+
*/
|
|
17
|
+
onVideoPacket?: (packet: RtpPacket) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Callback invoked for each audio RTP packet.
|
|
20
|
+
* Use this to send packets to your RTP implementation.
|
|
21
|
+
*
|
|
22
|
+
* @param packet - Serialized RTP packet ready for transmission
|
|
23
|
+
*/
|
|
24
|
+
onAudioPacket?: (packet: RtpPacket) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Callback invoked when the stream is closed or encounters an error.
|
|
27
|
+
*
|
|
28
|
+
* Called once per started session. On an error the stream has already been
|
|
29
|
+
* stopped and its resources (including the input connection) released.
|
|
30
|
+
* Exceptions thrown by the callback are logged and do not propagate.
|
|
31
|
+
*
|
|
32
|
+
* @param error - Optional error if stream closed due to an error
|
|
33
|
+
*/
|
|
34
|
+
onClose?: (error?: Error) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Supported video codec IDs for transcoding decisions.
|
|
37
|
+
* If not provided or empty, all video codecs are supported (passthrough only, no transcoding).
|
|
38
|
+
* If provided, only the specified codecs are supported and transcoding will be performed if needed.
|
|
39
|
+
*/
|
|
40
|
+
supportedVideoCodecs?: (AVCodecID | FFVideoEncoder)[];
|
|
41
|
+
/**
|
|
42
|
+
* Supported audio codec IDs for transcoding decisions.
|
|
43
|
+
* If not provided or empty, all audio codecs are supported (passthrough only, no transcoding).
|
|
44
|
+
* If provided, only the specified codecs are supported and transcoding will be performed if needed.
|
|
45
|
+
*/
|
|
46
|
+
supportedAudioCodecs?: (AVCodecID | FFAudioEncoder)[];
|
|
47
|
+
/**
|
|
48
|
+
* Hardware acceleration configuration.
|
|
49
|
+
*
|
|
50
|
+
* - `'auto'` - Automatically detect and use available hardware acceleration
|
|
51
|
+
* - Object with deviceType - Manually specify hardware acceleration type
|
|
52
|
+
*
|
|
53
|
+
* @default { deviceType: AV_HWDEVICE_TYPE_NONE }
|
|
54
|
+
*/
|
|
55
|
+
hardware?: 'auto' | {
|
|
56
|
+
deviceType: AVHWDeviceType | FFHWDeviceType;
|
|
57
|
+
device?: string;
|
|
58
|
+
options?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Input media options passed to Demuxer.
|
|
62
|
+
*/
|
|
63
|
+
inputOptions?: DemuxerOptions;
|
|
64
|
+
/**
|
|
65
|
+
* Video stream configuration.
|
|
66
|
+
*/
|
|
67
|
+
video?: {
|
|
68
|
+
ssrc?: number;
|
|
69
|
+
payloadType?: number;
|
|
70
|
+
mtu?: number;
|
|
71
|
+
fps?: number;
|
|
72
|
+
width?: number;
|
|
73
|
+
height?: number;
|
|
74
|
+
bitrate?: number;
|
|
75
|
+
dumpExtra?: boolean;
|
|
76
|
+
/** Transcode even when the source codec is one of `supportedVideoCodecs`. */
|
|
77
|
+
transcode?: boolean;
|
|
78
|
+
encoderOptions?: EncoderOptions['options'];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Audio stream configuration.
|
|
82
|
+
*/
|
|
83
|
+
audio?: {
|
|
84
|
+
ssrc?: number;
|
|
85
|
+
payloadType?: number;
|
|
86
|
+
mtu?: number;
|
|
87
|
+
sampleFormat?: AVSampleFormat;
|
|
88
|
+
sampleRate?: number;
|
|
89
|
+
channels?: number;
|
|
90
|
+
/** Transcode even when the source codec is one of `supportedAudioCodecs`. */
|
|
91
|
+
transcode?: boolean;
|
|
92
|
+
encoderOptions?: EncoderOptions['options'];
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* AbortSignal for cancellation.
|
|
96
|
+
*
|
|
97
|
+
* When aborted, the stream stops gracefully, equivalent to calling stop().
|
|
98
|
+
* If already aborted when start() is called, throws AbortError.
|
|
99
|
+
*/
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check whether a streaming-class input is a frame source (not a URL or Demuxer).
|
|
104
|
+
*
|
|
105
|
+
* @param input - The input passed to `create()`
|
|
106
|
+
*
|
|
107
|
+
* @returns True if `input` is a {@link MediaFrameSource}
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
export declare function isMediaFrameSource(input: string | Demuxer | MediaFrameSource): input is MediaFrameSource;
|
|
112
|
+
/**
|
|
113
|
+
* Generic RTP streaming with automatic codec detection and transcoding.
|
|
114
|
+
*
|
|
115
|
+
* Provides library-agnostic RTP streaming for various applications.
|
|
116
|
+
* Automatically detects input codecs and transcodes non-compatible formats.
|
|
117
|
+
* Supports hardware acceleration for video transcoding.
|
|
118
|
+
* Essential component for building RTP streaming servers.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import { RTPStream } from 'node-av/api';
|
|
123
|
+
*
|
|
124
|
+
* // Create stream with RTP packet callbacks
|
|
125
|
+
* const stream = RTPStream.create('rtsp://camera.local/stream', {
|
|
126
|
+
* mtu: 1200,
|
|
127
|
+
* hardware: 'auto',
|
|
128
|
+
* onVideoPacket: (rtp) => {
|
|
129
|
+
* // Send RTP packet
|
|
130
|
+
* sendRtpPacket(rtp);
|
|
131
|
+
* },
|
|
132
|
+
* onAudioPacket: (rtp) => {
|
|
133
|
+
* sendRtpPacket(rtp);
|
|
134
|
+
* }
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Start streaming
|
|
138
|
+
* await stream.start();
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @see {@link Demuxer} For input media handling
|
|
142
|
+
* @see {@link HardwareContext} For GPU acceleration
|
|
143
|
+
*/
|
|
144
|
+
export declare class RTPStream {
|
|
145
|
+
private options;
|
|
146
|
+
private inputUrl;
|
|
147
|
+
private inputOptions;
|
|
148
|
+
private input?;
|
|
149
|
+
private source?;
|
|
150
|
+
private videoOutput?;
|
|
151
|
+
private audioOutput?;
|
|
152
|
+
private hardwareContext?;
|
|
153
|
+
private videoDecoder?;
|
|
154
|
+
private videoFilter?;
|
|
155
|
+
private videoEncoder?;
|
|
156
|
+
private videoBitstreamFilter?;
|
|
157
|
+
private audioDecoder?;
|
|
158
|
+
private audioFilter?;
|
|
159
|
+
private audioEncoder?;
|
|
160
|
+
private pipeline?;
|
|
161
|
+
private startPromise?;
|
|
162
|
+
private signal?;
|
|
163
|
+
private supportedVideoCodecs;
|
|
164
|
+
private supportedAudioCodecs;
|
|
165
|
+
private abortHandler?;
|
|
166
|
+
private stopRequested;
|
|
167
|
+
private stopPromise?;
|
|
168
|
+
private startAbort?;
|
|
169
|
+
private stopSignal;
|
|
170
|
+
/**
|
|
171
|
+
* @param input - Media input URL or pre-opened Demuxer
|
|
172
|
+
*
|
|
173
|
+
* @param options - Stream configuration options
|
|
174
|
+
*
|
|
175
|
+
* Use {@link create} factory method
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
private constructor();
|
|
180
|
+
/**
|
|
181
|
+
* Create an RTP stream from a media source.
|
|
182
|
+
*
|
|
183
|
+
* Configures the stream with input URL and options. The input is not opened
|
|
184
|
+
* until start() is called, allowing the stream to be reused after stop().
|
|
185
|
+
*
|
|
186
|
+
* @param input - Media source URL (RTSP, file path, HTTP, etc.) or a pre-opened {@link Demuxer}
|
|
187
|
+
*
|
|
188
|
+
* @param options - Stream configuration options
|
|
189
|
+
*
|
|
190
|
+
* @returns Configured RTP stream instance
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Stream from RTSP camera
|
|
195
|
+
* const stream = RTPStream.create('rtsp://camera.local/stream', {
|
|
196
|
+
* mtu: 1200,
|
|
197
|
+
* onVideoPacket: (rtp) => sendPacket(rtp),
|
|
198
|
+
* onAudioPacket: (rtp) => sendPacket(rtp)
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* // Stream file with auto hardware acceleration
|
|
205
|
+
* const stream = RTPStream.create('video.mp4', {
|
|
206
|
+
* hardware: 'auto'
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* // Stream from a pre-opened Demuxer (e.g. Device.openScreen())
|
|
213
|
+
* const demuxer = await Device.openScreen({ frameRate: 30 });
|
|
214
|
+
* const stream = RTPStream.create(demuxer, {
|
|
215
|
+
* hardware: 'auto',
|
|
216
|
+
* onVideoPacket: (rtp) => sendPacket(rtp)
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
static create(input: string | Demuxer | MediaFrameSource, options?: RTPStreamOptions): RTPStream;
|
|
221
|
+
/**
|
|
222
|
+
* Check if the stream is active.
|
|
223
|
+
*
|
|
224
|
+
* Stays true while a requested stop is still unwinding: the pipeline reports
|
|
225
|
+
* itself stopped as soon as stop() is called, but its packets keep flowing
|
|
226
|
+
* and its native resources stay open until completion settles.
|
|
227
|
+
*
|
|
228
|
+
* @returns True if the stream is active, false otherwise
|
|
229
|
+
*/
|
|
230
|
+
get isStreamActive(): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Get the demuxer instance.
|
|
233
|
+
*
|
|
234
|
+
* Used for accessing the underlying demuxer.
|
|
235
|
+
* Only available after start() is called.
|
|
236
|
+
*
|
|
237
|
+
* @returns Demuxer instance or undefined if not started
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const stream = RTPStream.create('input.mp4', {
|
|
242
|
+
* onVideoPacket: (rtp) => sendRtp(rtp)
|
|
243
|
+
* });
|
|
244
|
+
* await stream.start();
|
|
245
|
+
* const input = stream.getInput();
|
|
246
|
+
* console.log('Bitrate:', input?.bitRate);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
getInput(): Demuxer | undefined;
|
|
250
|
+
/**
|
|
251
|
+
* Request that the next encoded video frame is a keyframe.
|
|
252
|
+
*
|
|
253
|
+
* Used to answer receiver feedback (e.g. a WebRTC PLI) so a receiver that
|
|
254
|
+
* missed the stream start or lost packets can resync without waiting for the
|
|
255
|
+
* next scheduled GOP keyframe. Effective whenever the video is encoded, from
|
|
256
|
+
* frame sources and from a transcoded URL or {@link Demuxer} input; a stream
|
|
257
|
+
* passed through keeps the source's keyframes.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* transceiver.sender.onPictureLossIndication.subscribe(() => {
|
|
262
|
+
* stream.requestVideoKeyframe();
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
requestVideoKeyframe(): void;
|
|
267
|
+
/**
|
|
268
|
+
* Start streaming media to RTP packets.
|
|
269
|
+
*
|
|
270
|
+
* Begins the media processing pipeline, reading packets from input,
|
|
271
|
+
* transcoding if necessary, and invoking RTP packet callbacks.
|
|
272
|
+
* Automatically handles video and audio streams in parallel.
|
|
273
|
+
* This method returns immediately after starting the pipeline.
|
|
274
|
+
*
|
|
275
|
+
* @returns Promise that resolves when pipeline is started
|
|
276
|
+
*
|
|
277
|
+
* @throws {Error} If no video stream found in input
|
|
278
|
+
*
|
|
279
|
+
* @throws {FFmpegError} If setup fails
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const stream = RTPStream.create('rtsp://camera.local/stream', {
|
|
284
|
+
* onVideoPacket: (rtp) => sendRtp(rtp)
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* // Start streaming (returns immediately)
|
|
288
|
+
* await stream.start();
|
|
289
|
+
*
|
|
290
|
+
* // Later: stop streaming
|
|
291
|
+
* await stream.stop();
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
start(): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Perform the actual startup (see {@link start}).
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
private doStart;
|
|
301
|
+
/**
|
|
302
|
+
* Abort an in-flight startup once stop() was requested.
|
|
303
|
+
*
|
|
304
|
+
* Checked after every await in the startup path: the resources created so
|
|
305
|
+
* far are all assigned to instance fields, so the stop() that is waiting on
|
|
306
|
+
* this startup tears them down the moment it unwinds.
|
|
307
|
+
*
|
|
308
|
+
* @throws {Error} If stop() was called while starting
|
|
309
|
+
*
|
|
310
|
+
* @internal
|
|
311
|
+
*/
|
|
312
|
+
private throwIfStopRequested;
|
|
313
|
+
/**
|
|
314
|
+
* Wire the pipeline completion to the onClose/error callbacks.
|
|
315
|
+
*
|
|
316
|
+
* On success invokes `onClose()`; on error stops the stream and invokes
|
|
317
|
+
* `onClose(error)`. Either way `onClose` runs exactly once and the detached
|
|
318
|
+
* chain never rejects. Runs in the background (not awaited).
|
|
319
|
+
*
|
|
320
|
+
* @param completion - The pipeline completion promise
|
|
321
|
+
*
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
private attachCompletion;
|
|
325
|
+
/**
|
|
326
|
+
* Invoke the owner's onClose callback.
|
|
327
|
+
*
|
|
328
|
+
* The completion chain runs detached, so an exception from the callback
|
|
329
|
+
* could only surface as an unhandled rejection - it is logged instead.
|
|
330
|
+
*
|
|
331
|
+
* @param error - Pipeline error, or undefined for a clean end
|
|
332
|
+
*
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
private emitClose;
|
|
336
|
+
/**
|
|
337
|
+
* Whether a pipeline rejection was caused by an intentional shutdown.
|
|
338
|
+
*
|
|
339
|
+
* @param error - The pipeline rejection reason
|
|
340
|
+
*
|
|
341
|
+
* @returns True when stop() is in flight or the owner's signal aborted
|
|
342
|
+
*
|
|
343
|
+
* @internal
|
|
344
|
+
*/
|
|
345
|
+
private isDeliberateStop;
|
|
346
|
+
/**
|
|
347
|
+
* Set up encoders and RTP outputs for a pre-composited frame source and start
|
|
348
|
+
* encoding. No demuxer or decoder is involved - the provided frames are encoded
|
|
349
|
+
* straight to RTP. Video and audio (whichever are present) run as separate
|
|
350
|
+
* pipelines combined behind a single control.
|
|
351
|
+
*
|
|
352
|
+
* @throws {Error} If the source has neither video nor audio frames
|
|
353
|
+
*
|
|
354
|
+
* @internal
|
|
355
|
+
*/
|
|
356
|
+
private startFromFrames;
|
|
357
|
+
/**
|
|
358
|
+
* Create the RTP video output muxer.
|
|
359
|
+
*
|
|
360
|
+
* Rewrites RTP sequence numbers (continuous) and rebases the PTS-derived
|
|
361
|
+
* timestamps (90 kHz) onto a random initial value in the write callback, then
|
|
362
|
+
* forwards each packet to `onVideoPacket`. Uses `this.input` when present
|
|
363
|
+
* (demuxer path) and no input for the frame-source path.
|
|
364
|
+
*
|
|
365
|
+
* @returns The configured video muxer
|
|
366
|
+
*
|
|
367
|
+
* @internal
|
|
368
|
+
*/
|
|
369
|
+
private createVideoOutput;
|
|
370
|
+
/**
|
|
371
|
+
* Create the RTP audio output muxer.
|
|
372
|
+
*
|
|
373
|
+
* Rewrites RTP sequence numbers (continuous) in the write callback and forwards
|
|
374
|
+
* each packet to `onAudioPacket`. Uses `this.input` when present (demuxer path)
|
|
375
|
+
* and no input for the frame-source path.
|
|
376
|
+
*
|
|
377
|
+
* @returns The configured audio muxer
|
|
378
|
+
*
|
|
379
|
+
* @internal
|
|
380
|
+
*/
|
|
381
|
+
private createAudioOutput;
|
|
382
|
+
/**
|
|
383
|
+
* Run the streaming pipeline until completion or stopped.
|
|
384
|
+
*
|
|
385
|
+
* @internal
|
|
386
|
+
*/
|
|
387
|
+
private runPipeline;
|
|
388
|
+
/**
|
|
389
|
+
* Stop streaming gracefully and clean up all resources.
|
|
390
|
+
*
|
|
391
|
+
* Stops the pipeline, closes output, and releases all FFmpeg resources.
|
|
392
|
+
* Safe to call multiple times. After stopping, you can call start() again
|
|
393
|
+
* to restart the stream. Resolves even if the pipeline had failed; that
|
|
394
|
+
* error is reported through `onClose(error)`.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* const stream = RTPStream.create('input.mp4', {
|
|
399
|
+
* onVideoPacket: (rtp) => sendRtp(rtp)
|
|
400
|
+
* });
|
|
401
|
+
* await stream.start();
|
|
402
|
+
*
|
|
403
|
+
* // Stop after 10 seconds
|
|
404
|
+
* setTimeout(async () => await stream.stop(), 10000);
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
stop(): Promise<void>;
|
|
408
|
+
/**
|
|
409
|
+
* Perform the actual teardown (see {@link stop}).
|
|
410
|
+
*
|
|
411
|
+
* @internal
|
|
412
|
+
*/
|
|
413
|
+
private doStop;
|
|
414
|
+
/**
|
|
415
|
+
* Check if the given audio codec is supported.
|
|
416
|
+
*
|
|
417
|
+
* @param codecId - The AVCodecID to check
|
|
418
|
+
*
|
|
419
|
+
* @returns True if the codec is supported, false otherwise
|
|
420
|
+
*
|
|
421
|
+
* @internal
|
|
422
|
+
*/
|
|
423
|
+
private isAudioCodecSupported;
|
|
424
|
+
/**
|
|
425
|
+
* Find the encoder for a target video codec, on the device when it works there.
|
|
426
|
+
*
|
|
427
|
+
* @param target - Codec ID, or the name of a specific encoder to use as it is
|
|
428
|
+
*
|
|
429
|
+
* @param size - The output size, when known before the first frame
|
|
430
|
+
*
|
|
431
|
+
* @param size.width - Width
|
|
432
|
+
*
|
|
433
|
+
* @param size.height - Height
|
|
434
|
+
*
|
|
435
|
+
* @returns The encoder, or null if none exists
|
|
436
|
+
*
|
|
437
|
+
* @internal
|
|
438
|
+
*/
|
|
439
|
+
private findVideoEncoder;
|
|
440
|
+
/**
|
|
441
|
+
* Check if the given video codec is supported.
|
|
442
|
+
*
|
|
443
|
+
* @param codecId - The AVCodecID to check
|
|
444
|
+
*
|
|
445
|
+
* @returns True if the codec is supported, false otherwise
|
|
446
|
+
*
|
|
447
|
+
* @internal
|
|
448
|
+
*/
|
|
449
|
+
private isVideoCodecSupported;
|
|
450
|
+
/**
|
|
451
|
+
* Select a codec-supported sample format for the desired one.
|
|
452
|
+
*
|
|
453
|
+
* Delegates to the shared {@link pickSupportedSampleFormat} so the RTP path and
|
|
454
|
+
* the encoder negotiate formats identically.
|
|
455
|
+
*
|
|
456
|
+
* @param codec - Audio encoder codec
|
|
457
|
+
*
|
|
458
|
+
* @param desiredFormat - Desired sample format
|
|
459
|
+
*
|
|
460
|
+
* @returns A sample format the codec accepts
|
|
461
|
+
*
|
|
462
|
+
* @internal
|
|
463
|
+
*/
|
|
464
|
+
private selectSampleFormat;
|
|
465
|
+
/**
|
|
466
|
+
* Select a codec-supported sample rate for the desired one.
|
|
467
|
+
*
|
|
468
|
+
* Delegates to the shared {@link pickSupportedRate} (keeps the desired rate when
|
|
469
|
+
* accepted, otherwise the nearest supported one).
|
|
470
|
+
*
|
|
471
|
+
* @param codec - Audio encoder codec
|
|
472
|
+
*
|
|
473
|
+
* @param desiredRate - Desired sample rate
|
|
474
|
+
*
|
|
475
|
+
* @returns A sample rate the codec accepts
|
|
476
|
+
*
|
|
477
|
+
* @internal
|
|
478
|
+
*/
|
|
479
|
+
private selectSampleRate;
|
|
480
|
+
/**
|
|
481
|
+
* Select a codec-supported channel layout for the desired channel count, as an
|
|
482
|
+
* SDP layout string.
|
|
483
|
+
*
|
|
484
|
+
* Delegates the choice to the shared {@link pickSupportedLayout} (nearest channel
|
|
485
|
+
* count when the exact count is unsupported), then renders it as `'mono'`,
|
|
486
|
+
* `'stereo'`, or the layout mask.
|
|
487
|
+
*
|
|
488
|
+
* @param codec - Audio encoder codec
|
|
489
|
+
*
|
|
490
|
+
* @param desiredChannels - Desired number of channels
|
|
491
|
+
*
|
|
492
|
+
* @returns Channel layout string the codec accepts
|
|
493
|
+
*
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
private selectChannelLayout;
|
|
497
|
+
}
|