5 Commits

Author SHA1 Message Date
2aebf3fc21 ci: add GitHub Actions test workflow 2026-02-23 18:07:27 +00:00
7e00ee78f0 chore(deps): update Go 1.20->1.26, update golang.org/x/sys 2026-02-23 18:07:27 +00:00
9541c767b4 update readme 2025-05-01 18:37:07 -07:00
46bae05250 Update README.md 2024-06-01 19:05:25 -07:00
65d6740d47 Update README.md 2024-06-01 19:04:48 -07:00
5 changed files with 50 additions and 5 deletions

17
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: Test
on:
push:
branches: [master]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go test -race ./...
- run: go vet ./...
- run: go build ./...

View File

@@ -1,4 +1,4 @@
Copyright (C) 2023 by Tai Groot <tai@taigrr.com>
Copyright (C) 2023-2025 by Tai Groot <tai@taigrr.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

View File

@@ -4,3 +4,31 @@ This is a tiny library that uses syscalls to efficiently determine which `/dev/v
are webcams and which are the additional metadata control handles.
The list of strings returned are the full filepaths to valid devices.
>[!IMPORTANT]
>In order for this library to work properly, the executing user must have either root or video group privileges
## Technical Details
The library works by:
1. Scanning `/dev` for files matching the pattern `video*`
2. Using the `VIDIOC_QUERYCAP` ioctl to check if each device is a video capture device
3. Filtering out non-capture devices (like metadata control handles)
The core functionality is implemented through direct syscalls to the Linux kernel's V4L2 (Video4Linux2) API. The library uses the `VIDIOC_QUERYCAP` ioctl command to query device capabilities and determine if a device supports video capture.
## Usage
```go
devices, err := vidnumerator.EnumeratedVideoDevices()
if err != nil {
// handle error
}
// devices will contain paths like "/dev/video0", "/dev/video2", etc.
```
## Implementation Notes
- Uses direct syscalls via `golang.org/x/sys/unix`
- Implements custom ioctl constants for V4L2 device querying
- Checks for specific device capabilities (0x4200001) to identify capture devices

4
go.mod
View File

@@ -1,5 +1,5 @@
module github.com/taigrr/vidnumerator
go 1.20
go 1.26.0
require golang.org/x/sys v0.9.0
require golang.org/x/sys v0.41.0

4
go.sum
View File

@@ -1,2 +1,2 @@
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=