From 5193153516e750535da16c029446607d10a0685f Mon Sep 17 00:00:00 2001 From: Jon Q Programmer Date: Mon, 18 Mar 2019 19:39:39 +0000 Subject: [PATCH] functional checkpoint --- h264player/appRaspi.js | 1 + h264player/serverBase.js | 16 ++++++++-------- h264player/serverRaspi.js | 9 +++++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/h264player/appRaspi.js b/h264player/appRaspi.js index be9f3af..0bd1586 100644 --- a/h264player/appRaspi.js +++ b/h264player/appRaspi.js @@ -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); diff --git a/h264player/serverBase.js b/h264player/serverBase.js index abbda5a..e0e03f3 100644 --- a/h264player/serverBase.js +++ b/h264player/serverBase.js @@ -18,7 +18,7 @@ class ServerBase this.readStream = null; } - getFeed() + getFeed(config) { throw new Error("to be implemented by subclasses"); } @@ -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; @@ -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 @@ -100,9 +100,9 @@ class ServerBase _onClientClose() { - this._stopFeed(); + console.log('Client closed'); + this._stopFeed(true/*force*/); } } - module.exports = ServerBase; diff --git a/h264player/serverRaspi.js b/h264player/serverRaspi.js index 70e14ce..f4de18c 100644 --- a/h264player/serverRaspi.js +++ b/h264player/serverRaspi.js @@ -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) {