1 /* Copyright (c) 2012-2016, 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 // To remove
33 #include <cutils/properties.h>
34 
35 // System dependencies
36 #include <math.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <utils/Errors.h>
40 #define SYSINFO_H <SYSTEM_HEADER_PREFIX/sysinfo.h>
41 #include SYSINFO_H
42 #include "gralloc_priv.h"
43 #include "graphics.h"
44 
45 // Camera dependencies
46 #include "QCameraBufferMaps.h"
47 #include "QCamera2HWI.h"
48 #include "QCameraParameters.h"
49 #include "QCameraTrace.h"
50 
51 extern "C" {
52 #include "mm_camera_dbg.h"
53 }
54 
55 #define PI 3.14159265
56 #define ASPECT_TOLERANCE 0.001
57 #define CAMERA_DEFAULT_LONGSHOT_STAGES 4
58 #define CAMERA_MIN_LONGSHOT_STAGES 2
59 #define FOCUS_PERCISION 0.0000001
60 
61 
62 namespace qcamera {
63 // Parameter keys to communicate between camera application and driver.
64 const char QCameraParameters::KEY_QC_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
65 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
66 const char QCameraParameters::KEY_QC_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
67 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
68 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
69 const char QCameraParameters::KEY_QC_TOUCH_AF_AEC[] = "touch-af-aec";
70 const char QCameraParameters::KEY_QC_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
71 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AEC[] = "touch-index-aec";
72 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AF[] = "touch-index-af";
73 const char QCameraParameters::KEY_QC_SCENE_DETECT[] = "scene-detect";
74 const char QCameraParameters::KEY_QC_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
75 const char QCameraParameters::KEY_QC_ISO_MODE[] = "iso";
76 const char QCameraParameters::KEY_QC_CONTINUOUS_ISO[] = "continuous-iso";
77 const char QCameraParameters::KEY_QC_MIN_ISO[] = "min-iso";
78 const char QCameraParameters::KEY_QC_MAX_ISO[] = "max-iso";
79 const char QCameraParameters::KEY_QC_SUPPORTED_ISO_MODES[] = "iso-values";
80 const char QCameraParameters::KEY_QC_EXPOSURE_TIME[] = "exposure-time";
81 const char QCameraParameters::KEY_QC_MIN_EXPOSURE_TIME[] = "min-exposure-time";
82 const char QCameraParameters::KEY_QC_MAX_EXPOSURE_TIME[] = "max-exposure-time";
83 const char QCameraParameters::KEY_QC_CURRENT_EXPOSURE_TIME[] = "cur-exposure-time";
84 const char QCameraParameters::KEY_QC_CURRENT_ISO[] = "cur-iso";
85 const char QCameraParameters::KEY_QC_LENSSHADE[] = "lensshade";
86 const char QCameraParameters::KEY_QC_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
87 const char QCameraParameters::KEY_QC_AUTO_EXPOSURE[] = "auto-exposure";
88 const char QCameraParameters::KEY_QC_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
89 const char QCameraParameters::KEY_QC_DENOISE[] = "denoise";
90 const char QCameraParameters::KEY_QC_SUPPORTED_DENOISE[] = "denoise-values";
91 const char QCameraParameters::KEY_QC_FOCUS_ALGO[] = "selectable-zone-af";
92 const char QCameraParameters::KEY_QC_SUPPORTED_FOCUS_ALGOS[] = "selectable-zone-af-values";
93 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POSITION[] = "manual-focus-position";
94 const char QCameraParameters::KEY_QC_MANUAL_FOCUS_POS_TYPE[] = "manual-focus-pos-type";
95 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_INDEX[] = "min-focus-pos-index";
96 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_INDEX[] = "max-focus-pos-index";
97 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DAC[] = "min-focus-pos-dac";
98 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DAC[] = "max-focus-pos-dac";
99 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_RATIO[] = "min-focus-pos-ratio";
100 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_RATIO[] = "max-focus-pos-ratio";
101 const char QCameraParameters::KEY_QC_FOCUS_POSITION_SCALE[] = "cur-focus-scale";
102 const char QCameraParameters::KEY_QC_MIN_FOCUS_POS_DIOPTER[] = "min-focus-pos-diopter";
103 const char QCameraParameters::KEY_QC_MAX_FOCUS_POS_DIOPTER[] = "max-focus-pos-diopter";
104 const char QCameraParameters::KEY_QC_FOCUS_POSITION_DIOPTER[] = "cur-focus-diopter";
105 const char QCameraParameters::KEY_QC_FACE_DETECTION[] = "face-detection";
106 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
107 const char QCameraParameters::KEY_QC_FACE_RECOGNITION[] = "face-recognition";
108 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_RECOGNITION[] = "face-recognition-values";
109 const char QCameraParameters::KEY_QC_MEMORY_COLOR_ENHANCEMENT[] = "mce";
110 const char QCameraParameters::KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
111 const char QCameraParameters::KEY_QC_DIS[] = "dis";
112 const char QCameraParameters::KEY_QC_OIS[] = "ois";
113 const char QCameraParameters::KEY_QC_SUPPORTED_DIS_MODES[] = "dis-values";
114 const char QCameraParameters::KEY_QC_SUPPORTED_OIS_MODES[] = "ois-values";
115 const char QCameraParameters::KEY_QC_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
116 const char QCameraParameters::KEY_QC_VIDEO_HIGH_SPEED_RECORDING[] = "video-hsr";
117 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
118 const char QCameraParameters::KEY_QC_REDEYE_REDUCTION[] = "redeye-reduction";
119 const char QCameraParameters::KEY_QC_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
120 const char QCameraParameters::KEY_QC_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
121 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
122 const char QCameraParameters::KEY_QC_ZSL[] = "zsl";
123 const char QCameraParameters::KEY_QC_SUPPORTED_ZSL_MODES[] = "zsl-values";
124 const char QCameraParameters::KEY_QC_ZSL_BURST_INTERVAL[] = "capture-burst-interval";
125 const char QCameraParameters::KEY_QC_ZSL_BURST_LOOKBACK[] = "capture-burst-retroactive";
126 const char QCameraParameters::KEY_QC_ZSL_QUEUE_DEPTH[] = "capture-burst-queue-depth";
127 const char QCameraParameters::KEY_QC_CAMERA_MODE[] = "camera-mode";
128 const char QCameraParameters::KEY_QC_AE_BRACKET_HDR[] = "ae-bracket-hdr";
129 const char QCameraParameters::KEY_QC_SUPPORTED_AE_BRACKET_MODES[] = "ae-bracket-hdr-values";
130 const char QCameraParameters::KEY_QC_SUPPORTED_RAW_FORMATS[] = "raw-format-values";
131 const char QCameraParameters::KEY_QC_RAW_FORMAT[] = "raw-format";
132 const char QCameraParameters::KEY_QC_ORIENTATION[] = "orientation";
133 const char QCameraParameters::KEY_QC_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
134 const char QCameraParameters::KEY_QC_CAPTURE_BURST_EXPOSURE[] = "capture-burst-exposures";
135 const char QCameraParameters::KEY_QC_NUM_SNAPSHOT_PER_SHUTTER[] = "num-snaps-per-shutter";
136 const char QCameraParameters::KEY_QC_NUM_RETRO_BURST_PER_SHUTTER[] = "num-retro-burst-per-shutter";
137 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD[] = "zsl-burst-led-on-period";
138 const char QCameraParameters::KEY_QC_NO_DISPLAY_MODE[] = "no-display-mode";
139 const char QCameraParameters::KEY_QC_RAW_PICUTRE_SIZE[] = "raw-size";
140 const char QCameraParameters::KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
141 const char QCameraParameters::KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES[] = "supported-live-snapshot-sizes";
142 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_NEED_1X[] = "hdr-need-1x-values";
143 const char QCameraParameters::KEY_QC_HDR_NEED_1X[] = "hdr-need-1x";
144 const char QCameraParameters::KEY_QC_PREVIEW_FLIP[] = "preview-flip";
145 const char QCameraParameters::KEY_QC_VIDEO_FLIP[] = "video-flip";
146 const char QCameraParameters::KEY_QC_SNAPSHOT_PICTURE_FLIP[] = "snapshot-picture-flip";
147 const char QCameraParameters::KEY_QC_SUPPORTED_FLIP_MODES[] = "flip-mode-values";
148 const char QCameraParameters::KEY_QC_VIDEO_HDR[] = "video-hdr";
149 const char QCameraParameters::KEY_QC_SENSOR_HDR[] = "sensor-hdr";
150 const char QCameraParameters::KEY_QC_VT_ENABLE[] = "avtimer";
151 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HDR_MODES[] = "video-hdr-values";
152 const char QCameraParameters::KEY_QC_SUPPORTED_SENSOR_HDR_MODES[] = "sensor-hdr-values";
153 const char QCameraParameters::KEY_QC_AUTO_HDR_ENABLE [] = "auto-hdr-enable";
154 const char QCameraParameters::KEY_QC_SNAPSHOT_BURST_NUM[] = "snapshot-burst-num";
155 const char QCameraParameters::KEY_QC_SNAPSHOT_FD_DATA[] = "snapshot-fd-data-enable";
156 const char QCameraParameters::KEY_QC_TINTLESS_ENABLE[] = "tintless";
157 const char QCameraParameters::KEY_QC_SCENE_SELECTION[] = "scene-selection";
158 const char QCameraParameters::KEY_QC_CDS_MODE[] = "cds-mode";
159 const char QCameraParameters::KEY_QC_VIDEO_CDS_MODE[] = "video-cds-mode";
160 const char QCameraParameters::KEY_QC_SUPPORTED_CDS_MODES[] = "cds-mode-values";
161 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_CDS_MODES[] = "video-cds-mode-values";
162 const char QCameraParameters::KEY_QC_TNR_MODE[] = "tnr-mode";
163 const char QCameraParameters::KEY_QC_VIDEO_TNR_MODE[] = "video-tnr-mode";
164 const char QCameraParameters::KEY_QC_SUPPORTED_TNR_MODES[] = "tnr-mode-values";
165 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_TNR_MODES[] = "video-tnr-mode-values";
166 const char QCameraParameters::KEY_QC_VIDEO_ROTATION[] = "video-rotation";
167 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES[] = "video-rotation-values";
168 const char QCameraParameters::KEY_QC_AF_BRACKET[] = "af-bracket";
169 const char QCameraParameters::KEY_QC_SUPPORTED_AF_BRACKET_MODES[] = "af-bracket-values";
170 const char QCameraParameters::KEY_QC_RE_FOCUS[] = "re-focus";
171 const char QCameraParameters::KEY_QC_SUPPORTED_RE_FOCUS_MODES[] = "re-focus-values";
172 const char QCameraParameters::KEY_QC_CHROMA_FLASH[] = "chroma-flash";
173 const char QCameraParameters::KEY_QC_SUPPORTED_CHROMA_FLASH_MODES[] = "chroma-flash-values";
174 const char QCameraParameters::KEY_QC_OPTI_ZOOM[] = "opti-zoom";
175 const char QCameraParameters::KEY_QC_SEE_MORE[] = "see-more";
176 const char QCameraParameters::KEY_QC_STILL_MORE[] = "still-more";
177 const char QCameraParameters::KEY_QC_SUPPORTED_OPTI_ZOOM_MODES[] = "opti-zoom-values";
178 const char QCameraParameters::KEY_QC_HDR_MODE[] = "hdr-mode";
179 const char QCameraParameters::KEY_QC_SUPPORTED_KEY_QC_HDR_MODES[] = "hdr-mode-values";
180 const char QCameraParameters::KEY_QC_TRUE_PORTRAIT[] = "true-portrait";
181 const char QCameraParameters::KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES[] = "true-portrait-values";
182 const char QCameraParameters::KEY_QC_SUPPORTED_SEE_MORE_MODES[] = "see-more-values";
183 const char QCameraParameters::KEY_QC_SUPPORTED_STILL_MORE_MODES[] = "still-more-values";
184 const char QCameraParameters::KEY_INTERNAL_PERVIEW_RESTART[] = "internal-restart";
185 const char QCameraParameters::KEY_QC_RDI_MODE[] = "rdi-mode";
186 const char QCameraParameters::KEY_QC_SUPPORTED_RDI_MODES[] = "rdi-mode-values";
187 const char QCameraParameters::KEY_QC_SECURE_MODE[] = "secure-mode";
188 const char QCameraParameters::KEY_QC_SUPPORTED_SECURE_MODES[] = "secure-mode-values";
189 const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
190 const char QCameraParameters::KEY_QC_AUTO_HDR_SUPPORTED[] = "auto-hdr-supported";
191 const char QCameraParameters::KEY_QC_LONGSHOT_SUPPORTED[] = "longshot-supported";
192 const char QCameraParameters::KEY_QC_ZSL_HDR_SUPPORTED[] = "zsl-hdr-supported";
193 const char QCameraParameters::KEY_QC_WB_MANUAL_CCT[] = "wb-manual-cct";
194 const char QCameraParameters::KEY_QC_MIN_WB_CCT[] = "min-wb-cct";
195 const char QCameraParameters::KEY_QC_MAX_WB_CCT[] = "max-wb-cct";
196 
197 const char QCameraParameters::KEY_QC_MANUAL_WB_GAINS[] = "manual-wb-gains";
198 const char QCameraParameters::KEY_QC_MIN_WB_GAIN[] = "min-wb-gain";
199 const char QCameraParameters::KEY_QC_MAX_WB_GAIN[] = "max-wb-gain";
200 
201 const char QCameraParameters::KEY_QC_MANUAL_WB_TYPE[] = "manual-wb-type";
202 const char QCameraParameters::KEY_QC_MANUAL_WB_VALUE[] = "manual-wb-value";
203 
204 const char QCameraParameters::WHITE_BALANCE_MANUAL[] = "manual";
205 const char QCameraParameters::FOCUS_MODE_MANUAL_POSITION[] = "manual";
206 const char QCameraParameters::KEY_QC_CACHE_VIDEO_BUFFERS[] = "cache-video-buffers";
207 
208 const char QCameraParameters::KEY_QC_LONG_SHOT[] = "long-shot";
209 const char QCameraParameters::KEY_QC_INITIAL_EXPOSURE_INDEX[] = "initial-exp-index";
210 const char QCameraParameters::KEY_QC_INSTANT_AEC[] = "instant-aec";
211 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE[] = "instant-capture";
212 const char QCameraParameters::KEY_QC_INSTANT_AEC_SUPPORTED_MODES[] = "instant-aec-values";
213 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_SUPPORTED_MODES[] = "instant-capture-values";
214 
215 // Values for effect settings.
216 const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
217 const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
218 const char QCameraParameters::EFFECT_NEON[] = "neon";
219 const char QCameraParameters::EFFECT_BEAUTY[] = "beauty";
220 
221 
222 // Values for auto exposure settings.
223 const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
224 const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
225 
226 // Values for scene mode settings.
227 const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
228 const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
229 const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
230 const char QCameraParameters::SCENE_MODE_AR[] = "AR";
231 const char QCameraParameters::SCENE_MODE_HDR[] = "hdr";
232 
233 // Formats for setPreviewFormat and setPictureFormat.
234 const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
235 const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
236 const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
237 const char QCameraParameters::QC_PIXEL_FORMAT_NV12_VENUS[] = "nv12-venus";
238 
239 // Values for raw image formats
240 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV[] = "yuv-raw8-yuyv";
241 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU[] = "yuv-raw8-yvyu";
242 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY[] = "yuv-raw8-uyvy";
243 const char QCameraParameters::QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY[] = "yuv-raw8-vyuy";
244 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG[] = "bayer-qcom-8gbrg";
245 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG[] = "bayer-qcom-8grbg";
246 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB[] = "bayer-qcom-8rggb";
247 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR[] = "bayer-qcom-8bggr";
248 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG[] = "bayer-qcom-10gbrg";
249 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG[] = "bayer-qcom-10grbg";
250 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB[] = "bayer-qcom-10rggb";
251 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR[] = "bayer-qcom-10bggr";
252 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG[] = "bayer-qcom-12gbrg";
253 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG[] = "bayer-qcom-12grbg";
254 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB[] = "bayer-qcom-12rggb";
255 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR[] = "bayer-qcom-12bggr";
256 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GBRG[] = "bayer-qcom-14gbrg";
257 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GRBG[] = "bayer-qcom-14grbg";
258 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14RGGB[] = "bayer-qcom-14rggb";
259 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14BGGR[] = "bayer-qcom-14bggr";
260 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG[] = "bayer-mipi-8gbrg";
261 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG[] = "bayer-mipi-8grbg";
262 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB[] = "bayer-mipi-8rggb";
263 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR[] = "bayer-mipi-8bggr";
264 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG[] = "bayer-mipi-10gbrg";
265 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG[] = "bayer-mipi-10grbg";
266 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB[] = "bayer-mipi-10rggb";
267 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR[] = "bayer-mipi-10bggr";
268 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG[] = "bayer-mipi-12gbrg";
269 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG[] = "bayer-mipi-12grbg";
270 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB[] = "bayer-mipi-12rggb";
271 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR[] = "bayer-mipi-12bggr";
272 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GBRG[] = "bayer-mipi-14gbrg";
273 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GRBG[] = "bayer-mipi-14grbg";
274 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14RGGB[] = "bayer-mipi-14rggb";
275 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14BGGR[] = "bayer-mipi-14bggr";
276 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG[] = "bayer-ideal-qcom-8gbrg";
277 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG[] = "bayer-ideal-qcom-8grbg";
278 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB[] = "bayer-ideal-qcom-8rggb";
279 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR[] = "bayer-ideal-qcom-8bggr";
280 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG[] = "bayer-ideal-qcom-10gbrg";
281 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG[] = "bayer-ideal-qcom-10grbg";
282 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB[] = "bayer-ideal-qcom-10rggb";
283 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR[] = "bayer-ideal-qcom-10bggr";
284 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG[] = "bayer-ideal-qcom-12gbrg";
285 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG[] = "bayer-ideal-qcom-12grbg";
286 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB[] = "bayer-ideal-qcom-12rggb";
287 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR[] = "bayer-ideal-qcom-12bggr";
288 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GBRG[] = "bayer-ideal-qcom-14gbrg";
289 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GRBG[] = "bayer-ideal-qcom-14grbg";
290 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14RGGB[] = "bayer-ideal-qcom-14rggb";
291 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14BGGR[] = "bayer-ideal-qcom-14bggr";
292 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG[] = "bayer-ideal-mipi-8gbrg";
293 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG[] = "bayer-ideal-mipi-8grbg";
294 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB[] = "bayer-ideal-mipi-8rggb";
295 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR[] = "bayer-ideal-mipi-8bggr";
296 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG[] = "bayer-ideal-mipi-10gbrg";
297 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG[] = "bayer-ideal-mipi-10grbg";
298 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB[] = "bayer-ideal-mipi-10rggb";
299 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR[] = "bayer-ideal-mipi-10bggr";
300 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG[] = "bayer-ideal-mipi-12gbrg";
301 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG[] = "bayer-ideal-mipi-12grbg";
302 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB[] = "bayer-ideal-mipi-12rggb";
303 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR[] = "bayer-ideal-mipi-12bggr";
304 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GBRG[] = "bayer-ideal-mipi-14gbrg";
305 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GRBG[] = "bayer-ideal-mipi-14grbg";
306 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14RGGB[] = "bayer-ideal-mipi-14rggb";
307 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14BGGR[] = "bayer-ideal-mipi-14bggr";
308 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG[] = "bayer-ideal-plain8-8gbrg";
309 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG[] = "bayer-ideal-plain8-8grbg";
310 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB[] = "bayer-ideal-plain8-8rggb";
311 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR[] = "bayer-ideal-plain8-8bggr";
312 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG[] = "bayer-ideal-plain16-8gbrg";
313 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG[] = "bayer-ideal-plain16-8grbg";
314 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB[] = "bayer-ideal-plain16-8rggb";
315 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR[] = "bayer-ideal-plain16-8bggr";
316 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG[] = "bayer-ideal-plain16-10gbrg";
317 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG[] = "bayer-ideal-plain16-10grbg";
318 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB[] = "bayer-ideal-plain16-10rggb";
319 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR[] = "bayer-ideal-plain16-10bggr";
320 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG[] = "bayer-ideal-plain16-12gbrg";
321 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG[] = "bayer-ideal-plain16-12grbg";
322 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB[] = "bayer-ideal-plain16-12rggb";
323 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR[] = "bayer-ideal-plain16-12bggr";
324 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GBRG[] = "bayer-ideal-plain16-14gbrg";
325 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GRBG[] = "bayer-ideal-plain16-14grbg";
326 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14RGGB[] = "bayer-ideal-plain16-14rggb";
327 const char QCameraParameters::QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14BGGR[] = "bayer-ideal-plain16-14bggr";
328 
329 // Values for ISO Settings
330 const char QCameraParameters::ISO_AUTO[] = "auto";
331 const char QCameraParameters::ISO_100[] = "ISO100";
332 const char QCameraParameters::ISO_200[] = "ISO200";
333 const char QCameraParameters::ISO_400[] = "ISO400";
334 const char QCameraParameters::ISO_800[] = "ISO800";
335 const char QCameraParameters::ISO_1600[] = "ISO1600";
336 const char QCameraParameters::ISO_3200[] = "ISO3200";
337 const char QCameraParameters::ISO_MANUAL[] = "manual";
338 
339 
340 // Values for auto exposure settings.
341 const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
342 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
343 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
344 const char QCameraParameters::AUTO_EXPOSURE_SMART_METERING[] = "smart-metering";
345 const char QCameraParameters::AUTO_EXPOSURE_USER_METERING[] = "user-metering";
346 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING_ADV[] = "spot-metering-adv";
347 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED_ADV[] = "center-weighted-adv";
348 
349 // Values for instant AEC modes
350 const char QCameraParameters::KEY_QC_INSTANT_AEC_DISABLE[] = "0";
351 const char QCameraParameters::KEY_QC_INSTANT_AEC_AGGRESSIVE_AEC[] = "1";
352 const char QCameraParameters::KEY_QC_INSTANT_AEC_FAST_AEC[] = "2";
353 
354 // Values for instant capture modes
355 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_DISABLE[] = "0";
356 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_AGGRESSIVE_AEC[] = "1";
357 const char QCameraParameters::KEY_QC_INSTANT_CAPTURE_FAST_AEC[] = "2";
358 
359 const char QCameraParameters::KEY_QC_GPS_LATITUDE_REF[] = "gps-latitude-ref";
360 const char QCameraParameters::KEY_QC_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
361 const char QCameraParameters::KEY_QC_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
362 const char QCameraParameters::KEY_QC_GPS_STATUS[] = "gps-status";
363 
364 const char QCameraParameters::KEY_QC_HISTOGRAM[] = "histogram";
365 const char QCameraParameters::KEY_QC_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
366 
367 const char QCameraParameters::VALUE_ENABLE[] = "enable";
368 const char QCameraParameters::VALUE_DISABLE[] = "disable";
369 const char QCameraParameters::VALUE_OFF[] = "off";
370 const char QCameraParameters::VALUE_ON[] = "on";
371 const char QCameraParameters::VALUE_TRUE[] = "true";
372 const char QCameraParameters::VALUE_FALSE[] = "false";
373 
374 const char QCameraParameters::VALUE_FAST[] = "fast";
375 const char QCameraParameters::VALUE_HIGH_QUALITY[] = "high-quality";
376 
377 const char QCameraParameters::KEY_QC_SHARPNESS[] = "sharpness";
378 const char QCameraParameters::KEY_QC_MIN_SHARPNESS[] = "min-sharpness";
379 const char QCameraParameters::KEY_QC_MAX_SHARPNESS[] = "max-sharpness";
380 const char QCameraParameters::KEY_QC_SHARPNESS_STEP[] = "sharpness-step";
381 const char QCameraParameters::KEY_QC_CONTRAST[] = "contrast";
382 const char QCameraParameters::KEY_QC_MIN_CONTRAST[] = "min-contrast";
383 const char QCameraParameters::KEY_QC_MAX_CONTRAST[] = "max-contrast";
384 const char QCameraParameters::KEY_QC_CONTRAST_STEP[] = "contrast-step";
385 const char QCameraParameters::KEY_QC_SATURATION[] = "saturation";
386 const char QCameraParameters::KEY_QC_MIN_SATURATION[] = "min-saturation";
387 const char QCameraParameters::KEY_QC_MAX_SATURATION[] = "max-saturation";
388 const char QCameraParameters::KEY_QC_SATURATION_STEP[] = "saturation-step";
389 const char QCameraParameters::KEY_QC_BRIGHTNESS[] = "luma-adaptation";
390 const char QCameraParameters::KEY_QC_MIN_BRIGHTNESS[] = "min-brightness";
391 const char QCameraParameters::KEY_QC_MAX_BRIGHTNESS[] = "max-brightness";
392 const char QCameraParameters::KEY_QC_BRIGHTNESS_STEP[] = "brightness-step";
393 const char QCameraParameters::KEY_QC_SCE_FACTOR[] = "skinToneEnhancement";
394 const char QCameraParameters::KEY_QC_MIN_SCE_FACTOR[] = "min-sce-factor";
395 const char QCameraParameters::KEY_QC_MAX_SCE_FACTOR[] = "max-sce-factor";
396 const char QCameraParameters::KEY_QC_SCE_FACTOR_STEP[] = "sce-factor-step";
397 
398 const char QCameraParameters::KEY_QC_SUPPORTED_CAMERA_FEATURES[] = "qc-camera-features";
399 const char QCameraParameters::KEY_QC_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
400 
401 //Values for DENOISE
402 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
403 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
404 
405 // Values for selectable zone af Settings
406 const char QCameraParameters::FOCUS_ALGO_AUTO[] = "auto";
407 const char QCameraParameters::FOCUS_ALGO_SPOT_METERING[] = "spot-metering";
408 const char QCameraParameters::FOCUS_ALGO_CENTER_WEIGHTED[] = "center-weighted";
409 const char QCameraParameters::FOCUS_ALGO_FRAME_AVERAGE[] = "frame-average";
410 
411 // Values for HFR settings.
412 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
413 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
414 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
415 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
416 const char QCameraParameters::VIDEO_HFR_5X[] = "150";
417 const char QCameraParameters::VIDEO_HFR_6X[] = "180";
418 const char QCameraParameters::VIDEO_HFR_7X[] = "210";
419 const char QCameraParameters::VIDEO_HFR_8X[] = "240";
420 const char QCameraParameters::VIDEO_HFR_9X[] = "480";
421 
422 // Values for HDR Bracketing settings.
423 const char QCameraParameters::AE_BRACKET_OFF[] = "Off";
424 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
425 
426 // Values for AF Bracketing setting.
427 const char QCameraParameters::AF_BRACKET_OFF[] = "af-bracket-off";
428 const char QCameraParameters::AF_BRACKET_ON[] = "af-bracket-on";
429 
430 // Values for Refocus setting.
431 const char QCameraParameters::RE_FOCUS_OFF[] = "re-focus-off";
432 const char QCameraParameters::RE_FOCUS_ON[] = "re-focus-on";
433 
434 // Values for Chroma Flash setting.
435 const char QCameraParameters::CHROMA_FLASH_OFF[] = "chroma-flash-off";
436 const char QCameraParameters::CHROMA_FLASH_ON[] = "chroma-flash-on";
437 
438 // Values for Opti Zoom setting.
439 const char QCameraParameters::OPTI_ZOOM_OFF[] = "opti-zoom-off";
440 const char QCameraParameters::OPTI_ZOOM_ON[] = "opti-zoom-on";
441 
442 // Values for Still More setting.
443 const char QCameraParameters::STILL_MORE_OFF[] = "still-more-off";
444 const char QCameraParameters::STILL_MORE_ON[] = "still-more-on";
445 
446 // Values for HDR mode setting.
447 const char QCameraParameters::HDR_MODE_SENSOR[] = "hdr-mode-sensor";
448 const char QCameraParameters::HDR_MODE_MULTI_FRAME[] = "hdr-mode-multiframe";
449 
450 // Values for True Portrait setting.
451 const char QCameraParameters::TRUE_PORTRAIT_OFF[] = "true-portrait-off";
452 const char QCameraParameters::TRUE_PORTRAIT_ON[] = "true-portrait-on";
453 
454 // Values for FLIP settings.
455 const char QCameraParameters::FLIP_MODE_OFF[] = "off";
456 const char QCameraParameters::FLIP_MODE_V[] = "flip-v";
457 const char QCameraParameters::FLIP_MODE_H[] = "flip-h";
458 const char QCameraParameters::FLIP_MODE_VH[] = "flip-vh";
459 
460 const char QCameraParameters::CDS_MODE_OFF[] = "off";
461 const char QCameraParameters::CDS_MODE_ON[] = "on";
462 const char QCameraParameters::CDS_MODE_AUTO[] = "auto";
463 
464 // Values for video rotation settings.
465 const char QCameraParameters::VIDEO_ROTATION_0[] = "0";
466 const char QCameraParameters::VIDEO_ROTATION_90[] = "90";
467 const char QCameraParameters::VIDEO_ROTATION_180[] = "180";
468 const char QCameraParameters::VIDEO_ROTATION_270[] = "270";
469 
470 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES[] = "manual-focus-modes";
471 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES[] = "manual-exposure-modes";
472 const char QCameraParameters::KEY_QC_SUPPORTED_MANUAL_WB_MODES[] = "manual-wb-modes";
473 const char QCameraParameters::KEY_QC_FOCUS_SCALE_MODE[] = "scale-mode";
474 const char QCameraParameters::KEY_QC_FOCUS_DIOPTER_MODE[] = "diopter-mode";
475 const char QCameraParameters::KEY_QC_ISO_PRIORITY[] = "iso-priority";
476 const char QCameraParameters::KEY_QC_EXP_TIME_PRIORITY[] = "exp-time-priority";
477 const char QCameraParameters::KEY_QC_USER_SETTING[] = "user-setting";
478 const char QCameraParameters::KEY_QC_WB_CCT_MODE[] = "color-temperature";
479 const char QCameraParameters::KEY_QC_WB_GAIN_MODE[] = "rbgb-gains";
480 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE[] = "noise-reduction-mode";
481 const char QCameraParameters::KEY_QC_NOISE_REDUCTION_MODE_VALUES[] = "noise-reduction-mode-values";
482 
483 #ifdef TARGET_TS_MAKEUP
484 const char QCameraParameters::KEY_TS_MAKEUP[] = "tsmakeup";
485 const char QCameraParameters::KEY_TS_MAKEUP_WHITEN[] = "tsmakeup_whiten";
486 const char QCameraParameters::KEY_TS_MAKEUP_CLEAN[] = "tsmakeup_clean";
487 #endif
488 
489 //KEY to share HFR batch size with video encoder.
490 const char QCameraParameters::KEY_QC_VIDEO_BATCH_SIZE[] = "video-batch-size";
491 
492 static const char* portrait = "portrait";
493 static const char* landscape = "landscape";
494 
495 const cam_dimension_t QCameraParameters::THUMBNAIL_SIZES_MAP[] = {
496     { 512, 288 }, //1.777778
497     { 480, 288 }, //1.666667
498     { 256, 154 }, //1.66233
499     { 432, 288 }, //1.5
500     { 320, 320 }, //1.0
501     { 320, 240 }, //1.33333
502     { 176, 144 }, //1.222222
503     /*Thumbnail sizes to match portrait picture size aspect ratio*/
504     { 240, 320 }, //to match 480X640 & 240X320 picture size
505     { 144, 176 }, //to match 144X176  picture size
506     { 0, 0 }      // required by Android SDK
507 };
508 
509 const QCameraParameters::QCameraMap<cam_auto_exposure_mode_type>
510         QCameraParameters::AUTO_EXPOSURE_MAP[] = {
511     { AUTO_EXPOSURE_FRAME_AVG,           CAM_AEC_MODE_FRAME_AVERAGE },
512     { AUTO_EXPOSURE_CENTER_WEIGHTED,     CAM_AEC_MODE_CENTER_WEIGHTED },
513     { AUTO_EXPOSURE_SPOT_METERING,       CAM_AEC_MODE_SPOT_METERING },
514     { AUTO_EXPOSURE_SMART_METERING,      CAM_AEC_MODE_SMART_METERING },
515     { AUTO_EXPOSURE_USER_METERING,       CAM_AEC_MODE_USER_METERING },
516     { AUTO_EXPOSURE_SPOT_METERING_ADV,   CAM_AEC_MODE_SPOT_METERING_ADV },
517     { AUTO_EXPOSURE_CENTER_WEIGHTED_ADV, CAM_AEC_MODE_CENTER_WEIGHTED_ADV },
518 };
519 
520 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
521         QCameraParameters::INSTANT_AEC_MODES_MAP[] = {
522     { KEY_QC_INSTANT_AEC_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
523     { KEY_QC_INSTANT_AEC_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
524     { KEY_QC_INSTANT_AEC_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
525 };
526 
527 const QCameraParameters::QCameraMap<cam_aec_convergence_type>
528         QCameraParameters::INSTANT_CAPTURE_MODES_MAP[] = {
529     { KEY_QC_INSTANT_CAPTURE_DISABLE,        CAM_AEC_NORMAL_CONVERGENCE },
530     { KEY_QC_INSTANT_CAPTURE_AGGRESSIVE_AEC, CAM_AEC_AGGRESSIVE_CONVERGENCE },
531     { KEY_QC_INSTANT_CAPTURE_FAST_AEC,       CAM_AEC_FAST_CONVERGENCE },
532 };
533 
534 const QCameraParameters::QCameraMap<cam_format_t>
535         QCameraParameters::PREVIEW_FORMATS_MAP[] = {
536     {PIXEL_FORMAT_YUV420SP,        CAM_FORMAT_YUV_420_NV21},
537     {PIXEL_FORMAT_YUV420P,         CAM_FORMAT_YUV_420_YV12},
538     {PIXEL_FORMAT_YUV420SP_ADRENO, CAM_FORMAT_YUV_420_NV21_ADRENO},
539     {PIXEL_FORMAT_YV12,            CAM_FORMAT_YUV_420_YV12},
540     {PIXEL_FORMAT_NV12,            CAM_FORMAT_YUV_420_NV12},
541     {QC_PIXEL_FORMAT_NV12_VENUS,   CAM_FORMAT_YUV_420_NV12_VENUS}
542 };
543 
544 const QCameraParameters::QCameraMap<cam_format_t>
545         QCameraParameters::PICTURE_TYPES_MAP[] = {
546     {PIXEL_FORMAT_JPEG,                          CAM_FORMAT_JPEG},
547     {PIXEL_FORMAT_YUV420SP,                      CAM_FORMAT_YUV_420_NV21},
548     {PIXEL_FORMAT_YUV422SP,                      CAM_FORMAT_YUV_422_NV16},
549     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YUYV,          CAM_FORMAT_YUV_RAW_8BIT_YUYV},
550     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_YVYU,          CAM_FORMAT_YUV_RAW_8BIT_YVYU},
551     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_UYVY,          CAM_FORMAT_YUV_RAW_8BIT_UYVY},
552     {QC_PIXEL_FORMAT_YUV_RAW_8BIT_VYUY,          CAM_FORMAT_YUV_RAW_8BIT_VYUY},
553     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GBRG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GBRG},
554     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8GRBG,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_GRBG},
555     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8RGGB,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_RGGB},
556     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_8BGGR,       CAM_FORMAT_BAYER_QCOM_RAW_8BPP_BGGR},
557     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG},
558     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GRBG},
559     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_RGGB},
560     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_10BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_10BPP_BGGR},
561     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GBRG},
562     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_GRBG},
563     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_RGGB},
564     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_12BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_12BPP_BGGR},
565     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GBRG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GBRG},
566     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14GRBG,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_GRBG},
567     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14RGGB,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_RGGB},
568     {QC_PIXEL_FORMAT_BAYER_QCOM_RAW_14BGGR,      CAM_FORMAT_BAYER_QCOM_RAW_14BPP_BGGR},
569     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GBRG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GBRG},
570     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8GRBG,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_GRBG},
571     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8RGGB,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_RGGB},
572     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_8BGGR,       CAM_FORMAT_BAYER_MIPI_RAW_8BPP_BGGR},
573     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GBRG},
574     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_GRBG},
575     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_RGGB},
576     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_10BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_10BPP_BGGR},
577     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GBRG},
578     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_GRBG},
579     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_RGGB},
580     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_12BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_12BPP_BGGR},
581     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GBRG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GBRG},
582     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14GRBG,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_GRBG},
583     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14RGGB,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_RGGB},
584     {QC_PIXEL_FORMAT_BAYER_MIPI_RAW_14BGGR,      CAM_FORMAT_BAYER_MIPI_RAW_14BPP_BGGR},
585     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GBRG},
586     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_GRBG},
587     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_RGGB},
588     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_8BPP_BGGR},
589     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GBRG},
590     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_GRBG},
591     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_RGGB},
592     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_10BPP_BGGR},
593     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GBRG},
594     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_GRBG},
595     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_RGGB},
596     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_12BPP_BGGR},
597     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GBRG},
598     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_GRBG},
599     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_RGGB},
600     {QC_PIXEL_FORMAT_BAYER_IDEAL_QCOM_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_QCOM_14BPP_BGGR},
601     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GBRG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GBRG},
602     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8GRBG,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_GRBG},
603     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8RGGB,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_RGGB},
604     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_8BGGR,     CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_8BPP_BGGR},
605     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GBRG},
606     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_GRBG},
607     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_RGGB},
608     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_10BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_10BPP_BGGR},
609     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GBRG},
610     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_GRBG},
611     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_RGGB},
612     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_12BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_12BPP_BGGR},
613     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GBRG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GBRG},
614     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14GRBG,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_GRBG},
615     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14RGGB,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_RGGB},
616     {QC_PIXEL_FORMAT_BAYER_IDEAL_MIPI_14BGGR,    CAM_FORMAT_BAYER_IDEAL_RAW_MIPI_14BPP_BGGR},
617     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GBRG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GBRG},
618     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8GRBG,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_GRBG},
619     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8RGGB,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_RGGB},
620     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN8_8BGGR,   CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN8_8BPP_BGGR},
621     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GBRG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GBRG},
622     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8GRBG,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_GRBG},
623     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8RGGB,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_RGGB},
624     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_8BGGR,  CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_8BPP_BGGR},
625     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GBRG},
626     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_GRBG},
627     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_RGGB},
628     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_10BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_10BPP_BGGR},
629     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GBRG},
630     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_GRBG},
631     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_RGGB},
632     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_12BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_12BPP_BGGR},
633     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GBRG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GBRG},
634     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14GRBG, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_GRBG},
635     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14RGGB, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_RGGB},
636     {QC_PIXEL_FORMAT_BAYER_IDEAL_PLAIN16_14BGGR, CAM_FORMAT_BAYER_IDEAL_RAW_PLAIN16_14BPP_BGGR}
637 };
638 
639 const QCameraParameters::QCameraMap<cam_focus_mode_type>
640         QCameraParameters::FOCUS_MODES_MAP[] = {
641     { FOCUS_MODE_AUTO,               CAM_FOCUS_MODE_AUTO },
642     { FOCUS_MODE_INFINITY,           CAM_FOCUS_MODE_INFINITY },
643     { FOCUS_MODE_MACRO,              CAM_FOCUS_MODE_MACRO },
644     { FOCUS_MODE_FIXED,              CAM_FOCUS_MODE_FIXED },
645     { FOCUS_MODE_EDOF,               CAM_FOCUS_MODE_EDOF },
646     { FOCUS_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
647     { FOCUS_MODE_CONTINUOUS_VIDEO,   CAM_FOCUS_MODE_CONTINOUS_VIDEO },
648     { FOCUS_MODE_MANUAL_POSITION,    CAM_FOCUS_MODE_MANUAL},
649 };
650 
651 const QCameraParameters::QCameraMap<cam_effect_mode_type>
652         QCameraParameters::EFFECT_MODES_MAP[] = {
653     { EFFECT_NONE,       CAM_EFFECT_MODE_OFF },
654     { EFFECT_MONO,       CAM_EFFECT_MODE_MONO },
655     { EFFECT_NEGATIVE,   CAM_EFFECT_MODE_NEGATIVE },
656     { EFFECT_SOLARIZE,   CAM_EFFECT_MODE_SOLARIZE },
657     { EFFECT_SEPIA,      CAM_EFFECT_MODE_SEPIA },
658     { EFFECT_POSTERIZE,  CAM_EFFECT_MODE_POSTERIZE },
659     { EFFECT_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
660     { EFFECT_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
661     { EFFECT_AQUA,       CAM_EFFECT_MODE_AQUA },
662     { EFFECT_EMBOSS,     CAM_EFFECT_MODE_EMBOSS },
663     { EFFECT_SKETCH,     CAM_EFFECT_MODE_SKETCH },
664     { EFFECT_NEON,       CAM_EFFECT_MODE_NEON },
665     { EFFECT_BEAUTY,     CAM_EFFECT_MODE_BEAUTY }
666 };
667 
668 const QCameraParameters::QCameraMap<cam_scene_mode_type>
669         QCameraParameters::SCENE_MODES_MAP[] = {
670     { SCENE_MODE_AUTO,           CAM_SCENE_MODE_OFF },
671     { SCENE_MODE_ACTION,         CAM_SCENE_MODE_ACTION },
672     { SCENE_MODE_PORTRAIT,       CAM_SCENE_MODE_PORTRAIT },
673     { SCENE_MODE_LANDSCAPE,      CAM_SCENE_MODE_LANDSCAPE },
674     { SCENE_MODE_NIGHT,          CAM_SCENE_MODE_NIGHT },
675     { SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
676     { SCENE_MODE_THEATRE,        CAM_SCENE_MODE_THEATRE },
677     { SCENE_MODE_BEACH,          CAM_SCENE_MODE_BEACH },
678     { SCENE_MODE_SNOW,           CAM_SCENE_MODE_SNOW },
679     { SCENE_MODE_SUNSET,         CAM_SCENE_MODE_SUNSET },
680     { SCENE_MODE_STEADYPHOTO,    CAM_SCENE_MODE_ANTISHAKE },
681     { SCENE_MODE_FIREWORKS ,     CAM_SCENE_MODE_FIREWORKS },
682     { SCENE_MODE_SPORTS ,        CAM_SCENE_MODE_SPORTS },
683     { SCENE_MODE_PARTY,          CAM_SCENE_MODE_PARTY },
684     { SCENE_MODE_CANDLELIGHT,    CAM_SCENE_MODE_CANDLELIGHT },
685     { SCENE_MODE_ASD,            CAM_SCENE_MODE_AUTO },
686     { SCENE_MODE_BACKLIGHT,      CAM_SCENE_MODE_BACKLIGHT },
687     { SCENE_MODE_FLOWERS,        CAM_SCENE_MODE_FLOWERS },
688     { SCENE_MODE_AR,             CAM_SCENE_MODE_AR },
689     { SCENE_MODE_HDR,            CAM_SCENE_MODE_HDR },
690 };
691 
692 const QCameraParameters::QCameraMap<cam_flash_mode_t>
693         QCameraParameters::FLASH_MODES_MAP[] = {
694     { FLASH_MODE_OFF,   CAM_FLASH_MODE_OFF },
695     { FLASH_MODE_AUTO,  CAM_FLASH_MODE_AUTO },
696     { FLASH_MODE_ON,    CAM_FLASH_MODE_ON },
697     { FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
698 };
699 
700 const QCameraParameters::QCameraMap<cam_focus_algorithm_type>
701          QCameraParameters::FOCUS_ALGO_MAP[] = {
702     { FOCUS_ALGO_AUTO,            CAM_FOCUS_ALGO_AUTO },
703     { FOCUS_ALGO_SPOT_METERING,   CAM_FOCUS_ALGO_SPOT },
704     { FOCUS_ALGO_CENTER_WEIGHTED, CAM_FOCUS_ALGO_CENTER_WEIGHTED },
705     { FOCUS_ALGO_FRAME_AVERAGE,   CAM_FOCUS_ALGO_AVERAGE }
706 };
707 
708 const QCameraParameters::QCameraMap<cam_wb_mode_type>
709         QCameraParameters::WHITE_BALANCE_MODES_MAP[] = {
710     { WHITE_BALANCE_AUTO,            CAM_WB_MODE_AUTO },
711     { WHITE_BALANCE_INCANDESCENT,    CAM_WB_MODE_INCANDESCENT },
712     { WHITE_BALANCE_FLUORESCENT,     CAM_WB_MODE_FLUORESCENT },
713     { WHITE_BALANCE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
714     { WHITE_BALANCE_DAYLIGHT,        CAM_WB_MODE_DAYLIGHT },
715     { WHITE_BALANCE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
716     { WHITE_BALANCE_TWILIGHT,        CAM_WB_MODE_TWILIGHT },
717     { WHITE_BALANCE_SHADE,           CAM_WB_MODE_SHADE },
718     { WHITE_BALANCE_MANUAL,          CAM_WB_MODE_MANUAL},
719 };
720 
721 const QCameraParameters::QCameraMap<cam_antibanding_mode_type>
722         QCameraParameters::ANTIBANDING_MODES_MAP[] = {
723     { ANTIBANDING_OFF,  CAM_ANTIBANDING_MODE_OFF },
724     { ANTIBANDING_50HZ, CAM_ANTIBANDING_MODE_50HZ },
725     { ANTIBANDING_60HZ, CAM_ANTIBANDING_MODE_60HZ },
726     { ANTIBANDING_AUTO, CAM_ANTIBANDING_MODE_AUTO }
727 };
728 
729 const QCameraParameters::QCameraMap<cam_iso_mode_type>
730         QCameraParameters::ISO_MODES_MAP[] = {
731     { ISO_AUTO,  CAM_ISO_MODE_AUTO },
732     { ISO_HJR,   CAM_ISO_MODE_DEBLUR },
733     { ISO_100,   CAM_ISO_MODE_100 },
734     { ISO_200,   CAM_ISO_MODE_200 },
735     { ISO_400,   CAM_ISO_MODE_400 },
736     { ISO_800,   CAM_ISO_MODE_800 },
737     { ISO_1600,  CAM_ISO_MODE_1600 },
738     { ISO_3200,  CAM_ISO_MODE_3200 }
739 };
740 
741 const QCameraParameters::QCameraMap<cam_hfr_mode_t>
742         QCameraParameters::HFR_MODES_MAP[] = {
743     { VIDEO_HFR_OFF, CAM_HFR_MODE_OFF },
744     { VIDEO_HFR_2X, CAM_HFR_MODE_60FPS },
745     { VIDEO_HFR_3X, CAM_HFR_MODE_90FPS },
746     { VIDEO_HFR_4X, CAM_HFR_MODE_120FPS },
747     { VIDEO_HFR_5X, CAM_HFR_MODE_150FPS },
748     { VIDEO_HFR_6X, CAM_HFR_MODE_180FPS },
749     { VIDEO_HFR_7X, CAM_HFR_MODE_210FPS },
750     { VIDEO_HFR_8X, CAM_HFR_MODE_240FPS },
751     { VIDEO_HFR_9X, CAM_HFR_MODE_480FPS }
752 };
753 
754 const QCameraParameters::QCameraMap<cam_bracket_mode>
755         QCameraParameters::BRACKETING_MODES_MAP[] = {
756     { AE_BRACKET_OFF, CAM_EXP_BRACKETING_OFF },
757     { AE_BRACKET,     CAM_EXP_BRACKETING_ON }
758 };
759 
760 const QCameraParameters::QCameraMap<int>
761         QCameraParameters::ON_OFF_MODES_MAP[] = {
762     { VALUE_OFF, 0 },
763     { VALUE_ON,  1 }
764 };
765 
766 const QCameraParameters::QCameraMap<int>
767         QCameraParameters::TOUCH_AF_AEC_MODES_MAP[] = {
768     { QCameraParameters::TOUCH_AF_AEC_OFF, 0 },
769     { QCameraParameters::TOUCH_AF_AEC_ON, 1 }
770 };
771 
772 const QCameraParameters::QCameraMap<int>
773         QCameraParameters::ENABLE_DISABLE_MODES_MAP[] = {
774     { VALUE_ENABLE,  1 },
775     { VALUE_DISABLE, 0 }
776 };
777 
778 const QCameraParameters::QCameraMap<int>
779         QCameraParameters::DENOISE_ON_OFF_MODES_MAP[] = {
780     { DENOISE_OFF, 0 },
781     { DENOISE_ON,  1 }
782 };
783 
784 const QCameraParameters::QCameraMap<int>
785         QCameraParameters::TRUE_FALSE_MODES_MAP[] = {
786     { VALUE_FALSE, 0},
787     { VALUE_TRUE,  1}
788 };
789 
790 const QCameraParameters::QCameraMap<cam_flip_t>
791         QCameraParameters::FLIP_MODES_MAP[] = {
792     {FLIP_MODE_OFF, FLIP_NONE},
793     {FLIP_MODE_V, FLIP_V},
794     {FLIP_MODE_H, FLIP_H},
795     {FLIP_MODE_VH, FLIP_V_H}
796 };
797 
798 const QCameraParameters::QCameraMap<int>
799         QCameraParameters::AF_BRACKETING_MODES_MAP[] = {
800     { AF_BRACKET_OFF, 0 },
801     { AF_BRACKET_ON,  1 }
802 };
803 
804 const QCameraParameters::QCameraMap<int>
805         QCameraParameters::RE_FOCUS_MODES_MAP[] = {
806     { RE_FOCUS_OFF, 0 },
807     { RE_FOCUS_ON,  1 }
808 };
809 
810 const QCameraParameters::QCameraMap<int>
811         QCameraParameters::CHROMA_FLASH_MODES_MAP[] = {
812     { CHROMA_FLASH_OFF, 0 },
813     { CHROMA_FLASH_ON,  1 }
814 };
815 
816 const QCameraParameters::QCameraMap<int>
817         QCameraParameters::OPTI_ZOOM_MODES_MAP[] = {
818     { OPTI_ZOOM_OFF, 0 },
819     { OPTI_ZOOM_ON,  1 }
820 };
821 
822 const QCameraParameters::QCameraMap<int>
823         QCameraParameters::TRUE_PORTRAIT_MODES_MAP[] = {
824     { TRUE_PORTRAIT_OFF, 0 },
825     { TRUE_PORTRAIT_ON,  1 }
826 };
827 
828 const QCameraParameters::QCameraMap<int>
829         QCameraParameters::STILL_MORE_MODES_MAP[] = {
830     { STILL_MORE_OFF, 0 },
831     { STILL_MORE_ON,  1 }
832 };
833 
834 const QCameraParameters::QCameraMap<cam_cds_mode_type_t>
835         QCameraParameters::CDS_MODES_MAP[] = {
836     { CDS_MODE_OFF, CAM_CDS_MODE_OFF },
837     { CDS_MODE_ON, CAM_CDS_MODE_ON },
838     { CDS_MODE_AUTO, CAM_CDS_MODE_AUTO}
839 };
840 
841 const QCameraParameters::QCameraMap<int>
842         QCameraParameters::HDR_MODES_MAP[] = {
843     { HDR_MODE_SENSOR, 0 },
844     { HDR_MODE_MULTI_FRAME, 1 }
845 };
846 
847 const QCameraParameters::QCameraMap<int>
848         QCameraParameters::VIDEO_ROTATION_MODES_MAP[] = {
849     { VIDEO_ROTATION_0, 0 },
850     { VIDEO_ROTATION_90, 90 },
851     { VIDEO_ROTATION_180, 180 },
852     { VIDEO_ROTATION_270, 270 }
853 };
854 
855 const QCameraParameters::QCameraMap<int>
856         QCameraParameters::NOISE_REDUCTION_MODES_MAP[] = {
857     { VALUE_OFF, 0 },
858     { VALUE_FAST,  1 },
859     { VALUE_HIGH_QUALITY,  2 }
860 };
861 
862 #define DEFAULT_CAMERA_AREA "(0, 0, 0, 0, 0)"
863 #define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
864 #define TOTAL_RAM_SIZE_512MB 536870912
865 #define PARAM_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
866 
867 /*===========================================================================
868  * FUNCTION   : isOEMFeat1PropEnabled
869  *
870  * DESCRIPTION: inline function to check from property if custom feature
871  *            is enabled
872  *
873  * PARAMETERS : none
874  *
875  * RETURN     : boolean true/false
876  *==========================================================================*/
isOEMFeat1PropEnabled()877 static inline bool isOEMFeat1PropEnabled()
878 {
879     char value[PROPERTY_VALUE_MAX];
880     property_get("persist.camera.imglib.oemfeat1", value, "0");
881     return atoi(value) > 0 ? true : false;
882 }
883 
884 /*===========================================================================
885  * FUNCTION   : QCameraParameters
886  *
887  * DESCRIPTION: default constructor of QCameraParameters
888  *
889  * PARAMETERS : none
890  *
891  * RETURN     : None
892  *==========================================================================*/
QCameraParameters()893 QCameraParameters::QCameraParameters()
894     : CameraParameters(),
895       m_reprocScaleParam(),
896       m_pCapability(NULL),
897       m_pCamOpsTbl(NULL),
898       m_pParamHeap(NULL),
899       m_pParamBuf(NULL),
900       m_pRelCamSyncHeap(NULL),
901       m_pRelCamSyncBuf(NULL),
902       mIsType(IS_TYPE_NONE),
903       m_bZslMode(false),
904       m_bZslMode_new(false),
905       m_bForceZslMode(false),
906       m_bRecordingHint(false),
907       m_bRecordingHint_new(false),
908       m_bHistogramEnabled(false),
909       m_bLongshotEnabled(false),
910       m_nFaceProcMask(0),
911       m_bFaceDetectionOn(0),
912       m_bDebugFps(false),
913       mFocusMode(CAM_FOCUS_MODE_MAX),
914       mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
915       mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
916       mPictureFormat(CAM_FORMAT_JPEG),
917       m_bNeedRestart(false),
918       m_bNoDisplayMode(false),
919       m_bWNROn(false),
920       m_bTNRPreviewOn(false),
921       m_bTNRVideoOn(false),
922       m_bTNRSnapshotOn(false),
923       m_bInited(false),
924       m_nRetroBurstNum(0),
925       m_nBurstLEDOnPeriod(100),
926       m_bUpdateEffects(false),
927       m_bSceneTransitionAuto(false),
928       m_bPreviewFlipChanged(false),
929       m_bVideoFlipChanged(false),
930       m_bSnapshotFlipChanged(false),
931       m_bFixedFrameRateSet(false),
932       m_bHDREnabled(false),
933       m_bAVTimerEnabled(false),
934       m_bDISEnabled(false),
935       m_MobiMask(0),
936       m_AdjustFPS(NULL),
937       m_bHDR1xFrameEnabled(false),
938       m_HDRSceneEnabled(false),
939       m_bHDRThumbnailProcessNeeded(false),
940       m_bHDR1xExtraBufferNeeded(true),
941       m_bHDROutputCropEnabled(false),
942       m_tempMap(),
943       m_bAFBracketingOn(false),
944       m_bReFocusOn(false),
945       m_bChromaFlashOn(false),
946       m_bOptiZoomOn(false),
947       m_bSceneSelection(false),
948       m_SelectedScene(CAM_SCENE_MODE_MAX),
949       m_bSeeMoreOn(false),
950       m_bStillMoreOn(false),
951       m_bHighQualityNoiseReductionMode(false),
952       m_bHfrMode(false),
953       m_bSensorHDREnabled(false),
954       m_bRdiMode(false),
955       m_bSecureMode(false),
956       m_bAeBracketingEnabled(false),
957       mFlashValue(CAM_FLASH_MODE_OFF),
958       mFlashDaemonValue(CAM_FLASH_MODE_OFF),
959       mHfrMode(CAM_HFR_MODE_OFF),
960       m_bHDRModeSensor(true),
961       mOfflineRAW(false),
962       m_bTruePortraitOn(false),
963       m_bIsLowMemoryDevice(false),
964       mCds_mode(CAM_CDS_MODE_OFF),
965       m_LLCaptureEnabled(FALSE),
966       m_LowLightLevel(CAM_LOW_LIGHT_OFF),
967       m_bLtmForSeeMoreEnabled(false),
968       m_expTime(0),
969       m_isoValue(0),
970       m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
971       m_dualLedCalibration(0),
972       m_bInstantAEC(false),
973       m_bInstantCapture(false),
974       mAecFrameBound(0),
975       mAecSkipDisplayFrameBound(0)
976 {
977     char value[PROPERTY_VALUE_MAX];
978     // TODO: may move to parameter instead of sysprop
979     property_get("persist.debug.sf.showfps", value, "0");
980     m_bDebugFps = atoi(value) > 0 ? true : false;
981 
982     // For thermal mode, it should be set as system property
983     // because system property applies to all applications, while
984     // parameters only apply to specific app.
985     property_get("persist.camera.thermal.mode", value, "fps");
986     if (!strcmp(value, "frameskip")) {
987         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FRAMESKIP;
988     } else {
989         if (strcmp(value, "fps"))
990             LOGW("Invalid camera thermal mode %s", value);
991         m_ThermalMode = QCAMERA_THERMAL_ADJUST_FPS;
992     }
993 
994     memset(value, 0, sizeof(value));
995     // As per Power/Quality evaluation, LTM is enabled by default in SeeMore/StillMore usecase
996     // to improve the quality as there is no much impact to power
997     property_get("persist.camera.ltmforseemore", value, "1");
998     m_bLtmForSeeMoreEnabled = atoi(value);
999 
1000     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
1001     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
1002     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
1003     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
1004     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
1005     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
1006     mTotalPPCount = 1;
1007     mZoomLevel = 0;
1008     mParmZoomLevel = 0;
1009     mCurPPCount = 0;
1010     mBufBatchCnt = 0;
1011     mRotation = 0;
1012     mJpegRotation = 0;
1013     mVideoBatchSize = 0;
1014     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
1015 }
1016 
1017 /*===========================================================================
1018  * FUNCTION   : QCameraParameters
1019  *
1020  * DESCRIPTION: constructor of QCameraParameters
1021  *
1022  * PARAMETERS :
1023  *   @params  : parameters in string
1024  *
1025  * RETURN     : None
1026  *==========================================================================*/
QCameraParameters(const String8 & params)1027 QCameraParameters::QCameraParameters(const String8 &params)
1028     : CameraParameters(params),
1029     m_reprocScaleParam(),
1030     m_pCapability(NULL),
1031     m_pCamOpsTbl(NULL),
1032     m_pParamHeap(NULL),
1033     m_pParamBuf(NULL),
1034     m_pRelCamSyncHeap(NULL),
1035     m_pRelCamSyncBuf(NULL),
1036     m_bZslMode(false),
1037     m_bZslMode_new(false),
1038     m_bForceZslMode(false),
1039     m_bRecordingHint(false),
1040     m_bRecordingHint_new(false),
1041     m_bHistogramEnabled(false),
1042     m_bLongshotEnabled(false),
1043     m_nFaceProcMask(0),
1044     m_bDebugFps(false),
1045     mFocusMode(CAM_FOCUS_MODE_MAX),
1046     mPreviewFormat(CAM_FORMAT_YUV_420_NV21),
1047     mAppPreviewFormat(CAM_FORMAT_YUV_420_NV21),
1048     mPictureFormat(CAM_FORMAT_JPEG),
1049     m_bNeedRestart(false),
1050     m_bNoDisplayMode(false),
1051     m_bWNROn(false),
1052     m_bTNRPreviewOn(false),
1053     m_bTNRVideoOn(false),
1054     m_bTNRSnapshotOn(false),
1055     m_bInited(false),
1056     m_nRetroBurstNum(0),
1057     m_nBurstLEDOnPeriod(100),
1058     m_bPreviewFlipChanged(false),
1059     m_bVideoFlipChanged(false),
1060     m_bSnapshotFlipChanged(false),
1061     m_bFixedFrameRateSet(false),
1062     m_bHDREnabled(false),
1063     m_bAVTimerEnabled(false),
1064     m_AdjustFPS(NULL),
1065     m_bHDR1xFrameEnabled(false),
1066     m_HDRSceneEnabled(false),
1067     m_bHDRThumbnailProcessNeeded(false),
1068     m_bHDR1xExtraBufferNeeded(true),
1069     m_bHDROutputCropEnabled(false),
1070     m_tempMap(),
1071     m_bAFBracketingOn(false),
1072     m_bReFocusOn(false),
1073     m_bChromaFlashOn(false),
1074     m_bOptiZoomOn(false),
1075     m_bSceneSelection(false),
1076     m_SelectedScene(CAM_SCENE_MODE_MAX),
1077     m_bSeeMoreOn(false),
1078     m_bStillMoreOn(false),
1079     m_bHighQualityNoiseReductionMode(false),
1080     m_bHfrMode(false),
1081     m_bSensorHDREnabled(false),
1082     m_bRdiMode(false),
1083     m_bSecureMode(false),
1084     m_bAeBracketingEnabled(false),
1085     mFlashValue(CAM_FLASH_MODE_OFF),
1086     mFlashDaemonValue(CAM_FLASH_MODE_OFF),
1087     mHfrMode(CAM_HFR_MODE_OFF),
1088     m_bHDRModeSensor(true),
1089     mOfflineRAW(false),
1090     m_bTruePortraitOn(false),
1091     m_bIsLowMemoryDevice(false),
1092     mCds_mode(CAM_CDS_MODE_OFF),
1093     mParmEffect(CAM_EFFECT_MODE_OFF),
1094     m_LLCaptureEnabled(FALSE),
1095     m_LowLightLevel(CAM_LOW_LIGHT_OFF),
1096     m_bLtmForSeeMoreEnabled(false),
1097     m_expTime(0),
1098     m_isoValue(0),
1099     m_ManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF),
1100     m_dualLedCalibration(0),
1101     m_bInstantAEC(false),
1102     m_bInstantCapture(false),
1103     mAecFrameBound(0),
1104     mAecSkipDisplayFrameBound(0)
1105 {
1106     memset(&m_LiveSnapshotSize, 0, sizeof(m_LiveSnapshotSize));
1107     memset(&m_default_fps_range, 0, sizeof(m_default_fps_range));
1108     memset(&m_hfrFpsRange, 0, sizeof(m_hfrFpsRange));
1109     memset(&m_stillmore_config, 0, sizeof(cam_still_more_t));
1110     memset(&m_relCamSyncInfo, 0, sizeof(cam_sync_related_sensors_event_info_t));
1111     mTotalPPCount = 0;
1112     mZoomLevel = 0;
1113     mParmZoomLevel = 0;
1114     mCurPPCount = 0;
1115     mRotation = 0;
1116     mJpegRotation = 0;
1117     mBufBatchCnt = 0;
1118     mVideoBatchSize = 0;
1119     m_bOEMFeatEnabled = isOEMFeat1PropEnabled();
1120 }
1121 
1122 /*===========================================================================
1123  * FUNCTION   : ~QCameraParameters
1124  *
1125  * DESCRIPTION: deconstructor of QCameraParameters
1126  *
1127  * PARAMETERS : none
1128  *
1129  * RETURN     : None
1130  *==========================================================================*/
~QCameraParameters()1131 QCameraParameters::~QCameraParameters()
1132 {
1133     deinit();
1134 }
1135 
1136 /*===========================================================================
1137  * FUNCTION   : createSizesString
1138  *
1139  * DESCRIPTION: create string obj contains array of dimensions
1140  *
1141  * PARAMETERS :
1142  *   @sizes   : array of dimensions
1143  *   @len     : size of dimension array
1144  *
1145  * RETURN     : string obj
1146  *==========================================================================*/
createSizesString(const cam_dimension_t * sizes,size_t len)1147 String8 QCameraParameters::createSizesString(const cam_dimension_t *sizes, size_t len)
1148 {
1149     String8 str;
1150     char buffer[32];
1151 
1152     if (len > 0) {
1153         snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
1154         str.append(buffer);
1155     }
1156     for (size_t i = 1; i < len; i++) {
1157         snprintf(buffer, sizeof(buffer), ",%dx%d",
1158                 sizes[i].width, sizes[i].height);
1159         str.append(buffer);
1160     }
1161     return str;
1162 }
1163 
1164 /*===========================================================================
1165  * FUNCTION   : createValuesString
1166  *
1167  * DESCRIPTION: create string obj contains array of values from map when matched
1168  *              from input values array
1169  *
1170  * PARAMETERS :
1171  *   @values  : array of values
1172  *   @len     : size of values array
1173  *   @map     : map contains the mapping between values and enums
1174  *   @map_len : size of the map
1175  *
1176  * RETURN     : string obj
1177  *==========================================================================*/
createValuesString(const valuesType * values,size_t len,const mapType * map,size_t map_len)1178 template <typename valuesType, class mapType> String8 createValuesString(
1179         const valuesType *values, size_t len, const mapType *map, size_t map_len)
1180 {
1181     String8 str;
1182     int count = 0;
1183 
1184     for (size_t i = 0; i < len; i++ ) {
1185         for (size_t j = 0; j < map_len; j ++)
1186             if (map[j].val == values[i]) {
1187                 if (NULL != map[j].desc) {
1188                     if (count > 0) {
1189                         str.append(",");
1190                     }
1191                     str.append(map[j].desc);
1192                     count++;
1193                     break; //loop j
1194                 }
1195             }
1196     }
1197     return str;
1198 }
1199 
1200 /*===========================================================================
1201  * FUNCTION   : createValuesStringFromMap
1202  *
1203  * DESCRIPTION: create string obj contains array of values directly from map
1204  *
1205  * PARAMETERS :
1206  *   @map     : map contains the mapping between values and enums
1207  *   @map_len : size of the map
1208  *
1209  * RETURN     : string obj
1210  *==========================================================================*/
createValuesStringFromMap(const mapType * map,size_t map_len)1211 template <class mapType> String8 createValuesStringFromMap(
1212         const mapType *map, size_t map_len)
1213 {
1214     String8 str;
1215 
1216     for (size_t i = 0; i < map_len; i++) {
1217         if (NULL != map[i].desc) {
1218             if (i > 0) {
1219                 str.append(",");
1220             }
1221             str.append(map[i].desc);
1222         }
1223     }
1224     return str;
1225 }
1226 
1227 /*===========================================================================
1228  * FUNCTION   : createZoomRatioValuesString
1229  *
1230  * DESCRIPTION: create string obj contains array of zoom ratio values
1231  *
1232  * PARAMETERS :
1233  *   @zoomRaios  : array of zoom ratios
1234  *   @length     : size of the array
1235  *
1236  * RETURN     : string obj
1237  *==========================================================================*/
createZoomRatioValuesString(uint32_t * zoomRatios,size_t length)1238 String8 QCameraParameters::createZoomRatioValuesString(uint32_t *zoomRatios,
1239         size_t length)
1240 {
1241     String8 str;
1242     char buffer[32] = {0};
1243 
1244     if(length > 0){
1245         snprintf(buffer, sizeof(buffer), "%d", zoomRatios[0]);
1246         str.append(buffer);
1247     }
1248 
1249     for (size_t i = 1; i < length; i++) {
1250         memset(buffer, 0, sizeof(buffer));
1251         snprintf(buffer, sizeof(buffer), ",%d", zoomRatios[i]);
1252         str.append(buffer);
1253     }
1254     return str;
1255 }
1256 
1257 /*===========================================================================
1258  * FUNCTION   : createHfrValuesString
1259  *
1260  * DESCRIPTION: create string obj contains array of hfr values from map when
1261  *              matched from input hfr values
1262  *
1263  * PARAMETERS :
1264  *   @values  : array of hfr info
1265  *   @len     : size of the array
1266  *   @map     : map of hfr string value and enum
1267  *   map_len  : size of map
1268  *
1269  * RETURN     : string obj
1270  *==========================================================================*/
createHfrValuesString(const cam_hfr_info_t * values,size_t len,const QCameraMap<cam_hfr_mode_t> * map,size_t map_len)1271 String8 QCameraParameters::createHfrValuesString(const cam_hfr_info_t *values,
1272         size_t len, const QCameraMap<cam_hfr_mode_t> *map, size_t map_len)
1273 {
1274     String8 str;
1275     int count = 0;
1276 
1277     char value[PROPERTY_VALUE_MAX];
1278     int8_t batch_count = 0;
1279 
1280     property_get("persist.camera.batchcount", value, "0");
1281     batch_count = atoi(value);
1282 
1283     for (size_t i = 0; i < len; i++ ) {
1284         for (size_t j = 0; j < map_len; j ++) {
1285             if ((batch_count < CAMERA_MIN_BATCH_COUNT)
1286                     && (map[j].val > CAM_HFR_MODE_120FPS)) {
1287                 /*TODO: Work around. Need to revert when we have
1288                 complete 240fps support*/
1289                 break;
1290             }
1291             if (map[j].val == (int)values[i].mode) {
1292                 if (NULL != map[j].desc) {
1293                     if (count > 0) {
1294                         str.append(",");
1295                     }
1296                      str.append(map[j].desc);
1297                      count++;
1298                      break; //loop j
1299                 }
1300             }
1301         }
1302     }
1303     if (count > 0) {
1304         str.append(",");
1305     }
1306     str.append(VIDEO_HFR_OFF);
1307     return str;
1308 }
1309 
1310 /*===========================================================================
1311  * FUNCTION   : createHfrSizesString
1312  *
1313  * DESCRIPTION: create string obj contains array of hfr sizes
1314  *
1315  * PARAMETERS :
1316  *   @values  : array of hfr info
1317  *   @len     : size of the array
1318  *
1319  * RETURN     : string obj
1320  *==========================================================================*/
createHfrSizesString(const cam_hfr_info_t * values,size_t len)1321 String8 QCameraParameters::createHfrSizesString(const cam_hfr_info_t *values, size_t len)
1322 {
1323     String8 str;
1324     char buffer[32];
1325 
1326     if (len > 0) {
1327         snprintf(buffer, sizeof(buffer), "%dx%d",
1328                  values[0].dim.width, values[0].dim.height);
1329         str.append(buffer);
1330     }
1331     for (size_t i = 1; i < len; i++) {
1332         snprintf(buffer, sizeof(buffer), ",%dx%d",
1333                  values[i].dim.width, values[i].dim.height);
1334         str.append(buffer);
1335     }
1336     return str;
1337 }
1338 
1339 /*===========================================================================
1340  * FUNCTION   : createFpsString
1341  *
1342  * DESCRIPTION: create string obj contains array of FPS rates
1343  *
1344  * PARAMETERS :
1345  *   @fps     : default fps range
1346  *
1347  * RETURN     : string obj
1348  *==========================================================================*/
createFpsString(cam_fps_range_t & fps)1349 String8 QCameraParameters::createFpsString(cam_fps_range_t &fps)
1350 {
1351     char buffer[32];
1352     String8 fpsValues;
1353 
1354     int min_fps = int(fps.min_fps);
1355     int max_fps = int(fps.max_fps);
1356 
1357     if (min_fps < fps.min_fps){
1358         min_fps++;
1359     }
1360     if (max_fps > fps.max_fps) {
1361         max_fps--;
1362     }
1363     if (min_fps <= max_fps) {
1364         snprintf(buffer, sizeof(buffer), "%d", min_fps);
1365         fpsValues.append(buffer);
1366     }
1367 
1368     for (int i = min_fps+1; i <= max_fps; i++) {
1369         snprintf(buffer, sizeof(buffer), ",%d", i);
1370         fpsValues.append(buffer);
1371     }
1372 
1373     return fpsValues;
1374 }
1375 
1376 /*===========================================================================
1377  * FUNCTION   : createFpsRangeString
1378  *
1379  * DESCRIPTION: create string obj contains array of FPS ranges
1380  *
1381  * PARAMETERS :
1382  *   @fps     : array of fps ranges
1383  *   @len     : size of the array
1384  *   @default_fps_index : reference to index of default fps range
1385  *
1386  * RETURN     : string obj
1387  *==========================================================================*/
createFpsRangeString(const cam_fps_range_t * fps,size_t len,int & default_fps_index)1388 String8 QCameraParameters::createFpsRangeString(const cam_fps_range_t* fps,
1389         size_t len, int &default_fps_index)
1390 {
1391     String8 str;
1392     char buffer[32];
1393     int max_range = 0;
1394     int min_fps, max_fps;
1395 
1396     if (len > 0) {
1397         min_fps = int(fps[0].min_fps * 1000);
1398         max_fps = int(fps[0].max_fps * 1000);
1399         max_range = max_fps - min_fps;
1400         default_fps_index = 0;
1401         snprintf(buffer, sizeof(buffer), "(%d,%d)", min_fps, max_fps);
1402         str.append(buffer);
1403     }
1404     for (size_t i = 1; i < len; i++) {
1405         min_fps = int(fps[i].min_fps * 1000);
1406         max_fps = int(fps[i].max_fps * 1000);
1407         if (max_range < (max_fps - min_fps)) {
1408             max_range = max_fps - min_fps;
1409             default_fps_index = (int)i;
1410         }
1411         snprintf(buffer, sizeof(buffer), ",(%d,%d)", min_fps, max_fps);
1412         str.append(buffer);
1413     }
1414     return str;
1415 }
1416 
1417 /*===========================================================================
1418  * FUNCTION   : lookupAttr
1419  *
1420  * DESCRIPTION: lookup a value by its name
1421  *
1422  * PARAMETERS :
1423  *   @attr    : map contains <name, value>
1424  *   @len     : size of the map
1425  *   @name    : name to be looked up
1426  *
1427  * RETURN     : valid value if found
1428  *              NAME_NOT_FOUND if not found
1429  *==========================================================================*/
lookupAttr(const mapType * arr,size_t len,const char * name)1430 template <class mapType> int lookupAttr(const mapType *arr,
1431         size_t len, const char *name)
1432 {
1433     if (name) {
1434         for (size_t i = 0; i < len; i++) {
1435             if (!strcmp(arr[i].desc, name))
1436                 return arr[i].val;
1437         }
1438     }
1439     return NAME_NOT_FOUND;
1440 }
1441 
1442 /*===========================================================================
1443  * FUNCTION   : lookupNameByValue
1444  *
1445  * DESCRIPTION: lookup a name by its value
1446  *
1447  * PARAMETERS :
1448  *   @attr    : map contains <name, value>
1449  *   @len     : size of the map
1450  *   @value   : value to be looked up
1451  *
1452  * RETURN     : name str or NULL if not found
1453  *==========================================================================*/
lookupNameByValue(const mapType * arr,size_t len,int value)1454 template <class mapType> const char *lookupNameByValue(const mapType *arr,
1455         size_t len, int value)
1456 {
1457     for (size_t i = 0; i < len; i++) {
1458         if (arr[i].val == value) {
1459             return arr[i].desc;
1460         }
1461     }
1462     return NULL;
1463 }
1464 
1465 /*===========================================================================
1466  * FUNCTION   : setPreviewSize
1467  *
1468  * DESCRIPTION: set preview size from user setting
1469  *
1470  * PARAMETERS :
1471  *   @params  : user setting parameters
1472  *
1473  * RETURN     : int32_t type of status
1474  *              NO_ERROR  -- success
1475  *              none-zero failure code
1476  *==========================================================================*/
setPreviewSize(const QCameraParameters & params)1477 int32_t QCameraParameters::setPreviewSize(const QCameraParameters& params)
1478 {
1479     int width = 0, height = 0;
1480     int old_width = 0, old_height = 0;
1481     params.getPreviewSize(&width, &height);
1482     CameraParameters::getPreviewSize(&old_width, &old_height);
1483 
1484     // Validate the preview size
1485     for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
1486         if (width ==  m_pCapability->preview_sizes_tbl[i].width
1487            && height ==  m_pCapability->preview_sizes_tbl[i].height) {
1488             // check if need to restart preview in case of preview size change
1489             if (width != old_width || height != old_height) {
1490                 LOGI("Requested preview size %d x %d", width, height);
1491                 m_bNeedRestart = true;
1492             }
1493             // set the new value
1494             CameraParameters::setPreviewSize(width, height);
1495             return NO_ERROR;
1496         }
1497     }
1498     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1499         char prop[PROPERTY_VALUE_MAX];
1500         // set prop to configure aux preview size
1501         property_get("persist.camera.aux.preview.size", prop, "0");
1502         parse_pair(prop, &width, &height, 'x', NULL);
1503         bool foundMatch = false;
1504         for (size_t i = 0; i < m_pCapability->preview_sizes_tbl_cnt; ++i) {
1505             if (width ==  m_pCapability->preview_sizes_tbl[i].width &&
1506                     height ==  m_pCapability->preview_sizes_tbl[i].height) {
1507                foundMatch = true;
1508             }
1509         }
1510         if (!foundMatch) {
1511             width = m_pCapability->preview_sizes_tbl[0].width;
1512             height = m_pCapability->preview_sizes_tbl[0].height;
1513         }
1514         // check if need to restart preview in case of preview size change
1515         if (width != old_width || height != old_height) {
1516             m_bNeedRestart = true;
1517         }
1518         CameraParameters::setPreviewSize(width, height);
1519         LOGH("Secondary Camera: preview size %d x %d", width, height);
1520         return NO_ERROR;
1521     }
1522 
1523     LOGE("Invalid preview size requested: %dx%d", width, height);
1524     return BAD_VALUE;
1525 }
1526 
1527 /*===========================================================================
1528  * FUNCTION   : setPictureSize
1529  *
1530  * DESCRIPTION: set picture size from user setting
1531  *
1532  * PARAMETERS :
1533  *   @params  : user setting parameters
1534  *
1535  * RETURN     : int32_t type of status
1536  *              NO_ERROR  -- success
1537  *              none-zero failure code
1538  *==========================================================================*/
setPictureSize(const QCameraParameters & params)1539 int32_t QCameraParameters::setPictureSize(const QCameraParameters& params)
1540 {
1541     int width, height;
1542     params.getPictureSize(&width, &height);
1543     int old_width, old_height;
1544     CameraParameters::getPictureSize(&old_width, &old_height);
1545 
1546     // Validate the picture size
1547     if(!m_reprocScaleParam.isScaleEnabled()){
1548         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1549             if (width ==  m_pCapability->picture_sizes_tbl[i].width
1550                && height ==  m_pCapability->picture_sizes_tbl[i].height) {
1551                 // check if need to restart preview in case of picture size change
1552                 if ((m_bZslMode || m_bRecordingHint) &&
1553                     (width != old_width || height != old_height)) {
1554                     LOGI("Requested picture size %d x %d", width, height);
1555                     m_bNeedRestart = true;
1556                 }
1557                 // set the new value
1558                 CameraParameters::setPictureSize(width, height);
1559                 // Update View angles based on Picture Aspect ratio
1560                 updateViewAngles();
1561                 return NO_ERROR;
1562             }
1563         }
1564     }else{
1565         //should use scaled picture size table to validate
1566         if(m_reprocScaleParam.setValidatePicSize(width, height) == NO_ERROR){
1567             // check if need to restart preview in case of picture size change
1568             if ((m_bZslMode || m_bRecordingHint) &&
1569                 (width != old_width || height != old_height)) {
1570                 m_bNeedRestart = true;
1571             }
1572             // set the new value
1573             char val[32];
1574             snprintf(val, sizeof(val), "%dx%d", width, height);
1575             updateParamEntry(KEY_PICTURE_SIZE, val);
1576             LOGH("%s", val);
1577             // Update View angles based on Picture Aspect ratio
1578             updateViewAngles();
1579             return NO_ERROR;
1580         }
1581     }
1582     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1583         char prop[PROPERTY_VALUE_MAX];
1584         // set prop to configure aux preview size
1585         property_get("persist.camera.aux.picture.size", prop, "0");
1586         parse_pair(prop, &width, &height, 'x', NULL);
1587         bool foundMatch = false;
1588         for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1589             if (width ==  m_pCapability->picture_sizes_tbl[i].width &&
1590                     height ==  m_pCapability->picture_sizes_tbl[i].height) {
1591                foundMatch = true;
1592             }
1593         }
1594         if (!foundMatch) {
1595             width = m_pCapability->picture_sizes_tbl[0].width;
1596             height = m_pCapability->picture_sizes_tbl[0].height;
1597         }
1598         // check if need to restart preview in case of preview size change
1599         if (width != old_width || height != old_height) {
1600             m_bNeedRestart = true;
1601         }
1602         char val[32];
1603         snprintf(val, sizeof(val), "%dx%d", width, height);
1604         set(KEY_PICTURE_SIZE, val);
1605         LOGH("Secondary Camera: picture size %s", val);
1606         return NO_ERROR;
1607     }
1608     LOGE("Invalid picture size requested: %dx%d", width, height);
1609     return BAD_VALUE;
1610 }
1611 
1612 /*===========================================================================
1613  * FUNCTION   : updateViewAngles
1614  *
1615  * DESCRIPTION: Update the Horizontal & Vertical based on the Aspect ratio of Preview and
1616  *                        Picture aspect ratio
1617  *
1618  * PARAMETERS : none
1619  *
1620  * RETURN     : none
1621  *==========================================================================*/
updateViewAngles()1622 void QCameraParameters::updateViewAngles()
1623 {
1624     double stillAspectRatio, maxPictureAspectRatio;
1625     int stillWidth, stillHeight, maxWidth, maxHeight;
1626     // The crop factors from the full sensor array to the still picture crop region
1627     double horizCropFactor = 1.f,vertCropFactor = 1.f;
1628     float horizViewAngle, vertViewAngle, maxHfov, maxVfov;
1629 
1630     // Get current Picture & max Snapshot sizes
1631     getPictureSize(&stillWidth, &stillHeight);
1632     maxWidth  = m_pCapability->picture_sizes_tbl[0].width;
1633     maxHeight = m_pCapability->picture_sizes_tbl[0].height;
1634 
1635     // Get default maximum FOV from corresponding sensor driver
1636     maxHfov = m_pCapability->hor_view_angle;
1637     maxVfov = m_pCapability->ver_view_angle;
1638 
1639     stillAspectRatio = (double)stillWidth/stillHeight;
1640     maxPictureAspectRatio = (double)maxWidth/maxHeight;
1641     LOGD("Stillwidth: %d, height: %d", stillWidth, stillHeight);
1642     LOGD("Max width: %d, height: %d", maxWidth, maxHeight);
1643     LOGD("still aspect: %f, Max Pic Aspect: %f",
1644             stillAspectRatio, maxPictureAspectRatio);
1645 
1646     // crop as per the Maximum Snapshot aspect ratio
1647     if (stillAspectRatio < maxPictureAspectRatio)
1648         horizCropFactor = stillAspectRatio/maxPictureAspectRatio;
1649     else
1650         vertCropFactor = maxPictureAspectRatio/stillAspectRatio;
1651 
1652     LOGD("horizCropFactor %f, vertCropFactor %f",
1653              horizCropFactor, vertCropFactor);
1654 
1655     // Now derive the final FOV's based on field of view formula is i.e,
1656     // angle of view = 2 * arctangent ( d / 2f )
1657     // where d is the physical sensor dimension of interest, and f is
1658     // the focal length. This only applies to rectilinear sensors, for focusing
1659     // at distances >> f, etc.
1660     // Here d/2f is nothing but the Maximum Horizontal or Veritical FOV
1661     horizViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxHfov/2)*(PI/180)));
1662     vertViewAngle = (180/PI)*2*atan(horizCropFactor*tan((maxVfov/2)*(PI/180)));
1663 
1664     setFloat(QCameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, horizViewAngle);
1665     setFloat(QCameraParameters::KEY_VERTICAL_VIEW_ANGLE, vertViewAngle);
1666     LOGH("Final horizViewAngle %f, vertViewAngle %f",
1667             horizViewAngle, vertViewAngle);
1668 }
1669 
1670 /*===========================================================================
1671  * FUNCTION   : setVideoSize
1672  *
1673  * DESCRIPTION: set video size from user setting
1674  *
1675  * PARAMETERS :
1676  *   @params  : user setting parameters
1677  *
1678  * RETURN     : int32_t type of status
1679  *              NO_ERROR  -- success
1680  *              none-zero failure code
1681  *==========================================================================*/
setVideoSize(const QCameraParameters & params)1682 int32_t QCameraParameters::setVideoSize(const QCameraParameters& params)
1683 {
1684     const char *str= NULL;
1685     int width, height;
1686     str = params.get(KEY_VIDEO_SIZE);
1687     int old_width, old_height;
1688     CameraParameters::getVideoSize(&old_width, &old_height);
1689     if(!str) {
1690         //If application didn't set this parameter string, use the values from
1691         //getPreviewSize() as video dimensions.
1692         params.getPreviewSize(&width, &height);
1693         LOGW("No Record Size requested, use the preview dimensions");
1694     } else {
1695         params.getVideoSize(&width, &height);
1696     }
1697 
1698     // Validate the video size
1699     for (size_t i = 0; i < m_pCapability->video_sizes_tbl_cnt; ++i) {
1700         if (width ==  m_pCapability->video_sizes_tbl[i].width
1701                 && height ==  m_pCapability->video_sizes_tbl[i].height) {
1702             // check if need to restart preview in case of video size change
1703             if (m_bRecordingHint &&
1704                (width != old_width || height != old_height)) {
1705                 m_bNeedRestart = true;
1706             }
1707 
1708             // set the new value
1709             LOGH("Requested video size %d x %d", width, height);
1710             CameraParameters::setVideoSize(width, height);
1711             return NO_ERROR;
1712         }
1713     }
1714     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
1715         // Set the default preview size for secondary camera
1716         width = m_pCapability->video_sizes_tbl[0].width;
1717         height = m_pCapability->video_sizes_tbl[0].height;
1718         // check if need to restart preview in case of preview size change
1719         if (width != old_width || height != old_height) {
1720             m_bNeedRestart = true;
1721         }
1722 
1723         CameraParameters::setVideoSize(width, height);
1724         LOGH("Secondary Camera: video size %d x %d",
1725                  width, height);
1726         return NO_ERROR;
1727     }
1728 
1729     LOGE("Error !! Invalid video size requested: %dx%d", width, height);
1730     return BAD_VALUE;
1731 }
1732 
1733 /*===========================================================================
1734  * FUNCTION   : getLiveSnapshotSize
1735  *
1736  * DESCRIPTION: get live snapshot size
1737  *
1738  * PARAMETERS : dim - Update dim with the liveshot size
1739  *
1740  *==========================================================================*/
getLiveSnapshotSize(cam_dimension_t & dim)1741 void QCameraParameters::getLiveSnapshotSize(cam_dimension_t &dim)
1742 {
1743     if(is4k2kVideoResolution()) {
1744         // We support maximum 8M liveshot @4K2K video resolution
1745         cam_dimension_t resolution = {0, 0};
1746         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1747         if((m_LiveSnapshotSize.width > resolution.width) ||
1748                 (m_LiveSnapshotSize.height > resolution.height)) {
1749             m_LiveSnapshotSize.width = resolution.width;
1750             m_LiveSnapshotSize.height = resolution.height;
1751         }
1752     }
1753     dim = m_LiveSnapshotSize;
1754     LOGH("w x h: %d x %d", dim.width, dim.height);
1755 }
1756 
1757 /*===========================================================================
1758  * FUNCTION   : setLiveSnapshotSize
1759  *
1760  * DESCRIPTION: set live snapshot size
1761  *
1762  * PARAMETERS :
1763  *   @params  : user setting parameters
1764  *
1765  * RETURN     : int32_t type of status
1766  *              NO_ERROR  -- success
1767  *              none-zero failure code
1768  *==========================================================================*/
setLiveSnapshotSize(const QCameraParameters & params)1769 int32_t QCameraParameters::setLiveSnapshotSize(const QCameraParameters& params)
1770 {
1771     char value[PROPERTY_VALUE_MAX];
1772     property_get("persist.camera.opt.livepic", value, "1");
1773     bool useOptimal = atoi(value) > 0 ? true : false;
1774     bool vHdrOn;
1775     int32_t liveSnapWidth = 0, liveSnapHeight = 0;
1776     // use picture size from user setting
1777     params.getPictureSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1778 
1779     size_t livesnapshot_sizes_tbl_cnt =
1780             m_pCapability->livesnapshot_sizes_tbl_cnt;
1781     cam_dimension_t *livesnapshot_sizes_tbl =
1782             &m_pCapability->livesnapshot_sizes_tbl[0];
1783 
1784     if(is4k2kVideoResolution()) {
1785         // We support maximum 8M liveshot @4K2K video resolution
1786         cam_dimension_t resolution = {0, 0};
1787         CameraParameters::getVideoSize(&resolution.width, &resolution.height);
1788         if((m_LiveSnapshotSize.width > resolution.width) ||
1789                 (m_LiveSnapshotSize.height > resolution.height)) {
1790             m_LiveSnapshotSize.width = resolution.width;
1791             m_LiveSnapshotSize.height = resolution.height;
1792         }
1793     }
1794 
1795     // check if HFR is enabled
1796     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
1797     cam_hfr_mode_t hfrMode = CAM_HFR_MODE_OFF;
1798     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
1799 
1800     const char *vhdrStr = params.get(KEY_QC_VIDEO_HDR);
1801     vHdrOn = (vhdrStr != NULL && (0 == strcmp(vhdrStr,"on"))) ? true : false;
1802     if (vHdrOn) {
1803         livesnapshot_sizes_tbl_cnt = m_pCapability->vhdr_livesnapshot_sizes_tbl_cnt;
1804         livesnapshot_sizes_tbl = &m_pCapability->vhdr_livesnapshot_sizes_tbl[0];
1805     }
1806     if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
1807         int32_t hsr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
1808         if ((hsr != NAME_NOT_FOUND) && (hsr > CAM_HFR_MODE_OFF)) {
1809             // if HSR is enabled, change live snapshot size
1810             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1811                 if (m_pCapability->hfr_tbl[i].mode == hsr) {
1812                     livesnapshot_sizes_tbl_cnt =
1813                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1814                     livesnapshot_sizes_tbl =
1815                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1816                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1817                     break;
1818                 }
1819             }
1820         }
1821     } else if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
1822         int32_t hfr = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
1823         if ((hfr != NAME_NOT_FOUND) && (hfr > CAM_HFR_MODE_OFF)) {
1824             // if HFR is enabled, change live snapshot size
1825             for (size_t i = 0; i < m_pCapability->hfr_tbl_cnt; i++) {
1826                 if (m_pCapability->hfr_tbl[i].mode == hfr) {
1827                     livesnapshot_sizes_tbl_cnt =
1828                             m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl_cnt;
1829                     livesnapshot_sizes_tbl =
1830                             &m_pCapability->hfr_tbl[i].livesnapshot_sizes_tbl[0];
1831                     hfrMode = m_pCapability->hfr_tbl[i].mode;
1832                     break;
1833                 }
1834             }
1835         }
1836     }
1837 
1838     if (useOptimal || hfrMode != CAM_HFR_MODE_OFF || vHdrOn) {
1839         bool found = false;
1840 
1841         // first check if picture size is within the list of supported sizes
1842         for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1843             if (m_LiveSnapshotSize.width == livesnapshot_sizes_tbl[i].width &&
1844                 m_LiveSnapshotSize.height == livesnapshot_sizes_tbl[i].height) {
1845                 found = true;
1846                 break;
1847             }
1848         }
1849 
1850         if (!found) {
1851             // use optimal live snapshot size from supported list,
1852             // that has same preview aspect ratio
1853             int width = 0, height = 0;
1854             params.getPreviewSize(&width, &height);
1855 
1856             double previewAspectRatio = (double)width / height;
1857             for (size_t i = 0; i < livesnapshot_sizes_tbl_cnt; ++i) {
1858                 double ratio = (double)livesnapshot_sizes_tbl[i].width /
1859                                 livesnapshot_sizes_tbl[i].height;
1860                 if (fabs(previewAspectRatio - ratio) <= ASPECT_TOLERANCE) {
1861                     m_LiveSnapshotSize = livesnapshot_sizes_tbl[i];
1862                     found = true;
1863                     break;
1864                 }
1865             }
1866 
1867             if (!found && ((hfrMode != CAM_HFR_MODE_OFF) || vHdrOn)) {
1868                 // Cannot find matching aspect ration from supported live snapshot list
1869                 // choose the max dim from preview and video size
1870                 LOGD("Cannot find matching aspect ratio, choose max of preview or video size");
1871                 params.getVideoSize(&m_LiveSnapshotSize.width, &m_LiveSnapshotSize.height);
1872                 if (m_LiveSnapshotSize.width < width && m_LiveSnapshotSize.height < height) {
1873                     m_LiveSnapshotSize.width = width;
1874                     m_LiveSnapshotSize.height = height;
1875                 }
1876             }
1877         }
1878     }
1879     //To read liveshot resolution from setprop instead of matching aspect ratio.
1880     //The setprop resolution format should be WxH.
1881     //e.g: adb shell setprop persist.camera.liveshot.size 1280x720
1882     memset(value, 0, PROPERTY_VALUE_MAX);
1883     property_get("persist.camera.liveshot.size", value, "");
1884     if (strlen(value) > 0) {
1885         char *saveptr = NULL;
1886         char *token = strtok_r(value, "x", &saveptr);
1887         if (token != NULL) {
1888             liveSnapWidth = atoi(token);
1889         }
1890         token = strtok_r(NULL, "x", &saveptr);
1891         if (token != NULL) {
1892             liveSnapHeight = atoi(token);
1893         }
1894         if ((liveSnapWidth!=0) && (liveSnapHeight!=0)) {
1895             for (size_t i = 0; i < m_pCapability->picture_sizes_tbl_cnt; ++i) {
1896                 if (liveSnapWidth ==  m_pCapability->picture_sizes_tbl[i].width
1897                         && liveSnapHeight ==  m_pCapability->picture_sizes_tbl[i].height) {
1898                    m_LiveSnapshotSize.width = liveSnapWidth;
1899                    m_LiveSnapshotSize.height = liveSnapHeight;
1900                    break;
1901                 }
1902             }
1903         }
1904     }
1905     LOGH("live snapshot size %d x %d",
1906           m_LiveSnapshotSize.width, m_LiveSnapshotSize.height);
1907 
1908     return NO_ERROR;
1909 }
1910 
1911 
1912 /*===========================================================================
1913  * FUNCTION   : setRawSize
1914  *
1915  * DESCRIPTION: set live snapshot size
1916  *
1917  * PARAMETERS :
1918  *   @params  : user setting parameters
1919  *
1920  * RETURN     : int32_t type of status
1921  *              NO_ERROR  -- success
1922  *              none-zero failure code
1923  *==========================================================================*/
setRawSize(cam_dimension_t & dim)1924 int32_t QCameraParameters::setRawSize(cam_dimension_t &dim)
1925 {
1926     m_rawSize = dim;
1927     return NO_ERROR;
1928 }
1929 /*===========================================================================
1930  * FUNCTION   : setPreviewFormat
1931  *
1932  * DESCRIPTION: set preview format from user setting
1933  *
1934  * PARAMETERS :
1935  *   @params  : user setting parameters
1936  *
1937  * RETURN     : int32_t type of status
1938  *              NO_ERROR  -- success
1939  *              none-zero failure code
1940  *==========================================================================*/
setPreviewFormat(const QCameraParameters & params)1941 int32_t QCameraParameters::setPreviewFormat(const QCameraParameters& params)
1942 {
1943     const char *str = params.getPreviewFormat();
1944     int32_t previewFormat = lookupAttr(PREVIEW_FORMATS_MAP,
1945             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP), str);
1946     if (previewFormat != NAME_NOT_FOUND) {
1947         if (isUBWCEnabled()) {
1948             char prop[PROPERTY_VALUE_MAX];
1949             int pFormat;
1950             memset(prop, 0, sizeof(prop));
1951             property_get("persist.camera.preview.ubwc", prop, "1");
1952 
1953             pFormat = atoi(prop);
1954             if (pFormat == 1) {
1955                 mPreviewFormat = CAM_FORMAT_YUV_420_NV12_UBWC;
1956                 mAppPreviewFormat = (cam_format_t)previewFormat;
1957             } else {
1958                 mPreviewFormat = (cam_format_t)previewFormat;
1959                 mAppPreviewFormat = (cam_format_t)previewFormat;
1960             }
1961         } else {
1962             mPreviewFormat = (cam_format_t)previewFormat;
1963             mAppPreviewFormat = (cam_format_t)previewFormat;
1964         }
1965         CameraParameters::setPreviewFormat(str);
1966         LOGH("format %d\n", mPreviewFormat);
1967         return NO_ERROR;
1968     }
1969     LOGE("Invalid preview format value: %s", (str == NULL) ? "NULL" : str);
1970     return BAD_VALUE;
1971 }
1972 
1973 /*===========================================================================
1974  * FUNCTION   : setPictureFormat
1975  *
1976  * DESCRIPTION: set picture format from user setting
1977  *
1978  * PARAMETERS :
1979  *   @params  : user setting parameters
1980  *
1981  * RETURN     : int32_t type of status
1982  *              NO_ERROR  -- success
1983  *              none-zero failure code
1984  *==========================================================================*/
setPictureFormat(const QCameraParameters & params)1985 int32_t QCameraParameters::setPictureFormat(const QCameraParameters& params)
1986 {
1987     const char *str = params.getPictureFormat();
1988     int32_t pictureFormat = lookupAttr(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), str);
1989     if (pictureFormat != NAME_NOT_FOUND) {
1990         mPictureFormat = pictureFormat;
1991 
1992         CameraParameters::setPictureFormat(str);
1993         LOGH("format %d\n", mPictureFormat);
1994         return NO_ERROR;
1995     }
1996     LOGE("Invalid picture format value: %s", (str == NULL) ? "NULL" : str);
1997     return BAD_VALUE;
1998 }
1999 
2000 /*===========================================================================
2001  * FUNCTION   : setJpegThumbnailSize
2002  *
2003  * DESCRIPTION: set jpeg thumbnail size from user setting
2004  *
2005  * PARAMETERS :
2006  *   @params  : user setting parameters
2007  *
2008  * RETURN     : int32_t type of status
2009  *              NO_ERROR  -- success
2010  *              none-zero failure code
2011  *==========================================================================*/
setJpegThumbnailSize(const QCameraParameters & params)2012 int32_t QCameraParameters::setJpegThumbnailSize(const QCameraParameters& params)
2013 {
2014     int width = params.getInt(KEY_JPEG_THUMBNAIL_WIDTH);
2015     int height = params.getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
2016 
2017     LOGD("requested jpeg thumbnail size %d x %d", width, height);
2018     int sizes_cnt = sizeof(THUMBNAIL_SIZES_MAP) / sizeof(cam_dimension_t);
2019     // Validate thumbnail size
2020     for (int i = 0; i < sizes_cnt; i++) {
2021         if (width == THUMBNAIL_SIZES_MAP[i].width &&
2022                 height == THUMBNAIL_SIZES_MAP[i].height) {
2023            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
2024            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
2025            return NO_ERROR;
2026         }
2027     }
2028     LOGE("error: setting jpeg thumbnail size (%d, %d)", width, height);
2029     return BAD_VALUE;
2030 }
2031 
2032 /*===========================================================================
2033 
2034  * FUNCTION   : setBurstLEDOnPeriod
2035  *
2036  * DESCRIPTION: set burst LED on period
2037  *
2038  * PARAMETERS :
2039  *   @params  : user setting parameters
2040  *
2041  * RETURN     : int32_t type of status
2042  *              NO_ERROR  -- success
2043  *              none-zero failure code
2044  *==========================================================================*/
setBurstLEDOnPeriod(const QCameraParameters & params)2045 int32_t QCameraParameters::setBurstLEDOnPeriod(const QCameraParameters& params)
2046 {
2047     int nBurstLEDOnPeriod = params.getInt(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD);
2048     //Check if the LED ON period is within limits
2049     if ((nBurstLEDOnPeriod <= 0) || (nBurstLEDOnPeriod > 800)) {
2050         // if burst led on period is not set in parameters,
2051         // read from sys prop
2052         char prop[PROPERTY_VALUE_MAX];
2053         memset(prop, 0, sizeof(prop));
2054         property_get("persist.camera.led.on.period", prop, "0");
2055         nBurstLEDOnPeriod = atoi(prop);
2056         if (nBurstLEDOnPeriod <= 0) {
2057             nBurstLEDOnPeriod = 300;
2058         }
2059     }
2060 
2061     set(KEY_QC_SNAPSHOT_BURST_LED_ON_PERIOD, nBurstLEDOnPeriod);
2062     m_nBurstLEDOnPeriod = nBurstLEDOnPeriod;
2063     LOGH("Burst LED on period  %u", m_nBurstLEDOnPeriod);
2064     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BURST_LED_ON_PERIOD,
2065             (uint32_t)nBurstLEDOnPeriod)) {
2066         return BAD_VALUE;
2067     }
2068 
2069     return NO_ERROR;
2070 }
2071 
2072 
2073 
2074 /*===========================================================================
2075  * FUNCTION   : setRetroActiveBurstNum
2076  *
2077  * DESCRIPTION: set retro active burst num
2078  *
2079  * PARAMETERS :
2080  *   @params  : user setting parameters
2081  *
2082  * RETURN     : int32_t type of status
2083  *              NO_ERROR  -- success
2084  *              none-zero failure code
2085  *==========================================================================*/
setRetroActiveBurstNum(const QCameraParameters & params)2086 int32_t QCameraParameters::setRetroActiveBurstNum(
2087         const QCameraParameters& params)
2088 {
2089     int32_t nBurstNum = params.getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
2090     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
2091     if (nBurstNum <= 0) {
2092         // if burst number is not set in parameters,
2093         // read from sys prop
2094         char prop[PROPERTY_VALUE_MAX];
2095         memset(prop, 0, sizeof(prop));
2096         property_get("persist.camera.retro.number", prop, "0");
2097         nBurstNum = atoi(prop);
2098         if (nBurstNum < 0) {
2099             nBurstNum = 0;
2100         }
2101     }
2102 
2103     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, nBurstNum);
2104 
2105     m_nRetroBurstNum = nBurstNum;
2106     LOGH("m_nRetroBurstNum = %d", m_nRetroBurstNum);
2107     return NO_ERROR;
2108 }
2109 
2110 /*===========================================================================
2111  * FUNCTION   : setJpegQuality
2112  *
2113  * DESCRIPTION: set jpeg encpding quality from user setting
2114  *
2115  * PARAMETERS :
2116  *   @params  : user setting parameters
2117  *
2118  * RETURN     : int32_t type of status
2119  *              NO_ERROR  -- success
2120  *              none-zero failure code
2121  *==========================================================================*/
setJpegQuality(const QCameraParameters & params)2122 int32_t QCameraParameters::setJpegQuality(const QCameraParameters& params)
2123 {
2124     int32_t rc = NO_ERROR;
2125     int quality = params.getInt(KEY_JPEG_QUALITY);
2126     if (quality >= 0 && quality <= 100) {
2127         set(KEY_JPEG_QUALITY, quality);
2128     } else {
2129         LOGE("Invalid jpeg quality=%d", quality);
2130         rc = BAD_VALUE;
2131     }
2132 
2133     quality = params.getInt(KEY_JPEG_THUMBNAIL_QUALITY);
2134     if (quality >= 0 && quality <= 100) {
2135         set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
2136     } else {
2137         LOGE("Invalid jpeg thumbnail quality=%d", quality);
2138         rc = BAD_VALUE;
2139     }
2140     return rc;
2141 }
2142 
2143 /*===========================================================================
2144  * FUNCTION   : setOrientaion
2145  *
2146  * DESCRIPTION: set orientaion from user setting
2147  *
2148  * PARAMETERS :
2149  *   @params  : user setting parameters
2150  *
2151  * RETURN     : int32_t type of status
2152  *              NO_ERROR  -- success
2153  *              none-zero failure code
2154  *==========================================================================*/
setOrientation(const QCameraParameters & params)2155 int32_t QCameraParameters::setOrientation(const QCameraParameters& params)
2156 {
2157     const char *str = params.get(KEY_QC_ORIENTATION);
2158 
2159     if (str != NULL) {
2160         if (strcmp(str, portrait) == 0 || strcmp(str, landscape) == 0) {
2161             // Camera service needs this to decide if the preview frames and raw
2162             // pictures should be rotated.
2163             set(KEY_QC_ORIENTATION, str);
2164         } else {
2165             LOGE("Invalid orientation value: %s", str);
2166             return BAD_VALUE;
2167         }
2168     }
2169     return NO_ERROR;
2170 }
2171 
2172 /*===========================================================================
2173  * FUNCTION   : setAutoExposure
2174  *
2175  * DESCRIPTION: set auto exposure value from user setting
2176  *
2177  * PARAMETERS :
2178  *   @params  : user setting parameters
2179  *
2180  * RETURN     : int32_t type of status
2181  *              NO_ERROR  -- success
2182  *              none-zero failure code
2183  *==========================================================================*/
setAutoExposure(const QCameraParameters & params)2184 int32_t QCameraParameters::setAutoExposure(const QCameraParameters& params)
2185 {
2186     const char *str = params.get(KEY_QC_AUTO_EXPOSURE);
2187     const char *prev_str = get(KEY_QC_AUTO_EXPOSURE);
2188     if (str != NULL) {
2189         if (prev_str == NULL ||
2190             strcmp(str, prev_str) != 0) {
2191             return setAutoExposure(str);
2192         }
2193     }
2194     return NO_ERROR;
2195 }
2196 
2197 /*===========================================================================
2198  * FUNCTION   : setPreviewFpsRange
2199  *
2200  * DESCRIPTION: set preview FPS range from user setting
2201  *
2202  * PARAMETERS :
2203  *   @params  : user setting parameters
2204  *
2205  * RETURN     : int32_t type of status
2206  *              NO_ERROR  -- success
2207  *              none-zero failure code
2208  *==========================================================================*/
setPreviewFpsRange(const QCameraParameters & params)2209 int32_t QCameraParameters::setPreviewFpsRange(const QCameraParameters& params)
2210 {
2211     int minFps,maxFps;
2212     int prevMinFps, prevMaxFps, vidMinFps, vidMaxFps;
2213     int rc = NO_ERROR;
2214     bool found = false, updateNeeded = false;
2215 
2216     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
2217     params.getPreviewFpsRange(&minFps, &maxFps);
2218 
2219     LOGH("FpsRange Values:(%d, %d)", prevMinFps, prevMaxFps);
2220     LOGH("Requested FpsRange Values:(%d, %d)", minFps, maxFps);
2221 
2222     //first check if we need to change fps because of HFR mode change
2223     updateNeeded = UpdateHFRFrameRate(params);
2224     if (updateNeeded) {
2225         m_bNeedRestart = true;
2226         rc = setHighFrameRate(mHfrMode);
2227         if (rc != NO_ERROR) goto end;
2228     }
2229     LOGH("UpdateHFRFrameRate %d", updateNeeded);
2230 
2231     vidMinFps = (int)m_hfrFpsRange.video_min_fps;
2232     vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
2233 
2234     if(minFps == prevMinFps && maxFps == prevMaxFps) {
2235         if ( m_bFixedFrameRateSet ) {
2236             minFps = params.getPreviewFrameRate() * 1000;
2237             maxFps = params.getPreviewFrameRate() * 1000;
2238             m_bFixedFrameRateSet = false;
2239         } else if (!updateNeeded) {
2240             LOGH("No change in FpsRange");
2241             rc = NO_ERROR;
2242             goto end;
2243         }
2244     }
2245     for(size_t i = 0; i < m_pCapability->fps_ranges_tbl_cnt; i++) {
2246         // if the value is in the supported list
2247         if (minFps >= m_pCapability->fps_ranges_tbl[i].min_fps * 1000 &&
2248                 maxFps <= m_pCapability->fps_ranges_tbl[i].max_fps * 1000) {
2249             found = true;
2250             LOGH("FPS i=%d : minFps = %d, maxFps = %d"
2251                     " vidMinFps = %d, vidMaxFps = %d",
2252                      i, minFps, maxFps,
2253                     (int)m_hfrFpsRange.video_min_fps,
2254                     (int)m_hfrFpsRange.video_max_fps);
2255             if ((0.0f >= m_hfrFpsRange.video_min_fps) ||
2256                     (0.0f >= m_hfrFpsRange.video_max_fps)) {
2257                 vidMinFps = minFps;
2258                 vidMaxFps = maxFps;
2259             }
2260             else {
2261                 vidMinFps = (int)m_hfrFpsRange.video_min_fps;
2262                 vidMaxFps = (int)m_hfrFpsRange.video_max_fps;
2263             }
2264 
2265             setPreviewFpsRange(minFps, maxFps, vidMinFps, vidMaxFps);
2266             break;
2267         }
2268     }
2269     if(found == false){
2270         LOGE("error: FPS range value not supported");
2271         rc = BAD_VALUE;
2272     }
2273 end:
2274     return rc;
2275 }
2276 
2277 /*===========================================================================
2278  * FUNCTION   : UpdateHFRFrameRate
2279  *
2280  * DESCRIPTION: set preview FPS range based on HFR setting
2281  *
2282  * PARAMETERS :
2283  *   @params  : user setting parameters
2284  *
2285  * RETURN     : bool true/false
2286  *                  true -if HAL needs to overwrite FPS range set by app, false otherwise.
2287  *==========================================================================*/
2288 
UpdateHFRFrameRate(const QCameraParameters & params)2289 bool QCameraParameters::UpdateHFRFrameRate(const QCameraParameters& params)
2290 {
2291     bool updateNeeded = false;
2292     int min_fps, max_fps;
2293     int32_t hfrMode = CAM_HFR_MODE_OFF;
2294     int32_t newHfrMode = CAM_HFR_MODE_OFF;
2295 
2296     int parm_minfps,parm_maxfps;
2297     int prevMinFps, prevMaxFps;
2298     CameraParameters::getPreviewFpsRange(&prevMinFps, &prevMaxFps);
2299     params.getPreviewFpsRange(&parm_minfps, &parm_maxfps);
2300     LOGH("CameraParameters - : minFps = %d, maxFps = %d ",
2301                  prevMinFps, prevMaxFps);
2302     LOGH("Requested params - : minFps = %d, maxFps = %d ",
2303                  parm_minfps, parm_maxfps);
2304 
2305     const char *hfrStr = params.get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2306     const char *hsrStr = params.get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2307 
2308     const char *prev_hfrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
2309     const char *prev_hsrStr = CameraParameters::get(KEY_QC_VIDEO_HIGH_SPEED_RECORDING);
2310 
2311     if ((hfrStr != NULL) && (prev_hfrStr != NULL) && strcmp(hfrStr, prev_hfrStr)) {
2312         updateParamEntry(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfrStr);
2313     }
2314 
2315     if ((hsrStr != NULL) && (prev_hsrStr != NULL) && strcmp(hsrStr, prev_hsrStr)) {
2316         updateParamEntry(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, hsrStr);
2317 
2318     }
2319 
2320     // check if HFR is enabled
2321     if ((hfrStr != NULL) && strcmp(hfrStr, "off")) {
2322         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hfrStr);
2323         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2324     }
2325     // check if HSR is enabled
2326     else if ((hsrStr != NULL) && strcmp(hsrStr, "off")) {
2327         hfrMode = lookupAttr(HFR_MODES_MAP, PARAM_MAP_SIZE(HFR_MODES_MAP), hsrStr);
2328         if (NAME_NOT_FOUND != hfrMode) newHfrMode = hfrMode;
2329     }
2330     LOGH("prevHfrMode - %d, currentHfrMode = %d ",
2331                  mHfrMode, newHfrMode);
2332 
2333     if (mHfrMode != newHfrMode) {
2334         updateNeeded = true;
2335         mHfrMode = newHfrMode;
2336         switch (mHfrMode) {
2337             case CAM_HFR_MODE_60FPS:
2338                 min_fps = 60000;
2339                 max_fps = 60000;
2340                 break;
2341             case CAM_HFR_MODE_90FPS:
2342                 min_fps = 90000;
2343                 max_fps = 90000;
2344                 break;
2345             case CAM_HFR_MODE_120FPS:
2346                 min_fps = 120000;
2347                 max_fps = 120000;
2348                 break;
2349             case CAM_HFR_MODE_150FPS:
2350                 min_fps = 150000;
2351                 max_fps = 150000;
2352                 break;
2353             case CAM_HFR_MODE_180FPS:
2354                 min_fps = 180000;
2355                 max_fps = 180000;
2356                 break;
2357             case CAM_HFR_MODE_210FPS:
2358                 min_fps = 210000;
2359                 max_fps = 210000;
2360                 break;
2361             case CAM_HFR_MODE_240FPS:
2362                 min_fps = 240000;
2363                 max_fps = 240000;
2364                 break;
2365             case CAM_HFR_MODE_480FPS:
2366                 min_fps = 480000;
2367                 max_fps = 480000;
2368                 break;
2369             case CAM_HFR_MODE_OFF:
2370             default:
2371                 // Set Video Fps to zero
2372                 min_fps = 0;
2373                 max_fps = 0;
2374                 break;
2375         }
2376         m_hfrFpsRange.video_min_fps = (float)min_fps;
2377         m_hfrFpsRange.video_max_fps = (float)max_fps;
2378 
2379         LOGH("HFR mode (%d) Set video FPS : minFps = %d, maxFps = %d ",
2380                  mHfrMode, min_fps, max_fps);
2381     }
2382 
2383     // Remember if HFR mode is ON
2384     if ((mHfrMode > CAM_HFR_MODE_OFF) && (mHfrMode < CAM_HFR_MODE_MAX)) {
2385         LOGH("HFR mode is ON");
2386         m_bHfrMode = true;
2387     } else {
2388         m_hfrFpsRange.video_min_fps = 0;
2389         m_hfrFpsRange.video_max_fps = 0;
2390         m_bHfrMode = false;
2391         LOGH("HFR mode is OFF");
2392     }
2393     m_hfrFpsRange.min_fps = (float)parm_minfps;
2394     m_hfrFpsRange.max_fps = (float)parm_maxfps;
2395 
2396     if (m_bHfrMode && (mHfrMode > CAM_HFR_MODE_120FPS)
2397             && (parm_maxfps != 0)) {
2398         //Configure buffer batch count to use batch mode for higher fps
2399         setBufBatchCount((int8_t)(m_hfrFpsRange.video_max_fps / parm_maxfps));
2400     } else {
2401         //Reset batch count and update KEY for encoder
2402         setBufBatchCount(0);
2403     }
2404     return updateNeeded;
2405 }
2406 
2407 /*===========================================================================
2408  * FUNCTION   : setPreviewFrameRate
2409  *
2410  * DESCRIPTION: set preview frame rate from user setting
2411  *
2412  * PARAMETERS :
2413  *   @params  : user setting parameters
2414  *
2415  * RETURN     : int32_t type of status
2416  *              NO_ERROR  -- success
2417  *              none-zero failure code
2418  *==========================================================================*/
setPreviewFrameRate(const QCameraParameters & params)2419 int32_t QCameraParameters::setPreviewFrameRate(const QCameraParameters& params)
2420 {
2421     const char *str = params.get(KEY_PREVIEW_FRAME_RATE);
2422     const char *prev_str = get(KEY_PREVIEW_FRAME_RATE);
2423 
2424     if ( str ) {
2425         if ( prev_str &&
2426              strcmp(str, prev_str)) {
2427             LOGD("Requested Fixed Frame Rate %s", str);
2428             updateParamEntry(KEY_PREVIEW_FRAME_RATE, str);
2429             m_bFixedFrameRateSet = true;
2430         }
2431     }
2432     return NO_ERROR;
2433 }
2434 
2435 /*===========================================================================
2436  * FUNCTION   : setEffect
2437  *
2438  * DESCRIPTION: set effect value from user setting
2439  *
2440  * PARAMETERS :
2441  *   @params  : user setting parameters
2442  *
2443  * RETURN     : int32_t type of status
2444  *              NO_ERROR  -- success
2445  *              none-zero failure code
2446  *==========================================================================*/
setEffect(const QCameraParameters & params)2447 int32_t QCameraParameters::setEffect(const QCameraParameters& params)
2448 {
2449     const char *str = params.get(KEY_EFFECT);
2450     const char *prev_str = get(KEY_EFFECT);
2451 
2452     char prop[PROPERTY_VALUE_MAX];
2453     memset(prop, 0, sizeof(prop));
2454     property_get("persist.camera.effect", prop, "none");
2455 
2456     if (strcmp(prop, "none")) {
2457         if ((prev_str == NULL) ||
2458                 (strcmp(prop, prev_str) != 0) ||
2459                 (m_bUpdateEffects == true)) {
2460             m_bUpdateEffects = false;
2461             return setEffect(prop);
2462         }
2463     } else if (str != NULL) {
2464         if ((prev_str == NULL) ||
2465                 (strcmp(str, prev_str) != 0) ||
2466                 (m_bUpdateEffects == true)) {
2467             m_bUpdateEffects = false;
2468             return setEffect(str);
2469         }
2470     }
2471     return NO_ERROR;
2472 }
2473 
2474 /*===========================================================================
2475  * FUNCTION   : setFocusMode
2476  *
2477  * DESCRIPTION: set focus mode from user setting
2478  *
2479  * PARAMETERS :
2480  *   @params  : user setting parameters
2481  *
2482  * RETURN     : int32_t type of status
2483  *              NO_ERROR  -- success
2484  *              none-zero failure code
2485  *==========================================================================*/
setFocusMode(const QCameraParameters & params)2486 int32_t QCameraParameters::setFocusMode(const QCameraParameters& params)
2487 {
2488     const char *str = params.get(KEY_FOCUS_MODE);
2489     const char *prev_str = get(KEY_FOCUS_MODE);
2490     if (str != NULL) {
2491         if (prev_str == NULL ||
2492             strcmp(str, prev_str) != 0) {
2493             return setFocusMode(str);
2494         }
2495     }
2496     return NO_ERROR;
2497 }
2498 
2499 /*===========================================================================
2500  * FUNCTION   : setFocusPosition
2501  *
2502  * DESCRIPTION: set focus position from user setting
2503  *
2504  * PARAMETERS :
2505  *   @params  : user setting parameters
2506  *
2507  * RETURN     : int32_t type of status
2508  *              NO_ERROR  -- success
2509  *              none-zero failure code
2510  *==========================================================================*/
setFocusPosition(const QCameraParameters & params)2511 int32_t  QCameraParameters::setFocusPosition(const QCameraParameters& params)
2512 {
2513     const char *focus_str = params.get(KEY_FOCUS_MODE);
2514     const char *prev_focus_str = get(KEY_FOCUS_MODE);
2515 
2516     if (NULL == focus_str) {
2517         return NO_ERROR;
2518     }
2519 
2520     LOGD("current focus mode: %s", focus_str);
2521     if (strcmp(focus_str, FOCUS_MODE_MANUAL_POSITION)) {
2522         LOGH(", dont set focus pos to back-end!");
2523         return NO_ERROR;
2524     }
2525 
2526     const char *pos = params.get(KEY_QC_MANUAL_FOCUS_POSITION);
2527     const char *prev_pos = get(KEY_QC_MANUAL_FOCUS_POSITION);
2528     const char *type = params.get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2529     const char *prev_type = get(KEY_QC_MANUAL_FOCUS_POS_TYPE);
2530 
2531     if ((pos != NULL) && (type != NULL) && (focus_str != NULL)) {
2532         if (prev_pos  == NULL || (strcmp(pos, prev_pos) != 0) ||
2533             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
2534             prev_focus_str == NULL || (strcmp(focus_str, prev_focus_str) != 0)) {
2535             return setFocusPosition(type, pos);
2536         }
2537     }
2538 
2539     return NO_ERROR;
2540 }
2541 
2542 /*===========================================================================
2543  * FUNCTION   : setBrightness
2544  *
2545  * DESCRIPTION: set brightness control value from user setting
2546  *
2547  * PARAMETERS :
2548  *   @params  : user setting parameters
2549  *
2550  * RETURN     : int32_t type of status
2551  *              NO_ERROR  -- success
2552  *              none-zero failure code
2553  *==========================================================================*/
setBrightness(const QCameraParameters & params)2554 int32_t QCameraParameters::setBrightness(const QCameraParameters& params)
2555 {
2556     int currentBrightness = getInt(KEY_QC_BRIGHTNESS);
2557     int brightness = params.getInt(KEY_QC_BRIGHTNESS);
2558 
2559     if(params.get(KEY_QC_BRIGHTNESS) == NULL) {
2560        LOGH("Brigtness not set by App ");
2561        return NO_ERROR;
2562     }
2563     if (currentBrightness !=  brightness) {
2564         if (brightness >= m_pCapability->brightness_ctrl.min_value &&
2565             brightness <= m_pCapability->brightness_ctrl.max_value) {
2566             LOGD("new brightness value : %d ", brightness);
2567             return setBrightness(brightness);
2568         } else {
2569             LOGE("invalid value %d out of (%d, %d)",
2570                    brightness,
2571                   m_pCapability->brightness_ctrl.min_value,
2572                   m_pCapability->brightness_ctrl.max_value);
2573             return BAD_VALUE;
2574         }
2575     } else {
2576         LOGD("No brightness value changed.");
2577         return NO_ERROR;
2578     }
2579 }
2580 
2581 /*===========================================================================
2582  * FUNCTION   : getBrightness
2583  *
2584  * DESCRIPTION: get brightness control value from user setting
2585  *
2586  * PARAMETERS :
2587  *   @params  : user setting parameters
2588  *
2589  * RETURN     : int32_t type of status
2590  *              NO_ERROR  -- success
2591  *              none-zero failure code
2592  *==========================================================================*/
getBrightness()2593 int QCameraParameters::getBrightness()
2594 {
2595     return getInt(KEY_QC_BRIGHTNESS);
2596 }
2597 
2598 /*===========================================================================
2599  * FUNCTION   : setSharpness
2600  *
2601  * DESCRIPTION: set sharpness control value from user setting
2602  *
2603  * PARAMETERS :
2604  *   @params  : user setting parameters
2605  *
2606  * RETURN     : int32_t type of status
2607  *              NO_ERROR  -- success
2608  *              none-zero failure code
2609  *==========================================================================*/
setSharpness(const QCameraParameters & params)2610 int32_t QCameraParameters::setSharpness(const QCameraParameters& params)
2611 {
2612     int shaprness = params.getInt(KEY_QC_SHARPNESS);
2613     int prev_sharp = getInt(KEY_QC_SHARPNESS);
2614 
2615     if(params.get(KEY_QC_SHARPNESS) == NULL) {
2616        LOGH("Sharpness not set by App ");
2617        return NO_ERROR;
2618     }
2619     if (prev_sharp !=  shaprness) {
2620         if((shaprness >= m_pCapability->sharpness_ctrl.min_value) &&
2621            (shaprness <= m_pCapability->sharpness_ctrl.max_value)) {
2622             LOGD("new sharpness value : %d ", shaprness);
2623             return setSharpness(shaprness);
2624         } else {
2625             LOGE("invalid value %d out of (%d, %d)",
2626                    shaprness,
2627                   m_pCapability->sharpness_ctrl.min_value,
2628                   m_pCapability->sharpness_ctrl.max_value);
2629             return BAD_VALUE;
2630         }
2631     } else {
2632         LOGD("No value change in shaprness");
2633         return NO_ERROR;
2634     }
2635 }
2636 
2637 /*===========================================================================
2638  * FUNCTION   : setSkintoneEnahancement
2639  *
2640  * DESCRIPTION: set skin tone enhancement factor from user setting
2641  *
2642  * PARAMETERS :
2643  *   @params  : user setting parameters
2644  *
2645  * RETURN     : int32_t type of status
2646  *              NO_ERROR  -- success
2647  *              none-zero failure code
2648  *==========================================================================*/
setSkinToneEnhancement(const QCameraParameters & params)2649 int32_t QCameraParameters::setSkinToneEnhancement(const QCameraParameters& params)
2650 {
2651     int sceFactor = params.getInt(KEY_QC_SCE_FACTOR);
2652     int prev_sceFactor = getInt(KEY_QC_SCE_FACTOR);
2653 
2654     if(params.get(KEY_QC_SCE_FACTOR) == NULL) {
2655        LOGH("Skintone enhancement not set by App ");
2656        return NO_ERROR;
2657     }
2658     if (prev_sceFactor != sceFactor) {
2659         if((sceFactor >= m_pCapability->sce_ctrl.min_value) &&
2660            (sceFactor <= m_pCapability->sce_ctrl.max_value)) {
2661             LOGD("new Skintone Enhancement value : %d ", sceFactor);
2662             return setSkinToneEnhancement(sceFactor);
2663         } else {
2664             LOGE("invalid value %d out of (%d, %d)",
2665                    sceFactor,
2666                   m_pCapability->sce_ctrl.min_value,
2667                   m_pCapability->sce_ctrl.max_value);
2668             return BAD_VALUE;
2669         }
2670     } else {
2671         LOGD("No value change in skintone enhancement factor");
2672         return NO_ERROR;
2673     }
2674 }
2675 
2676 /*===========================================================================
2677  * FUNCTION   : setSaturation
2678  *
2679  * DESCRIPTION: set saturation control value from user setting
2680  *
2681  * PARAMETERS :
2682  *   @params  : user setting parameters
2683  *
2684  * RETURN     : int32_t type of status
2685  *              NO_ERROR  -- success
2686  *              none-zero failure code
2687  *==========================================================================*/
setSaturation(const QCameraParameters & params)2688 int32_t QCameraParameters::setSaturation(const QCameraParameters& params)
2689 {
2690     int saturation = params.getInt(KEY_QC_SATURATION);
2691     int prev_sat = getInt(KEY_QC_SATURATION);
2692 
2693     if(params.get(KEY_QC_SATURATION) == NULL) {
2694        LOGH("Saturation not set by App ");
2695        return NO_ERROR;
2696     }
2697     if (prev_sat !=  saturation) {
2698         if((saturation >= m_pCapability->saturation_ctrl.min_value) &&
2699            (saturation <= m_pCapability->saturation_ctrl.max_value)) {
2700             LOGD("new saturation value : %d ", saturation);
2701             return setSaturation(saturation);
2702         } else {
2703             LOGE("invalid value %d out of (%d, %d)",
2704                    saturation,
2705                   m_pCapability->saturation_ctrl.min_value,
2706                   m_pCapability->saturation_ctrl.max_value);
2707             return BAD_VALUE;
2708         }
2709     } else {
2710         LOGD("No value change in saturation factor");
2711         return NO_ERROR;
2712     }
2713 }
2714 
2715 /*===========================================================================
2716  * FUNCTION   : setContrast
2717  *
2718  * DESCRIPTION: set contrast control value from user setting
2719  *
2720  * PARAMETERS :
2721  *   @params  : user setting parameters
2722  *
2723  * RETURN     : int32_t type of status
2724  *              NO_ERROR  -- success
2725  *              none-zero failure code
2726  *==========================================================================*/
setContrast(const QCameraParameters & params)2727 int32_t QCameraParameters::setContrast(const QCameraParameters& params)
2728 {
2729     int contrast = params.getInt(KEY_QC_CONTRAST);
2730     int prev_contrast = getInt(KEY_QC_CONTRAST);
2731 
2732     if(params.get(KEY_QC_CONTRAST) == NULL) {
2733        LOGH("Contrast not set by App ");
2734        return NO_ERROR;
2735     }
2736     if (prev_contrast !=  contrast) {
2737         if((contrast >= m_pCapability->contrast_ctrl.min_value) &&
2738            (contrast <= m_pCapability->contrast_ctrl.max_value)) {
2739             LOGD("new contrast value : %d ", contrast);
2740             int32_t rc = setContrast(contrast);
2741             return rc;
2742         } else {
2743             LOGE("invalid value %d out of (%d, %d)",
2744                    contrast,
2745                   m_pCapability->contrast_ctrl.min_value,
2746                   m_pCapability->contrast_ctrl.max_value);
2747             return BAD_VALUE;
2748         }
2749     } else {
2750         LOGD("No value change in contrast");
2751         return NO_ERROR;
2752     }
2753 }
2754 
2755 /*===========================================================================
2756  * FUNCTION   : setExposureCompensation
2757  *
2758  * DESCRIPTION: set exposure compensation value from user setting
2759  *
2760  * PARAMETERS :
2761  *   @params  : user setting parameters
2762  *
2763  * RETURN     : int32_t type of status
2764  *              NO_ERROR  -- success
2765  *              none-zero failure code
2766  *==========================================================================*/
setExposureCompensation(const QCameraParameters & params)2767 int32_t QCameraParameters::setExposureCompensation(const QCameraParameters & params)
2768 {
2769     int expComp = params.getInt(KEY_EXPOSURE_COMPENSATION);
2770     int prev_expComp = getInt(KEY_EXPOSURE_COMPENSATION);
2771 
2772     if(params.get(KEY_EXPOSURE_COMPENSATION) == NULL) {
2773        LOGH("Exposure compensation not set by App ");
2774        return NO_ERROR;
2775     }
2776     if (prev_expComp != expComp) {
2777         if((expComp >= m_pCapability->exposure_compensation_min) &&
2778            (expComp <= m_pCapability->exposure_compensation_max)) {
2779             LOGD("new Exposure Compensation value : %d ", expComp);
2780             return setExposureCompensation(expComp);
2781         } else {
2782             LOGE("invalid value %d out of (%d, %d)",
2783                    expComp,
2784                   m_pCapability->exposure_compensation_min,
2785                   m_pCapability->exposure_compensation_max);
2786             return BAD_VALUE;
2787         }
2788     } else {
2789         LOGD("No value change in Exposure Compensation");
2790         return NO_ERROR;
2791     }
2792 }
2793 
2794 /*===========================================================================
2795  * FUNCTION   : setWhiteBalance
2796  *
2797  * DESCRIPTION: set white balance value from user setting
2798  *
2799  * PARAMETERS :
2800  *   @params  : user setting parameters
2801  *
2802  * RETURN     : int32_t type of status
2803  *              NO_ERROR  -- success
2804  *              none-zero failure code
2805  *==========================================================================*/
setWhiteBalance(const QCameraParameters & params)2806 int32_t QCameraParameters::setWhiteBalance(const QCameraParameters& params)
2807 {
2808     const char *str = params.get(KEY_WHITE_BALANCE);
2809     const char *prev_str = get(KEY_WHITE_BALANCE);
2810     if (str != NULL) {
2811         if (prev_str == NULL ||
2812             strcmp(str, prev_str) != 0) {
2813             return setWhiteBalance(str);
2814         }
2815     }
2816     return NO_ERROR;
2817 }
2818 
2819 /*===========================================================================
2820  * FUNCTION   : setManualWhiteBalance
2821  *
2822  * DESCRIPTION: set manual white balance from user setting
2823  *
2824  * PARAMETERS :
2825  *   @params  : user setting parameters
2826  *
2827  * RETURN     : int32_t type of status
2828  *              NO_ERROR  -- success
2829  *              none-zero failure code
2830  *==========================================================================*/
setManualWhiteBalance(const QCameraParameters & params)2831 int32_t  QCameraParameters::setManualWhiteBalance(const QCameraParameters& params)
2832 {
2833     int32_t rc = NO_ERROR;
2834     const char *wb_str = params.get(KEY_WHITE_BALANCE);
2835     const char *prev_wb_str = get(KEY_WHITE_BALANCE);
2836     LOGD("current wb mode: %s", wb_str);
2837 
2838     if (wb_str != NULL) {
2839         if (strcmp(wb_str, WHITE_BALANCE_MANUAL)) {
2840             LOGD("dont set cct to back-end.");
2841             return NO_ERROR;
2842         }
2843     }
2844 
2845     const char *value = params.get(KEY_QC_MANUAL_WB_VALUE);
2846     const char *prev_value = get(KEY_QC_MANUAL_WB_VALUE);
2847     const char *type = params.get(KEY_QC_MANUAL_WB_TYPE);
2848     const char *prev_type = get(KEY_QC_MANUAL_WB_TYPE);
2849 
2850     if ((value != NULL) && (type != NULL) && (wb_str != NULL)) {
2851         if (prev_value  == NULL || (strcmp(value, prev_value) != 0) ||
2852             prev_type == NULL || (strcmp(type, prev_type) != 0) ||
2853             prev_wb_str == NULL || (strcmp(wb_str, prev_wb_str) != 0)) {
2854             updateParamEntry(KEY_QC_MANUAL_WB_TYPE, type);
2855             updateParamEntry(KEY_QC_MANUAL_WB_VALUE, value);
2856             int32_t wb_type = atoi(type);
2857             if (wb_type == CAM_MANUAL_WB_MODE_CCT) {
2858                 rc = setWBManualCCT(value);
2859             } else if (wb_type == CAM_MANUAL_WB_MODE_GAIN) {
2860                 rc = setManualWBGains(value);
2861             } else {
2862                 rc = BAD_VALUE;
2863             }
2864         }
2865     }
2866     return rc;
2867 }
2868 
2869 /*===========================================================================
2870  * FUNCTION   : setAntibanding
2871  *
2872  * DESCRIPTION: set antibanding value from user setting
2873  *
2874  * PARAMETERS :
2875  *   @params  : user setting parameters
2876  *
2877  * RETURN     : int32_t type of status
2878  *              NO_ERROR  -- success
2879  *              none-zero failure code
2880  *==========================================================================*/
setAntibanding(const QCameraParameters & params)2881 int32_t QCameraParameters::setAntibanding(const QCameraParameters& params)
2882 {
2883     const char *str = params.get(KEY_ANTIBANDING);
2884     const char *prev_str = get(KEY_ANTIBANDING);
2885     if (str != NULL) {
2886         if (prev_str == NULL ||
2887             strcmp(str, prev_str) != 0) {
2888             return setAntibanding(str);
2889         }
2890     }
2891     return NO_ERROR;
2892 }
2893 
2894 /*===========================================================================
2895  * FUNCTION   : setStatsDebugMask
2896  *
2897  * DESCRIPTION: get the value from persist file in Stats module that will
2898  *              control funtionality in the module
2899  *
2900  * PARAMETERS : none
2901  *
2902  * RETURN     : int32_t type of status
2903  *              NO_ERROR  -- success
2904  *              none-zero failure code
2905  *==========================================================================*/
setStatsDebugMask()2906 int32_t QCameraParameters::setStatsDebugMask()
2907 {
2908     uint32_t mask = 0;
2909     char value[PROPERTY_VALUE_MAX];
2910 
2911     property_get("persist.camera.stats.debug.mask", value, "0");
2912     mask = (uint32_t)atoi(value);
2913 
2914     LOGH("ctrl mask :%d", mask);
2915 
2916     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_DEBUG_MASK, mask)) {
2917         return BAD_VALUE;
2918     }
2919 
2920     return NO_ERROR;
2921 }
2922 
2923 /*===========================================================================
2924  * FUNCTION   : setPAAF
2925  *
2926  * DESCRIPTION: get the value from persist file in Stats module that will
2927  *              control the preview assisted AF in the module
2928  *
2929  * PARAMETERS : none
2930  *
2931  * RETURN     : int32_t type of status
2932  *              NO_ERROR  -- success
2933  *              none-zero failure code
2934  *==========================================================================*/
setPAAF()2935 int32_t QCameraParameters::setPAAF()
2936 {
2937     uint32_t paaf = 0;
2938     char value[PROPERTY_VALUE_MAX];
2939 
2940     property_get("persist.camera.stats.af.paaf", value, "1");
2941     paaf = (uint32_t)atoi(value);
2942 
2943     LOGH("PAAF is: %s", paaf ? "ON": "OFF");
2944 
2945     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_STATS_AF_PAAF, paaf)) {
2946         return BAD_VALUE;
2947     }
2948 
2949     return NO_ERROR;
2950 }
2951 
2952 /*===========================================================================
2953  * FUNCTION   : setSceneDetect
2954  *
2955  * DESCRIPTION: set scenen detect 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  *==========================================================================*/
setSceneDetect(const QCameraParameters & params)2964 int32_t QCameraParameters::setSceneDetect(const QCameraParameters& params)
2965 {
2966     const char *str = params.get(KEY_QC_SCENE_DETECT);
2967     const char *prev_str = get(KEY_QC_SCENE_DETECT);
2968     if (str != NULL) {
2969         if (prev_str == NULL ||
2970             strcmp(str, prev_str) != 0) {
2971             return setSceneDetect(str);
2972         }
2973     }
2974     return NO_ERROR;
2975 }
2976 
2977 /*===========================================================================
2978  * FUNCTION   : setVideoHDR
2979  *
2980  * DESCRIPTION: set video HDR value 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  *==========================================================================*/
setVideoHDR(const QCameraParameters & params)2989 int32_t QCameraParameters::setVideoHDR(const QCameraParameters& params)
2990 {
2991     const char *str = params.get(KEY_QC_VIDEO_HDR);
2992     const char *prev_str = get(KEY_QC_VIDEO_HDR);
2993     if (str != NULL) {
2994         if (prev_str == NULL ||
2995             strcmp(str, prev_str) != 0) {
2996             return setVideoHDR(str);
2997         }
2998     }
2999     return NO_ERROR;
3000 }
3001 
3002 /*===========================================================================
3003  * FUNCTION   : setVtEnable
3004  *
3005  * DESCRIPTION: set vt Time Stamp enable from user setting
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  *==========================================================================*/
setVtEnable(const QCameraParameters & params)3014 int32_t QCameraParameters::setVtEnable(const QCameraParameters& params)
3015 {
3016     const char *str = params.get(KEY_QC_VT_ENABLE);
3017     const char *prev_str = get(KEY_QC_VT_ENABLE);
3018     if (str != NULL) {
3019         if (prev_str == NULL ||
3020             strcmp(str, prev_str) != 0) {
3021             return setVtEnable(str);
3022         }
3023     }
3024     return NO_ERROR;
3025 }
3026 
3027 /*===========================================================================
3028  * FUNCTION   : setFaceRecognition
3029  *
3030  * DESCRIPTION: set face recognition mode from user setting
3031  *
3032  * PARAMETERS :
3033  *   @params  : user setting parameters
3034  *
3035  * RETURN     : int32_t type of status
3036  *              NO_ERROR  -- success
3037  *              none-zero failure code
3038  *==========================================================================*/
setFaceRecognition(const QCameraParameters & params)3039 int32_t QCameraParameters::setFaceRecognition(const QCameraParameters& params)
3040 {
3041     const char *str = params.get(KEY_QC_FACE_RECOGNITION);
3042     const char *prev_str = get(KEY_QC_FACE_RECOGNITION);
3043     if (str != NULL) {
3044         if (prev_str == NULL ||
3045             strcmp(str, prev_str) != 0) {
3046             uint32_t maxFaces = (uint32_t)params.getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
3047             return setFaceRecognition(str, maxFaces);
3048         }
3049     }
3050     return NO_ERROR;
3051 }
3052 
3053 /*===========================================================================
3054  * FUNCTION   : setZoom
3055  *
3056  * DESCRIPTION: set zoom value from user setting
3057  *
3058  * PARAMETERS :
3059  *   @params  : user setting parameters
3060  *
3061  * RETURN     : int32_t type of status
3062  *              NO_ERROR  -- success
3063  *              none-zero failure code
3064  *==========================================================================*/
setZoom(const QCameraParameters & params)3065 int32_t QCameraParameters::setZoom(const QCameraParameters& params)
3066 {
3067     if ((m_pCapability->zoom_supported == 0 ||
3068          m_pCapability->zoom_ratio_tbl_cnt == 0)) {
3069         LOGH("no zoom support");
3070         return NO_ERROR;
3071     }
3072 
3073     int zoomLevel = params.getInt(KEY_ZOOM);
3074     mParmZoomLevel = zoomLevel;
3075     if ((zoomLevel < 0) || (zoomLevel >= (int)m_pCapability->zoom_ratio_tbl_cnt)) {
3076         LOGE("invalid value %d out of (%d, %d)",
3077                zoomLevel,
3078               0, m_pCapability->zoom_ratio_tbl_cnt-1);
3079         return BAD_VALUE;
3080     }
3081 
3082     int prevZoomLevel = getInt(KEY_ZOOM);
3083     if (prevZoomLevel == zoomLevel) {
3084         LOGD("No value change in zoom %d %d", prevZoomLevel, zoomLevel);
3085         return NO_ERROR;
3086     }
3087 
3088     return setZoom(zoomLevel);
3089 }
3090 
3091 /*===========================================================================
3092  * FUNCTION   : setISOValue
3093  *
3094  * DESCRIPTION: set ISO value from user setting
3095  *
3096  * PARAMETERS :
3097  *   @params  : user setting parameters
3098  *
3099  * RETURN     : int32_t type of status
3100  *              NO_ERROR  -- success
3101  *              none-zero failure code
3102  *==========================================================================*/
setISOValue(const QCameraParameters & params)3103 int32_t  QCameraParameters::setISOValue(const QCameraParameters& params)
3104 {
3105     const char *str = params.get(KEY_QC_ISO_MODE);
3106     const char *prev_str = get(KEY_QC_ISO_MODE);
3107 
3108     if(getManualCaptureMode()) {
3109         char iso_val[PROPERTY_VALUE_MAX];
3110 
3111         property_get("persist.camera.iso", iso_val, "");
3112         if (strlen(iso_val) > 0) {
3113             if (prev_str == NULL ||
3114                     strcmp(iso_val, prev_str) != 0) {
3115                 return setISOValue(iso_val);
3116             }
3117         }
3118     } else if (str != NULL) {
3119         if (prev_str == NULL ||
3120             strcmp(str, prev_str) != 0) {
3121             return setISOValue(str);
3122         }
3123     }
3124     return NO_ERROR;
3125 }
3126 
3127 /*===========================================================================
3128  * FUNCTION   : setContinuousISO
3129  *
3130  * DESCRIPTION: set ISO value from user setting
3131  *
3132  * PARAMETERS :
3133  *   @params  : user setting parameters
3134  *
3135  * RETURN     : int32_t type of status
3136  *              NO_ERROR  -- success
3137  *              none-zero failure code
3138  *==========================================================================*/
setContinuousISO(const char * isoValue)3139 int32_t  QCameraParameters::setContinuousISO(const char *isoValue)
3140 {
3141     char iso[PROPERTY_VALUE_MAX];
3142     int32_t continous_iso = 0;
3143 
3144     // Check if continuous ISO is set through setproperty
3145     property_get("persist.camera.continuous.iso", iso, "");
3146     if (strlen(iso) > 0) {
3147         continous_iso = atoi(iso);
3148     } else {
3149         continous_iso = atoi(isoValue);
3150     }
3151 
3152     if ((continous_iso >= 0) &&
3153             (continous_iso <= m_pCapability->sensitivity_range.max_sensitivity)) {
3154         LOGH("Setting continuous ISO value %d", continous_iso);
3155         updateParamEntry(KEY_QC_CONTINUOUS_ISO, isoValue);
3156 
3157         cam_intf_parm_manual_3a_t iso_settings;
3158         memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
3159         iso_settings.previewOnly = FALSE;
3160         iso_settings.value = continous_iso;
3161         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
3162             return BAD_VALUE;
3163         }
3164         return NO_ERROR;
3165     }
3166     LOGE("Invalid iso value: %d", continous_iso);
3167     return BAD_VALUE;
3168 }
3169 
3170 /*===========================================================================
3171  * FUNCTION   : setExposureTime
3172  *
3173  * DESCRIPTION: set exposure time from user setting
3174  *
3175  * PARAMETERS :
3176  *   @params  : user setting parameters
3177  *
3178  * RETURN     : int32_t type of status
3179  *              NO_ERROR  -- success
3180  *              none-zero failure code
3181  *==========================================================================*/
setExposureTime(const QCameraParameters & params)3182 int32_t  QCameraParameters::setExposureTime(const QCameraParameters& params)
3183 {
3184     const char *str = params.get(KEY_QC_EXPOSURE_TIME);
3185     const char *prev_str = get(KEY_QC_EXPOSURE_TIME);
3186     if (str != NULL) {
3187         if (prev_str == NULL ||
3188                 strcmp(str, prev_str) != 0) {
3189             return setExposureTime(str);
3190         }
3191     } else if(getManualCaptureMode()) {
3192         char expTime[PROPERTY_VALUE_MAX];
3193 
3194         property_get("persist.camera.exposure.time", expTime, "");
3195         if (strlen(expTime) > 0) {
3196             if (prev_str == NULL ||
3197                     strcmp(expTime, prev_str) != 0) {
3198                 return setExposureTime(expTime);
3199             }
3200         }
3201     }
3202 
3203     return NO_ERROR;
3204 }
3205 
3206 /*===========================================================================
3207  * FUNCTION   : setVideoRotation
3208  *
3209  * DESCRIPTION: set rotation value from user setting
3210  *
3211  * PARAMETERS :
3212  *   @params  : user setting parameters
3213  *
3214  * RETURN     : int32_t type of status
3215  *              NO_ERROR  -- success
3216  *              none-zero failure code
3217  *==========================================================================*/
setVideoRotation(const QCameraParameters & params)3218 int32_t QCameraParameters::setVideoRotation(const QCameraParameters& params)
3219 {
3220     const char *str = params.get(KEY_QC_VIDEO_ROTATION);
3221     if(str != NULL) {
3222         int value = lookupAttr(VIDEO_ROTATION_MODES_MAP,
3223                 PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
3224         if (value != NAME_NOT_FOUND) {
3225             updateParamEntry(KEY_QC_VIDEO_ROTATION, str);
3226             LOGL("setVideoRotation:   %d: ", str, value);
3227         } else {
3228             LOGE("Invalid rotation value: %d", value);
3229             return BAD_VALUE;
3230         }
3231 
3232     }
3233     return NO_ERROR;
3234 }
3235 
3236 /*===========================================================================
3237  * FUNCTION   : setRotation
3238  *
3239  * DESCRIPTION: set rotation value from user setting
3240  *
3241  * PARAMETERS :
3242  *   @params  : user setting parameters
3243  *
3244  * RETURN     : int32_t type of status
3245  *              NO_ERROR  -- success
3246  *              none-zero failure code
3247  *==========================================================================*/
setRotation(const QCameraParameters & params)3248 int32_t QCameraParameters::setRotation(const QCameraParameters& params)
3249 {
3250     int32_t rotation = params.getInt(KEY_ROTATION);
3251     if (rotation != -1) {
3252         if (rotation == 0 || rotation == 90 ||
3253             rotation == 180 || rotation == 270) {
3254             set(KEY_ROTATION, rotation);
3255 
3256             ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_JPEG_ORIENTATION,
3257                     rotation);
3258             mRotation = rotation;
3259         } else {
3260             LOGE("Invalid rotation value: %d", rotation);
3261             return BAD_VALUE;
3262         }
3263     }
3264     return NO_ERROR;
3265 }
3266 
3267 /*===========================================================================
3268  * FUNCTION   : setFlash
3269  *
3270  * DESCRIPTION: set flash mode from user setting
3271  *
3272  * PARAMETERS :
3273  *   @params  : user setting parameters
3274  *
3275  * RETURN     : int32_t type of status
3276  *              NO_ERROR  -- success
3277  *              none-zero failure code
3278  *==========================================================================*/
setFlash(const QCameraParameters & params)3279 int32_t QCameraParameters::setFlash(const QCameraParameters& params)
3280 {
3281     const char *str = params.get(KEY_FLASH_MODE);
3282     const char *prev_str = get(KEY_FLASH_MODE);
3283     if (str != NULL) {
3284         if (prev_str == NULL ||
3285             strcmp(str, prev_str) != 0) {
3286             return setFlash(str);
3287         }
3288     }
3289     return NO_ERROR;
3290 }
3291 
3292 /*===========================================================================
3293  * FUNCTION   : setAecLock
3294  *
3295  * DESCRIPTION: set AEC lock value from user setting
3296  *
3297  * PARAMETERS :
3298  *   @params  : user setting parameters
3299  *
3300  * RETURN     : int32_t type of status
3301  *              NO_ERROR  -- success
3302  *              none-zero failure code
3303  *==========================================================================*/
setAecLock(const QCameraParameters & params)3304 int32_t QCameraParameters::setAecLock(const QCameraParameters& params)
3305 {
3306     const char *str = params.get(KEY_AUTO_EXPOSURE_LOCK);
3307     const char *prev_str = get(KEY_AUTO_EXPOSURE_LOCK);
3308     if (str != NULL) {
3309         if (prev_str == NULL ||
3310             strcmp(str, prev_str) != 0) {
3311             return setAecLock(str);
3312         }
3313     }
3314     return NO_ERROR;
3315 }
3316 
3317 /*===========================================================================
3318  * FUNCTION   : setAwbLock
3319  *
3320  * DESCRIPTION: set AWB lock from user setting
3321  *
3322  * PARAMETERS :
3323  *   @params  : user setting parameters
3324  *
3325  * RETURN     : int32_t type of status
3326  *              NO_ERROR  -- success
3327  *              none-zero failure code
3328  *==========================================================================*/
setAwbLock(const QCameraParameters & params)3329 int32_t QCameraParameters::setAwbLock(const QCameraParameters& params)
3330 {
3331     const char *str = params.get(KEY_AUTO_WHITEBALANCE_LOCK);
3332     const char *prev_str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3333     if (str != NULL) {
3334         if (prev_str == NULL ||
3335             strcmp(str, prev_str) != 0) {
3336             return setAwbLock(str);
3337         }
3338     }
3339     return NO_ERROR;
3340 }
3341 
3342 /*===========================================================================
3343  * FUNCTION   : setAutoHDR
3344  *
3345  * DESCRIPTION: Enable/disable auto HDR
3346  *
3347  * PARAMETERS :
3348  *   @params  : user setting parameters
3349  *
3350  * RETURN     : int32_t type of status
3351  *              NO_ERROR  -- success
3352  *              none-zero failure code
3353  *==========================================================================*/
setAutoHDR(const QCameraParameters & params)3354 int32_t QCameraParameters::setAutoHDR(const QCameraParameters& params)
3355 {
3356     const char *str = params.get(KEY_QC_AUTO_HDR_ENABLE);
3357     const char *prev_str = get(KEY_QC_AUTO_HDR_ENABLE);
3358     char prop[PROPERTY_VALUE_MAX];
3359 
3360     memset(prop, 0, sizeof(prop));
3361     property_get("persist.camera.auto.hdr.enable", prop, VALUE_DISABLE);
3362     if (str != NULL) {
3363        if (prev_str == NULL ||
3364            strcmp(str, prev_str) != 0) {
3365            LOGH("Auto HDR set to: %s", str);
3366            return updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, str);
3367        }
3368     } else {
3369        if (prev_str == NULL ||
3370            strcmp(prev_str, prop) != 0 ) {
3371            LOGH("Auto HDR set to: %s", prop);
3372            updateParamEntry(KEY_QC_AUTO_HDR_ENABLE, prop);
3373        }
3374     }
3375 
3376        return NO_ERROR;
3377 }
3378 
3379 /*===========================================================================
3380 * FUNCTION   : isAutoHDREnabled
3381 *
3382 * DESCRIPTION: Query auto HDR status
3383 *
3384 * PARAMETERS : None
3385 *
3386 * RETURN     : bool true/false
3387 *==========================================================================*/
isAutoHDREnabled()3388 bool QCameraParameters::isAutoHDREnabled()
3389 {
3390     const char *str = get(KEY_QC_AUTO_HDR_ENABLE);
3391     if (str != NULL) {
3392         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
3393                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
3394         if (value == NAME_NOT_FOUND) {
3395             LOGE("Invalid Auto HDR value %s", str);
3396             return false;
3397         }
3398 
3399         LOGH("Auto HDR status is: %d", value);
3400         return value ? true : false;
3401     }
3402 
3403     LOGH("Auto HDR status not set!");
3404     return false;
3405 }
3406 
3407 /*===========================================================================
3408  * FUNCTION   : setMCEValue
3409  *
3410  * DESCRIPTION: set memory color enhancement value from user setting
3411  *
3412  * PARAMETERS :
3413  *   @params  : user setting parameters
3414  *
3415  * RETURN     : int32_t type of status
3416  *              NO_ERROR  -- success
3417  *              none-zero failure code
3418  *==========================================================================*/
setMCEValue(const QCameraParameters & params)3419 int32_t QCameraParameters::setMCEValue(const QCameraParameters& params)
3420 {
3421     const char *str = params.get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3422     const char *prev_str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
3423     if (str != NULL) {
3424         if (prev_str == NULL ||
3425             strcmp(str, prev_str) != 0) {
3426             return setMCEValue(str);
3427         }
3428     }
3429     return NO_ERROR;
3430 }
3431 
3432 /*===========================================================================
3433  * FUNCTION   : setDISValue
3434  *
3435  * DESCRIPTION: enable/disable DIS from user setting
3436  *
3437  * PARAMETERS :
3438  *   @params  : user setting parameters
3439  *
3440  * RETURN     : int32_t type of status
3441  *              NO_ERROR  -- success
3442  *              none-zero failure code
3443  *==========================================================================*/
setDISValue(const QCameraParameters & params)3444 int32_t QCameraParameters::setDISValue(const QCameraParameters& params)
3445 {
3446     const char *str = params.get(KEY_QC_DIS);
3447     const char *prev_str = get(KEY_QC_DIS);
3448     if (str != NULL) {
3449         if (prev_str == NULL ||
3450             strcmp(str, prev_str) != 0) {
3451             return setDISValue(str);
3452         }
3453     }
3454     return NO_ERROR;
3455 }
3456 
3457 /*===========================================================================
3458  * FUNCTION   : setLensShadeValue
3459  *
3460  * DESCRIPTION: set lens shade value from user setting
3461  *
3462  * PARAMETERS :
3463  *   @params  : user setting parameters
3464  *
3465  * RETURN     : int32_t type of status
3466  *              NO_ERROR  -- success
3467  *              none-zero failure code
3468  *==========================================================================*/
setLensShadeValue(const QCameraParameters & params)3469 int32_t QCameraParameters::setLensShadeValue(const QCameraParameters& params)
3470 {
3471     const char *str = params.get(KEY_QC_LENSSHADE);
3472     const char *prev_str = get(KEY_QC_LENSSHADE);
3473     if (str != NULL) {
3474         if (prev_str == NULL ||
3475             strcmp(str, prev_str) != 0) {
3476             return setLensShadeValue(str);
3477         }
3478     }
3479     return NO_ERROR;
3480 }
3481 
3482 /*===========================================================================
3483  * FUNCTION   : setFocusAreas
3484  *
3485  * DESCRIPTION: set focus areas from user setting
3486  *
3487  * PARAMETERS :
3488  *   @params  : user setting parameters
3489  *
3490  * RETURN     : int32_t type of status
3491  *              NO_ERROR  -- success
3492  *              none-zero failure code
3493  *==========================================================================*/
setFocusAreas(const QCameraParameters & params)3494 int32_t QCameraParameters::setFocusAreas(const QCameraParameters& params)
3495 {
3496     const char *str = params.get(KEY_FOCUS_AREAS);
3497 
3498     if (getRelatedCamSyncInfo()->mode == CAM_MODE_SECONDARY) {
3499         // Ignore focus areas for secondary camera
3500         LOGH("Ignore focus areas for secondary camera!! ");
3501         return NO_ERROR;
3502     }
3503     if (str != NULL) {
3504         int max_num_af_areas = getInt(KEY_MAX_NUM_FOCUS_AREAS);
3505         if(max_num_af_areas == 0) {
3506             LOGE("max num of AF area is 0, cannot set focus areas");
3507             return BAD_VALUE;
3508         }
3509 
3510         const char *prev_str = get(KEY_FOCUS_AREAS);
3511         if (prev_str == NULL ||
3512             strcmp(str, prev_str) != 0) {
3513             return setFocusAreas(str);
3514         }
3515     }
3516     return NO_ERROR;
3517 }
3518 
3519 /*===========================================================================
3520  * FUNCTION   : setMeteringAreas
3521  *
3522  * DESCRIPTION: set metering areas from user setting
3523  *
3524  * PARAMETERS :
3525  *   @params  : user setting parameters
3526  *
3527  * RETURN     : int32_t type of status
3528  *              NO_ERROR  -- success
3529  *              none-zero failure code
3530  *==========================================================================*/
setMeteringAreas(const QCameraParameters & params)3531 int32_t QCameraParameters::setMeteringAreas(const QCameraParameters& params)
3532 {
3533     const char *str = params.get(KEY_METERING_AREAS);
3534     if (str != NULL) {
3535         int max_num_mtr_areas = getInt(KEY_MAX_NUM_METERING_AREAS);
3536         if(max_num_mtr_areas == 0) {
3537             LOGE("max num of metering areas is 0, cannot set focus areas");
3538             return BAD_VALUE;
3539         }
3540 
3541         const char *prev_str = get(KEY_METERING_AREAS);
3542         if (prev_str == NULL ||
3543             strcmp(str, prev_str) != 0 ||
3544             (m_bNeedRestart == true)) {
3545             return setMeteringAreas(str);
3546         }
3547     }
3548     return NO_ERROR;
3549 }
3550 
3551 /*===========================================================================
3552  * FUNCTION   : setSceneMode
3553  *
3554  * DESCRIPTION: set scenen mode from user setting
3555  *
3556  * PARAMETERS :
3557  *   @params  : user setting parameters
3558  *
3559  * RETURN     : int32_t type of status
3560  *              NO_ERROR  -- success
3561  *              none-zero failure code
3562  *==========================================================================*/
setSceneMode(const QCameraParameters & params)3563 int32_t QCameraParameters::setSceneMode(const QCameraParameters& params)
3564 {
3565     const char *str = params.get(KEY_SCENE_MODE);
3566     const char *prev_str = get(KEY_SCENE_MODE);
3567     LOGH("str - %s, prev_str - %s", str, prev_str);
3568 
3569     if (str != NULL) {
3570         if (prev_str == NULL ||
3571             strcmp(str, prev_str) != 0) {
3572 
3573             if(strcmp(str, SCENE_MODE_AUTO) == 0) {
3574                 m_bSceneTransitionAuto = true;
3575             }
3576             if (strcmp(str, SCENE_MODE_HDR) == 0) {
3577 
3578                 // If HDR is set from client  and the feature is not enabled in the backend, ignore it.
3579                 if (m_bHDRModeSensor && isSupportedSensorHdrSize(params)) {
3580                     m_bSensorHDREnabled = true;
3581                     LOGH("Sensor HDR mode Enabled");
3582                 } else {
3583                     m_bHDREnabled = true;
3584                     LOGH("S/W HDR Enabled");
3585                 }
3586             } else {
3587                 m_bHDREnabled = false;
3588                 if (m_bSensorHDREnabled) {
3589                     m_bSensorHDREnabled = false;
3590                     m_bNeedRestart = true;
3591                     setSensorSnapshotHDR("off");
3592                 }
3593             }
3594 
3595             if (m_bSensorHDREnabled) {
3596                 setSensorSnapshotHDR("on");
3597                 m_bNeedRestart = true;
3598             } else if ((m_bHDREnabled) ||
3599                 ((prev_str != NULL) && (strcmp(prev_str, SCENE_MODE_HDR) == 0))) {
3600                 LOGH("scene mode changed between HDR and non-HDR, need restart");
3601                 m_bNeedRestart = true;
3602             }
3603 
3604             return setSceneMode(str);
3605         }
3606     }
3607     return NO_ERROR;
3608 }
3609 
3610 /*===========================================================================
3611  * FUNCTION   : setSelectableZoneAf
3612  *
3613  * DESCRIPTION: set selectable zone auto focus value from user setting
3614  *
3615  * PARAMETERS :
3616  *   @params  : user setting parameters
3617  *
3618  * RETURN     : int32_t type of status
3619  *              NO_ERROR  -- success
3620  *              none-zero failure code
3621  *==========================================================================*/
setSelectableZoneAf(const QCameraParameters & params)3622 int32_t QCameraParameters::setSelectableZoneAf(const QCameraParameters& params)
3623 {
3624     const char *str = params.get(KEY_QC_SELECTABLE_ZONE_AF);
3625     const char *prev_str = get(KEY_QC_SELECTABLE_ZONE_AF);
3626     if (str != NULL) {
3627         if (prev_str == NULL ||
3628             strcmp(str, prev_str) != 0) {
3629             return setSelectableZoneAf(str);
3630         }
3631     }
3632     return NO_ERROR;
3633 }
3634 
3635 /*===========================================================================
3636  * FUNCTION   : setAEBracket
3637  *
3638  * DESCRIPTION: set AE bracket from user setting
3639  *
3640  * PARAMETERS :
3641  *   @params  : user setting parameters
3642  *
3643  * RETURN     : int32_t type of status
3644  *              NO_ERROR  -- success
3645  *              none-zero failure code
3646  *==========================================================================*/
setAEBracket(const QCameraParameters & params)3647 int32_t QCameraParameters::setAEBracket(const QCameraParameters& params)
3648 {
3649     if (isHDREnabled()) {
3650         LOGH("scene mode is HDR, overwrite AE bracket setting to off");
3651         return setAEBracket(AE_BRACKET_OFF);
3652     }
3653 
3654     const char *expStr = params.get(KEY_QC_CAPTURE_BURST_EXPOSURE);
3655     if (NULL != expStr && strlen(expStr) > 0) {
3656         set(KEY_QC_CAPTURE_BURST_EXPOSURE, expStr);
3657     } else {
3658         char prop[PROPERTY_VALUE_MAX];
3659         memset(prop, 0, sizeof(prop));
3660         property_get("persist.capture.burst.exposures", prop, "");
3661         if (strlen(prop) > 0) {
3662             set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
3663         } else {
3664             remove(KEY_QC_CAPTURE_BURST_EXPOSURE);
3665         }
3666     }
3667 
3668     const char *str = params.get(KEY_QC_AE_BRACKET_HDR);
3669     const char *prev_str = get(KEY_QC_AE_BRACKET_HDR);
3670     if (str != NULL) {
3671         if (prev_str == NULL ||
3672             strcmp(str, prev_str) != 0) {
3673             return setAEBracket(str);
3674         }
3675     }
3676     return NO_ERROR;
3677 }
3678 
3679 /*===========================================================================
3680  * FUNCTION   : setAFBracket
3681  *
3682  * DESCRIPTION: set AF bracket from user setting
3683  *
3684  * PARAMETERS :
3685  *   @params  : user setting parameters
3686  *
3687  * RETURN     : int32_t type of status
3688  *              NO_ERROR  -- success
3689  *              none-zero failure code
3690  *==========================================================================*/
setAFBracket(const QCameraParameters & params)3691 int32_t QCameraParameters::setAFBracket(const QCameraParameters& params)
3692 {
3693     if ((m_pCapability->qcom_supported_feature_mask &
3694             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3695         LOGH("AF Bracketing is not supported");
3696         return NO_ERROR;
3697     }
3698     const char *str = params.get(KEY_QC_AF_BRACKET);
3699     const char *prev_str = get(KEY_QC_AF_BRACKET);
3700     LOGH("str =%s & prev_str =%s", str, prev_str);
3701     if (str != NULL) {
3702         if (prev_str == NULL ||
3703             strcmp(str, prev_str) != 0) {
3704             m_bNeedRestart = true;
3705             return setAFBracket(str);
3706         }
3707     }
3708     return NO_ERROR;
3709 }
3710 
3711 /*===========================================================================
3712  * FUNCTION   : setReFocus
3713  *
3714  * DESCRIPTION: set refocus from user setting
3715  *
3716  * PARAMETERS :
3717  *   @params  : user setting parameters
3718  *
3719  * RETURN     : int32_t type of status
3720  *              NO_ERROR  -- success
3721  *              none-zero failure code
3722  *==========================================================================*/
setReFocus(const QCameraParameters & params)3723 int32_t QCameraParameters::setReFocus(const QCameraParameters& params)
3724 {
3725     if ((m_pCapability->qcom_supported_feature_mask &
3726             (CAM_QCOM_FEATURE_REFOCUS | CAM_QCOM_FEATURE_UBIFOCUS)) == 0) {
3727         LOGD("AF Bracketing is not supported");
3728         return NO_ERROR;
3729     }
3730     const char *str = params.get(KEY_QC_RE_FOCUS);
3731     const char *prev_str = get(KEY_QC_RE_FOCUS);
3732     LOGH("str =%s & prev_str =%s", str, prev_str);
3733     if (str != NULL) {
3734         if (prev_str == NULL ||
3735             strcmp(str, prev_str) != 0) {
3736             m_bNeedRestart = true;
3737             return setReFocus(str);
3738         }
3739     }
3740     return NO_ERROR;
3741 }
3742 
3743 /*===========================================================================
3744  * FUNCTION   : setChromaFlash
3745  *
3746  * DESCRIPTION: set chroma flash from user setting
3747  *
3748  * PARAMETERS :
3749  *   @params  : user setting parameters
3750  *
3751  * RETURN     : int32_t type of status
3752  *              NO_ERROR  -- success
3753  *              none-zero failure code
3754  *==========================================================================*/
setChromaFlash(const QCameraParameters & params)3755 int32_t QCameraParameters::setChromaFlash(const QCameraParameters& params)
3756 {
3757     if ((m_pCapability->qcom_supported_feature_mask &
3758         CAM_QCOM_FEATURE_CHROMA_FLASH) == 0) {
3759         LOGH("Chroma Flash is not supported");
3760         return NO_ERROR;
3761     }
3762     const char *str = params.get(KEY_QC_CHROMA_FLASH);
3763     const char *prev_str = get(KEY_QC_CHROMA_FLASH);
3764     LOGH("str =%s & prev_str =%s", str, prev_str);
3765     if (str != NULL) {
3766         if (prev_str == NULL ||
3767             strcmp(str, prev_str) != 0) {
3768             m_bNeedRestart = true;
3769             return setChromaFlash(str);
3770         }
3771     }
3772     return NO_ERROR;
3773 }
3774 
3775 /*===========================================================================
3776  * FUNCTION   : setOptiZoom
3777  *
3778  * DESCRIPTION: set opti zoom from user setting
3779  *
3780  * PARAMETERS :
3781  *   @params  : user setting parameters
3782  *
3783  * RETURN     : int32_t type of status
3784  *              NO_ERROR  -- success
3785  *              none-zero failure code
3786  *==========================================================================*/
setOptiZoom(const QCameraParameters & params)3787 int32_t QCameraParameters::setOptiZoom(const QCameraParameters& params)
3788 {
3789     if ((m_pCapability->qcom_supported_feature_mask &
3790         CAM_QCOM_FEATURE_OPTIZOOM) == 0){
3791         LOGH("Opti Zoom is not supported");
3792         return NO_ERROR;
3793     }
3794     const char *str = params.get(KEY_QC_OPTI_ZOOM);
3795     const char *prev_str = get(KEY_QC_OPTI_ZOOM);
3796     LOGH("str =%s & prev_str =%s", str, prev_str);
3797     if (str != NULL) {
3798         if (prev_str == NULL ||
3799             strcmp(str, prev_str) != 0) {
3800             m_bNeedRestart = true;
3801             return setOptiZoom(str);
3802         }
3803     }
3804     return NO_ERROR;
3805 }
3806 
3807 /*===========================================================================
3808  * FUNCTION   : setTruePortrait
3809  *
3810  * DESCRIPTION: set true portrait from user setting
3811  *
3812  * PARAMETERS :
3813  *   @params  : user setting parameters
3814  *
3815  * RETURN     : int32_t type of status
3816  *              NO_ERROR  -- success
3817  *              none-zero failure code
3818  *==========================================================================*/
setTruePortrait(const QCameraParameters & params)3819 int32_t QCameraParameters::setTruePortrait(const QCameraParameters& params)
3820 {
3821     if ((m_pCapability->qcom_supported_feature_mask &
3822             CAM_QCOM_FEATURE_TRUEPORTRAIT) == 0) {
3823         LOGD("True Portrait is not supported");
3824         return NO_ERROR;
3825     }
3826     const char *str = params.get(KEY_QC_TRUE_PORTRAIT);
3827     const char *prev_str = get(KEY_QC_TRUE_PORTRAIT);
3828     LOGH("str =%s & prev_str =%s", str, prev_str);
3829     if (str != NULL) {
3830         if (prev_str == NULL ||
3831             strcmp(str, prev_str) != 0) {
3832             return setTruePortrait(str);
3833         }
3834     }
3835     return NO_ERROR;
3836 }
3837 
3838 /*===========================================================================
3839  * FUNCTION   : setHDRMode
3840  *
3841  * DESCRIPTION: set HDR mode from user setting
3842  *
3843  * PARAMETERS :
3844  *   @params  : user setting parameters
3845  *
3846  * RETURN     : int32_t type of status
3847  *              NO_ERROR  -- success
3848  *              none-zero failure code
3849  *==========================================================================*/
setHDRMode(const QCameraParameters & params)3850 int32_t QCameraParameters::setHDRMode(const QCameraParameters& params)
3851 {
3852     const char *str = params.get(KEY_QC_HDR_MODE);
3853     const char *prev_str = get(KEY_QC_HDR_MODE);
3854     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
3855           (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
3856 
3857     LOGH("str =%s & prev_str =%s", str, prev_str);
3858     if (str != NULL) {
3859         if ((CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) &&
3860                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR)))) {
3861             LOGH("Only sensor HDR is supported");
3862             return NO_ERROR;
3863         } else if  ((CAM_QCOM_FEATURE_HDR == supported_hdr_modes) &&
3864                 (strncmp(str, HDR_MODE_SENSOR, strlen(HDR_MODE_MULTI_FRAME)))) {
3865             LOGH("Only multi frame HDR is supported");
3866             return NO_ERROR;
3867         } else if (!supported_hdr_modes) {
3868             LOGH("HDR is not supported");
3869             return NO_ERROR;
3870         }
3871         if (prev_str == NULL ||
3872                 strcmp(str, prev_str) != 0) {
3873             return setHDRMode(str);
3874         }
3875     }
3876 
3877     return NO_ERROR;
3878 }
3879 
3880 /*===========================================================================
3881  * FUNCTION   : setHDRNeed1x
3882  *
3883  * DESCRIPTION: set HDR need 1x from user setting
3884  *
3885  * PARAMETERS :
3886  *   @params  : user setting parameters
3887  *
3888  * RETURN     : int32_t type of status
3889  *              NO_ERROR  -- success
3890  *              none-zero failure code
3891  *==========================================================================*/
setHDRNeed1x(const QCameraParameters & params)3892 int32_t QCameraParameters::setHDRNeed1x(const QCameraParameters& params)
3893 {
3894     const char *str = params.get(KEY_QC_HDR_NEED_1X);
3895     const char *prev_str = get(KEY_QC_HDR_NEED_1X);
3896 
3897     LOGH("str =%s & prev_str =%s", str, prev_str);
3898     if (str != NULL) {
3899         if (m_bHDRModeSensor) {
3900             LOGH("Only multi frame HDR supports 1x frame");
3901             return NO_ERROR;
3902         }
3903         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
3904             return setHDRNeed1x(str);
3905         }
3906     }
3907     return NO_ERROR;
3908 }
3909 
3910 /*===========================================================================
3911  * FUNCTION   : setSeeMore
3912  *
3913  * DESCRIPTION: set see more (llvd) from user setting
3914  *
3915  * PARAMETERS :
3916  *   @params  : user setting parameters
3917  *
3918  * RETURN     : int32_t type of status
3919  *              NO_ERROR  -- success
3920  *              none-zero failure code
3921  *==========================================================================*/
setSeeMore(const QCameraParameters & params)3922 int32_t QCameraParameters::setSeeMore(const QCameraParameters& params)
3923 {
3924     if ((m_pCapability->qcom_supported_feature_mask &
3925             CAM_QCOM_FEATURE_LLVD) == 0) {
3926         LOGD("See more is not supported");
3927         return NO_ERROR;
3928     }
3929     const char *str = params.get(KEY_QC_SEE_MORE);
3930     const char *prev_str = get(KEY_QC_SEE_MORE);
3931     LOGH("str =%s & prev_str =%s", str, prev_str);
3932     if (str != NULL) {
3933         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3934             m_bNeedRestart = true;
3935             return setSeeMore(str);
3936         }
3937     }
3938     return NO_ERROR;
3939 }
3940 
3941 /*===========================================================================
3942  * FUNCTION   : setNoiseReductionMode
3943  *
3944  * DESCRIPTION: set noise reduction mode from user setting
3945  *
3946  * PARAMETERS :
3947  *   @params  : user setting parameters
3948  *
3949  * RETURN     : int32_t type of status
3950  *              NO_ERROR  -- success
3951  *              none-zero failure code
3952  *==========================================================================*/
setNoiseReductionMode(const QCameraParameters & params)3953 int32_t QCameraParameters::setNoiseReductionMode(const QCameraParameters& params)
3954 {
3955     if ((m_pCapability->qcom_supported_feature_mask & CAM_QTI_FEATURE_SW_TNR) == 0) {
3956         LOGD("SW TNR is not supported");
3957         return NO_ERROR;
3958     }
3959     const char *str = params.get(KEY_QC_NOISE_REDUCTION_MODE);
3960     const char *prev_str = get(KEY_QC_NOISE_REDUCTION_MODE);
3961     LOGH("str =%s & prev_str =%s", str, prev_str);
3962     if (str != NULL) {
3963         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3964             m_bNeedRestart = true;
3965             return setNoiseReductionMode(str);
3966         }
3967     }
3968     return NO_ERROR;
3969 }
3970 
3971 /*===========================================================================
3972  * FUNCTION   : setStillMore
3973  *
3974  * DESCRIPTION: set stillmore from user setting
3975  *
3976  * PARAMETERS :
3977  *   @params  : user setting parameters
3978  *
3979  * RETURN     : int32_t type of status
3980  *              NO_ERROR  -- success
3981  *              none-zero failure code
3982  *==========================================================================*/
setStillMore(const QCameraParameters & params)3983 int32_t QCameraParameters::setStillMore(const QCameraParameters& params)
3984 {
3985     if ((m_pCapability->qcom_supported_feature_mask &
3986             CAM_QCOM_FEATURE_STILLMORE) == 0) {
3987         LOGD("Stillmore is not supported");
3988         return NO_ERROR;
3989     }
3990     const char *str = params.get(KEY_QC_STILL_MORE);
3991     const char *prev_str = get(KEY_QC_STILL_MORE);
3992     LOGH("str =%s & prev_str =%s", str, prev_str);
3993     if (str != NULL) {
3994         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
3995             m_bNeedRestart = true;
3996             return setStillMore(str);
3997         }
3998     }
3999     return NO_ERROR;
4000 }
4001 
4002 /*===========================================================================
4003  * FUNCTION   : setRedeyeReduction
4004  *
4005  * DESCRIPTION: set red eye reduction setting from user setting
4006  *
4007  * PARAMETERS :
4008  *   @params  : user setting parameters
4009  *
4010  * RETURN     : int32_t type of status
4011  *              NO_ERROR  -- success
4012  *              none-zero failure code
4013  *==========================================================================*/
setRedeyeReduction(const QCameraParameters & params)4014 int32_t QCameraParameters::setRedeyeReduction(const QCameraParameters& params)
4015 {
4016     const char *str = params.get(KEY_QC_REDEYE_REDUCTION);
4017     const char *prev_str = get(KEY_QC_REDEYE_REDUCTION);
4018     if (str != NULL) {
4019         if (prev_str == NULL ||
4020             strcmp(str, prev_str) != 0) {
4021             return setRedeyeReduction(str);
4022         }
4023     }
4024     return NO_ERROR;
4025 }
4026 
4027 /*===========================================================================
4028  * FUNCTION   : setGpsLocation
4029  *
4030  * DESCRIPTION: set GPS location information from user setting
4031  *
4032  * PARAMETERS :
4033  *   @params  : user setting parameters
4034  *
4035  * RETURN     : int32_t type of status
4036  *              NO_ERROR  -- success
4037  *              none-zero failure code
4038  *==========================================================================*/
setGpsLocation(const QCameraParameters & params)4039 int32_t QCameraParameters::setGpsLocation(const QCameraParameters& params)
4040 {
4041     const char *method = params.get(KEY_GPS_PROCESSING_METHOD);
4042     if (method) {
4043         set(KEY_GPS_PROCESSING_METHOD, method);
4044     }else {
4045         remove(KEY_GPS_PROCESSING_METHOD);
4046     }
4047 
4048     const char *latitude = params.get(KEY_GPS_LATITUDE);
4049     if (latitude) {
4050         set(KEY_GPS_LATITUDE, latitude);
4051     }else {
4052         remove(KEY_GPS_LATITUDE);
4053     }
4054 
4055     const char *latitudeRef = params.get(KEY_QC_GPS_LATITUDE_REF);
4056     if (latitudeRef) {
4057         set(KEY_QC_GPS_LATITUDE_REF, latitudeRef);
4058     }else {
4059         remove(KEY_QC_GPS_LATITUDE_REF);
4060     }
4061 
4062     const char *longitude = params.get(KEY_GPS_LONGITUDE);
4063     if (longitude) {
4064         set(KEY_GPS_LONGITUDE, longitude);
4065     }else {
4066         remove(KEY_GPS_LONGITUDE);
4067     }
4068 
4069     const char *longitudeRef = params.get(KEY_QC_GPS_LONGITUDE_REF);
4070     if (longitudeRef) {
4071         set(KEY_QC_GPS_LONGITUDE_REF, longitudeRef);
4072     }else {
4073         remove(KEY_QC_GPS_LONGITUDE_REF);
4074     }
4075 
4076     const char *altitudeRef = params.get(KEY_QC_GPS_ALTITUDE_REF);
4077     if (altitudeRef) {
4078         set(KEY_QC_GPS_ALTITUDE_REF, altitudeRef);
4079     }else {
4080         remove(KEY_QC_GPS_ALTITUDE_REF);
4081     }
4082 
4083     const char *altitude = params.get(KEY_GPS_ALTITUDE);
4084     if (altitude) {
4085         set(KEY_GPS_ALTITUDE, altitude);
4086     }else {
4087         remove(KEY_GPS_ALTITUDE);
4088     }
4089 
4090     const char *status = params.get(KEY_QC_GPS_STATUS);
4091     if (status) {
4092         set(KEY_QC_GPS_STATUS, status);
4093     } else {
4094         remove(KEY_QC_GPS_STATUS);
4095     }
4096 
4097     const char *timestamp = params.get(KEY_GPS_TIMESTAMP);
4098     if (timestamp) {
4099         set(KEY_GPS_TIMESTAMP, timestamp);
4100     }else {
4101         remove(KEY_GPS_TIMESTAMP);
4102     }
4103     return NO_ERROR;
4104 }
4105 
4106 /*===========================================================================
4107  * FUNCTION   : setNumOfSnapshot
4108  *
4109  * DESCRIPTION: set number of snapshot per shutter from user setting
4110  *
4111  * PARAMETERS : none
4112  *
4113  * RETURN     : int32_t type of status
4114  *              NO_ERROR  -- success
4115  *              none-zero failure code
4116  *==========================================================================*/
setNumOfSnapshot()4117 int32_t QCameraParameters::setNumOfSnapshot()
4118 {
4119     int nBurstNum = 1;
4120     int nExpnum = 0;
4121 
4122     const char *bracket_str = get(KEY_QC_AE_BRACKET_HDR);
4123     if (bracket_str != NULL && strlen(bracket_str) > 0) {
4124         int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
4125                 bracket_str);
4126         switch (value) {
4127         case CAM_EXP_BRACKETING_ON:
4128             {
4129                 nExpnum = 0;
4130                 const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
4131                 if ((str_val != NULL) && (strlen(str_val) > 0)) {
4132                     char prop[PROPERTY_VALUE_MAX];
4133                     memset(prop, 0, sizeof(prop));
4134                     strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
4135                     char *saveptr = NULL;
4136                     char *token = strtok_r(prop, ",", &saveptr);
4137                     while (token != NULL) {
4138                         token = strtok_r(NULL, ",", &saveptr);
4139                         nExpnum++;
4140                     }
4141                 }
4142                 if (nExpnum == 0) {
4143                     nExpnum = 1;
4144                 }
4145             }
4146             break;
4147         default:
4148             nExpnum = 1 + getNumOfExtraHDROutBufsIfNeeded();
4149             break;
4150         }
4151     }
4152 
4153     if (isUbiRefocus()) {
4154         nBurstNum = m_pCapability->refocus_af_bracketing_need.output_count + 1;
4155     }
4156 
4157     LOGH("nBurstNum = %d, nExpnum = %d", nBurstNum, nExpnum);
4158     set(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER, nBurstNum * nExpnum);
4159     return NO_ERROR;
4160 }
4161 
4162 /*===========================================================================
4163  * FUNCTION   : setRecordingHint
4164  *
4165  * DESCRIPTION: set recording hint value from user setting
4166  *
4167  * PARAMETERS :
4168  *   @params  : user setting parameters
4169  *
4170  * RETURN     : int32_t type of status
4171  *              NO_ERROR  -- success
4172  *              none-zero failure code
4173  *==========================================================================*/
setRecordingHint(const QCameraParameters & params)4174 int32_t QCameraParameters::setRecordingHint(const QCameraParameters& params)
4175 {
4176     const char * str = params.get(KEY_RECORDING_HINT);
4177     const char *prev_str = get(KEY_RECORDING_HINT);
4178     if (str != NULL) {
4179         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4180             int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
4181                     str);
4182             if(value != NAME_NOT_FOUND){
4183                 updateParamEntry(KEY_RECORDING_HINT, str);
4184                 setRecordingHintValue(value);
4185                 if (getFaceDetectionOption() == true) {
4186                     if (!fdModeInVideo()) {
4187                         setFaceDetection(value > 0 ? false : true, false);
4188                     } else {
4189                         setFaceDetection(true, false);
4190                     }
4191                 }
4192                 if (m_bDISEnabled) {
4193                     LOGH("Setting DIS value again");
4194                     setDISValue(VALUE_ENABLE);
4195                 }
4196                 return NO_ERROR;
4197             } else {
4198                 LOGE("Invalid recording hint value: %s", str);
4199                 return BAD_VALUE;
4200             }
4201         }
4202     }
4203     return NO_ERROR;
4204 }
4205 
4206 /*===========================================================================
4207  * FUNCTION   : setNoDisplayMode
4208  *
4209  * DESCRIPTION: set no display mode from user setting
4210  *
4211  * PARAMETERS :
4212  *   @params  : user setting parameters
4213  *
4214  * RETURN     : int32_t type of status
4215  *              NO_ERROR  -- success
4216  *              none-zero failure code
4217  *==========================================================================*/
setNoDisplayMode(const QCameraParameters & params)4218 int32_t QCameraParameters::setNoDisplayMode(const QCameraParameters& params)
4219 {
4220     const char *str_val  = params.get(KEY_QC_NO_DISPLAY_MODE);
4221     const char *prev_str = get(KEY_QC_NO_DISPLAY_MODE);
4222     char prop[PROPERTY_VALUE_MAX];
4223     LOGD("str_val: %s, prev_str: %s", str_val, prev_str);
4224 
4225     // Aux Camera Mode, set no display mode
4226     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
4227         if (!m_bNoDisplayMode) {
4228             set(KEY_QC_NO_DISPLAY_MODE, 1);
4229             m_bNoDisplayMode = true;
4230             m_bNeedRestart = true;
4231         }
4232         return NO_ERROR;
4233     }
4234 
4235     if(str_val && strlen(str_val) > 0) {
4236         if (prev_str == NULL || strcmp(str_val, prev_str) != 0) {
4237             m_bNoDisplayMode = atoi(str_val);
4238             set(KEY_QC_NO_DISPLAY_MODE, str_val);
4239             m_bNeedRestart = true;
4240         }
4241     } else {
4242         memset(prop, 0, sizeof(prop));
4243         property_get("persist.camera.no-display", prop, "0");
4244         m_bNoDisplayMode = atoi(prop);
4245     }
4246     LOGH("Param m_bNoDisplayMode = %d", m_bNoDisplayMode);
4247     return NO_ERROR;
4248 }
4249 
4250 /*===========================================================================
4251  * FUNCTION   : setZslMode
4252  *
4253  * DESCRIPTION: set ZSL mode 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  *==========================================================================*/
setZslMode(const QCameraParameters & params)4262 int32_t QCameraParameters::setZslMode(const QCameraParameters& params)
4263 {
4264     const char *str_val  = params.get(KEY_QC_ZSL);
4265     const char *prev_val  = get(KEY_QC_ZSL);
4266     int32_t rc = NO_ERROR;
4267 
4268     if(m_bForceZslMode) {
4269         if (!m_bZslMode) {
4270             // Force ZSL mode to ON
4271             set(KEY_QC_ZSL, VALUE_ON);
4272             setZslMode(TRUE);
4273             LOGH("ZSL Mode forced to be enabled");
4274         }
4275     } else if (str_val != NULL) {
4276         if (prev_val == NULL || strcmp(str_val, prev_val) != 0) {
4277             int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
4278                     str_val);
4279             if (value != NAME_NOT_FOUND) {
4280                 set(KEY_QC_ZSL, str_val);
4281                 rc = setZslMode(value);
4282                 // ZSL mode changed, need restart preview
4283                 m_bNeedRestart = true;
4284             } else {
4285                 LOGE("Invalid ZSL mode value: %s", str_val);
4286                 rc = BAD_VALUE;
4287             }
4288         }
4289     }
4290     return rc;
4291 }
4292 
4293 /*===========================================================================
4294  * FUNCTION   : setZslMode
4295  *
4296  * DESCRIPTION: set ZSL mode from user setting
4297  *
4298  * PARAMETERS :
4299  *   @value  : ZSL mode value
4300  *
4301  * RETURN     : int32_t type of status
4302  *              NO_ERROR  -- success
4303  *              none-zero failure code
4304  *==========================================================================*/
setZslMode(bool value)4305 int32_t QCameraParameters::setZslMode(bool value)
4306 {
4307     int32_t rc = NO_ERROR;
4308     if(m_bForceZslMode) {
4309         if (!m_bZslMode) {
4310             // Force ZSL mode to ON
4311             set(KEY_QC_ZSL, VALUE_ON);
4312             m_bZslMode_new = true;
4313             m_bZslMode = true;
4314             m_bNeedRestart = true;
4315 
4316             int32_t value = m_bForceZslMode;
4317             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
4318                 rc = BAD_VALUE;
4319             }
4320 
4321             LOGI("ZSL Mode forced to be enabled");
4322         }
4323     } else {
4324         LOGI("ZSL Mode  -> %s", m_bZslMode_new ? "Enabled" : "Disabled");
4325         m_bZslMode_new = (value > 0)? true : false;
4326         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value)) {
4327             rc = BAD_VALUE;
4328         }
4329     }
4330     LOGH("enabled: %d rc = %d", m_bZslMode_new, rc);
4331     return rc;
4332 }
4333 
4334 /*===========================================================================
4335  * FUNCTION   : updateZSLModeValue
4336  *
4337  * DESCRIPTION: update zsl mode value locally and to daemon
4338  *
4339  * PARAMETERS :
4340  *   @value   : zsl mode value
4341  *
4342  * RETURN     : int32_t type of status
4343  *              NO_ERROR  -- success
4344  *              none-zero failure code
4345  *==========================================================================*/
updateZSLModeValue(bool value)4346 int32_t QCameraParameters::updateZSLModeValue(bool value)
4347 {
4348     int32_t rc = NO_ERROR;
4349     if(initBatchUpdate(m_pParamBuf) < 0 ) {
4350         LOGE("Failed to initialize group update table");
4351         return BAD_TYPE;
4352     }
4353 
4354     rc = setZslMode(value);
4355     if (rc != NO_ERROR) {
4356         LOGE("Failed to ZSL value");
4357         return rc;
4358     }
4359 
4360     rc = commitSetBatch();
4361     if (rc != NO_ERROR) {
4362         LOGE("Failed to update recording hint");
4363         return rc;
4364     }
4365 
4366     return rc;
4367 }
4368 
4369 /*===========================================================================
4370  * FUNCTION   : setWaveletDenoise
4371  *
4372  * DESCRIPTION: set wavelet denoise value from user setting
4373  *
4374  * PARAMETERS :
4375  *   @params  : user setting parameters
4376  *
4377  * RETURN     : int32_t type of status
4378  *              NO_ERROR  -- success
4379  *              none-zero failure code
4380  *==========================================================================*/
setWaveletDenoise(const QCameraParameters & params)4381 int32_t QCameraParameters::setWaveletDenoise(const QCameraParameters& params)
4382 {
4383     const char *str = params.get(KEY_QC_DENOISE);
4384     const char *prev_str = get(KEY_QC_DENOISE);
4385     if (str != NULL) {
4386         if (prev_str == NULL ||
4387             strcmp(str, prev_str) != 0) {
4388             return setWaveletDenoise(str);
4389         }
4390     }
4391     return NO_ERROR;
4392 }
4393 
4394 /*===========================================================================
4395  * FUNCTION   : setTemporalDenoise
4396  *
4397  * DESCRIPTION: set temporal denoise value from properties
4398  *
4399  * PARAMETERS : none
4400  *
4401  * RETURN     : int32_t type of status
4402  *              NO_ERROR  -- success
4403  *              none-zero failure code
4404  *==========================================================================*/
setTemporalDenoise(const QCameraParameters & params)4405 int32_t QCameraParameters::setTemporalDenoise(const QCameraParameters& params)
4406 {
4407     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_CPP_TNR) == 0) {
4408         LOGH("TNR is not supported");
4409         return NO_ERROR;
4410     }
4411 
4412     const char *str = params.get(KEY_QC_TNR_MODE);
4413     const char *prev_str = get(KEY_QC_TNR_MODE);
4414     const char *video_str = params.get(KEY_QC_VIDEO_TNR_MODE);
4415     const char *video_prev_str = get(KEY_QC_VIDEO_TNR_MODE);
4416     char video_value[PROPERTY_VALUE_MAX];
4417     char preview_value[PROPERTY_VALUE_MAX];
4418     bool prev_video_tnr = m_bTNRVideoOn;
4419     bool prev_preview_tnr = m_bTNRPreviewOn;
4420     bool prev_snap_tnr = m_bTNRSnapshotOn;
4421 
4422     char value[PROPERTY_VALUE_MAX];
4423     memset(value, 0, sizeof(value));
4424     property_get("persist.camera.tnr_cds", value, "0");
4425     uint8_t tnr_cds = (uint8_t)atoi(value);
4426 
4427     if (m_bRecordingHint_new == true) {
4428         if (video_str) {
4429             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
4430                 if (!strcmp(video_str, VALUE_ON)) {
4431                     m_bTNRVideoOn = true;
4432                     m_bTNRPreviewOn = true;
4433                 } else {
4434                     m_bTNRVideoOn = false;
4435                     m_bTNRPreviewOn = false;
4436                 }
4437                 updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_str);
4438             } else {
4439                 return NO_ERROR;
4440             }
4441         }
4442     } else {
4443         if (str) {
4444             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
4445                 if (!strcmp(str, VALUE_ON)) {
4446                     m_bTNRPreviewOn = true;
4447                 } else {
4448                     m_bTNRPreviewOn = false;
4449                 }
4450                 updateParamEntry(KEY_QC_TNR_MODE, str);
4451             } else {
4452                 return NO_ERROR;
4453             }
4454         }
4455     }
4456 
4457     //Read setprops only if UI is not present or disabled.
4458     if ((m_bRecordingHint_new == true)
4459             && ((video_str == NULL)
4460             || (strcmp(video_str, VALUE_ON)))) {
4461         memset(video_value, 0, sizeof(video_value));
4462         property_get("persist.camera.tnr.video", video_value, VALUE_OFF);
4463         if (!strcmp(video_value, VALUE_ON)) {
4464             m_bTNRVideoOn = true;
4465         } else {
4466             m_bTNRVideoOn = false;
4467         }
4468         updateParamEntry(KEY_QC_VIDEO_TNR_MODE, video_value);
4469 
4470         memset(preview_value, 0, sizeof(preview_value));
4471         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
4472         if (!strcmp(preview_value, VALUE_ON)) {
4473             m_bTNRPreviewOn = true;
4474         } else {
4475             m_bTNRPreviewOn = false;
4476         }
4477         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
4478     } else if ((m_bRecordingHint_new != true)
4479             && ((str == NULL) || (strcmp(str, VALUE_ON)))) {
4480         memset(preview_value, 0, sizeof(preview_value));
4481         property_get("persist.camera.tnr.preview", preview_value, VALUE_OFF);
4482         if (!strcmp(preview_value, VALUE_ON)) {
4483             m_bTNRPreviewOn = true;
4484         } else {
4485             m_bTNRPreviewOn = false;
4486         }
4487         updateParamEntry(KEY_QC_TNR_MODE, preview_value);
4488     }
4489 
4490     memset(value, 0, sizeof(value));
4491     property_get("persist.camera.tnr.snapshot", value, VALUE_OFF);
4492     if (!strcmp(value, VALUE_ON)) {
4493         m_bTNRSnapshotOn = true;
4494         LOGD("TNR enabled for SNAPSHOT stream");
4495     } else {
4496         m_bTNRSnapshotOn = false;
4497     }
4498 
4499     cam_denoise_param_t temp;
4500     memset(&temp, 0, sizeof(temp));
4501     if (m_bTNRVideoOn || m_bTNRPreviewOn || m_bTNRSnapshotOn) {
4502         temp.denoise_enable = 1;
4503         temp.process_plates = getDenoiseProcessPlate(
4504                 CAM_INTF_PARM_TEMPORAL_DENOISE);
4505 
4506         if (!tnr_cds) {
4507             int32_t cds_mode = lookupAttr(CDS_MODES_MAP,
4508                     PARAM_MAP_SIZE(CDS_MODES_MAP), CDS_MODE_OFF);
4509 
4510             if (cds_mode != NAME_NOT_FOUND) {
4511                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, CDS_MODE_OFF);
4512                 if (m_bTNRPreviewOn) {
4513                     updateParamEntry(KEY_QC_CDS_MODE, CDS_MODE_OFF);
4514                 }
4515                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
4516                         CAM_INTF_PARM_CDS_MODE, cds_mode)) {
4517                     LOGE("Failed CDS MODE to update table");
4518                     return BAD_VALUE;
4519                 }
4520                 LOGD("CDS is set to = %s when TNR is enabled",
4521                          CDS_MODE_OFF);
4522                 mCds_mode = cds_mode;
4523             } else {
4524                 LOGE("Invalid argument for video CDS MODE %d",
4525                          cds_mode);
4526             }
4527         } else {
4528             LOGH("Enabled TNR with CDS");
4529         }
4530     }
4531 
4532     if ((m_bTNRVideoOn != prev_video_tnr)
4533             || (m_bTNRPreviewOn != prev_preview_tnr)
4534             || (prev_snap_tnr != m_bTNRSnapshotOn)) {
4535         LOGD("TNR enabled = %d, plates = %d",
4536                 temp.denoise_enable, temp.process_plates);
4537         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
4538                 CAM_INTF_PARM_TEMPORAL_DENOISE, temp)) {
4539             return BAD_VALUE;
4540         }
4541     }
4542 
4543     return NO_ERROR;
4544 }
4545 
4546 /*===========================================================================
4547  * FUNCTION   : setCameraMode
4548  *
4549  * DESCRIPTION: set camera mode from user setting
4550  *
4551  * PARAMETERS :
4552  *   @params  : user setting parameters
4553  *
4554  * RETURN     : int32_t type of status
4555  *              NO_ERROR  -- success
4556  *              none-zero failure code
4557  *==========================================================================*/
setCameraMode(const QCameraParameters & params)4558 int32_t QCameraParameters::setCameraMode(const QCameraParameters& params)
4559 {
4560     const char *str = params.get(KEY_QC_CAMERA_MODE);
4561     if (str != NULL) {
4562         set(KEY_QC_CAMERA_MODE, str);
4563     } else {
4564         remove(KEY_QC_CAMERA_MODE);
4565     }
4566     return NO_ERROR;
4567 }
4568 
4569 /*===========================================================================
4570  * FUNCTION   : setSceneSelectionMode
4571  *
4572  * DESCRIPTION: set scene selection mode from user setting
4573  *
4574  * PARAMETERS :
4575  *   @params  : user setting parameters
4576  *
4577  * RETURN     : int32_t type of status
4578  *              NO_ERROR  -- success
4579  *              none-zero failure code
4580  *==========================================================================*/
setSceneSelectionMode(const QCameraParameters & params)4581 int32_t QCameraParameters::setSceneSelectionMode(const QCameraParameters& params)
4582 {
4583     const char *str = params.get(KEY_QC_SCENE_SELECTION);
4584     const char *prev_str = get(KEY_QC_SCENE_SELECTION);
4585     if (NULL != str) {
4586         if ((NULL == prev_str) || (strcmp(str, prev_str) != 0)) {
4587             int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
4588                     PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
4589             if (value != NAME_NOT_FOUND) {
4590                 LOGD("Setting selection value %s", str);
4591                 if (value && m_bZslMode_new) {
4592                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4593                     m_bNeedRestart = true;
4594                     m_bSceneSelection = true;
4595                 } else if (!value) {
4596                     updateParamEntry(KEY_QC_SCENE_SELECTION, str);
4597                     m_bNeedRestart = true;
4598                     m_bSceneSelection = false;
4599                 } else {
4600                     LOGE("Trying to enable scene selection in non ZSL mode!!!");
4601                     return BAD_VALUE;
4602                 }
4603             } else {
4604                 LOGE("Trying to configure invalid scene selection value: %s",
4605                         str);
4606                 return BAD_VALUE;
4607             }
4608         }
4609     }
4610 
4611     return NO_ERROR;
4612 }
4613 
4614 /*===========================================================================
4615  * FUNCTION   : setSelectedScene
4616  *
4617  * DESCRIPTION: select specific scene
4618  *
4619  * PARAMETERS :
4620  *   @scene   : scene mode
4621  *
4622  * RETURN     : int32_t type of status
4623  *              NO_ERROR  -- success
4624  *              none-zero failure code
4625  *==========================================================================*/
setSelectedScene(cam_scene_mode_type scene)4626 int32_t QCameraParameters::setSelectedScene(cam_scene_mode_type scene)
4627 {
4628     Mutex::Autolock l(m_SceneSelectLock);
4629     m_SelectedScene = scene;
4630     return NO_ERROR;
4631 }
4632 
4633 /*===========================================================================
4634  * FUNCTION   : getSelectedScene
4635  *
4636  * DESCRIPTION: get selected scene
4637  *
4638  * PARAMETERS :
4639  *
4640  * RETURN     : currently selected scene
4641  *==========================================================================*/
getSelectedScene()4642 cam_scene_mode_type QCameraParameters::getSelectedScene()
4643 {
4644     Mutex::Autolock l(m_SceneSelectLock);
4645     return m_SelectedScene;
4646 }
4647 
4648 /*==========================================================
4649  * FUNCTION   : setRdiMode
4650  *
4651  * DESCRIPTION: set Rdi mode from user setting
4652  *
4653  * PARAMETERS :
4654  *   @params  : user setting parameters
4655  *
4656  * RETURN     : int32_t type of status
4657  *              NO_ERROR  -- success
4658  *              none-zero failure code
4659  *===========================================================*/
setRdiMode(const QCameraParameters & params)4660 int32_t QCameraParameters::setRdiMode(const QCameraParameters& params)
4661 {
4662     const char *str = params.get(KEY_QC_RDI_MODE);
4663     const char *prev_str = get(KEY_QC_RDI_MODE);
4664     char prop[PROPERTY_VALUE_MAX];
4665     memset(prop, 0, sizeof(prop));
4666 
4667     property_get("persist.camera.rdi.mode", prop, VALUE_DISABLE);
4668     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4669         LOGD("RDI mode set to %s", str);
4670         setRdiMode(str);
4671     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4672         LOGD("RDI mode set to prop: %s", prop);
4673         setRdiMode(prop);
4674     }
4675     return NO_ERROR;
4676 }
4677 
4678 /*==========================================================
4679  * FUNCTION   : setSecureMode
4680  *
4681  * DESCRIPTION: set secure mode from user setting
4682  *
4683  * PARAMETERS :
4684  *   @params  : user setting parameters
4685  *
4686  * RETURN     : int32_t type of status
4687  *              NO_ERROR  -- success
4688  *              none-zero failure code
4689  *===========================================================*/
4690 
setSecureMode(const QCameraParameters & params)4691 int32_t QCameraParameters::setSecureMode(const QCameraParameters& params)
4692 {
4693     const char *str = params.get(KEY_QC_SECURE_MODE);
4694     const char *prev_str = get(KEY_QC_SECURE_MODE);
4695     char prop[PROPERTY_VALUE_MAX];
4696     memset(prop, 0, sizeof(prop));
4697 
4698     property_get("persist.camera.secure.mode", prop, VALUE_DISABLE);
4699     if ((str != NULL) && (prev_str == NULL || strcmp(str, prev_str) != 0)) {
4700         LOGD("Secure mode set to KEY: %s", str);
4701         setSecureMode(str);
4702     } else if (prev_str == NULL || strcmp(prev_str, prop) != 0 ) {
4703         LOGD("Secure mode set to prop: %s", prop);
4704         setSecureMode(prop);
4705     }
4706     return NO_ERROR;
4707 }
4708 
4709 /*===========================================================================
4710  * FUNCTION   : setZslAttributes
4711  *
4712  * DESCRIPTION: set ZSL related attributes from user setting
4713  *
4714  * PARAMETERS :
4715  *   @params  : user setting parameters
4716  *
4717  * RETURN     : int32_t type of status
4718  *              NO_ERROR  -- success
4719  *              none-zero failure code
4720  *==========================================================================*/
setZslAttributes(const QCameraParameters & params)4721 int32_t QCameraParameters::setZslAttributes(const QCameraParameters& params)
4722 {
4723     // TODO: may switch to pure param instead of sysprop
4724     char prop[PROPERTY_VALUE_MAX];
4725 
4726     const char *str = params.get(KEY_QC_ZSL_BURST_INTERVAL);
4727     if (str != NULL) {
4728         set(KEY_QC_ZSL_BURST_INTERVAL, str);
4729     } else {
4730         memset(prop, 0, sizeof(prop));
4731         property_get("persist.camera.zsl.interval", prop, "1");
4732         set(KEY_QC_ZSL_BURST_INTERVAL, prop);
4733         LOGH("burst interval: %s", prop);
4734     }
4735 
4736     str = params.get(KEY_QC_ZSL_BURST_LOOKBACK);
4737     if (str != NULL) {
4738         set(KEY_QC_ZSL_BURST_LOOKBACK, str);
4739     } else {
4740         memset(prop, 0, sizeof(prop));
4741         property_get("persist.camera.zsl.backlookcnt", prop, "2");
4742         uint32_t look_back_cnt = atoi(prop);
4743         if (m_relCamSyncInfo.is_frame_sync_enabled) {
4744             look_back_cnt += EXTRA_FRAME_SYNC_BUFFERS;
4745         }
4746         set(KEY_QC_ZSL_BURST_LOOKBACK, look_back_cnt);
4747         LOGH("look back count: %s", prop);
4748     }
4749 
4750     str = params.get(KEY_QC_ZSL_QUEUE_DEPTH);
4751     if (str != NULL) {
4752         set(KEY_QC_ZSL_QUEUE_DEPTH, str);
4753     } else {
4754         memset(prop, 0, sizeof(prop));
4755         property_get("persist.camera.zsl.queuedepth", prop, "2");
4756         uint32_t queue_depth = atoi(prop);
4757         if (m_relCamSyncInfo.is_frame_sync_enabled) {
4758             queue_depth += EXTRA_FRAME_SYNC_BUFFERS;
4759         }
4760         set(KEY_QC_ZSL_QUEUE_DEPTH, queue_depth);
4761         LOGH("queue depth: %s", prop);
4762     }
4763 
4764     return NO_ERROR;
4765 }
4766 
4767 /*===========================================================================
4768  * FUNCTION   : setFlip
4769  *
4770  * DESCRIPTION: set preview/ video/ picture flip mode from user setting
4771  *
4772  * PARAMETERS :
4773  *   @params  : user setting parameters
4774  *
4775  * RETURN     : int32_t type of status
4776  *              NO_ERROR  -- success
4777  *              none-zero failure code
4778  *==========================================================================*/
setFlip(const QCameraParameters & params)4779 int32_t QCameraParameters::setFlip(const QCameraParameters& params)
4780 {
4781     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) == 0) {
4782         LOGH("flip is not supported.");
4783         return NO_ERROR;
4784     }
4785 
4786     //check preview flip setting
4787     const char *str = params.get(KEY_QC_PREVIEW_FLIP);
4788     const char *prev_val = get(KEY_QC_PREVIEW_FLIP);
4789     if(str != NULL){
4790         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4791             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4792             if(value != NAME_NOT_FOUND){
4793                 set(KEY_QC_PREVIEW_FLIP, str);
4794                 m_bPreviewFlipChanged = true;
4795             }
4796         }
4797     }
4798 
4799     // check video filp setting
4800     str = params.get(KEY_QC_VIDEO_FLIP);
4801     prev_val = get(KEY_QC_VIDEO_FLIP);
4802     if(str != NULL){
4803         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4804             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4805             if(value != NAME_NOT_FOUND){
4806                 set(KEY_QC_VIDEO_FLIP, str);
4807                 m_bVideoFlipChanged = true;
4808             }
4809         }
4810     }
4811 
4812     // check picture filp setting
4813     str = params.get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
4814     prev_val = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
4815     if(str != NULL){
4816         if (prev_val == NULL || strcmp(str, prev_val) != 0) {
4817             int32_t value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
4818             if(value != NAME_NOT_FOUND){
4819                 set(KEY_QC_SNAPSHOT_PICTURE_FLIP, str);
4820                 m_bSnapshotFlipChanged = true;
4821             }
4822         }
4823     }
4824 
4825     return NO_ERROR;
4826 }
4827 
4828 /*===========================================================================
4829  * FUNCTION   : setSnapshotFDReq
4830  *
4831  * DESCRIPTION: set requirement of Face Detection Metadata in Snapshot mode.
4832  *
4833  * PARAMETERS :
4834  *   @params  : user setting parameters
4835  *
4836  * RETURN     : int32_t type of status
4837  *              NO_ERROR  -- success
4838  *              none-zero failure code
4839  *==========================================================================*/
setSnapshotFDReq(const QCameraParameters & params)4840 int32_t QCameraParameters::setSnapshotFDReq(const QCameraParameters& params)
4841 {
4842     char prop[PROPERTY_VALUE_MAX];
4843     const char *str = params.get(KEY_QC_SNAPSHOT_FD_DATA);
4844 
4845     if(str != NULL){
4846         set(KEY_QC_SNAPSHOT_FD_DATA, str);
4847     }else{
4848         memset(prop, 0, sizeof(prop));
4849         property_get("persist.camera.snapshot.fd", prop, "0");
4850         set(KEY_QC_SNAPSHOT_FD_DATA, prop);
4851     }
4852     return NO_ERROR;
4853 }
4854 
4855 /*===========================================================================
4856  * FUNCTION   : setMobicat
4857  *
4858  * DESCRIPTION: set Mobicat on/off.
4859  *
4860  * PARAMETERS :
4861  *   @params  : user setting parameters
4862  *
4863  * RETURN     : int32_t type of status
4864  *              NO_ERROR  -- success
4865  *              none-zero failure code
4866  *==========================================================================*/
setMobicat(const QCameraParameters &)4867 int32_t QCameraParameters::setMobicat(const QCameraParameters& )
4868 {
4869     char value [PROPERTY_VALUE_MAX];
4870     property_get("persist.camera.mobicat", value, "0");
4871     int32_t ret = NO_ERROR;
4872     uint8_t enableMobi = (uint8_t)atoi(value);
4873 
4874     if (enableMobi) {
4875         tune_cmd_t tune_cmd;
4876         tune_cmd.type = 2;
4877         tune_cmd.module = 0;
4878         tune_cmd.value = 1;
4879         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_VFE_COMMAND, tune_cmd)) {
4880             return BAD_VALUE;
4881         }
4882         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SET_PP_COMMAND, tune_cmd)) {
4883             ret = BAD_VALUE;
4884         }
4885     }
4886     m_MobiMask = enableMobi;
4887 
4888     return ret;
4889 }
4890 
4891 /*===========================================================================
4892  * FUNCTION   : setLongshotParam
4893  *
4894  * DESCRIPTION: set Longshot on/off.
4895  *
4896  * PARAMETERS :
4897  *   @params  : user setting parameters
4898  *
4899  * RETURN     : int32_t type of status
4900  *              NO_ERROR  -- success
4901  *              none-zero failure code
4902  *==========================================================================*/
setLongshotParam(const QCameraParameters & params)4903 int32_t QCameraParameters::setLongshotParam(const QCameraParameters& params)
4904 {
4905     const char *str = params.get(KEY_QC_LONG_SHOT);
4906     const char *prev_str = get(KEY_QC_LONG_SHOT);
4907 
4908     if (str != NULL) {
4909         if (prev_str == NULL || strcmp(str, prev_str) != 0) {
4910             set(KEY_QC_LONG_SHOT, str);
4911             if (!strcmp(str, "off")) {
4912                 if (m_bLongshotEnabled == true) {
4913                     // We restart here, to reset the FPS and no
4914                     // of buffers as per the requirement of single snapshot usecase.
4915                     m_bNeedRestart = true;
4916                 }
4917                 m_bLongshotEnabled = false;
4918             }
4919         }
4920     }
4921 
4922     return NO_ERROR;
4923 }
4924 
4925 /*===========================================================================
4926  * FUNCTION   : checkFeatureConcurrency
4927  *
4928  * DESCRIPTION: check if there is a feature concurrency issue with advanced
4929  *              camera features
4930  *
4931  * PARAMETERS : None
4932  *
4933  * RETURN     : int32_t type of status
4934  *              NO_ERROR  -- success
4935  *              none-zero failure code
4936  *==========================================================================*/
checkFeatureConcurrency()4937 int32_t QCameraParameters::checkFeatureConcurrency()
4938 {
4939     int32_t rc = NO_ERROR;
4940     uint32_t advancedFeatEnableBit = 0;
4941 
4942     if (isStillMoreEnabled()) {
4943         advancedFeatEnableBit |= CAM_QCOM_FEATURE_STILLMORE;
4944     }
4945     if (isHDREnabled()) {
4946         advancedFeatEnableBit |= CAM_QCOM_FEATURE_HDR;
4947     }
4948     if (isChromaFlashEnabled()) {
4949         advancedFeatEnableBit |= CAM_QCOM_FEATURE_CHROMA_FLASH;
4950     }
4951     if (isUbiFocusEnabled()) {
4952         advancedFeatEnableBit |= CAM_QCOM_FEATURE_UBIFOCUS;
4953     }
4954     if (isTruePortraitEnabled()) {
4955         advancedFeatEnableBit |= CAM_QCOM_FEATURE_TRUEPORTRAIT;
4956     }
4957     if (isOptiZoomEnabled()) {
4958         advancedFeatEnableBit |= CAM_QCOM_FEATURE_OPTIZOOM;
4959     }
4960     if (isUbiRefocus()) {
4961         advancedFeatEnableBit |= CAM_QCOM_FEATURE_REFOCUS;
4962     }
4963 
4964    if (m_bLongshotEnabled && advancedFeatEnableBit) {
4965         LOGE("Failed Longshot mode bit 0x%x",
4966                     advancedFeatEnableBit);
4967         rc = BAD_TYPE;
4968         return rc;
4969     }
4970 
4971     if(m_bRecordingHint_new) {
4972         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_STILLMORE;
4973 
4974         if (advancedFeatEnableBit) {
4975             LOGE("Failed recording mode bit 0x%x",
4976                     advancedFeatEnableBit);
4977             rc = BAD_TYPE;
4978         }
4979     } else if (m_bZslMode_new) {
4980         /* ZSL mode check if 2 bits are set */
4981         if (advancedFeatEnableBit & (advancedFeatEnableBit - 1)) {
4982             LOGE("Failed ZSL mode bit 0x%x", advancedFeatEnableBit);
4983             rc = BAD_TYPE;
4984         }
4985     } else { /* non-ZSL mode */
4986         advancedFeatEnableBit &= ~CAM_QCOM_FEATURE_HDR;
4987 
4988         /* non-ZSL mode check if 1 bit is set */
4989         if (advancedFeatEnableBit) {
4990             LOGE("Failed non-ZSL mode bit 0x%x", advancedFeatEnableBit);
4991             rc = BAD_TYPE;
4992         }
4993     }
4994     LOGI("Advance feature enabled 0x%x", advancedFeatEnableBit);
4995     return rc;
4996 }
4997 
4998 /*===========================================================================
4999  * FUNCTION   : updateParameters
5000  *
5001  * DESCRIPTION: update parameters from user setting
5002  *
5003  * PARAMETERS :
5004  *   @params  : user setting parameters
5005  *   @needRestart : [output] if preview need restart upon setting changes
5006  *
5007  * RETURN     : int32_t type of status
5008  *              NO_ERROR  -- success
5009  *              none-zero failure code
5010  *==========================================================================*/
updateParameters(const String8 & p,bool & needRestart)5011 int32_t QCameraParameters::updateParameters(const String8& p,
5012         bool &needRestart)
5013 {
5014     int32_t final_rc = NO_ERROR;
5015     int32_t rc;
5016     m_bNeedRestart = false;
5017     QCameraParameters params(p);
5018 
5019     if(initBatchUpdate(m_pParamBuf) < 0 ) {
5020         LOGE("Failed to initialize group update table");
5021         rc = BAD_TYPE;
5022         goto UPDATE_PARAM_DONE;
5023     }
5024 
5025     if ((rc = setPreviewSize(params)))                  final_rc = rc;
5026     if ((rc = setVideoSize(params)))                    final_rc = rc;
5027     if ((rc = setPictureSize(params)))                  final_rc = rc;
5028     if ((rc = setPreviewFormat(params)))                final_rc = rc;
5029     if ((rc = setPictureFormat(params)))                final_rc = rc;
5030     if ((rc = setJpegQuality(params)))                  final_rc = rc;
5031     if ((rc = setOrientation(params)))                  final_rc = rc;
5032     if ((rc = setRotation(params)))                     final_rc = rc;
5033     if ((rc = setVideoRotation(params)))                final_rc = rc;
5034     if ((rc = setNoDisplayMode(params)))                final_rc = rc;
5035     if ((rc = setZslMode(params)))                      final_rc = rc;
5036     if ((rc = setZslAttributes(params)))                final_rc = rc;
5037     if ((rc = setCameraMode(params)))                   final_rc = rc;
5038     if ((rc = setSceneSelectionMode(params)))           final_rc = rc;
5039     if ((rc = setRecordingHint(params)))                final_rc = rc;
5040     if ((rc = setRdiMode(params)))                      final_rc = rc;
5041     if ((rc = setSecureMode(params)))                   final_rc = rc;
5042     if ((rc = setPreviewFrameRate(params)))             final_rc = rc;
5043     if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
5044     if ((rc = setAutoExposure(params)))                 final_rc = rc;
5045     if ((rc = setEffect(params)))                       final_rc = rc;
5046     if ((rc = setBrightness(params)))                   final_rc = rc;
5047     if ((rc = setZoom(params)))                         final_rc = rc;
5048     if ((rc = setSharpness(params)))                    final_rc = rc;
5049     if ((rc = setSaturation(params)))                   final_rc = rc;
5050     if ((rc = setContrast(params)))                     final_rc = rc;
5051     if ((rc = setFocusMode(params)))                    final_rc = rc;
5052     if ((rc = setISOValue(params)))                     final_rc = rc;
5053     if ((rc = setContinuousISO(params)))                final_rc = rc;
5054     if ((rc = setExposureTime(params)))                 final_rc = rc;
5055     if ((rc = setSkinToneEnhancement(params)))          final_rc = rc;
5056     if ((rc = setFlash(params)))                        final_rc = rc;
5057     if ((rc = setAecLock(params)))                      final_rc = rc;
5058     if ((rc = setAwbLock(params)))                      final_rc = rc;
5059     if ((rc = setLensShadeValue(params)))               final_rc = rc;
5060     if ((rc = setMCEValue(params)))                     final_rc = rc;
5061     if ((rc = setDISValue(params)))                     final_rc = rc;
5062     if ((rc = setAntibanding(params)))                  final_rc = rc;
5063     if ((rc = setExposureCompensation(params)))         final_rc = rc;
5064     if ((rc = setWhiteBalance(params)))                 final_rc = rc;
5065     if ((rc = setHDRMode(params)))                      final_rc = rc;
5066     if ((rc = setHDRNeed1x(params)))                    final_rc = rc;
5067     if ((rc = setManualWhiteBalance(params)))           final_rc = rc;
5068     if ((rc = setSceneMode(params)))                    final_rc = rc;
5069     if ((rc = setFocusAreas(params)))                   final_rc = rc;
5070     if ((rc = setFocusPosition(params)))                final_rc = rc;
5071     if ((rc = setMeteringAreas(params)))                final_rc = rc;
5072     if ((rc = setSelectableZoneAf(params)))             final_rc = rc;
5073     if ((rc = setRedeyeReduction(params)))              final_rc = rc;
5074     if ((rc = setAEBracket(params)))                    final_rc = rc;
5075     if ((rc = setAutoHDR(params)))                      final_rc = rc;
5076     if ((rc = setGpsLocation(params)))                  final_rc = rc;
5077     if ((rc = setWaveletDenoise(params)))               final_rc = rc;
5078     if ((rc = setFaceRecognition(params)))              final_rc = rc;
5079     if ((rc = setFlip(params)))                         final_rc = rc;
5080     if ((rc = setVideoHDR(params)))                     final_rc = rc;
5081     if ((rc = setVtEnable(params)))                     final_rc = rc;
5082     if ((rc = setAFBracket(params)))                    final_rc = rc;
5083     if ((rc = setReFocus(params)))                      final_rc = rc;
5084     if ((rc = setChromaFlash(params)))                  final_rc = rc;
5085     if ((rc = setTruePortrait(params)))                 final_rc = rc;
5086     if ((rc = setOptiZoom(params)))                     final_rc = rc;
5087     if ((rc = setBurstLEDOnPeriod(params)))             final_rc = rc;
5088     if ((rc = setRetroActiveBurstNum(params)))          final_rc = rc;
5089     if ((rc = setSnapshotFDReq(params)))                final_rc = rc;
5090     if ((rc = setTintlessValue(params)))                final_rc = rc;
5091     if ((rc = setCDSMode(params)))                      final_rc = rc;
5092     if ((rc = setTemporalDenoise(params)))              final_rc = rc;
5093     if ((rc = setCacheVideoBuffers(params)))            final_rc = rc;
5094     if ((rc = setInitialExposureIndex(params)))         final_rc = rc;
5095     if ((rc = setInstantCapture(params)))               final_rc = rc;
5096     if ((rc = setInstantAEC(params)))                   final_rc = rc;
5097 
5098     // update live snapshot size after all other parameters are set
5099     if ((rc = setLiveSnapshotSize(params)))             final_rc = rc;
5100     if ((rc = setJpegThumbnailSize(params)))            final_rc = rc;
5101     if ((rc = setStatsDebugMask()))                     final_rc = rc;
5102     if ((rc = setPAAF()))                               final_rc = rc;
5103     if ((rc = setMobicat(params)))                      final_rc = rc;
5104     if ((rc = setSeeMore(params)))                      final_rc = rc;
5105     if ((rc = setStillMore(params)))                    final_rc = rc;
5106     if ((rc = setCustomParams(params)))                 final_rc = rc;
5107     if ((rc = setNoiseReductionMode(params)))           final_rc = rc;
5108 
5109     if ((rc = setLongshotParam(params)))                final_rc = rc;
5110     if ((rc = setDualLedCalibration(params)))           final_rc = rc;
5111 
5112     setVideoBatchSize();
5113     setLowLightCapture();
5114 
5115     if ((rc = updateFlash(false)))                      final_rc = rc;
5116 
5117 #ifdef TARGET_TS_MAKEUP
5118     if (params.get(KEY_TS_MAKEUP) != NULL) {
5119         set(KEY_TS_MAKEUP,params.get(KEY_TS_MAKEUP));
5120         final_rc = rc;
5121     }
5122     if (params.get(KEY_TS_MAKEUP_WHITEN) != NULL) {
5123         set(KEY_TS_MAKEUP_WHITEN,params.get(KEY_TS_MAKEUP_WHITEN));
5124         final_rc = rc;
5125     }
5126     if (params.get(KEY_TS_MAKEUP_CLEAN) != NULL) {
5127         set(KEY_TS_MAKEUP_CLEAN,params.get(KEY_TS_MAKEUP_CLEAN));
5128         final_rc = rc;
5129     }
5130 #endif
5131 
5132     if ((rc = setAdvancedCaptureMode()))                final_rc = rc;
5133 UPDATE_PARAM_DONE:
5134     needRestart = m_bNeedRestart;
5135     return final_rc;
5136 }
5137 
5138 /*===========================================================================
5139  * FUNCTION   : commitParameters
5140  *
5141  * DESCRIPTION: commit parameter changes to backend
5142  *
5143  * PARAMETERS : none
5144  *
5145  * RETURN     : int32_t type of status
5146  *              NO_ERROR  -- success
5147  *              none-zero failure code
5148  *==========================================================================*/
commitParameters()5149 int32_t QCameraParameters::commitParameters()
5150 {
5151     return commitSetBatch();
5152 }
5153 
5154 /*===========================================================================
5155  * FUNCTION   : initDefaultParameters
5156  *
5157  * DESCRIPTION: initialize default parameters for the first time
5158  *
5159  * PARAMETERS : none
5160  *
5161  * RETURN     : int32_t type of status
5162  *              NO_ERROR  -- success
5163  *              none-zero failure code
5164  *==========================================================================*/
initDefaultParameters()5165 int32_t QCameraParameters::initDefaultParameters()
5166 {
5167     if(initBatchUpdate(m_pParamBuf) < 0 ) {
5168         LOGE("Failed to initialize group update table");
5169         return BAD_TYPE;
5170     }
5171     int32_t hal_version = CAM_HAL_V1;
5172     ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HAL_VERSION, hal_version);
5173 
5174     /*************************Initialize Values******************************/
5175     // Set read only parameters from camera capability
5176     set(KEY_SMOOTH_ZOOM_SUPPORTED,
5177         m_pCapability->smooth_zoom_supported? VALUE_TRUE : VALUE_FALSE);
5178     set(KEY_ZOOM_SUPPORTED,
5179         m_pCapability->zoom_supported? VALUE_TRUE : VALUE_FALSE);
5180     set(KEY_VIDEO_SNAPSHOT_SUPPORTED,
5181         m_pCapability->video_snapshot_supported? VALUE_TRUE : VALUE_FALSE);
5182     set(KEY_VIDEO_STABILIZATION_SUPPORTED,
5183         m_pCapability->video_stablization_supported? VALUE_TRUE : VALUE_FALSE);
5184     set(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED,
5185         m_pCapability->auto_exposure_lock_supported? VALUE_TRUE : VALUE_FALSE);
5186     set(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED,
5187         m_pCapability->auto_wb_lock_supported? VALUE_TRUE : VALUE_FALSE);
5188     set(KEY_QC_SUPPORTED_CAMERA_FEATURES,
5189             (int)m_pCapability->qcom_supported_feature_mask);
5190     set(KEY_MAX_NUM_DETECTED_FACES_HW, m_pCapability->max_num_roi);
5191     set(KEY_MAX_NUM_DETECTED_FACES_SW, m_pCapability->max_num_roi);
5192     set(KEY_QC_MAX_NUM_REQUESTED_FACES, m_pCapability->max_num_roi);
5193     // Set focal length, horizontal view angle, and vertical view angle
5194     setFloat(KEY_FOCAL_LENGTH, m_pCapability->focal_length);
5195     setFloat(KEY_HORIZONTAL_VIEW_ANGLE, m_pCapability->hor_view_angle);
5196     setFloat(KEY_VERTICAL_VIEW_ANGLE, m_pCapability->ver_view_angle);
5197     set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
5198     set(KEY_QC_AUTO_HDR_SUPPORTED,
5199         (m_pCapability->auto_hdr_supported)? VALUE_TRUE : VALUE_FALSE);
5200     // Set supported preview sizes
5201     if (m_pCapability->preview_sizes_tbl_cnt > 0 &&
5202         m_pCapability->preview_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5203         String8 previewSizeValues = createSizesString(
5204                 m_pCapability->preview_sizes_tbl, m_pCapability->preview_sizes_tbl_cnt);
5205         set(KEY_SUPPORTED_PREVIEW_SIZES, previewSizeValues.string());
5206         LOGH("supported preview sizes: %s", previewSizeValues.string());
5207         // Set default preview size
5208         CameraParameters::setPreviewSize(m_pCapability->preview_sizes_tbl[0].width,
5209                                          m_pCapability->preview_sizes_tbl[0].height);
5210     } else {
5211         LOGW("supported preview sizes cnt is 0 or exceeds max!!!");
5212     }
5213 
5214     // Set supported video sizes
5215     if (m_pCapability->video_sizes_tbl_cnt > 0 &&
5216         m_pCapability->video_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5217         String8 videoSizeValues = createSizesString(
5218                 m_pCapability->video_sizes_tbl, m_pCapability->video_sizes_tbl_cnt);
5219         set(KEY_SUPPORTED_VIDEO_SIZES, videoSizeValues.string());
5220         LOGH("supported video sizes: %s", videoSizeValues.string());
5221         // Set default video size
5222         CameraParameters::setVideoSize(m_pCapability->video_sizes_tbl[0].width,
5223                                        m_pCapability->video_sizes_tbl[0].height);
5224 
5225         //Set preferred Preview size for video
5226         String8 vSize = createSizesString(&m_pCapability->preview_sizes_tbl[0], 1);
5227         set(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, vSize.string());
5228     } else {
5229         LOGW("supported video sizes cnt is 0 or exceeds max!!!");
5230     }
5231 
5232     // Set supported picture sizes
5233     if (m_pCapability->picture_sizes_tbl_cnt > 0 &&
5234         m_pCapability->picture_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5235         String8 pictureSizeValues = createSizesString(
5236                 m_pCapability->picture_sizes_tbl, m_pCapability->picture_sizes_tbl_cnt);
5237         set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
5238         LOGH("supported pic sizes: %s", pictureSizeValues.string());
5239         // Set default picture size to the smallest resolution
5240         CameraParameters::setPictureSize(
5241            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].width,
5242            m_pCapability->picture_sizes_tbl[m_pCapability->picture_sizes_tbl_cnt-1].height);
5243     } else {
5244         LOGW("supported picture sizes cnt is 0 or exceeds max!!!");
5245     }
5246 
5247     // Need check if scale should be enabled
5248     if (m_pCapability->scale_picture_sizes_cnt > 0 &&
5249         m_pCapability->scale_picture_sizes_cnt <= MAX_SCALE_SIZES_CNT){
5250         //get scale size, enable scaling. And re-set picture size table with scale sizes
5251         m_reprocScaleParam.setScaleEnable(true);
5252         int rc_s = m_reprocScaleParam.setScaleSizeTbl(
5253             m_pCapability->scale_picture_sizes_cnt, m_pCapability->scale_picture_sizes,
5254             m_pCapability->picture_sizes_tbl_cnt, m_pCapability->picture_sizes_tbl);
5255         if(rc_s == NO_ERROR){
5256             cam_dimension_t *totalSizeTbl = m_reprocScaleParam.getTotalSizeTbl();
5257             size_t totalSizeCnt = m_reprocScaleParam.getTotalSizeTblCnt();
5258             String8 pictureSizeValues = createSizesString(totalSizeTbl, totalSizeCnt);
5259             set(KEY_SUPPORTED_PICTURE_SIZES, pictureSizeValues.string());
5260             LOGH("scaled supported pic sizes: %s", pictureSizeValues.string());
5261         }else{
5262             m_reprocScaleParam.setScaleEnable(false);
5263             LOGW("reset scaled picture size table failed.");
5264         }
5265     }else{
5266         m_reprocScaleParam.setScaleEnable(false);
5267     }
5268 
5269     // Set supported thumbnail sizes
5270     String8 thumbnailSizeValues = createSizesString(
5271             THUMBNAIL_SIZES_MAP,
5272             PARAM_MAP_SIZE(THUMBNAIL_SIZES_MAP));
5273     set(KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, thumbnailSizeValues.string());
5274     // Set default thumnail size
5275     set(KEY_JPEG_THUMBNAIL_WIDTH, THUMBNAIL_SIZES_MAP[0].width);
5276     set(KEY_JPEG_THUMBNAIL_HEIGHT, THUMBNAIL_SIZES_MAP[0].height);
5277 
5278     // Set supported livesnapshot sizes
5279     if (m_pCapability->livesnapshot_sizes_tbl_cnt > 0 &&
5280         m_pCapability->livesnapshot_sizes_tbl_cnt <= MAX_SIZES_CNT) {
5281         String8 liveSnpashotSizeValues = createSizesString(
5282                 m_pCapability->livesnapshot_sizes_tbl,
5283                 m_pCapability->livesnapshot_sizes_tbl_cnt);
5284         set(KEY_QC_SUPPORTED_LIVESNAPSHOT_SIZES, liveSnpashotSizeValues.string());
5285         LOGD("supported live snapshot sizes: %s", liveSnpashotSizeValues.string());
5286         m_LiveSnapshotSize =
5287             m_pCapability->livesnapshot_sizes_tbl[m_pCapability->livesnapshot_sizes_tbl_cnt-1];
5288     }
5289 
5290     // Set supported preview formats
5291     String8 previewFormatValues = createValuesString(
5292             m_pCapability->supported_preview_fmts,
5293             m_pCapability->supported_preview_fmt_cnt,
5294             PREVIEW_FORMATS_MAP,
5295             PARAM_MAP_SIZE(PREVIEW_FORMATS_MAP));
5296     set(KEY_SUPPORTED_PREVIEW_FORMATS, previewFormatValues.string());
5297     // Set default preview format
5298     CameraParameters::setPreviewFormat(PIXEL_FORMAT_YUV420SP);
5299 
5300     // Set default Video Format as OPAQUE
5301     // Internally both Video and Camera subsystems use NV21_VENUS
5302     set(KEY_VIDEO_FRAME_FORMAT, PIXEL_FORMAT_ANDROID_OPAQUE);
5303 
5304     // Set supported picture formats
5305     String8 pictureTypeValues(PIXEL_FORMAT_JPEG);
5306     String8 str = createValuesString(
5307             m_pCapability->supported_raw_fmts,
5308             m_pCapability->supported_raw_fmt_cnt,
5309             PICTURE_TYPES_MAP,
5310             PARAM_MAP_SIZE(PICTURE_TYPES_MAP));
5311     if (str.string() != NULL) {
5312         pictureTypeValues.append(",");
5313         pictureTypeValues.append(str);
5314     }
5315 
5316     set(KEY_SUPPORTED_PICTURE_FORMATS, pictureTypeValues.string());
5317     // Set default picture Format
5318     CameraParameters::setPictureFormat(PIXEL_FORMAT_JPEG);
5319     // Set raw image size
5320     char raw_size_str[32];
5321     snprintf(raw_size_str, sizeof(raw_size_str), "%dx%d",
5322              m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
5323     set(KEY_QC_RAW_PICUTRE_SIZE, raw_size_str);
5324     LOGD("KEY_QC_RAW_PICUTRE_SIZE: w: %d, h: %d ",
5325        m_pCapability->raw_dim[0].width, m_pCapability->raw_dim[0].height);
5326 
5327     //set default jpeg quality and thumbnail quality
5328     set(KEY_JPEG_QUALITY, 85);
5329     set(KEY_JPEG_THUMBNAIL_QUALITY, 85);
5330 
5331     // Set FPS ranges
5332     if (m_pCapability->fps_ranges_tbl_cnt > 0 &&
5333         m_pCapability->fps_ranges_tbl_cnt <= MAX_SIZES_CNT) {
5334         int default_fps_index = 0;
5335         String8 fpsRangeValues = createFpsRangeString(m_pCapability->fps_ranges_tbl,
5336                                                       m_pCapability->fps_ranges_tbl_cnt,
5337                                                       default_fps_index);
5338         set(KEY_SUPPORTED_PREVIEW_FPS_RANGE, fpsRangeValues.string());
5339 
5340         int min_fps =
5341             int(m_pCapability->fps_ranges_tbl[default_fps_index].min_fps * 1000);
5342         int max_fps =
5343             int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps * 1000);
5344         m_default_fps_range = m_pCapability->fps_ranges_tbl[default_fps_index];
5345         //Set video fps same as preview fps
5346         setPreviewFpsRange(min_fps, max_fps, min_fps, max_fps);
5347 
5348         // Set legacy preview fps
5349         String8 fpsValues = createFpsString(m_pCapability->fps_ranges_tbl[default_fps_index]);
5350         set(KEY_SUPPORTED_PREVIEW_FRAME_RATES, fpsValues.string());
5351         LOGH("supported fps rates: %s", fpsValues.string());
5352         CameraParameters::setPreviewFrameRate(int(m_pCapability->fps_ranges_tbl[default_fps_index].max_fps));
5353     } else {
5354         LOGW("supported fps ranges cnt is 0 or exceeds max!!!");
5355     }
5356 
5357     // Set supported focus modes
5358     if (m_pCapability->supported_focus_modes_cnt > 0) {
5359         String8 focusModeValues = createValuesString(
5360                 m_pCapability->supported_focus_modes,
5361                 m_pCapability->supported_focus_modes_cnt,
5362                 FOCUS_MODES_MAP,
5363                 PARAM_MAP_SIZE(FOCUS_MODES_MAP));
5364         set(KEY_SUPPORTED_FOCUS_MODES, focusModeValues);
5365 
5366         // Set default focus mode and update corresponding parameter buf
5367         const char *focusMode = lookupNameByValue(FOCUS_MODES_MAP,
5368                 PARAM_MAP_SIZE(FOCUS_MODES_MAP),
5369                 m_pCapability->supported_focus_modes[0]);
5370         if (focusMode != NULL) {
5371             setFocusMode(focusMode);
5372         } else {
5373             setFocusMode(FOCUS_MODE_FIXED);
5374         }
5375     } else {
5376         LOGW("supported focus modes cnt is 0!!!");
5377     }
5378 
5379     // Set focus areas
5380     if (m_pCapability->max_num_focus_areas > MAX_ROI) {
5381         m_pCapability->max_num_focus_areas = MAX_ROI;
5382     }
5383     set(KEY_MAX_NUM_FOCUS_AREAS, m_pCapability->max_num_focus_areas);
5384     if (m_pCapability->max_num_focus_areas > 0) {
5385         setFocusAreas(DEFAULT_CAMERA_AREA);
5386     }
5387 
5388     // Set metering areas
5389     if (m_pCapability->max_num_metering_areas > MAX_ROI) {
5390         m_pCapability->max_num_metering_areas = MAX_ROI;
5391     }
5392     set(KEY_MAX_NUM_METERING_AREAS, m_pCapability->max_num_metering_areas);
5393     if (m_pCapability->max_num_metering_areas > 0) {
5394         setMeteringAreas(DEFAULT_CAMERA_AREA);
5395     }
5396 
5397     // set focus position, we should get them from m_pCapability
5398     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 0;
5399     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX] = 1023;
5400     set(KEY_QC_MIN_FOCUS_POS_INDEX,
5401             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
5402     set(KEY_QC_MAX_FOCUS_POS_INDEX,
5403             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_INDEX]);
5404 
5405     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 0;
5406     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE] = 1023;
5407     set(KEY_QC_MIN_FOCUS_POS_DAC,
5408             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
5409     set(KEY_QC_MAX_FOCUS_POS_DAC,
5410             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DAC_CODE]);
5411 
5412     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 0;
5413     m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO] = 100;
5414     set(KEY_QC_MIN_FOCUS_POS_RATIO,
5415             (int) m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
5416     set(KEY_QC_MAX_FOCUS_POS_RATIO,
5417             (int) m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_RATIO]);
5418 
5419     m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
5420     if (m_pCapability->min_focus_distance > 0) {
5421         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] =
5422                 100.0f / m_pCapability->min_focus_distance;
5423     } else {
5424         m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER] = 0;
5425     }
5426     setFloat(KEY_QC_MIN_FOCUS_POS_DIOPTER,
5427             m_pCapability->min_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
5428     setFloat(KEY_QC_MAX_FOCUS_POS_DIOPTER,
5429             m_pCapability->max_focus_pos[CAM_MANUAL_FOCUS_MODE_DIOPTER]);
5430 
5431     //set supported manual focus modes
5432     String8 manualFocusModes(VALUE_OFF);
5433     if (m_pCapability->supported_focus_modes_cnt > 1 &&
5434         m_pCapability->min_focus_distance > 0) {
5435         manualFocusModes.append(",");
5436         manualFocusModes.append(KEY_QC_FOCUS_SCALE_MODE);
5437         manualFocusModes.append(",");
5438         manualFocusModes.append(KEY_QC_FOCUS_DIOPTER_MODE);
5439     }
5440     set(KEY_QC_SUPPORTED_MANUAL_FOCUS_MODES, manualFocusModes.string());
5441 
5442     // Set Saturation
5443     set(KEY_QC_MIN_SATURATION, m_pCapability->saturation_ctrl.min_value);
5444     set(KEY_QC_MAX_SATURATION, m_pCapability->saturation_ctrl.max_value);
5445     set(KEY_QC_SATURATION_STEP, m_pCapability->saturation_ctrl.step);
5446     setSaturation(m_pCapability->saturation_ctrl.def_value);
5447 
5448     // Set Sharpness
5449     set(KEY_QC_MIN_SHARPNESS, m_pCapability->sharpness_ctrl.min_value);
5450     set(KEY_QC_MAX_SHARPNESS, m_pCapability->sharpness_ctrl.max_value);
5451     set(KEY_QC_SHARPNESS_STEP, m_pCapability->sharpness_ctrl.step);
5452     setSharpness(m_pCapability->sharpness_ctrl.def_value);
5453 
5454     // Set Contrast
5455     set(KEY_QC_MIN_CONTRAST, m_pCapability->contrast_ctrl.min_value);
5456     set(KEY_QC_MAX_CONTRAST, m_pCapability->contrast_ctrl.max_value);
5457     set(KEY_QC_CONTRAST_STEP, m_pCapability->contrast_ctrl.step);
5458     setContrast(m_pCapability->contrast_ctrl.def_value);
5459 
5460     // Set SCE factor
5461     set(KEY_QC_MIN_SCE_FACTOR, m_pCapability->sce_ctrl.min_value); // -100
5462     set(KEY_QC_MAX_SCE_FACTOR, m_pCapability->sce_ctrl.max_value); // 100
5463     set(KEY_QC_SCE_FACTOR_STEP, m_pCapability->sce_ctrl.step);     // 10
5464     setSkinToneEnhancement(m_pCapability->sce_ctrl.def_value);     // 0
5465 
5466     // Set Brightness
5467     set(KEY_QC_MIN_BRIGHTNESS, m_pCapability->brightness_ctrl.min_value); // 0
5468     set(KEY_QC_MAX_BRIGHTNESS, m_pCapability->brightness_ctrl.max_value); // 6
5469     set(KEY_QC_BRIGHTNESS_STEP, m_pCapability->brightness_ctrl.step);     // 1
5470     setBrightness(m_pCapability->brightness_ctrl.def_value);
5471 
5472     // Set Auto exposure
5473     String8 autoExposureValues = createValuesString(
5474             m_pCapability->supported_aec_modes,
5475             m_pCapability->supported_aec_modes_cnt,
5476             AUTO_EXPOSURE_MAP,
5477             PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP));
5478     set(KEY_QC_SUPPORTED_AUTO_EXPOSURE, autoExposureValues.string());
5479     setAutoExposure(AUTO_EXPOSURE_FRAME_AVG);
5480 
5481     // Set Exposure Compensation
5482     set(KEY_MAX_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_max); // 12
5483     set(KEY_MIN_EXPOSURE_COMPENSATION, m_pCapability->exposure_compensation_min); // -12
5484     setFloat(KEY_EXPOSURE_COMPENSATION_STEP, m_pCapability->exposure_compensation_step); // 1/6
5485     setExposureCompensation(m_pCapability->exposure_compensation_default); // 0
5486 
5487     // Set Instant AEC modes
5488     String8 instantAECModes = createValuesString(
5489             m_pCapability->supported_instant_aec_modes,
5490             m_pCapability->supported_instant_aec_modes_cnt,
5491             INSTANT_AEC_MODES_MAP,
5492             PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP));
5493     set(KEY_QC_INSTANT_AEC_SUPPORTED_MODES, instantAECModes.string());
5494 
5495     // Set Instant Capture modes
5496     String8 instantCaptureModes = createValuesString(
5497             m_pCapability->supported_instant_aec_modes,
5498             m_pCapability->supported_instant_aec_modes_cnt,
5499             INSTANT_CAPTURE_MODES_MAP,
5500             PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP));
5501     set(KEY_QC_INSTANT_CAPTURE_SUPPORTED_MODES, instantCaptureModes.string());
5502 
5503 
5504     // Set Antibanding
5505     String8 antibandingValues = createValuesString(
5506             m_pCapability->supported_antibandings,
5507             m_pCapability->supported_antibandings_cnt,
5508             ANTIBANDING_MODES_MAP,
5509             PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP));
5510     set(KEY_SUPPORTED_ANTIBANDING, antibandingValues);
5511     setAntibanding(ANTIBANDING_OFF);
5512 
5513     // Set Effect
5514     String8 effectValues = createValuesString(
5515             m_pCapability->supported_effects,
5516             m_pCapability->supported_effects_cnt,
5517             EFFECT_MODES_MAP,
5518             PARAM_MAP_SIZE(EFFECT_MODES_MAP));
5519 
5520     if (m_pCapability->supported_effects_cnt > 0) {
5521         set(KEY_SUPPORTED_EFFECTS, effectValues);
5522     } else {
5523         LOGW("Color effects are not available");
5524         set(KEY_SUPPORTED_EFFECTS, EFFECT_NONE);
5525     }
5526     setEffect(EFFECT_NONE);
5527 
5528     // Set WhiteBalance
5529     String8 whitebalanceValues = createValuesString(
5530             m_pCapability->supported_white_balances,
5531             m_pCapability->supported_white_balances_cnt,
5532             WHITE_BALANCE_MODES_MAP,
5533             PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP));
5534     set(KEY_SUPPORTED_WHITE_BALANCE, whitebalanceValues);
5535     setWhiteBalance(WHITE_BALANCE_AUTO);
5536 
5537     // set supported wb cct, we should get them from m_pCapability
5538     m_pCapability->min_wb_cct = 2000;
5539     m_pCapability->max_wb_cct = 8000;
5540     set(KEY_QC_MIN_WB_CCT, m_pCapability->min_wb_cct);
5541     set(KEY_QC_MAX_WB_CCT, m_pCapability->max_wb_cct);
5542 
5543     // set supported wb rgb gains, ideally we should get them from m_pCapability
5544     //but for now hardcode.
5545     m_pCapability->min_wb_gain = 1.0;
5546     m_pCapability->max_wb_gain = 4.0;
5547     setFloat(KEY_QC_MIN_WB_GAIN, m_pCapability->min_wb_gain);
5548     setFloat(KEY_QC_MAX_WB_GAIN, m_pCapability->max_wb_gain);
5549 
5550     //set supported manual wb modes
5551     String8 manualWBModes(VALUE_OFF);
5552     if(m_pCapability->sensor_type.sens_type != CAM_SENSOR_YUV) {
5553         manualWBModes.append(",");
5554         manualWBModes.append(KEY_QC_WB_CCT_MODE);
5555         manualWBModes.append(",");
5556         manualWBModes.append(KEY_QC_WB_GAIN_MODE);
5557     }
5558     set(KEY_QC_SUPPORTED_MANUAL_WB_MODES, manualWBModes.string());
5559 
5560     // Set Flash mode
5561     if(m_pCapability->supported_flash_modes_cnt > 0) {
5562        String8 flashValues = createValuesString(
5563                m_pCapability->supported_flash_modes,
5564                m_pCapability->supported_flash_modes_cnt,
5565                FLASH_MODES_MAP,
5566                PARAM_MAP_SIZE(FLASH_MODES_MAP));
5567        set(KEY_SUPPORTED_FLASH_MODES, flashValues);
5568        setFlash(FLASH_MODE_OFF);
5569     } else {
5570         LOGW("supported flash modes cnt is 0!!!");
5571     }
5572 
5573     // Set Scene Mode
5574     String8 sceneModeValues = createValuesString(
5575             m_pCapability->supported_scene_modes,
5576             m_pCapability->supported_scene_modes_cnt,
5577             SCENE_MODES_MAP,
5578             PARAM_MAP_SIZE(SCENE_MODES_MAP));
5579     set(KEY_SUPPORTED_SCENE_MODES, sceneModeValues);
5580     setSceneMode(SCENE_MODE_AUTO);
5581 
5582     // Set CDS Mode
5583     String8 cdsModeValues = createValuesStringFromMap(
5584             CDS_MODES_MAP,
5585             PARAM_MAP_SIZE(CDS_MODES_MAP));
5586     set(KEY_QC_SUPPORTED_CDS_MODES, cdsModeValues);
5587 
5588     // Set video CDS Mode
5589     String8 videoCdsModeValues = createValuesStringFromMap(
5590             CDS_MODES_MAP,
5591             PARAM_MAP_SIZE(CDS_MODES_MAP));
5592     set(KEY_QC_SUPPORTED_VIDEO_CDS_MODES, videoCdsModeValues);
5593 
5594     // Set TNR Mode
5595     String8 tnrModeValues = createValuesStringFromMap(
5596             ON_OFF_MODES_MAP,
5597             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5598     set(KEY_QC_SUPPORTED_TNR_MODES, tnrModeValues);
5599 
5600     // Set video TNR Mode
5601     String8 videoTnrModeValues = createValuesStringFromMap(
5602             ON_OFF_MODES_MAP,
5603             PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5604     set(KEY_QC_SUPPORTED_VIDEO_TNR_MODES, videoTnrModeValues);
5605 
5606     // Set ISO Mode
5607     String8 isoValues = createValuesString(
5608             m_pCapability->supported_iso_modes,
5609             m_pCapability->supported_iso_modes_cnt,
5610             ISO_MODES_MAP,
5611             PARAM_MAP_SIZE(ISO_MODES_MAP));
5612     set(KEY_QC_SUPPORTED_ISO_MODES, isoValues);
5613     setISOValue(ISO_AUTO);
5614 
5615     // Set exposure time
5616     String8 manualExpModes(VALUE_OFF);
5617     bool expTimeSupported = false;
5618     bool manualISOSupported = false;
5619     //capability values are in nano sec, convert to milli sec for upper layers
5620     char expTimeStr[20];
5621     double min_exp_time = (double) m_pCapability->exposure_time_range[0] / 1000000.0;
5622     double max_exp_time = (double) m_pCapability->exposure_time_range[1] / 1000000.0;
5623     snprintf(expTimeStr, sizeof(expTimeStr), "%f", min_exp_time);
5624     set(KEY_QC_MIN_EXPOSURE_TIME, expTimeStr);
5625     snprintf(expTimeStr, sizeof(expTimeStr), "%f", max_exp_time);
5626     set(KEY_QC_MAX_EXPOSURE_TIME, expTimeStr);
5627     if ((min_exp_time > 0) && (max_exp_time > min_exp_time)) {
5628         manualExpModes.append(",");
5629         manualExpModes.append(KEY_QC_EXP_TIME_PRIORITY);
5630         expTimeSupported = true;
5631     }
5632     LOGH(", Exposure time min %f ms, max %f ms",
5633             min_exp_time, max_exp_time);
5634 
5635     // Set iso
5636     set(KEY_QC_MIN_ISO, m_pCapability->sensitivity_range.min_sensitivity);
5637     set(KEY_QC_MAX_ISO, m_pCapability->sensitivity_range.max_sensitivity);
5638     LOGH(", ISO min %d, max %d",
5639             m_pCapability->sensitivity_range.min_sensitivity,
5640             m_pCapability->sensitivity_range.max_sensitivity);
5641     if ((m_pCapability->sensitivity_range.min_sensitivity > 0) &&
5642             (m_pCapability->sensitivity_range.max_sensitivity >
5643                     m_pCapability->sensitivity_range.min_sensitivity)) {
5644         manualExpModes.append(",");
5645         manualExpModes.append(KEY_QC_ISO_PRIORITY);
5646         manualISOSupported = true;
5647     }
5648     if (expTimeSupported && manualISOSupported) {
5649         manualExpModes.append(",");
5650         manualExpModes.append(KEY_QC_USER_SETTING);
5651     }
5652     //finally set supported manual exposure modes
5653     set(KEY_QC_SUPPORTED_MANUAL_EXPOSURE_MODES, manualExpModes.string());
5654 
5655     // Set HFR
5656     String8 hfrValues = createHfrValuesString(
5657             m_pCapability->hfr_tbl,
5658             m_pCapability->hfr_tbl_cnt,
5659             HFR_MODES_MAP,
5660             PARAM_MAP_SIZE(HFR_MODES_MAP));
5661     set(KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES, hfrValues.string());
5662     set(KEY_QC_VIDEO_HIGH_SPEED_RECORDING, "off");
5663     set(KEY_QC_VIDEO_HIGH_FRAME_RATE, "off");
5664     String8 hfrSizeValues = createHfrSizesString(
5665             m_pCapability->hfr_tbl,
5666             m_pCapability->hfr_tbl_cnt);
5667     set(KEY_QC_SUPPORTED_HFR_SIZES, hfrSizeValues.string());
5668     LOGD("HFR values %s HFR Sizes = %d", hfrValues.string(), hfrSizeValues.string());
5669     setHighFrameRate(CAM_HFR_MODE_OFF);
5670 
5671     // Set Focus algorithms
5672     String8 focusAlgoValues = createValuesString(
5673             m_pCapability->supported_focus_algos,
5674             m_pCapability->supported_focus_algos_cnt,
5675             FOCUS_ALGO_MAP,
5676             PARAM_MAP_SIZE(FOCUS_ALGO_MAP));
5677     set(KEY_QC_SUPPORTED_FOCUS_ALGOS, focusAlgoValues);
5678     setSelectableZoneAf(FOCUS_ALGO_AUTO);
5679 
5680     // Set Zoom Ratios
5681     if (m_pCapability->zoom_supported > 0) {
5682         String8 zoomRatioValues = createZoomRatioValuesString(
5683                 m_pCapability->zoom_ratio_tbl,
5684                 m_pCapability->zoom_ratio_tbl_cnt);
5685         set(KEY_ZOOM_RATIOS, zoomRatioValues);
5686         set(KEY_MAX_ZOOM, (int)(m_pCapability->zoom_ratio_tbl_cnt - 1));
5687         setZoom(0);
5688     }
5689 
5690     // Set Bracketing/HDR
5691     char prop[PROPERTY_VALUE_MAX];
5692     memset(prop, 0, sizeof(prop));
5693     property_get("persist.capture.burst.exposures", prop, "");
5694     if (strlen(prop) > 0) {
5695         set(KEY_QC_CAPTURE_BURST_EXPOSURE, prop);
5696     }
5697     String8 bracketingValues = createValuesStringFromMap(
5698             BRACKETING_MODES_MAP,
5699             PARAM_MAP_SIZE(BRACKETING_MODES_MAP));
5700     set(KEY_QC_SUPPORTED_AE_BRACKET_MODES, bracketingValues);
5701     setAEBracket(AE_BRACKET_OFF);
5702 
5703     //Set AF Bracketing.
5704     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5705         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5706                 ((m_pCapability->qcom_supported_feature_mask &
5707                         CAM_QCOM_FEATURE_UBIFOCUS) > 0)) {
5708             String8 afBracketingValues = createValuesStringFromMap(
5709                     AF_BRACKETING_MODES_MAP,
5710                     PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP));
5711             set(KEY_QC_SUPPORTED_AF_BRACKET_MODES, afBracketingValues);
5712             setAFBracket(AF_BRACKET_OFF);
5713             break;
5714          }
5715     }
5716 
5717     //Set Refocus.
5718     //Re-use ubifocus flag for now.
5719     for (size_t i = 0; i < m_pCapability->supported_focus_modes_cnt; i++) {
5720         if ((CAM_FOCUS_MODE_AUTO == m_pCapability->supported_focus_modes[i]) &&
5721                 (m_pCapability->qcom_supported_feature_mask &
5722                     CAM_QCOM_FEATURE_REFOCUS) > 0) {
5723             String8 reFocusValues = createValuesStringFromMap(
5724                     RE_FOCUS_MODES_MAP,
5725                     PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP));
5726             set(KEY_QC_SUPPORTED_RE_FOCUS_MODES, reFocusValues);
5727             setReFocus(RE_FOCUS_OFF);
5728         }
5729     }
5730 
5731     //Set Chroma Flash.
5732     if ((m_pCapability->supported_flash_modes_cnt > 0) &&
5733             (m_pCapability->qcom_supported_feature_mask &
5734             CAM_QCOM_FEATURE_CHROMA_FLASH) > 0) {
5735         String8 chromaFlashValues = createValuesStringFromMap(
5736                 CHROMA_FLASH_MODES_MAP,
5737                 PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP));
5738         set(KEY_QC_SUPPORTED_CHROMA_FLASH_MODES, chromaFlashValues);
5739         setChromaFlash(CHROMA_FLASH_OFF);
5740     }
5741 
5742     //Set Opti Zoom.
5743     if (m_pCapability->zoom_supported &&
5744             (m_pCapability->qcom_supported_feature_mask &
5745             CAM_QCOM_FEATURE_OPTIZOOM) > 0){
5746         String8 optiZoomValues = createValuesStringFromMap(
5747                 OPTI_ZOOM_MODES_MAP,
5748                 PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP));
5749         set(KEY_QC_SUPPORTED_OPTI_ZOOM_MODES, optiZoomValues);
5750         setOptiZoom(OPTI_ZOOM_OFF);
5751     }
5752 
5753     //Set HDR Type
5754     uint32_t supported_hdr_modes = m_pCapability->qcom_supported_feature_mask &
5755             (CAM_QCOM_FEATURE_SENSOR_HDR | CAM_QCOM_FEATURE_HDR);
5756     if (supported_hdr_modes) {
5757         if (CAM_QCOM_FEATURE_SENSOR_HDR == supported_hdr_modes) {
5758             String8 hdrModeValues;
5759             hdrModeValues.append(HDR_MODE_SENSOR);
5760             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5761             setHDRMode(HDR_MODE_SENSOR);
5762         } else if (CAM_QCOM_FEATURE_HDR == supported_hdr_modes) {
5763             String8 hdrModeValues;
5764             hdrModeValues.append(HDR_MODE_MULTI_FRAME);
5765             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5766             setHDRMode(HDR_MODE_MULTI_FRAME);
5767         } else {
5768             String8 hdrModeValues = createValuesStringFromMap(
5769                     HDR_MODES_MAP,
5770                     PARAM_MAP_SIZE(HDR_MODES_MAP));
5771             set(KEY_QC_SUPPORTED_KEY_QC_HDR_MODES, hdrModeValues);
5772             setHDRMode(HDR_MODE_MULTI_FRAME);
5773         }
5774     }
5775 
5776     //Set HDR need 1x
5777     String8 hdrNeed1xValues;
5778     if (!m_bHDRModeSensor) {
5779         hdrNeed1xValues = createValuesStringFromMap(TRUE_FALSE_MODES_MAP,
5780                 PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP));
5781     } else {
5782         hdrNeed1xValues.append(VALUE_FALSE);
5783     }
5784     setHDRNeed1x(VALUE_FALSE);
5785     set(KEY_QC_SUPPORTED_HDR_NEED_1X, hdrNeed1xValues);
5786 
5787     //Set True Portrait
5788     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_TRUEPORTRAIT) > 0) {
5789         String8 truePortraitValues = createValuesStringFromMap(
5790                 TRUE_PORTRAIT_MODES_MAP,
5791                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP));
5792         set(KEY_QC_SUPPORTED_TRUE_PORTRAIT_MODES, truePortraitValues);
5793     }
5794 
5795     // Set Denoise
5796     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) > 0){
5797     String8 denoiseValues = createValuesStringFromMap(
5798         DENOISE_ON_OFF_MODES_MAP, PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP));
5799     set(KEY_QC_SUPPORTED_DENOISE, denoiseValues.string());
5800 #ifdef DEFAULT_DENOISE_MODE_ON
5801     setWaveletDenoise(DENOISE_ON);
5802 #else
5803     setWaveletDenoise(DENOISE_OFF);
5804 #endif
5805     }
5806 
5807     // Set feature enable/disable
5808     String8 enableDisableValues = createValuesStringFromMap(
5809             ENABLE_DISABLE_MODES_MAP, PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP));
5810 
5811     // Set Lens Shading
5812     set(KEY_QC_SUPPORTED_LENSSHADE_MODES, enableDisableValues);
5813     setLensShadeValue(VALUE_ENABLE);
5814     // Set MCE
5815     set(KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES, enableDisableValues);
5816     setMCEValue(VALUE_ENABLE);
5817 
5818     // Set DIS
5819     set(KEY_QC_SUPPORTED_DIS_MODES, enableDisableValues);
5820     setDISValue(VALUE_DISABLE);
5821 
5822     // Set Histogram
5823     set(KEY_QC_SUPPORTED_HISTOGRAM_MODES,
5824         m_pCapability->histogram_supported ? enableDisableValues : "");
5825     set(KEY_QC_HISTOGRAM, VALUE_DISABLE);
5826 
5827     //Set Red Eye Reduction
5828     set(KEY_QC_SUPPORTED_REDEYE_REDUCTION, enableDisableValues);
5829     setRedeyeReduction(VALUE_DISABLE);
5830 
5831     //Set SkinTone Enhancement
5832     set(KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES, enableDisableValues);
5833 
5834     // Enable LTM by default and disable it in HDR & SeeMore usecases
5835     setToneMapMode(true, false);
5836 
5837     // Set feature on/off
5838     String8 onOffValues = createValuesStringFromMap(
5839             ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP));
5840 
5841     //Set See more (LLVD)
5842     if (m_pCapability->qcom_supported_feature_mask &
5843             CAM_QCOM_FEATURE_LLVD) {
5844         set(KEY_QC_SUPPORTED_SEE_MORE_MODES, onOffValues);
5845         setSeeMore(VALUE_OFF);
5846     }
5847 
5848     //Set Still more
5849     if (m_pCapability->qcom_supported_feature_mask &
5850             CAM_QCOM_FEATURE_STILLMORE) {
5851         String8 stillMoreValues = createValuesStringFromMap(
5852                 STILL_MORE_MODES_MAP,
5853                 PARAM_MAP_SIZE(STILL_MORE_MODES_MAP));
5854         set(KEY_QC_SUPPORTED_STILL_MORE_MODES, stillMoreValues);
5855         setStillMore(STILL_MORE_OFF);
5856     }
5857 
5858     //Set Noise Reduction mode
5859     if (m_pCapability->qcom_supported_feature_mask &
5860             CAM_QTI_FEATURE_SW_TNR) {
5861         String8 noiseReductionModesValues = createValuesStringFromMap(
5862                 NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP));
5863         set(KEY_QC_NOISE_REDUCTION_MODE_VALUES, noiseReductionModesValues);
5864         setNoiseReductionMode(VALUE_OFF);
5865     }
5866 
5867     //Set Scene Detection
5868     set(KEY_QC_SUPPORTED_SCENE_DETECT, onOffValues);
5869     setSceneDetect(VALUE_OFF);
5870     m_bHDREnabled = false;
5871     m_bHDR1xFrameEnabled = false;
5872 
5873     m_bHDRThumbnailProcessNeeded = false;
5874     m_bHDR1xExtraBufferNeeded = true;
5875     for (uint32_t i=0; i<m_pCapability->hdr_bracketing_setting.num_frames; i++) {
5876         if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[i]) {
5877             m_bHDR1xExtraBufferNeeded = false;
5878             break;
5879         }
5880     }
5881 
5882     // Set HDR output scaling
5883     char value[PROPERTY_VALUE_MAX];
5884 
5885     property_get("persist.camera.hdr.outcrop", value, VALUE_DISABLE);
5886     if (strncmp(VALUE_ENABLE, value, sizeof(VALUE_ENABLE))) {
5887       m_bHDROutputCropEnabled = false;
5888     } else {
5889       m_bHDROutputCropEnabled = true;
5890     }
5891 
5892     //Set Face Detection
5893     set(KEY_QC_SUPPORTED_FACE_DETECTION, onOffValues);
5894     set(KEY_QC_FACE_DETECTION, VALUE_OFF);
5895 
5896     //Set Face Recognition
5897     //set(KEY_QC_SUPPORTED_FACE_RECOGNITION, onOffValues);
5898     //set(KEY_QC_FACE_RECOGNITION, VALUE_OFF);
5899 
5900     //Set ZSL
5901     set(KEY_QC_SUPPORTED_ZSL_MODES, onOffValues);
5902 #ifdef DEFAULT_ZSL_MODE_ON
5903     set(KEY_QC_ZSL, VALUE_ON);
5904     m_bZslMode = true;
5905 #else
5906     set(KEY_QC_ZSL, VALUE_OFF);
5907     m_bZslMode = false;
5908 #endif
5909 
5910     // Check if zsl mode property is enabled.
5911     // If yes, force the camera to be in zsl mode
5912     // and force zsl mode to be enabled in dual camera mode.
5913     memset(value, 0x0, PROPERTY_VALUE_MAX);
5914     property_get("persist.camera.zsl.mode", value, "0");
5915     int32_t zsl_mode = atoi(value);
5916     if((zsl_mode == 1) ||
5917             (m_bZslMode == true) ||
5918             (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON)) {
5919         LOGH("%d: Forcing Camera to ZSL mode enabled");
5920         set(KEY_QC_ZSL, VALUE_ON);
5921         m_bForceZslMode = true;
5922         m_bZslMode = true;
5923         int32_t value = m_bForceZslMode;
5924         ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZSL_MODE, value);
5925     }
5926     m_bZslMode_new = m_bZslMode;
5927 
5928     set(KEY_QC_SCENE_SELECTION, VALUE_DISABLE);
5929 
5930     // Rdi mode
5931     set(KEY_QC_SUPPORTED_RDI_MODES, enableDisableValues);
5932     setRdiMode(VALUE_DISABLE);
5933 
5934     // Secure mode
5935     set(KEY_QC_SUPPORTED_SECURE_MODES, enableDisableValues);
5936     setSecureMode(VALUE_DISABLE);
5937 
5938     //Set video HDR
5939     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_VIDEO_HDR) > 0) {
5940         set(KEY_QC_SUPPORTED_VIDEO_HDR_MODES, onOffValues);
5941         set(KEY_QC_VIDEO_HDR, VALUE_OFF);
5942     }
5943 
5944     //Set HW Sensor Snapshot HDR
5945     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_SENSOR_HDR)> 0) {
5946         set(KEY_QC_SUPPORTED_SENSOR_HDR_MODES, onOffValues);
5947         set(KEY_QC_SENSOR_HDR, VALUE_OFF);
5948         m_bSensorHDREnabled = false;
5949     }
5950 
5951     // Set VT TimeStamp
5952     set(KEY_QC_VT_ENABLE, VALUE_DISABLE);
5953     //Set Touch AF/AEC
5954     String8 touchValues = createValuesStringFromMap(
5955             TOUCH_AF_AEC_MODES_MAP, PARAM_MAP_SIZE(TOUCH_AF_AEC_MODES_MAP));
5956 
5957     set(KEY_QC_SUPPORTED_TOUCH_AF_AEC, touchValues);
5958     set(KEY_QC_TOUCH_AF_AEC, TOUCH_AF_AEC_OFF);
5959 
5960     //set flip mode
5961     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_FLIP) > 0) {
5962         String8 flipModes = createValuesStringFromMap(
5963                 FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP));
5964         set(KEY_QC_SUPPORTED_FLIP_MODES, flipModes);
5965         set(KEY_QC_PREVIEW_FLIP, FLIP_MODE_OFF);
5966         set(KEY_QC_VIDEO_FLIP, FLIP_MODE_OFF);
5967         set(KEY_QC_SNAPSHOT_PICTURE_FLIP, FLIP_MODE_OFF);
5968     }
5969 
5970     // Set default Auto Exposure lock value
5971     setAecLock(VALUE_FALSE);
5972 
5973     // Set default AWB_LOCK lock value
5974     setAwbLock(VALUE_FALSE);
5975 
5976     // Set default Camera mode
5977     set(KEY_QC_CAMERA_MODE, 0);
5978 
5979     // Add support for internal preview restart
5980     set(KEY_INTERNAL_PERVIEW_RESTART, VALUE_TRUE);
5981     // Set default burst number
5982     set(KEY_QC_SNAPSHOT_BURST_NUM, 0);
5983     set(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER, 0);
5984 
5985     //Get RAM size and disable features which are memory rich
5986     struct sysinfo info;
5987     sysinfo(&info);
5988 
5989     LOGH("totalram = %ld, freeram = %ld ", info.totalram,
5990         info.freeram);
5991     if (info.totalram > TOTAL_RAM_SIZE_512MB) {
5992         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_TRUE);
5993     } else {
5994         m_bIsLowMemoryDevice = true;
5995         set(KEY_QC_ZSL_HDR_SUPPORTED, VALUE_FALSE);
5996     }
5997 
5998     setOfflineRAW();
5999     memset(mStreamPpMask, 0, sizeof(uint32_t)*CAM_STREAM_TYPE_MAX);
6000     //Set video buffers as uncached by default
6001     set(KEY_QC_CACHE_VIDEO_BUFFERS, VALUE_DISABLE);
6002 
6003     // Set default longshot mode
6004     set(KEY_QC_LONG_SHOT, "off");
6005     //Enable longshot by default
6006     set(KEY_QC_LONGSHOT_SUPPORTED, VALUE_TRUE);
6007 
6008     int32_t rc = commitParameters();
6009     if (rc == NO_ERROR) {
6010         rc = setNumOfSnapshot();
6011     }
6012 
6013     //Set Video Rotation
6014     String8 videoRotationValues = createValuesStringFromMap(VIDEO_ROTATION_MODES_MAP,
6015             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP));
6016 
6017     set(KEY_QC_SUPPORTED_VIDEO_ROTATION_VALUES, videoRotationValues.string());
6018     set(KEY_QC_VIDEO_ROTATION, VIDEO_ROTATION_0);
6019 
6020     //Check for EZTune
6021     setEztune();
6022     //Default set for video batch size
6023     set(KEY_QC_VIDEO_BATCH_SIZE, 0);
6024 
6025     //Setup dual-camera
6026     setDcrf();
6027 
6028     // For Aux Camera of dual camera Mode,
6029     // by default set no display mode
6030     if (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) {
6031         set(KEY_QC_NO_DISPLAY_MODE, 1);
6032         m_bNoDisplayMode = true;
6033     }
6034 
6035     cam_dimension_t pic_dim;
6036     pic_dim.width = 0;
6037     pic_dim.height = 0;
6038 
6039     for(uint32_t i = 0;
6040             i < (m_pCapability->picture_sizes_tbl_cnt - 1);
6041             i++) {
6042         if ((pic_dim.width * pic_dim.height) <
6043                 (int32_t)(m_pCapability->picture_sizes_tbl[i].width *
6044                 m_pCapability->picture_sizes_tbl[i].height)) {
6045             pic_dim.width =
6046                     m_pCapability->picture_sizes_tbl[i].width;
6047             pic_dim.height =
6048                     m_pCapability->picture_sizes_tbl[i].height;
6049         }
6050     }
6051     LOGD("max pic size = %d %d", pic_dim.width,
6052             pic_dim.height);
6053     setMaxPicSize(pic_dim);
6054 
6055     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
6056 
6057     return rc;
6058 }
6059 
6060 /*===========================================================================
6061  * FUNCTION   : allocate
6062  *
6063  * DESCRIPTION: Allocate buffer memory for parameter obj (if necessary)
6064  *
6065  * PARAMETERS : none
6066  *
6067  * RETURN     : int32_t type of status
6068  *              NO_ERROR  -- success
6069  *              none-zero failure code
6070  *==========================================================================*/
allocate()6071 int32_t QCameraParameters::allocate()
6072 {
6073     int32_t rc = NO_ERROR;
6074 
6075     if (m_pParamHeap != NULL) {
6076         return rc;
6077     }
6078 
6079     //Allocate Set Param Buffer
6080     m_pParamHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
6081     if (m_pParamHeap == NULL) {
6082         return NO_MEMORY;
6083     }
6084 
6085     rc = m_pParamHeap->allocate(1, sizeof(parm_buffer_t), NON_SECURE);
6086     if(rc != OK) {
6087         rc = NO_MEMORY;
6088         LOGE("Error!! Param buffers have not been allocated");
6089         delete m_pParamHeap;
6090         m_pParamHeap = NULL;
6091     }
6092 
6093     return rc;
6094 }
6095 
6096 /*===========================================================================
6097  * FUNCTION   : init
6098  *
6099  * DESCRIPTION: initialize parameter obj
6100  *
6101  * PARAMETERS :
6102  *   @capabilities  : ptr to camera capabilities
6103  *   @mmops         : ptr to memory ops table for mapping/unmapping
6104  *   @adjustFPS     : object reference for additional (possibly thermal)
6105  *                    framerate adjustment
6106  *
6107  * RETURN     : int32_t type of status
6108  *              NO_ERROR  -- success
6109  *              none-zero failure code
6110  *==========================================================================*/
init(cam_capability_t * capabilities,mm_camera_vtbl_t * mmOps,QCameraAdjustFPS * adjustFPS)6111 int32_t QCameraParameters::init(cam_capability_t *capabilities,
6112         mm_camera_vtbl_t *mmOps, QCameraAdjustFPS *adjustFPS)
6113 {
6114     int32_t rc = NO_ERROR;
6115 
6116     m_pCapability = capabilities;
6117     m_pCamOpsTbl = mmOps;
6118     m_AdjustFPS = adjustFPS;
6119 
6120     if (m_pParamHeap == NULL) {
6121         LOGE("Parameter buffers have not been allocated");
6122         rc = UNKNOWN_ERROR;
6123         goto TRANS_INIT_ERROR1;
6124     }
6125 
6126     //Map memory for parameters buffer
6127     cam_buf_map_type_list bufMapList;
6128     rc = QCameraBufferMaps::makeSingletonBufMapList(
6129             CAM_MAPPING_BUF_TYPE_PARM_BUF, 0 /*stream id*/,
6130             0 /*buffer index*/, -1 /*plane index*/, 0 /*cookie*/,
6131             m_pParamHeap->getFd(0), sizeof(parm_buffer_t), bufMapList);
6132 
6133     if (rc == NO_ERROR) {
6134         rc = m_pCamOpsTbl->ops->map_bufs(m_pCamOpsTbl->camera_handle,
6135                 &bufMapList);
6136     }
6137 
6138     if(rc < 0) {
6139         LOGE("failed to map SETPARM buffer");
6140         rc = FAILED_TRANSACTION;
6141         goto TRANS_INIT_ERROR2;
6142     }
6143     m_pParamBuf = (parm_buffer_t*) DATA_PTR(m_pParamHeap,0);
6144 
6145     // Check if it is dual camera mode
6146     if(m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
6147         //Allocate related cam sync buffer
6148         //this is needed for the payload that goes along with bundling cmd for related
6149         //camera use cases
6150         m_pRelCamSyncHeap = new QCameraHeapMemory(QCAMERA_ION_USE_CACHE);
6151         rc = m_pRelCamSyncHeap->allocate(1,
6152                 sizeof(cam_sync_related_sensors_event_info_t), NON_SECURE);
6153         if(rc != OK) {
6154             rc = NO_MEMORY;
6155             LOGE("Failed to allocate Related cam sync Heap memory");
6156             goto TRANS_INIT_ERROR3;
6157         }
6158 
6159         //Map memory for related cam sync buffer
6160         rc = m_pCamOpsTbl->ops->map_buf(m_pCamOpsTbl->camera_handle,
6161                 CAM_MAPPING_BUF_TYPE_SYNC_RELATED_SENSORS_BUF,
6162                 m_pRelCamSyncHeap->getFd(0),
6163                 sizeof(cam_sync_related_sensors_event_info_t));
6164         if(rc < 0) {
6165             LOGE("failed to map Related cam sync buffer");
6166             rc = FAILED_TRANSACTION;
6167             goto TRANS_INIT_ERROR4;
6168         }
6169         m_pRelCamSyncBuf =
6170                 (cam_sync_related_sensors_event_info_t*) DATA_PTR(m_pRelCamSyncHeap,0);
6171     }
6172 
6173     initDefaultParameters();
6174 
6175     m_bInited = true;
6176 
6177     goto TRANS_INIT_DONE;
6178 
6179 TRANS_INIT_ERROR4:
6180     m_pRelCamSyncHeap->deallocate();
6181 
6182 TRANS_INIT_ERROR3:
6183     delete m_pRelCamSyncHeap;
6184     m_pRelCamSyncHeap = NULL;
6185 
6186 TRANS_INIT_ERROR2:
6187     m_pParamHeap->deallocate();
6188     delete m_pParamHeap;
6189     m_pParamHeap = NULL;
6190 
6191 TRANS_INIT_ERROR1:
6192     m_pCapability = NULL;
6193     m_pCamOpsTbl = NULL;
6194     m_AdjustFPS = NULL;
6195 
6196 TRANS_INIT_DONE:
6197     return rc;
6198 }
6199 
6200 /*===========================================================================
6201  * FUNCTION   : deinit
6202  *
6203  * DESCRIPTION: deinitialize
6204  *
6205  * PARAMETERS : none
6206  *
6207  * RETURN     : none
6208  *==========================================================================*/
deinit()6209 void QCameraParameters::deinit()
6210 {
6211     if (!m_bInited) {
6212         return;
6213     }
6214 
6215     //clear all entries in the map
6216     String8 emptyStr;
6217     QCameraParameters::unflatten(emptyStr);
6218 
6219     if ((NULL != m_pCamOpsTbl) && (m_pCamOpsTbl->ops != NULL)) {
6220         m_pCamOpsTbl->ops->unmap_buf(
6221                              m_pCamOpsTbl->camera_handle,
6222                              CAM_MAPPING_BUF_TYPE_PARM_BUF);
6223 
6224         if (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
6225             m_pCamOpsTbl->ops->unmap_buf(
6226                     m_pCamOpsTbl->camera_handle,
6227                     CAM_MAPPING_BUF_TYPE_SYNC_RELATED_SENSORS_BUF);
6228         }
6229     }
6230 
6231     m_pCapability = NULL;
6232     if (NULL != m_pParamHeap) {
6233         m_pParamHeap->deallocate();
6234         delete m_pParamHeap;
6235         m_pParamHeap = NULL;
6236         m_pParamBuf = NULL;
6237     }
6238     if (NULL != m_pRelCamSyncHeap) {
6239         m_pRelCamSyncHeap->deallocate();
6240         delete m_pRelCamSyncHeap;
6241         m_pRelCamSyncHeap = NULL;
6242         m_pRelCamSyncBuf = NULL;
6243     }
6244 
6245     m_AdjustFPS = NULL;
6246     m_tempMap.clear();
6247     m_pCamOpsTbl = NULL;
6248     m_AdjustFPS = NULL;
6249 
6250     m_bInited = false;
6251 }
6252 
6253 /*===========================================================================
6254  * FUNCTION   : parse_pair
6255  *
6256  * DESCRIPTION: helper function to parse string like "640x480" or "10000,20000"
6257  *
6258  * PARAMETERS :
6259  *   @str     : input string to be parse
6260  *   @first   : [output] first value of the pair
6261  *   @second  : [output]  second value of the pair
6262  *   @delim   : [input] delimeter to seperate the pair
6263  *   @endptr  : [output] ptr to the end of the pair string
6264  *
6265  * RETURN     : int32_t type of status
6266  *              NO_ERROR  -- success
6267  *              none-zero failure code
6268  *==========================================================================*/
parse_pair(const char * str,int * first,int * second,char delim,char ** endptr=NULL)6269 int32_t QCameraParameters::parse_pair(const char *str,
6270                                       int *first,
6271                                       int *second,
6272                                       char delim,
6273                                       char **endptr = NULL)
6274 {
6275     // Find the first integer.
6276     char *end;
6277     int w = (int)strtol(str, &end, 10);
6278     // If a delimeter does not immediately follow, give up.
6279     if (*end != delim) {
6280         LOGE("Cannot find delimeter (%c) in str=%s", delim, str);
6281         return BAD_VALUE;
6282     }
6283 
6284     // Find the second integer, immediately after the delimeter.
6285     int h = (int)strtol(end+1, &end, 10);
6286 
6287     *first = w;
6288     *second = h;
6289 
6290     if (endptr) {
6291         *endptr = end;
6292     }
6293 
6294     return NO_ERROR;
6295 }
6296 
6297 /*===========================================================================
6298  * FUNCTION   : parseSizesList
6299  *
6300  * DESCRIPTION: helper function to parse string containing sizes
6301  *
6302  * PARAMETERS :
6303  *   @sizesStr: [input] input string to be parse
6304  *   @sizes   : [output] reference to store parsed sizes
6305  *
6306  * RETURN     : none
6307  *==========================================================================*/
parseSizesList(const char * sizesStr,Vector<Size> & sizes)6308 void QCameraParameters::parseSizesList(const char *sizesStr, Vector<Size> &sizes)
6309 {
6310     if (sizesStr == 0) {
6311         return;
6312     }
6313 
6314     char *sizeStartPtr = (char *)sizesStr;
6315 
6316     while (true) {
6317         int width, height;
6318         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
6319                                  &sizeStartPtr);
6320         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
6321             LOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
6322             return;
6323         }
6324         sizes.push(Size(width, height));
6325 
6326         if (*sizeStartPtr == '\0') {
6327             return;
6328         }
6329         sizeStartPtr++;
6330     }
6331 }
6332 
6333 /*===========================================================================
6334  * FUNCTION   : adjustPreviewFpsRange
6335  *
6336  * DESCRIPTION: adjust preview FPS ranges
6337  *              according to external events
6338  *
6339  * PARAMETERS :
6340  *   @minFPS  : min FPS value
6341  *   @maxFPS  : max FPS value
6342  *
6343  * RETURN     : int32_t type of status
6344  *              NO_ERROR  -- success
6345  *              none-zero failure code
6346  *==========================================================================*/
adjustPreviewFpsRange(cam_fps_range_t * fpsRange)6347 int32_t QCameraParameters::adjustPreviewFpsRange(cam_fps_range_t *fpsRange)
6348 {
6349     if ( fpsRange == NULL ) {
6350         return BAD_VALUE;
6351     }
6352 
6353     if ( m_pParamBuf == NULL ) {
6354         return NO_INIT;
6355     }
6356 
6357     int32_t rc = initBatchUpdate(m_pParamBuf);
6358     if ( rc != NO_ERROR ) {
6359         LOGE("Failed to initialize group update table");
6360         return rc;
6361     }
6362 
6363     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, *fpsRange)) {
6364         LOGE("Parameters batch failed");
6365         return BAD_VALUE;
6366     }
6367 
6368     rc = commitSetBatch();
6369     if ( rc != NO_ERROR ) {
6370         LOGE("Failed to commit batch parameters");
6371         return rc;
6372     }
6373 
6374     return rc;
6375 }
6376 
6377 /*===========================================================================
6378  * FUNCTION   : setPreviewFpsRanges
6379  *
6380  * DESCRIPTION: set preview FPS ranges
6381  *
6382  * PARAMETERS :
6383  *   @minFPS  : min FPS value
6384  *   @maxFPS  : max FPS value
6385  *
6386  * RETURN     : int32_t type of status
6387  *              NO_ERROR  -- success
6388  *              none-zero failure code
6389  *==========================================================================*/
setPreviewFpsRange(int min_fps,int max_fps,int vid_min_fps,int vid_max_fps)6390 int32_t QCameraParameters::setPreviewFpsRange(int min_fps,
6391         int max_fps, int vid_min_fps,int vid_max_fps)
6392 {
6393     char str[32];
6394     char value[PROPERTY_VALUE_MAX];
6395     int fixedFpsValue;
6396     /*This property get value should be the fps that user needs*/
6397     property_get("persist.debug.set.fixedfps", value, "0");
6398     fixedFpsValue = atoi(value);
6399 
6400     LOGD("E minFps = %d, maxFps = %d , vid minFps = %d, vid maxFps = %d",
6401                  min_fps, max_fps, vid_min_fps, vid_max_fps);
6402 
6403     if(fixedFpsValue != 0) {
6404       min_fps = max_fps = vid_min_fps = vid_max_fps = (int)fixedFpsValue*1000;
6405     }
6406     snprintf(str, sizeof(str), "%d,%d", min_fps, max_fps);
6407     LOGH("Setting preview fps range %s", str);
6408     updateParamEntry(KEY_PREVIEW_FPS_RANGE, str);
6409     cam_fps_range_t fps_range;
6410     memset(&fps_range, 0x00, sizeof(cam_fps_range_t));
6411     fps_range.min_fps = (float)min_fps / 1000.0f;
6412     fps_range.max_fps = (float)max_fps / 1000.0f;
6413     fps_range.video_min_fps = (float)vid_min_fps / 1000.0f;
6414     fps_range.video_max_fps = (float)vid_max_fps / 1000.0f;
6415 
6416     LOGH("Updated: minFps = %d, maxFps = %d ,"
6417             " vid minFps = %d, vid maxFps = %d",
6418              min_fps, max_fps, vid_min_fps, vid_max_fps);
6419 
6420     if ( NULL != m_AdjustFPS ) {
6421         if (m_ThermalMode == QCAMERA_THERMAL_ADJUST_FPS &&
6422                 !m_bRecordingHint) {
6423             float minVideoFps = min_fps, maxVideoFps = max_fps;
6424             if (isHfrMode()) {
6425                 minVideoFps = m_hfrFpsRange.video_min_fps;
6426                 maxVideoFps = m_hfrFpsRange.video_max_fps;
6427             }
6428             m_AdjustFPS->recalcFPSRange(min_fps, max_fps, minVideoFps, maxVideoFps, fps_range);
6429             LOGH("Thermal adjusted Preview fps range %3.2f,%3.2f, %3.2f, %3.2f",
6430                    fps_range.min_fps, fps_range.max_fps,
6431                   fps_range.video_min_fps, fps_range.video_max_fps);
6432         }
6433     }
6434 
6435     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FPS_RANGE, fps_range)) {
6436         return BAD_VALUE;
6437     }
6438 
6439     return NO_ERROR;
6440 }
6441 
6442 
6443 
6444 /*===========================================================================
6445  * FUNCTION   : setAutoExposure
6446  *
6447  * DESCRIPTION: set auto exposure
6448  *
6449  * PARAMETERS :
6450  *   @autoExp : auto exposure value string
6451  *
6452  * RETURN     : int32_t type of status
6453  *              NO_ERROR  -- success
6454  *              none-zero failure code
6455  *==========================================================================*/
setAutoExposure(const char * autoExp)6456 int32_t QCameraParameters::setAutoExposure(const char *autoExp)
6457 {
6458     if (autoExp != NULL) {
6459         int32_t value = lookupAttr(AUTO_EXPOSURE_MAP, PARAM_MAP_SIZE(AUTO_EXPOSURE_MAP), autoExp);
6460         if (value != NAME_NOT_FOUND) {
6461             LOGH("Setting auto exposure %s", autoExp);
6462             updateParamEntry(KEY_QC_AUTO_EXPOSURE, autoExp);
6463             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ALGO_TYPE, value)) {
6464                 return BAD_VALUE;
6465             }
6466             return NO_ERROR;
6467         }
6468     }
6469     LOGE("Invalid auto exposure value: %s", (autoExp == NULL) ? "NULL" : autoExp);
6470     return BAD_VALUE;
6471 }
6472 
6473 /*===========================================================================
6474  * FUNCTION   : setEffect
6475  *
6476  * DESCRIPTION: set effect
6477  *
6478  * PARAMETERS :
6479  *   @effect  : effect value string
6480  *
6481  * RETURN     : int32_t type of status
6482  *              NO_ERROR  -- success
6483  *              none-zero failure code
6484  *==========================================================================*/
setEffect(const char * effect)6485 int32_t QCameraParameters::setEffect(const char *effect)
6486 {
6487     if (effect != NULL) {
6488         int32_t value = lookupAttr(EFFECT_MODES_MAP, PARAM_MAP_SIZE(EFFECT_MODES_MAP), effect);
6489         if (value != NAME_NOT_FOUND) {
6490             LOGH("Setting effect %s", effect);
6491             updateParamEntry(KEY_EFFECT, effect);
6492             uint8_t prmEffect = static_cast<uint8_t>(value);
6493             mParmEffect = prmEffect;
6494             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EFFECT, prmEffect)) {
6495                 return BAD_VALUE;
6496             }
6497             return NO_ERROR;
6498         }
6499     }
6500     LOGE("Invalid effect value: %s", (effect == NULL) ? "NULL" : effect);
6501     return BAD_VALUE;
6502 }
6503 
6504 /*===========================================================================
6505  * FUNCTION   : setBrightness
6506  *
6507  * DESCRIPTION: set brightness control value
6508  *
6509  * PARAMETERS :
6510  *   @brightness  : brightness control value
6511  *
6512  * RETURN     : int32_t type of status
6513  *              NO_ERROR  -- success
6514  *              none-zero failure code
6515  *==========================================================================*/
setBrightness(int brightness)6516 int32_t QCameraParameters::setBrightness(int brightness)
6517 {
6518     char val[16];
6519     snprintf(val, sizeof(val), "%d", brightness);
6520     updateParamEntry(KEY_QC_BRIGHTNESS, val);
6521 
6522     LOGH("Setting brightness %s", val);
6523     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BRIGHTNESS, brightness)) {
6524         return BAD_VALUE;
6525     }
6526 
6527     return NO_ERROR;
6528 }
6529 
6530 /*===========================================================================
6531  * FUNCTION   : setFocusMode
6532  *
6533  * DESCRIPTION: set focus mode
6534  *
6535  * PARAMETERS :
6536  *   @focusMode  : focus mode value string
6537  *
6538  * RETURN     : int32_t type of status
6539  *              NO_ERROR  -- success
6540  *              none-zero failure code
6541  *==========================================================================*/
setFocusMode(const char * focusMode)6542 int32_t QCameraParameters::setFocusMode(const char *focusMode)
6543 {
6544     if (focusMode != NULL) {
6545         int32_t value = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focusMode);
6546         if (value != NAME_NOT_FOUND) {
6547             int32_t rc = NO_ERROR;
6548             LOGH("Setting focus mode %s", focusMode);
6549             mFocusMode = (cam_focus_mode_type)value;
6550 
6551             updateParamEntry(KEY_FOCUS_MODE, focusMode);
6552             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
6553                     CAM_INTF_PARM_FOCUS_MODE, (uint8_t)value)) {
6554                 rc = BAD_VALUE;
6555             }
6556             if (strcmp(focusMode,"infinity")==0){
6557                 set(QCameraParameters::KEY_FOCUS_DISTANCES, "Infinity,Infinity,Infinity");
6558             }
6559             return rc;
6560         }
6561     }
6562     LOGE("Invalid focus mode value: %s", (focusMode == NULL) ? "NULL" : focusMode);
6563     return BAD_VALUE;
6564 }
6565 
6566 /*===========================================================================
6567  * FUNCTION   : setFocusPosition
6568  *
6569  * DESCRIPTION: set focus position
6570  *
6571  * PARAMETERS :
6572  *   @typeStr : focus position type, index or dac_code
6573  *   @posStr : focus positon.
6574  *
6575  * RETURN     : int32_t type of status
6576  *              NO_ERROR  -- success
6577  *              none-zero failure code
6578  *==========================================================================*/
setFocusPosition(const char * typeStr,const char * posStr)6579 int32_t  QCameraParameters::setFocusPosition(const char *typeStr, const char *posStr)
6580 {
6581     LOGH(", type:%s, pos: %s", typeStr, posStr);
6582     int32_t type = atoi(typeStr);
6583     float pos = (float) atof(posStr);
6584 
6585     if ((type >= CAM_MANUAL_FOCUS_MODE_INDEX) &&
6586             (type < CAM_MANUAL_FOCUS_MODE_MAX)) {
6587         // get max and min focus position from m_pCapability
6588         float minFocusPos = m_pCapability->min_focus_pos[type];
6589         float maxFocusPos = m_pCapability->max_focus_pos[type];
6590         LOGH(", focusPos min: %f, max: %f", minFocusPos, maxFocusPos);
6591 
6592         if (pos >= minFocusPos && pos <= maxFocusPos) {
6593             updateParamEntry(KEY_QC_MANUAL_FOCUS_POS_TYPE, typeStr);
6594             updateParamEntry(KEY_QC_MANUAL_FOCUS_POSITION, posStr);
6595 
6596             cam_manual_focus_parm_t manual_focus;
6597             manual_focus.flag = (cam_manual_focus_mode_type)type;
6598             if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_DIOPTER) {
6599                 manual_focus.af_manual_diopter = pos;
6600             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_RATIO) {
6601                 manual_focus.af_manual_lens_position_ratio = (int32_t) pos;
6602             } else if (manual_focus.flag == CAM_MANUAL_FOCUS_MODE_INDEX) {
6603                 manual_focus.af_manual_lens_position_index = (int32_t) pos;
6604             } else {
6605                 manual_focus.af_manual_lens_position_dac = (int32_t) pos;
6606             }
6607 
6608             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MANUAL_FOCUS_POS,
6609                     manual_focus)) {
6610                 return BAD_VALUE;
6611             }
6612             return NO_ERROR;
6613         }
6614     }
6615 
6616     LOGE("invalid params, type:%d, pos: %f", type, pos);
6617     return BAD_VALUE;
6618 }
6619 
6620 /*===========================================================================
6621  * FUNCTION   : updateAEInfo
6622  *
6623  * DESCRIPTION: update exposure information from metadata callback
6624  *
6625  * PARAMETERS :
6626  *   @ae_params : auto exposure params
6627  *
6628  * RETURN     : void
6629  *==========================================================================*/
updateAEInfo(cam_3a_params_t & ae_params)6630 void  QCameraParameters::updateAEInfo(cam_3a_params_t &ae_params)
6631 {
6632     const char *prevExpTime = get(KEY_QC_CURRENT_EXPOSURE_TIME);
6633     char newExpTime[15];
6634     snprintf(newExpTime, sizeof(newExpTime), "%f", ae_params.exp_time*1000.0);
6635 
6636     if (prevExpTime == NULL || strcmp(prevExpTime, newExpTime)) {
6637         LOGD("update exposure time: old: %s, new: %s", prevExpTime, newExpTime);
6638         set(KEY_QC_CURRENT_EXPOSURE_TIME, newExpTime);
6639     }
6640 
6641     int32_t prevISO = getInt(KEY_QC_CURRENT_ISO);
6642     int32_t newISO = ae_params.iso_value;
6643     if (prevISO != newISO) {
6644         LOGD("update iso: old:%d, new:%d", prevISO, newISO);
6645         set(KEY_QC_CURRENT_ISO, newISO);
6646     }
6647 }
6648 
6649 /*===========================================================================
6650  * FUNCTION   : updateCurrentFocusPosition
6651  *
6652  * DESCRIPTION: update current focus position from metadata callback
6653  *
6654  * PARAMETERS :
6655  *   @pos : current focus position
6656  *
6657  * RETURN     : void
6658  *==========================================================================*/
updateCurrentFocusPosition(cam_focus_pos_info_t & cur_pos_info)6659 void  QCameraParameters::updateCurrentFocusPosition(cam_focus_pos_info_t &cur_pos_info)
6660 {
6661     int prevScalePos = getInt(KEY_QC_FOCUS_POSITION_SCALE);
6662     int newScalePos = (int) cur_pos_info.scale;
6663     if (prevScalePos != newScalePos) {
6664         LOGD("update focus scale: old:%d, new:%d", prevScalePos, newScalePos);
6665         set(KEY_QC_FOCUS_POSITION_SCALE, newScalePos);
6666     }
6667 
6668     float prevDiopterPos = getFloat(KEY_QC_FOCUS_POSITION_DIOPTER);
6669     float newDiopterPos = cur_pos_info.diopter;
6670     if (prevDiopterPos != newDiopterPos) {
6671         LOGD("update focus diopter: old:%f, new:%f", prevDiopterPos, newDiopterPos);
6672         setFloat(KEY_QC_FOCUS_POSITION_DIOPTER, newDiopterPos);
6673     }
6674 }
6675 
6676 /*===========================================================================
6677  * FUNCTION   : setSharpness
6678  *
6679  * DESCRIPTION: set sharpness control value
6680  *
6681  * PARAMETERS :
6682  *   @sharpness  : sharpness control value
6683  *
6684  * RETURN     : int32_t type of status
6685  *              NO_ERROR  -- success
6686  *              none-zero failure code
6687  *==========================================================================*/
setSharpness(int sharpness)6688 int32_t QCameraParameters::setSharpness(int sharpness)
6689 {
6690     char val[16];
6691     snprintf(val, sizeof(val), "%d", sharpness);
6692     updateParamEntry(KEY_QC_SHARPNESS, val);
6693     LOGH("Setting sharpness %s", val);
6694     m_nSharpness = sharpness;
6695     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SHARPNESS, m_nSharpness)) {
6696         return BAD_VALUE;
6697     }
6698 
6699     return NO_ERROR;
6700 }
6701 
6702 /*===========================================================================
6703  * FUNCTION   : setSkinToneEnhancement
6704  *
6705  * DESCRIPTION: set skin tone enhancement value
6706  *
6707  * PARAMETERS :
6708  *   @sceFactore  : skin tone enhancement factor value
6709  *
6710  * RETURN     : int32_t type of status
6711  *              NO_ERROR  -- success
6712  *              none-zero failure code
6713  *==========================================================================*/
setSkinToneEnhancement(int sceFactor)6714 int32_t QCameraParameters::setSkinToneEnhancement(int sceFactor)
6715 {
6716     char val[16];
6717     snprintf(val, sizeof(val), "%d", sceFactor);
6718     updateParamEntry(KEY_QC_SCE_FACTOR, val);
6719     LOGH("Setting skintone enhancement %s", val);
6720 
6721     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SCE_FACTOR, sceFactor)) {
6722         return BAD_VALUE;
6723     }
6724 
6725     return NO_ERROR;
6726 }
6727 
6728 /*===========================================================================
6729  * FUNCTION   : setSaturation
6730  *
6731  * DESCRIPTION: set saturation control value
6732  *
6733  * PARAMETERS :
6734  *   @saturation : saturation control value
6735  *
6736  * RETURN     : int32_t type of status
6737  *              NO_ERROR  -- success
6738  *              none-zero failure code
6739  *==========================================================================*/
setSaturation(int saturation)6740 int32_t QCameraParameters::setSaturation(int saturation)
6741 {
6742     char val[16];
6743     snprintf(val, sizeof(val), "%d", saturation);
6744     updateParamEntry(KEY_QC_SATURATION, val);
6745     LOGH("Setting saturation %s", val);
6746 
6747     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SATURATION, saturation)) {
6748         return BAD_VALUE;
6749     }
6750 
6751     return NO_ERROR;
6752 }
6753 
6754 /*===========================================================================
6755  * FUNCTION   : setContrast
6756  *
6757  * DESCRIPTION: set contrast control value
6758  *
6759  * PARAMETERS :
6760  *   @contrast : contrast control value
6761  *
6762  * RETURN     : int32_t type of status
6763  *              NO_ERROR  -- success
6764  *              none-zero failure code
6765  *==========================================================================*/
setContrast(int contrast)6766 int32_t QCameraParameters::setContrast(int contrast)
6767 {
6768     char val[16];
6769     snprintf(val, sizeof(val), "%d", contrast);
6770     updateParamEntry(KEY_QC_CONTRAST, val);
6771     LOGH("Setting contrast %s", val);
6772 
6773     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CONTRAST, contrast)) {
6774         return BAD_VALUE;
6775     }
6776 
6777     return NO_ERROR;
6778 }
6779 
6780 /*===========================================================================
6781  * FUNCTION   : setSceneDetect
6782  *
6783  * DESCRIPTION: set scenen detect value
6784  *
6785  * PARAMETERS :
6786  *   @sceneDetect  : scene detect value string
6787  *
6788  * RETURN     : int32_t type of status
6789  *              NO_ERROR  -- success
6790  *              none-zero failure code
6791  *==========================================================================*/
setSceneDetect(const char * sceneDetect)6792 int32_t QCameraParameters::setSceneDetect(const char *sceneDetect)
6793 {
6794     if (sceneDetect != NULL) {
6795         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
6796                 sceneDetect);
6797         if (value != NAME_NOT_FOUND) {
6798             LOGH("Setting Scene Detect %s", sceneDetect);
6799             updateParamEntry(KEY_QC_SCENE_DETECT, sceneDetect);
6800             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ASD_ENABLE, value)) {
6801                 return BAD_VALUE;
6802             }
6803             return NO_ERROR;
6804         }
6805     }
6806     LOGE("Invalid Scene Detect value: %s",
6807           (sceneDetect == NULL) ? "NULL" : sceneDetect);
6808     return BAD_VALUE;
6809 }
6810 
6811 /*===========================================================================
6812  * FUNCTION   : setSensorSnapshotHDR
6813  *
6814  * DESCRIPTION: set snapshot HDR value
6815  *
6816  * PARAMETERS :
6817  *   @snapshotHDR  : snapshot HDR value string
6818  *
6819  * RETURN     : int32_t type of status
6820  *              NO_ERROR  -- success
6821  *              none-zero failure code
6822  *==========================================================================*/
setSensorSnapshotHDR(const char * snapshotHDR)6823 int32_t QCameraParameters::setSensorSnapshotHDR(const char *snapshotHDR)
6824 {
6825     if (snapshotHDR != NULL) {
6826         int32_t value = (cam_sensor_hdr_type_t) lookupAttr(ON_OFF_MODES_MAP,
6827                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP), snapshotHDR);
6828         if (value != NAME_NOT_FOUND) {
6829             LOGH("Setting Sensor Snapshot HDR %s", snapshotHDR);
6830             updateParamEntry(KEY_QC_SENSOR_HDR, snapshotHDR);
6831 
6832             char zz_prop[PROPERTY_VALUE_MAX];
6833             memset(zz_prop, 0, sizeof(zz_prop));
6834             property_get("persist.camera.zzhdr.enable", zz_prop, "0");
6835             uint8_t zzhdr_enable = (uint8_t)atoi(zz_prop);
6836 
6837             if (zzhdr_enable && (value != CAM_SENSOR_HDR_OFF)) {
6838                 value = CAM_SENSOR_HDR_ZIGZAG;
6839                 LOGH("%s: Overriding to ZZ HDR Mode", __func__);
6840             }
6841 
6842             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t)value)) {
6843                 return BAD_VALUE;
6844             }
6845             return NO_ERROR;
6846         }
6847     }
6848     LOGE("Invalid Snapshot HDR value: %s",
6849           (snapshotHDR == NULL) ? "NULL" : snapshotHDR);
6850     return BAD_VALUE;
6851 
6852 }
6853 
6854 
6855 /*===========================================================================
6856  * FUNCTION   : setVideoHDR
6857  *
6858  * DESCRIPTION: set video HDR value
6859  *
6860  * PARAMETERS :
6861  *   @videoHDR  : svideo HDR value string
6862  *
6863  * RETURN     : int32_t type of status
6864  *              NO_ERROR  -- success
6865  *              none-zero failure code
6866  *==========================================================================*/
setVideoHDR(const char * videoHDR)6867 int32_t QCameraParameters::setVideoHDR(const char *videoHDR)
6868 {
6869     if (videoHDR != NULL) {
6870         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), videoHDR);
6871         if (value != NAME_NOT_FOUND) {
6872 
6873             char zz_prop[PROPERTY_VALUE_MAX];
6874             memset(zz_prop, 0, sizeof(zz_prop));
6875             property_get("persist.camera.zzhdr.video", zz_prop, "0");
6876             uint8_t use_zzhdr_video = (uint8_t)atoi(zz_prop);
6877 
6878             if (use_zzhdr_video) {
6879                 LOGH("%s: Using ZZ HDR for video mode", __func__);
6880                 if (value)
6881                     value = CAM_SENSOR_HDR_ZIGZAG;
6882                 else
6883                     value = CAM_SENSOR_HDR_OFF;
6884                 LOGH("%s: Overriding to sensor HDR Mode to:%d", __func__, value);
6885                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_SENSOR_HDR, (cam_sensor_hdr_type_t) value)) {
6886                     LOGE("%s: Override to sensor HDR mode for video HDR failed", __func__);
6887                     return BAD_VALUE;
6888                 }
6889                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
6890             } else {
6891                 LOGH("%s: Setting Video HDR %s", __func__, videoHDR);
6892                 updateParamEntry(KEY_QC_VIDEO_HDR, videoHDR);
6893                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VIDEO_HDR, value)) {
6894                     return BAD_VALUE;
6895                 }
6896             }
6897 
6898             return NO_ERROR;
6899         }
6900     }
6901     LOGE("Invalid Video HDR value: %s",
6902           (videoHDR == NULL) ? "NULL" : videoHDR);
6903     return BAD_VALUE;
6904 }
6905 
6906 
6907 
6908 /*===========================================================================
6909  * FUNCTION   : setVtEnable
6910  *
6911  * DESCRIPTION: set vt Enable value
6912  *
6913  * PARAMETERS :
6914  *   @videoHDR  : svtEnable value string
6915  *
6916  * RETURN     : int32_t type of status
6917  *              NO_ERROR  -- success
6918  *              none-zero failure code
6919  *==========================================================================*/
setVtEnable(const char * vtEnable)6920 int32_t QCameraParameters::setVtEnable(const char *vtEnable)
6921 {
6922     if (vtEnable != NULL) {
6923         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
6924                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), vtEnable);
6925         if (value != NAME_NOT_FOUND) {
6926             LOGH("Setting Vt Enable %s", vtEnable);
6927             m_bAVTimerEnabled = true;
6928             updateParamEntry(KEY_QC_VT_ENABLE, vtEnable);
6929             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_VT, value)) {
6930                 return BAD_VALUE;
6931             }
6932             return NO_ERROR;
6933         }
6934     }
6935     LOGE("Invalid Vt Enable value: %s",
6936           (vtEnable == NULL) ? "NULL" : vtEnable);
6937     m_bAVTimerEnabled = false;
6938     return BAD_VALUE;
6939 }
6940 
6941 /*===========================================================================
6942  * FUNCTION   : setFaceRecognition
6943  *
6944  * DESCRIPTION: set face recognition value
6945  *
6946  * PARAMETERS :
6947  *   @faceRecog  : face recognition value string
6948  *   @maxFaces   : number of max faces to be detected/recognized
6949  *
6950  * RETURN     : int32_t type of status
6951  *              NO_ERROR  -- success
6952  *              none-zero failure code
6953  *==========================================================================*/
setFaceRecognition(const char * faceRecog,uint32_t maxFaces)6954 int32_t QCameraParameters::setFaceRecognition(const char *faceRecog,
6955         uint32_t maxFaces)
6956 {
6957     if (faceRecog != NULL) {
6958         int32_t value = lookupAttr(ON_OFF_MODES_MAP, PARAM_MAP_SIZE(ON_OFF_MODES_MAP), faceRecog);
6959         if (value != NAME_NOT_FOUND) {
6960             LOGH("Setting face recognition %s", faceRecog);
6961             updateParamEntry(KEY_QC_FACE_RECOGNITION, faceRecog);
6962 
6963             uint32_t faceProcMask = m_nFaceProcMask;
6964             if (value > 0) {
6965                 faceProcMask |= CAM_FACE_PROCESS_MASK_RECOGNITION;
6966             } else {
6967                 faceProcMask &= (uint32_t)(~CAM_FACE_PROCESS_MASK_RECOGNITION);
6968             }
6969 
6970             if(m_nFaceProcMask == faceProcMask) {
6971                 LOGH("face process mask not changed, no ops here");
6972                 return NO_ERROR;
6973             }
6974             m_nFaceProcMask = faceProcMask;
6975             LOGH("FaceProcMask -> %d", m_nFaceProcMask);
6976 
6977             // set parm for face process
6978             cam_fd_set_parm_t fd_set_parm;
6979             memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
6980             fd_set_parm.fd_mode = m_nFaceProcMask;
6981             fd_set_parm.num_fd = maxFaces;
6982 
6983             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
6984                 return BAD_VALUE;
6985             }
6986             return NO_ERROR;
6987         }
6988     }
6989     LOGE("Invalid face recognition value: %s", (faceRecog == NULL) ? "NULL" : faceRecog);
6990     return BAD_VALUE;
6991 }
6992 
6993 /*===========================================================================
6994  * FUNCTION   : setZoom
6995  *
6996  * DESCRIPTION: set zoom level
6997  *
6998  * PARAMETERS :
6999  *   @zoom_level : zoom level
7000  *
7001  * RETURN     : int32_t type of status
7002  *              NO_ERROR  -- success
7003  *              none-zero failure code
7004  *==========================================================================*/
setZoom(int zoom_level)7005 int32_t QCameraParameters::setZoom(int zoom_level)
7006 {
7007     char val[16];
7008     snprintf(val, sizeof(val), "%d", zoom_level);
7009     updateParamEntry(KEY_ZOOM, val);
7010     LOGH("zoom level: %d", zoom_level);
7011     mZoomLevel = zoom_level;
7012     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
7013         return BAD_VALUE;
7014     }
7015 
7016     return NO_ERROR;
7017 }
7018 
7019 /*===========================================================================
7020  * FUNCTION   : setISOValue
7021  *
7022  * DESCRIPTION: set ISO value
7023  *
7024  * PARAMETERS :
7025  *   @isoValue : ISO value string
7026  *
7027  * RETURN     : int32_t type of status
7028  *              NO_ERROR  -- success
7029  *              none-zero failure code
7030  *==========================================================================*/
setISOValue(const char * isoValue)7031 int32_t  QCameraParameters::setISOValue(const char *isoValue)
7032 {
7033     if (isoValue != NULL) {
7034         if (!strcmp(isoValue, ISO_MANUAL)) {
7035             LOGD("iso manual mode - use continuous iso");
7036             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
7037             return NO_ERROR;
7038         }
7039         int32_t value = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), isoValue);
7040         if (value != NAME_NOT_FOUND) {
7041             LOGH("Setting ISO value %s", isoValue);
7042             updateParamEntry(KEY_QC_ISO_MODE, isoValue);
7043 
7044             cam_intf_parm_manual_3a_t iso_settings;
7045             memset(&iso_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
7046             iso_settings.previewOnly = FALSE;
7047             iso_settings.value = value;
7048             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7049                 iso_settings.previewOnly = TRUE;
7050             }
7051 
7052             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ISO, iso_settings)) {
7053                 return BAD_VALUE;
7054             }
7055             m_isoValue = value;
7056             return NO_ERROR;
7057         }
7058     }
7059     LOGE("Invalid ISO value: %s",
7060           (isoValue == NULL) ? "NULL" : isoValue);
7061     return BAD_VALUE;
7062 }
7063 
7064 
7065 /*===========================================================================
7066  * FUNCTION   : setContinuousISO
7067  *
7068  * DESCRIPTION: set continuous ISO value
7069  *
7070  * PARAMETERS :
7071  *   @params : ISO value parameter
7072  *
7073  * RETURN     : int32_t type of status
7074  *              NO_ERROR  -- success
7075  *              none-zero failure code
7076  *==========================================================================*/
setContinuousISO(const QCameraParameters & params)7077 int32_t  QCameraParameters::setContinuousISO(const QCameraParameters& params)
7078 {
7079     const char *iso = params.get(KEY_QC_ISO_MODE);
7080     LOGD("current iso mode: %s", iso);
7081 
7082     if (iso != NULL) {
7083         if (strcmp(iso, ISO_MANUAL)) {
7084             LOGD("dont set iso to back-end.");
7085             return NO_ERROR;
7086         }
7087     }
7088 
7089     const char *str = params.get(KEY_QC_CONTINUOUS_ISO);
7090     const char *prev_str = get(KEY_QC_CONTINUOUS_ISO);
7091     if (str != NULL) {
7092         if (prev_str == NULL ||
7093             strcmp(str, prev_str) != 0) {
7094             return setContinuousISO(str);
7095         }
7096     }
7097     return NO_ERROR;
7098 }
7099 
7100 /*===========================================================================
7101  * FUNCTION   : setExposureTime
7102  *
7103  * DESCRIPTION: set exposure time
7104  *
7105  * PARAMETERS :
7106  *   @expTimeStr : string of exposure time in ms
7107  *
7108  * RETURN     : int32_t type of status
7109  *              NO_ERROR  -- success
7110  *              none-zero failure code
7111  *==========================================================================*/
setExposureTime(const char * expTimeStr)7112 int32_t  QCameraParameters::setExposureTime(const char *expTimeStr)
7113 {
7114     if (expTimeStr != NULL) {
7115         double expTimeMs = atof(expTimeStr);
7116         //input is in milli seconds. Convert to nano sec for backend
7117         int64_t expTimeNs = (int64_t)(expTimeMs*1000000L);
7118 
7119         // expTime == 0 means not to use manual exposure time.
7120         if ((0 <= expTimeNs) &&
7121                 ((expTimeNs == 0) ||
7122                 ((expTimeNs >= m_pCapability->exposure_time_range[0]) &&
7123                 (expTimeNs <= m_pCapability->exposure_time_range[1])))) {
7124             LOGH(", exposure time: %f ms", expTimeMs);
7125             updateParamEntry(KEY_QC_EXPOSURE_TIME, expTimeStr);
7126 
7127             cam_intf_parm_manual_3a_t exp_settings;
7128             memset(&exp_settings, 0, sizeof(cam_intf_parm_manual_3a_t));
7129             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7130                 exp_settings.previewOnly = TRUE;
7131                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
7132                     exp_settings.value = expTimeNs;
7133                 } else {
7134                     exp_settings.value =
7135                             (int64_t)(QCAMERA_MAX_EXP_TIME_LEVEL1*1000000L);
7136                 }
7137             } else {
7138                 exp_settings.previewOnly = FALSE;
7139                 exp_settings.value = expTimeNs;
7140             }
7141 
7142             //Based on exposure values we can decide the capture type here
7143             if (getManualCaptureMode() != CAM_MANUAL_CAPTURE_TYPE_OFF) {
7144                 if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL1) {
7145                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_1);
7146                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL2) {
7147                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_2);
7148                 } else if (expTimeMs < QCAMERA_MAX_EXP_TIME_LEVEL4) {
7149                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_3);
7150                 } else {
7151                     setManualCaptureMode(CAM_MANUAL_CAPTURE_TYPE_OFF);
7152                 }
7153             }
7154 
7155             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_TIME,
7156                     exp_settings)) {
7157                 return BAD_VALUE;
7158             }
7159             m_expTime = expTimeNs;
7160 
7161             return NO_ERROR;
7162         }
7163     }
7164 
7165     LOGE("Invalid exposure time, value: %s",
7166           (expTimeStr == NULL) ? "NULL" : expTimeStr);
7167     return BAD_VALUE;
7168 }
7169 
7170 /*===========================================================================
7171  * FUNCTION   : setLongshotEnable
7172  *
7173  * DESCRIPTION: set a flag indicating longshot mode
7174  *
7175  * PARAMETERS :
7176  *   @enable  : true - Longshot enabled
7177  *              false - Longshot disabled
7178  *
7179  * RETURN     : int32_t type of status
7180  *              NO_ERROR  -- success
7181  *              none-zero failure code
7182  *==========================================================================*/
setLongshotEnable(bool enable)7183 int32_t QCameraParameters::setLongshotEnable(bool enable)
7184 {
7185     int32_t rc = NO_ERROR;
7186     int8_t value = enable ? 1 : 0;
7187 
7188     if(initBatchUpdate(m_pParamBuf) < 0 ) {
7189         LOGE("Failed to initialize group update table");
7190         return BAD_TYPE;
7191     }
7192 
7193     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LONGSHOT_ENABLE, value)) {
7194         LOGE("Failed to update table");
7195         return BAD_VALUE;
7196     }
7197 
7198     rc = commitSetBatch();
7199     if (rc != NO_ERROR) {
7200         LOGE("Failed to parameter changes");
7201         return rc;
7202     }
7203 
7204     if (enable == true) m_bLongshotEnabled = enable;
7205 
7206     return rc;
7207 }
7208 
7209 /*===========================================================================
7210  * FUNCTION   : setFlash
7211  *
7212  * DESCRIPTION: set flash mode
7213  *
7214  * PARAMETERS :
7215  *   @flashStr : LED flash mode value string
7216  *
7217  * RETURN     : int32_t type of status
7218  *              NO_ERROR  -- success
7219  *              none-zero failure code
7220  *==========================================================================*/
setFlash(const char * flashStr)7221 int32_t QCameraParameters::setFlash(const char *flashStr)
7222 {
7223     if (flashStr != NULL) {
7224         int32_t value = lookupAttr(FLASH_MODES_MAP, PARAM_MAP_SIZE(FLASH_MODES_MAP), flashStr);
7225         if (value != NAME_NOT_FOUND) {
7226             LOGH("Setting Flash value %s", flashStr);
7227             updateParamEntry(KEY_FLASH_MODE, flashStr);
7228             mFlashValue = value;
7229             return NO_ERROR;
7230         }
7231     }
7232     LOGE("Invalid flash value: %s", (flashStr == NULL) ? "NULL" : flashStr);
7233     return BAD_VALUE;
7234 }
7235 
7236 /*===========================================================================
7237  * FUNCTION   : updateFlashMode
7238  *
7239  * DESCRIPTION: update flash mode
7240  *
7241  * PARAMETERS :
7242  *   @flashStr : LED flash mode value
7243  *
7244  * RETURN     : int32_t type of status
7245  *              NO_ERROR  -- success
7246  *              none-zero failure code
7247  *==========================================================================*/
updateFlashMode(cam_flash_mode_t flash_mode)7248 int32_t QCameraParameters::updateFlashMode(cam_flash_mode_t flash_mode)
7249 {
7250     int32_t rc = NO_ERROR;
7251     if (flash_mode >= CAM_FLASH_MODE_MAX) {
7252         LOGH("Error!! Invalid flash mode (%d)", flash_mode);
7253         return BAD_VALUE;
7254     }
7255     LOGH("Setting Flash mode from EZTune %d", flash_mode);
7256 
7257     const char *flash_mode_str = lookupNameByValue(FLASH_MODES_MAP,
7258             PARAM_MAP_SIZE(FLASH_MODES_MAP), flash_mode);
7259     if(initBatchUpdate(m_pParamBuf) < 0 ) {
7260         LOGE("Failed to initialize group update table");
7261         return BAD_TYPE;
7262     }
7263     rc = setFlash(flash_mode_str);
7264     if (rc != NO_ERROR) {
7265         LOGE("Failed to update Flash mode");
7266         return rc;
7267     }
7268 
7269     LOGH("Setting Flash mode %d", mFlashValue);
7270     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, mFlashValue)) {
7271         LOGE("Failed to set led mode");
7272         return BAD_VALUE;
7273     }
7274 
7275     rc = commitSetBatch();
7276     if (rc != NO_ERROR) {
7277         LOGE("Failed to commit parameters");
7278         return rc;
7279     }
7280 
7281     return NO_ERROR;
7282 }
7283 
7284 
7285 /*===========================================================================
7286  * FUNCTION   : configureFlash
7287  *
7288  * DESCRIPTION: configure Flash Bracketing.
7289  *
7290  * PARAMETERS :
7291  *    @frame_config : output configuration structure to fill in.
7292  *
7293  * RETURN     : int32_t type of status
7294  *              NO_ERROR  -- success
7295  *              none-zero failure code
7296  *==========================================================================*/
configureFlash(cam_capture_frame_config_t & frame_config)7297 int32_t QCameraParameters::configureFlash(cam_capture_frame_config_t &frame_config)
7298 {
7299     LOGH("E");
7300     int32_t rc = NO_ERROR;
7301     uint32_t i = 0;
7302 
7303     if (isChromaFlashEnabled()) {
7304 
7305         rc = setToneMapMode(false, false);
7306         if (rc != NO_ERROR) {
7307             LOGE("Failed to configure tone map");
7308             return rc;
7309         }
7310 
7311         rc = setCDSMode(CAM_CDS_MODE_OFF, false);
7312         if (rc != NO_ERROR) {
7313             LOGE("Failed to configure csd mode");
7314             return rc;
7315         }
7316 
7317         LOGH("Enable Chroma Flash capture");
7318         cam_flash_mode_t flash_mode = CAM_FLASH_MODE_OFF;
7319         frame_config.num_batch =
7320                 m_pCapability->chroma_flash_settings_need.burst_count;
7321         if (frame_config.num_batch > CAM_MAX_FLASH_BRACKETING) {
7322             frame_config.num_batch = CAM_MAX_FLASH_BRACKETING;
7323         }
7324         for (i = 0; i < frame_config.num_batch; i++) {
7325             flash_mode = (m_pCapability->chroma_flash_settings_need.flash_bracketing[i]) ?
7326                     CAM_FLASH_MODE_ON:CAM_FLASH_MODE_OFF;
7327             frame_config.configs[i].num_frames = 1;
7328             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
7329             frame_config.configs[i].flash_mode = flash_mode;
7330         }
7331     } else if (mFlashValue != CAM_FLASH_MODE_OFF) {
7332         frame_config.num_batch = 1;
7333         for (i = 0; i < frame_config.num_batch; i++) {
7334             frame_config.configs[i].num_frames = getNumOfSnapshots();
7335             frame_config.configs[i].type = CAM_CAPTURE_FLASH;
7336             frame_config.configs[i].flash_mode =(cam_flash_mode_t)mFlashValue;
7337         }
7338     }
7339 
7340     LOGD("Flash frame batch cnt = %d",frame_config.num_batch);
7341     return rc;
7342 }
7343 
7344 /*===========================================================================
7345  * FUNCTION   : configureHDRBracketing
7346  *
7347  * DESCRIPTION: configure HDR Bracketing.
7348  *
7349  * PARAMETERS :
7350  *    @frame_config : output configuration structure to fill in.
7351  *
7352  * RETURN     : int32_t type of status
7353  *              NO_ERROR  -- success
7354  *              none-zero failure code
7355  *==========================================================================*/
configureHDRBracketing(cam_capture_frame_config_t & frame_config)7356 int32_t QCameraParameters::configureHDRBracketing(cam_capture_frame_config_t &frame_config)
7357 {
7358     LOGH("E");
7359     int32_t rc = NO_ERROR;
7360     uint32_t i = 0;
7361 
7362     uint32_t hdrFrameCount = m_pCapability->hdr_bracketing_setting.num_frames;
7363     LOGH("HDR values %d, %d frame count: %u",
7364           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[0],
7365           (int8_t) m_pCapability->hdr_bracketing_setting.exp_val.values[1],
7366           hdrFrameCount);
7367 
7368     frame_config.num_batch = hdrFrameCount;
7369 
7370     cam_bracket_mode mode =
7371             m_pCapability->hdr_bracketing_setting.exp_val.mode;
7372     if (mode == CAM_EXP_BRACKETING_ON) {
7373         rc = setToneMapMode(false, true);
7374         if (rc != NO_ERROR) {
7375             LOGW("Failed to disable tone map during HDR");
7376         }
7377     }
7378     for (i = 0; i < frame_config.num_batch; i++) {
7379         frame_config.configs[i].num_frames = 1;
7380         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
7381         frame_config.configs[i].hdr_mode.mode = mode;
7382         frame_config.configs[i].hdr_mode.values =
7383                 m_pCapability->hdr_bracketing_setting.exp_val.values[i];
7384         LOGD("exp values %d",
7385                 (int)frame_config.configs[i].hdr_mode.values);
7386     }
7387     return rc;
7388 }
7389 
7390 /*===========================================================================
7391  * FUNCTION   : configureAEBracketing
7392  *
7393  * DESCRIPTION: configure AE Bracketing.
7394  *
7395  * PARAMETERS :
7396  *    @frame_config : output configuration structure to fill in.
7397  *
7398  * RETURN     : int32_t type of status
7399  *              NO_ERROR  -- success
7400  *              none-zero failure code
7401  *==========================================================================*/
configureAEBracketing(cam_capture_frame_config_t & frame_config)7402 int32_t QCameraParameters::configureAEBracketing(cam_capture_frame_config_t &frame_config)
7403 {
7404     LOGH("E");
7405     int32_t rc = NO_ERROR;
7406     uint32_t i = 0;
7407     char exp_value[MAX_EXP_BRACKETING_LENGTH];
7408 
7409     rc = setToneMapMode(false, true);
7410     if (rc != NO_ERROR) {
7411         LOGH("Failed to disable tone map during AEBracketing");
7412     }
7413 
7414     uint32_t burstCount = 0;
7415     const char *str_val = m_AEBracketingClient.values;
7416     if ((str_val != NULL) && (strlen(str_val) > 0)) {
7417         char prop[PROPERTY_VALUE_MAX];
7418         memset(prop, 0, sizeof(prop));
7419         strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
7420         char *saveptr = NULL;
7421         char *token = strtok_r(prop, ",", &saveptr);
7422         if (token != NULL) {
7423             exp_value[burstCount++] = (char)atoi(token);
7424             while (token != NULL) {
7425                 token = strtok_r(NULL, ",", &saveptr);
7426                 if (token != NULL) {
7427                     exp_value[burstCount++] = (char)atoi(token);
7428                 }
7429             }
7430         }
7431     }
7432 
7433     frame_config.num_batch = burstCount;
7434     cam_bracket_mode mode = m_AEBracketingClient.mode;
7435 
7436     for (i = 0; i < frame_config.num_batch; i++) {
7437         frame_config.configs[i].num_frames = 1;
7438         frame_config.configs[i].type = CAM_CAPTURE_BRACKETING;
7439         frame_config.configs[i].hdr_mode.mode = mode;
7440         frame_config.configs[i].hdr_mode.values =
7441                 m_AEBracketingClient.values[i];
7442         LOGD("exp values %d", (int)m_AEBracketingClient.values[i]);
7443     }
7444 
7445     LOGH("num_frame = %d X", burstCount);
7446     return rc;
7447 }
7448 
7449 /*===========================================================================
7450  * FUNCTION   : configureLowLight
7451  *
7452  * DESCRIPTION: configure low light frame capture use case.
7453  *
7454  * PARAMETERS :
7455  *    @frame_config : output configuration structure to fill in.
7456  *
7457  * RETURN     : int32_t type of status
7458  *              NO_ERROR  -- success
7459  *              none-zero failure code
7460  *==========================================================================*/
configureLowLight(cam_capture_frame_config_t & frame_config)7461 int32_t QCameraParameters::configureLowLight(cam_capture_frame_config_t &frame_config)
7462 {
7463     int32_t rc = NO_ERROR;
7464 
7465     frame_config.num_batch = 1;
7466     frame_config.configs[0].num_frames = getNumOfSnapshots();
7467     frame_config.configs[0].type = CAM_CAPTURE_LOW_LIGHT;
7468     frame_config.configs[0].low_light_mode = CAM_LOW_LIGHT_ON;
7469     LOGH("Snapshot Count: %d", frame_config.configs[0].num_frames);
7470     return rc;
7471 }
7472 
7473 /*===========================================================================
7474  * FUNCTION   : configureManualCapture
7475  *
7476  * DESCRIPTION: configure manual capture.
7477  *
7478  * PARAMETERS :
7479  *    @frame_config : output configaration structure to fill in.
7480  *
7481  * RETURN     : int32_t type of status
7482  *              NO_ERROR  -- success
7483  *              none-zero failure code
7484  *==========================================================================*/
configureManualCapture(cam_capture_frame_config_t & frame_config)7485 int32_t QCameraParameters::configureManualCapture(cam_capture_frame_config_t &frame_config)
7486 {
7487     int32_t rc = NO_ERROR;
7488     uint32_t i = 0;
7489 
7490     LOGD("E");
7491     if (getManualCaptureMode()) {
7492         frame_config.num_batch = 1;
7493         for (i = 0; i < frame_config.num_batch; i++) {
7494             frame_config.configs[i].num_frames = getNumOfSnapshots();
7495             frame_config.configs[i].type = CAM_CAPTURE_MANUAL_3A;
7496             if (m_expTime != 0) {
7497                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_ON;
7498                 frame_config.configs[i].manual_3A_mode.exp_time = m_expTime;
7499             } else {
7500                 frame_config.configs[i].manual_3A_mode.exp_mode = CAM_SETTINGS_TYPE_AUTO;
7501                 frame_config.configs[i].manual_3A_mode.exp_time = 0;
7502             }
7503 
7504             if (m_isoValue != 0) {
7505                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_ON;
7506                 frame_config.configs[i].manual_3A_mode.iso_value = m_isoValue;
7507             } else {
7508                 frame_config.configs[i].manual_3A_mode.iso_mode = CAM_SETTINGS_TYPE_AUTO;
7509                 frame_config.configs[i].manual_3A_mode.iso_value = 0;
7510             }
7511         }
7512     }
7513     LOGD("X: batch cnt = %d", frame_config.num_batch);
7514     return rc;
7515 }
7516 
7517 /*===========================================================================
7518  * FUNCTION   : configFrameCapture
7519  *
7520  * DESCRIPTION: configuration for ZSL special captures (FLASH/HDR etc)
7521  *
7522  * PARAMETERS :
7523  *   @commitSettings : flag to enable or disable commit this this settings
7524  *
7525  * RETURN     : int32_t type of status
7526  *              NO_ERROR  -- success
7527  *              none-zero failure code
7528  *==========================================================================*/
configFrameCapture(bool commitSettings)7529 int32_t QCameraParameters::configFrameCapture(bool commitSettings)
7530 {
7531     int32_t rc = NO_ERROR;
7532     int32_t value;
7533 
7534     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
7535 
7536     if (commitSettings) {
7537         if(initBatchUpdate(m_pParamBuf) < 0 ) {
7538             LOGE("Failed to initialize group update table");
7539             return BAD_TYPE;
7540         }
7541     }
7542 
7543     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
7544           m_bOptiZoomOn || m_bReFocusOn || m_LowLightLevel
7545           || getManualCaptureMode()) {
7546         value = CAM_FLASH_MODE_OFF;
7547     } else if (isChromaFlashEnabled()) {
7548         value = CAM_FLASH_MODE_ON;
7549     } else {
7550         value = mFlashValue;
7551     }
7552 
7553     if (value != CAM_FLASH_MODE_OFF) {
7554         configureFlash(m_captureFrameConfig);
7555     } else if(isHDREnabled()) {
7556         configureHDRBracketing (m_captureFrameConfig);
7557     } else if(isAEBracketEnabled()) {
7558         configureAEBracketing (m_captureFrameConfig);
7559     } else if (m_LowLightLevel) {
7560         configureLowLight (m_captureFrameConfig);
7561 
7562         //Added reset capture type as a last batch for back-end to restore settings.
7563         int32_t batch_count = m_captureFrameConfig.num_batch;
7564         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
7565         m_captureFrameConfig.configs[batch_count].num_frames = 0;
7566         m_captureFrameConfig.num_batch++;
7567     } else if (getManualCaptureMode() >= CAM_MANUAL_CAPTURE_TYPE_2){
7568         rc = configureManualCapture (m_captureFrameConfig);
7569         //Added reset capture type as a last batch for back-end to restore settings.
7570         int32_t batch_count = m_captureFrameConfig.num_batch;
7571         m_captureFrameConfig.configs[batch_count].type = CAM_CAPTURE_RESET;
7572         m_captureFrameConfig.configs[batch_count].num_frames = 0;
7573         m_captureFrameConfig.num_batch++;
7574     }
7575 
7576     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
7577             (cam_capture_frame_config_t)m_captureFrameConfig);
7578     if (rc != NO_ERROR) {
7579         rc = BAD_VALUE;
7580         LOGE("Failed to set capture settings");
7581         return rc;
7582     }
7583 
7584     if (commitSettings) {
7585         rc = commitSetBatch();
7586         if (rc != NO_ERROR) {
7587             LOGE("Failed to commit parameters");
7588             return rc;
7589         }
7590     }
7591     return rc;
7592 }
7593 
7594 /*===========================================================================
7595  * FUNCTION   : resetFrameCapture
7596  *
7597  * DESCRIPTION: reset special captures settings(FLASH/HDR etc)
7598  *
7599  * PARAMETERS :
7600  *   @commitSettings : flag to enable or disable commit this this settings
7601  *
7602  * RETURN     : int32_t type of status
7603  *              NO_ERROR  -- success
7604  *              none-zero failure code
7605  *==========================================================================*/
resetFrameCapture(bool commitSettings)7606 int32_t QCameraParameters::resetFrameCapture(bool commitSettings)
7607 {
7608     int32_t rc = NO_ERROR;
7609     memset(&m_captureFrameConfig, 0, sizeof(cam_capture_frame_config_t));
7610 
7611     if (commitSettings) {
7612         if(initBatchUpdate(m_pParamBuf) < 0 ) {
7613             LOGE("Failed to initialize group update table");
7614             return BAD_TYPE;
7615         }
7616     }
7617 
7618     if (isHDREnabled() || isAEBracketEnabled()) {
7619         rc = setToneMapMode(true, true);
7620         if (rc != NO_ERROR) {
7621             LOGH("Failed to enable tone map during HDR/AEBracketing");
7622         }
7623         rc = stopAEBracket();
7624     } else if ((isChromaFlashEnabled()) || (mFlashValue != CAM_FLASH_MODE_OFF)
7625             || (getLowLightLevel() != CAM_LOW_LIGHT_OFF)) {
7626         rc = setToneMapMode(true, false);
7627         if (rc != NO_ERROR) {
7628             LOGH("Failed to enable tone map during chroma flash");
7629         }
7630 
7631         rc = setCDSMode(mCds_mode, false);
7632         if (rc != NO_ERROR) {
7633             LOGE("Failed to configure csd mode");
7634             return rc;
7635         }
7636     }
7637 
7638     rc = ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CAPTURE_FRAME_CONFIG,
7639             (cam_capture_frame_config_t)m_captureFrameConfig);
7640     if (rc != NO_ERROR) {
7641         rc = BAD_VALUE;
7642         LOGE("Failed to set capture settings");
7643         return rc;
7644     }
7645 
7646     if (commitSettings) {
7647         rc = commitSetBatch();
7648         if (rc != NO_ERROR) {
7649             LOGE("Failed to commit parameters");
7650             return rc;
7651         }
7652     }
7653     return rc;
7654 }
7655 
7656 /*===========================================================================
7657  * FUNCTION   : setAecLock
7658  *
7659  * DESCRIPTION: set AEC lock value
7660  *
7661  * PARAMETERS :
7662  *   @aecLockStr : AEC lock value string
7663  *
7664  * RETURN     : int32_t type of status
7665  *              NO_ERROR  -- success
7666  *              none-zero failure code
7667  *==========================================================================*/
setAecLock(const char * aecLockStr)7668 int32_t QCameraParameters::setAecLock(const char *aecLockStr)
7669 {
7670     if (aecLockStr != NULL) {
7671         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
7672                 aecLockStr);
7673         if (value != NAME_NOT_FOUND) {
7674             LOGH("Setting AECLock value %s", aecLockStr);
7675             updateParamEntry(KEY_AUTO_EXPOSURE_LOCK, aecLockStr);
7676             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7677                     CAM_INTF_PARM_AEC_LOCK, (uint32_t)value)) {
7678                 return BAD_VALUE;
7679             }
7680             return NO_ERROR;
7681         }
7682     }
7683     LOGE("Invalid AECLock value: %s",
7684         (aecLockStr == NULL) ? "NULL" : aecLockStr);
7685     return BAD_VALUE;
7686 }
7687 
7688 /*===========================================================================
7689  * FUNCTION   : setAwbLock
7690  *
7691  * DESCRIPTION: set AWB lock value
7692  *
7693  * PARAMETERS :
7694  *   @awbLockStr : AWB lock value string
7695  *
7696  * RETURN     : int32_t type of status
7697  *              NO_ERROR  -- success
7698  *              none-zero failure code
7699  *==========================================================================*/
setAwbLock(const char * awbLockStr)7700 int32_t QCameraParameters::setAwbLock(const char *awbLockStr)
7701 {
7702     if (awbLockStr != NULL) {
7703         int32_t value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
7704                 awbLockStr);
7705         if (value != NAME_NOT_FOUND) {
7706             LOGH("Setting AWBLock value %s", awbLockStr);
7707             updateParamEntry(KEY_AUTO_WHITEBALANCE_LOCK, awbLockStr);
7708             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7709                     CAM_INTF_PARM_AWB_LOCK, (uint32_t)value)) {
7710                 return BAD_VALUE;
7711             }
7712             return NO_ERROR;
7713         }
7714     }
7715     LOGE("Invalid AWBLock value: %s", (awbLockStr == NULL) ? "NULL" : awbLockStr);
7716     return BAD_VALUE;
7717 }
7718 
7719 /*===========================================================================
7720  * FUNCTION   : setMCEValue
7721  *
7722  * DESCRIPTION: set memory color enhancement value
7723  *
7724  * PARAMETERS :
7725  *   @mceStr : MCE value string
7726  *
7727  * RETURN     : int32_t type of status
7728  *              NO_ERROR  -- success
7729  *              none-zero failure code
7730  *==========================================================================*/
setMCEValue(const char * mceStr)7731 int32_t QCameraParameters::setMCEValue(const char *mceStr)
7732 {
7733     if (mceStr != NULL) {
7734         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
7735                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), mceStr);
7736         if (value != NAME_NOT_FOUND) {
7737             LOGH("Setting AWBLock value %s", mceStr);
7738             updateParamEntry(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mceStr);
7739             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MCE, value)) {
7740                 return BAD_VALUE;
7741             }
7742             return NO_ERROR;
7743         }
7744     }
7745     LOGE("Invalid MCE value: %s", (mceStr == NULL) ? "NULL" : mceStr);
7746     return BAD_VALUE;
7747 }
7748 
7749 /*===========================================================================
7750  * FUNCTION   : setTintlessValue
7751  *
7752  * DESCRIPTION: enable/disable tintless from user setting
7753  *
7754  * PARAMETERS :
7755  *   @params  : user setting parameters
7756  *
7757  * RETURN     : int32_t type of status
7758  *              NO_ERROR  -- success
7759  *              none-zero failure code
7760  *==========================================================================*/
setTintlessValue(const QCameraParameters & params)7761 int32_t QCameraParameters::setTintlessValue(const QCameraParameters& params)
7762 {
7763     const char *str = params.get(KEY_QC_TINTLESS_ENABLE);
7764     const char *prev_str = get(KEY_QC_TINTLESS_ENABLE);
7765     char prop[PROPERTY_VALUE_MAX];
7766 
7767     memset(prop, 0, sizeof(prop));
7768     property_get("persist.camera.tintless", prop, VALUE_ENABLE);
7769     if (str != NULL) {
7770         if (prev_str == NULL ||
7771             strcmp(str, prev_str) != 0) {
7772             return setTintlessValue(str);
7773         }
7774     } else {
7775         if (prev_str == NULL ||
7776             strcmp(prev_str, prop) != 0 ) {
7777             setTintlessValue(prop);
7778         }
7779     }
7780 
7781     return NO_ERROR;
7782 }
7783 
7784 /*===========================================================================
7785  * FUNCTION   : setTintless
7786  *
7787  * DESCRIPTION: set tintless mode
7788  *
7789  * PARAMETERS :
7790  *   @enable : 1 = enable, 0 = disable
7791  *
7792  * RETURN     : int32_t type of status
7793  *              NO_ERROR  -- success
7794  *              none-zero failure code
7795  *==========================================================================*/
setTintless(bool enable)7796 void QCameraParameters::setTintless(bool enable)
7797 {
7798     if (enable) {
7799         setTintlessValue(VALUE_ENABLE);
7800     } else {
7801         setTintlessValue(VALUE_DISABLE);
7802     }
7803 }
7804 
7805 /*===========================================================================
7806  * FUNCTION   : setTintlessValue
7807  *
7808  * DESCRIPTION: set tintless value
7809  *
7810  * PARAMETERS :
7811  *   @tintStr : Tintless value string
7812  *
7813  * RETURN     : int32_t type of status
7814  *              NO_ERROR  -- success
7815  *              none-zero failure code
7816  *==========================================================================*/
setTintlessValue(const char * tintStr)7817 int32_t QCameraParameters::setTintlessValue(const char *tintStr)
7818 {
7819     if (tintStr != NULL) {
7820         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
7821                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), tintStr);
7822         if (value != NAME_NOT_FOUND) {
7823             LOGH("Setting Tintless value %s", tintStr);
7824             updateParamEntry(KEY_QC_TINTLESS_ENABLE, tintStr);
7825             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TINTLESS, value)) {
7826                 return BAD_VALUE;
7827             }
7828             return NO_ERROR;
7829         }
7830     }
7831     LOGE("Invalid Tintless value: %s", (tintStr == NULL) ? "NULL" : tintStr);
7832     return BAD_VALUE;
7833 }
7834 
7835 /*===========================================================================
7836  * FUNCTION   : setCDSMode
7837  *
7838  * DESCRIPTION: Set CDS mode
7839  *
7840  * PARAMETERS :
7841  *   @params  : user setting parameters
7842  *
7843  * RETURN     : int32_t type of status
7844  *              NO_ERROR  -- success
7845  *              none-zero failure code
7846  *==========================================================================*/
setCDSMode(const QCameraParameters & params)7847 int32_t QCameraParameters::setCDSMode(const QCameraParameters& params)
7848 {
7849     const char *str = params.get(KEY_QC_CDS_MODE);
7850     const char *prev_str = get(KEY_QC_CDS_MODE);
7851     const char *video_str = params.get(KEY_QC_VIDEO_CDS_MODE);
7852     const char *video_prev_str = get(KEY_QC_VIDEO_CDS_MODE);
7853     int32_t rc = NO_ERROR;
7854 
7855     if (m_bRecordingHint_new == true) {
7856         if (video_str) {
7857             if ((video_prev_str == NULL) || (strcmp(video_str, video_prev_str) != 0)) {
7858                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
7859                         video_str);
7860                 if (cds_mode != NAME_NOT_FOUND) {
7861                     updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_str);
7862                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7863                         LOGE("Failed CDS MODE to update table");
7864                         rc = BAD_VALUE;
7865                     } else {
7866                         LOGD("Set CDS in video mode = %d", cds_mode);
7867                         mCds_mode = cds_mode;
7868                         m_bNeedRestart = true;
7869                     }
7870                 } else {
7871                     LOGE("Invalid argument for video CDS MODE %d",  cds_mode);
7872                     rc = BAD_VALUE;
7873                 }
7874             }
7875         } else {
7876             char video_prop[PROPERTY_VALUE_MAX];
7877             memset(video_prop, 0, sizeof(video_prop));
7878             property_get("persist.camera.video.CDS", video_prop, CDS_MODE_ON);
7879             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
7880                     video_prop);
7881             if (cds_mode != NAME_NOT_FOUND) {
7882                 updateParamEntry(KEY_QC_VIDEO_CDS_MODE, video_prop);
7883                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7884                     LOGE("Failed CDS MODE to update table");
7885                     rc = BAD_VALUE;
7886                 } else {
7887                     LOGD("Set CDS in video mode from setprop = %d", cds_mode);
7888                     mCds_mode = cds_mode;
7889                 }
7890             } else {
7891                 LOGE("Invalid prop for video CDS MODE %d",  cds_mode);
7892                 rc = BAD_VALUE;
7893             }
7894         }
7895     } else {
7896         if (str) {
7897             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
7898                 int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
7899                         str);
7900                 if (cds_mode != NAME_NOT_FOUND) {
7901                     updateParamEntry(KEY_QC_CDS_MODE, str);
7902                     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7903                         LOGE("Failed CDS MODE to update table");
7904                         rc = BAD_VALUE;
7905                     } else {
7906                         LOGD("Set CDS in capture mode = %d", cds_mode);
7907                         mCds_mode = cds_mode;
7908                         m_bNeedRestart = true;
7909                     }
7910                 } else {
7911                     LOGE("Invalid argument for snapshot CDS MODE %d",  cds_mode);
7912                     rc = BAD_VALUE;
7913                 }
7914             }
7915         } else {
7916             char prop[PROPERTY_VALUE_MAX];
7917             memset(prop, 0, sizeof(prop));
7918             property_get("persist.camera.CDS", prop, CDS_MODE_ON);
7919             int32_t cds_mode = lookupAttr(CDS_MODES_MAP, PARAM_MAP_SIZE(CDS_MODES_MAP),
7920                     prop);
7921             if (cds_mode != NAME_NOT_FOUND) {
7922                 updateParamEntry(KEY_QC_CDS_MODE, prop);
7923                 if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
7924                     LOGE("Failed CDS MODE to update table");
7925                     rc = BAD_VALUE;
7926                 } else {
7927                     LOGD("Set CDS in snapshot mode from setprop = %d", cds_mode);
7928                     mCds_mode = cds_mode;
7929                 }
7930             } else {
7931                 LOGE("Invalid prop for snapshot CDS MODE %d",  cds_mode);
7932                 rc = BAD_VALUE;
7933             }
7934         }
7935     }
7936 
7937     return rc;
7938 }
7939 
7940 /*===========================================================================
7941  * FUNCTION   : setInitialExposureIndex
7942  *
7943  * DESCRIPTION: Set initial exposure index value
7944  *
7945  * PARAMETERS :
7946  *   @params  : user setting parameters
7947  *
7948  * RETURN     : int32_t type of status
7949  *              NO_ERROR  -- success
7950  *              none-zero failure code
7951  *==========================================================================*/
setInitialExposureIndex(const QCameraParameters & params)7952 int32_t QCameraParameters::setInitialExposureIndex(const QCameraParameters& params)
7953 {
7954     int32_t rc = NO_ERROR;
7955     int value = -1;
7956     const char *str = params.get(KEY_QC_INITIAL_EXPOSURE_INDEX);
7957     const char *prev_str = get(KEY_QC_INITIAL_EXPOSURE_INDEX);
7958     if (str) {
7959         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
7960             value = atoi(str);
7961             LOGD("Set initial exposure index value from param = %d", value);
7962             if (value >= 0) {
7963                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, str);
7964             }
7965         }
7966     } else {
7967         char prop[PROPERTY_VALUE_MAX];
7968         memset(prop, 0, sizeof(prop));
7969         property_get("persist.camera.initial.exp.val", prop, "");
7970         if ((strlen(prop) > 0) &&
7971                 ( (prev_str == NULL) || (strcmp(prop, prev_str) != 0))) {
7972             value = atoi(prop);
7973             LOGD("Set initial exposure index value from setprop = %d", value);
7974             if (value >= 0) {
7975                 updateParamEntry(KEY_QC_INITIAL_EXPOSURE_INDEX, prop);
7976             }
7977         }
7978     }
7979 
7980     if (value >= 0) {
7981         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
7982                 CAM_INTF_PARM_INITIAL_EXPOSURE_INDEX, (uint32_t)value)) {
7983             LOGE("Failed to update initial exposure index value");
7984             rc = BAD_VALUE;
7985         }
7986     } else {
7987         LOGD("Invalid value for initial exposure index value %d", value);
7988     }
7989 
7990     return rc;
7991 }
7992 
7993 /*===========================================================================
7994  * FUNCTION   : setInstantCapture
7995  *
7996  * DESCRIPTION: Set Instant Capture related params
7997  *
7998  * PARAMETERS :
7999  *   @params  : user setting parameters
8000  *
8001  * RETURN     : int32_t type of status
8002  *              NO_ERROR  -- success
8003  *              none-zero failure code
8004  *==========================================================================*/
setInstantCapture(const QCameraParameters & params)8005 int32_t QCameraParameters::setInstantCapture(const QCameraParameters& params)
8006 {
8007     int32_t rc = NO_ERROR;
8008     int value = -1;
8009     // Check for instant capture, this will enable instant AEC as well.
8010     // This param will trigger the instant AEC param to backend
8011     // And also will be useful for instant capture.
8012     const char *str = params.get(KEY_QC_INSTANT_CAPTURE);
8013     const char *prev_str = get(KEY_QC_INSTANT_CAPTURE);
8014     if (str) {
8015         if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8016             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
8017                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), str);
8018             LOGD("Set instant Capture from param = %d", value);
8019             if(value != NAME_NOT_FOUND) {
8020                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, str);
8021             }
8022         }
8023     } else {
8024         char prop[PROPERTY_VALUE_MAX];
8025         memset(prop, 0, sizeof(prop));
8026         property_get("persist.camera.instant.capture", prop, KEY_QC_INSTANT_CAPTURE_DISABLE);
8027         if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
8028             value = lookupAttr(INSTANT_CAPTURE_MODES_MAP,
8029                     PARAM_MAP_SIZE(INSTANT_CAPTURE_MODES_MAP), prop);
8030             LOGD("Set instant capture from setprop = %d", value);
8031             if (value != NAME_NOT_FOUND) {
8032                 updateParamEntry(KEY_QC_INSTANT_CAPTURE, prop);
8033             }
8034         }
8035     }
8036 
8037     // Set instant AEC param to the backend for either instant capture or instant AEC
8038     // 0 - disbale (normal AEC)
8039     // 1 - Aggressive AEC (algo used in backend)
8040     // 2 - Fast AEC (algo used in backend)
8041     if (value != NAME_NOT_FOUND && value != -1) {
8042         m_bInstantCapture = (value > 0)? true : false;
8043         setInstantAEC((uint8_t)value, false);
8044     }
8045 
8046 
8047     // get frame aec bound value from setprop.
8048     // This value indicates the number of frames, camera interface
8049     // will wait for getting the instant capture frame.
8050     // Default value set to 7.
8051     // This value also indicates the number of frames, that HAL
8052     // will not display and will not send preview frames to app
8053     // This will be applicable only if instant capture is set.
8054     if (m_bInstantCapture) {
8055         char prop[PROPERTY_VALUE_MAX];
8056         memset(prop, 0, sizeof(prop));
8057         property_get("persist.camera.ae.capture.bound", prop, "7");
8058         int32_t frame_bound = atoi(prop);
8059         if (frame_bound >= 0) {
8060             mAecFrameBound = (uint8_t)frame_bound;
8061         } else {
8062             LOGE("Invalid prop for aec frame bound %d", frame_bound);
8063             rc = BAD_VALUE;
8064         }
8065     }
8066     return rc;
8067 }
8068 
8069 /*===========================================================================
8070  * FUNCTION   : setInstantAEC
8071  *
8072  * DESCRIPTION: Set Instant AEC related params
8073  *
8074  * PARAMETERS :
8075  *   @params  : user setting parameters
8076  *
8077  * RETURN     : int32_t type of status
8078  *              NO_ERROR  -- success
8079  *              none-zero failure code
8080  *==========================================================================*/
setInstantAEC(const QCameraParameters & params)8081 int32_t QCameraParameters::setInstantAEC(const QCameraParameters& params)
8082 {
8083     int32_t rc = NO_ERROR;
8084     int value = -1;
8085 
8086     // Check for instant AEC only when instant capture is not enabled.
8087     // Instant capture already takes care of the instant AEC as well.
8088     if (!m_bInstantCapture) {
8089         // Check for instant AEC. Instant AEC will only enable fast AEC.
8090         // It will not enable instant capture.
8091         // This param will trigger the instant AEC param to backend
8092         const char *str = params.get(KEY_QC_INSTANT_AEC);
8093         const char *prev_str = get(KEY_QC_INSTANT_AEC);
8094         if (str) {
8095             if ((prev_str == NULL) || (strcmp(str, prev_str) != 0)) {
8096                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
8097                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), str);
8098                 LOGD("Set instant AEC from param = %d", value);
8099             }
8100         } else {
8101             char prop[PROPERTY_VALUE_MAX];
8102             memset(prop, 0, sizeof(prop));
8103             property_get("persist.camera.instant.aec", prop, KEY_QC_INSTANT_AEC_DISABLE);
8104             if ((prev_str == NULL) || (strcmp(prop, prev_str) != 0)) {
8105                 value = lookupAttr(INSTANT_AEC_MODES_MAP,
8106                         PARAM_MAP_SIZE(INSTANT_AEC_MODES_MAP), prop);
8107                 LOGD("Set instant AEC from setprop = %d", value);
8108             }
8109         }
8110 
8111         // Set instant AEC param to the backend for either instant capture or instant AEC
8112         // 0 - disbale (normal AEC)
8113         // 1 - Aggressive AEC (algo used in backend)
8114         // 2 - Fast AEC (algo used in backend)
8115         if (value != NAME_NOT_FOUND && value != -1) {
8116             setInstantAEC((uint8_t)value, false);
8117         }
8118 
8119     }
8120 
8121     // get frame aec preview skip count from setprop.
8122     // This value indicates the number of frames, that HAL
8123     // will not display and will not send preview frames to app
8124     // Default value set to 7.
8125     // This will be applicable only if instant aec is set.
8126     if (m_bInstantAEC) {
8127         char prop[PROPERTY_VALUE_MAX];
8128         memset(prop, 0, sizeof(prop));
8129         property_get("persist.camera.ae.instant.bound", prop, "7");
8130         int32_t aec_frame_skip_cnt = atoi(prop);
8131         if (aec_frame_skip_cnt >= 0) {
8132             mAecSkipDisplayFrameBound = (uint8_t)aec_frame_skip_cnt;
8133         } else {
8134             LOGE("Invalid prop for aec frame bound %d", aec_frame_skip_cnt);
8135             rc = BAD_VALUE;
8136         }
8137     }
8138     return rc;
8139 }
8140 
8141 /*===========================================================================
8142  * FUNCTION   : setDISValue
8143  *
8144  * DESCRIPTION: set DIS value
8145  *
8146  * PARAMETERS :
8147  *   @disStr : DIS value string
8148  *
8149  * RETURN     : int32_t type of status
8150  *              NO_ERROR  -- success
8151  *              none-zero failure code
8152  *==========================================================================*/
setDISValue(const char * disStr)8153 int32_t QCameraParameters::setDISValue(const char *disStr)
8154 {
8155     if (disStr != NULL) {
8156         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8157                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), disStr);
8158         if (value != NAME_NOT_FOUND) {
8159             //For some IS types (like EIS 2.0), when DIS value is changed, we need to restart
8160             //preview because of topology change in backend. But, for now, restart preview
8161             //for all IS types.
8162             m_bNeedRestart = true;
8163             LOGH("Setting DIS value %s", disStr);
8164             updateParamEntry(KEY_QC_DIS, disStr);
8165             if (!(strcmp(disStr,"enable"))) {
8166                 m_bDISEnabled = true;
8167             } else {
8168                 m_bDISEnabled = false;
8169             }
8170             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_DIS_ENABLE, value)) {
8171                 return BAD_VALUE;
8172             }
8173             return NO_ERROR;
8174         }
8175     }
8176     LOGE("Invalid DIS value: %s", (disStr == NULL) ? "NULL" : disStr);
8177     m_bDISEnabled = false;
8178     return BAD_VALUE;
8179 }
8180 
8181 /*===========================================================================
8182  * FUNCTION   : updateOisValue
8183  *
8184  * DESCRIPTION: update OIS value
8185  *
8186  * PARAMETERS :
8187  *   @oisValue : OIS value TRUE/FALSE
8188  *
8189  * RETURN     : int32_t type of status
8190  *              NO_ERROR  -- success
8191  *              none-zero failure code
8192  *==========================================================================*/
updateOisValue(bool oisValue)8193 int32_t QCameraParameters::updateOisValue(bool oisValue)
8194 {
8195     uint8_t enable = 0;
8196     int32_t rc = NO_ERROR;
8197 
8198     // Check for OIS disable
8199     char ois_prop[PROPERTY_VALUE_MAX];
8200     memset(ois_prop, 0, sizeof(ois_prop));
8201     property_get("persist.camera.ois.disable", ois_prop, "0");
8202     uint8_t ois_disable = (uint8_t)atoi(ois_prop);
8203 
8204     //Enable OIS if it is camera mode or Camcoder 4K mode
8205     if (!m_bRecordingHint || (is4k2kVideoResolution() && m_bRecordingHint)) {
8206         enable = 1;
8207         LOGH("Valid OIS mode!! ");
8208     }
8209     // Disable OIS if setprop is set
8210     if (ois_disable || !oisValue) {
8211         //Disable OIS
8212         enable = 0;
8213         LOGH("Disable OIS mode!! ois_disable(%d) oisValue(%d)",
8214                  ois_disable, oisValue);
8215 
8216     }
8217     m_bOISEnabled = enable;
8218     if (m_bOISEnabled) {
8219         updateParamEntry(KEY_QC_OIS, VALUE_ENABLE);
8220     } else {
8221         updateParamEntry(KEY_QC_OIS, VALUE_DISABLE);
8222     }
8223 
8224     if (initBatchUpdate(m_pParamBuf) < 0 ) {
8225         LOGE("Failed to initialize group update table");
8226         return BAD_TYPE;
8227     }
8228 
8229     LOGH("Sending OIS mode (%d)", enable);
8230     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_META_LENS_OPT_STAB_MODE, enable)) {
8231         LOGE("Failed to update table");
8232         return BAD_VALUE;
8233     }
8234 
8235     rc = commitSetBatch();
8236     if (rc != NO_ERROR) {
8237         LOGE("Failed to parameter changes");
8238         return rc;
8239     }
8240 
8241     return rc;
8242 }
8243 
8244 /*===========================================================================
8245  * FUNCTION   : setHighFrameRate
8246  *
8247  * DESCRIPTION: set high frame rate
8248  *
8249  * PARAMETERS :
8250  *   @hfrMode : HFR mode
8251  *
8252  * RETURN     : int32_t type of status
8253  *              NO_ERROR  -- success
8254  *              none-zero failure code
8255  *==========================================================================*/
setHighFrameRate(const int32_t hfrMode)8256 int32_t QCameraParameters::setHighFrameRate(const int32_t hfrMode)
8257 {
8258     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HFR, hfrMode)) {
8259         return BAD_VALUE;
8260     }
8261 
8262     return NO_ERROR;
8263 }
8264 
8265 /*===========================================================================
8266  * FUNCTION   : setLensShadeValue
8267  *
8268  * DESCRIPTION: set lens shade value
8269  *
8270  * PARAMETERS :
8271  *   @lensSahdeStr : lens shade value string
8272  *
8273  * RETURN     : int32_t type of status
8274  *              NO_ERROR  -- success
8275  *              none-zero failure code
8276  *==========================================================================*/
setLensShadeValue(const char * lensShadeStr)8277 int32_t QCameraParameters::setLensShadeValue(const char *lensShadeStr)
8278 {
8279     if (lensShadeStr != NULL) {
8280         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
8281                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), lensShadeStr);
8282         if (value != NAME_NOT_FOUND) {
8283             LOGH("Setting LensShade value %s", lensShadeStr);
8284             updateParamEntry(KEY_QC_LENSSHADE, lensShadeStr);
8285             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROLLOFF, value)) {
8286                 return BAD_VALUE;
8287             }
8288             return NO_ERROR;
8289         }
8290     }
8291     LOGE("Invalid LensShade value: %s",
8292           (lensShadeStr == NULL) ? "NULL" : lensShadeStr);
8293     return BAD_VALUE;
8294 }
8295 
8296 /*===========================================================================
8297  * FUNCTION   : setExposureCompensation
8298  *
8299  * DESCRIPTION: set exposure compensation value
8300  *
8301  * PARAMETERS :
8302  *   @expComp : exposure compensation value
8303  *
8304  * RETURN     : int32_t type of status
8305  *              NO_ERROR  -- success
8306  *              none-zero failure code
8307  *==========================================================================*/
setExposureCompensation(int expComp)8308 int32_t QCameraParameters::setExposureCompensation(int expComp)
8309 {
8310     char val[16];
8311     snprintf(val, sizeof(val), "%d", expComp);
8312     updateParamEntry(KEY_EXPOSURE_COMPENSATION, val);
8313 
8314     // Don't need to pass step as part of setParameter because
8315     // camera daemon is already aware of it.
8316     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_EXPOSURE_COMPENSATION, expComp)) {
8317         return BAD_VALUE;
8318     }
8319 
8320     return NO_ERROR;
8321 }
8322 
8323 /*===========================================================================
8324  * FUNCTION   : setWhiteBalance
8325  *
8326  * DESCRIPTION: set white balance mode
8327  *
8328  * PARAMETERS :
8329  *   @wbStr   : white balance mode value string
8330  *
8331  * RETURN     : int32_t type of status
8332  *              NO_ERROR  -- success
8333  *              none-zero failure code
8334  *==========================================================================*/
setWhiteBalance(const char * wbStr)8335 int32_t QCameraParameters::setWhiteBalance(const char *wbStr)
8336 {
8337     if (wbStr != NULL) {
8338         int32_t value = lookupAttr(WHITE_BALANCE_MODES_MAP,
8339                 PARAM_MAP_SIZE(WHITE_BALANCE_MODES_MAP), wbStr);
8340         if (value != NAME_NOT_FOUND) {
8341             LOGH("Setting WhiteBalance value %s", wbStr);
8342             updateParamEntry(KEY_WHITE_BALANCE, wbStr);
8343             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WHITE_BALANCE, value)) {
8344                 return BAD_VALUE;
8345             }
8346             return NO_ERROR;
8347         }
8348     }
8349     LOGE("Invalid WhiteBalance value: %s", (wbStr == NULL) ? "NULL" : wbStr);
8350     return BAD_VALUE;
8351 }
8352 
8353 /*===========================================================================
8354  * FUNCTION   : setWBManualCCT
8355  *
8356  * DESCRIPTION: set setWBManualCCT time
8357  *
8358  * PARAMETERS :
8359  *   @cctStr : string of wb cct, range (2000, 8000) in K.
8360  *
8361  * RETURN     : int32_t type of status
8362  *              NO_ERROR  -- success
8363  *              none-zero failure code
8364  *==========================================================================*/
setWBManualCCT(const char * cctStr)8365 int32_t  QCameraParameters::setWBManualCCT(const char *cctStr)
8366 {
8367     if (cctStr != NULL) {
8368         int32_t cctVal = atoi(cctStr);
8369         int32_t minCct = m_pCapability->min_wb_cct; /* 2000K */
8370         int32_t maxCct = m_pCapability->max_wb_cct; /* 8000K */
8371 
8372         if (cctVal >= minCct && cctVal <= maxCct) {
8373             LOGH(", cct value: %d", cctVal);
8374             updateParamEntry(KEY_QC_WB_MANUAL_CCT, cctStr);
8375             cam_manual_wb_parm_t manual_wb;
8376             manual_wb.type = CAM_MANUAL_WB_MODE_CCT;
8377             manual_wb.cct = cctVal;
8378             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
8379                 return BAD_VALUE;
8380             }
8381             return NO_ERROR;
8382         }
8383     }
8384 
8385     LOGE("Invalid cct, value: %s",
8386             (cctStr == NULL) ? "NULL" : cctStr);
8387     return BAD_VALUE;
8388 }
8389 
8390 /*===========================================================================
8391  * FUNCTION   : updateAWBParams
8392  *
8393  * DESCRIPTION: update CCT parameters key
8394  *
8395  * PARAMETERS :
8396  *   @awb_params : WB parameters
8397  *
8398  * RETURN     : int32_t type of status
8399  *              NO_ERROR  -- success
8400  *              none-zero failure code
8401  *==========================================================================*/
updateAWBParams(cam_awb_params_t & awb_params)8402 int32_t QCameraParameters::updateAWBParams(cam_awb_params_t &awb_params)
8403 {
8404     //check and update CCT
8405     int32_t prev_cct = getInt(KEY_QC_WB_MANUAL_CCT);
8406     if (prev_cct != awb_params.cct_value) {
8407         LOGD("update current cct value. old:%d, now:%d",
8408                 prev_cct, awb_params.cct_value);
8409         set(KEY_QC_WB_MANUAL_CCT, awb_params.cct_value);
8410     }
8411 
8412     //check and update WB gains
8413     const char *prev_gains = get(KEY_QC_MANUAL_WB_GAINS);
8414     char gainStr[30];
8415     snprintf(gainStr, sizeof(gainStr), "%f,%f,%f", awb_params.rgb_gains.r_gain,
8416         awb_params.rgb_gains.g_gain, awb_params.rgb_gains.b_gain);
8417 
8418     if (prev_gains == NULL || strcmp(prev_gains, gainStr)) {
8419         set(KEY_QC_MANUAL_WB_GAINS, gainStr);
8420         LOGD("update currernt RGB gains: old %s new %s", prev_gains, gainStr);
8421     }
8422     return NO_ERROR;
8423 }
8424 
8425 /*===========================================================================
8426  * FUNCTION   : parseGains
8427  *
8428  * DESCRIPTION: parse WB gains
8429  *
8430  * PARAMETERS :
8431  *   @gainStr : WB result string
8432  *   @r_gain  : WB red gain
8433  *   @g_gain  : WB green gain
8434  *   @b_gain  : WB blue gain
8435  *
8436  * RETURN     : int32_t type of status
8437  *              NO_ERROR  -- success
8438  *              none-zero failure code
8439  *==========================================================================*/
parseGains(const char * gainStr,double & r_gain,double & g_gain,double & b_gain)8440 int32_t QCameraParameters::parseGains(const char *gainStr, double &r_gain,
8441                                           double &g_gain, double &b_gain)
8442 {
8443     int32_t rc = NO_ERROR;
8444     char *saveptr = NULL;
8445     size_t gains_size = strlen(gainStr) + 1;
8446     char* gains = (char*) calloc(1, gains_size);
8447     if (NULL == gains) {
8448         LOGE("No memory for gains");
8449         return NO_MEMORY;
8450     }
8451     strlcpy(gains, gainStr, gains_size);
8452     char *token = strtok_r(gains, ",", &saveptr);
8453 
8454     if (NULL != token) {
8455         r_gain = (float) atof(token);
8456         token = strtok_r(NULL, ",", &saveptr);
8457     }
8458 
8459     if (NULL != token) {
8460         g_gain = (float) atof(token);
8461         token = strtok_r(NULL, ",", &saveptr);
8462     }
8463 
8464     if (NULL != token) {
8465         b_gain = (float) atof(token);
8466     } else {
8467         LOGE("Malformed string for gains");
8468         rc = BAD_VALUE;
8469     }
8470 
8471     free(gains);
8472     return rc;
8473 }
8474 
8475 /*===========================================================================
8476  * FUNCTION   : setManualWBGains
8477  *
8478  * DESCRIPTION: set manual wb gains for r,g,b
8479  *
8480  * PARAMETERS :
8481  *   @cctStr : string of wb gains, range (1.0, 4.0).
8482  *
8483  * RETURN     : int32_t type of status
8484  *              NO_ERROR  -- success
8485  *              none-zero failure code
8486  *==========================================================================*/
setManualWBGains(const char * gainStr)8487 int32_t QCameraParameters::setManualWBGains(const char *gainStr)
8488 {
8489     int32_t rc = NO_ERROR;
8490     if (gainStr != NULL) {
8491         double r_gain,g_gain,b_gain;
8492         rc = parseGains(gainStr, r_gain, g_gain, b_gain);
8493         if (rc != NO_ERROR) {
8494             return rc;
8495         }
8496 
8497         double minGain = m_pCapability->min_wb_gain;
8498         double maxGain = m_pCapability->max_wb_gain;
8499 
8500         if (r_gain >= minGain && r_gain <= maxGain &&
8501             g_gain >= minGain && g_gain <= maxGain &&
8502             b_gain >= minGain && b_gain <= maxGain) {
8503             LOGH(", setting rgb gains: r = %lf g = %lf b = %lf",
8504                      r_gain, g_gain, b_gain);
8505             updateParamEntry(KEY_QC_MANUAL_WB_GAINS, gainStr);
8506             cam_manual_wb_parm_t manual_wb;
8507             manual_wb.type = CAM_MANUAL_WB_MODE_GAIN;
8508             manual_wb.gains.r_gain = r_gain;
8509             manual_wb.gains.g_gain = g_gain;
8510             manual_wb.gains.b_gain = b_gain;
8511             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WB_MANUAL, manual_wb)) {
8512                 return BAD_VALUE;
8513             }
8514             return NO_ERROR;
8515         }
8516     }
8517 
8518     LOGH("Invalid manual wb gains: %s",
8519           (gainStr == NULL) ? "NULL" : gainStr);
8520     return BAD_VALUE;
8521 }
8522 
getAutoFlickerMode()8523 int QCameraParameters::getAutoFlickerMode()
8524 {
8525     /* Enable Advanced Auto Antibanding where we can set
8526        any of the following option
8527        ie. CAM_ANTIBANDING_MODE_AUTO
8528            CAM_ANTIBANDING_MODE_AUTO_50HZ
8529            CAM_ANTIBANDING_MODE_AUTO_60HZ
8530       Currently setting it to default    */
8531     char prop[PROPERTY_VALUE_MAX];
8532     memset(prop, 0, sizeof(prop));
8533     property_get("persist.camera.set.afd", prop, "3");
8534     return atoi(prop);
8535 }
8536 
8537 /*===========================================================================
8538  * FUNCTION   : setAntibanding
8539  *
8540  * DESCRIPTION: set antibanding value
8541  *
8542  * PARAMETERS :
8543  *   @antiBandingStr : antibanding value string
8544  *
8545  * RETURN     : int32_t type of status
8546  *              NO_ERROR  -- success
8547  *              none-zero failure code
8548  *==========================================================================*/
setAntibanding(const char * antiBandingStr)8549 int32_t QCameraParameters::setAntibanding(const char *antiBandingStr)
8550 {
8551     if (antiBandingStr != NULL) {
8552         int32_t value = lookupAttr(ANTIBANDING_MODES_MAP, PARAM_MAP_SIZE(ANTIBANDING_MODES_MAP),
8553                 antiBandingStr);
8554         if (value != NAME_NOT_FOUND) {
8555             LOGH("Setting AntiBanding value %s", antiBandingStr);
8556             updateParamEntry(KEY_ANTIBANDING, antiBandingStr);
8557             if(value == CAM_ANTIBANDING_MODE_AUTO) {
8558                value = getAutoFlickerMode();
8559             }
8560             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
8561                     CAM_INTF_PARM_ANTIBANDING, (uint32_t)value)) {
8562                 return BAD_VALUE;
8563             }
8564             return NO_ERROR;
8565         }
8566     }
8567     LOGE("Invalid AntiBanding value: %s",
8568           (antiBandingStr == NULL) ? "NULL" : antiBandingStr);
8569     return BAD_VALUE;
8570 }
8571 
8572 /*===========================================================================
8573  * FUNCTION   : setFocusAreas
8574  *
8575  * DESCRIPTION: set focus areas
8576  *
8577  * PARAMETERS :
8578  *   @focusAreasStr : focus areas value string
8579  *
8580  * RETURN     : int32_t type of status
8581  *              NO_ERROR  -- success
8582  *              none-zero failure code
8583  *==========================================================================*/
setFocusAreas(const char * focusAreasStr)8584 int32_t QCameraParameters::setFocusAreas(const char *focusAreasStr)
8585 {
8586     if (m_pCapability->max_num_focus_areas == 0 ||
8587         focusAreasStr == NULL) {
8588         LOGD("Parameter string is null");
8589         return NO_ERROR;
8590     }
8591 
8592     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
8593     if (NULL == areas) {
8594         LOGE("No memory for areas");
8595         return NO_MEMORY;
8596     }
8597     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_focus_areas);
8598     int num_areas_found = 0;
8599     if (parseCameraAreaString(focusAreasStr,
8600                               m_pCapability->max_num_focus_areas,
8601                               areas,
8602                               num_areas_found) != NO_ERROR) {
8603         LOGE("Failed to parse the string: %s", focusAreasStr);
8604         free(areas);
8605         return BAD_VALUE;
8606     }
8607 
8608     if (validateCameraAreas(areas, num_areas_found) == false) {
8609         LOGE("invalid areas specified : %s", focusAreasStr);
8610         free(areas);
8611         return BAD_VALUE;
8612     }
8613 
8614     updateParamEntry(KEY_FOCUS_AREAS, focusAreasStr);
8615 
8616     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
8617     //so no action is takenby the lower layer
8618     if (num_areas_found == 1 &&
8619         areas[0].rect.left == 0 &&
8620         areas[0].rect.top == 0 &&
8621         areas[0].rect.width == 0 &&
8622         areas[0].rect.height == 0 &&
8623         areas[0].weight == 0) {
8624         num_areas_found = 0;
8625     }
8626 
8627     int previewWidth, previewHeight;
8628     getPreviewSize(&previewWidth, &previewHeight);
8629     cam_roi_info_t af_roi_value;
8630     memset(&af_roi_value, 0, sizeof(cam_roi_info_t));
8631     af_roi_value.num_roi = (uint8_t)num_areas_found;
8632     for (int i = 0; i < num_areas_found; i++) {
8633         LOGH("FocusArea[%d] = (%d, %d, %d, %d)",
8634                i, (areas[i].rect.top), (areas[i].rect.left),
8635               (areas[i].rect.width), (areas[i].rect.height));
8636 
8637         // Transform the coords from (-1000, 1000)
8638         // to (0, previewWidth or previewHeight).
8639         af_roi_value.roi[i].left =
8640                 (int32_t)(((double)areas[i].rect.left + 1000.0) *
8641                     ((double)previewWidth / 2000.0));
8642         af_roi_value.roi[i].top =
8643                 (int32_t)(((double)areas[i].rect.top + 1000.0) *
8644                     ((double)previewHeight / 2000.0));
8645         af_roi_value.roi[i].width =
8646                 (int32_t)((double)areas[i].rect.width *
8647                     (double)previewWidth / 2000.0);
8648         af_roi_value.roi[i].height =
8649                 (int32_t)((double)areas[i].rect.height *
8650                     (double)previewHeight / 2000.0);
8651         af_roi_value.weight[i] = areas[i].weight;
8652     }
8653     free(areas);
8654     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AF_ROI, af_roi_value)) {
8655         return BAD_VALUE;
8656     }
8657 
8658     return NO_ERROR;
8659 }
8660 
8661 /*===========================================================================
8662  * FUNCTION   : setMeteringAreas
8663  *
8664  * DESCRIPTION: set metering areas value
8665  *
8666  * PARAMETERS :
8667  *   @meteringAreasStr : metering areas value string
8668  *
8669  * RETURN     : int32_t type of status
8670  *              NO_ERROR  -- success
8671  *              none-zero failure code
8672  *==========================================================================*/
setMeteringAreas(const char * meteringAreasStr)8673 int32_t QCameraParameters::setMeteringAreas(const char *meteringAreasStr)
8674 {
8675     if (m_pCapability->max_num_metering_areas == 0 ||
8676         meteringAreasStr == NULL) {
8677         LOGD("Parameter string is null");
8678         return NO_ERROR;
8679     }
8680 
8681     cam_area_t *areas = (cam_area_t *)malloc(sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
8682     if (NULL == areas) {
8683         LOGE("No memory for areas");
8684         return NO_MEMORY;
8685     }
8686     memset(areas, 0, sizeof(cam_area_t) * m_pCapability->max_num_metering_areas);
8687     int num_areas_found = 0;
8688     if (parseCameraAreaString(meteringAreasStr,
8689                               m_pCapability->max_num_metering_areas,
8690                               areas,
8691                               num_areas_found) < 0) {
8692         LOGE("Failed to parse the string: %s", meteringAreasStr);
8693         free(areas);
8694         return BAD_VALUE;
8695     }
8696 
8697     if (validateCameraAreas(areas, num_areas_found) == false) {
8698         LOGE("invalid areas specified : %s", meteringAreasStr);
8699         free(areas);
8700         return BAD_VALUE;
8701     }
8702 
8703     updateParamEntry(KEY_METERING_AREAS, meteringAreasStr);
8704 
8705     //for special area string (0, 0, 0, 0, 0), set the num_areas_found to 0,
8706     //so no action is takenby the lower layer
8707     if (num_areas_found == 1 &&
8708         areas[0].rect.left == 0 &&
8709         areas[0].rect.top == 0 &&
8710         areas[0].rect.width == 0 &&
8711         areas[0].rect.height == 0 &&
8712         areas[0].weight == 0) {
8713         num_areas_found = 0;
8714     }
8715     cam_set_aec_roi_t aec_roi_value;
8716     int previewWidth, previewHeight;
8717     getPreviewSize(&previewWidth, &previewHeight);
8718 
8719     memset(&aec_roi_value, 0, sizeof(cam_set_aec_roi_t));
8720     if (num_areas_found > 0) {
8721         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_ON;
8722         aec_roi_value.aec_roi_type = CAM_AEC_ROI_BY_COORDINATE;
8723 
8724         for (int i = 0; i < num_areas_found; i++) {
8725             LOGH("MeteringArea[%d] = (%d, %d, %d, %d)",
8726                    i, (areas[i].rect.top), (areas[i].rect.left),
8727                   (areas[i].rect.width), (areas[i].rect.height));
8728 
8729             // Transform the coords from (-1000, 1000) to
8730             // (0, previewWidth or previewHeight).
8731             aec_roi_value.cam_aec_roi_position.coordinate[i].x =
8732                     (uint32_t)((((double)areas[i].rect.left +
8733                         (double)areas[i].rect.width / 2.0) + 1000.0) *
8734                             (double)previewWidth / 2000.0);
8735             aec_roi_value.cam_aec_roi_position.coordinate[i].y =
8736                     (uint32_t)((((double)areas[i].rect.top +
8737                         (double)areas[i].rect.height / 2.0) + 1000.0) *
8738                             (double)previewHeight / 2000.0);
8739         }
8740     } else {
8741         aec_roi_value.aec_roi_enable = CAM_AEC_ROI_OFF;
8742     }
8743     free(areas);
8744     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_ROI, aec_roi_value)) {
8745         return BAD_VALUE;
8746     }
8747 
8748     return NO_ERROR;
8749 }
8750 
8751 
8752 /*===========================================================================
8753  * FUNCTION   : isSupportedSensorHdrSize
8754  *
8755  * DESCRIPTION: Checks if the requested snapshot size is compatible with currently
8756  *              configured HDR mode, currently primary target for validation is
8757  *              zzhdr however this function can be extended in the future to vet
8758  *              all sensor based HDR configs
8759  *
8760  * PARAMETERS :
8761  *   @params  : CameraParameters object
8762  *
8763  * RETURN     : boolean type
8764  *              True  -- indicates supported config
8765  *              False -- indicated unsupported config should fallback to other
8766  *              available HDR modes
8767  *==========================================================================*/
isSupportedSensorHdrSize(const QCameraParameters & params)8768 bool QCameraParameters::isSupportedSensorHdrSize(const QCameraParameters& params)
8769 {
8770     char value[PROPERTY_VALUE_MAX];
8771     memset(value, 0, sizeof(value));
8772     property_get("persist.camera.zzhdr.enable", value, "0");
8773     uint8_t zzhdr_enable = (uint8_t)atoi(value);
8774 
8775     if (zzhdr_enable) {
8776 
8777         int req_w, req_h;
8778         params.getPictureSize(&req_w, &req_h);
8779 
8780         // Check if requested w x h is in zzhdr supported list
8781         for (size_t i = 0; i< m_pCapability->zzhdr_sizes_tbl_cnt; ++i) {
8782 
8783             if (req_w == m_pCapability->zzhdr_sizes_tbl[i].width &&
8784                     req_h == m_pCapability->zzhdr_sizes_tbl[i].height) {
8785                 LOGD("%s: Found match for %d x %d", __func__, req_w, req_h);
8786                 return true;
8787             }
8788         }
8789         LOGH("%s: %d x %d is not supported for zzhdr mode", __func__, req_w, req_h);
8790         return false;
8791     }
8792 
8793     return true;
8794 }
8795 
8796 /*===========================================================================
8797  * FUNCTION   : setSceneMode
8798  *
8799  * DESCRIPTION: set scene mode
8800  *
8801  * PARAMETERS :
8802  *   @sceneModeStr : scene mode value string
8803  *
8804  * RETURN     : int32_t type of status
8805  *              NO_ERROR  -- success
8806  *              none-zero failure code
8807  *==========================================================================*/
setSceneMode(const char * sceneModeStr)8808 int32_t QCameraParameters::setSceneMode(const char *sceneModeStr)
8809 {
8810     if (sceneModeStr != NULL) {
8811         int32_t value = lookupAttr(SCENE_MODES_MAP, PARAM_MAP_SIZE(SCENE_MODES_MAP), sceneModeStr);
8812         if (value != NAME_NOT_FOUND) {
8813             LOGD("Setting SceneMode %s", sceneModeStr);
8814             updateParamEntry(KEY_SCENE_MODE, sceneModeStr);
8815             if (m_bSensorHDREnabled) {
8816               // Incase of HW HDR mode, we do not update the same as Best shot mode.
8817               LOGH("H/W HDR mode enabled. Do not set Best Shot Mode");
8818               return NO_ERROR;
8819             }
8820             if (m_bSceneSelection) {
8821                 setSelectedScene((cam_scene_mode_type) value);
8822             }
8823             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_BESTSHOT_MODE,
8824                     (uint32_t)value)) {
8825                 return BAD_VALUE;
8826             }
8827             return NO_ERROR;
8828         }
8829     }
8830     LOGE("Invalid Secene Mode: %s",
8831            (sceneModeStr == NULL) ? "NULL" : sceneModeStr);
8832     return BAD_VALUE;
8833 }
8834 
8835 /*===========================================================================
8836  * FUNCTION   : setSelectableZoneAf
8837  *
8838  * DESCRIPTION: set selectable zone AF algorithm
8839  *
8840  * PARAMETERS :
8841  *   @selZoneAFStr : selectable zone AF algorithm value string
8842  *
8843  * RETURN     : int32_t type of status
8844  *              NO_ERROR  -- success
8845  *              none-zero failure code
8846  *==========================================================================*/
setSelectableZoneAf(const char * selZoneAFStr)8847 int32_t QCameraParameters::setSelectableZoneAf(const char *selZoneAFStr)
8848 {
8849     if (selZoneAFStr != NULL) {
8850         int32_t value = lookupAttr(FOCUS_ALGO_MAP, PARAM_MAP_SIZE(FOCUS_ALGO_MAP), selZoneAFStr);
8851         if (value != NAME_NOT_FOUND) {
8852             LOGD("Setting Selectable Zone AF value %s", selZoneAFStr);
8853             updateParamEntry(KEY_QC_SELECTABLE_ZONE_AF, selZoneAFStr);
8854             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_ALGO_TYPE, value)) {
8855                 return BAD_VALUE;
8856             }
8857             return NO_ERROR;
8858         }
8859     }
8860     LOGE("Invalid selectable zone af value: %s",
8861            (selZoneAFStr == NULL) ? "NULL" : selZoneAFStr);
8862     return BAD_VALUE;
8863 }
8864 
8865 /*===========================================================================
8866  * FUNCTION   : isAEBracketEnabled
8867  *
8868  * DESCRIPTION: checks if AE bracketing is enabled
8869  *
8870  * PARAMETERS :
8871  *
8872  * RETURN     : TRUE/FALSE
8873  *==========================================================================*/
isAEBracketEnabled()8874 bool QCameraParameters::isAEBracketEnabled()
8875 {
8876     const char *str = get(KEY_QC_AE_BRACKET_HDR);
8877     if (str != NULL) {
8878         if (strcmp(str, AE_BRACKET_OFF) != 0) {
8879             return true;
8880         }
8881     }
8882     return false;
8883 }
8884 
8885 /*===========================================================================
8886  * FUNCTION   : setAEBracket
8887  *
8888  * DESCRIPTION: set AE bracket value
8889  *
8890  * PARAMETERS :
8891  *   @aecBracketStr : AE bracket value string
8892  *
8893  * RETURN     : int32_t type of status
8894  *              NO_ERROR  -- success
8895  *              none-zero failure code
8896  *==========================================================================*/
setAEBracket(const char * aecBracketStr)8897 int32_t QCameraParameters::setAEBracket(const char *aecBracketStr)
8898 {
8899     if (aecBracketStr == NULL) {
8900         LOGD("setAEBracket with NULL value");
8901         return NO_ERROR;
8902     }
8903 
8904     cam_exp_bracketing_t expBracket;
8905     memset(&expBracket, 0, sizeof(expBracket));
8906 
8907     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
8908             aecBracketStr);
8909     switch (value) {
8910     case CAM_EXP_BRACKETING_ON:
8911         {
8912             LOGD("EXP_BRACKETING_ON");
8913             const char *str_val = get(KEY_QC_CAPTURE_BURST_EXPOSURE);
8914             if ((str_val != NULL) && (strlen(str_val)>0)) {
8915                 expBracket.mode = CAM_EXP_BRACKETING_ON;
8916                 m_bAeBracketingEnabled = true;
8917                 strlcpy(expBracket.values, str_val, MAX_EXP_BRACKETING_LENGTH);
8918                 LOGD("setting Exposure Bracketing value of %s",
8919                        expBracket.values);
8920             }
8921             else {
8922                 /* Apps not set capture-burst-exposures, error case fall into bracketing off mode */
8923                 LOGD("capture-burst-exposures not set, back to HDR OFF mode");
8924                 m_bAeBracketingEnabled = false;
8925                 expBracket.mode = CAM_EXP_BRACKETING_OFF;
8926             }
8927         }
8928         break;
8929     default:
8930         {
8931             m_bAeBracketingEnabled = false;
8932             LOGH(", EXP_BRACKETING_OFF");
8933             expBracket.mode = CAM_EXP_BRACKETING_OFF;
8934         }
8935         break;
8936     }
8937 
8938     // Cache client AE bracketing configuration
8939     memcpy(&m_AEBracketingClient, &expBracket, sizeof(cam_exp_bracketing_t));
8940 
8941     /* save the value*/
8942     updateParamEntry(KEY_QC_AE_BRACKET_HDR, aecBracketStr);
8943     return NO_ERROR;
8944 }
8945 
8946 /*===========================================================================
8947  * FUNCTION   : set3ALock
8948  *
8949  * DESCRIPTION: enable/disable 3A lock.
8950  *
8951  * PARAMETERS :
8952  *   @lock3A  : lock or unlock
8953  *
8954  * RETURN     : int32_t type of status
8955  *              NO_ERROR  -- success
8956  *              none-zero failure code
8957  *==========================================================================*/
set3ALock(bool lock3A)8958 int32_t QCameraParameters::set3ALock(bool lock3A)
8959 {
8960     int32_t rc = NO_ERROR;
8961     LOGH("Setting Lock %d", lock3A);
8962     if(initBatchUpdate(m_pParamBuf) < 0 ) {
8963         LOGE("Failed to initialize group update table");
8964         return BAD_TYPE;
8965     }
8966     uint32_t focus_mode = CAM_FOCUS_MODE_AUTO;
8967     if (lock3A) {
8968         if (isUbiFocusEnabled() || isUbiRefocus()) {
8969             //For Ubi focus move focus to infinity.
8970             focus_mode = CAM_FOCUS_MODE_INFINITY;
8971         } else if (isOptiZoomEnabled() || isStillMoreEnabled()) {
8972             //For optizoom and stillmore, set focus as fixed.
8973             focus_mode = CAM_FOCUS_MODE_FIXED;
8974         }
8975     } else {
8976         // retrieve previous focus value.
8977         const char *focus = get(KEY_FOCUS_MODE);
8978         int val = lookupAttr(FOCUS_MODES_MAP, PARAM_MAP_SIZE(FOCUS_MODES_MAP), focus);
8979         if (val != NAME_NOT_FOUND) {
8980             focus_mode = (uint32_t) val;
8981             LOGD("focus mode %s", focus);
8982         }
8983     }
8984     //Lock AWB
8985     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AWB_LOCK, (uint32_t)lock3A)) {
8986         return BAD_VALUE;
8987     }
8988     //Lock AEC
8989     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_AEC_LOCK, (uint32_t)lock3A)) {
8990         return BAD_VALUE;
8991     }
8992     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_MODE, focus_mode)) {
8993         return BAD_VALUE;
8994     }
8995 
8996     rc = commitSetBatch();
8997     if (rc != NO_ERROR) {
8998         LOGE("Failed to commit batch");
8999     }
9000     return rc;
9001 }
9002 
9003 /*===========================================================================
9004  * FUNCTION   : setAndCommitZoom
9005  *
9006  * DESCRIPTION: set zoom.
9007  *
9008  * PARAMETERS :
9009  *     @zoom_level : zoom level to set.
9010  *
9011  * RETURN     : int32_t type of status
9012  *              NO_ERROR  -- success
9013  *              none-zero failure code
9014  *==========================================================================*/
setAndCommitZoom(int zoom_level)9015 int32_t QCameraParameters::setAndCommitZoom(int zoom_level)
9016 {
9017     LOGH("E");
9018     int32_t rc = NO_ERROR;
9019     if (initBatchUpdate(m_pParamBuf) < 0 ) {
9020         LOGE("Failed to initialize group update table");
9021         return BAD_TYPE;
9022     }
9023 
9024     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ZOOM, zoom_level)) {
9025         LOGE("Failed to update table");
9026         return BAD_VALUE;
9027     }
9028 
9029     rc = commitSetBatch();
9030     if (rc != NO_ERROR) {
9031         LOGE("Failed to set Flash value");
9032     }
9033 
9034     mZoomLevel = zoom_level;
9035     LOGH("X");
9036 
9037     return rc;
9038 }
9039 
9040 /*===========================================================================
9041  * FUNCTION   : isOptiZoomEnabled
9042  *
9043  * DESCRIPTION: checks whether optizoom is enabled
9044  *
9045  * PARAMETERS :
9046  *
9047  * RETURN     : true - enabled, false - disabled
9048  *
9049  *==========================================================================*/
isOptiZoomEnabled()9050 bool QCameraParameters::isOptiZoomEnabled()
9051 {
9052     if (m_bOptiZoomOn && (0 <= mParmZoomLevel)) {
9053         uint32_t zoom_level = (uint32_t) mParmZoomLevel;
9054         cam_opti_zoom_t *opti_zoom_settings_need =
9055                 &(m_pCapability->opti_zoom_settings_need);
9056         uint32_t zoom_threshold = (uint32_t) opti_zoom_settings_need->zoom_threshold;
9057         LOGH("current zoom level =%u & zoom_threshold =%u",
9058                  zoom_level, zoom_threshold);
9059 
9060         if (zoom_level >= zoom_threshold) {
9061             return true;
9062         }
9063     }
9064 
9065     return false;
9066 }
9067 
9068 /*===========================================================================
9069  * FUNCTION   : setNoiseReductionMode
9070  *
9071  * DESCRIPTION: set noise reduction mode
9072  *
9073  * PARAMETERS :
9074  *   @noiseReductionModeStr : noise reduction mode
9075  *
9076  * RETURN     : int32_t type of status
9077  *              NO_ERROR  -- success
9078  *              none-zero failure code
9079  *==========================================================================*/
setNoiseReductionMode(const char * noiseReductionModeStr)9080 int32_t QCameraParameters::setNoiseReductionMode(const char *noiseReductionModeStr)
9081 {
9082     LOGH("noiseReductionModeStr = %s", noiseReductionModeStr);
9083     if (noiseReductionModeStr != NULL) {
9084         int value = lookupAttr(NOISE_REDUCTION_MODES_MAP, PARAM_MAP_SIZE(NOISE_REDUCTION_MODES_MAP),
9085                 noiseReductionModeStr);
9086         if (value != NAME_NOT_FOUND) {
9087             m_bHighQualityNoiseReductionMode =
9088                     !strncmp(VALUE_HIGH_QUALITY, noiseReductionModeStr, strlen(VALUE_HIGH_QUALITY));
9089             updateParamEntry(KEY_QC_NOISE_REDUCTION_MODE, noiseReductionModeStr);
9090             return NO_ERROR;
9091         }
9092     }
9093     LOGE("Invalid noise reduction mode value: %s",
9094             (noiseReductionModeStr == NULL) ? "NULL" : noiseReductionModeStr);
9095     return BAD_VALUE;
9096 }
9097 
9098 /*===========================================================================
9099  * FUNCTION   : commitAFBracket
9100  *
9101  * DESCRIPTION: commit AF Bracket.
9102  *
9103  * PARAMETERS :
9104  *   @AFBracket : AF bracketing configuration
9105  *
9106  * RETURN     : int32_t type of status
9107  *              NO_ERROR  -- success
9108  *              none-zero failure code
9109  *==========================================================================*/
commitAFBracket(cam_af_bracketing_t afBracket)9110 int32_t QCameraParameters::commitAFBracket(cam_af_bracketing_t afBracket)
9111 {
9112 
9113     int32_t rc = NO_ERROR;
9114     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9115         LOGE("Failed to initialize group update table");
9116         return BAD_TYPE;
9117     }
9118 
9119     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FOCUS_BRACKETING, afBracket)) {
9120         LOGE("Failed to update table");
9121         return BAD_VALUE;
9122     }
9123 
9124     rc = commitSetBatch();
9125     if (rc != NO_ERROR) {
9126         LOGE("Failed to commit batch");
9127         return rc;
9128     }
9129 
9130     return rc;
9131 }
9132 
9133 /*===========================================================================
9134  * FUNCTION   : setAFBracket
9135  *
9136  * DESCRIPTION: set AF bracket value
9137  *
9138  * PARAMETERS :
9139  *   @afBracketStr : AF bracket value string
9140  *
9141  * RETURN     : int32_t type of status
9142  *              NO_ERROR  -- success
9143  *              none-zero failure code
9144  *==========================================================================*/
setAFBracket(const char * afBracketStr)9145 int32_t QCameraParameters::setAFBracket(const char *afBracketStr)
9146 {
9147     LOGH("afBracketStr =%s",afBracketStr);
9148 
9149     if(afBracketStr != NULL) {
9150         int value = lookupAttr(AF_BRACKETING_MODES_MAP, PARAM_MAP_SIZE(AF_BRACKETING_MODES_MAP),
9151                 afBracketStr);
9152         if (value != NAME_NOT_FOUND) {
9153             m_bAFBracketingOn = (value != 0);
9154             updateParamEntry(KEY_QC_AF_BRACKET, afBracketStr);
9155 
9156             return NO_ERROR;
9157         }
9158     }
9159 
9160     LOGE("Invalid af bracket value: %s",
9161         (afBracketStr == NULL) ? "NULL" : afBracketStr);
9162     return BAD_VALUE;
9163 }
9164 
9165 /*===========================================================================
9166  * FUNCTION   : setReFocus
9167  *
9168  * DESCRIPTION: set refocus value
9169  *
9170  * PARAMETERS :
9171  *   @afBracketStr : refocus value string
9172  *
9173  * RETURN     : int32_t type of status
9174  *              NO_ERROR  -- success
9175  *              none-zero failure code
9176  *==========================================================================*/
setReFocus(const char * reFocusStr)9177 int32_t QCameraParameters::setReFocus(const char *reFocusStr)
9178 {
9179     LOGH("reFocusStr =%s",reFocusStr);
9180 
9181     if (reFocusStr != NULL) {
9182         int value = lookupAttr(RE_FOCUS_MODES_MAP, PARAM_MAP_SIZE(RE_FOCUS_MODES_MAP),
9183                 reFocusStr);
9184         if (value != NAME_NOT_FOUND) {
9185             m_bReFocusOn = (value != 0);
9186             updateParamEntry(KEY_QC_RE_FOCUS, reFocusStr);
9187             return NO_ERROR;
9188         }
9189     }
9190 
9191     return NO_ERROR;
9192 }
9193 
9194 /*===========================================================================
9195  * FUNCTION   : setChromaFlash
9196  *
9197  * DESCRIPTION: set chroma flash value
9198  *
9199  * PARAMETERS :
9200  *   @aecBracketStr : chroma flash value string
9201  *
9202  * RETURN     : int32_t type of status
9203  *              NO_ERROR  -- success
9204  *              none-zero failure code
9205  *==========================================================================*/
setChromaFlash(const char * chromaFlashStr)9206 int32_t QCameraParameters::setChromaFlash(const char *chromaFlashStr)
9207 {
9208     LOGH("chromaFlashStr =%s",chromaFlashStr);
9209     if(chromaFlashStr != NULL) {
9210         int value = lookupAttr(CHROMA_FLASH_MODES_MAP, PARAM_MAP_SIZE(CHROMA_FLASH_MODES_MAP),
9211                 chromaFlashStr);
9212         if(value != NAME_NOT_FOUND) {
9213             m_bChromaFlashOn = (value != 0);
9214             updateParamEntry(KEY_QC_CHROMA_FLASH, chromaFlashStr);
9215 
9216             return NO_ERROR;
9217         }
9218     }
9219 
9220     LOGE("Invalid chroma flash value: %s",
9221         (chromaFlashStr == NULL) ? "NULL" : chromaFlashStr);
9222     return BAD_VALUE;
9223 }
9224 
9225 /*===========================================================================
9226  * FUNCTION   : setOptiZoom
9227  *
9228  * DESCRIPTION: set opti zoom value
9229  *
9230  * PARAMETERS :
9231  *   @optiZoomStr : opti zoom value string
9232  *
9233  * RETURN     : int32_t type of status
9234  *              NO_ERROR  -- success
9235  *              none-zero failure code
9236  *==========================================================================*/
setOptiZoom(const char * optiZoomStr)9237 int32_t QCameraParameters::setOptiZoom(const char *optiZoomStr)
9238 {
9239     LOGH("optiZoomStr =%s",optiZoomStr);
9240     if(optiZoomStr != NULL) {
9241         int value = lookupAttr(OPTI_ZOOM_MODES_MAP, PARAM_MAP_SIZE(OPTI_ZOOM_MODES_MAP),
9242                 optiZoomStr);
9243         if(value != NAME_NOT_FOUND) {
9244             m_bOptiZoomOn = (value != 0);
9245             updateParamEntry(KEY_QC_OPTI_ZOOM, optiZoomStr);
9246 
9247             return NO_ERROR;
9248         }
9249     }
9250     LOGE("Invalid opti zoom value: %s",
9251         (optiZoomStr == NULL) ? "NULL" : optiZoomStr);
9252     return BAD_VALUE;
9253 }
9254 
9255 /*===========================================================================
9256  * FUNCTION   : setTruePortrait
9257  *
9258  * DESCRIPTION: set true portrait value
9259  *
9260  * PARAMETERS :
9261  *   @optiZoomStr : true portrait value string
9262  *
9263  * RETURN     : int32_t type of status
9264  *              NO_ERROR  -- success
9265  *              none-zero failure code
9266  *==========================================================================*/
setTruePortrait(const char * truePortraitStr)9267 int32_t QCameraParameters::setTruePortrait(const char *truePortraitStr)
9268 {
9269     LOGH("truePortraitStr =%s", truePortraitStr);
9270     if (truePortraitStr != NULL) {
9271         int value = lookupAttr(TRUE_PORTRAIT_MODES_MAP,
9272                 PARAM_MAP_SIZE(TRUE_PORTRAIT_MODES_MAP),
9273                 truePortraitStr);
9274         if (value != NAME_NOT_FOUND) {
9275             m_bTruePortraitOn = (value != 0);
9276             updateParamEntry(KEY_QC_TRUE_PORTRAIT, truePortraitStr);
9277             setFaceDetection(m_bFaceDetectionOn, false);
9278             return NO_ERROR;
9279         }
9280     }
9281     LOGH("Invalid true portrait value: %s",
9282             (truePortraitStr == NULL) ? "NULL" : truePortraitStr);
9283     return BAD_VALUE;
9284 }
9285 
9286 /*===========================================================================
9287  * FUNCTION   : setHDRMode
9288  *
9289  * DESCRIPTION: set hdr mode value
9290  *
9291  * PARAMETERS :
9292  *   @hdrModeStr : hdr mode value string
9293  *
9294  * RETURN     : int32_t type of status
9295  *              NO_ERROR  -- success
9296  *              none-zero failure code
9297  *==========================================================================*/
setHDRMode(const char * hdrModeStr)9298 int32_t QCameraParameters::setHDRMode(const char *hdrModeStr)
9299 {
9300     LOGH("hdrModeStr =%s", hdrModeStr);
9301     if (hdrModeStr != NULL) {
9302         int value = lookupAttr(HDR_MODES_MAP, PARAM_MAP_SIZE(HDR_MODES_MAP), hdrModeStr);
9303         if (value != NAME_NOT_FOUND) {
9304             const char *str = get(KEY_SCENE_MODE);
9305 
9306             m_bHDRModeSensor = !strncmp(hdrModeStr, HDR_MODE_SENSOR, strlen(HDR_MODE_SENSOR));
9307 
9308             updateParamEntry(KEY_QC_HDR_MODE, hdrModeStr);
9309 
9310             // If hdr is already selected, need to deselect it in local cache
9311             // So the new hdr mode will be applied
9312             if (str && !strncmp(str, SCENE_MODE_HDR, strlen(SCENE_MODE_HDR))) {
9313                 updateParamEntry(KEY_SCENE_MODE, SCENE_MODE_AUTO);
9314                 m_bNeedRestart = true;
9315             }
9316 
9317             return NO_ERROR;
9318         }
9319     }
9320     LOGH("Invalid hdr mode value: %s",
9321             (hdrModeStr == NULL) ? "NULL" : hdrModeStr);
9322     return BAD_VALUE;
9323 }
9324 
9325 /*===========================================================================
9326  * FUNCTION   : setSeeMore
9327  *
9328  * DESCRIPTION: set see more value
9329  *
9330  * PARAMETERS :
9331  *   @seeMoreStr : see more value string
9332  *
9333  * RETURN     : int32_t type of status
9334  *              NO_ERROR  -- success
9335  *              none-zero failure code
9336  *==========================================================================*/
setSeeMore(const char * seeMoreStr)9337 int32_t QCameraParameters::setSeeMore(const char *seeMoreStr)
9338 {
9339     int32_t rc = NO_ERROR;
9340 
9341     LOGH("seeMoreStr =%s", seeMoreStr);
9342     if (seeMoreStr != NULL) {
9343         int value = lookupAttr(ON_OFF_MODES_MAP,
9344                 PARAM_MAP_SIZE(ON_OFF_MODES_MAP),
9345                 seeMoreStr);
9346         if (value != NAME_NOT_FOUND) {
9347             m_bSeeMoreOn = (value != 0);
9348 
9349             // If SeeMore is enabled, enable StillMore for live snapshot
9350             // and disable tone map
9351             if (m_bSeeMoreOn) {
9352                 m_bStillMoreOn = TRUE;
9353                 if (!m_bLtmForSeeMoreEnabled) {
9354                     rc = setToneMapMode(false, false);
9355                 }
9356                 if (rc != NO_ERROR) {
9357                     LOGH("Failed to disable tone map during SeeMore");
9358                 }
9359             } else {
9360                 m_bStillMoreOn = FALSE;
9361                 if (!m_bLtmForSeeMoreEnabled) {
9362                     rc = setToneMapMode(true, false);
9363                 }
9364                 if (rc != NO_ERROR) {
9365                     LOGH("Failed to enable tone map during SeeMore");
9366                 }
9367             }
9368             updateParamEntry(KEY_QC_SEE_MORE, seeMoreStr);
9369             return NO_ERROR;
9370         }
9371     }
9372     LOGE("Invalid see more value: %s",
9373             (seeMoreStr == NULL) ? "NULL" : seeMoreStr);
9374     return BAD_VALUE;
9375 }
9376 
9377 /*===========================================================================
9378  * FUNCTION   : setStillMore
9379  *
9380  * DESCRIPTION: set still more value
9381  *
9382  * PARAMETERS :
9383  *   @seeMoreStr : still more value string
9384  *
9385  * RETURN     : int32_t type of status
9386  *              NO_ERROR  -- success
9387  *              none-zero failure code
9388  *==========================================================================*/
setStillMore(const char * stillMoreStr)9389 int32_t QCameraParameters::setStillMore(const char *stillMoreStr)
9390 {
9391     LOGH("stillMoreStr =%s", stillMoreStr);
9392     if (stillMoreStr != NULL) {
9393         int value = lookupAttr(STILL_MORE_MODES_MAP, PARAM_MAP_SIZE(STILL_MORE_MODES_MAP),
9394                 stillMoreStr);
9395         if (value != NAME_NOT_FOUND) {
9396             m_bStillMoreOn = (value != 0);
9397             updateParamEntry(KEY_QC_STILL_MORE, stillMoreStr);
9398 
9399             return NO_ERROR;
9400         }
9401     }
9402     LOGE("Invalid still more value: %s",
9403             (stillMoreStr == NULL) ? "NULL" : stillMoreStr);
9404     return BAD_VALUE;
9405 }
9406 
9407 /*===========================================================================
9408  * FUNCTION   : setHDRNeed1x
9409  *
9410  * DESCRIPTION: set hdr need 1x value
9411  *
9412  * PARAMETERS :
9413  *   @hdrModeStr : hdr need 1x value string
9414  *
9415  * RETURN     : int32_t type of status
9416  *              NO_ERROR  -- success
9417  *              none-zero failure code
9418  *==========================================================================*/
setHDRNeed1x(const char * hdrNeed1xStr)9419 int32_t QCameraParameters::setHDRNeed1x(const char *hdrNeed1xStr)
9420 {
9421     LOGH("hdrNeed1xStr =%s", hdrNeed1xStr);
9422     if (hdrNeed1xStr != NULL) {
9423         int value = lookupAttr(TRUE_FALSE_MODES_MAP, PARAM_MAP_SIZE(TRUE_FALSE_MODES_MAP),
9424                 hdrNeed1xStr);
9425         if (value != NAME_NOT_FOUND) {
9426             updateParamEntry(KEY_QC_HDR_NEED_1X, hdrNeed1xStr);
9427             m_bHDR1xFrameEnabled = !strncmp(hdrNeed1xStr, VALUE_TRUE, strlen(VALUE_TRUE));
9428             m_bNeedRestart = true;
9429 
9430             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR_NEED_1X,
9431                     m_bHDR1xFrameEnabled)) {
9432                 return BAD_VALUE;
9433             }
9434             return NO_ERROR;
9435         }
9436     }
9437 
9438     LOGH("Invalid hdr need 1x value: %s",
9439             (hdrNeed1xStr == NULL) ? "NULL" : hdrNeed1xStr);
9440     return BAD_VALUE;
9441 }
9442 
9443 /*===========================================================================
9444  * FUNCTION   : setAEBracketing
9445  *
9446  * DESCRIPTION: enables AE bracketing
9447  *
9448  * PARAMETERS :
9449  *
9450  * RETURN     : int32_t type of status
9451  *              NO_ERROR  -- success
9452  *              none-zero failure code
9453  *==========================================================================*/
setAEBracketing()9454 int32_t QCameraParameters::setAEBracketing()
9455 {
9456     int32_t rc = NO_ERROR;
9457     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9458         LOGE("Failed to initialize group update table");
9459         return BAD_TYPE;
9460     }
9461 
9462     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, m_AEBracketingClient)) {
9463         LOGE("Failed to update AE bracketing");
9464         return BAD_VALUE;
9465     }
9466 
9467     rc = commitSetBatch();
9468     if (rc != NO_ERROR) {
9469         LOGE("Failed to configure AE bracketing");
9470         return rc;
9471     }
9472 
9473     return rc;
9474 }
9475 
9476 /*===========================================================================
9477  * FUNCTION   : setHDRAEBracket
9478  *
9479  * DESCRIPTION: enables AE bracketing for HDR
9480  *
9481  * PARAMETERS :
9482  *   @hdrBracket : HDR bracketing configuration
9483  *
9484  * RETURN     : int32_t type of status
9485  *              NO_ERROR  -- success
9486  *              none-zero failure code
9487  *==========================================================================*/
setHDRAEBracket(cam_exp_bracketing_t hdrBracket)9488 int32_t QCameraParameters::setHDRAEBracket(cam_exp_bracketing_t hdrBracket)
9489 {
9490     int32_t rc = NO_ERROR;
9491     if(initBatchUpdate(m_pParamBuf) < 0 ) {
9492         LOGE("Failed to initialize group update table");
9493         return BAD_TYPE;
9494     }
9495 
9496     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HDR, hdrBracket)) {
9497         LOGE("Failed to update table");
9498         return BAD_TYPE;
9499     }
9500 
9501     rc = commitSetBatch();
9502     if (rc != NO_ERROR) {
9503         LOGE("Failed to configure HDR bracketing");
9504         return rc;
9505     }
9506 
9507     return rc;
9508 }
9509 
9510 /*===========================================================================
9511  * FUNCTION   : setCacheVideoBuffers
9512  *
9513  * DESCRIPTION: set cache video buffers value
9514  *
9515  * PARAMETERS :
9516  *   @cacheVideoStr : cache video buffer value string
9517  *
9518  * RETURN     : int32_t type of status
9519  *              NO_ERROR  -- success
9520  *              none-zero failure code
9521  *==========================================================================*/
setCacheVideoBuffers(const char * cacheVideoBufStr)9522 int32_t QCameraParameters::setCacheVideoBuffers(const char *cacheVideoBufStr)
9523 {
9524     if (cacheVideoBufStr != NULL) {
9525         int8_t cacheVideoBuf = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9526                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), cacheVideoBufStr);
9527         char prop[PROPERTY_VALUE_MAX];
9528         memset(prop, 0, sizeof(prop));
9529         property_get("persist.camera.mem.usecache", prop, "");
9530         if (strlen(prop) > 0) {
9531             cacheVideoBuf = atoi(prop);
9532         }
9533         if (cacheVideoBuf != NAME_NOT_FOUND) {
9534             const char *cacheStr = (strlen(prop)>0) ? prop : cacheVideoBufStr;
9535             LOGD("Setting video buffer %s",
9536                     (cacheVideoBuf == 0) ? "UnCached" : "Cached");
9537             return updateParamEntry(KEY_QC_CACHE_VIDEO_BUFFERS, cacheStr);
9538         }
9539         LOGE("Cache video buffers not set correctly");
9540     }
9541     return BAD_VALUE;
9542 }
9543 
9544 
9545 /*===========================================================================
9546  * FUNCTION   : setCacheVideoBuffers
9547  *
9548  * DESCRIPTION: Set buffers as Cache/Uncache Memory
9549  *
9550  * PARAMETERS :
9551  *   @params  : user setting parameters
9552  *
9553  * RETURN     : int32_t type of status
9554  *              NO_ERROR  -- success
9555  *              none-zero failure code
9556  *==========================================================================*/
setCacheVideoBuffers(const QCameraParameters & params)9557 int32_t QCameraParameters::setCacheVideoBuffers(const QCameraParameters& params)
9558 {
9559     const char *str = params.get(KEY_QC_CACHE_VIDEO_BUFFERS);;
9560     const char *prev_str = get(KEY_QC_CACHE_VIDEO_BUFFERS);
9561 
9562     if (str != NULL) {
9563         if (prev_str == NULL ||
9564                 strcmp(str, prev_str) != 0) {
9565             return setCacheVideoBuffers(str);
9566         }
9567     }
9568     return NO_ERROR;
9569 }
9570 
9571 /*===========================================================================
9572  * FUNCTION   : restoreAEBracket
9573  *
9574  * DESCRIPTION: restores client AE bracketing configuration after HDR is done
9575  *
9576  * PARAMETERS :
9577  *
9578  * RETURN     : int32_t type of status
9579  *              NO_ERROR  -- success
9580  *              none-zero failure code
9581  *==========================================================================*/
stopAEBracket()9582 int32_t QCameraParameters::stopAEBracket()
9583 {
9584   cam_exp_bracketing_t bracketing;
9585 
9586   bracketing.mode = CAM_EXP_BRACKETING_OFF;
9587 
9588   return setHDRAEBracket(bracketing);
9589 }
9590 
9591 /*===========================================================================
9592  * FUNCTION   : updateFlash
9593  *
9594  * DESCRIPTION: restores client flash configuration or disables flash
9595  *
9596  * PARAMETERS :
9597  *   @commitSettings : flag indicating whether settings need to be commited
9598  *
9599  * RETURN     : int32_t type of status
9600  *              NO_ERROR  -- success
9601  *              none-zero failure code
9602  *==========================================================================*/
updateFlash(bool commitSettings)9603 int32_t QCameraParameters::updateFlash(bool commitSettings)
9604 {
9605     int32_t rc = NO_ERROR;
9606     int32_t value;
9607 
9608     if (commitSettings) {
9609       if(initBatchUpdate(m_pParamBuf) < 0 ) {
9610           LOGE("Failed to initialize group update table");
9611           return BAD_TYPE;
9612       }
9613     }
9614 
9615     if (isHDREnabled() || m_bAeBracketingEnabled || m_bAFBracketingOn ||
9616           m_bOptiZoomOn || m_bReFocusOn || m_LowLightLevel) {
9617         value = CAM_FLASH_MODE_OFF;
9618     } else if (m_bChromaFlashOn) {
9619         value = CAM_FLASH_MODE_ON;
9620     } else {
9621         value = mFlashValue;
9622     }
9623 
9624     if (value != mFlashDaemonValue) {
9625         LOGD("Setting Flash value %d", value);
9626         if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_LED_MODE, value)) {
9627             LOGE("Failed to set led mode");
9628             return BAD_VALUE;
9629         }
9630         mFlashDaemonValue = value;
9631     } else {
9632         rc = NO_ERROR;
9633     }
9634 
9635     if (commitSettings) {
9636         rc = commitSetBatch();
9637         if (rc != NO_ERROR) {
9638             LOGE("Failed to configure HDR bracketing");
9639             return rc;
9640         }
9641     }
9642 
9643     return rc;
9644 }
9645 
9646 /*===========================================================================
9647  * FUNCTION   : setRedeyeReduction
9648  *
9649  * DESCRIPTION: set red eye reduction value
9650  *
9651  * PARAMETERS :
9652  *   @redeyeStr : red eye reduction value string
9653  *
9654  * RETURN     : int32_t type of status
9655  *              NO_ERROR  -- success
9656  *              none-zero failure code
9657  *==========================================================================*/
setRedeyeReduction(const char * redeyeStr)9658 int32_t QCameraParameters::setRedeyeReduction(const char *redeyeStr)
9659 {
9660     if (redeyeStr != NULL) {
9661         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9662                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), redeyeStr);
9663         if (value != NAME_NOT_FOUND) {
9664             LOGD("Setting RedEye Reduce value %s", redeyeStr);
9665             updateParamEntry(KEY_QC_REDEYE_REDUCTION, redeyeStr);
9666             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
9667                     CAM_INTF_PARM_REDEYE_REDUCTION, value)) {
9668                 return BAD_VALUE;
9669             }
9670             return NO_ERROR;
9671         }
9672     }
9673     LOGE("Invalid RedEye Reduce value: %s",
9674            (redeyeStr == NULL) ? "NULL" : redeyeStr);
9675     return BAD_VALUE;
9676 }
9677 
9678 /*===========================================================================
9679  * FUNCTION   : getDenoiseProcessPlate
9680  *
9681  * DESCRIPTION: query denoise process plate
9682  *
9683  * PARAMETERS : None
9684  *
9685  * RETURN     : NR process plate vlaue
9686  *==========================================================================*/
9687 cam_denoise_process_type_t
getDenoiseProcessPlate(cam_intf_parm_type_t type)9688         QCameraParameters::getDenoiseProcessPlate(cam_intf_parm_type_t type)
9689 {
9690     char prop[PROPERTY_VALUE_MAX];
9691     memset(prop, 0, sizeof(prop));
9692     cam_denoise_process_type_t processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
9693     if (CAM_INTF_PARM_WAVELET_DENOISE == type) {
9694         property_get("persist.denoise.process.plates", prop, "");
9695     } else if (CAM_INTF_PARM_TEMPORAL_DENOISE == type) {
9696         property_get("persist.tnr.process.plates", prop, "");
9697     } else {
9698         LOGW("Type not supported");
9699         prop[0] = '\0';
9700     }
9701     if (strlen(prop) > 0) {
9702         switch(atoi(prop)) {
9703         case 0:
9704             processPlate = CAM_WAVELET_DENOISE_YCBCR_PLANE;
9705             break;
9706         case 1:
9707             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
9708             break;
9709         case 2:
9710             processPlate = CAM_WAVELET_DENOISE_STREAMLINE_YCBCR;
9711             break;
9712         case 3:
9713             processPlate = CAM_WAVELET_DENOISE_STREAMLINED_CBCR;
9714             break;
9715         default:
9716             processPlate = CAM_WAVELET_DENOISE_CBCR_ONLY;
9717             break;
9718         }
9719     }
9720     return processPlate;
9721 }
9722 
9723 /*===========================================================================
9724  * FUNCTION   : setWaveletDenoise
9725  *
9726  * DESCRIPTION: set wavelet denoise value
9727  *
9728  * PARAMETERS :
9729  *   @wnrStr : wavelet denoise value string
9730  *
9731  * RETURN     : int32_t type of status
9732  *              NO_ERROR  -- success
9733  *              none-zero failure code
9734  *==========================================================================*/
setWaveletDenoise(const char * wnrStr)9735 int32_t QCameraParameters::setWaveletDenoise(const char *wnrStr)
9736 {
9737     if ((m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_DENOISE2D) == 0){
9738         LOGH("WNR is not supported");
9739         return NO_ERROR;
9740     }
9741 
9742     if (wnrStr != NULL) {
9743         int value = lookupAttr(DENOISE_ON_OFF_MODES_MAP,
9744                 PARAM_MAP_SIZE(DENOISE_ON_OFF_MODES_MAP), wnrStr);
9745         if (value != NAME_NOT_FOUND) {
9746             updateParamEntry(KEY_QC_DENOISE, wnrStr);
9747 
9748             cam_denoise_param_t temp;
9749             memset(&temp, 0, sizeof(temp));
9750             temp.denoise_enable = (uint8_t)value;
9751             m_bWNROn = (value != 0);
9752             if (m_bWNROn) {
9753                 temp.process_plates = getDenoiseProcessPlate(CAM_INTF_PARM_WAVELET_DENOISE);
9754             }
9755             LOGD("Denoise enable=%d, plates=%d",
9756                    temp.denoise_enable, temp.process_plates);
9757             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_WAVELET_DENOISE, temp)) {
9758                 return BAD_VALUE;
9759             }
9760             return NO_ERROR;
9761         }
9762     }
9763     LOGE("Invalid Denoise value: %s", (wnrStr == NULL) ? "NULL" : wnrStr);
9764     return BAD_VALUE;
9765 }
9766 
9767 /*===========================================================================
9768  * FUNCTION   : setRdiMode
9769  *
9770  * DESCRIPTION: set rdi mode value
9771  *
9772  * PARAMETERS :
9773  *   @str     : rdi mode value string
9774  *
9775  * RETURN     : int32_t type of status
9776  *              NO_ERROR  -- success
9777  *              none-zero failure code
9778  *==========================================================================*/
setRdiMode(const char * str)9779 int32_t QCameraParameters::setRdiMode(const char *str)
9780 {
9781     LOGD("RDI_DEBUG  rdi mode value: %s", str);
9782 
9783     if (str != NULL) {
9784         int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9785                 PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
9786         if (value != NAME_NOT_FOUND) {
9787             updateParamEntry(KEY_QC_RDI_MODE, str);
9788             m_bRdiMode = (value == 0) ? false : true;
9789             if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RDI_MODE, value)) {
9790                 return BAD_VALUE;
9791             }
9792             return NO_ERROR;
9793         }
9794     }
9795     LOGE("Invalid rdi mode value: %s", (str == NULL) ? "NULL" : str);
9796     return BAD_VALUE;
9797 }
9798 
9799 
9800 /*===========================================================================
9801  * FUNCTION   : setSecureMode
9802  *
9803  * DESCRIPTION: set secure mode value
9804  *
9805  * PARAMETERS :
9806  *   @str     : secure mode value string
9807  *
9808  * RETURN     : int32_t type of status
9809  *              NO_ERROR  -- success
9810  *              none-zero failure code
9811  *==========================================================================*/
setSecureMode(const char * str)9812 int32_t QCameraParameters::setSecureMode(const char *str)
9813 {
9814   LOGD("Secure mode value: %s", str);
9815 
9816   if (str != NULL) {
9817     int32_t value = lookupAttr(ENABLE_DISABLE_MODES_MAP,
9818             PARAM_MAP_SIZE(ENABLE_DISABLE_MODES_MAP), str);
9819     if (value != NAME_NOT_FOUND) {
9820         updateParamEntry(KEY_QC_SECURE_MODE, str);
9821         m_bSecureMode = (value == 0)? false : true;
9822         return NO_ERROR;
9823     }
9824   }
9825   LOGE("Invalid Secure mode value: %s",
9826      (str == NULL) ? "NULL" : str);
9827   return BAD_VALUE;
9828 }
9829 
9830 /*===========================================================================
9831  * FUNCTION   : getStreamRotation
9832  *
9833  * DESCRIPTION: get stream rotation by its type
9834  *
9835  * PARAMETERS :
9836  *   @streamType        : stream type
9837  *   @featureConfig     : stream feature config structure
9838  *   @dim               : stream dimension
9839  *
9840  * RETURN     : int32_t type of status
9841  *              NO_ERROR  -- success
9842  *              none-zero failure code
9843  *==========================================================================*/
getStreamRotation(cam_stream_type_t streamType,cam_pp_feature_config_t & featureConfig,cam_dimension_t & dim)9844 int32_t QCameraParameters::getStreamRotation(cam_stream_type_t streamType,
9845                                             cam_pp_feature_config_t &featureConfig,
9846                                             cam_dimension_t &dim)
9847 {
9848     int32_t ret = NO_ERROR;
9849     const char *str = get(KEY_QC_VIDEO_ROTATION);
9850     int rotationParam = lookupAttr(VIDEO_ROTATION_MODES_MAP,
9851             PARAM_MAP_SIZE(VIDEO_ROTATION_MODES_MAP), str);
9852     featureConfig.rotation = ROTATE_0;
9853     int swapDim = 0;
9854     switch (streamType) {
9855         case CAM_STREAM_TYPE_VIDEO:
9856             switch(rotationParam) {
9857                 case 90:
9858                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
9859                     featureConfig.rotation = ROTATE_90;
9860                     swapDim = 1;
9861                     break;
9862                 case 180:
9863                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
9864                     featureConfig.rotation = ROTATE_180;
9865                     break;
9866                 case 270:
9867                     featureConfig.feature_mask |= CAM_QCOM_FEATURE_ROTATION;
9868                     featureConfig.rotation = ROTATE_270;
9869                     swapDim = 1;
9870                     break;
9871                 default:
9872                     featureConfig.rotation = ROTATE_0;
9873             }
9874             break;
9875         case CAM_STREAM_TYPE_PREVIEW:
9876         case CAM_STREAM_TYPE_POSTVIEW:
9877         case CAM_STREAM_TYPE_SNAPSHOT:
9878         case CAM_STREAM_TYPE_RAW:
9879         case CAM_STREAM_TYPE_METADATA:
9880         case CAM_STREAM_TYPE_OFFLINE_PROC:
9881         case CAM_STREAM_TYPE_DEFAULT:
9882         default:
9883             break;
9884     }
9885 
9886     if (swapDim > 0) {
9887         int w = 0;
9888         w = dim.width;
9889         dim.width = dim.height;
9890         dim.height = w;
9891     }
9892     return ret;
9893 }
9894 
9895 /*===========================================================================
9896  * FUNCTION   : getStreamFormat
9897  *
9898  * DESCRIPTION: get stream format by its type
9899  *
9900  * PARAMETERS :
9901  *   @streamType : [input] stream type
9902  *   @format     : [output] stream format
9903  *
9904  * RETURN     : int32_t type of status
9905  *              NO_ERROR  -- success
9906  *              none-zero failure code
9907  *==========================================================================*/
getStreamFormat(cam_stream_type_t streamType,cam_format_t & format)9908 int32_t QCameraParameters::getStreamFormat(cam_stream_type_t streamType,
9909                                             cam_format_t &format)
9910 {
9911     int32_t ret = NO_ERROR;
9912     format = CAM_FORMAT_MAX;
9913     switch (streamType) {
9914     case CAM_STREAM_TYPE_PREVIEW:
9915         if (!isUBWCEnabled()) {
9916 #if VENUS_PRESENT
9917             cam_dimension_t preview;
9918             cam_dimension_t video;
9919             getStreamDimension(CAM_STREAM_TYPE_VIDEO , video);
9920             getStreamDimension(CAM_STREAM_TYPE_PREVIEW, preview);
9921             if (getRecordingHintValue() == true &&
9922                     video.width == preview.width &&
9923                     video.height == preview.height &&
9924                     mPreviewFormat == CAM_FORMAT_YUV_420_NV21) {
9925                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
9926             } else
9927 #endif
9928             format = mPreviewFormat;
9929         } else {
9930             format = mPreviewFormat;
9931         }
9932         break;
9933     case CAM_STREAM_TYPE_POSTVIEW:
9934     case CAM_STREAM_TYPE_CALLBACK:
9935         format = mAppPreviewFormat;
9936         break;
9937     case CAM_STREAM_TYPE_ANALYSIS:
9938         if (m_pCapability->hw_analysis_supported &&
9939                 m_pCapability->analysis_recommended_format == CAM_FORMAT_Y_ONLY) {
9940             format = m_pCapability->analysis_recommended_format;
9941         } else {
9942             if (m_pCapability->hw_analysis_supported) {
9943                 LOGW("Invalid analysis_recommended_format %d\n",
9944                         m_pCapability->analysis_recommended_format);
9945             }
9946             format = mAppPreviewFormat;
9947         }
9948         break;
9949     case CAM_STREAM_TYPE_SNAPSHOT:
9950         if ( mPictureFormat == CAM_FORMAT_YUV_422_NV16 ) {
9951             format = CAM_FORMAT_YUV_422_NV16;
9952         } else {
9953             char prop[PROPERTY_VALUE_MAX];
9954             int snapshotFormat;
9955             memset(prop, 0, sizeof(prop));
9956             property_get("persist.camera.snap.format", prop, "0");
9957             snapshotFormat = atoi(prop);
9958             if(snapshotFormat == 1) {
9959                 format = CAM_FORMAT_YUV_422_NV61;
9960             } else {
9961                 format = CAM_FORMAT_YUV_420_NV21;
9962             }
9963         }
9964         break;
9965     case CAM_STREAM_TYPE_VIDEO:
9966         if (isUBWCEnabled()) {
9967             char prop[PROPERTY_VALUE_MAX];
9968             int pFormat;
9969             memset(prop, 0, sizeof(prop));
9970             property_get("persist.camera.video.ubwc", prop, "1");
9971             pFormat = atoi(prop);
9972             if (pFormat == 1) {
9973                 format = CAM_FORMAT_YUV_420_NV12_UBWC;
9974             } else {
9975                 format = CAM_FORMAT_YUV_420_NV21_VENUS;
9976             }
9977         } else {
9978 #if VENUS_PRESENT
9979             format = CAM_FORMAT_YUV_420_NV21_VENUS;
9980 #else
9981             format = CAM_FORMAT_YUV_420_NV21;
9982 #endif
9983         }
9984         break;
9985     case CAM_STREAM_TYPE_RAW:
9986         if ((isRdiMode()) || (getofflineRAW())) {
9987             format = m_pCapability->rdi_mode_stream_fmt;
9988         } else if (mPictureFormat >= CAM_FORMAT_YUV_RAW_8BIT_YUYV) {
9989             format = (cam_format_t)mPictureFormat;
9990         } else {
9991             char raw_format[PROPERTY_VALUE_MAX];
9992             int rawFormat;
9993             memset(raw_format, 0, sizeof(raw_format));
9994             /*Default value is CAM_FORMAT_BAYER_QCOM_RAW_10BPP_GBRG*/
9995             property_get("persist.camera.raw.format", raw_format, "17");
9996             rawFormat = atoi(raw_format);
9997             format = (cam_format_t)rawFormat;
9998             LOGH("Raw stream format %d bundled with snapshot",
9999                     format);
10000         }
10001         break;
10002     case CAM_STREAM_TYPE_METADATA:
10003     case CAM_STREAM_TYPE_OFFLINE_PROC:
10004     case CAM_STREAM_TYPE_DEFAULT:
10005     default:
10006         break;
10007     }
10008 
10009     LOGD("Stream type = %d Stream Format = %d", streamType, format);
10010     return ret;
10011 }
10012 
10013 /*===========================================================================
10014  * FUNCTION   : getFlipMode
10015  *
10016  * DESCRIPTION: get flip mode
10017  *
10018  * PARAMETERS :
10019  *   @cam_intf_parm_type_t : [input] stream type
10020  *
10021  * RETURN     : int type of flip mode
10022  *              0 - no filp
10023  *              1 - FLIP_H
10024  *              2 - FLIP_V
10025  *              3 - FLIP_H | FLIP_V
10026  *==========================================================================*/
getFlipMode(cam_stream_type_t type)10027 int QCameraParameters::getFlipMode(cam_stream_type_t type)
10028 {
10029     const char *str = NULL;
10030     int flipMode = 0; // no flip
10031 
10032     switch(type){
10033     case CAM_STREAM_TYPE_PREVIEW:
10034         if (!isRdiMode()) {
10035             str = get(KEY_QC_PREVIEW_FLIP);
10036         }
10037         break;
10038     case CAM_STREAM_TYPE_VIDEO:
10039         str = get(KEY_QC_VIDEO_FLIP);
10040         break;
10041     case CAM_STREAM_TYPE_SNAPSHOT:
10042     case CAM_STREAM_TYPE_POSTVIEW:
10043         str = get(KEY_QC_SNAPSHOT_PICTURE_FLIP);
10044         break;
10045     default:
10046         LOGD("No flip mode for stream type %d", type);
10047         break;
10048     }
10049 
10050     if(str != NULL){
10051         //Need give corresponding filp value based on flip mode strings
10052         int value = lookupAttr(FLIP_MODES_MAP, PARAM_MAP_SIZE(FLIP_MODES_MAP), str);
10053         if(value != NAME_NOT_FOUND)
10054             flipMode = value;
10055         }
10056 
10057     LOGH("the filp mode of stream type %d is %d .", type, flipMode);
10058     return flipMode;
10059 }
10060 
10061 /*===========================================================================
10062  * FUNCTION   : isSnapshotFDNeeded
10063  *
10064  * DESCRIPTION: check whether Face Detection Metadata is needed
10065  *
10066  * PARAMETERS : none
10067  *
10068  * RETURN     : bool type of status
10069  *              0 - need
10070  *              1 - not need
10071  *==========================================================================*/
isSnapshotFDNeeded()10072 bool QCameraParameters::isSnapshotFDNeeded()
10073 {
10074     return getInt(KEY_QC_SNAPSHOT_FD_DATA);
10075 }
10076 
10077 /*===========================================================================
10078  * FUNCTION   : getStreamDimension
10079  *
10080  * DESCRIPTION: get stream dimension by its type
10081  *
10082  * PARAMETERS :
10083  *   @streamType : [input] stream type
10084  *   @dim        : [output] stream dimension
10085  *
10086  * RETURN     : int32_t type of status
10087  *              NO_ERROR  -- success
10088  *              none-zero failure code
10089  *==========================================================================*/
getStreamDimension(cam_stream_type_t streamType,cam_dimension_t & dim)10090 int32_t QCameraParameters::getStreamDimension(cam_stream_type_t streamType,
10091                                                cam_dimension_t &dim)
10092 {
10093     int32_t ret = NO_ERROR;
10094     memset(&dim, 0, sizeof(cam_dimension_t));
10095 
10096     switch (streamType) {
10097     case CAM_STREAM_TYPE_PREVIEW:
10098     case CAM_STREAM_TYPE_CALLBACK:
10099         getPreviewSize(&dim.width, &dim.height);
10100         break;
10101     case CAM_STREAM_TYPE_POSTVIEW:
10102         getPreviewSize(&dim.width, &dim.height);
10103         break;
10104     case CAM_STREAM_TYPE_SNAPSHOT:
10105         if (isPostProcScaling()) {
10106             getMaxPicSize(dim);
10107         } else if (getRecordingHintValue()) {
10108             // live snapshot
10109             getLiveSnapshotSize(dim);
10110         } else {
10111             getPictureSize(&dim.width, &dim.height);
10112         }
10113         break;
10114     case CAM_STREAM_TYPE_VIDEO:
10115         getVideoSize(&dim.width, &dim.height);
10116         break;
10117     case CAM_STREAM_TYPE_RAW:
10118         //dim = m_pCapability->raw_dim;
10119         getRawSize(dim);
10120         break;
10121     case CAM_STREAM_TYPE_METADATA:
10122         dim.width = (int32_t)sizeof(metadata_buffer_t);
10123         dim.height = 1;
10124         break;
10125     case CAM_STREAM_TYPE_OFFLINE_PROC:
10126         if (isPostProcScaling()) {
10127             if (getRecordingHintValue()) {
10128                 // live snapshot
10129                 getLiveSnapshotSize(dim);
10130             } else {
10131                 getPictureSize(&dim.width, &dim.height);
10132             }
10133         }
10134         break;
10135     case CAM_STREAM_TYPE_ANALYSIS:
10136         cam_dimension_t prv_dim, max_dim;
10137 
10138         /* Analysis stream need aspect ratio as preview stream */
10139         getPreviewSize(&prv_dim.width, &prv_dim.height);
10140 
10141         max_dim.width = m_pCapability->analysis_max_res.width;
10142         max_dim.height = m_pCapability->analysis_max_res.height;
10143 
10144         if ((getRecordingHintValue() == true)
10145                 && fdModeInVideo()
10146                 && m_pCapability->hw_analysis_supported) {
10147             max_dim.width /= 2;
10148             max_dim.height /= 2;
10149         }
10150 
10151         if (prv_dim.width > max_dim.width || prv_dim.height > max_dim.height) {
10152             double max_ratio, requested_ratio;
10153 
10154             max_ratio = (double)max_dim.width / (double)max_dim.height;
10155             requested_ratio = (double)prv_dim.width / (double)prv_dim.height;
10156 
10157             if (max_ratio < requested_ratio) {
10158                 dim.width = max_dim.width;
10159                 dim.height = (int32_t)((double)dim.width / requested_ratio);
10160             } else {
10161                 dim.height = max_dim.height;
10162                 dim.width = (int32_t)((double)max_dim.height * requested_ratio);
10163             }
10164             dim.width &= ~0x1;
10165             dim.height &= ~0x1;
10166         } else {
10167             dim.width = prv_dim.width;
10168             dim.height = prv_dim.height;
10169         }
10170       break;
10171     case CAM_STREAM_TYPE_DEFAULT:
10172     default:
10173         LOGE("no dimension for unsupported stream type %d",
10174                streamType);
10175         ret = BAD_VALUE;
10176         break;
10177     }
10178 
10179     LOGD("Stream type = %d Stream Dimension = %d X %d",
10180              streamType, dim.width, dim.height);
10181     return ret;
10182 }
10183 
10184 /*===========================================================================
10185  * FUNCTION   : getParameters
10186  *
10187  * DESCRIPTION: Return a C string containing the parameters
10188  *
10189  * PARAMETERS : none
10190  *
10191  * RETURN     : a string containing parameter pairs
10192  *==========================================================================*/
getParameters()10193 char* QCameraParameters::getParameters()
10194 {
10195     char* strParams = NULL;
10196     String8 str;
10197 
10198     int cur_width, cur_height;
10199     //Need take care Scale picture size
10200     if(m_reprocScaleParam.isScaleEnabled() &&
10201         m_reprocScaleParam.isUnderScaling()){
10202         int scale_width, scale_height;
10203 
10204         m_reprocScaleParam.getPicSizeFromAPK(scale_width,scale_height);
10205         getPictureSize(&cur_width, &cur_height);
10206 
10207         String8 pic_size;
10208         char buffer[32];
10209         snprintf(buffer, sizeof(buffer), "%dx%d", scale_width, scale_height);
10210         pic_size.append(buffer);
10211         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
10212     }
10213 
10214     str = flatten();
10215     strParams = (char *)malloc(sizeof(char)*(str.length()+1));
10216     if(strParams != NULL){
10217         memset(strParams, 0, sizeof(char)*(str.length()+1));
10218         strlcpy(strParams, str.string(), str.length()+1);
10219         strParams[str.length()] = 0;
10220     }
10221 
10222     if(m_reprocScaleParam.isScaleEnabled() &&
10223         m_reprocScaleParam.isUnderScaling()){
10224         //need set back picture size
10225         String8 pic_size;
10226         char buffer[32];
10227         snprintf(buffer, sizeof(buffer), "%dx%d", cur_width, cur_height);
10228         pic_size.append(buffer);
10229         set(CameraParameters::KEY_PICTURE_SIZE, pic_size);
10230     }
10231     return strParams;
10232 }
10233 
10234 #ifdef TARGET_TS_MAKEUP
10235 /*===========================================================================
10236  * FUNCTION   : getTsMakeupInfo
10237  *
10238  * DESCRIPTION: get TsMakeup info
10239  *
10240  * PARAMETERS :
10241  *   @whiteLevel : [output] white level
10242  *   @cleanLevel : [output] clean level
10243 
10244  * RETURN     : Whether makeup is enabled or not
10245  *==========================================================================*/
getTsMakeupInfo(int & whiteLevel,int & cleanLevel) const10246 bool QCameraParameters::getTsMakeupInfo(int &whiteLevel, int &cleanLevel) const
10247 {
10248     const char* pch_makeup_enable = get(QCameraParameters::KEY_TS_MAKEUP);
10249     if (pch_makeup_enable == NULL) {
10250         LOGH("pch_makeup_enable = null");
10251         return false;
10252     }
10253     bool enableMakeup =
10254             (strcmp(pch_makeup_enable,"On") == 0);
10255     if (enableMakeup) {
10256         whiteLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_WHITEN);
10257         cleanLevel = getInt(QCameraParameters::KEY_TS_MAKEUP_CLEAN);
10258     }
10259     return enableMakeup;
10260 }
10261 #endif
10262 
10263 /*===========================================================================
10264  * FUNCTION   : getPreviewHalPixelFormat
10265  *
10266  * DESCRIPTION: get preview HAL pixel format
10267  *
10268  * PARAMETERS : none
10269  *
10270  * RETURN     : HAL pixel format
10271  *==========================================================================*/
getPreviewHalPixelFormat()10272 int QCameraParameters::getPreviewHalPixelFormat()
10273 {
10274     int32_t halPixelFormat;
10275     cam_format_t fmt;
10276     getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
10277 
10278     switch (fmt) {
10279     case CAM_FORMAT_YUV_420_NV12:
10280         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP;
10281         break;
10282     case CAM_FORMAT_YUV_420_NV21:
10283         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
10284         break;
10285     case CAM_FORMAT_YUV_420_NV21_ADRENO:
10286         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
10287         break;
10288     case CAM_FORMAT_YUV_420_YV12:
10289         halPixelFormat = HAL_PIXEL_FORMAT_YV12;
10290         break;
10291     case CAM_FORMAT_YUV_420_NV12_VENUS:
10292         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;
10293         break;
10294     case CAM_FORMAT_YUV_420_NV21_VENUS:
10295         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS;
10296         break;
10297     case CAM_FORMAT_YUV_420_NV12_UBWC:
10298         halPixelFormat = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
10299         break;
10300     case CAM_FORMAT_YUV_422_NV16:
10301     case CAM_FORMAT_YUV_422_NV61:
10302     default:
10303         halPixelFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
10304         break;
10305     }
10306     LOGH("format %d\n", halPixelFormat);
10307     return halPixelFormat;
10308 }
10309 
10310 /*===========================================================================
10311  * FUNCTION   : getthumbnailSize
10312  *
10313  * DESCRIPTION: get thumbnail size
10314  *
10315  * PARAMETERS :
10316  *   @width, height : [output] thumbnail width and height
10317  *
10318  * RETURN     : none
10319  *==========================================================================*/
getThumbnailSize(int * width,int * height) const10320 void QCameraParameters::getThumbnailSize(int *width, int *height) const
10321 {
10322     *width = getInt(KEY_JPEG_THUMBNAIL_WIDTH);
10323     *height = getInt(KEY_JPEG_THUMBNAIL_HEIGHT);
10324 }
10325 
10326 /*===========================================================================
10327  * FUNCTION   : getZSLBurstInterval
10328  *
10329  * DESCRIPTION: get ZSL burst interval setting
10330  *
10331  * PARAMETERS : none
10332  *
10333  * RETURN     : ZSL burst interval value
10334  *==========================================================================*/
getZSLBurstInterval()10335 uint8_t QCameraParameters::getZSLBurstInterval()
10336 {
10337     int interval = getInt(KEY_QC_ZSL_BURST_INTERVAL);
10338     if (interval < 0) {
10339         interval = 1;
10340     }
10341     return (uint8_t)interval;
10342 }
10343 
10344 /*===========================================================================
10345  * FUNCTION   : getZSLQueueDepth
10346  *
10347  * DESCRIPTION: get ZSL queue depth
10348  *
10349  * PARAMETERS : none
10350  *
10351  * RETURN     : ZSL queue depth value
10352  *==========================================================================*/
getZSLQueueDepth()10353 uint8_t QCameraParameters::getZSLQueueDepth()
10354 {
10355     int qdepth = getInt(KEY_QC_ZSL_QUEUE_DEPTH);
10356     if (qdepth < 0) {
10357         qdepth = 2;
10358     }
10359     if (isLowMemoryDevice()) {
10360         qdepth = 1;
10361     }
10362     return (uint8_t)qdepth;
10363 }
10364 
10365 /*===========================================================================
10366  * FUNCTION   : getZSLBackLookCount
10367  *
10368  * DESCRIPTION: get ZSL backlook count setting
10369  *
10370  * PARAMETERS : none
10371  *
10372  * RETURN     : ZSL backlook count value
10373  *==========================================================================*/
getZSLBackLookCount()10374 uint8_t QCameraParameters::getZSLBackLookCount()
10375 {
10376     int look_back = getInt(KEY_QC_ZSL_BURST_LOOKBACK);
10377     if (look_back < 0) {
10378         look_back = 2;
10379     }
10380     if (isLowMemoryDevice()) {
10381         look_back = 1;
10382     }
10383     return (uint8_t)look_back;
10384 }
10385 /*===========================================================================
10386  * FUNCTION   : isVideoBuffersCached
10387  *
10388  * DESCRIPTION: Query buffers are cached /un cached
10389  *
10390  * PARAMETERS : None
10391  *
10392  * RETURN     : buffers are cached /un cached
10393  *==========================================================================*/
isVideoBuffersCached()10394 bool QCameraParameters::isVideoBuffersCached()
10395 {
10396     const char *cached_mem  = get(KEY_QC_CACHE_VIDEO_BUFFERS);
10397     if (cached_mem != NULL) {
10398         if (strcmp(cached_mem, VALUE_DISABLE) != 0) {
10399             return true;
10400         }
10401     }
10402     return false;
10403 }
10404 /*===========================================================================
10405  * FUNCTION   : getZSLMaxUnmatchedFrames
10406  *
10407  * DESCRIPTION: get allowed ZSL max unmatched frames number
10408  *
10409  * PARAMETERS : none
10410  *
10411  * RETURN     : ZSL backlook count value
10412  *==========================================================================*/
getMaxUnmatchedFramesInQueue()10413 uint8_t QCameraParameters::getMaxUnmatchedFramesInQueue()
10414 {
10415     return (uint8_t)(m_pCapability->min_num_pp_bufs);
10416 }
10417 
10418 /*===========================================================================
10419  * FUNCTION   : setRecordingHintValue
10420  *
10421  * DESCRIPTION: set recording hint
10422  *
10423  * PARAMETERS :
10424  *   @value   : video hint value
10425  *
10426  * RETURN     : int32_t type of status
10427  *              NO_ERROR  -- success
10428  *              none-zero failure code
10429  *==========================================================================*/
setRecordingHintValue(int32_t value)10430 int QCameraParameters::setRecordingHintValue(int32_t value)
10431 {
10432     LOGH("VideoHint = %d", value);
10433     bool newValue = (value > 0)? true : false;
10434 
10435     if ( m_bRecordingHint != newValue ) {
10436         m_bNeedRestart = true;
10437         m_bRecordingHint_new = newValue;
10438     } else {
10439         m_bRecordingHint_new = m_bRecordingHint;
10440     }
10441     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RECORDING_HINT, value)) {
10442         return BAD_VALUE;
10443     }
10444 
10445     return NO_ERROR;
10446 }
10447 
10448 /*===========================================================================
10449  * FUNCTION   : getNumOfSnapshots
10450  *
10451  * DESCRIPTION: get number of snapshot per shutter
10452  *
10453  * PARAMETERS : none
10454  *
10455  * RETURN     : number of snapshot per shutter
10456  *==========================================================================*/
getNumOfSnapshots()10457 uint8_t QCameraParameters::getNumOfSnapshots()
10458 {
10459     uint8_t numOfSnapshot = 1;
10460     int val = getInt(KEY_QC_NUM_SNAPSHOT_PER_SHUTTER);
10461     if (0 < val) {
10462         numOfSnapshot = (uint8_t)val;
10463     }
10464 
10465     return (uint8_t)numOfSnapshot;
10466 }
10467 
10468 /*===========================================================================
10469  * FUNCTION   : getBurstCountForAdvancedCapture
10470  *
10471  * DESCRIPTION: get burst count for advanced capture.
10472  *
10473  * PARAMETERS : none
10474  *
10475  * RETURN     : number of snapshot required for advanced capture.
10476  *==========================================================================*/
getBurstCountForAdvancedCapture()10477 uint8_t QCameraParameters::getBurstCountForAdvancedCapture()
10478 {
10479     uint32_t burstCount = 0;
10480     if (isUbiFocusEnabled()) {
10481         //number of snapshots required for Ubi Focus.
10482         burstCount = m_pCapability->ubifocus_af_bracketing_need.burst_count;
10483     } else if (isUbiRefocus()) {
10484         //number of snapshots required for Opti Zoom.
10485         burstCount = m_pCapability->refocus_af_bracketing_need.burst_count;
10486     } else if (isOptiZoomEnabled()) {
10487         //number of snapshots required for Opti Zoom.
10488         burstCount = m_pCapability->opti_zoom_settings_need.burst_count;
10489     } else if (isChromaFlashEnabled()) {
10490         //number of snapshots required for Chroma Flash.
10491         burstCount = m_pCapability->chroma_flash_settings_need.burst_count;
10492     } else if (isStillMoreEnabled()) {
10493         //number of snapshots required for Still More.
10494         if (isSeeMoreEnabled()) {
10495             burstCount = 1;
10496         } else if ((m_stillmore_config.burst_count >=
10497                 m_pCapability->stillmore_settings_need.min_burst_count) &&
10498                 (m_stillmore_config.burst_count <=
10499                 m_pCapability->stillmore_settings_need.max_burst_count)) {
10500             burstCount = m_stillmore_config.burst_count;
10501         } else {
10502             burstCount = m_pCapability->stillmore_settings_need.burst_count;
10503         }
10504     } else if (isHDREnabled()) {
10505         //number of snapshots required for HDR.
10506         burstCount = m_pCapability->hdr_bracketing_setting.num_frames;
10507     } else if (isAEBracketEnabled()) {
10508       burstCount = 0;
10509       const char *str_val = m_AEBracketingClient.values;
10510       if ((str_val != NULL) && (strlen(str_val) > 0)) {
10511           char prop[PROPERTY_VALUE_MAX];
10512           memset(prop, 0, sizeof(prop));
10513           strlcpy(prop, str_val, PROPERTY_VALUE_MAX);
10514           char *saveptr = NULL;
10515           char *token = strtok_r(prop, ",", &saveptr);
10516           while (token != NULL) {
10517               token = strtok_r(NULL, ",", &saveptr);
10518               burstCount++;
10519           }
10520       }
10521     }
10522 
10523     if (burstCount <= 0) {
10524         burstCount = getNumOfSnapshots();
10525     }
10526 
10527     LOGH("Snapshot burst count = %d", burstCount);
10528     return (uint8_t)burstCount;
10529 }
10530 
10531 /*===========================================================================
10532  * FUNCTION   : getNumOfRetroSnapshots
10533  *
10534  * DESCRIPTION: get number of retro active snapshots per shutter
10535  *
10536  * PARAMETERS : none
10537  *
10538  * RETURN     : number of retro active snapshots per shutter
10539  *==========================================================================*/
getNumOfRetroSnapshots()10540 uint8_t QCameraParameters::getNumOfRetroSnapshots()
10541 {
10542     int numOfRetroSnapshots = getInt(KEY_QC_NUM_RETRO_BURST_PER_SHUTTER);
10543     if (numOfRetroSnapshots < 0) {
10544         numOfRetroSnapshots = 0;
10545     }
10546     LOGH("numOfRetroSnaps - %d", numOfRetroSnapshots);
10547     return (uint8_t)numOfRetroSnapshots;
10548 }
10549 
10550 /*===========================================================================
10551  * FUNCTION   : getNumOfExtraHDRInBufsIfNeeded
10552  *
10553  * DESCRIPTION: get number of extra input buffers needed by HDR
10554  *
10555  * PARAMETERS : none
10556  *
10557  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
10558  *==========================================================================*/
getNumOfExtraHDRInBufsIfNeeded()10559 uint8_t QCameraParameters::getNumOfExtraHDRInBufsIfNeeded()
10560 {
10561     unsigned int numOfBufs = 0;
10562 
10563     if (isHDREnabled()) {
10564         numOfBufs += m_pCapability->hdr_bracketing_setting.num_frames;
10565         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
10566             numOfBufs++;
10567         }
10568         numOfBufs--; // Only additional buffers need to be returned
10569     }
10570 
10571     return (uint8_t)(numOfBufs);
10572 }
10573 
10574 /*===========================================================================
10575  * FUNCTION   : getNumOfExtraHDROutBufsIfNeeded
10576  *
10577  * DESCRIPTION: get number of extra output buffers needed by HDR
10578  *
10579  * PARAMETERS : none
10580  *
10581  * RETURN     : number of extra buffers needed by HDR; 0 if not HDR enabled
10582  *==========================================================================*/
getNumOfExtraHDROutBufsIfNeeded()10583 uint8_t QCameraParameters::getNumOfExtraHDROutBufsIfNeeded()
10584 {
10585     int numOfBufs = 0;
10586 
10587     if (isHDREnabled() && isHDR1xFrameEnabled()) {
10588         numOfBufs++;
10589     }
10590 
10591     return (uint8_t)(numOfBufs);
10592 }
10593 
10594 /*===========================================================================
10595  * FUNCTION   : getJpegQuality
10596  *
10597  * DESCRIPTION: get jpeg encoding quality
10598  *
10599  * PARAMETERS : none
10600  *
10601  * RETURN     : jpeg encoding quality
10602  *==========================================================================*/
getJpegQuality()10603 uint32_t QCameraParameters::getJpegQuality()
10604 {
10605     int quality = getInt(KEY_JPEG_QUALITY);
10606     if (quality < 0) {
10607         quality = 85; // set to default quality value
10608     }
10609     return (uint32_t)quality;
10610 }
10611 
10612 /*===========================================================================
10613  * FUNCTION   : getRotation
10614  *
10615  * DESCRIPTION: get application configured rotation
10616  *
10617  * PARAMETERS : none
10618  *
10619  * RETURN     : rotation value
10620  *==========================================================================*/
getRotation()10621 uint32_t QCameraParameters::getRotation() {
10622     int rotation = 0;
10623 
10624     //If exif rotation is set, do not rotate captured image
10625     if (!useJpegExifRotation()) {
10626         rotation = mRotation;
10627         if (rotation < 0) {
10628             rotation = 0;
10629         }
10630     }
10631     return (uint32_t)rotation;
10632 }
10633 
10634 /*===========================================================================
10635  * FUNCTION   : setJpegRotation
10636  *
10637  * DESCRIPTION: set jpeg rotation value configured internally
10638  *
10639  * PARAMETERS : none
10640  *
10641  * RETURN     : jpeg rotation value
10642  *==========================================================================*/
setJpegRotation(int rotation)10643 void QCameraParameters::setJpegRotation(int rotation) {
10644     if (rotation == 0 || rotation == 90 ||
10645             rotation == 180 || rotation == 270) {
10646         mJpegRotation = (uint32_t)rotation;
10647     }
10648 }
10649 
10650 /*===========================================================================
10651  * FUNCTION   : getDeviceRotation
10652  *
10653  * DESCRIPTION: get device rotation value
10654  *
10655  * PARAMETERS : none
10656  *
10657  * RETURN     : device rotation value
10658  *==========================================================================*/
getDeviceRotation()10659 uint32_t QCameraParameters::getDeviceRotation() {
10660     int rotation = 0;
10661 
10662     rotation = mRotation;
10663     if (rotation < 0) {
10664         rotation = 0;
10665     }
10666 
10667     return (uint32_t)rotation;
10668 }
10669 
10670 /*===========================================================================
10671  * FUNCTION   : getJpegExifRotation
10672  *
10673  * DESCRIPTION: get exif rotation value
10674  *
10675  * PARAMETERS : none
10676  *
10677  * RETURN     : rotation value
10678  *==========================================================================*/
getJpegExifRotation()10679 uint32_t QCameraParameters::getJpegExifRotation() {
10680     int rotation = 0;
10681 
10682     if (useJpegExifRotation()) {
10683         rotation = mRotation;
10684         if (rotation < 0) {
10685             rotation = 0;
10686         }
10687     }
10688     return (uint32_t)rotation;
10689 }
10690 
10691 /*===========================================================================
10692  * FUNCTION   : useJpegExifRotation
10693  *
10694  * DESCRIPTION: Check if jpeg exif rotation need to be used
10695  *
10696  * PARAMETERS : none
10697  *
10698  * RETURN     : true if jpeg exif rotation need to be used
10699  *==========================================================================*/
useJpegExifRotation()10700 bool QCameraParameters::useJpegExifRotation() {
10701     char exifRotation[PROPERTY_VALUE_MAX];
10702 
10703     property_get("persist.camera.exif.rotation", exifRotation, "off");
10704 
10705     if (!strcmp(exifRotation, "on")) {
10706         return true;
10707     }
10708 
10709     if (!(m_pCapability->qcom_supported_feature_mask & CAM_QCOM_FEATURE_ROTATION)) {
10710         return true;
10711     }
10712 
10713     return false;
10714 }
10715 
10716 /*===========================================================================
10717  * FUNCTION   : getEffectValue
10718  *
10719  * DESCRIPTION: get effect value
10720  *
10721  * PARAMETERS : none
10722  *
10723  * RETURN     : effect value
10724  *==========================================================================*/
getEffectValue()10725 int32_t QCameraParameters::getEffectValue()
10726 {
10727     uint32_t cnt = 0;
10728     const char *effect = get(KEY_EFFECT);
10729     if (effect) {
10730         while (NULL != EFFECT_MODES_MAP[cnt].desc) {
10731             if (!strcmp(EFFECT_MODES_MAP[cnt].desc, effect)) {
10732                 return EFFECT_MODES_MAP[cnt].val;
10733             }
10734             cnt++;
10735         }
10736     } else {
10737         LOGW("Missing effect value");
10738     }
10739     return CAM_EFFECT_MODE_OFF;
10740 }
10741 
10742 /*===========================================================================
10743  * FUNCTION   : parseGPSCoordinate
10744  *
10745  * DESCRIPTION: parse GPS coordinate string
10746  *
10747  * PARAMETERS :
10748  *   @coord_str : [input] coordinate string
10749  *   @coord     : [output]  ptr to struct to store coordinate
10750  *
10751  * RETURN     : int32_t type of status
10752  *              NO_ERROR  -- success
10753  *              none-zero failure code
10754  *==========================================================================*/
parseGPSCoordinate(const char * coord_str,rat_t * coord)10755 int QCameraParameters::parseGPSCoordinate(const char *coord_str, rat_t* coord)
10756 {
10757     if(coord == NULL) {
10758         LOGE("error, invalid argument coord == NULL");
10759         return BAD_VALUE;
10760     }
10761     double degF = atof(coord_str);
10762     if (degF < 0) {
10763         degF = -degF;
10764     }
10765     double minF = (degF - (double)(int) degF) * 60.0;
10766     double secF = (minF - (double)(int) minF) * 60.0;
10767 
10768     getRational(&coord[0], (int)degF, 1);
10769     getRational(&coord[1], (int)minF, 1);
10770     getRational(&coord[2], (int)(secF * 10000.0), 10000);
10771     return NO_ERROR;
10772 }
10773 
10774 /*===========================================================================
10775  * FUNCTION   : getExifDateTime
10776  *
10777  * DESCRIPTION: query exif date time
10778  *
10779  * PARAMETERS :
10780  *   @dateTime    : String to store exif date time.
10781  *                  Should be leaved unchanged in case of error.
10782  *   @subsecTime  : String to store exif time nanoseconds.
10783  *                  Should be leaved unchanged in case of error.
10784  *
10785  * RETURN     : int32_t type of status
10786  *              NO_ERROR  -- success
10787  *              none-zero failure code
10788  *==========================================================================*/
getExifDateTime(String8 & dateTime,String8 & subsecTime)10789 int32_t QCameraParameters::getExifDateTime(String8 &dateTime, String8 &subsecTime)
10790 {
10791     int32_t ret = NO_ERROR;
10792 
10793     //get time and date from system
10794     struct timeval tv;
10795     struct tm timeinfo_data;
10796 
10797     int res = gettimeofday(&tv, NULL);
10798     if (0 == res) {
10799         struct tm *timeinfo = localtime_r(&tv.tv_sec, &timeinfo_data);
10800         if (NULL != timeinfo) {
10801             //Write datetime according to EXIF Spec
10802             //"YYYY:MM:DD HH:MM:SS" (20 chars including \0)
10803             dateTime = String8::format("%04d:%02d:%02d %02d:%02d:%02d",
10804                     timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
10805                     timeinfo->tm_mday, timeinfo->tm_hour,
10806                     timeinfo->tm_min, timeinfo->tm_sec);
10807             //Write subsec according to EXIF Sepc
10808             subsecTime = String8::format("%06ld", tv.tv_usec);
10809         } else {
10810             LOGE("localtime_r() error");
10811             ret = UNKNOWN_ERROR;
10812         }
10813     } else if (-1 == res) {
10814         LOGE("gettimeofday() error: %s", strerror(errno));
10815         ret = UNKNOWN_ERROR;
10816     } else {
10817         LOGE("gettimeofday() unexpected return code: %d", res);
10818         ret = UNKNOWN_ERROR;
10819     }
10820 
10821     return ret;
10822 }
10823 
10824 /*===========================================================================
10825  * FUNCTION   : getRational
10826  *
10827  * DESCRIPTION: compose rational struct
10828  *
10829  * PARAMETERS :
10830  *   @rat     : ptr to struct to store rational info
10831  *   @num     :num of the rational
10832  *   @denom   : denom of the rational
10833  *
10834  * RETURN     : int32_t type of status
10835  *              NO_ERROR  -- success
10836  *              none-zero failure code
10837  *==========================================================================*/
getRational(rat_t * rat,int num,int denom)10838 int32_t QCameraParameters::getRational(rat_t *rat, int num, int denom)
10839 {
10840     if ((0 > num) || (0 > denom)) {
10841         LOGE("Negative values");
10842         return BAD_VALUE;
10843     }
10844     if (NULL == rat) {
10845         LOGE("NULL rat input");
10846         return BAD_VALUE;
10847     }
10848     rat->num = (uint32_t)num;
10849     rat->denom = (uint32_t)denom;
10850     return NO_ERROR;
10851 }
10852 
10853 /*===========================================================================
10854  * FUNCTION   : getExifFocalLength
10855  *
10856  * DESCRIPTION: get exif focal lenght
10857  *
10858  * PARAMETERS :
10859  *   @focalLength : ptr to rational strcut to store focal lenght
10860  *
10861  * RETURN     : int32_t type of status
10862  *              NO_ERROR  -- success
10863  *              none-zero failure code
10864  *==========================================================================*/
getExifFocalLength(rat_t * focalLength)10865 int32_t QCameraParameters::getExifFocalLength(rat_t *focalLength)
10866 {
10867     int focalLengthValue =
10868         (int)(getFloat(QCameraParameters::KEY_FOCAL_LENGTH) * FOCAL_LENGTH_DECIMAL_PRECISION);
10869     return getRational(focalLength, focalLengthValue, FOCAL_LENGTH_DECIMAL_PRECISION);
10870 }
10871 
10872 /*===========================================================================
10873  * FUNCTION   : getExifIsoSpeed
10874  *
10875  * DESCRIPTION: get exif ISO speed
10876  *
10877  * PARAMETERS : none
10878  *
10879  * RETURN     : ISO speed value
10880  *==========================================================================*/
getExifIsoSpeed()10881 uint16_t QCameraParameters::getExifIsoSpeed()
10882 {
10883     uint16_t isoSpeed = 0;
10884     const char *iso_str = get(QCameraParameters::KEY_QC_ISO_MODE);
10885     int iso_index = lookupAttr(ISO_MODES_MAP, PARAM_MAP_SIZE(ISO_MODES_MAP), iso_str);
10886     switch (iso_index) {
10887     case CAM_ISO_MODE_AUTO:
10888         isoSpeed = 0;
10889         break;
10890     case CAM_ISO_MODE_DEBLUR:
10891         isoSpeed = 1;
10892         break;
10893     case CAM_ISO_MODE_100:
10894         isoSpeed = 100;
10895         break;
10896     case CAM_ISO_MODE_200:
10897         isoSpeed = 200;
10898         break;
10899     case CAM_ISO_MODE_400:
10900         isoSpeed = 400;
10901         break;
10902     case CAM_ISO_MODE_800:
10903         isoSpeed = 800;
10904         break;
10905     case CAM_ISO_MODE_1600:
10906         isoSpeed = 1600;
10907         break;
10908     case CAM_ISO_MODE_3200:
10909         isoSpeed = 3200;
10910         break;
10911     }
10912     return isoSpeed;
10913 }
10914 
10915 /*===========================================================================
10916  * FUNCTION   : getExifGpsProcessingMethod
10917  *
10918  * DESCRIPTION: get GPS processing method
10919  *
10920  * PARAMETERS :
10921  *   @gpsProcessingMethod : string to store GPS process method
10922  *   @count               : lenght of the string
10923  *
10924  * RETURN     : int32_t type of status
10925  *              NO_ERROR  -- success
10926  *              none-zero failure code
10927  *==========================================================================*/
getExifGpsProcessingMethod(char * gpsProcessingMethod,uint32_t & count)10928 int32_t QCameraParameters::getExifGpsProcessingMethod(char *gpsProcessingMethod,
10929                                                       uint32_t &count)
10930 {
10931     const char *str = get(KEY_GPS_PROCESSING_METHOD);
10932     if(str != NULL) {
10933         memcpy(gpsProcessingMethod, ExifAsciiPrefix, EXIF_ASCII_PREFIX_SIZE);
10934         count = EXIF_ASCII_PREFIX_SIZE;
10935         strlcpy(gpsProcessingMethod + EXIF_ASCII_PREFIX_SIZE, str, GPS_PROCESSING_METHOD_SIZE);
10936         count += (uint32_t)strlen(str);
10937         gpsProcessingMethod[count++] = '\0'; // increase 1 for the last NULL char
10938         return NO_ERROR;
10939     } else {
10940         return BAD_VALUE;
10941     }
10942 }
10943 
10944 /*===========================================================================
10945  * FUNCTION   : getExifLatitude
10946  *
10947  * DESCRIPTION: get exif latitude
10948  *
10949  * PARAMETERS :
10950  *   @latitude : ptr to rational struct to store latitude info
10951  *   @ladRef   : charater to indicate latitude reference
10952  *
10953  * RETURN     : int32_t type of status
10954  *              NO_ERROR  -- success
10955  *              none-zero failure code
10956  *==========================================================================*/
getExifLatitude(rat_t * latitude,char * latRef)10957 int32_t QCameraParameters::getExifLatitude(rat_t *latitude,
10958                                            char *latRef)
10959 {
10960     const char *str = get(KEY_GPS_LATITUDE);
10961     if(str != NULL) {
10962         parseGPSCoordinate(str, latitude);
10963 
10964         //set Latitude Ref
10965         float latitudeValue = getFloat(KEY_GPS_LATITUDE);
10966         if(latitudeValue < 0.0f) {
10967             latRef[0] = 'S';
10968         } else {
10969             latRef[0] = 'N';
10970         }
10971         latRef[1] = '\0';
10972         return NO_ERROR;
10973     }else{
10974         return BAD_VALUE;
10975     }
10976 }
10977 
10978 /*===========================================================================
10979  * FUNCTION   : getExifLongitude
10980  *
10981  * DESCRIPTION: get exif longitude
10982  *
10983  * PARAMETERS :
10984  *   @longitude : ptr to rational struct to store longitude info
10985  *   @lonRef    : charater to indicate longitude reference
10986  *
10987  * RETURN     : int32_t type of status
10988  *              NO_ERROR  -- success
10989  *              none-zero failure code
10990  *==========================================================================*/
getExifLongitude(rat_t * longitude,char * lonRef)10991 int32_t QCameraParameters::getExifLongitude(rat_t *longitude,
10992                                             char *lonRef)
10993 {
10994     const char *str = get(KEY_GPS_LONGITUDE);
10995     if(str != NULL) {
10996         parseGPSCoordinate(str, longitude);
10997 
10998         //set Longitude Ref
10999         float longitudeValue = getFloat(KEY_GPS_LONGITUDE);
11000         if(longitudeValue < 0.0f) {
11001             lonRef[0] = 'W';
11002         } else {
11003             lonRef[0] = 'E';
11004         }
11005         lonRef[1] = '\0';
11006         return NO_ERROR;
11007     }else{
11008         return BAD_VALUE;
11009     }
11010 }
11011 
11012 /*===========================================================================
11013  * FUNCTION   : getExifAltitude
11014  *
11015  * DESCRIPTION: get exif altitude
11016  *
11017  * PARAMETERS :
11018  *   @altitude : ptr to rational struct to store altitude info
11019  *   @altRef   : charater to indicate altitude reference
11020  *
11021  * RETURN     : int32_t type of status
11022  *              NO_ERROR  -- success
11023  *              none-zero failure code
11024  *==========================================================================*/
getExifAltitude(rat_t * altitude,char * altRef)11025 int32_t QCameraParameters::getExifAltitude(rat_t *altitude,
11026                                            char *altRef)
11027 {
11028     const char *str = get(KEY_GPS_ALTITUDE);
11029     if(str != NULL) {
11030         double value = atof(str);
11031         *altRef = 0;
11032         if(value < 0){
11033             *altRef = 1;
11034             value = -value;
11035         }
11036         return getRational(altitude, (int)(value*1000), 1000);
11037     }else{
11038         return BAD_VALUE;
11039     }
11040 }
11041 
11042 /*===========================================================================
11043  * FUNCTION   : getExifGpsDateTimeStamp
11044  *
11045  * DESCRIPTION: get exif GPS date time stamp
11046  *
11047  * PARAMETERS :
11048  *   @gpsDateStamp : GPS date time stamp string
11049  *   @bufLen       : length of the string
11050  *   @gpsTimeStamp : ptr to rational struct to store time stamp info
11051  *
11052  * RETURN     : int32_t type of status
11053  *              NO_ERROR  -- success
11054  *              none-zero failure code
11055  *==========================================================================*/
getExifGpsDateTimeStamp(char * gpsDateStamp,uint32_t bufLen,rat_t * gpsTimeStamp)11056 int32_t QCameraParameters::getExifGpsDateTimeStamp(char *gpsDateStamp,
11057                                                    uint32_t bufLen,
11058                                                    rat_t *gpsTimeStamp)
11059 {
11060     const char *str = get(KEY_GPS_TIMESTAMP);
11061     if(str != NULL) {
11062         time_t unixTime = (time_t)atol(str);
11063         struct tm *UTCTimestamp = gmtime(&unixTime);
11064 
11065         if(!UTCTimestamp) {
11066             LOGE("UTCTimestamp is null\n");
11067             return BAD_VALUE;
11068         }
11069 
11070         strftime(gpsDateStamp, bufLen, "%Y:%m:%d", UTCTimestamp);
11071 
11072         getRational(&gpsTimeStamp[0], UTCTimestamp->tm_hour, 1);
11073         getRational(&gpsTimeStamp[1], UTCTimestamp->tm_min, 1);
11074         getRational(&gpsTimeStamp[2], UTCTimestamp->tm_sec, 1);
11075 
11076         return NO_ERROR;
11077     } else {
11078         return BAD_VALUE;
11079     }
11080 }
11081 
11082 /*===========================================================================
11083  * FUNCTION   : updateFocusDistances
11084  *
11085  * DESCRIPTION: update focus distances
11086  *
11087  * PARAMETERS :
11088  *   @focusDistances : ptr to focus distance info
11089  *
11090  * RETURN     : int32_t type of status
11091  *              NO_ERROR  -- success
11092  *              none-zero failure code
11093  *==========================================================================*/
updateFocusDistances(cam_focus_distances_info_t * focusDistances)11094 int32_t QCameraParameters::updateFocusDistances(cam_focus_distances_info_t *focusDistances)
11095 {
11096     String8 str;
11097     char buffer[32] = {0};
11098     //set all distances to infinity if focus mode is infinity
11099     if(mFocusMode == CAM_FOCUS_MODE_INFINITY) {
11100         str.append("Infinity,Infinity,Infinity");
11101     } else {
11102         if (focusDistances->focus_distance[0] < FOCUS_PERCISION) {
11103             str.append("Infinity");
11104         } else {
11105             snprintf(buffer, sizeof(buffer), "%f", 1.0/focusDistances->focus_distance[0]);
11106             str.append(buffer);
11107         }
11108         if (focusDistances->focus_distance[1] < FOCUS_PERCISION) {
11109             str.append(",Infinity");
11110         } else {
11111             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[1]);
11112             str.append(buffer);
11113         }
11114         if (focusDistances->focus_distance[2] < FOCUS_PERCISION) {
11115             str.append(",Infinity");
11116         } else {
11117             snprintf(buffer, sizeof(buffer), ",%f", 1.0/focusDistances->focus_distance[2]);
11118             str.append(buffer);
11119         }
11120     }
11121     LOGH("setting KEY_FOCUS_DISTANCES as %s", __FUNCTION__, str.string());
11122     set(QCameraParameters::KEY_FOCUS_DISTANCES, str.string());
11123     return NO_ERROR;
11124 }
11125 
11126 /*===========================================================================
11127  * FUNCTION   : updateRecordingHintValue
11128  *
11129  * DESCRIPTION: update recording hint locally and to daemon
11130  *
11131  * PARAMETERS :
11132  *   @value   : video hint value
11133  *
11134  * RETURN     : int32_t type of status
11135  *              NO_ERROR  -- success
11136  *              none-zero failure code
11137  *==========================================================================*/
updateRecordingHintValue(int32_t value)11138 int32_t QCameraParameters::updateRecordingHintValue(int32_t value)
11139 {
11140     int32_t rc = NO_ERROR;
11141     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11142         LOGE("Failed to initialize group update table");
11143         return BAD_TYPE;
11144     }
11145 
11146     rc = setRecordingHintValue(value);
11147     if (rc != NO_ERROR) {
11148         LOGE("Failed to update table");
11149         return rc;
11150     }
11151 
11152     if(m_bDISEnabled && (value==1)) {
11153         LOGH("%d: Setting DIS value again!!");
11154         setDISValue(VALUE_ENABLE);
11155     }
11156 
11157     rc = commitSetBatch();
11158     if (rc != NO_ERROR) {
11159         LOGE("Failed to update recording hint");
11160         return rc;
11161     }
11162 
11163     return rc;
11164 }
11165 
11166 /*===========================================================================
11167  * FUNCTION   : setHistogram
11168  *
11169  * DESCRIPTION: set histogram
11170  *
11171  * PARAMETERS :
11172  *   @enabled : if histogram is enabled
11173  *
11174  * RETURN     : int32_t type of status
11175  *              NO_ERROR  -- success
11176  *              none-zero failure code
11177  *==========================================================================*/
setHistogram(bool enabled)11178 int32_t QCameraParameters::setHistogram(bool enabled)
11179 {
11180     if(m_bHistogramEnabled == enabled) {
11181         LOGH("histogram flag not changed, no ops here");
11182         return NO_ERROR;
11183     }
11184 
11185     // set parm for histogram
11186     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11187         LOGE("Failed to initialize group update table");
11188         return BAD_TYPE;
11189     }
11190 
11191     int32_t value = enabled ? 1 : 0;
11192     int32_t rc = NO_ERROR;
11193     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_HISTOGRAM, value)) {
11194         LOGE("Failed to update table");
11195         return BAD_VALUE;
11196     }
11197 
11198     rc = commitSetBatch();
11199     if (rc != NO_ERROR) {
11200         LOGE("Failed to set histogram");
11201         return rc;
11202     }
11203 
11204     m_bHistogramEnabled = enabled;
11205 
11206     LOGH("Histogram -> %s", m_bHistogramEnabled ? "Enabled" : "Disabled");
11207 
11208     return rc;
11209 }
11210 
11211 /*===========================================================================
11212  * FUNCTION   : setIntEvent
11213  *
11214  * DESCRIPTION: set setIntEvent
11215  *
11216  * PARAMETERS :
11217  *   @params : image size and dimensions
11218  *
11219  * RETURN     : int32_t type of status
11220  *              NO_ERROR  -- success
11221  *              none-zero failure code
11222  *==========================================================================*/
setIntEvent(cam_int_evt_params_t params)11223 int32_t QCameraParameters::setIntEvent(cam_int_evt_params_t params)
11224 {
11225     int32_t rc = NO_ERROR;
11226 
11227     if ( m_pParamBuf == NULL ) {
11228         return NO_INIT;
11229     }
11230 
11231     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11232         LOGE("Failed to initialize group update table");
11233         return BAD_TYPE;
11234     }
11235 
11236     //Sending snapshot taken notification back to Eztune"
11237     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INT_EVT, params)) {
11238         LOGE("Failed to update table");
11239         return BAD_VALUE;
11240     }
11241 
11242     rc = commitSetBatch();
11243     if (rc != NO_ERROR) {
11244         LOGE("Failed to set frameskip info parm");
11245         return rc;
11246     }
11247 
11248     return rc;
11249 }
11250 
11251 /*===========================================================================
11252  * FUNCTION   : setFaceDetectionOption
11253  *
11254  * DESCRIPTION: set if face detection is enabled by SendCommand
11255  *
11256  * PARAMETERS :
11257  *   @enabled : bool flag if face detection should be enabled
11258  *
11259  * RETURN     : int32_t type of status
11260  *              NO_ERROR  -- success
11261  *              none-zero failure code
11262  *==========================================================================*/
setFaceDetectionOption(bool enabled)11263  int32_t QCameraParameters::setFaceDetectionOption(bool enabled)
11264 {
11265     m_bFaceDetectionOn = enabled;
11266     return NO_ERROR;
11267 }
11268 
11269 /*===========================================================================
11270  * FUNCTION   : setFaceDetection
11271  *
11272  * DESCRIPTION: set face detection
11273  *
11274  * PARAMETERS :
11275  *   @enabled : if face detection is enabled
11276  *   @initCommit : if configuration list need to be initialized and commited
11277  *
11278  * RETURN     : int32_t type of status
11279  *              NO_ERROR  -- success
11280  *              none-zero failure code
11281  *==========================================================================*/
setFaceDetection(bool enabled,bool initCommit)11282 int32_t QCameraParameters::setFaceDetection(bool enabled, bool initCommit)
11283 {
11284     uint32_t faceProcMask = m_nFaceProcMask;
11285     // set face detection mask
11286     if (enabled) {
11287         faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11288         if (getRecordingHintValue() > 0) {
11289             faceProcMask = 0;
11290             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
11291             if (fdModeInVideo() == CAM_FACE_PROCESS_MASK_DETECTION) {
11292                 faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11293             }
11294         } else {
11295             faceProcMask |= CAM_FACE_PROCESS_MASK_FOCUS;
11296             faceProcMask |= CAM_FACE_PROCESS_MASK_DETECTION;
11297         }
11298         if (isTruePortraitEnabled()) {
11299             LOGL("QCameraParameters::setFaceDetection trueportrait enabled");
11300             faceProcMask |= CAM_FACE_PROCESS_MASK_GAZE;
11301         } else {
11302             LOGL("QCameraParameters::setFaceDetection trueportrait disabled");
11303             faceProcMask &= ~CAM_FACE_PROCESS_MASK_GAZE;
11304         }
11305     } else {
11306         faceProcMask &= ~(CAM_FACE_PROCESS_MASK_DETECTION
11307                 | CAM_FACE_PROCESS_MASK_FOCUS
11308                 | CAM_FACE_PROCESS_MASK_GAZE);
11309     }
11310 
11311     if(m_nFaceProcMask == faceProcMask) {
11312         LOGH("face process mask not changed, no ops here");
11313         return NO_ERROR;
11314     }
11315 
11316     m_nFaceProcMask = faceProcMask;
11317 
11318     // set parm for face detection
11319     uint32_t requested_faces = (uint32_t)getInt(KEY_QC_MAX_NUM_REQUESTED_FACES);
11320     cam_fd_set_parm_t fd_set_parm;
11321     memset(&fd_set_parm, 0, sizeof(cam_fd_set_parm_t));
11322     fd_set_parm.fd_mode = faceProcMask;
11323     fd_set_parm.num_fd = requested_faces;
11324 
11325     LOGH("[KPI Perf]: PROFILE_FACE_DETECTION_VALUE = %d num_fd = %d",
11326            faceProcMask,requested_faces);
11327 
11328     if (initCommit) {
11329         if(initBatchUpdate(m_pParamBuf) < 0 ) {
11330             LOGE("Failed to initialize group update table");
11331             return BAD_TYPE;
11332         }
11333     }
11334 
11335     int32_t rc = NO_ERROR;
11336 
11337     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FD, fd_set_parm)) {
11338         LOGE("Failed to update table");
11339         return BAD_VALUE;
11340     }
11341 
11342     if (initCommit) {
11343         rc = commitSetBatch();
11344         if (rc != NO_ERROR) {
11345             LOGE("Failed to set face detection parm");
11346             return rc;
11347         }
11348     }
11349 
11350     LOGH("FaceProcMask -> %d", m_nFaceProcMask);
11351 
11352     return rc;
11353 }
11354 
11355 /*===========================================================================
11356  * FUNCTION   : setFrameSkip
11357  *
11358  * DESCRIPTION: send ISP frame skip pattern to camera daemon
11359  *
11360  * PARAMETERS :
11361  *   @pattern : skip pattern for ISP
11362  *
11363  * RETURN     : int32_t type of status
11364  *              NO_ERROR  -- success
11365  *              none-zero failure code
11366  *==========================================================================*/
setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)11367 int32_t QCameraParameters::setFrameSkip(enum msm_vfe_frame_skip_pattern pattern)
11368 {
11369     int32_t rc = NO_ERROR;
11370 
11371     if ( m_pParamBuf == NULL ) {
11372         return NO_INIT;
11373     }
11374 
11375     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11376         LOGE("Failed to initialize group update table");
11377         return BAD_TYPE;
11378     }
11379 
11380     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_FRAMESKIP, (int32_t)pattern)) {
11381         LOGE("Failed to update table");
11382         return BAD_VALUE;
11383     }
11384 
11385     rc = commitSetBatch();
11386     if (rc != NO_ERROR) {
11387         LOGE("Failed to set frameskip info parm");
11388         return rc;
11389     }
11390 
11391     return rc;
11392 }
11393 
11394 /*===========================================================================
11395  * FUNCTION   : updateRAW
11396  *
11397  * DESCRIPTION: Query sensor output size based on maximum stream dimension
11398  *
11399  * PARAMETERS :
11400  *   @max_dim : maximum stream dimension
11401  *
11402  * RETURN     : int32_t type of status
11403  *              NO_ERROR  -- success
11404  *              none-zero failure code
11405  *==========================================================================*/
updateRAW(cam_dimension_t max_dim)11406 int32_t QCameraParameters::updateRAW(cam_dimension_t max_dim)
11407 {
11408     int32_t rc = NO_ERROR;
11409     cam_dimension_t raw_dim, pic_dim;
11410 
11411     // If offline raw is enabled, check the dimensions from Picture size since snapshot
11412     // stream is not added but final JPEG is required of snapshot size
11413     if (getofflineRAW()) {
11414         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT, pic_dim);
11415         if (pic_dim.width > max_dim.width) {
11416             max_dim.width = pic_dim.width;
11417         }
11418         if (pic_dim.height > max_dim.height) {
11419             max_dim.height = pic_dim.height;
11420         }
11421     }
11422 
11423     if (max_dim.width == 0 || max_dim.height == 0) {
11424         max_dim = m_pCapability->raw_dim[0];
11425     }
11426 
11427     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11428         LOGE("Failed to initialize group update table");
11429         return BAD_TYPE;
11430     }
11431 
11432     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_MAX_DIMENSION, max_dim)) {
11433         LOGE("Failed to update table for CAM_INTF_PARM_MAX_DIMENSION ");
11434         return BAD_VALUE;
11435     }
11436 
11437     rc = commitSetBatch();
11438     if (rc != NO_ERROR) {
11439         LOGE("Failed to set lock CAM_INTF_PARM_MAX_DIMENSION parm");
11440         return rc;
11441     }
11442 
11443     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11444         LOGE("Failed to initialize group update table");
11445         return BAD_TYPE;
11446     }
11447 
11448     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION);
11449 
11450     rc = commitGetBatch();
11451     if (rc != NO_ERROR) {
11452         LOGE("Failed to get commit CAM_INTF_PARM_RAW_DIMENSION");
11453         return rc;
11454     }
11455 
11456     READ_PARAM_ENTRY(m_pParamBuf, CAM_INTF_PARM_RAW_DIMENSION, raw_dim);
11457 
11458     LOGH("RAW Dimension = %d X %d",raw_dim.width,raw_dim.height);
11459     if (raw_dim.width == 0 || raw_dim.height == 0) {
11460         LOGW("Error getting RAW size. Setting to Capability value");
11461         raw_dim = m_pCapability->raw_dim[0];
11462     }
11463     setRawSize(raw_dim);
11464     return rc;
11465 }
11466 
11467 /*===========================================================================
11468  * FUNCTION   : setHDRSceneEnable
11469  *
11470  * DESCRIPTION: sets hdr scene deteced flag
11471  *
11472  * PARAMETERS :
11473  *   @bflag : hdr scene deteced
11474  *
11475  * RETURN     : nothing
11476  *==========================================================================*/
setHDRSceneEnable(bool bflag)11477 void QCameraParameters::setHDRSceneEnable(bool bflag)
11478 {
11479     bool bupdate = false;
11480     if (m_HDRSceneEnabled != bflag) {
11481         bupdate = true;
11482     }
11483     m_HDRSceneEnabled = bflag;
11484 
11485     if (bupdate) {
11486         updateFlash(true);
11487     }
11488 }
11489 
11490 /*===========================================================================
11491  * FUNCTION   : getASDStateString
11492  *
11493  * DESCRIPTION: get ASD result in string format
11494  *
11495  * PARAMETERS :
11496  *   @scene : selected scene mode
11497  *
11498  * RETURN     : int32_t type of status
11499  *              NO_ERROR  -- success
11500  *              none-zero failure code
11501  *==========================================================================*/
getASDStateString(cam_auto_scene_t scene)11502  const char *QCameraParameters::getASDStateString(cam_auto_scene_t scene)
11503 {
11504     switch (scene) {
11505       case S_NORMAL :
11506         return "Normal";
11507       case S_SCENERY:
11508         return "Scenery";
11509       case S_PORTRAIT:
11510         return "Portrait";
11511       case S_PORTRAIT_BACKLIGHT:
11512         return "Portrait-Backlight";
11513       case S_SCENERY_BACKLIGHT:
11514         return "Scenery-Backlight";
11515       case S_BACKLIGHT:
11516         return "Backlight";
11517       default:
11518         return "<Unknown!>";
11519       }
11520 }
11521 
11522 /*===========================================================================
11523  * FUNCTION   : parseNDimVector
11524  *
11525  * DESCRIPTION: helper function to parse a string like "(1, 2, 3, 4, ..., N)"
11526  *              into N-dimension vector
11527  *
11528  * PARAMETERS :
11529  *   @str     : string to be parsed
11530  *   @num     : output array of size N to store vector element values
11531  *   @N       : number of dimension
11532  *   @delim   : delimeter to seperete string
11533  *
11534  * RETURN     : int32_t type of status
11535  *              NO_ERROR  -- success
11536  *              none-zero failure code
11537  *==========================================================================*/
parseNDimVector(const char * str,int * num,int N,char delim=',')11538 int32_t QCameraParameters::parseNDimVector(const char *str, int *num, int N, char delim = ',')
11539 {
11540     char *start, *end;
11541     if (num == NULL) {
11542         LOGE("Invalid output array (num == NULL)");
11543         return BAD_VALUE;
11544     }
11545 
11546     //check if string starts and ends with parantheses
11547     if(str[0] != '(' || str[strlen(str)-1] != ')') {
11548         LOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)",
11549                str);
11550         return BAD_VALUE;
11551     }
11552     start = (char*) str;
11553     start++;
11554     for(int i=0; i<N; i++) {
11555         *(num+i) = (int) strtol(start, &end, 10);
11556         if(*end != delim && i < N-1) {
11557             LOGE("Cannot find delimeter '%c' in string \"%s\". end = %c",
11558                    delim, str, *end);
11559             return -1;
11560         }
11561         start = end+1;
11562     }
11563     return NO_ERROR;
11564 }
11565 
11566 /*===========================================================================
11567  * FUNCTION   : parseCameraAreaString
11568  *
11569  * DESCRIPTION: helper function to parse a string of camera areas like
11570  *              "(1, 2, 3, 4, 5),(1, 2, 3, 4, 5),..."
11571  *
11572  * PARAMETERS :
11573  *   @str             : string to be parsed
11574  *   @max_num_areas   : max number of areas
11575  *   @pAreas          : ptr to struct to store areas
11576  *   @num_areas_found : number of areas found
11577  *
11578  * RETURN     : int32_t type of status
11579  *              NO_ERROR  -- success
11580  *              none-zero failure code
11581  *==========================================================================*/
parseCameraAreaString(const char * str,int max_num_areas,cam_area_t * pAreas,int & num_areas_found)11582 int32_t QCameraParameters::parseCameraAreaString(const char *str,
11583                                                  int max_num_areas,
11584                                                  cam_area_t *pAreas,
11585                                                  int& num_areas_found)
11586 {
11587     char area_str[32];
11588     const char *start, *end, *p;
11589     start = str; end = NULL;
11590     int values[5], index=0;
11591     num_areas_found = 0;
11592 
11593     memset(values, 0, sizeof(values));
11594     while(start != NULL) {
11595        if(*start != '(') {
11596             LOGE("error: Ill formatted area string: %s", str);
11597             return BAD_VALUE;
11598        }
11599        end = strchr(start, ')');
11600        if(end == NULL) {
11601             LOGE("error: Ill formatted area string: %s", str);
11602             return BAD_VALUE;
11603        }
11604        int i;
11605        for (i=0,p=start; p<=end; p++, i++) {
11606            area_str[i] = *p;
11607        }
11608        area_str[i] = '\0';
11609        if(parseNDimVector(area_str, values, 5) < 0){
11610             LOGE("error: Failed to parse the area string: %s", area_str);
11611             return BAD_VALUE;
11612        }
11613        // no more areas than max_num_areas are accepted.
11614        if(index >= max_num_areas) {
11615             LOGE("error: too many areas specified %s", str);
11616             return BAD_VALUE;
11617        }
11618        pAreas[index].rect.left = values[0];
11619        pAreas[index].rect.top = values[1];
11620        pAreas[index].rect.width = values[2] - values[0];
11621        pAreas[index].rect.height = values[3] - values[1];
11622        pAreas[index].weight = values[4];
11623 
11624        index++;
11625        start = strchr(end, '('); // serach for next '('
11626     }
11627     num_areas_found = index;
11628     return 0;
11629 }
11630 
11631 /*===========================================================================
11632  * FUNCTION   : validateCameraAreas
11633  *
11634  * DESCRIPTION: helper function to validate camera areas within (-1000, 1000)
11635  *
11636  * PARAMETERS :
11637  *   @areas     : ptr to array of areas
11638  *   @num_areas : number of areas
11639  *
11640  * RETURN     : true --  area is in valid range
11641  *              false -- not valid
11642  *==========================================================================*/
validateCameraAreas(cam_area_t * areas,int num_areas)11643 bool QCameraParameters::validateCameraAreas(cam_area_t *areas, int num_areas)
11644 {
11645     // special case: default area
11646     if (num_areas == 1 &&
11647         areas[0].rect.left == 0 &&
11648         areas[0].rect.top == 0 &&
11649         areas[0].rect.width == 0 &&
11650         areas[0].rect.height == 0 &&
11651         areas[0].weight == 0) {
11652         return true;
11653     }
11654 
11655     for(int i = 0; i < num_areas; i++) {
11656         // left should be >= -1000
11657         if(areas[i].rect.left < -1000) {
11658             return false;
11659         }
11660 
11661         // top  should be >= -1000
11662         if(areas[i].rect.top < -1000) {
11663             return false;
11664         }
11665 
11666         // width or height should be > 0
11667         if (areas[i].rect.width <= 0 || areas[i].rect.height <= 0) {
11668             return false;
11669         }
11670 
11671         // right  should be <= 1000
11672         if(areas[i].rect.left + areas[i].rect.width > 1000) {
11673             return false;
11674         }
11675 
11676         // bottom should be <= 1000
11677         if(areas[i].rect.top + areas[i].rect.height > 1000) {
11678             return false;
11679         }
11680 
11681         // weight should be within (1, 1000)
11682         if (areas[i].weight < 1 || areas[i].weight > 1000) {
11683             return false;
11684         }
11685     }
11686     return true;
11687 }
11688 
11689 /*===========================================================================
11690  * FUNCTION   : isYUVFrameInfoNeeded
11691  *
11692  * DESCRIPTION: In AE-Bracket mode, we need set yuv buffer information for up-layer
11693  *
11694  * PARAMETERS : none
11695  *
11696  * RETURN     : true: needed
11697  *              false: no need
11698  *==========================================================================*/
isYUVFrameInfoNeeded()11699 bool QCameraParameters::isYUVFrameInfoNeeded()
11700 {
11701     //In AE-Bracket mode, we need set raw buffer information for up-layer
11702     if(!isNV21PictureFormat() && !isNV16PictureFormat()){
11703         return false;
11704     }
11705     const char *aecBracketStr =  get(KEY_QC_AE_BRACKET_HDR);
11706 
11707     int value = lookupAttr(BRACKETING_MODES_MAP, PARAM_MAP_SIZE(BRACKETING_MODES_MAP),
11708             aecBracketStr);
11709     LOGH("aecBracketStr=%s, value=%d.", aecBracketStr, value);
11710     return (value == CAM_EXP_BRACKETING_ON);
11711 }
11712 
11713 /*===========================================================================
11714  * FUNCTION   : getFrameFmtString
11715  *
11716  * DESCRIPTION: get string name of frame format
11717  *
11718  * PARAMETERS :
11719  *   @frame   : frame format
11720  *
11721  * RETURN     : string name of frame format
11722  *==========================================================================*/
getFrameFmtString(cam_format_t fmt)11723 const char *QCameraParameters::getFrameFmtString(cam_format_t fmt)
11724 {
11725     return lookupNameByValue(PICTURE_TYPES_MAP, PARAM_MAP_SIZE(PICTURE_TYPES_MAP), fmt);
11726 }
11727 
11728 /*===========================================================================
11729  * FUNCTION   : setDcrf
11730  *
11731  * DESCRIPTION: Enable/Disable DCRF (dual-camera-range-finding)
11732  *
11733  * RETURN     : none
11734  *==========================================================================*/
setDcrf()11735 void QCameraParameters::setDcrf()
11736 {
11737     char prop[PROPERTY_VALUE_MAX];
11738     memset(prop, 0, sizeof(prop));
11739 
11740     // Set DCRF to off by default (assuming single-camera mode)
11741     m_bDcrfEnabled = 0;
11742 
11743     // In dual-cam mode, get sysprop and set it to on by default
11744     if(m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
11745         property_get("persist.camera.dcrf.enable", prop, "1");
11746         m_bDcrfEnabled = atoi(prop);
11747     }
11748 }
11749 
11750 /*===========================================================================
11751  * FUNCTION   : setRelatedCamSyncInfo
11752  *
11753  * DESCRIPTION: set the related cam info parameters
11754  * the related cam info is cached into params to make some decisions beforehand
11755  *
11756  * PARAMETERS :
11757  *   @info  : ptr to related cam info parameters
11758  *
11759  * RETURN     : int32_t type of status
11760  *              NO_ERROR  -- success
11761  *              none-zero failure code
11762  *==========================================================================*/
setRelatedCamSyncInfo(cam_sync_related_sensors_event_info_t * info)11763 int32_t QCameraParameters::setRelatedCamSyncInfo(
11764         cam_sync_related_sensors_event_info_t* info)
11765 {
11766     if(info != NULL){
11767         memcpy(&m_relCamSyncInfo, info,
11768                 sizeof(cam_sync_related_sensors_event_info_t));
11769         return NO_ERROR;
11770     } else {
11771         LOGE("info buffer is null");
11772         return UNKNOWN_ERROR;
11773     }
11774 }
11775 
11776 /*===========================================================================
11777  * FUNCTION   : getRelatedCamSyncInfo
11778  *
11779  * DESCRIPTION:returns the related cam sync info for this HWI instance
11780  *
11781  * PARAMETERS :none
11782  *
11783  * RETURN     : const pointer to cam_sync_related_sensors_event_info_t
11784  *==========================================================================*/
11785 const cam_sync_related_sensors_event_info_t*
getRelatedCamSyncInfo(void)11786         QCameraParameters::getRelatedCamSyncInfo(void)
11787 {
11788     return &m_relCamSyncInfo;
11789 }
11790 
11791 /*===========================================================================
11792  * FUNCTION   : bundleRelatedCameras
11793  *
11794  * DESCRIPTION: send trigger for bundling related camera sessions in the server
11795  *
11796  * PARAMETERS :
11797  *   @sync        :indicates whether syncing is On or Off
11798  *   @sessionid  :session id for other camera session
11799  *
11800  * RETURN     : int32_t type of status
11801  *              NO_ERROR  -- success
11802  *              none-zero failure code
11803  *==========================================================================*/
bundleRelatedCameras(bool sync,uint32_t sessionid)11804 int32_t QCameraParameters::bundleRelatedCameras(bool sync,
11805         uint32_t sessionid)
11806 {
11807     int32_t rc = NO_ERROR;
11808 
11809     if (NULL == m_pCamOpsTbl) {
11810         LOGE("Ops not initialized");
11811         return NO_INIT;
11812     }
11813 
11814     LOGD("Sending Bundling cmd sync %d, SessionId %d ",
11815             sync, sessionid);
11816 
11817     if(m_pRelCamSyncBuf) {
11818         if(sync) {
11819             m_pRelCamSyncBuf->sync_control = CAM_SYNC_RELATED_SENSORS_ON;
11820         }
11821         else {
11822             m_pRelCamSyncBuf->sync_control = CAM_SYNC_RELATED_SENSORS_OFF;
11823         }
11824         m_pRelCamSyncBuf->mode = m_relCamSyncInfo.mode;
11825         m_pRelCamSyncBuf->type = m_relCamSyncInfo.type;
11826         m_pRelCamSyncBuf->related_sensor_session_id = sessionid;
11827         rc = m_pCamOpsTbl->ops->sync_related_sensors(
11828                 m_pCamOpsTbl->camera_handle, m_pRelCamSyncBuf);
11829     } else {
11830         LOGE("Related Cam SyncBuffer not allocated", rc);
11831         return NO_INIT;
11832     }
11833 
11834     return rc;
11835 }
11836 
11837 /*===========================================================================
11838  * FUNCTION   : getRelatedCamCalibration
11839  *
11840  * DESCRIPTION: fetch the related camera subsystem calibration data
11841  *
11842  * PARAMETERS :
11843  *   @calib  : calibration data fetched
11844  *
11845  * RETURN     : int32_t type of status
11846  *              NO_ERROR  -- success
11847  *              none-zero failure code
11848  *==========================================================================*/
getRelatedCamCalibration(cam_related_system_calibration_data_t * calib)11849 int32_t QCameraParameters::getRelatedCamCalibration(
11850         cam_related_system_calibration_data_t* calib)
11851 {
11852     int32_t rc = NO_ERROR;
11853 
11854     if(!calib) {
11855         return BAD_TYPE;
11856     }
11857 
11858     if(initBatchUpdate(m_pParamBuf) < 0 ) {
11859         LOGE("Failed to initialize group update table");
11860         return BAD_TYPE;
11861     }
11862 
11863     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
11864             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION);
11865 
11866     rc = commitGetBatch();
11867     if (rc != NO_ERROR) {
11868         LOGE("Failed to get related cam calibration info");
11869         return rc;
11870     }
11871 
11872     READ_PARAM_ENTRY(m_pParamBuf,
11873             CAM_INTF_PARM_RELATED_SENSORS_CALIBRATION, *calib);
11874 
11875     LOGD("CALIB version %d ", calib->calibration_format_version);
11876     LOGD("CALIB normalized_focal_length %f ",
11877             calib->main_cam_specific_calibration.normalized_focal_length);
11878     LOGD("CALIB native_sensor_resolution_width %d ",
11879             calib->main_cam_specific_calibration.native_sensor_resolution_width);
11880     LOGD("CALIB native_sensor_resolution_height %d ",
11881             calib->main_cam_specific_calibration.native_sensor_resolution_height);
11882     LOGD("CALIB sensor_resolution_width %d ",
11883             calib->main_cam_specific_calibration.calibration_sensor_resolution_width);
11884     LOGD("CALIB sensor_resolution_height %d ",
11885             calib->main_cam_specific_calibration.calibration_sensor_resolution_height);
11886     LOGD("CALIB focal_length_ratio %f ",
11887             calib->main_cam_specific_calibration.focal_length_ratio);
11888 
11889     return rc;
11890 }
11891 
11892 /*===========================================================================
11893  * FUNCTION   : initBatchUpdate
11894  *
11895  * DESCRIPTION: init camera parameters buf entries
11896  *
11897  * PARAMETERS :
11898  *   @p_table : ptr to parameter buffer
11899  *
11900  * RETURN     : int32_t type of status
11901  *              NO_ERROR  -- success
11902  *              none-zero failure code
11903  *==========================================================================*/
initBatchUpdate(parm_buffer_t * p_table)11904 int32_t QCameraParameters::initBatchUpdate(parm_buffer_t *p_table)
11905 {
11906     m_tempMap.clear();
11907 
11908     clear_metadata_buffer(p_table);
11909     return NO_ERROR;
11910 }
11911 
11912 /*===========================================================================
11913  * FUNCTION   : commitSetBatch
11914  *
11915  * DESCRIPTION: commit all set parameters in the batch work to backend
11916  *
11917  * PARAMETERS : none
11918  *
11919  * RETURN     : int32_t type of status
11920  *              NO_ERROR  -- success
11921  *              none-zero failure code
11922  *==========================================================================*/
commitSetBatch()11923 int32_t QCameraParameters::commitSetBatch()
11924 {
11925     int32_t rc = NO_ERROR;
11926     int32_t i = 0;
11927 
11928     if (NULL == m_pParamBuf) {
11929         LOGE("Params not initialized");
11930         return NO_INIT;
11931     }
11932 
11933     /* Loop to check if atleast one entry is valid */
11934     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
11935         if(m_pParamBuf->is_valid[i])
11936             break;
11937     }
11938 
11939     if (NULL == m_pCamOpsTbl) {
11940         LOGE("Ops not initialized");
11941         return NO_INIT;
11942     }
11943 
11944     if (i < CAM_INTF_PARM_MAX) {
11945         rc = m_pCamOpsTbl->ops->set_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
11946     }
11947     if (rc == NO_ERROR) {
11948         // commit change from temp storage into param map
11949         rc = commitParamChanges();
11950     }
11951     return rc;
11952 }
11953 
11954 /*===========================================================================
11955  * FUNCTION   : commitGetBatch
11956  *
11957  * DESCRIPTION: commit all get parameters in the batch work to backend
11958  *
11959  * PARAMETERS : none
11960  *
11961  * RETURN     : int32_t type of status
11962  *              NO_ERROR  -- success
11963  *              none-zero failure code
11964  *==========================================================================*/
commitGetBatch()11965 int32_t QCameraParameters::commitGetBatch()
11966 {
11967     int32_t rc = NO_ERROR;
11968     int32_t i = 0;
11969 
11970     if (NULL == m_pParamBuf) {
11971         LOGE("Params not initialized");
11972         return NO_INIT;
11973     }
11974 
11975     /* Loop to check if atleast one entry is valid */
11976     for(i = 0; i < CAM_INTF_PARM_MAX; i++){
11977         if(m_pParamBuf->is_valid[i])
11978             break;
11979     }
11980 
11981     if (NULL == m_pCamOpsTbl) {
11982         LOGE("Ops not initialized");
11983         return NO_INIT;
11984     }
11985 
11986     if (i < CAM_INTF_PARM_MAX) {
11987         return m_pCamOpsTbl->ops->get_parms(m_pCamOpsTbl->camera_handle, m_pParamBuf);
11988     } else {
11989         return NO_ERROR;
11990     }
11991     return rc;
11992 }
11993 
11994 /*===========================================================================
11995  * FUNCTION   : updateParamEntry
11996  *
11997  * DESCRIPTION: update a parameter entry in the local temp map obj
11998  *
11999  * PARAMETERS :
12000  *   @key     : key of the entry
12001  *   @value   : value of the entry
12002  *
12003  * RETURN     : int32_t type of status
12004  *              NO_ERROR  -- success
12005  *              none-zero failure code
12006  *==========================================================================*/
updateParamEntry(const char * key,const char * value)12007 int32_t QCameraParameters::updateParamEntry(const char *key, const char *value)
12008 {
12009     m_tempMap.replaceValueFor(String8(key), String8(value));
12010     return NO_ERROR;
12011 }
12012 
12013 /*===========================================================================
12014  * FUNCTION   : commitParamChanges
12015  *
12016  * DESCRIPTION: commit all changes in local temp map obj into parameter obj
12017  *
12018  * PARAMETERS : none
12019  *
12020  * RETURN     : int32_t type of status
12021  *              NO_ERROR  -- success
12022  *              none-zero failure code
12023  *==========================================================================*/
commitParamChanges()12024 int32_t QCameraParameters::commitParamChanges()
12025 {
12026     size_t size = m_tempMap.size();
12027     for (size_t i = 0; i < size; i++) {
12028         String8 k, v;
12029         k = m_tempMap.keyAt(i);
12030         v = m_tempMap.valueAt(i);
12031         set(k, v);
12032     }
12033     m_tempMap.clear();
12034 
12035     // update local changes
12036     m_bRecordingHint = m_bRecordingHint_new;
12037     m_bZslMode = m_bZslMode_new;
12038 
12039     /* After applying scene mode auto,
12040       Camera effects need to be reapplied */
12041     if ( m_bSceneTransitionAuto ) {
12042         m_bUpdateEffects = true;
12043         m_bSceneTransitionAuto = false;
12044     }
12045 
12046 
12047     return NO_ERROR;
12048 }
12049 
12050 /*===========================================================================
12051  * FUNCTION   : QCameraReprocScaleParam
12052  *
12053  * DESCRIPTION: constructor of QCameraReprocScaleParam
12054  *
12055  * PARAMETERS : none
12056  *
12057  * RETURN     : none
12058  *==========================================================================*/
QCameraReprocScaleParam()12059 QCameraParameters::QCameraReprocScaleParam::QCameraReprocScaleParam()
12060   : mScaleEnabled(false),
12061     mIsUnderScaling(false),
12062     mNeedScaleCnt(0),
12063     mSensorSizeTblCnt(0),
12064     mSensorSizeTbl(NULL),
12065     mTotalSizeTblCnt(0)
12066 {
12067     mPicSizeFromAPK.width = 0;
12068     mPicSizeFromAPK.height = 0;
12069     mPicSizeSetted.width = 0;
12070     mPicSizeSetted.height = 0;
12071     memset(mNeedScaledSizeTbl, 0, sizeof(mNeedScaledSizeTbl));
12072     memset(mTotalSizeTbl, 0, sizeof(mTotalSizeTbl));
12073 }
12074 
12075 /*===========================================================================
12076  * FUNCTION   : ~~QCameraReprocScaleParam
12077  *
12078  * DESCRIPTION: destructor of QCameraReprocScaleParam
12079  *
12080  * PARAMETERS : none
12081  *
12082  * RETURN     : none
12083  *==========================================================================*/
~QCameraReprocScaleParam()12084 QCameraParameters::QCameraReprocScaleParam::~QCameraReprocScaleParam()
12085 {
12086     //do nothing now.
12087 }
12088 
12089 /*===========================================================================
12090  * FUNCTION   : setScaledSizeTbl
12091  *
12092  * DESCRIPTION: re-set picture size table with dimensions that need scaling if Reproc Scale is enabled
12093  *
12094  * PARAMETERS :
12095  *   @scale_cnt   : count of picture sizes that want scale
12096  *   @scale_tbl    : picture size table that want scale
12097  *   @org_cnt     : sensor supported picture size count
12098  *   @org_tbl      : sensor supported picture size table
12099  *
12100  * RETURN     : int32_t type of status
12101  *              NO_ERROR  -- success
12102  *              none-zero failure code
12103  *==========================================================================*/
setScaleSizeTbl(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)12104 int32_t QCameraParameters::QCameraReprocScaleParam::setScaleSizeTbl(size_t scale_cnt,
12105         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
12106 {
12107     int32_t rc = NO_ERROR;
12108     size_t i;
12109     mNeedScaleCnt = 0;
12110 
12111     if(!mScaleEnabled || scale_cnt <=0 || scale_tbl == NULL || org_cnt <=0 || org_tbl == NULL){
12112         return BAD_VALUE;    // Do not need scale, so also need not reset picture size table
12113     }
12114 
12115     mSensorSizeTblCnt = org_cnt;
12116     mSensorSizeTbl = org_tbl;
12117     mNeedScaleCnt = checkScaleSizeTable(scale_cnt, scale_tbl, org_cnt, org_tbl);
12118     if(mNeedScaleCnt <= 0){
12119         LOGE("do not have picture sizes need scaling.");
12120         return BAD_VALUE;
12121     }
12122 
12123     if(mNeedScaleCnt + org_cnt > MAX_SIZES_CNT){
12124         LOGE("picture size list exceed the max count.");
12125         return BAD_VALUE;
12126     }
12127 
12128     //get the total picture size table
12129     mTotalSizeTblCnt = mNeedScaleCnt + org_cnt;
12130 
12131     if (mNeedScaleCnt > MAX_SCALE_SIZES_CNT) {
12132         LOGE("Error!! mNeedScaleCnt (%d) is more than MAX_SCALE_SIZES_CNT",
12133                  mNeedScaleCnt);
12134         return BAD_VALUE;
12135     }
12136 
12137     for(i = 0; i < mNeedScaleCnt; i++){
12138         mTotalSizeTbl[i].width = mNeedScaledSizeTbl[i].width;
12139         mTotalSizeTbl[i].height = mNeedScaledSizeTbl[i].height;
12140         LOGH("scale picture size: i =%d, width=%d, height=%d.",
12141             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
12142     }
12143     for(; i < mTotalSizeTblCnt; i++){
12144         mTotalSizeTbl[i].width = org_tbl[i-mNeedScaleCnt].width;
12145         mTotalSizeTbl[i].height = org_tbl[i-mNeedScaleCnt].height;
12146         LOGH("sensor supportted picture size: i =%d, width=%d, height=%d.",
12147             i, mTotalSizeTbl[i].width, mTotalSizeTbl[i].height);
12148     }
12149     return rc;
12150 }
12151 
12152 /*===========================================================================
12153  * FUNCTION   : getScaledSizeTblCnt
12154  *
12155  * DESCRIPTION: get picture size cnt that need scale
12156  *
12157  * PARAMETERS : none
12158  *
12159  * RETURN     : uint8_t type of picture size count
12160  *==========================================================================*/
getScaleSizeTblCnt()12161 size_t QCameraParameters::QCameraReprocScaleParam::getScaleSizeTblCnt()
12162 {
12163     return mNeedScaleCnt;
12164 }
12165 
12166 /*===========================================================================
12167  * FUNCTION   : getScaledSizeTbl
12168  *
12169  * DESCRIPTION: get picture size table that need scale
12170  *
12171  * PARAMETERS :  none
12172  *
12173  * RETURN     : cam_dimension_t list of picture size table
12174  *==========================================================================*/
getScaledSizeTbl()12175 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getScaledSizeTbl()
12176 {
12177     if(!mScaleEnabled)
12178         return NULL;
12179 
12180     return mNeedScaledSizeTbl;
12181 }
12182 
12183 /*===========================================================================
12184  * FUNCTION   : setScaleEnable
12185  *
12186  * DESCRIPTION: enable or disable Reproc Scale
12187  *
12188  * PARAMETERS :
12189  *   @enabled : enable: 1; disable 0
12190  *
12191  * RETURN     : none
12192  *==========================================================================*/
setScaleEnable(bool enabled)12193 void QCameraParameters::QCameraReprocScaleParam::setScaleEnable(bool enabled)
12194 {
12195     mScaleEnabled = enabled;
12196 }
12197 
12198 /*===========================================================================
12199  * FUNCTION   : isScaleEnabled
12200  *
12201  * DESCRIPTION: check if Reproc Scale is enabled
12202  *
12203  * PARAMETERS :  none
12204  *
12205  * RETURN     : bool type of status
12206  *==========================================================================*/
isScaleEnabled()12207 bool QCameraParameters::QCameraReprocScaleParam::isScaleEnabled()
12208 {
12209     return mScaleEnabled;
12210 }
12211 
12212 /*===========================================================================
12213  * FUNCTION   : isScalePicSize
12214  *
12215  * DESCRIPTION: check if current picture size is from Scale Table
12216  *
12217  * PARAMETERS :
12218  *   @width     : current picture width
12219  *   @height    : current picture height
12220  *
12221  * RETURN     : bool type of status
12222  *==========================================================================*/
isScalePicSize(int width,int height)12223 bool QCameraParameters::QCameraReprocScaleParam::isScalePicSize(int width, int height)
12224 {
12225     //Check if the picture size is in scale table
12226     if(mNeedScaleCnt <= 0)
12227         return FALSE;
12228 
12229     for (size_t i = 0; i < mNeedScaleCnt; i++) {
12230         if ((mNeedScaledSizeTbl[i].width == width) && (mNeedScaledSizeTbl[i].height == height)) {
12231             //found match
12232             return TRUE;
12233         }
12234     }
12235 
12236     LOGE("Not in scale picture size table.");
12237     return FALSE;
12238 }
12239 
12240 /*===========================================================================
12241  * FUNCTION   : isValidatePicSize
12242  *
12243  * DESCRIPTION: check if current picture size is validate
12244  *
12245  * PARAMETERS :
12246  *   @width     : current picture width
12247  *   @height    : current picture height
12248  *
12249  * RETURN     : bool type of status
12250  *==========================================================================*/
isValidatePicSize(int width,int height)12251 bool QCameraParameters::QCameraReprocScaleParam::isValidatePicSize(int width, int height)
12252 {
12253     size_t i = 0;
12254 
12255     for(i = 0; i < mSensorSizeTblCnt; i++){
12256         if(mSensorSizeTbl[i].width == width
12257             && mSensorSizeTbl[i].height== height){
12258             return TRUE;
12259         }
12260     }
12261 
12262     for(i = 0; i < mNeedScaleCnt; i++){
12263         if(mNeedScaledSizeTbl[i].width == width
12264             && mNeedScaledSizeTbl[i].height== height){
12265             return TRUE;
12266         }
12267     }
12268 
12269     LOGE("Invalidate input picture size.");
12270     return FALSE;
12271 }
12272 
12273 /*===========================================================================
12274  * FUNCTION   : setSensorSupportedPicSize
12275  *
12276  * DESCRIPTION: set sensor supported picture size.
12277  *    For Snapshot stream size configuration, we need use sensor supported size.
12278  *    We will use CPP to do Scaling based on output Snapshot stream.
12279  *
12280  * PARAMETERS : none
12281  *
12282  * RETURN     : int32_t type of status
12283  *              NO_ERROR  -- success
12284  *              none-zero failure code
12285  *==========================================================================*/
setSensorSupportedPicSize()12286 int32_t QCameraParameters::QCameraReprocScaleParam::setSensorSupportedPicSize()
12287 {
12288     //will find a suitable picture size (here we leave a prossibility to add other scale requirement)
12289     //Currently we only focus on upscaling, and checkScaleSizeTable() has guaranteed the dimension ratio.
12290 
12291     if(!mIsUnderScaling || mSensorSizeTblCnt <= 0)
12292         return BAD_VALUE;
12293 
12294     //We just get the max sensor supported size here.
12295     mPicSizeSetted.width = mSensorSizeTbl[0].width;
12296     mPicSizeSetted.height = mSensorSizeTbl[0].height;
12297 
12298     return NO_ERROR;
12299 }
12300 
12301 
12302 /*===========================================================================
12303  * FUNCTION   : setValidatePicSize
12304  *
12305  * DESCRIPTION: set sensor supported size and change scale status.
12306  *
12307  * PARAMETERS :
12308  *   @width    : input picture width
12309  *   @height   : input picture height
12310  *
12311  * RETURN     : int32_t type of status
12312  *              NO_ERROR  -- success
12313  *              none-zero failure code
12314  *==========================================================================*/
setValidatePicSize(int & width,int & height)12315 int32_t QCameraParameters::QCameraReprocScaleParam::setValidatePicSize(int &width,int &height)
12316 {
12317     if(!mScaleEnabled)
12318         return BAD_VALUE;
12319 
12320     mIsUnderScaling = FALSE; //default: not under scale
12321 
12322     if(isScalePicSize(width, height)){
12323         // input picture size need scaling operation. Record size from APK and setted
12324         mIsUnderScaling = TRUE;
12325         mPicSizeFromAPK.width = width;
12326         mPicSizeFromAPK.height = height;
12327 
12328         if(setSensorSupportedPicSize() != NO_ERROR)
12329             return BAD_VALUE;
12330 
12331         //re-set picture size to sensor supported size
12332         width = mPicSizeSetted.width;
12333         height = mPicSizeSetted.height;
12334         LOGH("mPicSizeFromAPK- with=%d, height=%d, mPicSizeSetted- with =%d, height=%d.",
12335              mPicSizeFromAPK.width, mPicSizeFromAPK.height, mPicSizeSetted.width, mPicSizeSetted.height);
12336     }else{
12337         mIsUnderScaling = FALSE;
12338         //no scale is needed for input picture size
12339         if(!isValidatePicSize(width, height)){
12340             LOGE("invalidate input picture size.");
12341             return BAD_VALUE;
12342         }
12343         mPicSizeSetted.width = width;
12344         mPicSizeSetted.height = height;
12345     }
12346 
12347     LOGH("X. mIsUnderScaling=%d, width=%d, height=%d.", mIsUnderScaling, width, height);
12348     return NO_ERROR;
12349 }
12350 
12351 /*===========================================================================
12352  * FUNCTION   : getPicSizeFromAPK
12353  *
12354  * DESCRIPTION: get picture size that get from APK
12355  *
12356  * PARAMETERS :
12357  *   @width     : input width
12358  *   @height    : input height
12359  *
12360  * RETURN     : int32_t type of status
12361  *              NO_ERROR  -- success
12362  *              none-zero failure code
12363  *==========================================================================*/
getPicSizeFromAPK(int & width,int & height)12364 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeFromAPK(int &width, int &height)
12365 {
12366     if(!mIsUnderScaling)
12367         return BAD_VALUE;
12368 
12369     width = mPicSizeFromAPK.width;
12370     height = mPicSizeFromAPK.height;
12371     return NO_ERROR;
12372 }
12373 
12374 /*===========================================================================
12375  * FUNCTION   : getPicSizeSetted
12376  *
12377  * DESCRIPTION: get picture size that setted into mm-camera
12378  *
12379  * PARAMETERS :
12380  *   @width     : input width
12381  *   @height    : input height
12382  *
12383  * RETURN     : int32_t type of status
12384  *              NO_ERROR  -- success
12385  *              none-zero failure code
12386  *==========================================================================*/
getPicSizeSetted(int & width,int & height)12387 int32_t QCameraParameters::QCameraReprocScaleParam::getPicSizeSetted(int &width, int &height)
12388 {
12389     width = mPicSizeSetted.width;
12390     height = mPicSizeSetted.height;
12391     return NO_ERROR;
12392 }
12393 
12394 /*===========================================================================
12395  * FUNCTION   : isUnderScaling
12396  *
12397  * DESCRIPTION: check if we are in Reproc Scaling requirment
12398  *
12399  * PARAMETERS :  none
12400  *
12401  * RETURN     : bool type of status
12402  *==========================================================================*/
isUnderScaling()12403 bool QCameraParameters::QCameraReprocScaleParam::isUnderScaling()
12404 {
12405     return mIsUnderScaling;
12406 }
12407 
12408 /*===========================================================================
12409  * FUNCTION   : checkScaleSizeTable
12410  *
12411  * DESCRIPTION: check PICTURE_SIZE_NEED_SCALE to choose
12412  *
12413  * PARAMETERS :
12414  *   @scale_cnt   : count of picture sizes that want scale
12415  *   @scale_tbl    : picture size table that want scale
12416  *   @org_cnt     : sensor supported picture size count
12417  *   @org_tbl      : sensor supported picture size table
12418  *
12419  * RETURN     : bool type of status
12420  *==========================================================================*/
checkScaleSizeTable(size_t scale_cnt,cam_dimension_t * scale_tbl,size_t org_cnt,cam_dimension_t * org_tbl)12421 size_t QCameraParameters::QCameraReprocScaleParam::checkScaleSizeTable(size_t scale_cnt,
12422         cam_dimension_t *scale_tbl, size_t org_cnt, cam_dimension_t *org_tbl)
12423 {
12424     size_t stbl_cnt = 0;
12425     size_t temp_cnt = 0;
12426     ssize_t i = 0;
12427     if(scale_cnt <=0 || scale_tbl == NULL || org_tbl == NULL || org_cnt <= 0)
12428         return stbl_cnt;
12429 
12430     //get validate scale size table. Currently we only support:
12431     // 1. upscale. The scale size must larger than max sensor supported size
12432     // 2. Scale dimension ratio must be same as the max sensor supported size.
12433     temp_cnt = scale_cnt;
12434     for (i = (ssize_t)(scale_cnt - 1); i >= 0; i--) {
12435         if (scale_tbl[i].width > org_tbl[0].width ||
12436                 (scale_tbl[i].width == org_tbl[0].width &&
12437                     scale_tbl[i].height > org_tbl[0].height)) {
12438             //get the smallest scale size
12439             break;
12440         }
12441         temp_cnt--;
12442     }
12443 
12444     //check dimension ratio
12445     double supported_ratio = (double)org_tbl[0].width / (double)org_tbl[0].height;
12446     for (i = 0; i < (ssize_t)temp_cnt; i++) {
12447         double cur_ratio = (double)scale_tbl[i].width / (double)scale_tbl[i].height;
12448         if (fabs(supported_ratio - cur_ratio) > ASPECT_TOLERANCE) {
12449             continue;
12450         }
12451         mNeedScaledSizeTbl[stbl_cnt].width = scale_tbl[i].width;
12452         mNeedScaledSizeTbl[stbl_cnt].height= scale_tbl[i].height;
12453         stbl_cnt++;
12454     }
12455 
12456     return stbl_cnt;
12457 }
12458 
12459 /*===========================================================================
12460  * FUNCTION   : getTotalSizeTblCnt
12461  *
12462  * DESCRIPTION: get total picture size count after adding dimensions that need scaling
12463  *
12464  * PARAMETERS : none
12465  *
12466  * RETURN     : uint8_t type of picture size count
12467  *==========================================================================*/
getTotalSizeTblCnt()12468 size_t QCameraParameters::QCameraReprocScaleParam::getTotalSizeTblCnt()
12469 {
12470     return mTotalSizeTblCnt;
12471 }
12472 
12473 /*===========================================================================
12474  * FUNCTION   : getTotalSizeTbl
12475  *
12476  * DESCRIPTION: get picture size table after adding dimensions that need scaling
12477  *
12478  * PARAMETERS :  none
12479  *
12480  * RETURN     : cam_dimension_t list of picture size table
12481  *==========================================================================*/
getTotalSizeTbl()12482 cam_dimension_t *QCameraParameters::QCameraReprocScaleParam::getTotalSizeTbl()
12483 {
12484     if(!mScaleEnabled)
12485         return NULL;
12486 
12487     return mTotalSizeTbl;
12488 }
12489 
12490 /*===========================================================================
12491  * FUNCTION   : setEztune
12492  *
12493  * DESCRIPTION: Enable/Disable EZtune
12494  *
12495  *==========================================================================*/
setEztune()12496 int32_t QCameraParameters::setEztune()
12497 {
12498     char prop[PROPERTY_VALUE_MAX];
12499     memset(prop, 0, sizeof(prop));
12500     property_get("persist.camera.eztune.enable", prop, "0");
12501     m_bEztuneEnabled = atoi(prop);
12502     return NO_ERROR;
12503 }
12504 
12505 /*===========================================================================
12506  * FUNCTION   : isHDREnabled
12507  *
12508  * DESCRIPTION: if HDR is enabled
12509  *
12510  * PARAMETERS : none
12511  *
12512  * RETURN     : true: needed
12513  *              false: no need
12514  *==========================================================================*/
isHDREnabled()12515 bool QCameraParameters::isHDREnabled()
12516 {
12517     return ((m_bHDREnabled || m_HDRSceneEnabled));
12518 }
12519 
12520 /*===========================================================================
12521  * FUNCTION   : isAVTimerEnabled
12522  *
12523  * DESCRIPTION: if AVTimer is enabled
12524  *
12525  * PARAMETERS : none
12526  *
12527  * RETURN     : true: needed
12528  *              false: no need
12529  *==========================================================================*/
isAVTimerEnabled()12530 bool QCameraParameters::isAVTimerEnabled()
12531 {
12532     return m_bAVTimerEnabled;
12533 }
12534 
12535 /*===========================================================================
12536 * FUNCTION   : isDISEnabled
12537 *
12538 * DESCRIPTION: if DIS is enabled
12539 *
12540 * PARAMETERS : none
12541 *
12542 * RETURN    : true: needed
12543 *               false: no need
12544 *==========================================================================*/
isDISEnabled()12545 bool QCameraParameters::isDISEnabled()
12546 {
12547     return m_bDISEnabled;
12548 }
12549 
12550 /*===========================================================================
12551 * FUNCTION   : getISType
12552 *
12553 * DESCRIPTION: returns IS type
12554 *
12555 * PARAMETERS : none
12556 *
12557 * RETURN     : IS type
12558 *
12559 *==========================================================================*/
getISType()12560 cam_is_type_t QCameraParameters::getISType()
12561 {
12562     return mIsType;
12563 }
12564 
12565 /*===========================================================================
12566  * FUNCTION   : MobicatMask
12567  *
12568  * DESCRIPTION: returns mobicat mask
12569  *
12570  * PARAMETERS : none
12571  *
12572  * RETURN     : mobicat mask
12573  *
12574  *==========================================================================*/
getMobicatMask()12575 uint8_t QCameraParameters::getMobicatMask()
12576 {
12577     return m_MobiMask;
12578 }
12579 
12580 /*===========================================================================
12581  * FUNCTION   : sendStreamConfigInfo
12582  *
12583  * DESCRIPTION: send Stream config info.
12584  *
12585  * PARAMETERS :
12586  *   @stream_config_info: Stream config information
12587  *
12588  * RETURN     : int32_t type of status
12589  *              NO_ERROR  -- success
12590  *              none-zero failure code
12591  *==========================================================================*/
sendStreamConfigInfo(cam_stream_size_info_t & stream_config_info)12592 bool QCameraParameters::sendStreamConfigInfo(cam_stream_size_info_t &stream_config_info) {
12593     int32_t rc = NO_ERROR;
12594     if(initBatchUpdate(m_pParamBuf) < 0 ) {
12595         LOGE("Failed to initialize group update table");
12596         return BAD_TYPE;
12597     }
12598 
12599     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
12600             CAM_INTF_META_STREAM_INFO, stream_config_info)) {
12601         LOGE("Failed to update table");
12602         return BAD_VALUE;
12603     }
12604 
12605     rc = commitSetBatch();
12606     if (rc != NO_ERROR) {
12607         LOGE("Failed to set stream info parm");
12608         return rc;
12609     }
12610 
12611     return rc;
12612 }
12613 
12614 /*===========================================================================
12615  * FUNCTION   : setStreamConfigure
12616  *
12617  * DESCRIPTION: set stream type, stream dimension for all configured streams.
12618  *
12619  * PARAMETERS :
12620  *   @isCapture: Whether this configureation is for an image capture
12621  *   @previewAsPostview: Use preview as postview
12622  *
12623  * RETURN     : int32_t type of status
12624  *              NO_ERROR  -- success
12625  *              none-zero failure code
12626  *==========================================================================*/
setStreamConfigure(bool isCapture,bool previewAsPostview,bool resetConfig)12627 bool QCameraParameters::setStreamConfigure(bool isCapture,
12628         bool previewAsPostview, bool resetConfig) {
12629 
12630     int32_t rc = NO_ERROR;
12631     cam_stream_size_info_t stream_config_info;
12632     char value[PROPERTY_VALUE_MAX];
12633     bool raw_yuv = false;
12634     bool raw_capture = false;
12635 
12636     if ( m_pParamBuf == NULL ) {
12637         return NO_INIT;
12638     }
12639 
12640     memset(&stream_config_info, 0, sizeof(stream_config_info));
12641     stream_config_info.num_streams = 0;
12642 
12643     if (m_bStreamsConfigured) {
12644         LOGH("Reset stream config!!");
12645         rc = sendStreamConfigInfo(stream_config_info);
12646         m_bStreamsConfigured = false;
12647     }
12648     if (resetConfig) {
12649         LOGH("Done Resetting stream config!!");
12650         return rc;
12651     }
12652 
12653     stream_config_info.hfr_mode       = static_cast<cam_hfr_mode_t>(mHfrMode);
12654     stream_config_info.buf_alignment  = m_pCapability->buf_alignment;
12655     stream_config_info.min_stride     = m_pCapability->min_stride;
12656     stream_config_info.min_scanline   = m_pCapability->min_scanline;
12657     stream_config_info.batch_size = getBufBatchCount();
12658     LOGH("buf_alignment=%d stride X scan=%dx%d batch size = %d\n",
12659             m_pCapability->buf_alignment,
12660             m_pCapability->min_stride,
12661             m_pCapability->min_scanline,
12662             stream_config_info.batch_size);
12663 
12664 
12665     property_get("persist.camera.raw_yuv", value, "0");
12666     raw_yuv = atoi(value) > 0 ? true : false;
12667 
12668     if (isZSLMode() && getRecordingHintValue() != true) {
12669         stream_config_info.type[stream_config_info.num_streams] =
12670             CAM_STREAM_TYPE_PREVIEW;
12671         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
12672                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
12673         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
12674         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12675                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
12676         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
12677                 stream_config_info.format[stream_config_info.num_streams]);
12678         stream_config_info.num_streams++;
12679 
12680         stream_config_info.type[stream_config_info.num_streams] =
12681                 CAM_STREAM_TYPE_ANALYSIS;
12682         getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
12683                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
12684         updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
12685         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12686                 mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
12687         getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
12688                 stream_config_info.format[stream_config_info.num_streams]);
12689         stream_config_info.num_streams++;
12690 
12691         stream_config_info.type[stream_config_info.num_streams] =
12692                 CAM_STREAM_TYPE_SNAPSHOT;
12693         getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
12694                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
12695         updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
12696         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12697                 mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
12698         getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
12699                 stream_config_info.format[stream_config_info.num_streams]);
12700         stream_config_info.num_streams++;
12701 
12702         if (isUBWCEnabled() && getRecordingHintValue() != true) {
12703             cam_format_t fmt;
12704             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
12705             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
12706                 stream_config_info.type[stream_config_info.num_streams] =
12707                         CAM_STREAM_TYPE_CALLBACK;
12708                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
12709                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
12710                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
12711                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12712                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
12713                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
12714                         stream_config_info.format[stream_config_info.num_streams]);
12715                 stream_config_info.num_streams++;
12716             }
12717         }
12718 
12719     } else if (!isCapture) {
12720         if (m_bRecordingHint) {
12721             if (m_bDISEnabled) {
12722                 char value[PROPERTY_VALUE_MAX];
12723                 // Make default value for IS_TYPE as IS_TYPE_EIS_2_0
12724                 property_get("persist.camera.is_type", value, "4");
12725                 mIsType = static_cast<cam_is_type_t>(atoi(value));
12726             } else {
12727                 mIsType = IS_TYPE_NONE;
12728             }
12729             stream_config_info.is_type = mIsType;
12730             stream_config_info.type[stream_config_info.num_streams] =
12731                     CAM_STREAM_TYPE_SNAPSHOT;
12732             getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
12733                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
12734             updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
12735             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12736                     mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
12737             getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
12738                         stream_config_info.format[stream_config_info.num_streams]);
12739             stream_config_info.num_streams++;
12740 
12741             stream_config_info.type[stream_config_info.num_streams] =
12742                     CAM_STREAM_TYPE_VIDEO;
12743             getStreamDimension(CAM_STREAM_TYPE_VIDEO,
12744                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
12745             updatePpFeatureMask(CAM_STREAM_TYPE_VIDEO);
12746             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12747                     mStreamPpMask[CAM_STREAM_TYPE_VIDEO];
12748             getStreamFormat(CAM_STREAM_TYPE_VIDEO,
12749                     stream_config_info.format[stream_config_info.num_streams]);
12750             stream_config_info.num_streams++;
12751         }
12752 
12753         /* Analysis stream is needed by DCRF regardless of recording hint */
12754         if ((getDcrf() == true) ||
12755                 (getRecordingHintValue() != true) ||
12756                 (fdModeInVideo())) {
12757             stream_config_info.type[stream_config_info.num_streams] =
12758                     CAM_STREAM_TYPE_ANALYSIS;
12759             getStreamDimension(CAM_STREAM_TYPE_ANALYSIS,
12760                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
12761             updatePpFeatureMask(CAM_STREAM_TYPE_ANALYSIS);
12762             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12763                     mStreamPpMask[CAM_STREAM_TYPE_ANALYSIS];
12764             getStreamFormat(CAM_STREAM_TYPE_ANALYSIS,
12765                     stream_config_info.format[stream_config_info.num_streams]);
12766             stream_config_info.num_streams++;
12767         }
12768 
12769         stream_config_info.type[stream_config_info.num_streams] =
12770                 CAM_STREAM_TYPE_PREVIEW;
12771         getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
12772                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
12773         updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
12774         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12775                 mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
12776         getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
12777                     stream_config_info.format[stream_config_info.num_streams]);
12778         stream_config_info.num_streams++;
12779 
12780         if (isUBWCEnabled() && getRecordingHintValue() != true) {
12781             cam_format_t fmt;
12782             getStreamFormat(CAM_STREAM_TYPE_PREVIEW,fmt);
12783             if (fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
12784                 stream_config_info.type[stream_config_info.num_streams] =
12785                         CAM_STREAM_TYPE_CALLBACK;
12786                 getStreamDimension(CAM_STREAM_TYPE_CALLBACK,
12787                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
12788                 updatePpFeatureMask(CAM_STREAM_TYPE_CALLBACK);
12789                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12790                         mStreamPpMask[CAM_STREAM_TYPE_CALLBACK];
12791                 getStreamFormat(CAM_STREAM_TYPE_CALLBACK,
12792                         stream_config_info.format[stream_config_info.num_streams]);
12793                 stream_config_info.num_streams++;
12794             }
12795         }
12796 
12797     } else {
12798         if (isJpegPictureFormat() || isNV16PictureFormat() || isNV21PictureFormat()) {
12799             if (!getofflineRAW()) {
12800                 stream_config_info.type[stream_config_info.num_streams] =
12801                         CAM_STREAM_TYPE_SNAPSHOT;
12802                 getStreamDimension(CAM_STREAM_TYPE_SNAPSHOT,
12803                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
12804                 updatePpFeatureMask(CAM_STREAM_TYPE_SNAPSHOT);
12805                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12806                         mStreamPpMask[CAM_STREAM_TYPE_SNAPSHOT];
12807                 getStreamFormat(CAM_STREAM_TYPE_SNAPSHOT,
12808                         stream_config_info.format[stream_config_info.num_streams]);
12809                 stream_config_info.num_streams++;
12810             }
12811 
12812             if (previewAsPostview) {
12813                 stream_config_info.type[stream_config_info.num_streams] =
12814                         CAM_STREAM_TYPE_PREVIEW;
12815                 getStreamDimension(CAM_STREAM_TYPE_PREVIEW,
12816                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
12817                 updatePpFeatureMask(CAM_STREAM_TYPE_PREVIEW);
12818                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12819                         mStreamPpMask[CAM_STREAM_TYPE_PREVIEW];
12820                 getStreamFormat(CAM_STREAM_TYPE_PREVIEW,
12821                         stream_config_info.format[stream_config_info.num_streams]);
12822                 stream_config_info.num_streams++;
12823             } else {
12824                 stream_config_info.type[stream_config_info.num_streams] =
12825                         CAM_STREAM_TYPE_POSTVIEW;
12826                 getStreamDimension(CAM_STREAM_TYPE_POSTVIEW,
12827                         stream_config_info.stream_sizes[stream_config_info.num_streams]);
12828                 updatePpFeatureMask(CAM_STREAM_TYPE_POSTVIEW);
12829                 stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12830                         mStreamPpMask[CAM_STREAM_TYPE_POSTVIEW];
12831                 getStreamFormat(CAM_STREAM_TYPE_POSTVIEW,
12832                         stream_config_info.format[stream_config_info.num_streams]);
12833                 stream_config_info.num_streams++;
12834             }
12835         } else {
12836             raw_capture = true;
12837             stream_config_info.type[stream_config_info.num_streams] =
12838                     CAM_STREAM_TYPE_RAW;
12839             getStreamDimension(CAM_STREAM_TYPE_RAW,
12840                     stream_config_info.stream_sizes[stream_config_info.num_streams]);
12841             updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
12842             stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12843                     mStreamPpMask[CAM_STREAM_TYPE_RAW];
12844             getStreamFormat(CAM_STREAM_TYPE_RAW,
12845                     stream_config_info.format[stream_config_info.num_streams]);
12846             stream_config_info.num_streams++;
12847         }
12848     }
12849 
12850     if ((!raw_capture) && ((getofflineRAW() && !getRecordingHintValue())
12851             || (raw_yuv))) {
12852         cam_dimension_t max_dim = {0,0};
12853         // Find the Maximum dimension admong all the streams
12854         for (uint32_t j = 0; j < stream_config_info.num_streams; j++) {
12855             if (stream_config_info.stream_sizes[j].width > max_dim.width) {
12856                 max_dim.width = stream_config_info.stream_sizes[j].width;
12857             }
12858             if (stream_config_info.stream_sizes[j].height > max_dim.height) {
12859                 max_dim.height = stream_config_info.stream_sizes[j].height;
12860             }
12861         }
12862         LOGH("Max Dimension = %d X %d", max_dim.width, max_dim.height);
12863         updateRAW(max_dim);
12864         stream_config_info.type[stream_config_info.num_streams] =
12865                 CAM_STREAM_TYPE_RAW;
12866         getStreamDimension(CAM_STREAM_TYPE_RAW,
12867                 stream_config_info.stream_sizes[stream_config_info.num_streams]);
12868         updatePpFeatureMask(CAM_STREAM_TYPE_RAW);
12869         stream_config_info.postprocess_mask[stream_config_info.num_streams] =
12870                 mStreamPpMask[CAM_STREAM_TYPE_RAW];
12871         getStreamFormat(CAM_STREAM_TYPE_RAW,
12872                 stream_config_info.format[stream_config_info.num_streams]);
12873         stream_config_info.num_streams++;
12874     }
12875     for (uint32_t k = 0; k < stream_config_info.num_streams; k++) {
12876         LOGI("STREAM INFO : type %d, wxh: %d x %d, pp_mask: 0x%x Format = %d",
12877                 stream_config_info.type[k],
12878                 stream_config_info.stream_sizes[k].width,
12879                 stream_config_info.stream_sizes[k].height,
12880                 stream_config_info.postprocess_mask[k],
12881                 stream_config_info.format[k]);
12882     }
12883 
12884     rc = sendStreamConfigInfo(stream_config_info);
12885     m_bStreamsConfigured = true;
12886 
12887     return rc;
12888 }
12889 
12890 /*===========================================================================
12891  * FUNCTION   : addOnlineRotation
12892  *
12893  * DESCRIPTION: send additional rotation information for specific stream
12894  *
12895  * PARAMETERS :
12896  *   @rotation: rotation
12897  *   @streamId: internal stream id
12898  *   @device_rotation: device rotation
12899  *
12900  * RETURN     : int32_t type of status
12901  *              NO_ERROR  -- success
12902  *              none-zero failure code
12903  *==========================================================================*/
addOnlineRotation(uint32_t rotation,uint32_t streamId,int32_t device_rotation)12904 int32_t QCameraParameters::addOnlineRotation(uint32_t rotation, uint32_t streamId,
12905         int32_t device_rotation)
12906 {
12907     int32_t rc = NO_ERROR;
12908     cam_rotation_info_t rotation_info;
12909     memset(&rotation_info, 0, sizeof(cam_rotation_info_t));
12910 
12911     /* Add jpeg rotation information */
12912     if (rotation == 0) {
12913         rotation_info.rotation = ROTATE_0;
12914     } else if (rotation == 90) {
12915         rotation_info.rotation = ROTATE_90;
12916     } else if (rotation == 180) {
12917         rotation_info.rotation = ROTATE_180;
12918     } else if (rotation == 270) {
12919         rotation_info.rotation = ROTATE_270;
12920     } else {
12921         rotation_info.rotation = ROTATE_0;
12922     }
12923     rotation_info.streamId = streamId;
12924 
12925     /* Add device rotation information */
12926     if (device_rotation == 0) {
12927         rotation_info.device_rotation = ROTATE_0;
12928     } else if (device_rotation == 90) {
12929         rotation_info.device_rotation = ROTATE_90;
12930     } else if (device_rotation == 180) {
12931         rotation_info.device_rotation = ROTATE_180;
12932     } else if (device_rotation == 270) {
12933         rotation_info.device_rotation = ROTATE_270;
12934     } else {
12935         rotation_info.device_rotation = ROTATE_0;
12936     }
12937 
12938     if(initBatchUpdate(m_pParamBuf) < 0 ) {
12939         LOGE("Failed to initialize group update table");
12940         return BAD_TYPE;
12941     }
12942 
12943     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_ROTATION, rotation_info)) {
12944         LOGE("Failed to update table");
12945         return BAD_VALUE;
12946     }
12947 
12948     rc = commitSetBatch();
12949     if (rc != NO_ERROR) {
12950         LOGE("Failed to set stream info parm");
12951         return rc;
12952     }
12953 
12954     return rc;
12955 }
12956 
12957 /*===========================================================================
12958  * FUNCTION   : needThumbnailReprocess
12959  *
12960  * DESCRIPTION: Check if thumbnail reprocessing is needed
12961  *
12962  * PARAMETERS : @pFeatureMask - feature mask
12963  *
12964  * RETURN     : true: needed
12965  *              false: no need
12966  *==========================================================================*/
needThumbnailReprocess(uint32_t * pFeatureMask)12967 bool QCameraParameters::needThumbnailReprocess(uint32_t *pFeatureMask)
12968 {
12969     if (isUbiFocusEnabled() || isChromaFlashEnabled() ||
12970             isOptiZoomEnabled() || isUbiRefocus() ||
12971             isStillMoreEnabled() ||
12972             (isHDREnabled() && !isHDRThumbnailProcessNeeded())
12973             || isUBWCEnabled()) {
12974         *pFeatureMask &= ~CAM_QCOM_FEATURE_CHROMA_FLASH;
12975         *pFeatureMask &= ~CAM_QCOM_FEATURE_UBIFOCUS;
12976         *pFeatureMask &= ~CAM_QCOM_FEATURE_REFOCUS;
12977         *pFeatureMask &= ~CAM_QCOM_FEATURE_OPTIZOOM;
12978         *pFeatureMask &= ~CAM_QCOM_FEATURE_STILLMORE;
12979         *pFeatureMask &= ~CAM_QCOM_FEATURE_HDR;
12980         return false;
12981     } else {
12982         cam_dimension_t thumb_dim;
12983         getThumbnailSize(&(thumb_dim.width), &(thumb_dim.height));
12984         if (thumb_dim.width == 0 || thumb_dim.height == 0) {
12985             return false;
12986         }
12987         else {
12988             return true;
12989         }
12990     }
12991 }
12992 
12993 /*===========================================================================
12994  * FUNCTION   : getNumOfExtraBuffersForImageProc
12995  *
12996  * DESCRIPTION: get number of extra input buffers needed by image processing
12997  *
12998  * PARAMETERS : none
12999  *
13000  * RETURN     : number of extra buffers needed by ImageProc;
13001  *              0 if not ImageProc enabled
13002  *==========================================================================*/
getNumOfExtraBuffersForImageProc()13003 uint8_t QCameraParameters::getNumOfExtraBuffersForImageProc()
13004 {
13005     int numOfBufs = 0;
13006 
13007     if (isUbiRefocus()) {
13008         return (uint8_t)(m_pCapability->refocus_af_bracketing_need.burst_count - 1);
13009     } else if (isUbiFocusEnabled()) {
13010         numOfBufs += m_pCapability->ubifocus_af_bracketing_need.burst_count - 1;
13011     } else if (m_bOptiZoomOn) {
13012         numOfBufs += m_pCapability->opti_zoom_settings_need.burst_count - 1;
13013     } else if (isChromaFlashEnabled()) {
13014         numOfBufs += m_pCapability->chroma_flash_settings_need.burst_count - 1;
13015     } else if (isStillMoreEnabled()) {
13016         if (isSeeMoreEnabled()) {
13017             m_stillmore_config.burst_count = 1;
13018         } else if ((m_stillmore_config.burst_count >=
13019                 m_pCapability->stillmore_settings_need.min_burst_count) &&
13020                 (m_stillmore_config.burst_count <=
13021                 m_pCapability->stillmore_settings_need.max_burst_count)) {
13022             numOfBufs += m_stillmore_config.burst_count - 1;
13023         } else {
13024             numOfBufs += m_pCapability->stillmore_settings_need.burst_count - 1;
13025         }
13026     } else if (isOEMFeatEnabled()) {
13027         numOfBufs += 1;
13028     }
13029 
13030     return (uint8_t)(numOfBufs);
13031 }
13032 
13033 /*===========================================================================
13034  * FUNCTION   : getExifBufIndex
13035  *
13036  * DESCRIPTION: get index of metadata to be used for EXIF
13037  *
13038  * PARAMETERS : @captureIndex - index of current captured frame
13039  *
13040  * RETURN     : index of metadata to be used for EXIF
13041  *==========================================================================*/
getExifBufIndex(uint32_t captureIndex)13042 uint32_t QCameraParameters::getExifBufIndex(uint32_t captureIndex)
13043 {
13044     uint32_t index = captureIndex;
13045 
13046     if (isUbiRefocus()) {
13047         if (captureIndex < m_pCapability->refocus_af_bracketing_need.burst_count) {
13048             index = captureIndex;
13049         } else {
13050             index = 0;
13051         }
13052     } else if (isChromaFlashEnabled()) {
13053         index = m_pCapability->chroma_flash_settings_need.metadata_index;
13054     } else if (isHDREnabled()) {
13055         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
13056             index = m_pCapability->hdr_bracketing_setting.num_frames;
13057         } else {
13058             for (index = 0; index < m_pCapability->hdr_bracketing_setting.num_frames; index++) {
13059                 if (0 == m_pCapability->hdr_bracketing_setting.exp_val.values[index]) {
13060                     break;
13061                 }
13062             }
13063             if (index == m_pCapability->hdr_bracketing_setting.num_frames) {
13064                 index = captureIndex;
13065             }
13066         }
13067     }
13068 
13069     return index;
13070 }
13071 
13072 /*===========================================================================
13073  * FUNCTION   : getNumberInBufsForSingleShot
13074  *
13075  * DESCRIPTION: get number of input buffers for single shot
13076  *
13077  * PARAMETERS : none
13078  *
13079  * RETURN     : number of input buffers for single shot
13080  *==========================================================================*/
getNumberInBufsForSingleShot()13081 uint32_t QCameraParameters::getNumberInBufsForSingleShot()
13082 {
13083     uint32_t numOfBufs = 1;
13084 
13085     if (isUbiRefocus()) {
13086         numOfBufs = m_pCapability->refocus_af_bracketing_need.burst_count;
13087     } else if (isUbiFocusEnabled()) {
13088         numOfBufs = m_pCapability->ubifocus_af_bracketing_need.burst_count;
13089     } else if (m_bOptiZoomOn) {
13090         numOfBufs = m_pCapability->opti_zoom_settings_need.burst_count;
13091     } else if (isChromaFlashEnabled()) {
13092         numOfBufs = m_pCapability->chroma_flash_settings_need.burst_count;
13093     } else if (isHDREnabled()) {
13094         numOfBufs = m_pCapability->hdr_bracketing_setting.num_frames;
13095         if (isHDR1xFrameEnabled() && isHDR1xExtraBufferNeeded()) {
13096             numOfBufs++;
13097         }
13098     } else if (isStillMoreEnabled()) {
13099         if (isSeeMoreEnabled()) {
13100             m_stillmore_config.burst_count = 1;
13101             numOfBufs = m_stillmore_config.burst_count;
13102         } else if ((m_stillmore_config.burst_count >=
13103                 m_pCapability->stillmore_settings_need.min_burst_count) &&
13104                 (m_stillmore_config.burst_count <=
13105                 m_pCapability->stillmore_settings_need.max_burst_count)) {
13106             numOfBufs = m_stillmore_config.burst_count;
13107         } else {
13108             numOfBufs = m_pCapability->stillmore_settings_need.burst_count;
13109         }
13110     }
13111 
13112     return numOfBufs;
13113 }
13114 
13115 /*===========================================================================
13116  * FUNCTION   : getNumberOutBufsForSingleShot
13117  *
13118  * DESCRIPTION: get number of output buffers for single shot
13119  *
13120  * PARAMETERS : none
13121  *
13122  * RETURN     : number of output buffers for single shot
13123  *==========================================================================*/
getNumberOutBufsForSingleShot()13124 uint32_t QCameraParameters::getNumberOutBufsForSingleShot()
13125 {
13126     uint32_t numOfBufs = 1;
13127 
13128     if (isUbiRefocus()) {
13129         numOfBufs = m_pCapability->refocus_af_bracketing_need.output_count;
13130     } else if (isHDREnabled()) {
13131         if (isHDR1xFrameEnabled()) {
13132             numOfBufs++;
13133         }
13134     }
13135 
13136     return numOfBufs;
13137 }
13138 
13139 /*===========================================================================
13140  * FUNCTION   : is4k2kVideoResolution
13141  *
13142  * DESCRIPTION: if resolution is 4k x 2k or true 4k x 2k
13143  *
13144  * PARAMETERS : none
13145  *
13146  * RETURN     : true: video resolution is 4k x 2k
13147  *              false: video resolution is not 4k x 2k
13148  *==========================================================================*/
is4k2kVideoResolution()13149 bool QCameraParameters::is4k2kVideoResolution()
13150 {
13151    bool enabled = false;
13152    cam_dimension_t resolution;
13153    getVideoSize(&resolution.width, &resolution.height);
13154    if (!(resolution.width < 3840 && resolution.height < 2160)) {
13155       enabled = true;
13156    }
13157 
13158    return enabled;
13159 }
13160 
13161 /*===========================================================================
13162  * FUNCTION   : isPreviewSeeMoreRequired
13163  *
13164  * DESCRIPTION: This function checks whether SeeMmore(SW TNR) needs to be applied for
13165  *              preview stream depending on video resoluion and setprop
13166  *
13167  * PARAMETERS : none
13168  *
13169  * RETURN     : true: If SeeMore needs to apply
13170  *              false: No need to apply
13171  *==========================================================================*/
isPreviewSeeMoreRequired()13172 bool QCameraParameters::isPreviewSeeMoreRequired()
13173 {
13174    cam_dimension_t dim;
13175    char prop[PROPERTY_VALUE_MAX];
13176 
13177    getVideoSize(&dim.width, &dim.height);
13178    memset(prop, 0, sizeof(prop));
13179    property_get("persist.camera.preview.seemore", prop, "0");
13180    int enable = atoi(prop);
13181 
13182    // Enable SeeMore for preview stream if :
13183    // 1. Video resolution <= (1920x1080)  (or)
13184    // 2. persist.camera.preview.seemore is set
13185    LOGD("width=%d, height=%d, enable=%d", dim.width, dim.height, enable);
13186    return (((dim.width * dim.height) <= (1920 * 1080)) || enable);
13187 }
13188 
13189 /*===========================================================================
13190  * FUNCTION   : updateDebugLevel
13191  *
13192  * DESCRIPTION: send CAM_INTF_PARM_UPDATE_DEBUG_LEVEL to backend
13193  *
13194  * PARAMETERS : none
13195  *
13196  * RETURN     : NO_ERROR --success
13197  *              int32_t type of status
13198  *==========================================================================*/
updateDebugLevel()13199 int32_t QCameraParameters::updateDebugLevel()
13200 {
13201     if ( m_pParamBuf == NULL ) {
13202         return NO_INIT;
13203     }
13204 
13205     int32_t rc = initBatchUpdate(m_pParamBuf);
13206     if ( rc != NO_ERROR ) {
13207         LOGE("Failed to initialize group update table");
13208         return rc;
13209     }
13210 
13211     uint32_t dummyDebugLevel = 0;
13212     /* The value of dummyDebugLevel is irrelavent. On
13213      * CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, read debug property */
13214     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_UPDATE_DEBUG_LEVEL, dummyDebugLevel)) {
13215         LOGE("Parameters batch failed");
13216         return BAD_VALUE;
13217     }
13218 
13219     rc = commitSetBatch();
13220     if ( rc != NO_ERROR ) {
13221         LOGE("Failed to commit batch parameters");
13222         return rc;
13223     }
13224 
13225     return NO_ERROR;
13226 }
13227 
13228 /*===========================================================================
13229  * FUNCTION   : setOfflineRAW
13230  *
13231  * DESCRIPTION: Function to decide Offline RAW feature.
13232  *
13233  * PARAMETERS :
13234  *  @raw_value: offline raw value to set.
13235  *
13236  * RETURN     : none
13237  *==========================================================================*/
setOfflineRAW(bool raw_value)13238 void QCameraParameters::setOfflineRAW(bool raw_value)
13239 {
13240     char value[PROPERTY_VALUE_MAX];
13241     bool raw_yuv = false;
13242     bool offlineRaw = false;
13243 
13244     if (raw_value) {
13245         mOfflineRAW = true;
13246         LOGH("Offline Raw  %d", mOfflineRAW);
13247         return;
13248     }
13249 
13250     property_get("persist.camera.raw_yuv", value, "0");
13251     raw_yuv = atoi(value) > 0 ? true : false;
13252     property_get("persist.camera.offlineraw", value, "0");
13253     offlineRaw = atoi(value) > 0 ? true : false;
13254     if ((raw_yuv || isRdiMode()) && offlineRaw) {
13255         mOfflineRAW = true;
13256     } else {
13257         mOfflineRAW = false;
13258     }
13259     LOGH("Offline Raw  %d", mOfflineRAW);
13260 }
13261 
13262 /*===========================================================================
13263  * FUNCTION   : updatePpFeatureMask
13264  *
13265  * DESCRIPTION: Updates the feature mask for a particular stream depending
13266  *              on current client configuration.
13267  *
13268  * PARAMETERS :
13269  *  @stream_type: Camera stream type
13270  *
13271  * RETURN     : NO_ERROR --success
13272  *              int32_t type of status
13273  *==========================================================================*/
updatePpFeatureMask(cam_stream_type_t stream_type)13274 int32_t QCameraParameters::updatePpFeatureMask(cam_stream_type_t stream_type) {
13275 
13276     uint32_t feature_mask = 0;
13277 
13278     if (stream_type >= CAM_STREAM_TYPE_MAX) {
13279         LOGE("Error!! stream type: %d not valid", stream_type);
13280         return -1;
13281     }
13282 
13283     // Update feature mask for SeeMore in video and video preview
13284     if (isSeeMoreEnabled() && ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
13285             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
13286             isPreviewSeeMoreRequired()))) {
13287        feature_mask |= CAM_QCOM_FEATURE_LLVD;
13288     }
13289 
13290     if (isHighQualityNoiseReductionMode() &&
13291             ((stream_type == CAM_STREAM_TYPE_VIDEO) ||
13292             (stream_type == CAM_STREAM_TYPE_PREVIEW && getRecordingHintValue() &&
13293             isPreviewSeeMoreRequired()))) {
13294         feature_mask |= CAM_QTI_FEATURE_SW_TNR;
13295     }
13296 
13297     // Do not enable feature mask for ZSL/non-ZSL/liveshot snapshot except for 4K2k case
13298     if ((getRecordingHintValue() &&
13299             (stream_type == CAM_STREAM_TYPE_SNAPSHOT) && is4k2kVideoResolution()) ||
13300             (stream_type != CAM_STREAM_TYPE_SNAPSHOT)) {
13301         if ((m_nMinRequiredPpMask & CAM_QCOM_FEATURE_SHARPNESS) &&
13302                 !isOptiZoomEnabled()) {
13303             feature_mask |= CAM_QCOM_FEATURE_SHARPNESS;
13304         }
13305 
13306         if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_EFFECT) {
13307             feature_mask |= CAM_QCOM_FEATURE_EFFECT;
13308         }
13309         if (isWNREnabled()) {
13310             feature_mask |= CAM_QCOM_FEATURE_DENOISE2D;
13311         }
13312 
13313         //Set flip mode based on Stream type;
13314         int flipMode = getFlipMode(stream_type);
13315         if (flipMode > 0) {
13316             feature_mask |= CAM_QCOM_FEATURE_FLIP;
13317         }
13318     }
13319 
13320     if ((isTNRVideoEnabled() && (CAM_STREAM_TYPE_VIDEO == stream_type))
13321             || (isTNRPreviewEnabled() && (CAM_STREAM_TYPE_PREVIEW == stream_type))) {
13322         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
13323     }
13324     if (isEztuneEnabled() &&
13325             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
13326             (CAM_STREAM_TYPE_SNAPSHOT == stream_type))) {
13327         feature_mask |= CAM_QCOM_FEATURE_EZTUNE;
13328     }
13329 
13330     if ((getCDSMode() != CAM_CDS_MODE_OFF) &&
13331             ((CAM_STREAM_TYPE_PREVIEW == stream_type) ||
13332             (CAM_STREAM_TYPE_VIDEO == stream_type) ||
13333             (CAM_STREAM_TYPE_CALLBACK == stream_type) ||
13334             ((CAM_STREAM_TYPE_SNAPSHOT == stream_type) &&
13335             getRecordingHintValue() && is4k2kVideoResolution()))) {
13336          if (m_nMinRequiredPpMask & CAM_QCOM_FEATURE_DSDN) {
13337              feature_mask |= CAM_QCOM_FEATURE_DSDN;
13338          } else {
13339              feature_mask |= CAM_QCOM_FEATURE_CDS;
13340          }
13341     }
13342 
13343     if (isTNRSnapshotEnabled() && (CAM_STREAM_TYPE_SNAPSHOT == stream_type)
13344             && (isZSLMode() || getRecordingHintValue())) {
13345         feature_mask |= CAM_QCOM_FEATURE_CPP_TNR;
13346     }
13347 
13348     //Rotation could also have an effect on pp feature mask
13349     cam_pp_feature_config_t config;
13350     cam_dimension_t dim;
13351     memset(&config, 0, sizeof(cam_pp_feature_config_t));
13352     getStreamRotation(stream_type, config, dim);
13353     feature_mask |= config.feature_mask;
13354 
13355     // Dual Camera scenarios
13356     // all feature masks are disabled for preview and analysis streams for aux session
13357     // all required feature masks for aux session preview and analysis streams need
13358     // to be enabled explicitly here
13359     ///@note When aux camera is of bayer type, keep pp mask as is or we'd run
13360     ///      into stream mapping problems. YUV sensor is marked as interleaved and has
13361     ///      preferred mapping setup so we don't see any mapping issues.
13362     if (m_relCamSyncInfo.sync_control == CAM_SYNC_RELATED_SENSORS_ON) {
13363         if (((CAM_STREAM_TYPE_ANALYSIS == stream_type) ||
13364                 (CAM_STREAM_TYPE_PREVIEW == stream_type)) &&
13365                 (m_relCamSyncInfo.mode == CAM_MODE_SECONDARY) &&
13366                 (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
13367             LOGH("Disabling all pp feature masks for aux preview and "
13368                     "analysis streams");
13369             feature_mask = 0;
13370         }
13371 
13372         // all feature masks need to be enabled here
13373         // enable DCRF feature mask on analysis stream in case of dual camera
13374         if (m_bDcrfEnabled && (CAM_STREAM_TYPE_ANALYSIS == stream_type)) {
13375             feature_mask |= CAM_QCOM_FEATURE_DCRF;
13376         } else {
13377             feature_mask &= ~CAM_QCOM_FEATURE_DCRF;
13378         }
13379     }
13380 
13381     // Store stream feature mask
13382     setStreamPpMask(stream_type, feature_mask);
13383     LOGH("stream type: %d, pp_mask: 0x%x", stream_type, feature_mask);
13384 
13385     return NO_ERROR;
13386 }
13387 
13388 /*===========================================================================
13389  * FUNCTION   : setStreamPpMask
13390  *
13391  * DESCRIPTION: Stores a particular feature mask for a given camera stream
13392  *
13393  * PARAMETERS :
13394  *  @stream_type: Camera stream type
13395  *  @pp_mask  : Feature mask
13396  *
13397  * RETURN     : NO_ERROR --success
13398  *              int32_t type of status
13399  *==========================================================================*/
setStreamPpMask(cam_stream_type_t stream_type,uint32_t pp_mask)13400 int32_t QCameraParameters::setStreamPpMask(cam_stream_type_t stream_type,
13401         uint32_t pp_mask) {
13402 
13403     if(stream_type >= CAM_STREAM_TYPE_MAX) {
13404         return BAD_TYPE;
13405     }
13406 
13407     mStreamPpMask[stream_type] = pp_mask;
13408     return NO_ERROR;
13409 }
13410 
13411 /*===========================================================================
13412  * FUNCTION   : getStreamPpMask
13413  *
13414  * DESCRIPTION: Retrieves the feature mask for a given camera stream
13415  *
13416  * PARAMETERS :
13417  *  @stream_type: Camera stream type
13418  *  @pp_mask  : Feature mask
13419  *
13420  * RETURN     : NO_ERROR --success
13421  *              int32_t type of status
13422  *==========================================================================*/
getStreamPpMask(cam_stream_type_t stream_type,uint32_t & pp_mask)13423 int32_t QCameraParameters::getStreamPpMask(cam_stream_type_t stream_type,
13424         uint32_t &pp_mask) {
13425 
13426     if(stream_type >= CAM_STREAM_TYPE_MAX) {
13427         return BAD_TYPE;
13428     }
13429 
13430     pp_mask = mStreamPpMask[stream_type];
13431     return NO_ERROR;
13432 }
13433 
13434 /*===========================================================================
13435  * FUNCTION   : isMultiPassReprocessing
13436  *
13437  * DESCRIPTION: Read setprop to enable/disable multipass
13438  *
13439  * PARAMETERS : none
13440  *
13441  * RETURN     : TRUE  -- If enabled
13442  *              FALSE  -- disabled
13443  *==========================================================================*/
isMultiPassReprocessing()13444 bool QCameraParameters::isMultiPassReprocessing()
13445 {
13446     char value[PROPERTY_VALUE_MAX];
13447     int multpass = 0;
13448 
13449     property_get("persist.camera.multi_pass", value, "0");
13450     multpass = atoi(value);
13451 
13452     return (multpass == 0)? FALSE : TRUE;
13453 }
13454 
13455 /*===========================================================================
13456  * FUNCTION   : setReprocCount
13457  *
13458  * DESCRIPTION: Set total reprocessing pass count
13459  *
13460  * PARAMETERS : none
13461  *
13462  * RETURN     : None
13463  *==========================================================================*/
setReprocCount()13464 void QCameraParameters::setReprocCount()
13465 {
13466     mTotalPPCount = 1; //Default reprocessing Pass count
13467 
13468     if (getManualCaptureMode() >=
13469             CAM_MANUAL_CAPTURE_TYPE_3) {
13470         LOGD("Additional post processing enabled for manual capture");
13471         mTotalPPCount++;
13472     }
13473 
13474     if (!isMultiPassReprocessing()) {
13475         return;
13476     }
13477 
13478     if ((getZoomLevel() != 0)
13479             && (getBurstCountForAdvancedCapture()
13480             == getNumOfSnapshots())) {
13481         LOGD("2 Pass postprocessing enabled");
13482         mTotalPPCount++;
13483     }
13484 }
13485 
13486 /*===========================================================================
13487  * FUNCTION   : isUBWCEnabled
13488  *
13489  * DESCRIPTION: Function to get UBWC hardware support.
13490  *
13491  * PARAMETERS : None
13492  *
13493  * RETURN     : TRUE -- UBWC format supported
13494  *              FALSE -- UBWC is not supported.
13495  *==========================================================================*/
isUBWCEnabled()13496 bool QCameraParameters::isUBWCEnabled()
13497 {
13498 #ifdef UBWC_PRESENT
13499     char value[PROPERTY_VALUE_MAX];
13500     int prop_value = 0;
13501     memset(value, 0, sizeof(value));
13502     property_get("debug.gralloc.gfx_ubwc_disable", value, "0");
13503     prop_value = atoi(value);
13504     if (prop_value) {
13505         return FALSE;
13506     }
13507 
13508     //Disable UBWC if it is YUV sensor.
13509     if ((m_pCapability != NULL) &&
13510             (m_pCapability->sensor_type.sens_type == CAM_SENSOR_YUV)) {
13511         return FALSE;
13512     }
13513 
13514     //Disable UBWC if Eztune is enabled
13515     // Eztune works on CPP output and cannot understand UBWC buffer.
13516     memset(value, 0, sizeof(value));
13517     property_get("persist.camera.eztune.enable", value, "0");
13518     prop_value = atoi(value);
13519     if (prop_value) {
13520         return FALSE;
13521     }
13522     return TRUE;
13523 #else
13524     return FALSE;
13525 #endif
13526 }
13527 
13528 /*===========================================================================
13529  * FUNCTION   : isPostProcScaling
13530  *
13531  * DESCRIPTION: is scaling to be done by CPP?
13532  *
13533  * PARAMETERS : none
13534  *
13535  * RETURN     : TRUE  : If CPP scaling enabled
13536  *              FALSE : If VFE scaling enabled
13537  *==========================================================================*/
isPostProcScaling()13538 bool QCameraParameters::isPostProcScaling()
13539 {
13540     char value[PROPERTY_VALUE_MAX];
13541     bool cpp_scaling = FALSE;
13542 
13543     if (getRecordingHintValue()) {
13544         return FALSE;
13545     }
13546 
13547     property_get("persist.camera.pp_scaling", value, "0");
13548     cpp_scaling = atoi(value) > 0 ? TRUE : FALSE;
13549 
13550     LOGH("Post proc scaling enabled : %d",
13551              cpp_scaling);
13552     return cpp_scaling;
13553 }
13554 
13555 /*===========================================================================
13556  * FUNCTION   : isLLNoiseEnabled
13557  *
13558  * DESCRIPTION: Low light noise change
13559  *
13560  * PARAMETERS : none
13561  *
13562  * RETURN     : TRUE  : If low light noise enabled
13563  *              FALSE : If low light noise disabled
13564  *==========================================================================*/
isLLNoiseEnabled()13565 bool QCameraParameters::isLLNoiseEnabled()
13566 {
13567     char value[PROPERTY_VALUE_MAX];
13568     bool llnoise = FALSE;
13569 
13570     if (!isWNREnabled()) {
13571         return FALSE;
13572     }
13573 
13574     property_get("persist.camera.llnoise", value, "0");
13575     llnoise = atoi(value) > 0 ? TRUE : FALSE;
13576 
13577     LOGH("Low light noise enabled : %d",
13578              llnoise);
13579     return llnoise;
13580 }
13581 
13582 /*===========================================================================
13583  * FUNCTION   : setBufBatchCount
13584  *
13585  * DESCRIPTION: Function to configure batch buffer
13586  *
13587  * PARAMETERS : int8_t buf_cnt
13588  *                     Buffer batch count
13589  *
13590  * RETURN     :  None
13591  *==========================================================================*/
setBufBatchCount(int8_t buf_cnt)13592 void QCameraParameters::setBufBatchCount(int8_t buf_cnt)
13593 {
13594     mBufBatchCnt = 0;
13595     char value[PROPERTY_VALUE_MAX];
13596     int8_t count = 0;
13597 
13598     property_get("persist.camera.batchcount", value, "0");
13599     count = atoi(value);
13600 
13601     if (!(count != 0 || buf_cnt > CAMERA_MIN_BATCH_COUNT)) {
13602         LOGH("Buffer batch count = %d", mBufBatchCnt);
13603         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
13604         return;
13605     }
13606 
13607     while((m_pCapability->max_batch_bufs_supported != 0)
13608             && (m_pCapability->max_batch_bufs_supported < buf_cnt)) {
13609         buf_cnt = buf_cnt / 2;
13610     }
13611 
13612     if (count > 0) {
13613         mBufBatchCnt = count;
13614         LOGH("Buffer batch count = %d", mBufBatchCnt);
13615         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
13616         return;
13617     }
13618 
13619     if (buf_cnt > CAMERA_MIN_BATCH_COUNT) {
13620         mBufBatchCnt = buf_cnt;
13621         LOGH("Buffer batch count = %d", mBufBatchCnt);
13622         set(KEY_QC_VIDEO_BATCH_SIZE, mBufBatchCnt);
13623         return;
13624     }
13625 }
13626 
13627 /*===========================================================================
13628  * FUNCTION   : setVideoBatch()
13629  *
13630  * DESCRIPTION: Function to batching for video.
13631  *
13632  * PARAMETERS : none
13633  *
13634  * RETURN     :  None
13635  *==========================================================================*/
setVideoBatchSize()13636 void QCameraParameters::setVideoBatchSize()
13637 {
13638     char value[PROPERTY_VALUE_MAX];
13639     int8_t minBatchcnt = 2; //Batching enabled only if batch size if greater than 2;
13640     int32_t width = 0, height = 0;
13641     mVideoBatchSize = 0;
13642 
13643     if (getBufBatchCount()) {
13644         //We don't need HAL to HAL batching if camera batching enabled.
13645         return;
13646     }
13647 
13648     getVideoSize(&width, &height);
13649     if ((width > 1920) || (height > 1080)) {
13650         //Cannot enable batch mode for video size bigger than 1080p
13651         return;
13652     }
13653 
13654     //Batch size "6" is the recommended and gives optimal power saving.
13655     property_get("persist.camera.video.batchsize", value, "0");
13656     mVideoBatchSize = atoi(value);
13657 
13658     if (mVideoBatchSize > CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE) {
13659         mVideoBatchSize = CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE;
13660     } else if (mVideoBatchSize <= minBatchcnt) {
13661         //Batching enabled only if batch size is greater than 2.
13662         mVideoBatchSize = 0;
13663     }
13664     LOGD("mVideoBatchSize = %d", mVideoBatchSize);
13665     set(KEY_QC_VIDEO_BATCH_SIZE, mVideoBatchSize);
13666 }
13667 
13668 /*===========================================================================
13669  * FUNCTION   : setCustomParams
13670  *
13671  * DESCRIPTION: Function to update OEM specific custom parameter
13672  *
13673  * PARAMETERS : params: Input Parameter object
13674  *
13675  * RETURN     :  error value
13676  *==========================================================================*/
setCustomParams(__unused const QCameraParameters & params)13677 int32_t QCameraParameters::setCustomParams(__unused const QCameraParameters& params)
13678 {
13679     int32_t rc = NO_ERROR;
13680 
13681     /* Application specific parameter can be read from "params" and update m_pParamBuf
13682        We can also update internal OEM custom parameters in this funcion.
13683        "CAM_CUSTOM_PARM_EXAMPLE" is used as a example */
13684 
13685     /*Get the pointer of shared buffer for custom parameter*/
13686     custom_parm_buffer_t *customParam =
13687             (custom_parm_buffer_t *)POINTER_OF_META(CAM_INTF_PARM_CUSTOM, m_pParamBuf);
13688 
13689 
13690     /*start updating custom parameter values*/
13691     if (ADD_SET_PARAM_ENTRY_TO_BATCH(customParam, CAM_CUSTOM_PARM_EXAMPLE, 1)) {
13692         LOGE("Failed to update CAM_CUSTOM_PARM_DUMMY");
13693         return BAD_VALUE;
13694     }
13695 
13696     /*set custom parameter values to main parameter buffer. Update isvalid flag*/
13697     ADD_GET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CUSTOM);
13698 
13699     return rc;
13700 }
13701 
13702 /*===========================================================================
13703  * FUNCTION   : dump
13704  *
13705  * DESCRIPTION: Composes a string based on current configuration
13706  *
13707  * PARAMETERS : none
13708  *
13709  * RETURN     : Formatted string
13710  *==========================================================================*/
dump()13711 String8 QCameraParameters::dump()
13712 {
13713     String8 str("\n");
13714     char s[128];
13715 
13716     snprintf(s, 128, "Preview Pixel Fmt: %d\n", getPreviewHalPixelFormat());
13717     str += s;
13718 
13719     snprintf(s, 128, "ZSL Burst Interval: %d\n", getZSLBurstInterval());
13720     str += s;
13721 
13722     snprintf(s, 128, "ZSL Queue Depth: %d\n", getZSLQueueDepth());
13723     str += s;
13724 
13725     snprintf(s, 128, "ZSL Back Look Count %d\n", getZSLBackLookCount());
13726     str += s;
13727 
13728     snprintf(s, 128, "Max Unmatched Frames In Queue: %d\n",
13729         getMaxUnmatchedFramesInQueue());
13730     str += s;
13731 
13732     snprintf(s, 128, "Is ZSL Mode: %d\n", isZSLMode());
13733     str += s;
13734 
13735     snprintf(s, 128, "Is No Display Mode: %d\n", isNoDisplayMode());
13736     str += s;
13737 
13738     snprintf(s, 128, "Is WNR Enabled: %d\n", isWNREnabled());
13739     str += s;
13740 
13741     snprintf(s, 128, "isHfrMode: %d\n", isHfrMode());
13742     str += s;
13743 
13744     snprintf(s, 128, "getNumOfSnapshots: %d\n", getNumOfSnapshots());
13745     str += s;
13746 
13747     snprintf(s, 128, "getNumOfExtraHDRInBufsIfNeeded: %d\n",
13748         getNumOfExtraHDRInBufsIfNeeded());
13749     str += s;
13750 
13751     snprintf(s, 128, "getNumOfExtraHDROutBufsIfNeeded: %d\n",
13752         getNumOfExtraHDROutBufsIfNeeded());
13753     str += s;
13754 
13755     snprintf(s, 128, "getRecordingHintValue: %d\n", getRecordingHintValue());
13756     str += s;
13757 
13758     snprintf(s, 128, "getJpegQuality: %u\n", getJpegQuality());
13759     str += s;
13760 
13761     snprintf(s, 128, "getJpegRotation: %u\n", getJpegRotation());
13762     str += s;
13763 
13764     snprintf(s, 128, "isHistogramEnabled: %d\n", isHistogramEnabled());
13765     str += s;
13766 
13767     snprintf(s, 128, "isFaceDetectionEnabled: %d\n", isFaceDetectionEnabled());
13768     str += s;
13769 
13770     snprintf(s, 128, "isHDREnabled: %d\n", isHDREnabled());
13771     str += s;
13772 
13773     snprintf(s, 128, "isAutoHDREnabled: %d\n", isAutoHDREnabled());
13774     str += s;
13775 
13776     snprintf(s, 128, "isAVTimerEnabled: %d\n", isAVTimerEnabled());
13777     str += s;
13778 
13779     snprintf(s, 128, "getFocusMode: %d\n", getFocusMode());
13780     str += s;
13781 
13782     snprintf(s, 128, "isJpegPictureFormat: %d\n", isJpegPictureFormat());
13783     str += s;
13784 
13785     snprintf(s, 128, "isNV16PictureFormat: %d\n", isNV16PictureFormat());
13786     str += s;
13787 
13788     snprintf(s, 128, "isNV21PictureFormat: %d\n", isNV21PictureFormat());
13789     str += s;
13790 
13791     snprintf(s, 128, "isSnapshotFDNeeded: %d\n", isSnapshotFDNeeded());
13792     str += s;
13793 
13794     snprintf(s, 128, "isHDR1xFrameEnabled: %d\n", isHDR1xFrameEnabled());
13795     str += s;
13796 
13797     snprintf(s, 128, "isYUVFrameInfoNeeded: %d\n", isYUVFrameInfoNeeded());
13798     str += s;
13799 
13800     snprintf(s, 128, "isHDR1xExtraBufferNeeded: %d\n",
13801         isHDR1xExtraBufferNeeded());
13802     str += s;
13803 
13804     snprintf(s, 128, "isHDROutputCropEnabled: %d\n", isHDROutputCropEnabled());
13805     str += s;
13806 
13807     snprintf(s, 128, "isPreviewFlipChanged: %d\n", isPreviewFlipChanged());
13808     str += s;
13809 
13810     snprintf(s, 128, "isVideoFlipChanged: %d\n", isVideoFlipChanged());
13811     str += s;
13812 
13813     snprintf(s, 128, "isSnapshotFlipChanged: %d\n", isSnapshotFlipChanged());
13814     str += s;
13815 
13816     snprintf(s, 128, "isHDRThumbnailProcessNeeded: %d\n",
13817         isHDRThumbnailProcessNeeded());
13818     str += s;
13819 
13820     snprintf(s, 128, "getAutoFlickerMode: %d\n", getAutoFlickerMode());
13821     str += s;
13822 
13823     snprintf(s, 128, "getNumOfExtraBuffersForImageProc: %d\n",
13824         getNumOfExtraBuffersForImageProc());
13825     str += s;
13826 
13827     snprintf(s, 128, "isUbiFocusEnabled: %d\n", isUbiFocusEnabled());
13828     str += s;
13829 
13830     snprintf(s, 128, "isChromaFlashEnabled: %d\n", isChromaFlashEnabled());
13831     str += s;
13832 
13833     snprintf(s, 128, "isOptiZoomEnabled: %d\n", isOptiZoomEnabled());
13834     str += s;
13835 
13836     snprintf(s, 128, "isStillMoreEnabled: %d\n", isStillMoreEnabled());
13837     str += s;
13838 
13839     snprintf(s, 128, "getBurstCountForAdvancedCapture: %d\n",
13840         getBurstCountForAdvancedCapture());
13841     str += s;
13842 
13843     return str;
13844 }
13845 
13846 /*===========================================================================
13847  * FUNCTION   : getNumOfExtraBuffersForVideo
13848  *
13849  * DESCRIPTION: get number of extra buffers needed by image processing
13850  *
13851  * PARAMETERS : none
13852  *
13853  * RETURN     : number of extra buffers needed by ImageProc;
13854  *              0 if not ImageProc enabled
13855  *==========================================================================*/
getNumOfExtraBuffersForVideo()13856 uint8_t QCameraParameters::getNumOfExtraBuffersForVideo()
13857 {
13858     uint8_t numOfBufs = 0;
13859 
13860     if (isSeeMoreEnabled() || isHighQualityNoiseReductionMode()) {
13861         numOfBufs = 1;
13862     }
13863 
13864     return numOfBufs;
13865 }
13866 
13867 /*===========================================================================
13868  * FUNCTION   : getNumOfExtraBuffersForPreview
13869  *
13870  * DESCRIPTION: get number of extra buffers needed by image processing
13871  *
13872  * PARAMETERS : none
13873  *
13874  * RETURN     : number of extra buffers needed by ImageProc;
13875  *              0 if not ImageProc enabled
13876  *==========================================================================*/
getNumOfExtraBuffersForPreview()13877 uint8_t QCameraParameters::getNumOfExtraBuffersForPreview()
13878 {
13879     uint8_t numOfBufs = 0;
13880 
13881     if ((isSeeMoreEnabled() || isHighQualityNoiseReductionMode())
13882             && !isZSLMode() && getRecordingHintValue()) {
13883         numOfBufs = 1;
13884     }
13885 
13886     return numOfBufs;
13887 }
13888 
13889 /*===========================================================================
13890  * FUNCTION   : setToneMapMode
13891  *
13892  * DESCRIPTION: enable or disable tone map
13893  *
13894  * PARAMETERS :
13895  *   @enable : enable: 1; disable 0
13896  *   @initCommit: if configuration list needs to be initialized and commited
13897  *
13898  * RETURN     : int32_t type of status
13899  *              NO_ERROR  -- success
13900  *              none-zero failure code
13901  *==========================================================================*/
setToneMapMode(uint32_t enable,bool initCommit)13902 int32_t QCameraParameters::setToneMapMode(uint32_t enable, bool initCommit)
13903 {
13904     int32_t rc = NO_ERROR;
13905     LOGH("tone map mode %d ", enable);
13906 
13907     if (initCommit) {
13908         if (initBatchUpdate(m_pParamBuf) < 0) {
13909             LOGE("Failed to initialize group update table");
13910             return FAILED_TRANSACTION;
13911         }
13912     }
13913 
13914     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_TONE_MAP_MODE, enable)) {
13915         LOGE("Failed to update tone map mode");
13916         return BAD_VALUE;
13917     }
13918 
13919     if (initCommit) {
13920         rc = commitSetBatch();
13921         if (rc != NO_ERROR) {
13922             LOGE("Failed to commit tone map mode");
13923             return rc;
13924         }
13925     }
13926 
13927     return rc;
13928 }
13929 
13930 /*===========================================================================
13931  * FUNCTION   : getLongshotStages
13932  *
13933  * DESCRIPTION: get number of stages for longshot
13934  *
13935  * PARAMETERS : none
13936  *
13937  * RETURN     : number of stages
13938  *==========================================================================*/
getLongshotStages()13939 uint8_t QCameraParameters::getLongshotStages()
13940 {
13941     uint8_t numStages =
13942             isLowMemoryDevice() ? CAMERA_MIN_LONGSHOT_STAGES : CAMERA_DEFAULT_LONGSHOT_STAGES;
13943 
13944     char prop[PROPERTY_VALUE_MAX];
13945     memset(prop, 0, sizeof(prop));
13946     property_get("persist.camera.longshot.stages", prop, "0");
13947     uint8_t propStages = atoi(prop);
13948     if (propStages > 0 && propStages <= CAMERA_DEFAULT_LONGSHOT_STAGES) {
13949         numStages = propStages;
13950     }
13951     return numStages;
13952 }
13953 
13954 /*===========================================================================
13955  * FUNCTION   : setCDSMode
13956  *
13957  * DESCRIPTION: set CDS mode
13958  *
13959  * PARAMETERS :
13960  *   @cds_mode : cds mode
13961  *   @initCommit: if configuration list needs to be initialized and commited
13962  *
13963  * RETURN     : int32_t type of status
13964  *              NO_ERROR  -- success
13965  *              none-zero failure code
13966  *==========================================================================*/
setCDSMode(int32_t cds_mode,bool initCommit)13967 int32_t QCameraParameters::setCDSMode(int32_t cds_mode, bool initCommit)
13968 {
13969     if (initCommit) {
13970         if (initBatchUpdate(m_pParamBuf) < 0) {
13971             LOGE("Failed to initialize group update table");
13972             return FAILED_TRANSACTION;
13973         }
13974     }
13975 
13976     int32_t rc = NO_ERROR;
13977     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_CDS_MODE, cds_mode)) {
13978         LOGE("Failed to update cds mode");
13979         return BAD_VALUE;
13980     }
13981 
13982     if (initCommit) {
13983         rc = commitSetBatch();
13984         if (NO_ERROR != rc) {
13985             LOGE("Failed to set cds mode");
13986             return rc;
13987         }
13988     }
13989 
13990     LOGH("cds mode -> %d", cds_mode);
13991 
13992     return rc;
13993 }
13994 
13995 /*===========================================================================
13996  * FUNCTION   : setLowLightCapture
13997  *
13998  * DESCRIPTION: Function to enable low light capture
13999  *==========================================================================*/
setLowLightCapture()14000 void QCameraParameters::setLowLightCapture()
14001 {
14002     char prop[PROPERTY_VALUE_MAX];
14003     memset(prop, 0, sizeof(prop));
14004     property_get("persist.camera.llc", prop, "0");
14005     m_LLCaptureEnabled = (atoi(prop) > 0) ? TRUE : FALSE;
14006 
14007     if (!m_LLCaptureEnabled) {
14008         m_LowLightLevel = CAM_LOW_LIGHT_OFF;
14009     }
14010 }
14011 
14012 /*===========================================================================
14013  * FUNCTION   : fdModeInVideo
14014  *
14015  * DESCRIPTION: FD in Video change
14016  *
14017  * PARAMETERS : none
14018  *
14019  * RETURN     : FD Mode in Video
14020  *              0 : If FD in Video disabled
14021  *              1 : If FD in Video enabled for Detection, focus
14022  *              2 : If FD in Video enabled only for focus
14023  *==========================================================================*/
fdModeInVideo()14024 uint8_t QCameraParameters::fdModeInVideo()
14025 {
14026     char value[PROPERTY_VALUE_MAX];
14027     uint8_t fdvideo = 0;
14028 
14029     if (!m_pCapability->hw_analysis_supported) {
14030         return 0;
14031     }
14032 
14033     property_get("persist.camera.fdvideo", value, "0");
14034     fdvideo = (atoi(value) > 0) ? atoi(value) : 0;
14035 
14036     LOGD("FD mode in Video : %d", fdvideo);
14037     return fdvideo;
14038 }
14039 
14040 /*===========================================================================
14041  * FUNCTION   : setManualCaptureMode
14042  *
14043  * DESCRIPTION: Function to set Manual capture modes
14044  *
14045  * PARAMETERS :
14046  *   @mode : Capture mode configured
14047  *
14048  * RETURN     : int32_t type of status
14049  *              NO_ERROR  -- success
14050  *              none-zero failure code
14051  *==========================================================================*/
setManualCaptureMode(QCameraManualCaptureModes mode)14052 int32_t QCameraParameters::setManualCaptureMode(QCameraManualCaptureModes mode)
14053 {
14054     int32_t rc = NO_ERROR;
14055     char value[PROPERTY_VALUE_MAX];
14056     int8_t count = 0;
14057 
14058     property_get("persist.camera.manual.capture", value, "0");
14059     count = atoi(value);
14060 
14061     if (count) {
14062         if (mode == CAM_MANUAL_CAPTURE_TYPE_OFF) {
14063             m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_1;
14064         } else {
14065             m_ManualCaptureMode = mode;
14066         }
14067     } else {
14068         m_ManualCaptureMode = CAM_MANUAL_CAPTURE_TYPE_OFF;
14069     }
14070 
14071     if (m_ManualCaptureMode == CAM_MANUAL_CAPTURE_TYPE_2) {
14072         setOfflineRAW(FALSE);
14073     } else if (m_ManualCaptureMode >= CAM_MANUAL_CAPTURE_TYPE_3) {
14074         setOfflineRAW(TRUE);
14075     } else {
14076         setOfflineRAW(FALSE);
14077     }
14078     setReprocCount();
14079     LOGH("Manual capture mode - %d", m_ManualCaptureMode);
14080     return rc;
14081 }
14082 
14083 /*===========================================================================
14084  * FUNCTION   : isReprocScaleEnabled
14085  *
14086  * DESCRIPTION: Whether reprocess scale is enabled or not
14087  *
14088  * PARAMETERS : none
14089  *
14090  * RETURN     : TRUE  : Reprocess scale is enabled
14091  *              FALSE : Reprocess scale is not enabled
14092  *==========================================================================*/
isReprocScaleEnabled()14093 bool QCameraParameters::isReprocScaleEnabled()
14094 {
14095     return m_reprocScaleParam.isScaleEnabled();
14096 }
14097 
14098 /*===========================================================================
14099  * FUNCTION   : isUnderReprocScaling
14100  *
14101  * DESCRIPTION: Whether image is under reprocess scaling
14102  *
14103  * PARAMETERS : none
14104  *
14105  * RETURN     : TRUE  : Image is under reprocess scaling
14106  *              FALSE : Image is not under reprocess scaling
14107  *==========================================================================*/
isUnderReprocScaling()14108 bool QCameraParameters::isUnderReprocScaling()
14109 {
14110     return m_reprocScaleParam.isUnderScaling();
14111 }
14112 
14113 /*===========================================================================
14114  * FUNCTION   : getPicSizeFromAPK
14115  *
14116  * DESCRIPTION: Get picture size set from application.
14117  *
14118  * PARAMETERS :
14119  *   @width   : with set by application
14120  *   @height  : height set by application
14121  *
14122  * RETURN     : int32_t type of status
14123  *              NO_ERROR  -- success
14124  *              none-zero failure code
14125  *==========================================================================*/
getPicSizeFromAPK(int & width,int & height)14126 int32_t QCameraParameters::getPicSizeFromAPK(int &width, int &height)
14127 {
14128     return m_reprocScaleParam.getPicSizeFromAPK(width, height);
14129 }
14130 
14131 
14132 
14133 /*===========================================================================
14134  * FUNCTION   : setDualLedCalibration
14135  *
14136  * DESCRIPTION: set dual led calibration
14137  *
14138  * PARAMETERS :
14139  *   @params  : user setting parameters
14140  *
14141  * RETURN     : int32_t type of status
14142  *              NO_ERROR  -- success
14143  *              none-zero failure code
14144  *==========================================================================*/
setDualLedCalibration(__unused const QCameraParameters & params)14145 int32_t QCameraParameters::setDualLedCalibration(
14146         __unused const QCameraParameters& params)
14147 {
14148     char value[PROPERTY_VALUE_MAX];
14149     int32_t calibration = 0;
14150 
14151     memset(value, 0, sizeof(value));
14152     property_get("persist.camera.dual_led_calib", value, "0");
14153     calibration = atoi(value);
14154     if (calibration != m_dualLedCalibration) {
14155       m_dualLedCalibration = calibration;
14156       LOGD("%s:updating calibration=%d m_dualLedCalibration=%d",
14157         __func__, calibration, m_dualLedCalibration);
14158 
14159       if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
14160                CAM_INTF_PARM_DUAL_LED_CALIBRATION,
14161                m_dualLedCalibration)) {
14162           LOGE("%s:Failed to update dual led calibration param", __func__);
14163           return BAD_VALUE;
14164       }
14165     }
14166     return NO_ERROR;
14167 }
14168 
14169 /*===========================================================================
14170  * FUNCTION   : setinstantAEC
14171  *
14172  * DESCRIPTION: set instant AEC value to backend
14173  *
14174  * PARAMETERS :
14175  *   @value : instant aec enabled or not.
14176  *            0 - disable
14177  *            1 - Enable and set agressive AEC algo to the backend
14178  *            2 - Enable and set fast AEC algo to the backend
14179  *
14180  * RETURN     : int32_t type of status
14181  *              NO_ERROR  -- success
14182  *              none-zero failure code
14183  *==========================================================================*/
setInstantAEC(uint8_t value,bool initCommit)14184 int32_t QCameraParameters::setInstantAEC(uint8_t value, bool initCommit)
14185 {
14186     if (initCommit) {
14187         if (initBatchUpdate(m_pParamBuf) < 0) {
14188             LOGE("Failed to initialize group update table");
14189             return FAILED_TRANSACTION;
14190         }
14191     }
14192 
14193     int32_t rc = NO_ERROR;
14194     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf, CAM_INTF_PARM_INSTANT_AEC, value)) {
14195         LOGE("Failed to instant aec value");
14196         return BAD_VALUE;
14197     }
14198 
14199     // set the new value
14200     char val[8];
14201     snprintf(val, sizeof(val), "%d", value);
14202     updateParamEntry(KEY_QC_INSTANT_AEC, val);
14203 
14204     if (initCommit) {
14205         rc = commitSetBatch();
14206         if (NO_ERROR != rc) {
14207             LOGE("Failed to instant aec value");
14208             return rc;
14209         }
14210     }
14211 
14212     LOGD(" Instant AEC value set to backend %d", value);
14213     m_bInstantAEC = value;
14214     return rc;
14215 }
14216 
14217 /*===========================================================================
14218  * FUNCTION   : setAdvancedCaptureMode
14219  *
14220  * DESCRIPTION: set advanced capture mode
14221  *
14222  * PARAMETERS : none
14223  *
14224  * RETURN     : int32_t type of status
14225  *              NO_ERROR  -- success
14226  *              none-zero failure code
14227  *==========================================================================*/
setAdvancedCaptureMode()14228 int32_t QCameraParameters::setAdvancedCaptureMode()
14229 {
14230     uint8_t value = isAdvCamFeaturesEnabled();
14231     LOGD("updating advanced capture mode value to %d",value);
14232     if (ADD_SET_PARAM_ENTRY_TO_BATCH(m_pParamBuf,
14233             CAM_INTF_PARM_ADV_CAPTURE_MODE, value)) {
14234         LOGE("Failed to set advanced capture mode param");
14235         return BAD_VALUE;
14236     }
14237     return NO_ERROR;
14238 }
14239 
14240 }; // namespace qcamera
14241