Skip to content

Commit

Permalink
functional checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Q Programmer authored and Jon Q Programmer committed Mar 18, 2019
1 parent 7cb6035 commit 5193153
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions h264player/appRaspi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ app.use(express.static(__dirname + '/www'));
const server = http.createServer(app);
const silence = new WebStreamerServer(server);

console.log("appRaspi listening on port 8080");
server.listen(8080);
16 changes: 8 additions & 8 deletions h264player/serverBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ServerBase
this.readStream = null;
}

getFeed()
getFeed(config)
{
throw new Error("to be implemented by subclasses");
}
Expand All @@ -28,11 +28,11 @@ class ServerBase
console.log("endFeed isn't implemented by subclass");
}

_startFeed()
_startFeed(cfg)
{
if(this.readStream == null)
{
var readStream = this.getFeed(); // invokes subclass implementation
var readStream = this.getFeed(cfg); // invokes subclass method
readStream = readStream.pipe(new Splitter(NALseparator));
readStream.on("data", this._broadcast.bind(this));
this.readStream = readStream;
Expand Down Expand Up @@ -79,13 +79,13 @@ class ServerBase

_onClientMsg(data)
{
var cmd = "" + data;
var action = data.split(' ')[0];
var args = data.split(' ');
var action = args[0];
console.log("Incoming action '%s'", action);
switch(action)
{
case "REQUESTSTREAM":
this._startFeed();
this._startFeed(data);
break;
case "STOPSTREAM":
this._stopFeed(); // was pause
Expand All @@ -100,9 +100,9 @@ class ServerBase

_onClientClose()
{
this._stopFeed();
console.log('Client closed');
this._stopFeed(true/*force*/);
}
}


module.exports = ServerBase;
9 changes: 7 additions & 2 deletions h264player/serverRaspi.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ class RaspiServer extends ServerBase
this.streamer = null;
}

getFeed(cmd)
getFeed(data)
{
if(!this.streamer || this.streamer.killed)
{
var args = ["-t", "0",
// expect REQUESTSTREAM raspivid -t 0 -b 2000000 -o - -w 640...
var args = data.split(" ").slice(2); // skip first two args
if(args.length == 0)
{
args = ["-t", "0",
"-b", this.options.bitrate,
"-o", "-",
"-w", this.options.width,
"-h", this.options.height,
"-fps", this.options.fps,
"-pf", "baseline"];
}
console.log("raspivid", args.join(" "));
this.streamer = spawn("raspivid", args); // child process
this.streamer.on("exit", function(code) {
Expand Down

0 comments on commit 5193153

Please sign in to comment.