add second function call

This commit is contained in:
2023-06-27 16:09:07 -07:00
parent 5d726183d5
commit 210ae73aa7
2 changed files with 17 additions and 13 deletions

View File

@@ -1,7 +1,6 @@
# VidNumerator
This is a tiny library that only exports one function: `EnumerateVideoDevices`.
This function uses syscalls to efficiently determine which `/dev/videoN` devices
This is a tiny library that uses syscalls to efficiently determine which `/dev/videoN` devices
are webcams and which are the additional metadata control handles.
The list of strings returned are the full filepaths to valid devices.

View File

@@ -56,6 +56,21 @@ func (r *cap) QueryFd(fileDesciptor int) error {
return nil
}
// this function checks the ioctl for VIDIOC_QUERYCAP to see if the device is a video capture device
func IsVideoCapture(path string) (bool, error) {
f, err := os.OpenFile(path, os.O_RDONLY, 0o755)
if err != nil {
return false, err
}
fd := f.Fd()
ic := cap{}
err = ic.QueryFd(int(fd))
if err != nil {
return false, err
}
return ic.deviceCaps == 69206017, nil
}
// this function checks the ioctl for VIDIOC_QUERYCAP to see if the device is a video capture device
func EnumeratedVideoDevices() []string {
// list all files in the /dev directory
@@ -74,17 +89,7 @@ func EnumeratedVideoDevices() []string {
continue
}
fname = filepath.Join("/dev/", fname)
f, err := os.OpenFile(fname, os.O_RDONLY, 0o755)
if err != nil {
continue
}
fd := f.Fd()
ic := cap{}
err = ic.QueryFd(int(fd))
if err != nil {
continue
}
if ic.deviceCaps == 69206017 {
if isVidCap, _ := IsVideoCapture(fname); isVidCap {
devNames = append(devNames, fname)
}
}