mirror of https://bitbucket.org/ausocean/av.git
device/webcam: implement IsRunning method for webcam
This commit is contained in:
parent
f1d1fe2cad
commit
5c5672486e
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue