c64-ready 2.1.1 → 2.5.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/bin/admin.mjs +0 -0
- package/bin/headless.mjs +1 -0
- package/dist/assets/index-BAsZcXuS.js +178 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +3 -3
- package/dist-ts/emulator/c64-emulator.d.ts.map +1 -1
- package/dist-ts/emulator/c64-emulator.js +3 -2
- package/dist-ts/emulator/c64-emulator.js.map +1 -1
- package/dist-ts/emulator/c64-wasm.d.ts +5 -5
- package/dist-ts/emulator/c64-wasm.d.ts.map +1 -1
- package/dist-ts/emulator/c64-wasm.js.map +1 -1
- package/dist-ts/emulator/input.d.ts +11 -4
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +41 -11
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/audio-capture.d.ts +1 -1
- package/dist-ts/headless/c64-headless.d.ts +2 -2
- package/dist-ts/headless/c64-headless.js +4 -4
- package/dist-ts/headless/frame-capture.d.ts +1 -1
- package/dist-ts/headless/input-bridge.d.ts +1 -1
- package/dist-ts/player/audio-engine.d.ts.map +1 -1
- package/dist-ts/player/audio-engine.js +4 -0
- package/dist-ts/player/audio-engine.js.map +1 -1
- package/dist-ts/player/c64-player.d.ts +21 -5
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +126 -10
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/canvas-renderer.d.ts +2 -2
- package/dist-ts/player/index.d.ts +7 -7
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +4 -4
- package/dist-ts/player/input-handler.d.ts +14 -4
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +33 -12
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/load-formats.d.ts +1 -1
- package/dist-ts/player/load-formats.js +1 -1
- package/dist-ts/player/load-formats.js.map +1 -1
- package/dist-ts/player/ui-controller.d.ts +1 -1
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +10 -2
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +1 -1
- package/src/emulator/c64-emulator.ts +2 -1
- package/src/emulator/c64-wasm.ts +4 -4
- package/src/emulator/input.ts +50 -16
- package/src/headless/c64-key-map.mjs +357 -165
- package/src/headless/c64-wasm.mjs +2 -2
- package/src/headless/ffmpeg-runner.mjs +214 -75
- package/src/headless/headless-cli.d.ts +1 -1
- package/src/headless/headless-cli.mjs +137 -19
- package/src/headless/headless-cli.mjs.d.ts +1 -1
- package/src/headless/input-server.mjs +511 -67
- package/src/headless/webrtc-encoder.mjs +49 -25
- package/src/headless/webrtc-server.mjs +21 -20
- package/src/main.ts +3 -2
- package/src/player/audio-engine.ts +4 -0
- package/src/player/c64-player.ts +130 -8
- package/src/player/index.ts +8 -1
- package/src/player/input-handler.ts +44 -13
- package/src/player/load-formats.ts +1 -1
- package/src/player/styles/canvas-renderer.css +10 -5
- package/src/player/ui-controller.ts +26 -14
- package/dist/assets/index-Bk-mEPYS.js +0 -169
- package/dist-ts/emulator/memory.d.ts +0 -2
- package/dist-ts/emulator/memory.d.ts.map +0 -1
- package/dist-ts/emulator/memory.js +0 -9
- package/dist-ts/emulator/memory.js.map +0 -1
- package/src/emulator/memory.ts +0 -9
|
@@ -26,50 +26,58 @@ export class FFmpegRunner {
|
|
|
26
26
|
// Strategy B uses a named pipe (FIFO) for audio delivery.
|
|
27
27
|
// Node opens the write end; ffmpeg opens the read end via a file path.
|
|
28
28
|
// This is kernel-synchronised — no net.Server race, no unix socket.
|
|
29
|
-
_audioFifoPath = null;
|
|
30
|
-
_audioFifoFd = null;
|
|
29
|
+
_audioFifoPath = null; // path to the FIFO
|
|
30
|
+
_audioFifoFd = null; // write-end file descriptor (opened after ffmpeg starts)
|
|
31
31
|
_audioFifoStream = null; // WriteStream wrapping the fd
|
|
32
32
|
_liveAudio = false;
|
|
33
33
|
|
|
34
34
|
// ── Process health ────────────────────────────────────────────────────────
|
|
35
35
|
_diedResolve = null;
|
|
36
|
-
died = new Promise((resolve) => {
|
|
36
|
+
died = new Promise((resolve) => {
|
|
37
|
+
this._diedResolve = resolve;
|
|
38
|
+
});
|
|
37
39
|
|
|
38
40
|
async start(options = {}) {
|
|
39
|
-
const width
|
|
40
|
-
const height
|
|
41
|
-
const fps
|
|
42
|
-
const verbose
|
|
43
|
-
const audio
|
|
41
|
+
const width = options.width || 384;
|
|
42
|
+
const height = options.height || 272;
|
|
43
|
+
const fps = options.fps || 60;
|
|
44
|
+
const verbose = !!options.verbose;
|
|
45
|
+
const audio = !!options.audio;
|
|
44
46
|
const sampleRate = options.sampleRate || 44100;
|
|
45
47
|
|
|
46
|
-
this._audio
|
|
48
|
+
this._audio = audio;
|
|
47
49
|
this._sampleRate = sampleRate;
|
|
48
50
|
this._audioChunks = [];
|
|
49
|
-
this._verbose
|
|
50
|
-
this._fps
|
|
51
|
-
this._width
|
|
52
|
-
this._height
|
|
53
|
-
this._liveAudio
|
|
54
|
-
this._exitCode
|
|
55
|
-
this._stderr
|
|
56
|
-
this._audioFifoPath
|
|
57
|
-
this._audioFifoFd
|
|
51
|
+
this._verbose = verbose;
|
|
52
|
+
this._fps = fps;
|
|
53
|
+
this._width = width;
|
|
54
|
+
this._height = height;
|
|
55
|
+
this._liveAudio = false;
|
|
56
|
+
this._exitCode = null;
|
|
57
|
+
this._stderr = '';
|
|
58
|
+
this._audioFifoPath = null;
|
|
59
|
+
this._audioFifoFd = null;
|
|
58
60
|
this._audioFifoStream = null;
|
|
59
61
|
|
|
60
62
|
// Reset died promise for this run
|
|
61
|
-
this.died = new Promise((resolve) => {
|
|
63
|
+
this.died = new Promise((resolve) => {
|
|
64
|
+
this._diedResolve = resolve;
|
|
65
|
+
});
|
|
62
66
|
|
|
63
67
|
const isUrl = typeof options.output === 'string' && /^[a-zA-Z]+:\/\//.test(options.output);
|
|
64
68
|
const outPath = isUrl
|
|
65
69
|
? options.output
|
|
66
|
-
: path.resolve(
|
|
70
|
+
: path.resolve(
|
|
71
|
+
options.output || path.join(process.cwd(), 'temp', `c64-record-${Date.now()}.mp4`),
|
|
72
|
+
);
|
|
67
73
|
|
|
68
74
|
if (!isUrl) {
|
|
69
|
-
try {
|
|
75
|
+
try {
|
|
76
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
77
|
+
} catch (e) {}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
this._isUrl
|
|
80
|
+
this._isUrl = isUrl;
|
|
73
81
|
this._outPath = outPath;
|
|
74
82
|
|
|
75
83
|
// ── Raw mode ─────────────────────────────────────────────────────────────
|
|
@@ -117,22 +125,39 @@ export class FFmpegRunner {
|
|
|
117
125
|
const reachable = await new Promise((resolve) => {
|
|
118
126
|
const s = new net.Socket();
|
|
119
127
|
s.setTimeout(2000);
|
|
120
|
-
s.once('connect', () => {
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
s.once('connect', () => {
|
|
129
|
+
s.destroy();
|
|
130
|
+
resolve(true);
|
|
131
|
+
});
|
|
132
|
+
s.once('error', () => {
|
|
133
|
+
s.destroy();
|
|
134
|
+
resolve(false);
|
|
135
|
+
});
|
|
136
|
+
s.once('timeout', () => {
|
|
137
|
+
s.destroy();
|
|
138
|
+
resolve(false);
|
|
139
|
+
});
|
|
123
140
|
s.connect(port, host);
|
|
124
141
|
});
|
|
125
142
|
if (reachable) {
|
|
126
|
-
if (verbose)
|
|
143
|
+
if (verbose)
|
|
144
|
+
console.error(
|
|
145
|
+
`[ffmpeg-runner] RTMP host ${host}:${port} reachable — waiting 5s for NMS to stabilise`,
|
|
146
|
+
);
|
|
127
147
|
await new Promise((r) => setTimeout(r, 5000));
|
|
128
148
|
break;
|
|
129
149
|
}
|
|
130
|
-
if (verbose)
|
|
150
|
+
if (verbose)
|
|
151
|
+
console.error(
|
|
152
|
+
`[ffmpeg-runner] RTMP host not ready, retrying in ${probeIntervalMs}ms...`,
|
|
153
|
+
);
|
|
131
154
|
await new Promise((r) => setTimeout(r, probeIntervalMs));
|
|
132
155
|
waited += probeIntervalMs;
|
|
133
156
|
}
|
|
134
157
|
if (waited >= maxWaitMs) {
|
|
135
|
-
console.error(
|
|
158
|
+
console.error(
|
|
159
|
+
`[ffmpeg-runner] RTMP host ${host}:${port} unreachable after ${maxWaitMs}ms`,
|
|
160
|
+
);
|
|
136
161
|
}
|
|
137
162
|
}
|
|
138
163
|
}
|
|
@@ -151,23 +176,48 @@ export class FFmpegRunner {
|
|
|
151
176
|
if (isUrl) args.push('-re');
|
|
152
177
|
// Video input: stdin (fd0)
|
|
153
178
|
args.push(
|
|
154
|
-
'-thread_queue_size',
|
|
155
|
-
'
|
|
156
|
-
'-
|
|
157
|
-
'
|
|
179
|
+
'-thread_queue_size',
|
|
180
|
+
'512',
|
|
181
|
+
'-f',
|
|
182
|
+
'rawvideo',
|
|
183
|
+
'-pix_fmt',
|
|
184
|
+
'rgba',
|
|
185
|
+
'-s',
|
|
186
|
+
`${width}x${height}`,
|
|
187
|
+
'-r',
|
|
188
|
+
String(fps),
|
|
189
|
+
'-i',
|
|
190
|
+
'pipe:0',
|
|
158
191
|
);
|
|
159
192
|
// Audio input: fd3 pipe
|
|
160
193
|
args.push(
|
|
161
|
-
'-thread_queue_size',
|
|
162
|
-
'
|
|
163
|
-
'-
|
|
194
|
+
'-thread_queue_size',
|
|
195
|
+
'512',
|
|
196
|
+
'-f',
|
|
197
|
+
'f32le',
|
|
198
|
+
'-ar',
|
|
199
|
+
String(sampleRate),
|
|
200
|
+
'-ac',
|
|
201
|
+
'1',
|
|
202
|
+
'-i',
|
|
203
|
+
'pipe:3',
|
|
164
204
|
);
|
|
165
205
|
// Encoders
|
|
166
206
|
args.push(
|
|
167
|
-
'-pix_fmt',
|
|
168
|
-
'
|
|
169
|
-
'-
|
|
170
|
-
'
|
|
207
|
+
'-pix_fmt',
|
|
208
|
+
'yuv420p',
|
|
209
|
+
'-c:v',
|
|
210
|
+
'libx264',
|
|
211
|
+
'-preset',
|
|
212
|
+
'ultrafast',
|
|
213
|
+
'-tune',
|
|
214
|
+
'zerolatency',
|
|
215
|
+
'-g',
|
|
216
|
+
String(Math.max(1, Math.round(fps))),
|
|
217
|
+
'-c:a',
|
|
218
|
+
'aac',
|
|
219
|
+
'-b:a',
|
|
220
|
+
'128k',
|
|
171
221
|
);
|
|
172
222
|
// Output format + destination
|
|
173
223
|
if (isUrl) {
|
|
@@ -175,7 +225,11 @@ export class FFmpegRunner {
|
|
|
175
225
|
}
|
|
176
226
|
args.push('-y', outPath);
|
|
177
227
|
|
|
178
|
-
if (verbose)
|
|
228
|
+
if (verbose)
|
|
229
|
+
console.error(
|
|
230
|
+
`[ffmpeg-runner] strategy B (pipe audio fd3, ${isUrl ? 'rtmp' : 'file'}):`,
|
|
231
|
+
args.join(' '),
|
|
232
|
+
);
|
|
179
233
|
|
|
180
234
|
// Spawn with 4 stdio streams: [stdin, stdout, stderr, audioWrite]
|
|
181
235
|
this.proc = spawn('ffmpeg', args, { stdio: ['pipe', 'pipe', 'pipe', 'pipe'] });
|
|
@@ -195,24 +249,46 @@ export class FFmpegRunner {
|
|
|
195
249
|
this._audioFifoPath = null;
|
|
196
250
|
this._audioFifoFd = null;
|
|
197
251
|
|
|
198
|
-
this.proc.on('error', (err) => {
|
|
252
|
+
this.proc.on('error', (err) => {
|
|
253
|
+
this._stderr += `\nspawn error: ${String(err)}`;
|
|
254
|
+
try {
|
|
255
|
+
this.stdin = null;
|
|
256
|
+
} catch (e) {}
|
|
257
|
+
});
|
|
199
258
|
this.proc.stdin && this.proc.stdin.on('error', () => {});
|
|
200
259
|
try {
|
|
201
|
-
this.proc.stdout &&
|
|
202
|
-
|
|
260
|
+
this.proc.stdout &&
|
|
261
|
+
this.proc.stdout.on('data', (d) => {
|
|
262
|
+
this._stderr += String(d);
|
|
263
|
+
if (verbose) process.stdout.write(d);
|
|
264
|
+
});
|
|
265
|
+
this.proc.stderr &&
|
|
266
|
+
this.proc.stderr.on('data', (d) => {
|
|
267
|
+
this._stderr += String(d);
|
|
268
|
+
if (verbose) process.stderr.write(d);
|
|
269
|
+
});
|
|
203
270
|
} catch (e) {}
|
|
204
271
|
this.proc.on('close', (code) => {
|
|
205
272
|
this._exitCode = code;
|
|
206
|
-
try {
|
|
207
|
-
|
|
273
|
+
try {
|
|
274
|
+
this.stdin = null;
|
|
275
|
+
} catch (e) {}
|
|
276
|
+
if (this._diedResolve) {
|
|
277
|
+
this._diedResolve(code);
|
|
278
|
+
this._diedResolve = null;
|
|
279
|
+
}
|
|
208
280
|
if (code !== 0 && code !== null) {
|
|
209
|
-
console.error(
|
|
281
|
+
console.error(
|
|
282
|
+
`[ffmpeg-runner] ffmpeg exited unexpectedly (code ${code}): ${this._stderr.slice(-400)}`,
|
|
283
|
+
);
|
|
210
284
|
}
|
|
211
285
|
// Audio pipe (fd3) is owned by the child process — just null the ref.
|
|
212
286
|
this._audioFifoStream = null;
|
|
213
287
|
this._audioFifoFd = null;
|
|
214
288
|
});
|
|
215
|
-
try {
|
|
289
|
+
try {
|
|
290
|
+
this.proc.stdin.setMaxListeners(100);
|
|
291
|
+
} catch (e) {}
|
|
216
292
|
|
|
217
293
|
// No silent pre-prime needed: ffmpeg reads video (pipe:0) and audio
|
|
218
294
|
// (pipe:3) on independent threads, so neither blocks the other at
|
|
@@ -229,18 +305,36 @@ export class FFmpegRunner {
|
|
|
229
305
|
const args = [];
|
|
230
306
|
if (!verbose) args.push('-hide_banner', '-nostats', '-loglevel', 'warning');
|
|
231
307
|
args.push(
|
|
232
|
-
'-f',
|
|
233
|
-
'
|
|
234
|
-
'-
|
|
235
|
-
'
|
|
236
|
-
'-
|
|
237
|
-
|
|
308
|
+
'-f',
|
|
309
|
+
'rawvideo',
|
|
310
|
+
'-pix_fmt',
|
|
311
|
+
'rgba',
|
|
312
|
+
'-s',
|
|
313
|
+
`${width}x${height}`,
|
|
314
|
+
'-r',
|
|
315
|
+
String(fps),
|
|
316
|
+
'-i',
|
|
317
|
+
'pipe:0',
|
|
318
|
+
'-pix_fmt',
|
|
319
|
+
'yuv420p',
|
|
320
|
+
'-c:v',
|
|
321
|
+
'libx264',
|
|
322
|
+
'-preset',
|
|
323
|
+
'ultrafast',
|
|
324
|
+
'-tune',
|
|
325
|
+
'zerolatency',
|
|
326
|
+
'-g',
|
|
327
|
+
String(Math.max(1, Math.round(fps))),
|
|
238
328
|
'-an',
|
|
239
329
|
);
|
|
240
330
|
if (isUrl) args.push('-f', 'flv');
|
|
241
331
|
args.push('-y', outPath);
|
|
242
332
|
|
|
243
|
-
if (verbose)
|
|
333
|
+
if (verbose)
|
|
334
|
+
console.error(
|
|
335
|
+
`[ffmpeg-runner] strategy A (video-only, ${isUrl ? 'rtmp' : 'file'}):`,
|
|
336
|
+
args.join(' '),
|
|
337
|
+
);
|
|
244
338
|
|
|
245
339
|
this.proc = spawn('ffmpeg', args, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
246
340
|
this.stdin = this.proc.stdin;
|
|
@@ -248,21 +342,43 @@ export class FFmpegRunner {
|
|
|
248
342
|
this._stderr = '';
|
|
249
343
|
this._exitCode = null;
|
|
250
344
|
|
|
251
|
-
this.proc.on('error', (err) => {
|
|
345
|
+
this.proc.on('error', (err) => {
|
|
346
|
+
this._stderr += `\nspawn error: ${String(err)}`;
|
|
347
|
+
try {
|
|
348
|
+
this.stdin = null;
|
|
349
|
+
} catch (e) {}
|
|
350
|
+
});
|
|
252
351
|
this.proc.stdin && this.proc.stdin.on('error', () => {});
|
|
253
352
|
try {
|
|
254
|
-
this.proc.stdout &&
|
|
255
|
-
|
|
353
|
+
this.proc.stdout &&
|
|
354
|
+
this.proc.stdout.on('data', (d) => {
|
|
355
|
+
this._stderr += String(d);
|
|
356
|
+
if (verbose) process.stdout.write(d);
|
|
357
|
+
});
|
|
358
|
+
this.proc.stderr &&
|
|
359
|
+
this.proc.stderr.on('data', (d) => {
|
|
360
|
+
this._stderr += String(d);
|
|
361
|
+
if (verbose) process.stderr.write(d);
|
|
362
|
+
});
|
|
256
363
|
} catch (e) {}
|
|
257
364
|
this.proc.on('close', (code) => {
|
|
258
365
|
this._exitCode = code;
|
|
259
|
-
try {
|
|
260
|
-
|
|
366
|
+
try {
|
|
367
|
+
this.stdin = null;
|
|
368
|
+
} catch (e) {}
|
|
369
|
+
if (this._diedResolve) {
|
|
370
|
+
this._diedResolve(code);
|
|
371
|
+
this._diedResolve = null;
|
|
372
|
+
}
|
|
261
373
|
if (code !== 0 && code !== null) {
|
|
262
|
-
console.error(
|
|
374
|
+
console.error(
|
|
375
|
+
`[ffmpeg-runner] ffmpeg exited unexpectedly (code ${code}): ${this._stderr.slice(-400)}`,
|
|
376
|
+
);
|
|
263
377
|
}
|
|
264
378
|
});
|
|
265
|
-
try {
|
|
379
|
+
try {
|
|
380
|
+
this.proc.stdin.setMaxListeners(100);
|
|
381
|
+
} catch (e) {}
|
|
266
382
|
|
|
267
383
|
return !!this.proc && !!this.proc.pid;
|
|
268
384
|
}
|
|
@@ -278,7 +394,9 @@ export class FFmpegRunner {
|
|
|
278
394
|
if (this._raw) {
|
|
279
395
|
try {
|
|
280
396
|
if (this._stream && !this._stream.destroyed)
|
|
281
|
-
this._stream.write(
|
|
397
|
+
this._stream.write(
|
|
398
|
+
Buffer.from(videoFrame.buffer, videoFrame.byteOffset, videoFrame.byteLength),
|
|
399
|
+
);
|
|
282
400
|
} catch (e) {}
|
|
283
401
|
return Promise.resolve(true);
|
|
284
402
|
}
|
|
@@ -294,12 +412,12 @@ export class FFmpegRunner {
|
|
|
294
412
|
if (this._liveAudio && this._audioFifoStream && !this._audioFifoStream.destroyed) {
|
|
295
413
|
try {
|
|
296
414
|
this._audioFifoStream.write(
|
|
297
|
-
Buffer.from(audioChunk.buffer, audioChunk.byteOffset, audioChunk.byteLength)
|
|
415
|
+
Buffer.from(audioChunk.buffer, audioChunk.byteOffset, audioChunk.byteLength),
|
|
298
416
|
);
|
|
299
417
|
} catch (e) {}
|
|
300
418
|
} else if (!this._liveAudio) {
|
|
301
419
|
this._audioChunks.push(
|
|
302
|
-
Buffer.from(audioChunk.buffer, audioChunk.byteOffset, audioChunk.byteLength)
|
|
420
|
+
Buffer.from(audioChunk.buffer, audioChunk.byteOffset, audioChunk.byteLength),
|
|
303
421
|
);
|
|
304
422
|
}
|
|
305
423
|
}
|
|
@@ -344,8 +462,11 @@ export class FFmpegRunner {
|
|
|
344
462
|
}, 100);
|
|
345
463
|
const watchdog = setTimeout(() => {
|
|
346
464
|
if (this.proc && this._exitCode === null) {
|
|
347
|
-
if (this._verbose)
|
|
348
|
-
|
|
465
|
+
if (this._verbose)
|
|
466
|
+
console.error('[ffmpeg-runner] stdin drain timeout — killing ffmpeg');
|
|
467
|
+
try {
|
|
468
|
+
this.proc.kill('SIGTERM');
|
|
469
|
+
} catch (e) {}
|
|
349
470
|
}
|
|
350
471
|
done(false);
|
|
351
472
|
}, 15000);
|
|
@@ -353,7 +474,9 @@ export class FFmpegRunner {
|
|
|
353
474
|
} else {
|
|
354
475
|
setImmediate(() => resolve(true));
|
|
355
476
|
}
|
|
356
|
-
} catch (e) {
|
|
477
|
+
} catch (e) {
|
|
478
|
+
resolve(false);
|
|
479
|
+
}
|
|
357
480
|
});
|
|
358
481
|
}
|
|
359
482
|
|
|
@@ -365,22 +488,30 @@ export class FFmpegRunner {
|
|
|
365
488
|
if (!this._stream || this._stream.destroyed) return false;
|
|
366
489
|
this._stream.write(Buffer.from(frame.buffer ?? frame, frame.byteOffset, frame.byteLength));
|
|
367
490
|
return true;
|
|
368
|
-
} catch (e) {
|
|
491
|
+
} catch (e) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
369
494
|
}
|
|
370
495
|
if (!this.stdin || this.stdin.destroyed) return false;
|
|
371
496
|
try {
|
|
372
497
|
this.stdin.write(Buffer.from(frame.buffer ?? frame, frame.byteOffset, frame.byteLength));
|
|
373
498
|
return true;
|
|
374
|
-
} catch (e) {
|
|
499
|
+
} catch (e) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
375
502
|
}
|
|
376
503
|
|
|
377
504
|
tryWriteAudio(samples) {
|
|
378
505
|
if (!this._audio) return false;
|
|
379
506
|
if (this._liveAudio && this._audioFifoStream && !this._audioFifoStream.destroyed) {
|
|
380
507
|
try {
|
|
381
|
-
this._audioFifoStream.write(
|
|
508
|
+
this._audioFifoStream.write(
|
|
509
|
+
Buffer.from(samples.buffer, samples.byteOffset, samples.byteLength),
|
|
510
|
+
);
|
|
382
511
|
return true;
|
|
383
|
-
} catch (e) {
|
|
512
|
+
} catch (e) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
384
515
|
}
|
|
385
516
|
this._audioChunks.push(Buffer.from(samples.buffer, samples.byteOffset, samples.byteLength));
|
|
386
517
|
return true;
|
|
@@ -408,13 +539,17 @@ export class FFmpegRunner {
|
|
|
408
539
|
// ── Strategy B cleanup ────────────────────────────────────────────────
|
|
409
540
|
if (this._liveAudio) {
|
|
410
541
|
// Audio pipe (fd3) is owned by the child — end it to signal EOF to ffmpeg.
|
|
411
|
-
try {
|
|
542
|
+
try {
|
|
543
|
+
if (this._audioFifoStream && !this._audioFifoStream.destroyed) this._audioFifoStream.end();
|
|
544
|
+
} catch (e) {}
|
|
412
545
|
this._audioFifoStream = null;
|
|
413
546
|
this._audioFifoFd = null;
|
|
414
547
|
}
|
|
415
548
|
|
|
416
549
|
// End video stdin
|
|
417
|
-
try {
|
|
550
|
+
try {
|
|
551
|
+
this.stdin.end();
|
|
552
|
+
} catch (e) {}
|
|
418
553
|
|
|
419
554
|
await new Promise((resolve, reject) => {
|
|
420
555
|
const onClose = () => {
|
|
@@ -428,7 +563,12 @@ export class FFmpegRunner {
|
|
|
428
563
|
};
|
|
429
564
|
if (this._exitCode !== null) return onClose();
|
|
430
565
|
this.proc.once('close', onClose);
|
|
431
|
-
setTimeout(() => {
|
|
566
|
+
setTimeout(() => {
|
|
567
|
+
if (this.proc)
|
|
568
|
+
try {
|
|
569
|
+
this.proc.kill('SIGTERM');
|
|
570
|
+
} catch (e) {}
|
|
571
|
+
}, 10000);
|
|
432
572
|
});
|
|
433
573
|
|
|
434
574
|
if (this._liveAudio) return this._outPath;
|
|
@@ -439,4 +579,3 @@ export class FFmpegRunner {
|
|
|
439
579
|
}
|
|
440
580
|
|
|
441
581
|
export default FFmpegRunner;
|
|
442
|
-
|
|
@@ -3,7 +3,7 @@ declare module './headless-cli.mjs' {
|
|
|
3
3
|
export interface RunHeadlessOptions {
|
|
4
4
|
argv?: string[];
|
|
5
5
|
instantiateFn?: (
|
|
6
|
-
wasmBinary: ArrayBuffer | Uint8Array
|
|
6
|
+
wasmBinary: ArrayBuffer | Uint8Array<ArrayBuffer>,
|
|
7
7
|
importObject: unknown,
|
|
8
8
|
) => Promise<{ instance: { exports: unknown } }>;
|
|
9
9
|
repoRoot?: string;
|