node-av 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  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 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  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 +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -4,129 +4,74 @@ import { CodecParameters } from './codec-parameters.js';
4
4
  import { OptionMember } from './option.js';
5
5
  import { Rational } from './rational.js';
6
6
  /**
7
- * Bitstream filter context for processing packets.
7
+ * Bitstream filter context for processing compressed video/audio streams.
8
8
  *
9
- * Manages the state for bitstream filtering operations.
10
- * Processes packets through a bitstream filter without decoding.
11
- * Supports packet-by-packet filtering with internal buffering.
9
+ * Applies bitstream filters to modify or analyze compressed packets without
10
+ * full decoding/encoding. Common uses include format conversion (e.g., H.264 MP4 to Annex B),
11
+ * metadata extraction, parameter set manipulation, and packet splitting/merging.
12
+ * Essential for stream compatibility between different containers and decoders.
12
13
  *
13
14
  * Direct mapping to FFmpeg's AVBSFContext.
14
15
  *
15
16
  * @example
16
17
  * ```typescript
17
- * import { BitStreamFilter, BitStreamFilterContext, Packet, FFmpegError } from 'node-av';
18
- * import { AVERROR_EOF, AVERROR } from 'node-av/constants';
18
+ * import { BitStreamFilterContext, BitStreamFilter, Packet, FFmpegError } from 'node-av';
19
19
  *
20
- * // Create and initialize filter context
21
- * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
20
+ * // Create and initialize H.264 stream format converter
22
21
  * const ctx = new BitStreamFilterContext();
22
+ * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
23
+ * if (!filter) {
24
+ * throw new Error('H.264 filter not available');
25
+ * }
23
26
  *
24
- * // Allocate and configure
25
27
  * let ret = ctx.alloc(filter);
26
28
  * FFmpegError.throwIfError(ret, 'alloc');
27
29
  *
28
- * // Copy input parameters from stream to BSF context
29
- * stream.codecpar.copy(ctx.inputCodecParameters);
30
- * ctx.inputTimeBase = stream.timeBase;
31
- *
32
- * // Initialize filter
33
30
  * ret = ctx.init();
34
31
  * FFmpegError.throwIfError(ret, 'init');
35
32
  *
36
33
  * // Process packets
37
- * while (hasMorePackets) {
38
- * const inputPacket = getNextPacket();
39
- *
40
- * // Send packet to filter
41
- * ret = await ctx.sendPacket(inputPacket);
42
- * FFmpegError.throwIfError(ret, 'sendPacket');
43
- *
44
- * // Receive filtered packets
45
- * while (true) {
46
- * const outputPacket = new Packet();
47
- * const result = await ctx.receivePacket(outputPacket);
48
- *
49
- * if (result.eagain || result.eof) break;
50
- * FFmpegError.throwIfError(result.ret || result, 'receivePacket');
51
- *
52
- * // Process filtered packet
53
- * processPacket(outputPacket);
54
- * outputPacket.unref();
55
- * }
56
- * }
34
+ * const inputPacket = new Packet();
35
+ * const outputPacket = new Packet();
57
36
  *
58
- * // Send EOF
59
- * await ctx.sendPacket(null);
37
+ * ret = await ctx.sendPacket(inputPacket);
38
+ * FFmpegError.throwIfError(ret, 'sendPacket');
60
39
  *
61
- * // Drain remaining packets
62
- * while (true) {
63
- * const outputPacket = new Packet();
64
- * const result = await ctx.receivePacket(outputPacket);
65
- * if (result.eof) break;
66
- * // Process remaining packets
40
+ * ret = await ctx.receivePacket(outputPacket);
41
+ * if (ret >= 0) {
42
+ * // Process filtered packet
67
43
  * }
68
44
  *
69
45
  * // Cleanup
70
46
  * ctx.free();
71
47
  * ```
48
+ *
49
+ * @see {@link BitStreamFilter} For available filter types
50
+ * @see {@link Packet} For packet manipulation
72
51
  */
