node-av 5.2.0-beta.3 → 5.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.
- package/README.md +120 -66
- package/build_mac_local.sh +69 -0
- package/dist/api/bitstream-filter.d.ts +20 -1
- package/dist/api/bitstream-filter.js +11 -1
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +98 -2
- package/dist/api/decoder.js +17 -2
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/demuxer.d.ts +233 -4
- package/dist/api/demuxer.js +184 -21
- package/dist/api/demuxer.js.map +1 -1
- package/dist/api/device.d.ts +586 -0
- package/dist/api/device.js +961 -0
- package/dist/api/device.js.map +1 -0
- package/dist/api/encoder.d.ts +101 -2
- package/dist/api/encoder.js +17 -2
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-complex.d.ts +54 -2
- package/dist/api/filter-complex.js +1 -1
- package/dist/api/filter-complex.js.map +1 -1
- package/dist/api/filter.d.ts +95 -1
- package/dist/api/filter.js +12 -2
- package/dist/api/filter.js.map +1 -1
- package/dist/api/fmp4-stream.d.ts +5 -4
- package/dist/api/fmp4-stream.js +19 -7
- package/dist/api/fmp4-stream.js.map +1 -1
- package/dist/api/hardware.d.ts +17 -1
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +12 -12
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +188 -6
- package/dist/api/io-stream.js +167 -16
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/muxer.d.ts +184 -26
- package/dist/api/muxer.js +79 -15
- package/dist/api/muxer.js.map +1 -1
- package/dist/api/pipeline.d.ts +75 -21
- package/dist/api/pipeline.js +40 -12
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/rtp-stream.d.ts +15 -4
- package/dist/api/rtp-stream.js +29 -7
- package/dist/api/rtp-stream.js.map +1 -1
- package/dist/api/utilities/index.d.ts +2 -2
- package/dist/api/utilities/index.js +2 -2
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/webrtc-stream.d.ts +9 -9
- package/dist/api/webrtc-stream.js +26 -12
- package/dist/api/webrtc-stream.js.map +1 -1
- package/dist/constants/channel-layouts.d.ts +2 -0
- package/dist/constants/channel-layouts.js +22 -20
- package/dist/constants/channel-layouts.js.map +1 -1
- package/dist/constants/constants.d.ts +10 -5
- package/dist/constants/constants.js +13 -8
- package/dist/constants/constants.js.map +1 -1
- package/dist/constants/decoders.d.ts +1 -0
- package/dist/constants/decoders.js +2 -1
- package/dist/constants/decoders.js.map +1 -1
- package/dist/constants/encoders.d.ts +4 -2
- package/dist/constants/encoders.js +6 -4
- package/dist/constants/encoders.js.map +1 -1
- package/dist/lib/binding.d.ts +2 -1
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec.d.ts +10 -1
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/device.d.ts +291 -0
- package/dist/lib/device.js +324 -0
- package/dist/lib/device.js.map +1 -0
- package/dist/lib/filter.d.ts +8 -1
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +17 -2
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame-utils.d.ts +34 -1
- package/dist/lib/frame-utils.js.map +1 -1
- package/dist/lib/frame.d.ts +23 -1
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/index.d.ts +7 -6
- package/dist/lib/index.js +3 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/io-context.d.ts +16 -1
- package/dist/lib/io-context.js +17 -0
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +6 -1
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +62 -11
- package/dist/lib/native-types.js +0 -9
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/types.d.ts +2 -118
- package/dist/lib/types.js +0 -6
- package/dist/lib/types.js.map +1 -1
- package/package.json +14 -14
- package/BENCHMARK.md +0 -113
- package/dist/api/types.d.ts +0 -829
- package/dist/api/types.js +0 -2
- package/dist/api/types.js.map +0 -1
package/dist/api/io-stream.d.ts
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
1
2
|
import { IOContext } from '../lib/index.js';
|
|
2
|
-
import type {
|
|
3
|
+
import type { Writable } from 'node:stream';
|
|
4
|
+
import type { AVSeekWhence } from '../constants/index.js';
|
|
5
|
+
import type { DemuxerOptions } from './demuxer.js';
|
|
6
|
+
import type { MuxerOptions } from './muxer.js';
|
|
7
|
+
/**
|
|
8
|
+
* Custom I/O callbacks for implementing custom input sources.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export interface IOInputCallbacks {
|
|
12
|
+
/**
|
|
13
|
+
* Read callback - called when FFmpeg needs to read data.
|
|
14
|
+
*
|
|
15
|
+
* Can be synchronous or async (return a Promise).
|
|
16
|
+
*
|
|
17
|
+
* @param size - Number of bytes to read
|
|
18
|
+
*
|
|
19
|
+
* @returns Buffer with data, null for EOF, negative error code, or Promise resolving to same
|
|
20
|
+
*/
|
|
21
|
+
read: (size: number) => Buffer | null | number | Promise<Buffer | null | number>;
|
|
22
|
+
/**
|
|
23
|
+
* Seek callback - called when FFmpeg needs to seek in the stream.
|
|
24
|
+
*
|
|
25
|
+
* Can be synchronous or async (return a Promise).
|
|
26
|
+
*
|
|
27
|
+
* @param offset - Offset to seek to
|
|
28
|
+
*
|
|
29
|
+
* @param whence - Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, or AVSEEK_SIZE)
|
|
30
|
+
*
|
|
31
|
+
* @returns New position, negative error code, or Promise resolving to same
|
|
32
|
+
*/
|
|
33
|
+
seek?: (offset: bigint, whence: AVSeekWhence) => bigint | number | Promise<bigint | number>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Custom I/O callbacks for implementing custom output targets.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
export interface IOOutputCallbacks {
|
|
40
|
+
/**
|
|
41
|
+
* Write callback - called when FFmpeg needs to write data.
|
|
42
|
+
*
|
|
43
|
+
* Can be synchronous or async (return a Promise).
|
|
44
|
+
* The buffer may be reused by FFmpeg after the callback completes,
|
|
45
|
+
* so copy it if you need to keep the data.
|
|
46
|
+
*
|
|
47
|
+
* @param buffer - Buffer containing data to write
|
|
48
|
+
*
|
|
49
|
+
* @returns Number of bytes written, void (assumes all bytes written), or Promise resolving to same
|
|
50
|
+
*/
|
|
51
|
+
write: (buffer: Buffer) => number | void | Promise<number | void>;
|
|
52
|
+
/**
|
|
53
|
+
* Seek callback - called when FFmpeg needs to seek in the output.
|
|
54
|
+
*
|
|
55
|
+
* Can be synchronous or async (return a Promise).
|
|
56
|
+
*
|
|
57
|
+
* @param offset - Offset to seek to
|
|
58
|
+
*
|
|
59
|
+
* @param whence - Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)
|
|
60
|
+
*
|
|
61
|
+
* @returns New position, negative error code, or Promise resolving to same
|
|
62
|
+
*/
|
|
63
|
+
seek?: (offset: bigint, whence: AVSeekWhence) => bigint | number | Promise<bigint | number>;
|
|
64
|
+
/**
|
|
65
|
+
* Read callback - some formats may need to read back data.
|
|
66
|
+
*
|
|
67
|
+
* Can be synchronous or async (return a Promise).
|
|
68
|
+
*
|
|
69
|
+
* @param size - Number of bytes to read
|
|
70
|
+
*
|
|
71
|
+
* @returns Buffer with data, null for EOF, negative error code, or Promise resolving to same
|
|
72
|
+
*/
|
|
73
|
+
read?: (size: number) => Buffer | null | number | Promise<Buffer | null | number>;
|
|
74
|
+
}
|
|
3
75
|
/**
|
|
4
76
|
* Factory for creating custom I/O contexts.
|
|
5
77
|
*
|
|
@@ -90,6 +162,71 @@ export declare class IOStream {
|
|
|
90
162
|
* ```
|
|
91
163
|
*/
|
|
92
164
|
static create(callbacks: IOInputCallbacks, options?: DemuxerOptions): IOContext;
|
|
165
|
+
/**
|
|
166
|
+
* Create I/O context from a Node.js Readable stream.
|
|
167
|
+
*
|
|
168
|
+
* Creates an I/O context that reads from a Readable stream.
|
|
169
|
+
* Seeking is not supported for streams.
|
|
170
|
+
*
|
|
171
|
+
* @param stream - Node.js Readable stream
|
|
172
|
+
*
|
|
173
|
+
* @param options - I/O configuration options
|
|
174
|
+
*
|
|
175
|
+
* @returns Configured I/O context
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const readable = fs.createReadStream('video.mkv');
|
|
180
|
+
* const ioContext = IOStream.create(readable, { format: 'matroska' });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
static create(stream: Readable, options?: DemuxerOptions): IOContext;
|
|
184
|
+
/**
|
|
185
|
+
* Create I/O context for writing to a Node.js Writable stream.
|
|
186
|
+
*
|
|
187
|
+
* Creates a write-mode I/O context from a Writable stream with
|
|
188
|
+
* backpressure support and automatic buffer copying.
|
|
189
|
+
* Seeking is not supported for streams.
|
|
190
|
+
*
|
|
191
|
+
* @param stream - Node.js Writable stream
|
|
192
|
+
*
|
|
193
|
+
* @param options - Output configuration options
|
|
194
|
+
*
|
|
195
|
+
* @returns Configured I/O context
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const writable = fs.createWriteStream('output.mkv');
|
|
200
|
+
* const ioContext = IOStream.createOutput(writable, { format: 'matroska' });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
static createOutput(stream: Writable, options?: MuxerOptions): IOContext;
|
|
204
|
+
/**
|
|
205
|
+
* Create I/O context from custom output callbacks.
|
|
206
|
+
*
|
|
207
|
+
* Creates a write-mode I/O context using custom write, optional seek,
|
|
208
|
+
* and optional read callbacks.
|
|
209
|
+
*
|
|
210
|
+
* @param callbacks - I/O callbacks for write, seek, and read operations
|
|
211
|
+
*
|
|
212
|
+
* @param options - Output configuration options
|
|
213
|
+
*
|
|
214
|
+
* @returns Configured I/O context
|
|
215
|
+
*
|
|
216
|
+
* @throws {Error} If callbacks missing required write function
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const chunks: Buffer[] = [];
|
|
221
|
+
* const ioContext = IOStream.createOutput({
|
|
222
|
+
* write: (buffer) => {
|
|
223
|
+
* chunks.push(Buffer.from(buffer));
|
|
224
|
+
* return buffer.length;
|
|
225
|
+
* }
|
|
226
|
+
* }, { format: 'matroska' });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
static createOutput(callbacks: IOOutputCallbacks, options?: MuxerOptions): IOContext;
|
|
93
230
|
/**
|
|
94
231
|
* Create I/O context from buffer.
|
|
95
232
|
*
|
|
@@ -106,10 +243,41 @@ export declare class IOStream {
|
|
|
106
243
|
*/
|
|
107
244
|
private static createFromBuffer;
|
|
108
245
|
/**
|
|
109
|
-
* Create I/O context from
|
|
246
|
+
* Create I/O context from a Node.js Readable stream.
|
|
247
|
+
*
|
|
248
|
+
* Sets up async read callbacks that buffer data from the stream.
|
|
249
|
+
* Seeking is not supported for streams.
|
|
250
|
+
*
|
|
251
|
+
* @param stream - Node.js Readable stream
|
|
252
|
+
*
|
|
253
|
+
* @param bufferSize - Internal buffer size
|
|
254
|
+
*
|
|
255
|
+
* @returns Configured I/O context
|
|
110
256
|
*
|
|
111
|
-
*
|
|
112
|
-
|
|
257
|
+
* @internal
|
|
258
|
+
*/
|
|
259
|
+
private static createFromReadable;
|
|
260
|
+
/**
|
|
261
|
+
* Create I/O context for writing to a Node.js Writable stream.
|
|
262
|
+
*
|
|
263
|
+
* Sets up async write callbacks with backpressure support.
|
|
264
|
+
* The buffer is copied before writing since FFmpeg reuses its internal buffer.
|
|
265
|
+
*
|
|
266
|
+
* @param stream - Node.js Writable stream
|
|
267
|
+
*
|
|
268
|
+
* @param bufferSize - Internal buffer size
|
|
269
|
+
*
|
|
270
|
+
* @param maxPacketSize - Maximum packet size
|
|
271
|
+
*
|
|
272
|
+
* @returns Configured I/O context
|
|
273
|
+
*
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
private static createForWritable;
|
|
277
|
+
/**
|
|
278
|
+
* Create I/O context from custom input callbacks.
|
|
279
|
+
*
|
|
280
|
+
* Sets up custom I/O with user-provided read and optional seek callbacks.
|
|
113
281
|
*
|
|
114
282
|
* @param callbacks - User I/O callbacks
|
|
115
283
|
*
|
|
@@ -117,9 +285,23 @@ export declare class IOStream {
|
|
|
117
285
|
*
|
|
118
286
|
* @returns Configured I/O context
|
|
119
287
|
*
|
|
120
|
-
* @
|
|
288
|
+
* @internal
|
|
289
|
+
*/
|
|
290
|
+
private static createFromInputCallbacks;
|
|
291
|
+
/**
|
|
292
|
+
* Create I/O context from custom output callbacks.
|
|
293
|
+
*
|
|
294
|
+
* Sets up custom I/O with user-provided write, optional seek, and optional read callbacks.
|
|
295
|
+
*
|
|
296
|
+
* @param callbacks - User I/O callbacks
|
|
297
|
+
*
|
|
298
|
+
* @param bufferSize - Internal buffer size
|
|
299
|
+
*
|
|
300
|
+
* @param maxPacketSize - Maximum packet size
|
|
301
|
+
*
|
|
302
|
+
* @returns Configured I/O context
|
|
121
303
|
*
|
|
122
304
|
* @internal
|
|
123
305
|
*/
|
|
124
|
-
private static
|
|
306
|
+
private static createFromOutputCallbacks;
|
|
125
307
|
}
|
package/dist/api/io-stream.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
1
3
|
import { AVSEEK_CUR, AVSEEK_END, AVSEEK_SET, AVSEEK_SIZE } from '../constants/constants.js';
|
|
2
4
|
import { IOContext } from '../lib/index.js';
|
|
3
|
-
import { IO_BUFFER_SIZE } from './constants.js';
|
|
5
|
+
import { IO_BUFFER_SIZE, MAX_PACKET_SIZE } from './constants.js';
|
|
4
6
|
/**
|
|
5
7
|
* Factory for creating custom I/O contexts.
|
|
6
8
|
*
|
|
@@ -49,11 +51,27 @@ export class IOStream {
|
|
|
49
51
|
if (Buffer.isBuffer(input)) {
|
|
50
52
|
return this.createFromBuffer(input, bufferSize);
|
|
51
53
|
}
|
|
54
|
+
// Handle Readable stream (must be before callbacks check since Readable has 'read')
|
|
55
|
+
if (input instanceof Readable) {
|
|
56
|
+
return this.createFromReadable(input, bufferSize);
|
|
57
|
+
}
|
|
52
58
|
// Handle custom callbacks
|
|
53
59
|
if (typeof input === 'object' && 'read' in input) {
|
|
54
|
-
return this.
|
|
60
|
+
return this.createFromInputCallbacks(input, bufferSize);
|
|
55
61
|
}
|
|
56
|
-
throw new TypeError('Invalid input type. Expected Buffer or IOInputCallbacks');
|
|
62
|
+
throw new TypeError('Invalid input type. Expected Buffer, Readable, or IOInputCallbacks');
|
|
63
|
+
}
|
|
64
|
+
static createOutput(output, options) {
|
|
65
|
+
const { bufferSize = IO_BUFFER_SIZE, maxPacketSize = MAX_PACKET_SIZE } = options ?? {};
|
|
66
|
+
// Handle Writable stream (must be before callbacks check since Writable has 'write')
|
|
67
|
+
if (typeof output === 'object' && 'writable' in output) {
|
|
68
|
+
return this.createForWritable(output, bufferSize, maxPacketSize);
|
|
69
|
+
}
|
|
70
|
+
// Handle custom callbacks
|
|
71
|
+
if (typeof output === 'object' && 'write' in output) {
|
|
72
|
+
return this.createFromOutputCallbacks(output, bufferSize, maxPacketSize);
|
|
73
|
+
}
|
|
74
|
+
throw new TypeError('Invalid output type. Expected Writable or IOOutputCallbacks');
|
|
57
75
|
}
|
|
58
76
|
/**
|
|
59
77
|
* Create I/O context from buffer.
|
|
@@ -100,10 +118,129 @@ export class IOStream {
|
|
|
100
118
|
return ioContext;
|
|
101
119
|
}
|
|
102
120
|
/**
|
|
103
|
-
* Create I/O context from
|
|
121
|
+
* Create I/O context from a Node.js Readable stream.
|
|
122
|
+
*
|
|
123
|
+
* Sets up async read callbacks that buffer data from the stream.
|
|
124
|
+
* Seeking is not supported for streams.
|
|
125
|
+
*
|
|
126
|
+
* @param stream - Node.js Readable stream
|
|
127
|
+
*
|
|
128
|
+
* @param bufferSize - Internal buffer size
|
|
129
|
+
*
|
|
130
|
+
* @returns Configured I/O context
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
static createFromReadable(stream, bufferSize) {
|
|
135
|
+
let chunks = [];
|
|
136
|
+
let totalBuffered = 0;
|
|
137
|
+
let streamEnded = false;
|
|
138
|
+
let streamError = null;
|
|
139
|
+
let pendingResolve = null;
|
|
140
|
+
const wakeUp = () => {
|
|
141
|
+
if (pendingResolve) {
|
|
142
|
+
const resolve = pendingResolve;
|
|
143
|
+
pendingResolve = null;
|
|
144
|
+
resolve();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const removeListeners = () => {
|
|
148
|
+
stream.off('readable', onReadable);
|
|
149
|
+
stream.off('end', onEnd);
|
|
150
|
+
stream.off('error', onError);
|
|
151
|
+
stream.off('close', wakeUp);
|
|
152
|
+
};
|
|
153
|
+
const onReadable = () => wakeUp();
|
|
154
|
+
const onEnd = () => {
|
|
155
|
+
streamEnded = true;
|
|
156
|
+
wakeUp();
|
|
157
|
+
};
|
|
158
|
+
const onError = (err) => {
|
|
159
|
+
streamError = err;
|
|
160
|
+
wakeUp();
|
|
161
|
+
};
|
|
162
|
+
// Track state changes and wake up pending reads
|
|
163
|
+
stream.on('readable', onReadable);
|
|
164
|
+
stream.on('end', onEnd);
|
|
165
|
+
stream.on('error', onError);
|
|
166
|
+
stream.on('close', wakeUp);
|
|
167
|
+
const ioContext = new IOContext();
|
|
168
|
+
ioContext.allocContextWithCallbacks(bufferSize, 0, // read mode
|
|
169
|
+
async (size) => {
|
|
170
|
+
// Pull-based: read from stream on demand
|
|
171
|
+
while (totalBuffered < size && !streamEnded && !streamError && !stream.destroyed) {
|
|
172
|
+
// Try to read available data first
|
|
173
|
+
let chunk;
|
|
174
|
+
while ((chunk = stream.read()) !== null) {
|
|
175
|
+
chunks.push(chunk);
|
|
176
|
+
totalBuffered += chunk.length;
|
|
177
|
+
}
|
|
178
|
+
// If we have enough data, stop waiting
|
|
179
|
+
if (totalBuffered >= size)
|
|
180
|
+
break;
|
|
181
|
+
// If stream is done, stop waiting
|
|
182
|
+
if (streamEnded || streamError || stream.destroyed)
|
|
183
|
+
break;
|
|
184
|
+
// Wait for more data
|
|
185
|
+
await new Promise((resolve) => {
|
|
186
|
+
pendingResolve = resolve;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// No data available — EOF, remove listeners
|
|
190
|
+
if (totalBuffered === 0) {
|
|
191
|
+
removeListeners();
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const concat = Buffer.concat(chunks);
|
|
195
|
+
const result = concat.subarray(0, Math.min(size, concat.length));
|
|
196
|
+
const remainder = concat.subarray(result.length);
|
|
197
|
+
chunks = remainder.length > 0 ? [remainder] : [];
|
|
198
|
+
totalBuffered = remainder.length;
|
|
199
|
+
// If stream is done and all data consumed, remove listeners
|
|
200
|
+
if (totalBuffered === 0 && (streamEnded || streamError || stream.destroyed)) {
|
|
201
|
+
removeListeners();
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}, undefined, // no write
|
|
205
|
+
undefined);
|
|
206
|
+
return ioContext;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create I/O context for writing to a Node.js Writable stream.
|
|
210
|
+
*
|
|
211
|
+
* Sets up async write callbacks with backpressure support.
|
|
212
|
+
* The buffer is copied before writing since FFmpeg reuses its internal buffer.
|
|
213
|
+
*
|
|
214
|
+
* @param stream - Node.js Writable stream
|
|
215
|
+
*
|
|
216
|
+
* @param bufferSize - Internal buffer size
|
|
217
|
+
*
|
|
218
|
+
* @param maxPacketSize - Maximum packet size
|
|
219
|
+
*
|
|
220
|
+
* @returns Configured I/O context
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
static createForWritable(stream, bufferSize, maxPacketSize) {
|
|
225
|
+
const ioContext = new IOContext();
|
|
226
|
+
ioContext.allocContextWithCallbacks(bufferSize, 1, // write mode
|
|
227
|
+
undefined, // no read
|
|
228
|
+
async (buffer) => {
|
|
229
|
+
// Copy buffer — FFmpeg reuses the internal buffer after callback returns
|
|
230
|
+
const copy = Buffer.from(buffer);
|
|
231
|
+
if (!stream.write(copy)) {
|
|
232
|
+
// Backpressure: wait for drain
|
|
233
|
+
await once(stream, 'drain');
|
|
234
|
+
}
|
|
235
|
+
return copy.length;
|
|
236
|
+
}, undefined);
|
|
237
|
+
ioContext.maxPacketSize = maxPacketSize;
|
|
238
|
+
return ioContext;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Create I/O context from custom input callbacks.
|
|
104
242
|
*
|
|
105
|
-
* Sets up custom I/O with user-provided callbacks.
|
|
106
|
-
* Supports read and optional seek operations.
|
|
243
|
+
* Sets up custom I/O with user-provided read and optional seek callbacks.
|
|
107
244
|
*
|
|
108
245
|
* @param callbacks - User I/O callbacks
|
|
109
246
|
*
|
|
@@ -111,20 +248,34 @@ export class IOStream {
|
|
|
111
248
|
*
|
|
112
249
|
* @returns Configured I/O context
|
|
113
250
|
*
|
|
114
|
-
* @
|
|
251
|
+
* @internal
|
|
252
|
+
*/
|
|
253
|
+
static createFromInputCallbacks(callbacks, bufferSize) {
|
|
254
|
+
const ioContext = new IOContext();
|
|
255
|
+
ioContext.allocContextWithCallbacks(bufferSize, 0, // read mode
|
|
256
|
+
callbacks.read, undefined, callbacks.seek);
|
|
257
|
+
return ioContext;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create I/O context from custom output callbacks.
|
|
261
|
+
*
|
|
262
|
+
* Sets up custom I/O with user-provided write, optional seek, and optional read callbacks.
|
|
263
|
+
*
|
|
264
|
+
* @param callbacks - User I/O callbacks
|
|
265
|
+
*
|
|
266
|
+
* @param bufferSize - Internal buffer size
|
|
267
|
+
*
|
|
268
|
+
* @param maxPacketSize - Maximum packet size
|
|
269
|
+
*
|
|
270
|
+
* @returns Configured I/O context
|
|
115
271
|
*
|
|
116
272
|
* @internal
|
|
117
273
|
*/
|
|
118
|
-
static
|
|
119
|
-
// We only support read mode in the high-level API
|
|
120
|
-
// Write mode would be needed for custom output, which we don't currently support
|
|
121
|
-
if (!callbacks.read) {
|
|
122
|
-
throw new Error('Read callback is required');
|
|
123
|
-
}
|
|
274
|
+
static createFromOutputCallbacks(callbacks, bufferSize, maxPacketSize) {
|
|
124
275
|
const ioContext = new IOContext();
|
|
125
|
-
ioContext.allocContextWithCallbacks(bufferSize,
|
|
126
|
-
callbacks.read,
|
|
127
|
-
|
|
276
|
+
ioContext.allocContextWithCallbacks(bufferSize, 1, // write mode
|
|
277
|
+
callbacks.read, callbacks.write, callbacks.seek);
|
|
278
|
+
ioContext.maxPacketSize = maxPacketSize;
|
|
128
279
|
return ioContext;
|
|
129
280
|
}
|
|
130
281
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io-stream.js","sourceRoot":"","sources":["../../src/api/io-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"io-stream.js","sourceRoot":"","sources":["../../src/api/io-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAgFjE;;;;;;;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