Преглед изворни кода

refactor tsblast into new udp-blast module

Gil Pedersen пре 11 година
родитељ
комит
9139689d7e
3 измењених фајлова са 5 додато и 71 уклоњено
  1. 4 4
      bin/hlsdump
  2. 0 67
      lib/tsblast.js
  3. 1 0
      package.json

+ 4 - 4
bin/hlsdump

@@ -41,10 +41,10 @@ var util = require('util'),
 
 var streamprocess = require('streamprocess'),
     oncemore = require('oncemore'),
-    uristream = require('uristream');
+    uristream = require('uristream'),
+    UdpBlast = require('udp-blast');
 var reader = require('../lib/reader'),
-    tssmooth = require('../lib/tssmooth'),
-    tsblast = require('../lib/tsblast');
+    tssmooth = require('../lib/tssmooth');
 
 var Passthrough = require('readable-stream/passthrough');
 
@@ -176,7 +176,7 @@ var buffer = new Passthrough({highWaterMark:hlsdump.bufferSize});
 var outputs = [];
 
 if (hlsdump.udp)
-  outputs.push(tsblast(hlsdump.udp));
+  outputs.push(new UdpBlast(hlsdump.udp, { packetSize: 7 * 188 }));
 
 if (hlsdump.output) {
   if (hlsdump.output === '-')

+ 0 - 67
lib/tsblast.js

@@ -1,67 +0,0 @@
-"use strict";
-
-var dgram = require('dgram'),
-    util = require('util'),
-    assert = require('assert');
-
-var Writable = require('readable-stream/writable');
-
-function TsBlast(dst, options) {
-  Writable.call(this, options);
-
-  if (typeof dst === 'number')
-    dst = {port:dst, host:'localhost'};
-
-  this.dst = dst;
-  this.options = options || {};
-
-  this.buffer = new Buffer(0);
-  this.client = dgram.createSocket('udp4');
-  this.client.bind();
-
-  this.on('finish', function() {
-    this.client.close();
-  });
-
-  return this;
-}
-util.inherits(TsBlast, Writable);
-
-TsBlast.prototype._write = function(chunk, encoding, cb) {
-  var self = this;
-
-  if (chunk) {
-    if (this.buffer.length)
-      this.buffer = Buffer.concat([this.buffer, chunk]);
-    else
-      this.buffer = chunk;
-  }
-
-  var index = 0, psize = 188 * 7;
-
-  function sendnext() {
-    if ((self.buffer.length - index) >= psize) {
-      self.client.send(self.buffer, index, psize, self.dst.port, self.dst.host, function(/*err, bytes*/) {
-        // TODO: handle errors?
-        index += psize;
-        sendnext();
-      });
-    } else {
-      /*    if (!chunk) {
-            self.client.send(self.buffer, index, self.buffer.length - index, self.dst.port, self.dst.host);
-            index = self.buffer.length;
-          }*/
-      if (index) self.buffer = self.buffer.slice(index);
-      cb();
-    }
-  }
-
-  sendnext();
-};
-
-
-var tsblast = module.exports = function tsblast(dst, options) {
-  return new TsBlast(dst, options);
-};
-
-tsblast.TsBlast = TsBlast;

+ 1 - 0
package.json

@@ -37,6 +37,7 @@
     "oncemore": "~0.1.0",
     "readable-stream": "~1.0.0",
     "streamprocess": "0.0.1",
+    "udp-blast": "^1.0.0",
     "uristream": "~0.1.0",
     "xtend": "^2.0.3"
   },