Debian Codegraph @

v4l.go

raw
1 // Package v4l, a facade to the Video4Linux video capture interface
2 // Copyright (C) 2016 Zoltán Korándi <[email protected]>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 //go:build linux
18 // +build linux
19
20 package v4l
21
22 import (
23 "syscall"
24 "unsafe"
25 )
26
27 // Constants.
28
29 const (
30 v4l_capVideoCapture = 0x00000001
31 v4l_capDeviceCaps = 0x80000000
32 )
33
34 const (
35 v4l_bufTypeVideoCapture = 1
36 )
37
38 const (
39 v4l_colorspaceDefault = 0
40 )
41
42 const (
43 v4l_fieldNone = 1
44 )
45
46 const (
47 v4l_memoryMmap = 1
48 )
49
50 const (
51 v4l_frmsizeTypeDiscrete = 1
52 v4l_frmsizeTypeContinuous = 2
53 v4l_frmsizeTypeStepwise = 3
54 )
55
56 const (
57 v4l_frmivalTypeDiscrete = 1
58 v4l_frmivalTypeContinuous = 2
59 v4l_frmivalTypeStepwise = 3
60 )
61
62 const (
63 v4l_ctrlFlagDisabled = 0x0001
64 v4l_ctrlFlagNextCtrl = 0x80000000
65 )
66
67 const (
68 v4l_ctrlTypeInteger = 1
69 v4l_ctrlTypeBoolean = 2
70 v4l_ctrlTypeMenu = 3
71 v4l_ctrlTypeButton = 4
72 v4l_ctrlTypeIntegerMenu = 9
73 )
74
75 const (
76 v4l_cidBase = 0x00980900
77 v4l_cidLastp1 = 0x0098092b
78 v4l_cidPrivateBase = 0x08000000
79 )
80
81 // Structs.
82
83 type v4l_capability struct {
84 driver string
85 card string
86 busInfo string
87 version uint32
88 capabilities uint32
89 deviceCaps uint32
90 }
91
92 type v4l_format_pix struct {
93 typ uint32
94 fmt v4l_pixFormat
95 }
96
97 type v4l_pixFormat struct {
98 width uint32
99 height uint32
100 pixelformat uint32
101 field uint32
102 bytesperline uint32
103 sizeimage uint32
104 colorspace uint32
105 priv uint32
106 flags uint32
107 ycbcrEnc uint32
108 quantization uint32
109 xferFunc uint32
110 }
111
112 type v4l_streamparm_capture struct {
113 typ uint32
114 parm v4l_captureparm
115 }
116
117 type v4l_captureparm struct {
118 capability uint32
119 capturemode uint32
120 timeperframe v4l_fract
121 extendedmode uint32
122 readbuffers uint32
123 }
124
125 type v4l_requestbuffers struct {
126 count uint32
127 typ uint32
128 memory uint32
129 }
130
131 type v4l_buffer struct {
132 index uint32
133 typ uint32
134 bytesused uint32
135 flags uint32
136 field uint32
137 timecode v4l_timecode
138 sequence uint32
139 memory uint32
140 offset uint32
141 length uint32
142 }
143
144 type v4l_int int32
145
146 type v4l_cropcap struct {
147 typ uint32
148 bounds v4l_rect
149 defrect v4l_rect
150 pixelaspect v4l_fract
151 }
152
153 type v4l_crop struct {
154 typ uint32
155 c v4l_rect
156 }
157
158 type v4l_fract struct {
159 numerator uint32
160 denominator uint32
161 }
162
163 type v4l_timecode struct {
164 typ uint32
165 flags uint32
166 frames uint8
167 seconds uint8
168 minutes uint8
169 hours uint8
170 userbits [4]uint8
171 }
172
173 type v4l_rect struct {
174 left int32
175 top int32
176 width uint32
177 height uint32
178 }
179
180 type v4l_standard struct {
181 index uint32
182 id uint64
183 name string
184 frameperiod v4l_fract
185 framelines uint32
186 }
187
188 type v4l_fmtdesc struct {
189 index uint32
190 typ uint32
191 flags uint32
192 description string
193 pixelformat uint32
194 }
195
196 type v4l_frmsizeenum struct {
197 index uint32
198 pixelFormat uint32
199 typ uint32
200 discrete v4l_frmsizeDiscrete
201 stepwise v4l_frmsizeStepwise
202 }
203
204 type v4l_frmsizeDiscrete struct {
205 width uint32
206 height uint32
207 }
208
209 type v4l_frmsizeStepwise struct {
210 minWidth uint32
211 maxWidth uint32
212 stepWidth uint32
213 minHeight uint32
214 maxHeight uint32
215 stepHeight uint32
216 }
217
218 type v4l_frmivalenum struct {
219 index uint32
220 pixelFormat uint32
221 width uint32
222 height uint32
223 typ uint32
224 discrete v4l_fract
225 stepwise v4l_frmivalStepwise
226 }
227
228 type v4l_frmivalStepwise struct {
229 min v4l_fract
230 max v4l_fract
231 step v4l_fract
232 }
233
234 type v4l_queryctrl struct {
235 id uint32
236 typ uint32
237 name string
238 minimum int32
239 maximum int32
240 step int32
241 defaultValue int32
242 flags uint32
243 }
244
245 type v4l_querymenu struct {
246 id uint32
247 index uint32
248 name string
249 value int64
250 }
251
252 type v4l_control struct {
253 id uint32
254 value int32
255 }
256
257 // IOCTLs.
258
259 func ioctl_querycap(fd int, argp *v4l_capability) error {
260 return ioctl(fd, vidioc_querycap, argp)
261 }
262
263 func ioctl_gFmt_pix(fd int, argp *v4l_format_pix) error {
264 return ioctl(fd, vidioc_gFmt, argp)
265 }
266
267 func ioctl_sFmt_pix(fd int, argp *v4l_format_pix) error {
268 return ioctl(fd, vidioc_sFmt, argp)
269 }
270
271 func ioctl_gParm_capture(fd int, argp *v4l_streamparm_capture) error {
272 return ioctl(fd, vidioc_gParm, argp)
273 }
274
275 func ioctl_sParm_capture(fd int, argp *v4l_streamparm_capture) error {
276 return ioctl(fd, vidioc_sParm, argp)
277 }
278
279 func ioctl_reqbufs(fd int, argp *v4l_requestbuffers) error {
280 return ioctl(fd, vidioc_reqbufs, argp)
281 }
282
283 func ioctl_querybuf(fd int, argp *v4l_buffer) error {
284 return ioctl(fd, vidioc_querybuf, argp)
285 }
286
287 func ioctl_qbuf(fd int, argp *v4l_buffer) error {
288 return ioctl(fd, vidioc_qbuf, argp)
289 }
290
291 func ioctl_dqbuf(fd int, argp *v4l_buffer) error {
292 return ioctl(fd, vidioc_dqbuf, argp)
293 }
294
295 func ioctl_streamon(fd int, typ v4l_int) error {
296 return ioctl(fd, vidioc_streamon, &typ)
297 }
298
299 func ioctl_streamoff(fd int, typ v4l_int) error {
300 return ioctl(fd, vidioc_streamoff, &typ)
301 }
302
303 func ioctl_cropcap(fd int, argp *v4l_cropcap) error {
304 return ioctl(fd, vidioc_cropcap, argp)
305 }
306
307 func ioctl_sCrop(fd int, argp *v4l_crop) error {
308 return ioctl(fd, vidioc_sCrop, argp)
309 }
310
311 func ioctl_enumstd(fd int, argp *v4l_standard) error {
312 return ioctl(fd, vidioc_enumstd, argp)
313 }
314
315 func ioctl_enumFmt(fd int, argp *v4l_fmtdesc) error {
316 return ioctl(fd, vidioc_enumFmt, argp)
317 }
318
319 func ioctl_enumFramesizes(fd int, argp *v4l_frmsizeenum) error {
320 return ioctl(fd, vidioc_enumFramesizes, argp)
321 }
322
323 func ioctl_enumFrameintervals(fd int, argp *v4l_frmivalenum) error {
324 return ioctl(fd, vidioc_enumFrameintervals, argp)
325 }
326
327 func ioctl_queryctrl(fd int, argp *v4l_queryctrl) error {
328 return ioctl(fd, vidioc_queryctrl, argp)
329 }
330
331 func ioctl_querymenu(fd int, argp *v4l_querymenu) error {
332 return ioctl(fd, vidioc_querymenu, argp)
333 }
334
335 func ioctl_gCtrl(fd int, argp *v4l_control) error {
336 return ioctl(fd, vidioc_gCtrl, argp)
337 }
338
339 func ioctl_sCtrl(fd int, argp *v4l_control) error {
340 return ioctl(fd, vidioc_sCtrl, argp)
341 }
342
343 func ioctl(fd int, request uint, argp ioctlArg) error {
344 buf := make([]uint64, (argp.size()+7)/8)
345 p := unsafe.Pointer(&buf[0])
346 argp.put(p)
347 _, _, err := syscall.Syscall(syscall.SYS_IOCTL,
348 uintptr(fd), uintptr(request), uintptr(p))
349 if err != 0 {
350 return err
351 }
352 argp.get(p)
353 return nil
354 }
355
356 // Getters and putters.
357
358 type ioctlArg interface {
359 get(unsafe.Pointer)
360 put(unsafe.Pointer)
361 size() int
362 }
363
364 func (p *v4l_capability) get(q unsafe.Pointer) {
365 p.driver = getString(q, offs_capability_driver, size_capability_driver)
366 p.card = getString(q, offs_capability_card, size_capability_card)
367 p.busInfo = getString(q, offs_capability_busInfo, size_capability_busInfo)
368 p.version = getUint32(q, offs_capability_version)
369 p.capabilities = getUint32(q, offs_capability_capabilities)
370 p.deviceCaps = getUint32(q, offs_capability_deviceCaps)
371 }
372
373 func (p *v4l_capability) put(q unsafe.Pointer) {
374 putString(q, offs_capability_driver, size_capability_driver, p.driver)
375 putString(q, offs_capability_card, size_capability_card, p.card)
376 putString(q, offs_capability_busInfo, size_capability_busInfo, p.busInfo)
377 putUint32(q, offs_capability_version, p.version)
378 putUint32(q, offs_capability_capabilities, p.capabilities)
379 putUint32(q, offs_capability_deviceCaps, p.deviceCaps)
380 }
381
382 func (p *v4l_capability) size() int {
383 return size_capability
384 }
385
386 func (p *v4l_format_pix) get(q unsafe.Pointer) {
387 p.typ = getUint32(q, offs_format_typ)
388 p.fmt.get(unsafe.Pointer(uintptr(q) + offs_format_fmt))
389 }
390
391 func (p *v4l_format_pix) put(q unsafe.Pointer) {
392 putUint32(q, offs_format_typ, p.typ)
393 p.fmt.put(unsafe.Pointer(uintptr(q) + offs_format_fmt))
394 }
395
396 func (p *v4l_format_pix) size() int {
397 return size_format
398 }
399
400 func (p *v4l_pixFormat) get(q unsafe.Pointer) {
401 p.width = getUint32(q, offs_pixFormat_width)
402 p.height = getUint32(q, offs_pixFormat_height)
403 p.pixelformat = getUint32(q, offs_pixFormat_pixelformat)
404 p.field = getUint32(q, offs_pixFormat_field)
405 p.bytesperline = getUint32(q, offs_pixFormat_bytesperline)
406 p.sizeimage = getUint32(q, offs_pixFormat_sizeimage)
407 p.colorspace = getUint32(q, offs_pixFormat_colorspace)
408 p.priv = getUint32(q, offs_pixFormat_priv)
409 p.flags = getUint32(q, offs_pixFormat_flags)
410 p.ycbcrEnc = getUint32(q, offs_pixFormat_ycbcrEnc)
411 p.quantization = getUint32(q, offs_pixFormat_quantization)
412 p.xferFunc = getUint32(q, offs_pixFormat_xferFunc)
413 }
414
415 func (p *v4l_pixFormat) put(q unsafe.Pointer) {
416 putUint32(q, offs_pixFormat_width, p.width)
417 putUint32(q, offs_pixFormat_height, p.height)
418 putUint32(q, offs_pixFormat_pixelformat, p.pixelformat)
419 putUint32(q, offs_pixFormat_field, p.field)
420 putUint32(q, offs_pixFormat_bytesperline, p.bytesperline)
421 putUint32(q, offs_pixFormat_sizeimage, p.sizeimage)
422 putUint32(q, offs_pixFormat_colorspace, p.colorspace)
423 putUint32(q, offs_pixFormat_priv, p.priv)
424 putUint32(q, offs_pixFormat_flags, p.flags)
425 putUint32(q, offs_pixFormat_ycbcrEnc, p.ycbcrEnc)
426 putUint32(q, offs_pixFormat_quantization, p.quantization)
427 putUint32(q, offs_pixFormat_xferFunc, p.xferFunc)
428 }
429
430 func (p *v4l_streamparm_capture) get(q unsafe.Pointer) {
431 p.typ = getUint32(q, offs_streamparm_typ)
432 p.parm.get(unsafe.Pointer(uintptr(q) + offs_streamparm_parm))
433 }
434
435 func (p *v4l_streamparm_capture) put(q unsafe.Pointer) {
436 putUint32(q, offs_streamparm_typ, p.typ)
437 p.parm.put(unsafe.Pointer(uintptr(q) + offs_streamparm_parm))
438 }
439
440 func (p *v4l_streamparm_capture) size() int {
441 return size_streamparm
442 }
443
444 func (p *v4l_captureparm) get(q unsafe.Pointer) {
445 p.capability = getUint32(q, offs_captureparm_capability)
446 p.capturemode = getUint32(q, offs_captureparm_capturemode)
447 p.timeperframe.get(unsafe.Pointer(uintptr(q) + offs_captureparm_timeperframe))
448 p.extendedmode = getUint32(q, offs_captureparm_extendedmode)
449 p.readbuffers = getUint32(q, offs_captureparm_readbuffers)
450 }
451
452 func (p *v4l_captureparm) put(q unsafe.Pointer) {
453 putUint32(q, offs_captureparm_capability, p.capability)
454 putUint32(q, offs_captureparm_capturemode, p.capturemode)
455 p.timeperframe.put(unsafe.Pointer(uintptr(q) + offs_captureparm_timeperframe))
456 putUint32(q, offs_captureparm_extendedmode, p.extendedmode)
457 putUint32(q, offs_captureparm_readbuffers, p.readbuffers)
458 }
459
460 func (p *v4l_requestbuffers) get(q unsafe.Pointer) {
461 p.count = getUint32(q, offs_requestbuffers_count)
462 p.typ = getUint32(q, offs_requestbuffers_typ)
463 p.memory = getUint32(q, offs_requestbuffers_memory)
464 }
465
466 func (p *v4l_requestbuffers) put(q unsafe.Pointer) {
467 putUint32(q, offs_requestbuffers_count, p.count)
468 putUint32(q, offs_requestbuffers_typ, p.typ)
469 putUint32(q, offs_requestbuffers_memory, p.memory)
470 }
471
472 func (p *v4l_requestbuffers) size() int {
473 return size_requestbuffers
474 }
475
476 func (p *v4l_buffer) get(q unsafe.Pointer) {
477 p.index = getUint32(q, offs_buffer_index)
478 p.typ = getUint32(q, offs_buffer_typ)
479 p.bytesused = getUint32(q, offs_buffer_bytesused)
480 p.flags = getUint32(q, offs_buffer_flags)
481 p.field = getUint32(q, offs_buffer_field)
482 p.timecode.get(unsafe.Pointer(uintptr(q) + offs_buffer_timecode))
483 p.sequence = getUint32(q, offs_buffer_sequence)
484 p.memory = getUint32(q, offs_buffer_memory)
485 p.offset = getUint32(q, offs_buffer_offset)
486 p.length = getUint32(q, offs_buffer_length)
487 }
488
489 func (p *v4l_buffer) put(q unsafe.Pointer) {
490 putUint32(q, offs_buffer_index, p.index)
491 putUint32(q, offs_buffer_typ, p.typ)
492 putUint32(q, offs_buffer_bytesused, p.bytesused)
493 putUint32(q, offs_buffer_flags, p.flags)
494 putUint32(q, offs_buffer_field, p.field)
495 p.timecode.put(unsafe.Pointer(uintptr(q) + offs_buffer_timecode))
496 putUint32(q, offs_buffer_sequence, p.sequence)
497 putUint32(q, offs_buffer_memory, p.memory)
498 putUint32(q, offs_buffer_offset, p.offset)
499 putUint32(q, offs_buffer_length, p.length)
500 }
501
502 func (p *v4l_buffer) size() int {
503 return size_buffer
504 }
505
506 func (p *v4l_int) get(q unsafe.Pointer) {
507 *p = v4l_int(getInt(q, 0))
508 }
509
510 func (p *v4l_int) put(q unsafe.Pointer) {
511 putInt(q, 0, int32(*p))
512 }
513
514 func (p *v4l_int) size() int {
515 return size_int
516 }
517
518 func (p *v4l_cropcap) get(q unsafe.Pointer) {
519 p.typ = getUint32(q, offs_cropcap_typ)
520 p.bounds.get(unsafe.Pointer(uintptr(q) + offs_cropcap_bounds))
521 p.defrect.get(unsafe.Pointer(uintptr(q) + offs_cropcap_defrect))
522 p.pixelaspect.get(unsafe.Pointer(uintptr(q) + offs_cropcap_pixelaspect))
523 }
524
525 func (p *v4l_cropcap) put(q unsafe.Pointer) {
526 putUint32(q, offs_cropcap_typ, p.typ)
527 p.bounds.put(unsafe.Pointer(uintptr(q) + offs_cropcap_bounds))
528 p.defrect.put(unsafe.Pointer(uintptr(q) + offs_cropcap_defrect))
529 p.pixelaspect.put(unsafe.Pointer(uintptr(q) + offs_cropcap_pixelaspect))
530 }
531
532 func (p *v4l_cropcap) size() int {
533 return size_cropcap
534 }
535
536 func (p *v4l_crop) get(q unsafe.Pointer) {
537 p.typ = getUint32(q, offs_crop_typ)
538 p.c.get(unsafe.Pointer(uintptr(q) + offs_crop_c))
539 }
540
541 func (p *v4l_crop) put(q unsafe.Pointer) {
542 putUint32(q, offs_crop_typ, p.typ)
543 p.c.put(unsafe.Pointer(uintptr(q) + offs_crop_c))
544 }
545
546 func (p *v4l_crop) size() int {
547 return size_crop
548 }
549
550 func (p *v4l_fract) get(q unsafe.Pointer) {
551 p.numerator = getUint32(q, offs_fract_numerator)
552 p.denominator = getUint32(q, offs_fract_denominator)
553 }
554
555 func (p *v4l_fract) put(q unsafe.Pointer) {
556 putUint32(q, offs_fract_numerator, p.numerator)
557 putUint32(q, offs_fract_denominator, p.denominator)
558 }
559
560 func (p *v4l_timecode) get(q unsafe.Pointer) {
561 p.typ = getUint32(q, offs_timecode_typ)
562 p.flags = getUint32(q, offs_timecode_flags)
563 p.frames = getUint8(q, offs_timecode_frames)
564 p.seconds = getUint8(q, offs_timecode_seconds)
565 p.minutes = getUint8(q, offs_timecode_minutes)
566 p.hours = getUint8(q, offs_timecode_hours)
567 for i := range p.userbits {
568 p.userbits[i] = getUint8(q, offs_timecode_userbits+i)
569 }
570 }
571
572 func (p *v4l_timecode) put(q unsafe.Pointer) {
573 putUint32(q, offs_timecode_typ, p.typ)
574 putUint32(q, offs_timecode_flags, p.flags)
575 putUint8(q, offs_timecode_frames, p.frames)
576 putUint8(q, offs_timecode_seconds, p.seconds)
577 putUint8(q, offs_timecode_minutes, p.minutes)
578 putUint8(q, offs_timecode_hours, p.hours)
579 for i := range p.userbits {
580 putUint8(q, offs_timecode_userbits+i, p.userbits[i])
581 }
582 }
583
584 func (p *v4l_rect) get(q unsafe.Pointer) {
585 p.left = getInt32(q, offs_rect_left)
586 p.top = getInt32(q, offs_rect_top)
587 p.width = getUint32(q, offs_rect_width)
588 p.height = getUint32(q, offs_rect_height)
589 }
590
591 func (p *v4l_rect) put(q unsafe.Pointer) {
592 putInt32(q, offs_rect_left, p.left)
593 putInt32(q, offs_rect_top, p.top)
594 putUint32(q, offs_rect_width, p.width)
595 putUint32(q, offs_rect_height, p.height)
596 }
597
598 func (p *v4l_standard) get(q unsafe.Pointer) {
599 p.index = getUint32(q, offs_standard_index)
600 p.id = getUint64(q, offs_standard_id)
601 p.name = getString(q, offs_standard_name, size_standard_name)
602 p.frameperiod.get(unsafe.Pointer(uintptr(q) + offs_standard_frameperiod))
603 p.framelines = getUint32(q, offs_standard_framelines)
604 }
605
606 func (p *v4l_standard) put(q unsafe.Pointer) {
607 putUint32(q, offs_standard_index, p.index)
608 putUint64(q, offs_standard_id, p.id)
609 putString(q, offs_standard_name, size_standard_name, p.name)
610 p.frameperiod.put(unsafe.Pointer(uintptr(q) + offs_standard_frameperiod))
611 putUint32(q, offs_standard_framelines, p.framelines)
612 }
613
614 func (p *v4l_standard) size() int {
615 return size_standard
616 }
617
618 func (p *v4l_fmtdesc) get(q unsafe.Pointer) {
619 p.index = getUint32(q, offs_fmtdesc_index)
620 p.typ = getUint32(q, offs_fmtdesc_typ)
621 p.flags = getUint32(q, offs_fmtdesc_flags)
622 p.description = getString(q, offs_fmtdesc_description, size_fmtdesc_description)
623 p.pixelformat = getUint32(q, offs_fmtdesc_pixelformat)
624 }
625
626 func (p *v4l_fmtdesc) put(q unsafe.Pointer) {
627 putUint32(q, offs_fmtdesc_index, p.index)
628 putUint32(q, offs_fmtdesc_typ, p.typ)
629 putUint32(q, offs_fmtdesc_flags, p.flags)
630 putString(q, offs_fmtdesc_description, size_fmtdesc_description, p.description)
631 putUint32(q, offs_fmtdesc_pixelformat, p.pixelformat)
632
633 }
634
635 func (p *v4l_fmtdesc) size() int {
636 return size_fmtdesc
637 }
638
639 func (p *v4l_frmsizeenum) get(q unsafe.Pointer) {
640 p.index = getUint32(q, offs_frmsizeenum_index)
641 p.pixelFormat = getUint32(q, offs_frmsizeenum_pixelFormat)
642 p.typ = getUint32(q, offs_frmsizeenum_typ)
643 p.discrete.get(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_discrete))
644 p.stepwise.get(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_stepwise))
645 }
646
647 func (p *v4l_frmsizeenum) put(q unsafe.Pointer) {
648 putUint32(q, offs_frmsizeenum_index, p.index)
649 putUint32(q, offs_frmsizeenum_pixelFormat, p.pixelFormat)
650 putUint32(q, offs_frmsizeenum_typ, p.typ)
651 switch p.typ {
652 case v4l_frmsizeTypeDiscrete:
653 p.discrete.put(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_discrete))
654 case v4l_frmsizeTypeContinuous, v4l_frmsizeTypeStepwise:
655 p.stepwise.put(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_stepwise))
656 }
657 }
658
659 func (p *v4l_frmsizeenum) size() int {
660 return size_frmsizeenum
661 }
662
663 func (p *v4l_frmsizeDiscrete) get(q unsafe.Pointer) {
664 p.width = getUint32(q, offs_frmsizeDiscrete_width)
665 p.height = getUint32(q, offs_frmsizeDiscrete_height)
666 }
667
668 func (p *v4l_frmsizeDiscrete) put(q unsafe.Pointer) {
669 putUint32(q, offs_frmsizeDiscrete_width, p.width)
670 putUint32(q, offs_frmsizeDiscrete_height, p.height)
671 }
672
673 func (p *v4l_frmsizeStepwise) get(q unsafe.Pointer) {
674 p.minWidth = getUint32(q, offs_frmsizeStepwise_minWidth)
675 p.maxWidth = getUint32(q, offs_frmsizeStepwise_maxWidth)
676 p.stepWidth = getUint32(q, offs_frmsizeStepwise_stepWidth)
677 p.minHeight = getUint32(q, offs_frmsizeStepwise_minHeight)
678 p.maxHeight = getUint32(q, offs_frmsizeStepwise_maxHeight)
679 p.stepHeight = getUint32(q, offs_frmsizeStepwise_stepHeight)
680 }
681
682 func (p *v4l_frmsizeStepwise) put(q unsafe.Pointer) {
683 putUint32(q, offs_frmsizeStepwise_minWidth, p.minWidth)
684 putUint32(q, offs_frmsizeStepwise_maxWidth, p.maxWidth)
685 putUint32(q, offs_frmsizeStepwise_stepWidth, p.stepWidth)
686 putUint32(q, offs_frmsizeStepwise_minHeight, p.minHeight)
687 putUint32(q, offs_frmsizeStepwise_maxHeight, p.maxHeight)
688 putUint32(q, offs_frmsizeStepwise_stepHeight, p.stepHeight)
689 }
690
691 func (p *v4l_frmivalenum) get(q unsafe.Pointer) {
692 p.index = getUint32(q, offs_frmivalenum_index)
693 p.pixelFormat = getUint32(q, offs_frmivalenum_pixelFormat)
694 p.width = getUint32(q, offs_frmivalenum_width)
695 p.height = getUint32(q, offs_frmivalenum_height)
696 p.typ = getUint32(q, offs_frmivalenum_typ)
697 p.discrete.get(unsafe.Pointer(uintptr(q) + offs_frmivalenum_discrete))
698 p.stepwise.get(unsafe.Pointer(uintptr(q) + offs_frmivalenum_stepwise))
699 }
700
701 func (p *v4l_frmivalenum) put(q unsafe.Pointer) {
702 putUint32(q, offs_frmivalenum_index, p.index)
703 putUint32(q, offs_frmivalenum_pixelFormat, p.pixelFormat)
704 putUint32(q, offs_frmivalenum_width, p.width)
705 putUint32(q, offs_frmivalenum_height, p.height)
706 putUint32(q, offs_frmivalenum_typ, p.typ)
707 switch p.typ {
708 case v4l_frmivalTypeDiscrete:
709 p.discrete.put(unsafe.Pointer(uintptr(q) + offs_frmivalenum_discrete))
710 case v4l_frmivalTypeContinuous, v4l_frmivalTypeStepwise:
711 p.stepwise.put(unsafe.Pointer(uintptr(q) + offs_frmivalenum_stepwise))
712 }
713 }
714
715 func (p *v4l_frmivalenum) size() int {
716 return size_frmivalenum
717 }
718
719 func (p *v4l_frmivalStepwise) get(q unsafe.Pointer) {
720 p.min.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_min))
721 p.max.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_max))
722 p.step.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_step))
723 }
724
725 func (p *v4l_frmivalStepwise) put(q unsafe.Pointer) {
726 p.min.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_min))
727 p.max.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_max))
728 p.step.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_step))
729 }
730
731 func (p *v4l_queryctrl) get(q unsafe.Pointer) {
732 p.id = getUint32(q, offs_queryctrl_id)
733 p.typ = getUint32(q, offs_queryctrl_typ)
734 p.name = getString(q, offs_queryctrl_name, size_queryctrl_name)
735 p.minimum = getInt32(q, offs_queryctrl_minimum)
736 p.maximum = getInt32(q, offs_queryctrl_maximum)
737 p.step = getInt32(q, offs_queryctrl_step)
738 p.defaultValue = getInt32(q, offs_queryctrl_defaultValue)
739 p.flags = getUint32(q, offs_queryctrl_flags)
740 }
741
742 func (p *v4l_queryctrl) put(q unsafe.Pointer) {
743 putUint32(q, offs_queryctrl_id, p.id)
744 putUint32(q, offs_queryctrl_typ, p.typ)
745 putString(q, offs_queryctrl_name, size_queryctrl_name, p.name)
746 putInt32(q, offs_queryctrl_minimum, p.minimum)
747 putInt32(q, offs_queryctrl_maximum, p.maximum)
748 putInt32(q, offs_queryctrl_step, p.step)
749 putInt32(q, offs_queryctrl_defaultValue, p.defaultValue)
750 putUint32(q, offs_queryctrl_flags, p.flags)
751 }
752
753 func (p *v4l_queryctrl) size() int {
754 return size_queryctrl
755 }
756
757 func (p *v4l_querymenu) get(q unsafe.Pointer) {
758 p.id = getUint32(q, offs_querymenu_id)
759 p.index = getUint32(q, offs_querymenu_index)
760 p.name = getString(q, offs_querymenu_name, size_querymenu_name)
761 p.value = getInt64(q, offs_querymenu_value)
762 }
763
764 func (p *v4l_querymenu) put(q unsafe.Pointer) {
765 putUint32(q, offs_querymenu_id, p.id)
766 putUint32(q, offs_querymenu_index, p.index)
767 }
768
769 func (p *v4l_querymenu) size() int {
770 return size_querymenu
771 }
772
773 func (p *v4l_control) get(q unsafe.Pointer) {
774 p.id = getUint32(q, offs_control_id)
775 p.value = getInt32(q, offs_control_value)
776 }
777
778 func (p *v4l_control) put(q unsafe.Pointer) {
779 putUint32(q, offs_control_id, p.id)
780 putInt32(q, offs_control_value, p.value)
781 }
782
783 func (p *v4l_control) size() int {
784 return size_control
785 }
786
787 // Getters and putters for built-in types.
788
789 func getUint64(base unsafe.Pointer, offset int) uint64 {
790 ptr := (*uint64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
791 return *ptr
792 }
793
794 func putUint64(base unsafe.Pointer, offset int, value uint64) {
795 ptr := (*uint64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
796 *ptr = value
797 }
798
799 func getInt64(base unsafe.Pointer, offset int) int64 {
800 ptr := (*int64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
801 return *ptr
802 }
803
804 func putInt64(base unsafe.Pointer, offset int, value int64) {
805 ptr := (*int64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
806 *ptr = value
807 }
808
809 func getUint32(base unsafe.Pointer, offset int) uint32 {
810 ptr := (*uint32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
811 return *ptr
812 }
813
814 func putUint32(base unsafe.Pointer, offset int, value uint32) {
815 ptr := (*uint32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
816 *ptr = value
817 }
818
819 func getInt32(base unsafe.Pointer, offset int) int32 {
820 ptr := (*int32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
821 return *ptr
822 }
823
824 func putInt32(base unsafe.Pointer, offset int, value int32) {
825 ptr := (*int32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
826 *ptr = value
827 }
828
829 func getUint8(base unsafe.Pointer, offset int) uint8 {
830 ptr := (*uint8)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
831 return *ptr
832 }
833
834 func putUint8(base unsafe.Pointer, offset int, value uint8) {
835 ptr := (*uint8)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
836 *ptr = value
837 }
838
839 func getInt(base unsafe.Pointer, offset int) int64 {
840 p := unsafe.Pointer(uintptr(base) + uintptr(offset))
841 switch size_int {
842 case 4:
843 return int64(*(*uint32)(p))
844 case 8:
845 return *(*int64)(p)
846 default:
847 panic("bad int size")
848 }
849 }
850
851 func putInt(base unsafe.Pointer, offset int, value int32) {
852 p := unsafe.Pointer(uintptr(base) + uintptr(offset))
853 switch size_int {
854 case 4:
855 *(*int32)(p) = value
856 case 8:
857 *(*int64)(p) = int64(value)
858 default:
859 panic("bad int size")
860 }
861 }
862
863 func getString(base unsafe.Pointer, offset, maxLen int) string {
864 buf := make([]byte, 0, maxLen)
865 for i := 0; i < maxLen; i++ {
866 ptr := (*byte)(unsafe.Pointer(uintptr(base) + uintptr(offset+i)))
867 ch := *ptr
868 if ch == 0 {
869 break
870 }
871 buf = append(buf, ch)
872 }
873 return string(buf)
874 }
875
876 func putString(base unsafe.Pointer, offset, maxLen int, value string) {
877 for i := 0; i < maxLen; i++ {
878 ptr := (*byte)(unsafe.Pointer(uintptr(base) + uintptr(offset+i)))
879 var ch byte
880 if i < len(value) && i != maxLen-1 {
881 ch = value[i]
882 }
883 *ptr = ch
884 }
885 }