node-av 6.2.0-beta.2 → 6.2.0-beta.21

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 (93) hide show
  1. package/README.md +13 -8
  2. package/dist/api/audio-frame-buffer.d.ts +73 -1
  3. package/dist/api/audio-frame-buffer.js +127 -1
  4. package/dist/api/audio-frame-buffer.js.map +1 -1
  5. package/dist/api/bitstream-filter.d.ts +82 -4
  6. package/dist/api/bitstream-filter.js +197 -100
  7. package/dist/api/bitstream-filter.js.map +1 -1
  8. package/dist/api/decoder.d.ts +5 -0
  9. package/dist/api/decoder.js +13 -6
  10. package/dist/api/decoder.js.map +1 -1
  11. package/dist/api/demuxer.d.ts +15 -1
  12. package/dist/api/demuxer.js +165 -54
  13. package/dist/api/demuxer.js.map +1 -1
  14. package/dist/api/encoder-pool.d.ts +43 -1
  15. package/dist/api/encoder-pool.js +121 -9
  16. package/dist/api/encoder-pool.js.map +1 -1
  17. package/dist/api/encoder.d.ts +19 -0
  18. package/dist/api/encoder.js +112 -45
  19. package/dist/api/encoder.js.map +1 -1
  20. package/dist/api/filter.js +15 -6
  21. package/dist/api/filter.js.map +1 -1
  22. package/dist/api/fmp4-stream.d.ts +167 -3
  23. package/dist/api/fmp4-stream.js +423 -90
  24. package/dist/api/fmp4-stream.js.map +1 -1
  25. package/dist/api/hardware.d.ts +2 -0
  26. package/dist/api/hardware.js +25 -4
  27. package/dist/api/hardware.js.map +1 -1
  28. package/dist/api/io-stream.d.ts +3 -2
  29. package/dist/api/io-stream.js +61 -5
  30. package/dist/api/io-stream.js.map +1 -1
  31. package/dist/api/muxer.d.ts +14 -0
  32. package/dist/api/muxer.js +131 -51
  33. package/dist/api/muxer.js.map +1 -1
  34. package/dist/api/pipeline.d.ts +24 -0
  35. package/dist/api/pipeline.js +76 -5
  36. package/dist/api/pipeline.js.map +1 -1
  37. package/dist/api/rtp-stream.d.ts +56 -6
  38. package/dist/api/rtp-stream.js +252 -80
  39. package/dist/api/rtp-stream.js.map +1 -1
  40. package/dist/api/scaler.d.ts +105 -17
  41. package/dist/api/scaler.js +326 -108
  42. package/dist/api/scaler.js.map +1 -1
  43. package/dist/api/utilities/async-queue.d.ts +3 -0
  44. package/dist/api/utilities/async-queue.js +8 -0
  45. package/dist/api/utilities/async-queue.js.map +1 -1
  46. package/dist/api/webrtc-stream.d.ts +2 -0
  47. package/dist/api/webrtc-stream.js +46 -12
  48. package/dist/api/webrtc-stream.js.map +1 -1
  49. package/dist/api/whisper.d.ts +2 -0
  50. package/dist/api/whisper.js +63 -23
  51. package/dist/api/whisper.js.map +1 -1
  52. package/dist/constants/constants.d.ts +1 -0
  53. package/dist/constants/constants.js +1 -0
  54. package/dist/constants/constants.js.map +1 -1
  55. package/dist/constants/filter-options.d.ts +2 -0
  56. package/dist/ffmpeg/install.js +115 -29
  57. package/dist/ffmpeg/install.js.map +1 -1
  58. package/dist/ffmpeg/utils.js +7 -4
  59. package/dist/ffmpeg/utils.js.map +1 -1
  60. package/dist/lib/binding.d.ts +1 -0
  61. package/dist/lib/binding.js +12 -16
  62. package/dist/lib/binding.js.map +1 -1
  63. package/dist/lib/codec-context.d.ts +0 -2
  64. package/dist/lib/codec-context.js +4 -22
  65. package/dist/lib/codec-context.js.map +1 -1
  66. package/dist/lib/filter-context.d.ts +0 -1
  67. package/dist/lib/filter-context.js +2 -11
  68. package/dist/lib/filter-context.js.map +1 -1
  69. package/dist/lib/format-context.d.ts +63 -7
  70. package/dist/lib/format-context.js +70 -21
  71. package/dist/lib/format-context.js.map +1 -1
  72. package/dist/lib/frame.d.ts +11 -11
  73. package/dist/lib/frame.js +13 -20
  74. package/dist/lib/frame.js.map +1 -1
  75. package/dist/lib/hardware-frames-context.d.ts +0 -1
  76. package/dist/lib/hardware-frames-context.js +2 -8
  77. package/dist/lib/hardware-frames-context.js.map +1 -1
  78. package/dist/lib/io-context.d.ts +4 -2
  79. package/dist/lib/io-context.js +4 -2
  80. package/dist/lib/io-context.js.map +1 -1
  81. package/dist/lib/native-types.d.ts +4 -4
  82. package/dist/lib/option.d.ts +26 -0
  83. package/dist/lib/option.js +42 -18
  84. package/dist/lib/option.js.map +1 -1
  85. package/dist/lib/packet.d.ts +5 -0
  86. package/dist/lib/packet.js +5 -0
  87. package/dist/lib/packet.js.map +1 -1
  88. package/dist/lib/stream.d.ts +3 -4
  89. package/dist/lib/stream.js +17 -24
  90. package/dist/lib/stream.js.map +1 -1
  91. package/install/check.js +40 -79
  92. package/package.json +43 -32
  93. package/build_mac_local.sh +0 -69
