node-av 6.1.1 → 6.2.0-beta.10

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 (94) hide show
  1. package/README.md +29 -0
  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 +12 -5
  10. package/dist/api/decoder.js.map +1 -1
  11. package/dist/api/demuxer.d.ts +10 -1
  12. package/dist/api/demuxer.js +114 -31
  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 +113 -9
  16. package/dist/api/encoder-pool.js.map +1 -1
  17. package/dist/api/encoder.d.ts +2 -0
  18. package/dist/api/encoder.js +105 -41
  19. package/dist/api/encoder.js.map +1 -1
  20. package/dist/api/filter-complex.d.ts +16 -10
  21. package/dist/api/filter-complex.js +129 -81
  22. package/dist/api/filter-complex.js.map +1 -1
  23. package/dist/api/filter-presets.d.ts +15 -1
  24. package/dist/api/filter-presets.js +23 -5
  25. package/dist/api/filter-presets.js.map +1 -1
  26. package/dist/api/filter.js +15 -6
  27. package/dist/api/filter.js.map +1 -1
  28. package/dist/api/fmp4-stream.d.ts +211 -4
  29. package/dist/api/fmp4-stream.js +550 -84
  30. package/dist/api/fmp4-stream.js.map +1 -1
  31. package/dist/api/hardware.js +4 -3
  32. package/dist/api/hardware.js.map +1 -1
  33. package/dist/api/index.d.ts +1 -0
  34. package/dist/api/index.js.map +1 -1
  35. package/dist/api/io-stream.js +61 -5
  36. package/dist/api/io-stream.js.map +1 -1
  37. package/dist/api/muxer.d.ts +13 -0
  38. package/dist/api/muxer.js +82 -19
  39. package/dist/api/muxer.js.map +1 -1
  40. package/dist/api/pipeline.d.ts +122 -0
  41. package/dist/api/pipeline.js +25 -7
  42. package/dist/api/pipeline.js.map +1 -1
  43. package/dist/api/rtp-stream.d.ts +146 -1
  44. package/dist/api/rtp-stream.js +533 -125
  45. package/dist/api/rtp-stream.js.map +1 -1
  46. package/dist/api/scaler.d.ts +102 -16
  47. package/dist/api/scaler.js +316 -106
  48. package/dist/api/scaler.js.map +1 -1
  49. package/dist/api/types.d.ts +17 -0
  50. package/dist/api/types.js +2 -0
  51. package/dist/api/types.js.map +1 -0
  52. package/dist/api/utilities/async-queue.d.ts +3 -0
  53. package/dist/api/utilities/async-queue.js +8 -0
  54. package/dist/api/utilities/async-queue.js.map +1 -1
  55. package/dist/api/webrtc-stream.d.ts +17 -10
  56. package/dist/api/webrtc-stream.js +117 -24
  57. package/dist/api/webrtc-stream.js.map +1 -1
  58. package/dist/api/whisper.d.ts +2 -0
  59. package/dist/api/whisper.js +63 -23
  60. package/dist/api/whisper.js.map +1 -1
  61. package/dist/ffmpeg/install.js +115 -29
  62. package/dist/ffmpeg/install.js.map +1 -1
  63. package/dist/lib/binding.d.ts +1 -0
  64. package/dist/lib/binding.js.map +1 -1
  65. package/dist/lib/codec-context.d.ts +0 -2
  66. package/dist/lib/codec-context.js +4 -22
  67. package/dist/lib/codec-context.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +0 -1
  69. package/dist/lib/filter-context.js +2 -11
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/format-context.d.ts +45 -4
  72. package/dist/lib/format-context.js +50 -16
  73. package/dist/lib/format-context.js.map +1 -1
  74. package/dist/lib/frame.d.ts +12 -12
  75. package/dist/lib/frame.js +13 -20
  76. package/dist/lib/frame.js.map +1 -1
  77. package/dist/lib/hardware-frames-context.d.ts +0 -1
  78. package/dist/lib/hardware-frames-context.js +2 -8
  79. package/dist/lib/hardware-frames-context.js.map +1 -1
  80. package/dist/lib/native-types.d.ts +2 -2
  81. package/dist/lib/option.d.ts +26 -0
  82. package/dist/lib/option.js +42 -18
  83. package/dist/lib/option.js.map +1 -1
  84. package/dist/lib/packet.d.ts +7 -1
  85. package/dist/lib/packet.js +9 -2
  86. package/dist/lib/packet.js.map +1 -1
  87. package/dist/lib/stream.d.ts +3 -4
  88. package/dist/lib/stream.js +17 -24
  89. package/dist/lib/stream.js.map +1 -1
  90. package/dist/webrtc/index.d.ts +1 -0
  91. package/dist/webrtc/index.js.map +1 -1
  92. package/install/check.js +26 -63
  93. package/package.json +36 -19
  94. package/build_mac_local.sh +0 -69
