Permalink
Browse files

more futzing and an attempt at testing

  • Loading branch information...
1 parent bfd8c56 commit 333f1121735bfd45be4dadfb4ef28e8ba662d4f8 @brianleroux brianleroux committed Oct 14, 2012
Showing with 85 additions and 56 deletions.
  1. +2 −2 README.md
  2. +1 −1 bin/nodecopter-stream
  3. +7 −5 lib/drone-stream.js
  4. +39 −27 lib/ffmpeg.js
  5. +7 −3 lib/ffserver.js
  6. +10 −17 nodecopter-stream.js
  7. +2 −1 package.json
  8. +17 −0 spec/drone-stream.spec.js
View
@@ -14,12 +14,12 @@ Known to work is ffmpeg 0.11.1.git-1ad63ff (ffmpeg-devel from macports).
Install via Github to get the *latest* version:
```bash
-npm install git://github.com/bkw/nodecopter-stream.git
+npm install -g git://github.com/bkw/nodecopter-stream.git
```
Launch the server:
```bash
-node stream.js
+nodecopter-stream
```
... and then open index.html in a recent browser (firefox, chrome, opera).
View
@@ -2,7 +2,7 @@
require('./../nodecopter-stream')()
-console.log('NodeCopter Stream started! View the stream here: file://' + __dirname + '/index.html' + "\n\n\n\n\n\n")
+console.log('NodeCopter Stream started here: file://' + __dirname.replace('/bin','') + '/index.html' + "\n\n\n\n\n\n")
var gracefulShutdown = function (signal) {
console.log('Exit on signal', signal);
View
@@ -1,14 +1,16 @@
var arDrone = require('ar-drone')
, tcpVideoStream = new arDrone.Client.PngStream.TcpVideoStream({timeout:9000})
+, Parser = require('./PaVEParser')
module.exports = function (cb) {
console.log('Connecting to drone');
tcpVideoStream.connect(function () {
tcpVideoStream.on('close', function () {
// TODO: try to reconnect
- gracefulShutdown();
- });
- console.log('connected to drone.');
- cb(tcpVideoStream);
- });
+ })
+ console.log('connected to drone.')
+ var p = new Parser
+ tcpVideoStream.pipe(p)
+ cb(null, p)
+ })
};
View
@@ -1,34 +1,46 @@
-var spawn = require('child_process').spawn
-, feedUrl = 'http://localhost:8090/nodecopter.ffm'
-
+// swing a dead cat in the general direction of the latency issues:
module.exports = function (cb) {
- var ffmpeg = spawn('ffmpeg', [
- '-v', 'error',
- '-analyzeduration', 0,
- '-i', '-',
- // swing a dead cat in the general direction of the latency issues:
- '-fflags', '+genpts',
- '-quality', 'realtime',
- '-cpu-used', 5,
- '-speed', 5,
- feedUrl
- ])
+ var port = 8090
+ , spawn = require('child_process').spawn
+ , ffserver = require('./ffserver')
+ , url = 'http://localhost:' + port + '/nodecopter.ffm'
+ , opts = ['-v'
+ ,'error'
+ ,'-analyzeduration'
+ ,0
+ ,'-i'
+ ,'-'
+ ,'-fflags'
+ ,'+genpts'
+ ,'-quality'
+ ,'realtime'
+ ,'-cpu-used'
+ ,5
+ ,'-speed'
+ ,5
+ ,url
+ ]
+
+ ffserver(function (err, server) {
- /*
- ffmpeg.stderr.on('data', function (ffmpegerr) {
- console.error('ffmpeg error: ' + ffmpegerr);
- })
+ var ffmpeg = spawn('ffmpeg', opts)
- ffmpeg.stdout.on('data', function (ffmpegout) {
- console.log('ffmpeg out: ' + ffmpegout);
- })
-
- ffmpeg.on('exit', function (code, signal) {
- console.log('ffmpeg exit', code, signal);
- gracefulShutdown(signal);
+ ffmpeg.stderr.on('data', function(d) {
+ cb(d, null)
+ })
+
+ /*
+ ffmpeg.stdout.on('data', function (ffmpegout) {
+ console.log('ffmpeg out: ' + ffmpegout);
})
- */
+ */
- cb(ffmpeg)
+ ffmpeg.on('exit', function (code, signal) {
+ // console.log('ffmpeg exit', code, signal);
+ server.kill()
+ })
+
+ cb(null, ffmpeg)
+ })
}
View
@@ -6,9 +6,11 @@ var mkdirp = require('mkdirp')
, feed = path.join(feeddir, 'nodecopter.ffm')
, spawn = require('child_process').spawn
-module.exports = function(cb) {
+module.exports = function (cb) {
// create a swap file
mkdirp(feeddir, function(err) {
+
+ if (err) cb(err)
fs.writeFileSync(feed)
@@ -20,7 +22,7 @@ module.exports = function(cb) {
});
ffserver.stdout.on('data', function (ffsrvout) {
- console.log('ffserver out:', ffsrvout.toString());
+ // console.log('ffserver out:', ffsrvout.toString());
});
ffserver.on('exit', function (code, signal) {
@@ -30,6 +32,8 @@ module.exports = function(cb) {
});
// launch the rest as soon as we hear from ffserver:
- ffserver.stdout.once('data', cb)
+ ffserver.stdout.once('data', function() {
+ cb(null, ffserver)
+ })
})
}
View
@@ -1,20 +1,13 @@
-var parser = new (require(__dirname + '/lib/PaVEParser'))()
- , ffserver = require('./lib/ffserver')
- , ffmpeg = require('./lib/ffmpeg')
- , drone = require('./lib/drone-stream')
+var ffmpeg = require('./lib/ffmpeg')
+, drone = require('./lib/drone-stream')
-module.exports = function() {
- // init ffserver
- ffserver(function() {
- // init ffmpeg
- ffmpeg(function(ffmpeg) {
- // get the pngs from teh drone
- drone(function(tcpVideoStream) {
- // pipe stream the parser
- tcpVideoStream.pipe(parser)
- // pipe parser to ffmpeg
- parser.pipe(ffmpeg.stdin)
- });
- });
+module.exports = function (port) {
+ // init ffmpeg
+ ffmpeg(function(err, ffmpeg) {
+ // get the pngs from teh drone
+ drone(function(err, stream) {
+ // pipe parser to ffmpeg
+ stream.pipe(ffmpeg.stdin)
+ })
})
}
View
@@ -3,7 +3,8 @@
"version": "0.0.1",
"bin": "bin/nodecopter-stream",
"scripts": {
- "start": "stream.js"
+ "start": "nodecopter-stream.js",
+ "test": "jasmine-node spec"
},
"dependencies": {
"ar-drone": "https://github.com/bkw/node-ar-drone/tarball/master",
View
@@ -0,0 +1,17 @@
+var ds = require('./../lib/drone-stream')
+
+describe('drone-stream', function(){
+
+ it('should exist, thus demonstrating sanity', function() {
+ expect(ds).not.toBeNull()
+ })
+
+ it('should return a pave stream thing', function(done){
+ ds(function(err, stream) {
+ expect(stream).not.toBeNull()
+ done()
+ })
+ })
+
+ // EOD
+})

0 comments on commit 333f112

Please sign in to comment.