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.
Files changed (192) hide show
  1. package/README.md +88 -52
  2. package/binding.gyp +23 -11
  3. package/dist/api/audio-frame-buffer.d.ts +201 -0
  4. package/dist/api/audio-frame-buffer.js +275 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +320 -78
  7. package/dist/api/bitstream-filter.js +684 -151
  8. package/dist/api/bitstream-filter.js.map +1 -1
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  14. package/dist/api/data/test_vp8.ivf +0 -0
  15. package/dist/api/data/test_vp9.ivf +0 -0
  16. package/dist/api/decoder.d.ts +454 -77
  17. package/dist/api/decoder.js +1081 -271
  18. package/dist/api/decoder.js.map +1 -1
  19. package/dist/api/{media-input.d.ts → demuxer.d.ts} +295 -45
  20. package/dist/api/demuxer.js +1965 -0
  21. package/dist/api/demuxer.js.map +1 -0
  22. package/dist/api/encoder.d.ts +423 -132
  23. package/dist/api/encoder.js +1089 -240
  24. package/dist/api/encoder.js.map +1 -1
  25. package/dist/api/filter-complex.d.ts +769 -0
  26. package/dist/api/filter-complex.js +1596 -0
  27. package/dist/api/filter-complex.js.map +1 -0
  28. package/dist/api/filter-presets.d.ts +80 -5
  29. package/dist/api/filter-presets.js +117 -7
  30. package/dist/api/filter-presets.js.map +1 -1
  31. package/dist/api/filter.d.ts +561 -125
  32. package/dist/api/filter.js +1083 -274
  33. package/dist/api/filter.js.map +1 -1
  34. package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
  35. package/dist/api/fmp4-stream.js +539 -0
  36. package/dist/api/fmp4-stream.js.map +1 -0
  37. package/dist/api/hardware.d.ts +58 -6
  38. package/dist/api/hardware.js +127 -11
  39. package/dist/api/hardware.js.map +1 -1
  40. package/dist/api/index.d.ts +8 -4
  41. package/dist/api/index.js +17 -8
  42. package/dist/api/index.js.map +1 -1
  43. package/dist/api/io-stream.d.ts +6 -6
  44. package/dist/api/io-stream.js +5 -4
  45. package/dist/api/io-stream.js.map +1 -1
  46. package/dist/api/{media-output.d.ts → muxer.d.ts} +280 -66
  47. package/dist/api/muxer.js +1934 -0
  48. package/dist/api/muxer.js.map +1 -0
  49. package/dist/api/pipeline.d.ts +77 -29
  50. package/dist/api/pipeline.js +449 -439
  51. package/dist/api/pipeline.js.map +1 -1
  52. package/dist/api/rtp-stream.d.ts +312 -0
  53. package/dist/api/rtp-stream.js +630 -0
  54. package/dist/api/rtp-stream.js.map +1 -0
  55. package/dist/api/types.d.ts +533 -56
  56. package/dist/api/utilities/async-queue.d.ts +91 -0
  57. package/dist/api/utilities/async-queue.js +162 -0
  58. package/dist/api/utilities/async-queue.js.map +1 -0
  59. package/dist/api/utilities/audio-sample.d.ts +11 -1
  60. package/dist/api/utilities/audio-sample.js +10 -0
  61. package/dist/api/utilities/audio-sample.js.map +1 -1
  62. package/dist/api/utilities/channel-layout.d.ts +1 -0
  63. package/dist/api/utilities/channel-layout.js +1 -0
  64. package/dist/api/utilities/channel-layout.js.map +1 -1
  65. package/dist/api/utilities/image.d.ts +39 -1
  66. package/dist/api/utilities/image.js +38 -0
  67. package/dist/api/utilities/image.js.map +1 -1
  68. package/dist/api/utilities/index.d.ts +3 -0
  69. package/dist/api/utilities/index.js +6 -0
  70. package/dist/api/utilities/index.js.map +1 -1
  71. package/dist/api/utilities/media-type.d.ts +2 -1
  72. package/dist/api/utilities/media-type.js +1 -0
  73. package/dist/api/utilities/media-type.js.map +1 -1
  74. package/dist/api/utilities/pixel-format.d.ts +4 -1
  75. package/dist/api/utilities/pixel-format.js +3 -0
  76. package/dist/api/utilities/pixel-format.js.map +1 -1
  77. package/dist/api/utilities/sample-format.d.ts +6 -1
  78. package/dist/api/utilities/sample-format.js +5 -0
  79. package/dist/api/utilities/sample-format.js.map +1 -1
  80. package/dist/api/utilities/scheduler.d.ts +138 -0
  81. package/dist/api/utilities/scheduler.js +98 -0
  82. package/dist/api/utilities/scheduler.js.map +1 -0
  83. package/dist/api/utilities/streaming.d.ts +105 -15
  84. package/dist/api/utilities/streaming.js +201 -12
  85. package/dist/api/utilities/streaming.js.map +1 -1
  86. package/dist/api/utilities/timestamp.d.ts +15 -1
  87. package/dist/api/utilities/timestamp.js +14 -0
  88. package/dist/api/utilities/timestamp.js.map +1 -1
  89. package/dist/api/utilities/whisper-model.d.ts +310 -0
  90. package/dist/api/utilities/whisper-model.js +528 -0
  91. package/dist/api/utilities/whisper-model.js.map +1 -0
  92. package/dist/api/webrtc-stream.d.ts +288 -0
  93. package/dist/api/webrtc-stream.js +440 -0
  94. package/dist/api/webrtc-stream.js.map +1 -0
  95. package/dist/api/whisper.d.ts +324 -0
  96. package/dist/api/whisper.js +362 -0
  97. package/dist/api/whisper.js.map +1 -0
  98. package/dist/constants/constants.d.ts +54 -2
  99. package/dist/constants/constants.js +48 -1
  100. package/dist/constants/constants.js.map +1 -1
  101. package/dist/constants/encoders.d.ts +2 -1
  102. package/dist/constants/encoders.js +4 -3
  103. package/dist/constants/encoders.js.map +1 -1
  104. package/dist/constants/hardware.d.ts +26 -0
  105. package/dist/constants/hardware.js +27 -0
  106. package/dist/constants/hardware.js.map +1 -0
  107. package/dist/constants/index.d.ts +1 -0
  108. package/dist/constants/index.js +1 -0
  109. package/dist/constants/index.js.map +1 -1
  110. package/dist/ffmpeg/index.d.ts +3 -3
  111. package/dist/ffmpeg/index.js +3 -3
  112. package/dist/ffmpeg/utils.d.ts +27 -0
  113. package/dist/ffmpeg/utils.js +28 -16
  114. package/dist/ffmpeg/utils.js.map +1 -1
  115. package/dist/lib/binding.d.ts +22 -11
  116. package/dist/lib/binding.js.map +1 -1
  117. package/dist/lib/codec-context.d.ts +87 -0
  118. package/dist/lib/codec-context.js +125 -4
  119. package/dist/lib/codec-context.js.map +1 -1
  120. package/dist/lib/codec-parameters.d.ts +229 -1
  121. package/dist/lib/codec-parameters.js +264 -0
  122. package/dist/lib/codec-parameters.js.map +1 -1
  123. package/dist/lib/codec-parser.d.ts +23 -0
  124. package/dist/lib/codec-parser.js +25 -0
  125. package/dist/lib/codec-parser.js.map +1 -1
  126. package/dist/lib/codec.d.ts +26 -4
  127. package/dist/lib/codec.js +35 -0
  128. package/dist/lib/codec.js.map +1 -1
  129. package/dist/lib/dictionary.js +1 -0
  130. package/dist/lib/dictionary.js.map +1 -1
  131. package/dist/lib/error.js +1 -1
  132. package/dist/lib/error.js.map +1 -1
  133. package/dist/lib/fifo.d.ts +416 -0
  134. package/dist/lib/fifo.js +453 -0
  135. package/dist/lib/fifo.js.map +1 -0
  136. package/dist/lib/filter-context.d.ts +52 -11
  137. package/dist/lib/filter-context.js +56 -12
  138. package/dist/lib/filter-context.js.map +1 -1
  139. package/dist/lib/filter-graph.d.ts +9 -0
  140. package/dist/lib/filter-graph.js +13 -0
  141. package/dist/lib/filter-graph.js.map +1 -1
  142. package/dist/lib/filter.d.ts +21 -0
  143. package/dist/lib/filter.js +28 -0
  144. package/dist/lib/filter.js.map +1 -1
  145. package/dist/lib/format-context.d.ts +48 -14
  146. package/dist/lib/format-context.js +76 -7
  147. package/dist/lib/format-context.js.map +1 -1
  148. package/dist/lib/frame.d.ts +264 -1
  149. package/dist/lib/frame.js +351 -1
  150. package/dist/lib/frame.js.map +1 -1
  151. package/dist/lib/hardware-device-context.d.ts +3 -2
  152. package/dist/lib/hardware-device-context.js.map +1 -1
  153. package/dist/lib/index.d.ts +2 -0
  154. package/dist/lib/index.js +4 -0
  155. package/dist/lib/index.js.map +1 -1
  156. package/dist/lib/input-format.d.ts +21 -0
  157. package/dist/lib/input-format.js +42 -2
  158. package/dist/lib/input-format.js.map +1 -1
  159. package/dist/lib/native-types.d.ts +76 -27
  160. package/dist/lib/option.d.ts +25 -13
  161. package/dist/lib/option.js +28 -0
  162. package/dist/lib/option.js.map +1 -1
  163. package/dist/lib/output-format.d.ts +22 -1
  164. package/dist/lib/output-format.js +28 -0
  165. package/dist/lib/output-format.js.map +1 -1
  166. package/dist/lib/packet.d.ts +35 -0
  167. package/dist/lib/packet.js +52 -2
  168. package/dist/lib/packet.js.map +1 -1
  169. package/dist/lib/rational.d.ts +18 -0
  170. package/dist/lib/rational.js +19 -0
  171. package/dist/lib/rational.js.map +1 -1
  172. package/dist/lib/stream.d.ts +126 -0
  173. package/dist/lib/stream.js +188 -5
  174. package/dist/lib/stream.js.map +1 -1
  175. package/dist/lib/sync-queue.d.ts +179 -0
  176. package/dist/lib/sync-queue.js +197 -0
  177. package/dist/lib/sync-queue.js.map +1 -0
  178. package/dist/lib/types.d.ts +49 -1
  179. package/dist/lib/utilities.d.ts +281 -53
  180. package/dist/lib/utilities.js +298 -55
  181. package/dist/lib/utilities.js.map +1 -1
  182. package/install/check.js +2 -2
  183. package/package.json +37 -26
  184. package/dist/api/fmp4.js +0 -710
  185. package/dist/api/fmp4.js.map +0 -1
  186. package/dist/api/media-input.js +0 -1075
  187. package/dist/api/media-input.js.map +0 -1
  188. package/dist/api/media-output.js +0 -1040
  189. package/dist/api/media-output.js.map +0 -1
  190. package/dist/api/webrtc.d.ts +0 -664
  191. package/dist/api/webrtc.js +0 -1132
  192. package/dist/api/webrtc.js.map +0 -1
