3 (defclass v4l2
(standard-class) ())
5 (defmethod validate-superclass ((obj v4l2
) (obj1 standard-class
)) t
)
7 (defmacro define-wrapper
(class-and-type supers
&optional slots
)
8 (destructuring-bind (class-name &optional
(struct-type class-name
))
9 (cffi::ensure-list class-and-type
)
10 (let ((slots (or slots
(cffi::foreign-slot-names struct-type
))))
12 (defclass ,class-name
,supers
13 (,@(loop for slot in slots collect
15 (raw :accessor
,(cffi::format-symbol t
"~A-RAW" class-name
)))
18 ,@(loop for slot in slots
19 for slot-name
= (cffi::format-symbol t
"~A-~A" class-name slot
)
20 for slot-type
= (cffi::slot-type
(cffi::get-slot-info class-name slot
))
22 `(defun ,slot-name
(inst)
23 ,(if (or (eq slot-type
:char
) (eq slot-type
:uchar
))
24 `(cffi:convert-from-foreign
25 (cffi:foreign-slot-value
(slot-value inst
'raw
) ',class-name
',slot
) :string
)
26 (if (cffi::aggregatep
(cffi::parse-type slot-type
))
27 `(make-instance ',slot-type
28 :pointer
(cffi:foreign-slot-value
(slot-value inst
'raw
) ',class-name
',slot
))
29 `(cffi:foreign-slot-value
(slot-value inst
'raw
) ',class-name
',slot
))))
31 `(defun (setf ,slot-name
) (new inst
)
32 (let ((raw (slot-value inst
'raw
)))
33 (setf (cffi:foreign-slot-value raw
',class-name
',slot
)
34 (cffi:convert-to-foreign new
',slot-type
)))))
36 (defmethod slot-value-using-class ((class v4l2
) inst slot
)
37 (if (string= (string-upcase (slot-definition-name slot
)) "RAW")
38 (call-next-method class inst
)
39 (funcall (symbol-function
40 (cffi::format-symbol t
"~A-~A"
42 (slot-definition-name slot
)))
45 (defmethod (setf slot-value-using-class
) (new (class v4l2
) inst slot
)
46 (let ((slot-name (string-upcase (slot-definition-name slot
))))
47 (if (string= slot-name
"RAW")
48 (call-next-method new class inst
)
50 (read-from-string (format nil
"(SETF ~A-~A)"
55 (defmethod initialize-instance :after
((inst ,class-name
) &key pointer
)
56 (let ((obj (or pointer
(cffi:foreign-alloc
',class-name
))))
57 (setf (slot-value inst
'raw
) obj
)
59 (tg:finalize inst
(lambda ()
60 (format t
"finalize ~A~%" obj
)
61 (foreign-free obj
))))))
64 (defmacro def-c-struct
(name &rest args
)
68 (define-wrapper ,name
())))
70 (defmacro def-c-union
(name &rest args
)
74 (define-wrapper ,name
())))
76 (def-c-struct v4l2-capability
77 (driver :uchar
:count
16)
78 (card :uchar
:count
32)
79 (bus-info :uchar
:count
32)
81 (capabilities :uint32
)
82 (reserved :uint32
:count
4))
84 (def-c-struct v4l2-fract
86 (denominator :uint32
))
88 (def-c-struct v4l2-captureparm
89 (capability :uint32
) ; Supported modes
90 (capturemode :uint32
) ; Current mode
91 (timeperframe v4l2-fract
) ; Time per frame in .1us units
92 (extendedmode :uint32
) ; Driver-specific extensions
93 (readbuffers :uint32
) ; # of buffers for read
94 (reserved :uint32
:count
4))
96 (def-c-struct v4l2-outputparm
97 (capability :uint32
) ; Supported modes
98 (outputmode :uint32
) ; Current mode
99 (timeperframe v4l2-fract
) ; Time per frame in .1us units
100 (extendedmode :uint32
) ; Driver-specific extensions
101 (writebuffers :uint32
) ; # of buffers for write
102 (reserved :uint32
:count
4))
104 (def-c-union v4l2-streamparm-union
105 (capture v4l2-captureparm
)
106 (output v4l2-outputparm
)
107 (raw-data :uchar
:count
200))
109 (defcenum v4l2-buf-type
110 (:buf-type-video-capture
1)
111 :buf-type-video-output
112 :buf-type-video-overlay
113 :buf-type-vbi-capture
115 :buf-type-sliced-vbi-capture
116 :buf-type-sliced-vbi-output
117 :buf-type-video-output-overlay
)
119 (def-c-struct v4l2-streamparm
121 (parm v4l2-streamparm-union
))
123 (defcenum v4l2-tuner-type
128 (def-c-struct v4l2-tuner
130 (name :uchar
:count
32)
131 (type v4l2-tuner-type
)
139 (reserved :uint32
:count
4))
141 (def-c-struct v4l2-standard
144 (name :uchar
:count
24)
145 (frameperiod v4l2-fract
)
147 (reserved :uint32
:count
4))
149 (def-c-struct v4l2-input
150 (index :uint32
) ; Which input
151 (name :uchar
:count
32) ; Label
152 (type :uint32
) ; Type of input
153 (audioset :uint32
) ; Associated audios (bitfield)
154 (tuner :uint32
) ; Associated tuner
157 (reserved :uint32
:count
4))
160 ;; F O R M A T E N U M E R A T I O N
162 (def-c-struct v4l2-fmtdesc
163 (index :uint32
) ; Format number
164 (type v4l2-buf-type
) ; buffer type
166 (description :uchar
:count
32) ; Description string
167 (pixelformat :uint32
) ; Format fourcc
168 (reserved :uint32
:count
4))
170 ;; Values for the 'type' field
171 (defconstant v4l2-input-type-tuner
1)
173 (defconstant v4l2-input-type-camera
2)
176 :field-any
; driver can choose from none
177 ; top, bottom, interlaced
178 ; depending on whatever it thinks
180 :field-none
; this device has no fields ...
181 :field-top
; top field only
182 :field-bottom
; bottom field only
183 :field-interlaced
; both fields interlaced
184 :field-seq-tb
; both fields sequential into one
185 ; buffer, top-bottom order
186 :field-seq-bt
; same as above + bottom-top order
187 :field-alternate
; both fields alternating into
189 :field-interlaced-tb
; both fields interlaced, top field
190 ; first and the top field is
192 :field-interlaced-bt
; both fields interlaced, top field
193 ; first and the bottom field is
197 (defcenum v4l2-colorspace
198 (:colorspace-smpte170m
1) ; ITU-R 601 -- broadcast NTSC/PAL
199 :colorspace_smpte240m
; 1125-Line (US) HDTV
200 :colorspace-rec709
; HD and modern captures.
201 ; broken BT878 extents (601, luma range 16-253 instead of 16-235)
203 ; These should be useful. Assume 601 extents.
204 :colorspace-470-system-m
205 :colorspace-470-system-bg
207 ; I know there will be cameras that send this. So, this is
208 ; unspecified chromaticities and full 0-255 on each of the
212 ; For RGB colourspaces, this is probably a good start.
216 ;; V I D E O I M A G E F O R M A T
218 (def-c-struct v4l2-pix-format
221 (pixelformat :uint32
)
223 (bytesperline :uint32
) ; for padding, zero if unused
225 (colorspace v4l2-colorspace
)
226 (priv :uint32
)) ; private data, depends on pixelformat
228 ;; Stream data format
231 (def-c-struct v4l2-timecode
238 (userbits :uchar
:count
4))
240 (defcenum v4l2-memory
245 ;; M E M O R Y - M A P P I N G B U F F E R S
247 (def-c-struct v4l2-requestbuffers
251 (reserved :uint32
:count
2))
253 (def-c-union v4l2-buffer-union
257 (def-c-struct v4l2-buffer
264 (timecode v4l2-timecode
)
268 (m v4l2-buffer-union
)
273 (defcenum v4l2-ctrl-type
274 (:ctrl-type-integer
1)
279 :ctrl-type-ctrl-class
)
281 ;; Used in the VIDIOC_QUERYCTRL ioctl for querying controls
282 (def-c-struct v4l2-queryctrl
284 (type v4l2-ctrl-type
)
285 (name :uchar
:count
32)
289 (default-value :int32
)
291 (reserved :uint32
:count
2))
293 (def-c-struct v4l2-control
297 (defcenum v4l2-power-line-frequency
298 :cid-power-line-frequency-disabled
299 :cid-power-line-frequency-50hz
300 :cid-power-line-frequency-60hz
)
302 (defcenum v4l2-colorfx
307 (defcenum v4l2-exposure-auto-type
310 :exposure-shutter-priority
311 :exposure-aperture-priority
)