@revizly/node-av 5.2.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,592 @@
1
+ import { bindings } from './binding.js';
2
+ import { OptionMember } from './option.js';
3
+ /**
4
+ * Audio resampling and format conversion context.
5
+ *
6
+ * Provides comprehensive audio format conversion including sample rate conversion,
7
+ * channel layout remapping, and sample format conversion. Essential for audio
8
+ * processing pipelines where format compatibility is required between components.
9
+ * Supports high-quality resampling algorithms with configurable parameters.
10
+ *
11
+ * Direct mapping to FFmpeg's SwrContext.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { SoftwareResampleContext, Frame, FFmpegError } from 'node-av';
16
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
17
+ *
18
+ * // Create resampler
19
+ * const resampler = new SoftwareResampleContext();
20
+ *
21
+ * // Configure format conversion
22
+ * const outLayout = { nbChannels: 2, order: 1, u: { mask: 3n } }; // Stereo
23
+ * const inLayout = { nbChannels: 1, order: 1, u: { mask: 1n } }; // Mono
24
+ *
25
+ * const ret = resampler.allocSetOpts2(
26
+ * outLayout, AV_SAMPLE_FMT_S16, 48000, // Output: Stereo, 16-bit, 48kHz
27
+ * inLayout, AV_SAMPLE_FMT_FLTP, 44100 // Input: Mono, float, 44.1kHz
28
+ * );
29
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
30
+ *
31
+ * const ret2 = resampler.init();
32
+ * FFmpegError.throwIfError(ret2, 'init');
33
+ *
34
+ * // Convert audio frame
35
+ * const outFrame = new Frame();
36
+ * outFrame.nbSamples = 1024;
37
+ * outFrame.format = AV_SAMPLE_FMT_S16;
38
+ * outFrame.channelLayout = outLayout;
39
+ * outFrame.sampleRate = 48000;
40
+ * outFrame.allocBuffer();
41
+ *
42
+ * const ret3 = resampler.convertFrame(outFrame, inFrame);
43
+ * FFmpegError.throwIfError(ret3, 'convertFrame');
44
+ *
45
+ * // Get conversion delay
46
+ * const delay = resampler.getDelay(48000n);
47
+ * console.log(`Resampler delay: ${delay} samples`);
48
+ *
49
+ * // Clean up
50
+ * resampler.free();
51
+ * ```
52
+ *
53
+ * @see [SwrContext](https://ffmpeg.org/doxygen/trunk/structSwrContext.html) - FFmpeg Doxygen
54
+ * @see {@link Frame} For audio frame operations
55
+ */
56
+ export class SoftwareResampleContext extends OptionMember {
57
+ constructor() {
58
+ super(new bindings.SoftwareResampleContext());
59
+ }
60
+ /**
61
+ * Allocate resample context.
62
+ *
63
+ * Allocates memory for the resampler.
64
+ * Must be called before configuration.
65
+ *
66
+ * Direct mapping to swr_alloc().
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const resampler = new SoftwareResampleContext();
71
+ * resampler.alloc();
72
+ * // Now configure with setOption() or allocSetOpts2()
73
+ * ```
74
+ *
75
+ * @see {@link allocSetOpts2} For combined allocation and configuration
76
+ */
77
+ alloc() {
78
+ this.native.alloc();
79
+ }
80
+ /**
81
+ * Allocate and configure resampler.
82
+ *
83
+ * Combined allocation and configuration of the resampler with
84
+ * input and output format specifications.
85
+ *
86
+ * Direct mapping to swr_alloc_set_opts2().
87
+ *
88
+ * @param outChLayout - Output channel layout
89
+ *
90
+ * @param outSampleFmt - Output sample format
91
+ *
92
+ * @param outSampleRate - Output sample rate in Hz
93
+ *
94
+ * @param inChLayout - Input channel layout
95
+ *
96
+ * @param inSampleFmt - Input sample format
97
+ *
98
+ * @param inSampleRate - Input sample rate in Hz
99
+ *
100
+ * @returns 0 on success, negative AVERROR on error:
101
+ * - AVERROR_EINVAL: Invalid parameters
102
+ * - AVERROR_ENOMEM: Memory allocation failure
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * import { FFmpegError } from 'node-av';
107
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
108
+ *
109
+ * // Stereo layout
110
+ * const stereo = { nbChannels: 2, order: 1, u: { mask: 3n } };
111
+ * // 5.1 layout
112
+ * const surround = { nbChannels: 6, order: 1, u: { mask: 63n } };
113
+ *
114
+ * // Convert 5.1 float to stereo 16-bit
115
+ * const ret = resampler.allocSetOpts2(
116
+ * stereo, AV_SAMPLE_FMT_S16, 48000,
117
+ * surround, AV_SAMPLE_FMT_FLTP, 48000
118
+ * );
119
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
120
+ * ```
121
+ *
122
+ * @see {@link init} Must be called after configuration
123
+ */
124
+ allocSetOpts2(outChLayout, outSampleFmt, outSampleRate, inChLayout, inSampleFmt, inSampleRate) {
125
+ return this.native.allocSetOpts2(outChLayout, outSampleFmt, outSampleRate, inChLayout, inSampleFmt, inSampleRate);
126
+ }
127
+ /**
128
+ * Initialize resampler.
129
+ *
130
+ * Initializes the resampler after configuration.
131
+ * Must be called before any conversion operations.
132
+ *
133
+ * Direct mapping to swr_init().
134
+ *
135
+ * @returns 0 on success, negative AVERROR on error:
136
+ * - AVERROR_EINVAL: Invalid configuration
137
+ * - AVERROR_ENOMEM: Memory allocation failure
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * import { FFmpegError } from 'node-av';
142
+ *
143
+ * const ret = resampler.init();
144
+ * FFmpegError.throwIfError(ret, 'init');
145
+ * ```
146
+ *
147
+ * @see {@link allocSetOpts2} For configuration
148
+ * @see {@link isInitialized} To check initialization status
149
+ */
150
+ init() {
151
+ return this.native.init();
152
+ }
153
+ /**
154
+ * Free resampler context.
155
+ *
156
+ * Releases all resources associated with the resampler.
157
+ * The context becomes invalid after calling this.
158
+ *
159
+ * Direct mapping to swr_free().
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * resampler.free();
164
+ * // Resampler is now invalid
165
+ * ```
166
+ *
167
+ * @see {@link close} For closing without freeing
168
+ * @see {@link Symbol.dispose} For automatic cleanup
169
+ */
170
+ free() {
171
+ this.native.free();
172
+ }
173
+ /**
174
+ * Close resampler context.
175
+ *
176
+ * Closes the resampler but keeps the context allocated.
177
+ * Can be reconfigured and reinitialized after closing.
178
+ *
179
+ * Direct mapping to swr_close().
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * resampler.close();
184
+ * // Can now reconfigure and reinit
185
+ * ```
186
+ *
187
+ * @see {@link free} For complete deallocation
188
+ */
189
+ close() {
190
+ this.native.close();
191
+ }
192
+ /**
193
+ * Convert audio samples.
194
+ *
195
+ * Converts audio samples from input format to output format.
196
+ * Handles resampling, channel remapping, and format conversion.
197
+ *
198
+ * Direct mapping to swr_convert().
199
+ *
200
+ * @param outBuffer - Output sample buffers (one per channel for planar)
201
+ *
202
+ * @param outCount - Maximum output samples per channel
203
+ *
204
+ * @param inBuffer - Input sample buffers (one per channel for planar)
205
+ *
206
+ * @param inCount - Input samples per channel
207
+ *
208
+ * @returns Number of output samples per channel, negative AVERROR on error:
209
+ * - AVERROR_EINVAL: Invalid parameters
210
+ * - AVERROR_INPUT_CHANGED: Input format changed
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * import { FFmpegError } from 'node-av';
215
+ *
216
+ * // Convert audio buffers
217
+ * const outBuffers = [Buffer.alloc(4096), Buffer.alloc(4096)]; // Stereo
218
+ * const inBuffers = [inputBuffer]; // Mono
219
+ *
220
+ * const samples = await resampler.convert(
221
+ * outBuffers, 1024,
222
+ * inBuffers, inputSamples
223
+ * );
224
+ *
225
+ * if (samples < 0) {
226
+ * FFmpegError.throwIfError(samples, 'convert');
227
+ * }
228
+ * console.log(`Converted ${samples} samples`);
229
+ * ```
230
+ *
231
+ * @see {@link convertFrame} For frame-based conversion
232
+ */
233
+ async convert(outBuffer, outCount, inBuffer, inCount) {
234
+ return await this.native.convert(outBuffer, outCount, inBuffer, inCount);
235
+ }
236
+ /**
237
+ * Convert audio samples synchronously.
238
+ * Synchronous version of convert.
239
+ *
240
+ * Converts audio between formats, sample rates, and channel layouts.
241
+ * Can handle format conversion, resampling, and channel mixing.
242
+ *
243
+ * Direct mapping to swr_convert().
244
+ *
245
+ * @param outBuffer - Output buffer array (one per channel, null to get delay)
246
+ *
247
+ * @param outCount - Number of output samples space per channel
248
+ *
249
+ * @param inBuffer - Input buffer array (one per channel, null to flush)
250
+ *
251
+ * @param inCount - Number of input samples per channel
252
+ *
253
+ * @returns Number of samples output per channel, or negative AVERROR:
254
+ * - AVERROR_EINVAL: Invalid parameters
255
+ * - AVERROR_ENOMEM: Memory allocation failure
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * import { FFmpegError } from 'node-av';
260
+ *
261
+ * // Convert stereo float to mono s16
262
+ * const inBuffers = [leftChannel, rightChannel];
263
+ * const outBuffers = [monoOutput];
264
+ *
265
+ * const samples = resampler.convertSync(
266
+ * outBuffers, 1024, // Output: 1024 samples max
267
+ * inBuffers, 1024 // Input: 1024 samples
268
+ * );
269
+ * FFmpegError.throwIfError(samples, 'convertSync');
270
+ * console.log(`Converted ${samples} samples`);
271
+ * ```
272
+ *
273
+ * @see {@link convert} For async version
274
+ */
275
+ convertSync(outBuffer, outCount, inBuffer, inCount) {
276
+ return this.native.convertSync(outBuffer, outCount, inBuffer, inCount);
277
+ }
278
+ /**
279
+ * Convert audio frame.
280
+ *
281
+ * Converts an entire audio frame to the output format.
282
+ * Simpler interface than convert() for frame-based processing.
283
+ *
284
+ * Direct mapping to swr_convert_frame().
285
+ *
286
+ * @param outFrame - Output frame (null to drain)
287
+ *
288
+ * @param inFrame - Input frame (null to flush)
289
+ *
290
+ * @returns 0 on success, negative AVERROR on error:
291
+ * - AVERROR_EINVAL: Invalid parameters
292
+ * - AVERROR_ENOMEM: Memory allocation failure
293
+ * - AVERROR_INPUT_CHANGED: Input format changed
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * import { Frame, FFmpegError } from 'node-av';
298
+ *
299
+ * // Convert frame
300
+ * const outFrame = new Frame();
301
+ * const ret = resampler.convertFrame(outFrame, inFrame);
302
+ * FFmpegError.throwIfError(ret, 'convertFrame');
303
+ *
304
+ * // Drain remaining samples
305
+ * const drainFrame = new Frame();
306
+ * const ret2 = resampler.convertFrame(drainFrame, null);
307
+ * if (ret2 === 0) {
308
+ * // Got drained samples
309
+ * }
310
+ * ```
311
+ *
312
+ * @see {@link convert} For buffer-based conversion
313
+ * @see {@link configFrame} To configure from frame
314
+ */
315
+ convertFrame(outFrame, inFrame) {
316
+ return this.native.convertFrame(outFrame?.getNative() ?? null, inFrame?.getNative() ?? null);
317
+ }
318
+ /**
319
+ * Configure resampler from frames.
320
+ *
321
+ * Configures the resampler using format information from frames.
322
+ * Alternative to allocSetOpts2() for frame-based setup.
323
+ *
324
+ * Direct mapping to swr_config_frame().
325
+ *
326
+ * @param outFrame - Frame with output format
327
+ *
328
+ * @param inFrame - Frame with input format
329
+ *
330
+ * @returns 0 on success, negative AVERROR on error:
331
+ * - AVERROR_EINVAL: Invalid parameters
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * import { FFmpegError } from 'node-av';
336
+ *
337
+ * // Configure from frames
338
+ * const ret = resampler.configFrame(outFrame, inFrame);
339
+ * FFmpegError.throwIfError(ret, 'configFrame');
340
+ *
341
+ * const ret2 = resampler.init();
342
+ * FFmpegError.throwIfError(ret2, 'init');
343
+ * ```
344
+ *
345
+ * @see {@link allocSetOpts2} For manual configuration
346
+ */
347
+ configFrame(outFrame, inFrame) {
348
+ return this.native.configFrame(outFrame?.getNative() ?? null, inFrame?.getNative() ?? null);
349
+ }
350
+ /**
351
+ * Check if initialized.
352
+ *
353
+ * Returns whether the resampler has been initialized.
354
+ *
355
+ * Direct mapping to swr_is_initialized().
356
+ *
357
+ * @returns True if initialized, false otherwise
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * if (!resampler.isInitialized()) {
362
+ * resampler.init();
363
+ * }
364
+ * ```
365
+ *
366
+ * @see {@link init} To initialize
367
+ */
368
+ isInitialized() {
369
+ return this.native.isInitialized();
370
+ }
371
+ /**
372
+ * Get resampler delay.
373
+ *
374
+ * Returns the number of samples currently buffered in the resampler.
375
+ * These samples will be output when flushing or with new input.
376
+ *
377
+ * Direct mapping to swr_get_delay().
378
+ *
379
+ * @param base - Time base for the returned delay
380
+ *
381
+ * @returns Delay in samples at the given base rate
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * // Get delay in output sample rate
386
+ * const delay = resampler.getDelay(48000n);
387
+ * console.log(`${delay} samples buffered`);
388
+ *
389
+ * // Get delay in microseconds
390
+ * const delayUs = resampler.getDelay(1000000n);
391
+ * console.log(`${delayUs} microseconds delay`);
392
+ * ```
393
+ */
394
+ getDelay(base) {
395
+ return this.native.getDelay(base);
396
+ }
397
+ /**
398
+ * Calculate output sample count.
399
+ *
400
+ * Calculates how many output samples will be produced
401
+ * for a given number of input samples.
402
+ *
403
+ * Direct mapping to swr_get_out_samples().
404
+ *
405
+ * @param inSamples - Number of input samples
406
+ *
407
+ * @returns Number of output samples
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * const outSamples = resampler.getOutSamples(1024);
412
+ * console.log(`1024 input samples -> ${outSamples} output samples`);
413
+ * ```
414
+ */
415
+ getOutSamples(inSamples) {
416
+ return this.native.getOutSamples(inSamples);
417
+ }
418
+ /**
419
+ * Calculate next PTS.
420
+ *
421
+ * Calculates the presentation timestamp for the next output sample.
422
+ *
423
+ * Direct mapping to swr_next_pts().
424
+ *
425
+ * @param pts - Current presentation timestamp
426
+ *
427
+ * @returns Next presentation timestamp
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * let pts = 0n;
432
+ * pts = resampler.nextPts(pts);
433
+ * console.log(`Next PTS: ${pts}`);
434
+ * ```
435
+ */
436
+ nextPts(pts) {
437
+ return this.native.nextPts(pts);
438
+ }
439
+ /**
440
+ * Set compensation.
441
+ *
442
+ * Adjusts the resampling rate to compensate for clock drift.
443
+ * Used for audio/video synchronization.
444
+ *
445
+ * Direct mapping to swr_set_compensation().
446
+ *
447
+ * @param sampleDelta - Sample difference to compensate
448
+ *
449
+ * @param compensationDistance - Distance over which to compensate
450
+ *
451
+ * @returns 0 on success, negative AVERROR on error:
452
+ * - AVERROR_EINVAL: Invalid parameters
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * import { FFmpegError } from 'node-av';
457
+ *
458
+ * // Compensate 10 samples over 1000 samples
459
+ * const ret = resampler.setCompensation(10, 1000);
460
+ * FFmpegError.throwIfError(ret, 'setCompensation');
461
+ * ```
462
+ */
463
+ setCompensation(sampleDelta, compensationDistance) {
464
+ return this.native.setCompensation(sampleDelta, compensationDistance);
465
+ }
466
+ /**
467
+ * Set channel mapping.
468
+ *
469
+ * Sets custom channel mapping for remixing.
470
+ *
471
+ * Direct mapping to swr_set_channel_mapping().
472
+ *
473
+ * @param channelMap - Array mapping input to output channels
474
+ *
475
+ * @returns 0 on success, negative AVERROR on error
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * // Map stereo to reverse stereo (swap L/R)
480
+ * const ret = resampler.setChannelMapping([1, 0]);
481
+ * FFmpegError.throwIfError(ret, 'setChannelMapping');
482
+ * ```
483
+ */
484
+ setChannelMapping(channelMap) {
485
+ return this.native.setChannelMapping(channelMap);
486
+ }
487
+ /**
488
+ * Set mixing matrix.
489
+ *
490
+ * Sets a custom mixing matrix for channel remapping.
491
+ *
492
+ * Direct mapping to swr_set_matrix().
493
+ *
494
+ * @param matrix - Mixing matrix coefficients
495
+ *
496
+ * @param stride - Matrix row stride
497
+ *
498
+ * @returns 0 on success, negative AVERROR on error
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * // Custom downmix matrix
503
+ * const matrix = [
504
+ * 1.0, 0.0, // Left channel
505
+ * 0.0, 1.0, // Right channel
506
+ * ];
507
+ * const ret = resampler.setMatrix(matrix, 2);
508
+ * FFmpegError.throwIfError(ret, 'setMatrix');
509
+ * ```
510
+ */
511
+ setMatrix(matrix, stride) {
512
+ return this.native.setMatrix(matrix, stride);
513
+ }
514
+ /**
515
+ * Drop output samples.
516
+ *
517
+ * Drops the specified number of output samples.
518
+ * Used for synchronization adjustments.
519
+ *
520
+ * Direct mapping to swr_drop_output().
521
+ *
522
+ * @param count - Number of samples to drop
523
+ *
524
+ * @returns 0 on success, negative AVERROR on error
525
+ *
526
+ * @example
527
+ * ```typescript
528
+ * // Drop 100 output samples
529
+ * const ret = resampler.dropOutput(100);
530
+ * if (ret >= 0) {
531
+ * console.log(`Dropped ${ret} samples`);
532
+ * }
533
+ * ```
534
+ */
535
+ dropOutput(count) {
536
+ return this.native.dropOutput(count);
537
+ }
538
+ /**
539
+ * Inject silence.
540
+ *
541
+ * Injects silent samples into the output.
542
+ * Used for padding or synchronization.
543
+ *
544
+ * Direct mapping to swr_inject_silence().
545
+ *
546
+ * @param count - Number of silent samples to inject
547
+ *
548
+ * @returns 0 on success, negative AVERROR on error
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * // Inject 100 silent samples
553
+ * const ret = resampler.injectSilence(100);
554
+ * if (ret >= 0) {
555
+ * console.log(`Injected ${ret} silent samples`);
556
+ * }
557
+ * ```
558
+ */
559
+ injectSilence(count) {
560
+ return this.native.injectSilence(count);
561
+ }
562
+ /**
563
+ * Get the underlying native SoftwareResampleContext object.
564
+ *
565
+ * @returns The native SoftwareResampleContext binding object
566
+ *
567
+ * @internal
568
+ */
569
+ getNative() {
570
+ return this.native;
571
+ }
572
+ /**
573
+ * Dispose of the resampler context.
574
+ *
575
+ * Implements the Disposable interface for automatic cleanup.
576
+ * Equivalent to calling free().
577
+ *
578
+ * @example
579
+ * ```typescript
580
+ * {
581
+ * using resampler = new SoftwareResampleContext();
582
+ * resampler.allocSetOpts2(...);
583
+ * resampler.init();
584
+ * // Use resampler...
585
+ * } // Automatically freed when leaving scope
586
+ * ```
587
+ */
588
+ [Symbol.dispose]() {
589
+ this.native[Symbol.dispose]();
590
+ }
591
+ }
592
+ //# sourceMappingURL=software-resample-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"software-resample-context.js","sourceRoot":"","sources":["../../src/lib/software-resample-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,OAAO,uBAAwB,SAAQ,YAA2C;IACtF;QACE,KAAK,CAAC,IAAI,QAAQ,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACH,aAAa,CACX,WAA0B,EAC1B,YAA4B,EAC5B,aAAqB,EACrB,UAAyB,EACzB,WAA2B,EAC3B,YAAoB;QAEpB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IACpH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,KAAK,CAAC,OAAO,CAAC,SAA0B,EAAE,QAAgB,EAAE,QAAyB,EAAE,OAAe;QACpG,OAAO,MAAM,IAAI,CAAC,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