1 /* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #define LOG_TAG "QCameraParameters"
31 
32 #include <cutils/properties.h>
33 #include <math.h>
34 #include <utils/Errors.h>
35 #include <utils/Log.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <gralloc_priv.h>
39 #include <sys/sysinfo.h>
40 #include "QCamera2HWI.h"
41 #include "QCameraParameters.h"
42 
43 #define ASPECT_TOLERANCE 0.001
44 
45 namespace qcamera {
46 // Parameter keys to communicate between camera application and driver.
47 const char QCameraParameters::KEY_QC_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
48 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
49 const char QCameraParameters::KEY_QC_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
50 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
51 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
52 const char QCameraParameters::KEY_QC_TOUCH_AF_AEC[] = "touch-af-aec";
53 const char QCameraParameters::KEY_QC_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
54 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AEC[] = "touch-index-aec";
55 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AF[] = "touch-index-af";
56 const char QCameraParameters::KEY_QC_SCENE_DETECT[] = "scene-detect";
57 const char QCameraParameters::KEY_QC_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
58 const char QCameraParameters::KEY_QC_ISO_MODE[] = "iso";
59 const char QCameraParameters::KEY_QC_CONTINUOUS_ISO[] = "continuous-iso";
60 const char QCameraParameters::KEY_QC_MIN_ISO[] = "min-iso";
61 const char QCameraParameters::KEY_QC_MAX_ISO[] = "max-iso";
62 const char QCameraParameters::KEY_QC_SUPPORTED_ISO_MODES[] = "iso-values";
63 const char QCameraParameters::KEY_QC_EXPOSURE_TIME[] = "exposure-time";
64 const char QCameraParameters::KEY_QC_MIN_EXPOSURE_TIME[] = "min-exposure-time";
65 const char QCameraParameters::KEY_QC_MAX_EXPOSURE_TIME[] = "max-exposure-time";
66 const char QCameraParameters::KEY_QC_CURRENT_EXPOSURE_TIME[] = "cur-exposure-time";
67 const char QCameraParameters::KEY_QC_CURRENT_ISO[] = "cur-iso";
68 const char QCameraParameters::KEY_QC_LENSSHADE[] = "lensshade";
69 const char QCameraParameters::KEY_QC_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
70 const char QCameraParameters::KEY_QC_AUTO_EXPOSURE[] = "auto-exposure";
71 const char QCameraParameters::KEY_QC_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
72 const char QCameraParameters::KEY_QC_DENOISE[] = "denoise";
73 const char QCameraParameters::KEY_QC_SUPPORTED_DENOISE[] = "denoise-values";
74 const char QCameraParameters::KEY_QC_FOCUS_ALGO[] = "selectable-zone-af";
75 const char QCameraParameters::KEY_QC_SUPPORTED_FOCUS_ALGOS[] = "selectable-zone-af-values";
76 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POSITION[] = "manual-focus-position";
77 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POS_TYPE[] = "manual-focus-pos-type";
78 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_INDEX[] = "min-focus-pos-index";
79 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_INDEX[] = "max-focus-pos-index";
80 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DAC[] = "min-focus-pos-dac";
81 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DAC[] = "max-focus-pos-dac";
82 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_RATIO[] = "min-focus-pos-ratio";
83 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_RATIO[] = "max-focus-pos-ratio";
84 const char QCameraParameters::KEY_QC_FOCUS_POSITION_SCALE[] = "cur-focus-scale";
85 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DIOPTER[] = "min-focus-pos-diopter";
86 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DIOPTER[] = "max-focus-pos-diopter";
87 const char QCameraParameters::KEY_QC_FOCUS_POSITION_DIOPTER[] = "cur-focus-diopter";
88 const char QCameraParameters::KEY_QC_FACE_DETECTION[] = "face-detection";
89 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
90 const char QCameraParameters::KEY_QC_FACE_RECOGNITION[] = "face-recognition";
91 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_RECOGNITION[] = "face-recognition-values";
92 const char QCameraParameters::KEY_QC_MEMORY_COLOR_ENHANCEMENT[] = "mce";
93 const char QCameraParameters::KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
94 const char QCameraParameters::KEY_QC_DIS[] = "dis";
95 const char QCameraParameters::KEY_QC_OIS[] = "ois";
96 const char QCameraParameters::KEY_QC_SUPPORTED_DIS_MODES[] = "dis-values";
97 const char QCameraParameters::KEY_QC_SUPPORTED_OIS_MODES[] = "ois-values";
98 const char QCameraParameters::KEY_QC_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
99 const char QCameraParameters::KEY_QC_VIDEO_HIGH_SPEED_RECORDING[] = "video-hsr";
100 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
101 const char QCameraParameters::KEY_QC_REDEYE_REDUCTION[] = "redeye-reduction";
102 const char QCameraParameters::KEY_QC_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
103 const char QCameraParameters::KEY_QC_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
104 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
105 const char QCameraParameters::KEY_QC_ZSL[] = "zsl";
106 const char QCameraParameters::KEY_QC_SUPPORTED_ZSL_MODES[] = "zsl-values";
107 const char QCameraParameters::KEY_QC_ZSL_BURST_INTERVAL[] = "capture-burst-interval";
108 const char QCameraParameters::KEY_QC_ZSL_BURST_LOOKBACK[] = "capture-burst-retroactive";
109 const char QCameraParameters::KEY_QC_ZSL_QUEUE_DEPTH[] = "capture-burst-queue-depth";
110 const char QCameraParameters::KEY_QC_CAMERA_MODE[] = "camera-mode";
111 const char QCameraParameters::KEY_QC_AE_BRACKET_HDR[] = "ae-bracket-hdr";
112 const char QCameraParameters::KEY_QC_SUPPORTED_AE_BRACKET_MODES[] = "ae-bracket-hdr-values";
113 const char QCameraParameters::KEY_QC_SUPPORTED_RAW_FORMATS[] = "raw-format-values";
114 const char QCameraParameters::KEY_QC_RAW_FORMAT[] = "raw-format";
115 const char QCameraParameters::KEY_QC_ORIENTATION[] = "orientation";
116 const char QCameraParameters::KEY_QC_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
117 const char QCameraParameters::KEY_QC_CAPTURE_BURST_EXPOSURE[] = "capture-burst-exposures";
118 const char QCameraParameters::KEY_QC_NUM_SNAPSHOT_PER_SHUTTER[] = "num-snaps-per-shutter";
119 const char QCameraParameters::KEY_QC_NUM_RETRO_BURST_PER_SHUTTER[] = "num-retro-burst-per-shutter";
120 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD[] = "zsl-burst-led-on-period";
121 const char QCameraParameters::KEY_QC_NO_DISPLAY_MODE[] = "no-display-mode";
122 const char QCameraParameters::KEY_QC_RAW_PICUTRE_SIZE[] = "raw-size";
123 const char QCameraParameters::KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
124 const char QCameraParameters::KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES[] = "supported-live-snapshot-sizes";
125 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_NEED_1X[] = "hdr-need-1x-values";
126 const char QCameraParameters::KEY_QC_HDR_NEED_1X[] = "hdr-need-1x";
127 const char QCameraParameters::KEY_QC_PREVIEW_FLIP[] = "preview-flip";
128 const char QCameraParameters::KEY_QC_VIDEO_FLIP[] = "video-flip";
129 const char QCameraParameters::KEY_QC_SNAPSHOT_PICTURE_FLIP[] = "snapshot-picture-flip";
130 const char QCameraParameters::KEY_QC_SUPPORTED_FLIP_MODES[] = "flip-mode-values";
131 const char QCameraParameters::KEY_QC_VIDEO_HDR[] = "video-hdr";
132 const char QCameraParameters::KEY_QC_SENSOR_HDR[] = "sensor-hdr";
133 const char QCameraParameters::KEY_QC_VT_ENABLE[] = "avtimer";
134 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HDR_MODES[] = "video-hdr-values";
135 const char QCameraParameters::KEY_QC_SUPPORTED_SENSOR_HDR_MODES[] = "sensor-hdr-values";
136 const char QCameraParameters::KEY_QC_AUTO_HDR_ENABLE [] = "auto-hdr-enable";
137 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_NUM[] = "snapshot-burst-num";
138 const char QCameraParameters::KEY_QC_SNAPSHOT_FD_DATA[] = "snapshot-fd-data-enable";
139 const char QCameraParameters::KEY_QC_TINTLESS_ENABLE[] = "tintless";
140 const char QCameraParameters::KEY_QC_SCENE_SELECTION[] = "scene-selection";
141 const char QCameraParameters::KEY_QC_CDS_MODE[] = "cds-mode";
142 const char QCameraParameters::KEY_QC_VIDEO_CDS_MODE[] = "video-cds-mode";
143 const char QCameraParameters::KEY_QC_SUPPORTED_CDS_MODES[] = "cds-mode-values";
144 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_CDS_MODES[] = "video-cds-mode-values";
145 const char QCameraParameters::KEY_QC_TNR_MODE[] = "tnr-mode";
146 const char QCameraParameters::KEY_QC_VIDEO_TNR_MODE[] = "video-tnr-mode";
147 const char QCameraParameters::KEY_QC_SUPPORTED_TNR_MODES[] = "tnr-mode-values";
148 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_TNR_MODES[] = "video-tnr-mode-values";
149 const char QCameraParameters::KEY_QC_VIDEO_ROTATION[] = "video-rotation";
150 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES[] = "video-rotation-values";
151 const char QCameraParameters::KEY_QC_AF_BRACKET[] = "af-bracket";
152 const char QCameraParameters::KEY_QC_SUPPORTED_AF_BRACKET_MODES[] = "af-bracket-values";
153 const char QCameraParameters::KEY_QC_RE_FOCUS[] = "re-focus";
154 const char QCameraParameters::KEY_QC_SUPPORTED_RE_FOCUS_MODES[] = "re-focus-values";
155 const char QCameraParameters::KEY_QC_CHROMA_FLASH[] = "chroma-flash";
156 const char QCameraParameters::KEY_QC_SUPPORTED_CHROMA_FLASH_MODES[] = "chroma-flash-values";
157 const char QCameraParameters::KEY_QC_OPTI_ZOOM[] = "opti-zoom";
158 const char QCameraParameters::KEY_QC_SEE_MORE[] = "see-more";
159 const char QCameraParameters::KEY_QC_STILL_MORE[] = "still-more";
160 const char QCameraParameters::KEY_QC_SUPPORTED_OPTI_ZOOM_MODES[] = "opti-zoom-values";
161 const char QCameraParameters::KEY_QC_HDR_MODE[] = "hdr-mode";
162 const char QCameraParameters::KEY_QC_SUPPORTED_KEY_QC_HDR_MODES[] = "hdr-mode-values";
163 const char QCameraParameters::KEY_QC_TRUE_PORTRAIT[] = "true-portrait";
164 const char QCameraParameters::KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES[] = "true-portrait-values";
165 const char QCameraParameters::KEY_QC_SUPPORTED_SEE_MORE_MODES[] = "see-more-values";
166 const char QCameraParameters::KEY_QC_SUPPORTED_STILL_MORE_MODES[] = "still-more-values";
167 const char QCameraParameters::KEY_INTERNAL_PERVIEW_RESTART[] = "internal-restart";
168 const char QCameraParameters::KEY_QC_RDI_MODE[] = "rdi-mode";
169 const char QCameraParameters::KEY_QC_SUPPORTED_RDI_MODES[] = "rdi-mode-values";
170 const char QCameraParameters::KEY_QC_SECURE_MODE[] = "secure-mode";
171 const char QCameraParameters::KEY_QC_SUPPORTED_SECURE_MODES[] = "secure-mode-values";
172 const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
173 const char QCameraParameters::KEY_QC_AUTO_HDR_SUPPORTED[] = "auto-hdr-supported";
174 const char QCameraParameters::KEY_QC_LONGSHOT_SUPPORTED[] = "longshot-supported";
175 const char QCameraParameters::KEY_QC_ZSL_HDR_SUPPORTED[] = "zsl-hdr-supported";
176 const char QCameraParameters::KEY_QC_WB_MANUAL_CCT[] = "wb-manual-cct";
177 const char QCameraParameters::KEY_QC_MIN_WB_CCT[] = "min-wb-cct";
178 const char QCameraParameters::KEY_QC_MAX_WB_CCT[] = "max-wb-cct";
179 
180 const char QCameraParameters::KEY_QC_MANUAL_WB_GAINS[] = "manual-wb-gains";
181 const char QCameraParameters::KEY_QC_MIN_WB_GAIN[] = "min-wb-gain";
182 const char QCameraParameters::KEY_QC_MAX_WB_GAIN[] = "max-wb-gain";
183 
184 const char QCameraParameters::KEY_QC_MANUAL_WB_TYPE[] = "manual-wb-type";
185 const char QCameraParameters::KEY_QC_MANUAL_WB_VALUE[] = "manual-wb-value";
186 
187 const char QCameraParameters::WHITE_BALANCE_MANUAL[] = "manual";
188 const char QCameraParameters::FOCUS_MODE_MANUAL_POSITION[] = "manual";
189 
190 
191 // Values for effect settings.
192 const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
193 const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
194 const char QCameraParameters::EFFECT_NEON[] = "neon";
195 
196 // Values for auto exposure settings.
197 const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
198 const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
199 
200 // Values for scene mode settings.
201 const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
202 const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
203 const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
204 const char QCameraParameters::SCENE_MODE_AR[] = "AR";
205 const char QCameraParameters::SCENE_MODE_HDR[] = "hdr";
206 
207 // Formats for setPreviewFormat and setPictureFormat.
208 const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
209 const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
210 const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
211 const char QCameraParameters::QC_PIXEL_FORMAT_NV12_VENUS[] = "nv12-venus";
212 
213 // Values for raw image formats
214 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV[] = "yuv-raw8-yuyv";
215 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU[] = "yuv-raw8-yvyu";
216 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY[] = "yuv-raw8-uyvy";
217 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY[] = "yuv-raw8-vyuy";
218 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG[] = "bayer-qcom-8gbrg";
219 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG[] = "bayer-qcom-8grbg";
220 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB[] = "bayer-qcom-8rggb";
221 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR[] = "bayer-qcom-8bggr";
222 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG[] = "bayer-qcom-10gbrg";
223 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG[] = "bayer-qcom-10grbg";
224 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB[] = "bayer-qcom-10rggb";
225 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR[] = "bayer-qcom-10bggr";
226 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG[] = "bayer-qcom-12gbrg";
227 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG[] = "bayer-qcom-12grbg";
228 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB[] = "bayer-qcom-12rggb";
229 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR[] = "bayer-qcom-12bggr";
230 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG[] = "bayer-mipi-8gbrg";
231 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG[] = "bayer-mipi-8grbg";
232 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB[] = "bayer-mipi-8rggb";
233 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR[] = "bayer-mipi-8bggr";
234 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG[] = "bayer-mipi-10gbrg";
235 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG[] = "bayer-mipi-10grbg";
236 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB[] = "bayer-mipi-10rggb";
237 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR[] = "bayer-mipi-10bggr";
238 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG[] = "bayer-mipi-12gbrg";
239 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG[] = "bayer-mipi-12grbg";
240 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB[] = "bayer-mipi-12rggb";
241 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR[] = "bayer-mipi-12bggr";
242 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG[] = "bayer-ideal-qcom-8gbrg";
243 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG[] = "bayer-ideal-qcom-8grbg";
244 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB[] = "bayer-ideal-qcom-8rggb";
245 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR[] = "bayer-ideal-qcom-8bggr";
246 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG[] = "bayer-ideal-qcom-10gbrg";
247 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG[] = "bayer-ideal-qcom-10grbg";
248 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB[] = "bayer-ideal-qcom-10rggb";
249 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR[] = "bayer-ideal-qcom-10bggr";
250 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG[] = "bayer-ideal-qcom-12gbrg";
251 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG[] = "bayer-ideal-qcom-12grbg";
252 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB[] = "bayer-ideal-qcom-12rggb";
253 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR[] = "bayer-ideal-qcom-12bggr";
254 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG[] = "bayer-ideal-mipi-8gbrg";
255 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG[] = "bayer-ideal-mipi-8grbg";
256 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB[] = "bayer-ideal-mipi-8rggb";
257 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR[] = "bayer-ideal-mipi-8bggr";
258 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG[] = "bayer-ideal-mipi-10gbrg";
259 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG[] = "bayer-ideal-mipi-10grbg";
260 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB[] = "bayer-ideal-mipi-10rggb";
261 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR[] = "bayer-ideal-mipi-10bggr";
262 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG[] = "bayer-ideal-mipi-12gbrg";
263 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG[] = "bayer-ideal-mipi-12grbg";
264 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB[] = "bayer-ideal-mipi-12rggb";
265 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR[] = "bayer-ideal-mipi-12bggr";
266 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG[] = "bayer-ideal-plain8-8gbrg";
267 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG[] = "bayer-ideal-plain8-8grbg";
268 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB[] = "bayer-ideal-plain8-8rggb";
269 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR[] = "bayer-ideal-plain8-8bggr";
270 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG[] = "bayer-ideal-plain16-8gbrg";
271 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG[] = "bayer-ideal-plain16-8grbg";
272 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB[] = "bayer-ideal-plain16-8rggb";
273 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR[] = "bayer-ideal-plain16-8bggr";
274 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG[] = "bayer-ideal-plain16-10gbrg";
275 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG[] = "bayer-ideal-plain16-10grbg";
276 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB[] = "bayer-ideal-plain16-10rggb";
277 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR[] = "bayer-ideal-plain16-10bggr";
278 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG[] = "bayer-ideal-plain16-12gbrg";
279 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG[] = "bayer-ideal-plain16-12grbg";
280 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB[] = "bayer-ideal-plain16-12rggb";
281 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR[] = "bayer-ideal-plain16-12bggr";
282 
283 // Values for ISO Settings
284 const char QCameraParameters::ISO_AUTO[] = "auto";
285 const char QCameraParameters::ISO_100[] = "ISO100";
286 const char QCameraParameters::ISO_200[] = "ISO200";
287 const char QCameraParameters::ISO_400[] = "ISO400";
288 const char QCameraParameters::ISO_800[] = "ISO800";
289 const char QCameraParameters::ISO_1600[] = "ISO1600";
290 const char QCameraParameters::ISO_3200[] = "ISO3200";
291 const char QCameraParameters::ISO_MANUAL[] = "manual";
292 
293 
294 // Values for auto exposure settings.
295 const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
296 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
297 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
298 const char QCameraParameters::AUTO_EXPOSURE_SMART_METERING[] = "smart-metering";
299 const char QCameraParameters::AUTO_EXPOSURE_USER_METERING[] = "user-metering";
300 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING_ADV[] = "spot-metering-adv";
301 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED_ADV[] = "center-weighted-adv";
302 
303 const char QCameraParameters::KEY_QC_GPS_LATITUDE_REF[] = "gps-latitude-ref";
304 const char QCameraParameters::KEY_QC_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
305 const char QCameraParameters::KEY_QC_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
306 const char QCameraParameters::KEY_QC_GPS_STATUS[] = "gps-status";
307 
308 const char QCameraParameters::KEY_QC_HISTOGRAM[] = "histogram";
309 const char QCameraParameters::KEY_QC_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
310 
311 const char QCameraParameters::VALUE_ENABLE[] = "enable";
312 const char QCameraParameters::VALUE_DISABLE[] = "disable";
313 const char QCameraParameters::VALUE_OFF[] = "off";
314 const char QCameraParameters::VALUE_ON[] = "on";
315 const char QCameraParameters::VALUE_TRUE[] = "true";
316 const char QCameraParameters::VALUE_FALSE[] = "false";
317 
318 const char QCameraParameters::KEY_QC_SHARPNESS[] = "sharpness";
319 const char QCameraParameters::KEY_QC_MIN_SHARPNESS[] = "min-sharpness";
320 const char QCameraParameters::KEY_QC_MAX_SHARPNESS[] = "max-sharpness";
321 const char QCameraParameters::KEY_QC_SHARPNESS_STEP[] = "sharpness-step";
322 const char QCameraParameters::KEY_QC_CONTRAST[] = "contrast";
323 const char QCameraParameters::KEY_QC_MIN_CONTRAST[] = "min-contrast";
324 const char QCameraParameters::KEY_QC_MAX_CONTRAST[] = "max-contrast";
325 const char QCameraParameters::KEY_QC_CONTRAST_STEP[] = "contrast-step";
326 const char QCameraParameters::KEY_QC_SATURATION[] = "saturation";
327 const char QCameraParameters::KEY_QC_MIN_SATURATION[] = "min-saturation";
328 const char QCameraParameters::KEY_QC_MAX_SATURATION[] = "max-saturation";
329 const char QCameraParameters::KEY_QC_SATURATION_STEP[] = "saturation-step";
330 const char QCameraParameters::KEY_QC_BRIGHTNESS[] = "luma-adaptation";
331 const char QCameraParameters::KEY_QC_MIN_BRIGHTNESS[] = "min-brightness";
332 const char QCameraParameters::KEY_QC_MAX_BRIGHTNESS[] = "max-brightness";
333 const char QCameraParameters::KEY_QC_BRIGHTNESS_STEP[] = "brightness-step";
334 const char QCameraParameters::KEY_QC_SCE_FACTOR[] = "skinToneEnhancement";
335 const char QCameraParameters::KEY_QC_MIN_SCE_FACTOR[] = "min-sce-factor";
336 const char QCameraParameters::KEY_QC_MAX_SCE_FACTOR[] = "max-sce-factor";
337 const char QCameraParameters::KEY_QC_SCE_FACTOR_STEP[] = "sce-factor-step";
338 
339 const char QCameraParameters::KEY_QC_SUPPORTED_CAMERA_FEATURES[] = "qc-camera-features";
340 const char QCameraParameters::KEY_QC_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
341 
342 //Values for DENOISE
343 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
344 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
345 
346 // Values for selectable zone af Settings
347 const char QCameraParameters::FOCUS_ALGO_AUTO[] = "auto";
348 const char QCameraParameters::FOCUS_ALGO_SPOT_METERING[] = "spot-metering";
349 const char QCameraParameters::FOCUS_ALGO_CENTER_WEIGHTED[] = "center-weighted";
350 const char QCameraParameters::FOCUS_ALGO_FRAME_AVERAGE[] = "frame-average";
351 
352 // Values for HFR settings.
353 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
354 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
355 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
356 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
357 const char QCameraParameters::VIDEO_HFR_5X[] = "150";
358 const char QCameraParameters::VIDEO_HFR_6X[] = "180";
359 const char QCameraParameters::VIDEO_HFR_7X[] = "210";
360 const char QCameraParameters::VIDEO_HFR_8X[] = "240";
361 const char QCameraParameters::VIDEO_HFR_9X[] = "480";
362 
363 // Values for HDR Bracketing settings.
364 const char QCameraParameters::AE_BRACKET_OFF[] = "Off";
365 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
366 
367 // Values for AF Bracketing setting.
368 const char QCameraParameters::AF_BRACKET_OFF[] = "af-bracket-off";
369 const char QCameraParameters::AF_BRACKET_ON[] = "af-bracket-on";
370 
371 // Values for Refocus setting.
372 const char QCameraParameters::RE_FOCUS_OFF[] = "re-focus-off";
373 const char QCameraParameters::RE_FOCUS_ON[] = "re-focus-on";
374 
375 // Values for Chroma Flash setting.
376 const char QCameraParameters::CHROMA_FLASH_OFF[] = "chroma-flash-off";
377 const char QCameraParameters::CHROMA_FLASH_ON[] = "chroma-flash-on";
378 
379 // Values for Opti Zoom setting.
380 const char QCameraParameters::OPTI_ZOOM_OFF[] = "opti-zoom-off";
381 const char QCameraParameters::OPTI_ZOOM_ON[] = "opti-zoom-on";
382 
383 // Values for Still More setting.
384 const char QCameraParameters::STILL_MORE_OFF[] = "still-more-off";
385 const char QCameraParameters::STILL_MORE_ON[] = "still-more-on";
386 
387 // Values for HDR mode setting.
388 const char QCameraParameters::HDR_MODE_SENSOR[] = "hdr-mode-sensor";
389 const char QCameraParameters::HDR_MODE_MULTI_FRAME[] = "hdr-mode-multiframe";
390 
391 // Values for True Portrait setting.
392 const char QCameraParameters::TRUE_PORTRAIT_OFF[] = "true-portrait-off";
393 const char QCameraParameters::TRUE_PORTRAIT_ON[] = "true-portrait-on";
394 
395 // Values for FLIP settings.
396 const char QCameraParameters::FLIP_MODE_OFF[] = "off";
397 const char QCameraParameters::FLIP_MODE_V[] = "flip-v";
398 const char QCameraParameters::FLIP_MODE_H[] = "flip-h";
399 const char QCameraParameters::FLIP_MODE_VH[] = "flip-vh";
400 
401 const char QCameraParameters::CDS_MODE_OFF[] = "off";
402 const char QCameraParameters::CDS_MODE_ON[] = "on";
403 const char QCameraParameters::CDS_MODE_AUTO[] = "auto";
404 
405 const char QCameraParameters::KEY_SELECTED_AUTO_SCENE[] = "selected-auto-scene";
406 
407 // Values for video rotation settings.
408 const char QCameraParameters::VIDEO_ROTATION_0[] = "0";
409 const char QCameraParameters::VIDEO_ROTATION_90[] = "90";
410 const char QCameraParameters::VIDEO_ROTATION_180[] = "180";
411 const char QCameraParameters::VIDEO_ROTATION_270[] = "270";
412 
413 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES[] = "manual-focus-modes";
414 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES[] = "manual-exposure-modes";
415 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_WB_MODES[] = "manual-wb-modes";
416 const char QCameraParameters::KEY_QC_FOCUS_SCALE_MODE[] = "scale-mode";
417 const char QCameraParameters::KEY_QC_FOCUS_DIOPTER_MODE[] = "diopter-mode";
418 const char QCameraParameters::KEY_QC_ISO_PRIORITY[] = "iso-priority";
419 const char QCameraParameters::KEY_QC_EXP_TIME_PRIORITY[] = "exp-time-priority";
420 const char QCameraParameters::KEY_QC_USER_SETTING[] = "user-setting";
421 const char QCameraParameters::KEY_QC_WB_CCT_MODE[] = "color-temperature";
422 const char QCameraParameters::KEY_QC_WB_GAIN_MODE[] = "rbgb-gains";
423 
424 static const char* portrait = "portrait";
425 static const char* landscape = "landscape";
426 
427 const cam_dimension_t QCameraParameters::THUMBNAIL_SIZES_MAP[] = {
428     { 512, 288 }, //1.777778
429     { 480, 288 }, //1.666667
430     { 256, 154 }, //1.66233
431     { 432, 288 }, //1.5
432     { 320, 320 }, //1.0
433     { 320, 240 }, //1.33333
434     { 176, 144 }, //1.222222
435     { 0, 0 }      // required by Android SDK
436 };
437 
438 const QCameraParameters::QCameraMap<cam_auto_exposure_mode_type>
439         QCameraParameters::AUTO_EXPOSURE_MAP[] = {
440     { AUTO_EXPOSURE_FRAME_AVG,           CAM_AEC_MODE_FRAME_AVERAGE },
441     { AUTO_EXPOSURE_CENTER_WEIGHTED,     CAM_AEC_MODE_CENTER_WEIGHTED },
442     { AUTO_EXPOSURE_SPOT_METERING,       CAM_AEC_MODE_SPOT_METERING },
443     { AUTO_EXPOSURE_SMART_METERING,      CAM_AEC_MODE_SMART_METERING },
444     { AUTO_EXPOSURE_USER_METERING,       CAM_AEC_MODE_USER_METERING },
445     { AUTO_EXPOSURE_SPOT_METERING_ADV,   CAM_AEC_MODE_SPOT_METERING_ADV },
446     { AUTO_EXPOSURE_CENTER_WEIGHTED_ADV, CAM_AEC_MODE_CENTER_WEIGHTED_ADV },
447 };
448 
449 const QCameraParameters::QCameraMap<cam_format_t>
450         QCameraParameters::PREVIEW_FORMATS_MAP[] = {
451     {PIXEL_FORMAT_YUV420SP,        CAM_FORMAT_YUV_420_NV21},
452     {PIXEL_FORMAT_YUV420P,         CAM_FORMAT_YUV_420_YV12},
453     {PIXEL_FORMAT_YUV420SP_ADRENO, CAM_FORMAT_YUV_420_NV21_ADRENO},
454     {PIXEL_FORMAT_YV12,            CAM_FORMAT_YUV_420_YV12},
455     {PIXEL_FORMAT_NV12,            CAM_FORMAT_YUV_420_NV12},
456     {QC_PIXEL_FORMAT_NV12_VENUS,   CAM_FORMAT_YUV_420_NV12_VENUS}
457 };
458 
459 const QCameraParameters::QCameraMap<cam_format_t>
460         QCameraParameters::PICTURE_TYPES_MAP[] = {
461     {PIXEL_FORMAT_JPEG,                          CAM_FORMAT_JPEG},
462     {PIXEL_FORMAT_YUV420SP,                      CAM_FORMAT_YUV_420_NV21},
463     {PIXEL_FORMAT_YUV422SP,                      CAM_FORMAT_YUV_422_NV16},
464     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV,          CAM_FORMAT_YUV_RAW_8BIT_YUYV},
465     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU,          CAM_FORMAT_YUV_RAW_8BIT_YVYU},
466     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY,          CAM_FORMAT_YUV_RAW_8BIT_UYVY},
467     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY,          CAM_FORMAT_YUV_RAW_8BIT_VYUY},
468     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GBRG},
469     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GRBG},
470     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_RGGB},
471     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_BGGR},
472     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG},
473     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GRBG},
474     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_RGGB},
475     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_BGGR},
476     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GBRG},
477     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GRBG},
478     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_RGGB},
479     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_BGGR},
480     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GBRG},
481     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GRBG},
482     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_RGGB},
483     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_BGGR},
484     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GBRG},
485     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GRBG},
486     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_RGGB},
487     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR},
488     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GBRG},
489     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GRBG},
490     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_RGGB},
491     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_BGGR},
492     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GBRG},
493     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GRBG},
494     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_RGGB},
495     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_BGGR},
496     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GBRG},
497     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GRBG},
498     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_RGGB},
499     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_BGGR},
500     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GBRG},
501     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GRBG},
502     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_RGGB},
503     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_BGGR},
504     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GBRG},
505     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GRBG},
506     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_RGGB},
507     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_BGGR},
508     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GBRG},
509     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GRBG},
510     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_RGGB},
511     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_BGGR},
512     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GBRG},
513     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GRBG},
514     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_RGGB},
515     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_BGGR},
516     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GBRG},
517     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GRBG},
518     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_RGGB},
519     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_BGGR},
520     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GBRG},
521     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GRBG},
522     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_RGGB},
523     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_BGGR},
524     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG},
525     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG},
526     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB},
527     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR},
528     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GBRG},
529     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GRBG},
530     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_RGGB},
531     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_BGGR}
532 };
533 
534 const QCameraParameters::QCameraMap<cam_focus_mode_type>
535         QCameraParameters::FOCUS_MODES_MAP[] = {
536     { FOCUS_MODE_AUTO,               CAM_FOCUS_MODE_AUTO },
537     { FOCUS_MODE_INFINITY,           CAM_FOCUS_MODE_INFINITY },
538     { FOCUS_MODE_MACRO,              CAM_FOCUS_MODE_MACRO },
539     { FOCUS_MODE_FIXED,              CAM_FOCUS_MODE_FIXED },
540     { FOCUS_MODE_EDOF,               CAM_FOCUS_MODE_EDOF },
541     { FOCUS_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
542     { FOCUS_MODE_CONTINUOUS_VIDEO,   CAM_FOCUS_MODE_CONTINOUS_VIDEO },
543     { FOCUS_MODE_MANUAL_POSITION,    CAM_FOCUS_MODE_MANUAL},
544 };
545 
546 const QCameraParameters::QCameraMap<cam_effect_mode_type>
547         QCameraParameters::EFFECT_MODES_MAP[] = {
548     { EFFECT_NONE,       CAM_EFFECT_MODE_OFF },
549     { EFFECT_MONO,       CAM_EFFECT_MODE_MONO },
550     { EFFECT_NEGATIVE,   CAM_EFFECT_MODE_NEGATIVE },
551     { EFFECT_SOLARIZE,   CAM_EFFECT_MODE_SOLARIZE },
552     { EFFECT_SEPIA,      CAM_EFFECT_MODE_SEPIA },
553     { EFFECT_POSTERIZE,  CAM_EFFECT_MODE_POSTERIZE },
554     { EFFECT_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
555     { EFFECT_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
556     { EFFECT_AQUA,       CAM_EFFECT_MODE_AQUA },
557     { EFFECT_EMBOSS,     CAM_EFFECT_MODE_EMBOSS },
558     { EFFECT_SKETCH,     CAM_EFFECT_MODE_SKETCH },
559     { EFFECT_NEON,       CAM_EFFECT_MODE_NEON }
560 };
561 
562 const QCameraParameters::QCameraMap<cam_scene_mode_type>
563         QCameraParameters::SCENE_MODES_MAP[] = {
564     { SCENE_MODE_AUTO,           CAM_SCENE_MODE_OFF },
565     { SCENE_MODE_ACTION,         CAM_SCENE_MODE_ACTION },
566     { SCENE_MODE_PORTRAIT,       CAM_SCENE_MODE_PORTRAIT },
567     { SCENE_MODE_LANDSCAPE,      CAM_SCENE_MODE_LANDSCAPE },
568     { SCENE_MODE_NIGHT,          CAM_SCENE_MODE_NIGHT },
569     { SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
570     { SCENE_MODE_THEATRE,        CAM_SCENE_MODE_THEATRE },
571     { SCENE_MODE_BEACH,          CAM_SCENE_MODE_BEACH },
572     { SCENE_MODE_SNOW,           CAM_SCENE_MODE_SNOW },
573     { SCENE_MODE_SUNSET,         CAM_SCENE_MODE_SUNSET },
574     { SCENE_MODE_STEADYPHOTO,    CAM_SCENE_MODE_ANTISHAKE },
575     { SCENE_MODE_FIREWORKS ,     CAM_SCENE_MODE_FIREWORKS },
576     { SCENE_MODE_SPORTS ,        CAM_SCENE_MODE_SPORTS },
577     { SCENE_MODE_PARTY,          CAM_SCENE_MODE_PARTY },
578     { SCENE_MODE_CANDLELIGHT,    CAM_SCENE_MODE_CANDLELIGHT },
579     { SCENE_MODE_ASD,            CAM_SCENE_MODE_AUTO },
580     { SCENE_MODE_BACKLIGHT,      CAM_SCENE_MODE_BACKLIGHT },
581     { SCENE_MODE_FLOWERS,        CAM_SCENE_MODE_FLOWERS },
582     { SCENE_MODE_AR,             CAM_SCENE_MODE_AR },
583     { SCENE_MODE_HDR,            CAM_SCENE_MODE_HDR },
584 };
585 
586 const QCameraParameters::QCameraMap<cam_flash_mode_t>
587         QCameraParameters::FLASH_MODES_MAP[] = {
588     { FLASH_MODE_OFF,   CAM_FLASH_MODE_OFF },
589     { FLASH_MODE_AUTO,  CAM_FLASH_MODE_AUTO },
590     { FLASH_MODE_ON,    CAM_FLASH_MODE_ON },
591     { FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
592 };
593 
594 const QCameraParameters::QCameraMap<cam_focus_algorithm_type>
595          QCameraParameters::FOCUS_ALGO_MAP[] = {
596     { FOCUS_ALGO_AUTO,            CAM_FOCUS_ALGO_AUTO },
597     { FOCUS_ALGO_SPOT_METERING,   CAM_FOCUS_ALGO_SPOT },
598     { FOCUS_ALGO_CENTER_WEIGHTED, CAM_FOCUS_ALGO_CENTER_WEIGHTED },
599     { FOCUS_ALGO_FRAME_AVERAGE,   CAM_FOCUS_ALGO_AVERAGE }
600 };
601 
602 const QCameraParameters::QCameraMap<cam_wb_mode_type>
603         QCameraParameters::WHITE_BALANCE_MODES_MAP[] = {
604     { WHITE_BALANCE_AUTO,            CAM_WB_MODE_AUTO },
605     { WHITE_BALANCE_INCANDESCENT,    CAM_WB_MODE_INCANDESCENT },
606     { WHITE_BALANCE_FLUORESCENT,     CAM_WB_MODE_FLUORESCENT },
607     { WHITE_BALANCE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
608     { WHITE_BALANCE_DAYLIGHT,        CAM_WB_MODE_DAYLIGHT },
609     { WHITE_BALANCE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
610     { WHITE_BALANCE_TWILIGHT,        CAM_WB_MODE_TWILIGHT },
611     { WHITE_BALANCE_SHADE,           CAM_WB_MODE_SHADE },
612     { WHITE_BALANCE_MANUAL,          CAM_WB_MODE_MANUAL},
613 };
614 
615 const QCameraParameters::QCameraMap<cam_antibanding_mode_type>
616         QCameraParameters::ANTIBANDING_MODES_MAP[] = {
617     { ANTIBANDING_OFF,  CAM_ANTIBANDING_MODE_OFF },
618     { ANTIBANDING_50HZ, CAM_ANTIBANDING_MODE_50HZ },
619     { ANTIBANDING_60HZ, CAM_ANTIBANDING_MODE_60HZ },
620     { ANTIBANDING_AUTO, CAM_ANTIBANDING_MODE_AUTO }
621 };
622 
623 const QCameraParameters::QCameraMap<cam_iso_mode_type>
624         QCameraParameters::ISO_MODES_MAP[] = {
625     { ISO_AUTO,  CAM_ISO_MODE_AUTO },
626     { ISO_HJR,   CAM_ISO_MODE_DEBLUR },
627     { ISO_100,   CAM_ISO_MODE_100 },
628     { ISO_200,   CAM_ISO_MODE_200 },
629     { ISO_400,   CAM_ISO_MODE_400 },
630     { ISO_800,   CAM_ISO_MODE_800 },
631     { ISO_1600,  CAM_ISO_MODE_1600 },
632     { ISO_3200,  CAM_ISO_MODE_3200 }
633 };
634 
635 const QCameraParameters::QCameraMap<cam_hfr_mode_t>
636         QCameraParameters::HFR_MODES_MAP[] = {
637     { VIDEO_HFR_OFF, CAM_HFR_MODE_OFF },
638     { VIDEO_HFR_2X, CAM_HFR_MODE_60FPS },
639     { VIDEO_HFR_3X, CAM_HFR_MODE_90FPS },
640     { VIDEO_HFR_4X, CAM_HFR_MODE_120FPS },
641     { VIDEO_HFR_5X, CAM_HFR_MODE_150FPS },
642     { VIDEO_HFR_6X, CAM_HFR_MODE_180FPS },
643     { VIDEO_HFR_7X, CAM_HFR_MODE_210FPS },
644     { VIDEO_HFR_8X, CAM_HFR_MODE_240FPS },
645     { VIDEO_HFR_9X, CAM_HFR_MODE_480FPS }
646 };
647 
648 const QCameraParameters::QCameraMap<cam_bracket_mode>
649         QCameraParameters::BRACKETING_MODES_MAP[] = {
650     { AE_BRACKET_OFF, CAM_EXP_BRACKETING_OFF },
651     { AE_BRACKET,     CAM_EXP_BRACKETING_ON }
652 };
653 
654 const QCameraParameters::QCameraMap<int>
655         QCameraParameters::ON_OFF_MODES_MAP[] = {
656     { VALUE_OFF, 0 },
657     { VALUE_ON,  1 }
658 };
659 
660 const QCameraParameters::QCameraMap<int>
661         QCameraParameters::TOUCH_AF_AEC_MODES_MAP[] = {
662     { QCameraParameters::TOUCH_AF_AEC_OFF, 0 },
663     { QCameraParameters::TOUCH_AF_AEC_ON, 1 }
664 };
665 
666 const QCameraParameters::QCameraMap<int>
667         QCameraParameters::ENABLE_DISABLE_MODES_MAP[] = {
668     { VALUE_ENABLE,  1 },
669     { VALUE_DISABLE, 0 }
670 };
671 
672 const QCameraParameters::QCameraMap<int>
673         QCameraParameters::DENOISE_ON_OFF_MODES_MAP[] = {
674     { DENOISE_OFF, 0 },
675     { DENOISE_ON,  1 }
676 };
677 
678 const QCameraParameters::QCameraMap<int>
679         QCameraParameters::TRUE_FALSE_MODES_MAP[] = {
680     { VALUE_FALSE, 0},
681     { VALUE_TRUE,  1}
682 };
683 
684 const QCameraParameters::QCameraMap<cam_flip_t>
685         QCameraParameters::FLIP_MODES_MAP[] = {
686     {FLIP_MODE_OFF, FLIP_NONE},
687     {FLIP_MODE_V, FLIP_V},
688     {FLIP_MODE_H, FLIP_H},
689     {FLIP_MODE_VH, FLIP_V_H}
690 };
691 
692 const QCameraParameters::QCameraMap<int>
693         QCameraParameters::AF_BRACKETING_MODES_MAP[] = {
694     { AF_BRACKET_OFF, 0 },
695     { AF_BRACKET_ON,  1 }
696 };
697 
698 const QCameraParameters::QCameraMap<int>
699         QCameraParameters::RE_FOCUS_MODES_MAP[] = {
700     { RE_FOCUS_OFF, 0 },
701     { RE_FOCUS_ON,  1 }
702 };
703 
704 const QCameraParameters::QCameraMap<int>
705         QCameraParameters::CHROMA_FLASH_MODES_MAP[] = {
706     { CHROMA_FLASH_OFF, 0 },
707     { CHROMA_FLASH_ON,  1 }
708 };
709 
710 const QCameraParameters::QCameraMap<int>
711         QCameraParameters::OPTI_ZOOM_MODES_MAP[] = {
712     { OPTI_ZOOM_OFF, 0 },
713     { OPTI_ZOOM_ON,  1 }
714 };
715 
716 const QCameraParameters::QCameraMap<int>
717         QCameraParameters::TRUE_PORTRAIT_MODES_MAP[] = {
718     { TRUE_PORTRAIT_OFF, 0 },
719     { TRUE_PORTRAIT_ON,  1 }
720 };
721 
722 const QCameraParameters::QCameraMap<int>
723         QCameraParameters::STILL_MORE_MODES_MAP[] = {
724     { STILL_MORE_OFF, 0 },
725     { STILL_MORE_ON,  1 }
726 };
727 
728 const QCameraParameters::QCameraMap<cam_cds_mode_type_t>
729         QCameraParameters::CDS_MODES_MAP[] = {
730     { CDS_MODE_OFF, CAM_CDS_MODE_OFF },
731     { CDS_MODE_ON, CAM_CDS_MODE_ON },
732     { CDS_MODE_AUTO, CAM_CDS_MODE_AUTO}
733 };
734 
735 const QCameraParameters::QCameraMap<int>
736         QCameraParameters::HDR_MODES_MAP[] = {
737     { HDR_MODE_SENSOR, 0 },
738     { HDR_MODE_MULTI_FRAME, 1 }
739 };
740 
741 const QCameraParameters::QCameraMap<int>
742         QCameraParameters::VIDEO_ROTATION_MODES_MAP[] = {
743     { VIDEO_ROTATION_0, 0 },
744     { VIDEO_ROTATION_90, 90 },
745     { VIDEO_ROTATION_180, 180 },
746     { VIDEO_ROTATION_270, 270 }
747 };
748 
749 #define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)"
750 #define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
751 #define TOTAL_RAM_SIZE_512MB 536870912
752 #define PARAM_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
753 
754 /*===========================================================================
755  * FUNCTION   : QCameraParameters
756  *
757  * DESCRIPTION: default constructor of QCameraParameters
758  *
759  * PARAMETERS : none
760  *
761  * RETURN     : None
762  *==========================================================================*/
QCameraParameters()763 QCameraParameters::QCameraParameters()
764     : CameraParameters(),
765       m_reprocScaleParam(this),
766       m_pCapability(NULL),
767       m_pCamOpsTbl(NULL),
768       m_pParamHeap(NULL),
769       m_pParamBuf(NULL),
770       mIsType(IS_TYPE_NONE),
771       m_bZslMode(false),
772       m_bZslMode_new(false),
773       m_bForceZslMode(false),
774       m_bRecordingHint(false),
775       m_bRecordingHint_new(false),
776       m_bHistogramEnabled(false),
777       m_nFaceProcMask(0),
778       m_bFaceDetectionOn(0),
779       m_bDebugFps(false),
780       mFocusMode(CAM_FOCUS_MODE_MAX),
781       mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
782       mPictureFormat(CAM_FORMAT_JPEG),
783       m_bNeedRestart(false),
784       m_bNoDisplayMode(false),
785       m_bWNROn(false),
786       m_bTNRPreviewOn(false),
787       m_bTNRVideoOn(false),
788       m_bInited(false),
789       m_nBurstNum(1),
790       m_nRetroBurstNum(0),
791       m_nBurstLEDOnPeriod(100),
792       m_bUpdateEffects(false),
793       m_bSceneTransitionAuto(false),
794       m_bPreviewFlipChanged(false),
795       m_bVideoFlipChanged(false),
796       m_bSnapshotFlipChanged(false),
797       m_bFixedFrameRateSet(false),
798       m_bHDREnabled(false),
799       m_bAVTimerEnabled(false),
800       m_bDISEnabled(false),
801       m_MobiMask(0),
802       m_AdjustFPS(NULL),
803       m_bHDR1xFrameEnabled(true),
804       m_HDRSceneEnabled(false),
805       m_bHDRThumbnailProcessNeeded(false),
806       m_bHDR1xExtraBufferNeeded(true),
807       m_bHDROutputCropEnabled(false),
808       m_tempMap(),
809       m_bAFBracketingOn(false),
810       m_bReFocusOn(false),
811       m_bChromaFlashOn(false),
812       m_bOptiZoomOn(false),
813       m_bSceneSelection(false),
814       m_SelectedScene(CAM_SCENE_MODE_MAX),
815       m_bSeeMoreOn(false),
816       m_bStillMoreOn(false),
817       m_bHfrMode(false),
818       m_bSensorHDREnabled(false),
819       m_bRdiMode(false),
820       m_bDisplayFrame(true),
821       m_bSecureMode(false),
822       m_bAeBracketingEnabled(false),
823       mFlashValue(CAM_FLASH_MODE_OFF),
824       mFlashDaemonValue(CAM_FLASH_MODE_OFF),
825       mHfrMode(CAM_HFR_MODE_OFF),
826       m_bHDRModeSensor(true),
827       mOfflineRAW(false),
828       m_bTruePortraitOn(false),
829       mCds_mode(CAM_CDS_MODE_OFF)
830 {
831     char value[PROPERTY_VALUE_MAX];
832     // TODO: may move to parameter instead of sysprop
833     property_get("persist.debug.sf.showfps", value, "0");
834     m_bDebugFps = atoi(value) > 0 ? true : false;
835 
836     // For thermal mode, it should be set as system property
837     // because system property applies to all applications, while
838     // parameters only apply to specific app.
839     property_get("persist.camera.thermal.mode", value, "fps");
840     if (!strcmp(value, "frameskip")) {
841         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FRAMESKIP;
842     } else {
843         if (strcmp(value, "fps"))
844             ALOGE("%s: Invalid camera thermal mode %s", __func__, value);
845         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FPS;
846     }
847 
848     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
849     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
850     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
851     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
852     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
853     mTotalPPCount = 0;
854     mZoomLevel = 0;
855     mParmZoomLevel = 0;
856     mCurPPCount = 0;
857     mBufBatchCnt = 0;
858     mRotation = 0;
859     mJpegRotation = 0;
860 }
861 
862 /*===========================================================================
863  * FUNCTION   : QCameraParameters
864  *
865  * DESCRIPTION: constructor of QCameraParameters
866  *
867  * PARAMETERS :
868  *   @params  : parameters in string
869  *
870  * RETURN     : None
871  *==========================================================================*/
QCameraParameters(const String8 & params)872 QCameraParameters::QCameraParameters(const String8 &params)
873     : CameraParameters(params),
874     m_reprocScaleParam(this),
875     m_pCapability(NULL),
876     m_pCamOpsTbl(NULL),
877     m_pParamHeap(NULL),
878     m_pParamBuf(NULL),
879     m_bZslMode(false),
880     m_bZslMode_new(false),
881     m_bForceZslMode(false),
882     m_bRecordingHint(false),
883     m_bRecordingHint_new(false),
884     m_bHistogramEnabled(false),
885     m_nFaceProcMask(0),
886     m_bDebugFps(false),
887     mFocusMode(CAM_FOCUS_MODE_MAX),
888     mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
889     mPictureFormat(CAM_FORMAT_JPEG),
890     m_bNeedRestart(false),
891     m_bNoDisplayMode(false),
892     m_bWNROn(false),
893     m_bTNRPreviewOn(false),
894     m_bTNRVideoOn(false),
895     m_bInited(false),
896     m_nBurstNum(1),
897     m_nRetroBurstNum(0),
898     m_nBurstLEDOnPeriod(100),
899     m_bPreviewFlipChanged(false),
900     m_bVideoFlipChanged(false),
901     m_bSnapshotFlipChanged(false),
902     m_bFixedFrameRateSet(false),
903     m_bHDREnabled(false),
904     m_bAVTimerEnabled(false),
905     m_AdjustFPS(NULL),
906     m_bHDR1xFrameEnabled(true),
907     m_HDRSceneEnabled(false),
908     m_bHDRThumbnailProcessNeeded(false),
909     m_bHDR1xExtraBufferNeeded(true),
910     m_bHDROutputCropEnabled(false),
911     m_tempMap(),
912     m_bAFBracketingOn(false),
913     m_bReFocusOn(false),
914     m_bChromaFlashOn(false),
915     m_bOptiZoomOn(false),
916     m_bSceneSelection(false),
917     m_SelectedScene(CAM_SCENE_MODE_MAX),
918     m_bSeeMoreOn(false),
919     m_bStillMoreOn(false),
920     m_bHfrMode(false),
921     m_bSensorHDREnabled(false),
922     m_bRdiMode(false),
923     m_bSecureMode(false),
924     m_bAeBracketingEnabled(false),
925     mFlashValue(CAM_FLASH_MODE_OFF),
926     mFlashDaemonValue(CAM_FLASH_MODE_OFF),
927     mHfrMode(CAM_HFR_MODE_OFF),
928     m_bHDRModeSensor(true),
929     mOfflineRAW(false),
930     m_bTruePortraitOn(false),
931     mCds_mode(CAM_CDS_MODE_OFF),
932     mParmEffect(CAM_EFFECT_MODE_OFF)
933 {
934     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
935     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
936     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
937     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
938     mTotalPPCount = 0;
939     mZoomLevel = 0;
940     mParmZoomLevel = 0;
941     mCurPPCount = 0;
942     mRotation = 0;
943     mJpegRotation = 0;
944 }
945 
946 /*===========================================================================
947  * FUNCTION   : ~QCameraParameters
948  *
949  * DESCRIPTION: deconstructor of QCameraParameters
950  *
951  * PARAMETERS : none
952  *
953  * RETURN     : None
954  *==========================================================================*/
~QCameraParameters()955 QCameraParameters::~QCameraParameters()
956 {
957     deinit();
958 }
959 
960 /*===========================================================================
961  * FUNCTION   : createSizesString
962  *
963  * DESCRIPTION: create string obj contains array of dimensions
964  *
965  * PARAMETERS :
966  *   @sizes   : array of dimensions
967  *   @len     : size of dimension array
968  *
969  * RETURN     : string obj
970  *==========================================================================*/
createSizesString(const cam_dimension_t * sizes,size_t len)971 String8 QCameraParameters::createSizesString(const cam_dimension_t *sizes, size_t len)
972 {
973     String8 str;
974     char buffer[32];
975 
976     if (len > 0) {
977         snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
978         str.append(buffer);
979     }
980     for (size_t i = 1; i < len; i++) {
981         snprintf(buffer, sizeof(buffer), ",%dx%d",
982                 sizes[i].width, sizes[i].height);
983         str.append(buffer);
984     }
985     return str;
986 }
987 
988 /*===========================================================================
989  * FUNCTION   : createValuesString
990  *
991  * DESCRIPTION: create string obj contains array of values from map when matched
992  *              from input values array
993  *
994  * PARAMETERS :
995  *   @values  : array of values
996  *   @len     : size of values array
997  *   @map     : map contains the mapping between values and enums
998  *   @map_len : size of the map
999  *
1000  * RETURN     : string obj
1001  *==========================================================================*/
createValuesString(const valuesType * values,size_t len,const mapType * map,size_t map_len)1002 template <typename valuesType, class mapType> String8 createValuesString(
1003         const valuesType *values, size_t len, const mapType *map, size_t map_len)
1004 {
1005     String8 str;
1006     int count = 0;
1007 
1008     for (size_t i = 0; i < len; i++ ) {
1009         for (size_t j = 0; j < map_len; j ++)
1010             if (map[j].val == values[i]) {
1011                 if (NULL != map[j].desc) {
1012                     if (count > 0) {
1013                         str.append(",");
1014                     }
1015                     str.append(map[j].desc);
1016                     count++;
1017                     break; //loop j
1018                 }
1019             }
1020     }
1021     return str;
1022 }
1023 
1024 /*===========================================================================
1025  * FUNCTION   : createValuesStringFromMap
1026  *
1027  * DESCRIPTION: create string obj contains array of values directly from map
1028  *
1029  * PARAMETERS :
1030  *   @map     : map contains the mapping between values and enums
1031  *   @map_len : size of the map
1032  *
1033  * RETURN     : string obj
1034  *==========================================================================*/
createValuesStringFromMap(const mapType * map,size_t map_len)1035 template <class mapType> String8 createValuesStringFromMap(
1036         const mapType *map, size_t map_len)
1037 {
1038     String8 str;
1039 
1040     for (size_t i = 0; i < map_len; i++) {
1041         if (NULL != map[i].desc) {
1042             if (i > 0) {
1043                 str.append(",");
1044             }
1045             str.append(map[i].desc);
1046         }
1047     }
1048     return str;
1049 }
1050 
1051 /*===========================================================================
1052  * FUNCTION   : createZoomRatioValuesString
1053  *
1054  * DESCRIPTION: create string obj contains array of zoom ratio values
1055  *
1056  * PARAMETERS :
1057  *   @zoomRaios  : array of zoom ratios
1058  *   @length     : size of the array
1059  *
1060  * RETURN     : string obj
1061  *==========================================================================*/
createZoomRatioValuesString(uint32_t * zoomRatios,size_t length)1062 String8 QCameraParameters::createZoomRatioValuesString(uint32_t *zoomRatios,
1063         size_t length)
1064 {
1065     String8 str;
1066     char buffer[32] = {0};
1067 
1068     if(length > 0){
1069         snprintf(buffer, sizeof(buffer), "%d", zoomRatios[0]);
1070         str.append(buffer);
1071     }
1072 
1073     for (size_t i = 1; i < length; i++) {
1074         memset(buffer, 0, sizeof(buffer));
1075         snprintf(buffer, sizeof(buffer), ",%d", zoomRatios[i]);
1076         str.append(buffer);
1077     }
1078     return str;
1079 }
1080 
1081 /*===========================================================================
1082  * FUNCTION   : createHfrValuesString
1083  *
1084  * DESCRIPTION: create string obj contains array of hfr values from map when
1085  *              matched from input hfr values
1086  *
1087  * PARAMETERS :
1088  *   @values  : array of hfr info
1089  *   @len     : size of the array
1090  *   @map     : map of hfr string value and enum
1091  *   map_len  : size of map
1092  *
1093  * RETURN     : string obj
1094  *==========================================================================*/
createHfrValuesString(const cam_hfr_info_t * values,size_t len,const QCameraMap<cam_hfr_mode_t> * map,size_t map_len)1095 String8 QCameraParameters::createHfrValuesString(const cam_hfr_info_t *values,
1096         size_t len, const QCameraMap<cam_hfr_mode_t> *map, size_t map_len)
1097 {
1098     String8 str;
1099     int count = 0;
1100 
1101     char value[PROPERTY_VALUE_MAX];
1102     int8_t batch_count = 0;
1103 
1104     property_get("persist.camera.batchcount", value, "0");
1105     batch_count = atoi(value);
1106 
1107     for (size_t i = 0; i < len; i++ ) {
1108         for (size_t j = 0; j < map_len; j ++) {
1109             if ((batch_count < CAMERA_MIN_BATCH_COUNT)
1110                     && (map[j].val > CAM_HFR_MODE_120FPS)) {
1111                 /*TODO: Work around. Need to revert when we have
1112                 complete 240fps support*/
1113                 break;
1114             }
1115             if (map[j].val == (int)values[i].mode) {
1116                 if (NULL != map[j].desc) {
1117                     if (count > 0) {
1118                         str.append(",");
1119                     }
1120                      str.append(map[j].desc);
1121                      count++;
1122                      break; //loop j
1123                 }
1124             }
1125         }
1126     }
1127     if (count > 0) {
1128         str.append(",");
1129     }
1130     str.append(VIDEO_HFR_OFF);
1131     return str;
1132 }
1133 
1134 /*===========================================================================
1135  * FUNCTION   : createHfrSizesString
1136  *
1137  * DESCRIPTION: create string obj contains array of hfr sizes
1138  *
1139  * PARAMETERS :
1140  *   @values  : array of hfr info
1141  *   @len     : size of the array
1142  *
1143  * RETURN     : string obj
1144  *==========================================================================*/
createHfrSizesString(const cam_hfr_info_t * values,size_t len)1145 String8 QCameraParameters::createHfrSizesString(const cam_hfr_info_t *values, size_t len)
1146 {
1147     String8 str;
1148     char buffer[32];
1149 
1150     if (len > 0) {
1151         snprintf(buffer, sizeof(buffer), "%dx%d",
1152                  values[0].dim.width, values[0].dim.height);
1153         str.append(buffer);
1154     }
1155     for (size_t i = 1; i < len; i++) {
1156         snprintf(buffer, sizeof(buffer), ",%dx%d",
1157                  values[i].dim.width, values[i].dim.height);
1158         str.append(buffer);
1159     }
1160     return str;
1161 }
1162 
1163 /*===========================================================================
1164  * FUNCTION   : createFpsString
1165  *
1166  * DESCRIPTION: create string obj contains array of FPS rates
1167  *
1168  * PARAMETERS :
1169  *   @fps     : default fps range
1170  *
1171  * RETURN     : string obj
1172  *==========================================================================*/
createFpsString(cam_fps_range_t & fps)1173 String8 QCameraParameters::createFpsString(cam_fps_range_t &fps)
1174 {
1175     char buffer[32];
1176     String8 fpsValues;
1177 
1178     int min_fps = int(fps.min_fps);
1179     int max_fps = int(fps.max_fps);
1180 
1181     if (min_fps < fps.min_fps){
1182         min_fps++;
1183     }
1184     if (max_fps > fps.max_fps) {
1185         max_fps--;
1186     }
1187     if (min_fps <= max_fps) {
1188         snprintf(buffer, sizeof(buffer), "%d", min_fps);
1189         fpsValues.append(buffer);
1190     }
1191 
1192     for (int i = min_fps+1; i <= max_fps; i++) {
1193         snprintf(buffer, sizeof(buffer), ",%d", i);
1194         fpsValues.append(buffer);
1195     }
1196 
1197     return fpsValues;
1198 }
1199 
1200 /*===========================================================================
1201  * FUNCTION   : createFpsRangeString
1202  *
1203  * DESCRIPTION: create string obj contains array of FPS ranges
1204  *
1205  * PARAMETERS :
1206  *   @fps     : array of fps ranges
1207  *   @len     : size of the array
1208  *   @default_fps_index : reference to index of default fps range
1209  *
1210  * RETURN     : string obj
1211  *==========================================================================*/
createFpsRangeString(const cam_fps_range_t * fps,size_t len,int & default_fps_index)1212 String8 QCameraParameters::createFpsRangeString(const cam_fps_range_t* fps,
1213         size_t len, int &default_fps_index)
1214 {
1215     String8 str;
1216     char buffer[32];
1217     int max_range = 0;
1218     int min_fps, max_fps;
1219 
1220     if (len > 0) {
1221         min_fps = int(fps[0].min_fps * 1000);
1222         max_fps = int(fps[0].max_fps * 1000);
1223         max_range = max_fps - min_fps;
1224         default_fps_index = 0;
1225         snprintf(buffer, sizeof(buffer), "(%d,%d)", min_fps, max_fps);
1226         str.append(buffer);
1227     }
1228     for (size_t i = 1; i < len; i++) {
1229         min_fps = int(fps[i].min_fps * 1000);
1230         max_fps = int(fps[i].max_fps * 1000);
1231         if (max_range < (max_fps - min_fps)) {
1232             max_range = max_fps - min_fps;
1233             default_fps_index = (int)i;
1234         }
1235         snprintf(buffer, sizeof(buffer), ",(%d,%d)", min_fps, max_fps);
1236         str.append(buffer);
1237     }
1238     return str;
1239 }
1240 
1241 /*===========================================================================
1242  * FUNCTION   : lookupAttr
1243  *
1244  * DESCRIPTION: lookup a value by its name
1245  *
1246  * PARAMETERS :
1247  *   @attr    : map contains <name, value>
1248  *   @len     : size of the map
1249  *   @name    : name to be looked up
1250  *
1251  * RETURN     : valid value if found
1252  *              NAME_NOT_FOUND if not found
1253  *==========================================================================*/
lookupAttr(const mapType * arr,size_t len,const char * name)1254 template <class mapType> int lookupAttr(const mapType *arr,
1255         size_t len, const char *name)
1256 {
1257     if (name) {
1258         for (size_t i = 0; i < len; i++) {
1259             if (!strcmp(arr[i].desc, name))
1260                 return arr[i].val;
1261         }
1262     }
1263     return NAME_NOT_FOUND;
1264 }
1265 
1266 /*===========================================================================
1267  * FUNCTION   : lookupNameByValue
1268  *
1269  * DESCRIPTION: lookup a name by its value
1270  *
1271  * PARAMETERS :
1272  *   @attr    : map contains <name, value>
1273  *   @len     : size of the map
1274  *   @value   : value to be looked up
1275  *
1276  * RETURN     : name str or NULL if not found
1277  *==========================================================================*/
lookupNameByValue(const mapType * arr,size_t len,int value)1278 template <class mapType> const char *lookupNameByValue(const mapType *arr,
1279         size_t len, int value)
1280 {
1281     for (size_t i = 0; i < len; i++) {
1282         if (arr[i].val == value) {
1283             return arr[i].desc;
1284         }
1285     }
1286     return NULL;
1287 }
1288 
1289 /*===========================================================================
1290  * FUNCTION   : setPreviewSize
1291  *
1292  * DESCRIPTION: set preview size from user setting
1293  *
1294  * PARAMETERS :
1295  *   @params  : user setting parameters
1296  *
1297  * RETURN     : int32_t type of status
1298  *              NO_ERROR  -- success
1299  *              none-zero failure code
1300  *==========================================================================*/
setPreviewSize(const QCameraParameters & params)1301 int32_t QCameraParameters::setPreviewSize(const QCameraParameters& params)
1302 {
1303     int width, height;
1304     params.getPreviewSize(&width, &height);
1305     ALOGI("Requested preview size %d x %d", width, height);
1306 
1307     // Validate the preview size
1308     for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
1309         if (width ==  m_pCapability->preview_sizes_tbl[i].width
1310            && height ==  m_pCapability->preview_sizes_tbl[i].height) {
1311             // check if need to restart preview in case of preview size change
1312             int old_width, old_height;
1313             CameraParameters::getPreviewSize(&old_width, &old_height);
1314             if (width != old_width || height != old_height) {
1315                 m_bNeedRestart = true;
1316             }
1317 
1318             // set the new value
1319             CameraParameters::setPreviewSize(width, height);
1320             return NO_ERROR;
1321         }
1322     }
1323     ALOGE("Invalid preview size requested: %dx%d", width, height);
1324     return BAD_VALUE;
1325 }
1326 
1327 /*===========================================================================
1328  * FUNCTION   : setPictureSize
1329  *
1330  * DESCRIPTION: set picture size from user setting
1331  *
1332  * PARAMETERS :
1333  *   @params  : user setting parameters
1334  *
1335  * RETURN     : int32_t type of status
1336  *              NO_ERROR  -- success
1337  *              none-zero failure code
1338  *==========================================================================*/
setPictureSize(const QCameraParameters & params)1339 int32_t QCameraParameters::setPictureSize(const QCameraParameters& params)
1340 {
1341     int width, height;
1342     params.getPictureSize(&width, &height);
1343     ALOGI("Requested picture size %d x %d", width, height);
1344 
1345     // Validate the picture size
1346     if(!m_reprocScaleParam.isScaleEnabled()){
1347         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1348             if (width ==  m_pCapability->picture_sizes_tbl[i].width
1349                && height ==  m_pCapability->picture_sizes_tbl[i].height) {
1350                 // check if need to restart preview in case of picture size change
1351                 int old_width, old_height;
1352                 CameraParameters::getPictureSize(&old_width, &old_height);
1353                 if ((m_bZslMode || m_bRecordingHint) &&
1354                     (width != old_width || height != old_height)) {
1355                     m_bNeedRestart = true;
1356                 }
1357 
1358                 // set the new value
1359                 CameraParameters::setPictureSize(width, height);
1360                 return NO_ERROR;
1361             }
1362         }
1363     }else{
1364         //should use scaled picture size table to validate
1365         if(m_reprocScaleParam.setValidatePicSize(width, height) == NO_ERROR){
1366             // check if need to restart preview in case of picture size change
1367             int old_width, old_height;
1368             CameraParameters::getPictureSize(&old_width, &old_height);
1369             if ((m_bZslMode || m_bRecordingHint) &&
1370                 (width != old_width || height != old_height)) {
1371                 m_bNeedRestart = true;
1372             }
1373 
1374             // set the new value
1375             char val[32];
1376             snprintf(val, sizeof(val), "%dx%d", width, height);
1377             updateParamEntry(KEY_PICTURE_SIZE, val);
1378             CDBG("%s: %s", __func__, val);
1379             return NO_ERROR;
1380         }
1381     }
1382     ALOGE("Invalid picture size requested: %dx%d", width, height);
1383     return BAD_VALUE;
1384 }
1385 
1386 /*===========================================================================
1387  * FUNCTION   : setVideoSize
1388  *
1389  * DESCRIPTION: set video size from user setting
1390  *
1391  * PARAMETERS :
1392  *   @params  : user setting parameters
1393  *
1394  * RETURN     : int32_t type of status
1395  *              NO_ERROR  -- success
1396  *              none-zero failure code
1397  *==========================================================================*/
setVideoSize(const QCameraParameters & params)1398 int32_t QCameraParameters::setVideoSize(const QCameraParameters& params)
1399 {
1400     const char *str= NULL;
1401     int width, height;
1402     str = params.get(KEY_VIDEO_SIZE);
1403     if(!str) {
1404         //If application didn't set this parameter string, use the values from
1405         //getPreviewSize() as video dimensions.
1406         params.getPreviewSize(&width, &height);
1407         ALOGE("No Record Size requested, use the preview dimensions");
1408     } else {
1409         params.getVideoSize(&width, &height);
1410     }
1411 
1412     // Validate the video size
1413     for (size_t i = 0; i < m_pCapability->video_sizes_tbl_cnt; ++i) {
1414         if (width ==  m_pCapability->video_sizes_tbl[i].width
1415                 && height ==  m_pCapability->video_sizes_tbl[i].height) {
1416             // check if need to restart preview in case of video size change
1417             int old_width, old_height;
1418             CameraParameters::getVideoSize(&old_width, &old_height);
1419             if (m_bRecordingHint &&
1420                (width != old_width || height != old_height)) {
1421                 m_bNeedRestart = true;
1422             }
1423 
1424             // set the new value
1425             CameraParameters::setVideoSize(width, height);
1426             return NO_ERROR;
1427         }
1428     }
1429 
1430     ALOGE("Invalid video size requested: %dx%d", width, height);
1431     return BAD_VALUE;
1432 }
1433 
1434 /*===========================================================================
1435  * FUNCTION   : getLiveSnapshotSize
1436  *
1437  * DESCRIPTION: get live snapshot size
1438  *
1439  * PARAMETERS : dim - Update dim with the liveshot size
1440  *
1441  *==========================================================================*/
getLiveSnapshotSize(cam_dimension_t & dim)1442 void QCameraParameters::getLiveSnapshotSize(cam_dimension_t &dim)
1443 {
1444     if(is4k2kVideoResolution()) {
1445         // We support maximum 8M liveshot @4K2K video resolution
1446         cam_dimension_t resolution = {0, 0};
1447         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1448         if((m_LiveSnapshotSize.width > resolution.width) ||
1449                 (m_LiveSnapshotSize.height > resolution.height)) {
1450             m_LiveSnapshotSize.width = resolution.width;
1451             m_LiveSnapshotSize.height = resolution.height;
1452         }
1453     }
1454     dim = m_LiveSnapshotSize;
1455     CDBG_HIGH("%s: w x h: %d x %d", __func__, dim.width, dim.height);
1456 }
1457 
1458 /*===========================================================================
1459  * FUNCTION   : setLiveSnapshotSize
1460  *
1461  * DESCRIPTION: set live snapshot size
1462  *
1463  * PARAMETERS :
1464  *   @params  : user setting parameters
1465  *
1466  * RETURN     : int32_t type of status
1467  *              NO_ERROR  -- success
1468  *              none-zero failure code
1469  *==========================================================================*/
setLiveSnapshotSize(const QCameraParameters & params)1470 int32_t QCameraParameters::setLiveSnapshotSize(const QCameraParameters& params)
1471 {
1472     char value[PROPERTY_VALUE_MAX];
1473     property_get("persist.camera.opt.livepic", value, "1");
1474     bool useOptimal = atoi(value) > 0 ? true : false;
1475 
1476     // use picture size from user setting
1477     params.getPictureSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1478 
1479     size_t livesnapshot_sizes_tbl_cnt =
1480             m_pCapability->livesnapshot_sizes_tbl_cnt;
1481     cam_dimension_t *livesnapshot_sizes_tbl =
1482             &m_pCapability->livesnapshot_sizes_tbl[0];
1483 
1484     if(is4k2kVideoResolution()) {
1485         // We support maximum 8M liveshot @4K2K video resolution
1486         cam_dimension_t resolution = {0, 0};
1487         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1488         if((m_LiveSnapshotSize.width > resolution.width) ||
1489                 (m_LiveSnapshotSize.height > resolution.height)) {
1490             m_LiveSnapshotSize.width = resolution.width;
1491             m_LiveSnapshotSize.height = resolution.height;
1492         }
1493     }
1494 
1495     // check if HFR is enabled
1496     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
1497     cam_hfr_mode_t hfrMode = CAM_HFR_MODE_OFF;
1498     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
1499 
1500     if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
1501         int32_t hsr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
1502         if ((hsr != NAME_NOT_FOUND) && (hsr > CAM_HFR_MODE_OFF)) {
1503             // if HSR is enabled, change live snapshot size
1504             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1505                 if (m_pCapability->hfr_tbl[i].mode == hsr) {
1506                     livesnapshot_sizes_tbl_cnt =
1507                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1508                     livesnapshot_sizes_tbl =
1509                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1510                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1511                     break;
1512                 }
1513             }
1514         }
1515     } else if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
1516         int32_t hfr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
1517         if ((hfr != NAME_NOT_FOUND) && (hfr > CAM_HFR_MODE_OFF)) {
1518             // if HFR is enabled, change live snapshot size
1519             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1520                 if (m_pCapability->hfr_tbl[i].mode == hfr) {
1521                     livesnapshot_sizes_tbl_cnt =
1522                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1523                     livesnapshot_sizes_tbl =
1524                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1525                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1526                     break;
1527                 }
1528             }
1529         }
1530     }
1531 
1532     if (useOptimal || hfrMode != CAM_HFR_MODE_OFF) {
1533         bool found = false;
1534 
1535         // first check if picture size is within the list of supported sizes
1536         for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1537             if (m_LiveSnapshotSize.width == livesnapshot_sizes_tbl[i].width &&
1538                 m_LiveSnapshotSize.height == livesnapshot_sizes_tbl[i].height) {
1539                 found = true;
1540                 break;
1541             }
1542         }
1543 
1544         if (!found) {
1545             // use optimal live snapshot size from supported list,
1546             // that has same preview aspect ratio
1547             int width = 0, height = 0;
1548             params.getPreviewSize(&width, &height);
1549 
1550             double previewAspectRatio = (double)width / height;
1551             for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1552                 double ratio = (double)livesnapshot_sizes_tbl[i].width /
1553                                 livesnapshot_sizes_tbl[i].height;
1554                 if (fabs(previewAspectRatio - ratio) <= ASPECT_TOLERANCE) {
1555                     m_LiveSnapshotSize = livesnapshot_sizes_tbl[i];
1556                     found = true;
1557                     break;
1558                 }
1559             }
1560 
1561             if (!found && hfrMode != CAM_HFR_MODE_OFF) {
1562                 // Cannot find matching aspect ration from supported live snapshot list
1563                 // choose the max dim from preview and video size
1564                 CDBG("%s: Cannot find matching aspect ratio, choose max of preview or video size", __func__);
1565                 params.getVideoSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1566                 if (m_LiveSnapshotSize.width < width && m_LiveSnapshotSize.height < height) {
1567                     m_LiveSnapshotSize.width = width;
1568                     m_LiveSnapshotSize.height = height;
1569                 }
1570             }
1571         }
1572     }
1573     CDBG_HIGH("%s: live snapshot size %d x %d", __func__,
1574           m_LiveSnapshotSize.width, m_LiveSnapshotSize.height);
1575 
1576     return NO_ERROR;
1577 }
1578 
1579 
1580 /*===========================================================================
1581  * FUNCTION   : setRawSize
1582  *
1583  * DESCRIPTION: set live snapshot size
1584  *
1585  * PARAMETERS :
1586  *   @params  : user setting parameters
1587  *
1588  * RETURN     : int32_t type of status
1589  *              NO_ERROR  -- success
1590  *              none-zero failure code
1591  *==========================================================================*/
setRawSize(cam_dimension_t & dim)1592 int32_t QCameraParameters::setRawSize(cam_dimension_t &dim)
1593 {
1594     m_rawSize = dim;
1595     return NO_ERROR;
1596 }
1597 /*===========================================================================
1598  * FUNCTION   : setPreviewFormat
1599  *
1600  * DESCRIPTION: set preview format from user setting
1601  *
1602  * PARAMETERS :
1603  *   @params  : user setting parameters
1604  *
1605  * RETURN     : int32_t type of status
1606  *              NO_ERROR  -- success
1607  *              none-zero failure code
1608  *==========================================================================*/
setPreviewFormat(const QCameraParameters & params)1609 int32_t QCameraParameters::setPreviewFormat(const QCameraParameters& params)
1610 {
1611     const char *str = params.getPreviewFormat();
1612     int32_t previewFormat = lookupAttr(PREVIEW_FORMATS_MAP,
1613             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP), str);
1614     if (previewFormat != NAME_NOT_FOUND) {
1615         mPreviewFormat = (cam_format_t)previewFormat;
1616 
1617         CameraParameters::setPreviewFormat(str);
1618         CDBG_HIGH("%s: format %d\n", __func__, mPreviewFormat);
1619         return NO_ERROR;
1620     }
1621     ALOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str);
1622     return BAD_VALUE;
1623 }
1624 
1625 /*===========================================================================
1626  * FUNCTION   : setPictureFormat
1627  *
1628  * DESCRIPTION: set picture format from user setting
1629  *
1630  * PARAMETERS :
1631  *   @params  : user setting parameters
1632  *
1633  * RETURN     : int32_t type of status
1634  *              NO_ERROR  -- success
1635  *              none-zero failure code
1636  *==========================================================================*/
setPictureFormat(const QCameraParameters & params)1637 int32_t QCameraParameters::setPictureFormat(const QCameraParameters& params)
1638 {
1639     const char *str = params.getPictureFormat();
1640     int32_t pictureFormat = lookupAttr(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), str);
1641     if (pictureFormat != NAME_NOT_FOUND) {
1642         mPictureFormat = pictureFormat;
1643 
1644         CameraParameters::setPictureFormat(str);
1645         CDBG_HIGH("%s: format %d\n", __func__, mPictureFormat);
1646         return NO_ERROR;
1647     }
1648     ALOGE("%s: Invalid picture format value: %s", __func__, (str == NULL) ? "NULL" : str);
1649     return BAD_VALUE;
1650 }
1651 
1652 /*===========================================================================
1653  * FUNCTION   : setJpegThumbnailSize
1654  *
1655  * DESCRIPTION: set jpeg thumbnail size from user setting
1656  *
1657  * PARAMETERS :
1658  *   @params  : user setting parameters
1659  *
1660  * RETURN     : int32_t type of status
1661  *              NO_ERROR  -- success
1662  *              none-zero failure code
1663  *==========================================================================*/
setJpegThumbnailSize(const QCameraParameters & params)1664 int32_t QCameraParameters::setJpegThumbnailSize(const QCameraParameters& params)
1665 {
1666     int width = params.getInt(KEY_JPEG_THUMBNAIL_WIDTH);
1667     int height = params.getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
1668 
1669     CDBG("requested jpeg thumbnail size %d x %d", width, height);
1670 
1671     size_t sizes_cnt = PARAM_MAP_SIZE(THUMBNAIL_SIZES_MAP);
1672 
1673     cam_dimension_t dim;
1674 
1675     // While taking livesnaphot match jpeg thumbnail size aspect
1676     // ratio to liveshot size. For normal snapshot match thumbnail
1677     // aspect ratio to picture size.
1678     if (m_bRecordingHint) {
1679         getLiveSnapshotSize(dim);
1680     } else {
1681         params.getPictureSize(&dim.width, &dim.height);
1682     }
1683 
1684     if (0 == dim.height) {
1685         ALOGE("%s: picture size is invalid (%d x %d)", __func__, dim.width, dim.height);
1686         return BAD_VALUE;
1687     }
1688     double picAspectRatio = (double)dim.width / (double)dim.height;
1689 
1690     int optimalWidth = 0, optimalHeight = 0;
1691     if (width != 0 || height != 0) {
1692         // If input jpeg thumnmail size is (0,0), meaning no thumbnail needed
1693         // hornor this setting.
1694         // Otherwise, search for optimal jpeg thumbnail size that has the same
1695         // aspect ratio as picture size.
1696         // If missign jpeg thumbnail size with appropriate aspect ratio,
1697         // just honor setting supplied by application.
1698 
1699         // Try to find a size matches aspect ratio and has the largest width
1700         for (size_t i = 0; i < sizes_cnt; i++) {
1701             if (THUMBNAIL_SIZES_MAP[i].height == 0) {
1702                 // No thumbnail case, just skip
1703                 continue;
1704             }
1705             double ratio =
1706                 (double)THUMBNAIL_SIZES_MAP[i].width / THUMBNAIL_SIZES_MAP[i].height;
1707             if (fabs(ratio - picAspectRatio) > ASPECT_TOLERANCE)  {
1708                 continue;
1709             }
1710             if (THUMBNAIL_SIZES_MAP[i].width > optimalWidth) {
1711                 optimalWidth = THUMBNAIL_SIZES_MAP[i].width;
1712                 optimalHeight = THUMBNAIL_SIZES_MAP[i].height;
1713             }
1714         }
1715 
1716         if ((0 == optimalWidth) || (0 == optimalHeight)) {
1717             // Optimal size not found
1718             // Validate thumbnail size
1719             for (size_t i = 0; i < sizes_cnt; i++) {
1720                 if (width == THUMBNAIL_SIZES_MAP[i].width &&
1721                     height == THUMBNAIL_SIZES_MAP[i].height) {
1722                     optimalWidth = width;
1723                     optimalHeight = height;
1724                     break;
1725                 }
1726             }
1727         }
1728     }
1729 
1730     set(KEY_JPEG_THUMBNAIL_WIDTH, optimalWidth);
1731     set(KEY_JPEG_THUMBNAIL_HEIGHT, optimalHeight);
1732     return NO_ERROR;
1733 }
1734 
1735 /*===========================================================================
1736 
1737  * FUNCTION   : setBurstLEDOnPeriod
1738  *
1739  * DESCRIPTION: set burst LED on period
1740  *
1741  * PARAMETERS :
1742  *   @params  : user setting parameters
1743  *
1744  * RETURN     : int32_t type of status
1745  *              NO_ERROR  -- success
1746  *              none-zero failure code
1747  *==========================================================================*/
setBurstLEDOnPeriod(const QCameraParameters & params)1748 int32_t QCameraParameters::setBurstLEDOnPeriod(const QCameraParameters& params)
1749 {
1750     int nBurstLEDOnPeriod = params.getInt(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD);
1751     //Check if the LED ON period is within limits
1752     if ((nBurstLEDOnPeriod <= 0) || (nBurstLEDOnPeriod > 800)) {
1753         // if burst led on period is not set in parameters,
1754         // read from sys prop
1755         char prop[PROPERTY_VALUE_MAX];
1756         memset(prop, 0, sizeof(prop));
1757         property_get("persist.camera.led.on.period", prop, "0");
1758         nBurstLEDOnPeriod = atoi(prop);
1759         if (nBurstLEDOnPeriod <= 0) {
1760             nBurstLEDOnPeriod = 300;
1761         }
1762     }
1763 
1764     set(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD, nBurstLEDOnPeriod);
1765     m_nBurstLEDOnPeriod = nBurstLEDOnPeriod;
1766     CDBG_HIGH("%s: Burst LED on period  %u", __func__, m_nBurstLEDOnPeriod);
1767     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BURST_LED_ON_PERIOD,
1768             (uint32_t)nBurstLEDOnPeriod)) {
1769         return BAD_VALUE;
1770     }
1771 
1772     return NO_ERROR;
1773 }
1774 
1775 
1776 
1777 /*===========================================================================
1778  * FUNCTION   : setRetroActiveBurstNum
1779  *
1780  * DESCRIPTION: set retro active burst num
1781  *
1782  * PARAMETERS :
1783  *   @params  : user setting parameters
1784  *
1785  * RETURN     : int32_t type of status
1786  *              NO_ERROR  -- success
1787  *              none-zero failure code
1788  *==========================================================================*/
setRetroActiveBurstNum(const QCameraParameters & params)1789 int32_t QCameraParameters::setRetroActiveBurstNum(
1790         const QCameraParameters& params)
1791 {
1792     int32_t nBurstNum = params.getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
1793     CDBG_HIGH("%s:[ZSL Retro] m_nRetroBurstNum = %d", __func__, m_nRetroBurstNum);
1794     if (nBurstNum <= 0) {
1795         // if burst number is not set in parameters,
1796         // read from sys prop
1797         char prop[PROPERTY_VALUE_MAX];
1798         memset(prop, 0, sizeof(prop));
1799         property_get("persist.camera.retro.number", prop, "0");
1800         nBurstNum = atoi(prop);
1801         if (nBurstNum < 0) {
1802             nBurstNum = 0;
1803         }
1804     }
1805 
1806     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, nBurstNum);
1807 
1808     m_nRetroBurstNum = nBurstNum;
1809     CDBG_HIGH("%s: [ZSL Retro] m_nRetroBurstNum = %d", __func__, m_nRetroBurstNum);
1810     return NO_ERROR;
1811 }
1812 
1813 /*===========================================================================
1814  * FUNCTION   : setJpegQuality
1815  *
1816  * DESCRIPTION: set jpeg encpding quality from user setting
1817  *
1818  * PARAMETERS :
1819  *   @params  : user setting parameters
1820  *
1821  * RETURN     : int32_t type of status
1822  *              NO_ERROR  -- success
1823  *              none-zero failure code
1824  *==========================================================================*/
setJpegQuality(const QCameraParameters & params)1825 int32_t QCameraParameters::setJpegQuality(const QCameraParameters& params)
1826 {
1827     int32_t rc = NO_ERROR;
1828     int quality = params.getInt(KEY_JPEG_QUALITY);
1829     if (quality >= 0 && quality <= 100) {
1830         set(KEY_JPEG_QUALITY, quality);
1831     } else {
1832         ALOGE("%s: Invalid jpeg quality=%d", __func__, quality);
1833         rc = BAD_VALUE;
1834     }
1835 
1836     quality = params.getInt(KEY_JPEG_THUMBNAIL_QUALITY);
1837     if (quality >= 0 && quality <= 100) {
1838         set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
1839     } else {
1840         ALOGE("%s: Invalid jpeg thumbnail quality=%d", __func__, quality);
1841         rc = BAD_VALUE;
1842     }
1843     return rc;
1844 }
1845 
1846 /*===========================================================================
1847  * FUNCTION   : setOrientaion
1848  *
1849  * DESCRIPTION: set orientaion from user setting
1850  *
1851  * PARAMETERS :
1852  *   @params  : user setting parameters
1853  *
1854  * RETURN     : int32_t type of status
1855  *              NO_ERROR  -- success
1856  *              none-zero failure code
1857  *==========================================================================*/
setOrientation(const QCameraParameters & params)1858 int32_t QCameraParameters::setOrientation(const QCameraParameters& params)
1859 {
1860     const char *str = params.get(KEY_QC_ORIENTATION);
1861 
1862     if (str != NULL) {
1863         if (strcmp(str, portrait) == 0 || strcmp(str, landscape) == 0) {
1864             // Camera service needs this to decide if the preview frames and raw
1865             // pictures should be rotated.
1866             set(KEY_QC_ORIENTATION, str);
1867         } else {
1868             ALOGE("%s: Invalid orientation value: %s", __func__, str);
1869             return BAD_VALUE;
1870         }
1871     }
1872     return NO_ERROR;
1873 }
1874 
1875 /*===========================================================================
1876  * FUNCTION   : setAutoExposure
1877  *
1878  * DESCRIPTION: set auto exposure value from user setting
1879  *
1880  * PARAMETERS :
1881  *   @params  : user setting parameters
1882  *
1883  * RETURN     : int32_t type of status
1884  *              NO_ERROR  -- success
1885  *              none-zero failure code
1886  *==========================================================================*/
setAutoExposure(const QCameraParameters & params)1887 int32_t QCameraParameters::setAutoExposure(const QCameraParameters& params)
1888 {
1889     const char *str = params.get(KEY_QC_AUTO_EXPOSURE);
1890     const char *prev_str = get(KEY_QC_AUTO_EXPOSURE);
1891     if (str != NULL) {
1892         if (prev_str == NULL ||
1893             strcmp(str, prev_str) != 0) {
1894             return setAutoExposure(str);
1895         }
1896     }
1897     return NO_ERROR;
1898 }
1899 
1900 /*===========================================================================
1901  * FUNCTION   : setPreviewFpsRange
1902  *
1903  * DESCRIPTION: set preview FPS range from user setting
1904  *
1905  * PARAMETERS :
1906  *   @params  : user setting parameters
1907  *
1908  * RETURN     : int32_t type of status
1909  *              NO_ERROR  -- success
1910  *              none-zero failure code
1911  *==========================================================================*/
setPreviewFpsRange(const QCameraParameters & params)1912 int32_t QCameraParameters::setPreviewFpsRange(const QCameraParameters& params)
1913 {
1914     int minFps,maxFps;
1915     int prevMinFps, prevMaxFps, vidMinFps, vidMaxFps;
1916     int rc = NO_ERROR;
1917     bool found = false, updateNeeded = false;
1918 
1919     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
1920     params.getPreviewFpsRange(&minFps, &maxFps);
1921 
1922     CDBG_HIGH("%s: FpsRange Values:(%d, %d)", __func__, prevMinFps, prevMaxFps);
1923     CDBG_HIGH("%s: Requested FpsRange Values:(%d, %d)", __func__, minFps, maxFps);
1924 
1925     //first check if we need to change fps because of HFR mode change
1926     updateNeeded = UpdateHFRFrameRate(params);
1927     if (updateNeeded) {
1928         m_bNeedRestart = true;
1929         rc = setHighFrameRate(mHfrMode);
1930         if (rc != NO_ERROR) goto end;
1931     }
1932     CDBG_HIGH("%s: UpdateHFRFrameRate %d", __func__, updateNeeded);
1933 
1934     vidMinFps = (int)m_hfrFpsRange.video_min_fps;
1935     vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
1936 
1937     if(minFps == prevMinFps && maxFps == prevMaxFps) {
1938         if ( m_bFixedFrameRateSet ) {
1939             minFps = params.getPreviewFrameRate() * 1000;
1940             maxFps = params.getPreviewFrameRate() * 1000;
1941             m_bFixedFrameRateSet = false;
1942         } else if (!updateNeeded) {
1943             CDBG_HIGH("%s: No change in FpsRange", __func__);
1944             rc = NO_ERROR;
1945             goto end;
1946         }
1947     }
1948     for(size_t i = 0; i < m_pCapability->fps_ranges_tbl_cnt; i++) {
1949         // if the value is in the supported list
1950         if (minFps >= m_pCapability->fps_ranges_tbl[i].min_fps * 1000 &&
1951                 maxFps <= m_pCapability->fps_ranges_tbl[i].max_fps * 1000) {
1952             found = true;
1953             CDBG_HIGH("%s: FPS i=%d : minFps = %d, maxFps = %d"
1954                     " vidMinFps = %d, vidMaxFps = %d",
1955                     __func__, i, minFps, maxFps,
1956                     (int)m_hfrFpsRange.video_min_fps,
1957                     (int)m_hfrFpsRange.video_max_fps);
1958             if ((0.0f >= m_hfrFpsRange.video_min_fps) ||
1959                     (0.0f >= m_hfrFpsRange.video_max_fps)) {
1960                 vidMinFps = minFps;
1961                 vidMaxFps = maxFps;
1962             }
1963             else {
1964                 vidMinFps = (int)m_hfrFpsRange.video_min_fps;
1965                 vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
1966             }
1967 
1968             setPreviewFpsRange(minFps, maxFps, vidMinFps, vidMaxFps);
1969             break;
1970         }
1971     }
1972     if(found == false){
1973         ALOGE("%s: error: FPS range value not supported", __func__);
1974         rc = BAD_VALUE;
1975     }
1976 end:
1977     return rc;
1978 }
1979 
1980 /*===========================================================================
1981  * FUNCTION   : UpdateHFRFrameRate
1982  *
1983  * DESCRIPTION: set preview FPS range based on HFR setting
1984  *
1985  * PARAMETERS :
1986  *   @params  : user setting parameters
1987  *
1988  * RETURN     : bool true/false
1989  *                  true -if HAL needs to overwrite FPS range set by app, false otherwise.
1990  *==========================================================================*/
1991 
UpdateHFRFrameRate(const QCameraParameters & params)1992 bool QCameraParameters::UpdateHFRFrameRate(const QCameraParameters& params)
1993 {
1994     bool updateNeeded = false;
1995     int min_fps, max_fps;
1996     int32_t hfrMode = CAM_HFR_MODE_OFF;
1997     int32_t newHfrMode = CAM_HFR_MODE_OFF;
1998 
1999     int parm_minfps,parm_maxfps;
2000     int prevMinFps, prevMaxFps;
2001     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
2002     params.getPreviewFpsRange(&parm_minfps, &parm_maxfps);
2003     CDBG_HIGH("%s: CameraParameters - : minFps = %d, maxFps = %d ",
2004                 __func__, prevMinFps, prevMaxFps);
2005     CDBG_HIGH("%s: Requested params - : minFps = %d, maxFps = %d ",
2006                 __func__, parm_minfps, parm_maxfps);
2007 
2008     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2009     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2010 
2011     const char *prev_hfrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2012     const char *prev_hsrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2013 
2014     if ((hfrStr != NULL) && (prev_hfrStr != NULL) && strcmp(hfrStr, prev_hfrStr)) {
2015         updateParamEntry(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfrStr);
2016     }
2017 
2018     if ((hsrStr != NULL) && (prev_hsrStr != NULL) && strcmp(hsrStr, prev_hsrStr)) {
2019         updateParamEntry(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, hsrStr);
2020 
2021     }
2022 
2023     // check if HFR is enabled
2024     if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
2025         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
2026         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2027     }
2028     // check if HSR is enabled
2029     else if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
2030         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
2031         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2032     }
2033     CDBG_HIGH("%s: prevHfrMode - %d, currentHfrMode = %d ",
2034                 __func__, mHfrMode, newHfrMode);
2035 
2036     if (mHfrMode != newHfrMode) {
2037         updateNeeded = true;
2038         mHfrMode = newHfrMode;
2039         switch (mHfrMode) {
2040             case CAM_HFR_MODE_60FPS:
2041                 min_fps = 60000;
2042                 max_fps = 60000;
2043                 break;
2044             case CAM_HFR_MODE_90FPS:
2045                 min_fps = 90000;
2046                 max_fps = 90000;
2047                 break;
2048             case CAM_HFR_MODE_120FPS:
2049                 min_fps = 120000;
2050                 max_fps = 120000;
2051                 break;
2052             case CAM_HFR_MODE_150FPS:
2053                 min_fps = 150000;
2054                 max_fps = 150000;
2055                 break;
2056             case CAM_HFR_MODE_180FPS:
2057                 min_fps = 180000;
2058                 max_fps = 180000;
2059                 break;
2060             case CAM_HFR_MODE_210FPS:
2061                 min_fps = 210000;
2062                 max_fps = 210000;
2063                 break;
2064             case CAM_HFR_MODE_240FPS:
2065                 min_fps = 240000;
2066                 max_fps = 240000;
2067                 break;
2068             case CAM_HFR_MODE_480FPS:
2069                 min_fps = 480000;
2070                 max_fps = 480000;
2071                 break;
2072             case CAM_HFR_MODE_OFF:
2073             default:
2074                 // Set Video Fps to zero
2075                 min_fps = 0;
2076                 max_fps = 0;
2077                 break;
2078         }
2079         m_hfrFpsRange.video_min_fps = (float)min_fps;
2080         m_hfrFpsRange.video_max_fps = (float)max_fps;
2081 
2082         CDBG_HIGH("%s: HFR mode (%d) Set video FPS : minFps = %d, maxFps = %d ",
2083                 __func__, mHfrMode, min_fps, max_fps);
2084     }
2085 
2086     m_hfrFpsRange.min_fps = (float)parm_minfps;
2087     m_hfrFpsRange.max_fps = (float)parm_maxfps;
2088 
2089     // Remember if HFR mode is ON
2090     if ((mHfrMode > CAM_HFR_MODE_OFF) && (mHfrMode < CAM_HFR_MODE_MAX)) {
2091         CDBG_HIGH("HFR mode is ON");
2092         m_bHfrMode = true;
2093     } else {
2094         m_hfrFpsRange.video_min_fps = 0;
2095         m_hfrFpsRange.video_max_fps = 0;
2096         m_bHfrMode = false;
2097         CDBG_HIGH("HFR mode is OFF");
2098     }
2099 
2100     if (m_bHfrMode && (mHfrMode > CAM_HFR_MODE_120FPS)
2101             && (parm_maxfps != 0)) {
2102         /* Setting Buffer batch count to use batch mode for higher fps*/
2103         setBufBatchCount((int8_t)(m_hfrFpsRange.video_max_fps / parm_maxfps));
2104     }
2105 
2106     return updateNeeded;
2107 }
2108 
2109 /*===========================================================================
2110  * FUNCTION   : setPreviewFrameRate
2111  *
2112  * DESCRIPTION: set preview frame rate from user setting
2113  *
2114  * PARAMETERS :
2115  *   @params  : user setting parameters
2116  *
2117  * RETURN     : int32_t type of status
2118  *              NO_ERROR  -- success
2119  *              none-zero failure code
2120  *==========================================================================*/
setPreviewFrameRate(const QCameraParameters & params)2121 int32_t QCameraParameters::setPreviewFrameRate(const QCameraParameters& params)
2122 {
2123     const char *str = params.get(KEY_PREVIEW_FRAME_RATE);
2124     const char *prev_str = get(KEY_PREVIEW_FRAME_RATE);
2125 
2126     if ( str ) {
2127         if ( prev_str &&
2128              strcmp(str, prev_str)) {
2129             CDBG("%s: Requested Fixed Frame Rate %s", __func__, str);
2130             updateParamEntry(KEY_PREVIEW_FRAME_RATE, str);
2131             m_bFixedFrameRateSet = true;
2132         }
2133     }
2134     return NO_ERROR;
2135 }
2136 
2137 /*===========================================================================
2138  * FUNCTION   : setEffect
2139  *
2140  * DESCRIPTION: set effect value from user setting
2141  *
2142  * PARAMETERS :
2143  *   @params  : user setting parameters
2144  *
2145  * RETURN     : int32_t type of status
2146  *              NO_ERROR  -- success
2147  *              none-zero failure code
2148  *==========================================================================*/
setEffect(const QCameraParameters & params)2149 int32_t QCameraParameters::setEffect(const QCameraParameters& params)
2150 {
2151     const char *str = params.get(KEY_EFFECT);
2152     const char *prev_str = get(KEY_EFFECT);
2153     if (str != NULL) {
2154         if (prev_str == NULL ||
2155             strcmp(str, prev_str) != 0 ||
2156             m_bUpdateEffects == true ) {
2157             m_bUpdateEffects = false;
2158             return setEffect(str);
2159         }
2160     }
2161     return NO_ERROR;
2162 }
2163 
2164 /*===========================================================================
2165  * FUNCTION   : setFocusMode
2166  *
2167  * DESCRIPTION: set focus mode from user setting
2168  *
2169  * PARAMETERS :
2170  *   @params  : user setting parameters
2171  *
2172  * RETURN     : int32_t type of status
2173  *              NO_ERROR  -- success
2174  *              none-zero failure code
2175  *==========================================================================*/
setFocusMode(const QCameraParameters & params)2176 int32_t QCameraParameters::setFocusMode(const QCameraParameters& params)
2177 {
2178     const char *str = params.get(KEY_FOCUS_MODE);
2179     const char *prev_str = get(KEY_FOCUS_MODE);
2180     if (str != NULL) {
2181         if (prev_str == NULL ||
2182             strcmp(str, prev_str) != 0) {
2183             return setFocusMode(str);
2184         }
2185     }
2186     return NO_ERROR;
2187 }
2188 
2189 /*===========================================================================
2190  * FUNCTION   : setFocusPosition
2191  *
2192  * DESCRIPTION: set focus position from user setting
2193  *
2194  * PARAMETERS :
2195  *   @params  : user setting parameters
2196  *
2197  * RETURN     : int32_t type of status
2198  *              NO_ERROR  -- success
2199  *              none-zero failure code
2200  *==========================================================================*/
setFocusPosition(const QCameraParameters & params)2201 int32_t  QCameraParameters::setFocusPosition(const QCameraParameters& params)
2202 {
2203     const char *focus_str = params.get(KEY_FOCUS_MODE);
2204 
2205     if (NULL == focus_str) {
2206         return NO_ERROR;
2207     }
2208 
2209     CDBG("%s, current focus mode: %s", __func__, focus_str);
2210     if (strcmp(focus_str, FOCUS_MODE_MANUAL_POSITION)) {
2211         CDBG_HIGH("%s, dont set focus pos to back-end!", __func__);
2212         return NO_ERROR;
2213     }
2214 
2215     const char *pos = params.get(KEY_QC_MANUAL_FOCUS_POSITION);
2216     const char *prev_pos = get(KEY_QC_MANUAL_FOCUS_POSITION);
2217     const char *type = params.get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2218     const char *prev_type = get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2219 
2220     if ((pos != NULL) && (type != NULL)) {
2221         if (prev_pos  == NULL || (strcmp(pos, prev_pos) != 0) ||
2222                 prev_type == NULL || (strcmp(type, prev_type) != 0)) {
2223             return setFocusPosition(type, pos);
2224         }
2225     }
2226 
2227     return NO_ERROR;
2228 }
2229 
2230 /*===========================================================================
2231  * FUNCTION   : setBrightness
2232  *
2233  * DESCRIPTION: set brightness control value from user setting
2234  *
2235  * PARAMETERS :
2236  *   @params  : user setting parameters
2237  *
2238  * RETURN     : int32_t type of status
2239  *              NO_ERROR  -- success
2240  *              none-zero failure code
2241  *==========================================================================*/
setBrightness(const QCameraParameters & params)2242 int32_t QCameraParameters::setBrightness(const QCameraParameters& params)
2243 {
2244     int currentBrightness = getInt(KEY_QC_BRIGHTNESS);
2245     int brightness = params.getInt(KEY_QC_BRIGHTNESS);
2246 
2247     if(params.get(KEY_QC_BRIGHTNESS) == NULL) {
2248        CDBG_HIGH("%s: Brigtness not set by App ",__func__);
2249        return NO_ERROR;
2250     }
2251     if (currentBrightness !=  brightness) {
2252         if (brightness >= m_pCapability->brightness_ctrl.min_value &&
2253             brightness <= m_pCapability->brightness_ctrl.max_value) {
2254             CDBG(" new brightness value : %d ", brightness);
2255             return setBrightness(brightness);
2256         } else {
2257             ALOGE("%s: invalid value %d out of (%d, %d)",
2258                   __func__, brightness,
2259                   m_pCapability->brightness_ctrl.min_value,
2260                   m_pCapability->brightness_ctrl.max_value);
2261             return BAD_VALUE;
2262         }
2263     } else {
2264         CDBG("%s: No brightness value changed.", __func__);
2265         return NO_ERROR;
2266     }
2267 }
2268 
2269 /*===========================================================================
2270  * FUNCTION   : getBrightness
2271  *
2272  * DESCRIPTION: get brightness control value from user setting
2273  *
2274  * PARAMETERS :
2275  *   @params  : user setting parameters
2276  *
2277  * RETURN     : int32_t type of status
2278  *              NO_ERROR  -- success
2279  *              none-zero failure code
2280  *==========================================================================*/
getBrightness()2281 int QCameraParameters::getBrightness()
2282 {
2283     return getInt(KEY_QC_BRIGHTNESS);
2284 }
2285 
2286 /*===========================================================================
2287  * FUNCTION   : setSharpness
2288  *
2289  * DESCRIPTION: set sharpness control value from user setting
2290  *
2291  * PARAMETERS :
2292  *   @params  : user setting parameters
2293  *
2294  * RETURN     : int32_t type of status
2295  *              NO_ERROR  -- success
2296  *              none-zero failure code
2297  *==========================================================================*/
setSharpness(const QCameraParameters & params)2298 int32_t QCameraParameters::setSharpness(const QCameraParameters& params)
2299 {
2300     int shaprness = params.getInt(KEY_QC_SHARPNESS);
2301     int prev_sharp = getInt(KEY_QC_SHARPNESS);
2302 
2303     if(params.get(KEY_QC_SHARPNESS) == NULL) {
2304        CDBG_HIGH("%s: Sharpness not set by App ",__func__);
2305        return NO_ERROR;
2306     }
2307     if (prev_sharp !=  shaprness) {
2308         if((shaprness >= m_pCapability->sharpness_ctrl.min_value) &&
2309            (shaprness <= m_pCapability->sharpness_ctrl.max_value)) {
2310             CDBG(" new sharpness value : %d ", shaprness);
2311             return setSharpness(shaprness);
2312         } else {
2313             ALOGE("%s: invalid value %d out of (%d, %d)",
2314                   __func__, shaprness,
2315                   m_pCapability->sharpness_ctrl.min_value,
2316                   m_pCapability->sharpness_ctrl.max_value);
2317             return BAD_VALUE;
2318         }
2319     } else {
2320         CDBG("%s: No value change in shaprness", __func__);
2321         return NO_ERROR;
2322     }
2323 }
2324 
2325 /*===========================================================================
2326  * FUNCTION   : setSkintoneEnahancement
2327  *
2328  * DESCRIPTION: set skin tone enhancement factor from user setting
2329  *
2330  * PARAMETERS :
2331  *   @params  : user setting parameters
2332  *
2333  * RETURN     : int32_t type of status
2334  *              NO_ERROR  -- success
2335  *              none-zero failure code
2336  *==========================================================================*/
setSkinToneEnhancement(const QCameraParameters & params)2337 int32_t QCameraParameters::setSkinToneEnhancement(const QCameraParameters& params)
2338 {
2339     int sceFactor = params.getInt(KEY_QC_SCE_FACTOR);
2340     int prev_sceFactor = getInt(KEY_QC_SCE_FACTOR);
2341 
2342     if(params.get(KEY_QC_SCE_FACTOR) == NULL) {
2343        CDBG_HIGH("%s: Skintone enhancement not set by App ",__func__);
2344        return NO_ERROR;
2345     }
2346     if (prev_sceFactor != sceFactor) {
2347         if((sceFactor >= m_pCapability->sce_ctrl.min_value) &&
2348            (sceFactor <= m_pCapability->sce_ctrl.max_value)) {
2349             CDBG(" new Skintone Enhancement value : %d ", sceFactor);
2350             return setSkinToneEnhancement(sceFactor);
2351         } else {
2352             ALOGE("%s: invalid value %d out of (%d, %d)",
2353                   __func__, sceFactor,
2354                   m_pCapability->sce_ctrl.min_value,
2355                   m_pCapability->sce_ctrl.max_value);
2356             return BAD_VALUE;
2357         }
2358     } else {
2359         CDBG("%s: No value change in skintone enhancement factor", __func__);
2360         return NO_ERROR;
2361     }
2362 }
2363 
2364 /*===========================================================================
2365  * FUNCTION   : setSaturation
2366  *
2367  * DESCRIPTION: set saturation control value from user setting
2368  *
2369  * PARAMETERS :
2370  *   @params  : user setting parameters
2371  *
2372  * RETURN     : int32_t type of status
2373  *              NO_ERROR  -- success
2374  *              none-zero failure code
2375  *==========================================================================*/
setSaturation(const QCameraParameters & params)2376 int32_t QCameraParameters::setSaturation(const QCameraParameters& params)
2377 {
2378     int saturation = params.getInt(KEY_QC_SATURATION);
2379     int prev_sat = getInt(KEY_QC_SATURATION);
2380 
2381     if(params.get(KEY_QC_SATURATION) == NULL) {
2382        CDBG_HIGH("%s: Saturation not set by App ",__func__);
2383        return NO_ERROR;
2384     }
2385     if (prev_sat !=  saturation) {
2386         if((saturation >= m_pCapability->saturation_ctrl.min_value) &&
2387            (saturation <= m_pCapability->saturation_ctrl.max_value)) {
2388             CDBG(" new saturation value : %d ", saturation);
2389             return setSaturation(saturation);
2390         } else {
2391             ALOGE("%s: invalid value %d out of (%d, %d)",
2392                   __func__, saturation,
2393                   m_pCapability->saturation_ctrl.min_value,
2394                   m_pCapability->saturation_ctrl.max_value);
2395             return BAD_VALUE;
2396         }
2397     } else {
2398         CDBG("%s: No value change in saturation factor", __func__);
2399         return NO_ERROR;
2400     }
2401 }
2402 
2403 /*===========================================================================
2404  * FUNCTION   : setContrast
2405  *
2406  * DESCRIPTION: set contrast control value from user setting
2407  *
2408  * PARAMETERS :
2409  *   @params  : user setting parameters
2410  *
2411  * RETURN     : int32_t type of status
2412  *              NO_ERROR  -- success
2413  *              none-zero failure code
2414  *==========================================================================*/
setContrast(const QCameraParameters & params)2415 int32_t QCameraParameters::setContrast(const QCameraParameters& params)
2416 {
2417     int contrast = params.getInt(KEY_QC_CONTRAST);
2418     int prev_contrast = getInt(KEY_QC_CONTRAST);
2419 
2420     if(params.get(KEY_QC_CONTRAST) == NULL) {
2421        CDBG_HIGH("%s: Contrast not set by App ",__func__);
2422        return NO_ERROR;
2423     }
2424     if (prev_contrast !=  contrast) {
2425         if((contrast >= m_pCapability->contrast_ctrl.min_value) &&
2426            (contrast <= m_pCapability->contrast_ctrl.max_value)) {
2427             CDBG(" new contrast value : %d ", contrast);
2428             int32_t rc = setContrast(contrast);
2429             return rc;
2430         } else {
2431             ALOGE("%s: invalid value %d out of (%d, %d)",
2432                   __func__, contrast,
2433                   m_pCapability->contrast_ctrl.min_value,
2434                   m_pCapability->contrast_ctrl.max_value);
2435             return BAD_VALUE;
2436         }
2437     } else {
2438         CDBG("%s: No value change in contrast", __func__);
2439         return NO_ERROR;
2440     }
2441 }
2442 
2443 /*===========================================================================
2444  * FUNCTION   : setExposureCompensation
2445  *
2446  * DESCRIPTION: set exposure compensation value from user setting
2447  *
2448  * PARAMETERS :
2449  *   @params  : user setting parameters
2450  *
2451  * RETURN     : int32_t type of status
2452  *              NO_ERROR  -- success
2453  *              none-zero failure code
2454  *==========================================================================*/
setExposureCompensation(const QCameraParameters & params)2455 int32_t QCameraParameters::setExposureCompensation(const QCameraParameters & params)
2456 {
2457     int expComp = params.getInt(KEY_EXPOSURE_COMPENSATION);
2458     int prev_expComp = getInt(KEY_EXPOSURE_COMPENSATION);
2459 
2460     if(params.get(KEY_EXPOSURE_COMPENSATION) == NULL) {
2461        CDBG_HIGH("%s: Exposure compensation not set by App ",__func__);
2462        return NO_ERROR;
2463     }
2464     if (prev_expComp != expComp) {
2465         if((expComp >= m_pCapability->exposure_compensation_min) &&
2466            (expComp <= m_pCapability->exposure_compensation_max)) {
2467             CDBG(" new Exposure Compensation value : %d ", expComp);
2468             return setExposureCompensation(expComp);
2469         } else {
2470             ALOGE("%s: invalid value %d out of (%d, %d)",
2471                   __func__, expComp,
2472                   m_pCapability->exposure_compensation_min,
2473                   m_pCapability->exposure_compensation_max);
2474             return BAD_VALUE;
2475         }
2476     } else {
2477         CDBG("%s: No value change in Exposure Compensation", __func__);
2478         return NO_ERROR;
2479     }
2480 }
2481 
2482 /*===========================================================================
2483  * FUNCTION   : setWhiteBalance
2484  *
2485  * DESCRIPTION: set white balance value from user setting
2486  *
2487  * PARAMETERS :
2488  *   @params  : user setting parameters
2489  *
2490  * RETURN     : int32_t type of status
2491  *              NO_ERROR  -- success
2492  *              none-zero failure code
2493  *==========================================================================*/
setWhiteBalance(const QCameraParameters & params)2494 int32_t QCameraParameters::setWhiteBalance(const QCameraParameters& params)
2495 {
2496     const char *str = params.get(KEY_WHITE_BALANCE);
2497     const char *prev_str = get(KEY_WHITE_BALANCE);
2498     if (str != NULL) {
2499         if (prev_str == NULL ||
2500             strcmp(str, prev_str) != 0) {
2501             return setWhiteBalance(str);
2502         }
2503     }
2504     return NO_ERROR;
2505 }
2506 
2507 /*===========================================================================
2508  * FUNCTION   : setManualWhiteBalance
2509  *
2510  * DESCRIPTION: set manual white balance from user setting
2511  *
2512  * PARAMETERS :
2513  *   @params  : user setting parameters
2514  *
2515  * RETURN     : int32_t type of status
2516  *              NO_ERROR  -- success
2517  *              none-zero failure code
2518  *==========================================================================*/
setManualWhiteBalance(const QCameraParameters & params)2519 int32_t  QCameraParameters::setManualWhiteBalance(const QCameraParameters& params)
2520 {
2521     int32_t rc = NO_ERROR;
2522     const char *wb_str = params.get(KEY_WHITE_BALANCE);
2523     CDBG("%s, current wb mode: %s", __func__, wb_str);
2524 
2525     if (wb_str != NULL) {
2526         if (strcmp(wb_str, WHITE_BALANCE_MANUAL)) {
2527             CDBG("%s, dont set cct to back-end.", __func__);
2528             return NO_ERROR;
2529         }
2530     }
2531 
2532     const char *value = params.get(KEY_QC_MANUAL_WB_VALUE);
2533     const char *prev_value = get(KEY_QC_MANUAL_WB_VALUE);
2534     const char *type = params.get(KEY_QC_MANUAL_WB_TYPE);
2535     const char *prev_type = get(KEY_QC_MANUAL_WB_TYPE);
2536 
2537     if ((value != NULL) && (type != NULL)) {
2538         if (prev_value  == NULL || (strcmp(value, prev_value) != 0) ||
2539                 prev_type == NULL || (strcmp(type, prev_type) != 0)) {
2540             updateParamEntry(KEY_QC_MANUAL_WB_TYPE, type);
2541             updateParamEntry(KEY_QC_MANUAL_WB_VALUE, value);
2542             int32_t wb_type = atoi(type);
2543             if (wb_type == CAM_MANUAL_WB_MODE_CCT) {
2544                 rc = setWBManualCCT(value);
2545             } else if (wb_type == CAM_MANUAL_WB_MODE_GAIN) {
2546                 rc = setManualWBGains(value);
2547             } else {
2548                 rc = BAD_VALUE;
2549             }
2550         }
2551     }
2552     return rc;
2553 }
2554 
2555 /*===========================================================================
2556  * FUNCTION   : setAntibanding
2557  *
2558  * DESCRIPTION: set antibanding value from user setting
2559  *
2560  * PARAMETERS :
2561  *   @params  : user setting parameters
2562  *
2563  * RETURN     : int32_t type of status
2564  *              NO_ERROR  -- success
2565  *              none-zero failure code
2566  *==========================================================================*/
setAntibanding(const QCameraParameters & params)2567 int32_t QCameraParameters::setAntibanding(const QCameraParameters& params)
2568 {
2569     const char *str = params.get(KEY_ANTIBANDING);
2570     const char *prev_str = get(KEY_ANTIBANDING);
2571     if (str != NULL) {
2572         if (prev_str == NULL ||
2573             strcmp(str, prev_str) != 0) {
2574             return setAntibanding(str);
2575         }
2576     }
2577     return NO_ERROR;
2578 }
2579 
2580 /*===========================================================================
2581  * FUNCTION   : setStatsDebugMask
2582  *
2583  * DESCRIPTION: get the value from persist file in Stats module that will
2584  *              control funtionality in the module
2585  *
2586  * PARAMETERS : none
2587  *
2588  * RETURN     : int32_t type of status
2589  *              NO_ERROR  -- success
2590  *              none-zero failure code
2591  *==========================================================================*/
setStatsDebugMask()2592 int32_t QCameraParameters::setStatsDebugMask()
2593 {
2594     uint32_t mask = 0;
2595     char value[PROPERTY_VALUE_MAX];
2596 
2597     property_get("persist.camera.stats.debug.mask", value, "0");
2598     mask = (uint32_t)atoi(value);
2599 
2600     CDBG_HIGH("%s: ctrl mask :%d", __func__, mask);
2601 
2602     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_DEBUG_MASK, mask)) {
2603         return BAD_VALUE;
2604     }
2605 
2606     return NO_ERROR;
2607 }
2608 
2609 /*===========================================================================
2610  * FUNCTION   : setPAAF
2611  *
2612  * DESCRIPTION: get the value from persist file in Stats module that will
2613  *              control the preview assisted AF in the module
2614  *
2615  * PARAMETERS : none
2616  *
2617  * RETURN     : int32_t type of status
2618  *              NO_ERROR  -- success
2619  *              none-zero failure code
2620  *==========================================================================*/
setPAAF()2621 int32_t QCameraParameters::setPAAF()
2622 {
2623     uint32_t paaf = 0;
2624     char value[PROPERTY_VALUE_MAX];
2625 
2626     property_get("persist.camera.stats.af.paaf", value, "1");
2627     paaf = (uint32_t)atoi(value);
2628 
2629     CDBG_HIGH("%s: PAAF is: %s", __func__, paaf ? "ON": "OFF");
2630 
2631     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_AF_PAAF, paaf)) {
2632         return BAD_VALUE;
2633     }
2634 
2635     return NO_ERROR;
2636 }
2637 
2638 /*===========================================================================
2639  * FUNCTION   : setSceneDetect
2640  *
2641  * DESCRIPTION: set scenen detect value from user setting
2642  *
2643  * PARAMETERS :
2644  *   @params  : user setting parameters
2645  *
2646  * RETURN     : int32_t type of status
2647  *              NO_ERROR  -- success
2648  *              none-zero failure code
2649  *==========================================================================*/
setSceneDetect(const QCameraParameters & params)2650 int32_t QCameraParameters::setSceneDetect(const QCameraParameters& params)
2651 {
2652     const char *str = params.get(KEY_QC_SCENE_DETECT);
2653     const char *prev_str = get(KEY_QC_SCENE_DETECT);
2654     if (str != NULL) {
2655         if (prev_str == NULL ||
2656             strcmp(str, prev_str) != 0) {
2657             return setSceneDetect(str);
2658         }
2659     }
2660     return NO_ERROR;
2661 }
2662 
2663 /*===========================================================================
2664  * FUNCTION   : setVideoHDR
2665  *
2666  * DESCRIPTION: set video HDR value from user setting
2667  *
2668  * PARAMETERS :
2669  *   @params  : user setting parameters
2670  *
2671  * RETURN     : int32_t type of status
2672  *              NO_ERROR  -- success
2673  *              none-zero failure code
2674  *==========================================================================*/
setVideoHDR(const QCameraParameters & params)2675 int32_t QCameraParameters::setVideoHDR(const QCameraParameters& params)
2676 {
2677     const char *str = params.get(KEY_QC_VIDEO_HDR);
2678     const char *prev_str = get(KEY_QC_VIDEO_HDR);
2679     if (str != NULL) {
2680         if (prev_str == NULL ||
2681             strcmp(str, prev_str) != 0) {
2682             return setVideoHDR(str);
2683         }
2684     }
2685     return NO_ERROR;
2686 }
2687 
2688 /*===========================================================================
2689  * FUNCTION   : setVtEnable
2690  *
2691  * DESCRIPTION: set vt Time Stamp enable from user setting
2692  *
2693  * PARAMETERS :
2694  *   @params  : user setting parameters
2695  *
2696  * RETURN     : int32_t type of status
2697  *              NO_ERROR  -- success
2698  *              none-zero failure code
2699  *==========================================================================*/
setVtEnable(const QCameraParameters & params)2700 int32_t QCameraParameters::setVtEnable(const QCameraParameters& params)
2701 {
2702     const char *str = params.get(KEY_QC_VT_ENABLE);
2703     const char *prev_str = get(KEY_QC_VT_ENABLE);
2704     if (str != NULL) {
2705         if (prev_str == NULL ||
2706             strcmp(str, prev_str) != 0) {
2707             return setVtEnable(str);
2708         }
2709     }
2710     return NO_ERROR;
2711 }
2712 
2713 /*===========================================================================
2714  * FUNCTION   : setFaceRecognition
2715  *
2716  * DESCRIPTION: set face recognition mode from user setting
2717  *
2718  * PARAMETERS :
2719  *   @params  : user setting parameters
2720  *
2721  * RETURN     : int32_t type of status
2722  *              NO_ERROR  -- success
2723  *              none-zero failure code
2724  *==========================================================================*/
setFaceRecognition(const QCameraParameters & params)2725 int32_t QCameraParameters::setFaceRecognition(const QCameraParameters& params)
2726 {
2727     const char *str = params.get(KEY_QC_FACE_RECOGNITION);
2728     const char *prev_str = get(KEY_QC_FACE_RECOGNITION);
2729     if (str != NULL) {
2730         if (prev_str == NULL ||
2731             strcmp(str, prev_str) != 0) {
2732             uint32_t maxFaces = (uint32_t)params.getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
2733             return setFaceRecognition(str, maxFaces);
2734         }
2735     }
2736     return NO_ERROR;
2737 }
2738 
2739 /*===========================================================================
2740  * FUNCTION   : setZoom
2741  *
2742  * DESCRIPTION: set zoom value from user setting
2743  *
2744  * PARAMETERS :
2745  *   @params  : user setting parameters
2746  *
2747  * RETURN     : int32_t type of status
2748  *              NO_ERROR  -- success
2749  *              none-zero failure code
2750  *==========================================================================*/
setZoom(const QCameraParameters & params)2751 int32_t QCameraParameters::setZoom(const QCameraParameters& params)
2752 {
2753     if ((m_pCapability->zoom_supported == 0 ||
2754          m_pCapability->zoom_ratio_tbl_cnt == 0)) {
2755         CDBG_HIGH("%s: no zoom support", __func__);
2756         return NO_ERROR;
2757     }
2758 
2759     int zoomLevel = params.getInt(KEY_ZOOM);
2760     mParmZoomLevel = zoomLevel;
2761     if ((zoomLevel < 0) || (zoomLevel >= (int)m_pCapability->zoom_ratio_tbl_cnt)) {
2762         ALOGE("%s: invalid value %d out of (%d, %d)",
2763               __func__, zoomLevel,
2764               0, m_pCapability->zoom_ratio_tbl_cnt-1);
2765         return BAD_VALUE;
2766     }
2767 
2768     int prevZoomLevel = getInt(KEY_ZOOM);
2769     if (prevZoomLevel == zoomLevel) {
2770         CDBG("%s: No value change in zoom %d %d", __func__, prevZoomLevel, zoomLevel);
2771         return NO_ERROR;
2772     }
2773 
2774     return setZoom(zoomLevel);
2775 }
2776 
2777 /*===========================================================================
2778  * FUNCTION   : setISOValue
2779  *
2780  * DESCRIPTION: set ISO value from user setting
2781  *
2782  * PARAMETERS :
2783  *   @params  : user setting parameters
2784  *
2785  * RETURN     : int32_t type of status
2786  *              NO_ERROR  -- success
2787  *              none-zero failure code
2788  *==========================================================================*/
setISOValue(const QCameraParameters & params)2789 int32_t  QCameraParameters::setISOValue(const QCameraParameters& params)
2790 {
2791     const char *str = params.get(KEY_QC_ISO_MODE);
2792     const char *prev_str = get(KEY_QC_ISO_MODE);
2793     if (str != NULL) {
2794         if (prev_str == NULL ||
2795             strcmp(str, prev_str) != 0) {
2796             return setISOValue(str);
2797         }
2798     }
2799     return NO_ERROR;
2800 }
2801 
2802 /*===========================================================================
2803  * FUNCTION   : setContinuousISO
2804  *
2805  * DESCRIPTION: set ISO value from user setting
2806  *
2807  * PARAMETERS :
2808  *   @params  : user setting parameters
2809  *
2810  * RETURN     : int32_t type of status
2811  *              NO_ERROR  -- success
2812  *              none-zero failure code
2813  *==========================================================================*/
setContinuousISO(const char * isoValue)2814 int32_t  QCameraParameters::setContinuousISO(const char *isoValue)
2815 {
2816     char iso[PROPERTY_VALUE_MAX];
2817     int32_t continous_iso = 0;
2818 
2819     // Check if continuous ISO is set through setproperty
2820     property_get("persist.camera.continuous.iso", iso, "");
2821     if (strlen(iso) > 0) {
2822         continous_iso = atoi(iso);
2823     } else {
2824         continous_iso = atoi(isoValue);
2825     }
2826 
2827     if ((continous_iso >= 0) &&
2828             (continous_iso <= m_pCapability->sensitivity_range.max_sensitivity)) {
2829         CDBG_HIGH("%s: Setting continuous ISO value %d", __func__, continous_iso);
2830         updateParamEntry(KEY_QC_CONTINUOUS_ISO, isoValue);
2831         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, continous_iso)) {
2832             return BAD_VALUE;
2833         }
2834         return NO_ERROR;
2835     }
2836     ALOGE("Invalid iso value: %d", continous_iso);
2837     return BAD_VALUE;
2838 }
2839 
2840 /*===========================================================================
2841  * FUNCTION   : setExposureTime
2842  *
2843  * DESCRIPTION: set exposure time from user setting
2844  *
2845  * PARAMETERS :
2846  *   @params  : user setting parameters
2847  *
2848  * RETURN     : int32_t type of status
2849  *              NO_ERROR  -- success
2850  *              none-zero failure code
2851  *==========================================================================*/
setExposureTime(const QCameraParameters & params)2852 int32_t  QCameraParameters::setExposureTime(const QCameraParameters& params)
2853 {
2854     const char *str = params.get(KEY_QC_EXPOSURE_TIME);
2855     const char *prev_str = get(KEY_QC_EXPOSURE_TIME);
2856     if (str != NULL) {
2857         if (prev_str == NULL ||
2858                 strcmp(str, prev_str) != 0) {
2859             return setExposureTime(str);
2860         }
2861     }
2862 
2863     return NO_ERROR;
2864 }
2865 
2866 /*===========================================================================
2867  * FUNCTION   : setVideoRotation
2868  *
2869  * DESCRIPTION: set rotation value from user setting
2870  *
2871  * PARAMETERS :
2872  *   @params  : user setting parameters
2873  *
2874  * RETURN     : int32_t type of status
2875  *              NO_ERROR  -- success
2876  *              none-zero failure code
2877  *==========================================================================*/
setVideoRotation(const QCameraParameters & params)2878 int32_t QCameraParameters::setVideoRotation(const QCameraParameters& params)
2879 {
2880     const char *str = params.get(KEY_QC_VIDEO_ROTATION);
2881     if(str != NULL) {
2882         int value = lookupAttr(VIDEO_ROTATION_MODES_MAP,
2883                 PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
2884         if (value != NAME_NOT_FOUND) {
2885             updateParamEntry(KEY_QC_VIDEO_ROTATION, str);
2886             ALOGV("setVideoRotation: %s:  %d: ", str, value);
2887         } else {
2888             ALOGE("Invalid rotation value: %d", value);
2889             return BAD_VALUE;
2890         }
2891 
2892     }
2893     return NO_ERROR;
2894 }
2895 
2896 /*===========================================================================
2897  * FUNCTION   : setRotation
2898  *
2899  * DESCRIPTION: set rotation value from user setting
2900  *
2901  * PARAMETERS :
2902  *   @params  : user setting parameters
2903  *
2904  * RETURN     : int32_t type of status
2905  *              NO_ERROR  -- success
2906  *              none-zero failure code
2907  *==========================================================================*/
setRotation(const QCameraParameters & params)2908 int32_t QCameraParameters::setRotation(const QCameraParameters& params)
2909 {
2910     int32_t rotation = params.getInt(KEY_ROTATION);
2911     if (rotation != -1) {
2912         if (rotation == 0 || rotation == 90 ||
2913             rotation == 180 || rotation == 270) {
2914             set(KEY_ROTATION, rotation);
2915 
2916             ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_JPEG_ORIENTATION,
2917                     rotation);
2918             mRotation = rotation;
2919         } else {
2920             ALOGE("Invalid rotation value: %d", rotation);
2921             return BAD_VALUE;
2922         }
2923     }
2924     return NO_ERROR;
2925 }
2926 
2927 /*===========================================================================
2928  * FUNCTION   : setFlash
2929  *
2930  * DESCRIPTION: set flash mode from user setting
2931  *
2932  * PARAMETERS :
2933  *   @params  : user setting parameters
2934  *
2935  * RETURN     : int32_t type of status
2936  *              NO_ERROR  -- success
2937  *              none-zero failure code
2938  *==========================================================================*/
setFlash(const QCameraParameters & params)2939 int32_t QCameraParameters::setFlash(const QCameraParameters& params)
2940 {
2941     const char *str = params.get(KEY_FLASH_MODE);
2942     const char *prev_str = get(KEY_FLASH_MODE);
2943     if (str != NULL) {
2944         if (prev_str == NULL ||
2945             strcmp(str, prev_str) != 0) {
2946             return setFlash(str);
2947         }
2948     }
2949     return NO_ERROR;
2950 }
2951 
2952 /*===========================================================================
2953  * FUNCTION   : setAecLock
2954  *
2955  * DESCRIPTION: set AEC lock value from user setting
2956  *
2957  * PARAMETERS :
2958  *   @params  : user setting parameters
2959  *
2960  * RETURN     : int32_t type of status
2961  *              NO_ERROR  -- success
2962  *              none-zero failure code
2963  *==========================================================================*/
setAecLock(const QCameraParameters & params)2964 int32_t QCameraParameters::setAecLock(const QCameraParameters& params)
2965 {
2966     const char *str = params.get(KEY_AUTO_EXPOSURE_LOCK);
2967     const char *prev_str = get(KEY_AUTO_EXPOSURE_LOCK);
2968     if (str != NULL) {
2969         if (prev_str == NULL ||
2970             strcmp(str, prev_str) != 0) {
2971             return setAecLock(str);
2972         }
2973     }
2974     return NO_ERROR;
2975 }
2976 
2977 /*===========================================================================
2978  * FUNCTION   : setAwbLock
2979  *
2980  * DESCRIPTION: set AWB lock from user setting
2981  *
2982  * PARAMETERS :
2983  *   @params  : user setting parameters
2984  *
2985  * RETURN     : int32_t type of status
2986  *              NO_ERROR  -- success
2987  *              none-zero failure code
2988  *==========================================================================*/
setAwbLock(const QCameraParameters & params)2989 int32_t QCameraParameters::setAwbLock(const QCameraParameters& params)
2990 {
2991     const char *str = params.get(KEY_AUTO_WHITEBALANCE_LOCK);
2992     const char *prev_str = get(KEY_AUTO_WHITEBALANCE_LOCK);
2993     if (str != NULL) {
2994         if (prev_str == NULL ||
2995             strcmp(str, prev_str) != 0) {
2996             return setAwbLock(str);
2997         }
2998     }
2999     return NO_ERROR;
3000 }
3001 
3002 /*===========================================================================
3003  * FUNCTION   : setAutoHDR
3004  *
3005  * DESCRIPTION: Enable/disable auto HDR
3006  *
3007  * PARAMETERS :
3008  *   @params  : user setting parameters
3009  *
3010  * RETURN     : int32_t type of status
3011  *              NO_ERROR  -- success
3012  *              none-zero failure code
3013  *==========================================================================*/
setAutoHDR(const QCameraParameters & params)3014 int32_t QCameraParameters::setAutoHDR(const QCameraParameters& params)
3015 {
3016     const char *str = params.get(KEY_QC_AUTO_HDR_ENABLE);
3017     const char *prev_str = get(KEY_QC_AUTO_HDR_ENABLE);
3018     char prop[PROPERTY_VALUE_MAX];
3019 
3020     memset(prop, 0, sizeof(prop));
3021     property_get("persist.camera.auto.hdr.enable", prop, VALUE_DISABLE);
3022     if (str != NULL) {
3023        if (prev_str == NULL ||
3024            strcmp(str, prev_str) != 0) {
3025            CDBG_HIGH("%s : Auto HDR set to: %s", __func__, str);
3026            return updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, str);
3027        }
3028     } else {
3029        if (prev_str == NULL ||
3030            strcmp(prev_str, prop) != 0 ) {
3031            CDBG_HIGH("%s : Auto HDR set to: %s", __func__, prop);
3032            updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, prop);
3033        }
3034     }
3035 
3036        return NO_ERROR;
3037 }
3038 
3039 /*===========================================================================
3040 * FUNCTION   : isAutoHDREnabled
3041 *
3042 * DESCRIPTION: Query auto HDR status
3043 *
3044 * PARAMETERS : None
3045 *
3046 * RETURN     : bool true/false
3047 *==========================================================================*/
isAutoHDREnabled()3048 bool QCameraParameters::isAutoHDREnabled()
3049 {
3050     const char *str = get(KEY_QC_AUTO_HDR_ENABLE);
3051     if (str != NULL) {
3052         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
3053                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
3054         if (value == NAME_NOT_FOUND) {
3055             ALOGE("%s: Invalid Auto HDR value %s", __func__, str);
3056             return false;
3057         }
3058 
3059         CDBG_HIGH("%s : Auto HDR status is: %d", __func__, value);
3060         return value ? true : false;
3061     }
3062 
3063     CDBG_HIGH("%s : Auto HDR status not set!", __func__);
3064     return false;
3065 }
3066 
3067 /*===========================================================================
3068  * FUNCTION   : setMCEValue
3069  *
3070  * DESCRIPTION: set memory color enhancement value from user setting
3071  *
3072  * PARAMETERS :
3073  *   @params  : user setting parameters
3074  *
3075  * RETURN     : int32_t type of status
3076  *              NO_ERROR  -- success
3077  *              none-zero failure code
3078  *==========================================================================*/
setMCEValue(const QCameraParameters & params)3079 int32_t QCameraParameters::setMCEValue(const QCameraParameters& params)
3080 {
3081     const char *str = params.get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3082     const char *prev_str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3083     if (str != NULL) {
3084         if (prev_str == NULL ||
3085             strcmp(str, prev_str) != 0) {
3086             return setMCEValue(str);
3087         }
3088     }
3089     return NO_ERROR;
3090 }
3091 
3092 /*===========================================================================
3093  * FUNCTION   : setDISValue
3094  *
3095  * DESCRIPTION: enable/disable DIS from user setting
3096  *
3097  * PARAMETERS :
3098  *   @params  : user setting parameters
3099  *
3100  * RETURN     : int32_t type of status
3101  *              NO_ERROR  -- success
3102  *              none-zero failure code
3103  *==========================================================================*/
setDISValue(const QCameraParameters & params)3104 int32_t QCameraParameters::setDISValue(const QCameraParameters& params)
3105 {
3106     const char *str = params.get(KEY_QC_DIS);
3107     const char *prev_str = get(KEY_QC_DIS);
3108     if (str != NULL) {
3109         if (prev_str == NULL ||
3110             strcmp(str, prev_str) != 0) {
3111             return setDISValue(str);
3112         }
3113     }
3114     return NO_ERROR;
3115 }
3116 
3117 /*===========================================================================
3118  * FUNCTION   : setLensShadeValue
3119  *
3120  * DESCRIPTION: set lens shade value from user setting
3121  *
3122  * PARAMETERS :
3123  *   @params  : user setting parameters
3124  *
3125  * RETURN     : int32_t type of status
3126  *              NO_ERROR  -- success
3127  *              none-zero failure code
3128  *==========================================================================*/
setLensShadeValue(const QCameraParameters & params)3129 int32_t QCameraParameters::setLensShadeValue(const QCameraParameters& params)
3130 {
3131     const char *str = params.get(KEY_QC_LENSSHADE);
3132     const char *prev_str = get(KEY_QC_LENSSHADE);
3133     if (str != NULL) {
3134         if (prev_str == NULL ||
3135             strcmp(str, prev_str) != 0) {
3136             return setLensShadeValue(str);
3137         }
3138     }
3139     return NO_ERROR;
3140 }
3141 
3142 /*===========================================================================
3143  * FUNCTION   : setFocusAreas
3144  *
3145  * DESCRIPTION: set focus areas from user setting
3146  *
3147  * PARAMETERS :
3148  *   @params  : user setting parameters
3149  *
3150  * RETURN     : int32_t type of status
3151  *              NO_ERROR  -- success
3152  *              none-zero failure code
3153  *==========================================================================*/
setFocusAreas(const QCameraParameters & params)3154 int32_t QCameraParameters::setFocusAreas(const QCameraParameters& params)
3155 {
3156     const char *str = params.get(KEY_FOCUS_AREAS);
3157     if (str != NULL) {
3158         int max_num_af_areas = getInt(KEY_MAX_NUM_FOCUS_AREAS);
3159         if(max_num_af_areas == 0) {
3160             ALOGE("%s: max num of AF area is 0, cannot set focus areas", __func__);
3161             return BAD_VALUE;
3162         }
3163 
3164         const char *prev_str = get(KEY_FOCUS_AREAS);
3165         if (prev_str == NULL ||
3166             strcmp(str, prev_str) != 0) {
3167             return setFocusAreas(str);
3168         }
3169     }
3170     return NO_ERROR;
3171 }
3172 
3173 /*===========================================================================
3174  * FUNCTION   : setMeteringAreas
3175  *
3176  * DESCRIPTION: set metering areas from user setting
3177  *
3178  * PARAMETERS :
3179  *   @params  : user setting parameters
3180  *
3181  * RETURN     : int32_t type of status
3182  *              NO_ERROR  -- success
3183  *              none-zero failure code
3184  *==========================================================================*/
setMeteringAreas(const QCameraParameters & params)3185 int32_t QCameraParameters::setMeteringAreas(const QCameraParameters& params)
3186 {
3187     const char *str = params.get(KEY_METERING_AREAS);
3188     if (str != NULL) {
3189         int max_num_mtr_areas = getInt(KEY_MAX_NUM_METERING_AREAS);
3190         if(max_num_mtr_areas == 0) {
3191             ALOGE("%s: max num of metering areas is 0, cannot set focus areas", __func__);
3192             return BAD_VALUE;
3193         }
3194 
3195         const char *prev_str = get(KEY_METERING_AREAS);
3196         if (prev_str == NULL ||
3197             strcmp(str, prev_str) != 0) {
3198             return setMeteringAreas(str);
3199         }
3200     }
3201     return NO_ERROR;
3202 }
3203 
3204 /*===========================================================================
3205  * FUNCTION   : setSceneMode
3206  *
3207  * DESCRIPTION: set scenen mode from user setting
3208  *
3209  * PARAMETERS :
3210  *   @params  : user setting parameters
3211  *
3212  * RETURN     : int32_t type of status
3213  *              NO_ERROR  -- success
3214  *              none-zero failure code
3215  *==========================================================================*/
setSceneMode(const QCameraParameters & params)3216 int32_t QCameraParameters::setSceneMode(const QCameraParameters& params)
3217 {
3218     const char *str = params.get(KEY_SCENE_MODE);
3219     const char *prev_str = get(KEY_SCENE_MODE);
3220     CDBG_HIGH("%s: str - %s, prev_str - %s",__func__, str, prev_str);
3221 
3222     if (str != NULL) {
3223         if (prev_str == NULL ||
3224             strcmp(str, prev_str) != 0) {
3225 
3226             if(strcmp(str, SCENE_MODE_AUTO) == 0) {
3227                 m_bSceneTransitionAuto = true;
3228             }
3229             if (strcmp(str, SCENE_MODE_HDR) == 0) {
3230 
3231                 // If HDR is set from client  and the feature is not enabled in the backend, ignore it.
3232                 if (m_bHDRModeSensor) {
3233                     m_bSensorHDREnabled = true;
3234                     CDBG_HIGH("%s: Sensor HDR mode Enabled",__func__);
3235                 } else {
3236                     m_bHDREnabled = true;
3237                     CDBG_HIGH("%s: S/W HDR Enabled",__func__);
3238                 }
3239             } else {
3240                 m_bHDREnabled = false;
3241                 if (m_bSensorHDREnabled) {
3242                     m_bSensorHDREnabled = false;
3243                     m_bNeedRestart = true;
3244                     setSensorSnapshotHDR("off");
3245                 }
3246             }
3247 
3248             if (m_bSensorHDREnabled) {
3249                 setSensorSnapshotHDR("on");
3250                 m_bNeedRestart = true;
3251             } else if ((m_bHDREnabled) ||
3252                 ((prev_str != NULL) && (strcmp(prev_str, SCENE_MODE_HDR) == 0))) {
3253                 CDBG_HIGH("%s: scene mode changed between HDR and non-HDR, need restart", __func__);
3254 
3255                 m_bNeedRestart = true;
3256             }
3257 
3258             return setSceneMode(str);
3259         }
3260     }
3261     return NO_ERROR;
3262 }
3263 
3264 /*===========================================================================
3265  * FUNCTION   : setSelectableZoneAf
3266  *
3267  * DESCRIPTION: set selectable zone auto focus value from user setting
3268  *
3269  * PARAMETERS :
3270  *   @params  : user setting parameters
3271  *
3272  * RETURN     : int32_t type of status
3273  *              NO_ERROR  -- success
3274  *              none-zero failure code
3275  *==========================================================================*/
setSelectableZoneAf(const QCameraParameters & params)3276 int32_t QCameraParameters::setSelectableZoneAf(const QCameraParameters& params)
3277 {
3278     const char *str = params.get(KEY_QC_SELECTABLE_ZONE_AF);
3279     const char *prev_str = get(KEY_QC_SELECTABLE_ZONE_AF);
3280     if (str != NULL) {
3281         if (prev_str == NULL ||
3282             strcmp(str, prev_str) != 0) {
3283             return setSelectableZoneAf(str);
3284         }
3285     }
3286     return NO_ERROR;
3287 }
3288 
3289 /*===========================================================================
3290  * FUNCTION   : setAEBracket
3291  *
3292  * DESCRIPTION: set AE bracket from user setting
3293  *
3294  * PARAMETERS :
3295  *   @params  : user setting parameters
3296  *
3297  * RETURN     : int32_t type of status
3298  *              NO_ERROR  -- success
3299  *              none-zero failure code
3300  *==========================================================================*/
setAEBracket(const QCameraParameters & params)3301 int32_t QCameraParameters::setAEBracket(const QCameraParameters& params)
3302 {
3303     if (isHDREnabled()) {
3304         CDBG_HIGH("%s: scene mode is HDR, overwrite AE bracket setting to off", __func__);
3305         return setAEBracket(AE_BRACKET_OFF);
3306     }
3307 
3308     const char *expStr = params.get(KEY_QC_CAPTURE_BURST_EXPOSURE);
3309     if (NULL != expStr && strlen(expStr) > 0) {
3310         set(KEY_QC_CAPTURE_BURST_EXPOSURE, expStr);
3311     } else {
3312         char prop[PROPERTY_VALUE_MAX];
3313         memset(prop, 0, sizeof(prop));
3314         property_get("persist.capture.burst.exposures", prop, "");
3315         if (strlen(prop) > 0) {
3316             set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
3317         } else {
3318             remove(KEY_QC_CAPTURE_BURST_EXPOSURE);
3319         }
3320     }
3321 
3322     const char *str = params.get(KEY_QC_AE_BRACKET_HDR);
3323     const char *prev_str = get(KEY_QC_AE_BRACKET_HDR);
3324     if (str != NULL) {
3325         if (prev_str == NULL ||
3326             strcmp(str, prev_str) != 0) {
3327             return setAEBracket(str);
3328         }
3329     }
3330     return NO_ERROR;
3331 }
3332 
3333 /*===========================================================================
3334  * FUNCTION   : setAFBracket
3335  *
3336  * DESCRIPTION: set AF bracket from user setting
3337  *
3338  * PARAMETERS :
3339  *   @params  : user setting parameters
3340  *
3341  * RETURN     : int32_t type of status
3342  *              NO_ERROR  -- success
3343  *              none-zero failure code
3344  *==========================================================================*/
setAFBracket(const QCameraParameters & params)3345 int32_t QCameraParameters::setAFBracket(const QCameraParameters& params)
3346 {
3347     if ((m_pCapability->qcom_supported_feature_mask &
3348             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3349         CDBG_HIGH("%s: AF Bracketing is not supported",__func__);
3350         return NO_ERROR;
3351     }
3352     const char *str = params.get(KEY_QC_AF_BRACKET);
3353     const char *prev_str = get(KEY_QC_AF_BRACKET);
3354     CDBG_HIGH("%s: str =%s & prev_str =%s",__func__, str, prev_str);
3355     if (str != NULL) {
3356         if (prev_str == NULL ||
3357             strcmp(str, prev_str) != 0) {
3358             m_bNeedRestart = true;
3359             return setAFBracket(str);
3360         }
3361     }
3362     return NO_ERROR;
3363 }
3364 
3365 /*===========================================================================
3366  * FUNCTION   : setReFocus
3367  *
3368  * DESCRIPTION: set refocus from user setting
3369  *
3370  * PARAMETERS :
3371  *   @params  : user setting parameters
3372  *
3373  * RETURN     : int32_t type of status
3374  *              NO_ERROR  -- success
3375  *              none-zero failure code
3376  *==========================================================================*/
setReFocus(const QCameraParameters & params)3377 int32_t QCameraParameters::setReFocus(const QCameraParameters& params)
3378 {
3379     if ((m_pCapability->qcom_supported_feature_mask &
3380             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3381         ALOGD("%s: AF Bracketing is not supported",__func__);
3382         return NO_ERROR;
3383     }
3384     const char *str = params.get(KEY_QC_RE_FOCUS);
3385     const char *prev_str = get(KEY_QC_RE_FOCUS);
3386     CDBG_HIGH("%s: str =%s & prev_str =%s",__func__, str, prev_str);
3387     if (str != NULL) {
3388         if (prev_str == NULL ||
3389             strcmp(str, prev_str) != 0) {
3390             m_bNeedRestart = true;
3391             return setReFocus(str);
3392         }
3393     }
3394     return NO_ERROR;
3395 }
3396 
3397 /*===========================================================================
3398  * FUNCTION   : setChromaFlash
3399  *
3400  * DESCRIPTION: set chroma flash from user setting
3401  *
3402  * PARAMETERS :
3403  *   @params  : user setting parameters
3404  *
3405  * RETURN     : int32_t type of status
3406  *              NO_ERROR  -- success
3407  *              none-zero failure code
3408  *==========================================================================*/
setChromaFlash(const QCameraParameters & params)3409 int32_t QCameraParameters::setChromaFlash(const QCameraParameters& params)
3410 {
3411     if ((m_pCapability->qcom_supported_feature_mask &
3412         CAM_QCOM_FEATURE_CHROMA_FLASH) == 0) {
3413         CDBG_HIGH("%s: Chroma Flash is not supported",__func__);
3414         return NO_ERROR;
3415     }
3416     const char *str = params.get(KEY_QC_CHROMA_FLASH);
3417     const char *prev_str = get(KEY_QC_CHROMA_FLASH);
3418     CDBG_HIGH("%s: str =%s & prev_str =%s",__func__, str, prev_str);
3419     if (str != NULL) {
3420         if (prev_str == NULL ||
3421             strcmp(str, prev_str) != 0) {
3422             m_bNeedRestart = true;
3423             return setChromaFlash(str);
3424         }
3425     }
3426     return NO_ERROR;
3427 }
3428 
3429 /*===========================================================================
3430  * FUNCTION   : setOptiZoom
3431  *
3432  * DESCRIPTION: set opti zoom from user setting
3433  *
3434  * PARAMETERS :
3435  *   @params  : user setting parameters
3436  *
3437  * RETURN     : int32_t type of status
3438  *              NO_ERROR  -- success
3439  *              none-zero failure code
3440  *==========================================================================*/
setOptiZoom(const QCameraParameters & params)3441 int32_t QCameraParameters::setOptiZoom(const QCameraParameters& params)
3442 {
3443     if ((m_pCapability->qcom_supported_feature_mask &
3444         CAM_QCOM_FEATURE_OPTIZOOM) == 0){
3445         CDBG_HIGH("%s: Opti Zoom is not supported",__func__);
3446         return NO_ERROR;
3447     }
3448     const char *str = params.get(KEY_QC_OPTI_ZOOM);
3449     const char *prev_str = get(KEY_QC_OPTI_ZOOM);
3450     CDBG_HIGH("%s: str =%s & prev_str =%s",__func__, str, prev_str);
3451     if (str != NULL) {
3452         if (prev_str == NULL ||
3453             strcmp(str, prev_str) != 0) {
3454             m_bNeedRestart = true;
3455             return setOptiZoom(str);
3456         }
3457     }
3458     return NO_ERROR;
3459 }
3460 
3461 /*===========================================================================
3462  * FUNCTION   : setTruePortrait
3463  *
3464  * DESCRIPTION: set true portrait from user setting
3465  *
3466  * PARAMETERS :
3467  *   @params  : user setting parameters
3468  *
3469  * RETURN     : int32_t type of status
3470  *              NO_ERROR  -- success
3471  *              none-zero failure code
3472  *==========================================================================*/
setTruePortrait(const QCameraParameters & params)3473 int32_t QCameraParameters::setTruePortrait(const QCameraParameters& params)
3474 {
3475     if ((m_pCapability->qcom_supported_feature_mask &
3476             CAM_QCOM_FEATURE_TRUEPORTRAIT) == 0) {
3477         CDBG("%s: True Portrait is not supported",__func__);
3478         return NO_ERROR;
3479     }
3480     const char *str = params.get(KEY_QC_TRUE_PORTRAIT);
3481     const char *prev_str = get(KEY_QC_TRUE_PORTRAIT);
3482     CDBG_HIGH("%s: str =%s & prev_str =%s", __func__, str, prev_str);
3483     if (str != NULL) {
3484         if (prev_str == NULL ||
3485             strcmp(str, prev_str) != 0) {
3486             return setTruePortrait(str);
3487         }
3488     }
3489     return NO_ERROR;
3490 }
3491 
3492 /*===========================================================================
3493  * FUNCTION   : setHDRMode
3494  *
3495  * DESCRIPTION: set HDR mode from user setting
3496  *
3497  * PARAMETERS :
3498  *   @params  : user setting parameters
3499  *
3500  * RETURN     : int32_t type of status
3501  *              NO_ERROR  -- success
3502  *              none-zero failure code
3503  *==========================================================================*/
setHDRMode(const QCameraParameters & params)3504 int32_t QCameraParameters::setHDRMode(const QCameraParameters& params)
3505 {
3506     const char *str = params.get(KEY_QC_HDR_MODE);
3507     const char *prev_str = get(KEY_QC_HDR_MODE);
3508     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
3509           (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
3510 
3511     CDBG_HIGH("%s: str =%s & prev_str =%s",__func__, str, prev_str);
3512     if (str != NULL) {
3513         if ((CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) &&
3514                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR)))) {
3515             CDBG_HIGH("%s: Only sensor HDR is supported",__func__);
3516             return NO_ERROR;
3517         } else if  ((CAM_QCOM_FEATURE_HDR == supported_hdr_modes) &&
3518                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_MULTI_FRAME)))) {
3519             CDBG_HIGH("%s: Only multi frame HDR is supported",__func__);
3520             return NO_ERROR;
3521         } else if (!supported_hdr_modes) {
3522             CDBG_HIGH("%s: HDR is not supported",__func__);
3523             return NO_ERROR;
3524         }
3525         if (prev_str == NULL ||
3526                 strcmp(str, prev_str) != 0) {
3527             return setHDRMode(str);
3528         }
3529     }
3530 
3531     return NO_ERROR;
3532 }
3533 
3534 /*===========================================================================
3535  * FUNCTION   : setHDRNeed1x
3536  *
3537  * DESCRIPTION: set HDR need 1x from user setting
3538  *
3539  * PARAMETERS :
3540  *   @params  : user setting parameters
3541  *
3542  * RETURN     : int32_t type of status
3543  *              NO_ERROR  -- success
3544  *              none-zero failure code
3545  *==========================================================================*/
setHDRNeed1x(const QCameraParameters & params)3546 int32_t QCameraParameters::setHDRNeed1x(const QCameraParameters& params)
3547 {
3548     const char *str = params.get(KEY_QC_HDR_NEED_1X);
3549     const char *prev_str = get(KEY_QC_HDR_NEED_1X);
3550 
3551     CDBG_HIGH("%s: str =%s & prev_str =%s", __func__, str, prev_str);
3552     if (str != NULL) {
3553         if (m_bHDRModeSensor) {
3554             CDBG_HIGH("%s: Only multi frame HDR supports 1x frame",__func__);
3555             return NO_ERROR;
3556         }
3557         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
3558             return setHDRNeed1x(str);
3559         }
3560     }
3561     return NO_ERROR;
3562 }
3563 
3564 /*===========================================================================
3565  * FUNCTION   : setSeeMore
3566  *
3567  * DESCRIPTION: set see more (llvd) from user setting
3568  *
3569  * PARAMETERS :
3570  *   @params  : user setting parameters
3571  *
3572  * RETURN     : int32_t type of status
3573  *              NO_ERROR  -- success
3574  *              none-zero failure code
3575  *==========================================================================*/
setSeeMore(const QCameraParameters & params)3576 int32_t QCameraParameters::setSeeMore(const QCameraParameters& params)
3577 {
3578     if ((m_pCapability->qcom_supported_feature_mask &
3579             CAM_QCOM_FEATURE_LLVD) == 0) {
3580         CDBG("%s: See more is not supported", __func__);
3581         return NO_ERROR;
3582     }
3583     const char *str = params.get(KEY_QC_SEE_MORE);
3584     const char *prev_str = get(KEY_QC_SEE_MORE);
3585     CDBG_HIGH("%s: str =%s & prev_str =%s", __func__, str, prev_str);
3586     if (str != NULL) {
3587         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3588             m_bNeedRestart = true;
3589             return setSeeMore(str);
3590         }
3591     }
3592     return NO_ERROR;
3593 }
3594 
3595 /*===========================================================================
3596  * FUNCTION   : setStillMore
3597  *
3598  * DESCRIPTION: set stillmore from user setting
3599  *
3600  * PARAMETERS :
3601  *   @params  : user setting parameters
3602  *
3603  * RETURN     : int32_t type of status
3604  *              NO_ERROR  -- success
3605  *              none-zero failure code
3606  *==========================================================================*/
setStillMore(const QCameraParameters & params)3607 int32_t QCameraParameters::setStillMore(const QCameraParameters& params)
3608 {
3609     if ((m_pCapability->qcom_supported_feature_mask &
3610             CAM_QCOM_FEATURE_STILLMORE) == 0) {
3611         CDBG("%s: Stillmore is not supported",__func__);
3612         return NO_ERROR;
3613     }
3614     const char *str = params.get(KEY_QC_STILL_MORE);
3615     const char *prev_str = get(KEY_QC_STILL_MORE);
3616     CDBG_HIGH("%s: str =%s & prev_str =%s", __func__, str, prev_str);
3617     if (str != NULL) {
3618         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3619             m_bNeedRestart = true;
3620             return setStillMore(str);
3621         }
3622     }
3623     return NO_ERROR;
3624 }
3625 
3626 /*===========================================================================
3627  * FUNCTION   : setRedeyeReduction
3628  *
3629  * DESCRIPTION: set red eye reduction setting from user setting
3630  *
3631  * PARAMETERS :
3632  *   @params  : user setting parameters
3633  *
3634  * RETURN     : int32_t type of status
3635  *              NO_ERROR  -- success
3636  *              none-zero failure code
3637  *==========================================================================*/
setRedeyeReduction(const QCameraParameters & params)3638 int32_t QCameraParameters::setRedeyeReduction(const QCameraParameters& params)
3639 {
3640     const char *str = params.get(KEY_QC_REDEYE_REDUCTION);
3641     const char *prev_str = get(KEY_QC_REDEYE_REDUCTION);
3642     if (str != NULL) {
3643         if (prev_str == NULL ||
3644             strcmp(str, prev_str) != 0) {
3645             return setRedeyeReduction(str);
3646         }
3647     }
3648     return NO_ERROR;
3649 }
3650 
3651 /*===========================================================================
3652  * FUNCTION   : setGpsLocation
3653  *
3654  * DESCRIPTION: set GPS location information from user setting
3655  *
3656  * PARAMETERS :
3657  *   @params  : user setting parameters
3658  *
3659  * RETURN     : int32_t type of status
3660  *              NO_ERROR  -- success
3661  *              none-zero failure code
3662  *==========================================================================*/
setGpsLocation(const QCameraParameters & params)3663 int32_t QCameraParameters::setGpsLocation(const QCameraParameters& params)
3664 {
3665     const char *method = params.get(KEY_GPS_PROCESSING_METHOD);
3666     if (method) {
3667         set(KEY_GPS_PROCESSING_METHOD, method);
3668     }else {
3669         remove(KEY_GPS_PROCESSING_METHOD);
3670     }
3671 
3672     const char *latitude = params.get(KEY_GPS_LATITUDE);
3673     if (latitude) {
3674         set(KEY_GPS_LATITUDE, latitude);
3675     }else {
3676         remove(KEY_GPS_LATITUDE);
3677     }
3678 
3679     const char *latitudeRef = params.get(KEY_QC_GPS_LATITUDE_REF);
3680     if (latitudeRef) {
3681         set(KEY_QC_GPS_LATITUDE_REF, latitudeRef);
3682     }else {
3683         remove(KEY_QC_GPS_LATITUDE_REF);
3684     }
3685 
3686     const char *longitude = params.get(KEY_GPS_LONGITUDE);
3687     if (longitude) {
3688         set(KEY_GPS_LONGITUDE, longitude);
3689     }else {
3690         remove(KEY_GPS_LONGITUDE);
3691     }
3692 
3693     const char *longitudeRef = params.get(KEY_QC_GPS_LONGITUDE_REF);
3694     if (longitudeRef) {
3695         set(KEY_QC_GPS_LONGITUDE_REF, longitudeRef);
3696     }else {
3697         remove(KEY_QC_GPS_LONGITUDE_REF);
3698     }
3699 
3700     const char *altitudeRef = params.get(KEY_QC_GPS_ALTITUDE_REF);
3701     if (altitudeRef) {
3702         set(KEY_QC_GPS_ALTITUDE_REF, altitudeRef);
3703     }else {
3704         remove(KEY_QC_GPS_ALTITUDE_REF);
3705     }
3706 
3707     const char *altitude = params.get(KEY_GPS_ALTITUDE);
3708     if (altitude) {
3709         set(KEY_GPS_ALTITUDE, altitude);
3710     }else {
3711         remove(KEY_GPS_ALTITUDE);
3712     }
3713 
3714     const char *status = params.get(KEY_QC_GPS_STATUS);
3715     if (status) {
3716         set(KEY_QC_GPS_STATUS, status);
3717     } else {
3718         remove(KEY_QC_GPS_STATUS);
3719     }
3720 
3721     const char *timestamp = params.get(KEY_GPS_TIMESTAMP);
3722     if (timestamp) {
3723         set(KEY_GPS_TIMESTAMP, timestamp);
3724     }else {
3725         remove(KEY_GPS_TIMESTAMP);
3726     }
3727     return NO_ERROR;
3728 }
3729 
3730 /*===========================================================================
3731  * FUNCTION   : setNumOfSnapshot
3732  *
3733  * DESCRIPTION: set number of snapshot per shutter from user setting
3734  *
3735  * PARAMETERS : none
3736  *
3737  * RETURN     : int32_t type of status
3738  *              NO_ERROR  -- success
3739  *              none-zero failure code
3740  *==========================================================================*/
setNumOfSnapshot()3741 int32_t QCameraParameters::setNumOfSnapshot()
3742 {
3743     int nBurstNum = getBurstNum();
3744     int nExpnum = 0;
3745 
3746     const char *bracket_str = get(KEY_QC_AE_BRACKET_HDR);
3747     if (bracket_str != NULL && strlen(bracket_str) > 0) {
3748         int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
3749                 bracket_str);
3750         switch (value) {
3751         case CAM_EXP_BRACKETING_ON:
3752             {
3753                 nExpnum = 0;
3754                 const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
3755                 if ((str_val != NULL) && (strlen(str_val) > 0)) {
3756                     char prop[PROPERTY_VALUE_MAX];
3757                     memset(prop, 0, sizeof(prop));
3758                     strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
3759                     char *saveptr = NULL;
3760                     char *token = strtok_r(prop, ",", &saveptr);
3761                     while (token != NULL) {
3762                         token = strtok_r(NULL, ",", &saveptr);
3763                         nExpnum++;
3764                     }
3765                 }
3766                 if (nExpnum == 0) {
3767                     nExpnum = 1;
3768                 }
3769             }
3770             break;
3771         default:
3772             nExpnum = 1 + getNumOfExtraHDROutBufsIfNeeded();
3773             break;
3774         }
3775     }
3776 
3777     if (isUbiRefocus()) {
3778         nBurstNum = m_pCapability->refocus_af_bracketing_need.output_count + 1;
3779     }
3780 
3781     CDBG_HIGH("%s: nBurstNum = %d, nExpnum = %d", __func__, nBurstNum, nExpnum);
3782     set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, nBurstNum * nExpnum);
3783     return NO_ERROR;
3784 }
3785 
3786 /*===========================================================================
3787  * FUNCTION   : setRecordingHint
3788  *
3789  * DESCRIPTION: set recording hint value from user setting
3790  *
3791  * PARAMETERS :
3792  *   @params  : user setting parameters
3793  *
3794  * RETURN     : int32_t type of status
3795  *              NO_ERROR  -- success
3796  *              none-zero failure code
3797  *==========================================================================*/
setRecordingHint(const QCameraParameters & params)3798 int32_t QCameraParameters::setRecordingHint(const QCameraParameters& params)
3799 {
3800     const char * str = params.get(KEY_RECORDING_HINT);
3801     const char *prev_str = get(KEY_RECORDING_HINT);
3802     if (str != NULL) {
3803         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3804             int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
3805                     str);
3806             if(value != NAME_NOT_FOUND){
3807                 updateParamEntry(KEY_RECORDING_HINT, str);
3808                 setRecordingHintValue(value);
3809                 if (getFaceDetectionOption() == true) {
3810                     setFaceDetection(value > 0 ? false : true, false);
3811                 }
3812                 if (m_bDISEnabled) {
3813                     CDBG_HIGH("%s: %d: Setting DIS value again", __func__, __LINE__);
3814                     setDISValue(VALUE_ENABLE);
3815                 }
3816                 return NO_ERROR;
3817             } else {
3818                 ALOGE("Invalid recording hint value: %s", str);
3819                 return BAD_VALUE;
3820             }
3821         }
3822     }
3823     return NO_ERROR;
3824 }
3825 
3826 /*===========================================================================
3827  * FUNCTION   : setNoDisplayMode
3828  *
3829  * DESCRIPTION: set no display mode from user setting
3830  *
3831  * PARAMETERS :
3832  *   @params  : user setting parameters
3833  *
3834  * RETURN     : int32_t type of status
3835  *              NO_ERROR  -- success
3836  *              none-zero failure code
3837  *==========================================================================*/
setNoDisplayMode(const QCameraParameters & params)3838 int32_t QCameraParameters::setNoDisplayMode(const QCameraParameters& params)
3839 {
3840     const char *str_val  = params.get(KEY_QC_NO_DISPLAY_MODE);
3841     const char *prev_str = get(KEY_QC_NO_DISPLAY_MODE);
3842     char prop[PROPERTY_VALUE_MAX];
3843 
3844     if(str_val && strlen(str_val) > 0) {
3845         if (prev_str == NULL || strcmp(str_val, prev_str) != 0) {
3846             m_bNoDisplayMode = atoi(str_val);
3847             set(KEY_QC_NO_DISPLAY_MODE, str_val);
3848             m_bNeedRestart = true;
3849         }
3850     } else {
3851         memset(prop, 0, sizeof(prop));
3852         property_get("persist.camera.no-display", prop, "0");
3853         m_bNoDisplayMode = atoi(prop);
3854     }
3855     CDBG_HIGH("Param m_bNoDisplayMode = %d", m_bNoDisplayMode);
3856     return NO_ERROR;
3857 }
3858 
3859 /*===========================================================================
3860  * FUNCTION   : setZslMode
3861  *
3862  * DESCRIPTION: set ZSL mode from user setting
3863  *
3864  * PARAMETERS :
3865  *   @params  : user setting parameters
3866  *
3867  * RETURN     : int32_t type of status
3868  *              NO_ERROR  -- success
3869  *              none-zero failure code
3870  *==========================================================================*/
setZslMode(const QCameraParameters & params)3871 int32_t QCameraParameters::setZslMode(const QCameraParameters& params)
3872 {
3873     const char *str_val  = params.get(KEY_QC_ZSL);
3874     const char *prev_val  = get(KEY_QC_ZSL);
3875     int32_t rc = NO_ERROR;
3876 
3877     if(m_bForceZslMode && !m_bZslMode) {
3878         // Force ZSL mode to ON
3879         set(KEY_QC_ZSL, VALUE_ON);
3880         m_bZslMode_new = true;
3881         m_bZslMode = true;
3882         m_bNeedRestart = true;
3883         int32_t value = m_bForceZslMode;
3884         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
3885             rc = BAD_VALUE;
3886         }
3887     } else if (str_val != NULL) {
3888         if (prev_val == NULL || strcmp(str_val, prev_val) != 0) {
3889             int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
3890                     str_val);
3891             if (value != NAME_NOT_FOUND) {
3892                 set(KEY_QC_ZSL, str_val);
3893                 m_bZslMode_new = (value > 0)? true : false;
3894 
3895                 // ZSL mode changed, need restart preview
3896                 m_bNeedRestart = true;
3897 
3898                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
3899                     rc = BAD_VALUE;
3900                 }
3901             } else {
3902                 ALOGE("Invalid ZSL mode value: %s", str_val);
3903                 rc = BAD_VALUE;
3904             }
3905         }
3906     }
3907     ALOGI("%s: enabled: %d", __func__, m_bZslMode_new);
3908     return rc;
3909 }
3910 
3911 /*===========================================================================
3912  * FUNCTION   : setWaveletDenoise
3913  *
3914  * DESCRIPTION: set wavelet denoise value from user setting
3915  *
3916  * PARAMETERS :
3917  *   @params  : user setting parameters
3918  *
3919  * RETURN     : int32_t type of status
3920  *              NO_ERROR  -- success
3921  *              none-zero failure code
3922  *==========================================================================*/
setWaveletDenoise(const QCameraParameters & params)3923 int32_t QCameraParameters::setWaveletDenoise(const QCameraParameters& params)
3924 {
3925     const char *str_pf = params.getPictureFormat();
3926     int32_t pictureFormat = lookupAttr(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP),
3927             str_pf);
3928     if (pictureFormat != NAME_NOT_FOUND) {
3929         if (CAM_FORMAT_YUV_422_NV16 == pictureFormat) {
3930             ALOGE("NV16 format isn't supported in denoise lib!");
3931             return setWaveletDenoise(DENOISE_OFF);
3932         }
3933     }
3934     const char *str = params.get(KEY_QC_DENOISE);
3935     const char *prev_str = get(KEY_QC_DENOISE);
3936     if (str != NULL) {
3937         if (prev_str == NULL ||
3938             strcmp(str, prev_str) != 0) {
3939             return setWaveletDenoise(str);
3940         }
3941     }
3942     return NO_ERROR;
3943 }
3944 
3945 /*===========================================================================
3946  * FUNCTION   : setTemporalDenoise
3947  *
3948  * DESCRIPTION: set temporal denoise value from properties
3949  *
3950  * PARAMETERS : none
3951  *
3952  * RETURN     : int32_t type of status
3953  *              NO_ERROR  -- success
3954  *              none-zero failure code
3955  *==========================================================================*/
setTemporalDenoise(const QCameraParameters & params)3956 int32_t QCameraParameters::setTemporalDenoise(const QCameraParameters& params)
3957 {
3958     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_CPP_TNR) == 0) {
3959         CDBG_HIGH("%s: TNR is not supported",__func__);
3960         return NO_ERROR;
3961     }
3962     const char *str = params.get(KEY_QC_TNR_MODE);
3963     const char *prev_str = get(KEY_QC_TNR_MODE);
3964     const char *video_str = params.get(KEY_QC_VIDEO_TNR_MODE);
3965     const char *video_prev_str = get(KEY_QC_VIDEO_TNR_MODE);
3966 
3967     if (m_bRecordingHint_new == true) {
3968         if (video_str) {
3969             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
3970                 if (!strcmp(video_str, VALUE_ON)) {
3971                     m_bTNRVideoOn = true;
3972                     m_bTNRPreviewOn = true;
3973                 } else {
3974                     m_bTNRVideoOn = false;
3975                     m_bTNRPreviewOn = false;
3976                 }
3977                 updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_str);
3978             } else {
3979                 return NO_ERROR;
3980             }
3981         } else {
3982             char video_value[PROPERTY_VALUE_MAX];
3983             memset(video_value, 0, sizeof(video_value));
3984             property_get("persist.camera.tnr.video", video_value, VALUE_OFF);
3985             if (!strcmp(video_value, VALUE_ON)) {
3986                 m_bTNRVideoOn = true;
3987             } else {
3988                 m_bTNRVideoOn = false;
3989             }
3990             updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_value);
3991 
3992             char preview_value[PROPERTY_VALUE_MAX];
3993             memset(preview_value, 0, sizeof(preview_value));
3994             property_get("persist.camera.tnr.preview", preview_value, video_value);
3995             if (!strcmp(preview_value, VALUE_ON)) {
3996                 m_bTNRPreviewOn = true;
3997             } else {
3998                 m_bTNRPreviewOn = false;
3999             }
4000             updateParamEntry(KEY_QC_TNR_MODE, preview_value);
4001         }
4002 
4003         cam_denoise_param_t temp;
4004         memset(&temp, 0, sizeof(temp));
4005         if (m_bTNRVideoOn || m_bTNRPreviewOn) {
4006             temp.denoise_enable = 1;
4007             temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_TEMPORAL_DENOISE);
4008 
4009             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
4010                     CDS_MODE_OFF);
4011 
4012             if (cds_mode != NAME_NOT_FOUND) {
4013                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, CDS_MODE_OFF);
4014                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
4015                     ALOGE("%s:Failed CDS MODE to update table", __func__);
4016                     return BAD_VALUE;
4017                 }
4018                 CDBG("%s: CDS in video mode is set to = %s when TNR is enabled",
4019                         __func__, CDS_MODE_OFF);
4020                 mCds_mode = cds_mode;
4021             } else {
4022                 ALOGE("%s: Invalid argument for video CDS MODE %d", __func__, cds_mode);
4023             }
4024         }
4025         CDBG("%s: TNR enable in video mode = %d, plates = %d", __func__,
4026                 temp.denoise_enable, temp.process_plates);
4027         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TEMPORAL_DENOISE, temp)) {
4028             return BAD_VALUE;
4029         }
4030     } else {
4031         if (str) {
4032             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
4033                 if (!strcmp(str, VALUE_ON)) {
4034                     m_bTNRPreviewOn = true;
4035                 } else {
4036                     m_bTNRPreviewOn = false;
4037                 }
4038                 updateParamEntry(KEY_QC_TNR_MODE, str);
4039             } else {
4040                 return NO_ERROR;
4041             }
4042         } else {
4043             char value[PROPERTY_VALUE_MAX];
4044             memset(value, 0, sizeof(value));
4045             property_get("persist.camera.tnr.preview", value, VALUE_OFF);
4046             if (!strcmp(value, VALUE_ON)) {
4047                 m_bTNRPreviewOn = true;
4048             } else {
4049                 m_bTNRPreviewOn = false;
4050             }
4051             updateParamEntry(KEY_QC_TNR_MODE, value);
4052         }
4053         cam_denoise_param_t temp;
4054         memset(&temp, 0, sizeof(temp));
4055         if (m_bTNRPreviewOn) {
4056             temp.denoise_enable = 1;
4057             temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_TEMPORAL_DENOISE);
4058 
4059             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
4060                     CDS_MODE_OFF);
4061 
4062             if (cds_mode != NAME_NOT_FOUND) {
4063                 updateParamEntry(KEY_QC_CDS_MODE, CDS_MODE_OFF);
4064                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
4065                     ALOGE("%s:Failed CDS MODE to update table", __func__);
4066                     return BAD_VALUE;
4067                 }
4068                 CDBG("%s: CDS in snapshot mode is set to = %s when TNR is enabled",
4069                         __func__, CDS_MODE_OFF);
4070                 mCds_mode = cds_mode;
4071             } else {
4072                 ALOGE("%s: Invalid argument for snapshot CDS MODE %d", __func__, cds_mode);
4073             }
4074         }
4075         CDBG("%s: TNR enable in snapshot mode = %d, plates = %d", __func__,
4076                 temp.denoise_enable, temp.process_plates);
4077         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TEMPORAL_DENOISE, temp)) {
4078             return BAD_VALUE;
4079         }
4080     }
4081 
4082     return NO_ERROR;
4083 }
4084 
4085 /*===========================================================================
4086  * FUNCTION   : setCameraMode
4087  *
4088  * DESCRIPTION: set camera mode from user setting
4089  *
4090  * PARAMETERS :
4091  *   @params  : user setting parameters
4092  *
4093  * RETURN     : int32_t type of status
4094  *              NO_ERROR  -- success
4095  *              none-zero failure code
4096  *==========================================================================*/
setCameraMode(const QCameraParameters & params)4097 int32_t QCameraParameters::setCameraMode(const QCameraParameters& params)
4098 {
4099     const char *str = params.get(KEY_QC_CAMERA_MODE);
4100     if (str != NULL) {
4101         set(KEY_QC_CAMERA_MODE, str);
4102     } else {
4103         remove(KEY_QC_CAMERA_MODE);
4104     }
4105     return NO_ERROR;
4106 }
4107 
4108 /*===========================================================================
4109  * FUNCTION   : setSceneSelectionMode
4110  *
4111  * DESCRIPTION: set scene selection mode from user setting
4112  *
4113  * PARAMETERS :
4114  *   @params  : user setting parameters
4115  *
4116  * RETURN     : int32_t type of status
4117  *              NO_ERROR  -- success
4118  *              none-zero failure code
4119  *==========================================================================*/
setSceneSelectionMode(const QCameraParameters & params)4120 int32_t QCameraParameters::setSceneSelectionMode(const QCameraParameters& params)
4121 {
4122     const char *str = params.get(KEY_QC_SCENE_SELECTION);
4123     const char *prev_str = get(KEY_QC_SCENE_SELECTION);
4124     if (NULL != str) {
4125         if ((NULL == prev_str) || (strcmp(str, prev_str) != 0)) {
4126             int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4127                     PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
4128             if (value != NAME_NOT_FOUND) {
4129                 ALOGD("%s: Setting selection value %s", __func__, str);
4130                 if (value && m_bZslMode_new) {
4131                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4132                     m_bNeedRestart = true;
4133                     m_bSceneSelection = true;
4134                 } else if (!value) {
4135                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4136                     m_bNeedRestart = true;
4137                     m_bSceneSelection = false;
4138                 } else {
4139                     ALOGE("%s: Trying to enable scene selection in non ZSL mode!!!",
4140                             __func__);
4141                     return BAD_VALUE;
4142                 }
4143             } else {
4144                 ALOGE("%s: Trying to configure invalid scene selection value: %s",
4145                         __func__,
4146                         str);
4147                 return BAD_VALUE;
4148             }
4149         }
4150     }
4151 
4152     return NO_ERROR;
4153 }
4154 
4155 /*===========================================================================
4156  * FUNCTION   : setSelectedScene
4157  *
4158  * DESCRIPTION: select specific scene
4159  *
4160  * PARAMETERS :
4161  *   @scene   : scene mode
4162  *
4163  * RETURN     : int32_t type of status
4164  *              NO_ERROR  -- success
4165  *              none-zero failure code
4166  *==========================================================================*/
setSelectedScene(cam_scene_mode_type scene)4167 int32_t QCameraParameters::setSelectedScene(cam_scene_mode_type scene)
4168 {
4169     Mutex::Autolock l(m_SceneSelectLock);
4170     m_SelectedScene = scene;
4171     return NO_ERROR;
4172 }
4173 
4174 /*===========================================================================
4175  * FUNCTION   : getSelectedScene
4176  *
4177  * DESCRIPTION: get selected scene
4178  *
4179  * PARAMETERS :
4180  *
4181  * RETURN     : currently selected scene
4182  *==========================================================================*/
getSelectedScene()4183 cam_scene_mode_type QCameraParameters::getSelectedScene()
4184 {
4185     Mutex::Autolock l(m_SceneSelectLock);
4186     return m_SelectedScene;
4187 }
4188 
4189 /*==========================================================
4190  * FUNCTION   : setRdiMode
4191  *
4192  * DESCRIPTION: set Rdi mode from user setting
4193  *
4194  * PARAMETERS :
4195  *   @params  : user setting parameters
4196  *
4197  * RETURN     : int32_t type of status
4198  *              NO_ERROR  -- success
4199  *              none-zero failure code
4200  *===========================================================*/
setRdiMode(const QCameraParameters & params)4201 int32_t QCameraParameters::setRdiMode(const QCameraParameters& params)
4202 {
4203     const char *str = params.get(KEY_QC_RDI_MODE);
4204     const char *prev_str = get(KEY_QC_RDI_MODE);
4205     char prop[PROPERTY_VALUE_MAX];
4206     memset(prop, 0, sizeof(prop));
4207 
4208     property_get("persist.camera.rdi.mode", prop, VALUE_DISABLE);
4209     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4210         ALOGD("%s:%d : RDI mode set to %s", __func__, __LINE__, str);
4211         setRdiMode(str);
4212     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4213         ALOGD("%s:%d : RDI mode set to prop: %s", __func__, __LINE__, prop);
4214         setRdiMode(prop);
4215     }
4216     return NO_ERROR;
4217 }
4218 
4219 /*==========================================================
4220  * FUNCTION   : setSecureMode
4221  *
4222  * DESCRIPTION: set secure mode from user setting
4223  *
4224  * PARAMETERS :
4225  *   @params  : user setting parameters
4226  *
4227  * RETURN     : int32_t type of status
4228  *              NO_ERROR  -- success
4229  *              none-zero failure code
4230  *===========================================================*/
4231 
setSecureMode(const QCameraParameters & params)4232 int32_t QCameraParameters::setSecureMode(const QCameraParameters& params)
4233 {
4234     const char *str = params.get(KEY_QC_SECURE_MODE);
4235     const char *prev_str = get(KEY_QC_SECURE_MODE);
4236     char prop[PROPERTY_VALUE_MAX];
4237     memset(prop, 0, sizeof(prop));
4238 
4239     property_get("persist.camera.secure.mode", prop, VALUE_DISABLE);
4240     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4241         ALOGD("%s : Secure mode set to KEY: %s", __func__, str);
4242         setSecureMode(str);
4243     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4244         ALOGD("%s : Secure mode set to prop: %s", __func__, prop);
4245         setSecureMode(prop);
4246     }
4247     return NO_ERROR;
4248 }
4249 
4250 /*===========================================================================
4251  * FUNCTION   : setZslAttributes
4252  *
4253  * DESCRIPTION: set ZSL related attributes from user setting
4254  *
4255  * PARAMETERS :
4256  *   @params  : user setting parameters
4257  *
4258  * RETURN     : int32_t type of status
4259  *              NO_ERROR  -- success
4260  *              none-zero failure code
4261  *==========================================================================*/
setZslAttributes(const QCameraParameters & params)4262 int32_t QCameraParameters::setZslAttributes(const QCameraParameters& params)
4263 {
4264     // TODO: may switch to pure param instead of sysprop
4265     char prop[PROPERTY_VALUE_MAX];
4266 
4267     const char *str = params.get(KEY_QC_ZSL_BURST_INTERVAL);
4268     if (str != NULL) {
4269         set(KEY_QC_ZSL_BURST_INTERVAL, str);
4270     } else {
4271         memset(prop, 0, sizeof(prop));
4272         property_get("persist.camera.zsl.interval", prop, "1");
4273         set(KEY_QC_ZSL_BURST_INTERVAL, prop);
4274         CDBG_HIGH("%s: [ZSL Retro] burst interval: %s", __func__, prop);
4275     }
4276 
4277     str = params.get(KEY_QC_ZSL_BURST_LOOKBACK);
4278     if (str != NULL) {
4279         set(KEY_QC_ZSL_BURST_LOOKBACK, str);
4280     } else {
4281         memset(prop, 0, sizeof(prop));
4282         property_get("persist.camera.zsl.backlookcnt", prop, "2");
4283         set(KEY_QC_ZSL_BURST_LOOKBACK, prop);
4284         CDBG_HIGH("%s: [ZSL Retro] look back count: %s", __func__, prop);
4285     }
4286 
4287     str = params.get(KEY_QC_ZSL_QUEUE_DEPTH);
4288     if (str != NULL) {
4289         set(KEY_QC_ZSL_QUEUE_DEPTH, str);
4290     } else {
4291         memset(prop, 0, sizeof(prop));
4292         property_get("persist.camera.zsl.queuedepth", prop, "2");
4293         set(KEY_QC_ZSL_QUEUE_DEPTH, prop);
4294         CDBG_HIGH("%s: [ZSL Retro] queue depth: %s", __func__, prop);
4295     }
4296 
4297     return NO_ERROR;
4298 }
4299 
4300 /*===========================================================================
4301  * FUNCTION   : setFlip
4302  *
4303  * DESCRIPTION: set preview/ video/ picture flip mode from user setting
4304  *
4305  * PARAMETERS :
4306  *   @params  : user setting parameters
4307  *
4308  * RETURN     : int32_t type of status
4309  *              NO_ERROR  -- success
4310  *              none-zero failure code
4311  *==========================================================================*/
setFlip(const QCameraParameters & params)4312 int32_t QCameraParameters::setFlip(const QCameraParameters& params)
4313 {
4314     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) == 0) {
4315         CDBG_HIGH("%s: flip is not supported.", __func__);
4316         return NO_ERROR;
4317     }
4318 
4319     //check preview flip setting
4320     const char *str = params.get(KEY_QC_PREVIEW_FLIP);
4321     const char *prev_val = get(KEY_QC_PREVIEW_FLIP);
4322     if(str != NULL){
4323         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4324             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4325             if(value != NAME_NOT_FOUND){
4326                 set(KEY_QC_PREVIEW_FLIP, str);
4327                 m_bPreviewFlipChanged = true;
4328             }
4329         }
4330     }
4331 
4332     // check video filp setting
4333     str = params.get(KEY_QC_VIDEO_FLIP);
4334     prev_val = get(KEY_QC_VIDEO_FLIP);
4335     if(str != NULL){
4336         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4337             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4338             if(value != NAME_NOT_FOUND){
4339                 set(KEY_QC_VIDEO_FLIP, str);
4340                 m_bVideoFlipChanged = true;
4341             }
4342         }
4343     }
4344 
4345     // check picture filp setting
4346     str = params.get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
4347     prev_val = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
4348     if(str != NULL){
4349         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4350             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4351             if(value != NAME_NOT_FOUND){
4352                 set(KEY_QC_SNAPSHOT_PICTURE_FLIP, str);
4353                 m_bSnapshotFlipChanged = true;
4354             }
4355         }
4356     }
4357 
4358     return NO_ERROR;
4359 }
4360 
4361 /*===========================================================================
4362  * FUNCTION   : setBurstNum
4363  *
4364  * DESCRIPTION: set burst number of snapshot
4365  *
4366  * PARAMETERS :
4367  *   @params  : user setting parameters
4368  *
4369  * RETURN     : int32_t type of status
4370  *              NO_ERROR  -- success
4371  *              none-zero failure code
4372  *==========================================================================*/
setBurstNum(const QCameraParameters & params)4373 int32_t QCameraParameters::setBurstNum(const QCameraParameters& params)
4374 {
4375     int nBurstNum = params.getInt(KEY_QC_SNAPSHOT_BURST_NUM);
4376     if (isAdvCamFeaturesEnabled()) {
4377         nBurstNum = 1;
4378     }
4379     if (nBurstNum <= 0) {
4380         // if burst number is not set in parameters,
4381         // read from sys prop
4382         char prop[PROPERTY_VALUE_MAX];
4383         memset(prop, 0, sizeof(prop));
4384         property_get("persist.camera.snapshot.number", prop, "0");
4385         nBurstNum = atoi(prop);
4386         if (nBurstNum <= 0) {
4387             nBurstNum = 1;
4388         }
4389     }
4390     set(KEY_QC_SNAPSHOT_BURST_NUM, nBurstNum);
4391     m_nBurstNum = (uint8_t)nBurstNum;
4392     CDBG_HIGH("%s: [ZSL Retro] m_nBurstNum = %d", __func__, m_nBurstNum);
4393     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BURST_NUM, (uint32_t)nBurstNum)) {
4394         return BAD_VALUE;
4395     }
4396 
4397     return NO_ERROR;
4398 }
4399 
4400 /*===========================================================================
4401  * FUNCTION   : setSnapshotFDReq
4402  *
4403  * DESCRIPTION: set requirement of Face Detection Metadata in Snapshot mode.
4404  *
4405  * PARAMETERS :
4406  *   @params  : user setting parameters
4407  *
4408  * RETURN     : int32_t type of status
4409  *              NO_ERROR  -- success
4410  *              none-zero failure code
4411  *==========================================================================*/
setSnapshotFDReq(const QCameraParameters & params)4412 int32_t QCameraParameters::setSnapshotFDReq(const QCameraParameters& params)
4413 {
4414     char prop[PROPERTY_VALUE_MAX];
4415     const char *str = params.get(KEY_QC_SNAPSHOT_FD_DATA);
4416 
4417     if(str != NULL){
4418         set(KEY_QC_SNAPSHOT_FD_DATA, str);
4419     }else{
4420         memset(prop, 0, sizeof(prop));
4421         property_get("persist.camera.snapshot.fd", prop, "0");
4422         set(KEY_QC_SNAPSHOT_FD_DATA, prop);
4423     }
4424     return NO_ERROR;
4425 }
4426 
4427 /*===========================================================================
4428  * FUNCTION   : setMobicat
4429  *
4430  * DESCRIPTION: set Mobicat on/off.
4431  *
4432  * PARAMETERS :
4433  *   @params  : user setting parameters
4434  *
4435  * RETURN     : int32_t type of status
4436  *              NO_ERROR  -- success
4437  *              none-zero failure code
4438  *==========================================================================*/
setMobicat(const QCameraParameters &)4439 int32_t QCameraParameters::setMobicat(const QCameraParameters& )
4440 {
4441     char value [PROPERTY_VALUE_MAX];
4442     property_get("persist.camera.mobicat", value, "0");
4443     int32_t ret = NO_ERROR;
4444     uint8_t enableMobi = (uint8_t)atoi(value);
4445 
4446     if (enableMobi) {
4447         tune_cmd_t tune_cmd;
4448         tune_cmd.type = 2;
4449         tune_cmd.module = 0;
4450         tune_cmd.value = 1;
4451         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_VFE_COMMAND, tune_cmd)) {
4452             return BAD_VALUE;
4453         }
4454         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_PP_COMMAND, tune_cmd)) {
4455             ret = BAD_VALUE;
4456         }
4457     }
4458     m_MobiMask = enableMobi;
4459 
4460     return ret;
4461 }
4462 
4463 /*===========================================================================
4464  * FUNCTION   : updateParameters
4465  *
4466  * DESCRIPTION: update parameters from user setting
4467  *
4468  * PARAMETERS :
4469  *   @params  : user setting parameters
4470  *   @needRestart : [output] if preview need restart upon setting changes
4471  *
4472  * RETURN     : int32_t type of status
4473  *              NO_ERROR  -- success
4474  *              none-zero failure code
4475  *==========================================================================*/
updateParameters(QCameraParameters & params,bool & needRestart)4476 int32_t QCameraParameters::updateParameters(QCameraParameters& params,
4477         bool &needRestart)
4478 {
4479     int32_t final_rc = NO_ERROR;
4480     int32_t rc;
4481     m_bNeedRestart = false;
4482 
4483     if(initBatchUpdate(m_pParamBuf) < 0 ) {
4484         ALOGE("%s:Failed to initialize group update table",__func__);
4485         rc = BAD_TYPE;
4486         goto UPDATE_PARAM_DONE;
4487     }
4488 
4489     if ((rc = setPreviewSize(params)))                  final_rc = rc;
4490     if ((rc = setVideoSize(params)))                    final_rc = rc;
4491     if ((rc = setPictureSize(params)))                  final_rc = rc;
4492     if ((rc = setPreviewFormat(params)))                final_rc = rc;
4493     if ((rc = setPictureFormat(params)))                final_rc = rc;
4494     if ((rc = setJpegQuality(params)))                  final_rc = rc;
4495     if ((rc = setOrientation(params)))                  final_rc = rc;
4496     if ((rc = setRotation(params)))                     final_rc = rc;
4497     if ((rc = setVideoRotation(params)))                final_rc = rc;
4498     if ((rc = setNoDisplayMode(params)))                final_rc = rc;
4499     if ((rc = setZslMode(params)))                      final_rc = rc;
4500     if ((rc = setZslAttributes(params)))                final_rc = rc;
4501     if ((rc = setCameraMode(params)))                   final_rc = rc;
4502     if ((rc = setSceneSelectionMode(params)))           final_rc = rc;
4503     if ((rc = setRecordingHint(params)))                final_rc = rc;
4504     if ((rc = setRdiMode(params)))                      final_rc = rc;
4505     if ((rc = setSecureMode(params)))                   final_rc = rc;
4506     if ((rc = setPreviewFrameRate(params)))             final_rc = rc;
4507     if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
4508     if ((rc = setAutoExposure(params)))                 final_rc = rc;
4509     if ((rc = setEffect(params)))                       final_rc = rc;
4510     if ((rc = setBrightness(params)))                   final_rc = rc;
4511     if ((rc = setZoom(params)))                         final_rc = rc;
4512     if ((rc = setSharpness(params)))                    final_rc = rc;
4513     if ((rc = setSaturation(params)))                   final_rc = rc;
4514     if ((rc = setContrast(params)))                     final_rc = rc;
4515     if ((rc = setFocusMode(params)))                    final_rc = rc;
4516     if ((rc = setISOValue(params)))                     final_rc = rc;
4517     if ((rc = setContinuousISO(params)))                final_rc = rc;
4518     if ((rc = setExposureTime(params)))                 final_rc = rc;
4519     if ((rc = setSkinToneEnhancement(params)))          final_rc = rc;
4520     if ((rc = setFlash(params)))                        final_rc = rc;
4521     if ((rc = setAecLock(params)))                      final_rc = rc;
4522     if ((rc = setAwbLock(params)))                      final_rc = rc;
4523     if ((rc = setLensShadeValue(params)))               final_rc = rc;
4524     if ((rc = setMCEValue(params)))                     final_rc = rc;
4525     if ((rc = setDISValue(params)))                     final_rc = rc;
4526     if ((rc = setAntibanding(params)))                  final_rc = rc;
4527     if ((rc = setExposureCompensation(params)))         final_rc = rc;
4528     if ((rc = setWhiteBalance(params)))                 final_rc = rc;
4529     if ((rc = setHDRMode(params)))                      final_rc = rc;
4530     if ((rc = setHDRNeed1x(params)))                    final_rc = rc;
4531     if ((rc = setManualWhiteBalance(params)))           final_rc = rc;
4532     if ((rc = setSceneMode(params)))                    final_rc = rc;
4533     if ((rc = setFocusAreas(params)))                   final_rc = rc;
4534     if ((rc = setFocusPosition(params)))                final_rc = rc;
4535     if ((rc = setMeteringAreas(params)))                final_rc = rc;
4536     if ((rc = setSelectableZoneAf(params)))             final_rc = rc;
4537     if ((rc = setRedeyeReduction(params)))              final_rc = rc;
4538     if ((rc = setAEBracket(params)))                    final_rc = rc;
4539     if ((rc = setAutoHDR(params)))                      final_rc = rc;
4540     if ((rc = setGpsLocation(params)))                  final_rc = rc;
4541     if ((rc = setWaveletDenoise(params)))               final_rc = rc;
4542     if ((rc = setFaceRecognition(params)))              final_rc = rc;
4543     if ((rc = setFlip(params)))                         final_rc = rc;
4544     if ((rc = setVideoHDR(params)))                     final_rc = rc;
4545     if ((rc = setVtEnable(params)))                     final_rc = rc;
4546     if ((rc = setAFBracket(params)))                    final_rc = rc;
4547     if ((rc = setReFocus(params)))                      final_rc = rc;
4548     if ((rc = setChromaFlash(params)))                  final_rc = rc;
4549     if ((rc = setTruePortrait(params)))                 final_rc = rc;
4550     if ((rc = setOptiZoom(params)))                     final_rc = rc;
4551     if ((rc = setBurstNum(params)))                     final_rc = rc;
4552     if ((rc = setBurstLEDOnPeriod(params)))             final_rc = rc;
4553     if ((rc = setRetroActiveBurstNum(params)))          final_rc = rc;
4554     if ((rc = setSnapshotFDReq(params)))                final_rc = rc;
4555     if ((rc = setTintlessValue(params)))                final_rc = rc;
4556     if ((rc = setCDSMode(params)))                      final_rc = rc;
4557     if ((rc = setTemporalDenoise(params)))              final_rc = rc;
4558 
4559     // update live snapshot size after all other parameters are set
4560     if ((rc = setLiveSnapshotSize(params)))             final_rc = rc;
4561     if ((rc = setJpegThumbnailSize(params)))            final_rc = rc;
4562     if ((rc = setStatsDebugMask()))                     final_rc = rc;
4563     if ((rc = setPAAF()))                               final_rc = rc;
4564     if ((rc = setMobicat(params)))                      final_rc = rc;
4565     if ((rc = setSeeMore(params)))                      final_rc = rc;
4566     if ((rc = setStillMore(params)))                    final_rc = rc;
4567 
4568     if ((rc = updateFlash(false)))                      final_rc = rc;
4569 
4570 UPDATE_PARAM_DONE:
4571     needRestart = m_bNeedRestart;
4572     return final_rc;
4573 }
4574 
4575 /*===========================================================================
4576  * FUNCTION   : commitParameters
4577  *
4578  * DESCRIPTION: commit parameter changes to backend
4579  *
4580  * PARAMETERS : none
4581  *
4582  * RETURN     : int32_t type of status
4583  *              NO_ERROR  -- success
4584  *              none-zero failure code
4585  *==========================================================================*/
commitParameters()4586 int32_t QCameraParameters::commitParameters()
4587 {
4588     return commitSetBatch();
4589 }
4590 
4591 /*===========================================================================
4592  * FUNCTION   : initDefaultParameters
4593  *
4594  * DESCRIPTION: initialize default parameters for the first time
4595  *
4596  * PARAMETERS : none
4597  *
4598  * RETURN     : int32_t type of status
4599  *              NO_ERROR  -- success
4600  *              none-zero failure code
4601  *==========================================================================*/
initDefaultParameters()4602 int32_t QCameraParameters::initDefaultParameters()
4603 {
4604     if(initBatchUpdate(m_pParamBuf) < 0 ) {
4605         ALOGE("%s:Failed to initialize group update table", __func__);
4606         return BAD_TYPE;
4607     }
4608     int32_t hal_version = CAM_HAL_V1;
4609     ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HAL_VERSION, hal_version);
4610 
4611     /*************************Initialize Values******************************/
4612     // Set read only parameters from camera capability
4613     set(KEY_SMOOTH_ZOOM_SUPPORTED,
4614         m_pCapability->smooth_zoom_supported? VALUE_TRUE : VALUE_FALSE);
4615     set(KEY_ZOOM_SUPPORTED,
4616         m_pCapability->zoom_supported? VALUE_TRUE : VALUE_FALSE);
4617     set(KEY_VIDEO_SNAPSHOT_SUPPORTED,
4618         m_pCapability->video_snapshot_supported? VALUE_TRUE : VALUE_FALSE);
4619     set(KEY_VIDEO_STABILIZATION_SUPPORTED,
4620         m_pCapability->video_stablization_supported? VALUE_TRUE : VALUE_FALSE);
4621     set(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED,
4622         m_pCapability->auto_exposure_lock_supported? VALUE_TRUE : VALUE_FALSE);
4623     set(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED,
4624         m_pCapability->auto_wb_lock_supported? VALUE_TRUE : VALUE_FALSE);
4625     set(KEY_QC_SUPPORTED_CAMERA_FEATURES,
4626             (int)m_pCapability->qcom_supported_feature_mask);
4627     set(KEY_MAX_NUM_DETECTED_FACES_HW, m_pCapability->max_num_roi);
4628     set(KEY_MAX_NUM_DETECTED_FACES_SW, m_pCapability->max_num_roi);
4629     set(KEY_QC_MAX_NUM_REQUESTED_FACES, m_pCapability->max_num_roi);
4630     // Set focal length, horizontal view angle, and vertical view angle
4631     setFloat(KEY_FOCAL_LENGTH, m_pCapability->focal_length);
4632     setFloat(KEY_HORIZONTAL_VIEW_ANGLE, m_pCapability->hor_view_angle);
4633     setFloat(KEY_VERTICAL_VIEW_ANGLE, m_pCapability->ver_view_angle);
4634     set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
4635     set(KEY_QC_AUTO_HDR_SUPPORTED,
4636         (m_pCapability->auto_hdr_supported)? VALUE_TRUE : VALUE_FALSE);
4637     // Set supported preview sizes
4638     if (m_pCapability->preview_sizes_tbl_cnt > 0 &&
4639         m_pCapability->preview_sizes_tbl_cnt <= MAX_SIZES_CNT) {
4640         String8 previewSizeValues = createSizesString(
4641                 m_pCapability->preview_sizes_tbl, m_pCapability->preview_sizes_tbl_cnt);
4642         set(KEY_SUPPORTED_PREVIEW_SIZES, previewSizeValues.string());
4643         CDBG_HIGH("%s: supported preview sizes: %s", __func__, previewSizeValues.string());
4644         // Set default preview size
4645         CameraParameters::setPreviewSize(m_pCapability->preview_sizes_tbl[0].width,
4646                                          m_pCapability->preview_sizes_tbl[0].height);
4647     } else {
4648         ALOGE("%s: supported preview sizes cnt is 0 or exceeds max!!!", __func__);
4649     }
4650 
4651     // Set supported video sizes
4652     if (m_pCapability->video_sizes_tbl_cnt > 0 &&
4653         m_pCapability->video_sizes_tbl_cnt <= MAX_SIZES_CNT) {
4654         String8 videoSizeValues = createSizesString(
4655                 m_pCapability->video_sizes_tbl, m_pCapability->video_sizes_tbl_cnt);
4656         set(KEY_SUPPORTED_VIDEO_SIZES, videoSizeValues.string());
4657         CDBG_HIGH("%s: supported video sizes: %s", __func__, videoSizeValues.string());
4658         // Set default video size
4659         CameraParameters::setVideoSize(m_pCapability->video_sizes_tbl[0].width,
4660                                        m_pCapability->video_sizes_tbl[0].height);
4661 
4662         //Set preferred Preview size for video
4663         String8 vSize = createSizesString(&m_pCapability->preview_sizes_tbl[0], 1);
4664         set(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, vSize.string());
4665     } else {
4666         ALOGE("%s: supported video sizes cnt is 0 or exceeds max!!!", __func__);
4667     }
4668 
4669     // Set supported picture sizes
4670     if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
4671         m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
4672         String8 pictureSizeValues = createSizesString(
4673                 m_pCapability->picture_sizes_tbl, m_pCapability->picture_sizes_tbl_cnt);
4674         set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
4675         CDBG_HIGH("%s: supported pic sizes: %s", __func__, pictureSizeValues.string());
4676         // Set default picture size to the smallest resolution
4677         CameraParameters::setPictureSize(
4678            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].width,
4679            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].height);
4680     } else {
4681         ALOGE("%s: supported picture sizes cnt is 0 or exceeds max!!!", __func__);
4682     }
4683 
4684     // Need check if scale should be enabled
4685     if (m_pCapability->scale_picture_sizes_cnt > 0 &&
4686         m_pCapability->scale_picture_sizes_cnt <= MAX_SCALE_SIZES_CNT){
4687         //get scale size, enable scaling. And re-set picture size table with scale sizes
4688         m_reprocScaleParam.setScaleEnable(true);
4689         int rc_s = m_reprocScaleParam.setScaleSizeTbl(
4690             m_pCapability->scale_picture_sizes_cnt, m_pCapability->scale_picture_sizes,
4691             m_pCapability->picture_sizes_tbl_cnt, m_pCapability->picture_sizes_tbl);
4692         if(rc_s == NO_ERROR){
4693             cam_dimension_t *totalSizeTbl = m_reprocScaleParam.getTotalSizeTbl();
4694             size_t totalSizeCnt = m_reprocScaleParam.getTotalSizeTblCnt();
4695             String8 pictureSizeValues = createSizesString(totalSizeTbl, totalSizeCnt);
4696             set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
4697             CDBG_HIGH("%s: scaled supported pic sizes: %s", __func__, pictureSizeValues.string());
4698         }else{
4699             m_reprocScaleParam.setScaleEnable(false);
4700             ALOGE("%s: reset scaled picture size table failed.", __func__);
4701         }
4702     }else{
4703         m_reprocScaleParam.setScaleEnable(false);
4704     }
4705 
4706     // Set supported thumbnail sizes
4707     String8 thumbnailSizeValues = createSizesString(
4708             THUMBNAIL_SIZES_MAP,
4709             PARAM_MAP_SIZE(THUMBNAIL_SIZES_MAP));
4710     set(KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, thumbnailSizeValues.string());
4711     // Set default thumnail size
4712     set(KEY_JPEG_THUMBNAIL_WIDTH, THUMBNAIL_SIZES_MAP[0].width);
4713     set(KEY_JPEG_THUMBNAIL_HEIGHT, THUMBNAIL_SIZES_MAP[0].height);
4714 
4715     // Set supported livesnapshot sizes
4716     if (m_pCapability->livesnapshot_sizes_tbl_cnt > 0 &&
4717         m_pCapability->livesnapshot_sizes_tbl_cnt <= MAX_SIZES_CNT) {
4718         String8 liveSnpashotSizeValues = createSizesString(
4719                 m_pCapability->livesnapshot_sizes_tbl,
4720                 m_pCapability->livesnapshot_sizes_tbl_cnt);
4721         set(KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES, liveSnpashotSizeValues.string());
4722         CDBG("%s: supported live snapshot sizes: %s", __func__, liveSnpashotSizeValues.string());
4723         m_LiveSnapshotSize =
4724             m_pCapability->livesnapshot_sizes_tbl[m_pCapability->livesnapshot_sizes_tbl_cnt-1];
4725     }
4726 
4727     // Set supported preview formats
4728     String8 previewFormatValues = createValuesString(
4729             m_pCapability->supported_preview_fmts,
4730             m_pCapability->supported_preview_fmt_cnt,
4731             PREVIEW_FORMATS_MAP,
4732             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP));
4733     set(KEY_SUPPORTED_PREVIEW_FORMATS, previewFormatValues.string());
4734     // Set default preview format
4735     CameraParameters::setPreviewFormat(PIXEL_FORMAT_YUV420SP);
4736 
4737     // Set default Video Format
4738     set(KEY_VIDEO_FRAME_FORMAT, PIXEL_FORMAT_YUV420SP);
4739 
4740     // Set supported picture formats
4741     String8 pictureTypeValues(PIXEL_FORMAT_JPEG);
4742     String8 str = createValuesString(
4743             m_pCapability->supported_raw_fmts,
4744             m_pCapability->supported_raw_fmt_cnt,
4745             PICTURE_TYPES_MAP,
4746             PARAM_MAP_SIZE(PICTURE_TYPES_MAP));
4747     if (str.string() != NULL) {
4748         pictureTypeValues.append(",");
4749         pictureTypeValues.append(str);
4750     }
4751 
4752     set(KEY_SUPPORTED_PICTURE_FORMATS, pictureTypeValues.string());
4753     // Set default picture Format
4754     CameraParameters::setPictureFormat(PIXEL_FORMAT_JPEG);
4755     // Set raw image size
4756     char raw_size_str[32];
4757     snprintf(raw_size_str, sizeof(raw_size_str), "%dx%d",
4758              m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
4759     set(KEY_QC_RAW_PICUTRE_SIZE, raw_size_str);
4760     CDBG("%s: KEY_QC_RAW_PICUTRE_SIZE: w: %d, h: %d ", __func__,
4761        m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
4762 
4763     //set default jpeg quality and thumbnail quality
4764     set(KEY_JPEG_QUALITY, 85);
4765     set(KEY_JPEG_THUMBNAIL_QUALITY, 85);
4766 
4767     // Set FPS ranges
4768     if (m_pCapability->fps_ranges_tbl_cnt > 0 &&
4769         m_pCapability->fps_ranges_tbl_cnt <= MAX_SIZES_CNT) {
4770         int default_fps_index = 0;
4771         String8 fpsRangeValues = createFpsRangeString(m_pCapability->fps_ranges_tbl,
4772                                                       m_pCapability->fps_ranges_tbl_cnt,
4773                                                       default_fps_index);
4774         set(KEY_SUPPORTED_PREVIEW_FPS_RANGE, fpsRangeValues.string());
4775 
4776         int min_fps =
4777             int(m_pCapability->fps_ranges_tbl[default_fps_index].min_fps * 1000);
4778         int max_fps =
4779             int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps * 1000);
4780         m_default_fps_range = m_pCapability->fps_ranges_tbl[default_fps_index];
4781         //Set video fps same as preview fps
4782         setPreviewFpsRange(min_fps, max_fps, min_fps, max_fps);
4783 
4784         // Set legacy preview fps
4785         String8 fpsValues = createFpsString(m_pCapability->fps_ranges_tbl[default_fps_index]);
4786         set(KEY_SUPPORTED_PREVIEW_FRAME_RATES, fpsValues.string());
4787         CDBG_HIGH("%s: supported fps rates: %s", __func__, fpsValues.string());
4788         CameraParameters::setPreviewFrameRate(int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps));
4789     } else {
4790         ALOGE("%s: supported fps ranges cnt is 0 or exceeds max!!!", __func__);
4791     }
4792 
4793     // Set supported focus modes
4794     if (m_pCapability->supported_focus_modes_cnt > 0) {
4795         String8 focusModeValues = createValuesString(
4796                 m_pCapability->supported_focus_modes,
4797                 m_pCapability->supported_focus_modes_cnt,
4798                 FOCUS_MODES_MAP,
4799                 PARAM_MAP_SIZE(FOCUS_MODES_MAP));
4800         set(KEY_SUPPORTED_FOCUS_MODES, focusModeValues);
4801 
4802         // Set default focus mode and update corresponding parameter buf
4803         const char *focusMode = lookupNameByValue(FOCUS_MODES_MAP,
4804                 PARAM_MAP_SIZE(FOCUS_MODES_MAP),
4805                 m_pCapability->supported_focus_modes[0]);
4806         if (focusMode != NULL) {
4807             setFocusMode(focusMode);
4808         } else {
4809             setFocusMode(FOCUS_MODE_FIXED);
4810         }
4811     } else {
4812         ALOGE("%s: supported focus modes cnt is 0!!!", __func__);
4813     }
4814 
4815     // Set focus areas
4816     if (m_pCapability->max_num_focus_areas > MAX_ROI) {
4817         m_pCapability->max_num_focus_areas = MAX_ROI;
4818     }
4819     set(KEY_MAX_NUM_FOCUS_AREAS, m_pCapability->max_num_focus_areas);
4820     if (m_pCapability->max_num_focus_areas > 0) {
4821         setFocusAreas(DEFAULT_CAMERA_AREA);
4822     }
4823 
4824     // Set metering areas
4825     if (m_pCapability->max_num_metering_areas > MAX_ROI) {
4826         m_pCapability->max_num_metering_areas = MAX_ROI;
4827     }
4828     set(KEY_MAX_NUM_METERING_AREAS, m_pCapability->max_num_metering_areas);
4829     if (m_pCapability->max_num_metering_areas > 0) {
4830         setMeteringAreas(DEFAULT_CAMERA_AREA);
4831     }
4832 
4833     // set focus position, we should get them from m_pCapability
4834     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 0;
4835     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 1023;
4836     set(KEY_QC_MIN_FOCUS_POS_INDEX,
4837             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
4838     set(KEY_QC_MAX_FOCUS_POS_INDEX,
4839             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
4840 
4841     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 0;
4842     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 1023;
4843     set(KEY_QC_MIN_FOCUS_POS_DAC,
4844             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
4845     set(KEY_QC_MAX_FOCUS_POS_DAC,
4846             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
4847 
4848     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 0;
4849     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 100;
4850     set(KEY_QC_MIN_FOCUS_POS_RATIO,
4851             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
4852     set(KEY_QC_MAX_FOCUS_POS_RATIO,
4853             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
4854 
4855     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
4856     if (m_pCapability->min_focus_distance > 0) {
4857         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] =
4858                 100.0f / m_pCapability->min_focus_distance;
4859     } else {
4860         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
4861     }
4862     setFloat(KEY_QC_MIN_FOCUS_POS_DIOPTER,
4863             m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
4864     setFloat(KEY_QC_MAX_FOCUS_POS_DIOPTER,
4865             m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
4866 
4867     //set supported manual focus modes
4868     String8 manualFocusModes(VALUE_OFF);
4869     if (m_pCapability->supported_focus_modes_cnt > 1 &&
4870         m_pCapability->min_focus_distance > 0) {
4871         manualFocusModes.append(",");
4872         manualFocusModes.append(KEY_QC_FOCUS_SCALE_MODE);
4873         manualFocusModes.append(",");
4874         manualFocusModes.append(KEY_QC_FOCUS_DIOPTER_MODE);
4875     }
4876     set(KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES, manualFocusModes.string());
4877 
4878     // Set Saturation
4879     set(KEY_QC_MIN_SATURATION, m_pCapability->saturation_ctrl.min_value);
4880     set(KEY_QC_MAX_SATURATION, m_pCapability->saturation_ctrl.max_value);
4881     set(KEY_QC_SATURATION_STEP, m_pCapability->saturation_ctrl.step);
4882     setSaturation(m_pCapability->saturation_ctrl.def_value);
4883 
4884     // Set Sharpness
4885     set(KEY_QC_MIN_SHARPNESS, m_pCapability->sharpness_ctrl.min_value);
4886     set(KEY_QC_MAX_SHARPNESS, m_pCapability->sharpness_ctrl.max_value);
4887     set(KEY_QC_SHARPNESS_STEP, m_pCapability->sharpness_ctrl.step);
4888     setSharpness(m_pCapability->sharpness_ctrl.def_value);
4889 
4890     // Set Contrast
4891     set(KEY_QC_MIN_CONTRAST, m_pCapability->contrast_ctrl.min_value);
4892     set(KEY_QC_MAX_CONTRAST, m_pCapability->contrast_ctrl.max_value);
4893     set(KEY_QC_CONTRAST_STEP, m_pCapability->contrast_ctrl.step);
4894     setContrast(m_pCapability->contrast_ctrl.def_value);
4895 
4896     // Set SCE factor
4897     set(KEY_QC_MIN_SCE_FACTOR, m_pCapability->sce_ctrl.min_value); // -100
4898     set(KEY_QC_MAX_SCE_FACTOR, m_pCapability->sce_ctrl.max_value); // 100
4899     set(KEY_QC_SCE_FACTOR_STEP, m_pCapability->sce_ctrl.step);     // 10
4900     setSkinToneEnhancement(m_pCapability->sce_ctrl.def_value);     // 0
4901 
4902     // Set Brightness
4903     set(KEY_QC_MIN_BRIGHTNESS, m_pCapability->brightness_ctrl.min_value); // 0
4904     set(KEY_QC_MAX_BRIGHTNESS, m_pCapability->brightness_ctrl.max_value); // 6
4905     set(KEY_QC_BRIGHTNESS_STEP, m_pCapability->brightness_ctrl.step);     // 1
4906     setBrightness(m_pCapability->brightness_ctrl.def_value);
4907 
4908     // Set Auto exposure
4909     String8 autoExposureValues = createValuesString(
4910             m_pCapability->supported_aec_modes,
4911             m_pCapability->supported_aec_modes_cnt,
4912             AUTO_EXPOSURE_MAP,
4913             PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP));
4914     set(KEY_QC_SUPPORTED_AUTO_EXPOSURE, autoExposureValues.string());
4915     setAutoExposure(AUTO_EXPOSURE_FRAME_AVG);
4916 
4917     // Set Exposure Compensation
4918     set(KEY_MAX_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_max); // 12
4919     set(KEY_MIN_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_min); // -12
4920     setFloat(KEY_EXPOSURE_COMPENSATION_STEP, m_pCapability->exposure_compensation_step); // 1/6
4921     setExposureCompensation(m_pCapability->exposure_compensation_default); // 0
4922 
4923     // Set Antibanding
4924     String8 antibandingValues = createValuesString(
4925             m_pCapability->supported_antibandings,
4926             m_pCapability->supported_antibandings_cnt,
4927             ANTIBANDING_MODES_MAP,
4928             PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP));
4929     set(KEY_SUPPORTED_ANTIBANDING, antibandingValues);
4930     setAntibanding(ANTIBANDING_OFF);
4931 
4932     // Set Effect
4933     String8 effectValues = createValuesString(
4934             m_pCapability->supported_effects,
4935             m_pCapability->supported_effects_cnt,
4936             EFFECT_MODES_MAP,
4937             PARAM_MAP_SIZE(EFFECT_MODES_MAP));
4938     set(KEY_SUPPORTED_EFFECTS, effectValues);
4939     setEffect(EFFECT_NONE);
4940 
4941     // Set WhiteBalance
4942     String8 whitebalanceValues = createValuesString(
4943             m_pCapability->supported_white_balances,
4944             m_pCapability->supported_white_balances_cnt,
4945             WHITE_BALANCE_MODES_MAP,
4946             PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP));
4947     set(KEY_SUPPORTED_WHITE_BALANCE, whitebalanceValues);
4948     setWhiteBalance(WHITE_BALANCE_AUTO);
4949 
4950     // set supported wb cct, we should get them from m_pCapability
4951     m_pCapability->min_wb_cct = 2000;
4952     m_pCapability->max_wb_cct = 8000;
4953     set(KEY_QC_MIN_WB_CCT, m_pCapability->min_wb_cct);
4954     set(KEY_QC_MAX_WB_CCT, m_pCapability->max_wb_cct);
4955 
4956     // set supported wb rgb gains, ideally we should get them from m_pCapability
4957     //but for now hardcode.
4958     m_pCapability->min_wb_gain = 1.0;
4959     m_pCapability->max_wb_gain = 4.0;
4960     setFloat(KEY_QC_MIN_WB_GAIN, m_pCapability->min_wb_gain);
4961     setFloat(KEY_QC_MAX_WB_GAIN, m_pCapability->max_wb_gain);
4962 
4963     //set supported manual wb modes
4964     String8 manualWBModes(VALUE_OFF);
4965     if(m_pCapability->sensor_type.sens_type != CAM_SENSOR_YUV) {
4966         manualWBModes.append(",");
4967         manualWBModes.append(KEY_QC_WB_CCT_MODE);
4968         manualWBModes.append(",");
4969         manualWBModes.append(KEY_QC_WB_GAIN_MODE);
4970     }
4971     set(KEY_QC_SUPPORTED_MANUAL_WB_MODES, manualWBModes.string());
4972 
4973     // Set Flash mode
4974     if(m_pCapability->supported_flash_modes_cnt > 0) {
4975        String8 flashValues = createValuesString(
4976                m_pCapability->supported_flash_modes,
4977                m_pCapability->supported_flash_modes_cnt,
4978                FLASH_MODES_MAP,
4979                PARAM_MAP_SIZE(FLASH_MODES_MAP));
4980        set(KEY_SUPPORTED_FLASH_MODES, flashValues);
4981        setFlash(FLASH_MODE_OFF);
4982     } else {
4983         ALOGE("%s: supported flash modes cnt is 0!!!", __func__);
4984     }
4985 
4986     // Set Scene Mode
4987     String8 sceneModeValues = createValuesString(
4988             m_pCapability->supported_scene_modes,
4989             m_pCapability->supported_scene_modes_cnt,
4990             SCENE_MODES_MAP,
4991             PARAM_MAP_SIZE(SCENE_MODES_MAP));
4992     set(KEY_SUPPORTED_SCENE_MODES, sceneModeValues);
4993     setSceneMode(SCENE_MODE_AUTO);
4994 
4995     // Set CDS Mode
4996     String8 cdsModeValues = createValuesStringFromMap(
4997             CDS_MODES_MAP,
4998             PARAM_MAP_SIZE(CDS_MODES_MAP));
4999     set(KEY_QC_SUPPORTED_CDS_MODES, cdsModeValues);
5000 
5001     // Set video CDS Mode
5002     String8 videoCdsModeValues = createValuesStringFromMap(
5003             CDS_MODES_MAP,
5004             PARAM_MAP_SIZE(CDS_MODES_MAP));
5005     set(KEY_QC_SUPPORTED_VIDEO_CDS_MODES, videoCdsModeValues);
5006 
5007     // Set TNR Mode
5008     String8 tnrModeValues = createValuesStringFromMap(
5009             ON_OFF_MODES_MAP,
5010             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5011     set(KEY_QC_SUPPORTED_TNR_MODES, tnrModeValues);
5012 
5013     // Set video TNR Mode
5014     String8 videoTnrModeValues = createValuesStringFromMap(
5015             ON_OFF_MODES_MAP,
5016             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5017     set(KEY_QC_SUPPORTED_VIDEO_TNR_MODES, videoTnrModeValues);
5018 
5019     // Set ISO Mode
5020     String8 isoValues = createValuesString(
5021             m_pCapability->supported_iso_modes,
5022             m_pCapability->supported_iso_modes_cnt,
5023             ISO_MODES_MAP,
5024             PARAM_MAP_SIZE(ISO_MODES_MAP));
5025     set(KEY_QC_SUPPORTED_ISO_MODES, isoValues);
5026     setISOValue(ISO_AUTO);
5027 
5028     // Set exposure time
5029     String8 manualExpModes(VALUE_OFF);
5030     bool expTimeSupported = false;
5031     bool manualISOSupported = false;
5032     //capability values are in nano sec, convert to milli sec for upper layers
5033     char expTimeStr[20];
5034     double min_exp_time = (double) m_pCapability->exposure_time_range[0] / 1000000.0;
5035     double max_exp_time = (double) m_pCapability->exposure_time_range[1] / 1000000.0;
5036     snprintf(expTimeStr, sizeof(expTimeStr), "%f", min_exp_time);
5037     set(KEY_QC_MIN_EXPOSURE_TIME, expTimeStr);
5038     snprintf(expTimeStr, sizeof(expTimeStr), "%f", max_exp_time);
5039     set(KEY_QC_MAX_EXPOSURE_TIME, expTimeStr);
5040     if ((min_exp_time > 0) && (max_exp_time > min_exp_time)) {
5041         manualExpModes.append(",");
5042         manualExpModes.append(KEY_QC_EXP_TIME_PRIORITY);
5043         expTimeSupported = true;
5044     }
5045     CDBG_HIGH("%s, Exposure time min %f ms, max %f ms", __func__,
5046             min_exp_time, max_exp_time);
5047 
5048     // Set iso
5049     set(KEY_QC_MIN_ISO, m_pCapability->sensitivity_range.min_sensitivity);
5050     set(KEY_QC_MAX_ISO, m_pCapability->sensitivity_range.max_sensitivity);
5051     CDBG_HIGH("%s, ISO min %d, max %d", __func__,
5052             m_pCapability->sensitivity_range.min_sensitivity,
5053             m_pCapability->sensitivity_range.max_sensitivity);
5054     if ((m_pCapability->sensitivity_range.min_sensitivity > 0) &&
5055             (m_pCapability->sensitivity_range.max_sensitivity >
5056                     m_pCapability->sensitivity_range.min_sensitivity)) {
5057         manualExpModes.append(",");
5058         manualExpModes.append(KEY_QC_ISO_PRIORITY);
5059         manualISOSupported = true;
5060     }
5061     if (expTimeSupported && manualISOSupported) {
5062         manualExpModes.append(",");
5063         manualExpModes.append(KEY_QC_USER_SETTING);
5064     }
5065     //finally set supported manual exposure modes
5066     set(KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES, manualExpModes.string());
5067 
5068     // Set HFR
5069     String8 hfrValues = createHfrValuesString(
5070             m_pCapability->hfr_tbl,
5071             m_pCapability->hfr_tbl_cnt,
5072             HFR_MODES_MAP,
5073             PARAM_MAP_SIZE(HFR_MODES_MAP));
5074     set(KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, hfrValues.string());
5075     set(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, "off");
5076     set(KEY_QC_VIDEO_HIGH_FRAME_RATE, "off");
5077     String8 hfrSizeValues = createHfrSizesString(
5078             m_pCapability->hfr_tbl,
5079             m_pCapability->hfr_tbl_cnt);
5080     set(KEY_QC_SUPPORTED_HFR_SIZES, hfrSizeValues.string());
5081     CDBG("HFR values %s HFR Sizes = %s", hfrValues.string(), hfrSizeValues.string());
5082     setHighFrameRate(CAM_HFR_MODE_OFF);
5083 
5084     // Set Focus algorithms
5085     String8 focusAlgoValues = createValuesString(
5086             m_pCapability->supported_focus_algos,
5087             m_pCapability->supported_focus_algos_cnt,
5088             FOCUS_ALGO_MAP,
5089             PARAM_MAP_SIZE(FOCUS_ALGO_MAP));
5090     set(KEY_QC_SUPPORTED_FOCUS_ALGOS, focusAlgoValues);
5091     setSelectableZoneAf(FOCUS_ALGO_AUTO);
5092 
5093     // Set Zoom Ratios
5094     if (m_pCapability->zoom_supported > 0) {
5095         String8 zoomRatioValues = createZoomRatioValuesString(
5096                 m_pCapability->zoom_ratio_tbl,
5097                 m_pCapability->zoom_ratio_tbl_cnt);
5098         set(KEY_ZOOM_RATIOS, zoomRatioValues);
5099         set(KEY_MAX_ZOOM, (int)(m_pCapability->zoom_ratio_tbl_cnt - 1));
5100         setZoom(0);
5101     }
5102 
5103     // Set Bracketing/HDR
5104     char prop[PROPERTY_VALUE_MAX];
5105     memset(prop, 0, sizeof(prop));
5106     property_get("persist.capture.burst.exposures", prop, "");
5107     if (strlen(prop) > 0) {
5108         set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
5109     }
5110     String8 bracketingValues = createValuesStringFromMap(
5111             BRACKETING_MODES_MAP,
5112             PARAM_MAP_SIZE(BRACKETING_MODES_MAP));
5113     set(KEY_QC_SUPPORTED_AE_BRACKET_MODES, bracketingValues);
5114     setAEBracket(AE_BRACKET_OFF);
5115 
5116     //Set AF Bracketing.
5117     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5118         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5119                 ((m_pCapability->qcom_supported_feature_mask &
5120                         CAM_QCOM_FEATURE_UBIFOCUS) > 0)) {
5121             String8 afBracketingValues = createValuesStringFromMap(
5122                     AF_BRACKETING_MODES_MAP,
5123                     PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP));
5124             set(KEY_QC_SUPPORTED_AF_BRACKET_MODES, afBracketingValues);
5125             setAFBracket(AF_BRACKET_OFF);
5126             break;
5127          }
5128     }
5129 
5130     //Set Refocus.
5131     //Re-use ubifocus flag for now.
5132     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5133         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5134                 (m_pCapability->qcom_supported_feature_mask &
5135                     CAM_QCOM_FEATURE_REFOCUS) > 0) {
5136             String8 reFocusValues = createValuesStringFromMap(
5137                     RE_FOCUS_MODES_MAP,
5138                     PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP));
5139             set(KEY_QC_SUPPORTED_RE_FOCUS_MODES, reFocusValues);
5140             setReFocus(RE_FOCUS_OFF);
5141         }
5142     }
5143 
5144     //Set Chroma Flash.
5145     if ((m_pCapability->supported_flash_modes_cnt > 0) &&
5146             (m_pCapability->qcom_supported_feature_mask &
5147             CAM_QCOM_FEATURE_CHROMA_FLASH) > 0) {
5148         String8 chromaFlashValues = createValuesStringFromMap(
5149                 CHROMA_FLASH_MODES_MAP,
5150                 PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP));
5151         set(KEY_QC_SUPPORTED_CHROMA_FLASH_MODES, chromaFlashValues);
5152         setChromaFlash(CHROMA_FLASH_OFF);
5153     }
5154 
5155     //Set Opti Zoom.
5156     if (m_pCapability->zoom_supported &&
5157             (m_pCapability->qcom_supported_feature_mask &
5158             CAM_QCOM_FEATURE_OPTIZOOM) > 0){
5159         String8 optiZoomValues = createValuesStringFromMap(
5160                 OPTI_ZOOM_MODES_MAP,
5161                 PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP));
5162         set(KEY_QC_SUPPORTED_OPTI_ZOOM_MODES, optiZoomValues);
5163         setOptiZoom(OPTI_ZOOM_OFF);
5164     }
5165 
5166     //Set HDR Type
5167     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
5168             (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
5169     if (supported_hdr_modes) {
5170         if (CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) {
5171             String8 hdrModeValues;
5172             hdrModeValues.append(HDR_MODE_SENSOR);
5173             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5174             setHDRMode(HDR_MODE_SENSOR);
5175         } else if (CAM_QCOM_FEATURE_HDR == supported_hdr_modes) {
5176             String8 hdrModeValues;
5177             hdrModeValues.append(HDR_MODE_MULTI_FRAME);
5178             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5179             setHDRMode(HDR_MODE_MULTI_FRAME);
5180         } else {
5181             String8 hdrModeValues = createValuesStringFromMap(
5182                     HDR_MODES_MAP,
5183                     PARAM_MAP_SIZE(HDR_MODES_MAP));
5184             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5185             setHDRMode(HDR_MODE_MULTI_FRAME);
5186         }
5187     }
5188 
5189     //Set HDR need 1x
5190     String8 hdrNeed1xValues;
5191     if (!m_bHDRModeSensor) {
5192         hdrNeed1xValues = createValuesStringFromMap(TRUE_FALSE_MODES_MAP,
5193                 PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP));
5194         setHDRNeed1x(VALUE_TRUE);
5195     } else {
5196         hdrNeed1xValues.append(VALUE_FALSE);
5197         setHDRNeed1x(VALUE_FALSE);
5198     }
5199     set(KEY_QC_SUPPORTED_HDR_NEED_1X, hdrNeed1xValues);
5200 
5201     //Set True Portrait
5202     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_TRUEPORTRAIT) > 0) {
5203         String8 truePortraitValues = createValuesStringFromMap(
5204                 TRUE_PORTRAIT_MODES_MAP,
5205                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP));
5206         set(KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES, truePortraitValues);
5207     }
5208 
5209     // Set Denoise
5210     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) > 0){
5211     String8 denoiseValues = createValuesStringFromMap(
5212         DENOISE_ON_OFF_MODES_MAP, PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP));
5213     set(KEY_QC_SUPPORTED_DENOISE, denoiseValues.string());
5214 #ifdef DEFAULT_DENOISE_MODE_ON
5215     setWaveletDenoise(DENOISE_ON);
5216 #else
5217     setWaveletDenoise(DENOISE_OFF);
5218 #endif
5219     }
5220 
5221     // Set feature enable/disable
5222     String8 enableDisableValues = createValuesStringFromMap(
5223             ENABLE_DISABLE_MODES_MAP, PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP));
5224 
5225     // Set Lens Shading
5226     set(KEY_QC_SUPPORTED_LENSSHADE_MODES, enableDisableValues);
5227     setLensShadeValue(VALUE_ENABLE);
5228     // Set MCE
5229     set(KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES, enableDisableValues);
5230     setMCEValue(VALUE_ENABLE);
5231 
5232     // Set DIS
5233     set(KEY_QC_SUPPORTED_DIS_MODES, enableDisableValues);
5234     setDISValue(VALUE_DISABLE);
5235 
5236     // Set Histogram
5237     set(KEY_QC_SUPPORTED_HISTOGRAM_MODES,
5238         m_pCapability->histogram_supported ? enableDisableValues : "");
5239     set(KEY_QC_HISTOGRAM, VALUE_DISABLE);
5240 
5241     //Set Red Eye Reduction
5242     set(KEY_QC_SUPPORTED_REDEYE_REDUCTION, enableDisableValues);
5243     setRedeyeReduction(VALUE_DISABLE);
5244 
5245     //Set SkinTone Enhancement
5246     set(KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, enableDisableValues);
5247 
5248     // Set feature on/off
5249     String8 onOffValues = createValuesStringFromMap(
5250             ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5251 
5252     //Set See more (LLVD)
5253     if (m_pCapability->qcom_supported_feature_mask &
5254             CAM_QCOM_FEATURE_LLVD) {
5255         set(KEY_QC_SUPPORTED_SEE_MORE_MODES, onOffValues);
5256         setSeeMore(VALUE_OFF);
5257     }
5258 
5259     //Set Still more
5260     if (m_pCapability->qcom_supported_feature_mask &
5261             CAM_QCOM_FEATURE_STILLMORE) {
5262         String8 stillMoreValues = createValuesStringFromMap(
5263                 STILL_MORE_MODES_MAP,
5264                 PARAM_MAP_SIZE(STILL_MORE_MODES_MAP));
5265         set(KEY_QC_SUPPORTED_STILL_MORE_MODES, stillMoreValues);
5266         setStillMore(STILL_MORE_OFF);
5267     }
5268 
5269     //Set Scene Detection
5270     set(KEY_QC_SUPPORTED_SCENE_DETECT, onOffValues);
5271     setSceneDetect(VALUE_OFF);
5272     m_bHDREnabled = false;
5273     m_bHDR1xFrameEnabled = true;
5274 
5275     m_bHDRThumbnailProcessNeeded = false;
5276     m_bHDR1xExtraBufferNeeded = true;
5277     for (uint32_t i=0; i<m_pCapability->hdr_bracketing_setting.num_frames; i++) {
5278         if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[i]) {
5279             m_bHDR1xExtraBufferNeeded = false;
5280             break;
5281         }
5282     }
5283 
5284     // Set HDR output scaling
5285     char value[PROPERTY_VALUE_MAX];
5286 
5287     property_get("persist.camera.hdr.outcrop", value, VALUE_DISABLE);
5288     if (strncmp(VALUE_ENABLE, value, sizeof(VALUE_ENABLE))) {
5289       m_bHDROutputCropEnabled = false;
5290     } else {
5291       m_bHDROutputCropEnabled = true;
5292     }
5293 
5294     //Set Face Detection
5295     set(KEY_QC_SUPPORTED_FACE_DETECTION, onOffValues);
5296     set(KEY_QC_FACE_DETECTION, VALUE_OFF);
5297 
5298     //Set Face Recognition
5299     //set(KEY_QC_SUPPORTED_FACE_RECOGNITION, onOffValues);
5300     //set(KEY_QC_FACE_RECOGNITION, VALUE_OFF);
5301 
5302     //Set ZSL
5303     set(KEY_QC_SUPPORTED_ZSL_MODES, onOffValues);
5304 #ifdef DEFAULT_ZSL_MODE_ON
5305     set(KEY_QC_ZSL, VALUE_ON);
5306     m_bZslMode = true;
5307 #else
5308     set(KEY_QC_ZSL, VALUE_OFF);
5309     m_bZslMode = false;
5310 #endif
5311 
5312     // Check if zsl mode property is enabled.
5313     // If yes, force the camera to be in zsl mode
5314     memset(value, 0x00, PROPERTY_VALUE_MAX);
5315     property_get("persist.camera.zsl.mode", value, "0");
5316     int32_t zsl_mode = atoi(value);
5317     if(zsl_mode == 1) {
5318         CDBG_HIGH("%s: %d: Forcing Camera to ZSL mode ", __func__, __LINE__);
5319         set(KEY_QC_ZSL, VALUE_ON);
5320         m_bForceZslMode = true;
5321         m_bZslMode = true;
5322     }
5323     m_bZslMode_new = m_bZslMode;
5324 
5325     set(KEY_QC_SCENE_SELECTION, VALUE_DISABLE);
5326 
5327     // Rdi mode
5328     set(KEY_QC_SUPPORTED_RDI_MODES, enableDisableValues);
5329     setRdiMode(VALUE_DISABLE);
5330 
5331     // Secure mode
5332     set(KEY_QC_SUPPORTED_SECURE_MODES, enableDisableValues);
5333     setSecureMode(VALUE_DISABLE);
5334 
5335     //Set video HDR
5336     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_VIDEO_HDR) > 0) {
5337         set(KEY_QC_SUPPORTED_VIDEO_HDR_MODES, onOffValues);
5338         set(KEY_QC_VIDEO_HDR, VALUE_OFF);
5339     }
5340 
5341     //Set HW Sensor Snapshot HDR
5342     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_SENSOR_HDR)> 0) {
5343         set(KEY_QC_SUPPORTED_SENSOR_HDR_MODES, onOffValues);
5344         set(KEY_QC_SENSOR_HDR, VALUE_OFF);
5345         m_bSensorHDREnabled = false;
5346     }
5347 
5348     // Set VT TimeStamp
5349     set(KEY_QC_VT_ENABLE, VALUE_DISABLE);
5350     //Set Touch AF/AEC
5351     String8 touchValues = createValuesStringFromMap(
5352             TOUCH_AF_AEC_MODES_MAP, PARAM_MAP_SIZE(TOUCH_AF_AEC_MODES_MAP));
5353 
5354     set(KEY_QC_SUPPORTED_TOUCH_AF_AEC, touchValues);
5355     set(KEY_QC_TOUCH_AF_AEC, TOUCH_AF_AEC_OFF);
5356 
5357     //set flip mode
5358     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) > 0) {
5359         String8 flipModes = createValuesStringFromMap(
5360                 FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP));
5361         set(KEY_QC_SUPPORTED_FLIP_MODES, flipModes);
5362         set(KEY_QC_PREVIEW_FLIP, FLIP_MODE_OFF);
5363         set(KEY_QC_VIDEO_FLIP, FLIP_MODE_OFF);
5364         set(KEY_QC_SNAPSHOT_PICTURE_FLIP, FLIP_MODE_OFF);
5365     }
5366 
5367     // Set default Auto Exposure lock value
5368     setAecLock(VALUE_FALSE);
5369 
5370     // Set default AWB_LOCK lock value
5371     setAwbLock(VALUE_FALSE);
5372 
5373     // Set default Camera mode
5374     set(KEY_QC_CAMERA_MODE, 0);
5375 
5376     // Add support for internal preview restart
5377     set(KEY_INTERNAL_PERVIEW_RESTART, VALUE_TRUE);
5378     // Set default burst number
5379     set(KEY_QC_SNAPSHOT_BURST_NUM, 0);
5380     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, 0);
5381 
5382     //Get RAM size and disable features which are memory rich
5383     struct sysinfo info;
5384     sysinfo(&info);
5385 
5386     CDBG_HIGH("%s: totalram = %ld, freeram = %ld ", __func__, info.totalram,
5387         info.freeram);
5388     if (info.totalram > TOTAL_RAM_SIZE_512MB) {
5389         set(KEY_QC_LONGSHOT_SUPPORTED, VALUE_TRUE);
5390         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_TRUE);
5391     } else {
5392         set(KEY_QC_LONGSHOT_SUPPORTED, VALUE_FALSE);
5393         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_FALSE);
5394     }
5395 
5396     setOfflineRAW();
5397     memset(mStreamPpMask, 0, sizeof(uint32_t)*CAM_STREAM_TYPE_MAX);
5398 
5399     int32_t rc = commitParameters();
5400     if (rc == NO_ERROR) {
5401         rc = setNumOfSnapshot();
5402     }
5403 
5404     //Set Video Rotation
5405     String8 videoRotationValues = createValuesStringFromMap(VIDEO_ROTATION_MODES_MAP,
5406             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP));
5407 
5408     set(KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES, videoRotationValues.string());
5409     set(KEY_QC_VIDEO_ROTATION, VIDEO_ROTATION_0);
5410     return rc;
5411 }
5412 
5413 /*===========================================================================
5414  * FUNCTION   : init
5415  *
5416  * DESCRIPTION: initialize parameter obj
5417  *
5418  * PARAMETERS :
5419  *   @capabilities  : ptr to camera capabilities
5420  *   @mmops         : ptr to memory ops table for mapping/unmapping
5421  *   @adjustFPS     : object reference for additional (possibly thermal)
5422  *                    framerate adjustment
5423  *
5424  * RETURN     : int32_t type of status
5425  *              NO_ERROR  -- success
5426  *              none-zero failure code
5427  *==========================================================================*/
init(cam_capability_t * capabilities,mm_camera_vtbl_t * mmOps,QCameraAdjustFPS * adjustFPS)5428 int32_t QCameraParameters::init(cam_capability_t *capabilities,
5429         mm_camera_vtbl_t *mmOps, QCameraAdjustFPS *adjustFPS)
5430 {
5431     int32_t rc = NO_ERROR;
5432 
5433     m_pCapability = capabilities;
5434     m_pCamOpsTbl = mmOps;
5435     m_AdjustFPS = adjustFPS;
5436 
5437     //Allocate Set Param Buffer
5438     m_pParamHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
5439     rc = m_pParamHeap->allocate(1, sizeof(parm_buffer_t), NON_SECURE);
5440     if(rc != OK) {
5441         rc = NO_MEMORY;
5442         ALOGE("Failed to allocate SETPARM Heap memory");
5443         goto TRANS_INIT_ERROR1;
5444     }
5445 
5446     //Map memory for parameters buffer
5447     rc = m_pCamOpsTbl->ops->map_buf(m_pCamOpsTbl->camera_handle,
5448                              CAM_MAPPING_BUF_TYPE_PARM_BUF,
5449                              m_pParamHeap->getFd(0),
5450                              sizeof(parm_buffer_t));
5451     if(rc < 0) {
5452         ALOGE("%s:failed to map SETPARM buffer",__func__);
5453         rc = FAILED_TRANSACTION;
5454         goto TRANS_INIT_ERROR2;
5455     }
5456     m_pParamBuf = (parm_buffer_t*) DATA_PTR(m_pParamHeap,0);
5457 
5458     initDefaultParameters();
5459 
5460     m_bInited = true;
5461 
5462     goto TRANS_INIT_DONE;
5463 
5464 TRANS_INIT_ERROR2:
5465     m_pParamHeap->deallocate();
5466 
5467 TRANS_INIT_ERROR1:
5468     delete m_pParamHeap;
5469     m_pParamHeap = NULL;
5470 
5471 TRANS_INIT_DONE:
5472     return rc;
5473 }
5474 
5475 /*===========================================================================
5476  * FUNCTION   : deinit
5477  *
5478  * DESCRIPTION: deinitialize
5479  *
5480  * PARAMETERS : none
5481  *
5482  * RETURN     : none
5483  *==========================================================================*/
deinit()5484 void QCameraParameters::deinit()
5485 {
5486     if (!m_bInited) {
5487         return;
5488     }
5489 
5490     //clear all entries in the map
5491     String8 emptyStr;
5492     QCameraParameters::unflatten(emptyStr);
5493 
5494     if (NULL != m_pCamOpsTbl) {
5495         m_pCamOpsTbl->ops->unmap_buf(
5496                              m_pCamOpsTbl->camera_handle,
5497                              CAM_MAPPING_BUF_TYPE_PARM_BUF);
5498         m_pCamOpsTbl = NULL;
5499     }
5500     m_pCapability = NULL;
5501     if (NULL != m_pParamHeap) {
5502         m_pParamHeap->deallocate();
5503         delete m_pParamHeap;
5504         m_pParamHeap = NULL;
5505         m_pParamBuf = NULL;
5506     }
5507 
5508     m_AdjustFPS = NULL;
5509 
5510     m_tempMap.clear();
5511 
5512     m_bInited = false;
5513 }
5514 
5515 /*===========================================================================
5516  * FUNCTION   : parse_pair
5517  *
5518  * DESCRIPTION: helper function to parse string like "640x480" or "10000,20000"
5519  *
5520  * PARAMETERS :
5521  *   @str     : input string to be parse
5522  *   @first   : [output] first value of the pair
5523  *   @second  : [output]  second value of the pair
5524  *   @delim   : [input] delimeter to seperate the pair
5525  *   @endptr  : [output] ptr to the end of the pair string
5526  *
5527  * RETURN     : int32_t type of status
5528  *              NO_ERROR  -- success
5529  *              none-zero failure code
5530  *==========================================================================*/
parse_pair(const char * str,int * first,int * second,char delim,char ** endptr=NULL)5531 int32_t QCameraParameters::parse_pair(const char *str,
5532                                       int *first,
5533                                       int *second,
5534                                       char delim,
5535                                       char **endptr = NULL)
5536 {
5537     // Find the first integer.
5538     char *end;
5539     int w = (int)strtol(str, &end, 10);
5540     // If a delimeter does not immediately follow, give up.
5541     if (*end != delim) {
5542         ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
5543         return BAD_VALUE;
5544     }
5545 
5546     // Find the second integer, immediately after the delimeter.
5547     int h = (int)strtol(end+1, &end, 10);
5548 
5549     *first = w;
5550     *second = h;
5551 
5552     if (endptr) {
5553         *endptr = end;
5554     }
5555 
5556     return NO_ERROR;
5557 }
5558 
5559 /*===========================================================================
5560  * FUNCTION   : parseSizesList
5561  *
5562  * DESCRIPTION: helper function to parse string containing sizes
5563  *
5564  * PARAMETERS :
5565  *   @sizesStr: [input] input string to be parse
5566  *   @sizes   : [output] reference to store parsed sizes
5567  *
5568  * RETURN     : none
5569  *==========================================================================*/
parseSizesList(const char * sizesStr,Vector<Size> & sizes)5570 void QCameraParameters::parseSizesList(const char *sizesStr, Vector<Size> &sizes)
5571 {
5572     if (sizesStr == 0) {
5573         return;
5574     }
5575 
5576     char *sizeStartPtr = (char *)sizesStr;
5577 
5578     while (true) {
5579         int width, height;
5580         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
5581                                  &sizeStartPtr);
5582         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
5583             ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
5584             return;
5585         }
5586         sizes.push(Size(width, height));
5587 
5588         if (*sizeStartPtr == '\0') {
5589             return;
5590         }
5591         sizeStartPtr++;
5592     }
5593 }
5594 
5595 /*===========================================================================
5596  * FUNCTION   : getSupportedHfrSizes
5597  *
5598  * DESCRIPTION: return supported HFR sizes
5599  *
5600  * PARAMETERS :
5601  *   @sizes  : [output] reference to a vector storing supported HFR sizes
5602  *
5603  * RETURN     : none
5604  *==========================================================================*/
getSupportedHfrSizes(Vector<Size> & sizes)5605 void QCameraParameters::getSupportedHfrSizes(Vector<Size> &sizes)
5606 {
5607     const char *hfrSizesStr = get(KEY_QC_SUPPORTED_HFR_SIZES);
5608     parseSizesList(hfrSizesStr, sizes);
5609 }
5610 
5611 /*===========================================================================
5612  * FUNCTION   : adjustPreviewFpsRanges
5613  *
5614  * DESCRIPTION: adjust preview FPS ranges
5615  *              according to external events
5616  *
5617  * PARAMETERS :
5618  *   @minFPS  : min FPS value
5619  *   @maxFPS  : max FPS value
5620  *
5621  * RETURN     : int32_t type of status
5622  *              NO_ERROR  -- success
5623  *              none-zero failure code
5624  *==========================================================================*/
adjustPreviewFpsRange(cam_fps_range_t * fpsRange)5625 int32_t QCameraParameters::adjustPreviewFpsRange(cam_fps_range_t *fpsRange)
5626 {
5627     if ( fpsRange == NULL ) {
5628         return BAD_VALUE;
5629     }
5630 
5631     if ( m_pParamBuf == NULL ) {
5632         return NO_INIT;
5633     }
5634 
5635     int32_t rc = initBatchUpdate(m_pParamBuf);
5636     if ( rc != NO_ERROR ) {
5637         ALOGE("%s:Failed to initialize group update table", __func__);
5638         return rc;
5639     }
5640 
5641     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, *fpsRange)) {
5642         ALOGE("%s: Parameters batch failed",__func__);
5643         return BAD_VALUE;
5644     }
5645 
5646     rc = commitSetBatch();
5647     if ( rc != NO_ERROR ) {
5648         ALOGE("%s:Failed to commit batch parameters", __func__);
5649         return rc;
5650     }
5651 
5652     return rc;
5653 }
5654 
5655 /*===========================================================================
5656  * FUNCTION   : setPreviewFpsRanges
5657  *
5658  * DESCRIPTION: set preview FPS ranges
5659  *
5660  * PARAMETERS :
5661  *   @minFPS  : min FPS value
5662  *   @maxFPS  : max FPS value
5663  *
5664  * RETURN     : int32_t type of status
5665  *              NO_ERROR  -- success
5666  *              none-zero failure code
5667  *==========================================================================*/
setPreviewFpsRange(int min_fps,int max_fps,int vid_min_fps,int vid_max_fps)5668 int32_t QCameraParameters::setPreviewFpsRange(int min_fps,
5669         int max_fps, int vid_min_fps,int vid_max_fps)
5670 {
5671     char str[32];
5672     char value[PROPERTY_VALUE_MAX];
5673     int fixedFpsValue;
5674     /*This property get value should be the fps that user needs*/
5675     property_get("persist.debug.set.fixedfps", value, "0");
5676     fixedFpsValue = atoi(value);
5677 
5678     CDBG("%s: E minFps = %d, maxFps = %d , vid minFps = %d, vid maxFps = %d",
5679                 __func__, min_fps, max_fps, vid_min_fps, vid_max_fps);
5680 
5681     if(fixedFpsValue != 0) {
5682       min_fps = (int)fixedFpsValue*1000;
5683       max_fps = (int)fixedFpsValue*1000;
5684     }
5685     snprintf(str, sizeof(str), "%d,%d", min_fps, max_fps);
5686     CDBG_HIGH("%s: Setting preview fps range %s", __func__, str);
5687     updateParamEntry(KEY_PREVIEW_FPS_RANGE, str);
5688     cam_fps_range_t fps_range;
5689     memset(&fps_range, 0x00, sizeof(cam_fps_range_t));
5690     fps_range.min_fps = (float)min_fps / 1000.0f;
5691     fps_range.max_fps = (float)max_fps / 1000.0f;
5692     fps_range.video_min_fps = (float)vid_min_fps / 1000.0f;
5693     fps_range.video_max_fps = (float)vid_max_fps / 1000.0f;
5694 
5695     CDBG_HIGH("%s: Updated: minFps = %d, maxFps = %d ,"
5696             " vid minFps = %d, vid maxFps = %d",
5697             __func__, min_fps, max_fps, vid_min_fps, vid_max_fps);
5698 
5699     if ( NULL != m_AdjustFPS ) {
5700         m_AdjustFPS->recalcFPSRange(min_fps, max_fps, fps_range);
5701         CDBG_HIGH("%s: Thermal adjusted Preview fps range %3.2f,%3.2f, %3.2f, %3.2f",
5702               __func__, fps_range.min_fps, fps_range.max_fps,
5703               fps_range.video_min_fps, fps_range.video_max_fps);
5704     }
5705 
5706     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, fps_range)) {
5707         return BAD_VALUE;
5708     }
5709 
5710     return NO_ERROR;
5711 }
5712 
5713 
5714 
5715 /*===========================================================================
5716  * FUNCTION   : setAutoExposure
5717  *
5718  * DESCRIPTION: set auto exposure
5719  *
5720  * PARAMETERS :
5721  *   @autoExp : auto exposure value string
5722  *
5723  * RETURN     : int32_t type of status
5724  *              NO_ERROR  -- success
5725  *              none-zero failure code
5726  *==========================================================================*/
setAutoExposure(const char * autoExp)5727 int32_t QCameraParameters::setAutoExposure(const char *autoExp)
5728 {
5729     if (autoExp != NULL) {
5730         int32_t value = lookupAttr(AUTO_EXPOSURE_MAP, PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP), autoExp);
5731         if (value != NAME_NOT_FOUND) {
5732             CDBG_HIGH("%s: Setting auto exposure %s", __func__, autoExp);
5733             updateParamEntry(KEY_QC_AUTO_EXPOSURE, autoExp);
5734             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ALGO_TYPE, value)) {
5735                 return BAD_VALUE;
5736             }
5737             return NO_ERROR;
5738         }
5739     }
5740     ALOGE("Invalid auto exposure value: %s", (autoExp == NULL) ? "NULL" : autoExp);
5741     return BAD_VALUE;
5742 }
5743 
5744 /*===========================================================================
5745  * FUNCTION   : setEffect
5746  *
5747  * DESCRIPTION: set effect
5748  *
5749  * PARAMETERS :
5750  *   @effect  : effect value string
5751  *
5752  * RETURN     : int32_t type of status
5753  *              NO_ERROR  -- success
5754  *              none-zero failure code
5755  *==========================================================================*/
setEffect(const char * effect)5756 int32_t QCameraParameters::setEffect(const char *effect)
5757 {
5758     if (effect != NULL) {
5759         int32_t value = lookupAttr(EFFECT_MODES_MAP, PARAM_MAP_SIZE(EFFECT_MODES_MAP), effect);
5760         if (value != NAME_NOT_FOUND) {
5761             CDBG_HIGH("%s: Setting effect %s", __func__, effect);
5762             updateParamEntry(KEY_EFFECT, effect);
5763             uint8_t prmEffect = static_cast<uint8_t>(value);
5764             mParmEffect = prmEffect;
5765             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EFFECT, prmEffect)) {
5766                 return BAD_VALUE;
5767             }
5768             return NO_ERROR;
5769         }
5770     }
5771     ALOGE("Invalid effect value: %s", (effect == NULL) ? "NULL" : effect);
5772     return BAD_VALUE;
5773 }
5774 
5775 /*===========================================================================
5776  * FUNCTION   : setBrightness
5777  *
5778  * DESCRIPTION: set brightness control value
5779  *
5780  * PARAMETERS :
5781  *   @brightness  : brightness control value
5782  *
5783  * RETURN     : int32_t type of status
5784  *              NO_ERROR  -- success
5785  *              none-zero failure code
5786  *==========================================================================*/
setBrightness(int brightness)5787 int32_t QCameraParameters::setBrightness(int brightness)
5788 {
5789     char val[16];
5790     snprintf(val, sizeof(val), "%d", brightness);
5791     updateParamEntry(KEY_QC_BRIGHTNESS, val);
5792 
5793     CDBG_HIGH("%s: Setting brightness %s", __func__, val);
5794     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BRIGHTNESS, brightness)) {
5795         return BAD_VALUE;
5796     }
5797 
5798     return NO_ERROR;
5799 }
5800 
5801 /*===========================================================================
5802  * FUNCTION   : setFocusMode
5803  *
5804  * DESCRIPTION: set focus mode
5805  *
5806  * PARAMETERS :
5807  *   @focusMode  : focus mode value string
5808  *
5809  * RETURN     : int32_t type of status
5810  *              NO_ERROR  -- success
5811  *              none-zero failure code
5812  *==========================================================================*/
setFocusMode(const char * focusMode)5813 int32_t QCameraParameters::setFocusMode(const char *focusMode)
5814 {
5815     if (focusMode != NULL) {
5816         int32_t value = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focusMode);
5817         if (value != NAME_NOT_FOUND) {
5818             int32_t rc = NO_ERROR;
5819             CDBG_HIGH("%s: Setting focus mode %s", __func__, focusMode);
5820             mFocusMode = (cam_focus_mode_type)value;
5821 
5822             updateParamEntry(KEY_FOCUS_MODE, focusMode);
5823             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
5824                     CAM_INTF_PARM_FOCUS_MODE, (uint8_t)value)) {
5825                 rc = BAD_VALUE;
5826             }
5827             if (strcmp(focusMode,"infinity")==0){
5828                 set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
5829             }
5830             return rc;
5831         }
5832     }
5833     ALOGE("Invalid focus mode value: %s", (focusMode == NULL) ? "NULL" : focusMode);
5834     return BAD_VALUE;
5835 }
5836 
5837 /*===========================================================================
5838  * FUNCTION   : setFocusPosition
5839  *
5840  * DESCRIPTION: set focus position
5841  *
5842  * PARAMETERS :
5843  *   @typeStr : focus position type, index or dac_code
5844  *   @posStr : focus positon.
5845  *
5846  * RETURN     : int32_t type of status
5847  *              NO_ERROR  -- success
5848  *              none-zero failure code
5849  *==========================================================================*/
setFocusPosition(const char * typeStr,const char * posStr)5850 int32_t  QCameraParameters::setFocusPosition(const char *typeStr, const char *posStr)
5851 {
5852     CDBG_HIGH("%s, type:%s, pos: %s", __func__, typeStr, posStr);
5853     int32_t type = atoi(typeStr);
5854     float pos = (float) atof(posStr);
5855 
5856     if ((type >= CAM_MANUAL_FOCUS_MODE_INDEX) &&
5857             (type < CAM_MANUAL_FOCUS_MODE_MAX)) {
5858         // get max and min focus position from m_pCapability
5859         int32_t minFocusPos = (int32_t) m_pCapability->min_focus_pos[type];
5860         int32_t maxFocusPos = (int32_t) m_pCapability->max_focus_pos[type];
5861         CDBG_HIGH("%s, focusPos min: %d, max: %d", __func__, minFocusPos, maxFocusPos);
5862 
5863         if (pos >= minFocusPos && pos <= maxFocusPos) {
5864             updateParamEntry(KEY_QC_MANUAL_FOCUS_POS_TYPE, typeStr);
5865             updateParamEntry(KEY_QC_MANUAL_FOCUS_POSITION, posStr);
5866 
5867             cam_manual_focus_parm_t manual_focus;
5868             manual_focus.flag = (cam_manual_focus_mode_type)type;
5869             if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_DIOPTER) {
5870                 manual_focus.af_manual_diopter = pos;
5871             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_RATIO) {
5872                 manual_focus.af_manual_lens_position_ratio = (int32_t) pos;
5873             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_INDEX) {
5874                 manual_focus.af_manual_lens_position_index = (int32_t) pos;
5875             } else {
5876                 manual_focus.af_manual_lens_position_dac = (int32_t) pos;
5877             }
5878 
5879             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MANUAL_FOCUS_POS,
5880                     manual_focus)) {
5881                 return BAD_VALUE;
5882             }
5883             return NO_ERROR;
5884         }
5885     }
5886 
5887     ALOGE("%s, invalid params, type:%d, pos: %f", __func__, type, pos);
5888     return BAD_VALUE;
5889 }
5890 
5891 /*===========================================================================
5892  * FUNCTION   : updateAEInfo
5893  *
5894  * DESCRIPTION: update exposure information from metadata callback
5895  *
5896  * PARAMETERS :
5897  *   @ae_params : auto exposure params
5898  *
5899  * RETURN     : void
5900  *==========================================================================*/
updateAEInfo(cam_3a_params_t & ae_params)5901 void  QCameraParameters::updateAEInfo(cam_3a_params_t &ae_params)
5902 {
5903     const char *prevExpTime = get(KEY_QC_CURRENT_EXPOSURE_TIME);
5904     char newExpTime[15];
5905     snprintf(newExpTime, sizeof(newExpTime), "%f", ae_params.exp_time*1000.0);
5906 
5907     if (prevExpTime == NULL || strcmp(prevExpTime, newExpTime)) {
5908         CDBG("update exposure time: old: %s, new: %s", prevExpTime, newExpTime);
5909         set(KEY_QC_CURRENT_EXPOSURE_TIME, newExpTime);
5910     }
5911 
5912     int32_t prevISO = getInt(KEY_QC_CURRENT_ISO);
5913     int32_t newISO = ae_params.iso_value;
5914     if (prevISO != newISO) {
5915         CDBG("update iso: old:%d, new:%d", prevISO, newISO);
5916         set(KEY_QC_CURRENT_ISO, newISO);
5917     }
5918 }
5919 
5920 /*===========================================================================
5921  * FUNCTION   : updateCurrentFocusPosition
5922  *
5923  * DESCRIPTION: update current focus position from metadata callback
5924  *
5925  * PARAMETERS :
5926  *   @pos : current focus position
5927  *
5928  * RETURN     : void
5929  *==========================================================================*/
updateCurrentFocusPosition(cam_focus_pos_info_t & cur_pos_info)5930 void  QCameraParameters::updateCurrentFocusPosition(cam_focus_pos_info_t &cur_pos_info)
5931 {
5932     int prevScalePos = getInt(KEY_QC_FOCUS_POSITION_SCALE);
5933     int newScalePos = (int) cur_pos_info.scale;
5934     if (prevScalePos != newScalePos) {
5935         CDBG("update focus scale: old:%d, new:%d", prevScalePos, newScalePos);
5936         set(KEY_QC_FOCUS_POSITION_SCALE, newScalePos);
5937     }
5938 
5939     float prevDiopterPos = getFloat(KEY_QC_FOCUS_POSITION_DIOPTER);
5940     float newDiopterPos = cur_pos_info.diopter;
5941     if (prevDiopterPos != newDiopterPos) {
5942         CDBG("update focus diopter: old:%f, new:%f", prevDiopterPos, newDiopterPos);
5943         setFloat(KEY_QC_FOCUS_POSITION_DIOPTER, newDiopterPos);
5944     }
5945 }
5946 
5947 /*===========================================================================
5948  * FUNCTION   : setSharpness
5949  *
5950  * DESCRIPTION: set sharpness control value
5951  *
5952  * PARAMETERS :
5953  *   @sharpness  : sharpness control value
5954  *
5955  * RETURN     : int32_t type of status
5956  *              NO_ERROR  -- success
5957  *              none-zero failure code
5958  *==========================================================================*/
setSharpness(int sharpness)5959 int32_t QCameraParameters::setSharpness(int sharpness)
5960 {
5961     char val[16];
5962     snprintf(val, sizeof(val), "%d", sharpness);
5963     updateParamEntry(KEY_QC_SHARPNESS, val);
5964     CDBG_HIGH("%s: Setting sharpness %s", __func__, val);
5965     m_nSharpness = sharpness;
5966     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SHARPNESS, m_nSharpness)) {
5967         return BAD_VALUE;
5968     }
5969 
5970     return NO_ERROR;
5971 }
5972 
5973 /*===========================================================================
5974  * FUNCTION   : setSkinToneEnhancement
5975  *
5976  * DESCRIPTION: set skin tone enhancement value
5977  *
5978  * PARAMETERS :
5979  *   @sceFactore  : skin tone enhancement factor value
5980  *
5981  * RETURN     : int32_t type of status
5982  *              NO_ERROR  -- success
5983  *              none-zero failure code
5984  *==========================================================================*/
setSkinToneEnhancement(int sceFactor)5985 int32_t QCameraParameters::setSkinToneEnhancement(int sceFactor)
5986 {
5987     char val[16];
5988     snprintf(val, sizeof(val), "%d", sceFactor);
5989     updateParamEntry(KEY_QC_SCE_FACTOR, val);
5990     CDBG_HIGH("%s: Setting skintone enhancement %s", __func__, val);
5991 
5992     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SCE_FACTOR, sceFactor)) {
5993         return BAD_VALUE;
5994     }
5995 
5996     return NO_ERROR;
5997 }
5998 
5999 /*===========================================================================
6000  * FUNCTION   : setSaturation
6001  *
6002  * DESCRIPTION: set saturation control value
6003  *
6004  * PARAMETERS :
6005  *   @saturation : saturation control value
6006  *
6007  * RETURN     : int32_t type of status
6008  *              NO_ERROR  -- success
6009  *              none-zero failure code
6010  *==========================================================================*/
setSaturation(int saturation)6011 int32_t QCameraParameters::setSaturation(int saturation)
6012 {
6013     char val[16];
6014     snprintf(val, sizeof(val), "%d", saturation);
6015     updateParamEntry(KEY_QC_SATURATION, val);
6016     CDBG_HIGH("%s: Setting saturation %s", __func__, val);
6017 
6018     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SATURATION, saturation)) {
6019         return BAD_VALUE;
6020     }
6021 
6022     return NO_ERROR;
6023 }
6024 
6025 /*===========================================================================
6026  * FUNCTION   : setContrast
6027  *
6028  * DESCRIPTION: set contrast control value
6029  *
6030  * PARAMETERS :
6031  *   @contrast : contrast control value
6032  *
6033  * RETURN     : int32_t type of status
6034  *              NO_ERROR  -- success
6035  *              none-zero failure code
6036  *==========================================================================*/
setContrast(int contrast)6037 int32_t QCameraParameters::setContrast(int contrast)
6038 {
6039     char val[16];
6040     snprintf(val, sizeof(val), "%d", contrast);
6041     updateParamEntry(KEY_QC_CONTRAST, val);
6042     CDBG_HIGH("%s: Setting contrast %s", __func__, val);
6043 
6044     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CONTRAST, contrast)) {
6045         return BAD_VALUE;
6046     }
6047 
6048     return NO_ERROR;
6049 }
6050 
6051 /*===========================================================================
6052  * FUNCTION   : setSceneDetect
6053  *
6054  * DESCRIPTION: set scenen detect value
6055  *
6056  * PARAMETERS :
6057  *   @sceneDetect  : scene detect value string
6058  *
6059  * RETURN     : int32_t type of status
6060  *              NO_ERROR  -- success
6061  *              none-zero failure code
6062  *==========================================================================*/
setSceneDetect(const char * sceneDetect)6063 int32_t QCameraParameters::setSceneDetect(const char *sceneDetect)
6064 {
6065     if (sceneDetect != NULL) {
6066         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
6067                 sceneDetect);
6068         if (value != NAME_NOT_FOUND) {
6069             CDBG_HIGH("%s: Setting Scene Detect %s", __func__, sceneDetect);
6070             updateParamEntry(KEY_QC_SCENE_DETECT, sceneDetect);
6071             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ASD_ENABLE, value)) {
6072                 return BAD_VALUE;
6073             }
6074             return NO_ERROR;
6075         }
6076     }
6077     ALOGE("Invalid Scene Detect value: %s",
6078           (sceneDetect == NULL) ? "NULL" : sceneDetect);
6079     return BAD_VALUE;
6080 }
6081 
6082 /*===========================================================================
6083  * FUNCTION   : setSensorSnapshotHDR
6084  *
6085  * DESCRIPTION: set snapshot HDR value
6086  *
6087  * PARAMETERS :
6088  *   @snapshotHDR  : snapshot HDR value string
6089  *
6090  * RETURN     : int32_t type of status
6091  *              NO_ERROR  -- success
6092  *              none-zero failure code
6093  *==========================================================================*/
setSensorSnapshotHDR(const char * snapshotHDR)6094 int32_t QCameraParameters::setSensorSnapshotHDR(const char *snapshotHDR)
6095 {
6096     if (snapshotHDR != NULL) {
6097         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
6098                 snapshotHDR);
6099         if (value != NAME_NOT_FOUND) {
6100             CDBG_HIGH("%s: Setting Sensor Snapshot HDR %s", __func__, snapshotHDR);
6101             updateParamEntry(KEY_QC_SENSOR_HDR, snapshotHDR);
6102             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, value)) {
6103                 return BAD_VALUE;
6104             }
6105             return NO_ERROR;
6106         }
6107     }
6108     ALOGE("Invalid Snapshot HDR value: %s",
6109           (snapshotHDR == NULL) ? "NULL" : snapshotHDR);
6110     return BAD_VALUE;
6111 
6112 }
6113 
6114 
6115 /*===========================================================================
6116  * FUNCTION   : setVideoHDR
6117  *
6118  * DESCRIPTION: set video HDR value
6119  *
6120  * PARAMETERS :
6121  *   @videoHDR  : svideo HDR value string
6122  *
6123  * RETURN     : int32_t type of status
6124  *              NO_ERROR  -- success
6125  *              none-zero failure code
6126  *==========================================================================*/
setVideoHDR(const char * videoHDR)6127 int32_t QCameraParameters::setVideoHDR(const char *videoHDR)
6128 {
6129     if (videoHDR != NULL) {
6130         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), videoHDR);
6131         if (value != NAME_NOT_FOUND) {
6132             CDBG_HIGH("%s: Setting Video HDR %s", __func__, videoHDR);
6133             updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
6134             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VIDEO_HDR, value)) {
6135                 return BAD_VALUE;
6136             }
6137             return NO_ERROR;
6138         }
6139     }
6140     ALOGE("Invalid Video HDR value: %s",
6141           (videoHDR == NULL) ? "NULL" : videoHDR);
6142     return BAD_VALUE;
6143 }
6144 
6145 
6146 
6147 /*===========================================================================
6148  * FUNCTION   : setVtEnable
6149  *
6150  * DESCRIPTION: set vt Enable value
6151  *
6152  * PARAMETERS :
6153  *   @videoHDR  : svtEnable value string
6154  *
6155  * RETURN     : int32_t type of status
6156  *              NO_ERROR  -- success
6157  *              none-zero failure code
6158  *==========================================================================*/
setVtEnable(const char * vtEnable)6159 int32_t QCameraParameters::setVtEnable(const char *vtEnable)
6160 {
6161     if (vtEnable != NULL) {
6162         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
6163                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), vtEnable);
6164         if (value != NAME_NOT_FOUND) {
6165             CDBG_HIGH("%s: Setting Vt Enable %s", __func__, vtEnable);
6166             m_bAVTimerEnabled = true;
6167             updateParamEntry(KEY_QC_VT_ENABLE, vtEnable);
6168             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VT, value)) {
6169                 return BAD_VALUE;
6170             }
6171             return NO_ERROR;
6172         }
6173     }
6174     ALOGE("Invalid Vt Enable value: %s",
6175           (vtEnable == NULL) ? "NULL" : vtEnable);
6176     m_bAVTimerEnabled = false;
6177     return BAD_VALUE;
6178 }
6179 
6180 /*===========================================================================
6181  * FUNCTION   : setFaceRecognition
6182  *
6183  * DESCRIPTION: set face recognition value
6184  *
6185  * PARAMETERS :
6186  *   @faceRecog  : face recognition value string
6187  *   @maxFaces   : number of max faces to be detected/recognized
6188  *
6189  * RETURN     : int32_t type of status
6190  *              NO_ERROR  -- success
6191  *              none-zero failure code
6192  *==========================================================================*/
setFaceRecognition(const char * faceRecog,uint32_t maxFaces)6193 int32_t QCameraParameters::setFaceRecognition(const char *faceRecog,
6194         uint32_t maxFaces)
6195 {
6196     if (faceRecog != NULL) {
6197         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), faceRecog);
6198         if (value != NAME_NOT_FOUND) {
6199             CDBG_HIGH("%s: Setting face recognition %s", __func__, faceRecog);
6200             updateParamEntry(KEY_QC_FACE_RECOGNITION, faceRecog);
6201 
6202             uint32_t faceProcMask = m_nFaceProcMask;
6203             if (value > 0) {
6204                 faceProcMask |= CAM_FACE_PROCESS_MASK_RECOGNITION;
6205             } else {
6206                 faceProcMask &= (uint32_t)(~CAM_FACE_PROCESS_MASK_RECOGNITION);
6207             }
6208 
6209             if(m_nFaceProcMask == faceProcMask) {
6210                 CDBG_HIGH("%s: face process mask not changed, no ops here", __func__);
6211                 return NO_ERROR;
6212             }
6213             m_nFaceProcMask = faceProcMask;
6214             CDBG_HIGH("%s: FaceProcMask -> %d", __func__, m_nFaceProcMask);
6215 
6216             // set parm for face process
6217             cam_fd_set_parm_t fd_set_parm;
6218             memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
6219             fd_set_parm.fd_mode = m_nFaceProcMask;
6220             fd_set_parm.num_fd = maxFaces;
6221 
6222             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
6223                 return BAD_VALUE;
6224             }
6225             return NO_ERROR;
6226         }
6227     }
6228     ALOGE("Invalid face recognition value: %s", (faceRecog == NULL) ? "NULL" : faceRecog);
6229     return BAD_VALUE;
6230 }
6231 
6232 /*===========================================================================
6233  * FUNCTION   : setZoom
6234  *
6235  * DESCRIPTION: set zoom level
6236  *
6237  * PARAMETERS :
6238  *   @zoom_level : zoom level
6239  *
6240  * RETURN     : int32_t type of status
6241  *              NO_ERROR  -- success
6242  *              none-zero failure code
6243  *==========================================================================*/
setZoom(int zoom_level)6244 int32_t QCameraParameters::setZoom(int zoom_level)
6245 {
6246     char val[16];
6247     snprintf(val, sizeof(val), "%d", zoom_level);
6248     updateParamEntry(KEY_ZOOM, val);
6249     CDBG_HIGH("%s: zoom level: %d", __func__, zoom_level);
6250     mZoomLevel = zoom_level;
6251     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
6252         return BAD_VALUE;
6253     }
6254 
6255     return NO_ERROR;
6256 }
6257 
6258 /*===========================================================================
6259  * FUNCTION   : setISOValue
6260  *
6261  * DESCRIPTION: set ISO value
6262  *
6263  * PARAMETERS :
6264  *   @isoValue : ISO value string
6265  *
6266  * RETURN     : int32_t type of status
6267  *              NO_ERROR  -- success
6268  *              none-zero failure code
6269  *==========================================================================*/
setISOValue(const char * isoValue)6270 int32_t  QCameraParameters::setISOValue(const char *isoValue)
6271 {
6272     if (isoValue != NULL) {
6273         if (!strcmp(isoValue, ISO_MANUAL)) {
6274             CDBG("%s, iso manual mode - use continuous iso", __func__);
6275             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
6276             return NO_ERROR;
6277         }
6278         int32_t value = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), isoValue);
6279         if (value != NAME_NOT_FOUND) {
6280             CDBG_HIGH("%s: Setting ISO value %s", __func__, isoValue);
6281             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
6282             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, value)) {
6283                 return BAD_VALUE;
6284             }
6285             return NO_ERROR;
6286         }
6287     }
6288     ALOGE("Invalid ISO value: %s",
6289           (isoValue == NULL) ? "NULL" : isoValue);
6290     return BAD_VALUE;
6291 }
6292 
6293 
6294 /*===========================================================================
6295  * FUNCTION   : setContinuousISO
6296  *
6297  * DESCRIPTION: set continuous ISO value
6298  *
6299  * PARAMETERS :
6300  *   @params : ISO value parameter
6301  *
6302  * RETURN     : int32_t type of status
6303  *              NO_ERROR  -- success
6304  *              none-zero failure code
6305  *==========================================================================*/
setContinuousISO(const QCameraParameters & params)6306 int32_t  QCameraParameters::setContinuousISO(const QCameraParameters& params)
6307 {
6308     const char *iso = params.get(KEY_QC_ISO_MODE);
6309     CDBG("%s, current iso mode: %s", __func__, iso);
6310 
6311     if (iso != NULL) {
6312         if (strcmp(iso, ISO_MANUAL)) {
6313             CDBG("%s, dont set iso to back-end.", __func__);
6314             return NO_ERROR;
6315         }
6316     }
6317 
6318     const char *str = params.get(KEY_QC_CONTINUOUS_ISO);
6319     const char *prev_str = get(KEY_QC_CONTINUOUS_ISO);
6320     if (str != NULL) {
6321         if (prev_str == NULL ||
6322             strcmp(str, prev_str) != 0) {
6323             return setContinuousISO(str);
6324         }
6325     }
6326     return NO_ERROR;
6327 }
6328 
6329 /*===========================================================================
6330  * FUNCTION   : setExposureTime
6331  *
6332  * DESCRIPTION: set exposure time
6333  *
6334  * PARAMETERS :
6335  *   @expTimeStr : string of exposure time in ms
6336  *
6337  * RETURN     : int32_t type of status
6338  *              NO_ERROR  -- success
6339  *              none-zero failure code
6340  *==========================================================================*/
setExposureTime(const char * expTimeStr)6341 int32_t  QCameraParameters::setExposureTime(const char *expTimeStr)
6342 {
6343     if (expTimeStr != NULL) {
6344         double expTimeMs = atof(expTimeStr);
6345         //input is in milli seconds. Convert to nano sec for backend
6346         int64_t expTimeNs = ((int64_t)expTimeMs)*1000000L;
6347 
6348         // expTime == 0 means not to use manual exposure time.
6349         if ((0 <= expTimeNs) &&
6350                 ((expTimeNs == 0) ||
6351                 ((expTimeNs >= m_pCapability->exposure_time_range[0]) &&
6352                 (expTimeNs <= m_pCapability->exposure_time_range[1])))) {
6353             CDBG_HIGH("%s, exposure time: %f ms", __func__, expTimeMs);
6354             updateParamEntry(KEY_QC_EXPOSURE_TIME, expTimeStr);
6355             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_TIME,
6356                     (uint64_t)expTimeNs)) {
6357                 return BAD_VALUE;
6358             }
6359             return NO_ERROR;
6360         }
6361     }
6362 
6363     ALOGE("Invalid exposure time, value: %s",
6364           (expTimeStr == NULL) ? "NULL" : expTimeStr);
6365     return BAD_VALUE;
6366 }
6367 
6368 /*===========================================================================
6369  * FUNCTION   : setLongshotEnable
6370  *
6371  * DESCRIPTION: set a flag indicating longshot mode
6372  *
6373  * PARAMETERS :
6374  *   @enable  : true - Longshot enabled
6375  *              false - Longshot disabled
6376  *
6377  * RETURN     : int32_t type of status
6378  *              NO_ERROR  -- success
6379  *              none-zero failure code
6380  *==========================================================================*/
setLongshotEnable(bool enable)6381 int32_t QCameraParameters::setLongshotEnable(bool enable)
6382 {
6383     int32_t rc = NO_ERROR;
6384     int8_t value = enable ? 1 : 0;
6385 
6386     if(initBatchUpdate(m_pParamBuf) < 0 ) {
6387         ALOGE("%s:Failed to initialize group update table", __func__);
6388         return BAD_TYPE;
6389     }
6390 
6391     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LONGSHOT_ENABLE, value)) {
6392         ALOGE("%s:Failed to update table", __func__);
6393         return BAD_VALUE;
6394     }
6395 
6396     rc = commitSetBatch();
6397     if (rc != NO_ERROR) {
6398         ALOGE("%s:Failed to parameter changes", __func__);
6399         return rc;
6400     }
6401 
6402     return rc;
6403 }
6404 
6405 /*===========================================================================
6406  * FUNCTION   : setFlash
6407  *
6408  * DESCRIPTION: set flash mode
6409  *
6410  * PARAMETERS :
6411  *   @flashStr : LED flash mode value string
6412  *
6413  * RETURN     : int32_t type of status
6414  *              NO_ERROR  -- success
6415  *              none-zero failure code
6416  *==========================================================================*/
setFlash(const char * flashStr)6417 int32_t QCameraParameters::setFlash(const char *flashStr)
6418 {
6419     if (flashStr != NULL) {
6420         int32_t value = lookupAttr(FLASH_MODES_MAP, PARAM_MAP_SIZE(FLASH_MODES_MAP), flashStr);
6421         if (value != NAME_NOT_FOUND) {
6422             CDBG_HIGH("%s: Setting Flash value %s", __func__, flashStr);
6423             updateParamEntry(KEY_FLASH_MODE, flashStr);
6424             mFlashValue = value;
6425             return NO_ERROR;
6426         }
6427     }
6428     ALOGE("Invalid flash value: %s", (flashStr == NULL) ? "NULL" : flashStr);
6429     return BAD_VALUE;
6430 }
6431 
6432 /*===========================================================================
6433  * FUNCTION   : updateFlashMode
6434  *
6435  * DESCRIPTION: update flash mode
6436  *
6437  * PARAMETERS :
6438  *   @flashStr : LED flash mode value
6439  *
6440  * RETURN     : int32_t type of status
6441  *              NO_ERROR  -- success
6442  *              none-zero failure code
6443  *==========================================================================*/
updateFlashMode(cam_flash_mode_t flash_mode)6444 int32_t QCameraParameters::updateFlashMode(cam_flash_mode_t flash_mode)
6445 {
6446     int32_t rc = NO_ERROR;
6447     if (flash_mode >= CAM_FLASH_MODE_MAX) {
6448         CDBG_HIGH("%s: Error!! Invalid flash mode (%d)", __func__, flash_mode);
6449         return BAD_VALUE;
6450     }
6451     CDBG_HIGH("%s: Setting Flash mode from EZTune %d", __func__, flash_mode);
6452 
6453     const char *flash_mode_str = lookupNameByValue(FLASH_MODES_MAP,
6454             PARAM_MAP_SIZE(FLASH_MODES_MAP), flash_mode);
6455     if(initBatchUpdate(m_pParamBuf) < 0 ) {
6456         ALOGE("%s:Failed to initialize group update table", __func__);
6457         return BAD_TYPE;
6458     }
6459     rc = setFlash(flash_mode_str);
6460     if (rc != NO_ERROR) {
6461         ALOGE("%s:Failed to update Flash mode", __func__);
6462         return rc;
6463     }
6464 
6465     CDBG_HIGH("%s: Setting Flash mode %d", __func__, mFlashValue);
6466     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, mFlashValue)) {
6467         ALOGE("%s:Failed to set led mode", __func__);
6468         return BAD_VALUE;
6469     }
6470 
6471     rc = commitSetBatch();
6472     if (rc != NO_ERROR) {
6473         ALOGE("%s:Failed to commit parameters", __func__);
6474         return rc;
6475     }
6476 
6477     return NO_ERROR;
6478 }
6479 
6480 
6481 /*===========================================================================
6482  * FUNCTION   : configureFlash
6483  *
6484  * DESCRIPTION: configure Flash Bracketing.
6485  *
6486  * PARAMETERS :
6487  *    @frame_config : output configaration structure to fill in.
6488  *
6489  * RETURN     : int32_t type of status
6490  *              NO_ERROR  -- success
6491  *              none-zero failure code
6492  *==========================================================================*/
configureFlash(cam_capture_frame_config_t & frame_config)6493 int32_t QCameraParameters::configureFlash(cam_capture_frame_config_t &frame_config)
6494 {
6495     CDBG_HIGH("%s: E",__func__);
6496     int32_t rc = NO_ERROR;
6497     uint32_t i = 0;
6498 
6499     if (isChromaFlashEnabled()) {
6500 
6501         rc = setToneMapMode(false, false);
6502         if (rc != NO_ERROR) {
6503             ALOGE("%s: Failed to configure tone map", __func__);
6504             return rc;
6505         }
6506 
6507         rc = setCDSMode(CAM_CDS_MODE_OFF, false);
6508         if (rc != NO_ERROR) {
6509             ALOGE("%s: Failed to configure csd mode", __func__);
6510             return rc;
6511         }
6512 
6513         CDBG_HIGH("%s : Enable Chroma Flash capture", __func__);
6514         cam_flash_mode_t flash_mode = CAM_FLASH_MODE_OFF;
6515         frame_config.num_batch =
6516                 m_pCapability->chroma_flash_settings_need.burst_count;
6517         if (frame_config.num_batch > CAM_MAX_FLASH_BRACKETING) {
6518             frame_config.num_batch = CAM_MAX_FLASH_BRACKETING;
6519         }
6520         for (i = 0; i < frame_config.num_batch; i++) {
6521             flash_mode = (m_pCapability->chroma_flash_settings_need.flash_bracketing[i]) ?
6522                     CAM_FLASH_MODE_ON:CAM_FLASH_MODE_OFF;
6523             frame_config.configs[i].num_frames = 1;
6524             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
6525             frame_config.configs[i].flash_mode = flash_mode;
6526         }
6527     } else if (mFlashValue != CAM_FLASH_MODE_OFF) {
6528         frame_config.num_batch = 1;
6529         for (i = 0; i < frame_config.num_batch; i++) {
6530             frame_config.configs[i].num_frames = 1;
6531             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
6532             frame_config.configs[i].flash_mode =(cam_flash_mode_t)mFlashValue;
6533         }
6534     }
6535 
6536     CDBG("%s: Chroma Flash cnt = %d", __func__,frame_config.num_batch);
6537     return rc;
6538 }
6539 
6540 /*===========================================================================
6541  * FUNCTION   : configureHDRBracketing
6542  *
6543  * DESCRIPTION: configure HDR Bracketing.
6544  *
6545  * PARAMETERS :
6546  *    @frame_config : output configaration structure to fill in.
6547  *
6548  * RETURN     : int32_t type of status
6549  *              NO_ERROR  -- success
6550  *              none-zero failure code
6551  *==========================================================================*/
configureHDRBracketing(cam_capture_frame_config_t & frame_config)6552 int32_t QCameraParameters::configureHDRBracketing(cam_capture_frame_config_t &frame_config)
6553 {
6554     CDBG_HIGH("%s: E",__func__);
6555     int32_t rc = NO_ERROR;
6556     uint32_t i = 0;
6557 
6558     uint32_t hdrFrameCount = m_pCapability->hdr_bracketing_setting.num_frames;
6559     CDBG_HIGH("%s : HDR values %d, %d frame count: %u",
6560           __func__,
6561           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[0],
6562           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[1],
6563           hdrFrameCount);
6564 
6565     frame_config.num_batch = hdrFrameCount;
6566 
6567     cam_bracket_mode mode =
6568             m_pCapability->hdr_bracketing_setting.exp_val.mode;
6569     if (mode == CAM_EXP_BRACKETING_ON) {
6570         rc = setToneMapMode(false, true);
6571         if (rc != NO_ERROR) {
6572             ALOGE("%s: Failed to disable tone map during HDR", __func__);
6573         }
6574     }
6575     for (i = 0; i < frame_config.num_batch; i++) {
6576         frame_config.configs[i].num_frames = 1;
6577         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
6578         frame_config.configs[i].hdr_mode.mode = mode;
6579         frame_config.configs[i].hdr_mode.values =
6580                 m_pCapability->hdr_bracketing_setting.exp_val.values[i];
6581         CDBG("%s: exp values %d", __func__,
6582                 (int)frame_config.configs[i].hdr_mode.values);
6583     }
6584     return rc;
6585 }
6586 
6587 /*===========================================================================
6588  * FUNCTION   : configureAEBracketing
6589  *
6590  * DESCRIPTION: configure AE Bracketing.
6591  *
6592  * PARAMETERS :
6593  *    @frame_config : output configaration structure to fill in.
6594  *
6595  * RETURN     : int32_t type of status
6596  *              NO_ERROR  -- success
6597  *              none-zero failure code
6598  *==========================================================================*/
configureAEBracketing(cam_capture_frame_config_t & frame_config)6599 int32_t QCameraParameters::configureAEBracketing(cam_capture_frame_config_t &frame_config)
6600 {
6601     CDBG_HIGH("%s: E",__func__);
6602     int32_t rc = NO_ERROR;
6603     uint32_t i = 0;
6604     char exp_value[MAX_EXP_BRACKETING_LENGTH];
6605 
6606     rc = setToneMapMode(false, true);
6607     if (rc != NO_ERROR) {
6608         CDBG_HIGH("%s: Failed to disable tone map during AEBracketing", __func__);
6609     }
6610 
6611     uint32_t burstCount = 0;
6612     const char *str_val = m_AEBracketingClient.values;
6613     if ((str_val != NULL) && (strlen(str_val) > 0)) {
6614         char prop[PROPERTY_VALUE_MAX];
6615         memset(prop, 0, sizeof(prop));
6616         strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
6617         char *saveptr = NULL;
6618         char *token = strtok_r(prop, ",", &saveptr);
6619         if (token != NULL) {
6620             exp_value[burstCount++] = (char)atoi(token);
6621             while (token != NULL) {
6622                 token = strtok_r(NULL, ",", &saveptr);
6623                 if (token != NULL) {
6624                     exp_value[burstCount++] = (char)atoi(token);
6625                 }
6626             }
6627         }
6628     }
6629 
6630     frame_config.num_batch = burstCount;
6631     cam_bracket_mode mode = m_AEBracketingClient.mode;
6632 
6633     for (i = 0; i < frame_config.num_batch; i++) {
6634         frame_config.configs[i].num_frames = 1;
6635         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
6636         frame_config.configs[i].hdr_mode.mode = mode;
6637         frame_config.configs[i].hdr_mode.values =
6638                 m_AEBracketingClient.values[i];
6639         CDBG("%s: exp values %d", __func__, (int)m_AEBracketingClient.values[i]);
6640     }
6641 
6642     CDBG_HIGH("%s: num_frame = %d X",__func__, burstCount);
6643     return rc;
6644 }
6645 
6646 /*===========================================================================
6647  * FUNCTION   : configFrameCapture
6648  *
6649  * DESCRIPTION: configuration for ZSL special captures (FLASH/HDR etc)
6650  *
6651  * PARAMETERS :
6652  *   @commitSettings : flag to enable or disable commit this this settings
6653  *
6654  * RETURN     : int32_t type of status
6655  *              NO_ERROR  -- success
6656  *              none-zero failure code
6657  *==========================================================================*/
configFrameCapture(bool commitSettings)6658 int32_t QCameraParameters::configFrameCapture(bool commitSettings)
6659 {
6660     int32_t rc = NO_ERROR;
6661     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
6662 
6663     if (commitSettings) {
6664         if(initBatchUpdate(m_pParamBuf) < 0 ) {
6665             ALOGE("%s:Failed to initialize group update table", __func__);
6666             return BAD_TYPE;
6667         }
6668     }
6669 
6670     if (isChromaFlashEnabled() || mFlashValue != CAM_FLASH_MODE_OFF) {
6671         configureFlash(m_captureFrameConfig);
6672     } else if(isHDREnabled()) {
6673         configureHDRBracketing (m_captureFrameConfig);
6674     } else if(isAEBracketEnabled()) {
6675         configureAEBracketing (m_captureFrameConfig);
6676     }
6677 
6678     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
6679             (cam_capture_frame_config_t)m_captureFrameConfig);
6680     if (rc != NO_ERROR) {
6681         rc = BAD_VALUE;
6682         ALOGE("%s:Failed to set capture settings", __func__);
6683         return rc;
6684     }
6685 
6686     if (commitSettings) {
6687         rc = commitSetBatch();
6688         if (rc != NO_ERROR) {
6689             ALOGE("%s:Failed to commit parameters", __func__);
6690             return rc;
6691         }
6692     }
6693     return rc;
6694 }
6695 
6696 /*===========================================================================
6697  * FUNCTION   : resetFrameCapture
6698  *
6699  * DESCRIPTION: reset special captures settings(FLASH/HDR etc)
6700  *
6701  * PARAMETERS :
6702  *   @commitSettings : flag to enable or disable commit this this settings
6703  *
6704  * RETURN     : int32_t type of status
6705  *              NO_ERROR  -- success
6706  *              none-zero failure code
6707  *==========================================================================*/
resetFrameCapture(bool commitSettings)6708 int32_t QCameraParameters::resetFrameCapture(bool commitSettings)
6709 {
6710     int32_t rc = NO_ERROR, i = 0;
6711     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
6712 
6713     if (commitSettings) {
6714         if(initBatchUpdate(m_pParamBuf) < 0 ) {
6715             ALOGE("%s:Failed to initialize group update table", __func__);
6716             return BAD_TYPE;
6717         }
6718     }
6719 
6720     if (isHDREnabled() || isAEBracketEnabled()) {
6721         rc = setToneMapMode(true, true);
6722         if (rc != NO_ERROR) {
6723             CDBG_HIGH("%s: Failed to enable tone map during HDR/AEBracketing", __func__);
6724         }
6725         rc = stopAEBracket();
6726     } else if (isChromaFlashEnabled()) {
6727         rc = setToneMapMode(true, false);
6728         if (rc != NO_ERROR) {
6729             CDBG_HIGH("%s: Failed to enable tone map during chroma flash", __func__);
6730         }
6731 
6732         rc = setCDSMode(mCds_mode, false);
6733         if (rc != NO_ERROR) {
6734             ALOGE("%s: Failed to configure csd mode", __func__);
6735             return rc;
6736         }
6737     }
6738 
6739     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
6740             (cam_capture_frame_config_t)m_captureFrameConfig);
6741     if (rc != NO_ERROR) {
6742         rc = BAD_VALUE;
6743         ALOGE("%s:Failed to set capture settings", __func__);
6744         return rc;
6745     }
6746 
6747     if (commitSettings) {
6748         rc = commitSetBatch();
6749         if (rc != NO_ERROR) {
6750             ALOGE("%s:Failed to commit parameters", __func__);
6751             return rc;
6752         }
6753     }
6754     return rc;
6755 }
6756 
6757 /*===========================================================================
6758  * FUNCTION   : setAecLock
6759  *
6760  * DESCRIPTION: set AEC lock value
6761  *
6762  * PARAMETERS :
6763  *   @aecLockStr : AEC lock value string
6764  *
6765  * RETURN     : int32_t type of status
6766  *              NO_ERROR  -- success
6767  *              none-zero failure code
6768  *==========================================================================*/
setAecLock(const char * aecLockStr)6769 int32_t QCameraParameters::setAecLock(const char *aecLockStr)
6770 {
6771     if (aecLockStr != NULL) {
6772         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
6773                 aecLockStr);
6774         if (value != NAME_NOT_FOUND) {
6775             CDBG_HIGH("%s: Setting AECLock value %s", __func__, aecLockStr);
6776             updateParamEntry(KEY_AUTO_EXPOSURE_LOCK, aecLockStr);
6777             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
6778                     CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
6779                 return BAD_VALUE;
6780             }
6781             return NO_ERROR;
6782         }
6783     }
6784     ALOGE("Invalid AECLock value: %s",
6785         (aecLockStr == NULL) ? "NULL" : aecLockStr);
6786     return BAD_VALUE;
6787 }
6788 
6789 /*===========================================================================
6790  * FUNCTION   : setAwbLock
6791  *
6792  * DESCRIPTION: set AWB lock value
6793  *
6794  * PARAMETERS :
6795  *   @awbLockStr : AWB lock value string
6796  *
6797  * RETURN     : int32_t type of status
6798  *              NO_ERROR  -- success
6799  *              none-zero failure code
6800  *==========================================================================*/
setAwbLock(const char * awbLockStr)6801 int32_t QCameraParameters::setAwbLock(const char *awbLockStr)
6802 {
6803     if (awbLockStr != NULL) {
6804         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
6805                 awbLockStr);
6806         if (value != NAME_NOT_FOUND) {
6807             CDBG_HIGH("%s: Setting AWBLock value %s", __func__, awbLockStr);
6808             updateParamEntry(KEY_AUTO_WHITEBALANCE_LOCK, awbLockStr);
6809             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
6810                     CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
6811                 return BAD_VALUE;
6812             }
6813             return NO_ERROR;
6814         }
6815     }
6816     ALOGE("Invalid AWBLock value: %s", (awbLockStr == NULL) ? "NULL" : awbLockStr);
6817     return BAD_VALUE;
6818 }
6819 
6820 /*===========================================================================
6821  * FUNCTION   : setMCEValue
6822  *
6823  * DESCRIPTION: set memory color enhancement value
6824  *
6825  * PARAMETERS :
6826  *   @mceStr : MCE value string
6827  *
6828  * RETURN     : int32_t type of status
6829  *              NO_ERROR  -- success
6830  *              none-zero failure code
6831  *==========================================================================*/
setMCEValue(const char * mceStr)6832 int32_t QCameraParameters::setMCEValue(const char *mceStr)
6833 {
6834     if (mceStr != NULL) {
6835         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
6836                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), mceStr);
6837         if (value != NAME_NOT_FOUND) {
6838             CDBG_HIGH("%s: Setting AWBLock value %s", __func__, mceStr);
6839             updateParamEntry(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mceStr);
6840             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MCE, value)) {
6841                 return BAD_VALUE;
6842             }
6843             return NO_ERROR;
6844         }
6845     }
6846     ALOGE("Invalid MCE value: %s", (mceStr == NULL) ? "NULL" : mceStr);
6847     return BAD_VALUE;
6848 }
6849 
6850 /*===========================================================================
6851  * FUNCTION   : setTintlessValue
6852  *
6853  * DESCRIPTION: enable/disable tintless from user setting
6854  *
6855  * PARAMETERS :
6856  *   @params  : user setting parameters
6857  *
6858  * RETURN     : int32_t type of status
6859  *              NO_ERROR  -- success
6860  *              none-zero failure code
6861  *==========================================================================*/
setTintlessValue(const QCameraParameters & params)6862 int32_t QCameraParameters::setTintlessValue(const QCameraParameters& params)
6863 {
6864     const char *str = params.get(KEY_QC_TINTLESS_ENABLE);
6865     const char *prev_str = get(KEY_QC_TINTLESS_ENABLE);
6866     char prop[PROPERTY_VALUE_MAX];
6867 
6868     memset(prop, 0, sizeof(prop));
6869     property_get("persist.camera.tintless", prop, VALUE_ENABLE);
6870     if (str != NULL) {
6871         if (prev_str == NULL ||
6872             strcmp(str, prev_str) != 0) {
6873             return setTintlessValue(str);
6874         }
6875     } else {
6876         if (prev_str == NULL ||
6877             strcmp(prev_str, prop) != 0 ) {
6878             setTintlessValue(prop);
6879         }
6880     }
6881 
6882     return NO_ERROR;
6883 }
6884 
6885 /*===========================================================================
6886  * FUNCTION   : setTintless
6887  *
6888  * DESCRIPTION: set tintless mode
6889  *
6890  * PARAMETERS :
6891  *   @enable : 1 = enable, 0 = disable
6892  *
6893  * RETURN     : int32_t type of status
6894  *              NO_ERROR  -- success
6895  *              none-zero failure code
6896  *==========================================================================*/
setTintless(bool enable)6897 void QCameraParameters::setTintless(bool enable)
6898 {
6899     if (enable) {
6900         setTintlessValue(VALUE_ENABLE);
6901     } else {
6902         setTintlessValue(VALUE_DISABLE);
6903     }
6904 }
6905 
6906 /*===========================================================================
6907  * FUNCTION   : setTintlessValue
6908  *
6909  * DESCRIPTION: set tintless value
6910  *
6911  * PARAMETERS :
6912  *   @tintStr : Tintless value string
6913  *
6914  * RETURN     : int32_t type of status
6915  *              NO_ERROR  -- success
6916  *              none-zero failure code
6917  *==========================================================================*/
setTintlessValue(const char * tintStr)6918 int32_t QCameraParameters::setTintlessValue(const char *tintStr)
6919 {
6920     if (tintStr != NULL) {
6921         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
6922                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), tintStr);
6923         if (value != NAME_NOT_FOUND) {
6924             CDBG_HIGH("%s: Setting Tintless value %s", __func__, tintStr);
6925             updateParamEntry(KEY_QC_TINTLESS_ENABLE, tintStr);
6926             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TINTLESS, value)) {
6927                 return BAD_VALUE;
6928             }
6929             return NO_ERROR;
6930         }
6931     }
6932     ALOGE("Invalid Tintless value: %s", (tintStr == NULL) ? "NULL" : tintStr);
6933     return BAD_VALUE;
6934 }
6935 
6936 /*===========================================================================
6937  * FUNCTION   : setCDSMode
6938  *
6939  * DESCRIPTION: Set CDS mode
6940  *
6941  * PARAMETERS :
6942  *   @params  : user setting parameters
6943  *
6944  * RETURN     : int32_t type of status
6945  *              NO_ERROR  -- success
6946  *              none-zero failure code
6947  *==========================================================================*/
setCDSMode(const QCameraParameters & params)6948 int32_t QCameraParameters::setCDSMode(const QCameraParameters& params)
6949 {
6950     const char *str = params.get(KEY_QC_CDS_MODE);
6951     const char *prev_str = get(KEY_QC_CDS_MODE);
6952     const char *video_str = params.get(KEY_QC_VIDEO_CDS_MODE);
6953     const char *video_prev_str = get(KEY_QC_VIDEO_CDS_MODE);
6954     int32_t rc = NO_ERROR;
6955 
6956     if (m_bRecordingHint_new == true) {
6957         if (video_str) {
6958             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
6959                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
6960                         video_str);
6961                 if (cds_mode != NAME_NOT_FOUND) {
6962                     updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_str);
6963                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
6964                         ALOGE("%s:Failed CDS MODE to update table", __func__);
6965                         rc = BAD_VALUE;
6966                     } else {
6967                         CDBG("%s: Set CDS in video mode = %d", __func__, cds_mode);
6968                         mCds_mode = cds_mode;
6969                     }
6970                 } else {
6971                     ALOGE("%s: Invalid argument for video CDS MODE %d", __func__,  cds_mode);
6972                     rc = BAD_VALUE;
6973                 }
6974             }
6975         } else {
6976             char video_prop[PROPERTY_VALUE_MAX];
6977             memset(video_prop, 0, sizeof(video_prop));
6978             property_get("persist.camera.video.CDS", video_prop, CDS_MODE_ON);
6979             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
6980                     video_prop);
6981             if (cds_mode != NAME_NOT_FOUND) {
6982                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_prop);
6983                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
6984                     ALOGE("%s:Failed CDS MODE to update table", __func__);
6985                     rc = BAD_VALUE;
6986                 } else {
6987                     CDBG("%s: Set CDS in video mode from setprop = %d", __func__, cds_mode);
6988                     mCds_mode = cds_mode;
6989                 }
6990             } else {
6991                 ALOGE("%s: Invalid prop for video CDS MODE %d", __func__,  cds_mode);
6992                 rc = BAD_VALUE;
6993             }
6994         }
6995     } else {
6996         if (str) {
6997             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
6998                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
6999                         str);
7000                 if (cds_mode != NAME_NOT_FOUND) {
7001                     updateParamEntry(KEY_QC_CDS_MODE, str);
7002                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7003                         ALOGE("%s:Failed CDS MODE to update table", __func__);
7004                         rc = BAD_VALUE;
7005                     } else {
7006                         CDBG("%s: Set CDS in capture mode = %d", __func__, cds_mode);
7007                         mCds_mode = cds_mode;
7008                     }
7009                 } else {
7010                     ALOGE("%s: Invalid argument for snapshot CDS MODE %d", __func__,  cds_mode);
7011                     rc = BAD_VALUE;
7012                 }
7013             }
7014         } else {
7015             char prop[PROPERTY_VALUE_MAX];
7016             memset(prop, 0, sizeof(prop));
7017             property_get("persist.camera.CDS", prop, CDS_MODE_ON);
7018             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
7019                     prop);
7020             if (cds_mode != NAME_NOT_FOUND) {
7021                 updateParamEntry(KEY_QC_CDS_MODE, prop);
7022                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7023                     ALOGE("%s:Failed CDS MODE to update table", __func__);
7024                     rc = BAD_VALUE;
7025                 } else {
7026                     CDBG("%s: Set CDS in snapshot mode from setprop = %d", __func__, cds_mode);
7027                     mCds_mode = cds_mode;
7028                 }
7029             } else {
7030                 ALOGE("%s: Invalid prop for snapshot CDS MODE %d", __func__,  cds_mode);
7031                 rc = BAD_VALUE;
7032             }
7033         }
7034     }
7035 
7036     return rc;
7037 }
7038 
7039 /*===========================================================================
7040  * FUNCTION   : setDISValue
7041  *
7042  * DESCRIPTION: set DIS value
7043  *
7044  * PARAMETERS :
7045  *   @disStr : DIS value string
7046  *
7047  * RETURN     : int32_t type of status
7048  *              NO_ERROR  -- success
7049  *              none-zero failure code
7050  *==========================================================================*/
setDISValue(const char * disStr)7051 int32_t QCameraParameters::setDISValue(const char *disStr)
7052 {
7053     if (disStr != NULL) {
7054         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
7055                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), disStr);
7056         if (value != NAME_NOT_FOUND) {
7057             //For some IS types (like EIS 2.0), when DIS value is changed, we need to restart
7058             //preview because of topology change in backend. But, for now, restart preview
7059             //for all IS types.
7060             m_bNeedRestart = true;
7061             CDBG_HIGH("%s: Setting DIS value %s", __func__, disStr);
7062             updateParamEntry(KEY_QC_DIS, disStr);
7063             if (!(strcmp(disStr,"enable"))) {
7064                 m_bDISEnabled = true;
7065             } else {
7066                 m_bDISEnabled = false;
7067             }
7068             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_DIS_ENABLE, value)) {
7069                 return BAD_VALUE;
7070             }
7071             return NO_ERROR;
7072         }
7073     }
7074     ALOGE("Invalid DIS value: %s", (disStr == NULL) ? "NULL" : disStr);
7075     m_bDISEnabled = false;
7076     return BAD_VALUE;
7077 }
7078 
7079 /*===========================================================================
7080  * FUNCTION   : updateOisValue
7081  *
7082  * DESCRIPTION: update OIS value
7083  *
7084  * PARAMETERS :
7085  *   @oisValue : OIS value TRUE/FALSE
7086  *
7087  * RETURN     : int32_t type of status
7088  *              NO_ERROR  -- success
7089  *              none-zero failure code
7090  *==========================================================================*/
updateOisValue(bool oisValue)7091 int32_t QCameraParameters::updateOisValue(bool oisValue)
7092 {
7093     uint8_t enable = 0;
7094     int32_t rc = NO_ERROR;
7095 
7096     // Check for OIS disable
7097     char ois_prop[PROPERTY_VALUE_MAX];
7098     memset(ois_prop, 0, sizeof(ois_prop));
7099     property_get("persist.camera.ois.disable", ois_prop, "0");
7100     uint8_t ois_disable = (uint8_t)atoi(ois_prop);
7101 
7102     //Enable OIS if it is camera mode or Camcoder 4K mode
7103     if (!m_bRecordingHint || (is4k2kVideoResolution() && m_bRecordingHint)) {
7104         enable = 1;
7105         CDBG_HIGH("%s: Valid OIS mode!! ", __func__);
7106     }
7107     // Disable OIS if setprop is set
7108     if (ois_disable || !oisValue) {
7109         //Disable OIS
7110         enable = 0;
7111         CDBG_HIGH("%s: Disable OIS mode!! ois_disable(%d) oisValue(%d)",
7112                 __func__, ois_disable, oisValue);
7113 
7114     }
7115     m_bOISEnabled = enable;
7116     if (m_bOISEnabled) {
7117         updateParamEntry(KEY_QC_OIS, VALUE_ENABLE);
7118     } else {
7119         updateParamEntry(KEY_QC_OIS, VALUE_DISABLE);
7120     }
7121 
7122     if (initBatchUpdate(m_pParamBuf) < 0 ) {
7123         ALOGE("%s:Failed to initialize group update table", __func__);
7124         return BAD_TYPE;
7125     }
7126 
7127     CDBG_HIGH("%s: Sending OIS mode (%d)", __func__, enable);
7128     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_LENS_OPT_STAB_MODE, enable)) {
7129         ALOGE("%s:Failed to update table", __func__);
7130         return BAD_VALUE;
7131     }
7132 
7133     rc = commitSetBatch();
7134     if (rc != NO_ERROR) {
7135         ALOGE("%s:Failed to parameter changes", __func__);
7136         return rc;
7137     }
7138 
7139     return rc;
7140 }
7141 
7142 /*===========================================================================
7143  * FUNCTION   : setHighFrameRate
7144  *
7145  * DESCRIPTION: set high frame rate
7146  *
7147  * PARAMETERS :
7148  *   @hfrMode : HFR mode
7149  *
7150  * RETURN     : int32_t type of status
7151  *              NO_ERROR  -- success
7152  *              none-zero failure code
7153  *==========================================================================*/
setHighFrameRate(const int32_t hfrMode)7154 int32_t QCameraParameters::setHighFrameRate(const int32_t hfrMode)
7155 {
7156     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HFR, hfrMode)) {
7157         return BAD_VALUE;
7158     }
7159 
7160     return NO_ERROR;
7161 }
7162 
7163 /*===========================================================================
7164  * FUNCTION   : setLensShadeValue
7165  *
7166  * DESCRIPTION: set lens shade value
7167  *
7168  * PARAMETERS :
7169  *   @lensSahdeStr : lens shade value string
7170  *
7171  * RETURN     : int32_t type of status
7172  *              NO_ERROR  -- success
7173  *              none-zero failure code
7174  *==========================================================================*/
setLensShadeValue(const char * lensShadeStr)7175 int32_t QCameraParameters::setLensShadeValue(const char *lensShadeStr)
7176 {
7177     if (lensShadeStr != NULL) {
7178         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
7179                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), lensShadeStr);
7180         if (value != NAME_NOT_FOUND) {
7181             CDBG_HIGH("%s: Setting LensShade value %s", __func__, lensShadeStr);
7182             updateParamEntry(KEY_QC_LENSSHADE, lensShadeStr);
7183             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROLLOFF, value)) {
7184                 return BAD_VALUE;
7185             }
7186             return NO_ERROR;
7187         }
7188     }
7189     ALOGE("Invalid LensShade value: %s",
7190           (lensShadeStr == NULL) ? "NULL" : lensShadeStr);
7191     return BAD_VALUE;
7192 }
7193 
7194 /*===========================================================================
7195  * FUNCTION   : setExposureCompensation
7196  *
7197  * DESCRIPTION: set exposure compensation value
7198  *
7199  * PARAMETERS :
7200  *   @expComp : exposure compensation value
7201  *
7202  * RETURN     : int32_t type of status
7203  *              NO_ERROR  -- success
7204  *              none-zero failure code
7205  *==========================================================================*/
setExposureCompensation(int expComp)7206 int32_t QCameraParameters::setExposureCompensation(int expComp)
7207 {
7208     char val[16];
7209     snprintf(val, sizeof(val), "%d", expComp);
7210     updateParamEntry(KEY_EXPOSURE_COMPENSATION, val);
7211 
7212     // Don't need to pass step as part of setParameter because
7213     // camera daemon is already aware of it.
7214     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_COMPENSATION, expComp)) {
7215         return BAD_VALUE;
7216     }
7217 
7218     return NO_ERROR;
7219 }
7220 
7221 /*===========================================================================
7222  * FUNCTION   : setWhiteBalance
7223  *
7224  * DESCRIPTION: set white balance mode
7225  *
7226  * PARAMETERS :
7227  *   @wbStr   : white balance mode value string
7228  *
7229  * RETURN     : int32_t type of status
7230  *              NO_ERROR  -- success
7231  *              none-zero failure code
7232  *==========================================================================*/
setWhiteBalance(const char * wbStr)7233 int32_t QCameraParameters::setWhiteBalance(const char *wbStr)
7234 {
7235     if (wbStr != NULL) {
7236         int32_t value = lookupAttr(WHITE_BALANCE_MODES_MAP,
7237                 PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP), wbStr);
7238         if (value != NAME_NOT_FOUND) {
7239             CDBG_HIGH("%s: Setting WhiteBalance value %s", __func__, wbStr);
7240             updateParamEntry(KEY_WHITE_BALANCE, wbStr);
7241             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WHITE_BALANCE, value)) {
7242                 return BAD_VALUE;
7243             }
7244             return NO_ERROR;
7245         }
7246     }
7247     ALOGE("Invalid WhiteBalance value: %s", (wbStr == NULL) ? "NULL" : wbStr);
7248     return BAD_VALUE;
7249 }
7250 
7251 /*===========================================================================
7252  * FUNCTION   : setWBManualCCT
7253  *
7254  * DESCRIPTION: set setWBManualCCT time
7255  *
7256  * PARAMETERS :
7257  *   @cctStr : string of wb cct, range (2000, 8000) in K.
7258  *
7259  * RETURN     : int32_t type of status
7260  *              NO_ERROR  -- success
7261  *              none-zero failure code
7262  *==========================================================================*/
setWBManualCCT(const char * cctStr)7263 int32_t  QCameraParameters::setWBManualCCT(const char *cctStr)
7264 {
7265     if (cctStr != NULL) {
7266         int32_t cctVal = atoi(cctStr);
7267         int32_t minCct = m_pCapability->min_wb_cct; /* 2000K */
7268         int32_t maxCct = m_pCapability->max_wb_cct; /* 8000K */
7269 
7270         if (cctVal >= minCct && cctVal <= maxCct) {
7271             CDBG_HIGH("%s, cct value: %d", __func__, cctVal);
7272             updateParamEntry(KEY_QC_WB_MANUAL_CCT, cctStr);
7273             cam_manual_wb_parm_t manual_wb;
7274             manual_wb.type = CAM_MANUAL_WB_MODE_CCT;
7275             manual_wb.cct = cctVal;
7276             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
7277                 return BAD_VALUE;
7278             }
7279             return NO_ERROR;
7280         }
7281     }
7282 
7283     ALOGE("Invalid cct, value: %s",
7284             (cctStr == NULL) ? "NULL" : cctStr);
7285     return BAD_VALUE;
7286 }
7287 
7288 /*===========================================================================
7289  * FUNCTION   : updateAWBParams
7290  *
7291  * DESCRIPTION: update CCT parameters key
7292  *
7293  * PARAMETERS :
7294  *   @awb_params : WB parameters
7295  *
7296  * RETURN     : int32_t type of status
7297  *              NO_ERROR  -- success
7298  *              none-zero failure code
7299  *==========================================================================*/
updateAWBParams(cam_awb_params_t & awb_params)7300 int32_t QCameraParameters::updateAWBParams(cam_awb_params_t &awb_params)
7301 {
7302     //check and update CCT
7303     int32_t prev_cct = getInt(KEY_QC_WB_MANUAL_CCT);
7304     if (prev_cct != awb_params.cct_value) {
7305         CDBG("%s: update current cct value. old:%d, now:%d", __func__,
7306                 prev_cct, awb_params.cct_value);
7307         set(KEY_QC_WB_MANUAL_CCT, awb_params.cct_value);
7308     }
7309 
7310     //check and update WB gains
7311     const char *prev_gains = get(KEY_QC_MANUAL_WB_GAINS);
7312     char gainStr[30];
7313     snprintf(gainStr, sizeof(gainStr), "%f,%f,%f", awb_params.rgb_gains.r_gain,
7314         awb_params.rgb_gains.g_gain, awb_params.rgb_gains.b_gain);
7315 
7316     if (prev_gains == NULL || strcmp(prev_gains, gainStr)) {
7317         set(KEY_QC_MANUAL_WB_GAINS, gainStr);
7318         CDBG("%s: update currernt RGB gains: old %s new %s",__func__, prev_gains, gainStr);
7319     }
7320     return NO_ERROR;
7321 }
7322 
7323 /*===========================================================================
7324  * FUNCTION   : parseGains
7325  *
7326  * DESCRIPTION: parse WB gains
7327  *
7328  * PARAMETERS :
7329  *   @gainStr : WB result string
7330  *   @r_gain  : WB red gain
7331  *   @g_gain  : WB green gain
7332  *   @b_gain  : WB blue gain
7333  *
7334  * RETURN     : int32_t type of status
7335  *              NO_ERROR  -- success
7336  *              none-zero failure code
7337  *==========================================================================*/
parseGains(const char * gainStr,float & r_gain,float & g_gain,float & b_gain)7338 int32_t QCameraParameters::parseGains(const char *gainStr, float &r_gain,
7339         float &g_gain, float &b_gain)
7340 {
7341     int32_t rc = NO_ERROR;
7342     char *saveptr = NULL;
7343     char* gains = (char*) calloc(1, strlen(gainStr) + 1);
7344     if (NULL == gains) {
7345         ALOGE("%s: No memory for gains", __func__);
7346         return NO_MEMORY;
7347     }
7348     strlcpy(gains, gainStr, strlen(gainStr) + 1);
7349     char *token = strtok_r(gains, ",", &saveptr);
7350 
7351     if (NULL != token) {
7352         r_gain = atof(token);
7353         token = strtok_r(NULL, ",", &saveptr);
7354     }
7355 
7356     if (NULL != token) {
7357         g_gain = atof(token);
7358         token = strtok_r(NULL, ",", &saveptr);
7359     }
7360 
7361     if (NULL != token) {
7362         b_gain = (float) atof(token);
7363     } else {
7364         ALOGE("%s: Malformed string for gains", __func__);
7365         rc = BAD_VALUE;
7366     }
7367 
7368     free(gains);
7369     return rc;
7370 }
7371 
7372 /*===========================================================================
7373  * FUNCTION   : setManualWBGains
7374  *
7375  * DESCRIPTION: set manual wb gains for r,g,b
7376  *
7377  * PARAMETERS :
7378  *   @cctStr : string of wb gains, range (1.0, 4.0).
7379  *
7380  * RETURN     : int32_t type of status
7381  *              NO_ERROR  -- success
7382  *              none-zero failure code
7383  *==========================================================================*/
setManualWBGains(const char * gainStr)7384 int32_t QCameraParameters::setManualWBGains(const char *gainStr)
7385 {
7386     int32_t rc = NO_ERROR;
7387     if (gainStr != NULL) {
7388         float r_gain, g_gain, b_gain;
7389         rc = parseGains(gainStr, r_gain, g_gain, b_gain);
7390         if (rc != NO_ERROR) {
7391             return rc;
7392         }
7393 
7394         float minGain = m_pCapability->min_wb_gain;
7395         float maxGain = m_pCapability->max_wb_gain;
7396 
7397         if ((r_gain >= minGain) && (r_gain <= maxGain) &&
7398                 (g_gain >= minGain) && (g_gain <= maxGain) &&
7399                 (b_gain >= minGain) && (b_gain <= maxGain)) {
7400             CDBG_HIGH("%s, setting rgb gains: %s", __func__, gainStr);
7401             updateParamEntry(KEY_QC_MANUAL_WB_GAINS, gainStr);
7402             cam_manual_wb_parm_t manual_wb;
7403             manual_wb.type = CAM_MANUAL_WB_MODE_GAIN;
7404             manual_wb.gains.r_gain = r_gain;
7405             manual_wb.gains.g_gain = g_gain;
7406             manual_wb.gains.b_gain = b_gain;
7407             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
7408                 return BAD_VALUE;
7409             }
7410             return NO_ERROR;
7411         }
7412     }
7413 
7414     CDBG_HIGH("Invalid manual wb gains: %s",
7415           (gainStr == NULL) ? "NULL" : gainStr);
7416     return BAD_VALUE;
7417 }
7418 
getAutoFlickerMode()7419 int QCameraParameters::getAutoFlickerMode()
7420 {
7421     /* Enable Advanced Auto Antibanding where we can set
7422        any of the following option
7423        ie. CAM_ANTIBANDING_MODE_AUTO
7424            CAM_ANTIBANDING_MODE_AUTO_50HZ
7425            CAM_ANTIBANDING_MODE_AUTO_60HZ
7426       Currently setting it to default    */
7427     char prop[PROPERTY_VALUE_MAX];
7428     memset(prop, 0, sizeof(prop));
7429     property_get("persist.camera.set.afd", prop, "3");
7430     return atoi(prop);
7431 }
7432 
7433 /*===========================================================================
7434  * FUNCTION   : setAntibanding
7435  *
7436  * DESCRIPTION: set antibanding value
7437  *
7438  * PARAMETERS :
7439  *   @antiBandingStr : antibanding value string
7440  *
7441  * RETURN     : int32_t type of status
7442  *              NO_ERROR  -- success
7443  *              none-zero failure code
7444  *==========================================================================*/
setAntibanding(const char * antiBandingStr)7445 int32_t QCameraParameters::setAntibanding(const char *antiBandingStr)
7446 {
7447     if (antiBandingStr != NULL) {
7448         int32_t value = lookupAttr(ANTIBANDING_MODES_MAP, PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP),
7449                 antiBandingStr);
7450         if (value != NAME_NOT_FOUND) {
7451             CDBG_HIGH("%s: Setting AntiBanding value %s", __func__, antiBandingStr);
7452             updateParamEntry(KEY_ANTIBANDING, antiBandingStr);
7453             if(value == CAM_ANTIBANDING_MODE_AUTO) {
7454                value = getAutoFlickerMode();
7455             }
7456             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7457                     CAM_INTF_PARM_ANTIBANDING, (uint32_t)value)) {
7458                 return BAD_VALUE;
7459             }
7460             return NO_ERROR;
7461         }
7462     }
7463     ALOGE("Invalid AntiBanding value: %s",
7464           (antiBandingStr == NULL) ? "NULL" : antiBandingStr);
7465     return BAD_VALUE;
7466 }
7467 
7468 /*===========================================================================
7469  * FUNCTION   : setFocusAreas
7470  *
7471  * DESCRIPTION: set focus areas
7472  *
7473  * PARAMETERS :
7474  *   @focusAreasStr : focus areas value string
7475  *
7476  * RETURN     : int32_t type of status
7477  *              NO_ERROR  -- success
7478  *              none-zero failure code
7479  *==========================================================================*/
setFocusAreas(const char * focusAreasStr)7480 int32_t QCameraParameters::setFocusAreas(const char *focusAreasStr)
7481 {
7482     if (m_pCapability->max_num_focus_areas == 0 ||
7483         focusAreasStr == NULL) {
7484         CDBG("%s: Parameter string is null", __func__);
7485         return NO_ERROR;
7486     }
7487 
7488     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
7489     if (NULL == areas) {
7490         ALOGE("%s: No memory for areas", __func__);
7491         return NO_MEMORY;
7492     }
7493     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
7494     int num_areas_found = 0;
7495     if (parseCameraAreaString(focusAreasStr,
7496                               m_pCapability->max_num_focus_areas,
7497                               areas,
7498                               num_areas_found) != NO_ERROR) {
7499         ALOGE("%s: Failed to parse the string: %s", __func__, focusAreasStr);
7500         free(areas);
7501         return BAD_VALUE;
7502     }
7503 
7504     if (validateCameraAreas(areas, num_areas_found) == false) {
7505         ALOGE("%s: invalid areas specified : %s", __func__, focusAreasStr);
7506         free(areas);
7507         return BAD_VALUE;
7508     }
7509 
7510     updateParamEntry(KEY_FOCUS_AREAS, focusAreasStr);
7511 
7512     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
7513     //so no action is takenby the lower layer
7514     if (num_areas_found == 1 &&
7515         areas[0].rect.left == 0 &&
7516         areas[0].rect.top == 0 &&
7517         areas[0].rect.width == 0 &&
7518         areas[0].rect.height == 0 &&
7519         areas[0].weight == 0) {
7520         num_areas_found = 0;
7521     }
7522 
7523     int previewWidth, previewHeight;
7524     getPreviewSize(&previewWidth, &previewHeight);
7525     cam_roi_info_t af_roi_value;
7526     memset(&af_roi_value, 0, sizeof(cam_roi_info_t));
7527     af_roi_value.num_roi = (uint8_t)num_areas_found;
7528     for (int i = 0; i < num_areas_found; i++) {
7529         CDBG_HIGH("%s: FocusArea[%d] = (%d, %d, %d, %d)",
7530               __func__, i, (areas[i].rect.top), (areas[i].rect.left),
7531               (areas[i].rect.width), (areas[i].rect.height));
7532 
7533         // Transform the coords from (-1000, 1000)
7534         // to (0, previewWidth or previewHeight).
7535         af_roi_value.roi[i].left =
7536                 (int32_t)(((double)areas[i].rect.left + 1000.0) *
7537                     ((double)previewWidth / 2000.0));
7538         af_roi_value.roi[i].top =
7539                 (int32_t)(((double)areas[i].rect.top + 1000.0) *
7540                     ((double)previewHeight / 2000.0));
7541         af_roi_value.roi[i].width =
7542                 (int32_t)((double)areas[i].rect.width *
7543                     (double)previewWidth / 2000.0);
7544         af_roi_value.roi[i].height =
7545                 (int32_t)((double)areas[i].rect.height *
7546                     (double)previewHeight / 2000.0);
7547         af_roi_value.weight[i] = areas[i].weight;
7548     }
7549     free(areas);
7550     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AF_ROI, af_roi_value)) {
7551         return BAD_VALUE;
7552     }
7553 
7554     return NO_ERROR;
7555 }
7556 
7557 /*===========================================================================
7558  * FUNCTION   : setMeteringAreas
7559  *
7560  * DESCRIPTION: set metering areas value
7561  *
7562  * PARAMETERS :
7563  *   @meteringAreasStr : metering areas value string
7564  *
7565  * RETURN     : int32_t type of status
7566  *              NO_ERROR  -- success
7567  *              none-zero failure code
7568  *==========================================================================*/
setMeteringAreas(const char * meteringAreasStr)7569 int32_t QCameraParameters::setMeteringAreas(const char *meteringAreasStr)
7570 {
7571     if (m_pCapability->max_num_metering_areas == 0 ||
7572         meteringAreasStr == NULL) {
7573         CDBG("%s: Parameter string is null", __func__);
7574         return NO_ERROR;
7575     }
7576 
7577     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
7578     if (NULL == areas) {
7579         ALOGE("%s: No memory for areas", __func__);
7580         return NO_MEMORY;
7581     }
7582     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
7583     int num_areas_found = 0;
7584     if (parseCameraAreaString(meteringAreasStr,
7585                               m_pCapability->max_num_metering_areas,
7586                               areas,
7587                               num_areas_found) < 0) {
7588         ALOGE("%s: Failed to parse the string: %s", __func__, meteringAreasStr);
7589         free(areas);
7590         return BAD_VALUE;
7591     }
7592 
7593     if (validateCameraAreas(areas, num_areas_found) == false) {
7594         ALOGE("%s: invalid areas specified : %s", __func__, meteringAreasStr);
7595         free(areas);
7596         return BAD_VALUE;
7597     }
7598 
7599     updateParamEntry(KEY_METERING_AREAS, meteringAreasStr);
7600 
7601     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
7602     //so no action is takenby the lower layer
7603     if (num_areas_found == 1 &&
7604         areas[0].rect.left == 0 &&
7605         areas[0].rect.top == 0 &&
7606         areas[0].rect.width == 0 &&
7607         areas[0].rect.height == 0 &&
7608         areas[0].weight == 0) {
7609         num_areas_found = 0;
7610     }
7611     cam_set_aec_roi_t aec_roi_value;
7612     int previewWidth, previewHeight;
7613     getPreviewSize(&previewWidth, &previewHeight);
7614 
7615     memset(&aec_roi_value, 0, sizeof(cam_set_aec_roi_t));
7616     if (num_areas_found > 0) {
7617         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_ON;
7618         aec_roi_value.aec_roi_type = CAM_AEC_ROI_BY_COORDINATE;
7619 
7620         for (int i = 0; i < num_areas_found; i++) {
7621             CDBG_HIGH("%s: MeteringArea[%d] = (%d, %d, %d, %d)",
7622                   __func__, i, (areas[i].rect.top), (areas[i].rect.left),
7623                   (areas[i].rect.width), (areas[i].rect.height));
7624 
7625             // Transform the coords from (-1000, 1000) to
7626             // (0, previewWidth or previewHeight).
7627             aec_roi_value.cam_aec_roi_position.coordinate[i].x =
7628                     (uint32_t)((((double)areas[i].rect.left +
7629                         (double)areas[i].rect.width / 2.0) + 1000.0) *
7630                             (double)previewWidth / 2000.0);
7631             aec_roi_value.cam_aec_roi_position.coordinate[i].y =
7632                     (uint32_t)((((double)areas[i].rect.top +
7633                         (double)areas[i].rect.height / 2.0) + 1000.0) *
7634                             (double)previewHeight / 2000.0);
7635         }
7636     } else {
7637         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_OFF;
7638     }
7639     free(areas);
7640     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ROI, aec_roi_value)) {
7641         return BAD_VALUE;
7642     }
7643 
7644     return NO_ERROR;
7645 }
7646 
7647 /*===========================================================================
7648  * FUNCTION   : setSceneMode
7649  *
7650  * DESCRIPTION: set scene mode
7651  *
7652  * PARAMETERS :
7653  *   @sceneModeStr : scene mode value string
7654  *
7655  * RETURN     : int32_t type of status
7656  *              NO_ERROR  -- success
7657  *              none-zero failure code
7658  *==========================================================================*/
setSceneMode(const char * sceneModeStr)7659 int32_t QCameraParameters::setSceneMode(const char *sceneModeStr)
7660 {
7661     if (sceneModeStr != NULL) {
7662         int32_t value = lookupAttr(SCENE_MODES_MAP, PARAM_MAP_SIZE(SCENE_MODES_MAP), sceneModeStr);
7663         if (value != NAME_NOT_FOUND) {
7664             CDBG("%s: Setting SceneMode %s", __func__, sceneModeStr);
7665             updateParamEntry(KEY_SCENE_MODE, sceneModeStr);
7666             if (m_bSensorHDREnabled) {
7667               // Incase of HW HDR mode, we do not update the same as Best shot mode.
7668               CDBG_HIGH("%s: H/W HDR mode enabled. Do not set Best Shot Mode", __func__);
7669               return NO_ERROR;
7670             }
7671             if (m_bSceneSelection) {
7672                 setSelectedScene((cam_scene_mode_type) value);
7673             }
7674             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BESTSHOT_MODE,
7675                     (uint32_t)value)) {
7676                 return BAD_VALUE;
7677             }
7678             return NO_ERROR;
7679         }
7680     }
7681     ALOGE("%s: Invalid Secene Mode: %s",
7682           __func__, (sceneModeStr == NULL) ? "NULL" : sceneModeStr);
7683     return BAD_VALUE;
7684 }
7685 
7686 /*===========================================================================
7687  * FUNCTION   : setSelectableZoneAf
7688  *
7689  * DESCRIPTION: set selectable zone AF algorithm
7690  *
7691  * PARAMETERS :
7692  *   @selZoneAFStr : selectable zone AF algorithm value string
7693  *
7694  * RETURN     : int32_t type of status
7695  *              NO_ERROR  -- success
7696  *              none-zero failure code
7697  *==========================================================================*/
setSelectableZoneAf(const char * selZoneAFStr)7698 int32_t QCameraParameters::setSelectableZoneAf(const char *selZoneAFStr)
7699 {
7700     if (selZoneAFStr != NULL) {
7701         int32_t value = lookupAttr(FOCUS_ALGO_MAP, PARAM_MAP_SIZE(FOCUS_ALGO_MAP), selZoneAFStr);
7702         if (value != NAME_NOT_FOUND) {
7703             CDBG("%s: Setting Selectable Zone AF value %s", __func__, selZoneAFStr);
7704             updateParamEntry(KEY_QC_SELECTABLE_ZONE_AF, selZoneAFStr);
7705             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_ALGO_TYPE, value)) {
7706                 return BAD_VALUE;
7707             }
7708             return NO_ERROR;
7709         }
7710     }
7711     ALOGE("%s: Invalid selectable zone af value: %s",
7712           __func__, (selZoneAFStr == NULL) ? "NULL" : selZoneAFStr);
7713     return BAD_VALUE;
7714 }
7715 
7716 /*===========================================================================
7717  * FUNCTION   : isAEBracketEnabled
7718  *
7719  * DESCRIPTION: checks if AE bracketing is enabled
7720  *
7721  * PARAMETERS :
7722  *
7723  * RETURN     : TRUE/FALSE
7724  *==========================================================================*/
isAEBracketEnabled()7725 bool QCameraParameters::isAEBracketEnabled()
7726 {
7727     const char *str = get(KEY_QC_AE_BRACKET_HDR);
7728     if (str != NULL) {
7729         if (strcmp(str, AE_BRACKET_OFF) != 0) {
7730             return true;
7731         }
7732     }
7733     return false;
7734 }
7735 
7736 /*===========================================================================
7737  * FUNCTION   : setAEBracket
7738  *
7739  * DESCRIPTION: set AE bracket value
7740  *
7741  * PARAMETERS :
7742  *   @aecBracketStr : AE bracket value string
7743  *
7744  * RETURN     : int32_t type of status
7745  *              NO_ERROR  -- success
7746  *              none-zero failure code
7747  *==========================================================================*/
setAEBracket(const char * aecBracketStr)7748 int32_t QCameraParameters::setAEBracket(const char *aecBracketStr)
7749 {
7750     if (aecBracketStr == NULL) {
7751         CDBG("%s: setAEBracket with NULL value", __func__);
7752         return NO_ERROR;
7753     }
7754 
7755     cam_exp_bracketing_t expBracket;
7756     memset(&expBracket, 0, sizeof(expBracket));
7757 
7758     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
7759             aecBracketStr);
7760     switch (value) {
7761     case CAM_EXP_BRACKETING_ON:
7762         {
7763             CDBG("%s, EXP_BRACKETING_ON", __func__);
7764             const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
7765             if ((str_val != NULL) && (strlen(str_val)>0)) {
7766                 expBracket.mode = CAM_EXP_BRACKETING_ON;
7767                 m_bAeBracketingEnabled = true;
7768                 strlcpy(expBracket.values, str_val, MAX_EXP_BRACKETING_LENGTH);
7769                 CDBG("%s: setting Exposure Bracketing value of %s",
7770                       __func__, expBracket.values);
7771             }
7772             else {
7773                 /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */
7774                 CDBG("%s: capture-burst-exposures not set, back to HDR OFF mode", __func__);
7775                 m_bAeBracketingEnabled = false;
7776                 expBracket.mode = CAM_EXP_BRACKETING_OFF;
7777             }
7778         }
7779         break;
7780     default:
7781         {
7782             m_bAeBracketingEnabled = false;
7783             CDBG_HIGH("%s, EXP_BRACKETING_OFF", __func__);
7784             expBracket.mode = CAM_EXP_BRACKETING_OFF;
7785         }
7786         break;
7787     }
7788 
7789     // Cache client AE bracketing configuration
7790     memcpy(&m_AEBracketingClient, &expBracket, sizeof(cam_exp_bracketing_t));
7791 
7792     /* save the value*/
7793     updateParamEntry(KEY_QC_AE_BRACKET_HDR, aecBracketStr);
7794     return NO_ERROR;
7795 }
7796 
7797 /*===========================================================================
7798  * FUNCTION   : set3ALock
7799  *
7800  * DESCRIPTION: enable/disable 3A lock.
7801  *
7802  * PARAMETERS :
7803  *   @lockStr : lock value string.
7804  *
7805  * RETURN     : int32_t type of status
7806  *              NO_ERROR  -- success
7807  *              none-zero failure code
7808  *==========================================================================*/
set3ALock(const char * lockStr)7809 int32_t QCameraParameters::set3ALock(const char *lockStr)
7810 {
7811     int32_t rc = NO_ERROR;
7812     if (lockStr != NULL) {
7813         int value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
7814                 lockStr);
7815         if (value != NAME_NOT_FOUND) {
7816             CDBG_HIGH("%s: Setting Lock lockStr =%s", __func__, lockStr);
7817             if(initBatchUpdate(m_pParamBuf) < 0 ) {
7818                 ALOGE("%s:Failed to initialize group update table", __func__);
7819                 return BAD_TYPE;
7820             }
7821             uint32_t focus_mode = CAM_FOCUS_MODE_AUTO;
7822             if (value == 1) {
7823                 if (isUbiFocusEnabled() || isUbiRefocus()) {
7824                     //For Ubi focus move focus to infinity.
7825                     focus_mode = CAM_FOCUS_MODE_INFINITY;
7826                 } else if (isOptiZoomEnabled() || isStillMoreEnabled()) {
7827                     //For optizoom and stillmore, set focus as fixed.
7828                     focus_mode = CAM_FOCUS_MODE_FIXED;
7829                 }
7830             } else {
7831                 // retrieve previous focus value.
7832                 const char *focus = get(KEY_FOCUS_MODE);
7833                 int val = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focus);
7834                 if (val != NAME_NOT_FOUND) {
7835                     focus_mode = (uint32_t) val;
7836                     CDBG("%s: focus mode %s", __func__, focus);
7837                 }
7838             }
7839             //Lock AWB
7840             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
7841                 return BAD_VALUE;
7842             }
7843             //Lock AEC
7844             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
7845                 return BAD_VALUE;
7846             }
7847             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_MODE, focus_mode)) {
7848                 return BAD_VALUE;
7849             }
7850 
7851             rc = commitSetBatch();
7852             if (rc != NO_ERROR) {
7853                 ALOGE("%s:Failed to commit batch", __func__);
7854             }
7855         }
7856     }
7857     return rc;
7858 }
7859 
7860 /*===========================================================================
7861  * FUNCTION   : setAndCommitZoom
7862  *
7863  * DESCRIPTION: set zoom.
7864  *
7865  * PARAMETERS :
7866  *     @zoom_level : zoom level to set.
7867  *
7868  * RETURN     : int32_t type of status
7869  *              NO_ERROR  -- success
7870  *              none-zero failure code
7871  *==========================================================================*/
setAndCommitZoom(int zoom_level)7872 int32_t QCameraParameters::setAndCommitZoom(int zoom_level)
7873 {
7874     CDBG_HIGH("%s: E",__func__);
7875     int32_t rc = NO_ERROR;
7876     if (initBatchUpdate(m_pParamBuf) < 0 ) {
7877         ALOGE("%s:Failed to initialize group update table", __func__);
7878         return BAD_TYPE;
7879     }
7880 
7881     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
7882         ALOGE("%s:Failed to update table", __func__);
7883         return BAD_VALUE;
7884     }
7885 
7886     rc = commitSetBatch();
7887     if (rc != NO_ERROR) {
7888         ALOGE("%s:Failed to set Flash value", __func__);
7889     }
7890 
7891     mZoomLevel = zoom_level;
7892     CDBG_HIGH("%s: X",__func__);
7893 
7894     return rc;
7895 }
7896 
7897 /*===========================================================================
7898  * FUNCTION   : isOptiZoomEnabled
7899  *
7900  * DESCRIPTION: checks whether optizoom is enabled
7901  *
7902  * PARAMETERS :
7903  *
7904  * RETURN     : true - enabled, false - disabled
7905  *
7906  *==========================================================================*/
isOptiZoomEnabled()7907 bool QCameraParameters::isOptiZoomEnabled()
7908 {
7909     if (m_bOptiZoomOn && (0 <= mParmZoomLevel)) {
7910         uint32_t zoom_level = (uint32_t) mParmZoomLevel;
7911         cam_opti_zoom_t *opti_zoom_settings_need =
7912                 &(m_pCapability->opti_zoom_settings_need);
7913         uint32_t zoom_threshold = (uint32_t) opti_zoom_settings_need->zoom_threshold;
7914         CDBG_HIGH("%s: current zoom level =%u & zoom_threshold =%u",
7915                 __func__, zoom_level, zoom_threshold);
7916 
7917         if (zoom_level >= zoom_threshold) {
7918             return true;
7919         }
7920     }
7921 
7922     return false;
7923 }
7924 
7925 /*===========================================================================
7926  * FUNCTION   : commitAFBracket
7927  *
7928  * DESCRIPTION: commit AF Bracket.
7929  *
7930  * PARAMETERS :
7931  *   @AFBracket : AF bracketing configuration
7932  *
7933  * RETURN     : int32_t type of status
7934  *              NO_ERROR  -- success
7935  *              none-zero failure code
7936  *==========================================================================*/
commitAFBracket(cam_af_bracketing_t afBracket)7937 int32_t QCameraParameters::commitAFBracket(cam_af_bracketing_t afBracket)
7938 {
7939 
7940     int32_t rc = NO_ERROR;
7941     if(initBatchUpdate(m_pParamBuf) < 0 ) {
7942         ALOGE("%s:Failed to initialize group update table", __func__);
7943         return BAD_TYPE;
7944     }
7945 
7946     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_BRACKETING, afBracket)) {
7947         ALOGE("%s:Failed to update table", __func__);
7948         return BAD_VALUE;
7949     }
7950 
7951     rc = commitSetBatch();
7952     if (rc != NO_ERROR) {
7953         ALOGE("%s:Failed to commit batch", __func__);
7954         return rc;
7955     }
7956 
7957     return rc;
7958 }
7959 
7960 /*===========================================================================
7961  * FUNCTION   : commitFlashBracket
7962  *
7963  * DESCRIPTION: commit Flash Bracket.
7964  *
7965  * PARAMETERS :
7966  *   @AFBracket : Flash bracketing configuration
7967  *
7968  * RETURN     : int32_t type of status
7969  *              NO_ERROR  -- success
7970  *              none-zero failure code
7971  *==========================================================================*/
commitFlashBracket(cam_flash_bracketing_t flashBracket)7972 int32_t QCameraParameters::commitFlashBracket(cam_flash_bracketing_t flashBracket)
7973 {
7974     CDBG_HIGH("%s: E",__func__);
7975     int32_t rc = NO_ERROR;
7976     if(initBatchUpdate(m_pParamBuf) < 0 ) {
7977         ALOGE("%s:Failed to initialize group update table", __func__);
7978         return BAD_TYPE;
7979     }
7980 
7981     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7982             CAM_INTF_PARM_FLASH_BRACKETING, flashBracket)) {
7983         ALOGE("%s:Failed to update table", __func__);
7984         return BAD_VALUE;
7985     }
7986 
7987     rc = commitSetBatch();
7988     if (rc != NO_ERROR) {
7989         ALOGE("%s:Failed to commit batch", __func__);
7990     }
7991 
7992     CDBG_HIGH("%s: X",__func__);
7993     return rc;
7994 }
7995 
7996 /*===========================================================================
7997  * FUNCTION   : setAFBracket
7998  *
7999  * DESCRIPTION: set AF bracket value
8000  *
8001  * PARAMETERS :
8002  *   @afBracketStr : AF bracket value string
8003  *
8004  * RETURN     : int32_t type of status
8005  *              NO_ERROR  -- success
8006  *              none-zero failure code
8007  *==========================================================================*/
setAFBracket(const char * afBracketStr)8008 int32_t QCameraParameters::setAFBracket(const char *afBracketStr)
8009 {
8010     CDBG_HIGH("%s: afBracketStr =%s",__func__,afBracketStr);
8011 
8012     if(afBracketStr != NULL) {
8013         int value = lookupAttr(AF_BRACKETING_MODES_MAP, PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP),
8014                 afBracketStr);
8015         if (value != NAME_NOT_FOUND) {
8016             m_bAFBracketingOn = (value != 0);
8017             updateParamEntry(KEY_QC_AF_BRACKET, afBracketStr);
8018 
8019             return NO_ERROR;
8020         }
8021     }
8022 
8023     ALOGE("Invalid af bracket value: %s",
8024         (afBracketStr == NULL) ? "NULL" : afBracketStr);
8025     return BAD_VALUE;
8026 }
8027 
8028 /*===========================================================================
8029  * FUNCTION   : setReFocus
8030  *
8031  * DESCRIPTION: set refocus value
8032  *
8033  * PARAMETERS :
8034  *   @afBracketStr : refocus value string
8035  *
8036  * RETURN     : int32_t type of status
8037  *              NO_ERROR  -- success
8038  *              none-zero failure code
8039  *==========================================================================*/
setReFocus(const char * reFocusStr)8040 int32_t QCameraParameters::setReFocus(const char *reFocusStr)
8041 {
8042     CDBG_HIGH("%s: reFocusStr =%s",__func__,reFocusStr);
8043 
8044     if (reFocusStr != NULL) {
8045         int value = lookupAttr(RE_FOCUS_MODES_MAP, PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP),
8046                 reFocusStr);
8047         if (value != NAME_NOT_FOUND) {
8048             m_bReFocusOn = (value != 0);
8049             updateParamEntry(KEY_QC_RE_FOCUS, reFocusStr);
8050             return NO_ERROR;
8051         }
8052     }
8053 
8054     return NO_ERROR;
8055 }
8056 
8057 /*===========================================================================
8058  * FUNCTION   : setChromaFlash
8059  *
8060  * DESCRIPTION: set chroma flash value
8061  *
8062  * PARAMETERS :
8063  *   @aecBracketStr : chroma flash value string
8064  *
8065  * RETURN     : int32_t type of status
8066  *              NO_ERROR  -- success
8067  *              none-zero failure code
8068  *==========================================================================*/
setChromaFlash(const char * chromaFlashStr)8069 int32_t QCameraParameters::setChromaFlash(const char *chromaFlashStr)
8070 {
8071     CDBG_HIGH("%s: chromaFlashStr =%s",__func__,chromaFlashStr);
8072     if(chromaFlashStr != NULL) {
8073         int value = lookupAttr(CHROMA_FLASH_MODES_MAP, PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP),
8074                 chromaFlashStr);
8075         if(value != NAME_NOT_FOUND) {
8076             m_bChromaFlashOn = (value != 0);
8077             updateParamEntry(KEY_QC_CHROMA_FLASH, chromaFlashStr);
8078 
8079             return NO_ERROR;
8080         }
8081     }
8082 
8083     ALOGE("Invalid chroma flash value: %s",
8084         (chromaFlashStr == NULL) ? "NULL" : chromaFlashStr);
8085     return BAD_VALUE;
8086 }
8087 
8088 /*===========================================================================
8089  * FUNCTION   : setOptiZoom
8090  *
8091  * DESCRIPTION: set opti zoom value
8092  *
8093  * PARAMETERS :
8094  *   @optiZoomStr : opti zoom value string
8095  *
8096  * RETURN     : int32_t type of status
8097  *              NO_ERROR  -- success
8098  *              none-zero failure code
8099  *==========================================================================*/
setOptiZoom(const char * optiZoomStr)8100 int32_t QCameraParameters::setOptiZoom(const char *optiZoomStr)
8101 {
8102     CDBG_HIGH("%s: optiZoomStr =%s",__func__,optiZoomStr);
8103     if(optiZoomStr != NULL) {
8104         int value = lookupAttr(OPTI_ZOOM_MODES_MAP, PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP),
8105                 optiZoomStr);
8106         if(value != NAME_NOT_FOUND) {
8107             m_bOptiZoomOn = (value != 0);
8108             updateParamEntry(KEY_QC_OPTI_ZOOM, optiZoomStr);
8109 
8110             return NO_ERROR;
8111         }
8112     }
8113     ALOGE("Invalid opti zoom value: %s",
8114         (optiZoomStr == NULL) ? "NULL" : optiZoomStr);
8115     return BAD_VALUE;
8116 }
8117 
8118 /*===========================================================================
8119  * FUNCTION   : setTruePortrait
8120  *
8121  * DESCRIPTION: set true portrait value
8122  *
8123  * PARAMETERS :
8124  *   @optiZoomStr : true portrait value string
8125  *
8126  * RETURN     : int32_t type of status
8127  *              NO_ERROR  -- success
8128  *              none-zero failure code
8129  *==========================================================================*/
setTruePortrait(const char * truePortraitStr)8130 int32_t QCameraParameters::setTruePortrait(const char *truePortraitStr)
8131 {
8132     CDBG_HIGH("%s: truePortraitStr =%s", __func__, truePortraitStr);
8133     if (truePortraitStr != NULL) {
8134         int value = lookupAttr(TRUE_PORTRAIT_MODES_MAP,
8135                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP),
8136                 truePortraitStr);
8137         if (value != NAME_NOT_FOUND) {
8138             m_bTruePortraitOn = (value != 0);
8139             updateParamEntry(KEY_QC_TRUE_PORTRAIT, truePortraitStr);
8140             return NO_ERROR;
8141         }
8142     }
8143     CDBG_HIGH("Invalid true portrait value: %s",
8144             (truePortraitStr == NULL) ? "NULL" : truePortraitStr);
8145     return BAD_VALUE;
8146 }
8147 
8148 /*===========================================================================
8149  * FUNCTION   : setHDRMode
8150  *
8151  * DESCRIPTION: set hdr mode value
8152  *
8153  * PARAMETERS :
8154  *   @hdrModeStr : hdr mode value string
8155  *
8156  * RETURN     : int32_t type of status
8157  *              NO_ERROR  -- success
8158  *              none-zero failure code
8159  *==========================================================================*/
setHDRMode(const char * hdrModeStr)8160 int32_t QCameraParameters::setHDRMode(const char *hdrModeStr)
8161 {
8162     CDBG_HIGH("%s: hdrModeStr =%s", __func__, hdrModeStr);
8163     if (hdrModeStr != NULL) {
8164         int value = lookupAttr(HDR_MODES_MAP, PARAM_MAP_SIZE(HDR_MODES_MAP), hdrModeStr);
8165         if (value != NAME_NOT_FOUND) {
8166             const char *str = get(KEY_SCENE_MODE);
8167 
8168             m_bHDRModeSensor = !strncmp(hdrModeStr, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR));
8169 
8170             updateParamEntry(KEY_QC_HDR_MODE, hdrModeStr);
8171 
8172             // If hdr is already selected, need to deselect it in local cache
8173             // So the new hdr mode will be applied
8174             if (str && !strncmp(str, SCENE_MODE_HDR, strlen(SCENE_MODE_HDR))) {
8175                 updateParamEntry(KEY_SCENE_MODE, SCENE_MODE_AUTO);
8176                 m_bNeedRestart = true;
8177             }
8178 
8179             return NO_ERROR;
8180         }
8181     }
8182     CDBG_HIGH("Invalid hdr mode value: %s",
8183             (hdrModeStr == NULL) ? "NULL" : hdrModeStr);
8184     return BAD_VALUE;
8185 }
8186 
8187 /*===========================================================================
8188  * FUNCTION   : setSeeMore
8189  *
8190  * DESCRIPTION: set see more value
8191  *
8192  * PARAMETERS :
8193  *   @seeMoreStr : see more value string
8194  *
8195  * RETURN     : int32_t type of status
8196  *              NO_ERROR  -- success
8197  *              none-zero failure code
8198  *==========================================================================*/
setSeeMore(const char * seeMoreStr)8199 int32_t QCameraParameters::setSeeMore(const char *seeMoreStr)
8200 {
8201     int32_t rc = NO_ERROR;
8202 
8203     CDBG_HIGH("%s: seeMoreStr =%s", __func__, seeMoreStr);
8204     if (seeMoreStr != NULL) {
8205         int value = lookupAttr(ON_OFF_MODES_MAP,
8206                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
8207                 seeMoreStr);
8208         if (value != NAME_NOT_FOUND) {
8209             m_bSeeMoreOn = (value != 0);
8210 
8211             // If SeeMore is enabled, enable StillMore for live snapshot
8212             // and disable tone map
8213             if (m_bSeeMoreOn) {
8214                 m_bStillMoreOn = TRUE;
8215                 rc = setToneMapMode(false, false);
8216                 if (rc != NO_ERROR) {
8217                     CDBG_HIGH("%s: Failed to disable tone map during SeeMore", __func__);
8218                 }
8219             } else {
8220                 m_bStillMoreOn = FALSE;
8221                 rc = setToneMapMode(true, false);
8222                 if (rc != NO_ERROR) {
8223                     CDBG_HIGH("%s: Failed to enable tone map during SeeMore", __func__);
8224                 }
8225             }
8226             updateParamEntry(KEY_QC_SEE_MORE, seeMoreStr);
8227             return NO_ERROR;
8228         }
8229     }
8230     ALOGE("Invalid see more value: %s",
8231             (seeMoreStr == NULL) ? "NULL" : seeMoreStr);
8232     return BAD_VALUE;
8233 }
8234 
8235 /*===========================================================================
8236  * FUNCTION   : setStillMore
8237  *
8238  * DESCRIPTION: set still more value
8239  *
8240  * PARAMETERS :
8241  *   @seeMoreStr : still more value string
8242  *
8243  * RETURN     : int32_t type of status
8244  *              NO_ERROR  -- success
8245  *              none-zero failure code
8246  *==========================================================================*/
setStillMore(const char * stillMoreStr)8247 int32_t QCameraParameters::setStillMore(const char *stillMoreStr)
8248 {
8249     CDBG_HIGH("%s: stillMoreStr =%s", __func__, stillMoreStr);
8250     if (stillMoreStr != NULL) {
8251         int value = lookupAttr(STILL_MORE_MODES_MAP, PARAM_MAP_SIZE(STILL_MORE_MODES_MAP),
8252                 stillMoreStr);
8253         if (value != NAME_NOT_FOUND) {
8254             m_bStillMoreOn = (value != 0);
8255             updateParamEntry(KEY_QC_STILL_MORE, stillMoreStr);
8256 
8257             return NO_ERROR;
8258         }
8259     }
8260     ALOGE("Invalid still more value: %s",
8261             (stillMoreStr == NULL) ? "NULL" : stillMoreStr);
8262     return BAD_VALUE;
8263 }
8264 
8265 /*===========================================================================
8266  * FUNCTION   : setHDRNeed1x
8267  *
8268  * DESCRIPTION: set hdr need 1x value
8269  *
8270  * PARAMETERS :
8271  *   @hdrModeStr : hdr need 1x value string
8272  *
8273  * RETURN     : int32_t type of status
8274  *              NO_ERROR  -- success
8275  *              none-zero failure code
8276  *==========================================================================*/
setHDRNeed1x(const char * hdrNeed1xStr)8277 int32_t QCameraParameters::setHDRNeed1x(const char *hdrNeed1xStr)
8278 {
8279     CDBG_HIGH("%s: hdrNeed1xStr =%s", __func__, hdrNeed1xStr);
8280     if (hdrNeed1xStr != NULL) {
8281         int value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
8282                 hdrNeed1xStr);
8283         if (value != NAME_NOT_FOUND) {
8284             updateParamEntry(KEY_QC_HDR_NEED_1X, hdrNeed1xStr);
8285             m_bHDR1xFrameEnabled = !strncmp(hdrNeed1xStr, VALUE_TRUE, strlen(VALUE_TRUE));
8286             m_bNeedRestart = true;
8287 
8288             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR_NEED_1X,
8289                     m_bHDR1xFrameEnabled)) {
8290                 return BAD_VALUE;
8291             }
8292             return NO_ERROR;
8293         }
8294     }
8295 
8296     CDBG_HIGH("Invalid hdr need 1x value: %s",
8297             (hdrNeed1xStr == NULL) ? "NULL" : hdrNeed1xStr);
8298     return BAD_VALUE;
8299 }
8300 
8301 /*===========================================================================
8302  * FUNCTION   : setAEBracketing
8303  *
8304  * DESCRIPTION: enables AE bracketing
8305  *
8306  * PARAMETERS :
8307  *
8308  * RETURN     : int32_t type of status
8309  *              NO_ERROR  -- success
8310  *              none-zero failure code
8311  *==========================================================================*/
setAEBracketing()8312 int32_t QCameraParameters::setAEBracketing()
8313 {
8314     int32_t rc = NO_ERROR;
8315     if(initBatchUpdate(m_pParamBuf) < 0 ) {
8316         ALOGE("%s:Failed to initialize group update table", __func__);
8317         return BAD_TYPE;
8318     }
8319 
8320     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, m_AEBracketingClient)) {
8321         ALOGE("%s:Failed to update AE bracketing", __func__);
8322         return BAD_VALUE;
8323     }
8324 
8325     rc = commitSetBatch();
8326     if (rc != NO_ERROR) {
8327         ALOGE("%s:Failed to configure AE bracketing", __func__);
8328         return rc;
8329     }
8330 
8331     return rc;
8332 }
8333 
8334 /*===========================================================================
8335  * FUNCTION   : setHDRAEBracket
8336  *
8337  * DESCRIPTION: enables AE bracketing for HDR
8338  *
8339  * PARAMETERS :
8340  *   @hdrBracket : HDR bracketing configuration
8341  *
8342  * RETURN     : int32_t type of status
8343  *              NO_ERROR  -- success
8344  *              none-zero failure code
8345  *==========================================================================*/
setHDRAEBracket(cam_exp_bracketing_t hdrBracket)8346 int32_t QCameraParameters::setHDRAEBracket(cam_exp_bracketing_t hdrBracket)
8347 {
8348     int32_t rc = NO_ERROR;
8349     if(initBatchUpdate(m_pParamBuf) < 0 ) {
8350         ALOGE("%s:Failed to initialize group update table", __func__);
8351         return BAD_TYPE;
8352     }
8353 
8354     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, hdrBracket)) {
8355         ALOGE("%s:Failed to update table", __func__);
8356         return BAD_TYPE;
8357     }
8358 
8359     rc = commitSetBatch();
8360     if (rc != NO_ERROR) {
8361         ALOGE("%s:Failed to configure HDR bracketing", __func__);
8362         return rc;
8363     }
8364 
8365     return rc;
8366 }
8367 
8368 /*===========================================================================
8369  * FUNCTION   : restoreAEBracket
8370  *
8371  * DESCRIPTION: restores client AE bracketing configuration after HDR is done
8372  *
8373  * PARAMETERS :
8374  *
8375  * RETURN     : int32_t type of status
8376  *              NO_ERROR  -- success
8377  *              none-zero failure code
8378  *==========================================================================*/
stopAEBracket()8379 int32_t QCameraParameters::stopAEBracket()
8380 {
8381   cam_exp_bracketing_t bracketing;
8382 
8383   bracketing.mode = CAM_EXP_BRACKETING_OFF;
8384 
8385   return setHDRAEBracket(bracketing);
8386 }
8387 
8388 /*===========================================================================
8389  * FUNCTION   : updateFlash
8390  *
8391  * DESCRIPTION: restores client flash configuration or disables flash
8392  *
8393  * PARAMETERS :
8394  *   @commitSettings : flag indicating whether settings need to be commited
8395  *
8396  * RETURN     : int32_t type of status
8397  *              NO_ERROR  -- success
8398  *              none-zero failure code
8399  *==========================================================================*/
updateFlash(bool commitSettings)8400 int32_t QCameraParameters::updateFlash(bool commitSettings)
8401 {
8402     int32_t rc = NO_ERROR;
8403     int32_t value;
8404 
8405     if (commitSettings) {
8406       if(initBatchUpdate(m_pParamBuf) < 0 ) {
8407           ALOGE("%s:Failed to initialize group update table", __func__);
8408           return BAD_TYPE;
8409       }
8410     }
8411 
8412     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
8413           m_bOptiZoomOn || m_bReFocusOn) {
8414         value = CAM_FLASH_MODE_OFF;
8415     } else if (m_bChromaFlashOn) {
8416         value = CAM_FLASH_MODE_ON;
8417     } else {
8418         value = mFlashValue;
8419     }
8420 
8421     if (value != mFlashDaemonValue) {
8422         CDBG("%s: Setting Flash value %d", __func__, value);
8423         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, value)) {
8424             ALOGE("%s:Failed to set led mode", __func__);
8425             return BAD_VALUE;
8426         }
8427         mFlashDaemonValue = value;
8428     } else {
8429         rc = NO_ERROR;
8430     }
8431 
8432     if (commitSettings) {
8433         rc = commitSetBatch();
8434         if (rc != NO_ERROR) {
8435             ALOGE("%s:Failed to configure HDR bracketing", __func__);
8436             return rc;
8437         }
8438     }
8439 
8440     return rc;
8441 }
8442 
8443 /*===========================================================================
8444  * FUNCTION   : setRedeyeReduction
8445  *
8446  * DESCRIPTION: set red eye reduction value
8447  *
8448  * PARAMETERS :
8449  *   @redeyeStr : red eye reduction value string
8450  *
8451  * RETURN     : int32_t type of status
8452  *              NO_ERROR  -- success
8453  *              none-zero failure code
8454  *==========================================================================*/
setRedeyeReduction(const char * redeyeStr)8455 int32_t QCameraParameters::setRedeyeReduction(const char *redeyeStr)
8456 {
8457     if (redeyeStr != NULL) {
8458         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8459                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), redeyeStr);
8460         if (value != NAME_NOT_FOUND) {
8461             CDBG("%s: Setting RedEye Reduce value %s", __func__, redeyeStr);
8462             updateParamEntry(KEY_QC_REDEYE_REDUCTION, redeyeStr);
8463             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
8464                     CAM_INTF_PARM_REDEYE_REDUCTION, value)) {
8465                 return BAD_VALUE;
8466             }
8467             return NO_ERROR;
8468         }
8469     }
8470     ALOGE("%s: Invalid RedEye Reduce value: %s",
8471           __func__, (redeyeStr == NULL) ? "NULL" : redeyeStr);
8472     return BAD_VALUE;
8473 }
8474 
8475 /*===========================================================================
8476  * FUNCTION   : getDenoiseProcessPlate
8477  *
8478  * DESCRIPTION: query denoise process plate
8479  *
8480  * PARAMETERS : None
8481  *
8482  * RETURN     : NR process plate vlaue
8483  *==========================================================================*/
8484 cam_denoise_process_type_t
getDenoiseProcessPlate(cam_intf_parm_type_t type)8485         QCameraParameters::getDenoiseProcessPlate(cam_intf_parm_type_t type)
8486 {
8487     char prop[PROPERTY_VALUE_MAX];
8488     memset(prop, 0, sizeof(prop));
8489     cam_denoise_process_type_t processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
8490     if (CAM_INTF_PARM_WAVELET_DENOISE == type) {
8491         property_get("persist.denoise.process.plates", prop, "");
8492     } else if (CAM_INTF_PARM_TEMPORAL_DENOISE == type) {
8493         property_get("persist.tnr.process.plates", prop, "");
8494     } else {
8495         ALOGE("%s: Type not supported", __func__);
8496         prop[0] = '\0';
8497     }
8498     if (strlen(prop) > 0) {
8499         switch(atoi(prop)) {
8500         case 0:
8501             processPlate = CAM_WAVELET_DENOISE_YCBCR_PLANE;
8502             break;
8503         case 1:
8504             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
8505             break;
8506         case 2:
8507             processPlate = CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
8508             break;
8509         case 3:
8510             processPlate = CAM_WAVELET_DENOISE_STREAMLINED_CBCR;
8511             break;
8512         default:
8513             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
8514             break;
8515         }
8516     }
8517     return processPlate;
8518 }
8519 
8520 /*===========================================================================
8521  * FUNCTION   : setWaveletDenoise
8522  *
8523  * DESCRIPTION: set wavelet denoise value
8524  *
8525  * PARAMETERS :
8526  *   @wnrStr : wavelet denoise value string
8527  *
8528  * RETURN     : int32_t type of status
8529  *              NO_ERROR  -- success
8530  *              none-zero failure code
8531  *==========================================================================*/
setWaveletDenoise(const char * wnrStr)8532 int32_t QCameraParameters::setWaveletDenoise(const char *wnrStr)
8533 {
8534     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) == 0){
8535         CDBG_HIGH("%s: WNR is not supported",__func__);
8536         return NO_ERROR;
8537     }
8538 
8539     if (wnrStr != NULL) {
8540         int value = lookupAttr(DENOISE_ON_OFF_MODES_MAP,
8541                 PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP), wnrStr);
8542         if (value != NAME_NOT_FOUND) {
8543             updateParamEntry(KEY_QC_DENOISE, wnrStr);
8544 
8545             cam_denoise_param_t temp;
8546             memset(&temp, 0, sizeof(temp));
8547             temp.denoise_enable = (uint8_t)value;
8548             m_bWNROn = (value != 0);
8549             if (m_bWNROn) {
8550                 temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_WAVELET_DENOISE);
8551             }
8552             CDBG("%s: Denoise enable=%d, plates=%d",
8553                   __func__, temp.denoise_enable, temp.process_plates);
8554             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WAVELET_DENOISE, temp)) {
8555                 return BAD_VALUE;
8556             }
8557             return NO_ERROR;
8558         }
8559     }
8560     ALOGE("%s: Invalid Denoise value: %s", __func__, (wnrStr == NULL) ? "NULL" : wnrStr);
8561     return BAD_VALUE;
8562 }
8563 
8564 /*===========================================================================
8565  * FUNCTION   : setRdiMode
8566  *
8567  * DESCRIPTION: set rdi mode value
8568  *
8569  * PARAMETERS :
8570  *   @str     : rdi mode value string
8571  *
8572  * RETURN     : int32_t type of status
8573  *              NO_ERROR  -- success
8574  *              none-zero failure code
8575  *==========================================================================*/
setRdiMode(const char * str)8576 int32_t QCameraParameters::setRdiMode(const char *str)
8577 {
8578     CDBG("RDI_DEBUG %s: rdi mode value: %s", __func__, str);
8579 
8580     if (str != NULL) {
8581         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8582                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
8583         if (value != NAME_NOT_FOUND) {
8584             updateParamEntry(KEY_QC_RDI_MODE, str);
8585             m_bRdiMode = (value == 0) ? false : true;
8586             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RDI_MODE, value)) {
8587                 return BAD_VALUE;
8588             }
8589             return NO_ERROR;
8590         }
8591     }
8592     ALOGE("%s: Invalid rdi mode value: %s", __func__, (str == NULL) ? "NULL" : str);
8593     return BAD_VALUE;
8594 }
8595 
8596 
8597 /*===========================================================================
8598  * FUNCTION   : setSecureMode
8599  *
8600  * DESCRIPTION: set secure mode value
8601  *
8602  * PARAMETERS :
8603  *   @str     : secure mode value string
8604  *
8605  * RETURN     : int32_t type of status
8606  *              NO_ERROR  -- success
8607  *              none-zero failure code
8608  *==========================================================================*/
setSecureMode(const char * str)8609 int32_t QCameraParameters::setSecureMode(const char *str)
8610 {
8611   ALOGD("%s: Secure mode value: %s", __func__, str);
8612 
8613   if (str != NULL) {
8614     int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8615             PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
8616     if (value != NAME_NOT_FOUND) {
8617         updateParamEntry(KEY_QC_SECURE_MODE, str);
8618         m_bSecureMode = (value == 0)? false : true;
8619         return NO_ERROR;
8620     }
8621   }
8622   ALOGE("%s: Invalid Secure mode value: %s",
8623     __func__, (str == NULL) ? "NULL" : str);
8624   return BAD_VALUE;
8625 }
8626 
8627 /*===========================================================================
8628  * FUNCTION   : setPreviewFrameRateMode
8629  *
8630  * DESCRIPTION: set preview frame rate mode
8631  *
8632  * PARAMETERS :
8633  *   @mode    : preview frame rate mode
8634  *
8635  * RETURN     : none
8636  *==========================================================================*/
setPreviewFrameRateMode(const char * mode)8637 void QCameraParameters::setPreviewFrameRateMode(const char *mode)
8638 {
8639     set(KEY_QC_PREVIEW_FRAME_RATE_MODE, mode);
8640 }
8641 
8642 /*===========================================================================
8643  * FUNCTION   : getPreviewFrameRateMode
8644  *
8645  * DESCRIPTION: get preview frame rate mode
8646  *
8647  * PARAMETERS : none
8648  *
8649  * RETURN     : preview frame rate mode string
8650  *==========================================================================*/
getPreviewFrameRateMode() const8651 const char *QCameraParameters::getPreviewFrameRateMode() const
8652 {
8653     return get(KEY_QC_PREVIEW_FRAME_RATE_MODE);
8654 }
8655 
8656 /*===========================================================================
8657  * FUNCTION   : setTouchIndexAec
8658  *
8659  * DESCRIPTION: set touch index AEC
8660  *
8661  * PARAMETERS :
8662  *   @x,y     :
8663  *
8664  * RETURN     : none
8665  *==========================================================================*/
setTouchIndexAec(int x,int y)8666 void QCameraParameters::setTouchIndexAec(int x, int y)
8667 {
8668     char str[32];
8669     snprintf(str, sizeof(str), "%dx%d", x, y);
8670     set(KEY_QC_TOUCH_INDEX_AEC, str);
8671 }
8672 
8673 /*===========================================================================
8674  * FUNCTION   : getTouchIndexAec
8675  *
8676  * DESCRIPTION: get touch index AEC
8677  *
8678  * PARAMETERS :
8679  *   @x,y     :
8680  *
8681  * RETURN     : none
8682  *==========================================================================*/
getTouchIndexAec(int * x,int * y)8683 void QCameraParameters::getTouchIndexAec(int *x, int *y)
8684 {
8685     *x = -1;
8686     *y = -1;
8687 
8688     // Get the current string, if it doesn't exist, leave the -1x-1
8689     const char *p = get(KEY_QC_TOUCH_INDEX_AEC);
8690     if (p == 0)
8691         return;
8692 
8693     int tempX, tempY;
8694     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
8695         *x = tempX;
8696         *y = tempY;
8697     }
8698 }
8699 
8700 /*===========================================================================
8701  * FUNCTION   : setTouchIndexAf
8702  *
8703  * DESCRIPTION: set touch index AF
8704  *
8705  * PARAMETERS :
8706  *   @x,y     :
8707  *
8708  * RETURN     : none
8709  *==========================================================================*/
setTouchIndexAf(int x,int y)8710 void QCameraParameters::setTouchIndexAf(int x, int y)
8711 {
8712     char str[32];
8713     snprintf(str, sizeof(str), "%dx%d", x, y);
8714     set(KEY_QC_TOUCH_INDEX_AF, str);
8715 }
8716 
8717 /*===========================================================================
8718  * FUNCTION   : getTouchIndexAf
8719  *
8720  * DESCRIPTION: get touch index AF
8721  *
8722  * PARAMETERS :
8723  *   @x,y     :
8724  *
8725  * RETURN     : none
8726  *==========================================================================*/
getTouchIndexAf(int * x,int * y)8727 void QCameraParameters::getTouchIndexAf(int *x, int *y)
8728 {
8729     *x = -1;
8730     *y = -1;
8731 
8732     // Get the current string, if it doesn't exist, leave the -1x-1
8733     const char *p = get(KEY_QC_TOUCH_INDEX_AF);
8734     if (p == 0)
8735         return;
8736 
8737     int tempX, tempY;
8738     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
8739         *x = tempX;
8740         *y = tempY;
8741     }
8742 }
8743 
8744 /*===========================================================================
8745  * FUNCTION   : getStreamFormat
8746  *
8747  * DESCRIPTION: get stream format by its type
8748  *
8749  * PARAMETERS :
8750  *   @streamType : [input] stream type
8751  *   @format     : [output] stream format
8752  *
8753  * RETURN     : int32_t type of status
8754  *              NO_ERROR  -- success
8755  *              none-zero failure code
8756  *==========================================================================*/
getStreamRotation(cam_stream_type_t streamType,cam_pp_feature_config_t & featureConfig,cam_dimension_t & dim)8757 int32_t QCameraParameters::getStreamRotation(cam_stream_type_t streamType,
8758                                             cam_pp_feature_config_t &featureConfig,
8759                                             cam_dimension_t &dim)
8760 {
8761     int32_t ret = NO_ERROR;
8762     const char *str = get(KEY_QC_VIDEO_ROTATION);
8763     int rotationParam = lookupAttr(VIDEO_ROTATION_MODES_MAP,
8764             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
8765     featureConfig.rotation = ROTATE_0;
8766     int swapDim = 0;
8767     switch (streamType) {
8768         case CAM_STREAM_TYPE_VIDEO:
8769             switch(rotationParam) {
8770                 case 90:
8771                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
8772                     featureConfig.rotation = ROTATE_90;
8773                     swapDim = 1;
8774                     break;
8775                 case 180:
8776                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
8777                     featureConfig.rotation = ROTATE_180;
8778                     break;
8779                 case 270:
8780                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
8781                     featureConfig.rotation = ROTATE_270;
8782                     swapDim = 1;
8783                     break;
8784                 default:
8785                     featureConfig.rotation = ROTATE_0;
8786             }
8787             break;
8788         case CAM_STREAM_TYPE_PREVIEW:
8789         case CAM_STREAM_TYPE_POSTVIEW:
8790         case CAM_STREAM_TYPE_SNAPSHOT:
8791         case CAM_STREAM_TYPE_RAW:
8792         case CAM_STREAM_TYPE_METADATA:
8793         case CAM_STREAM_TYPE_OFFLINE_PROC:
8794         case CAM_STREAM_TYPE_DEFAULT:
8795         default:
8796             break;
8797     }
8798 
8799     if (swapDim > 0) {
8800         int w = 0;
8801         w = dim.width;
8802         dim.width = dim.height;
8803         dim.height = w;
8804     }
8805     return ret;
8806 }
8807 
8808 /*===========================================================================
8809  * FUNCTION   : getStreamFormat
8810  *
8811  * DESCRIPTION: get stream format by its type
8812  *
8813  * PARAMETERS :
8814  *   @streamType : [input] stream type
8815  *   @format     : [output] stream format
8816  *
8817  * RETURN     : int32_t type of status
8818  *              NO_ERROR  -- success
8819  *              none-zero failure code
8820  *==========================================================================*/
getStreamFormat(cam_stream_type_t streamType,cam_format_t & format)8821 int32_t QCameraParameters::getStreamFormat(cam_stream_type_t streamType,
8822                                             cam_format_t &format)
8823 {
8824     int32_t ret = NO_ERROR;
8825 
8826     format = CAM_FORMAT_MAX;
8827     switch (streamType) {
8828     case CAM_STREAM_TYPE_PREVIEW:
8829     case CAM_STREAM_TYPE_POSTVIEW:
8830     case CAM_STREAM_TYPE_CALLBACK:
8831         format = mPreviewFormat;
8832         break;
8833     case CAM_STREAM_TYPE_ANALYSIS:
8834         if (m_pCapability->analysis_recommended_format ==
8835                 CAM_FORMAT_Y_ONLY) {
8836             format = m_pCapability->analysis_recommended_format;
8837         } else {
8838             ALOGE("%s:%d invalid analysis_recommended_format %d\n",
8839                     __func__, __LINE__,
8840                     m_pCapability->analysis_recommended_format);
8841             format = mPreviewFormat;
8842         }
8843       break;
8844     case CAM_STREAM_TYPE_SNAPSHOT:
8845         if ( mPictureFormat == CAM_FORMAT_YUV_422_NV16 ) {
8846             format = CAM_FORMAT_YUV_422_NV16;
8847         } else {
8848             char prop[PROPERTY_VALUE_MAX];
8849             int snapshotFormat;
8850             memset(prop, 0, sizeof(prop));
8851             property_get("persist.camera.snap.format", prop, "0");
8852             snapshotFormat = atoi(prop);
8853             if(snapshotFormat == 1) {
8854                 format = CAM_FORMAT_YUV_422_NV61;
8855             } else {
8856                 format = CAM_FORMAT_YUV_420_NV21;
8857             }
8858         }
8859         break;
8860     case CAM_STREAM_TYPE_VIDEO:
8861         format = CAM_FORMAT_YUV_420_NV12;
8862         break;
8863     case CAM_STREAM_TYPE_RAW:
8864         if (isRdiMode()) {
8865             format = m_pCapability->rdi_mode_stream_fmt;
8866         } else if (mPictureFormat >= CAM_FORMAT_YUV_RAW_8BIT_YUYV) {
8867             format = (cam_format_t)mPictureFormat;
8868         } else if (getofflineRAW()) {
8869             format = CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR;
8870         } else {
8871             char raw_format[PROPERTY_VALUE_MAX];
8872             int rawFormat;
8873             memset(raw_format, 0, sizeof(raw_format));
8874             /*Default value is CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG*/
8875             property_get("persist.camera.raw.format", raw_format, "16");
8876             rawFormat = atoi(raw_format);
8877             format = (cam_format_t)rawFormat;
8878             CDBG_HIGH("%s: Raw stream format %d bundled with snapshot",
8879                    __func__, format);
8880         }
8881         break;
8882     case CAM_STREAM_TYPE_METADATA:
8883     case CAM_STREAM_TYPE_OFFLINE_PROC:
8884     case CAM_STREAM_TYPE_DEFAULT:
8885     default:
8886         break;
8887     }
8888 
8889     return ret;
8890 }
8891 
8892 /*===========================================================================
8893  * FUNCTION   : getFlipMode
8894  *
8895  * DESCRIPTION: get flip mode
8896  *
8897  * PARAMETERS :
8898  *   @cam_intf_parm_type_t : [input] stream type
8899  *
8900  * RETURN     : int type of flip mode
8901  *              0 - no filp
8902  *              1 - FLIP_H
8903  *              2 - FLIP_V
8904  *              3 - FLIP_H | FLIP_V
8905  *==========================================================================*/
getFlipMode(cam_stream_type_t type)8906 int QCameraParameters::getFlipMode(cam_stream_type_t type)
8907 {
8908     const char *str = NULL;
8909     int flipMode = 0; // no flip
8910 
8911     switch(type){
8912     case CAM_STREAM_TYPE_PREVIEW:
8913         if (!isRdiMode()) {
8914             str = get(KEY_QC_PREVIEW_FLIP);
8915         }
8916         break;
8917     case CAM_STREAM_TYPE_VIDEO:
8918         str = get(KEY_QC_VIDEO_FLIP);
8919         break;
8920     case CAM_STREAM_TYPE_SNAPSHOT:
8921     case CAM_STREAM_TYPE_POSTVIEW:
8922         str = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
8923         break;
8924     default:
8925         CDBG("%s: No flip mode for stream type %d", __func__, type);
8926         break;
8927     }
8928 
8929     if(str != NULL){
8930         //Need give corresponding filp value based on flip mode strings
8931         int value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
8932         if(value != NAME_NOT_FOUND)
8933             flipMode = value;
8934         }
8935 
8936     CDBG_HIGH("%s: the filp mode of stream type %d is %d .", __func__, type, flipMode);
8937     return flipMode;
8938 }
8939 
8940 /*===========================================================================
8941  * FUNCTION   : isSnapshotFDNeeded
8942  *
8943  * DESCRIPTION: check whether Face Detection Metadata is needed
8944  *
8945  * PARAMETERS : none
8946  *
8947  * RETURN     : bool type of status
8948  *              0 - need
8949  *              1 - not need
8950  *==========================================================================*/
isSnapshotFDNeeded()8951 bool QCameraParameters::isSnapshotFDNeeded()
8952 {
8953     return getInt(KEY_QC_SNAPSHOT_FD_DATA);
8954 }
8955 
8956 /*===========================================================================
8957  * FUNCTION   : getStreamDimension
8958  *
8959  * DESCRIPTION: get stream dimension by its type
8960  *
8961  * PARAMETERS :
8962  *   @streamType : [input] stream type
8963  *   @dim        : [output] stream dimension
8964  *
8965  * RETURN     : int32_t type of status
8966  *              NO_ERROR  -- success
8967  *              none-zero failure code
8968  *==========================================================================*/
getStreamDimension(cam_stream_type_t streamType,cam_dimension_t & dim)8969 int32_t QCameraParameters::getStreamDimension(cam_stream_type_t streamType,
8970                                                cam_dimension_t &dim)
8971 {
8972     int32_t ret = NO_ERROR;
8973     memset(&dim, 0, sizeof(cam_dimension_t));
8974 
8975     switch (streamType) {
8976     case CAM_STREAM_TYPE_PREVIEW:
8977         getPreviewSize(&dim.width, &dim.height);
8978         break;
8979     case CAM_STREAM_TYPE_POSTVIEW:
8980         getPreviewSize(&dim.width, &dim.height);
8981         break;
8982     case CAM_STREAM_TYPE_SNAPSHOT:
8983         if (getRecordingHintValue() == true) {
8984             // live snapshot
8985             getLiveSnapshotSize(dim);
8986         } else {
8987             getPictureSize(&dim.width, &dim.height);
8988         }
8989         break;
8990     case CAM_STREAM_TYPE_VIDEO:
8991         getVideoSize(&dim.width, &dim.height);
8992         break;
8993     case CAM_STREAM_TYPE_RAW:
8994         //dim = m_pCapability->raw_dim;
8995         getRawSize(dim);
8996         break;
8997     case CAM_STREAM_TYPE_METADATA:
8998         dim.width = (int32_t)sizeof(metadata_buffer_t);
8999         dim.height = 1;
9000         break;
9001     case CAM_STREAM_TYPE_OFFLINE_PROC:
9002         break;
9003     case CAM_STREAM_TYPE_ANALYSIS:
9004         cam_dimension_t prv_dim, max_dim;
9005 
9006         /* Analysis stream need aspect ratio as preview stream */
9007         getPreviewSize(&prv_dim.width, &prv_dim.height);
9008 
9009         max_dim.width = m_pCapability->analysis_max_res.width;
9010         max_dim.height = m_pCapability->analysis_max_res.height;
9011 
9012         if (prv_dim.width > max_dim.width || prv_dim.height > max_dim.height) {
9013             double max_ratio, requested_ratio;
9014 
9015             max_ratio = (double)max_dim.width / (double)max_dim.height;
9016             requested_ratio = (double)prv_dim.width / (double)prv_dim.height;
9017 
9018             if (max_ratio < requested_ratio) {
9019                 dim.width = max_dim.width;
9020                 dim.height = (int32_t)((double)dim.width / requested_ratio);
9021             } else {
9022                 dim.height = max_dim.height;
9023                 dim.width = (int32_t)((double)max_dim.height * requested_ratio);
9024             }
9025             dim.width &= ~0x1;
9026             dim.height &= ~0x1;
9027         } else {
9028             dim.width = prv_dim.width;
9029             dim.height = prv_dim.height;
9030         }
9031       break;
9032     case CAM_STREAM_TYPE_DEFAULT:
9033     default:
9034         ALOGE("%s: no dimension for unsupported stream type %d",
9035               __func__, streamType);
9036         ret = BAD_VALUE;
9037         break;
9038     }
9039     return ret;
9040 }
9041 
9042 /*===========================================================================
9043  * FUNCTION   : getPreviewHalPixelFormat
9044  *
9045  * DESCRIPTION: get preview HAL pixel format
9046  *
9047  * PARAMETERS : none
9048  *
9049  * RETURN     : HAL pixel format
9050  *==========================================================================*/
getPreviewHalPixelFormat() const9051 int QCameraParameters::getPreviewHalPixelFormat() const
9052 {
9053     int32_t halPixelFormat;
9054 
9055     switch (mPreviewFormat) {
9056     case CAM_FORMAT_YUV_420_NV12:
9057         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
9058         break;
9059     case CAM_FORMAT_YUV_420_NV21:
9060         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
9061         break;
9062     case CAM_FORMAT_YUV_420_NV21_ADRENO:
9063         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
9064         break;
9065     case CAM_FORMAT_YUV_420_YV12:
9066         halPixelFormat = HAL_PIXEL_FORMAT_YV12;
9067         break;
9068     case CAM_FORMAT_YUV_420_NV12_VENUS:
9069         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;
9070         break;
9071     case CAM_FORMAT_YUV_422_NV16:
9072     case CAM_FORMAT_YUV_422_NV61:
9073     default:
9074         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
9075         break;
9076     }
9077     CDBG_HIGH("%s: format %d\n", __func__, halPixelFormat);
9078     return halPixelFormat;
9079 }
9080 
9081 /*===========================================================================
9082  * FUNCTION   : getthumbnailSize
9083  *
9084  * DESCRIPTION: get thumbnail size
9085  *
9086  * PARAMETERS :
9087  *   @width, height : [output] thumbnail width and height
9088  *
9089  * RETURN     : none
9090  *==========================================================================*/
getThumbnailSize(int * width,int * height) const9091 void QCameraParameters::getThumbnailSize(int *width, int *height) const
9092 {
9093     *width = getInt(KEY_JPEG_THUMBNAIL_WIDTH);
9094     *height = getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
9095 }
9096 
9097 /*===========================================================================
9098  * FUNCTION   : getZSLBurstInterval
9099  *
9100  * DESCRIPTION: get ZSL burst interval setting
9101  *
9102  * PARAMETERS : none
9103  *
9104  * RETURN     : ZSL burst interval value
9105  *==========================================================================*/
getZSLBurstInterval()9106 uint8_t QCameraParameters::getZSLBurstInterval()
9107 {
9108     int interval = getInt(KEY_QC_ZSL_BURST_INTERVAL);
9109     if (interval < 0) {
9110         interval = 1;
9111     }
9112     return (uint8_t)interval;
9113 }
9114 
9115 /*===========================================================================
9116  * FUNCTION   : getZSLQueueDepth
9117  *
9118  * DESCRIPTION: get ZSL queue depth
9119  *
9120  * PARAMETERS : none
9121  *
9122  * RETURN     : ZSL queue depth value
9123  *==========================================================================*/
getZSLQueueDepth()9124 uint8_t QCameraParameters::getZSLQueueDepth()
9125 {
9126     int qdepth = getInt(KEY_QC_ZSL_QUEUE_DEPTH);
9127     if (qdepth < 0) {
9128         qdepth = 2;
9129     }
9130     return (uint8_t)qdepth;
9131 }
9132 
9133 /*===========================================================================
9134  * FUNCTION   : getZSLBackLookCount
9135  *
9136  * DESCRIPTION: get ZSL backlook count setting
9137  *
9138  * PARAMETERS : none
9139  *
9140  * RETURN     : ZSL backlook count value
9141  *==========================================================================*/
getZSLBackLookCount()9142 uint8_t QCameraParameters::getZSLBackLookCount()
9143 {
9144     int look_back = getInt(KEY_QC_ZSL_BURST_LOOKBACK);
9145     if (look_back < 0) {
9146         look_back = 2;
9147     }
9148     return (uint8_t)look_back;
9149 }
9150 
9151 /*===========================================================================
9152  * FUNCTION   : getZSLMaxUnmatchedFrames
9153  *
9154  * DESCRIPTION: get allowed ZSL max unmatched frames number
9155  *
9156  * PARAMETERS : none
9157  *
9158  * RETURN     : ZSL backlook count value
9159  *==========================================================================*/
getMaxUnmatchedFramesInQueue()9160 uint8_t QCameraParameters::getMaxUnmatchedFramesInQueue()
9161 {
9162     return (uint8_t)(m_pCapability->min_num_pp_bufs + (m_nBurstNum / 10));
9163 }
9164 
9165 /*===========================================================================
9166  * FUNCTION   : setRecordingHintValue
9167  *
9168  * DESCRIPTION: set recording hint
9169  *
9170  * PARAMETERS :
9171  *   @value   : video hint value
9172  *
9173  * RETURN     : int32_t type of status
9174  *              NO_ERROR  -- success
9175  *              none-zero failure code
9176  *==========================================================================*/
setRecordingHintValue(int32_t value)9177 int QCameraParameters::setRecordingHintValue(int32_t value)
9178 {
9179     CDBG_HIGH("%s: VideoHint = %d", __func__, value);
9180     bool newValue = (value > 0)? true : false;
9181 
9182     if ( m_bRecordingHint != newValue ) {
9183         m_bNeedRestart = true;
9184         m_bRecordingHint_new = newValue;
9185     } else {
9186         m_bRecordingHint_new = m_bRecordingHint;
9187     }
9188     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RECORDING_HINT, value)) {
9189         return BAD_VALUE;
9190     }
9191 
9192     return NO_ERROR;
9193 }
9194 
9195 /*===========================================================================
9196  * FUNCTION   : getNumOfSnapshots
9197  *
9198  * DESCRIPTION: get number of snapshot per shutter
9199  *
9200  * PARAMETERS : none
9201  *
9202  * RETURN     : number of snapshot per shutter
9203  *==========================================================================*/
getNumOfSnapshots()9204 uint8_t QCameraParameters::getNumOfSnapshots()
9205 {
9206     uint8_t numOfSnapshot = 1;
9207     int val = getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER);
9208     if (0 < val) {
9209         numOfSnapshot = (uint8_t)val;
9210     }
9211 
9212     return (uint8_t)numOfSnapshot;
9213 }
9214 
9215 /*===========================================================================
9216  * FUNCTION   : getBurstCountForAdvancedCapture
9217  *
9218  * DESCRIPTION: get burst count for advanced capture.
9219  *
9220  * PARAMETERS : none
9221  *
9222  * RETURN     : number of snapshot required for advanced capture.
9223  *==========================================================================*/
getBurstCountForAdvancedCapture()9224 uint8_t QCameraParameters::getBurstCountForAdvancedCapture()
9225 {
9226     uint32_t burstCount = 0;
9227     if (isUbiFocusEnabled()) {
9228         //number of snapshots required for Ubi Focus.
9229         burstCount = m_pCapability->ubifocus_af_bracketing_need.burst_count;
9230     } else if (isUbiRefocus()) {
9231         //number of snapshots required for Opti Zoom.
9232         burstCount = m_pCapability->refocus_af_bracketing_need.burst_count;
9233     } else if (isOptiZoomEnabled()) {
9234         //number of snapshots required for Opti Zoom.
9235         burstCount = m_pCapability->opti_zoom_settings_need.burst_count;
9236     } else if (isChromaFlashEnabled()) {
9237         //number of snapshots required for Chroma Flash.
9238         burstCount = m_pCapability->chroma_flash_settings_need.burst_count;
9239     } else if (isStillMoreEnabled()) {
9240         //number of snapshots required for Still More.
9241         if (isSeeMoreEnabled()) {
9242             burstCount = 1;
9243         } else if ((m_stillmore_config.burst_count >=
9244                 m_pCapability->stillmore_settings_need.min_burst_count) &&
9245                 (m_stillmore_config.burst_count <=
9246                 m_pCapability->stillmore_settings_need.max_burst_count)) {
9247             burstCount = m_stillmore_config.burst_count;
9248         } else {
9249             burstCount = m_pCapability->stillmore_settings_need.burst_count;
9250         }
9251     } else if (isHDREnabled()) {
9252         //number of snapshots required for HDR.
9253         burstCount = m_pCapability->hdr_bracketing_setting.num_frames;
9254     } else if (isAEBracketEnabled()) {
9255       burstCount = 0;
9256       const char *str_val = m_AEBracketingClient.values;
9257       if ((str_val != NULL) && (strlen(str_val) > 0)) {
9258           char prop[PROPERTY_VALUE_MAX];
9259           memset(prop, 0, sizeof(prop));
9260           strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
9261           char *saveptr = NULL;
9262           char *token = strtok_r(prop, ",", &saveptr);
9263           while (token != NULL) {
9264               token = strtok_r(NULL, ",", &saveptr);
9265               burstCount++;
9266           }
9267       }
9268     }
9269     if (burstCount <= 0) {
9270         burstCount = 1;
9271     }
9272 
9273     CDBG_HIGH("%s: Snapshot burst count = %d", __func__, burstCount);
9274     return (uint8_t)burstCount;
9275 }
9276 
9277 /*===========================================================================
9278  * FUNCTION   : getNumOfRetroSnapshots
9279  *
9280  * DESCRIPTION: get number of retro active snapshots per shutter
9281  *
9282  * PARAMETERS : none
9283  *
9284  * RETURN     : number of retro active snapshots per shutter
9285  *==========================================================================*/
getNumOfRetroSnapshots()9286 uint8_t QCameraParameters::getNumOfRetroSnapshots()
9287 {
9288     int numOfRetroSnapshots = getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
9289     if (numOfRetroSnapshots < 0) {
9290         numOfRetroSnapshots = 0;
9291     }
9292     CDBG_HIGH("%s: [ZSL Retro] : numOfRetroSnaps - %d", __func__, numOfRetroSnapshots);
9293     return (uint8_t)numOfRetroSnapshots;
9294 }
9295 
9296 /*===========================================================================
9297  * FUNCTION   : getBurstLEDOnPeriod
9298  *
9299  * DESCRIPTION: get burst LED on period
9300  *
9301  * PARAMETERS : none
9302  *
9303  * RETURN     : burst LED on period
9304  *==========================================================================*/
getBurstLEDOnPeriod()9305 int QCameraParameters::getBurstLEDOnPeriod()
9306 {
9307   CDBG_HIGH("%s: [ZSL Retro] burst LED ON period: %d", __func__, m_nBurstLEDOnPeriod);
9308   return m_nBurstLEDOnPeriod;
9309 }
9310 
9311 /*===========================================================================
9312  * FUNCTION   : getNumOfExtraHDRInBufsIfNeeded
9313  *
9314  * DESCRIPTION: get number of extra input buffers needed by HDR
9315  *
9316  * PARAMETERS : none
9317  *
9318  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
9319  *==========================================================================*/
getNumOfExtraHDRInBufsIfNeeded()9320 uint8_t QCameraParameters::getNumOfExtraHDRInBufsIfNeeded()
9321 {
9322     unsigned int numOfBufs = 0;
9323 
9324     if (isHDREnabled()) {
9325         numOfBufs += m_pCapability->hdr_bracketing_setting.num_frames;
9326         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
9327             numOfBufs++;
9328         }
9329         numOfBufs--; // Only additional buffers need to be returned
9330     }
9331 
9332     return (uint8_t)(numOfBufs * getBurstNum());
9333 }
9334 
9335 /*===========================================================================
9336  * FUNCTION   : getNumOfExtraHDROutBufsIfNeeded
9337  *
9338  * DESCRIPTION: get number of extra output buffers needed by HDR
9339  *
9340  * PARAMETERS : none
9341  *
9342  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
9343  *==========================================================================*/
getNumOfExtraHDROutBufsIfNeeded()9344 uint8_t QCameraParameters::getNumOfExtraHDROutBufsIfNeeded()
9345 {
9346     int numOfBufs = 0;
9347 
9348     if (isHDREnabled() && isHDR1xFrameEnabled()) {
9349         numOfBufs++;
9350     }
9351 
9352     return (uint8_t)(numOfBufs * getBurstNum());
9353 }
9354 
9355 /*===========================================================================
9356  * FUNCTION   : getBurstNum
9357  *
9358  * DESCRIPTION: get burst number of snapshot
9359  *
9360  * PARAMETERS : none
9361  *
9362  * RETURN     : number of burst
9363  *==========================================================================*/
getBurstNum()9364 uint8_t QCameraParameters::getBurstNum()
9365 {
9366     CDBG_HIGH("%s: m_nBurstNum = %d", __func__, m_nBurstNum);
9367     return m_nBurstNum;
9368 }
9369 
9370 /*===========================================================================
9371  * FUNCTION   : getJpegQuality
9372  *
9373  * DESCRIPTION: get jpeg encoding quality
9374  *
9375  * PARAMETERS : none
9376  *
9377  * RETURN     : jpeg encoding quality
9378  *==========================================================================*/
getJpegQuality()9379 uint32_t QCameraParameters::getJpegQuality()
9380 {
9381     int quality = getInt(KEY_JPEG_QUALITY);
9382     if (quality < 0) {
9383         quality = 85; // set to default quality value
9384     }
9385     return (uint32_t)quality;
9386 }
9387 
9388 /*===========================================================================
9389  * FUNCTION   : getRotation
9390  *
9391  * DESCRIPTION: get application configured rotation
9392  *
9393  * PARAMETERS : none
9394  *
9395  * RETURN     : rotation value
9396  *==========================================================================*/
getRotation()9397 uint32_t QCameraParameters::getRotation() {
9398     int rotation = 0;
9399 
9400     //If exif rotation is set, do not rotate captured image
9401     if (!useJpegExifRotation()) {
9402         rotation = mRotation;
9403         if (rotation < 0) {
9404             rotation = 0;
9405         }
9406     }
9407     return (uint32_t)rotation;
9408 }
9409 
9410 /*===========================================================================
9411  * FUNCTION   : setJpegRotation
9412  *
9413  * DESCRIPTION: set jpeg rotation value configured internally
9414  *
9415  * PARAMETERS : none
9416  *
9417  * RETURN     : jpeg rotation value
9418  *==========================================================================*/
setJpegRotation(int rotation)9419 void QCameraParameters::setJpegRotation(int rotation) {
9420     if (rotation == 0 || rotation == 90 ||
9421             rotation == 180 || rotation == 270) {
9422         mJpegRotation = (uint32_t)rotation;
9423     }
9424 }
9425 
9426 /*===========================================================================
9427  * FUNCTION   : getDeviceRotation
9428  *
9429  * DESCRIPTION: get device rotation value
9430  *
9431  * PARAMETERS : none
9432  *
9433  * RETURN     : device rotation value
9434  *==========================================================================*/
getDeviceRotation()9435 uint32_t QCameraParameters::getDeviceRotation() {
9436     int rotation = 0;
9437 
9438     rotation = mRotation;
9439     if (rotation < 0) {
9440         rotation = 0;
9441     }
9442 
9443     return (uint32_t)rotation;
9444 }
9445 
9446 /*===========================================================================
9447  * FUNCTION   : getJpegExifRotation
9448  *
9449  * DESCRIPTION: get exif rotation value
9450  *
9451  * PARAMETERS : none
9452  *
9453  * RETURN     : rotation value
9454  *==========================================================================*/
getJpegExifRotation()9455 uint32_t QCameraParameters::getJpegExifRotation() {
9456     int rotation = 0;
9457 
9458     if (useJpegExifRotation()) {
9459         rotation = mRotation;
9460         if (rotation < 0) {
9461             rotation = 0;
9462         }
9463     }
9464     return (uint32_t)rotation;
9465 }
9466 
9467 /*===========================================================================
9468  * FUNCTION   : useJpegExifRotation
9469  *
9470  * DESCRIPTION: Check if jpeg exif rotation need to be used
9471  *
9472  * PARAMETERS : none
9473  *
9474  * RETURN     : true if jpeg exif rotation need to be used
9475  *==========================================================================*/
useJpegExifRotation()9476 bool QCameraParameters::useJpegExifRotation() {
9477     char exifRotation[PROPERTY_VALUE_MAX];
9478 
9479     property_get("persist.camera.exif.rotation", exifRotation, "off");
9480     if (!strcmp(exifRotation, "on")) {
9481         return true;
9482     }
9483     return false;
9484 }
9485 
9486 /*===========================================================================
9487  * FUNCTION   : getEffectValue
9488  *
9489  * DESCRIPTION: get effect value
9490  *
9491  * PARAMETERS : none
9492  *
9493  * RETURN     : effect value
9494  *==========================================================================*/
getEffectValue()9495 int32_t QCameraParameters::getEffectValue()
9496 {
9497     uint32_t cnt = 0;
9498     const char *effect = get(KEY_EFFECT);
9499     if (effect) {
9500         while (NULL != EFFECT_MODES_MAP[cnt].desc) {
9501             if (!strcmp(EFFECT_MODES_MAP[cnt].desc, effect)) {
9502                 return EFFECT_MODES_MAP[cnt].val;
9503             }
9504             cnt++;
9505         }
9506     } else {
9507         ALOGE("%s: Missing effect value", __func__);
9508     }
9509     return CAM_EFFECT_MODE_OFF;
9510 }
9511 
9512 /*===========================================================================
9513  * FUNCTION   : parseGPSCoordinate
9514  *
9515  * DESCRIPTION: parse GPS coordinate string
9516  *
9517  * PARAMETERS :
9518  *   @coord_str : [input] coordinate string
9519  *   @coord     : [output]  ptr to struct to store coordinate
9520  *
9521  * RETURN     : int32_t type of status
9522  *              NO_ERROR  -- success
9523  *              none-zero failure code
9524  *==========================================================================*/
parseGPSCoordinate(const char * coord_str,rat_t * coord)9525 int QCameraParameters::parseGPSCoordinate(const char *coord_str, rat_t* coord)
9526 {
9527     if(coord == NULL) {
9528         ALOGE("%s: error, invalid argument coord == NULL", __func__);
9529         return BAD_VALUE;
9530     }
9531     double degF = atof(coord_str);
9532     if (degF < 0) {
9533         degF = -degF;
9534     }
9535     double minF = (degF - (double)(int) degF) * 60.0;
9536     double secF = (minF - (double)(int) minF) * 60.0;
9537 
9538     getRational(&coord[0], (int)degF, 1);
9539     getRational(&coord[1], (int)minF, 1);
9540     getRational(&coord[2], (int)(secF * 10000.0), 10000);
9541     return NO_ERROR;
9542 }
9543 
9544 /*===========================================================================
9545  * FUNCTION   : getExifDateTime
9546  *
9547  * DESCRIPTION: query exif date time
9548  *
9549  * PARAMETERS :
9550  *   @dateTime    : String to store exif date time.
9551  *                  Should be leaved unchanged in case of error.
9552  *   @subsecTime  : String to store exif time nanoseconds.
9553  *                  Should be leaved unchanged in case of error.
9554  *
9555  * RETURN     : int32_t type of status
9556  *              NO_ERROR  -- success
9557  *              none-zero failure code
9558  *==========================================================================*/
getExifDateTime(String8 & dateTime,String8 & subsecTime)9559 int32_t QCameraParameters::getExifDateTime(String8 &dateTime, String8 &subsecTime)
9560 {
9561     int32_t ret = NO_ERROR;
9562 
9563     //get time and date from system
9564     struct timeval tv;
9565     struct tm timeinfo_data;
9566 
9567     int res = gettimeofday(&tv, NULL);
9568     if (0 == res) {
9569         struct tm *timeinfo = localtime_r(&tv.tv_sec, &timeinfo_data);
9570         if (NULL != timeinfo) {
9571             //Write datetime according to EXIF Spec
9572             //"YYYY:MM:DD HH:MM:SS" (20 chars including \0)
9573             dateTime = String8::format("%04d:%02d:%02d %02d:%02d:%02d",
9574                     timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
9575                     timeinfo->tm_mday, timeinfo->tm_hour,
9576                     timeinfo->tm_min, timeinfo->tm_sec);
9577             //Write subsec according to EXIF Sepc
9578             subsecTime = String8::format("%06ld", tv.tv_usec);
9579         } else {
9580             ALOGE("%s: localtime_r() error", __func__);
9581             ret = UNKNOWN_ERROR;
9582         }
9583     } else if (-1 == res) {
9584         ALOGE("%s: gettimeofday() error: %s", __func__, strerror(errno));
9585         ret = UNKNOWN_ERROR;
9586     } else {
9587         ALOGE("%s: gettimeofday() unexpected return code: %d", __func__, res);
9588         ret = UNKNOWN_ERROR;
9589     }
9590 
9591     return ret;
9592 }
9593 
9594 /*===========================================================================
9595  * FUNCTION   : getRational
9596  *
9597  * DESCRIPTION: compose rational struct
9598  *
9599  * PARAMETERS :
9600  *   @rat     : ptr to struct to store rational info
9601  *   @num     :num of the rational
9602  *   @denom   : denom of the rational
9603  *
9604  * RETURN     : int32_t type of status
9605  *              NO_ERROR  -- success
9606  *              none-zero failure code
9607  *==========================================================================*/
getRational(rat_t * rat,int num,int denom)9608 int32_t QCameraParameters::getRational(rat_t *rat, int num, int denom)
9609 {
9610     if ((0 > num) || (0 > denom)) {
9611         ALOGE("%s: Negative values", __func__);
9612         return BAD_VALUE;
9613     }
9614     if (NULL == rat) {
9615         ALOGE("%s: NULL rat input", __func__);
9616         return BAD_VALUE;
9617     }
9618     rat->num = (uint32_t)num;
9619     rat->denom = (uint32_t)denom;
9620     return NO_ERROR;
9621 }
9622 
9623 /*===========================================================================
9624  * FUNCTION   : getExifFocalLength
9625  *
9626  * DESCRIPTION: get exif focal lenght
9627  *
9628  * PARAMETERS :
9629  *   @focalLength : ptr to rational strcut to store focal lenght
9630  *
9631  * RETURN     : int32_t type of status
9632  *              NO_ERROR  -- success
9633  *              none-zero failure code
9634  *==========================================================================*/
getExifFocalLength(rat_t * focalLength)9635 int32_t QCameraParameters::getExifFocalLength(rat_t *focalLength)
9636 {
9637     int focalLengthValue =
9638         (int)(getFloat(QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION);
9639     return getRational(focalLength, focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION);
9640 }
9641 
9642 /*===========================================================================
9643  * FUNCTION   : getExifIsoSpeed
9644  *
9645  * DESCRIPTION: get exif ISO speed
9646  *
9647  * PARAMETERS : none
9648  *
9649  * RETURN     : ISO speed value
9650  *==========================================================================*/
getExifIsoSpeed()9651 uint16_t QCameraParameters::getExifIsoSpeed()
9652 {
9653     uint16_t isoSpeed = 0;
9654     const char *iso_str = get(QCameraParameters::KEY_QC_ISO_MODE);
9655     int iso_index = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), iso_str);
9656     switch (iso_index) {
9657     case CAM_ISO_MODE_AUTO:
9658         isoSpeed = 0;
9659         break;
9660     case CAM_ISO_MODE_DEBLUR:
9661         isoSpeed = 1;
9662         break;
9663     case CAM_ISO_MODE_100:
9664         isoSpeed = 100;
9665         break;
9666     case CAM_ISO_MODE_200:
9667         isoSpeed = 200;
9668         break;
9669     case CAM_ISO_MODE_400:
9670         isoSpeed = 400;
9671         break;
9672     case CAM_ISO_MODE_800:
9673         isoSpeed = 800;
9674         break;
9675     case CAM_ISO_MODE_1600:
9676         isoSpeed = 1600;
9677         break;
9678     case CAM_ISO_MODE_3200:
9679         isoSpeed = 3200;
9680         break;
9681     }
9682     return isoSpeed;
9683 }
9684 
9685 /*===========================================================================
9686  * FUNCTION   : getExifGpsProcessingMethod
9687  *
9688  * DESCRIPTION: get GPS processing method
9689  *
9690  * PARAMETERS :
9691  *   @gpsProcessingMethod : string to store GPS process method
9692  *   @count               : lenght of the string
9693  *
9694  * RETURN     : int32_t type of status
9695  *              NO_ERROR  -- success
9696  *              none-zero failure code
9697  *==========================================================================*/
getExifGpsProcessingMethod(char * gpsProcessingMethod,uint32_t & count)9698 int32_t QCameraParameters::getExifGpsProcessingMethod(char *gpsProcessingMethod,
9699                                                       uint32_t &count)
9700 {
9701     const char *str = get(KEY_GPS_PROCESSING_METHOD);
9702     if(str != NULL) {
9703         memcpy(gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE);
9704         count = EXIF_ASCII_PREFIX_SIZE;
9705         strlcpy(gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, strlen(str)+1);
9706         count += (uint32_t)strlen(str);
9707         gpsProcessingMethod[count++] = '\0'; // increase 1 for the last NULL char
9708         return NO_ERROR;
9709     } else {
9710         return BAD_VALUE;
9711     }
9712 }
9713 
9714 /*===========================================================================
9715  * FUNCTION   : getExifLatitude
9716  *
9717  * DESCRIPTION: get exif latitude
9718  *
9719  * PARAMETERS :
9720  *   @latitude : ptr to rational struct to store latitude info
9721  *   @ladRef   : charater to indicate latitude reference
9722  *
9723  * RETURN     : int32_t type of status
9724  *              NO_ERROR  -- success
9725  *              none-zero failure code
9726  *==========================================================================*/
getExifLatitude(rat_t * latitude,char * latRef)9727 int32_t QCameraParameters::getExifLatitude(rat_t *latitude,
9728                                            char *latRef)
9729 {
9730     const char *str = get(KEY_GPS_LATITUDE);
9731     if(str != NULL) {
9732         parseGPSCoordinate(str, latitude);
9733 
9734         //set Latitude Ref
9735         float latitudeValue = getFloat(KEY_GPS_LATITUDE);
9736         if(latitudeValue < 0.0f) {
9737             latRef[0] = 'S';
9738         } else {
9739             latRef[0] = 'N';
9740         }
9741         latRef[1] = '\0';
9742         return NO_ERROR;
9743     }else{
9744         return BAD_VALUE;
9745     }
9746 }
9747 
9748 /*===========================================================================
9749  * FUNCTION   : getExifLongitude
9750  *
9751  * DESCRIPTION: get exif longitude
9752  *
9753  * PARAMETERS :
9754  *   @longitude : ptr to rational struct to store longitude info
9755  *   @lonRef    : charater to indicate longitude reference
9756  *
9757  * RETURN     : int32_t type of status
9758  *              NO_ERROR  -- success
9759  *              none-zero failure code
9760  *==========================================================================*/
getExifLongitude(rat_t * longitude,char * lonRef)9761 int32_t QCameraParameters::getExifLongitude(rat_t *longitude,
9762                                             char *lonRef)
9763 {
9764     const char *str = get(KEY_GPS_LONGITUDE);
9765     if(str != NULL) {
9766         parseGPSCoordinate(str, longitude);
9767 
9768         //set Longitude Ref
9769         float longitudeValue = getFloat(KEY_GPS_LONGITUDE);
9770         if(longitudeValue < 0.0f) {
9771             lonRef[0] = 'W';
9772         } else {
9773             lonRef[0] = 'E';
9774         }
9775         lonRef[1] = '\0';
9776         return NO_ERROR;
9777     }else{
9778         return BAD_VALUE;
9779     }
9780 }
9781 
9782 /*===========================================================================
9783  * FUNCTION   : getExifAltitude
9784  *
9785  * DESCRIPTION: get exif altitude
9786  *
9787  * PARAMETERS :
9788  *   @altitude : ptr to rational struct to store altitude info
9789  *   @altRef   : charater to indicate altitude reference
9790  *
9791  * RETURN     : int32_t type of status
9792  *              NO_ERROR  -- success
9793  *              none-zero failure code
9794  *==========================================================================*/
getExifAltitude(rat_t * altitude,char * altRef)9795 int32_t QCameraParameters::getExifAltitude(rat_t *altitude,
9796                                            char *altRef)
9797 {
9798     const char *str = get(KEY_GPS_ALTITUDE);
9799     if(str != NULL) {
9800         double value = atof(str);
9801         *altRef = 0;
9802         if(value < 0){
9803             *altRef = 1;
9804             value = -value;
9805         }
9806         return getRational(altitude, (int)(value*1000), 1000);
9807     }else{
9808         return BAD_VALUE;
9809     }
9810 }
9811 
9812 /*===========================================================================
9813  * FUNCTION   : getExifGpsDateTimeStamp
9814  *
9815  * DESCRIPTION: get exif GPS date time stamp
9816  *
9817  * PARAMETERS :
9818  *   @gpsDateStamp : GPS date time stamp string
9819  *   @bufLen       : length of the string
9820  *   @gpsTimeStamp : ptr to rational struct to store time stamp info
9821  *
9822  * RETURN     : int32_t type of status
9823  *              NO_ERROR  -- success
9824  *              none-zero failure code
9825  *==========================================================================*/
getExifGpsDateTimeStamp(char * gpsDateStamp,uint32_t bufLen,rat_t * gpsTimeStamp)9826 int32_t QCameraParameters::getExifGpsDateTimeStamp(char *gpsDateStamp,
9827                                                    uint32_t bufLen,
9828                                                    rat_t *gpsTimeStamp)
9829 {
9830     const char *str = get(KEY_GPS_TIMESTAMP);
9831     if(str != NULL) {
9832         time_t unixTime = (time_t)atol(str);
9833         struct tm *UTCTimestamp = gmtime(&unixTime);
9834 
9835         if(!UTCTimestamp) {
9836             ALOGE("%s: UTCTimestamp is null\n", __func__);
9837             return BAD_VALUE;
9838         }
9839 
9840         strftime(gpsDateStamp, bufLen, "%Y:%m:%d", UTCTimestamp);
9841 
9842         getRational(&gpsTimeStamp[0], UTCTimestamp->tm_hour, 1);
9843         getRational(&gpsTimeStamp[1], UTCTimestamp->tm_min, 1);
9844         getRational(&gpsTimeStamp[2], UTCTimestamp->tm_sec, 1);
9845 
9846         return NO_ERROR;
9847     } else {
9848         return BAD_VALUE;
9849     }
9850 }
9851 
9852 /*===========================================================================
9853  * FUNCTION   : updateFocusDistances
9854  *
9855  * DESCRIPTION: update focus distances
9856  *
9857  * PARAMETERS :
9858  *   @focusDistances : ptr to focus distance info
9859  *
9860  * RETURN     : int32_t type of status
9861  *              NO_ERROR  -- success
9862  *              none-zero failure code
9863  *==========================================================================*/
updateFocusDistances(cam_focus_distances_info_t * focusDistances)9864 int32_t QCameraParameters::updateFocusDistances(cam_focus_distances_info_t *focusDistances)
9865 {
9866     String8 str;
9867     char buffer[32] = {0};
9868     //set all distances to infinity if focus mode is infinity
9869     if(mFocusMode == CAM_FOCUS_MODE_INFINITY) {
9870         str.append("Infinity,Infinity,Infinity");
9871     } else {
9872         snprintf(buffer, sizeof(buffer), "%f", focusDistances->focus_distance[0]);
9873         str.append(buffer);
9874         snprintf(buffer, sizeof(buffer), ",%f", focusDistances->focus_distance[1]);
9875         str.append(buffer);
9876         snprintf(buffer, sizeof(buffer), ",%f", focusDistances->focus_distance[2]);
9877         str.append(buffer);
9878     }
9879     CDBG_HIGH("%s: setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string());
9880     set(QCameraParameters::KEY_FOCUS_DISTANCES, str.string());
9881     return NO_ERROR;
9882 }
9883 
9884 /*===========================================================================
9885  * FUNCTION   : updateRecordingHintValue
9886  *
9887  * DESCRIPTION: update recording hint locally and to daemon
9888  *
9889  * PARAMETERS :
9890  *   @value   : video hint value
9891  *
9892  * RETURN     : int32_t type of status
9893  *              NO_ERROR  -- success
9894  *              none-zero failure code
9895  *==========================================================================*/
updateRecordingHintValue(int32_t value)9896 int32_t QCameraParameters::updateRecordingHintValue(int32_t value)
9897 {
9898     int32_t rc = NO_ERROR;
9899     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9900         ALOGE("%s:Failed to initialize group update table", __func__);
9901         return BAD_TYPE;
9902     }
9903 
9904     rc = setRecordingHintValue(value);
9905     if (rc != NO_ERROR) {
9906         ALOGE("%s:Failed to update table", __func__);
9907         return rc;
9908     }
9909 
9910     if(m_bDISEnabled && (value==1)) {
9911         CDBG_HIGH("%s: %d: Setting DIS value again!!", __func__, __LINE__);
9912         setDISValue(VALUE_ENABLE);
9913     }
9914 
9915     rc = commitSetBatch();
9916     if (rc != NO_ERROR) {
9917         ALOGE("%s:Failed to update recording hint", __func__);
9918         return rc;
9919     }
9920 
9921     return rc;
9922 }
9923 
9924 /*===========================================================================
9925  * FUNCTION   : setHistogram
9926  *
9927  * DESCRIPTION: set histogram
9928  *
9929  * PARAMETERS :
9930  *   @enabled : if histogram is enabled
9931  *
9932  * RETURN     : int32_t type of status
9933  *              NO_ERROR  -- success
9934  *              none-zero failure code
9935  *==========================================================================*/
setHistogram(bool enabled)9936 int32_t QCameraParameters::setHistogram(bool enabled)
9937 {
9938     if(m_bHistogramEnabled == enabled) {
9939         CDBG_HIGH("%s: histogram flag not changed, no ops here", __func__);
9940         return NO_ERROR;
9941     }
9942 
9943     // set parm for histogram
9944     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9945         ALOGE("%s:Failed to initialize group update table", __func__);
9946         return BAD_TYPE;
9947     }
9948 
9949     int32_t value = enabled ? 1 : 0;
9950     int32_t rc = NO_ERROR;
9951     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HISTOGRAM, value)) {
9952         ALOGE("%s:Failed to update table", __func__);
9953         return BAD_VALUE;
9954     }
9955 
9956     rc = commitSetBatch();
9957     if (rc != NO_ERROR) {
9958         ALOGE("%s:Failed to set histogram", __func__);
9959         return rc;
9960     }
9961 
9962     m_bHistogramEnabled = enabled;
9963 
9964     CDBG_HIGH(" Histogram -> %s", m_bHistogramEnabled ? "Enabled" : "Disabled");
9965 
9966     return rc;
9967 }
9968 
9969 /*===========================================================================
9970  * FUNCTION   : setIntEvent
9971  *
9972  * DESCRIPTION: set setIntEvent
9973  *
9974  * PARAMETERS :
9975  *   @params : image size and dimensions
9976  *
9977  * RETURN     : int32_t type of status
9978  *              NO_ERROR  -- success
9979  *              none-zero failure code
9980  *==========================================================================*/
setIntEvent(cam_int_evt_params_t params)9981 int32_t QCameraParameters::setIntEvent(cam_int_evt_params_t params)
9982 {
9983     int32_t rc = NO_ERROR;
9984 
9985     if ( m_pParamBuf == NULL ) {
9986         return NO_INIT;
9987     }
9988 
9989     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9990         ALOGE("%s:Failed to initialize group update table", __func__);
9991         return BAD_TYPE;
9992     }
9993 
9994     //Sending snapshot taken notification back to Eztune"
9995     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INT_EVT, params)) {
9996         ALOGE("%s:Failed to update table", __func__);
9997         return BAD_VALUE;
9998     }
9999 
10000     rc = commitSetBatch();
10001     if (rc != NO_ERROR) {
10002         ALOGE("%s:Failed to set frameskip info parm", __func__);
10003         return rc;
10004     }
10005 
10006     return rc;
10007 }
10008 
10009 /*===========================================================================
10010  * FUNCTION   : setFaceDetectionOption
10011  *
10012  * DESCRIPTION: set if face detection is enabled by SendCommand
10013  *
10014  * PARAMETERS :
10015  *   @enabled : bool flag if face detection should be enabled
10016  *
10017  * RETURN     : int32_t type of status
10018  *              NO_ERROR  -- success
10019  *              none-zero failure code
10020  *==========================================================================*/
setFaceDetectionOption(bool enabled)10021  int32_t QCameraParameters::setFaceDetectionOption(bool enabled)
10022 {
10023     m_bFaceDetectionOn = enabled;
10024     return NO_ERROR;
10025 }
10026 
10027 /*===========================================================================
10028  * FUNCTION   : setFaceDetection
10029  *
10030  * DESCRIPTION: set face detection
10031  *
10032  * PARAMETERS :
10033  *   @enabled : if face detection is enabled
10034  *   @initCommit : if configuration list need to be initialized and commited
10035  *
10036  * RETURN     : int32_t type of status
10037  *              NO_ERROR  -- success
10038  *              none-zero failure code
10039  *==========================================================================*/
setFaceDetection(bool enabled,bool initCommit)10040 int32_t QCameraParameters::setFaceDetection(bool enabled, bool initCommit)
10041 {
10042     uint32_t faceProcMask = m_nFaceProcMask;
10043     // set face detection mask
10044     if (enabled) {
10045         faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
10046     } else {
10047         faceProcMask &= ~CAM_FACE_PROCESS_MASK_DETECTION;
10048     }
10049 
10050     if(m_nFaceProcMask == faceProcMask) {
10051         CDBG_HIGH("%s: face process mask not changed, no ops here", __func__);
10052         return NO_ERROR;
10053     }
10054 
10055     m_nFaceProcMask = faceProcMask;
10056 
10057     // set parm for face detection
10058     uint32_t requested_faces = (uint32_t)getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
10059     cam_fd_set_parm_t fd_set_parm;
10060     memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
10061     fd_set_parm.fd_mode = faceProcMask;
10062     fd_set_parm.num_fd = requested_faces;
10063 
10064     CDBG_HIGH("[KPI Perf] %s: PROFILE_FACE_DETECTION_VALUE = %d num_fd = %d",
10065           __func__, faceProcMask,requested_faces);
10066 
10067     if (initCommit) {
10068         if(initBatchUpdate(m_pParamBuf) < 0 ) {
10069             ALOGE("%s:Failed to initialize group update table", __func__);
10070             return BAD_TYPE;
10071         }
10072     }
10073 
10074     int32_t rc = NO_ERROR;
10075 
10076     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
10077         ALOGE("%s:Failed to update table", __func__);
10078         return BAD_VALUE;
10079     }
10080 
10081     if (initCommit) {
10082         rc = commitSetBatch();
10083         if (rc != NO_ERROR) {
10084             ALOGE("%s:Failed to set face detection parm", __func__);
10085             return rc;
10086         }
10087     }
10088 
10089     CDBG_HIGH("%s: FaceProcMask -> %d", __func__, m_nFaceProcMask);
10090 
10091     return rc;
10092 }
10093 
10094 /*===========================================================================
10095  * FUNCTION   : setFrameSkip
10096  *
10097  * DESCRIPTION: send ISP frame skip pattern to camera daemon
10098  *
10099  * PARAMETERS :
10100  *   @pattern : skip pattern for ISP
10101  *
10102  * RETURN     : int32_t type of status
10103  *              NO_ERROR  -- success
10104  *              none-zero failure code
10105  *==========================================================================*/
setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)10106 int32_t QCameraParameters::setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)
10107 {
10108     int32_t rc = NO_ERROR;
10109 
10110     if ( m_pParamBuf == NULL ) {
10111         return NO_INIT;
10112     }
10113 
10114     if(initBatchUpdate(m_pParamBuf) < 0 ) {
10115         ALOGE("%s:Failed to initialize group update table", __func__);
10116         return BAD_TYPE;
10117     }
10118 
10119     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FRAMESKIP, (int32_t)pattern)) {
10120         ALOGE("%s:Failed to update table", __func__);
10121         return BAD_VALUE;
10122     }
10123 
10124     rc = commitSetBatch();
10125     if (rc != NO_ERROR) {
10126         ALOGE("%s:Failed to set frameskip info parm", __func__);
10127         return rc;
10128     }
10129 
10130     return rc;
10131 }
10132 
updateRAW(cam_dimension_t max_dim)10133 int32_t QCameraParameters::updateRAW(cam_dimension_t max_dim)
10134 {
10135     int32_t rc = NO_ERROR;
10136     cam_dimension_t raw_dim;
10137 
10138     if (max_dim.width == 0 || max_dim.height == 0) {
10139         max_dim = m_pCapability->raw_dim[0];
10140     }
10141 
10142     if(initBatchUpdate(m_pParamBuf) < 0 ) {
10143         ALOGE("%s:Failed to initialize group update table", __func__);
10144         return BAD_TYPE;
10145     }
10146 
10147     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MAX_DIMENSION, max_dim)) {
10148         ALOGE("%s:Failed to update table for CAM_INTF_PARM_MAX_DIMENSION ", __func__);
10149         return BAD_VALUE;
10150     }
10151 
10152     rc = commitSetBatch();
10153     if (rc != NO_ERROR) {
10154         ALOGE("%s:Failed to set lock CAM_INTF_PARM_MAX_DIMENSION parm", __func__);
10155         return rc;
10156     }
10157 
10158     if(initBatchUpdate(m_pParamBuf) < 0 ) {
10159         ALOGE("%s:Failed to initialize group update table", __func__);
10160         return BAD_TYPE;
10161     }
10162 
10163     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION);
10164 
10165     rc = commitGetBatch();
10166     if (rc != NO_ERROR) {
10167         ALOGE("%s:Failed to get commit CAM_INTF_PARM_RAW_DIMENSION", __func__);
10168         return rc;
10169     }
10170 
10171     READ_PARAM_ENTRY(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION, raw_dim);
10172 
10173     CDBG_HIGH("%s : RAW Dimension = %d X %d",__func__,raw_dim.width,raw_dim.height);
10174     if (raw_dim.width == 0 || raw_dim.height == 0) {
10175         ALOGE("%s: Error getting RAW size. Setting to Capability value",__func__);
10176         raw_dim = m_pCapability->raw_dim[0];
10177     }
10178     setRawSize(raw_dim);
10179     return rc;
10180 }
10181 
10182 /*===========================================================================
10183  * FUNCTION   : setHDRSceneEnable
10184  *
10185  * DESCRIPTION: sets hdr scene deteced flag
10186  *
10187  * PARAMETERS :
10188  *   @bflag : hdr scene deteced
10189  *
10190  * RETURN     : nothing
10191  *==========================================================================*/
setHDRSceneEnable(bool bflag)10192 void QCameraParameters::setHDRSceneEnable(bool bflag)
10193 {
10194     bool bupdate = false;
10195     if (m_HDRSceneEnabled != bflag) {
10196         bupdate = true;
10197     }
10198     m_HDRSceneEnabled = bflag;
10199 
10200     if (bupdate) {
10201         updateFlash(true);
10202     }
10203 }
10204 
10205 /*===========================================================================
10206  * FUNCTION   : getASDStateString
10207  *
10208  * DESCRIPTION: get ASD result in string format
10209  *
10210  * PARAMETERS :
10211  *   @scene : selected scene mode
10212  *
10213  * RETURN     : int32_t type of status
10214  *              NO_ERROR  -- success
10215  *              none-zero failure code
10216  *==========================================================================*/
getASDStateString(cam_auto_scene_t scene)10217  const char *QCameraParameters::getASDStateString(cam_auto_scene_t scene)
10218 {
10219     switch (scene) {
10220       case S_NORMAL :
10221         return "Normal";
10222       case S_SCENERY:
10223         return "Scenery";
10224       case S_PORTRAIT:
10225         return "Portrait";
10226       case S_PORTRAIT_BACKLIGHT:
10227         return "Portrait-Backlight";
10228       case S_SCENERY_BACKLIGHT:
10229         return "Scenery-Backlight";
10230       case S_BACKLIGHT:
10231         return "Backlight";
10232       default:
10233         return "<Unknown!>";
10234       }
10235 }
10236 
10237 /*===========================================================================
10238  * FUNCTION   : parseNDimVector
10239  *
10240  * DESCRIPTION: helper function to parse a string like "(1, 2, 3, 4, ..., N)"
10241  *              into N-dimension vector
10242  *
10243  * PARAMETERS :
10244  *   @str     : string to be parsed
10245  *   @num     : output array of size N to store vector element values
10246  *   @N       : number of dimension
10247  *   @delim   : delimeter to seperete string
10248  *
10249  * RETURN     : int32_t type of status
10250  *              NO_ERROR  -- success
10251  *              none-zero failure code
10252  *==========================================================================*/
parseNDimVector(const char * str,int * num,int N,char delim=',')10253 int32_t QCameraParameters::parseNDimVector(const char *str, int *num, int N, char delim = ',')
10254 {
10255     char *start, *end;
10256     if (num == NULL) {
10257         ALOGE("%s: Invalid output array (num == NULL)", __func__);
10258         return BAD_VALUE;
10259     }
10260 
10261     //check if string starts and ends with parantheses
10262     if(str[0] != '(' || str[strlen(str)-1] != ')') {
10263         ALOGE("%s: Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)",
10264               __func__, str);
10265         return BAD_VALUE;
10266     }
10267     start = (char*) str;
10268     start++;
10269     for(int i=0; i<N; i++) {
10270         *(num+i) = (int) strtol(start, &end, 10);
10271         if(*end != delim && i < N-1) {
10272             ALOGE("%s: Cannot find delimeter '%c' in string \"%s\". end = %c",
10273                   __func__, delim, str, *end);
10274             return -1;
10275         }
10276         start = end+1;
10277     }
10278     return NO_ERROR;
10279 }
10280 
10281 /*===========================================================================
10282  * FUNCTION   : parseCameraAreaString
10283  *
10284  * DESCRIPTION: helper function to parse a string of camera areas like
10285  *              "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..."
10286  *
10287  * PARAMETERS :
10288  *   @str             : string to be parsed
10289  *   @max_num_areas   : max number of areas
10290  *   @pAreas          : ptr to struct to store areas
10291  *   @num_areas_found : number of areas found
10292  *
10293  * RETURN     : int32_t type of status
10294  *              NO_ERROR  -- success
10295  *              none-zero failure code
10296  *==========================================================================*/
parseCameraAreaString(const char * str,int max_num_areas,cam_area_t * pAreas,int & num_areas_found)10297 int32_t QCameraParameters::parseCameraAreaString(const char *str,
10298                                                  int max_num_areas,
10299                                                  cam_area_t *pAreas,
10300                                                  int& num_areas_found)
10301 {
10302     char area_str[32];
10303     const char *start, *end, *p;
10304     start = str; end = NULL;
10305     int values[5], index=0;
10306     num_areas_found = 0;
10307 
10308     memset(values, 0, sizeof(values));
10309     while(start != NULL) {
10310        if(*start != '(') {
10311             ALOGE("%s: error: Ill formatted area string: %s", __func__, str);
10312             return BAD_VALUE;
10313        }
10314        end = strchr(start, ')');
10315        if(end == NULL) {
10316             ALOGE("%s: error: Ill formatted area string: %s", __func__, str);
10317             return BAD_VALUE;
10318        }
10319        int i;
10320        for (i=0,p=start; p<=end; p++, i++) {
10321            area_str[i] = *p;
10322        }
10323        area_str[i] = '\0';
10324        if(parseNDimVector(area_str, values, 5) < 0){
10325             ALOGE("%s: error: Failed to parse the area string: %s", __func__, area_str);
10326             return BAD_VALUE;
10327        }
10328        // no more areas than max_num_areas are accepted.
10329        if(index >= max_num_areas) {
10330             ALOGE("%s: error: too many areas specified %s", __func__, str);
10331             return BAD_VALUE;
10332        }
10333        pAreas[index].rect.left = values[0];
10334        pAreas[index].rect.top = values[1];
10335        pAreas[index].rect.width = values[2] - values[0];
10336        pAreas[index].rect.height = values[3] - values[1];
10337        pAreas[index].weight = values[4];
10338 
10339        index++;
10340        start = strchr(end, '('); // serach for next '('
10341     }
10342     num_areas_found = index;
10343     return 0;
10344 }
10345 
10346 /*===========================================================================
10347  * FUNCTION   : validateCameraAreas
10348  *
10349  * DESCRIPTION: helper function to validate camera areas within (-1000, 1000)
10350  *
10351  * PARAMETERS :
10352  *   @areas     : ptr to array of areas
10353  *   @num_areas : number of areas
10354  *
10355  * RETURN     : true --  area is in valid range
10356  *              false -- not valid
10357  *==========================================================================*/
validateCameraAreas(cam_area_t * areas,int num_areas)10358 bool QCameraParameters::validateCameraAreas(cam_area_t *areas, int num_areas)
10359 {
10360     // special case: default area
10361     if (num_areas == 1 &&
10362         areas[0].rect.left == 0 &&
10363         areas[0].rect.top == 0 &&
10364         areas[0].rect.width == 0 &&
10365         areas[0].rect.height == 0 &&
10366         areas[0].weight == 0) {
10367         return true;
10368     }
10369 
10370     for(int i = 0; i < num_areas; i++) {
10371         // left should be >= -1000
10372         if(areas[i].rect.left < -1000) {
10373             return false;
10374         }
10375 
10376         // top  should be >= -1000
10377         if(areas[i].rect.top < -1000) {
10378             return false;
10379         }
10380 
10381         // width or height should be > 0
10382         if (areas[i].rect.width <= 0 || areas[i].rect.height <= 0) {
10383             return false;
10384         }
10385 
10386         // right  should be <= 1000
10387         if(areas[i].rect.left + areas[i].rect.width > 1000) {
10388             return false;
10389         }
10390 
10391         // bottom should be <= 1000
10392         if(areas[i].rect.top + areas[i].rect.height > 1000) {
10393             return false;
10394         }
10395 
10396         // weight should be within (1, 1000)
10397         if (areas[i].weight < 1 || areas[i].weight > 1000) {
10398             return false;
10399         }
10400     }
10401     return true;
10402 }
10403 
10404 /*===========================================================================
10405  * FUNCTION   : isYUVFrameInfoNeeded
10406  *
10407  * DESCRIPTION: In AE-Bracket mode, we need set yuv buffer information for up-layer
10408  *
10409  * PARAMETERS : none
10410  *
10411  * RETURN     : true: needed
10412  *              false: no need
10413  *==========================================================================*/
isYUVFrameInfoNeeded()10414 bool QCameraParameters::isYUVFrameInfoNeeded()
10415 {
10416     //In AE-Bracket mode, we need set raw buffer information for up-layer
10417     if(!isNV21PictureFormat() && !isNV16PictureFormat()){
10418         return false;
10419     }
10420     const char *aecBracketStr =  get(KEY_QC_AE_BRACKET_HDR);
10421 
10422     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
10423             aecBracketStr);
10424     CDBG_HIGH("%s: aecBracketStr=%s, value=%d.", __func__, aecBracketStr, value);
10425     return (value == CAM_EXP_BRACKETING_ON);
10426 }
10427 
10428 /*===========================================================================
10429  * FUNCTION   : getFrameFmtString
10430  *
10431  * DESCRIPTION: get string name of frame format
10432  *
10433  * PARAMETERS :
10434  *   @frame   : frame format
10435  *
10436  * RETURN     : string name of frame format
10437  *==========================================================================*/
getFrameFmtString(cam_format_t fmt)10438 const char *QCameraParameters::getFrameFmtString(cam_format_t fmt)
10439 {
10440     return lookupNameByValue(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), fmt);
10441 }
10442 
10443 /*===========================================================================
10444  * FUNCTION   : initBatchUpdate
10445  *
10446  * DESCRIPTION: init camera parameters buf entries
10447  *
10448  * PARAMETERS :
10449  *   @p_table : ptr to parameter buffer
10450  *
10451  * RETURN     : int32_t type of status
10452  *              NO_ERROR  -- success
10453  *              none-zero failure code
10454  *==========================================================================*/
initBatchUpdate(parm_buffer_t * p_table)10455 int32_t QCameraParameters::initBatchUpdate(parm_buffer_t *p_table)
10456 {
10457     m_tempMap.clear();
10458 
10459     clear_metadata_buffer(p_table);
10460     return NO_ERROR;
10461 }
10462 
10463 /*===========================================================================
10464  * FUNCTION   : commitSetBatch
10465  *
10466  * DESCRIPTION: commit all set parameters in the batch work to backend
10467  *
10468  * PARAMETERS : none
10469  *
10470  * RETURN     : int32_t type of status
10471  *              NO_ERROR  -- success
10472  *              none-zero failure code
10473  *==========================================================================*/
commitSetBatch()10474 int32_t QCameraParameters::commitSetBatch()
10475 {
10476     int32_t rc = NO_ERROR;
10477     int32_t i = 0;
10478 
10479     if (NULL == m_pParamBuf) {
10480         ALOGE("%s: Params not initialized", __func__);
10481         return NO_INIT;
10482     }
10483 
10484     /* Loop to check if atleast one entry is valid */
10485     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
10486         if(m_pParamBuf->is_valid[i])
10487             break;
10488     }
10489 
10490     if (NULL == m_pCamOpsTbl) {
10491         ALOGE("%s: Ops not initialized", __func__);
10492         return NO_INIT;
10493     }
10494 
10495     if (i < CAM_INTF_PARM_MAX) {
10496         rc = m_pCamOpsTbl->ops->set_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
10497     }
10498     if (rc == NO_ERROR) {
10499         // commit change from temp storage into param map
10500         rc = commitParamChanges();
10501     }
10502     return rc;
10503 }
10504 
10505 /*===========================================================================
10506  * FUNCTION   : commitGetBatch
10507  *
10508  * DESCRIPTION: commit all get parameters in the batch work to backend
10509  *
10510  * PARAMETERS : none
10511  *
10512  * RETURN     : int32_t type of status
10513  *              NO_ERROR  -- success
10514  *              none-zero failure code
10515  *==========================================================================*/
commitGetBatch()10516 int32_t QCameraParameters::commitGetBatch()
10517 {
10518     int32_t rc = NO_ERROR;
10519     int32_t i = 0;
10520 
10521     if (NULL == m_pParamBuf) {
10522         ALOGE("%s: Params not initialized", __func__);
10523         return NO_INIT;
10524     }
10525 
10526     /* Loop to check if atleast one entry is valid */
10527     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
10528         if(m_pParamBuf->is_valid[i])
10529             break;
10530     }
10531 
10532     if (NULL == m_pCamOpsTbl) {
10533         ALOGE("%s: Ops not initialized", __func__);
10534         return NO_INIT;
10535     }
10536 
10537     if (i < CAM_INTF_PARM_MAX) {
10538         return m_pCamOpsTbl->ops->get_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
10539     } else {
10540         return NO_ERROR;
10541     }
10542     return rc;
10543 }
10544 
10545 /*===========================================================================
10546  * FUNCTION   : updateParamEntry
10547  *
10548  * DESCRIPTION: update a parameter entry in the local temp map obj
10549  *
10550  * PARAMETERS :
10551  *   @key     : key of the entry
10552  *   @value   : value of the entry
10553  *
10554  * RETURN     : int32_t type of status
10555  *              NO_ERROR  -- success
10556  *              none-zero failure code
10557  *==========================================================================*/
updateParamEntry(const char * key,const char * value)10558 int32_t QCameraParameters::updateParamEntry(const char *key, const char *value)
10559 {
10560     m_tempMap.replaceValueFor(String8(key), String8(value));
10561     return NO_ERROR;
10562 }
10563 
10564 /*===========================================================================
10565  * FUNCTION   : commitParamChanges
10566  *
10567  * DESCRIPTION: commit all changes in local temp map obj into parameter obj
10568  *
10569  * PARAMETERS : none
10570  *
10571  * RETURN     : int32_t type of status
10572  *              NO_ERROR  -- success
10573  *              none-zero failure code
10574  *==========================================================================*/
commitParamChanges()10575 int32_t QCameraParameters::commitParamChanges()
10576 {
10577     size_t size = m_tempMap.size();
10578     for (size_t i = 0; i < size; i++) {
10579         String8 k, v;
10580         k = m_tempMap.keyAt(i);
10581         v = m_tempMap.valueAt(i);
10582         set(k, v);
10583     }
10584     m_tempMap.clear();
10585 
10586     // update local changes
10587     m_bRecordingHint = m_bRecordingHint_new;
10588     m_bZslMode = m_bZslMode_new;
10589 
10590     /* After applying scene mode auto,
10591       Camera effects need to be reapplied */
10592     if ( m_bSceneTransitionAuto ) {
10593         m_bUpdateEffects = true;
10594         m_bSceneTransitionAuto = false;
10595     }
10596 
10597 
10598     return NO_ERROR;
10599 }
10600 
10601 /*===========================================================================
10602  * FUNCTION   : QCameraReprocScaleParam
10603  *
10604  * DESCRIPTION: constructor of QCameraReprocScaleParam
10605  *
10606  * PARAMETERS : none
10607  *
10608  * RETURN     : none
10609  *==========================================================================*/
QCameraReprocScaleParam(QCameraParameters * parent)10610 QCameraReprocScaleParam::QCameraReprocScaleParam(QCameraParameters *parent)
10611   : mParent(parent),
10612     mScaleEnabled(false),
10613     mIsUnderScaling(false),
10614     mScaleDirection(0),
10615     mNeedScaleCnt(0),
10616     mSensorSizeTblCnt(0),
10617     mSensorSizeTbl(NULL),
10618     mTotalSizeTblCnt(0)
10619 {
10620     mPicSizeFromAPK.width = 0;
10621     mPicSizeFromAPK.height = 0;
10622     mPicSizeSetted.width = 0;
10623     mPicSizeSetted.height = 0;
10624     memset(mNeedScaledSizeTbl, 0, sizeof(mNeedScaledSizeTbl));
10625     memset(mTotalSizeTbl, 0, sizeof(mTotalSizeTbl));
10626 }
10627 
10628 /*===========================================================================
10629  * FUNCTION   : ~~QCameraReprocScaleParam
10630  *
10631  * DESCRIPTION: destructor of QCameraReprocScaleParam
10632  *
10633  * PARAMETERS : none
10634  *
10635  * RETURN     : none
10636  *==========================================================================*/
~QCameraReprocScaleParam()10637 QCameraReprocScaleParam::~QCameraReprocScaleParam()
10638 {
10639     //do nothing now.
10640 }
10641 
10642 /*===========================================================================
10643  * FUNCTION   : setScaledSizeTbl
10644  *
10645  * DESCRIPTION: re-set picture size table with dimensions that need scaling if Reproc Scale is enabled
10646  *
10647  * PARAMETERS :
10648  *   @scale_cnt   : count of picture sizes that want scale
10649  *   @scale_tbl    : picture size table that want scale
10650  *   @org_cnt     : sensor supported picture size count
10651  *   @org_tbl      : sensor supported picture size table
10652  *
10653  * RETURN     : int32_t type of status
10654  *              NO_ERROR  -- success
10655  *              none-zero failure code
10656  *==========================================================================*/
setScaleSizeTbl(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)10657 int32_t QCameraReprocScaleParam::setScaleSizeTbl(size_t scale_cnt,
10658         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
10659 {
10660     int32_t rc = NO_ERROR;
10661     size_t i;
10662     mNeedScaleCnt = 0;
10663 
10664     if(!mScaleEnabled || scale_cnt <=0 || scale_tbl == NULL || org_cnt <=0 || org_tbl == NULL){
10665         return BAD_VALUE;    // Do not need scale, so also need not reset picture size table
10666     }
10667 
10668     mSensorSizeTblCnt = org_cnt;
10669     mSensorSizeTbl = org_tbl;
10670     mNeedScaleCnt = checkScaleSizeTable(scale_cnt, scale_tbl, org_cnt, org_tbl);
10671     if(mNeedScaleCnt <= 0){
10672         ALOGE("%s: do not have picture sizes need scaling.", __func__);
10673         return BAD_VALUE;
10674     }
10675 
10676     if(mNeedScaleCnt + org_cnt > MAX_SIZES_CNT){
10677         ALOGE("%s: picture size list exceed the max count.", __func__);
10678         return BAD_VALUE;
10679     }
10680 
10681     //get the total picture size table
10682     mTotalSizeTblCnt = mNeedScaleCnt + org_cnt;
10683 
10684     if (mNeedScaleCnt > MAX_SCALE_SIZES_CNT) {
10685         ALOGE("%s: Error!! mNeedScaleCnt (%d) is more than MAX_SCALE_SIZES_CNT",
10686                 __func__, mNeedScaleCnt);
10687         return BAD_VALUE;
10688     }
10689 
10690     for(i = 0; i < mNeedScaleCnt; i++){
10691         mTotalSizeTbl[i].width = mNeedScaledSizeTbl[i].width;
10692         mTotalSizeTbl[i].height = mNeedScaledSizeTbl[i].height;
10693         CDBG_HIGH("%s: scale picture size: i =%d, width=%d, height=%d.", __func__,
10694             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
10695     }
10696     for(; i < mTotalSizeTblCnt; i++){
10697         mTotalSizeTbl[i].width = org_tbl[i-mNeedScaleCnt].width;
10698         mTotalSizeTbl[i].height = org_tbl[i-mNeedScaleCnt].height;
10699         CDBG_HIGH("%s: sensor supportted picture size: i =%d, width=%d, height=%d.", __func__,
10700             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
10701     }
10702     return rc;
10703 }
10704 
10705 /*===========================================================================
10706  * FUNCTION   : getScaledSizeTblCnt
10707  *
10708  * DESCRIPTION: get picture size cnt that need scale
10709  *
10710  * PARAMETERS : none
10711  *
10712  * RETURN     : uint8_t type of picture size count
10713  *==========================================================================*/
getScaleSizeTblCnt()10714 size_t QCameraReprocScaleParam::getScaleSizeTblCnt()
10715 {
10716     return mNeedScaleCnt;
10717 }
10718 
10719 /*===========================================================================
10720  * FUNCTION   : getScaledSizeTbl
10721  *
10722  * DESCRIPTION: get picture size table that need scale
10723  *
10724  * PARAMETERS :  none
10725  *
10726  * RETURN     : cam_dimension_t list of picture size table
10727  *==========================================================================*/
getScaledSizeTbl()10728 cam_dimension_t *QCameraReprocScaleParam::getScaledSizeTbl()
10729 {
10730     if(!mScaleEnabled)
10731         return NULL;
10732 
10733     return mNeedScaledSizeTbl;
10734 }
10735 
10736 /*===========================================================================
10737  * FUNCTION   : setScaleEnable
10738  *
10739  * DESCRIPTION: enable or disable Reproc Scale
10740  *
10741  * PARAMETERS :
10742  *   @enabled : enable: 1; disable 0
10743  *
10744  * RETURN     : none
10745  *==========================================================================*/
setScaleEnable(bool enabled)10746 void QCameraReprocScaleParam::setScaleEnable(bool enabled)
10747 {
10748     mScaleEnabled = enabled;
10749 }
10750 
10751 /*===========================================================================
10752  * FUNCTION   : isScaleEnabled
10753  *
10754  * DESCRIPTION: check if Reproc Scale is enabled
10755  *
10756  * PARAMETERS :  none
10757  *
10758  * RETURN     : bool type of status
10759  *==========================================================================*/
isScaleEnabled()10760 bool QCameraReprocScaleParam::isScaleEnabled()
10761 {
10762     return mScaleEnabled;
10763 }
10764 
10765 /*===========================================================================
10766  * FUNCTION   : isScalePicSize
10767  *
10768  * DESCRIPTION: check if current picture size is from Scale Table
10769  *
10770  * PARAMETERS :
10771  *   @width     : current picture width
10772  *   @height    : current picture height
10773  *
10774  * RETURN     : bool type of status
10775  *==========================================================================*/
isScalePicSize(int width,int height)10776 bool QCameraReprocScaleParam::isScalePicSize(int width, int height)
10777 {
10778     //Check if the picture size is in scale table
10779     if(mNeedScaleCnt <= 0)
10780         return FALSE;
10781 
10782     for (size_t i = 0; i < mNeedScaleCnt; i++) {
10783         if ((mNeedScaledSizeTbl[i].width == width) && (mNeedScaledSizeTbl[i].height == height)) {
10784             //found match
10785             return TRUE;
10786         }
10787     }
10788 
10789     ALOGE("%s: Not in scale picture size table.", __func__);
10790     return FALSE;
10791 }
10792 
10793 /*===========================================================================
10794  * FUNCTION   : isValidatePicSize
10795  *
10796  * DESCRIPTION: check if current picture size is validate
10797  *
10798  * PARAMETERS :
10799  *   @width     : current picture width
10800  *   @height    : current picture height
10801  *
10802  * RETURN     : bool type of status
10803  *==========================================================================*/
isValidatePicSize(int width,int height)10804 bool QCameraReprocScaleParam::isValidatePicSize(int width, int height)
10805 {
10806     size_t i = 0;
10807 
10808     for(i = 0; i < mSensorSizeTblCnt; i++){
10809         if(mSensorSizeTbl[i].width == width
10810             && mSensorSizeTbl[i].height== height){
10811             return TRUE;
10812         }
10813     }
10814 
10815     for(i = 0; i < mNeedScaleCnt; i++){
10816         if(mNeedScaledSizeTbl[i].width == width
10817             && mNeedScaledSizeTbl[i].height== height){
10818             return TRUE;
10819         }
10820     }
10821 
10822     ALOGE("%s: Invalidate input picture size.", __func__);
10823     return FALSE;
10824 }
10825 
10826 /*===========================================================================
10827  * FUNCTION   : setSensorSupportedPicSize
10828  *
10829  * DESCRIPTION: set sensor supported picture size.
10830  *    For Snapshot stream size configuration, we need use sensor supported size.
10831  *    We will use CPP to do Scaling based on output Snapshot stream.
10832  *
10833  * PARAMETERS : none
10834  *
10835  * RETURN     : int32_t type of status
10836  *              NO_ERROR  -- success
10837  *              none-zero failure code
10838  *==========================================================================*/
setSensorSupportedPicSize()10839 int32_t QCameraReprocScaleParam::setSensorSupportedPicSize()
10840 {
10841     //will find a suitable picture size (here we leave a prossibility to add other scale requirement)
10842     //Currently we only focus on upscaling, and checkScaleSizeTable() has guaranteed the dimension ratio.
10843 
10844     if(!mIsUnderScaling || mSensorSizeTblCnt <= 0)
10845         return BAD_VALUE;
10846 
10847     //We just get the max sensor supported size here.
10848     mPicSizeSetted.width = mSensorSizeTbl[0].width;
10849     mPicSizeSetted.height = mSensorSizeTbl[0].height;
10850 
10851     return NO_ERROR;
10852 }
10853 
10854 
10855 /*===========================================================================
10856  * FUNCTION   : setValidatePicSize
10857  *
10858  * DESCRIPTION: set sensor supported size and change scale status.
10859  *
10860  * PARAMETERS :
10861  *   @width    : input picture width
10862  *   @height   : input picture height
10863  *
10864  * RETURN     : int32_t type of status
10865  *              NO_ERROR  -- success
10866  *              none-zero failure code
10867  *==========================================================================*/
setValidatePicSize(int & width,int & height)10868 int32_t QCameraReprocScaleParam::setValidatePicSize(int &width,int &height)
10869 {
10870     if(!mScaleEnabled)
10871         return BAD_VALUE;
10872 
10873     mIsUnderScaling = FALSE; //default: not under scale
10874 
10875     if(isScalePicSize(width, height)){
10876         // input picture size need scaling operation. Record size from APK and setted
10877         mIsUnderScaling = TRUE;
10878         mPicSizeFromAPK.width = width;
10879         mPicSizeFromAPK.height = height;
10880 
10881         if(setSensorSupportedPicSize() != NO_ERROR)
10882             return BAD_VALUE;
10883 
10884         //re-set picture size to sensor supported size
10885         width = mPicSizeSetted.width;
10886         height = mPicSizeSetted.height;
10887         CDBG_HIGH("%s: mPicSizeFromAPK- with=%d, height=%d, mPicSizeSetted- with =%d, height=%d.",
10888             __func__, mPicSizeFromAPK.width, mPicSizeFromAPK.height, mPicSizeSetted.width, mPicSizeSetted.height);
10889     }else{
10890         mIsUnderScaling = FALSE;
10891         //no scale is needed for input picture size
10892         if(!isValidatePicSize(width, height)){
10893             ALOGE("%s: invalidate input picture size.", __func__);
10894             return BAD_VALUE;
10895         }
10896         mPicSizeSetted.width = width;
10897         mPicSizeSetted.height = height;
10898     }
10899 
10900     CDBG_HIGH("%s: X. mIsUnderScaling=%d, width=%d, height=%d.", __func__, mIsUnderScaling, width, height);
10901     return NO_ERROR;
10902 }
10903 
10904 /*===========================================================================
10905  * FUNCTION   : getPicSizeFromAPK
10906  *
10907  * DESCRIPTION: get picture size that get from APK
10908  *
10909  * PARAMETERS :
10910  *   @width     : input width
10911  *   @height    : input height
10912  *
10913  * RETURN     : int32_t type of status
10914  *              NO_ERROR  -- success
10915  *              none-zero failure code
10916  *==========================================================================*/
getPicSizeFromAPK(int & width,int & height)10917 int32_t QCameraReprocScaleParam::getPicSizeFromAPK(int &width, int &height)
10918 {
10919     if(!mIsUnderScaling)
10920         return BAD_VALUE;
10921 
10922     width = mPicSizeFromAPK.width;
10923     height = mPicSizeFromAPK.height;
10924     return NO_ERROR;
10925 }
10926 
10927 /*===========================================================================
10928  * FUNCTION   : getPicSizeSetted
10929  *
10930  * DESCRIPTION: get picture size that setted into mm-camera
10931  *
10932  * PARAMETERS :
10933  *   @width     : input width
10934  *   @height    : input height
10935  *
10936  * RETURN     : int32_t type of status
10937  *              NO_ERROR  -- success
10938  *              none-zero failure code
10939  *==========================================================================*/
getPicSizeSetted(int & width,int & height)10940 int32_t QCameraReprocScaleParam::getPicSizeSetted(int &width, int &height)
10941 {
10942     width = mPicSizeSetted.width;
10943     height = mPicSizeSetted.height;
10944     return NO_ERROR;
10945 }
10946 
10947 /*===========================================================================
10948  * FUNCTION   : isUnderScaling
10949  *
10950  * DESCRIPTION: check if we are in Reproc Scaling requirment
10951  *
10952  * PARAMETERS :  none
10953  *
10954  * RETURN     : bool type of status
10955  *==========================================================================*/
isUnderScaling()10956 bool QCameraReprocScaleParam::isUnderScaling()
10957 {
10958     return mIsUnderScaling;
10959 }
10960 
10961 /*===========================================================================
10962  * FUNCTION   : checkScaleSizeTable
10963  *
10964  * DESCRIPTION: check PICTURE_SIZE_NEED_SCALE to choose
10965  *
10966  * PARAMETERS :
10967  *   @scale_cnt   : count of picture sizes that want scale
10968  *   @scale_tbl    : picture size table that want scale
10969  *   @org_cnt     : sensor supported picture size count
10970  *   @org_tbl      : sensor supported picture size table
10971  *
10972  * RETURN     : bool type of status
10973  *==========================================================================*/
checkScaleSizeTable(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)10974 size_t QCameraReprocScaleParam::checkScaleSizeTable(size_t scale_cnt,
10975         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
10976 {
10977     size_t stbl_cnt = 0;
10978     size_t temp_cnt = 0;
10979     ssize_t i = 0;
10980     if(scale_cnt <=0 || scale_tbl == NULL || org_tbl == NULL || org_cnt <= 0)
10981         return stbl_cnt;
10982 
10983     //get validate scale size table. Currently we only support:
10984     // 1. upscale. The scale size must larger than max sensor supported size
10985     // 2. Scale dimension ratio must be same as the max sensor supported size.
10986     temp_cnt = scale_cnt;
10987     for (i = (ssize_t)(scale_cnt - 1); i >= 0; i--) {
10988         if (scale_tbl[i].width > org_tbl[0].width ||
10989                 (scale_tbl[i].width == org_tbl[0].width &&
10990                     scale_tbl[i].height > org_tbl[0].height)) {
10991             //get the smallest scale size
10992             break;
10993         }
10994         temp_cnt--;
10995     }
10996 
10997     //check dimension ratio
10998     double supported_ratio = (double)org_tbl[0].width / (double)org_tbl[0].height;
10999     for (i = 0; i < (ssize_t)temp_cnt; i++) {
11000         double cur_ratio = (double)scale_tbl[i].width / (double)scale_tbl[i].height;
11001         if (fabs(supported_ratio - cur_ratio) > ASPECT_TOLERANCE) {
11002             continue;
11003         }
11004         mNeedScaledSizeTbl[stbl_cnt].width = scale_tbl[i].width;
11005         mNeedScaledSizeTbl[stbl_cnt].height= scale_tbl[i].height;
11006         stbl_cnt++;
11007     }
11008 
11009     return stbl_cnt;
11010 }
11011 
11012 /*===========================================================================
11013  * FUNCTION   : getTotalSizeTblCnt
11014  *
11015  * DESCRIPTION: get total picture size count after adding dimensions that need scaling
11016  *
11017  * PARAMETERS : none
11018  *
11019  * RETURN     : uint8_t type of picture size count
11020  *==========================================================================*/
getTotalSizeTblCnt()11021 size_t QCameraReprocScaleParam::getTotalSizeTblCnt()
11022 {
11023     return mTotalSizeTblCnt;
11024 }
11025 
11026 /*===========================================================================
11027  * FUNCTION   : getTotalSizeTbl
11028  *
11029  * DESCRIPTION: get picture size table after adding dimensions that need scaling
11030  *
11031  * PARAMETERS :  none
11032  *
11033  * RETURN     : cam_dimension_t list of picture size table
11034  *==========================================================================*/
getTotalSizeTbl()11035 cam_dimension_t *QCameraReprocScaleParam::getTotalSizeTbl()
11036 {
11037     if(!mScaleEnabled)
11038         return NULL;
11039 
11040     return mTotalSizeTbl;
11041 }
11042 
11043 /*===========================================================================
11044  * FUNCTION   : isHDREnabled
11045  *
11046  * DESCRIPTION: if HDR is enabled
11047  *
11048  * PARAMETERS : none
11049  *
11050  * RETURN     : true: needed
11051  *              false: no need
11052  *==========================================================================*/
isHDREnabled()11053 bool QCameraParameters::isHDREnabled()
11054 {
11055     return ((m_nBurstNum == 1) && (m_bHDREnabled || m_HDRSceneEnabled));
11056 }
11057 
11058 /*===========================================================================
11059  * FUNCTION   : isAVTimerEnabled
11060  *
11061  * DESCRIPTION: if AVTimer is enabled
11062  *
11063  * PARAMETERS : none
11064  *
11065  * RETURN     : true: needed
11066  *              false: no need
11067  *==========================================================================*/
isAVTimerEnabled()11068 bool QCameraParameters::isAVTimerEnabled()
11069 {
11070     return m_bAVTimerEnabled;
11071 }
11072 
11073 /*===========================================================================
11074 * FUNCTION   : isDISEnabled
11075 *
11076 * DESCRIPTION: if DIS is enabled
11077 *
11078 * PARAMETERS : none
11079 *
11080 * RETURN    : true: needed
11081 *               false: no need
11082 *==========================================================================*/
isDISEnabled()11083 bool QCameraParameters::isDISEnabled()
11084 {
11085     return m_bDISEnabled;
11086 }
11087 
11088 /*===========================================================================
11089 * FUNCTION   : getISType
11090 *
11091 * DESCRIPTION: returns IS type
11092 *
11093 * PARAMETERS : none
11094 *
11095 * RETURN     : IS type
11096 *
11097 *==========================================================================*/
getISType()11098 cam_is_type_t QCameraParameters::getISType()
11099 {
11100     return mIsType;
11101 }
11102 
11103 /*===========================================================================
11104  * FUNCTION   : MobicatMask
11105  *
11106  * DESCRIPTION: returns mobicat mask
11107  *
11108  * PARAMETERS : none
11109  *
11110  * RETURN     : mobicat mask
11111  *
11112  *==========================================================================*/
getMobicatMask()11113 uint8_t QCameraParameters::getMobicatMask()
11114 {
11115     return m_MobiMask;
11116 }
11117 
11118 /*===========================================================================
11119  * FUNCTION   : sendStreamConfigInfo
11120  *
11121  * DESCRIPTION: send Stream config info.
11122  *
11123  * PARAMETERS :
11124  *   @stream_config_info: Stream config information
11125  *
11126  * RETURN     : int32_t type of status
11127  *              NO_ERROR  -- success
11128  *              none-zero failure code
11129  *==========================================================================*/
sendStreamConfigInfo(cam_stream_size_info_t & stream_config_info)11130 bool QCameraParameters::sendStreamConfigInfo(cam_stream_size_info_t &stream_config_info) {
11131     int32_t rc = NO_ERROR;
11132     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11133         ALOGE("%s:Failed to initialize group update table", __func__);
11134         return BAD_TYPE;
11135     }
11136 
11137     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
11138             CAM_INTF_META_STREAM_INFO, stream_config_info)) {
11139         ALOGE("%s:Failed to update table", __func__);
11140         return BAD_VALUE;
11141     }
11142 
11143     rc = commitSetBatch();
11144     if (rc != NO_ERROR) {
11145         ALOGE("%s:Failed to set stream info parm", __func__);
11146         return rc;
11147     }
11148 
11149     return rc;
11150 }
11151 
11152 /*===========================================================================
11153  * FUNCTION   : setStreamConfigure
11154  *
11155  * DESCRIPTION: set stream type, stream dimension for all configured streams.
11156  *
11157  * PARAMETERS :
11158  *   @isCapture: Whether this configureation is for an image capture
11159  *   @previewAsPostview: Use preview as postview
11160  *
11161  * RETURN     : int32_t type of status
11162  *              NO_ERROR  -- success
11163  *              none-zero failure code
11164  *==========================================================================*/
setStreamConfigure(bool isCapture,bool previewAsPostview,bool resetConfig)11165 bool QCameraParameters::setStreamConfigure(bool isCapture,
11166         bool previewAsPostview, bool resetConfig) {
11167 
11168     int32_t rc = NO_ERROR;
11169     cam_stream_size_info_t stream_config_info;
11170     char value[PROPERTY_VALUE_MAX];
11171     bool raw_yuv = false;
11172     bool raw_capture = false;
11173 
11174     if ( m_pParamBuf == NULL ) {
11175         return NO_INIT;
11176     }
11177 
11178     memset(&stream_config_info, 0, sizeof(stream_config_info));
11179     stream_config_info.num_streams = 0;
11180 
11181     if (m_bStreamsConfigured) {
11182         CDBG_HIGH("%s: Reset stream config!!", __func__);
11183         rc = sendStreamConfigInfo(stream_config_info);
11184         m_bStreamsConfigured = false;
11185     }
11186     if (resetConfig) {
11187         CDBG_HIGH("%s: Done Resetting stream config!!", __func__);
11188         return rc;
11189     }
11190 
11191     property_get("persist.camera.raw_yuv", value, "0");
11192     raw_yuv = atoi(value) > 0 ? true : false;
11193 
11194     if (isZSLMode() && getRecordingHintValue() != true) {
11195         stream_config_info.type[stream_config_info.num_streams] =
11196             CAM_STREAM_TYPE_PREVIEW;
11197         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
11198                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
11199         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
11200         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11201                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
11202         stream_config_info.num_streams++;
11203 
11204         stream_config_info.type[stream_config_info.num_streams] =
11205                 CAM_STREAM_TYPE_ANALYSIS;
11206         getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
11207                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
11208         updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
11209         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11210                 mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
11211         stream_config_info.num_streams++;
11212 
11213         stream_config_info.type[stream_config_info.num_streams] =
11214                 CAM_STREAM_TYPE_SNAPSHOT;
11215         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
11216                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
11217         updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
11218         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11219                 mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
11220         stream_config_info.num_streams++;
11221 
11222     } else if (!isCapture) {
11223         if (m_bRecordingHint) {
11224             if (m_bDISEnabled) {
11225                 char value[PROPERTY_VALUE_MAX];
11226                 // Make default value for IS_TYPE as IS_TYPE_EIS_2_0
11227                 property_get("persist.camera.is_type", value, "4");
11228                 mIsType = static_cast<cam_is_type_t>(atoi(value));
11229             } else {
11230                 mIsType = IS_TYPE_NONE;
11231             }
11232             stream_config_info.is_type = mIsType;
11233             stream_config_info.type[stream_config_info.num_streams] =
11234                     CAM_STREAM_TYPE_SNAPSHOT;
11235             getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
11236                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
11237             updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
11238             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11239                     mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
11240             stream_config_info.num_streams++;
11241 
11242             stream_config_info.type[stream_config_info.num_streams] =
11243                     CAM_STREAM_TYPE_VIDEO;
11244             getStreamDimension(CAM_STREAM_TYPE_VIDEO,
11245                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
11246             updatePpFeatureMask(CAM_STREAM_TYPE_VIDEO);
11247             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11248                     mStreamPpMask[CAM_STREAM_TYPE_VIDEO];
11249             stream_config_info.num_streams++;
11250         }
11251 
11252         if (getRecordingHintValue() != true) {
11253             /* Analysis stream is used only in capture usecase */
11254             stream_config_info.type[stream_config_info.num_streams] =
11255                     CAM_STREAM_TYPE_ANALYSIS;
11256             getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
11257                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
11258             updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
11259             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11260                     mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
11261             stream_config_info.num_streams++;
11262         }
11263 
11264         stream_config_info.type[stream_config_info.num_streams] =
11265                 CAM_STREAM_TYPE_PREVIEW;
11266         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
11267                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
11268         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
11269         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11270                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
11271         stream_config_info.num_streams++;
11272 
11273     } else {
11274         if (isJpegPictureFormat() || isNV16PictureFormat() || isNV21PictureFormat()) {
11275             if (!getofflineRAW()) {
11276                 stream_config_info.type[stream_config_info.num_streams] =
11277                         CAM_STREAM_TYPE_SNAPSHOT;
11278                 getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
11279                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
11280                 updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
11281                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11282                         mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
11283                 stream_config_info.num_streams++;
11284             }
11285 
11286             if (previewAsPostview) {
11287                 stream_config_info.type[stream_config_info.num_streams] =
11288                         CAM_STREAM_TYPE_PREVIEW;
11289                 getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
11290                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
11291                 updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
11292                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11293                         mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
11294                 stream_config_info.num_streams++;
11295             } else {
11296                 stream_config_info.type[stream_config_info.num_streams] =
11297                         CAM_STREAM_TYPE_POSTVIEW;
11298                 getStreamDimension(CAM_STREAM_TYPE_POSTVIEW,
11299                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
11300                 updatePpFeatureMask(CAM_STREAM_TYPE_POSTVIEW);
11301                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11302                         mStreamPpMask[CAM_STREAM_TYPE_POSTVIEW];
11303                 stream_config_info.num_streams++;
11304             }
11305         } else {
11306             raw_capture = true;
11307             stream_config_info.type[stream_config_info.num_streams] =
11308                     CAM_STREAM_TYPE_RAW;
11309             getStreamDimension(CAM_STREAM_TYPE_RAW,
11310                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
11311             updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
11312             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11313                     mStreamPpMask[CAM_STREAM_TYPE_RAW];
11314             stream_config_info.num_streams++;
11315         }
11316     }
11317     if (raw_yuv && !raw_capture && (isZSLMode() ||
11318             (getofflineRAW() && isCapture && !getRecordingHintValue()))) {
11319         cam_dimension_t max_dim = {0,0};
11320         updateRAW(max_dim);
11321         stream_config_info.type[stream_config_info.num_streams] =
11322                 CAM_STREAM_TYPE_RAW;
11323         getStreamDimension(CAM_STREAM_TYPE_RAW,
11324                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
11325         updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
11326         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
11327                 mStreamPpMask[CAM_STREAM_TYPE_RAW];
11328         stream_config_info.num_streams++;
11329     }
11330     for (uint32_t k = 0; k < stream_config_info.num_streams; k++) {
11331         ALOGI("%s: stream type %d, w x h: %d x %d, pp_mask: 0x%x", __func__,
11332                 stream_config_info.type[k],
11333                 stream_config_info.stream_sizes[k].width,
11334                 stream_config_info.stream_sizes[k].height,
11335                 stream_config_info.postprocess_mask[k]);
11336     }
11337 
11338     rc = sendStreamConfigInfo(stream_config_info);
11339     m_bStreamsConfigured = true;
11340 
11341     return rc;
11342 }
11343 
11344 /*===========================================================================
11345  * FUNCTION   : addOnlineRotation
11346  *
11347  * DESCRIPTION: send additional rotation information for specific stream
11348  *
11349  * PARAMETERS :
11350  *   @rotation: rotation
11351  *   @streamId: internal stream id
11352  *   @device_rotation: device rotation
11353  *
11354  * RETURN     : int32_t type of status
11355  *              NO_ERROR  -- success
11356  *              none-zero failure code
11357  *==========================================================================*/
addOnlineRotation(uint32_t rotation,uint32_t streamId,int32_t device_rotation)11358 int32_t QCameraParameters::addOnlineRotation(uint32_t rotation, uint32_t streamId,
11359         int32_t device_rotation)
11360 {
11361     int32_t rc = NO_ERROR;
11362     cam_rotation_info_t rotation_info;
11363     memset(&rotation_info, 0, sizeof(cam_rotation_info_t));
11364 
11365     /* Add jpeg rotation information */
11366     if (rotation == 0) {
11367         rotation_info.rotation = ROTATE_0;
11368     } else if (rotation == 90) {
11369         rotation_info.rotation = ROTATE_90;
11370     } else if (rotation == 180) {
11371         rotation_info.rotation = ROTATE_180;
11372     } else if (rotation == 270) {
11373         rotation_info.rotation = ROTATE_270;
11374     } else {
11375         rotation_info.rotation = ROTATE_0;
11376     }
11377     rotation_info.streamId = streamId;
11378 
11379     /* Add device rotation information */
11380     if (device_rotation == 0) {
11381         rotation_info.device_rotation = ROTATE_0;
11382     } else if (device_rotation == 90) {
11383         rotation_info.device_rotation = ROTATE_90;
11384     } else if (device_rotation == 180) {
11385         rotation_info.device_rotation = ROTATE_180;
11386     } else if (device_rotation == 270) {
11387         rotation_info.device_rotation = ROTATE_270;
11388     } else {
11389         rotation_info.device_rotation = ROTATE_0;
11390     }
11391 
11392     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11393         ALOGE("%s:Failed to initialize group update table", __func__);
11394         return BAD_TYPE;
11395     }
11396 
11397     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROTATION, rotation_info)) {
11398         ALOGE("%s:Failed to update table", __func__);
11399         return BAD_VALUE;
11400     }
11401 
11402     rc = commitSetBatch();
11403     if (rc != NO_ERROR) {
11404         ALOGE("%s:Failed to set stream info parm", __func__);
11405         return rc;
11406     }
11407 
11408     return rc;
11409 }
11410 
11411 /*===========================================================================
11412  * FUNCTION   : needThumbnailReprocess
11413  *
11414  * DESCRIPTION: Check if thumbnail reprocessing is needed
11415  *
11416  * PARAMETERS : @pFeatureMask - feature mask
11417  *
11418  * RETURN     : true: needed
11419  *              false: no need
11420  *==========================================================================*/
needThumbnailReprocess(uint32_t * pFeatureMask)11421 bool QCameraParameters::needThumbnailReprocess(uint32_t *pFeatureMask)
11422 {
11423     if (isUbiFocusEnabled() || isChromaFlashEnabled() ||
11424             isOptiZoomEnabled() || isUbiRefocus() ||
11425             isStillMoreEnabled()) {
11426         *pFeatureMask &= ~CAM_QCOM_FEATURE_CHROMA_FLASH;
11427         *pFeatureMask &= ~CAM_QCOM_FEATURE_UBIFOCUS;
11428         *pFeatureMask &= ~CAM_QCOM_FEATURE_REFOCUS;
11429         *pFeatureMask &= ~CAM_QCOM_FEATURE_OPTIZOOM;
11430         *pFeatureMask &= ~CAM_QCOM_FEATURE_STILLMORE;
11431         return false;
11432     } else {
11433         return true;
11434     }
11435 }
11436 
11437 /*===========================================================================
11438  * FUNCTION   : getNumOfExtraBuffersForImageProc
11439  *
11440  * DESCRIPTION: get number of extra input buffers needed by image processing
11441  *
11442  * PARAMETERS : none
11443  *
11444  * RETURN     : number of extra buffers needed by ImageProc;
11445  *              0 if not ImageProc enabled
11446  *==========================================================================*/
getNumOfExtraBuffersForImageProc()11447 uint8_t QCameraParameters::getNumOfExtraBuffersForImageProc()
11448 {
11449     int numOfBufs = 0;
11450 
11451     if (isUbiRefocus()) {
11452         return (uint8_t)(m_pCapability->refocus_af_bracketing_need.burst_count - 1);
11453     } else if (isUbiFocusEnabled()) {
11454         numOfBufs += m_pCapability->ubifocus_af_bracketing_need.burst_count - 1;
11455     } else if (m_bOptiZoomOn) {
11456         numOfBufs += m_pCapability->opti_zoom_settings_need.burst_count - 1;
11457     } else if (isChromaFlashEnabled()) {
11458         numOfBufs += m_pCapability->chroma_flash_settings_need.burst_count - 1;
11459     } else if (isStillMoreEnabled()) {
11460         if (isSeeMoreEnabled()) {
11461             m_stillmore_config.burst_count = 1;
11462         } else if ((m_stillmore_config.burst_count >=
11463                 m_pCapability->stillmore_settings_need.min_burst_count) &&
11464                 (m_stillmore_config.burst_count <=
11465                 m_pCapability->stillmore_settings_need.max_burst_count)) {
11466             numOfBufs += m_stillmore_config.burst_count - 1;
11467         } else {
11468             numOfBufs += m_pCapability->stillmore_settings_need.burst_count - 1;
11469         }
11470     }
11471 
11472     return (uint8_t)(numOfBufs * getBurstNum());
11473 }
11474 
11475 /*===========================================================================
11476  * FUNCTION   : getExifBufIndex
11477  *
11478  * DESCRIPTION: get index of metadata to be used for EXIF
11479  *
11480  * PARAMETERS : @captureIndex - index of current captured frame
11481  *
11482  * RETURN     : index of metadata to be used for EXIF
11483  *==========================================================================*/
getExifBufIndex(uint32_t captureIndex)11484 uint32_t QCameraParameters::getExifBufIndex(uint32_t captureIndex)
11485 {
11486     uint32_t index = captureIndex;
11487 
11488     if (isUbiRefocus()) {
11489         if (captureIndex < m_pCapability->refocus_af_bracketing_need.burst_count) {
11490             index = captureIndex;
11491         } else {
11492             index = 0;
11493         }
11494     } else if (isChromaFlashEnabled()) {
11495         index = m_pCapability->chroma_flash_settings_need.metadata_index;
11496     } else if (isHDREnabled()) {
11497         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
11498             index = m_pCapability->hdr_bracketing_setting.num_frames;
11499         } else {
11500             for (index = 0; index < m_pCapability->hdr_bracketing_setting.num_frames; index++) {
11501                 if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[index]) {
11502                     break;
11503                 }
11504             }
11505             if (index == m_pCapability->hdr_bracketing_setting.num_frames) {
11506                 index = captureIndex;
11507             }
11508         }
11509     }
11510 
11511     return index;
11512 }
11513 
11514 /*===========================================================================
11515  * FUNCTION   : getNumberInBufsForSingleShot
11516  *
11517  * DESCRIPTION: get number of input buffers for single shot
11518  *
11519  * PARAMETERS : none
11520  *
11521  * RETURN     : number of input buffers for single shot
11522  *==========================================================================*/
getNumberInBufsForSingleShot()11523 uint32_t QCameraParameters::getNumberInBufsForSingleShot()
11524 {
11525     uint32_t numOfBufs = 1;
11526 
11527     if (isUbiRefocus()) {
11528         numOfBufs = m_pCapability->refocus_af_bracketing_need.burst_count;
11529     } else if (isUbiFocusEnabled()) {
11530         numOfBufs = m_pCapability->ubifocus_af_bracketing_need.burst_count;
11531     } else if (m_bOptiZoomOn) {
11532         numOfBufs = m_pCapability->opti_zoom_settings_need.burst_count;
11533     } else if (isChromaFlashEnabled()) {
11534         numOfBufs = m_pCapability->chroma_flash_settings_need.burst_count;
11535     } else if (isHDREnabled()) {
11536         numOfBufs = m_pCapability->hdr_bracketing_setting.num_frames;
11537         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
11538             numOfBufs++;
11539         }
11540     } else if (isStillMoreEnabled()) {
11541         if (isSeeMoreEnabled()) {
11542             m_stillmore_config.burst_count = 1;
11543             numOfBufs = m_stillmore_config.burst_count;
11544         } else if ((m_stillmore_config.burst_count >=
11545                 m_pCapability->stillmore_settings_need.min_burst_count) &&
11546                 (m_stillmore_config.burst_count <=
11547                 m_pCapability->stillmore_settings_need.max_burst_count)) {
11548             numOfBufs = m_stillmore_config.burst_count;
11549         } else {
11550             numOfBufs = m_pCapability->stillmore_settings_need.burst_count;
11551         }
11552     }
11553 
11554     return numOfBufs;
11555 }
11556 
11557 /*===========================================================================
11558  * FUNCTION   : getNumberOutBufsForSingleShot
11559  *
11560  * DESCRIPTION: get number of output buffers for single shot
11561  *
11562  * PARAMETERS : none
11563  *
11564  * RETURN     : number of output buffers for single shot
11565  *==========================================================================*/
getNumberOutBufsForSingleShot()11566 uint32_t QCameraParameters::getNumberOutBufsForSingleShot()
11567 {
11568     uint32_t numOfBufs = 1;
11569 
11570     if (isUbiRefocus()) {
11571         numOfBufs = m_pCapability->refocus_af_bracketing_need.output_count;
11572     } else if (isHDREnabled()) {
11573         if (isHDR1xFrameEnabled()) {
11574             numOfBufs++;
11575         }
11576     }
11577 
11578     return numOfBufs;
11579 }
11580 
11581 /*===========================================================================
11582  * FUNCTION   : is4k2kVideoResolution
11583  *
11584  * DESCRIPTION: if resolution is 4k x 2k or true 4k x 2k
11585  *
11586  * PARAMETERS : none
11587  *
11588  * RETURN     : true: video resolution is 4k x 2k
11589  *              false: video resolution is not 4k x 2k
11590  *==========================================================================*/
is4k2kVideoResolution()11591 bool QCameraParameters::is4k2kVideoResolution()
11592 {
11593    bool enabled = false;
11594    cam_dimension_t resolution;
11595    getVideoSize(&resolution.width, &resolution.height);
11596    if (!(resolution.width < 3840 && resolution.height < 2160)) {
11597       enabled = true;
11598    }
11599 
11600    return enabled;
11601 }
11602 
11603 /*===========================================================================
11604  * FUNCTION   : updateDebugLevel
11605  *
11606  * DESCRIPTION: send CAM_INTF_PARM_UPDATE_DEBUG_LEVEL to backend
11607  *
11608  * PARAMETERS : none
11609  *
11610  * RETURN     : NO_ERROR --success
11611  *              int32_t type of status
11612  *==========================================================================*/
updateDebugLevel()11613 int32_t QCameraParameters::updateDebugLevel()
11614 {
11615     if ( m_pParamBuf == NULL ) {
11616         return NO_INIT;
11617     }
11618 
11619     int32_t rc = initBatchUpdate(m_pParamBuf);
11620     if ( rc != NO_ERROR ) {
11621         ALOGE("%s:Failed to initialize group update table", __func__);
11622         return rc;
11623     }
11624 
11625     uint32_t dummyDebugLevel = 0;
11626     /* The value of dummyDebugLevel is irrelavent. On
11627      * CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, read debug property */
11628     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, dummyDebugLevel)) {
11629         ALOGE("%s: Parameters batch failed",__func__);
11630         return BAD_VALUE;
11631     }
11632 
11633     rc = commitSetBatch();
11634     if ( rc != NO_ERROR ) {
11635         ALOGE("%s:Failed to commit batch parameters", __func__);
11636         return rc;
11637     }
11638 
11639     return NO_ERROR;
11640 }
11641 
11642 /*===========================================================================
11643  * FUNCTION   : setOfflineRAW
11644  *
11645  * DESCRIPTION: Function to decide Offline RAW feature.
11646  *
11647  * PARAMETERS : none
11648  *
11649  * RETURN     : none
11650  *==========================================================================*/
setOfflineRAW()11651 void QCameraParameters::setOfflineRAW()
11652 {
11653    char value[PROPERTY_VALUE_MAX];
11654    bool raw_yuv = false;
11655    bool offlineRaw = false;
11656 
11657    property_get("persist.camera.raw_yuv", value, "0");
11658    raw_yuv = atoi(value) > 0 ? true : false;
11659    property_get("persist.camera.offlineraw", value, "0");
11660    offlineRaw = atoi(value) > 0 ? true : false;
11661    if((raw_yuv || isRdiMode()) && offlineRaw){
11662        mOfflineRAW = true;
11663    }else{
11664        mOfflineRAW = false;
11665    }
11666    CDBG_HIGH("%s: Offline Raw  %d",__func__, mOfflineRAW);
11667 }
11668 
11669 /*===========================================================================
11670  * FUNCTION   : updatePpFeatureMask
11671  *
11672  * DESCRIPTION: Updates the feature mask for a particular stream depending
11673  *              on current client configuration.
11674  *
11675  * PARAMETERS :
11676  *  @stream_type: Camera stream type
11677  *
11678  * RETURN     : NO_ERROR --success
11679  *              int32_t type of status
11680  *==========================================================================*/
updatePpFeatureMask(cam_stream_type_t stream_type)11681 int32_t QCameraParameters::updatePpFeatureMask(cam_stream_type_t stream_type) {
11682 
11683     uint32_t feature_mask = 0;
11684 
11685     if (stream_type >= CAM_STREAM_TYPE_MAX) {
11686         ALOGE("%s: Error!! stream type: %d not valid", __func__, stream_type);
11687         return -1;
11688     }
11689 
11690     // Update feature mask for SeeMore in video and video preview
11691     if (isSeeMoreEnabled() &&
11692             !is4k2kVideoResolution() &&
11693             ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
11694             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue()))) {
11695        feature_mask |= CAM_QCOM_FEATURE_LLVD;
11696     }
11697 
11698     // Do not enable feature mask for ZSL/non-ZSL/liveshot snapshot except for 4K2k case
11699     if ((getRecordingHintValue() &&
11700             (stream_type == CAM_STREAM_TYPE_SNAPSHOT) && is4k2kVideoResolution()) ||
11701             (stream_type != CAM_STREAM_TYPE_SNAPSHOT)) {
11702         if ((m_nMinRequiredPpMask & CAM_QCOM_FEATURE_SHARPNESS) &&
11703                 !isOptiZoomEnabled()) {
11704             feature_mask |= CAM_QCOM_FEATURE_SHARPNESS;
11705         }
11706 
11707         if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_EFFECT) {
11708             feature_mask |= CAM_QCOM_FEATURE_EFFECT;
11709         }
11710         if (isWNREnabled() && (getRecordingHintValue() == false)) {
11711             feature_mask |= CAM_QCOM_FEATURE_DENOISE2D;
11712         }
11713 
11714         //Set flip mode based on Stream type;
11715         int flipMode = getFlipMode(stream_type);
11716         if (flipMode > 0) {
11717             feature_mask |= CAM_QCOM_FEATURE_FLIP;
11718         }
11719     }
11720 
11721     if ((isTNRVideoEnabled() && (CAM_STREAM_TYPE_VIDEO == stream_type))
11722             || (isTNRPreviewEnabled() && (CAM_STREAM_TYPE_PREVIEW == stream_type))) {
11723         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
11724     }
11725 
11726     //Rotation could also have an effect on pp feature mask
11727     cam_pp_feature_config_t config;
11728     cam_dimension_t dim;
11729     memset(&config, 0, sizeof(cam_pp_feature_config_t));
11730     getStreamRotation(stream_type, config, dim);
11731     feature_mask |= config.feature_mask;
11732 
11733     // Store stream feature mask
11734     setStreamPpMask(stream_type, feature_mask);
11735     CDBG_HIGH("%s: stream type: %d, pp_mask: 0x%x", __func__, stream_type, feature_mask);
11736 
11737     return NO_ERROR;
11738 }
11739 
11740 /*===========================================================================
11741  * FUNCTION   : setStreamPpMask
11742  *
11743  * DESCRIPTION: Stores a particular feature mask for a given camera stream
11744  *
11745  * PARAMETERS :
11746  *  @stream_type: Camera stream type
11747  *  @pp_mask  : Feature mask
11748  *
11749  * RETURN     : NO_ERROR --success
11750  *              int32_t type of status
11751  *==========================================================================*/
setStreamPpMask(cam_stream_type_t stream_type,uint32_t pp_mask)11752 int32_t QCameraParameters::setStreamPpMask(cam_stream_type_t stream_type,
11753         uint32_t pp_mask) {
11754 
11755     if(stream_type >= CAM_STREAM_TYPE_MAX) {
11756         return BAD_TYPE;
11757     }
11758 
11759     mStreamPpMask[stream_type] = pp_mask;
11760     return NO_ERROR;
11761 }
11762 
11763 /*===========================================================================
11764  * FUNCTION   : getStreamPpMask
11765  *
11766  * DESCRIPTION: Retrieves the feature mask for a given camera stream
11767  *
11768  * PARAMETERS :
11769  *  @stream_type: Camera stream type
11770  *  @pp_mask  : Feature mask
11771  *
11772  * RETURN     : NO_ERROR --success
11773  *              int32_t type of status
11774  *==========================================================================*/
getStreamPpMask(cam_stream_type_t stream_type,uint32_t & pp_mask)11775 int32_t QCameraParameters::getStreamPpMask(cam_stream_type_t stream_type,
11776         uint32_t &pp_mask) {
11777 
11778     if(stream_type >= CAM_STREAM_TYPE_MAX) {
11779         return BAD_TYPE;
11780     }
11781 
11782     pp_mask = mStreamPpMask[stream_type];
11783     return NO_ERROR;
11784 }
11785 
11786 /*===========================================================================
11787  * FUNCTION   : setReprocCount
11788  *
11789  * DESCRIPTION: Set total reprocessing pass count
11790  *
11791  * PARAMETERS : none
11792  *
11793  * RETURN     : None
11794  *==========================================================================*/
setReprocCount()11795 void QCameraParameters::setReprocCount()
11796 {
11797     mTotalPPCount = 1; //Default reprocessing Pass count
11798     char value[PROPERTY_VALUE_MAX];
11799     int multpass = 0;
11800 
11801     property_get("persist.camera.multi_pass", value, "0");
11802     multpass = atoi(value);
11803 
11804    if ( multpass == 0 ) {
11805        return;
11806    }
11807 
11808     if ((getZoomLevel() != 0) && (isZSLMode())) {
11809         ALOGW("Zoom Present. Need 2nd pass for post processing");
11810         mTotalPPCount++;
11811     }
11812 }
11813 
11814 /*===========================================================================
11815  * FUNCTION   : setBufBatchCount
11816  *
11817  * DESCRIPTION: Function to configure batch buffer
11818  *
11819  * PARAMETERS : int8_t buf_cnt
11820  *                     Buffer batch count
11821  *
11822  * RETURN     :  None
11823  *==========================================================================*/
setBufBatchCount(int8_t buf_cnt)11824 void QCameraParameters::setBufBatchCount(int8_t buf_cnt)
11825 {
11826     mBufBatchCnt = 0;
11827     char value[PROPERTY_VALUE_MAX];
11828     int8_t count = 0;
11829 
11830     property_get("persist.camera.batchcount", value, "0");
11831     count = atoi(value);
11832 
11833     if (!(count != 0 || buf_cnt > CAMERA_MIN_BATCH_COUNT)) {
11834         CDBG_HIGH("%s : Buffer batch count = %d", __func__, mBufBatchCnt);
11835         return;
11836     }
11837 
11838     while((m_pCapability->max_batch_bufs_supported != 0)
11839             && (m_pCapability->max_batch_bufs_supported < buf_cnt)) {
11840         buf_cnt = buf_cnt / 2;
11841     }
11842 
11843     if (count > 0) {
11844         mBufBatchCnt = count;
11845         CDBG_HIGH("%s : Buffer batch count = %d", __func__, mBufBatchCnt);
11846         return;
11847     }
11848 
11849     if (buf_cnt > CAMERA_MIN_BATCH_COUNT) {
11850         mBufBatchCnt = buf_cnt;
11851         CDBG_HIGH("%s : Buffer batch count = %d", __func__, mBufBatchCnt);
11852         return;
11853     }
11854 }
11855 
11856 /*===========================================================================
11857  * FUNCTION   : dump
11858  *
11859  * DESCRIPTION: Composes a string based on current configuration
11860  *
11861  * PARAMETERS : none
11862  *
11863  * RETURN     : Formatted string
11864  *==========================================================================*/
dump()11865 String8 QCameraParameters::dump()
11866 {
11867     String8 str("\n");
11868     char s[128];
11869 
11870     snprintf(s, 128, "Preview Pixel Fmt: %d\n", getPreviewHalPixelFormat());
11871     str += s;
11872 
11873     snprintf(s, 128, "ZSL Burst Interval: %d\n", getZSLBurstInterval());
11874     str += s;
11875 
11876     snprintf(s, 128, "ZSL Queue Depth: %d\n", getZSLQueueDepth());
11877     str += s;
11878 
11879     snprintf(s, 128, "ZSL Back Look Count %d\n", getZSLBackLookCount());
11880     str += s;
11881 
11882     snprintf(s, 128, "Max Unmatched Frames In Queue: %d\n",
11883         getMaxUnmatchedFramesInQueue());
11884     str += s;
11885 
11886     snprintf(s, 128, "Is ZSL Mode: %d\n", isZSLMode());
11887     str += s;
11888 
11889     snprintf(s, 128, "Is No Display Mode: %d\n", isNoDisplayMode());
11890     str += s;
11891 
11892     snprintf(s, 128, "Is WNR Enabled: %d\n", isWNREnabled());
11893     str += s;
11894 
11895     snprintf(s, 128, "isHfrMode: %d\n", isHfrMode());
11896     str += s;
11897 
11898     snprintf(s, 128, "getNumOfSnapshots: %d\n", getNumOfSnapshots());
11899     str += s;
11900 
11901     snprintf(s, 128, "getNumOfExtraHDRInBufsIfNeeded: %d\n",
11902         getNumOfExtraHDRInBufsIfNeeded());
11903     str += s;
11904 
11905     snprintf(s, 128, "getNumOfExtraHDROutBufsIfNeeded: %d\n",
11906         getNumOfExtraHDROutBufsIfNeeded());
11907     str += s;
11908 
11909     snprintf(s, 128, "getBurstNum: %d\n", getBurstNum());
11910     str += s;
11911 
11912     snprintf(s, 128, "getRecordingHintValue: %d\n", getRecordingHintValue());
11913     str += s;
11914 
11915     snprintf(s, 128, "getJpegQuality: %u\n", getJpegQuality());
11916     str += s;
11917 
11918     snprintf(s, 128, "getJpegRotation: %u\n", getJpegRotation());
11919     str += s;
11920 
11921     snprintf(s, 128, "isHistogramEnabled: %d\n", isHistogramEnabled());
11922     str += s;
11923 
11924     snprintf(s, 128, "isFaceDetectionEnabled: %d\n", isFaceDetectionEnabled());
11925     str += s;
11926 
11927     snprintf(s, 128, "isHDREnabled: %d\n", isHDREnabled());
11928     str += s;
11929 
11930     snprintf(s, 128, "isAutoHDREnabled: %d\n", isAutoHDREnabled());
11931     str += s;
11932 
11933     snprintf(s, 128, "isAVTimerEnabled: %d\n", isAVTimerEnabled());
11934     str += s;
11935 
11936     snprintf(s, 128, "getFocusMode: %d\n", getFocusMode());
11937     str += s;
11938 
11939     snprintf(s, 128, "isJpegPictureFormat: %d\n", isJpegPictureFormat());
11940     str += s;
11941 
11942     snprintf(s, 128, "isNV16PictureFormat: %d\n", isNV16PictureFormat());
11943     str += s;
11944 
11945     snprintf(s, 128, "isNV21PictureFormat: %d\n", isNV21PictureFormat());
11946     str += s;
11947 
11948     snprintf(s, 128, "isSnapshotFDNeeded: %d\n", isSnapshotFDNeeded());
11949     str += s;
11950 
11951     snprintf(s, 128, "isHDR1xFrameEnabled: %d\n", isHDR1xFrameEnabled());
11952     str += s;
11953 
11954     snprintf(s, 128, "isYUVFrameInfoNeeded: %d\n", isYUVFrameInfoNeeded());
11955     str += s;
11956 
11957     snprintf(s, 128, "isHDR1xExtraBufferNeeded: %d\n",
11958         isHDR1xExtraBufferNeeded());
11959     str += s;
11960 
11961     snprintf(s, 128, "isHDROutputCropEnabled: %d\n", isHDROutputCropEnabled());
11962     str += s;
11963 
11964     snprintf(s, 128, "isPreviewFlipChanged: %d\n", isPreviewFlipChanged());
11965     str += s;
11966 
11967     snprintf(s, 128, "isVideoFlipChanged: %d\n", isVideoFlipChanged());
11968     str += s;
11969 
11970     snprintf(s, 128, "isSnapshotFlipChanged: %d\n", isSnapshotFlipChanged());
11971     str += s;
11972 
11973     snprintf(s, 128, "isHDRThumbnailProcessNeeded: %d\n",
11974         isHDRThumbnailProcessNeeded());
11975     str += s;
11976 
11977     snprintf(s, 128, "getAutoFlickerMode: %d\n", getAutoFlickerMode());
11978     str += s;
11979 
11980     snprintf(s, 128, "getNumOfExtraBuffersForImageProc: %d\n",
11981         getNumOfExtraBuffersForImageProc());
11982     str += s;
11983 
11984     snprintf(s, 128, "isUbiFocusEnabled: %d\n", isUbiFocusEnabled());
11985     str += s;
11986 
11987     snprintf(s, 128, "isChromaFlashEnabled: %d\n", isChromaFlashEnabled());
11988     str += s;
11989 
11990     snprintf(s, 128, "isOptiZoomEnabled: %d\n", isOptiZoomEnabled());
11991     str += s;
11992 
11993     snprintf(s, 128, "isStillMoreEnabled: %d\n", isStillMoreEnabled());
11994     str += s;
11995 
11996     snprintf(s, 128, "getBurstCountForAdvancedCapture: %d\n",
11997         getBurstCountForAdvancedCapture());
11998     str += s;
11999 
12000     return str;
12001 }
12002 
12003 /*===========================================================================
12004  * FUNCTION   : getNumOfExtraBuffersForVideo
12005  *
12006  * DESCRIPTION: get number of extra buffers needed by image processing
12007  *
12008  * PARAMETERS : none
12009  *
12010  * RETURN     : number of extra buffers needed by ImageProc;
12011  *              0 if not ImageProc enabled
12012  *==========================================================================*/
getNumOfExtraBuffersForVideo()12013 uint8_t QCameraParameters::getNumOfExtraBuffersForVideo()
12014 {
12015     uint8_t numOfBufs = 0;
12016 
12017     if (isSeeMoreEnabled()) {
12018         numOfBufs = 1;
12019     }
12020 
12021     return numOfBufs;
12022 }
12023 
12024 /*===========================================================================
12025  * FUNCTION   : getNumOfExtraBuffersForPreview
12026  *
12027  * DESCRIPTION: get number of extra buffers needed by image processing
12028  *
12029  * PARAMETERS : none
12030  *
12031  * RETURN     : number of extra buffers needed by ImageProc;
12032  *              0 if not ImageProc enabled
12033  *==========================================================================*/
getNumOfExtraBuffersForPreview()12034 uint8_t QCameraParameters::getNumOfExtraBuffersForPreview()
12035 {
12036     uint8_t numOfBufs = 0;
12037 
12038     if (isSeeMoreEnabled() && !isZSLMode() && getRecordingHintValue()) {
12039         numOfBufs = 1;
12040     }
12041 
12042     return numOfBufs;
12043 }
12044 
12045 /*===========================================================================
12046  * FUNCTION   : setToneMapMode
12047  *
12048  * DESCRIPTION: enable or disable tone map
12049  *
12050  * PARAMETERS :
12051  *   @enable : enable: 1; disable 0
12052  *   @initCommit: if configuration list needs to be initialized and commited
12053  *
12054  * RETURN     : int32_t type of status
12055  *              NO_ERROR  -- success
12056  *              none-zero failure code
12057  *==========================================================================*/
setToneMapMode(uint32_t enable,bool initCommit)12058 int32_t QCameraParameters::setToneMapMode(uint32_t enable, bool initCommit)
12059 {
12060     int32_t rc = NO_ERROR;
12061     CDBG_HIGH("%s: tone map mode %d ", __func__, enable);
12062 
12063     if (initCommit) {
12064         if (initBatchUpdate(m_pParamBuf) < 0) {
12065             ALOGE("%s:Failed to initialize group update table", __func__);
12066             return FAILED_TRANSACTION;
12067         }
12068     }
12069 
12070     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TONE_MAP_MODE, enable)) {
12071         ALOGE("%s:Failed to update tone map mode", __func__);
12072         return BAD_VALUE;
12073     }
12074 
12075     if (initCommit) {
12076         rc = commitSetBatch();
12077         if (rc != NO_ERROR) {
12078             ALOGE("%s:Failed to commit tone map mode", __func__);
12079             return rc;
12080         }
12081     }
12082 
12083     return rc;
12084 }
12085 
12086 /*===========================================================================
12087  * FUNCTION   : setCDSMode
12088  *
12089  * DESCRIPTION: set CDS mode
12090  *
12091  * PARAMETERS :
12092  *   @cds_mode : cds mode
12093  *   @initCommit: if configuration list needs to be initialized and commited
12094  *
12095  * RETURN     : int32_t type of status
12096  *              NO_ERROR  -- success
12097  *              none-zero failure code
12098  *==========================================================================*/
setCDSMode(int32_t cds_mode,bool initCommit)12099 int32_t QCameraParameters::setCDSMode(int32_t cds_mode, bool initCommit)
12100 {
12101     if (initCommit) {
12102         if (initBatchUpdate(m_pParamBuf) < 0) {
12103             ALOGE("%s:Failed to initialize group update table", __func__);
12104             return FAILED_TRANSACTION;
12105         }
12106     }
12107 
12108     int32_t rc = NO_ERROR;
12109     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
12110         ALOGE("%s:Failed to update cds mode", __func__);
12111         return BAD_VALUE;
12112     }
12113 
12114     if (initCommit) {
12115         rc = commitSetBatch();
12116         if (NO_ERROR != rc) {
12117             ALOGE("%s:Failed to set cds mode", __func__);
12118             return rc;
12119         }
12120     }
12121 
12122     CDBG_HIGH(" cds mode -> %d", cds_mode);
12123 
12124     return rc;
12125 }
12126 
12127 }; // namespace qcamera
12128