Forráskód Böngészése

update streams2 API usage to match what will likely be released

This also temporarily disables node 0.8 functionality until readable-stream is updated.
Gil Pedersen 13 éve
szülő
commit
8948274cd8
5 módosított fájl, 13 hozzáadás és 11 törlés
  1. 1 1
      bin/hlsdump
  2. 2 2
      lib/reader.js
  3. 1 1
      lib/tsblast.js
  4. 6 6
      lib/tssmooth.js
  5. 3 1
      package.json

+ 1 - 1
bin/hlsdump

@@ -56,7 +56,7 @@ r.on('end', function() {
 
 var stream = r;
 if (hlsdump.sync)
-  stream = stream.pipe(tssmooth(), {chunkSize:16*1024});
+  stream = stream.pipe(tssmooth());
 
 if (hlsdump.udp)
   stream.pipe(tsblast(hlsdump.udp));

+ 2 - 2
lib/reader.js

@@ -56,7 +56,7 @@ function getFileStream(srcUrl, options, cb) {
         req.abort();
         return cb(new Error('Bad server response code: '+statusCode));
       }
-      req.setEncoding = res.setEncoding; // hack to fix setencoding called from carrier
+      req.setEncoding = res.setEncoding.bind(res); // hack to fix setencoding called from carrier
 
       var stream = req;
       if (res.headers['content-encoding'] === 'gzip' || res.headers['content-encoding'] === 'deflate') {
@@ -216,7 +216,7 @@ function HlsStreamReader(src, options) {
         stream.on('close', Done);
 
         self.readState.stream = stream;
-        self.stream_start(true, !self.push(new Buffer(0)));
+        self.stream_start(true, !self.push(''));
 
         function Done(err) {
           debug('finished with input stream');

+ 1 - 1
lib/tsblast.js

@@ -33,7 +33,7 @@ function TsBlast(dst, options) {
 }
 util.inherits(TsBlast, Writable);
 
-TsBlast.prototype._write = function(chunk, cb) {
+TsBlast.prototype._write = function(chunk, encoding, cb) {
   var self = this;
 
   if (chunk) {

+ 6 - 6
lib/tssmooth.js

@@ -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();
 };
 

+ 3 - 1
package.json

@@ -28,11 +28,13 @@
     "debug": "~0.7.0",
     "carrier": "~0.1.8",
     "commander": "~1.1.1",
-    "readable-stream": "~0.3.0",
     "request": "~2.14.0"
   },
   "devDependencies": {
     "mocha": "~1.7.4",
     "should": "~1.2.1"
+  },
+  "engines" : {
+    "node" : ">=0.9.12"
   }
 }