diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 4c991897..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 { @@ -343,21 +350,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 diff --git a/revid/revid.go b/revid/revid.go index e5af76f3..ddf8dacb 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -286,10 +286,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") @@ -297,14 +296,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") @@ -315,6 +314,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