mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00

Commits (Ingo Oppermann): - Add experimental SRT connection stats and logs - Hide /config/reload endpoint in reade-only mode - Add SRT server - Create v16 in go.mod - Fix data races, tests, lint, and update dependencies - Add trailing slash for routed directories (datarhei/restreamer#340) - Allow relative URLs in content in static routes Co-Authored-By: Ingo Oppermann <57445+ioppermann@users.noreply.github.com>
69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
package skills
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"os/exec"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// DevicesV4L returns a list of available V4L devices
|
|
func DevicesV4L() ([]HWDevice, error) {
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
cmd := exec.Command("v4l2-ctl", "--list-devices")
|
|
cmd.Env = []string{}
|
|
cmd.Stdout = buf
|
|
cmd.Run()
|
|
|
|
devices := parseV4LDevices(buf)
|
|
|
|
return devices, nil
|
|
}
|
|
|
|
func parseV4LDevices(data *bytes.Buffer) []HWDevice {
|
|
devices := []HWDevice{}
|
|
|
|
reName := regexp.MustCompile(`^(.*)\((.*?)\):$`)
|
|
reDevice := regexp.MustCompile(`/dev/video[0-9]+`)
|
|
|
|
name := ""
|
|
extra := ""
|
|
|
|
scanner := bufio.NewScanner(data)
|
|
scanner.Split(bufio.ScanLines)
|
|
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
|
|
matches := reDevice.FindStringSubmatch(line)
|
|
if matches == nil {
|
|
matches = reName.FindStringSubmatch(line)
|
|
if matches == nil {
|
|
continue
|
|
}
|
|
|
|
name = strings.TrimSpace(matches[1])
|
|
extra = matches[2]
|
|
|
|
continue
|
|
}
|
|
|
|
if name == "" {
|
|
continue
|
|
}
|
|
|
|
device := HWDevice{
|
|
Id: matches[0],
|
|
Name: name,
|
|
Extra: extra,
|
|
Media: "video",
|
|
}
|
|
|
|
devices = append(devices, device)
|
|
}
|
|
|
|
return devices
|
|
}
|