-
Notifications
You must be signed in to change notification settings - Fork 1
/
v4l2_dm368_r1.c
2204 lines (1943 loc) · 57.1 KB
/
v4l2_dm368_r1.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
/*
** V4L2 video capture example
**
** This program can be used and distributed without restrictions.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> // getopt_long()
#include <fcntl.h> // for open()
#include <unistd.h> // for close()
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <asm/types.h> // for videodev2.h
#include <linux/videodev.h>
#include <linux/videodev2.h>
#include <media/davinci/dm365_ccdc.h>
#include <media/davinci/vpfe_capture.h>
#include <media/davinci/imp_previewer.h>
#include <media/davinci/imp_resizer.h>
#include <media/davinci/dm365_ipipe.h>
#include <video/davincifb_ioctl.h>
#include <video/davinci_osd.h>
#define ROTATE 0
#define FBDEV 0
#define CLEAR(x) memset (&(x), 0, sizeof (x))
#define CAPTURE_DEVICE "/dev/video0"
#define VID0_DEVICE "/dev/video2"
#define VID1_DEVICE "/dev/video3"
#define OSD0_DEVICE "/dev/fb0"
#define OSD1_DEVICE "/dev/fb2"
#define FBVID0_DEVICE "/dev/fb1"
#define FBVID1_DEVICE "/dev/fb3"
/* Function error codes */
#define SUCCESS 0
#define FAILURE -1
/* Bits per pixel for video window */
#define YUV_422_BPP 16
#define BITMAP_BPP_8 8
#define round_32(width) ((((width) + 31) / 32) * 32 )
/* D1 screen dimensions */
#define VID0_WIDTH 384
#define VID0_HEIGHT 384
#define VID0_BPP 16
#define VID0_FRAME_SIZE (VID0_WIDTH*VID0_HEIGHT)
#define VID0_VMODE FB_VMODE_INTERLACED
#define VID1_WIDTH 384
#define VID1_HEIGHT 384
#define VID1_BPP 16
#define VID1_FRAME_SIZE (VID1_WIDTH*VID1_HEIGHT)
#define VID1_VMODE FB_VMODE_INTERLACED
#define OSD0_BPP 4
#define OSD0_WIDTH (round_32(240*OSD0_BPP/8) * 8/OSD0_BPP)
#define OSD0_HEIGHT 120
#define OSD0_FRAME_SIZE (OSD0_WIDTH*OSD0_HEIGHT)
#define OSD0_VMODE FB_VMODE_INTERLACED
#define OSD1_BPP 8
#define OSD1_WIDTH (round_32(240*OSD1_BPP/8) * 8/OSD1_BPP)
#define OSD1_HEIGHT 120
#define OSD1_FRAME_SIZE (OSD1_WIDTH*OSD1_HEIGHT)
#define OSD1_VMODE FB_VMODE_INTERLACED
/* position */
#define OSD0_XPOS 0
#define OSD0_YPOS 0
#define OSD1_XPOS 300
#define OSD1_YPOS 250
#define VID0_XPOS 0
#define VID0_YPOS 0
#define VID1_XPOS 20
#define VID1_YPOS 100
/* Zoom Params */
#define OSD0_HZOOM 0
#define OSD0_VZOOM 0
#define OSD1_HZOOM 0
#define OSD1_VZOOM 0
#define VID0_HZOOM 0
#define VID0_VZOOM 0
#define VID1_HZOOM 0
#define VID1_VZOOM 0
/* OSD window blend factor */
#define OSD1_WINDOW_BF 0
#define OSD1_WINDOW_CK 0
#define OSD1_CK 0
#define OSD0_WINDOW_BF 3
#define OSD0_WINDOW_CK 0
#define OSD0_CK 0
#define VIDEO_NUM_BUFS 3
#define OSD_NUM_BUFS 2
#define RED_COLOR 249
#define BLUE_COLOR 140 //blue color
#define RAM_CLUT_IDX 0xFF
#define BITMAP_COLOR 0x11
#define CURSOR_XPOS 100
#define CURSOR_YPOS 100
#define CURSOR_XRES 50
#define CURSOR_YRES 50
#define CURSOR_THICKNESS 1
#define CURSOR_COLOR 0xF9
#define ATTR_BLINK_INTERVAL 1
#define ATTR_BLEND_VAL 0xaa
#define ATTRIB_MODE "mode"
#define ATTRIB_OUTPUT "output"
#define LOOP_COUNT 500
#define DEBUG
#ifdef DEBUG
#define DBGENTER printf("%s : Enter\n", __FUNCTION__);
#define DBGEXIT printf("%s : Leave\n", __FUNCTION__);
#define PREV_DEBUG(x) printf("DEBUG:%s:%s:%s\n",__FUNCTION__,__LINE__,x);
#else
#define DBGENTER
#define DBGEXIT
#define PREV_DEBUG(x)
#endif
struct buffer
{
void *start;
size_t length;
};
char *dev_name_prev = "/dev/davinci_previewer";
char *dev_name_rsz = "/dev/davinci_resizer";
#define YEE_TABLE_FILE "EE_Table.txt"
static short yee_table[MAX_SIZE_YEE_LUT];
struct vpbe_test_info {
int vid0_width;
int vid0_height;
int vid0_bpp;
int vid0_frame_size;
int vid0_vmode;
int vid1_width;
int vid1_height;
int vid1_bpp;
int vid1_frame_size;
int vid1_vmode;
int osd0_bpp;
int osd0_width;
int osd0_height;
int osd0_frame_size;
int osd0_vmode;
int osd1_bpp;
int osd1_width;
int osd1_height;
int osd1_frame_size;
int osd1_vmode;
int osd0_xpos;
int osd0_ypos;
int osd1_xpos;
int osd1_ypos;
int vid0_xpos;
int vid0_ypos;
int vid1_xpos;
int vid1_ypos;
int osd0_hzoom;
int osd0_vzoom;
int osd1_hzoom;
int osd1_vzoom;
int vid0_hzoom;
int vid0_vzoom;
int vid1_hzoom;
int vid1_vzoom;
int osd1_window_bf;
int osd1_window_ck;
int osd1_ck;
int osd0_window_bf;
int osd0_window_ck;
int osd0_ck;
int osd0_coloridx;
int osd1_coloridx;
int ram_clut_idx;
int bitmap_color;
int cursor_xpos;
int cursor_ypos;
int cursor_xres;
int cursor_yres;
int cursor_thickness;
int cursor_color;
int attr_blink_interval;
int attr_blend_val;
};
static struct vpbe_test_info test_data = {
VID0_WIDTH,
VID0_HEIGHT,
VID0_BPP,
VID0_FRAME_SIZE,
VID0_VMODE,
VID1_WIDTH,
VID1_HEIGHT,
VID1_BPP,
VID1_FRAME_SIZE,
VID1_VMODE,
OSD0_BPP,
OSD0_WIDTH,
OSD0_HEIGHT,
OSD0_FRAME_SIZE,
OSD0_VMODE,
OSD1_BPP,
OSD1_WIDTH,
OSD1_HEIGHT,
OSD1_FRAME_SIZE,
OSD1_VMODE,
OSD0_XPOS,
OSD0_YPOS,
OSD1_XPOS,
OSD1_YPOS,
VID0_XPOS,
VID0_YPOS,
VID1_XPOS,
VID1_YPOS,
OSD0_HZOOM,
OSD0_VZOOM,
OSD1_HZOOM,
OSD1_VZOOM,
VID0_HZOOM,
VID0_VZOOM,
VID1_HZOOM,
VID1_VZOOM,
OSD1_WINDOW_BF,
OSD1_WINDOW_CK,
OSD1_CK,
OSD0_WINDOW_BF,
OSD0_WINDOW_CK,
OSD0_CK,
BLUE_COLOR,
RED_COLOR,
RAM_CLUT_IDX,
BITMAP_COLOR,
CURSOR_XPOS,
CURSOR_YPOS,
CURSOR_XRES,
CURSOR_YRES,
CURSOR_THICKNESS,
CURSOR_COLOR,
ATTR_BLINK_INTERVAL,
ATTR_BLEND_VAL,
};
static int preview_fd;
static int resizer_fd;
static int capture_fd = -1;
static int vid0_fd;
static int linearization_en;
static int csc_en;
static int vldfc_en;
static int en_culling;
static unsigned int n_buffers = 0;
static unsigned long oper_mode_1;
static unsigned long user_mode_1;
static struct rsz_channel_config rsz_chan_config; // resizer channel config
static struct rsz_single_shot_config rsz_ss_config;
static struct rsz_continuous_config rsz_ctn_config;
static struct prev_channel_config prev_chan_config;
static struct prev_single_shot_config prev_ss_config;
static struct prev_continuous_config prev_ctn_config;
static struct v4l2_format fmt;
static struct v4l2_streamparm parm;
static struct v4l2_requestbuffers reqbuf; // for display
static struct v4l2_requestbuffers req; // for capture
static struct buffer *buffers = NULL; // for capture
static struct buffer *vid0Buf; // for display
static struct fb_var_screeninfo vid1_varInfo, osd0_varInfo, osd1_varInfo,
prev_vid1_var, prev_osd0_var;
static struct fb_fix_screeninfo vid0_fixInfo, vid1_fixInfo, osd0_fixInfo,
osd1_fixInfo;
static int fd_vid0, fd_vid1, fd_osd0, fd_osd1;
static int vid0_size, vid1_size, osd0_size, osd1_size;
static char *vid0_display[VIDEO_NUM_BUFS];
static char *vid1_display[VIDEO_NUM_BUFS];
static char *osd0_display[OSD_NUM_BUFS];
static char *osd1_display[OSD_NUM_BUFS];
static void open_resizer(void);
static int parse_yee_table(void);
static void open_previewer(void);
static void open_capture(void);
static void capture_get_chip_id(void);
static void capture_query_capability(void);
static void capture_set_format(void);
static void capture_init_mmap(void);
static void capture_set_input(void);
static void ccdc_config_raw(void);
static void capture_start_streaming(void);
static void open_display_dev(void);
static void display_query_capability(void);
static void display_request_buffers(void);
static void display_set_format(void);
static void display_get_format(void);
static void display_init_mmap(void);
static void display_getinfo_control(void);
static void display_start_streaming(void);
static void start_loop(void);
static int open_all_windows(void);
static void close_all_windows(void);
static void init_vid1_device(void);
static void init_osd0_device(void);
static int mmap_vid1(void);
static int mmap_osd0(void);
static int disable_all_windows(void);
static int display_frame(char id, void *ptr_buffer);
int main(int argc, char **argv)
{
// open_device
open_resizer();
open_previewer();
open_capture();
open_all_windows();
// init_capture
//capture_get_chip_id();
capture_query_capability();
capture_set_format();
capture_init_mmap();
capture_set_input();
//ccdc_config_raw();
capture_start_streaming();
// init_display
open_display_dev();
display_query_capability();
display_request_buffers();
display_set_format();
display_get_format();
display_init_mmap();
//display_getinfo_control();
display_start_streaming();
// init_vid1_device();
// //init_osd0_device();
// mmap_vid1();
// //mmap_osd0();
// disable_all_windows();
start_loop();
// TODO: release device and memory
return 0;
}
static void open_resizer(void)
{
// oper_mode_1 = 0;
oper_mode_1 = IMP_MODE_CONTINUOUS;
// printf("Configuring resizer in the chain mode\n");
// printf("Opening resizer device, %s\n",dev_name_rsz);
resizer_fd = open(dev_name_rsz, O_RDWR);
if (ioctl(resizer_fd, RSZ_S_OPER_MODE, &oper_mode_1) < 0)
{
perror("Error in setting default configuration for oper mode\n");
close(resizer_fd);
}
if (ioctl(resizer_fd, RSZ_G_OPER_MODE, &user_mode_1) < 0)
{
perror("Error in getting default configuration for oper mode\n");
close(resizer_fd);
}
if (oper_mode_1 == user_mode_1)
{
// printf("RESIZER: Operating mode changed successfully to Continuous");
}
else
{
//printf("RESIZER: Couldn't change operation mode to Continuous");
close(resizer_fd);
}
rsz_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
rsz_chan_config.chain = 1;
rsz_chan_config.len = 0;
rsz_chan_config.config = NULL; /* to set defaults in driver */
if (ioctl(resizer_fd, RSZ_S_CONFIG, &rsz_chan_config) < 0)
{
perror("Error in setting default configuration for continuous mode\n");
close(resizer_fd);
}
CLEAR (rsz_ctn_config);
rsz_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
rsz_chan_config.chain = 1;
rsz_chan_config.len = sizeof(struct rsz_continuous_config);
rsz_chan_config.config = &rsz_ctn_config;
if (ioctl(resizer_fd, RSZ_G_CONFIG, &rsz_chan_config) < 0)
{
perror("Error in getting default configuration for continuous mode\n");
close(resizer_fd);
}
rsz_ctn_config.output1.enable = 1;
rsz_ctn_config.output2.enable = 0;
rsz_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
rsz_chan_config.chain = 1;
rsz_chan_config.len = sizeof(struct rsz_continuous_config);
rsz_chan_config.config = &rsz_ctn_config; /* to set defaults in driver */
if (ioctl(resizer_fd, RSZ_S_CONFIG, &rsz_chan_config) < 0) {
perror("Error in setting default configuration for continuous mode\n");
close(resizer_fd);
}
#if 0
// form planar_resize.c
/* getting physical address for mmap */
ch1_bufd.buf_type = RSZ_BUF_IN;
ch1_bufd.index = 0;
if (ioctl(ch1_fd, RSZ_QUERYBUF, &ch1_bufd) == -1)
{
printf("query buffer failed \n");
close(ch1_fd);
exit(-1);
}
ch1_resize.in_buf.offset = ch1_bufd.offset;
// from do_resize.c
bzero(&convert,sizeof(convert));
// bzero(output1_buffer.user_addr, output1_size);
// memcpy(input_buffer.user_addr, in_buf, size);
convert.in_buff.buf_type = IMP_BUF_IN;
convert.in_buff.index = -1;
//convert.in_buff.offset = (unsigned int)input_buffer.user_addr;
convert.in_buff.size = 400*400;
convert.out_buff1.buf_type = IMP_BUF_OUT1;
convert.out_buff1.index = -1;
// convert.out_buff1.offset = (unsigned int)output1_buffer.user_addr;
convert.out_buff1.size = 800*800;
if (ioctl(resizer_fd, RSZ_RESIZE, &convert) < 0)
{
perror("Error in doing resize\n");
ret = -1;
// goto out;
}
#endif
}
static int parse_yee_table(void)
{
int ret = -1, val, i;
FILE *fp;
fp = fopen(YEE_TABLE_FILE, "r");
if (fp == NULL) {
printf("Error in opening file %s\n", YEE_TABLE_FILE);
goto out;
}
for (i = 0; i < MAX_SIZE_YEE_LUT; i++) {
fscanf(fp, "%d", &val);
printf("%d,", val);
yee_table[i] = val & 0x1FF;
}
printf("\n");
if (i != MAX_SIZE_YEE_LUT)
goto clean_file;
ret = 0;
clean_file:
fclose(fp);
out:
return ret;
}
static void open_previewer(void)
{
oper_mode_1 = IMP_MODE_CONTINUOUS; // same as resizer
preview_fd = open(dev_name_prev, O_RDWR);
if(preview_fd <= 0)
{
printf("Cannot open previewer device\n");
close(preview_fd);
}
if (ioctl(preview_fd, PREV_S_OPER_MODE, &oper_mode_1) < 0)
{
perror("Can't set operation mode\n");
close(preview_fd);
}
if (ioctl(preview_fd, PREV_G_OPER_MODE, &user_mode_1) < 0)
{
perror("Can't get operation mode\n");
close(preview_fd);
}
if (oper_mode_1 == user_mode_1)
{
//printf("Operating mode changed successfully to continuous in previewer");
}
else
{
//printf("failed to set mode to continuous in previewer\n");
close(preview_fd);
}
prev_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
prev_chan_config.len = 0;
prev_chan_config.config = NULL; /* to set defaults in driver */
if (ioctl(preview_fd, PREV_S_CONFIG, &prev_chan_config) < 0)
{
perror("Error in setting default configuration\n");
close(preview_fd);
}
CLEAR (prev_ctn_config);
prev_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
prev_chan_config.len = sizeof(struct prev_continuous_config);
prev_chan_config.config = &prev_ctn_config;
if (ioctl(preview_fd, PREV_G_CONFIG, &prev_chan_config) < 0)
{
perror("Error in getting configuration from driver\n");
close(preview_fd);
}
prev_chan_config.oper_mode = IMP_MODE_CONTINUOUS;
prev_chan_config.len = sizeof(struct prev_continuous_config);
prev_chan_config.config = &prev_ctn_config;
#if 0
/*
Gb B
R Gr
*/
prev_ctn_config.input.colp_elep= IPIPE_RED;
prev_ctn_config.input.colp_elop= IPIPE_GREEN_RED;
prev_ctn_config.input.colp_olep= IPIPE_GREEN_BLUE;
prev_ctn_config.input.colp_olop= IPIPE_BLUE;
#endif
#if 0
/*
B Gb
Gr R
*/
prev_ctn_config.input.colp_elep= IPIPE_GREEN_RED;
prev_ctn_config.input.colp_elop= IPIPE_RED;
prev_ctn_config.input.colp_olep= IPIPE_BLUE;
prev_ctn_config.input.colp_olop= IPIPE_GREEN_BLUE;
#endif
#if 1
/*
Gr R
B Gb
*/
prev_ctn_config.input.colp_elep= IPIPE_BLUE;
prev_ctn_config.input.colp_elop= IPIPE_GREEN_BLUE;
prev_ctn_config.input.colp_olep= IPIPE_GREEN_RED;
prev_ctn_config.input.colp_olop= IPIPE_RED;
#endif
#if 0
/*
R Gr
Gb B
*/
prev_ctn_config.input.colp_elep= IPIPE_GREEN_BLUE;
prev_ctn_config.input.colp_elop= IPIPE_BLUE;
prev_ctn_config.input.colp_olep= IPIPE_RED;
prev_ctn_config.input.colp_olop= IPIPE_GREEN_RED;
#endif
if (ioctl(preview_fd, PREV_S_CONFIG, &prev_chan_config) < 0)
{
perror("Error in setting default configuration\n");
close(preview_fd);
}
struct prev_cap cap;
struct prev_module_param mod_param;
struct prev_wb wb;
struct prev_lum_adj lum_adj;
struct prev_gamma gamma;
struct prev_yee yee;
int ret;
cap.index=0;
while (1)
{
ret = ioctl(preview_fd , PREV_ENUM_CAP, &cap);
if (ret < 0)
{
break;
}
// find the defaults for this module
strcpy(mod_param.version,cap.version);
mod_param.module_id = cap.module_id;
// try set parameter for this module
if(cap.module_id == PREV_WB)
{
printf("cap.module_id == PREV_WB\n");
bzero((void *)&wb, sizeof (struct prev_wb));
wb.gain_r.integer = 1;
wb.gain_r.decimal = 0;
wb.gain_gr.integer = 1;
wb.gain_gr.decimal = 0;
wb.gain_gb.integer = 1;
wb.gain_gb.decimal = 0;
wb.gain_b.integer = 1;
wb.gain_b.decimal = 0;
wb.ofst_r = 0;
wb.ofst_gb = 0;
wb.ofst_b = 0;
mod_param.len = sizeof(struct prev_wb);
mod_param.param = &wb;
}
else if(cap.module_id == PREV_LUM_ADJ)
{
printf("cap.module_id == PREV_LUM_ADJ\n");
bzero((void *)&lum_adj, sizeof (struct prev_lum_adj));
lum_adj.brightness = 0;
lum_adj.contrast = 20;
mod_param.len = sizeof (struct prev_lum_adj);
mod_param.param = &lum_adj;
}
else if (cap.module_id == PREV_GAMMA)
{
printf("Setting gamma for %s\n", cap.module_name);
bzero((void *)&gamma, sizeof (struct prev_gamma));
gamma.bypass_r = 1;
gamma.bypass_b = 1;
gamma.bypass_g = 1;
gamma.tbl_sel = IPIPE_GAMMA_TBL_RAM;
gamma.tbl_size = IPIPE_GAMMA_TBL_SZ_512;
mod_param.len = sizeof (struct prev_gamma);
mod_param.param = γ
}
else if (cap.module_id == PREV_YEE)
{
printf("Setting Edge Enhancement for %s\n", cap.module_name);
bzero((void *)&yee, sizeof (struct prev_yee));
bzero((void *)&yee_table, sizeof (struct prev_yee));
yee.en = 1;
//yee.en_halo_red = 1;
yee.en_halo_red = 0;
//yee.merge_meth = IPIPE_YEE_ABS_MAX;
yee.merge_meth = IPIPE_YEE_EE_ES;
yee.hpf_shft = 6; // 5, 10
//yee.hpf_coef_00 = 8;
//yee.hpf_coef_01 = 2;
//yee.hpf_coef_02 = -2;
//yee.hpf_coef_10 = 2;
//yee.hpf_coef_11 = 0;
//yee.hpf_coef_12 = -1;
//yee.hpf_coef_20 = -2;
//yee.hpf_coef_21 = -1;
//yee.hpf_coef_22 = 0;
yee.hpf_coef_00 = 84,
yee.hpf_coef_01 = (-8 & 0x3FF),
yee.hpf_coef_02 = (-4 & 0x3FF),
yee.hpf_coef_10 = (-8 & 0x3FF),
yee.hpf_coef_11 = (-4 & 0x3FF),
yee.hpf_coef_12 = (-2 & 0x3FF),
yee.hpf_coef_20 = (-4 & 0x3FF),
yee.hpf_coef_21 = (-2 & 0x3FF),
yee.hpf_coef_22 = (-1 & 0x3FF),
yee.yee_thr = 20; //12
yee.es_gain = 128;
yee.es_thr1 = 768;
yee.es_thr2 = 32;
yee.es_gain_grad = 32;
yee.es_ofst_grad = 0;
if(parse_yee_table() <0)
{
printf("read yee table error.\n");
}
yee.table = yee_table;
mod_param.len = sizeof (struct prev_yee);
mod_param.param = &yee;
}
else
{
// using defaults
printf("Setting default for %s\n", cap.module_name);
mod_param.param = NULL;
}
if (ioctl(preview_fd, PREV_S_PARAM, &mod_param) < 0)
{
printf("Error in Setting %s params from driver\n", cap.module_name);
close(preview_fd);
//exit (EXIT_FAILURE);
}
cap.index++;
}
}
static void open_capture(void)
{
capture_fd = open(CAPTURE_DEVICE, O_RDWR | O_NONBLOCK, 0);
if (-1 == capture_fd)
{
fprintf (stderr, "Cannot open '%s': %d, %s\n", CAPTURE_DEVICE, errno, strerror (errno));
exit (EXIT_FAILURE);
}
}
static void capture_get_chip_id(void)
{
struct v4l2_dbg_chip_ident chip;
CLEAR (chip);
if (ioctl(capture_fd, VIDIOC_DBG_G_CHIP_IDENT, &chip))
{
printf("VIDIOC_DBG_G_CHIP_IDENT failed.\n");
//return FAIL;
}
else
{
printf("sensor chip is %s\n", chip.match.name);
}
}
static void capture_query_capability(void)
{
struct v4l2_capability cap;
struct v4l2_fmtdesc fmtdesc;
CLEAR (cap);
if (ioctl(capture_fd, VIDIOC_QUERYCAP, &cap))
{
printf("VIDIOC_QUERYCAP failed. %s is no V4L2 device\n", CAPTURE_DEVICE);
//return FAIL;
}
else
{
printf("%s is a V4L2 device\n", CAPTURE_DEVICE);
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
fprintf (stderr, "%s is no video capture device\n", CAPTURE_DEVICE);
exit (EXIT_FAILURE);
}
#if 0
else
{
printf("%s is a video capture device\n", CAPTURE_DEVICE);
}
if (!(cap.capabilities & V4L2_CAP_READWRITE))
{
printf("It can not be read\n");
}
else
{
printf("It can be read\n");
}
if (!(cap.capabilities & V4L2_CAP_STREAMING))
{
printf("It can not streaming\n");
}
else
{
printf("It can streaming\n");
}
#endif
}
// TODO: VIDIOC_CROPCAP
CLEAR (fmtdesc);
fmtdesc.index=0;
fmtdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
// printf("Supportformat:\n");
while(ioctl(capture_fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
{
// printf("\tfmt_desc.index = %d\n", fmtdesc.index);
// printf(format,args...)("\tfmt_desc.type = %d\n", fmtdesc.type);
// printf("\tfmt_desc.description = %s\n", fmtdesc.description);
// printf("\tfmt_desc.pixelformat = %x\n", fmtdesc.pixelformat);
// //printf("\t%d.%s\n",fmtdesc.index+1,fmtdesc.description);
fmtdesc.index++;
}
// TODO: VIDIOC_TRY_FMT
}
static void capture_set_format(void)
{
CLEAR (fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(capture_fd, VIDIOC_G_FMT, &fmt);
CLEAR (fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = 384;
fmt.fmt.pix.height = 384;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV12;
//fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV21;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
//fmt.fmt.pix.bytesperline=2560;
printf("pixelformat = %x\n",fmt.fmt.pix.pixelformat);
if (ioctl(capture_fd, VIDIOC_S_FMT, &fmt))
{
printf("VIDIOC_S_FMT failed.\n");
//return FAIL;
}
// frame-rate
CLEAR (parm);
parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
parm.parm.capture.timeperframe.numerator = 1;
parm.parm.capture.timeperframe.denominator = 60;
parm.parm.capture.capturemode = 0;
if (-1 == ioctl(capture_fd, VIDIOC_S_PARM, &parm))
{
//printf("VIDIOC_S_PARM failed ");
}
// else
// {
// printf("VIDIOC_S_PARM SUCCESS!\n");
// }
if (-1 == ioctl(capture_fd, VIDIOC_G_PARM, &parm))
{
printf("VIDIOC_G_PARM failed ");
}
else
{
printf("streamparm:\n\tnumerator =%d\n\tdenominator=%d\n\tcapturemode=%d\n\n",
parm.parm.capture.timeperframe.numerator,
parm.parm.capture.timeperframe.denominator,
parm.parm.capture.capturemode);
}
}
static void capture_init_mmap(void)
{
static struct v4l2_buffer buf;
CLEAR (req);
req.count = 3;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
if (ioctl(capture_fd, VIDIOC_REQBUFS, &req))
{
printf("VIDIOC_REQBUFS failed.\n");
//return FAIL;
}
else
{
printf("success: request buffers for capture\n");
}
// 2 is minimum buffers
if (req.count < 2)
{
fprintf (stderr, "Insufficient buffer memory on %s\n", CAPTURE_DEVICE);
exit (EXIT_FAILURE);
}
// request buffer
buffers = calloc (req.count, sizeof (*buffers));
if (!buffers)
{
//fprintf (stderr, "Out of memory\n");
printf("fail: Out of memory for capture\n");
exit (EXIT_FAILURE);
}
// else
// {
// printf("success in init_capture_buffers calloc\n");
// }
// query buffer status
for (n_buffers = 0; n_buffers < req.count; ++n_buffers)
{
// printf("process n_buffers %d\n", n_buffers);
CLEAR (buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers;
if (-1 == ioctl (capture_fd, VIDIOC_QUERYBUF, &buf))
{
printf("fail: in init_capture_buffers: VIDIOC_QUERYBUF\n");
//fprintf (stderr, "%s error %d, %s\n", s, errno, strerror (errno));
exit (EXIT_FAILURE);
}
else
{
printf("success: query buffers for capture\n");
// printf("buffer.length = %d\n",buf.length);
// printf("buffer.bytesused = %d\n",buf.bytesused);
}
buffers[n_buffers].length = buf.length;
buffers[n_buffers].start = mmap (NULL /* start anywhere */ ,
buf.length,
PROT_READ | PROT_WRITE /* required */ ,
MAP_SHARED /* recommended */ ,
capture_fd, buf.m.offset);
printf("buffer:%d phy:%x mmap:%p length:%d\n",
buf.index,
buf.m.offset,
buffers[n_buffers].start,
buf.length);
if (MAP_FAILED == buffers[n_buffers].start)
{
printf("failed in init_capture_buffers: mmap\n");
exit (EXIT_FAILURE);
}
// else
// {
// printf("success in init_capture_buffers mmap\n");
// }
}
}
static void capture_set_input(void)
{
struct v4l2_input input;
int ret;
input.type = V4L2_INPUT_TYPE_CAMERA;
input.index = 0;
// query input device
while ((ret = ioctl(capture_fd,VIDIOC_ENUMINPUT, &input) == 0))
{
printf("input.name = %s at input.index = %d\n", input.name, input.index);
input.index++;