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