@@ -0,0 +1,453 @@
1
+ import { AVFLAG_NONE } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ /**
4
+ * Generic FIFO (First-In-First-Out) buffer for arbitrary data types.
5
+ *
6
+ * Provides a thread-safe buffer for generic data elements. Unlike AudioFifo which is
7
+ * specialized for audio samples, Fifo can handle any data type by specifying the element size.
8
+ * Supports automatic growth and manual size management.
9
+ *
10
+ * Direct mapping to FFmpeg's AVFifo.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { Fifo, FFmpegError } from 'node-av';
15
+ * import { AV_FIFO_FLAG_AUTO_GROW } from 'node-av/constants';
16
+ *
17
+ * // Create FIFO for 32-bit integers
18
+ * const fifo = new Fifo();
19
+ * fifo.alloc(100, 4, AV_FIFO_FLAG_AUTO_GROW);
20
+ * fifo.setAutoGrowLimit(1000);
21
+ *
22
+ * // Write data
23
+ * const data = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
24
+ * const written = await fifo.write(data, 2); // Write 2 elements (8 bytes)
25
+ * FFmpegError.throwIfError(written, 'write');
26
+ *
27
+ * // Read data
28
+ * const outBuffer = Buffer.alloc(8);
29
+ * const read = await fifo.read(outBuffer, 2); // Read 2 elements
30
+ * FFmpegError.throwIfError(read, 'read');
31
+ *
32
+ * // Cleanup
33
+ * fifo.free();
34
+ * ```
35
+ *
36
+ * @see [AVFifo](https://ffmpeg.org/doxygen/trunk/structAVFifo.html) - FFmpeg Doxygen
37
+ */
38
+ export class Fifo {
39
+ native;
40
+ constructor() {
41
+ this.native = new bindings.Fifo();
42
+ }
43
+ /**
44
+ * Number of elements currently in the FIFO.
45
+ *
46
+ * Direct mapping to av_fifo_can_read().
47
+ */
48
+ get size() {
49
+ return this.native.size;
50
+ }
51
+ /**
52
+ * Number of elements that can be read from the FIFO.
53
+ *
54
+ * Direct mapping to av_fifo_can_read().
55
+ */
56
+ get canRead() {
57
+ return this.native.canRead;
58
+ }
59
+ /**
60
+ * Number of elements that can be written without reallocation.
61
+ *
62
+ * Direct mapping to av_fifo_can_write().
63
+ */
64
+ get canWrite() {
65
+ return this.native.canWrite;
66
+ }
67
+ /**
68
+ * Size in bytes of a single element.
69
+ *
70
+ * Direct mapping to av_fifo_elem_size().
71
+ */
72
+ get elemSize() {
73
+ return this.native.elemSize;
74
+ }
75
+ /**
76
+ * Allocate an AVFifo buffer.
77
+ *
78
+ * Creates a FIFO buffer with the specified element count, size and flags.
79
+ * The FIFO can be configured to automatically grow when full.
80
+ *
81
+ * Direct mapping to av_fifo_alloc2().
82
+ *
83
+ * @param nbElems - Initial number of elements to allocate
84
+ *
85
+ * @param elemSize - Size in bytes of each element
86
+ *
87
+ * @param flags - Optional flags (e.g., AV_FIFO_FLAG_AUTO_GROW). Defaults to 0
88
+ *
89
+ * @throws {Error} If allocation fails (ENOMEM)
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import { Fifo } from 'node-av';
94
+ * import { AV_FIFO_FLAG_AUTO_GROW } from 'node-av/constants';
95
+ *
96
+ * // Fixed size FIFO for 100 32-bit integers
97
+ * const fifo1 = new Fifo();
98
+ * fifo1.alloc(100, 4);
99
+ *
100
+ * // Auto-growing FIFO for 8-byte structures
101
+ * const fifo2 = new Fifo();
102
+ * fifo2.alloc(50, 8, AV_FIFO_FLAG_AUTO_GROW);
103
+ * fifo2.setAutoGrowLimit(1000); // Max 1000 elements
104
+ * ```
105
+ *
106
+ * @see {@link grow} To manually grow the FIFO
107
+ * @see {@link setAutoGrowLimit} To set auto-grow limit
108
+ * @see {@link free} To release the FIFO
109
+ */
110
+ alloc(nbElems, elemSize, flags = AVFLAG_NONE) {
111
+ this.native.alloc(nbElems, elemSize, flags);
112
+ }
113
+ /**
114
+ * Free the FIFO buffer and all associated resources.
115
+ *
116
+ * After calling this, the FIFO is invalid and must be reallocated before use.
117
+ *
118
+ * Direct mapping to av_fifo_freep().
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * fifo.free();
123
+ * // FIFO is now invalid, must call alloc() before using again
124
+ * ```
125
+ *
126
+ * @see {@link Symbol.dispose} For automatic cleanup
127
+ * @see {@link alloc} To allocate
128
+ */
129
+ free() {
130
+ this.native.free();
131
+ }
132
+ /**
133
+ * Write elements to the FIFO.
134
+ *
135
+ * Writes elements to the FIFO buffer. If AV_FIFO_FLAG_AUTO_GROW was set,
136
+ * automatically reallocates if more space is needed (up to auto-grow limit).
137
+ *
138
+ * Direct mapping to av_fifo_write().
139
+ *
140
+ * @param buf - Data buffer containing elements to write
141
+ *
142
+ * @param nbElems - Number of elements to write
143
+ *
144
+ * @returns Number of elements written (>= 0), or negative AVERROR:
145
+ * - AVERROR_EINVAL: Invalid parameters
146
+ * - AVERROR_ENOMEM: Not enough space and auto-grow failed/disabled
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * import { FFmpegError } from 'node-av';
151
+ *
152
+ * // Write 4 32-bit integers (16 bytes)
153
+ * const data = Buffer.from([
154
+ * 0x01, 0x00, 0x00, 0x00, // 1
155
+ * 0x02, 0x00, 0x00, 0x00, // 2
156
+ * 0x03, 0x00, 0x00, 0x00, // 3
157
+ * 0x04, 0x00, 0x00, 0x00, // 4
158
+ * ]);
159
+ * const written = await fifo.write(data, 4);
160
+ * FFmpegError.throwIfError(written, 'write');
161
+ * console.log(`Wrote ${written} elements`);
162
+ * ```
163
+ *
164
+ * @see {@link read} To retrieve elements from FIFO
165
+ * @see {@link canWrite} To check available space
166
+ */
167
+ async write(buf, nbElems) {
168
+ return await this.native.write(buf, nbElems);
169
+ }
170
+ /**
171
+ * Write elements to the FIFO synchronously.
172
+ * Synchronous version of write.
173
+ *
174
+ * Writes elements to the FIFO buffer. Can write fewer elements than requested
175
+ * if space is limited and auto-grow is disabled or has reached the limit.
176
+ *
177
+ * Direct mapping to av_fifo_write().
178
+ *
179
+ * @param buf - Data buffer containing elements to write
180
+ *
181
+ * @param nbElems - Number of elements to write
182
+ *
183
+ * @returns Number of elements written (>= 0), or negative AVERROR:
184
+ * - AVERROR_EINVAL: Invalid parameters
185
+ * - AVERROR_ENOMEM: Not enough space
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { FFmpegError } from 'node-av';
190
+ *
191
+ * const buffer = Buffer.alloc(32); // 8 elements of 4 bytes each
192
+ * // Fill with data...
193
+ *
194
+ * const written = fifo.writeSync(buffer, 8);
195
+ * FFmpegError.throwIfError(written, 'writeSync');
196
+ * console.log(`Wrote ${written} elements`);
197
+ * ```
198
+ *
199
+ * @see {@link write} For async version
200
+ */
201
+ writeSync(buf, nbElems) {
202
+ return this.native.writeSync(buf, nbElems);
203
+ }
204
+ /**
205
+ * Read and remove elements from the FIFO.
206
+ *
207
+ * Reads up to the specified number of elements from the FIFO.
208
+ * The elements are removed from the FIFO after reading.
209
+ * Buffer must be pre-allocated with sufficient size (nbElems * elemSize).
210
+ *
211
+ * Direct mapping to av_fifo_read().
212
+ *
213
+ * @param buf - Pre-allocated buffer to read into
214
+ *
215
+ * @param nbElems - Maximum number of elements to read
216
+ *
217
+ * @returns Number of elements read (>= 0), or negative AVERROR:
218
+ * - AVERROR_EINVAL: Invalid parameters or insufficient buffer size
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * import { FFmpegError } from 'node-av';
223
+ *
224
+ * // Check available elements
225
+ * const available = fifo.canRead;
226
+ * if (available >= 10) {
227
+ * // Read 10 elements (40 bytes for 4-byte elements)
228
+ * const outBuffer = Buffer.alloc(40);
229
+ * const read = await fifo.read(outBuffer, 10);
230
+ * FFmpegError.throwIfError(read, 'read');
231
+ * console.log(`Read ${read} elements`);
232
+ * }
233
+ * ```
234
+ *
235
+ * @see {@link peek} To read without removing
236
+ * @see {@link canRead} To check available elements
237
+ */
238
+ async read(buf, nbElems) {
239
+ return await this.native.read(buf, nbElems);
240
+ }
241
+ /**
242
+ * Read and remove elements from the FIFO synchronously.
243
+ * Synchronous version of read.
244
+ *
245
+ * Reads up to the specified number of elements from the FIFO.
246
+ * The elements are removed from the FIFO after reading.
247
+ * Buffer must be pre-allocated with sufficient size.
248
+ *
249
+ * Direct mapping to av_fifo_read().
250
+ *
251
+ * @param buf - Pre-allocated buffer to read into
252
+ *
253
+ * @param nbElems - Maximum number of elements to read
254
+ *
255
+ * @returns Number of elements read (>= 0), or negative AVERROR:
256
+ * - AVERROR_EINVAL: Invalid parameters
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * import { FFmpegError } from 'node-av';
261
+ *
262
+ * // Read up to 20 elements
263
+ * const readBuffer = Buffer.alloc(20 * fifo.elemSize);
264
+ * const read = fifo.readSync(readBuffer, 20);
265
+ * FFmpegError.throwIfError(read, 'readSync');
266
+ *
267
+ * console.log(`Read ${read} elements from FIFO`);
268
+ * console.log(`FIFO now has ${fifo.canRead} elements remaining`);
269
+ * ```
270
+ *
271
+ * @see {@link read} For async version
272
+ */
273
+ readSync(buf, nbElems) {
274
+ return this.native.readSync(buf, nbElems);
275
+ }
276
+ /**
277
+ * Read elements from the FIFO without removing them.
278
+ *
279
+ * Similar to read() but leaves the elements in the FIFO.
280
+ * Useful for inspecting upcoming data without consuming it.
281
+ * Optionally start reading from an offset.
282
+ *
283
+ * Direct mapping to av_fifo_peek().
284
+ *
285
+ * @param buf - Pre-allocated buffer to peek into
286
+ *
287
+ * @param nbElems - Maximum number of elements to peek
288
+ *
289
+ * @param offset - Offset in elements from start of FIFO. Defaults to 0
290
+ *
291
+ * @returns Number of elements peeked (>= 0), or negative AVERROR:
292
+ * - AVERROR_EINVAL: Invalid parameters or offset too large
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * import { FFmpegError } from 'node-av';
297
+ *
298
+ * // Peek at next 5 elements without removing them
299
+ * const peekBuffer = Buffer.alloc(5 * fifo.elemSize);
300
+ * const peeked = await fifo.peek(peekBuffer, 5);
301
+ * FFmpegError.throwIfError(peeked, 'peek');
302
+ *
303
+ * // Peek at elements starting at offset 10
304
+ * const peeked2 = await fifo.peek(peekBuffer, 5, 10);
305
+ * FFmpegError.throwIfError(peeked2, 'peek');
306
+ *
307
+ * // Elements are still in FIFO
308
+ * console.log(`FIFO still has ${fifo.canRead} elements`);
309
+ * ```
310
+ *
311
+ * @see {@link read} To read and remove elements
312
+ */
313
+ async peek(buf, nbElems, offset = 0) {
314
+ return await this.native.peek(buf, nbElems, offset);
315
+ }
316
+ /**
317
+ * Read elements from the FIFO without removing them synchronously.
318
+ * Synchronous version of peek.
319
+ *
320
+ * Similar to readSync() but leaves the elements in the FIFO.
321
+ * Useful for inspecting upcoming data without consuming it.
322
+ * Optionally start reading from an offset.
323
+ *
324
+ * Direct mapping to av_fifo_peek().
325
+ *
326
+ * @param buf - Pre-allocated buffer to peek into
327
+ *
328
+ * @param nbElems - Maximum number of elements to peek
329
+ *
330
+ * @param offset - Offset in elements from start of FIFO. Defaults to 0
331
+ *
332
+ * @returns Number of elements peeked (>= 0), or negative AVERROR:
333
+ * - AVERROR_EINVAL: Invalid parameters or offset too large
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * import { FFmpegError } from 'node-av';
338
+ *
339
+ * // Peek at next elements without removing them
340
+ * const peekBuffer = Buffer.alloc(10 * fifo.elemSize);
341
+ * const peeked = fifo.peekSync(peekBuffer, 10);
342
+ * FFmpegError.throwIfError(peeked, 'peekSync');
343
+ *
344
+ * // Elements are still in FIFO
345
+ * console.log(`FIFO still has ${fifo.canRead} elements`);
346
+ * ```
347
+ *
348
+ * @see {@link peek} For async version
349
+ */
350
+ peekSync(buf, nbElems, offset = 0) {
351
+ return this.native.peekSync(buf, nbElems, offset);
352
+ }
353
+ /**
354
+ * Grow the FIFO buffer by the specified number of elements.
355
+ *
356
+ * Increases the allocated size of the FIFO by adding more space.
357
+ * Existing elements are preserved.
358
+ *
359
+ * Direct mapping to av_fifo_grow2().
360
+ *
361
+ * @param inc - Number of additional elements to allocate
362
+ *
363
+ * @returns 0 on success, negative AVERROR on error:
364
+ * - AVERROR_EINVAL: Invalid size
365
+ * - AVERROR_ENOMEM: Memory allocation failure
366
+ *
367
+ * @example
368
+ * ```typescript
369
+ * import { FFmpegError } from 'node-av';
370
+ *
371
+ * // Grow FIFO to handle more elements
372
+ * const ret = fifo.grow(100);
373
+ * FFmpegError.throwIfError(ret, 'grow');
374
+ * console.log(`New write capacity: ${fifo.canWrite} elements`);
375
+ * ```
376
+ *
377
+ * @see {@link alloc} For initial allocation
378
+ */
379
+ grow(inc) {
380
+ return this.native.grow(inc);
381
+ }
382
+ /**
383
+ * Remove all elements from the FIFO.
384
+ *
385
+ * Empties the FIFO buffer without deallocating it.
386
+ * The FIFO remains allocated and ready for new data.
387
+ *
388
+ * Direct mapping to av_fifo_reset2().
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * fifo.reset();
393
+ * console.log(fifo.canRead); // 0
394
+ * console.log(fifo.canWrite); // Original allocation size
395
+ * ```
396
+ */
397
+ reset() {
398
+ this.native.reset();
399
+ }
400
+ /**
401
+ * Set the maximum number of elements for auto-grow.
402
+ *
403
+ * When AV_FIFO_FLAG_AUTO_GROW is set, the FIFO will automatically grow
404
+ * up to this limit when full. After reaching the limit, writes will fail.
405
+ *
406
+ * Direct mapping to av_fifo_auto_grow_limit().
407
+ *
408
+ * @param maxElems - Maximum number of elements (0 = unlimited)
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * import { AV_FIFO_FLAG_AUTO_GROW } from 'node-av/constants';
413
+ *
414
+ * const fifo = new Fifo();
415
+ * fifo.alloc(100, 4, AV_FIFO_FLAG_AUTO_GROW);
416
+ * fifo.setAutoGrowLimit(10000); // Limit to 10000 elements
417
+ * ```
418
+ *
419
+ * @see {@link alloc} For setting auto-grow flag
420
+ */
421
+ setAutoGrowLimit(maxElems) {
422
+ this.native.setAutoGrowLimit(maxElems);
423
+ }
424
+ /**
425
+ * Get the underlying native Fifo object.
426
+ *
427
+ * @returns The native Fifo binding object
428
+ *
429
+ * @internal
430
+ */
431
+ getNative() {
432
+ return this.native;
433
+ }
434
+ /**
435
+ * Dispose of the FIFO buffer.
436
+ *
437
+ * Implements the Disposable interface for automatic cleanup.
438
+ * Equivalent to calling free().
439
+ *
440
+ * @example
441
+ * ```typescript
442
+ * {
443
+ * using fifo = new Fifo();
444
+ * fifo.alloc(100, 4);
445
+ * // Use fifo...
446
+ * } // Automatically freed when leaving scope
447
+ * ```
448
+ */
449
+ [Symbol.dispose]() {
450
+ this.native[Symbol.dispose]();
451
+ }
452
+ }
453
+ //# sourceMappingURL=fifo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fifo.js","sourceRoot":"","sources":["../../src/lib/fifo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B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IACzC,CAAC;IAED;;;;;;OAMG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}
@@ -2,7 +2,7 @@ import { Filter } from './filter.js';
2
2
  import { HardwareDeviceContext } from './hardware-device-context.js';