@@ -3,6 +3,7 @@ import { Demuxer } from './demuxer.js';
3
3
  import type { AVCodecID, AVHWDeviceType, AVSampleFormat, FFAudioEncoder, FFHWDeviceType, FFVideoEncoder } from '../constants/index.js';
4
4
  import type { DemuxerOptions } from './demuxer.js';
5
5
  import type { EncoderOptions } from './encoder.js';
6
+ import type { MediaFrameSource } from './types.js';
6
7
  /**
7
8
  * Options for configuring RTP streaming.
8
9
  */
@@ -66,6 +67,7 @@ export interface RTPStreamOptions {
66
67
  fps?: number;
67
68
  width?: number;
68
69
  height?: number;
70
+ bitrate?: number;
69
71
  encoderOptions?: EncoderOptions['options'];
70
72
  };
71
73
  /**
@@ -88,6 +90,16 @@ export interface RTPStreamOptions {
88
90
  */
89
91
  signal?: AbortSignal;
90
92
  }
93
+ /**
94
+ * Check whether a streaming-class input is a frame source (not a URL or Demuxer).
95
+ *
96
+ * @param input - The input passed to `create()`
97
+ *
98
+ * @returns True if `input` is a {@link MediaFrameSource}
99
+ *
100
+ * @internal
101
+ */
102
+ export declare function isMediaFrameSource(input: string | Demuxer | MediaFrameSource): input is MediaFrameSource;
91
103
  /**
92
104
  * Generic RTP streaming with automatic codec detection and transcoding.
93
105
  *
@@ -125,6 +137,7 @@ export declare class RTPStream {
125
137
  private inputUrl;
126
138
  private inputOptions;
127
139
  private input?;
140
+ private source?;
128
141
  private videoOutput?;
129
142
  private audioOutput?;
130
143
  private hardwareContext?;
@@ -135,9 +148,15 @@ export declare class RTPStream {
135
148
  private audioFilter?;
136
149
  private audioEncoder?;
137
150
  private pipeline?;
151
+ private startPromise?;
138
152
  private signal?;
139
153
  private supportedVideoCodecs;
140
154
  private supportedAudioCodecs;
155
+ private videoKeyframeRequested;
156
+ private abortHandler?;
157
+ private stopRequested;
158
+ private stopPromise?;
159
+ private startAbort?;
141
160
  /**
142
161
  * @param input - Media input URL or pre-opened Demuxer
143
162
  *
@@ -188,7 +207,7 @@ export declare class RTPStream {
188
207
  * });
189
208
  * ```
190
209
  */
191
- static create(input: string | Demuxer, options?: RTPStreamOptions): RTPStream;
210
+ static create(input: string | Demuxer | MediaFrameSource, options?: RTPStreamOptions): RTPStream;
192
211
  /**
193
212
  * Check if the stream is active.
194
213
  *
@@ -214,6 +233,37 @@ export declare class RTPStream {
214
233
  * ```
215
234
  */
216
235
  getInput(): Demuxer | undefined;
236
+ /**
237
+ * Request that the next encoded video frame is a keyframe.
238
+ *
239
+ * Used to answer receiver feedback (e.g. a WebRTC PLI) so a receiver that
240
+ * missed the stream start or lost packets can resync without waiting for the
241
+ * next scheduled GOP keyframe. Currently effective for frame-source inputs
242
+ * ({@link MediaFrameSource}); for demuxer inputs the encoder's regular GOP
243
+ * cadence applies.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * transceiver.sender.onPictureLossIndication.subscribe(() => {
248
+ * stream.requestVideoKeyframe();
249
+ * });
250
+ * ```
251
+ */
252
+ requestVideoKeyframe(): void;
253
+ /**
254
+ * Pass video frames through, forcing a keyframe when one was requested.
255
+ *
256
+ * Sets `pictType = I` on the next frame after {@link requestVideoKeyframe};
257
+ * combined with the encoder's `forced-idr` option this produces an IDR the
258
+ * receiver can resync on.
259
+ *
260
+ * @param src - The user-provided video frame source
261
+ *
262
+ * @yields {Frame | null} The unchanged frames (with pictType forced when requested)
263
+ *
264
+ * @internal
265
+ */
266
+ private wrapVideoSource;
217
267
  /**
218
268
  * Start streaming media to RTP packets.
219
269
  *
@@ -242,6 +292,95 @@ export declare class RTPStream {
242
292
  * ```
243
293
  */
