mirror of
https://github.com/taigrr/vidnumerator.git
synced 2026-04-01 20:58:51 -07:00
feat: add tests, fix typo, extract magic number, bump deps
- Add 6 tests covering nil receiver, invalid fd, invalid path, regular file, device enumeration, and capability constant - Fix typo: fileDesciptor -> fileDescriptor - Extract magic number 69206017 into V4L2CapVideoCapture constant - Bump golang.org/x/sys v0.41.0 -> v0.42.0 - Bump Go 1.26.0 -> 1.26.1 - Add staticcheck to CI workflow
This commit is contained in:
@@ -28,6 +28,10 @@ const (
|
||||
(uintptr('V') << IOCTypeShift) |
|
||||
(0 << IOCNrShift) |
|
||||
(unsafe.Sizeof(cap{}) << IOCSizeShift)
|
||||
|
||||
// V4L2CapVideoCapture is the device capability flag indicating
|
||||
// the device supports video capture (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS).
|
||||
V4L2CapVideoCapture uint32 = 69206017
|
||||
)
|
||||
|
||||
type cap struct {
|
||||
@@ -40,13 +44,13 @@ type cap struct {
|
||||
reserved [3]uint32
|
||||
}
|
||||
|
||||
func (r *cap) QueryFd(fileDesciptor int) error {
|
||||
func (r *cap) QueryFd(fileDescriptor int) error {
|
||||
if r == nil {
|
||||
return fmt.Errorf("nil receiver")
|
||||
}
|
||||
_, _, errorNumber := unix.Syscall(
|
||||
unix.SYS_IOCTL,
|
||||
uintptr(fileDesciptor),
|
||||
uintptr(fileDescriptor),
|
||||
VidIOCQueryCap,
|
||||
uintptr(unsafe.Pointer(r)),
|
||||
)
|
||||
@@ -68,7 +72,7 @@ func IsVideoCapture(path string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return ic.deviceCaps == 69206017, nil
|
||||
return ic.deviceCaps == V4L2CapVideoCapture, nil
|
||||
}
|
||||
|
||||
// this function checks the ioctl for VIDIOC_QUERYCAP to see if the device is a video capture device
|
||||
|
||||
Reference in New Issue
Block a user