mirror of https://bitbucket.org/ausocean/av.git
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:
commit
ae34ebe368
|
@ -75,10 +75,13 @@ func main() {
|
||||||
// run revid for the specified duration
|
// run revid for the specified duration
|
||||||
rv, _, err := startRevid(nil, cfg)
|
rv, _, err := startRevid(nil, cfg)
|
||||||
if err != nil {
|
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)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +299,11 @@ func run(rv *revid.Revid, cfg revid.Config) error {
|
||||||
if vars["mode"] == "Paused" {
|
if vars["mode"] == "Paused" {
|
||||||
if !paused {
|
if !paused {
|
||||||
log.Log(logger.Info, pkg+"pausing revid")
|
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
|
paused = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -343,21 +350,28 @@ func startRevid(ns *netsender.Sender, cfg revid.Config) (*revid.Revid, revid.Con
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cfg, err
|
return nil, cfg, err
|
||||||
}
|
}
|
||||||
rv.Start()
|
err = rv.Start()
|
||||||
return rv, cfg, nil
|
return rv, cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopRevid(rv *revid.Revid) {
|
func stopRevid(rv *revid.Revid) error {
|
||||||
rv.Stop()
|
err := rv.Stop()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME(kortschak): Is this waiting on completion of work?
|
// FIXME(kortschak): Is this waiting on completion of work?
|
||||||
// Use a wait group and Wait method if it is.
|
// Use a wait group and Wait method if it is.
|
||||||
time.Sleep(revidStopTime)
|
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) {
|
func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars map[string]string, stop bool) (*revid.Revid, revid.Config, error) {
|
||||||
if stop {
|
if stop {
|
||||||
stopRevid(rv)
|
err := stopRevid(rv)
|
||||||
|
if err != nil {
|
||||||
|
return nil, cfg, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//look through the vars and update revid where needed
|
//look through the vars and update revid where needed
|
||||||
|
|
|
@ -286,10 +286,9 @@ func (r *Revid) IsRunning() bool {
|
||||||
|
|
||||||
// Start invokes a Revid to start processing video from a defined input
|
// Start invokes a Revid to start processing video from a defined input
|
||||||
// and packetising (if theres packetization) to a defined output.
|
// and packetising (if theres packetization) to a defined output.
|
||||||
func (r *Revid) Start() {
|
func (r *Revid) Start() error {
|
||||||
if r.isRunning {
|
if r.isRunning {
|
||||||
r.config.Logger.Log(logger.Warning, pkg+"revid.Start() called but revid already running")
|
return errors.New(pkg + "start called but revid is already running")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
r.config.Logger.Log(logger.Info, pkg+"starting Revid")
|
r.config.Logger.Log(logger.Info, pkg+"starting Revid")
|
||||||
r.config.Logger.Log(logger.Debug, pkg+"setting up output")
|
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")
|
r.config.Logger.Log(logger.Info, pkg+"starting output routine")
|
||||||
go r.outputClips()
|
go r.outputClips()
|
||||||
r.config.Logger.Log(logger.Info, pkg+"setting up input and receiving content")
|
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
|
// Stop halts any processing of video data from a camera or file
|
||||||
func (r *Revid) Stop() {
|
func (r *Revid) Stop() error {
|
||||||
if !r.isRunning {
|
if !r.isRunning {
|
||||||
r.config.Logger.Log(logger.Warning, pkg+"revid.Stop() called but revid not running")
|
return errors.New(pkg + "stop called but revid is already stopped")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.config.Logger.Log(logger.Info, pkg+"stopping revid")
|
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 {
|
if r.cmd != nil && r.cmd.Process != nil {
|
||||||
r.cmd.Process.Kill()
|
r.cmd.Process.Kill()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// outputClips takes the clips produced in the packClips method and outputs them
|
// outputClips takes the clips produced in the packClips method and outputs them
|
||||||
|
|
Loading…
Reference in New Issue