node-av 1.1.0 → 1.2.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 +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
package/dist/lib/audio-fifo.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AVSampleFormat } from '../constants/constants.js';
|
|
2
2
|
import type { NativeAudioFifo, NativeWrapper } from './native-types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Audio FIFO buffer for
|
|
4
|
+
* Audio FIFO (First-In-First-Out) buffer for managing audio samples.
|
|
5
5
|
*
|
|
6
|
-
* Provides a
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Provides a thread-safe buffer for audio sample data, supporting both planar and interleaved formats.
|
|
7
|
+
* Automatically handles buffer reallocation when needed. Essential for audio resampling,
|
|
8
|
+
* format conversion, and buffering operations.
|
|
9
9
|
*
|
|
10
10
|
* Direct mapping to FFmpeg's AVAudioFifo.
|
|
11
11
|
*
|
|
@@ -14,236 +14,191 @@ import type { NativeAudioFifo, NativeWrapper } from './native-types.js';
|
|
|
14
14
|
* import { AudioFifo, FFmpegError } from 'node-av';
|
|
15
15
|
* import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
16
16
|
*
|
|
17
|
-
* // Create
|
|
17
|
+
* // Create FIFO for stereo float planar audio
|
|
18
18
|
* const fifo = new AudioFifo();
|
|
19
19
|
* fifo.alloc(AV_SAMPLE_FMT_FLTP, 2, 4096);
|
|
20
20
|
*
|
|
21
|
-
* // Write samples
|
|
22
|
-
* const
|
|
23
|
-
*
|
|
21
|
+
* // Write samples
|
|
22
|
+
* const leftChannel = Buffer.alloc(1024 * 4); // 1024 float samples
|
|
23
|
+
* const rightChannel = Buffer.alloc(1024 * 4);
|
|
24
|
+
* const written = await fifo.write([leftChannel, rightChannel], 1024);
|
|
25
|
+
* FFmpegError.throwIfError(written, 'write');
|
|
24
26
|
*
|
|
25
|
-
* // Read samples
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* // Read samples when enough available
|
|
28
|
+
* if (fifo.size >= 512) {
|
|
29
|
+
* const outLeft = Buffer.alloc(512 * 4);
|
|
30
|
+
* const outRight = Buffer.alloc(512 * 4);
|
|
31
|
+
* const read = await fifo.read([outLeft, outRight], 512);
|
|
32
|
+
* FFmpegError.throwIfError(read, 'read');
|
|
33
|
+
* }
|
|
31
34
|
*
|
|
32
35
|
* // Cleanup
|
|
33
36
|
* fifo.free();
|
|
34
37
|
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see [AudioFifo](https://ffmpeg.org/doxygen/trunk/structAVAudioFifo.html) - FFmpeg Doxygen
|
|
35
40
|
*/
|
|
36
41
|
export declare class AudioFifo implements Disposable, NativeWrapper<NativeAudioFifo> {
|
|
37
42
|
private native;
|
|
38
|
-
/**
|
|
39
|
-
* Create a new audio FIFO buffer.
|
|
40
|
-
*
|
|
41
|
-
* The FIFO is uninitialized - you must call alloc() before use.
|
|
42
|
-
* No FFmpeg resources are allocated until alloc() is called.
|
|
43
|
-
*
|
|
44
|
-
* Direct wrapper around AVAudioFifo.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { AudioFifo } from 'node-av';
|
|
49
|
-
* import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
50
|
-
*
|
|
51
|
-
* const fifo = new AudioFifo();
|
|
52
|
-
* fifo.alloc(AV_SAMPLE_FMT_S16, 2, 1024);
|
|
53
|
-
* // FIFO is now ready for use
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
43
|
constructor();
|
|
57
44
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* Returns the number of samples currently buffered in the FIFO.
|
|
61
|
-
*
|
|
62
|
-
* Direct mapping to av_audio_fifo_size()
|
|
63
|
-
*
|
|
64
|
-
* @returns Number of samples currently in the FIFO
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import { FFmpegError } from 'node-av';
|
|
69
|
-
*
|
|
70
|
-
* if (fifo.size >= frameSize) {
|
|
71
|
-
* // Enough samples available for a full frame
|
|
72
|
-
* const ret = await fifo.read(outputBuffer, frameSize);
|
|
73
|
-
* FFmpegError.throwIfError(ret, 'read');
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
45
|
+
* Number of samples currently in the FIFO.
|
|
76
46
|
*
|
|
77
|
-
*
|
|
47
|
+
* Direct mapping to av_audio_fifo_size().
|
|
78
48
|
*/
|
|
79
49
|
get size(): number;
|
|
80
50
|
/**
|
|
81
|
-
*
|
|
51
|
+
* Number of samples that can be written without reallocation.
|
|
82
52
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* Direct mapping to av_audio_fifo_space()
|
|
86
|
-
*
|
|
87
|
-
* @returns Number of samples that can be written to the FIFO
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```typescript
|
|
91
|
-
* import { FFmpegError } from 'node-av';
|
|
92
|
-
*
|
|
93
|
-
* if (fifo.space >= frameSize) {
|
|
94
|
-
* // Enough space for a full frame
|
|
95
|
-
* const ret = await fifo.write(inputBuffer, frameSize);
|
|
96
|
-
* FFmpegError.throwIfError(ret, 'write');
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
|
-
* @readonly
|
|
53
|
+
* Direct mapping to av_audio_fifo_space().
|
|
101
54
|
*/
|
|
102
55
|
get space(): number;
|
|
103
56
|
/**
|
|
104
|
-
* Allocate an AVAudioFifo.
|
|
57
|
+
* Allocate an AVAudioFifo buffer.
|
|
105
58
|
*
|
|
106
|
-
*
|
|
59
|
+
* Creates a FIFO buffer for the specified audio format and size.
|
|
107
60
|
* The FIFO will automatically grow if more data is written than allocated.
|
|
108
61
|
*
|
|
109
|
-
* Direct mapping to av_audio_fifo_alloc()
|
|
62
|
+
* Direct mapping to av_audio_fifo_alloc().
|
|
110
63
|
*
|
|
111
64
|
* @param sampleFmt - Sample format (e.g., AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP)
|
|
112
|
-
* @param channels - Number of channels
|
|
113
|
-
* @param nbSamples - Initial
|
|
65
|
+
* @param channels - Number of audio channels
|
|
66
|
+
* @param nbSamples - Initial buffer size in samples
|
|
114
67
|
*
|
|
115
|
-
* @throws {Error}
|
|
68
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
116
69
|
*
|
|
117
70
|
* @example
|
|
118
71
|
* ```typescript
|
|
119
72
|
* import { AudioFifo } from 'node-av';
|
|
120
|
-
* import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
73
|
+
* import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
74
|
+
*
|
|
75
|
+
* // For interleaved 16-bit stereo
|
|
76
|
+
* const fifo1 = new AudioFifo();
|
|
77
|
+
* fifo1.alloc(AV_SAMPLE_FMT_S16, 2, 4096);
|
|
121
78
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
79
|
+
* // For planar float 5.1 audio
|
|
80
|
+
* const fifo2 = new AudioFifo();
|
|
81
|
+
* fifo2.alloc(AV_SAMPLE_FMT_FLTP, 6, 8192);
|
|
125
82
|
* ```
|
|
126
83
|
*
|
|
127
84
|
* @see {@link realloc} To resize the FIFO
|
|
85
|
+
* @see {@link free} To release the FIFO
|
|
128
86
|
*/
|
|
129
87
|
alloc(sampleFmt: AVSampleFormat, channels: number, nbSamples: number): void;
|
|
130
88
|
/**
|
|
131
|
-
* Free
|
|
89
|
+
* Free the FIFO buffer and all associated resources.
|
|
132
90
|
*
|
|
133
|
-
*
|
|
134
|
-
* The FIFO object becomes invalid after this call.
|
|
91
|
+
* After calling this, the FIFO is invalid and must be reallocated before use.
|
|
135
92
|
*
|
|
136
|
-
* Direct mapping to av_audio_fifo_free()
|
|
93
|
+
* Direct mapping to av_audio_fifo_free().
|
|
137
94
|
*
|
|
138
95
|
* @example
|
|
139
96
|
* ```typescript
|
|
140
97
|
* fifo.free();
|
|
141
|
-
* // FIFO is now invalid
|
|
98
|
+
* // FIFO is now invalid, must call alloc() before using again
|
|
142
99
|
* ```
|
|
100
|
+
*
|
|
101
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
102
|
+
* @see {@link alloc} To allocate
|
|
143
103
|
*/
|
|
144
104
|
free(): void;
|
|
145
105
|
/**
|
|
146
|
-
* Write
|
|
106
|
+
* Write audio samples to the FIFO.
|
|
147
107
|
*
|
|
148
|
-
* Writes
|
|
149
|
-
*
|
|
108
|
+
* Writes samples to the FIFO buffer. Automatically reallocates if more space is needed.
|
|
109
|
+
* For planar formats, provide an array of buffers (one per channel).
|
|
110
|
+
* For interleaved formats, provide a single buffer.
|
|
150
111
|
*
|
|
151
|
-
* Direct mapping to av_audio_fifo_write()
|
|
112
|
+
* Direct mapping to av_audio_fifo_write().
|
|
152
113
|
*
|
|
153
|
-
* @param data - Audio buffer(s)
|
|
154
|
-
* For planar formats: array of buffers (one per channel).
|
|
155
|
-
* For interleaved formats: single buffer.
|
|
114
|
+
* @param data - Audio data buffer(s). Array for planar, single Buffer for interleaved
|
|
156
115
|
* @param nbSamples - Number of samples to write
|
|
157
116
|
*
|
|
158
|
-
* @returns Number of samples
|
|
159
|
-
* -
|
|
160
|
-
* -
|
|
161
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
117
|
+
* @returns Number of samples written, or negative AVERROR:
|
|
118
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
119
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
162
120
|
*
|
|
163
121
|
* @example
|
|
164
122
|
* ```typescript
|
|
165
123
|
* import { FFmpegError } from 'node-av';
|
|
166
124
|
*
|
|
167
|
-
* // Planar format (separate buffers per channel
|
|
168
|
-
* const
|
|
169
|
-
* const
|
|
170
|
-
* const written = await fifo.write([
|
|
125
|
+
* // Planar format (e.g., FLTP) - separate buffers per channel
|
|
126
|
+
* const leftData = Buffer.alloc(1024 * 4); // 1024 float samples
|
|
127
|
+
* const rightData = Buffer.alloc(1024 * 4);
|
|
128
|
+
* const written = await fifo.write([leftData, rightData], 1024);
|
|
171
129
|
* FFmpegError.throwIfError(written, 'write');
|
|
130
|
+
* console.log(`Wrote ${written} samples`);
|
|
172
131
|
*
|
|
173
|
-
* // Interleaved format (single buffer
|
|
174
|
-
* const
|
|
175
|
-
* const written2 = await fifo.write(
|
|
132
|
+
* // Interleaved format (e.g., S16) - single buffer
|
|
133
|
+
* const interleavedData = Buffer.alloc(1024 * 2 * 2); // 1024 stereo S16 samples
|
|
134
|
+
* const written2 = await fifo.write(interleavedData, 1024);
|
|
176
135
|
* FFmpegError.throwIfError(written2, 'write');
|
|
177
136
|
* ```
|
|
178
137
|
*
|
|
179
|
-
* @see {@link read} To
|
|
138
|
+
* @see {@link read} To retrieve samples from FIFO
|
|
139
|
+
* @see {@link space} To check available space
|
|
180
140
|
*/
|
|
181
141
|
write(data: Buffer | Buffer[], nbSamples: number): Promise<number>;
|
|
182
142
|
/**
|
|
183
|
-
* Read
|
|
143
|
+
* Read and remove samples from the FIFO.
|
|
184
144
|
*
|
|
185
|
-
* Reads
|
|
186
|
-
*
|
|
145
|
+
* Reads up to the specified number of samples from the FIFO.
|
|
146
|
+
* The samples are removed from the FIFO after reading.
|
|
147
|
+
* Buffers must be pre-allocated with sufficient size.
|
|
187
148
|
*
|
|
188
|
-
* Direct mapping to av_audio_fifo_read()
|
|
149
|
+
* Direct mapping to av_audio_fifo_read().
|
|
189
150
|
*
|
|
190
|
-
* @param data -
|
|
191
|
-
*
|
|
192
|
-
* For interleaved formats: single buffer.
|
|
193
|
-
* Buffers must be pre-allocated with sufficient size.
|
|
194
|
-
* @param nbSamples - Number of samples to read
|
|
151
|
+
* @param data - Pre-allocated buffer(s) to read into. Array for planar, single Buffer for interleaved
|
|
152
|
+
* @param nbSamples - Maximum number of samples to read
|
|
195
153
|
*
|
|
196
|
-
* @returns Number of samples
|
|
197
|
-
* -
|
|
198
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
154
|
+
* @returns Number of samples read, or negative AVERROR:
|
|
155
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
199
156
|
*
|
|
200
157
|
* @example
|
|
201
158
|
* ```typescript
|
|
202
159
|
* import { FFmpegError } from 'node-av';
|
|
203
160
|
*
|
|
204
|
-
* //
|
|
205
|
-
* const
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
161
|
+
* // Check available samples
|
|
162
|
+
* const available = fifo.size;
|
|
163
|
+
* if (available >= 1024) {
|
|
164
|
+
* // Planar format
|
|
165
|
+
* const leftOut = Buffer.alloc(1024 * 4);
|
|
166
|
+
* const rightOut = Buffer.alloc(1024 * 4);
|
|
167
|
+
* const read = await fifo.read([leftOut, rightOut], 1024);
|
|
168
|
+
* FFmpegError.throwIfError(read, 'read');
|
|
169
|
+
* console.log(`Read ${read} samples`);
|
|
170
|
+
* }
|
|
214
171
|
* ```
|
|
215
172
|
*
|
|
216
173
|
* @see {@link peek} To read without removing
|
|
217
|
-
* @see {@link
|
|
174
|
+
* @see {@link size} To check available samples
|
|
218
175
|
*/
|
|
219
176
|
read(data: Buffer | Buffer[], nbSamples: number): Promise<number>;
|
|
220
177
|
/**
|
|
221
|
-
*
|
|
178
|
+
* Read samples from the FIFO without removing them.
|
|
222
179
|
*
|
|
223
|
-
*
|
|
224
|
-
* Useful for inspecting upcoming data.
|
|
180
|
+
* Similar to read() but leaves the samples in the FIFO.
|
|
181
|
+
* Useful for inspecting upcoming data without consuming it.
|
|
225
182
|
*
|
|
226
|
-
* Direct mapping to av_audio_fifo_peek()
|
|
183
|
+
* Direct mapping to av_audio_fifo_peek().
|
|
227
184
|
*
|
|
228
|
-
* @param data -
|
|
229
|
-
*
|
|
230
|
-
* For interleaved formats: single buffer.
|
|
231
|
-
* Buffers must be pre-allocated.
|
|
232
|
-
* @param nbSamples - Number of samples to peek
|
|
185
|
+
* @param data - Pre-allocated buffer(s) to peek into. Array for planar, single Buffer for interleaved
|
|
186
|
+
* @param nbSamples - Maximum number of samples to peek
|
|
233
187
|
*
|
|
234
|
-
* @returns Number of samples
|
|
235
|
-
* -
|
|
236
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
188
|
+
* @returns Number of samples peeked, or negative AVERROR:
|
|
189
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
237
190
|
*
|
|
238
191
|
* @example
|
|
239
192
|
* ```typescript
|
|
240
193
|
* import { FFmpegError } from 'node-av';
|
|
241
194
|
*
|
|
242
195
|
* // Peek at next samples without removing them
|
|
243
|
-
* const peekBuffer = Buffer.alloc(
|
|
244
|
-
* const peeked = await fifo.peek(peekBuffer,
|
|
196
|
+
* const peekBuffer = Buffer.alloc(256 * 4);
|
|
197
|
+
* const peeked = await fifo.peek(peekBuffer, 256);
|
|
245
198
|
* FFmpegError.throwIfError(peeked, 'peek');
|
|
246
|
-
*
|
|
199
|
+
*
|
|
200
|
+
* // Samples are still in FIFO
|
|
201
|
+
* console.log(`FIFO still has ${fifo.size} samples`);
|
|
247
202
|
* ```
|
|
248
203
|
*
|
|
249
204
|
* @see {@link read} To read and remove samples
|
|
@@ -255,64 +210,71 @@ export declare class AudioFifo implements Disposable, NativeWrapper<NativeAudioF
|
|
|
255
210
|
* Discards the specified number of samples from the FIFO.
|
|
256
211
|
* Useful for skipping unwanted audio data.
|
|
257
212
|
*
|
|
258
|
-
* Direct mapping to av_audio_fifo_drain()
|
|
213
|
+
* Direct mapping to av_audio_fifo_drain().
|
|
259
214
|
*
|
|
260
|
-
* @param nbSamples - Number of samples to
|
|
215
|
+
* @param nbSamples - Number of samples to discard
|
|
261
216
|
*
|
|
262
217
|
* @example
|
|
263
218
|
* ```typescript
|
|
264
|
-
* // Skip
|
|
219
|
+
* // Skip 100 samples
|
|
265
220
|
* fifo.drain(100);
|
|
221
|
+
* console.log(`FIFO now has ${fifo.size} samples`);
|
|
266
222
|
* ```
|
|
223
|
+
*
|
|
224
|
+
* @see {@link reset} To remove all samples
|
|
267
225
|
*/
|
|
268
226
|
drain(nbSamples: number): void;
|
|
269
227
|
/**
|
|
270
|
-
*
|
|
228
|
+
* Remove all samples from the FIFO.
|
|
271
229
|
*
|
|
272
|
-
* Empties
|
|
273
|
-
* The FIFO remains allocated and ready for
|
|
230
|
+
* Empties the FIFO buffer without deallocating it.
|
|
231
|
+
* The FIFO remains allocated and ready for new data.
|
|
274
232
|
*
|
|
275
|
-
* Direct mapping to av_audio_fifo_reset()
|
|
233
|
+
* Direct mapping to av_audio_fifo_reset().
|
|
276
234
|
*
|
|
277
235
|
* @example
|
|
278
236
|
* ```typescript
|
|
279
237
|
* fifo.reset();
|
|
280
|
-
* //
|
|
238
|
+
* console.log(fifo.size); // 0
|
|
239
|
+
* console.log(fifo.space); // Original allocation size
|
|
281
240
|
* ```
|
|
241
|
+
*
|
|
242
|
+
* @see {@link drain} To remove specific number of samples
|
|
282
243
|
*/
|
|
283
244
|
reset(): void;
|
|
284
245
|
/**
|
|
285
|
-
*
|
|
246
|
+
* Resize the FIFO buffer.
|
|
286
247
|
*
|
|
287
|
-
* Changes the size of the FIFO buffer.
|
|
288
|
-
*
|
|
248
|
+
* Changes the allocated size of the FIFO. Can grow or shrink the buffer.
|
|
249
|
+
* Existing samples are preserved up to the new size.
|
|
289
250
|
*
|
|
290
|
-
* Direct mapping to av_audio_fifo_realloc()
|
|
251
|
+
* Direct mapping to av_audio_fifo_realloc().
|
|
291
252
|
*
|
|
292
|
-
* @param nbSamples - New allocation size
|
|
253
|
+
* @param nbSamples - New allocation size in samples
|
|
293
254
|
*
|
|
294
255
|
* @returns 0 on success, negative AVERROR on error:
|
|
295
|
-
* -
|
|
296
|
-
* -
|
|
297
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
256
|
+
* - AVERROR_EINVAL: Invalid size
|
|
257
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
298
258
|
*
|
|
299
259
|
* @example
|
|
300
260
|
* ```typescript
|
|
301
261
|
* import { FFmpegError } from 'node-av';
|
|
302
262
|
*
|
|
303
|
-
* //
|
|
304
|
-
* const ret = fifo.realloc(
|
|
263
|
+
* // Grow FIFO to handle larger buffers
|
|
264
|
+
* const ret = fifo.realloc(16384);
|
|
305
265
|
* FFmpegError.throwIfError(ret, 'realloc');
|
|
266
|
+
* console.log(`New space: ${fifo.space} samples`);
|
|
306
267
|
* ```
|
|
307
268
|
*
|
|
308
269
|
* @see {@link alloc} For initial allocation
|
|
309
270
|
*/
|
|
310
271
|
realloc(nbSamples: number): number;
|
|
311
272
|
/**
|
|
312
|
-
* Get the native
|
|
273
|
+
* Get the underlying native AudioFifo object.
|
|
274
|
+
*
|
|
275
|
+
* @returns The native AudioFifo binding object
|
|
313
276
|
*
|
|
314
|
-
* @internal
|
|
315
|
-
* @returns The underlying native AudioFifo object
|
|
277
|
+
* @internal
|
|
316
278
|
*/
|
|
317
279
|
getNative(): NativeAudioFifo;
|
|
318
280
|
/**
|
|
@@ -323,17 +285,12 @@ export declare class AudioFifo implements Disposable, NativeWrapper<NativeAudioF
|
|
|
323
285
|
*
|
|
324
286
|
* @example
|
|
325
287
|
* ```typescript
|
|
326
|
-
* import { AudioFifo } from 'node-av';
|
|
327
|
-
* import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
328
|
-
*
|
|
329
288
|
* {
|
|
330
289
|
* using fifo = new AudioFifo();
|
|
331
|
-
* fifo.alloc(
|
|
332
|
-
* // ...
|
|
290
|
+
* fifo.alloc(AV_SAMPLE_FMT_FLTP, 2, 4096);
|
|
291
|
+
* // Use fifo...
|
|
333
292
|
* } // Automatically freed when leaving scope
|
|
334
293
|
* ```
|
|
335
|
-
*
|
|
336
|
-
* @see {@link free} For manual cleanup
|
|
337
294
|
*/
|
|
338
295
|
[Symbol.dispose](): void;
|
|
339
296
|
}
|