244
294
  start(): Promise<void>;
295
+ /**
296
+ * Perform the actual startup (see {@link start}).
297
+ *
298
+ * @internal
299
+ */
300
+ private doStart;
301
+ /**
302
+ * Abort an in-flight startup once stop() was requested.
303
+ *
304
+ * Checked after every await in the startup path: the resources created so
305
+ * far are all assigned to instance fields, so the stop() that is waiting on
306
+ * this startup tears them down the moment it unwinds.
307
+ *
308
+ * @throws {Error} If stop() was called while starting
309
+ *
310
+ * @internal
311
+ */
312
+ private throwIfStopRequested;
313
+ /**
314
+ * Cap the video bitrate on the encoder context.
315
+ *
316
+ * Sets the target bitrate together with a VBV cap (maxrate + a 1s buffer).
317
+ * Encoder.create() always seeds a default target bitrate (1 Mbps for video),
318
+ * so the target MUST be lowered along with the cap.
319
+ *
320
+ * @param ctx - Encoder codec context
321
+ *
322
+ * @param bitrate - Maximum bitrate in bits per second, or undefined
323
+ *
324
+ * @internal
325
+ */
326
+ private applyBitrate;
327
+ /**
328
+ * Wire the pipeline completion to the onClose/error callbacks.
329
+ *
330
+ * On success invokes `onClose()`; on error stops the stream and invokes
331
+ * `onClose(error)`. Runs in the background (not awaited).
332
+ *
333
+ * @param completion - The pipeline completion promise
334
+ *
335
+ * @internal
336
+ */
337
+ private attachCompletion;
338
+ /**
339
+ * Whether a pipeline rejection was caused by an intentional shutdown.
340
+ *
341
+ * @param error - The pipeline rejection reason
342
+ *
343
+ * @returns True when stop() is in flight or the owner's signal aborted
344
+ *
345
+ * @internal
346
+ */
347
+ private isDeliberateStop;
348
+ /**
349
+ * Set up encoders and RTP outputs for a pre-composited frame source and start
350
+ * encoding. No demuxer or decoder is involved - the provided frames are encoded
351
+ * straight to RTP. Video and audio (whichever are present) run as separate
352
+ * pipelines combined behind a single control.
353
+ *
354
+ * @throws {Error} If the source has neither video nor audio frames
355
+ *
356
+ * @internal
357
+ */
358
+ private startFromFrames;
359
+ /**
360
+ * Create the RTP video output muxer.
361
+ *
362
+ * Rewrites RTP sequence numbers (continuous) and rebases the PTS-derived
363
+ * timestamps (90 kHz) onto a random initial value in the write callback, then
364
+ * forwards each packet to `onVideoPacket`. Uses `this.input` when present
365
+ * (demuxer path) and no input for the frame-source path.
366
+ *
367
+ * @returns The configured video muxer
368
+ *
369
+ * @internal
370
+ */
371
+ private createVideoOutput;
372
+ /**
373
+ * Create the RTP audio output muxer.
374
+ *
375
+ * Rewrites RTP sequence numbers (continuous) in the write callback and forwards
376
+ * each packet to `onAudioPacket`. Uses `this.input` when present (demuxer path)
377
+ * and no input for the frame-source path.
378
+ *
379
+ * @returns The configured audio muxer
380
+ *
381
+ * @internal
382
+ */
383
+ private createAudioOutput;
245
384
  /**
246
385
  * Run the streaming pipeline until completion or stopped.
247
386
  *
@@ -267,6 +406,12 @@ export declare class RTPStream {
267
406
  * ```
268
407
  */
269
408
  stop(): Promise<void>;
409
+ /**
410
+ * Perform the actual teardown (see {@link stop}).
411
+ *
412
+ * @internal
413
+ */
414
+ private doStop;
270
415
  /**
271
416
  * Check if the given audio codec is supported.
272
417
  *