|
|
@@ -108,14 +108,14 @@ function utime() {
|
|
|
}
|
|
|
|
|
|
// smoothly outputs given buffer before endTime
|
|
|
-function outputBefore(buffer, endTime, packetSize, outputFn, cb) {
|
|
|
+function outputBefore(stream, buffer, endTime, packetSize, cb) {
|
|
|
var index = 0;
|
|
|
|
|
|
function outputPacket() {
|
|
|
var now = utime();
|
|
|
var packetTime = (endTime - now) * (packetSize / (buffer.length - index));
|
|
|
|
|
|
- outputFn(buffer.slice(index, Math.min(buffer.length, index+packetSize)));
|
|
|
+ stream.push(buffer.slice(index, Math.min(buffer.length, index+packetSize)));
|
|
|
index += packetSize;
|
|
|
|
|
|
if (index < buffer.length) {
|
|
|
@@ -127,7 +127,7 @@ function outputBefore(buffer, endTime, packetSize, outputFn, cb) {
|
|
|
process.nextTick(outputPacket);
|
|
|
}
|
|
|
|
|
|
-TsSmooth.prototype._transform = function(chunk, output, cb) {
|
|
|
+TsSmooth.prototype._transform = function(chunk, encoding, cb) {
|
|
|
var self = this;
|
|
|
|
|
|
var index = Math.floor(this.buffer.length/188)*188;
|
|
|
@@ -160,7 +160,7 @@ TsSmooth.prototype._transform = function(chunk, output, cb) {
|
|
|
if (outtime !== -1 && index !== startIndex) {
|
|
|
var slice = buf.slice(startIndex, index);
|
|
|
startIndex = index;
|
|
|
- return outputBefore(slice, outtime, self.packetSize, output, processNext);
|
|
|
+ return outputBefore(self, slice, outtime, self.packetSize, processNext);
|
|
|
}
|
|
|
index += 188;
|
|
|
}
|
|
|
@@ -172,8 +172,8 @@ TsSmooth.prototype._transform = function(chunk, output, cb) {
|
|
|
processNext();
|
|
|
};
|
|
|
|
|
|
-TsSmooth.prototype._flush = function(output, cb) {
|
|
|
- if (this.buffer.length) output(this.buffer); // TODO: use outputBefore() based on current stream speed?
|
|
|
+TsSmooth.prototype._flush = function(cb) {
|
|
|
+ if (this.buffer.length) this.push(this.buffer); // TODO: use outputBefore() based on current stream speed?
|
|
|
cb();
|
|
|
};
|
|
|
|