blackjack / webcam

Golang webcam library for Linux
MIT License
416 stars 92 forks source link

Changed how the linux v4l2 file is opened #66

Closed bpstark closed 7 months ago

bpstark commented 7 months ago

open the file as read only. ioctl does not require files to be open for writing, and capturing a frame should be done read only. This should prevent blocking other processes including the camera produce in cases where the v4l2 device is actually a loopback device.

Additionally fixed error handling around file opening to check for negative value prior to casting to unsigned.

edaniels commented 7 months ago

Thank you @bpstark!

edaniels commented 7 months ago

@bpstark what kind of manual testing did you do?

bpstark commented 7 months ago

@edaniels I tested this using an application I am working on for streaming video, which uses pion and pion/mediadevices. I found the issue while trying to stream a v4l2 loopback device, which would sometimes fail due to syscall.EBUSY which was because the v4l2 device was being written to by the loopback driver. After going through https://github.com/pion/mediadevices I was able to isolate the issue to this package, when trying to open the file v4l2 file. Looking through how the file was being used I was able to determine that there was no need to open with write, and confirmed that by making this change and using the go.mod replace to test the change within my application. I was able to easily confirm that I can now read v4l2 device without any issues or contention from writers.

edaniels commented 7 months ago

Okay great, thank you for explaining/testing.