From 64754f7e0f33a6ae37000ed732a4f70d9a2f2771 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 24 Jan 2020 21:25:27 +1030 Subject: [PATCH] revid: use loop in processFrom instead of goto --- revid/revid.go | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 7aca384e..3d9d26c5 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -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")