From 5c5672486ebd57bf8cec62d37f7c308edcc77a8d Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 30 Jan 2020 11:21:39 +1030 Subject: [PATCH] device/webcam: implement IsRunning method for webcam --- device/webcam/webcam.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/device/webcam/webcam.go b/device/webcam/webcam.go index 96780376..583a8158 100644 --- a/device/webcam/webcam.go +++ b/device/webcam/webcam.go @@ -62,11 +62,12 @@ var ( // Webcam is an implementation of the AVDevice interface for a Webcam. Webcam // uses an ffmpeg process to pipe the video data from the webcam. type Webcam struct { - out io.ReadCloser - log config.Logger - cfg config.Config - cmd *exec.Cmd - done chan struct{} + out io.ReadCloser + log config.Logger + cfg config.Config + cmd *exec.Cmd + done chan struct{} + isRunning bool } // New returns a new Webcam. @@ -161,6 +162,8 @@ func (w *Webcam) Start() error { return fmt.Errorf("could not pipe command error: %w", err) } + w.isRunning = true + go func() { for { select { @@ -202,7 +205,12 @@ func (w *Webcam) Stop() error { if err != nil { return fmt.Errorf("could not kill ffmpeg process: %w", err) } - return w.out.Close() + err = 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. @@ -215,6 +223,5 @@ func (w *Webcam) Read(p []byte) (int, error) { // IsRunning is used to determine if the webcam is running. func (w *Webcam) IsRunning() bool { - panic("not implemented") - return false + return w.isRunning }