ソースを参照

ignore late data

Gil Pedersen 12 年 前
コミット
5d7d0db3e5
1 ファイル変更5 行追加1 行削除
  1. 5 1
      lib/tssmooth.js

+ 5 - 1
lib/tssmooth.js

@@ -54,6 +54,7 @@ function TsSmooth(options) {
   this.pcr = -1;
   this.pcr = -1;
   this.last = null;
   this.last = null;
 
 
+  this.error_limit = 80000; /* 80 ms */
   this.bitrate = 10E06;
   this.bitrate = 10E06;
   this.pcrtime = -1;
   this.pcrtime = -1;
 
 
@@ -175,7 +176,7 @@ TsSmooth.prototype._transform = function(chunk, encoding, cb) {
 
 
         var now = utime();
         var now = utime();
         var error = (out.time - now) - out.delta;
         var error = (out.time - now) - out.delta;
-        var waittime = (error > 80000) ? (error/1000 - 5) : 0;
+        var waittime = (error > self.error_limit) ? (error/1000 - 5) : 0;
 
 
         if (error < -2*1E6 || error > 300*1E6) {
         if (error < -2*1E6 || error > 300*1E6) {
           // negative == buffer too late
           // negative == buffer too late
@@ -183,6 +184,9 @@ TsSmooth.prototype._transform = function(chunk, encoding, cb) {
           self.emit('warning', new RateError('PCR sync offset '+(error/1E6).toFixed(2)+'s error'));
           self.emit('warning', new RateError('PCR sync offset '+(error/1E6).toFixed(2)+'s error'));
           self.reset(pcr);
           self.reset(pcr);
           waittime = 0;
           waittime = 0;
+        } else if (error < -self.error_limit) {
+          // ignore the data since it is too late
+          return processNext();
         }
         }
 
 
         return wait(waittime, function output() {
         return wait(waittime, function output() {