device/webcam: don't close closed chan

This commit is contained in:
Dan Kortschak 2020-02-03 15:24:30 +10:30
parent 0dfb2df939
commit 2f85dbcdf6
1 changed files with 5 additions and 6 deletions

View File

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