-
Notifications
You must be signed in to change notification settings - Fork 9
/
formatfamily_framesizes.go
115 lines (92 loc) · 2.33 KB
/
formatfamily_framesizes.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
105
106
107
108
109
110
111
112
113
114
115
package v4l2
import (
"github.com/reiver/go-v4l2/framesize"
"github.com/reiver/go-v4l2/pixelformat"
"golang.org/x/sys/unix"
"unsafe"
)
// FrameSizes returns an iterator that enables you to list out all the supported frame sizes by the format family.
func (receiver *FormatFamily) FrameSizes() (FrameSizes, error) {
if nil == receiver {
return FrameSizes{}, errNilReceiver
}
device := receiver.device
if nil == device {
return FrameSizes{}, errInternalError
}
if err := device.unfit(); nil != err {
return FrameSizes{}, err
}
return FrameSizes{
device: receiver.device,
pixelFormat: receiver.internal.pixelFormat,
}, nil
}
// FrameSizes is an interator that enables you to list out all the supported formats by the format family.
type FrameSizes struct {
device *Device
pixelFormat v4l2_pixelformat.Type
err error
datum v4l2_framesize.Type
}
// Close closes the FrameSizes iterator.
func (receiver *FrameSizes) Close() error {
if nil == receiver {
return nil
}
receiver.device = nil
receiver.err = nil
receiver.datum.Index = 0
return nil
}
// Decode loads the next frame size (previously obtained by calling Next).
func (receiver FrameSizes) Decode(x interface{}) error {
if nil != receiver.err {
return receiver.err
}
p, ok := x.(*v4l2_framesize.Type)
if !ok {
return errUnsupportedType
}
*p = receiver.datum
return nil
}
// Err returns any errors that occurred when Next was called.
func (receiver *FrameSizes) Err() error {
if nil == receiver {
return errNilReceiver
}
return receiver.err
}
// Next fetches the next frame size.
//
// If there is a next frame size, it returns true.
// And the next frame size get be obtained by calling Decode.
//
// If there is not next frame size, then it returns false.
func (receiver *FrameSizes) Next() bool {
if nil == receiver {
return false
}
device := receiver.device
if nil == device {
receiver.err = errInternalError
return false
}
receiver.datum.PixelFormat = receiver.pixelFormat
_, _, errorNumber := unix.Syscall(
unix.SYS_IOCTL,
uintptr(device.fileDescriptor),
const_VIDIOC_ENUM_FRAMESIZES,
uintptr(unsafe.Pointer(&receiver.datum)),
)
if unix.EINVAL == errorNumber {
return false
}
if 0 != errorNumber {
receiver.err = errorNumber
return false
}
receiver.datum.Index++
return true
}