forked from LineageOS/android_device_samsung_smdk4412-common
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexynos_camera.c
3883 lines (3062 loc) · 109 KB
/
exynos_camera.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
/*
* Copyright (C) 2013 Paul Kocialkowski
*
* Based on crespo libcamera and exynos4 hal libcamera:
* Copyright 2008, The Android Open Source Project
* Copyright 2010, Samsung Electronics Co. LTD
*
* 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/>.
*/
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#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 <asm/types.h>
#define LOG_TAG "exynos_camera"
#include <utils/Log.h>
#include <utils/Timers.h>
#include "exynos_camera.h"
#define BIG2LITTLE_ENDIAN(big) ((big & 0xff) << 24 | (big & 0xff00) << 8 | (big & 0xff0000) >> 8 | (big & 0xff000000) >> 24)
/*
* Devices configurations
*/
struct exynos_camera_mbus_resolution exynos_camera_mbus_resolutions_s5k6a3_smdk4x12[] = {
// 16:9 ratio
{ 1280, 720, 1344, 756 },
// 4:3 ratio
{ 1280, 960, 1392, 1044 },
{ 960, 720, 1392, 1044 },
{ 640, 480, 1392, 1044 },
{ 320, 240, 1392, 1044 },
// 1:1 ratio
{ 1392, 1392, 1392, 1392 },
{ 704, 704, 1392, 1392 },
{ 320, 320, 1392, 1392 },
};
struct exynos_camera_videosnapshot_resolution exynos_camera_videosnapshot_resolutions_s5c73m3[] = {
//Capture Size - Snapshot Size
{ 1920, 1080, 3264, 1836 },
{ 1280, 720, 3264, 1836 },
{ 720, 480, 3264, 2176 },
{ 640, 480, 3264, 2488 },
{ 352, 288, 3264, 2488 },
{ 320, 240, 3264, 2488 },
{ 176, 144, 3264, 2488 },
};
struct exynos_camera_preset exynos_camera_presets_smdk4x12[] = {
{
.name = "S5C73M3",
.facing = CAMERA_FACING_BACK,
.orientation = 90,
.rotation = 0,
.hflip = 0,
.vflip = 0,
.capture_format = V4L2_PIX_FMT_INTERLEAVED,
.picture_format = V4L2_PIX_FMT_JPEG,
.fimc_is = 0,
.focal_length = 3.7f,
.horizontal_view_angle = 63.0f,
.vertical_view_angle = 49.3f,
.metering = METERING_CENTER,
.params = {
.preview_size_values = "960x720,1280x720,640x480,352x288,320x240",
.preview_size = "960x720",
.preview_video_size = "1280x720",
.preview_format_values = "yuv420sp,rgb565",
.preview_format = "yuv420sp",
.preview_frame_rate_values = "30,20,15",
.preview_frame_rate = 30,
.preview_fps_range_values = "(15000,15000),(15000,30000),(30000,30000)",
.preview_fps_range = "15000,30000",
.picture_size_values = "640x480,1024x768,1280x720,1600x1200,2560x1920,3264x2448,2048x1536,3264x1836,2048x1152,3264x2176",
.picture_size = "3264x2448",
.picture_format_values = "jpeg",
.picture_format = "jpeg",
.jpeg_thumbnail_size_values = "160x120,160x90,144x96",
.jpeg_thumbnail_width = 160,
.jpeg_thumbnail_height = 120,
.jpeg_thumbnail_quality = 100,
.jpeg_quality = 90,
.video_snapshot_supported = 1,
.full_video_snap_supported = 0,
.recording_size = "1280x720",
.recording_size_values = "1920x1080,1280x720,720x480,640x480,352x288,320x240,176x144",
.recording_format = "yuv420sp",
.focus_mode = "auto",
.focus_mode_values = "auto,infinity,macro,fixed,continuous-picture,continuous-video",
.focus_distances = "0.15,1.20,Infinity",
.focus_areas = "(0,0,0,0,0)",
.max_num_focus_areas = 1,
.max_detected_faces = 15,
.zoom_supported = 1,
.smooth_zoom_supported = 0,
.zoom_ratios = "100,102,104,109,111,113,119,121,124,131,134,138,146,150,155,159,165,170,182,189,200,213,222,232,243,255,283,300,319,364,400",
.zoom = 0,
.max_zoom = 30,
.auto_exposure_lock_supported = 1,
.auto_exposure_lock = 0,
.auto_white_balance_lock_supported = 1,
.auto_white_balance_lock = 0,
.flash_mode = "off",
.flash_mode_values = "off,auto,on,torch",
.exposure_compensation = 0,
.exposure_compensation_step = 0.5,
.min_exposure_compensation = -4,
.max_exposure_compensation = 4,
.whitebalance = "auto",
.whitebalance_values = "auto,incandescent,fluorescent,daylight,cloudy-daylight",
.antibanding = "auto",
.antibanding_values = "off,auto,50hz,60hz",
.scene_mode = "auto",
.scene_mode_values = "auto,portrait,landscape,night,beach,snow,sunset,fireworks,action,party,candlelight,dusk-dawn,fall-color,text,back-light,high-sensitivity",
.effect = "none",
.effect_values = "none,mono,negative,sepia,solarize,posterize,washed,vintage-warm,vintage-cold,point-blue,point-red-yellow,point-green",
.iso = "auto",
.iso_values = "auto,ISO100,ISO200,ISO400,ISO800",
.image_stabilization = "off",
.image_stabilization_values = "on,off",
},
.mbus_resolutions = NULL,
.mbus_resolutions_count = 0,
.videosnapshot_resolutions = (struct exynos_camera_videosnapshot_resolution *) &exynos_camera_videosnapshot_resolutions_s5c73m3,
.videosnapshot_resolutions_count = 7,
},
{
.name = "S5K6A3",
.facing = CAMERA_FACING_FRONT,
.orientation = 270,
.rotation = 0,
.hflip = 0,
.vflip = 0,
.capture_format = V4L2_PIX_FMT_UYVY,
.picture_format = V4L2_PIX_FMT_JPEG,
.fimc_is = 1,
.focal_length = 2.73f,
.horizontal_view_angle = 52.58f,
.vertical_view_angle = 52.58f,
.metering = METERING_CENTER,
.params = {
.preview_size_values = "1280x720,960x720,640x480,320x240,704x704,320x320",
.preview_size = "960x720",
.preview_video_size = "1280x720",
.preview_format_values = "yuv420sp,rgb565",
.preview_format = "yuv420sp",
.preview_frame_rate_values = "30,20,15,8",
.preview_frame_rate = 30,
.preview_fps_range_values = "(8000,8000),(15000,15000),(15000,30000),(30000,30000)",
.preview_fps_range = "15000,30000",
.picture_size_values = "1280x960,1392x1392,640x480,1280x720,720x480,320x240",
.picture_size = "1280x960",
.picture_format_values = "jpeg",
.picture_format = "jpeg",
.jpeg_thumbnail_size_values = "160x120,160x160,160x90,144x96",
.jpeg_thumbnail_width = 160,
.jpeg_thumbnail_height = 120,
.jpeg_thumbnail_quality = 100,
.jpeg_quality = 90,
.video_snapshot_supported = 1,
.full_video_snap_supported = 1,
.recording_size = "1280x720",
.recording_size_values = "1280x720,720x480,640x480,352x288,320x320,320x240,176x144",
.recording_format = "yuv420sp",
.focus_mode = "fixed",
.focus_mode_values = "infinity,fixed",
.focus_distances = "0.20,0.25,Infinity",
.focus_areas = NULL,
.max_num_focus_areas = 0,
.zoom_supported = 0,
.auto_exposure_lock_supported = 0,
.auto_exposure_lock = 0,
.auto_white_balance_lock_supported = 0,
.auto_white_balance_lock = 0,
.flash_mode = NULL,
.flash_mode_values = NULL,
.max_detected_faces = 5,
.exposure_compensation = 0,
.exposure_compensation_step = 0.5,
.min_exposure_compensation = -4,
.max_exposure_compensation = 4,
.whitebalance = "auto",
.whitebalance_values = "auto,incandescent,fluorescent,daylight,cloudy-daylight",
.antibanding = NULL,
.antibanding_values = NULL,
.scene_mode = NULL,
.scene_mode_values = NULL,
.effect = "none",
.effect_values = "none,mono,negative,sepia,solarize,posterize,washed,vintage-warm,vintage-cold,point-blue,point-red-yellow,point-green",
.iso = "auto",
.iso_values = "auto",
.image_stabilization = "off",
.image_stabilization_values = "off",
},
.mbus_resolutions = (struct exynos_camera_mbus_resolution *) &exynos_camera_mbus_resolutions_s5k6a3_smdk4x12,
.mbus_resolutions_count = 8,
},
};
struct exynos_v4l2_node exynos_v4l2_nodes_smdk4x12[] = {
{ // FIMC0 is used for capture
.id = 0,
.node = "/dev/video0",
},
{ // FIMC1 is used for preview output
.id = 1,
.node = "/dev/video1",
},
{ // FIMC2 is used for picture output
.id = 2,
.node = "/dev/video2",
},
{ // FIMC3 is used for recording output
.id = 3,
.node = "/dev/video3",
},
};
struct exynox_camera_config exynos_camera_config_smdk4x12 = {
.presets = (struct exynos_camera_preset *) &exynos_camera_presets_smdk4x12,
.presets_count = 2,
.v4l2_nodes = (struct exynos_v4l2_node *) &exynos_v4l2_nodes_smdk4x12,
.v4l2_nodes_count = 4,
};
/*
* Exynos Camera
*/
struct exynox_camera_config *exynos_camera_config =
&exynos_camera_config_smdk4x12;
int exynos_camera_start(struct exynos_camera *exynos_camera, int id)
{
int rc;
if (exynos_camera == NULL || id >= exynos_camera->config->presets_count)
return -EINVAL;
// ION
#ifdef EXYNOS_ION
rc = exynos_ion_init(exynos_camera);
if (rc < 0) {
ALOGE("%s: Unable to init ION", __func__);
goto error;
}
rc = exynos_ion_open(exynos_camera);
if (rc < 0) {
ALOGE("%s: Unable to open ION", __func__);
goto error;
}
#endif
// V4L2
rc = exynos_v4l2_init(exynos_camera);
if (rc < 0) {
ALOGE("%s: Unable to init v4l2", __func__);
goto error;
}
// FIMC0
rc = exynos_v4l2_open(exynos_camera, 0);
if (rc < 0) {
ALOGE("%s: Unable to open v4l2 device", __func__);
goto error;
}
rc = exynos_v4l2_querycap_cap(exynos_camera, 0);
if (rc < 0) {
ALOGE("%s: Unable to query capabilities", __func__);
goto error;
}
rc = exynos_v4l2_enum_input(exynos_camera, 0, id);
if (rc < 0) {
ALOGE("%s: Unable to enumerate input", __func__);
goto error;
}
rc = exynos_v4l2_s_input(exynos_camera, 0, id);
if (rc < 0) {
ALOGE("%s: Unable to set inputs", __func__);
goto error;
}
// Recording
exynos_camera->recording_metadata = 1;
// Params
rc = exynos_camera_params_init(exynos_camera, id);
if (rc < 0) {
ALOGE("%s: Unable to init params", __func__);
goto error;
}
// Gralloc
rc = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const struct hw_module_t **) &exynos_camera->gralloc);
if (rc)
ALOGE("%s: Unable to get gralloc module", __func__);
rc = 0;
goto complete;
error:
exynos_v4l2_close(exynos_camera, 0);
#ifdef EXYNOS_ION
exynos_ion_close(exynos_camera);
#endif
rc = -1;
complete:
return rc;
}
void exynos_camera_stop(struct exynos_camera *exynos_camera)
{
int i;
int id;
if (exynos_camera == NULL || exynos_camera->config == NULL)
return;
exynos_v4l2_close(exynos_camera, 0);
#ifdef EXYNOS_ION
exynos_ion_close(exynos_camera);
#endif
}
// Params
int exynos_camera_params_init(struct exynos_camera *exynos_camera, int id)
{
int rc;
if (exynos_camera == NULL || id >= exynos_camera->config->presets_count)
return -EINVAL;
// Camera params
exynos_camera->camera_rotation = exynos_camera->config->presets[id].rotation;
exynos_camera->camera_hflip = exynos_camera->config->presets[id].hflip;
exynos_camera->camera_vflip = exynos_camera->config->presets[id].vflip;
exynos_camera->camera_capture_format = exynos_camera->config->presets[id].capture_format;
exynos_camera->camera_picture_format = exynos_camera->config->presets[id].picture_format;
exynos_camera->camera_fimc_is = exynos_camera->config->presets[id].fimc_is;
exynos_camera->camera_focal_length = (int) (exynos_camera->config->presets[id].focal_length * 100);
exynos_camera->camera_metering = exynos_camera->config->presets[id].metering;
exynos_camera->camera_mbus_resolutions = exynos_camera->config->presets[id].mbus_resolutions;
exynos_camera->camera_mbus_resolutions_count = exynos_camera->config->presets[id].mbus_resolutions_count;
exynos_camera->camera_videosnapshot_resolutions = exynos_camera->config->presets[id].videosnapshot_resolutions;
exynos_camera->camera_videosnapshot_resolutions_count = exynos_camera->config->presets[id].videosnapshot_resolutions_count;
// Recording preview
exynos_param_string_set(exynos_camera, "preferred-preview-size-for-video",
exynos_camera->config->presets[id].params.preview_video_size);
// Preview
exynos_param_string_set(exynos_camera, "preview-size-values",
exynos_camera->config->presets[id].params.preview_size_values);
exynos_param_string_set(exynos_camera, "preview-size",
exynos_camera->config->presets[id].params.preview_size);
exynos_param_string_set(exynos_camera, "preview-format-values",
exynos_camera->config->presets[id].params.preview_format_values);
exynos_param_string_set(exynos_camera, "preview-format",
exynos_camera->config->presets[id].params.preview_format);
exynos_param_string_set(exynos_camera, "preview-frame-rate-values",
exynos_camera->config->presets[id].params.preview_frame_rate_values);
exynos_param_int_set(exynos_camera, "preview-frame-rate",
exynos_camera->config->presets[id].params.preview_frame_rate);
exynos_param_string_set(exynos_camera, "preview-fps-range-values",
exynos_camera->config->presets[id].params.preview_fps_range_values);
exynos_param_string_set(exynos_camera, "preview-fps-range",
exynos_camera->config->presets[id].params.preview_fps_range);
// Picture
exynos_param_string_set(exynos_camera, "picture-size-values",
exynos_camera->config->presets[id].params.picture_size_values);
exynos_param_string_set(exynos_camera, "picture-size",
exynos_camera->config->presets[id].params.picture_size);
exynos_param_string_set(exynos_camera, "picture-format-values",
exynos_camera->config->presets[id].params.picture_format_values);
exynos_param_string_set(exynos_camera, "picture-format",
exynos_camera->config->presets[id].params.picture_format);
exynos_param_string_set(exynos_camera, "jpeg-thumbnail-size-values",
exynos_camera->config->presets[id].params.jpeg_thumbnail_size_values);
exynos_param_int_set(exynos_camera, "jpeg-thumbnail-width",
exynos_camera->config->presets[id].params.jpeg_thumbnail_width);
exynos_param_int_set(exynos_camera, "jpeg-thumbnail-height",
exynos_camera->config->presets[id].params.jpeg_thumbnail_height);
exynos_param_int_set(exynos_camera, "jpeg-thumbnail-quality",
exynos_camera->config->presets[id].params.jpeg_thumbnail_quality);
exynos_param_int_set(exynos_camera, "jpeg-quality",
exynos_camera->config->presets[id].params.jpeg_quality);
if (exynos_camera->config->presets[id].params.video_snapshot_supported == 1)
exynos_param_string_set(exynos_camera, "video-snapshot-supported", "true");
if (exynos_camera->config->presets[id].params.full_video_snap_supported == 1)
exynos_param_string_set(exynos_camera, "full-video-snap-supported", "true");
// Recording
exynos_param_string_set(exynos_camera, "video-size",
exynos_camera->config->presets[id].params.recording_size);
exynos_param_string_set(exynos_camera, "video-size-values",
exynos_camera->config->presets[id].params.recording_size_values);
exynos_param_string_set(exynos_camera, "video-frame-format",
exynos_camera->config->presets[id].params.recording_format);
// Focus
exynos_param_string_set(exynos_camera, "focus-mode",
exynos_camera->config->presets[id].params.focus_mode);
exynos_param_string_set(exynos_camera, "focus-mode-values",
exynos_camera->config->presets[id].params.focus_mode_values);
exynos_param_string_set(exynos_camera, "focus-distances",
exynos_camera->config->presets[id].params.focus_distances);
if (exynos_camera->config->presets[id].params.max_num_focus_areas > 0) {
exynos_param_string_set(exynos_camera, "focus-areas",
exynos_camera->config->presets[id].params.focus_areas);
sprintf(exynos_camera->raw_focus_areas,"%s",
exynos_camera->config->presets[id].params.focus_areas);
exynos_param_int_set(exynos_camera, "max-num-focus-areas",
exynos_camera->config->presets[id].params.max_num_focus_areas);
}
// Face Detection
exynos_camera->max_detected_faces = exynos_camera->config->presets[id].params.max_detected_faces;
exynos_param_int_set(exynos_camera, "max-num-detected-faces-hw",
exynos_camera->max_detected_faces);
// Zoom
if (exynos_camera->config->presets[id].params.zoom_supported == 1) {
exynos_param_string_set(exynos_camera, "zoom-supported", "true");
if (exynos_camera->config->presets[id].params.smooth_zoom_supported == 1)
exynos_param_string_set(exynos_camera, "smooth-zoom-supported", "true");
if (exynos_camera->config->presets[id].params.zoom_ratios != NULL)
exynos_param_string_set(exynos_camera, "zoom-ratios", exynos_camera->config->presets[id].params.zoom_ratios);
exynos_param_int_set(exynos_camera, "zoom", exynos_camera->config->presets[id].params.zoom);
exynos_param_int_set(exynos_camera, "max-zoom", exynos_camera->config->presets[id].params.max_zoom);
} else {
exynos_param_string_set(exynos_camera, "zoom-supported", "false");
}
// AE lock
if (exynos_camera->config->presets[id].params.auto_exposure_lock_supported == 1) {
exynos_param_string_set(exynos_camera, "auto-exposure-lock-supported", "true");
if (exynos_camera->config->presets[id].params.auto_exposure_lock)
exynos_param_string_set(exynos_camera, "auto-exposure-lock", "true");
else
exynos_param_string_set(exynos_camera, "auto-exposure-lock", "false");
}
// AWB lock
if (exynos_camera->config->presets[id].params.auto_white_balance_lock_supported == 1) {
exynos_param_string_set(exynos_camera, "auto-whitebalance-lock-supported", "true");
if (exynos_camera->config->presets[id].params.auto_white_balance_lock)
exynos_param_string_set(exynos_camera, "auto-whitebalance-lock", "true");
else
exynos_param_string_set(exynos_camera, "auto-whitebalance-lock", "false");
}
// Flash
exynos_param_string_set(exynos_camera, "flash-mode",
exynos_camera->config->presets[id].params.flash_mode);
exynos_param_string_set(exynos_camera, "flash-mode-values",
exynos_camera->config->presets[id].params.flash_mode_values);
// Exposure
exynos_param_int_set(exynos_camera, "exposure-compensation",
exynos_camera->config->presets[id].params.exposure_compensation);
exynos_param_float_set(exynos_camera, "exposure-compensation-step",
exynos_camera->config->presets[id].params.exposure_compensation_step);
exynos_param_int_set(exynos_camera, "min-exposure-compensation",
exynos_camera->config->presets[id].params.min_exposure_compensation);
exynos_param_int_set(exynos_camera, "max-exposure-compensation",
exynos_camera->config->presets[id].params.max_exposure_compensation);
// Antibanding
exynos_param_string_set(exynos_camera, "antibanding",
exynos_camera->config->presets[id].params.antibanding);
exynos_param_string_set(exynos_camera, "antibanding-values",
exynos_camera->config->presets[id].params.antibanding_values);
// WB
exynos_param_string_set(exynos_camera, "whitebalance",
exynos_camera->config->presets[id].params.whitebalance);
exynos_param_string_set(exynos_camera, "whitebalance-values",
exynos_camera->config->presets[id].params.whitebalance_values);
// Scene mode
exynos_param_string_set(exynos_camera, "scene-mode",
exynos_camera->config->presets[id].params.scene_mode);
exynos_param_string_set(exynos_camera, "scene-mode-values",
exynos_camera->config->presets[id].params.scene_mode_values);
// Effect
exynos_param_string_set(exynos_camera, "effect",
exynos_camera->config->presets[id].params.effect);
exynos_param_string_set(exynos_camera, "effect-values",
exynos_camera->config->presets[id].params.effect_values);
// ISO
exynos_param_string_set(exynos_camera, "iso",
exynos_camera->config->presets[id].params.iso);
exynos_param_string_set(exynos_camera, "iso-values",
exynos_camera->config->presets[id].params.iso_values);
// Image stabilization (Anti-shake)
exynos_param_string_set(exynos_camera, "image-stabilization",
exynos_camera->config->presets[id].params.image_stabilization);
exynos_param_string_set(exynos_camera, "image-stabilization-values",
exynos_camera->config->presets[id].params.image_stabilization_values);
// Camera
exynos_param_float_set(exynos_camera, "focal-length",
exynos_camera->config->presets[id].focal_length);
exynos_param_float_set(exynos_camera, "horizontal-view-angle",
exynos_camera->config->presets[id].horizontal_view_angle);
exynos_param_float_set(exynos_camera, "vertical-view-angle",
exynos_camera->config->presets[id].vertical_view_angle);
rc = exynos_camera_params_apply(exynos_camera, 1);
if (rc < 0) {
ALOGE("%s: Unable to apply params", __func__);
return -1;
}
return 0;
}
static int validate_focus_areas(int l, int t, int r, int b, int w) {
if (!(l || r || t || b || w)) {
// All zeros is a valid area
return 0;
}
// If existing, a focus area must be contained between -1000 and 1000,
// on both dimensions
if (l < -1000 || t < -1000 || r > 1000 || b > 1000) {
return -EINVAL;
}
// No superimposed or reverted edges
if (l >= r || t >= b) {
return -EINVAL;
}
// If there's an area defined, weight must be positive and up to 1000
if ((l !=0 || r !=0) && (w < 1 || w > 1000)) {
return -EINVAL;
}
return 0;
}
int exynos_camera_params_apply(struct exynos_camera *exynos_camera, int force)
{
char *recording_hint_string;
char *recording_preview_size_string;
char *preview_size_string;
int preview_width = 0;
int preview_height = 0;
char *preview_format_string;
int preview_format;
int preview_fps;
char *picture_size_string;
int picture_width = 0;
int picture_height = 0;
char *picture_format_string;
int picture_format;
int jpeg_thumbnail_width;
int jpeg_thumbnail_height;
int jpeg_thumbnail_quality;
int jpeg_quality;
char *video_size_string;
int recording_width = 0;
int recording_height = 0;
char *video_frame_format_string;
int recording_format;
int camera_sensor_mode;
int fimc_is_mode = 0;
char *focus_mode_string;
int focus_mode = FOCUS_MODE_DEFAULT;
char *focus_areas_string;
int focus_left, focus_top, focus_right, focus_bottom, focus_weight;
int focus_x;
int focus_y;
char *zoom_supported_string;
int zoom, max_zoom;
char *ae_lock_supported_string;
char *ae_lock_string;
int ae_lock = 0;
char *awb_lock_supported_string;
char *awb_lock_string;
int awb_lock = 0;
int aeawb = 0;
char *flash_mode_string;
int flash_mode = 0;
int exposure_compensation;
int min_exposure_compensation;
int max_exposure_compensation;
char *antibanding_string;
int antibanding;
char *whitebalance_string;
int whitebalance;
char *scene_mode_string;
int scene_mode;
char *effect_string;
int effect;
char *iso_string;
int iso;
char *image_stabilization_string;
int image_stabilization;
int w, h;
char *k;
int rc, i;
if (exynos_camera == NULL)
return -EINVAL;
// Preview
preview_size_string = exynos_param_string_get(exynos_camera, "preview-size");
if (preview_size_string != NULL) {
sscanf(preview_size_string, "%dx%d", &preview_width, &preview_height);
if (preview_width < 0 && preview_height < 0) {
char reset_preview[128];
sprintf(reset_preview, "%dx%d", exynos_camera->preview_width, exynos_camera->preview_height);
exynos_param_string_set(exynos_camera, "preview-size",
reset_preview);
return -EINVAL;
}
if (preview_width != 0 && preview_width != exynos_camera->preview_width)
exynos_camera->preview_width = preview_width;
if (preview_height != 0 && preview_height != exynos_camera->preview_height)
exynos_camera->preview_height = preview_height;
}
preview_format_string = exynos_param_string_get(exynos_camera, "preview-format");
if (preview_format_string != NULL) {
if (strcmp(preview_format_string, "yuv420sp") == 0) {
preview_format = V4L2_PIX_FMT_NV21;
} else if (strcmp(preview_format_string, "yuv420p") == 0) {
preview_format = V4L2_PIX_FMT_YUV420;
} else if (strcmp(preview_format_string, "rgb565") == 0) {
preview_format = V4L2_PIX_FMT_RGB565;
} else if (strcmp(preview_format_string, "rgb8888") == 0) {
preview_format = V4L2_PIX_FMT_RGB32;
} else {
ALOGE("%s: Unsupported preview format: %s", __func__, preview_format_string);
preview_format = V4L2_PIX_FMT_NV21;
}
if (preview_format != exynos_camera->preview_format)
exynos_camera->preview_format = preview_format;
}
preview_fps = exynos_param_int_get(exynos_camera, "preview-frame-rate");
if (preview_fps > 0)
exynos_camera->preview_fps = preview_fps;
else
exynos_camera->preview_fps = 0;
// Picture
picture_format_string = exynos_param_string_get(exynos_camera, "picture-format");
if (picture_format_string != NULL) {
if (strcmp(picture_format_string, "jpeg") == 0) {
picture_format = V4L2_PIX_FMT_JPEG;
} else {
ALOGE("%s: Unsupported picture format: %s", __func__, picture_format_string);
picture_format = V4L2_PIX_FMT_JPEG;
}
if (picture_format != exynos_camera->picture_format)
exynos_camera->picture_format = picture_format;
}
jpeg_thumbnail_width = exynos_param_int_get(exynos_camera, "jpeg-thumbnail-width");
if (jpeg_thumbnail_width > 0)
exynos_camera->jpeg_thumbnail_width = jpeg_thumbnail_width;
jpeg_thumbnail_height = exynos_param_int_get(exynos_camera, "jpeg-thumbnail-height");
if (jpeg_thumbnail_height > 0)
exynos_camera->jpeg_thumbnail_height = jpeg_thumbnail_height;
jpeg_thumbnail_quality = exynos_param_int_get(exynos_camera, "jpeg-thumbnail-quality");
if (jpeg_thumbnail_quality > 0)
exynos_camera->jpeg_thumbnail_quality = jpeg_thumbnail_quality;
jpeg_quality = exynos_param_int_get(exynos_camera, "jpeg-quality");
if (jpeg_quality <= 100 && jpeg_quality >= 0 && (jpeg_quality != exynos_camera->jpeg_quality || force)) {
exynos_camera->jpeg_quality = jpeg_quality;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAM_JPEG_QUALITY, jpeg_quality);
if (rc < 0)
ALOGE("%s: Unable to set jpeg quality", __func__);
}
// Recording
video_size_string = exynos_param_string_get(exynos_camera, "video-size");
if (video_size_string == NULL)
video_size_string = exynos_param_string_get(exynos_camera, "preview-size");
if (video_size_string != NULL) {
sscanf(video_size_string, "%dx%d", &recording_width, &recording_height);
if (recording_width != 0 && recording_width != exynos_camera->recording_width)
exynos_camera->recording_width = recording_width;
if (recording_height != 0 && recording_height != exynos_camera->recording_height)
exynos_camera->recording_height = recording_height;
}
video_frame_format_string = exynos_param_string_get(exynos_camera, "video-frame-format");
if (video_frame_format_string != NULL) {
if (strcmp(video_frame_format_string, "yuv420sp") == 0) {
recording_format = V4L2_PIX_FMT_NV12;
} else if (strcmp(video_frame_format_string, "yuv420p") == 0) {
recording_format = V4L2_PIX_FMT_YUV420;
} else if (strcmp(video_frame_format_string, "rgb565") == 0) {
recording_format = V4L2_PIX_FMT_RGB565;
} else if (strcmp(video_frame_format_string, "rgb8888") == 0) {
recording_format = V4L2_PIX_FMT_RGB32;
} else {
ALOGE("%s: Unsupported recording format: %s", __func__, video_frame_format_string);
recording_format = V4L2_PIX_FMT_NV12;
}
if (recording_format != exynos_camera->recording_format)
exynos_camera->recording_format = recording_format;
}
recording_hint_string = exynos_param_string_get(exynos_camera, "recording-hint");
if (recording_hint_string != NULL && strcmp(recording_hint_string, "true") == 0) {
camera_sensor_mode = SENSOR_MOVIE;
k = exynos_param_string_get(exynos_camera, "preview-size-values");
while (recording_width != 0 && recording_height != 0) {
if (k == NULL)
break;
sscanf(k, "%dx%d", &w, &h);
// Look for same aspect ratio
if ((recording_width * h) / recording_height == w) {
preview_width = w;
preview_height = h;
break;
}
k = strchr(k, ',');
if (k == NULL)
break;
k++;
}
if (preview_width != 0 && preview_width != exynos_camera->preview_width)
exynos_camera->preview_width = preview_width;
if (preview_height != 0 && preview_height != exynos_camera->preview_height)
exynos_camera->preview_height = preview_height;
if (exynos_camera->camera_fimc_is)
fimc_is_mode = IS_MODE_PREVIEW_VIDEO;
} else {
camera_sensor_mode = SENSOR_CAMERA;
if (exynos_camera->camera_fimc_is)
fimc_is_mode = IS_MODE_PREVIEW_STILL;
}
// Picture size and Video Snapshot Resolution
picture_size_string = exynos_param_string_get(exynos_camera, "picture-size");
if (picture_size_string != NULL) {
sscanf(picture_size_string, "%dx%d", &picture_width, &picture_height);
if (camera_sensor_mode == SENSOR_MOVIE) {
//Set Video Recording SnapShot Resolutions
if (exynos_camera->camera_videosnapshot_resolutions != NULL) {
//Back Camera
if (!exynos_camera->camera_fimc_is) {
for (i = 0; i < exynos_camera->camera_videosnapshot_resolutions_count; i++) {
if (exynos_camera->camera_videosnapshot_resolutions[i].video_width == exynos_camera->recording_width && exynos_camera->camera_videosnapshot_resolutions[i].video_height == exynos_camera->recording_height) {
picture_width = exynos_camera->camera_videosnapshot_resolutions[i].snapshot_width;
picture_height = exynos_camera->camera_videosnapshot_resolutions[i].snapshot_height;
break;
}
}
} else {
//Front Facing Camera - Use Recording size as Snapshot size
picture_width = exynos_camera->recording_width;
picture_height = exynos_camera->recording_height;
}
}
}
if (picture_width != 0 && picture_height != 0 && (picture_width != exynos_camera->picture_width || picture_height != exynos_camera->picture_height)) {
exynos_camera->picture_width = picture_width;
exynos_camera->picture_height = picture_height;
if (!exynos_camera->camera_fimc_is) {
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_JPEG_RESOLUTION, (picture_width & 0xffff) << 16 | (picture_height & 0xffff));
if (rc < 0)
ALOGE("%s: Unable to set jpeg resolution", __func__);
}
}
}
// Switching modes
if (camera_sensor_mode != exynos_camera->camera_sensor_mode) {
exynos_camera->camera_sensor_mode = camera_sensor_mode;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SENSOR_MODE, camera_sensor_mode);
if (rc < 0)
ALOGE("%s: Unable to set sensor mode", __func__);
}
if (exynos_camera->camera_fimc_is && fimc_is_mode != exynos_camera->fimc_is_mode) {
exynos_camera->fimc_is_mode = fimc_is_mode;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_IS_S_FORMAT_SCENARIO, exynos_camera->fimc_is_mode);
if (rc < 0)
ALOGE("%s: Unable to set FIMC-IS scenario", __func__);
}
// Focus
focus_areas_string = exynos_param_string_get(exynos_camera, "focus-areas");
if (focus_areas_string != NULL) {
focus_left = focus_top = focus_right = focus_bottom = focus_weight = 0;
rc = sscanf(focus_areas_string, "(%d,%d,%d,%d,%d)",
&focus_left, &focus_top, &focus_right, &focus_bottom, &focus_weight);
if (rc != 5) {
ALOGE("%s: Unable to scan focus areas", __func__);
} else if (validate_focus_areas(focus_left, focus_top, focus_right, focus_bottom, focus_weight) != 0 || strstr(focus_areas_string, "),(")) {
exynos_param_string_set(exynos_camera, "focus-areas",
exynos_camera->raw_focus_areas);
return -EINVAL;
} else if ((focus_left != 0 || focus_right != 0) && (focus_top != 0 || focus_bottom != 0)) {
sprintf(exynos_camera->raw_focus_areas,"%s",focus_areas_string);
focus_x = (((focus_left + focus_right) / 2) + 1000) * preview_width / 2000;
focus_y = (((focus_top + focus_bottom) / 2) + 1000) * preview_height / 2000;
if (focus_x != exynos_camera->focus_x || force) {
exynos_camera->focus_x = focus_x;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_OBJECT_POSITION_X, focus_x);
if (rc < 0)
ALOGE("%s: Unable to set object x position", __func__);
}
if (focus_y != exynos_camera->focus_y || force) {
exynos_camera->focus_y = focus_y;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_OBJECT_POSITION_Y, focus_y);
if (rc < 0)
ALOGE("%s: Unable to set object y position", __func__);
}
/* After taking a picture, focus-areas is reseted by stock camera app to the center of the screen */
if (! ( (focus_x == (preview_width / 2)) && (focus_y == (preview_height / 2)) )) {
//ALOGV("%s focus_mode changed to %d due to focus-areas='%s'", __func__, focus_mode, focus_areas_string);
focus_mode = FOCUS_MODE_TOUCH;
}
}
}
// Zoom
zoom_supported_string = exynos_param_string_get(exynos_camera, "zoom-supported");
if (zoom_supported_string != NULL && strcmp(zoom_supported_string, "true") == 0) {
zoom = exynos_param_int_get(exynos_camera, "zoom");
max_zoom = exynos_param_int_get(exynos_camera, "max-zoom");
if (zoom <= max_zoom && zoom >= 0 && (zoom != exynos_camera->zoom || force)) {
exynos_camera->zoom = zoom;
rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_ZOOM, zoom);
if (rc < 0)
ALOGE("%s: Unable to set camera zoom", __func__);
} else if (zoom > max_zoom) {
exynos_param_int_set(exynos_camera, "zoom", max_zoom);
return -EINVAL;
}
}
// AE lock
ae_lock_supported_string = exynos_param_string_get(exynos_camera, "auto-exposure-lock-supported");
ae_lock_string = exynos_param_string_get(exynos_camera, "auto-exposure-lock");
if (ae_lock_supported_string != NULL && ae_lock_string != NULL && strcmp(ae_lock_supported_string, "true") == 0 && strcmp(ae_lock_string, "true") == 0)
ae_lock = 1;
else