Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Webcam struct {
bufcount uint32
buffers [][]byte
streaming bool
closed bool
pollFds []unix.PollFd
}

Expand Down Expand Up @@ -333,13 +334,19 @@ func (w *Webcam) StopStreaming() error {
return stopStreaming(w.fd)
}

// Close the device
// Close the device. Calling Close more than once returns nil; the
// underlying file descriptor is only released on the first call so
// the kernel can't hand it to unrelated code in the meantime.
func (w *Webcam) Close() error {
if w.closed {
return nil
}
if w.streaming {
w.StopStreaming()
}

err := unix.Close(int(w.fd))
w.closed = true

return err
}
Expand Down