mirror of
https://github.com/taigrr/vidnumerator.git
synced 2026-04-01 20:58:51 -07:00
add second function call
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
# VidNumerator
|
# VidNumerator
|
||||||
|
|
||||||
This is a tiny library that only exports one function: `EnumerateVideoDevices`.
|
This is a tiny library that uses syscalls to efficiently determine which `/dev/videoN` devices
|
||||||
This function uses syscalls to efficiently determine which `/dev/videoN` devices
|
|
||||||
are webcams and which are the additional metadata control handles.
|
are webcams and which are the additional metadata control handles.
|
||||||
The list of strings returned are the full filepaths to valid devices.
|
The list of strings returned are the full filepaths to valid devices.
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,21 @@ func (r *cap) QueryFd(fileDesciptor int) error {
|
|||||||
return nil
|
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
|
// this function checks the ioctl for VIDIOC_QUERYCAP to see if the device is a video capture device
|
||||||
func EnumeratedVideoDevices() []string {
|
func EnumeratedVideoDevices() []string {
|
||||||
// list all files in the /dev directory
|
// list all files in the /dev directory
|
||||||
@@ -74,17 +89,7 @@ func EnumeratedVideoDevices() []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fname = filepath.Join("/dev/", fname)
|
fname = filepath.Join("/dev/", fname)
|
||||||
f, err := os.OpenFile(fname, os.O_RDONLY, 0o755)
|
if isVidCap, _ := IsVideoCapture(fname); isVidCap {
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fd := f.Fd()
|
|
||||||
ic := cap{}
|
|
||||||
err = ic.QueryFd(int(fd))
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if ic.deviceCaps == 69206017 {
|
|
||||||
devNames = append(devNames, fname)
|
devNames = append(devNames, fname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user