Merged in webcam-bang (pull request #369)

device/webcam: don't close closed chan

Approved-by: Saxon Milton <saxon.milton@gmail.com>
Approved-by: Scott Barnard <scott@ausocean.org>
This commit is contained in:
kortschak 2020-02-06 04:36:09 +00:00
commit 4e60728a0f
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. // Stop will kill the ffmpeg process and close the output pipe.
func (w *Webcam) Stop() error { func (w *Webcam) Stop() error {
if !w.isRunning {
return nil
}
w.isRunning = false
close(w.done) close(w.done)
if w.cmd == nil || w.cmd.Process == nil { if w.cmd == nil || w.cmd.Process == nil {
return errors.New("ffmpeg process was never started") return errors.New("ffmpeg process was never started")
@ -205,12 +209,7 @@ func (w *Webcam) Stop() error {
if err != nil { if err != nil {
return fmt.Errorf("could not kill ffmpeg process: %w", err) return fmt.Errorf("could not kill ffmpeg process: %w", err)
} }
err = w.out.Close() return w.out.Close()
if err == nil {
w.isRunning = false
return nil
}
return err
} }
// Read implements io.Reader. If the pipe is nil a read error is returned. // Read implements io.Reader. If the pipe is nil a read error is returned.