FFMPEG fix (finally) (#390)

Programmix sucks at this
This commit is contained in:
Programmix
2016-05-30 11:13:01 -07:00
committed by abalabahaha
parent 6bc2750f3d
commit 6b5f4fa773
4 changed files with 40 additions and 34 deletions

View File

@@ -122,17 +122,17 @@ var AudioEncoder = (function () {
}; };
AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) { AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) {
var _this4 = this;
var processKilled = false; var processKilled = false;
function killProcess() { function killProcess(cause) {
if (processKilled) return; if (processKilled) return;
enc.stdin.pause(); enc.stdin.pause();
enc.kill("SIGINT"); enc.kill("SIGKILL");
processKilled = true; processKilled = true;
reject(cause);
} }
var ffmpegErrors = ""; var ffmpegErrors = "";
@@ -143,10 +143,12 @@ var AudioEncoder = (function () {
ffmpegErrors += "\n" + new Buffer(data).toString().trim(); ffmpegErrors += "\n" + new Buffer(data).toString().trim();
}); });
enc.stdout.on("end", function () { enc.stdout.once("end", function () {
killProcess(); killProcess("end");
});
reject("end"); enc.stdout.once("error", function () {
enc.stdout.emit("end");
}); });
enc.once("exit", function (code, signal) { enc.once("exit", function (code, signal) {
@@ -170,21 +172,19 @@ var AudioEncoder = (function () {
}); });
this.volume.once("end", function () { this.volume.once("end", function () {
killProcess(); killProcess("end");
});
reject("end"); this.volume.once("error", function () {
killProcess("end");
}); });
this.volume.on("end", function () { this.volume.on("end", function () {
killProcess(); killProcess("end");
reject("end");
}); });
this.volume.on("close", function () { this.volume.on("close", function () {
killProcess(); killProcess("close");
reject("close");
}); });
}; };

View File

@@ -129,7 +129,7 @@ var VoiceConnection = (function (_EventEmitter) {
} }
if (this.streamProc) { if (this.streamProc) {
this.streamProc.stdin.pause(); this.streamProc.stdin.pause();
this.streamProc.kill("SIGINT"); this.streamProc.kill("SIGKILL");
this.streamProc = null; this.streamProc = null;
} }
}; };
@@ -156,6 +156,7 @@ var VoiceConnection = (function (_EventEmitter) {
} }
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
self.stopPlaying();
retStream.emit("end"); retStream.emit("end");
return; return;
} }
@@ -166,6 +167,7 @@ var VoiceConnection = (function (_EventEmitter) {
if (!buffer) { if (!buffer) {
if (onWarning) { if (onWarning) {
self.setSpeaking(false); self.setSpeaking(false);
self.stopPlaying();
retStream.emit("end"); retStream.emit("end");
return; return;
} else { } else {

View File

@@ -114,28 +114,32 @@ export default class AudioEncoder {
hookEncodingProcess(resolve, reject, enc, stream) { hookEncodingProcess(resolve, reject, enc, stream) {
var processKilled = false; var processKilled = false;
function killProcess() { function killProcess(cause) {
if (processKilled) if (processKilled)
return; return;
enc.stdin.pause(); enc.stdin.pause();
enc.kill("SIGINT"); enc.kill("SIGKILL");
processKilled = true; processKilled = true;
reject(cause);
} }
var ffmpegErrors = ""; var ffmpegErrors = "";
enc.stdout.pipe(this.volume); enc.stdout.pipe(this.volume);
enc.stderr.on("data", (data) => { enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim(); ffmpegErrors += "\n" + new Buffer(data).toString().trim();
}); });
enc.stdout.on("end", () => { enc.stdout.once("end", () => {
killProcess(); killProcess("end");
});
reject("end"); enc.stdout.once("error", () => {
enc.stdout.emit("end");
}); });
enc.once("exit", (code, signal) => { enc.once("exit", (code, signal) => {
@@ -144,10 +148,10 @@ export default class AudioEncoder {
} }
}); });
this.volume.once("readable", () => { this.volume.once("readable", function () {
var data = { var data = {
proc: enc, proc: enc,
stream: this.volume, stream: _this4.volume,
channels: 2 channels: 2
}; };
@@ -159,21 +163,19 @@ export default class AudioEncoder {
}); });
this.volume.once("end", () => { this.volume.once("end", () => {
killProcess(); killProcess("end");
reject("end");
}); });
this.volume.on("end", () => { this.volume.once("error", () => {
killProcess(); killProcess("end");
})
reject("end"); this.volume.on("end", () => {
killProcess("end");
}); });
this.volume.on("close", () => { this.volume.on("close", () => {
killProcess(); killProcess("close");
reject("close");
}); });
} }
} }

View File

@@ -93,7 +93,7 @@ export default class VoiceConnection extends EventEmitter {
} }
if (this.streamProc) { if (this.streamProc) {
this.streamProc.stdin.pause(); this.streamProc.stdin.pause();
this.streamProc.kill("SIGINT"); this.streamProc.kill("SIGKILL");
this.streamProc = null; this.streamProc = null;
} }
} }
@@ -118,6 +118,7 @@ export default class VoiceConnection extends EventEmitter {
} }
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
self.stopPlaying();
retStream.emit("end"); retStream.emit("end");
return; return;
} }
@@ -128,6 +129,7 @@ export default class VoiceConnection extends EventEmitter {
if (!buffer) { if (!buffer) {
if (onWarning) { if (onWarning) {
self.setSpeaking(false); self.setSpeaking(false);
self.stopPlaying();
retStream.emit("end"); retStream.emit("end");
return; return;
} else { } else {