Potential FFMPEG process fix (#381)

I am by no means sure that this will work. This is an experimental fix.
Please review it carefully; I’m not the best at working with
audio/streams.
This commit is contained in:
Programmix
2016-05-27 23:09:16 -07:00
committed by abalabahaha
parent e912c72a95
commit 2194632b7d
4 changed files with 118 additions and 171 deletions

View File

@@ -1605,9 +1605,9 @@ var InternalClient = (function () {
data = { data = {
name: data.name || channel.name, name: data.name || channel.name,
topic: data.topic || channel.topic, topic: data.topic || channel.topic,
position: data.position || channel.position, position: data.position ? data.position : channel.position,
user_limit: data.userLimit || channel.userLimit, user_limit: data.userLimit ? data.userLimit : channel.userLimit,
bitrate: data.bitrate || channel.bitrate bitrate: data.bitrate ? data.bitrate : channel.bitrate
}; };
if (data.position < 0) { if (data.position < 0) {

View File

@@ -91,34 +91,7 @@ var AudioEncoder = (function () {
stream.pipe(enc.stdin); stream.pipe(enc.stdin);
var ffmpegErrors = ""; hookEncodingProcess(resolve, reject, enc, stream);
enc.stdout.pipe(_this.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
_this.volume.once("readable", function () {
resolve({
proc: enc,
stream: _this.volume,
instream: stream,
channels: 2
});
});
_this.volume.on("end", function () {
reject("end");
});
_this.volume.on("close", function () {
reject("close");
});
}); });
}; };
@@ -130,33 +103,7 @@ var AudioEncoder = (function () {
var enc = _child_process2["default"].spawn(_this2.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']); var enc = _child_process2["default"].spawn(_this2.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
var ffmpegErrors = ""; hookEncodingProcess(resolve, reject, enc);
enc.stdout.pipe(_this2.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
_this2.volume.once("readable", function () {
resolve({
proc: enc,
stream: _this2.volume,
channels: 2
});
});
_this2.volume.on("end", function () {
reject("end");
});
_this2.volume.on("close", function () {
reject("close");
});
}); });
}; };
@@ -170,9 +117,27 @@ var AudioEncoder = (function () {
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']); var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
var enc = _child_process2["default"].spawn(_this3.getCommand(), options); var enc = _child_process2["default"].spawn(_this3.getCommand(), options);
hookEncodingProcess(resolve, reject, enc);
});
};
AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) {
var _this4 = this;
var processKilled = false;
function killProcess() {
if (processKilled) return;
enc.stdin.pause();
enc.kill("SIGINT");
processKilled = true;
}
var ffmpegErrors = ""; var ffmpegErrors = "";
enc.stdout.pipe(_this3.volume); enc.stdout.pipe(this.volume);
enc.stderr.on("data", function (data) { enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim(); ffmpegErrors += "\n" + new Buffer(data).toString().trim();
}); });
@@ -182,22 +147,31 @@ var AudioEncoder = (function () {
} }
}); });
_this3.volume.once("readable", function () { this.volume.once("readable", function () {
resolve({ var data = {
proc: enc, proc: enc,
stream: _this3.volume, stream: _this4.volume,
channels: 2 channels: 2
}); };
if (stream) {
data.instream = stream;
}
resolve(data);
}); });
_this3.volume.on("end", function () { this.volume.on("end", function () {
killProcess();
reject("end"); reject("end");
}); });
_this3.volume.on("close", function () { this.volume.on("close", function () {
killProcess();
reject("close"); reject("close");
}); });
});
}; };
return AudioEncoder; return AudioEncoder;

View File

@@ -73,34 +73,7 @@ export default class AudioEncoder {
stream.pipe(enc.stdin); stream.pipe(enc.stdin);
var ffmpegErrors = ""; hookEncodingProcess(resolve, reject, enc, stream);
enc.stdout.pipe(this.volume);
enc.stderr.on("data", (data) => {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", (code, signal) => {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
})
this.volume.once("readable", () => {
resolve({
proc: enc,
stream: this.volume,
instream: stream,
channels: 2
});
});
this.volume.on("end", () => {
reject("end");
});
this.volume.on("close", () => {
reject("close");
});
}); });
} }
@@ -117,33 +90,7 @@ export default class AudioEncoder {
'pipe:1' 'pipe:1'
]); ]);
var ffmpegErrors = ""; hookEncodingProcess(resolve, reject, enc);
enc.stdout.pipe(this.volume);
enc.stderr.on("data", (data) => {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", (code, signal) => {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
})
this.volume.once("readable", () => {
resolve({
proc: enc,
stream: this.volume,
channels: 2
});
});
this.volume.on("end", () => {
reject("end");
});
this.volume.on("close", () => {
reject("close");
});
}); });
} }
@@ -160,6 +107,23 @@ export default class AudioEncoder {
]); ]);
var enc = cpoc.spawn(this.getCommand(), options); var enc = cpoc.spawn(this.getCommand(), options);
hookEncodingProcess(resolve, reject, enc);
});
}
hookEncodingProcess(resolve, reject, enc, stream) {
var processKilled = false;
function killProcess() {
if (processKilled)
return;
enc.stdin.pause();
enc.kill("SIGINT");
processKilled = true;
}
var ffmpegErrors = ""; var ffmpegErrors = "";
enc.stdout.pipe(this.volume); enc.stdout.pipe(this.volume);
@@ -170,23 +134,32 @@ export default class AudioEncoder {
if (code) { if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors)); reject(new Error("FFMPEG: " + ffmpegErrors));
} }
}) });
this.volume.once("readable", () => { this.volume.once("readable", () => {
resolve({ var data = {
proc: enc, proc: enc,
stream: this.volume, stream: this.volume,
channels: 2 channels: 2
}); };
if (stream) {
data.instream = stream;
}
resolve(data);
}); });
this.volume.on("end", () => { this.volume.on("end", () => {
killProcess();
reject("end"); reject("end");
}); });
this.volume.on("close", () => { this.volume.on("close", () => {
killProcess();
reject("close"); reject("close");
}); });
});
} }
} }