/
camera.reds
98 lines (90 loc) · 1.64 KB
/
camera.reds
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
Red/System [
Title: "camera device"
Author: "bitbegin"
File: %camera.reds
Tabs: 4
Rights: "Copyright (C) 2020 Red Foundation. All rights reserved."
License: {
Distributed under the Boost Software License, Version 1.0.
See https://github.com/red/red/blob/master/BSL-License.txt
}
]
camera: context [
#include %v4l2.reds
open: func [
name [c-string!]
w [integer!]
h [integer!]
cfg [int-ptr!]
return: [logic!]
/local
config [v4l2-config!]
hr [integer!]
][
config: as v4l2-config! allocate size? v4l2-config!
cfg/1: as integer! config
config/name: name
config/width: w
config/height: h
hr: v4l2/open config
if hr = 0 [return true]
free as byte-ptr! config
cfg/1: 0
false
]
close: func [
cfg [integer!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
v4l2/close config
free as byte-ptr! cfg
]
attach: func [
cfg [integer!]
widget [int-ptr!]
cb [int-ptr!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
v4l2/attach config widget cb
]
start: func [
cfg [integer!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
v4l2/start config
]
get-data: func [
cfg [integer!]
data [int-ptr!]
dlen [int-ptr!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
data/1: as integer! config/buffer
dlen/1: config/bused
]
trylock: func [
cfg [integer!]
return: [integer!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
v4l2/trylock config
]
unlock: func [
cfg [integer!]
/local
config [v4l2-config!]
][
config: as v4l2-config! cfg
v4l2/unlock config
]
]