revid: use loop in processFrom instead of goto

This commit is contained in:
Saxon 2020-01-24 21:25:27 +10:30
parent 0e14c0a056
commit 64754f7e0f
1 changed files with 20 additions and 24 deletions

View File

@ -859,32 +859,28 @@ func (r *Revid) Update(vars map[string]string) error {
func (r *Revid) processFrom(in device.AVDevice, delay time.Duration) {
defer r.wg.Done()
restart:
err := in.Start()
if err != nil {
r.err <- fmt.Errorf("could not start input device: %w", err)
return
}
for l := true; l; l = r.cfg.Loop {
err := in.Start()
if err != nil {
r.err <- fmt.Errorf("could not start input device: %w", err)
return
}
// Lex data from input device, in, until finished or an error is encountered.
// For a continuous source e.g. a camera or microphone, we should remain
// in this call indefinitely unless in.Stop() is called and an io.EOF is forced.
r.cfg.Logger.Log(logger.Info, pkg+"lexing")
err = r.lexTo(r.filters[0], in, delay)
switch err {
case nil, io.EOF, io.ErrUnexpectedEOF:
default:
r.err <- err
}
// Lex data from input device, in, until finished or an error is encountered.
// For a continuous source e.g. a camera or microphone, we should remain
// in this call indefinitely unless in.Stop() is called and an io.EOF is forced.
r.cfg.Logger.Log(logger.Info, pkg+"lexing")
err = r.lexTo(r.filters[0], in, delay)
switch err {
case nil, io.EOF, io.ErrUnexpectedEOF:
default:
r.err <- err
}
err = in.Stop()
if err != nil {
r.err <- fmt.Errorf("could not stop input source: %w", err)
}
if r.cfg.Loop {
r.cfg.Logger.Log(logger.Info, pkg+"looping input")
goto restart
err = in.Stop()
if err != nil {
r.err <- fmt.Errorf("could not stop input source: %w", err)
}
}
r.cfg.Logger.Log(logger.Info, pkg+"finished lexing")