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