From 5ae1e41e38519adbf674da228b9cca2dc6c6a129 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 13 Jan 2019 22:01:04 +1030 Subject: [PATCH 1/3] revid: start and stop now return errors --- revid/revid.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 2b0bddbb..f14b1b2b 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -296,10 +296,9 @@ func (r *Revid) IsRunning() bool { // Start invokes a Revid to start processing video from a defined input // and packetising (if theres packetization) to a defined output. -func (r *Revid) Start() { +func (r *Revid) Start() error { if r.isRunning { - r.config.Logger.Log(logger.Warning, pkg+"revid.Start() called but revid already running") - return + return errors.New(pkg + "start called but revid is already running") } r.config.Logger.Log(logger.Info, pkg+"starting Revid") r.config.Logger.Log(logger.Debug, pkg+"setting up output") @@ -307,14 +306,14 @@ func (r *Revid) Start() { r.config.Logger.Log(logger.Info, pkg+"starting output routine") go r.outputClips() r.config.Logger.Log(logger.Info, pkg+"setting up input and receiving content") - go r.setupInput() + err := r.setupInput() + return err } // Stop halts any processing of video data from a camera or file -func (r *Revid) Stop() { +func (r *Revid) Stop() error { if !r.isRunning { - r.config.Logger.Log(logger.Warning, pkg+"revid.Stop() called but revid not running") - return + return errors.New(pkg + "stop called but revid is already stopped") } r.config.Logger.Log(logger.Info, pkg+"stopping revid") @@ -325,6 +324,7 @@ func (r *Revid) Stop() { if r.cmd != nil && r.cmd.Process != nil { r.cmd.Process.Kill() } + return nil } // outputClips takes the clips produced in the packClips method and outputs them From 19ae6f1ca646ec430afb19aceeebb3d6c017a927 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 13 Jan 2019 22:04:50 +1030 Subject: [PATCH 2/3] revid-cli: dealing with errors in revid-cli from start and stop if they occur --- cmd/revid-cli/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 4c991897..bc318694 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -343,21 +343,28 @@ func startRevid(ns *netsender.Sender, cfg revid.Config) (*revid.Revid, revid.Con if err != nil { return nil, cfg, err } - rv.Start() - return rv, cfg, nil + err = rv.Start() + return rv, cfg, err } -func stopRevid(rv *revid.Revid) { - rv.Stop() +func stopRevid(rv *revid.Revid) error { + err := rv.Stop() + if err != nil { + return err + } // FIXME(kortschak): Is this waiting on completion of work? // Use a wait group and Wait method if it is. time.Sleep(revidStopTime) + return nil } func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars map[string]string, stop bool) (*revid.Revid, revid.Config, error) { if stop { - stopRevid(rv) + err := stopRevid(rv) + if err != nil { + return nil, cfg, err + } } //look through the vars and update revid where needed From ae792ac11e6372596174e1f0b3f396696fb0f8cf Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 13 Jan 2019 22:15:30 +1030 Subject: [PATCH 3/3] revid-cli: capturing errors from calls to stopRevid --- cmd/revid-cli/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index bc318694..a6096b98 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -75,10 +75,13 @@ func main() { // run revid for the specified duration rv, _, err := startRevid(nil, cfg) if err != nil { - cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", err.Error()) + cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", "error", err.Error()) } time.Sleep(*runDurationPtr) - stopRevid(rv) + err = stopRevid(rv) + if err != nil { + cfg.Logger.Log(logger.Error, pkg+"failed to stop revid before program termination", "error", err.Error()) + } return } @@ -296,7 +299,11 @@ func run(rv *revid.Revid, cfg revid.Config) error { if vars["mode"] == "Paused" { if !paused { log.Log(logger.Info, pkg+"pausing revid") - stopRevid(rv) + err = stopRevid(rv) + if err != nil { + log.Log(logger.Error, pkg+"failed to stop revide", "error", err.Error()) + continue + } paused = true } } else {