Repository navigation
feat(auth): fall back to direct V4L2 capture for devices libcamera does not list - #237
Merged
Merged
Conversation
…es not list libcamera does not list V4L2-only devices (custom DKMS drivers such as gc2607, v4l2loopback), so an explicit /dev/videoN for them failed since 1.4.0. When an explicit path is not a libcamera camera, open it with a new V4l2CaptureSession (kernel headers only: QUERYCAP, ENUM_FMT/FRAMESIZES, S_FMT, 4 mmap buffers, poll). It reuses the libcamera path's format preference, size cap, warmup and IR brightest-of-N rules, and fails closed. Auto-select stays libcamera-only. listCameraFormats gets the same fallback. meanLuma moves to capture_policy and kMaxDroppedFrames to frame_sampling.h so both sessions share them. Refs #142 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The helper runs as root and opens the configured camera path, so the V4L2 fallback could open any node, e.g. /dev/watchdog, whose open has side effects. openDevice now pins the path with O_PATH, requires a char device with the V4L2 major (81), reopens that same inode via /proc/self/fd with O_NOCTTY and checks st_rdev again, so a swapped symlink cannot redirect it. Stepwise/continuous frame sizes are no longer taken at their max (v4l2loopback without a producer offers 8192x8192): the format's cap is clamped into the range on its step grid. REQBUFS granting no buffers is logged on its own instead of with a stale errno. Refs #142 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since 1.4.0 capture goes through libcamera, which does not list V4L2-only devices: custom DKMS drivers such as gc2607, and v4l2loopback (#142). openpnp-capture used to open any node that reported
V4L2_CAP_VIDEO_CAPTURE. This PR adds a direct V4L2 capture session, used only when the configured camera path is not a libcamera device.Closes #142
Changes
openDevicefirst)V4l2CaptureSession(auth/face/common/v4l2_capture.{h,cc}), built on kernel headers only.poll()against the capture deadline.V4L2_BUF_FLAG_ERROR, treatENODEVas a disconnect.openDevice(the helper runs as root): open withO_PATH(no driver call),fstat, require a char device with major 81 (VIDEO_MAJOR), then reopen through/proc/self/fd/NwithO_RDWR|O_NONBLOCK|O_CLOEXEC|O_NOCTTYand re-checkst_rdev. A config path such as/dev/watchdogis never opened.pickCaptureSizeInRange). v4l2loopback's 8192x8192 range gives 640x480 (1280x720 for MJPEG).openCameraSession: when an explicit path is not found by libcamera, log at info level and try V4L2. Auto-select stays libcamera-only.listCameraFormatsfalls back the same way.meanLumamoved tocapture_policy,kMaxDroppedFramestoframe_sampling.h.docs/IR camera.mdmentions the fallback.v4l2_capture: fourcc mapping, format choice, bytes-per-line fallback, video char device check (watchdog, block device,/dev/nullrejected).capture_policy: size range cases,meanLuma.Verification
A temporary harness (not committed) drove
V4l2CaptureSessiondirectly:/dev/video0colour/dev/video2grey/dev/null, a symlink to it,/tmp/dev/video0Manual testing:
.deb/.rpm/AUR/source)Not tested:
Review report
O_RDWR, e.g./dev/watchdog, which lets a user reboot the machine. Fixed withO_PATH+ major 81 +/proc/self/fdreopen.--list-formatsshows a range as min and max sizes. Dismissed: display only, in the debug tool.auth/faceonly). The root open was covered in the code review.Risk
What could break, and for whom: only users whose configured camera is not a libcamera device. They used to fail every time; now they capture through V4L2. The helper runs as root, so it opens V4L2 nodes on their behalf, but only nodes with the video major.
How to revert
git revertis enough. No config or packaging change.Checklist
🤖 Generated with Claude Code