3
3
  import { OptionMember } from './option.js';
4
4
  import { Rational } from './rational.js';
5
- import type { AVColorRange, AVColorSpace, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
5
+ import type { AVBufferSrcFlag, AVColorRange, AVColorSpace, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
6
6
  import type { Frame } from './frame.js';
7
7
  import type { HardwareFramesContext } from './hardware-frames-context.js';
8
8
  import type { NativeDictionary, NativeFilterContext, NativeFilterGraph, NativeWrapper } from './native-types.js';
@@ -228,10 +228,12 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
228
228
  * Sends a frame into the filter graph through a buffer source.
229
229
  * Only valid for buffer source filters. Send null to signal EOF.
230
230
  *
231
- * Direct mapping to av_buffersrc_add_frame().
231
+ * Direct mapping to av_buffersrc_add_frame_flags().
232
232
  *
233
233
  * @param frame - Frame to send, or null for EOF
234
234
  *
235
+ * @param flags - Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)
236
+ *
235
237
  * @returns 0 on success, negative AVERROR on error:
236
238
  * - AVERROR_EAGAIN: Filter needs more output consumption
237
239
  * - AVERROR_EOF: Filter has been closed
@@ -241,10 +243,10 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
241
243
  * @example
242
244
  * ```typescript
243
245
  * import { FFmpegError } from 'node-av';
244
- * import { AVERROR_EAGAIN } from 'node-av/constants';
246
+ * import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';
245
247
  *
246
- * // Send frame to filter graph
247
- * const ret = await bufferSrc.buffersrcAddFrame(frame);
248
+ * // Send frame to filter graph with PUSH flag (immediate processing)
249
+ * const ret = await bufferSrc.buffersrcAddFrame(frame, AV_BUFFERSRC_FLAG_PUSH);
248
250
  * if (ret === AVERROR_EAGAIN) {
249
251
  * // Need to consume output first
250
252
  * } else {
@@ -257,7 +259,7 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
257
259
  *
258
260
  * @see {@link buffersinkGetFrame} To retrieve filtered frames
259
261
  */
260
- buffersrcAddFrame(frame: Frame | null): Promise<number>;
262
+ buffersrcAddFrame(frame: Frame | null, flags?: AVBufferSrcFlag): Promise<number>;
261
263
  /**
262
264
  * Add frame to buffer source filter synchronously.
263
265
  * Synchronous version of buffersrcAddFrame.
@@ -265,10 +267,12 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
265
267
  * Sends a frame to a buffer source filter for processing.
266
268
  * Only valid for buffer source filters (buffer, abuffer).
267
269
  *
268
- * Direct mapping to av_buffersrc_add_frame().
270
+ * Direct mapping to av_buffersrc_add_frame_flags().
269
271
  *
270
272
  * @param frame - Frame to send (null to mark EOF)
271
273
  *
274
+ * @param flags - Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)
275
+ *
272
276
  * @returns 0 on success, negative AVERROR on error:
273
277
  * - AVERROR_EAGAIN: Need to retrieve output first
274
278
  * - AVERROR_EOF: Graph has finished processing
@@ -278,10 +282,10 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
278
282
  * @example
279
283
  * ```typescript
280
284
  * import { FFmpegError } from 'node-av';
281
- * import { AVERROR_EAGAIN } from 'node-av/constants';
285
+ * import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';
282
286
  *
283
- * // Send frame to filter
284
- * const ret = bufferSrc.buffersrcAddFrameSync(frame);
287
+ * // Send frame to filter with PUSH flag (immediate processing)
288
+ * const ret = bufferSrc.buffersrcAddFrameSync(frame, AV_BUFFERSRC_FLAG_PUSH);
285
289
  * if (ret === AVERROR_EAGAIN) {
286
290
  * // Need to get output frames first
287
291
  * const filtered = new Frame();
@@ -296,7 +300,7 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
296
300
  *
297
301
  * @see {@link buffersrcAddFrame} For async version
298
302
  */
299
- buffersrcAddFrameSync(frame: Frame | null): number;
303
+ buffersrcAddFrameSync(frame: Frame | null, flags?: AVBufferSrcFlag): number;
300
304
  /**
301
305
  * Set parameters for a buffer source filter.
302
306
  *
@@ -329,6 +333,8 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
329
333
  *
330
334
  * @param params.colorSpace - Color space for video
331
335
  *
336
+ * @param params.alphaMode - Alpha channel mode
337
+ *
332
338
  * @returns 0 on success, negative AVERROR on error:
333
339
  * - AVERROR_EINVAL: Invalid parameters
334
340
  * - AVERROR_ENOMEM: Memory allocation failure
@@ -374,6 +380,7 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
374
380
  channelLayout?: bigint;
375
381
  colorRange?: AVColorRange;
376
382
  colorSpace?: AVColorSpace;
383
+ alphaMode?: number;
377
384
  }): number;
378
385
  /**
379
386
  * Get a frame from a buffer sink filter.
@@ -593,6 +600,40 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
593
600
  * ```
594
601
  */
595
602
  buffersinkGetChannelLayout(): ChannelLayout;
603
+ /**
604
+ * Get color space from buffer sink.
605
+ *
606
+ * Returns the color space of video from a buffer sink filter.
607
+ * Only valid for video buffer sink filters.
608
+ *
609
+ * Direct mapping to av_buffersink_get_colorspace().
610
+ *
611
+ * @returns Color space
612
+ *
613
+ * @example
614
+ * ```typescript
615
+ * const colorSpace = bufferSink.buffersinkGetColorspace();
616
+ * console.log(`Color space: ${colorSpace}`);
617
+ * ```
618
+ */
619
+ buffersinkGetColorspace(): AVColorSpace;
620
+ /**
621
+ * Get color range from buffer sink.
622
+ *
623
+ * Returns the color range of video from a buffer sink filter.
624
+ * Only valid for video buffer sink filters.
625
+ *
626
+ * Direct mapping to av_buffersink_get_color_range().
627
+ *
628
+ * @returns Color range
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * const colorRange = bufferSink.buffersinkGetColorRange();
633
+ * console.log(`Color range: ${colorRange}`);
634
+ * ```
635
+ */
636
+ buffersinkGetColorRange(): AVColorRange;
596
637
  /**
597
638
  * Free the filter context.
598
639
  *