dont fill up our input buffers too much/too fast
This commit is contained in:
parent
126266e4d9
commit
362a00c967
15
lib/input.js
15
lib/input.js
@ -35,6 +35,8 @@ function Input(args) {
|
||||
this.channels = args.channels;
|
||||
this.bitDepth = args.bitDepth;
|
||||
this.sampleRate = args.sampleRate;
|
||||
|
||||
this.getMoreData = null;
|
||||
}
|
||||
|
||||
util.inherits(Input, Writable);
|
||||
@ -44,6 +46,13 @@ Input.prototype.read = function (samples) {
|
||||
if (this.buffer.length < bytes) bytes = this.buffer.length;
|
||||
var r = this.buffer.slice(0, bytes);
|
||||
this.buffer = this.buffer.slice(bytes);
|
||||
|
||||
if (this.buffer.length <= 131072 && this.getMoreData !== null) {
|
||||
var getMoreData = this.getMoreData;
|
||||
this.getMoreData = null;
|
||||
process.nextTick(getMoreData);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -85,6 +94,12 @@ Input.prototype._write = function (chunk, encoding, next) {
|
||||
}
|
||||
*/
|
||||
this.buffer = Buffer.concat([this.buffer, chunk]);
|
||||
if (this.buffer.length > 131072) {
|
||||
this.getMoreData = next;
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user