node-av 3.1.3 → 5.0.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/README.md +88 -52
- package/binding.gyp +23 -11
- package/dist/api/audio-frame-buffer.d.ts +201 -0
- package/dist/api/audio-frame-buffer.js +275 -0
- package/dist/api/audio-frame-buffer.js.map +1 -0
- package/dist/api/bitstream-filter.d.ts +320 -78
- package/dist/api/bitstream-filter.js +684 -151
- package/dist/api/bitstream-filter.js.map +1 -1
- 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_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 +454 -77
- package/dist/api/decoder.js +1081 -271
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/{media-input.d.ts → demuxer.d.ts} +295 -45
- package/dist/api/demuxer.js +1965 -0
- package/dist/api/demuxer.js.map +1 -0
- package/dist/api/encoder.d.ts +423 -132
- package/dist/api/encoder.js +1089 -240
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-complex.d.ts +769 -0
- package/dist/api/filter-complex.js +1596 -0
- package/dist/api/filter-complex.js.map +1 -0
- package/dist/api/filter-presets.d.ts +80 -5
- package/dist/api/filter-presets.js +117 -7
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +561 -125
- package/dist/api/filter.js +1083 -274
- package/dist/api/filter.js.map +1 -1
- package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
- package/dist/api/fmp4-stream.js +539 -0
- package/dist/api/fmp4-stream.js.map +1 -0
- package/dist/api/hardware.d.ts +58 -6
- package/dist/api/hardware.js +127 -11
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +8 -4
- package/dist/api/index.js +17 -8
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +6 -6
- package/dist/api/io-stream.js +5 -4
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/{media-output.d.ts → muxer.d.ts} +280 -66
- package/dist/api/muxer.js +1934 -0
- package/dist/api/muxer.js.map +1 -0
- package/dist/api/pipeline.d.ts +77 -29
- package/dist/api/pipeline.js +449 -439
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/rtp-stream.d.ts +312 -0
- package/dist/api/rtp-stream.js +630 -0
- package/dist/api/rtp-stream.js.map +1 -0
- package/dist/api/types.d.ts +533 -56
- package/dist/api/utilities/async-queue.d.ts +91 -0
- package/dist/api/utilities/async-queue.js +162 -0
- package/dist/api/utilities/async-queue.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +11 -1
- package/dist/api/utilities/audio-sample.js +10 -0
- package/dist/api/utilities/audio-sample.js.map +1 -1
- package/dist/api/utilities/channel-layout.d.ts +1 -0
- package/dist/api/utilities/channel-layout.js +1 -0
- package/dist/api/utilities/channel-layout.js.map +1 -1
- package/dist/api/utilities/image.d.ts +39 -1
- package/dist/api/utilities/image.js +38 -0
- package/dist/api/utilities/image.js.map +1 -1
- package/dist/api/utilities/index.d.ts +3 -0
- package/dist/api/utilities/index.js +6 -0
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +2 -1
- package/dist/api/utilities/media-type.js +1 -0
- package/dist/api/utilities/media-type.js.map +1 -1
- package/dist/api/utilities/pixel-format.d.ts +4 -1
- package/dist/api/utilities/pixel-format.js +3 -0
- package/dist/api/utilities/pixel-format.js.map +1 -1
- package/dist/api/utilities/sample-format.d.ts +6 -1
- package/dist/api/utilities/sample-format.js +5 -0
- package/dist/api/utilities/sample-format.js.map +1 -1
- 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 +105 -15
- package/dist/api/utilities/streaming.js +201 -12
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +15 -1
- package/dist/api/utilities/timestamp.js +14 -0
- package/dist/api/utilities/timestamp.js.map +1 -1
- package/dist/api/utilities/whisper-model.d.ts +310 -0
- package/dist/api/utilities/whisper-model.js +528 -0
- package/dist/api/utilities/whisper-model.js.map +1 -0
- package/dist/api/webrtc-stream.d.ts +288 -0
- package/dist/api/webrtc-stream.js +440 -0
- package/dist/api/webrtc-stream.js.map +1 -0
- package/dist/api/whisper.d.ts +324 -0
- package/dist/api/whisper.js +362 -0
- package/dist/api/whisper.js.map +1 -0
- package/dist/constants/constants.d.ts +54 -2
- package/dist/constants/constants.js +48 -1
- package/dist/constants/constants.js.map +1 -1
- package/dist/constants/encoders.d.ts +2 -1
- package/dist/constants/encoders.js +4 -3
- package/dist/constants/encoders.js.map +1 -1
- 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 +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -3
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/utils.d.ts +27 -0
- package/dist/ffmpeg/utils.js +28 -16
- package/dist/ffmpeg/utils.js.map +1 -1
- package/dist/lib/binding.d.ts +22 -11
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec-context.d.ts +87 -0
- package/dist/lib/codec-context.js +125 -4
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +229 -1
- package/dist/lib/codec-parameters.js +264 -0
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +23 -0
- package/dist/lib/codec-parser.js +25 -0
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +26 -4
- package/dist/lib/codec.js +35 -0
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.js +1 -0
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.js +1 -1
- package/dist/lib/error.js.map +1 -1
- 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 +52 -11
- package/dist/lib/filter-context.js +56 -12
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +9 -0
- package/dist/lib/filter-graph.js +13 -0
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter.d.ts +21 -0
- package/dist/lib/filter.js +28 -0
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +48 -14
- package/dist/lib/format-context.js +76 -7
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +264 -1
- package/dist/lib/frame.js +351 -1
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +3 -2
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +21 -0
- package/dist/lib/input-format.js +42 -2
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/native-types.d.ts +76 -27
- package/dist/lib/option.d.ts +25 -13
- package/dist/lib/option.js +28 -0
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +22 -1
- package/dist/lib/output-format.js +28 -0
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +35 -0
- package/dist/lib/packet.js +52 -2
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +18 -0
- package/dist/lib/rational.js +19 -0
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/stream.d.ts +126 -0
- package/dist/lib/stream.js +188 -5
- package/dist/lib/stream.js.map +1 -1
- 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 +49 -1
- package/dist/lib/utilities.d.ts +281 -53
- package/dist/lib/utilities.js +298 -55
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +2 -2
- package/package.json +37 -26
- package/dist/api/fmp4.js +0 -710
- package/dist/api/fmp4.js.map +0 -1
- package/dist/api/media-input.js +0 -1075
- package/dist/api/media-input.js.map +0 -1
- package/dist/api/media-output.js +0 -1040
- package/dist/api/media-output.js.map +0 -1
- package/dist/api/webrtc.d.ts +0 -664
- package/dist/api/webrtc.js +0 -1132
- package/dist/api/webrtc.js.map +0 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { AVMEDIA_TYPE_VIDEO } from '../../constants/constants.js';
|
|
2
|
+
import { Codec } from '../../lib/codec.js';
|
|
3
|
+
import { FormatContext } from '../../lib/format-context.js';
|
|
4
|
+
import { Rational } from '../../lib/rational.js';
|
|
1
5
|
import { avSdpCreate } from '../../lib/utilities.js';
|
|
2
6
|
/**
|
|
3
7
|
* Streaming protocol utilities.
|
|
@@ -7,11 +11,11 @@ import { avSdpCreate } from '../../lib/utilities.js';
|
|
|
7
11
|
*
|
|
8
12
|
* @example
|
|
9
13
|
* ```typescript
|
|
10
|
-
* import { StreamingUtils,
|
|
14
|
+
* import { StreamingUtils, Muxer } from 'node-av/api';
|
|
11
15
|
*
|
|
12
16
|
* // Create RTP outputs
|
|
13
|
-
* const videoOutput = await
|
|
14
|
-
* const audioOutput = await
|
|
17
|
+
* const videoOutput = await Muxer.open('rtp://127.0.0.1:5004');
|
|
18
|
+
* const audioOutput = await Muxer.open('rtp://127.0.0.1:5006');
|
|
15
19
|
*
|
|
16
20
|
* // Generate SDP for streaming
|
|
17
21
|
* const sdp = StreamingUtils.createSdp([videoOutput, audioOutput]);
|
|
@@ -23,23 +27,24 @@ import { avSdpCreate } from '../../lib/utilities.js';
|
|
|
23
27
|
*/
|
|
24
28
|
export class StreamingUtils {
|
|
25
29
|
/**
|
|
26
|
-
* Create an SDP (Session Description Protocol) string from
|
|
30
|
+
* Create an SDP (Session Description Protocol) string from demuxer/muxer
|
|
27
31
|
*
|
|
28
32
|
* Generates an SDP description for RTP/RTSP streaming from one or more
|
|
29
|
-
* configured
|
|
33
|
+
* configured demuxer/muxer. The inputs/outputs should be configured with RTP
|
|
30
34
|
* format and have their streams set up before calling this method.
|
|
31
35
|
*
|
|
32
|
-
* @param
|
|
36
|
+
* @param contexts - Alternatively, array of FormatContext objects
|
|
37
|
+
*
|
|
33
38
|
* @returns SDP string if successful, null if failed
|
|
34
39
|
*
|
|
35
40
|
* @example
|
|
36
41
|
* ```typescript
|
|
37
42
|
* // Set up RTP outputs with streams
|
|
38
|
-
* const output1 = await
|
|
39
|
-
* await output1.
|
|
43
|
+
* const output1 = await Muxer.open('rtp://239.0.0.1:5004');
|
|
44
|
+
* await output1.addStream(encoder1);
|
|
40
45
|
*
|
|
41
|
-
* const output2 = await
|
|
42
|
-
* await output2.
|
|
46
|
+
* const output2 = await Muxer.open('rtp://239.0.0.1:5006');
|
|
47
|
+
* await output2.addStream(encoder2);
|
|
43
48
|
*
|
|
44
49
|
* // Generate SDP for multicast streaming
|
|
45
50
|
* const sdp = StreamingUtils.createSdp([output1.getFormatContext(), output2.getFormatContext()]);
|
|
@@ -55,15 +60,148 @@ export class StreamingUtils {
|
|
|
55
60
|
}
|
|
56
61
|
return avSdpCreate(contexts);
|
|
57
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Generate SDP for RTP/SRTP input using FFmpeg's native SDP generator
|
|
65
|
+
*
|
|
66
|
+
* Creates an RFC-compliant SDP description using FFmpeg's internal logic.
|
|
67
|
+
* This ensures correct codec names, clock rates, and formatting for all codecs.
|
|
68
|
+
*
|
|
69
|
+
* @param configs - Array of stream configurations
|
|
70
|
+
*
|
|
71
|
+
* @param sessionName - Optional session name for the SDP (default: 'RTP Stream')
|
|
72
|
+
*
|
|
73
|
+
* @returns SDP string with proper rtpmap and optional crypto attributes
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { StreamingUtils } from 'node-av/api';
|
|
78
|
+
* import { AV_CODEC_ID_OPUS, AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
79
|
+
*
|
|
80
|
+
* // Single audio stream with SRTP
|
|
81
|
+
* const sdp = StreamingUtils.createInputSDP([{
|
|
82
|
+
* port: 5004,
|
|
83
|
+
* codecId: AV_CODEC_ID_OPUS,
|
|
84
|
+
* payloadType: 111,
|
|
85
|
+
* clockRate: 48000,
|
|
86
|
+
* channels: 2,
|
|
87
|
+
* srtp: {
|
|
88
|
+
* key: Buffer.alloc(16, 0x12),
|
|
89
|
+
* salt: Buffer.alloc(14, 0x34)
|
|
90
|
+
* }
|
|
91
|
+
* }]);
|
|
92
|
+
*
|
|
93
|
+
* // Multi-stream (video + audio)
|
|
94
|
+
* const sdp = StreamingUtils.createInputSDP([
|
|
95
|
+
* { port: 5006, codecId: AV_CODEC_ID_H264, payloadType: 96, clockRate: 90000 },
|
|
96
|
+
* { port: 5004, codecId: AV_CODEC_ID_OPUS, payloadType: 111, clockRate: 48000, channels: 2 }
|
|
97
|
+
* ], 'My Stream');
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
static createInputSDP(configs, sessionName = 'RTP Stream') {
|
|
101
|
+
const contexts = [];
|
|
102
|
+
try {
|
|
103
|
+
// Create one FormatContext per stream with individual URL (port)
|
|
104
|
+
for (const streamConfig of configs) {
|
|
105
|
+
const codec = Codec.findDecoder(streamConfig.codecId);
|
|
106
|
+
if (!codec) {
|
|
107
|
+
throw new Error(`Codec not found for codec ID: ${streamConfig.codecId}`);
|
|
108
|
+
}
|
|
109
|
+
// Create format context with URL containing the port
|
|
110
|
+
const ctx = new FormatContext();
|
|
111
|
+
ctx.allocContext();
|
|
112
|
+
ctx.url = `rtp://127.0.0.1:${streamConfig.port}`;
|
|
113
|
+
// Create stream with codec parameters
|
|
114
|
+
const stream = ctx.newStream(null);
|
|
115
|
+
stream.codecpar.codecId = streamConfig.codecId;
|
|
116
|
+
stream.codecpar.codecType = codec.type;
|
|
117
|
+
// Set audio-specific parameters
|
|
118
|
+
if (codec.type !== AVMEDIA_TYPE_VIDEO) {
|
|
119
|
+
if (streamConfig.clockRate) {
|
|
120
|
+
stream.codecpar.sampleRate = streamConfig.clockRate;
|
|
121
|
+
}
|
|
122
|
+
if (streamConfig.channels) {
|
|
123
|
+
stream.codecpar.channels = streamConfig.channels;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Set time base (required for SDP generation)
|
|
127
|
+
stream.timeBase = new Rational(1, streamConfig.clockRate);
|
|
128
|
+
contexts.push(ctx);
|
|
129
|
+
}
|
|
130
|
+
// Generate SDP using FFmpeg's native generator
|
|
131
|
+
// FFmpeg will automatically use the port from each context's URL and generate RFC-compliant codec names
|
|
132
|
+
let sdp = avSdpCreate(contexts);
|
|
133
|
+
if (!sdp) {
|
|
134
|
+
throw new Error('Failed to generate SDP');
|
|
135
|
+
}
|
|
136
|
+
// Post-process: Replace session name if provided
|
|
137
|
+
if (sessionName !== 'RTP Stream') {
|
|
138
|
+
sdp = sdp.replace(/^s=.*$/m, `s=${sessionName}`);
|
|
139
|
+
}
|
|
140
|
+
// Post-process: Replace payload types, add SRTP crypto lines, and/or custom fmtp
|
|
141
|
+
// Note: We always need to process because FFmpeg assigns payload types automatically
|
|
142
|
+
const sdpLines = sdp.split('\n');
|
|
143
|
+
const newLines = [];
|
|
144
|
+
let streamIndex = -1;
|
|
145
|
+
for (let i = 0; i < sdpLines.length; i++) {
|
|
146
|
+
const line = sdpLines[i];
|
|
147
|
+
if (line.startsWith('m=')) {
|
|
148
|
+
// New media section
|
|
149
|
+
streamIndex++;
|
|
150
|
+
const streamCfg = configs[streamIndex];
|
|
151
|
+
// Replace FFmpeg's auto-assigned payload type with user-specified one
|
|
152
|
+
const replaced = line.replace(/RTP\/AVP\s+(\d+)/, `RTP/AVP ${streamCfg.payloadType}`);
|
|
153
|
+
newLines.push(replaced);
|
|
154
|
+
// Add SRTP crypto line right after m= line if configured
|
|
155
|
+
if (streamCfg?.srtp) {
|
|
156
|
+
const suite = streamCfg.srtp.suite ?? 'AES_CM_128_HMAC_SHA1_80';
|
|
157
|
+
const keyMaterial = Buffer.concat([streamCfg.srtp.key, streamCfg.srtp.salt]).toString('base64');
|
|
158
|
+
newLines.push(`a=crypto:1 ${suite} inline:${keyMaterial}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (line.startsWith('a=rtpmap:')) {
|
|
162
|
+
// Replace payload type in rtpmap line
|
|
163
|
+
const streamCfg = configs[streamIndex];
|
|
164
|
+
const replaced = line.replace(/^a=rtpmap:(\d+)/, `a=rtpmap:${streamCfg.payloadType}`);
|
|
165
|
+
newLines.push(replaced);
|
|
166
|
+
// If custom fmtp is provided but FFmpeg didn't generate one, add it
|
|
167
|
+
if (streamCfg?.fmtp && !sdpLines[i + 1]?.startsWith('a=fmtp:')) {
|
|
168
|
+
newLines.push(`a=fmtp:${streamCfg.payloadType} ${streamCfg.fmtp}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (line.startsWith('a=fmtp:')) {
|
|
172
|
+
// Replace payload type in fmtp line and optionally replace content
|
|
173
|
+
const streamCfg = configs[streamIndex];
|
|
174
|
+
if (streamCfg?.fmtp) {
|
|
175
|
+
newLines.push(`a=fmtp:${streamCfg.payloadType} ${streamCfg.fmtp}`);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const replaced = line.replace(/^a=fmtp:(\d+)/, `a=fmtp:${streamCfg.payloadType}`);
|
|
179
|
+
newLines.push(replaced);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
newLines.push(line);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return newLines.join('\n');
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
// Cleanup all contexts
|
|
190
|
+
for (const ctx of contexts) {
|
|
191
|
+
ctx.freeContext();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
58
195
|
/**
|
|
59
196
|
* Validate if an output is configured for RTP streaming
|
|
60
197
|
*
|
|
61
|
-
* @param output -
|
|
198
|
+
* @param output - Muxer to check
|
|
199
|
+
*
|
|
62
200
|
* @returns true if configured for RTP
|
|
63
201
|
*
|
|
64
202
|
* @example
|
|
65
203
|
* ```typescript
|
|
66
|
-
* const output = await
|
|
204
|
+
* const output = await Muxer.open('rtp://127.0.0.1:5004');
|
|
67
205
|
* if (StreamingUtils.isRtpOutput(output)) {
|
|
68
206
|
* const sdp = StreamingUtils.createSdpForOutput(output);
|
|
69
207
|
* }
|
|
@@ -85,8 +223,19 @@ export class StreamingUtils {
|
|
|
85
223
|
* Helper to construct RTP URLs with proper formatting.
|
|
86
224
|
*
|
|
87
225
|
* @param host - IP address or hostname
|
|
226
|
+
*
|
|
88
227
|
* @param port - Port number
|
|
228
|
+
*
|
|
89
229
|
* @param options - Additional options
|
|
230
|
+
*
|
|
231
|
+
* @param options.ttl - Time-to-live for multicast
|
|
232
|
+
*
|
|
233
|
+
* @param options.localrtpport - Local RTP port
|
|
234
|
+
*
|
|
235
|
+
* @param options.localrtcpport - Local RTCP port
|
|
236
|
+
*
|
|
237
|
+
* @param options.pkt_size - Packet size
|
|
238
|
+
*
|
|
90
239
|
* @returns Formatted RTP URL
|
|
91
240
|
*
|
|
92
241
|
* @example
|
|
@@ -116,5 +265,45 @@ export class StreamingUtils {
|
|
|
116
265
|
}
|
|
117
266
|
return url;
|
|
118
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Extract all UDP ports from SDP content
|
|
270
|
+
*
|
|
271
|
+
* @param sdp - SDP content string
|
|
272
|
+
*
|
|
273
|
+
* @returns Array of port numbers (one per stream)
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* import { StreamingUtils } from 'node-av/api';
|
|
278
|
+
*
|
|
279
|
+
* const sdp = `v=0
|
|
280
|
+
* o=- 0 0 IN IP4 127.0.0.1
|
|
281
|
+
* s=Test Stream
|
|
282
|
+
* c=IN IP4 127.0.0.1
|
|
283
|
+
* t=0 0
|
|
284
|
+
* m=audio 5004 RTP/AVP 111
|
|
285
|
+
* a=rtpmap:111 OPUS/48000/2
|
|
286
|
+
* m=video 5006 RTP/AVP 96
|
|
287
|
+
* a=rtpmap:96 H264/90000`;
|
|
288
|
+
*
|
|
289
|
+
* const ports = StreamingUtils.extractPortsFromSDP(sdp);
|
|
290
|
+
* console.log(ports); // [5004, 5006]
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
static extractPortsFromSDP(sdp) {
|
|
294
|
+
const ports = [];
|
|
295
|
+
const lines = sdp.split('\n');
|
|
296
|
+
for (const line of lines) {
|
|
297
|
+
if (line.startsWith('m=')) {
|
|
298
|
+
// m=audio 5004 RTP/AVP 111
|
|
299
|
+
// m=video 5006 RTP/AVP 96
|
|
300
|
+
const match = /m=\w+\s+(\d+)/.exec(line);
|
|
301
|
+
if (match) {
|
|
302
|
+
ports.push(parseInt(match[1], 10));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return ports;
|
|
307
|
+
}
|
|
119
308
|
}
|
|
120
309
|
//# sourceMappingURL=streaming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/api/utilities/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,cAAc;IACzB
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/api/utilities/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,KA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CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AVRounding } from '../../constants/
|
|
1
|
+
import type { AVRounding } from '../../constants/index.js';
|
|
2
2
|
import type { IRational } from '../../lib/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Timestamp and time base utilities.
|
|
@@ -36,6 +36,7 @@ export declare class TimestampUtils {
|
|
|
36
36
|
* Direct mapping to av_ts2str()
|
|
37
37
|
*
|
|
38
38
|
* @param ts - Timestamp value (bigint or number), or null
|
|
39
|
+
*
|
|
39
40
|
* @returns String representation
|
|
40
41
|
*
|
|
41
42
|
* @example
|
|
@@ -56,7 +57,9 @@ export declare class TimestampUtils {
|
|
|
56
57
|
* Direct mapping to av_ts2timestr()
|
|
57
58
|
*
|
|
58
59
|
* @param ts - Timestamp value
|
|
60
|
+
*
|
|
59
61
|
* @param timeBase - Time base for conversion
|
|
62
|
+
*
|
|
60
63
|
* @returns Time string in seconds with decimal places
|
|
61
64
|
*
|
|
62
65
|
* @example
|
|
@@ -78,9 +81,13 @@ export declare class TimestampUtils {
|
|
|
78
81
|
* Direct mapping to av_compare_ts()
|
|
79
82
|
*
|
|
80
83
|
* @param tsA - First timestamp
|
|
84
|
+
*
|
|
81
85
|
* @param tbA - Time base of first timestamp
|
|
86
|
+
*
|
|
82
87
|
* @param tsB - Second timestamp
|
|
88
|
+
*
|
|
83
89
|
* @param tbB - Time base of second timestamp
|
|
90
|
+
*
|
|
84
91
|
* @returns -1 if tsA < tsB, 0 if equal, 1 if tsA > tsB
|
|
85
92
|
*
|
|
86
93
|
* @example
|
|
@@ -107,8 +114,11 @@ export declare class TimestampUtils {
|
|
|
107
114
|
* Direct mapping to av_rescale_q()
|
|
108
115
|
*
|
|
109
116
|
* @param a - Timestamp to rescale
|
|
117
|
+
*
|
|
110
118
|
* @param bq - Source time base
|
|
119
|
+
*
|
|
111
120
|
* @param cq - Destination time base
|
|
121
|
+
*
|
|
112
122
|
* @returns Rescaled timestamp
|
|
113
123
|
*
|
|
114
124
|
* @example
|
|
@@ -133,9 +143,13 @@ export declare class TimestampUtils {
|
|
|
133
143
|
* Direct mapping to av_rescale_rnd()
|
|
134
144
|
*
|
|
135
145
|
* @param a - Value to rescale
|
|
146
|
+
*
|
|
136
147
|
* @param b - Multiplier
|
|
148
|
+
*
|
|
137
149
|
* @param c - Divisor
|
|
150
|
+
*
|
|
138
151
|
* @param rnd - Rounding mode
|
|
152
|
+
*
|
|
139
153
|
* @returns Rescaled value: a * b / c
|
|
140
154
|
*
|
|
141
155
|
* @example
|
|
@@ -36,6 +36,7 @@ export class TimestampUtils {
|
|
|
36
36
|
* Direct mapping to av_ts2str()
|
|
37
37
|
*
|
|
38
38
|
* @param ts - Timestamp value (bigint or number), or null
|
|
39
|
+
*
|
|
39
40
|
* @returns String representation
|
|
40
41
|
*
|
|
41
42
|
* @example
|
|
@@ -58,7 +59,9 @@ export class TimestampUtils {
|
|
|
58
59
|
* Direct mapping to av_ts2timestr()
|
|
59
60
|
*
|
|
60
61
|
* @param ts - Timestamp value
|
|
62
|
+
*
|
|
61
63
|
* @param timeBase - Time base for conversion
|
|
64
|
+
*
|
|
62
65
|
* @returns Time string in seconds with decimal places
|
|
63
66
|
*
|
|
64
67
|
* @example
|
|
@@ -82,9 +85,13 @@ export class TimestampUtils {
|
|
|
82
85
|
* Direct mapping to av_compare_ts()
|
|
83
86
|
*
|
|
84
87
|
* @param tsA - First timestamp
|
|
88
|
+
*
|
|
85
89
|
* @param tbA - Time base of first timestamp
|
|
90
|
+
*
|
|
86
91
|
* @param tsB - Second timestamp
|
|
92
|
+
*
|
|
87
93
|
* @param tbB - Time base of second timestamp
|
|
94
|
+
*
|
|
88
95
|
* @returns -1 if tsA < tsB, 0 if equal, 1 if tsA > tsB
|
|
89
96
|
*
|
|
90
97
|
* @example
|
|
@@ -113,8 +120,11 @@ export class TimestampUtils {
|
|
|
113
120
|
* Direct mapping to av_rescale_q()
|
|
114
121
|
*
|
|
115
122
|
* @param a - Timestamp to rescale
|
|
123
|
+
*
|
|
116
124
|
* @param bq - Source time base
|
|
125
|
+
*
|
|
117
126
|
* @param cq - Destination time base
|
|
127
|
+
*
|
|
118
128
|
* @returns Rescaled timestamp
|
|
119
129
|
*
|
|
120
130
|
* @example
|
|
@@ -141,9 +151,13 @@ export class TimestampUtils {
|
|
|
141
151
|
* Direct mapping to av_rescale_rnd()
|
|
142
152
|
*
|
|
143
153
|
* @param a - Value to rescale
|
|
154
|
+
*
|
|
144
155
|
* @param b - Multiplier
|
|
156
|
+
*
|
|
145
157
|
* @param c - Divisor
|
|
158
|
+
*
|
|
146
159
|
* @param rnd - Rounding mode
|
|
160
|
+
*
|
|
147
161
|
* @returns Rescaled value: a * b / c
|
|
148
162
|
*
|
|
149
163
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../../src/api/utilities/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,cAAc;IACzB,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../../src/api/utilities/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,cAAc;IACzB,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,QAAQ,CAAC,EAA0B;QACxC,OAAO,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC/B,CA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