-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv4l2n.c
3560 lines (3213 loc) · 101 KB
/
v4l2n.c
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
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Next Video Tool for Linux* OS - Video4Linux2 API tool for developers.
*
* Copyright (c) 2011-2017 Intel Corporation. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* 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.
*
*/
#include "v4l2n.h"
#include "extradefs.h"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <time.h>
#include <limits.h>
#include <sys/wait.h>
#include <stdint.h>
#include <setjmp.h>
#include "linux/videodev2.h"
#include "linux/v4l2-subdev.h"
#define LOGPREFIX "V4L2N> "
#define USE_ATOMISP 1
#if USE_ATOMISP
#define CONFIG_VIDEO_ATOMISP_CSS20
#include "linux/atomisp.h"
#endif
#define FALSE 0
#define TRUE (!FALSE)
#define STRINGIFY_(x) #x
#define STRINGIFY(x) STRINGIFY_(x)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define MAX(a,b) ((a) >= (b) ? (a) : (b))
#define CLEAR(x) memset(&(x), 0, sizeof(x));
#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define BIT(x) (1<<(x))
static unsigned long int _PAGE_SIZE;
static unsigned long int _PAGE_MASK;
#define PAGE_ALIGN(x) ((typeof(x))(((unsigned long int)(x) + _PAGE_SIZE - 1) & _PAGE_MASK))
#define MAX_RING_BUFFERS 20
#define MAX_CAPTURE_BUFFERS 160
#define MAX_BUFFER_SIZE (64*1024*1024)
#define MAX_PIPES 6
#define V4L2_TYPE_IS_META(type) \
((type) == V4L2_BUF_TYPE_META_CAPTURE \
|| (type) == V4L2_BUF_TYPE_META_OUTPUT)
#define V4L2_TYPE_IS_VIDEO(type) \
((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE \
|| (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT \
|| (type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \
|| (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
typedef unsigned char bool;
static char *name = "v4l2n";
static const int FILLER = 0xFE;
/* Holds information returned by QUERYBUF and needed
* for subsequent QBUF/DQBUF. Buffers are reused for long sequences. */
struct ring_buffer {
struct v4l2_buffer querybuf;
struct v4l2_plane planes[VIDEO_MAX_PLANES];
bool queued;
void *malloc_p; /* Points to address returned by malloc() */
void *mmap_p; /* Points to address returned by mmap() */
void *start; /* Points to beginning of data in the buffer */
};
/* Used for saving each captured frame if saving was requested */
struct capture_buffer {
struct v4l2_format format;
void *image;
int length; /* Length of data in the buffer in bytes */
};
struct pipe {
int fd;
char *output;
void *bufdata; /* Data to be stored into buffers for driver */
unsigned int bufdata_length;
unsigned int bufdata_pos; /* Current read position */
struct v4l2_format format;
struct v4l2_requestbuffers reqbufs;
int num_capture_buffers;
struct capture_buffer capture_buffers[MAX_CAPTURE_BUFFERS];
struct ring_buffer ring_buffers[MAX_RING_BUFFERS];
bool streaming;
bool active;
bool msg_full_printed;
};
static struct {
int verbosity;
FILE *logfile;
bool save_images;
bool calculate_stats;
struct timeval start_time;
jmp_buf exception;
unsigned int pipe;
struct pipe pipes[MAX_PIPES];
} vars;
struct symbol_list {
int id;
const char *symbol;
};
#define SYMBOL_END { -1, NULL }
struct token_list {
int id;
int flags;
const char *token;
const struct symbol_list *symbols;
};
#define TOKEN_END { 0, 0, NULL, NULL }
#define TOKEN_F_OPTARG BIT(0) /* Token may have optional argument */
#define TOKEN_F_ARG BIT(1) /* Token must have argument or it is an error */
#define TOKEN_F_ARG2 BIT(2) /* Token may have 2 integer arguments */
#define TOKEN_F_ARG4 BIT(3) /* Token may have 4 integer arguments */
#define TOKEN_F_FLAGS BIT(8) /* Token contains flags (ie. is a bitmask) */
#define V4L2_CID "V4L2_CID_"
#define CONTROL(id) { V4L2_CID_##id, (#id) }
static const struct symbol_list controls[] = {
CONTROL(USER_CLASS),
CONTROL(BRIGHTNESS),
CONTROL(CONTRAST),
CONTROL(SATURATION),
CONTROL(HUE),
CONTROL(AUDIO_VOLUME),
CONTROL(AUDIO_BALANCE),
CONTROL(AUDIO_BASS),
CONTROL(AUDIO_TREBLE),
CONTROL(AUDIO_MUTE),
CONTROL(AUDIO_LOUDNESS),
CONTROL(BLACK_LEVEL),
CONTROL(AUTO_WHITE_BALANCE),
CONTROL(DO_WHITE_BALANCE),
CONTROL(RED_BALANCE),
CONTROL(BLUE_BALANCE),
CONTROL(GAMMA),
CONTROL(WHITENESS),
CONTROL(EXPOSURE),
CONTROL(AUTOGAIN),
CONTROL(GAIN),
CONTROL(HFLIP),
CONTROL(VFLIP),
CONTROL(POWER_LINE_FREQUENCY),
CONTROL(HUE_AUTO),
CONTROL(WHITE_BALANCE_TEMPERATURE),
CONTROL(SHARPNESS),
CONTROL(BACKLIGHT_COMPENSATION),
CONTROL(CHROMA_AGC),
CONTROL(COLOR_KILLER),
CONTROL(COLORFX),
CONTROL(AUTOBRIGHTNESS),
CONTROL(BAND_STOP_FILTER),
CONTROL(ROTATE),
CONTROL(BG_COLOR),
CONTROL(CHROMA_GAIN),
CONTROL(ILLUMINATORS_1),
CONTROL(ILLUMINATORS_2),
CONTROL(MIN_BUFFERS_FOR_CAPTURE),
CONTROL(MIN_BUFFERS_FOR_OUTPUT),
CONTROL(ALPHA_COMPONENT),
CONTROL(COLORFX_CBCR),
CONTROL(LASTP1),
CONTROL(USER_MEYE_BASE),
CONTROL(USER_BTTV_BASE),
CONTROL(USER_S2255_BASE),
CONTROL(USER_SI476X_BASE),
CONTROL(USER_TI_VPE_BASE),
CONTROL(USER_SAA7134_BASE),
CONTROL(USER_ADV7180_BASE),
CONTROL(MPEG_BASE),
CONTROL(MPEG_CLASS),
CONTROL(MPEG_STREAM_TYPE),
CONTROL(MPEG_STREAM_PID_PMT),
CONTROL(MPEG_STREAM_PID_AUDIO),
CONTROL(MPEG_STREAM_PID_VIDEO),
CONTROL(MPEG_STREAM_PID_PCR),
CONTROL(MPEG_STREAM_PES_ID_AUDIO),
CONTROL(MPEG_STREAM_PES_ID_VIDEO),
CONTROL(MPEG_STREAM_VBI_FMT),
CONTROL(MPEG_AUDIO_SAMPLING_FREQ),
CONTROL(MPEG_AUDIO_ENCODING),
CONTROL(MPEG_AUDIO_L1_BITRATE),
CONTROL(MPEG_AUDIO_L2_BITRATE),
CONTROL(MPEG_AUDIO_L3_BITRATE),
CONTROL(MPEG_AUDIO_MODE),
CONTROL(MPEG_AUDIO_MODE_EXTENSION),
CONTROL(MPEG_AUDIO_EMPHASIS),
CONTROL(MPEG_AUDIO_CRC),
CONTROL(MPEG_AUDIO_MUTE),
CONTROL(MPEG_AUDIO_AAC_BITRATE),
CONTROL(MPEG_AUDIO_AC3_BITRATE),
CONTROL(MPEG_AUDIO_DEC_PLAYBACK),
CONTROL(MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK),
CONTROL(MPEG_VIDEO_ENCODING),
CONTROL(MPEG_VIDEO_ASPECT),
CONTROL(MPEG_VIDEO_B_FRAMES),
CONTROL(MPEG_VIDEO_GOP_SIZE),
CONTROL(MPEG_VIDEO_GOP_CLOSURE),
CONTROL(MPEG_VIDEO_PULLDOWN),
CONTROL(MPEG_VIDEO_BITRATE_MODE),
CONTROL(MPEG_VIDEO_BITRATE),
CONTROL(MPEG_VIDEO_BITRATE_PEAK),
CONTROL(MPEG_VIDEO_TEMPORAL_DECIMATION),
CONTROL(MPEG_VIDEO_MUTE),
CONTROL(MPEG_VIDEO_MUTE_YUV),
CONTROL(MPEG_VIDEO_DECODER_SLICE_INTERFACE),
CONTROL(MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER),
CONTROL(MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB),
CONTROL(MPEG_VIDEO_FRAME_RC_ENABLE),
CONTROL(MPEG_VIDEO_HEADER_MODE),
CONTROL(MPEG_VIDEO_MAX_REF_PIC),
CONTROL(MPEG_VIDEO_MB_RC_ENABLE),
CONTROL(MPEG_VIDEO_MULTI_SLICE_MAX_BYTES),
CONTROL(MPEG_VIDEO_MULTI_SLICE_MAX_MB),
CONTROL(MPEG_VIDEO_MULTI_SLICE_MODE),
CONTROL(MPEG_VIDEO_VBV_SIZE),
CONTROL(MPEG_VIDEO_DEC_PTS),
CONTROL(MPEG_VIDEO_DEC_FRAME),
CONTROL(MPEG_VIDEO_VBV_DELAY),
CONTROL(MPEG_VIDEO_REPEAT_SEQ_HEADER),
CONTROL(MPEG_VIDEO_MV_H_SEARCH_RANGE),
CONTROL(MPEG_VIDEO_MV_V_SEARCH_RANGE),
CONTROL(MPEG_VIDEO_H263_I_FRAME_QP),
CONTROL(MPEG_VIDEO_H263_P_FRAME_QP),
CONTROL(MPEG_VIDEO_H263_B_FRAME_QP),
CONTROL(MPEG_VIDEO_H263_MIN_QP),
CONTROL(MPEG_VIDEO_H263_MAX_QP),
CONTROL(MPEG_VIDEO_H264_I_FRAME_QP),
CONTROL(MPEG_VIDEO_H264_P_FRAME_QP),
CONTROL(MPEG_VIDEO_H264_B_FRAME_QP),
CONTROL(MPEG_VIDEO_H264_MIN_QP),
CONTROL(MPEG_VIDEO_H264_MAX_QP),
CONTROL(MPEG_VIDEO_H264_8X8_TRANSFORM),
CONTROL(MPEG_VIDEO_H264_CPB_SIZE),
CONTROL(MPEG_VIDEO_H264_ENTROPY_MODE),
CONTROL(MPEG_VIDEO_H264_I_PERIOD),
CONTROL(MPEG_VIDEO_H264_LEVEL),
CONTROL(MPEG_VIDEO_H264_LOOP_FILTER_ALPHA),
CONTROL(MPEG_VIDEO_H264_LOOP_FILTER_BETA),
CONTROL(MPEG_VIDEO_H264_LOOP_FILTER_MODE),
CONTROL(MPEG_VIDEO_H264_PROFILE),
CONTROL(MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT),
CONTROL(MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH),
CONTROL(MPEG_VIDEO_H264_VUI_SAR_ENABLE),
CONTROL(MPEG_VIDEO_H264_VUI_SAR_IDC),
CONTROL(MPEG_VIDEO_H264_SEI_FRAME_PACKING),
CONTROL(MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0),
CONTROL(MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE),
CONTROL(MPEG_VIDEO_H264_FMO),
CONTROL(MPEG_VIDEO_H264_FMO_MAP_TYPE),
CONTROL(MPEG_VIDEO_H264_FMO_SLICE_GROUP),
CONTROL(MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION),
CONTROL(MPEG_VIDEO_H264_FMO_CHANGE_RATE),
CONTROL(MPEG_VIDEO_H264_FMO_RUN_LENGTH),
CONTROL(MPEG_VIDEO_H264_ASO),
CONTROL(MPEG_VIDEO_H264_ASO_SLICE_ORDER),
CONTROL(MPEG_VIDEO_H264_HIERARCHICAL_CODING),
CONTROL(MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE),
CONTROL(MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER),
CONTROL(MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP),
CONTROL(MPEG_VIDEO_MPEG4_I_FRAME_QP),
CONTROL(MPEG_VIDEO_MPEG4_P_FRAME_QP),
CONTROL(MPEG_VIDEO_MPEG4_B_FRAME_QP),
CONTROL(MPEG_VIDEO_MPEG4_MIN_QP),
CONTROL(MPEG_VIDEO_MPEG4_MAX_QP),
CONTROL(MPEG_VIDEO_MPEG4_LEVEL),
CONTROL(MPEG_VIDEO_MPEG4_PROFILE),
CONTROL(MPEG_VIDEO_MPEG4_QPEL),
CONTROL(MPEG_VIDEO_VPX_NUM_PARTITIONS),
CONTROL(MPEG_VIDEO_VPX_IMD_DISABLE_4X4),
CONTROL(MPEG_VIDEO_VPX_NUM_REF_FRAMES),
CONTROL(MPEG_VIDEO_VPX_FILTER_LEVEL),
CONTROL(MPEG_VIDEO_VPX_FILTER_SHARPNESS),
CONTROL(MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD),
CONTROL(MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL),
CONTROL(MPEG_VIDEO_VPX_MIN_QP),
CONTROL(MPEG_VIDEO_VPX_MAX_QP),
CONTROL(MPEG_VIDEO_VPX_I_FRAME_QP),
CONTROL(MPEG_VIDEO_VPX_P_FRAME_QP),
CONTROL(MPEG_VIDEO_VPX_PROFILE),
CONTROL(MPEG_CX2341X_BASE),
CONTROL(MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE),
CONTROL(MPEG_CX2341X_VIDEO_SPATIAL_FILTER),
CONTROL(MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE),
CONTROL(MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE),
CONTROL(MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE),
CONTROL(MPEG_CX2341X_VIDEO_TEMPORAL_FILTER),
CONTROL(MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE),
CONTROL(MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM),
CONTROL(MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP),
CONTROL(MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM),
CONTROL(MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP),
CONTROL(MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS),
CONTROL(MPEG_MFC51_BASE),
CONTROL(MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY),
CONTROL(MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE),
CONTROL(MPEG_MFC51_VIDEO_FRAME_SKIP_MODE),
CONTROL(MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE),
CONTROL(MPEG_MFC51_VIDEO_PADDING),
CONTROL(MPEG_MFC51_VIDEO_PADDING_YUV),
CONTROL(MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT),
CONTROL(MPEG_MFC51_VIDEO_RC_REACTION_COEFF),
CONTROL(MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY),
CONTROL(MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK),
CONTROL(MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH),
CONTROL(MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC),
CONTROL(MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P),
CONTROL(CAMERA_CLASS_BASE),
CONTROL(CAMERA_CLASS),
CONTROL(EXPOSURE_AUTO),
CONTROL(EXPOSURE_ABSOLUTE),
CONTROL(EXPOSURE_AUTO_PRIORITY),
CONTROL(PAN_RELATIVE),
CONTROL(TILT_RELATIVE),
CONTROL(PAN_RESET),
CONTROL(TILT_RESET),
CONTROL(PAN_ABSOLUTE),
CONTROL(TILT_ABSOLUTE),
CONTROL(FOCUS_ABSOLUTE),
CONTROL(FOCUS_RELATIVE),
CONTROL(FOCUS_AUTO),
CONTROL(ZOOM_ABSOLUTE),
CONTROL(ZOOM_RELATIVE),
CONTROL(ZOOM_CONTINUOUS),
CONTROL(PRIVACY),
CONTROL(IRIS_ABSOLUTE),
CONTROL(IRIS_RELATIVE),
CONTROL(AUTO_EXPOSURE_BIAS),
CONTROL(AUTO_N_PRESET_WHITE_BALANCE),
CONTROL(WIDE_DYNAMIC_RANGE),
CONTROL(IMAGE_STABILIZATION),
CONTROL(ISO_SENSITIVITY),
CONTROL(ISO_SENSITIVITY_AUTO),
CONTROL(EXPOSURE_METERING),
CONTROL(SCENE_MODE),
CONTROL(3A_LOCK),
CONTROL(AUTO_FOCUS_START),
CONTROL(AUTO_FOCUS_STOP),
CONTROL(AUTO_FOCUS_STATUS),
CONTROL(AUTO_FOCUS_RANGE),
CONTROL(PAN_SPEED),
CONTROL(TILT_SPEED),
CONTROL(FM_TX_CLASS_BASE),
CONTROL(FM_TX_CLASS),
CONTROL(RDS_TX_DEVIATION),
CONTROL(RDS_TX_PI),
CONTROL(RDS_TX_PTY),
CONTROL(RDS_TX_PS_NAME),
CONTROL(RDS_TX_RADIO_TEXT),
CONTROL(RDS_TX_MONO_STEREO),
CONTROL(RDS_TX_ARTIFICIAL_HEAD),
CONTROL(RDS_TX_COMPRESSED),
CONTROL(RDS_TX_DYNAMIC_PTY),
CONTROL(RDS_TX_TRAFFIC_ANNOUNCEMENT),
CONTROL(RDS_TX_TRAFFIC_PROGRAM),
CONTROL(RDS_TX_MUSIC_SPEECH),
CONTROL(RDS_TX_ALT_FREQS_ENABLE),
CONTROL(RDS_TX_ALT_FREQS),
CONTROL(AUDIO_LIMITER_ENABLED),
CONTROL(AUDIO_LIMITER_RELEASE_TIME),
CONTROL(AUDIO_LIMITER_DEVIATION),
CONTROL(AUDIO_COMPRESSION_ENABLED),
CONTROL(AUDIO_COMPRESSION_GAIN),
CONTROL(AUDIO_COMPRESSION_THRESHOLD),
CONTROL(AUDIO_COMPRESSION_ATTACK_TIME),
CONTROL(AUDIO_COMPRESSION_RELEASE_TIME),
CONTROL(PILOT_TONE_ENABLED),
CONTROL(PILOT_TONE_DEVIATION),
CONTROL(PILOT_TONE_FREQUENCY),
CONTROL(TUNE_PREEMPHASIS),
CONTROL(TUNE_POWER_LEVEL),
CONTROL(TUNE_ANTENNA_CAPACITOR),
CONTROL(FLASH_CLASS_BASE),
CONTROL(FLASH_CLASS),
CONTROL(FLASH_LED_MODE),
CONTROL(FLASH_STROBE_SOURCE),
CONTROL(FLASH_STROBE),
CONTROL(FLASH_STROBE_STOP),
CONTROL(FLASH_STROBE_STATUS),
CONTROL(FLASH_TIMEOUT),
CONTROL(FLASH_INTENSITY),
CONTROL(FLASH_TORCH_INTENSITY),
CONTROL(FLASH_INDICATOR_INTENSITY),
CONTROL(FLASH_FAULT),
CONTROL(FLASH_CHARGE),
CONTROL(FLASH_READY),
CONTROL(JPEG_CLASS_BASE),
CONTROL(JPEG_CLASS),
CONTROL(IMAGE_SOURCE_CLASS_BASE),
CONTROL(IMAGE_SOURCE_CLASS),
CONTROL(VBLANK),
CONTROL(HBLANK),
CONTROL(ANALOGUE_GAIN),
CONTROL(TEST_PATTERN_RED),
CONTROL(TEST_PATTERN_GREENR),
CONTROL(TEST_PATTERN_BLUE),
CONTROL(TEST_PATTERN_GREENB),
CONTROL(MIPI_LANES),
CONTROL(IMAGE_PROC_CLASS_BASE),
CONTROL(IMAGE_PROC_CLASS),
CONTROL(LINK_FREQ),
CONTROL(PIXEL_RATE),
CONTROL(TEST_PATTERN),
CONTROL(DV_CLASS_BASE),
CONTROL(DV_CLASS),
CONTROL(DV_TX_RGB_RANGE),
CONTROL(DV_RX_RGB_RANGE),
CONTROL(FM_RX_CLASS_BASE),
CONTROL(FM_RX_CLASS),
CONTROL(TUNE_DEEMPHASIS),
CONTROL(RDS_RECEPTION),
CONTROL(RDS_RX_PTY),
CONTROL(RDS_RX_PS_NAME),
CONTROL(RDS_RX_RADIO_TEXT),
CONTROL(RDS_RX_TRAFFIC_ANNOUNCEMENT),
CONTROL(RDS_RX_TRAFFIC_PROGRAM),
CONTROL(RDS_RX_MUSIC_SPEECH),
CONTROL(RF_TUNER_CLASS_BASE),
CONTROL(RF_TUNER_CLASS),
CONTROL(RF_TUNER_BANDWIDTH_AUTO),
CONTROL(RF_TUNER_BANDWIDTH),
CONTROL(RF_TUNER_LNA_GAIN_AUTO),
CONTROL(RF_TUNER_LNA_GAIN),
CONTROL(RF_TUNER_MIXER_GAIN_AUTO),
CONTROL(RF_TUNER_MIXER_GAIN),
CONTROL(RF_TUNER_IF_GAIN_AUTO),
CONTROL(RF_TUNER_IF_GAIN),
CONTROL(RF_TUNER_PLL_LOCK),
CONTROL(DETECT_CLASS_BASE),
CONTROL(DETECT_CLASS),
CONTROL(DETECT_MD_MODE),
CONTROL(DETECT_MD_GLOBAL_THRESHOLD),
CONTROL(DETECT_MD_THRESHOLD_GRID),
CONTROL(DETECT_MD_REGION_GRID),
CONTROL(MAX_CTRLS),
CONTROL(PRIVATE_BASE),
#if USE_ATOMISP
CONTROL(ATOMISP_BAD_PIXEL_DETECTION),
CONTROL(ATOMISP_POSTPROCESS_GDC_CAC),
CONTROL(ATOMISP_VIDEO_STABLIZATION),
CONTROL(ATOMISP_FIXED_PATTERN_NR),
CONTROL(ATOMISP_FALSE_COLOR_CORRECTION),
CONTROL(ATOMISP_LOW_LIGHT),
CONTROL(FOCAL_ABSOLUTE),
CONTROL(FNUMBER_ABSOLUTE),
CONTROL(FNUMBER_RANGE),
CONTROL(REQUEST_FLASH),
CONTROL(FLASH_INTENSITY),
CONTROL(FLASH_STATUS),
CONTROL(FLASH_TORCH_INTENSITY),
CONTROL(FLASH_INDICATOR_INTENSITY),
CONTROL(FLASH_TIMEOUT),
CONTROL(FLASH_STROBE),
CONTROL(FLASH_MODE),
CONTROL(VCM_SLEW),
CONTROL(VCM_TIMEING),
CONTROL(TEST_PATTERN),
CONTROL(FOCUS_STATUS),
CONTROL(BIN_FACTOR_HORZ),
CONTROL(BIN_FACTOR_VERT),
CONTROL(G_SKIP_FRAMES),
#endif
SYMBOL_END
};
#define V4L2_BUF_TYPE "V4L2_BUF_TYPE_"
#define BUFTYPE(id) { V4L2_BUF_TYPE_##id, (#id) }
static const struct symbol_list v4l2_buf_types[] = {
BUFTYPE(VIDEO_CAPTURE),
BUFTYPE(VIDEO_CAPTURE_MPLANE),
BUFTYPE(VIDEO_OUTPUT),
BUFTYPE(VIDEO_OUTPUT_MPLANE),
BUFTYPE(VIDEO_OVERLAY),
BUFTYPE(VBI_CAPTURE),
BUFTYPE(VBI_OUTPUT),
BUFTYPE(SLICED_VBI_CAPTURE),
BUFTYPE(SLICED_VBI_OUTPUT),
BUFTYPE(VIDEO_OUTPUT_OVERLAY),
BUFTYPE(PRIVATE),
BUFTYPE(META_CAPTURE),
BUFTYPE(META_OUTPUT),
SYMBOL_END
};
#define V4L2_PIX_FMT "V4L2_PIX_FMT_"
#define PIXFMT(id) { V4L2_PIX_FMT_##id, (#id) }
#define METAFMT(id) { V4L2_META_FMT_##id, (#id) }
static const struct symbol_list pixelformats[] = {
PIXFMT(RGB332),
PIXFMT(RGB444),
PIXFMT(ARGB444),
PIXFMT(XRGB444),
PIXFMT(RGB555),
PIXFMT(ARGB555),
PIXFMT(XRGB555),
PIXFMT(RGB565),
PIXFMT(RGB555X),
PIXFMT(ARGB555X),
PIXFMT(XRGB555X),
PIXFMT(RGB565X),
PIXFMT(BGR666),
PIXFMT(BGR24),
PIXFMT(RGB24),
PIXFMT(BGR32),
PIXFMT(ABGR32),
PIXFMT(XBGR32),
PIXFMT(RGB32),
PIXFMT(ARGB32),
PIXFMT(XRGB32),
PIXFMT(GREY),
PIXFMT(Y4),
PIXFMT(Y6),
PIXFMT(Y10),
PIXFMT(Y12),
PIXFMT(Y16),
PIXFMT(Y10BPACK),
PIXFMT(PAL8),
PIXFMT(UV8),
PIXFMT(YVU410),
PIXFMT(YVU420),
PIXFMT(YUYV),
PIXFMT(YYUV),
PIXFMT(YVYU),
PIXFMT(UYVY),
PIXFMT(VYUY),
PIXFMT(YUV422P),
PIXFMT(YUV411P),
PIXFMT(Y41P),
PIXFMT(YUV444),
PIXFMT(YUV555),
PIXFMT(YUV565),
PIXFMT(YUV32),
PIXFMT(YUV410),
PIXFMT(YUV420),
PIXFMT(HI240),
PIXFMT(HM12),
PIXFMT(M420),
PIXFMT(NV12),
PIXFMT(NV21),
PIXFMT(NV16),
PIXFMT(NV61),
PIXFMT(NV24),
PIXFMT(NV42),
PIXFMT(NV12M),
PIXFMT(NV21M),
PIXFMT(NV16M),
PIXFMT(NV61M),
PIXFMT(NV12MT),
PIXFMT(NV12MT_16X16),
PIXFMT(YUV420M),
PIXFMT(YVU420M),
PIXFMT(SBGGR8),
PIXFMT(SGBRG8),
PIXFMT(SGRBG8),
PIXFMT(SRGGB8),
PIXFMT(SBGGR10),
PIXFMT(SGBRG10),
PIXFMT(SGRBG10),
PIXFMT(SRGGB10),
PIXFMT(SBGGR10P),
PIXFMT(SGBRG10P),
PIXFMT(SGRBG10P),
PIXFMT(SRGGB10P),
PIXFMT(SBGGR10ALAW8),
PIXFMT(SGBRG10ALAW8),
PIXFMT(SGRBG10ALAW8),
PIXFMT(SRGGB10ALAW8),
PIXFMT(SBGGR10DPCM8),
PIXFMT(SGBRG10DPCM8),
PIXFMT(SGRBG10DPCM8),
PIXFMT(SRGGB10DPCM8),
PIXFMT(SBGGR12),
PIXFMT(SGBRG12),
PIXFMT(SGRBG12),
PIXFMT(SRGGB12),
PIXFMT(SBGGR12P),
PIXFMT(SGBRG12P),
PIXFMT(SGRBG12P),
PIXFMT(SRGGB12P),
PIXFMT(SBGGR14),
PIXFMT(SGBRG14),
PIXFMT(SGRBG14),
PIXFMT(SRGGB14),
PIXFMT(SBGGR14P),
PIXFMT(SGBRG14P),
PIXFMT(SGRBG14P),
PIXFMT(SRGGB14P),
PIXFMT(SBGGR16),
PIXFMT(SBGGR8_16V32),
PIXFMT(SGBRG8_16V32),
PIXFMT(SGRBG8_16V32),
PIXFMT(SRGGB8_16V32),
PIXFMT(SBGGR10V32),
PIXFMT(SGBRG10V32),
PIXFMT(SGRBG10V32),
PIXFMT(SRGGB10V32),
PIXFMT(SBGGR12V32),
PIXFMT(SGBRG12V32),
PIXFMT(SGRBG12V32),
PIXFMT(SRGGB12V32),
PIXFMT(SBGGR8V32),
PIXFMT(SGBRG8V32),
PIXFMT(SGRBG8V32),
PIXFMT(SRGGB8V32),
PIXFMT(UYVY_V32),
PIXFMT(YUYV420_V32),
PIXFMT(MJPEG),
PIXFMT(JPEG),
PIXFMT(DV),
PIXFMT(MPEG),
PIXFMT(H264),
PIXFMT(H264_NO_SC),
PIXFMT(H264_MVC),
PIXFMT(H263),
PIXFMT(MPEG1),
PIXFMT(MPEG2),
PIXFMT(MPEG4),
PIXFMT(XVID),
PIXFMT(VC1_ANNEX_G),
PIXFMT(VC1_ANNEX_L),
PIXFMT(VP8),
PIXFMT(CPIA1),
PIXFMT(WNVA),
PIXFMT(SN9C10X),
PIXFMT(SN9C20X_I420),
PIXFMT(PWC1),
PIXFMT(PWC2),
PIXFMT(ET61X251),
PIXFMT(SPCA501),
PIXFMT(SPCA505),
PIXFMT(SPCA508),
PIXFMT(SPCA561),
PIXFMT(PAC207),
PIXFMT(MR97310A),
PIXFMT(JL2005BCD),
PIXFMT(SN9C2028),
PIXFMT(SQ905C),
PIXFMT(PJPG),
PIXFMT(OV511),
PIXFMT(OV518),
PIXFMT(STV0680),
PIXFMT(TM6000),
PIXFMT(CIT_YYVYUY),
PIXFMT(KONICA420),
PIXFMT(JPGL),
PIXFMT(SE401),
PIXFMT(S5C_UYVY_JPG),
PIXFMT(SMIAPP_META_8),
PIXFMT(YYUV420_V32),
PIXFMT(PRIV_MAGIC),
PIXFMT(FLAG_PREMUL_ALPHA),
PIXFMT(IPU3_SBGGR10),
PIXFMT(IPU3_SGBRG10),
PIXFMT(IPU3_SGRBG10),
PIXFMT(IPU3_SRGGB10),
METAFMT(IPU3_PARAMS),
METAFMT(IPU3_STAT_3A),
METAFMT(IPU3_STAT_DVS),
METAFMT(IPU3_STAT_LACE),
SYMBOL_END
};
static const struct symbol_list v4l2_memory[] = {
{ V4L2_MEMORY_MMAP, "MMAP" },
{ V4L2_MEMORY_USERPTR, "USERPTR" },
SYMBOL_END
};
static const struct symbol_list v4l2_queryctrl_type[] = {
{ V4L2_CTRL_TYPE_INTEGER, "V4L2_CTRL_TYPE_INTEGER" },
{ V4L2_CTRL_TYPE_BOOLEAN, "V4L2_CTRL_TYPE_BOOLEAN" },
{ V4L2_CTRL_TYPE_MENU, "V4L2_CTRL_TYPE_MENU" },
{ V4L2_CTRL_TYPE_BUTTON, "V4L2_CTRL_TYPE_BUTTON" },
{ V4L2_CTRL_TYPE_INTEGER64, "V4L2_CTRL_TYPE_INTEGER64" },
{ V4L2_CTRL_TYPE_CTRL_CLASS, "V4L2_CTRL_TYPE_CTRL_CLASS" },
{ V4L2_CTRL_TYPE_STRING, "V4L2_CTRL_TYPE_STRING" },
{ V4L2_CTRL_TYPE_BITMASK, "V4L2_CTRL_TYPE_BITMASK" },
{ V4L2_CTRL_TYPE_INTEGER_MENU, "V4L2_CTRL_TYPE_INTEGER_MENU" },
/* Compound types are >= 0x0100 */
{ V4L2_CTRL_TYPE_U8, "V4L2_CTRL_TYPE_U8" },
{ V4L2_CTRL_TYPE_U16, "V4L2_CTRL_TYPE_U16" },
{ V4L2_CTRL_TYPE_U32, "V4L2_CTRL_TYPE_U32" },
{ V4L2_CTRL_TYPE_PRIVATE, "V4L2_CTRL_TYPE_PRIVATE" },
SYMBOL_END
};
static const struct symbol_list v4l2_queryctrl_flags[] = {
{ V4L2_CTRL_FLAG_DISABLED, "V4L2_CTRL_FLAG_DISABLED" },
{ V4L2_CTRL_FLAG_GRABBED, "V4L2_CTRL_FLAG_GRABBED" },
{ V4L2_CTRL_FLAG_READ_ONLY, "V4L2_CTRL_FLAG_READ_ONLY" },
{ V4L2_CTRL_FLAG_UPDATE, "V4L2_CTRL_FLAG_UPDATE" },
{ V4L2_CTRL_FLAG_INACTIVE, "V4L2_CTRL_FLAG_INACTIVE" },
{ V4L2_CTRL_FLAG_SLIDER, "V4L2_CTRL_FLAG_SLIDER" },
{ V4L2_CTRL_FLAG_WRITE_ONLY, "V4L2_CTRL_FLAG_WRITE_ONLY" },
{ V4L2_CTRL_FLAG_VOLATILE, "V4L2_CTRL_FLAG_VOLATILE" },
{ V4L2_CTRL_FLAG_HAS_PAYLOAD, "V4L2_CTRL_FLAG_HAS_PAYLOAD" },
{ V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, "V4L2_CTRL_FLAG_EXECUTE_ON_WRITE" },
SYMBOL_END
};
static char *get_pipestring(void)
{
static char buf[5];
if (vars.pipe < 0 || vars.pipe >= MAX_PIPES)
return "";
snprintf(buf, sizeof(buf), "p%u: ", vars.pipe);
return buf;
}
static void print(int lvl, char *msg, ...)
{
static bool firstcol = TRUE;
va_list ap;
if (vars.verbosity < lvl)
return;
va_start(ap, msg);
if (vars.logfile) {
if (firstcol) {
fprintf(vars.logfile, LOGPREFIX);
fprintf(vars.logfile, "%s", get_pipestring());
}
vfprintf(vars.logfile, msg, ap);
fflush(vars.logfile);
va_end(ap);
va_start(ap, msg);
}
if (firstcol)
printf("%s", get_pipestring());
vprintf(msg, ap);
if (msg[0] != 0)
firstcol = msg[strlen(msg) - 1]=='\n';
va_end(ap);
fflush(stdout);
}
static void error(char *msg, ...)
{
FILE *f = stdout;
va_list ap;
int e = errno;
va_start(ap, msg);
if (vars.logfile) {
fprintf(vars.logfile, LOGPREFIX);
fprintf(vars.logfile, "%s%s: ", get_pipestring(), name);
vfprintf(vars.logfile, msg, ap);
if (e)
fprintf(vars.logfile, ": %s (%i)", strerror(e), e);
fprintf(vars.logfile, "\n");
fflush(vars.logfile);
}
fprintf(f, "%s%s: ", get_pipestring(), name);
vfprintf(f, msg, ap);
if (e)
fprintf(f, ": %s (%i)", strerror(e), e);
fprintf(f, "\n");
fflush(f);
va_end(ap);
longjmp(vars.exception, 1);
exit(1);
}
#define itd_xioctl(io, arg) itd_xioctl_(#io, io, arg)
static void itd_xioctl_(char *ios, int ion, void *arg)
{
int fd = vars.pipes[vars.pipe].fd;
int r = ioctl(fd, ion, arg);
if (r)
error("%s failed on fd %i", ios, fd);
}
static int itd_xioctl_try(int ion, void *arg)
{
int r = ioctl(vars.pipes[vars.pipe].fd, ion, arg);
if (r != 0) {
int e = -errno;
if (e == 0)
return INT_MIN;
return e;
}
return 0;
}
static void *ralloc(void *p, int s)
{
void *r = realloc(p, s);
if (r)
return r;
free(p);
error("memory reallocation failed");
return NULL;
}
static void usage(void)
{
print(1,"v4l2n: Next Video Tool for Linux* OS CLI compiled " __DATE__ " " __TIME__ "\n"
"Copyright (c) 2011-2017 Intel Corporation. All Rights Reserved.\n"
"This is free software with ABSOLUTELY NO WARRANTY.\n"
"License GPLv2: GNU GPL version 2\n"
" <https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html>.\n"
"\n"
"Usage: %s [-h] [-d device]\n"
"-h Show this help\n"
"--help\n"
"-v\n"
"--verbose increase message verbosity\n"
"-q\n"
"--quiet decrease message verbosity\n"
"--log[=X] output messages also to log file,\n"
"-l default /dev/kmsg\n"
"-d open /dev/videoX device node\n"
"--device\n"
"--open\n"
"--close close device node\n"
"--querycap Query device capabilities (VIDIOC_QUERYCAP)\n"
"-i Set/get input device (VIDIOC_S/G_INPUT)\n"
"--input\n"
"--enuminput Enumerate available input devices (VIDIOC_ENUMINPUT)\n"
"--enumfmt Enumerate formats, frame sizes, and frame intervals\n"
" (VIDIOC_ENUM_FMT, VIDIOC_ENUM_FRAMESIZES, VIDIOC_ENUM_FRAMEINTERVALS)\n"
"-o FILENAME Set output filename for captured images\n"
"--output\n"
"--parm Set/get parameters (VIDIOC_S/G_PARM)\n"
"-t Try format (VIDIOC_TRY_FORMAT)\n"
"--try_fmt\n"
"-f Set/get format (VIDIOC_S/G_FMT)\n"
"--fmt\n"
"-r Request buffers (VIDIOC_REQBUFS)\n"
"--reqbufs\n"
"-s VIDIOC_STREAMON: start streaming\n"
"--streamon\n"
"-e VIDIOC_STREAMOFF: stop streaming\n"
"--streamoff\n"
"-a [N] Capture N [1] buffers with QBUF/DQBUF\n"
"--capture=[N]\n"
"--stream=[N] Capture N [1] buffers with QBUF/DQBUF and leave streaming on\n"
"--subdev_frame_interval=X\n"
" Set/get subdev frame interval\n"
"-x [EC,EF,AG,DG] Set coarse_itg, fine_itg, analog gain, and digital gain [ATOMISP]\n"
"--exposure (ATOMISP_IOC_S_EXPOSURE)\n"
"--sensor_mode_data\n"
" Get sensor mode data (ATOMISP_IOC_G_SENSOR_MODE_DATA) [ATOMISP]\n"
"--priv_data[=file]\n"
" Read and optionally save to file sensor OTP/EEPROM data\n"
" (ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA)\n"
"--motor_priv_data[=file]\n"
" Read and optionally save to file af motor OTP/EEPROM data\n"
" (ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA)\n"
"--isp_dump=addr,len\n"
" Dump ISP memory to kernel log\n"
"--cvf_parm Set continuous vf parameters [num_captures,skip_frames,offset]\n"
"--parameters Set ISP image processing parameters\n"
"--ctrl-list List supported V4L2 controls\n"
"--ctrl=$ Request given V4L2 controls\n"
"--fmt-list List supported pixel formats\n"
"--enumctrl Enumerate device V4L2 controls\n"
"-c $ (VIDIOC_QUERYCTRL / VIDIOC_S/G_CTRL / VIDIOC_S/G_EXT_CTRLS)\n"
"-w [x] Wait of x seconds (may be fractional)\n"
"--wait\n"
"--waitkey[=file]\n"
" Read a line from given file (default stdin)\n"
"--shell=CMD Run shell command CMD\n"
"--statistics Calculate statistics from each frame\n"
"--file <name> Read commands (options) from given file\n"
"--pipe <n,m,..> Select current pipes to operate on\n"
"--load <name> Load buffer data from file for driver\n"
"--crop <args> Set/get cropping parameters\n"
"--cropcap <type=x> Get cropping capabilities\n"
"--selection <args> Set/get selection parameters\n"
"\n"
"List of V4L2 controls syntax: <[V4L2_CID_]control_name_or_id>[+][=value|?|#][,...]\n"
"where control_name_or_id is either symbolic name or numerical id.\n"
"When + is given, use extended controls, otherwise use old-style control call.\n"
"\"=\" sets the value, \"?\" gets the current value, and \"#\" shows control info.\n",
name);
}
static int isident(int c)
{
return isalnum(c) || c == '_';
}
static int isseparator(int c)
{
return c ==',' || c == '/' || c == ';';
}
static void symbol_dump(const char *prefix, const struct symbol_list *list)
{
int i;
for (i = 0; list[i].symbol != NULL; i++)
print(0, "%s%s [0x%08X]\n", prefix, list[i].symbol, list[i].id);
}
static int symbol_get(const struct symbol_list *list, const char **symbol)
{
const char *start;
const char *end;
int r, i;
if (!symbol || !symbol[0])
error("symbol missing");
start = *symbol;
if (isdigit(start[0])) {
r = strtol(start, (char **)&end, 0);
if (end == start)
error("zero-length symbol value");
} else {
end = start;
while (isalnum(*end) || *end == '_') end++;
if (start == end)
error("zero-length symbol");
if (!list)
error("only numeric value allowed");
for (i=0; list[i].symbol!=NULL; i++) {
if (strncasecmp(start, list[i].symbol, end-start) == 0)
break;
}
if (list[i].symbol == NULL)
error("symbol `%s' not found", start);
r = list[i].id;
}
*symbol = end;
return r;
}
static int values_get(int *val, int val_size, const char **ptr)
{
const char *s = *ptr;
bool paren = FALSE;
int i = 0;
if (!s)
error("missing integer values");
if (*s == '(') {
s++;
paren = TRUE;
}
while (i < val_size) {
char *a;
val[i] = strtol(s, &a, 0);
if (a == s)
break;
s = a;
i++;
if (!isseparator(*s))
break;
s++;
}
if (paren) {
if (*s != ')')
error("missing closing parenthesis");
s++;
}
*ptr = s;