@@ -81,6 +81,10 @@ export interface ScalerOptions {
81
81
  * Software frames are scaled with swscale; hardware frames are cropped, scaled,
82
82
  * and converted on the GPU with only the small result downloaded.
83
83
  *
84
+ * Safe for concurrent use: calls that share a cached graph or pooled encoder are
85
+ * serialized on that resource, while distinct output configurations run fully in
86
+ * parallel, and cache eviction never disposes a resource that is still in flight.
87
+ *
84
88
  * @example
85
89
  * ```typescript
86
90
  * import { Scaler } from 'node-av/api';
@@ -99,13 +103,14 @@ export interface ScalerOptions {
99
103
  */
100
104
  export declare class Scaler implements Disposable {
101
105
  private native;
106
+ private syncNative?;
107
+ private nativeLock;
102
108
  private hardware?;
103
109
  private flags;
104
110
  private maxCacheSize;
105
111
  private graphs;
106
112
  private jpegPool?;
107
113
  private pngPool?;
108
- private downloadFrame?;
109
114
  private disposed;
110
115
  /**
111
116
  * Create a new scaler.
@@ -259,12 +264,13 @@ export declare class Scaler implements Disposable {
259
264
  /**
260
265
  * Download a hardware frame to system memory (no hardware context available).
261
266
  *
262
- * Reuses a single target frame across calls. The frame's own hwframe context
263
- * selects a supported software format.
267
+ * Allocates a fresh target per call - concurrent downloads must not share a
268
+ * staging frame. The frame's own hwframe context selects a supported software
269
+ * format. The caller frees the returned frame.
264
270
  *
265
271
  * @param frame - Hardware source frame
266
272
  *
267
- * @returns Software frame
273
+ * @returns Software frame (caller frees)
268
274
  *
269
275
  * @throws {FFmpegError} If the transfer fails
270
276
  *
@@ -276,7 +282,7 @@ export declare class Scaler implements Disposable {
276
282
  *
277
283
  * @param frame - Hardware source frame
278
284
  *
279
- * @returns Software frame
285
+ * @returns Software frame (caller frees)
280
286
  *
281
287
  * @throws {FFmpegError} If the transfer fails
282
288
  *
@@ -284,13 +290,34 @@ export declare class Scaler implements Disposable {
284
290
  */
285
291
  private downloadToSoftwareSync;
286
292
  /**
287
- * Lazily allocate and reset the reused download target frame.
293
+ * Run the pooled native software scaler, serialized per instance.
294
+ *
295
+ * The native scaler reuses staging frames and sws contexts per configuration;
296
+ * overlapping async calls would race on them in the worker threads.
297
+ *
298
+ * @param frame - Software source frame
299
+ *
300
+ * @param options - Crop, resize, and format options
301
+ *
302
+ * @returns Tightly packed pixel data
303
+ *
304
+ * @throws {FFmpegError} If scaling fails
305
+ *
306
+ * @internal
307
+ */
308
+ private processNative;
309
+ /**
310
+ * The native scaler used by the sync path (lazily created).
311
+ *
312
+ * Sync calls block the event loop but can land while an async call's worker is
313
+ * scaling in the background; a separate native instance keeps them off the async
314
+ * scaler's pooled contexts, which are not safe to share across threads.
288
315
  *
289
- * @returns The cleared download frame
316
+ * @returns The sync-path native scaler
290
317
  *
291
318
  * @internal
292
319
  */
293
- private prepareDownloadTarget;
320
+ private getSyncNative;
294
321
  /**
295
322
  * Scale/crop/convert a frame through a cached filter graph and return the
296
323
  * resulting frame (caller must free it).
@@ -318,6 +345,10 @@ export declare class Scaler implements Disposable {
318
345
  /**
319
346
  * Synchronous version of toFrame.
320
347
  *
348
+ * Sync scales cannot interleave with each other (they block the event loop),
349
+ * but they can land between the awaits of an in-flight async scale; a busy
350
+ * cached graph is bypassed with a throwaway graph in that case.
351
+ *
321
352
  * @param frame - Source frame (software, or hardware with a hardware context)
322
353
  *
323
354
  * @param crop - Crop region, or undefined for the full frame
@@ -332,9 +363,23 @@ export declare class Scaler implements Disposable {
332
363
  */
333
364
  private toFrameSync;
334
365
  /**
335
- * Resolve (and, on demand, build) the cached filter graph for a frame, applying
336
- * the crop reconfiguration. Shared by the sync and async scaling paths; all of
337
- * this work (parse, config, sendCommand) is synchronous.
366
+ * Scale through a throwaway graph with the crop baked in, bypassing the cache.
367
+ *
368
+ * @param frame - Source frame
369
+ *
370
+ * @param acq - Resolved operation configuration
371
+ *
372
+ * @returns The scaled output frame (caller frees)
373
+ *
374
+ * @throws {Error} If the graph produces no frame
375
+ *
376
+ * @internal
377
+ */
378
+ private scaleOneShotSync;
379
+ /**
380
+ * Resolve (and, on demand, build) the cached filter graph for a frame. Shared
381
+ * by the sync and async scaling paths; all of this work is synchronous, so a
382
+ * resolved entry cannot be evicted before the caller marks it in use.
338
383
  *
339
384
  * @param frame - Source frame (software, or hardware with a hardware context)
340
385
  *
@@ -344,7 +389,7 @@ export declare class Scaler implements Disposable {
344
389
  *
345
390
  * @param format - Output pixel format
346
391
  *
347
- * @returns The cached graph entry (ready to process the frame) and its cache key
392
+ * @returns The cached graph entry and the resolved operation configuration
348
393
  *
349
394
  * @throws {Error} If the crop is out of bounds
350
395
  *
@@ -352,16 +397,57 @@ export declare class Scaler implements Disposable {
352
397
  */
353
398
  private resolveGraph;
354
399
  /**
355
- * Dispose a cached graph and remove it from the cache.
400
+ * Bring a cached graph in line with the current call. Must run under the entry
401
+ * lock (async path) or with no async call in flight (sync path).
402
+ *
403
+ * Rebuilds the graph when the source parameters changed: FilterAPI would
404
+ * otherwise reinitialize itself from the original graph description, silently
405
+ * resurrecting the crop baked in at build time instead of the current one. A
406
+ * graph that has not seen a frame yet is likewise rebuilt when the crop
407
+ * differs, because commands cannot be sent before initialization. Otherwise a
408
+ * changed crop is re-aimed with runtime commands - identical crops reuse the
409
+ * graph untouched (no config_input/config_output re-run).
356
410
  *
357
- * Used after a graph has been flushed (and is therefore at EOF and can no
358
- * longer accept frames) so the next operation rebuilds it.
411
+ * @param acq - Resolved graph and operation configuration
359
412
  *
360
- * @param key - Cache key of the graph to evict
413
+ * @param frame - Frame about to be processed
414
+ *
415
+ * @internal
416
+ */
417
+ private prepareGraph;
418
+ /**
419
+ * Remove a graph from the cache and retire it.
420
+ *
421
+ * Identity-checked so a newer graph cached under the same key is left alone.
422
+ * Used after a flush (the graph is at EOF and can no longer accept frames) and
423
+ * after mid-stream failures, so the next operation rebuilds it.
424
+ *
425
+ * @param key - Cache key of the graph
426
+ *
427
+ * @param entry - The exact entry to evict
361
428
  *
362
429
  * @internal
363
430
  */
364
431
  private evictGraph;
432
+ /**
433
+ * Take a graph out of service, disposing it now or on last release.
434
+ *
435
+ * An entry with in-flight scales is only marked; the final {@link releaseGraph}
436
+ * disposes the filter once nothing uses it anymore.
437
+ *
438
+ * @param entry - Entry removed from the cache
439
+ *
440
+ * @internal
441
+ */
442
+ private retireEntry;
443
+ /**
444
+ * Drop an in-flight reference, disposing the graph if it was retired meanwhile.
445
+ *
446
+ * @param entry - Entry acquired by {@link toFrame}
447
+ *
448
+ * @internal
449
+ */
450
+ private releaseGraph;
365
451
  /**
366
452
  * Tag a frame for MJPEG encoding: full color range and a per-frame quality.
367
453
  *
@@ -397,7 +483,9 @@ export declare class Scaler implements Disposable {
397
483
  * For software frames this is `crop,scale,format`. For hardware frames the crop
398
484
  * filter sets crop metadata that the hardware scaler (scale_vt/scale_cuda/
399
485
  * scale_vaapi) applies on the GPU; the result is kept in NV12, downloaded, and
400
- * converted on the CPU. When `commandable` the crop is a labeled instance
486
+ * converted on the CPU. Scalers with a same-size/same-format passthrough mode
487
+ * (scale_vaapi/scale_cuda/vpp_qsv) get `passthrough=0`, since skipping the scaler
488
+ * would drop the crop metadata unapplied. When `commandable` the crop is a labeled instance
401
489
  * (`crop@sc`) whose initial region is `crop` but which is re-aimed per frame via
402
490
  * `sendCommand`. Otherwise (OpenCL) the crop is fixed in the graph.
403
491
  *