device/webcam: implement IsRunning method for webcam

This commit is contained in:
Scott 2020-01-30 11:21:39 +10:30
parent f1d1fe2cad
commit 5c5672486e
1 changed files with 15 additions and 8 deletions

View File

@ -67,6 +67,7 @@ type Webcam struct {
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
}