diff --git a/v4l2.go b/v4l2.go index 79dc65d..03083a8 100644 --- a/v4l2.go +++ b/v4l2.go @@ -499,7 +499,7 @@ func mmapQueryBuffer(fd uintptr, index uint32, length *uint32) (buffer []byte, e *length = req.length - buffer, err = unix.Mmap(int(fd), int64(offset), int(req.length), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED) + buffer, err = unix.Mmap(int(fd), int64(offset), int(req.length), unix.PROT_READ, unix.MAP_SHARED) return } diff --git a/webcam.go b/webcam.go index cc3adfa..e008410 100644 --- a/webcam.go +++ b/webcam.go @@ -5,6 +5,7 @@ package webcam import ( "errors" + "fmt" "reflect" "unsafe" @@ -35,12 +36,14 @@ type Control struct { // capable to stream video func Open(path string) (*Webcam, error) { - handle, err := unix.Open(path, unix.O_RDWR|unix.O_NONBLOCK, 0666) - fd := uintptr(handle) - - if fd < 0 || err != nil { + handle, err := unix.Open(path, unix.O_RDONLY|unix.O_NONBLOCK, 0666) + if err != nil { return nil, err } + if handle < 0 { + return nil, fmt.Errorf("failed to open %v", path) + } + fd := uintptr(handle) supportsVideoCapture, supportsVideoStreaming, err := checkCapabilities(fd)