Merged in revid-start-stop-errors (pull request #114)

Return errors from revid.Start and revid.Stop

Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
Saxon Milton 2019-01-14 04:27:34 +00:00
commit ae34ebe368
2 changed files with 29 additions and 15 deletions

View File

@ -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

View File

@ -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