fix: crash EPIPE lors ecriture dans sox stdin ferme
- Ajout error handler sur playbackProcess.stdin (capture EPIPE) - Verification stdin.writable avant write - Stop playback loop si stdin non disponible - Evite crash serveur lors stop/reload AudioBridge
This commit is contained in:
@@ -282,6 +282,16 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
|
|
||||||
this.playbackProcess = spawn('sox', args);
|
this.playbackProcess = spawn('sox', args);
|
||||||
|
|
||||||
|
// Gérer l'erreur EPIPE sur stdin (si processus se ferme)
|
||||||
|
this.playbackProcess.stdin.on('error', (error) => {
|
||||||
|
if (error.code === 'EPIPE') {
|
||||||
|
console.warn('⚠️ Sox playback stdin fermé (EPIPE)');
|
||||||
|
this.isPlaying = false;
|
||||||
|
} else {
|
||||||
|
console.error('Erreur stdin sox playback:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.playbackProcess.stderr.on('data', (data) => {
|
this.playbackProcess.stderr.on('data', (data) => {
|
||||||
const msg = data.toString();
|
const msg = data.toString();
|
||||||
if (!msg.includes('sox WARN')) {
|
if (!msg.includes('sox WARN')) {
|
||||||
@@ -347,22 +357,32 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
_startPlaybackLoop() {
|
_startPlaybackLoop() {
|
||||||
const playNextChunk = () => {
|
const playNextChunk = () => {
|
||||||
if (!this.isPlaying || !this.playbackProcess) return;
|
if (!this.isPlaying || !this.playbackProcess || !this.playbackProcess.stdin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.playbackBuffer.length > 0) {
|
if (this.playbackBuffer.length > 0) {
|
||||||
const chunk = this.playbackBuffer.shift();
|
const chunk = this.playbackBuffer.shift();
|
||||||
try {
|
try {
|
||||||
this.playbackProcess.stdin.write(chunk);
|
if (this.playbackProcess.stdin.writable) {
|
||||||
|
this.playbackProcess.stdin.write(chunk);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur écriture stdin sox:', error);
|
console.error('Erreur écriture stdin sox:', error);
|
||||||
|
this.isPlaying = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Buffer vide : underrun (silence)
|
// Buffer vide : underrun (silence)
|
||||||
const silenceBuffer = Buffer.alloc(this.options.framesPerBuffer * 2 * this.options.channels);
|
const silenceBuffer = Buffer.alloc(this.options.framesPerBuffer * 2 * this.options.channels);
|
||||||
try {
|
try {
|
||||||
this.playbackProcess.stdin.write(silenceBuffer);
|
if (this.playbackProcess.stdin.writable) {
|
||||||
|
this.playbackProcess.stdin.write(silenceBuffer);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore si process fermé
|
// Ignore si process fermé
|
||||||
|
this.isPlaying = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.emit('bufferUnderrun');
|
this.emit('bufferUnderrun');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ audio:
|
|||||||
jitterBufferMs: 40
|
jitterBufferMs: 40
|
||||||
device:
|
device:
|
||||||
inputDeviceId: 1
|
inputDeviceId: 1
|
||||||
outputDeviceId: 2
|
outputDeviceId: 0
|
||||||
sampleRate: 48000
|
sampleRate: 48000
|
||||||
routing:
|
routing:
|
||||||
inputToGroup:
|
inputToGroup:
|
||||||
|
|||||||
Reference in New Issue
Block a user