-
Notifications
You must be signed in to change notification settings - Fork 9
/
internal_capabilities.go
104 lines (80 loc) · 1.75 KB
/
internal_capabilities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package v4l2
import (
"golang.org/x/sys/unix"
"fmt"
"unsafe"
)
// internalCapability is used to receive the capabilities of a V4L2 (Video4Linux video 2) device.
//
// Example:
//
// device, err := v4l2.Open(v4l2.Video0)
//
// //...
//
// var cap internalCapability
//
// err := cap.Query(videoDevice)
//
// This is used internally of v4l2.Device
type internalCapability struct {
driver [16]uint8
card [32]uint8
busInfo [32]uint8
version uint32
capabilities uint32
deviceCaps uint32
reserved [3]uint32
}
func (receiver *internalCapability) QueryFd(fileDesciptor int) error {
if nil == receiver {
return errNilReceiver
}
_, _, errorNumber := unix.Syscall(
unix.SYS_IOCTL,
uintptr(fileDesciptor),
const_VIDIOC_QUERYCAP,
uintptr(unsafe.Pointer(receiver)),
)
if 0 != errorNumber {
return errorNumber
}
return nil
}
func (receiver internalCapability) BusInfo() string {
max := len(receiver.busInfo)
index := 0
for ; index < max; index++ {
if 0 == receiver.busInfo[index] {
break
}
}
return string(receiver.busInfo[:index])
}
func (receiver internalCapability) Card() string {
max := len(receiver.card)
index := 0
for ; index < max; index++ {
if 0 == receiver.card[index] {
break
}
}
return string(receiver.card[:index])
}
func (receiver internalCapability) Driver() string {
max := len(receiver.driver)
index := 0
for ; index < max; index++ {
if 0 == receiver.driver[index] {
break
}
}
return string(receiver.driver[:index])
}
func (receiver internalCapability) Version() string {
version := receiver.version
major := (version >> 16) & 0xFF
minor := (version >> 8) & 0xFF
patch := (version ) & 0xFF
return fmt.Sprintf("%d.%d.%d", major, minor, patch)
}