73
52
  export class BitStreamFilterContext extends OptionMember {
74
53
  _filter; // Cache for filter wrapper
75
- /**
76
- * Create a new bitstream filter context.
77
- *
78
- * The context is uninitialized - you must call alloc() and init() before use.
79
- * No FFmpeg resources are allocated until initialization.
80
- *
81
- * Direct wrapper around AVBSFContext.
82
- *
83
- * @example
84
- * ```typescript
85
- * const ctx = new BitStreamFilterContext();
86
- * ctx.alloc(filter);
87
- * ctx.init();
88
- * // Context is now ready for filtering
89
- * ```
90
- */
91
54
  constructor() {
92
55
  super(new bindings.BitStreamFilterContext());
93
56
  }
94
57
  /**
95
- * Check if the context is initialized.
58
+ * Check if the context has been initialized.
96
59
  *
97
- * Returns true if init() has been called successfully.
98
- *
99
- * @returns True if initialized, false otherwise
60
+ * Returns true if init() has been successfully called.
61
+ * The context must be initialized before sending/receiving packets.
100
62
  */
101
63
  get isInitialized() {
102
64
  return this.native.isInitialized();
103
65
  }
104
66
  /**
105
- * Input codec parameters (read-only reference, mutable contents).
106
- *
107
- * Returns a reference to the BSF context's internal codec parameters.
108
- * While you cannot replace this object (no setter), you can modify its contents
109
- * or use it as a destination for copy operations.
67
+ * Input codec parameters.
110
68
  *
111
- * You must configure these parameters before calling init().
112
- *
113
- * Maps to AVBSFContext->par_in.
114
- *
115
- * @example
116
- * ```typescript
117
- * // Copy parameters from input stream to BSF context
118
- * if (ctx.inputCodecParameters) {
119
- * stream.codecpar.copy(ctx.inputCodecParameters);
69
+ * Parameters describing the input stream format.
70
+ * These are automatically configured from the input packets in most cases.
120
71
  *
121
- * // Or set individual properties
122
- * ctx.inputCodecParameters.codecType = AVMEDIA_TYPE_VIDEO;
123
- * ctx.inputCodecParameters.codecId = AV_CODEC_ID_H264;
124
- * }
125
- * ```
72
+ * Direct mapping to AVBSFContext->par_in.
126
73
  */
127
74
  get inputCodecParameters() {
128
- // The native binding returns a CodecParameters object created with the constructor
129
- // It's the native object itself, not a TypeScript wrapper
130
75
  const nativeParams = this.native.inputCodecParameters;
131
76
  if (!nativeParams) {
132
77
  return null;
@@ -137,28 +82,14 @@ export class BitStreamFilterContext extends OptionMember {
137
82
  return wrapper;
138
83
  }
139
84
  /**
140
- * Output codec parameters (read-only reference, read-only contents).
141
- *
142
- * Returns a reference to the BSF context's output codec parameters.
143
- * These are automatically configured by the filter during init().
144
- * You should not modify these parameters.
145
- *
146
- * Maps to AVBSFContext->par_out.
85
+ * Output codec parameters.
147
86
  *
148
- * @example
149
- * ```typescript
150
- * // After initialization, read the output parameters
151
- * console.log(`Output codec: ${ctx.outputCodecParameters?.codecId}`);
87
+ * Parameters describing the output stream format after filtering.
88
+ * These reflect any changes made by the bitstream filter.
152
89
  *
153
- * // Use them to configure downstream components
154
- * if (ctx.outputCodecParameters) {
155
- * ctx.outputCodecParameters.copy(nextStream.codecpar);
156
- * }
157
- * ```
90
+ * Direct mapping to AVBSFContext->par_out.
158
91
  */
159
92
  get outputCodecParameters() {
160
- // The native binding returns a CodecParameters object created with the constructor
161
- // It's the native object itself, not a TypeScript wrapper
162
93
  const nativeParams = this.native.outputCodecParameters;
163
94
  if (!nativeParams) {
164
95
  return null;
@@ -171,15 +102,10 @@ export class BitStreamFilterContext extends OptionMember {
171
102
  /**
172
103
  * Input time base.
173
104
  *
174
- * Time base for input packet timestamps.
175
- * Must be set before calling init().
105
+ * Time base of the input packets (timestamps per second).
106
+ * Must be set before init() for proper timestamp handling.
176
107
  *
177
- * Maps to AVBSFContext->time_base_in.
178
- *
179
- * @example
180
- * ```typescript
181
- * ctx.inputTimeBase = new Rational(1, 1000); // 1ms time base
182
- * ```
108
+ * Direct mapping to AVBSFContext->time_base_in.
183
109
  */
184
110
  get inputTimeBase() {
185
111
  const tb = this.native.inputTimeBase;
@@ -191,16 +117,10 @@ export class BitStreamFilterContext extends OptionMember {
191
117
  /**
192
118
  * Output time base.
193
119
  *
194
- * Time base for output packet timestamps.
195
- * Set by the filter during init().
120
+ * Time base of the output packets after filtering.
121
+ * May differ from input if the filter modifies timing.
196
122
  *
197
- * Maps to AVBSFContext->time_base_out.
198
- *
199
- * @example
200
- * ```typescript
201
- * // After initialization
202
- * console.log(`Output time base: ${ctx.outputTimeBase.num}/${ctx.outputTimeBase.den}`);
203
- * ```
123
+ * Direct mapping to AVBSFContext->time_base_out.
204
124
  */
205
125
  get outputTimeBase() {
206
126
  const tb = this.native.outputTimeBase;
@@ -211,14 +131,9 @@ export class BitStreamFilterContext extends OptionMember {
211
131
  /**
212
132
  * The bitstream filter being used.
213
133
  *
214
- * Reference to the filter this context was allocated with.
134
+ * Reference to the filter descriptor allocated to this context.
215
135
  *
216
- * Maps to AVBSFContext->filter.
217
- *
218
- * @example
219
- * ```typescript
220
- * console.log(`Using filter: ${ctx.filter?.name}`);
221
- * ```
136
+ * Direct mapping to AVBSFContext->filter.
222
137
  */
223
138
  get filter() {
224
139
  if (!this._filter) {
@@ -231,24 +146,33 @@ export class BitStreamFilterContext extends OptionMember {
231
146
  return this._filter;
232
147
  }
233
148
  /**
234
- * Allocate the bitstream filter context.
149
+ * Allocate a bitstream filter context.
235
150
  *
236
- * Allocates the context for the specified filter.
237
- * Must be called before any other operations.
238
- * After allocation, configure input parameters before calling init().
151
+ * Allocates and configures the context for the specified filter.
152
+ * Must be called before init().
239
153
  *
240
- * Calls av_bsf_alloc() internally.
154
+ * Direct mapping to av_bsf_alloc().
241
155
  *
242
156
  * @param filter - The bitstream filter to use
243
- * @returns 0 on success, negative error code on failure
157
+ * @returns 0 on success, negative AVERROR on error:
158
+ * - AVERROR_ENOMEM: Memory allocation failure
159
+ * - AVERROR_EINVAL: Invalid filter
244
160
  *
245
161
  * @example
246
162
  * ```typescript
163
+ * import { FFmpegError } from 'node-av';
164
+ *
247
165
  * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
248
- * const ctx = new BitStreamFilterContext();
166
+ * if (!filter) {
167
+ * throw new Error('Filter not found');
168
+ * }
169
+ *
249
170
  * const ret = ctx.alloc(filter);
250
171
  * FFmpegError.throwIfError(ret, 'alloc');
251
172
  * ```
173
+ *
174
+ * @see {@link init} To initialize after allocation
175
+ * @see {@link BitStreamFilter.getByName} To get filter by name
252
176
  */
253
177
  alloc(filter) {
254
178
  return this.native.alloc(filter.getNative());
@@ -256,20 +180,32 @@ export class BitStreamFilterContext extends OptionMember {
256
180
  /**
257
181
  * Initialize the bitstream filter context.
258
182
  *
259
- * Prepares the filter for use after parameters have been set.
260
- * Sets up output parameters based on input and filter configuration.
261
- * Must be called after alloc() and parameter configuration.
183
+ * Initializes the filter with the configured parameters.
184
+ * Must be called after alloc() and before processing packets.
262
185
  *
263
- * Calls av_bsf_init() internally.
186
+ * Direct mapping to av_bsf_init().
264
187
  *
265
- * @returns 0 on success, negative error code on failure
188
+ * @returns 0 on success, negative AVERROR on error:
189
+ * - AVERROR_EINVAL: Invalid parameters
190
+ * - AVERROR_ENOMEM: Memory allocation failure
266
191
  *
267
192
  * @example
268
193
  * ```typescript
269
- * // After allocation and parameter setup
270
- * const ret = ctx.init();
271
- * FFmpegError.throwIfError(ret, 'init');
194
+ * import { FFmpegError } from 'node-av';
195
+ *
196
+ * // Allocate and initialize
197
+ * const ret1 = ctx.alloc(filter);
198
+ * FFmpegError.throwIfError(ret1, 'alloc');
199
+ *
200
+ * // Set parameters if needed
201
+ * ctx.inputTimeBase = new Rational(1, 25);
202
+ *
203
+ * const ret2 = ctx.init();
204
+ * FFmpegError.throwIfError(ret2, 'init');
272
205
  * ```
206
+ *
207
+ * @see {@link alloc} Must be called first
208
+ * @see {@link isInitialized} To check initialization status
273
209
  */
274
210
  init() {
275
211
  return this.native.init();
@@ -278,15 +214,18 @@ export class BitStreamFilterContext extends OptionMember {
278
214
  * Free the bitstream filter context.
279
215
  *
280
216
  * Releases all resources associated with the context.
281
- * The context cannot be used after calling this method.
217
+ * The context becomes invalid after calling this.
282
218
  *
283
- * Calls av_bsf_free() internally.
219
+ * Direct mapping to av_bsf_free().
284
220
  *
285
221
  * @example
286
222
  * ```typescript
287
223
  * ctx.free();
288
- * // Context is now freed and unusable
224
+ * // Context is now invalid
289
225
  * ```
226
+ *
227
+ * @see {@link Symbol.dispose} For automatic cleanup
228
+ * @see {@link alloc} To allocate
290
229
  */
291
230
  free() {
292
231
  this.native.free();
@@ -295,108 +234,120 @@ export class BitStreamFilterContext extends OptionMember {
295
234
  /**
296
235
  * Flush the bitstream filter.
297
236
  *
298
- * Resets the internal filter state.
299
- * Should be called when seeking or switching streams.
237
+ * Resets the internal state and discards any buffered data.
238
+ * Useful when seeking or switching streams.
300
239
  *
301
- * Calls av_bsf_flush() internally.
240
+ * Direct mapping to av_bsf_flush().
302
241
  *
303
242
  * @example
304
243
  * ```typescript
305
- * // When seeking
244
+ * // Flush when seeking
306
245
  * ctx.flush();
307
- * // Filter is reset and ready for new packets
246
+ * // Now ready to process packets from new position
308
247
  * ```
309
248
  */
310
249
  flush() {
311
250
  this.native.flush();
312
251
  }
313
252
  /**
314
- * Send a packet to the filter.
315
- *
316
- * Submits a packet for filtering.
317
- * The filter takes ownership of the packet.
318
- * Pass null to signal end of stream.
253
+ * Send a packet to the bitstream filter.
319
254
  *
320
- * After sending a packet, call receivePacket() repeatedly
321
- * until it returns EAGAIN or EOF.
255
+ * Submits a packet for filtering. The filter may buffer the packet
256
+ * internally and require multiple calls to receivePacket() to retrieve
257
+ * all output. Send null to signal end of stream.
322
258
  *
323
- * Calls av_bsf_send_packet() internally.
259
+ * Direct mapping to av_bsf_send_packet().
324
260
  *
325
- * @param packet - Packet to filter, or null for EOF
326
- * @returns Promise resolving to 0 on success, error code on failure
261
+ * @param packet - Packet to filter, or null to signal EOF
262
+ * @returns 0 on success, negative AVERROR on error:
263
+ * - AVERROR_EAGAIN: Filter needs output to be consumed first
264
+ * - AVERROR_EOF: Filter has been flushed
265
+ * - AVERROR_EINVAL: Invalid parameters
266
+ * - AVERROR_ENOMEM: Memory allocation failure
327
267
  *
328
268
  * @example
329
269
  * ```typescript
330
- * // Send packet
270
+ * import { FFmpegError } from 'node-av';
271
+ * import { AVERROR_EAGAIN } from 'node-av';
272
+ *
331
273
  * const ret = await ctx.sendPacket(inputPacket);
332
- * if (ret < 0 && ret !== AVERROR_EAGAIN) {
333
- * throw new Error('Failed to send packet');
274
+ * if (ret === AVERROR_EAGAIN) {
275
+ * // Need to receive packets first
276
+ * const ret2 = await ctx.receivePacket(outputPacket);
277
+ * FFmpegError.throwIfError(ret2, 'receivePacket');
278
+ * } else {
279
+ * FFmpegError.throwIfError(ret, 'sendPacket');
334
280
  * }
335
281
  *
336
282
  * // Send EOF
337
283
  * await ctx.sendPacket(null);
338
284
  * ```
285
+ *
286
+ * @see {@link receivePacket} To retrieve filtered packets
339
287
  */
340
288
  async sendPacket(packet) {
341
289
  return await this.native.sendPacket(packet ? packet.getNative() : null);
342
290
  }
343
291
  /**
344
- * Receive a filtered packet.
292
+ * Receive a filtered packet from the bitstream filter.
345
293
  *
346
- * Gets a filtered packet from the filter.
347
- * Must be called repeatedly after sendPacket() until EAGAIN or EOF.
348
- * One input packet may produce multiple output packets.
294
+ * Retrieves a packet that has been processed by the filter.
295
+ * May need to be called multiple times after each sendPacket().
349
296
  *
350
- * Calls av_bsf_receive_packet() internally.
297
+ * Direct mapping to av_bsf_receive_packet().
351
298
  *
352
299
  * @param packet - Packet to receive filtered data into
353
- * @returns Promise resolving to 0 on success, negative error code on failure
300
+ * @returns 0 on success, negative AVERROR on error:
301
+ * - AVERROR_EAGAIN: Need more input
302
+ * - AVERROR_EOF: No more packets available
303
+ * - AVERROR_EINVAL: Invalid parameters
354
304
  *
355
305
  * @example
356
306
  * ```typescript
357
- * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
358
- *
359
- * const packet = new Packet();
360
- * const ret = await ctx.receivePacket(packet);
361
- *
362
- * if (ret === AVERROR_EAGAIN) {
363
- * // Need to send more packets
364
- * } else if (ret === AVERROR_EOF) {
365
- * // No more packets
366
- * } else if (ret < 0) {
367
- * // Error occurred
368
- * } else {
369
- * // Got a packet successfully
370
- * processPacket(packet);
307
+ * import { FFmpegError } from 'node-av';
308
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
309
+ *
310
+ * // Receive all available packets
311
+ * while (true) {
312
+ * const ret = await ctx.receivePacket(outputPacket);
313
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
314
+ * break;
315
+ * }
316
+ * FFmpegError.throwIfError(ret, 'receivePacket');
317
+ *
318
+ * // Process filtered packet
319
+ * console.log(`Filtered packet size: ${outputPacket.size}`);
371
320
  * }
372
321
  * ```
322
+ *
323
+ * @see {@link sendPacket} To submit packets for filtering
373
324
  */
374
325
  async receivePacket(packet) {
375
326
  return await this.native.receivePacket(packet.getNative());
376
327
  }
377
328
  /**
378
- * Get the underlying native object.
329
+ * Get the underlying native BitStreamFilterContext object.
379
330
  *
380
- * For advanced use cases that need direct access to the native bindings.
331
+ * @returns The native BitStreamFilterContext binding object
381
332
  *
382
- * @returns Native BitStreamFilterContext object
383
333
  * @internal
384
334
  */
385
335
  getNative() {
386
336
  return this.native;
387
337
  }
388
338
  /**
389
- * Dispose of the context resources.
339
+ * Dispose of the bitstream filter context.
390
340
  *
391
- * Automatically called when using the `using` statement.
392
- * Frees all associated FFmpeg resources.
341
+ * Implements the Disposable interface for automatic cleanup.
342
+ * Equivalent to calling free().
393
343
  *
394
344
  * @example
395
345
  * ```typescript
396
346
  * {
397
347
  * using ctx = new BitStreamFilterContext();
398
348
  * ctx.alloc(filter);
399
- * // ... use context
349
+ * ctx.init();
350
+ * // Use context...
400
351
  * } // Automatically freed when leaving scope
401
352
  * ```
402
353
  */
@@ -1 +1 @@
1
- {"version":3,"file":"bitstream-filter-context.js","sourceRoot":"","sources":["../../src/lib/bitstream-filter-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,YAA0C;IAC5E,OAAO,CAAmB,CAAC,2BAA2B;IAE9D;;;;;;;;;;;;;;;O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