From 2f85dbcdf63e6d890712bba54fa7644e4ad467da Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 3 Feb 2020 15:24:30 +1030 Subject: [PATCH] device/webcam: don't close closed chan --- device/webcam/webcam.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/device/webcam/webcam.go b/device/webcam/webcam.go index 583a8158..bb41b7cf 100644 --- a/device/webcam/webcam.go +++ b/device/webcam/webcam.go @@ -197,6 +197,10 @@ func (w *Webcam) Start() error { // Stop will kill the ffmpeg process and close the output pipe. func (w *Webcam) Stop() error { + if !w.isRunning { + return nil + } + w.isRunning = false close(w.done) if w.cmd == nil || w.cmd.Process == nil { return errors.New("ffmpeg process was never started") @@ -205,12 +209,7 @@ func (w *Webcam) Stop() error { if err != nil { return fmt.Errorf("could not kill ffmpeg process: %w", err) } - err = w.out.Close() - if err == nil { - w.isRunning = false - return nil - } - return err + return w.out.Close() } // Read implements io.Reader. If the pipe is nil a read error is returned.